From sln at netherlands.com Thu Jan 1 00:23:52 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Thu, 01 Jan 2009 05:23:52 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: >Xah Lee wrote: >> Just spent 3 hours looking into Ruby today. Here's my short impression >> for those interested. >> >> * Why Not Ruby? >> http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html >> >> plain text version follows: >> -------------------------------------- >> >> Why Not Ruby? >> >> Xah Lee, 2008-12-31 >> >> Spent about 3 hours looking into Ruby language today. >> >> The articles i read in detail are: >> >> * Wikipedia: Ruby (programming language)?J. Gives general overview. >> >> * Brief tutorial: "Ruby in Twenty Minutes" >> http://www.ruby-lang.org/en/documentation/quickstart/ >> >> * Personal blog by Stevey Yegge, published in 2004-10. >> http://steve.yegge.googlepages.com/ruby-tour >> >> The Wikipedia gives the best intro and overview in proper context. The >> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete >> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't >> teach much and rambles, but provide a little personal view. I read it >> because his opinions i respect. >> >> Q: Will you learn Ruby? >> >> No. For practical application, the lang is some 100 times less useful >> than each of Perl, Python, PHP, Javascript. For academic study, >> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far >> more interesting and powerful in almost all aspects. Further, there's >> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or >> power, these modern lang of the past 5 years matches or exceed Ruby. >> >> Q: Do you think Ruby lang is elegant? >> >> Yes. In my opinion, better than Perl, Python, PHP. As a high level >> lang, it's far better than Java, C, C++ type of shit. However, i don't >> think it is any better than emacs lisp, Scheme lisp, javascript, >> Mathematica. Note that Ruby doesn't have a spec, and nor a formal >> spec. Javascript has. Ruby's syntax isn't that regular, nor is it >> based on a system. Mathemtica's is. Ruby's power is probably less than >> Scheme, and probably same as Javascript. >> >> I also didn't like the fact that ruby uses keyword "end" to indicate >> code block much as Pascal and Visual Basic, Logo, do. I don't like >> that. >> >> Q: Won't Ruby be a interesting learning experience? >> >> No. As far as semantics goes, Ruby is basically identical to Perl, >> Python, PHP. I am a expert in Perl and PHP, and have working knowledge >> of Python. I already regretted having spent significant amount of time >> (roughly over a year) on Python. In retrospect, i didn't consider the >> time invested in Python worthwhile. (as it turns out, i don't like >> Python and Guido cult, as the lang is going the ways of OOP mumbo- >> jumbo with its Python 3 "brand new" future.) There is absolutely >> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp, >> Scheme lisp. >> >> Q: Do you recommend new programers to learn Ruby then? >> >> Not particularly. As i mentioned, if you are interested in practical >> utility, there's already Perl, PHP, Python, Javascript, which are all >> heavily used in the computing industry. If you are interested as a >> academic exercise, there's Scheme lisp, and much of functional langs >> such as OCaml, Haskell, Mathematica, which will teach you a whole lot >> more about computer science, features of language semantics, etc. >> >> Q: Do you condemn Ruby? >> >> No. I think it's reasonably elegant, but today there are too many >> languages, so Ruby don't particularly standout for me. Many of them, >> are arguably quite more elegant and powerful than Ruby. See: >> Proliferation of Computing Languages. >> > >Kenny Tilton, 2008-12-31 > >Q: Why not Xah's review of Ruby? > >>> Spent about 3 hours looking into Ruby language today. > >A. Three hours? I've had belches that lasted longer than that. Of >course, a true master can tell a lot in just a few hours of coding with >a new language... > >>> The articles i read in detail are: > >Q: Read?! > >A: That's what he said. > > >hth,kzo Be carefull what you say. If they pay me I would rip your and Xah's guts out in a second. sln From mail at microcorp.co.za Thu Jan 1 01:45:38 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 1 Jan 2009 08:45:38 +0200 Subject: select.select and socket.setblocking References: <495a661d$0$11384$5fc30a8@news.tiscali.it><495b34d8$0$11387$5fc30a8@news.tiscali.it> <495b4be5$0$11379$5fc30a8@news.tiscali.it> Message-ID: <010601c96be0$538bffa0$0d00a8c0@hendrik> "Francesco Bochicchio" wrote: > but then, IIRC TCP guarantees that the packet is fully received by > hand-shaking at transport level between sender and receiver. Ad once the > packet is fully in the receiver buffer, why should recv choose to give > back to the application only a piece of it? This depends a lot on the definition of "package" - At the TCP/IP level, the protocol is quite complex - there are all sorts of info flowing back and forth, telling the transmitter how much space the receiver has available. So your "record" or "package" could be split up... But it gets worse, or better, depending on your point of view: At the ethernet level, a packet is less than 1.5k - so if your record is longer, it can also be split up - OTOH, if it all fits into one ethernet packet, there is every chance that it won't be split up, unless you send a lot of them in a row, without waiting for a response - if you are running something that sends a small request and listens for a small answer, then you will probably never see a record split - but if you run a kind of sliding window protocol that streams a lot of data (even in small packets) then sooner or later one of them will be partly delivered... - Hendrik From rt8396 at gmail.com Thu Jan 1 02:12:48 2009 From: rt8396 at gmail.com (r) Date: Wed, 31 Dec 2008 23:12:48 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Hey Lee, I really like your overview of the official Python tut, it's spot on, and your study of OOP was quite fascinating! I like people who are honest and not afraid to go up against the status quo, although i will admit you go a little further than i might at times :). But the world needs an enema from time to time. "Revolution is my name!" Face it, the world needs people like Xah. Go check out his site, his insights of languages and tech is fascinating. The man lives in a world driven by common sense, and you know what they say --"Common sense is the least most common thing"-- just look around at the responses here. I come from a different world than IT, and I thought initially the IT world would be filled with intelligent, free thinking, and open minded people... BOY was i wrong! I would not turn my back on these people for a second, lest you catch a knife in it! I find it laughable how people hate you so much, but would still take the time to reply to your post, just so they can call you a troll. You are not a troll Xah, but your posts do expose the true trolls and their minions. Instead of engaging in any sort of intellectual conversation, they spit 3 grade insults and try to discredit you. There is nothing wrong with a person expressing their opinion on any subject. Apparently some of you need to get laid and calm down a little. Xah has just as much right as anyone here to post his thoughts, even if they are off topic. Look, if you don't like what he is saying, DON'T F'IN READ IT! Xah, I been watching your posts for sometime and it looks like you have been around for a while. Your profile shows one star & 410 ratings. I have only been in usenet for 2 month and i have one star and 253 ratings(that will grow to much more after this post), most are from my supposed "brothers" here at c.l.py. Just letting you know there are open minded people out here. I would hate to live in a world that did not contain an Xah lee. Keep up the good work my brother, you have much more to give! Thanks From jasonrumney at gmail.com Thu Jan 1 03:05:41 2009 From: jasonrumney at gmail.com (Jason Rumney) Date: Thu, 1 Jan 2009 00:05:41 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: On Jan 1, 3:12?pm, r wrote: > The man lives in a world driven by common sense "Common" sense suggests that his views are shared among the general populace. I don't see much evidence of that in the sometimes never- ending threads that frequently follow his postings. But it is good to start debates about making changes to the status quo, often the debates will result in worthwhile changes, even if those changes are not what he proposed. I just wish he would choose his venue a little more carefully sometimes. From geon at post.cz Thu Jan 1 03:11:50 2009 From: geon at post.cz (Pavel Kosina) Date: Thu, 01 Jan 2009 09:11:50 +0100 Subject: idle 3.0 unicode Message-ID: <495C7AC6.1000506@post.cz> As for unicode in Python 2.5 everything works fine in program running either in IDLE or under Command line: # -*- coding: utf-8 -*- print u"?????????" In 3.0 there is an error. The same program, moved to 3.0 syntax, in IDLE editor : # -*- coding: utf-8 -*- print ("?????????") prints: ?????????????????? The same program running in Command line from PSPad editor works fine. Is it mistake of my misunderstanding or of IDLE? ------------- The same program without coding declaration (but saved in utf8) : print ("?????????") even immediately destroyed my IDLE window without any error message. -- geon Pavel Kosina From bockman at virgilio.it Thu Jan 1 03:31:13 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Thu, 01 Jan 2009 09:31:13 +0100 Subject: select.select and socket.setblocking In-Reply-To: References: <495a661d$0$11384$5fc30a8@news.tiscali.it> <495b34d8$0$11387$5fc30a8@news.tiscali.it> Message-ID: <495c7f52$0$733$5fc30a8@news.tiscali.it> > Can you post an example program that exhibits the behavior you > describe? > > I was forgetting about the MSG_WAITALL flag ... When I started programming with sockets, it was on a platform (IIRC Solaris) that by default behaved like MSG_WAITALL was set by default (actually, I don't remember it being mentioned at all in the man pages). This sort of biased my understanding of the matter. I actually used that flag recently - on Linux - to get the same behavior I was used to, but forgot about that. My bad :-) Ciao ------ FB From s.selvamsiva at gmail.com Thu Jan 1 03:38:53 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 1 Jan 2009 14:08:53 +0530 Subject: pygtkspell-help Message-ID: Hello, i am in a process of writing spell checker for my local language(Tamil). I wrote a plugin for gedit with pygtk for gui.Recently i came to know about pygtkspell ,that can be used for spell checking and suggestion offering. I am bit congused about it and could not able to get useful info by googling.It will be nice if someone can direct me in right way(may be by giving appropriate links or example program) -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Thu Jan 1 03:58:20 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 08:58:20 +0000 Subject: Videocapture in python In-Reply-To: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: Can you post your code or a code segment? I would be interested in seeing how this works. On Thu, Jan 1, 2009 at 3:29 AM, wrote: > I face issues in videocapture in python. Cant find anyplace where we > can raise bug reports, so mentioning here. Also help required if > somebody has solved it earlier. > > On using videocapture (python 2.4), I am facing the following issues > while creating a video sort of application. > -> Pull out the usb cable : Videocapture gets the data stored > initially in the buffer and returns always. The images are not updated > - but also there is no error returned. > i.e. there is no information to the viewer that it is not working > anymore. Especially because since the timestamp is updated everytime > (it is done inside videocapture.py - wherein current time is > overwritten on the received image), it gives a feeling that video is > running. > > Currently I have done a workaround in that every 2 captures, i setup > the camera again - but it takes too much time. Anyone has any > suggestions on solving this? > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Thu Jan 1 04:04:15 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 09:04:15 +0000 Subject: Creating an application for Linux In-Reply-To: <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> Message-ID: I found a great video on how to do this last night. I wasn't even looking for it. Check it out. It's really good. Makes me want to start making videos as well. Thanks. Ubuntu: Making a .deb package out of a python program (English) tutorial video - Ubuntu: Making a .deb package out of a python program (English) - Learn: python, deb, deb_package, publishing, package, english, ubuntu, linux On Wed, Dec 31, 2008 at 9:54 PM, Mike Driscoll wrote: > On Dec 31, 3:36 pm, lkcl wrote: > > hiya mike: where do i know you from? i've heard your name somewhere > > and for the life of me can't remember where! anyway... onwards. > > > > I don't know...while your username looks vaguely familiar, I don't > think I've communicated with you recently. I spend most of my time on > the wxPython list now... > > > > your simplest bet is to take advantage of the .deb install system, > > which, if you follow that, will allow you to pull in all of the > > dependencies _without_ screwing around with the ubuntu distribution, > > or requiring that you build "special" versions of the dependencies. > > > > so - your first port of call is to locate a similar app to your own > > one: > > > > apt-cache search wxwidgets > > [rose-tinted filter on the results...] > > cryptonit - A client side PKI (X.509) cryptographic tool > > fontypython - A GUI tool to manage ttf fonts > > jmdlx - jugglemaster deluxe using wxWidgets > > wxmaxima - a wxWidgets GUI for the computer algebra system maxima > > multiget - graphical download manager > > > > then, do apt-cache show , paying particular attention to > > the dependencies. apt-cache show fontypython looks like a good > > candidate. > > > > so, do apt-get source fontypython (or other candidate) > > > > also do apt-get build-essential dh-make dpkg-dev debutils python-dev > > devscripts python-setuptools juuust for fun, but the essential ones > > are probably dh-make and dpkg-dev. > > > > then you have something to work from (an example - the source of the > > deb-wrapped fontypython) and you will have most of the debian > > developer utils etc. etc. > > > > _then_ you go to e.g. oooo this: > http://www.pythonmark.com/python-library/debian/howto-build-a-debian-... > > the preamble for which says "don't bother with that annoying ubuntu > > python deb howto video, particularly on the basis that who gives a > > stuff about _verbal_ instructions when you actually want stuff you can > > READ!" > > > > :) > > > > the most important thing that _you_ need to remember is that you > > _must_ identify the correct libraries (and their debian packagenames - > > can't bring myself to say ubuntu packagenames) and make damn sure that > > you add them into the dependencies in the debian/control file. > > > > do _not_ be tempted to "bundle" customised versions of python- > > pysqlite, python-sqlalchemy etc. etc. > > > > testing: you should really use a debootstrap absolute "basic" > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > whatever). > > > I thought the general practice was to test on the closest software/ > hardware combo that your application was most likely to run on. I have > heard of doing testing on the lowest common denominator before though. > Unfortunately, I don't have time to set up a bare-bones VM since we're > closing soon, but I may give this a go on Friday and report back. > > > > > ... and _then_ install your .deb (with dpkg -i) followed by apt-get -f > > install (to pull in all of the dependencies). > > > > then, use export DISPLAY=192.168.1.5:0.0 (adapt as necessary), run > > xhost + on 192.168.1.5 (adapt as necessary), and _then_ fire up your > > test app. > > > > if you get a python library not found runtime error, you know that you > > got your dependencies wrong, in the debian/control file. > > > > if you install a "vanilla" ubuntu desktop, various other packages will > > pull in the dependencies for you - and you will never find out if you > > got all of the dependencies correct. > > > > that having been said, if you don't _care_ about correctness, skip the > > above six sentences :) > > > > l. > > > > Thanks for the instructions. > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.grimm at science-computing.de Thu Jan 1 04:23:32 2009 From: r.grimm at science-computing.de (r.grimm at science-computing.de) Date: Thu, 1 Jan 2009 01:23:32 -0800 (PST) Subject: folder extraction References: Message-ID: On Dec 30 2008, 4:30 pm, ibpe... at gmail.com wrote: > how do i get along with this task of extracting multiples folder and > generating their names individually in a their respective files as > they were generated. Hallo, I hope, that I interpret your question in the right way. You can use the following function as a starting point to get all files ending with py or pyc from your working dir. Invoke getAllFilesOfPatterns(".","*.py *.pyc") import os import fnmatch def getAllFilesOfPatterns( dir ,patterns="*", recursive=True ): """ patterns must be space separeted string of patterns e.g: *.pdf *.ps *.html """ patterns= patterns.split() retValue=[] for path,dirs,files in os.walk(dir): for file in files: for pattern in patterns: if fnmatch.fnmatch( file , pattern ): retValue.append(os.path.join(path,file)) if not recursive: break return retValue Greetings From aleksandr.goretoy at gmail.com Thu Jan 1 04:25:16 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 09:25:16 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: I recently conquered this pass by ref thing. This is how I did it. Python 2.4.3 (#1, Apr 3 2006, 14:02:53) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(v): ... v="asdf" ... >>> def f2(v): ... v=["asdf"] ... >>> def f3(v): ... v.append("asdf") ... >>> a="fdsa" >>> b=["fdsa"] >>> f1(a) >>> a 'fdsa' >>> f1(b) >>> b ['fdsa'] >>> f2(a) >>> a 'fdsa' >>> f2(b) >>> b ['fdsa'] >>> f3(a) Traceback (most recent call last): File "", line 1, in ? File "", line 2, in f3 AttributeError: 'str' object has no attribute 'append' >>> f3(b) >>> b ['fdsa', 'asdf'] >>> if you only want one value in there, you can pop off the first value and then append. def f4(v): _old=v.pop() v.append("asdf") you can then also turn it back into a string by doing this: b[0] I was very glad to have learned this way to do by ref. Thanks. On Wed, Dec 31, 2008 at 11:32 PM, Aaron Brady wrote: > On Dec 31, 5:30 am, iu2 wrote: > > Hi, > > > > Is it possible somehow to change a varible by passing it to a > > function? > > > > I tried this: > > > > def change_var(dict0, varname, val): > > dict0[varname] = val > > > > def test(): > > a = 100 > > change_var(locals(), 'a', 3) > > print a > > > > But test() didn't work, the value a remains 100. > > > > I have several variables initialized to None. > > I need to convert each one of them an object only if it is None. > > something like: > > > > if not var1: var1 = MyObject() > > > > I want this to be a function, that is: > > > > def create_obj(var): > > if not var: var = MyObj() > > # set properties of var > > > > Now, I know I can achieve this by functional programming, > > > > def create_obj(var): > > if not var: > > x = MyObj() > > # set properties of x > > return x > > return var > > > > and then > > > > var = creaet_obj(var) > > > > Is there another way? > > > > Thanks > > A practical way is to use a container. Some people use lists; I like > an object. > > thingref= Ref( thing ) > f( thingref ) > print thingref() #or thingref.get() or w'ver. > > Then 'f' can assign like this: > > def f( aref ): > # blah blah > aref( newthing ) #or aref.set( newthing ) > > But the short answer is no. A function receives the contents of a > variable, not a variable. > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From qdlqdl at 163.com Thu Jan 1 04:32:12 2009 From: qdlqdl at 163.com (=?ISO-2022-JP?B?GyRCPi5PMBsoQg==?=) Date: Thu, 1 Jan 2009 01:32:12 -0800 (PST) Subject: idle 3.0 unicode References: Message-ID: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> On 1?1?, ??4?11?, Pavel Kosina wrote: > As for unicode in Python 2.5 everything works fine in program running > either in IDLE or under Command line: > # -*- coding: utf-8 -*- > print u"?????????" > > In 3.0 there is an error. ?The same program, moved to 3.0 syntax, in > IDLE editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program running in Command line from PSPad editor works fine. ? > Is it mistake of my misunderstanding or of IDLE? > > ------------- > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. > > -- > geon > Pavel Kosina #coding="utf-8" #?? print('a') saved in utf8 alt+x,destroyed IDLE... me too,why? From joshua86 at gmail.com Thu Jan 1 04:43:59 2009 From: joshua86 at gmail.com (Joshua Moore) Date: Thu, 1 Jan 2009 01:43:59 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <95479382-5996-40da-b20d-8e6e83b725ea@s1g2000prg.googlegroups.com> On Dec 30 2008, 8:07?am, "andyh... at gmail.com" wrote: > Hi, > > Can anybody recommend an approach for loading and parsing Excel > spreadsheets in Python. Any well known/recommended libraries for this? > > The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, > but I'd rather get some more input before going with something I don't > know. > > Thanks, > Andy. Is saving the spreadsheet as a comma separated file an option for you? If so, it's not hard to throw something together for cvs files, but there are even modules for that. Josh From sjmachin at lexicon.net Thu Jan 1 04:56:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 1 Jan 2009 01:56:10 -0800 (PST) Subject: folder extraction References: Message-ID: <9e75caba-1f52-4a01-b7d4-6c2bd52f3946@i20g2000prf.googlegroups.com> On Jan 1, 8:23?pm, r.gr... at science-computing.de wrote: > On Dec 30 2008, 4:30 pm, ibpe... at gmail.com wrote: > > > how do i get along with this task of extracting multiples folder and > > generating their names individually in a their respective files as > > they were generated. > > Hallo, > I hope, that I interpret your question in the right way. > You can use the following function as a starting point to get all > files ending with py or pyc from your working dir. > Invoke getAllFilesOfPatterns(".","*.py *.pyc") > > import os > import fnmatch > def getAllFilesOfPatterns( dir ,patterns="*", ?recursive=True ?): > ? ? """ patterns must be space separeted string of patterns > ? ? ? ? e.g: *.pdf *.ps *.html > ? ? ? ? """ > ? ? patterns= patterns.split() > ? ? retValue=[] > ? ? for path,dirs,files in os.walk(dir): > ? ? ? ? for file in files: > ? ? ? ? ? ? for pattern in patterns: > ? ? ? ? ? ? ? ? if fnmatch.fnmatch( file , pattern ): > ? ? ? ? ? ? ? ? ? ? retValue.append(os.path.join(path,file)) # put a "break" after the append so that you avoid (a) duplicates [if the patterns are not mutually exclusive] (b) waste of CPU time [always] > ? ? ? ? if not recursive: break > ? ? return retValue > > Greetings From geon at post.cz Thu Jan 1 05:06:48 2009 From: geon at post.cz (Pavel Kosina) Date: Thu, 01 Jan 2009 11:06:48 +0100 Subject: idle 3.0 unicode In-Reply-To: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> References: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> Message-ID: <495C95B8.7080300@post.cz> ?? napsal(a), dne 1.1.2009 10:32: > #coding="utf-8" > #?? > print('a') > > saved in utf8 > alt+x,destroyed IDLE... > me too,why? > Are you sure? Run (F5) with print('a') is OK here. Maybe you have redefined key bindings in IDLE ... -- geon Pavel Kosina From merlyn at stonehenge.com Thu Jan 1 05:07:26 2009 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Thu, 01 Jan 2009 02:07:26 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <861vvnqqzl.fsf@blue.stonehenge.com> >>>>> "r" == r writes: r> Xah, I been watching your posts for sometime and it looks like you r> have been around for a while. Your profile shows one star & 410 r> ratings. I have only been in usenet for 2 month and i have one star r> and 253 ratings(that will grow to much more after this post), most are r> from my supposed "brothers" here at c.l.py. Just letting you know r> there are open minded people out here. I would hate to live in a world r> that did not contain an Xah lee. Since Usenet has neither "stars" nor "ratings", you are hallucinating. Care to elaborate? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion From mirnazim at gmail.com Thu Jan 1 05:28:40 2009 From: mirnazim at gmail.com (Mir Nazim) Date: Thu, 1 Jan 2009 02:28:40 -0800 (PST) Subject: Chart libs for python Message-ID: <4a8c13a2-a2ae-4815-9560-8e1ef1e21f97@i24g2000prf.googlegroups.com> Hi guys, Please suggest me chart generation library for python comparable to google chart in features and ease of development. Google Chart has a limitation on amount on data you can send in a URL. Thanks From stef.mientki at gmail.com Thu Jan 1 06:10:34 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 01 Jan 2009 12:10:34 +0100 Subject: Easy-to-use Python GUI In-Reply-To: <6s2n0sF408fuU1@mid.uni-berlin.de> References: <6s2n0sF408fuU1@mid.uni-berlin.de> Message-ID: <495CA4AA.1080003@gmail.com> Gerhard H?ring wrote: > Dotan Cohen wrote: >> I have been following this thread with interest. Is there a way to >> build Qt apps with relative easy? I use KDE and would prefer the Qt >> toolkit for my GUI apps. Thanks. > > A few years ago, I've had bad experiences with wxPython (random things > not actually working on Linux, only on Windows; getting segfaults when > using not exactly the right values for API calls). > > So, when I had to decide for a toolkit for a new application I'm > developing on my job which required: > > - ability to run on Windows > - ability to run on MacOS > - time to develop is short > > I recommended to go with PyQt. > > I remembered it was warmly recommended by Alex Martelli and others a > few years ago. > > So far, it's been nothing but joy. We bought the book "Rapid GUI > Programming with Python and Qt" (http://www.qtrac.eu/pyqtbook.html) > which is *really* well written. It's probably the best tech book I > ever had. The author formerly did Qt documentation for Trolltech, so > he has deep understanding of what he's writing about. > > There may be not so many third-party add-ons for PyQt like for > wxPython, but in my opinion, the quality of Qt, PyQt and > documentation like the book make up for it. > > And, it's really extensive. So far I've found everything in Qt/PyQt I > wanted/needed: > > - MDI workspaces > - Dock windows > - I needed something like wxPythons wxOGL for a process modeler and > after looking around for two days, I found out that it's already all > there in Qt 4.4: QGraphicsScene/QGraphicsView > - etc. > I think wxPython now has it all too. I replaced wxOGL with a modified version of OGLlike, see some screenshots here: http://mientki.ruhosting.nl/data_www/pylab_works/pw_animations_screenshots.html cheers, Stef > -- Gerhard > -- > http://mail.python.org/mailman/listinfo/python-list From placebo at dontbesilly.com Thu Jan 1 06:34:42 2009 From: placebo at dontbesilly.com (Peter Wyzl) Date: Thu, 01 Jan 2009 11:34:42 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <861vvnqqzl.fsf@blue.stonehenge.com> Message-ID: "Randal L. Schwartz" wrote in message news:861vvnqqzl.fsf at blue.stonehenge.com... >>>>>> "r" == r writes: > > r> Xah, I been watching your posts for sometime and it looks like you > r> have been around for a while. Your profile shows one star & 410 > r> ratings. I have only been in usenet for 2 month and i have one star > r> and 253 ratings(that will grow to much more after this post), most are > r> from my supposed "brothers" here at c.l.py. Just letting you know > r> there are open minded people out here. I would hate to live in a world > r> that did not contain an Xah lee. > > Since Usenet has neither "stars" nor "ratings", you are hallucinating. > > Care to elaborate? Google groups' corrupting influence... P From huffman at tokyo.email.ne.jp Thu Jan 1 06:37:19 2009 From: huffman at tokyo.email.ne.jp (Tokyo Dan) Date: Thu, 1 Jan 2009 03:37:19 -0800 (PST) Subject: If your were going to program a game... Message-ID: If your were going to program a game in python what technologies would you use? The game is a board game with some piece animations, but no movement animation...think of a chess king exploding. The game runs in a browser in a window of a social site built around the game. The social site has login, chat, player stats, list of active games, etc. AND there is also be a desktop client that accesses the game server via the same communication mechanism (like an AIR-based desktop client/ app) as the browser-based version - I guess using JSON/RPC. From koranthala at gmail.com Thu Jan 1 07:28:21 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 04:28:21 -0800 (PST) Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: On Jan 1, 1:58?pm, "alex goretoy" wrote: > Can you post your code or a code segment? I would be interested in seeing > how this works. > > > > On Thu, Jan 1, 2009 at 3:29 AM, wrote: > > I face issues in videocapture in python. Cant find anyplace where we > > can raise bug reports, so mentioning here. Also help required if > > somebody has solved it earlier. > > > On using videocapture (python 2.4), I am facing the following issues > > while creating a video sort of application. > > -> Pull out the usb cable : Videocapture gets the data stored > > initially in the buffer and returns always. The images are not updated > > - but also there is no error returned. > > i.e. there is no information to the viewer that it is not working > > anymore. Especially because since the timestamp is updated everytime > > (it is done inside videocapture.py - wherein current time is > > overwritten on the received image), it gives a feeling that video is > > running. > > > Currently I have done a workaround in that every 2 captures, i setup > > the camera again - but it takes too much time. Anyone has any > > suggestions on solving this? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? Since the code uses a lot of other variables - due to being a part of a larger project, I will try to provide pseudocode. At initialization: def setup_cam(): global cam, i cam = Device (devnum = 0) i = 0 def take_photo(obj): i += 1 if i >2: setup_cam() obj.img = cam.getImage(timestamp=3) I actually would like to have the code as try: obj.img = cam.getImage(timestamp=3) except CamException: setup_cam() But, since no exception is provided, I have to resort to the kludge shown. Please let me know if you need any more information. From koranthala at gmail.com Thu Jan 1 07:44:33 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 04:44:33 -0800 (PST) Subject: initialization in python Message-ID: How does an average product handle initialization in python? I am facing lot of issues in handling initialization, especially if I import specific variables, due to the variables not getting updated. For example - taking a sqlalchemy based product: Module database: ^^^^^^^^^^^^^^^^^^^ Session = None def init(dbname): engine = create_engine('sqlite:///%s' %dbname) ... global Session Session = sessionmaker(bind=engine) In entry module to the application (APPENTRY): ^^^^^^^^^^^^^^^^^^^ import A, B, C, D <---- Please note, very important .... .... database.init('testdb.db') Now in user module A: ^^^^^^^^^^^^^^^^^^^^^^^^^^ from database import Session print Session --->This will print None, because at APPENTRY, during importing A itself, Session is stored. I have to call database.Session to get the values. Why is the variable not getting updated? Can anyone help me out? From bdesth.quelquechose at free.quelquepart.fr Thu Jan 1 08:43:30 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 01 Jan 2009 14:43:30 +0100 Subject: SQL, lite lite lite In-Reply-To: References: <39322fe4-e606-42dc-9123-71751258c3ae@a12g2000pro.googlegroups.com> <8da5c6b1-951f-4abd-8ee7-07b63802b9f6@13g2000yql.googlegroups.com> <186e44f7-f949-45e2-b1e2-a913560acf94@s9g2000prg.googlegroups.com> <495a97ce$0$25469$426a74cc@news.free.fr> Message-ID: <495cd630$0$17993$426a74cc@news.free.fr> Aaron Brady a ?crit : > On Dec 30, 2:52 pm, Bruno Desthuilliers > wrote: >> Aaron Brady a ?crit : >> >>> On Dec 30, 11:16 am, prueba... at latinmail.com wrote: >> (snip) >>>> You really do like to reinvent the wheels do you? :-) Nothing wrong >>>> with that. Just be aware that most people that really need what you >>>> are proposing are probably already using mature feature rich libraries >>>> for that. >>>> http://wiki.python.org/moin/HigherLevelDatabaseProgramming >>> Look at these options! Who invents the wheel? Naturally, I've had >>> time to master every one. >> Oh, so that's why you propose to add yet another item to the list ? > > Aha, so it is. Your criticism might seem harsh, This was mostly a tentative to make you notice that it might be better to check out the existing solutions and possibly contribute to one of them instead of inventing yet another one... > but it has an > advantage. It made me get the lead out, that is, think. > (snip) ... but it obviously failed. From luke.leighton at googlemail.com Thu Jan 1 08:47:22 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 1 Jan 2009 05:47:22 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> Message-ID: <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > On Dec 31, 3:36 pm,lkcl wrote: > > > hiya mike: where do i know you from? i've heard your name somewhere > > and for the life of me can't remember where! anyway... onwards. > > I don't know...while your username looks vaguely familiar, I don't > think I've communicated with you recently. I spend most of my time on > the wxPython list now... i think it might be from my old school - i could be confusing you with someone, though - "gary driscoll", perhaps? anyway, never mind :) > > testing: you should really use a debootstrap absolute "basic" > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > whatever). > > I thought the general practice was to test on the closest software/ > hardware combo that your application was most likely to run on. that you should do as well :) you should be able to either upgrade the bare-bones version using "tasksel install desktop" or just... what-the-heck, install on a vanilla combo. http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/current/images/netboot/ archive.ubuntu.com appears offline at the moment - maybe it'll be back later. i recommend you go for the mini.iso > I have > heard of doing testing on the lowest common denominator before though. > Unfortunately, I don't have time to set up a bare-bones VM since we're > closing soon, but I may give this a go on Friday and report back. ok - the issue that you will face if you _don't_ do a LCD test is that should ubuntu get upgraded, and one of the packages that _used_ to pull in a dependency [that you missed] no longer does so... From sjmachin at lexicon.net Thu Jan 1 08:54:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 1 Jan 2009 05:54:42 -0800 (PST) Subject: initialization in python References: Message-ID: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> On Jan 1, 11:44?pm, koranth... at gmail.com wrote: > How does an average product handle initialization in python? > I am facing lot of issues in handling initialization, especially if I > import specific variables, due to the variables not getting updated. > > For example - taking a sqlalchemy based product: > Module database: > ^^^^^^^^^^^^^^^^^^^ > Session = None > > def init(dbname): > ? ?engine = create_engine('sqlite:///%s' %dbname) > ? ?... > ? ?global Session > ? ?Session = sessionmaker(bind=engine) > > In entry module to the application (APPENTRY): > ^^^^^^^^^^^^^^^^^^^ > import A, B, C, D ?<---- Please note, very important > .... > .... > database.init('testdb.db') > > Now in user module A: > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > from database import Session > print Session > --->This will print None, because at APPENTRY, during importing A > itself, Session is stored. This is happening when you import A, which happens *before* you call database.init(). database.init binds the name database.Session to a new value. The name A.Session has been bound earlier to the value None. > I have to call database.Session to get the values. I don't understand that sentence. Is database.Session callable (i.e. is a function or class)? What valueS (plural)? > Why is the variable not getting updated? Firstly, it's not a "variable" in the sense of a named slice of memory to which various values can be assigned. Secondly, it could be updated only if the "from database import Session" operated like it was creating an alias e.g. A.Session isanaliasof database.Session like a C macro #define A_Session database_Session but it isn't; its effect is that of a fancy "assignment", more or less like: import database Session = database.Session del database In any case, mucking about with module globals like you are trying to do is not a good idea. As you have seen, it introduces dependencies like you need to import A after the database is initiated. As soon as you need more than one session at a time, or the single session needs to be closed and restarted, it really falls apart. Try passing your session around as a function arg, or as an attribute of an object that contains current state information. HTH, John From bj_666 at gmx.net Thu Jan 1 09:26:03 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 1 Jan 2009 14:26:03 GMT Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: <6s423rF44m1hU1@mid.uni-berlin.de> On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > Please let me know if you need any more information. Where does `videocapture.py` coming from? It's not part of the standard library. And which operating system are we talking about? Ciao, Marc 'BlackJack' Rintsch From david at abbottdavid.com Thu Jan 1 10:23:04 2009 From: david at abbottdavid.com (David) Date: Thu, 01 Jan 2009 10:23:04 -0500 Subject: Videocapture in python In-Reply-To: <6s423rF44m1hU1@mid.uni-berlin.de> References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: <495CDFD8.1010309@abbottdavid.com> Marc 'BlackJack' Rintsch wrote: > On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > >> Please let me know if you need any more information. > > Where does `videocapture.py` coming from? It's not part of the standard > library. And which operating system are we talking about? > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list > > Hope this is not off topic, I am new to python. I use linux and use the subprocess module, feel free to point out my noviceness; #!/usr/bin/python import subprocess def take_shot_func(): streamer = "/usr/bin/streamer" s_arg1 = "-c" s_device = "/dev/video0" s_arg2 = "-b" s_rate = "16" s_arg3 = "-o" save_to = "/tmp/camshot.jpeg" print "Taking picture with webcam and saved to /tmp/camshot.jpeg" subprocess.call([streamer, s_arg1, s_device, s_arg2, s_rate, s_arg3, save_to]) def main(): take_shot_func() if __name__ == "__main__": main() -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From koranthala at gmail.com Thu Jan 1 10:35:11 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 07:35:11 -0800 (PST) Subject: initialization in python References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: On Jan 1, 6:54?pm, John Machin wrote: > On Jan 1, 11:44?pm, koranth... at gmail.com wrote: > > > > > How does an average product handle initialization in python? > > I am facing lot of issues in handling initialization, especially if I > > import specific variables, due to the variables not getting updated. > > > For example - taking a sqlalchemy based product: > > Module database: > > ^^^^^^^^^^^^^^^^^^^ > > Session = None > > > def init(dbname): > > ? ?engine = create_engine('sqlite:///%s' %dbname) > > ? ?... > > ? ?global Session > > ? ?Session = sessionmaker(bind=engine) > > > In entry module to the application (APPENTRY): > > ^^^^^^^^^^^^^^^^^^^ > > import A, B, C, D ?<---- Please note, very important > > .... > > .... > > database.init('testdb.db') > > > Now in user module A: > > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > > from database import Session > > print Session > > --->This will print None, because at APPENTRY, during importing A > > itself, Session is stored. > > This is happening when you import A, which happens *before* you call > database.init(). database.init binds the name database.Session to a > new value. The name A.Session has been bound earlier to the value > None. > > > I have to call database.Session to get the values. > > I don't understand that sentence. Is database.Session callable (i.e. > is a function or class)? What valueS (plural)? > > > Why is the variable not getting updated? > > Firstly, it's not a "variable" in the sense of a named slice of memory > to which various values can be assigned. > > Secondly, it could be updated only if the "from database import > Session" operated like it was creating an alias e.g. > ? ? A.Session isanaliasof database.Session > like a C macro > ? ? #define A_Session database_Session > but it isn't; its effect is that of a fancy "assignment", more or less > like: > ? ? import database > ? ? Session = database.Session > ? ? del database > > In any case, mucking about with module globals like you are trying to > do is not a good idea. As you have seen, it introduces dependencies > like you need to import A after the database is initiated. As soon as > you need more than one session at a time, or the single session needs > to be closed and restarted, it really falls apart. Try passing your > session around as a function arg, or as an attribute of an object that > contains current state information. > > HTH, > John > This is happening when you import A, which happens *before* you call > database.init(). database.init binds the name database.Session to a > new value. The name A.Session has been bound earlier to the value > None. I guessed as much. But, I was under the impression that if the original value is modified, the variables value also will change. > I don't understand that sentence. Is database.Session callable (i.e. > is a function or class)? What valueS (plural)? Session() here is a session manager in SQLAlchemy. database.Session() creates a new session. > import database > Session = database.Session > del database Thank you. This answers my query. > In any case, mucking about with module globals like you are trying to > do is not a good idea. As you have seen, it introduces dependencies I avoid global variables as much as possible. But SQLAlchemy tutorial recommends this method of assignment. So, I was using this. Anyways, I now use database.Session always, and these dependencies are no longer there. From koranthala at gmail.com Thu Jan 1 10:40:41 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 07:40:41 -0800 (PST) Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: On Jan 1, 7:26?pm, Marc 'BlackJack' Rintsch wrote: > On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > > Please let me know if you need any more information. > > Where does `videocapture.py` coming from? ?It's not part of the standard > library. ?And which operating system are we talking about? > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch Hi Marc, It is not part of standard library. Sorry for me being very brief earlier. It is taken from http://videocapture.sourceforge.net/, - a very good tool for webcam capture in Win32. Hi David, I am in Windows. And there is a possibility that I might be using device 0 or 1. So, I am using the excellent VideoCapture tool created by Markus Gritsch. From Ron.Barak at lsi.com Thu Jan 1 11:19:03 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 1 Jan 2009 16:19:03 +0000 Subject: How to find the beginning of last line of a big text file ? Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Hi, I have a very big text file: I need to find the place where the last line begins (namely, the offset of the one-before-the-last '\n' + 1). Could you suggest a way to do that without getting all the file into memory (as I said, it's a big file), or heaving to readline() all lines (ditto) ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyosohma at gmail.com Thu Jan 1 11:36:14 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:36:14 -0800 (PST) Subject: Iowa Python Users Group Meeting (Jan. 5, 2008) Message-ID: Hi, The next Iowa Python Users Group meeting is Monday, January 5th, 2008, barring bad weather. We will be meeting from 7-9 p.m. at the following location: Marshall County Sheriff's Office 2369 Jessup Ave Marshalltown, IA 50158 Currently we have one tentative speaker scheduled and a workshop planned. If you don't have a laptop, let me know. We can provide a few for the workshop but we need to know ahead of time. Also let us know if you do plan to come so we know how many to expect. Email me off- list so we don't annoy the other people on this list. Our group is for both experience and new programmers. All experience levels are welcome. We hope to see you there! If you have any questions, just let me know. Mike Driscoll www.pyowa.org From kyosohma at gmail.com Thu Jan 1 11:38:39 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:38:39 -0800 (PST) Subject: Iowa Python Users Group Meeting (Jan. 5, 2008) References: Message-ID: <8c34ea80-2914-43dc-bf9d-a445439bfc6e@w39g2000prb.googlegroups.com> On Jan 1, 10:36?am, Mike Driscoll wrote: > Hi, > > The next Iowa Python Users Group meeting is Monday, January 5th, 2008, > barring bad weather. We will be meeting from 7-9 p.m. at the following > location: > > Marshall County Sheriff's Office > 2369 Jessup Ave > Marshalltown, IA 50158 > > Currently we have one tentative speaker scheduled and a workshop > planned. If you don't have a laptop, let me know. We can provide a few > for the workshop but we need to know ahead of time. Also let us know > if you do plan to come so we know how many to expect. Email me off- > list so we don't annoy the other people on this list. > > Our group is for both experience and new programmers. All experience > levels are welcome. We hope to see you there! If you have any > questions, just let me know. > > Mike Driscollwww.pyowa.org Looks like I am still getting over the lack of sleep from New Years. The date should be 2009, not 2008. Sorry about that. Mike From kyosohma at gmail.com Thu Jan 1 11:44:26 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:44:26 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> Message-ID: <05e462b7-cfab-4f37-b545-bdff51f0e684@a12g2000pro.googlegroups.com> On Jan 1, 7:47?am, lkcl wrote: > On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > > > On Dec 31, 3:36 pm,lkcl wrote: > > > > hiya mike: where do i know you from? ?i've heard your name somewhere > > > and for the life of me can't remember where! ?anyway... onwards. > > > I don't know...while your username looks vaguely familiar, I don't > > think I've communicated with you recently. I spend most of my time on > > the wxPython list now... > > ?i think it might be from my old school - i could be confusing you > with > ?someone, though - "gary driscoll", perhaps? anyway, never mind :) > > > > testing: you should really use a debootstrap absolute "basic" > > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > > whatever). > > > I thought the general practice was to test on the closest software/ > > hardware combo that your application was most likely to run on. > > ?that you should do as well :) ?you should be able to either upgrade > ?the bare-bones version using "tasksel install desktop" or just... > ?what-the-heck, install on a vanilla combo. > > ?http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/c... > > ?archive.ubuntu.com appears offline at the moment - maybe it'll be > back later. ?i recommend you go for the mini.iso > Ok...thanks for the info! > > I have > > heard of doing testing on the lowest common denominator before though. > > Unfortunately, I don't have time to set up a bare-bones VM since we're > > closing soon, but I may give this a go on Friday and report back. > > ?ok - the issue that you will face if you _don't_ do a LCD test is > that > ?should ubuntu get upgraded, and one of the packages that _used_ to > pull > ?in a dependency [that you missed] no longer does so... I see. I had hoped that there was a way to create a frozen application like I do with py2exe on Windows so I wouldn't have to worry about a Linux upgrade breaking my application. I've been told that PyInstaller might do the trick too. Either way, I'll post the solution that works for me. Happy New Year! Mike From thorsten at thorstenkampe.de Thu Jan 1 11:50:39 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 1 Jan 2009 17:50:39 +0100 Subject: Desktop/File management support on MS Windows References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> Message-ID: * riklaunim at gmail.com (Wed, 31 Dec 2008 09:08:46 -0800 (PST))> > Are there any Python libraries that can trash files (move to Trash, > not delete) or for example return a list of applications that can open > given file? I can't find anything related to this for Windows. http://timgolden.me.uk/python/winshell.html Thorsten From sbassi at clubdelarazon.org Thu Jan 1 11:54:44 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Thu, 1 Jan 2009 14:54:44 -0200 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Message-ID: <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: > I have a very big text file: I need to find the place where the last line > begins (namely, the offset of the one-before-the-last '\n' + 1). > Could you suggest a way to do that without getting all the file into memory > (as I said, it's a big file), or heaving to readline() all lines (ditto) ? for line in open(filename): lastline = line print "the lastline is: %s",%lastline This will read all the lines, but line by line, so you will never have the whole file in memory. There may be more eficient ways to do this, like using the itertools. Best, SB. From kentilton at gmail.com Thu Jan 1 12:24:16 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Thu, 01 Jan 2009 12:24:16 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: <495cfcd2$0$4889$607ed4bc@cv.net> sln at netherlands.com wrote: > On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: > >> Xah Lee wrote: >>> Just spent 3 hours looking into Ruby today. Here's my short impression >>> for those interested. >>> >>> * Why Not Ruby? >>> http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html >>> >>> plain text version follows: >>> -------------------------------------- >>> >>> Why Not Ruby? >>> >>> Xah Lee, 2008-12-31 >>> >>> Spent about 3 hours looking into Ruby language today. >>> >>> The articles i read in detail are: >>> >>> * Wikipedia: Ruby (programming language)?J. Gives general overview. >>> >>> * Brief tutorial: "Ruby in Twenty Minutes" >>> http://www.ruby-lang.org/en/documentation/quickstart/ >>> >>> * Personal blog by Stevey Yegge, published in 2004-10. >>> http://steve.yegge.googlepages.com/ruby-tour >>> >>> The Wikipedia gives the best intro and overview in proper context. The >>> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete >>> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't >>> teach much and rambles, but provide a little personal view. I read it >>> because his opinions i respect. >>> >>> Q: Will you learn Ruby? >>> >>> No. For practical application, the lang is some 100 times less useful >>> than each of Perl, Python, PHP, Javascript. For academic study, >>> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far >>> more interesting and powerful in almost all aspects. Further, there's >>> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or >>> power, these modern lang of the past 5 years matches or exceed Ruby. >>> >>> Q: Do you think Ruby lang is elegant? >>> >>> Yes. In my opinion, better than Perl, Python, PHP. As a high level >>> lang, it's far better than Java, C, C++ type of shit. However, i don't >>> think it is any better than emacs lisp, Scheme lisp, javascript, >>> Mathematica. Note that Ruby doesn't have a spec, and nor a formal >>> spec. Javascript has. Ruby's syntax isn't that regular, nor is it >>> based on a system. Mathemtica's is. Ruby's power is probably less than >>> Scheme, and probably same as Javascript. >>> >>> I also didn't like the fact that ruby uses keyword "end" to indicate >>> code block much as Pascal and Visual Basic, Logo, do. I don't like >>> that. >>> >>> Q: Won't Ruby be a interesting learning experience? >>> >>> No. As far as semantics goes, Ruby is basically identical to Perl, >>> Python, PHP. I am a expert in Perl and PHP, and have working knowledge >>> of Python. I already regretted having spent significant amount of time >>> (roughly over a year) on Python. In retrospect, i didn't consider the >>> time invested in Python worthwhile. (as it turns out, i don't like >>> Python and Guido cult, as the lang is going the ways of OOP mumbo- >>> jumbo with its Python 3 "brand new" future.) There is absolutely >>> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp, >>> Scheme lisp. >>> >>> Q: Do you recommend new programers to learn Ruby then? >>> >>> Not particularly. As i mentioned, if you are interested in practical >>> utility, there's already Perl, PHP, Python, Javascript, which are all >>> heavily used in the computing industry. If you are interested as a >>> academic exercise, there's Scheme lisp, and much of functional langs >>> such as OCaml, Haskell, Mathematica, which will teach you a whole lot >>> more about computer science, features of language semantics, etc. >>> >>> Q: Do you condemn Ruby? >>> >>> No. I think it's reasonably elegant, but today there are too many >>> languages, so Ruby don't particularly standout for me. Many of them, >>> are arguably quite more elegant and powerful than Ruby. See: >>> Proliferation of Computing Languages. >>> >> Kenny Tilton, 2008-12-31 >> >> Q: Why not Xah's review of Ruby? >> >>>> Spent about 3 hours looking into Ruby language today. >> A. Three hours? I've had belches that lasted longer than that. Of >> course, a true master can tell a lot in just a few hours of coding with >> a new language... >> >>>> The articles i read in detail are: >> Q: Read?! >> >> A: That's what he said. >> >> >> hth,kzo > > Be carefull what you say. If they pay me I would rip your and Xah's > guts out in a second. Sorry, my new President has banned drama so I will only be responding pleasantly to civil comments. (This has been a non-responding response.) Peace,k From google at mrabarnett.plus.com Thu Jan 1 12:31:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jan 2009 17:31:06 +0000 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Message-ID: <495CFDDA.7000507@mrabarnett.plus.com> Barak, Ron wrote: > Hi, > > I have a _very_ big text file: I need to find the place where the last > line begins (namely, the offset of the one-before-the-last '\n' + 1). > > Could you suggest a way to do that without getting all the file into > memory (as I said, it's a big file), or heaving to readline() all lines > (ditto) ? > You could seek() to near the end of the file before reading lines with readline(). Remember that the seek will almost certainly put the file pointer somewhere in the middle of a line, but that doesn't matter provided that it's not the last line (ie if the second readline() returns "" then the first readline() started somewhere in middle of the last line of the file). If you find that the seek put the file pointer somewhere in the middle of the last line, then try again, but this time seeking further back from the end of file before reading. Repeat as necessary. From sthalik at test123.ltd.pl Thu Jan 1 12:34:51 2009 From: sthalik at test123.ltd.pl (=?UTF-8?Q?Stanis=C5=82aw?= Halik) Date: Thu, 1 Jan 2009 17:34:51 +0000 (UTC) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: In comp.lang.lisp r wrote: > Face it, the world needs people like Xah. Go check out his site, his > insights of languages and tech is fascinating. The man lives in a > world driven by common sense, and you know what they say --"Common > sense is the least most common thing"-- just look around at the > responses here. Might hold true for some rants, but most of it's tl;dr drivel. For instance, his critique of Lisp's homoiconicity is completely off-target. > I come from a different world than IT, and I thought initially the IT > world would be filled with intelligent, free thinking, and open minded > people... BOY was i wrong! I would not turn my back on these people > for a second, lest you catch a knife in it! So-called "IT" is driven by capitalistic impulses. Dijkstra and his followers get dismissed as ivory tower intellectuals. FUT warning. -- You only have power over people so long as you don?t take everything away from them. But when you?ve robbed a man of everything he?s no longer in your power ? he?s free again. -- Aleksandr Isayevich Solzhenitsyn From rt8396 at gmail.com Thu Jan 1 12:50:57 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 09:50:57 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <39d1883d-fb26-41cd-8de3-9185760445f7@f13g2000yqj.googlegroups.com> On Jan 1, 2:05?am, Jason Rumney wrote: > On Jan 1, 3:12?pm, r wrote: > > > The man lives in a world driven by common sense > > "Common" sense suggests that his views are shared among the general > populace. I don't see much evidence of that in the sometimes never- > ending threads that frequently follow his postings. But it is good to > start debates about making changes to the status quo, often the > debates will result in worthwhile changes, even if those changes are > not what he proposed. I just wish he would choose his venue a little > more carefully sometimes. I think if you will consider society as a whole, you will see that most people don't display much sense at all. "Joe Blow" only cares about paris hilton, britney spears, or janet jackson wardrobe malfunctions. The only thing they contribute to society is human excrement. So --"Common sense is the least most common thing"-- really means there exists no sense as a commonality. This can apply to higher educated people too, even Guido. Go and read Xahs take on the Python official tutorial, you will find your self agreeing with everything that he says. Guido filled it with so much fluff and off topic BS, causing the learning process to shut down. The only kind of person that might find it enjoying would be a fellow Computer Science Graduate. I did not know it at the time but this contributed to my late understanding of classes and regexes. And being such a fanboy of Python and carrying such a high respect for Guido that is hard for me to say, BUT it is the TRUTH nonetheless. Guido has no business writing tutorials anymore, WHY you ask. Because he is too smart, and too much on the inside. He cannot relate to the n00b pythoneer, he has crossed the Rubicon. Less fluff more simple examples are the key to quick learning. My love for python has blinded me to some of the atrocities that exist here. I have many more examples from the Official-TUT than Xah covered. Don't take my word, judge for yourself... http://xahlee.org/perl-python/xlali_skami_cukta.html here is Xah's take on OOP, very good reading for beginners and Gurus... http://xahlee.org/Periodic_dosage_dir/t2/oop.html If all Xah did was come here and say "Hey, python sucks donkey dicks!", i would pay him no mind. But he brings much intelligence, and vigor to an otherwise boring, and sometimes mindless newsgroup. What i like about him is his out-side-the-box thinking style. He does not give in to this BS "Proper Society" wants to push onto us. He is a real rebel, but WITH a cause! And the cause is to bring common sense back to a world of fluff an BS jargonisms. I don't always agree with his thoughts, but most the time he's spot on. Open your min c.l.py. Lest it close forever. eliminate the life decline... its time to change... can't stay the same... Revolution is my name! -Phil Anselmo- From wicijowski at gmail.com Thu Jan 1 12:52:45 2009 From: wicijowski at gmail.com (janislaw) Date: Thu, 1 Jan 2009 09:52:45 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <9b40ed7a-cfde-4c00-8685-913c1a3889f9@r15g2000prd.googlegroups.com> On 1 Sty, 12:37, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. If I were to write a python game that ran in a _browser_ I'd go for jython applet. JW From tjreedy at udel.edu Thu Jan 1 13:01:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jan 2009 13:01:03 -0500 Subject: Videocapture in python In-Reply-To: References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: koranthala at gmail.com wrote: > It is taken from http://videocapture.sourceforge.net/, - a very > good tool for webcam capture in Win32. > Hi David, > I am in Windows. And there is a possibility that I might be using > device 0 or 1. So, I am using the excellent VideoCapture tool created > by Markus Gritsch. Does the capture software require 2.4? Given " I actually would like to have the code as try: obj.img = cam.getImage(timestamp=3) except CamException: setup_cam() But, since no exception is provided, " I do not think the tool is so excellent. It should either return a picture or raise and exception. Request that of the author. From gliderman at none Thu Jan 1 13:01:48 2009 From: gliderman at none (gliderman) Date: Thu, 01 Jan 2009 19:01:48 +0100 Subject: python and gloox Message-ID: <495d04f4$0$19294$426a34cc@news.free.fr> Hi I am trying to use a python version of gloox (XMPP client library written in C++). The python binding is done using SWIG (provided by the author of gloox). I am trying to adapt first a c++ example to python. The code below fails with Traceback (most recent call last): File "tutu.py", line 54, in ? t.run() File "tutu.py", line 28, in run self.f = gloox.SIProfileFT( self.c, self ) File "/home/karim/boulot/gliders/archi/project//lib/python2.4/site-packages/gloox/gloox.py", line 1965, in __init__ this = _gloox.new_SIProfileFT(*args) NotImplementedError: Wrong number of arguments for overloaded function 'new_SIProfileFT'. Possible C/C++ prototypes are: gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *,gloox::SIManager *,gloox::SOCKS5BytestreamManager *) gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *,gloox::SIManager *) gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *) If I comment gloox.LogHandler.__init__( self ) (and self.c.logInstance().registerLogHandler( gloox....), it "works". The order to initialize the objects seems to be important. The error can differ with the order of __init__ . Moreover when I replace C++ : m_s5b->registerSOCKS5BytestreamDataHandler( this ); by its python version: self.m_s5b.registerSOCKS5BytestreamDataHandler(self) a pointer object in m_s5b is always null (it shouldnt). There is no constructor in c++ classes SIProfileFTHandler,LogHandler,ConnectionListener, SOCKS5BytestreamDataHandler (almost pure virtual). import gloox import sys import os class MyClient( gloox.SIProfileFTHandler,gloox.LogHandler,gloox.ConnectionListener,gloox.SOCKS5BytestreamDataHandler): def __init__( self ): gloox.ConnectionListener.__init__( self ) gloox.SOCKS5BytestreamDataHandler.__init__( self ) gloox.SIProfileFTHandler.__init__( self ) gloox.LogHandler.__init__( self ) self.j = gloox.JID( "test at localhost/yop" ) self.c = gloox.Client( self.j, 'test' ) self.f=None def run(self): self.c.registerConnectionListener(self ) self.c.logInstance().registerLogHandler( gloox.LogLevelDebug, gloox.LogAreaAll,self) m_server=gloox.SOCKS5BytestreamServer( self.c.logInstance(), 6666 ) le = m_server.listen() if le != gloox.ConnNoError: print( "listen returned: %d\n"% le) print( "listening\n" ) self.f = gloox.SIProfileFT( self.c, self ) self.f.registerSOCKS5BytestreamServer( m_server ) self.f.addStreamHost( gloox.JID("jabberd"), "127.0.0.1", 7777 ); b = self.c.connect( False ) if b: print 'successfully connected' ce = gloox.ConnNoError while ce == gloox.ConnNoError: ce = self.c.recv( 1 ) return def handleLog(self,level,area,message): print("log: level: %d, area: %d, %s\n", level, area, message ) def onConnect(self): print( "connected!!!\n" ) def onDisconnect(self, e ): print( "ft_send: disconnected: %d\n"% e ) if e == gloox.ConnAuthenticationFailed : print( "auth failed. reason: %d\n"% c.authError() ) ########################################################### t = MyClient() t.run() Thanks for any hint (and happy new year !) Karim From python.list at tim.thechases.com Thu Jan 1 13:03:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 01 Jan 2009 12:03:46 -0600 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> Message-ID: <495D0582.4010002@tim.thechases.com> Sebastian Bassi wrote: > On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: >> I have a very big text file: I need to find the place where the last line >> begins (namely, the offset of the one-before-the-last '\n' + 1). >> Could you suggest a way to do that without getting all the file into memory >> (as I said, it's a big file), or heaving to readline() all lines (ditto) ? > > for line in open(filename): > lastline = line > print "the lastline is: %s",%lastline > > This will read all the lines, but line by line, so you will never have > the whole file in memory. > There may be more eficient ways to do this, like using the itertools. I think the OP wanted to do it without having to touch each line in the file. The following should do the trick, returning both the offset in the file, and that last line's content. from os import stat def last_line(fname, estimated_line_size=1024): assert estimated_line_size > 0 file_size = stat(fname).st_size if not file_size: return 0, "" f = file(fname, 'rb') f.seek(-1, 2) # grab the last character if f.read(1) == '\n': # a "proper" text file file_size -= 1 offset = file_size content = "" while offset >= 0 and '\n' not in content: offset -= estimated_line_size if offset < 0: estimated_line_size += offset # back it off offset = 0 f.seek(offset) block = f.read(estimated_line_size) content = block + content f.close() loc = content.rfind('\n') + 1 # after the newline return offset + loc, content[loc:] offset, line = last_line('some_file.txt') print "[%r] was found at offset %i" % (line, offset) In theory, it should even handle "malformed" text-files that don't end in a newline. There might be some odd edge-cases that I missed, but I think I caught most of them. -tkc From geert.discussions at gmail.com Thu Jan 1 13:05:29 2009 From: geert.discussions at gmail.com (Geert Vancompernolle) Date: Thu, 01 Jan 2009 19:05:29 +0100 Subject: How to run Python in Windows w/o popping a DOS box? Message-ID: <495D05E9.4000004@gmail.com> I know it's been a long while since this thread has been handled, but maybe this is a "final" solution to your problem (if not yet resolved): http://www.py2exe.org/index.cgi/SingleFileExecutable Especially the last setup.py file results in only one exe which contains *all* the necessary stuff (only tested it on small examples, though) Maybe you can give this a try... Best rgds, --Geert * * From mmanns at gmx.net Thu Jan 1 13:12:26 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Thu, 1 Jan 2009 19:12:26 +0100 Subject: Testing if an index is in a slice Message-ID: <20090101191226.5137adb6@Schlamber.localdomain> Hi I would like to check if an index is in a slice or not without iterating over the slice. Something like: >>> isinslice(36, slice(None, 34, -1)) True I would like to use the batteries if possible. However, I looked in the docs, pypi and in Usenet without luck. Does anyone have a solution? Martin From davidalvi at gmail.com Thu Jan 1 13:13:07 2009 From: davidalvi at gmail.com (davidalvi at gmail.com) Date: Thu, 1 Jan 2009 10:13:07 -0800 (PST) Subject: Is this a bug in Python or something I do not understand. Message-ID: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Consider these two lists comprehensions: L1=[[1 for j in range(3)] for i in range(3)] L2=[[1]*3]*3 print L1 print L2 print L1==L2 The result is: [[1, 1, 1], [1, 1, 1], [1, 1, 1]] [[1, 1, 1], [1, 1, 1], [1, 1, 1]] True So far, everything is OK, but let us now modify the lists' contents in the following way: for i in range(3): for j in range(3): if j References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: koranthala at gmail.com wrote: >>> Module database: >>> ^^^^^^^^^^^^^^^^^^^ >>> Session = None 'Initializing' names is not necessary. Delete this. Without it, your error would be more obvious. >>> def init(dbname): >>> engine = create_engine('sqlite:///%s' %dbname) >>> ... >>> global Session >>> Session = sessionmaker(bind=engine) This **rebinds* the module name 'Session' to a new object, making the initial bindin irrelevant and misleading. [snip] > > I guessed as much. But, I was under the impression that if the > original value is modified, the variables value also will change. Python has names and slots bound to objects. Some objects are mutable and some not. None is not mutable. You replaced it. If you had done something like Session = sessionmaker() def init(dbname): Session.engine = create_engine('sqlite:///%s' %dbname) ... then you would have *modified* the original object (value) bound to 'Session' and would have seen the behavior you expected. Terry Jan Reedy From mmanns at gmx.net Thu Jan 1 13:15:00 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Thu, 1 Jan 2009 19:15:00 +0100 Subject: Testing if an index is in a slice Message-ID: <20090101191500.27ca3cce@Schlamber.localdomain> Hi I would like to check if an index is in a slice or not without iterating over the slice. Something like: >>> isinslice(36, slice(None, 34, -1)) True I would like to use the batteries if possible. However, I looked in the docs, pypi and in Usenet without luck. Does anyone have a solution? Martin From jurgenex at hotmail.com Thu Jan 1 13:17:54 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 10:17:54 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: r wrote: [Why not Ruby?] Becasue it is off topic in CL.perl.M just as in any other NG he posted to. >Face it, the world needs people like Xah. Go check out his site, his Oh my good, the idiot discovered alter egos. >There is nothing wrong with a person expressing their opinion on any >subject. Apparently some of you need to get laid and calm down a >little. Xah has just as much right as anyone here to post his >thoughts, even if they are off topic. Exactly everyone's point. He has exactly the same right as anybody else which is exactly that NOBODY has the "right" to post off topic posts. Sometimes they may be tolerated, on rare, special occasions even be welcome. But by and large they are as disturbing as playing 'Love me tender' during a perfomance of the Walkuere. I don't want to hear Elvis, I paid my money for Wagner! If I wanted to listen to Elvis, then I would go to an Elvis concert. >Look, if you don't like what he >is saying, DON'T F'IN READ IT! He has been plonked a loooooooong time ago. It's just he newcomers, who still respond to him. And no his alter ego with the unpronouncable name of rt8396. >Xah, I been watching your posts for sometime and it looks like you >have been around for a while. Your profile shows one star & 410 >ratings. I have only been in usenet for 2 month and i have one star >and 253 ratings(that will grow to much more after this post), most are There are neither profiles nor stars or ratings on Usenet. Keep you made-up nonsense to yourself. jue From semanticist at gmail.com Thu Jan 1 13:20:51 2009 From: semanticist at gmail.com (Miles) Date: Thu, 1 Jan 2009 13:20:51 -0500 Subject: Is this a bug in Python or something I do not understand. In-Reply-To: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 1:13 PM, wrote: > Consider these two lists comprehensions: > > L1=[[1 for j in range(3)] for i in range(3)] > L2=[[1]*3]*3 > [snip] > > It seems a misbehaviour in Python, or there is something I do not > understand in the syntax ???? It's not a Python bug. Does this help illuminate the difference? >>> L1 = [object() for j in range(3)] >>> L2 = [object()] * 3 >>> [id(o) for o in L1] [164968, 164976, 164984] >>> L1[0] is L1[1] False >>> [id(o) for o in L2] [164992, 164992, 164992] >>> L2[0] is L2[1] True -Miles From tjreedy at udel.edu Thu Jan 1 13:22:34 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jan 2009 13:22:34 -0500 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: alex goretoy wrote: > I recently conquered this pass by ref thing. This is how I did it. What you did was to pass a mutable object and mutate it. Absolutely standard practice in Python. I am glad you learned it, but also learning and using the standard terminology will also help. Hope you enjoy Python too. tjr From rt8396 at gmail.com Thu Jan 1 13:35:54 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 10:35:54 -0800 (PST) Subject: Why not Ruby? References: Message-ID: Xah Lee, > I also didn't like the fact that ruby uses keyword "end" to indicate > code block much as Pascal and Visual Basic, Logo, do. I don't like > that. You could not be more right Xah, the use of "end" in a language as high level as Ruby is redundant, and idiotic. There are a few things about Ruby i really like, but this "end" business is blasphemy. If ruby did not use indentation, i would see the need for "end", or braces, or whatever, but why use both indentation AND the "end" word? Such stupidity. I guess Mats thought Ruby would look too much like Python, ARE YOU KIDDING MATS?, you already took so much from Python anyway, dropping the end statement won't change that. And heck, you will gain many new users with out it's archaic redundancy!!!! I must say at first i did not like the each method but it has grow on me because of its space saving attributes. There are also some nice shortcuts in Ruby that do not exist in Python. I am beginning to think the perfect high level language would take the best for Ruby and Python. The ultimate language with speed in mind, pythons clear syntax, but with shortcuts for gurus. I would probably lean more towards python scoping and classes than ruby, but python classes need a little less redundancy also. Of course pythons list, dict, strings in my opinion just can't be beat, and regex forget-a-about-it! Python rules here. Even though Ruby has built in support, python's is much more elegant. I really like pythons handling of modules and module.class.method syntax. Both languages have much to offer, i believe though Python has a better base, it just needs some cleaning up, and shortcut syntax so moderate/Gurus don't develop carpal tunnel too early :) From geert.discussions at gmail.com Thu Jan 1 13:45:55 2009 From: geert.discussions at gmail.com (GeertVc) Date: Thu, 1 Jan 2009 10:45:55 -0800 (PST) Subject: How to run Python in Windows w/o popping a DOS box? References: Message-ID: <34e493fd-3a2a-49df-8b82-74f87c46cf9b@r36g2000prf.googlegroups.com> On Jan 1, 7:05?pm, Geert Vancompernolle wrote: > I know it's been a long while since this thread has been handled, but > maybe this is a "final" solution to your problem (if not yet resolved): > > http://www.py2exe.org/index.cgi/SingleFileExecutable > > Especially the last setup.py file results in only one exe which contains > *all* the necessary stuff (only tested it on small examples, though) > > Maybe you can give this a try... > > Best rgds, > --Geert > * > * Might seem an "odd" posting at first, but I wanted to reply on a (quite) old thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/456bc00fa11f689/b4357c9aa47f04d3?lnk=gst&q=dos+box+remove I couldn't reply any more on that one, so... Best rgds, --Geert From rtomek at ceti.com.pl Thu Jan 1 14:08:34 2009 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Thu, 1 Jan 2009 20:08:34 +0100 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: On Thu, 1 Jan 2009, sln at netherlands.com wrote: > On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: > > >Xah Lee wrote: > >> Just spent 3 hours looking into Ruby today. Here's my short impression > >> for those interested. > >> > > Be carefull what you say. If they pay me I would rip your and Xah's > guts out in a second. > > sln Too much champagne? A guy (XL) is sometimes off topic and I don't always agree with his postings - if I find the subject somewhat worthy, I usually skim through it, this is how I have found myself knee deep in this strange exchange between XL's supporters and opponents. And his website is big like a magazine and full of strange, sometimes not interesting or hard to assess stuff (it needs time to read and time is hard to find nowadays). But sometimes, what he writes is informative, too. A bit redundant but still, I would give him a small "plus", rather than "zero" or "minus". But I do not remember him being blunt or agressive. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From metolone+gmane at gmail.com Thu Jan 1 14:12:44 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 1 Jan 2009 11:12:44 -0800 Subject: idle 3.0 unicode References: <495C7AC6.1000506@post.cz> Message-ID: "Pavel Kosina" wrote in message news:495C7AC6.1000506 at post.cz... > As for unicode in Python 2.5 everything works fine in program running > either in IDLE or under Command line: > # -*- coding: utf-8 -*- > print u"?????????" > > In 3.0 there is an error. The same program, moved to 3.0 syntax, in IDLE > editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program running in Command line from PSPad editor works fine. Is > it mistake of my misunderstanding or of IDLE? > > ------------- > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. Both versions, with and without 'coding' line, destroy IDLE for me. Looks like a bug in IDLE 3.0. The print works fine from the shell, but not from a program run with F5. -Mark From ajaksu at gmail.com Thu Jan 1 14:34:53 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 1 Jan 2009 11:34:53 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 1, 4:12?pm, mma... at gmx.net wrote: > I would like to check if an index is in a slice or not without > iterating over the slice. > > Something like: > > >>> isinslice(36, slice(None, 34, -1)) > > True I think it'd be feasible for slices that can be mapped to ranges[1], but slices are more flexible than that. What would the answer be for: >>> isinslice(36, slice(0, -1, 1)) ? This shows the issue: >>> sli = slice(0, -1, 1) >>> range(4)[sli] [0, 1, 2] >>> range(10)[sli] [0, 1, 2, 3, 4, 5, 6, 7, 8] HTH, Daniel [1] http://article.gmane.org/gmane.comp.python.python-3000.devel/8732 From kay.schluehr at gmx.net Thu Jan 1 14:37:44 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 1 Jan 2009 11:37:44 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: On 1 Jan., 12:37, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. There is no solution to this problem from a Python perspective. Do what everyone does right now: use Flash for the game and manage your site with Python if you like the language. From excord80 at gmail.com Thu Jan 1 15:24:38 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 12:24:38 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> On Jan 1, 2:37?pm, Kay Schluehr wrote: > There is no solution to this problem from a Python perspective. Do > what everyone does right now: [snip] It still surprises me that no one has implemented the solution for this yet. Maybe it's harder than it seems, but it *seeems* like it's just a matter of telling Firefox, "hey, when you see this special html element that tells you to run this python code from the web, do it". Then have FF load up a python interpreter, sandbox it somehow (that is, limit it to only a safe subset of its std lib), it runs the code within its region of the browser window, and Bob's your uncle. People would go bonkers for that. From excord80 at gmail.com Thu Jan 1 15:29:33 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 12:29:33 -0800 (PST) Subject: Chart libs for python References: <4a8c13a2-a2ae-4815-9560-8e1ef1e21f97@i24g2000prf.googlegroups.com> Message-ID: <5d0f7788-2a28-4eb0-bb2a-22371ac7b236@m2g2000vbp.googlegroups.com> You might start by having a look at the wiki: http://wiki.python.org/moin/NumericAndScientific/Plotting From darcy at PyGreSQL.org Thu Jan 1 15:29:37 2009 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Thu, 1 Jan 2009 15:29:37 -0500 Subject: Release of PyGreSQL 4.0 Message-ID: <20090101152937.bf8ca6c3.darcy@PyGreSQL.org> We are please to announce the release of PyGreSQL 4.0. his is a major release and you should check it carefully before using in existing applications. There may be some incompatibilities. PyGreSQL is a Python module that interfaces to a PostgreSQL database. It embeds the PostgreSQL query library to allow easy use of the powerful PostgreSQL features from a Python script. For more information, please visit http://www.PyGreSQL.org/. >From the changelog: - Dropped support for Python below 2.3 and PostgreSQL below 7.4. - Improved performance of fetchall() for large result sets by speeding up the type casts (as suggested by Peter Schuller). - Exposed exceptions as attributes of the connection object. - Exposed connection as attribute of the cursor object. - Cursors now support the iteration protocol. - Added new method to get parameter settings. - Added customizable row_factory as suggested by Simon Pamies. - Separated between mandatory and additional type objects. - Added keyword args to insert, update and delete methods. - Added exception handling for direct copy. - Release the GIL while making a connection (as suggested by Peter Schuller). - If available, use decimal.Decimal for numeric types. - Allow DB wrapper to be used with DB-API 2 connections (as suggested by Chris Hilton). - Made private attributes of DB wrapper accessible. - Dropped dependence on mx.DateTime module. - Support for PQescapeStringConn() and PQescapeByteaConn(); these are now also used by the internal _quote() functions. - Added 'int8' to INTEGER types. New SMALLINT type. - Added a way to find the number of rows affected by a query() with the classic pg module by returning it as a string. For single inserts, query() still returns the oid as an integer. The pgdb module already provides the "rowcount" cursor attribute for the same purpose. - Improved getnotify() by calling PQconsumeInput() instead of submitting an empty command. - Removed compatibility code for old OID munging style. - The insert() and update() methods now use the "returning" clause if possible to get all changed values, and they also check in advance whether a subsequent select is possible, so that ongoing transactions won't break if there is no select privilege. - Added "protocol_version" and "server_version" attributes. - Revived the "user" attribute. - The pg module now works correctly with composite primary keys; these are represented as frozensets. - Removed the undocumented and actually unnecessary "view" parameter from the get() method. - get() raises a nicer ProgrammingError instead of a KeyError if no primary key was found. - delete() now also works based on the primary key if no oid available and returns whether the row existed or not. -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org From http Thu Jan 1 15:32:53 2009 From: http (Paul Rubin) Date: 01 Jan 2009 12:32:53 -0800 Subject: Why not Ruby? References: Message-ID: <7xr63m3gy2.fsf@ruckus.brouhaha.com> r writes: > I am beginning to think > the perfect high level language would take the best for Ruby and > Python. The ultimate language with speed in mind, pythons clear > syntax, but with shortcuts for gurus. You might like Tim Sweeney's POPL talk: http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf > Of course pythons list, dict, strings in my opinion just can't be beat, On many occasions I've wished for a functional dictionary implementation in Python, like Haskell's Data.Map. One of these years I'll get around to writing one. From clp at rebertia.com Thu Jan 1 15:55:06 2009 From: clp at rebertia.com (Chris Rebert) Date: Thu, 1 Jan 2009 12:55:06 -0800 Subject: If your were going to program a game... In-Reply-To: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <47c890dc0901011255s1b9ed128kcaada3de6f16be1@mail.gmail.com> On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > On Jan 1, 2:37 pm, Kay Schluehr wrote: > >> There is no solution to this problem from a Python perspective. Do >> what everyone does right now: [snip] > > It still surprises me that no one has implemented the solution for > this yet. > > Maybe it's harder than it seems, but it *seeems* like it's just a > matter of telling Firefox, "hey, when you see this special html > element that tells you to run this python code from the web, do it". > Then have FF load up a python interpreter, sandbox it somehow (that > is, limit it to only a safe subset of its std lib), it runs the code The "sandbox it somehow" part is significantly harder than you seem to believe it would be. Python tried previously with the rexec and Bastion modules, but they were found to be irreparably flawed and thus were removed. However, Google App Engine seems to have found at least a partial solution, but they're keeping it to themselves as far as I know, and it's server-side rather than client-side anyway. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From clp at rebertia.com Thu Jan 1 16:00:25 2009 From: clp at rebertia.com (Chris Rebert) Date: Thu, 1 Jan 2009 13:00:25 -0800 Subject: Is this a bug in Python or something I do not understand. In-Reply-To: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: <47c890dc0901011300i309055abn6607dc1c626da0a@mail.gmail.com> On Thu, Jan 1, 2009 at 10:13 AM, wrote: > Consider these two lists comprehensions: > > L1=[[1 for j in range(3)] for i in range(3)] > L2=[[1]*3]*3 > So far, everything is OK, but let us now modify the lists' contents in > the following way: > It seems a misbehaviour in Python, or there is something I do not > understand in the syntax ???? The latter, and it's a FAQ. Please read http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list (it's question 4.6). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Caseyweb at gmail.com Thu Jan 1 16:03:59 2009 From: Caseyweb at gmail.com (Casey) Date: Thu, 1 Jan 2009 13:03:59 -0800 (PST) Subject: Is this a bug in Python or something I do not understand. References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: <723622f6-d03d-4ccf-9342-bd96909b5f9b@v42g2000yqv.googlegroups.com> L1 is a list of three different lists, although each list holds the same values. L2 is a list of three references to the same list (the '*' operator doesn't do a deep copy). So when you modify any of the referenced lists, you modify all of them. Try this: >>> q = [1, 1, 1] >>> r = [q, q, q] >>> r [[1, 1, 1], [1, 1, 1], [1, 1, 1]] >>> r[0][0] = 999 >>> r [[999, 1, 1], [999, 1, 1], [999, 1, 1]] Regards, Casey From fuzzyman at gmail.com Thu Jan 1 16:13:19 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 13:13:19 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> Message-ID: <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> On Jan 1, 8:32?pm, Paul Rubin wrote: [snip...] > > Of course pythons list, dict, strings in my opinion just can't be beat, > > On many occasions I've wished for a functional dictionary > implementation in Python, like Haskell's Data.Map. ?One of these years > I'll get around to writing one. Care to save me the effort of looking it up and tell me what Data.Map does that Python's dict doesn't? I guess if it is functional then every mutation must copy and return a new data structure? (Which will be much more efficient in Haskell than in Python - Haskell can share most of the underlying data whereas Python would have to create a new dict every time. At least it only stores references.) Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Thu Jan 1 16:18:40 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 13:18:40 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <60d98b76-344e-4d94-a39c-28d06f1b46d1@35g2000pry.googlegroups.com> On Jan 1, 8:55?pm, "Chris Rebert" wrote: > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > >> There is no solution to this problem from a Python perspective. Do > >> what everyone does right now: [snip] > > > It still surprises me that no one has implemented the solution for > > this yet. > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > matter of telling Firefox, "hey, when you see this special html > > element that tells you to run this python code from the web, do it". > > Then have FF load up a python interpreter, sandbox it somehow (that > > is, limit it to only a safe subset of its std lib), it runs the code > > The "sandbox it somehow" part is significantly harder than you seem to > believe it would be. Python tried previously with the rexec and > Bastion modules, but they were found to be irreparably flawed and thus > were removed. > However, Google App Engine seems to have found at least a partial > solution, but they're keeping it to themselves as far as I know, and > it's server-side rather than client-side anyway. > PyPy allows *true* sandboxing, as does IronPython through AppDomains. I wouldn't recommend either for 'in the browser' use though. You can do client side programming in the browser with Silverlight. It's great fun to program, and very flexible, but limited to Safari, IE & Firefox on Mac and Windows. Moonlight is making good progress which will bring Silverlight to Firefox on Linux - and eventually more browsers and platforms. Michael Foord -- http://www.ironpythoninaction.com/ From castironpi at gmail.com Thu Jan 1 17:13:42 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:13:42 -0800 (PST) Subject: game engine (as in rules not graphics) References: <402f625f-b835-4cb8-bcea-523756c489ca@g39g2000pri.googlegroups.com> Message-ID: <8fc5f865-43cf-4c5c-9c8e-1d6d6b06602c@t39g2000prh.googlegroups.com> On Dec 29 2008, 8:52?am, Aaron Brady wrote: > On Dec 29, 4:14?am, Martin wrote: > > > Hi, > > > 2008/12/29 Phil Runciman : > > > > See: Chris Moss, Prolog++: The Power of Object-Oriented and Logic Programming (ISBN 0201565072) > > > > This book is a pretty handy intro to an OO version Prolog produced by Logic Programming Associates. > > > From: Aaron Brady [mailto:castiro... at gmail.com] > > > Sent: Sunday, 28 December 2008 1:22 p.m. > > > Not my expertise but here are my $0.02. ?You are looking for ways to represent rules: buying a house is legal in such and such situation, and the formula for calculating its price is something. ?You want "predicates" such as InJail, OwnedBy, Costs. > > > > Costs( New York Ave, 200 ) > > > InJail( player2 ) > > > OwnedBy( St. Charles Ave, player4 ) > > > LegalMove( rolldie ) > > > LegalMove( sellhouse ) > > > I'm not sure I'm looking for prolog, i had an introductory course back > > at the university but it didn't exactly like it. I'm after some info > > how such rules would defined in python (specifically python althou > > logic programming is probably the more appropriate way). > > > I guess I'm missing quite some basics in the design of such concepts, > > I'll head back to google to find some introductory stuff now :). > > snip > > It depends on what you want to do with it. ?Do you want to answer a > question about whether something is legal? ?Do you want a catalog of > legal moves? ?Do you want to forward-chain moves to a state? ?Do you > want just a representation for its own sake? > > For instance, the game just started. ?Player 1 landed on Oriental, > bought it, and Player 2 landed in the same place. ?Here are the legal > possibilities. > > Player 1 offers to sell Oriental to Player X. > Player X offers to buy Oriental from Player 1. > Player 1 mortgages Oriental. > Player 1 collects rent from Player 2. > Player 3 rolls dice. > > Thinking aloud, I think the closest thing to predicates you'll have in > Python is to build a Relation class or use a relational database. > Some tables you might use are: Property( id, name, price, rent0houses, > rent1house, ..., numhouses, mortgaged, owner ). ?Player( id, location, > money ). ?LastMove( player.id ). > > P.S. ?There is 'pyprolog' on sourceforge; I did not check it out. You know what I am thinking for this-- not that the OP is still around-- is a regular expression / BNF grammar that transitions on moves from one legal set of moves to the next. It will need some sort of concatenation structure, since late in the game, selling each property a player has is a legal move. Sorry for the replies to myself. From castironpi at gmail.com Thu Jan 1 17:17:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:17:40 -0800 (PST) Subject: SQL, lite lite lite References: <39322fe4-e606-42dc-9123-71751258c3ae@a12g2000pro.googlegroups.com> <8da5c6b1-951f-4abd-8ee7-07b63802b9f6@13g2000yql.googlegroups.com> <186e44f7-f949-45e2-b1e2-a913560acf94@s9g2000prg.googlegroups.com> <495a97ce$0$25469$426a74cc@news.free.fr> <495cd630$0$17993$426a74cc@news.free.fr> Message-ID: On Jan 1, 7:43?am, Bruno Desthuilliers wrote: > Aaron Brady a ?crit : > > > > > On Dec 30, 2:52 pm, Bruno Desthuilliers > > wrote: > >> Aaron Brady a ?crit : > > >>> On Dec 30, 11:16 am, prueba... at latinmail.com wrote: > >> (snip) > >>>> You really do like to reinvent the wheels do you? :-) Nothing wrong > >>>> with that. Just be aware that most people that really need what you > >>>> are proposing are probably already using mature feature rich libraries > >>>> for that. > >>>>http://wiki.python.org/moin/HigherLevelDatabaseProgramming > >>> Look at these options! ?Who invents the wheel? ?Naturally, I've had > >>> time to master every one. > >> Oh, so that's why you propose to add yet another item to the list ? > > > Aha, so it is. ?Your criticism might seem harsh, > > This was mostly a tentative to make you notice that it might be better > to check out the existing solutions and possibly contribute to one of > them instead of inventing yet another one... > > > but it has an > > advantage. ?It made me get the lead out, that is, think. > > (snip) > > ... but it obviously failed. You have to admit that mine is simpler than a Django statement. If they want to use it, that's fine with me, but I have to invent it first. That's the reason I'm sharing on a newsgroup. Recap: An ADAPTER from a Django class into something simpler and less functional. From castironpi at gmail.com Thu Jan 1 17:24:02 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:24:02 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> On Jan 1, 2:55?pm, "Chris Rebert" wrote: > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > >> There is no solution to this problem from a Python perspective. Do > >> what everyone does right now: [snip] > > > It still surprises me that no one has implemented the solution for > > this yet. > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > matter of telling Firefox, "hey, when you see this special html > > element that tells you to run this python code from the web, do it". > > Then have FF load up a python interpreter, sandbox it somehow (that > > is, limit it to only a safe subset of its std lib), it runs the code > > The "sandbox it somehow" part is significantly harder than you seem to > believe it would be. Python tried previously with the rexec and > Bastion modules, but they were found to be irreparably flawed and thus > were removed. Suppose you compiled a version with no file type and a reduced os module? From larrydag at sbcglobal.net Thu Jan 1 17:24:05 2009 From: larrydag at sbcglobal.net (larrydag) Date: Thu, 1 Jan 2009 14:24:05 -0800 (PST) Subject: OpenOpt 0.21 (free optimization framework) References: Message-ID: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> On Dec 15 2008, 4:32?pm, dmitrey wrote: > Hi all, > OpenOpt 0.21, free optimization framework (license: BSD) with some own > solvers and connections to tens of 3rd party ones, has been released. > > All details here: > > http://openopt.blogspot.com/2008/12/openopt-release-021.html > > Regards, OpenOpt developers. Demitry, I love hearing about new implementations of free and open source operations research software. In fact I've made an update to my blog to notify about your new release. I suggest you may want to make an announcement at the comp.lang.python Usenet group. You could probably get some interest in python development from that group. Larry http://industrialengineertools.blogspot.com/ From castironpi at gmail.com Thu Jan 1 17:27:45 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:27:45 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 1, 12:12?pm, mma... at gmx.net wrote: > Hi > > I would like to check if an index is in a slice or not without > iterating over the slice. > > Something like: > > >>> isinslice(36, slice(None, 34, -1)) > > True > > I would like to use the batteries if possible. > However, I looked in the docs, pypi and in Usenet without luck. > > Does anyone have a solution? > > Martin Untested: if slice.end< 0: slice.end= len( obj )- slice.end+ 1 if slice.step< 0 and slice.start<= target< slice.end: return True if slice.step> 0 and slice.start>= target> slice.end: return True return False From rileyrgdev at gmail.com Thu Jan 1 17:28:08 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:28:08 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: Jason Rumney writes: > On Jan 1, 3:12?pm, r wrote: > >> The man lives in a world driven by common sense > > "Common" sense suggests that his views are shared among the general > populace. I don't see much evidence of that in the sometimes never- > ending threads that frequently follow his postings. But it is good to > start debates about making changes to the status quo, often the > debates will result in worthwhile changes, even if those changes are > not what he proposed. I just wish he would choose his venue a little > more carefully sometimes. I find that with Xah's posts people argue the man and not his points. And they argue the man because he refuses to be brow beaten by those who do not like to be criticised or are too think skinned. I rarely find his posts controversial but always interesting. His ELisp tutorial is far and away better than anything else out there for the programmer moving to Elisp IMO. He backs up his points with reasons and supportive evidence and rarely with "because I'm experienced and thats the way it is" - something not every one takes the time to do. He is clearly intelligent, thoughtful and experienced if a little lacking in finesse at times. The world needs more Xah lees. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From fuzzyman at gmail.com Thu Jan 1 17:28:35 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 14:28:35 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> Message-ID: <370a021b-aaba-4aae-8f89-605f6229cf8a@n33g2000pri.googlegroups.com> On Jan 1, 10:24?pm, Aaron Brady wrote: > On Jan 1, 2:55?pm, "Chris Rebert" wrote: > > > > > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > > >> There is no solution to this problem from a Python perspective. Do > > >> what everyone does right now: [snip] > > > > It still surprises me that no one has implemented the solution for > > > this yet. > > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > > matter of telling Firefox, "hey, when you see this special html > > > element that tells you to run this python code from the web, do it". > > > Then have FF load up a python interpreter, sandbox it somehow (that > > > is, limit it to only a safe subset of its std lib), it runs the code > > > The "sandbox it somehow" part is significantly harder than you seem to > > believe it would be. Python tried previously with the rexec and > > Bastion modules, but they were found to be irreparably flawed and thus > > were removed. > > Suppose you compiled a version with no file type and a reduced os > module? How would it be able to import? (I realise there is an answer to that question, but it would require more changes than you might think.) Python uses Python - so pulling bits out tends to break things... Michael Foord -- http://www.ironpythoninaction.com/ From rileyrgdev at gmail.com Thu Jan 1 17:29:31 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:29:31 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <39d1883d-fb26-41cd-8de3-9185760445f7@f13g2000yqj.googlegroups.com> Message-ID: r writes: > On Jan 1, 2:05?am, Jason Rumney wrote: >> On Jan 1, 3:12?pm, r wrote: >> >> > The man lives in a world driven by common sense >> >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I think if you will consider society as a whole, you will see that > most people don't display much sense at all. "Joe Blow" only cares > about paris hilton, britney spears, or janet jackson wardrobe > malfunctions. The only thing they contribute to society is human > excrement. So --"Common sense is the least most common thing"-- really > means there exists no sense as a commonality. > > This can apply to higher educated people too, even Guido. Go and read > Xahs take on the Python official tutorial, you will find your self > agreeing with everything that he says. Guido filled it with so much > fluff and off topic BS, causing the learning process to shut down. The > only kind of person that might find it enjoying would be a fellow > Computer Science Graduate. I did not know it at the time but this > contributed to my late understanding of classes and regexes. And being > such a fanboy of Python and carrying such a high respect for Guido > that is hard for me to say, BUT it is the TRUTH nonetheless. Guido has > no business writing tutorials anymore, WHY you ask. Because he is too > smart, and too much on the inside. He cannot relate to the n00b > pythoneer, he has crossed the Rubicon. Less fluff more simple examples > are the key to quick learning. My love for python has blinded me to > some of the atrocities that exist here. I have many more examples from > the Official-TUT than Xah covered. > > Don't take my word, judge for yourself... > http://xahlee.org/perl-python/xlali_skami_cukta.html > > here is Xah's take on OOP, very good reading for beginners and > Gurus... > http://xahlee.org/Periodic_dosage_dir/t2/oop.html > > If all Xah did was come here and say "Hey, python sucks donkey > dicks!", i would pay him no mind. But he brings much intelligence, and > vigor to an otherwise boring, and sometimes mindless newsgroup. What i > like about him is his out-side-the-box thinking style. He does not > give in to this BS "Proper Society" wants to push onto us. He is a > real rebel, but WITH a cause! And the cause is to bring common sense > back to a world of fluff an BS jargonisms. I don't always agree with > his thoughts, but most the time he's spot on. Open your min c.l.py. > Lest it close forever. Great post and I agree with you 100%. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From rileyrgdev at gmail.com Thu Jan 1 17:34:43 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:34:43 +0100 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Tim Greer writes: > Giampaolo Rodola' wrote: > >> This is not a Ruby group. >> I recommend you to go waste your time there. > > That poster has a frequent habit of cross posting to multiple, > irrelevant news groups. There's no rhyme or reason to it. It's best > to just filter the guy's posts. No rhyme nor reason? It's quite clear, to me, why. How is a comparison article not relevant when he is trying to stimulate discussion about alternative languages for modern development? Most news readers feature a kill thread command if you are not interested in the content. Certainly less extreme or ignorant than killing all posts from someone who clearly has interesting things to say about development practises and tools. From tkpapp at gmail.com Thu Jan 1 17:36:28 2009 From: tkpapp at gmail.com (Tamas K Papp) Date: 1 Jan 2009 22:36:28 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <6s4urcF47nr3U2@mid.individual.net> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: > posts controversial but always interesting. His ELisp tutorial is far > and away better than anything else out there for the programmer moving > to Elisp IMO. He backs up his points with reasons and supportive Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity when you want to program Emacs. No one in his/her right mind would use it in any other context, as far better alternatives exist (eg CL for those who like Lisp). Tamas From rileyrgdev at gmail.com Thu Jan 1 17:38:43 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:38:43 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Tamas K Papp writes: > On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: > >> posts controversial but always interesting. His ELisp tutorial is far >> and away better than anything else out there for the programmer moving >> to Elisp IMO. He backs up his points with reasons and supportive > > Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity > when you want to program Emacs. No one in his/her right mind would use > it in any other context, as far better alternatives exist (eg CL for > those who like Lisp). > > Tamas "move to Elisp" was clearly meant as "moving towards it in order to use it". In this case to modify emacs. And to suggest that jobs of work are not done in Emacs is ridiculous. I am at a loss to really understand what you mean here in the context. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From robert.kern at gmail.com Thu Jan 1 17:40:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 01 Jan 2009 17:40:32 -0500 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: Hamish McKenzie wrote: > sometimes I want to be able to initialize an instance with a variety of different data types. > > as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > > is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? I recommend keeping the __init__() as dumb as possible. Ideally, it should just assign to attributes. I would add a from() classmethod for each that I wanted to support. If I really wanted an all-singing, all-dancing initialization method, I would add another classmethod that would just dispatch to the appropriate type-specific classmethod. I prefer classmethods to plain functions because I can subclass. -- 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 hamish at valvesoftware.com Thu Jan 1 17:46:54 2009 From: hamish at valvesoftware.com (Hamish McKenzie) Date: Thu, 1 Jan 2009 14:46:54 -0800 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016be89e$0$6988$c3e8da3@news.astraweb.com> Message-ID: >> You could also use a dict with type:method key/value pairings. This is closer to a switch/case than an if...elif chain is. of course, that's a great idea... thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Thu Jan 1 17:47:49 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 1 Jan 2009 16:47:49 -0600 Subject: OpenOpt 0.21 (free optimization framework) In-Reply-To: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> References: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> Message-ID: <18781.18453.704082.526949@montanaro-dyndns-org.local> Larry> I suggest you may want to make an announcement at the Larry> comp.lang.python Usenet group. You could probably get some Larry> interest in python development from that group. Larry, Apparently you read the python-list at python.org mailing list. That list is bidirectionally gatewayed with the comp.lang.python Usenet newsgroup. If OpenOpt was announced on the mailing list then it was also announced on the newsgroup. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From raw at RawMBP.local Thu Jan 1 17:51:30 2009 From: raw at RawMBP.local (Raymond Wiker) Date: Thu, 01 Jan 2009 23:51:30 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Richard Riley writes: > Tamas K Papp writes: > >> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: >> >>> posts controversial but always interesting. His ELisp tutorial is far >>> and away better than anything else out there for the programmer moving >>> to Elisp IMO. He backs up his points with reasons and supportive >> >> Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity >> when you want to program Emacs. No one in his/her right mind would use >> it in any other context, as far better alternatives exist (eg CL for >> those who like Lisp). >> >> Tamas > > "move to Elisp" was clearly meant as "moving towards it in order to use > it". In this case to modify emacs. And to suggest that jobs of work are > not done in Emacs is ridiculous. I am at a loss to really understand > what you mean here in the context. OK, how about this: Xah's elisp code stinks to high heaven. His code should not be studied by anybody who actually wants to actually learn elisp (or anything else). From benjamin.kaplan at case.edu Thu Jan 1 18:01:25 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 1 Jan 2009 18:01:25 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 5:28 PM, Richard Riley wrote: > Jason Rumney writes: > > > On Jan 1, 3:12 pm, r wrote: > > > >> The man lives in a world driven by common sense > > > > "Common" sense suggests that his views are shared among the general > > populace. I don't see much evidence of that in the sometimes never- > > ending threads that frequently follow his postings. But it is good to > > start debates about making changes to the status quo, often the > > debates will result in worthwhile changes, even if those changes are > > not what he proposed. I just wish he would choose his venue a little > > more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. And they argue the man because he refuses to be brow beaten by > those who do not like to be criticised or are too think skinned. I > rarely find his posts controversial but always interesting. His ELisp > tutorial is far and away better than anything else out there for the > programmer moving to Elisp IMO. He backs up his points with reasons and > supportive evidence and rarely with "because I'm experienced and thats > the way it is" - something not every one takes the time to do. He is > clearly intelligent, thoughtful and experienced if a little lacking in > finesse at times. The world needs more Xah lees. If this were an Elisp/Mathematica/Ruby group, those posts would be fine. It isn't just the content of the posts, it's their subject that gets on everyone's nerves. We don't want to hear about Elisp tutorials or why Mathematica is superior to Python. We want to hear about Python. This isn't people being closed-minded, it's about people trying to keep comp.lang.* python* focused on python. If we want to hear about Elisp, we'd ask about it on an emacs or a lisp group. If we want to hear about Mathematica, we'd ask Wolfram for help. If Xah Lee came to the group with posts that constituted "general discussions and questions about Python" people on the list wouldn't get so annoyed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Jan 1 18:05:27 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 1 Jan 2009 18:05:27 -0500 Subject: If your were going to program a game... In-Reply-To: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 3:24 PM, excord80 wrote: > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > > There is no solution to this problem from a Python perspective. Do > > what everyone does right now: [snip] > > It still surprises me that no one has implemented the solution for > this yet. > > Maybe it's harder than it seems, but it *seeems* like it's just a > matter of telling Firefox, "hey, when you see this special html > element that tells you to run this python code from the web, do it". > Then have FF load up a python interpreter, sandbox it somehow (that > is, limit it to only a safe subset of its std lib), it runs the code > within its region of the browser window, and Bob's your uncle. > > People would go bonkers for that. This is just as bad as people who post broken HTML just because IE can display it. You should never post content online that only works in one browser. It will just irritate people. If you don't mind using Microsoft stuff, I believe that Silverlight 2 supports IronPython. Novell is almost finished with their open source implementation (Moonlight), but I don't know if they have ipy support yet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at burlyhost.com Thu Jan 1 18:19:58 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 15:19:58 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Richard Riley wrote: > > Tim Greer writes: > >> Giampaolo Rodola' wrote: >> >>> This is not a Ruby group. >>> I recommend you to go waste your time there. >> >> That poster has a frequent habit of cross posting to multiple, >> irrelevant news groups. There's no rhyme or reason to it. It's best >> to just filter the guy's posts. > > No rhyme nor reason? It's quite clear, to me, why. > > How is a comparison article not relevant when he is trying to > stimulate discussion about alternative languages for modern > development? Most news readers feature a kill thread command if you > are not interested in the content. Certainly less extreme or ignorant > than killing all posts from someone who clearly has interesting things > to say about development practises and tools. Don't get so wound up because people in groups he cross posts this junk to actually don't want to see it. This poster is hardly interesting or offering anything intelligent. This poster has a history of posting things that he is personally interested in arguing about, and posting it in groups that are not about the languages he chooses to complain about. There is no rhyme or reason to post in the Perl news group, for example, if you're complaining about Ruby. This is not even close to the first time this has happened, much like his relentless posts about Mathematica (again, cross posted to several groups, including Perl). This user has a specific bias and is trolling to get a rise out of people by picking random languages and trying to cut them down, claiming *his* opinions (based on lack of insights, ironically) are superior. He does this often, and always cross posts to several groups that are completely irrelevant to his argument. The fact you actually buy into this nonsense, actually doesn't make anyone else wrong or ignorant for not agreeing with him, or falling for it. In fact, it means exactly the opposite. If he had something actually interesting and/or relevant, then his rants would be more tolerated by users of these groups. However, since he offers none of those aspects, this is why you see people voice their grievances. Look at this in its basic element, if you don't believe what people say -- this user didn't post the topic in the most revelant group (being the ruby group), and each time he goes off on another misguided tangent, several people prove him wrong, and it doesn't phase him or change anything -- he just continues to cross post. Like I said, if you think he's interesting, fine. However, many people don't. Perhaps as you learn more about programming, development and specific tools and practices, you'll come to realize this fact as well. In the meantime, the irony is probably lost when you actually believe he is offering something of substance, interest or that people whom know better are somehow ignorant. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From slafs.e at gmail.com Thu Jan 1 18:21:18 2009 From: slafs.e at gmail.com (Slafs) Date: Thu, 1 Jan 2009 15:21:18 -0800 (PST) Subject: yacc statement recognition Message-ID: Hi ALL! I have to write in yacc an acceptor of files with lines matching this regexp: '[0-9],[0-9]' and I don't know what I am doing wrong beacuse this: -------- tokens = ( 'NUMBER', ) literals = [','] t_NUMBER = r'\d' ... def p_statement_exp(p): '''statement : NUMBER ',' NUMBER ''' print "OK!" sys.exit() ------- also accepts lines like 2,abcdef3 which of could someone please tell me what's wrong in my code? full source on http://paste-it.net/public/vba22d5/ From tim at burlyhost.com Thu Jan 1 18:24:44 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 15:24:44 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <1hc7l.23929$mE3.719@newsfe14.iad> Richard Riley wrote: > Jason Rumney writes: > >> On Jan 1, 3:12?pm, r wrote: >> >>> The man lives in a world driven by common sense >> >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. And they argue the man because he refuses to be brow beaten by > those who do not like to be criticised or are too think skinned. I > rarely find his posts controversial but always interesting. His ELisp > tutorial is far and away better than anything else out there for the > programmer moving to Elisp IMO. He backs up his points with reasons > and supportive evidence and rarely with "because I'm experienced and > thats the way it is" - something not every one takes the time to do. > He is clearly intelligent, thoughtful and experienced if a little > lacking in finesse at times. The world needs more Xah lees. > You say he's intelligent and interesting, others see it as the opposite. If you want to read his rants, by all means. However, there have been many, many posts there this poster was proven wrong. That is when the poster become more belligerent, off topic, and vulgar. That is not the actions of an intelligent person that's staying on topic or providing anything interesting. The only thing I find interesting, is two anonymous posters from gmail.com rushing to his defense, especially in light of the fact that few people share your version of this person's talents. I'm not trying to be mean, but the guy is what people call a usenet troll. By all means, be his fan, but don't encourage his cross posting trolling as a means to provoke interesting, intelligent debating (because he's not and it's absolutely not his intention). Believe what you want, though, and I'll believe what I know. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From kentilton at gmail.com Thu Jan 1 18:34:19 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Thu, 01 Jan 2009 18:34:19 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <495D52FB.6070601@gmail.com> Richard Riley wrote: > Jason Rumney writes: > >> On Jan 1, 3:12 pm, r wrote: >> >>> The man lives in a world driven by common sense >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. Precisely, and thus they are the trolls: few of them trim followups, and all of them try to sound funny or clever in their attacks. Xah has something to say about technology, like what he says or not. His attackers just see an open mike and want to hear the sound of their own voice, which I certainly understand. And before anyone goes for that old argument from self-reference, the madding crowd succeeded once in their harrassment of The Xah so remaining silent is no option. p,k From timr at probo.com Thu Jan 1 18:43:00 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 01 Jan 2009 23:43:00 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <0fkql4huhn5tc87utlg6pbdtgt7gqiseca@4ax.com> Aaron Brady wrote: > >I agree that the form of the 4th fragment is 'X and Y are' in >general. However, native speakers don't often use the form 'X and X >are'. This is the source of my protest, because X = the Morning Star >= the Evening Star. We don't say, 'G.H.W. Bush and the President >are...', say, at Camp David. Only now do I begin to see the point you were trying to make. You chose that specific example because the Morning Star and the Evening Star happen to be the same celestial body -- the same object. However, in grammatical terms, that is absolutely irrelevant. For example, "The car and the patent are white rabbits" is, grammatically speaking, 100% correct. Grammatically correct sentences do not have to be logically consistent. Here's a counter example: The Pope and the Head of the Catholic Church are the same person. I don't think any moderately proficient English speaker would have trouble parsing that. By the way, G.H.W. Bush was president from 1988 to 1992. The President today is G.W. Bush. The current president doesn't have an "H". There has to be a pun about "getting the H out of there", but I'll leave that to the reader. >It is not that the meaning is unclear, it's just that form is never used. Well, *I* use it. ;) >How all this relates to Python semantics is, if I say, 'a and b are >the same object', the listener can get confused. I'm inclined to disagree, but in contexts where it is important, I always try to say "a and b are bound to the same object". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rileyrgdev at gmail.com Thu Jan 1 18:52:35 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 00:52:35 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Raymond Wiker writes: > Richard Riley writes: > >> Tamas K Papp writes: >> >>> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: >>> >>>> posts controversial but always interesting. His ELisp tutorial is far >>>> and away better than anything else out there for the programmer moving >>>> to Elisp IMO. He backs up his points with reasons and supportive >>> >>> Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity >>> when you want to program Emacs. No one in his/her right mind would use >>> it in any other context, as far better alternatives exist (eg CL for >>> those who like Lisp). >>> >>> Tamas >> >> "move to Elisp" was clearly meant as "moving towards it in order to use >> it". In this case to modify emacs. And to suggest that jobs of work are >> not done in Emacs is ridiculous. I am at a loss to really understand >> what you mean here in the context. > > OK, how about this: Xah's elisp code stinks to high > heaven. His code should not be studied by anybody who actually wants > to actually learn elisp (or anything else). I found his tutorial easy to use and very convenient for finding out how to do things quickly and easily. I grant you that possibly thats not the way to be a true Elisp god, but for getting things done in a timely and efficient manner I thought it was good. Clearly Xah Lee stirs up some strong emotions here. I can only go on what I have read from him and I find him interesting and always willing to back up his own research and views. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From rileyrgdev at gmail.com Thu Jan 1 18:57:06 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 00:57:06 +0100 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Tim Greer writes: > Richard Riley wrote: > >> >> Tim Greer writes: >> >>> Giampaolo Rodola' wrote: >>> >>>> This is not a Ruby group. >>>> I recommend you to go waste your time there. >>> >>> That poster has a frequent habit of cross posting to multiple, >>> irrelevant news groups. There's no rhyme or reason to it. It's best >>> to just filter the guy's posts. >> >> No rhyme nor reason? It's quite clear, to me, why. >> >> How is a comparison article not relevant when he is trying to >> stimulate discussion about alternative languages for modern >> development? Most news readers feature a kill thread command if you >> are not interested in the content. Certainly less extreme or ignorant >> than killing all posts from someone who clearly has interesting things >> to say about development practises and tools. > > Don't get so wound up because people in groups he cross posts this > junk Wound up? I am not wound up in any shape or form. I am suggesting the opposite. It seems you are the one a little wound up. So wound up in fact you are taking it on yourself to tell people who they should or should not read. > to actually don't want to see it. This poster is hardly interesting or > offering anything intelligent. This poster has a history of posting > things that he is personally interested in arguing about, and posting > it in groups that are not about the languages he chooses to complain > about. There is no rhyme or reason to post in the Perl news group, > for You dont seem to think that a comparison article is relevant in the groups dedicated to the languages he compares too? OK. I do. You are, of course, welcome to your opinion and I certainly would not tell you who to read or not read. I would suggest that not everyone woul agree with you and that telling people who to killfile is not at all constructive. > example, if you're complaining about Ruby. This is not even close to > the first time this has happened, much like his relentless posts about > Mathematica (again, cross posted to several groups, including Perl). > This user has a specific bias and is trolling to get a rise out of > people by picking random languages and trying to cut them down, > claiming *his* opinions (based on lack of insights, ironically) are > superior. He does this often, and always cross posts to several groups > that are completely irrelevant to his argument. You clearly have a personal issue with Xah Lee. Possibly it is better you killfile him or your spring will over wind :-; regards, r. From rileyrgdev at gmail.com Thu Jan 1 19:00:19 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 01:00:19 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: Kenneth Tilton writes: > Richard Riley wrote: >> Jason Rumney writes: >> >>> On Jan 1, 3:12 pm, r wrote: >>> >>>> The man lives in a world driven by common sense >>> "Common" sense suggests that his views are shared among the general >>> populace. I don't see much evidence of that in the sometimes never- >>> ending threads that frequently follow his postings. But it is good to >>> start debates about making changes to the status quo, often the >>> debates will result in worthwhile changes, even if those changes are >>> not what he proposed. I just wish he would choose his venue a little >>> more carefully sometimes. >> >> I find that with Xah's posts people argue the man and not his >> points. > > Precisely, and thus they are the trolls: few of them trim followups, > and all of them try to sound funny or clever in their attacks. Xah has > something to say about technology, like what he says or not. His > attackers just see an open mike and want to hear the sound of their > own voice, which I certainly understand. > > And before anyone goes for that old argument from self-reference, the > madding crowd succeeded once in their harrassment of The Xah so > remaining silent is no option. > > p,k It's good to see I am not alone in my views on some of the more aggressive posters who seem to take delight in attacking Xah Lee. I was wondering if I had backed myself into a corner with no chance of escape for a moment. I found the comments on his elisp tutorial and reference particularly offensive and destructive considering I know it to be of at least some use as I referred to it quite a bit when trying some basic customisations. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From jurgenex at hotmail.com Thu Jan 1 19:02:44 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 16:02:44 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <6cmql4hmfbsrtr1mgsub2l2p6o0lv7n03l@4ax.com> Richard Riley wrote: >discussion about alternative languages for modern development? Most news >readers feature a kill thread command if you are not interested in the >content. Certainly less extreme or ignorant than killing all posts from >someone Thank you for reminding me *PLONK* jue From jurgenex at hotmail.com Thu Jan 1 19:05:11 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 16:05:11 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: Kenneth Tilton wrote: >Xah has >something to say about technology, like what he says or not. Unfortunately it's unrelated to the topics the NGs he is spamming. *PLONK* jue From steve at REMOVE-THIS-cybersource.com.au Thu Jan 1 19:16:14 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 00:16:14 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> Message-ID: <016d53c1$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > On many occasions I've wished for a functional dictionary implementation > in Python, like Haskell's Data.Map. One of these years I'll get around > to writing one. You don't think Python's dict implementation is functional? That's pretty strange, Python dicts are the basis of much of the language. They certainly work, and work well, what makes you think they aren't functional? What does Data.Map do that dicts don't? Oh, and Paul, you've been around long enough that you should know better than to be cross-posting like you did. -- Steven From tim at burlyhost.com Thu Jan 1 19:18:54 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 16:18:54 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Richard Riley wrote: > Tim Greer writes: > >> Richard Riley wrote: >> >>> >>> Tim Greer writes: >>> >>>> Giampaolo Rodola' wrote: >>>> >>>>> This is not a Ruby group. >>>>> I recommend you to go waste your time there. >>>> >>>> That poster has a frequent habit of cross posting to multiple, >>>> irrelevant news groups. There's no rhyme or reason to it. It's >>>> best to just filter the guy's posts. >>> >>> No rhyme nor reason? It's quite clear, to me, why. >>> >>> How is a comparison article not relevant when he is trying to >>> stimulate discussion about alternative languages for modern >>> development? Most news readers feature a kill thread command if you >>> are not interested in the content. Certainly less extreme or >>> ignorant than killing all posts from someone who clearly has >>> interesting things to say about development practises and tools. >> >> Don't get so wound up because people in groups he cross posts this >> junk > > > Wound up? Yes, I'd say that accusing people of bring ignorant and attacking them for not sharing your view on the irrelevant cross posting and trolling of the Xah poster, is indeed an indication that you appear to be wound up. Perhaps you've not seen the posts and threads he's made that I've seen? Perhaps I've not seen the one's you have? Either way, the one's I have, have all been either self serving garbage about his own personal feelings that he attempts to covey as fact with his overbearing arrogance, or it's simply to attack others for not sharing his view. I find that ironic. He attacks others, acting belligerent, and you attack those that simply say he's better ignored. > I am not wound up in any shape or form. Then convey that in your attitude when replying to others you don't know anything about, and try and be civil and not accuse people you don't know. > I am suggesting the > opposite. Suggesting it by doing exactly what you're saying people should not do? > It seems you are the one a little wound up. Nope, I responded to your attempts to provoke an issue, when you accused myself and others of being "ignorant" for not sharing your view regarding the Xah poster. > So wound up in > fact you are taking it on yourself to tell people who they should or > should not read. A suggestion is not an instruction or demand. You listed reasons why you believed those that didn't agree with you were wrong and ignorant, and I listed reasons in response to your claim to dispute it. >> to actually don't want to see it. This poster is hardly interesting >> or >> offering anything intelligent. This poster has a history of posting >> things that he is personally interested in arguing about, and posting >> it in groups that are not about the languages he chooses to complain >> about. There is no rhyme or reason to post in the Perl news group, >> for > > You dont seem to think that a comparison article is relevant in the > groups dedicated to the languages he compares too? No. Not when it's just his own feelings about the languages. A lot of people have their personal feelings about various languages, imagine all of the pollution we'd see if everyone was as arrogant as this guy, all posting their views as if they are the authority on the matter? Again, going by that deduction, what do you suppose explains his failure to consider posting this in the ruby group itself, since that is the primary (and actually, only) relevant group (dismissing his personal views)? > OK. I do. If you do, that's fine. However, many people in the Perl group, which I'm seeing this thread, have voiced their issues with this poster's relentless postings of this nature. I did as well, in this new thread. > You are, > of course, welcome to your opinion and I certainly would not tell you > who to read or not read. I can appreciate that, and I didn't tell you to do anything though, now did I? > I would suggest that not everyone woul agree > with you and that telling people who to killfile is not at all > constructive. Of course I don't expect everyone to agree with me. The poster that replied displayed annoyance at seeing the off topic, self serving and trollish post that this Xah poster is known for (at least in this group), and in response to *that*, I had suggested they don't take him seriously, and this is "what he does" (in my experience). There's no reason to read more into it and start claiming people are ignorant for not agreeing with you. And, I think it's perfectly constructive to advise someone that this isn't abnormal, and for future reference, to consider such an option if they are too annoyed by it. >> example, if you're complaining about Ruby. This is not even close to >> the first time this has happened, much like his relentless posts >> about Mathematica (again, cross posted to several groups, including >> Perl). This user has a specific bias and is trolling to get a rise >> out of people by picking random languages and trying to cut them >> down, claiming *his* opinions (based on lack of insights, ironically) >> are >> superior. He does this often, and always cross posts to several >> groups that are completely irrelevant to his argument. > > You clearly have a personal issue with Xah Lee. Not at all. It's not personal. It's a simple observation and opinion based on my experience seeing his cross posting trolling over the last few weeks. I didn't accuse you of having a personal issue with me for not agreeing with my opinion and methods, so perhaps you can consider the gesture of not making such accusations. They aren't true or relevant. Yeah, I verbalized (textualized) my displeasure with his tactics, but that's the end of the matter, really. > Possibly it is better > you killfile him or your spring will over wind :-; Uh huh. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From fuzzyman at gmail.com Thu Jan 1 19:19:38 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 16:19:38 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 2, 12:16?am, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > > On many occasions I've wished for a functional dictionary implementation > > in Python, like Haskell's Data.Map. ?One of these years I'll get around > > to writing one. > > You don't think Python's dict implementation is functional? That's pretty > strange, Python dicts are the basis of much of the language. They > certainly work, and work well, what makes you think they aren't > functional? What does Data.Map do that dicts don't? > He almost certainly (I assume) means functional in the way that Haskell is a functional language. Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Thu Jan 1 19:22:15 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 16:22:15 -0800 (PST) Subject: why cannot assign to function call References: <97a11245-a034-4558-82d4-0c87e02bdb7e@u18g2000pro.googlegroups.com> Message-ID: <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> On Dec 29 2008, 9:34?am, John Machin wrote: > On Dec 29, 5:01?pm, scsoce wrote: > > > I have a function return a reference, > > Stop right there. You don't have (and can't have, in Python) a > function which returns a reference that acts like a pointer in C or C+ > +. Please tell us what manual, tutorial, book, blog or Usenet posting > gave you that idea, and we'll get the SWAT team sent out straight > away. > > > and want to assign to the > > reference, simply like this: > > ?>>def f(a) > > ? ? ? ? ? return a > > That's not a very useful function, even after you fix the syntax error > in the def statement. Would you care to give us a more realistic > example of what you are trying to achieve? > > > ? ? ?b = 0 > > ? ? * f( b ) = 1* > > Is the * at the start of the line meant to indicate pointer > dereferencing like in C? If not, what is it? Why is there a * at the > end of the line? > > > but the last line will be refused as "can't assign to function call". > > In my thought , the assignment is very nature, > > Natural?? Please tell us why you would want to do that instead of: > > ? ? b = 1 > > >?but ?why the interpreter > > refused to do that ? > > Because (the BDFL be praised!) it (was not, is not, will not be) in > the language grammar. Although not being able to do the following has on occasion annoyed me: f(x) += 1 If the object returned by f(x) supports in place operations then it is an entirely logical meaning, but not the interpreter can't know ahead of time whether that is the case or not. Michael Foord -- http://www.ironpythoninaction.com/ From rt8396 at gmail.com Thu Jan 1 19:24:43 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 16:24:43 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: <00354316-4d95-4eca-8ff3-45d804ddf97a@s37g2000vbp.googlegroups.com> On Jan 1, 5:34?pm, Kenneth Tilton wrote: > Richard Riley wrote: > > Jason Rumney writes: > > >> On Jan 1, 3:12 pm, r wrote: > > >>> The man lives in a world driven by common sense > >> "Common" sense suggests that his views are shared among the general > >> populace. I don't see much evidence of that in the sometimes never- > >> ending threads that frequently follow his postings. But it is good to > >> start debates about making changes to the status quo, often the > >> debates will result in worthwhile changes, even if those changes are > >> not what he proposed. I just wish he would choose his venue a little > >> more carefully sometimes. > > > I find that with Xah's posts people argue the man and not his > > points. > > Precisely, and thus they are the trolls: few of them trim followups, and > all of them try to sound funny or clever in their attacks. Xah has > something to say about technology, like what he says or not. His > attackers just see an open mike and want to hear the sound of their own > voice, which I certainly understand. > > And before anyone goes for that old argument from self-reference, the > madding crowd succeeded once in their harrassment of The Xah so > remaining silent is no option. > > p,k Good Point, Starting a new thread is not off topic no matter what subject. I have never witnessed a time where Xah jumped in the middle of a thread and started a ruckus(i could be wrong), But i do see many interrupting Xah's threads or any thread for that matter that they feel is irrelevant to them. The topic of a thread is it's title. Here, the title is "Why Not Ruby". I am the only person yet to offer argument for or against Ruby here. From mmanns at gmx.net Thu Jan 1 19:28:23 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Fri, 2 Jan 2009 01:28:23 +0100 Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: <20090102012823.7bae496b@Schlamber.localdomain> On Thu, 1 Jan 2009 11:34:53 -0800 (PST) ajaksu wrote: > http://article.gmane.org/gmane.comp.python.python-3000.devel/8732 I will build upon this code. Thanks for your help Martin From google at mrabarnett.plus.com Thu Jan 1 20:04:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 02 Jan 2009 01:04:55 +0000 Subject: why cannot assign to function call In-Reply-To: <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> References: <97a11245-a034-4558-82d4-0c87e02bdb7e@u18g2000pro.googlegroups.com> <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> Message-ID: <495D6837.6090307@mrabarnett.plus.com> Fuzzyman wrote: > On Dec 29 2008, 9:34 am, John Machin wrote: >> On Dec 29, 5:01 pm, scsoce wrote: >> >>> I have a function return a reference, >> Stop right there. You don't have (and can't have, in Python) a >> function which returns a reference that acts like a pointer in C or C+ >> +. Please tell us what manual, tutorial, book, blog or Usenet posting >> gave you that idea, and we'll get the SWAT team sent out straight >> away. >> >>> and want to assign to the >>> reference, simply like this: >>> >>def f(a) >>> return a >> That's not a very useful function, even after you fix the syntax error >> in the def statement. Would you care to give us a more realistic >> example of what you are trying to achieve? >> >>> b = 0 >>> * f( b ) = 1* >> Is the * at the start of the line meant to indicate pointer >> dereferencing like in C? If not, what is it? Why is there a * at the >> end of the line? >> >>> but the last line will be refused as "can't assign to function call". >>> In my thought , the assignment is very nature, >> Natural?? Please tell us why you would want to do that instead of: >> >> b = 1 >> >>> but why the interpreter >>> refused to do that ? >> Because (the BDFL be praised!) it (was not, is not, will not be) in >> the language grammar. > > Although not being able to do the following has on occasion annoyed > me: > > f(x) += 1 > > If the object returned by f(x) supports in place operations then it is > an entirely logical meaning, but not the interpreter can't know ahead > of time whether that is the case or not. > += always rebinds, even for in-place operations, so, in a sense, it's not surprising! I suppose it's like forbidding assignment within an expression (such as an if- or while-condition): annoying sometimes, but a reasonable restriction. From timr at probo.com Thu Jan 1 20:30:30 2009 From: timr at probo.com (Tim Roberts) Date: Fri, 02 Jan 2009 01:30:30 GMT Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > >On using videocapture (python 2.4), I am facing the following issues >while creating a video sort of application. >-> Pull out the usb cable : Videocapture gets the data stored >initially in the buffer and returns always. The images are not updated >- but also there is no error returned. >i.e. there is no information to the viewer that it is not working >anymore. Especially because since the timestamp is updated everytime >(it is done inside videocapture.py - wherein current time is >overwritten on the received image), it gives a feeling that video is >running. > >Currently I have done a workaround in that every 2 captures, i setup >the camera again - but it takes too much time. Anyone has any >suggestions on solving this? The "right" way to fix this is to modify the C++ code that sets up the DirectShow filter graph. The graph builder has the ability to deliver events asynchronously, like when the device goes away, but it would not be trivial to incorporate that into the module as written. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rt8396 at gmail.com Thu Jan 1 20:38:02 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 17:38:02 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> On Jan 1, 6:16?pm, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > > On many occasions I've wished for a functional dictionary implementation > > in Python, like Haskell's Data.Map. ?One of these years I'll get around > > to writing one. > > You don't think Python's dict implementation is functional? That's pretty > strange, Python dicts are the basis of much of the language. They > certainly work, and work well, what makes you think they aren't > functional? What does Data.Map do that dicts don't? > > Oh, and Paul, you've been around long enough that you should know better > than to be cross-posting like you did. > > -- > Steven Steven, He was not cross posting. His reference to python dicts is a result of the nested scope of my references to Xah. Making them perfectly and completely valid in this thread, and the scope therein! I do not believe a linear conversation would do anybody any good here and even valid. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 1 20:38:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 01:38:06 GMT Subject: Why not Ruby? References: Message-ID: <016d66f1$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > the use of "end" in a language as > high level as Ruby is redundant, and idiotic. There are a few things > about Ruby i really like, but this "end" business is blasphemy. "Blasphemy"? You really are an idiot. Programming languages are not religions. Step away from the computer, and don't come back until you've grown up. And stop cross-posting, you rude little delinquent. -- Steven From excord80 at gmail.com Thu Jan 1 20:49:22 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 17:49:22 -0800 (PST) Subject: mod_pylite? Message-ID: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Just read this interesting post by chromatic on what features Perl 5 needs right now http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html and he mentions a neat-looking project called ``mod_perlite``. It sounds like it will be very handy. Anyone working on a ``mod_pylite``? Has it been done before, maybe under a different name? From jgardner at jonathangardner.net Thu Jan 1 21:10:30 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 1 Jan 2009 18:10:30 -0800 (PST) Subject: Understanding search queries, semantics, and "Meaning" ...aren't we all looking for meaning? References: <82372457-2503-4682-96b3-37540328bf26@w39g2000prb.googlegroups.com> <94ab1653-c88d-4bad-a094-47d67e435618@w1g2000prm.googlegroups.com> <3d4991d9-d0ab-4483-aee7-2763e3712b96@w1g2000prm.googlegroups.com> Message-ID: <23f35a8e-d560-41ac-8a86-c682a8596c81@k36g2000pri.googlegroups.com> On Dec 30 2008, 3:25?pm, 5lvqbw... at sneakemail.com wrote: > > In a typical SQL database, when you type in "SELECT foo FROM bar WHERE > > baz='bo'", you are not writing a program, at least not in the sense of > > Python or C or Java or Perl where you give instructions on HOW to run > > the program. You are writing a program in the sense of Lisp or Scheme > > or Haskell in that you are giving instructions on WHAT the program is. > > I've gotten a strong inkling that parsing a query yields new code, > (lambdas) that are created on the fly to do the search. > More on this at the very end. Just smile to know that you're very close. > > course. Instead, it transforms the query (the WHAT) into a set of > > procedures that describe HOW to get the result. > > For now I'm not parsing actual text queries... my real "search query" > is coded directly in python like this: > p1 = lambda: db.search_leaf('x location', 'lte', 5) > p2 = lambda: db.search_leaf('footprint', 'eq', '0603') > p3 = lambda: db.search(db.AND, p1, p2) > > p4 = lambda: db.search_leaf('x location', 'gte', 19) > p5 = lambda: db.search_leaf('footprint', 'eq', '0402') > p6 = lambda: db.search(db.AND, p1, p2) > > fc = db.search(db.OR, p3, p4) > > this particular example doesn't necessarily make any sense, but in > effect I'm trying to string together lambda functions which are > created explicitly for the individual query, then strung together with > combiner functions. > If only compilers were so simple... Again, you're writing the "HOW" when you're doing what you're doing above, when you really want to write the "WHAT". Oh, and BTW, lambdas are just an expression to generate a function quickly. You're confusing the python lambda expression with lambdas the theoretical concepts. Lambdas the theoretical concept are really Python's callable objects. Python just expresses them in a very weird way that is seemingly unrelated to lambda the theoretical concept (but really is). > > Oh, by the way, this step is nondeterministic. Why? Well, no one can > > really say what the BEST way to run any sufficiently complicated > > program is. We can point out good ways and bad ways, but not the best > > way. It's like the travelling salesman problem in a way. > > The nondeterministic stuff... wow, I've come across (call/cc...), > (require...), and different variants of this, both in sicp, teach > yourself scheme, the plt docs, other places, etc., but it still eludes > me. ?I'm afraid that unless I understand it, I'll wind up creating > some type of cargo-cult mimcry of a database without doing it right > (http://en.wikipedia.org/wiki/Cargo_cult) > Sorry, I got confused on the meaning of non-deterministic programming. I forgot that this was a specific thing in the Scheme world. Yes, you've got to understand this. It makes writing a compiler much, much easier, almost trivial. > > programmer, will be infinitely better for it. When you understand it, > > you will really unlock the full potential of Python and Scheme and > > whatever other language is out there because you will see how to go > > from HOW languages to WHAT languages. > > I'm under the impression python doesn't have the internal guts for > nondeterministic programming, specifcially that its lambdas are > limited to single-line expressions, but I may be wrong here. > (Recall what I mentioned about lambdas above. It applies here as well.) > Still, at the begining of the nondeterministic section of SICP > (section 4.3), it says "nondeterministic computing... is useful for > 'generate and test' applications", which almost categorically sounds > like an element-by-element search for what you're looking for. ?This > was my initial intention behind (prematurely?) optimizing the database > by using parameter keys instead of something like [x for x in stuff if > pred(x, val)] filtering. > Yes, you certainly can't use list comprehensions to solve your problems. They're too primitive and part of the interface is that they actually iterate through the sequence. > > Programmers who can write compilers are GOOD programmers. Programmers > > who can understand someone else's compilers are even better. > > Does incorporating a search capability in an application necessarily > mean I'm writing a search compiler? ?That seems overkill for the > specific case, but may be true generally. ?For instance, if a word > processing app allows you to search for characters with a certain > font, is that incorporating a search compiler and query language? ?Or > is it just brute-force filtering? > Ok, here's some big picture hand-waving. I'm going to make an assertion, and it turns out to be fundamental. I won't explain it here but I hope you'll learn what it means as time goes on. The assertion is this: All programs simply transform one program's code into another program's code. By program, I mean, a set of instructions to a computer of some sort that are meant to be actually evaluated somehow. By program's code, I mean a description in any form of such a program. For instance, all human language is really some kind of program code. So is all Scheme, Lisp, Python, whatever code. So is HTML. So are bytes and words in memory representing a compiled program. So are IP packets on the internet. When you type in search terms to the search feature of Word, you are writing program code. Sure, the program code is going to be interpreted in some way, but it represents a program that says, "Find, by whatever method available, the next instance of text matching the text I type in here". That's a fairly easy thing to do, and you don't need to know about relational algebra and non-deterministic code to write a correct and fast solution. If you're going to implement a general function that takes arbitrary search criteria against arbitrary structured data and uses several methods together to find the answers, that's going to require a fairly advanced compiler and optimizer. You can use Scheme's non- deterministic methods to build that program, which is really neat and a big time-saver in terms of development time. That level of program is pretty advanced and only those who really understand how to write a compiler can put it together. For the mouse-hovering bit, since you're always running the same query, you can "pre-compile" it and just write a specific index and some specific code to look it up. This isn't too difficult. From skip at pobox.com Thu Jan 1 21:12:32 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 1 Jan 2009 20:12:32 -0600 Subject: mod_pylite? In-Reply-To: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Message-ID: <18781.30736.601023.757172@montanaro-dyndns-org.local> >> http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html >> and he mentions a neat-looking project called ``mod_perlite``. It >> sounds like it will be very handy. Anyone working on a >> ``mod_pylite``? Has it been done before, maybe under a different >> name? It's kind of hard to tell. There's very little description of how mod_perlite would be different than mod_perl other than it would be more lightweight, presumably as mod_php somehow is. That hardly seems like a well-defined requirement document. Does mod_wsgi fit the bill? http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From marek at xivilization.net Thu Jan 1 21:13:34 2009 From: marek at xivilization.net (Marek Kubica) Date: Fri, 2 Jan 2009 02:13:34 +0000 (UTC) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> Message-ID: On Thu, 01 Jan 2009 13:13:19 -0800, Fuzzyman wrote: > Care to save me the effort of looking it up and tell me what Data.Map > does that Python's dict doesn't? > > I guess if it is functional then every mutation must copy and return a > new data structure? (Which will be much more efficient in Haskell than > in Python - Haskell can share most of the underlying data whereas Python > would have to create a new dict every time. At least it only stores > references.) Who says that it must create a whole new one? I could imagine that with a bit weakref code and some thought an immutable dictionary that shares data would be possible in Python too. regards, Marek From excord80 at gmail.com Thu Jan 1 22:28:17 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 19:28:17 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Message-ID: <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> On Jan 1, 9:12?pm, s... at pobox.com wrote: > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > ? ? >> sounds like it will be very handy. Anyone working on a > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > ? ? >> name? > > It's kind of hard to tell. ?There's very little description of how > mod_perlite would be different than mod_perl other than it would be more > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > well-defined requirement document. > > Does mod_wsgi fit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > I'm not sure if it fits the bill or not. The bill is two-fold: 1. The Apache module should present little risk to the admin who installs it. That is, it should not expose Apache's innards. 2. The Apache module should keep a Python instance running; run, for example, ``foo.py`` when a user accesses (for example) ``http:// www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the usual way; and return whatever html that script spits out. I'm not familiar with php or ``mod_php``, but I suspect that setup does something very similar to what's described above. This might explain why it's so blasted easy to deploy php scripts and create small and simple sites (and even not-so-small/simple sites) with it. Does mod_wsgi fit that bill? I don't know. The docs seem to be at http://code.google.com/p/modwsgi/w/list . Many of those are named "ChangesInVersionXXXX". I don't see any that named anything like "Introduction" or "BasicUsage" or "SimpleUsageLikeCGI" or even "Tutorial". So, my guess is that ``mod_wsgi`` doesn't fit the bill. From http Thu Jan 1 22:48:17 2009 From: http (Paul Rubin) Date: 01 Jan 2009 19:48:17 -0800 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xeizmtlku.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > You don't think Python's dict implementation is functional? I'm using the term "functional" in the sense of Chris Okasaki's book "Purely Functional Data Structures". Basically a functional dictionary is an immutable dictionary that supports fast "update" operations by letting you quickly make a new dictionary that shares structure with the old one. For example, if d is a functional dictionary, then e = d.update(("name", "joe")) would be something like Python's e = d.copy() e["name"] = "joe" except that it would not incur the overhead of copying d completely and instead would usually take O(log n) operations where n is the number of entries in d. Among other things this makes it trivial to implement rollback for dictionaries, multiple views of the same data, etc. Functional dictionaries are normally implemented using balanced tree structures such as red-black trees as their association mechanism, rather than hash tables. From http Thu Jan 1 22:51:53 2009 From: http (Paul Rubin) Date: 01 Jan 2009 19:51:53 -0800 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> Message-ID: <7xabaatleu.fsf@ruckus.brouhaha.com> Marek Kubica writes: > > I guess if it is functional then every mutation must copy and return a > > new data structure? Yes. > > (Which will be much more efficient in Haskell than > > in Python - Haskell can share most of the underlying data whereas Python > > would have to create a new dict every time. At least it only stores > > references.) The structure sharing is essential, but you can do it in Python, just not using Python dicts as far as I can tell. > Who says that it must create a whole new one? I could imagine that with a > bit weakref code and some thought an immutable dictionary that shares > data would be possible in Python too. I don't see a way to do that. Suppose d and e are dicts that are supposed to share structure except d['name']='bob' and e['name']='joe'. How do weakrefs help? Functional dictionaries are usually implemented using red-black trees or AVL trees or similar data structures, rather than hash tables. From Graham.Dumpleton at gmail.com Thu Jan 1 23:40:52 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 1 Jan 2009 20:40:52 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> Message-ID: <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> On Jan 2, 2:28?pm, excord80 wrote: > On Jan 1, 9:12?pm, s... at pobox.com wrote: > > > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > > ? ? >> sounds like it will be very handy. Anyone working on a > > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > > ? ? >> name? > > > It's kind of hard to tell. ?There's very little description of how > > mod_perlite would be different than mod_perl other than it would be more > > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > > well-defined requirement document. > > > Doesmod_wsgifit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > > I'm not sure if it fits the bill or not. The bill is two-fold: > > 1. The Apache module should present little risk to the admin who > installs it. That is, it should not expose Apache's innards. > > 2. The Apache module should keep a Python instance running; run, for > example, ``foo.py`` when a user accesses (for example) ``http://www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the > usual way; and return whatever html that script spits out. > > I'm not familiar with php or ``mod_php``, but I suspect that setup > does something very similar to what's described above. This might > explain why it's so blasted easy to deploy php scripts and create > small and simple sites (and even not-so-small/simple sites) with it. > > Doesmod_wsgifit that bill? I don't know. The docs seem to be athttp://code.google.com/p/modwsgi/w/list. Many of those are named > "ChangesInVersionXXXX". I don't see any that named anything like > "Introduction" or "BasicUsage" or "SimpleUsageLikeCGI" or even > "Tutorial". So, my guess is that ``mod_wsgi`` doesn't fit the bill. Have you looked up what the WSGI specification for Python even is? http://www.python.org/dev/peps/pep-0333/ http://www.wsgi.org/wsgi/Learn_WSGI Did you also read the front page of the wiki for mod_wsgi and follow the main links it gives on the front page? http://code.google.com/p/modwsgi/ http://code.google.com/p/modwsgi/wiki/InstallationInstructions http://code.google.com/p/modwsgi/wiki/DeveloperGuidelines If you understand what WSGI is, then you will realise that mod_wsgi is a very slim adapter for Apache that allows one to host any WSGI application. In the way one normally uses it, the internals of Apache are not exposed and do not need to be as the whole point of WSGI is that it is a portable interface for hosting Python web applications on various web hosting solutions and not Apache specifically. Back to whether it is equivalent to mod_perlite, that really depends on what mod_perlite does. If mod_perlite tries to enforce some sort of page template system like how PHP does then no mod_wsgi is not equivalent, as that isn't what WSGI itself is about. All WSGI is about is providing a most minimal interface for communicating with the web server, everything else has to be done by the application running on top of it. Thus WSGI and mod_wsgi is a light as it can get, perhaps even lighter than mod_perlite could be as it may have to embody the templating system, form handling, session management etc etc etc. This doesn't mean you couldn't use mod_wsgi to effectively achieve the same thing though, it just means your most minimal templating system, ie., like PHP or even closer to traditional Python CGI, needs to be implemented as an application on top of WSGI. Rather than do the dispatch in your WSGI application though, you can still use Apache to do the dispatching to individual file based resource files with the right configuration. How this could be done has been answered a number of times on mod_wsgi list as others have already wanted to know about how to do a PHP like solution in Python and so it has been discussed. If you want to talk more about this, come over to the mod_wsgi list on Google Groups. Graham From koranthala at gmail.com Fri Jan 2 00:48:34 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 21:48:34 -0800 (PST) Subject: initialization in python References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: <7bfb4f18-f133-4e2a-a11c-e339d2686acc@w1g2000prm.googlegroups.com> On Jan 1, 11:14?pm, Terry Reedy wrote: > koranth... at gmail.com wrote: > >>> Module database: > >>> ^^^^^^^^^^^^^^^^^^^ > >>> Session = None > > 'Initializing' names is not necessary. ?Delete this. ?Without it, your > error would be more obvious. > > >>> def init(dbname): > >>> ? ?engine = create_engine('sqlite:///%s' %dbname) > >>> ? ?... > >>> ? ?global Session > >>> ? ?Session = sessionmaker(bind=engine) > > This **rebinds* the module name 'Session' to a new object, making the > initial bindin irrelevant and misleading. > > [snip] > > > > > I guessed as much. But, I was under the impression that if the > > original value is modified, the variables value also will change. > > Python has names and slots bound to objects. ?Some objects are mutable > and some not. ?None is not mutable. ?You replaced it. > > If you had done something like > > Session = sessionmaker() > > def init(dbname): > ? ? ?Session.engine = create_engine('sqlite:///%s' %dbname) > ? ? ?... > > then you would have *modified* the original object (value) bound to > 'Session' and would have seen the behavior you expected. > > Terry Jan Reedy I did not think about it. I was using database.Session till now. I have now modified the code. Thank you very much, Terry Jan Reedy From ssalam at gmail.com Fri Jan 2 01:58:16 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Fri, 2 Jan 2009 12:28:16 +0530 Subject: Switching user in a SSH connection Message-ID: Hi Group, I am trying to connect to a Linux maching using paramiko. and able to run a command like "ls -l" Now I want to switch user being in the connection ( eg running something like "su -" ) Will you please let me know how to do that. Regds Shah From rt8396 at gmail.com Fri Jan 2 02:11:38 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 23:11:38 -0800 (PST) Subject: Why not Ruby? References: <016d66f1$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 1, 7:38?pm, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > > the use of "end" in a language as > > high level as Ruby is redundant, and idiotic. There are a few things > > about Ruby i really like, but this "end" business is blasphemy. > > "Blasphemy"? > > You really are an idiot. Programming languages are not religions. Step > away from the computer, and don't come back until you've grown up. > > And stop cross-posting, you rude little delinquent. > > -- > Steven Steven, Spare us your flamery, get on board, and be a part of the solution, and not just a constant problem to those you don't agree with. Or at least do like my friend Bruno, and send me up,up,and away to your bozo filter! Your one of the few trolls left that i have to deal with around here. And it's sad because sometimes you do offer good information. From rt8396 at gmail.com Fri Jan 2 02:54:36 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 23:54:36 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: On Jan 1, 4:40?pm, Robert Kern wrote: > Hamish McKenzie wrote: > > sometimes I want to be able to initialize an instance with a variety of different data types. > > > as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > > > is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > > I recommend keeping the __init__() as dumb as possible. Ideally, it should just > assign to attributes. I would add a from() classmethod for each that > I wanted to support. If I really wanted an all-singing, all-dancing > initialization method, I would add another classmethod that would just dispatch > to the appropriate type-specific classmethod. I prefer classmethods to plain > functions because I can subclass. > > -- > 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 Why are you busting into this thread? why have you not created your own thread. Someone asked a question about recycle bin access and you come in here, bust down the door and ask a completely off topic question, which is OK if you start a new thread of your own. And the most insane part to all of this, is that Steven just plays right along?!?!? Come on Stevie, you know better than this! PS (To OP) mark hammonds win32 package will not do what you ask, sorry From dotancohen at gmail.com Fri Jan 2 03:42:27 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 2 Jan 2009 10:42:27 +0200 Subject: Easy-to-use Python GUI In-Reply-To: <6s2n0sF408fuU1@mid.uni-berlin.de> References: <6s2n0sF408fuU1@mid.uni-berlin.de> Message-ID: <880dece00901020042m69878826y896c67b2fceacb3c@mail.gmail.com> 2009/1/1 Gerhard H?ring : > Dotan Cohen wrote: >> >> I have been following this thread with interest. Is there a way to >> build Qt apps with relative easy? I use KDE and would prefer the Qt >> toolkit for my GUI apps. Thanks. > > A few years ago, I've had bad experiences with wxPython (random things not > actually working on Linux, only on Windows; getting segfaults when using not > exactly the right values for API calls). > > So, when I had to decide for a toolkit for a new application I'm developing > on my job which required: > > - ability to run on Windows > - ability to run on MacOS > - time to develop is short > > I recommended to go with PyQt. > > I remembered it was warmly recommended by Alex Martelli and others a few > years ago. > > So far, it's been nothing but joy. We bought the book "Rapid GUI Programming > with Python and Qt" (http://www.qtrac.eu/pyqtbook.html) which is *really* > well written. It's probably the best tech book I ever had. The author > formerly did Qt documentation for Trolltech, so he has deep understanding of > what he's writing about. > > There may be not so many third-party add-ons for PyQt like for wxPython, > but in my opinion, the quality of Qt, PyQt and documentation like the book > make up for it. > > And, it's really extensive. So far I've found everything in Qt/PyQt I > wanted/needed: > > - MDI workspaces > - Dock windows > - I needed something like wxPythons wxOGL for a process modeler and after > looking around for two days, I found out that it's already all there in Qt > 4.4: QGraphicsScene/QGraphicsView > - etc. > Thank you. I just googled the book and it seems to be Python 2 only, which is not surprising considering that Python 3 just came out. I will purchase a copy as soon as it is updated for Python 3. Thanks! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From no-spam at no-spam.invalid Fri Jan 2 04:07:54 2009 From: no-spam at no-spam.invalid (robert) Date: Fri, 02 Jan 2009 10:07:54 +0100 Subject: similar words index? Message-ID: how can one index (text documents) for efficient similar word search? existing modules? what principles are used by search engines therefore? From bockman at virgilio.it Fri Jan 2 04:12:50 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 10:12:50 +0100 Subject: yacc statement recognition [PLY] In-Reply-To: References: Message-ID: <495dda95$0$749$5fc30a8@news.tiscali.it> Slafs ha scritto: > Hi ALL! > > I have to write in yacc an acceptor of files with lines matching this > regexp: > '[0-9],[0-9]' > and I don't know what I am doing wrong beacuse this: > > -------- > tokens = ( > 'NUMBER', > ) > literals = [','] > > t_NUMBER = r'\d' > > ... > > def p_statement_exp(p): > '''statement : NUMBER ',' NUMBER > ''' > print "OK!" > sys.exit() > ------- > > also accepts lines like 2,abcdef3 which of > could someone please tell me what's wrong in my code? > > full source on http://paste-it.net/public/vba22d5/ Your code works for me (Python 2.5 and ply 2.3 on ubuntu 8.10), except that, from the rest of your code, I see that you parse separately each line of file. Since you put a sys.exit() in the parsing rule, it means that at the first line successfully parsed your program will quit. Try putting a simple print in it and instead putting the sys.exit in your p_error function (if you want to exit at the first 'wrong' line line). BTW, are you aware that exists a specific google group for ply users? Specific ply questions could be answered here : http://groups.google.com/group/ply-hack?pli=1 Ciao ---- FB From tino at wildenhain.de Fri Jan 2 04:22:18 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 02 Jan 2009 10:22:18 +0100 Subject: Switching user in a SSH connection In-Reply-To: References: Message-ID: <495DDCCA.60009@wildenhain.de> Shah Sultan Alam wrote: > Hi Group, > I am trying to connect to a Linux maching using paramiko. > and able to run a command like "ls -l" > > Now I want to switch user being in the connection ( eg running > something like "su -" ) > > Will you please let me know how to do that. You would for example run su - in that connection? Or sudo if installed and configured. What else would you need? Tino. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From sjmachin at lexicon.net Fri Jan 2 04:32:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 01:32:51 -0800 (PST) Subject: similar words index? References: Message-ID: <6736f1d6-c1ab-42cb-8c91-bf832bfd4f76@b41g2000pra.googlegroups.com> On Jan 2, 8:07?pm, robert wrote: > how can one index (text documents) for efficient similar word search? > existing modules? > what principles are used by search engines therefore? Only your second question is on-topic for this newsgroup. Try this: http://pylucene.osafoundation.org/ Looking at the site for Lucene itself, where you should find references to the various technologies they use, and some (definitely recommended) googling should give you some clues about your other questions. Some computer science topics are: Burkhard-Keller tree, Voronoi diagram/tree, permuted lexicon ... do bear in mind that what is actually used in the real-world search engines like Google may be rather difficult to find out; Google sure ain't open source, not any more. HTH, John From usenet-nospam at well-adjusted.de Fri Jan 2 04:54:59 2009 From: usenet-nospam at well-adjusted.de (Jochen Schulz) Date: Fri, 2 Jan 2009 10:54:59 +0100 Subject: similar words index? References: Message-ID: * robert: > how can one index (text documents) for efficient similar word search? > existing modules? I implemented one approach in mspace.py: http://well-adjusted.de/mspace.py/ But beware that it is pure Python and not optimized for speed. You gain quite a lot by having Psyco installed, though. J. -- I count my partner's eyelashes. [Agree] [Disagree] From code at pizzashack.org Fri Jan 2 05:39:15 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 04:39:15 -0600 Subject: why cannot assign to function call In-Reply-To: <200812301421.29888.mail@johnohagan.com> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: <20090102103915.GJ28417@dragontoe.org> On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > Fortunately, unlike the murky world of philosophy, Python (AIUI) > simplifies this question by simply declaring that yes, in the case > of mutable objects, we may say that we are still referring to the > same object although we've changed it, and no, in the case of > immutable objects, we may not, and must exchange it if we want a > different "value" (a word too fraught with ambiguity in this context > to use unquoted!). That's sort of true; it would seem to be more accurate to say that whenever a name is assigned to an object and subsequently reassigned, the name no longer is associated with the original object. In the case of mutable objects, the object can be changed by performing an assignment of *part* of the object through its original name, i.e. strings may be mutable, but the following code still produces two different objects: a = 'hello' a = 'goodbye' The first object so created is orphaned; it's been given the Russian non-person treatment. It still exists, but the authorities (i.e. the python interpreter) don't acknowledge it and provide the rest of the world no way to communicate with it, and eventually it is reaped by the garbage collector. :) What the Python community often overlooks, when this discussion again rears its ugly head (as it seems to every other hour or so), is that its assignment model is BIZARRE, as in it's conceptually different from virtually all other languages substantially taught in undergraduate computer science programs. And for that matter, it's pretty unintuitive generally. That is, in what I'll call "normal" computer languages, a variable name is thought of as the address of a bin where some data is stored, and the name is inexorably tied to that bin. You can change what's in the bin, but the name you gave the bin always points to the same bin. This tends to be conceptually true even if it might technically not be true in a given implementation of a language. Python is very different from this. Names are not addresses of bins; they are instead simply ephemeral labels which are given to bins, where the bin is a Python object which contains specific data at the time of assignment. A second assignment of that name doesn't change what's in the original bin; it actually (probably) first creates a new bin, then removes the name from the original bin and assigns it to the new one. Intuitively, it's a bit like saying your kitchen table is no longer a kitchen table, and now the thing where you wash your dishes is a kitchen table. It doesn't really make a lot of sense (whether or not it's so for good reason), and it makes describing the assignment model necessarily convoluted, whereas the "named bins" model from the majority of other languages people are likely to have been exposed to is simple and sensible. It's small wonder that neophytes try to cram Python behaviors into terms and computing concepts they already understand from learning other languages, and that they fail to do so. What's mystifying is that when Pythonistas reply to their messages, they universally seem confused at how this could possibly happen, and often enough actually seem offended (or at least offensive) when it inevitably does happen... -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From bearophileHUGS at lycos.com Fri Jan 2 05:43:41 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 02:43:41 -0800 (PST) Subject: similar words index? References: Message-ID: <4a1e6211-03b0-4c54-bdcb-54f04344dcc5@q26g2000prq.googlegroups.com> Jochen Schulz: > I implemented one approach in mspace.py: > http://well-adjusted.de/mspace.py/ > But beware that it is pure Python and not optimized for speed. You gain > quite a lot by having Psyco installed, though. Something similar, I haven't compared performance, Psyco helps a lot here too: http://code.activestate.com/recipes/572156/ (I have also implemented the same code in D language through a bridge created by Pyd, more than 100 times faster). Bye, bearophile From code at pizzashack.org Fri Jan 2 05:52:21 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 04:52:21 -0600 Subject: why cannot assign to function call In-Reply-To: <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: <20090102105221.GK28417@dragontoe.org> On a mostly not related note: On Tue, Dec 30, 2008 at 07:52:26AM -0800, Aaron Brady wrote: > According to some rules, these are ungrammatical sentences, due to > plurality disagreement. Ex: > > The Morning Star is ... > The Evening Star is ... > *The Morning Star and The Evening Star is... > *The Morning Star and The Evening Star are... > > Neither of the latter two is correct. (* marks ungrammatical.) As > such, the listener isn't sure what meaning to take. This statement is false. The latter of the two is grammatically correct. The subject is a compound subject joined by the conjunction "and" which indicates that there are two subjects, and thus the plural form of the verb is necessary and correct. > Identity isn't defined on math objects, only on Python objects; there > is no notion of 'is' in math. This is also false, it even has its own operator (which requires Unicode to display): ? Still, the point you're trying to make is right: this stuff is hard to talk about, and the model actually encourages the use of ambiguous or even contradictory explanations. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 06:15:25 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 12:15:25 +0100 Subject: Why not Ruby? In-Reply-To: <016d66f1$0$8693$c3e8da3@news.astraweb.com> References: <016d66f1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <495e04fb$0$24380$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > (snip stupid troll) > > You really are an idiot. Steven, this bozo is just another Xah Lee, so don't waste your time with him. We all know how to deal with trolls, don't we ? From koranthala at gmail.com Fri Jan 2 06:31:17 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 2 Jan 2009 03:31:17 -0800 (PST) Subject: Python logging question Message-ID: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Hi, I was reading through Python Logging tutorial, and I found one scenario which I couldnt properly understand. The tutorial (http://docs.python.org/library/logging.html) mentions at first that -- "Multiple calls to getLogger() with the same name will return a reference to the same logger object". In an example for Python Logging Adapter, the tutorial then mentions that - "While it might be tempting to create Logger instances on a per- connection basis, this is not a good idea because these instances are not garbage collected". I am confused reading both together. I will try to explain my confusion with an example: basicLogger = logging.getLogger("basic") Class A(): def __init__(self): self.logger = logging.getLogger("basic.class_a") Now, I make say 10 instances of A and then delete one by one. My understanding was that since the same name is used, a single basic.class_a logger object is created inside the logging system, and any calls to getLogger("basic.class_a") would return the same object everytime. So, my confusion is based on the second tutorial item I mentioned - why is it not a good idea to create logger instances on a per-instance basis? We are not creating new instances, right? And, if I create an instance of A, it will be garbage collected later, right? Could somebody help me out? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 06:38:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 11:38:23 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <016df39f$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 16:19:38 -0800, Fuzzyman wrote: > On Jan 2, 12:16?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: >> > On many occasions I've wished for a functional dictionary >> > implementation in Python, like Haskell's Data.Map. ?One of these >> > years I'll get around to writing one. >> >> You don't think Python's dict implementation is functional? That's >> pretty strange, Python dicts are the basis of much of the language. >> They certainly work, and work well, what makes you think they aren't >> functional? What does Data.Map do that dicts don't? >> >> > He almost certainly (I assume) means functional in the way that Haskell > is a functional language. *slaps head* D'oh! Er, I mean... Of course, I knew that, I was checking to see if anyone else did. *cough* -- Steven From hendrik.kaju at gmail.com Fri Jan 2 07:14:08 2009 From: hendrik.kaju at gmail.com (Hendrik Kaju) Date: Fri, 02 Jan 2009 14:14:08 +0200 Subject: Open Source survey Message-ID: <1230898448.7751.0.camel@gecko3> Dear developers My name is Hendrik Kaju and I am a high school student and an open source enthusiast (and a Python programmer) from Estonia. As a part of my school project, I am conducting a survey on open source software development (how developing OSS is related to a developer's day job, etc). It is located at http://www.surveygizmo.com/s/90385/open-source I would really appreciate it if you could take a few minutes to fill out this short survey. Best regards, Hendrik Kaju -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: See on s?numi digitaalselt allkirjastatud osa URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 07:45:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 12:45:36 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> Message-ID: <016e0360$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: > He was not cross posting. You don't actually know what cross-posting is, do you? You've just earned a plonking for the next month. Do try to have at least half a clue by February. -- Steven From vinay_sajip at yahoo.co.uk Fri Jan 2 08:21:35 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 2 Jan 2009 05:21:35 -0800 (PST) Subject: Python logging question References: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Message-ID: On Jan 2, 11:31 am, koranth... at gmail.com wrote: > I am confused reading both together. I will try to explain my > confusion with an example: > > basicLogger =logging.getLogger("basic") > > Class A(): > def __init__(self): > self.logger =logging.getLogger("basic.class_a") > > Now, I make say 10 instances of A and then delete one by one. > > My understanding was that since the same name is used, a single > basic.class_a logger object is created inside theloggingsystem, and > any calls to getLogger("basic.class_a") would return the same object > everytime. That is correct. The logger instances stay around for the life of the process, and are not garbage collected. > So, my confusion is based on the second tutorial item I mentioned - > why is it not a good idea to create logger instances on a per-instance > basis? We are not creating new instances, right? And, if I create an > instance of A, it will be garbage collected later, right? > It's not a problem to create loggers per *class*, as in your example. It can be a bad idea to create different logger per class *instances*. The second example in the docs talks about creating loggers on a per- connection basis in a networked app. This is not per connection class, mind you, but per connection instance. You would typically have only a few dozen classes, but you might have hundreds of thousands of connection instances created in a long-lived server app. If you created a unique logger for each connection, for example based on the time the connection was instantiated - e.g. with name "connection. 20090102123456543", this would create hundreds of thousands of unique logger instances and have a potentially adverse impact on process memory. That's when you use LoggerAdapters. I hope that's clearer. Regards, Vinay Sajip From koranthala at gmail.com Fri Jan 2 08:38:41 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 2 Jan 2009 05:38:41 -0800 (PST) Subject: Python logging question References: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Message-ID: <4e629256-e620-4c80-900e-1e8d276bf0ac@d36g2000prf.googlegroups.com> On Jan 2, 6:21?pm, Vinay Sajip wrote: > On Jan 2, 11:31 am, koranth... at gmail.com wrote: > > > ? ? I am confused reading both together. I will try to explain my > > confusion with an example: > > > basicLogger =logging.getLogger("basic") > > > Class A(): > > ? def __init__(self): > > ? ? ?self.logger =logging.getLogger("basic.class_a") > > > ? ?Now, I make say 10 instances of A and then delete one by one. > > > My understanding was that since the same name is used, a single > > basic.class_a logger object is created inside theloggingsystem, and > > any calls to getLogger("basic.class_a") would return the same object > > everytime. > > That is correct. The logger instances stay around for the life of the > process, and are not garbage collected. > > > So, my confusion is based on the second tutorial item I mentioned - > > why is it not a good idea to create logger instances on a per-instance > > basis? We are not creating new instances, right? And, if I create an > > instance of A, it will be garbage collected later, right? > > It's not a problem to create loggers per *class*, as in your example. > It can be a bad idea to create different logger per class *instances*. > The second example in the docs talks about creating loggers on a per- > connection basis in a networked app. This is not per connection class, > mind you, but per connection instance. You would typically have only a > few dozen classes, but you might have hundreds of thousands of > connection instances created in a long-lived server app. If you > created a unique logger for each connection, for example based on the > time the connection was instantiated - e.g. with name "connection. > 20090102123456543", this would create hundreds of thousands of unique > logger instances and have a potentially adverse impact on process > memory. That's when you use LoggerAdapters. > > I hope that's clearer. > > Regards, > > Vinay Sajip Thank you very much Vinay. I was confused by the way it was mentioned in the tutorial. Again, Thank you Regards Koranthala From stef.mientki at gmail.com Fri Jan 2 08:39:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 02 Jan 2009 14:39:25 +0100 Subject: Triple quoted string in exec function ? In-Reply-To: <495A253B.6010003@gmail.com> References: <495A253B.6010003@gmail.com> Message-ID: <495E190D.2090904@gmail.com> Stef Mientki wrote: > hello, > > I'm running scripts, with the execute function (Python 2.5), > and it seems that triple quoted strings are not allowed. > > Is there a workaround, > or is this a fundamental problem of the exec-function ? > > thanks, > Stef Mientki thanks for all the answers, but I still don't understand it yet :-( So maybe someone could explain why the next few lines of code don't work: Code = '' Code += """multiline comment and more lines""" exec ( Code ) thanks, Stef Mientki From Brian.Kelly at uwsp.edu Fri Jan 2 09:09:26 2009 From: Brian.Kelly at uwsp.edu (Kelly, Brian) Date: Fri, 2 Jan 2009 08:09:26 -0600 Subject: FW: python import sys.path Message-ID: After following your suggestions I was able to confirm that the 2.5 interpreter was being invoked. So then I grepped for all instances of python in the scripts that were imported as modules: from bacula_conf import * The calling script cleanup.py is invoking purge_client.py like an external script: def purgeAll(options, computer_name): cmd = "python purge_client.py %s" % computer_name if options.pretend <> True: error = os.system(cmd) else: _log.info("Done. No changes made due to --pretend flag.") if not error: return True else: return False When I saw the imports I assumed the functions in purge_client.py were being referenced from the calling scripts symbol table. However, that is not the case. Thanks, Brian -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Tuesday, December 30, 2008 4:42 PM To: python-list at python.org Subject: Re: python import sys.path On Dec 31, 5:05?am, "Kelly, Brian" wrote: > I have both 2.4 and 2.5 interpreters installed on a linux box. The > PythonPath is set to : > > PYTHONPATH=/usr/lib64/portage/pym:/prod/bacula/local/lib64/python2.4/site-pa > ckages:/prod/bacula/local/lib/python2.4/site-packages > > My main script is getting called like so: > > python2.4 cleanup.py wrkstnbs > > The imports statements in cleanup.py are as follows: > > import os,sys > print sys.path > from datetime import datetime > from optparse import OptionParser ? ? ? ?# used for parsing parameters > from bacula_conf import * ? ? ? ? ? ? ? ?# used for connecting to our > databases, etc. > from registration_cleanup \ > ? ? import RegistrationCleanup ? ? ? ? ? # used for interacting w/ > registration db (sql1) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# and configuration database > (genunix) > import directory_cleanup as fclean ? ? ? # file cleanup. > > One of the scripts being imported from bacula_conf is called > purge_client.py. > > It has the following imports: > > import sys > import MySQLdb > > Everytime I run "python2.4 cleanup.py wrkstnbs" I get the following error: > > Traceback (most recent call last): Have you snipped any traceback entries here? You say you are running cleanup.py but the first traceback entry is from purge_client.py!! You should first fix that, so that you've got the full story. My guess is that something along that trail is invoking another instance of the Python interpreter and somehow that instance is 2.5, not 2.4. I can't imagine how those 2.5-related entries would otherwise get into sys.path Suggestions: (1) where you are debug-printing sys.path, also print sys.version and sys.argv[0] ... and do debug-printing at more places between start and error. (2) run "python2.4 -vv cleanup.py wrkstnbs" and look for the first mention of 2.5 (indicating something has manipulated sys.path), or sudden cessation of -vv output (indicating a new instance of python is running without -vv), or some other phenomenon ... > ? File "purge_client.py", line 22, in > ? ? import MySQLdb > ? File > "/prod/bacula/local/lib64/python2.4/site-packages/MySQLdb/__init__.py", line > 27, in > ? ? import _mysql > ImportError: /prod/bacula/local/lib64/python2.4/site-packages/_mysql.so: > undefined symbol: Py_InitModule4 What happens when you run python2.4 and at the interactive prompt do >>> import _mysql ? Is there a possibility that you installed 2.5 MySQLdb into the 2.4 hierarchy? [could be a stupid question from a windows guy; this may be a non-problem on linux] Is this the first thing that you've tried after installing 2.5, or the only problem found in an exhaustive regression test of all your apps using 2.4, or somewhere in the middle? [big snip] HTH, John -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 5082 bytes Desc: not available URL: From sjmachin at lexicon.net Fri Jan 2 09:18:06 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 06:18:06 -0800 (PST) Subject: Triple quoted string in exec function ? References: <495A253B.6010003@gmail.com> Message-ID: On Jan 3, 12:39?am, Stef Mientki wrote: > Stef Mientki wrote: > > hello, > > > I'm running scripts, with the execute function (Python 2.5), > > and it seems that triple quoted strings are not allowed. > > > Is there a workaround, > > or is this a fundamental problem of the exec-function ? > > > thanks, > > Stef Mientki > > thanks for all the answers, > but I still don't understand it yet :-( > So maybe someone could explain why the next few lines of code don't work: Stef, "it doesn't work" is user-speak. Say what what you expected, and what happened instead. > Code = '' > Code += """multiline comment > and more lines""" > exec ( Code ) That is equivalent to: code = "multiline comment\nand morelines" exec(code) which of course produces a Syntax Error. What did you expect? Oh, yeah, the so-called "multiline comment". I can't imagine why you want to put comments in code that you're going to exec, but you need an extra layer of quotes: Code += '''"""multiline comment and more lines"""''' From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 09:24:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 14:24:39 GMT Subject: Triple quoted string in exec function ? References: <495A253B.6010003@gmail.com> Message-ID: <016e1a94$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 14:39:25 +0100, Stef Mientki wrote: > thanks for all the answers, > but I still don't understand it yet :-( So maybe someone could explain > why the next few lines of code don't work: > > Code = '' > Code += """multiline comment > and more lines""" > exec ( Code ) You don't actually tell us what you expect to happen, so I'm going to take a wild guess. You are expecting that the contents of Code above should be a triple-quoted string, which Python treats as a comment when it is on its own (unless it is a doc string). A clue as to what is going on: >>> s = "x = 1" >>> print s x = 1 >>> exec s >>> x 1 Notice that even though the string s is created with delimiters ", the quote marks are not part of the string. Whether you use delimiters " ' ''' or """ doesn't matter, the delimiters are not part of the string. If you want quote marks *inside* the string, you need to include them as characters, not as delimiters: >>> s = "y = " # using " as delimiters >>> s += 'abc' # using ' as delimiters >>> print s # no quotes inside s y = abc >>> exec s Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'abc' is not defined >>> s = "y = " >>> s += '"abc"' # quotes inside the string >>> print s # includes quotes inside s y = "abc" >>> exec s >>> y 'abc' The fact that your earlier example used """ as delimiters instead of " is irrelevant. The delimiters are not part of the string, and so aren't seen by exec. There's no problem with exec and triple-quoted strings. You're just not giving it a triple-quoted string to work with. Another thing, you wrote: Code = '' Code += """multiline comment and more lines""" That's a little like saying: x = 0 x += 1 instead of just x = 1. Except that in general, string concatenation is potentially MUCH MUCH MUCH slower than addition. (If you haven't noticed the slow down, you're lucky you haven't hit the right circumstances.) s = """multiline comment and more lines""" makes a string s that starts with the letter m: >>> print s multiline comment and more lines That's no different from any other string delimiters. The delimiters are never part of the string. You want the string to start with three quotation marks, not m, so you have to include the quote marks inside the string. To do that, you need to use two different quote delimiters: >>> s = """'''multiline comment ... and more lines'''""" >>> print s '''multiline comment and more lines''' >>> exec s >>> Works perfectly. -- Steven From steve at holdenweb.com Fri Jan 2 09:25:32 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 09:25:32 -0500 Subject: If your were going to program a game... In-Reply-To: <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> Message-ID: Aaron Brady wrote: > On Jan 1, 2:55 pm, "Chris Rebert" wrote: >> On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: >>> On Jan 1, 2:37 pm, Kay Schluehr wrote: >>>> There is no solution to this problem from a Python perspective. Do >>>> what everyone does right now: [snip] >>> It still surprises me that no one has implemented the solution for >>> this yet. >>> Maybe it's harder than it seems, but it *seeems* like it's just a >>> matter of telling Firefox, "hey, when you see this special html >>> element that tells you to run this python code from the web, do it". >>> Then have FF load up a python interpreter, sandbox it somehow (that >>> is, limit it to only a safe subset of its std lib), it runs the code >> The "sandbox it somehow" part is significantly harder than you seem to >> believe it would be. Python tried previously with the rexec and >> Bastion modules, but they were found to be irreparably flawed and thus >> were removed. > > Suppose you compiled a version with no file type and a reduced os > module? "Cars are dangerous". "Yes, but suppose you made them completely elastic". Sheesh. The developers are way less dumb than you seem to believe. Suppose you did compile a version with no file type and a reduce os module? Perhaps you would like to do some research into *why* rexec and bastion were dropped from the implementation. Or read Brett Cannon's work on "safe" execution of arbitrary Python. That way you would stop making fatuous suggestions that don't help anybody. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Fri Jan 2 09:28:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 06:28:15 -0800 (PST) Subject: FW: python import sys.path References: Message-ID: <68177ab8-f073-4767-86b6-9abf8c331e36@r10g2000prf.googlegroups.com> On Jan 3, 1:09?am, "Kelly, Brian" wrote: > After following your suggestions I was able to confirm that the 2.5 > interpreter was being invoked. So then I grepped for all instances of python > in the scripts that were imported as modules: from bacula_conf import * > > The calling script cleanup.py is invoking purge_client.py like an external > script: > > def purgeAll(options, computer_name): > ? ? cmd = "python purge_client.py %s" % computer_name > ? ? if options.pretend <> True: Who wrote that? > ? ? ? ? error = os.system(cmd) > ? ? else: > ? ? ? ? _log.info("Done. No changes made due to --pretend flag.") #### error is not defined in this branch > ? ? if not error: #### Splat! > ? ? ? ? return True > ? ? else: > ? ? ? ? return False AArrgh! Try: return not error > When I saw the imports I assumed the functions in purge_client.py were being > referenced from the calling scripts symbol table. What does that mean?? From excord80 at gmail.com Fri Jan 2 09:49:03 2009 From: excord80 at gmail.com (excord80) Date: Fri, 2 Jan 2009 06:49:03 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> Message-ID: On Jan 1, 11:40?pm, Graham Dumpleton wrote: > On Jan 2, 2:28?pm, excord80 wrote: > > > > > On Jan 1, 9:12?pm, s... at pobox.com wrote: > > > > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > > > ? ? >> sounds like it will be very handy. Anyone working on a > > > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > > > ? ? >> name? > > > > It's kind of hard to tell. ?There's very little description of how > > > mod_perlite would be different than mod_perl other than it would be more > > > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > > > well-defined requirement document. > > > > Doesmod_wsgifit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > > > I'm not sure if it fits the bill or not. The bill is two-fold: > > > 1. The Apache module should present little risk to the admin who > > installs it. That is, it should not expose Apache's innards. > > > 2. The Apache module should keep a Python instance running; run, for > > example, ``foo.py`` when a user accesses (for example) ``http://www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the > > usual way; and return whatever html that script spits out. > > > I'm not familiar with php or ``mod_php``, but I suspect that setup > > does something very similar to what's described above. This might > > explain why it's so blasted easy to deploy php scripts and create > > small and simple sites (and even not-so-small/simple sites) with it. > > > Doesmod_wsgifit that bill? I don't know. [snip] > > Have you looked up what the WSGI specification for Python even is? > > ?http://www.python.org/dev/peps/pep-0333/ > ?http://www.wsgi.org/wsgi/Learn_WSGI > Hi Graham, thanks for the links. I took a quick look at some of the articles on the Learn_WSGI page, but regrettably, my free time for this stuff has evaporated for now. > If you understand what WSGI is, then you will realise that mod_wsgi is > a very slim adapter for Apache that allows one to host any WSGI > application. [snip] > > All WSGI is about > is providing a most minimal interface for communicating with the web > server, It sounds interesting, however, after reading a bit about it, I see that a large part of wsgi is providing a nice interface between web server and webapp. I don't think I need any such interface, or at least, a replacement for CGI. I just need something like CGI but with a persistent Python so the web server doesn't have to restart python for every request. And I don't need need it to work with anything else other than Apache. I think that actually probably sums up what a lot of users want. For better or worse, most people use Apache. Apache works and is free software. And it's either already installed, or easy to install. And shared hosting providers already have it available. > This doesn't mean you couldn't use mod_wsgi to effectively achieve the > same thing though, [snip] I can't say I understand the details of wsgi, but if it does what I'm asking, and if shared hosting providers can be coaxed into installing mod_wsgi, then I think a fast-track to wide adoption for wsgi would be to provide an out-of-the-box drop-in little-to-no-configuration- required solution for getting php-style small webapps going as described above. If your answer to that is, "Oh no! WSGI is more general than that! You can do it, but can also do X, Y, Z ...", then I'm sorry, but I don't have the time right now to learn about all the details, and about things like Paste and middleware. Again, I'm only using Apache, and I only want the script to run when I access it in a url and to get its output back to the browser. Yes, I realize this is bush-league, but the php folks have been doing it for a long while now, and it works ok for small webapps and shared hosting setups, so I'm reluctant to thumb my nose at it. > If you want to talk more about this, come over to the mod_wsgi list on > Google Groups. Thank you, but, as I mentioned, my free time right now is in the negative numbers. Bleh. I wish it weren't so. From geekmail at usenot.de Fri Jan 2 10:00:14 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 16:00:14 +0100 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> Message-ID: <20090102160014.47a330c5@usenot.de> On 02 Jan 2009 12:45:36 GMT Steven D'Aprano wrote: > You've just earned a plonking for the next month. Do try to have at > least half a clue by February. I will state again that there seems to have been a slight change of tone in clp lately. How about we Python guys work a bit harder on not calling each other names and such? Not that I have a particular problem with *what* Steven said here, but it could have been phrased a tad more calmly, just for the sake of not stirring up unnecessary feelings of defiance. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From BrooklineTom at gmail.com Fri Jan 2 10:01:33 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Fri, 2 Jan 2009 07:01:33 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: On Dec 31 2008, 9:56 am, John Machin wrote: > On Dec 31 2008, 4:02 pm, brooklineTom wrote: > > > andyh... at gmail.com wrote: > > > Hi, > > > > Can anybody recommend an approach for loading and parsing Excel > > > spreadsheets in Python. Any well known/recommended libraries for this? > > > > The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, > > > but I'd rather get some more input before going with something I don't > > > know. > > > > Thanks, > > > Andy. > > > I save the spreadsheets (in Excel) in xml format. > > Which means that you need to be on a Windows box with a licensed copy > of Excel. I presume you talking about using Excel 2003 and saving as > "XML Spreadsheet (*.xml)". Do you save the files manually, or using a > COM script? What is the largest xls file that you've saved as xml, how > big was the xml file, and how long did it take to parse the xml file? > Do you extract formatting information or just cell contents? 1. The OP requested Excel files, by construction those must be generated with a licensed copy of Excel. I did the actual processing on both linux and windoze platforms. 2. Yes, I used Excel 2003. I haven't looked at later versions. 3. The largest file I used was about 228M, containing 36,393 hotel properties from Commission Junction. Each entry had 113 cells. The parsing overhead was minimal (on a per-entry basis) -- that's why I choose to use a pull-parser. 4. I extracted primarily cell contents, though I did some very limited format handling (looking for non-text fields and such). > > I started with the > > standard xml tools (xml.dom and xml.dom.minidom). I built a > > pullparser, and then just crack them. The MS format is tedious and > > overly complex (like all MS stuff), but straightforward. > > What do you think of the xml spat out by Excel 2007's (default) xlsx > format? I haven't looked at this. > > Once I've > > cracked them into their component parts (headers, rows, cells, etc), > > then I walk through them doing whatever I want. > > > I found this material to be no worse than doing similar crud with > > xhtml. I know there are various python packages around that do it, but > > I found the learning curve of those packages to be steeper than just > > grokking the spreadsheet structure itself. > > I'm curious to know which are the "various python packages" with the > so steep learning curves, and what the steep bits were. I looked, briefly, at xlrd. I found and scanned a few alternatives, though I don't remember what the others were. I needed something I could incorporate into my own application framework, and I knew I didn't need most of the formatting information. I'm not in any way criticizing xlrd, it's simply that, based on its API summary, it seems focused on problems I didn't have to solve. I knew that I needed only a small subset of the xlrd behavior, and I concluded (perhaps incorrectly) that it would be easier to roll my own parser than find, extract, and then port (to my own framework) the corresponding parts of xlrd. I needed to extract the content of each row, cell by cell, and build data objects (in my framework) with the content of various cells. I also needed to build an "exception file" containing malformed entries that I could re-open with Excel after my code finished, so that the bogus entries could be manually corrected. What I mean by "malformed" entry is, for example, an address field that fails to correctly geocode or comment fields with confused utf8/unicode contents. My focus was on data content, as opposed to presentation. I needed to crack the cells into things like "string", "boolean", "float", and so on. Most importantly, I needed to do this one entry at a time -- I did *not* want to load the entire spreadsheet at once. I'm not saying that this couldn't be done with xlrd; only that I chose to roll my own and had minimal difficulty doing so. I hope this helps! From james at agentultra.com Fri Jan 2 10:02:10 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 10:02:10 -0500 Subject: If your were going to program a game... References: Message-ID: <85eizlhhu5.fsf@dozer.localdomain> Tokyo Dan writes: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. Ever see chess.com? I don't know what they're using in the backend, but the client is entirely javascript. You could probably roll your own python javascript compiler to suit your needs. It could probably even build up your own DSL for writing these games. It's a worthwhile project and I think there might be support for it from other developers. From vinay_sajip at yahoo.co.uk Fri Jan 2 10:20:39 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 2 Jan 2009 07:20:39 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'DatagramHandler' (ubuntu-8.10, python 2.5.2) References: <4c6f0831-c05f-401f-b956-376600b38e06@r15g2000prd.googlegroups.com> Message-ID: <5958c48b-721e-45ae-9951-825317a7d0d5@g3g2000pre.googlegroups.com> On Dec 29 2008, 12:18 pm, "Chris Rebert" wrote: > > "The StreamHandler and FileHandler classes are defined in the coreloggingpackage. The other handlers are defined in a sub- module,logging.handlers." > > There's your answer. I do agree though that the "classlogging.DatagramHandler" line in the docs is misleading to say the > least. Perhaps a docs bug should be filed... > This should now be fixed in the current docs - thanks to Georg Brandl (creator of the Python documentation system). Regards, Vinay Sajip From victorsubervi at gmail.com Fri Jan 2 10:24:59 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 2 Jan 2009 16:24:59 +0100 Subject: =?ISO-8859-1?Q?Re:_Can=B4t_Surf_Python_Pages_in_Windoze?= In-Reply-To: References: <4dc0cfea0812260701q6baf0ccbj154c5b3fa2281cdb@mail.gmail.com> <4954FB9F.5050702@wildenhain.de> <4dc0cfea0812260911k4dbc0f2ame9cc874e067b7816@mail.gmail.com> Message-ID: <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> On Fri, Dec 26, 2008 at 8:00 PM, Gabriel Genellina wrote: > En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi < > victorsubervi at gmail.com> escribi?: > >> On 12/26/08, Tino Wildenhain wrote: >> > > print "Content-Type: text/html" >>>> print >>>> print """ >>>> >>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>> >>> > I think there should be only one blank line between header and content, you > have two (so the document contains an empty line before the doctype > declaration, and I think this is invalid). > Will try. Thanks. Let you know next week if problem. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From mamingcao at gmail.com Fri Jan 2 10:45:10 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:45:10 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop Message-ID: Hi all, I'm new to here and python. When I tried the code below to test python's speed... I found that python use more than 1.5G memory to run this and cost several minutes.... And this happened only under my linux os. Both jython and python... Is there something wrong with python under linux or my code? Thanks! a = 0 for i in range(100000000): a = a + 1 print a From michele.simionato at gmail.com Fri Jan 2 10:49:02 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 2 Jan 2009 07:49:02 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: On Jan 2, 4:45?pm, ming_cuhk wrote: > Hi all, I'm new to here and python. > When I tried the code below to test python's speed... > I found that python use more than 1.5G memory to run this and cost > several minutes.... And this happened only under my linux os. Both > jython and python... ?Is there something wrong with python under linux > or my code? > Thanks! > > a = 0 > for i in range(100000000): > ? ? a = a + 1 > print a This is fixed in Python 3.0. In older Python versions, use xrange instead of range. From mamingcao at gmail.com Fri Jan 2 10:50:32 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:50:32 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: On Jan 2, 11:49?pm, Michele Simionato wrote: > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > Hi all, I'm new to here and python. > > When I tried the code below to test python's speed... > > I found that python use more than 1.5G memory to run this and cost > > several minutes.... And this happened only under my linux os. Both > > jython and python... ?Is there something wrong with python under linux > > or my code? > > Thanks! > > > a = 0 > > for i in range(100000000): > > ? ? a = a + 1 > > print a > > This is fixed in Python 3.0. In older Python versions, use > xrange instead of range. Thanks! But this isn't appear in MAC and Windows~? From michele.simionato at gmail.com Fri Jan 2 10:52:18 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 2 Jan 2009 07:52:18 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: <7eb33c9d-4105-4671-828d-20ff9b5ff485@t39g2000prh.googlegroups.com> On Jan 2, 4:50?pm, ming_cuhk wrote: > On Jan 2, 11:49?pm, Michele Simionato > wrote: > > > > > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > > Hi all, I'm new to here and python. > > > When I tried the code below to test python's speed... > > > I found that python use more than 1.5G memory to run this and cost > > > several minutes.... And this happened only under my linux os. Both > > > jython and python... ?Is there something wrong with python under linux > > > or my code? > > > Thanks! > > > > a = 0 > > > for i in range(100000000): > > > ? ? a = a + 1 > > > print a > > > This is fixed in Python 3.0. In older Python versions, use > > xrange instead of range. > > Thanks! But this isn't appear in MAC and Windows~? It should happen on all platforms, since you are building a list with 100 millions of integers, which is quite large, especially if you are running on a 64 bit OS. From mamingcao at gmail.com Fri Jan 2 10:57:24 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:57:24 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: <7eb33c9d-4105-4671-828d-20ff9b5ff485@t39g2000prh.googlegroups.com> Message-ID: <6021cfa9-3f45-4503-9a26-ffc8c95847ca@y1g2000pra.googlegroups.com> On Jan 2, 11:52?pm, Michele Simionato wrote: > On Jan 2, 4:50?pm, ming_cuhk wrote: > > > > > On Jan 2, 11:49?pm, Michele Simionato > > wrote: > > > > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > > > Hi all, I'm new to here and python. > > > > When I tried the code below to test python's speed... > > > > I found that python use more than 1.5G memory to run this and cost > > > > several minutes.... And this happened only under my linux os. Both > > > > jython and python... ?Is there something wrong with python under linux > > > > or my code? > > > > Thanks! > > > > > a = 0 > > > > for i in range(100000000): > > > > ? ? a = a + 1 > > > > print a > > > > This is fixed in Python 3.0. In older Python versions, use > > > xrange instead of range. > > > Thanks! But this isn't appear in MAC and Windows~? > > It should happen on all platforms, since you are building > a list with 100 millions of integers, which is quite large, > especially if you are running on a 64 bit OS. You are right...Thanks.... Since my MAC have too much RAM..I didn't notice it.... From luke.leighton at googlemail.com Fri Jan 2 11:05:03 2009 From: luke.leighton at googlemail.com (lkcl) Date: Fri, 2 Jan 2009 08:05:03 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> <05e462b7-cfab-4f37-b545-bdff51f0e684@a12g2000pro.googlegroups.com> Message-ID: <8f510c9a-3c35-4f93-8e69-43adb5d1fa50@u18g2000pro.googlegroups.com> On Jan 1, 4:44 pm, Mike Driscoll wrote: > On Jan 1, 7:47 am,lkcl wrote: > > > > > On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > > > > On Dec 31, 3:36 pm,lkcl wrote: > > > > > hiya mike: where do i know you from? i've heard your name somewhere > > > > and for the life of me can't remember where! anyway... onwards. > > > > I don't know...while your username looks vaguely familiar, I don't > > > think I've communicated with you recently. I spend most of my time on > > > the wxPython list now... > > > i think it might be from my old school - i could be confusing you > > with > > someone, though - "gary driscoll", perhaps? anyway, never mind :) > > > > > testing: you should really use a debootstrap absolute "basic" > > > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > > > whatever). > > > > I thought the general practice was to test on the closest software/ > > > hardware combo that your application was most likely to run on. > > > that you should do as well :) you should be able to either upgrade > > the bare-bones version using "tasksel install desktop" or just... > > what-the-heck, install on a vanilla combo. > > > http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/c... > > > archive.ubuntu.com appears offline at the moment - maybe it'll be > > back later. i recommend you go for the mini.iso > > Ok...thanks for the info! > > > > I have > > > heard of doing testing on the lowest common denominator before though. > > > Unfortunately, I don't have time to set up a bare-bones VM since we're > > > closing soon, but I may give this a go on Friday and report back. > > > ok - the issue that you will face if you _don't_ do a LCD test is > > that > > should ubuntu get upgraded, and one of the packages that _used_ to > > pull > > in a dependency [that you missed] no longer does so... > > I see. I had hoped that there was a way to create a frozen application > like I do with py2exe on Windows so I wouldn't have to worry about a > Linux upgrade breaking my application. I've been told that ok - to do _that_, you will have to download copies of every single library that your app uses, compile them specially into a customised location (/opt/local or /usr/local); you will have to then make sure that PYTHONPATH environment variable is set to point to the locations. from a random manual somewhere: The PYTHONPATH variable can be set to a list of paths that will be added to the beginning of sys.path. For example, if PYTHONPATH is set to "/www/python:/opt/py", the search path will begin with ['/www/ python', '/opt/py']. (Note that directories must exist in order to be added to sys.path; the site module removes paths that don't exist.) having multiple copies of python libraries on your system was exactly the thing that i recommended that you _not_ do :) because you _still_ have to install them, and the process to do _that_ easily, on ubuntu, is "apt-get install" - so why bother duplicating that effort? path of least resistance says "go with the debian flow". well... it does in my book, anyway :) l. From darcy at druid.net Fri Jan 2 11:14:33 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 2 Jan 2009 11:14:33 -0500 Subject: Please show some restraint (Was: Why not Ruby?) In-Reply-To: References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <20090102111433.2e64afa3.darcy@druid.net> On Fri, 02 Jan 2009 00:57:06 +0100 Richard Riley wrote: > You clearly have a personal issue with Xah Lee. Possibly it is better > you killfile him or your spring will over wind :-; What good does a killfile do if people insist on repeating his posts in their entirety? Please people, try to resist the urge to reply to every post that raises your blood pressure a point or two but if you must reply, please trim. Anyone can always go back and review a previous message if they need more context. Heck, we can even review messages posted by people in our killfile. Personally, if I can't see your reply without scrolling down I just tend to hit the delete key. That means that thanks to you non-trimmers I get to read Xah posts over and over but never get to see your witty, entertaining and educational replies. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rcmn73 at gmail.com Fri Jan 2 11:19:01 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 08:19:01 -0800 (PST) Subject: Py2exe issue Message-ID: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> I'm using 2.6 (the issue was the same with 2.5) script.py: [code]import re from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", action="store", type="string", dest="filename") parser.add_option("-o", "--output", action="store", type="string", dest="fileout") (options, args) = parser.parse_args() from subprocess import Popen, PIPE if options.fileout: fileoutput = options.fileout output = open(fileoutput, "w") else: output = open("output.txt", "w") if options.filename: rawfile = options.filename file = open(rawfile) else: print "type -h for help" exit() from threading import Thread class Pinger(object): def __init__(self, hosts): for host in hosts: pa = PingAgent(host) pa.start() class PingAgent(Thread): def __init__(self, host): Thread.__init__(self) self.host = host def run(self): p = Popen('ping -n 1 ' + self.host, stdout=PIPE, stderr=True) m = re.search('Average = (.*)ms', p.stdout.read()) if m: output.write (self.host+",pingable\n") else: output.write (self.host+",not pingable\n") if __name__ == '__main__': pinglist = [] for line in file: pinglist.append(line.strip("\n")) Pinger(pinglist)[/code] py2exe setup.py : [code]from distutils.core import setup import py2exe, sys, os sys.argv.append('py2exe') setup( options = {'py2exe': {'bundle_files': 1}}, console = [{'script': "script.py"}], zipfile = None, ) [/code] error when the "script.exe" run [code]Exception in thread Thread-500 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "threading.pyc", line 522, in __bootstrap_inner File "script.py", line 35, in run File "subprocess.pyc", line 588, in __init__ [/code] So the script.py run perfectly well under the py environment but if i use py2exe to make an exe then i get the error above. I read the note in the py2exe Fac regarding Popen, but i don't know if it's relevant in my case. From kyosohma at gmail.com Fri Jan 2 11:26:13 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Fri, 2 Jan 2009 08:26:13 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> Message-ID: <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> On Jan 2, 10:19?am, rcmn wrote: > I'm using 2.6 (the issue was the same with 2.5) > > script.py: > > [code]import re > > from optparse import OptionParser > parser = OptionParser() > parser.add_option("-f", "--file", action="store", type="string", > dest="filename") > parser.add_option("-o", "--output", action="store", type="string", > dest="fileout") > (options, args) = parser.parse_args() > > from subprocess import Popen, PIPE > if options.fileout: > ? ? ? ? fileoutput = options.fileout > ? ? ? ? output = open(fileoutput, "w") > else: > ? ? ? ? output = open("output.txt", "w") > if options.filename: > ? ? ? ? rawfile = options.filename > ? ? ? ? file = open(rawfile) > else: > ? ? ? ? print "type -h for help" > ? ? ? ? exit() > > from threading import Thread > class Pinger(object): > ? ? def __init__(self, hosts): > ? ? ? ? for host in hosts: > ? ? ? ? ? ? pa = PingAgent(host) > ? ? ? ? ? ? pa.start() > > class PingAgent(Thread): > ? ? def __init__(self, host): > ? ? ? ? Thread.__init__(self) > ? ? ? ? self.host = host > > ? ? def run(self): > ? ? ? ? p = Popen('ping -n 1 ' + self.host, stdout=PIPE, stderr=True) > ? ? ? ? m = re.search('Average = (.*)ms', p.stdout.read()) > ? ? ? ? if m: > ? ? ? ? ? ? ? ? ? ? ? ? output.write (self.host+",pingable\n") > ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? output.write (self.host+",not pingable\n") > > if __name__ == '__main__': > ? ? ? ? pinglist = [] > ? ? ? ? for line in file: > ? ? ? ? ? ? ? ? pinglist.append(line.strip("\n")) > ? ? ? ? Pinger(pinglist)[/code] > > py2exe setup.py : > > [code]from distutils.core import setup > import py2exe, sys, os > > sys.argv.append('py2exe') > > setup( > ? ? ?options = {'py2exe': {'bundle_files': 1}}, > ? ? ?console = [{'script': "script.py"}], > ? ? ?zipfile = None, > ?) > [/code] > > error when the "script.exe" run > [code]Exception in thread Thread-500 (most likely raised during > interpreter shutdown): > Traceback (most recent call last): > ? File "threading.pyc", line 522, in __bootstrap_inner > ? File "script.py", line 35, in run > ? File "subprocess.pyc", line 588, in __init__ > [/code] > > So the script.py run perfectly well under the py environment but if i > use py2exe to make an exe then i get the error above. > I read the note in the py2exe Fac regarding Popen, but i don't know if > it's relevant in my case. Try it with bundle_files option 3 instead of 1. Also what version of py2exe are you using? Mike From steve at holdenweb.com Fri Jan 2 11:32:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:32:39 -0500 Subject: Parsing Excel spreadsheets In-Reply-To: References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <495E41A7.1050503@holdenweb.com> brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: >> On Dec 31 2008, 4:02 pm, brooklineTom wrote: >> >>> andyh... at gmail.com wrote: >>>> Hi, >>>> Can anybody recommend an approach for loading and parsing Excel >>>> spreadsheets in Python. Any well known/recommended libraries for this? >>>> The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, >>>> but I'd rather get some more input before going with something I don't >>>> know. >>>> Thanks, >>>> Andy. >>> I save the spreadsheets (in Excel) in xml format. >> Which means that you need to be on a Windows box with a licensed copy >> of Excel. I presume you talking about using Excel 2003 and saving as >> "XML Spreadsheet (*.xml)". Do you save the files manually, or using a >> COM script? What is the largest xls file that you've saved as xml, how >> big was the xml file, and how long did it take to parse the xml file? >> Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. Well, even if Andy meant "Excel files" rather than "Excel-formatted files" there are many ways to come by these without having a licensed copy of Excel. FTP and email attachment come to mind most readily. How then to convert those to XML without Excel? [...]> I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. > My own case was similar, in that I only needed the value data. The approach I took was to install xlrd and use it. Job done. > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > My data files weren't that large (IIRC the largest spreadsheet was about 6MB), so I was quite happy to load the whole thing in memory, iterate over it and then write the results to the database as they were extracted. > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > Given the constraints of your problem it seems like an intelligent approach. > I hope this helps! I'm sure it will. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 11:32:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:32:39 -0500 Subject: Parsing Excel spreadsheets In-Reply-To: References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <495E41A7.1050503@holdenweb.com> brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: >> On Dec 31 2008, 4:02 pm, brooklineTom wrote: >> >>> andyh... at gmail.com wrote: >>>> Hi, >>>> Can anybody recommend an approach for loading and parsing Excel >>>> spreadsheets in Python. Any well known/recommended libraries for this? >>>> The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, >>>> but I'd rather get some more input before going with something I don't >>>> know. >>>> Thanks, >>>> Andy. >>> I save the spreadsheets (in Excel) in xml format. >> Which means that you need to be on a Windows box with a licensed copy >> of Excel. I presume you talking about using Excel 2003 and saving as >> "XML Spreadsheet (*.xml)". Do you save the files manually, or using a >> COM script? What is the largest xls file that you've saved as xml, how >> big was the xml file, and how long did it take to parse the xml file? >> Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. Well, even if Andy meant "Excel files" rather than "Excel-formatted files" there are many ways to come by these without having a licensed copy of Excel. FTP and email attachment come to mind most readily. How then to convert those to XML without Excel? [...]> I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. > My own case was similar, in that I only needed the value data. The approach I took was to install xlrd and use it. Job done. > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > My data files weren't that large (IIRC the largest spreadsheet was about 6MB), so I was quite happy to load the whole thing in memory, iterate over it and then write the results to the database as they were extracted. > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > Given the constraints of your problem it seems like an intelligent approach. > I hope this helps! I'm sure it will. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 11:43:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:43:30 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102103915.GJ28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: [...] > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. > I'd definitely argue against bizarre. It's actually very easy to understand, and Python is by no means the only language to have used it. > That is, in what I'll call "normal" computer languages, a variable > name is thought of as the address of a bin where some data is stored, > and the name is inexorably tied to that bin. You can change what's in > the bin, but the name you gave the bin always points to the same bin. > This tends to be conceptually true even if it might technically not be > true in a given implementation of a language. > I'd argue that this approach is out of date and overly-restrictive, requiring data copying not required by the Python data model and running the risk, in the absence of such copying, of returning invalid references (the C++ "dangling pointer" issue being the best-known manifestation of such problems). > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, > where the bin is a Python object which contains specific data at the > time of assignment. A second assignment of that name doesn't change > what's in the original bin; it actually (probably) first creates a new > bin, then removes the name from the original bin and assigns it to > the new one. Intuitively, it's a bit like saying your kitchen table > is no longer a kitchen table, and now the thing where you wash your > dishes is a kitchen table. It doesn't really make a lot of sense > (whether or not it's so for good reason), and it makes describing the > assignment model necessarily convoluted, whereas the "named bins" > model from the majority of other languages people are likely to have > been exposed to is simple and sensible. > I'd instead say that Python uses ephemeral names for long-lived objects, where other languages use the addresses of ephemeral objects. Your ideas of "simple" and "sensible" are being conditioned by your experience. > It's small wonder that neophytes try to cram Python behaviors into > terms and computing concepts they already understand from learning > other languages, and that they fail to do so. What's mystifying is > that when Pythonistas reply to their messages, they universally seem > confused at how this could possibly happen, and often enough actually > seem offended (or at least offensive) when it inevitably does happen... > Generally speaking we try not to be offensive first on this list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rt8396 at gmail.com Fri Jan 2 12:00:01 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 09:00:01 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> Message-ID: <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> On Jan 2, 6:45?am, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: > > He was not cross posting. > > You don't actually know what cross-posting is, do you? > > You've just earned a plonking for the next month. Do try to have at least > half a clue by February. > > -- > Steven Steven i got you NOW! Everybody go and look at this thread, there Mr. Makinzie butts in and posts an off-topic question, and Steven answers it, contributing to the off-topicalitly of the thread. And has yet to apologize for it, or admit his screwup, but will he preach to everyone else about making off topic post... Pot meet Kettle; Kettle Pot! http://groups.google.com/group/comp.lang.python/browse_thread/thread/fc57c18c3cff5937?hl=en&q=recycle+bin#97254d877903bbd From excord80 at gmail.com Fri Jan 2 12:10:08 2009 From: excord80 at gmail.com (excord80) Date: Fri, 2 Jan 2009 09:10:08 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> Message-ID: You might find this recent blog post interesting: http://www.mechanicalcat.net/richard/log/Python/Sane_Python_application_packaging__initial_solution From igouy2 at yahoo.com Fri Jan 2 12:28:26 2009 From: igouy2 at yahoo.com (Isaac Gouy) Date: Fri, 2 Jan 2009 09:28:26 -0800 (PST) Subject: 2to3 used in the Shootout References: <4f1a8f03-fd7f-49ea-8031-61f73fb0c0e8@x16g2000prn.googlegroups.com> <65a43a69-1ef2-4a41-b860-a370891aecbd@g39g2000pri.googlegroups.com> <67424d25-69c3-4c9d-ba38-0df208a28428@k19g2000yqg.googlegroups.com> Message-ID: On Dec 29 2008, 8:36?am, prueba... at latinmail.com wrote: > On Dec 23, 5:21?pm, Isaac Gouy wrote: > > > On Dec 23, 11:51?am, bearophileH... at lycos.com wrote: > > > > They have translated the Python benchmarks of theShootoutsite from > > > Py2 to Py3 using 2to3: > > > >http://shootout.alioth.debian.org/u32/benchmark.php?test=all?=pyt... > > > So please re-write those programs to remove problems created by > > automatic translation and better take advantage of Python 3 > > functionality... > > >http://shootout.alioth.debian.org/u32/faq.php#play > > > > It shows some "performance bugs" of Python3 itself (especially > > > regarding the binary-trees benchmark, that was unexpected by me), and > > > two points where 2to3 may be improved, for example after the > > > translation this gives error: > > > ? ? ? ? ?table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy', > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'TGVHCDM > > > \nKNSYAAWBRTGVHCDMKNSYAAWBR')): > > > > Gives: > > > TypeError: maketrans arguments must be bytes objects > > > > Bye, > > > bearophile > > BTW I am not sure how to submit this or if this is actually valid to > do, but I have a faster version for the pidigits program that uses > basically the same algorithm but removes function calls and unused > terms of the formula. > >
> import time
>
> def pi_digits(n, width):
> ? ? out = []
> ? ? wrt = out.append
> ? ? aq = 1
> ? ? ar = 0
> ? ? at = 1
> ? ? k = 0
> ? ? f = 1
> ? ? g = 2
> ? ? i = 0
> ? ? while i < n:
> ? ? ? ? y = (aq*3+ar)//at
> ? ? ? ? while y != ((aq*4+ar)//at):
> ? ? ? ? ? ? k += 1
> ? ? ? ? ? ? f += 2
> ? ? ? ? ? ? g += 4
> ? ? ? ? ? ? ar = aq*g+ar*f
> ? ? ? ? ? ? aq = aq*k
> ? ? ? ? ? ? at = at*f
> ? ? ? ? ? ? y = (aq*3+ar)//at
> ? ? ? ? aq = 10*aq
> ? ? ? ? ar = 10*ar-10*y*at
> ? ? ? ? i += 1
> ? ? ? ? wrt(str(y))
> ? ? ? ? if not i%width:
> ? ? ? ? ? ? wrt('\t:%d\n'%i)
> ? ? wrt(' '*(width-i%width))
> ? ? wrt('\t:%d\n'%i)
> ? ? return ''.join(out)
>
> def main():
> ? ? begin = time.time()
> ? ? n = 1000
> ? ? width = 70
> ? ? print pi_digits(n,width)
> ? ? print 'Total Time:', time.time()-begin
>
> main()
>
> 
http://shootout.alioth.debian.org/u32q/faq.php#play From fuzzyman at gmail.com Fri Jan 2 12:40:34 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:40:34 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> Message-ID: On Jan 2, 2:49?pm, excord80 wrote: [snip...] > > It sounds interesting, however, after reading a bit about it, I see > that a large part of wsgi is providing a nice interface between web > server and webapp. I don't think I need any such interface, or at > least, a replacement for CGI. I just need something like CGI but with > a persistent Python so the web server doesn't have to restart python > for every request. And I don't need need it to work with anything else > other than Apache. > And indeed that is exactly what mod_wsgi is / does. It does a bit more - because CGI really isn't enough for most web apps these days, but WSGI can be used very simply. Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Fri Jan 2 12:44:55 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:44:55 -0800 (PST) Subject: If your were going to program a game... References: <85eizlhhu5.fsf@dozer.localdomain> Message-ID: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> On Jan 2, 3:02?pm, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > > browser in a window of a social site built around the game. The social > > site has login, chat, player stats, list of active games, etc. AND > > there is also be a desktop client that accesses the game server via > > the same communication mechanism (like an AIR-based desktop client/ > > app) as the browser-based version - I guess using JSON/RPC. > > Ever see chess.com? > > I don't know what they're using in the backend, but the client is > entirely javascript. > > You could probably roll your own python javascript compiler to suit your > needs. It could probably even build up your own DSL for writing these > games. > > It's a worthwhile project and I think there might be support for it from > other developers. There's a project called Pyjamas, and PyPy also has a Python to Javascript compiler. Imagine debugging it though - ouch. Just write some Javascript already. ;-) Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Fri Jan 2 12:49:03 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:49:03 -0800 (PST) Subject: FW: python import sys.path References: <68177ab8-f073-4767-86b6-9abf8c331e36@r10g2000prf.googlegroups.com> Message-ID: <1b8445ae-2b9a-4656-b035-4a0af1ce55a5@i20g2000prf.googlegroups.com> On Jan 2, 2:28?pm, John Machin wrote: > On Jan 3, 1:09?am, "Kelly, Brian" wrote:> After following your suggestions I was able to confirm that the 2.5 > > interpreter was being invoked. So then I grepped for all instances of python > > in the scripts that were imported as modules: from bacula_conf import * > > > The calling script cleanup.py is invoking purge_client.py like an external > > script: > > > def purgeAll(options, computer_name): > > ? ? cmd = "python purge_client.py %s" % computer_name > > ? ? if options.pretend <> True: > > Who wrote that? > > > ? ? ? ? error = os.system(cmd) > > ? ? else: > > ? ? ? ? _log.info("Done. No changes made due to --pretend flag.") > > ? ? ? ? ? ?#### error is not defined in this branch> ? ? if not error: #### Splat! > > ? ? ? ? return True > > ? ? else: > > ? ? ? ? return False > > ?AArrgh! Try: > > ? ?return not error > That will still blow up with a NameError when the path doing the logging is invoked. How about: def purgeAll(options, computer_name): cmd = "python purge_client.py %s" % computer_name if options.pretend != True: # if not options.pretend (assuming it is a bool) error = os.system(cmd) return not error _log.info("Done. No changes made due to --pretend flag.") return True Michael -- http://www.ironpythoninaction.com/ From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 13:09:47 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 19:09:47 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <495e6619$0$3500$426a34cc@news.free.fr> Kottiyath a ?crit : > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? complement = lambda t: (t[0], None, t[1]) if len(t) == 2 else t for k, u, v in map(complement, L): print k, u, v From n.kottiyath at gmail.com Fri Jan 2 13:11:09 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Fri, 2 Jan 2009 10:11:09 -0800 (PST) Subject: Is there a better algorithm? Message-ID: I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: >>> for i in l: ... u = None ... try: ... (k, v) = i ... except ValueError: ... (k, u, v) = i ... print k, u, v --------- 1 None 2 3 4 5 6 None 7 ------------- But, this algorithm doesnt look very beautiful - like say -> for k, u, v in L: Can anyone suggest a better algorithm to get the values? From exarkun at divmod.com Fri Jan 2 13:16:13 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 2 Jan 2009 13:16:13 -0500 Subject: If your were going to program a game... In-Reply-To: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> Message-ID: <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: >On Jan 2, 3:02?pm, J Kenneth King wrote: >> Tokyo Dan writes: >> > If your were going to program a game in python what technologies would >> > you use? >> >> > The game is a board game with some piece animations, but no movement >> > animation...think of a chess king exploding. The game runs in a >> > browser in a window of a social site built around the game. The social >> > site has login, chat, player stats, list of active games, etc. AND >> > there is also be a desktop client that accesses the game server via >> > the same communication mechanism (like an AIR-based desktop client/ >> > app) as the browser-based version - I guess using JSON/RPC. >> >> Ever see chess.com? >> >> I don't know what they're using in the backend, but the client is >> entirely javascript. >> >> You could probably roll your own python javascript compiler to suit your >> needs. It could probably even build up your own DSL for writing these >> games. >> >> It's a worthwhile project and I think there might be support for it from >> other developers. > >There's a project called Pyjamas, and PyPy also has a Python to >Javascript compiler. No, PyPy includes an RPython to JavaScript compiler. RPython and Python are different languages. Jean-Paul From fuzzyman at gmail.com Fri Jan 2 13:16:58 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 10:16:58 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> On Jan 2, 6:11?pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ... ?u = None > ... ?try: > ... ? (k, v) = i > ... ?except ValueError: > ... ? (k, u, v) = i > ... ?print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? for i in l: u = None if len(i) == 2: k, v = i else: k, u, v = i Best I could come up with. Alternatively: def mangle(i): if len(i) == 3: return i k, v = i return k, None, v for i in l: k, u, v = mangle(i) I'm sure there is a clever one liner using the Python 2.5 ternary expression syntax. On the other hand I'm not sure it would be very readable, so a straightforward (if less clever) solution is probably better. Michael -- http://www.ironpythoninaction.com/ From tavares at fe.up.pt Fri Jan 2 13:17:59 2009 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Fri, 2 Jan 2009 10:17:59 -0800 (PST) Subject: =?windows-1252?Q?Workshop_=22Medical_Imaging_Systems=22_within_EUROMEDIA_?= =?windows-1252?Q?2009_=96_Announce_=26_Call_for_Papers?= Message-ID: -------------------------------------------------------------------------------------------------------------------------------------------- Workshop ?Medical Imaging Systems? within EUROSIS EUROMEDIA 2009 April 15-17, 2009, Novotel, Bruges, Belgium http://www.eurosis.org/cms/?q=taxonomy/term/172 (Apologies for cross-posting. We would appreciate if you could distribute this information by your colleagues and co-workers.) -------------------------------------------------------------------------------------------------------------------------------------------- Dear Colleague, In recent years, extensive research has been performed to develop more and more efficient and powerful medical imaging systems. Such systems are crucial for medical specialists, allowing a deeper analysis and to understand what is going inside the human body, and therefore they play an essential role for adequate medical diagnosis and treatments. To accomplish efficient and powerful medical imaging systems, many research works have being done in many domains, like the ones related with medical image devices, signal processing, image processing and analysis, biomechanical simulation and data visualization. The main goal of the Workshop ?Medical Imaging Systems? is to bring together researchers involved in the related domains, in order to set the major lines of development for the near future. Therefore, the proposed Workshop will consist of researchers representing various fields related to Medical Devices, Signal Processing, Computational Vision, Computer Graphics, Computational Mechanics, Scientific Visualization, Mathematics and Medical Imaging. The Workshop endeavors to contribute to obtain better solutions for more efficient and powerful medical imaging systems, and attempts to establish a bridge between clinicians and researchers from these diverse fields. Due to your research activities in the field, we would like to invite you to submit a contributed paper for the Workshop ?Medical Imaging Systems?. Important Dates - Submission Deadline: January 20, 2009; - Notification of Acceptance or Rejection: March 20, 2009; - Authors provide camera-ready manuscript: April 15-17, 2009; - Conference Events: April 15-17, 2009. For further details please see the conference website at: http://www.eurosis.org/cms/?q=taxonomy/term/172 We are looking forward to see you in Bruges next April. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, tavares at fe.up.pt, www.fe.up.pt/~tavares) From fuzzyman at gmail.com Fri Jan 2 13:19:50 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 10:19:50 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <890cb4a3-7b45-4c50-ba60-b4ce4094fa14@n33g2000pri.googlegroups.com> On Jan 2, 6:16?pm, Jean-Paul Calderone wrote: > On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: > >On Jan 2, 3:02?pm, J Kenneth King wrote: > >> Tokyo Dan writes: > >> > If your were going to program a game in python what technologies would > >> > you use? > > >> > The game is a board game with some piece animations, but no movement > >> > animation...think of a chess king exploding. The game runs in a > >> > browser in a window of a social site built around the game. The social > >> > site has login, chat, player stats, list of active games, etc. AND > >> > there is also be a desktop client that accesses the game server via > >> > the same communication mechanism (like an AIR-based desktop client/ > >> > app) as the browser-based version - I guess using JSON/RPC. > > >> Ever see chess.com? > > >> I don't know what they're using in the backend, but the client is > >> entirely javascript. > > >> You could probably roll your own python javascript compiler to suit your > >> needs. It could probably even build up your own DSL for writing these > >> games. > > >> It's a worthwhile project and I think there might be support for it from > >> other developers. > > >There's a project called Pyjamas, and PyPy also has a Python to > >Javascript compiler. > > No, PyPy includes an RPython to JavaScript compiler. ?RPython and Python are > different languages. > Well valid RPython is valid Python - so different for some value of different... The advantage of PyPy is that it even does things like turn runtime exceptions into Python exceptions, so it should be much easier to debug. It is much more 'heavyweight' though. Michael Foord -- http://www.ironpythoninaction.com/ From imageguy1206 at gmail.com Fri Jan 2 13:34:12 2009 From: imageguy1206 at gmail.com (imageguy) Date: Fri, 2 Jan 2009 10:34:12 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string Message-ID: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' FWIW, the string is created using ctypes.create_string_buffer function The following code works but feels a bit clunk and is rather slow too. blist = list(buffer) for start in xrange(0,len(blist), 3): try: blue = blist[start] red = blist[start+2] blist[start] = red blist[start+2] = blue except IndexError: pass new_buffer = ''.join(blist) new_buffer is then passed to a wx program to create and image. Any thoughts comments would be appreciated. geoff. PS: I started this post earlier, but I think I hit the send button too soon. My apologies to the group for sloppy typing. From steve at holdenweb.com Fri Jan 2 13:41:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 13:41:58 -0500 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? L = [(1, 2), (3, 4, 5), (6, 7)] for i in L: if len(i) == 2: k, v, u = i + (None, ) else: k, u, v = i print k, u, v regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 13:50:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 13:50:50 -0500 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > May not be any quicker, but it works: blues = buffer[0::3] greens = buffer[1::3] reds = buffer[2::3] result = "".join("".join(x) for x in zip(reds, blues, greens)) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From news at slash-me.net Fri Jan 2 13:55:43 2009 From: news at slash-me.net (Markus Brueckner) Date: Fri, 02 Jan 2009 19:55:43 +0100 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> Message-ID: <6s769gF4gge3U1@mid.individual.net> Hi, Fuzzyman wrote: > I'm sure there is a clever one liner using the Python 2.5 ternary > expression syntax. On the other hand I'm not sure it would be very > readable, so a straightforward (if less clever) solution is probably > better. that would be something like this (using a generator) L = [(1, 2), (3, 4, 5), (6, 7)] g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in L) for elem in g: print elem So long, Markus P.S: No, I don't consider that more readable than your example ;-) -- "Hacking is like having sex: you get in, you get out and you hope that you did not leave anything which can be traced back to you" - Unbekannt From tekion at gmail.com Fri Jan 2 14:03:44 2009 From: tekion at gmail.com (tekion) Date: Fri, 2 Jan 2009 11:03:44 -0800 (PST) Subject: is there a way to determine a relative path to the script? Message-ID: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Hello, I have a script in /usr/local/app/mypython.py and a configuration file relative to /usr/local/app/conf. When I call the script with an absolute path of /usr/local/app/mypthon.py I recieved an error similar to the below error: Traceback (most recent call last): File "script/art/auditlog.py", line 28, in ? database = Config.get("DB", "user") File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/ConfigParser.py", line 505, in get raise NoSectionError(section) ConfigParser.NoSectionError: No section: 'DB' I know why, the configuration which I reference in the script is relative to "/usr/local/app", when I call the script via an absolute path, then the relative the configuration file is base on where ever I call the script from. One way to fix this is to add a path manually into the variable. But I would like to avoid this hard-coding parameter into my script. Is there a way to determined the relative location of the script programatically? FYI, in the end this scrip would run from CRON. From bockman at virgilio.it Fri Jan 2 14:15:58 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 20:15:58 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <495e67ef$0$743$5fc30a8@news.tiscali.it> Kottiyath ha scritto: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? One way to avoid explicit checks on tuple size (but making the code a bit less clear and probably slower): for i in l: k, v, u = (i[:3]+(None,))[:3] ... Ciao ----- FB From geekmail at usenot.de Fri Jan 2 14:27:41 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 20:27:41 +0100 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> <6s769gF4gge3U1@mid.individual.net> Message-ID: <20090102202741.14263c92@usenot.de> On Fri, 02 Jan 2009 19:55:43 +0100 Markus Brueckner wrote: > g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in > L) If this isn't proof of Python's versatility, I don't know what is. In one line it can mimic both Lisp and Perl. Sweet. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From bockman at virgilio.it Fri Jan 2 14:29:11 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 20:29:11 +0100 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <495e6b08$0$11376$5fc30a8@news.tiscali.it> imageguy ha scritto: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > You could try the same algorithm on an array.array object : it might be faster. Ciao ---- FB From ryan.mccoskrie at gmail.com Fri Jan 2 14:39:30 2009 From: ryan.mccoskrie at gmail.com (Ryan McCoskrie) Date: Sat, 03 Jan 2009 08:39:30 +1300 Subject: Why not Ruby? References: Message-ID: Xah Lee wrote: > Q: Do you condemn Ruby? > > No. I think it's reasonably elegant, but today there are too many > languages, so Ruby don't particularly standout for me. Many of them, > are arguably quite more elegant and powerful than Ruby. There is one thing that Ruby is exceptionally good for and that is replacing COBOL and Visual Basic as the programming languages for non-programmers. It's dead boring as a language but somebody who is an accountant or something could make some okayish tools for personal use in it. Next point. If your going to post this sort of thing _only_ post to comp.programming and _never_ post what is on your website. Just put it into your sig block. ------------------------------------------------------------------------ Quote of the login: Computers don't actually think. You just think they think. (We think.) From robert.kern at gmail.com Fri Jan 2 14:46:31 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 02 Jan 2009 14:46:31 -0500 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: r wrote: > On Jan 1, 4:40 pm, Robert Kern wrote: >> Hamish McKenzie wrote: >>> sometimes I want to be able to initialize an instance with a variety of different data types. >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just >> assign to attributes. I would add a from() classmethod for each that >> I wanted to support. If I really wanted an all-singing, all-dancing >> initialization method, I would add another classmethod that would just dispatch >> to the appropriate type-specific classmethod. I prefer classmethods to plain >> functions because I can subclass. >> >> -- >> 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 > > Why are you busting into this thread? Are you talking to me, or Hamish, who (presumably unintentionally) responded to a message instead of making a new thread? If you want to suggest that one should have more care about starting new threads, that's fine, but please do not jump to the conclusion that there is malintent. And don't chastise people for not being as rude as you. -- 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 rcmn73 at gmail.com Fri Jan 2 15:04:41 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 12:04:41 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> Message-ID: <788a7ce3-1ba2-4996-af47-5af6c0a69b37@a26g2000prf.googlegroups.com> I'm using py2exe-0.6.9.win32-py2.6.exe i used option 3. On a list of 500 i get the same error than previous. On a list of 250 once it just quit leaving the open file at 0k and on the second attempt it failed with the same error and a note about "TypeError: 'NoneType' object is not callable". Basically totally random errors. Obviously there is something that py2exe cannot bundle. because I have been using this script(as *.py) more than 30 times now .And as long as i respect the 500 window$ limitation. I had no issues. From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 15:05:51 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 21:05:51 +0100 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <495e814d$0$3502$426a34cc@news.free.fr> Derek Martin a ?crit : > On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: >> Derek Martin wrote: >>> What the Python community often overlooks, when this discussion again >>> rears its ugly head (as it seems to every other hour or so), is that >>> its assignment model is BIZARRE, as in it's conceptually different >>> from virtually all other languages substantially taught in >>> undergraduate computer science programs. And for that matter, it's >>> pretty unintuitive generally. >>> >> I'd definitely argue against bizarre. It's actually very easy to >> understand, and Python is by no means the only language to have used it. > > Clearly the first and third are true. :) But CS programs still > generally teach primarily C/C++, Java, and (some form of) assembly > AFAICT. A few odd ones pop up here and there along the way (I studied > with scheme, for example), but they vary and are highly > program-dependent. What the average CS grad sees is, AFAICT, still > very much what I described. Those languages also behave similarly to > what students see in mathematics (e.g. algebra etc.). With only that > to go on, Python seems rather weird, and I think from the frequency > with which these discussions occur on this list, clearly it *IS* > difficult for a neophyte Python programmer to understand the > assignment model. Took me about half an hour to grasp, not even being "CS grad" (nor whathever "grad" FWIW). By that time, I had a couple monthes working experience with VB, and had learned (but never seriously used) bits of C, C++, Java and Pascal. From rt8396 at gmail.com Fri Jan 2 15:11:34 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 12:11:34 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: On Jan 2, 1:46?pm, Robert Kern wrote: > r wrote: > > On Jan 1, 4:40 pm, Robert Kern wrote: > >> Hamish McKenzie wrote: > >>> sometimes I want to be able to initialize an instance with a variety of different data types. > >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just > >> assign to attributes. I would add a from() classmethod for each that > >> I wanted to support. If I really wanted an all-singing, all-dancing > >> initialization method, I would add another classmethod that would just dispatch > >> to the appropriate type-specific classmethod. I prefer classmethods to plain > >> functions because I can subclass. > > >> -- > >> 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 > > > Why are you busting into this thread? > > Are you talking to me, or Hamish, who (presumably unintentionally) responded to > a message instead of making a new thread? > > If you want to suggest that one should have more care about starting new > threads, that's fine, but please do not jump to the conclusion that there is > malintent. And don't chastise people for not being as rude as you. > > -- > 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 I am not so much chastising Hamish as i am Steven, Steven knows better than this BS, and has preached to so many people about off topic post that my ears are bleeding from his incessant rambling about it. Now, he goes and does what he complains about soooo much. I'm just calling him on it thats all. I can't speak for the other responders because i know of none of them. From code at pizzashack.org Fri Jan 2 15:44:44 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 14:44:44 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <20090102204444.GL28417@dragontoe.org> On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: > Derek Martin wrote: > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that > > its assignment model is BIZARRE, as in it's conceptually different > > from virtually all other languages substantially taught in > > undergraduate computer science programs. And for that matter, it's > > pretty unintuitive generally. > > > I'd definitely argue against bizarre. It's actually very easy to > understand, and Python is by no means the only language to have used it. Clearly the first and third are true. :) But CS programs still generally teach primarily C/C++, Java, and (some form of) assembly AFAICT. A few odd ones pop up here and there along the way (I studied with scheme, for example), but they vary and are highly program-dependent. What the average CS grad sees is, AFAICT, still very much what I described. Those languages also behave similarly to what students see in mathematics (e.g. algebra etc.). With only that to go on, Python seems rather weird, and I think from the frequency with which these discussions occur on this list, clearly it *IS* difficult for a neophyte Python programmer to understand the assignment model. And this is, in part, because it's kind of difficult to explain precisely, as has oft been demonstrated in this forum. > I'd argue that this approach is out of date and overly-restrictive, Sure, I already hinted that it's useful... but it's still uncommon, in the experience of most CS students -- not even taking into account the number of people who program who have never studied in a formal CS program. > I'd instead say that Python uses ephemeral names for long-lived objects, > where other languages use the addresses of ephemeral objects. Your ideas > of "simple" and "sensible" are being conditioned by your experience. Of course... I'd argue that our experience is a large part of what makes things simple or sensible. Things that behave like other things we are very familiar will be simple to understand. Python's assignment model is probably new to most people when they first start using it. To look at Python's code, at first glance assignment seems to be the same as everywhere else you've encountered it... Only once someone starts to write "real" programs does the difference really matter. > > It's small wonder that neophytes try to cram Python behaviors into > > terms and computing concepts they already understand from learning > > other languages, and that they fail to do so. What's mystifying is > > that when Pythonistas reply to their messages, they universally seem > > confused at how this could possibly happen, and often enough actually > > seem offended (or at least offensive) when it inevitably does happen... > > > Generally speaking we try not to be offensive first on this list. Perhaps I've misused the term Pythonista... I meant roughly, "people who frequent this list/news group who seem to consider themselves experts at programming Python (and for the most part, are)." I consider myself pretty well informed about Python (though not an expert by any means), and I still read this list often (I use the mailing list interface), because I still find that I learn useful things from the posts to it from time to time. But I often see python "experts" lambasting people who clearly from their posts are new at python, because their code is bad, their understanding is bad, or in this case even accusing the learning materials of being sub-par. I realize that some of this is meant in jest, but a lot of it isn't, and it can be quite difficult for someone who doesn't speak your language natively (or even one who does, given the medium) to tell the difference. There are better ways to foster understanding... ;-) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From GDoermann at gmail.com Fri Jan 2 15:46:00 2009 From: GDoermann at gmail.com (TechieInsite) Date: Fri, 2 Jan 2009 12:46:00 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Message-ID: <31f698b9-a6e7-41c5-91d3-b2264b9dec74@e1g2000pra.googlegroups.com> import os base = __file__.split(os.sep) os.path.relpath('path/to/your/file/, base) I hope this helps. Greg tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/local/app/mypthon.py I recieved an error > similar to the below error: > > Traceback (most recent call last): > File "script/art/auditlog.py", line 28, in ? > database = Config.get("DB", "user") > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > python2.3/ConfigParser.py", line 505, in get > raise NoSectionError(section) > ConfigParser.NoSectionError: No section: 'DB' > > I know why, the configuration which I reference in the script is > relative to "/usr/local/app", when I call the script via an absolute > path, then the relative the configuration file is base on where ever I > call the script from. One way to fix this is to add a path manually > into the variable. But I would like to avoid this hard-coding > parameter into my script. Is there a way to determined the relative > location of the script programatically? FYI, in the end this scrip > would run from CRON. From max at alcyone.com Fri Jan 2 15:50:44 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Jan 2009 12:50:44 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: Derek Martin wrote: > On a mostly not related note: > > On Tue, Dec 30, 2008 at 07:52:26AM -0800, Aaron Brady wrote: >> According to some rules, these are ungrammatical sentences, due to >> plurality disagreement. Ex: >> >> The Morning Star is ... >> The Evening Star is ... >> *The Morning Star and The Evening Star is... >> *The Morning Star and The Evening Star are... >> >> Neither of the latter two is correct. (* marks ungrammatical.) As >> such, the listener isn't sure what meaning to take. > > This statement is false. The latter of the two is grammatically > correct. The subject is a compound subject joined by the conjunction > "and" which indicates that there are two subjects, and thus the plural > form of the verb is necessary and correct. > >> Identity isn't defined on math objects, only on Python objects; there >> is no notion of 'is' in math. > > This is also false, it even has its own operator (which requires > Unicode to display): ? That can mean a number of things, one of which means "is identically equal to," but identity means something different in mathematics than it means here. In mathematics, identity means a relationship that is true regardless of the value of the variables involved (as opposed to equality which is only true under more specific circumstances). In computer science, identity means that two expressions are represented by the same object, something which not only has no meaning in mathematics, but which should also be clear since mathematical identities need not have any individual variables on either side of the triple bar; take, for instance, the trigonometric identity cos^2 theta + sin^2 theta = 1. Even if you write this equation with the triple bar to represent a mathematical identity (which it is), it obviously doesn't say anything about which "objects" are the same as each other. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Scars are like memories. We do not have them removed. -- Chmeee From james at agentultra.com Fri Jan 2 15:57:22 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 15:57:22 -0500 Subject: Is there a better algorithm? References: Message-ID: <85aba9h1e5.fsf@dozer.localdomain> Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? Just a note: this isn't really an algorithm problem. ;) It's more of a grammar obstruction. To make your code more simple, it would be nice if the assignment operator would return, "None," in the case where there are too few values to unpack from the right-operand of the assignment operator. Aside from the typical workarounds that first came to mind, I started wondering whether it was possible to expose the problem and solve it directly. Sadly, it appears to be non-trivial (or at least, well hidden from the unwashed masses). I'd be really curious if the unpacking machinery were exposed to the developer. I started poking around the operator and types modules, but the implementation isn't obvious. What methods are being called on the operands by the assignment operator in the following statement: a, b, c = some_tuple I'm sorry if this line of inquiry is not very pythonic; but one is curious if this is some python magic happening here. After using the idiom for years I hadn't really thought about it much until recently. From http Fri Jan 2 15:58:24 2009 From: http (Paul Rubin) Date: 02 Jan 2009 12:58:24 -0800 Subject: Is there a better algorithm? References: Message-ID: <7x8wptifwv.fsf@ruckus.brouhaha.com> Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > I want to loop through the list and extract the values. Others have suggested messy ways to code what you're asking. At another level, that list format seems like a code smell. You may be better off organizing the program so that L = [(1, None, 2), (3, 4, 5), (6, None, 7)] after which unpacking becomes trivial. From bearophileHUGS at lycos.com Fri Jan 2 15:58:41 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 12:58:41 -0800 (PST) Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> Message-ID: <95c3672c-105e-46b9-a241-7cb199ed45ba@r15g2000prh.googlegroups.com> Fuzzyman: > for i in l: > ? ?u = None > ? ?if len(i) == 2: > ? ? ? k, v = i > ? ?else: > ? ? ? ?k, u, v = i That's the best solution I have seen in this thread so far (but I suggest to improve indents and use better variable names). In programming it's generally better to follow the KISS principle. Bye, bearophile From steve at holdenweb.com Fri Jan 2 15:58:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 15:58:55 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102204444.GL28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <20090102204444.GL28417@dragontoe.org> Message-ID: <495E800F.8080808@holdenweb.com> Derek Martin wrote: > On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: >> Derek Martin wrote: [...] >>> It's small wonder that neophytes try to cram Python behaviors into >>> terms and computing concepts they already understand from learning >>> other languages, and that they fail to do so. What's mystifying is >>> that when Pythonistas reply to their messages, they universally seem >>> confused at how this could possibly happen, and often enough actually >>> seem offended (or at least offensive) when it inevitably does happen... >>> >> Generally speaking we try not to be offensive first on this list. > > Perhaps I've misused the term Pythonista... I meant roughly, "people > who frequent this list/news group who seem to consider themselves > experts at programming Python (and for the most part, are)." > I consider myself pretty well informed about Python (though not an > expert by any means), and I still read this list often (I use the > mailing list interface), because I still find that I learn useful > things from the posts to it from time to time. But I often see python > "experts" lambasting people who clearly from their posts are new at > python, because their code is bad, their understanding is bad, or in > this case even accusing the learning materials of being sub-par. I > realize that some of this is meant in jest, but a lot of it isn't, and > it can be quite difficult for someone who doesn't speak your language > natively (or even one who does, given the medium) to tell the > difference. There are better ways to foster understanding... ;-) > I don't think you can abuse a term that doesn't have any set meaning - generally it's used to refer simply to users of Python, or at least that's the way I use it. Lambasting is definitely not the way to proceed with learners, and generally the denizens of this group mostly behave properly. Even when meant in jest it's not appropriate, not helpful, and not Pythonic. I have been known to be unnecessarily crabby myself on the odd off-day, though usually when I catch myself behaving that way I try to apologize when it's appropriate. There are a few individuals who pop up from time to time and whose behavior is incendiary, but we should even ignore those. Not answering a post is the best way to ensure they don't come back seeking to offend again. Or, better still, change their ways and become model citizens. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From james at agentultra.com Fri Jan 2 16:06:48 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 16:06:48 -0500 Subject: Is there a better algorithm? References: <7x8wptifwv.fsf@ruckus.brouhaha.com> Message-ID: <8563kxh0yf.fsf@dozer.localdomain> Paul Rubin writes: > Kottiyath writes: >> I have the following list of tuples: >> L = [(1, 2), (3, 4, 5), (6, 7)] >> I want to loop through the list and extract the values. > > Others have suggested messy ways to code what you're asking. At another > level, that list format seems like a code smell. You may be better off > organizing the program so that > > L = [(1, None, 2), (3, 4, 5), (6, None, 7)] > > after which unpacking becomes trivial. Very true. +1 From GDoermann at gmail.com Fri Jan 2 16:07:56 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:07:56 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Message-ID: <2847b673-f936-4699-a5c0-46e66f884b8d@r36g2000prf.googlegroups.com> import os os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/local/app/mypthon.py I recieved an error > similar to the below error: > > Traceback (most recent call last): > File "script/art/auditlog.py", line 28, in ? > database = Config.get("DB", "user") > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > python2.3/ConfigParser.py", line 505, in get > raise NoSectionError(section) > ConfigParser.NoSectionError: No section: 'DB' > > I know why, the configuration which I reference in the script is > relative to "/usr/local/app", when I call the script via an absolute > path, then the relative the configuration file is base on where ever I > call the script from. One way to fix this is to add a path manually > into the variable. But I would like to avoid this hard-coding > parameter into my script. Is there a way to determined the relative > location of the script programatically? FYI, in the end this scrip > would run from CRON. From rcmn73 at gmail.com Fri Jan 2 16:08:34 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 13:08:34 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> Message-ID: <18c8ef26-116a-4ba8-85b8-a7013ad184b2@n33g2000pri.googlegroups.com> I just tried to compile with gui2exe. And i ran the exe. it faile the same way but at least generate a log. Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyc", line 522, in __bootstrap_inner File "pingable.py", line 35, in run File "subprocess.pyc", line 588, in __init__ File "subprocess.pyc", line 707, in _get_handles File "subprocess.pyc", line 752, in _make_inheritable WindowsError: [Error 6] The handle is invalid for every entry it generate this error and the line 35 is ...Popen ! From tjreedy at udel.edu Fri Jan 2 16:08:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jan 2009 16:08:57 -0500 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' For speed, I would look at PIL or pygame for existing function, or use numpy -- read into 2-d array, swap first and third members, flatten. From jsprad at gmail.com Fri Jan 2 16:15:04 2009 From: jsprad at gmail.com (sprad) Date: Fri, 2 Jan 2009 13:15:04 -0800 (PST) Subject: Noob question: Is all this typecasting normal? Message-ID: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> I've done a good bit of Perl, but I'm new to Python. I find myself doing a lot of typecasting (or whatever this thing I'm about to show you is called), and I'm wondering if it's normal, or if I'm missing an important idiom. For example: bet = raw_input("Enter your bet") if int(bet) == 0: # respond to a zero bet Or later, I'll have an integer, and I end up doing something like this: print "You still have $" + str(money) + " remaining" All the time, I'm going int(this) and str(that). Am I supposed to? From rcmn73 at gmail.com Fri Jan 2 16:15:45 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 13:15:45 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> <18c8ef26-116a-4ba8-85b8-a7013ad184b2@n33g2000pri.googlegroups.com> Message-ID: <7aa2f627-ea69-4f73-ba2b-400388637f33@w24g2000prd.googlegroups.com> On Jan 2, 3:08?pm, rcmn wrote: > I just tried to compile with gui2exe. And i ran the exe. it faile the > same way but at least generate a log. > Exception in thread Thread-1: > Traceback (most recent call last): > ? File "threading.pyc", line 522, in __bootstrap_inner > ? File "pingable.py", line 35, in run > ? File "subprocess.pyc", line 588, in __init__ > ? File "subprocess.pyc", line 707, in _get_handles > ? File "subprocess.pyc", line 752, in _make_inheritable > WindowsError: [Error 6] The handle is invalid > > for every entry it generate this error and the line 35 is ...Popen ! alright here is the issue : http://www.py2exe.org/index.cgi/Py2ExeSubprocessInteractions From gh at ghaering.de Fri Jan 2 16:16:26 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 02 Jan 2009 22:16:26 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <6s7ehbF4kp3aU1@mid.uni-berlin.de> Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: [...] If this is part of a real program, instead of an exercise, you should fix the code that creates this list of tuples so that they have a uniform length of 3. And if the third element is missing, it should be None. This saves lots of trouble later on. -- Gerhard From GDoermann at gmail.com Fri Jan 2 16:16:37 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:16:37 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> <2847b673-f936-4699-a5c0-46e66f884b8d@r36g2000prf.googlegroups.com> Message-ID: Note: The os.path.relpath is new in 2.6. If you are using an older version you will have to write your own algorithm TechieInsights wrote: > import os > os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) > > tekion wrote: > > Hello, > > I have a script in /usr/local/app/mypython.py and a configuration file > > relative to /usr/local/app/conf. When I call the script with an > > absolute path of /usr/local/app/mypthon.py I recieved an error > > similar to the below error: > > > > Traceback (most recent call last): > > File "script/art/auditlog.py", line 28, in ? > > database = Config.get("DB", "user") > > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > > python2.3/ConfigParser.py", line 505, in get > > raise NoSectionError(section) > > ConfigParser.NoSectionError: No section: 'DB' > > > > I know why, the configuration which I reference in the script is > > relative to "/usr/local/app", when I call the script via an absolute > > path, then the relative the configuration file is base on where ever I > > call the script from. One way to fix this is to add a path manually > > into the variable. But I would like to avoid this hard-coding > > parameter into my script. Is there a way to determined the relative > > location of the script programatically? FYI, in the end this scrip > > would run from CRON. From nad at acm.org Fri Jan 2 16:19:31 2009 From: nad at acm.org (Ned Deily) Date: Fri, 02 Jan 2009 13:19:31 -0800 Subject: Is there a better algorithm? References: <85aba9h1e5.fsf@dozer.localdomain> Message-ID: In article <85aba9h1e5.fsf at dozer.localdomain>, J Kenneth King wrote: > Kottiyath writes: > > I have the following list of tuples: > > L = [(1, 2), (3, 4, 5), (6, 7)] > > > > I want to loop through the list and extract the values. > > The only algorithm I could think of is: > >>>> for i in l: > > ... u = None > > ... try: > > ... (k, v) = i > > ... except ValueError: > > ... (k, u, v) = i > > ... print k, u, v > > --------- > > 1 None 2 > > 3 4 5 > > 6 None 7 > > ------------- > > But, this algorithm doesnt look very beautiful - like say -> for k, u, > > v in L: > > Can anyone suggest a better algorithm to get the values? > > Just a note: this isn't really an algorithm problem. ;) > > It's more of a grammar obstruction. > > To make your code more simple, it would be nice if the assignment > operator would return, "None," in the case where there are too few > values to unpack from the right-operand of the assignment operator. Looks like the extended iterable unpacking feature of Python 3.0, described in PEP 3132, comes to the rescue here: >>> L = [(1, 2), (3, 4, 5), (6, 7)] >>> for i in L: ... k, *u, v = i ... print(k, u, v) ... 1 [] 2 3 [4] 5 6 [] 7 -- Ned Deily, nad at acm.org From tjreedy at udel.edu Fri Jan 2 16:20:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jan 2009 16:20:07 -0500 Subject: If your were going to program a game... In-Reply-To: <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> References: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> Message-ID: Jean-Paul Calderone wrote: > No, PyPy includes an RPython to JavaScript compiler. RPython and Python > are > different languages. My impression from a few years ago is that RPython stands for Restricted Python and that it was/is? a proper subset of Python. Has this changed? From code at pizzashack.org Fri Jan 2 16:28:29 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 15:28:29 -0600 Subject: why cannot assign to function call In-Reply-To: <495e814d$0$3502$426a34cc@news.free.fr> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: <20090102212829.GM28417@dragontoe.org> On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: >> Python seems rather weird, and I think from the frequency >> with which these discussions occur on this list, clearly it *IS* >> difficult for a neophyte Python programmer to understand the >> assignment model. > > Took me about half an hour to grasp, not even being "CS grad" (nor > whathever "grad" FWIW). By that time, I had a couple monthes working > experience with VB, and had learned (but never seriously used) bits of > C, C++, Java and Pascal. It took me about a half a second to grasp the "named bins" concept -- i.e. as soon as I was finished reading the words that explained it I understood it, so I'd say that based on your half-hour number, Python's model is substantially more complicated. My own experience was kind of similar... When I read about Python's model I didn't understand it the first time around, had to re-read the section I read that described it, and then had to play with it to see for myself how it worked. I'd estimate it took 10 minutes. I'm not a CS grad either (my degree is in information technology) but I did take the first two years of CS classes at my local college (as a bridge to a masters degree in CS, which I never completed), and I've been programming as a hobbyist, in school, and in my profession for 25 years. I would argue that ideally, it should not take an experienced programmer 10 minutes to understand variable assignment. :) [Note that I'm including the semantics for passing arguments to functions as part of "assignment" for purposes of this discussion.] -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From benjamin.kaplan at case.edu Fri Jan 2 16:35:52 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 2 Jan 2009 16:35:52 -0500 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: On Fri, Jan 2, 2009 at 4:15 PM, sprad wrote: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet > > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" > > All the time, I'm going int(this) and str(that). Am I supposed to? The cast to the int is needed. The cast to a string isn't. Use string formatting instead. As an added bonus, you can ensure that you always show 2 digits past the decimal. >>> money = 2.1 >>>print "You still have $%0.2f remaining" % money You still have $2.10 remaining > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Jan 2 16:36:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 02 Jan 2009 22:36:00 +0100 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <6s7fm0F4k5tsU1@mid.uni-berlin.de> sprad schrieb: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. It is normal, although below you make things needlessly complicated. Python is strongly typed, which is a good thing. It refuses to guess you mean when you multiply a string with a number. Or how a number is to be formatted when printed. > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet You might better do bet = int(raw_input("Enter your bet")) because then you don't need to later on convert bet again and again. But *one* conversion you need. > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" This is more concisely & with much better control over the output-format (think e.g. digits of a fraction) using string-interpolation. See http://docs.python.org/library/stdtypes.html#string-formatting-operations for an overview. In your case, a simple print "You still have $%i remaining" % bet does the trick. Diez From castironpi at gmail.com Fri Jan 2 16:36:16 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 2 Jan 2009 13:36:16 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: On Jan 2, 12:11?pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ... ?u = None > ... ?try: > ... ? (k, v) = i > ... ?except ValueError: > ... ? (k, u, v) = i > ... ?print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? for i in L: k, u, v= i[ 0 ], i[ 1 ], i[ -1 ] if len( i )== 2: u= None From mario.ruggier at gmail.com Fri Jan 2 16:38:15 2009 From: mario.ruggier at gmail.com (mr) Date: Fri, 2 Jan 2009 13:38:15 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> As has been noted, the best is to fix the input to be regular-3- tuples. For the fun of it, here's another variation of a solution: tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u, v for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: print k, u, v From GDoermann at gmail.com Fri Jan 2 16:47:25 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:47:25 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <222d2d49-e96d-412e-aace-3fae272b59e6@u18g2000pro.googlegroups.com> You can use the built-in string formatting options and operations. 2.5: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html 2.6: http://docs.python.org/library/string.html In essence, you can do: print "You still have $%i remaining" %(money) On Jan 2, 2:15?pm, sprad wrote: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > ? ? # respond to a zero bet > > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" > > All the time, I'm going int(this) and str(that). Am I supposed to? From bthate at gmail.com Fri Jan 2 17:04:46 2009 From: bthate at gmail.com (Bart Thate) Date: Fri, 2 Jan 2009 14:04:46 -0800 (PST) Subject: Request For (gozerbot) Testers Message-ID: So 0.9 is getting in shape and there is one issue that keeps me from releasing 0.9 and that is the upgrade path. 0.9 is vastely different from 0.8 so a special upgrade script has been written to aid with this. Now i have tested this on some gozerbot users but i need a more broader audience that wants to test this for me. So if you run a 0.8 gozerbot you could help me out with testing the 0.9 upgrade script, testing can be done along side your own bot so you dont loose your old configuration. To test do the following: 1) hg clone http://core.gozerbot.org/hg/dev/0.9 0.9bot 2) cd 0.9bot 3) hg clone http://core.gozerbot.org/hg/plugs/gozerplugs 4) ./bin/gozerbot-upgrade . 5) ./bin/gozerbot Check if the bot has converted your data properly with the !size command. As a last step you can test the plugins with the !test-plugs command. If you have any problems with testing gozerbot 0.9 let me know on #dunkbots IRCnet or at bthate at gmail.com .. THNX ;] Bart see http://gozerbot.org/newsite/0.9/ for more information about the upcoming 0.9 release From code at pizzashack.org Fri Jan 2 17:16:41 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 16:16:41 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: <20090102221641.GN28417@dragontoe.org> On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: >>> Identity isn't defined on math objects, only on Python objects; there >>> is no notion of 'is' in math. >> >> This is also false, it even has its own operator (which requires >> Unicode to display): ? > > That can mean a number of things, one of which means "is identically > equal to," Quite so. > but identity means something different in mathematics than it means > here. But for non-mutable objects, aren't they essentially the same? Mathematics has no concept of "objects" in the sense that computer science does, so of course the best you can really do is draw parallels. > In mathematics, identity means a relationship that is true > regardless of the value of the variables involved (as opposed to > equality which is only true under more specific circumstances). Does 2 = 2 not qualify? Isn't it true that 2 ? 2 and 2 is 2? :) Yet there are no variables at all... The "objects" of mathematics are numbers, which are constants, which as such I would argue always have the same "identity" as themselves. Other components of mathematics are "expressions", which may or may not evaluate to constants, depending on the set conditions. Python has those too, and they are not the same as objects. > In computer science, identity means that two expressions are > represented by the same object, something which not only has no > meaning in mathematics, We're getting way off track here, but I would argue this is also false. Take sets, for example: A = { 1, 2, 3 } B = { 1, 2, 3 } Is it not true that A ? B and in fact these two sets are the same, i.e. they are not actually two different sets at all; the have the same identity, even considering a definition of "identity" which reflects that in Python? A and B are in fact simply two different names we've given to the same mathematical entity. The major difference between mathematics and Python is that mathematical objects are essentially unique, i.e. the constant 1 is arguably always the same 1 wherever it appears, because there is no mathematical need to have multiple instances of the constant 1: Wherever you see the symbol '1' OR an expression which evaluates to the constant 1, it refers to a *concept* of the numerical value representing mathematical singularity and wholeness. In python, you can have multiple instances of objects which are identical to each other (though for this simple case, even python only creates one instance of the object). > but which should also be clear since > mathematical identities need not have any individual variables on > either side of the triple bar; take, for instance, the > trigonometric identity > > cos^2 theta + sin^2 theta = 1. Is theta not a variable? :) Not that it matters... > Even if you write this equation with the triple bar to represent a > mathematical identity (which it is), it obviously doesn't say anything > about which "objects" are the same as each other. I don't imagine I would agree, based on what I just said. To elaborate, each side of the expression contain symbols which always evaluate to the same constant. The identity of a constant is constant. :) Thus the objects on both sides are indeed the same identical mathematical entity... they are just expressed differently. It's just like if you refered to your kitchen table (assuming you have only one kitchen table) as "the table" or as "the large table I eat on in the kitchen..." No matter what you call it, it's still the same table. In the case where the identity can not be reduced to constants, the two expressions still evaluate to the same mathematical entity... except that you need to set the conditions (i.e. give values to the variables) to find out what that actually is. It seems exactly analogous to Python to me, except that again, unlike Python, there is no possibility that there can ever be two instances of the same object and thus applying the term "identity" to mathematical objects is not useful. It's not that it is meaningless, it just isn't very interesting. Clearly though, 2 is not 3, and these two mathematical objects do not have the same identity. Perhaps there is no concept of identity in mathematics precisely because it is unnecessary: 1 is always 1, by definition. But that is the definition of "is"... :) But the discussion is bordering on philosophy, and I will resign from it at this point, having previously made the points I intended to. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From vminch at gmail.com Fri Jan 2 17:36:04 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 14:36:04 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> Message-ID: <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> > You might better do > > bet = int(raw_input("Enter your bet")) > > because then you don't need to later on convert bet again and again. This is all fine until you give it to an end-user. This is what I picture: $ ./script.py Enter your bet: $10 .. or perhaps "ten", "all", or a jillion other tainted inputs. Python will try to cast these strings, but will slap you with a ValueError instead (an error of some sort, at least). There needs to be a "user_io" or "sanitize" module in the standard library to take care of this stuff. Like: import userio logic = userio.userio() number = logic.getNumeric("blah: ") # will offer the user a "re-do" in case of bad input number = logic.forceGetNumeric("Enter your bet!: ") # even if input is tainted, will return some number text = logic.getText("blargh: ") # return all text text = logic.setValidText("[A-Za-z]") text = logic.forceGetText("blargh: ") # return some text, strips invalid chars ... but there isn't, as far as I know. From geekmail at usenot.de Fri Jan 2 17:41:28 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 23:41:28 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <20090102234128.0078d982@usenot.de> On Fri, 2 Jan 2009 14:36:04 -0800 (PST) vk wrote: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > [snip example] > Great idea! +1 > ... but there isn't, as far as I know. Well, get to it, then. ;) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From don at geddis.org Fri Jan 2 17:47:35 2009 From: don at geddis.org (Don Geddis) Date: Fri, 02 Jan 2009 14:47:35 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <878wpt8gvs.fsf@geddis.org> Richard Riley wrote on Thu, 01 Jan 2009: > Tim Greer writes: >> That poster has a frequent habit of cross posting to multiple, irrelevant >> news groups. There's no rhyme or reason to it. > > No rhyme nor reason? It's quite clear, to me, why. How is a comparison > article not relevant when he is trying to stimulate discussion about > alternative languages for modern development? Sometimes crossposting can be useful. But you ought to at least be aware of some of the possible drawbacks, e.g. expressed here: http://www.nhplace.com/kent/PFAQ/cross-posting.html In particular, the usual hope by the poster is that the content is relevant to the union of people in the different groups, but the actual experience is that it is often relevant only to the intersection of such people. And, moreover, that a long cross-posted thread on controversial topics often winds up with people talking at cross-purposes past each other, because they don't share enough common values to have a useful conversation. In particular, the poster that started this thread is well known for adding far more noise than signal to any discussion, and for showing no interest in the greater good of any of the communities, but only in his own glorification. You labor under the delusion that there is at least good intent here, and the poster ought to receive the benefit of the doubt. Long prior experience shows that this hope is misplaced. -- Don _______________________________________________________________________________ Don Geddis http://don.geddis.org/ don at geddis.org The only purpose for which power can be rightfully exercised over any member of a civilized community, against his will, is to prevent harm to others. His own good, either physical or moral, is not a sufficient warrant. -- John Stuart Mill, _On Liberty_ From huffman at tokyo.email.ne.jp Fri Jan 2 17:48:00 2009 From: huffman at tokyo.email.ne.jp (Tokyo Dan) Date: Fri, 2 Jan 2009 14:48:00 -0800 (PST) Subject: If your were going to program a game... References: <85eizlhhu5.fsf@dozer.localdomain> Message-ID: On Jan 3, 12:02?am, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > > browser in a window of a social site built around the game. The social > > site has login, chat, player stats, list of active games, etc. AND > > there is also be a desktop client that accesses the game server via > > the same communication mechanism (like an AIR-based desktop client/ > > app) as the browser-based version - I guess using JSON/RPC. > > Ever see chess.com? > > I don't know what they're using in the backend, but the client is > entirely javascript. > > You could probably roll your own python javascript compiler to suit your > needs. It could probably even build up your own DSL for writing these > games. > > It's a worthwhile project and I think there might be support for it from > other developers. "You could probably roll your own python javascript compiler..." There's already one. I'm surprised that you don't know about it: "Pyjamas" st http://pyjs.org . Also see Pyjamas-desktop" at http://pyjd.org From max at alcyone.com Fri Jan 2 17:53:46 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Jan 2009 14:53:46 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: Derek Martin wrote: > On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: >>>> Identity isn't defined on math objects, only on Python objects; there >>>> is no notion of 'is' in math. >>> This is also false, it even has its own operator (which requires >>> Unicode to display): ? >> That can mean a number of things, one of which means "is identically >> equal to," > > Quite so. > >> but identity means something different in mathematics than it means >> here. > > But for non-mutable objects, aren't they essentially the same? > Mathematics has no concept of "objects" in the sense that computer > science does, so of course the best you can really do is draw > parallels. That's exactly the point. There is no concept of object identity in mathematics, so the above statement that you called false is, in fact, true. The concept does not translate. >> In computer science, identity means that two expressions are >> represented by the same object, something which not only has no >> meaning in mathematics, > > We're getting way off track here, but I would argue this is also > false. Take sets, for example: > > A = { 1, 2, 3 } > B = { 1, 2, 3 } > > Is it not true that A ? B and in fact these two sets are the same, > i.e. they are not actually two different sets at all; the have the > same identity, even considering a definition of "identity" which > reflects that in Python? Only if you try to make up a concept of identity that mathematics doesn't already have. The existing concept, which you invoked, has nothing to do with _object_ identity, it just has to do with a broader equality. > I don't imagine I would agree, based on what I just said. To elaborate, > each side of the expression contain symbols which always evaluate to > the same constant. The identity of a constant is constant. :) Except identities don't have to contain constants at all. They can contain arbitrary expressions on either side of the "is identically equal to" symbol. Which clearly indicates that the symbol can't mean the same thing as the identity operator in computer science, as you were claiming it did. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis There's something immoral about abandoning your own judgement. -- John F. Kennedy From rt8396 at gmail.com Fri Jan 2 17:57:07 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 14:57:07 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <14ec52c0-69e9-4366-90c3-c91e9a7a48a2@m2g2000vbp.googlegroups.com> > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. [snip] +1 You are sooo right. You know, it is easy to forget about such things after you learn a language, i have written my own input logic, but i remember my __init__ days with python now and the learning curve. Every new user will makes much use of raw_input()[or input 3.0] and has to climb this same little hill every time, you and i do it as second nature. A small module like you describe would be a great addition to the standard library, and heck, i would even use it :) From google at mrabarnett.plus.com Fri Jan 2 18:00:54 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 02 Jan 2009 23:00:54 +0000 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <495e6b08$0$11376$5fc30a8@news.tiscali.it> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <495e6b08$0$11376$5fc30a8@news.tiscali.it> Message-ID: <495E9CA6.20008@mrabarnett.plus.com> Francesco Bochicchio wrote: > imageguy ha scritto: >> I am looking for the most efficient method of replacing a repeating >> sequence in a byte string returned from a imaging .dll, connected via >> >> I receive the byte string with the following sequence 'bgrbgrbgrbgr' >> and I would like to convert this to 'rbgrbgrbgrbg' >> FWIW, the string is created using ctypes.create_string_buffer function >> >> The following code works but feels a bit clunk and is rather slow too. >> >> blist = list(buffer) >> for start in xrange(0,len(blist), 3): >> try: >> blue = blist[start] >> red = blist[start+2] >> blist[start] = red >> blist[start+2] = blue >> except IndexError: >> pass >> >> new_buffer = ''.join(blist) >> >> new_buffer is then passed to a wx program to create and image. >> >> Any thoughts comments would be appreciated. >> >> geoff. >> >> PS: I started this post earlier, but I think I hit the send button >> too soon. My apologies to the group for sloppy typing. >> > You could try the same algorithm on an array.array object : it might be > faster. > >>> s = "012345678" >>> from array import array >>> a = array("b", s) >>> a array('b', [48, 49, 50, 51, 52, 53, 54, 55, 56]) >>> a[0::3], a[2::3] = a[2::3], a[0::3] >>> a array('b', [50, 49, 48, 53, 52, 51, 56, 55, 54]) >>> a.tostring() '210543876' From bignose+hates-spam at benfinney.id.au Fri Jan 2 18:18:55 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 10:18:55 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <87sko1l2jk.fsf@benfinney.id.au> vk writes: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > Like: > > import userio > > logic = userio.userio() > > number = logic.getNumeric("blah: ") # will offer the user a "re-do" in > case of bad input > number = logic.forceGetNumeric("Enter your bet!: ") # even if input is > tainted, will return some number > > text = logic.getText("blargh: ") # return all text > > text = logic.setValidText("[A-Za-z]") > text = logic.forceGetText("blargh: ") # return some text, strips > invalid chars > > > ... but there isn't, as far as I know. If there were, I would expect it to conform with PEP 8 (get those ugly camelCase names outta there :-) -- \ ?The face of a child can say it all, especially the mouth part | `\ of the face.? ?Jack Handey | _o__) | Ben Finney From bearophileHUGS at lycos.com Fri Jan 2 18:28:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 15:28:57 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <495e6b08$0$11376$5fc30a8@news.tiscali.it> Message-ID: <10101f11-9380-436f-a36a-b16a5bf47611@e1g2000pra.googlegroups.com> imageguy: > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function MRAB: > ?>>> a.tostring() > '210543876' That's not the required 'rbgrbgrbgrbg', but you are close to a correct solution: >>> from array import array >>> s = 'bgrbgrbgrbgr' >>> a = array("B", s) # uppercase B >>> a[0::3], a[1::3], a[2::3] = a[2::3], a[0::3], a[1::3] >>> a.tostring() 'rbgrbgrbgrbg' Bye, bearophile From hamish at valvesoftware.com Fri Jan 2 18:49:25 2009 From: hamish at valvesoftware.com (Hamish McKenzie) Date: Fri, 2 Jan 2009 15:49:25 -0800 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: I actually have no idea what ur talking about... aren't conversations threaded by subject? -----Original Message----- From: python-list-bounces+hamish=valvesoftware.com at python.org [mailto:python-list-bounces+hamish=valvesoftware.com at python.org] On Behalf Of r Sent: Friday, January 02, 2009 12:12 PM To: python-list at python.org Subject: Re: type conversion On Jan 2, 1:46 pm, Robert Kern wrote: > r wrote: > > On Jan 1, 4:40 pm, Robert Kern wrote: > >> Hamish McKenzie wrote: > >>> sometimes I want to be able to initialize an instance with a variety of different data types. > >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just > >> assign to attributes. I would add a from() classmethod for each that > >> I wanted to support. If I really wanted an all-singing, all-dancing > >> initialization method, I would add another classmethod that would just dispatch > >> to the appropriate type-specific classmethod. I prefer classmethods to plain > >> functions because I can subclass. > > >> -- > >> 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 > > > Why are you busting into this thread? > > Are you talking to me, or Hamish, who (presumably unintentionally) responded to > a message instead of making a new thread? > > If you want to suggest that one should have more care about starting new > threads, that's fine, but please do not jump to the conclusion that there is > malintent. And don't chastise people for not being as rude as you. > > -- > 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 I am not so much chastising Hamish as i am Steven, Steven knows better than this BS, and has preached to so many people about off topic post that my ears are bleeding from his incessant rambling about it. Now, he goes and does what he complains about soooo much. I'm just calling him on it thats all. I can't speak for the other responders because i know of none of them. -- http://mail.python.org/mailman/listinfo/python-list From sjmachin at lexicon.net Fri Jan 2 19:04:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 16:04:32 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <782c68cf-ce9d-4f32-8ea3-6d57257b1b54@x16g2000prn.googlegroups.com> On Jan 3, 2:01?am, brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: > > On Dec 31 2008, 4:02 pm, brooklineTom wrote: > > > > andyh... at gmail.com wrote: > > > > Hi, > > > > > Can anybody recommend an approach for loading and parsing Excel > > > > spreadsheets in Python. Any well known/recommended libraries for this? > > > > > The only thing I found in a brief search was http://www.lexicon.net/sjmachin/xlrd.htm, > > > > but I'd rather get some more input before going with something I don't > > > > know. > > > > > Thanks, > > > > Andy. > > > > I save the spreadsheets (in Excel) in xml format. > > > Which means that you need to be on a Windows box with a licensed copy > > of Excel. I presume you talking about using Excel 2003 and saving as > > "XML Spreadsheet (*.xml)". Do you save the files manually, or using a > > COM script? What is the largest xls file that you've saved as xml, how > > big was the xml file, and how long did it take to parse the xml file? > > Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. My point was that however the original XLS files were created or acquired, the first step in your solution involves converting the XLS file to "XML Spreadsheet" format, which requires a copy of Excel on a Windows box. Many people start with an XLS file, no Excel and no Windows box, no COM, and users who can't be relied on to open a file and save it in the right format with the right name and extension. BTW, did you consider opening the XLS files with OpenOffice.org's Calc and saving it in their default ods format (chunks of XML in a zip file)? > 3. The largest file I used was about 228M, Is that the XLS file or the XML file? > containing 36,393 hotel > properties from Commission Junction. Each entry had 113 cells. The > parsing overhead was minimal (on a per-entry basis) -- that's why I > choose to use a pull-parser. > 4. I extracted primarily cell contents, though I did some very limited > format handling (looking for non-text fields and such). I don't understand "looking for non-text fields" as "format handling". To my way of thinking, knowing the data-type that Excel has assigned to a cell is close to essential for effective use of the contents. And you don't have to look very far: the ss:Type attribute tells you whether a cell's content is String, Number, DateTime, Boolean, or Error. > > > xhtml. I know there are various python packages around that do it, but > > > I found the learning curve of those packages to be steeper than just > > > grokking the spreadsheet structure itself. > > > I'm curious to know which are the "various python packages" with the > > so steep learning curves, and what the steep bits were. > > I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. Not so focused at all. The default behaviour of xlrd is to ignore formatting info as much as possible. AFAICT this is the mode used by most users. > I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. Possibly incorrectly. If approached at the time, I would have said: (a) if desperate to DIY: (a1) ignore any code for old Excel versions (self.biff_version < 80) (a2) ignore any code for extracting formatting info (self.formatting_info) (a3) find the Sheet.put_cell* methods in sheet.py e.g. def put_cell(self, rowx, colx, ctype, value, xf_index): ignore the xf_index arg and subvert them to your own needs instead of filling up a big rectangular arena with data (b) if not really so desperate, talk to me about implementing an option in xlrd where callers can specify a callback to be used instead of the Sheet.put_cell* methods (c) What is all this "port to my own framework" caper anyway? If you need to extract data from a database, do you rummage in their code libraries and port the relevant bits to your own framework? > > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. Building objects in your own framework and checking data integrity is something that happens *after* you've got the basics for a cell (row id, column id, data type, data value). You have dodgy postal addresses? You're not alone, and it's not relevant to how you parse the spreadsheet or even whether the data source was a spreadsheet or a database query or a box of punched cards. > My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. "Crack"? It's not the Enigma code. It's not even rot13. Spreadsheet XML tells you the type (String, Boolean, ...). xlrd tells you the type (XL_CELL_TEXT, XL_CELL_BOOLEAN, ...). > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > > I hope this helps! I think so. Thanks. You didn't directly address the "steep learning curve" question, but you explained enough of where you came from. It's a matter of "horses for courses". I guess some people might regard (xml.dom, xml.dom.minidom, DIY "pullparser") as having a slightly non-horizontal learning curve :-) Cheers, John From vminch at gmail.com Fri Jan 2 19:16:10 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 16:16:10 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> Message-ID: <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> > If there were, I would expect it to conform with PEP 8 (get those ugly > camelCase names outta there :-) haha, please forgive me. I'll try and think of some more creative names. atm, I've got a chem final to study for. I'll probably post something resembling useful code tomorrow morning. until then, int(input()) away! From lists at cheimes.de Fri Jan 2 19:16:17 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 03 Jan 2009 01:16:17 +0100 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: Hamish McKenzie schrieb: > I actually have no idea what ur talking about... aren't conversations threaded by subject? Nope, they are threaded by message id. The subject is used as fallback only. Christian From tim at burlyhost.com Fri Jan 2 19:20:49 2009 From: tim at burlyhost.com (Tim Greer) Date: Fri, 02 Jan 2009 16:20:49 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: Don Geddis wrote: > Richard Riley wrote on Thu, 01 Jan 2009: >> Tim Greer writes: >>> That poster has a frequent habit of cross posting to multiple, >>> irrelevant >>> news groups. There's no rhyme or reason to it. >> >> No rhyme nor reason? It's quite clear, to me, why. How is a >> comparison article not relevant when he is trying to stimulate >> discussion about alternative languages for modern development? > > Sometimes crossposting can be useful. But you ought to at least be > aware of some of the possible drawbacks, e.g. expressed here: > http://www.nhplace.com/kent/PFAQ/cross-posting.html > > In particular, the usual hope by the poster is that the content is > relevant to the union of people in the different groups, but the > actual experience is that it is often relevant only to the > intersection of such people. > > And, moreover, that a long cross-posted thread on controversial topics > often winds up with people talking at cross-purposes past each other, > because they don't share enough common values to have a useful > conversation. > > In particular, the poster that started this thread is well known for > adding far more noise than signal to any discussion, and for showing > no interest in the greater good of any of the communities, but only in > his own glorification. > > You labor under the delusion that there is at least good intent here, > and the > poster ought to receive the benefit of the doubt. Long prior > experience shows that this hope is misplaced. > > -- Don Thank you, Don, for outlining the issue far more eloquently than I was able to. Also, to be clear, I don't think anyone's upset that people find his posts interesting, but it doesn't make it so for everyone else (or assign them any ailment if they don't see it that way) -- especially in regard to the other groups he cross posts to (of which one should have specifically been the ruby group, but I digress.) -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From geekmail at usenot.de Fri Jan 2 19:26:25 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 3 Jan 2009 01:26:25 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <20090103012625.2d0fbf21@usenot.de> On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. FYI: The names themselves aren't he problem at all. They just should be all_lowercase_with_underscores if they're functions or variables. CamelCase (with initial capital!) is "reserved" for classnames only. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From sjmachin at lexicon.net Fri Jan 2 19:33:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 16:33:28 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> On Jan 3, 5:34?am, imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. For some very strange definition of "works". You say you have 'bgr' and want to convert it to 'rbg'. The following code converts 'bgr' to 'rgb', which is somewhat more plausible, but not what you said you wanted. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > ? ?try: > ? ? ? ? blue = blist[start] > ? ? ? ? red = blist[start+2] > ? ? ? ? blist[start] = red > ? ? ? ? blist[start+2] = blue > ? ?except IndexError: > ? ? ? ?pass > > new_buffer = ''.join(blist) > From rt8396 at gmail.com Fri Jan 2 19:44:11 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 16:44:11 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> Message-ID: On Jan 2, 6:26?pm, Andreas Waldenburger wrote: > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-) ? > > > haha, please forgive me. > > I'll try and think of some more creative names. > > FYI: The names themselves aren't he problem at all. They just should > be all_lowercase_with_underscores if they're functions or variables. > CamelCase (with initial capital!) is "reserved" for classnames only. > > /W > > -- > My real email address is constructed by swapping the domain with the > recipient (local part). FYI camelCase with __init__ capital is called "title case" try this: >>> 'hello world".title() From greno at verizon.net Fri Jan 2 19:54:38 2009 From: greno at verizon.net (Gerry Reno) Date: Fri, 02 Jan 2009 19:54:38 -0500 Subject: Why not Ruby? In-Reply-To: References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: <495EB74E.10301@verizon.net> There's been almost 50 responses to this rubbish post. Could you please all stop! From geekmail at usenot.de Fri Jan 2 19:57:25 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 3 Jan 2009 01:57:25 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> Message-ID: <20090103015725.086f7658@usenot.de> On Fri, 2 Jan 2009 16:44:11 -0800 (PST) r wrote: > On Jan 2, 6:26?pm, Andreas Waldenburger wrote: > > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > > > If there were, I would expect it to conform with PEP 8 (get > > > > those ugly camelCase names outta there :-) ? > > > > > haha, please forgive me. > > > I'll try and think of some more creative names. > > > > FYI: The names themselves aren't he problem at all. They just should > > be all_lowercase_with_underscores if they're functions or variables. > > CamelCase (with initial capital!) is "reserved" for classnames only. > > > > /W > > > > -- > > My real email address is constructed by swapping the domain with the > > recipient (local part). > > FYI camelCase with __init__ capital is called "title case" try this: > OK, since we're smartassing anyway: CamelCase refers specifically to compound words or phrases that are conjoined, that is, written without spaces between the words, where words are separated by writing their respective first letters in capitals. Title case however refers to normal phrases where (space separated) words are capitalized, and no inner capitals occur (unless of course actual CamelCase words are used in the phrase). You even assumed that distinction in your example: > >>> 'hello world".title() /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gherron at islandtraining.com Fri Jan 2 20:05:35 2009 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 02 Jan 2009 17:05:35 -0800 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <495EB9DF.6050001@islandtraining.com> imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > > -- > http://mail.python.org/mailman/listinfo/python-list > I've not seen anyone mention numpy yet, but numpy has a nice (efficient) way to do this: >>> import numpy >>> s = 'bgrBGRcbaCBA' >>> a=numpy.array(s, 'c') # Initialize an array >>> a.shape = (4,3) # Reinterpret as a ?? by 3 array >>> b=a[...,::-1] # reverse the second dimension >>> print b.tostring() # Convert back to a string. rgbRGBabcABC Gary Herron From sjmachin at lexicon.net Fri Jan 2 20:06:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 17:06:02 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <27cc82fd-277e-4420-8df5-ac64c5c37e6e@b38g2000prf.googlegroups.com> On Jan 3, 11:16?am, vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those ugly > > camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. > > atm, I've got a chem final to study for. > I'll probably post something resembling useful code tomorrow morning. > > until then, int(input()) away! Building on the earlier example (entering the amount of money for a bet), consider the following possibilities: 10 $10 USD 10.00 USD 10,00 # many European locales 10000 # moving to the high rollers table 10,000 10.000 # European 10T # T -> thousand dates: 1/12/35 # 1 December or 12 January? What year? 2035? Perhaps not, if the prompt was 'Enter pensioner's date of birth -> '. etc etc ... IOW consider not biting off more than you can chew. Also consider that raw_input is not sufficiently frequently used in real-world applications to warrant a data validation library to be built on top of it. From rt8396 at gmail.com Fri Jan 2 20:12:00 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 17:12:00 -0800 (PST) Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: On Jan 2, 6:54?pm, Gerry Reno wrote: > There's been almost 50 responses to this rubbish post. Could you please > all stop! Donde es Xah Lee? From bignose+hates-spam at benfinney.id.au Fri Jan 2 20:20:32 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 12:20:32 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <87k59dkwwv.fsf@benfinney.id.au> vk writes: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. They don't need to be creative; they merely need to conform with the naming scheme as laid out in the PEP. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From 4329402926 at txt.att.net Fri Jan 2 20:28:39 2009 From: 4329402926 at txt.att.net (4329402926 at txt.att.net) Date: Fri, 2 Jan 2009 20:28:39 -0500 Subject: No subject Message-ID: <20090103012839.KNSY5498.atlmtaow03.cingularme.com@txt.att.net> -- ================================================================== This mobile text message is brought to you by AT&T From mario.ruggier at gmail.com Fri Jan 2 20:29:29 2009 From: mario.ruggier at gmail.com (mario) Date: Fri, 2 Jan 2009 17:29:29 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? Message-ID: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Hi, below is the essence of a an expression evaluator, by means of a getitem lookup. The expression codes are compiled and cached -- the lookup is actually recursive, and the first time around it will always fail. import sys class GetItemEval(object): def __init__(self): self.globals = globals() # some dict (always the same) self.locals = {} # some other dict (may be different between evaluations) self.codes = {} # compiled code expressions cache def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # KeyError, NameError, AttributeError, SyntaxError, ValueError, # TypeError, IOError # # Special case if a KeyError is coming from the self.codes [name] # lookup (traceback should consist of a single frame only): if sys.exc_info()[2].tb_next is None: if sys.exc_info()[0] is KeyError: self.codes[expr] = compile(expr, '', 'eval') return self[expr] # otherwise handle eval error in some way... This class could be used in a way as follows: # define some expressions def f(s): return "["+s+"]" exprs = ["1+2+3", "2*3*5", "f(__name__)"] # instantiate one gie = GetItemEval() # use it to lookup/eval each expression for x in exprs: print x, "=", gie[x] And, fwiw, some sample timeit code: import timeit print timeit.Timer("for x in exprs: gie[x]", "from __main__ import gie, exprs").timeit(500000) I had done various poking to discover if it could be made to go faster, and in the end I settled on the version above. mario Incidentally this constitutes the lion's share of the evaluation runtime of evoque templating... http://evoque.gizmojo.org/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 20:46:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 01:46:37 GMT Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: <016eba68$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 15:49:25 -0800, Hamish McKenzie wrote: > I actually have no idea what ur talking about... aren't conversations > threaded by subject? Not usually. When you hit Reply to a post, your post gets a hidden header line that says "I'm a reply to post #12345" (whatever post number it is). Just because you change the subject line doesn't change that. Most newsreader programs thread by that header, not the subject. Consequently most people who view posts in thread order will see: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Hello I'm changing the subject line +-- Re: Hello I'm changing the subject line +-- Re: Subject X Y Z +-- Re: Subject X Y Z This has the serious disadvantages that: (1) It annoys people who do threading; and (2) If people are ignoring a thread, they won't even see your post even though you have changed the subject line. It is considered rude to hijack a thread for a completely new subject, although it is acceptable to change the subject line if the thread gradually evolves to a new discussion: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Subject A B C [was Re: Subject X Y Z] +-- Re: Subject A B C [was Re: Subject X Y Z] Don't mistake the above for off-topic posting, which is something completely different, nor for cross-posting, which is different again. Off-topic posts are ones that don't have anything to do with the news group they are sent to, e.g. a message about Ruby sent to a Python list. It is barely acceptable to occasionally post brief off-topic messages that are particularly amusing or important if you label them such with [OT] or [off-topic] in the subject line. Cross-posting is sending a single message to more than one newsgroup. If you absolutely must cross-post, you should always set the Followup-To header to *one* newsgroup. If you don't know how to set followups, then don't cross-post. -- Steven From aleksandr.goretoy at gmail.com Fri Jan 2 20:52:04 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 01:52:04 +0000 Subject: list iteration if statement Message-ID: Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not int("0") then append to v list? Thank you in advance. -A -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 2 21:02:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 21:02:19 -0500 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <87k59dkwwv.fsf@benfinney.id.au> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > vk writes: > >>> If there were, I would expect it to conform with PEP 8 (get those >>> ugly camelCase names outta there :-) >> haha, please forgive me. >> I'll try and think of some more creative names. > > They don't need to be creative; they merely need to conform with the > naming scheme as laid out in the PEP. > They don't *need* to do that. It's just a good habit to get into if you plan to write code that gets read and possibly modified by other people. If you write a function called doSomething the PSU won't "%@#&%":,,.. carrier lost From aleksandr.goretoy at gmail.com Fri Jan 2 21:05:49 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:05:49 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login", "user":l["user"], "pass":l["pass"] } and it wouldn't work. So I had to do some research on how to make it work. passing a mutable object resolved my problem. Thank you for correcting me. -A On Thu, Jan 1, 2009 at 6:22 PM, Terry Reedy wrote: > alex goretoy wrote: > >> I recently conquered this pass by ref thing. This is how I did it. >> > > What you did was to pass a mutable object and mutate it. Absolutely > standard practice in Python. I am glad you learned it, but also learning > and using the standard terminology will also help. Hope you enjoy Python > too. > > tjr > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:07:35 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:07:35 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login", "user":l["user"], "pass":l["pass"] } and it wouldn't work. So I had to do some research on how to make it work. passing a mutable object resolved my problem. Thank you for correcting me. -A ps.I have this habit of pressing reply instead of reply to all. Working on fixing that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Fri Jan 2 21:07:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 02:07:57 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: <495EC87D.4040003@mrabarnett.plus.com> alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A > By: if j is not int("0") I assume you mean: if j != int("0") or just: if j != 0 The list comprehension is: [[v.append(j) for j in i if j != 0] for i in self.value] BWT, do you know that v.append(j) modifies v in-place and returns None, so the result of the list comprehension is a list of lists of None? From steve at holdenweb.com Fri Jan 2 21:09:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 21:09:48 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A Who, tiger. It "works" for a value of "works" that involves creating two lists. One is the one you want, referenced by v, and the other is the value if the list comprehension, which will be a list full of lists of all the None values returned by those append() calls. But I presume you are throwing that second list away ... See, a list comprehension is intended to create a list. So what you should have used (assuming v was the empty list before you started) was v = [[j for j in i] for i in self.value] Further, when you say 'j is not int("0")', do you actually mean that a is not in integer with the value 0? Assuming you do then what you need is v = [[j for j in i if not j] for i in self.value] or, more pedantically v = [[j for j in i if j==0] for i in self.value] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From s0suk3 at gmail.com Fri Jan 2 21:15:57 2009 From: s0suk3 at gmail.com (s0suk3 at gmail.com) Date: Fri, 2 Jan 2009 18:15:57 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: On Jan 2, 7:20?pm, Ben Finney wrote: > vk writes: > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-) > > > haha, please forgive me. > > I'll try and think of some more creative names. > > They don't need to be creative; they merely need to conform with the > naming scheme as laid out in the PEP. If it's something to be included in the standard library, I agree (just for consistency, not because using_underscores is better). But for user code, I prefer mixedCase. +1 for mixedCase! Sebastian From rt8396 at gmail.com Fri Jan 2 21:20:52 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 18:20:52 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> <20090103015725.086f7658@usenot.de> Message-ID: On Jan 2, 6:57?pm, Andreas Waldenburger wrote: [snip] > You even assumed that distinction in your example: > > > >>> 'hello world".title() [snip] sorry, here is TitleCase.py_b2 py> 'hello world'.title().replace(' ', '') From aleksandr.goretoy at gmail.com Fri Jan 2 21:38:54 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:38:54 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing this I get an unwanted list of None how do I make it disappear or not return this list. Would I have to be modifying it in place for this to happen? Wouldn't modifying it in place potentially overwrite some other values? I just don't want it to return [[None], [None, None], [None, None], [None]] You guys rock, thanks for helping me learn python. On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: > alex goretoy wrote: > > Hello All, > > > > I'm doing this in my code > > > > [[v.append(j) for j in i] for i in self.value] > > > > if works and all, but I need to add a if statement in the mix. Can't > > seem to remember the syntax to do so and everything I've tried seems to > > fail. How do I add a check to see if j is not int("0") then append to v > > list? Thank you in advance. -A > > Who, tiger. It "works" for a value of "works" that involves creating two > lists. One is the one you want, referenced by v, and the other is the > value if the list comprehension, which will be a list full of lists of > all the None values returned by those append() calls. But I presume you > are throwing that second list away ... > > See, a list comprehension is intended to create a list. So what you > should have used (assuming v was the empty list before you started) was > > v = [[j for j in i] for i in self.value] > > Further, when you say 'j is not int("0")', do you actually mean that a > is not in integer with the value 0? Assuming you do then what you need is > > v = [[j for j in i if not j] for i in self.value] > > or, more pedantically > > v = [[j for j in i if j==0] for i in self.value] > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:43:46 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:43:46 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: rather, how do I suppress the output of the list with all None in it? >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] >>> v=[] >>> [[v.append(j)for j in i if j != "0"] for i in l] [[None], [None], [None], []] >>> v ['39', '32', '1'] >>> On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > > the value is actually stored as a string so I would need to check if it is > "0". I do have one more question about list comprehension though. After > doing this I get an unwanted list of None how do I make it disappear or not > return this list. Would I have to be modifying it in place for this to > happen? Wouldn't modifying it in place potentially overwrite some other > values? I just don't want it to return [[None], [None, None], [None, None], > [None]] > > You guys rock, thanks for helping me learn python. > > > On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: > >> alex goretoy wrote: >> > Hello All, >> > >> > I'm doing this in my code >> > >> > [[v.append(j) for j in i] for i in self.value] >> > >> > if works and all, but I need to add a if statement in the mix. Can't >> > seem to remember the syntax to do so and everything I've tried seems to >> > fail. How do I add a check to see if j is not int("0") then append to v >> > list? Thank you in advance. -A >> >> Who, tiger. It "works" for a value of "works" that involves creating two >> lists. One is the one you want, referenced by v, and the other is the >> value if the list comprehension, which will be a list full of lists of >> all the None values returned by those append() calls. But I presume you >> are throwing that second list away ... >> >> See, a list comprehension is intended to create a list. So what you >> should have used (assuming v was the empty list before you started) was >> >> v = [[j for j in i] for i in self.value] >> >> Further, when you say 'j is not int("0")', do you actually mean that a >> is not in integer with the value 0? Assuming you do then what you need is >> >> v = [[j for j in i if not j] for i in self.value] >> >> or, more pedantically >> >> v = [[j for j in i if j==0] for i in self.value] >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:47:42 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:47:42 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: v should have ['3','4','1'] sorry if I made it confusing. On Sat, Jan 3, 2009 at 2:43 AM, alex goretoy wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > [[None], [None], [None], []] > >>> v > ['39', '32', '1'] > > >>> > > On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > >> Thank you Steve and MRAB, >> >> This is what I was looking for: >> >> [[v.append(j) for j in i if j != 0] for i in self.value] >> >> the value is actually stored as a string so I would need to check if it is >> "0". I do have one more question about list comprehension though. After >> doing this I get an unwanted list of None how do I make it disappear or not >> return this list. Would I have to be modifying it in place for this to >> happen? Wouldn't modifying it in place potentially overwrite some other >> values? I just don't want it to return [[None], [None, None], [None, None], >> [None]] >> >> You guys rock, thanks for helping me learn python. >> >> >> On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: >> >>> alex goretoy wrote: >>> > Hello All, >>> > >>> > I'm doing this in my code >>> > >>> > [[v.append(j) for j in i] for i in self.value] >>> > >>> > if works and all, but I need to add a if statement in the mix. Can't >>> > seem to remember the syntax to do so and everything I've tried seems to >>> > fail. How do I add a check to see if j is not int("0") then append to v >>> > list? Thank you in advance. -A >>> >>> Who, tiger. It "works" for a value of "works" that involves creating two >>> lists. One is the one you want, referenced by v, and the other is the >>> value if the list comprehension, which will be a list full of lists of >>> all the None values returned by those append() calls. But I presume you >>> are throwing that second list away ... >>> >>> See, a list comprehension is intended to create a list. So what you >>> should have used (assuming v was the empty list before you started) was >>> >>> v = [[j for j in i] for i in self.value] >>> >>> Further, when you say 'j is not int("0")', do you actually mean that a >>> is not in integer with the value 0? Assuming you do then what you need is >>> >>> v = [[j for j in i if not j] for i in self.value] >>> >>> or, more pedantically >>> >>> v = [[j for j in i if j==0] for i in self.value] >>> >>> regards >>> Steve >>> -- >>> Steve Holden +1 571 484 6266 +1 800 494 3119 >>> Holden Web LLC http://www.holdenweb.com/ >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? >> ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? >> > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 21:47:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 02:47:44 GMT Subject: list iteration if statement References: Message-ID: <016ec8b9$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 01:52:04 +0000, alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, Replacing "self.value" with a list of lists of ints: >>> list_of_lists = [[1, 2, 3], [2, 4, 6]] >>> v = [] >>> output = [[v.append(j) for j in sublist] for sublist in list_of_lists] >>> v [1, 2, 3, 2, 4, 6] >>> output [[None, None, None], [None, None, None]] So you create two lists, one is a copy of self.value which has been flattened, and the other is a nested list of nothing but None. What a waste of effort if your input is large. Why not just do the obvious for loop? v = [] for L in list_of_lists: for item in L: v.append(item) > but I need to add a if statement in the mix. Using a for loop, it should be obvious: v = [] for L in list_of_lists: for item in L: if item != 0: v.append(item) > Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. If you *insist* on doing it the wrong way, [[v.append(j) for j in i if j != 0] for i in self.value] > How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A Is there some significance of you saying int("0") instead of 0? -- Steven. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 21:47:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 02:47:57 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <016ec8c6$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 21:02:19 -0500, Steve Holden wrote: > Ben Finney wrote: >> vk writes: >> >>>> If there were, I would expect it to conform with PEP 8 (get those >>>> ugly camelCase names outta there :-) >>> haha, please forgive me. >>> I'll try and think of some more creative names. >> >> They don't need to be creative; they merely need to conform with the >> naming scheme as laid out in the PEP. >> > They don't *need* to do that. They do if you want it accepted into the standard library, which was the hope. Not *my* hope, you understand, but that of the person who suggested it :) -- Steven From google at mrabarnett.plus.com Fri Jan 2 22:12:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 03:12:38 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: <495ED7A6.4090205@mrabarnett.plus.com> alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > > the value is actually stored as a string so I would need to check if it > is "0". I do have one more question about list comprehension though. > After doing this I get an unwanted list of None how do I make it > disappear or not return this list. Would I have to be modifying it in > place for this to happen? Wouldn't modifying it in place potentially > overwrite some other values? I just don't want it to return [[None], > [None, None], [None, None], [None]] > > You guys rock, thanks for helping me learn python. > No, it's Python that rocks. ;-) [snip] From rt8396 at gmail.com Fri Jan 2 22:23:00 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 19:23:00 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016eba68$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 2, 7:46?pm, Steven D'Aprano wrote: ...incessant rambling about a news reader , 101 excuses for butting into a thread [snip] Throw your newsreader in the garbage and use Google groups, less headache, more filling! No need to worry about "hidden headers" And you may even get a star or 2 :) > If people are ignoring a thread, they won't even see your post even though you have changed the subject line. Yea NO $#Y, that makes a lot of sense, if i am ignoring something i course i will not see it! OK, Steven so you did not go off topic you simply high-jacked this thread. I get it now :) From mensanator at aol.com Fri Jan 2 22:23:17 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 2 Jan 2009 19:23:17 -0800 (PST) Subject: list iteration if statement References: Message-ID: <65f824f9-4f9d-4888-993c-79685d2dea5d@o40g2000prn.googlegroups.com> On Jan 2, 8:43?pm, "alex goretoy" wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > > [[None], [None], [None], []] > > >>> v > ['39', '32', '1'] > Assign it to something. >>> ignore_me = [[v.append(j)for j in i if j != "0"] for i in l] >>> v ['3', '4', '1'] From Russ.Paielli at gmail.com Fri Jan 2 22:28:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 2 Jan 2009 19:28:15 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <9730b858-421f-4214-acb9-3c359c257339@s9g2000prg.googlegroups.com> On Jan 2, 6:15?pm, s0s... at gmail.com wrote: > On Jan 2, 7:20?pm, Ben Finney > wrote: > > > vk writes: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > > ugly camelCase names outta there :-) > > > > haha, please forgive me. > > > I'll try and think of some more creative names. > > > They don't need to be creative; they merely need to conform with the > > naming scheme as laid out in the PEP. > > If it's something to be included in the standard library, I agree > (just for consistency, not because using_underscores is better). > > But for user code, I prefer mixedCase. > > +1 for mixedCase! > > Sebastian I agree. I find underscores in variable names to be both ugly and harder to read. At first glance, the underscores are easy to miss. From steve at holdenweb.com Fri Jan 2 23:04:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 23:04:27 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > No, it wasn't. You should *not* be modifying v in the list comprehension! > the value is actually stored as a string so I would need to check if it > is "0". I do have one more question about list comprehension though. If the value is stored as a string them you should be testing for "0", not 0. > After doing this I get an unwanted list of None how do I make it > disappear or not return this list. Would I have to be modifying it in > place for this to happen? Wouldn't modifying it in place potentially > overwrite some other values? I just don't want it to return [[None], > [None, None], [None, None], [None]] > If you just want to append all those lists to v then you should just say v += [[j for j in i if j != "0"] for i in self.value] You are getting the None values because the append method returns None. regards Steve > You guys rock, thanks for helping me learn python. > > On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden > wrote: > > alex goretoy wrote: > > Hello All, > > > > I'm doing this in my code > > > > [[v.append(j) for j in i] for i in self.value] > > > > if works and all, but I need to add a if statement in the mix. Can't > > seem to remember the syntax to do so and everything I've tried > seems to > > fail. How do I add a check to see if j is not int("0") then append > to v > > list? Thank you in advance. -A > > Who, tiger. It "works" for a value of "works" that involves creating two > lists. One is the one you want, referenced by v, and the other is the > value if the list comprehension, which will be a list full of lists of > all the None values returned by those append() calls. But I presume you > are throwing that second list away ... > > See, a list comprehension is intended to create a list. So what you > should have used (assuming v was the empty list before you started) was > > v = [[j for j in i] for i in self.value] > > Further, when you say 'j is not int("0")', do you actually mean that a > is not in integer with the value 0? Assuming you do then what you > need is > > v = [[j for j in i if not j] for i in self.value] > > or, more pedantically > > v = [[j for j in i if j==0] for i in self.value] > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 23:07:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 23:07:36 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > v should have ['3','4','1'] sorry if I made it confusing. > [...] Aah, I see I was giving you incorrect advice. I now realise that you want to flatten the lists as well. Don't try to do this with a list comprehension. It won't work without creating an unnecessary list of lists of None. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Fri Jan 2 23:55:12 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Fri, 2 Jan 2009 20:55:12 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: On Jan 3, 2:38?am, mr wrote: > As has been noted, the best is to fix the input to be regular-3- > tuples. For the fun of it, here's another variation of a solution: > > tuples = [(1, 2), (3, 4, 5), (6, 7)] > > def triple_or_pair(seq): > ? ? u = None > ? ? try: > ? ? ? ? k, u, v = seq > ? ? except ValueError: > ? ? ? ? k, v = seq > ? ? return k, u, v > > for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: > ? ? print k, u, v It is a code to post some data to HTML server. Even though usually the POST values are of type(name, value), if file transfer is involved, then POST values change to (name, filename, value). My view was that since filename is a rare occurance and doesnt make sense in a usual POST, I had not kept it as a full 3 tuple. Since so many programmers (that too much more capable than me) are suggesting that it is code smell, I am reviewing my decision. From vminch at gmail.com Sat Jan 3 00:05:28 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 21:05:28 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <9730b858-421f-4214-acb9-3c359c257339@s9g2000prg.googlegroups.com> Message-ID: <2cf9d91e-99ee-45de-87b3-9c185ffd6c7b@f40g2000pri.googlegroups.com> > etc etc ... IOW consider not biting off more than you can chew. It's possible that I am, but where's the fun without the risk? Good thinking in your post though! I will add "get_date" at some point, and I've modified "get_numeric" already. All-right, the moment you've all been waiting for: --------------------------------------------------------------------- http://docs.google.com/View?docid=dgsp7w2t_2gwf447g8 --------------------------------------------------------------------- Provides: 1) user_io.user_io -- get_text(msg) -- filter_get(msg, valid_chars) -- get_numeric(msg) -- bully_numeric(msg) 2) user_io.progress_bar -- ping() -- stop() Read the doc-strings for details. I know it isn't perfect, so just yell at me on this thread if you don't like something and I'll try to fix it. Actually, I'd rather you fix it yourself and THEN yell at me to update the module. have fun! From vminch at gmail.com Sat Jan 3 00:17:37 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 21:17:37 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Message-ID: What do you mean by 'fail'? you have; :: self.codes = {} so :: try: :: return eval(self.codes[expr], self.globals, self.locals) will always return an exception the first time (if this is what you're referring to). From aleksandr.goretoy at gmail.com Sat Jan 3 00:18:28 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 05:18:28 +0000 Subject: Is there a better algorithm? In-Reply-To: References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: I personally like this solution the best. Thanks mr. tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u, v for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: print k, u, v On Sat, Jan 3, 2009 at 4:55 AM, Kottiyath wrote: > On Jan 3, 2:38 am, mr wrote: > > As has been noted, the best is to fix the input to be regular-3- > > tuples. For the fun of it, here's another variation of a solution: > > > > tuples = [(1, 2), (3, 4, 5), (6, 7)] > > > > def triple_or_pair(seq): > > u = None > > try: > > k, u, v = seq > > except ValueError: > > k, v = seq > > return k, u, v > > > > for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: > > print k, u, v > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 01:16:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 06:16:39 GMT Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Message-ID: <016ef9b0$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 17:29:29 -0800, mario wrote: > Hi, > > below is the essence of a an expression evaluator, by means of a getitem > lookup. The expression codes are compiled and cached -- the lookup is > actually recursive, and the first time around it will always fail. > > import sys > class GetItemEval(object): > > def __init__(self): > self.globals = globals() # some dict (always the same) > self.locals = {} # some other dict (may be different between > evaluations) > self.codes = {} # compiled code expressions cache > > def __getitem__(self, expr): > try: > return eval(self.codes[expr], self.globals, self.locals) I was about to make a comment about this being a security hole, but I see from here http://evoque.gizmojo.org/usage/restricted/ that you are aware of at least some of the issues. I must say though, your choice of builtins to prohibit seems rather arbitrary. What is dangerous about (e.g.) id() and isinstance()? > except: > # KeyError, NameError, AttributeError, SyntaxError, > # ValueError, TypeError, IOError If you want to capture seven exceptions, then capture seven exceptions, not any exception. You should write: except (KeyError, NameError, ..., IOError): instead of a bare except clause. That will capture exceptions that represent bugs in your code as well as exceptions that should propbably be allowed to propagate, such as KeyboardInterupt and SystemExit. > # Special case if a KeyError is coming from the self.codes[name] > # lookup (traceback should consist of a single frame only): > if sys.exc_info()[2].tb_next is None: > if sys.exc_info()[0] is KeyError: > self.codes[expr] = compile(expr, '', 'eval') > return self[expr] > # otherwise handle eval error in some way... That seems awfully complicated for no good reason. If you want to handle KeyError differently, then capture KeyError: try: ... except KeyError: handle_keyerror() except: (NameError, ..., IOError): handle_everythingelse() It also seems significant slower: >>> import sys >>> def catch1(): ... D = {} ... try: ... D['x'] ... except KeyError: ... pass ... >>> def catch2(): ... D = {} ... try: ... D['x'] ... except: ... if sys.exc_info()[2].tb_next is None: ... if sys.exc_info()[0] is KeyError: ... pass ... >>> from timeit import Timer >>> t1 = Timer('catch1()', 'from __main__ import catch1') >>> t2 = Timer('catch2()', 'from __main__ import catch2, sys') >>> min(t1.repeat()) 4.8421750068664551 >>> min(t2.repeat()) 6.2694659233093262 -- Steven From bignose+hates-spam at benfinney.id.au Sat Jan 3 01:50:33 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 17:50:33 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <87d4f4lw7a.fsf@benfinney.id.au> s0suk3 at gmail.com writes: > On Jan 2, 7:20?pm, Ben Finney > wrote: > > They don't need to be creative; they merely need to conform with > > the naming scheme as laid out in the PEP. > > If it's something to be included in the standard library, I agree > (just for consistency, not because using_underscores is better). > > But for user code, I prefer mixedCase. That seems superficially like an easy distinction. Indeed, PEP 8 explicitly is meant to apply only to code intended for inclusion in the Python standard library. But consider: Python libraries generally don't get into the standard library until they've had a history of widespread public use as an external library. This helps ensure many of the harder-to-find wrinkles get discovered through wide exposure and ironed out before becoming standard. Code bases, especially library interfaces, that get a lot of use across wide communities are naturally going to have a whole lot of other people's code directly using those interfaces. Interfaces that are so widely used garner a high resistance to change, especially for something as non-functional as a naming convention. Choosing the naming convention for one's code is much easier to do when its usage base is smaller than when that base is larger. Therefore the easiest time to choose when to code in conformance to PEP 8 is right at the start. The best conclusion I can come to from this? Unless you explicitly *never* intend sharing your code with *anyone*, it's best to code all your Python code in accordance with PEP 8 anyway. You then don't have to make the decision about whether this is the time to follow PEP 8 or not; just do it by default, and you avoid the needless pain on those occasions, often unforeseeable at the start, where your code later ends up widely used. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From vminch at gmail.com Sat Jan 3 02:18:08 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 23:18:08 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> Message-ID: <91201b2b-7a66-49ae-b25f-b377dbb6bad4@z6g2000pre.googlegroups.com> > Unless you explicitly *never* intend sharing your code with *anyone*, > it's best to code all your Python code in accordance with PEP 8 anyway. Well said. Let's bury the puppy already. Anyone have something to say about the userio stuff? From vminch at gmail.com Sat Jan 3 02:22:51 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 23:22:51 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <91201b2b-7a66-49ae-b25f-b377dbb6bad4@z6g2000pre.googlegroups.com> Message-ID: > Anyone have something to say about the userio stuff? (If you're going to post something about my coding style, I invite you to do something infinitely more useful: write crapToPep8.py {or is it crap_to_pep8?} to satisfy your sick fetish for consistency.) From mail at microcorp.co.za Sat Jan 3 03:40:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 3 Jan 2009 10:40:39 +0200 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> <95c3672c-105e-46b9-a241-7cb199ed45ba@r15g2000prh.googlegroups.com> Message-ID: <021201c96d83$603b1d40$0d00a8c0@hendrik> bearophile wrote: >Fuzzyman: > >> for i in l: >> u = None >> if len(i) == 2: >> k, v = i >> else: >> k, u, v = i > >That's the best solution I have seen in this thread so far (but I >suggest to improve indents and use better variable names). In >programming it's generally better to follow the KISS principle. Strange that nobody has suggested: for Tup in Lst: for item in Tup: print item, print Because if I recall correctly, all the OP was doing was printing the stuff. Gets a bit hairier if you want to return the values though. - if you replace the first print statement above with a yield and delete the second, bare print, you lose knowledge of which tuple the item belongs to. It is not trivial to do if you don't have a priori knowledge of the maximum and minimum tuple length. Seems to me it is one of those gems that is a PITA to do completely generally - basically because you don't know when you call it how many items to unpack - so you have to return a count or something, or just fall back on a two step approach - get the tuple from the list, then do something with the items in the tuple. - Hendrik From geon at post.cz Sat Jan 3 04:39:41 2009 From: geon at post.cz (Pavel Kosina) Date: Sat, 03 Jan 2009 10:39:41 +0100 Subject: patch Message-ID: <495F325D.8090204@post.cz> T?k? se to Pythonu okrajov?, p?esto to d?v?m sem. Mysl?m, ?e by se mohlo hodit i ostatn?m, kdo cht?j? zkou?et pod Windows nov? v?ci z development verze: Jak opatchovat (python?rsk?) soubor pod Windows? Co jsem ud?lal: 1/ st?hl jsem http://gnuwin32.sourceforge.net/packages/patch.htm 2/ nainstaloval pod amin, p?idal cestu do ..bin .. do PATH 3/ st?hl http://bugs.python.org/file12561/conv.diff a ulo?il do Lib/idlelib 4/ cmd: patch < conf.diff h?z? chybu: C:\prg\Python30\Lib\idlelib>patch < conv.diff patching file IOBinding.py Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Patchuje n?kdo tady pod Windows? D?ky -- geon Pavel Kosina From pavel.kosina at gmail.com Sat Jan 3 04:43:53 2009 From: pavel.kosina at gmail.com (geon) Date: Sat, 3 Jan 2009 01:43:53 -0800 (PST) Subject: patch References: Message-ID: sorry, pls forget :-( From geon at post.cz Sat Jan 3 04:48:51 2009 From: geon at post.cz (Pavel Kosina) Date: Sat, 03 Jan 2009 10:48:51 +0100 Subject: patch Message-ID: <495F3483.3040806@post.cz> sorry, pls forget ... -- geon Pavel Kosina From jobolosh at gmail.com Sat Jan 3 04:55:24 2009 From: jobolosh at gmail.com (John Boloshevich) Date: Sat, 3 Jan 2009 09:55:24 +0000 Subject: ACL in python Message-ID: Hello, does anybody know about an ACL implementation for python, which is not tied to the filesystem? I would like to use ACL on different objects not on files, so the POSIX file access solution is not the one I am looking for. I would like to be able to define ACOs, AROs, but it would be even nicer, if there would be AXO possibility as well. I have tried to find already, but I wasn't really successful. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From bj_666 at gmx.net Sat Jan 3 04:56:12 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 09:56:12 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> Message-ID: <6s8r1sF4op56U1@mid.uni-berlin.de> On Fri, 02 Jan 2009 09:00:01 -0800, r wrote: > On Jan 2, 6:45?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: >> > He was not cross posting. >> >> You don't actually know what cross-posting is, do you? >> >> You've just earned a plonking for the next month. Do try to have at >> least half a clue by February. > > Steven i got you NOW! > Everybody go and look at this thread, there Mr. Makinzie butts in and > posts an off-topic question, and Steven answers it, contributing to the > off-topicalitly of the thread. And has yet to apologize for it, or admit > his screwup, but will he preach to everyone else about making off topic > post... Pot meet Kettle; Kettle Pot! > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/ fc57c18c3cff5937?hl=en&q=recycle+bin#97254d877903bbd No you didn't "got" Steven, as unnecessary cross posting is something different than answering a question that should have been a new thread start. Oh, and: *plonk* for your childish annoying behaviour? Ciao, Marc 'BlackJack' Rintsch From bj_666 at gmx.net Sat Jan 3 05:15:51 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 10:15:51 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: <6s8s6nF4op56U2@mid.uni-berlin.de> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that its > assignment model is BIZARRE, as in it's conceptually different from > virtually all other languages substantially taught in undergraduate > computer science programs. What's the difference between Python and Java or C# here!? Or are they also "BIZARRE"!? > And for that matter, it's pretty unintuitive generally. Names and objects are quite "natural" IMHO. There are many real world objects which we attach one or more names to, or refer to in sequences like "please give me the third book on that shelve" (``shelve[2]``). > That is, in what I'll call "normal" computer languages, a variable name > is thought of as the address of a bin where some data is stored, and the > name is inexorably tied to that bin. You just call that "normal" or "intuitive" because that's what you learned first. > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, where > the bin is a Python object which contains specific data at the time of > assignment. A second assignment of that name doesn't change what's in > the original bin; it actually (probably) first creates a new bin, then > removes the name from the original bin and assigns it to the new one. > Intuitively, it's a bit like saying your kitchen table is no longer a > kitchen table, and now the thing where you wash your dishes is a kitchen > table. It doesn't really make a lot of sense (whether or not it's so > for good reason), and it makes describing the assignment model > necessarily convoluted, whereas the "named bins" model from the majority > of other languages people are likely to have been exposed to is simple > and sensible. I think the "bin model" is more complex because you don't just have a name and an object but always that indirection of the "bin". Ciao, Marc 'BlackJack' Rintsch From mario.ruggier at gmail.com Sat Jan 3 07:14:14 2009 From: mario.ruggier at gmail.com (mario) Date: Sat, 3 Jan 2009 04:14:14 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> Message-ID: <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> On Jan 3, 7:16?am, Steven D'Aprano wrote: > I was about to make a comment about this being a security hole, Strange that you say this, as you are also implying that *all* the widely-used templating systems for python are security holes... Well, you would be right to say that of course ;-) Infact, evoque is really one of the few (or even the only one?) that was conceived from the start to support restricted evaluation. > but I see from here > > http://evoque.gizmojo.org/usage/restricted/ > > that you are aware of at least some of the issues. > > I must say though, your choice of builtins to prohibit seems rather > arbitrary. What is dangerous about (e.g.) id() and isinstance()? Preventive, probably. I also feel that temlates should have any business with info such as the memory addressed returnred by id(). For isinstance, becuase it is somewhat related to __subclasses__ that is known to be insecure. Incidentally, I updated the page you point to clarify what is going on. I also added a link to Brett Cannon's inspiration paper on the topic of securing the python interpreter... > > ? ? except: > > ? ? ? ? # KeyError, NameError, AttributeError, SyntaxError, > > ? ? ? ? # ValueError, TypeError, IOError > > If you want to capture seven exceptions, then capture seven exceptions, > not any exception. Absolutely not. I want to catch ALL evaluation exceptions... it would actually *be* a secuity hole to allow any exception to bubble. hey will however be handled appropriately as per the application policy/ config/deployment. > You should write: > > ? ? except (KeyError, NameError, ..., IOError): > > instead of a bare except clause. That will capture exceptions that > represent bugs in your code as well as exceptions that should propbably > be allowed to propagate, such as KeyboardInterupt and SystemExit. Again, no. Template presentational logic has no business issuing SystemExits or so. And, of course, there are no bugs in my code ;-) > > ? ? ? ? # Special case if a KeyError is coming from the self.codes[name] > > ? ? ? ? # lookup (traceback should consist of a single frame only): > > ? ? ? ? if sys.exc_info()[2].tb_next is None: > > ? ? ? ? ? ? if sys.exc_info()[0] is KeyError: > > ? ? ? ? ? ? ? ? self.codes[expr] = compile(expr, '', 'eval') > > ? ? ? ? ? ? ? ? ? ? return self[expr] > That seems awfully complicated for no good reason. Yes, you are probably right. I wanted to be precise in that if the KeyError originates strictly from the codes lookup and not from the actual eval of the expr itself -- in which case the expr should be compiled and added to codes (yes, this is the "first-time failure" I referred to in the first message). I tested the performance of your 2 variations in context, and there seems to be no noticeable performance gain (something like less than 1% gain). But note the two variations as you code them do not quite do exactly the same test. I have adjusted to use this code now: def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # We want to catch **all** evaluation errors! # KeyError, NameError, AttributeError, SyntaxError, V # alueError, TypeError, IOError, ... # # Special case: # if KeyError is coming from self.codes[expr] lookup, # then we add the compiledentry and try again: if not name in self.codes: self.codes[expr] = compile(name, '', 'eval') return self[expr] # handle any other error... This retains the correctness of the check, and has the same marginal perf improvement (that is basically negligible, but at least it is not slower) and has teh advantage that the code is clearer. Thanks for the remarks! mario > -- > Steven From tino at wildenhain.de Sat Jan 3 07:18:29 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 03 Jan 2009 13:18:29 +0100 Subject: ACL in python In-Reply-To: References: Message-ID: <495F5795.2090303@wildenhain.de> John Boloshevich wrote: > Hello, > > does anybody know about an ACL implementation for python, which is not > tied to the filesystem? I would like to use ACL on different objects not > on files, so the POSIX file access solution is not the one I am looking for. You mean something like the restricted environment you find within zope for all the TTW-stuff? Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mario.ruggier at gmail.com Sat Jan 3 07:19:42 2009 From: mario.ruggier at gmail.com (mario) Date: Sat, 3 Jan 2009 04:19:42 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: correction: the code posted in previous message should have been: def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # We want to catch **all** evaluation errors! # KeyError, NameError, AttributeError, SyntaxError, V # alueError, TypeError, IOError, ... # # Special case: # if KeyError is coming from self.codes[expr] lookup, # then we add the compiledentry and try again: if not expr in self.codes: self.codes[expr] = compile(expr, '', 'eval') return self[expr] # handle any other error... From nobody at dizum.com Sat Jan 3 08:30:02 2009 From: nobody at dizum.com (Nomen Nescio) Date: Sat, 3 Jan 2009 14:30:02 +0100 (CET) Subject: python is great Message-ID: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> python is great. From nick at craig-wood.com Sat Jan 3 08:31:12 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 03 Jan 2009 07:31:12 -0600 Subject: multiprocessing vs thread performance References: Message-ID: mk wrote: > After reading http://www.python.org/dev/peps/pep-0371/ I was under > impression that performance of multiprocessing package is similar to > that of thread / threading. However, to familiarize myself with both > packages I wrote my own test of spawning and returning 100,000 empty > threads or processes (while maintaining at most 100 processes / threads > active at any one time), respectively. > > The results I got are very different from the benchmark quoted in PEP > 371. On twin Xeon machine the threaded version executed in 5.54 secs, > while multiprocessing version took over 222 secs to complete! > > Am I doing smth wrong in code below? Yes! The problem with your code is that you never start more than one process at once in the multiprocessing example. Just check ps when it is running and you will see. My conjecture is that this is due to the way fork() works under unix. I think that when the parent forks it yields the CPU to the child. Because you are giving the child effectively no work to do it returns immediately, re-awakening the parent, thus serialising your jobs. If you give the children some work to do you'll see a quite different result. I gave each child time.sleep(1) to do and cut down the total number to 10,000. $ ./test_multiprocessing.py == Process 1000 working == == Process 2000 working == == Process 3000 working == == Process 4000 working == == Process 5000 working == == Process 6000 working == == Process 7000 working == == Process 8000 working == == Process 9000 working == == Process 10000 working == === Main thread waiting for all processes to finish === Total time: 101.382129192 $ ./test_threading.py == Thread 1000 working == == Thread 2000 working == == Thread 3000 working == == Thread 4000 working == == Thread 5000 working == == Thread 6000 working == == Thread 7000 working == == Thread 8000 working == == Thread 9000 working == == Thread 10000 working == Total time: 100.659118176 So almost identical results and as expected - we ran 10,000 sleep(1)s in 100 seconds so we must have been running 100 simultaneously. If you replace the "time.sleep(1)" with "for _ in xrange(1000000): pass" you get this much more interesting answer on my dual core linux laptop, showing nicely the effect of the contention on the python global interpreter lock and how multiprocessing avoids it. $ ./test_multiprocessing.py == Process 1000 working == == Process 2000 working == == Process 3000 working == == Process 4000 working == == Process 5000 working == == Process 6000 working == == Process 7000 working == == Process 8000 working == == Process 9000 working == == Process 10000 working == === Main thread waiting for all processes to finish === Total time: 266.808327913 $ ./test_threading.py == Thread 1000 working == == Thread 2000 working == == Thread 3000 working == == Thread 4000 working == == Thread 5000 working == == Thread 6000 working == == Thread 7000 working == == Thread 8000 working == == Thread 9000 working == == Thread 10000 working == Total time: 834.81882 -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mdw at distorted.org.uk Sat Jan 3 10:00:22 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 3 Jan 2009 15:00:22 +0000 (UTC) Subject: greenlets and how they can be used References: Message-ID: James Mills wrote: > The "greenlet" from http://codespeak.net/py/dist/greenlet.html > is a rather interesting way of handling flow of control. Ahh, yes. It's actually a rather old idea, but too rarely used. > What can "greenlet"'s be used for ? What use-cases have you guys used > them for (if any) ? I've one project in which I use coroutines (either greenlets or some coroutines I concocted out of Python's built-in threading) extensively. The system consists of a server which speaks a text-based protocol (written in C), a graphical monitor program, and a number of ancillary services which are both clients of the server, and augment it by providing additional commands. The monitor and the services are all in Python, and make extensive use of coroutines. One reason for this is that some of the server's commands can take a long time, so it's useful for the programs to be able to do other things while they wait for replies. Full-on threading would be possible, but (a) in fact I make a /lot/ of coroutines, and (b) with coroutines I don't have to think anywhere near as hard about synchronization. You can browse about here, if you like: http://git.distorted.org.uk/gitweb/~mdw/tripe?a=tree;h=python The main Python module is in py/; the services are in svc/, and the graphical monitor is in mon/. > Can they be used in place of threads with much the same effect - but > more lightweight ? More lightweight, and much easier to reason about. They also confuse other libraries less. -- [mdw] From bdesth.quelquechose at free.quelquepart.fr Sat Jan 3 10:08:54 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jan 2009 16:08:54 +0100 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: <495f8d33$0$741$426a34cc@news.free.fr> Derek Martin a ?crit : > On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: >>> Python seems rather weird, and I think from the frequency >>> with which these discussions occur on this list, clearly it *IS* >>> difficult for a neophyte Python programmer to understand the >>> assignment model. >> Took me about half an hour to grasp, not even being "CS grad" (nor >> whathever "grad" FWIW). By that time, I had a couple monthes working >> experience with VB, and had learned (but never seriously used) bits of >> C, C++, Java and Pascal. > > It took me about a half a second to grasp the "named bins" concept -- Oh yes ? With all it's implications ? Fine, you're way smarter than I'm - or, as it seems, you were much more experimented and CS-litterate that I was by that time. But that was not the point. What I meant is that a concept that takes less than an hour to grasp for a newbie self-taught programmer with no previous exposure to the concept should by no mean be a problem for a CS graduate. From bdesth.quelquechose at free.quelquepart.fr Sat Jan 3 10:19:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jan 2009 16:19:58 +0100 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <495f8fcc$0$20340$426a34cc@news.free.fr> sprad a ?crit : > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), Actually, it's just plain object instanciation. > and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet raw_input() returns a string. If you want an int and the string is supposed to contain a legitimate string representation of an integer, then yes, passing the string to the int object constructor is the right thing to do. I'd just write it a bit diffently: bet = int(raw_input("Enter your bet")) if bet == 0: # code here or even better: def read_int(prompt, err="Sorry, '%s' is not a valid integer"): while True: answer = raw_input(prompt) try: return int(answer) except ValueError: print err % answer bet = read_int("Enter your bet") if bet == 0: # code here > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" May suggest learning about string formatting ? print "You still have $%s remaining" % money But indeed, you obviously cannot add strings with numerics nor concatenate numerics with strings. This would make no sense. > All the time, I'm going int(this) and str(that). Am I supposed to? Depends on the context. From koranthala at gmail.com Sat Jan 3 11:39:52 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 3 Jan 2009 08:39:52 -0800 (PST) Subject: Doubt on creating threads Message-ID: I was going through Python posts and this post caught my attention http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a You have missed an important point. A well designed application does neither create so many threads nor processes. The creation of a thread or forking of a process is an expensive operation. You should use a pool of threads or processes. I am creating an application and it creates ~1-2 threads every second and kill it within 10 seconds. After reading this I am worried. Is creating a thread a very costly operation? I cannot use a pool of threads because I am using an external application (twisted) to create the threads (deferToThread). From research at johnohagan.com Sat Jan 3 12:25:17 2009 From: research at johnohagan.com (John O'Hagan) Date: Sat, 3 Jan 2009 17:25:17 +0000 Subject: why cannot assign to function call In-Reply-To: <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <200901031725.18083.research@johnohagan.com> On Tue, 30th Dec 2008, Aaron Brady wrote: >Accepting that, I'll adopt the terms John proposed, 'change' vs. >'exchange', the former when the material configuration changes, the >latter when the communication axioms change. > >b= [2, 3] >b= [3, 4] > >'b' has exchanged. (Somewhat ungrammatical.) > >b= [2, 3] >b.append( 4 ) > >'b' has changed. > >According to this, when you replace every floorboard on a porch, one >at a time, it's still the same porch-- it's changed, it's different, >and it's the same. However, if you haul off the porch and put a new >one in its place, it's not. ('porch[:]=' vs. 'porch='.) You can't >just look at the initial and final configurations of matter to >determine so. Therefore, 'id' is an informal function. This analogy describes the "ontological minefield" I was referring to in a previous post in this thread (which has expired in my mail reader, so my apologies if the threading goes awry): In what sense is a porch (or list, or string) the same if all (or even some of) its parts have been exchanged? I think the answer is something to do with the abstraction, the "container", the instance of the class. Would it be fair to say that perhaps there are no truly mutable objects, only immutable containers whose contents (also immutable objects themselves) may be exchanged? Or to pose the question another way, are objects only mutable insofar as they are composite? As you argue above, the planks are not the porch; I would add that it's your _decision_ to build (or tear down) a porch which makes it _that_ particular porch (or not). As you imply above (I think), you have to keep looking (or someone does, presumably the interpreter) to know whether an object is the same as or just equal to another (which starts to sound spookily like the role of "the observer" in phenomenology or quantum physics). Whether this means that id() is "informal" or not, I'll leave to others better informed than I. Regards, John From fakeaddress at nowhere.org Sat Jan 3 12:26:06 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 09:26:06 -0800 Subject: select.select and socket.setblocking In-Reply-To: References: Message-ID: Laszlo Nagy wrote: [...] > I have read the socket programming howto ( > http://docs.python.org/howto/sockets.html#sockets ) but it does not > explain how a blocking socket + select is different from a non blocking > socket + select. Is there any difference? There is, but it may not effect you. There are cases where a socket can select() as readable, but not be readable by the time of a following recv() or accept() call. All such cases with which I'm familiar call for a non-blocking socket. Where does this come up? Suppose that to take advantage of multi-core processors, our server runs as four processes, each with a single thread that responds to events via select(). Clients all connect to the same server port, so the socket listening on that port is shared by all four processes. A perfectly reasonable architecture (though with many more processes the simple implementation suffers the "thundering herd problem"). Two of our processors may be waiting on select() when a new connections comes in. The select() call returns in both processes, showing the socket ready for read, so both call accept() to complete the connection. The O.S. ensures that accept() [and recv()] are atomic, so one process gets the new connection; what happens in the other depends on whether we use a blocking or non-blocking socket, and clearly we want non-blocking. -- --Bryan From ashen_light at messir.net Sat Jan 3 12:31:42 2009 From: ashen_light at messir.net (Exe) Date: Sat, 03 Jan 2009 20:31:42 +0300 Subject: strange thing after call PyObject_CallMethod Message-ID: Hello everybody! I'm in trouble. This code shows that ob_refcnt increased by python if "on_recv" method throws exception. This occurs only if base C-class subclassed in python code. ====== my_old_refcnt = Py_REFCNT(self); py_result = PyObject_CallMethod(self, "on_recv", "(y#)", recvbuf, result); my_new_refcnt = Py_REFCNT(self); log_debug("refcnt before call %d", my_old_refcnt); log_debug("after call: %d\n", my_new_refcnt); ====== Output: ====== tcpconn.c: refcnt before call 1 tcpconn.c: after call: 2 ====== If PyObject_CallMethod returns success(any non-NULL value) anything okay. Tested on Python 3.1a0 (py3k:68145M, Jan 2 2009, 20:51:28). Why this happenning and who makes Py_INCREF(self)? PS garbage collector knows about this so on exit PyGC_Collect deletes instance. -- //wbr Kandalintsev Alexandre From grante at visi.com Sat Jan 3 12:38:46 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 03 Jan 2009 11:38:46 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> On 2009-01-03, Marc 'BlackJack' Rintsch wrote: > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > >> What the Python community often overlooks, when this discussion again >> rears its ugly head (as it seems to every other hour or so), is that its >> assignment model is BIZARRE, as in it's conceptually different from >> virtually all other languages substantially taught in undergraduate >> computer science programs. > > What's the difference between Python and Java or C# here!? Or scheme, or lisp, or smalltalk, or .... > Or are they also "BIZARRE"!? One presumes that Mr. Martin finds anything different from his first computer language to be BIZARRE. He should try out Prolog or something genuinely different. -- Grant From exarkun at divmod.com Sat Jan 3 12:41:35 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sat, 3 Jan 2009 12:41:35 -0500 Subject: Doubt on creating threads In-Reply-To: Message-ID: <20090103174135.20272.301262509.divmod.quotient.31149@ohm> On Sat, 3 Jan 2009 08:39:52 -0800 (PST), koranthala at gmail.com wrote: >I was going through Python posts and this post caught my attention >http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a > > > You have missed an important point. A well designed application does > neither create so many threads nor processes. The creation of a >thread > or forking of a process is an expensive operation. You should use a >pool > of threads or processes. > > >I am creating an application and it creates ~1-2 threads every second >and kill it within 10 seconds. After reading this I am worried. Is >creating a thread a very costly operation? I cannot use a pool of >threads because I am using an external application (twisted) to create >the threads (deferToThread). Actually, deferToThread is implemented in terms of a thread pool. So you're only creating a small number of threads, and then they're being re-used. I somewhat disagree with the assertion that not using a threadpool means that your application is "well designed". However, it's absolutely true that using a threadpool lowers the runtime cost of using threads compared to creating and destroying threads all the time. Jean-Paul From martin at v.loewis.de Sat Jan 3 13:00:18 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 03 Jan 2009 19:00:18 +0100 Subject: strange thing after call PyObject_CallMethod In-Reply-To: References: Message-ID: <495fa7b2$0$22840$9b622d9e@news.freenet.de> > Why this happenning and who makes Py_INCREF(self)? There are multiple possible explanations, but I think you have ruled out most of them: 1. on_recv might be returning self. So py_result would be the same as self, and hence be an additional reference. However, you said that on_recv raised an exception, so py_result should be NULL (can you confirm?) 2. there might be a reference leak in the implementation of on_recv. However, you say that it is all fine at the end, so this is unlikely 3. The implementation of on_recv stores the object inside another objects. There are too many possibilities for that to enumerate; here are some examples: def on_recv(self, buf): global foo, bar foo = self # creates global reference bar = self.on_send # creates bound method self.foo = self # creates cyclic reference foobar.append(self) # adds self into container If you are using gdb, I recommend to set a watchpoint on changes to ob_refcnt: (gdb) p &((PyObject*)self)->ob_refcnt $1 = (Py_ssize_t *) 0xa0cb5a0 (gdb) watch *(Py_ssize_t *) 0xa0cb5a0 Hardware watchpoint 2: *(ssize_t *) 168605088 (gdb) c Continuing. Hardware watchpoint 2: *(ssize_t *) 168605088 Old value = 2 New value = 1 0xb7d5f406 in list_clear (a=0xa041c74) at Objects/listobject.c:550 550 Py_XDECREF(item[i]); As you can see: this specific object was stored in a list, and the list is now being cleared. HTH, Martin From Russ.Paielli at gmail.com Sat Jan 3 13:14:14 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 3 Jan 2009 10:14:14 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> Message-ID: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> On Jan 2, 10:50?pm, Ben Finney wrote: > s0s... at gmail.com writes: > > On Jan 2, 7:20?pm, Ben Finney > > wrote: > > > They don't need to be creative; they merely need to conform with > > > the naming scheme as laid out in the PEP. > > > If it's something to be included in the standard library, I agree > > (just for consistency, not because using_underscores is better). > > > But for user code, I prefer mixedCase. > > That seems superficially like an easy distinction. Indeed, PEP 8 > explicitly is meant to apply only to code intended for inclusion in > the Python standard library. > > But consider: > > Python libraries generally don't get into the standard library until > they've had a history of widespread public use as an external library. > This helps ensure many of the harder-to-find wrinkles get discovered > through wide exposure and ironed out before becoming standard. > > Code bases, especially library interfaces, that get a lot of use > across wide communities are naturally going to have a whole lot of > other people's code directly using those interfaces. > > Interfaces that are so widely used garner a high resistance to change, > especially for something as non-functional as a naming convention. > > Choosing the naming convention for one's code is much easier to do > when its usage base is smaller than when that base is larger. > Therefore the easiest time to choose when to code in conformance to > PEP 8 is right at the start. > > The best conclusion I can come to from this? Unless you explicitly > *never* intend sharing your code with *anyone*, it's best to code all > your Python code in accordance with PEP 8 anyway. You then don't have > to make the decision about whether this is the time to follow PEP 8 or > not; just do it by default, and you avoid the needless pain on those > occasions, often unforeseeable at the start, where your code later > ends up widely used. > > -- > ?\ ? ? ? ?One of the most important things you learn from the internet | > ? `\ ? is that there is no ?them? out there. It's just an awful lot of | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??us?.? ?Douglas Adams | > Ben Finney Fair enough, but for code that is not intended for general public usage (i.e., most code) so-called camelCase is every bit as good if not better than using underscores to divide variable names. It saves a few characters, and in my opinion it's significantly easier to read. Identifiers divided by underscores always appear to me at first glance to be multiple words, and I find that very annoying. So unless you think the standard library will someday include code for air traffic management, I'll stick with camelCase, and I'll thank you for not making an issue of it. As far as I am concerned, this is one of the most important bits of advice in PEP 8: A Foolish Consistency is the Hobgoblin of Little Minds From jonas.esp at googlemail.com Sat Jan 3 13:43:01 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 10:43:01 -0800 (PST) Subject: Returning a string Message-ID: How is possible that I can print a variable, but when I use *return var* it returns an empty string http://paste.pocoo.org/show/97588/ From sajmikins at gmail.com Sat Jan 3 13:56:17 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 3 Jan 2009 10:56:17 -0800 (PST) Subject: Doubt on creating threads References: Message-ID: On Jan 3, 8:39?am, koranth... at gmail.com wrote: > I was going through Python posts and this post caught my attentionhttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > ?You have missed an important point. A well designed application does > ?neither create so many threads nor processes. The creation of a > thread > ?or forking of a process is an expensive operation. You should use a > pool > ?of threads or processes. > > > I am creating an application and it creates ~1-2 threads every second > and kill it within 10 seconds. After reading this I am worried. Is > creating a thread a very costly operation? I cannot use a pool of > threads because I am using an external application (twisted) to create > the threads (deferToThread). Generally you should only worry about this sort of thing if A) you actually notice a performance problem and B) testing indicates that it's thread creation which is causing it. Otherwise you could spend a lot of time working on something that doesn't actually affect your app's performance. ~S From deets at nospam.web.de Sat Jan 3 14:12:02 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:12:02 +0100 Subject: Returning a string In-Reply-To: References: Message-ID: <6s9rk3F4vutmU1@mid.uni-berlin.de> Kless schrieb: > How is possible that I can print a variable, but when I use *return > var* it returns an empty string > > http://paste.pocoo.org/show/97588/ I don't see anything that indicates that the returned object is the empty string. Simply because there is no code testing for that. And of course you don't show any debugging output, which doesn't help either. Diez From jonas.esp at googlemail.com Sat Jan 3 14:20:19 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:20:19 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> Message-ID: <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> On 3 ene, 19:12, "Diez B. Roggisch" wrote: > Kless schrieb: > > > How is possible that I can print a variable, but when I use *return > > var* it returns an empty string > > >http://paste.pocoo.org/show/97588/ > > I don't see anything that indicates that the returned object is the > empty string. Simply because there is no code testing for that. And of > course you don't show any debugging output, which doesn't help either. > > Diez Afghanistan AF Out[19]: u'AF' AFG Out[19]: u'AFG' 004 Out[19]: u'004' From sajmikins at gmail.com Sat Jan 3 14:40:19 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 3 Jan 2009 11:40:19 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: On Jan 3, 11:20?am, Kless wrote: > On 3 ene, 19:12, "Diez B. Roggisch" wrote: > > > Kless schrieb: > > > > How is possible that I can print a variable, but when I use *return > > > var* it returns an empty string > > > >http://paste.pocoo.org/show/97588/ > > > I don't see anything that indicates that the returned object is the > > empty string. Simply because there is no code testing for that. And of > > course you don't show any debugging output, which doesn't help either. > > > Diez > > Afghanistan > AF > Out[19]: u'AF' > AFG > Out[19]: u'AFG' > 004 > Out[19]: u'004' What? From jonas.esp at googlemail.com Sat Jan 3 14:46:10 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:46:10 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> On 3 ene, 19:40, Simon Forman wrote: > On Jan 3, 11:20?am, Kless wrote: > > > Afghanistan > > AF > > Out[19]: u'AF' > > AFG > > Out[19]: u'AFG' > > 004 > > Out[19]: u'004' > > What? That's the output got from ipython. As you can see, it prints 'Afghanistan' but it can not returns it. In change, the another strings are returned. Could it be because it isn't returning the value from the recursivecall? From deets at nospam.web.de Sat Jan 3 14:49:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:49:36 +0100 Subject: Returning a string In-Reply-To: <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: <6s9tqhF4vtr6U1@mid.uni-berlin.de> Kless schrieb: > On 3 ene, 19:12, "Diez B. Roggisch" wrote: >> Kless schrieb: >> >>> How is possible that I can print a variable, but when I use *return >>> var* it returns an empty string >>> http://paste.pocoo.org/show/97588/ >> I don't see anything that indicates that the returned object is the >> empty string. Simply because there is no code testing for that. And of >> course you don't show any debugging output, which doesn't help either. >> >> Diez > > Afghanistan > AF > Out[19]: u'AF' > AFG > Out[19]: u'AFG' > 004 > Out[19]: u'004' What is that? IPython? And I don't see no empty string here. *What* I see is the way python's interactive prompt puts out strings, like this: >>> unicode("foo") u'foo' Do you mean by any chance that you don't understand why print prints foo, but the prompt shows u"foo"? That is because the prompt invokes repr(o) to print out an object: >>> print repr(unicode("foo")) u'foo' Which means that the output includes quotes and the "u"-prefix in case of an unicode object to help the user to see what the current object looks like. Diez From deets at nospam.web.de Sat Jan 3 14:51:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:51:16 +0100 Subject: Returning a string In-Reply-To: <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> Message-ID: <6s9ttkF4vtr6U2@mid.uni-berlin.de> Kless schrieb: > On 3 ene, 19:40, Simon Forman wrote: >> On Jan 3, 11:20 am, Kless wrote: >> >>> Afghanistan >>> AF >>> Out[19]: u'AF' >>> AFG >>> Out[19]: u'AFG' >>> 004 >>> Out[19]: u'004' >> What? > > That's the output got from ipython. As you can see, it prints > 'Afghanistan' but it can not returns it. In change, the another > strings are returned. > > Could it be because it isn't returning the value from the > recursivecall? Yep, I guess that's the problem. You need to do if cell_tag: return clean_tags(cell_tag) Diez From bj_666 at gmx.net Sat Jan 3 14:51:22 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 19:51:22 GMT Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> Message-ID: <6s9ttqF4op56U3@mid.uni-berlin.de> On Sat, 03 Jan 2009 11:46:10 -0800, Kless wrote: > On 3 ene, 19:40, Simon Forman wrote: >> On Jan 3, 11:20?am, Kless wrote: >> >> > Afghanistan >> > AF >> > Out[19]: u'AF' >> > AFG >> > Out[19]: u'AFG' >> > 004 >> > Out[19]: u'004' >> >> What? > > That's the output got from ipython. As you can see, it prints > 'Afghanistan' but it can not returns it. In change, the another strings > are returned. Maybe you should show the *input* too? Ciao, Marc 'BlackJack' Rintsch From jonas.esp at googlemail.com Sat Jan 3 14:57:30 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:57:30 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> <6s9ttkF4vtr6U2@mid.uni-berlin.de> Message-ID: <97e5048e-29ba-41f9-80c0-479a6c8f2b39@r15g2000prh.googlegroups.com> On 3 ene, 19:51, "Diez B. Roggisch" wrote: > Kless schrieb: > > > > > On 3 ene, 19:40, Simon Forman wrote: > >> On Jan 3, 11:20 am, Kless wrote: > > >>> Afghanistan > >>> AF > >>> Out[19]: u'AF' > >>> AFG > >>> Out[19]: u'AFG' > >>> 004 > >>> Out[19]: u'004' > >> What? > > > That's the output got from ipython. As you can see, it prints > > 'Afghanistan' but it can not returns it. In change, the another > > strings are returned. > > > Could it be because it isn't returning the value from the > > recursivecall? > > Yep, I guess that's the problem. You need to do > > if cell_tag: > ? ? return clean_tags(cell_tag) > > Diez Thank you very much. It works now. From imageguy1206 at gmail.com Sat Jan 3 15:10:15 2009 From: imageguy1206 at gmail.com (imageguy) Date: Sat, 3 Jan 2009 12:10:15 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> Message-ID: <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> On Jan 2, 7:33?pm, John Machin wrote: > For some very strange definition of "works". You say you have 'bgr' > and want to convert it to 'rbg'. The following code converts 'bgr' to > 'rgb', which is somewhat more plausible, but not what you said you > wanted. Well that's embarrassing ... you are correct. I need to convert from 'bgr' to 'rgb' Thanks to all others for suggestions FWIW, I realized the the C.types string buffer is/was mutable so settled on this; for start in xrange(0, ctypes.sizeof(buffer), 3): if buffer[start] != buffer[start+2]: #only need to swap the bits if they are different. ie if both are white or black, no change is required. blue, red = buffer[start], buffer[start+2] buffer[start], buffer[start+2] = red, blue This was about 30-40% faster that converting to list, processing and then converting back again. Will try the array module too ... but I think I need to find a new graphic package rather that makes working with the bits easier. g. From aleksandr.goretoy at gmail.com Sat Jan 3 15:35:25 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 20:35:25 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: for each his own. Any more word on userio? On Sat, Jan 3, 2009 at 6:14 PM, Russ P. wrote: > On Jan 2, 10:50 pm, Ben Finney > > > wrote: > > s0s... at gmail.com writes: > > > On Jan 2, 7:20 pm, Ben Finney > > > > > wrote: > > > > They don't need to be creative; they merely need to conform with > > > > the naming scheme as laid out in the PEP. > > > > > If it's something to be included in the standard library, I agree > > > (just for consistency, not because using_underscores is better). > > > > > But for user code, I prefer mixedCase. > > > > That seems superficially like an easy distinction. Indeed, PEP 8 > > explicitly is meant to apply only to code intended for inclusion in > > the Python standard library. > > > > But consider: > > > > Python libraries generally don't get into the standard library until > > they've had a history of widespread public use as an external library. > > This helps ensure many of the harder-to-find wrinkles get discovered > > through wide exposure and ironed out before becoming standard. > > > > Code bases, especially library interfaces, that get a lot of use > > across wide communities are naturally going to have a whole lot of > > other people's code directly using those interfaces. > > > > Interfaces that are so widely used garner a high resistance to change, > > especially for something as non-functional as a naming convention. > > > > Choosing the naming convention for one's code is much easier to do > > when its usage base is smaller than when that base is larger. > > Therefore the easiest time to choose when to code in conformance to > > PEP 8 is right at the start. > > > > The best conclusion I can come to from this? Unless you explicitly > > *never* intend sharing your code with *anyone*, it's best to code all > > your Python code in accordance with PEP 8 anyway. You then don't have > > to make the decision about whether this is the time to follow PEP 8 or > > not; just do it by default, and you avoid the needless pain on those > > occasions, often unforeseeable at the start, where your code later > > ends up widely used. > > > > -- > > \ "One of the most important things you learn from the internet | > > `\ is that there is no 'them' out there. It's just an awful lot of | > > _o__) 'us'." ?Douglas Adams | > > Ben Finney > > Fair enough, but for code that is not intended for general public > usage (i.e., most code) so-called camelCase is every bit as good if > not better than using underscores to divide variable names. It saves a > few characters, and in my opinion it's significantly easier to read. > Identifiers divided by underscores always appear to me at first glance > to be multiple words, and I find that very annoying. > > So unless you think the standard library will someday include code for > air traffic management, I'll stick with camelCase, and I'll thank you > for not making an issue of it. > > As far as I am concerned, this is one of the most important bits of > advice in PEP 8: > > A Foolish Consistency is the Hobgoblin of Little Minds > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lipun4u at gmail.com Sat Jan 3 15:38:38 2009 From: lipun4u at gmail.com (asit) Date: Sat, 3 Jan 2009 12:38:38 -0800 (PST) Subject: ResponseNotReady exception Message-ID: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> import httplib class Server: #server class def __init__(self, host): self.host = host def fetch(self, path): http = httplib.HTTPConnection(self.host) http.putrequest("GET", path) r = http.getresponse() print str(r.status) + " : " + r.reason server = Server("www.python.org") fp=open("phpvuln.txt") x=fp.readlines(); for y in x: server.fetch("/" + y); In the above code the phpvuln.txt file contains a list of directories. Why the above code throws ResponseNotReady exception ??? From bug_hunter at messir.net Sat Jan 3 15:43:38 2009 From: bug_hunter at messir.net (Bug Hunter) Date: Sat, 03 Jan 2009 23:43:38 +0300 Subject: strange thing after call PyObject_CallMethod In-Reply-To: <495fa7b2$0$22840$9b622d9e@news.freenet.de> References: <495fa7b2$0$22840$9b622d9e@news.freenet.de> Message-ID: Thank you for so amazing debugging tutorial :). I owe you a beer. I found source of problem: then unhandled in python code exception occurs frame_dealloc() (Objects/frameobject.c:422) not called. Even if I call PyErr_Print(). But! If I call PyErr_Clear() then all okay! Docs says that both this functions clears error indicator... I hit a bug or my brains overheated? Some gdb output if you are intrested: Without exception: http://dpaste.com/104973/ With exception: http://dpaste.com/104975/ From saju.pillai at gmail.com Sat Jan 3 15:44:09 2009 From: saju.pillai at gmail.com (Saju Pillai) Date: Sat, 3 Jan 2009 20:44:09 +0000 (UTC) Subject: select.select and socket.setblocking References: Message-ID: Bryan Olson wrote: > >Where does this come up? Suppose that to take advantage of multi-core >processors, our server runs as four processes, each with a single thread >that responds to events via select(). Clients all connect to the same >server port, so the socket listening on that port is shared by all four >processes. A perfectly reasonable architecture (though with many more >processes the simple implementation suffers the "thundering herd problem"). Which is why it is common for real world servers to serialize the select()/accept() code - usually via a file lock or a semaphore. -srp -- http://saju.net.in > >Two of our processors may be waiting on select() when a new connections >comes in. The select() call returns in both processes, showing the >socket ready for read, so both call accept() to complete the connection. > The O.S. ensures that accept() [and recv()] are atomic, so one process >gets the new connection; what happens in the other depends on whether we >use a blocking or non-blocking socket, and clearly we want non-blocking. > > >-- >--Bryan From vminch at gmail.com Sat Jan 3 15:48:38 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 12:48:38 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <5827781d-a583-499b-840e-a5face83328e@q26g2000prq.googlegroups.com> > Any more word on userio? None yet, I'm afraid. Should've started a different thread for it - but it's stuck here (in obscurity) forever xd. From enleverlesX.XmcX at XmclaveauX.com Sat Jan 3 15:50:30 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sat, 3 Jan 2009 21:50:30 +0100 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <495fd1f5$0$18383$ba4acef3@news.orange.fr> > python is great. No. Python is VERY GREAT !!!!!!! From vminch at gmail.com Sat Jan 3 15:54:41 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 12:54:41 -0800 (PST) Subject: ResponseNotReady exception References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <0f833b10-643f-4ae2-95de-9fd76aa8f270@d36g2000prf.googlegroups.com> http://www.python.org/phpvuln.txt Error 404: File Not Found The URL you requested was not found on this server. From clp at rebertia.com Sat Jan 3 15:59:37 2009 From: clp at rebertia.com (Chris Rebert) Date: Sat, 3 Jan 2009 12:59:37 -0800 Subject: ResponseNotReady exception In-Reply-To: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <47c890dc0901031259u8a6c029ie848f23795a18216@mail.gmail.com> On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > import httplib > > class Server: > #server class > def __init__(self, host): > self.host = host > def fetch(self, path): > http = httplib.HTTPConnection(self.host) > http.putrequest("GET", path) According to the docs, if you use .putrequest(), you have to also then call .putheader() [as many times as necessary], .endheaders(), and .send(), in that order. I'd advise just changing .putrequest() to .request() instead. And you should also read the fine docs yourself: http://docs.python.org/library/httplib.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From vminch at gmail.com Sat Jan 3 16:03:33 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 13:03:33 -0800 (PST) Subject: Port of python stdlib to other languages. Message-ID: Have there been ports of the Python standard library to other languages? I would imagine using pickle, urllib, and sys in C (with pythonic naming conventions) would be easier than using other libraries to do the same thing. From deets at nospam.web.de Sat Jan 3 16:08:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 22:08:15 +0100 Subject: Port of python stdlib to other languages. In-Reply-To: References: Message-ID: <6sa2dvF4uc5uU1@mid.uni-berlin.de> vk schrieb: > Have there been ports of the Python standard library to other > languages? > > I would imagine using pickle, urllib, and sys in C (with pythonic > naming conventions) would be easier than using other libraries to do > the same thing. AFAIK not. You could try elmer (found on SF) to expose these as C-DLL. However, I doubt this will be widely adopted - to much hassle, especially for OO-style interfaces. Those aren't properly exposable. What do you need C for anyway? Or, to put it the other way round - why not expose whatever you need in C as python extension, and write your app in Python? Diez From goldnery at gmail.com Sat Jan 3 16:10:47 2009 From: goldnery at gmail.com (Gandalf) Date: Sat, 3 Jan 2009 13:10:47 -0800 (PST) Subject: win32gui Message-ID: <8bf17a89-11bc-4c89-8ebc-db46fccefaa2@o4g2000pra.googlegroups.com> Hi, I'm trying to capture the text word under the user cursor, so I was searching the win32 lib for functions I can use. i used this to fined the controller under the cursor win32gui.WindowFromPoint(win32gui.GetCursorPos()) to get the controller, but then when I try to read the text with this GetWindowText function it most of the time doesn't work, all the "getline" methon like the following didn't worked in most of the time too win32gui.SendMessage(hwnd, win32con.EM_GETLINE, line, linetext) I found this GetCharFromPosition in a VB forum which sound promising but unfortunately it's not part of the win32gui for python so now i'm looking for a reliable way to rich text from a controller or position if you know a function who may do it or a better way please tell me/ thank you and have a nice day From lipun4u at gmail.com Sat Jan 3 16:14:45 2009 From: lipun4u at gmail.com (asit) Date: Sat, 3 Jan 2009 13:14:45 -0800 (PST) Subject: ResponseNotReady exception References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <764fc7a9-fa2f-44e0-ab97-73c13d94f7a7@40g2000prx.googlegroups.com> On Jan 4, 1:59?am, "Chris Rebert" wrote: > On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > > import httplib > > > class Server: > > ? ?#server class > > ? ?def __init__(self, host): > > ? ? ? ?self.host = host > > ? ?def fetch(self, path): > > ? ? ? ?http = httplib.HTTPConnection(self.host) > > ? ? ? ?http.putrequest("GET", path) > > According to the docs, if you use .putrequest(), you have to also then > call .putheader() [as many times as necessary], .endheaders(), and > .send(), in that order. I'd advise just changing .putrequest() to > .request() instead. > > And you should also read the fine docs yourself:http://docs.python.org/library/httplib.html > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanx From lkcl at lkcl.net Sat Jan 3 16:22:33 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sat, 3 Jan 2009 21:22:33 +0000 Subject: compiling python2.5 on linux under wine Message-ID: hey, has anyone investigated compiling python2.5 using winegcc, under wine? i'm presently working my way through it, just for kicks, and was wondering if anyone would like to pitch in or stare at the mess under a microscope. it's not as crazed as it sounds. cross-compiling python2.5 for win32 with mingw32 is an absolute miserable bitch of a job that goes horribly wrong when you actually try to use the minimalist compiler to do any real work. so i figured that it would be easier to get python compiled using wine. i _have_ got some success - a python script and a python.exe.so (which is winegcc's friendly way of telling you you have something that stands a chance of working) as well as a libpython25.dll.so. what i _don't_ yet have is an _md5.dll (or should it be _md5.lib?) i.e. the standard modules are a bit... iffy. the _winreg.o is compiled; the _md5.o is compiled; the winreg.lib is not. whoops. plus, it's necessary to enable nt_dl.c which is in PC/ _not_ in Modules/. one of the key issues that's a bit of a bitch is that python is compiled up for win32 with a hard-coded pyconfig.h which someone went to a _lot_ of trouble to create by hand instead of using autoconf. oh - and it uses visualstudio so there's not even a Makefile. ignoring that for the time-being was what allowed me to get as far as actually having a python interpreter (with no c-based modules). so there's a whole _stack_ of stuff that needs dragging kicking and screaming into the 21st century. there _is_ a reason why i want to do this. actually, there's two. firstly, i sure as shit do _not_ want to buy, download, install _or_ run visual studio. i flat-out refuse to run an MS os and visual studio runs like a dog under wine. secondly, i want a python25.lib which i can use to cross-compile modules for poor windows users _despite_ sticking to my principles and keeping my integrity as a free software developer. thirdly i'd like to cross-compile pywebkitgtk for win32 fourthly i'd like to compile and link applications to the extremely successful and well wicked MSHTML.DLL... in the _wine_ project :) not the one in windows (!) i want to experiment with DOM model manipulation - from python - similar to the OLPC HulaHop project - _but_ i want to compile or cross-compile everything from linux, not windows (see 1 above) fifthly i'd like to see COM (DCOM) working and pywin32 compiled and useable under wine, even if it means having to get a license to use dcom98 and oleauth.lib and oleauth.h etc. and all the developer files needed to link DCOM applications under windows. actually what i'd _really_ like to see is FreeDCE's DCOM work actually damn well finished, it's only been eight years since wez committed the first versions of the IDL and header files, and it's only been over fifteen years since microsoft began its world domination using COM and DCOM. ... but that's another story :) so that's ... five reasons not two. if anyone would like to collaborate on a crazed project with someone who can't count, i'm happy to make available what i've got up to so far, on github.org. l. From roy at panix.com Sat Jan 3 16:25:59 2009 From: roy at panix.com (Roy Smith) Date: Sat, 03 Jan 2009 16:25:59 -0500 Subject: select.select and socket.setblocking References: Message-ID: Bryan Olson wrote: > There are cases where a socket can select() as readable, but not be > readable by the time of a following recv() or accept() call. All such > cases with which I'm familiar call for a non-blocking socket. I used to believe that if select() said data was ready for reading, a subsequent read/recv/recvfrom() call could not block. It could return an error, but it could not block. I was confident of this until just a few months ago when reality blew up in my face. The specific incident involved a bug in the linux kernel. If you received an UDP packet with a checksum error, the select() would return when the packet arrived, *before* the checksum was checked. By the time you did the recv(), the packet had been discarded and the recv() would block. This led me on a big research quest (including some close readings of Stevens, which appeared to say that this couldn't happen). The more I read, the more I (re) discovered just how vague and poorly written the Berkeley Socket API docs are :-) The bottom line is that Bryan is correct -- regardless of what the various man pages and textbooks say, in the real world, it is possible for a read() to block after select() says the descriptor is ready. The right way to think about select() is to treat it as a heuristic which can make a polling loop more efficient, but should never be relied upon to predict the future. Neither the negative nor positive behavior is guaranteed. There's no guaranteed response time; just because select() hasn't returned yet doesn't mean a descriptor couldn't be read without blocking in another thread right now. And, just because it has returned, that doesn't mean by the time you get around to reading, there will still be anything there. From dickinsm at gmail.com Sat Jan 3 16:27:06 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 3 Jan 2009 13:27:06 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> Message-ID: <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> On Dec 31 2008, 11:02?pm, Steven D'Aprano wrote: > On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: > > On Dec 28, 7:28?am, Steven D'Aprano > cybersource.com.au> wrote: > >> Ah crap, I forgot that from_float() has been left out of the decimal > >> API. That's very annoying. > > > Agreed. ?It's maybe even annoying enough that a feature request at > > bugs.python.org might be honoured. ?(Hint, hint!) > > I can take a hint :) > > http://bugs.python.org/issue4796# Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 and Python 3.1, within 72 hours of Steven submitting the feature request. If only all issues could be resolved this quickly. :-) Mark From dickinsm at gmail.com Sat Jan 3 16:34:11 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 3 Jan 2009 13:34:11 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> Message-ID: <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> On Jan 3, 9:27?pm, Mark Dickinson wrote: > Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > and Python 3.1, within 72 hours of Steven submitting the feature > request. ?If only all issues could be resolved this quickly. :-) Rats. I left out the crucial line of that post, namely: Thank you, Steven! From sjmachin at lexicon.net Sat Jan 3 17:08:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 3 Jan 2009 14:08:21 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> Message-ID: On Jan 4, 7:10?am, imageguy wrote: > On Jan 2, 7:33?pm, John Machin wrote: > > > For some very strange definition of "works". You say you have 'bgr' > > and want to convert it to 'rbg'. The following code converts 'bgr' to > > 'rgb', which is somewhat more plausible, but not what you said you > > wanted. > > Well that's embarrassing ... you are correct. ?I need to convert from > 'bgr' to 'rgb' > > Thanks to all others for suggestions > > FWIW, I realized the the C.types string buffer is/was mutable so > settled on this; > > for start in xrange(0, ctypes.sizeof(buffer), 3): > ? ? if buffer[start] != buffer[start+2]: > ? ? ? ? ?#only need to swap the bits if they are different. ?ie if > both are white or black, no change is required. > ? ? ? ? ?blue, red = buffer[start], buffer[start+2] > ? ? ? ? ?buffer[start], buffer[start+2] = red, blue You are likely find that using buffer[start], buffer[start+2] = buffer[start+2], buffer[start] is faster. Cheers, John From gruszczy at gmail.com Sat Jan 3 17:21:03 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sat, 3 Jan 2009 23:21:03 +0100 Subject: deleting a method Message-ID: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> I am trying to delete a method from a class. It's easy to delete other attributes, but when I try: >>> class A: ... def foo(): ... pass ... >>> a = A() >>> del a.foo I get Traceback (most recent call last): File "", line 1, in AttributeError: A instance has no attribute 'foo' Why is it so and how may still delete it? -- Filip Gruszczy?ski From google at mrabarnett.plus.com Sat Jan 3 17:36:47 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 22:36:47 +0000 Subject: deleting a method In-Reply-To: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <495FE87F.6050905@mrabarnett.plus.com> Filip Gruszczy?ski wrote: > I am trying to delete a method from a class. It's easy to delete other > attributes, but when I try: > >>>> class A: > ... def foo(): > ... pass > ... >>>> a = A() >>>> del a.foo > > I get > > Traceback (most recent call last): > File "", line 1, in > AttributeError: A instance has no attribute 'foo' > > Why is it so and how may still delete it? > 'a' is an instance of class A. You're trying to delete 'foo' from the instance. From bignose+hates-spam at benfinney.id.au Sat Jan 3 17:41:45 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 04 Jan 2009 09:41:45 +1100 Subject: deleting a method References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <87zli8j9li.fsf@benfinney.id.au> MRAB writes: > Filip Gruszczy?ski wrote: > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: A instance has no attribute 'foo' > > > > Why is it so and how may still delete it? > > > 'a' is an instance of class A. You're trying to delete 'foo' from > the instance. To answer the second question: since ?foo? is an attribute of the class ?A?, you can delete the attribute from the class. >>> class A(object): ... def foo(self): ... pass ... >>> a = A() >>> 'foo' in dir(a) True >>> del A.foo >>> 'foo' in dir(a) False -- \ ?If you don't know what your program is supposed to do, you'd | `\ better not start writing it.? ?Edsger W. Dijkstra | _o__) | Ben Finney From fakeaddress at nowhere.org Sat Jan 3 17:53:12 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 14:53:12 -0800 Subject: Testing if an index is in a slice In-Reply-To: References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: ajaksu wrote: > On Jan 1, 4:12 pm, mma... at gmx.net wrote: >> I would like to check if an index is in a slice or not without >> iterating over the slice. >> >> Something like: >> >>>>> isinslice(36, slice(None, 34, -1)) >> True > > I think it'd be feasible for slices that can be mapped to ranges[1], > but slices are more flexible than that. If we add a parameter for the length of the list to which the slice is applied, then inslice() is well-defined. I thought it would easy to write, but that was hours ago when I knew less about Python slice indexing than I do now. And I thought I new a bunch from writing a virtual slice class. I'm leaning towards mmanns' idea that this should be built in. Handling all the cases is remarkably tricky. Here's a verbose version, with a little test: def inslice(i, slc, length): """ Would index i be part of slice slc of a list of len length? """ step = slc.step or 1 if step > 0: if slc.start is None: start = 0 elif slc.start >= 0: start = slc.start else: start = max(0, length + slc.start) if slc.stop is None: stop = length elif slc.stop >= 0: stop = min(length, slc.stop) else: stop = length + slc.stop return start <= i < stop and (i - start) % step == 0 else: if slc.start is None: start = length - 1 elif slc.start >= 0: start = min(length - 1, slc.start) else: start = length + slc.start if slc.stop is None: stop = -1 elif slc.stop >= 0: stop = slc.stop else: stop = max(-1, length + slc.stop) return start >= i > stop and (start - i) % (-step) == 0 # test for start in [None, 0, 1, -1, -3, 4]: for stop in [None, 0, 1, -1, 3, -5]: for step in [None, 1, -1, 2, -3]: for n in [0, 1, 2, 3, 5, 11, 16]: slc = slice(start, stop, step) s1 = [i for i in range(-3, n + 5) if inslice(i, slc, n)] s2 = sorted(range(n)[slc]) assert s1 == s2 -- --Bryan From castironpi at gmail.com Sat Jan 3 18:42:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 3 Jan 2009 15:42:47 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> On Jan 3, 11:25?am, John O'Hagan wrote: > On Tue, 30th Dec 2008, Aaron Brady wrote: > >Accepting that, I'll adopt the terms John proposed, 'change' vs. > >'exchange', the former when the material configuration changes, the > >latter when the communication axioms change. > > >b= [2, 3] > >b= [3, 4] > > >'b' has exchanged. ?(Somewhat ungrammatical.) > > >b= [2, 3] > >b.append( 4 ) > > >'b' has changed. > > >According to this, when you replace every floorboard on a porch, one > >at a time, it's still the same porch-- it's changed, it's different, > >and it's the same. ?However, if you haul off the porch and put a new > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > >just look at the initial and final configurations of matter to > >determine so. ?Therefore, 'id' is an informal function. > > This analogy describes the "ontological minefield" I was referring to in a > previous post in this thread (which has expired in my mail reader, so my > apologies if the threading goes awry): In what sense is a porch (or list, or > string) the same if all (or even some of) its parts have been exchanged? > > I think the answer is something to do with the abstraction, the "container", > the instance of the class. Would it be fair to say that perhaps there are no > truly mutable objects, only immutable containers whose contents (also > immutable objects themselves) may be exchanged? Or to pose the question > another way, are objects only mutable insofar as they are composite? > > As you argue above, the planks are not the porch; I would add that it's your > _decision_ to build (or tear down) a porch which makes it _that_ ?particular > porch (or not). > > As you imply above (I think), you have to keep looking (or someone does, > presumably the interpreter) to know whether an object is the same as or just > equal to another (which starts to sound spookily like the role of "the > observer" in phenomenology or quantum physics). Whether this means that id() > is "informal" or not, I'll leave to others better informed than I. > > Regards, > > John I think the key ingredient is that there's no such thing as side effect in math. In example, a= [0, 1, 2] a[:]= [3, 4, 5] There aren't many natural language senses in which 'a' is the same object as before. If I have a leg transplant, I'm the same person, but if you replace the entire contents of me, I'm not. But 'a' is. The porch is defined by its location, but not exclusively. Natural language identity is a cluster concept, without strict necessary and sufficient conditions. Nothing really presses our boundaries of it that much; there aren't many practical questions that lay out the facts, then ask, 'But is it the same?' You can replace the porch board-at-a-time, and it is; and you can haul it somewhere and it is. But rearrange the same boards, and it's not. Continuity of form is probably the prevalent feature, which as you state, does break down in the case of composite (piece-wise) transformations. You might get farther comparing container objects to spots on a bulletin board. The only thing that goes 'in' a container is a denoting phrase to another object (and by the way, not a description); the other also has its own spot independently on the board. It's not clear IMO that the question is so much a minefield-- a question that it's really easy to get throw (fall) off course pursuing, as it is that there's no such course. In short, there is no such thing as composite identity, only matter; or in Python, only spots on the bulletin board. > Or to pose the question > another way, are objects only mutable insofar as they are composite? No; tuples are composite. If I flip one bit in a byte somewhere, is it the same byte? From fakeaddress at nowhere.org Sat Jan 3 18:44:34 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 15:44:34 -0800 Subject: socket send help In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > greywine at gmail.com escribi?: [...] >> A simple server: >> >> from socket import * >> myHost = '' > > Try with myHost = '127.0.0.1' instead - a firewall might be blocking > your server. Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty string is that a firewall might *not* be blocking your server. The Python sockets module interprets the empty string as INADDR_ANY, which means to bind to all available adapters including the loopback, A.K.A localhost, A.K.A '127.0.0.1'. -- --Bryan From fakeaddress at nowhere.org Sat Jan 3 18:59:02 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 15:59:02 -0800 Subject: Doubt on creating threads In-Reply-To: References: Message-ID: koranthala at gmail.com wrote: > I am creating an application and it creates ~1-2 threads every second > and kill it within 10 seconds. After reading this I am worried. Is > creating a thread a very costly operation? Compared to a procedure call it's expensive, but a couple threads per second is insignificant. My out-dated Pentium 4 desktop can create and destroy a few thousand threads per second under WinXP; more under recent Linux. -- --Bryan From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:27:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:27:30 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <01700766$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 20:35:25 +0000, alex goretoy wrote: > for each his own. Please don't top-post. Please don't quote the ENTIRE body of text (PLUS doubling it by including a completely useless HTML version) just to add a trivial comment. Trim the text you are replying to. > Any more word on userio? I doubt many people care about it. Why don't you write it, put it up on the Cheeseshop, and see if anyone uses it? Just because you think it is useful doesn't mean others do, but if they do, then great. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:30:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:30:18 GMT Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> Message-ID: <0170080e$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: > On Jan 3, 9:27?pm, Mark Dickinson wrote: >> Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 >> and Python 3.1, within 72 hours of Steven submitting the feature >> request. ?If only all issues could be resolved this quickly. :-) > > Rats. I left out the crucial line of that post, namely: > > Thank you, Steven! And many thanks to both you and Raymond, firstly for doing the actual work, and secondly for your patience with my questions on the bug tracker. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:41:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:41:37 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> Message-ID: <01700ab5$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 16:19:58 +0100, Bruno Desthuilliers wrote: > But indeed, you obviously cannot add strings with numerics nor > concatenate numerics with strings. This would make no sense. The OP comes from a Perl background, which AFAIK allows you to concat numbers to strings and add strings to numbers. That's probably the (mis) feature he was hoping Python had. -- Steven From workingpad at gmail.com Sat Jan 3 21:09:26 2009 From: workingpad at gmail.com (Jack.Chu) Date: Sat, 3 Jan 2009 18:09:26 -0800 (PST) Subject: Why not Ruby? References: <0640abb6-ab69-4709-a46c-b0ee8c9f0c09@n21g2000vba.googlegroups.com> Message-ID: <6af2263b-b31b-4e64-a283-b9c6e1fcf24f@p2g2000prf.googlegroups.com> On Jan 1, 3:55?am, Roger wrote: > On Dec 31, 12:55?pm, Xah Lee wrote: > > > Just spent 3 hours looking into Ruby today. Here's my short impression > > for those interested. > > Who are you? > > In case no one tells you, you are a cocky, egotistical windbag with > opinions that border constructive but never gets there. ?Why would > anyone care what you think? ?Again, who are you? ?Xah Lee? ?And? ?I > didn't subscribe to read reviews on Ruby. ?And I'm pretty sure anyone > that bothers to subscribe to a group about programming has the > wherewithal to research a language themselves and come to their own > determiniation. > > Also, this is a Python group and not Ruby. ?I knew I should have > avoided this post and read the one about Nike Shoes from China. ?At > least those bits of trolling spam don't try to mask themselves as > something worthwhile. agree with you. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 21:11:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 02:11:56 GMT Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: <017011ce$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 04:14:14 -0800, mario wrote: > On Jan 3, 7:16?am, Steven D'Aprano cybersource.com.au> wrote: [...] >> I must say though, your choice of builtins to prohibit seems rather >> arbitrary. What is dangerous about (e.g.) id() and isinstance()? > > Preventive, probably. I also feel that temlates should have any business > with info such as the memory addressed returnred by id(). For > isinstance, becuase it is somewhat related to __subclasses__ that is > known to be insecure. It's that "probably" that worries me. In my earlier post, I was going to say "your choice of builtins to prohibit seems rather Cargo Cult-ish", but I decided that might be a bit rude, and I decided to give you the benefit of the doubt. But your answer here doesn't really give me any more confidence. What security issues do you think you are preventing by prohibiting id()? It is true that the id returned is a memory address in CPython, but that's a mere implementation detail, and may not be true in other implementations. Even if it is a memory address, so what? You can't do anything with it except treat it as an integer. I don't see how id() decreases security one iota. In the absence of even a theoretical threat, banning a function that returns an int because the int is derived from a memory address (but can't be used as one!) makes you appear to be engaging in Cargo Cult programming: following the ritual, without any understanding of what you are doing. http://catb.org/~esr/jargon/html/C/cargo-cult-programming.html Sorry to be so harsh, especially over such a tiny little thing as the id() function, but that's the impression it gives me, and I'm probably not the only one. It is true that a false positive (needlessly banning a harmless function) has less serious consequences than a false negative (failing to ban a harmful function), but it does reduce confidence that you know what you're doing. Likewise for isinstance() and issubclass(). They may be related to __subclasses__, but they don't give the caller access to __subclassess__. So what is the actual threat you are defending against? I'm not saying that there must be an actual in-the-wild demonstrated vulnerability before you prohibit a built-in, but there should be at least a plausible attack vector. > Incidentally, I updated the page you point to clarify what is going on. Speaking of that page, you have an obvious typo ("teh" instead of "the") that should be fixed: "In addition to teh above, all subclasses of BaseException..." http://evoque.gizmojo.org/usage/restricted/ > I also added a link to Brett Cannon's inspiration paper on the topic of > securing the python interpreter... > >> > ? ? except: >> > ? ? ? ? # KeyError, NameError, AttributeError, SyntaxError, # >> > ? ? ? ? ValueError, TypeError, IOError >> >> If you want to capture seven exceptions, then capture seven exceptions, >> not any exception. > > Absolutely not. I want to catch ALL evaluation exceptions... I see. It wasn't clear that this was deliberate, I read it as if there was a fixed, finite list you wanted to catch, and nothing else. You should make sure this is clearly documented in your code. -- Steven. From eric.kemp at cox.net Sat Jan 3 21:29:28 2009 From: eric.kemp at cox.net (Eric Kemp) Date: Sat, 03 Jan 2009 21:29:28 -0500 Subject: strange behavior of math.sqrt() in new 3.0 version In-Reply-To: References: Message-ID: Tim Roberts wrote: > Scott David Daniels wrote: >> I avoid using single-letter variables except where I know the types >>from the name (so I use i, j, k, l, m, n as integers, s as string, >> and w, x, y, and z I am a little looser with (but usually float or >> complex). > > It's amazing to me that Fortran continues to live on in the hearts and > minds of today's programmers. Fortran is alive and well. If you can find a Fortran 2003 compiler, you can even use classes. From guotie.9 at gmail.com Sat Jan 3 21:47:39 2009 From: guotie.9 at gmail.com (=?GB2312?B?tqO2o7WxtbE=?=) Date: Sat, 3 Jan 2009 18:47:39 -0800 (PST) Subject: =?ISO-2022-JP?B?V2hlbiBkb2VzIHB5dGhvbiAzLjEbJEIhJBsoQiAzLjIgdmVyc2lvbiBvdXQbJEIhKRsoQg==?= Message-ID: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Now? the 3.0 version is out for a time. I wonder when the python 3.1 is out, and what change is in python 3.1. Thanks. From musiccomposition at gmail.com Sat Jan 3 22:54:13 2009 From: musiccomposition at gmail.com (Benjamin) Date: Sat, 3 Jan 2009 19:54:13 -0800 (PST) Subject: =?ISO-2022-JP?B?UmU6IFdoZW4gZG9lcyBweXRob24gMy4xGyRCISQbKEIgMy4yIHZlcnNpb24gb3V0GyRCISkbKEI=?= References: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Message-ID: <786cce5a-6d55-41bf-8481-055153693004@w1g2000prk.googlegroups.com> On Jan 3, 8:47 pm, ???? wrote: > Now? the 3.0 version is out for a time. > > I wonder when the python 3.1 is out, and what change is in python 3.1. There's no schedule yet. Hopefully, one will come into being around PyCon. From greywine at gmail.com Sat Jan 3 22:58:19 2009 From: greywine at gmail.com (greywine at gmail.com) Date: Sat, 3 Jan 2009 19:58:19 -0800 (PST) Subject: simple turn-based multiplayer game via TCP server/client Message-ID: Hi everyone, I'm learning python to get a multiplayer roleplaying game up and running. I didn't see any simple examples of multiplayer games on the web so I thought I'd post mine here. I choose Rock, Paper, Scissors as a first game to experiment with as the game logic/options are easy to implement and understand. Initially, I tried to get the socketserver.TCPServer example in the Python Docs to work, but couldn't get my game variables into the handle method of the class MyTCPHandler. And I didn't know how else to do it. I ended up creating my own server & client out of simple sockets based on the simple echo server & client examples in the Python Docs. I also wanted to send chat messages OR game variables back & forth, but I couldn't figure out how to do the OR, so the basic idea in this implementation is to send the dictionary 'game' back and forth. game dict contains all the gaming variables as well as any chat messages. The program processes results depending on whether the game is starting, there's a chat message, or there's a game move. Finally, in testing, I ran the server in IDLE, but I had to load a command prompt and switch to c:\python30; then type 'python rpsmulti.py' for the client every time. Anyone know how to test server/client code strictly in IDLE? Anyway, try it out and let me know how you would improve it. John R. # NAME: rpsmulti.py # DESCRIPTION: rock, paper, scissors game multiplayer game # AUTHOR: John Robinson # DATE: 1/3/09 # VERSION: Python 3.0 # TO DO: # .server_address instead of HOST, PORT? import socket from random import choice from pickle import dumps, loads from pprint import pprint HOST, PORT = "localhost", 9999 # defined for now BUFFSIZE = 1024 # for socket.send & recv commands BACKLOG = 2 # number of clients supported by server SECONDS = 3 # seconds until socket.timeout (not implemented) # moves dict to translate 'rps' choice MOVES = {'r':'Rock', 'p':'Paper', 's':'Scissors'} # outcome dict stores result for all possible scenarios OUTCOME = {('p','r'): 'win', ('r','s'): 'win', ('s','p'): 'win', ('p','p'): 'draw', ('r','r'): 'draw', ('s','s'): 'draw', ('r','p'): 'lose', ('s','r'): 'lose', ('p','s'): 'lose'} def main_menu(game): """ initialize game dict variables & opening screen of the game """ game['total'] = 0 # total number of games played game['won'] = 0 # total games won by player game['lost'] = 0 # total games lost by player game['drew'] = 0 # total games drew by player game['move'] = '' # player's move (rps) game['message'] = '' # player's chat message game['sentmessage'] = '' # player's previous message game['start'] = True # setting up the game boolean print("\tROCK PAPER SCISSORS\n") if game['name']=='': # if returning to menu don't display the following game['name'] = get_name() print("Welcome "+game['name']+". Remember...") print("Rock smashes scissors! Paper covers Rock! Scissors cuts paper!\n") print("1. Play single player game") print("2. Start two player game") print("3. Join two player game") print("4. Quit") print() c = safe_input("Your choice? ", "1234") c = int(c) if c==1: one_player(game) elif c==2: start_two_player(game) elif c==3: two_player_join(game) else: print('Play again soon.') def safe_input(prompt, values='abcdefghijklmnopqrstuvwxyz'): """ gives prompt, checks first char of input, assures it meets given values default is anything goes """ while True: i = input(prompt) try: c = i[0].lower() except IndexError: # the only possible error?! if c=='': print("Try again.") else: if c not in values: # some other character print("Try again.") else: # looks good. continue. break return i def get_name(): """ returns input as name """ while True: name = input("What is your name? ") check = input(name + ". Correct (y/n)? ") if check[0] in 'yY': break return name def get_result(player, opponent): """ reports opponent's choice; checks player and opponent dicts ['move'] against OUTCOME dict; reports result returns player dict with updated values """ print(opponent['name'], 'chose %s.' % (MOVES[opponent['move']])) # check lookout dict (OUTCOME dictionary) result = OUTCOME[(player['move'], opponent['move'])] # update game variables player['total'] += 1 if result=='win': print('%s beats %s. You win.' % (MOVES[player['move']], MOVES [opponent['move']])) player['won'] += 1 elif result=='draw': print('%s - %s: no one wins. You draw.' % (MOVES[player ['move']], MOVES[opponent['move']])) player['drew'] += 1 else: print('%s loses to %s. You lose.' % (MOVES[player['move']], MOVES[opponent['move']])) player['lost'] += 1 return player def one_player(game): """ implements one player game with minimal opponent dict """ print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to return to \ main menu.") opponent = {} opponent['name'] = 'Computer' # gaming loop while True: # gets player's choice game['move'] = safe_input('1, 2, 3, GO! ','rpsq') if game['move']=='q': break # computer chooses via random.choice opponent['move'] = choice('rps') # check game outcome dict game = get_result(game, opponent) # exit loop print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) def start_two_player(game): """ starts tcp server and implements two player game game dict = player 1""" # Create a socket (SOCK_STREAM means a TCP socket) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((HOST, PORT)) sock.listen(BACKLOG) serverip, serverport = sock.getsockname() print("Running at %s, %s" % (serverip, serverport)) print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ return to main menu.") print("Waiting for player...") client, address = sock.accept() clientip, clientport = address # server/game loop while True: try: P2game = loads(client.recv(BUFFSIZE)) # receive other game variables except EOFError: # if available print(P2game['name'], "left the game.") break client.send(dumps(game)) # send our variables # it's either the start... if P2game['start']: print(P2game['name'],"logged on at", clientip, clientport) game['start'] = False # or there's a message if P2game['message']!='' and P2game['message']!=game ['sentmessage']: print(P2game['name']+': '+P2game['message']) game['sentmessage'] = P2game['message'] # to avoid many print calls game['move'] = '' # message always takes priority # or there's a move if game['move']=='': game['move'] = safe_input('1, 2, 3, GO! ') if game['move']=='q': break elif game['move'] not in 'rps': game['message'] = game['move'] game['move'] = '' # only check result if P2game also made a move if P2game['move']!='': # check game outcome dict game=get_result(game, P2game) game['move']='' # exit loop client.close() print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) def two_player_join(game): """ joins a tcp server two player game game dict = player 2""" # Create a socket (SOCK_STREAM means a TCP socket) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ return to main menu.") # client/game loop while True: sock.send(dumps(game)) try: P1game = loads(sock.recv(BUFFSIZE)) except EOFError: print(P1game['name'], "left the game.") break if P1game['start']: print("You're connected to "+P1game['name']+"'s game.") game['start'] = False if P1game['message']!='' and P1game['message']!=game ['sentmessage']: print(P1game['name']+': '+P1game['message']) game['sentmessage'] = P1game['message'] game['move'] = '' if game['move']=='': game['move'] = safe_input('1, 2, 3, GO! ') if game['move']=='q': break elif game['move'] not in 'rps': game['message'] = game['move'] game['move'] = '' if P1game['move']!='': # check game outcome dict game=get_result(game, P1game) game['move']='' # exit loop sock.close() print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) if __name__=='__main__': game = {} # initialize game dict to store all game variables game['name'] = '' # player's name initially main_menu(game) From timr at probo.com Sat Jan 3 23:11:34 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 04 Jan 2009 04:11:34 GMT Subject: win32gui References: <8bf17a89-11bc-4c89-8ebc-db46fccefaa2@o4g2000pra.googlegroups.com> Message-ID: Gandalf wrote: > >I'm trying to capture the text word under the user cursor, >so I was searching the win32 lib for functions I can use. You should know that, in the general case, this is impossible. Remember that the screen image you are looking at is just a big array of dots. If the window underneath happens to be an image, there won't be any text to fetch. Now, in many cases it IS possible, but it's not easy. >i used this to fined the controller under the cursor >win32gui.WindowFromPoint(win32gui.GetCursorPos()) > to get the controller, That's the first step. Then, you need to figure out what kind of window it is. If it is a standard edit box, you can use the EM_GETLINE functions. If it's a rich text edit box, you can use the rich text messages. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From vminch at gmail.com Sat Jan 3 23:15:17 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 20:15:17 -0800 (PST) Subject: Port of python stdlib to other languages. References: <6sa2dvF4uc5uU1@mid.uni-berlin.de> Message-ID: <7b8157b6-0781-4509-b1ba-b799a41a406b@a29g2000pra.googlegroups.com> > AFAIK not. You could try elmer Elmer looks very interesting, but not really what I was getting at. > What do you need C for anyway? Or, to put it the other way round - why > not expose whatever you need in C as python extension, and write your > app in Python? I'm not looking to write a Python app atm. Just curious if someone had started a project like this, to, say, make Python users more comfortable using other languages (for whatever reason), or allow other people to try "python-like" code in their language to see if it suits them. From koranthala at gmail.com Sat Jan 3 23:25:59 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 3 Jan 2009 20:25:59 -0800 (PST) Subject: Doubt on creating threads References: Message-ID: <8f2a3eb8-ee54-404f-b565-a44ad2a62f10@n33g2000pri.googlegroups.com> On Jan 4, 4:59?am, Bryan Olson wrote: > koranth... at gmail.com wrote: > > I am creating an application and it creates ~1-2 threads every second > > and kill it within 10 seconds. After reading this I am worried. Is > > creating a thread a very costly operation? > > Compared to a procedure call it's expensive, but a couple threads per > second is insignificant. My out-dated Pentium 4 desktop can create and > destroy a few thousand threads per second under WinXP; more under recent > Linux. > > -- > --Bryan Thank you very much. I was worried about this a lot. From mensanator at aol.com Sat Jan 3 23:27:44 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 3 Jan 2009 20:27:44 -0800 (PST) Subject: Port of python stdlib to other languages. References: <6sa2dvF4uc5uU1@mid.uni-berlin.de> <7b8157b6-0781-4509-b1ba-b799a41a406b@a29g2000pra.googlegroups.com> Message-ID: <491ccedf-ea2d-4294-864c-ed8977c9185f@p2g2000prn.googlegroups.com> On Jan 3, 10:15?pm, vk wrote: > > AFAIK not. You could try elmer > > Elmer looks very interesting, but not really what I was getting at. > > > What do you need C for anyway? Or, to put it the other way round - why > > not expose whatever you need in C as python extension, and write your > > app in Python? > > I'm not looking to write a Python app atm. > > Just curious if someone had started a project like this, to, say, make > Python users more comfortable using other languages (for whatever > reason), > or allow other people to try "python-like" code in their language to > see > if it suits them. But wouldn't your language of choice first have to support things like lists, generators, etc.? I can use GMP library in C instead of gmpy in Python, but not if I need to use Python things that I don't know how to implement in C. From ptmcg at austin.rr.com Sat Jan 3 23:55:57 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 3 Jan 2009 20:55:57 -0800 (PST) Subject: Memoizing and WeakValueDictionary Message-ID: <482f1e7f-52a7-4c7f-819b-59faeb4e203e@e10g2000vbe.googlegroups.com> Just wanted to share some experience I had in doing some memory and performance tuning of a graphics script. I've been running some long- running scripts on high-resolution images, and added memoizing to optimize/minimize object creation (my objects are immutable, so better to reuse objects from a cache than constantly create and discard instances). This helped my script early on, but as the data files got larger and larger, and runs got longer and longer, the object memoize cache started to suck up some serious memory, and performance started to degrade for a different reason - low memory -> page thrashing -> program crawling. It occurred to me that in my program, a given object may get used for a while, but once its use declines, it doesn't come back for a while. At first blush, I thought about using some sort of LRU cache, but first I tried the WeakValueDictionary from the wkref module. This worked great! Now I get fairly optimal reuse of my immutable instances, but my object cache doesn't grow without bounds. Does this sound like a correct interpretation of this behavior? If so, it would seem that WeakValueDictionary would be a good recommendation to go along with any memoizing implementations. From aleksandr.goretoy at gmail.com Sun Jan 4 02:18:45 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 07:18:45 +0000 Subject: simple turn-based multiplayer game via TCP server/client In-Reply-To: References: Message-ID: Since we are on the subject of Rock, Paper, Scissors. I've recntly watched this one video on how to make a .deb out of .py files and the tutor was using a rock, paper scissors game. Not sure how this may come of use to you but, I'll post it anyway for you to look at. May help somehow. http://www.google.com/search?hl=en&q=filetype%3Apy+%22rock+paper+scissors%22&btnG=Search http://www.showmedo.com/videos/video?name=linuxJensMakingDeb&fromSeriesID=37 Hope this help you in your journey for multiplayer game somehow On Sun, Jan 4, 2009 at 3:58 AM, greywine at gmail.com wrote: > Hi everyone, > > I'm learning python to get a multiplayer roleplaying game up and > running. > > I didn't see any simple examples of multiplayer games on the web so I > thought I'd post mine here. I choose Rock, Paper, Scissors as a first > game to experiment with as the game logic/options are easy to > implement and understand. > > Initially, I tried to get the socketserver.TCPServer example in the > Python Docs to work, but couldn't get my game variables into the > handle method of the class MyTCPHandler. And I didn't know how else > to do it. I ended up creating my own server & client out of simple > sockets based on the simple echo server & client examples in the > Python Docs. > > I also wanted to send chat messages OR game variables back & forth, > but I couldn't figure out how to do the OR, so the basic idea in this > implementation is to send the dictionary 'game' back and forth. game > dict contains all the gaming variables as well as any chat messages. > The program processes results depending on whether the game is > starting, there's a chat message, or there's a game move. > > Finally, in testing, I ran the server in IDLE, but I had to load a > command prompt and switch to c:\python30; then type 'python > rpsmulti.py' for the client every time. Anyone know how to test > server/client code strictly in IDLE? > > Anyway, try it out and let me know how you would improve it. > > John R. > > # NAME: rpsmulti.py > # DESCRIPTION: rock, paper, scissors game multiplayer game > # AUTHOR: John Robinson > # DATE: 1/3/09 > # VERSION: Python 3.0 > # TO DO: > # .server_address instead of HOST, PORT? > > import socket > from random import choice > from pickle import dumps, loads > from pprint import pprint > > HOST, PORT = "localhost", 9999 # defined for now > BUFFSIZE = 1024 # for socket.send & recv commands > BACKLOG = 2 # number of clients supported by > server > SECONDS = 3 # seconds until socket.timeout (not > implemented) > # moves dict to translate 'rps' choice > MOVES = {'r':'Rock', > 'p':'Paper', > 's':'Scissors'} > # outcome dict stores result for all possible scenarios > OUTCOME = {('p','r'): 'win', > ('r','s'): 'win', > ('s','p'): 'win', > ('p','p'): 'draw', > ('r','r'): 'draw', > ('s','s'): 'draw', > ('r','p'): 'lose', > ('s','r'): 'lose', > ('p','s'): 'lose'} > > def main_menu(game): > """ initialize game dict variables & opening screen of the game > """ > game['total'] = 0 # total number of games played > game['won'] = 0 # total games won by player > game['lost'] = 0 # total games lost by player > game['drew'] = 0 # total games drew by player > game['move'] = '' # player's move (rps) > game['message'] = '' # player's chat message > game['sentmessage'] = '' # player's previous message > game['start'] = True # setting up the game boolean > > print("\tROCK PAPER SCISSORS\n") > if game['name']=='': # if returning to menu don't display > the following > game['name'] = get_name() > print("Welcome "+game['name']+". Remember...") > print("Rock smashes scissors! Paper covers Rock! Scissors cuts > paper!\n") > print("1. Play single player game") > print("2. Start two player game") > print("3. Join two player game") > print("4. Quit") > print() > c = safe_input("Your choice? ", "1234") > c = int(c) > if c==1: > one_player(game) > elif c==2: > start_two_player(game) > elif c==3: > two_player_join(game) > else: > print('Play again soon.') > > def safe_input(prompt, values='abcdefghijklmnopqrstuvwxyz'): > """ gives prompt, checks first char of input, assures it meets > given values > default is anything goes """ > while True: > i = input(prompt) > try: > c = i[0].lower() > except IndexError: # the only possible error?! > if c=='': > print("Try again.") > else: > if c not in values: # some other character > print("Try again.") > else: # looks good. continue. > break > return i > > def get_name(): > """ returns input as name """ > while True: > name = input("What is your name? ") > check = input(name + ". Correct (y/n)? ") > if check[0] in 'yY': > break > return name > > def get_result(player, opponent): > """ reports opponent's choice; > checks player and opponent dicts ['move'] against OUTCOME > dict; > reports result > returns player dict with updated values """ > print(opponent['name'], 'chose %s.' % (MOVES[opponent['move']])) > # check lookout dict (OUTCOME dictionary) > result = OUTCOME[(player['move'], opponent['move'])] > # update game variables > player['total'] += 1 > if result=='win': > print('%s beats %s. You win.' % (MOVES[player['move']], MOVES > [opponent['move']])) > player['won'] += 1 > elif result=='draw': > print('%s - %s: no one wins. You draw.' % (MOVES[player > ['move']], MOVES[opponent['move']])) > player['drew'] += 1 > else: > print('%s loses to %s. You lose.' % (MOVES[player['move']], > MOVES[opponent['move']])) > player['lost'] += 1 > return player > > def one_player(game): > """ implements one player game with minimal opponent dict """ > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to > return to \ > main menu.") > opponent = {} > opponent['name'] = 'Computer' > > # gaming loop > while True: > # gets player's choice > game['move'] = safe_input('1, 2, 3, GO! ','rpsq') > if game['move']=='q': > break > # computer chooses via random.choice > opponent['move'] = choice('rps') > # check game outcome dict > game = get_result(game, opponent) > > # exit loop > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > def start_two_player(game): > """ starts tcp server and implements two player game > game dict = player 1""" > # Create a socket (SOCK_STREAM means a TCP socket) > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.bind((HOST, PORT)) > sock.listen(BACKLOG) > serverip, serverport = sock.getsockname() > print("Running at %s, %s" % (serverip, serverport)) > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ > return to main menu.") > print("Waiting for player...") > > client, address = sock.accept() > clientip, clientport = address > # server/game loop > while True: > try: > P2game = loads(client.recv(BUFFSIZE)) # receive other > game variables > except EOFError: # if available > print(P2game['name'], "left the game.") > break > client.send(dumps(game)) # send our > variables > # it's either the start... > if P2game['start']: > print(P2game['name'],"logged on at", clientip, clientport) > game['start'] = False > # or there's a message > if P2game['message']!='' and P2game['message']!=game > ['sentmessage']: > print(P2game['name']+': '+P2game['message']) > game['sentmessage'] = P2game['message'] # to avoid many > print calls > game['move'] = '' # message always takes > priority > # or there's a move > if game['move']=='': > game['move'] = safe_input('1, 2, 3, GO! ') > if game['move']=='q': > break > elif game['move'] not in 'rps': > game['message'] = game['move'] > game['move'] = '' > # only check result if P2game also made a move > if P2game['move']!='': > # check game outcome dict > game=get_result(game, P2game) > game['move']='' > # exit loop > client.close() > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > def two_player_join(game): > """ joins a tcp server two player game > game dict = player 2""" > # Create a socket (SOCK_STREAM means a TCP socket) > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.connect((HOST, PORT)) > > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ > return to main menu.") > > # client/game loop > while True: > sock.send(dumps(game)) > try: > P1game = loads(sock.recv(BUFFSIZE)) > except EOFError: > print(P1game['name'], "left the game.") > break > if P1game['start']: > print("You're connected to "+P1game['name']+"'s game.") > game['start'] = False > if P1game['message']!='' and P1game['message']!=game > ['sentmessage']: > print(P1game['name']+': '+P1game['message']) > game['sentmessage'] = P1game['message'] > game['move'] = '' > if game['move']=='': > game['move'] = safe_input('1, 2, 3, GO! ') > if game['move']=='q': > break > elif game['move'] not in 'rps': > game['message'] = game['move'] > game['move'] = '' > if P1game['move']!='': > # check game outcome dict > game=get_result(game, P1game) > game['move']='' > # exit loop > sock.close() > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > if __name__=='__main__': > game = {} # initialize game dict to store all game > variables > game['name'] = '' # player's name initially > main_menu(game) > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 02:28:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 07:28:38 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> Message-ID: <01705c07$0$8693$c3e8da3@news.astraweb.com> I'm answering both John and Aaron's comments in the following. Mostly John at the start, Aaron toward the end. On Sat, 03 Jan 2009 15:42:47 -0800, Aaron Brady wrote: > On Jan 3, 11:25?am, John O'Hagan wrote: [...] > > >According to this, when you replace every floorboard on a porch, one > > >at a time, it's still the same porch-- it's changed, it's different, > > >and it's the same. ?However, if you haul off the porch and put a new > > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > > >just look at the initial and final configurations of matter to > > >determine so. ?Therefore, 'id' is an informal function. > > > > This analogy describes the "ontological minefield" I was referring to > > in a previous post in this thread (which has expired in my mail > > reader, so my apologies if the threading goes awry): In what sense is > > a porch (or list, or string) the same if all (or even some of) its > > parts have been exchanged? > > > > I think the answer is something to do with the abstraction, the > > "container", the instance of the class. That seems reasonable. When you say alist[:] = [1, 2, 3] the container remains "the same", while the contents change. > > Would it be fair to say that perhaps there are no > > truly mutable objects, only immutable containers whose contents (also > > immutable objects themselves) may be exchanged? Or to pose the > > question another way, are objects only mutable insofar as they are > > composite? That depends on what you mean by composite. Everything is composite in some sense, even a single bit in memory has a physical reality made of atoms with magnetic fields. But taken as an abstract entity, it is reasonable to treat a single bit as an atomic non-composite thing, and a single bit is mutable. In practice, actual Python objects tend to be mutable only if they are composite (although being composite doesn't make them mutable -- consider frozen sets and tuples). In principle, this is not necessary. There's no reason why Python couldn't expose a single bit as a data type, so you could write this: >>> n = bit(1) >>> bool(n) True >>> n.flip() >>> bool(n) False > > As you argue above, the planks are not the porch; I would add that > > it's your _decision_ to build (or tear down) a porch which makes it > > _that_ ?particular porch (or not). No, there's no such decision needed. Perhaps a hurricane comes through and rips the porch up. Maybe a rogue television crew comes by while you're at work and renovates your house without your knowledge. The lack of decision-making needed is more obvious when you consider something like a fast-flowing river. The specific water molecules making up the river at any particular instant in time flow away in a matter of days or weeks, but rivers have a continuity of existence measured in thousands of years. I trust that nobody is going to argue that the river makes any decisions at all? > > As you imply above (I think), you have to keep looking (or someone > > does, presumably the interpreter) to know whether an object is the > > same as or just equal to another (which starts to sound spookily like > > the role of "the observer" in phenomenology or quantum physics). No, I think you're introducing mysticism here that isn't needed. A bit like quantum mechanics, really :) In Python, every object has an identity and a value. If objects X and Y have the same identity, they are the same object. If X is the object with id 1234, and Y is the object with id 1234, then both are the same object. If their ids are different, then they are not. In CPython, the id is given by the memory location of the object, which leads to a very intuitive understanding of "same": the object with id 1234 is at memory location 1234, and since there can only be one object at a particular memory location at a time, obviously all objects with id 1234 must be the same object (provided they exist simultaneously). (To be pedantic, there can't actually be objects [note plural] existing simultaneously with the same id. There can only be multiple references to the one object.) In Python implementations where the id is not a memory address (IronPython and Jython I think?) the above remains true, even though there isn't the simple intuitive picture of "only one object can be at a specific memory address". Python guarantees that the id is *something* which is guaranteed to be unique over the lifetime of every object. Actually, our intuition about one thing per place at the one time is not strictly correct. Consider the memory address 1234, which currently has the value in hex of 0x58. That byte may be the numeric value 88, the ASCII char "X", the set of flags 1011000, or any other thing, depending on what interpretation we give to it. "What a thing is" is actually a more difficult question than it appears at first glance. [...] > I think the key ingredient is that there's no such thing as side > effect in math. I don't see that this is relevant. We're not talking about mathematical equality, but about the more general concepts of identity and sameness. > In example, > > a= [0, 1, 2] > a[:]= [3, 4, 5] > > There aren't many natural language senses in which 'a' is the same > object as before. Of course there are. If I have a box containing three things (a piece of paper with the number "0" written on it, a plastic block in the shape of "1" and a tally stick with two notches cut in it), and then I remove those three things and replace them with something else, it's the same box. The English and Australian cricket teams have been playing international Test cricket since 1877. None of the team members playing in 1877 are still alive today. The entire lineup of both cricket teams has been replaced repeatedly, and yet they are the same teams. The same holds for many, many different organisations: churches, armies, regiments, political parties, social clubs, companies, guilds, nations, sporting teams, secret societies, criminal gangs, ecosystems, tribes, communities of many sorts, and so forth. Far from being rare, this is very common. > If I have a leg transplant, I'm the same person, > but if you replace the entire contents of me, I'm not. Every (?) molecule in your body is replaced over a period of approximately seven years. Some molecules are replaced much quicker, some a little slower, but speaking roughly, the entire contents of you is replaced every seven years. Aaron, are you the same person you were a decade ago? In some sense, not at all -- you're a different person to the annoying person who called himself "castironpi" and was repeatedly accused of being a bot only a few months ago. But in another sense, yes, you are the same person -- there is a continuity of existence. See also the Ship of Theseus paradox, otherwise known as My Grandfather's Axe paradox. http://en.wikipedia.org/wiki/Ship_of_Theseus [...] > The porch is defined by its location, but not exclusively. If we remove the porch from the house and transport it whole to another house, it remains the same porch attached to a different house. > Natural > language identity is a cluster concept, without strict necessary and > sufficient conditions. Nothing really presses our boundaries of it > that much; there aren't many practical questions that lay out the > facts, then ask, 'But is it the same?' You can replace the porch > board-at-a-time, and it is; and you can haul it somewhere and it is. > But rearrange the same boards, and it's not. I think you overstate your case. If you move the boards around on the porch, it remains the same porch. Likewise if I have a chest of drawers, and I take the top drawer and put it at the bottom, the bottom drawer in the middle and the middle drawer at the top, surely it is the same chest of drawers? I haven't even replaced anything, just moved them around. > Continuity of form is > probably the prevalent feature, which as you state, does break down in > the case of composite (piece-wise) transformations. I think continuity of form is an important factor in deciding what is the same and what is not, but I don't think it is the only one. See for example the anecdote about the Japanese temple in the Wikipedia article above. And I think you're wrong to say that piece-wise transformations break down continuity of form. You are, in some sense, the same person who some years ago was a crawling baby unable to speak. There are significant changes and replacements and add-ons that nevertheless don't break continuity. > You might get farther comparing container objects to spots on a > bulletin board. The only thing that goes 'in' a container is a > denoting phrase to another object (and by the way, not a description); > the other also has its own spot independently on the board. That's a reasonable analogy for the implementation of CPython, but it need not be the only implementation. It wouldn't be fast, or efficient, or reasonable, but one could create a Python implementation where (for example) a list didn't just hold pointers to objects, but it held the actual entire object (no matter how large). Identity could be divorced from memory location: the one object could exist in many different places in memory, in the same way that an object can exist in many different times. The underlying VM would ensure that all such instantiations of the one object remained in sync at all time. Such an implementation would be inefficient and foolish, but it would still be Python. Having said that, it is perfectly valid to ignore the implementation when describing how Python operates. It really doesn't matter whether CPython is implemented like a bulletin board or not, it behaves as if it were, and that makes it a reasonable analogy. -- Steven From ajaksu at gmail.com Sun Jan 4 02:46:42 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 3 Jan 2009 23:46:42 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 3, 8:53?pm, Bryan Olson wrote: > If we add a parameter for the length of the list to which the slice is > applied, then inslice() is well-defined. Cool! > I thought it would easy to write, Heh, I gave up on the example I mentioned above :) > but that was hours ago when I knew > less about Python slice indexing than I do now. And I thought I new a > bunch from writing a virtual slice class. Maybe you could write about what you learned in the docs? > I'm leaning towards mmanns' idea that this should be built in. Handling > all the cases is remarkably tricky. Even without testing your code, I agree. I suggest that you add this as a feature request to the tracker at http://bugs.python.org/. I hope Raymond Hettinger likes it and adds an islice version :) From gruszczy at gmail.com Sun Jan 4 04:43:37 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 4 Jan 2009 10:43:37 +0100 Subject: deleting a method In-Reply-To: <87zli8j9li.fsf@benfinney.id.au> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> Message-ID: <1be78d220901040143v5918b5aft24df79b35b9cef25@mail.gmail.com> > To answer the second question: since 'foo' is an attribute of the > class 'A', you can delete the attribute from the class. > > >>> class A(object): > ... def foo(self): > ... pass > ... > >>> a = A() > >>> 'foo' in dir(a) > True > >>> del A.foo > >>> 'foo' in dir(a) > False Thanks, now I see, what happens, but don't exactly know why. Could you point me to some good explanation how object creation is performed in Python? I browsed language reference and google, but couldn't find good explanation. -- Filip Gruszczy?ski From aleksandr.goretoy at gmail.com Sun Jan 4 04:52:41 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 09:52:41 +0000 Subject: math module for Decimals In-Reply-To: <0170080e$0$8693$c3e8da3@news.astraweb.com> References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: I've been watching this thread for couple days now. I followed the bug report and all that stuff. It's very interesting to me how you guys talk about this stuff. I like it alot. I a new guy to python, just fyi. I'm one of my current projects I'm using Decimal as well and I think it be a huge pain in the you know what that it doesn't take floats as input. I'm currently doing this in my code: a=str(decimal.Decimal(str(round(self.value,2)-round(float(subtract),2)))) I know it's messy and I need sleep, yawn. But you see what I'm getting at here. I have to jump through somuch hoops to get what I wanted out of this. To be up front, I'm not sure that's what I wanted. Too tired. Anyway, I'm glad you guys got it pushed into 2.7 and 3.1. Thank you so much for this. Also, another reason why I'm posting to this thread. I noticed some error/typo in line 683 of decimal.py located on public svn repo. This is what is looks like. sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 I'm not trying to mention it to show someones flaws, rather I want to help you guys. Genuinely. I want in on the action. To do what I can, or what I'm capable of. So please do _NOT_ take it that way. This is awesome stuff, Thank you. -A On Sun, Jan 4, 2009 at 1:30 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: > > > On Jan 3, 9:27 pm, Mark Dickinson wrote: > >> Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > >> and Python 3.1, within 72 hours of Steven submitting the feature > >> request. If only all issues could be resolved this quickly. :-) > > > > Rats. I left out the crucial line of that post, namely: > > > > Thank you, Steven! > > And many thanks to both you and Raymond, firstly for doing the actual > work, and secondly for your patience with my questions on the bug tracker. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 04:52:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 09:52:49 GMT Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: <01707dd1$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 14:53:12 -0800, Bryan Olson wrote about testing whether or not an index is in a slice: > I'm leaning towards mmanns' idea that this should be built in. What's the use-case for it? > Handling > all the cases is remarkably tricky. Here's a verbose version, with a > little test: [snip code] Here's a less verbose version which passes your test cases: def inslice(index, slc, len): """Return True if index would be part of slice slc of a sequence of length len, otherwise return False. """ start, stop, stride = slc.indices(len) if stride < 0: return (start >= index > stop) and ((start-index) % -stride == 0) else: return (start <= index < stop) and ((index-start) % stride == 0) (Hint: help(slice) is your friend.) -- Steven From manishsinha.tech at gmail.com Sun Jan 4 05:09:27 2009 From: manishsinha.tech at gmail.com (Manish Sinha) Date: Sun, 04 Jan 2009 15:39:27 +0530 Subject: deleting a method In-Reply-To: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <49608AD7.7050704@gmail.com> Filip Gruszczy?ski wrote: > I am trying to delete a method from a class. It's easy to delete other > attributes, but when I try: > > >>>> class A: >>>> > ... def foo(): > ... pass > ... > >>>> a = A() >>>> del a.foo >>>> > > I get > > Traceback (most recent call last): > File "", line 1, in > AttributeError: A instance has no attribute 'foo' > > Why is it so and how may still delete it? > > Sounds crazy.... If you want to delete a function, create lambda functions though am not sure whether it can be deleted or not. -- Manish Sinha Personal Blog: http://www.manishsinha.info Tech Blog: http://manishtech.wordpress.com OpenPGP Key: 99E6658F -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Sun Jan 4 05:12:41 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 04 Jan 2009 21:12:41 +1100 Subject: deleting a method References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> Message-ID: <87r63jjs6e.fsf@benfinney.id.au> "Filip Gruszczy?ski" writes: > Thanks, now I see, what happens, but don't exactly know why. Could > you point me to some good explanation how object creation is > performed in Python? Rather than ?how object creation is performed?, I would recommend you get a better handle on how the object *model* works in Python. If you haven't yet, please work through all of the Python Tutorial . Read each part, experiment with code until you understand what is presented, and only *then* move on to the next section. For theoretical explanations, the effbot's ?Python Objects? article is also recommended. Before theory though, use the Tutorial for concrete demonstrations coming from your very fingers. -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From dickinsm at gmail.com Sun Jan 4 05:21:34 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jan 2009 02:21:34 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 9:52?am, "alex goretoy" wrote: > Also, another reason why I'm posting to this thread. I noticed some > error/typo in line 683 of decimal.py located on public svn repo. This is > what is looks like. > > ? ? ? ? sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 This line looks okay to me; can you say why you think there's a typo here? If it's the 'sign = 0' part that's bothering you, that's just a peculiarity of Decimal: the stored sign value is 0 for positive numbers, 1 for negative numbers, which I agree is a little counterintuitive. (Think of the sign as analogous to the sign *bit* in an IEEE 754 floating-point number.) Mark From aleksandr.goretoy at gmail.com Sun Jan 4 05:38:11 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 10:38:11 +0000 Subject: math module for Decimals In-Reply-To: References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: No, I know there's a typo because python told me there is. If you have svn repo locally. then cd into Lib/ and run python decimal.py It will tell you line 683 has syntax error, please see below. haha python-svn # python Lib/decimal.py File "Lib/decimal.py", line 683 sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 ^ SyntaxError: invalid syntax Although, It may be only because I ran it through python 2.4.3 Thanks for quick response, I wasn't expecting so quick. :) On Sun, Jan 4, 2009 at 10:21 AM, Mark Dickinson wrote: > On Jan 4, 9:52 am, "alex goretoy" wrote: > > Also, another reason why I'm posting to this thread. I noticed some > > error/typo in line 683 of decimal.py located on public svn repo. This is > > what is looks like. > > > > sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 > > This line looks okay to me; can you say why you think there's a typo > here? > > If it's the 'sign = 0' part that's bothering you, that's just > a peculiarity of Decimal: the stored sign value is 0 for > positive numbers, 1 for negative numbers, which I agree > is a little counterintuitive. (Think of the sign > as analogous to the sign *bit* in an IEEE 754 floating-point > number.) > > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Sun Jan 4 05:43:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 4 Jan 2009 12:43:18 +0200 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> Message-ID: <010a01c96e64$78890380$0d00a8c0@hendrik> "Aaron Brady" wrote: >No; tuples are composite. If I flip one bit in a byte somewhere, is >it the same byte? Yes and No and No and Others: Yes it is the byte at the same somewhere in memory. No it is not the same as it was a moment ago, because the bit has flipped. No it is one of the bytes recently corrupted by a passing cosmic ray. [Insert other points of view here] And of course, depending on what we are doing, we take the viewpoint that is useful to the task in hand. Taking all at the same time leads to a room with soft walls and a jacket with funny sleeves. Simplifying the porch example: Here is a family heirloom - it is my grandfather's axe. My father fixed it up by replacing the handle, and I replaced the head because it was so worn. I still think of it as my grandfather's axe, though. Natural language seems to have very little to do with logic, or even common sense, as constructs like "my grandfather's axe" can be encountered in the wild, without causing excessive cognitive dissonance. I think the root trouble for computers when we want them to make decisions about stuff like this is that they are too rigid - their binary or boolean nature forces them into taking the first branch that looks true at the time. We probably need something softer based on majority logic like neural nets, or something entirely new if we want to use them to explore this kind of stuff. (yes I know we can write a simulation, but a simulation is not an interpreter, is not a compiler, is not an assembler is not an executable - and its at the executable level that the rigidity is most apparent) - Hendrik From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 05:55:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 10:55:17 GMT Subject: Take the first n items of an iterator Message-ID: <01708c76$0$8693$c3e8da3@news.astraweb.com> I thought there was an iterator in itertools for taking the first n items of an iterator, then halting, but I can't find it. Did I imagine such a tool, or am I missing something? -- Steven From dickinsm at gmail.com Sun Jan 4 05:56:01 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jan 2009 02:56:01 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 10:38?am, "alex goretoy" wrote: > haha python-svn # python Lib/decimal.py > ? File "Lib/decimal.py", line 683 > ? ? sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 > ? ? ? ? ? ? ? ^ > SyntaxError: invalid syntax > > Although, It may be only because I ran it through python 2.4.3 Ah yes, that's it: the 'x if b else y' syntax wasn't introduced until Python 2.5; see http://docs.python.org/dev/whatsnew/2.5.html#pep-308-conditional-expressions for more. Hmm. Maybe we shouldn't be using this syntax in from_float, if it's the only thing that prevents the trunk version of decimal.py from being used with Python 2.4. On the other hand, from_float isn't going to work until 2.7 anyway, since it uses a whole bunch of new stuff: as_integer_ratio and copysign (both introduced in 2.6), and bit_length (introduced in 2.7). Mark From bj_666 at gmx.net Sun Jan 4 06:10:05 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 4 Jan 2009 11:10:05 GMT Subject: Take the first n items of an iterator References: <01708c76$0$8693$c3e8da3@news.astraweb.com> Message-ID: <6sbjodF51cmkU2@mid.uni-berlin.de> On Sun, 04 Jan 2009 10:55:17 +0000, Steven D'Aprano wrote: > I thought there was an iterator in itertools for taking the first n > items of an iterator, then halting, but I can't find it. Did I imagine > such a tool, or am I missing something? `itertools.islice()` Ciao, Marc 'BlackJack' Rintsch From Ron.Barak at lsi.com Sun Jan 4 06:25:18 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 4 Jan 2009 11:25:18 +0000 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <495D0582.4010002@tim.thechases.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> <495D0582.4010002@tim.thechases.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494880@enbmail01.lsi.com> Hi Tim, Thanks for the solution (and effort), and for teaching me some interesting new tricks. Happy 2009! Ron. -----Original Message----- From: Tim Chase [mailto:python.list at tim.thechases.com] Sent: Thursday, January 01, 2009 20:04 To: Sebastian Bassi Cc: python-list at python.org Subject: Re: How to find the beginning of last line of a big text file ? Sebastian Bassi wrote: > On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: >> I have a very big text file: I need to find the place where the last >> line begins (namely, the offset of the one-before-the-last '\n' + 1). >> Could you suggest a way to do that without getting all the file into >> memory (as I said, it's a big file), or heaving to readline() all lines (ditto) ? > > for line in open(filename): > lastline = line > print "the lastline is: %s",%lastline > > This will read all the lines, but line by line, so you will never have > the whole file in memory. > There may be more eficient ways to do this, like using the itertools. I think the OP wanted to do it without having to touch each line in the file. The following should do the trick, returning both the offset in the file, and that last line's content. from os import stat def last_line(fname, estimated_line_size=1024): assert estimated_line_size > 0 file_size = stat(fname).st_size if not file_size: return 0, "" f = file(fname, 'rb') f.seek(-1, 2) # grab the last character if f.read(1) == '\n': # a "proper" text file file_size -= 1 offset = file_size content = "" while offset >= 0 and '\n' not in content: offset -= estimated_line_size if offset < 0: estimated_line_size += offset # back it off offset = 0 f.seek(offset) block = f.read(estimated_line_size) content = block + content f.close() loc = content.rfind('\n') + 1 # after the newline return offset + loc, content[loc:] offset, line = last_line('some_file.txt') print "[%r] was found at offset %i" % (line, offset) In theory, it should even handle "malformed" text-files that don't end in a newline. There might be some odd edge-cases that I missed, but I think I caught most of them. -tkc From hubaghdadi at gmail.com Sun Jan 4 06:35:37 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Sun, 4 Jan 2009 03:35:37 -0800 (PST) Subject: Code coverage to Python code Message-ID: Hey, What is the best code coverage tool available for Python? Thanks. From hsoft at hardcoded.net Sun Jan 4 06:59:21 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Sun, 4 Jan 2009 03:59:21 -0800 (PST) Subject: Memoizing and WeakValueDictionary References: <482f1e7f-52a7-4c7f-819b-59faeb4e203e@e10g2000vbe.googlegroups.com> Message-ID: <94857225-f2b3-44f6-8f7d-a1391eb05540@v4g2000vbb.googlegroups.com> On Jan 4, 5:55?am, Paul McGuire wrote: > Just wanted to share some experience I had in doing some memory and > performance tuning of a graphics script. ?I've been running some long- > running scripts on high-resolution images, and added memoizing to > optimize/minimize object creation (my objects are immutable, so better > to reuse objects from a cache than constantly create and discard > instances). ?This helped my script early on, but as the data files got > larger and larger, and runs got longer and longer, the object memoize > cache started to suck up some serious memory, and performance started > to degrade for a different reason - low memory -> page thrashing -> > program crawling. > > It occurred to me that in my program, a given object may get used for > a while, but once its use declines, it doesn't come back for a while. > At first blush, I thought about using some sort of LRU cache, but > first I tried the WeakValueDictionary from the wkref module. ?This > worked great! > > Now I get fairly optimal reuse of my immutable instances, but my > object cache doesn't grow without bounds. > > Does this sound like a correct interpretation of this behavior? ?If > so, it would seem that WeakValueDictionary would be a good > recommendation to go along with any memoizing implementations. It depends on what you use memoizing for. If your memoized function return data from a dataset, then yeah, you want to use a weakref scheme because when such data is removed from the dataset, you want the memory associated to it to be freed. However, if you use memoizing on a function that creates the return value, you don't want to use a weakref scheme, because it makes the memoizing useless: If the caller of the memoized function doesn't keep a reference to the returned value, there will be no memoizing taking place for the next call of the function with the same arguments. To make it short: it depends. From skip at pobox.com Sun Jan 4 07:06:59 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 06:06:59 -0600 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: <18784.42595.41923.729353@montanaro.dyndns.org> Hussein> What is the best code coverage tool available for Python? Probably Ned Batchelders coverage.py. There is a trace.py module which comes with Python as well. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From aleksandr.goretoy at gmail.com Sun Jan 4 07:20:27 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 12:20:27 +0000 Subject: deleting a method In-Reply-To: <87r63jjs6e.fsf@benfinney.id.au> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> <87r63jjs6e.fsf@benfinney.id.au> Message-ID: HAHAHAHA, I like your sig Ben. So much that I blogged about it. starnixalpha.blogspot.com Oh yeah, and the info on this thread was helpful. Thanks, -A ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? On Sun, Jan 4, 2009 at 10:12 AM, Ben Finney < bignose+hates-spam at benfinney.id.au >wrote: > "Filip Gruszczy?ski" writes: > > > Thanks, now I see, what happens, but don't exactly know why. Could > > you point me to some good explanation how object creation is > > performed in Python? > > Rather than "how object creation is performed", I would recommend > you get a better handle on how the object *model* works in Python. > > If you haven't yet, please work through all of the Python Tutorial > . Read each part, experiment > with code until you understand what is presented, and only *then* move > on to the next section. > > For theoretical explanations, the effbot's "Python Objects" article > is also recommended. > > Before theory though, use the Tutorial for concrete demonstrations > coming from your very fingers. > > -- > \ "? a Microsoft Certified System Engineer is to information | > `\ technology as a McDonalds Certified Food Specialist is to the | > _o__) culinary arts." ?Michael Bacarella | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Sun Jan 4 07:25:58 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 12:25:58 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <01700ab5$0$8693$c3e8da3@news.astraweb.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: My gmail did that. FYI, it wasn't intentional. ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? Paula Poundstone - "I don't have a bank account because I don't know my mother's maiden name." On Sun, Jan 4, 2009 at 1:41 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 03 Jan 2009 16:19:58 +0100, Bruno Desthuilliers wrote: > > > But indeed, you obviously cannot add strings with numerics nor > > concatenate numerics with strings. This would make no sense. > > The OP comes from a Perl background, which AFAIK allows you to concat > numbers to strings and add strings to numbers. That's probably the (mis) > feature he was hoping Python had. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wim76 at care2.com Sun Jan 4 07:56:51 2009 From: wim76 at care2.com (Morgul Banner Bearer) Date: Sun, 4 Jan 2009 04:56:51 -0800 (PST) Subject: Using PythonPath under Windows Vista. Message-ID: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Hi Everybody, I was using the O'Reilly book from 1999 to look into Python and ran into a problem with the use of Pythonpath. I have Python installed under c:\python26. I have the module "Brian.py" that i want to run installed under c \python26\work In Windows Vista, I have set an environment variable "Pythonpath" equal to c:\python26\work (by using the "My computer", "Properties", "Advanced", "Environment Variables". The behaviour of the program is as follows : In a Dos Box, the program executes nicely when i type : "c\python26>python c:\python26\work\brian.py". Now i understand that- because I set the Pythonpath- the program should also run if i type: "c\python26>python brian.py" (under these conditions Python should look for the file brian.py in the folders specified in the Pythonpath). However, this does not work, but gives : "Can't open file... No such file or directory". I have not found further info availlable on bulletin boards on the internet, so if anybody can post the solution here, that would help me out. Thanks, wim76. From steve at holdenweb.com Sun Jan 4 08:29:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:29:50 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: Wolfgang Strobl wrote: > Derek Martin : > >> It took me about a half a second to grasp the "named bins" concept -- >> i.e. as soon as I was finished reading the words that explained it I >> understood it, so I'd say that based on your half-hour number, >> Python's model is substantially more complicated. > > I don't think so. Personally, I started programming by punching Fortran > IV statements into an IBM 26, submitting them as a batch job to an IBM > 7090, so the "named bins" concept is quite heavily engraved into my > brain. :-) But it didn't take me long to grasp (and enjoy!) the much > more advanced concept of variable bindings in SNOBOL4, which is similar > to Pythons, but predates Python quite some time. > > Quoting > > http://burks.bton.ac.uk/burks/language/snobol/catspaw/manual/ch6.htm > > Chapter 6 : DATA TYPES AND CONVERSION > > Most other programming languages require the user to explicitly declare > the type of data to be stored in a variable. In SNOBOL4, any variable > may contain any data type. Furthermore, the variable's type may be > freely altered during program execution. SNOBOL4 remembers what kind of > data is in each variable. > [...] > > C:\e\spitbol>spitbol test.spt > SPITBOL-386 Release 3.7(ver 1.30.16) Serial 20158 > (c) Copyright 1987-1997 Robert B. K. Dewar and Catspaw, Inc. > Snobol/Spitbol Beispiel [...] > Thanks for the memories. I developed the DECSystem-10 Spitbol implementation. I had no idea support of the language continued up to 1997, as I switched to Icon when Griswold produced that and found it a far superior language. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bockman at virgilio.it Sun Jan 4 08:34:38 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 04 Jan 2009 14:34:38 +0100 Subject: Using PythonPath under Windows Vista. References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: On Sun, 04 Jan 2009 04:56:51 -0800, Morgul Banner Bearer wrote: > Hi Everybody, > ... > > > The behaviour of the program is as follows : > In a Dos Box, the program executes nicely when i type : > "c\python26>python c:\python26\work\brian.py". > > Now i understand that- because I set the Pythonpath- the program > should also run if i type: > "c\python26>python brian.py" > (under these conditions Python should look for the file brian.py in > the folders specified in the > Pythonpath). However, this does not work, but gives : "Can't open > file... No such file or directory". > > I have not found further info availlable on bulletin boards on the > internet, so if anybody can post > the solution here, that would help me out. > AFAIK, PYTHONPATH only works for the imported modules. For the main module, you have to do give the full path. OR you could try out the new flag -m, which allows to run directly a module from the standard library and - I guess - also user modules if PYTHONPATH is set correcltly. So try from a "DOS Box" the command: "c\python26>python -m brian.py" Ciao --- FB From andrew at monkeysailor.co.uk Sun Jan 4 08:36:38 2009 From: andrew at monkeysailor.co.uk (Andrew Lewis) Date: Sun, 4 Jan 2009 13:36:38 +0000 Subject: Using PythonPath under Windows Vista. In-Reply-To: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: > In Windows Vista, I have set an environment variable "Pythonpath" > equal to c:\python26\work > (by using the "My computer", "Properties", "Advanced", "Environment > Variables". I always thought pythonpath was only for imports, try adding the location to the regular path variable. Andrew From steve at holdenweb.com Sun Jan 4 08:46:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:46:06 -0500 Subject: deleting a method In-Reply-To: <49608AD7.7050704@gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <49608AD7.7050704@gmail.com> Message-ID: Manish Sinha wrote: > Filip Gruszczy?ski wrote: >> I am trying to delete a method from a class. It's easy to delete other >> attributes, but when I try: >> >> >>>>> class A: >>>>> >> ... def foo(): >> ... pass >> ... >> >>>>> a = A() >>>>> del a.foo >>>>> >> >> I get >> >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: A instance has no attribute 'foo' >> >> Why is it so and how may still delete it? >> >> > Sounds crazy.... > > If you want to delete a function, create lambda functions though am not > sure whether it can be deleted or not. > In what sense are lambda functions any more or less "deletable" than functions or methods created using the "def" statement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 4 08:55:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:55:52 -0500 Subject: Using PythonPath under Windows Vista. In-Reply-To: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: Morgul Banner Bearer wrote: > Hi Everybody, > > I was using the O'Reilly book from 1999 to look into Python and ran > into a problem with > the use of Pythonpath. > > I have Python installed under c:\python26. > I have the module "Brian.py" that i want to run installed under c > \python26\work > > In Windows Vista, I have set an environment variable "Pythonpath" > equal to c:\python26\work > (by using the "My computer", "Properties", "Advanced", "Environment > Variables". > > The behaviour of the program is as follows : > In a Dos Box, the program executes nicely when i type : > "c\python26>python c:\python26\work\brian.py". > > Now i understand that- because I set the Pythonpath- the program > should also run if i type: > "c\python26>python brian.py" > (under these conditions Python should look for the file brian.py in > the folders specified in the > Pythonpath). However, this does not work, but gives : "Can't open > file... No such file or directory". > The PYTHONPATH variable is used by the interpreter to augment the set of locations to search for *imported* modules. It isn't used in locating the script from the command line. However, you might find that your installation has set .py up to be executed by the Python interpreter using the pathext mechanism, in which case you can just give the script's name and it will be found if it's somewwhere on your PATH (not your PYTHONPATH). > I have not found further info availlable on bulletin boards on the > internet, so if anybody can post > the solution here, that would help me out. > Well, you could have tried the FAQ, but I don't know off the top of my head whether that explains things. [Pauses to re-read http://www.python.org/doc/faq/windows/]. Well, some useful things are covered there, but it doesn't answer your question. Since the -m option runs the code of a module you will probably find that python -m brian will do what you expect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 4 09:09:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 09:09:57 -0500 Subject: Using PythonPath under Windows Vista. In-Reply-To: References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: Francesco Bochicchio wrote: [...] > AFAIK, PYTHONPATH only works for the imported modules. For the main > module, you have to do give the full path. > OR you could try out the new flag -m, which allows to run directly a > module from the standard library and - I guess - also user modules if > PYTHONPATH is set correcltly. So try from a "DOS Box" the command: > > "c\python26>python -m brian.py" > Note that you need to give the *name* of the module to the -m option, so that should be brian, not brian.py. E.g.: $ python -m StringIO File length = 1001 First line = 'SYSTEM:*:18:544:,S-1-5-18::\n' Position = 28 Second line = 'LocalService:*:19:544:U-NT AUTHORITY\\LocalService,S-1-5-19::\n' Read 8 more lines File length = 1001 Truncated length = 500 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 09:49:42 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 14:49:42 GMT Subject: Take the first n items of an iterator References: <01708c76$0$8693$c3e8da3@news.astraweb.com> <6sbjodF51cmkU2@mid.uni-berlin.de> Message-ID: <0170c364$0$8693$c3e8da3@news.astraweb.com> On Sun, 04 Jan 2009 11:10:05 +0000, Marc 'BlackJack' Rintsch wrote: > On Sun, 04 Jan 2009 10:55:17 +0000, Steven D'Aprano wrote: > >> I thought there was an iterator in itertools for taking the first n >> items of an iterator, then halting, but I can't find it. Did I imagine >> such a tool, or am I missing something? > > `itertools.islice()` Thanks Marc, time to check my glasses I think, I must have looked at that a dozen times and didn't draw the connection. -- Steven From roy at panix.com Sun Jan 4 10:08:01 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 07:08:01 -0800 (PST) Subject: Which SOAP module? Message-ID: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> I'm starting to play with SOAP. The zeroth question that needs answering is, "Which SOAP module should I use?" There seem to be a number of different ones to pick from. Any suggestions? From ralf at schoenian-online.de Sun Jan 4 10:41:40 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sun, 04 Jan 2009 16:41:40 +0100 Subject: Which SOAP module? In-Reply-To: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> Message-ID: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Roy Smith wrote: > I'm starting to play with SOAP. The zeroth question that needs > answering is, "Which SOAP module should I use?" There seem to be a > number of different ones to pick from. Any suggestions? > > It depends on whether you want to write a client or a server application. If you only want to write a client I found suds ( https://fedorahosted.org/suds/ ) very helpful. It is actively developed and the documentation is comprehensive. Well, for the server I think you have to rely on the ZSI (http://pywebsvcs.sourceforge.net/) project. In retrospect my first steps in this library were rather painful but som year ago it was the most sophisticated library. Regards, Ralf From roy at panix.com Sun Jan 4 11:09:06 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 08:09:06 -0800 (PST) Subject: Which SOAP module? References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <78be1000-73b7-47b1-be39-7a9da19f59e0@13g2000yql.googlegroups.com> On Jan 4, 10:41?am, Ralf Schoenian wrote: > It depends on whether you want to write a client or a server > application. At least for now, I'm only interesting in clients. From stefan_ml at behnel.de Sun Jan 4 11:10:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jan 2009 17:10:40 +0100 Subject: Which SOAP module? In-Reply-To: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4960df80$0$31334$9b4e6d93@newsspool4.arcor-online.net> Ralf Schoenian wrote: > Roy Smith wrote: >> I'm starting to play with SOAP. The zeroth question that needs >> answering is, "Which SOAP module should I use?" There seem to be a >> number of different ones to pick from. Any suggestions? > > for the server I think you > have to rely on the ZSI (http://pywebsvcs.sourceforge.net/) > project. In retrospect my first steps in this library were rather > painful but som year ago it was the most sophisticated library. Use soaplib (for client and/or server), it's a lot less painful. Stefan From hanser at club-internet.fr Sun Jan 4 11:49:18 2009 From: hanser at club-internet.fr (Pierre Hanser) Date: Sun, 04 Jan 2009 17:49:18 +0100 Subject: Which SOAP module? In-Reply-To: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4960e88d$0$28676$7a628cd7@news.club-internet.fr> Ralf Schoenian a ?crit : > Roy Smith wrote: >> I'm starting to play with SOAP. The zeroth question that needs >> answering is, "Which SOAP module should I use?" There seem to be a >> number of different ones to pick from. Any suggestions? >> >> > It depends on whether you want to write a client or a server > application. If you only want to write a client I found suds ( > https://fedorahosted.org/suds/ ) very helpful. It is actively developed > and the documentation is comprehensive. +1 for suds From michael.p.yang at gmail.com Sun Jan 4 12:14:52 2009 From: michael.p.yang at gmail.com (Michael Yang) Date: Mon, 5 Jan 2009 01:14:52 +0800 Subject: some question about python2.6 and python3k Message-ID: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Hi,guys i am a new guy for python world,i have some question want to ask 1.should i learn about python2.6 or python3k?i heard of it has some difference from them 2.Do python3k has some good web framework(like web.py)? Thanks ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From clockworksaint at gmail.com Sun Jan 4 12:26:51 2009 From: clockworksaint at gmail.com (Weeble) Date: Sun, 4 Jan 2009 09:26:51 -0800 (PST) Subject: TKinter and multiprocessing in GNU/Linux/X Message-ID: I'm using the multiprocessing module in Python 2.6 to run a pygame application. When errors occur, I create a new Process with the multiprocessing module and have it display a TKinter dialog. The pygame application can carry on happily without waiting for the dialog. This works fine on Windows. However, I've just tried the same code on Linux, and the TKinter dialog never appears. The process is spawned - if I print from it then it still appears on the console, but it does not display any TKinter window. If I create a TKinter window in my main process it works okay. I have a feeling that on Linux the multiprocessing module is doing a fork and all of the subprocesses end up fighting over the same connection to the X-server, is this possible? If so, is there some way to get multiprocessing to create a more "independent" process like on Windows? Or is there some way to tell TKinter to create a new connection to the X-server? I posted this as a question on Stack Overflow already, and there I've included source code to demonstrate what I'm doing: http://stackoverflow.com/questions/410469/why-dont-tkinter-windows-appear-when-using-multiprocessing-on-linux From benjamin.kaplan at case.edu Sun Jan 4 12:36:50 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 4 Jan 2009 12:36:50 -0500 Subject: some question about python2.6 and python3k In-Reply-To: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: On Sun, Jan 4, 2009 at 12:14 PM, Michael Yang wrote: > Hi,guys > > i am a new guy for python world,i have some question want to ask > > 1.should i learn about python2.6 or python3k?i heard of it has some > difference from them > If you don't have to worry about external libraries, you should probably start using Py3k. If you need external libraries and they aren't ported yet, you should probably use Python 2.6. There aren't that many major differences and, when everything is ported to Python 3, you should be able to pick it up pretty quickly. > > 2.Do python3k has some good web framework(like web.py)? AFAIK, none of the major web frameworks have been ported to Python 3 *yet*. Python 3 just came out a month ago, and the differences are enough to cause some problems for these large projects. If you're trying to do web programming, you should probably stick with 2.6 for now. > > > > Thanks ! > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Sun Jan 4 12:46:40 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sun, 04 Jan 2009 18:46:40 +0100 Subject: Ideas to optimize this getitem/eval call? In-Reply-To: <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: <4960F600.8030909@wildenhain.de> mario wrote: > On Jan 3, 7:16 am, Steven D'Aprano cybersource.com.au> wrote: > >> I was about to make a comment about this being a security hole, > > Strange that you say this, as you are also implying that *all* the > widely-used templating systems for python are security holes... Well, > you would be right to say that of course ;-) Infact, evoque is really > one of the few (or even the only one?) that was conceived from the > start to support restricted evaluation. Thats is definitively not the case. There are at least 2 quite old template systems on top of a quite good restricted environment. Cheers Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From ken at seehart.com Sun Jan 4 13:04:48 2009 From: ken at seehart.com (Ken Seehart) Date: Sun, 04 Jan 2009 19:04:48 +0100 Subject: some question about python2.6 and python3k In-Reply-To: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: <4960FA40.2000702@seehart.com> Michael Yang wrote: > Hi,guys > > i am a new guy for python world,i have some question want to ask > > 1.should i learn about python2.6 or python3k?i heard of it has some > difference from them > . I think you should go directly to 3K to save your self the extra work of learning the differences. The main advantage of using 2.6 is compatibility with the past. People who have already developed major projects will use 2.6 for a while until they get around to converting (if ever). But if you are new to python, this advantage is not very relevant to you, so you should start with 3K. > 2.Do python3k has some good web framework(like web.py)? > I don't know whether web.py specifically works under python 3K, but it seems to be a fairly active project, so my uneducated guess is that it will soon if it doesn't already. In any case 3K has plenty of direct support for all web related things. > > Thanks ! > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From bdesth.quelquechose at free.quelquepart.fr Sun Jan 4 13:05:36 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 04 Jan 2009 19:05:36 +0100 Subject: some question about python2.6 and python3k In-Reply-To: References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: <4961081e$0$3293$426a74cc@news.free.fr> Ken Seehart a ?crit : > Michael Yang wrote: >> Hi,guys >> >> i am a new guy for python world,i have some question want to ask >> >> 1.should i learn about python2.6 or python3k?i heard of it has some >> difference from them >> . > I think you should go directly to 3K to save your self the extra work of > learning the differences. That is, if you don't have any use for most major third-part lib. > The main advantage of using 2.6 is compatibility with the past. It's also compatibility with most third-part libs and with most existing tutorials and books. > People > who have already developed major projects will use 2.6 for a while until > they get around to converting (if ever). But if you are new to python, > this advantage is not very relevant to you, Unless you plan to work on any project relying on third-part libs... > so you should start with 3K. >> 2.Do python3k has some good web framework(like web.py)? >> > I don't know whether web.py specifically works under python 3K, but it > seems to be a fairly active project, so my uneducated guess is that it > will soon if it doesn't already. Django is also a "fairly active project", and it's by no mean py3k ready yet. Most major, active web frameworks will be ported to Py3k, but this will take some time. > In any case 3K has plenty of direct > support for all web related things. Sure, but this doesn't replace a full-blown framework. From kleefaj at gmail.com Sun Jan 4 13:14:29 2009 From: kleefaj at gmail.com (kleefaj) Date: Sun, 4 Jan 2009 10:14:29 -0800 (PST) Subject: IDLE spinning beach ball on OS X 10.3.9 Panther Message-ID: Greetings. I want to run IDLE on my iBook running Mac OS X 10.3.9 (Panther). Per the instructions on "Python on the Macintosh" [1], I downloaded and installed TclTkAqua [2], then downloaded and installed Universal- MacPython-2.4.3 [3]. Python launches in Terminal. The version shown is 2.4.3. When I launch IDLE (Applications/MacPython 2.4), a Console window and a *Python Shell* window open, and then I get the spinning beach ball. I have to Force Quit. Did I miss anything? How do I get this to work? Thanks, Jeff [1] http://www.python.org/download/mac/ [2] http://prdownloads.sourceforge.net/tcltkaqua/TclTkAqua-8.4.10.dmg?download [3] http://www.python.org/ftp/python/2.4.3/Universal-MacPython-2.4.3-2006-04-07.dmg From h at realh.co.uk Sun Jan 4 13:20:31 2009 From: h at realh.co.uk (Tony Houghton) Date: Sun, 4 Jan 2009 18:20:31 +0000 Subject: How to declare python ints in C extensions? Message-ID: <20090104182031.22dc6954@realh.co.uk> I want to write python wrappers for the Linux DVB API. The underlying structures and constants may change from time to time, and some of the constants are generated from macros, so I think it would be better to write the module in C rather than just copying the constants into pure python code and using python's ioctl and struct modules. The trouble is I can't find out how to define a simple python int variable/constant in a C extension. The docs only seem to tell you how to define functions/methods and new types. For example, where the kernel header dvb/frontend.h defines: typedef enum fe_type { FE_QPSK, FE_QAM, FE_OFDM, FE_ATSC } fe_type_t; I want to make them available as if there was a python module dvb/frontend.py containing: FE_QPSK = 0 FE_QAM = 1 FE_OFDM = 2 FE_ATSC = 3 but in real life the module would be dvb/frontendmodule.c. -- TH * http://www.realh.co.uk From saju.pillai at gmail.com Sun Jan 4 13:38:05 2009 From: saju.pillai at gmail.com (Saju Pillai) Date: Mon, 05 Jan 2009 00:08:05 +0530 Subject: How to declare python ints in C extensions? In-Reply-To: <20090104182031.22dc6954@realh.co.uk> References: <20090104182031.22dc6954@realh.co.uk> Message-ID: Tony Houghton wrote: > I want to write python wrappers for the Linux DVB API. The underlying > structures and constants may change from time to time, and some of the > constants are generated from macros, so I think it would be better to > write the module in C rather than just copying the constants into pure > python code and using python's ioctl and struct modules. > > The trouble is I can't find out how to define a simple python int > variable/constant in a C extension. The docs only seem to tell you how > to define functions/methods and new types. > > For example, where the kernel header dvb/frontend.h defines: > > typedef enum fe_type { > FE_QPSK, > FE_QAM, > FE_OFDM, > FE_ATSC > } fe_type_t; > > I want to make them available as if there was a python module > dvb/frontend.py containing: > > FE_QPSK = 0 > FE_QAM = 1 > FE_OFDM = 2 > FE_ATSC = 3 > > but in real life the module would be dvb/frontendmodule.c. > Create Python Int objects for each of these constants and set them into your module object's dictionary foo = PyInt_FromLong(1L); PyDict_SetItemString(PyModule_GetDict(your_module), "foo", foo); Py_DECREF(foo) srp -- http://saju.net.in From philip at semanchuk.com Sun Jan 4 13:46:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 4 Jan 2009 13:46:35 -0500 Subject: How to declare python ints in C extensions? In-Reply-To: <20090104182031.22dc6954@realh.co.uk> References: <20090104182031.22dc6954@realh.co.uk> Message-ID: On Jan 4, 2009, at 1:20 PM, Tony Houghton wrote: > I want to write python wrappers for the Linux DVB API. The underlying > structures and constants may change from time to time, and some of the > constants are generated from macros, so I think it would be better to > write the module in C rather than just copying the constants into pure > python code and using python's ioctl and struct modules. > > The trouble is I can't find out how to define a simple python int > variable/constant in a C extension. This works for me: PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); I've had to learn a lot about writing extensions from looking at the Python source code. Lots of valuable tricks to be learned there. HTH Philip From tommy.nordgren at comhem.se Sun Jan 4 14:16:57 2009 From: tommy.nordgren at comhem.se (Tommy Nordgren) Date: Sun, 4 Jan 2009 20:16:57 +0100 Subject: IDLE spinning beach ball on OS X 10.3.9 Panther In-Reply-To: References: Message-ID: <4C4C31F7-1ECC-407A-9100-6B541A2C8090@comhem.se> On Jan 4, 2009, at 7:14 PM, kleefaj wrote: > Greetings. > > I want to run IDLE on my iBook running Mac OS X 10.3.9 (Panther). > > Per the instructions on "Python on the Macintosh" [1], I downloaded > and installed TclTkAqua [2], then downloaded and installed Universal- > MacPython-2.4.3 [3]. > > Python launches in Terminal. The version shown is 2.4.3. > > When I launch IDLE (Applications/MacPython 2.4), a Console window and > a *Python Shell* window open, and then I get the spinning beach ball. > I have to Force Quit. > > Did I miss anything? How do I get this to work? > > Thanks, > Jeff > > [1] http://www.python.org/download/mac/ > [2] http://prdownloads.sourceforge.net/tcltkaqua/TclTkAqua-8.4.10.dmg?download > [3] http://www.python.org/ftp/python/2.4.3/Universal-MacPython-2.4.3-2006-04-07.dmg > -- > http://mail.python.org/mailman/listinfo/python-list That an app beach balls don't mean it's hung or crashed, but only that it does something time consuming on the main thread (the one that handles UI) ------------------------------------------------------ "Home is not where you are born, but where your heart finds peace" - Tommy Nordgren, "The dying old crone" tommy.nordgren at comhem.se From lutz at rmi.net Sun Jan 4 14:29:12 2009 From: lutz at rmi.net (Mark Lutz) Date: Sun, 4 Jan 2009 11:29:12 -0800 (PST) Subject: Python training in Colorado, January 27-30 Message-ID: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> Python author and trainer Mark Lutz will be teaching a 4-day Python class on January 27-30, in Longmont, Colorado. This is a public training session open to individual enrollments, and covers the same topics and hands-on lab work as the onsite sessions that Mark teaches. The class provides an in-depth introduction to both Python and its common applications, and parallels the instructor's popular Python books. For more information on this session, please visit its web page: http://home.earthlink.net/~python-training/2009-public-classes.htm For additional background on the class itself, see our home page: http://home.earthlink.net/~python-training Thanks for your interest, --Python Training Services From roy at panix.com Sun Jan 4 14:47:30 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 11:47:30 -0800 (PST) Subject: pep-8 vs. external interfaces? Message-ID: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> I'm building a Python language wrapper to an network protocol which traditionally uses camelCase function names. I'm trying to make the new code pep-8 compliant, which means function names should be written this_way() instead of thisWay(). I've got a couple of choices open to me. I could convert all the protocol names to pep-8 style mechanically. This is not as much work as it seems; the lowest-level Python code is already machine generated from a tabular description of the protocol. It's about one more line of code to convert getLibraries() to get_libraries(). This will leave the result the cleanest from the Python point of view. It'll also make the Python binding look a little different from the C++, Java, Perl, etc, bindings. Or, I could draw a line in the sand and say, "If it's a protocol primitive, it stays as written. Otherwise, it's pep-8". That's a little uglier because it's not always obvious to the user exactly which names are protocol primitives and which are higher-level operations. I figure either way, somebody's going to complain that I did it wrong :-) I realize there's no single correct answer here. I'm seeking input from people who have faced this question before. Which way did you go? In retrospect, was it the right decision? From lists at cheimes.de Sun Jan 4 15:05:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 04 Jan 2009 21:05:14 +0100 Subject: How to declare python ints in C extensions? In-Reply-To: References: <20090104182031.22dc6954@realh.co.uk> Message-ID: Philip Semanchuk schrieb: > This works for me: > PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); > > I've had to learn a lot about writing extensions from looking at the > Python source code. Lots of valuable tricks to be learned there. This trick makes it even easier: #ifndef PyModule_AddIntMacro #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) #endif if (!PyModule_AddIntMacro(mod, O_CREAT)) return; Christian From boblatest at yahoo.com Sun Jan 4 15:18:09 2009 From: boblatest at yahoo.com (Robert Latest) Date: 4 Jan 2009 20:18:09 GMT Subject: Memory debugging tool for Python/C API? Message-ID: <6scjs1F4s2rjU1@mid.uni-berlin.de> Hello, extending Python in C ist just the coolest thing since sliced bread (and I'm particularly happy because I really had started to miss C when I did more and more things in Python). I've got one question though. Tha C/API documentation is not quite clear (to me, anyway) on what happens exactly to ressources between the C/Python side. One example is this: I wrote a function that assembles a string into a dynamically-allocated buffer, then creates a PyString from it which it returns to the Python side: PyObject *dyn_string(void) { char *buffer = malloc(20); PyObject *pystr; strcpy(buffer, "Hello, World"); pystr = PyString_FromString(buffer); free(buffer); return pystr; } This works, but I'm not sure if PyString...() really makes a new copy of the data (ellowing me to use free()), or if this will segfault one day. OTOH I wouldn't know how to safely dispose of the string data otherwise. Another example (all on the C side of things) is a function where I build a dictionary from a set of keys, putting PyNone into each value (Py_INCREF()ing PyNone each time). At another point some of the values are replaced by other PyObjects. At first I used PyDECREF() on each value before setting the new value, but that botched up the dictionary beyond repair. Without the PyDECREF() calls everything worked fine. Now to my actual question: Is there some sort of debugging tool that I could use to analyze my code to see if everything gets properly allocated and deallocated and if the reference counting works right? Thanks, robert From aleksandr.goretoy at gmail.com Sun Jan 4 15:19:15 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 20:19:15 +0000 Subject: Python training in Colorado, January 27-30 In-Reply-To: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> References: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> Message-ID: I'd be interested in attending if you make it to Tulsa,OK. Are your courses only in Colorado? -Alex Goretoy http://www.alexgoretoy.com On Sun, Jan 4, 2009 at 7:29 PM, Mark Lutz wrote: > Python author and trainer Mark Lutz will be teaching a 4-day > Python class on January 27-30, in Longmont, Colorado. > > This is a public training session open to individual enrollments, > and covers the same topics and hands-on lab work as the onsite > sessions that Mark teaches. The class provides an in-depth > introduction to both Python and its common applications, and > parallels the instructor's popular Python books. > > For more information on this session, please visit its web page: > > http://home.earthlink.net/~python-training/2009-public-classes.htm > > For additional background on the class itself, see our home page: > > http://home.earthlink.net/~python-training > > Thanks for your interest, > --Python Training Services > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexus at gmail.com Sun Jan 4 15:54:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 12:54:44 -0800 (PST) Subject: Python3 Message-ID: I wanted to try out new Python 3 on my system, so I did "make fullinstall" and now as promised it broke every single program there is that runs on my system that depends on Python. is there a way to undo that? I've tried re-installing Python 2, yet that didn't help me at all. From tmohr at s.netic.de Sun Jan 4 16:10:42 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 04 Jan 2009 22:10:42 +0100 Subject: Package / Module Hierarchy question Message-ID: Hi, in a package i use these files: module (dir) __init__.py submodule __init__.py qwe.py qwe.py defines a class that derives from a class defined in submodule (and by that in submodule/__init__.py. Is it possible somehow to write in qwe.py to import submodule (though __init__.py is in the same directory as qwe.py ? I'd like to keep the tests for qwe.py within qwe.py, the code that i want to execute when i directly execute qwe.py and then: if __name__ == '__main__': some_test_code() Or do i need to write an external test code? Thanks for any hints, Torsten. From skip at pobox.com Sun Jan 4 16:23:07 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 15:23:07 -0600 Subject: Python3 In-Reply-To: References: Message-ID: <18785.10427.762775.464617@montanaro.dyndns.org> alexus> I wanted to try out new Python 3 on my system, so I did "make alexus> fullinstall" and now as promised it broke every single program alexus> there is that runs on my system that depends on Python. alexus> is there a way to undo that? I've tried re-installing Python 2, alexus> yet that didn't help me at all. The install targets for Python 3 explicitly don't create a symlink named "python", so it's not obvious how you might have obliterated your Python 2 installation. You didn't provide any information about your environment (Windows? Linux? Mac? Was Python 2 provided by your OS vendor or installed by you?) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From naplanetu at gmail.com Sun Jan 4 16:30:15 2009 From: naplanetu at gmail.com (Taras Ivashchenko) Date: Mon, 5 Jan 2009 00:30:15 +0300 Subject: SSL certificate parsing? Message-ID: Hello, list! I use pyopenssl [0] for checking SSL certificates. And one of such checks is if given certificate is self-signed. I can do it using values of X509v3 extensions: the subject key identifier and the authority key id: X509v3 Subject Key Identifier: 0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 X509v3 Authority Key Identifier: keyid:0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 I read documentation of pyOpenSSL but I didn't find way how to grub this information from certificate using, for example, methods of X509 object. May be there is another way to parse SSL certificates? I will be glad to get ever text version of given SSL certificate :) [0] http://pyopenssl.sourceforge.net/ P.S. I already wrote to pyopenssl mailing list, but there is now answer there :( ????? ???????? (Taras Ivashchenko) -- "Software is like sex: it's better when it's free.", - Linus Torvalds. From alexus at gmail.com Sun Jan 4 16:39:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 13:39:44 -0800 (PST) Subject: Python3 References: Message-ID: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> On Jan 4, 4:23?pm, s... at pobox.com wrote: > ? ? alexus> I wanted to try out new Python 3 on my system, so I did "make > ? ? alexus> fullinstall" and now as promised it broke every single program > ? ? alexus> there is that runs on my system that depends on Python. > > ? ? alexus> is there a way to undo that? I've tried re-installing Python 2, > ? ? alexus> yet that didn't help me at all. > > The install targets for Python 3 explicitly don't create a symlink named > "python", so it's not obvious how you might have obliterated your Python 2 > installation. ?You didn't provide any information about your environment > (Windows? ?Linux? ?Mac? ?Was Python 2 provided by your OS vendor or > installed by you?) > > -- > Skip Montanaro - s... at pobox.com -http://smontanaro.dyndns.org/ sorry, for not providing all information at the first place, here it is: enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- p7 #6: Wed Dec 24 15:58:06 EST 2008 alexus at j.jothost.com:/usr/obj/ usr/src/sys/GENERIC i386 I installed both of Python 2 and Python 3 via source code (compile them myself) From skip at pobox.com Sun Jan 4 16:46:38 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 15:46:38 -0600 Subject: Python3 In-Reply-To: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> References: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> Message-ID: <18785.11838.976517.677454@montanaro.dyndns.org> alexus> enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- alexus> p7 #6: Wed Dec 24 15:58:06 EST 2008 alexus at j.jothost.com:/usr/obj/ alexus> usr/src/sys/GENERIC i386 alexus> I installed both of Python 2 and Python 3 via source code alexus> (compile them myself) Where was Python 2 installed? /usr/bin or /usr/local/bin or somewhere else? What was the --prefix arg to configure when building Python 3? S From aleksandr.goretoy at gmail.com Sun Jan 4 16:57:31 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 21:57:31 +0000 Subject: Package / Module Hierarchy question In-Reply-To: References: Message-ID: You might try this in qwe.py import os,sys sys.path.append(os.getcwd()+"../") This will allow you to then import modules from module(dir). Hope this helps. OTOH, there maybe a better solution. -Alex Goretoy http://www.alexgoretoy.com On Sun, Jan 4, 2009 at 9:10 PM, Torsten Mohr wrote: > Hi, > > in a package i use these files: > > module (dir) > __init__.py > submodule > __init__.py > qwe.py > > > qwe.py defines a class that derives from a class defined in submodule (and > by that in submodule/__init__.py. > > Is it possible somehow to write in qwe.py to import submodule (though > __init__.py is in the same directory as qwe.py ? > > I'd like to keep the tests for qwe.py within qwe.py, the code that i want > to > execute when i directly execute qwe.py and then: > > if __name__ == '__main__': > some_test_code() > > > Or do i need to write an external test code? > > > Thanks for any hints, > Torsten. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexus at gmail.com Sun Jan 4 17:03:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 14:03:44 -0800 (PST) Subject: Python3 References: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> Message-ID: <9a4c7014-0b5a-41bf-b23b-ab202d75f158@g39g2000pri.googlegroups.com> On Jan 4, 4:46?pm, s... at pobox.com wrote: > ? ? alexus> enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- > ? ? alexus> p7 #6: Wed Dec 24 15:58:06 EST 2008 ? ? ale... at j.jothost.com:/usr/obj/ > ? ? alexus> usr/src/sys/GENERIC ?i386 > > ? ? alexus> I installed both of Python 2 and Python 3 via source code > ? ? alexus> (compile them myself) > > Where was Python 2 installed? ?/usr/bin or /usr/local/bin or somewhere else? > What was the --prefix arg to configure when building Python 3? > > S both of them were default --prefix, so I assume --prefix=/usr/local/ su-3.2# whereis python python: /usr/local/bin/python /usr/ports/lang/python su-3.2# /usr/local/bin/python --version Python 2.6.1 su-3.2# it's shows like 2.6.1 is there, yet when I ran "trac-admin", I get su-3.2# trac-admin Traceback (most recent call last): File "/usr/local/bin/trac-admin", line 5, in from pkg_resources import load_entry_point ImportError: No module named pkg_resources su-3.2# From robert.kern at gmail.com Sun Jan 4 17:41:03 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 04 Jan 2009 17:41:03 -0500 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: Hussein B wrote: > Hey, > What is the best code coverage tool available for Python? I like Titus Brown's figleaf. http://darcs.idyll.org/~t/projects/figleaf/doc/ -- 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 prologic at shortcircuit.net.au Sun Jan 4 18:03:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 09:03:49 +1000 Subject: greenlets and how they can be used In-Reply-To: <495FB40A.9060606@gmx.net> References: <495FB40A.9060606@gmx.net> Message-ID: On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst wrote: > Back when I was still using Perl, there was - and still is, I guess - a really nice framework called POE, that allowed you to write event-driven state machines in a really easy and pleasant way. Under POE, EVERYTHING was an event. When writing a network server, each incoming client connection was an event, within a connection, each incoming piece of data was an event; when reading a file, each line fired an event (i.e. I/O was completely asynchronous); when querying a database, each result row would fire an event. What was even better, you could very easily plug GTK's or Tk's event loop into the whole mix and have GUI interactions fire events, too. > POE was one of the nicest software frameworks I have ever used, and I've been continuously frustrated by the lack of something like it in other languages such as Python or Ruby. It does exist :) It's called circuits. Or at least circuits is a framework that I develop and build which sounds very similar to POE in some ways :) cheers James From martin at v.loewis.de Sun Jan 4 18:05:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 05 Jan 2009 00:05:01 +0100 Subject: Memory debugging tool for Python/C API? In-Reply-To: <6scjs1F4s2rjU1@mid.uni-berlin.de> References: <6scjs1F4s2rjU1@mid.uni-berlin.de> Message-ID: <4961409d$0$22820$9b622d9e@news.freenet.de> > This works, but I'm not sure if PyString...() really makes a new copy of > the data (ellowing me to use free()) See the documentation: http://docs.python.org/c-api/string.html#PyString_FromString # Return a new string object with a *copy* of the string v as value > Another example (all on the C side of things) is a function where I > build a dictionary from a set of keys, putting PyNone into each value > (Py_INCREF()ing PyNone each time). Assuming you use PyDict_SetItem(String): you shouldn't INCREF Py_None; the SetItem will itself incref the value (and decref any old value that might be already stored under that key). The only exception where you, as a caller, have to INCREF is when the reference is documented as "stolen"; very few API functions steal references. > At another point some of the values > are replaced by other PyObjects. At first I used PyDECREF() on each > value before setting the new value, but that botched up the dictionary > beyond repair. Without the PyDECREF() calls everything worked fine. See above. > Now to my actual question: Is there some sort of debugging tool that I > could use to analyze my code to see if everything gets properly > allocated and deallocated and if the reference counting works right? You should compile Python in pydebug mode; this will perform some additional checks each time. In addition, you can look at sys.getrefcount repeatedly. If you create a test that allocates stuff and then releases it, then sys.getrefcount should be unchanged. If it does change, you might have a reference leak. Regards, Martin From h at realh.co.uk Sun Jan 4 18:47:29 2009 From: h at realh.co.uk (Tony Houghton) Date: Sun, 4 Jan 2009 23:47:29 +0000 Subject: How to declare python ints in C extensions? References: <20090104182031.22dc6954@realh.co.uk> Message-ID: <20090104234729.10c9ea77@realh.co.uk> On Sun, 04 Jan 2009 21:05:14 +0100 Christian Heimes wrote: > Philip Semanchuk schrieb: > > This works for me: > > PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); > > > > I've had to learn a lot about writing extensions from looking at the > > Python source code. Lots of valuable tricks to be learned there. Thanks, that's perfect. I see it is documented, but I didn't know where to look. > This trick makes it even easier: > > #ifndef PyModule_AddIntMacro > #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) > #endif Good idea, but I'm a lot more experienced with C in general than in interfacing it with python, so I already thought of it :-). -- TH * http://www.realh.co.uk From missive at hotmail.com Sun Jan 4 18:52:33 2009 From: missive at hotmail.com (Lee Harr) Date: Mon, 5 Jan 2009 04:22:33 +0430 Subject: [ANN] TZMud 0.8 Message-ID: TZMud is a Python MUD server. http://tzmud.googlecode.com/ A MUD is a text-based virtual environment accessed via telnet, or with a specialised MUD client. TZMud development is still in early stages, focusing on API and server stability. TZMud uses several high-quality Python libraries to facilitate rapid development: Twisted, ZODB, and Pyparsing. TZMud is released under GPLv3. Changes in TZMud-0.8: - web access to database - better cross-platform operation - added configuration file verifcation tool - more readable and natural messages and commands - improved handling of object attributes - Exit can now be subclassed and cloned - objects can now be invisible - objects can now have a weight - rudimentary plugin framework - more teleportation commands - more secure password storage - xyzzy - new items/ mobs/ exits: - ring of invisibility - traps - spawner - players only exit _________________________________________________________________ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/events.aspx From fakeaddress at nowhere.org Sun Jan 4 19:03:01 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 04 Jan 2009 16:03:01 -0800 Subject: Testing if an index is in a slice In-Reply-To: <01707dd1$0$8693$c3e8da3@news.astraweb.com> References: <20090101191226.5137adb6@Schlamber.localdomain> <01707dd1$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Here's a less verbose version which passes your test cases: > > def inslice(index, slc, len): > """Return True if index would be part of slice slc of a > sequence of length len, otherwise return False. > """ > start, stop, stride = slc.indices(len) > if stride < 0: > return (start >= index > stop) and ((start-index) % -stride == 0) > else: > return (start <= index < stop) and ((index-start) % stride == 0) > > > (Hint: help(slice) is your friend.) I should really think about abandoning my strategy of doing everything the hard way. -- --Bryan From tmohr at s.netic.de Sun Jan 4 19:17:57 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 05 Jan 2009 01:17:57 +0100 Subject: structuring a package? Message-ID: Hi, i have a question on how to structure a package best, would be great if anybody could give me some hint on this: Assuming i have a base class GraphicObject and derived from that some classes like Square, Circle, ... It looks natural to me to write in a code that uses the package: import graphic import graphic.square import graphic.circle That way i'd have to structure the code like this: graphic/ __init__,py (GraphicObject) square.py (Square) circle.py (Circle) Does that make sense like this? Are there better ways to structure things in Python? One thing that bothers me is that when i write in circly.py something like "import graphic", then i can't have the test code for the Circle within circle.py, at least it looks to me like this. The closest thing that handles this issue that i could find was PEP 328, but it doesn't cover this problem. Thanks for any hints, Torsten. From prologic at shortcircuit.net.au Sun Jan 4 19:27:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 10:27:37 +1000 Subject: structuring a package? In-Reply-To: References: Message-ID: On Mon, Jan 5, 2009 at 10:17 AM, Torsten Mohr wrote: > It looks natural to me to write in a code that uses the package: > > import graphic > import graphic.square > import graphic.circle > > That way i'd have to structure the code like this: > > graphic/ > __init__,py (GraphicObject) > square.py (Square) > circle.py (Circle) > > Does that make sense like this? This seems perfectly acceptable. cheers James From Scott.Daniels at Acm.Org Sun Jan 4 19:28:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 04 Jan 2009 16:28:06 -0800 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> Message-ID: imageguy wrote: > On Jan 2, 7:33 pm, John Machin wrote: >> For some very strange definition of "works".... > > Well that's embarrassing ... you are correct. I need to convert from > 'bgr' to 'rgb' If that is the only issue: >>> import Image >>> p = Image.open('~/VPython.png') >>> r, g, b = p.split() >>> q = Image.merge('RGB', [b, r, g]) >>> q.save('~/VPython1.png') Should be plenty fast. Read the PIL docs before rolling your own solutions. --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Sun Jan 4 20:22:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 4 Jan 2009 17:22:00 -0800 (PST) Subject: pep-8 vs. external interfaces? References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> Message-ID: <27c6b149-3a5f-478d-a6fc-da87a66b9d4c@r36g2000prf.googlegroups.com> On Jan 4, 1:47?pm, Roy Smith wrote: > Or, I could draw a line in the sand and say, "If it's a protocol > primitive, it stays as written. ?Otherwise, it's pep-8". ?That's a > little uglier because it's not always obvious to the user exactly > which names are protocol primitives and which are higher-level > operations. So the question becomes, "Why are you mixing protocol primitives and high-level operations in the same namespace?" Because that's not normally a well-advised thing to do. 1. If you answered, "I shouldn't be", you should separate them and use camel case for the protocol primitives. 2. If you answered, "I'm including protocol primitive functions alongside high-level operations because conceptually they are the same, it's just that some functions happen to map directly to the underlying protocol", you should follow PEP-8, because by doing that you've implicity raised the protocol primitive functions to high-level status. 3. If you answered, "Protocol primitives are in the same namespace for convenience, but high-level users shouldn't use them", then you should use camel case for the protocol primitives but prepend an underscore. 4. If you answered, "I include those functions in the same namespace because I am following the example of other language bindings in Perl, Java, Ruby, etc.,", then figure out whether it's important to be consistent with Perl, Java, Ruby, etc., and if so, do whatever they did. If not, see #1. Carl Banks From code at pizzashack.org Sun Jan 4 21:03:11 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 20:03:11 -0600 Subject: why cannot assign to function call In-Reply-To: <6s8s6nF4op56U2@mid.uni-berlin.de> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <20090105020311.GP28417@dragontoe.org> On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that its > > assignment model is BIZARRE, as in it's conceptually different from > > virtually all other languages substantially taught in undergraduate > > computer science programs. > > What's the difference between Python and Java or C# here!? Or are they > also "BIZARRE"!? I am happily ignorant of C#. As for Java, take the following code: a = 6; a = 5; In Python, when you execute the equivalent code, it causes two different objects to spring into existence, the first of which may be cleaned up by the GC (except that since we're using small integers, that's not likely to happen). Unless I'm misinformed (which is very possible, my experience with Java has been extremely limited) in Java that's not the case... the storage is allocated to the name a when you execute its declaration, and the *same storage* is reused upon subsequent assignment. That behaves exactly like named bins. > > And for that matter, it's pretty unintuitive generally. > > Names and objects are quite "natural" IMHO. There are many real world > objects which we attach one or more names to, or refer to in sequences > like "please give me the third book on that shelve" (``shelve[2]``). Indeed, but the way we assign names to them does not behave as it does in Python. Nor does Python's assignment work like it does in algebra, or anywhere else the Python student is particularly likely to have seen variable assignment before encountering it in Python. Let's define intuitive, shall we? From dictionary.com (choosing the definition which most easily makes my point): intuitive: adj. capable of being perceived or known by intuition. I'm going to go out on a limb and assert that there's NO POSSIBLE WAY a student could intuit Python's variable assignment behavior, having never been exposed to that same behavior prior. It needs to be taught. > > That is, in what I'll call "normal" computer languages, a variable name > > is thought of as the address of a bin where some data is stored, and the > > name is inexorably tied to that bin. > > You just call that "normal" or "intuitive" because that's what you > learned first. In a sense, yes... but isn't that what intuition really is? You can figure something out whithout being told how it works... That's either because it's immediately obvious from observing it, or it behaves like something you've seen before. That is what intitive is. > I think the "bin model" is more complex because you don't just have a > name and an object but always that indirection of the "bin". I cheerfully disagree. :) "Named bins" is essentially how algebra works, and how several generations of computer languages, not to mention the actual machine language those generated, behaved, before the current crop. Those interpretations came first, because, much as in the evolution of any other science, that was the model which was most intuitive or easily explained. But you need not take my word for it. Simply read the archives and see for yourself how much confusion this has caused on this list. [Please include the closely related behavior of parameter passing in your search.] -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From cjlesh at gmail.com Sun Jan 4 21:06:44 2009 From: cjlesh at gmail.com (cjl) Date: Sun, 4 Jan 2009 18:06:44 -0800 (PST) Subject: Windows Python install vs. MSI extract question Message-ID: OK -- this might be a strange question. If I do a 'full' install of Python on Windows XP, the result is a directory 'C:\Python25'. Depending on whether I install for all users or just me, the 'python25.dll' might end up in 'C:\Python25', or in the Windows system directory. If I copy python25.dll to the 'C: \Python25' directory, I now should have everything that Python installs all in on spot, correct? Now, if I download the Python installer, create an empty directory 'C: \python' and type the following at the command prompt: msiexec /a python-2.5.4.msi /qb TARGETDIR=C:\python Is there any difference between the folder that resulted from running the installer and the folder that resulted from extracting the MSI? I put together a portable version of Django (www.instantdjango.com), and want to experiment with multiple versions of Python on Windows without running the installer. Besides the changes to the registry and environment variable, am I missing anything when I extract the MSI? Thanks in advance, cjlesh From code at pizzashack.org Sun Jan 4 21:07:51 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 20:07:51 -0600 Subject: why cannot assign to function call In-Reply-To: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <20090105020751.GQ28417@dragontoe.org> On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: > > Or are they also "BIZARRE"!? > > One presumes that Mr. Martin finds anything different from his > first computer language to be BIZARRE. He should try out > Prolog or something genuinely different. One's presumption would be mistaken. However thank you for illustrating my point so precisely, which was after all the condescending and insulting way people "communicate" with people whom (they think) know less than they do in this forum, and not actually how difficult or easy the assignment model of Python is to understand. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From roy at panix.com Sun Jan 4 21:26:05 2009 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jan 2009 21:26:05 -0500 Subject: Code coverage to Python code References: Message-ID: In article , Robert Kern wrote: > Hussein B wrote: > > Hey, > > What is the best code coverage tool available for Python? > > I like Titus Brown's figleaf. > > http://darcs.idyll.org/~t/projects/figleaf/doc/ I was playing with Ned Batchelder's coverage.py module today. Once I stopped screwing around trying to get the "easy install" stuff to work and just copied the danged .py file to my site-packages directory, I was up and running in a few minutes. I suppose there's a lot of bells and whistles you could add, but it ran my code and told me which lines had executed and which hadn't. That pretty much seems like what you want a code coverage tool to do. http://nedbatchelder.com/code/modules/coverage.html From steve at holdenweb.com Sun Jan 4 21:30:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 21:30:20 -0500 Subject: why cannot assign to function call In-Reply-To: <20090105020311.GP28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: >> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: >> >>> On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: >>> What the Python community often overlooks, when this discussion again >>> rears its ugly head (as it seems to every other hour or so), is that its >>> assignment model is BIZARRE, as in it's conceptually different from >>> virtually all other languages substantially taught in undergraduate >>> computer science programs. >> What's the difference between Python and Java or C# here!? Or are they >> also "BIZARRE"!? > > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two > different objects to spring into existence, the first of which may be > cleaned up by the GC (except that since we're using small integers, > that's not likely to happen). Unless I'm misinformed (which is very > possible, my experience with Java has been extremely limited) in Java > that's not the case... the storage is allocated to the name a when > you execute its declaration, and the *same storage* is reused upon > subsequent assignment. > > That behaves exactly like named bins. > Ah, but if the right-hand-side expressions had been Integers rather than integers, things would have been different, no? The point is that once values become complex types it's convenient not to copy them each time they are required. but I needn't flog this particular dead horse as you clearly do understand Python's assignment semantics. >>> And for that matter, it's pretty unintuitive generally. >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. Nor does Python's assignment work like it does in algebra, > or anywhere else the Python student is particularly likely to have > seen variable assignment before encountering it in Python. Let's > define intuitive, shall we? From dictionary.com (choosing the > definition which most easily makes my point): > Algebra contains no assignments. > intuitive: adj. capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > a student could intuit Python's variable assignment behavior, having > never been exposed to that same behavior prior. It needs to be > taught. > As does assignment of any kind. You can't argue that one semantic or another is more intuitive without offering evidence. >>> That is, in what I'll call "normal" computer languages, a variable name >>> is thought of as the address of a bin where some data is stored, and the >>> name is inexorably tied to that bin. >> You just call that "normal" or "intuitive" because that's what you >> learned first. > > In a sense, yes... but isn't that what intuition really is? You can > figure something out whithout being told how it works... That's > either because it's immediately obvious from observing it, or it > behaves like something you've seen before. That is what intitive is. > >> I think the "bin model" is more complex because you don't just have a >> name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, and how several generations of computer languages, not to > mention the actual machine language those generated, behaved, before > the current crop. Those interpretations came first, because, much as > in the evolution of any other science, that was the model which was > most intuitive or easily explained. > You're perhaps familiar with some algebra that I didn't study. In algebra and number theory identity and equality are equivalent. This is far from the case in programming languages, so any analogy based on it is specious to some degree. Programming isn't mathematics (except perhaps for functional programming). > But you need not take my word for it. Simply read the archives and > see for yourself how much confusion this has caused on this list. > [Please include the closely related behavior of parameter passing in > your search.] > It's difficult to think of a single aspect of Python that doesn't cause confusion in a typical year. The confusion is sometimes caused by ill-informed comment. While well-informed, you appear to feel that everyone else should share your idea of what's intuitive and what's BIZARRE. Before extending this thread too long please ruminate on the recent parameter-passing thread, of which you are clearly aware. Let's try and create light rather than heat. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dstanek at dstanek.com Sun Jan 4 22:20:44 2009 From: dstanek at dstanek.com (David Stanek) Date: Sun, 4 Jan 2009 22:20:44 -0500 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: On Sun, Jan 4, 2009 at 9:26 PM, Roy Smith wrote: > In article , > Robert Kern wrote: > >> Hussein B wrote: >> > Hey, >> > What is the best code coverage tool available for Python? >> >> I like Titus Brown's figleaf. >> >> http://darcs.idyll.org/~t/projects/figleaf/doc/ > > I was playing with Ned Batchelder's coverage.py module today. Once I > stopped screwing around trying to get the "easy install" stuff to work and > just copied the danged .py file to my site-packages directory, I was up and > running in a few minutes. > > I suppose there's a lot of bells and whistles you could add, but it ran my > code and told me which lines had executed and which hadn't. That pretty > much seems like what you want a code coverage tool to do. > > http://nedbatchelder.com/code/modules/coverage.html It will show lines as covered when they are executed by the interpreter. Class statements, function definitions, etc. can show up as executed. Are you seeing other code show up as covered? Recently I pushed a branch of an experimental project I am calling Barbarian[0]. It uses nose, figleaf and pylint to generate HTML for a project. A blog post with a more detailed description will be posted within a few days. [0] http://code.launchpad.net/~dstanek/+junk/Barbarian -- David http://www.traceback.org From prologic at shortcircuit.net.au Sun Jan 4 22:29:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 13:29:06 +1000 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: On Sun, Jan 4, 2009 at 9:35 PM, Hussein B wrote: > What is the best code coverage tool available for Python? I like ot use nose with it's coverage plugin. easy_install nose easy_install co And I use the following in my top-level Makefile tests: @nosetests \ --with-coverage \ --cover-package=circuits \ --cover-erase \ --cover-inclusive \ --with-doctest cheers James From jsprad at gmail.com Sun Jan 4 22:47:33 2009 From: jsprad at gmail.com (sprad) Date: Sun, 4 Jan 2009 19:47:33 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 3, 6:41?pm, Steven D'Aprano wrote: > The OP comes from a Perl background, which AFAIK allows you to concat > numbers to strings and add strings to numbers. That's probably the (mis) > feature he was hoping Python had. That's correct -- and that's been one of the more difficult parts of my transition. Learned C++ in college, spent a few years doing Perl, and now all of a sudden type matters again. It's a very different philosophy, but I'm determined to stick with it until I have an Aha! moment and find something I can do more easily than I can with Perl. From grante at visi.com Sun Jan 4 22:56:33 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 04 Jan 2009 21:56:33 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: On 2009-01-05, Derek Martin wrote: > On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: >> > Or are they also "BIZARRE"!? >> >> One presumes that Mr. Martin finds anything different from his >> first computer language to be BIZARRE. He should try out >> Prolog or something genuinely different. > > One's presumption would be mistaken. However thank you for > illustrating my point so precisely, which was after all the > condescending and insulting way people "communicate" with > people whom (they think) know less than they do in this forum, > and not actually how difficult or easy the assignment model of > Python is to understand. I'm sorry, but I really don't see how Python's assignment model could be considered bizarre by anybody who's familiar with more than one or two languages. It's actually somewhat common outside the world of FORTRAN/assembly/C/Pascal. The only thing about Python that ever struck me as odd was the semantic significance of whitespace (and that's not without precedents either). The significance of white-space changed very quickly from odd to brilliant. Among the languages I've known, Python is probably in the bottom 10% as far as bizarrness goes. Lisp/Scheme, Prolog, SNOBOL, COBOL, APL, Forth, Smalltalk and several now-forgotton almost-purely-functional languages all seemed to me orders of magnitude more bizarre than Python. I must admit that a some of those languages (e.g. Forth and Smalltalk) probably felt more "bizarre" due to their developement environment than due to the language itself. And then there is C++ which is bizarre only in the extent to which it's a complete dog's-breakfast. Back to work... -- Grant From roy at panix.com Sun Jan 4 23:03:26 2009 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jan 2009 23:03:26 -0500 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: In article , sprad wrote: > On Jan 3, 6:41?pm, Steven D'Aprano cybersource.com.au> wrote: > > The OP comes from a Perl background, which AFAIK allows you to concat > > numbers to strings and add strings to numbers. That's probably the (mis) > > feature he was hoping Python had. > > That's correct -- and that's been one of the more difficult parts of > my transition. Learned C++ in college, spent a few years doing Perl, > and now all of a sudden type matters again. It's a very different > philosophy, but I'm determined to stick with it until I have an Aha! > moment and find something I can do more easily than I can with Perl. The Aha! moment comes 6 months from now, when you discover that you can understand the Python code you wrote 6 months ago, but the Perl code you wrote at the same time has become gibberish, even to you. The other day, I came upon this gem. It's a bit of perl embedded in a Makefile; this makes it even more gnarly because all the $'s get doubled to hide them from make: define absmondir $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print \\\$$1}"`; chomp($$prefix); \ ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! ); } \ ?? return unslash(undot(undotdot($$a))); }; \ sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; return($$_[0]); }; \ sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ sub undotdot ($$) { my $$in = $$_[0]; \ ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ print absmon("$(1)","$(2)"); \ ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? endef Barf-o-rama. I know what it's supposed to do, and I still can't figure it out. From prologic at shortcircuit.net.au Sun Jan 4 23:17:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 14:17:06 +1000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jan 5, 2009 at 1:47 PM, sprad wrote: > On Jan 3, 6:41 pm, Steven D'Aprano cybersource.com.au> wrote: >> The OP comes from a Perl background, which AFAIK allows you to concat >> numbers to strings and add strings to numbers. That's probably the (mis) >> feature he was hoping Python had. I guess perl must have coercing for it's built-in types ? :) *shrugs* To be honest, doing such operations doesn't make much sense to me ... It's difficult to correctly understand what the following expression should evaluate to: >>> a = 2 >>> b = 3 >>> c = "foo" >>> a + b + c Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> "%d %d %s" % (a, b, c) '2 3 foo' >>> > That's correct -- and that's been one of the more difficult parts of > my transition. Learned C++ in college, spent a few years doing Perl, > and now all of a sudden type matters again. It's a very different > philosophy, but I'm determined to stick with it until I have an Aha! > moment and find something I can do more easily than I can with Perl. As mentioned string formatting is your friend :) cheers James From code at pizzashack.org Sun Jan 4 23:55:09 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 22:55:09 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <20090105045509.GR28417@dragontoe.org> On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > > a student could intuit Python's variable assignment behavior, having > > never been exposed to that same behavior prior. It needs to be > > taught. > > > As does assignment of any kind. I'm not sure that's true. Having taken algebra prior to learning Basic, I intuitively understood what this program would do when I executed it, the first time I saw the code, and before I read the explanation: 10 let x = 10 20 print x [Well, to be honest it's been a very long time since I've programmed in Pet BASIC, and the syntax may be wrong. The point is, just as I did then, I am positive that you intuitively understand what the above is intended to do, even if it is not valid BASIC syntax -- because if you did not, we would not be having this discussion.] > You can't argue that one semantic or another is more intuitive > without offering evidence. I think I have though, not that it matters, since that was never really my point. Python's assignment model requires more explanation than the traditional one, simply to state what it does. That alone is evidence (but not proof). I haven't proven it scientifically, and I'm not willing to jump through the necessary hoops (which would require a psychological study) to do so simply to win an argument on Usenet. It's not about winning... it's about illumination. ;-) > You're perhaps familiar with some algebra that I didn't study. Not unless you never studied it at all... ;-) > In algebra and number theory identity and equality are equivalent. Indeed. The point of bringing up algebra is that it provides a background against which someone might be very likely to intuit what variable assignment does in traditional programming languages -- at least accurately enough to use it effectively without needing to understand the underlying implementation and worry about any corner cases. It really doesn't need to be explained, unless the student has no prior background in either math or computers. In the case of passing parameters things unavoidably get hairy, but at least at the moment we're not discussing that, and also that has no analogous in (at least high school) mathematics (at least, that I can think of) or much of anywhere else from whence a student might draw any insights. As for there being no assignment in algebra, is that not really what variable substitution is? They have different names, but in my estimation they perform exactly the same function. You're assigning specific values to the variables in an expression so that you can solve for a constant... just like in a computer program. There is even an allocation of memory: it's in your brain. :D > This is far from the case in programming languages, so any analogy > based on it is specious to some degree. Programming isn't > mathematics (except perhaps for functional programming). I agree; but I wasn't making an analogy. I was pointing out (an extremely likely) basis for intuition. > It's difficult to think of a single aspect of Python that doesn't cause > confusion in a typical year. Surely some cause more than others... and surely some are more surprising than others. ;-) > The confusion is sometimes caused by ill-informed comment. While > well-informed, you appear to feel that everyone else should share > your idea of what's intuitive and what's BIZARRE. Alright, perhaps I exaggerated when I said bizarre, but I did explain exactly what I meant, and I believe that what I said in my explanation is at least arguably true. I stand by the idea that it's much less intuitive than the traditional assignment model, and despite your protestations of lack of proof, I'm pretty sure you agree. ;-) Ultimately, none of this really matters, as perhaps my point is that Python *is different* from what A LOT of folks learning it have already seen (if anything), and it's often easy for them to misunderstand the Python way. As you said, let's provide light, not heat, when we come across people who get confused between Python and something else. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From code at pizzashack.org Mon Jan 5 00:09:27 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 23:09:27 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <20090105050927.GS28417@dragontoe.org> On Sun, Jan 04, 2009 at 09:56:33PM -0600, Grant Edwards wrote: > On 2009-01-05, Derek Martin wrote: > > On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: > >> One presumes that Mr. Martin finds anything different from his > >> first computer language to be BIZARRE. He should try out > >> Prolog or something genuinely different. > > > > One's presumption would be mistaken. However thank you for > > illustrating my point so precisely, which was after all the > > condescending and insulting way people "communicate" with > > people whom (they think) know less than they do in this forum, > > and not actually how difficult or easy the assignment model of > > Python is to understand. > > I'm sorry, but I really don't see how Python's assignment model > could be considered bizarre by anybody who's familiar with more > than one or two languages. And... what if one wasn't? The OP of this thread clearly didn't understand... Whereas if you've read the thread, clearly I do. Of course, had you read my post, you probably would have understood that my comment about the model being bizarre was intended to be viewed from the perspective of someone who *had not* seen anything like it before, which is LOTS of relatively new programmers, whether or not it might be old hat to anyone here. The ultimate point of my post was not so much about whether the assignment model of Python was or wasn't easy to understand; it was about the idea that when someone doesn't understand, we should try to help them instead of making snide remarks about how stupid or small-minded they are. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From code at pizzashack.org Mon Jan 5 00:27:31 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 23:27:31 -0600 Subject: why cannot assign to function call In-Reply-To: <20090105045509.GR28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> <20090105045509.GR28417@dragontoe.org> Message-ID: <20090105052731.GT28417@dragontoe.org> Forgive my indulgence, I find this rather academic discussion kind of interesting, as it turns out. On Sun, Jan 04, 2009 at 10:55:09PM -0600, Derek Martin wrote: > > You can't argue that one semantic or another is more intuitive > > without offering evidence. > > I think I have though, not that it matters, since that was never > really my point. Python's assignment model requires more explanation > than the traditional one, simply to state what it does. That alone is > evidence (but not proof). Here's (I think) a better argument, FWIW: The traditional model ties a name to some (usually predefined and static) storage (a memory address, or at least the start of a string of them). This is a very concrete thing to represent, and the conceptualization of variables as named bins in such languages captures this very succinctly, and requires no understanding of the underlying implementation for the programmer to use (at least with primitive data types, which are all that are used generally when variables are first introduced). The Python model binds a name to a particular Python object, which is itself an abstraction; understanding requires understanding first what an "object" is, and I think at least in some measure some knowledge about how Python is implemented (primitive data types are actually objects; and also recall the recent discussion about what constitutes a "value" in Python). The abstraction, and the requirement to partially understand the underlying implemenation, make the Python model inherently more complicated, and therefore also inherently less intuitive. That also is not proof, but as I said, real proof is rather hard to come by... And FWIW, remember that I never suggested that all this was without good reason, and I'm not attempting to advocate for simplifying the model. :) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aleksandr.goretoy at gmail.com Mon Jan 5 01:00:50 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 06:00:50 +0000 Subject: threading a 10 lines out of a file Message-ID: Hello All, I have a question. I'm not sure exactly as how to explain it in any other way then the way I will explain it. So I'm sorry if it's hard to understand exactly what it is I'm trying to do. Maybe not. Anyway. Here goes. Lets say I have a file that looks like this. id,name,desc,test 123,abc,testing is fun,yeah baby 456,qwe,python makes if funner, yeah baby 789,zxc,this is another line in this file, yeah baby ... ... This file can have an unknown amount of lines in it. It can be 700,400 or even 7,000. I do this to read the file: try: reader = csv.reader(file(filename, "rb")) try: header = reader.next() self.buffer = list(reader) # total = len(self.buffer) self.bufferp= [dict(zip(header,line)) for line in self.buffer] self.header = header #for row in reader: #self.buffer.append(row) #s,a=[],{} #for j in range(len(self.buffer[0])): #a[self.buffer[0][j]]=row[j] #self.bufferp.append(a) #i+=1 #self.total = i-1 except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) except IOError, e: sys.exit('file %s, IOError: %s' % (filename, e)) What I am currently doing is looping over this file, performing a function for every line. This function isbeing called from this class __init__(), def loop_lines(self): for k in range(len(self.buffer)): #for every line in csv file self.line=self.buffer[k] self.some_function(self.line) Now, for my question. Is it possible for me to thread this scenario somehow? So that I can set a variable that says how many lines to work on at the same time? lets say 10 lines at a time, once it finishes some it moves on to the next ones that are not in the thread pool or something to that nature. Always making sure that it works on 10 at the same time. How would I achieve something like this in my program? Can someone please recommend something for me. I would greatly appreciate. My program would appreciate it too, seeing as it will be multi-threaded :) Thank you for your help. -Alex Goretoy http://www.alexgoretoy.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From grante at visi.com Mon Jan 5 02:13:48 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 01:13:48 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> On 2009-01-05, Derek Martin wrote: >> I'm sorry, but I really don't see how Python's assignment >> model could be considered bizarre by anybody who's familiar >> with more than one or two languages. > > And... what if one wasn't? The OP of this thread clearly > didn't understand... Whereas if you've read the thread, > clearly I do. Of course, had you read my post, you probably > would have understood that my comment about the model being > bizarre was intended to be viewed from the perspective of > someone who *had not* seen anything like it before, X is bizarre because it is unfamiliar to anybody who has never seen X before? -- Grant From nospam at nospam.com Mon Jan 5 02:15:38 2009 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 05 Jan 2009 08:15:38 +0100 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' Message-ID: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Hello I successfully use the email package to send e-mail from Python scripts, but this script fails when I fetch addresses from an SQLite database where data is Unicode-encoded: ====== from email.MIMEText import MIMEText import smtplib,sys import apsw connection=apsw.Connection("test.sqlite") cursor=connection.cursor() subject = "My subject" f = open("message.txt", "r") message = f.read() f.close() msg = MIMEText(message) msg['Subject'] = subject >From = "me at acme.com" msg['From'] = From server = smtplib.SMTP("smtp.acme.com") sql="SELECT email FROM people WHERE email IS NOT NULL" rows=list(cursor.execute(sql)) for email in rows: To = email msg['To'] = email #print To #(u'dummy at acme.com',) #AttributeError: 'tuple' object has no attribute 'lstrip' #server.sendmail(From,[To],msg.as_string()) server.quit connection.close(True) ====== Does someone know what is wrong with the above? Does email choke on Unicode? Thank you. From aleksandr.goretoy at gmail.com Mon Jan 5 02:22:33 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 07:22:33 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: I've found a great example on how to do threads. It compares a ping program in regular for loop and with threaded for loop. The link is below if anyone is interested. http://www.wellho.net/solutions/python-python-threads-a-first-example.html I hope my eagerness to post doesn't annoy anyone. I like to get as much info from as many places as possible and compare. This way I think I may have a better solution for a problem. Plus people that Google will find this post or any words in it. Any more information on threading a for loop would be greatly appreciated. TIA -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:00 AM, alex goretoy wrote: > Hello All, > > I have a question. I'm not sure exactly as how to explain it in any other > way then the way I will explain it. So I'm sorry if it's hard to understand > exactly what it is I'm trying to do. Maybe not. Anyway. Here goes. > > Lets say I have a file that looks like this. > > id,name,desc,test > 123,abc,testing is fun,yeah baby > 456,qwe,python makes if funner, yeah baby > 789,zxc,this is another line in this file, yeah baby > ... > ... > > This file can have an unknown amount of lines in it. It can be 700,400 or > even 7,000. > I do this to read the file: > > try: > reader = csv.reader(file(filename, "rb")) > try: > header = reader.next() > self.buffer = list(reader) # total = len(self.buffer) > self.bufferp= [dict(zip(header,line)) for line in > self.buffer] > self.header = header > #for row in reader: > #self.buffer.append(row) > #s,a=[],{} > > #for j in range(len(self.buffer[0])): > #a[self.buffer[0][j]]=row[j] > #self.bufferp.append(a) > #i+=1 > #self.total = i-1 > except csv.Error, e: > sys.exit('file %s, line %d: %s' % (filename, > reader.line_num, e)) > except IOError, e: > sys.exit('file %s, IOError: %s' % (filename, e)) > > What I am currently doing is looping over this file, performing a function > for every line. This function isbeing called from this class __init__(), > > def loop_lines(self): > > for k in range(len(self.buffer)): #for every line in csv file > self.line=self.buffer[k] > self.some_function(self.line) > > > Now, for my question. Is it possible for me to thread this scenario > somehow? > > So that I can set a variable that says how many lines to work on at the > same time? > > lets say 10 lines at a time, once it finishes some it moves on to the next > ones that are not in the thread pool or something to that nature. Always > making sure that it works on 10 at the same time. > > How would I achieve something like this in my program? Can someone please > recommend something for me. I would greatly appreciate. My program would > appreciate it too, seeing as it will be multi-threaded :) Thank you for your > help. > > -Alex Goretoy > http://www.alexgoretoy.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp at rebertia.com Mon Jan 5 02:24:16 2009 From: clp at rebertia.com (Chris Rebert) Date: Sun, 4 Jan 2009 23:24:16 -0800 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' In-Reply-To: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: <47c890dc0901042324uee73cc7yf1a9d9492eca2086@mail.gmail.com> On Sun, Jan 4, 2009 at 11:15 PM, Gilles Ganault wrote: > Hello > > I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject > >From = "me at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > To = email > msg['To'] = email > > #print To > #(u'dummy at acme.com',) > > #AttributeError: 'tuple' object has no attribute 'lstrip' > #server.sendmail(From,[To],msg.as_string()) > > server.quit > > connection.close(True) > ====== > > Does someone know what is wrong with the above? Does email choke on > Unicode? Please include the full Traceback so that you can be helped more easily. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 02:47:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 07:47:11 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> Message-ID: On Mon, 05 Jan 2009 01:13:48 -0600, Grant Edwards wrote: > On 2009-01-05, Derek Martin wrote: > >>> I'm sorry, but I really don't see how Python's assignment model could >>> be considered bizarre by anybody who's familiar with more than one or >>> two languages. >> >> And... what if one wasn't? The OP of this thread clearly didn't >> understand... Whereas if you've read the thread, clearly I do. Of >> course, had you read my post, you probably would have understood that >> my comment about the model being bizarre was intended to be viewed from >> the perspective of someone who *had not* seen anything like it before, > > X is bizarre because it is unfamiliar to anybody who has never seen X > before? Bizarre: "conspicuously or grossly unconventional or unusual". The bizarre is contingent on what people consider familiar, and naturally if you've never seen X or anything like X before, you will find it unfamiliar and likely bizarre. There's no shame in finding spaghetti alla vongole bizarre if you've never seen noodles or clams before. What is shameful is the refusal to consider that just because it is bizarre to *you* doesn't mean that it is bizarre to anyone else, and that your sense of bizarreness probably reflects more your ignorance of the wide range of edible dishes than anything strange about the food itself. (On the other hand, maggot cheese really is bizarre. http://en.wikipedia.org/wiki/Casu_marzu ) By all means, if Derek doesn't like the assignment model used by Python (and Java, Ruby, C#, Perl, RealBasic, VisualBasic, Lua, and many other languages going back to at least CLU in the mid 1970s) he's free to say so. There are plenty of other languages out there, and perhaps he will find one that he likes. Or he will continue to use Python, hating every minute of it. Or perhaps he'll even come to like the assignment model, and wonder how he ever could have found it bizarre. But it's rather rich for him to claim that his subjective feelings about Python's assignment model should be treated as objective fact. -- Steven From kay.schluehr at gmx.net Mon Jan 5 02:56:26 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sun, 4 Jan 2009 23:56:26 -0800 (PST) Subject: Code coverage to Python code References: Message-ID: <21c3085b-927d-4577-a04f-0b362ead66b1@f3g2000vbf.googlegroups.com> On 4 Jan., 12:35, Hussein B wrote: > Hey, > What is the best code coverage tool available for Python? > Thanks. It depends. What are your requirements? From sjmachin at lexicon.net Mon Jan 5 03:12:54 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 5 Jan 2009 00:12:54 -0800 (PST) Subject: AttributeError: 'tuple' object has no attribute 'lstrip' References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: On Jan 5, 6:15?pm, Gilles Ganault wrote: > Hello > > ? ? ? ? I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject > From = "m... at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > ? ? ? ? To = email > ? ? ? ? msg['To'] = email > > ? ? ? ? #print To > ? ? ? ? #(u'du... at acme.com',) That looks like a tuple to me. What does it look like to you? > > ? ? ? ? #AttributeError: 'tuple' object has no attribute 'lstrip' > ? ? ? ? #server.sendmail(From,[To],msg.as_string()) When are asking for help, could you *PLEASE* supply the actual code that you ran, with the actual output, and (just in case the problem is not otherwise screamingly obvious) the *FULL* traceback? The to_addrs arg of SMTP.sendmail() should be a single string, or a list of strings. You have supplied [(u'du... at acme.com',)] which is a list containing one tuple. That tuple is a result of your SQL query, which has returned a 1-column row as a tuple (as expected/documented). SMTP.sendmail() treats your tuple as though it were a string, and consequently an exception is raised. > server.quit Should that perhaps be server.quit() ? > Does email choke on Unicode? I've got no idea; I've never used email or smtplib. Why don't you feed them some Unicode and find out? Also consider having a look at the manual. HTH, John From max at alcyone.com Mon Jan 5 03:28:43 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 05 Jan 2009 00:28:43 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: >>> I'm going to go out on a limb and assert that there's NO POSSIBLE WAY >>> a student could intuit Python's variable assignment behavior, having >>> never been exposed to that same behavior prior. It needs to be >>> taught. >>> >> As does assignment of any kind. > > I'm not sure that's true. Having taken algebra prior to learning Basic, > I intuitively understood what this program would do when I executed > it, the first time I saw the code, and before I read the explanation: > > 10 let x = 10 > 20 print x Did you understand that the first time you saw the statement in BASIC: X = X + 1 the = symbol couldn't possibly have the same meaning as it does in algebra? In BASIC, this is a statement which replaces the value of a variable X with the previous value, incremented by one. In algebra, this is an equation which has no solutions, since it reduces to 0 = 1, an equation which is inconsistent. The two things aren't even related. That is the whole point here. Computer science and programming languages have objects. Mathematics has no such concept whatsoever, unless you wish to define one. You're welcome to do so with a rigorous definition that you can publish papers about and decide whether other mathematicians are interested in your line of reasoning, but pretending that there is a natural overlap between the mathematical concepts of equality and identity and the computer scientific ones (especially since the term _identity_ isn't even used in remotely the same way) is simply ignoring the fact that other people either won't know what you mean or will presume you're misunderstanding something. Because, based on your previous comments, you are. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Do we ask what profit the little bird hopes for in singing? -- Johannes Kepler, 1571-1630 From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 03:41:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 08:41:08 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two different > objects to spring into existence, the first of which may be cleaned up > by the GC (except that since we're using small integers, that's not > likely to happen). Unless I'm misinformed (which is very possible, my > experience with Java has been extremely limited) in Java that's not the > case... the storage is allocated to the name a when you execute its > declaration, and the *same storage* is reused upon subsequent > assignment. > > That behaves exactly like named bins. In the case of Java, that's because Java uses two assignment models: named bins for "primitives" like ints and floats, and the Python model for class instances, which is *nearly* everything in Java except a few primitive types. >> > And for that matter, it's pretty unintuitive generally. >> >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. It doesn't? Oh my, you're going to be confused in a few weeks when The President of the USA ceases to be George W Bush and becomes Barack Obama. Same name (or rather, title), different object (person). > Nor does Python's assignment work like it does in algebra, Nor does any programming language, with the possible exception of computer algebra systems. > or anywhere else the Python student is particularly likely to have seen > variable assignment before encountering it in Python. Let's define > intuitive, shall we? From dictionary.com (choosing the definition which > most easily makes my point): > > intuitive: adj. capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY a > student could intuit Python's variable assignment behavior, having never > been exposed to that same behavior prior. Unless they've used Java, Perl, Ruby, or any number of other languages. > It needs to be taught. Exactly the same as the named bins assignment model needs to be taught. But, really, you're exaggerating the differences. There are differences of course, but for somebody writing a simple programming with (say) mathematical expressions, there's little or no difference between the models. x = 4 if y > 2: x = x-1 else: x = x+1 print x+y will have the same effect whether you are using the named bins model or not. [...] > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, I don't think so. Variables in algebra are quite different from variables in programming languages. Contrast the statement: x = x+1 as a programming expression and an algebraic equation. As a programming expression, it means "increment x by one". But as an algebraic expression, it means "x is some value such that it is equal to one more than itself", and there is no solution to such an equation. In algebra, a variable name (like x, or c) generally represents one of three things: (1) an an unknown quantity to be solved for; (2) a constant (either a known constant, or an arbitrary parameter); or (3) an alias, such as when you do a change-of-variable. One thing which algebraic variables are not is a bucket or bin that you can set to some value, then modify over and over again. > and how several generations of computer languages, not to mention > the actual machine language those generated, behaved, before the current > crop. Sure. And? > Those interpretations came first, because, much as in the > evolution of any other science, that was the model which was most > intuitive or easily explained. No no no no. That was the model that was most easily implemented! Before the named bins model of assignment was pure machine code, where you didn't have bins at all, just bits, and there was no distinction between code and data. And before that was *wires* -- early programmers literally had to plug and unplug wires to change the state of the computer. And before that were purely mechanical devices, such as the Enigma Machine, old calculators, and the grand-daddy of them all, Charles Babbage's difference engine and it's precursors. > But you need not take my word for it. Simply read the archives and see > for yourself how much confusion this has caused on this list. [Please > include the closely related behavior of parameter passing in your > search.] In my opinion, the cause of that confusion is nothing to do with Python's assignment model, and everything to do with the instance of some people to use named bins terminology when describing the Python model. If you keep the named bins terminology for describing the named bins model, you're fine; and if you keep the name/object terminology for describing languages with names/objects, you're fine. You only run into trouble when you mix them. That's when you get people confused because "Python is Call By Something, but it doesn't behave like Call By Something in language Foo I've used before". -- Steven From workingpad at gmail.com Mon Jan 5 04:47:09 2009 From: workingpad at gmail.com (Jack.Chu) Date: Mon, 5 Jan 2009 01:47:09 -0800 (PST) Subject: My last working day of 2007 Message-ID: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Hello guys: I created a simple tool to count how I wasted my time day by day ;-) http://www.flickr.com/photos/34017270 at N07/3169438647/sizes/o/ It's simple, a small program running on background, logging the title of foreground window. A python script parses the log file and then generates chart by matplotlib. I just want to get suggestions to improve it, or know the news that somebody had implemented a better one so I can abandon my toy. thanks. From vedrandekovic at gmail.com Mon Jan 5 04:53:11 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Mon, 5 Jan 2009 01:53:11 -0800 (PST) Subject: Python stack and heap Message-ID: <33b05bc0-d4f3-4fde-94bc-8b996f5a1266@f24g2000vbf.googlegroups.com> Hello, Does anybody know how can I get usage of stack or/heap memory in Python on Windows XP? Regards, Vedran From matrixhasu at gmail.com Mon Jan 5 04:57:48 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Mon, 5 Jan 2009 01:57:48 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? Message-ID: Hello and Happy 2009! I received the interesting proposal to author a book on Matplotlib, the powerful 2D plotting library for Python. While preparing the arguments list, I'd like to hear even your opinion, because different points-of-view will lead to a better product. Some basic question I'd like to ask are: - what are you using matplotlib for? - what are the things you like the most of matplotlib, that you want to give emphasis to? And why? - what are the (basic) things that, when you were beginning to use matplotlib, you wanted to see grouped up but couldn't find? - what would you like to see in a book about matplotlib? - what are some those advanced feature that made you yell "WOW!!" ? - what are the things you'd like to explore of matplotlib and never had time to do? Your suggestions are really appreciated :) And wish me good luck! From ssalam at gmail.com Mon Jan 5 05:00:08 2009 From: ssalam at gmail.com (Shah Alam) Date: Mon, 5 Jan 2009 02:00:08 -0800 (PST) Subject: Switching user in a SSH connection References: Message-ID: On Jan 2, 2:22?pm, Tino Wildenhain wrote: > Shah Sultan Alam wrote: > > Hi Group, > > ?I am trying to connect to a Linux maching using paramiko. > > ?and able to run a command like "ls -l" > > > ?Now I want to switch user being in the connection ( eg running > > something like "su -" ) > > > Will you please let me know how to do that. > > You would for example run su - in that connection? Or sudo if > installed and configured. > > What else would you need? > > Tino. > > ?smime.p7s > 4KViewDownload I am trying to run su - on that connection.. sudo is not configured From huwdjones at gmail.com Mon Jan 5 05:01:37 2009 From: huwdjones at gmail.com (huw_at1) Date: Mon, 5 Jan 2009 02:01:37 -0800 (PST) Subject: cx_Oracle issues References: <5b2dad81-2750-4347-8079-6ab31321d579@s1g2000prg.googlegroups.com> <9142a8f1-7f76-4fc0-9ca1-c9dec310f2ce@r37g2000prr.googlegroups.com> <9f436c9e-2319-499c-a306-d255996372fc@e22g2000vbe.googlegroups.com> <09b53231-5a92-437c-859b-6e5d0ce106c8@k36g2000pri.googlegroups.com> <75a97df3-7ee9-41ce-9f10-e525c42a7653@e18g2000vbe.googlegroups.com> Message-ID: On Dec 18 2008, 10:34?am, huw_at1 wrote: > On Dec 16, 12:17?pm, huw_at1 wrote: > > > > > On Dec 15, 12:59?pm, "ron.re... at gmail.com" > > wrote: > > > > On Dec 15, 2:44?am, huw_at1 wrote: > > > > > On Dec 11, 5:34?pm, "ron.re... at gmail.com" wrote: > > > > > > On Dec 10, 9:48?am, huw_at1 wrote: > > > > > > > Hey all. When usingcx_Oracleto run a procedure like: > > > > > > > cursor.execute("select (obj.function(value)) from table where > > > > > > id=blah") > > > > > > > I am getting the following error: > > > > > > > ORA-06502: PL/SQL: numeric or value error: character string buffer too > > > > > > small ORA-06512: at line 1 > > > > > > > Looking at cursor.description I get: > > > > > > > [('(obj.function(value))', , 4000, 4000, 0, > > > > > > 0, 1)] > > > > > > > Any tips - i have never seen this error before but am guessing that > > > > > > the value being returned is too big for the buffer size set for the > > > > > > cursor. the procedure fetches data from a LOB. > > > > > > > Any suggestions/confirmations? > > > > > > > Many thanks > > > > > > This error is a problem with the PL/SQL, notcx_Oracle. ?You need to > > > > > debug obj.function to see what kind of data is being accessed and then > > > > > a data analysis of that data to understand why this error occurs. ?I > > > > > can tell you the function is most likely expecting characters from a > > > > > column that are numeric [0 .. 9] and is getting alpha characters. > > > > > > -- > > > > > Ron Reidy > > > > > Sr. Oracle DBA > > > > > Hi thanks for the responses. Unfortunately the procedure in question > > > > is from a third party vendor so I can't really debug it so I'd say I > > > > was fairly stumped. Just out of interest how do you increase the > > > > output buffer size withcx_Oracle? > > > > > Many thanks- Hide quoted text - > > > > > - Show quoted text - > > > > Hi, > > > > Sure you can. ?You can see the PL/SQL source from the ditionary view > > > ALL_SOURCE: > > > select text from all_source where name = 'NAME_OF_FUNCTION'; > > > > From there, reverse engineeer which table(s) and column(s) are being > > > accesses and do the data analysis. > > > > -- > > > Ron Reidy > > > Hi all, > > > So I tried Rons query but unfortunately I got 0 records returned. > > However I can confirm that running the select query from a client does > > indeed generate the same error. Is there anything else I could try? > > Otherwise I'll just get in touch with the vendor I guess. > > Hi again. A further update to theseissuesis that I found some java > executable which seemed to execute the SQL query without hitch. My > Java isn't great but from what I could make out it seems that the > query is broken down from: > > select (obj.function(value)) from table where id=blah > > to: > > select value from table where id=blah > > obj.function(value) > > So make two queries. In the first retrieve the BLOB (value) and store > it in a java.sql.blob object. Then pass this back in to the stored > procedure. I'm a bit puzzled as to why this way would work over just > performing the straight select statement. Culd it be the jdbc > connector handles BLOBs better? Anyway I was wondering if I could > implement something similar usingcx_Oracle. however I am a bit stuck > on how to pass a BLOB in to the second query - specifically: > > cursor.execute(obj.function(value)) > > where value is the BLOB. I get an error: > > cx_Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data > typecx_Oracle.LOB > > So I wonder if I need to set something for the input type but I do not > know how to do this. > > Any suggestions? > > Many thanks again. Hi there. Any suggestions? I'm still a bit stuck on this one? Cheers From bj_666 at gmx.net Mon Jan 5 05:37:53 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 5 Jan 2009 10:37:53 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <6se680F5fbrrU1@mid.uni-berlin.de> On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch > wrote: >> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: >> >> What's the difference between Python and Java or C# here!? Or are they >> also "BIZARRE"!? > > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two different > objects to spring into existence, the first of which may be cleaned up > by the GC (except that since we're using small integers, that's not > likely to happen). Unless I'm misinformed (which is very possible, my > experience with Java has been extremely limited) in Java that's not the > case... the storage is allocated to the name a when you execute its > declaration, and the *same storage* is reused upon subsequent > assignment. > > That behaves exactly like named bins. So does the equivalent in Python. Or to see it the other way: In both languages it *behaves* like (re)binding the name `a` to two different objects. So it is an implementation detail. Even a Python implementation could reuse the same memory location to store the two numbers. >> > And for that matter, it's pretty unintuitive generally. >> >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. In what way? >> I think the "bin model" is more complex because you don't just have a >> name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, No it isn't. Mathematics is about binding names and not about putting values into bins. And a mathematical variable can't be rebound once you assigned a value to it. The "intuitive" model for people with a math background would be that of functional languages like Haskell, which is even more strange for people used to "named bins" than the Python, Java, Ruby, ? approach. > and how several generations of computer languages, not to mention > the actual machine language those generated, behaved, before the current > crop. Those interpretations came first, because, much as in the > evolution of any other science, that was the model which was most > intuitive or easily explained. In terms of the underlying machine, but that is exactly what I meant by the additional indirection of the bins. You just have to drag the low level named bins into the explanation because it is an implementation detail of the languages. And there where always languages that use a model like Python parallel to the "named bins languages", it is nothing new. Ciao, Marc 'BlackJack' Rintsch From phil at freehackers.org Mon Jan 5 06:05:32 2009 From: phil at freehackers.org (BlueBird) Date: Mon, 5 Jan 2009 03:05:32 -0800 (PST) Subject: How to "kill" orphaned threads at program exit References: Message-ID: <69d64bbe-792d-4ec9-b422-bab1886f161f@q30g2000prq.googlegroups.com> On Dec 28 2008, 6:33?pm, "Giampaolo Rodola'" wrote: > Hi, > I know that it's not possible to "kill" threads but I'm wondering if > does exist some workaround for my problem. > I have a test suite which does a massive usage of threads. > Sometimes happens that one test fails, the test suite keeps running > until the end, and when it's finished the program hangs on and the > only way to stop is to kill it manually. > I noticed that, at the end of the program, I can call > threading.enumerate() and see the pending thread objects: > Hi, The way I handle it is to make sure that after each test, the thread count has returned to what I expect. It is possible to kill a thread if it's not blocked on a system call. It's highly unrecommended for standard usage but your use case exactly the one where the ability to kill a thread is very useful. I use the following code, which I borrowed to the Python Cook book somewhere: def _async_raise(tid, exctype): '''Raises an exception in the threads with id tid''' if not inspect.isclass(exctype): raise TypeError("Only types can be raised (not instances)") res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("invalid thread id") elif res != 1: # """if it returns a number greater than one, you're in trouble, # and you should call it again with exc=NULL to revert the effect""" ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0) raise SystemError("PyThreadState_SetAsyncExc failed") class ThreadWithExc(threading.Thread): '''A thread class that supports raising exception in the thread from another thread. ''' def _get_my_tid(self): """determines this (self's) thread id CAREFUL : this function is executed in the context of the caller thread, to get the identity of the thread represented by this instance. """ if not self.isAlive(): raise threading.ThreadError("the thread is not active") # do we have it cached? if hasattr(self, "_thread_id"): return self._thread_id # no, look for it in the _active dict for tid, tobj in threading._active.items(): if tobj is self: self._thread_id = tid return tid # TODO : in python 2.6, there's a simpler way to do : self.ident ... raise AssertionError("could not determine the thread's id") def raiseExc(self, exctype): """Raises the given exception type in the context of this thread. If the thread is busy in a system call (time.sleep(), socket.accept(), ...) the exception is simply ignored. If you are sure that your exception should terminate the thread, one way to ensure that it works is: t = ThreadWithExc( ... ) ... t.raiseExc( SomeException ) while t.isAlive(): time.sleep( 0.1 ) t.raiseExc( SomeException ) If the exception is to be caught by the thread, you need a way to check that your thread has caught it. CAREFUL : this function is executed in the context of the caller thread, to raise an excpetion in the context of the thread represented by this instance. """ _async_raise( self._get_my_tid(), exctype ) cheers, Philippe From bj_666 at gmx.net Mon Jan 5 06:15:12 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 5 Jan 2009 11:15:12 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <6se8e0F5fbrrU2@mid.uni-berlin.de> On Sun, 04 Jan 2009 22:55:09 -0600, Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: >> > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY >> > a student could intuit Python's variable assignment behavior, having >> > never been exposed to that same behavior prior. It needs to be >> > taught. >> > >> As does assignment of any kind. > > I'm not sure that's true. Having taken algebra prior to learning Basic, > I intuitively understood what this program would do when I executed it, > the first time I saw the code, and before I read the explanation: > > 10 let x = 10 > 20 print x Do you really thought of `x` as a named memory location where the bit pattern for the floating point value 10 is stored, with just the algebra knowledge!? Isn't "Ah there the name `x` is bound to the value 10." more likely? As it is the technically easier and IMHO more intuitive explanation when you go from math to programming. > [Well, to be honest it's been a very long time since I've programmed in > Pet BASIC, and the syntax may be wrong. The point is, just as I did > then, I am positive that you intuitively understand what the above is > intended to do, even if it is not valid BASIC syntax -- because if you > did not, we would not be having this discussion.] Syntax is correct. :-) The ``let`` is optional in Commodore BASIC. But where is the difference to x = 10 print x ? Wouldn't you have guessed what this Python program will do just the same? Ciao, Marc 'BlackJack' Rintsch From lipun4u at gmail.com Mon Jan 5 06:37:31 2009 From: lipun4u at gmail.com (asit) Date: Mon, 5 Jan 2009 03:37:31 -0800 (PST) Subject: fetch image Message-ID: <43df25e3-8b98-4468-8e9c-e02e0e3d978e@p2g2000prf.googlegroups.com> import httplib class Server: #server class def __init__(self, host): self.host = host def fetch(self, path): http = httplib.HTTPConnection(self.host) http.request("GET", path) r = http.getresponse() print str(r.status) + " : " + r.reason server = Server("www.python.org") fp=open("phpvuln.txt") x=fp.readlines(); for y in x: server.fetch("/" + y); The above code fetches only the html source of the webpage. How to get the image, flash animation and other stuffs ???? From deets at nospam.web.de Mon Jan 5 06:41:26 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 05 Jan 2009 12:41:26 +0100 Subject: fetch image References: <43df25e3-8b98-4468-8e9c-e02e0e3d978e@p2g2000prf.googlegroups.com> Message-ID: <6se9v6F56eioU1@mid.uni-berlin.de> asit wrote: > import httplib > > class Server: > #server class > def __init__(self, host): > self.host = host > def fetch(self, path): > http = httplib.HTTPConnection(self.host) > http.request("GET", path) > r = http.getresponse() > print str(r.status) + " : " + r.reason > > server = Server("www.python.org") > fp=open("phpvuln.txt") > x=fp.readlines(); > for y in x: > server.fetch("/" + y); > > The above code fetches only the html source of the webpage. How to get > the image, flash animation and other stuffs ???? By parsing the result, extracting img-tags and others that contain references, and fetching these explicitly. The keywords on this for successful search are "python" and "crawling" or "crawler". There are some out there, e.g. here: http://weblab.infosci.cornell.edu/documentation/webbackscript Diez From tmohr at s.netic.de Mon Jan 5 07:12:57 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 05 Jan 2009 13:12:57 +0100 Subject: structuring a package? References: Message-ID: Hello James, >> That way i'd have to structure the code like this: >> >> graphic/ >> __init__,py (GraphicObject) >> square.py (Square) >> circle.py (Circle) >> >> Does that make sense like this? > > This seems perfectly acceptable. Thanks for that hint. Do you see a way that i could write in circle.py: circle.py: import graphic class Circle(graphic.GraphicObject): ..... if __name__ == '__main__': abc = Circle() abc.some_test_code() Thanks for any hints, Torsten. From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 5 08:18:06 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jan 2009 14:18:06 +0100 Subject: structuring a package? In-Reply-To: References: Message-ID: <4962088d$0$24202$426a74cc@news.free.fr> Torsten Mohr a ?crit : > Hi, > > i have a question on how to structure a package best, would be great if > anybody could give me some hint on this: > > Assuming i have a base class GraphicObject and derived from that some > classes like Square, Circle, ... > > It looks natural to me to write in a code that uses the package: > > import graphic > import graphic.square > import graphic.circle > > That way i'd have to structure the code like this: > > graphic/ > __init__,py (GraphicObject) > square.py (Square) > circle.py (Circle) > > Does that make sense like this? > > Are there better ways to structure things in Python? Well... Unless your Square and Circle classes are monster classes, or you have many many GraphicObject subclasses - that is, unless you need to do so for source-file size management -, there's not much reason to use a Java-like "one class per file" scheme[1], and it's not the common way to organize Python code. Now if you do have (or just really want - well, it's your code, isn't it ?-)) to use one-class-per-file, you may be better moving the base GraphicObject class in a base.py module. This would be easier to understand IMHO, and should make internal imports easier to manage. [1] A package can act as a facade for submodules/subpackages (using the __init__.py to expose submodules/subpackages at the top level), so it's not a problem to refactor a single module into a package... > One thing that bothers me is that when i write in circly.py something like > "import graphic", then i can't have the test code for the Circle within > circle.py, at least it looks to me like this. Depends on how you write your test code, but as far as I'm concerned, I prefer to separate source from tests (and use a unittesting framework). From truelixin at gmail.com Mon Jan 5 08:24:07 2009 From: truelixin at gmail.com (truelixin at gmail.com) Date: Mon, 5 Jan 2009 05:24:07 -0800 (PST) Subject: About PyOpenGL Message-ID: I follow the , write a small test: #!/usr/bin/env python # encoding=utf-8 import sys from OpenGL.GL import * from OpenGL.GLUT import * def display(): glClear(GL_COLOR_BUFFER_BIT) glColor(1.0, 1.0, 1.0) glBegin(GL_POLYGON) glVertex(0.25, 0.25, 0.0) glVertex(0.75, 0.25, 0.0) glVertex(0.75, 0.75, 0.0) glVertex(0.25, 0.75, 0.0) glEnd() glFlush() def init(): glClearColor(0.0, 0.0, 0.0, 0.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) glutCreateWindow('hello') init() glutDisplayFunc(display) glutMainLoop() if __name__ == '__main__': main() But I got an error: Traceback (most recent call last): File "test.py", line 36, in main() File "test.py", line 26, in main glutInit(sys.argv) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\GLUT\special.py", line 316, in glutInit _base_glutInit( ctypes.byref(count), holder ) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\GLUT\special.py", line 57, in _base_glutInit return __glutInitWithExit(pargc, argv, _exitfunc) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\platform\baseplatform.py", line 280, in __call__ self.__name__, self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined function __glutInitWithExit, check for bool(__glutInitWithExit) before calling Can anyone please tell me why? From digitig at gmail.com Mon Jan 5 08:31:35 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 5 Jan 2009 13:31:35 +0000 Subject: Why not Ruby? In-Reply-To: References: Message-ID: 2009/1/1 r : > I am beginning to think > the perfect high level language would take the best for Ruby and > Python. The ultimate language with speed in mind, pythons clear > syntax, but with shortcuts for gurus. I spent quite a few evenings looking at Ruby, and didn't find a single thing I liked (and I certainly didn't find it "elegant", as the original poster described it). What do you see in it that you think would be good in Python? Remember, put in too many shortcuts and you'll end up with code that's as unmaintainable as Perl! -- Tim Rowe From antroy at gmail.com Mon Jan 5 08:46:52 2009 From: antroy at gmail.com (Ant) Date: Mon, 5 Jan 2009 05:46:52 -0800 (PST) Subject: My last working day of 2007 References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: On Jan 5, 9:47?am, "Jack.Chu" wrote: > Hello guys: > I created a simple tool to count how I wasted my time day by day ;-)http://www.flickr.com/photos/34017270 at N07/3169438647/sizes/o/ Looks interesting - did you have some sort of time machine to be spending that much time in Chrome at the end of 2007? ;-) > I just want to get suggestions to improve it, ... It's a bit hard to tell just from the screenshot... Do you have some code we could look at? Would be perhaps good to sub-log each window's title so that you could subdivide, for example, Firefox's time by the pages you were looking at (this would work quite well for numerous apps.) From thomasvangurp at gmail.com Mon Jan 5 08:52:56 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Mon, 5 Jan 2009 05:52:56 -0800 (PST) Subject: f.seek() unwanted output Message-ID: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> I'm having trouble with a script that is printing the output of f.seek () whereas in the documentation it is quoted not to have any output: ---- file.seek(offset[, whence])? Set the file?s current position, like stdio?s fseek. The whence argument is optional and defaults to os.SEEK_SET or 0 (absolute file positioning); other values are os.SEEK_CUR or 1 (seek relative to the current position) and os.SEEK_END or 2 (seek relative to the file?s end). There is no return value. -------------- I have a file in memory. when i try f.seek(0) #or any other value in f.tell() it gives me 0 as output: the following script illustrates my 'problem' >>> for a in range(10): f.seek(a) 0 1 2 3 4 5 6 7 8 9 >>> I don't want python to produce output when setting the file pointer. Any help woul be appreciated. Kind regards, Thomas From python.list at tim.thechases.com Mon Jan 5 09:13:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Jan 2009 08:13:30 -0600 Subject: f.seek() unwanted output In-Reply-To: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: <4962158A.9030605@tim.thechases.com> > I'm having trouble with a script that is printing the output of f.seek > () [snip] > I have a file in memory. > when i try f.seek(0) #or any other value in f.tell() > it gives me 0 as output: > > the following script illustrates my 'problem' >>>> for a in range(10): > f.seek(a) > > > 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 You're seeing an artifact of the command-line (evidenced by your ">>>" before your command). Just like int("42") returns output...the Python console prints the output while a script (saved to the disk) doesn't. Try putting your test in foo.py and running that -- you'll notice that it doesn't echo back the numbers as you describe. The behavior seems to vary. In my Python2.4, seek() for file/cStringIO/StringIO objects returns None with each. Whichever version (or object-type) you're using seems to return its input offset as its output. -tkc From thomasvangurp at gmail.com Mon Jan 5 09:22:44 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Mon, 5 Jan 2009 06:22:44 -0800 (PST) Subject: f.seek() unwanted output References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: Hi Tim, works! thanx a lot Thomas From djames.suhanko at gmail.com Mon Jan 5 09:25:53 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 5 Jan 2009 12:25:53 -0200 Subject: Tkinter - problem closing window Message-ID: Hello! I'm sorry my terrible english (my native language is portuguese). I has a litle program that open another window. When I close de root window in quit button, I need clicking 2 times to close. is where the problem? The source: 1 #!/usr/bin/env python 2 from Tkinter import * 3 import sys 4 import random 5 class App: 6 def __init__(self, master): 7 frame = Frame(master) 8 frame.pack() 9 rotulo = Label(frame, text="Clique em 'Gerar' e boa sorte!",borderwidth=2,bg="gray",justify=C ENTER,relief=SUNKEN) 10 rotulo.pack() 11 12 self.button = Button(frame, text="Sair", fg="red", command=frame.quit,borderwidth=1) 13 self.button.pack(side=LEFT) 14 self.hi_there = Button(frame, text="Gerar Numero", command=self.say_hi,borderwidth=1) 15 self.hi_there.pack(side=RIGHT,padx=2,pady=2) 16 17 def gera_seis(self): 18 a = {} 19 for i in range(6): 20 a[i] = "%02d" % int (random.randint(0,60)) 21 resultadoA = "%s-%s-%s-%s-%s-%s" % (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) 22 return resultadoA 23 24 def say_hi(self): 25 resultado = self.gera_seis() 26 raiz = Tk() 27 F = Frame(raiz) 28 F.pack() 29 hello = Label(F, text=resultado) 30 hello.pack() 31 F.mainloop() 32 33 root = Tk() 34 root.title("$$$ Loteria $$$") 35 app = App(root) 36 root.mainloop() -- Djames Suhanko LinuxUser 158.760 From pruebauno at latinmail.com Mon Jan 5 09:54:51 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 5 Jan 2009 06:54:51 -0800 (PST) Subject: f.seek() unwanted output References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: On Jan 5, 8:52?am, "thomasvang... at gmail.com" wrote: > I'm having trouble with a script that is printing the output of f.seek > () whereas in the documentation it is quoted not to have any output: > > ---- > file.seek(offset[, whence])? > > ? ? Set the file?s current position, like stdio?s fseek. The whence > argument is optional and defaults to os.SEEK_SET or 0 (absolute file > positioning); other values are os.SEEK_CUR or 1 (seek relative to the > current position) and os.SEEK_END or 2 (seek relative to the file?s > end). There is no return value. > -------------- > > I have a file in memory. > when i try f.seek(0) #or any other value in f.tell() > it gives me 0 as output: > > the following script illustrates my 'problem'>>> for a in range(10): > > ? ? ? ? f.seek(a) > > 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > > > > I don't want python to produce output when setting the file pointer. > Any help woul be appreciated. > Kind regards, > Thomas You can also avoid the output by assigning the output to something: >>> for a in range(10): dummy=f.seek(a) From __peter__ at web.de Mon Jan 5 10:07:27 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Jan 2009 16:07:27 +0100 Subject: Tkinter - problem closing window References: Message-ID: Djames Suhanko wrote: > Hello! > I'm sorry my terrible english (my native language is portuguese). > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > The source: > 1 #!/usr/bin/env python > 2 from Tkinter import * > 3 import sys > 4 import random > 5 class App: > 6 def __init__(self, master): > 7 frame = Frame(master) > 8 frame.pack() > 9 rotulo = Label(frame, text="Clique em 'Gerar' e boa > sorte!",borderwidth=2,bg="gray",justify=C ENTER,relief=SUNKEN) > 10 rotulo.pack() > 11 > 12 self.button = Button(frame, text="Sair", fg="red", > command=frame.quit,borderwidth=1) > 13 self.button.pack(side=LEFT) > 14 self.hi_there = Button(frame, text="Gerar Numero", > command=self.say_hi,borderwidth=1) > 15 self.hi_there.pack(side=RIGHT,padx=2,pady=2) > 16 > 17 def gera_seis(self): > 18 a = {} > 19 for i in range(6): > 20 a[i] = "%02d" % int (random.randint(0,60)) > 21 resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > 22 return resultadoA > 23 > 24 def say_hi(self): > 25 resultado = self.gera_seis() > 26 raiz = Tk() > 27 F = Frame(raiz) > 28 F.pack() > 29 hello = Label(F, text=resultado) > 30 hello.pack() > 31 F.mainloop() You need only one mainloop(). Remove line 31 and you should be OK. > 32 > 33 root = Tk() > 34 root.title("$$$ Loteria $$$") > 35 app = App(root) > 36 root.mainloop() Peter From skip at pobox.com Mon Jan 5 10:18:53 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 5 Jan 2009 09:18:53 -0600 Subject: My last working day of 2007 In-Reply-To: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: <18786.9437.669282.928437@montanaro.dyndns.org> Jack> It's simple, a small program running on background, logging the Jack> title of foreground window. A python script parses the log file Jack> and then generates chart by matplotlib. Jack> I just want to get suggestions to improve it, or know the news Jack> that somebody had implemented a better one so I can abandon my Jack> toy. For starters, you might figure out how to make it work on a real operating system which allows multiple active processes. Nudge, nudge. Wink, wink. Say no more. Say no more. ;-) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From psaffrey at googlemail.com Mon Jan 5 10:39:44 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 5 Jan 2009 07:39:44 -0800 (PST) Subject: mod_python: delay in files changing after alteration Message-ID: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Maybe this is an apache question, in which case apologies. I am running mod_python 3.3.1-3 on apache 2.2.9-7. It works fine, but I find that when I alter a source file during development, it sometimes takes 5 seconds or so for the changes to be seen. This might sound trivial, but when debugging tens of silly errors, it's annoying that I have to keep hitting refresh on my browser waiting for the change to "take". I'm guessing this is just a caching issue of some kind, but can't figure out how to switch it off. Any suggestions? The entry in my apache2.conf looks like this: SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On Thanks, Peter From cousinstanley at gmail.com Mon Jan 5 10:59:51 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 5 Jan 2009 15:59:51 +0000 (UTC) Subject: About PyOpenGL References: Message-ID: > .... > OpenGL.error.NullFunctionError: Attempt to call an undefined function > __glutInitWithExit, check for bool(__glutInitWithExit) before calling > > Can anyone please tell me why? Your opengl program runs exactly as coded without error under Debian 5.0 Linux Lenny .... Perhaps a required library is missing from your opengl installation .... Sorry I couldn't provide more help .... -- Stanley C. Kitching Human Being Phoenix, Arizona From guillaume.aubert at gmail.com Mon Jan 5 11:29:47 2009 From: guillaume.aubert at gmail.com (guss) Date: Mon, 5 Jan 2009 08:29:47 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname Message-ID: I cannot find a satisfying answer to this question on the web so let's try here. My problem is the following, I would like to instantiate some object from a configuration file that would contain class names like for example classname=org.common.resource.MyResource. Here my resource is the class to instanciate and it is in the module resource that is in a package hierachy. In fact I would like to do something very similar to the Java: klass = Class.forname("org.common.resource.MyResource") instance = klass.newInstance() The second line is easy once I have a classobj but I have some problems to find the right recipe for getting it. I know how to create a class from scratch with new.classobj but how do you get a class object and then create an object ? I would like a recipe working for all cases (whatever the module is not the local one ...) Maybe I should follow another idiom I don't know ? Thanks your help Guillaume From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 5 11:34:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jan 2009 17:34:24 +0100 Subject: reflection as in Java: how to create an instance from a classname In-Reply-To: References: Message-ID: <4962368e$0$25548$426a74cc@news.free.fr> guss a ?crit : > I cannot find a satisfying answer to this question on the web so let's > try here. > > My problem is the following, I would like to instantiate some object > from a configuration file that would contain class names like for > example classname=org.common.resource.MyResource. > Here my resource is the class to instanciate and it is in the module > resource that is in a package hierachy. > > In fact I would like to do something very similar to the Java: > > klass = Class.forname("org.common.resource.MyResource") > > instance = klass.newInstance() > > The second line is easy once I have a classobj but I have some > problems to find the right recipe for getting it. > > I know how to create a class from scratch with new.classobj but how do > you get a class object and then create an object ? > > I would like a recipe working for all cases (whatever the module is > not the local one ...) use __import__ to get the module object, then getattr(module, classname) to get the class object (sorry, no much time right now to give you a full recipe, but that should be enough to get you started). HTH From qgallet at gmail.com Mon Jan 5 11:37:21 2009 From: qgallet at gmail.com (Quentin Gallet-Gilles) Date: Mon, 5 Jan 2009 17:37:21 +0100 Subject: reflection as in Java: how to create an instance from a classname In-Reply-To: <4962368e$0$25548$426a74cc@news.free.fr> References: <4962368e$0$25548$426a74cc@news.free.fr> Message-ID: <8b943f2b0901050837m6d399f91p825c63cf1ce01d85@mail.gmail.com> On Mon, Jan 5, 2009 at 5:34 PM, Bruno Desthuilliers wrote: > guss a ?crit : > >> I cannot find a satisfying answer to this question on the web so let's >> try here. >> >> My problem is the following, I would like to instantiate some object >> from a configuration file that would contain class names like for >> example classname=org.common.resource.MyResource. >> Here my resource is the class to instanciate and it is in the module >> resource that is in a package hierachy. >> >> In fact I would like to do something very similar to the Java: >> >> klass = Class.forname("org.common.resource.MyResource") >> >> instance = klass.newInstance() >> >> The second line is easy once I have a classobj but I have some >> problems to find the right recipe for getting it. >> >> I know how to create a class from scratch with new.classobj but how do >> you get a class object and then create an object ? >> >> I would like a recipe working for all cases (whatever the module is >> not the local one ...) >> > > use __import__ to get the module object, then getattr(module, classname) to > get the class object (sorry, no much time right now to give you a full > recipe, but that should be enough to get you started). > > HTH > A longer version of Bruno's idea can be found here : http://mail.python.org/pipermail/python-list/2003-March/192221.html Cheers, Quentin -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Mon Jan 5 11:50:17 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 16:50:17 +0000 Subject: math module for Decimals In-Reply-To: References: <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: > > Hmm. Maybe we shouldn't be using this syntax in from_float, if it's > the only thing that prevents the trunk version of decimal.py from > being used with Python 2.4. On the other hand, from_float isn't > going to work until 2.7 anyway, since it uses a whole bunch of > new stuff: as_integer_ratio and copysign (both introduced in 2.6), > and bit_length (introduced in 2.7). > I so new to python that I'm not sure that anything I can say may help as much as someone with more experience. I would leave is compatability to be decided by what other functions it relies on.(as_integer_ratio and copysign) Throw the rest out the window. Since that would make this function more bulky and I don't think there will be that many people wanting to use it with 2.4, OTOH I'm using BackTrack2 and it comes with python2.4.3 I started building my little program using ubuntu with python2.5.x, then I started to use my other option for dual-boot. Backtrack2 is an old time favorite and is alot faster for me to use when running X,firefox(with anywhere from 15-100 tabs open),konqueror,etc Ialready installed other versions of python for bt, no problem there. I'm just wondering about this import error in decimal.py inside python2.7a0(svn repo), don't let curiosity kill this cat. I just wanted to let All know what decimal.py is doing on my pc. Maybe I'm the only one getting this? This version of python2.7 is from python's svn repo. Is the python repo considered to be unstable(wrong word?) and this is expected? I get this when importing decimal: Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/decimal.py", line 138, in import math as _math ImportError: No module named math >>> Are other people seeing this as well? Just curious. -------------- next part -------------- An HTML attachment was scrubbed... URL: From collin.day.0 at gmail.com Mon Jan 5 11:52:48 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 5 Jan 2009 08:52:48 -0800 (PST) Subject: Tkinter - problem closing window References: Message-ID: On Jan 5, 6:25?am, "Djames Suhanko" wrote: > Hello! > I'm sorry my terrible english (my native language is portuguese). > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > The source: > ? 1 #!/usr/bin/env python > ? 2 from Tkinter import * > ? 3 import sys > ? 4 import random > ? 5 class App: > ? 6 ?def __init__(self, master): > ? 7 ? ?frame = Frame(master) > ? 8 ? ?frame.pack() > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > ?10 ? ?rotulo.pack() > ?11 > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > command=frame.quit,borderwidth=1) > ?13 ? ?self.button.pack(side=LEFT) > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > command=self.say_hi,borderwidth=1) > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > ?16 > ?17 ?def gera_seis(self): > ?18 ? ?a = {} > ?19 ? ?for i in range(6): > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > ?22 ? ?return resultadoA > ?23 > ?24 ?def say_hi(self): > ?25 ? ?resultado = self.gera_seis() > ?26 ? ?raiz = Tk() > ?27 ? ?F = Frame(raiz) > ?28 ? ?F.pack() > ?29 ? ?hello = Label(F, text=resultado) > ?30 ? ?hello.pack() > ?31 ? ?F.mainloop() > ?32 > ?33 root = Tk() > ?34 root.title("$$$ Loteria $$$") > ?35 app = App(root) > ?36 root.mainloop() > > -- > Djames Suhanko > LinuxUser 158.760 Also for style, you might want to group the import lines so they look like this: from Tkinter import * import sys, random A bit more pythonic. :P From rtw at freenet.co.uk Mon Jan 5 11:58:10 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Mon, 05 Jan 2009 10:58:10 -0600 Subject: About PyOpenGL References: Message-ID: truelixin at gmail.com wrote in news:f8099226-a953-4598-bfe2-61ee5772ce26 @l33g2000pri.googlegroups.com in comp.lang.python: > > Traceback (most recent call last): > File "test.py", line 36, in > main() > File "test.py", line 26, in main > glutInit(sys.argv) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\GLUT\special.py", line 316, in glutInit > _base_glutInit( ctypes.byref(count), holder ) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\GLUT\special.py", line 57, in _base_glutInit > return __glutInitWithExit(pargc, argv, _exitfunc) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\platform\baseplatform.py", line 280, in __call__ > self.__name__, self.__name__, > OpenGL.error.NullFunctionError: Attempt to call an undefined function > __glutInitWithExit, check for bool(__glutInitWithExit) before calling To get you code running I needed (in addition to the PyOpenGL download) to download. glut-3.7.6-bin.zip (117 KB) from http://www.xmission.com/~nate/glut.html and put the glut32.dll where python can find it, the readme says \system which worked, but sticking it in the same directory as python.exe (c:\python25 in your case) worked too. http://pyopengl.sourceforge.net/ http://pyopengl.sourceforge.net/documentation/installation.html Rob. -- http://www.victim-prime.dsl.pipex.com/ From koranthala at gmail.com Mon Jan 5 11:59:35 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Mon, 5 Jan 2009 08:59:35 -0800 (PST) Subject: Python return values Message-ID: <8ddbd429-64d5-4e64-ba7d-556e6b508164@w1g2000prk.googlegroups.com> I have a newbie doubt about Python return values. In (say) C/C++, if we try to return a value which is stored inside the procedure stack, we will get an error when trying to access it outside of that procedure. For example: function foo(): dcl y int dcl x pointer to int pointing to y return x function bar(): x = foo() ... use x This will error out since the memory has be taken back. Now, in Python, we do it everytime, because all variables are references, and even returns just copies the references. function pyfoo(): return 786 function pyfoo1(): x = xclass() return x function pybar(): x = pyfoo() y = pyfoo1() ... use x, y Why doesnt it error out? From djm300 at gmail.com Mon Jan 5 12:00:37 2009 From: djm300 at gmail.com (Joris) Date: Mon, 5 Jan 2009 18:00:37 +0100 Subject: Python callback functions and static methods Message-ID: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Hello, I'm trying to implement callback functionality in a static class. I have a feeling that I'm doing something against the Python philosophy and not some programming error but any help would be appreciated. First, a piece of proof-of-concept-code: * class Data: callfunc = None @staticmethod def setCallBack(callfunc): Data.callfunc = callfunc @staticmethod def OnData(data): Data.callfunc(data) def DataCallback(a): print 'I received some data: '+ a Data.setCallBack(DataCallback) Data.OnData('I have new data') * I have defined a class called Data, which I want to use as a "static" class (i.e. I will never create an instance of it). (I come from a Java background so forgive me calling this static) It contains a class variable and 2 static methods. I also defined a separate function called DataCallback, which would just print the data it receives. The goal of this is to use the Data class as a dispatcher of some chunk of data to whatever function I would like, settable at run-time. When executing this script, following error occurs: *Traceback (most recent call last): File "callback.py", line 17, in Data.OnData('I have new data') File "callback.py", line 11, in OnData Data.callfunc(data) TypeError: unbound method DataCallback() must be called with Data instance as first argument (got str instance instead) * What I don't understand is why Python is expecting me to call the DataCallback() function with a Data instance. To my understanding, the DataCallback() function can be called from a static method and thus does not require any instance. Can anyone point me in the right direction ? Thanks, Joris -------------- next part -------------- An HTML attachment was scrubbed... URL: From schapman1974 at gmail.com Mon Jan 5 12:08:08 2009 From: schapman1974 at gmail.com (Stephen Chapman) Date: Mon, 5 Jan 2009 12:08:08 -0500 Subject: mod_python: delay in files changing after alteration In-Reply-To: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Message-ID: I have never noticed any such delay. After making a change I just hit F5 on my browser and its fine. Maybe its a browser issue On 1/5/09, psaffrey at googlemail.com wrote: > Maybe this is an apache question, in which case apologies. > > I am running mod_python 3.3.1-3 on apache 2.2.9-7. It works fine, but > I find that when I alter a source file during development, it > sometimes takes 5 seconds or so for the changes to be seen. This might > sound trivial, but when debugging tens of silly errors, it's annoying > that I have to keep hitting refresh on my browser waiting for the > change to "take". I'm guessing this is just a caching issue of some > kind, but can't figure out how to switch it off. Any suggestions? > > The entry in my apache2.conf looks like this: > > > SetHandler mod_python > PythonHandler mod_python.publisher > PythonDebug On > > > > Thanks, > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from Gmail for mobile | mobile.google.com From mwilson at the-wire.com Mon Jan 5 12:09:01 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 05 Jan 2009 12:09:01 -0500 Subject: Python return values References: <8ddbd429-64d5-4e64-ba7d-556e6b508164@w1g2000prk.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > I have a newbie doubt about Python return values. > > In (say) C/C++, if we try to return a value which is stored inside the > procedure stack, we will get an error when trying to access it outside > of that procedure. > For example: > function foo(): > dcl y int > dcl x pointer to int pointing to y > return x > > > function bar(): > x = foo() > ... > use x > > This will error out since the memory has be taken back. > > Now, in Python, we do it everytime, because all variables are > references, and even returns just copies the references. > function pyfoo(): > return 786 > > function pyfoo1(): > x = xclass() > return x > > function pybar(): > x = pyfoo() > y = pyfoo1() > ... > use x, y > > Why doesnt it error out? Because Python doesn't use the procedure stack that way. Using C/C++ terms, all objects are in the heap, and objects are deallocated automatically after all references to them disappear. Mel. From rdcollum at gmail.com Mon Jan 5 12:21:38 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 5 Jan 2009 09:21:38 -0800 (PST) Subject: Tkinter - problem closing window References: Message-ID: <3bd8f10c-abba-4e82-9795-0de7612ac7f0@s36g2000vbp.googlegroups.com> On Jan 5, 11:52?am, Collin D wrote: > On Jan 5, 6:25?am, "Djames Suhanko" wrote: > > > > > Hello! > > I'm sorry my terrible english (my native language is portuguese). > > I has a litle program that open another window. When I close de root > > window in quit button, I need clicking 2 times to close. is where the > > problem? > > > The source: > > ? 1 #!/usr/bin/env python > > ? 2 from Tkinter import * > > ? 3 import sys > > ? 4 import random > > ? 5 class App: > > ? 6 ?def __init__(self, master): > > ? 7 ? ?frame = Frame(master) > > ? 8 ? ?frame.pack() > > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > > ?10 ? ?rotulo.pack() > > ?11 > > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > > command=frame.quit,borderwidth=1) > > ?13 ? ?self.button.pack(side=LEFT) > > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > > command=self.say_hi,borderwidth=1) > > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > > ?16 > > ?17 ?def gera_seis(self): > > ?18 ? ?a = {} > > ?19 ? ?for i in range(6): > > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > > ?22 ? ?return resultadoA > > ?23 > > ?24 ?def say_hi(self): > > ?25 ? ?resultado = self.gera_seis() > > ?26 ? ?raiz = Tk() > > ?27 ? ?F = Frame(raiz) > > ?28 ? ?F.pack() > > ?29 ? ?hello = Label(F, text=resultado) > > ?30 ? ?hello.pack() > > ?31 ? ?F.mainloop() > > ?32 > > ?33 root = Tk() > > ?34 root.title("$$$ Loteria $$$") > > ?35 app = App(root) > > ?36 root.mainloop() > > > -- > > Djames Suhanko > > LinuxUser 158.760 > > Also for style, you might want to group the import lines so they look > like this: > > from Tkinter import * > import sys, random > > A bit more pythonic. :P In that case you probably want to take out the 'from' import and: import Tkinter, sys, random in order to avoid any namespace issues especially if you have a large project with lots of gui manipulations. But that's just me being pedantic. ;) From google at mrabarnett.plus.com Mon Jan 5 12:31:24 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 05 Jan 2009 17:31:24 +0000 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <496243EC.7010107@mrabarnett.plus.com> Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy > and not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > * > class Data: > > callfunc = None > > @staticmethod > def setCallBack(callfunc): > Data.callfunc = callfunc > > @staticmethod > def OnData(data): > Data.callfunc(data) > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > * > > I have defined a class called Data, which I want to use as a "static" > class (i.e. I will never create an instance of it). (I come from a Java > background so forgive me calling this static) > It contains a class variable and 2 static methods. > > I also defined a separate function called DataCallback, which would just > print the data it receives. > > The goal of this is to use the Data class as a dispatcher of some chunk > of data to whatever function I would like, settable at run-time. > > When executing this script, following error occurs: > > *Traceback (most recent call last): > File "callback.py", line 17, in > Data.OnData('I have new data') > File "callback.py", line 11, in OnData > Data.callfunc(data) > TypeError: unbound method DataCallback() must be called with Data > instance as first argument (got str instance instead) > * > What I don't understand is why Python is expecting me to call the > DataCallback() function with a Data instance. To my understanding, the > DataCallback() function can be called from a static method and thus does > not require any instance. > > Can anyone point me in the right direction ? > DataCallback isn't a static method, it's a plain function. Try this instead: class Data: ... @staticmethod def setCallBack(callfunc): Data.callfunc = staticmethod(callfunc) ... From clp at rebertia.com Mon Jan 5 12:33:23 2009 From: clp at rebertia.com (Chris Rebert) Date: Mon, 5 Jan 2009 09:33:23 -0800 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <47c890dc0901050933w3a04fde8ncb0bbc26bddc8544@mail.gmail.com> On Mon, Jan 5, 2009 at 9:00 AM, Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy and > not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > > class Data: > The call to setCallBack effectively makes it as though you'd done this (note that we're within the class body): def callfunc(a): print 'I received some data: '+ a Obviously this method is not "static" in the Java sense, hence the error about not being called with an instance. Here are my suggested changes: > @classmethod #class methods are closer to Java "static" methods; Python static methods are just functions in a class def setCallBack(cls, callfunc): cls.callfunc = staticmethod(callfunc) > @classmethod def OnData(cls, data): cls.callfunc(data) > > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > > Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Mon Jan 5 12:42:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 05 Jan 2009 15:42:39 -0200 Subject: socket send help References: Message-ID: En Sat, 03 Jan 2009 21:44:34 -0200, Bryan Olson escribi?: > Gabriel Genellina wrote: >> greywine at gmail.com escribi?: > [...] >>> A simple server: >>> >>> from socket import * >>> myHost = '' >> Try with myHost = '127.0.0.1' instead - a firewall might be blocking >> your server. > > Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty > string is that a firewall might *not* be blocking your server. > > The Python sockets module interprets the empty string as INADDR_ANY, > which means to bind to all available adapters including the loopback, > A.K.A localhost, A.K.A '127.0.0.1'. I thought a firewall would block an attempt to bind to any routeable address, but not to localhost. So using INADDR_ANY would be rejected. -- Gabriel Genellina From exarkun at divmod.com Mon Jan 5 13:07:07 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 5 Jan 2009 13:07:07 -0500 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <20090105180707.20272.1723525760.divmod.quotient.32109@ohm> On Mon, 5 Jan 2009 18:00:37 +0100, Joris wrote: >Hello, > >I'm trying to implement callback functionality in a static class. > >I have a feeling that I'm doing something against the Python philosophy and >not some programming error but any help would be appreciated. > Others have explained what was wrong with your `Data` class, so I won't bother going into that. I will recommend that you take a look at Deferred and perhaps use it, rather than implementing something yourself: http://twistedmatrix.com/projects/core/documentation/howto/defer.html Jean-Paul From steve at holdenweb.com Mon Jan 5 13:07:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:07:27 -0500 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy > and not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > * > class Data: > > callfunc = None > > @staticmethod > def setCallBack(callfunc): > Data.callfunc = callfunc > > @staticmethod > def OnData(data): > Data.callfunc(data) > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > * > > I have defined a class called Data, which I want to use as a "static" > class (i.e. I will never create an instance of it). (I come from a Java > background so forgive me calling this static) > It contains a class variable and 2 static methods. > > I also defined a separate function called DataCallback, which would just > print the data it receives. > > The goal of this is to use the Data class as a dispatcher of some chunk > of data to whatever function I would like, settable at run-time. > > When executing this script, following error occurs: > > *Traceback (most recent call last): > File "callback.py", line 17, in > Data.OnData('I have new data') > File "callback.py", line 11, in OnData > Data.callfunc(data) > TypeError: unbound method DataCallback() must be called with Data > instance as first argument (got str instance instead) > * > What I don't understand is why Python is expecting me to call the > DataCallback() function with a Data instance. To my understanding, the > DataCallback() function can be called from a static method and thus does > not require any instance. > > Can anyone point me in the right direction ? > Although other posters have pointed out your mistake in strict terms, I would like to suggest that as long as you never intend to instantiate the class you would be better off without it, defining this functionality as a module and using the nodule global namespace instead of the class namespace. Something like this: callfunc = None def setCallBack(f): global callfunc callfunc = f def OnData(data): callfunc(data) if __name__ == "__main__": def DataCallback(a): print "I received this data:", a setCallBack(DataCallback) OnData("I have new data") OnData("And here's some more!") In other words, I'm not sure what you feel the class organization is buying you. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:13:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:13:29 -0500 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: alex goretoy wrote: > I've found a great example on how to do threads. It compares a ping > program in regular for loop and with threaded for loop. The link is > below if anyone is interested. > > http://www.wellho.net/solutions/python-python-threads-a-first-example.html > > I hope my eagerness to post doesn't annoy anyone. I like to get as much > info from as many places as possible and compare. This way I think I may > have a better solution for a problem. Plus people that Google will find > this post or any words in it. Any more information on threading a for > loop would be greatly appreciated. TIA > Your understanding that such eagerness can become annoying if taken too far is appreciated. So far I haven't heard anyone suggest you should move to comp.lang.somewhere-noobs-get-flamed ... Be aware, however, that the CPython implementation won't net you any benefit if all threads are CPU-bound, since due to something called the GIL (global interpreter lock) no two threads will run concurrently. If you search my past posts on threading you will doubtless find a couple where I've posted my standard example. I don't want to bore long-time readers (any more than I normally do) by repeating it yet again. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:23:04 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:23:04 -0500 Subject: why cannot assign to function call In-Reply-To: <20090105050927.GS28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:56:33PM -0600, Grant Edwards wrote: >> On 2009-01-05, Derek Martin wrote: >>> On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: >>>> One presumes that Mr. Martin finds anything different from his >>>> first computer language to be BIZARRE. He should try out >>>> Prolog or something genuinely different. >>> One's presumption would be mistaken. However thank you for >>> illustrating my point so precisely, which was after all the >>> condescending and insulting way people "communicate" with >>> people whom (they think) know less than they do in this forum, >>> and not actually how difficult or easy the assignment model of >>> Python is to understand. >> I'm sorry, but I really don't see how Python's assignment model >> could be considered bizarre by anybody who's familiar with more >> than one or two languages. > > And... what if one wasn't? The OP of this thread clearly didn't > understand... Whereas if you've read the thread, clearly I do. > Of course, had you read my post, you probably would have understood > that my comment about the model being bizarre was intended to be > viewed from the perspective of someone who *had not* seen anything > like it before, which is LOTS of relatively new programmers, whether > or not it might be old hat to anyone here. The ultimate point of my > post was not so much about whether the assignment model of Python was > or wasn't easy to understand; it was about the idea that when someone > doesn't understand, we should try to help them instead of making snide > remarks about how stupid or small-minded they are. Even if they really are small-minded or stupid I agree this wouldn't be helpful behavior. But neither would your characterization of Python's assignment model as "bizarre" (even ignoring that you SHOUTED IT AT US), and I have yet to see you admit that such a characterization was, shall we say, inappropriate. It takes little to admit one is in the wrong even when one isn't. I've had to learn to do it because I often *am* wrong about things. Could you be persuaded to consider the possibility that you met with a somewhat hostile reaction (whether or not such a reaction was useful or necessary) because you were, in a small way, poking people in the side with a sharp stick? If you couldn't I might find that a *little* bizarre. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:31:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:31:48 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: Steven D'Aprano wrote: > On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: [...]>>>> And for that matter, it's pretty unintuitive generally. >>> Names and objects are quite "natural" IMHO. There are many real world >>> objects which we attach one or more names to, or refer to in sequences >>> like "please give me the third book on that shelve" (``shelve[2]``). >> Indeed, but the way we assign names to them does not behave as it does >> in Python. > > It doesn't? > > Oh my, you're going to be confused in a few weeks when The President of > the USA ceases to be George W Bush and becomes Barack Obama. Same name > (or rather, title), different object (person). > No, he will doubtless describe the White House as a President variable whose value has been overwritten. There are many fine jokes to be made about the need to garbage-collect President Bush ... > > >> Nor does Python's assignment work like it does in algebra, > > Nor does any programming language, with the possible exception of > computer algebra systems. > I'm still waiting for an explanation of where assignment comes into algebra in the first place. > [...] > >> Those interpretations came first, because, much as in the >> evolution of any other science, that was the model which was most >> intuitive or easily explained. > > No no no no. That was the model that was most easily implemented! > Agreed. In those days the von Neumann architecture was a shiny new thing, and it was even a while before people thought of using computers for symbolic rather than numeric operations (which is IMHO what makes them so interesting). > Before the named bins model of assignment was pure machine code, where > you didn't have bins at all, just bits, and there was no distinction > between code and data. And before that was *wires* -- early programmers > literally had to plug and unplug wires to change the state of the > computer. And before that were purely mechanical devices, such as the > Enigma Machine, old calculators, and the grand-daddy of them all, Charles > Babbage's difference engine and it's precursors. > Aah, the old Univac 1004. Sorry, I'm rambling. > > >> But you need not take my word for it. Simply read the archives and see >> for yourself how much confusion this has caused on this list. [Please >> include the closely related behavior of parameter passing in your >> search.] > > In my opinion, the cause of that confusion is nothing to do with Python's > assignment model, and everything to do with the instance of some people > to use named bins terminology when describing the Python model. If you > keep the named bins terminology for describing the named bins model, > you're fine; and if you keep the name/object terminology for describing > languages with names/objects, you're fine. You only run into trouble when > you mix them. That's when you get people confused because "Python is Call > By Something, but it doesn't behave like Call By Something in language > Foo I've used before". > > This really does go to show that (some) people will argue about anything, with the major intention of proving themselves right rather than reaching a common understanding. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lutz at rmi.net Mon Jan 5 13:34:52 2009 From: lutz at rmi.net (lutz at rmi.net) Date: Mon, 5 Jan 2009 11:34:52 -0700 (GMT-07:00) Subject: Python training in Colorado, January 27-30 Message-ID: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> Yes, my public classes are held only in Colorado today. Most students travel from out-of-town to attend. Per my web page, my classes may be available in a different location later this year (Florida is a strong possibility), but not in Tulsa, unfortunately. Thanks, --Mark Lutz -----Original Message----- >From: alex goretoy >Sent: Jan 4, 2009 1:19 PM >To: Mark Lutz >Cc: python-list at python.org >Subject: Re: Python training in Colorado, January 27-30 > >I'd be interested in attending if you make it to Tulsa,OK. Are your courses >only in Colorado? > >-Alex Goretoy >http://www.alexgoretoy.com > > >On Sun, Jan 4, 2009 at 7:29 PM, Mark Lutz wrote: > >> Python author and trainer Mark Lutz will be teaching a 4-day >> Python class on January 27-30, in Longmont, Colorado. >> >> This is a public training session open to individual enrollments, >> and covers the same topics and hands-on lab work as the onsite >> sessions that Mark teaches. The class provides an in-depth >> introduction to both Python and its common applications, and >> parallels the instructor's popular Python books. >> >> For more information on this session, please visit its web page: >> >> http://home.earthlink.net/~python-training/2009-public-classes.htm >> >> For additional background on the class itself, see our home page: >> >> http://home.earthlink.net/~python-training >> >> Thanks for your interest, >> --Python Training Services >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From skip at pobox.com Mon Jan 5 13:47:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 5 Jan 2009 12:47:12 -0600 Subject: Python training in Colorado, January 27-30 In-Reply-To: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> References: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> Message-ID: <18786.21936.349848.917388@montanaro.dyndns.org> lutz> Per my web page, my classes may be available in a different lutz> location later this year (Florida is a strong possibility), but lutz> not in Tulsa, unfortunately. Maybe if Tulsa had more appealing geography or weather??? ;-) Skip From rt8396 at gmail.com Mon Jan 5 14:17:38 2009 From: rt8396 at gmail.com (r) Date: Mon, 5 Jan 2009 11:17:38 -0800 (PST) Subject: Why not Ruby? References: Message-ID: On Jan 5, 7:31 am, "Tim Rowe" wrote: > 2009/1/1 r : > > > I am beginning to think > > the perfect high level language would take the best for Ruby and > > Python. The ultimate language with speed in mind, pythons clear > > syntax, but with shortcuts for gurus. > > I spent quite a few evenings looking at Ruby, and didn't find a single > thing I liked (and I certainly didn't find it "elegant", as the > original poster described it). What do you see in it that you think > would be good in Python? Remember, put in too many shortcuts and > you'll end up with code that's as unmaintainable as Perl! > > -- > Tim Rowe Hello Tim, I think mainly i was just talking out of my bum. I am forced to learn Ruby because it is the only API available for one of my favorite applications. I lament every day that Python was not chosen for the API, not only for myself, but for the poor users who must deal with Ruby's backward way of doing things. I really think Python is the best high level language available today and teaches it's users more than meets-the-eye. I quite enjoy writing Python code, and learned the language very quickly despite the fact that i had no prior programming experience, and very little computer experience in general -- indecently Ruby was the first high level language i tried :) There were a few things initially that i -thought- i liked better about Ruby, but after much consideration, have decided they are not better, and are actually complete rubbish. If i had a choice i would much rather invest my time learning Perl than Ruby. I -will- never get over the use of "end", especially since indentation is allowed. In a language that is as "supposedly" high level as Ruby, this is moronic- monkey-drivel. This complete ludicrisness, coupled with archaic thought processes, is completely redundant, bombastically asinine, and morbidly irreprehensible. Which in turn evaluates to this plague of human excrement we must plow through each and every day! I could could go on and on for hours bashing Ruby, but i should probably stop here before somebody gets upset although i am sure that i will be viciously lambasted for what i have already said.(Pssft-- some people around here are quite touchy!) So let the tongue lashings begin! From code at pizzashack.org Mon Jan 5 14:21:09 2009 From: code at pizzashack.org (Derek Martin) Date: Mon, 5 Jan 2009 13:21:09 -0600 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: <20090105192109.GU28417@dragontoe.org> On Mon, Jan 05, 2009 at 01:23:04PM -0500, Steve Holden wrote: > Even if they really are small-minded or stupid I agree this wouldn't be > helpful behavior. But neither would your characterization of Python's > assignment model as "bizarre" (even ignoring that you SHOUTED IT AT US), > and I have yet to see you admit that such a characterization was, shall > we say, inappropriate. Actually I did, in one of my two most recent posts. But as Steve D'Arpano just pointed out (even though he clearly disagreed with me), such a characterization is subjective, and as such you can't rightly say it's inappropriate. That's the largest part of my point in posting in this thread. Many folks do exactly that, very often. Someone disagrees with you, tries to shed some light on a different perspective, or simply fails to understand something, and some members of this community treat them like heretics, fools, or criminals. I understand why the assignment model works the way it does, and it's quite sensible, *when you understand it*. However, I do also think that to someone who has not encountered such a model before, and who has not had it explained to them, and/or who has not the background to understand why it is implemented that way, it very likely might seem "markedly unusual in appearance, style, or general character and often involving incongruous or unexpected elements;" as dictionary.com defines the term bizarre. So no, I don't think that's a mischaracterization at all. As for using the term in all caps, I did so precisely because it was clear to me that many people here think that it could not be unusual, and I wanted to emphasize the fact that other perspectives exist... That they are not the same as yours does not invalidate them! > It takes little to admit one is in the wrong even when one isn't. I've > had to learn to do it because I often *am* wrong about things. Could you > be persuaded to consider the possibility that you met with a somewhat > hostile reaction (whether or not such a reaction was useful or > necessary) because you were, in a small way, poking people in the side > with a sharp stick? I fully expected to receive a hostile reaction, because I am criticising the behavior of the collective, and supplying a dissenting perspective -- something I knew from the start would trigger such hostility *because it always does*. I have witnessed hostile reactions time and time again in this forum, from some of the same people who are dumping on me for suggesting that the assignment model might be something other than obvious, and from others, for much less: I expect it because I see it in response to nothing more than asking a simple question, when the question displays a clear indication that the poster has missed something critical preventing them from understanding how to achieve their goals. My intent was exactly to point out this behavior, in an attempt to call to people's attention that it is what they are doing, and thereby discourage it. I fully expected a negative response. You in particular have responded quite well, but the rest of the community by and large has sadly not failed to live up to my expectations, even in the face of me saying that that is exactly what they are doing. Quite impressive. Some of the comments from people include the idea that the assignment model is nothing special, if you've encountered any one of a dozen other languages. I didn't realize programming in any of those languages was a prerequisite for posting questions here, or for programming with Python. And that speaks to my ultimate point: Some members of the community seem to make assumptions about what people know or should know, or have experienced, and talk down to people who haven't met their expectations. They meet different perspectives with hostility. Posts which phrase questions in terms commonly used in other programming paradigms are generally even more likely to be met with that same hostility, when they could simply instead explain politely that Python behaves according to a different model than what they are used to. Often this happens, but too often not without someone also letting the OP know what a mindless jerk he is... *This* is the "common understanding" which I'd hoped could be reached... But you were right... it's very difficult for people to admit that they might be wrong. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From GDoermann at gmail.com Mon Jan 5 14:49:09 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 11:49:09 -0800 (PST) Subject: __init__.py and package help Message-ID: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Ok I have read all of the tutorials and documents I could find. I am running Python 2.6 on windows. The problem I am having with packages is that they don't show up! Simple example of what isn't working... Structure- pytest/ Root directory of package __init__.py- code: __all__ = ['folder'] folder/ Another folder in the package __init__.py- code: __all__ = ['hello'] hello.py- code: print('Hello World') Then I append the path to sys.path, and try and import... >>> sys.path.append(r'E:\dev\test\pytest') >>> from pytest.folder import hello Traceback (most recent call last): File "", line 1, in ImportError: No module named pytest.folder What am I doing wrong! It's driving me crazy. Thanks in advance, Greg From GDoermann at gmail.com Mon Jan 5 14:58:09 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 11:58:09 -0800 (PST) Subject: __init__.py and package help References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: <1be7bd39-2642-4fb0-a540-b48ce9f0d7cf@r15g2000prd.googlegroups.com> Ok... I figured it out... you can only import packages via the __all__ = ['subpackage/folder']... if you include a module such as hello.py, it will fail. Go figures I'd find this right after posting here... Greg TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = ['folder'] > folder/ Another folder in the package > __init__.py- code: __all__ = ['hello'] > hello.py- code: print('Hello World') > > Then I append the path to sys.path, and try and import... > > >>> sys.path.append(r'E:\dev\test\pytest') > >>> from pytest.folder import hello > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named pytest.folder > > What am I doing wrong! It's driving me crazy. > Thanks in advance, > Greg From jcd at sdf.lonestar.org Mon Jan 5 15:01:26 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 05 Jan 2009 15:01:26 -0500 Subject: __init__.py and package help In-Reply-To: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: <1231185686.5932.50.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = ['folder'] > folder/ Another folder in the package > __init__.py- code: __all__ = ['hello'] > hello.py- code: print('Hello World') > > Then I append the path to sys.path, and try and import... > > >>> sys.path.append(r'E:\dev\test\pytest') > >>> from pytest.folder import hello > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named pytest.folder > > What am I doing wrong! It's driving me crazy. > Thanks in advance, > Greg You want >>> sys.path.append(r'E:\dev\test') unless your code is in E:\dev\test\pytest\pytest\folder\hello.py > -- > http://mail.python.org/mailman/listinfo/python-list > From GDoermann at gmail.com Mon Jan 5 15:03:24 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 12:03:24 -0800 (PST) Subject: replacement for __file__ in compiled exe Message-ID: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> __file__ command does not work when compiled to exe. It makes since because the file is now in a compressed library. Is there a replacement or something else you can do? The real problem is that when you create an exe of your program with python embedded, you can't always guarantee that your current directory is the directory of your program. I guess when you could just set a registry entry on windows... but it would be nice to have a quick fix for this (like os.path.dirname(__file__)). Thanks, Greg From GDoermann at gmail.com Mon Jan 5 15:05:45 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 12:05:45 -0800 (PST) Subject: __init__.py and package help References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: Thanks J. Cliff Dyer wrote: > On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > > Ok I have read all of the tutorials and documents I could find. I am > > running Python 2.6 on windows. The problem I am having with packages > > is that they don't show up! > > > > Simple example of what isn't working... > > Structure- > > > > pytest/ Root directory of package > > __init__.py- code: __all__ = ['folder'] > > folder/ Another folder in the package > > __init__.py- code: __all__ = ['hello'] > > hello.py- code: print('Hello World') > > > > Then I append the path to sys.path, and try and import... > > > > >>> sys.path.append(r'E:\dev\test\pytest') > > >>> from pytest.folder import hello > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named pytest.folder > > > > What am I doing wrong! It's driving me crazy. > > Thanks in advance, > > Greg > > You want > > >>> sys.path.append(r'E:\dev\test') > > unless your code is in E:\dev\test\pytest\pytest\folder\hello.py > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > From heniser at yahoo.com Mon Jan 5 15:06:13 2009 From: heniser at yahoo.com (Ryan) Date: Mon, 5 Jan 2009 12:06:13 -0800 (PST) Subject: Extending Python with C or C++ Message-ID: I've been using Python for many years now. It's a wonderful language that I enjoy using everyday. I'm now interested in getting to know more about the guts (C/C++) and extending it. But, extending python still seems like a black art to me. Is there anymore docs or info on extending it besides the standard sparse ones (http://www.python.org/ doc/2.5.2/ext/intro.html) that may give me more insight? Is there a class available? How can I learn more about the guts of python? How would one go about following an interest in contributing to the development of python. Thanks, Ryan From ralf at schoenian-online.de Mon Jan 5 15:28:28 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Mon, 05 Jan 2009 21:28:28 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: Message-ID: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts (C/C++) and extending it. But, extending python > still seems like a black art to me. Is there anymore docs or info on > extending it besides the standard sparse ones (http://www.python.org/ > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > class available? How can I learn more about the guts of python? How > would one go about following an interest in contributing to the > development of python. > > Thanks, > > Ryan It is not exactly what you are looking for but nevertheless I am thinking the article "Automatic C Library Wrapping -- Ctypes from the Trenches" may be interesting for you. You can find it in the latest Python Papers issue or simply following the link: http://ojs.pythonpapers.org/index.php/tpp/article/view/71 Regards, Ralf From aleksandr.goretoy at gmail.com Mon Jan 5 15:46:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 20:46:23 +0000 Subject: Python training in Colorado, January 27-30 In-Reply-To: <18786.21936.349848.917388@montanaro.dyndns.org> References: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> <18786.21936.349848.917388@montanaro.dyndns.org> Message-ID: > > lutz> Per my web page, my classes may be available in a different > lutz> location later this year (Florida is a strong possibility), but > lutz> not in Tulsa, unfortunately. > > Maybe if Tulsa had more appealing geography or weather??? ;-) > > Skip Yes, that makes sense to me. Thank you. There's just not much going on here in Tulsa. I moved here about 3 years ago. It's difficult with linux, PHP,python,administration,networking jobs around here. That's one of the reason why I want to boost the blood flow here in Tulsa. I mainly like it here because it's quiet and the people are nice. Depends on what you compare that too though. It's a good place for family. But if your a linux system administrator, programmer then it's a little more difficult for that stuff here. It's not in the market here. Everyone wants .Net this, Microsoft that. I don't like Microsoft, but don't get me wrong I still have to virtualize it sometimes to get certain things done. I just wish that it were the other way around. Not that it won't be sometime in the near future. Simply due to how things are looking for Micr0$pft. I think I heard something about them getting in to linux/unix as base or is capable of running linux side-by-side. Not virtualbox. Something else. But, I think that's a rumor. Can someone verify that for me? Sorry, of topic. That's why I want to do something to change things around. Maybe open a small school(dream?) Monthly meetings or something. so people can hang out, talk geek. I also want to somehow make it so more people dive into linux, python development. The only way that I think this to be conceivable is if people don't have to pay for it to go there. Or maybe just a small cover charge. They learn cool s*** for fun and profit. I think one way to do this is to bring some trainers to the area. Note I haven't done this before. But I want t organize someway for linux, python development to boom around here and spread all around like a virus. Kinda like organized crime only legal. It's fun. :) Then we find a place to do this and boom. We have a 3 day event in python development here in Tulsa. If more people are able to go then there's a better chance for them to get into linux and python. *Some possible room would be:* Picking a flavor of linux, focusing on gentoo,slackware,ubuntu,centos,bsd as > main choice for starters. Installing that flavor and using it for daily > tasks that a person would perform in windows. > > Ubuntu Linux Installation and customization. Merging from windows, command > line, tools, development starting points,best application to use,techniques, > etc... > > Customizing and using c,python(pyrex),bash,php,etc... > > Then we could go around to some companies.Get them to goto to these meetings. It doesn't even have to be companies. But it is preferred. Somehow making it so that every company/person starts to invest at least 33% of there resource/time on linux and python, for starters. The only thing is that, I don't know where to start. to achieve this. I've been thinking about this from a long time ago. I even bought a domain. HackersHappenHere.com in contrast with the Microsoft launch of HeroesHappenHere.com (Are they saying they want to find more Heroes for there crisis they have going on?) We need more hackers. Oh, one question. How would I get someone, say like Ubuntu to sponsor this whole shenanigans? Or Google for that matter. This would actually, inderictly prepare everyone for Chrome for Linux and undeniably move people from IE. What if there were billboards for linux in the USA? How would that effect Microsoft? OUCH. I think someones turf gonna get jacked. People driving by will see Ubuntu, and be like whats that? A new windows? I gotta try it. Need a upgrade. Then they call there local computer guy,etc... Google will definitely have more playing ground on this turf, not that there sandbox isn't big enough as it is. I just really like google. They have a good culture, etc... I would like this culture to spread out side of google though. This I think would be nice. This way there can be events to go across the USA for Hacker Happen Here. People will truly then start seeing some of the power that linux has over windows and how cost effective it use to use it. Not only for servers, but as a desktop too. Most people, all they need is Firefox. Ubuntu has that. For development it's a different story. For me linux is better for development. I know I can do more with it. Windows I think is somewhat restrictive to what a person can do with there computer. Is there something like this for linux already? Am I missing out on something? trying to duplicate some else's efforts? Certainly, I'm not trying to do that. This will hopefully get some of those really good .Net developers to try python,spe,ubuntu,etc...If they haven't yet. All I know is this. I want linux and python to own USA turf. This will also make it so that development and new applications/tools will come out faster. More users, programmers, hackers, etc... Don't get me wrong, It's nothing personal against Microsoft. I just don't like how so many people are wasting there time with it. Especially when there are significantly way better things out there to feed you mind and your computer. In an unrestrictive so much environment as windows. Especially for development. Sorry this is long and off topic. (I need to learn how to write better.) It's just some things I think about sometimes. Please help me some how to achieve this goal. I want people to really harness the true power of there computer and stop eating BS for applications and development environments. If there is more sand, then there's more sand castles, holes and fun. Why would someone want to pass up the ability to use the same thing in so many more ways than one. It doesn't compute. By all means I'm not trying to steal your thread. Please don't feel that way. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:47 PM, wrote: > > lutz> Per my web page, my classes may be available in a different > lutz> location later this year (Florida is a strong possibility), but > lutz> not in Tulsa, unfortunately. > > Maybe if Tulsa had more appealing geography or weather??? ;-) > > Skip > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Mon Jan 5 15:51:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 5 Jan 2009 12:51:31 -0800 (PST) Subject: replacement for __file__ in compiled exe References: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> Message-ID: <00d1a607-7f1a-4b56-8675-1a44d6926541@z28g2000prd.googlegroups.com> On Jan 6, 7:03?am, TechieInsights wrote: > __file__ command does not work when compiled to exe. ?It makes since > because the file is now in a compressed library. ?Is there a > replacement or something else you can do? ?The real problem is that > when you create an exe of your program with python embedded, you can't > always guarantee that your current directory is the directory of your > program. How can you *ever* guarantee that the current directory is the same as the directory in which the program resides? This lack of guarantee is quite independent of whether the "program" is .py, .exe, .bat, .com, etc. Isn't the real problem how to find out which directory the program is in? > ?I guess when you could just set a registry entry on > windows... but it would be nice to have a quick fix for this (like > os.path.dirname(__file__)). if hasattr(sys, 'frozen'): answer = os.path.split(sys.executable)[0] else: answer = os.path.split(sys.argv[0])[0] (maybe) ... your question is a little unclear. HTH, John From aleksandr.goretoy at gmail.com Mon Jan 5 16:05:36 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:05:36 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: Steve, Are you referring to the endless GIL debate? I googled about what you said. I'll look into it here shortly. I just know one thing, is that I need a comparison for regular code and something about how GIL and threading fit in the picture. It makes it easier for me to understand what is going on. Can you post an example? something I can use to truely thread a for loop? The example previously posted show that it works 10 times faster than original for loop. My current program runs for 4.5 hours. I think it will be good to minimize that by 10 times. But if It can do more/faster, than that would be great. TIA for all your help. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:13 PM, Steve Holden wrote: > re, however, that the CPython implementation won't net you any > benefit if all threads are CPU-bound, since due to something called the > GIL (global interpreter lock) no two threads will run concurrently. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Jan 5 16:17:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 16:17:30 -0500 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: alex goretoy wrote: > Steve, > > Are you referring to the endless GIL debate? I googled about what you > said. I'll look into it here shortly. I just know one thing, is that I > need a comparison for regular code and something about how GIL and > threading fit in the picture. It makes it easier for me to understand > what is going on. Can you post an example? something I can use to truely > thread a for loop? The example previously posted show that it works 10 > times faster than original for loop. My current program runs for 4.5 > hours. I think it will be good to minimize that by 10 times. But if It > can do more/faster, than that would be great. TIA for all your help. > Sadly my example doesn't show that. I did, once upon a time, write code that used several hundred threads to send emails, and gave a dramatic speed-up (because of the network-bound nature of the task). Can I presume that your original inquiry was a toy, and that your real problem is also IO-bound? Otherwise I am unsure how you will benefit by threading - if your line-processing tasks don't contain any IO then using a threaded approach will not yield any speed-up at all. The example you quoted achieved its speed-up because a thread releases the GIL while waiting for a network response, allowing other threads to process. Thus it effectively ran all the pings in parallel. Se we need to know a bit more about your 4.5-hour program before we can determine whether threads can help. There is light at the end of the tunnel, however, since even if threads don't work it's possible that the multiprocessing module will (assuming you have multi-processor hardware at your disposal). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From news123 at free.fr Mon Jan 5 16:40:24 2009 From: news123 at free.fr (News123) Date: Mon, 05 Jan 2009 22:40:24 +0100 Subject: My last working day of 2007 In-Reply-To: References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: <49627e48$0$21839$426a34cc@news.free.fr> skip at pobox.com wrote: > Jack> It's simple, a small program running on background, logging the > Jack> title of foreground window. A python script parses the log file > Jack> and then generates chart by matplotlib. > > Jack> I just want to get suggestions to improve it, or know the news > Jack> that somebody had implemented a better one so I can abandon my > Jack> toy. > > For starters, you might figure out how to make it work on a real operating > system which allows multiple active processes. Well the computer can do things in paralell. Most human beings, and according to stereotypes especially male human beings are only single tasking, (like the mouse focus). So if you want to find out what a user is busy with I guess, that the title of the window in focus is probaly a very reasonable indicator. Of course if you want to find out what the computer is busy with, then you should make statistics of the processes and heir cpu loads. bye N > > Nudge, nudge. Wink, wink. Say no more. Say no more. ;-) > From aleksandr.goretoy at gmail.com Mon Jan 5 16:43:00 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:43:00 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: > > Se we need to know a bit more about your 4.5-hour program before we can > determine whether threads can help. There is light at the end of the > tunnel, however, since even if threads don't work it's possible that the > multiprocessing module will (assuming you have multi-processor hardware > at your disposal). What my program is doing is sending each line to a function that processes it via pycurl(with urllib fallback),mysqlDB(with _mysql fallback). It check the mysql database to see if this line exists. If it doesn't then it sends it either via mysql query or pycurl. Depending on the option set in the functions. Some sections of the function have time.sleep(6) in them. Otherwise things won't work. This considerably slows down performance. If I thread all lines then it will process more at the same time. So that means there will be like 10 or set amount threads running doing all steps in the functions. posting forms, performing queries and waiting for form postings to process on the server, etc... I hope this adds more light at the end of that tunnel. It currently works under my ubuntu install of python(2.5.x) and bt's python(2.4.3). Then reason why I added a fallback to MySQLdb and pycurl is then a person can install this on a server that is hosted elsewhere. Where you can't install python modules, due to permissions and such. I want it to work everywhere. There's alot more to this application, I'm not sure I can disclose at the moment. Seeing as it can be used for good or bad. I don't want it to get in the wrong hands if it's public. OTOH, I think I'll make it public. That's all up in the air at the moment. One thing it that it does make life easier for me. A lot easier. Although, I haven't made money with it. Yet. Plus, I want to make pyGTK frontend for it. Looking into that too. I wouldn't be against a private team assembling to create this though. As long as I can get money out of it somehow. Cuz I'm broke. and I live with my mom. Not sure how anyone can help me there. But I'll throw it up in the air for all to see. Maybe somethings comes out of it. This program is an idea I've been building inside my garage(my room) for about a year and a half. Built in PHP and python, now. Would something that uses pycurl,mysql be good for threading? It doesn't run on SMP but maybe one day. I also need to look into how to make a python package out of it. I researched some stuff awhile ago, but I didn't quite need it then. I just wanted to see what I'm getting into. Any other stuff about this would be appreciated to. Although of topic. Sorry. By the way, I wanted to really thank everyone for all your help. It means a lot to me. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 9:17 PM, Steve Holden wrote: > I did, once upon a time, write code > that used several hundred threads to send emails, and gave a dramatic > speed-up (because of the network-bound nature of the task). Can I > presume that your original inquiry was a toy, and that your real problem > is also IO-bound? Otherwise I am unsure how you will benefit by > threading - if your line-processing tasks don't contain any IO then > using a threaded approach will not yield any speed-up at all. > > The example you quoted achieved its speed-up because a thread releases > the GIL while waiting for a network response, allowing other threads to > process. Thus it effectively ran all the pings in parallel. > > Se we need to know a bit more about your 4.5-hour program before we can > determine whether threads can help. There is light at the end of the > tunnel, however, since even if threads don't work it's possible that the > multiprocessing module will (assuming you have multi-processor hardware > at your disposal). > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aixer77 at gmail.com Mon Jan 5 17:26:06 2009 From: aixer77 at gmail.com (Kangkook Jee) Date: Mon, 05 Jan 2009 17:26:06 -0500 Subject: Measuring bytes of packet sent from python application Message-ID: <49628901$0$90271$14726298@news.sunsite.dk> Hi, all I'd like to measure number of bytes sent(or recv'd) from my python application. Does anyone have any idea how can I achieve this? I tried to do this by tracing some socket calls (send, sendto, sendAll) using 'metaclass' but I could find exactly place that I can put this in. My application runs some number of protocols (bittorrent, xmlrpc ..) in it and will be measured for a couple of hours. Thanks a lot for your help, in advance /Kangkook From steve at REMOVE-THIS-cybersource.com.au Mon Jan 5 17:28:59 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 22:28:59 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: <01728080$0$8693$c3e8da3@news.astraweb.com> On Mon, 05 Jan 2009 13:21:09 -0600, Derek Martin wrote: > Some of the comments from people include the idea that the assignment > model is nothing special, if you've encountered any one of a dozen other > languages. I didn't realize programming in any of those languages was a > prerequisite for posting questions here, or for programming with Python. It's not. But the tone of your argument suggests you think that matching the named bins assignment model of the 1970s should be a prerequisite for all new programming languages. There are, in general, four types of programmers new to Python. In no particular order: (1) People with no programming experience at all. They won't have any problems with Python's assignment model because they have no preconceived ideas about how assignment should work. (2) People who are used to name binding in Ruby, Java, etc. and so will find Python's assignment model more or less identical. (3) Those who come from an entirely different programming model, say, Forth or Haskell. For them, Python's assignment model is going to be the least of their worries. (4) People who are used to the named bins model from C, Pascal or Fortran, who will find some unusual corner cases where Python behaves differently to their mental model of assignment (but not for simple arithmetic using numbers). Python is accessible to *all* of the above groups, although naturally some will need to put in more effort in different directions than others. The tone of reproach in your posts suggests that you believe that the people in group 4 are more authentic programmers whose opinions are more correct than those in groups 1-3. I do not think there is any good reason to believe that group 4 is more special than the other groups. Nor do I believe that newly created languages (as Python was, a decade and a half ago) should be limited to following the named bin assignment model for fear that C etc programmers will be put off by the (supposed) bizarreness of name binding. Speaking as a former Pascal programmer, I think most C, Fortran and Pascal programmers are far too smart for that. > And that speaks to my ultimate point: Some members of the community > seem to make assumptions about what people know or should know, or have > experienced, and talk down to people who haven't met their expectations. > They meet different perspectives with hostility. In my experience, two perspectives are likely to be met with hostility: * those which arrogantly assume that they are the One True and Correct perspective and all others are inferior and wrong; and * those which ignorantly assume that they are the only perspective possible. Your first post in this topic made the extraordinarily arrogant and incorrect claim that: [quote] What the Python community often overlooks, when this discussion again rears its ugly head (as it seems to every other hour or so), is that its assignment model is BIZARRE, as in it's conceptually different from virtually all other languages substantially taught in undergraduate computer science programs. [end quote] We can see some pretty poor assumptions right there: * That the Python community is capable of uniformly overlooking Python's differences from other languages. * That only languages "substantially taught" in undergraduate CS courses matter. It seems that you don't include in the Python community all those who use the term "name binding" instead of variable assignment specifically because it gives new users a clue that Python is not the same as C. You've also missed out on probably twenty years of CS where Java (using the same assignment model as Python!) has been *the* language of choice for undergrad CS, not to mention those introductory courses which use Python. And then you're shocked, SHOCKED!!! that people respond sharply. How different do you think the response would have been if you had said: "What we in the Python community should try to remember is that for those new to the language, there can sometimes be preconceived ideas about how assignment works that clashes with Python's assignment model. From my own perspective, I found the differences between Python's name binding model and the named-bins model of C/Pascal/Fortran confusing at first, and to be honest, I still get caught by those differences. Naturally this is a general problem for every language, Python is hardly unique, but please remember not to bite the newbies just because they are still thinking in some other language." -- Steven From prologic at shortcircuit.net.au Mon Jan 5 17:30:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 08:30:46 +1000 Subject: greenlets and how they can be used In-Reply-To: <496253F8.4070905@gmx.net> References: <495FB40A.9060606@gmx.net> <496253F8.4070905@gmx.net> Message-ID: On Tue, Jan 6, 2009 at 4:39 AM, Benjamin Walkenhorst wrote: > James Mills wrote: >> On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst wrote: >>> POE was one of the nicest software frameworks I have ever used, and I've been continuously frustrated by the lack of something like it in other languages such as Python or Ruby. >> >> It does exist :) It's called circuits. >> Or at least circuits is a framework that I develop >> and build which sounds very similar to POE in >> some ways :) (snip) > Then, one very sad day, a Gentoo upgrade broke POE. I got it working again a few months later, but by then I had somehow lost interest in Perl and discovered the beauty of Python, where my search for an appropriate replacement was frustrated (Twisted seemed to be the closest equivalent, but it seemed overly complex to me, at least I never got the hang of it...). It would seem to me that circuits is quite similar to POE - I've never really used or played with Perl though and probably will never :) > Or, to put it briefly, I would really like to take a look at that sometime. If you intend to release it in any form, I would like to hear about it. Currently released: circuits-1.0b1 See: http://trac.softcircuit.com.au/circuits/ > Oh. I see, it already IS available. How nice!!! That is going to be an interesting evening! > Oh, and thank you very much for bringing this to my attention!!! Your very welcome ... circuits is by no means a replacement or competitor to Twisted - it has very different design goals and architecture (nicer/simpler ihmo). That said though anything that Twisted can do, circuits can do - I've deliberately tried to keep the Component Library as simple and straight forward as possible. Happy hacking! cheers James From collin.day.0 at gmail.com Mon Jan 5 17:36:12 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 5 Jan 2009 14:36:12 -0800 (PST) Subject: Tkinter - problem closing window References: <3bd8f10c-abba-4e82-9795-0de7612ac7f0@s36g2000vbp.googlegroups.com> Message-ID: <18f37013-f140-465e-9393-8ea17c3e5574@35g2000pry.googlegroups.com> On Jan 5, 9:21?am, Roger wrote: > On Jan 5, 11:52?am, Collin D wrote: > > > > > On Jan 5, 6:25?am, "Djames Suhanko" wrote: > > > > Hello! > > > I'm sorry my terrible english (my native language is portuguese). > > > I has a litle program that open another window. When I close de root > > > window in quit button, I need clicking 2 times to close. is where the > > > problem? > > > > The source: > > > ? 1 #!/usr/bin/env python > > > ? 2 from Tkinter import * > > > ? 3 import sys > > > ? 4 import random > > > ? 5 class App: > > > ? 6 ?def __init__(self, master): > > > ? 7 ? ?frame = Frame(master) > > > ? 8 ? ?frame.pack() > > > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > > > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > > > ?10 ? ?rotulo.pack() > > > ?11 > > > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > > > command=frame.quit,borderwidth=1) > > > ?13 ? ?self.button.pack(side=LEFT) > > > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > > > command=self.say_hi,borderwidth=1) > > > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > > > ?16 > > > ?17 ?def gera_seis(self): > > > ?18 ? ?a = {} > > > ?19 ? ?for i in range(6): > > > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > > > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > > > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > > > ?22 ? ?return resultadoA > > > ?23 > > > ?24 ?def say_hi(self): > > > ?25 ? ?resultado = self.gera_seis() > > > ?26 ? ?raiz = Tk() > > > ?27 ? ?F = Frame(raiz) > > > ?28 ? ?F.pack() > > > ?29 ? ?hello = Label(F, text=resultado) > > > ?30 ? ?hello.pack() > > > ?31 ? ?F.mainloop() > > > ?32 > > > ?33 root = Tk() > > > ?34 root.title("$$$ Loteria $$$") > > > ?35 app = App(root) > > > ?36 root.mainloop() > > > > -- > > > Djames Suhanko > > > LinuxUser 158.760 > > > Also for style, you might want to group the import lines so they look > > like this: > > > from Tkinter import * > > import sys, random > > > A bit more pythonic. :P > > In that case you probably want to take out the 'from' import and: > > import Tkinter, sys, random > > in order to avoid any namespace issues especially if you have a large > project with lots of gui manipulations. ?But that's just me being > pedantic. ;) I agree... you could have conflicting functions.. not fun. XD From tjreedy at udel.edu Mon Jan 5 17:37:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 17:37:43 -0500 Subject: Extending Python with C or C++ In-Reply-To: References: Message-ID: Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts The 'guts' of Python the language include the object model, namespaces (including modules), and the statement and infix-expression syntax. > (C/C++) and extending it. Now you are asking about CPython, the leading computer implementation. > But, extending python still seems like a black art to me. > Is there anymore docs or info on > extending it besides the standard sparse ones (http://www.python.org/ > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > class available? If you want to connect CPython to Python-oblivious code written in C, Swig (with C code) and Ctypes (with Python code) are the main choices. If you want to write new Python-aware (and specific) code, you can use the CPython C-API functions. Extensions in C are written as importable modules. The interface for such is not difficult; existing examples should be a good guide. > How can I learn more about the guts of python? The 'guts' of an implementation follow from the 'guts' of the language. There must be a syntax parser and compiler to internal form, evaluation loop, and implemenations of built-in constants, functions, classes, and modules. CPython's source tree begins as http://svn.python.org/view/ You might actually want to start at http://svn.python.org/view/python/trunk/ Note: if you click a filename, such as 'setup.py', you get the entire revision history with checkin messages. If you click the displayed revision number, such as '67978', you get the latest checkin message and the current version of the file. > How would one go about following an interest in contributing to the > development of python. Read http://python.org/dev/ and start following the pydev list, mirrored to gmane.comp.python.devel at news.gmane.org. Terry Jan Reedy From tjreedy at udel.edu Mon Jan 5 17:54:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 17:54:19 -0500 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' In-Reply-To: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: Gilles Ganault wrote: > Hello > > I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject >>From = "me at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > To = email Why is 'email' renamed 'To'? > msg['To'] = email > > #print To > #(u'dummy at acme.com',) Why are these line comments? Why is the string enclosed in a tuple? > #AttributeError: 'tuple' object has no attribute 'lstrip' True. Only strings have lstrip method. > #server.sendmail(From,[To],msg.as_string()) Ditto. This looks looks a line from a doc. If you want help interpreting an error message, copy and paste the *entire traceback* without editing. > > server.quit > > connection.close(True) > ====== > > Does someone know what is wrong with the above? Why do you think anything is wrong? Post the actual error message separate from the code that generates the error message. > Does email choke on Unicode? tjr From jgardner at jonathangardner.net Mon Jan 5 17:59:44 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 5 Jan 2009 14:59:44 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> On Jan 5, 2:26?pm, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my python > application. Does anyone have any idea how can I achieve this? > > I tried to do this by tracing some socket calls (send, sendto, sendAll) > ? using 'metaclass' but I could find exactly place that I can put this in. > > My application runs some number of protocols (bittorrent, xmlrpc ..) in > it and will be measured for a couple of hours. > A good universal tool on the Linux platform is tcpdump. It takes some learning, but is very useful for this kind of task. You can use a tool like ethereal to visualize the data that tcpdump gathers. From GDoermann at gmail.com Mon Jan 5 18:00:34 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 15:00:34 -0800 (PST) Subject: replacement for __file__ in compiled exe References: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> <00d1a607-7f1a-4b56-8675-1a44d6926541@z28g2000prd.googlegroups.com> Message-ID: <290f4077-c794-4f60-bf0e-49f2c8733584@z27g2000prd.googlegroups.com> Yes, that is my exact question. How do you get the file path of your script/program. Normally in python you can use __file__ and it will return the file path of the script you are in, however, when you compile the script to exe py2exe (or whatever util you are using) compresses them into a zip folder... not usually a problem, except when you want the access the file path of the exe. Thanks for the answer... I should have thought of that all along... just look on the system path. Sometimes the answer was right in front of your face the whole time... Greg On Jan 5, 1:51?pm, John Machin wrote: > On Jan 6, 7:03?am, TechieInsights wrote: > > > __file__ command does not work when compiled to exe. ?It makes since > > because the file is now in a compressed library. ?Is there a > > replacement or something else you can do? ?The real problem is that > > when you create an exe of your program with python embedded, you can't > > always guarantee that your current directory is the directory of your > > program. > > How can you *ever* guarantee that the current directory is the same as > the directory in which the program resides? This lack of guarantee is > quite independent of whether the "program" is .py, .exe, .bat, .com, > etc. Isn't the real problem how to find out which directory the > program is in? > > > ?I guess when you could just set a registry entry on > > windows... but it would be nice to have a quick fix for this (like > > os.path.dirname(__file__)). > > ? ? if hasattr(sys, 'frozen'): > ? ? ? ? answer = os.path.split(sys.executable)[0] > ? ? else: > ? ? ? ? answer = os.path.split(sys.argv[0])[0] > > (maybe) ... your question is a little unclear. > > HTH, > John From rhodri at wildebst.demon.co.uk Mon Jan 5 18:05:43 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 05 Jan 2009 23:05:43 -0000 Subject: why cannot assign to function call In-Reply-To: <01728080$0$8693$c3e8da3@news.astraweb.com> References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, 05 Jan 2009 22:28:59 -0000, Steven D'Aprano wrote: > * That only languages "substantially taught" in undergraduate CS courses > matter. As an aside, I use only one of the languages I was taught in my Computer Science course, and that only for poking my EMACS configuration. Every other language I use (yes, including C) I learned afterwards. Moral: times change. -- Rhodri James *-* Wildebeeste Herder to the Masses From aixer77 at gmail.com Mon Jan 5 18:23:10 2009 From: aixer77 at gmail.com (Kangkook Jee) Date: Mon, 05 Jan 2009 18:23:10 -0500 Subject: Measuring bytes of packet sent from python application In-Reply-To: <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> Message-ID: <4962965f$0$90276$14726298@news.sunsite.dk> Jonathan Gardner wrote: > On Jan 5, 2:26 pm, Kangkook Jee wrote: >> I'd like to measure number of bytes sent(or recv'd) from my python >> application. Does anyone have any idea how can I achieve this? >> >> I tried to do this by tracing some socket calls (send, sendto, sendAll) >> using 'metaclass' but I could find exactly place that I can put this in. >> >> My application runs some number of protocols (bittorrent, xmlrpc ..) in >> it and will be measured for a couple of hours. >> > > A good universal tool on the Linux platform is tcpdump. It takes some > learning, but is very useful for this kind of task. You can use a tool > like ethereal to visualize the data that tcpdump gathers. Thanks a lot Jonathan That seems like a good solution for my issue but how can I distinguish traffics from my application to others? I'm still struggling to solve it within python process since it looks cleaner but it doesn't seems to be easy at all. From jgardner at jonathangardner.net Mon Jan 5 18:36:42 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 5 Jan 2009 15:36:42 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On Jan 5, 3:23?pm, Kangkook Jee wrote: > Jonathan Gardner wrote: > > A good universal tool on the Linux platform is tcpdump. It takes some > > learning, but is very useful for this kind of task. You can use a tool > > like ethereal to visualize the data that tcpdump gathers. > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > There are a variety of ways to distinguish traffic with tcpdump and ethereal. Usually you should have some idea of what ports or hosts your traffic is going to. If not, then you will have some indicator within the packets themselves. Note that tcpdump is remarkable since it can identify TCP sessions, and not just individual packets. > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. Replacing a lower-level component of a 3rd party library is difficult at best. If you can get it to work without rewriting the library, congratulations. At the very least, you'll probably have to do some low-level things within the libraries themselves. From aleksandr.goretoy at gmail.com Mon Jan 5 18:38:41 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 23:38:41 +0000 Subject: multiprocessing vs thread performance In-Reply-To: References: Message-ID: There doesn't seem to be any good examples on POSH or it's not clear to me. For when using with a for loop like mk is doing who started this thread. How would somethings like this be possible to do with POSH? The example show how to share variables between processes/threads but nothing about How the thread starts or a for loop. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sat, Jan 3, 2009 at 1:31 PM, Nick Craig-Wood wrote: > mk wrote: > > After reading http://www.python.org/dev/peps/pep-0371/ I was under > > impression that performance of multiprocessing package is similar to > > that of thread / threading. However, to familiarize myself with both > > packages I wrote my own test of spawning and returning 100,000 empty > > threads or processes (while maintaining at most 100 processes / threads > > active at any one time), respectively. > > > > The results I got are very different from the benchmark quoted in PEP > > 371. On twin Xeon machine the threaded version executed in 5.54 secs, > > while multiprocessing version took over 222 secs to complete! > > > > Am I doing smth wrong in code below? > > Yes! > > The problem with your code is that you never start more than one > process at once in the multiprocessing example. Just check ps when it > is running and you will see. > > My conjecture is that this is due to the way fork() works under unix. > I think that when the parent forks it yields the CPU to the child. > Because you are giving the child effectively no work to do it returns > immediately, re-awakening the parent, thus serialising your jobs. > > If you give the children some work to do you'll see a quite different > result. I gave each child time.sleep(1) to do and cut down the total > number to 10,000. > > $ ./test_multiprocessing.py > == Process 1000 working == > == Process 2000 working == > == Process 3000 working == > == Process 4000 working == > == Process 5000 working == > == Process 6000 working == > == Process 7000 working == > == Process 8000 working == > == Process 9000 working == > == Process 10000 working == > === Main thread waiting for all processes to finish === > Total time: 101.382129192 > > $ ./test_threading.py > == Thread 1000 working == > == Thread 2000 working == > == Thread 3000 working == > == Thread 4000 working == > == Thread 5000 working == > == Thread 6000 working == > == Thread 7000 working == > == Thread 8000 working == > == Thread 9000 working == > == Thread 10000 working == > Total time: 100.659118176 > > So almost identical results and as expected - we ran 10,000 sleep(1)s > in 100 seconds so we must have been running 100 simultaneously. > > If you replace the "time.sleep(1)" with "for _ in xrange(1000000): > pass" you get this much more interesting answer on my dual core linux > laptop, showing nicely the effect of the contention on the python > global interpreter lock and how multiprocessing avoids it. > > $ ./test_multiprocessing.py > == Process 1000 working == > == Process 2000 working == > == Process 3000 working == > == Process 4000 working == > == Process 5000 working == > == Process 6000 working == > == Process 7000 working == > == Process 8000 working == > == Process 9000 working == > == Process 10000 working == > === Main thread waiting for all processes to finish === > Total time: 266.808327913 > > $ ./test_threading.py > == Thread 1000 working == > == Thread 2000 working == > == Thread 3000 working == > == Thread 4000 working == > == Thread 5000 working == > == Thread 6000 working == > == Thread 7000 working == > == Thread 8000 working == > == Thread 9000 working == > == Thread 10000 working == > Total time: 834.81882 > > -- > Nick Craig-Wood -- http://www.craig-wood.com/nick > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at opensuse.us Mon Jan 5 18:42:00 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 5 Jan 2009 15:42:00 -0800 Subject: Is there a best linux distro for a python hobbyist? Message-ID: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... And so on. From prologic at shortcircuit.net.au Mon Jan 5 18:44:45 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 09:44:45 +1000 Subject: Measuring bytes of packet sent from python application In-Reply-To: <49628901$0$90271$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: On Tue, Jan 6, 2009 at 8:26 AM, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my python > application. Does anyone have any idea how can I achieve this? > > I tried to do this by tracing some socket calls (send, sendto, sendAll) > using 'metaclass' but I could find exactly place that I can put this in. > > > My application runs some number of protocols (bittorrent, xmlrpc ..) in > it and will be measured for a couple of hours. > > Thanks a lot for your help, in advance Something like this perhaps ? Example code follows ... NB: This uses circuits (1) $ ./test.py smtp-int.vision6.com.au 25 Trying smtp-int.vision6.com.au... Connected to smtp-int.vision6.com.au 220 marvin.vision6.com.au ESMTP EHLO localhost 250-marvin.vision6.com.au 250-AUTH LOGIN CRAM-MD5 PLAIN 250-AUTH=LOGIN CRAM-MD5 PLAIN 250-PIPELINING 250 8BITMIME QUIT 221 marvin.vision6.com.au Connection closed Traffic In: 179 bytes Out: 20 bytes --------------------------------------------------------- http://codepad.org/V32fsqKt Note the Stats component on line 60. --------------------------------------------------------- cheers James From aleksandr.goretoy at gmail.com Mon Jan 5 18:45:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 23:45:23 +0000 Subject: Measuring bytes of packet sent from python application In-Reply-To: <4962965f$0$90276$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: Have you looked into scapy? www.secdev.org/projects/*scapy*/ There's another one, it comes with python I think. Can't seem to remember the name. I may be mistaken though. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 11:23 PM, Kangkook Jee wrote: > Jonathan Gardner wrote: > >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >> >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, sendAll) >>> using 'metaclass' but I could find exactly place that I can put this in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) in >>> it and will be measured for a couple of hours. >>> >>> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. >> > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.pruitt at gmail.com Mon Jan 5 19:18:29 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Mon, 5 Jan 2009 18:18:29 -0600 Subject: Regex Generator From Multiple Files Message-ID: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> I am looking for a way given a number of files, say 3, that represent technical support tickets in the same format to generate regular expressions for the different fields automatically. An example from of one line from each file: Date: 12/30/2008 Room: 457 Building: Main Date: 12/31/2008 Room: A21 Building: Annex Date: 1/4/2009 Room: L69 Building: Library The program would then, possibly using the python diff library, generate the regular expression needed to parse out different fields. In this case it might return a tuple like ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.*)[\w]+$") that would match each of the fields based on the common data and sort of assume that what doesn't change between them is data we are looking for. -------------- next part -------------- An HTML attachment was scrubbed... URL: From heniser at yahoo.com Mon Jan 5 19:27:34 2009 From: heniser at yahoo.com (Ryan) Date: Mon, 5 Jan 2009 16:27:34 -0800 (PST) Subject: Extending Python with C or C++ References: Message-ID: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> On Jan 5, 2:37 pm, Terry Reedy wrote: > Ryan wrote: > > I've been using Python for many years now. It's a wonderful language > > that I enjoy using everyday. I'm now interested in getting to know > > more about the guts > > The 'guts' of Python the language include the object model, namespaces > (including modules), and the statement and infix-expression syntax. > > > (C/C++) and extending it. > > Now you are asking about CPython, the leading computer implementation. > > > But, extending python still seems like a black art to me. > > > Is there anymore docs or info on > > > extending it besides the standard sparse ones (http://www.python.org/ > > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > > class available? > > If you want to connect CPython to Python-oblivious code written in C, > Swig (with C code) and Ctypes (with Python code) are the main choices. > If you want to write new Python-aware (and specific) code, you can use > the CPython C-API functions. Extensions in C are written as importable > modules. The interface for such is not difficult; existing examples > should be a good guide. > > > How can I learn more about the guts of python? > > The 'guts' of an implementation follow from the 'guts' of the language. > There must be a syntax parser and compiler to internal form, > evaluation loop, and implemenations of built-in constants, functions, > classes, and modules. CPython's source tree begins ashttp://svn.python.org/view/ > You might actually want to start athttp://svn.python.org/view/python/trunk/ > Note: if you click a filename, such as 'setup.py', you get the entire > revision history with checkin messages. > If you click the displayed revision number, such as '67978', you get the > latest checkin message and the current version of the file. > > > How would one go about following an interest in contributing to the > > development of python. > > Readhttp://python.org/dev/ > and start following the pydev list, mirrored to gmane.comp.python.devel > at news.gmane.org. > > Terry Jan Reedy Thanks Terry! This clarifies many of the concepts that I want to get started to dive deeper into CPython. 1. The abstract Python Language (not specific to any implementation) 2. The CPython implementation (http://svn.python.org/view/python/ trunk/) 3. Extending CPython by connecting it to Python-oblivious code written in C with Ctypes (Ralf's suggestion is good for this) 4. Extending CPython by connecting it to Python-aware (and specific) code using the CPython C-API functions (http://docs.python.org/c-api/) From david.lyon at preisshare.net Mon Jan 5 19:39:25 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Mon, 05 Jan 2009 19:39:25 -0500 Subject: Is there a best linux distro for a python =?UTF-8?Q?hobbyist=3F?= In-Reply-To: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: Hi, I would have to put in a vote for Ubuntu. There seems to be a working ubuntu package for most of the things that I have tried. Instead of having to use a pythonic package - just get one from the os. As for the things you mention.. give it a go On Mon, 5 Jan 2009 15:42:00 -0800, "member thudfoo" wrote: > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > And so on. From google at mrabarnett.plus.com Mon Jan 5 19:48:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jan 2009 00:48:20 +0000 Subject: Regex Generator From Multiple Files In-Reply-To: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> References: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> Message-ID: <4962AA54.7030500@mrabarnett.plus.com> James Pruitt wrote: > I am looking for a way given a number of files, say 3, that represent > technical support tickets in the same format to generate regular > expressions for the different fields automatically. > > An example from of one line from each file: > Date: 12/30/2008 Room: 457 Building: Main > Date: 12/31/2008 Room: A21 Building: Annex > Date: 1/4/2009 Room: L69 Building: Library > > The program would then, possibly using the python diff library, generate > the regular expression needed to parse out different fields. In this > case it might return a tuple like > ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.*)[\w]+$") > that would match each of the fields based on the common data and sort of > assume that what doesn't change between them is data we are looking for. > Why not just assume that each field consists of a word terminated by a colon, then some text, then the next field or the end of the line? From fakeaddress at nowhere.org Mon Jan 5 19:49:59 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 05 Jan 2009 16:49:59 -0800 Subject: socket send help In-Reply-To: References: Message-ID: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Gabriel Genellina wrote: > Bryan Olson escribi?: > >> Gabriel Genellina wrote: >>> greywine at gmail.com escribi?: >> [...] >>>> A simple server: >>>> >>>> from socket import * >>>> myHost = '' >>> Try with myHost = '127.0.0.1' instead - a firewall might be blocking >>> your server. >> >> Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty >> string is that a firewall might *not* be blocking your server. >> >> The Python sockets module interprets the empty string as INADDR_ANY, >> which means to bind to all available adapters including the loopback, >> A.K.A localhost, A.K.A '127.0.0.1'. > > I thought a firewall would block an attempt to bind to any routeable > address, but not to localhost. So using INADDR_ANY would be rejected. So you thought this would fail at bind()? My understanding is that firewalls block network traffic, not system calls. -- --Bryan From mdw at distorted.org.uk Mon Jan 5 19:55:06 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 00:55:06 +0000 (UTC) Subject: Rich Comparisons Gotcha References: <014c51d9$0$20670$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There is nothing to blame them for. This is the correct behaviour. NaNs > should *not* compare equal to themselves, that's mathematically > incoherent. Indeed. The problem is a paucity of equality predicates. This is hardly surprising: Common Lisp has four general-purpose equality predicates (EQ, EQL, EQUAL and EQUALP), and many more type-specific ones (=, STRING=, STRING-EQUAL (yes, I know...), CHAR=, ...), and still doesn't really have enough. For example, EQUAL compares strings case-sensitively, but other arrays are compared by address; EQUALP will recurse into arbitrary arrays, but compares strings case-insensitively... For the purposes of this discussion, however, it has enough to be able to distinguish between * numerical comparisons, which (as you explain later) should /not/ claim that two NaNs are equal, and * object comparisons, which clearly must declare an object equal to itself. For example, I had the following edifying conversation with SBCL. CL-USER> ;; Return NaNs rather than signalling errors. (sb-int:set-floating-point-modes :traps nil) ; No value CL-USER> (defconstant nan (/ 0.0 0.0)) NAN CL-USER> (loop for func in '(eql equal equalp =) collect (list func (funcall func nan nan))) ((EQL T) (EQUAL T) (EQUALP T) (= NIL)) CL-USER> That is, a NaN is EQL, EQUAL and EQUALP to itself, but not = to itself. (Due to the vagaries of EQ, a NaN might or might not be EQ to itself or other NaNs.) Python has a much more limited selection of equality predicates -- in fact, just == and is. The is operator is Python's equivalent of Lisp's EQ predicate: it compares objects by address. I can have a similar chat with Python. In [12]: nan = float('nan') In [13]: nan is nan Out[13]: True In [14]: nan == nan Out[14]: False In [16]: nan is float('nan') Out[16]: False Python numbers are the same as themselves reliably, unlike in Lisp. But there's no sensible way of asking whether something is `basically the same as' nan, like Lisp's EQL or EQUAL. I agree that the primary equality predicate for numbers must be the numerical comparison, and NaNs can't (sensibly) be numerically equal to themselves. Address comparisons are great when you're dealing with singletons, or when you carefully intern your objects. In other cases, you're left with ==. This puts a great deal of responsibility on the programmer of an == method to weigh carefully the potentially conflicting demands of compatibility (many other libraries just expect == to be an equality operator returning a straightforward truth value, and given that there isn't a separate dedicated equality operator, this isn't unreasonable), and doing something more domain-specifically useful. It's worth pointing out that numpy isn't unique in having == not return a straightforward truth value. The SAGE computer algebra system (and sympy, I believe) implement the == operator on algebraic formulae so as to construct equations. For example, the following is syntactically and semantically Python, with fancy libraries. sage: var('x') # x is now a variable x sage: solve(x**2 + 2*x - 4 == 1) [x == -sqrt(6) - 1, x == sqrt(6) - 1] (SAGE has some syntactic tweaks, such as ^ meaning the same as **, but I didn't use them.) I think this is an excellent use of the == operator -- but it does have some potential to interfere with other libraries which make assumptions about how == behaves. The SAGE developers have been clever here, though: sage: 2*x + 1 == (2 + 4*x)/2 2*x + 1 == (4*x + 2)/2 sage: bool(2*x + 1 == (2 + 4*x)/2) True sage: bool(2*x + 1 == (2 + 4*x)/3) False I think Python manages surprisingly well with its limited equality predicates. But the keyword there is `surprisingly' -- and it may not continue this trick forever. -- [mdw] From prologic at shortcircuit.net.au Mon Jan 5 19:59:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 10:59:46 +1000 Subject: socket send help In-Reply-To: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: On Tue, Jan 6, 2009 at 10:49 AM, Bryan Olson wrote: >> I thought a firewall would block an attempt to bind to any routeable >> address, but not to localhost. So using INADDR_ANY would be rejected. No. > My understanding is that firewalls block network traffic, not system calls. This is correct. Firewalls (real firewalls) can only act on incoming and outgoing traffic on the IP level. cheers James From prologic at shortcircuit.net.au Mon Jan 5 20:02:43 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 11:02:43 +1000 Subject: socket send help In-Reply-To: References: Message-ID: On Wed, Dec 24, 2008 at 3:59 PM, greywine at gmail.com wrote: (snip) > If I run testserver.py via the cmd prompt in Windows XP and then the > testclient.py program, I get the following error: > > Traceback (most recent call last): > File "C:\Python30\testclient.py", line 12, in > s.send('Hello world') # send the data > TypeError: send() argument 1 must be string or buffer, not str > > This happens in 2.6 or 3.0 and with different example client & server > programs from the web. What am I missing? I'm sorry I should have answered sooner :) Python 3.x (and probably 2.6+) required that you use bytes to send your data through sockets rather than strings. This was part of the revamp for better unicode support irrc. cheers James From zac256 at gmail.com Mon Jan 5 20:04:30 2009 From: zac256 at gmail.com (Zac Burns) Date: Mon, 5 Jan 2009 17:04:30 -0800 Subject: cPickle vs pickle discrepancy Message-ID: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Greetings, I have a module that attempts to pickle classes defined in that module. I get an error of the form: PicklingError: Can't pickle : import of module Module.SubModule failed when using cPickle (protocol -1, python version 2.5.1). The module has already been imported and is in sys.modules when the exception is raised. Using pickle instead of cPickle works, but the section of the code is performance critical. How can this be worked around? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From aleksandr.goretoy at gmail.com Mon Jan 5 20:11:44 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 01:11:44 +0000 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: +1 for ubuntu -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 12:39 AM, wrote: > Hi, > > I would have to put in a vote for Ubuntu. > > There seems to be a working ubuntu package for most of the things that I > have tried. Instead of having to use a pythonic package - just get one from > the os. > > As for the things you mention.. give it a go > > On Mon, 5 Jan 2009 15:42:00 -0800, "member thudfoo" > wrote: > > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > > And so on. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 5 20:14:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 11:14:10 +1000 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: On Tue, Jan 6, 2009 at 11:11 AM, alex goretoy wrote: > +1 for ubuntu +1 for Ubuntu also (for the novice and ex-windows user(s)) +2 for CRUX (1) cheers James 1. http://crux.nu/ From floss at lex.hider.name Mon Jan 5 20:16:08 2009 From: floss at lex.hider.name (Lex Hider) Date: Tue, 6 Jan 2009 12:16:08 +1100 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Probably not a big difference in most cases between debian, ubuntu, fedora. The latter two may be more likely to have more recent versions. I'm pretty sure ubuntu is the only one which currently has python 3.0 in it's archives [no, it's not the default version]. On 06/01/2009, member thudfoo wrote: > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > And so on. > -- > http://mail.python.org/mailman/listinfo/python-list > From mdw at distorted.org.uk Mon Jan 5 20:24:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 01:24:58 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > I've already mentioned NaNs. Sentinel values also sometimes need to > compare not equal with themselves. Forcing them to compare equal will > cause breakage. There's a conflict between such domain-specific considerations (NaNs, strange sentinels, SAGE's equations), and relatively natural assumptions about an == operator, such as it being an equivalence relation. I don't know how to resolve this conflict without introducing a new function which is (or at least strongly encourages developers to arrange for it to be) an equivalence relation. -- [mdw] From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 20:53:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 01:53:17 GMT Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On Mon, 05 Jan 2009 18:23:10 -0500, Kangkook Jee wrote: > Jonathan Gardner wrote: >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, >>> sendAll) >>> using 'metaclass' but I could find exactly place that I can put this >>> in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) >>> in it and will be measured for a couple of hours. >>> >>> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. A relatively straightforward, if not totally accurate, way of doing that is to create a layer between your application code and the network libraries, and have the layer measure the amount of data you send before it reaches the specific protocols being used. Naturally this won't give you a totally accurate count of network traffic sent from your application, since every protocol includes some overhead, but that might not matter for your use-case. -- Steven From castironpi at gmail.com Mon Jan 5 21:01:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 5 Jan 2009 18:01:55 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> <01705c07$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 1:28?am, Steven D'Aprano wrote: > I'm answering both John and Aaron's comments in the following. Mostly > John at the start, Aaron toward the end. > > On Sat, 03 Jan 2009 15:42:47 -0800, Aaron Brady wrote: > > On Jan 3, 11:25?am, John O'Hagan wrote: > > [...] > > > > >According to this, when you replace every floorboard on a porch, one > > > >at a time, it's still the same porch-- it's changed, it's different, > > > >and it's the same. ?However, if you haul off the porch and put a new > > > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > > > >just look at the initial and final configurations of matter to > > > >determine so. ?Therefore, 'id' is an informal function. > > > > This analogy describes the "ontological minefield" I was referring to > > > in a previous post in this thread (which has expired in my mail > > > reader, so my apologies if the threading goes awry): In what sense is > > > a porch (or list, or string) the same if all (or even some of) its > > > parts have been exchanged? > > > > I think the answer is something to do with the abstraction, the > > > "container", the instance of the class. > > That seems reasonable. When you say alist[:] = [1, 2, 3] the container > remains "the same", while the contents change. > > > > Would it be fair to say that perhaps there are no > > > truly mutable objects, only immutable containers whose contents (also > > > immutable objects themselves) may be exchanged? Or to pose the > > > question another way, are objects only mutable insofar as they are > > > composite? > > That depends on what you mean by composite. Everything is composite in > some sense, even a single bit in memory has a physical reality made of > atoms with magnetic fields. But taken as an abstract entity, it is > reasonable to treat a single bit as an atomic non-composite thing, and a > single bit is mutable. > > In practice, actual Python objects tend to be mutable only if they are > composite (although being composite doesn't make them mutable -- consider > frozen sets and tuples). In principle, this is not necessary. There's no > reason why Python couldn't expose a single bit as a data type, so you > could write this: > > >>> n = bit(1) > >>> bool(n) > True > >>> n.flip() > >>> bool(n) > > False > > > > As you argue above, the planks are not the porch; I would add that > > > it's your _decision_ to build (or tear down) a porch which makes it > > > _that_ ?particular porch (or not). > > No, there's no such decision needed. Perhaps a hurricane comes through > and rips the porch up. Maybe a rogue television crew comes by while > you're at work and renovates your house without your knowledge. > > The lack of decision-making needed is more obvious when you consider > something like a fast-flowing river. The specific water molecules making > up the river at any particular instant in time flow away in a matter of > days or weeks, but rivers have a continuity of existence measured in > thousands of years. I trust that nobody is going to argue that the river > makes any decisions at all? > > > > As you imply above (I think), you have to keep looking (or someone > > > does, presumably the interpreter) to know whether an object is the > > > same as or just equal to another (which starts to sound spookily like > > > the role of "the observer" in phenomenology or quantum physics). > > No, I think you're introducing mysticism here that isn't needed. A bit > like quantum mechanics, really :) > > In Python, every object has an identity and a value. If objects X and Y > have the same identity, they are the same object. If X is the object with > id 1234, and Y is the object with id 1234, then both are the same object. > If their ids are different, then they are not. > > In CPython, the id is given by the memory location of the object, which > leads to a very intuitive understanding of "same": the object with id > 1234 is at memory location 1234, and since there can only be one object > at a particular memory location at a time, obviously all objects with id > 1234 must be the same object (provided they exist simultaneously). > > (To be pedantic, there can't actually be objects [note plural] existing > simultaneously with the same id. There can only be multiple references to > the one object.) > > In Python implementations where the id is not a memory address > (IronPython and Jython I think?) the above remains true, even though > there isn't the simple intuitive picture of "only one object can be at a > specific memory address". Python guarantees that the id is *something* > which is guaranteed to be unique over the lifetime of every object. > > Actually, our intuition about one thing per place at the one time is not > strictly correct. Consider the memory address 1234, which currently has > the value in hex of 0x58. That byte may be the numeric value 88, the > ASCII char "X", the set of flags 1011000, or any other thing, depending > on what interpretation we give to it. "What a thing is" is actually a > more difficult question than it appears at first glance. > > [...] > > > I think the key ingredient is that there's no such thing as side > > effect in math. > > I don't see that this is relevant. We're not talking about mathematical > equality, but about the more general concepts of identity and sameness. > > > In example, > > > a= [0, 1, 2] > > a[:]= [3, 4, 5] > > > There aren't many natural language senses in which 'a' is the same > > object as before. > > Of course there are. > > If I have a box containing three things (a piece of paper with the number > "0" written on it, a plastic block in the shape of "1" and a tally stick > with two notches cut in it), and then I remove those three things and > replace them with something else, it's the same box. > > The English and Australian cricket teams have been playing international > Test cricket since 1877. None of the team members playing in 1877 are > still alive today. The entire lineup of both cricket teams has been > replaced repeatedly, and yet they are the same teams. > > The same holds for many, many different organisations: churches, armies, > regiments, political parties, social clubs, companies, guilds, nations, > sporting teams, secret societies, criminal gangs, ecosystems, tribes, > communities of many sorts, and so forth. > > Far from being rare, this is very common. > > > If I have a leg transplant, I'm the same person, > > but if you replace the entire contents of me, I'm not. > > Every (?) molecule in your body is replaced over a period of > approximately seven years. Some molecules are replaced much quicker, some > a little slower, but speaking roughly, the entire contents of you is > replaced every seven years. Aaron, are you the same person you were a > decade ago? In some sense, not at all -- you're a different person to the > annoying person who called himself "castironpi" and was repeatedly > accused of being a bot only a few months ago. But in another sense, yes, > you are the same person -- there is a continuity of existence. > > See also the Ship of Theseus paradox, otherwise known as My Grandfather's > Axe paradox. > > http://en.wikipedia.org/wiki/Ship_of_Theseus > > [...] > > > The porch is defined by its location, but not exclusively. > > If we remove the porch from the house and transport it whole to another > house, it remains the same porch attached to a different house. > > > Natural > > language identity is a cluster concept, without strict necessary and > > sufficient conditions. ?Nothing really presses our boundaries of it > > that much; there aren't many practical questions that lay out the > > facts, then ask, 'But is it the same?' ?You can replace the porch > > board-at-a-time, and it is; and you can haul it somewhere and it is. > > But rearrange the same boards, and it's not. > > I think you overstate your case. If you move the boards around on the > porch, it remains the same porch. Likewise if I have a chest of drawers, > and I take the top drawer and put it at the bottom, the bottom drawer in > the middle and the middle drawer at the top, surely it is the same chest > of drawers? I haven't even replaced anything, just moved them around. > > > Continuity of form is > > probably the prevalent feature, which as you state, does break down in > > the case of composite (piece-wise) transformations. > > I think continuity of form is an important factor in deciding what is the > same and what is not, but I don't think it is the only one. See for > example the anecdote about the Japanese temple in the Wikipedia article > above. And I think you're wrong to say that piece-wise transformations > break down continuity of form. You are, in some sense, the same person > who some years ago was a crawling baby unable to speak. There are > significant changes and replacements and add-ons that nevertheless don't > break continuity. > > > You might get farther comparing container objects to spots on a > > bulletin board. ?The only thing that goes 'in' a container is a > > denoting phrase to another object (and by the way, not a description); > > the other also has its own spot independently on the board. > > That's a reasonable analogy for the implementation of CPython, but it > need not be the only implementation. It wouldn't be fast, or efficient, > or reasonable, but one could create a Python implementation where (for > example) a list didn't just hold pointers to objects, but it held the > actual entire object (no matter how large). Identity could be divorced > from memory location: the one object could exist in many different places > in memory, in the same way that an object can exist in many different > times. The underlying VM would ensure that all such instantiations of the > one object remained in sync at all time. > > Such an implementation would be inefficient and foolish, but it would > still be Python. > > Having said that, it is perfectly valid to ignore the implementation when > describing how Python operates. It really doesn't matter whether CPython > is implemented like a bulletin board or not, it behaves as if it were, > and that makes it a reasonable analogy. > > -- > Steven Hi, a bit behind in the discussion. (What'd I miss?) I think it would be funny in math if someone said, "No, the answer is *that* five, not this one," or "Don't use that five, use this other one." You can use either one. Containers are funny in Python in that 'a in a' can be true. It can't in real containers. Also true in 'a in b and a in c and b is not c' (and 'b not in c' technically). About the porch, you could rearrange some of the boards into a swing or porch door or something, and it's not the same; even though you have the same boards. In the Grandfather's Axe story, you could divide the blade into two, and reattach both halves. It's the same material, but in a different configuration. And here's a funny example of the usage of 'same'. -- X and Y have the same teacher. -- X and Y have the same shower curtain. -- X and Y have the same car. -- X and Y have the same shirt. -- X and Y have the same shirt on. Do you think that context determines the meaning of all of these; that is, that they never lead to confusion? Do you think they're common to say, or do people find other ways, to avoid confusion? The meaning of 'same' varies from one to another, without syntactical markings. I want to conclude that 'equality' and 'identicality' (sharing an identity) are two of the meanings of same, and closely related enough that they can be confusing for neophyte programmers. 'J and K are not the same, just the same.' I think earlier, when John said, you have to keep an eye on the porch to know if it's the same between two points in time, he was observing that 'id([])==id([])' can be true. The porch was secretly wrecked and rebuilt overnight. 'Same' isn't too far down in frequency (U.K. corpus). http://ucrel.lancs.ac.uk/bncfreq/lists/2_2_spokenvwritten.txt > actual entire object (no matter how large). Identity could be divorced > from memory location: the one object could exist in many different places > in memory, in the same way that an object can exist in many different Yes, and it's even possible that multiple objects could exist in the same place, such as in a copy-on-write. > above. And I think you're wrong to say that piece-wise transformations > break down continuity of form. You are, in some sense, the same person > who some years ago was a crawling baby unable to speak. There are It's common enough to say, 'He's not the same person around his parents.' > porch, it remains the same porch. Likewise if I have a chest of drawers, > and I take the top drawer and put it at the bottom, the bottom drawer in > the middle and the middle drawer at the top, surely it is the same chest > of drawers? I haven't even replaced anything, just moved them around. Surely. But what if you remove them, and exchange them with new drawers? > The English and Australian cricket teams have been playing international > Test cricket since 1877. None of the team members playing in 1877 are > still alive today. The entire lineup of both cricket teams has been > replaced repeatedly, and yet they are the same teams. Yet, you could comfortably say, 'The team's not the same without Michael Jordan (star player)'. I don't think identity is indestructible. Over the years, the ballpark, name, uniform, fan base, manager, owner, and players have *all* changed. Not the same. There's a famous psychology example about a brain injury, after which the subject's friends said, 'He's not the same man anymore', and 'It just isn't him.' I don't remember if they (his friends) were native speakers or not. From grante at visi.com Mon Jan 5 21:06:41 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:06:41 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> Message-ID: On 2009-01-05, Jonathan Gardner wrote: > On Jan 5, 2:26?pm, Kangkook Jee wrote: >> >> I'd like to measure number of bytes sent(or recv'd) from my >> python application. Does anyone have any idea how can I >> achieve this? >> >> I tried to do this by tracing some socket calls (send, sendto, >> sendAll) using 'metaclass' but I could find exactly place that >> I can put this in. >> >> My application runs some number of protocols (bittorrent, >> xmlrpc ..) in it and will be measured for a couple of hours. > > A good universal tool on the Linux platform is tcpdump. It takes some > learning, but is very useful for this kind of task. You can use a tool > like ethereal to visualize the data that tcpdump gathers. Ethereal has been called wireshark for quite a while now. It can be used to capture the traffic as well as to visualize it. Wireshark is available for both Linux and Windows. -- Grant From grante at visi.com Mon Jan 5 21:08:25 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:08:25 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On 2009-01-05, Kangkook Jee wrote: > Jonathan Gardner wrote: >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, sendAll) >>> using 'metaclass' but I could find exactly place that I can put this in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) in >>> it and will be measured for a couple of hours. >>> >> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? You can't predict ahead of time what hosts/ports that your application is going to be using? > I'm still struggling to solve it within python process since > it looks cleaner but it doesn't seems to be easy at all. I don't why adding bunches of code to your app would be "cleaner" than gathering data using external programs. -- Grant From grante at visi.com Mon Jan 5 21:14:26 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:14:26 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: On 2009-01-05, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my > python application. Does anyone have any idea how can I > achieve this? Aside from tcpdump/wireshark, you can set up iptables rules to enable accounting for traffic based on IP addresses and ports. http://wiki.openvz.org/Traffic_accounting_with_iptables http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html http://www.catonmat.net/blog/traffic-accounting-with-iptables/ -- Grant From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 21:16:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 02:16:50 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Tue, 06 Jan 2009 01:24:58 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I've already mentioned NaNs. Sentinel values also sometimes need to >> compare not equal with themselves. Forcing them to compare equal will >> cause breakage. > > There's a conflict between such domain-specific considerations (NaNs, > strange sentinels, SAGE's equations), and relatively natural assumptions > about an == operator, such as it being an equivalence relation. Such assumptions only hold under particular domains though. You can't assume equality is an equivalence relation once you start thinking about arbitrary domains. > I don't know how to resolve this conflict without introducing a new > function which is (or at least strongly encourages developers to arrange > for it to be) an equivalence relation. But there cannot be any such function which is a domain-independent equivalence relation, not if we're talking about arbitrarily wacky domains. Even something as straight-forward as "is" can't be an equivalence relation under a domain where identity isn't well-defined. -- Steven From gagsl-py2 at yahoo.com.ar Mon Jan 5 21:42:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 00:42:38 -0200 Subject: idle 3.0 unicode References: <495C7AC6.1000506@post.cz> Message-ID: En Thu, 01 Jan 2009 06:11:50 -0200, Pavel Kosina escribi?: > In 3.0 there is an error. The same program, moved to 3.0 syntax, in > IDLE editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. There are some unicode-related errors reported for IDLE and 3.0, but I could not find this one. Better to file a bug report at http://bugs.python.org -- Gabriel Genellina From workingpad at gmail.com Mon Jan 5 21:42:58 2009 From: workingpad at gmail.com (Jack.Chu) Date: Mon, 5 Jan 2009 18:42:58 -0800 (PST) Subject: My last working day of 2007 References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> <49627e48$0$21839$426a34cc@news.free.fr> Message-ID: <0bac21a4-85bb-4533-9418-690e881e29c7@v5g2000prm.googlegroups.com> Actually I want to put the funny statistic on web. It means create a simple website and show informations such as that picture. But the hard job is I don't know how to collect the log info from client. If I have to install something I don't think people would dare to install it - it is too dangerous to use, and without big benefit. From eric.pruitt at gmail.com Mon Jan 5 21:55:37 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Mon, 5 Jan 2009 20:55:37 -0600 Subject: Diff Across Multiple Files Message-ID: <171e8a410901051855k7b5bed5l6ca58d0a1eda32e1@mail.gmail.com> I am looking for a way to diff across multiple files; on average around 30 to 60 using python and probably the diff library so that we could see what is common between all files and sort of ignore the differences. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Jan 5 21:58:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 00:58:58 -0200 Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: En Sat, 03 Jan 2009 02:55:12 -0200, Kottiyath escribi?: >> tuples = [(1, 2), (3, 4, 5), (6, 7)] > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. What about using another data structure instead - like this: class entry: filename = None def __init__(self, name, value, filename=None): self.name = name self.value = value if filename is not None: self.filename = filename [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, 'path/to/file')] -- Gabriel Genellina From aleksandr.goretoy at gmail.com Mon Jan 5 22:00:01 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:00:01 -0600 Subject: Measuring bytes of packet sent from python application In-Reply-To: References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: You can alot run "lsof -i -T -n" from popen2 to see what applications use what port and addr they are connected to. In order to see all jobs though it needs to be ran as root. This way you can find out what ports and such Then perform tcp dump thru popen2 and filter for port and addr. This is just a first shot, then I would figure out what to do after having gotten to this point. import popen2 #find out what ports and addrs what program is connected to r,w,e=popen2.popen3("lsof -i -T -n") # this may need sudo prepended to lsof r=r.readlines() e=e.readlines() #get tcpdump, doesn't quiet work here....needs something more, maybe a different way altogether. #tcpdump to pcap file and read file periodically? r1,w1,e1=popen2.popen3("sudo tcpdump -i eth1") r1=r1.readlines() e1=e1.readlines() Something to this nature, then do regular expression on tcpdump output, either logged to pcap output file or by other means. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 8:14 PM, Grant Edwards wrote: > On 2009-01-05, Kangkook Jee wrote: > > > I'd like to measure number of bytes sent(or recv'd) from my > > python application. Does anyone have any idea how can I > > achieve this? > > Aside from tcpdump/wireshark, you can set up iptables rules to > enable accounting for traffic based on IP addresses and ports. > > http://wiki.openvz.org/Traffic_accounting_with_iptables > http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html > http://www.catonmat.net/blog/traffic-accounting-with-iptables/ > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Mon Jan 5 22:04:21 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:04:21 -0600 Subject: Is there a better algorithm? In-Reply-To: References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: > > class entry: > filename = None > > def __init__(self, name, value, filename=None): > self.name = name > self.value = value > if filename is not None: > self.filename = filename > > [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, > 'path/to/file')] Gabriel thank you for this. I just now realized I've being doing things the hard way. :) -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 8:58 PM, Gabriel Genellina wrote: > En Sat, 03 Jan 2009 02:55:12 -0200, Kottiyath > escribi?: > > tuples = [(1, 2), (3, 4, 5), (6, 7)] >>> >> >> It is a code to post some data to HTML server. >> Even though usually the POST values are of type(name, value), if file >> transfer is involved, then POST values change to (name, filename, >> value). >> My view was that since filename is a rare occurance and doesnt make >> sense in a usual POST, I had not kept it as a full 3 tuple. >> Since so many programmers (that too much more capable than me) are >> suggesting that it is code smell, I am reviewing my decision. >> > > What about using another data structure instead - like this: > > class entry: > filename = None > > def __init__(self, name, value, filename=None): > self.name = name > self.value = value > if filename is not None: > self.filename = filename > > [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, > 'path/to/file')] > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerb at rogerbinns.com Mon Jan 5 22:16:26 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 05 Jan 2009 19:16:26 -0800 Subject: Measuring bytes of packet sent from python application In-Reply-To: <4962965f$0$90276$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Kangkook Jee wrote: > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? I use nethogs on Ubuntu. If you use Intrepid, you can press 'm' to make it change amongst different displays (eg cumulative traffic, send/receive rates etc). Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAklizQYACgkQmOOfHg372QQc2gCgiMCeY1X9Qd/Fyh77SuDUNPqx 7lkAn1ozstsf2542+OuFuBC54vtOaaUR =qSxN -----END PGP SIGNATURE----- From gagsl-py2 at yahoo.com.ar Mon Jan 5 22:24:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 01:24:14 -0200 Subject: multiprocessing vs thread performance References: Message-ID: En Sat, 03 Jan 2009 11:31:12 -0200, Nick Craig-Wood escribi?: > mk wrote: >> The results I got are very different from the benchmark quoted in PEP >> 371. On twin Xeon machine the threaded version executed in 5.54 secs, >> while multiprocessing version took over 222 secs to complete! >> >> Am I doing smth wrong in code below? > > Yes! > > The problem with your code is that you never start more than one > process at once in the multiprocessing example. Just check ps when it > is running and you will see. Oh, very good analysis! Those results were worriying me a little. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 5 22:44:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 01:44:18 -0200 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: En Mon, 05 Jan 2009 02:03:26 -0200, Roy Smith escribi?: > The other day, I came upon this gem. It's a bit of perl embedded in a > Makefile; this makes it even more gnarly because all the $'s get doubled > to > hide them from make: > > define absmondir > $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print \\\$$1}"`; > chomp($$prefix); \ > ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ > ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ > ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! ); > } \ > ?? return unslash(undot(undotdot($$a))); }; \ > sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; > return($$_[0]); > }; \ > sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ > sub undotdot ($$) { my $$in = $$_[0]; \ > ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ > print absmon("$(1)","$(2)"); \ > ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > endef > > Barf-o-rama. I know what it's supposed to do, and I still can't figure > it out. Ouch! Me too, when I come to some piece of Perl code I've written some years ago, I invariably think "what's all this noise?". Never happens with other languages I've used in the past. -- Gabriel Genellina From truelixin at gmail.com Mon Jan 5 23:30:42 2009 From: truelixin at gmail.com (truelixin at gmail.com) Date: Mon, 5 Jan 2009 20:30:42 -0800 (PST) Subject: About PyOpenGL References: Message-ID: <1311f0d4-f0b1-4e82-b66b-014988609e59@n33g2000pri.googlegroups.com> On Jan 6, 12:58?am, Rob Williscroft wrote: > trueli... at gmail.com wrote in news:f8099226-a953-4598-bfe2-61ee5772ce26 > @l33g2000pri.googlegroups.com in comp.lang.python: > > > > > > > Traceback (most recent call last): > > ? File "test.py", line 36, in > > ? ? main() > > ? File "test.py", line 26, in main > > ? ? glutInit(sys.argv) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\GLUT\special.py", line 316, in glutInit > > ? ? _base_glutInit( ctypes.byref(count), holder ) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\GLUT\special.py", line 57, in _base_glutInit > > ? ? return __glutInitWithExit(pargc, argv, _exitfunc) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\platform\baseplatform.py", line 280, in __call__ > > ? ? self.__name__, self.__name__, > > OpenGL.error.NullFunctionError: Attempt to call an undefined function > > __glutInitWithExit, check for bool(__glutInitWithExit) before calling > > To get you code running I needed (in addition to the PyOpenGL download) > to download. > > glut-3.7.6-bin.zip (117 KB) fromhttp://www.xmission.com/~nate/glut.html > > and put the glut32.dll where python can find it, the readme says > \system which worked, but sticking it in the same directory > as python.exe (c:\python25 in your case) worked too. > > http://pyopengl.sourceforge.net/http://pyopengl.sourceforge.net/documentation/installation.html > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Yeah! It works now! Thank you very much! From tjreedy at udel.edu Mon Jan 5 23:45:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 23:45:10 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> <01705c07$0$8693$c3e8da3@news.astraweb.com> Message-ID: Aaron Brady wrote: > > Containers are funny in Python in that 'a in a' can be true. > It can't in real containers. Guido uses 'container' in the Ref Manual because such 'contain' references (of an undefined nature). Thinking more abstractly, I use 'collection', rather that 'container' and think of the object as a 'roster' -- like for the members of a club. A bibliography of bibliographies could list itself but would only metaphorically 'contain' itself. An association of associations could conceivably be a member of itself. tjr From pythonnutter at gmail.com Tue Jan 6 02:11:40 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Tue, 6 Jan 2009 18:11:40 +1100 Subject: SSL certificate parsing? In-Reply-To: References: Message-ID: If no one answers, the way I do my work with certificates is I just wrap OpenSSL myself by doing a popen call (probably now should be using subprocess for any future scripts I write). I then redirect the output that normally goes to the shell window into a buffer then I search/slice out the fields using standard Python string searching. You could go to regex's but its overkill in my opinion if you can simply do standard string searches. The buffer always follows a set pattern so you are not going to have to search wildly varying output from OpenSSL call to OpenSSL call. I looked at PyOpenSSL but I have country specific OIDs that are standard by not in the default ISO standard. Most libraries fall short on supporting what I need and it was brain dead easy to just call OpenSSL in my script directly and capture the output for parsing. Its up to you what you want to do with the extracted information, you could just populate a dict with it and perhaps shelve or store it for later use if you have such a need or as in my case since I only process the certificates once I just use the parsed information immediately in my scripts logic decision tree(s) to create various output. Cheers, PN 2009/1/5 Taras Ivashchenko : > Hello, list! > > I use pyopenssl [0] for checking SSL certificates. > And one of such checks is if given certificate is self-signed. > I can do it using values of X509v3 extensions: the subject key identifier and > the authority key id: > X509v3 Subject Key Identifier: > 0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 > X509v3 Authority Key Identifier: > keyid:0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 > > I read documentation of pyOpenSSL but I didn't find way how to grub > this information > from certificate using, for example, methods of X509 object. > > May be there is another way to parse SSL certificates? > I will be glad to get ever text version of given SSL certificate :) > > [0] http://pyopenssl.sourceforge.net/ > > P.S. I already wrote to pyopenssl mailing list, but there is now > answer there :( > > ????? ???????? (Taras Ivashchenko) > -- > "Software is like sex: it's better when it's free.", - Linus Torvalds. > -- > http://mail.python.org/mailman/listinfo/python-list > From david at crouse.us Tue Jan 6 02:41:58 2009 From: david at crouse.us (David Crouse) Date: Tue, 6 Jan 2009 01:41:58 -0600 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Message-ID: <596da3790901052341yd74400ard4b621a3b67618c6@mail.gmail.com> I use Arch Linux, it has Python 3.0 and 2.6 and 2.4. Below are some common packages and their version numbers. I wouldn't however recommend Arch to a new Linux user, it's not Ubuntu. However once installed and configured, it's very easy to maintain. python3 3.0-3 python 2.6.1-1 python24 2.4.6-1 wxpython 2.8.9.1-1 pykde 3.16.2-1 pygtk 2.13.0-2 pyqt 4.4.4-1 eric 4.2.4a-1 scite 1.77-1 ipython 0.9.1-1 python-cheetah 2.0.1-2 django 1.0.2-1 cherrypy 3.1.1-1 pil 1.1.6-5 pylint 0.15.2-1 beautiful-soup 3.1.0-1 On Mon, Jan 5, 2009 at 7:16 PM, Lex Hider wrote: > Probably not a big difference in most cases between debian, ubuntu, > fedora. The latter two may be more likely to have more recent > versions. > > I'm pretty sure ubuntu is the only one which currently has python 3.0 > in it's archives [no, it's not the default version]. > > On 06/01/2009, member thudfoo wrote: >> One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... >> And so on. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > From electronixtar at gmail.com Tue Jan 6 03:09:24 2009 From: electronixtar at gmail.com (est) Date: Tue, 6 Jan 2009 00:09:24 -0800 (PST) Subject: ctypes to customize MSN now playing status Message-ID: <2ab68e63-ad77-46d5-9323-cfc88ad4f712@i18g2000prf.googlegroups.com> Hi guys, I am trying to switch MSN/WLM now playing status using ctypes with python, here's my code import ctypes, win32con, win32api, win32gui FindWindow = ctypes.windll.User32.FindWindowA SendMessage = ctypes.windll.User32.SendMessageA hWnd = FindWindow('MsnMsgrUIManager', None) s = u"\\0Music\\01\\0{test}\\0\\0\\0\\0\\0" class MsnData(ctypes.Structure): _fields_ = [("dwData", ctypes.c_int), ("cbData", ctypes.c_int), ("lpData", ctypes.c_wchar_p), ] msndata = MsnData(0x547, 256, ctypes.c_wchar_p(s)) SendMessage(hWnd, win32con.WM_COPYDATA, 0, ctypes.byref(msndata)) The code is not working, could anybody help? From guillaume.aubert at gmail.com Tue Jan 6 03:24:49 2009 From: guillaume.aubert at gmail.com (guss) Date: Tue, 6 Jan 2009 00:24:49 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> Message-ID: <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> hi Thanks for the tip but I had to play with the __import__ func a bit. Indeed to load not only the top module with __import__ one needs to try to load an object from the module: Here is my forname: def forname(modname, classname): module = __import__(modname,globals(),locals(),['NoName'],-1) classobj = getattr(module, classname) return classobj Like that I can load MyError from the module org.myapp.exceptions >>> c = forname('org.myapp.exceptions','MyError') >>> instance = c('My Message') If I do not put 'NoName' that is a fake object only module will be org and not org.myapp.exceptions. This is strange ? I think Python has all the elements for doing java like reflection and introspection and even more but the API is not as mature and it is quite difficult to find the information. There is the need for a high level API. Maybe it already exists, if anyone knows please tell me. Thanks. Guillaume On Jan 5, 5:34?pm, Bruno Desthuilliers wrote: > guss a ?crit : > > > > > I cannot find a satisfying answer to this question on the web so let's > > try here. > > > My problem is the following, I would like to instantiate some object > > from a configuration file that would contain class names like for > > example classname=org.common.resource.MyResource. > > Here my resource is the class to instanciate and it is in the module > > resource that is in a package hierachy. > > > In fact I would like to do something very similar to the Java: > > > klass = Class.forname("org.common.resource.MyResource") > > > instance = klass.newInstance() > > > The second line is easy once I have a classobj but I have some > > problems to find the right recipe for getting it. > > > I know how to create a class from scratch with new.classobj but how do > > you get a class object and then create an object ? > > > I would like a recipe working for all cases (whatever the module is > > not the local one ...) > > use __import__ to get the module object, then getattr(module, classname) > to get the class object (sorry, no much time right now to give you a > full recipe, but that should be enough to get you started). > > HTH From nawijn at gmail.com Tue Jan 6 03:26:13 2009 From: nawijn at gmail.com (Marco Nawijn) Date: Tue, 6 Jan 2009 00:26:13 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <32ed6add-2266-498d-b9a9-96b6b426dc15@g1g2000pra.googlegroups.com> On Jan 5, 10:57?am, Sandro Tosi wrote: > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? > - what would you like to see in a book about matplotlib? > - what are some those advanced feature that made you yell "WOW!!" ? > - what are the things you'd like to explore of matplotlib and never > had time to do? > > Your suggestions are really appreciated :) And wish me good luck! Hello Sandro, I am happy to hear that there might be a book on Matplotlib. I am using Matplotlib for a while now and find it a very usefull and powerfull library for generating graphs. I will try to answer some of your questions. I am by no means an expert in the field, so I only express my personal experience. >> What are you using matplotlib for? I currently use Matplotlib to generate a series of graphs that visualise data channels (strain measurements) during a structural test. These graphs need to be refreshed about every 4 seconds. Each of the graphs contains 1 to 6 curves. >> What are the things you like the most of matplotlib, that you want to give emphasis to? And why? In general I like the most the fact that I can generate high quality publication ready graphs with a consistent look with minimal effort. Further, although the matlab-style commands are very usefull I think the class interface is more powerfull. The class interface also has a steeper learning curve. So, for me it would be very interesting if much emphasis will be on the class interface. >> What are the (basic) things that, when you were beginning to use matplotlib, you wanted to see grouped up but couldn't find? I seriously hope the book is not for "dummies", but provides at least a significant amount of information on more advanced features of Matplotlib. I think the currently available tutorials are sufficient to getting started. From my point of view I am very interested in: - Dynamically updating a series of graphs - Configuring layout of graphs (colors, labels, legends, etc.) - Managing dimensions of the figure when you export the figure to e.g PNG. For me this is interesting in the sense that if I insert a figure in a report/paper, I would like that the fonts used in the graph remain proportional to the surrounding text. If you need more information please let me know. I wish you good luck! Kind regards, Marco From jstroud at mbi.ucla.edu Tue Jan 6 03:33:31 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:33:31 -0800 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: Sandro Tosi wrote: > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? Matplot lib shines for interactive environments wherein graphs and charts must be produced. I have incorporated it into a simple program for analysis of fluorometric data: http://fluorit.bravais.net/ (The forthcoming version 1.0 is a quantum improvement in speed and function over the SLOW *prototype* version 0.9 currently available--see the wish list, feature requests, and known issues for details. Version 1.0 is very fast.) > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? The ability to embed a figure (composed of subplots) into a custom window is my favorite aspect. Also: massive configurability of plots, event driven plot canvas, antigrain geometry antialiasing are also all very important. Additionally the toolbar of standard interactive functions and the ability to export plots in a variety of formats are also invaluable features. > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? The documentation for basic plot configuration, especially for embedded plots, and also tapping into the event model is very weak currently. These need the most improvement. > - what would you like to see in a book about matplotlib? A big, huge, gigantic, chapter---no make that 3 chapters--on programming interactivity with the plot canvas. > - what are some those advanced feature that made you yell "WOW!!" ? I listed them above, but my most "WOW" moment was when I saw the Tkinter backend doing beautiful antialiasing. I was also very happy to seamlessly add new functionality to the toolbar. > - what are the things you'd like to explore of matplotlib and never > had time to do? I want to program a lot of interactivity with the plots in my current application. > Your suggestions are really appreciated :) And wish me good luck! Good luck! I can't wait to read your book! James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From narkewoody at gmail.com Tue Jan 6 03:38:16 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 6 Jan 2009 16:38:16 +0800 Subject: __builtin__ quote Message-ID: Hi, I am a new leaner and I get a question: abs() is a member of __builtin__ module, but why should I use abs() rather than __builtin__.abs() ? Thanks. From jstroud at mbi.ucla.edu Tue Jan 6 03:42:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:42:53 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: Steven Woody wrote: > Hi, > > I am a new leaner and I get a question: abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. It saves typing. This might help your understanding: py> import __builtin__ py> __builtin__.abs is abs True James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bj_666 at gmx.net Tue Jan 6 03:47:00 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 6 Jan 2009 08:47:00 GMT Subject: Tkinter - problem closing window References: Message-ID: <6sgk44F5qmm8U2@mid.uni-berlin.de> On Mon, 05 Jan 2009 12:25:53 -0200, Djames Suhanko wrote: > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > [?] > > 17 def gera_seis(self): > 18 a = {} > 19 for i in range(6): > 20 a[i] = "%02d" % int (random.randint(0,60)) > 21 resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > 22 return resultadoA Not the problem but unnecessary complex. `random.randint()` already returns an int, no need to call `int()` on it. The string formatting with ``%`` returns strings, so there is no need to call `str()` on the values. Even if the values where not strings: The '%s' place holder implies a call to `str()` while formatting. If you put something into a dictionary with consecutive `int` keys, you might use a list instead. All this can be written as a simple one liner:: '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) > 24 def say_hi(self): > 25 resultado = self.gera_seis() > 26 raiz = Tk() The problem is here? > 27 F = Frame(raiz) > 28 F.pack() > 29 hello = Label(F, text=resultado) 30 hello.pack() > 31 F.mainloop() ?and here. There is only one `Tk` instance and mainloop allowed per `Tkinter` application. Otherwise really strange things can happen. Additional windows have to be created as `Toplevel` instances. Ciao, Marc 'BlackJack' Rintsch From narkewoody at gmail.com Tue Jan 6 03:47:57 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 6 Jan 2009 16:47:57 +0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: > Steven Woody wrote: >> >> Hi, >> >> I am a new leaner and I get a question: abs() is a member of >> __builtin__ module, but why should I use abs() rather than >> __builtin__.abs() ? Thanks. > > It saves typing. > > This might help your understanding: > > py> import __builtin__ > py> __builtin__.abs is abs > True > Does that mean someone did 'import * from __builtin__' when python startup? From clp at rebertia.com Tue Jan 6 03:50:16 2009 From: clp at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 00:50:16 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <47c890dc0901060050o69360e40ida6e097bff9da605@mail.gmail.com> On Tue, Jan 6, 2009 at 12:47 AM, Steven Woody wrote: > On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: >> Steven Woody wrote: >>> >>> Hi, >>> >>> I am a new leaner and I get a question: abs() is a member of >>> __builtin__ module, but why should I use abs() rather than >>> __builtin__.abs() ? Thanks. >> >> It saves typing. >> >> This might help your understanding: >> >> py> import __builtin__ >> py> __builtin__.abs is abs >> True >> > > Does that mean someone did 'import * from __builtin__' when python startup? In a sense, yes. The interpreter effectively automatically does such an import. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From cournape at gmail.com Tue Jan 6 03:51:53 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 6 Jan 2009 17:51:53 +0900 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Message-ID: <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> On Tue, Jan 6, 2009 at 10:16 AM, Lex Hider wrote: > Probably not a big difference in most cases between debian, ubuntu, > fedora. The latter two may be more likely to have more recent > versions. > > I'm pretty sure ubuntu is the only one which currently has python 3.0 > in it's archives [no, it's not the default version]. OTOH, it does not have python 2.6 yet, which is a bit annoying. cheers, David From clp at rebertia.com Tue Jan 6 03:52:06 2009 From: clp at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 00:52:06 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <47c890dc0901060052m13053526ube60edaaf90a43bf@mail.gmail.com> On Tue, Jan 6, 2009 at 12:38 AM, Steven Woody wrote: > Hi, > > I am a new leaner and I get a question: abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. To clarify, having __builtin__ is just the language's way of reifying the notion of "built-in functions" in the form of a special module. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apardon at forel.vub.ac.be Tue Jan 6 03:53:12 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Jan 2009 08:53:12 GMT Subject: ftp seems to get a delayed reaction. Message-ID: I'm not sure if this is a python problem or something else. I'm trying with the use of ftplib to get a dump on a remote machine. The dump mirrors the directory structure but instead of the files a bziped tar file is made and transferred. While mirroring the directory structure I don't care to check which directories are already present. I just try to make the directory and catch the exception when it occurs. This worked fine until now. I recently movade the script to a new computer and use a different ftp server. Now it seems the error code for the ftp.mkd is received by the storbinary later on. This is the traceback: Traceback (most recent call last): File "ftpdump", line 141, in main() File "ftpdump", line 133, in main process(path) File "ftpdump", line 90, in process ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl) File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary self.voidcmd('TYPE I') File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.5/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists This is part of the code: # Somethings define somewhere above # # pj = os.path.join # FTPProblem = ftplib.error_temp while problem: try: ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl) fl.close() problem = False except FTPProblem: warn ("reconnecting for %s\n" % cprt) try: ftp.quit() except Exception: pass time.sleep(5) ftpconnect() So what seems to happen is that I call the ftp.storbinary and that I get the mesg: ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists That I should have gotten while doing the ftp.mkd earlier. Can someone shed some light on how to deal with this? -- Antoon Pardon From jstroud at mbi.ucla.edu Tue Jan 6 03:56:36 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:56:36 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <81F8l.4494$jZ1.3657@flpi144.ffdc.sbc.com> Steven Woody wrote: > On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: >> py> import __builtin__ >> py> __builtin__.abs is abs >> True > > Does that mean someone did 'import * from __builtin__' when python startup? In terms of the exact implementation of the cPython interpreter, I don't know. But the interpreter behaves as if someone did just that. So there is nothing wrong with thinking of it this way if it helps you understand the interpreter. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From you680 at gmail.com Tue Jan 6 04:10:28 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 01:10:28 -0800 (PST) Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data Message-ID: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> hi all: when I handled mass data table in mysql with python's MySQLdb lib, something frustrated me. I could't find any function like datareader, which yield one row by recording rows' anchor ,after each time I invoked 'read()' in a loop.fetchall or fetchmany just fetched all data in once, which take so much memory when meeting one mass data table. Is anybody know that function or other lib similar to MySQLdb ? thanks! From alexi.zuo at gmail.com Tue Jan 6 04:12:21 2009 From: alexi.zuo at gmail.com (Alexi Zuo) Date: Tue, 6 Jan 2009 17:12:21 +0800 Subject: Python subprocess question Message-ID: <5259b2e20901060112x4943e946xc4a5871425cbb4ee@mail.gmail.com> Hi everyone, Here I have a simple program which starts a thread and the thread use Popen to execute a shell cmd which needs a long time. I want to stop the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this program enters a dead loop. Can anyone tell me what is wrong? Alex from subprocess import * import threading import time class TestThread(threading.Thread): def run(self): try: while True: p=Popen("for (( i = 0 ; i <= 100000; i++ )); do echo hello; done", shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE,close_fds=True) print p.stdout.readlines() print p.stderr.readlines() except KeyboardInterrupt: print "got ex" print "leave..." a=TestThread() a.start() try: a.join() except: print "gone" From dcml1 at crouse.us Tue Jan 6 04:21:34 2009 From: dcml1 at crouse.us (Dave Crouse) Date: Tue, 6 Jan 2009 03:21:34 -0600 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> Message-ID: <596da3790901060121p7015f3ebo540404475196a1a2@mail.gmail.com> My apologies to the list if this is a double post. My email client tried to send with the wrong email address. I use Arch Linux, it has Python 3.0 and 2.6 and 2.4. Below are some common packages and their version numbers. I wouldn't however recommend Arch to a new Linux user, it's not Ubuntu. However once installed and configured, it's very easy to maintain. python3 3.0-3 python 2.6.1-1 python24 2.4.6-1 wxpython 2.8.9.1-1 pykde 3.16.2-1 pygtk 2.13.0-2 pyqt 4.4.4-1 eric 4.2.4a-1 scite 1.77-1 ipython 0.9.1-1 python-cheetah 2.0.1-2 django 1.0.2-1 cherrypy 3.1.1-1 pil 1.1.6-5 pylint 0.15.2-1 beautiful-soup 3.1.0-1 On Tue, Jan 6, 2009 at 2:51 AM, David Cournapeau wrote: > On Tue, Jan 6, 2009 at 10:16 AM, Lex Hider wrote: >> Probably not a big difference in most cases between debian, ubuntu, >> fedora. The latter two may be more likely to have more recent >> versions. >> >> I'm pretty sure ubuntu is the only one which currently has python 3.0 >> in it's archives [no, it's not the default version]. > > OTOH, it does not have python 2.6 yet, which is a bit annoying. > > cheers, > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From pavlovevidence at gmail.com Tue Jan 6 04:29:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 6 Jan 2009 01:29:00 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> Message-ID: <32f65b9f-7cb6-4ba3-8c26-92acf0811a14@s9g2000prm.googlegroups.com> On Jan 6, 2:24?am, guss wrote: > hi Thanks for the tip but I had to play with the __import__ func a > bit. > Indeed to load not only the top module with __import__ one needs to > try to load an object from the module: > > Here is my forname: > > def forname(modname, classname): > ? ? module = __import__(modname,globals(),locals(),['NoName'],-1) > ? ? classobj = getattr(module, classname) > ? ? return classobj > > Like that I can load MyError from the module org.myapp.exceptions > > >>> c = forname('org.myapp.exceptions','MyError') > >>> instance = c('My Message') > > If I do not put 'NoName' that is a fake object only module will be org > and not org.myapp.exceptions. This is strange ? Yes, it's strange. It's that way for historical and logistical reasons. Here's how I'd write the function; no need to specify modname and classname separately. def forname(name): parts = name.split(".") obj = __import__(".".join(parts[:-1])) for part in parts[1:]: obj = getattr(obj,part) return obj > I think Python has all the elements for doing java like reflection and > introspection and even more but the API is not as mature and it is > quite difficult to find the information. > There is the need for a high level API. > > Maybe it already exists, if anyone knows please tell me. > Thanks. I'm going to suggest that the reason high-level reflection APIs are used so often in Java is to compensate for Java's lack of run-time flexibility. If you don't know what class to use or method to call at compile-time, the easiest thing to do is to store the name in a string and use the Reflection API to get at it at run-time. Python, OTOH, is very dynamic, so there is not much demand for spiffy introspection APIs. Functions and classes are ordinary objects, so if you don't know what function to call or class to use at compile-time, you can just pass the objects around. No strings required. So what I'm saying is: the Python developers didn't bother to make an high-level, easy-to-use __import__ because there really isn't much demand for it. Carl Banks From sjmachin at lexicon.net Tue Jan 6 04:38:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 6 Jan 2009 01:38:20 -0800 (PST) Subject: __builtin__ quote References: Message-ID: <7327e5f7-c0d1-4f54-b202-fdc9831a9edd@r10g2000prf.googlegroups.com> On Jan 6, 7:38?pm, "Steven Woody" wrote: > Hi, > > I am a new leaner and I get a question: ?abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. Fewer keystrokes. From stefan_ml at behnel.de Tue Jan 6 05:25:59 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Jan 2009 11:25:59 +0100 Subject: Extending Python with C or C++ In-Reply-To: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> References: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> Message-ID: <496331b8$0$32665$9b4e6d93@newsspool2.arcor-online.net> Ryan wrote: > 3. Extending CPython by connecting it to Python-oblivious code written > in C with Ctypes (Ralf's suggestion is good for this) > 4. Extending CPython by connecting it to Python-aware (and specific) > code using the CPython C-API functions (http://docs.python.org/c-api/) For extending CPython (and possibly connecting it to external C code/libraries) without learning too many new things (Python + a little C should be enough), you can use ctypes if you can accept the runtime overhead and the dependency on the ctypes module (which does not exist in all CPython releases). However, I'd recommend Cython instead, as it gives you very fast and portable code that works with all CPython versions. And Cython code is not any harder to write at all. http://cython.org/ Stefan From dickinsm at gmail.com Tue Jan 6 05:44:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 6 Jan 2009 10:44:56 +0000 Subject: math module for Decimals In-Reply-To: References: <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> On Mon, Jan 5, 2009 at 4:50 PM, alex goretoy wrote: > I get this when importing decimal: > > Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) > [GCC 3.4.6] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import decimal > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python2.7/decimal.py", line 138, in > import math as _math > ImportError: No module named math >>>> It's working fine for me. I assume that a simple "import math" also fails? A couple of possibilities: (1) the math module built, but Python is looking in the wrong place for it, for some reason. (2) the math module failed to build. If you look at the end of the make output, you'll probably see some lines that look like the following (but with different modules listed). Python build finished, but the necessary bits to build these modules were not found: bsddb185 gdbm linuxaudiodev ossaudiodev spwd sunaudiodev If math is included in the modules listed, then I'd very much like to know about it. Mark From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 6 06:29:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 06 Jan 2009 12:29:49 +0100 Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data In-Reply-To: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> References: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> Message-ID: <496340a6$0$3533$426a74cc@news.free.fr> Jeremy.Chen a ?crit : > hi all: > when I handled mass data table in mysql with python's MySQLdb lib, > something frustrated me. I could't find any function like datareader, > which yield one row by recording rows' anchor ,after each time I > invoked 'read()' in a loop. I think you want cursor.fetchone(). But read below... > fetchall or fetchmany just fetched all data > in once, which take so much memory when meeting one mass data > table. The cursor object is it's own iterator. So you just have to do: cursor.execute(your_query) for row in cursor: process(row) HTH From nick at craig-wood.com Tue Jan 6 06:31:14 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 06 Jan 2009 05:31:14 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Ralf Schoenian wrote: > Ryan wrote: > > I've been using Python for many years now. It's a wonderful language > > that I enjoy using everyday. I'm now interested in getting to know > > more about the guts (C/C++) and extending it. But, extending python > > still seems like a black art to me. Is there anymore docs or info on > > extending it besides the standard sparse ones (http://www.python.org/ > > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > > class available? How can I learn more about the guts of python? How > > would one go about following an interest in contributing to the > > development of python. > > It is not exactly what you are looking for but nevertheless I am > thinking the article "Automatic C Library Wrapping -- Ctypes from the > Trenches" may be interesting for you. You can find it in the latest > Python Papers issue or simply following the link: > http://ojs.pythonpapers.org/index.php/tpp/article/view/71 Interesting - I didn't know about h2xml and xml2py before and I've done lots of ctypes wrapping! Something to help with the initial drudge work of converting the structures would be very helpful. ( http://pypi.python.org/pypi/ctypeslib/ ) I gave it a quick go and it worked fine. I had to edit the XML in one place to make it acceptable (removing a u from a hex number). The output of xml2py was an excellent place to start for the conversion, though I don't think I'd want to use an automated process like in the paper above as its output needed tweaking. ... Here are my thoughts on the conversion :- It converted an interface which looked like this (the inotify interface) struct inotify_event { int wd; /* Watch descriptor */ uint32_t mask; /* Mask of events */ uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */ uint32_t len; /* Size of name field */ char name[]; /* Optional null-terminated name */ }; Into this class inotify_event(Structure): pass inotify_event._fields_ = [ ('wd', c_int), ('mask', uint32_t), ('cookie', uint32_t), ('len', uint32_t), ('name', c_char * 0), ] Which is a very good start. However it defined these which clearly aren't portable int32_t = c_int uint32_t = c_uint Whereas it should have been using the ctypes inbuilt types c_int32 c_uint32 Also I don't think c_char * 0 does anything sensible in ctypes, c_byte * 0 is what is required plus a bit of casting. This is a non-standard GNU extension to C though. All that said though, it looks like a great time saver. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From apardon at forel.vub.ac.be Tue Jan 6 06:56:52 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Jan 2009 11:56:52 GMT Subject: ftp seems to get a delayed reaction. References: Message-ID: I have managed to prune the script, so I can post it here: ========================================================== from ftplib import FTP bckrt = "/tmpstor/rcpc42" def process(): print "making directory" try: ftp.mkd('ftp-tst') print "mkdir succeeded" except Exception, ErrMsg: print "mkdir failed: %s" % ErrMsg fl = open("tstfile") print "storing file" ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) fl.close() ftp = FTP('ftphost', 'user', 'passwd') ftp.set_pasv(False) ftp.cwd(bckrt) print "Doing once" process() print "Doing twice" process() ---------------------------------------------------------- And this is the output: ========================================================== Doing once making directory mkdir succeeded storing file Doing twice making directory mkdir failed: 500 '': command not understood. storing file Traceback (most recent call last): File "ftptst", line 24, in process() File "ftptst", line 14, in process ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary self.voidcmd('TYPE I') File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.5/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists From guillaume.aubert at gmail.com Tue Jan 6 07:28:29 2009 From: guillaume.aubert at gmail.com (guss) Date: Tue, 6 Jan 2009 04:28:29 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> <32f65b9f-7cb6-4ba3-8c26-92acf0811a14@s9g2000prm.googlegroups.com> Message-ID: <93ada359-2d4f-4064-a7fa-20301b11c6fc@w24g2000prd.googlegroups.com> Hi Carl thanks for your improved forname method. Regarding the high level reflection API, it is true that we don't need an API as complex as in Java considering the dynamic aspect of Python but you have a forname function I needed one so it could be nice to have it (and other services related to reflection and introspection) standardized in an api supported by default by Python. Who doesn't need to load or create a class (a plugin object ...) from a configuration file these days. Cheers Guillaume > On Jan 6, 2:24?am, guss wrote: > > > > > hi Thanks for the tip but I had to play with the __import__ func a > > bit. > > Indeed to load not only the top module with __import__ one needs to > > try to load an object from the module: > > > Here is my forname: > > > def forname(modname, classname): > > ? ? module = __import__(modname,globals(),locals(),['NoName'],-1) > > ? ? classobj = getattr(module, classname) > > ? ? return classobj > > > Like that I can load MyError from the module org.myapp.exceptions > > > >>> c = forname('org.myapp.exceptions','MyError') > > >>> instance = c('My Message') > > > If I do not put 'NoName' that is a fake object only module will be org > > and not org.myapp.exceptions. This is strange ? > > Yes, it's strange. ?It's that way for historical and logistical > reasons. ?Here's how I'd write the function; no need to specify > modname and classname separately. > > def forname(name): > ? ? parts = name.split(".") > ? ? obj = __import__(".".join(parts[:-1])) > ? ? for part in parts[1:]: > ? ? ? ? obj = getattr(obj,part) > ? ? return obj > > > I think Python has all the elements for doing java like reflection and > > introspection and even more but the API is not as mature and it is > > quite difficult to find the information. > > There is the need for a high level API. > > > Maybe it already exists, if anyone knows please tell me. > > Thanks. > > I'm going to suggest that the reason high-level reflection APIs are > used so often in Java is to compensate for Java's lack of run-time > flexibility. ?If you don't know what class to use or method to call at > compile-time, the easiest thing to do is to store the name in a string > and use the Reflection API to get at it at run-time. > > Python, OTOH, is very dynamic, so there is not much demand for spiffy > introspection APIs. ?Functions and classes are ordinary objects, so if > you don't know what function to call or class to use at compile-time, > you can just pass the objects around. ?No strings required. > > So what I'm saying is: the Python developers didn't bother to make an > high-level, easy-to-use __import__ because there really isn't much > demand for it. > > Carl Banks From aleksandr.goretoy at gmail.com Tue Jan 6 07:33:42 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 12:33:42 +0000 Subject: math module for Decimals In-Reply-To: <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> References: <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> Message-ID: Yes I ran strace python and imported math time(NULL) = 1231244692 futex(0x80575d8, FUTEX_WAKE, 1) = 0 stat64("math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python24.zip/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/plat-linux2/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/lib-tk/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/lib-dynload/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-dynload/math.so", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0 open("/usr/lib/python2.4/lib-dynload/math.so", O_RDONLY) = 4 read(4, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\16"..., 512) = 512 fstat64(4, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0 mmap2(NULL, 15588, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0xb7f2b000 mmap2(0xb7f2e000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x2) = 0xb7f2e000 close(4) = 0 close(3) = 0 It's probably because I only downloaded python from svn repo and ran ./configure&&make&&make install I didn't do anything else. Like set PYTHONPATH. I solved it though. You can tell by the output it's looking for it in my other python install lib path. Thank you. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 10:44 AM, Mark Dickinson wrote: > dule built, but Python is looking in the wrong > place for it, for some reason. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Jan 6 07:42:13 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 12:42:13 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > Such assumptions only hold under particular domains though. You can't > assume equality is an equivalence relation once you start thinking > about arbitrary domains. >From a formal mathematical point of view, equality /is/ an equivalence relation. If you have a relation on some domain, and it's not an equivalence relation, then it ain't the equality relation, and that's flat. > But there cannot be any such function which is a domain-independent > equivalence relation, not if we're talking about arbitrarily wacky > domains. That looks like a claim which requires a proof to me. But it could also do with a definition of `domain', so I'll settle for one of those first. If we're dealing with sets (i.e., `domain's form a subclass of `sets') then the claim is clearly false, and equality (determined by comparison of elements) is indeed a domain-independent equivalence relation. > Even something as straight-forward as "is" can't be an equivalence > relation under a domain where identity isn't well-defined. You've completely lost me here. The Python `is' operator is (the characteristic function of) an equivalence relation on Python values: that's its definition. You could describe an extension of the `is' relation to a larger set of items, such that it fails to be an equivalence relation on that set, but you'd be (rightly) criticized for failing to preserve one of its two defining properties. (The other is that `is' makes distinctions between values which are at least as fine as any other method, and this property should also be extended .) Let me have another go. All Python objects are instances of `object' or of some more specific class. The `==' operator on `object' is (the characteristic function of) an equivalence relation. In, fact, it's the same as `is' -- but `==' can be overridden by subclasses, and subclasses are permitted -- according to the interface definition -- to coarsen the relation. In fact, they're permitted to make it not be an equivalence class at all. I claim that this is a problem. I /agree/ that domain-specific predicates are useful, and can be sufficiently useful that they deserve the `==' name -- as well as floats and numpy, I've provided SAGE and sympy as examples myself. But I also believe that there are good reasons to want an `equivalence' operator (I'll write it as `=~', though I don't propose this as Python syntax -- see below) with the following properties: * `=~' is the characteristic function[1] of an equivalence relation, i.e., for all values x, y, z: x =~ y in (True, False); (x =~ x) == True; if x =~ y then y =~ x; and if x =~ y and y =~ z then x =~ z * Moreover, `=~' is a coarsening of `is', i.e. for all values x, y: if x is y then x =~ y. A valuable property might be that x =~ y if x and y are indistinguishable without using `is'. That would mean immediately that 'xyz' =~ 'xy' + 'z' (regardless of interning, because strings are immutable). But for tuples this would imply elementwise comparison, which may be expensive -- and, in the case of tuples manufactured by C extensions, nontrivial because manufactured tuples need not be acyclic. On the other hand, `==' is already recursive on tuples. We can envisage a collection of different relations, according to which distinguishing methods we're willing to disallow. For example, for numerical types, there are actually a number of interesting relations, according to whether you think the answers to the following questions are true or false. * Is 1 =~ 1/1? (Here, 1 is an integer, and 1/1 is a rational number; both are the multiplicative identities of their respective rings. I'd suggest that it doesn't seem very useful to say `no' here, but there might be reasons why one would want type(x) is type(y) if x =~ y.) * Is 1 =~ 1.0? (This is trickier. Numerically the values are equal; but the former is exact and the latter inexact, and this is a good reason to want a separation.) Essentially, these are asking whether `type' is a legitimate distinguisher, and I think that the answer, unhelpful as it may be, is `sometimes'. A third useful distinguishing technique is mutation. Given two singleton lists whose respective elements compare equivalent, I can mutate one of them to decide whether the other is in fact the same. Is this something which `=~' should distinguish? Again, the answer is probably `sometimes'. To summarize: we're left with at least three different characteristics which an equivalence predicate might have: * efficient (e.g., bounded recursion depth, works on circular values); * neglects irrelevant (to whom?) differences of type; and * neglects differences due to mutability. A predicate used to compare set elements or hash-table keys should probably /respect/ mutability. (Associating hashing with this predicate, rather than `==', would coherently allow mutable objects such as lists to be used as dictionary keys, though they'd be compared by address. I don't actually know how useful this would be, but suspect that it wouldn't.) Oh, before I go, let me make this very clear: I am /not/ proposing a language change. I think the right way to addres these problems is using existing mechanisms such as generic functions with multimethods. Syntax can come later if it seems sufficiently important. [1] I'll settle for it being a partial function, i.e., attempting to evaluate x =~ y might raise exceptions, e.g., if x is in some invalid state, or perhaps if one or both of x or y is circular, though it would be good to minimize such cases. -- [mdw] From nytrokiss at gmail.com Tue Jan 6 07:45:05 2009 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 6 Jan 2009 14:45:05 +0200 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> I agree but please enlighten us what caused you to say that python is great? On Sat, Jan 3, 2009 at 3:30 PM, Nomen Nescio wrote: > python is great. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Tue Jan 6 07:46:13 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Jan 2009 12:46:13 GMT Subject: Python subprocess question References: Message-ID: "Alexi Zuo" wrote: > Hi everyone, > > Here I have a simple program which starts a thread and the thread use > Popen to execute a shell cmd which needs a long time. I want to stop > the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this > program enters a dead loop. Can anyone tell me what is wrong? The KeyboardInterrupt exception is being raised in your main thread which doesn't handle it so it just terminates. Your child thread isn't marked as a daemon thread so the program won't exit until the child thread has also terminated. From skip at pobox.com Tue Jan 6 07:50:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 06:50:06 -0600 Subject: How to get involved In-Reply-To: <33e09baf-00b5-40f0-9b5f-152c370941e6@r36g2000prf.googlegroups.com> References: <33e09baf-00b5-40f0-9b5f-152c370941e6@r36g2000prf.googlegroups.com> Message-ID: <18787.21374.941591.845418@montanaro.dyndns.org> Kaj> I'm new to the open source comunnity and I was wondering if there Kaj> are any bugs that I can trouble shoot or just some beginner tasks I Kaj> can be sent? Python bugs and patches are tracked at http://bugs.python.org/ You can always write patches for bugs or review other peoples' patches. There is talk of a Python Bug Day in the near future. I suspect it will be announced here. A bug day is a virtual exercise where lots of people work on closing out items on the bug tracker. People communicate via IRC. You might check out the links in the core development page: http://www.python.org/dev/ You can also get involved with open source projects written in Python. There are plenty: Twisted SpamBayes Matplotlib SciPy etc etc etc -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From googler.1.webmaster at spamgourmet.com Tue Jan 6 07:53:52 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Tue, 6 Jan 2009 04:53:52 -0800 (PST) Subject: Compile as static library Message-ID: <32445465-1109-4df0-aea0-e86b3a8d7b8b@x16g2000prn.googlegroups.com> Hi! I have a big problem with compiling Python on MacOSX. I compile it - everything works ./configure make so I get a libpython2.5.a file which I include into a Xcode Project. I want to static link it with my project (works in Debug mode but not in Release) 1. Is there a static library flag which I have to set, or something like that? 2. Why does it work in Debug mode, not in Release? The import settings for a library doesn't differe between debug and release, does it? Thanks a lot. From you680 at gmail.com Tue Jan 6 08:00:36 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:00:36 -0800 (PST) Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data References: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> <496340a6$0$3533$426a74cc@news.free.fr> Message-ID: <6d409588-8f63-485b-932f-45b9dc23634e@w1g2000prk.googlegroups.com> On Jan 6, 7:29?pm, Bruno Desthuilliers wrote: > Jeremy.Chen a ?crit : > > > hi all: > > ? when I handled mass data table in mysql with python's MySQLdb lib, > > something frustrated me. I could't find any function like datareader, > > which yield one row by recording rows' anchor ,after each time I > > invoked 'read()' in a loop. > > I think you want cursor.fetchone(). But read below... > > > fetchall or fetchmany just fetched all data > > in once, which take so much memory when meeting one mass data > > table. > > The cursor object is it's own iterator. So you just have to do: > > cursor.execute(your_query) > for row in cursor: > ? ? process(row) > > HTH That's what I want. I see,cursor also can be a iterator. From mdw at distorted.org.uk Tue Jan 6 08:05:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 13:05:50 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> Message-ID: Steven D'Aprano wrote: > By all means, if Derek doesn't like the assignment model used by Python > (and Java, Ruby, C#, Perl, RealBasic, VisualBasic, Lua, and many other > languages going back to at least CLU in the mid 1970s) It goes back to Lisp in the late 1950s. [snip stuff I agree with.] -- [mdw] From you680 at gmail.com Tue Jan 6 08:08:53 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:08:53 -0800 (PST) Subject: ftp seems to get a delayed reaction. References: Message-ID: <125c8dc6-d467-443f-8755-4ab725266b22@z28g2000prd.googlegroups.com> On Jan 6, 7:56?pm, Antoon Pardon wrote: > I have managed to prune the script, so I can post it here: > > ========================================================== > > from ftplib import FTP > > bckrt = "/tmpstor/rcpc42" > > def process(): > ? print "making directory" > ? try: > ? ? ftp.mkd('ftp-tst') > ? ? print "mkdir succeeded" > ? except Exception, ErrMsg: > ? ? print "mkdir failed: %s" % ErrMsg > ? fl = open("tstfile") > ? print "storing file" > ? ftp.storbinary("STOR ftp-tst/ftp-file\n", ?fl) > ? fl.close() > > ftp = FTP('ftphost', 'user', 'passwd') > ftp.set_pasv(False) > ftp.cwd(bckrt) > > print "Doing once" > process() > print "Doing twice" > process() > > ---------------------------------------------------------- > And this is the output: > ========================================================== > Doing once > making directory > mkdir succeeded > storing file > Doing twice > making directory > mkdir failed: 500 '': command not understood. > storing file > Traceback (most recent call last): > ? File "ftptst", line 24, in > ? ? process() > ? File "ftptst", line 14, in process > ? ? ftp.storbinary("STOR ftp-tst/ftp-file\n", ?fl) > ? File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary > ? ? self.voidcmd('TYPE I') > ? File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd > ? ? return self.voidresp() > ? File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp > ? ? resp = self.getresp() > ? File "/usr/lib/python2.5/ftplib.py", line 216, in getresp > ? ? raise error_perm, resp > ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) ---------- I think the params after STOR should't be a path,should be splited. ftp.cwd("ftp-tst") ftp.storbinary("STOR ftp-file\n", fl) From you680 at gmail.com Tue Jan 6 08:17:01 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:17:01 -0800 (PST) Subject: Regex Generator From Multiple Files References: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> Message-ID: <76ab1a89-1e94-4a1c-be2f-55d87d3c2139@p2g2000prf.googlegroups.com> On Jan 6, 8:48?am, MRAB wrote: > James Pruitt wrote: > > I am looking for a way given a number of files, say 3, that represent > > technical support tickets in the same format to generate regular > > expressions for the different fields automatically. > > > An example from of one line from each file: > > Date: 12/30/2008 Room: 457 Building: Main > > Date: 12/31/2008 Room: A21 Building: Annex > > Date: 1/4/2009 Room: L69 Building: Library > > > The program would then, possibly using the python diff library, generate > > the regular expression needed to parse out different fields. In this > > case it might return a tuple like > > ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.?*)[\w]+$") > > that would match each of the fields based on the common data and sort of > > assume that what doesn't change between them is data we are looking for. > > Why not just assume that each field consists of a word terminated by a > colon, then some text, then the next field or the end of the line?- Hide quoted text - > > - Show quoted text - do you mean the sub method? ------------- re.sub( r'(?i)(example)',self.captureRegxp,content ) From victorsubervi at gmail.com Tue Jan 6 08:18:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 6 Jan 2009 14:18:52 +0100 Subject: =?ISO-8859-1?Q?Re:_Can=B4t_Surf_Python_Pages_in_Windoze?= In-Reply-To: <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> References: <4dc0cfea0812260701q6baf0ccbj154c5b3fa2281cdb@mail.gmail.com> <4954FB9F.5050702@wildenhain.de> <4dc0cfea0812260911k4dbc0f2ame9cc874e067b7816@mail.gmail.com> <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> Message-ID: <4dc0cfea0901060518k6d3d3b70w668fadfad58f1e63@mail.gmail.com> On Fri, Jan 2, 2009 at 4:24 PM, Victor Subervi wrote: > On Fri, Dec 26, 2008 at 8:00 PM, Gabriel Genellina > wrote: > >> En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi < >> victorsubervi at gmail.com> escribi?: >> >>> On 12/26/08, Tino Wildenhain wrote: >>> >> >> print "Content-Type: text/html" >>>>> print >>>>> print """ >>>>> >>>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>>> >>>> >> I think there should be only one blank line between header and content, >> you have two (so the document contains an empty line before the doctype >> declaration, and I think this is invalid). >> > I tried eliminating the second line (print) but it didn?t help. Seems there is a problem with Python on my Windoze box. I reinstalled with no luck. I tried opening a page which should have opened (works fine on my server) with same "black box" problem. Thanks, Victor > > Will try. Thanks. Let you know next week if problem. > Victor > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mal at egenix.com Tue Jan 6 08:31:52 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 14:31:52 +0100 Subject: creating a datetime.datetime from an XML xs:dateTime In-Reply-To: References: <5fa6c12e0812271208x4baccaedk262e51becb6e2076@mail.gmail.com> <18774.36465.346262.883182@montanaro-dyndns-org.local> <5fa6c12e0812271255l4f4893e8w9f96e9ace73ea50c@mail.gmail.com> Message-ID: <49635D48.9020803@egenix.com> On 2008-12-29 05:26, Jack.Chu wrote: > I think a simple regular expression is a relatively easy solution. Or use mxDateTime and let the parser do all the heavy lifting for you: >>> from mx.DateTime import Parser >>> t = Parser.DateTimeFromString('2000-01-12T12:13:14Z') >>> t >>> t = Parser.DateTimeFromString('2000-01') >>> t >>> t = Parser.DateTimeFromString('2000-01-12') >>> t http://www.egenix.com/products/python/mxBase/mxDateTime/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From Caseyweb at gmail.com Tue Jan 6 08:31:52 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 05:31:52 -0800 (PST) Subject: Python 3.0 nonlocal statement Message-ID: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> In PEP 3104 the nonlocal statement was proposed and accepted for implementation in Python 3.0 for access to names in outer scopes. The proposed syntax included an optional assignment or augmented assignment to the outer name, such as: nonlocal x += 1 This syntax doesn't appear to be supported in the 3.0 implementation. My question is: was this intentional or was it missed in the initial release? If it was intentional, is there any plan to support it in a later 3.x release? I realize it is a very small convenience feature but I have already come across a couple of cases where I use nested functions where it does make the code seem a little cleaner. Regards, Casey From n.kottiyath at gmail.com Tue Jan 6 08:33:29 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 6 Jan 2009 05:33:29 -0800 (PST) Subject: Traceback in Logging Message-ID: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> Hi all, Is it possible to print traceback for all logging? I have created something like this: def trace(): import traceback return ''.join(traceback.format_stack(limit=4)[1:]) And during every logging, append it - self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data, kwargs, trace())) -->Result<-- 2009-01-06 18:52:21,483 - test- INFO ---> Data:, kwargs: {} Traceback: File "C:\test.py", line 48, in success super(testObj, self).success(reply, **kwargs) File "C:\test.py", line 87, in success self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data, kwargs, trace())) File "C:\test.py", line 151, in trace return ''.join(traceback.format_stack(limit=4)[1:]) This seems somewhat kludgy. Is it possible in logging mechanism itself to provide traceback as default? I use Python2.4, so LoggingAdapter is not there too. From mdw at distorted.org.uk Tue Jan 6 09:03:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:03:16 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > (3) Those who come from an entirely different programming model, say, > Forth or Haskell. For them, Python's assignment model is going to be the > least of their worries. Actually, Haskell's assignment model (you have to grubbing about for IORefs or STRefs to find it but it's there) is exactly the same as Lisp, Scheme, Python, Dylan, Perl, Lua, Icon, Ruby, Erlang, ML, ... The variables-and-containers-hold-references-to-objects idea is common to a very large number (probably the majority? depends how you count) of high-level languages. Java is in the same category. C# is definitely not, since `struct's are composite, mutable value types clearly distinguishable from anything Python can do. The main dissent is probably from Tcl, which pretends to copy values -- even complex objects such as lists -- wholesale (though actually does fancy copy-on-write things under the covers). > Your first post in this topic made the extraordinarily arrogant and > incorrect claim that: > > [quote] > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. > [end quote] > > We can see some pretty poor assumptions right there: > > * That the Python community is capable of uniformly overlooking Python's > differences from other languages. > > * That only languages "substantially taught" in undergraduate CS courses > matter. And a massive assumption about the languages taught to CS undergrads too. In particular, Scheme is a fairly popular language to teach to undergrads, often as a first language. See, for example, `The Structure and Interpretation of Computer Programs' by Abelson and Sussman, and the (much more recent) `How to Design Programs' by Felleisen, Findler, Flatt and Krishnamurthi. > It seems that you don't include in the Python community all those who > use the term "name binding" instead of variable assignment > specifically because it gives new users a clue that Python is not the > same as C. Unfortunately, this practice causes other confusion, since `binding' is often used (in other language communities, notably Lisp and the functional languages) to describe the association between names and slots that hold references. Let me explain. I'll try to be clear, though I know that Stephen already understands this stuff well. At run-time, each named variable denotes a storage area (I'll call it a slot[2]) which holds a reference to some object[1]. +-----+ name ----> | ref -----> object +-----+ If we `assign' a different object to the variable, what really happens is that the slot is modified to refer to the other object; but the name continues to denote the same slot. Usually `binding', or `rebinding', a name describes a different process, whereby the name (for a while) denotes a different slot. This name-to- slot mapping is important because it's the mapping which is inherited by nested functions. This is most clearly shown by example. Consider this Python interaction. In [1]: l = [] In [2]: for i in [1, 2, 3]: ...: l.append(lambda: i) ...: In [3]: [f() for f in l] Out[3]: [3, 3, 3] This prints [3, 3, 3]. What's happened is that the lambdas have closed over the prevailing /binding/ of i -- i.e., which reference slot it denotes. Since the for loop operates by assignment, and /not/ by rebinding i, the three lambdas all closed over the same environment, and return the same value. Scheme's DO loop, by contrast, really does operate by binding. Consider this example of a GNU Guile interaction. guile> (define l '()) guile> (do ((i (list 1 2 3) (cdr i))) ... ((null? i)) ... (set! l (append l (list (lambda () (car i)))))) guile> (map (lambda (f) (f)) l) $1 = (1 2 3) That is, each time through the loop, the variable I denotes a /different/ reference slot; the LAMBDAs close over different environments, and the functions return different values. (This example illustrates both binding and assignment, since the SET! changes the value referred to in the slot denoted by L, without rebinding L.) A very approximate translation of the above into Python looks like this. In [1]: l = [] In [2]: items = [1, 2, 3] In [3]: def _loop(ix): ...: if ix >= len(items): return ...: l.append(lambda: items[ix]) ...: _loop(ix + 1) ...: In [4]: _loop(0) In [5]: [f() for f in l] Out[5]: [1, 2, 3] (I've cheated and used indices because Python lists don't have the head/tail structure of Lisp lists.) None of this is a criticism of Python's behaviour. (Sometimes it'd be nice if `for' worked by rebinding, but sometimes it's better that it doesn't.) But it is a criticism of the Python community's confusing use of the word `binding' to mean something different from what fairly closely-related communities use it to mean. [1] Lisp has a notion of `unbound variables', which is another confusing use of the terminology. What this usually means is that the variable really refers to a special value, and the run-time signals an error if it retrieves this value from a variable. [2] `Slot' gets used a lot too. Sorry. This usage has nothing to do with Lisp's structure or instance slots, and nothing to do with Python's __slots__. > You've also missed out on probably twenty years of CS where Java (using > the same assignment model as Python!) has been *the* language of choice > for undergrad CS, not to mention those introductory courses which use > Python. There's no way that Java has been taught anywhere for 20 years. It just isn't old enough. Wikipedia claims that Java appeared in 1995, which looks right to me. Python, released in 1991, is therefore older. > > And then you're shocked, SHOCKED!!! that people respond sharply. > > How different do you think the response would have been if you had said: > > "What we in the Python community should try to remember is that for those > new to the language, there can sometimes be preconceived ideas about how > assignment works that clashes with Python's assignment model. From my own > perspective, I found the differences between Python's name binding model > and the named-bins model of C/Pascal/Fortran confusing at first, and to > be honest, I still get caught by those differences. Naturally this is a > general problem for every language, Python is hardly unique, but please > remember not to bite the newbies just because they are still thinking in > some other language." > > -- [mdw] From mdw at distorted.org.uk Tue Jan 6 09:12:19 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:12:19 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: Steven D'Aprano wrote: > I don't think so. Variables in algebra are quite different from variables > in programming languages. Contrast the statement: > > x = x+1 > > as a programming expression and an algebraic equation. As a programming > expression, it means "increment x by one". But as an algebraic > expression, it means "x is some value such that it is equal to one more > than itself", and there is no solution to such an equation. Surely there is. The solution is: 1 = 0 (and hence x is an -- no, /the/ -- element of the trivial ring). > > and how several generations of computer languages, not to mention > > the actual machine language those generated, behaved, before the current > > crop. > > Sure. And? Actally, this is true only for /very/ small values of `several'. There was FORTRAN in 1957, with what you're calling the `named bins' model, and I call assignment-is-copying, and Lisp in 1958, with the assignment- is-pointer-diddling model. -- [mdw] From simon at brunningonline.net Tue Jan 6 09:15:11 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 6 Jan 2009 14:15:11 +0000 Subject: Returning a string In-Reply-To: References: Message-ID: <8c7f10c60901060615o3de4a9f7ybb2480e3eee91784@mail.gmail.com> 2009/1/3 Kless : > How is possible that I can print a variable, but when I use *return > var* it returns an empty string What makes you think it's returning an empty string? You aren't doing anything with the return value in line 26 of your example. -- Cheers, Simon B. From lihang9999 at gmail.com Tue Jan 6 09:28:37 2009 From: lihang9999 at gmail.com (Li Han) Date: Tue, 6 Jan 2009 06:28:37 -0800 (PST) Subject: image recogniton? Message-ID: Hi! I know little about the computer image processing, and now I have a fancy problem which is how to read the time from the picture of a clock by programming ? Is there anyone who can give me some suggestions? Thank! Li Han From mdw at distorted.org.uk Tue Jan 6 09:32:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:32:04 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > I think I have though, not that it matters, since that was never > really my point. Python's assignment model requires more explanation > than the traditional one, simply to state what it does. That alone is > evidence (but not proof). Hmm. Actually, it's not the assignment model which is strange at all. It's the data model. What does an expression like [1, 2, 3] denote? Is it the list itself, or a /reference/ to the list? If you answer the first, you'll want Tcl/C/Fortran semantics. If you answer the second, you'll want Lisp/Python/Javascript semantics. If you answer `it depends', you'll want to be confused. Python decided that all values are passed around as and manipulated through references. (There are no locatives: references are not values, and you can't have a reference to a reference.) Lists store references; tuples store references; and so on. If one is to be able to implement complex data structures which involve sharing of data (e.g., cyclic graphs) or which allow efficient reorganization (e.g., various kinds of trees) we need to be able to manage references to values somehow. There are a number of ways of doing this. * Everything is a reference. This is the most uniform. Once you've got the hang of it, there are no surprises. * Nothing is a reference. If you want complex data structures, you're either screwed (e.g., if your data model is too weak) or you have to invent them yourself using array indices or something wretched like that. Tcl is in this category: you have to mess with (associative) arrays or variable names to make complex data structures. * Some values are references to others. This is like C, and causes exciting problems when you get confused. C++ makes things more confusing because dereferencing can happen implicitly. Perl manages to be in this camp /and/ the first one. It's very strange. * Some things are references, and some aren't. This is what Java and C# do. Java says that only simple, atomic things are non-references, so assignment looks the same either way, but you can't store primitive things in containers expecting to store references (until Sun added automatic boxing and unboxing -- eventually). C# makes matters more complicated by letting users define structured mutable data which aren't handled by reference, but does the boxing and unboxing thing transparently. > As for there being no assignment in algebra, is that not really what > variable substitution is? No. > They have different names, but in my estimation they perform exactly > the same function. You're assigning specific values to the variables > in an expression so that you can solve for a constant... just like in > a computer program. When you do this, you construct a different expression. They might have equal values, but they're still different. (You can consider equivalence classes under some appropriate equivalence relation if you like, but that just makes things more complex.) > There is even an allocation of memory: it's in your brain. :D Ahh! You're modifying a memory location in your brain so that it refers to a different expression. Isn't this the Lisp/Python/Javascript model? ;-) -- [mdw] From dotancohen at gmail.com Tue Jan 6 09:35:11 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 16:35:11 +0200 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <880dece00901060635g5c6a73eew6352f13d449ca695@mail.gmail.com> 2009/1/3 Nomen Nescio : > python is great. > No, those are anacondas. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From furkankuru at gmail.com Tue Jan 6 09:50:04 2009 From: furkankuru at gmail.com (Furkan Kuru) Date: Tue, 6 Jan 2009 16:50:04 +0200 Subject: image recogniton? In-Reply-To: References: Message-ID: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> start with Python Image Library: http://www.pythonware.com/products/pil/ On Tue, Jan 6, 2009 at 4:28 PM, Li Han wrote: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han > -- > http://mail.python.org/mailman/listinfo/python-list > -- Furkan Kuru -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-url at phaseit.net Tue Jan 6 10:05:37 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 6 Jan 2009 15:05:37 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 6) Message-ID: QOTW: "If you have good, experienced people who are able to withstand the pressure to deliver no matter what and are familiar with the problem domain, then any project is on the way to succeess no matter what technology was chosen in my experience. The choice of type system is way down on the list." - Stefan Axelsson Performance comparison: multiprocessing vs threading: http://groups.google.com/group/comp.lang.python/t/f99326a4e5d394e/ A speed boost of more than 15% in many common situations is exciting: http://bugs.python.org/issue4753 How to seek to the last line in a text file: http://groups.google.com/group/comp.lang.python/t/e24ac82e6d236c1e/ Counting elements - where a "bag" class would be useful: http://groups.google.com/group/comp.lang.python/t/68acebd75fb7c61c/ How (and when) to forcibly kill a thread: http://groups.google.com/group/comp.lang.python/t/c080c23fed0f8a5a/ Getting all function defined in a file: http://groups.google.com/group/comp.lang.python/t/7be03c127bd8eabe/ Debugging embedded applications: http://groups.google.com/group/comp.lang.python/t/1edb44574e4da6b6/ Guilherme Polo nicely illustrates embedding in a tktable Tkinter cell: http://mail.python.org/pipermail/tkinter-discuss/2009-January/001787.html Running Python scripts inside a web browser: http://groups.google.com/group/comp.lang.python/t/d977140a3a163025/ Unpacking tuples of different sizes: http://groups.google.com/group/comp.lang.python/t/b8eb96ba3097a27e/ http://groups.google.com/group/comp.lang.python/t/ecf29cdc64010a4d/ Why isn't `some*(arbitrary-expression) = value` allowed? http://groups.google.com/group/comp.lang.python/t/75a63598d7f0b60c/ It's not a good idea to create many logger instances: http://groups.google.com/group/comp.lang.python/t/31c394f0bd0bc8b3/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From andrea.francia at REMOVE-FROM-HERE.ohoihihoihoih.TO-HERE.gmx.it Tue Jan 6 10:20:15 2009 From: andrea.francia at REMOVE-FROM-HERE.ohoihihoihoih.TO-HERE.gmx.it (Andrea Francia) Date: Tue, 06 Jan 2009 15:20:15 GMT Subject: Code Review request for the trash-cli project Message-ID: The trash-cli project is a opensource implementation of the FreeDesktop.org Trash Specification that provides a command line interface to manage the trashcan. It's provide the following commands: * trash-put trashes files and directories. * trash-empty empty the trashcan(s). * trash-list list trashed file. * trash-restore restore a trashed file. It is written in python and its sources are available at http://code.google.com/p/trash-cli/source/browse/#svn/trunk I'm the main developer and I'm not so good in Python as I would be. Would you review my software and point out the problems you see? The review comments can be written using the code-review facilities of google code. You need only to double click the line of code where you want add a comment. Patches are also welcome. Thank you. From fredrik.johansson at gmail.com Tue Jan 6 10:23:10 2009 From: fredrik.johansson at gmail.com (Fredrik Johansson) Date: Tue, 6 Jan 2009 07:23:10 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> Message-ID: <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> On Dec 28 2008, 4:55?pm, jerry.carl... at gmail.com wrote: > > - are you usingDecimalfor the base-10-ness or the > > ? extra precisionDecimalprovides? ?Or significant zeros? > > ? Or compatibility with existingDecimalcode, or what? > > Oh boy, now I will finally prove myself illiterate... well, so be it. > But i am after the extra precision: > > >>> from math import * > >>> (1+1e-16)-1 > > 0.0 > > Agree: sin, cos and atan would do it. FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- precision standard transcendental functions in pure Python. It is much faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, and handles huge arguments just fine. Fredrik From tino at wildenhain.de Tue Jan 6 10:25:45 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 06 Jan 2009 16:25:45 +0100 Subject: image recogniton? In-Reply-To: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> Message-ID: <496377F9.6080903@wildenhain.de> Hi, Furkan Kuru wrote: > start with Python Image Library: > http://www.pythonware.com/products/pil/ I think this is more a job for OpenCV and its python bindings. http://opencv.willowgarage.com/wiki/PythonInterface > On Tue, Jan 6, 2009 at 4:28 PM, Li Han > wrote: > > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mail at microcorp.co.za Tue Jan 6 10:26:45 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 6 Jan 2009 17:26:45 +0200 Subject: image recogniton? References: Message-ID: <008d01c97014$1df62fe0$0d00a8c0@hendrik> "Li Han" wrote: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? When the big hand is on the twelve, and the little hand is on the eight, it is eight O'clock... :-) - Hendrik From dotancohen at gmail.com Tue Jan 6 10:30:19 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 17:30:19 +0200 Subject: Code Review request for the trash-cli project In-Reply-To: References: Message-ID: <880dece00901060730s56747954he2d251267d503173@mail.gmail.com> 2009/1/6 Andrea Francia : > The trash-cli project is a opensource implementation of the FreeDesktop.org > Trash Specification that provides a command line interface to manage the > trashcan. > > It's provide the following commands: > * trash-put trashes files and directories. > * trash-empty empty the trashcan(s). > * trash-list list trashed file. > * trash-restore restore a trashed file. > > It is written in python and its sources are available at > > http://code.google.com/p/trash-cli/source/browse/#svn/trunk > > I'm the main developer and I'm not so good in Python as I would be. > > Would you review my software and point out the problems you see? > > The review comments can be written using the code-review facilities of > google code. You need only to double click the line of code where you want > add a comment. > > Patches are also welcome. > > Thank you. > I don't know about the code, but would there be a reason _not_ to alias rm, rmdir to this program? I see that it is GPL, so this would be a great addition to any Linux distro. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From mark.fink1 at googlemail.com Tue Jan 6 10:32:20 2009 From: mark.fink1 at googlemail.com (mark) Date: Tue, 6 Jan 2009 07:32:20 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python Message-ID: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. This means no disturbing '.;()\' characters. I like to have the power of the hosting language as well. Thats why I want to build it as an internal DSL and NOT as a external DSL. I want the DSL as human readable as possible: >>> open_browser navigate_to 'www.openstreetmap.org' website search 'Von-Gumppenberg-Strasse, Schmiechen' verify search_result zoom in <<< Martin Fowler recommends "Method Chaining" to build internal DSLs: >>> Browser("http://www.openstreetmap.org/") \ .search("Von-Gumppenberg-Strasse, Schmiechen") \ .zoom_in() <<< I guess that it is possible to argue that this means the same. Nevertheless I do not like all the parentheses and punctuation necessary to satisfy the Python interpreter. The reason why I need this is that I want to have non technical people review the files written in the DSL. I already know that there are parser frameworks available but I want to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and whatnot). How would one approach this in Python? Do I need to build a custom loader which compiles *.dsl files to *.pyc files? Is it possible to switch between the custom DSL and the standard Python interpreter? From dotancohen at gmail.com Tue Jan 6 10:45:36 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 17:45:36 +0200 Subject: image recogniton? In-Reply-To: <008d01c97014$1df62fe0$0d00a8c0@hendrik> References: <008d01c97014$1df62fe0$0d00a8c0@hendrik> Message-ID: <880dece00901060745y7ba1ed15kf45d50d2d43a5689@mail.gmail.com> 2009/1/6 Hendrik van Rooyen : > "Li Han" wrote: > >> Hi! I know little about the computer image processing, and now I have >> a fancy problem which is how to read the time from the picture of a >> clock by programming ? Is there anyone who can give me some >> suggestions? > > When the big hand is on the twelve, and the little hand is on the eight, > it is eight O'clock... > My clock is digital, you insensitive clod! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From skip at pobox.com Tue Jan 6 10:53:55 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 09:53:55 -0600 Subject: image recogniton? In-Reply-To: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> Message-ID: <18787.32403.82637.308936@montanaro.dyndns.org> Furkan> start with Python Image Library: Furkan> http://www.pythonware.com/products/pil/ Well, there's the little problem of optical character recognition. You might want to check out open source OCR tools like gocr: http://jocr.sourceforge.net/ Just use PIL to convert input images into PNM format, run gocr in a subprocess read the stdout to get text. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From tekion at gmail.com Tue Jan 6 10:56:18 2009 From: tekion at gmail.com (tekion) Date: Tue, 6 Jan 2009 07:56:18 -0800 (PST) Subject: figuring week of the day.... Message-ID: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Is there a module where you could figure week of the day, like where it starts and end. I need to do this for a whole year. Thanks. From rt8396 at gmail.com Tue Jan 6 11:00:14 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 08:00:14 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <0546c834-957f-41e3-94e1-db359a5fd36f@w39g2000prb.googlegroups.com> On Jan 6, 9:56?am, tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. import datetime help(datetime) import time help(time) From vinay_sajip at yahoo.co.uk Tue Jan 6 11:01:01 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jan 2009 08:01:01 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> Message-ID: <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> On Jan 6, 1:33 pm, Kottiyath wrote: > This seems somewhat kludgy. Is it possible in logging mechanism itself > to provide traceback as default? > No, because it's not a common use case to print tracebacks for every logging call. There's support for adding traceback information in exception handling, via use of the Logger.exception method in the exception handling code. > I use Python2.4, so LoggingAdapter is not there too. If you need LoggingAdapter, you can always copy and paste the relevant code from Python's SVN repository into your own application. Regards, Vinay Sajip From joe at strout.net Tue Jan 6 11:01:31 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 09:01:31 -0700 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <4963805B.3090000@strout.net> Mark Wooding wrote: > Derek Martin wrote: > >> I think I have though, not that it matters, since that was never >> really my point. Python's assignment model requires more explanation >> than the traditional one, simply to state what it does. That alone is >> evidence (but not proof). > > Hmm. Actually, it's not the assignment model which is strange at all. > It's the data model. What does an expression like > > [1, 2, 3] > > denote? Is it the list itself, or a /reference/ to the list? If you > answer the first, you'll want Tcl/C/Fortran semantics. If you answer > the second, you'll want Lisp/Python/Javascript semantics. If you answer > `it depends', you'll want to be confused. Well said! You can easily see that assignment in Python is perfectly ordinary, by comparing it to languages that have both values and references (such as C++, Java, or REALbasic). Those languages have only one assignment model, that operates on both values and references just fine. Python has only references, and I think it's for this reason that some people here try to pretend that it doesn't have them at all, thus leading them to weird explanations of strange assignment and argument-passing behavior. > Python decided that all values are passed around as and manipulated > through references. (There are no locatives: references are not values, > and you can't have a reference to a reference.) Also very clearly put. If you don't mind, I may crib some of your verbage for , as it may be clearer than my own. Best, - Joe From sturlamolden at yahoo.no Tue Jan 6 11:03:41 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:03:41 -0800 (PST) Subject: Extending Python with C or C++ References: Message-ID: <87a6fd18-d9bc-4a65-b635-f1519e67b5cf@t39g2000prh.googlegroups.com> On Jan 5, 9:06 pm, Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts (C/C++) and extending it. But, extending python > still seems like a black art to me. There are several alternatives to using the Python C API by hand, depending on your particular need. It will save you a lot of greif: Pyrex: Python-like language for creating extension modules. *Cython: clone of Pyrex *ctypes: call DLLs from python comtypes: call COM DLLs from Python *f2py: generate wrappers for Fortran or C libraries. Knowledge of Fortran required. pywin32: use or implement ActiveX objects with Python *scipy.weave: inline C++ code in Python Swig: generate wrappers for C libraries (some C++ support) CXX: C++ wrapper for the Python C API Boost.Python: C++ wrapper for the Python C API SIP: generate wrappers for C++ libraries (* Works easily with NumPy arrays.) From mccredie at gmail.com Tue Jan 6 11:10:13 2009 From: mccredie at gmail.com (Matimus) Date: Tue, 6 Jan 2009 08:10:13 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> Message-ID: <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> On Jan 6, 5:31?am, Casey wrote: > In PEP 3104 the nonlocal statement was proposed and accepted for > implementation in Python 3.0 for access to names in outer scopes. ?The > proposed syntax included an optional assignment or augmented > assignment to the outer name, such as: > > nonlocal x += 1 > > This syntax doesn't appear to be supported in the 3.0 implementation. > My question is: was this intentional or was it missed in the initial > release? ?If it was intentional, is there any plan to support it in a > later 3.x release? ?I realize it is a very small convenience feature > but I have already come across a couple of cases where I use nested > functions where it does make the code seem a little cleaner. > > Regards, Casey `nonlocal` should behave just like `global` does. It doesn't support that syntax either. So, yes it was intentional. No, there probably is no plan to support it in a later release. Matt From sturlamolden at yahoo.no Tue Jan 6 11:13:46 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:13:46 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <614dfad7-8367-479f-bf99-45e11ee1122d@w24g2000prd.googlegroups.com> On Jan 6, 4:32 pm, mark wrote: > Is it possible to > switch between the custom DSL and the standard Python interpreter? As far as I can tell, there are three different options: - Embed a Python and DSL interpreter in the same executable. - Write the DSL interpreter in Python. - Expose the DSL interpreter as a Python extension module. I don't know which you prefer, but I would try to avoid the first. From n.kottiyath at gmail.com Tue Jan 6 11:17:02 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 6 Jan 2009 08:17:02 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: I dont want the whole traceback. I just wanted to know where the log was generated from i.e. which procedure and which line. I have 3/4 points in many procedures where I encounter a small error (not an exception) and want to log it. So having individual names for each looks to be somewhat verbose - esp since the application is >10K LOC. This might be a good item to have in the logging system - along with time and level, just proc name and the line number. Thank you for the help. Regards K Vinay Sajip wrote: > On Jan 6, 1:33 pm, Kottiyath wrote: > > This seems somewhat kludgy. Is it possible in logging mechanism itself > > to provide traceback as default? > > > > No, because it's not a common use case to print tracebacks for every > logging call. There's support for adding traceback information in > exception handling, via use of the Logger.exception method in the > exception handling code. > > > > I use Python2.4, so LoggingAdapter is not there too. > > If you need LoggingAdapter, you can always copy and paste the relevant > code from Python's SVN repository into your own application. > > Regards, > > Vinay Sajip From sturlamolden at yahoo.no Tue Jan 6 11:18:08 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:18:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> On Jan 6, 4:32 pm, mark wrote: > I want to implement a internal DSL in Python. I would like the syntax > as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). From skip at pobox.com Tue Jan 6 11:30:43 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 10:30:43 -0600 Subject: Traceback in Logging In-Reply-To: References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: <18787.34611.420657.794371@montanaro.dyndns.org> Kottiyath> I dont want the whole traceback. I just wanted to know where Kottiyath> the log was generated from i.e. which procedure and which Kottiyath> line. The asyncore standard module has an undocumented compact_traceback() function: #!/usr/bin/env python import asyncore def f(): 1/0 def g(): f() def h(): g() try: h() except ZeroDivisionError: print asyncore.compact_traceback()[3] Output looks like this: % python f.py [f.py||15] [f.py|h|12] [f.py|g|9] [f.py|f|6] Might be of interest. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From metalzong at 163.com Tue Jan 6 11:45:45 2009 From: metalzong at 163.com (Metal Zong) Date: Wed, 7 Jan 2009 00:45:45 +0800 Subject: Problem on pylab - matplotlib_examples_0.98.3 Message-ID: <029201c9701e$392a67e0$6501a8c0@nsnintra.net> Hello, I meet some problems on pylab (matplotlib_examples_0.98.3). I could not get valuable information from api document. Any help is appreciated. Or is there any other convenient library for making charts. Thanks a lot. 1, It's ok to draw table chart with enclosed file. 2. The problem is - the position is wrong if I try to add plot on this chart - (un-comment the part in the end) -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 1898740 bytes Desc: not available URL: From rtw at freenet.co.uk Tue Jan 6 11:46:02 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 06 Jan 2009 10:46:02 -0600 Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: Matimus wrote in news:2a3d6700-85f0-4861-84c9-9f269791f044 @f40g2000pri.googlegroups.com in comp.lang.python: > On Jan 6, 5:31?am, Casey wrote: >> In PEP 3104 the nonlocal statement was proposed and accepted for >> implementation in Python 3.0 for access to names in outer scopes. ?The >> proposed syntax included an optional assignment or augmented >> assignment to the outer name, such as: >> >> nonlocal x += 1 >> >> This syntax doesn't appear to be supported in the 3.0 implementation. >> My question is: was this intentional or was it missed in the initial >> release? ?If it was intentional, is there any plan to support it in a >> later 3.x release? ?I realize it is a very small convenience feature >> but I have already come across a couple of cases where I use nested >> functions where it does make the code seem a little cleaner. >> >> Regards, Casey > > `nonlocal` should behave just like `global` does. It doesn't support > that syntax either. So, yes it was intentional. No, there probably is > no plan to support it in a later release. > > Matt > http://www.python.org/dev/peps/pep-3104/ A shorthand form is also permitted, in which nonlocal is prepended to an assignment or augmented assignment: nonlocal x = 3 The above has exactly the same meaning as nonlocal x; x = 3. (Guido supports a similar form of the global statement [24].) Searching (AKA googling) for: nonlocal site:bugs.python.org leads to: http://bugs.python.org/issue4199 Rob. -- http://www.victim-prime.dsl.pipex.com/ From Caseyweb at gmail.com Tue Jan 6 11:48:15 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 08:48:15 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: <886f160b-4cdb-4249-adfe-566996e28915@m2g2000vbp.googlegroups.com> On Jan 6, 11:10?am, Matimus wrote: > `nonlocal` should behave just like `global` does. It doesn't support > that syntax either. So, yes it was intentional. No, there probably is > no plan to support it in a later release. > > Matt >From my perspective, that's an unfortunate decision and I question the rationale. First, nonlocal doesn't behave exactly like global (you cannot declare a previously undefined variable nonlocal as you can with global). Second, the PEP 3104 description explicitly mentions that Guido favored adding this behavior to global; I would have preferred that approach to not providing the extended assignment support for nonlocal. Third, I believe that it adds some clarity to the code. Seeing 'nonlocal x += 1' immediately tells me that I'm incrementing a variable defined in an outer scope. Having 'nonlocal x' on one line and 'x += 1' on another makes it a little less clear. But I do appreciate the reply! Casey From Caseyweb at gmail.com Tue Jan 6 11:52:40 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 08:52:40 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: <26dce886-497d-4edc-8bbe-a32333356621@q18g2000vbn.googlegroups.com> On Jan 6, 11:46?am, Rob Williscroft wrote: > Matimus wrote in news:2a3d6700-85f0-4861-84c9-9f269791f044 > Searching (AKA googling) for: nonlocal site:bugs.python.org > leads to:http://bugs.python.org/issue4199 > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Doh. I looked at the PEP and the 3.0 BNF syntax and never thought to search the online bugs. Thanks, Rob! From sturlamolden at yahoo.no Tue Jan 6 12:18:10 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 09:18:10 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <62471ee7-fcb6-455f-8442-56595c1f78ce@f40g2000pri.googlegroups.com> On Jan 2, 5:43 pm, Steve Holden wrote: > Derek Martin wrote: > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > [...] > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that > > its assignment model is BIZARRE, as in it's conceptually different > > from virtually all other languages substantially taught in > > undergraduate computer science programs. And for that matter, it's > > pretty unintuitive generally. > > I'd definitely argue against bizarre. It's actually very easy to > understand, and Python is by no means the only language to have used it. A statement like f(x) = 1 has no meaning in most languages - including Python, C and Java. C++ references allows operator= to be overloaded. It is one of few languages where a statement like 'f(x) = 1;' maybe meaningful. But C++ references are addresses (pointers in disguise), not names. The = is Python's name binding operator. Python is similar to Java in this respect. If anything is bizarre here, it is C++ references. P.S. The C statement '*f(x) = 1;' does have meaning, but 'f(x) = 1;' do not. But in the former case, one is not assigning to the return value. Python and Java do not have raw pointers like C. From joe at strout.net Tue Jan 6 12:36:47 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 10:36:47 -0700 Subject: python is great In-Reply-To: <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> Message-ID: <496396AF.5020809@strout.net> I've actually been rather frustrated by Python lately. It's great at some things, but rather poor at others. In the latter category is building a neatly packaged executable that can be shipped to users and run reliably on their machine. On the Mac in particular, if you want your app to run on any PowerPC or Intel machine runing 10.4 or later, and you're using anything not in the standard framework (such as MySQLdb), it's a bit of a nightmare. Compare this to, say, REALbasic, where you just check "Mac OS X Universal" in the Build Settings, click Build, and you're done. (RB has its own issues, of course.) So I would say that Python as a language is great, and its standard framework is great. But its (many) IDEs are pretty poor, and the process of building a polished, packaged app is abysmal. And there are some things (such as Flash-style web applets) that you still can't do at all in Python, even after all these years. But of course, the nice thing about an open-source environment is that, with enough motivation, time, and expertise, one can fix the most annoying limitations oneself. And if I stick with Python over the upcoming years, I'll certainly do my part. Best, - Joe From rt8396 at gmail.com Tue Jan 6 12:37:45 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 09:37:45 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <0546c834-957f-41e3-94e1-db359a5fd36f@w39g2000prb.googlegroups.com> Message-ID: <31bd361e-438b-4d1f-9736-3cd21f128693@e1g2000pra.googlegroups.com> here are a few tuts that go into more detail http://effbot.org/librarybook/datetime.htm http://seehuhn.de/pages/pdate From joe at strout.net Tue Jan 6 12:44:39 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 10:44:39 -0700 Subject: If your were going to program a game... In-Reply-To: References: Message-ID: <49639887.5000806@strout.net> Kay Schluehr wrote: > There is no solution to this problem from a Python perspective. Do > what everyone does right now: use Flash for the game and manage your > site with Python if you like the language. I know this has been discussed before, and the difficulties are many, yadda yadda etc... But suppose we reduce the scope: just the core Python language, maybe a VERY few of the standard modules (e.g. math and string), plus some pygame-like classes to move sprites around, play sounds, and check keyboard and mouse state. Or to look at it another way: Python is used as the scripting language in many commercial games. Why couldn't we make a browser plugin (in C++, for example) that implements a "generic" game, i.e. moving of sprites and playing of sounds and so on -- and that uses Python as its scripting language? Not that I have anything against Flash; I've started learning it just last week, and apart from the nasty C-derived syntax, it's quite nice. It has a good IDE, good performance, great portability, and it's easy to use. It just surprises me that after all these years, the Python community hasn't done something similar. Best, - Joe From sturlamolden at yahoo.no Tue Jan 6 12:45:02 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 09:45:02 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: On Jan 2, 11:39 am, Derek Martin wrote: > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. For one thing, Python's 'assignment model' (an annoying buzzword) is similar to that of Java. It cannot be that different from what is thought in undergraduate CS classes. But take a look at C++: int& foobar(int& x) { // blahblah } Now a statement like 'foobar(x) = y;' can actually have a meaning. Whereas, int* foobar(int& x) { // blahblah } would make the same statement illegal. I have yet to see undergraduate students knowing the difference between C++ pointers and references after attending an introductory CS course. Try to do the same in, say, Java. You will see that is behaves like Python. And as for bizarreness, I feel that Python and Java is greatly surpassed by C++. Note that C do not share the bizarreness of C++. From lists at js3d.co.uk Tue Jan 6 12:51:03 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 17:51:03 -0000 Subject: reading stdout from a running win32 process Message-ID: <017601c97027$58d83690$0a88a3b0$@co.uk> Hi list, I'm launching a process from windows using the demo 'winprocess' from the win32 extensions. I want to be able to record the output of the process as it runs and display it elsewhere. If I use the following [very bad] code: import winprocess import tempfile import time some_condition=True out=tempfile.TemporaryFile() #launch process winprocess.run('xsibatch.exe', show=1, stdout=out, stderr=out) while some_condition<20: print out.read() time.sleep(0.2) some_condition+=1 out.close() I don't seem to be able to read the 'out' at all? If I omit redirecting stdout etc then the output displays fine in the console. Any info / pointers on where I'm going very wrong much appreciated. Jules From rdcollum at gmail.com Tue Jan 6 13:07:04 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 6 Jan 2009 10:07:04 -0800 (PST) Subject: Python subprocess question References: Message-ID: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> On Jan 6, 7:46?am, Duncan Booth wrote: > "Alexi Zuo" wrote: > > Hi everyone, > > > Here I have a simple program which starts a thread and the thread use > > Popen to execute a shell cmd which needs a long time. ?I want to stop > > the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this > > program enters a dead loop. Can anyone tell me what is wrong? > > The KeyboardInterrupt exception is being raised in your main thread which > doesn't handle it so it just terminates. Your child thread isn't marked as > a daemon thread so the program won't exit until the child thread has also > terminated. I've been recently working with threads for the first time and I've been unclear on the setDaemon flag though I've sifted through the documentation for a clear answer (most likely my reading comprehension has failed me and not the documentation). I think I had the notion of that flag backwards. .setDaemon(True) means the thread gets destroyed when the program exits and default .setDaemon(False) means that the thread continues to process even when the main program is gone? From sturlamolden at yahoo.no Tue Jan 6 13:18:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 10:18:29 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: On Jan 6, 3:35 pm, "Dotan Cohen" wrote: > 2009/1/3 Nomen Nescio : > > > python is great. > > No, those are anacondas. Unless Nomen Nescio is thinking of the giant serpent Python from greek mythology. - Python lived in a cave near Delphi. CPython can be embedded in Delphi. - Python was made of slime. CPython runs equally slow. - Python had pythian games. CPython has PyGame. - Pythian can be made pythonian. - Pythians are benevolent. Pythonistas are not (except for Guido). I think that sums it up. From skip at pobox.com Tue Jan 6 13:18:42 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 12:18:42 -0600 Subject: Python subprocess question In-Reply-To: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> References: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> Message-ID: <18787.41090.846416.883877@montanaro.dyndns.org> Roger> .setDaemon(True) means the thread gets destroyed when the program Roger> exits and default .setDaemon(False) means that the thread Roger> continues to process even when the main program is gone? Approximately. The main thread (and thus the program) will exit only when all non-daemon threads have finished. A thread can't continue to run if the main program has exited. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From sturlamolden at yahoo.no Tue Jan 6 13:29:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 10:29:49 -0800 (PST) Subject: reading stdout from a running win32 process References: Message-ID: <21f99889-9440-436e-8d0d-de89aa19c1d4@z6g2000pre.googlegroups.com> On Jan 6, 6:51 pm, "Jules Stevenson" wrote: > I don't seem to be able to read the 'out' at all? If I omit redirecting > stdout etc then the output displays fine in the console. You are redirecting to a file, not a pipe. Read the file from beginning to end after your process had finished. Or redirect to a pipe. From jcd at sdf.lonestar.org Tue Jan 6 13:55:36 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 06 Jan 2009 13:55:36 -0500 Subject: python is great In-Reply-To: <496396AF.5020809@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: <1231268136.14487.1.camel@aalcdl07.lib.unc.edu> On Tue, 2009-01-06 at 10:36 -0700, Joe Strout wrote: > I've actually been rather frustrated by Python lately. OFF TOPIC!!! Please try to stay within the subject presented by the subject header. The subject in question is "python is great," not "python is frustrating." Speaking of which, python is truly great. From dotancohen at gmail.com Tue Jan 6 13:59:50 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 20:59:50 +0200 Subject: python is great In-Reply-To: References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <880dece00901061059m76eb0c00kcc662ebd70bb1055@mail.gmail.com> 2009/1/6 sturlamolden : > On Jan 6, 3:35 pm, "Dotan Cohen" wrote: >> 2009/1/3 Nomen Nescio : >> >> > python is great. >> >> No, those are anacondas. > > Unless Nomen Nescio is thinking of the giant serpent Python from greek > mythology. > The word "great" means large, as well as "doubleplusgood". So I mentioned something related, but larger. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From jgardner at jonathangardner.net Tue Jan 6 14:03:08 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 11:03:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <614dfad7-8367-479f-bf99-45e11ee1122d@w24g2000prd.googlegroups.com> Message-ID: <19350a8e-4e88-4e1a-a75d-45697698088a@k1g2000prb.googlegroups.com> On Jan 6, 8:13?am, sturlamolden wrote: > On Jan 6, 4:32 pm, mark wrote: > > > > Is it possible to > > switch between the custom DSL and the standard Python interpreter? > > > > - Write the DSL interpreter in Python. > There are Python modules out there that make writing a language interpreter almost trivial, provided you are familiar with tools like Bison and the theories about parsing in general. I suggest PLY, but there are other really good solution out there. If you are familiar enough with parsing and the syntax is simple enough, you can write your own parser. The syntax you describe above is really simple, so using str.split and then calling a function based on the first item is probably enough. From jgardner at jonathangardner.net Tue Jan 6 14:04:27 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 11:04:27 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> Message-ID: <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> On Jan 6, 8:18?am, sturlamolden wrote: > On Jan 6, 4:32 pm, mark wrote: > > > I want to implement a internal DSL in Python. I would like the syntax > > as human readable as possible. > > Also beware that Python is not Lisp. You cannot define new syntax (yes > I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. From rcmn73 at gmail.com Tue Jan 6 14:23:22 2009 From: rcmn73 at gmail.com (rcmn) Date: Tue, 6 Jan 2009 11:23:22 -0800 (PST) Subject: parse/slice/... Message-ID: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> I'm not sure how to call it sorry for the subject description. Here what i'm trying to accomplish. the script i'm working on, take a submitted list (for line in file) and generate thread for it. unfortunately winxp has a limit of 500 thread . So I have to parse/slice the file by chunk of 500 and loop until the list is done. I though i would of done it in no time but i can't get started for some reason. And i can't find a good way to do it efficiently . Does anyone have something similar to this. thank you From vinay_sajip at yahoo.co.uk Tue Jan 6 14:24:54 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jan 2009 11:24:54 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> On Jan 6, 4:17 pm, Kottiyath wrote: > I dont want the whole traceback. I just wanted to know where the log > was generated from i.e. which procedure and which line. I have 3/4 > points in many procedures where I encounter a small error (not an > exception) and want to log it. So having individual names for each > looks to be somewhat verbose - esp since the application is >10K LOC. > Don't the funcName and lineno arguments in the format string work for you? (See http://docs.python.org/library/logging.html#id1) Regards, Vinay Sajip From dickinsm at gmail.com Tue Jan 6 14:29:55 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 6 Jan 2009 11:29:55 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> Message-ID: On Jan 6, 3:23?pm, Fredrik Johansson wrote: > FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- > precision standard transcendental functions in pure Python. It is much > faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, > and handles huge arguments just fine. Yes, I think mpmath was mentioned already somewhere above; it sounds like a perfect tool for the OP's requirements. Note that it's still subject to the same limitations as anything else for trig_function(really huge argument), of course: >>> import mpmath >>> mpmath.cos(mpmath.mpf('1e999999999')) [... still waiting for a result 30 minutes later ...] (not a criticism of mpmath: just a demonstration that this really is pretty much unavoidable). Out of curiosity, what sort of guarantees does mpmath give on error bounds? It looks like it aims for 'almost correctly rounded'; i.e., error < 0.500...001 ulps. Here's one place in mpmath where it looks as though more internal precision is needed (with default settings: 53-bit precision, etc.) >>> mpmath.log(mpmath.mpc(0.6, 0.8)) mpc(real='0.0', imag='0.9272952180016123') Shouldn't the real part here be something like: 2.2204460492503132e-17 instead of 0.0? Mark From skip at pobox.com Tue Jan 6 14:30:25 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 13:30:25 -0600 Subject: parse/slice/... In-Reply-To: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: <18787.45393.134938.550581@montanaro.dyndns.org> rcmn> So I have to parse/slice the file by chunk of 500 and loop until rcmn> the list is done. I though i would of done it in no time but i rcmn> can't get started for some reason. Check the itertools module. Probably itertools.islice. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From rdcollum at gmail.com Tue Jan 6 14:34:46 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 6 Jan 2009 11:34:46 -0800 (PST) Subject: Python subprocess question References: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> Message-ID: <21301d5c-9db8-4126-a728-d7b6adf07e74@s1g2000prg.googlegroups.com> On Jan 6, 1:18?pm, s... at pobox.com wrote: > ? ? Roger> .setDaemon(True) means the thread gets destroyed when the program > ? ? Roger> exits and default .setDaemon(False) means that the thread > ? ? Roger> continues to process even when the main program is gone? > > Approximately. ?The main thread (and thus the program) will exit only when > all non-daemon threads have finished. ?A thread can't continue to run if the > main program has exited. > > -- > Skip Montanaro - s... at pobox.com -http://smontanaro.dyndns.org/ Gotcha. Thank you, that makes it clearer. =) From kay.schluehr at gmx.net Tue Jan 6 14:42:55 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Tue, 6 Jan 2009 11:42:55 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> > How would one approach this in Python? Do I need to build a custom > loader which compiles *.dsl files to *.pyc files? Is it possible to > switch between the custom DSL and the standard Python interpreter? Sure, but there is no way to avoid extending the Python parser and then your DSL becomes external. I remember having had a similar discussion a while ago with Kevin Dangoor the original TurboGears developer who has also written Paver [1]. In the end DSL syntax wasn't worth the hassle and Kevin developed Paver entirely in Python. Kay [1] http://www.blueskyonmars.com/projects/paver/ From andrea.francia at no.spam.invalid Tue Jan 6 14:45:35 2009 From: andrea.francia at no.spam.invalid (Andrea Francia) Date: Tue, 06 Jan 2009 20:45:35 +0100 Subject: Code Review request for the trash-cli project In-Reply-To: References: Message-ID: <4963b4e4$0$17068$6e1ede2f@read.cnntp.org> Dotan Cohen wrote: > 2009/1/6 Andrea Francia > : >> The trash-cli project is a opensource implementation of the FreeDesktop.org > > I don't know about the code, but would there be a reason _not_ to > alias rm, rmdir to this program? Actually the trash-put command accept all the options of GNU rm in order allows user doing alias rm='trash-put', but it does not accept yet some GNU rmdir options (--ignore-fail-on-non-empty, -p, --parents). A enhancement issue about accepting rmdir options was added to the tracker. > I see that it is GPL, so this would > be a great addition to any Linux distro. It's available in some distro but many distro uses a very old version, to gain all the advantages of the latest development version you can use: easy_install trash-cli The easy_install command is provided by the python-setuptools package. From mrmakent at cox.net Tue Jan 6 14:53:03 2009 From: mrmakent at cox.net (Mike Kent) Date: Tue, 6 Jan 2009 11:53:03 -0800 (PST) Subject: Problem building Python 2.5.2 curses module on HP/UX 11.11 Message-ID: I'm having a problem building the Python 2.5.2 curses module on HP/UX 11.11 using gcc 3.3.6, and was hoping someone had a solution. Compiling Modules/_cursesmodule.c is giving several warnings, but no errors. The relevant compile/link output is below. The key output line is: *** WARNING: renaming "_curses" since importing it failed: dynamic module does n ot define init function (init_curses) So, given that there are no actual errors during the compile, and the warnings are probably benign, does anyone know what would cause the resulting compiled module to NOT have the init function? Full build output: building '_curses' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict- prototype s -I. -I/usr/local/src/xyzpython/Python-2.5.2/./Include -I/usr/local/ xyz/python/ include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/ src/xyzpytho n/Python-2.5.2/Include -I/usr/local/src/xyzpython/Python-2.5.2 -c /usr/ local/src /xyzpython/Python-2.5.2/Modules/_cursesmodule.c -o build/temp.hp-ux-B. 11.11-9000 -800-2.5/usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.o In file included from /usr/local/src/xyzpython/Python-2.5.2/Include/ Python.h:8, from /usr/local/src/xyzpython/Python-2.5.2/Modules/ _cursesmodul e.c:102: pyconfig.h:942:1: warning: "_POSIX_C_SOURCE" redefined :6:1: warning: this is the location of the previous definition /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rsesWindow_AddStr': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:449: warning: impl icit declaration of function `getattrs' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_getsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1712: warning: imp licit declaration of function `getsyx' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_setsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2369: warning: imp licit declaration of function `setsyx' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_UnCtrl': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2499: warning: imp licit declaration of function `unctrl' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2499: warning: pas sing arg 1 of `PyString_FromString' makes pointer from integer without a cast /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_getsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1708: warning: `x' might be used uninitialized in this function /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1708: warning: `y' might be used uninitialized in this function /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: At top level: /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2266: warning: `up date_lines_cols' defined but not used ld -b build/temp.hp-ux-B.11.11-9000-800-2.5/usr/local/src/xyzpython/ Python-2.5.2 /Modules/_cursesmodule.o -L/usr/local/xyz/python/lib -L/usr/local/lib - lncurses -o build/lib.hp-ux-B.11.11-9000-800-2.5/_curses.sl *** WARNING: renaming "_curses" since importing it failed: dynamic module does n ot define init function (init_curses) From mal at egenix.com Tue Jan 6 15:02:36 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 21:02:36 +0100 Subject: python is great In-Reply-To: <496396AF.5020809@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: <4963B8DC.1020508@egenix.com> On 2009-01-06 18:36, Joe Strout wrote: > I've actually been rather frustrated by Python lately. It's great at > some things, but rather poor at others. In the latter category is > building a neatly packaged executable that can be shipped to users and > run reliably on their machine. On the Mac in particular, if you want > your app to run on any PowerPC or Intel machine runing 10.4 or later, > and you're using anything not in the standard framework (such as > MySQLdb), it's a bit of a nightmare. > > Compare this to, say, REALbasic, where you just check "Mac OS X > Universal" in the Build Settings, click Build, and you're done. (RB has > its own issues, of course.) You're looking for py2app: http://undefined.org/python/py2app.html (creating a button that invokes it is left as exercise to the interested reader :-) > So I would say that Python as a language is great, and its standard > framework is great. But its (many) IDEs are pretty poor, and the > process of building a polished, packaged app is abysmal. It's certainly work, but that's always the case for nicely polished apps :-) For packaging, you can choose from a multitude of installer builders - none of which are really Python specific. We tend to use InnoSetup on Windows, the Mac OS installer for Mac OS X and an installer shell script for Unix. More recently we've found InstallJammer which looks very promising, esp. when building applications for multiple platforms. > And there are > some things (such as Flash-style web applets) that you still can't do at > all in Python, even after all these years. You're looking for Silverlight: http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > But of course, the nice thing about an open-source environment is that, > with enough motivation, time, and expertise, one can fix the most > annoying limitations oneself. And if I stick with Python over the > upcoming years, I'll certainly do my part. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From james at agentultra.com Tue Jan 6 15:04:04 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:04:04 -0500 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: <858wporykr.fsf@dozer.localdomain> "Gabriel Genellina" writes: > En Mon, 05 Jan 2009 02:03:26 -0200, Roy Smith escribi?: > > >> The other day, I came upon this gem. It's a bit of perl embedded in a >> Makefile; this makes it even more gnarly because all the $'s get >> doubled to >> hide them from make: >> >> define absmondir >> $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? ? ? ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? >> ? ? ? ? ? ? ? ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print >> \\\$$1}"`; >> chomp($$prefix); \ >> ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ >> ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ >> ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! >> ); } \ >> ?? return unslash(undot(undotdot($$a))); }; \ >> sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; >> return($$_[0]); >> }; \ >> sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ >> sub undotdot ($$) { my $$in = $$_[0]; \ >> ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ >> print absmon("$(1)","$(2)"); \ >> ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? endef >> >> Barf-o-rama. I know what it's supposed to do, and I still can't >> figure it out. > > Ouch! Me too, when I come to some piece of Perl code I've written some > years ago, I invariably think "what's all this noise?". Never happens > with other languages I've used in the past. I still occassion upon the chance to write some Perl, and even as a full-time developer who works with Python for a living, I relish every opportunity. The funny thing is that I've never had the problem of writing code like this in Perl. The example is a very poor use-case and doesn't reflect on the useful/useless-ness of the language itself but more on the choices of the implementor. Perl is a very useful language overall and when used properly, very powerful. From marduk at letterboxes.org Tue Jan 6 15:05:46 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 06 Jan 2009 15:05:46 -0500 Subject: parse/slice/... In-Reply-To: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: <1231272346.3312.7.camel@localhost.localdomain> On Tue, 2009-01-06 at 11:23 -0800, rcmn wrote: > I'm not sure how to call it sorry for the subject description. > Here what i'm trying to accomplish. > the script i'm working on, take a submitted list (for line in file) > and generate thread for it. unfortunately winxp has a limit of 500 > thread . So I have to parse/slice the file by chunk of 500 and loop > until the list is done. > I though i would of done it in no time but i can't get started for > some reason. > And i can't find a good way to do it efficiently . Does anyone have > something similar to this. If your thread is smart enough to handle the file you can do something like: class Worker(threading.Thread): def __init__(self, file_object): self.file_object = file_object threading.Thread.__init__(self) def run(self): while True: line = self.file_object.readline() if line == '': return # process line NUM_WORKERS = 500 bigfile = open('somefile', 'r') workers = [Worker(bigfile) for i in range(NUM_WORKERS)] for worker in workers: worker.start() From dotancohen at gmail.com Tue Jan 6 15:05:59 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 22:05:59 +0200 Subject: image recogniton? In-Reply-To: <18787.32403.82637.308936@montanaro.dyndns.org> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> <18787.32403.82637.308936@montanaro.dyndns.org> Message-ID: <880dece00901061205x1a84c1d6yda49e7244ee38306@mail.gmail.com> This was just mentioned on the KDE bugtracker: http://opencv.willowgarage.com/wiki/FaceDetection -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From radix at twistedmatrix.com Tue Jan 6 15:07:34 2009 From: radix at twistedmatrix.com (Christopher Armstrong) Date: Tue, 6 Jan 2009 15:07:34 -0500 Subject: ANN: Twisted 8.2 released Message-ID: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> Version 8.2 of Twisted is now out (actually, it's been out for over a week now!). You can download it (in Windows, Mac, and source forms) at: http://twistedmatrix.com/ Twisted 8.2 is a major feature release, also including many important bug fixes: * twistd now has a --umask option for specifying the umask * Log observers can now be configured in .tac files * ProcessProtocols can now implement processExited to get reliable notification of a process exiting * FTPClient has many more convenience methods * Twisted.words now has a standalone XMPP router * Twisted.names now supports NAPTR records * Twisted.web can now deal with multi-value headers and supports the Range header in requests for static files There have been many additional improvements which you can read all about in the release notes: http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/NEWS?format=raw What is Twisted? From the web site: Twisted is an event-driven networking engine written in Python and licensed under the MIT license. Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH, IRC, FTP, and others), and much more. See more at: http://twistedmatrix.com/ -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/ http://canonical.com/ From mal at egenix.com Tue Jan 6 15:11:40 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 21:11:40 +0100 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> References: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> Message-ID: <4963BAFC.1040209@egenix.com> On 2009-01-06 20:42, Kay Schluehr wrote: >> How would one approach this in Python? Do I need to build a custom >> loader which compiles *.dsl files to *.pyc files? Is it possible to >> switch between the custom DSL and the standard Python interpreter? > Sure, but there is no way to avoid extending the Python parser and > then your DSL becomes external. Try python4ply: http://dalkescientific.com/Python/python4ply.html ...much easier to work with than extending the Python parser by hand. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From rt8396 at gmail.com Tue Jan 6 15:13:56 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 12:13:56 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> Message-ID: On Jan 6, 11:36?am, Joe Strout wrote: > I've actually been rather frustrated by Python lately. ?It's great at > some things, but rather poor at others. ?In the latter category is > building a neatly packaged executable that can be shipped to users and > run reliably on their machine. ?On the Mac in particular, if you want > your app to run on any PowerPC or Intel machine runing 10.4 or later, > and you're using anything not in the standard framework (such as > MySQLdb), it's a bit of a nightmare. > > Compare this to, say, REALbasic, where you just check "Mac OS X > Universal" in the Build Settings, click Build, and you're done. ?(RB has > its own issues, of course.) > > So I would say that Python as a language is great, and its standard > framework is great. ?But its (many) IDEs are pretty poor, and the > process of building a polished, packaged app is abysmal. ?And there are > some things (such as Flash-style web applets) that you still can't do at > all in Python, even after all these years. > > But of course, the nice thing about an open-source environment is that, > with enough motivation, time, and expertise, one can fix the most > annoying limitations oneself. ?And if I stick with Python over the > upcoming years, I'll certainly do my part. > > Best, > - Joe Joe, At post.readlines()[:1] i was quite angry, but from [2:] i started agreeing very much with you. I very much love the python programming language(and everyone here knows that) but app packaging is dismal in python. And many improvements need to be made to IDLE. You make some very good points and hopefully i will be able to give my time shortly to help fix some of these deficiencies. PS: Whoever rated the OP with one star needs to hang out somewhere else! From james at agentultra.com Tue Jan 6 15:14:05 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:14:05 -0500 Subject: image recogniton? References: Message-ID: <854p0cry42.fsf@dozer.localdomain> Li Han writes: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han I do work in object recognition, and I would classify this as a rather difficult problem. Not impossible of course, but you'll need some OCR to read the clock face and some sort of magnitude vector feature to tell which hand is which and the "general direction" is is pointing in. Also, depends if we're talking digital clocks or analog. :) The other problem is one of accuracy: depending on your input image, even slight variances can change your results. I'm curious as to what application the solution to this problem is practical for all of its difficulty? From joe at strout.net Tue Jan 6 15:24:40 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 13:24:40 -0700 Subject: python is great In-Reply-To: <4963B8DC.1020508@egenix.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> Message-ID: <4963BE08.5070006@strout.net> M.-A. Lemburg wrote: >> On the Mac in particular, if you want >> your app to run on any PowerPC or Intel machine runing 10.4 or later, >> and you're using anything not in the standard framework (such as >> MySQLdb), it's a bit of a nightmare. >> > > You're looking for py2app: > > http://undefined.org/python/py2app.html No, I'm *using* py2app. I've been trying to use it for a couple of weeks now, with the generous help of such people as Robin Dunn, and I still don't have it quite working properly. (I'd be happy to send you my notes on what was required to get as far as I've gotten, but it's several pages, a bit long to post here.) (py2exe works a little more easily, thank goodness.) >> So I would say that Python as a language is great, and its standard >> framework is great. But its (many) IDEs are pretty poor, and the >> process of building a polished, packaged app is abysmal. > > It's certainly work, but that's always the case for nicely polished > apps :-) In Python, yes. :) Not in all environments. > For packaging, you can choose from a multitude of installer builders - > none of which are really Python specific. I'm not even talking about that level of packaging -- I'm just talking about making something that appears to the user like a normal executable, which they can double-click on their system and have it actually run, rather than aborting with something unhelpful like "No module named MySQLdb". >> And there are >> some things (such as Flash-style web applets) that you still can't do at >> all in Python, even after all these years. > > You're looking for Silverlight: > http://www.voidspace.org.uk/ironpython/silverlight/index.shtml Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit that this does mostly fit the bill I described above (or has the potential to, anyway). Thanks, - Joe From james at agentultra.com Tue Jan 6 15:24:43 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:24:43 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> Message-ID: <85zli4qj1w.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 6, 8:18?am, sturlamolden wrote: >> On Jan 6, 4:32 pm, mark wrote: >> >> > I want to implement a internal DSL in Python. I would like the syntax >> > as human readable as possible. >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >> I've seen the goto joke). > > This isn't really true. You can, for instance, write a program (in > Python) that takes your pseudo-Python and converts it into Python. > This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. From akineko at gmail.com Tue Jan 6 15:34:48 2009 From: akineko at gmail.com (akineko) Date: Tue, 6 Jan 2009 12:34:48 -0800 (PST) Subject: subclassing 'list' Message-ID: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Hello everyone, I'm creating a class which is subclassed from list (Bulit-in type). It works great. However, I'm having a hard time finding a way to set a new value to the object (within the class). There are methods that alter a part of the object (ex. __setitem__()). But I couldn't find any method that can replace the value of the object. I wanted to do something like the following: class Mylist(list): def arrange(self): new_value = .... list.self.__assign__.(self, new_value) I serached the newsgroup and found that assignment operator ('=') cannot be overridden because it is not an operator. But it shouldn't stop Python to provide a way to re-assign the value internally. Any suggestions will be highly appreciated. Best regards, Aki- From benjamin.kaplan at case.edu Tue Jan 6 15:36:44 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 6 Jan 2009 15:36:44 -0500 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: On Tue, Jan 6, 2009 at 3:24 PM, Joe Strout wrote: > M.-A. Lemburg wrote: > > On the Mac in particular, if you want >>> your app to run on any PowerPC or Intel machine runing 10.4 or later, >>> and you're using anything not in the standard framework (such as >>> MySQLdb), it's a bit of a nightmare. >>> >>> >> You're looking for py2app: >> >> http://undefined.org/python/py2app.html >> > > No, I'm *using* py2app. I've been trying to use it for a couple of weeks > now, with the generous help of such people as Robin Dunn, and I still don't > have it quite working properly. (I'd be happy to send you my notes on what > was required to get as far as I've gotten, but it's several pages, a bit > long to post here.) > > (py2exe works a little more easily, thank goodness.) > > So I would say that Python as a language is great, and its standard >>> framework is great. But its (many) IDEs are pretty poor, and the >>> process of building a polished, packaged app is abysmal. >>> >> >> It's certainly work, but that's always the case for nicely polished >> apps :-) >> > > In Python, yes. :) Not in all environments. > > For packaging, you can choose from a multitude of installer builders - >> none of which are really Python specific. >> > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal executable, > which they can double-click on their system and have it actually run, rather > than aborting with something unhelpful like "No module named MySQLdb". > > And there are >>> some things (such as Flash-style web applets) that you still can't do at >>> all in Python, even after all these years. >>> >> >> You're looking for Silverlight: >> http://www.voidspace.org.uk/ironpython/silverlight/index.shtml >> > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit that > this does mostly fit the bill I described above (or has the potential to, > anyway). If your only problem with Silverlight is Microsoft, there is an open source .NET implementation called Mono (www.mono-project.com) and an open source Silverlight plugin, Moonlight (http://www.go-mono.com/moonlight/). > > > Thanks, > - Joe > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 6 15:43:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 12:43:57 -0800 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <50697b2c0901061243o1b88e249w2eb3da51140db548@mail.gmail.com> On Tue, Jan 6, 2009 at 12:34 PM, akineko wrote: > > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) If you mean you want to replace the contents of the list with that of another list, just do: def arrange(self): self.clear() #empty the list self.extend(new_list) #append the contents of other list If you instead mean that you want the object to somehow completely "become" or be replaced by another object, that's not possible (short of proxying). Smalltalk has a `become` method, but not Python (it's pretty deep black magic anyway). If you gave more info about _why_ you want to do that, someone could probably suggest an alternative. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jstroud at mbi.ucla.edu Tue Jan 6 15:45:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 12:45:53 -0800 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) > > I serached the newsgroup and found that assignment operator ('=') > cannot be overridden because it is not an operator. But it shouldn't > stop Python to provide a way to re-assign the value internally. > > Any suggestions will be highly appreciated. > > Best regards, > Aki- Slice assignment will behave as you like: py> class Mylist(list): ... def arrange(self): ... new_value = [1, 2, 3] ... self[:] = new_value ... py> m = Mylist() py> m.arrange() py> m [1, 2, 3] Your other option is to arrange the list in-place, depending on what it means to arrange the list. You may want to provide a more explicit example. From dotancohen at gmail.com Tue Jan 6 16:05:58 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 23:05:58 +0200 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: <880dece00901061305l69806a14l6e79673c05bc4518@mail.gmail.com> 2009/1/6 Joe Strout : > No, I'm *using* py2app. I've been trying to use it for a couple of weeks > now, with the generous help of such people as Robin Dunn, and I still don't > have it quite working properly. (I'd be happy to send you my notes on what > was required to get as far as I've gotten, but it's several pages, a bit > long to post here.) > If you want to save me the trouble, then I'd like to see those notes. If you want, I can host the notes at dotancohen.com to that they will be publicaly accessible. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From jcd at sdf.lonestar.org Tue Jan 6 16:09:13 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 06 Jan 2009 16:09:13 -0500 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <1231276153.16001.12.camel@aalcdl07.lib.unc.edu> On Tue, 2009-01-06 at 12:34 -0800, akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) > > I serached the newsgroup and found that assignment operator ('=') > cannot be overridden because it is not an operator. But it shouldn't > stop Python to provide a way to re-assign the value internally. Aki, I'm not sure I understand your problem. What I see above is an attribute error: AttributeError: type object 'list' has no attribute 'self' coming from your use of list.self, but it doesn't sound like that's what you are asking about. Do you mean that you want to be able to specify some sort of processing to be done when you assign to an attribute of your object? To do that, you need to use properties: import math class Circle(object): def __init__(self, radius=1.0): self._radius = radius self.circum = 2.0 * self._radius * math.pi def __get_radius(self): return self._radius def __set_radius(self,radius): self._radius = radius self.circum = 2.0 * self._radius * math.pi radius = property(__get_radius, __set_radius) Then you can do: >>> circ = Circle(2.0) >>> print circ.radius 2.0 >>> print circ.circum 12.5663706144 >>> circ.radius = 4.5 >>> print circ.radius 4.5 >>> print circ.circum 28.2743338823 There are lots of good tutorials on this online. From mal at egenix.com Tue Jan 6 16:09:52 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 22:09:52 +0100 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: <4963C8A0.8090606@egenix.com> On 2009-01-06 21:24, Joe Strout wrote: > M.-A. Lemburg wrote: > >>> On the Mac in particular, if you want >>> your app to run on any PowerPC or Intel machine runing 10.4 or later, >>> and you're using anything not in the standard framework (such as >>> MySQLdb), it's a bit of a nightmare. >>> >> >> You're looking for py2app: >> >> http://undefined.org/python/py2app.html > > No, I'm *using* py2app. I've been trying to use it for a couple of > weeks now, with the generous help of such people as Robin Dunn, and I > still don't have it quite working properly. (I'd be happy to send you > my notes on what was required to get as far as I've gotten, but it's > several pages, a bit long to post here.) Perhaps not post it here, but put it up on the web somewhere and link to it from the Python.org wiki. > (py2exe works a little more easily, thank goodness.) We're using py2exe to wrap up apps on Windows and then pass them on to InnoSetup for creating the installer. On Unix, we tried using cx_Freeze, but that had too many issues. We've then modified and updated an old project of mine, called mxCGIPython, to create a one file Python interpreter and use that with the applications: http://www.egenix.com/www2002/python/mxCGIPython.html One of these days, we're going to release the new version as OSS. >>> So I would say that Python as a language is great, and its standard >>> framework is great. But its (many) IDEs are pretty poor, and the >>> process of building a polished, packaged app is abysmal. >> >> It's certainly work, but that's always the case for nicely polished >> apps :-) > > In Python, yes. :) Not in all environments. Hmm, I'm not only referring to nice looking GUIs. Those are only part of the game. More important is well working application, without any annoying bugs. >> For packaging, you can choose from a multitude of installer builders - >> none of which are really Python specific. > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal > executable, which they can double-click on their system and have it > actually run, rather than aborting with something unhelpful like "No > module named MySQLdb". That's part of polishing the application, IMHO. For point-and-click apps, you need to include all the required dependencies together with the application. >>> And there are >>> some things (such as Flash-style web applets) that you still can't do at >>> all in Python, even after all these years. >> >> You're looking for Silverlight: >> http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit > that this does mostly fit the bill I described above (or has the > potential to, anyway). Ok, how about a Firefox Extension, then... http://pyxpcomext.mozdev.org/ together with a shell: http://pyxpcomext.mozdev.org/samples.html#pyshell With this plugin you write the GUI using XUL and JavaScript... and after some polishing, which includes dropping the Firefox GUI and turning to XULRunner, you can create apps such as Miro: http://www.getmiro.com/ and watch TED videos driven by Python (and a gazillion other tools working for you behind the scenes). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From akineko at gmail.com Tue Jan 6 16:11:00 2009 From: akineko at gmail.com (akineko) Date: Tue, 6 Jan 2009 13:11:00 -0800 (PST) Subject: subclassing 'list' References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <8ece7e06-70fc-4e12-b78d-ec20dc3fb06c@n33g2000pri.googlegroups.com> Hello Chris and James, Thank you for you guys' prompt response. Yes, that is what I wanted to do. I, somehow, didn't think of using those list methods. Instead, I was looking for a single method to override. Big Thanks! Aki- On Jan 6, 12:43 pm, "Chris Rebert" wrote: > If you mean you want to replace the contents of the list with that of > another list, just do: > > def arrange(self): > self.clear() #empty the list > self.extend(new_list) #append the contents of other list On Jan 6, 12:45 pm, James Stroud wrote: > Slice assignment will behave as you like: > > py> class Mylist(list): > ... def arrange(self): > ... new_value = [1, 2, 3] > ... self[:] = new_value > ... From nospam at nospam.com Tue Jan 6 16:13:38 2009 From: nospam at nospam.com (Gilles Ganault) Date: Tue, 06 Jan 2009 22:13:38 +0100 Subject: [http] Example with proxy + post + cookie? Message-ID: Hello I need to write a script that goes out through a proxy, connects with a POST query, and receives a cookie for a Session ID. I didn't find an example on the Net that did it all three, but only some of the features. Does someone have one handy by any chance? Thank you. From nospam at nospam.com Tue Jan 6 16:16:35 2009 From: nospam at nospam.com (Gilles Ganault) Date: Tue, 06 Jan 2009 22:16:35 +0100 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: On Mon, 05 Jan 2009 17:54:19 -0500, Terry Reedy wrote: >> for email in rows: >> To = email Thanks guys. Turns out email is a tuple, so here's how to extract the columns: for email in rows: email=email[0] From steve at holdenweb.com Tue Jan 6 16:19:00 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 06 Jan 2009 16:19:00 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <85zli4qj1w.fsf@dozer.localdomain> References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> Message-ID: J Kenneth King wrote: [...] > I could go on a really long rant about how the two are worlds apart, but > I'll let Google tell you if you're really interested. a) How is Google going to know if he's really interested? b) Put a space after the "--" in your sig, please; that way my mailer won't yto to quote your signature as part of the message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From philip at semanchuk.com Tue Jan 6 16:21:07 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 6 Jan 2009 16:21:07 -0500 Subject: pep-8 vs. external interfaces? In-Reply-To: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> Message-ID: <01F63503-9BCE-49BF-88D1-5FFC0DC113A9@semanchuk.com> On Jan 4, 2009, at 2:47 PM, Roy Smith wrote: > I'm building a Python language wrapper to an network protocol which > traditionally uses camelCase function names. I'm trying to make the > new code pep-8 compliant, which means function names should be written > this_way() instead of thisWay(). I've got a couple of choices open to > me. > > I could convert all the protocol names to pep-8 style mechanically. > This is not as much work as it seems; the lowest-level Python code is > already machine generated from a tabular description of the protocol. > It's about one more line of code to convert getLibraries() to > get_libraries(). This will leave the result the cleanest from the > Python point of view. It'll also make the Python binding look a > little different from the C++, Java, Perl, etc, bindings. +1 for PEP 8 compliance. Programmers unfamiliar with the existing protocol will appreciate its Pythonic feel instead of wondering why the names are all "wrong". Those familiar with the existing protocol will have to make a mental adjustment, but at least they'll be adjusting to a target (standard Python style) that they presumably know. > I figure either way, somebody's going to complain that I did it > wrong :-) I promise to be the first to complain no matter what you choose. ;) Good luck Philip From kyosohma at gmail.com Tue Jan 6 16:24:10 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 6 Jan 2009 13:24:10 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> Message-ID: <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> On Jan 6, 2:24?pm, Joe Strout wrote: > M.-A. Lemburg wrote: > >> On the Mac in particular, if you want > >> your app to run on any PowerPC or Intel machine runing 10.4 or later, > >> and you're using anything not in the standard framework (such as > >> MySQLdb), it's a bit of a nightmare. > > > You're looking for py2app: > > >http://undefined.org/python/py2app.html > > No, I'm *using* py2app. ?I've been trying to use it for a couple of > weeks now, with the generous help of such people as Robin Dunn, and I > still don't have it quite working properly. ?(I'd be happy to send you > my notes on what was required to get as far as I've gotten, but it's > several pages, a bit long to post here.) > > (py2exe works a little more easily, thank goodness.) > > >> So I would say that Python as a language is great, and its standard > >> framework is great. ?But its (many) IDEs are pretty poor, and the > >> process of building a polished, packaged app is abysmal. > > > It's certainly work, but that's always the case for nicely polished > > apps :-) > > In Python, yes. ?:) ?Not in all environments. > > > For packaging, you can choose from a multitude of installer builders - > > none of which are really Python specific. > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal > executable, which they can double-click on their system and have it > actually run, rather than aborting with something unhelpful like "No > module named MySQLdb". > > >> And there are > >> some things (such as Flash-style web applets) that you still can't do at > >> all in Python, even after all these years. > > > You're looking for Silverlight: > >http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > Maybe. ?I'm not a big fan of anything so Microsoftian, but I'll admit > that this does mostly fit the bill I described above (or has the > potential to, anyway). > > Thanks, > - Joe I use Andrea Gavana's GUI2Exe to create my binaries. He recently added a py2app wrapper to it. I don't have a Mac, so I haven't tested that part of his app. However, the py2exe portion rocks! I put in the path to my main Python executable, add any special 3rd party modules and it just works! I've written a tutorial for the py2exe part of it if you're interested... Mike From lasizoillo at gmail.com Tue Jan 6 16:26:23 2009 From: lasizoillo at gmail.com (lasizoillo) Date: Tue, 6 Jan 2009 22:26:23 +0100 Subject: [Twisted-web] ANN: Twisted 8.2 released In-Reply-To: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> References: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> Message-ID: <49414f570901061326v1d500b35ob95c603ca7d4449f@mail.gmail.com> 2009/1/6 Christopher Armstrong : > Version 8.2 of Twisted is now out (actually, it's been out for over a > week now!). You can download it (in Windows, Mac, and source forms) > at: > > http://twistedmatrix.com/ This year is for 9.x version, isn't? A query to cheese shop returns 8.1 Version: http://pypi.python.org/pypi?%3Aaction=search&term=twisted&submit=search :-( Thanks a lot for all twisted contributors > > Twisted 8.2 is a major feature release, also including many important bug fixes: > > * twistd now has a --umask option for specifying the umask > * Log observers can now be configured in .tac files > * ProcessProtocols can now implement processExited to get reliable > notification of a process exiting > * FTPClient has many more convenience methods > * Twisted.words now has a standalone XMPP router > * Twisted.names now supports NAPTR records > * Twisted.web can now deal with multi-value headers and supports the > Range header in requests for static files > > There have been many additional improvements which you can read all > about in the release notes: > > http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/NEWS?format=raw > > > What is Twisted? From the web site: > > Twisted is an event-driven networking engine written in Python and > licensed under the MIT license. > > Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix > sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH, > IRC, FTP, and others), and much more. See more at: > > http://twistedmatrix.com/ > > > -- > Christopher Armstrong > http://radix.twistedmatrix.com/ > http://planet-if.com/ > http://canonical.com/ > > _______________________________________________ > Twisted-web mailing list > Twisted-web at twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web > From aleksandr.goretoy at gmail.com Tue Jan 6 16:28:11 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 21:28:11 +0000 Subject: python is great In-Reply-To: <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> Message-ID: > > I use Andrea Gavana's GUI2Exe to create my binaries. He recently added > a py2app wrapper to it. I don't have a Mac, so I haven't tested that > part of his app. However, the py2exe portion rocks! I put in the path > to my main Python executable, add any special 3rd party modules and it > just works! I've written a tutorial for the py2exe part of it if > you're interested... > Can you post the link to this tutorial? If you want to save me the trouble, then I'd like to see those notes. > If you want, I can host the notes at dotancohen.com to that they will > be publicaly accessible. > Any more news on this research? -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 9:24 PM, Mike Driscoll wrote: > On Jan 6, 2:24 pm, Joe Strout wrote: > > M.-A. Lemburg wrote: > > >> On the Mac in particular, if you want > > >> your app to run on any PowerPC or Intel machine runing 10.4 or later, > > >> and you're using anything not in the standard framework (such as > > >> MySQLdb), it's a bit of a nightmare. > > > > > You're looking for py2app: > > > > >http://undefined.org/python/py2app.html > > > > No, I'm *using* py2app. I've been trying to use it for a couple of > > weeks now, with the generous help of such people as Robin Dunn, and I > > still don't have it quite working properly. (I'd be happy to send you > > my notes on what was required to get as far as I've gotten, but it's > > several pages, a bit long to post here.) > > > > (py2exe works a little more easily, thank goodness.) > > > > >> So I would say that Python as a language is great, and its standard > > >> framework is great. But its (many) IDEs are pretty poor, and the > > >> process of building a polished, packaged app is abysmal. > > > > > It's certainly work, but that's always the case for nicely polished > > > apps :-) > > > > In Python, yes. :) Not in all environments. > > > > > For packaging, you can choose from a multitude of installer builders - > > > none of which are really Python specific. > > > > I'm not even talking about that level of packaging -- I'm just talking > > about making something that appears to the user like a normal > > executable, which they can double-click on their system and have it > > actually run, rather than aborting with something unhelpful like "No > > module named MySQLdb". > > > > >> And there are > > >> some things (such as Flash-style web applets) that you still can't do > at > > >> all in Python, even after all these years. > > > > > You're looking for Silverlight: > > >http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit > > that this does mostly fit the bill I described above (or has the > > potential to, anyway). > > > > Thanks, > > - Joe > > I use Andrea Gavana's GUI2Exe to create my binaries. He recently added > a py2app wrapper to it. I don't have a Mac, so I haven't tested that > part of his app. However, the py2exe portion rocks! I put in the path > to my main Python executable, add any special 3rd party modules and it > just works! I've written a tutorial for the py2exe part of it if > you're interested... > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From David Tue Jan 6 16:34:03 2009 From: David (David) Date: Tue, 06 Jan 2009 15:34:03 -0600 Subject: How to get millisec/fractional seconds out of a time object ? Message-ID: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Thanks for help to a beginner. script23 import time import datetime start_time = datetime.datetime.now() time.sleep(0.14) end_time = datetime.datetime.now() datetime.timedelta = end_time - start_time print(datetime.timedelta) # works, prints 0:00:0.141000 print(datetime.timedelta.seconds) # prints 0 print(datetime.timedelta.milliseconds) # fails < object has no attribute milliseconds > How do I get the 0.141000 out of that or any time object ? On line docs are arcane to a novice. From castironpi at gmail.com Tue Jan 6 16:43:01 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 6 Jan 2009 13:43:01 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> On Jan 6, 8:03?am, Mark Wooding wrote: > Steven D'Aprano wrote: snip > > It seems that you don't include in the Python community all those who > > use the term "name binding" instead of variable assignment > > specifically because it gives new users a clue that Python is not the > > same as C. > > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. > > Let me explain. ?I'll try to be clear, though I know that Stephen > already understands this stuff well. > > At run-time, each named variable denotes a storage area (I'll call it a > slot[2]) which holds a reference to some object[1]. > > ? ? ? ? ? ? ? +-----+ > ? ?name ----> | ref -----> object ? > ? ? ? ? ? ? ? +-----+ > > If we `assign' a different object to the variable, what really happens > is that the slot is modified to refer to the other object; but the name > continues to denote the same slot. > > Usually `binding', or `rebinding', a name describes a different process, > whereby the name (for a while) denotes a different slot. ?This name-to- > slot mapping is important because it's the mapping which is inherited by > nested functions. Say you start with: +------+ a ----> | ref1 -----> (1, 2, 3) +------+ Then you can do: +------+ a ----> | ref2 -----> (4, 5, 6) +------+ But not: +------+ a ----> | ref1 -----> (4, 5, 6) +------+ That is, you can 'repoint a' to another 'ref', but not repoint a 'ref'. I think one of the ideas we have trouble communicating is that [1, 2, 3] and [4, 5, 6] can be the same object (using '[:]='), but [1, 2, 3] and [1, 2, 3] don't have to be. From Scott.Daniels at Acm.Org Tue Jan 6 16:44:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 06 Jan 2009 13:44:31 -0800 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <9rOdnbo7LoQaTf7UnZ2dnUVZ_sTinZ2d@pdx.net> David Lemper wrote: > Thanks for help to a beginner. > > script23 > ... > datetime.timedelta = end_time - start_time This is a bad idea. You are changing the globals of another module. You are lucky you didn't break anything. Better would be: elapsed = end_time - start_time then use things like: print elapsed print elapsed.seconds >... How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. Try this: print dir(elapsed) The answer should become obvious. --Scott David Daniels Scott.Daniels at Acm.Org From clp2 at rebertia.com Tue Jan 6 16:46:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 13:46:46 -0800 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <50697b2c0901061346q2a6b43d5i246fe2380280c04b@mail.gmail.com> On Tue, Jan 6, 2009 at 1:34 PM, wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. Not all that arcane. >From http://docs.python.org/library/datetime.html : """ timedelta Objects A timedelta object represents a duration, the difference between two dates or times. [...] Attribute Value days Between -999999999 and 999999999 inclusive seconds Between 0 and 86399 inclusive microseconds Between 0 and 999999 inclusive """ The attribute you're looking for is 'microseconds', not 'milliseconds'. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From fredrik.johansson at gmail.com Tue Jan 6 16:48:54 2009 From: fredrik.johansson at gmail.com (Fredrik Johansson) Date: Tue, 6 Jan 2009 13:48:54 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> Message-ID: <88f22492-0d01-48a1-9db7-d2de7cbe450f@k36g2000pri.googlegroups.com> On Jan 6, 8:29 pm, Mark Dickinson wrote: > Note that it's still subject to the same limitations as anything > else for trig_function(really huge argument), of course: > > >>> import mpmath > >>> mpmath.cos(mpmath.mpf('1e999999999')) > > [... still waiting for a result 30 minutes later ...] > > (not a criticism of mpmath: just a demonstration that this > really is pretty much unavoidable). Indeed. That's asking for 1 billion digits of pi. (I feel that I need to point out that mpmath really does go out of its way to make ridiculous things like that work, though. It uses a very fast algorithm to compute pi, faster than MPFR even. Assuming gmpy is installed on the system and enough RAM, cos('1e999999999') should finish in about 10^5 seconds = 1 day (based on extrapolation on my computer). You just weren't patient enough :-) > Out of curiosity, what sort of guarantees does mpmath give on > error bounds? It looks like it aims for 'almost correctly > rounded'; i.e., error < 0.500...001 ulps. Sort of; there are different standards of rigor. The basic arithmetic operations are correctly rounded. The elementary functions are 'almost correctly rounded' in the sense you described (subject to the usual bug disclaimer); they are also correctly rounded around some zeros and poles (e.g. sin(x) for sufficiently small x properly rounds to x or x* (1-eps) if upward/downward rounding is used). Some other functions like erf and gamma are 'almost correctly rounded' for real arguments, but currently no attempt is made to correct for cancellations in real/imaginary parts (this problem is mostly avoided for elementary functions by decomposition into real-valued functions like cos(a+b*i) = cos(a)*cosh(b)-sin(a)*sinh(b)*i). Finally, some "higher" functions are computed more naively and can easily be forced to lose accuracy by finding large arguments that correspond to small function values. It would indeed be nice to support correct rounding for at least the elementary transcendental functions in the future. One advantage of arbitrary precision is that the user can compensate for rounding errors very easily by just increasing the working precision, but ideally that shouldn't be necessary for atomic operations. > Here's one place in mpmath where it looks as though more > internal precision is needed (with default settings: 53-bit > precision, etc.) > > >>> mpmath.log(mpmath.mpc(0.6, 0.8)) > > mpc(real='0.0', imag='0.9272952180016123') > > Shouldn't the real part here be something like: > > 2.2204460492503132e-17 > > instead of 0.0? That's certainly a bug; it should be fixed soon. Fredrik From lists at js3d.co.uk Tue Jan 6 16:48:59 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 21:48:59 -0000 Subject: read pipe information on a running (popen) process Message-ID: <004c01c97048$956ffb30$c04ff190$@co.uk> Hi, I'm really struggling with how to read the stdout on a running process. All the examples I've seen tend to rely on waiting for the process to finish. The process I'm running takes a while and I need to get stdout [and stderr] and be able to pipe them into a string for displaying in a web app. My shoddy code is currently this: p = subprocess.Popen('xsibatch.exe -s', bufsize=200, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while p.returncode==None: p.poll() print p.stdout.readline(), p.stderr.readline(), time.sleep(1) print 'finished' Which results in it printing (i think) the last line written to the pipe file. I'm thinking there must be a simpler way to access this information. Ideally I'd like to dump the whole lot to a string at periodic intervals but am completely stumped as to how to do this as readlines() and many other methods require an EOF. On a side note [and much lesser problem currently], I was under the impression that p.poll() writes the returncode attribute, but from what I can see when the process terminates p.poll() still returns none? Many thanks, Jules From google at mrabarnett.plus.com Tue Jan 6 16:49:58 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jan 2009 21:49:58 +0000 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <4963D206.2040403@mrabarnett.plus.com> David at bag.python.org wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time You've just overwritten the timedelta class in the datetime module! Do something like this instead: elapsed_time = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > print (elapsed_time.microseconds / 1.0E6) > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. > From lists at js3d.co.uk Tue Jan 6 17:00:50 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 22:00:50 -0000 Subject: read pipe information on a running (popen) process In-Reply-To: <004c01c97048$956ffb30$c04ff190$@co.uk> References: <004c01c97048$956ffb30$c04ff190$@co.uk> Message-ID: <005401c9704a$3dc85600$b9590200$@co.uk> > Which results in it printing (i think) the last line written to the > pipe > file. I'm thinking there must be a simpler way to access this > information. > Ideally I'd like to dump the whole lot to a string at periodic > intervals but > am completely stumped as to how to do this as readlines() and many > other > methods require an EOF. FWIW google found this, which looks very promising: http://code.activestate.com/recipes/440554/ From thorsten at thorstenkampe.de Tue Jan 6 17:19:51 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 6 Jan 2009 23:19:51 +0100 Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: * Vinay Sajip (Tue, 6 Jan 2009 11:24:54 -0800 (PST)) > On Jan 6, 4:17 pm, Kottiyath wrote: > > I dont want the whole traceback. I just wanted to know where the log > > was generated from i.e. which procedure and which line. I have 3/4 > > points in many procedures where I encounter a small error (not an > > exception) and want to log it. So having individual names for each > > looks to be somewhat verbose - esp since the application is >10K LOC. > > > > Don't the funcName and lineno arguments in the format string work for > you? > > (See http://docs.python.org/library/logging.html#id1) I don't think he's interested in the "line number where the logging call was issued" but where the exception occurred. Thorsten From jgardner at jonathangardner.net Tue Jan 6 17:20:01 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 14:20:01 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> Message-ID: <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> On Jan 6, 12:24?pm, J Kenneth King wrote: > Jonathan Gardner writes: > > On Jan 6, 8:18?am, sturlamolden wrote: > >> On Jan 6, 4:32 pm, mark wrote: > > >> > I want to implement a internal DSL in Python. I would like the syntax > >> > as human readable as possible. > > >> Also beware that Python is not Lisp. You cannot define new syntax (yes > >> I've seen the goto joke). > > > This isn't really true. You can, for instance, write a program (in > > Python) that takes your pseudo-Python and converts it into Python. > > This is what a number of templating libraries such as Mako do. > > Which is not even close to being the same. > > Lisp - the program source is also the data format > > Python - the program source is a string > > I could go on a really long rant about how the two are worlds apart, but > I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. From gagsl-py2 at yahoo.com.ar Tue Jan 6 17:49:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 20:49:19 -0200 Subject: socket send help References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: En Mon, 05 Jan 2009 22:59:46 -0200, James Mills escribi?: > On Tue, Jan 6, 2009 at 10:49 AM, Bryan Olson > wrote: >>> I thought a firewall would block an attempt to bind to any routeable >>> address, but not to localhost. So using INADDR_ANY would be rejected. > > No. > >> My understanding is that firewalls block network traffic, not system >> calls. > > This is correct. Firewalls (real firewalls) can only act on incoming > and outgoing traffic on the IP level. That's true for hardware firewalls (those found in a router, by example). They can at most analyze traffic at the application layer but have no idea of the applications (processes) behind. A "software firewall" may react not just to traffic but to *who* is doing that; it may block *processes* when they try to bind/listen to any port, even before any packet is sent or received. See http://www.securityfocus.com/infocus/1839 (One may argue whether those are *real* firewalls or not, but that's their common name...) (Also note that I'm far for being an expert on these topics) -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:10:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:10:08 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Tue, 06 Jan 2009 12:42:13 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Such assumptions only hold under particular domains though. You can't >> assume equality is an equivalence relation once you start thinking >> about arbitrary domains. > > From a formal mathematical point of view, equality /is/ an equivalence > relation. If you have a relation on some domain, and it's not an > equivalence relation, then it ain't the equality relation, and that's > flat. Okay, fair enough. In the formal mathematical sense, equality is always an equivalence relation. So there are certain domains which don't have equality, e.g. floating point, since nan != nan. Also Python objects, since x.__eq__(y) is not necessarily the same as y.__eq__(x). >> But there cannot be any such function which is a domain-independent >> equivalence relation, not if we're talking about arbitrarily wacky >> domains. > > That looks like a claim which requires a proof to me. But it could also > do with a definition of `domain', so I'll settle for one of those first. I'm talking about domain in the sense of "a particular problem domain". That is, the model, data and operations used to solve a problem. I don't know that I can be more formal than that. To prove my claim, all you need is two domains with a mutually incompatible definition of equality. That's not so difficult, surely? How about equality of integers, versus equality of integers modulo some N? > If we're dealing with sets (i.e., `domain's form a subclass of `sets') > then the claim is clearly false, and equality (determined by comparison > of elements) is indeed a domain-independent equivalence relation. It isn't domain-independent in my sense, because you have specified one specific domain, namely set equality. >> Even something as straight-forward as "is" can't be an equivalence >> relation under a domain where identity isn't well-defined. > > You've completely lost me here. The Python `is' operator is (the > characteristic function of) an equivalence relation on Python values: > that's its definition. Yes, that's because identity is well-defined in Python. I'm saying that if identity isn't well-defined, then neither is the 'is' operator, and therefore it isn't an equivalence relation. That shouldn't be controversial. > All Python objects are instances of `object' or of some more specific > class. The `==' operator on `object' is (the characteristic function > of) an equivalence relation. In, fact, it's the same as `is' -- but > `==' can be overridden by subclasses, and subclasses are permitted -- > according to the interface definition -- to coarsen the relation. In > fact, they're permitted to make it not be an equivalence class at all. > > I claim that this is a problem. It *can* be a problem, if you insist on using == on arbitrary types while still expecting it to be an equivalence relation. If you drop the requirement that it remain an e-r, then you can apply == to arbitrary types. And if you limit yourself to non-arbitrary types, then you can safely use (say) any strings you like, and == will remain an e-r. I /agree/ that domain-specific > predicates are useful, and can be sufficiently useful that they deserve > the `==' name -- as well as floats and numpy, I've provided SAGE and > sympy as examples myself. But I also believe that there are good > reasons to want an `equivalence' operator (I'll write it as `=~', though > I don't propose this as Python syntax -- see below) with the following > properties: > > * `=~' is the characteristic function[1] of an equivalence relation, > i.e., for all values x, y, z: x =~ y in (True, False); (x =~ x) == > True; if x =~ y then y =~ x; and if x =~ y and y =~ z then x =~ z > > * Moreover, `=~' is a coarsening of `is', i.e. for all values x, y: if > x is y then x =~ y. Ah, but you can't have such a generic e-r that applies across all problem domains. Consider: Let's denote regular, case-sensitive strings using "abc", and special, case-insensitive strings using i"abc". So for regular strings, equality is an e-r; for case-insensitive strings, equality is also an e-r (I trust that the truth of this is obvious). But if you try to use equality on *both* regular and case-insensitive strings, it fails to be an e-r: i"abc" =~ "ABC" returns True if you use the case-insensitive definition of equality, but returns False if you use the case-sensitive definition. There is no single definition of equality that is *simultaneously* case- sensitive and case-insensitive. > A valuable property might be that x =~ y if x and y are > indistinguishable without using `is'. That's a little strong, because it implies that equality must look at *everything* about a particular object, not just whatever bits of data are relevant for the problem domain. For example, consider storing data in a dict. >>> D1 = {-1: 0, -2: 0} >>> D2 = {-2: 0} >>> D2[-1] = 0 >>> D1 == D2 True We certainly want D1 and D2 to be equal. But their history is different, and that makes their internal details different, which has detectable consequences: >>> D1 {-2: 0, -1: 0} >>> D2 {-1: 0, -2: 0} The same happens with trees. Given a tree structure defined as: (payload, left-subtree, right-subtree) do you want the following two trees to be equal? ('b', ('a', None, None), ('c', None, None)) ('a', None, ('b', None, ('c', None, None))) Unless I've made a silly mistake, not only are the payloads of the two trees equal, but so are the in-order representation of both. Only the specific order the nodes are stored in differ, and that may not be important for the specific problem you are trying to solve. There may be problem domains where the order of elements in a list (or tree structure) *is* important, and other problem domains where order is irrelevant. One single relation can't cover all such conflicting requirements. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:15:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:15:35 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Tue, 06 Jan 2009 14:03:16 +0000, Mark Wooding wrote: >> You've also missed out on probably twenty years of CS where Java (using >> the same assignment model as Python!) has been *the* language of choice >> for undergrad CS, not to mention those introductory courses which use >> Python. > > There's no way that Java has been taught anywhere for 20 years. It just > isn't old enough. Wikipedia claims that Java appeared in 1995, which > looks right to me. Python, released in 1991, is therefore older. I stand corrected. Can we agree that Java has been the language of choice for most of a decade? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:18:39 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:18:39 GMT Subject: Code Review request for the trash-cli project References: Message-ID: On Tue, 06 Jan 2009 17:30:19 +0200, Dotan Cohen wrote: > I don't know about the code, but would there be a reason _not_ to alias > rm, rmdir to this program? I see that it is GPL, so this would be a > great addition to any Linux distro. I sure as hell don't want rm to move files to the trash. If I rm something, I want it *gone*. I do want a *different* command for moving files to the trash. But absolutely not rm. Of course, if anyone wants to alias rm in their own shell, they're welcome to. That's what the alias command is for. -- Steven From Graham.Dumpleton at gmail.com Tue Jan 6 18:31:29 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 6 Jan 2009 15:31:29 -0800 (PST) Subject: mod_python: delay in files changing after alteration References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Message-ID: <80e89ae6-af47-420b-8d25-63966f92891a@o40g2000prn.googlegroups.com> On Jan 6, 2:39?am, "psaff... at googlemail.com" wrote: > Maybe this is an apache question, in which case apologies. > > I am runningmod_python3.3.1-3 on apache 2.2.9-7. It works fine, but > I find that when I alter a source file during development, it > sometimes takes 5 seconds or so for the changes to be seen. This might > sound trivial, but when debugging tens of silly errors, it's annoying > that I have to keep hitting refresh on my browser waiting for the > change to "take". I'm guessing this is just a caching issue of some > kind, but can't figure out how to switch it off. Any suggestions? > > The entry in my apache2.conf looks like this: > > > ? ?SetHandlermod_python > ? ?PythonHandlermod_python.publisher > ? ?PythonDebug On > If the change is to a Python module installed on sys.path the change would never be reloaded by a process. If you are seeing a delay, it is probably only because the request is being handled by a different Apache child process that has never loaded the code before. This is all because Apache is a multiprocess web server on UNIX. Thus, any changes to modules/packages installed on sys.path require a full restart of Apache to ensure they are loaded by all Apache child worker processes. So, which code files are you actually modifying, ie., where do they exist and how are they imported? Graham From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:35:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:35:12 GMT Subject: If your were going to program a game... References: Message-ID: On Tue, 06 Jan 2009 10:44:39 -0700, Joe Strout wrote: > Not that I have anything against Flash; I've started learning it just > last week, and apart from the nasty C-derived syntax, it's quite nice. > It has a good IDE, good performance, great portability, and it's easy to > use. It just surprises me that after all these years, the Python > community hasn't done something similar. It's bad enough that every time I go to a website using Flash, my browser is running untrusted code in my browser, but at least Adobe has spent a bucket-load of time and money making it (almost) secure. I sure as hell don't want arbitrary Python code running in my browser. Oh, and even Adobe hasn't got it completely right: IBM research Mark Dowd has demonstrated an incredible vulnerability that allows a single Trojan to exploit Flash in either IE or Firefox while leaving the Flash runtime operating normally. And it can bypass Vista security. Although Dowd doesn't explicitly mention other OSes, I see no reason to believe the same technique wouldn't work on Linux. http://www.matasano.com/log/1032/this-new-vulnerability-dowds-inhuman- flash-exploit/ This is not your regular buffer overflow vulnerability. Read it and weep. -- Steven From gagsl-py2 at yahoo.com.ar Tue Jan 6 18:41:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 21:41:32 -0200 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> Message-ID: En Fri, 02 Jan 2009 15:00:01 -0200, r escribi?: > Steven i got you NOW! > Everybody go and look at this thread, there Mr. Makinzie butts in and > posts an off-topic question, and Steven answers it, contributing to > the off-topicalitly of the thread. And has yet to apologize for it, or Does the word "annoyness" exist? You're getting high scores on my ranking. -- Gabriel Genellina From bowman.joseph at gmail.com Tue Jan 6 19:18:10 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Tue, 6 Jan 2009 16:18:10 -0800 (PST) Subject: having problems with a multi-conditional while statement Message-ID: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Hi, I'm trying to write a multi-conditional while statement, and am having problems. I've broken it down to this simple demo. #!/usr/bin/python2.5 condition1 = False condition2 = False while not condition1 and not condition2: print 'conditions met' if condition1: condition2 = True condition1 = True As I understand it, this should print 'conditions met' twice, however, it only prints it once. It seems that once condition1 is made true, the whole thing evaluates as true and stops the while loop. I've also tried to set the while condition the following ways also, and had the same problem while (not condition1 and not condition2): while (not condition1) and (not condition2): while condition1 != True and condition2 != True: while (condition1 != True and condition2 != True): while (condition1 != True) and (condition2 != True): Can someone lend me a hand in understanding this? From philip at semanchuk.com Tue Jan 6 19:34:32 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 6 Jan 2009 19:34:32 -0500 Subject: having problems with a multi-conditional while statement In-Reply-To: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: <95F236CF-6FAE-4690-AB81-9D2FF54341CD@semanchuk.com> On Jan 6, 2009, at 7:18 PM, bowman.joseph at gmail.com wrote: > Hi, > > I'm trying to write a multi-conditional while statement, and am having > problems. I've broken it down to this simple demo. > > #!/usr/bin/python2.5 > > condition1 = False > condition2 = False > > while not condition1 and not condition2: > print 'conditions met' > if condition1: > condition2 = True > condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > it only prints it once. It seems that once condition1 is made true, > the whole thing evaluates as true and stops the while loop. Think it through. At the outset: while (not condition1) and (not condition2) ==> while (not False) and (not False) ==> while True and True ==> while True After it's been through the loop once: while (not condition1) and (not condition2) ==> while (not True) and (not False) ==> while False and True ==> while False Change the "and" to an "or" and you'll get the result you expected. From nad at acm.org Tue Jan 6 19:42:26 2009 From: nad at acm.org (Ned Deily) Date: Tue, 06 Jan 2009 16:42:26 -0800 Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: In article <40a44d6b-c638-464d-b166-ef66496a0676 at l16g2000yqo.googlegroups.com>, "bowman.joseph at gmail.com" wrote: > Hi, > > I'm trying to write a multi-conditional while statement, and am having > problems. I've broken it down to this simple demo. > > #!/usr/bin/python2.5 > > condition1 = False > condition2 = False > > while not condition1 and not condition2: > print 'conditions met' > if condition1: > condition2 = True > condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > it only prints it once. It seems that once condition1 is made true, > the whole thing evaluates as true and stops the while loop. Are you perhaps expecting that the "while" condition is tested at the end of the loop? It's not; it is tested at the top of the loop, so, once the condition evaluates as false, the loop exits. This can even result in zero trips: >>> while False: ... print "never" ... >>> Unwinding the snippet above: >>> condition1 = False >>> condition2 = False >>> not condition1 and not condition2 True >>> if condition1: ... condition2 = True ... >>> condition1 = True >>> not condition1 and not condition2 False # -> while loop exits after 1 trip -- Ned Deily, nad at acm.org From gagsl-py2 at yahoo.com.ar Tue Jan 6 19:57:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 22:57:43 -0200 Subject: cPickle vs pickle discrepancy References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: En Mon, 05 Jan 2009 23:04:30 -0200, Zac Burns escribi?: > I have a module that attempts to pickle classes defined in that module. > > I get an error of the form: > PicklingError: Can't pickle : import > of module Module.SubModule failed > when using cPickle (protocol -1, python version 2.5.1). > > The module has already been imported and is in sys.modules when the > exception is raised. There is no thing as a "submodule"; very likely you have a package, and a module inside that package. - always import the "submodules" from the package, not directly (relative imports are safer) - in general, don't play with PYTHONPATH, sys.path, and such things. - don't directly execute a module inside a package (it's name is always __main__ and it doesn't even "know" it's part of a package). > Using pickle instead of cPickle works, but the section of the code is > performance critical. Could you provide a short example? I'd say that if you stick to the above rules you won't have the issue again, but anyway I'd like to know in which cases Pickle and cPickle differ. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 20:02:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 01:02:54 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Tue, 06 Jan 2009 14:32:04 +0000, Mark Wooding wrote: > Derek Martin wrote: > >> I think I have though, not that it matters, since that was never really >> my point. Python's assignment model requires more explanation than the >> traditional one, simply to state what it does. That alone is evidence >> (but not proof). > > Hmm. Actually, it's not the assignment model which is strange at all. > It's the data model. What does an expression like > > [1, 2, 3] > > denote? Is it the list itself, Yes. > or a /reference/ to the list? No. > If you answer the first, you'll want Tcl/C/Fortran semantics. Absolutely not! I want *Python* semantics, and amazingly enough, that's *just what Python gives*. > If you answer the second, you'll want Lisp/Python/Javascript > semantics. If I wanted a reference to a list, I'd expect to *dereference* the reference to get to the list. That's not what Python forces you do to: you just use the list as the list object itself. This isn't hard people. Stop confusing the implementation details of how CPython works under the hood with Python level code. In Python, [1, 2, 3] is a list, not a reference to a list. When you pass [1, 2, 3] to a function, the function sees the list you passed it. The function doesn't see "a reference to a list", it sees a list: >>> def func(x): ... print type(x) ... >>> func([1, 2, 3]) It's so easy, some people refuse to believe it could be that easy, and insist on complicating matters by bring the implementation details into the discussion. Just stop, please. References belong in the *implementation*, nothing to do with Python level code. In Python code, there are no references and no dereferencing. > Python decided that all values are passed around as and manipulated > through references. Oh really? Then why can't I write a Python function that does this? x = 1 y = 2 swap(x, y) assert x == 2 assert y == 1 You can't, because Python doesn't have references. In a language with references, that's easy. Here's an untested Pascal version for swap: procedure swap(var x: integer, var y: integer); var tmp: integer; begin tmp := x; x := y; y := x; end; It's harder (impossible?) to write a version that will operate on arbitrary types, but that's statically typed languages for you. > (There are no locatives: references are not values, But references *are* locatives. > and you can't have a reference to a reference.) Lists store references; > tuples store references; and so on. No no no, lists and tuples store *objects*. Such storage happens to be implemented as pointers in CPython, but that's an irrelevant detail at the level of Python. -- Steven From bowman.joseph at gmail.com Tue Jan 6 20:17:36 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Tue, 6 Jan 2009 17:17:36 -0800 (PST) Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: <509aed9c-a761-4d05-bda0-02971fc2e495@r37g2000prr.googlegroups.com> Thanks for the assistance. I actually realized I was making things more complicated than they needed to be and I really only needed one condition to be met. On Jan 6, 7:42?pm, Ned Deily wrote: > In article > <40a44d6b-c638-464d-b166-ef66496a0... at l16g2000yqo.googlegroups.com>, > > > > ?"bowman.jos... at gmail.com" wrote: > > Hi, > > > I'm trying to write a multi-conditional while statement, and am having > > problems. I've broken it down to this simple demo. > > > #!/usr/bin/python2.5 > > > condition1 = False > > condition2 = False > > > while not condition1 and not condition2: > > ? ? print 'conditions met' > > ? ? if condition1: > > ? ? ? ? condition2 = True > > ? ? condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > > it only prints it once. It seems that once condition1 is made true, > > the whole thing evaluates as true and stops the while loop. > > Are you perhaps expecting that the "while" condition is tested at the > end of the loop? ? It's not; it is tested at the top of the loop, so, > once the condition evaluates as false, the loop exits. ?This can even > result in zero trips: > > >>> while False: > > ... ? ? print "never" > ... > > > > Unwinding the snippet above: > > >>> condition1 = False > >>> condition2 = False > >>> not condition1 and not condition2 > True > >>> if condition1: > > ... ? ? condition2 = True > ...>>> condition1 = True > >>> not condition1 and not condition2 > > False > > # -> while loop exits after 1 trip > > -- > ?Ned Deily, > ?n... at acm.org From mdw at distorted.org.uk Tue Jan 6 20:23:19 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 01:23:19 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > To prove my claim, all you need is two domains with a mutually > incompatible definition of equality. That's not so difficult, surely? How > about equality of integers, versus equality of integers modulo some N? No, that's not an example. The integers modulo N form a ring Z/NZ of residue classes. Such residue classes are distinct from the integers -- e.g., an integer 3 (say) is not the same as the set 3 + NZ { ..., 3 - 2N, 3 - N, 3, 3 + N, 3 + 2N, ... } -- but there is a homomorphism from Z to Z/NZ under which 3 + NZ is the image of 3. If we decide to define the == operator such that 3 == 3 + NZ and 3 + N == 3 + NZ then == is not an equivalence relation (in particular, transitivity fails). But that's just an artifact of the definition. If we distinguish 3 from 3 + NZ then everything is fine. 3 + NZ == (3 + N) + NZ correctly, but 3 != 3 + N, and all is well. Here, at least, the problem is not that == as an equivalence relation fails in some particular domain -- because in both Z and Z/NZ it can be a perfectly fine equivalence relation -- but that it can potentially fail on the boundaries between domains. Easy answer: don't mess it up at the boundaries. Proposition. Let U, U' be disjoint sets, and let E, E' be equivalence relations on U, U' respectively. Define E^ on U union U' as E^ = E union E', i.e., E^(x, y) iff x in U and y in U and E(x, y) or x in U' and y in U' and E'(x, y) Then E^ is an equivalence relation. Proof. Reflexivity and symmetry are trivial; transitivity follows from disjointness of U and U'. > It *can* be a problem, if you insist on using == on arbitrary types > while still expecting it to be an equivalence relation. Unfortunately, from the surrounding discussion, it seems that container types particularly want to be able to contain arbitrary objects, and the failure of == to be a equivalence relation makes this fail. The problem is that objects with wacky == operators are still more or less quacking like the more usual kinds of ducks; but they turn out to taste very different. > Let's denote regular, case-sensitive strings using "abc", and special, > case-insensitive strings using i"abc". So for regular strings, equality > is an e-r; for case-insensitive strings, equality is also an e-r (I > trust that the truth of this is obvious). But if you try to use equality > on *both* regular and case-insensitive strings, it fails to be an e-r: > > i"abc" =~ "ABC" returns True if you use the case-insensitive definition > of equality, but returns False if you use the case-sensitive definition. > There is no single definition of equality that is *simultaneously* case- > sensitive and case-insensitive. A case-sensitive string is /not the same/ as a case-insensitive string. One's a duck, the other's a goose. I'd claim here that i"abc" =~ "ABC" must be False, because i"abc" =~ "abc" must be false also! To define it otherwise leads to the incoherence you describe. But the above proposition provides an easy answer. > > A valuable property might be that x =~ y if x and y are > > indistinguishable without using `is'. > > That's a little strong, because it implies that equality must look at > *everything* about a particular object, not just whatever bits of data > are relevant for the problem domain. Yes. That's one of the reasons that =~ isn't the same as ==. I've been thinking on my feet in this thread, so I haven't thought everything through. And as I mention below, there are /many/ useful equality predicates on values. As I didn't mention (but hope is obvious) having a massively-parametrized equality predicate is daft, and providing enough to suit every possible application equally so. But we might be able to do well enough with just one or two -- or maybe by just leaving things as they are. > For example, consider storing data in a dict. > > >>> D1 = {-1: 0, -2: 0} > >>> D2 = {-2: 0} > >>> D2[-1] = 0 > >>> D1 == D2 > True > > > We certainly want D1 and D2 to be equal. Do we? If we're using my `indistinguishable without using ``is''' criterion from above, then D1 and D2 are certainly different! To detect the difference, mutate one and see if the other changes: def distinct_dictionaries_p(D1, D2): """ Decide whether D1 and D2 are the same dictionary or not. Not threadsafe. """ magic = [] more_magic = [magic] old = D1.get('mumble', more_magic) D1['mumble'] = magic result = D2.get('mumble', more_magic) is magic if old is more_magic: del D1['mumble'] else: D1['mumble'] = old return result But that criterion was a suggestion -- a way of defining a coherent equivalence relation on the whole of the Python value space which is coarser than `is' and maybe more useful. My primary purpose in proposing it was to stimulate discussion: what /do/ we want from equality predicates? We already have `is', which is too fine-grained to be widely useful: it distinguishes between different instances of the number 500000, for example, and I can't for the life of me see why that's a useful behaviour. (The `is' operator is a fine thing, and I wouldn't want it any other way: it trades away some useful semantics for the sake of speed, and that was the /right/ decision.) My criterion succeeds in distinguishing 1 from 1.0 (they have different types), which may be considered good. It doesn't distinguish a quiet NaN from another quiet NaN: that's definitely good. (It'd be bogus for a numeric equality operator, but we've already got one of those, so we don't need to define another.) But you're probably right: it's still too fine-grained for some purposes. > But their history is different, and that makes their internal details > different, which has detectable consequences: > > >>> D1 > {-2: 0, -1: 0} > >>> D2 > {-1: 0, -2: 0} So in this case, `str' also works as a distinguisher. Fine. > There may be problem domains where the order of elements in a list (or > tree structure) *is* important, and other problem domains where order is > irrelevant. One single relation can't cover all such conflicting > requirements. Absolutely. This is why Common Lisp provides four(!) out of the box and it still isn't enough. Python provides one (`is') and a half (`==' when it's behaving) is actually coping remarkably well considering. But this /is/ causing problems, and so thinking about solutions seems reasonable. I'm not trying to change the language. I don't have a pet feature I want added. I do think the discussion is interesting and worthwhile, though. -- [mdw] From gdamjan at gmail.com Tue Jan 6 20:24:31 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 07 Jan 2009 02:24:31 +0100 Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: >> And there are >> some things (such as Flash-style web applets) that you still can't do >> at all in Python, even after all these years. > > You're looking for Silverlight: > > http://www.voidspace.org.uk/ironpython/silverlight/index.shtml or clutter which has Python bindings http://www.clutter-project.org/ -- ?????? ( http://softver.org.mk/damjan/ ) Hi! I'm a .signature virus! copy me into your .signature file to help me spread! From gagsl-py2 at yahoo.com.ar Tue Jan 6 20:24:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 23:24:32 -0200 Subject: __builtin__ quote References: <81F8l.4494$jZ1.3657@flpi144.ffdc.sbc.com> Message-ID: En Tue, 06 Jan 2009 06:56:36 -0200, James Stroud escribi?: > Steven Woody wrote: >> On Tue, Jan 6, 2009 at 4:42 PM, James Stroud >> wrote: >>> py> import __builtin__ >>> py> __builtin__.abs is abs >>> True >> Does that mean someone did 'import * from __builtin__' when python >> startup? > > In terms of the exact implementation of the cPython interpreter, I don't > know. But the interpreter behaves as if someone did just that. So there > is nothing wrong with thinking of it this way if it helps you understand > the interpreter. Not exactly. Built-in names are "one step further" global names; it's not that builtin names populate by default the global namespace. As local names "hide" (or "shadow") global names, those global names "hide" builtin names. Those three namespaces are distinct, like onion layers (global and local namespaces are the same at the module level). If the interpreter did the equivalent of "from __builtin__ import *", redefining builtin names would destroy them, but that's not the case: # the builtin "abs" function >>> abs(-3) 3 >>> abs # this one "hides" the builtin abs >>> def abs(x): ... return "Hi, I'm the abs() global function!" ... >>> abs(-3) "Hi, I'm the abs() global function!" >>> abs # remove the global "abs" >>> del abs # we can access again the builtin "abs" >>> abs(-3) 3 >>> abs -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 21:25:21 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 02:25:21 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Tue, 06 Jan 2009 13:43:01 -0800, Aaron Brady wrote: > I think one of the ideas we have trouble communicating is that [1, 2, 3] > and [4, 5, 6] can be the same object Not at the same time they can't. > (using '[:]='), but [1, 2, 3] and [1, 2, 3] don't have to be. I don't think this is hard to get across, if you think about objects. You have a list. It's like a box. That box can hold items 1, 2 and 3. You can replace those items with 4, 5 and 6, and it's still the same box. Likewise, you can have a box with items 1, 2 and 3 inside it, and a different box also with items 1, 2 and 3, and they're still different boxes. The only tricky thing is that items 1, 2 and 3 can be inside two different boxes at the same time. There's no obvious real world analogy to that without the boxes being nested. This ability for objects to be in two places at once (or even to be inside themselves!) is one of the few reasons why Python's use of references in the implementation needs to be mentioned. -- Steven From narkewoody at gmail.com Tue Jan 6 21:56:26 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 10:56:26 +0800 Subject: message of Exception Message-ID: Hi, I am trying define an Exception as below: class MyError(Exception): def __init__(self, message): self.message = message And, I expect that when I raise a MyError as raise MyError, "my message" the python should print a line such as MyError: my message But I did not get that, I just got: ... MyError I guess I had made something wrong with the __init__() definition, but I can not find an answer in doc. Please help, thanks! - narke From gnewsg at gmail.com Tue Jan 6 22:01:48 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Tue, 6 Jan 2009 19:01:48 -0800 (PST) Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? Message-ID: <76277bc4-2810-48f4-8953-4393eb97c810@t26g2000prh.googlegroups.com> Hi, I'm trying to add TLS/SSL support to pyftpdlib. Since various defects have been found in the SSLv2 protocol many FTPS servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 only and sistematically reject any client attempting to use SSLv2. Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 connections only? If that's not possible can I determine the encryption protocol being used *after* that the SSL/TLS handshake took place? I tried to use wrap_socket as follows: self.socket = ssl.wrap_socket(self.socket, , certfile=CERTFILE, server_side=True, ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) ...it works if on the client side I use TLSv1 but not if I use SSLv3 ("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is raised) Thanks in advance for any help. --- Giampaolo http://code.google.com/p/pyftpdlib/ From clp2 at rebertia.com Tue Jan 6 22:09:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 19:09:17 -0800 Subject: message of Exception In-Reply-To: References: Message-ID: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> On Tue, Jan 6, 2009 at 6:56 PM, Steven Woody wrote: > Hi, > > I am trying define an Exception as below: > > class MyError(Exception): > def __init__(self, message): > self.message = message > > And, I expect that when I raise a MyError as > raise MyError, "my message" > the python should print a line such as > MyError: my message > > But I did not get that, I just got: > ... > MyError > > I guess I had made something wrong with the __init__() definition, but > I can not find an answer in doc. Please help, thanks! You need to call the superclass constructor: #note: this code will be different in Py 3.0 class MyError(Exception): def __init__(self, message): super(MyError, self).__init__(message) Or if you're not going to add anything else to MyError, you might as well just leave the class body empty and it'll use Exception's __init__, which takes care of the message. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rurpy at yahoo.com Tue Jan 6 22:21:13 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 6 Jan 2009 19:21:13 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> On Jan 6, 7:03?am, Mark Wooding wrote: ... > > It seems that you don't include in the Python community all those who > > use the term "name binding" instead of variable assignment > > specifically because it gives new users a clue that Python is not the > > same as C. > > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. Is not the proper term "aliasing"? Perhaps Python "variables" should be called "alises". >From http://en.wikipedia.org/wiki/Aliasing_(computing) "aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program." From mdw at distorted.org.uk Tue Jan 6 22:36:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 03:36:50 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Steven D'Aprano wrote: > If I wanted a reference to a list, I'd expect to *dereference* the > reference to get to the list. That's not what Python forces you do to: > you just use the list as the list object itself. That's odd. No, you give a reference to the list to a function, and the function messes with the list for you. > This isn't hard people. Stop confusing the implementation details of > how CPython works under the hood with Python level code. I'm not confusing anything. This is conceptual-model stuff, not implementation details. (Further discussion below.) > In Python, [1, 2, 3] is a list, not a reference to a list. In [1]: l = [1, 2, 3] In [2]: l[1] = l In [3]: l Out[3]: [1, , 3] Now, if you're right, then l directly contains itself and some other stuff, which is obviously absurd: it's a list, not a Tardis. If I'm right, then l is bound to a reference to a list which contains three references, two of them to integers and a third to the list itself. This doesn't seem absurd at all any more. Variables are not the only places where sharing can occur! Explaining this is much harder if you don't start from the idea that all you're doing is carting uniformly shaped references about. Another example: In [1]: a = [1, 2, 3] In [2]: b = (a, a) In [3]: b Out[3]: ([1, 2, 3], [1, 2, 3]) In [4]: a[1] = 0 In [5]: b Out[5]: ([1, 0, 3], [1, 0, 3]) If b is a tuple containing two copies of a, then this shouldn't have happened. The only satisfactory explanation is that the tuple that b refers to actually contains two references to the same list, so when I mutate that list, the change shows up twice. > When you pass [1, 2, 3] to a function, the function sees the list you > passed it. The function doesn't see "a reference to a list", it sees a > list: > > >>> def func(x): > ... print type(x) > ... > >>> func([1, 2, 3]) > It sees the reference. `type' sees the reference. `type' digs the type of the object out of the reference, and returns you a reference to the type. > It's so easy, some people refuse to believe it could be that easy, and > insist on complicating matters by bring the implementation details into > the discussion. Just stop, please. References belong in the > *implementation*, nothing to do with Python level code. I'm not getting into implementation details. I'm presenting a mental model. The `they're objects: they contain other objects' model is invalidated when you create circular or shared structures, as I've shown above. There are other epicyclic explanations you could invent to explain sharing, maybe -- like keeping lists of clones, and magically updating all the clones whenever one us mutated. That may even be a valid implementation for a distributed Python (with cached copies of objects and a cache-coherency protocol and all that), but it makes a rotten mental model. And it still doesn't explain circularity. Internally, Tcl uses pointers to values in its implementation. The common currency inside the Tcl interpreter is a Tcl_Obj *. (It used to be a char *, before Tcl 8.) So Tcl could easily offer the same semantics as Python and friends. But there's a twist. Tcl does copy-on-write. It's just impossible to make a circular value in Tcl, and sharing doesn't happen. For example, here's a snippet of a tclsh session. % set l {a b c} a b c % lreplace $l 1 1 $l a {a b c} c Tcl really /can/ be explained without talking about references. The existence of Tcl_Obj, and its strange dual-ported nature (it contains a string and an internal representation, and lazily updates one from the other, and uses the string in order to allow changes of internal representation as necessary) really is an implementation detail, and it's possible to have a full understanding of the behaviour of Tcl programs without knowing about it. This is just impossible with Python. Reference semantics pervade the language. > In Python code, there are no references and no dereferencing. You're right! But the concept is essential in understanding the semantics of the language. Even though no references are explicitly made, and no dereferencing explicitly performed, these things are done repeatedly under the covers -- and failure to understand that will lead to confusion. > > Python decided that all values are passed around as and manipulated > > through references. > > Oh really? Then why can't I write a Python function that does this? > > x = 1 > y = 2 > swap(x, y) > assert x == 2 > assert y == 1 Because the function is given references to the objects. It's not given references to /your/ references to those objects. Therefore it can't modify /your/ references, only its ones. Pedantic answer: def swap(hunoz, hukairz): global x, y x, y = y, x (Maybe nonlocal for Python 3.) > You can't, because Python doesn't have references. In a language with > references, that's easy. Here's an untested Pascal version for swap: [snip] That's call-by-reference, which is a different thing. Python, like Lisp, Scheme, Javascript, ML, Haskell, Lua, Smalltalk, Erlang, Prolog, Java, and indeed C, does call-by-value exclusively. This deserves to be called out as a display: Python passes references by value. By contrast, Pascal (sometimes) passes values by reference! The terminology is admittedly confusing, because it comes from different places. If you don't like me talking about Python having references, then pretend I've been saying `pointer' instead, all the way through. I think `pointer' and `reference' are synonymous in this context, attempts by Stroustrup to confuse everybody notwithstanding. But `pointer' has unhelpful connotations: * pointers are more usually values rather than strange behind-the- scenes things, e.g., in C; * pointers, probably because of C, are associated with scariness and non-safe-ness; and * talking of pointers does seem like it's getting towards implementation details, and I wanted to avoid that. Anyway, call-by-value means that the function gets given copies of the caller's arguments; call-by-reference means that the function gets told where the caller's arguments are. In other words call-by-reference introduces /another/ level of indirection between variables and values. > > (There are no locatives: references are not values, > > But references *are* locatives. No! A locative is a /reified/ reference -- a /value/ that /is/ a reference. That is a locative is a reference, but a reference need not be a locative. (A sheep is a mammal, but not all mammals are sheep.) The Lisp Machine had real locatives. You dereferenced them using CAR and RPLACA -- most unpleasant. In modern Lisp systems they seem to have died a death, probably because making them work with fancy things like resizing arrays when you don't have invisible pointers is too painful. > No no no, lists and tuples store *objects*. Such storage happens to be > implemented as pointers in CPython, but that's an irrelevant detail at > the level of Python. Uh-uh. There's no way that an object can store itself and still have room left over. The idea is just crazy. It can't possibly fit. (Axiom of foundation, if you're into that funky stuff.) If you say `no, but it can store a reference to itself', then everything makes sense. It's completely uniform, and not very scary. Lisp people draw these box-and-pointer diagrams all over the place +-----+-----+ | * | *------> NIL +--|--+-----+ | v 3 to show how the data model works. Of course, the Lisp data model is /exactly the same as Python's/. After a while, the diagrams get less pedantic, and tend to show values stashed /in/ the cons cells. In fact, this is actually closer to most implementations for small things like fixnums, characters and flonums, because they're represented by stashing the actual value with some special not-really-a-pointer tag bits -- but the program can't tell, so this doesn't need to be part of your mental model until you start worrying about performance hacking and why your program is consing so much. -- [mdw] From mdw at distorted.org.uk Tue Jan 6 22:49:02 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 03:49:02 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: Steven D'Aprano wrote: > The only tricky thing is that items 1, 2 and 3 can be inside two > different boxes at the same time. There's no obvious real world analogy > to that without the boxes being nested. This ability for objects to be in > two places at once (or even to be inside themselves!) is one of the few > reasons why Python's use of references in the implementation needs to be > mentioned. Ahh. So it /does/ need to be mentioned after all. But you're wrong: it's not an implementation detail: it's an essential part of the language semantics. A better analogy. The objects are scattered across the floor. No object is contained in another. However, we have a plentiful supply of bits of string, each of which is tied to a Teflon-covered paperweight at one end and has a blob of Blu-Tack on the other. Instead of putting something in a box directly, what we do is grab a piece of string, stick the Blu-Tack to the thing, and put the paperweight in the box. This way, we can stick several bits of string to the same object and put the paperweights in different boxes. Indeed, nothing stops us sticking two bits of string to a box, and putting both paperweights inside that same box. But fitting a box into itself twice requires origami skills that frighten me. The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos you're not allowed to do that. There's a daemon who comes around periodically and cleans up the mess of paperweights which aren't in boxes, and tidies away things which don't have any string stuck to them any more, but really he's just an implementation detail and you wouldn't need him if your floor was big enough and you had enough bits of sufficiently long string. -- [mdw] From narkewoody at gmail.com Tue Jan 6 22:55:56 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 11:55:56 +0800 Subject: message of Exception In-Reply-To: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> References: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> Message-ID: On Wed, Jan 7, 2009 at 11:09 AM, Chris Rebert wrote: > On Tue, Jan 6, 2009 at 6:56 PM, Steven Woody wrote: >> Hi, >> >> I am trying define an Exception as below: >> >> class MyError(Exception): >> def __init__(self, message): >> self.message = message >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" >> the python should print a line such as >> MyError: my message >> >> But I did not get that, I just got: >> ... >> MyError >> >> I guess I had made something wrong with the __init__() definition, but >> I can not find an answer in doc. Please help, thanks! > > You need to call the superclass constructor: > > #note: this code will be different in Py 3.0 > class MyError(Exception): > def __init__(self, message): > super(MyError, self).__init__(message) Thank you, I forgot to call base class's __init__() > > Or if you're not going to add anything else to MyError, you might as > well just leave the class body empty and it'll use Exception's > __init__, which takes care of the message. Yes, I know that, I just want to try and learn something. From tjreedy at udel.edu Tue Jan 6 23:02:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jan 2009 23:02:20 -0500 Subject: message of Exception In-Reply-To: References: Message-ID: Steven Woody wrote: > Hi, > > I am trying define an Exception as below: > > class MyError(Exception): > def __init__(self, message): > self.message = message > > And, I expect that when I raise a MyError as > raise MyError, "my message" In 2.x you may and in 3.0 you must write that as raise MyError("my message") Best to start looking forward ;-). From mdw at distorted.org.uk Tue Jan 6 23:20:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 04:20:26 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Is not the proper term "aliasing"? Perhaps Python "variables" should > be called "alises". No. The proper term is most definitely `binding': see SICP, for example. (Wikipedia has a link to the full text.) The topic of `aliasing' deals with a problem in compiler implementation, where certain optimizations are valid only if two objects are known not to share storage, so that mutating one won't alter the other. This is a particular problem for C, since C programs makes heavy use of pointers; also, Fortran semantics allow the compiler to assume that aliasing does not occur in a number of places, and C compiler writers are keen to keep up with Fortran performance levels. In a wider context, `aliases' tend to be /additional/ names for things, with the connotation of being secondary to some primary or canonical name. For example, Linux 2.2 network interfaces had `aliases', which were additional logical interfaces associated with the physical interface, but with different (but related) names and distinct addresses. Nowadays, Linux network interfaces can have multiple addresses anyway, and the idea of aliases is left as a compatibility hack. -- [mdw] From narkewoody at gmail.com Wed Jan 7 00:03:51 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 13:03:51 +0800 Subject: message of Exception In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 12:02 PM, Terry Reedy wrote: > Steven Woody wrote: >> >> Hi, >> >> I am trying define an Exception as below: >> >> class MyError(Exception): >> def __init__(self, message): >> self.message = message >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" > > In 2.x you may and in 3.0 you must write that as > raise MyError("my message") > Best to start looking forward ;-). Ok, I will adapt the advice. From wuwei23 at gmail.com Wed Jan 7 00:04:45 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 6 Jan 2009 21:04:45 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <795ea4a1-ed8e-44e8-9a06-9199318b9e01@f40g2000pri.googlegroups.com> On Jan 1, 9:37?pm, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? pyglet[1], pygame[2], or pycap[3]. > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. You could always make Firefox + the PyXPCOM[4] extensions a requirement for use, then just code up the UI in Python where you'd usually use JavaScript. The desktop client could be based on XULRunner [5], then both the web & desktop versions should be pretty much identical. 1: http://www.pyglet.org/ 2: http://www.pygame.org/ 3: http://www.farbs.org/pycap.html 4: http://pyxpcomext.mozdev.org/ 5: https://developer.mozilla.org/en/XULRunner From steve at holdenweb.com Wed Jan 7 00:19:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 00:19:11 -0500 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <49643B4F.7020709@holdenweb.com> Mark Wooding wrote: > Steven D'Aprano wrote: > >> The only tricky thing is that items 1, 2 and 3 can be inside two >> different boxes at the same time. There's no obvious real world analogy >> to that without the boxes being nested. This ability for objects to be in >> two places at once (or even to be inside themselves!) is one of the few >> reasons why Python's use of references in the implementation needs to be >> mentioned. > > Ahh. So it /does/ need to be mentioned after all. But you're wrong: > it's not an implementation detail: it's an essential part of the > language semantics. > > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. > > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, but really he's just an > implementation detail and you wouldn't need him if your floor was big > enough and you had enough bits of sufficiently long string. > Thanks for nailing that one. I have long felt the semantics of Python could be but poorly served without the use of the term "reference" (and indeed I have pointed out int he past that the language reference manual feels free to use the term liberally), but I wasn't able to persist long enough to bring the conversation to this conclusion (except that I am pretty sure this *won't* be a conclusion ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mensanator at aol.com Wed Jan 7 01:25:07 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 6 Jan 2009 22:25:07 -0800 (PST) Subject: Oh! The people of all over the world! References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> Message-ID: <6f17738f-3355-4b3c-b137-6c32b8e5a0ed@r41g2000prr.googlegroups.com> On Jan 6, 7:51?pm, "Obaid R." wrote: > On Jan 7, 2:53?am, Mensanator wrote: > > > But the OP isn't trying to get sympathy for the Isrealis, he's > > trying to get sympathy for his own cause. > > > Which is hard to do given the provocation that's resulting > > in Isreal's retalliation. > > > If the civilians are suffering, why isn't this appeal being > > made to the Hamas leadership? > > > > -- > > > Steven > > So an illegal occupation is NOT a provocation Jesus taught that you don't react to provocation, so you won't make any headway with that argument. > but fighting the > occupation IS? By which scales do you judge? I don't judge, I ignore. Your real task is to break the apathy. > > I would argue that a person following such backwards logic and who > sees these pictures[1] The problem is that no one sees the pictures. Which came first, the rockets or the cluster bombs? Because the rockets were first, no one cares to peruse the pictures because they have already decided that the victims are just getting what they deserve. You may have a keen sense of logic but obviously are clueless about human nature. > and STILL claims that showing sympathy is Doesn't this campaign of yours make you a heretic to the true believers who advocate martyrdom? > difficult has a serious problem. After all the logic is simple: for > every action (read occupation) there is a reaction (read resistance) > equal to it in force and opposite to it in direction. > > You can of course argue that the reaction is the cause of the action, > but that is clearly illogical and proves your iniquity in this matter > and your bias against the victim. It might take a humanitarian > catastrophe of sizable proportions and a biased person would still not > feel any sympathy. Not that there is no catastrophe, but rather > because bias is by nature practiced in spite of good reason and > available evidence, not because of it. > > [1] Pictures > -------------http://www.aljazeera.net/mritems/images/2009/1/6/1_883542_1_34.jpghttp://www.aljazeera.net/mritems/images/2009/1/5/1_883331_1_34.jpghttp://www.aljazeera.net/mritems/images/2009/1/2/1_882580_1_23.jpghttp://newsimg.bbc.co.uk/media/images/45348000/jpg/_45348570_2.jpghttp://newsimg.bbc.co.uk/media/images/45348000/jpg/_45348571_3.jpghttp://newsimg.bbc.co.uk/media/images/45350000/jpg/_45350743_boygrab2...http://newsimg.bbc.co.uk/media/images/45346000/jpg/_45346309_ambulanc...http://www.alquds.co.uk/latest/data/2009-01-06-14-21-12.jpghttp://www.alquds.co.uk/today/06z49.jpghttp://www.alrai.com/img/208500/208725.jpg From harish.shastry at gmail.com Wed Jan 7 01:28:09 2009 From: harish.shastry at gmail.com (Harish Vishwanath) Date: Wed, 7 Jan 2009 11:58:09 +0530 Subject: What is ''r'' in python? Message-ID: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Hello, I accidentally did this in the shell. >>> ''r'' '' >>> ''r'' == '' True >>> ''r'' == "" True That is . However if I try -> >>> ''c'' File "", line 1 ''c'' ^ SyntaxError: invalid syntax >>> ''z'' File "", line 1 ''z'' ^ SyntaxError: invalid syntax Any other character that way is Invalid Syntax. What is so special about character r enclose within a pair of single quotes? Regards, Harish -------------- next part -------------- An HTML attachment was scrubbed... URL: From c2thunes at brewtab.com Wed Jan 7 01:38:33 2009 From: c2thunes at brewtab.com (Christopher Thunes) Date: Wed, 07 Jan 2009 01:38:33 -0500 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <49644DE9.4070002@brewtab.com> Hey Harish, Python automatically concatenates strings constants so this is actually '' then r'' which is the empty string followed by a 'raw' empty string. See here, http://docs.python.org/tutorial/introduction.html#strings. ''u'' and ''b'' will work for the same reason. - Chris Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > >> >> ''r'' > '' >> >> ''r'' == '' > True >> >> ''r'' == "" > True > > That is . However if > I try -> > >> >> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax >> >> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special about > character r enclose within a pair of single quotes? > > Regards, > Harish > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Wed Jan 7 01:45:51 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 22:45:51 -0800 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <50697b2c0901062245t53c75ea0w72d8c865b15545ab@mail.gmail.com> On Tue, Jan 6, 2009 at 10:28 PM, Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > >>>> ''r'' > '' >>>> ''r'' == '' > True >>>> ''r'' == "" > True > > That is . However if I > try -> > >>>> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax >>>> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special about > character r enclose within a pair of single quotes? That's probably an artifact of r being used as the prefix in the syntax for raw strings. See http://docs.python.org/reference/lexical_analysis.html#string-literals for more on raw strings. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gherron at islandtraining.com Wed Jan 7 01:47:44 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 06 Jan 2009 22:47:44 -0800 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <49645010.1020703@islandtraining.com> Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > > >>> ''r'' > '' > >>> ''r'' == '' > True > >>> ''r'' == "" > True > > That is . However > if I try -> > > >>> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax > >>> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special > about character r enclose within a pair of single quotes? Well... For starters, that's not what you have. Python does not have "pairs of single quotes", so you'll have to look elsewhere for an answer. Here it is, but bear with me for a minute: Strings can be created in many different ways: 'a' # single quotes "b" # double quotes '''c''' # Triple single quotes """c""" # Triple double quotes Then there are the so-called raw strings which interpret backslashes differently r'a' r"b" ... Then there are also Unicode strings -- but we don't need those here. So what you have when you type ''r'' # (That's four single quotes although your font may make it look like two double quotes.) is an empty string '' followed by another empty string (using raw syntax) r'' The last piece of the puzzle is a (seemingly) little know feature of Python's syntax: If you specify two strings (in any syntax) without an operator between them, they are automatically concatenated. Like this: >>> 'a' 'b' 'ab' >>> "a" 'b' 'ab' >>> 'a' r'b' 'ab' >>> 'a' u'b' u'ab' So there you have it. Your mystery is the (automatic) concatenation of two empty strings. Gary Herron > > Regards, > Harish > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From quian.xu at stud.tu-ilmenau.de Wed Jan 7 02:16:23 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 08:16:23 +0100 Subject: pg_result_status() alternative? Message-ID: Hi All, I am using the pg module (http://www.pygresql.org/pg.html) for database testing. I have got a problem now: I want to check the result status of postgresql database, which can be done in php by using pg_result_status() (http://www.phpbuilder.com/manual/en/function.pg-result-status.php) How can I do the same thing in python (2.5)? Thanks in advance -- Qian Xu From apardon at forel.vub.ac.be Wed Jan 7 02:31:06 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 7 Jan 2009 07:31:06 GMT Subject: ftp seems to get a delayed reaction. References: <125c8dc6-d467-443f-8755-4ab725266b22@z28g2000prd.googlegroups.com> Message-ID: On 2009-01-06, Jeremy.Chen wrote: > ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) > ---------- > I think the params after STOR should't be a path,should be splited. > ftp.cwd("ftp-tst") > ftp.storbinary("STOR ftp-file\n", fl) No that isn't the problem. The problem is the '\n' at the end of the string. Having removed it, all worked fine. -- Antoon Pardon From mail at microcorp.co.za Wed Jan 7 02:44:36 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 7 Jan 2009 09:44:36 +0200 Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> <95F236CF-6FAE-4690-AB81-9D2FF54341CD@semanchuk.com> Message-ID: <019501c970a1$699e5700$0d00a8c0@hendrik> "Philip Semanchuk" wrote: 8<------------ nice explanation -------------------- > Change the "and" to an "or" and you'll get the result you expected. Also google for "De Morgan", or "De Morgan's laws" Almost everybody stumbles over this or one of it's corollaries at least once in their careers. - Hendrik -- With the disappearance of the gas mantle and the advent of the short circuit, man's tranquillity began to be threatened by everything he put his hand on. (James Thurber. First sentence of Sex ex Machina) From alessio.pace at gmail.com Wed Jan 7 02:54:40 2009 From: alessio.pace at gmail.com (Alessio Pace) Date: Tue, 6 Jan 2009 23:54:40 -0800 (PST) Subject: Portable (Linux/Mac/Win) way to get network interfaces names and their addresses? Message-ID: <80b18a66-2817-4080-8a64-2e0392b8042d@c36g2000prc.googlegroups.com> Hi, I'm wondering how could I get, possibly in a pure Python solution, the list of network addresses on a machine and the IP address of each of them. In fact I came across recently on two solutions, one that is pure Python but that works only on Linux: ############################# def all_interfaces(): max_possible = 128 # arbitrary. raise if needed. bytes = max_possible * 32 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) names = array.array('B', '\0' * bytes) outbytes = struct.unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, # SIOCGIFCONF struct.pack('iL', bytes, names.buffer_info()[0]) ))[0] namestr = names.tostring() return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) ########################### and one other instead that is in the "netifaces" package (=> http://alastairs-place.net/netifaces/) which is written in C. Thanks in advance for any suggestion. -- Alessio Pace. From mail at microcorp.co.za Wed Jan 7 03:20:43 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 7 Jan 2009 10:20:43 +0200 Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com><200812301421.29888.mail@johnohagan.com><6s8s6nF4op56U2@mid.uni-berlin.de><3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet><20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com><531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <019601c970a1$6a3566e0$0d00a8c0@hendrik> "Mark Wooding" wrote: > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. > > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, but really he's just an > implementation detail and you wouldn't need him if your floor was big > enough and you had enough bits of sufficiently long string. > Lovely! This is the nicest analogy I have seen, and it seems to completely account for all the observed effects. The only other one that comes close is Dennis L Bieber's "Wandering Names". I propose that we name the garbage collection demon "Steven" because he has IMO lost this argument, and therefore deserves to spend eternity tied up in string. ;-) - Hendrik -- With the disappearance of the gas mantle and the advent of the short circuit, man's tranquillity began to be threatened by everything he put his hand on. (James Thurber. First sentence of Sex ex Machina) From mobiledreamers at gmail.com Wed Jan 7 03:37:13 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Wed, 7 Jan 2009 00:37:13 -0800 Subject: Using couchdb to build a EMAIL messaging solution with threaded inline replies Message-ID: Using couchdb to build a EMAIL messaging solution with threaded inline replies http://pylab.blogspot.com/search/label/couchdb -------------- next part -------------- An HTML attachment was scrubbed... URL: From ihatespam at hotmail.com Wed Jan 7 03:48:09 2009 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Wed, 7 Jan 2009 03:48:09 -0500 Subject: Any news on when some libraries will be ported to Python 3.0? Message-ID: I'm excited to use Python 3.0 (foolishly, it's the only Python interpreter I have on my system) but there are no libraries for it beyond the kitchen sink. Personally, a good start would be Beautiful Soup and Mechanize. I could also use DB. Has there been any word on Beautiful Soup? Has there been any word on Mechanize? What about DB? PIL would be nice, too, now that I think about it. Anyway, I'd love to hear some news about any of these things in particular or even anything in general. Am I the only one who's psyched for this version of Python? Thank you... From steven at REMOVE.THIS.cybersource.com.au Wed Jan 7 03:53:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 08:53:29 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 03:49:02 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> The only tricky thing is that items 1, 2 and 3 can be inside two >> different boxes at the same time. There's no obvious real world analogy >> to that without the boxes being nested. This ability for objects to be >> in two places at once (or even to be inside themselves!) is one of the >> few reasons why Python's use of references in the implementation needs >> to be mentioned. > > Ahh. So it /does/ need to be mentioned after all. Only in the sense that the behaviour of *real world* objects don't entirely match the behaviour of Python objects. If you just accept that Python objects can be in two places at once, an unintuitive concept I accept but hardly difficult to grasp, then you don't need to mention references. (Of course, as a purely practical matter, the English language makes it difficult to avoid the word "reference" entirely. That's not my intention.) > But you're wrong: > it's not an implementation detail: it's an essential part of the > language semantics. Er, pardon me, but you yourself suggested that one could implement Python without using references to objects, "like keeping lists of clones, and magically updating all the clones whenever one us mutated. That may even be a valid implementation for a distributed Python". Like you suggested, it would be a seriously rotten model for standard Python, but it is possible. The language semantics specifies the *behaviour*, not the *mechanism* required to implement that behaviour. > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. Not a bad analogy. I like it. But it still fails. Why can't I stick the paperweight in the box *before* attaching the Blu- Tack to something else, and then forget about attaching the Blu-Tack? There's nothing in your model to prevent dangling pointers, except hand- waving "it doesn't work like that". I assume the string is made of Teflon, otherwise I could stick the Blu- Tack to another piece of string. By the same token, the floor needs to be Teflon too. Why can't I grab the string by the end with the Blu-Tack and follow it backwards to find out where the paperweight is? I obviously know how to handle the end, because according to your model I'm sticking it to other objects. I suppose maybe there's a robot that does that Blu-Tack sticking for me, I just point to the object and say "That one!" and it happens. The string itself is invisible except to radar, which the robot has, and I don't. That way I can't follow the string backwards to find out where the paperweight is. Hmmm. This model is getting awfully complicated: Teflon string, Teflon paperweights, Blu-Tack, *and* a robot (presumably Teflon as well), none of which are visible to Python code, as well as objects which are. > This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. Ah, you've obviously never studied origami under Sensei Ping of the Clan of the Pointed Stick! > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, So there's a brief moment between creating the object and sticking the Blu-Tack on it when the daemon might take the object and the string away? No, I guess not, that's another thing I just have to take on faith... the daemon knows not to touch anything until the robot has finished with it. Can I tie two pieces of string together, stop the daemon from disposing of them? Apparently not. Objects in two places at one time isn't sounding that weird any more. I actually do like your model, despite poking holes in it. As a model for what CPython is doing under the hood, it pretty good. But it's not a model for what a Python programmer does when writing Python code. There's no action equivalent to "attach blob of Blu-Tack to object", no action equivalent to "put the paperweight in the box". The robot does that when you point to an object and say "put that inside the box". The programmer doesn't do these things, he says "put that object in the box" and the robot attaches the Blu-Tack and moves the paperweight. The strings and paperweights and Blu-Tack are invisible and intangible to the programmer, *and* they are an implementation detail: as you put it, we could implement Python using clones of objects magically kept in sync, no string required. -- Steven From rogerb at rogerbinns.com Wed Jan 7 04:13:11 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 07 Jan 2009 01:13:11 -0800 Subject: Any news on when some libraries will be ported to Python 3.0? In-Reply-To: References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just Another Victim of the Ambient Morality wrote: > Anyway, I'd love to hear some news about any of these things in > particular or even anything in general. Am I the only one who's psyched for > this version of Python? I ported my APSW SQLite access module many months before Python 3.0 was released (around the time of the first beta release). The same codebase supports both Python 2 and 3 with very few conditionals and a few macros to make some Python 2 C api look like the Python 3 C api (eg pretending that the bytes type exists). Python 2.3 and up are supported on all platforms. It took longest to port my test suite over as I have 99.6% code coverage which is achieved by the test suite abusing every corner of the language and implementation. Fortunately a whole host of issues go away because of no 8 bit strings in Python 3. Other tools like Sphinx made my documentation so much better. That actually psyches me the most since Python is all about ease of reading and writing. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAklkchwACgkQmOOfHg372QTgewCfXBrz0UGuUNDqxjVGEJOwfF4p N6QAoJvZCZ1Vm9f6sN0P4bXb8o3I2pVj =Lba+ -----END PGP SIGNATURE----- From akineko at gmail.com Wed Jan 7 04:24:56 2009 From: akineko at gmail.com (akineko) Date: Wed, 7 Jan 2009 01:24:56 -0800 (PST) Subject: multiprocessing and SIGINT Message-ID: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> Hello everyone, I'm trying to use multiprocessing module, which is now available with Python 2.6. It is a nice enhancement and it worked great. However, I have a situation and I couldn't figure out how to deal with. My Python program spawns another process to take care of GUI house- keeping. When I type Ctrl-C to my terminal, instead of my main process, the spawned process always gets the SIGINT. I don't want the spawned process to handle SIGINT event. An exception handler (KeyboardInterrupt) is placed in the main program (but it didn't catch the event). I never encountered this problem before as spawned threads won't take SIGINT event. Is there any way I can force SIGINT event routing so that my main process will get it? Because of another requirement, I cannot swap main and spawned process. Any suggestions will be greatly appreciated. Best regards, Aki Niimura From steven at REMOVE.THIS.cybersource.com.au Wed Jan 7 04:26:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 09:26:47 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Wed, 07 Jan 2009 01:23:19 +0000, Mark Wooding wrote: > A case-sensitive string is /not the same/ as a case-insensitive string. > One's a duck, the other's a goose. I'd claim here that i"abc" =~ "ABC" > must be False, because i"abc" =~ "abc" must be false also! To define it > otherwise leads to the incoherence you describe. It's only incoherent if you need equality to be an equivalence relation. If you don't, it is perfectly reasonable to declare that i"abc" equals "abc". -- Steven From sibteym at infotechsw.com Wed Jan 7 04:53:13 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Wed, 7 Jan 2009 15:23:13 +0530 Subject: Multiprocessing takes higher execution time Message-ID: <005701c970ad$c1b27140$5fc513ac@pwit.com> Hi, I use multiprocessing to compare more then one set of files. For comparison each set of files (i.e. Old file1 Vs New file1) I create a process, Process(target=compare, args=(oldFile, newFile)).start() It takes 61 seconds execution time. When I do the same comparison without implementing multiprocessing, it takes 52 seconds execution time. The parallel processing time should be lesser. I am not able to get advantage of multiprocessing here. Any suggestions can be very helpful. Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at python.net Wed Jan 7 04:58:05 2009 From: theller at python.net (Thomas Heller) Date: Wed, 07 Jan 2009 10:58:05 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <6sjcksF6574qU1@mid.individual.net> Nick Craig-Wood schrieb: > Ralf Schoenian wrote: >> Ryan wrote: >> > I've been using Python for many years now. It's a wonderful language >> > that I enjoy using everyday. I'm now interested in getting to know >> > more about the guts (C/C++) and extending it. But, extending python >> > still seems like a black art to me. Is there anymore docs or info on >> > extending it besides the standard sparse ones (http://www.python.org/ >> > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a >> > class available? How can I learn more about the guts of python? How >> > would one go about following an interest in contributing to the >> > development of python. >> >> It is not exactly what you are looking for but nevertheless I am >> thinking the article "Automatic C Library Wrapping -- Ctypes from the >> Trenches" may be interesting for you. You can find it in the latest >> Python Papers issue or simply following the link: >> http://ojs.pythonpapers.org/index.php/tpp/article/view/71 > > Interesting - I didn't know about h2xml and xml2py before and I've > done lots of ctypes wrapping! Something to help with the initial > drudge work of converting the structures would be very helpful. > > ( http://pypi.python.org/pypi/ctypeslib/ ) > > I gave it a quick go and it worked fine. I had to edit the XML in one > place to make it acceptable (removing a u from a hex number). The > output of xml2py was an excellent place to start for the conversion, > though I don't think I'd want to use an automated process like in the > paper above as its output needed tweaking. > > ... If you are using a recent version of gccxml, then you should use the ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should really merge the gccxml-0.9 branch into the trunk;-) If you are already using the branch and the XML file is not accepted, then could you please provide a short C code snippet that reproduces the problem so that I can fix it? > Here are my thoughts on the conversion :- > > It converted an interface which looked like this (the inotify interface) > > struct inotify_event { > int wd; /* Watch descriptor */ > uint32_t mask; /* Mask of events */ > uint32_t cookie; /* Unique cookie associating related > events (for rename(2)) */ > uint32_t len; /* Size of name field */ > char name[]; /* Optional null-terminated name */ > }; > > Into this > > class inotify_event(Structure): > pass > inotify_event._fields_ = [ > ('wd', c_int), > ('mask', uint32_t), > ('cookie', uint32_t), > ('len', uint32_t), > ('name', c_char * 0), > ] > > Which is a very good start. However it defined these which clearly > aren't portable > > int32_t = c_int > uint32_t = c_uint > > Whereas it should have been using the ctypes inbuilt types > > c_int32 > c_uint32 IMO this would be difficult to achive automatically. There are cases wher c_int is the correct type, in other cases c_int32 is correct. > Also I don't think c_char * 0 does anything sensible in ctypes, > c_byte * 0 is what is required plus a bit of casting. This is a > non-standard GNU extension to C though. > > All that said though, it looks like a great time saver. > Thanks, Thomas From mdw at distorted.org.uk Wed Jan 7 05:17:55 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 10:17:55 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: Steven D'Aprano wrote: > Only in the sense that the behaviour of *real world* objects don't > entirely match the behaviour of Python objects. If you just accept > that Python objects can be in two places at once, an unintuitive > concept I accept but hardly difficult to grasp, then you don't need to > mention references. To my mind, explaining that objects can actually be in two (or three, or any unbounded number) of places at once, stashed inside each other to an arbitrary degree -- that looks like the excuses of someone who's been caught in a lie. Maybe it was a useful lie-to-children, meant to avoid explaining the full details in advance, but the time comes to put away childish things, and learn the truth. (I can't believe I just quoted Paul. I feel all dirty.) > Er, pardon me, but you yourself suggested that one could implement > Python without using references to objects, "like keeping lists of > clones, and magically updating all the clones whenever one us mutated. > That may even be a valid implementation for a distributed Python". > > Like you suggested, it would be a seriously rotten model for standard > Python, but it is possible. The language semantics specifies the > *behaviour*, not the *mechanism* required to implement that behaviour. Yes, there's an isomorphism between the two, so technically either could be used as a model to explain the behaviour of Python. But, to my mind at least, the idea of references (or sticky bits of string) is the simpler -- it doesn't involve doing anything`magically' -- so Occam suggests that it's superior. I'm sure, if I tried, I could come with an even more absurd model, or express it in more complicated ways, but the power of a model lies in its combination of simplicity and explanatory power. The `they're just objects' model is very simple, but gets tied up in knots explaining things. The `it's all references' model is only a little more complicated, but explains everything. It might be -- and I don't know, because I'm not an educator -- that the `they're just objects' model hits a local maximum in the tradeoff between simplicity and explanation that's sufficiently high that it's useful for teaching beginners. It's hard to expose this simple model's weaknesses without assignment (or messing with `is' or `id'); unfortunately, it's very easy to explose them once you do have assignment (or any kind of mutable state). And Python's purely functional subset is rarely used exclusively in nontrivial programs. So I'm sceptical that this particular lie-to-children doesn't cause more harm than good. > Why can't I stick the paperweight in the box *before* attaching the Blu- > Tack to something else, and then forget about attaching the Blu-Tack? > There's nothing in your model to prevent dangling pointers, except hand- > waving "it doesn't work like that". Perils of posting at half past three in the morning, I'm afraid. I seemed to have hit a creative streak, but my clarity of thinking was definitely impaired. You are only allowed to handle paperweights. A robot does the rest. Some of the objects might give you splinters or paper cuts. The robot is concerned about your safety and won't let you go near them. There's a wall between you and the playpen, with a catflap in it. The robot will fit through the catflap but you're too big. (For advanced users only: there might be a secret hatch which lets you into the main arena where the robot works, via a storeroom containing a surprising quantity of handy power tools, heavy weaponry, and explosives, but oddly lacking in safety goggles. You can build some truly marvellous things by sneaking through here, and persuade the robot to do things it wouldn't usually by threatening it at gunpoint, but you can also blow yourself up.) You tell the robot what you want him to do by handing him paperweights. He doesn't take the paperweights away with him, but instead hooks onto the string so that he can follow it to the other end. He's quite good at following even tangled strings, and at finding paperweights in boxes and hooking onto their strings too. The robot will stick new strings onto objects at your request and hand you the paperweights. > I assume the string is made of Teflon, otherwise I could stick the Blu- > Tack to another piece of string. By the same token, the floor needs to be > Teflon too. You could do, if you were actually given a loose piece of string. But you aren't, so that's OK. I was wrong that the paperweights needed to be Teflon. > Why can't I grab the string by the end with the Blu-Tack and follow it > backwards to find out where the paperweight is? Because you're never at that end. And the robot just won't do that. (The daemon in the MIT Scheme environment /can/ do this for you. It uses a feature called `wabbit hunting'. You set up a `Fudd thunk' describing which objects you want it to find the paperweights of, and set the thing to `wabbit season'. The daemon will track down the `wabbits' -- boxes holding those paperweights -- that you asked for and returns them. When you want it to stop doing this, you return to `duck season'. Yes, it's very silly.) > This model is getting awfully complicated: Teflon string, Teflon > paperweights, Blu-Tack, *and* a robot (presumably Teflon as well), > none of which are visible to Python code, as well as objects which > are. Wow. I didn't actually read this far before hitting `follow-up', but you anticipated the robot. Well done. But, no, actually nothing needs to be made of Teflon, and I was just tired. > Ah, you've obviously never studied origami under Sensei Ping of the > Clan of the Pointed Stick! Apparently not. My origami skills are, alas, weak. > So there's a brief moment between creating the object and sticking the > Blu-Tack on it when the daemon might take the object and the string away? > No, I guess not, that's another thing I just have to take on faith... the > daemon knows not to touch anything until the robot has finished with > it. The daemon knows not to interfere with the robot, and the robot knows to do everything in the right order. But the daemon is an optional part of the model, so we can just ignore him until we're ready to deal with him. The daemon's name is Maxwell, by the way. Say hello, Maxwell. > Can I tie two pieces of string together, stop the daemon from disposing > of them? Apparently not. No, but you can confuse him for a little while by building box- paperweight-string-box-... cycles. Eventually he cottons on to what you've done, though. > But it's not a model for what a Python programmer does when writing > Python code. There's no action equivalent to "attach blob of Blu-Tack > to object", no action equivalent to "put the paperweight in the box". No, indeed. Python is a language for talking about paperweights. And it's because of the paperweights that the duck-typing works: all the paperweights are the same shape and size, so they're physically interchangeable. > The robot does that when you point to an object and say "put that > inside the box". The programmer doesn't do these things, he says "put > that object in the box" and the robot attaches the Blu-Tack and moves > the paperweight. Yup! > The strings and paperweights and Blu-Tack are invisible and intangible > to the programmer, *and* they are an implementation detail: as you put > it, we could implement Python using clones of objects magically kept > in sync, no string required. You could try to explain Python in terms of paperweights only, but since they all look identical, it's hard to see why interesting behaviour emerges without explaining about the world on the side of the strings. Of course, the paperweights-and-string-(and-robot-and-catflap-(and- storeroom-cum-arms-cache)) model explains it all, and doesn't leave you having to learn Sensei Ping's arcane origami skills. If you're actually /in/ the arena with the objects, armed with the ability to fold a box so strangely that you can store it in three other boxes and itself, how come you never make a catastrophic mistake? My answer is that the robot doesn't make mistakes often, and the worst you can do to yourself is get in a bit of a tangle with those bits of string. If you're really cunning, you might manage to persuade the robot to fetch a hand-grenade from the storeroom and blow itself up, but there'll be a new version of the robot available later which won't fall for that trick. -- [mdw] From mdw at distorted.org.uk Wed Jan 7 05:21:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 10:21:50 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > It's only incoherent if you need equality to be an equivalence relation. > If you don't, it is perfectly reasonable to declare that i"abc" equals > "abc". Right! And if you didn't want an equivalence relation, then `==' will suit you fine. The problem is that some applications seem to /want/ an equivalence relation, and one that's more useful (i.e., less discriminating) than `is'. -- [mdw] From jstroud at mbi.ucla.edu Wed Jan 7 05:25:31 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 02:25:31 -0800 Subject: Oh! The people of all over the world! In-Reply-To: <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> Message-ID: Obaid R. wrote: > So an illegal occupation is NOT a provocation but fighting the > occupation IS? By which scales do you judge? > > I would argue that a person following such backwards logic and who > sees these pictures[1] and STILL claims that showing sympathy is > difficult has a serious problem. After all the logic is simple: for > every action (read occupation) there is a reaction (read resistance) > equal to it in force and opposite to it in direction. > > You can of course argue that the reaction is the cause of the action, > but that is clearly illogical and proves your iniquity in this matter > and your bias against the victim. It might take a humanitarian > catastrophe of sizable proportions and a biased person would still not > feel any sympathy. Not that there is no catastrophe, but rather > because bias is by nature practiced in spite of good reason and > available evidence, not because of it. I'm much more apt to listen now that you aren't invoking references to religion at every sentence. If Israel is guilty of inhumanity, then it is more appropriate to appeal to one's humanity. By the way, its obvious to most rational people that the Israeli reaction is overwrought and likely morally unjust--but I can't stand antisemitism just like I can't stand hatred of Islam just like I can't stand hatred of Christians. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From quian.xu at stud.tu-ilmenau.de Wed Jan 7 05:40:35 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 11:40:35 +0100 Subject: string length problem? Message-ID: Hi All, why the code print len(u"?test?") returns 8 instead of 6? Best regards Qian From vinay_sajip at yahoo.co.uk Wed Jan 7 05:47:32 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 7 Jan 2009 02:47:32 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: <5710ebc5-cf13-4978-a411-08d1df6eb422@40g2000prx.googlegroups.com> On Jan 6, 10:19 pm, Thorsten Kampe wrote: > I don't think he's interested in the "line number where the logging call > was issued" but where the exception occurred. Well, he does say "all logging" and "every logging". And, as I mentioned earlier, there is already support for tracebacks by using the Logger.exception method in an exception handler. Regards, Vinay Sajip From david at hlacik.eu Wed Jan 7 05:57:57 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Wed, 7 Jan 2009 11:57:57 +0100 Subject: linked list with cycle structure Message-ID: dictionary with cycle structure Hello guys, I have a linked list where *number of elements is unlimited* and **last element points on random (can be first, last, in middle , anywhere) element within linked list** - this is important . My goals is to create an architecture /scheme for **algoritmus which will count total number of elements** of such linked list. Yes , maybe it sounds strange, but we need to implement this and i would be very gladfull for your toughts. Thanks in advance and wishing you a sucessfull year! David From martin at v.loewis.de Wed Jan 7 06:17:58 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 12:17:58 +0100 Subject: Problem building Python 2.5.2 curses module on HP/UX 11.11 In-Reply-To: References: Message-ID: <49648f66$0$32239$9b622d9e@news.freenet.de> > So, given that there are no actual errors during the compile, and the > warnings are probably benign, does anyone know what would cause the > resulting compiled module to NOT have the init function? Can you do nm(1) on the module? It's now called _curses_failed.sl Regards, Martin From __peter__ at web.de Wed Jan 7 06:26:12 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Jan 2009 12:26:12 +0100 Subject: string length problem? References: Message-ID: Qian Xu wrote: > why the code > print len(u"?test?") > returns 8 instead of 6? You may have declared an encoding that differs from the one your editor actually uses, e. g. # -*- coding: iso-8859-1 -*- print len(u"?test?") whereas your editor writes UTF-8. Peter From nospam at nospam.com Wed Jan 7 06:27:00 2009 From: nospam at nospam.com (Gilles Ganault) Date: Wed, 07 Jan 2009 12:27:00 +0100 Subject: [urllib2] 302 -> can't get cookie Message-ID: Hello I'm using urllib2 to connect to a web server with POST, and then the server sends a cookie to hold the session ID, but also redirects the user to another page: === HTTP/1.1 302 Found Date: Wed, 07 Jan 2009 11:20:51 GMT Server: Apache Set-Cookie: PHPSESSID=4015f14eb04dc81159253a9533a7c590; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Location: second_page.php Content-Length: 0 Connection: close Content-Type: text/html; charset=ISO-8859-1 === As a result, urllib2 follows this new page, and the HTTP header that I get is the one from the second page. Is there a way to ignore this second page, and stick to the first page through which I connect? Thank you. From quian.xu at stud.tu-ilmenau.de Wed Jan 7 06:28:17 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 12:28:17 +0100 Subject: string length problem? References: Message-ID: Qian Xu wrote: > Hi All, > > why the code > print len(u"?test?") > returns 8 instead of 6? > > Best regards > Qian I have solved the problem myself. # -*- coding: utf-8 -*- print len(u"?test?") --- or --- s = "?test?" print len(s.decode("utf-8")) --Qian From sturlamolden at yahoo.no Wed Jan 7 06:45:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jan 2009 03:45:00 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Jan 7, 2:02 am, Steven D'Aprano wrote: > In Python code, there are no references and no dereferencing. The why does CPython keep track of reference counts? > You can't, because Python doesn't have references. In a language with > references, that's easy. Python does not 'pass-by-reference' as Fortran or Pascal do. > It's harder (impossible?) to write a version that will operate on > arbitrary types, but that's statically typed languages for you. In Python an assignment (re)binds the name to another value. You can certainly write a swap method for mutable types. But you cannot use the assignment operator to swap the values. > No no no, lists and tuples store *objects*. >>> a = 123456789 >>> b = [a] >>> c = [a] >>> d = [a, a] >>> b[0] is a True >>> c[0] is a True >>> d[0] is a True >>> d[1] is a True Where is the object 'a' stored? From steve at holdenweb.com Wed Jan 7 06:47:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 06:47:27 -0500 Subject: pg_result_status() alternative? In-Reply-To: References: Message-ID: Qian Xu wrote: > Hi All, > > I am using the pg module (http://www.pygresql.org/pg.html) for database > testing. > > I have got a problem now: > I want to check the result status of postgresql database, which can be done > in php by using pg_result_status() > (http://www.phpbuilder.com/manual/en/function.pg-result-status.php) > > How can I do the same thing in python (2.5)? > Without knowing the full details of that particular module I would hazard a guess that any database errors will raise exceptions in Python. No exceptions means your database operation worked fine. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 7 06:49:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 06:49:46 -0500 Subject: Multiprocessing takes higher execution time In-Reply-To: <005701c970ad$c1b27140$5fc513ac@pwit.com> References: <005701c970ad$c1b27140$5fc513ac@pwit.com> Message-ID: Sibtey Mehdi wrote: > Hi, > > > > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) I create > a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > > > When I do the same comparison without implementing multiprocessing, it > takes 52 seconds execution time. > > > > The parallel processing time should be lesser. > > > > I am not able to get advantage of multiprocessing here. > > > > Any suggestions can be very helpful. > My first suggestion would be: show us some code. We aren't psychic, you know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From quian.xu at stud.tu-ilmenau.de Wed Jan 7 07:21:23 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 13:21:23 +0100 Subject: pg_result_status() alternative? References: Message-ID: Steve Holden wrote: > Without knowing the full details of that particular module I would > hazard a guess that any database errors will raise exceptions in Python. > No exceptions means your database operation worked fine. result status is not an exception. It means the information of frontend/backend protocal, after a SQL-statement is execute. The following is a list of backend IPC commands (v3) ---------------------------------------------------- Z - Zero / Ready for Query E - Error Code A - Notification P - Cursor Response B - Binary Row D - Data, Ascii C - Complete G - Copy IN H - Copy OUT I - Idle T - Row Description V - Function result For instance: ---------------------------------------------------- SELECT * FROM my_table; The backend protocal should return T (Row Description) and the frontend protocal should return Q (Query) ---------------------------------------------------- DROP TABLE my_table; The backend protocal should return C (Complete) and the frontend protocal should return Q (Query) --Qian From marcisimo at googlemail.com Wed Jan 7 07:27:17 2009 From: marcisimo at googlemail.com (marco kuhn) Date: Wed, 7 Jan 2009 13:27:17 +0100 Subject: mac osx how to use a specific python environment Message-ID: hi, I would like to use a specific python environment in a script . The script is load as a plugin by a program which offer a python api . The python environment is build in. How can I use the standard python environment. Can i explicit load the env in my python script. Best MArco -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Wed Jan 7 07:31:15 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 07 Jan 2009 06:31:15 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> Message-ID: Thomas Heller wrote: > Nick Craig-Wood schrieb: > > Interesting - I didn't know about h2xml and xml2py before and I've > > done lots of ctypes wrapping! Something to help with the initial > > drudge work of converting the structures would be very helpful. > > > > ( http://pypi.python.org/pypi/ctypeslib/ ) > > > > I gave it a quick go and it worked fine. I had to edit the XML in one > > place to make it acceptable (removing a u from a hex number). > > If you are using a recent version of gccxml, then you should use the > ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should > really merge the gccxml-0.9 branch into the trunk;-) > > If you are already using the branch and the XML file is not accepted, > then could you please provide a short C code snippet that reproduces > the problem so that I can fix it? I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess doesn't have the code from the branch in. > > Here are my thoughts on the conversion :- > > > > It converted an interface which looked like this (the inotify interface) > > > > struct inotify_event { > > int wd; /* Watch descriptor */ > > uint32_t mask; /* Mask of events */ > > uint32_t cookie; /* Unique cookie associating related > > events (for rename(2)) */ > > uint32_t len; /* Size of name field */ > > char name[]; /* Optional null-terminated name */ > > }; > > > > Into this > > > > class inotify_event(Structure): > > pass > > inotify_event._fields_ = [ > > ('wd', c_int), > > ('mask', uint32_t), > > ('cookie', uint32_t), > > ('len', uint32_t), > > ('name', c_char * 0), > > ] > > > > Which is a very good start. However it defined these which clearly > > aren't portable > > > > int32_t = c_int > > uint32_t = c_uint > > > > Whereas it should have been using the ctypes inbuilt types > > > > c_int32 > > c_uint32 > > IMO this would be difficult to achive automatically. There are cases > wher c_int is the correct type, in other cases c_int32 is correct. Yes it is almost impossible difficult to achieve automatically - exactly how far do you want to unravel the twisty turny mess of typedefs that make up uint32_t? It is easy to change the generated output since it defines the type in one place. uint32_t and friends (stdint.h) are standardised in C99 so might it be reasonable to put some special cases in for them, expecially since the corresponding types already exist in ctypes? -- Nick Craig-Wood -- http://www.craig-wood.com/nick From wladimirufc at gmail.com Wed Jan 7 07:44:43 2009 From: wladimirufc at gmail.com (wladimir) Date: Wed, 7 Jan 2009 04:44:43 -0800 (PST) Subject: Defer problem Message-ID: <21330603.post@talk.nabble.com> Hi, I have an problem. I want to fire one callback after n callbacks fired, but when i fire one callback all the chain will be executed. Example: def handle(x): print 'callback ' + str(x) def handle2(x): print 'after callbacks' d1 = defer.Deffered() d2 = defer.Deffered() d3 = defer.Deffered() d = defer.DeferredList([d1, d2, d3], fireOnOneCallback =1 , fireOnOneErrback=1) d1.addCallback(handle) d2.addCallback(handle) d3.addCallback(handle) #d.addCallback(handle2) d1.callback(1) d2.callback(2) d3.callback(3) I want fire handle2 after all handle -- View this message in context: http://www.nabble.com/Defer-problem-tp21330603p21330603.html Sent from the Python - python-list mailing list archive at Nabble.com. From exarkun at divmod.com Wed Jan 7 08:05:53 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 7 Jan 2009 08:05:53 -0500 Subject: Defer problem In-Reply-To: <21330603.post@talk.nabble.com> Message-ID: <20090107130553.20272.1063061710.divmod.quotient.32919@ohm> On Wed, 7 Jan 2009 04:44:43 -0800 (PST), wladimir wrote: > >Hi, > >I have an problem. I want to fire one callback after n callbacks fired, but >when i fire one callback all the chain will be executed. Example: > >def handle(x): > print 'callback ' + str(x) > > >def handle2(x): > print 'after callbacks' > > >d1 = defer.Deffered() >d2 = defer.Deffered() >d3 = defer.Deffered() > >d = defer.DeferredList([d1, d2, d3], fireOnOneCallback =1 , >fireOnOneErrback=1) `fireOnOneCallback? is the flag which makes the `DeferredList? fire when the first wrapped `Deferred? has fired. If you want the `DeferredList? to only fire after all of the wrapped deferreds have fired, don't pass this flag. Jean-Paul From sjmachin at lexicon.net Wed Jan 7 08:12:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 7 Jan 2009 05:12:03 -0800 (PST) Subject: string length problem? References: Message-ID: On Jan 7, 9:40?pm, Qian Xu wrote: > Hi All, > > why the code > ? print len(u"?test?") > returns 8 instead of 6? I suggest that you do print repr(u"?test?") and inspect the result. HTH, John From exarkun at divmod.com Wed Jan 7 08:21:21 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 7 Jan 2009 08:21:21 -0500 Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? In-Reply-To: <76277bc4-2810-48f4-8953-4393eb97c810@t26g2000prh.googlegroups.com> Message-ID: <20090107132121.20272.551977417.divmod.quotient.32922@ohm> On Tue, 6 Jan 2009 19:01:48 -0800 (PST), Giampaolo Rodola' wrote: >Hi, >I'm trying to add TLS/SSL support to pyftpdlib. >Since various defects have been found in the SSLv2 protocol many FTPS >servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 >only and sistematically reject any client attempting to use SSLv2. >Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 >connections only? >If that's not possible can I determine the encryption protocol being >used *after* that the SSL/TLS handshake took place? > > >I tried to use wrap_socket as follows: > >self.socket = ssl.wrap_socket(self.socket, , > certfile=CERTFILE, > server_side=True, > >ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) > >...it works if on the client side I use TLSv1 but not if I use SSLv3 >("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL >routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is >raised) > At the OpenSSL level, you do this by specifying SSLv23_METHOD and then setting the SSL_OP_NO_SSLv2 flag. With pyOpenSSL, you do this by creating a context with SSLv23_METHOD and then setting SSL_OP_NO_SSLv2 on it, like so: from OpenSSL.SSL import Context, SSLv23_METHOD, OP_NO_SSLv2 context = Context(SSLv23_METHOD) context.set_options(OP_NO_SSLv2) It seems the ssl module does expose SSLv23_METHOD as PROTOCOL_SSLv23, but I don't see SSL_OP_NO_SSLv2 anywhere, nor any way to specify any extra flags. Oring PROTOCOL_SSLv3 together with PROTOCOL_TLSv1 is almost certainly not the right approach, anyway (as you saw with your tests). Jean-Paul From deets at nospam.web.de Wed Jan 7 08:22:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 14:22:16 +0100 Subject: linked list with cycle structure References: Message-ID: <6sjok8F6dqciU1@mid.uni-berlin.de> David Hl??ik wrote: > dictionary with cycle structure > > Hello guys, > > I have a linked list where *number of elements is unlimited* and > **last element points on random (can be first, last, in middle , > anywhere) element within linked list** - this is important . My goals > is to create an architecture /scheme for **algoritmus which will count > total number of elements** of such linked list. > Yes , maybe it sounds strange, but we need to implement this and i > would be very gladfull for your toughts. Time for homework again? Last time sorting in O(n), now this. How about you try something yourself and show us the results - then we might comment on enhancements or problems. Diez From lihang9999 at gmail.com Wed Jan 7 08:31:14 2009 From: lihang9999 at gmail.com (Li Han) Date: Wed, 7 Jan 2009 05:31:14 -0800 (PST) Subject: image recogniton? References: <854p0cry42.fsf@dozer.localdomain> Message-ID: On 1?7?, ??4?14?, J Kenneth King wrote: > I'm curious as to what application the solution to this problem is > practical for all of its difficulty? Sorry, I oversimplified the question because of my poor english. It is an analog compass whose value we need to read into the computer every second. We use a video camera keep shooting it, and the compass and camera are fixed. -- Li Han From alessiogiovanni.baroni at gmail.com Wed Jan 7 08:42:31 2009 From: alessiogiovanni.baroni at gmail.com (alessiogiovanni.baroni at gmail.com) Date: Wed, 7 Jan 2009 05:42:31 -0800 (PST) Subject: Interpreter & Thread state & Frame structures. Message-ID: Hi to all, there are some fields in the PyInterpreterState and PyThreadState obscures. PyInterpreterState: 1) Why there are the fields *next and *tstate_head? PyThreadState: 1) Why there is the field *next? An object PyFrameObject is a portion of code, with a state. But exactly? Contents of a method/function, or more simply any block indented of code? For example, this code: def foo(s): if s > 0: return True else: return False how much frames are? Thank you! From David Wed Jan 7 09:04:18 2009 From: David (David) Date: Wed, 07 Jan 2009 08:04:18 -0600 Subject: How to get millisec/fractional seconds out of a time object ? References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: On Tue, 6 Jan 2009 13:46:46 -0800, "Chris Rebert" wrote: >The attribute you're looking for is 'microseconds', not 'milliseconds'. > >Cheers, >Chris Thanks Most of the docs are useful but those on timedelta seemed too concise. Dave From bj_666 at gmx.net Wed Jan 7 09:37:09 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 14:37:09 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <6sjt0lF6bhk2U3@mid.uni-berlin.de> On Wed, 07 Jan 2009 03:45:00 -0800, sturlamolden wrote: > On Jan 7, 2:02 am, Steven D'Aprano > wrote: > >> In Python code, there are no references and no dereferencing. > > The why does CPython keep track of reference counts? Show me the *Python* code that does that. Using reference counting for memory management is an implementation detail. It's possible to use other garbage collectors without the need of reference counting. Ciao, Marc 'BlackJack' Rintsch From fake at usenet.no Wed Jan 7 09:45:18 2009 From: fake at usenet.no (Terje) Date: Wed, 07 Jan 2009 15:45:18 +0100 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> Message-ID: <6sjtg5F6gnvfU1@mid.individual.net> Is there a web service/API out there identifying Israel owned software/software companies/web sites/web services? If I am about to buy a piece of software, but don't want to support the Israeli economy, it would have been handy if I could just poll a web service to get the answer. This information should be kept in a database, and be public to the world through a very simple xml API, something along these lines: Request: Some Company Name Response: true Here's one source for this kind of information (I am sure there are plenty others): http://www.science.co.il/SoftwareCo.asp Of course, a web service like this would be equally useful to those who want to support Israeli companies. From almar.klein at gmail.com Wed Jan 7 10:06:08 2009 From: almar.klein at gmail.com (Almar Klein) Date: Wed, 7 Jan 2009 16:06:08 +0100 Subject: image recogniton? In-Reply-To: References: <854p0cry42.fsf@dozer.localdomain> Message-ID: 2009/1/7 Li Han > On 1?7?, ??4?14?, J Kenneth King wrote: > > I'm curious as to what application the solution to this problem is > > practical for all of its difficulty? > Sorry, I oversimplified the question because of my poor english. It is > an analog compass whose value we need to read into the computer every > second. We use a video camera keep shooting it, and the compass and > camera are fixed. > -- > Li Han > > -- > http://mail.python.org/mailman/listinfo/python-list > The compass of the needle looks like a line. Lines can be best detected using second order (Gaussian) derivatives. scipy.ndimage.gaussian_filter provides a filter you can use for that. Then maybe PCA to find the direction of the needle, and you're done! There's probably more to it (there always is), but this might get you started. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Jan 7 10:07:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jan 2009 10:07:18 -0500 Subject: mac osx how to use a specific python environment In-Reply-To: References: Message-ID: <476B6270-EDDE-45E1-96A6-12C4180C2D14@semanchuk.com> On Jan 7, 2009, at 7:27 AM, marco kuhn wrote: > hi, > > I would like to use a specific python environment in a script . > The script is load as a plugin by a program which offer a python api . > The python environment is build in. > > How can I use the standard python environment. > Can i explicit load the env in my python script. Hi Marco, I'm not exactly sure what you want to do. But if you execute `python` at the command line, OS X will launch whatever version of Python it finds first in your PATH. Hope this helps Philip From joe at strout.net Wed Jan 7 10:09:55 2009 From: joe at strout.net (Joe Strout) Date: Wed, 07 Jan 2009 08:09:55 -0700 Subject: image recogniton? In-Reply-To: References: <854p0cry42.fsf@dozer.localdomain> Message-ID: <4964C5C3.602@strout.net> Li Han wrote: > Sorry, I oversimplified the question because of my poor english. It is > an analog compass whose value we need to read into the computer every > second. We use a video camera keep shooting it, and the compass and > camera are fixed. If you have any choice about it, it would be greatly simpler, cheaper, and more effective to throw out the camera and analog compass, and use an electronic compass instead. These are affordable and work quite well provided you keep them level (the same constraint you have with an old-fashioned compass too). You can make some simple interface hardware, or spend a bit more for something with a USB or serial interface built in, like this: Best, - Joe From pruebauno at latinmail.com Wed Jan 7 10:19:49 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Wed, 7 Jan 2009 07:19:49 -0800 (PST) Subject: Any news on when some libraries will be ported to Python 3.0? References: Message-ID: On Jan 7, 3:48?am, "Just Another Victim of the Ambient Morality" wrote: > ? ? Anyway, I'd love to hear some news about any of these things in > particular or even anything in general. ?Am I the only one who's psyched for > this version of Python? > ? ? Thank you... There are many people psyched about 3.0, but also many older farts that have been using Python since 1.0 and have tons of code that already works fine and feel a little bit like the mechanic that has to switch his tools from imperial to metric; it is overall probably for the better but still a pain to adapt everything to the new system. This is open source so you either have to find a way to motivate the authors of the libraries without pissing them off, or you will have to be patient. From djames.suhanko at gmail.com Wed Jan 7 10:21:25 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Wed, 7 Jan 2009 13:21:25 -0200 Subject: Tkinter - problem closing window In-Reply-To: <6sgk44F5qmm8U2@mid.uni-berlin.de> References: <6sgk44F5qmm8U2@mid.uni-berlin.de> Message-ID: Wow, nice! But, with join i can't padding with 0. '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) Then, i has been used: a[i] = "%02d" % int(random.randint(0,60)) I will change int(random.randint(0,60)) for random.randint(0,60), only. Thank you, guys !! ;-) The problem was solved when removed the second "mainloop". I will use the Toplevel instead Tk() again. Thank you for the nice lesson !! On Tue, Jan 6, 2009 at 6:47 AM, Marc 'BlackJack' Rintsch wrote: > On Mon, 05 Jan 2009 12:25:53 -0200, Djames Suhanko wrote: > >> I has a litle program that open another window. When I close de root >> window in quit button, I need clicking 2 times to close. is where the >> problem? >> >> [?] >> >> 17 def gera_seis(self): >> 18 a = {} >> 19 for i in range(6): >> 20 a[i] = "%02d" % int (random.randint(0,60)) >> 21 resultadoA = "%s-%s-%s-%s-%s-%s" % >> (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) >> 22 return resultadoA > > Not the problem but unnecessary complex. `random.randint()` already > returns an int, no need to call `int()` on it. The string formatting > with ``%`` returns strings, so there is no need to call `str()` on the > values. Even if the values where not strings: The '%s' place holder > implies a call to `str()` while formatting. If you put something into a > dictionary with consecutive `int` keys, you might use a list instead. > > All this can be written as a simple one liner:: > > '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) > >> 24 def say_hi(self): >> 25 resultado = self.gera_seis() >> 26 raiz = Tk() > > The problem is here? > >> 27 F = Frame(raiz) >> 28 F.pack() >> 29 hello = Label(F, text=resultado) 30 hello.pack() >> 31 F.mainloop() > > ?and here. > > There is only one `Tk` instance and mainloop allowed per `Tkinter` > application. Otherwise really strange things can happen. Additional > windows have to be created as `Toplevel` instances. > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list > -- Djames Suhanko LinuxUser 158.760 From invalid at invalid Wed Jan 7 10:28:27 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 07 Jan 2009 09:28:27 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> Message-ID: <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> On 2009-01-07, Steve Holden wrote: >> I use multiprocessing to compare more then one set of files. >> >> For comparison each set of files (i.e. Old file1 Vs New file1) >> I create a process, >> >> Process(target=compare, args=(oldFile, newFile)).start() >> >> It takes 61 seconds execution time. >> >> When I do the same comparison without implementing >> multiprocessing, it takes 52 seconds execution time. > My first suggestion would be: show us some code. We aren't > psychic, you know. I am! He's only got one processor, and he's just been bit by Amdahl's law when P<1 and S<1. There you have a perfectly "psychic" answer: an educated guess camoflaged in plausible-sounding but mostly-bullshit buzzwords. A better psychic would have avoided making that one falsifiable statement (he's only got one processor). -- Grant Edwards grante Yow! Hello. Just walk at along and try NOT to think visi.com about your INTESTINES being almost FORTY YARDS LONG!! From tryg.olson at gmail.com Wed Jan 7 10:35:58 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Wed, 7 Jan 2009 07:35:58 -0800 (PST) Subject: How to set a cookie using Cookie Module Message-ID: Hello - This is my first attempt at python cookies. I'm using the Cookie module and trying to set a cookie. Below is my code. The cookie does not get set. What am I doing wrong? print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" print print """ My Page """ c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print If I put javascript code to create a cookie in place of my python cookie code, the javascript cookie gets set. Any tips appreciated! Tryg From james at agentultra.com Wed Jan 7 10:50:56 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 07 Jan 2009 10:50:56 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> Message-ID: <85vdsrqfmn.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 6, 12:24?pm, J Kenneth King wrote: >> Jonathan Gardner writes: >> > On Jan 6, 8:18?am, sturlamolden wrote: >> >> On Jan 6, 4:32 pm, mark wrote: >> >> >> > I want to implement a internal DSL in Python. I would like the syntax >> >> > as human readable as possible. >> >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >> >> I've seen the goto joke). >> >> > This isn't really true. You can, for instance, write a program (in >> > Python) that takes your pseudo-Python and converts it into Python. >> > This is what a number of templating libraries such as Mako do. >> >> Which is not even close to being the same. >> >> Lisp - the program source is also the data format >> >> Python - the program source is a string >> >> I could go on a really long rant about how the two are worlds apart, but >> I'll let Google tell you if you're really interested. > > I get that Lisp is special because you can hack on the reader as it is > reading the file in. This is strongly discouraged behavior, as far as > I know, despite the number of cute hacks you can accomplish with it. It is generally discouraged unless there's a reason for it. > But consider that this really isn't different than having a program > read in the lisp-with-modification source and spitting out pure lisp, > to be read by an honest-to-gosh lisp program later. > > If that's the case, then Lisp and Python really aren't that different > in this regard, except that you don't have the option of modifying the > reader as it reads in the file. I think you are missing the distinction. Lisp expressions are also data structures. A Lisp expression can be passed to functions and macros to be operated on before being executed. When you're writing Lisp source, you're basically looking at the AST on one level and when you start writing macros for your program, you're creating a "DSL" or interface to that AST. Lisp source is eventually expanded to a giant list that is consed by the evaluator (as far as I understand it. I'm just getting into the compiler stuff myself). Consider: (my-func 1 2 3) This is just a list, the "primitive" data-type in Lisp! This piece of "data" can be operated on by other bits of Lisp code because it is just a list as far as Lisp is concerned. In contrast, Python source is a string that needs to be parsed into bytecode which is then run through the interpreter. The AST is completely hidden from the source author. Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. I can only write a python program that parses some other string and generates code that can be run by another interpreter. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. From hv at tbz-pariv.de Wed Jan 7 11:11:14 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 07 Jan 2009 17:11:14 +0100 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: <6sk2h5F6h203U1@mid.individual.net> Sandro Tosi schrieb: > Some basic question I'd like to ask are: > > - what are you using matplotlib for? I use the API to create PNGs from data stored in postgres. Webframework: Django. > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? The API is not good documented. It was very hard for me to understand what was going on the source. > - what would you like to see in a book about matplotlib? How to use the API. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From per.olav.kroka at ericsson.com Wed Jan 7 11:17:52 2009 From: per.olav.kroka at ericsson.com (PerOK) Date: Wed, 7 Jan 2009 17:17:52 +0100 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid Message-ID: os.listdir() keep giving this error: [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid: 'V:\\ETOPOK_Example_MyTestView\\LD_FuncBlocks_013\\cnh1603087_ui_toolkit_mid p\\test/*.*' The V:\\ETOPOK_Example_MyTestView refer to a ClearCase (CC) dynamic view. I have found that MS Visual Studio.Net 2002 and 2003 seems to have this problem with CC. But I am not using any of MS's Visual Studios. (see http://www-01.ibm.com/support/docview.wss?ratlid=cctocbody&rs=984&uid=swg21229572) The seen problem only to appear when some/all caches have forgot about the directory. If I query the directory again (multiple times) listdir() will finally return the content of the directory. The "DOS" command DIR has no problem listing the same directory. Configuration: >>> sys.version '2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]' >>> sys.getwindowsversion() (5, 0, 2195, 2, 'Service Pack 4') >>> sys.platform 'win32' Per OK PS: Why does the listdir() function add '*.*' to the path? PS2: Why does the listdir() function add '/*.*' to the path on windows and not '\\*.*' ? From nick at craig-wood.com Wed Jan 7 11:31:15 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 07 Jan 2009 10:31:15 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: Grant Edwards wrote: > On 2009-01-07, Steve Holden wrote: > > >> I use multiprocessing to compare more then one set of files. > >> > >> For comparison each set of files (i.e. Old file1 Vs New file1) > >> I create a process, > >> > >> Process(target=compare, args=(oldFile, newFile)).start() > >> > >> It takes 61 seconds execution time. > >> > >> When I do the same comparison without implementing > >> multiprocessing, it takes 52 seconds execution time. > > > My first suggestion would be: show us some code. We aren't > > psychic, you know. > > I am! > > He's only got one processor, and he's just been bit by Amdahl's > law when P<1 and S<1. > > There you have a perfectly "psychic" answer: an educated guess > camoflaged in plausible-sounding but mostly-bullshit buzzwords. > A better psychic would have avoided making that one falsifiable > statement (he's only got one processor). ;-) My guess would be that the job is IO bound rather than CPU bound, but that is covered by Amdahl's Law too where P is approx 0, N irrelevant... Being IO bound explains why it takes longer with multiprocessing - it causes more disk seeks to run an IO bound algorithm in parallel than running it sequentially. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jcd at unc.edu Wed Jan 7 11:38:29 2009 From: jcd at unc.edu (J. Cliff Dyer) Date: Wed, 07 Jan 2009 11:38:29 -0500 Subject: Creating new instances of subclasses. Message-ID: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> I want to be able to create an object of a certain subclass, depending on the argument given to the class constructor. I have three fields, and one might need to be a StringField, one an IntegerField, and the last a ListField. But I'd like my class to delegate to the proper subclass automatically, so I can just do: >>> f1 = Field('abc') >>> f2 = Field('123') >>> f3 = Field('D,E,F') >>> f1.data 'abc' >>> f2.data 123 >>> f3.data ['D','E','F'] >>> type(f1) >>> type(f2) >>> type(f3) I've come up with a solution, but I suspect there's something cleaner I can do with the inheritance structure of __new__. I don't like explicitly leapfrogging over Field.__new__ to object.__new__. My attempt is below: def is_list(arg): if ',' in arg: return True else: return False def is_integer(arg): try: int(arg) except ValueError: return False else: return True class Field(object): def __new__(cls, a): if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) def __init__(self, input): super(Field, self).__init__(input) self.data = input class IntegerField(Field): def __new__(cls, a): return object.__new__(cls, a) def __init__(self, s): super(IntegerField, self).__init__(s) self.s = int(self.s) class ListField(Field): def __new__(cls, a): return object.__new__(cls, a) def __init__(self, s): super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): def __new__(cls, a): return object.__new__(cls, a) Is there a cleaner way to do this? The main problem is that Field.__new__ gets in the way of properly constructing the subclasses once I've used it to select the proper subclass in the first place. Cheers, Cliff -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill From davidgshi at googlemail.com Wed Jan 7 11:44:55 2009 From: davidgshi at googlemail.com (davidgshi at googlemail.com) Date: Wed, 7 Jan 2009 08:44:55 -0800 (PST) Subject: Looking for a generic Python script to turn xml into a dataset/array Message-ID: I am looking for a generic Python script to turn xml into a dataset/ array, to be ready to be saved in a .dbf file. The xml contains CDATA section. Regards. David From steve at holdenweb.com Wed Jan 7 11:47:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 11:47:19 -0500 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <6sjtg5F6gnvfU1@mid.individual.net> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: Terje wrote: > Is there a web service/API out there identifying Israel owned > software/software companies/web sites/web services? If I am about to buy > a piece of software, but don't want to support the Israeli economy, it > would have been handy if I could just poll a web service to get the > answer. This information should be kept in a database, and be public to > the world through a very simple xml API, something along these lines: > > Request: > Some Company Name > > Response: > true > > Here's one source for this kind of information (I am sure there are > plenty others): > http://www.science.co.il/SoftwareCo.asp > > Of course, a web service like this would be equally useful to those who > want to support Israeli companies. Words fail me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kay.schluehr at gmx.net Wed Jan 7 12:11:29 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Wed, 7 Jan 2009 09:11:29 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: On 7 Jan., 16:50, J Kenneth King wrote: > Python expressions are not > data types either and hence no macros -- I can't write a python function > that generates python code at compile time. Have you ever considered there are languages providing macros other than Lisp? Macros have nothing to do with homoiconcity. > I can only write a python > program that parses some other string and generates code that can be run > by another interpreter. No, it is the same interpreter and it is also possible to modify python parsers on the fly. This is just not possible with Pythons builtin parser. > > Consider: > > for i in range(0, 100): > ? ? do_something_interesting(i) > > That's a pretty straight forward Python expression, but I can't do > anything with it -- it's not a unit of data, it's a string. > > The distinction is not subtle by any means. From arkanes at gmail.com Wed Jan 7 12:16:48 2009 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 7 Jan 2009 11:16:48 -0600 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <85vdsrqfmn.fsf@dozer.localdomain> References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <4866bea60901070916q33a8f0e6x4fbf625ba68ddea3@mail.gmail.com> On Wed, Jan 7, 2009 at 9:50 AM, J Kenneth King wrote: > Jonathan Gardner writes: > >> On Jan 6, 12:24 pm, J Kenneth King wrote: >>> Jonathan Gardner writes: >>> > On Jan 6, 8:18 am, sturlamolden wrote: >>> >> On Jan 6, 4:32 pm, mark wrote: >>> >>> >> > I want to implement a internal DSL in Python. I would like the syntax >>> >> > as human readable as possible. >>> >>> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >>> >> I've seen the goto joke). >>> >>> > This isn't really true. You can, for instance, write a program (in >>> > Python) that takes your pseudo-Python and converts it into Python. >>> > This is what a number of templating libraries such as Mako do. >>> >>> Which is not even close to being the same. >>> >>> Lisp - the program source is also the data format >>> >>> Python - the program source is a string >>> >>> I could go on a really long rant about how the two are worlds apart, but >>> I'll let Google tell you if you're really interested. >> >> I get that Lisp is special because you can hack on the reader as it is >> reading the file in. This is strongly discouraged behavior, as far as >> I know, despite the number of cute hacks you can accomplish with it. > > It is generally discouraged unless there's a reason for it. > >> But consider that this really isn't different than having a program >> read in the lisp-with-modification source and spitting out pure lisp, >> to be read by an honest-to-gosh lisp program later. >> >> If that's the case, then Lisp and Python really aren't that different >> in this regard, except that you don't have the option of modifying the >> reader as it reads in the file. > > I think you are missing the distinction. > > Lisp expressions are also data structures. A Lisp expression can be > passed to functions and macros to be operated on before being > executed. When you're writing Lisp source, you're basically looking at > the AST on one level and when you start writing macros for your program, > you're creating a "DSL" or interface to that AST. Lisp source is > eventually expanded to a giant list that is consed by the evaluator (as > far as I understand it. I'm just getting into the compiler stuff > myself). > > Consider: > > (my-func 1 2 3) > > This is just a list, the "primitive" data-type in Lisp! This piece of > "data" can be operated on by other bits of Lisp code because it is just > a list as far as Lisp is concerned. > > In contrast, Python source is a string that needs to be parsed into > bytecode which is then run through the interpreter. The AST is > completely hidden from the source author. Python expressions are not > data types either and hence no macros -- I can't write a python function > that generates python code at compile time. I can only write a python > program that parses some other string and generates code that can be run > by another interpreter. > > Consider: > > for i in range(0, 100): > do_something_interesting(i) > > That's a pretty straight forward Python expression, but I can't do > anything with it -- it's not a unit of data, it's a string. > > The distinction is not subtle by any means. Ignoring reader macros for a moment, there is no way in either lisp, ruby, or python to change the syntax that the compiler understands, and the ability to work with your code directly as a data structure (which is what makes lisp macros powerful) isn't directly relevant to the idea of an "internal' DSL. The OP wants a Ruby-style DSL by which he means "something that lets me write words instead of expressions". The ruby syntax is amenable to this, python (and lisp, for that matter) syntax is not and you can't implement that style of internal DSL in those languages. The answer to the OP is "you can't - use Ruby or modify your requirements". From adal.chiriliuc at gmail.com Wed Jan 7 12:24:00 2009 From: adal.chiriliuc at gmail.com (Adal Chiriliuc) Date: Wed, 7 Jan 2009 09:24:00 -0800 (PST) Subject: Is it ok to type check a boolean argument? Message-ID: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Hello, Me and my colleagues are having an discussion about the best way to code a function (more Pythonic). Here is the offending function: def find(field, order): ....if not isinstance(order, bool): ........raise ValueError("order must be a bool") ....order_by = "asc" if order else "desc" ....return _find(field + "+" + order_by) We are not sure what's the best practice here. Should we or should we not check the type of the "order" variable, which should be a bool? In one of our unit-tests we passed the "invalid_order" string as the order argument value. No exception was raised, since the string was evaluated as being True. We know about "Don't look before we jump", but we are not sure how it applies in this case, since we don't get any exception when passing an invalid type argument. This function is not visible to our clients, only internally in our project. It's part of the public interface of a sub-system, so we are not sure either if the fact that it returns an invalid result for a badly type argument it's an API specification break or not. The pro argument was that if a new programmer comes and passes a wrongly typed argument, he will get a silent failure. The cons argument was that there are many functions which could silently fail in this mode, especially those having bool arguments. Should we in general check when doing unit-testing that the methods behave correctly when passed arguments of the wrong type? What do you do in your projects? From gnewsg at gmail.com Wed Jan 7 12:27:37 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 7 Jan 2009 09:27:37 -0800 (PST) Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? References: Message-ID: On 7 Gen, 14:21, Jean-Paul Calderone wrote: > On Tue, 6 Jan 2009 19:01:48 -0800 (PST), Giampaolo Rodola' wrote: > >Hi, > >I'm trying to add TLS/SSL support to pyftpdlib. > >Since various defects have been found in the SSLv2 protocol many FTPS > >servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 > >only and sistematically reject any client attempting to use SSLv2. > >Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 > >connections only? > >If that's not possible can I determine the encryption protocol being > >used *after* that the SSL/TLS handshake took place? > > >I tried to use wrap_socket as follows: > > >self.socket = ssl.wrap_socket(self.socket, , > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?certfile=CERTFILE, > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?server_side=True, > > >ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) > > >...it works if on the client side I use TLSv1 but not if I use SSLv3 > >("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL > >routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is > >raised) > > At the OpenSSL level, you do this by specifying SSLv23_METHOD and then > setting the SSL_OP_NO_SSLv2 flag. ?With pyOpenSSL, you do this by > creating a context with SSLv23_METHOD and then setting SSL_OP_NO_SSLv2 on > it, like so: > > ? ? from OpenSSL.SSL import Context, SSLv23_METHOD, OP_NO_SSLv2 > ? ? context = Context(SSLv23_METHOD) > ? ? context.set_options(OP_NO_SSLv2) > > It seems the ssl module does expose SSLv23_METHOD as PROTOCOL_SSLv23, > but I don't see SSL_OP_NO_SSLv2 anywhere, nor any way to specify any > extra flags. > > Oring PROTOCOL_SSLv3 together with PROTOCOL_TLSv1 is almost certainly > not the right approach, anyway (as you saw with your tests). > > Jean-Paul- Nascondi testo citato > > - Mostra testo citato - These are pretty bad news. I'm going to open a request on the bug tracker hoping that this situation could be solved soon. Thanks for your reply anyway. Sincerely --- Giampaolo http://code.google.com/p/pyftpdlib From e4me4m at gmail.com Wed Jan 7 12:29:06 2009 From: e4me4m at gmail.com (e4me4m at gmail.com) Date: Wed, 7 Jan 2009 09:29:06 -0800 (PST) Subject: Importing modules Message-ID: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Coming from a scripting background where we used to write everything into one script, I'm now going modular with Python. I place related functions in one module, and other functions in other modules. This all works OK, but I'm a bit confused about importing modules from the standard library. For example, say 3 of my 12 modules use os and os.path. Right now, I have import statements in all 3 modules that import both os and os.path. This seems wrong to me. I read the docs and understand that before loading a module that Python is smart enough to look and see if it's already loaded, so there is no performance issue (it would seem), but I was thinking there is probably a way to load all the modules I need in some orderly fashion without having these multiple import statements in my separate modules. Could someone point me to some docs that explain the Python way of loading modules when breaking old, big (everything in one script) into more manageable modular scripts? Thanks, e4m From jakecjacobson at gmail.com Wed Jan 7 12:32:23 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 09:32:23 -0800 (PST) Subject: FTP example going through a FTP Proxy Message-ID: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> Hi, I need to write a simple Python script that I can connect to a FTP server and download files from the server to my local box. I am required to go through a FTP Proxy and I don't see any examples on how to do this. The FTP proxy doesn't require username or password to connect but the FTP server that I am connecting to does. Any examples on how to do this would be greatly appreciated. I am limited to using Python version 2.4.3 on a Linux box. From nospam at forMe.thks Wed Jan 7 12:35:31 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:35:31 -0500 Subject: formatted 'time' data in calculations Message-ID: There seems to be no shortage of information around on how to use the time module, for example to use time.ctime() and push it into strftime and get something nice out the other side, but I haven't found anything helpful in going the other way. That is, given some formatted text describing times - is there something that makes it easy to calculate time differences, or do I have to index my way through the string pulling out characters, converting to integers etc... Data is formatted: t1 = 09:12:10 t2 = 11:22:14 I want to calculate tdiff = t2-t1 Any suggestions? (Thanks for anything you can offer) -Ross From deets at nospam.web.de Wed Jan 7 12:39:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 18:39:16 +0100 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: <6sk7m4F6oe4jU1@mid.uni-berlin.de> e4me4m at gmail.com wrote: > Coming from a scripting background where we used to write everything > into one script, I'm now going modular with Python. I place related > functions in one module, and other functions in other modules. > > This all works OK, but I'm a bit confused about importing modules from > the standard library. For example, say 3 of my 12 modules use os and > os.path. Right now, I have import statements in all 3 modules that > import both os and os.path. This seems wrong to me. > > I read the docs and understand that before loading a module that > Python is smart enough to look and see if it's already loaded, so > there is no performance issue (it would seem), but I was thinking > there is probably a way to load all the modules I need in some orderly > fashion without having these multiple import statements in my separate > modules. > > Could someone point me to some docs that explain the Python way of > loading modules when breaking old, big (everything in one script) into > more manageable modular scripts? There is no way around the multiple imports. Or, at least not a clean way - you *could* stuff things into __builtin__ in one module, effectively making it available globally. But this is a hack at best, and certainly not the way to go. The thing about modularization is that you want single pieces of code that can be read and understood and extended by themselves (even if embedded and useful in - or only in - a larger context). So the seemingly unnecessary imports serve documentation purposes - what is actually needed by the current module. Diez From clp2 at rebertia.com Wed Jan 7 12:40:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 09:40:12 -0800 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid In-Reply-To: References: Message-ID: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> > PS: Why does the listdir() function add '*.*' to the path? Don't know what you're talking about. It doesn't do any globbing or add "*.*" to the path. Its exclusive purpose is to list the contents of a directory, so /in a sense/ it does add "*.*", but then not adding "*.*" would make the function completely useless given its purpose. > PS2: Why does the listdir() function add '/*.*' to the path on windows and > not '\\*.*' ? You can use either directory separator (\ or /) with the Python APIs on Windows. r"c:\WINDOWS\" works just as well as "c:/WINDOWS/". Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tim.arnold at sas.com Wed Jan 7 12:42:45 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Wed, 7 Jan 2009 12:42:45 -0500 Subject: parse/slice/... References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: "rcmn" wrote in message news:51451b8a-6377-45d7-a8c8-54d4cadb2594 at n33g2000pri.googlegroups.com... > I'm not sure how to call it sorry for the subject description. > Here what i'm trying to accomplish. > the script i'm working on, take a submitted list (for line in file) > and generate thread for it. unfortunately winxp has a limit of 500 > thread . So I have to parse/slice the file by chunk of 500 and loop > until the list is done. > I though i would of done it in no time but i can't get started for > some reason. > And i can't find a good way to do it efficiently . Does anyone have > something similar to this. > > thank you Here's how I work on a list a bunch of items (100 by default) ata time: def drain_list(tlist,step=None): if not step: step = 100 j=0 for i in range(step,len(tlist), step): yield tlist[j:i] j = i if j < len(tlist): yield tlist[j:] --Tim From schap at offenbachers.com Wed Jan 7 12:45:12 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 07 Jan 2009 12:45:12 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <4964EA28.4050203@offenbachers.com> Here is how I have done adjustments to time in the past. This is mostly Date related but it may help today = datetime.date.today() wkdiff = datetime.timedelta(weeks=1) daydiff = datetime.timedelta(days=1) startdate=(today-wkdiff)-daydiff this will subtract 1 week and 1 day from today. Stephen Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found > anything helpful in going the other way. > > That is, given some formatted text describing times - is there > something that makes it easy to calculate time differences, or do I > have to index my way through the string pulling out characters, > converting to integers etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) > > -Ross > -- > http://mail.python.org/mailman/listinfo/python-list > > From steve at holdenweb.com Wed Jan 7 12:46:10 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 12:46:10 -0500 Subject: Importing modules In-Reply-To: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: e4me4m at gmail.com wrote: > Coming from a scripting background where we used to write everything > into one script, I'm now going modular with Python. I place related > functions in one module, and other functions in other modules. > > This all works OK, but I'm a bit confused about importing modules from > the standard library. For example, say 3 of my 12 modules use os and > os.path. Right now, I have import statements in all 3 modules that > import both os and os.path. This seems wrong to me. > It isn't. > I read the docs and understand that before loading a module that > Python is smart enough to look and see if it's already loaded, so > there is no performance issue (it would seem), but I was thinking > there is probably a way to load all the modules I need in some orderly > fashion without having these multiple import statements in my separate > modules. > Think of the import statement as giving access to a particular namespace, with the side-effect of loading the code if it's the first import. > Could someone point me to some docs that explain the Python way of > loading modules when breaking old, big (everything in one script) into > more manageable modular scripts? > Import each module into every other module that requires its functionality. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From simonharrison.uk at googlemail.com Wed Jan 7 12:46:22 2009 From: simonharrison.uk at googlemail.com (simonh) Date: Wed, 7 Jan 2009 09:46:22 -0800 (PST) Subject: #python IRC help - my internet provider is banned! Message-ID: Hi. Not sure if anyone can help here, but I'm trying to access #python and have found out that my ISP has a blanket ban (for some reason). Does anyone know how I can contact an operator to join? Thanks. From ptmcg at austin.rr.com Wed Jan 7 12:48:19 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 09:48:19 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: On Jan 7, 11:24?am, Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > First of all, please get used to saying "My colleagues and I..." instead of "Me and my colleagues". My kids still haven't learned this (both are in college!), and it annoys me daily. Sorry for the rant, you were just the final straw, so I'm taking it out on you. The offending part of this function is the argument name "order". If this is a boolean argument, I would assume that True should be ordered data, and False would be unordered or randomly ordered data. The name "order" really does not clue me in that the two choices are "ascending" and "descending", nor is it clear what the mapping is to True and False. You are right, Python's inference of boolean-ness makes it easy for coders to guess wrong as to the argument type and still get a program that emits no exceptions, although possibly doing the opposite of the intended function. I would suggest that in your project, you establish a naming convention for these boolean arguments. The name should be descriptive and assertive, so that the value of True is reasonably intuitive. Instead of "order", perhaps "return_ascending_results" with a default value of True. To further cue your developers that a boolean argument is desired, you could try adding "_flag" to all of your boolean arguments, sort of a Reverse Hungarian Notation. Or another option altogether would be to define some module level constants, like this: ASCENDING_RESULTS = object() DESCENDING_RESULTS = object() def find(field, results_order=ASCENDING_RESULTS): order_by = { ASCENDING_RESULTS : "asc", DESCENDING_RESULTS: "desc"} [results_order] return _find(field + "+" + order_by) If anything other than those two constants is passed for the results_order argument, then a KeyError exception will be raised. (I used a similar technique to this in pyparsing's operatorPrecedence method, in which an argument indicates whether an operator is right- or left-associative.) -- Paul From deets at nospam.web.de Wed Jan 7 12:49:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 18:49:10 +0100 Subject: formatted 'time' data in calculations References: Message-ID: <6sk88mF6qpbhU1@mid.uni-berlin.de> Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found anything > helpful in going the other way. > > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index > my way through the string pulling out characters, converting to integers > etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) The datetime module contains everything you need. Look at the strptime-function that will allow you to parse the above string to an actual datetime.time-object, and the you can subtract these to yield a datetime.timedelta-object. Diez From clp2 at rebertia.com Wed Jan 7 12:50:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 09:50:32 -0800 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <50697b2c0901070950y66a61f84h6b999a7e9056444d@mail.gmail.com> On Wed, Jan 7, 2009 at 9:35 AM, Ross wrote: > There seems to be no shortage of information around on how to use the time > module, for example to use time.ctime() and push it into strftime and get > something nice out the other side, but I haven't found anything helpful in > going the other way. > > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index my > way through the string pulling out characters, converting to integers etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) Use the `datetime` class in the `datetime` module (http://docs.python.org/library/datetime.html). It has a class method .strptime() to parse a string into a `datetime` object. You can then subtract one `datetime` from another to produce a `timedelta` object representing the difference between them. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ptmcg at austin.rr.com Wed Jan 7 12:53:17 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 09:53:17 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> ...and don't worry about a possible performance issue of importing os (or any other module) multiple times - the Python import manager is smart enough to recognize previously imported modules, and wont import them again. If a module uses the os module, then it should import it - that's just it. Another consideration might be that you are breaking up your own program modules too much. For instance, if I had a program in which I were importing urllib in lots of modules, it might indicate that I still have some regrouping to do, and that I could probably gather all of my urllib dependent code into a single place. -- Paul From nospam at forMe.thks Wed Jan 7 12:54:13 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:54:13 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <4964EC45.3040902@forMe.thks> Thanks Chris and Diez for the quick pointers... Very helpful Ross. From nospam at forMe.thks Wed Jan 7 12:54:54 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:54:54 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Thanks Chris and Diez for the quick pointers... Very helpful Ross. From philip at semanchuk.com Wed Jan 7 12:59:34 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jan 2009 12:59:34 -0500 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <82FCAE42-F733-47FC-B411-AB31383DD590@semanchuk.com> On Jan 7, 2009, at 12:24 PM, Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? IMHO you should not. > The pro argument was that if a new programmer comes and passes a > wrongly typed argument, he will get a silent failure. "Wrongly typed" is a matter of opinion. The following values also evaluate to False when converted to bool: None [] () "" {} To me, they're just as false as False is, if you catch my meaning. I would not like to have to convert them to bool to be able to use them when calling your function. Imagine this scenario -- order = read_order_from_preferences_xml_file(default_value = None) # order is now "ascending" or None find(the_field_name, order) It seems logical to pass a string or None in this case without converting them to bool. You might feel more comfortable if the parameter was called "is_ordered", which would at least imply that it is a boolean so that someone unfamiliar with the interface would be less tempted to pass something like the last part of an ORDER BY statement, like "last_name, first_name, age DESC". I can understand your temptation to enforce bool-ness, but you have a very good point about this one function then being different from all of the others that aren't as picky. HTH Philip From ptmcg at austin.rr.com Wed Jan 7 13:00:06 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 10:00:06 -0800 (PST) Subject: Creating new instances of subclasses. References: Message-ID: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> On Jan 7, 10:38?am, "J. Cliff Dyer" wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. ?But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > > >>> f1 = Field('abc') > >>> f2 = Field('123') > >>> f3 = Field('D,E,F') O-O is not always the solution to every problem. Since inheritance is getting in your way, try using a class-level factory method. Instead of using the Field constructor, use a staticmethod of Field, something like: @staticmethod def make_Field(a) if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) and then get rid of all those __new__ methods, too. -- Paul From mwilson at the-wire.com Wed Jan 7 13:06:53 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 07 Jan 2009 13:06:53 -0500 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: Steve Holden wrote: > e4me4m at gmail.com wrote: [ ... ] >> Could someone point me to some docs that explain the Python way of >> loading modules when breaking old, big (everything in one script) into >> more manageable modular scripts? >> > Import each module into every other module that requires its > functionality. True. The O.P. can note one of the miracles of Python: (for an example, I'll pick a library module at random .. image) One can write a module -- myimage.py, say, that imports image, and has some functions that return objects based on calls to image functions. A program that imports myimage can use these objects in all possible ways and not have to import image. It doesn't need to know anything about just where myimage gets its stuff. Importing only strictly needs to be one level deep. (Of course, the programmer needs to know what all those possible ways are. The programmer may have to have read the docs for the image module ... ) Mel. From tjreedy at udel.edu Wed Jan 7 13:11:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 13:11:09 -0500 Subject: Creating new instances of subclasses. In-Reply-To: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> References: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> Message-ID: J. Cliff Dyer wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > >>>> f1 = Field('abc') >>>> f2 = Field('123') >>>> f3 = Field('D,E,F') >>>> f1.data > 'abc' >>>> f2.data > 123 >>>> f3.data > ['D','E','F'] >>>> type(f1) > >>>> type(f2) > >>>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner Make your master class _Field and make Field a factory function that returns the proper subclass instance. The body of Field could be the body of __new__ below. Then dump the __new__ methods. tjr I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. > > Cheers, > Cliff > From mensanator at aol.com Wed Jan 7 13:17:55 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 7 Jan 2009 10:17:55 -0800 (PST) Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: On Jan 7, 8:45?am, Terje wrote: > Is there a web service/API out there identifying Israel owned > software/software companies/web sites/web services? If I am about to buy > a piece of software, but don't want to support the Israeli economy, it > would have been handy if I could just poll a web service to get the > answer. This information should be kept in a database, and be public to > the world through a very simple xml API, something along these lines: > > Request: > Some Company Name > > Response: > true > > Here's one source for this kind of information (I am sure there are > plenty others):http://www.science.co.il/SoftwareCo.asp > > Of course, a web service like this would be equally useful to those who > want to support Israeli companies. Something like that web-service that publishes the names and addresses of doctors who perform abortions so that they can be assassinated? From mildew_spores at hotmail.com Wed Jan 7 13:30:32 2009 From: mildew_spores at hotmail.com (Mildew Spores) Date: Wed, 7 Jan 2009 18:30:32 -0000 Subject: #python IRC help - my internet provider is banned! References: Message-ID: What? Sounds a bit unlikely unless its Virgin.. I'd imagine it might be that your isp needs to get itself off a black list. Brian -- My Hotmail Account mildew_spores at hotmail.com "simonh" wrote in message news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com... > Hi. Not sure if anyone can help here, but I'm trying to access #python > and have found out that my ISP has a blanket ban (for some reason). > Does anyone know how I can contact an operator to join? Thanks. From thedavidfactor at gmail.com Wed Jan 7 13:32:34 2009 From: thedavidfactor at gmail.com (TheDavidFactor) Date: Wed, 7 Jan 2009 10:32:34 -0800 (PST) Subject: socket.error 24: too many open files Message-ID: I'm new to python, but have been writing programs in other languages for about 15 years now. As part of my job I develop applications that interface with Asterisk in various ways. As a way of getting my feet wet I decided to try to rewrite an outbound call script that I have in another language into python. It's a deamon that runs on a linux box and every 15 seconds it checks a MySQL table for new records, if there are any it creates a .call file on the Asterisk server using ssh, it also checks the Asterisk server, again via ssh, for any finished calls and if there are any it reads the .call file and writes the result in to the MySQL table. I did a google search for ssh and a python script that someone had written that wraps up some paramiko calls to make the ssh interaction easier. I'm also using MySQLdb for the MySQL access. It sleeps for 15 seconds then creates an ssh connection the asterisk server, checks the MySQL table, checks the asterisk server, closes the connection and goes back to sleep. After it has run for an hour or so I get the error in the subject when the ssh class tries to create a new socket. I have double checked that it is closing the socket. I don't know what else to check, any suggestions would be much appreciated. From enleverlesX.XmcX at XmclaveauX.com Wed Jan 7 13:44:33 2009 From: enleverlesX.XmcX at XmclaveauX.com (=?utf-8?Q?M=C3=A9ta-MCI_=28MVP=29?=) Date: Wed, 7 Jan 2009 19:44:33 +0100 Subject: =?utf-8?Q?Re:_When_does_python_3.1=EF=BC=8C_3.2_ve?= =?utf-8?Q?rsion_out=EF=BC=9F?= In-Reply-To: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> References: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Message-ID: <4964f93c$0$4079$ba4acef3@news.orange.fr> Hi! The mountain Python-3000 gave birth to a mouse Python-3. You must waiting for Python-4000... @+ MCI From tjreedy at udel.edu Wed Jan 7 13:45:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 13:45:52 -0500 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: Adal Chiriliuc wrote: > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) My opinions: 1. 'order' should be 'a' (the default) or 'd'. True and False by themselves are meaningless. Then the check, if needed, is "if order not in 'ad':". 'up' and 'down' are possible too. 2. Consider renaming _find as find, with two params and do the parameter check there. Except when one is calling a function recursively (repeatedly) with known-good params, wrapping a function with a simple arg check seems like noise to me. > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? I say it should not be a bool. The below illustrates another reason why this is the wrong type. > In one of our unit-tests we passed the "invalid_order" string as the > order argument value. No exception was raised, since the string was > evaluated as being True. If you make 'order' a string, then a bad string input should raise an exception somewhere. I suspect _find could be written to do this if it does not already. > We know about "Don't look before we jump", but we are not sure how it > applies in this case, since we don't get any exception when passing an > invalid type argument. > This function is not visible to our clients, only internally in our > project. It's part of the public interface of a sub-system, so we are > not sure either if the fact that it returns an invalid result for a > badly type argument it's an API specification break or not. > > The pro argument was that if a new programmer comes and passes a > wrongly typed argument, he will get a silent failure. That is bad, but in this case, I see the problem as a slight mis-design. > The cons argument was that there are many functions which could > silently fail in this mode, especially those having bool arguments. Which are rather rare, I think. In the 3.0 builtin functions, sorted's 'reverse' param is the only one. For back compatibility, it actually accepts ints. > Should we in general check when doing unit-testing that the methods > behave correctly when passed arguments of the wrong type? As in 'raise an exception', I think at least one test is good. Terry Jan Reedy From tiktak.hodiki at gmail.com Wed Jan 7 13:49:26 2009 From: tiktak.hodiki at gmail.com (tiktak.hodiki at gmail.com) Date: Wed, 7 Jan 2009 10:49:26 -0800 (PST) Subject: [Mechanize.ClientForm] double reading from urllib2.urlopen Message-ID: Hello, folks! I use mechanize.clientform to parse HTML-forms. I preliminary check response and call response.read().find("..."). But when it's taken to ClientForm.ParseResponse, it can't parse because of response.read() is zero-length text. The problem is that ClientForm.ParseResponse is not taken text of response, only object. Example: import urllib from ClientForm import ParseResponse response = urllib.urlopen("http://yandex.ru") if -1 != response.read().find("foobar"): pass form = ParseResponse(response)[1] <-- there is exception IndexError From simonharrison.uk at googlemail.com Wed Jan 7 13:52:51 2009 From: simonharrison.uk at googlemail.com (simonh) Date: Wed, 7 Jan 2009 10:52:51 -0800 (PST) Subject: #python IRC help - my internet provider is banned! References: Message-ID: On Jan 7, 6:30?pm, "Mildew Spores" wrote: > What? Sounds a bit unlikely unless its Virgin.. > I'd imagine it might be that your isp needs to get itself off a black list. > Brian > > -- > My Hotmail Account > mildew_spo... at hotmail.com > > "simonh" wrote in message > > news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com... > > > Hi. Not sure if anyone can help here, but I'm trying to access #python > > and have found out that my ISP has a blanket ban (for some reason). > > Does anyone know how I can contact an operator to join? Thanks. > > ISP is bethere and client is Chatzilla. From mal at egenix.com Wed Jan 7 14:10:58 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 07 Jan 2009 20:10:58 +0100 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <4964FE42.4090706@egenix.com> On 2009-01-06 22:34, David at bag.python.org wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. If you're only interested in the fractional seconds part, you're much better off with doing: import time start_time = time.time() ... end_time = time.time() delta_seconds = end_time - start_time delta_milliseconds = delta_seconds * 1000 -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 07 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From jakecjacobson at gmail.com Wed Jan 7 14:11:27 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 11:11:27 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> Message-ID: <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> On Jan 7, 12:32?pm, jakecjacobson wrote: > Hi, > > I need to write a simple Python script that I can connect to a FTP > server and download files from the server to my local box. ?I am > required to go through a FTP Proxy and I don't see any examples on how > to do this. ?The FTP proxy doesn't require username or password to > connect but the FTP server that I am connecting to does. > > Any examples on how to do this would be greatly appreciated. ?I am > limited to using Python version 2.4.3 on a Linux box. This is what I have tried so far, import urllib proxies = {'ftp':'ftp://proxy_server:21'} ftp_server = 'ftp.somecompany.com' ftp_port='21' username = 'aaaa' password = 'secretPW' ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + ftp_port data = urllib.urlopen(ftp_string, proxies=proxies) data=urllib.urlopen(req).read() print data I get the following error: Traceback (most recent call last): File "./ftptest.py", line 22, in ? data = urllib.urlopen(ftp_server, proxies=proxies) File "/usr/lib/python2.4/urllib.py", line 82, in urlopen return opener.open(url) File "/usr/lib/python2.4/urllib.py", line 190, in open return getattr(self, name)(url) File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp host, path = splithost(url) File "/usr/lib/python2.4/urllib.py", line 949, in splithost match = _hostprog.match(url) TypeError: expected string or buffer From google at mrabarnett.plus.com Wed Jan 7 14:12:15 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 19:12:15 +0000 Subject: [Mechanize.ClientForm] double reading from urllib2.urlopen In-Reply-To: References: Message-ID: <4964FE8F.3000004@mrabarnett.plus.com> tiktak.hodiki at gmail.com wrote: > Hello, folks! > I use mechanize.clientform to parse HTML-forms. I preliminary check > response and call response.read().find("..."). But when it's taken to > ClientForm.ParseResponse, it can't parse because of response.read() is > zero-length text. The problem is that ClientForm.ParseResponse is not > taken text of response, only object. > > Example: > > import urllib > from ClientForm import ParseResponse > response = urllib.urlopen("http://yandex.ru") > if -1 != response.read().find("foobar"): > pass > form = ParseResponse(response)[1] <-- there is exception IndexError > It might be that read() is consuming the data, so there's none remaining for the second read(). Try: response = urllib.urlopen("http://yandex.ru") text = response.read() if "foobar" in text: # preferred to find() pass form = ParseResponse(text)[1] From stefan_ml at behnel.de Wed Jan 7 14:22:36 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Jan 2009 20:22:36 +0100 Subject: Any news on when some libraries will be ported to Python 3.0? In-Reply-To: References: Message-ID: <496500fd$0$32663$9b4e6d93@newsspool2.arcor-online.net> Just Another Victim of the Ambient Morality wrote: > I'm excited to use Python 3.0 (foolishly, it's the only Python > interpreter I have on my system) but there are no libraries for it beyond > the kitchen sink. Personally, a good start would be Beautiful Soup and > Mechanize. I could also use DB. > Has there been any word on Beautiful Soup? At least for new code, you can use lxml instead. Being written (mostly) in Cython, it compiles and works in Py3. Stefan From Scott.Daniels at Acm.Org Wed Jan 7 14:23:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 11:23:32 -0800 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found anything > helpful in going the other way. As to a paucity of conversion formatting, there is no magic way to take everyone's way of putting date and time information in text and convert it to unambiguous format, in part because there are too many different and contradictory formats. When I write dates, I know what I intended; when I read dates, I guess what the author intended. Have you read the entire time module document? If so, which functions in that module take strings as arguments? > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index > my way through the string pulling out characters, converting to integers > etc... > > Data is formatted: > t1 = 09:12:10 > t2 = 11:22:14 > I want to calculate tdiff = t2-t1 Do you do any work yourself? Show us your attempts. This looks like a trivial exercise. It seems that for less than four times the effort of asking your question you might have found the answer. Perhaps I am being too cranky this morning. --Scott David Daniels Scott.Daniels at Acm.Org From excord80 at gmail.com Wed Jan 7 14:31:23 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 11:31:23 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? Message-ID: Does Python work with Tk 8.5? I'm manually installing my own Python 2.6.1 (separate from my system's Python 2.5.2), and am about to install my own Tcl/Tk 8.5 but am unsure how to make them talk to eachother. Should I install Tk first? If I put Tk into my home directory (under "~/opt" most likely), is there some configure option I need to pass Python to tell it where to find my Tk? Also, I see that Python comes with Tix. Was Tix supposed to be something to make up for what was lacking in Tk prior to its 8.5 release? Is Tix here to stay, or has it been eclipsed by what comes with Tk 8.5 OOTB? From esnow at verio.net Wed Jan 7 14:39:13 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:39:13 -0800 (PST) Subject: del behavior Message-ID: I was reading in the documentation about __del__ and have a couple of questions. Here is what I was looking at: http://docs.python.org/reference/datamodel.html#object.__del__ What is globals referring to in the following text from that reference page? "Starting with version 1.5, Python guarantees that globals whose name begins with a single underscore are deleted from their module before other globals are deleted; if no other references to such globals exist, this may help in assuring that imported modules are still available at the time when the __del__() method is called." Thus those with an _ get deleted before everything else. This is not referring to members of my objects is it, such that those members starting with _ get deleted first? I suppose that would delete __del__ before it would get called so I assume that is not the case. But I want to be sure about that behavior and exactly what globals is. Is globals meaning the contents of "globals" or something else. I ask because sometimes some words get used for varied meanings. From ahill21programming at gmail.com Wed Jan 7 14:41:58 2009 From: ahill21programming at gmail.com (Aaron Hill) Date: Wed, 7 Jan 2009 12:41:58 -0700 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <1e38ae490901071141y72840b9u6ba0054f699034a0@mail.gmail.com> I personally use epoch time since its absolute. I have a simple time clock app that uses this method, from that it is easy to convert into human date: [code] def OnButtonIn(self,evt): 'create time stamp with ID/action' 'print to the rightFrame text' if self.punchedIn: print "Already punched in cannot punch again" else: seconds = time.time() current = time.localtime(seconds) day = time.localtime() # time string can have characters 0..9, -, period, or space timeday = time.strftime('%H:%M-%m.%d.%y', day) formatday = time.strftime('%c', day) self.ClockIntext = seconds #self.text = "Clock in: " + self.text self.punchIn.SetValue(formatday) self.punchedIn = True self.punchedOut = False def OnButtonOut(self,evt): if self.punchedOut: print "Already punched out!" else: 'create time stamp with ID/action' 'print to the rightFrame text' 'write to time sheet' seconds = time.time() current = time.localtime(seconds) day = time.localtime() # time string can have characters 0..9, -, period, or space timeday = time.strftime('%H:%M-%m.%d.%y', day) formatday = time.strftime('%c', day) self.ClockOuttext = seconds self.punchOut.SetValue(formatday) self.punchedIn = False self.punchedOut = True 'create a file and write the table to it' file = open('timesheet.txt', 'a') file.write(str(self.ClockIntext)) file.write('\t') file.write(str(self.ClockOuttext)) file.write('\n') file.close() return None def OnButtonCalc(self,event): 'open the time sheet and calculate the total time' file = open('timesheet.txt','r') lines = file.readlines() time1 = '' time2 = '' self.hours = 0.000 for punch in lines: for x in punch: if(len(x) <= 0): self.hours = self.hours else: if x != '\t' and x!= '\n': time1 = time1 + x elif x == '\t': time2 = time1 time1 = '' elif x == '\n': self.hours = self.hours + abs(((float(time2)-float(time1))/60)/60) time2 = '' time1 = '' self.total.SetValue('%2f' % self.hours) [/code] Oops wrong person, sorry about that. This time it should go to the mailing list Aaron Hill -------------- next part -------------- An HTML attachment was scrubbed... URL: From esnow at verio.net Wed Jan 7 14:42:43 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:42:43 -0800 (PST) Subject: del behavior 2 Message-ID: I was reading in the documentation about __del__ and have a couple of questions. Here is what I was looking at: http://docs.python.org/reference/datamodel.html#object.__del__ My second question is about the following: "It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits." I understand that and have seen it too. That's fine. But how do any of you deal with things that are left open because you did not get a chance to close them? How do you clean up after the fact? Do you simply keep track externally the things that need to be cleaned up if __del__ doesn't get a chance? Any ideas? Thanks -eric From clp2 at rebertia.com Wed Jan 7 14:48:06 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 11:48:06 -0800 Subject: del behavior In-Reply-To: References: Message-ID: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > What is globals referring to in the following text from that reference > page? Globals are variables that have toplevel module scope. Basically, any assignments, function definitions, or class definitions with no indentation from the left margin will create a global variable. If you can get at the variable by appending something of the form "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in function, then it's a global. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From esnow at verio.net Wed Jan 7 14:55:28 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:55:28 -0800 (PST) Subject: del behavior References: Message-ID: On Jan 7, 12:48?pm, "Chris Rebert" wrote: > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > > I was reading in the documentation about __del__ and have a couple of > > questions. ?Here is what I was looking at: > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > What is globals referring to in the following text from that reference > > page? > > Globals are variables that have toplevel module scope. Basically, any > assignments, function definitions, or class definitions with no > indentation from the left margin will create a global variable. If you > can get at the variable by appending something of the form > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > function, then it's a global. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Perfect! that is kind of what I thought. Thanks. So any such in any module every variable in memory that starts with an underscore will be deleted before the rest. Then this does not affect the order in which variables are deleted in instances of my classes, and thus all my class and instance variables (including methods) are available when the __del__ of the class instance is called? -eric From google at mrabarnett.plus.com Wed Jan 7 14:55:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 19:55:40 +0000 Subject: del behavior 2 In-Reply-To: References: Message-ID: <496508BC.7080607@mrabarnett.plus.com> Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks > There's the 'with' statement and try...finally. From clp2 at rebertia.com Wed Jan 7 14:57:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 11:57:00 -0800 Subject: del behavior 2 In-Reply-To: References: Message-ID: <50697b2c0901071157n12aa1b1fi92baef5792d268ec@mail.gmail.com> On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks As you point out, __del__ is not a reliable way to free limited resources. Instead, one generally includes logic to explicitly free the resources. This is generally done using try-finally or the `with` statement. Example: def mess_with_file(f): try: #fiddle with the file finally: f.close() #guarantee that the file gets closed def mess_with_other_file(filename): with open(filename) as f: #do stuff with file x = None #the file has now been closed, and it'll be closed even if an exception gets raised #the "context handler" (see PEP 343) for the `file` type guarantees this for us Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From esnow at verio.net Wed Jan 7 14:57:41 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:57:41 -0800 (PST) Subject: del behavior References: Message-ID: On Jan 7, 12:55?pm, Eric Snow wrote: > On Jan 7, 12:48?pm, "Chris Rebert" wrote: > > > > > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > > > I was reading in the documentation about __del__ and have a couple of > > > questions. ?Here is what I was looking at: > > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > > What is globals referring to in the following text from that reference > > > page? > > > Globals are variables that have toplevel module scope. Basically, any > > assignments, function definitions, or class definitions with no > > indentation from the left margin will create a global variable. If you > > can get at the variable by appending something of the form > > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > > function, then it's a global. > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Perfect! ?that is kind of what I thought. ?Thanks. > > So any such in any module every variable in memory that starts with an > underscore will be deleted before the rest. ?Then this does not affect > the order in which variables are deleted in instances of my classes, > and thus all my class and instance variables (including methods) are > available when the __del__ of the class instance is called? > > -eric Typo. Perfect! that is kind of what I thought. Thanks. So in any module every such variable in memory that starts with an underscore will be deleted before the rest. Then this does not affect the order in which variables are deleted in instances of my classes, and thus all my class and instance variables (including methods) are available when the __del__ of the class instance is called? -eric From martin at v.loewis.de Wed Jan 7 14:59:20 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 20:59:20 +0100 Subject: del behavior 2 In-Reply-To: References: Message-ID: <49650999$0$22775$9b622d9e@news.freenet.de> > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks You should try to write you program so that any kind of process exit will not need any cleanup. For many kinds of things, this will work automatically on most file systems. For example, file handles and network connections get automatically closed - so you don't absolutely have to close them if your program exits abnormally. Likewise, database connections will shut down properly, and windows will close just fine. What kind of thing do you have that remains open even after the process terminates? Regards, Martin From esnow at verio.net Wed Jan 7 15:03:36 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 12:03:36 -0800 (PST) Subject: del behavior 2 References: Message-ID: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> On Jan 7, 12:57?pm, "Chris Rebert" wrote: > On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > > I was reading in the documentation about __del__ and have a couple of > > questions. ?Here is what I was looking at: > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > My second question is about the following: > > > "It is not guaranteed that __del__() methods are called for objects > > that still exist when the interpreter exits." > > > I understand that and have seen it too. ?That's fine. ?But how do any > > of you deal with things that are left open because you did not get a > > chance to close them? ?How do you clean up after the fact? ?Do you > > simply keep track externally the things that need to be cleaned up if > > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > As you point out, __del__ is not a reliable way to free limited > resources. Instead, one generally includes logic to explicitly free > the resources. This is generally done using try-finally or the `with` > statement. > > Example: > > def mess_with_file(f): > ? ? try: > ? ? ? ? #fiddle with the file > ? ? finally: > ? ? ? ? f.close() #guarantee that the file gets closed > > def mess_with_other_file(filename): > ? ? with open(filename) as f: > ? ? ? ? #do stuff with file > ? ? x = None #the file has now been closed, and it'll be closed even > if an exception gets raised > ? ? #the "context handler" (see PEP 343) for the `file` type > guarantees this for us > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanks for the responses. What I mean is when a python process is interrupted and does not get a chance to clean everything up then what is a good way to do so? For instance, I have a script that uses child ptys to facilitate ssh connections (I'm using pxssh). When I ^C the python process I am left with the child processes running and the ssh connections open. Naturally I run out of ttys if this happens too much, which I have had happen. So if python does not get a chance to take care of those, what is a good way to do so? Does a try/finally or a with statement address that? Thanks! -eric From esnow at verio.net Wed Jan 7 15:04:35 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 12:04:35 -0800 (PST) Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <52a6e7f5-5a0e-4760-8afc-a73da250aee0@40g2000prx.googlegroups.com> On Jan 7, 1:03?pm, Eric Snow wrote: > On Jan 7, 12:57?pm, "Chris Rebert" wrote: > > > > > On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > > > I was reading in the documentation about __del__ and have a couple of > > > questions. ?Here is what I was looking at: > > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > > My second question is about the following: > > > > "It is not guaranteed that __del__() methods are called for objects > > > that still exist when the interpreter exits." > > > > I understand that and have seen it too. ?That's fine. ?But how do any > > > of you deal with things that are left open because you did not get a > > > chance to close them? ?How do you clean up after the fact? ?Do you > > > simply keep track externally the things that need to be cleaned up if > > > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > > As you point out, __del__ is not a reliable way to free limited > > resources. Instead, one generally includes logic to explicitly free > > the resources. This is generally done using try-finally or the `with` > > statement. > > > Example: > > > def mess_with_file(f): > > ? ? try: > > ? ? ? ? #fiddle with the file > > ? ? finally: > > ? ? ? ? f.close() #guarantee that the file gets closed > > > def mess_with_other_file(filename): > > ? ? with open(filename) as f: > > ? ? ? ? #do stuff with file > > ? ? x = None #the file has now been closed, and it'll be closed even > > if an exception gets raised > > ? ? #the "context handler" (see PEP 343) for the `file` type > > guarantees this for us > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Thanks for the responses. ?What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? ?For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). ?When I ^C the > python process I am left with the child processes running and the ssh > connections open. ?Naturally I run out of ttys if this happens too > much, which I have had happen. ?So if python does not get a chance to > take care of those, what is a good way to do so? ?Does a try/finally > or a with statement address that? ?Thanks! > > -eric pxssh uses pexpect which uses pty.fork From clp2 at rebertia.com Wed Jan 7 15:05:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 12:05:30 -0800 Subject: del behavior In-Reply-To: References: Message-ID: <50697b2c0901071205t67ed8b9bna7d39859ea907141@mail.gmail.com> On Wed, Jan 7, 2009 at 11:55 AM, Eric Snow wrote: > On Jan 7, 12:48 pm, "Chris Rebert" wrote: >> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >> > I was reading in the documentation about __del__ and have a couple of >> > questions. Here is what I was looking at: >> >> >http://docs.python.org/reference/datamodel.html#object.__del__ >> >> > What is globals referring to in the following text from that reference >> > page? >> >> Globals are variables that have toplevel module scope. Basically, any >> assignments, function definitions, or class definitions with no >> indentation from the left margin will create a global variable. If you >> can get at the variable by appending something of the form >> "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in >> function, then it's a global. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana...http://rebertia.com > > Perfect! that is kind of what I thought. Thanks. > > So any such in any module every variable in memory that starts with an > underscore will be deleted before the rest. Then this does not affect > the order in which variables are deleted in instances of my classes, > and thus all my class and instance variables (including methods) are > available when the __del__ of the class instance is called? Indeed. The underscore special-casing only applies to modules. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From google at mrabarnett.plus.com Wed Jan 7 15:05:33 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 20:05:33 +0000 Subject: del behavior In-Reply-To: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> References: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> Message-ID: <49650B0D.1080707@mrabarnett.plus.com> Chris Rebert wrote: > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >> I was reading in the documentation about __del__ and have a couple of >> questions. Here is what I was looking at: >> >> http://docs.python.org/reference/datamodel.html#object.__del__ >> >> What is globals referring to in the following text from that reference >> page? > > Globals are variables that have toplevel module scope. Basically, any > assignments, function definitions, or class definitions with no > indentation from the left margin will create a global variable. If you > can get at the variable by appending something of the form > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > function, then it's a global. > Actually, the amount of indentation doesn't matter. What matters is whether it's within a 'def' or 'class' statement or not. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 7 15:15:20 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 07 Jan 2009 21:15:20 +0100 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <49651b04$0$24804$426a74cc@news.free.fr> Adal Chiriliuc a ?crit : > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? This kind of typechecking is usually considered bad practice in Python, but well, practicallity beats purity - and as a matter of fact, if you refer to list.sort, passing a non-integer value as the 'reverse' argument raises a TypeError... This being said, I can only concur with other posters here about the very poor naming. As far as I'm concerned, I'd either keep the argument as a boolean but rename it "ascending" (and use a default True value), or keep the 'order' name but then accept 'asc' and 'desc' as values ('asc' being the default). My 2 cents... From clp2 at rebertia.com Wed Jan 7 15:15:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 12:15:21 -0800 Subject: del behavior In-Reply-To: <49650B0D.1080707@mrabarnett.plus.com> References: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> <49650B0D.1080707@mrabarnett.plus.com> Message-ID: <50697b2c0901071215n78803232of12e274ea96f3e7a@mail.gmail.com> On Wed, Jan 7, 2009 at 12:05 PM, MRAB wrote: > Chris Rebert wrote: >> >> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >>> >>> I was reading in the documentation about __del__ and have a couple of >>> questions. Here is what I was looking at: >>> >>> http://docs.python.org/reference/datamodel.html#object.__del__ >>> >>> What is globals referring to in the following text from that reference >>> page? >> >> Globals are variables that have toplevel module scope. Basically, any >> assignments, function definitions, or class definitions with no >> indentation from the left margin will create a global variable. If you >> can get at the variable by appending something of the form >> "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in >> function, then it's a global. >> > Actually, the amount of indentation doesn't matter. What matters is whether > it's within a 'def' or 'class' statement or not. Yes, but those do require you *to indent* (though so do while & if for that matter); I just couldn't seem to come up with a better description of the rule at the time. But you are correct and yours is a much better description of the rule. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rdcollum at gmail.com Wed Jan 7 15:31:09 2009 From: rdcollum at gmail.com (Roger) Date: Wed, 7 Jan 2009 12:31:09 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: <330a26a3-860a-4c0e-82a3-831417472310@j39g2000yqn.googlegroups.com> On Jan 7, 2:31?pm, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? > > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? I'm curious about this too. If no one responds please let us know how it goes. From lkcl at lkcl.net Wed Jan 7 15:40:23 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 7 Jan 2009 20:40:23 +0000 Subject: compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Sat, Jan 3, 2009 at 9:22 PM, Luke Kenneth Casson Leighton wrote: > hey, has anyone investigated compiling python2.5 using winegcc, under wine? some people might find this kind of thing amusing. it's considered in very obtuse circles to be "progress"... :) lkcl at gonzalez:/mnt/src/python2.5-2.5.2/Lib$ ../build/python -v Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] # installing zipimport hook import zipimport # builtin # installed zipimport hook 'import site' failed; traceback: ImportError: No module named site Python 2.5.2 (r252:60911, Jan 7 2009, 20:33:53) [gcc] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import site fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored [....] [....] [....] import sre_compile # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.py fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.pyc import _sre # builtin import sre_constants # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_constants.py # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_constants.pyc import sre_parse # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_parse.py # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_parse.pyc Traceback (most recent call last): File "", line 1, in File "site.py", line 415, in main() File "site.py", line 406, in main aliasmbcs() File "site.py", line 356, in aliasmbcs import locale, codecs File "Z:\mnt\src\python2.5-2.5.2\Lib\locale.py", line 167, in import re, operator File "Z:\mnt\src\python2.5-2.5.2\Lib\re.py", line 223, in _pattern_type = type(sre_compile.compile("", 0)) File "Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.py", line 530, in compile groupindex, indexgroup OverflowError: signed integer is less than minimum >>> From bdesth.quelquechose at free.quelquepart.fr Wed Jan 7 15:41:55 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 07 Jan 2009 21:41:55 +0100 Subject: Creating new instances of subclasses. In-Reply-To: References: Message-ID: <49652140$0$29486$426a34cc@news.free.fr> J. Cliff Dyer a ?crit : > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > >>>> f1 = Field('abc') >>>> f2 = Field('123') >>>> f3 = Field('D,E,F') >>>> f1.data > 'abc' >>>> f2.data > 123 >>>> f3.data > ['D','E','F'] >>>> type(f1) > >>>> type(f2) > >>>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. Not only that, but the base class should know nothing of its subclasses. As Paul suggested, a better solution would be to make Field a factory function (and rename the Field class to BaseField). Also and FWIW, since your Field subclasses are responsible for doing the conversion, you could as well use this to find out the concrete class to use for a given value, ie (not tested): class Field(object): __classes = [] __default = None @classmethod def register(cls, subclass, is_default=False): if is_default: if cls.__default is not None: raise WhateverError("only one default subclass, thanks") cls.__default = subclass cls.__classes.append(subclass) def __new__(cls, value): for subclass in cls.__classes: try: return subclass(value) except (TypeError, ValueError): continue if cls.__default is not None: return cls.__default(value) raise ValueError("no appropriate subclass for '%s'" % value) class BaseField(object): # common code here class FloatField(BaseField): def __init__(self, value): self.value = float(value) Field.register(FloatField) class ListField(BaseField): def __init__(self, value): if "," in value: self.value = value.split(",") raise ValueError("could not convert '%s' to a list" % value) Field.register(ListField) class IntegerField(BaseField): def __init__(self, value): self.value = int(value) Field.register(IntegerField) class StringField(self, value): def __init__(self, value): self.value = str(value) Field.register(StringField, is_default=True) Now this may just be overkill for your needs - I don't have enough context to know !-) From rolf.oltmans at gmail.com Wed Jan 7 15:42:21 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Wed, 7 Jan 2009 12:42:21 -0800 (PST) Subject: How to store passwords? Message-ID: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> I'm writing a program in which I will ask users to enter user name and password once only. It's a console based program that will run on Windows XP. Actually, I'm trying to provide the similar functionality as "Remember me" thing in browsers. For that, I will need to store user name and passwords on the disk. I don't have a background in Crypto so how do you suggest I do that? What algorithms shall I be using? Moreover, I cannot use a whole library to do that due to certain issues. However, I can use like 1--2 files that will be shipped along with the main script. Any ideas? Any help will be really appreciated. Thanks. From james at agentultra.com Wed Jan 7 15:50:10 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 07 Jan 2009 15:50:10 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <85ocyivo1p.fsf@dozer.localdomain> Kay Schluehr writes: > On 7 Jan., 16:50, J Kenneth King wrote: > >> Python expressions are not >> data types either and hence no macros -- I can't write a python function >> that generates python code at compile time. > > Have you ever considered there are languages providing macros other > than Lisp? Of course. > Macros have nothing to do with homoiconcity. Not directly, no. >> I can only write a python >> program that parses some other string and generates code that can be run >> by another interpreter. > > No, it is the same interpreter and it is also possible to modify > python parsers on the fly. This is just not possible with Pythons > builtin parser. PyPy is probably the best bet when/if it gets finished. > > >> >> Consider: >> >> for i in range(0, 100): >> ? ? do_something_interesting(i) >> >> That's a pretty straight forward Python expression, but I can't do >> anything with it -- it's not a unit of data, it's a string. >> >> The distinction is not subtle by any means. From daniel.a.esch at gmail.com Wed Jan 7 15:53:13 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Wed, 7 Jan 2009 15:53:13 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102103915.GJ28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Wait a sec... I think I get this... In essence, the implication of immutability for Python is that there is only one "parrot", one "spam,"in fact one anything. (This seems like it must hold for data primitives - does it hold for complex objects as well? It seems it must...) In addition there is only one 1, and one 2 etc. We may or may not have realized that string in a memory address to which variable names can be bound, but should we do so, there is only one "parrot" Python, is in fact, a Platonic programming language. Weird. If I've got this right, worth chewing on.... On 1/2/09, Derek Martin wrote: > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > Fortunately, unlike the murky world of philosophy, Python (AIUI) > > simplifies this question by simply declaring that yes, in the case > > of mutable objects, we may say that we are still referring to the > > same object although we've changed it, and no, in the case of > > immutable objects, we may not, and must exchange it if we want a > > different "value" (a word too fraught with ambiguity in this context > > to use unquoted!). > > That's sort of true; it would seem to be more accurate to say that > whenever a name is assigned to an object and subsequently reassigned, > the name no longer is associated with the original object. In the > case of mutable objects, the object can be changed by performing an > assignment of *part* of the object through its original name, i.e. > strings may be mutable, but the following code still produces two > different objects: > > a = 'hello' > a = 'goodbye' > > The first object so created is orphaned; it's been given the Russian > non-person treatment. It still exists, but the authorities (i.e. the > python interpreter) don't acknowledge it and provide the rest of the > world no way to communicate with it, and eventually it is reaped by > the garbage collector. :) > > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. > > That is, in what I'll call "normal" computer languages, a variable > name is thought of as the address of a bin where some data is stored, > and the name is inexorably tied to that bin. You can change what's in > the bin, but the name you gave the bin always points to the same bin. > This tends to be conceptually true even if it might technically not be > true in a given implementation of a language. > > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, > where the bin is a Python object which contains specific data at the > time of assignment. A second assignment of that name doesn't change > what's in the original bin; it actually (probably) first creates a new > bin, then removes the name from the original bin and assigns it to > the new one. Intuitively, it's a bit like saying your kitchen table > is no longer a kitchen table, and now the thing where you wash your > dishes is a kitchen table. It doesn't really make a lot of sense > (whether or not it's so for good reason), and it makes describing the > assignment model necessarily convoluted, whereas the "named bins" > model from the majority of other languages people are likely to have > been exposed to is simple and sensible. > > It's small wonder that neophytes try to cram Python behaviors into > terms and computing concepts they already understand from learning > other languages, and that they fail to do so. What's mystifying is > that when Pythonistas reply to their messages, they universally seem > confused at how this could possibly happen, and often enough actually > seem offended (or at least offensive) when it inevitably does happen... > > -- > Derek D. Martin > http://www.pizzashack.org/ > GPG Key ID: 0x81CFE75D > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From casey.mcginty at gmail.com Wed Jan 7 15:53:56 2009 From: casey.mcginty at gmail.com (Casey McGinty) Date: Wed, 7 Jan 2009 10:53:56 -1000 Subject: Free place to host python files? In-Reply-To: <4948E346.7090009@mattnordhoff.com> References: <7f3baaf3-6116-4a7a-8181-6f88b0e44950@w24g2000prd.googlegroups.com> <47c890dc0812161625o76f5c7e6lb8809b99f6962d32@mail.gmail.com> <4948E346.7090009@mattnordhoff.com> Message-ID: Check out nearlyfreespeech.net for a free account. You could store hundreds of scripts on there for about 12 cents a year. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sbassi at clubdelarazon.org Wed Jan 7 15:55:29 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 7 Jan 2009 18:55:29 -0200 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <9e2f512b0901071255q523ada4p84a1b4e72e68003a@mail.gmail.com> On Wed, Jan 7, 2009 at 6:42 PM, Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on In general you don't store the password, but a "hash" of it. Then when the user logs-in, you hash it and compare the result with the stored hash. About hash, use sha, look here: http://docs.python.org/library/hashlib.html#module-hashlib > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in I don't understand how this is supposed to work. "Remember me" in browser doesn't store passwords. > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. The library I pointed out before is built-in. Best, SB. -- Sebasti?n Bassi. Diplomado en Ciencia y Tecnolog?a. Book: Python for bioinformatics. http://tinyurl.com/biopython Vendo isla: http://www.genesdigitales.com/isla What's new in Python 3: http://tinyurl.com/5cd89r Curso Biologia molecular para programadores: http://tinyurl.com/2vv8w6 From jakecjacobson at gmail.com Wed Jan 7 15:56:58 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 12:56:58 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> Message-ID: <341b04d3-10be-4a29-b170-fd6ec3a2be51@k8g2000yqn.googlegroups.com> On Jan 7, 2:11?pm, jakecjacobson wrote: > On Jan 7, 12:32?pm, jakecjacobson wrote: > > > Hi, > > > I need to write a simple Python script that I can connect to a FTP > > server and download files from the server to my local box. ?I am > > required to go through a FTP Proxy and I don't see any examples on how > > to do this. ?The FTP proxy doesn't require username or password to > > connect but the FTP server that I am connecting to does. > > > Any examples on how to do this would be greatly appreciated. ?I am > > limited to using Python version 2.4.3 on a Linux box. > > This is what I have tried so far, > > import urllib > > proxies = {'ftp':'ftp://proxy_server:21'} > ftp_server = 'ftp.somecompany.com' > ftp_port='21' > username = 'aaaa' > password = 'secretPW' > > ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + > ftp_port > > data = urllib.urlopen(ftp_string, proxies=proxies) > > data=urllib.urlopen(req).read() > > print data > > I get the following error: > > Traceback (most recent call last): > ? File "./ftptest.py", line 22, in ? > ? ? data = urllib.urlopen(ftp_server, proxies=proxies) > ? File "/usr/lib/python2.4/urllib.py", line 82, in urlopen > ? ? return opener.open(url) > ? File "/usr/lib/python2.4/urllib.py", line 190, in open > ? ? return getattr(self, name)(url) > ? File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp > ? ? host, path = splithost(url) > ? File "/usr/lib/python2.4/urllib.py", line 949, in splithost > ? ? match = _hostprog.match(url) > TypeError: expected string or buffer I might be getting closer. Now I am getting "I/O error(ftp error): (111, 'Connection refused')" error with the following code: import urllib2 proxies = {'ftp':'ftp://proxy_server:21'} ftp_server = 'ftp.somecompany.com' ftp_port='21' username = 'aaaa' password = 'secretPW' password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() top_level_url = ftp_server password_mgr.add_password(None, top_level_url, username, password) proxy_support = urllib2.ProxyHandler(proxies) handler = urllib2.HTTPBasicAuthHandler(password_mgr) opener = urllib2.build_opener(proxy_support) opener = urllib2.build_opener(handler) a_url = 'ftp://' + ftp_server + ':' + ftp_port + '/' print a_url try: data = opener.open(a_url) print data except IOError, (errno, strerror): print "I/O error(%s): %s" % (errno, strerror) From floob.spam at gmail.com Wed Jan 7 16:00:48 2009 From: floob.spam at gmail.com (floob) Date: Wed, 7 Jan 2009 13:00:48 -0800 (PST) Subject: Printed Documentation Message-ID: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> I have been searching for a way to print the official Python documentation into some kind of book (for my own uses). I don't really care if it's printed on newspaper and bound with elmer's glue ... any way I can get relatively recent _official documentation_ in print form will do. I'm on the go a lot, and can't read for long periods of time on LCD screens anyhow (so having a laptop is not my solution). Until eBook readers grow up a bit, I'm stuck trying to print the documentation that I REALLY need to read and absorb. Lulu.com is an option, but it would cost something around $100 US before shipping to get everything printed. Also, I would have to split up some larger documents into Volumes, which I'd rather not have to do. Has anyone tried this before? Is the documentation already available in print? Thanks, drfloob From rolf.oltmans at gmail.com Wed Jan 7 16:06:07 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Wed, 7 Jan 2009 13:06:07 -0800 (PST) Subject: How to store passwords? References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> On Jan 8, 1:55 am, "Sebastian Bassi" wrote: > In general you don't store the password, but a "hash" of it. Then when > the user logs-in, you hash it and compare the result with the stored > hash. > About hash, use sha, look here:http://docs.python.org/library/hashlib.html#module-hashlib But the thing is that I will ask the user for user name and password only once i.e. when they start the application for the first time. After that, I'm not supposed to ask the user name and password again. So in this scenario, if I store a hash on the disk I cannot retrieve plain-text string back from my hash as I've to send user name and password to the server in plain-text. From jstroud at mbi.ucla.edu Wed Jan 7 16:10:54 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 13:10:54 -0800 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? What algorithms shall I be > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. There is a pure python implementation of blowfish out there. Google will help you. I can't remember which, if any, types of block chaining it supports. In some cases, it is important to use a block chaining protocol, but for passwords with high entropy (ie good passwords), block chaining is not really necessary. 256 bit Blowfish or AES are adequate for storage of sensitive passwords. You would be well advised to read a manual like Schneier before you use cryptography for sensitive applications. Pitfalls exist even when you use a strong algorithm and think you know what you are doing. Stay away from stream ciphers. They are easy to screw up. Don't attempt to use DES, etc., for this either, they are not secure enough. Don't pretend that you can invent your own cipher either just in case the thought might cross your mind. Google "adacrypt" for some hilarity in this area. If you check out sf.passerby.net and download the source, you will see a pure python module in there called jenncrypt which can help with buffering and has minimal fileIO type emulation for block ciphers, which you will appreciate when you try to use your block cipher for plaintexts of irregular sizes. James From jstroud at mbi.ucla.edu Wed Jan 7 16:12:43 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 13:12:43 -0800 Subject: How to store passwords? In-Reply-To: References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: James Stroud wrote: > Oltmans wrote: >> I'm writing a program in which I will ask users to enter user name and >> password once only. It's a console based program that will run on >> Windows XP. Actually, I'm trying to provide the similar functionality >> as "Remember me" thing in browsers. For that, I will need to store >> user name and passwords on the disk. I don't have a background in >> Crypto so how do you suggest I do that? What algorithms shall I be >> using? Moreover, I cannot use a whole library to do that due to >> certain issues. However, I can use like 1--2 files that will be >> shipped along with the main script. Any ideas? Any help will be really >> appreciated. Thanks. > > There is a pure python implementation of blowfish out there. Google will > help you. I can't remember which, if any, types of block chaining it > supports. In some cases, it is important to use a block chaining > protocol, but for passwords with high entropy (ie good passwords), block > chaining is not really necessary. > > 256 bit Blowfish or AES are adequate for storage of sensitive passwords. > You would be well advised to read a manual like Schneier before you use > cryptography for sensitive applications. Pitfalls exist even when you > use a strong algorithm and think you know what you are doing. Stay away > from stream ciphers. They are easy to screw up. > > Don't attempt to use DES, etc., for this either, they are not secure > enough. Don't pretend that you can invent your own cipher either just in > case the thought might cross your mind. Google "adacrypt" for some > hilarity in this area. > > If you check out sf.passerby.net and download the source, you will see a > pure python module in there called jenncrypt which can help with > buffering and has minimal fileIO type emulation for block ciphers, which > you will appreciate when you try to use your block cipher for plaintexts > of irregular sizes. > > James Before anyone jumps me, I just realized the point is authentication. Use a hash as others have suggested. James From sjmachin at lexicon.net Wed Jan 7 16:14:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 7 Jan 2009 13:14:17 -0800 (PST) Subject: formatted 'time' data in calculations References: Message-ID: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> On Jan 8, 6:23?am, Scott David Daniels wrote: > Ross wrote: > > There seems to be no shortage of information around on how to use the > > time module, for example to use time.ctime() and push it into strftime > > and get something nice out the other side, but I haven't found anything > > helpful in going the other way. > > As to a paucity of conversion formatting, there is no magic way to take > everyone's way of putting date and time information in text and convert > it to unambiguous format, in part because there are too many different > and contradictory formats. ?When I write dates, I know what I intended; > when I read dates, I guess what the author intended. > > Have you read the entire time module document? ?If so, which functions > in that module take strings as arguments? > > > That is, given some formatted text describing times - is there something > > that makes it easy to calculate time differences, or do I have to index > > my way through the string pulling out characters, converting to integers > > etc... > > > Data is formatted: > > ? ?t1 = 09:12:10 > > ? ?t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Do you do any work yourself? ?Show us your attempts. ?This looks like > a trivial exercise. ?It seems that for less than four times the effort > of asking your question you might have found the answer. > > Perhaps I am being too cranky this morning. Indeed. Be not cranky at clueless bludgers and cargo-cultists lest they rise high in the serried ranks of IT management and remember your name inclusive-or the net-nannies sally forth and wallop thee with a balloon on a stick. To the OP: Your Lordship did not specify whether output should be expressed in hours and a fraction, or in hours, minutes, and seconds. So that the eminent one may avoid having to make a decision in public, I humbly submit answers to both possibilities: >>> t1 = "09:12:10" >>> t2 = "11:22:14" >>> sum((a - b) / c for (a, b, c) in zip(map(int, t2.split(":")), map(int,t1.split(":")), (1., 60., 3600.))) 2.1677777777777778 >>> def tdiff(t1, t2): ... h, m, s = [a - b for (a, b) in zip(map(int, t2.split(":")), map (int,t1.split(":")))] ... if s < 0: ... s += 60 ... m -= 1 ... if m < 0: ... m += 60 ... h -= 1 ... return h, m, s ... >>> tdiff(t1, t2) (2, 10, 4) >>> tdiff('09:12:10', '10:11:09') (0, 58, 59) HTH, John From pavlovevidence at gmail.com Wed Jan 7 16:29:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jan 2009 13:29:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> On Jan 6, 9:32?am, mark wrote: > I want to implement a internal DSL in Python. I would like the syntax > as human readable as possible. This means no disturbing '.;()\' > characters. I like to have the power of the hosting language as well. > Thats why I want to build it as an internal DSL and NOT as a external > DSL. > > I want the DSL as human readable as possible: > > open_browser > > navigate_to 'www.openstreetmap.org'website > > search 'Von-Gumppenberg-Strasse, Schmiechen' > > verify search_result > > zoom in In the Python grammar, there are no non-trivial situations where two expressions can be separated by whitespace and not punctuation. (The trivial exception is string concatentation.) String constants like 'www.openstreetmap.org' and identifiers like open_browser are expressions, and if you try to separate them with whitespace you get a syntax error. So you can't make an internal DSL like this that uses Python's built- in grammar. You'd have to hack the parser or settle for an external preprocessor. > Martin Fowler recommends "Method Chaining" to build internal DSLs: > > ?Browser("http://www.openstreetmap.org/") \ > ? ? ? ? .search("Von-Gumppenberg-Strasse, Schmiechen") \ > ? ? ? ? .zoom_in() > ?<<< > > I guess that it is possible to argue that this means the same. > Nevertheless I do not like all the parentheses and punctuation > necessary to satisfy the Python interpreter. > > The reason why I need this is that I want to have non technical people > review the files written in the DSL. > > I already know that there are parser frameworks available but I want > to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and > whatnot). > > How would one approach this in Python? Do I need to build a custom > loader which compiles *.dsl files to *.pyc files? Is it possible to > switch between the custom DSL and the standard Python interpreter? I don't know specifically what you mean my "custom loader", or "switching between the custom DSL and the standard Python interpreter". However, the gist of it seems to be that you want to be able to write files in your DSL that can be imported just like a regular Python module. Yes, that can be done. See PEP 302, Import Hooks: http://www.python.org/dev/peps/pep-0302/ Python's standard importer looks for files with *.py, *.pyc, *.pyd, or *.so extensions. You could write an importer that looks for *.dsl files, and, instead of loading it as a Python file, invokes your DSL parser. Carl Banks From bj_666 at gmx.net Wed Jan 7 16:30:52 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 21:30:52 GMT Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <6skl8cF6bhk2U4@mid.uni-berlin.de> On Wed, 07 Jan 2009 12:03:36 -0800, Eric Snow wrote: > Thanks for the responses. What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? Well, if it doesn't get a chance then it doesn't get a chance. ;-) > For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). When I ^C the > python process I am left with the child processes running and the ssh > connections open. Naturally I run out of ttys if this happens too much, > which I have had happen. So if python does not get a chance to take > care of those, what is a good way to do so? Does a try/finally or a > with statement address that? Thanks! If you clean up the mess in the ``finally`` branch: yes. + raises a `KeyboardInterrupt`. Ciao, Marc 'BlackJack' Rintsch From BrooklineTom at gmail.com Wed Jan 7 16:34:23 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Wed, 7 Jan 2009 13:34:23 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> <782c68cf-ce9d-4f32-8ea3-6d57257b1b54@x16g2000prn.googlegroups.com> Message-ID: <63505b1a-6cbf-48b6-953e-38c25c34dea0@n41g2000yqh.googlegroups.com> On Jan 2, 7:04 pm, John Machin wrote: > On Jan 3, 2:01 am, brooklineTom wrote: > > > > My point was that however the original XLS files were created or > acquired, the first step in your solution involves converting the XLS > file to "XML Spreadsheet" format, which requires a copy of Excel on a > Windows box. Many people start with an XLS file, no Excel and no > Windows box, no COM, and users who can't be relied on to open a file > and save it in the right format with the right name and extension. True enough. I develop on a WinXP box and have Excel. I just used it. > BTW, did you consider opening the XLS files with OpenOffice.org's Calc > and saving it in their default ods format (chunks of XML in a zip > file)? No. As I said, I have Excel. > > 3. The largest file I used was about 228M, > > Is that the XLS file or the XML file? That's the xml file size. I just *love* file-bloat, don't you? :-) > > > > > I knew that I needed only > > a small subset of the xlrd behavior, and I concluded (perhaps > > incorrectly) that it would be easier to roll my own parser than find, > > extract, and then port (to my own framework) the corresponding parts > > of xlrd. > > Possibly incorrectly. If approached at the time, I would have said: > (a) if desperate to DIY: > (a1) ignore any code for old Excel versions (self.biff_version < 80) > (a2) ignore any code for extracting formatting info > (self.formatting_info) > (a3) find the Sheet.put_cell* methods in sheet.py e.g. > > def put_cell(self, rowx, colx, ctype, value, xf_index): > > ignore the xf_index arg and subvert them to your own needs instead of > filling up a big rectangular arena with data > > (b) if not really so desperate, talk to me about implementing an > option in xlrd where callers can specify a callback to be used instead > of the Sheet.put_cell* methods > > (c) What is all this "port to my own framework" caper anyway? If you > need to extract data from a database, do you rummage in their code > libraries and port the relevant bits to your own framework? I'm sure xlrd is fine, I wasn't any way suggesting that any "improvements" are needed. I was just explaining what I did. > > > > "Crack"? It's not the Enigma code. It's not even rot13. Spreadsheet > XML tells you the type (String, Boolean, ...). xlrd tells you the type > (XL_CELL_TEXT, XL_CELL_BOOLEAN, ...). Sure, once you've sorted through the excess MS-specific stuff, dealt with the runs of empty cells, and so on. I needed to write an exception file, containing the original spreadsheet entries that failed, so that our curators could find and fix (or delete) them. Thus, I already had to do row-by-row handling of the input, I had to catch and handle exceptions, I had to know and remember enough about the original SS format/layout to replicate it in the exception file, and so on. > I think so. Thanks. You didn't directly address the "steep learning > curve" question, but you explained enough of where you came from. > > It's a matter of "horses for courses". I guess some people might > regard (xml.dom, xml.dom.minidom, DIY "pullparser") as having a > slightly non-horizontal learning curve :-) *LOL* Yes. Sadly, I had already climbed the dom/minidom/pullparser curve for all the other stuff I have to do. In the space I work in, xml handling is pervasive enough that I already have all that stuff "in my hands" anyway. I wonder if the OP ever read any of this.... :-) Thx, Tom From steve at holdenweb.com Wed Jan 7 16:35:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 16:35:53 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Dan Esch wrote: > Wait a sec... > > I think I get this... > > In essence, the implication of immutability for Python is that there is > only one "parrot", one "spam,"in fact one anything. (This seems like it > must hold for data primitives - does it hold for complex objects as > well? It seems it must...) In addition there is only one 1, and one 2 > etc. We may or may not have realized that string in a memory address to > which variable names can be bound, but should we do so, there is only > one "parrot" > > Python, is in fact, a Platonic programming language. Weird. If I've > got this right, worth chewing on.... > 'Fraid not. Certain immutables are cached by the interpreter, but most are not. >>> s1 = "a" + "b" + "c" >>> n = 12345 >>> s2 = "ab" + chr(99) >>> m = 2469 * 5 >>> s1 == s2 True >>> s1 is s2 False >>> n == m True >>> n is m False >>> id(s1), id(s2), id(n), id(m) (2146661888, 2146661792, 14453620, 14453584) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From excord80 at gmail.com Wed Jan 7 16:39:00 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 13:39:00 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> On Jan 7, 4:00?pm, floob wrote: > I have been searching for a way to print the official Python > documentation into some kind of book (for my own uses). ?I don't > really care if it's printed on newspaper and bound with elmer's > glue ... any way I can get relatively recent _official documentation_ > in print form will do. > > I'm on the go a lot, and can't read for long periods of time on LCD > screens anyhow (so having a laptop is not my solution). ?Until eBook > readers grow up a bit, I'm stuck trying to print the documentation > that I REALLY need to read and absorb. > > Lulu.com is an option, but it would cost something around $100 US > before shipping to get everything printed. ?Also, I would have to > split up some larger documents into Volumes, which I'd rather not have > to do. > > Has anyone tried this before? ?Is the documentation already available > in print? > > Thanks, > > drfloob http://docs.python.org/download.html I'd try taking the pdf to my local print shop and ask how much they'd charge. Local print shops have options for various bindings too. From bj_666 at gmx.net Wed Jan 7 16:52:10 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 21:52:10 GMT Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: <6skmgaF6bhk2U5@mid.uni-berlin.de> On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: > On Jan 7, 8:45?am, Terje wrote: >> Is there a web service/API out there identifying Israel owned >> software/software companies/web sites/web services? If I am about to >> buy a piece of software, but don't want to support the Israeli economy, >> it would have been handy if I could just poll a web service to get the >> answer. This information should be kept in a database, and be public to >> the world through a very simple xml API, something along these lines: >> >> Request: >> Some Company Name >> >> Response: >> true >> >> Here's one source for this kind of information (I am sure there are >> plenty others):http://www.science.co.il/SoftwareCo.asp >> >> Of course, a web service like this would be equally useful to those who >> want to support Israeli companies. > > Something like that web-service that publishes the names and addresses > of doctors who perform abortions so that they can be assassinated? Hey, it's about boycott, not killing them. Applied to the doctors example: You go to someone without a doctors degree, a clothes hanger and some experience? ;-) Ciao, Marc 'BlackJack' Rintsch From google at mrabarnett.plus.com Wed Jan 7 17:00:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 22:00:12 +0000 Subject: How to store passwords? In-Reply-To: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> Message-ID: <496525EC.7080409@mrabarnett.plus.com> Oltmans wrote: > On Jan 8, 1:55 am, "Sebastian Bassi" > wrote: > >> In general you don't store the password, but a "hash" of it. Then >> when the user logs-in, you hash it and compare the result with the >> stored hash. About hash, use sha, look >> here:http://docs.python.org/library/hashlib.html#module-hashlib > > But the thing is that I will ask the user for user name and password > only once i.e. when they start the application for the first time. > After that, I'm not supposed to ask the user name and password again. > So in this scenario, if I store a hash on the disk I cannot retrieve > plain-text string back from my hash as I've to send user name and > password to the server in plain-text. > Is the application itself password-protected? If not, then there's no point in encrypting the username and password for the server in a file because anyone could just run the application after the first time and use it to access the server. From daniel.a.esch at gmail.com Wed Jan 7 17:06:07 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Wed, 7 Jan 2009 17:06:07 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Okay, thanks... Still trying to wrap my fragile little VBA-corrupted brain around names, namespaces, and objects. Progress is being made. For me, the naive idea of variable ==> label for bin has been hard to get past simply because someone in the the back of my head is screaming, "Wait, if the VARIABLE doesn't point to a memory address, (somewhere down the implementation stack) whatinthehell does??" Further reading clarifies: For object X, id(X) is an immutable attribute reference that can ultimately be bound to a memory address (he said, blithely skipping over several layers of architecture...) So, okay, now I can relax. To oversimplify (told you VBA warped my mind) everything in python is an object (at some level). At minimum, all objects have an identity-- id(X), a type which subclasses and extends it from object, and some content, the nature of which depends on the object type. Once I got my head around the idea that there was something that was a fixed point of reference for the object, nevermind what, then I could relax and get on with get on with getting my head around names and namespaces. Thanks for listening to me ramble. On 1/7/09, Steve Holden wrote: > > Dan Esch wrote: > > Wait a sec... > > > > I think I get this... > > > > In essence, the implication of immutability for Python is that there is > > only one "parrot", one "spam,"in fact one anything. (This seems like it > > must hold for data primitives - does it hold for complex objects as > > well? It seems it must...) In addition there is only one 1, and one 2 > > etc. We may or may not have realized that string in a memory address to > > which variable names can be bound, but should we do so, there is only > > one "parrot" > > > > Python, is in fact, a Platonic programming language. Weird. If I've > > got this right, worth chewing on.... > > > 'Fraid not. Certain immutables are cached by the interpreter, but most > are not. > > >>> s1 = "a" + "b" + "c" > >>> n = 12345 > >>> s2 = "ab" + chr(99) > >>> m = 2469 * 5 > >>> s1 == s2 > True > >>> s1 is s2 > False > >>> n == m > True > >>> n is m > False > >>> id(s1), id(s2), id(n), id(m) > (2146661888, 2146661792, 14453620, 14453584) > >>> > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at hlacik.eu Wed Jan 7 17:13:57 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Wed, 7 Jan 2009 23:13:57 +0100 Subject: linked list with cycle structure In-Reply-To: <6sjok8F6dqciU1@mid.uni-berlin.de> References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: Hi, so okay, i will create a helping set, where i will be adding elements ID, when element ID will be allready in my helping set i will stop and count number of elements in helping set. This is how long my cycled linked list is. But what if i have another condition , and that is *i can use only helping memory with constant size* ? This means i am not able to create any set and adding elements there. I need to have a constant size variables . This is complication a complication for me. Thanks in advance! David On Wed, Jan 7, 2009 at 2:22 PM, Diez B. Roggisch wrote: > > David Hl??ik wrote: > > > dictionary with cycle structure > > > > Hello guys, > > > > I have a linked list where *number of elements is unlimited* and > > **last element points on random (can be first, last, in middle , > > anywhere) element within linked list** - this is important . My goals > > is to create an architecture /scheme for **algoritmus which will count > > total number of elements** of such linked list. > > Yes , maybe it sounds strange, but we need to implement this and i > > would be very gladfull for your toughts. > > Time for homework again? Last time sorting in O(n), now this. How about you > try something yourself and show us the results - then we might comment on > enhancements or problems. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list From floob.spam at gmail.com Wed Jan 7 17:14:31 2009 From: floob.spam at gmail.com (floob) Date: Wed, 7 Jan 2009 14:14:31 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> Message-ID: <2727789e-b644-4403-83a5-59b96a7317e0@s9g2000prg.googlegroups.com> On Jan 7, 1:39?pm, excord80 wrote: > On Jan 7, 4:00?pm, floob wrote: > > > > > I have been searching for a way to print the official Python > > documentation into some kind of book (for my own uses). ?I don't > > really care if it's printed on newspaper and bound with elmer's > > glue ... any way I can get relatively recent _official documentation_ > > in print form will do. > > > I'm on the go a lot, and can't read for long periods of time on LCD > > screens anyhow (so having a laptop is not my solution). ?Until eBook > > readers grow up a bit, I'm stuck trying to print the documentation > > that I REALLY need to read and absorb. > > > Lulu.com is an option, but it would cost something around $100 US > > before shipping to get everything printed. ?Also, I would have to > > split up some larger documents into Volumes, which I'd rather not have > > to do. > > > Has anyone tried this before? ?Is the documentation already available > > in print? > > > Thanks, > > > drfloob > > http://docs.python.org/download.html > > I'd try taking the pdf to my local print shop and ask how much they'd > charge. > > Local print shops have options for various bindings too. I tried 7 print shops in my area. Five refused to print single-run books (minimum quantity of 100). Of the 2 that WOULD print a single set of books, the cheapest was $250.00 (spiral bound, no covers, 8.5" x 11", cheapest paper available). That quote included roughly: the tutorial, library, reference, distutils, extending, and c-api pdfs. For that price, I could buy an eBook reader with plans to throw it away when I was done! Off on a bit of a tangent: if the Python Software Foundation could strike a deal with a charitable printing company, users could probably get a slight discount on buying printed documentation, and I'd bet Python's organization could get a small percentage of each sale. I believe ubuntu is doing something like this with Lulu.com. It'd be nice to support Python while doing something I was going to do on my own, anyhow. From martin at v.loewis.de Wed Jan 7 17:23:14 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 23:23:14 +0100 Subject: del behavior 2 In-Reply-To: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <49652b53$0$25195$9b622d9e@news.freenet.de> > Thanks for the responses. What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). When I ^C the > python process I am left with the child processes running and the ssh > connections open. Naturally I run out of ttys if this happens too > much, which I have had happen. So if python does not get a chance to > take care of those, what is a good way to do so? Does a try/finally > or a with statement address that? Thanks! That's strange. When the parent process terminates, the tty master should get closed, causing the slave to be closed as well, in addition to sending a SIGHUP signal to the child, which ssh should interpret as terminating. Perhaps the problem is that the master socket *doesn't* get closed? I see that pexpect closes all file descriptors in the child before invoking exec. Could it be that you are starting addition child processes which inherit the master socket? Regards, Martin From benjamin.kaplan at case.edu Wed Jan 7 17:25:25 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 17:25:25 -0500 Subject: del behavior In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 2:39 PM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > What is globals referring to in the following text from that reference > page? > > "Starting with version 1.5, Python guarantees that globals whose name > begins with a single underscore are deleted from their module before > other globals are deleted; if no other references to such globals > exist, this may help in assuring that imported modules are still > available at the time when the __del__() method is called." > > Thus those with an _ get deleted before everything else. This is not > referring to members of my objects is it, such that those members > starting with _ get deleted first? I suppose that would delete > __del__ before it would get called so I assume that is not the case. > But I want to be sure about that behavior and exactly what globals > is. Is globals meaning the contents of "globals" or something else. > I ask because sometimes some words get used for varied meanings. Names with a *single* leading underscore are, by convention, "private". Names with double leading and trailing underscores are for special methods. The sort-of private methods are the ones that get deleted first, not the special methods. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From David Wed Jan 7 17:46:06 2009 From: David (David) Date: Wed, 07 Jan 2009 16:46:06 -0600 Subject: How do you write to the printer ? Message-ID: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Can find nothing in the on-line docs or a book. Groping in the dark I attempted : script24 import io io.open('stdprn','w') # accepted stdprn.write('hello printer') # fails < stdprn is not defined > Thanks to all responders I'm inching up on the snake. Dave WB3DWE From Scott.Daniels at Acm.Org Wed Jan 7 17:51:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 14:51:22 -0800 Subject: formatted 'time' data in calculations In-Reply-To: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> References: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> Message-ID: John Machin wrote: > On Jan 8, 6:23 am, Scott David Daniels wrote: >> ...some stuff perhaps too cranky... >> Have you read the entire time module document? If so, which functions >> in that module take strings as arguments?.... then even more cranky stuff... > > Indeed. Be not cranky at clueless bludgers and cargo-cultists .... And since others are pointing you at datetime and othert places, I'll just point out that I _did_, in fact, answer your question: (1) The answer to the oblique clue is strptime. (2) Only mktime takes a time_struct and returns a non-string. import time struct_time1 = time.strptime('14:11-01.07.09', '%H:%M-%m.%d.%y') struct_time2 = time.strptime('14:18-01.07.09', '%H:%M-%m.%d.%y') since_epoch1 = time.mktime(struct_time1) since_epoch2 = time.mktime(struct_time2) print int((since_epoch2 - since_epoch1) / 10) Hmmmm.... where have I seen that number before? A slightly less cranky kid because of the mollifying influence of the ever-diplomatic John Machin. --Scott David Daniels Scott.Daniels at Acm.Org From excord80 at gmail.com Wed Jan 7 17:53:40 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 14:53:40 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> <2727789e-b644-4403-83a5-59b96a7317e0@s9g2000prg.googlegroups.com> Message-ID: On Jan 7, 5:14?pm, floob wrote: > On Jan 7, 1:39?pm, excord80 wrote: > > > > > On Jan 7, 4:00?pm, floob wrote: > > > > I have been searching for a way to print the official Python > > > documentation into some kind of book (for my own uses). > > > > http://docs.python.org/download.html > > > I'd try taking the pdf to my local print shop and ask how much they'd > > charge. > > > Local print shops have options for various bindings too. > > I tried 7 print shops in my area. ?Five refused to print single-run > books (minimum quantity of 100). ?Of the 2 that WOULD print a single > set of books, the cheapest was $250.00 (spiral bound, no covers, 8.5" > x 11", cheapest paper available). Oh, heck. In that case, I'd just take the pdf on a flash drive to my local Fedex Kinkos and use their self-server printing machines and print it myself. If you can get it to print double-sided, it should cost half as much. Then just 3-hole-punch what you print out and put it into a 3-ring binder. I've done this myself in the past for docs that I wanted to have on my shelf and it works great. From ken.dambrosio at segway.com Wed Jan 7 17:54:03 2009 From: ken.dambrosio at segway.com (Ken D'Ambrosio) Date: Wed, 7 Jan 2009 17:54:03 -0500 (EST) Subject: Regular Expressions... Message-ID: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" the re module. For example, I'd like to do a few things (I'm going to use phone numbers, 'cause that's what I'm currently dealing with): 12345678900 -- How would I: - Get just the area code? - Get just the seven-digit number? In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have that stuff in $1 and $2, respectively. But the Python stuff simply isn't clicking for me. If anyone could supply concrete examples of how to do the problem, above, that would be terrific. Thanks! -Ken From fakeaddress at nowhere.org Wed Jan 7 17:54:04 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 07 Jan 2009 14:54:04 -0800 Subject: socket send help In-Reply-To: References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: Gabriel Genellina wrote: > James Mills escribi?: >> Bryan Olson wrote: >>>> I thought a firewall would block an attempt to bind to any routeable >>>> address, but not to localhost. So using INADDR_ANY would be rejected. >> >> No. >> >>> My understanding is that firewalls block network traffic, not system >>> calls. >> >> This is correct. Firewalls (real firewalls) can only act on incoming >> and outgoing traffic on the IP level. > > That's true for hardware firewalls (those found in a router, by > example). They can at most analyze traffic at the application layer but > have no idea of the applications (processes) behind. > A "software firewall" may react not just to traffic but to *who* is > doing that; it may block *processes* when they try to bind/listen to any > port, even before any packet is sent or received. See > http://www.securityfocus.com/infocus/1839 > (One may argue whether those are *real* firewalls or not, but that's > their common name...) Even if one's 'firewall' product is one of "the rather useless ones that merely hook socket calls" (in the words of the linked article), I still don't see failing a bind() to INADDR_ANY while allowing a bind() to 127.0.0.1. INADDR_ANY means all available adapters. If some physical network adapter should be unavailable while the loopback is allowed, fine; passing INADDR_ANY should work and bind to the loopback adapter. > (Also note that I'm far for being an expert on these topics) Sure. I was mostly just making a couple points because at one time they confused me. Python's socket.bind() treats the empty string as INADDR_ANY, which means all available adapters. It's a fine address parameter for bind(), and ought to work at least as well as any. The time to bind() to localhost is when we specifically do not want to be available on an external network adapter. Now don't get me started on the vagaries of passing INADDR_ANY to connect(). -- --Bryan From prologic at shortcircuit.net.au Wed Jan 7 18:02:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 09:02:14 +1000 Subject: Regular Expressions... In-Reply-To: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> References: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Message-ID: On Thu, Jan 8, 2009 at 8:54 AM, Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" > the re module. For example, I'd like to do a few things (I'm going to use > phone numbers, 'cause that's what I'm currently dealing with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like > m/^1(...)(.......)/; > and then I'd have that stuff in $1 and $2, respectively. But the Python > stuff > simply isn't clicking for me. If anyone could supply concrete examples of > how to do the problem, above, that would be terrific. There is nothing so special or different about Python's re module than say over any other language's regular expression library or capabilities. You should be able to use pretty much the same things, however: 1. Why can't you just use ordinary string manipulation her e? One of Python's strengths is in string manipulation. Consider: >>> s = "1234567890" >>> area, number = s[:2], s[2:] >>> area '12' >>> number '34567890' cheers James From mensanator at aol.com Wed Jan 7 18:02:58 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 7 Jan 2009 15:02:58 -0800 (PST) Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> Message-ID: <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> On Jan 7, 3:52?pm, Marc 'BlackJack' Rintsch wrote: > On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: > > On Jan 7, 8:45?am, Terje wrote: > >> Is there a web service/API out there identifying Israel owned > >> software/software companies/web sites/web services? If I am about to > >> buy a piece of software, but don't want to support the Israeli economy, > >> it would have been handy if I could just poll a web service to get the > >> answer. This information should be kept in a database, and be public to > >> the world through a very simple xml API, something along these lines: > > >> Request: > >> Some Company Name > > >> Response: > >> true > > >> Here's one source for this kind of information (I am sure there are > >> plenty others):http://www.science.co.il/SoftwareCo.asp > > >> Of course, a web service like this would be equally useful to those who > >> want to support Israeli companies. > > > Something like that web-service that publishes the names and addresses > > of doctors who perform abortions so that they can be assassinated? > > Hey, it's about boycott, not killing them. ? One person's boycott is another person's murder. It's like they say, guns don't kill people, people kill people. If guns are banned, then databases of such information should be banned also. > Applied to the doctors > example: ?You go to someone without a doctors degree, a clothes hanger > and some experience? ?;-) > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch- Hide quoted text - > > - Show quoted text - From rurpy at yahoo.com Wed Jan 7 18:06:47 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 7 Jan 2009 15:06:47 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> Message-ID: <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> On Jan 6, 9:20 pm, Mark Wooding wrote: > ru... at yahoo.com wrote: > > Is not the proper term "aliasing"? Perhaps Python "variables" should > > be called "alises". > > No. The proper term is most definitely `binding': see SICP, for > example. (Wikipedia has a link to the full text.) I thought you were objecting to Python's use of the term "binding" when you wrote: > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. in response to someone talking about "...all those who use the term \"name binding\" instead of variable assignment...". From Scott.Daniels at Acm.Org Wed Jan 7 18:17:19 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 15:17:19 -0800 Subject: How do you write to the printer ? In-Reply-To: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: David Lemper wrote: > Can find nothing in the on-line docs or a book. > Groping in the dark I attempted : > > script24 > import io > io.open('stdprn','w') # accepted Here's your first mistake: you need to get the result of that call. Try: stdprn = io.open('stdprn', 'w') > stdprn.write('hello printer') # fails < stdprn is not defined > Note that (1) You may have just created a file named stdprn. (2) You need to close that file bwhen you are done. (3) A final end-of-line is traditional. (4) You could give us a clue about your operating environment. (To wit: os, version, python version) A printer is nothing Python has or controls, it is a standard thing for a computer system, so details about your computing environment are necessary in order to give you good advice. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Wed Jan 7 18:24:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 18:24:06 -0500 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> Message-ID: Mensanator wrote: > On Jan 7, 3:52 pm, Marc 'BlackJack' Rintsch wrote: >> On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: >>> On Jan 7, 8:45 am, Terje wrote: >>>> Is there a web service/API out there identifying Israel owned >>>> software/software companies/web sites/web services? If I am about to >>>> buy a piece of software, but don't want to support the Israeli economy, >>>> it would have been handy if I could just poll a web service to get the >>>> answer. This information should be kept in a database, and be public to >>>> the world through a very simple xml API, something along these lines: >>>> Request: >>>> Some Company Name >>>> Response: >>>> true >>>> Here's one source for this kind of information (I am sure there are >>>> plenty others):http://www.science.co.il/SoftwareCo.asp >>>> Of course, a web service like this would be equally useful to those who >>>> want to support Israeli companies. >>> Something like that web-service that publishes the names and addresses >>> of doctors who perform abortions so that they can be assassinated? >> Hey, it's about boycott, not killing them. > > One person's boycott is another person's murder. > > It's like they say, guns don't kill people, people kill > people. > > If guns are banned, then databases of such information > should be banned also. > >> Applied to the doctors >> example: You go to someone without a doctors degree, a clothes hanger >> and some experience? ;-) >> OK, that's enough non-Python ramblings for this thread. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From martin at v.loewis.de Wed Jan 7 18:25:45 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 00:25:45 +0100 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <496539fa$0$11157$9b622d9e@news.freenet.de> > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? Here is how the "Remember me" thing in browsers works: 1. The user *has* to pick a "master password". It can't work without (ignoring smartcards etc.). 2. the browser uses the master password to encrypt the many individual passwords that the user needs. 3. when the user navigates to a password protected site, the browser checks whether it has a cached password, and uses the master password to restore the encrypted site password. In interaction, several cases can occur A1. site never seen, no master password entered - ask user for site password, and whether to store password - ask user for master password - encrypt site password, and store on disk - remember master password in memory A2. site seen before, no master password entered - ask for master password, then continue with B2 B1. site never seen, master password entered - ask user for site password, and whether to store it - (if store) encrypt site password, store on disk B2. site seen before, master password entered - load encrypted password from disk, decrypt with master password, send to site The "encrypt" and "decrypt" operations are "symmetric", so what you need is a symmetric encryption algorithm. If you absolutely cannot accept additional algorithms, you can implement XOR password encryption yourself: Compute, letter-for-letter, the exclusive or of the site password and the master password; if you run out of master password letters, start over with the first one. Notice that this algorithm is very poor, and can be cracked by a crypto expert easily, given a few encrypted passwords. If you want a good algorithm, you might chose AES, with pure-Python implementations available here: http://bitconjurer.org/rijndael.py A simpler, yet supposedly secure algorithm is TEA: http://mail.python.org/pipermail/python-list/2002-August/159138.html Regards, Martin From news123 at free.fr Wed Jan 7 18:26:17 2009 From: news123 at free.fr (News123) Date: Thu, 08 Jan 2009 00:26:17 +0100 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <49653a19$0$5267$426a74cc@news.free.fr> Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? What algorithms shall I be > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. If you have to store user name and password in order to send them at a later time to another application, then there is really no point for encryption. If your script can read it, then anybody who can read your script (and thus the encryption password) will be able to decrypt the username and password. One exception on linux: suid executables writing the password file with restricted permissions, but then you rely on file system permissions and not on passwords ANother exception would be if - you start your python script - you enter a password interactively - the user switches then over enters his username and password, which you encrypt with your interactive pwd Lateron you could - start your script - enter your interactive password - read the encrypted user name / passwords from a file and send them over the network. Perhaps it would be best if you explain EXACTLY, what you would like to achieve and who trusts whom, whom you want to hide the passwords from, etc . bye N From prologic at shortcircuit.net.au Wed Jan 7 18:33:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 09:33:36 +1000 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> Message-ID: On Thu, Jan 8, 2009 at 9:24 AM, Steve Holden wrote: (...) > OK, that's enough non-Python ramblings for this thread. God I wish we could delete threads :) cheers James From joe at strout.net Wed Jan 7 18:34:14 2009 From: joe at strout.net (Joe Strout) Date: Wed, 07 Jan 2009 16:34:14 -0700 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <49653BF6.5020004@strout.net> Dan Esch wrote: > In essence, the implication of immutability for Python is that there is > only one "parrot", one "spam,"in fact one anything. (This seems like it > must hold for data primitives - does it hold for complex objects as > well? It seems it must...) In addition there is only one 1, and one 2 > etc. That's not necessarily true. If you have a = "par" + "rot" b = "parrot" then, most likely (though it depends on how clever the compiler optimizations are), there are two different string objects containing the data "parrot". In this case, "a == b" is true because string equality testing compares the data, but "a is b" is false because a and b refer to different objects. And by the way, don't let the people claiming that Python's assignment model is bizarre confuse you. Assignment and parameter-passing in Python is exactly the same as in any other modern OOP language; it just so happens that in Python, all variables are references, while in most other languages, some variables are references and others are primitive types. But it should be obvious (though apparently isn't, to some) that this restricted, uniform data model does not fundamentally change anything; it just makes Python a little more restricted and uniform. For details, see: Best, - Joe From adal.chiriliuc at gmail.com Wed Jan 7 18:38:05 2009 From: adal.chiriliuc at gmail.com (Adal Chiriliuc) Date: Wed, 7 Jan 2009 15:38:05 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> Message-ID: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> On Jan 7, 10:15?pm, Bruno Desthuilliers wrote: > This being said, I can only concur with other posters here about the > very poor naming. As far as I'm concerned, I'd either keep the argument > as a boolean but rename it "ascending" (and use a default True value), > or keep the 'order' name but then accept 'asc' and 'desc' as values > ('asc' being the default). Well, I lied a bit :-p The actual function is 20 lines long, and does other stuff to. The "order" argument is not passed as an argument, but as a field on an input object. Since I generally don't like it when people post questions and include gazillions of lines of code, I boiled down the real function to the one posted above, which is the minimum required to show our dilemma. "_find" also does not exist in the real code. You are all right, "order" is a bad name choice. "sort_ascending" would be a much better name for a boolean variable. I found Paul's idea very interesting, but I prefer to not introduce new objects which behave like C enums (maybe that would be more Pythonic?), so I found this variant: def find(field, sort_ascending): ....order_by = {True: "asc", False: "desc"} ....return _find(field + "+" + order_by[sort_ascending]) But what if we can't solve it as ellegantly, and we need to execute different code depending on the condition: def find(field, fast_mode=True): ....if fast_mode: ........do_something(field, 1, DEFAULT_PAGE_SIZE) ....else: ........do_another_thing(field, False, "xml", ignore_error=False) ........and_another_one() Should we typecheck in this case to ensure that if we pass a string for "fast_mode" we will raise an exception? From jgardner at jonathangardner.net Wed Jan 7 18:38:13 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 7 Jan 2009 15:38:13 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: On Jan 7, 7:50?am, J Kenneth King wrote: > Jonathan Gardner writes: > > On Jan 6, 12:24?pm, J Kenneth King wrote: > >> Jonathan Gardner writes: > >> > On Jan 6, 8:18?am, sturlamolden wrote: > >> >> On Jan 6, 4:32 pm, mark wrote: > > >> >> > I want to implement a internal DSL in Python. I would like the syntax > >> >> > as human readable as possible. > > >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes > >> >> I've seen the goto joke). > > >> > This isn't really true. You can, for instance, write a program (in > >> > Python) that takes your pseudo-Python and converts it into Python. > >> > This is what a number of templating libraries such as Mako do. > > >> Which is not even close to being the same. > > >> Lisp - the program source is also the data format > > >> Python - the program source is a string > > >> I could go on a really long rant about how the two are worlds apart, but > >> I'll let Google tell you if you're really interested. > > > I get that Lisp is special because you can hack on the reader as it is > > reading the file in. This is strongly discouraged behavior, as far as > > I know, despite the number of cute hacks you can accomplish with it. > > It is generally discouraged unless there's a reason for it. > > > But consider that this really isn't different than having a program > > read in the lisp-with-modification source and spitting out pure lisp, > > to be read by an honest-to-gosh lisp program later. > > > If that's the case, then Lisp and Python really aren't that different > > in this regard, except that you don't have the option of modifying the > > reader as it reads in the file. > > I think you are missing the distinction. > > Lisp expressions are also data structures. A Lisp expression can be > passed to functions and macros to be operated on before being > executed. When you're writing Lisp source, you're basically looking at > the AST on one level and when you start writing macros for your program, > you're creating a "DSL" or interface to that AST. Lisp source is > eventually expanded to a giant list that is consed by the evaluator (as > far as I understand it. I'm just getting into the compiler stuff > myself). > I think you misunderstood what I was trying to explain. Yes, you can do those wonderful things with Lisp. You can also do wonderful things with Python. Consider programs that take some text written in some other language besides Python. Those programs interpret and translate the text to Python. Then the programs feed the translations to the Python interpreter. Tada! You have a DSL in Python. No, it's not built in, nor is there any standard, but it is entirely possible and people are doing it today. That's how the variety of templating solutions work in the Python world. It's why I can write ${x +y} in Mako and get a Python program that will do the right thing. Alternatively, you can skip the Python interpreter altogether, and write your own interpreter for the language. If it's a simple language (like the original poster hinted at), this is very easy to do. From jgardner at jonathangardner.net Wed Jan 7 18:40:37 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 7 Jan 2009 15:40:37 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> On Jan 7, 9:16?am, "Chris Mellon" wrote: > > The OP wants a Ruby-style DSL by which he means "something that lets > me write words instead of expressions". The ruby syntax is amenable to > this, python (and lisp, for that matter) syntax is not and you can't > implement that style of internal DSL in those languages. > > The answer to the OP is "you can't - use Ruby or modify your requirements". > As far as putting the code into Python, yeah, you can't put it in Python. The best you can do is store it in a string and then interpret the string with some function later on. From David Wed Jan 7 18:45:04 2009 From: David (David) Date: Wed, 07 Jan 2009 17:45:04 -0600 Subject: How do you write to the printer ? References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: On Wed, 07 Jan 2009 15:17:19 -0800, Scott David Daniels wrote: >David Lemper wrote: >> Can find nothing in the on-line docs or a book. >> Groping in the dark I attempted : >Note that (1) You may have just created a file named stdprn. > (2) You need to close that file bwhen you are done. > (3) A final end-of-line is traditional. > (4) You could give us a clue about your operating environment. > (To wit: os, version, python version) > >A printer is nothing Python has or controls, it is a standard thing for >a computer system, so details about your computing environment are >necessary in order to give you good advice. > >--Scott David Daniels >Scott.Daniels at Acm.Org Thanks Scott. System is Windows XP on an Intel, Python version 3.0 Dave From google at mrabarnett.plus.com Wed Jan 7 18:51:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 23:51:09 +0000 Subject: Regular Expressions... In-Reply-To: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> References: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Message-ID: <49653FED.800@mrabarnett.plus.com> Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, I have to admit I don't quite > "get" the re module. For example, I'd like to do a few things (I'm > going to use phone numbers, 'cause that's what I'm currently dealing > with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have > that stuff in $1 and $2, respectively. But the Python stuff simply > isn't clicking for me. If anyone could supply concrete examples of > how to do the problem, above, that would be terrific. > Perl puts the captured text into variables as a side-effect, which, from the Python point of view, is undesirable 'magic'. The Python way is for the result to be returned like any normal function or method call: match = re.search(r"^1(...)(.......)", phone_number) # match is now a match object if successful or None if unsuccessful if match: area_code = match.group(1) local_code = match.group(2) # or: # area_code, local_code = match.groups() No magic involved! (In this case simple string slicing would be simpler and faster.) From gh at ghaering.de Wed Jan 7 18:54:53 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 08 Jan 2009 00:54:53 +0100 Subject: pg_result_status() alternative? In-Reply-To: References: Message-ID: <6sktmdF6t1jiU1@mid.uni-berlin.de> Qian Xu wrote: > Steve Holden wrote: >> Without knowing the full details of that particular module I would >> hazard a guess that any database errors will raise exceptions in Python. >> No exceptions means your database operation worked fine. > > result status is not an exception. > It means the information of frontend/backend protocal, after a SQL-statement > is execute. > > The following is a list of backend IPC commands (v3) > ---------------------------------------------------- > Z - Zero / Ready for Query > [...] > For instance: > ---------------------------------------------------- > SELECT * FROM my_table; > The backend protocal should return T (Row Description) and the frontend > protocal should return Q (Query) > ---------------------------------------------------- > DROP TABLE my_table; > The backend protocal should return C (Complete) and the frontend protocal > should return Q (Query) What are you testing, really? "Normal" Python code should use a PostgreSQL DB-API module or a wrapper on top of it, like SQLAlchemy. Generally, you shouldn't have to drop down to protocol-level functions, unless you're developing a PostgreSQL adapter yourself. Care to explain why you're messing around with this low-level functions? -- Gerhard From jstroud at mbi.ucla.edu Wed Jan 7 18:55:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 15:55:52 -0800 Subject: How to store passwords? In-Reply-To: References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: James Stroud wrote: > If you check out sf.passerby.net and download the source, you will see a passerby.sf.net Shuffle things I did. From roy at panix.com Wed Jan 7 18:56:31 2009 From: roy at panix.com (Roy Smith) Date: Wed, 07 Jan 2009 18:56:31 -0500 Subject: socket.error 24: too many open files References: Message-ID: In article , TheDavidFactor wrote: > I have double checked that it is closing the socket. I don't know what > else to check, any suggestions would be much appreciated. All of the symptoms you report point to sockets not getting closed. What does "double checked" mean? Don't rely on __del__() closing sockets, because __del__() may never get called. Here's a few ways to look for sockets that aren't getting closed: 1) Run netstat. 2) Look in /proc. 3) This is the cute one; iterate over all possible descriptors from 0 to `ulimit -n`. For each one, dup() it, then close the dupe. If dup() didn't raise an exception, the descriptor was valid. Count the ones that don't fail, and you know how many descriptors are open at any time. This is useful for tracking descriptor leaks (which sounds like what you've got). From google at mrabarnett.plus.com Wed Jan 7 19:00:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 00:00:00 +0000 Subject: [SPAM] Re: How do you write to the printer ? In-Reply-To: References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: <49654200.4080505@mrabarnett.plus.com> David at bag.python.org wrote: > On Wed, 07 Jan 2009 15:17:19 -0800, Scott David Daniels > wrote: > >> David Lemper wrote: >>> Can find nothing in the on-line docs or a book. >>> Groping in the dark I attempted : > >> Note that (1) You may have just created a file named stdprn. >> (2) You need to close that file bwhen you are done. >> (3) A final end-of-line is traditional. >> (4) You could give us a clue about your operating environment. >> (To wit: os, version, python version) >> >> A printer is nothing Python has or controls, it is a standard thing for >> a computer system, so details about your computing environment are >> necessary in order to give you good advice. >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Thanks Scott. System is Windows XP on an Intel, Python version 3.0 > The simplest way on Windows is opening "PRN:" or "LPT1": printer = open("PRN:", "wb") printer.write(binary_data) printer.close() where 'binary_data' is a bytestring (class 'bytes' in Python 3.x). From jstroud at mbi.ucla.edu Wed Jan 7 19:03:56 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 16:03:56 -0800 Subject: Regular Expressions... In-Reply-To: References: Message-ID: Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, [snip] > In Perl, I'd so something like > m/^1(...)(.......)/; Indeed it seems you are recovering from an especially bad case. I recommend two doses of the python cookbook per day for one to two months. Report back here after your first cycle and we'll tell you how you are doing. I'm very optimistic about the prognosis. James From fakeaddress at nowhere.org Wed Jan 7 19:06:02 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 07 Jan 2009 16:06:02 -0800 Subject: socket.error 24: too many open files In-Reply-To: References: Message-ID: TheDavidFactor wrote: > [...] It's a deamon that runs on a linux box > and every 15 seconds it checks a MySQL table for new records, if there > are any it creates a .call file on the Asterisk server using ssh, it > also checks the Asterisk server, again via ssh, for any finished calls > and if there are any it reads the .call file and writes the result in > to the MySQL table. > > [...] After it has run for an hour or so I get the error > in the subject when the ssh class tries to create a new socket. I have > double checked that it is closing the socket. I don't know what else > to check, any suggestions would be much appreciated. Is it possible you keep accumulating MySQLdb connection or cursor objects and don't close() them? (I don't know the innards of MySQLdb, but it's something to check.) One thing you might try is to regularly log the filno() of your sockets. -- --Bryan From tjreedy at udel.edu Wed Jan 7 19:08:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 19:08:03 -0500 Subject: linked list with cycle structure In-Reply-To: References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: David Hl??ik wrote: > so okay, i will create a helping set, where i will be adding elements > ID, when element ID will be allready in my helping set i will stop and > count number of elements in helping set. This is how long my cycled > linked list is. CPython now does this in printing and marshalling/pickling so that the following terminates instead of going into an infinite spin. >>> a=[1] >>> b=[2,a] >>> c=[3,b] >>> d=[4,c] >>> a.append(d) >>> a [1, [4, [3, [2, [...]]]]] >>> Sets cannot be recursive because members must be hashable. Dict values do not have to be. So >>> d={1:None} >>> d[1]=d >>> d {1: {...}} >>> > But what if i have another condition , and that is *i can use only > helping memory with constant size* ? This means i am not able to > create any set and adding elements there. I need to have a constant > size variables . This is complication a complication for me. Interesting problem. If it is homework, there must be an answer. Think time-space tradeoff. However, this of really off-topic here. It not only has nothing in particular to with Python, but an indefinitely long looping linked list is something very unlikely in a Python program since Python is based on array-type lists. If you do write a solution in Python, you could, however, post it. tjr From prologic at shortcircuit.net.au Wed Jan 7 19:10:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 10:10:10 +1000 Subject: Regular Expressions... In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 10:03 AM, James Stroud wrote: (...) > Indeed it seems you are recovering from an especially bad case. I recommend > two doses of the python cookbook per day for one to two months. Report back > here after your first cycle and we'll tell you how you are doing. I'm very > optimistic about the prognosis. 2nd opinion :) I highly recommend a strong dose of the Python Tutorial (1) followed by a recovery program of the Python Docs (2) cheers James 1. http://docs.python.org/tutorial/ 2. http://docs.python.org/ From leith.bade at silentone.com Wed Jan 7 19:11:32 2009 From: leith.bade at silentone.com (Leith Bade) Date: Thu, 8 Jan 2009 13:11:32 +1300 Subject: Detecting a GUI session Message-ID: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> I would like to know whether my GUI program is being run under python or pythonw. I would like to know this so I can redirect stderr when their is no console window (pythonw) otherwise leave it spitting to the console window (python). This is because I debug using python while the customer release build uses pythonw. I can see their is sys.executable but a google search turned up various discussions on what this actually means (e.g when run under an integrated exe file - which we do for our release builds). Leith Bade -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jan 7 19:21:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 16:21:06 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> Message-ID: <1ZednYe8UMYq2_jUnZ2dnUVZ_rrinZ2d@pdx.net> Adal Chiriliuc wrote: > On Jan 7, 10:15 pm, Bruno Desthuilliers > wrote: >> ... I'd either keep the argument as a boolean but rename it "ascending" ... > > Well, I lied a bit :-p .... > But what if we can't solve it as elegantly, and we need to ... > > Should we typecheck in this case to ensure that if we pass a string > for "fast_mode" we will raise an exception? Why are you concerned only with type errors on inputs? Even if you could do exhaustive checking of input parameters to make sure they are the only acceptable values, what prevents your user from providing the wrong valid value? What made you pick on type errors in the first place? If it turns out that an argument of 422 is a typo for 42, why is that less of a problem? Just because you are used to systems where one kind of error is always caught does not really make you invulnerable. You'll have no problem telling your users that the 422 is their fault. Why do you have such certainty that passing in "nonsense" as a boolean is a failure you need to deal with? Anyhow, you can guess where my votes would go. If the failure in results will come sufficiently far removed from the bad entry, I sometimes resort to input validation. Often those cases are for setting attributes used much later in an interactive environment. Maybe you can layer your checking in: have a subclass that wraps calls with lots of checking, and see if the subclass or the base is used more. One place I have needed validation is in setting callbacks, since the callback typically gets called asynchronously, and I have trouble discovering why those things blew up. If I can, I manage to try the callback once first, hoping for an early explosion. --Scott David Daniels Scott.Daniels at Acm.Org From jstroud at mbi.ucla.edu Wed Jan 7 19:21:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 16:21:52 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? None of the above. You have put unnecessary constraints on find by requiring a certain data type. def find(field, order_by='desc'): return _find(field + "+" + order_by) Here we are deferring error checking to the _find function. Otherwise: def find(field, order_by='desc'): if order_by not in ['asc', 'desc']: raise ValueError, 'Bad order_by parameter.' else: return _find(field + "+" + order_by) Now you have achieved the exact same affect without any sort of explicit type checking. Moreover, you have eliminated an "if" statement. Also, you leave room for exotic orderings should you ever want them. James From tjreedy at udel.edu Wed Jan 7 19:22:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 19:22:00 -0500 Subject: why cannot assign to function call In-Reply-To: <49653BF6.5020004@strout.net> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: Joe Strout wrote: > That's not necessarily true. If you have > > a = "par" + "rot" > b = "parrot" > > then, most likely (though it depends on how clever the compiler > optimizations are), there are two different string objects containing > the data "parrot". >>> a='par'+'rot' >>> b='parrot' >>> a is b True From robert.kern at gmail.com Wed Jan 7 19:23:24 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 07 Jan 2009 19:23:24 -0500 Subject: linked list with cycle structure In-Reply-To: References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: Terry Reedy wrote: > David Hl??ik wrote: >> But what if i have another condition , and that is *i can use only >> helping memory with constant size* ? This means i am not able to >> create any set and adding elements there. I need to have a constant >> size variables . This is complication a complication for me. > > Interesting problem. If it is homework, there must be an answer. It's also an interview question I've seen reasonably often, particularly with that last complication. -- 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 bearophileHUGS at lycos.com Wed Jan 7 19:24:40 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 7 Jan 2009 16:24:40 -0800 (PST) Subject: Regular Expressions... References: Message-ID: Ken D'Ambrosio: >?But the Python stuff simply isn't clicking for me. For people coming from Perl that want to perform some string processing with Python I suggest to learn first array/string slices and string methods. And to try to use the regular expressions as little as possible. Bye, bearophile From Scott.Daniels at Acm.Org Wed Jan 7 19:29:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 16:29:53 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: James Stroud wrote: > ... > def find(field, order_by='desc'): > if order_by not in ['asc', 'desc']: > raise ValueError, 'Bad order_by parameter.' > ... I'd try a little harder with that error message. At least: raise ValueError('Bad order_by parameter %r.' % (order_by,)) if not: raise ValueError('Bad order_by = %r (should be in %r).' % ( order_by, ['asc', 'desc'])) --Scott David Daniels Scott.Daniels at Acm.Org From rurpy at yahoo.com Wed Jan 7 19:45:06 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 7 Jan 2009 16:45:06 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: On Jan 5, 12:21 pm, Derek Martin wrote: ... > I understand why the assignment model works the way it does, and it's > quite sensible, *when you understand it*. However, I do also think > that to someone who has not encountered such a model before, and who > has not had it explained to them, and/or who has not the background to > understand why it is implemented that way, it very likely might seem > "markedly unusual in appearance, style, or general character and often > involving incongruous or unexpected elements;" as dictionary.com > defines the term bizarre. So no, I don't think that's a > mischaracterization at all. ... Ignoring the nit-picking over choice of words, or what languages are taught in CS courses, I agree with Derek's general point that Python's assignment semantics is *not* the same as many other common languages, and that this confuses people coming to Python from those languages, as evidenced by frequent postings to this list by those people. I concluded exactly the same a long time ago. When I started using Python I had no problem with Python's assignment semantics because I had been using references in Perl for years. I did not have a very hard time with Perl's references, after I recognized their similarities to C's pointers. But as I recall, it took a *long* time to wrap my mind around C pointers. Here is the output of set of equivalent programs in five common (at least at one time) languages (code below) that I have worked in and that formed my "intuition" about how assignment works. Sure looks to me as though Python is the odd man out. Perl: 1, 4, 3 1, 2, 3 Basic (MS VBA): 1 4 3 1 2 3 C: 1, 4, 3 1, 2, 3 Fortran: 1 4 3 1 2 3 Python: [1, 4, 3] [1, 4, 3] Of course, one can dismiss these as non-mainstream or non-modern languages, and maintain that all "important" languages have the same assignment semantics as Python, but then one is left having to explain the frequent confusion about assignment that is visible on this list. I find Derek's explantion more plausible than any others I have read in this thread. ======================================================== Python: #/usr/bin/python a = [1,2,3] b = a a[1] = 4 print a print b ======================================================== Perl: #!/usr/bin/perl @a = (1,2,3); @b = @a; $a[1] = 4; print join (',', @a), "\n"; print join (',', @b), "\n"; ======================================================== Basic: Sub test() Dim a, b a = Array(1, 2, 3) b = a a(1) = 4 Debug.Print a(0), a(1), a(2) Debug.Print b(0), b(1), b(2) End Sub ======================================================== C: #include main () { int i; struct {int a[3];} a, b; for (i=0; i<3; i++) { a.a[i] = i+1; } b = a; a.a[1] = 4; printf ("%i,%i,%i\n", a.a[0], a.a[1], a.a[2]); printf ("%i,%i,%i\n", b.a[0], b.a[1], b.a[2]); } ========================================================== Fortran: program test integer a(3), b(3) do 100, i=1,3 a(i) = i 100 continue b = a a(2) = 4 write(unit=*,fmt=*) a write(unit=*,fmt=*) b end From ken at jots.org Wed Jan 7 19:51:21 2009 From: ken at jots.org (Ken D'Ambrosio) Date: Wed, 7 Jan 2009 19:51:21 -0500 (EST) Subject: Regular Expressions... Message-ID: <41178.75.67.222.25.1231375881.squirrel@webmail.jots.org> Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" the re module. For example, I'd like to do a few things (I'm going to use phone numbers, 'cause that's what I'm currently dealing with): 12345678900 -- How would I: - Get just the area code? - Get just the seven-digit number? In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have the numbers in $1 and $2, respectively. But the Python stuff simply isn't clicking for me. If anyone could supply concrete examples of how to do the problem, above, that would be terrific. Thanks! -Ken From erexsha at gmail.com Wed Jan 7 19:55:51 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 7 Jan 2009 16:55:51 -0800 Subject: multiprocessing vs thread performance In-Reply-To: References: Message-ID: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Hi All , Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch of good example for it? I am trying to break a loop to run it over multiple core in a system. And I need to return an integer value as the result of the process an accumulate all of them. the examples that I found there is no return for the process. Thanks, -Arash On Mon, Jan 5, 2009 at 7:24 PM, Gabriel Genellina wrote: > En Sat, 03 Jan 2009 11:31:12 -0200, Nick Craig-Wood > escribi?: > >> mk wrote: >> > > The results I got are very different from the benchmark quoted in PEP >>> 371. On twin Xeon machine the threaded version executed in 5.54 secs, >>> while multiprocessing version took over 222 secs to complete! >>> >>> Am I doing smth wrong in code below? >>> >> >> Yes! >> >> The problem with your code is that you never start more than one >> process at once in the multiprocessing example. Just check ps when it >> is running and you will see. >> > > Oh, very good analysis! Those results were worriying me a little. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Wed Jan 7 19:58:12 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 11:58:12 +1100 Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <87y6xmhavv.fsf@benfinney.id.au> Scott David Daniels writes: > James Stroud wrote: > > ... > > def find(field, order_by='desc'): > > if order_by not in ['asc', 'desc']: > > raise ValueError, 'Bad order_by parameter.' > > ... > I'd try a little harder with that error message. > At least: > raise ValueError('Bad order_by parameter %r.' % (order_by,)) > if not: > raise ValueError('Bad order_by = %r (should be in %r).' % ( > > order_by, ['asc', 'desc'])) Why are people so reluctant to make error message templates clearer with named placeholders? valid_order_by_values = ['asc', 'desc'] if order_by not in valid_order_by_values: raise ValueError( 'Bad order_by parameter %(order_by)r, should be in %(valid_order_by_values)r' % vars()) -- \ ?I love and treasure individuals as I meet them, I loathe and | `\ despise the groups they identify with and belong to.? ?George | _o__) Carlin, 2007 | Ben Finney From p at ulmcnett.com Wed Jan 7 20:00:07 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 17:00:07 -0800 Subject: Unexpected scientific notation Message-ID: <49655017.6010100@ulmcnett.com> One of my users has reported that my app is giving them scientific notation instead of decimal notation for one specific value among many that display properly. I am unable to reproduce on my end, and this is the first I've heard of anything like this since the app's launch 2 years ago. The app bundles python 2.5.2 using py2exe. It displays '3E+1' instead of '30.0'. As I can't reproduce I'm looking for an idea brainstorm of what could be causing this. What would be choosing to display such a normal number in scientific notation? Ideas? Paul From benjamin.kaplan at case.edu Wed Jan 7 20:01:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 20:01:35 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 2:31 PM, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? > > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? Python will work with Tk 8.5. Regardless of the version, Tk has to be installed first. I also think you'll have to modify the detect_modules method in setup.py to include the directory where Tk is installed. I'm on a Mac, so the method for detecting Tk is a little bit different. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Wed Jan 7 20:05:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 11:05:53 +1000 Subject: multiprocessing vs thread performance In-Reply-To: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> References: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Message-ID: On Thu, Jan 8, 2009 at 10:55 AM, Arash Arfaee wrote: > Hi All , HI :) > Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch of > good example for it? I am trying to break a loop to run it over multiple > core in a system. And I need to return an integer value as the result of the > process an accumulate all of them. the examples that I found there is no > return for the process. You communicate with the process in one of several ways: * Semaphores * Locks * PIpes I prefer to use Pipes which act much like sockets. (in fact they are). Read the docs and let us know how you go :) I'm actually implementing multiprocessing support into circuits (1) right now... cheers James 1. http://trac.softcircuit.com.au/circuits/ From max at alcyone.com Wed Jan 7 20:07:29 2009 From: max at alcyone.com (Erik Max Francis) Date: Wed, 07 Jan 2009 17:07:29 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: <6LqdnQurg-dMzPjUnZ2dnUVZ_uGdnZ2d@speakeasy.net> Terry Reedy wrote: > Joe Strout wrote: > >> That's not necessarily true. If you have >> >> a = "par" + "rot" >> b = "parrot" >> >> then, most likely (though it depends on how clever the compiler >> optimizations are), there are two different string objects containing >> the data "parrot". > > >>> a='par'+'rot' > >>> b='parrot' > >>> a is b > True One exactly doesn't really say much. It's implementation dependent, and depends on the length of the string: >>> a = 'this is a much longer ' + 'parrot' >>> b = 'this is a much longer parrot' >>> a is b False In practice, tests like these are pretty much never useful. It's completely implementation dependent when and under what circumstances fundamental immutable objects are reused, and it's not useful anyway; what you care about is whether two objects are equal or not, not whether they're the same object through some optimization behind the scenes. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis All delays are dangerous in war. -- John Dryden, 1631-1700 From robert.kern at gmail.com Wed Jan 7 20:18:15 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 07 Jan 2009 20:18:15 -0500 Subject: Unexpected scientific notation In-Reply-To: <49655017.6010100@ulmcnett.com> References: <49655017.6010100@ulmcnett.com> Message-ID: Paul McNett wrote: > One of my users has reported that my app is giving them scientific > notation instead of decimal notation for one specific value among many > that display properly. I am unable to reproduce on my end, and this is > the first I've heard of anything like this since the app's launch 2 > years ago. > > The app bundles python 2.5.2 using py2exe. > > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be > causing this. What would be choosing to display such a normal number in > scientific notation? > > Ideas? Locales? Do you at last know the code that's responsible for formatting the number? -- 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 benjamin.kaplan at case.edu Wed Jan 7 20:19:51 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 20:19:51 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: On Wed, Jan 7, 2009 at 7:22 PM, Terry Reedy wrote: > Joe Strout wrote: > > That's not necessarily true. If you have >> >> a = "par" + "rot" >> b = "parrot" >> >> then, most likely (though it depends on how clever the compiler >> optimizations are), there are two different string objects containing the >> data "parrot". >> > > >>> a='par'+'rot' > >>> b='parrot' > >>> a is b > True (this is on Mono. I don't know if the real .NET and/or newer versions of IronPython do this differently) IronPython 1.1 (1.1) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. >>> a = "par" + "rot" >>> b="parrot" >>> a is b False > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at mbi.ucla.edu Wed Jan 7 20:27:49 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 17:27:49 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <87y6xmhavv.fsf@benfinney.id.au> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <87y6xmhavv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Why are people so reluctant to make error message templates clearer > with named placeholders? Because they can never remember they even exist. Thanks for the reminder. From lists at cheimes.de Wed Jan 7 20:31:24 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jan 2009 02:31:24 +0100 Subject: Detecting a GUI session In-Reply-To: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> References: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> Message-ID: Leith Bade schrieb: > I would like to know whether my GUI program is being run under python or > pythonw. > > I would like to know this so I can redirect stderr when their is no > console window (pythonw) otherwise leave it spitting to the console > window (python). > > This is because I debug using python while the customer release build > uses pythonw. > > I can see their is sys.executable but a google search turned up various > discussions on what this actually means (e.g when run under an > integrated exe file - which we do for our release builds). You can check the file descriptor number of sys.stderr. If sys.stderr.fileno() returns -1 or any other value smaller than zero than stderr is not connected to a stream. Christian From bignose+hates-spam at benfinney.id.au Wed Jan 7 20:41:14 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 12:41:14 +1100 Subject: Regular Expressions... References: Message-ID: <87tz8ah8w5.fsf@benfinney.id.au> "Ken D'Ambrosio" writes: > Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" > the re module. For example, I'd like to do a few things (I'm going to use > phone numbers, 'cause that's what I'm currently dealing with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like > m/^1(...)(.......)/; Wouldn't that be better as: m/^1(\d{3})(\d{7})$/; I'll assume that more-precise expression in what follows. > and then I'd have the numbers in $1 and $2, respectively. But the Python > stuff simply isn't clicking for me. In general, where a set of data is likely to be iterated, the Pythonic way to present it is via a single iterable (instead of, in your Perl example, separate variables). Then, for those (generally less frequent) cases where you do want the separate items, you can bind them in a single statement: (foo, bar, baz) = some_sequence or (foo, bar, baz) = (item for item in some_sequence) e.g.: >>> (foo, bar, baz) = [1, 2, 3] >>> foo 1 >>> bar 2 >>> baz 3 So, the match returned by the various ?re? module match functions is an object which allows access to the grouped matches as a sequence. > If anyone could supply concrete examples of how to do the problem, > above, that would be terrific. Assuming the following: >>> import re >>> phone_number_regex = '^1(\d{3})(\d{7})$' Trivial one-shot example: >>> phone_number = '12345678900' >>> (area_code, local_number) = re.match(phone_number_regex, phone_number).groups() >>> area_code '234' >>> local_number '5678900' More explicit example, showing the various steps and assuming you want to re-use the various values in multiple statements: >>> phone_number_pattern = re.compile(phone_number_regex) >>> phone_number_pattern <_sre.SRE_Pattern object at 0xf7f8c598> >>> phone_number = '12345678900' >>> phone_number_match = phone_number_pattern.match(phone_number) >>> phone_number_match <_sre.SRE_Match object at 0xf7f52338> >>> (area_code, local_number) = phone_number_match.groups() >>> area_code '234' >>> local_number '5678900' Python regular expressions also allow naming each group, for later access to the matches via a dict: >>> phone_number_regex = '^1(?P\d{3})(?P\d{7})' >>> phone_number_pattern = re.compile(phone_number_regex) >>> phone_number_match = phone_number_pattern.match(phone_number) >>> phone_number_groups = phone_number_match.groupdict() >>> phone_number_groups['area_code'] '234' >>> phone_number_groups['local_number'] '5678900' -- \ ?? one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.? ?Robert Firth | Ben Finney From cs at zip.com.au Wed Jan 7 20:55:30 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 8 Jan 2009 12:55:30 +1100 Subject: Regular Expressions... In-Reply-To: <41178.75.67.222.25.1231375881.squirrel@webmail.jots.org> Message-ID: <20090108015530.GA13974@cskk.homeip.net> On 07Jan2009 19:51, Ken D'Ambrosio wrote: | Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" | the re module. For example, I'd like to do a few things (I'm going to use | phone numbers, 'cause that's what I'm currently dealing with): | 12345678900 -- How would I: | - Get just the area code? | - Get just the seven-digit number? | | In Perl, I'd so something like | m/^1(...)(.......)/; | and then I'd have the numbers in $1 and $2, respectively. But the Python | stuff simply isn't clicking for me. If anyone could supply concrete | examples of how to do the problem, above, that would be terrific. I presume you're consulting this: http://docs.python.org/library/re.html#module-re Something like this (untested): import re phone = '12345678900' num_re = re.compile('^1(...)(.......)') num_re is now a regular expression object: http://docs.python.org/library/re.html#regular-expression-objects much as you get from a "precompiled" perl regular expression. m = num_re.match(phone) m is now the result of a match against the phone number: http://docs.python.org/library/re.html#id1 m.group(0) is what was matched by the whole expression. m.group(1) is perl's $1, m.group(2) is $2 etc. For example: area_code = m.group(1) There is also an expand() method that accepts \1, \2 etc in its template. For direct substitutions (as in perl's s/this/that/) there is the regular expression object sub() method. It's a bit more broken out than you normally get in perl, but the pieces are all there. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Teamwork is essential. It lets you blame someone else. From bignose+hates-spam at benfinney.id.au Wed Jan 7 20:56:58 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 12:56:58 +1100 Subject: Unexpected scientific notation References: Message-ID: <87priyh85x.fsf@benfinney.id.au> Paul McNett

writes: > The app bundles python 2.5.2 using py2exe. > > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what > could be causing this. What would be choosing to display such a > normal number in scientific notation? As I understand it, the Python string formatting operations use the operating system's C library to perform (some of?) the formatting. The different behaviours you see might therefore be caused by different C libraries in the operating system. To avoid these and related problems, I would avoid floating point wherever possible and use the ?Decimal? type for representing decimal numbers. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From ndbecker2 at gmail.com Wed Jan 7 20:58:41 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 20:58:41 -0500 Subject: buffer creates only read-only buffer? Message-ID: m = mmap.mmap (fd, 64, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) b2 = buffer (m) print b2 Why read-only? Why doesn't 'buffer' allow creation of read-write? Should buffer constructor take an additional optional arg for specifying this? Doc doesn't say anything about the fact that it's read only. From p at ulmcnett.com Wed Jan 7 21:04:16 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 18:04:16 -0800 Subject: Unexpected scientific notation In-Reply-To: References: <49655017.6010100@ulmcnett.com> Message-ID: <49655F20.1020901@ulmcnett.com> Robert Kern wrote: > Paul McNett wrote: >> One of my users has reported that my app is giving them scientific >> notation instead of decimal notation for one specific value among many >> that display properly. I am unable to reproduce on my end, and this is >> the first I've heard of anything like this since the app's launch 2 >> years ago. >> >> The app bundles python 2.5.2 using py2exe. >> >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what could >> be causing this. What would be choosing to display such a normal >> number in scientific notation? >> >> Ideas? > > Locales? Do you at last know the code that's responsible for formatting > the number? I do use locale.format, but I use it for all numbers, and only one such number displays in scientific notation - the rest are fine. Here's the code: 1355 def uom_string(self, val): 1356 """Given a decimal value, format it for string display.""" 1357 if self.unit_of_measure == "inches": 1358 fd = dabo.dAppRef.getSSPref("fraction_display") 1359 if fd == "decimal": 1360 return '%s"' % locale.format("%.5f", val.normalize(), True) 1361 else: 1362 return '%s"' % fractions.getImperial(val) 1363 elif self.unit_of_measure == "millimeters": 1364 #return u"%s\u339C" % self.uom_round(val) 1365 return "%smm" % locale.format("%.1f", self.uom_round(val), True) 1366 else: 1367 raise ValueError, "Unit of Measure '%s' not recognized." % self.unit_of_measure In this case, self.unit_of_measure == "inches" and fd == "decimal". Thanks Paul From greno at verizon.net Wed Jan 7 21:09:01 2009 From: greno at verizon.net (Gerry Reno) Date: Wed, 07 Jan 2009 21:09:01 -0500 Subject: Distutils, bdist_XXX, rpmbuild issues Message-ID: <4965603D.7030207@verizon.net> I've been trying to use the "built distribution" distutils commands such as bdist_rpm to create distro-specific packages for python applications but I'm running into some thorny issues specifically with pre-release versioning of source distributions and built distributions and how to get a "final" release to update these pre-release distributions. For example: We have an application, foo-5.0.0, and we want to put out some pre-release candidates for testing, so we set the version to "5.0.0_rc1" in setup.py. We create the source distribution with: $ python setup.py sdist which creates a source archive, foo-5.0.0_rc1.tar.gz. We extract this archive and 'cd' into the foo-5.0.0_rc1 directory and create a built distribution with: $ python setup.py bdist_rpm which creates source and binary RPMS in the form: foo-5.0.0_rc1-1.noarch.rpm. So we think everything is fine. Everyone installs and tests using the pre-release candidate and subsequent candidates but when you eventually get to the final release, foo-5.0.0, and build your final release RPMS, foo-5.0.0-1.noarch.rpm, you find that it will not update your last pre-release candidate RPM, foo-5.0.0_rcX-1.noarch.rpm because it is not "rpm newer". So I've been working on this for a while but have not found a good way to do this by setting options in a setup.cfg file. It seems like for RPM purposes we have to keep the version to "5.0.0" and set "release" to "0_rcX" for the pre-release candidates and this will work for RPM purposes but then "sdist" does not generate the correct tarball names for each pre-release candidate. It always generates foo-5.0.0.tar.gz. Has anyone managed to solve this issue or is distutils in need of some enhancement. We need the "sdist" command to generate distinct pre-release candidate tarball names. And we need the "bdist_XXX" commands to generate distro-specific package naming such that the pre-release candidate packages can be updated by the final release package. Regards, Gerry From ndbecker2 at gmail.com Wed Jan 7 21:14:50 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 21:14:50 -0500 Subject: mmap only supports string Message-ID: Problem is, AFAIK a string can only be created as a copy of some other data. Say I'd like to take some large object and read/write to/from mmap object. A good way to do this would be the buffer protocol. Unfortunately, mmap only supports string. A string could only be created after copying the original object AFAIK. I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. Specifically, mmap slice should support buffer protocol. From ndbecker2 at gmail.com Wed Jan 7 21:29:45 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 21:29:45 -0500 Subject: mmap doesn't support weakref Message-ID: r = weakref.ref (m) TypeError: cannot create weak reference to 'mmap.mmap' object I believe it would be very useful for mmap object to support weakref. Can it be added? From bignose+hates-spam at benfinney.id.au Wed Jan 7 21:36:54 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 13:36:54 +1100 Subject: Distutils, bdist_XXX, rpmbuild issues References: Message-ID: <87ljtmh6bd.fsf@benfinney.id.au> Gerry Reno writes: > We have an application, foo-5.0.0, and we want to put out some > pre-release candidates for testing, so we set the version to > "5.0.0_rc1" in setup.py. That's where your problems start (as you no doubt surmised). If you want version numbers to compare in a certain order, you should name them so that the version string will trivially compare in that order. > Has anyone managed to solve this issue or is distutils in need of > some enhancement. Surely the solution is to choose version strings that will compare correctly without complicated algorithms? -- \ ?A fine is a tax for doing wrong. A tax is a fine for doing | `\ well.? ?anonymous | _o__) | Ben Finney From prologic at shortcircuit.net.au Wed Jan 7 21:40:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 12:40:26 +1000 Subject: subclassing multiprocessing.Process Message-ID: Hey all, Just a quick clarification on multiprocessing' Process object. If I were to subclass this, say: class Foo(Process): def foo(self): ... def run(self): ... Would the parent and child objects be identical ? That is, would the same methods of Foo exist in the child ? Basically I'm trying to create a Process object, and within that a Pipe to communicate between the parent and child processes. cheers James -- -- "Problems are solved by method" From rhodri at wildebst.demon.co.uk Wed Jan 7 21:46:21 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 08 Jan 2009 02:46:21 -0000 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: On Thu, 08 Jan 2009 00:45:06 -0000, wrote: > When I started using Python I had no problem with Python's > assignment semantics because I had been using references in > Perl for years. I did not have a very hard time with Perl's > references, after I recognized their similarities to C's > pointers. But as I recall, it took a *long* time to wrap > my mind around C pointers. I'd suggest that part of the reason for that is C's blurring of the line between arrays and pointers. You can treat them interchangeably enough of the time that when you can't it catches you by surprise. My experience of teaching twelve-year olds Python is that they understand assignment when it's explained in terms of giving names to these objects (numbers, strings, wombats...) that we've already shown them. It's a lot harder to get them to understand the "putting an object into a labelled box" model when working with other languages. I don't know why this should be, but it is. -- Rhodri James *-* Wildebeeste Herder to the Masses From acooke.org at gmail.com Wed Jan 7 21:46:55 2009 From: acooke.org at gmail.com (acooke.org at gmail.com) Date: Wed, 7 Jan 2009 18:46:55 -0800 (PST) Subject: Generator metadata/attributes Message-ID: Hi, (I searched back and found some previous discussion on generator attributes that seemed to be related to callable generators - this is NOT that, as far as I can tell) I want to associate some data with a generator. This is in a decorator function, as it happens; the generator is being returned and I want to add some info that is useful for debugging later. I have tried modifying both .__doc__ and an arbitrary attribute, but the first is read-only, and the second does not exist (ie you cant just add one by writing to it; same error with setattr). I realise I could create my own wrapper that implements __next__ (I am using Python 3 and haven't checked the exact interface required, but I guess it's something like that), and add the information that way, but I am worried I am doing something too complicated. Is there really no way to stick some arbitrary data onto a generator (from a function that "yield"s)? In case it's any help, the decorator is basically: def mydecorator(f): def decorate(self, *args): generator = f(self, *args) # none of these work generator.__doc__ = 'From ' + str(self) generator.description = 'From ' + str(self) setattr(generator, 'description', 'From ' + str(self)) return generator return decorate and it's used like: class ... @mydeocrator def foo(self, ...): yield... Thanks, Andrew From greno at verizon.net Wed Jan 7 21:52:50 2009 From: greno at verizon.net (Gerry Reno) Date: Wed, 07 Jan 2009 21:52:50 -0500 Subject: Distutils, bdist_XXX, rpmbuild issues In-Reply-To: <87ljtmh6bd.fsf@benfinney.id.au> References: <87ljtmh6bd.fsf@benfinney.id.au> Message-ID: <49656A82.6040604@verizon.net> Ben Finney wrote: > Gerry Reno writes: > > >> We have an application, foo-5.0.0, and we want to put out some >> pre-release candidates for testing, so we set the version to >> "5.0.0_rc1" in setup.py. >> > > That's where your problems start (as you no doubt surmised). If you > want version numbers to compare in a certain order, you should name > them so that the version string will trivially compare in that order. > In many instances we don't get to make that decision when we join projects already in motion. Otherwise, I would not have bothered to post the problem to the list. The fact is that many applications use version string constructs such as I illustrated, "5.0.0_rc1" when they create their release candidates. And yes, the final release, "5.0.0", is not lexically superior. But, as much as I might like that everyone would not do this, I cannot change the whole world which has developed a habit of such things. So I am looking for a solution that works with the world as it is. Regards, Gerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 7 21:56:00 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 08 Jan 2009 02:56:00 -0000 Subject: How to store passwords? In-Reply-To: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 21:06:07 -0000, Oltmans wrote: > But the thing is that I will ask the user for user name and password > only once i.e. when they start the application for the first time. > After that, I'm not supposed to ask the user name and password again. > So in this scenario, if I store a hash on the disk I cannot retrieve > plain-text string back from my hash as I've to send user name and > password to the server in plain-text. The words "massive security hole" spring to mind. Does your server really require you to reauthenticate so often? Can't you invoke some kind of secured protocol instead? -- Rhodri James *-* Wildebeeste Herder to the Masses From jstroud at mbi.ucla.edu Wed Jan 7 22:14:55 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 19:14:55 -0800 Subject: Generator metadata/attributes In-Reply-To: References: Message-ID: acooke.org at gmail.com wrote: > Hi, > > (I searched back and found some previous discussion on generator > attributes that seemed to be related to callable generators - this is > NOT that, as far as I can tell) > > I want to associate some data with a generator. This is in a > decorator function, as it happens; the generator is being returned and > I want to add some info that is useful for debugging later. I have > tried modifying both .__doc__ and an arbitrary attribute, but the > first is read-only, and the second does not exist (ie you cant just > add one by writing to it; same error with setattr). > > I realise I could create my own wrapper that implements __next__ That is what you are going to have to do. Immutable python builtins work that way: py> i = 4 py> i.bob = 2 ------------------------------------------------------------ Traceback (most recent call last): File "", line 1, in : 'int' object has no attribute 'bob' py> i.__doc__ = 'I am an int' ------------------------------------------------------------ Traceback (most recent call last): File "", line 1, in : 'int' object attribute '__doc__' is read-only James From musiccomposition at gmail.com Wed Jan 7 22:27:44 2009 From: musiccomposition at gmail.com (Benjamin) Date: Wed, 7 Jan 2009 19:27:44 -0800 (PST) Subject: Interpreter & Thread state & Frame structures. References: Message-ID: <0a7a0b16-5e8d-46af-a8ef-f8ee696acaaa@i24g2000prf.googlegroups.com> On Jan 7, 7:42?am, alessiogiovanni.bar... at gmail.com wrote: > Hi to all, > there are some fields in the PyInterpreterState and PyThreadState > obscures. > PyInterpreterState: > ? 1) Why there are the fields *next and *tstate_head? When there are multiple interpreters active, they are kept in a linked list. *next refers to the next interpreter state in the list. > > PyThreadState: > ? 1) Why there is the field *next? ditto for thread states > > An object PyFrameObject is a portion of code, with a state. But > exactly? Contents of a method/function, or more simply any block > indented of code? For example, this code: > ? ? def foo(s): > ? ? ? ? if s > 0: > ? ? ? ? ? ? return True > ? ? ? ? else: > ? ? ? ? ? ? return False > > how much frames are? 1 in this case. Each, module, class, function (and method) have a code object which corresponds to one frame when it is executed. From jeff at jmcneil.net Wed Jan 7 22:57:17 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 7 Jan 2009 19:57:17 -0800 (PST) Subject: Generator metadata/attributes References: Message-ID: You'll see the same behavior if you attempt to add an attribute to an instance of object as well. >>> object().t = 5 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 't' >>> You'll have to build your own iterator or wrap the generator object and delegate calls to it. If you elect the latter, you should also ensure that send and throw and gang work properly. Perhaps something nice and thin using getattr within your wrapper class. Jeff On Jan 7, 9:46?pm, acooke.... at gmail.com wrote: > Hi, > > (I searched back and found some previous discussion on generator > attributes that seemed to be related to callable generators - this is > NOT that, as far as I can tell) > > I want to associate some data with a generator. ?This is in a > decorator function, as it happens; the generator is being returned and > I want to add some info that is useful for debugging later. ?I have > tried modifying both .__doc__ and an arbitrary attribute, but the > first is read-only, and the second does not exist (ie you cant just > add one by writing to it; same error with setattr). > > I realise I could create my own wrapper that implements __next__ (I am > using Python 3 and haven't checked the exact interface required, but I > guess it's something like that), and add the information that way, but > I am worried I am doing something too complicated. ?Is there really no > way to stick some arbitrary data onto a generator (from a function > that "yield"s)? > > In case it's any help, the decorator is basically: > > def mydecorator(f): > ? def decorate(self, *args): > ? ? generator = f(self, *args) > ? ? # none of these work > ? ? generator.__doc__ = 'From ' + str(self) > ? ? generator.description = 'From ' + str(self) > ? ? setattr(generator, 'description', 'From ' + str(self)) > ? ? return generator > ? return decorate > > and it's used like: > > class ... > ? @mydeocrator > ? def foo(self, ...): > ? ? yield... > > Thanks, > Andrew From rtw at freenet.co.uk Wed Jan 7 23:18:19 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 07 Jan 2009 22:18:19 -0600 Subject: Generator metadata/attributes References: Message-ID: wrote in news:d301c93a-8a73-4cbb-9601-fe0c18a94f97 @v5g2000prm.googlegroups.com in comp.lang.python: > I realise I could create my own wrapper that implements __next__ (I am > using Python 3 and haven't checked the exact interface required, but I > guess it's something like that), and add the information that way, but > I am worried I am doing something too complicated. Is there really no > way to stick some arbitrary data onto a generator (from a function > that "yield"s)? > > In case it's any help, the decorator is basically: > > def mydecorator(f): > def decorate(self, *args): > generator = f(self, *args) You can use something like this: def mydecorator( f ): def decorated(self, *args): for i in f(self, *args): yield i decorated.__doc__ = 'madeup doc string' return decorated class Example( object ): @mydecorator def foo(self, a, b, ): yield 1 print( help( Example ) ) But realise that when the decorator ("mydecorator" above) is run neither the class ("Example") or the instance (self) is available. Which limits somewhat the debugging information you can attach automatically. Rob. -- http://www.victim-prime.dsl.pipex.com/ From p at ulmcnett.com Wed Jan 7 23:23:52 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 20:23:52 -0800 Subject: Unexpected scientific notation In-Reply-To: <87priyh85x.fsf@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> Message-ID: <49657FD8.8020001@ulmcnett.com> [Some day hopefully I'll remember to change the to: address to python-list at python.org instead of the original sender. I always end up sending the first reply to the sender, then going "oops, forgot to hit 'reply-all'", and sending another copy to the list.] Ben Finney wrote: > Paul McNett

writes: > >> The app bundles python 2.5.2 using py2exe. >> >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what >> could be causing this. What would be choosing to display such a >> normal number in scientific notation? > > As I understand it, the Python string formatting operations > > use the operating system's C library to perform (some of?) the > formatting. > > The different behaviours you see might therefore be caused by > different C libraries in the operating system. > > To avoid these and related problems, I would avoid floating point > wherever possible and use the ?Decimal? type for representing decimal > numbers. Thanks. I forgot to mention that all numbers are already instances of decimal.Decimal, not float. As I mentioned in a prior message, they do go through a locale.format() call to display the value. Paul From gshanemiller at verizon.net Thu Jan 8 00:08:42 2009 From: gshanemiller at verizon.net (Shane) Date: Wed, 7 Jan 2009 21:08:42 -0800 (PST) Subject: parallel and/or synchronous start/run/stop on multiple boxes Message-ID: Consider a network of 3 fully-connected boxes i.e. every box as a TCP- IP connection to every other box. Suppose you start a python program P on box A. Is there a Python mechanism for P to send a copy of itself to box B or C then start that program P on B or C by running a method p in P? Is there a way that P on A could wait for that result? Bottom line: we have a number of needs in which it'd very convienent to write a phython program, install and run it, so that it could automatically propogate itself to wherever the code needs to go and run itself so that there could be multiple copies of the code running on different boxes with synchrounous (maybe asychronous) communication. Shane From bignose+hates-spam at benfinney.id.au Thu Jan 8 00:14:04 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 16:14:04 +1100 Subject: Replying to list messages (was: Unexpected scientific notation) References: <87priyh85x.fsf@benfinney.id.au> Message-ID: <87hc4agz1f.fsf_-_@benfinney.id.au> Paul McNett

writes: > [Some day hopefully I'll remember to change the to: address to > python-list at python.org instead of the original sender. Even better: Take full advantage of the standards-compliant messages from the list, by using the ?Reply to list? function of your RFC 2369 compliant mail program. That way the message is sent to the declared list posting address, without you having to change anything. If your mail program still doesn't have such a function, over a decade since RFC 2369 was written, lobby the vendor to add it. Or, in the case of free software, act some way yourself (write code, pay someone else to do so, or some other action) to have that function added for everyone. For Thunderbird (which I see you're using, Paul), the open bug report is . Meanwhile, you can install an add-on to provide the function . > I always end up sending the first reply to the sender, then going > "oops, forgot to hit reply-all'", and sending another copy to the > list.] At least that's merely a minor inconvenience; easily rectified by just sending the message again using the correct function. That's much better, of course, than the opposite situation which exists on some misconfigured mailing lists: that a message sent using the ?Reply to sender? function, with content written in the knowledge that only the original message's sender should be reading it, instead ends up going to the mailing list. That damage can't be undone. Thanks to the Python mailing list administrators for conforming to the standards and not breaking the configuration like that! -- \ ?[T]he question of whether machines can think ? is about as | `\ relevant as the question of whether submarines can swim.? | _o__) ?Edsger W. Dijkstra | Ben Finney From prologic at shortcircuit.net.au Thu Jan 8 00:17:35 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:17:35 +1000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:08 PM, Shane wrote: > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > IP connection to every other box. > > Suppose you start a python program P on box A. Is there a Python > mechanism for P to send a copy of itself to box B or C then start that > program P on B or C by running a method p in P? Is there a way that P > on A could wait for that result? No, python provides no such mechanism. However, I would highly recommend you take a look at circuits (1) for this task - as it's been especially developed for distributed processing in the manner you describe above. In order for your program to propagate itself, you would have to rely on ssh (recommended). There are several good ssh libraries/clients for python, and pexpect might come in handy as well. cheers James 1. http://trac.softcircuit.com.au/circuits/ From sibteym at infotechsw.com Thu Jan 8 00:18:10 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Thu, 8 Jan 2009 10:48:10 +0530 Subject: Multiprocessing takes higher execution time In-Reply-To: <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: <00f701c97150$7fcc2f20$5fc513ac@pwit.com> Hello, Please see the code I have send in attachment. Any suggestions will highly appreciate. Thanks and Regards, Gopal -----Original Message----- From: Grant Edwards [mailto:invalid at invalid] Sent: Wednesday, January 07, 2009 8:58 PM To: python-list at python.org Subject: Re: Multiprocessing takes higher execution time On 2009-01-07, Steve Holden wrote: >> I use multiprocessing to compare more then one set of files. >> >> For comparison each set of files (i.e. Old file1 Vs New file1) >> I create a process, >> >> Process(target=compare, args=(oldFile, newFile)).start() >> >> It takes 61 seconds execution time. >> >> When I do the same comparison without implementing >> multiprocessing, it takes 52 seconds execution time. > My first suggestion would be: show us some code. We aren't > psychic, you know. I am! He's only got one processor, and he's just been bit by Amdahl's law when P<1 and S<1. There you have a perfectly "psychic" answer: an educated guess camoflaged in plausible-sounding but mostly-bullshit buzzwords. A better psychic would have avoided making that one falsifiable statement (he's only got one processor). -- Grant Edwards grante Yow! Hello. Just walk at along and try NOT to think visi.com about your INTESTINES being almost FORTY YARDS LONG!! -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: zipFilesComparision.txt URL: From tjreedy at udel.edu Thu Jan 8 00:22:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 00:22:44 -0500 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: Rhodri James wrote: > On Thu, 08 Jan 2009 00:45:06 -0000, wrote: > >> When I started using Python I had no problem with Python's >> assignment semantics because I had been using references in >> Perl for years. I did not have a very hard time with Perl's >> references, after I recognized their similarities to C's >> pointers. But as I recall, it took a *long* time to wrap >> my mind around C pointers. > > I'd suggest that part of the reason for that is C's blurring > of the line between arrays and pointers. You can treat them > interchangeably enough of the time that when you can't it > catches you by surprise. > > My experience of teaching twelve-year olds Python is that > they understand assignment when it's explained in terms of > giving names to these objects (numbers, strings, wombats...) > that we've already shown them. It's a lot harder to get > them to understand the "putting an object into a labelled > box" model when working with other languages. I don't know > why this should be, but it is. Kids have little experience with being 'the guest in Room 203' or 'the inmate in cell a-23'. From v+python at g.nevcal.com Thu Jan 8 00:28:14 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Wed, 07 Jan 2009 21:28:14 -0800 Subject: length of a tuple or a list containing only one element In-Reply-To: <490F572D.7070708@tim.thechases.com> References: <874p2pngab.fsf@benfinney.id.au> <490F572D.7070708@tim.thechases.com> Message-ID: <49658EEE.80308@g.nevcal.com> On approximately 11/3/2008 11:55 AM, came the following characters from the keyboard of Tim Chase: >>>> For making a literal tuple, parentheses are irrelevant; only the >>>> commas matter: >>> I don't think I'd go so far as to say that the parentheses around >>> tuples are *irrelevant*...maybe just relevant in select contexts >>> >>> >>> def foo(*args): >>> ... for i, arg in enumerate(args): >>> ... print i, arg >>> ... >>> >>> foo(1,2) >>> 0 1 >>> 1 2 >>> >>> foo((1,2)) # these parens are pretty important :) >>> 0 (1, 2) >>> >>> pedantically-grinning-ducktyping-and-running-ly yers, >> >> I'll see your pedantry and raise you one: >> >>> foo() >> >>> foo(()) >> 0 () > > And just because another "tuples without parens" case exists: > > >>> foo(,) > File "", line 1 > foo(,) > ^ > SyntaxError: invalid syntax > > To maintain the poker theme, I'd say "You raised, and I call" but my > call fails :-P > > -tkc > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm glad you guys had this thread, which I read with interest and some amusement back when it happened. I am an experienced programmer, but a relative newcomer to Python. And so it was, the last couple nights, that I spent much time looking for why my CherryPy configuration didn't work, and after much searching of the CherryPy documentation for a tracing technique (which I still wish I could find), I finally hacked the code to add an extra pprint. Even after that, I focused on the wrong data in the pprint output. At long last, I discovered that somehow my hash-of-hashes was mostly a hash-of-hashes, but there was a tuple in there that contained a hash too! Now how did that get in there? conf['/path'] = { 'item1': 'value1', 'item2': 'value2', }, So I was focusing on the items and values of the pprint, and they were all correct. But this tuple clearly didn't belong, but my brain was expecting that tuples would be surrounded by () in source... -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From p at ulmcnett.com Thu Jan 8 00:44:15 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 21:44:15 -0800 Subject: Replying to list messages In-Reply-To: <87hc4agz1f.fsf_-_@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: <496592AF.2020603@ulmcnett.com> Ben Finney wrote: > Paul McNett

writes: > >> [Some day hopefully I'll remember to change the to: address to >> python-list at python.org instead of the original sender. > > Even better: Take full advantage of the standards-compliant messages > from the list, by using the ?Reply to list? function of your RFC > 2369 compliant mail program. That way the message is sent to the > declared list posting address, without you having to change anything. > > If your mail program still doesn't have such a function, over a decade > since RFC 2369 was written, lobby the vendor to add it. Or, in the > case of free software, act some way yourself (write code, pay someone > else to do so, or some other action) to have that function added for > everyone. I remember taking advantage of that in KMail, before that program became unusably bloated. > For Thunderbird (which I see you're using, Paul), the open bug report > is . > Meanwhile, you can install an add-on to provide the function > . Thanks; I'll follow up with those. In general I don't tend to use add-ons because I have at least 3 computers I regularly use and it is a pain to keep them all configured consistently. >> I always end up sending the first reply to the sender, then going >> "oops, forgot to hit reply-all'", and sending another copy to the >> list.] > > At least that's merely a minor inconvenience; easily rectified by > just sending the message again using the correct function. Yep. > That's much better, of course, than the opposite situation which > exists on some misconfigured mailing lists: that a message sent using > the ?Reply to sender? function, with content written in the > knowledge that only the original message's sender should be reading > it, instead ends up going to the mailing list. That damage can't be > undone. Well, when you are a member of a public mailing list, replying to a thread, the expectation is that you are replying to the list, so I happen to think the correct behavior is the one you think is broken, because practicality beats purity. If I want to send a private message to someone, I'll start a new mail to that person, or simply copy/paste their email addy over the list address, but the most common case is that someone intends to reply to the list. But arguing about this here isn't going to change anything: opinions differ just like tabs/spaces and bottom-post/top-post. > Thanks to the Python mailing list administrators for conforming to the > standards and not breaking the configuration like that! Thanks to the Python mailing list volunteers for running such a well-oiled and popular list! Paul From nad at acm.org Thu Jan 8 00:44:58 2009 From: nad at acm.org (Ned Deily) Date: Wed, 07 Jan 2009 21:44:58 -0800 Subject: parallel and/or synchronous start/run/stop on multiple boxes References: Message-ID: In article , "James Mills" wrote: > On Thu, Jan 8, 2009 at 3:08 PM, Shane wrote: > > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > > IP connection to every other box. > > > > Suppose you start a python program P on box A. Is there a Python > > mechanism for P to send a copy of itself to box B or C then start that > > program P on B or C by running a method p in P? Is there a way that P > > on A could wait for that result? > > No, python provides no such mechanism. The multiprocessing module, new in the 2.6 standard library and available in PyPi as a backport to 2.4 and 2.5, supports managing of processes on both local and remote machines. The 2.6 module documentation has an "example/demo of how to use the managers.SyncManager, Process and others to build a system which can distribute processes and work via a distributed queue to a 'cluster' of machines on a network, accessible via SSH". -- Ned Deily, nad at acm.org From prologic at shortcircuit.net.au Thu Jan 8 00:45:18 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:45:18 +1000 Subject: asynchronous events with multithreading and multiprocessing with circuits Message-ID: Hi folks, For those interested, I have just completed implementing multiprocessing support for circuits (1). It has historically always had multithreading support. These components can be found in circuits.workers and are called: Thread and Process The reason these exist is to perform "work", ie: long-running and potentially blocking tasks that should not be handled with regular event handlers of components in a single process or thread. Here is the code that I used to test this with that utilizes 1 main process/thread, 1 additional thread and 1 additional process. ------------------------------------------------------------ #!/usr/bin/env python from time import sleep from circuits import listener, Event, Component, Debugger, Manager from workers import Thread, Process class Foo(Component): @listener("foo") def onFOO(self): print "foo" @listener("msg") def onMSG(self, s): print s class A(Thread): def run(self): while self.running: try: sleep(2) self.push(Event("Hello from A"), "msg") except KeyboardInterrupt: self.running = False break class B(Process): def run(self): while self.running: try: sleep(3) self.push(Event("Hello from B"), "msg") except KeyboardInterrupt: self.running = False break manager = Manager() #manager += Debugger() foo = Foo() a = A() b = B() manager += foo manager += a manager += b a.start() b.start() while True: try: manager.flush() b.poll() sleep(1) manager.push(Event(), "foo") except KeyboardInterrupt: break a.stop() b.stop() a.unregister() b.unregister() ------------------------------------------------------------ I'll be later adapating primes.py found in the examples/ directory of the circuits distribution to utilize multiprocessing as well as distributed processing. I may also provide other examples of typical use-cases (distributed and parallel csv processing for example). The result of running the above test results in the following (expected) output: ------------------------------------------------------------ $ python test.py foo foo Hello from A Hello from B foo foo Hello from A foo Hello from B foo Hello from A foo foo Hello from A Hello from B foo ^C ------------------------------------------------------------ Note: Each output line is approximately 1s in time. Have a nice day and happy hacking :) cheers James -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Thu Jan 8 00:47:19 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:47:19 +1000 Subject: asynchronous events with multithreading and multiprocessing with circuits In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:45 PM, James Mills wrote: > For those interested, I have just completed implementing > multiprocessing support for circuits (1). (...) PS: circuits can be found on PyPi or here: http://trac.softcircuits.com.au/circuits/ The code/support I mentioned is in the development branch. cheers James From prologic at shortcircuit.net.au Thu Jan 8 00:49:13 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:49:13 +1000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:44 PM, Ned Deily wrote: > The multiprocessing module, new in the 2.6 standard library and > available in PyPi as a backport to 2.4 and 2.5, supports managing of > processes on both local and remote machines. The 2.6 module > documentation has an "example/demo of how to use the > managers.SyncManager, Process and others to build a system which can > distribute processes and work via a distributed queue to a 'cluster' of > machines on a network, accessible via SSH". Wow! :) I didn't know that! It seems the multiprocessing library packs quite a punch! :) cheers James From narkewoody at gmail.com Thu Jan 8 00:56:59 2009 From: narkewoody at gmail.com (Steven Woody) Date: Thu, 8 Jan 2009 13:56:59 +0800 Subject: frontend + backend style application design Message-ID: Hi, I am considering write an application, its core functionalities should be implemented in a command-line application with which a user can interact via its command line interface. This kind of command line interface can help batch usage of the application. On the other hand, I still want a GUI front-end which does not implement any core functionality but only provides a rich GUI interface and communicates with the command-line back-end. I am asking you experts, in the terms of python, what idea/tools/module support this kind of architecture? Thanks in advance. - narke From prologic at shortcircuit.net.au Thu Jan 8 01:05:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 16:05:10 +1000 Subject: frontend + backend style application design In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:56 PM, Steven Woody wrote: > I am considering write an application, its core functionalities should > be implemented in a command-line application with which a user can > interact via its command line interface. This kind of command line > interface can help batch usage of the application. On the other hand, > I still want a GUI front-end which does not implement any core > functionality but only provides a rich GUI interface and communicates > with the command-line back-end. > > I am asking you experts, in the terms of python, what > idea/tools/module support this kind of architecture? Quite simple really. 1. Implement all your core functionality as part of a library. 2. Implement your command-line tools that utilize this library. 3. Implement your gui that also utilizes the same library. myproject/ | |-setup.py | |-myproject/ | |-__init__.py | |-foo.py |-bar.py |-gui.py | |-tools/ | |-foo.py |-bar.py |-myproject.py (gu) You can also take advantage of setuptools along with distutils and define "entry points" for your application. cheers James From esnow at verio.net Thu Jan 8 01:32:24 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 22:32:24 -0800 (PST) Subject: os.fork and pty.fork Message-ID: <1336d687-b147-4466-8c25-8edb1c23744b@w39g2000prb.googlegroups.com> I am trying to wrap my head around an issue here that has to do with running python without a tty. I use pexpect to connect to ssh and run some commands. However, if my script runs from a process which I forked using os.fork my pexpect spawn object can't open a good file descriptor in which to run my ssh command, as far as I can tell. pexpect uses pty.fork to fork the process, attach a tty, and run my command in the child with os.exec. When I go to expect something on the spawn object the read on the fd of the child returns EOF, which indicates that the child's fd is already closed before I did anything. This is the point at which I am trying to make sense of things. pty.fork gave pexpect the child's fd but does that fd actually go to a tty? Does the fact that my use of pexpect happens in a process which is not running in a tty, as it was generated from os.fork? It looks like pty.fork tries to use os.forkpty but I am not sure how an existing tty plays in to getting a new tty for the child process... Any insight into os.fork and pty.fork would be great. Thanks. -eric From bignose+hates-spam at benfinney.id.au Thu Jan 8 01:48:06 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 17:48:06 +1100 Subject: Replying to list messages References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: <878wpmguop.fsf@benfinney.id.au> Paul McNett

writes: > Ben Finney wrote: > > For Thunderbird (which I see you're using, Paul), the open bug > > report is > > . > > Meanwhile, you can install an add-on to provide the function > > . > > Thanks; I'll follow up with those. In general I don't tend to use > add-ons because I have at least 3 computers I regularly use and it > is a pain to keep them all configured consistently. You're welcome. It sounds like you're definitely in the position of wanting to get the above bug fixed; hopefully you can use the frustration you expressed as motivation for getting progress on that. > > [some mailing lists are misconfigured such] that a message sent > > using the ?Reply to sender? function, with content written in > > the knowledge that only the original message's sender should be > > reading it, instead ends up going to the mailing list. That damage > > can't be undone. > > Well, when you are a member of a public mailing list, replying to a > thread, the expectation is that you are replying to the list, so I > happen to think the correct behavior is the one you think is broken, Those lists are misconfigured because they violate the email standards (in this case, RFC 2822) by munging the ?Reply-To? field, reserved for use only by the author of the message. That's broken, and enabling that broken behaviour by failing to provide a ?Reply to list? function in a mail client is also broken. More at . > If I want to send a private message to someone, I'll start a new > mail to that person, or simply copy/paste their email addy over the > list address All of that bother is avoided by simply using the ?Reply to author? function of any mail program, so long as the mailing list isn't misconfigured. > but the most common case is that someone intends to reply to the > list. Indeed it is, which is why RFC 2369 is a standard: it recommends (and just about every mailing list active today conforms by) providing fields in the header of mailing list messages to allow a mail program to implement the ?Reply to list? function for that common case. That's been a standard for over ten years. The mailing list programs are pretty much all conformant with it, and have been for many years. Any mail client that *still* isn't making use of those fields, not even for the very common use case of a ?Reply to list? function, is rather backward. > But arguing about this here isn't going to change anything: opinions > differ just like tabs/spaces and bottom-post/top-post. In cases like this, one side can simply be wrong :-) Best of luck getting your programs behaving as you want them to! -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From quian.xu at stud.tu-ilmenau.de Thu Jan 8 02:41:27 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Thu, 08 Jan 2009 08:41:27 +0100 Subject: pg_result_status() alternative? References: <6sktmdF6t1jiU1@mid.uni-berlin.de> Message-ID: Gerhard H?ring wrote: > What are you testing, really? "Normal" Python code should use a > PostgreSQL DB-API module or a wrapper on top of it, like SQLAlchemy. > > Generally, you shouldn't have to drop down to protocol-level functions, > unless you're developing a PostgreSQL adapter yourself. > > Care to explain why you're messing around with this low-level functions? > I am using pgpool (a middleware that works between PostgreSQL servers and a PostgreSQL database client. http://pgpool.projects.postgresql.org/) for data republication. And it works not stable. Sometimes it crashes after couple of weeks. So I want to test. whether the pgpool behaviors correctly. I performed same queries to a real postgresql database and to a pgpool by using the pg module (http://www.pygresql.org/pg.html). Same query results and same frontend/backend protocol responses are expected. 1. There is no problem to compare the query results. 2. There is no problem to retrieve the protocol responses of pgpool (by calling an API of pgpool) as well. 3. But I have problem to retrieve the protocol responses of a real postgresql database. This is my motivation of using the low-level function. --Qian From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 02:45:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 07:45:35 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Only in the sense that the behaviour of *real world* objects don't >> entirely match the behaviour of Python objects. If you just accept that >> Python objects can be in two places at once, an unintuitive concept I >> accept but hardly difficult to grasp, then you don't need to mention >> references. > > To my mind, explaining that objects can actually be in two (or three, or > any unbounded number) of places at once, stashed inside each other to an > arbitrary degree -- that looks like the excuses of someone who's been > caught in a lie. Maybe it was a useful lie-to-children, meant to avoid > explaining the full details in advance, but the time comes to put away > childish things, and learn the truth. (I can't believe I just quoted > Paul. I feel all dirty.) All analogies are lies-to-children. I don't think this is any worse than the lie-to-children about magic pieces of string that you can only handle by the paperweight at one end. Both analogies contain leaky abstractions. > The `they're just objects' model is very simple, but gets tied up in > knots explaining things. The `it's all references' model is only a > little more complicated, but explains everything. But it *over* explains, because it implies things that "everybody knows" about references in other languages that aren't true for Python. Of course it's not literally true that "everybody knows" that you can use references to implement a swap(x, y) procedure. But people coming from a C or Pascal background tend to assume that everything is like C/Pascal, and there are a lot of them. If C was a rare, unfamiliar language, my opposition to using the term "reference" would be a lot milder. Maybe in another five years? > No, indeed. Python is a language for talking about paperweights. And > it's because of the paperweights that the duck-typing works: all the > paperweights are the same shape and size, so they're physically > interchangeable. Okay, the abstraction has leaked again... are the paperweights references to the objects, or the names we've bound objects to? I'm confused... How do we deal with anonymous objects in your model? -- Steven From per.olav.kroka at ericsson.com Thu Jan 8 02:58:34 2009 From: per.olav.kroka at ericsson.com (Per Olav Kroka) Date: Thu, 8 Jan 2009 08:58:34 +0100 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid In-Reply-To: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> References: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> Message-ID: <61D8D34BB13CFE408D154529C120E0790243F7E8@eseldmw101.eemea.ericsson.se> FYI: the '/*.*' is part of the error message returned. -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Wednesday, January 07, 2009 6:40 PM To: Per Olav Kroka Cc: python-list at python.org Subject: Re: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid > PS: Why does the listdir() function add '*.*' to the path? Don't know what you're talking about. It doesn't do any globbing or add "*.*" to the path. Its exclusive purpose is to list the contents of a directory, so /in a sense/ it does add "*.*", but then not adding "*.*" would make the function completely useless given its purpose. > PS2: Why does the listdir() function add '/*.*' to the path on windows > and not '\\*.*' ? You can use either directory separator (\ or /) with the Python APIs on Windows. r"c:\WINDOWS\" works just as well as "c:/WINDOWS/". Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sri_annauni at yahoo.co.in Thu Jan 8 02:59:37 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Thu, 8 Jan 2009 13:29:37 +0530 (IST) Subject: How to deepcopy a list of user defined lists? Message-ID: <35331.99250.qm@web7908.mail.in.yahoo.com> Hi, I have a class which is a subclass of builtin-type list. #------------------------------------------------------------------------------ class clist(list): ??? def __new__(cls, values, ctor): ??????? val = [] ??????? for item in values: ??????????? item = ctor(item) ??????????? val.append(item) ??????? ??????? self = list.__new__(cls, val) ??????? self.__values = val ??????? self.__ctor = ctor ??????? return self #----------------------------------------------------------------------------------- I have a list of clists, say c1 = [clist1, clist2, clist3] How do i deepcopy this list? I tried using copy.deepcopy() method. But i got?some errors. Please suggest me. Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From clp2 at rebertia.com Thu Jan 8 03:26:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 00:26:27 -0800 Subject: How to deepcopy a list of user defined lists? In-Reply-To: <35331.99250.qm@web7908.mail.in.yahoo.com> References: <35331.99250.qm@web7908.mail.in.yahoo.com> Message-ID: <50697b2c0901080026vcd1637bk1208d33e976ee9e9@mail.gmail.com> On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > def __new__(cls, values, ctor): > val = [] > for item in values: > item = ctor(item) > val.append(item) > > self = list.__new__(cls, val) > self.__values = val > self.__ctor = ctor > return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] > How do i deepcopy this list? I tried using copy.deepcopy() method. But i got some errors. Please suggest me. And those errors are? Please include a full Traceback. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 03:37:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 08:37:12 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Wed, 07 Jan 2009 03:45:00 -0800, sturlamolden wrote: > On Jan 7, 2:02 am, Steven D'Aprano > wrote: > >> In Python code, there are no references and no dereferencing. > > The why does CPython keep track of reference counts? Two different levels of explanation. At the level of Python code, you don't see reference counts. You never manipulate reference counts directly. The gc module does expose them, if you want to see them, but the gc module deliberately peaks behind the curtains. It's special. At the implementation level, CPython uses references so it needs reference counts. Jython doesn't keep reference counts at all, because it uses Java's garbage collection (or so I understand). And the hypothetical Distributed Python uses clones of objects and a daemon which keeps them in sync, and hence there are no reference counts because each clone is attached once and once only. >> You can't, because Python doesn't have references. In a language with >> references, that's easy. > > Python does not 'pass-by-reference' as Fortran or Pascal do. That's right. But sadly, if you tell people that Python uses references, many people will say "How do I pass a reference to this object to a function?". >>>> a = 123456789 >>>> b = [a] >>>> c = [a] >>>> d = [a, a] > >>>> b[0] is a > True >>>> c[0] is a > True >>>> d[0] is a > True >>>> d[1] is a > True > > Where is the object 'a' stored? Somewhere in memory, floating free, where it is referred to under the name 'a'. In CPython, it will be in the heap, unless it has been paged out to disk. In the lists 'b', 'c' and (twice) 'd'. I don't have a problem with objects being in two places at the same time. It's just a mental model. I understand that, underneath, the memory for the object is in *one place*, somewhere, because distributed storage is a hard problem and no existing Python does it. But I also understand that underneath, *everything* is just mutable bytes. There are no ints or strings or lists or dicts, they're just an abstraction. If you keep looking behind the curtains, looking at the implementation of each level of abstraction, eventually you'll get to bytes, and then electrons. If you go there, then you'll conclude that the object 'a' isn't anywhere. I'm happy with a high-level abstraction where Python objects can be in more than one place at once. Now, how do you implement such an abstraction? The easiest way is to have the object in one (hidden?) place, and have everywhere else use a pointer or reference to it. But that's a lower level of description than you can reach from Python code, because you can't access those pointers. You can only infer that they are there because otherwise you have to accept that objects can be in two places at once. Or because you've read the source code, but that's implementation. -- Steven From castironpi at gmail.com Thu Jan 8 03:40:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 8 Jan 2009 00:40:46 -0800 (PST) Subject: mmap only supports string References: Message-ID: <97e28947-8560-4029-beb5-d25ac1ef94da@y1g2000pra.googlegroups.com> On Jan 7, 8:14?pm, Neal Becker wrote: > Problem is, AFAIK a string can only be created as a copy of some other data. ?Say I'd like to take some large object and read/write to/from mmap object. ?A good way to do this would be the buffer protocol. ?Unfortunately, mmap only supports string. ?A string could only be created after copying the original object AFAIK. > > I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. ?Specifically, mmap slice should support buffer protocol. Hi. It is a weakness. Strings are supposed to be read-only in Python: so. You can use and get the PyObject_AsWriteBuffer C function from 'ctypes' if you are interested. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 03:51:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 08:51:40 GMT Subject: How to deepcopy a list of user defined lists? References: Message-ID: On Thu, 08 Jan 2009 13:29:37 +0530, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > ??? def __new__(cls, values, ctor): > ??????? val = [] > ??????? for item in values: > ??????????? item = ctor(item) > ??????????? val.append(item) > ??????? > ??????? self = list.__new__(cls, val) > ??????? self.__values = val > ??????? self.__ctor = ctor > ??????? return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] How do i > deepcopy this list? I tried using copy.deepcopy() method. But i got?some > errors. Please suggest me. Don't tell us what the errors are, I love guessing games!!! Let's see... is it TypeError because your class doesn't override the list.__init__ method? >>> clist1 = clist([1,2,3], str) Traceback (most recent call last): File "", line 1, in TypeError: list() takes at most 1 argument (2 given) Before you get to deepcopy, you actually need to have clist work correctly. Once you've done that, show us what error you get. -- Steven From sri_annauni at yahoo.co.in Thu Jan 8 03:53:42 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Thu, 8 Jan 2009 14:23:42 +0530 (IST) Subject: How to deepcopy a list of user defined lists? References: <35331.99250.qm@web7908.mail.in.yahoo.com> <50697b2c0901080026vcd1637bk1208d33e976ee9e9@mail.gmail.com> Message-ID: <537836.85410.qm@web7904.mail.in.yahoo.com> --> 964???????? self.__tmp_data = copy.deepcopy(self.__data) ??? 965 /usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil) ??? 160???? copier = _deepcopy_dispatch.get(cls) ??? 161???? if copier: --> 162???????? y = copier(x, memo) ??? 163???? else: ??? 164???????? try: /usr/local/python-2.5.1/lib/python2.5/copy.py in _deepcopy_list(x, memo) ??? 225???? memo[id(x)] = y ??? 226???? for a in x: --> 227???????? y.append(deepcopy(a, memo)) ??? 228???? return y ??? 229 d[list] = _deepcopy_list /usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil) ??? 187???????????????????????????? raise Error( ??? 188???????????????????????????????? "un(deep)copyable object of type %s" % cls) --> 189???????????????? y = _reconstruct(x, rv, 1, memo) ??? 190 ??? 191???? memo[d] = y /usr/local/python-2.5.1/lib/python2.5/copy.py in _reconstruct(x, info, deep, memo) ??? 320???? if deep: ??? 321???????? args = deepcopy(args, memo) --> 322???? y = callable(*args) ??? 323???? memo[id(x)] = y ??? 324???? if listiter is not None: /usr/local/python-2.5.1/lib/python2.5/copy_reg.py in __newobj__(cls, *args) ???? 90 ???? 91 def __newobj__(cls, *args): ---> 92???? return cls.__new__(cls, *args) ???? 93 ???? 94 def _slotnames(cls): : __new__() takes exactly 3 arguments (1 given) ----- Original Message ---- From: Chris Rebert To: srinivasan srinivas Cc: python-list at python.org Sent: Thursday, 8 January, 2009 1:56:27 PM Subject: Re: How to deepcopy a list of user defined lists? On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): >? ? def __new__(cls, values, ctor): >? ? ? ? val = [] >? ? ? ? for item in values: >? ? ? ? ? ? item = ctor(item) >? ? ? ? ? ? val.append(item) > >? ? ? ? self = list.__new__(cls, val) >? ? ? ? self.__values = val >? ? ? ? self.__ctor = ctor >? ? ? ? return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] > How do i deepcopy this list? I tried using copy.deepcopy() method. But i got some errors. Please suggest me. And those errors are? Please include a full Traceback. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/ From see.signature at no.spam Thu Jan 8 04:24:39 2009 From: see.signature at no.spam (Eric Brunel) Date: Thu, 08 Jan 2009 10:24:39 +0100 Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: On Wed, 07 Jan 2009 20:31:23 +0100, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? There's some important information missing here: the platform you're on... Anyway, you should indeed install tcl/tk first. Then, assuming you're on Linux, you should edit the file named Setup in the Modules sub-directory of your Python installation, find the lines for the _tkinter module and edit them to match your installation. Then, you can build and install Python and it should work without problem. As for Python 2.6 / tk 8.5 compatibility, it depends on what you want to do. Since tk 8.5 still offers the 'regular' tk widgets, these will work in Python 2.6. If you want the new widgets (aka ttk), I'm not sure there are official wrappers for them in the distro (there weren't any last time I checked). If there aren't, you can find the 'pre-official' ones here: http://pypi.python.org/pypi/pyttk > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? I've never worked with Tix myself, but I'd say the widget set offered by tk/ttk is now quite complete. HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From nick at craig-wood.com Thu Jan 8 04:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 08 Jan 2009 03:31:16 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: Sibtey Mehdi wrote: > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) > I create a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > When I do the same comparison without implementing > multiprocessing, it takes 52 seconds execution time. > The oldProjects and newProjects will contains zip files > i.e(oldxyz1.zip,oldxyz2.zip, newxyz2.zip,newxyz2.zip) > it will unzip both the zip files and compare all the files between old > and new (mdb files or txt files) and gives the result. > I do this comparision for n number set of zip files and i assigne each > set of zip files comparision to a process. I had a brief look at the code and your use of multiprocessing looks fine. How many projects are you processing at once? And how many MB of zip files is it? As reading zip files does lots of disk IO I would guess it is disk limited rather than anything else, which explains why doing many at once is actually slower (the disk has to do more seeks). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Thu Jan 8 04:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 08 Jan 2009 03:31:16 -0600 Subject: Creating new instances of subclasses. References: Message-ID: J. Cliff Dyer wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > > >>> f1 = Field('abc') > >>> f2 = Field('123') > >>> f3 = Field('D,E,F') > >>> f1.data > 'abc' > >>> f2.data > 123 > >>> f3.data > ['D','E','F'] > >>> type(f1) > > >>> type(f2) > > >>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. How about this minor modification? # rest as above class Field(object): def __new__(cls, a): if cls != Field: return object.__new__(cls, a) if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) def __init__(self, input): super(Field, self).__init__(input) self.data = input class IntegerField(Field): def __init__(self, s): super(IntegerField, self).__init__(s) self.s = int(s) class ListField(Field): def __init__(self, s): super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass Or you could go for the full metaclass self registration scheme like this, which is actually less code since I delegated the "is this ok" test to the subclass - failing it returns a ValueError. class Field(object): registry = [] class __metaclass__(type): def __init__(cls, name, bases, dict): cls.registry.append(cls) def __new__(cls, a): if cls != Field: return object.__new__(cls, a) for subcls in cls.registry: if subcls == Field: continue try: return subcls(a) except ValueError: pass raise ValueError("Couldn't find subclass") def __init__(self, input): super(Field, self).__init__(input) self.data = input # Raise a ValueError in init if not suitable args for this subtype class IntegerField(Field): def __init__(self, s): s = int(s) super(IntegerField, self).__init__(s) self.s = s class ListField(Field): def __init__(self, s): if ',' not in s: raise ValueError("Not a list") super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass -- Nick Craig-Wood -- http://www.craig-wood.com/nick From amvds at xs4all.nl Thu Jan 8 04:31:45 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 09:31:45 GMT Subject: eval('07') works, eval('08') fails, why? Message-ID: <4965c801$0$193$e4fe514c@news.xs4all.nl> I am baffled by this: IDLE 1.2.2 ==== No Subprocess ==== >>> input() 07 7 >>> input() 08 Traceback (most recent call last): File "", line 1, in input() File "", line 1 08 ^ SyntaxError: invalid token of course, I can work around this using raw_input() but I want to understand why this happens. It boils down to: >>> eval('07') 7 >>> eval('08') Traceback (most recent call last): File "", line 1, in eval('08') File "", line 1 08 ^ SyntaxError: invalid token I can't think of anything that could cause this. Similarly, eval('09') fails, but for string 0x with x<8 it works. I am teaching myself Python in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-- >VisualBasic(2000)-->Python. I am a physicist, have programmed computers all my life but I won't understand the real tech jargon of present day computer science. Please keep it simple Thanks in advance, Alex van der Spek From hv at tbz-pariv.de Thu Jan 8 04:34:21 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 08 Jan 2009 10:34:21 +0100 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: <4965c801$0$193$e4fe514c@news.xs4all.nl> References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <6slvktF6q6dfU1@mid.individual.net> Hi, 07 is octal. That's way 08 is invalid. Try this: ===> python >>> print 011 9 >>> print int('011') 11 -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From hv at tbz-pariv.de Thu Jan 8 04:38:01 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 08 Jan 2009 10:38:01 +0100 Subject: Force exception on attribute write access only one object Message-ID: <6slvrrF71ds4U1@mid.individual.net> Hi, for debugging I want to raise an exception if an attribute is changed on an object. Since it is only for debugging I don't want to change the integer attribute to a property. This should raise an exception: myobj.foo=1 Background: Somewhere this value gets changed. But I don't now where. -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From prologic at shortcircuit.net.au Thu Jan 8 04:38:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 19:38:02 +1000 Subject: Multiprocessing takes higher execution time In-Reply-To: References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: On Thu, Jan 8, 2009 at 7:31 PM, Nick Craig-Wood wrote: (...) > How many projects are you processing at once? And how many MB of zip > files is it? As reading zip files does lots of disk IO I would guess > it is disk limited rather than anything else, which explains why doing > many at once is actually slower (the disk has to do more seeks). If this is the case, this problem is not well suited to multi processing but rather distributed processing :) --JamesMills From dickinsm at gmail.com Thu Jan 8 04:38:35 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jan 2009 01:38:35 -0800 (PST) Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <9709ed24-8990-4f11-82e2-e6d32dddaa19@q18g2000vbn.googlegroups.com> On Jan 8, 9:31?am, Alex van der Spek wrote: > >>> eval('07') > 7 > >>> eval('08') > > Traceback (most recent call last): > ? File "", line 1, in > ? ? eval('08') > ? File "", line 1 > ? ? 08 > ? ? ?^ > SyntaxError: invalid token An integer literal with a leading zero is interpreted as an octal (base 8) number, so only digits in the range 0-7 (inclusive) are permitted in such a literal. Mark > > I can't think of anything that could cause this. Similarly, eval('09') > fails, but for string 0x with x<8 it works. I am teaching myself Python > in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-->VisualBasic(2000)-->Python. I am a physicist, have programmed computers > > all my life but I won't understand the real tech jargon of present day > computer science. Please keep it simple > > Thanks in advance, > Alex van der Spek From clp2 at rebertia.com Thu Jan 8 04:59:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 01:59:55 -0800 Subject: Force exception on attribute write access only one object In-Reply-To: <6slvrrF71ds4U1@mid.individual.net> References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: <50697b2c0901080159i15c15fb0n72c422ee68b5a707@mail.gmail.com> On Thu, Jan 8, 2009 at 1:38 AM, Thomas Guettler wrote: > Hi, > > for debugging I want to raise an exception if an attribute is > changed on an object. Since it is only for debugging I don't want > to change the integer attribute to a property. > > This should raise an exception: > > myobj.foo=1 > > Background: > Somewhere this value gets changed. But I don't now where. Completely untested: class Protector(object): def __init__(self, delegate, *forbidden): self.__delegate = delegate self.__forbidden = set(forbidden) def __getattr__(self, name): return getattr(self.__delegate, name) def __setattr__(self, name, value): if name in self.__forbidden: raise TypeError("attempt to assign to forbidden attribute '%s'" % name) setattr(self.__delegate, name, value) x = Foo() x = Protector(x, "bar") x.bar = 6 #should raise TypeError Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From n.kottiyath at gmail.com Thu Jan 8 05:06:51 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 8 Jan 2009 02:06:51 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: <3f5390c2-1ab0-4ce3-b902-29145e6c2ab0@w1g2000prm.googlegroups.com> The issue is that I am on Python 2.4 which doesnt support func name. I am using filename and lineno now. That does serve the purpose. Thank you, I had not checked all the parameters. Regards K Vinay Sajip wrote: > On Jan 6, 4:17 pm, Kottiyath wrote: > > I dont want the whole traceback. I just wanted to know where the log > > was generated from i.e. which procedure and which line. I have 3/4 > > points in many procedures where I encounter a small error (not an > > exception) and want to log it. So having individual names for each > > looks to be somewhat verbose - esp since the application is >10K LOC. > > > > Don't the funcName and lineno arguments in the format string work for > you? > > (See http://docs.python.org/library/logging.html#id1) > > Regards, > > Vinay Sajip From amvds at xs4all.nl Thu Jan 8 05:07:53 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 10:07:53 GMT Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <4965d079$0$199$e4fe514c@news.xs4all.nl> Thanks much, that makes sense! Alex van der Spek From amvds at xs4all.nl Thu Jan 8 05:25:55 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 10:25:55 GMT Subject: Reading C# serialized objects into Python? Message-ID: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Is there a way to read C# serialized objects into Python? I know the definition and structure of the C# objects. The Python docs say that pickle is specific to Python, which does not give me much hope. There may be a library however that I haven't come across yet. Thanks much, Alex van der Spek From anurag.bagaria at gmail.com Thu Jan 8 05:38:01 2009 From: anurag.bagaria at gmail.com (ANURAG BAGARIA) Date: Thu, 8 Jan 2009 11:38:01 +0100 Subject: using subprocess module in Python CGI In-Reply-To: <49518848.1080602@mattnordhoff.com> References: <49518848.1080602@mattnordhoff.com> Message-ID: Dear Matt, Thank you for your answer. This script is just a kind of test script so as to actually get it started on doing any simple job. The actual process would be much more complicated where in I would like to extract the tar file and search for a file with certain extension and this file would be given as input to another program installed on the server. Later on I would also like to use process.wait() so that I can get a status of the job execution and completion from the server and this information can be displayed to the users on the web-page where they submit their jobs. As to what I understand subprocess.call() would be the best in that case. Please correct, if I am wrong. The whole process is like a user submitting a tar file via the web-browser with some data and getting back the processed results in the form of a new tar file after performing a few operations on the files submitted as input tar file. Thanking you once again for your valuable time. Regards. On Wed, Dec 24, 2008 at 1:54 AM, Matt Nordhoff wrote: > ANURAG BAGARIA wrote: > > Hello, > > > > I am a Python Newbie and would like to call a short python script via > > browser using a CGI script, but initially I am trying to call the same > > python script directly through python command line. The script intends > > to perform a few command line in a pipe and I have written the script (a > > short one) as follows. > > > > #!/usr/bin/python > > > > import cgi, string, os, sys, cgitb, commands, subprocess > > import posixpath, macpath > > #file = "x.tar.gz" > > #comd = "tar -xf %s" % (file) > > #os.system(comd) > > #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../') > > comd = [\ > > "tar -xf x.tar.gz", \ > > "cd demo", \ > > "cp README ../", \ > > ] > > That's not how subprocess.call() works. You're trying to run an > executable called "tar -xf x.tar.gz", passing it the arguments "cd demo" > and "cp README ../". > > > outFile = os.path.join(os.curdir, "output.log") > > outptr = file(outFile, "w") > > errFile = os.path.join(os.curdir, "error.log") > > errptr = file(errFile, "w") > > retval = subprocess.call(comd, 0, None, None, outptr, errptr) > > errptr.close() > > outptr.close() > > if not retval == 0: > > errptr = file(errFile, "r") > > errData = errptr.read() > > errptr.close() > > raise Exception("Error executing command: " + repr(errData)) > > > > > > but after trying to execute this independently, I get the following > > error which I am unable to interpret : > > > > Traceback (most recent call last): > > File "process.py", line 18, in > > retval = subprocess.call(comd, 0, None, None, outptr, errptr) > > File "/usr/lib/python2.5/subprocess.py", line 443, in call > > return Popen(*popenargs, **kwargs).wait() > > File "/usr/lib/python2.5/subprocess.py", line 593, in __init__ > > errread, errwrite) > > File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child > > raise child_exception > > > > > > Could someone suggest where am I going wrong and if corrected, what is > > the probability of this script being compatible with being called > > through the browser. Thanking you people in advance. > > Well, you'd need to output something, but otherwise, sure, why not? > > print "Content-Type: text/html" > print > print "..." > > > Regards. > > Why do you even need to use subprocess to do this? All it's doing is > extracting the README file from a tarball, right? You can use the > tarfile module for that. > > > -- > -- I just want to LIVE while I'm alive. AB -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Jan 8 05:55:57 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 11:55:57 +0100 Subject: Reading C# serialized objects into Python? References: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Message-ID: <6sm4dtF72ul9U1@mid.uni-berlin.de> Alex van der Spek wrote: > Is there a way to read C# serialized objects into Python? > > I know the definition and structure of the C# objects. The Python docs > say that pickle is specific to Python, which does not give me much hope. > There may be a library however that I haven't come across yet. IronPython might be of help here. You might try to de-serialize in IronPython, and then serialize again using pickle. Diez From castironpi at gmail.com Thu Jan 8 06:11:05 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 8 Jan 2009 03:11:05 -0800 (PST) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> On Jan 8, 1:45?am, Steven D'Aprano wrote: > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: snip > > The `they're just objects' model is very simple, but gets tied up in > > knots explaining things. ?The `it's all references' model is only a > > little more complicated, but explains everything. > > But it *over* explains, because it implies things that "everybody knows" > about references in other languages that aren't true for Python. > > Of course it's not literally true that "everybody knows" that you can use > references to implement a swap(x, y) procedure. But people coming from a > C or Pascal background tend to assume that everything is like C/Pascal, > and there are a lot of them. If C was a rare, unfamiliar language, my > opposition to using the term "reference" would be a lot milder. Maybe in > another five years? > > > No, indeed. ?Python is a language for talking about paperweights. ?And > > it's because of the paperweights that the duck-typing works: all the > > paperweights are the same shape and size, so they're physically > > interchangeable. > > Okay, the abstraction has leaked again... are the paperweights references > to the objects, or the names we've bound objects to? I'm confused... > > How do we deal with anonymous objects in your model? > > -- > Steven Mark, hi, Steven, pleasure as always. Neither side is perfect or wild; (Do admit it); How do we decide what is best for newcomers to Python, depending on background? From mdw at distorted.org.uk Thu Jan 8 06:13:40 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 11:13:40 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > I thought you were objecting to Python's use of the term "binding" > when you wrote: [snip] > in response to someone talking about "...all those who use the term > \"name binding\" instead of variable assignment...". Oh, that. Well, the terms are `binding' and `assignment'. Python doesn't need another name for assignment, because actually its idea of assignment is the same as anyone else's. The difference is in the way it deals with objects. See argument elsewhere. -- [mdw] From acooke.org at gmail.com Thu Jan 8 06:14:28 2009 From: acooke.org at gmail.com (acooke.org at gmail.com) Date: Thu, 8 Jan 2009 03:14:28 -0800 (PST) Subject: Generator metadata/attributes References: Message-ID: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Thanks folks. Will write my own class.... Andrew PS So for the record, this works and isn't as ugly/verbose as I was expecting: class TaggedWrapper(): def __init__(self, generator, logMixin, stream): self.__generator = generator self.__tag = '%s@%s' % (logMixin.describe(), stream) logMixin._debug('Created %s' % self) def __next__(self): return next(self.__generator) def __str__(self): return self.__tag def tag_generator(f): ''' Log the generator. ''' def call(self, stream): return TaggedWrapper(f(self, stream), self, stream) return call From __peter__ at web.de Thu Jan 8 06:29:19 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Jan 2009 12:29:19 +0100 Subject: Force exception on attribute write access only one object References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > for debugging I want to raise an exception if an attribute is > changed on an object. Since it is only for debugging I don't want > to change the integer attribute to a property. Why? > This should raise an exception: > > myobj.foo=1 > > Background: > Somewhere this value gets changed. But I don't now where. If you change your mind: class A(object): def __init__(self): self.foo = 42 a = A() b = A() class B(A): @property def foo(self): return self.__dict__["foo"] b.__class__ = B a.foo = "whatever" print b.foo b.foo = "whatever" Peter From steve at holdenweb.com Thu Jan 8 07:11:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:11:22 -0500 Subject: Python Community Service Awards Message-ID: <4965ED6A.8080207@holdenweb.com> Ben Finney recently wrote: > Paul McNett

writes: [...] >> I always end up sending the first reply to the sender, then going >> "oops, forgot to hit reply-all'", and sending another copy to the >> list.] [...] > Thanks to the Python mailing list administrators for conforming to the > standards and not breaking the configuration like that! > And for the way they keep the mail flowing day after day, and for the news/email gateway function, and ... Brad Knowles is a frequently unsung hero, who thoroughly deserves the PSF Community Award he got for his sterling service in the email area. He is ably assisted in this task by Ralf Hildebrandt and Patrick Koetter, authors of "The Book of Postfix". If you know of anyone whom you think deserves to be similarly honored please feel free to let me, or the PSF Board, know about it. When we can't reward people in a material way I believe it's very important to acknowledge these voluntary contributions. http://www.python.org/community/awards/psf-awards/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 07:14:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:14:50 -0500 Subject: Reading C# serialized objects into Python? In-Reply-To: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> References: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek wrote: > Is there a way to read C# serialized objects into Python? > > I know the definition and structure of the C# objects. The Python docs > say that pickle is specific to Python, which does not give me much hope. > There may be a library however that I haven't come across yet. > struct? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 07:18:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:18:06 -0500 Subject: why cannot assign to function call In-Reply-To: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: Aaron Brady wrote: > On Jan 8, 1:45 am, Steven D'Aprano > wrote: >> On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > snip >>> The `they're just objects' model is very simple, but gets tied up in >>> knots explaining things. The `it's all references' model is only a >>> little more complicated, but explains everything. >> But it *over* explains, because it implies things that "everybody knows" >> about references in other languages that aren't true for Python. >> >> Of course it's not literally true that "everybody knows" that you can use >> references to implement a swap(x, y) procedure. But people coming from a >> C or Pascal background tend to assume that everything is like C/Pascal, >> and there are a lot of them. If C was a rare, unfamiliar language, my >> opposition to using the term "reference" would be a lot milder. Maybe in >> another five years? >> >>> No, indeed. Python is a language for talking about paperweights. And >>> it's because of the paperweights that the duck-typing works: all the >>> paperweights are the same shape and size, so they're physically >>> interchangeable. >> Okay, the abstraction has leaked again... are the paperweights references >> to the objects, or the names we've bound objects to? I'm confused... >> >> How do we deal with anonymous objects in your model? >> >> -- >> Steven > > Mark, hi, Steven, pleasure as always. > > Neither side is perfect or wild; (Do admit it); How do we decide what > is best for newcomers to Python, depending on background? The crux of this mistake is assuming that all beginners are alike, and that there is therefore a single "best" way to explain things to them. Teaching should be a dialog, in which the teacher makes use of knowledge revealed by the student about their existing knowledge and ways of thinking to present ideas in an easily assimilable form. In other words, don't treat all students the same. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sibteym at infotechsw.com Thu Jan 8 07:33:23 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Thu, 8 Jan 2009 18:03:23 +0530 Subject: Multiprocessing takes higher execution time In-Reply-To: References: <005701c970ad$c1b27140$5fc513ac@pwit.com><0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: <002f01c9718d$4c4d94d0$5fc513ac@pwit.com> Thanks Nick. It processes 10-15 projects(i.e. 10-15 processes are started) at once. One Zip file size is 2-3 MB. When I used dual core system it reduced the execution time from 61 seconds to 55 seconds. My dual core system Configuration is, Pentium(R) D CPU 3.00GHz, 2.99GHz 1 GB RAM Regards, Gopal -----Original Message----- From: Nick Craig-Wood [mailto:nick at craig-wood.com] Sent: Thursday, January 08, 2009 3:01 PM To: python-list at python.org Subject: Re: Multiprocessing takes higher execution time Sibtey Mehdi wrote: > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) > I create a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > When I do the same comparison without implementing > multiprocessing, it takes 52 seconds execution time. > The oldProjects and newProjects will contains zip files > i.e(oldxyz1.zip,oldxyz2.zip, newxyz2.zip,newxyz2.zip) > it will unzip both the zip files and compare all the files between old > and new (mdb files or txt files) and gives the result. > I do this comparision for n number set of zip files and i assigne each > set of zip files comparision to a process. I had a brief look at the code and your use of multiprocessing looks fine. How many projects are you processing at once? And how many MB of zip files is it? As reading zip files does lots of disk IO I would guess it is disk limited rather than anything else, which explains why doing many at once is actually slower (the disk has to do more seeks). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 8 07:38:19 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 13:38:19 +0100 Subject: Is it ok to type check a boolean argument? In-Reply-To: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> Message-ID: <4965f3a7$0$16997$426a74cc@news.free.fr> Adal Chiriliuc a ?crit : > On Jan 7, 10:15 pm, Bruno Desthuilliers > wrote: >> This being said, I can only concur with other posters here about the >> very poor naming. As far as I'm concerned, I'd either keep the argument >> as a boolean but rename it "ascending" (and use a default True value), >> or keep the 'order' name but then accept 'asc' and 'desc' as values >> ('asc' being the default). > > Well, I lied a bit :-p > > The actual function is 20 lines long, and does other stuff to. The > "order" argument is not passed as an argument, but as a field on an > input object. Then the input object should probably be responsible for validating this (IMHO). (snip) > You are all right, "order" is a bad name choice. "sort_ascending" > would be a much better name for a boolean variable. > > I found Paul's idea very interesting, but I prefer to not introduce > new objects which behave like C enums (maybe that would be more > Pythonic?), so I found this variant: > > def find(field, sort_ascending): > ....order_by = {True: "asc", False: "desc"} > ....return _find(field + "+" + order_by[sort_ascending]) for a simple True/False dispatch, my usual idiom (predating the ternary operator) is: order_by = ("desc", "asc")[sort_ascending] > But what if we can't solve it as ellegantly, and we need to execute > different code depending on the condition: > > def find(field, fast_mode=True): > ....if fast_mode: > ........do_something(field, 1, DEFAULT_PAGE_SIZE) > ....else: > ........do_another_thing(field, False, "xml", ignore_error=False) > ........and_another_one() > > Should we typecheck in this case to ensure that if we pass a string > for "fast_mode" we will raise an exception? I don't think so. Going that way, you will end up typechecking each and any function argument. While there are a couple typechecks here and there even in the stdlib and builtins, this doesn't mean it's how Python is supposed to be used - Python is a dynamic language, leave with it or choose another one !-) But anyway, ensuring a program's correctness requires much more than static typing. What you want IMHO is: 1/ a solid *user input* validation/conversion framework (FormEncode comes to mind) 2/ a sensible set of unittests and integration tests. Trying to forcefit static typing into Python will only buy you pain and frustration (not even talking about the waste of time). From hodgestar+pythondev at gmail.com Thu Jan 8 07:42:09 2009 From: hodgestar+pythondev at gmail.com (Simon Cross) Date: Thu, 8 Jan 2009 14:42:09 +0200 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton wrote: > secondly, i want a python25.lib which i can use to cross-compile > modules for poor windows users _despite_ sticking to my principles and > keeping my integrity as a free software developer. If this eventually leads to being able to compile Python software for Windows under Wine (using for example, py2exe) it would make my life a lot easier. Schiavo Simon From cournape at gmail.com Thu Jan 8 08:11:28 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jan 2009 22:11:28 +0900 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross wrote: > On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton > wrote: >> secondly, i want a python25.lib which i can use to cross-compile >> modules for poor windows users _despite_ sticking to my principles and >> keeping my integrity as a free software developer. > > If this eventually leads to being able to compile Python software for > Windows under Wine (using for example, py2exe) it would make my life a > lot easier. You can already do that: just install windows python under wine. It works quite well, actually. You need mingw, though, of course - Visual Studio is far from being usable on wine. cheers, David From voidwrk at gmail.com Thu Jan 8 08:53:23 2009 From: voidwrk at gmail.com (Sergey Kishchenko) Date: Thu, 8 Jan 2009 05:53:23 -0800 (PST) Subject: Default __nonzero__ impl doesn't throw a TypeError exception Message-ID: In Python empty container equals False in 'if' statements: # prints "It's ok" if not []: print "It's ok" Let's create a simple Foo class: class Foo: pass Now I can use Foo objects in 'if' statements: #prints "Ouch!" f=Foo() if f: print "Ouch!" So, default __nonzero__ impl is to return True. I think, this behaviour conflicts with 'Explicit is better than implicit' and 'Practicality beats purity' statements. I think, throwing a TypeError exception would be better. It will result in more explicit code with fewer errors. From lkcl at lkcl.net Thu Jan 8 08:53:57 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 13:53:57 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 12:42 PM, Simon Cross wrote: > On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton > wrote: >> secondly, i want a python25.lib which i can use to cross-compile >> modules for poor windows users _despite_ sticking to my principles and >> keeping my integrity as a free software developer. > > If this eventually leads to being able to compile Python software for > Windows under Wine (using for example, py2exe) it would make my life a > lot easier. that looks like being an accidental side-effect, yes. where i'm up to so far: * i'm using -I $(src_dir)/PC at the beginning of the includes, so that PC/pyconfig.h gets pulled in as a priority over-and-above the auto-generated pyconfig.h (yukkk - i know); this makes the job of building almost-exactly-like-the-visual-studio-build much easier. * i'm manually compiling-linking the Modules/*.c and PC/*modules.c as i also pulled in PC/config.c and left out Modules/config.c - that got me even further * as a result i've actually got a python.exe.so that.... damnit, it works! the winreg test actually passes for example! the fly in the ointment i'm presently trying to track down: len([1,2]) returns 1L which of course screws up sre_parse.py at line 515 with "TypeError: __nonzero__ should return an int" because duh "if subpattern" is returning a Long not an Int. tracking this down further, it would appear that there's some lovely logic in PyInt_FromSsize_t() which i believe is what's getting called from PyInt_AsSsize_t() which is what's getting called from slot_sq_length() (i think) - and, although in this case this build is _definitely_ returning a Long type when it shouldn't, if the value is ever over LONG_MAX then the result will be "if subpattern" will definitely fail. but... i mean... if ever anyone passes in over 2^^31 items into sre_parse then they _deserve_ to have their code fail, but that's not the point. anyway, i'm floundering around a bit and making a bit of a mess of the code, looking for where LONG_MAX is messing up. l. which of course means that there's a bug in From lkcl at lkcl.net Thu Jan 8 09:02:01 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 14:02:01 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: On Thu, Jan 8, 2009 at 1:11 PM, David Cournapeau wrote: > On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross > wrote: >> On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton >> wrote: >>> secondly, i want a python25.lib which i can use to cross-compile >>> modules for poor windows users _despite_ sticking to my principles and >>> keeping my integrity as a free software developer. >> >> If this eventually leads to being able to compile Python software for >> Windows under Wine (using for example, py2exe) it would make my life a >> lot easier. > > You can already do that: just install windows python under wine. i tried that a few months ago - the builder requires the MS installer, which segfaulted on my installation of wine (i installed it using winetricks) which left me flummoxed because other people report successful use of MSI. i also don't want "just" the python.exe, i want the libpython25.a, i want the libpython25.lib, so as to be able to build libraries such as pywekbit-gtk for win32 (cross-compiled using winegcc of course) unpacking the python installer .exe (which was, again, created with a proprietary program) i found that all of the contents were name-mangled and so were useless: i wasn't about to work my way through nearly a hundred files, manually, when i can just as well get python compiling under wine once and then stand a good chance of being able to repeat the exercise in the future, also for python 2.6. so, basically, i really don't want to use visual studio, i really don't want to install a proprietary MSI installer, i really don't want a proprietarily-built python25.exe, and i really don't want a proprietarily-packed installation. i'd just ... much rather be completely independent of proprietary software when it comes to building free software. .... onwards.... :) From cournape at gmail.com Thu Jan 8 09:05:54 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jan 2009 23:05:54 +0900 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: <5b8d13220901080605l6ecc7224ve7d579612f09abd1@mail.gmail.com> On Thu, Jan 8, 2009 at 11:02 PM, Luke Kenneth Casson Leighton wrote: > On Thu, Jan 8, 2009 at 1:11 PM, David Cournapeau wrote: >> On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross >> wrote: >>> On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton >>> wrote: >>>> secondly, i want a python25.lib which i can use to cross-compile >>>> modules for poor windows users _despite_ sticking to my principles and >>>> keeping my integrity as a free software developer. >>> >>> If this eventually leads to being able to compile Python software for >>> Windows under Wine (using for example, py2exe) it would make my life a >>> lot easier. >> >> You can already do that: just install windows python under wine. > > i tried that a few months ago - the builder requires the MS > installer, which segfaulted on my installation of wine (i installed it > using winetricks) which left me flummoxed because other people report > successful use of MSI. > Hm, I could definitely install python - I have python in wine ATM. wine python -c 'import sys; print sys.version' -> 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] IIRC, I could build numpy on it, which is far from a trivial package from a build POV :) I think it crashes on wine, though - which I why I did not pursued it so far. But I believe python itself at least is usable in wine, depending on what you are trying to do. David From Ron.Barak at lsi.com Thu Jan 8 09:11:20 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 8 Jan 2009 14:11:20 +0000 Subject: Nubie question: how to not pass "self" in call to seek() function ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Hi, I am getting the error TypeError: seek() takes exactly 2 arguments (3 given), namely: $ ./_LogStream.py Traceback (most recent call last): File "./_LogStream.py", line 47, in log_stream.last_line_loc_and_contents() File "./_LogStream.py", line 20, in last_line_loc_and_contents self.input_file.seek(-1, 2) # grab the last character TypeError: seek() takes exactly 2 arguments (3 given) When I run the below code. I understand that the extra argument is the "self", but I don't know how to change my class to make the seek(-1,2) work. Could you help ? Thanks, Ron. $ cat _LogStream.py #!/usr/bin/env python import gzip import sys from Debug import _line as line class LogStream(): def __init__(self, filename): self.filename = filename self.input_file = self.open_file(filename) self.index_increment = 10 self.last_line_offset = -1 def last_line_loc_and_contents(self, estimated_line_size=1024): assert estimated_line_size > 0 file_size = len(self.input_file.read()) self.input_file.seek(-1, 2) # grab the last character if self.input_file.read(1) == '\n': # a "proper" text file file_size -= 1 def open_file(self, in_file): """ The gzip module checks if the input file is a gzipped file, only at the read stage. This is why the f.readline() is needed. """ try: f = gzip.GzipFile(in_file, "r") f.readline() except IOError: f = open(in_file, "r") f.readline() f.seek(0) return(f) if __name__ == "__main__": filename = "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" log_stream = LogStream(filename) log_stream.limit_ = 1000 log_stream.index_increment = 12 log_stream.last_line_loc_and_contents() -------------- next part -------------- An HTML attachment was scrubbed... URL: From antroy at gmail.com Thu Jan 8 09:14:32 2009 From: antroy at gmail.com (Ant) Date: Thu, 8 Jan 2009 06:14:32 -0800 (PST) Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: You could look at something like the following to turn the class iteslf into a decorator (changed lines *-ed): > class TaggedWrapper(): > * ? ? def __init__(self, logMixin, stream): > ? ? ? ? self.__tag = '%s@%s' % (logMixin.describe(), stream) > ? ? ? ? logMixin._debug('Created %s' % self) > > ? ? def __next__(self): > ? ? ? ? return next(self.__generator) > > ? ? def __str__(self): > ? ? ? ? return self.__tag def __call__(self, generator): self.__generator = generator return self and then decorate your generator: @TaggedWrapper(mixin, stream) def myGen; for a in range(1,100): yield a (Disclaimer: Completely untested...) From tryg.olson at gmail.com Thu Jan 8 09:39:12 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 06:39:12 -0800 (PST) Subject: How to set a cookie using Cookie Module References: Message-ID: <851933b7-d24f-48a6-8391-93275c205c9f@a29g2000pra.googlegroups.com> On Jan 7, 9:35 am, tryg.ol... at gmail.com wrote: > Hello - > > This is my first attempt at python cookies. I'm using the Cookie > module and trying to set a cookie. Below is my code. The cookie does > not get set. What am I doing wrong? > > print "Cache-Control: max-age=0, must-revalidate, no-store" > print "Content-type: text/html" > print > print """ > My Page > """ > > c = Cookie.Cookie() > c['MyCookie'] = "Tryg" > print c > print > > If I put javascript code to create a cookie in place of my python > cookie code, the javascript cookie gets set. > > Any tips appreciated! > Tryg I eventually figured it out myself. The cookie code needs to be part of the HTTP header. See example below. print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print print """ My Page """ From tryg.olson at gmail.com Thu Jan 8 09:39:25 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 06:39:25 -0800 (PST) Subject: How to set a cookie using Cookie Module References: Message-ID: On Jan 7, 9:35 am, tryg.ol... at gmail.com wrote: > Hello - > > This is my first attempt at python cookies. I'm using the Cookie > module and trying to set a cookie. Below is my code. The cookie does > not get set. What am I doing wrong? > > print "Cache-Control: max-age=0, must-revalidate, no-store" > print "Content-type: text/html" > print > print """ > My Page > """ > > c = Cookie.Cookie() > c['MyCookie'] = "Tryg" > print c > print > > If I put javascript code to create a cookie in place of my python > cookie code, the javascript cookie gets set. > > Any tips appreciated! > Tryg I eventually figured it out myself. The cookie code needs to be part of the HTTP header. See example below. print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print print """ My Page """ From rtw at freenet.co.uk Thu Jan 8 09:42:55 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 08 Jan 2009 08:42:55 -0600 Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: wrote in news:053df793-9e8e-4855-aba1-f92482cd8922 @v31g2000vbb.googlegroups.com in comp.lang.python: > class TaggedWrapper(): > > def __init__(self, generator, logMixin, stream): > self.__generator = generator > self.__tag = '%s@%s' % (logMixin.describe(), stream) > logMixin._debug('Created %s' % self) Note that "self" in the above is the instance of the wrapper class TaggedWrapper, not the class that is having its (generator) method decorated. import logging logging.basicConfig( level = logging.DEBUG ) def mydecorator( f ): def decorated(self, *args): logging.debug( "Created %s", self.__class__.__name__ ) for i in f(self, *args): yield i return decorated class Example( object ): @mydecorator def foo(self, a, b, ): yield 1 + a + b e = Example() for i in e.foo( 2, 3 ): print( i ) Output of the above is: DEBUG:root:Created Example 6 Rob. -- http://www.victim-prime.dsl.pipex.com/ From ptmcg at austin.rr.com Thu Jan 8 09:52:15 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 8 Jan 2009 06:52:15 -0800 (PST) Subject: Creating new instances of subclasses. References: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> Message-ID: On Jan 7, 12:00?pm, Paul McGuire wrote: > On Jan 7, 10:38?am, "J. Cliff Dyer" wrote: > > > I want to be able to create an object of a certain subclass, depending > > on the argument given to the class constructor. > > > I have three fields, and one might need to be a StringField, one an > > IntegerField, and the last a ListField. ?But I'd like my class to > > delegate to the proper subclass automatically, so I can just do: > > > >>> f1 = Field('abc') > > >>> f2 = Field('123') > > >>> f3 = Field('D,E,F') > > O-O is not always the solution to every problem. ?Since inheritance is > getting in your way, try using a class-level factory method. ?Instead > of using the Field constructor, use a staticmethod of Field, something > like: > > @staticmethod > def make_Field(a) > ? ? if is_list(a): > ? ? ? ? return ListField(a) > ? ? elif is_integer(a): > ? ? ? ? return IntegerField(a) > ? ? else: > ? ? ? ? return StringField(a) > > and then get rid of all those __new__ methods, too. > > -- Paul After looking this over a bit more, I decided I didn't like make_Field having to know the criteria for creating the different subclasses, but wanted to put the smarts into the subclasses themselves. Here is an excerpt that shows this working: class Field(object): def __init__(self, input): super(Field, self).__init__(input) self.data = input @staticmethod def make_Field(a): subs = (ListField, IntegerField, StringField) ret = None for cls in subs: try: ret = cls(a) except TypeError: continue else: break return ret class IntegerField(Field): def __new__(cls, a): if not is_integer(a): raise TypeError() return Field.__new__(cls, a) ... ListField has a similar __new__ method, and StringField just creates the object, with no validation. make_Field still has to know what order to list the subclasses in (StringField is the most permissive, and so must come last in the list of subclasses), but the specific type tests are moved into the subclasses, which is a more appropriate place I think. -- Paul From gruszczy at gmail.com Thu Jan 8 09:53:00 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 15:53:00 +0100 Subject: Tree views - Best design practices Message-ID: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Hi! I have certain design problem, which I cannot solve elegantly. Maybe you know some good design patterns for this kind of tasks. Task: We have a model which has two kinds of objects: groups and elements. Groups can hold other groups (subgroups) and elements. It's a simple directory tree, for example. We would like to display it in a tree view (which sound good for this kind of model). What is more required, for groups and elements there are different sets of operations, which should be available under right click. For example for group, there should be operations: 'add element' and 'add group', and for element there should be 'change properties'. Do you know any smart way to achieve this? The simplest way is to ask for the class and display operations accordingly. But from the first day with OO programming I have heard, that asking for class is wrong. But I can hardly see any easy and more maintainable solution for this problem. Could you help me with this? -- Filip Gruszczy?ski From lkcl at lkcl.net Thu Jan 8 09:57:03 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 14:57:03 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: > anyway, i'm floundering around a bit and making a bit of a mess of the > code, looking for where LONG_MAX is messing up. fixed with this: PyObject * PyInt_FromSsize_t(Py_ssize_t ival) { if ((long)ival >= (long)LONG_MIN && (long)ival <= (long)LONG_MAX) { return PyInt_FromLong((long)ival); } return _PyLong_FromSsize_t(ival); } raised as http://bugs.python.org/issue4880 next bug: distutils.sysconfig.get_config_var('srcdir') is returning None (!!) From daniel.a.esch at gmail.com Thu Jan 8 09:57:16 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 09:57:16 -0500 Subject: why cannot assign to function call In-Reply-To: References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: Absolutely. Trivially and at a high level, teaching python to kids who are learning programming as introductory material teaching python to motivated college graduate students teaching python to adult non-professional programmers with a need to learn python (like for instance, frustrated accountants who have HAD IT with VBA...) The difference between the last 2 is important. I am not now nor will I ever be a professional programmer; there's a depth of knowledge to the subject that I will not ever systematically study (mostly due to time constraints). On the other hand, the problems I want and need to solve, I want to get right and will put in the effort to learn what I need to get it right. Contrast the college student. He's getting a broad and hopefully deep grounding in more CS theory than I have. How much does he care? Well, the beer bash Friday at 4 probably has a higher priority in his life right now, not unreasonably. So you can explain things to me fairly technically (I've done lots of VBA programming, hated it, and am motivated in self-study in python), but not too abstractly, because I don't have a deep ground in the theory behind CS and programming. (What I know of grammar parsing comes via some linguistics work I did in college, not Backus-Naur Form, although Noam chomsky was important in both fields) In contrast, the CS student should get a generalized explanation because he needs to grow the skills to work it out on his own, and because the generalized and theoretically grounded explanation is more useful for him in extrapolating to other areas. If he can't do more with it than i can, he needs to change majors. On 1/8/09, Steve Holden wrote: > > Aaron Brady wrote: > > On Jan 8, 1:45 am, Steven D'Aprano > > wrote: > >> On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > snip > >>> The `they're just objects' model is very simple, but gets tied up in > >>> knots explaining things. The `it's all references' model is only a > >>> little more complicated, but explains everything. > >> But it *over* explains, because it implies things that "everybody knows" > >> about references in other languages that aren't true for Python. > >> > >> Of course it's not literally true that "everybody knows" that you can > use > >> references to implement a swap(x, y) procedure. But people coming from a > >> C or Pascal background tend to assume that everything is like C/Pascal, > >> and there are a lot of them. If C was a rare, unfamiliar language, my > >> opposition to using the term "reference" would be a lot milder. Maybe in > >> another five years? > >> > >>> No, indeed. Python is a language for talking about paperweights. And > >>> it's because of the paperweights that the duck-typing works: all the > >>> paperweights are the same shape and size, so they're physically > >>> interchangeable. > >> Okay, the abstraction has leaked again... are the paperweights > references > >> to the objects, or the names we've bound objects to? I'm confused... > >> > >> How do we deal with anonymous objects in your model? > >> > >> -- > >> Steven > > > > Mark, hi, Steven, pleasure as always. > > > > Neither side is perfect or wild; (Do admit it); How do we decide what > > is best for newcomers to Python, depending on background? > > The crux of this mistake is assuming that all beginners are alike, and > that there is therefore a single "best" way to explain things to them. > Teaching should be a dialog, in which the teacher makes use of knowledge > revealed by the student about their existing knowledge and ways of > thinking to present ideas in an easily assimilable form. > > In other words, don't treat all students the same. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.a.esch at gmail.com Thu Jan 8 10:07:13 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 10:07:13 -0500 Subject: Work with Open Office Message-ID: Okay, I'm currently stuck with VBA / Excel in work and the following paradigm: VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access Where I'd like to be is this Python ==> X ==> Open Office / (MySQL or other) for some sufficiently useful value of X. Does it exist? Is it just a set of modules I need to be looking for? or something else? -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Thu Jan 8 10:16:15 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 8 Jan 2009 07:16:15 -0800 Subject: Nubie question: how to not pass "self" in call to seek() function ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know how > to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, only > at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list From tryg.olson at gmail.com Thu Jan 8 10:16:42 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 07:16:42 -0800 (PST) Subject: How to Delete a Cookie? Message-ID: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Hello - I managed to get a cookie set. Now I want to delete it but it is not working. Do I need to do another 'set-cookie' in the HTTP header? I tried (code below setting expires to 0) and it didn't work. c = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) c["mycook"]["expires"] = 0 print c In case its useful, here is how I set my cookie: c = Cookie.SimpleCookie() c["mycook"] = "Tryg" c["mycook"]["expires"] = 60*60*24 c["mycook"]["comment"] = "" c["mycook"]["path"] = "/" c["mycook"]["domain"] = "" c["mycook"]["secure"] = "" print c Thanks Tryg From lkcl at lkcl.net Thu Jan 8 10:18:03 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 15:18:03 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: > next bug: distutils.sysconfig.get_config_var('srcdir') is returning None (!!) ok ... actually, that's correct. oops. sysconfig.get_config_vars() only returns these, on win32: {'EXE': '.exe', 'exec_prefix': 'Z:\\mnt\\src\\python2.5-2.5.2', 'LIBDEST': 'Z:\\mnt\\src\\python2.5-2.5.2\\Lib', 'prefix': 'Z:\\mnt\\src\\python2.5-2.5.2', 'SO': '.pyd', 'BINLIBDEST': 'Z:\\mnt\\src\\python2.5-2.5.2\\Lib', 'INCLUDEPY': 'Z:\\mnt\\src\\python2.5-2.5.2\\include'} ... aaaand, that means disabling setup.py or hacking it significantly to support a win32 build, e.g. to build pyexpat, detect which modules are left, etc. by examining the remaining vcproj files in PCbuild. .... ok - i'm done for now. the project's not complete, but can be regarded as successful so far. i think the best thing is being able to do "import _winreg" on a linux system. that absolutely tickles me silly :) been running a few tests - test_mmap.py is a hoot, esp. the Try opening a bad file descriptor... that causes a wine segfault. if anyone wants to play with this further, source is here: http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine at some point - if i feel like taking this further, and if people offer some advice and hints on where to go (with e.g. setup.py) i'll continue. then once that's done i'll do python 2.6 as well. l. From grflanagan at gmail.com Thu Jan 8 10:18:24 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 08 Jan 2009 15:18:24 GMT Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: <4Po9l.1$H27.0@newsfe10.ams2> On Thu, 08 Jan 2009 08:42:55 -0600, Rob Williscroft wrote: > > def mydecorator( f ): > def decorated(self, *args): > logging.debug( "Created %s", self.__class__.__name__ ) > for i in f(self, *args): > yield i > return decorated > can optionally be written as: def mydecorator( f ): def decorated(self, *args): logging.debug( "Created %s", self.__class__.__name__ ) return f(self, *args) return decorated From benjamin.kaplan at case.edu Thu Jan 8 10:21:42 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 8 Jan 2009 10:21:42 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch wrote: > Okay, I'm currently stuck with VBA / Excel in work and the following > paradigm: > > VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access > > Where I'd like to be is this > > Python ==> X ==> Open Office / (MySQL or other) for some sufficiently > useful value of X. > > Does it exist? Is it just a set of modules I need to be looking for? or > something else? > > Did you google search first? This is the second result for "Python OpenOffice". http://wiki.services.openoffice.org/wiki/Python -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Thu Jan 8 10:25:56 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 08 Jan 2009 10:25:56 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> Message-ID: <85hc49vmyj.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 7, 9:16?am, "Chris Mellon" wrote: >> >> The OP wants a Ruby-style DSL by which he means "something that lets >> me write words instead of expressions". The ruby syntax is amenable to >> this, python (and lisp, for that matter) syntax is not and you can't >> implement that style of internal DSL in those languages. >> >> The answer to the OP is "you can't - use Ruby or modify your requirements". >> > > As far as putting the code into Python, yeah, you can't put it in > Python. The best you can do is store it in a string and then interpret > the string with some function later on. That's what I'm saying. It seems we're defining "DSL" in two different ways. You can't write a DSL in Python because you can't change the syntax and you don't have macros. You can write a compiler in Python that will compile your "DSL." As another poster mentioned, eventually PyPy will be done and then you'll get more of an "in-Python" DSL. From tavares at fe.up.pt Thu Jan 8 10:26:07 2009 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Thu, 8 Jan 2009 07:26:07 -0800 (PST) Subject: =?windows-1252?Q?Symposium_=93Image_Processing_and_Visualization_in_S?= =?windows-1252?Q?olid_Mechanics_Processes=94_within_the_ESMC2009_Conference_?= =?windows-1252?Q?=96_Announce_=26_Call_for_Papers?= Message-ID: <6ff6c038-e25e-4fa2-ada1-2f1387735ca2@g39g2000pri.googlegroups.com> --------------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) Symposium on ?Visualization and Human-Computer? 7th EUROMECH Solid Mechanics Conference (ESMC2009) Instituto Superior T?cnico, Lisbon, PORTUGAL, September 7-11, 2009 http://www.dem.ist.utl.pt/esmc2009/ (We would appreciate if you could distribute this information by your colleagues and co-workers.) ------------------------------------------------------------------------------------------------------------------------------- Dear Colleague, Within the 7th EUROMECH Solid Mechanics Conference (ESMC2009), to be held in Instituto Superior T?cnico, Lisbon, Portugal, September 7-11, 2009, we are organizing the Symposium ?Image Processing and Visualization in Solid Mechanics Processes?. Examples of some topics that will be considered are: Image Analysis; Image Restoration, Compression, Segmentation and Description; Object Tracking, Matching, Recognition, and Reconstruction; Visual Inspection; 3D Vision; Medical Imaging; Data Processing, Modeling and Analysis; Scientific Visualization; Enhanced Visualization; Human Computer Interaction; Virtual Reality; Simulation and Animation; Software Development for Image Processing and Visualization; Grid Computing in Image Processing and Visualization; Applications of Image Processing and Visualization. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Image Processing and Visualization in Solid Mechanics Processes?. For instructions and submission, please access to the conference website at: http://www.dem.ist.utl.pt/esmc2009/ Please note that, when submitting your work, you should select the Symposium MS-08 ? ?Image Processing and Visualization in Solid Mechanics Processes?. Important dates: - Abstract submission: January 31, 2009; - Notification of acceptance: March 15, 2009; - Conference Events: September 7-11, 2009. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Michel A. Audette (Kitware, USA, michel.audette at kitware.com) (Symposium organizers) From thorsten at thorstenkampe.de Thu Jan 8 10:38:53 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 16:38:53 +0100 Subject: "python -3" not working as expected Message-ID: [Python 2.6.1] Hi, to test existing Python code, I ran "python -3" ("warn about Python 3.x incompatibilities") against a test file that only contains "print 'test'". Unfortunately I saw no warnings about print becoming a function in Python 3 ("print()"). Where is the problem? Thorsten From jldunn2000 at googlemail.com Thu Jan 8 10:39:03 2009 From: jldunn2000 at googlemail.com (loial) Date: Thu, 8 Jan 2009 07:39:03 -0800 (PST) Subject: sftp with no password from python Message-ID: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> Is it possible to use sftp without a password from python? From Ron.Barak at lsi.com Thu Jan 8 10:44:16 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 8 Jan 2009 15:44:16 +0000 Subject: Nubie question: how to not pass "self" in call to seek() function ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494BCB@enbmail01.lsi.com> Hi Mark, I think my open_file() - that is called in __init__ - assures that self.input_file is a regular text file, regardless if filename is a gz or a regular text file. My Python is Python 2.5.2. Bye, Ron. -----Original Message----- From: Mark Tolonen [mailto:metolone+gmane at gmail.com] Sent: Thursday, January 08, 2009 17:16 To: python-list at python.org Subject: Re: Nubie question: how to not pass "self" in call to seek() function ? "Barak, Ron" <> wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know > how to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, > only at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list From nospam at forMe.thks Thu Jan 8 10:45:23 2009 From: nospam at forMe.thks (Ross) Date: Thu, 08 Jan 2009 10:45:23 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Ross wrote: >> There seems to be no shortage of information around on how to use the >> time module, for example to use time.ctime() and push it into strftime >> and get something nice out the other side, but I haven't found >> anything helpful in going the other way. > > As to a paucity of conversion formatting, there is no magic way to take > everyone's way of putting date and time information in text and convert > it to unambiguous format, in part because there are too many different > and contradictory formats. When I write dates, I know what I intended; > when I read dates, I guess what the author intended. > > Have you read the entire time module document? If so, which functions > in that module take strings as arguments? > >> That is, given some formatted text describing times - is there >> something that makes it easy to calculate time differences, or do I >> have to index my way through the string pulling out characters, >> converting to integers etc... >> >> Data is formatted: >> t1 = 09:12:10 >> t2 = 11:22:14 >> I want to calculate tdiff = t2-t1 > > Do you do any work yourself? Show us your attempts. This looks like > a trivial exercise. It seems that for less than four times the effort > of asking your question you might have found the answer. > > Perhaps I am being too cranky this morning. > --Scott David Daniels > Scott.Daniels at Acm.Org Jeeze, you're quite an ass aren't you? From invalid at invalid Thu Jan 8 10:46:26 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 08 Jan 2009 09:46:26 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: On 2009-01-08, Alex van der Spek wrote: > Thanks much, that makes sense! Well, that's the correct explanation. Whether that feature makes sense or not is debatable. Even I'm not old-school enough that I ever use octal literals -- and I used Unix on a PDP-11 for years (actually had my own PDP-11 for while, but it never worked). Now that I think of it, my Heathkit Z80 stuff used octal notation too. -- Grant Edwards grante Yow! I represent a at sardine!! visi.com From google at mrabarnett.plus.com Thu Jan 8 10:47:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 15:47:07 +0000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: <49661FFB.1090604@mrabarnett.plus.com> Shane wrote: > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > IP connection to every other box. > > Suppose you start a python program P on box A. Is there a Python > mechanism for P to send a copy of itself to box B or C then start that > program P on B or C by running a method p in P? Is there a way that P > on A could wait for that result? > > Bottom line: we have a number of needs in which it'd very convienent > to write a phython program, install and run it, so that it could > automatically propogate itself to wherever the code needs to go and > run itself so that there could be multiple copies of the code running > on different boxes with synchrounous (maybe asychronous) > communication. > A sort of Pythonic virus? :-) From xulx1981 at gmail.com Thu Jan 8 10:48:50 2009 From: xulx1981 at gmail.com (=?GB2312?B?0OzBttDC?=) Date: Thu, 8 Jan 2009 23:48:50 +0800 Subject: ask a question about richtextctrl Message-ID: <88e0f95b0901080748y19b70c66vad1f2b9426542bc8@mail.gmail.com> I have countered a problem while using wx.RichTextCtrl. I want to do some check when user presss Ctrl+C to paste. But i found that i can not get the wx.EVT_CHAR event while Ctrl+C is pressed. And I have tried many methods but all failed. So anybody can tell me some tips?Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From kay.schluehr at gmx.net Thu Jan 8 11:03:03 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 8 Jan 2009 08:03:03 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> Message-ID: <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> On 8 Jan., 16:25, J Kenneth King wrote: > As another poster mentioned, eventually PyPy will be done and then > you'll get more of an "in-Python" DSL. May I ask why you consider it as important that the interpreter is written in Python? I see no connection between PyPy and syntactical Python extensions and the latter isn't an objective of PyPy. You can write Python extensions with virtually any Python aware parser. M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then there is ANTLR which provides a Python grammar. I also know about two other Python aware parsers. One of them was written by myself. From daniel.a.esch at gmail.com Thu Jan 8 11:10:32 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 11:10:32 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: Have been browsing through this list and reading documentation and tutorials for python self-study. I have, apparently, teh stupid. Google is my friend. Off I go. Thanks. On 1/8/09, Benjamin Kaplan wrote: > > > > On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch wrote: > >> Okay, I'm currently stuck with VBA / Excel in work and the following >> paradigm: >> >> VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access >> >> Where I'd like to be is this >> >> Python ==> X ==> Open Office / (MySQL or other) for some sufficiently >> useful value of X. >> >> Does it exist? Is it just a set of modules I need to be looking for? or >> something else? >> >> > > Did you google search first? This is the second result for "Python > OpenOffice". > > http://wiki.services.openoffice.org/wiki/Python > > -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Thu Jan 8 11:16:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 16:16:38 +0000 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Message-ID: <496626E6.2030501@mrabarnett.plus.com> Filip Gruszczy?ski wrote: > Hi! > > I have certain design problem, which I cannot solve elegantly. Maybe > you know some good design patterns for this kind of tasks. > > Task: > > We have a model which has two kinds of objects: groups and elements. > Groups can hold other groups (subgroups) and elements. It's a simple > directory tree, for example. We would like to display it in a tree > view (which sound good for this kind of model). What is more required, > for groups and elements there are different sets of operations, which > should be available under right click. For example for group, there > should be operations: 'add element' and 'add group', and for element > there should be 'change properties'. > > Do you know any smart way to achieve this? The simplest way is to ask > for the class and display operations accordingly. But from the first > day with OO programming I have heard, that asking for class is wrong. > But I can hardly see any easy and more maintainable solution for this > problem. Could you help me with this? > You could ask the object what the operations are. Here's an example using strings: >>> class Element(object): operations = "Element operations" >>> class Group(object): operations = "Group operations" >>> e = Element() >>> g = Group() >>> >>> e.operations 'Element operations' >>> g.operations 'Group operations' From gruszczy at gmail.com Thu Jan 8 11:21:52 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 17:21:52 +0100 Subject: Tree views - Best design practices In-Reply-To: <496626E6.2030501@mrabarnett.plus.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> Message-ID: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> >>>> class Element(object): > operations = "Element operations" > > >>>> class Group(object): > operations = "Group operations" > > >>>> e = Element() >>>> g = Group() >>>> >>>> e.operations > 'Element operations' >>>> g.operations > 'Group operations' But this is the same as asking for a class, except for having to write a method giving some form of a class name and then basing on this classname display operations. I know this solution, but this is what I would like to evade. -- Filip Gruszczy?ski From luke.leighton at googlemail.com Thu Jan 8 11:26:48 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 8 Jan 2009 08:26:48 -0800 (PST) Subject: compiling python2.5 on linux under wine References: Message-ID: <852657ad-8fa8-4e71-a2d8-8028c97f06c8@t39g2000prh.googlegroups.com> > ... aaaand, that means disabling setup.py or hacking it significantly > to support a win32 build, e.g. to build pyexpat, detect which modules > are left, etc. by examining the remaining vcproj files in PCbuild. > > .... ok - i'm done for now. > if anyone wants to play with this further, source is here: > > http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine patch is also here: http://bugs.python.org/issue4880 From bj_666 at gmx.net Thu Jan 8 11:26:55 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 8 Jan 2009 16:26:55 GMT Subject: "python -3" not working as expected References: Message-ID: <6smnqfF71c2fU1@mid.uni-berlin.de> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > [Python 2.6.1] > > Hi, > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > incompatibilities") against a test file that only contains "print > 'test'". > > Unfortunately I saw no warnings about print becoming a function in > Python 3 ("print()"). Where is the problem? There is no problem. ``print``\s are handled fine by the 2to3.py script. The option warns about stuff that is not easily automatically converted. Ciao, Marc 'BlackJack' Rintsch From google at mrabarnett.plus.com Thu Jan 8 11:40:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 16:40:07 +0000 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: <49662C67.5030800@mrabarnett.plus.com> Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, except for having to write > a method giving some form of a class name and then basing on this > classname display operations. I know this solution, but this is what I > would like to evade. > My point was that the 'operations' attribute could specify the operations for that kind of object. More explicitly: class Element(object): operations = [change_properties] class Group(object): operations = [add_element, add_group] and so on. From deets at nospam.web.de Thu Jan 8 11:41:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:41:20 +0100 Subject: Tree views - Best design practices References: Message-ID: <6smolgF763pbU1@mid.uni-berlin.de> Filip Gruszczy?ski wrote: > Hi! > > I have certain design problem, which I cannot solve elegantly. Maybe > you know some good design patterns for this kind of tasks. > > Task: > > We have a model which has two kinds of objects: groups and elements. > Groups can hold other groups (subgroups) and elements. It's a simple > directory tree, for example. We would like to display it in a tree > view (which sound good for this kind of model). What is more required, > for groups and elements there are different sets of operations, which > should be available under right click. For example for group, there > should be operations: 'add element' and 'add group', and for element > there should be 'change properties'. > > Do you know any smart way to achieve this? The simplest way is to ask > for the class and display operations accordingly. But from the first > day with OO programming I have heard, that asking for class is wrong. > But I can hardly see any easy and more maintainable solution for this > problem. Could you help me with this? You don't ask *for* the class. You ask the class itself (or better, the object you currently deal with) what operations it supports. Your treeview-code then gets a list of strings for example (or better, a list of tuples (action, menuentry) ) that it uses to build the context-menu. When a given entry is selected, you then ask the object again to perform the action on itself, by passing the action-name. Or invoking a method called that way, or some such. Thus your treeview-code is completely generic and easily extendable with new functionality. There are variations of this scheme, if you don't want to "pollute" your model-classes with view/controller-logic. Then you need some sort of ActionFactory or something like that, which eventually somewhere might resort to a hard-coded list of class-to-action-mappings. Diez From jakecjacobson at gmail.com Thu Jan 8 11:44:26 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Thu, 8 Jan 2009 08:44:26 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> <341b04d3-10be-4a29-b170-fd6ec3a2be51@k8g2000yqn.googlegroups.com> Message-ID: <612e02a4-543c-46fd-8aa6-312f8c51a6fd@r15g2000prd.googlegroups.com> On Jan 7, 3:56?pm, jakecjacobson wrote: > On Jan 7, 2:11?pm, jakecjacobson wrote: > > > > > On Jan 7, 12:32?pm, jakecjacobson wrote: > > > > Hi, > > > > I need to write a simple Python script that I can connect to a FTP > > > server and download files from the server to my local box. ?I am > > > required to go through a FTP Proxy and I don't see any examples on how > > > to do this. ?The FTP proxy doesn't require username or password to > > > connect but the FTP server that I am connecting to does. > > > > Any examples on how to do this would be greatly appreciated. ?I am > > > limited to using Python version 2.4.3 on a Linux box. > > > This is what I have tried so far, > > > import urllib > > > proxies = {'ftp':'ftp://proxy_server:21'} > > ftp_server = 'ftp.somecompany.com' > > ftp_port='21' > > username = 'aaaa' > > password = 'secretPW' > > > ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + > > ftp_port > > > data = urllib.urlopen(ftp_string, proxies=proxies) > > > data=urllib.urlopen(req).read() > > > print data > > > I get the following error: > > > Traceback (most recent call last): > > ? File "./ftptest.py", line 22, in ? > > ? ? data = urllib.urlopen(ftp_server, proxies=proxies) > > ? File "/usr/lib/python2.4/urllib.py", line 82, in urlopen > > ? ? return opener.open(url) > > ? File "/usr/lib/python2.4/urllib.py", line 190, in open > > ? ? return getattr(self, name)(url) > > ? File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp > > ? ? host, path = splithost(url) > > ? File "/usr/lib/python2.4/urllib.py", line 949, in splithost > > ? ? match = _hostprog.match(url) > > TypeError: expected string or buffer > > I might be getting closer. ?Now I am getting "I/O error(ftp error): > (111, 'Connection refused')" error with the following code: > > import urllib2 > > proxies = {'ftp':'ftp://proxy_server:21'} > ftp_server = 'ftp.somecompany.com' > ftp_port='21' > username = 'aaaa' > password = 'secretPW' > > password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() > top_level_url = ftp_server > password_mgr.add_password(None, top_level_url, username, password) > > proxy_support = urllib2.ProxyHandler(proxies) > handler = urllib2.HTTPBasicAuthHandler(password_mgr) > opener = urllib2.build_opener(proxy_support) > opener = urllib2.build_opener(handler) > a_url = 'ftp://' + ftp_server + ':' + ftp_port + '/' > print a_url > > try: > ? ? ? ? data = opener.open(a_url) > ? ? ? ? print data > except IOError, (errno, strerror): > ? ? ? ? print "I/O error(%s): %s" % (errno, strerror) I tried the same code from a different box and got a different error message: I/O error(ftp error): 501 USER format: proxy-user:auth- method at destination. Closing connection. My guess is that my original box couldn't connect with the firewall proxy so I was getting a connection refused error. Now it appears that the password mgr has an issue if I understand the error correctly. I really hope that someone out in the Python Community can give me a pointer. From deets at nospam.web.de Thu Jan 8 11:48:39 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:48:39 +0100 Subject: linked list with cycle structure References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: <6smp37F763pbU2@mid.uni-berlin.de> David Hl??ik wrote: > Hi, > > so okay, i will create a helping set, where i will be adding elements > ID, when element ID will be allready in my helping set i will stop and > count number of elements in helping set. This is how long my cycled > linked list is. > But what if i have another condition , and that is *i can use only > helping memory with constant size* ? This means i am not able to > create any set and adding elements there. I need to have a constant > size variables . This is complication a complication for me. This isn't to hard - think about what you are really interested in - knowing if *all* other elements are already counted, or a specific one? You can get away with only one, to detect the cycle and abort. Diez From ZeeGeek at gmail.com Thu Jan 8 11:52:18 2009 From: ZeeGeek at gmail.com (ZeeGeek) Date: Thu, 8 Jan 2009 08:52:18 -0800 (PST) Subject: socket and thread Message-ID: <9a013936-c5b2-4671-ae7d-138a57695a8c@s1g2000prg.googlegroups.com> I'm writing a small program which uses different threads to monitor an IMAP mailbox and an RSS feed. If network is not available when the program starts, both threads will sleep for a while and try again. It seems that the first thread succeeds when the network becomes available will cause the other thread to always give a gaierror "No address associated with hostname". The weird thing is that this only happens when the program starts with network unavailable. If network is available when the program starts, both threads work well, even if the network drops in the middle, the threads can recover properly when the network comes back alive. Is Python socket thread-unsafe or is it because of some other problems? Thanks. From deets at nospam.web.de Thu Jan 8 11:52:21 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:52:21 +0100 Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> Message-ID: <6smpa5F763pbU3@mid.uni-berlin.de> Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, except for having to write > a method giving some form of a class name and then basing on this > classname display operations. I know this solution, but this is what I > would like to evade. > It is *not* the same - the code that knows about the operations is not in the treeview-logic anymore, but local to the class that can actually deal with the operations. Diez From kyosohma at gmail.com Thu Jan 8 12:11:44 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 8 Jan 2009 09:11:44 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: <1a939f2e-90c5-4b25-812f-dfa2b3da53f8@r15g2000prh.googlegroups.com> On Jan 8, 9:16?am, tryg.ol... at gmail.com wrote: > Hello - > > I managed to get a cookie set. ?Now I want to delete it but it is not > working. > > Do I need to do another 'set-cookie' in the HTTP header? ?I tried > (code below setting expires to 0) and it didn't work. > c = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) > c["mycook"]["expires"] = 0 > print c > > In case its useful, here is how I set my cookie: > c = Cookie.SimpleCookie() > c["mycook"] = "Tryg" > c["mycook"]["expires"] = 60*60*24 > c["mycook"]["comment"] = "" > c["mycook"]["path"] ? ?= "/" > c["mycook"]["domain"] ?= "" > c["mycook"]["secure"] ?= "" > print c > > Thanks > Tryg Well, if you know where the cookie file is stored, you should be able to do this: os.remove(path) Mike From steve at holdenweb.com Thu Jan 8 12:15:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 12:15:03 -0500 Subject: "python -3" not working as expected In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > [Python 2.6.1] > > Hi, > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > incompatibilities") against a test file that only contains "print > 'test'". > > Unfortunately I saw no warnings about print becoming a function in > Python 3 ("print()"). Where is the problem? > I *believe* that's not flagged because 2to3 will fix it automatically. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 12:17:13 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 12:17:13 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Ross wrote: > Scott David Daniels wrote: >> Ross wrote: >>> There seems to be no shortage of information around on how to use the >>> time module, for example to use time.ctime() and push it into >>> strftime and get something nice out the other side, but I haven't >>> found anything helpful in going the other way. >> >> As to a paucity of conversion formatting, there is no magic way to take >> everyone's way of putting date and time information in text and convert >> it to unambiguous format, in part because there are too many different >> and contradictory formats. When I write dates, I know what I intended; >> when I read dates, I guess what the author intended. >> >> Have you read the entire time module document? If so, which functions >> in that module take strings as arguments? >> >>> That is, given some formatted text describing times - is there >>> something that makes it easy to calculate time differences, or do I >>> have to index my way through the string pulling out characters, >>> converting to integers etc... >>> >>> Data is formatted: >>> t1 = 09:12:10 >>> t2 = 11:22:14 >>> I want to calculate tdiff = t2-t1 >> >> Do you do any work yourself? Show us your attempts. This looks like >> a trivial exercise. It seems that for less than four times the effort >> of asking your question you might have found the answer. >> >> Perhaps I am being too cranky this morning. > > Jeeze, you're quite an ass aren't you? And how did sending this message improve things? Let's keep it civil, guys. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From theller at python.net Thu Jan 8 12:29:16 2009 From: theller at python.net (Thomas Heller) Date: Thu, 08 Jan 2009 18:29:16 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> Message-ID: <6smrejF74ss9U1@mid.individual.net> Nick Craig-Wood schrieb: > Thomas Heller wrote: >> Nick Craig-Wood schrieb: >> > Interesting - I didn't know about h2xml and xml2py before and I've >> > done lots of ctypes wrapping! Something to help with the initial >> > drudge work of converting the structures would be very helpful. >> > >> > ( http://pypi.python.org/pypi/ctypeslib/ ) >> > >> > I gave it a quick go and it worked fine. I had to edit the XML in one >> > place to make it acceptable (removing a u from a hex number). >> >> If you are using a recent version of gccxml, then you should use the >> ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should >> really merge the gccxml-0.9 branch into the trunk;-) >> >> If you are already using the branch and the XML file is not accepted, >> then could you please provide a short C code snippet that reproduces >> the problem so that I can fix it? > > I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess > doesn't have the code from the branch in. I meant the branch in the repository where ctypeslib lives in. Anyway, it doesn't matter anymore since I merged that branch into the ctypeslib trunk. Now the problem with the 'u' suffix that you mentioned should be fixed, and I also made a quick change so that the sized integer types from stdint.h are generated correctly. So, please update your ctypeslib installation and trey again;-) Thomas From jason.ribeiro at gmail.com Thu Jan 8 12:30:58 2009 From: jason.ribeiro at gmail.com (Jason Ribeiro) Date: Thu, 8 Jan 2009 12:30:58 -0500 Subject: #python IRC help - my internet provider is banned! In-Reply-To: References: Message-ID: I am not a #python operator, but do note that #python is +r so you must be registered and identified to join the channel, see http://freenode.net/faq.shtml#userregistration . Otherwise, giving the exact ban that is affecting you or your hostmask would probably be helpful to the operators. On Wed, Jan 7, 2009 at 1:52 PM, simonh wrote: > On Jan 7, 6:30 pm, "Mildew Spores" wrote: > > What? Sounds a bit unlikely unless its Virgin.. > > I'd imagine it might be that your isp needs to get itself off a black > list. > > Brian > > > > -- > > My Hotmail Account > > mildew_spo... at hotmail.com > > > > "simonh" wrote in message > > > > news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com. > .. > > > > > Hi. Not sure if anyone can help here, but I'm trying to access #python > > > and have found out that my ISP has a blanket ban (for some reason). > > > Does anyone know how I can contact an operator to join? Thanks. > > > > > > > ISP is bethere and client is Chatzilla. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Jan 8 12:45:56 2009 From: mrkafk at gmail.com (mk) Date: Thu, 08 Jan 2009 18:45:56 +0100 Subject: How to Delete a Cookie? In-Reply-To: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: tryg.olson at gmail.com wrote: > Hello - > > I managed to get a cookie set. Now I want to delete it but it is not > working. Why struggle with this manually? Isn't it better to learn a bit of framework like Pylons and have it all done for you (e.g. in Pylons you have response.delete_cookie method)? Regards, mk From tim.arnold at sas.com Thu Jan 8 12:48:26 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 8 Jan 2009 12:48:26 -0500 Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: "floob" wrote in message news:0af87074-6d9c-41a8-98ec-501f6f37bf9a at s1g2000prg.googlegroups.com... >I have been searching for a way to print the official Python > documentation into some kind of book (for my own uses). I don't > really care if it's printed on newspaper and bound with elmer's > glue ... any way I can get relatively recent _official documentation_ > in print form will do. > > I'm on the go a lot, and can't read for long periods of time on LCD > screens anyhow (so having a laptop is not my solution). Until eBook > readers grow up a bit, I'm stuck trying to print the documentation > that I REALLY need to read and absorb. > > Lulu.com is an option, but it would cost something around $100 US > before shipping to get everything printed. Also, I would have to > split up some larger documents into Volumes, which I'd rather not have > to do. > > Has anyone tried this before? Is the documentation already available > in print? > > Thanks, > > drfloob just a datapoint, but I used lulu.com to print the latex sources (525 pages) hardbound for a cost of $25 US. --Tim Arnold From nad at acm.org Thu Jan 8 12:56:11 2009 From: nad at acm.org (Ned Deily) Date: Thu, 08 Jan 2009 09:56:11 -0800 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: In article , Unknown wrote: > On 2009-01-08, Alex van der Spek wrote: > > Thanks much, that makes sense! > Well, that's the correct explanation. > Whether that feature makes sense or not is debatable. The debate is over! In Py 3.0, octal literals changed from 07 to 0o7; the old format gets an 'invalid token' parsing error. -- Ned Deily, nad at acm.org From brendandetracey at yahoo.com Thu Jan 8 12:58:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 8 Jan 2009 09:58:46 -0800 (PST) Subject: ftplib - 226 message not received Message-ID: I am trying to download a file within a very large zipfile. I need two partial downloads of the zipfile. The first to get the file byte offset, the second to get the file itself which I then inflate. I am implementing the partial downloads as follows: con = ftp.transfercmd('RETR ' + filename, rest_offset) # the data socket while True: block = con.recv(blocksize) # stop transfer while it isn't finished yet if bytes_recv >= buf_length: break elif not block: break buf = ''.join([buf, block]) bytes_recv += len(block) con.close() My problem is that even though the socket is closed, I have no way to receive the 226 response from server so I can proceed with the next download. Of course I could close the ftp connection entirely and open a new one, but I am hoping to avoid doing so. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 13:02:45 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 19:02:45 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: Message-ID: <49664d71$0$15794$426a74cc@news.free.fr> Zac Burns a ?crit : > I have a decorator in a class Why ? (snip) > The exception that I get when using it as a staticmethod and try to > use it in the baseclass is "TypeError: 'staticmethod' object is not > callable". > When it is not staticmethod the exception I get in the extension class > is is "TypeError: unbound method decorateTest() must be called with C > instance as first argument (got function instance instead)" Just make it a plain function and you'll be fine. From houdinihound69 at gmail.com Thu Jan 8 13:16:28 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 10:16:28 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> > c["mycook"]["expires"] = 0 Set ["expires"] using the following format to any time less than current (which causes the browser to delete the cookie). Here's a function I use to return a cookie expiry timestamp, negative values passed in result in cookie being deleted. def cookie_expiry_date(numdays): """ Returns a cookie expiry date in the required format. -ve value in = kill cookie. `expires` should be a string in the format "Wdy, DD-Mon-YY HH:MM:SS GMT" NOTE! Must use [expires] because earlier IE versions don't support [max-age]. """ from datetime import date, timedelta new = date.today() + timedelta(days = numdays) return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") Usage: c["mycook"]["expires"] = cookie_expiry_date(-10) # any negative value will remove cookie HTH, JC From esnow at verio.net Thu Jan 8 13:17:44 2009 From: esnow at verio.net (Eric Snow) Date: Thu, 8 Jan 2009 10:17:44 -0800 (PST) Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> <49652b53$0$25195$9b622d9e@news.freenet.de> Message-ID: On Jan 7, 3:23?pm, "Martin v. L?wis" wrote: > > Thanks for the responses. ?What I mean is when a python process is > > interrupted and does not get a chance to clean everything up then what > > is a good way to do so? ?For instance, I have a script that uses child > > ptys to facilitate ssh connections (I'm using pxssh). ?When I ^C the > > python process I am left with the child processes running and the ssh > > connections open. ?Naturally I run out of ttys if this happens too > > much, which I have had happen. ?So if python does not get a chance to > > take care of those, what is a good way to do so? ?Does a try/finally > > or a with statement address that? ?Thanks! > > That's strange. When the parent process terminates, the tty master > should get closed, causing the slave to be closed as well, in addition > to sending a SIGHUP signal to the child, which ssh should interpret > as terminating. > > Perhaps the problem is that the master socket *doesn't* get closed? > I see that pexpect closes all file descriptors in the child before > invoking exec. Could it be that you are starting addition child > processes which inherit the master socket? > > Regards, > Martin Thanks. I'll look into that. -eric From esnow at verio.net Thu Jan 8 13:21:58 2009 From: esnow at verio.net (Eric Snow) Date: Thu, 8 Jan 2009 10:21:58 -0800 (PST) Subject: del behavior 2 References: Message-ID: <882912bf-d016-4645-80fa-4f754b1a6a09@w1g2000prk.googlegroups.com> On Jan 7, 12:42?pm, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. ?Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. ?That's fine. ?But how do any > of you deal with things that are left open because you did not get a > chance to close them? ?How do you clean up after the fact? ?Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > -eric So I see a couple of options here. Thanks for all the suggestions everyone. Here is what I have: - use try/finally to clean things up - set a handler using signal.signal to clean everything up There is also having try/except for more specific behvaior, like for KeyboardInterrupt, but I am not sure I need that much specificity. Again, thanks for all the great help. Really cleared things up for me. -eric From zac256 at gmail.com Thu Jan 8 13:27:45 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 10:27:45 -0800 Subject: cPickle vs pickle discrepancy In-Reply-To: References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: <333edbe80901081027g49ef3319xd24d931914d4dd42@mail.gmail.com> Thanks for your patience waiting for me to isolate the problem. | Package --__init__.py ->empty --Package.py ->empty --Module.py import cPickle class C(object): pass def fail(): return cPickle.dumps(C(), -1) import Package.Module Package.Module.fail() The failure seems to happen because pickle correctly does an absolute import and cPickle incorrectly relatively imports Package.py and fails to find Module underneath. The package and the module named package was because in there was a main class defined with the same name as the package in that file and Module.py contained support code for the package. -Zac -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Jan 6, 2009 at 4:57 PM, Gabriel Genellina wrote: > En Mon, 05 Jan 2009 23:04:30 -0200, Zac Burns escribi?: > >> I have a module that attempts to pickle classes defined in that module. >> >> I get an error of the form: >> PicklingError: Can't pickle : import >> of module Module.SubModule failed >> when using cPickle (protocol -1, python version 2.5.1). >> >> The module has already been imported and is in sys.modules when the >> exception is raised. > > There is no thing as a "submodule"; very likely you have a package, and a > module inside that package. > - always import the "submodules" from the package, not directly (relative > imports are safer) > - in general, don't play with PYTHONPATH, sys.path, and such things. > - don't directly execute a module inside a package (it's name is always > __main__ and it doesn't even "know" it's part of a package). > >> Using pickle instead of cPickle works, but the section of the code is >> performance critical. > > Could you provide a short example? I'd say that if you stick to the above > rules you won't have the issue again, but anyway I'd like to know in which > cases Pickle and cPickle differ. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From brendandetracey at yahoo.com Thu Jan 8 13:32:40 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 8 Jan 2009 10:32:40 -0800 (PST) Subject: ftplib - 226 message not received References: Message-ID: <3caa2010-80c9-45cf-8886-6ef8844d55ff@o40g2000prn.googlegroups.com> Okay, found it on my own. ftp.voidresp() is what is needed, and it does _not_ seem to be in the Python documentation for ftplib. On Jan 8, 1:58?pm, Brendan wrote: > I am trying to download a file within a very large zipfile. I need two > partial downloads of the zipfile. The first to get the file byte > offset, the second to get the file itself which I then inflate. > > I am implementing the partial downloads as follows: > > con = ftp.transfercmd('RETR ' + filename, rest_offset) ?# the data > socket > while True: > ? ? block = con.recv(blocksize) > # stop transfer while it isn't finished yet > ? ? if bytes_recv >= buf_length: > ? ? ? ? break > ? ? elif not block: > ? ? ? ? break > ? ? buf = ''.join([buf, block]) > ? ? bytes_recv += len(block) > con.close() > > My problem is that even though the socket is closed, I have no way to > receive the 226 response from server so I can proceed with the next > download. ?Of course I could close the ftp connection entirely and > open a new one, but I am hoping to avoid doing so. From tryg.olson at gmail.com Thu Jan 8 13:33:02 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 10:33:02 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> Message-ID: On Jan 8, 1:16 pm, Jose C wrote: > > c["mycook"]["expires"] = 0 > > Set ["expires"] using the following format to any time less than > current (which causes the browser to delete the cookie). > Here's a function I use to return a cookie expiry timestamp, negative > values passed in result in cookie being deleted. > > def cookie_expiry_date(numdays): > """ Returns a cookie expiry date in the required format. -ve > value in = kill cookie. > `expires` should be a string in the format "Wdy, DD-Mon-YY > HH:MM:SS GMT" > NOTE! Must use [expires] because earlier IE versions don't > support [max-age]. > """ > from datetime import date, timedelta > new = date.today() + timedelta(days = numdays) > return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") > > Usage: > c["mycook"]["expires"] = cookie_expiry_date(-10) # any negative value > will remove cookie > > HTH, > JC Jose C's piece of code works to delete the cookie as does setting ["expires"]=0 but ONLY as long as I also set the path. Why is this? So what would be the best way to do this. I tried reading in the existing cookie (b), creating a new cookie (c) with all the same values except for the "expires" but this did not get my cookie deleted. b = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) c = Cookie.SimpleCookie() c[cookieName] = b[cookieName].value c[cookieName]["expires"] = 0 c[cookieName]["path"] = b[cookieName]["path"] print c From mdw at distorted.org.uk Thu Jan 8 13:33:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 18:33:50 +0000 (UTC) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: [Steven's message hasn't reached my server, so I'll reply to it here. Sorry if this is confusing.] Aaron Brady wrote: > On Jan 8, 1:45 am, Steven D'Aprano > wrote: > > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > > > > The `they're just objects' model is very simple, but gets tied up in > > > knots explaining things. The `it's all references' model is only a > > > little more complicated, but explains everything. > > > > But it *over* explains, because it implies things that "everybody knows" > > about references in other languages that aren't true for Python. I addressed this elsewhere. Summary: `pass-by-reference' is a different thing to `all you manipulate are references': Python does pass-by-value, but the things it passes -- by value -- are references. (The `pass-by-*' notions are confusingly named anyway. Pass-by-name doesn't actually involve names at all.) > > Of course it's not literally true that "everybody knows" that you > > can use references to implement a swap(x, y) procedure. But people > > coming from a C or Pascal background tend to assume that everything > > is like C/Pascal, and there are a lot of them. If C was a rare, > > unfamiliar language, my opposition to using the term "reference" > > would be a lot milder. Maybe in another five years? I agree with the comment about Pascal, but C is actually pretty similar to Python here. C only does pass-by-value. If you want a function to modify your variable, you have to pass a pointer value which points to it. Python has no pointer values, so you need a different hack. The hack usually involves lists. (Though it's easier in the main to return compound data objects like tuples. I don't suppose that a proposal for true multiple return values would go down well here. No, didn't think so...) > > Okay, the abstraction has leaked again... are the paperweights references > > to the objects, or the names we've bound objects to? I'm confused... They're the references to the objects. You don't bind names to objects. You bind names slots in which you store references. This discussion -- I'd call it an argument, but that might give the wrong impression, because I think we're being remarkably civil and constructive by the standards of Usenet arguments! -- hasn't started on the topic of variable bindings or environments yet. > > How do we deal with anonymous objects in your model? > > > > -- > > Steven > > Mark, hi, Steven, pleasure as always. Hello. ;-) > Neither side is perfect or wild; (Do admit it); It's true. > How do we decide what is best for newcomers to Python, depending on > background? That I really don't know. I'm not good at teaching total beginners (does it show?) because I'm too enmired in the theory. (It doesn't help that I go off on tangents about how language X does something similar but subtly different all the time, though my rich background comes in very useful all over the place and that's something I think is worth sharing.) It probably doesn't help that I came to Python with a thorough understanding of Scheme (among many others) under my belt, because many Scheme concepts carry over directly, including the data model (it's all references) and the variable model (nested, mutable, lexical environments with closures). What I am pretty sure of is that references are going to have to enter the picture at some point, because other models get too complicated. Oh, while I remember: the `distributed Python' model, with auto-updating copies, only works for sharing. Circular structures still require actual references or a Tardis. -- [mdw] From benjamin at python.org Thu Jan 8 13:37:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 8 Jan 2009 18:37:21 +0000 (UTC) Subject: "python -3" not working as expected References: Message-ID: Steve Holden holdenweb.com> writes: > Thorsten Kampe wrote: > > Unfortunately I saw no warnings about print becoming a function in > > Python 3 ("print()"). Where is the problem? > > > I *believe* that's not flagged because 2to3 will fix it automatically. This is correct; there's not much point to adding py3k warning for things that 2to3 can fix easily. From p at ulmcnett.com Thu Jan 8 13:42:13 2009 From: p at ulmcnett.com (Paul McNett) Date: Thu, 08 Jan 2009 10:42:13 -0800 Subject: Replying to list messages In-Reply-To: <878wpmguop.fsf@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> <878wpmguop.fsf@benfinney.id.au> Message-ID: <49664905.2010806@ulmcnett.com> Ben Finney wrote: > Paul McNett

writes: >> But arguing about this here isn't going to change anything: opinions >> differ just like tabs/spaces and bottom-post/top-post. > > In cases like this, one side can simply be wrong :-) > > Best of luck getting your programs behaving as you want them to! BTW, I agree with you that in an ideal, pure world mailing lists wouldn't munge the reply-to field, but when 80% of the people use email clients that don't support reply-list, the practical thing to do as a list admin that wants to avoid having to explain over and over again that "your client software is broken" is to simply swallow some pride and munge the reply-to. Now, 99% of the users are happy, and the remaining 1% are elite enough to understand how to get around any problems this caused. Happy is good. Paul From pavlovevidence at gmail.com Thu Jan 8 13:49:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 10:49:03 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> <1ZednYe8UMYq2_jUnZ2dnUVZ_rrinZ2d@pdx.net> Message-ID: On Jan 7, 6:21?pm, Scott David Daniels wrote: > Adal Chiriliuc wrote: > > On Jan 7, 10:15 pm, Bruno Desthuilliers > > wrote: > >> ... I'd either keep the argument as a boolean but rename it "ascending" ... > > > Well, I lied a bit :-p ?.... > > But what if we can't solve it as elegantly, and we need to ... > > > Should we typecheck in this case to ensure that if we pass a string > > for "fast_mode" we will raise an exception? > > Why are you concerned only with type errors on inputs? > Even if you could do exhaustive checking of input parameters to > make sure they are the only acceptable values, what prevents your > user from providing the wrong valid value? ?What made you pick on > type errors in the first place? ?If it turns out that an argument > of 422 is a typo for 42, why is that less of a problem? ?Just because > you are used to systems where one kind of error is always caught does > not really make you invulnerable. ?You'll have no problem telling > your users that the 422 is their fault. ?Why do you have such > certainty that passing in "nonsense" as a boolean is a failure > you need to deal with? I'm going to play Devil's Advocate here. The motivation here is not "we want type safety" but "our unit tests can't register this deliberate error because it passes silently". Presumably if they had a function that accepted integers, and 442 was an invalid value, and the function failed silently in a unit test, they would also consider whether it should instead fail loudly. It's always a judgment call how much to screen for bad input, but type errors aren't different from any other error in this regard. Sometimes it's appropriate (note: not, IMHO, in this case), just like it's sometimes appropriate to check for 442. Carl Banks From mhjorleifsson at gmail.com Thu Jan 8 13:49:54 2009 From: mhjorleifsson at gmail.com (Mike Hjorleifsson) Date: Thu, 8 Jan 2009 10:49:54 -0800 (PST) Subject: sftp with no password from python References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> Message-ID: <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> On Jan 8, 10:39?am, loial wrote: > Is it possible to use sftp without a password from python? Yes you can use keys you preestablish between the server and client so you dont need passwords, i do this on all my servers then lock off the ability to accept passwords at all, this way no one can dictionary attack my ssh servers. From luke.leighton at googlemail.com Thu Jan 8 13:50:23 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 8 Jan 2009 10:50:23 -0800 (PST) Subject: compiling python2.5 on linux under wine References: Message-ID: > ... aaaand, that means disabling setup.py or hacking it significantly > to support a win32 build, e.g. to build pyexpat, detect which modules > are left, etc. by examining the remaining vcproj files in PCbuild. ok - i started the hacking. the first bit of hacking is this, in distutils/sysconfig.py, added to _init_nt() try: filename = get_makefile_filename() parse_makefile(filename, g) except IOError, msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror raise DistutilsPlatformError(my_msg) # load the installed pyconfig.h: try: prefix = EXEC_PREFIX prefix = os.path.join(prefix, "PC") filename = os.path.join(prefix, "pyconfig.h") parse_config_h(file(filename), g) except IOError, msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror raise DistutilsPlatformError(my_msg) global _config_vars _config_vars = g that gets me part-way - at least i get... oh dear : self.build_extensions() File "../setup.py", line 183, in build_extensions self.compiler.set_executables(**args) File "Z:\mnt\src\python2.5-2.5.2\lib\distutils\ccompiler.py", line 165, in set_executables (key, self.__class__.__name__) ValueError: unknown executable 'compiler_so' for class MSVCCompiler whoops :) so, next, we hack in a compiler, in to ... ooo, let's saaay... distutils/cygwinccompiler.py, just for fun. now we get this! winegcc -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IZ:\mnt\src\python2.5-2.5.2\./Include -I. - IInclude -I../Include -I/usr/local/include -IZ:\mnt\src \python2.5-2.5.2\include -IZ:\mnt\src\python2.5-2.5.2\PC -c Z:\mnt\src \python2.5-2.5.2\Modules\_ctypes/_ctypes_test.c -o z:\mnt\src \python2.5-2.5.2\modules\_ctypes\_ctypes_test.o wha-hey! but... oh dear. oh dear number 1) firstly, err.... this is cross-compiling - those path names are bullshit because actually we're compiling on.... LINUX damnit, not windows. hmm.... there's something to work around that one, perhaps, by installing the mingw32 compiler under wine (o god i've done that before, it's dreadfully slow) oh dear number 2) File "Z:\mnt\src\python2.5-2.5.2\lib\os.py", line 562, in spawnv return _spawnvef(mode, file, args, None, execv) File "Z:\mnt\src\python2.5-2.5.2\lib\os.py", line 545, in _spawnvef wpid, sts = waitpid(pid, 0) NameError: global name 'waitpid' is not defined err.... oh - ok, found another missing function: spawnv. so, added that, in PC/pcbuild.h: #ifdef __WINE__ #define HAVE_SPAWNV #endif and after some futzing around with yet more #ifdefs in posixmodule.c we have another build - this time using wine's spawnv so it doesn't try to find a non-existent waitpid aaannnd SPLAT yesss, we get the crash-output from winegcc: Failed to configure _ctypes module building '_ctypes_test' extension winegcc -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IZ:\mnt\src\python2.5-2.5.2\./Include -I. - IInclude -I../Include -I/usr/local/include -IZ:\mnt\src \python2.5-2.5.2\include -IZ:\mnt\src\python2.5-2.5.2\PC -c Z:\mnt\src \python2.5-2.5.2\Modules\_ctypes/_ctypes_test.c -o z:\mnt\src \python2.5-2.5.2\modules\_ctypes\_ctypes_test.o wine: Unhandled page fault on read access to 0x7265704f at address 0x601ec25b (thread 001c), starting debugger... Unhandled exception: page fault on read access to 0x7265704f in 32-bit code (0x601ec25b). Register dump: CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b EIP:601ec25b ESP:0032c70c EBP:0032c718 EFLAGS:00010206( - 00 - RIP1) EAX:7265704f EBX:7bc8a7a4 ECX:00000003 EDX:604ab3d7 ESI:0032c848 EDI:7265704f Stack dump: 0x0032c70c: 7bc6859d 7265704f 6056a0b8 0032c788 0x0032c71c: 603fd0eb 7265704f 006e9544 001bc84c 0x0032c72c: 006c574c 6056b82c 605721a0 00000002 0x0032c73c: 0032c7d8 718e21fe 0016329c 7265704f 0x0032c74c: 00730065 002e0074 0000006f 00159320 0x0032c75c: 603aa590 001b3f0c 005086e0 00000004 Backtrace: =>1 0x601ec25b strlen+0xb() in libc.so.6 (0x0032c718) fixme:dbghelp_dwarf:dwarf2_parse_variable Unsupported form for const value degToRad (a) 2 0x603fd0eb do_mkvalue+0x3db(p_format=, p_va=, flags=0x0) [/mnt/src/python2.5-2.5.2/ build/../Python/modsupport.c:419] in python (0x0032c788) 3 0x603fcc6d do_mktuple+0x7d(p_format=0x32c848, p_va=0x32c844, endchar=0x29, n=0x2, flags=0x0) [/mnt/src/python2.5-2.5.2/build/../ Python/modsupport.c:268] in python (0x0032c7b8) ..... ..... hey, this is fun! let's try a crazed compile of python and see what falls over, wheeeee :) ... much as this seems to be consuming much of my time, for some bizarre reason i just can't seem to stop. anyway - yes, this is effectively cross-compiling, and so the python25.exe and environment created is unfortunately expecting to see a windows-like environment. bugger. i'll ask on the wine lists if there's a "back-translator". winegcc and wineg++ are wrapper-scripts that wrap gcc and g++ to "make it look like" you're compiling for win32 when in fact you're compiling under linux. if there was a back-translation of that concept, that recognised z: \blahblah and back-translated it into /unix/blah then it would be possible to get away with specifying _that_ script as the compiler, which would then pass winegcc as _its_ script.... yuukkk! From zac256 at gmail.com Thu Jan 8 13:54:31 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 10:54:31 -0800 Subject: Making a decorator a staticmethod Message-ID: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> I have a decorator in a class to be used by that class and by inheriting classes ###### class C(object): @staticmethod # With this line enabled or disabled usage in either C or D will be broken. To see that D works remember to remove usage in C def decorateTest(func): def newFunc(*args, **kwargs): print args, kwargs return func(*args, **kwargs) return newFunc @decorateTest def testDecorated(self): return None class D(C): @C.decorateTest def test2(self): return None ###### The exception that I get when using it as a staticmethod and try to use it in the baseclass is "TypeError: 'staticmethod' object is not callable". When it is not staticmethod the exception I get in the extension class is is "TypeError: unbound method decorateTest() must be called with C instance as first argument (got function instance instead)" Python version is 2.5.1 -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From houdinihound69 at gmail.com Thu Jan 8 13:58:05 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 10:58:05 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> Message-ID: <51303f95-3e67-4baf-9b90-93300fcb9605@k36g2000pri.googlegroups.com> On Jan 8, 10:33?am, tryg.ol... at gmail.com wrote: > On Jan 8, 1:16 pm, Jose C wrote: > > > > > > c["mycook"]["expires"] = 0 > > > Set ["expires"] using the following format to any time less than > > current (which causes the browser to delete the cookie). > > Here's a function I use to return a cookie expiry timestamp, negative > > values passed in result in cookie being deleted. > > > def cookie_expiry_date(numdays): > > ? ? """ Returns a cookie expiry date in the required format. ?-ve > > value in = kill cookie. > > ? ? `expires` should be a string in the format "Wdy, DD-Mon-YY > > HH:MM:SS GMT" > > ? ? NOTE! ?Must use [expires] because earlier IE versions don't > > support [max-age]. > > ? ? """ > > ? ? from datetime import date, timedelta > > ? ? new = date.today() + timedelta(days = numdays) > > ? ? return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") > > > Usage: > > c["mycook"]["expires"] = cookie_expiry_date(-10) ?# any negative value > > will remove cookie > > > HTH, > > JC > > Jose C's piece of code works to delete the cookie as does setting > ["expires"]=0 but ONLY as long as I also set the path. ?Why is this? The path specifies which directory the cookie is active. Usually the path is set to /, which means the cookie is valid throughout the entire domain, but you could set it to /mydir meaning it would only be active for pages within /mydir. > So what would be the best way to do this. ?I tried reading in the > existing cookie (b), creating a new cookie (c) with all the same > values except for the "expires" but this did not get my cookie > deleted. To kill the cookie, simply set a cookie with the same name (and path) and a past date (or 0, although IIRC there was some issue with 0 being used on a particular browser some time ago, can't remember which on at the moment) as an 'expires' parameter, is enough to tell the browser to kill an existing cookie with that same name, regardles of it's value or previous expiry, etc. Basically, when you set a cookie, the browser overwrites the previous one of the same name if it exists. If not, it creates a new cookie with your specified parameters. So in your case, when you want to kill the cookie you set previously, you should be able to just set a cookie of the exact same name, path and 'expire' it appropriately, and the browser takes care of the rest. Don't worry about assigning it's previous value, the browser is just going to delete it anyway. JC From marduk at letterboxes.org Thu Jan 8 14:07:34 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 08 Jan 2009 14:07:34 -0500 Subject: How do you write to the printer ? In-Reply-To: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: <1231441654.3358.3.camel@localhost.localdomain> On Wed, 2009-01-07 at 16:46 -0600, David at bag.python.org wrote: > Can find nothing in the on-line docs or a book. > Groping in the dark I attempted : > > script24 > import io > io.open('stdprn','w') # accepted > stdprn.write('hello printer') # fails < stdprn is not defined > You didn't specify what platform you are running on, but the first problem I see with the above is... well stdprn is not defined. Did you perhaps mean: sdtprn = io.open('stdprn', 'w') stdprn.write(...) However on a Linux system that will simply open and write to a file called 'stdprn' in your current directory. -a From houdinihound69 at gmail.com Thu Jan 8 14:07:44 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 11:07:44 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> <51303f95-3e67-4baf-9b90-93300fcb9605@k36g2000pri.googlegroups.com> Message-ID: <6e3d1e0c-0d96-40a6-adb2-b3bc10de8995@z28g2000prd.googlegroups.com> > To kill the cookie, simply set a cookie with the same name (and path) Actually you may not even need to specify the path. Just the name and expires param should do the trick. Haven't played with cookies in a while so try with and without the path. From mdw at distorted.org.uk Thu Jan 8 14:13:38 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 19:13:38 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> <6LqdnQurg-dMzPjUnZ2dnUVZ_uGdnZ2d@speakeasy.net> Message-ID: Erik Max Francis wrote: > Terry Reedy wrote: > > > >>> a='par'+'rot' > > >>> b='parrot' > > >>> a is b > > True > > One exactly doesn't really say much. It's implementation dependent, and > depends on the length of the string: > > >>> a = 'this is a much longer ' + 'parrot' > >>> b = 'this is a much longer parrot' > >>> a is b > False That Terry's example works is due to constant folding in the bytecode compiler. Consider: In [1]: a = 'parrot' In [2]: a is 'par' + 'rot' Out[2]: True Fair enough. But build the string in a more complicated way: In [3]: b = 'par' In [4]: a is b + 'rot' Out[4]: False What's going on? In the first case, the compiler notices that both operands to `+' are constants, and evaluates the concatenation at compile-time. The resulting constant string is then interned if it's short enough. Putting part of the string in a variable is enough to stymie this optimization -- the same compiler gets used in functions which can't assume that the variable will still have the same value as it does now. The concatenation method on strings doesn't try to intern the result, as that might be a runtime performance loss. > In practice, tests like these are pretty much never useful. It's > completely implementation dependent when and under what circumstances > fundamental immutable objects are reused, and it's not useful anyway; > what you care about is whether two objects are equal or not, not whether > they're the same object through some optimization behind the scenes. Absolutely. The examples above provide insight into how the specific implementation actually behaves; but that's of strictly academic interest. (Well, I find that sort of thing interesting, anyway.) -- [mdw] From zac256 at gmail.com Thu Jan 8 14:18:37 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 11:18:37 -0800 Subject: Making a decorator a staticmethod In-Reply-To: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <333edbe80901081118p2f6cfb8mda01a908bebf8f7d@mail.gmail.com> I've read the "Making staticmethod objects callable?" thread now, and would have to disagree that all the use cases are strange as stated at http://www.python.org/dev/summary/2006-03-01_2006-03-15/#making-staticmethod-objects-callable In my use case (not the example below) the decorator returns a function of the form def f(self, *args, **kwargs) which makes use of attributes on the instance self. So, it only makes sense to use the staticmethod in the class and in the baseclass. Making this decorator a module level function doesn't make sense here. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 10:54 AM, Zac Burns wrote: > I have a decorator in a class to be used by that class and by inheriting classes > > ###### > class C(object): > @staticmethod # With this line enabled or disabled usage in either C > or D will be broken. To see that D works remember to remove usage in C > def decorateTest(func): > def newFunc(*args, **kwargs): > print args, kwargs > return func(*args, **kwargs) > return newFunc > > @decorateTest > def testDecorated(self): > return None > class D(C): > @C.decorateTest > def test2(self): > return None > ###### > > The exception that I get when using it as a staticmethod and try to > use it in the baseclass is "TypeError: 'staticmethod' object is not > callable". > When it is not staticmethod the exception I get in the extension class > is is "TypeError: unbound method decorateTest() must be called with C > instance as first argument (got function instance instead)" > > Python version is 2.5.1 > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From tjreedy at udel.edu Thu Jan 8 14:32:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:32:57 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > > > On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch > wrote: > > Okay, I'm currently stuck with VBA / Excel in work and the following > paradigm: > > VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access > > Where I'd like to be is this > > Python ==> X ==> Open Office / (MySQL or other) for some > sufficiently useful value of X. > > Does it exist? Is it just a set of modules I need to be looking > for? or something else? > > > > Did you google search first? This is the second result for "Python > OpenOffice". > > http://wiki.services.openoffice.org/wiki/Python PyUNO is basically for working 'live' with OOo. There is also odfpy at http://opendocumentfellowship.com/development/projects/odfpy for working with open doc format documents as produced by OOo and other programs. From pavlovevidence at gmail.com Thu Jan 8 14:34:59 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 11:34:59 -0800 (PST) Subject: cPickle vs pickle discrepancy References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: On Jan 8, 12:27?pm, "Zac Burns" wrote: > Thanks for your patience waiting for me to isolate the problem. > > | Package > --__init__.py ->empty > --Package.py ->empty > --Module.py > ? ? ?import cPickle > ? ? ?class C(object): > ? ? ? ? pass > ? ? ?def fail(): > ? ? ? ? return cPickle.dumps(C(), -1) > > import Package.Module > Package.Module.fail() > > The failure seems to happen because pickle correctly does an absolute > import and cPickle incorrectly relatively imports Package.py and fails > to find Module underneath. > > The package and the module named package was because in there was a > main class defined with the same name as the package in that file and > Module.py contained support code for the package. I'd call it a bug. Nice detecitve work pinpointing it. I suspect the issue disappears (accidentally) in 2.6, though. From the What's New in Python 2.6 doc: C API: the PyImport_Import and PyImport_ImportModule functions now default to absolute imports, not relative imports. This will affect C extensions that import other modules. Presumably __import__ also defaults to absolute (since PyImport_Import calls it) so the two modules should both use absolute imports in 2.6. Carl Banks From tjreedy at udel.edu Thu Jan 8 14:40:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:40:24 -0500 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, The point is to put (and use) the information about what operations apply to instances in each class rather than in an external function. From mark.fink1 at googlemail.com Thu Jan 8 14:43:43 2009 From: mark.fink1 at googlemail.com (mark) Date: Thu, 8 Jan 2009 11:43:43 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> Message-ID: <1642fe0d-c7e5-41ca-9b7b-753d96646ebc@i18g2000prf.googlegroups.com> > So you can't make an internal DSL like this that uses Python's built- > in grammar. ?You'd have to hack the parser or settle for an external > preprocessor. This time it is really hard for me but I begin accepting the fact that I will have to build an external DSL. I experimented some weeks ago with ANTLR and the tools work fine but I do not like the extra effort to learn and maintain the extra tooling. I think that in the beginning the DSL language will have to change a very often as new features are added. To implement a standardized rock solid language like SQL ANTLR might be the perfect tool but to develop something from scratch that will be expanded interactively a internal DSL has huge benefits. Please not that I really like ANTLR. It is just the first tool I used for this task and I want to double check if other tools fit better to my needs. I will look into Ply and Pyparsing over the next weeks unless someone points out that there is some special tool that makes growing a new "fast evolving" language as easy as building an internal DSL. Maybe this is all overkill and there is a hacking ruby-style DSLs with regular expressions recipe out there? So far I could not find one. > However, the gist of it seems to be that you want to be able to write > files in your DSL that can be imported just like a regular Python > module. ?Yes, that can be done. > > See PEP 302, Import Hooks: > > http://www.python.org/dev/peps/pep-0302/ > > Python's standard importer looks for files with *.py, *.pyc, *.pyd, or > *.so extensions. ?You could write an importer that looks for *.dsl > files, and, instead of loading it as a Python file, invokes your DSL > parser. This is really helpful. Thanks for giving me directions. Mark From zac256 at gmail.com Thu Jan 8 14:49:22 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 11:49:22 -0800 Subject: cPickle vs pickle discrepancy In-Reply-To: References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: <333edbe80901081149v768cb2f1jdb02270b30b9e5da@mail.gmail.com> Correct, 2.6.1 does not complain. If only I could upgrade! The workaround is obvious and I'll do that. Thanks for your help. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 11:34 AM, Carl Banks wrote: > On Jan 8, 12:27 pm, "Zac Burns" wrote: >> Thanks for your patience waiting for me to isolate the problem. >> >> | Package >> --__init__.py ->empty >> --Package.py ->empty >> --Module.py >> import cPickle >> class C(object): >> pass >> def fail(): >> return cPickle.dumps(C(), -1) >> >> import Package.Module >> Package.Module.fail() >> >> The failure seems to happen because pickle correctly does an absolute >> import and cPickle incorrectly relatively imports Package.py and fails >> to find Module underneath. >> >> The package and the module named package was because in there was a >> main class defined with the same name as the package in that file and >> Module.py contained support code for the package. > > I'd call it a bug. Nice detecitve work pinpointing it. > > I suspect the issue disappears (accidentally) in 2.6, though. From > the What's New in Python 2.6 doc: > > C API: the PyImport_Import and PyImport_ImportModule functions now > default to absolute imports, not relative imports. This will affect C > extensions that import other modules. > > Presumably __import__ also defaults to absolute (since PyImport_Import > calls it) so the two modules should both use absolute imports in 2.6. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Jan 8 14:51:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:51:23 -0500 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: Sergey Kishchenko wrote: > In Python empty container equals False in 'if' statements: > > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: > > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. I think, this > behaviour conflicts with 'Explicit is better than implicit' and > 'Practicality beats purity' statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. Sensible (and documented) defaults pervade Python. From tim at thechases.com Thu Jan 8 14:52:38 2009 From: tim at thechases.com (Tim Chase) Date: Thu, 08 Jan 2009 13:52:38 -0600 Subject: figuring week of the day.... In-Reply-To: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <49665986.7080301@thechases.com> tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. sounds like you want the standard library's "calendar" module, particularly the monthcalendar() which gets you pretty close. For a lazy version just using the stdlib with minimal fuss: >>> import calendar as c >>> week = lambda y,m,d: [w for w in c.monthcalendar(y, m) if d in w][0] >>> week(2009, 1, 8) [5, 6, 7, 8, 9, 10, 11] the monthcalendar() call returns the whole month's calendar which may be more what you want for the big-picture. -tkc From joe at strout.net Thu Jan 8 14:57:05 2009 From: joe at strout.net (Joe Strout) Date: Thu, 08 Jan 2009 12:57:05 -0700 Subject: why cannot assign to function call In-Reply-To: References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <49665A91.8070801@strout.net> Mark Wooding wrote: >>>> The `they're just objects' model is very simple, but gets tied up in >>>> knots explaining things. The `it's all references' model is only a >>>> little more complicated, but explains everything. >>> But it *over* explains, because it implies things that "everybody knows" >>> about references in other languages that aren't true for Python. > > I addressed this elsewhere. Summary: `pass-by-reference' is a different > thing to `all you manipulate are references': Python does pass-by-value, > but the things it passes -- by value -- are references. Quite right. It's easy to see this in languages where some types are references and others are simple values; and even easier in such a language that supports both pass-by-value and pass-by-reference (such as REALbasic or VB.NET). Then you can easily see, in one language, all combinations of [value type, reference type] * [pass by ref, pass by val]. In Python, we only have reference types, and we only have pass by value, so out of the four combinations above, there is only one: references passed by value. You'd think this would make it easier, but from the raging debates and repeated obfuscation on this point, it apparently makes Python MORE difficult to understand and explain (at least for some). > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. If you want a function to > modify your variable, you have to pass a pointer value which points to > it. Right -- a C/C++ pointer is (or at least, can be in normal usage) pretty similar to a reference (though of course you can do more low-level and hackish things with them too). In C, such a reference is always passed by value, as in Python or Java, and just like the default mode in RB or .NET. In C++, you can also choose to pass such a parameter by reference, like the ByRef mode in RB and .NET. This parameter passing mode is unavailable in Python or Java. >>> Okay, the abstraction has leaked again... are the paperweights references >>> to the objects, or the names we've bound objects to? I'm confused... > > They're the references to the objects. You don't bind names to > objects. You bind names slots in which you store references. Well put (again). This is technically the correct description, though in casual usage, I think it's fine to occasionally gloss over some of these layers as long as everyone involved understands what is meant. (This is especially true when the references are to immutable objects, which are functionally very similar to simple values.) >> How do we decide what is best for newcomers to Python, depending on >> background? > > That I really don't know. I'm not good at teaching total beginners > (does it show?) because I'm too enmired in the theory. ... FWIW, I've spent a fair amount of time teaching beginners, though not so much in Python yet. But plenty of time in other languages where the same questions come up. In my experience, pointing out that a variable of any object type contains a *reference* to that object, rather than the object data itself, and then illustrating with a couple of examples, quickly clears up any confusion. I've never had a newbie require more than a couple of exchanges on this topic before they get it. (And before I joined the Python community, I never even felt the need to actually draw a picture [1] to make it clearer.) > What I am pretty sure of is that references are going to have to enter > the picture at some point, because other models get too complicated. I agree completely. I can barely understand the other models myself. Best, - Joe [1] http://www.strout.net/info/coding/valref/ From jgardner at jonathangardner.net Thu Jan 8 14:57:54 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 11:57:54 -0800 (PST) Subject: Making a decorator a staticmethod References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> On Jan 8, 11:18?am, "Zac Burns" wrote: > > In my use case (not the example below) the decorator returns a > function of the form def f(self, *args, **kwargs) which makes use of > attributes on the instance self. So, it only makes sense to use the > staticmethod in the class and in the baseclass. Making this decorator > a module level function doesn't make sense here. > I don't think you should be using staticmethod in this case since you are relying on information in the class itself. This really looks like it should be a classmethod. Granted, the example you gave can be a staticmethod, but it sounds like you want to incorporate some of the information in the class. (Aside: I really can't think of any reason to use staticmethods in Python other than to organize functions into namespaces, and even then, that's what modules are for, right?) I think you need to show a better example of what it is you are trying to do. From clp2 at rebertia.com Thu Jan 8 15:03:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 12:03:35 -0800 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: <50697b2c0901081203n459bd979idabb843f322d40f1@mail.gmail.com> On Thu, Jan 8, 2009 at 5:53 AM, Sergey Kishchenko wrote: > In Python empty container equals False in 'if' statements: > > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: > > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. I think, this > behaviour conflicts with 'Explicit is better than implicit' and > 'Practicality beats purity' statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. Python has a rich notion of boolean truth compared to other languages. In this case, by default, non-None objects are considered True. It's a reasonable default behavior since wanting to differentiate between None and non-None objects is such a common task. Also, I've been programming in Python for a long while and have yet to encounter any bug due to this behavior. Regarding the Zen, on the contrary, this is a perfect example of "Practicality beats purity" in action. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 8 15:04:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:04:07 -0500 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: <4965c801$0$193$e4fe514c@news.xs4all.nl> References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek wrote: > I can't think of anything that could cause this. Similarly, eval('09') > fails, but for string 0x with x<8 it works. I am teaching myself Python > in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-- >> VisualBasic(2000)-->Python. I am a physicist, have programmed computers > all my life but I won't understand the real tech jargon of present day > computer science. Please keep it simple I taught myself Python as a statistician with a Fortran/C backgound by interleaving interactive experiments (such as you did) with reading of the manuals. The Language Manual chapter on Lexical Analysis has an Integer Literals subsection that answers this question. I strongly recommend you peruse the Language Manual and the initial Library Manual chapters on built-ins. tjr From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:06:29 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:06:29 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <49666a71$0$25544$426a74cc@news.free.fr> Zac Burns a ?crit : > I've read the "Making staticmethod objects callable?" thread now, and > would have to disagree that all the use cases are strange as stated at > http://www.python.org/dev/summary/2006-03-01_2006-03-15/#making-staticmethod-objects-callable > > In my use case (not the example below) Then please provide the concrete use case (or at least anything close enough) > the decorator returns a > function of the form def f(self, *args, **kwargs) There's nothing magic wrt/ 'self'. Heck, it's not even a keyword. > which makes use of > attributes on the instance self. s/instance self/object passed as first argument/ > So, it only makes sense to use the > staticmethod in the class and in the baseclass. Nope. It makes senses for any object implementing the (implied) interface, whatever the class or base class. > Making this decorator > a module level function doesn't make sense here. It does, as long as you clearly document the expected interface. Please understand that what you decorate are plain functions - not "methods". Whether the function is being used as the implementation for a method or not is totally irrelevant - what's relevant is what the decorated function expects as arguments. wrt/ functions vs methods, technically, there's *no* difference between: def func(some_interface): do_something_depending_on(some_interface) and class SomeClassImplementingSomeInterface(object): def method(self): do_something_depending_on(some_interface) As a matter of fact, the second snippet is strictly equivalent to: def func(some_interface): do_something_depending_on(some_interface) class SomeClassImplementingSomeInterface(object): pass SomeClassImplementingSomeInterface.method = func IOW, a method is implemented by a function (that takes the object as first argument). To be true, a Python "method" object is only a thin wrapper around a function and an object, that is instanciated (by the function object itself) each time an attribute lookup resolves to a function object accessed thru the descriptor protocol. wrt/ decorators: well, a "decorator" is just any callable(that is, any object implementing the __call__ method) taking a callable as first argument and returning a callable[1]. Now some decorator are generic - they just don't care about the decorated function's signature -, and some are not - they expect a (more or less) defined argument list. For example, the Django framework provides a set of decorators that expects to be applied to callables taking an HttpRequest object as first argument. That doesn't mean these decorators have to be methods of the HttpRequest class - they are just callable that takes as argument a callable which itself takes an HttpRequest object as first argument. [1] and even this definition, while technically mostly correct, doesn't cover all acceptations of the term "decorator" - some so-called decorators are in fact callables taking some specific argument list and returning a proper decorator. That's what you get each time you see something like: @decorate(some_arg) def some_func(other_arg): code_here HTH From clp2 at rebertia.com Thu Jan 8 15:11:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 12:11:36 -0800 Subject: figuring week of the day.... In-Reply-To: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <50697b2c0901081211k7c18df01je8990b0269e9c363@mail.gmail.com> On Tue, Jan 6, 2009 at 7:56 AM, tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. The "%U" time format specifier (Week number of the year) to strftime() [http://docs.python.org/library/datetime.html#strftime-behavior] might be helpful. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gruszczy at gmail.com Thu Jan 8 15:13:37 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 21:13:37 +0100 Subject: Tree views - Best design practices In-Reply-To: References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: <1be78d220901081213r201f6549jc0ecfed82a8cacee@mail.gmail.com> I'd love to have operations methods, which would return names of operations and references to proper methods. The problem is that certain operations require more, than just running some operation on the Group or Element. Let's say, you want to add new group to an existing one - you can't do that to an element. But adding a group cannot be just done by calling group.addGroup. You must first construct the group or at least get information require to construct a group, so you must for example call a dialog which will ask for information about the group. And that's in conflict with model/view pattern. And that's not all. I am using qt and when I want to add this group to another one, I have to first call beginInsertRows on the model used by the tree view (it's a layer between the gui and the real model). I tried building a wrapper around my model which would provide additional info, but then I had to keep relations between objects in two places (relations between real groups and elements and wrapper groups and wrapper elements), which wasn't the right way to do. I just can figure a simple, elegant way to do this. -- Filip Gruszczy?ski From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:21:07 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:21:07 +0100 Subject: Making a decorator a staticmethod In-Reply-To: <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> Message-ID: <49666ddf$0$10251$426a74cc@news.free.fr> Jonathan Gardner a ?crit : > On Jan 8, 11:18 am, "Zac Burns" wrote: >> In my use case (not the example below) the decorator returns a >> function of the form def f(self, *args, **kwargs) which makes use of >> attributes on the instance self. So, it only makes sense to use the >> staticmethod in the class and in the baseclass. Making this decorator >> a module level function doesn't make sense here. >> > > I don't think you should be using staticmethod in this case since you > are relying on information in the class itself. Nope. He's relying on (part of) the interface(s) implemented by the first argument. The class object itself has nothing to do with is (well... it does, but only as far as it contribute to the implementation of the interface expected by the decorator). > (Aside: I really can't think of any reason to use staticmethods in > Python other than to organize functions into namespaces, and even > then, that's what modules are for, right?) I sometimes found staticmethods to be useful, in that they provided polymorphic dispatch without having to care about the containing module (or whether the object thru which the staticmethod_or_function is accessed is a module, class or instance). > I think you need to show a better example of what it is you are trying > to do. +1 on this. So far, the only concrete use case for staticmethod as a decorator I can think of is the one exposed above for staticmethods in general. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:24:40 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:24:40 +0100 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: <49666eb4$0$10251$426a74cc@news.free.fr> Grant Edwards a ?crit : > On 2009-01-08, Alex van der Spek wrote: > >> Thanks much, that makes sense! > > Well, that's the correct explanation. > > Whether that feature makes sense or not is debatable. Even I'm > not old-school enough that I ever use octal literals -- and I > used Unix on a PDP-11 for years (actually had my own PDP-11 for > while, but it never worked). Now that I think of it, my > Heathkit Z80 stuff used octal notation too. What about your DeathStation 9000 ?-) From tjreedy at udel.edu Thu Jan 8 15:33:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:33:59 -0500 Subject: How to deepcopy a list of user defined lists? In-Reply-To: <35331.99250.qm@web7908.mail.in.yahoo.com> References: <35331.99250.qm@web7908.mail.in.yahoo.com> Message-ID: srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > def __new__(cls, values, ctor): > val = [] > for item in values: > item = ctor(item) > val.append(item) > > self = list.__new__(cls, val) > self.__values = val > self.__ctor = ctor > return self A subclass of list should populate the list in __init__, not __new__, usually by calling list.__init__, as lists are mutable and subclasses thereof should be too. class clist(list): def __init__(self, values, ctor): list.__init__(self, map(ctor, values)) self.__ctor = ctor clist1 = clist((1,2,3),str) clist2 = clist((1,2,3), float) alist1 = [clist1,clist2] print(alist1) #[['1', '2', '3'], [1.0, 2.0, 3.0]] from copy import deepcopy alist2 = deepcopy(alist1) print(alist2) #[['1', '2', '3'], [1.0, 2.0, 3.0]] print(alist1[0] is alist2[0]) #False - ie, inner clist was copied I omitted your __values attribute as redundant with the value of the clist itself. Since clist is not a mixin class, double underscores for name-mangling are not needed. Unless you make use of _ctor in other methods, initializing regular lists with 'list(map(ctor,values)) would work as well. Terry Jan Reedy From jgardner at jonathangardner.net Thu Jan 8 15:35:36 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 12:35:36 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Message-ID: <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> On Jan 8, 8:16?am, MRAB wrote: > Filip Gruszczy?ski wrote: > > Hi! > > > I have certain design problem, which I cannot solve elegantly. Maybe > > you know some good design patterns for this kind of tasks. > > > Task: > > > We have a model which has two kinds of objects: groups and elements. > > Groups can hold other groups (subgroups) and elements. It's a simple > > directory tree, for example. We would like to display it in a tree > > view (which sound good for this kind of model). What is more required, > > for groups and elements there are different sets of operations, which > > should be available under right click. For example for group, there > > should be operations: 'add element' and 'add group', and for element > > there should be 'change properties'. > > > Do you know any smart way to achieve this? The simplest way is to ask > > for the class and display operations accordingly. But from the first > > day with OO programming I have heard, that asking for class is wrong. > > But I can hardly see any easy and more maintainable solution for this > > problem. Could you help me with this? > > You could ask the object what the operations are. Here's an example > using strings: > > ?>>> class Element(object): > ? ? ? ? operations = "Element operations" > > ?>>> class Group(object): > ? ? ? ? operations = "Group operations" > > ?>>> e = Element() > ?>>> g = Group() > ?>>> > ?>>> e.operations > 'Element operations' > ?>>> g.operations > 'Group operations' When faced with this kind of scenario, I usually write boolean methods like "is_leaf" or "is_branch". class Element(object): @staticmethod def is_leaf(): return True @staticmethod def is_branch(): return False class Group(object): @staticmethod def is_leaf(): return False @staticmethod def is_branch(): return True Of course, you have to give priority to one or the other, in case an object thinks it is both. if thing.is_branch(): # Treat it like a branch elif thing.is_leaf(): # Treat it like a leaf I believe this is a simpler method than checking a single attribute for a name. From tjreedy at udel.edu Thu Jan 8 15:43:34 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:43:34 -0500 Subject: Replying to list messages In-Reply-To: <87hc4agz1f.fsf_-_@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > For Thunderbird (which I see you're using, Paul), the open bug report > is . > Meanwhile, you can install an add-on to provide the function > . When I read the list as a newsgroup (gmane.comp.python.general), the Reply button of Thunderbird replies to the newsgroup. There is also a Replay All button and Message/Reply to Sender only menu selection. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:51:44 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:51:44 +0100 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: <4966750c$0$5150$426a74cc@news.free.fr> Sergey Kishchenko a ?crit : > In Python empty container equals False in 'if' statements: Yes. > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: Yes. > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. Yes. It's clearly documented FWIW. > I think, this > behaviour conflicts with 'Explicit is better than implicit' Why so ? It *is* explicit that the default for an object is to have a true value in a boolean context. > and > 'Practicality beats purity' Quite on the contrary. From a practical POV, the default truth values of Python objects are most of the time what you practically want in a boolean context - that is, any non-None object, non-empty sequence and non-zero numeric objects are true. __nonzero__ is here for the *very few* corner cases where this is not the sensible default. > statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. I can understand that you've been bitten by the rules regarding truth values of Python objects. But if so, please remember that it's only because *you* assumed something different from what's documented. From robert.kern at gmail.com Thu Jan 8 15:51:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Jan 2009 15:51:45 -0500 Subject: mmap only supports string In-Reply-To: References: Message-ID: Neal Becker wrote: > Problem is, AFAIK a string can only be created as a copy of some other data. Say I'd like to take some large object and read/write to/from mmap object. A good way to do this would be the buffer protocol. Unfortunately, mmap only supports string. A string could only be created after copying the original object AFAIK. > > I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. Specifically, mmap slice should support buffer protocol. You could use numpy as an intermediate. Slices will be numpy arrays which are views onto the mmap (no memory copying), and you can get a buffer from the numpy arrays. -- 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 lindahl at pbm.com Thu Jan 8 15:52:36 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 12:52:36 -0800 (PST) Subject: ulimit stack size and python threads Message-ID: I figure this is a FAQ, but I can't find it in any FAQs. I want to limit the stacksize on my server. If I set it to 8 megs, or unlimited, python is happy. If I set it to 4 gigabytes, things like yum (which is a python program) crash creating a thread. This is on an x86_64 linux kernel, RHEL5, etc etc. Why is Python overloading the meaning of the ulimit -s like this? There are plenty of real non-python programs with huge stack usage, and I'd like my system default stack limit to be less than unlimited but much larger than Python will allow. -- greg From gruszczy at gmail.com Thu Jan 8 16:00:04 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 22:00:04 +0100 Subject: Tree views - Best design practices In-Reply-To: <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: <1be78d220901081300x67023278gb5ae5645298947af@mail.gmail.com> > class Element(object): > @staticmethod > def is_leaf(): return True > @staticmethod > def is_branch(): return False > > class Group(object): > @staticmethod > def is_leaf(): return False > @staticmethod > def is_branch(): return True > > Of course, you have to give priority to one or the other, in case an > object thinks it is both. > > if thing.is_branch(): > # Treat it like a branch > elif thing.is_leaf(): > # Treat it like a leaf > > I believe this is a simpler method than checking a single attribute > for a name. Is it really any better than asking for class? I mean, if I need to add another class to a hierarchy which behaves differently, will it be more flexible (actually you have to add another method to every class and check for in the gui). I believe it's just the same as asking for the class, but we hide it under static methods. It's no different though. -- Filip Gruszczy?ski From google at mrabarnett.plus.com Thu Jan 8 16:03:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 21:03:53 +0000 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49666A39.5000205@mrabarnett.plus.com> Greg Lindahl wrote: > I figure this is a FAQ, but I can't find it in any FAQs. > > I want to limit the stacksize on my server. > > If I set it to 8 megs, or unlimited, python is happy. > > If I set it to 4 gigabytes, things like yum (which is a python > program) crash creating a thread. This is on an x86_64 linux kernel, > RHEL5, etc etc. > > Why is Python overloading the meaning of the ulimit -s like this? > There are plenty of real non-python programs with huge stack usage, > and I'd like my system default stack limit to be less than unlimited > but much larger than Python will allow. > I'm only guessing, but could it be a 32-bit limit somewhere? Have you tried, say, 1GB, which would be within a 32-bit limit? From tim.arnold at sas.com Thu Jan 8 16:06:21 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 8 Jan 2009 16:06:21 -0500 Subject: drive a desktop app from python? Message-ID: Hi, I don't even know what to google for on this one. I need to drive a commercial desktop app (on windows xp) since the app doesn't have a batch interface. It's intended to analyze one file at a time and display a report. I can get the thing to write out the report an html browser, but I have thousands of files I need it to analyze every night. Is there any lib or recipe(s) for doing something like this via python? thanks, --Tim Arnold From martin at v.loewis.de Thu Jan 8 16:07:03 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 22:07:03 +0100 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: <49666AF7.9010804@v.loewis.de> > i'd just ... much rather be completely independent of proprietary > software when it comes to building free software. I guess my question is then: why do you want to use Windows in the first place? Regards, Martin From lindahl at pbm.com Thu Jan 8 16:07:49 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 13:07:49 -0800 (PST) Subject: ulimit stack size and python threads References: Message-ID: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> > I'm only guessing, but could it be a 32-bit limit somewhere? Have you > tried, say, 1GB, which would be within a 32-bit limit? Indeed, ulimit -s 1000000 (a bit smaller than 1 GB) does work, but it doesn't solve my problem, since I want to set the limit higher than 1 GB. -- greg From jgardner at jonathangardner.net Thu Jan 8 16:25:36 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 13:25:36 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> On Jan 8, 1:00?pm, "Filip Gruszczy?ski" wrote: > > Is it really any better than asking for class? I mean, if I need to > add another class to a hierarchy which behaves differently, will it be > more flexible (actually you have to add another method to every class > and check for in the gui). I believe it's just the same as asking for > the class, but we hide it under static methods. It's no different > though. > Yes. There is a difference between the interface of an object (namely, what methods and attributes it has and what their semantic meaning is) and the class of an object (what methods and attributes it has and how they are implemented.) In general, you shouldn't be asking about an object's class. Down the road, you may want to use an object that isn't of the same class but does support the interface. Consider how the file object is used in Python. Pretty much every place you can use a file object you can use a StringIO, right? That's because StringIO supports the file interface while it isn't a file. You may want to read up on 'duck typing' to get a better sense of why this is important. From jgardner at jonathangardner.net Thu Jan 8 16:33:17 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 13:33:17 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: On Jan 8, 1:00?pm, "Filip Gruszczy?ski" wrote: > > Is it really any better than asking for class? I mean, if I need to > add another class to a hierarchy which behaves differently, will it be > more flexible (actually you have to add another method to every class > and check for in the gui). I believe it's just the same as asking for > the class, but we hide it under static methods. It's no different > though. > One additional note: Given that the interface and class of an object are two, orthogonal and independent things, how do you tell what interfaces an object supports? There are a variety of methods. I can break them down into 3. (1) The user of the object keeps track of which classes support which interfaces. This is bad because you can't anticipate new classes properly. Sometimes it is necessary when the other two options aren't feasible. (2) The implementor of the object provides information on what interfaces it supports through a method or attribute of some sort. This is bad because there may be new interfaces that come into existence that the object does support but the implementor doesn't know about it and so the object says it doesn't support the interface. (3) Some 3rd Party registration of interfaces and classes keeps track of which classes support which interfaces, and vice-versa. When you add a new interface, you have to list all the existing classes that also support that interface. When you add a new class, you list all the existing interfaces that it supports. This is just plain hard to do, of course. None of these solutions are perfect, of course. Duck typing tries to solve this problem with option (4): Nobody really keeps track of interfaces at all, and you just kind of wing it hoping for the best. This solution is also far from perfect, but it suggests that you never look at the class of an object, or really, even its interface. You just start using it. So my solution is the "just use it" bit. All the user really needs to know is "Are you a leaf or a branch?" And the objects simply have to answer that question. From thorsten at thorstenkampe.de Thu Jan 8 16:39:18 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 22:39:18 +0100 Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) > On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > > [Python 2.6.1] > > > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > > incompatibilities") against a test file that only contains "print > > 'test'". > > > > Unfortunately I saw no warnings about print becoming a function in > > Python 3 ("print()"). Where is the problem? > > There is no problem. ``print``\s are handled fine by the 2to3.py > script. The option warns about stuff that is not easily automatically > converted. There /is/ obviously a problem: the Python command line help[1] and the "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido van Rossum are misleading (if not to say wrong): """ For porting existing [...] code to Python 3.0, the best strategy is the following: [...] 2. [...] Turn on the -3 command line switch. This enables warnings about features that will be removed (or change) in 3.0.[...] 3. Run the 2to3 source-to-source translator [...] """ Thorsten [1] "-3 : warn about Python 3.x incompatibilities" From gruszczy at gmail.com Thu Jan 8 16:50:50 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 22:50:50 +0100 Subject: Tree views - Best design practices In-Reply-To: <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> Message-ID: <1be78d220901081350h6200dfcfy10196642b7190f6b@mail.gmail.com> > Yes. There is a difference between the interface of an object (namely, > what methods and attributes it has and what their semantic meaning is) > and the class of an object (what methods and attributes it has and how > they are implemented.) > > In general, you shouldn't be asking about an object's class. Down the > road, you may want to use an object that isn't of the same class but > does support the interface. > > Consider how the file object is used in Python. Pretty much every > place you can use a file object you can use a StringIO, right? That's > because StringIO supports the file interface while it isn't a file. > > You may want to read up on 'duck typing' to get a better sense of why > this is important. I have read also your next message and these are good arguments for dynamically typed languages and really convinces me - I mean that they provide some flexibility at the cost of writing a little more. They provide flexibility though in a different field. Duck typing is great, because it allows completely use of a completely different hierarchy, which only has to have the same interface. But I am looking for a different type of flexibility. I would like to be able to add more classes to my hierarchy and not have to change my code in many places when I add new class to the hierarchy. If I have to change every class in the hierarchy because I add new class, then it's not something I would like to do. And idea how I can avoid this? -- Filip Gruszczy?ski From torriem at gmail.com Thu Jan 8 16:54:34 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 08 Jan 2009 14:54:34 -0700 Subject: Work with Open Office In-Reply-To: References: Message-ID: <4966761A.6090507@gmail.com> Dan Esch wrote: > Have been browsing through this list and reading documentation and tutorials > for python self-study. I have, apparently, teh stupid. Google is my > friend. Off I go. Thanks. Let us know how it goes. Last time I tried to script OO, I found it to be much more difficult than VBA. OO's scripting is a mess, honestly. From google at mrabarnett.plus.com Thu Jan 8 16:54:56 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 21:54:56 +0000 Subject: ulimit stack size and python threads In-Reply-To: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> Message-ID: <49667630.80006@mrabarnett.plus.com> Greg Lindahl wrote: >> I'm only guessing, but could it be a 32-bit limit somewhere? Have you >> tried, say, 1GB, which would be within a 32-bit limit? > > Indeed, ulimit -s 1000000 (a bit smaller than 1 GB) does work, but it > doesn't solve my problem, since I want to set the limit higher than 1 > GB. > How much higher? You could try just under 4GB (unsigned 32-bit) and just under 2GB (signed 32-bit). From tjreedy at udel.edu Thu Jan 8 17:04:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 17:04:04 -0500 Subject: "python -3" not working as expected In-Reply-To: References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: Thorsten Kampe wrote: > * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) >> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: >>> [Python 2.6.1] >>> >>> to test existing Python code, I ran "python -3" ("warn about Python 3.x >>> incompatibilities") against a test file that only contains "print >>> 'test'". >>> >>> Unfortunately I saw no warnings about print becoming a function in >>> Python 3 ("print()"). Where is the problem? >> There is no problem. ``print``\s are handled fine by the 2to3.py >> script. The option warns about stuff that is not easily automatically >> converted. > > There /is/ obviously a problem: the Python command line help[1] and the > "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido > van Rossum are misleading (if not to say wrong): > > """ > For porting existing [...] code to Python 3.0, the best strategy is the > following: > [...] > 2. [...] Turn on the -3 command line switch. This enables warnings about > features that will be removed (or change) in 3.0.[...] > 3. Run the 2to3 source-to-source translator [...] > """ > > Thorsten > [1] "-3 : warn about Python 3.x incompatibilities" > -- Since you are, I believe, at least the second person to report being bit by this confusion, please open an issue at bugs.python.org and suggest a couple of revised sentences that you think are more informative. From zac256 at gmail.com Thu Jan 8 17:07:16 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 14:07:16 -0800 Subject: Making a decorator a staticmethod In-Reply-To: <49666ddf$0$10251$426a74cc@news.free.fr> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> <49666ddf$0$10251$426a74cc@news.free.fr> Message-ID: <333edbe80901081407u7b41f7a8oe27d98c870561c9a@mail.gmail.com> To Bruno's first e-mail: Everything you said was correct but largely off topic. I did already understand these things as well. To Bruno's second email quote: """ Nope. He's relying on (part of) the interface(s) implemented by the first argument. The class object itself has nothing to do with is (well... it does, but only as far as it contribute to the implementation of the interface expected by the decorator). """ Yes - this is exactly what I was trying to communicate. In addition - perhaps what I should have made clear all along is that the interface I'm relying on isn't as much of an interface as it is an implementation. The attributes that I will be accessing are 'local' (starting with underscores, let's not get into a discussion about this - I know they aren't really local) and are subject to change as the implementation of the class changes. The class provides a 'service' for the inherited classes with differing behaviors for different method via the decorators it provides. The details of which I can't get into because it's proprietary. If this use case is objectionable to you then fine, I've implemented my own staticdecorator. (which simply inherits from staticmethod and implements call). But to those who the use case makes sense for it may be worth thinking about implementing the call method in the main distribution. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 12:21 PM, Bruno Desthuilliers wrote: > Jonathan Gardner a ?crit : >> >> On Jan 8, 11:18 am, "Zac Burns" wrote: >>> >>> In my use case (not the example below) the decorator returns a >>> function of the form def f(self, *args, **kwargs) which makes use of >>> attributes on the instance self. So, it only makes sense to use the >>> staticmethod in the class and in the baseclass. Making this decorator >>> a module level function doesn't make sense here. >>> >> >> I don't think you should be using staticmethod in this case since you >> are relying on information in the class itself. > > Nope. He's relying on (part of) the interface(s) implemented by the first > argument. The class object itself has nothing to do with is (well... it > does, but only as far as it contribute to the implementation of the > interface expected by the decorator). > > >> (Aside: I really can't think of any reason to use staticmethods in >> Python other than to organize functions into namespaces, and even >> then, that's what modules are for, right?) > > I sometimes found staticmethods to be useful, in that they provided > polymorphic dispatch without having to care about the containing module (or > whether the object thru which the staticmethod_or_function is accessed is a > module, class or instance). > > >> I think you need to show a better example of what it is you are trying >> to do. > > +1 on this. So far, the only concrete use case for staticmethod as a > decorator I can think of is the one exposed above for staticmethods in > general. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Thu Jan 8 17:11:29 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 23:11:29 +0100 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49667a11$0$22812$9b622d9e@news.freenet.de> > Why is Python overloading the meaning of the ulimit -s like this? Why do you think Python is overloading the meaning of that? I ensure you it isn't - it doesn't actively care what the limits are. Regards, Martin From invalid at invalid Thu Jan 8 17:12:00 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 08 Jan 2009 16:12:00 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> <49666eb4$0$10251$426a74cc@news.free.fr> Message-ID: On 2009-01-08, Bruno Desthuilliers wrote: > Grant Edwards a ?crit : >> On 2009-01-08, Alex van der Spek wrote: >> >>> Thanks much, that makes sense! >> >> Well, that's the correct explanation. >> >> Whether that feature makes sense or not is debatable. Even I'm >> not old-school enough that I ever use octal literals -- and I >> used Unix on a PDP-11 for years (actually had my own PDP-11 for >> while, but it never worked). Now that I think of it, my >> Heathkit Z80 stuff used octal notation too. > > What about your DeathStation 9000 ?-) The closest thing I've seen to a DS9K would probably be a CDC Cyber 6600 mainframe. I guess for somebody with a mainframe background it might not have been too weird, but for somebody who came from a PDP-11, Z80, 65XX background, it seemed awfully obtuse. -- Grant Edwards grante Yow! I'm having a RELIGIOUS at EXPERIENCE ... and I don't visi.com take any DRUGS From thorsten at thorstenkampe.de Thu Jan 8 17:21:04 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 23:21:04 +0100 Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > Thorsten Kampe wrote: > > * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) > >> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > >>> [Python 2.6.1] > >>> > >>> to test existing Python code, I ran "python -3" ("warn about Python 3.x > >>> incompatibilities") against a test file that only contains "print > >>> 'test'". > >>> > >>> Unfortunately I saw no warnings about print becoming a function in > >>> Python 3 ("print()"). Where is the problem? > >> There is no problem. ``print``\s are handled fine by the 2to3.py > >> script. The option warns about stuff that is not easily automatically > >> converted. > > > > There /is/ obviously a problem: the Python command line help[1] and the > > "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido > > van Rossum are misleading (if not to say wrong): > > > > """ > > For porting existing [...] code to Python 3.0, the best strategy is the > > following: > > [...] > > 2. [...] Turn on the -3 command line switch. This enables warnings about > > features that will be removed (or change) in 3.0.[...] > > 3. Run the 2to3 source-to-source translator [...] > > """ > > > > Thorsten > > [1] "-3 : warn about Python 3.x incompatibilities" > > -- > > Since you are, I believe, at least the second person to report being bit > by this confusion, please open an issue at bugs.python.org and suggest a > couple of revised sentences that you think are more informative. Will do tomorrow. The revised sentence could be in the line of "warn about Python 3.x incompatibilities that cannot trivially be fixed by 2to3.py". Thorsten From david at hlacik.eu Thu Jan 8 17:24:21 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Thu, 8 Jan 2009 23:24:21 +0100 Subject: linked list with cycle structure In-Reply-To: <6smp37F763pbU2@mid.uni-berlin.de> References: <6sjok8F6dqciU1@mid.uni-berlin.de> <6smp37F763pbU2@mid.uni-berlin.de> Message-ID: Hi, well i am able to find a loop in a list using two iterators.One iterator runs "two times faster than the other", and if he encounters the first, it means that there is a loop. Example : 1,2,3,4,5,6,7,8,9,5 the algorithm would generate: start - 1,2 iteration 1- 2, 4 iteration 2- 3, 6 iteration 3- 4, 8 iteration 4- 5, 5 ( match) But how can this help me with counting list elements? :( Thanks, D. On Thu, Jan 8, 2009 at 5:48 PM, Diez B. Roggisch wrote: > > David Hl??ik wrote: > > > Hi, > > > > so okay, i will create a helping set, where i will be adding elements > > ID, when element ID will be allready in my helping set i will stop and > > count number of elements in helping set. This is how long my cycled > > linked list is. > > > But what if i have another condition , and that is *i can use only > > helping memory with constant size* ? This means i am not able to > > create any set and adding elements there. I need to have a constant > > size variables . This is complication a complication for me. > > This isn't to hard - think about what you are really interested in - knowing > if *all* other elements are already counted, or a specific one? You can get > away with only one, to detect the cycle and abort. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 17:26:19 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 23:26:19 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> <49666ddf$0$10251$426a74cc@news.free.fr> Message-ID: <49668b37$0$27584$426a74cc@news.free.fr> Zac Burns a ?crit : > To Bruno's first e-mail: Everything you said was correct but largely > off topic. for a definition of "off topic" equals to "didn't fit your expectations". > I did already understand these things as well. Sorry - but it was not necessarily obvious from your post, and it's near to impossible to guess someone's background on a single post basis. So please don't hold it against me. Anyway, you're not the only people reading this group, and some readers might not have the same knowledge. > To Bruno's second email > quote: > """ > Nope. He's relying on (part of) the interface(s) implemented by the > first argument. The class object itself has nothing to do with is > (well... it does, but only as far as it contribute to the > implementation of the interface expected by the decorator). > """ > > Yes - this is exactly what I was trying to communicate. In addition - > perhaps what I should have made clear all along is that the interface > I'm relying on isn't as much of an interface as it is an > implementation. The attributes that I will be accessing are 'local' > (starting with underscores, let's not get into a discussion about this > - I know they aren't really local) and are subject to change as the > implementation of the class changes. Ok. > The class provides a 'service' for the inherited classes with > differing behaviors for different method via the decorators it > provides. Not sure it's quite clear to me, but I think I get the whole picture. > The details of which I can't get into because it's > proprietary. No problem - the above precisions are enough IMHO. > If this use case is objectionable to you then fine, I've implemented > my own staticdecorator. What I still find questionable is the "necessity" to make your decorators part of the base class. OO is about objects - not classes - and Python's functions _are_ objects (just like modules, classes and everything else FWIW), so even if your decorators are bound to a specific implementation, well, what's the problem ? (BTW, please read until the end of the post before replying). Just document the fact that they only accept instances of your base class, and that's enough - well, IMHO at least !-). Anyway, given Python's highly dynamic nature, being an instance of a given class _at a given moment in time_ doesn't garantee you have this or this _implementation attribute - at best, it makes it highly plausible, but that's all you can expect, really. > (which simply inherits from staticmethod and > implements call). If it makes you feel better - no judgement call on this, I personnaly care a lot about feeling good with my own code, and perfectly understand we don't all have the same feeling about what looks right or wrong -, then go for it. FWIW, I might even agree with your choice if I saw the real code and knew the whole context. My point was just that it was not *technically* necessary to make the decorators part of the base class !-) > But to those who the use case makes sense for it may > be worth thinking about implementing the call method in the main > distribution. Python is a free, opensource software, so feel free to send the patch - who knows, it might even be accepted if don't break anything. But prepare to make your point, the BDFL tends to be very conservative (which is a very GoodThing(tm) IMHO). From lindahl at pbm.com Thu Jan 8 17:32:20 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 14:32:20 -0800 (PST) Subject: ulimit stack size and python threads References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> Message-ID: <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> > How much higher? You could try just under 4GB (unsigned 32-bit) and just > under 2GB (signed 32-bit). I'd like to set it to be about 1/2 the memory size of my server, which happens to end up being 4 gbytes. And no, slightly less than 4 gb doesn't work. But even if that worked, I'd be worried that python is doing something bad with the ulimit -s value under the covers. -- greg From jgardner at jonathangardner.net Thu Jan 8 17:41:56 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 14:41:56 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> Message-ID: <6d9db505-7564-4c96-9f97-2d8d3cd0b677@i20g2000prf.googlegroups.com> On Jan 8, 1:50?pm, "Filip Gruszczy?ski" wrote: > > But I am looking for a different type of flexibility. I would like to > be able to add more classes to my hierarchy and not have to change my > code in many places when I add new class to the hierarchy. If I have > to change every class in the hierarchy because I add new class, then > it's not something I would like to do. And idea how I can avoid this? > I don't understand why you have to change other classes when you add a new class under duck typing. The whole point of duck typing is you don't look at the class or the interface of an object so you don't have to keep track of it. From martin at v.loewis.de Thu Jan 8 18:00:52 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 00:00:52 +0100 Subject: ulimit stack size and python threads In-Reply-To: <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> Message-ID: <496685A4.8050105@v.loewis.de> > But even if that worked, I'd be worried that python is doing something > bad with the ulimit -s value under the covers. Again: it definitely isn't. Regards, Martin From andymac at bullseye.apana.org.au Thu Jan 8 18:06:47 2009 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 09 Jan 2009 10:06:47 +1100 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49668707.6090204@bullseye.andymac.org> Greg Lindahl wrote: > I figure this is a FAQ, but I can't find it in any FAQs. > > I want to limit the stacksize on my server. > > If I set it to 8 megs, or unlimited, python is happy. > > If I set it to 4 gigabytes, things like yum (which is a python > program) crash creating a thread. This is on an x86_64 linux kernel, > RHEL5, etc etc. > > Why is Python overloading the meaning of the ulimit -s like this? > There are plenty of real non-python programs with huge stack usage, > and I'd like my system default stack limit to be less than unlimited > but much larger than Python will allow. The Python interpreter itself (absent a call to resource.setrlimit()) does nothing with resource limits - it just uses the environment it is loaded into. In the absence of effective alternative solutions, it may be possible to achieve the effect you desire by calling resource.setrlimit() in your Python installation's site.py, effectively over-riding the system default. -- ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From lindahl at pbm.com Thu Jan 8 18:27:27 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 15:27:27 -0800 (PST) Subject: ulimit stack size and python threads References: <49667a11$0$22812$9b622d9e@news.freenet.de> Message-ID: <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> > Why do you think Python is overloading the meaning of that? I ensure > you it isn't - it doesn't actively care what the limits are. Always crashing because I asked the OS to please not allow a process to grow too big is what I call overloading the meaning of ulimit -s. It's quite surprising. Not to mention the poor error message. -- greg From james at agentultra.com Thu Jan 8 18:35:41 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 08 Jan 2009 18:35:41 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> Message-ID: <85bpuhv0aa.fsf@dozer.localdomain> Kay Schluehr writes: > On 8 Jan., 16:25, J Kenneth King wrote: > >> As another poster mentioned, eventually PyPy will be done and then >> you'll get more of an "in-Python" DSL. > > May I ask why you consider it as important that the interpreter is > written in Python? I don't think it's important for Python to have a meta-circular interpreter (though it can't hurt). > I see no connection between PyPy and syntactical > Python extensions and the latter isn't an objective of PyPy. You can > write Python extensions with virtually any Python aware parser. > M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then > there is ANTLR which provides a Python grammar. I also know about two > other Python aware parsers. One of them was written by myself. Because... there is no connection to see? I never mentioned any such relation. DSL's tend to be a natural side-effect of languages which can manipulate their own expressions without extensive parsing. Creating a new parser that can generate Python AST's is certainly a valid approach (and probably the easiest one). It's not the only one. It depends on your definition of a DSL. My definition isn't satisfied with creating a parser, and so my answers reflect that. From voidwrk at gmail.com Thu Jan 8 19:26:28 2009 From: voidwrk at gmail.com (Sergey Kishchenko) Date: Thu, 8 Jan 2009 16:26:28 -0800 (PST) Subject: Default __nonzero__ impl doesn't throw a TypeError exception References: Message-ID: On 8 ???, 22:03, "Chris Rebert" wrote: > On Thu, Jan 8, 2009 at 5:53 AM, Sergey Kishchenko wrote: > > In Python empty container equals False in 'if' statements: > > > # prints "It's ok" > > if not []: > > ? ?print "It's ok" > > > Let's create a simple Foo class: > > > class Foo: > > ? ?pass > > > Now I can use Foo objects in 'if' statements: > > > #prints "Ouch!" > > f=Foo() > > if f: > > ? ?print "Ouch!" > > > So, default __nonzero__ impl is to return True. I think, this > > behaviour conflicts with 'Explicit is better than implicit' and > > 'Practicality beats purity' statements. I think, throwing a TypeError > > exception would be better. ?It will result in more explicit code with > > fewer errors. > > Python has a rich notion of boolean truth compared to other languages. > In this case, by default, non-None objects are considered True. It's a > reasonable default behavior since wanting to differentiate between > None and non-None objects is such a common task. > Also, I've been programming in Python for a long while and have yet to > encounter any bug due to this behavior. > Regarding the Zen, on the contrary, this is a perfect example of > "Practicality beats purity" in action. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com I agree with you. I completely forget about differentiating between None and non-None objects. I think, thread can be closed. From lindahl at pbm.com Thu Jan 8 19:44:08 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 16:44:08 -0800 (PST) Subject: ulimit stack size and python threads References: Message-ID: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> I see. I should be blaming the default behavior of pthreads. I did work on a OpenMP library once, and we worked around this problem, plus we gave good error messages. Given the number of HPC sites which use Python, I'd think that Python would have grown similar features. (HPC sites are more likely to have intermediate-sized stack limits due to use of Fortran.) -- greg From ryandw at gmail.com Thu Jan 8 19:47:39 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 16:47:39 -0800 (PST) Subject: BadZipfile "file is not a zip file" Message-ID: The error... >>> file = zipfile.ZipFile('data.zip', "r") Traceback (most recent call last): File "", line 1, in file = zipfile.ZipFile('data.zip', "r") File "C:\Python25\lib\zipfile.py", line 346, in __init__ self._GetContents() File "C:\Python25\lib\zipfile.py", line 366, in _GetContents self._RealGetContents() File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents raise BadZipfile, "File is not a zip file" BadZipfile: File is not a zip file When I look at data.zip in Windows, it appears to be a valid zip file. I am able to uncompress it in Windows XP, and can also uncompress it with 7-Zip. It looks like zipfile is not able to read a "table of contents" in the zip file. That's not a concept I'm familiar with. data.zip is created in this script... decoded = base64.b64decode(datum) f = open('data.zip', 'wb') f.write(decoded) f.close() file = zipfile.ZipFile('data.zip', "r") datum is a base64 encoded zip file. Again, I am able to open data.zip as if it's a valid zip file. Maybe there is something wrong with the approach I've taken to writing the data to data.zip? I'm not sure if it matters, but the zipped data is Unicode. What would cause a zip file to not have a table of contents? Is there some way I can add a table of contents to a zip file using python? Maybe there is some more fundamental problem with the data that is making it seem like there is no table of contents? Thanks in advance for your help. Ryan From google at mrabarnett.plus.com Thu Jan 8 20:02:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 01:02:44 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <4966A234.3070808@mrabarnett.plus.com> webcomm wrote: > The error... > >>>> file = zipfile.ZipFile('data.zip', "r") > Traceback (most recent call last): > File "", line 1, in > file = zipfile.ZipFile('data.zip', "r") > File "C:\Python25\lib\zipfile.py", line 346, in __init__ > self._GetContents() > File "C:\Python25\lib\zipfile.py", line 366, in _GetContents > self._RealGetContents() > File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents > raise BadZipfile, "File is not a zip file" > BadZipfile: File is not a zip file > > When I look at data.zip in Windows, it appears to be a valid zip > file. I am able to uncompress it in Windows XP, and can also > uncompress it with 7-Zip. It looks like zipfile is not able to read a > "table of contents" in the zip file. That's not a concept I'm > familiar with. > > data.zip is created in this script... > > decoded = base64.b64decode(datum) > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > file = zipfile.ZipFile('data.zip', "r") > > datum is a base64 encoded zip file. Again, I am able to open data.zip > as if it's a valid zip file. Maybe there is something wrong with the > approach I've taken to writing the data to data.zip? I'm not sure if > it matters, but the zipped data is Unicode. > > What would cause a zip file to not have a table of contents? Is there > some way I can add a table of contents to a zip file using python? > Maybe there is some more fundamental problem with the data that is > making it seem like there is no table of contents? > You're just creating a file called "data.zip". That doesn't make it a zip file. A zip file has a specific format. If the file doesn't have that format then the zipfile module will complain. From rurpy at yahoo.com Thu Jan 8 20:24:25 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 17:24:25 -0800 (PST) Subject: why cannot assign to function call References: <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> Message-ID: <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Mark Wooding wrote: ... > Python doesn't need another name for assignment, OK. > because actually its > idea of assignment is the same as anyone else's. The difference is in > the way it deals with objects. See argument elsewhere. "the same as anyone else's" only if [Python's] "idea of assignment" does not include producing the same results. a = array (1,2,3) b = a a[1] = 4 print b C, C++, VBA, Fortran, Perl: 1, 2, 3 Python: 1, 4, 3 Telling someone coming to Python from one of those languages that Python's assignment works the same way as those languages is confusing at best. "dealing objects" is part of assignment semantics ISTM. From rurpy at yahoo.com Thu Jan 8 20:27:33 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 17:27:33 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Mark Wooding wrote: ... > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. As a side comment (because it always bugs me when I read this, even though I read it in very authoritative sources), ISTM that C passes everything by value except arrays; they are passed by reference (by passing a pointer to the array by value.) Admittedly, the close relationship between arrays and pointers makes it easy conflate them. From ryandw at gmail.com Thu Jan 8 20:28:17 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 17:28:17 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:02?pm, MRAB wrote: > You're just creating a file called "data.zip". That doesn't make it a > zip file. A zip file has a specific format. If the file doesn't have > that format then the zipfile module will complain. Hmm. When I open it in Windows or with 7-Zip, it contains a text file that has the data I would expect it to have. I guess that alone doesn't necessarily prove it's a zip file? datum is something I'm downloading via a web service. The providers of the service say it's a zip file, and have provided a code sample in C# (which I know nothing about) that shows how to deal with it. In the code sample, the file is base64 decoded and then unzipped. I'm trying to write something in Python to decode and unzip the file. I checked the file for comments and it has none. At least, when I view the properties in Windows, there are no comments. From aahz at pythoncraft.com Thu Jan 8 20:29:50 2009 From: aahz at pythoncraft.com (Aahz) Date: Thu, 8 Jan 2009 17:29:50 -0800 Subject: OSCON 2009: Call For Participation Message-ID: <20090109012950.GA5426@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From googler.1.webmaster at spamgourmet.com Thu Jan 8 20:30:00 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 8 Jan 2009 17:30:00 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report Message-ID: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> Hi! I compiled Python 2.6.1 on a Mac OSX 10.5.5 Intel machine with this configure command and got this message FAILS: ./configure --with-framework-name=Python --with- universal-archs=all --enable-framework --enable- universalsdk=@executable_path/my/path/to/app WORKS: ./configure --with-framework-name=Python --with- universal-archs=all --enable-framework --enable-universalsdk=/ [...] configure: WARNING: dlfcn.h: present but cannot be compiled configure: WARNING: dlfcn.h: check for missing prerequisite headers? configure: WARNING: dlfcn.h: see the Autoconf documentation configure: WARNING: dlfcn.h: section "Present But Cannot Be Compiled" configure: WARNING: dlfcn.h: proceeding with the preprocessor's result configure: WARNING: dlfcn.h: in the future, the compiler will take precedence configure: WARNING: ## ------------------------------------------------ ## configure: WARNING: ## Report this to http://www.python.org/python-bugs ## configure: WARNING: ## ------------------------------------------------ ## checking for dlfcn.h... yes [...] many of this error warnings occure. /* its already noted in the bug reporter but there is no solution. Does anyone know how to use my custom path? Thanks. From prologic at shortcircuit.net.au Thu Jan 8 20:39:50 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 11:39:50 +1000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 11:28 AM, webcomm wrote: > Hmm. When I open it in Windows or with 7-Zip, it contains a text file > that has the data I would expect it to have. I guess that alone > doesn't necessarily prove it's a zip file? > > datum is something I'm downloading via a web service. The providers > of the service say it's a zip file, and have provided a code sample in > C# (which I know nothing about) that shows how to deal with it. In > the code sample, the file is base64 decoded and then unzipped. I'm > trying to write something in Python to decode and unzip the file. Send us a sample of this file in question... cheers James From googler.1.webmaster at spamgourmet.com Thu Jan 8 20:41:56 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 8 Jan 2009 17:41:56 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> Message-ID: <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> Hi searched for "Library/Frameworks/" in the config file and edited it to "@executable_path". Well my configure and make command worked very fine. Just 'make install' aborted after this error message. test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python 2.6" test -d "/Applications/Python 2.6/IDLE.app" && rm -r "/Applications/ Python 2.6/IDLE.app" cp -PR IDLE.app "/Applications/Python 2.6" touch "/Applications/Python 2.6/IDLE.app" cp ./config-main.def "@executable_path/Python.framework/Versions/2.6/ lib/python2.6/idlelib/config-main.def" cp: @executable_path/Python.framework/Versions/2.6/lib/python2.6/ idlelib/config-main.def: No such file or directory make[2]: *** [install] Error 1 make[1]: *** [install_IDLE] Error 2 make: *** [frameworkinstallapps4way] Error 2 That is not cool.. really.. thats not cool. Thanks for your tipps. From ryandw at gmail.com Thu Jan 8 20:44:45 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 17:44:45 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:39?pm, "James Mills" wrote: > Send us a sample of this file in question... It contains data that I can't share publicly. I could ask the providers of the service if they have a dummy file I could use that doesn't contain any real data, but I don't know how responsive they'll be. It's an event registration service called RegOnline. From google at mrabarnett.plus.com Thu Jan 8 20:54:54 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 01:54:54 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <4966AE6E.4070204@mrabarnett.plus.com> webcomm wrote: > On Jan 8, 8:02 pm, MRAB wrote: >> You're just creating a file called "data.zip". That doesn't make it >> a zip file. A zip file has a specific format. If the file doesn't >> have that format then the zipfile module will complain. > > Hmm. When I open it in Windows or with 7-Zip, it contains a text > file that has the data I would expect it to have. I guess that alone > doesn't necessarily prove it's a zip file? > > datum is something I'm downloading via a web service. The providers > of the service say it's a zip file, and have provided a code sample > in C# (which I know nothing about) that shows how to deal with it. > In the code sample, the file is base64 decoded and then unzipped. > I'm trying to write something in Python to decode and unzip the file. > > I checked the file for comments and it has none. At least, when I > view the properties in Windows, there are no comments. > Ah, OK. You didn't explicitly say in your original posting that the decoded data was definitely zipfile data. There was a thread a month ago about gzip Unix commands which could also handle non-gzipped files and I was wondering whether this problem was something like that. Have you tried gzip instead? From ryandw at gmail.com Thu Jan 8 21:56:14 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 18:56:14 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:54?pm, MRAB wrote: > Have you tried gzip instead? There's no option to download the data in a gzipped format. The files are .zip archives. From musiccomposition at gmail.com Thu Jan 8 21:56:56 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 8 Jan 2009 18:56:56 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> On Jan 8, 4:21?pm, Thorsten Kampe wrote: > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > Since you are, I believe, at least the second person to report being bit > > by this confusion, please open an issue at bugs.python.org and suggest a > > couple of revised sentences that you think are more informative. > > Will do tomorrow. The revised sentence could be in the line of "warn > about Python 3.x incompatibilities that cannot trivially be fixed by > 2to3.py". Actually, don't bother now; I've fixed it up in the trunk. From dfnsonfsduifb at gmx.de Thu Jan 8 22:04:41 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 04:04:41 +0100 Subject: Implementing file reading in C/Python Message-ID: <9fri36xno7.ln2@joeserver.homelan.net> Hello group, I've come from C/C++ and am now trying to code some Python because I absolutely love the language. However I still have trouble getting Python code to run efficiently. Right now I have a easy task: Get a file, split it up into a million chunks, count the most prominent character in each chunk and output that value into a file - in other words: Say we have a 2 GB file, we evaluate what character is most prominent in filepos [0, 2048[ - say it's a "A", then put a 65 in there (ord("A")). I've first tried Python. Please don't beat me, it's slow as hell and probably a horrible solution: #!/usr/bin/python import sys import os f = open(sys.argv[1], "r") filesize = os.stat(sys.argv[1])[6] width = 1024 height = 1024 pixels = width * height blocksize = filesize / width / height print("Filesize : %d" % (filesize)) print("Image size : %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) picture = { } havepixels = 0 while True: data = f.read(blocksize) if len(data) <= 0: break datamap = { } for i in range(len(data)): datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 maxchr = None maxcnt = None for (char, count) in datamap.items(): if (maxcnt is None) or (count > maxcnt): maxcnt = count maxchr = char most = maxchr posx = havepixels % width posy = havepixels / width havepixels += 1 if (havepixels % 1024) == 0: print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / pixels)) picture[(posx, posy)] = most pic = open(sys.argv[1] + ".pgm", "w") pic.write("P2\n") pic.write("# CREATOR: Crappyass Python Script\n") pic.write("%d %d\n" % (width, height)) pic.write("255\n") for y in range(height): for x in range(width): pos = (x, y) most = picture.get(pos, -1) pic.write("%d\n" % (most)) As this was horribly slow (20 Minutes for a 2GB file) I coded the whole thing in C also: #include #include #include #include #define BLOCKSIZE 2048 int main(int argc, char **argv) { unsigned int count[256]; int width, height; FILE *f; FILE *in; width = 1024; height = 1024; char temp[2048]; if (argc != 2) { fprintf(stderr, "Argument?\n"); exit(2); } in = fopen(argv[1], "r"); if (!in) { perror("fopen"); exit(1); } snprintf(temp, 255, "%s.pgm", argv[1]); f = fopen(temp, "w"); if (!f) { perror("fopen"); exit(1); } fprintf(f, "P2\n"); fprintf(f, "# CREATOR: C\n"); fprintf(f, "%d %d\n", width, height); fprintf(f, "255\n"); width = 1024; height = 1024; while (fread(temp, 1, sizeof(temp), in) == sizeof(temp)) { int i; memset(count, 0, sizeof(count)); for (i = 0; i < sizeof(temp); i++) { count[(int)temp[i]]++; } int greatest; int maxcount; greatest = 0; maxcount = count[0]; for (i = 1; i < 256; i++) { if (count[i] > maxcount) { maxcount = count[i]; greatest = i; } } fprintf(f, "%d\n", greatest); } fclose(f); fclose(in); return 0; } Which takes about 40 seconds. I want the niceness of Python but a little more speed than I'm getting (I'd settle for factor 2 or 3 slower, but factor 30 is just too much). Can anyone point out how to solve this efficiently in Python? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From google at mrabarnett.plus.com Thu Jan 8 22:05:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 03:05:19 +0000 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <4966BEEF.5040007@mrabarnett.plus.com> Johannes Bauer wrote: > Hello group, > > I've come from C/C++ and am now trying to code some Python because I > absolutely love the language. However I still have trouble getting > Python code to run efficiently. Right now I have a easy task: Get a > file, split it up into a million chunks, count the most prominent > character in each chunk and output that value into a file - in other > words: Say we have a 2 GB file, we evaluate what character is most > prominent in filepos [0, 2048[ - say it's a "A", then put a 65 in there > (ord("A")). > > I've first tried Python. Please don't beat me, it's slow as hell and > probably a horrible solution: > > #!/usr/bin/python > import sys > import os > > f = open(sys.argv[1], "r") > filesize = os.stat(sys.argv[1])[6] > > width = 1024 > height = 1024 > pixels = width * height > blocksize = filesize / width / height > > print("Filesize : %d" % (filesize)) > print("Image size : %dx%d" % (width, height)) > print("Bytes per Pixel: %d" % (blocksize)) > > picture = { } > havepixels = 0 > while True: > data = f.read(blocksize) > if len(data) <= 0: break > > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 > > maxchr = None > maxcnt = None > for (char, count) in datamap.items(): > if (maxcnt is None) or (count > maxcnt): > maxcnt = count > maxchr = char > > most = maxchr > > posx = havepixels % width > posy = havepixels / width > > havepixels += 1 > if (havepixels % 1024) == 0: > print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / pixels)) > > picture[(posx, posy)] = most > > pic = open(sys.argv[1] + ".pgm", "w") > pic.write("P2\n") > pic.write("# CREATOR: Crappyass Python Script\n") > pic.write("%d %d\n" % (width, height)) > pic.write("255\n") > for y in range(height): > for x in range(width): > pos = (x, y) > most = picture.get(pos, -1) > pic.write("%d\n" % (most)) > > As this was horribly slow (20 Minutes for a 2GB file) I coded the whole > thing in C also: > > #include > #include > #include > #include > > #define BLOCKSIZE 2048 > > int main(int argc, char **argv) { > unsigned int count[256]; > int width, height; > FILE *f; > FILE *in; > width = 1024; > height = 1024; > char temp[2048]; > > if (argc != 2) { fprintf(stderr, "Argument?\n"); exit(2); } > > in = fopen(argv[1], "r"); > if (!in) { perror("fopen"); exit(1); } > > snprintf(temp, 255, "%s.pgm", argv[1]); > f = fopen(temp, "w"); > if (!f) { perror("fopen"); exit(1); } > > fprintf(f, "P2\n"); > fprintf(f, "# CREATOR: C\n"); > fprintf(f, "%d %d\n", width, height); > fprintf(f, "255\n"); > > width = 1024; > height = 1024; > while (fread(temp, 1, sizeof(temp), in) == sizeof(temp)) { > int i; > memset(count, 0, sizeof(count)); > for (i = 0; i < sizeof(temp); i++) { > count[(int)temp[i]]++; > } > > int greatest; > int maxcount; > > greatest = 0; > maxcount = count[0]; > for (i = 1; i < 256; i++) { > if (count[i] > maxcount) { > maxcount = count[i]; > greatest = i; > } > } > > fprintf(f, "%d\n", greatest); > } > > fclose(f); > fclose(in); > return 0; > } > > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). > > Can anyone point out how to solve this efficiently in Python? > Have a look at psyco: http://psyco.sourceforge.net/ From prologic at shortcircuit.net.au Thu Jan 8 23:16:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 14:16:05 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 1:04 PM, Johannes Bauer wrote: > Hello group, Hello. (...) > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). > > Can anyone point out how to solve this efficiently in Python? Johannes, your 2 programs, 1 in Python and the other in C do _not_ produce the same result. I have tested this against a randomly generated file from /dev/urandom (10M). Yes the Python one is much slower, but I believe it's bebcause the Python implementation is _correct_ where teh C one is _wrong_ :) The resulting test.bin.pgm from python is exactly 3.5M (from 10M). The resulting test.bin.pgm from the C version is 16K. Something is not quite right here :) cheers James From joe at strout.net Thu Jan 8 23:22:17 2009 From: joe at strout.net (Joe Strout) Date: Thu, 08 Jan 2009 21:22:17 -0700 Subject: why cannot assign to function call In-Reply-To: <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> References: <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Message-ID: <4966D0F9.8070100@strout.net> rurpy at yahoo.com wrote: > "the same as anyone else's" only if [Python's] "idea > of assignment" does not include producing the same > results. > > a = array (1,2,3) > b = a > a[1] = 4 > print b > > C, C++, VBA, Fortran, Perl: 1, 2, 3 > Python: 1, 4, 3 You are mistaken (except perhaps in the Fortran case, which is an oddball by modern standards, and I don't know Perl well enough to judge). C/C++ code: int* a = malloc(3); a[0] = 1; a[1] = 2; a[2] = 3; int* b = a; a[1] = 4; print_array(b) ---> Result: 1, 4, 3 REALbasic code: Dim a() As Integer = Array(1,2,3) Dim b() As Integer = a a(1) = 4 PrintArray b --> Result: 1, 4, 3 VB.NET code would be very similar in syntax, and identical in behavior, to the REALbasic code. Java would also have the same semantics, though my Java is too rusty to get the syntax right without actually trying it. If you can find a language where an array variable is NOT a reference (and thus does not behave exactly as in Python, Java, REALbasic, C++, etc.), then that language is either a dinosaur or some weird academic oddity. Best, - Joe From prologic at shortcircuit.net.au Thu Jan 8 23:29:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 14:29:46 +1000 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 3:13 PM, Johannes Bauer wrote: > Uhh, yes, you're right there... I must admit that I was too lazy to > include all the stat headers and to a proper st_size check in the C > version (just a quick hack), so it's practically hardcoded. > > With files of exactly 2GB in size the results should be the same (more > or less, +- 1 line doesn't matter really), because 2 GB / 2048 (the > buffer) = 1 Million. > > Sorry I didn't mention that, it was really kind of sloppy, > quick-and-dirty C writing on my part. But you're right, the Python > implementation does what is actually supposed to happen. I shall attempt to optimize this :) I have a funny feeling you might be caught up with some features of Python - one notable one being that some things in Python are immutable. psyco might help here though ... cheers James From pavlovevidence at gmail.com Thu Jan 8 23:40:37 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 20:40:37 -0800 (PST) Subject: Making a decorator a staticmethod References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> Message-ID: <77aa3b25-581b-4207-a758-12b4387e471f@z28g2000prd.googlegroups.com> On Jan 8, 1:57?pm, Jonathan Gardner wrote: > (Aside: I really can't think of any reason to use staticmethods in > Python other than to organize functions into namespaces, and even > then, that's what modules are for, right?) In a certain widget toolkit (which I won't mention by name but it begins with G, ends with K, and the middle rhymes with "be") sometimes when subclassing a widget and setting up methods of the class to be event handlers, you want to use staticmethods, because the toolkit passes the widget as the first argument. Since this is a subclass of the widget, the first argument ends up being the object itself, so we end up with odd-looking definitions like this: @staticmethod def on_mouse_button_down(self,event): If it wasn't for staticmethods, you'd have to define it like this: def on_mouse_button_down(self,widget,event): widget and self would always be the same object, and that's just a waste. Carl Banks From narkewoody at gmail.com Thu Jan 8 23:57:44 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 12:57:44 +0800 Subject: Best practice in organize classes into modules Message-ID: Hi, In C++/Java, people usually put one class into one file. What's the suggestion on this topic in Python? I so much interesting this especially when exception classes also involved. Thanks. - narke From prologic at shortcircuit.net.au Fri Jan 9 00:02:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 15:02:51 +1000 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: > In C++/Java, people usually put one class into one file. What's the > suggestion on this topic in Python? I so much interesting this > especially when exception classes also involved. Normally i group related functionality into the one module. I do try to keep my std dev. as low as I can though if that makes any sense. cheers James From akineko at gmail.com Fri Jan 9 00:04:58 2009 From: akineko at gmail.com (akineko) Date: Thu, 8 Jan 2009 21:04:58 -0800 (PST) Subject: multiprocessing and SIGINT References: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> Message-ID: <493e1114-84c4-47df-be80-e93ed4fcbfce@a12g2000pro.googlegroups.com> It is a bit awkward to respond to my posting but I have some updates. I created two simple test programs, one uses threading and another uses multiprocessing. What I found was: (1) test program with threading Only main thread receives SIGINT (generated thread won't receive SIGINT) (2) test program with multiprocessing Both processes receives SIGINT. OS apparently distributes the SIGINT event to processes associated with the terminal. (3) signal handler I realized that I could assign a signal handler specific to a process by placing it to a worker method. def worker(): # this process ignores SIGINT signal.signal(signal.SIGINT, signal.SIG_IGN) ... the rest ... def main(): process = multiprocessing.Process(target=worker) process.start() (4) terminating the spawned process I needed to send a shutdown message to the process via a communication between two processes. You can use Process.terminate() to brutally kill the process but that is a last resort. Now my program can shutdown elegantly when I type Ctrl-C. I see a big potential in multiprocessing as more PCs now have multi- Core CPU. Aki- From narkewoody at gmail.com Fri Jan 9 00:09:06 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 13:09:06 +0800 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 1:02 PM, James Mills wrote: > On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >> In C++/Java, people usually put one class into one file. What's the >> suggestion on this topic in Python? I so much interesting this >> especially when exception classes also involved. > > Normally i group related functionality into the one module. Will that lead to too large source file size? Is there a recommendation on max lines of a python source? Thanks. > I do try to keep my std dev. as low as I can though > if that makes any sense. > > cheers > James > From dfnsonfsduifb at gmx.de Fri Jan 9 00:13:26 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 06:13:26 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: James Mills schrieb: > I have tested this against a randomly generated > file from /dev/urandom (10M). Yes the Python > one is much slower, but I believe it's bebcause > the Python implementation is _correct_ where > teh C one is _wrong_ :) > > The resulting test.bin.pgm from python is exactly > 3.5M (from 10M). The resulting test.bin.pgm from > the C version is 16K. > > Something is not quite right here :) Uhh, yes, you're right there... I must admit that I was too lazy to include all the stat headers and to a proper st_size check in the C version (just a quick hack), so it's practically hardcoded. With files of exactly 2GB in size the results should be the same (more or less, +- 1 line doesn't matter really), because 2 GB / 2048 (the buffer) = 1 Million. Sorry I didn't mention that, it was really kind of sloppy, quick-and-dirty C writing on my part. But you're right, the Python implementation does what is actually supposed to happen. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From clp2 at rebertia.com Fri Jan 9 00:22:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 21:22:03 -0800 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: > On Fri, Jan 9, 2009 at 1:02 PM, James Mills > wrote: >> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>> In C++/Java, people usually put one class into one file. What's the >>> suggestion on this topic in Python? I so much interesting this >>> especially when exception classes also involved. >> >> Normally i group related functionality into the one module. > > Will that lead to too large source file size? Is there a > recommendation on max lines of a python source? Thanks. I don't think there's really a hard-and-fast rule (just like in Java & C++!). When the program starts to feel unwieldly, then start splitting it into multiple modules. Python files can generally contain several classes and functions and still be quite manageable. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Fri Jan 9 00:35:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 8 Jan 2009 21:35:19 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> Message-ID: <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> On Jan 9, 1:56?pm, Benjamin wrote: > On Jan 8, 4:21?pm, Thorsten Kampe wrote: > > > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > > Since you are, I believe, at least the second person to report being bit > > > by this confusion, please open an issue at bugs.python.org and suggest a > > > couple of revised sentences that you think are more informative. > > > Will do tomorrow. The revised sentence could be in the line of "warn > > about Python 3.x incompatibilities that cannot trivially be fixed by > > 2to3.py". > > Actually, don't bother now; I've fixed it up in the trunk. Would you mind giving a pointer to where or what your fix is? The reason for asking is that Thorsten's suggestion is ambiguous: warn about some? all? 3.x problems that can't be trivially fixed by 2to3? Can't be "all"; there are in fact a number of problems that can't be trivially fixed by 2to3 and can't be detected by running 2.6 with the -3 option. These include (a) problems that cause a reasonably informative exception in 3.x right at the point where the problem exists (b) problems where the behaviour has changed but no exception is raised, and your code lurches off down the wrong path, and you need to work backwards from subsequent exception(s) and/or failing test case (s) to pin-point the problem. I'll use string constants to provide an example of each type. When faced with "abcd", 2to3 has no way of telling whether that should be str ("abcd") or bytes (b"abcd"). In the vast majority of cases, to guess it should be str is correct, so there is no change to the source file, and a warning would almostly always be noise. Example of problem (a): chunks is a list of slices of bytes read from a binary file. In 2.x you write glued = ''.join(chunks) In 3.0 you get this: >>> chunks = [b'x', b'y'] >>> ''.join(chunks) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 0: expected str instance, bytes found Example of problem (b): some_bytes has been read from a file that was opened in 'rb' mode and contains the 4 ASCII bytes 'abcd' # 2.x simulation >> some_bytes == "abcd" True # 3.0 simulation >>> type(some_bytes) >>> type("abcd") >>> some_bytes == "abcd" False # because the types are not comparable for equality. Another type (b) example is the (majority-guessed) 2to3 change from [c] StringIO.StringIO to io.StringIO ... if you really should feed some library an io.BytesIO instance instead, it can travel quite a distance before blowing up. Perhaps some of this info could be put into http://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 ... or maybe a separate HOWTO or wiki chapter could be set up for porting to 3.x, including topics like: (1) maintaining one set of source files (when you are maintaining a package that must run on e.g. 2.1 through 3.x) (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x support-range issue but would like to have the one set of source looking like 3.x code instead of the ugliness of version-conditional stuff like BYTES_NULL = bytes(0) # 3.x or BYTES_NULL = '' # 2.x and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? Cheers, John From rurpy at yahoo.com Fri Jan 9 00:56:05 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 21:56:05 -0800 (PST) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Message-ID: <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >> "the same as anyone else's" only if [Python's] "idea >> of assignment" does not include producing the same >> results. >> >> a = array (1,2,3) >> b = a >> a[1] = 4 >> print b >> >> C, C++, VBA, Fortran, Perl: 1, 2, 3 >> Python: 1, 4, 3 > > You are mistaken I don't think so. See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 The code I quoted there was tested. In the C/C++ case, array-to-pointer coercion confuses the issue so I embedded the array in a struct which is more like an "object". The assignment semantics are copy-like producing the results I quoted. (Keep in mind my point was not to show the behavior of arrays, but to show that several common languages *do not* use Python's "*all* names are references" model -- though of course this does not preclude their having some Python-like assignments since they all have some way of doing references.) It seems plausible to me that experience with copy-like assignments semantics in other languages accounts for the frequent misunderstanding of Python assignments that is seen on this list. > (except perhaps in the Fortran case, which is an > oddball by modern standards, and I don't know Perl well enough to judge). Whether or not Perl is oddball or modern is irrelevant; it is still widely used and it is reasonable to assume that there are a significant number of people coming to Python with a lot of previous experience with Perl. Even Fortran is still used in scientific computing circles (or so I'm told) although I can't say I have seen any c.l.p. postings from people claiming Python doesn't work like fortran. :-) > C/C++ code: > > int* a = malloc(3); > a[0] = 1; > a[1] = 2; > a[2] = 3; > int* b = a; > a[1] = 4; > print_array(b) > ---> Result: 1, 4, 3 > > REALbasic code: > > Dim a() As Integer = Array(1,2,3) > Dim b() As Integer = a > a(1) = 4 > PrintArray b > --> Result: 1, 4, 3 > > VB.NET code would be very similar in syntax, and identical in behavior, > to the REALbasic code. Don't know about RealBasic or VB.Net, my experience and quoted results were from MS Visual Basic for Apps which is (I think) based on VB6. From nl.srinivas at gmail.com Fri Jan 9 00:58:27 2009 From: nl.srinivas at gmail.com (Srinivasa NL) Date: Fri, 9 Jan 2009 11:28:27 +0530 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: <8b85ec440901082158g6f1a277ao4f85284323a74914@mail.gmail.com> You can use subprocess module to start an application and also read it's output. You can kill it yourself (when you know when to do it) Srinivas. On Fri, Jan 9, 2009 at 2:36 AM, Tim Arnold wrote: > Hi, I don't even know what to google for on this one. I need to drive a > commercial desktop app (on windows xp) since the app doesn't have a batch > interface. It's intended to analyze one file at a time and display a > report. > > I can get the thing to write out the report an html browser, but I have > thousands of files I need it to analyze every night. > > Is there any lib or recipe(s) for doing something like this via python? > > thanks, > --Tim Arnold > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Fri Jan 9 01:31:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 16:31:49 +1000 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 2:29 PM, James Mills wrote: > I shall attempt to optimize this :) > I have a funny feeling you might be caught up with > some features of Python - one notable one being that > some things in Python are immutable. > > psyco might help here though ... What does this little tool do anyway ? It's very interesting the images it creates out of files. What is this called ? I'm curious :) I haven't had much tiem to optimize it yet - I'll try to when I get home from work. cheers James From steve at holdenweb.com Fri Jan 9 01:49:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 01:49:30 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <4966BEEF.5040007@mrabarnett.plus.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <4966BEEF.5040007@mrabarnett.plus.com> Message-ID: MRAB wrote: > Johannes Bauer wrote: >> Hello group, [and about 200 other lines there was no need to quote] [...] > Have a look at psyco: http://psyco.sourceforge.net/ Have a little consideration for others when making a short reply to a long post, please. Trim what isn't necessary. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 9 01:52:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 01:52:44 -0500 Subject: Best practice in organize classes into modules In-Reply-To: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> References: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: >> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >> wrote: >>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>>> In C++/Java, people usually put one class into one file. What's the >>>> suggestion on this topic in Python? I so much interesting this >>>> especially when exception classes also involved. >>> Normally i group related functionality into the one module. >> Will that lead to too large source file size? Is there a >> recommendation on max lines of a python source? Thanks. > > I don't think there's really a hard-and-fast rule (just like in Java & > C++!). When the program starts to feel unwieldly, then start splitting > it into multiple modules. Python files can generally contain several > classes and functions and still be quite manageable. > The OP can take a look at the standard library to get some impression of what's been considered acceptable over the years. Just remember that some of the code is a little antiquated, as working code is not rewritten just for the fun of fixing the bugs this would inject. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From narkewoody at gmail.com Fri Jan 9 02:10:17 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:10:17 +0800 Subject: Best practice in organize classes into modules In-Reply-To: References: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> Message-ID: On Fri, Jan 9, 2009 at 2:52 PM, Steve Holden wrote: > Chris Rebert wrote: >> On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: >>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >>> wrote: >>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>>>> In C++/Java, people usually put one class into one file. What's the >>>>> suggestion on this topic in Python? I so much interesting this >>>>> especially when exception classes also involved. >>>> Normally i group related functionality into the one module. >>> Will that lead to too large source file size? Is there a >>> recommendation on max lines of a python source? Thanks. >> >> I don't think there's really a hard-and-fast rule (just like in Java & >> C++!). When the program starts to feel unwieldly, then start splitting >> it into multiple modules. Python files can generally contain several >> classes and functions and still be quite manageable. >> > The OP can take a look at the standard library to get some impression of > what's been considered acceptable over the years. Just remember that > some of the code is a little antiquated, as working code is not > rewritten just for the fun of fixing the bugs this would inject. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for all your inputs! From narkewoody at gmail.com Fri Jan 9 02:15:28 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:15:28 +0800 Subject: threading in PyQt vs threading in standard library Message-ID: Hi, I am considering using PyQt for GUI programs, and I notices that both of them include threading supports, so which one should I pick up? Similar also applies 'socket'. Thanks. From phil at riverbankcomputing.com Fri Jan 9 02:32:34 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Fri, 09 Jan 2009 07:32:34 +0000 Subject: threading in PyQt vs threading in standard library In-Reply-To: References: Message-ID: On Fri, 9 Jan 2009 15:15:28 +0800, "Steven Woody" wrote: > Hi, > > I am considering using PyQt for GUI programs, and I notices that both > of them include threading supports, so which one should I pick up? > Similar also applies 'socket'. I'd recommend using the PyQt versions of both. A significant advantage of PyQt's sockets is that they are integrated with the event loop. This means you don't need threads to handle networking. Phil From narkewoody at gmail.com Fri Jan 9 02:48:17 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:48:17 +0800 Subject: threading in PyQt vs threading in standard library In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 3:32 PM, Phil Thompson wrote: > On Fri, 9 Jan 2009 15:15:28 +0800, "Steven Woody" > wrote: >> Hi, >> >> I am considering using PyQt for GUI programs, and I notices that both >> of them include threading supports, so which one should I pick up? >> Similar also applies 'socket'. > > I'd recommend using the PyQt versions of both. > > A significant advantage of PyQt's sockets is that they are integrated with > the event loop. This means you don't need threads to handle networking. > Thank you. From a.bilgin.a at gmail.com Fri Jan 9 02:49:39 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Fri, 9 Jan 2009 09:49:39 +0200 Subject: Python Imaging Library and textmate Message-ID: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> Hello, I am a beginner in python and I am trying to create image files that contain lines from a text file. I am trying to do this with PIL, which seems like a suitable tool. I have a copy of TextMate(1.5.8) and I run Macosx 10.5.6 The problem is, even though I installed PIL correctly (I get no errors from "import Image" in IDLE or in terminal), I can't get TextMate to import the module. I keep getting "ImportError: No module named Image" error. I tried reloading TextMate's bundles but that did not work either. I used this set of instructions to install PIL http://www.p16blog.com/p16/2008/05/appengine-installing-pil-on-os-x-1053.html I think there is something wrong with symbolic links, although I am also a novice to UNIX based systems so I do not know for sure what to do about it. There was a similar thread in this list with textmate but I can't understand how that issue was solved in the end. Thanks Ali -------------- next part -------------- An HTML attachment was scrubbed... URL: From kay.schluehr at gmx.net Fri Jan 9 02:54:56 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 8 Jan 2009 23:54:56 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> <1642fe0d-c7e5-41ca-9b7b-753d96646ebc@i18g2000prf.googlegroups.com> Message-ID: O.K. Mark. Since you seem to accept the basic requirement to build an *external* DSL I can provide some help. I'm the author of EasyExtend ( EE ) which is a system to build external DSLs for Python. http://www.fiber-space.de/EasyExtend/doc/EE.html EE is very much work in progress and in the last year I was more engaged with increasing power than enhance accessibility for beginners. So be warned. A DSL in EE is called a *langlet*. Download the EE package and import it in a Python shell. A langlet can then be built this way: >>> import EasyExtend >>> EasyExtend.new_langlet("my_langlet", prompt = "myl> ", source_ext = ".dsl") This creates a bunch of files in a directory /EasyExtend/langlets/my_langlet Among them is run_my_langet.py and langlet.py. You can cd to the directory and apply $python run_my_langlet.py which opens a console with prompt 'myl>'. Each langlet is immediatly interactive. A user can also run a langlet specific module like $python run_my_langlet.py mod.dsl with the suffix .dsl defined in the langlet builder function. Each module xxx.dsl can be imported from other modules of the my_langlet langlet. EE provides a generic import hook for user defined suffixes. In order to do anything meaningful one has to implement langlet transformations in the langlet.py module. The main transformations are defined in a class called LangletTransformer. It defines a set of visitor methods that are marked by a decorator called @trans. Each @trans method is named like a terminal/non-terminal in a grammar file and responds to a terminal or non-terminal node of the parse tree which is traversed. The structure of the parse tree is the same as those you'd get from Pythons builtin parser. It is entirely determined by 4 files: - Grammar which is precisely the Python grammar found in the Python source distribution. - Grammar.ext which defines new non-terminals and overwrites old ones. - Token which defines Pythons token. - Token.ext which is the analog of Grammar.ext for token definitions. The Grammar.ext file is in the directory my_langlet/parsedef. There is also an analog lexdef directory for Token.ext. A possible Grammar.ext extension of the Python grammar that overwrites two non-terminals of looks like this: Grammar.ext ----------- trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | NAME | NUMBER | STRING atom: ('(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING) ----------- Once this has been defined you can start a new my_langlet session and type myl> navigate_to 'www.openstreetmap.org' website Traceback (most recent call last): File "C:\lang\Python25\lib\site-packages\EasyExtend\eeconsole.py", line 270, in compile_cst _code = compile(src,"","single", COMPILER_FLAGS) File "", line 1 navigate_to 'www.openstreetmap.org' website ^ SyntaxError: invalid syntax myl> It will raise a SyntaxError but notice that this error stems from the *compiler*, not the parser. The parser perfectly accepts the modified non-terminals and produces a parse tree. This parse tree has to be transformed into a valid Python parse tree that can be accepted by Pythons bytecode compiler. I'm not going into detail here but recommend to read the tutorial http://www.fiber-space.de/EasyExtend/doc/tutorial/EETutorial.html that walks through a complete example that defines a few terminals, non-terminals and the transformations accordingly. It also shows how to use command line options to display parse tree properties, unparse parse trees back into source code ( you can eliminate DSL code from the code base entirely and replace it by equivalent Python code ), do some validation on transformed parse trees etc. From martin at v.loewis.de Fri Jan 9 03:16:16 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:16:16 +0100 Subject: ulimit stack size and python threads In-Reply-To: <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> References: <49667a11$0$22812$9b622d9e@news.freenet.de> <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> Message-ID: <496707D0.9050502@v.loewis.de> > Always crashing because I asked the OS to please not allow a process > to grow too big is what I call overloading the meaning of ulimit -s. Please trust that there is no explicit code in the Python interpreter that tests whether the stack size is 4GB, and then produces an explicit crash. > It's quite surprising. Not to mention the poor error message. AFAICT, you didn't even *report* yet what the error message is, so I don't know whether it is poor. Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 03:16:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 08:16:17 GMT Subject: BadZipfile "file is not a zip file" References: Message-ID: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > The error... ... > BadZipfile: File is not a zip file > > When I look at data.zip in Windows, it appears to be a valid zip file. > I am able to uncompress it in Windows XP, and can also uncompress it > with 7-Zip. It looks like zipfile is not able to read a "table of > contents" in the zip file. That's not a concept I'm familiar with. No, ZipFile can read table of contents: Help on method printdir in module zipfile: printdir(self) unbound zipfile.ZipFile method Print a table of contents for the zip file. In my experience, zip files originating from Windows sometimes have garbage at the end of the file. WinZip just ignores the garbage, but other tools sometimes don't -- if I recall correctly, Linux unzip successfully unzips the file but then complains that the file was corrupt. It's possible that you're running into a similar problem. > data.zip is created in this script... > > decoded = base64.b64decode(datum) > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > file = zipfile.ZipFile('data.zip', "r") > > datum is a base64 encoded zip file. Again, I am able to open data.zip > as if it's a valid zip file. Maybe there is something wrong with the > approach I've taken to writing the data to data.zip? I'm not sure if it > matters, but the zipped data is Unicode. The full signature of ZipFile is: ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and see if that makes any difference. The zip format does support alternative compression methods, it's possible that this particular file uses a different sort of compression which Python doesn't deal with. > What would cause a zip file to not have a table of contents? What makes you think it doesn't have one? -- Steven From martin at v.loewis.de Fri Jan 9 03:18:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:18:01 +0100 Subject: ulimit stack size and python threads In-Reply-To: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> References: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> Message-ID: <49670839$0$25219$9b622d9e@news.freenet.de> > I see. I should be blaming the default behavior of pthreads. You shouldn't blame anybody. Instead, you should sit down and study the problem in detail, until you fully understand it. Then you should start contributing fixes. Never ever should you spread blame. Regards, Martin From koranthala at gmail.com Fri Jan 9 03:21:09 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 9 Jan 2009 00:21:09 -0800 (PST) Subject: Encrypted Logging in python Message-ID: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> I was wondering if there is a mechanism to encrypt logging automatically in python. The issue is as follows: (a) An application (after py2exe) will go as executable and there is no need for the user to know that it is written in python. If an exception occurs and it is logged, then the user can understand it is written in python. (b) A security threat. If an exception occurs, the code is seen by the user - and possibly be misused. Base64 encoding somewhat helps - which is supported by logging module - but even that is not very secure. If there can be an option - wherein we send in the password and the logging is encrypted - it might be better. I would have loved to provide the code, but I am completely tied up at the moment and wont be able to help for another month. From martin at v.loewis.de Fri Jan 9 03:30:17 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:30:17 +0100 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <49670B19.4090504@v.loewis.de> > What would cause a zip file to not have a table of contents? AFAICT, _EndRecData is failing to find the "end of zipfile" structure in the file. You might want debug through it to see where it looks, and how it decides that this structure is not present in the file. Towards 22 bytes before the end of the file, the bytes PK\005\006 should appear. If they don't appear, you don't have a zipfile. If they appear, but elsewhere towards the end of the file, there might be a bug in the zip file module (or, more likely, the zip file uses an optional zip feature which the module doesn't implement). Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 03:32:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 08:32:23 GMT Subject: Replying to list messages References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> <878wpmguop.fsf@benfinney.id.au> Message-ID: <01770252$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 10:42:13 -0800, Paul McNett wrote: > Ben Finney wrote: >> Paul McNett

writes: >>> But arguing about this here isn't going to change anything: opinions >>> differ just like tabs/spaces and bottom-post/top-post. >> >> In cases like this, one side can simply be wrong :-) >> >> Best of luck getting your programs behaving as you want them to! > > BTW, I agree with you that in an ideal, pure world mailing lists > wouldn't munge the reply-to field, but when 80% of the people use email > clients that don't support reply-list, the practical thing to do as a > list admin that wants to avoid having to explain over and over again > that "your client software is broken" is to simply swallow some pride > and munge the reply-to. Now, 99% of the users are happy, and the > remaining 1% are elite enough to understand how to get around any > problems this caused. The only problem this leads to is people who hit send without checking where they are sending to are likely to be embarrassed when they send personal posts to the entire mailing list. As far as I'm concerned, hitting send without looking to see who you are sending to is akin to turning into a busy road without looking to see if there are any cars coming: any accident that happens is YOUR fault, not the fault of the road, car, mail client or mailing list. It boggles my brain that [insert sweeping generalisation here] the people who are most vehement about blaming the mailing list software are usually also the least understanding when (l)users click "OK" to dialogs without reading what the dialog says first. -- Steven From pavlovevidence at gmail.com Fri Jan 9 03:46:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 00:46:27 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 2:16?am, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > The error... > ... > > BadZipfile: File is not a zip file > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > I am able to uncompress it in Windows XP, and can also uncompress it > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > contents" in the zip file. ?That's not a concept I'm familiar with. > > No, ZipFile can read table of contents: > > ? ? Help on method printdir in module zipfile: > > ? ? printdir(self) unbound zipfile.ZipFile method > ? ? ? ? Print a table of contents for the zip file. > > In my experience, zip files originating from Windows sometimes have > garbage at the end of the file. WinZip just ignores the garbage, but > other tools sometimes don't -- if I recall correctly, Linux unzip > successfully unzips the file but then complains that the file was > corrupt. It's possible that you're running into a similar problem. The zipfile format is kind of brain dead, you can't tell where the end of the file is supposed to be by looking at the header. If the end of file hasn't yet been reached there could be more data. To make matters worse, somehow zip files came to have text comments simply appended to the end of them. (Probably this was for the benefit of people who would cat them to the terminal.) Anyway, if you see something that doesn't adhere to the zipfile format, you don't have any foolproof way to know if it's because the file is corrupted or if it's just an appended comment. Most zipfile readers use a heuristic to distinguish. Python's zipfile module just assumes it's corrupted. The following post from a while back gives a solution that tries to snip the comment off so that zipfile module can handle it. It might help you out. http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 Carl Banks From jstroud at mbi.ucla.edu Fri Jan 9 03:50:24 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 09 Jan 2009 00:50:24 -0800 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: Tim Arnold wrote: > Hi, I don't even know what to google for on this one. I need to drive a > commercial desktop app (on windows xp) since the app doesn't have a batch > interface. It's intended to analyze one file at a time and display a > report. > > I can get the thing to write out the report an html browser, but I have > thousands of files I need it to analyze every night. > > Is there any lib or recipe(s) for doing something like this via python? You are a little thin on details here. My only advice at this point is to check out os.system, which is the simplest option. From there you can move to the popen2 module for greater control, but if you are talking about a gui app, you may run into hang-ups. A quick recipe would be the following pretend application that recursively descends from the current directory calling the utility named "dosapp" on every file it finds that ends with "jpg" (what "dosapp" does is left to your imagination): import os def doit(suffix, adir, filenames): for afile in filenames: if afile.endswith(suffix): pathname = os.path.join(adir, afile) os.system('dosapp %s' % pathname) top = '.' suffix = '.jpg' os.path.walk(top, doit, suffix) Read the docs on os.path.walk, of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 03:54:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 09:54:44 +0100 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: <496710ba$0$27487$426a74cc@news.free.fr> Steven Woody a ?crit : > On Fri, Jan 9, 2009 at 1:02 PM, James Mills > wrote: >> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>> In C++/Java, people usually put one class into one file. What's the >>> suggestion on this topic in Python? I so much interesting this >>> especially when exception classes also involved. >> Normally i group related functionality into the one module. > > Will that lead to too large source file size? When the case happens, then you can safely refactor the module into a package with submodules, and use the package's __init__.py to make it a facade for the submodules so the refactoring is transparent for client code. But given Python's expressivity and metaprogramming features, it's usually easy to avoid cruft and boilerplate and keep the code short. > Is there a > recommendation on max lines of a python source? Not really - use your own judgement, mostly. As far as I'm concerned, I start worrying about this when a module grows bigger than 1Kloc, but I seldom have this problem. From narkewoody at gmail.com Fri Jan 9 03:59:26 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 16:59:26 +0800 Subject: Best practice in organize classes into modules In-Reply-To: <496710ba$0$27487$426a74cc@news.free.fr> References: <496710ba$0$27487$426a74cc@news.free.fr> Message-ID: On Fri, Jan 9, 2009 at 4:54 PM, Bruno Desthuilliers wrote: > Steven Woody a ?crit : >> >> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >> wrote: >>> >>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody >>> wrote: >>>> >>>> In C++/Java, people usually put one class into one file. What's the >>>> suggestion on this topic in Python? I so much interesting this >>>> especially when exception classes also involved. >>> >>> Normally i group related functionality into the one module. >> >> Will that lead to too large source file size? > > When the case happens, then you can safely refactor the module into a > package with submodules, and use the package's __init__.py to make it a > facade for the submodules so the refactoring is transparent for client code. really a smart idea. Did you mean putting some 'import statement in __init__.py and use the old module name as the new package name? Thanks. From bj_666 at gmx.net Fri Jan 9 04:15:20 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:15:20 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6soit7F7bavsU1@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > I've first tried Python. Please don't beat me, it's slow as hell and > probably a horrible solution: > > #!/usr/bin/python > import sys > import os > > f = open(sys.argv[1], "r") Mode should be 'rb'. > filesize = os.stat(sys.argv[1])[6] `os.path.getsize()` is a little bit more readable. > width = 1024 > height = 1024 > pixels = width * height > blocksize = filesize / width / height > > print("Filesize : %d" % (filesize)) print("Image size : %dx%d" > % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is a statement and not a function. > picture = { } > havepixels = 0 > while True: > data = f.read(blocksize) > if len(data) <= 0: break if data: break is enough. > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 Here you are creating a list full of integers to use them as index into `data` (twice) instead of iterating directly over the elements in `data`. And you are calling `ord()` for *every* byte in the file although you just need it for one value in each block. If it's possible to write the raw PGM format this conversion wouldn't be necessary at all. For the `datamap` a `collections.defaultdict()` might be faster. > maxchr = None > maxcnt = None > for (char, count) in datamap.items(): > if (maxcnt is None) or (count > maxcnt): > maxcnt = count > maxchr = char Untested: maxchr = max((i, c) for c, i in datamap.iteritems())[1] > most = maxchr Why? > posx = havepixels % width > posy = havepixels / width posx, posy = divmod(havepixels, width) Don't know if this is faster though. > havepixels += 1 > if (havepixels % 1024) == 0: > print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / > pixels)) > > picture[(posx, posy)] = most Why are you using a dictionary as "2d array"? In the C code you simply write the values sequentially, why can't you just use a flat list and append here? Ciao, Marc 'BlackJack' Rintsch From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 04:15:50 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 10:15:50 +0100 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: <4966750c$0$5150$426a74cc@news.free.fr> References: <4966750c$0$5150$426a74cc@news.free.fr> Message-ID: <496715ac$0$15321$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Sergey Kishchenko a ?crit : (snip) >> #prints "Ouch!" >> f=Foo() >> if f: >> print "Ouch!" >> >> So, default __nonzero__ impl is to return True. > > Yes. It's clearly documented FWIW. To be more exact: there's no "default __nonzero__". The boolean value of an object is eval'd this way: If the object is None (special cased by the interpreter AFAICT), it is false. Else if the object implements __nonzero__, it has the boolean value returned by __nonzero__. Else if the object implements __len__, it has the boolean value of its length. Else if is true. >> I think, this >> behaviour conflicts with 'Explicit is better than implicit' > > Why so ? It *is* explicit that the default for an object is to have a > true value in a boolean context. I meant "explicit because documented", of course. >> and >> 'Practicality beats purity' > > Quite on the contrary. From a practical POV, the default truth values of > Python objects are most of the time what you practically want in a > boolean context - that is, any non-None object, non-empty sequence and > non-zero numeric objects are true. __nonzero__ is here for the *very > few* corner cases where this is not the sensible default. >> statements. I think, throwing a TypeError >> exception would be better. It will result in more explicit code with >> fewer errors. As a last note wrt/ explicitness and practicality: Implementing your proposition, one would have to either put each and every boolean expression in a try/except block or "explicitly" define __nonzero__ for each and any class - most of the time (about 99.9999% I'd say) implementing it as to return True - and expect that *everybody* does so. So yes, from a "purity" POV, it might look "more explicit". But this would certainly not be practical at all. OTHO, since boolean algebra only knows two values, it's clear that what is not false is by definition true. So having a default value (true) and a way to override it (__len__ and __nonzero__) is perhaps less "pure", but really as explicit and much more practical. My 2 cents... From googler.1.webmaster at spamgourmet.com Fri Jan 9 04:18:40 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 01:18:40 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> Message-ID: <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> hm... any ideas? From cournape at gmail.com Fri Jan 9 04:24:01 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 9 Jan 2009 18:24:01 +0900 Subject: Python 2.6 fails on compiling > Bug report In-Reply-To: <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: <5b8d13220901090124k64b7b867v6419cef7f08fc52f@mail.gmail.com> On Fri, Jan 9, 2009 at 6:18 PM, wrote: > hm... any ideas? Posting the config.log file would be a first step to give more information, David From prologic at shortcircuit.net.au Fri Jan 9 04:33:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 19:33:53 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch wrote: >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. Not true as of 2.6+ and 3.0+ print is now a function. cheers James From sjmachin at lexicon.net Fri Jan 9 04:37:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 01:37:50 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <2b959051-0871-44da-acb7-e43b0eaf2f66@x16g2000prn.googlegroups.com> On Jan 9, 7:16?pm, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > The error... > ... > > BadZipfile: File is not a zip file > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > I am able to uncompress it in Windows XP, and can also uncompress it > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > contents" in the zip file. ?That's not a concept I'm familiar with. > > No, ZipFile can read table of contents: > > ? ? Help on method printdir in module zipfile: > > ? ? printdir(self) unbound zipfile.ZipFile method > ? ? ? ? Print a table of contents for the zip file. > > In my experience, zip files originating from Windows sometimes have > garbage at the end of the file. WinZip just ignores the garbage, but > other tools sometimes don't -- if I recall correctly, Linux unzip > successfully unzips the file but then complains that the file was > corrupt. It's possible that you're running into a similar problem. > > > data.zip is created in this script... > > > ? ? decoded = base64.b64decode(datum) > > ? ? f = open('data.zip', 'wb') > > ? ? f.write(decoded) > > ? ? f.close() > > ? ? file = zipfile.ZipFile('data.zip', "r") > > > datum is a base64 encoded zip file. ?Again, I am able to open data.zip > > as if it's a valid zip file. ?Maybe there is something wrong with the > > approach I've taken to writing the data to data.zip? ?I'm not sure if it > > matters, but the zipped data is Unicode. > > The full signature of ZipFile is: > > ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) > > Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and > see if that makes any difference. "compression" is irrelevant when reading. The compression method used is stored on a per-file basis, not on a per-archive basis, and it hasn't got anywhere near per-file details when that exception is raised. "allowZip64" has not been used either. > > The zip format does support alternative compression methods, it's > possible that this particular file uses a different sort of compression > which Python doesn't deal with. > > > What would cause a zip file to not have a table of contents? > > What makes you think it doesn't have one? > > -- > Steven From antroy at gmail.com Fri Jan 9 04:38:21 2009 From: antroy at gmail.com (Ant) Date: Fri, 9 Jan 2009 01:38:21 -0800 (PST) Subject: drive a desktop app from python? References: Message-ID: On Jan 8, 9:06?pm, "Tim Arnold" wrote: > Is there any lib or recipe(s) for doing something like this via python? Look into the PyWin32 extension module. It gives access to Windows internals including the COM interface. You'll need to do some research into how to automate the GUI you're using from other sources (there are often VBA examples on the web that can be modified). http://pywin32.sourceforge.net/ I've successfully used this in the past for automating MS Excel. From bj_666 at gmx.net Fri Jan 9 04:41:49 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:41:49 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <6soketF7bavsU2@mid.uni-berlin.de> On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch > wrote: >> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >> is a statement and not a function. > > Not true as of 2.6+ and 3.0+ > > print is now a function. Please read again what I wrote. Ciao, Marc 'BlackJack' Rintsch From bj_666 at gmx.net Fri Jan 9 04:45:50 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:45:50 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6sokmeF7bavsU3@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 Here is an error by the way: You call `ord()` just on the left side of the ``=``, so all keys in the dictionary are mapped to ones after the loop which gives a pretty boring PGM. :-) Ciao, Marc 'BlackJack' Rintsch From prologic at shortcircuit.net.au Fri Jan 9 04:46:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 19:46:58 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <6soketF7bavsU2@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> <6soketF7bavsU2@mid.uni-berlin.de> Message-ID: On Fri, Jan 9, 2009 at 7:41 PM, Marc 'BlackJack' Rintsch wrote: > Please read again what I wrote. Lol I thought "<3" was a smiley! :) Sorry! cheers James From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:01:00 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:01:00 GMT Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <01771716$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 18:33:50 +0000, Mark Wooding wrote: > [Steven's message hasn't reached my server, so I'll reply to it here. > Sorry if this is confusing.] > > Aaron Brady wrote: >> On Jan 8, 1:45 am, Steven D'Aprano >> wrote: >> > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: >> > >> > > The `they're just objects' model is very simple, but gets tied up >> > > in knots explaining things. The `it's all references' model is >> > > only a little more complicated, but explains everything. >> > >> > But it *over* explains, because it implies things that "everybody >> > knows" about references in other languages that aren't true for >> > Python. > > I addressed this elsewhere. Summary: `pass-by-reference' is a different > thing to `all you manipulate are references': You know, I've written a fair bit of Python code over the years, and I've never manipulated a reference *once*. Ints, strings, floats, lists, tuples... but references? Never. I'm pretty sure that no other pure-Python coder has manipulated references either. They've manipulated objects. Whatever the VM does under the hood is another story. If you insist on talking about implementations, then at least get it right: in Python, like every other programming language, all you do is flip bits. It's *all* bit flipping. That's why we should try to keep the different layers of explanation separate, without conflating them. Python programmers don't actually flip bits, and neither do they manipulate references. Python programmers don't have access to bits, or references. What they have access to is objects. (Of course, there are ways to get under the hood if you really want to.) > Python does pass-by-value, > but the things it passes -- by value -- are references. If you're going to misuse pass-by-value to describe what Python does, *everything* is pass-by-value "where the value is foo", for some foo. You can't have anything but pass-by-value with current computer technology, because computers don't actually move arguments, they only copy bytes. So pass-by-value becomes a meaningless term, because it describes every computer language imaginable, including hypothetical ones using calling conventions not yet invented, and therefore explains nothing. > (The `pass-by-*' notions are confusingly named anyway. Pass-by-name > doesn't actually involve names at all.) You might find them confusing, but I don't. What I find confusing is that people insist on misusing terminology invented for describing one type of behaviour in order to use it for a completely different type of behaviour just because of certain similarities under the hood. >> > Of course it's not literally true that "everybody knows" that you can >> > use references to implement a swap(x, y) procedure. But people coming >> > from a C or Pascal background tend to assume that everything is like >> > C/Pascal, and there are a lot of them. If C was a rare, unfamiliar >> > language, my opposition to using the term "reference" would be a lot >> > milder. Maybe in another five years? > > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. Except for arrays. > If you want a function to > modify your variable, you have to pass a pointer value which points to > it. Yes, because the variable is copied before the function sees it. So if you pass a struct, and modify one of the struct's fields, the caller doesn't see the change. Now try that with Python, and you'll see completely different behaviour. (You'll have to use something *like* a struct, because Python doesn't have them. Try an object with attributes.) In other words... C is call-by-value, and (according to you) Python is call-by-value, but they behaviour differently. > Python has no pointer values, so you need a different hack. The > hack usually involves lists. (Though it's easier in the main to return > compound data objects like tuples. I don't suppose that a proposal for > true multiple return values would go down well here. No, didn't think > so...) Out of curiosity, what makes Python returning tuples less "true" than "true multiple return values", and what can you do with TMRVs that you can't do with tuples? >> > Okay, the abstraction has leaked again... are the paperweights >> > references to the objects, or the names we've bound objects to? I'm >> > confused... > > They're the references to the objects. You don't bind names to objects. Amazing. It sure feels like it to me. x = 23 There's a name, and an object, and I've bound the name to the object so I can refer to the object 23 by the name x. > You bind names slots in which you store references. I'm pretty sure I don't. I'd have noticed. You may have missed my last question: >> > How do we deal with anonymous objects in your model? > What I am pretty sure of is that references are going to have to enter > the picture at some point, because other models get too complicated. Well, I dare say that at *some* point all models are insufficient. The map is not the territory, and there's always something that gets left out. But I think your model with strings is more complicated: robots, sticky Blu-Tack, string that you can't touch or see, and so forth. Compared to that, TARDIS technology enabling objects to be in two places at once is remarkably straightforward. Despite it being physically unrealistic, it's logically simple. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:09:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:09:58 GMT Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <01771931$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 00:46:27 -0800, Carl Banks wrote: > On Jan 9, 2:16?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: >> > The error... >> ... >> > BadZipfile: File is not a zip file >> >> > When I look at data.zip in Windows, it appears to be a valid zip >> > file. I am able to uncompress it in Windows XP, and can also >> > uncompress it with 7-Zip. ?It looks like zipfile is not able to read >> > a "table of contents" in the zip file. ?That's not a concept I'm >> > familiar with. >> >> No, ZipFile can read table of contents: >> >> ? ? Help on method printdir in module zipfile: >> >> ? ? printdir(self) unbound zipfile.ZipFile method >> ? ? ? ? Print a table of contents for the zip file. >> >> In my experience, zip files originating from Windows sometimes have >> garbage at the end of the file. WinZip just ignores the garbage, but >> other tools sometimes don't -- if I recall correctly, Linux unzip >> successfully unzips the file but then complains that the file was >> corrupt. It's possible that you're running into a similar problem. > > > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. If the end of > file hasn't yet been reached there could be more data. To make matters > worse, somehow zip files came to have text comments simply appended to > the end of them. (Probably this was for the benefit of people who would > cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile format, > you don't have any foolproof way to know if it's because the file is > corrupted or if it's just an appended comment. Yes, this has lead to a nice little attack vector, using hostile Java classes inside JAR files (a variant of ZIP). http://www.infoworld.com/article/08/08/01/ A_photo_that_can_steal_your_online_credentials_1.html or http://snipurl.com/9oh0e -- Steven From gandalf at shopzeus.com Fri Jan 9 05:11:43 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 11:11:43 +0100 Subject: Fatal Python error: ceval: tstate mix-up Message-ID: <496722DF.6080206@shopzeus.com> After upgrading my system, a program started to throw this error, and make a core dump: Fatal Python error: ceval: tstate mix-up Kernel log says: Jan 9 05:06:49 shopzeus kernel: pid 89184 (python), uid 1024: exited on signal 6 (core dumped) I found out that this can happen only when executing Python code without holding the GIL. My program is written entriely in Python, but uses some third part libraries: py25-json py25-psycopg2 Here is Python version: Python 2.5.2 (r252:60911, Nov 17 2008, 22:19:20) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 (OS is FreeBSD 7.0 amd64 stable on dual quad core xeon 5420, it that matters...) I have the code dump, but I do not know how to debug that. What should I do? Thanks, Laszlo From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:15:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:15:35 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <01771a82$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch > wrote: >>> print("Filesize : %d" % (filesize)) print("Image size : >>> %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) >> >> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >> is a statement and not a function. > > Not true as of 2.6+ and 3.0+ > > print is now a function. Not so. print is still a statement in 2.6. $ python2.6 Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13) [GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> print 23 23 -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:16:05 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:16:05 GMT Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> Message-ID: <01771aa0$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 00:21:09 -0800, koranthala wrote: > I was wondering if there is a mechanism to encrypt logging automatically > in python. > The issue is as follows: > (a) An application (after py2exe) will go as executable and there > is no need for the user to know that it is written in python. If an > exception occurs and it is logged, then the user can understand it is > written in python. > (b) A security threat. If an exception occurs, the code is seen by > the user - and possibly be misused. Security by obscurity is not security. If your application isn't secure against people who know what language is written in, then it isn't secure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:17:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:17:36 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <01771afb$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 09:15:20 +0000, Marc 'BlackJack' Rintsch wrote: >> picture = { } >> havepixels = 0 >> while True: >> data = f.read(blocksize) >> if len(data) <= 0: break > > if data: > break > > is enough. You've reversed the sense of the test. The OP exits the loop when data is empty, you exit the loop when it *isn't* empty. -- Steven From bj_666 at gmx.net Fri Jan 9 05:32:34 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 10:32:34 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6sone1F7bavsU5@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > As this was horribly slow (20 Minutes for a 2GB file) I coded the whole > thing in C also: Yours took ~37?minutes for 2?GiB here. This "just" ~15?minutes: #!/usr/bin/env python from __future__ import division, with_statement import os import sys from collections import defaultdict from functools import partial from itertools import imap def iter_max_values(blocks, block_count): for i, block in enumerate(blocks): histogram = defaultdict(int) for byte in block: histogram[byte] += 1 yield max((count, byte) for value, count in histogram.iteritems())[1] if i % 1024 == 0: print 'Progresss: %.1f%%' % (100 * i / block_count) def write_pgm(filename, width, height, pixel_values): with open(filename, 'w') as pgm_file: pgm_file.write('P2\n' '# CREATOR: Crappyass Python Script\n' '%d %d\n' '255\n' % (width, height)) pgm_file.writelines('%d\n' % value for value in pixel_values) def main(): filename = sys.argv[1] filesize = os.path.getsize(filename) width = 1024 height = 1024 pixels = width * height blocksize = filesize // width // height print 'Filesize : %d' % filesize print 'Image size : %dx%d' % (width, height) print 'Bytes per Pixel: %d' % blocksize with open(filename, 'rb') as data_file: blocks = iter(partial(data_file.read, blocksize), '') pixel_values = imap(ord, iter_max_values(blocks, pixels)) write_pgm(filename + '.pgm', width, height, pixel_values) if __name__ == '__main__': main() Ciao, Marc 'BlackJack' Rintsch From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 05:34:55 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 11:34:55 +0100 Subject: Best practice in organize classes into modules In-Reply-To: References: <496710ba$0$27487$426a74cc@news.free.fr> Message-ID: <49672835$0$31446$426a74cc@news.free.fr> Steven Woody a ?crit : > On Fri, Jan 9, 2009 at 4:54 PM, Bruno Desthuilliers > wrote: >> Steven Woody a ?crit : >>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >>> wrote: >>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody >>>> wrote: >>>>> In C++/Java, people usually put one class into one file. What's the >>>>> suggestion on this topic in Python? I so much interesting this >>>>> especially when exception classes also involved. >>>> Normally i group related functionality into the one module. >>> Will that lead to too large source file size? >> When the case happens, then you can safely refactor the module into a >> package with submodules, and use the package's __init__.py to make it a >> facade for the submodules so the refactoring is transparent for client code. > > really a smart idea. Mostly a common Python idiom. > Did you mean putting some 'import statement in > __init__.py and use the old module name as the new package name? Yes, you guessed. From steve at holdenweb.com Fri Jan 9 05:41:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 05:41:39 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: [...] >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. > Portability? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Fri Jan 9 05:42:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 02:42:32 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 7:46?pm, Carl Banks wrote: > On Jan 9, 2:16?am, Steven D'Aprano > > > > > cybersource.com.au> wrote: > > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > > The error... > > ... > > > BadZipfile: File is not a zip file > > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > > I am able to uncompress it in Windows XP, and can also uncompress it > > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > > contents" in the zip file. ?That's not a concept I'm familiar with. > > > No, ZipFile can read table of contents: > > > ? ? Help on method printdir in module zipfile: > > > ? ? printdir(self) unbound zipfile.ZipFile method > > ? ? ? ? Print a table of contents for the zip file. > > > In my experience, zip files originating from Windows sometimes have > > garbage at the end of the file. WinZip just ignores the garbage, but > > other tools sometimes don't -- if I recall correctly, Linux unzip > > successfully unzips the file but then complains that the file was > > corrupt. It's possible that you're running into a similar problem. > > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. ?If the end of > file hasn't yet been reached there could be more data. ?To make > matters worse, somehow zip files came to have text comments simply > appended to the end of them. ?(Probably this was for the benefit of > people who would cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile > format, you don't have any foolproof way to know if it's because the > file is corrupted or if it's just an appended comment. > > Most zipfile readers use a heuristic to distinguish. ?Python's zipfile > module just assumes it's corrupted. > > The following post from a while back gives a solution that tries to > snip the comment off so that zipfile module can handle it. ?It might > help you out. > > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 And here's a little gadget that might help the diagnostic effort; it shows the archive size and the position of all the "magic" PKnn markers. In a "normal" uncommented archive, EndArchive_pos + 22 == archive_size. 8<--- # usage: python zip_susser.py name_of_archive.zip import sys grimoire = [ ("FileHeader", "PK\003\004"), # magic number for file header ("CentralDir", "PK\001\002"), # magic number for central directory ("EndArchive", "PK\005\006"), # magic number for end of archive record ("EndArchive64", "PK\x06\x06"), # magic token for Zip64 header ("EndArchive64Locator", "PK\x06\x07"), # magic token for locator header ] f = open(sys.argv[1], 'rb') buff = f.read() f.close() blen = len(buff) print "archive size is", blen for magic_name, magic in grimoire: pos = 0 while pos < blen: pos = buff.find(magic, pos) if pos < 0: break print "%s at %d" % (magic_name, pos) pos += 4 8<--- HTH, John From steve at holdenweb.com Fri Jan 9 05:45:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 05:45:29 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <01771a82$0$8693$c3e8da3@news.astraweb.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> <01771a82$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > >> On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch >> wrote: >>>> print("Filesize : %d" % (filesize)) print("Image size : >>>> %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) >>> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >>> is a statement and not a function. >> Not true as of 2.6+ and 3.0+ >> >> print is now a function. > > > Not so. print is still a statement in 2.6. > > $ python2.6 > Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13) > [GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> print 23 > 23 > C:\Users\sholden>\python26\python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print >>> OK, I confess I missed out >>> from __future__ import print_function regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pistacchio at gmail.com Fri Jan 9 05:47:42 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 11:47:42 +0100 Subject: Line completion with custom commands Message-ID: Hi, my Python program can be launched with a range of different options (or subcommands) like: $ myProgram doSomething $ myProgram doSomethingElse $ myProgram nowDoSomethingDifferent I want it to use auto-completion with so that if i type "myProgram d" it returns "myProgram doSomething" and if i type "myProgram n" it renders "myProgram nowDoSomethingDifferent". This is similar to the average use of the module rlcompleter, but it does not pick possible completion options from the filesystem (or from history) but from a custom set of strings (that correspond to the available options for my program) Any idea on how to implement this? I'm aware of the variable PYTHONSTARTUP (that should point to a file I don't know how to write). As a working example, django-admin (from the django package) has the same exact feature i'm looking for From lkcl at lkcl.net Fri Jan 9 05:51:13 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Fri, 9 Jan 2009 10:51:13 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: <49666AF7.9010804@v.loewis.de> References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> <49666AF7.9010804@v.loewis.de> Message-ID: On Thu, Jan 8, 2009 at 9:07 PM, "Martin v. L?wis" wrote: >> i'd just ... much rather be completely independent of proprietary >> software when it comes to building free software. > > I guess my question is then: why do you want to use Windows in the > first place? ha ha :) the same question was asked when i started the nt domains reverse-engineering for samba, in 1996. the answer is: i don't. but there are a lot of users and developers who feel that they don't have a choice. or haven't been given one. so if it's possible for me, as one of the "under 1% of computer users i.e. linux" to compile stuff that will work on the "over 95% of computers used by everyone else i.e. windows" _and_ i get to stick to free software principles, that's gotta be good. take pywebkit-gtk as an example. the first-level (and some of the second-level) dependencies for pywebkit-gtk are roughly as follows: * libstdc++ * cairo, pango, gdk, fontconfig, gtk * libxml2 (which is dodgy) * libxslt1 (which is so dodgy and dependent on incompatible versions of libxml2 it can't be compiled on win32) * libicu38 * libcurl * libssl * webkit * python2.5 * python-gobect * python-gtk that's a *big* xxxxing list that comes in at a whopping 40mb of _binaries_. webkit itself comes in at 10mb alone. libicu38 fails _miserably_ to cross-compile with mingw32. i was damn lucky to have beaten it into submission: it took two days and i couldn't run any of the tests, but actually managed to get at least some .libs, .dlls and .a's out of the mess. libxslt1 and libxml2 have compile errors in mutually incompatible versions on win32, plus, unfortunately, the versions that _do_ compile correctly (really old versions like libxslt-1.12 + libxml2-18 or something) are not the ones that can be used on webkit! i had to get the source code for gcc (4.4) because when linking webkit against the MSVC-compiled libicu38 gcc actually segfaulted (!). and that was tracked down to exception handling across process / thread boundaries in libstdc++-6 which had only literally been fixed/patched a few days before i started the monster-compile-process. i tried hunting down python-gobject and python-gtk for win32, but there is a dependency needed before you get to that: python25.lib. as i mentioned previously i tried hunting down a .lib for python25 but of course that would be useless unless i also have a libtool-compiled .a so there wasn't any point. so, all the hard work that i did cross-compiling up webkit for win32 was completely wasted because python itself could not be compiled on linux for a win32 platform. hence my interest in making sure that it can be. _then_ i can go back and revisit the monster compile process and finally come up with the goods, on win32, on the gobject-based DOM-model manipulation stuff i've added to pywebkit-gtk. i've got linux covered, i've got macosx covered. win32 is the last one. l. From mrkafk at gmail.com Fri Jan 9 05:56:35 2009 From: mrkafk at gmail.com (mk) Date: Fri, 09 Jan 2009 11:56:35 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Johannes Bauer wrote: > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). This probably doesn't contribute much, but have you tried using Python profiler? You might have *something* wrong that eats up a lot of time in the code. The factor of 30 indeed does not seem right -- I have done somewhat similar stuff (calculating Levenshtein distance [edit distance] on words read from very large files), coded the same algorithm in pure Python and C++ (using linked lists in C++) and Python version was 2.5 times slower. Regards, mk From steve at holdenweb.com Fri Jan 9 06:03:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 06:03:47 -0500 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: gu wrote: > > Hi, my Python program can be launched with a range of different options > (or subcommands) like: > > $ myProgram doSomething > $ myProgram doSomethingElse > $ myProgram nowDoSomethingDifferent > > I want it to use auto-completion with so that if i type "myProgram d" it > returns "myProgram doSomething" and if i type "myProgram n" it renders > "myProgram nowDoSomethingDifferent". This is similar to the average use > of the module rlcompleter, but it does not pick possible completion > options from the filesystem (or from history) but from a custom set of > strings (that correspond to the available options for my program) > > Any idea on how to implement this? > > I'm aware of the variable PYTHONSTARTUP (that should point to a file I > don't know how to write). > > As a working example, django-admin (from the django package) has the > same exact feature i'm looking for The issue here is that Python doesn't get control until afer you've hit RETURN on the command line. so nothing you can do in your program or interpreter setup will have any effect on how the command shell behaves. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Fri Jan 9 06:05:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 09 Jan 2009 05:05:46 -0600 Subject: figuring week of the day.... In-Reply-To: <49665986.7080301@thechases.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <49665986.7080301@thechases.com> Message-ID: <49672F8A.6040001@tim.thechases.com> Tim Chase wrote: > tekion wrote: >> Is there a module where you could figure week of the day, like where >> it starts and end. I need to do this for a whole year. Thanks. > > the monthcalendar() call returns the whole month's calendar which > may be more what you want for the big-picture. And if you want a whole year's worth, you can get pretty close with: import itertools as i import calendar as c for month in range(1,13): for week in c.monthcalendar(2009, month): print repr(w) You don't detail how you want the month-boundaries to behave, so this gives "calendar"'s default behavior of filling in zeros on month-boundaries, so November through the 1st week in Dec 2009 comes back as ... [0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], ... rather than ... [26, 27, 28, 29, 30, 31, 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, 1, 2, 3, 4, 5, 6], ... -tkc From pistacchio at gmail.com Fri Jan 9 06:12:15 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:12:15 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <4967310F.8070704@gmail.com> Steve Holden wrote: > gu wrote: >> Hi, my Python program can be launched with a range of different options >> (or subcommands) like: >> >> $ myProgram doSomething >> $ myProgram doSomethingElse >> $ myProgram nowDoSomethingDifferent >> >> I want it to use auto-completion with so that if i type "myProgram d" it >> returns "myProgram doSomething" and if i type "myProgram n" it renders >> "myProgram nowDoSomethingDifferent". This is similar to the average use >> of the module rlcompleter, but it does not pick possible completion >> options from the filesystem (or from history) but from a custom set of >> strings (that correspond to the available options for my program) >> >> Any idea on how to implement this? >> >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >> don't know how to write). >> >> As a working example, django-admin (from the django package) has the >> same exact feature i'm looking for > > The issue here is that Python doesn't get control until afer you've hit > RETURN on the command line. so nothing you can do in your program or > interpreter setup will have any effect on how the command shell behaves. > > regards > Steve I see, but how does django-admin work, then? From pistacchio at gmail.com Fri Jan 9 06:12:15 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:12:15 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <4967310F.8070704@gmail.com> Steve Holden wrote: > gu wrote: >> Hi, my Python program can be launched with a range of different options >> (or subcommands) like: >> >> $ myProgram doSomething >> $ myProgram doSomethingElse >> $ myProgram nowDoSomethingDifferent >> >> I want it to use auto-completion with so that if i type "myProgram d" it >> returns "myProgram doSomething" and if i type "myProgram n" it renders >> "myProgram nowDoSomethingDifferent". This is similar to the average use >> of the module rlcompleter, but it does not pick possible completion >> options from the filesystem (or from history) but from a custom set of >> strings (that correspond to the available options for my program) >> >> Any idea on how to implement this? >> >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >> don't know how to write). >> >> As a working example, django-admin (from the django package) has the >> same exact feature i'm looking for > > The issue here is that Python doesn't get control until afer you've hit > RETURN on the command line. so nothing you can do in your program or > interpreter setup will have any effect on how the command shell behaves. > > regards > Steve I see, but how does django-admin work, then? From castironpi at gmail.com Fri Jan 9 06:15:57 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 9 Jan 2009 03:15:57 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> On Jan 9, 4:01?am, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 18:33:50 +0000, Mark Wooding wrote: > > [Steven's message hasn't reached my server, so I'll reply to it here. > > Sorry if this is confusing.] > > > Aaron Brady wrote: > >> On Jan 8, 1:45 am, Steven D'Aprano > >> wrote: > >> > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > >> > > The `they're just objects' model is very simple, but gets tied up > >> > > in knots explaining things. ?The `it's all references' model is > >> > > only a little more complicated, but explains everything. > > >> > But it *over* explains, because it implies things that "everybody > >> > knows" about references in other languages that aren't true for > >> > Python. > > > I addressed this elsewhere. ?Summary: `pass-by-reference' is a different > > thing to `all you manipulate are references': > > You know, I've written a fair bit of Python code over the years, and I've > never manipulated a reference *once*. Ints, strings, floats, lists, > tuples... but references? Never. snip > That's why we should try to keep the different layers of explanation > separate, without conflating them. Python programmers don't actually flip > bits, and neither do they manipulate references. Python programmers don't > have access to bits, or references. What they have access to is objects. snip > >> > How do we deal with anonymous objects in your model? > > What I am pretty sure of is that references are going to have to enter > > the picture at some point, because other models get too complicated. > > Well, I dare say that at *some* point all models are insufficient. The > map is not the territory, and there's always something that gets left > out. But I think your model with strings is more complicated: robots, > sticky Blu-Tack, string that you can't touch or see, and so forth. > Compared to that, TARDIS technology enabling objects to be in two places > at once is remarkably straightforward. Despite it being physically > unrealistic, it's logically simple. > > -- > Steven Possible compromise. You can think of functions as mutation-only. You pass the object, and it gets a new (additional) name. The old name doesn't go in. Regardless, IMO, references don't add any explanatory power; they just make you feel cocky that you know what they are. M: If 'fun()' returned a reference, you would be able to assign to it. m: You can't assign to it. C: It doesn't return a reference. -- Why can't I assign to a function call? -- Python variables are references only. -- Ok, why can't I assign to a function call? -- [Explanation Steven is trying to give.] In other words, Mark and Joe, cut to the chase. You're shirking. From marco at sferacarta.com Fri Jan 9 06:18:14 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 09 Jan 2009 12:18:14 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: gu wrote: > I see, but how does django-admin work, then? from bash: complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram From steve at holdenweb.com Fri Jan 9 06:24:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 06:24:29 -0500 Subject: Line completion with custom commands In-Reply-To: <4967310F.8070704@gmail.com> References: <4967310F.8070704@gmail.com> Message-ID: gu wrote: > Steve Holden wrote: >> gu wrote: >>> Hi, my Python program can be launched with a range of different options >>> (or subcommands) like: >>> >>> $ myProgram doSomething >>> $ myProgram doSomethingElse >>> $ myProgram nowDoSomethingDifferent >>> >>> I want it to use auto-completion with so that if i type "myProgram d" it >>> returns "myProgram doSomething" and if i type "myProgram n" it renders >>> "myProgram nowDoSomethingDifferent". This is similar to the average use >>> of the module rlcompleter, but it does not pick possible completion >>> options from the filesystem (or from history) but from a custom set of >>> strings (that correspond to the available options for my program) >>> >>> Any idea on how to implement this? >>> >>> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >>> don't know how to write). >>> >>> As a working example, django-admin (from the django package) has the >>> same exact feature i'm looking for >> >> The issue here is that Python doesn't get control until afer you've hit >> RETURN on the command line. so nothing you can do in your program or >> interpreter setup will have any effect on how the command shell behaves. >> >> regards >> Steve > > I see, but how does django-admin work, then? > Probably the issue you has was not knowing the name of the feature. When I asked Google to tell me about django-admin command completion it said: http://code.djangoproject.com/ticket/1240 as the first hit. As you will see, this is done by configuring the shell to know about the specific commands it has to deal with. Enjoy! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pistacchio at gmail.com Fri Jan 9 06:28:04 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:28:04 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <496734C4.201@gmail.com> Marco Mariani wrote: > gu wrote: > >> I see, but how does django-admin work, then? > > from bash: > > complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram This worked like a charm, thank you so much. Is this available for bash only or any shell? From zugnush at gmail.com Fri Jan 9 06:38:34 2009 From: zugnush at gmail.com (zugnush at gmail.com) Date: Fri, 9 Jan 2009 03:38:34 -0800 (PST) Subject: drive a desktop app from python? References: Message-ID: <4dd5903b-78f2-4ed4-9885-a43ed07da80c@w1g2000prk.googlegroups.com> > Is there any lib or recipe(s) for doing something like this via python? > I've used pywinauto to do something similar, and found it good. http://pywinauto.openqa.org/ From boyee118 at gmail.com Fri Jan 9 06:39:10 2009 From: boyee118 at gmail.com (Korobase) Date: Fri, 9 Jan 2009 19:39:10 +0800 Subject: [Help] The pywinauto Can't select the MDI's menu using the MenuItems() which return []. In-Reply-To: <8c7f10c60812220156k4a290fa1re469bc8c4a4019ae@mail.gmail.com> References: <85676.52949.qm@web32801.mail.mud.yahoo.com> <8c7f10c60812220156k4a290fa1re469bc8c4a4019ae@mail.gmail.com> Message-ID: 2008/12/22 Simon Brunning > 2008/12/21 : > > The code below opens the Choose Font dialog on my Spanish Windows > version: > > > > py> from pywinauto.application import Application > > py> app = Application.start("Notepad.exe") > > Notepad's menus are build with MFC. Word's menus are not. Trust me, > give it up. For automating Word, COM (with Mark Hammond's excellent > Python/COM bridge) is the only way to go. Yeah. But the GuiLib program also don't work. You can dowload sample from http://www.beyondata.com/ and use the pywinauto to test it. I want to know how to do the GuiLib's automation. > > > -- > Cheers, > Simon B. > simon at brunningonline.net > -- > http://mail.python.org/mailman/listinfo/python-list > -- "OpenBookProject"-?????????? ??: http://groups.google.com/group/OpenBookProject ??: http://wiki.woodpecker.org.cn/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Fri Jan 9 06:55:27 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 03:55:27 -0800 (PST) Subject: Unexpected scientific notation References: Message-ID: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> On Jan 8, 1:00?am, Paul McNett wrote: > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be causing > this. What would be choosing to display such a normal number in scientific notation? > > Ideas? [I thought I replied to this earlier, but the post isn't showing up. So here it is again.] I suspect it's your use of the Decimal normalize() method that's causing this. Trailing zeros on Decimal instances are significant, so Decimal('30.0'), Decimal('30') and Decimal('3E+1') are considered distinct (though they all have the same value). The normalize method strips all trailing zeros, turning Decimal('30.0') into Decimal('3E +1'). One way to get around this is to add 0 after normalizing: this will make sure that scientific notation is used only for very large or small numbers, as usual. Python 2.7a0 (trunk:68298:68318, Jan 6 2009, 10:39:14) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal >>> 0 + Decimal('3E1') Decimal('30') >>> Decimal('0.0') + Decimal('3E1') Decimal('30.0') Adding 0 also has the side-effect of turning a negative zero into a positive zero, but I suspect that this isn't going to worry you much. :) You might also want to look at the Decimal.quantize method. Mark From gandalf at shopzeus.com Fri Jan 9 07:40:36 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 13:40:36 +0100 Subject: Fatal Python error: ceval: tstate mix-up In-Reply-To: <496722DF.6080206@shopzeus.com> References: <496722DF.6080206@shopzeus.com> Message-ID: <496745C4.60105@shopzeus.com> I could start "gdb python python.core" but don't know what it means. Unfortunately, there are no debugging symbols. %gdb /usr/local/bin/python python.core GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)... Core was generated by `python'. Program terminated with signal 6, Aborted. Reading symbols from /lib/libutil.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libutil.so.7 Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libm.so.5 Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done. Loaded symbols for /lib/libthr.so.3 Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libc.so.7 Reading symbols from /usr/local/lib/python2.5/lib-dynload/time.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/time.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/collections.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/collections.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/datetime.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/datetime.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/cStringIO.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/cStringIO.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/strop.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/strop.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/operator.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/operator.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_struct.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_struct.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/binascii.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/binascii.so Reading symbols from /usr/local/lib/python2.5/site-packages/sgmlop.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/sgmlop.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/pyexpat.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/pyexpat.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_socket.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_socket.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_ssl.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_ssl.so Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done. Loaded symbols for /usr/lib/libssl.so.5 Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libcrypto.so.5 Reading symbols from /usr/local/lib/python2.5/lib-dynload/math.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/math.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_random.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_random.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/fcntl.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/fcntl.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/select.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/select.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/rand.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/rand.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/crypto.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/crypto.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/SSL.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/SSL.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/cPickle.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/cPickle.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_weakref.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_weakref.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_hashlib.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_hashlib.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_bisect.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_bisect.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_locale.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_locale.so Reading symbols from /usr/local/lib/python2.5/site-packages/psycopg2/_psycopg.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/psycopg2/_psycopg.so Reading symbols from /usr/local/lib/libpq.so.5...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libpq.so.5 Reading symbols from /usr/local/lib/libintl.so.8...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libintl.so.8 Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done. Loaded symbols for /lib/libcrypt.so.4 Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libiconv.so.3 Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done. Loaded symbols for /libexec/ld-elf.so.1 #0 0x0000000800a9cfec in thr_kill () from /lib/libc.so.7 [New Thread 0x800d05060 (LWP 100709)] [New Thread 0x800d04ef0 (LWP 100269)] [New Thread 0x800d04d80 (LWP 100253)] [New Thread 0x800d04c10 (LWP 100231)] [New Thread 0x800d04aa0 (LWP 100226)] [New Thread 0x800d04930 (LWP 100206)] [New Thread 0x800d047c0 (LWP 100189)] [New Thread 0x800d01120 (LWP 100096)] (gdb) From daved170 at gmail.com Fri Jan 9 07:45:33 2009 From: daved170 at gmail.com (Dave Dave) Date: Fri, 9 Jan 2009 14:45:33 +0200 Subject: pySerial - accessing GSM module failed Message-ID: Hello all, I'm newbie in the serial buissness and I beed some Help. I'm a student at my last year and I got final assaignment. My goal is to comunicate with SIM free, GSM Module through computer. I want to simulate SIM card by receiving and transferring data from my code. In order to understand how to comunicate with the GSM module I took an existing module which gut RS232 connector and connected it to the computer. I ran my python code: class MySerial(): def __init__ (self,port,baundrate,....) self.s = serial.Serial(port,baundreate,....) def read(self,size=1): txt = self.s.read(size) def write(self,text=''): txt = self.s.write(text) def main(): obj = MySerial('COM1') obj.write('ATI') sleep(1) obj.read(10) the code run and I send the comman 'ATI' which ask the GSM Module if everything is OK. the read line returs 'ATI'. echo to my write function. Whenever I run this comman ('ATI') through hyperterminal I gut the result : 232 OK Does any one got an Idea why my code isn't getting the same answer from the GSM Module? thanks dave -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Fri Jan 9 08:01:10 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 09 Jan 2009 14:01:10 +0100 Subject: Force exception on attribute write access only one object In-Reply-To: References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: <6sp04mF7hgjdU1@mid.individual.net> Hi Peter and others, your idea was good, but it does not work with Django ORM Models: Traceback (most recent call last): File "/localhome/modw/django/core/handlers/base.py", line 87, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/localhome/modw/foo/views/filter.py", line 473, in add return edit(request, 'add') File "/localhome/modw/foo/views/filter.py", line 493, in edit filter=form.save() File "/localhome/modw/foo/views/filter.py", line 457, in save action=form.save() File "/localhome/modw/django/forms/models.py", line 315, in save if self.instance.pk is None: File "/localhome/modw/django/db/models/base.py", line 292, in _get_pk_val return getattr(self, meta.pk.attname) AttributeError: 'MyAction' object has no attribute 'filter_action_ptr_id' Peter Otten schrieb: > Thomas Guettler wrote: > >> for debugging I want to raise an exception if an attribute is >> changed on an object. Since it is only for debugging I don't want >> to change the integer attribute to a property. > > Why? > >> This should raise an exception: >> >> myobj.foo=1 >> >> Background: >> Somewhere this value gets changed. But I don't now where. > > If you change your mind: > > class A(object): > def __init__(self): > self.foo = 42 > > a = A() > b = A() > > class B(A): > @property > def foo(self): > return self.__dict__["foo"] > > b.__class__ = B > > a.foo = "whatever" > print b.foo > b.foo = "whatever" > > Peter -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From koranthala at gmail.com Fri Jan 9 08:02:16 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 9 Jan 2009 05:02:16 -0800 (PST) Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> <01771aa0$0$8693$c3e8da3@news.astraweb.com> Message-ID: <3d7f8241-50ae-48e1-a541-f562f056aa8d@r37g2000prr.googlegroups.com> On Jan 9, 3:16?pm, Steven D'Aprano wrote: > On Fri, 09 Jan 2009 00:21:09 -0800, koranthala wrote: > > I was wondering if there is a mechanism to encrypt logging automatically > > in python. > > ? ?The issue is as follows: > > ? ? (a) An application (after py2exe) will go as executable and there > > is no need for the user to know that it is written in python. If an > > exception occurs and it is logged, then the user can understand it is > > written in python. > > ? ? (b) A security threat. If an exception occurs, the code is seen by > > the user - and possibly be misused. > > Security by obscurity is not security. If your application isn't secure > against people who know what language is written in, then it isn't secure. > > -- > Steven I understand that completely. My point is that even though I can try to make the application completely secure - I can never be sure of that. Especially if your company is a very small one - and might not be able to have the best programmers around. So, another layer of security - even security through obscurity - can give that bit extra time in which the bugs in the system can be ironed out. Also, what I am asking is a generic option in logging - which can help the adoption of the logging framework in even closed source systems. It is not just about security - just that a closed source company might be much more comfortable in using the system if crypt is there. From gandalf at shopzeus.com Fri Jan 9 08:08:39 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 14:08:39 +0100 Subject: Fatal Python error: ceval: tstate mix-up In-Reply-To: <496722DF.6080206@shopzeus.com> References: <496722DF.6080206@shopzeus.com> Message-ID: <49674C57.3040908@shopzeus.com> Meanwhile I'm trying to turn off threads in that program one by one. I just got this new type of error: Fatal Python error: PyThreadState_Delete: invalid tstate From goldnery at gmail.com Fri Jan 9 08:34:06 2009 From: goldnery at gmail.com (Gandalf) Date: Fri, 9 Jan 2009 05:34:06 -0800 (PST) Subject: win32gui Message-ID: Hi, everyone I'm searching the win32gui lib to find a way to get the text under the user cursor. so far I managed to find only the controller ID which under the cursor this way cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) their is function called GetWindowText I tried to use but it doesn't work in most of the time someone know a way to do this? thank you! From dfnsonfsduifb at gmx.de Fri Jan 9 08:38:20 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:38:20 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch schrieb: >> f = open(sys.argv[1], "r") > > Mode should be 'rb'. Check. >> filesize = os.stat(sys.argv[1])[6] > > `os.path.getsize()` is a little bit more readable. Check. >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. I write all new code to work under Python3.0. Actually I develop on Python 3.0 but the code is currently deployed onto 2.6. >> picture = { } >> havepixels = 0 >> while True: >> data = f.read(blocksize) >> if len(data) <= 0: break > > if data: > break > > is enough. > >> datamap = { } >> for i in range(len(data)): >> datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 > > Here you are creating a list full of integers to use them as index into > `data` (twice) instead of iterating directly over the elements in > `data`. And you are calling `ord()` for *every* byte in the file > although you just need it for one value in each block. If it's possible > to write the raw PGM format this conversion wouldn't be necessary at all. OK, those two are just stupid, you're right. I changed it to: datamap = { } for i in data: datamap[i] = datamap.get(i, 0) + 1 array = sorted([(b, a) for (a, b) in datamap.items()], reverse=True) most = ord(array[0][1]) pic.write("%d\n" % (most)) > For the `datamap` a `collections.defaultdict()` might be faster. Tried that, not much of a change. >> maxchr = None >> maxcnt = None >> for (char, count) in datamap.items(): >> if (maxcnt is None) or (count > maxcnt): >> maxcnt = count >> maxchr = char > > Untested: > > maxchr = max((i, c) for c, i in datamap.iteritems())[1] This is nice, I use it - the sort thing was a workaround anyways. >> most = maxchr > > Why? I don't really know anymore :-\ >> posx = havepixels % width >> posy = havepixels / width > > posx, posy = divmod(havepixels, width) That's a nice one. > Why are you using a dictionary as "2d array"? In the C code you simply > write the values sequentially, why can't you just use a flat list and > append here? Yup, I changed the Python code to behave the same way the C code did - however overall it's not much of an improvement: Takes about 15 minutes to execute (still factor 23). Thanks for all your pointers! Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From dfnsonfsduifb at gmx.de Fri Jan 9 08:42:37 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:42:37 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: James Mills schrieb: > What does this little tool do anyway ? > It's very interesting the images it creates > out of files. What is this called ? It has no particular name. I was toying around with the Princeton Cold Boot Attack (http://citp.princeton.edu/memory/). In particular I was interested in how much memory is erased when I would (on my system) enable the slow POST (which counts through all RAM three times). I downloaded the provided utitilities, dumped my system memory via PXE boot onto another system after resetting it hard in the middle of a running Linux session. I did sync, though. Praise all journaling filesystems. As a 2GB file is not really of much use for telling where something is and where isn't, I thought of that picture coloring. In a 1024x1024 picture a pixel is 2048 bytes with 2GB of RAM, so exactly half a page. This is sufficiently high resolution to detect what's in there. > I'm curious :) I haven't had much tiem to > optimize it yet - I'll try to when I get home from work. Thanks for your effort, I appreciate it... hope my work leads to some meaningful results. Currently it looks (*cough* if there aren't bugs in my picture code) as if my PC would reset the whole RAM anyways, although I do not have any ECC. Strange. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From dfnsonfsduifb at gmx.de Fri Jan 9 08:46:19 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:46:19 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <6sone1F7bavsU5@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch schrieb: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > >> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >> thing in C also: > > Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: Ah, ok... when implementing your suggestions int he other post, I did not get such a drastic performance increase. I really will have a look at it and try to locate where I'm wasting the time. Thanks a lot, Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From mdw at distorted.org.uk Fri Jan 9 08:47:43 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 13:47:43 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > As a side comment (because it always bugs me when I read this, even > though I read it in very authoritative sources), ISTM that C passes > everything by value except arrays; they are passed by reference (by > passing a pointer to the array by value.) Admittedly, the close > relationship between arrays and pointers makes it easy conflate them. Arrays are distinctly second-class citizens in C. Basically, in C, arrays aren't passed at all but there's some syntactic sugar so you can squint and con yourself that they're passed by reference. If you try to pass an array, the array name immediately decays to a pointer, and the pointer gets passed instead -- by value. The corresponding function parameter must be a pointer to an approrpriate kind of thing, though you're allowed to write []s to confuse yourself if you like -- T D[] in a function parameter declaration means precisely the same as T *D -- to the extent that &D has type T **D and so on. -- [mdw] From dfnsonfsduifb at gmx.de Fri Jan 9 08:48:30 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:48:30 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: mk schrieb: > Johannes Bauer wrote: > >> Which takes about 40 seconds. I want the niceness of Python but a little >> more speed than I'm getting (I'd settle for factor 2 or 3 slower, but >> factor 30 is just too much). > > This probably doesn't contribute much, but have you tried using Python > profiler? You might have *something* wrong that eats up a lot of time in > the code. No - and I've not known there was a profiler yet have found anything meaningful (there seems to be an profiling C interface, but that won't get me anywhere). Is that a seperate tool or something? Could you provide a link? > The factor of 30 indeed does not seem right -- I have done somewhat > similar stuff (calculating Levenshtein distance [edit distance] on words > read from very large files), coded the same algorithm in pure Python and > C++ (using linked lists in C++) and Python version was 2.5 times slower. Yup, that was about what I had expected (and what I could well live with, it's a tradeoff). Thanks, Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From duane.kaufman at gmail.com Fri Jan 9 09:08:22 2009 From: duane.kaufman at gmail.com (TheSeeker) Date: Fri, 9 Jan 2009 06:08:22 -0800 (PST) Subject: win32gui References: Message-ID: On Jan 9, 7:34?am, Gandalf wrote: > Hi, everyone > I'm searching the win32gui lib to find a way to get the text under the > user cursor. > so far I managed to find only the controller ID which under the cursor > this way > > cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) > > their is function called GetWindowText I tried to use but it doesn't > work in most of the time > > someone know a way to do this? > > thank you! One app that might be of help with your endeavors is called AutoIt (http://www.autoitscript.com/autoit3/) This suite of apps has a nice window browser, which shows most (if mot all) information available from a Windows window. Sometimes not all text in a window is available, depending on the window. It even comes with a COM component, so it can be scripted from Python... No affiliation, other than a contented user. Duane From pruebauno at latinmail.com Fri Jan 9 09:27:54 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 9 Jan 2009 06:27:54 -0800 (PST) Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> <01771aa0$0$8693$c3e8da3@news.astraweb.com> <3d7f8241-50ae-48e1-a541-f562f056aa8d@r37g2000prr.googlegroups.com> Message-ID: <1dd44189-f6dd-48b9-bcf5-b77236bc6a8f@a26g2000prf.googlegroups.com> On Jan 9, 8:02?am, koranth... at gmail.com wrote: > Also, what I am asking is a generic option in logging - which can help > the adoption of the logging framework in even closed source systems. > It is not just about security - just that a closed source company > might be much more comfortable in using the system if crypt is there. Python is an open source project. Many people that read this list don't like closed source code too much and are not willing to invest time to work in features like this. You might get lucky and somebody that is interested in the topic might give you some tips. From slbentley at gmail.com Fri Jan 9 09:36:46 2009 From: slbentley at gmail.com (Scooter) Date: Fri, 9 Jan 2009 06:36:46 -0800 (PST) Subject: Python Apache Handler Message-ID: Does anyone have any good examples, or links thereto for using python as an Apache handler? And I should qualify all of this by saying I'm a python newbie, and while having experience with Apache, I've never done anything outside whats "in the box" . What I'm looking for is how one might use Python not from the CGI/ presentation side but more on the backend...i.e. for each page Apache serves up examine the request and update some headers, or add a cookie to the response. Or possibly use Python for writing a custom Apache logger. I've searched the web but typically end up with pages for mod_python and writing CGI scripts. And if you feel this is better posted in an Apache group vs. here, let me apologize up front. Thanks From goldnery at gmail.com Fri Jan 9 09:39:15 2009 From: goldnery at gmail.com (Gandalf) Date: Fri, 9 Jan 2009 06:39:15 -0800 (PST) Subject: win32gui References: Message-ID: <54ca66c2-fceb-4402-9086-5ae622c420e6@x16g2000prn.googlegroups.com> thank you I'm checking autoit documentation... From ricaraoz at gmail.com Fri Jan 9 09:45:14 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 09 Jan 2009 12:45:14 -0200 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: <496762FA.6040203@gmail.com> James Stroud wrote: > Tim Arnold wrote: >> Hi, I don't even know what to google for on this one. I need to drive >> a commercial desktop app (on windows xp) since the app doesn't have a >> batch interface. It's intended to analyze one file at a time and >> display a report. >> >> I can get the thing to write out the report an html browser, but I >> have thousands of files I need it to analyze every night. >> >> Is there any lib or recipe(s) for doing something like this via python? > > You are a little thin on details here. My only advice at this point is > to check out os.system, which is the simplest option. From there you > can move to the popen2 module for greater control, but if you are > talking about a gui app, you may run into hang-ups. > > A quick recipe would be the following pretend application that > recursively descends from the current directory calling the utility > named "dosapp" on every file it finds that ends with "jpg" (what > "dosapp" does is left to your imagination): > > > > import os > > def doit(suffix, adir, filenames): > for afile in filenames: > if afile.endswith(suffix): > pathname = os.path.join(adir, afile) > os.system('dosapp %s' % pathname) > > > top = '.' > suffix = '.jpg' > > os.path.walk(top, doit, suffix) > > > Read the docs on os.path.walk, of course. > > James > > >From a search in my mail's lists : http://www.openqa.org/pywinauto/ or http://pywinauto.openqa.org/ http://wwwsearch.sourceforge.net/mechanize/ http://www.autoitscript.com/autoit3/ (see the COM server) http://people.redhat.com/zcerza/dogtail/ HTH From philip at semanchuk.com Fri Jan 9 09:46:51 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 9 Jan 2009 09:46:51 -0500 Subject: Python Imaging Library and textmate In-Reply-To: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> References: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> Message-ID: On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: > Hello, > I am a beginner in python and I am trying to create image files that > contain > lines from a text file. > I am trying to do this with PIL, which seems like a suitable tool. I > have a > copy of TextMate(1.5.8) and I run Macosx 10.5.6 > > The problem is, even though I installed PIL correctly (I get no > errors from > "import Image" in IDLE or in terminal), I can't get TextMate to > import the > module. > I keep getting "ImportError: No module named Image" error. > I tried reloading TextMate's bundles but that did not work either. I use TextMate but I don't know what you mean when you say you can't get TM to import a module. Can you give a little more context? > There was a similar thread in this list with textmate but I can't > understand > how that issue was solved in the end. link? bye Philip From ryandw at gmail.com Fri Jan 9 09:59:36 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 06:59:36 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 3:16?am, Steven D'Aprano wrote: > The full signature of ZipFile is: > > ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) > > Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and > see if that makes any difference. Those arguments didn't make a difference in my case. > The zip format does support alternative compression methods, it's > possible that this particular file uses a different sort of compression > which Python doesn't deal with. > > > What would cause a zip file to not have a table of contents? > > What makes you think it doesn't have one? Because when I search for the "file is not a zip file" error in zipfile.py, there is a function that checks for a table of contents. Tho it looks like there are other ideas in this thread about what might cause that error... I'll keep reading... From ryandw at gmail.com Fri Jan 9 10:05:25 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:05:25 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 3:46?am, Carl Banks wrote: > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. ?If the end of > file hasn't yet been reached there could be more data. ?To make > matters worse, somehow zip files came to have text comments simply > appended to the end of them. ?(Probably this was for the benefit of > people who would cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile > format, you don't have any foolproof way to know if it's because the > file is corrupted or if it's just an appended comment. > > Most zipfile readers use a heuristic to distinguish. ?Python's zipfile > module just assumes it's corrupted. > > The following post from a while back gives a solution that tries to > snip the comment off so that zipfile module can handle it. ?It might > help you out. > > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > > Carl Banks Thanks Carl. I tried Scott's getzip() function yesterday... I stumbled upon it in my searches. It didn't seem to help in my case, though it did produce a different error: ValueError, substring not found. Not sure what that means. From againstmethod at gmail.com Fri Jan 9 10:11:59 2009 From: againstmethod at gmail.com (Rich Henry) Date: Fri, 9 Jan 2009 10:11:59 -0500 Subject: struct unpack to pre-allocated array? Message-ID: <329fe1530901090711w7bafbc1cyb2a014bbe5d9524e@mail.gmail.com> Is there any way to struct.unpack or struct.unpack_from into an existing array.array or similar structure? I am unpacking file data in a loop and i was hoping to find something that performs better than simply unpacking into a new tuple each iteration. Thanks in advance, Rich -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Fri Jan 9 10:12:32 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 08:12:32 -0700 Subject: why cannot assign to function call In-Reply-To: <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Message-ID: <49676960.3050802@strout.net> rurpy at yahoo.com wrote: >>> a = array (1,2,3) >>> b = a >>> a[1] = 4 >>> print b >>> >>> C, C++, VBA, Fortran, Perl: 1, 2, 3 >>> Python: 1, 4, 3 >> You are mistaken > > I don't think so. > See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 > The code I quoted there was tested. > In the C/C++ case, array-to-pointer coercion confuses > the issue so I embedded the array in a struct which > is more like an "object". No, that's cheating (IMHO). Structs used directly (rather than via pointers) are the odd beast, and while they're certainly possible in C, they are far from the normal idiom. And certainly embedding an array in a struct just to force it to be copied, avoiding the standard reference semantics, is an arbitrary trick. I never claimed that you *couldn't* have copy semantics in C; you can do almost anything you want in C (or C++). But the *normal* usage of an array is via a pointer, in which case the semantics are exactly the same as in Python, Java, REALbasic, .NET, etc. >(Keep in mind > my point was not to show the behavior of arrays, but to > show that several common languages *do not* use Python's > "*all* names are references" model -- though of course > this does not preclude their having some Python-like > assignments since they all have some way of doing > references.) Ah. OK then, I guess I missed you're point. You're absolutely right; many languages have both reference types and value types. Python is a bit unusual in that it has only reference types. I would have picked a different example to illustrate that, but it's true nonetheless. Best, - Joe From arkanes at gmail.com Fri Jan 9 10:14:35 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 09:14:35 -0600 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4866bea60901090714x296e38dwefa540beb28419a3@mail.gmail.com> On Fri, Jan 9, 2009 at 9:05 AM, webcomm wrote: > On Jan 9, 3:46 am, Carl Banks wrote: >> The zipfile format is kind of brain dead, you can't tell where the end >> of the file is supposed to be by looking at the header. If the end of >> file hasn't yet been reached there could be more data. To make >> matters worse, somehow zip files came to have text comments simply >> appended to the end of them. (Probably this was for the benefit of >> people who would cat them to the terminal.) >> >> Anyway, if you see something that doesn't adhere to the zipfile >> format, you don't have any foolproof way to know if it's because the >> file is corrupted or if it's just an appended comment. >> >> Most zipfile readers use a heuristic to distinguish. Python's zipfile >> module just assumes it's corrupted. >> >> The following post from a while back gives a solution that tries to >> snip the comment off so that zipfile module can handle it. It might >> help you out. >> >> http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 >> >> Carl Banks > > Thanks Carl. I tried Scott's getzip() function yesterday... I > stumbled upon it in my searches. It didn't seem to help in my case, > though it did produce a different error: ValueError, substring not > found. Not sure what that means. > -- > http://mail.python.org/mailman/listinfo/python-list > This is a ticket about another issue or 2 with invalid zipfiles that the zipfile module won't load, but that other tools will compensate for: http://bugs.python.org/issue1757072 From pruebauno at latinmail.com Fri Jan 9 10:14:48 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 9 Jan 2009 07:14:48 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Jan 9, 8:48?am, Johannes Bauer wrote: > No - and I've not known there was a profiler yet have found anything > meaningful (there seems to be an profiling C interface, but that won't > get me anywhere). Is that a seperate tool or something? Could you > provide a link? > Thanks, > Kind regards, > Johannes It is part of the python standard library: http://docs.python.org/library/profile.html From jldunn2000 at googlemail.com Fri Jan 9 10:20:50 2009 From: jldunn2000 at googlemail.com (loial) Date: Fri, 9 Jan 2009 07:20:50 -0800 (PST) Subject: sftp with no password from python References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> Message-ID: <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> On 8 Jan, 18:49, Mike Hjorleifsson wrote: > On Jan 8, 10:39?am, loial wrote: > > > Is it possible to usesftpwithout a password from python? > > Yes you can use keys you preestablish between the server and client so > you dont need passwords, i do this on all my servers then lock off the > ability to accept passwords at all, this way no one can dictionary > attack my ssh servers. Thanks...do you have any python examples of using sftp? From ryandw at gmail.com Fri Jan 9 10:22:16 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:22:16 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> On Jan 9, 5:42?am, John Machin wrote: > And here's a little gadget that might help the diagnostic effort; it > shows the archive size and the position of all the "magic" PKnn > markers. In a "normal" uncommented archive, EndArchive_pos + 22 == > archive_size. I ran the diagnostic gadget... archive size is 69888 FileHeader at 0 CentralDir at 43796 EndArchive at 43846 From ryandw at gmail.com Fri Jan 9 10:29:05 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:29:05 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 10:14?am, "Chris Mellon" wrote: > This is a ticket about another issue or 2 with invalid zipfiles that > the zipfile module won't load, but that other tools will compensate > for: > > http://bugs.python.org/issue1757072 Hmm. That's interesting. Are there other tools I can use in a python script that are more forgiving? I am using the zipfile module only because it seems to be the most widely used. Are other options in python likely to be just as unforgiving? Guess I'll look and see... From joe at strout.net Fri Jan 9 10:30:46 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 08:30:46 -0700 Subject: why cannot assign to function call In-Reply-To: <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <49676DA6.3030600@strout.net> Aaron Brady wrote: > Possible compromise. You can think of functions as mutation-only. > You pass the object, and it gets a new (additional) name. The old > name doesn't go in. That's correct. The reference itself is passed in, not the variable (or expression) that held or generated the reference in the calling code. This is no different from, in C, passing an integer: void foo(int bar) { bar = 42; } int baz = 0; foo(baz); This doesn't change baz because, speaking precisely, baz wasn't passed to foo -- only the *value* of baz (i.e. 0) was passed to foo. Within foo, that value was stored in bar. Assigning a new value to bar does not affect foo. It's the exact same thing when the value happens to be a reference to an object: typedef SomeClass* SomeClassPtr; void foo(SomeClassPtr bar) { bar = new SomeClass(); } SomeClassPtr baz = NULL; foo(baz); Again, we're not passing baz into foo; we're passing the *value* of baz (i.e. NULL) into foo. That value is stored in bar within foo, and when we assign a new value (a reference to a freshly minted SomeClass object) into bar, of course it doesn't affect baz. > Regardless, IMO, references don't add any explanatory power; they just > make you feel cocky that you know what they are. Nonsense. They are the simple and clear explanation of what's going on. > M: If 'fun()' returned a reference, you would be able to assign to it. > m: You can't assign to it. > C: It doesn't return a reference. C is false because M is false (at least, in the way I believe you mean it). Or, more precisely, both M and m are nonsensical; what does it mean to "assign to a reference"? It makes no sense. What would it mean to assign to 42? You don't assign to references any more than you assign to integers or assign to strings or assign to None. Those are all values, and you don't assign to values -- you assign to variables. "Assign" means to give a new value to a variable, i.e. to let (or cause) a variable to have a new value. (Ye olde BASIC even used the LET keyword to indicate this, e.g. LET X = 42.) Speaking casually, we don't always make this distinction, but I think precision is needed here. So, I see two ways to make sense of your argument: M1: If 'fun()' returned a variable, you would be able to assign to it. m1: You can't assign to it. C1: It doesn't return a variable. This is true. (Technically, instead of variable, we should say "LValue" here -- there are things slightly more complex than simple variables that can serve as the left-hand side of an assignment. So replace "variable" with "lvalue" above if you prefer.) Or, the other way some may see it is: M2: If 'fun()' returned a reference, you might be able to mutate the object that refers to. m2: You can sometimes mutate the object it refers to. C2: 'fun()' returns a reference. This is true (though the logic is flawed, but fixable). > -- Why can't I assign to a function call? > -- Python variables are references only. > -- Ok, why can't I assign to a function call? You're right, "Python variables are references only" has nothing to do with it. In a language where the only data type were "integer", you wouldn't be able to assign to a function call either. You can't assign to a function call because a function call is not itself an lvalue, and it doesn't return an lvalue. That's just not something you can get for free from the type model; it's an extra feature that would have to be built into the language somehow, and Python doesn't have it. If assignment were an operator rather than a statement, and could be overridden in a class via some specially-named method -- or, for that matter, if the assignment statement looked for such a method when it finds an object reference on the left-hand side -- then any object could be an lvalue, and you COULD (in some cases) assign to the result of a function. But it's not and it doesn't. Best, - Joe From nick at craig-wood.com Fri Jan 9 10:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 09 Jan 2009 09:31:16 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> <6smrejF74ss9U1@mid.individual.net> Message-ID: Thomas Heller wrote: > Nick Craig-Wood schrieb: > > Thomas Heller wrote: > >> Nick Craig-Wood schrieb: > >> > Interesting - I didn't know about h2xml and xml2py before and I've > >> > done lots of ctypes wrapping! Something to help with the initial > >> > drudge work of converting the structures would be very helpful. > >> > > >> > ( http://pypi.python.org/pypi/ctypeslib/ ) > >> > > >> > I gave it a quick go and it worked fine. I had to edit the XML in one > >> > place to make it acceptable (removing a u from a hex number). > >> > >> If you are using a recent version of gccxml, then you should use the > >> ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should > >> really merge the gccxml-0.9 branch into the trunk;-) > >> > >> If you are already using the branch and the XML file is not accepted, > >> then could you please provide a short C code snippet that reproduces > >> the problem so that I can fix it? > > > > I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess > > doesn't have the code from the branch in. > > I meant the branch in the repository where ctypeslib lives in. > Anyway, it doesn't matter anymore since I merged that branch > into the ctypeslib trunk. > > Now the problem with the 'u' suffix that you mentioned should be fixed, and > I also made a quick change so that the sized integer types from stdint.h are generated > correctly. So, please update your ctypeslib installation and trey again;-) I gave it a go and I can report success on both counts! Well done and thank you. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From rurpy at yahoo.com Fri Jan 9 10:33:27 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 07:33:27 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <5f85a3a8-e718-475d-9bb1-238bb61b5018@x16g2000prn.googlegroups.com> On Jan 9, 6:48 am, Johannes Bauer wrote: > mk schrieb: > > The factor of 30 indeed does not seem right -- I have done somewhat > > similar stuff (calculating Levenshtein distance [edit distance] on words > > read from very large files), coded the same algorithm in pure Python and > > C++ (using linked lists in C++) and Python version was 2.5 times slower. > > Yup, that was about what I had expected (and what I could well live > with, it's a tradeoff). The rule-of-thumb I use is that Python is generally 5 to 50 times slower than C. It is considered blasphemy to say it in this group, but Python is slow. It does of course have many compensating advantages that make using it advantageous when runtime speed is not of primary importance. From google at mrabarnett.plus.com Fri Jan 9 10:34:17 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 15:34:17 +0000 Subject: Implementing file reading in C/Python In-Reply-To: <6sone1F7bavsU5@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: <49676E79.1000709@mrabarnett.plus.com> Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > >> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >> thing in C also: > > Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: > > #!/usr/bin/env python > from __future__ import division, with_statement > import os > import sys > from collections import defaultdict > from functools import partial > from itertools import imap > > > def iter_max_values(blocks, block_count): > for i, block in enumerate(blocks): > histogram = defaultdict(int) > for byte in block: > histogram[byte] += 1 > > yield max((count, byte) > for value, count in histogram.iteritems())[1] > [snip] Would it be faster if histogram was a list initialised to [0] * 256? From googler.1.webmaster at spamgourmet.com Fri Jan 9 10:49:21 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 07:49:21 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: Hi! I didn't wanted to post 11.000 Lines here, so I uploaded it here: http://rapidshare.com/files/181425216/config.log.html From jcd at sdf.lonestar.org Fri Jan 9 10:50:15 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 09 Jan 2009 10:50:15 -0500 Subject: Creating new instances of subclasses. In-Reply-To: References: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> Message-ID: <1231516215.31282.29.camel@aalcdl07.lib.unc.edu> Thanks for the solutions everyone! I'm not sure which I'll end up using, but I think I've got a better grasp of the problem now. Cool stuff. Cheers, Cliff On Thu, 2009-01-08 at 06:52 -0800, Paul McGuire wrote: > On Jan 7, 12:00 pm, Paul McGuire wrote: > > On Jan 7, 10:38 am, "J. Cliff Dyer" wrote: > > > > > I want to be able to create an object of a certain subclass, depending > > > on the argument given to the class constructor. > > > > > I have three fields, and one might need to be a StringField, one an > > > IntegerField, and the last a ListField. But I'd like my class to > > > delegate to the proper subclass automatically, so I can just do: > > > > > >>> f1 = Field('abc') > > > >>> f2 = Field('123') > > > >>> f3 = Field('D,E,F') > > > > O-O is not always the solution to every problem. Since inheritance is > > getting in your way, try using a class-level factory method. Instead > > of using the Field constructor, use a staticmethod of Field, something > > like: > > > > @staticmethod > > def make_Field(a) > > if is_list(a): > > return ListField(a) > > elif is_integer(a): > > return IntegerField(a) > > else: > > return StringField(a) > > > > and then get rid of all those __new__ methods, too. > > > > -- Paul > > After looking this over a bit more, I decided I didn't like make_Field > having to know the criteria for creating the different subclasses, but > wanted to put the smarts into the subclasses themselves. Here is an > excerpt that shows this working: > > class Field(object): > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > @staticmethod > def make_Field(a): > subs = (ListField, IntegerField, StringField) > ret = None > for cls in subs: > try: > ret = cls(a) > except TypeError: > continue > else: > break > return ret > > class IntegerField(Field): > def __new__(cls, a): > if not is_integer(a): > raise TypeError() > return Field.__new__(cls, a) > > ... > ListField has a similar __new__ method, and StringField just creates > the object, with no validation. > > make_Field still has to know what order to list the subclasses in > (StringField is the most permissive, and so must come last in the list > of subclasses), but the specific type tests are moved into the > subclasses, which is a more appropriate place I think. > > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From chardish at gmail.com Fri Jan 9 11:14:16 2009 From: chardish at gmail.com (Evan Jones) Date: Fri, 9 Jan 2009 11:14:16 -0500 Subject: Guaranteeing an n-byte data type? Message-ID: Hello all, I'm trying to use sockets to implement a pre-defined network protocol that requires that I send messages of exactly a certain number of bytes. In Python, integer values are represented as 4 bytes each (AFAIK.) However I don't want to always send 4 bytes: sometimes I want to send one byte, or 11 bytes, or 33 bytes, or any other permutation that's not a multiple of 4. It seems to make the most sense to use one-byte data members and concatenate them before sending. This is reasonably easy in C (thanks to the uint8_t data type), but with Python I'm not sure how I'd implement it. The send() method in the socket module will take any kind of data, but you can't specify the number of bytes you want to send, so there's no guarantee as to how many you're actually sending (particularly if you're sending a value that's regarded in Python as a long integer - who knows how that data is actually represented in memory behind the scenes!) Perhaps since I'm trying to perform low-level operations, Python is simply the wrong tool for this job. However, I'd very much like to write this implementation in Python for sake of quick implementation and testing. Cheers, Evan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 9 11:42:16 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 11:42:16 -0500 Subject: why cannot assign to function call In-Reply-To: <49676DA6.3030600@strout.net> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <49676DA6.3030600@strout.net> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> Possible compromise. You can think of functions as mutation-only. >> You pass the object, and it gets a new (additional) name. The old >> name doesn't go in. > > That's correct. The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. > > This is no different from, in C, passing an integer: > > void foo(int bar) { > bar = 42; > } > int baz = 0; > foo(baz); > > This doesn't change baz because, speaking precisely, baz wasn't passed > to foo -- only the *value* of baz (i.e. 0) was passed to foo. Within > foo, that value was stored in bar. Assigning a new value to bar does > not affect foo. > > It's the exact same thing when the value happens to be a reference to an > object: > > typedef SomeClass* SomeClassPtr; > void foo(SomeClassPtr bar) { > bar = new SomeClass(); > } > SomeClassPtr baz = NULL; > foo(baz); > > Again, we're not passing baz into foo; we're passing the *value* of baz > (i.e. NULL) into foo. That value is stored in bar within foo, and when > we assign a new value (a reference to a freshly minted SomeClass object) > into bar, of course it doesn't affect baz. > >> Regardless, IMO, references don't add any explanatory power; they just >> make you feel cocky that you know what they are. > > Nonsense. They are the simple and clear explanation of what's going on. > >> M: If 'fun()' returned a reference, you would be able to assign to it. >> m: You can't assign to it. >> C: It doesn't return a reference. > > C is false because M is false (at least, in the way I believe you mean > it). Or, more precisely, both M and m are nonsensical; what does it > mean to "assign to a reference"? It makes no sense. What would it mean > to assign to 42? > > You don't assign to references any more than you assign to integers or > assign to strings or assign to None. Those are all values, and you > don't assign to values -- you assign to variables. "Assign" means to > give a new value to a variable, i.e. to let (or cause) a variable to > have a new value. (Ye olde BASIC even used the LET keyword to indicate > this, e.g. LET X = 42.) Speaking casually, we don't always make this > distinction, but I think precision is needed here. > > So, I see two ways to make sense of your argument: > > M1: If 'fun()' returned a variable, you would be able to assign to it. > m1: You can't assign to it. > C1: It doesn't return a variable. > > This is true. (Technically, instead of variable, we should say "LValue" > here -- there are things slightly more complex than simple variables > that can serve as the left-hand side of an assignment. So replace > "variable" with "lvalue" above if you prefer.) > > Or, the other way some may see it is: > > M2: If 'fun()' returned a reference, you might be able to mutate the > object that refers to. > m2: You can sometimes mutate the object it refers to. > C2: 'fun()' returns a reference. > > This is true (though the logic is flawed, but fixable). > >> -- Why can't I assign to a function call? >> -- Python variables are references only. >> -- Ok, why can't I assign to a function call? > > You're right, "Python variables are references only" has nothing to do > with it. In a language where the only data type were "integer", you > wouldn't be able to assign to a function call either. > > You can't assign to a function call because a function call is not > itself an lvalue, and it doesn't return an lvalue. That's just not > something you can get for free from the type model; it's an extra > feature that would have to be built into the language somehow, and > Python doesn't have it. > > If assignment were an operator rather than a statement, and could be > overridden in a class via some specially-named method -- or, for that > matter, if the assignment statement looked for such a method when it > finds an object reference on the left-hand side -- then any object could > be an lvalue, and you COULD (in some cases) assign to the result of a > function. But it's not and it doesn't. > Pretty soon you guys will have me believing Python doesn't work ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 11:43:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 16:43:39 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <01777574$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 08:30:46 -0700, Joe Strout wrote: > That's correct. The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. > > This is no different from, in C, passing an integer: > > void foo(int bar) { > bar = 42; > } > int baz = 0; > foo(baz); > > This doesn't change baz because, speaking precisely, baz wasn't passed > to foo -- only the *value* of baz (i.e. 0) was passed to foo. We can check whether bar and baz are the same thing, by printing their addresses: #include void foo(int bar) { printf("\n The address of bar is %p ", &bar); bar = 42; } int main() { int baz = 0; printf("\n The address of baz is %p ", &baz); foo(baz); return 0; } When I do this, I get: The address of baz is 0xbfa72870 The address of bar is 0xbfa72850 So we can agree that baz and bar are different entities. Now, would anyone like to take a small wager on what the equivalent code in CPython would print? def foo(bar): print " The address of bar is %s " % id(bar) bar = 42 baz = 0 print " The address of baz is %s " % id(baz) foo(baz) When I execute this, I get The address of baz is 143599468 The address of bar is 143599468 Python doesn't do the same thing as C. It actually passes the same value to the function, without copying it. Why oh why do you keep insisting that Python is no different from C? Let's try one more. In C: #include #include struct record { int x; }; void mutate(struct record bar) { printf("\n The address of bar is %p ", &bar); bar.x = 0; printf("\n Inside: %d ", bar.x); } struct record baz; int main(void) { baz.x = 1; printf("\n The address of baz is %p ", &baz); printf("\n Before: %d ", baz.x); mutate(baz); printf("\n After: %d ", baz.x); return 0; } gives output: The address of baz is 0x80496fc Before: 1 The address of bar is 0xbfb8f980 Inside: 0 After: 1 We can clearly see that baz and bar are different entities, and changes made to bar inside the function don't affect baz. A Python equivalent: class struct: pass def mutate(bar): print " The address of bar is %d " % id(bar) bar.x = 0; print " Inside: %d " % bar.x baz = struct() baz.x = 1 print " The address of baz is %d " % id(baz) print " Before: %d " % baz.x mutate(baz) print " After: %d " % baz.x which gives output: The address of baz is 3085537420 Before: 1 The address of bar is 3085537420 Inside: 0 After: 0 Why oh why do you keep insisting that Python is no different from C? -- Steven From google at mrabarnett.plus.com Fri Jan 9 11:45:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 16:45:04 +0000 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: <49677F10.3070907@mrabarnett.plus.com> Evan Jones wrote: > Hello all, > > I'm trying to use sockets to implement a pre-defined network protocol > that requires that I send messages of exactly a certain number of bytes. > In Python, integer values are represented as 4 bytes each (AFAIK.) > However I don't want to always send 4 bytes: sometimes I want to send > one byte, or 11 bytes, or 33 bytes, or any other permutation that's not > a multiple of 4. It seems to make the most sense to use one-byte data > members and concatenate them before sending. > > This is reasonably easy in C (thanks to the uint8_t data type), but with > Python I'm not sure how I'd implement it. The send() method in the > socket module will take any kind of data, but you can't specify the > number of bytes you want to send, so there's no guarantee as to how many > you're actually sending (particularly if you're sending a value that's > regarded in Python as a long integer - who knows how that data is > actually represented in memory behind the scenes!) > > Perhaps since I'm trying to perform low-level operations, Python is > simply the wrong tool for this job. However, I'd very much like to write > this implementation in Python for sake of quick implementation and testing. > The send() method takes a bytestring argument (class "str" in Python 2.x, class "bytes" in Python 3.x), which is a string of 8-bit characters (1 byte per character). Just build your bytestring and then send it (actually it's better to use sendall() because send() isn't guaranteed to send all the bytes in one call). From steve at holdenweb.com Fri Jan 9 11:46:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 11:46:52 -0500 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: Evan Jones wrote: > Hello all, > > I'm trying to use sockets to implement a pre-defined network protocol > that requires that I send messages of exactly a certain number of bytes. > In Python, integer values are represented as 4 bytes each (AFAIK.) > However I don't want to always send 4 bytes: sometimes I want to send > one byte, or 11 bytes, or 33 bytes, or any other permutation that's not > a multiple of 4. It seems to make the most sense to use one-byte data > members and concatenate them before sending. > > This is reasonably easy in C (thanks to the uint8_t data type), but with > Python I'm not sure how I'd implement it. The send() method in the > socket module will take any kind of data, but you can't specify the > number of bytes you want to send, so there's no guarantee as to how many > you're actually sending (particularly if you're sending a value that's > regarded in Python as a long integer - who knows how that data is > actually represented in memory behind the scenes!) > > Perhaps since I'm trying to perform low-level operations, Python is > simply the wrong tool for this job. However, I'd very much like to write > this implementation in Python for sake of quick implementation and testing. > In Python 2 you'd use an 8-bit string - though as you surmise you need access to the conversions to and from the primitive data types. This is provided by the struct module. In Python 3 you'll use a bytes object; in 2.6 and onwards the bytes syntax can be used to refer to regular strings, to make portability easier (in Python 3, strings are Unicode by default). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From invalid at invalid Fri Jan 9 11:56:44 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 10:56:44 -0600 Subject: Guaranteeing an n-byte data type? References: Message-ID: Evan Jones wrote: > I'm trying to use sockets to implement a pre-defined network > protocol that requires that I send messages of exactly a > certain number of bytes. In Python, integer values are > represented as 4 bytes each (AFAIK.) However I don't want to > always send 4 bytes: sometimes I want to send one byte, or 11 > bytes, or 33 bytes, or any other permutation that's not a > multiple of 4. It seems to make the most sense to use one-byte > data members and concatenate them before sending. In addition to previous suggestions, you should look at the "struct" and "ctypes" modules in the standard Python library. Both allow you to pack/unpack data to/from data structures with arbitrary layout and endianness. -- Grant Edwards grante Yow! I'm meditating on at the FORMALDEHYDE and the visi.com ASBESTOS leaking into my PERSONAL SPACE!! From ryandw at gmail.com Fri Jan 9 11:58:14 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 08:58:14 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 10:14?am, "Chris Mellon" wrote: > This is a ticket about another issue or 2 with invalid zipfiles that > the zipfile module won't load, but that other tools will compensate > for: > > http://bugs.python.org/issue1757072 Looks like I just need to do this to unzip with unix... from os import popen popen("unzip data.zip") That works for me. No idea why I didn't think of that earlier. I'm new to python but should have realized I could run unix commands with python. I had blinders on. Now I just need to get rid of some bad characters in the unzipped file. I'll start a new thread if I need help with that... From invalid at invalid Fri Jan 9 11:59:41 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 10:59:41 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On 2009-01-09, Johannes Bauer wrote: > I've come from C/C++ and am now trying to code some Python because I > absolutely love the language. However I still have trouble getting > Python code to run efficiently. Right now I have a easy task: Get a > file, If I were you, I'd try mmap()ing the file instead of reading it into string objects one chunk at a time. -- Grant Edwards grante Yow! I'm DESPONDENT ... I at hope there's something visi.com DEEP-FRIED under this miniature DOMED STADIUM ... From wesbrooks at gmail.com Fri Jan 9 12:06:28 2009 From: wesbrooks at gmail.com (Wesley Brooks) Date: Fri, 9 Jan 2009 17:06:28 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: I missed the begining of this thread and so appologise if I'm repeating what someone else has said! I had a very similar problem with this error and it turned out it was due to me moving a file across a socket connection and either not reading it or writing it in the binary mode, ie open(filename, 'rb') or write(filename, 'wb'). This didn't make any difference on the linux machines (where the error didn't occur) but did on the windows machines and fixed the problem. Cheers, Wes On 09/01/2009, webcomm wrote: > > On Jan 9, 10:14 am, "Chris Mellon" wrote: > > This is a ticket about another issue or 2 with invalid zipfiles that > > the zipfile module won't load, but that other tools will compensate > > for: > > > > http://bugs.python.org/issue1757072 > > Looks like I just need to do this to unzip with unix... > > from os import popen > popen("unzip data.zip") > > That works for me. No idea why I didn't think of that earlier. I'm > new to python but should have realized I could run unix commands with > python. I had blinders on. Now I just need to get rid of some bad > characters in the unzipped file. I'll start a new thread if I need > help with that... > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Fri Jan 9 12:13:03 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 9 Jan 2009 09:13:03 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Johannes Bauer, I was about to start writing a faster version. I think with some care and Psyco you can go about as 5 times slower than C or something like that. To do that you need to use almost the same code for the C version, with a list of 256 ints for the frequencies, not using max() but a manual loop, not using itertools or generators, maybe splitting code in two functions to allow Psyco to optimize better, maybe using another array("...") for the frequences too. The data can be read into an array.array("B"), and so on. But I think all this work is a waste of time. I like Python, but that C code, after some cleaning and polishing looks fine for this job. Of course there are other languages that may give you a little nicer code for this program, like D, and there may be ways to use numpy too to speed up the computation of the mode, but they don't look so much important this time. Bye, bearophile From p at ulmcnett.com Fri Jan 9 12:16:35 2009 From: p at ulmcnett.com (Paul McNett) Date: Fri, 09 Jan 2009 09:16:35 -0800 Subject: Unexpected scientific notation In-Reply-To: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> Message-ID: <49678673.5000003@ulmcnett.com> Mark Dickinson wrote: > On Jan 8, 1:00 am, Paul McNett wrote: >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what could be causing >> this. What would be choosing to display such a normal number in scientific notation? >> >> Ideas? > > [I thought I replied to this earlier, but the post isn't showing up. > So here it is again.] LOL! > I suspect it's your use of the Decimal normalize() method that's > causing > this. Trailing zeros on Decimal instances are significant, so > Decimal('30.0'), Decimal('30') and Decimal('3E+1') are considered > distinct (though they all have the same value). The normalize method > strips all trailing zeros, turning Decimal('30.0') into Decimal('3E > +1'). > > One way to get around this is to add 0 after normalizing: this will > make sure that scientific notation is used only for very large > or small numbers, as usual. Thank you for the insight. I believe the problem is with my use of normalize(), but I still can't figure out why I can't reproduce the issue in my running app. But I can see in the interpreter that printing Decimal("30.0").normalize() results in "3E+1". Paul From concat_names at hotmail.com Fri Jan 9 12:17:08 2009 From: concat_names at hotmail.com (Aivar Annamaa) Date: Fri, 09 Jan 2009 19:17:08 +0200 Subject: Problem with -3 switch Message-ID: Hi I'm getting started with Python and in order to get good habits for Python 3, i'd like to run my Python 2.6.1 with Python 3 warning mode. When i run python -3 and execute statement >>> print 4 then i expect to see a warning because i've understood that this statement is not valid in Python 3 however no warning appears. Have is misunderstood something? I'm running Python on Windows Vista. thanks in advance! Aivar From a.bilgin.a at gmail.com Fri Jan 9 12:19:43 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Fri, 9 Jan 2009 19:19:43 +0200 Subject: Python Imaging Library and textmate Message-ID: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> Hi Philip, I tried to install PIL with the directions given and it seemed to be ok. When I tried it with IDLE, import Image did not give an error and as far as I checked it seemed to be working. However, importing Image module in TextMate gives an error, saying that the module cannot be found for some strange reason. The code simply contains the line *"import Image"* in both cases On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: >* Hello, *>* I am a beginner in python and I am trying to create image files that *>* contain *>* lines from a text file. *>* I am trying to do this with PIL, which seems like a suitable tool. I *>* have a *>* copy of TextMate(1.5.8) and I run Macosx 10.5.6 *>* *>* The problem is, even though I installed PIL correctly (I get no *>* errors from *>* "import Image" in IDLE or in terminal), I can't get TextMate to *>* import the *>* module. *>* I keep getting "ImportError: No module named Image" error. *>* I tried reloading TextMate's bundles but that did not work either. * I use TextMate but I don't know what you mean when you say you can't get TM to import a module. Can you give a little more context? >* There was a similar thread in this list with textmate but I can't *>* understand *>* how that issue was solved in the end. * link? bye Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 9 12:26:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 09:26:27 -0800 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: <50697b2c0901090926r10e1008ct35c80ea6ab0ef0c6@mail.gmail.com> On Fri, Jan 9, 2009 at 9:17 AM, Aivar Annamaa wrote: > Hi > > I'm getting started with Python and in order to get good habits for Python > 3, i'd like to run my Python 2.6.1 with Python 3 warning mode. > > When i run > python -3 > > and execute statement >>>> print 4 > > then i expect to see a warning because i've understood that this statement > is not valid in Python 3 > > however no warning appears. > > Have is misunderstood something? As was recently pointed out in a nearly identical thread, the -3 switch only points out problems that the 2to3 converter tool can't automatically fix. Changing print to print() on the other hand is easily fixed by 2to3. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From dickinsm at gmail.com Fri Jan 9 12:31:42 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 09:31:42 -0800 (PST) Subject: Unexpected scientific notation References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> Message-ID: On Jan 9, 5:16?pm, Paul McNett wrote: > Thank you for the insight. I believe the problem is with my use of normalize(), but I > still can't figure out why I can't reproduce the issue in my running app. Me neither. In particular, I can't see how it could this output could come out of a locale.format call. Is it possible that your user is somehow seeing a direct str() or "%s" of a Decimal instance, rather than something that's been through a format method? Mark From gh at ghaering.de Fri Jan 9 12:32:11 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 09 Jan 2009 18:32:11 +0100 Subject: Python Apache Handler In-Reply-To: References: Message-ID: Scooter wrote: > Does anyone have any good examples, or links thereto for using python > as an Apache handler? And I should qualify all of this by saying I'm a > python newbie, and while having experience with Apache, I've never > done anything outside whats "in the box" . > > What I'm looking for is how one might use Python not from the CGI/ > presentation side but more on the backend...i.e. for each page Apache > serves up examine the request and update some headers, or add a cookie > to the response. I vaguely remembered that mod_python can do such things. Looking again it seems to be the case: http://www.modpython.org/live/current/doc-html/pyapi-filter.html > Or possibly use Python for writing a custom Apache > logger. [...] Maybe http://www.modpython.org/live/current/doc-html/dir-handlers-plh.html The documentation about this is a joke, though. Remember that you can write custom Apache loggers quite easily with "piped logs": http://httpd.apache.org/docs/2.2/logs.html This looks roughly like this: CustomLog "|/path/to/my_script.py" common ## begin my_script.py ## import sys for line in sys.stdin: # do stuff ## end ## -- Gerhard From p at ulmcnett.com Fri Jan 9 12:38:36 2009 From: p at ulmcnett.com (Paul McNett) Date: Fri, 09 Jan 2009 09:38:36 -0800 Subject: Unexpected scientific notation In-Reply-To: <49678673.5000003@ulmcnett.com> References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> <49678673.5000003@ulmcnett.com> Message-ID: <49678B9C.9030009@ulmcnett.com> Paul McNett wrote: > Mark Dickinson wrote: >> On Jan 8, 1:00 am, Paul McNett wrote: >>> It displays '3E+1' instead of '30.0'. >>> >>> As I can't reproduce I'm looking for an idea brainstorm of what could >>> be causing >>> this. What would be choosing to display such a normal number in >>> scientific notation? >>> >>> Ideas? >> >> [I thought I replied to this earlier, but the post isn't showing up. >> So here it is again.] > > LOL! I'll clarify my LOL: Mark initially replied to me directly, to which I responded directly. Because he replied directly, I kept my response offline, too, not knowing if he had a special reason to discuss this offline instead of in public. Then he replied to the list, so I made a different response to the list. Anyway, thanks again Mark for your guidance. Paul From concat_names at hotmail.com Fri Jan 9 12:39:03 2009 From: concat_names at hotmail.com (Aivar Annamaa) Date: Fri, 09 Jan 2009 19:39:03 +0200 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: > As was recently pointed out in a nearly identical thread, the -3 > switch only points out problems that the 2to3 converter tool can't > automatically fix. Changing print to print() on the other hand is > easily fixed by 2to3. > > Cheers, > Chris > I see. So i gotta keep my own discipline with print() then :) thanks! A From siona at chiark.greenend.org.uk Fri Jan 9 12:41:29 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 09 Jan 2009 17:41:29 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Grant Edwards wrote: >On 2009-01-09, Johannes Bauer wrote: >> I've come from C/C++ and am now trying to code some Python because I >> absolutely love the language. However I still have trouble getting >> Python code to run efficiently. Right now I have a easy task: Get a >> file, >If I were you, I'd try mmap()ing the file instead of reading it >into string objects one chunk at a time. You've snipped the bit further on in that sentence where the OP says that the file of interest is 2GB. Do you still want to try mmap'ing it? -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From ryandw at gmail.com Fri Jan 9 12:46:44 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 09:46:44 -0800 (PST) Subject: how to remove 'FFFD' character Message-ID: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> Does anyone know a way to remove the 'FFFD' character with python? You can see the browser output I'm dealing with here: http://webcomm.webfactional.com/htdocs/fffd.JPG I deleted a big chunk out of the middle of that JPG to protect sensitive data. I don't know what the character encoding of this data is and don't know what the 'FFFD' represents. I guess it is something that can't be represented in whatever this particular encoding is, or maybe it is something corrupt that can't be represented in any encoding. I just want to scrub it out. I tried this... clean = txt.encode('ascii','ignore') ...but the 'FFFD' still comes through. Other ideas? Thanks, Ryan From gh at ghaering.de Fri Jan 9 12:48:44 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 09 Jan 2009 18:48:44 +0100 Subject: Encrypted Logging in python In-Reply-To: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > I was wondering if there is a mechanism to encrypt logging > automatically in python. Python's standard library doesn't include any "strong" symmetric ciphers. But if you include for example a cryptographic module for AES, for example, it should be easy (I guess 10 lines of code, yes, the issue always is *which* 10 lines) to write a custom logger that encrypts using a hardcoded key. As others have said, this is not really secure, so you could just as well use something stupid like rot13 or base64 instead. > The issue is as follows: > (a) An application (after py2exe) will go as executable and there > is no need for the user to know that it is written in python. If an > exception occurs and it is logged, then the user can understand it is > written in python. In 99.326 % of all cases, the answer is: so what? > (b) A security threat. If an exception occurs, the code is seen by > the user - and possibly be misused. Simply make the user not see the exception, but use a fallback exception handler that does whatever you want to. Write to a log file. Or write to an encrypted log file if you still think that helps. > Base64 encoding somewhat helps - which is supported by logging > module - but even that is not very secure. If there can be an option - > wherein we send in the password and the logging is encrypted - it > might be better. [...] As I said before, that should be trivial to program if you look up the documentation about the logging module. Just subclass FileHandler. And make sure your class is then used. That's probably the hardest part ;-) That all being said, I have one final advise: Your time is probably much better spent on *real* issues. -- Gerhard From philip at semanchuk.com Fri Jan 9 12:53:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 9 Jan 2009 12:53:35 -0500 Subject: Python Imaging Library and textmate In-Reply-To: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> References: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> Message-ID: <0432ACB4-1255-4046-B816-46F5D124C3C1@semanchuk.com> On Jan 9, 2009, at 12:19 PM, bilgin arslan wrote: > Hi Philip, > I tried to install PIL with the directions given and it seemed to be > ok. > > When I tried it with IDLE, import Image did not give an error and as > far as I checked it seemed to be working. > However, importing Image module in TextMate gives an error, saying > that the module cannot be found for some strange reason. I am still unclear on how you're importing Python modules via TextMate. It's a text editor, so even though I've used it for a couple of years, it's not at all obvious to me how you'd use it to import a Python module. I think I can help you, but to do so I need you to tell me *exactly* what menu items you're clicking on, e.g. "Bundle/Python/ Run Script..." > The code simply contains the line *"import Image"* in both cases From what I can see in the PIL documentation, this wouldn't work. You'd need either this: from PIL import Image or this: import PIL.Image What am I missing? > On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: > >> * Hello, > *>* I am a beginner in python and I am trying to create image files > that > *>* contain > *>* lines from a text file. > *>* I am trying to do this with PIL, which seems like a suitable > tool. I > *>* have a > *>* copy of TextMate(1.5.8) and I run Macosx 10.5.6 > *>* > *>* The problem is, even though I installed PIL correctly (I get no > *>* errors from > *>* "import Image" in IDLE or in terminal), I can't get TextMate to > *>* import the > *>* module. > *>* I keep getting "ImportError: No module named Image" error. > *>* I tried reloading TextMate's bundles but that did not work either. > * > I use TextMate but I don't know what you mean when you say you can't > get TM to import a module. Can you give a little more context? > > >> * There was a similar thread in this list with textmate but I can't > *>* understand > *>* how that issue was solved in the end. > * > link? > > > > bye > Philip > -- > http://mail.python.org/mailman/listinfo/python-list From chardish at gmail.com Fri Jan 9 13:12:18 2009 From: chardish at gmail.com (Evan Jones) Date: Fri, 9 Jan 2009 13:12:18 -0500 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 11:56 AM, Grant Edwards wrote: > In addition to previous suggestions, you should look at the > "struct" and "ctypes" modules in the standard Python library. > Both allow you to pack/unpack data to/from data structures with > arbitrary layout and endianness. > > Thank you, everyone. struct appears to be exactly what I want; combined with MRAB's insight into how socket.send() works, I feel I should be able to code this in at around 25% the length of equivalent C code. Cheers, Evan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 9 13:13:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 13:13:37 -0500 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: Aivar Annamaa wrote: >> As was recently pointed out in a nearly identical thread, the -3 >> switch only points out problems that the 2to3 converter tool can't >> automatically fix. Changing print to print() on the other hand is >> easily fixed by 2to3. >> >> Cheers, >> Chris >> > > I see. > So i gotta keep my own discipline with print() then :) > Only if you don't want to run your 2.x code through 2to3 before you use it as Python 3.x code. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Fri Jan 9 13:32:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 09 Jan 2009 10:32:54 -0800 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: webcomm wrote: > .... I tried Scott's getzip() function yesterday... I > stumbled upon it in my searches. It didn't seem to help in my case, > though it did produce a different error: ValueError, substring not > found. Not sure what that means. and in another message webcomm wrote: > I ran the diagnostic gadget... > > archive size is 69888 > FileHeader at 0 > CentralDir at 43796 > EndArchive at 43846 This is telling you that the archive ends at 43846, but the file is 69888 bytes long (69888 - 43846 = 26042 post-archive bytes). Have you tried calling getzip(filename, ignoreable=30000)? The whole point of the function is to ignore the nasty stuff at the end, but if _I_ had a file with more than 25K of post-archive bytes, I'd certainly try to figure out if the archive was mis-handled somewhere along the way. Byt the way, one reason you cannot find the archive by looking at the start of the file is that the zip file format is meant to allow you to append a zip file to another file (such as an executable) and treat the combination as an archive. --Scott David Daniels Scott.Daniels at Acm.Org From jcd at sdf.lonestar.org Fri Jan 9 13:36:59 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 09 Jan 2009 13:36:59 -0500 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: <1231526219.1464.7.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > Aivar Annamaa wrote: > >> As was recently pointed out in a nearly identical thread, the -3 > >> switch only points out problems that the 2to3 converter tool can't > >> automatically fix. Changing print to print() on the other hand is > >> easily fixed by 2to3. > >> > >> Cheers, > >> Chris > >> > > > > I see. > > So i gotta keep my own discipline with print() then :) > > > Only if you don't want to run your 2.x code through 2to3 before you use > it as Python 3.x code. > > regards > Steve And mind you, if you follow that route, you are programming in a mightily crippled language. It's about as bad as trying to write cross-browser CSS. Don't put yourself through that pain if you don't have to. From vginer at gmail.com Fri Jan 9 13:41:37 2009 From: vginer at gmail.com (Vicent) Date: Fri, 9 Jan 2009 19:41:37 +0100 Subject: Where's Psyco now? Message-ID: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Hello. This is my first message to the list. In this article written in 2002 http://www.ibm.com/developerworks/library/l-psyco.html they talk about Psyco as a module that makes it possible to accelerate Python. Is it still a state-of-the-art module? I found it here also: http://pypi.python.org/pypi/psyco/1.6 Do you think it's useful, or it depends...? -- Vicent Giner-Bosch, Valencia, Spain -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Jan 9 13:43:28 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:43:28 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> Message-ID: On Jan 8, 7:25?am, J Kenneth King wrote: > Jonathan Gardner writes: > > It seems we're defining "DSL" in two different ways. > > You can't write a DSL in Python because you can't change the syntax and > you don't have macros. > > You can write a compiler in Python that will compile your "DSL." > Yes, that's what I'm saying. You can get the same results even thought you can't manipulate the Python language itself as it's compiling Python because you can feed it Python code that you've generated. > As another poster mentioned, eventually PyPy will be done and then > you'll get more of an "in-Python" DSL. Of course, such a language wouldn't be Python anymore because Python doesn't have such features. From jgardner at jonathangardner.net Fri Jan 9 13:45:55 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:45:55 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> Message-ID: On Jan 8, 8:03?am, Kay Schluehr wrote: > On 8 Jan., 16:25, J Kenneth King wrote: > > > As another poster mentioned, eventually PyPy will be done and then > > you'll get more of an "in-Python" DSL. > > May I ask why you consider it as important that the interpreter is > written in Python? I see no connection between PyPy and syntactical > Python extensions and the latter isn't an objective of PyPy. You can > write Python extensions with virtually any Python aware parser. > M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then > there is ANTLR which provides a Python grammar. I also know about two > other Python aware parsers. One of them was written by myself. If you're going to manipulate the Python compiler/interpreter from the Python program itself, it's only reasonable that the Python compiler/ interpreter be written in Python so that it can be manipulated. If you haven't already made it through SICP, you really should. It will help you understand why being able to write a language in itself is a big deal and why having the language around to be manipulated from within the language is very useful. From jgardner at jonathangardner.net Fri Jan 9 13:50:01 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:50:01 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: <02c701b5-68a1-476d-9885-ba2dab406b58@k1g2000prb.googlegroups.com> On Jan 5, 6:08?pm, Grant Edwards wrote: > On 2009-01-05, Kangkook Jee wrote: > > I'm still struggling to solve it within python process since > > it looks cleaner but it doesn't seems to be easy at all. > > I don't why adding bunches of code to your app would be > "cleaner" than gathering data using external programs. > Those external programs may not be available on all the platforms he might want to run in. Or he may have some specific requirements that those tools can't satisfy. Software reuse is wonderful when it works. But it doesn't work all the time, even though it probably should. From carsten.haese at gmail.com Fri Jan 9 14:12:44 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 09 Jan 2009 14:12:44 -0500 Subject: how to remove 'FFFD' character In-Reply-To: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> References: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> Message-ID: webcomm wrote: > I don't know what the character encoding of this data is and don't > know what the 'FFFD' represents. The codepoint 0xFFFD is the so-called 'REPLACEMENT CHARACTER'. It is used replace an incoming character whose value is unknown or unrepresentable in Unicode. The browser might display these if for example a page is encoded in latin-1 but it claims to be utf-8, so the byte stream will contain byte sequences that can't be decoded into unicode code points. > I just > want to scrub it out. I tried this... > > clean = txt.encode('ascii','ignore') > > ...but the 'FFFD' still comes through. You must be doing something wrong, then: py> u'Hello,\ufffd World'.encode('ascii', 'ignore') 'Hello, World' HTH, -- Carsten Haese http://informixdb.sourceforge.net From dickinsm at gmail.com Fri Jan 9 14:14:31 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 11:14:31 -0800 (PST) Subject: Unexpected scientific notation References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> <49678673.5000003@ulmcnett.com> Message-ID: <309bbdb9-ea6d-4da3-a5df-78ebe1267f58@t39g2000prh.googlegroups.com> On Jan 9, 5:38?pm, Paul McNett wrote: > I'll clarify my LOL: Mark initially replied to me directly, to which I responded > directly. Because he replied directly, I kept my response offline, too, not knowing > if he had a special reason to discuss this offline instead of in public. Yup, definitely a special reason. Nothing to do with being unable to distinguish between 'Reply' and 'Reply to author'. Honest. Mark From jmazzonelli at gmail.com Fri Jan 9 14:17:50 2009 From: jmazzonelli at gmail.com (Jorge Mazzonelli) Date: Fri, 9 Jan 2009 17:17:50 -0200 Subject: sftp with no password from python In-Reply-To: <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> Message-ID: <138a70320901091117h76c8944epfbe017bbf3b77d19@mail.gmail.com> You should try the paramiko package for that (http://www.lag.net/paramiko/) A google search on that package & SFTP got me this example: http://commandline.org.uk/python/sftp-python/ Cheers Jorge On Fri, Jan 9, 2009 at 1:20 PM, loial wrote: > On 8 Jan, 18:49, Mike Hjorleifsson wrote: > > On Jan 8, 10:39 am, loial wrote: > > > > > Is it possible to usesftpwithout a password from python? > > > > Yes you can use keys you preestablish between the server and client so > > you dont need passwords, i do this on all my servers then lock off the > > ability to accept passwords at all, this way no one can dictionary > > attack my ssh servers. > > Thanks...do you have any python examples of using sftp? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- (\__/) (='.'=)This is Bunny. Copy and paste bunny into your (")_(")signature to help him gain world domination. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 9 14:21:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 11:21:28 -0800 Subject: Where's Psyco now? In-Reply-To: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: <50697b2c0901091121u523a506ei40c62d4bce5be107@mail.gmail.com> On Fri, Jan 9, 2009 at 10:41 AM, Vicent wrote: > Hello. This is my first message to the list. > > In this article written in 2002 > > http://www.ibm.com/developerworks/library/l-psyco.html > > they talk about Psyco as a module that makes it possible to accelerate > Python. > > Is it still a state-of-the-art module? > > I found it here also: http://pypi.python.org/pypi/psyco/1.6 > > Do you think it's useful, or it depends...? Its present homepage is http://psyco.sourceforge.net/ , and yes, it is still useful and fairly current. However, it should be used judiciously; only bother with it if you're having a performance problem and would otherwise be tempted to rewrite the algorithm in C. Don't casually use it as an all-purpose accelerator, as that's not what it was built for. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From invalid at invalid Fri Jan 9 14:39:17 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 13:39:17 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On 2009-01-09, Sion Arrowsmith wrote: > Grant Edwards wrote: >>On 2009-01-09, Johannes Bauer wrote: >>> I've come from C/C++ and am now trying to code some Python because I >>> absolutely love the language. However I still have trouble getting >>> Python code to run efficiently. Right now I have a easy task: Get a >>> file, >>If I were you, I'd try mmap()ing the file instead of reading it >>into string objects one chunk at a time. > > You've snipped the bit further on in that sentence where the > OP says that the file of interest is 2GB. Do you still want to > try mmap'ing it? Sure. The larger the file, the more you gain from mmap'ing it. 2GB should easily fit within the process's virtual memory space. When you mmap a file, it doesn't take up any physical memory. As you access different parts of it, pages are swapped in/out by the OS's VM system. If you're using a decent OS, the demand-paged VM system will handle things far more efficiently than creating millions of strings and letting the Python garbage collector clean them up. Or does "mmap" in Python mean something completely different than "mmap" in the C library? -- Grant Edwards grante Yow! Everybody gets free at BORSCHT! visi.com From invalid at invalid Fri Jan 9 14:47:27 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 13:47:27 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: On 2009-01-09, Dennis Lee Bieber wrote: > On Thu, 08 Jan 2009 09:46:26 -0600, Grant Edwards > declaimed the following in comp.lang.python: > > >> Heathkit Z80 stuff used octal notation too. > > Octal worked well for the old 8080 and derivative processors as > there were only 7 registers and "memory/indirect" to encode in an > instruction... So (pseudo example) a MOV command might have been > > 01sssddd (binary) > > or > > 1SD (octal) > > > and S or D representing > > A 1 > B 2 > C 3 > D 4 > E 5 > H 6 > L 7 > Mem 0 (indirect via contents of HL pair) I presume that's why DEC chose octal for the PDP-11 also. There were 8 registers and 8 addressing modes, so they ended up with several fields within the opcodes that were three-bits wide and aligned with octal digits: http://en.wikipedia.org/wiki/PDP-11#Instruction_set When I was in University, we spent an entire quarter studying the PDP-11 instruction set at the binary/octal level and discussing instruction decoding and sequencing. We wrote a few PDP-11 assembly language programs as well, but the course was more about machine level instruction sets than about assembly language. Octal made a lot of sense if you had to deal with raw memory, but once you had access to an assembler and disassembler it didn't really matter. -- Grant Edwards grante Yow! NANCY!! Why is at everything RED?! visi.com From ryandw at gmail.com Fri Jan 9 14:49:23 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 11:49:23 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file Message-ID: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Hi, In python, is there a distinction between unzipping bytes and unzipping a binary file to which those bytes have been written? The following code is, I think, an example of writing bytes to a file and then unzipping... decoded = base64.b64decode(datum) #datum is a base64 encoded string of data downloaded from a web service f = open('data.zip', 'wb') f.write(decoded) f.close() x = zipfile.ZipFile('data.zip', 'r') After looking at the preceding code, the provider of the web service gave me this advice... "Instead of trying to create a file, take the unzipped bytes and get a Unicode string of text from it." If so, I'm not sure how to do what he's suggesting, or if it's really different from what I've done. I find that I am able to unzip the resulting data.zip using the unix unzip command, but the file inside contains some FFFD characters, as described in this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# I don't know if the unwanted characters might be the result of my trying to write and unzip a file, rather than unzipping the bytes. The file does contain a semblance of what I ultimately want -- it's not all garbage. Apologies if it's not appropriate to start a new thread for this. It just seems like a different topic than how to deal with the resulting FFFD characters. Thanks for your help, Ryan From ryandw at gmail.com Fri Jan 9 14:54:14 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 11:54:14 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: On Jan 9, 2:49?pm, webcomm wrote: > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') Sorry, that code is not what I mean to paste. This is what I intended... decoded = base64.b64decode(datum) #datum is a base64 encoded string of data downloaded from a web service f = open('data.zip', 'wb') f.write(decoded) f.close() x = popen("unzip data.zip") From pavlovevidence at gmail.com Fri Jan 9 14:58:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 11:58:21 -0800 (PST) Subject: Problem with -3 switch References: Message-ID: On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > Aivar Annamaa wrote: > > >> As was recently pointed out in a nearly identical thread, the -3 > > >> switch only points out problems that the 2to3 converter tool can't > > >> automatically fix. Changing print to print() on the other hand is > > >> easily fixed by 2to3. > > > >> Cheers, > > >> Chris > > > > I see. > > > So i gotta keep my own discipline with print() then :) > > > Only if you don't want to run your 2.x code through 2to3 before you use > > it as Python 3.x code. > > > regards > > ?Steve > > And mind you, if you follow that route, you are programming in a > mightily crippled language. How do you figure? I expect that it'd be a PITA in some cases to use the transitional dialect (like getting all your Us in place), but that doesn't mean the language is crippled. >?It's about as bad as trying to write > cross-browser CSS. ?Don't put yourself through that pain if you don't > have to. Have you tried doing that, or are you imagining how it will be? I'm curious about people's actual experiences. Problem is, a lot of people use the "bang at it with a hammer till it works" approach to programming, and really have no shame when it comes to engaging in questionable practices like relying on accidental side effects, rather than taking the time to try to program robustly. I expect people with that style of programming will have many more issues with the transition. Carl Banks From rurpy at yahoo.com Fri Jan 9 15:06:22 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 12:06:22 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Message-ID: <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >>>> a = array (1,2,3) >>>> b = a >>>> a[1] = 4 >>>> print b >>>> >>>> C, C++, VBA, Fortran, Perl: 1, 2, 3 >>>> Python: 1, 4, 3 >>> You are mistaken >> >> I don't think so. >> See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 >> The code I quoted there was tested. >> In the C/C++ case, array-to-pointer coercion confuses >> the issue so I embedded the array in a struct which >> is more like an "object". > > No, that's cheating (IMHO). Structs used directly (rather than via > pointers) are the odd beast, and while they're certainly possible in C, > they are far from the normal idiom. And certainly embedding an array in > a struct just to force it to be copied, avoiding the standard reference > semantics, is an arbitrary trick. It was intended as a purely rhetorical device to avoid requiring a lot of verbiage to say why a struct example is used for C and arrays for the others and why that makes no difference to my point. Actually, the whole code/results thing was purely for effect since I presume most people reading already understand how assignments work in these languages, or that least that there are significant languages using copy-like assignments. > I never claimed that you *couldn't* have copy semantics in C; you can do > almost anything you want in C (or C++). But the *normal* usage of an > array is via a pointer, in which case the semantics are exactly the same > as in Python, Java, REALbasic, .NET, etc. Arrays are the only datatype in C that don't use copy-like assignment. Everything else does. >>(Keep in mind >> my point was not to show the behavior of arrays, but to >> show that several common languages *do not* use Python's >> "*all* names are references" model -- though of course >> this does not preclude their having some Python-like >> assignments since they all have some way of doing >> references.) > > Ah. OK then, I guess I missed you're point. You're absolutely right; > many languages have both reference types and value types. Python is a > bit unusual in that it has only reference types. I would have picked a > different example to illustrate that, but it's true nonetheless. If one accepts that there are a "lot" of people who post in here that clearly are surprised by Python's assignment semantics, and further appear to expect assignment to have copy-like semantics, then where is that expectation coming from? How would anyone develop that expectation if (from a different post in this thread), "[Python's] idea of assignment is the same as anyone else's." If you maintain that reference-like assignment is very common and something every programmer is accustomed to, then where are they getting the copy-like assignment expectations from? I agree that most of the time, when one is using large (memory) composite "objects", and one needs to pass, or access them by different names, one will often use references to do so in order to avoid expensive copies or to get desired "shared" behavior. But (with the exception of C arrays [*1]), doing so requires some special syntax in all the languages I mentioned (AFAIK). So it still seems to me that this is a likely explanation to why there is frequent misunderstanding of Python's assignments, and why responding to such misunderstandings with, "Python's assignments are the same as other languages'", is at best not helpful. [*1] I have often wished that C handled arrays the same way it does structs. I am sure that the pointer-array pseudo-equivalence seemed like a very clever idea at the time but I wonder if Dennis Richie ever had second thoughts about it. From steve at holdenweb.com Fri Jan 9 15:15:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 15:15:29 -0500 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: webcomm wrote: > Hi, > In python, is there a distinction between unzipping bytes and > unzipping a binary file to which those bytes have been written? > > The following code is, I think, an example of writing bytes to a file > and then unzipping... > > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') > > After looking at the preceding code, the provider of the web service > gave me this advice... > "Instead of trying to create a file, take the unzipped bytes and get a > Unicode string of text from it." > Not terribly useful advice, but one presumes he she or it was trying to be helpful. > If so, I'm not sure how to do what he's suggesting, or if it's really > different from what I've done. > Well, what you have done appears pretty wrong to me, but let's take a look. What's datum? You appear to be treating it as base64-encoded data; is that correct? Have you examined it? f = open('data.zip', 'wb') opens the file data.zip for writing in binary. Not as a zip file, you understand, just as a regular file. I suspect here you really needed f = zipfile.ZipFile('data.zip', 'w') Now, of course, you need to remember what zipfiles contain. Which is other files. So the data you *write* tot he zipfile has to be associated with a filename in the archive. Of course you don't have the data in a file, you have it in a string, so you would use f.writestr("somefile.dat", decoded) f.close() You have now written a zip file containing a single "somefile.dat" file with the decoded base64 data in it. Open it with Winzip or one of its buddies and see if anyone barfs. > I find that I am able to unzip the resulting data.zip using the unix > unzip command, but the file inside contains some FFFD characters, as > described in this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# > I don't know if the unwanted characters might be the result of my > trying to write and unzip a file, rather than unzipping the bytes. > The file does contain a semblance of what I ultimately want -- it's > not all garbage. > But it's certainly not a zip file. > Apologies if it's not appropriate to start a new thread for this. It > just seems like a different topic than how to deal with the resulting > FFFD characters. > Don't worry about it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Fri Jan 9 15:16:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 20:16:01 +0000 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: <4967B081.2030901@mrabarnett.plus.com> webcomm wrote: > Hi, > In python, is there a distinction between unzipping bytes and > unzipping a binary file to which those bytes have been written? > Python's zipfile module can only read and write zip files; it can't compress or decompress data as a bytestring. > The following code is, I think, an example of writing bytes to a file > and then unzipping... > > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') > > After looking at the preceding code, the provider of the web service > gave me this advice... > "Instead of trying to create a file, take the unzipped bytes and get a > Unicode string of text from it." > > If so, I'm not sure how to do what he's suggesting, or if it's really > different from what I've done. > If what you've been given is data which has been zipped and then base-64 encoded, then I can't see that you might be doing wrong. > I find that I am able to unzip the resulting data.zip using the unix > unzip command, but the file inside contains some FFFD characters, as > described in this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# > I don't know if the unwanted characters might be the result of my > trying to write and unzip a file, rather than unzipping the bytes. > The file does contain a semblance of what I ultimately want -- it's > not all garbage. > > Apologies if it's not appropriate to start a new thread for this. It > just seems like a different topic than how to deal with the resulting > FFFD characters. > From ryandw at gmail.com Fri Jan 9 15:18:35 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 12:18:35 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 1:32?pm, Scott David Daniels wrote: > I'd certainly try to figure out if the archive was mis-handled > somewhere along the way. ? Quite possible that I'm mishandling something, or the service provider is mishandling something. Probably the former. Please see this more recent thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864?hl=en# From mdw at distorted.org.uk Fri Jan 9 15:23:11 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 20:23:11 +0000 (UTC) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: [Sigh. I must apologize for the length of this article. I can't, alas, see a satisfactory way of trimming it. The doubly-quoted stuff later on was by me.] Steven D'Aprano wrote: > I'm pretty sure that no other pure-Python coder has manipulated > references either. They've manipulated objects. No: not directly. The Python program deals solely with references; anything involving actual objects is mediated by the runtime. > Whatever the VM does under the hood is another story. (And, to stave off a return to the discussion about synchronized clones and other implementation techniques, whether a reference is a memory pointer, a tagged immutable immediate value, or an element of an equivalence-class of clones is an irrelevant implementation detail; but the reference needs to exist to explain observed, specified behaviour. For the purposes of this discussion, I shall continue to use the commonly accepted term `reference' to denote an arbitrary and implementation-specific choice of the isomorphism class of such possible implementation techniques.) > That's why we should try to keep the different layers of explanation > separate, without conflating them. Python programmers don't actually > flip bits, and neither do they manipulate references. Python > programmers don't have access to bits, or references. What they have > access to is objects. No, that's my point: Python programmers /don't/ have direct access to objects. The objects themselves are kept at arm's length by the indirection layer of references. > (Of course, there are ways to get under the hood if you really want > to.) Yes, but -- as I've done throughout this discussion -- I shall continue to use only Python examples whose behaviour is fully specified and implementation independent in order to support my thesis. > > Python does pass-by-value, but the things it passes -- by value -- > > are references. > > If you're going to misuse pass-by-value to describe what Python does, > *everything* is pass-by-value "where the value is foo", for some foo. No. I've tried explaining this before, with apparently little success. This is probably my fault: I don't seem to be good at explaining concepts to people whose mindset is significantly different to mine. (My refusal to ignore complicated corner cases doesn't help.) The words `value' and `reference' have significantly different meanings depending on whether we're talking on the one hand about data models and on the other hand about argument-passing models. In particular, the latter focuses on details at a lower abstraction level. This is extremely unfortunate, and is causing a lot of confusion. I can only speculate that the origins of this mess are historical and have their origins in the fact that lower-level languages have tended to have more exotic argument-passing models. This is going to be (as far as I can make it) a language-independent survey. That in itself is going to make matters complicated, because I know a lot of programming languages, and they differ in sometimes subtle ways. Enough of the disclaimers, and on to some terminology. For the avoidance of confusion, I shall use the following terms in perhaps technical senses, defined below. Even so, I believe that I'm using these terms in the senses (or at least, in ways similar to the senses) commonly understood in the field of programming language design. * A /value/ is an item of data. The range and nature of values is language specific. Typically, values encompass at least some kinds of numbers, textual data, and compound data structures; they may also include behavioural items such as functions. * A /location/[1] is an area of memory suitable for storing the /immediate representation/ (which I shall abbreviate to /IR/) of a value. (A location may be capable of storing things other than IRs, e.g., representations of unevaluated expressions in lazily evaluated languages. Locations may vary in size, e.g., in order to be capable of storing different types of IRs.) * A /variable/ is a location to which has been /bound/ a name. Given an occurrence of a name in a program's source, there is a language specific rule for determining the variable to which it is bound. * /Evaluation/ is the process of determining a value from an expression. The /value of/ an expression is the result of evaluating the expression. This value is, in general, dependent on the contents of the locations to which names appearing in the expression are bound. * A /function/ (synonymously, /procedure/) is a subprogram which may be /called/ by another (not necessarily distinct) part of the program, supplying zero or more /arguments/, performing a computation depending on these arguments, and returning zero or more /results/. Whether functions are values is language specific. The nature of the arguments and results is language specific. [1] Previously, I used the term `slot' for what I'm now calling a `location'. The argument passing model `pass-by-value' has a number of distinctive properties. * The argument expression is fully evaluated before the function is called, yielding an argument value. * The corresponding parameter name is bound to a fresh location. * The argument value IR is stored in the parameter's location. By contrast, the `pass-by-reference' model has other distinguishing properties. * Whether arbitrary argument expressions are permitted is language dependent; often, only a subset of available expressions -- those that designate locations -- are permitted. If the argument expression does designate a location, then this location is the /argument location/. If arbitrary expressions are permitted, and the expression does not designate a location, then a fresh location is allocated to be the argument location, the expression evaluated, and the resulting IR stored in the argument location. * The corresponding parameter name is bound to the argument location. There are other models, including value/return and call-by-name. It should be clear that it is possible to write the traditional `swap' function trivially using pass-by-reference, but one requires explicit indirection in order to achieve the same effect using pass-by-value. > You can't have anything but pass-by-value with current computer > technology, because computers don't actually move arguments, they only > copy bytes. So pass-by-value becomes a meaningless term, because it > describes every computer language imaginable, including hypothetical > ones using calling conventions not yet invented, and therefore > explains nothing. I hope that I have convincingly demonstrated that it's possible to define `pass-by-value' in a coherent manner, consistent with conventional usage, and distinguishing it clearly from `pass-by- reference'. > > (The `pass-by-*' notions are confusingly named anyway. Pass-by-name > > doesn't actually involve names at all.) > > You might find them confusing, but I don't. What I find confusing is > that people insist on misusing terminology invented for describing one > type of behaviour in order to use it for a completely different type > of behaviour just because of certain similarities under the hood. I hope that I've also demonstrated that the similarities `under the hood' are not actually there. Indeed, I've defined `pass-by-reference' without describing references at all. This is actually as it should be. The simple assembler procedure xchg eax, ebx ret implements a `swap' function pretty well. We can map the abstract concepts listed above onto the low-level details easily: locations can be in memory on in registers; argument locations are in registers; argument value IRs are words; and the binding of names to locations is fixed. > > I agree with the comment about Pascal, but C is actually pretty similar > > to Python here. C only does pass-by-value. > > Except for arrays. Even for those. C doesn't pass arrays at all; instead it passes (programmer-visible) pointers. See other article. > > If you want a function to modify your variable, you have to pass a > > pointer value which points to it. > > Yes, because the variable is copied before the function sees it. So if > you pass a struct, and modify one of the struct's fields, the caller > doesn't see the change. > > Now try that with Python, and you'll see completely different behaviour. > (You'll have to use something *like* a struct, because Python doesn't > have them. Try an object with attributes.) That's because C's IRs are raw value representations; its `locations' correspond to what the C standard calls `objects' (3.15). Pass-by-value works by storing IRs in freshly allocated locations -- in C, these are objects with automatic storage duration (6.2.4, 6.5.2.2). > In other words... C is call-by-value, and (according to you) Python is > call-by-value, but they behaviour differently. And this is entirely due to the difference in their immediate representations of values. > > Python has no pointer values, so you need a different hack. The > > hack usually involves lists. (Though it's easier in the main to return > > compound data objects like tuples. I don't suppose that a proposal for > > true multiple return values would go down well here. No, didn't think > > so...) > > Out of curiosity, what makes Python returning tuples less "true" than > "true multiple return values", and what can you do with TMRVs that you > can't do with tuples? `What can you do with ... that you can't do with ...' questions are meaningless when asked about Turing-complete languages, since they're obviously equipotent. In Python, if I want to convey multiple results to a function's caller, I usually use a tuple. This is a proper first-class value and needs to be properly allocated and populated, and a reference returned. Python's unpacking assignment syntax provides a relatively reasonable way of destructuring the tuple and recovering the individual results. So all of that's fine. * Construction, population and destructuring of the intermediate tuple has a performance impact. An intelligent compiler with knowledge of the function and the call site might be able to optimize the tuple away, but this is difficult due to Python's intrinsically dynamic nature: dynamic typing means a compiler must be better at drawing inferences from complicated code, and it not actually be possible to determine at compile time which actual function is being called anyway. (Not that I'd have Python any other way.) This would matter more if there were a significant statically-compiled implementation of Python that was intended for high-performance computing. * I quite frequently find myself only interested in one of several results from a function. For example, a function which parses some data from the head of a string might plausibly return both the parsed object and the remainder of the string. If I'm interested only in the object, I'll write something like obj = parse(string) and then obj will be a tuple. If the thing I'm expecting might be a tuple (or at least a sequence of some kind) it might be a while before an error occurs, if ever. Multiple return values would either (Common Lisp model) let me ignore return values I wasn't interested in, or (Scheme model) signal errors that I'd done something wrong. The Common Lisp model is riskier (I can ignore things which perhaps I shouldn't) but more flexible (in particular, I can enhance functions by adding return values without breaking existing callers, and I can write functions which return potentially interesting things which they computed anyway but weren't part of the main objective). It's not a big deal. Forget I mentioned it. In particular, there's no convenient syntax left to use for multiple return values anyway. When (not if) I want Lisp, I /do/ know where to find it. > x = 23 > > There's a name, and an object, and I've bound the name to the object so I > can refer to the object 23 by the name x. (Assume that x was previously unbound, and this is evaluated at top level) The above expression: binds x to a new location, and stores the immediate representation of the constant 23 in this location. (Languages -- other than C++ -- seem pretty uniform in their interpretation of assignment as overwriting a location with a new IR.) Because 23 is immutable, its IR doesn't actually matter that much. These things become apparent only with mutable data. > > You bind names slots in which you store references. Oops. Missing `to' between `names' and `slots'. Sorry. > I'm pretty sure I don't. I'd have noticed. You bind names to locations which store immediate representations. Python IRs are (in the sense defined above) exclusively references. > You may have missed my last question: > > >> > How do we deal with anonymous objects in your model? No. I decided that it was irrelevant given the previous answers I'd already given. That is, if an object's only attached paperweights are stored in other objects -- maybe in boxes -- then it has no obvious name; if there is no path from you to the object, then no action you take can be affected if the daemon clears it away -- so it might as well do that. (This is my fault, I know, but: `model' is the wrong word for the objects/boxes/string/paperweights description. `Metaphor' is probably better. Sorry for my lack of precision on this subject.) > > What I am pretty sure of is that references are going to have to > > enter the picture at some point, because other models get too > > complicated. > Well, I dare say that at *some* point all models are insufficient. No. The Python Language Reference presents a model of Python. CPython, and other implementations are expected to implement this model: failure to do so is (presumably) a bug in the implementation, or a defect in the document. The PLM (assumed defect-free) is therefore a sufficient model of Python, capable of describing all aspects of the language which are not implementation specific. > The map is not the territory, and there's always something that gets > left out. The trick is to explain Python, rather than implementations of Python. But the behaviour of l = [1, 2, 3] l[1] = l can be understood without recourse to implementation specifics. I argue -- and this has really been my point all along -- that this understanding is best achieved by a diagram of the form ,----------, v | +---+ +---+ | l: | *----> | *-----> 1 | +---+ +---+ | | *----------' +---+ | *-----> 3 +---+ than by one of the form +-----+ l: | 1 | +-----+ | <------------- in here is an identical copy of l +-----+ | 3 | +-----+ This immediately gets me thinking about `G?del Escher Bach', strange loops, and all manner of weirdness. Such things still give me the willies occasionally. (I'm willing to accept that I suck at drawing diagrams, and that I might anyway have accidentally misrepresented your position. If you think you can draw a more convincing diagram of this data structure, according to your model, please do.) > But I think your model with strings is more complicated: robots, > sticky Blu-Tack, string that you can't touch or see, and so forth. The metaphor is complicated, yes, but the concepts are somewhat complicated too. Fortunately there are direct mappings from the metaphor to identifiable > Compared to that, TARDIS technology enabling objects to be in two > places at once is remarkably straightforward. Despite it being > physically unrealistic, it's logically simple. You certainly get to talk about Tardises, which is cool. ;-) There is some interesting and relevant material in the classic Who stories `Logopolis' and `Castrovalva'. And, if the resulting recursion is explained thoroughly, it'll lead you on some fascinating diversions around some valuable areas of theory... -- [mdw] From lelandpeng at gmail.com Fri Jan 9 15:26:19 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:26:19 -0800 (PST) Subject: string split Message-ID: Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES It seems work this way, is there more elegant way to do this? Thanks, Leland From joe at strout.net Fri Jan 9 15:29:35 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 13:29:35 -0700 Subject: why cannot assign to function call In-Reply-To: <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <4967B3AF.8050507@strout.net> rurpy at yahoo.com wrote: >> I never claimed that you *couldn't* have copy semantics in C; you can do >> almost anything you want in C (or C++). But the *normal* usage of an >> array is via a pointer, in which case the semantics are exactly the same >> as in Python, Java, REALbasic, .NET, etc. > > Arrays are the only datatype in C that don't use > copy-like assignment. Everything else does. No, arrays are just one reference type; pointers are another (and in most ways, these are the same thing). When dealing with objects in C++, one routinely handles them with pointers, so that's the use case which is analogous to Python -- all the value types can be ignored for the sake of comparison. (C is not an OOP language, of course, but even there, all but the most trivial of structs are usually allocated on the heap and passed around via pointers, just like in C++, Java, .NET, RB, and Python.) >> Ah. OK then, I guess I missed you're point. You're absolutely right; >> many languages have both reference types and value types. Python is a >> bit unusual in that it has only reference types. I would have picked a >> different example to illustrate that, but it's true nonetheless. > > If one accepts that there are a "lot" of people > who post in here that clearly are surprised by > Python's assignment semantics, and further appear > to expect assignment to have copy-like semantics, > then where is that expectation coming from? I think it comes from people stumbling across posts in this forum claiming that Python has unusual assignment semantics. I wish people would stop saying that, as it causes a lot of confusion. > How would anyone develop that expectation if (from > a different post in this thread), "[Python's] idea > of assignment is the same as anyone else's." I can think of two ways: 1. They're new to programming in general, and would have had the same expectation for any other language. OR, 2. They already understand some other language, and then they come here and read wild claims that Python's assignment and parameter-passing semantics are different from other languages. Duped by this claim, they conclude that, if it's unlike other languages, then Python must have copy semantics. > If you maintain that reference-like assignment > is very common and something every programmer is > accustomed to, then where are they getting the > copy-like assignment expectations from? Reference-like assignment IS very common (see ). So, see above. > I agree that most of the time, when one is using > large (memory) composite "objects", and one needs > to pass, or access them by different names, one will > often use references to do so in order to avoid > expensive copies or to get desired "shared" behavior. Right. > But (with the exception of C arrays [*1]), doing so > requires some special syntax in all the languages I > mentioned (AFAIK). Whether you consider it "special" or not, pointers are extremely common in C. Even more so in C++, which is the closest thing to an OOP language in the list of moldy languages you mentioned. You also mentioned VBA -- if that's anything like VB, it does NOT require any special syntax; a variable is a reference type if its declared type is a class or string, and a simple type if it's anything else (just like in .NET, Java, and REALbasic). > So it still seems to me that this is a likely > explanation to why there is frequent misunderstanding > of Python's assignments, and why responding to such > misunderstandings with, "Python's assignments are > the same as other languages'", is at best not helpful. I don't think so. More likely, people are being confused by the claim that Python's assignments are NOT like other languages, when in fact they are. Best, - Joe From fred.sells at adventistcare.org Fri Jan 9 15:31:06 2009 From: fred.sells at adventistcare.org (Sells, Fred) Date: Fri, 9 Jan 2009 15:31:06 -0500 Subject: Python Apache Handler In-Reply-To: References: Message-ID: Mod_python works, but if you are doing anything significant look into one of the many frameworks like turbogears or django. More structure to learn but less code when all is said and done. > -----Original Message----- > From: python-list-bounces+frsells=adventistcare.org at python.org > [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On > Behalf Of Scooter > Sent: Friday, January 09, 2009 9:37 AM > To: python-list at python.org > Subject: Python Apache Handler > > Does anyone have any good examples, or links thereto for using python > as an Apache handler? And I should qualify all of this by saying I'm a > python newbie, and while having experience with Apache, I've never > done anything outside whats "in the box" . > > What I'm looking for is how one might use Python not from the CGI/ > presentation side but more on the backend...i.e. for each page Apache > serves up examine the request and update some headers, or add a cookie > to the response. Or possibly use Python for writing a custom Apache > logger. I've searched the web but typically end up with pages for > mod_python and writing CGI scripts. > > And if you feel this is better posted in an Apache group vs. here, let > me apologize up front. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list From ryandw at gmail.com Fri Jan 9 15:32:28 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 12:32:28 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: On Jan 9, 3:15?pm, Steve Holden wrote: > webcomm wrote: > > Hi, > > In python, is there a distinction between unzipping bytes and > > unzipping a binary file to which those bytes have been written? > > > The following code is, I think, an example of writing bytes to a file > > and then unzipping... > > > decoded = base64.b64decode(datum) > > #datum is a base64 encoded string of data downloaded from a web > > service > > f = open('data.zip', 'wb') > > f.write(decoded) > > f.close() > > x = zipfile.ZipFile('data.zip', 'r') > > > After looking at the preceding code, the provider of the web service > > gave me this advice... > > "Instead of trying to create a file, take the unzipped bytes and get a > > Unicode string of text from it." > > Not terribly useful advice, but one presumes he she or it was trying to > be helpful. > > > If so, I'm not sure how to do what he's suggesting, or if it's really > > different from what I've done. > > Well, what you have done appears pretty wrong to me, but let's take a > look. What's datum? You appear to be treating it as base64-encoded data; > is that correct? Have you examined it? It's data that has been compressed then base64 encoded by the web service. I'm supposed to download it, then decode, then unzip. They provide a C# example of how to do this on page 13 of http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf If you have a minute, see also this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 From markus.falb at fasel.at Fri Jan 9 15:33:55 2009 From: markus.falb at fasel.at (Markus Falb) Date: Fri, 9 Jan 2009 21:33:55 +0100 (CET) Subject: mac osx how to use a specific python environment References: Message-ID: On Wed, 07 Jan 2009 10:07:18 -0500, Philip Semanchuk wrote: > On Jan 7, 2009, at 7:27 AM, marco kuhn wrote: > >> hi, >> >> I would like to use a specific python environment in a script . The >> script is load as a plugin by a program which offer a python api . The >> python environment is build in. >> >> How can I use the standard python environment. Can i explicit load the >> env in my python script. > > Hi Marco, > I'm not exactly sure what you want to do. But if you execute `python` at > the command line, OS X will launch whatever version of Python it finds > first in your PATH. also, with unix you can set a "per script" interpreter in the first line of the script #!/usr/bin/env python2.5 or #!/usr/bin/python2.3 or #!/usr/bin/python or something like that should do the trick. however, i'm also not exactly sure what you want to do. i dont think its possible to switch the interpreter in case you import your plugin as a module best regards, markus From lelandpeng at gmail.com Fri Jan 9 15:36:34 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:36:34 -0800 (PST) Subject: string split Message-ID: <1ac9a2f6-7561-4f5e-8655-1dee27632a5d@d42g2000prb.googlegroups.com> Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES if str7[0] == "\"" : str8=str7.split("\"", 2) str9=str8[1] else : str8=str7.split(",", 1) str9=str8[0] print(key, ":", str9) It seems work this way, but is there more elegant way to do this? Thanks, Leland From rdcollum at gmail.com Fri Jan 9 15:37:38 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 9 Jan 2009 12:37:38 -0800 (PST) Subject: Where's Psyco now? References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: On Jan 9, 2:21?pm, "Chris Rebert" wrote: > On Fri, Jan 9, 2009 at 10:41 AM, Vicent wrote: > > Hello. This is my first message to the list. > > > In this article written in 2002 > > >http://www.ibm.com/developerworks/library/l-psyco.html > > > they talk about Psyco as a module that makes it possible to accelerate > > Python. > > > Is it still a state-of-the-art module? > > > I found it here also:http://pypi.python.org/pypi/psyco/1.6 > > > Do you think it's useful, or it depends...? > > Its present homepage ishttp://psyco.sourceforge.net/, and yes, it is > still useful and fairly current. > However, it should be used judiciously; only bother with it if you're > having a performance problem and would otherwise be tempted to rewrite > the algorithm in C. Don't casually use it as an all-purpose > accelerator, as that's not what it was built for. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com If that's the case where's the point of diminishing returns on using psyco? Why would it not be useful in a general setting? From lelandpeng at gmail.com Fri Jan 9 15:39:22 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:39:22 -0800 (PST) Subject: string split Message-ID: <26c34fad-a0cf-4f0a-9db6-410e19f38ba3@z28g2000prd.googlegroups.com> Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES if str7[0] == "\"" : str8=str7.split("\"", 2) str9=str8[1] else : str8=str7.split(",", 1) str9=str8[0] print(key, ":", str9) It seems work this way, but is there more elegant way to do this? Thanks, Leland From benjamin.kaplan at case.edu Fri Jan 9 15:39:54 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 9 Jan 2009 15:39:54 -0500 Subject: string split In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 3:26 PM, Leland wrote: > Hi, > > I have some formatted strings that I'd like to split and get the > meaningful data, here is the example of the string format. The big > difference of these two line are the second double quote set at the > second line > 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, > 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", > 3,"D24,D72,D104", > > I want to split the string into the following format: > '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' > '100-01004-001', 'Diode,High Voltage General Purpose,600mA, > 200V,SOT-23', '3', 'D24,D72,D104' > [snip code] This looks like a CSV file to me. If that is the case, it is easier to use the built-in csv module than to try to write your own parser. http://docs.python.org/library/csv.html#module-csv -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Fri Jan 9 15:46:06 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 20:46:06 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: Aaron Brady wrote: > Possible compromise. You can think of functions as mutation-only. > You pass the object, and it gets a new (additional) name. The old > name doesn't go in. Huh? That doesn't explain circular data structures at all, unless your idea of `name' is unrelated to the identifiers the programmer has typed and in fact is the same as what I'm calling a reference. > Regardless, IMO, references don't add any explanatory power; they just > make you feel cocky that you know what they are. No, they're essential to understanding sharing and circular data. > M: If 'fun()' returned a reference, you would be able to assign to it. [mdw]: Why would you think that you can assign to a reference? You assign to variables, not references. > -- Why can't I assign to a function call? > -- Python variables are references only. You may have missed this, but I explained at least twice: variables are bound to `slots' or `locations'; locations, in Python, store references to values; references are not values. But I answered this lot ages ago. I'm still dealing with the fallout because of my approach, though. > In other words, Mark and Joe, cut to the chase. You're shirking. I'm trying to explain somewhat complex concepts in defence of my thesis. This is not intended to be an answer to the original poster: the discussion has become considerably more technical since then. -- [mdw] From sjmachin at lexicon.net Fri Jan 9 15:48:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 12:48:57 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 10, 5:32?am, Scott David Daniels wrote: > webcomm wrote: > > .... ?I tried Scott's getzip() function yesterday... I > > stumbled upon it in my searches. ?It didn't seem to help in my case, > > though it did produce a different error: ?ValueError, substring not > > found. ?Not sure what that means. > > and in another message webcomm wrote: > ?> I ran the diagnostic gadget... > ?> > ?> archive size is 69888 > ?> FileHeader at 0 > ?> CentralDir at 43796 > ?> EndArchive at 43846 > > This is telling you that the archive ends at 43846, Not quite. """In a "normal" uncommented archive, EndArchive_pos + 22 == archive_size.""" > but the file > is 69888 bytes long (69888 - 43846 = 26042 post-archive bytes). > Have you tried calling getzip(filename, ignoreable=30000)? > The whole point of the function is to ignore the nasty stuff at the > end, but if _I_ had a file with more than 25K of post-archive bytes, > I'd certainly try to figure out if the archive was mis-handled > somewhere along the way. Me too. Further, if I wasn't "ever diplomatic" :-), I wouldn't be calling software (or people!) that blithely ignored 25kb of unexplained data "forgiving" ... some other f-words, perhaps. > ?Byt the way, one reason you cannot find > the archive by looking at the start of the file is that the zip file > format is meant to allow you to append a zip file to another file (such > as an executable) and treat the combination as an archive. > > --Scott David Daniels > Scott.Dani... at Acm.Org From bj_666 at gmx.net Fri Jan 9 15:52:59 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 20:52:59 GMT Subject: string split References: <26c34fad-a0cf-4f0a-9db6-410e19f38ba3@z28g2000prd.googlegroups.com> Message-ID: <6sprpbF7n8nmU1@mid.uni-berlin.de> On Fri, 09 Jan 2009 12:39:22 -0800, Leland wrote: > It seems work this way, but is there more elegant way to do this? Yes, the `csv` module in the standard library. Ciao, Marc 'BlackJack' Rintsch From malaclypse2 at gmail.com Fri Jan 9 15:57:42 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 9 Jan 2009 15:57:42 -0500 Subject: string split In-Reply-To: References: Message-ID: <16651e80901091257x42e633bcnee738d262188c525@mail.gmail.com> On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan > This looks like a CSV file to me. If that is the case, it is easier to use > the built-in csv module than to try to write your own parser. It should be as easy as this: import csv testfile = open('testfile.csv', 'w') testdata = """100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23",3,"D24,D72,D104", """ testfile.write(testdata) testfile.close() infile = open('testfile.csv', 'r') reader = csv.reader(infile) for line in reader: print line The output of that code is: ['100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46', ''] ['100-01004-001', 'Diode,High Voltage General Purpose,600mA,200V,SOT-23', '3', 'D24,D72,D104', ''] so line[0] is your part number, etc. -- Jerry From tjreedy at udel.edu Fri Jan 9 15:58:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jan 2009 15:58:56 -0500 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: <496715ac$0$15321$426a74cc@news.free.fr> References: <4966750c$0$5150$426a74cc@news.free.fr> <496715ac$0$15321$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > > To be more exact: there's no "default __nonzero__". In Py3, '__nonzero__' has been renamed to __bool__. All objects are instances of class object, which indeed has no __bool__ method to be a default (it does have default __hash__ and __eq__, etc). > The boolean value of > an object is eval'd this way: > > If the object is None (special cased by the interpreter AFAICT), it is > false. Must be, since None.__bool__ does not exist. > Else if the object implements __nonzero__, it has the boolean value > returned by __nonzero__. Leaving None aside, __bool__ is only needed for non-collection classes (which do not have __len__) if at least 1 instance of the class is intended to be False. For built-in classes, this means numbers. > Else if the object implements __len__, it has the boolean value of its > length. This method, interpreted more generally as 'object count', essentially defines collection classes. > Else if is true. Thank you for the clarification. Then the __new__ method of class bool would be implemented in Python as def __new__(cls, ob): if ob is None: return False elif hasattr(ob, '__bool__'): b = ob.__bool__() if b.__class__ is bool: return b else: raise TypeError("__bool__ should return bool, returned %s" % b.__class__) elif hasattr(ob, '__len__'): return len(ob) != 0 # ob.__len__() != 0 does not do len's typecheck on return else: return True Experiments show that 3.0 bool.__new__ does typecheck the return of ob.__bool__ and raises the error indicated and that __len__ must return a value that passes len's typecheck. Terry Jan Reedy From bj_666 at gmx.net Fri Jan 9 16:02:57 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 21:02:57 GMT Subject: Where's Psyco now? References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: <6spsc1F7n8nmU2@mid.uni-berlin.de> On Fri, 09 Jan 2009 12:37:38 -0800, Roger wrote: > If that's the case where's the point of diminishing returns on using > psyco? Why would it not be useful in a general setting? There is some overhead involved with the runtime analysis and compiling. Functions that are only called once usually don't benefit from psyco, even worse they can be slower because of the unnecessary overhead. And not all code can be accelerated. Best candidates are functions that are somewhat C-like, i.e. doing lots of operations on simple number types. Things that can be translated directly to machine code. And for some very generic functions that are called with lots of different types, the memory consumption is high because of all the specialized code that will be compiled. Ciao, Marc 'BlackJack' Rintsch From mdw at distorted.org.uk Fri Jan 9 16:03:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 21:03:39 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Python doesn't do the same thing as C. It actually passes the same value > to the function, without copying it. > > Why oh why do you keep insisting that Python is no different from C? I'm beginning to think that you're not bothing to read what I'm writing, but I'll assume instead that I'm just not writing clearly enough. In one respect, C and Python are alike. That respect is that they both pass arguments to functions `by value'. In another respect, C and Python are different. That respect is that they represent these arguments differently: C stores a binary representation of the value directly in the object allocated to store it (6.2.6.1); whereas Python stores a reference to the actual value (3.1, 4.1). This is what I mean when I say that Python passes arguments by value -- but the `values' that are passed are references. References to the C standard are to ISO 9899:1999, though I'm fairly sure that N843 and N1256 will do as well; references to the Python Language Reference are to the 2.5.2 version dated 2008-02-21. I'll note here that the PLM uses the term `binding' in the usual sense understood by the larger programming-language community, and not as a confusing synonym for assignment. > Why oh why do you keep insisting that Python is no different from C? Why oh why do you keep insisting that, because I claim that the two languages are alike in one respect, that I believe that they must be alike in a different respect, despite my repeated assertions to the contrary? -- [mdw] From lelandpeng at gmail.com Fri Jan 9 16:05:24 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 13:05:24 -0800 (PST) Subject: string split References: Message-ID: <0f73cff0-b5db-4e43-851b-9ff12b1ab159@t39g2000prh.googlegroups.com> On Jan 9, 12:57?pm, "Jerry Hill" wrote: > On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan > > > This looks like a CSV file to me. If that is the case, it is easier to use > > the built-in csv module than to try to write your own parser. > > It should be as easy as this: > > import csv > > testfile = open('testfile.csv', 'w') > testdata = """100-01001-001,"Diode,Small Signal,SOT-23",1,D46, > 100-01004-001,"Diode,High Voltage General > Purpose,600mA,200V,SOT-23",3,"D24,D72,D104", > """ > testfile.write(testdata) > testfile.close() > > infile = open('testfile.csv', 'r') > reader = csv.reader(infile) > for line in reader: > ? ? print line > > The output of that code is: > > ['100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46', ''] > ['100-01004-001', 'Diode,High Voltage General > Purpose,600mA,200V,SOT-23', '3', 'D24,D72,D104', ''] > > so line[0] is your part number, etc. > > -- > Jerry It works like a charm. Really appreciate all the helps. From arkanes at gmail.com Fri Jan 9 16:08:35 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 15:08:35 -0600 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> On Fri, Jan 9, 2009 at 2:32 PM, webcomm wrote: > On Jan 9, 3:15 pm, Steve Holden wrote: >> webcomm wrote: >> > Hi, >> > In python, is there a distinction between unzipping bytes and >> > unzipping a binary file to which those bytes have been written? >> >> > The following code is, I think, an example of writing bytes to a file >> > and then unzipping... >> >> > decoded = base64.b64decode(datum) >> > #datum is a base64 encoded string of data downloaded from a web >> > service >> > f = open('data.zip', 'wb') >> > f.write(decoded) >> > f.close() >> > x = zipfile.ZipFile('data.zip', 'r') >> >> > After looking at the preceding code, the provider of the web service >> > gave me this advice... >> > "Instead of trying to create a file, take the unzipped bytes and get a >> > Unicode string of text from it." >> >> Not terribly useful advice, but one presumes he she or it was trying to >> be helpful. >> >> > If so, I'm not sure how to do what he's suggesting, or if it's really >> > different from what I've done. >> >> Well, what you have done appears pretty wrong to me, but let's take a >> look. What's datum? You appear to be treating it as base64-encoded data; >> is that correct? Have you examined it? > > It's data that has been compressed then base64 encoded by the web > service. I'm supposed to download it, then decode, then unzip. They > provide a C# example of how to do this on page 13 of > http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf > > If you have a minute, see also this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 > When they say "zip", they're talking about a zlib compressed stream of bytes, not a zip archive. You want to base64 decode the data, then zlib decompress it, then finally interpret it as (I think) UTF-16, as that's what Windows usually means when it says "Unicode". decoded = base64.b64decode(datum) decompressed = zlib.decompress(decoded) result = decompressed.decode('utf-16') From arkanes at gmail.com Fri Jan 9 16:12:42 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 15:12:42 -0600 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> Message-ID: <4866bea60901091312s760c9649hab50693e204ef604@mail.gmail.com> On Fri, Jan 9, 2009 at 3:08 PM, Chris Mellon wrote: > On Fri, Jan 9, 2009 at 2:32 PM, webcomm wrote: >> On Jan 9, 3:15 pm, Steve Holden wrote: >>> webcomm wrote: >>> > Hi, >>> > In python, is there a distinction between unzipping bytes and >>> > unzipping a binary file to which those bytes have been written? >>> >>> > The following code is, I think, an example of writing bytes to a file >>> > and then unzipping... >>> >>> > decoded = base64.b64decode(datum) >>> > #datum is a base64 encoded string of data downloaded from a web >>> > service >>> > f = open('data.zip', 'wb') >>> > f.write(decoded) >>> > f.close() >>> > x = zipfile.ZipFile('data.zip', 'r') >>> >>> > After looking at the preceding code, the provider of the web service >>> > gave me this advice... >>> > "Instead of trying to create a file, take the unzipped bytes and get a >>> > Unicode string of text from it." >>> >>> Not terribly useful advice, but one presumes he she or it was trying to >>> be helpful. >>> >>> > If so, I'm not sure how to do what he's suggesting, or if it's really >>> > different from what I've done. >>> >>> Well, what you have done appears pretty wrong to me, but let's take a >>> look. What's datum? You appear to be treating it as base64-encoded data; >>> is that correct? Have you examined it? >> >> It's data that has been compressed then base64 encoded by the web >> service. I'm supposed to download it, then decode, then unzip. They >> provide a C# example of how to do this on page 13 of >> http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf >> >> If you have a minute, see also this thread... >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 >> > > When they say "zip", they're talking about a zlib compressed stream of > bytes, not a zip archive. > > You want to base64 decode the data, then zlib decompress it, then > finally interpret it as (I think) UTF-16, as that's what Windows > usually means when it says "Unicode". > > decoded = base64.b64decode(datum) > decompressed = zlib.decompress(decoded) > result = decompressed.decode('utf-16') > And of course as *soon* as I write that, I read the appendix on the documentation in full and turn out to be wrong. Ignore me *sigh*. It would really help if you could post a sample file somewhere. From bj_666 at gmx.net Fri Jan 9 16:14:52 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 21:14:52 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: <6spt2cF7n8nmU3@mid.uni-berlin.de> On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > Marc 'BlackJack' Rintsch wrote: > >> def iter_max_values(blocks, block_count): >> for i, block in enumerate(blocks): >> histogram = defaultdict(int) >> for byte in block: >> histogram[byte] += 1 >> >> yield max((count, byte) >> for value, count in histogram.iteritems())[1] >> > [snip] > Would it be faster if histogram was a list initialised to [0] * 256? Don't know. Then for every byte in the 2?GiB we have to call `ord()`. Maybe the speedup from the list compensates this, maybe not. I think that we have to to something with *every* byte of that really large file *at Python level* is the main problem here. In C that's just some primitive numbers. Python has all the object overhead. Ciao, Marc 'BlackJack' Rintsch From robert.kern at gmail.com Fri Jan 9 16:33:10 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 09 Jan 2009 15:33:10 -0600 Subject: Printed Documentation In-Reply-To: References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: Tim Arnold wrote: > just a datapoint, but I used lulu.com to print the latex sources (525 pages) > hardbound for a cost of $25 US. Did they handle the LaTeX fonts well? The last time I looked at Lulu, they claimed that there were some font issues with PDFs made by LaTeX. -- 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 ryandw at gmail.com Fri Jan 9 16:56:56 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 13:56:56 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> Message-ID: <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> On Jan 9, 4:12?pm, "Chris Mellon" wrote: > It would really help if you could post a sample file somewhere. Here's a sample with some dummy data from the web service: http://webcomm.webfactional.com/htdocs/data.zip That's the zip created in this line of my code... f = open('data.zip', 'wb') If I open the file it contains as unicode in my text editor (EditPlus) on Windows XP, there is ostensibly nothing wrong with it. It looks like valid XML. But if I return it to my browser with python+django, there are bad characters every other character If I unzip it like this... popen("unzip data.zip") ...then the bad characters are 'FFFD' characters as described and pictured here... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# If I unzip it like this... getzip('data.zip', ignoreable=30000) ...using the function at... http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 ...then the bad characters are \x00 characters. From ryandw at gmail.com Fri Jan 9 17:00:36 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:00:36 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> On Jan 8, 8:39?pm, "James Mills" wrote: > Send us a sample of this file in question... Here's a sample with some dummy data from the web service: http://webcomm.webfactional.com/htdocs/data.zip That's the zip created in this line of my code... f = open('data.zip', 'wb') If I open the file it contains as unicode in my text editor (EditPlus) on Windows XP, there is ostensibly nothing wrong with it. It looks like valid XML. But if I return it to my browser with python+django, there are bad characters every other character If I unzip it like this... popen("unzip data.zip") ...then the bad characters are 'FFFD' characters as described and pictured here... http://groups.google.com/group/comp.lang.python/browse_thread/thread/... If I unzip it like this... getzip('data.zip', ignoreable=30000) ...using Scott's function at... http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 ...then the bad characters are \x00 characters. From ryandw at gmail.com Fri Jan 9 17:04:15 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:04:15 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> Message-ID: <59234154-ab06-442b-8433-52275e774eae@p36g2000prp.googlegroups.com> On Jan 9, 5:00?pm, webcomm wrote: > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > trying again to post the link re: FFFD characters... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# From sjmachin at lexicon.net Fri Jan 9 17:21:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 14:21:55 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> Message-ID: <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> On Jan 10, 2:22?am, webcomm wrote: > On Jan 9, 5:42?am, John Machin wrote: > > > And here's a little gadget that might help the diagnostic effort; it > > shows the archive size and the position of all the "magic" PKnn > > markers. In a "normal" uncommented archive, EndArchive_pos + 22 == > > archive_size. > > I ran the diagnostic gadget... > > archive size is 69888 > FileHeader at 0 > CentralDir at 43796 > EndArchive at 43846 Thanks. Would you mind spending a few minutes more on this so that we can see if it's a problem that can be fixed easily, like the one that Chris Mellon reported? The above output says that there are 43868 (43846 + 22) bytes of useable data. That leaves 69888 - 43868 = 26020 bytes of "comment" ... rather large for a comment. Have you run a virus scanner over this file? At the end is an updated version of the diagnostic gadget. It explores the "EndArchive" structure and the comment at the end, with a special check for all '\0' (as per Chris's bug report) and another for all blank. Please run it over your file and show us the results. Note: you may want to suppress the display of the first 100 bytes of comment if it turns out to be private data. Cheers, John 8<--- # zip_susser_v2.py import sys grimoire = [ ("FileHeader", "PK\003\004"), # magic number for file header ("DataDescriptor", "PK\x07\x08"), # see PKZIP APPNOTE (V) (C) ("CentralDir", "PK\001\002"), # magic number for central directory ("EndArchive", "PK\005\006"), # magic number for end of archive record ("EndArchive64", "PK\x06\x06"), # magic token for Zip64 header ("EndArchive64Locator", "PK\x06\x07"), # magic token for locator header ("ArchiveExtraData", "PK\x06\x08"), # APPNOTE (V) (E) ("DigitalSignature", "PK\x05\x05"), # APPNOTE (V) (F) ] f = open(sys.argv[1], 'rb') buff = f.read() f.close() blen = len(buff) print "archive size is", blen for magic_name, magic in grimoire: pos = 0 while pos < blen: pos = buff.find(magic, pos) if pos < 0: break print "%s at %d" % (magic_name, pos) pos += 4 # # find what is in the EndArchive struct # structEndArchive = "<4s4H2LH" # 9 [sic] items, end of archive, 22 bytes import struct posEndArchive = buff.find("PK\005\006") print "using posEndArchive =", posEndArchive assert 0 < posEndArchive < blen endArchive = struct.unpack(structEndArchive, buff [posEndArchive:posEndArchive+22]) print "endArchive:", repr(endArchive) endArchiveFieldNames = """ signature this_disk_num central_dir_disk_num central_dir_this_disk_num_entries central_dir_overall_num_entries central_dir_size central_dir_offset comment_size """.split() for name, value in zip(endArchiveFieldNames, endArchive): print "%33s : %r" % (name, value) # # inspect the comment # actual_comment_size = blen - 22 - posEndArchive expected_comment_size = endArchive[7] comment = buff[posEndArchive + 22:] print print "expected_comment_size:", expected_comment_size print "actual_comment_size:", actual_comment_size print "comment is all spaces:", comment == ' ' * actual_comment_size print "comment is all '\\0':", comment == '\0' * actual_comment_size print "comment (first 100 bytes):", repr(comment[:100]) 8<--- From invalid at invalid Fri Jan 9 17:23:28 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 16:23:28 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> <6spt2cF7n8nmU3@mid.uni-berlin.de> Message-ID: On 2009-01-09, Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > >> Marc 'BlackJack' Rintsch wrote: >> >>> def iter_max_values(blocks, block_count): >>> for i, block in enumerate(blocks): >>> histogram = defaultdict(int) >>> for byte in block: >>> histogram[byte] += 1 >>> >>> yield max((count, byte) >>> for value, count in histogram.iteritems())[1] >>> >> [snip] >> Would it be faster if histogram was a list initialised to [0] * 256? > > Don't know. Then for every byte in the 2??GiB we have to call `ord()`. > Maybe the speedup from the list compensates this, maybe not. > > I think that we have to to something with *every* byte of that really > large file *at Python level* is the main problem here. In C that's just > some primitive numbers. Python has all the object overhead. Using buffers or arrays of bytes instead of strings/lists would probably reduce the overhead quite a bit. -- Grant Edwards grante Yow! I've got an IDEA!! at Why don't I STARE at you visi.com so HARD, you forget your SOCIAL SECURITY NUMBER!! From steven.klass at gmail.com Fri Jan 9 17:30:30 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 14:30:30 -0800 (PST) Subject: redirecting stderr back.. Message-ID: Hi All, Can someone tell me how to redirect stderr back to the console once you've moved it? import os,sys se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) sys.stderr.write("Foobar\n") Foobar os.dup2(se, 2) cmds = os.popen("ls alaksjdf") sys.stderr.write("Foobar\n") Foobar Any ideas? Thanks From steven.klass at gmail.com Fri Jan 9 17:33:53 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 14:33:53 -0800 (PST) Subject: redirecting stderr back.. Message-ID: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Hi All, Can someone tell me how to redirect stderr back to the console once you've moved it? import os,sys se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) sys.stderr.write("Foobar\n") Foobar os.dup2(se, 2) cmds = os.popen("ls alaksjdf") sys.stderr.write("Foobar\n") Foobar Any ideas? Thanks From lists at cheimes.de Fri Jan 9 17:38:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jan 2009 23:38:41 +0100 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: rh0dium schrieb: > Hi All, > > Can someone tell me how to redirect stderr back to the console once > you've moved it? sys.stderr = sys.__stderr__ or better: orig_stderr = sys.stderr try: sys.stderr = open(...) ... finally: sys.stderr = orig_stderr Christian From robert.kern at gmail.com Fri Jan 9 17:42:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 09 Jan 2009 16:42:46 -0600 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: Christian Heimes wrote: > rh0dium schrieb: >> Hi All, >> >> Can someone tell me how to redirect stderr back to the console once >> you've moved it? > > sys.stderr = sys.__stderr__ > > or better: > > orig_stderr = sys.stderr > try: > sys.stderr = open(...) > ... > finally: > sys.stderr = orig_stderr He's not reassigning the sys.stderr object; he's fiddling with the underlying file descriptor. Steven, look at my code here for a mostly complete solution: http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/redir/ -- 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 bedouglas at earthlink.net Fri Jan 9 17:47:17 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 14:47:17 -0800 Subject: spawning pyhon apps... Message-ID: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> hi... toying with an idea.. trying to figure out a good/best way to spawn multiple python scripts from a parent python app. i'm trying to figure out how to determine when all child apps have completed, or to possibly determine if any of the child processes have died/halted.. parent app spawn child1 spawn child2 spawn child3 . . . spawn childn do i iterate through a os.waitpid(pid) for each pid of the child processes i create? is there another approach? code samples/tutorial...?? i've seen various approaches via google, but not just what i'm looking for.. thanks From lists at cheimes.de Fri Jan 9 17:52:17 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jan 2009 23:52:17 +0100 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: Robert Kern schrieb: > Christian Heimes wrote: >> rh0dium schrieb: >>> Hi All, >>> >>> Can someone tell me how to redirect stderr back to the console once >>> you've moved it? >> >> sys.stderr = sys.__stderr__ >> >> or better: >> >> orig_stderr = sys.stderr >> try: >> sys.stderr = open(...) >> ... >> finally: >> sys.stderr = orig_stderr > > He's not reassigning the sys.stderr object; he's fiddling with the > underlying file descriptor. I know that. I wanted to show him a better way than messing around with file descriptors. In Python one doesn't have to (and should not) alter the file descriptor of a standard stream. Python always uses sys.stderr to write to the standard error stream. Christian From ryandw at gmail.com Fri Jan 9 17:52:24 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:52:24 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> Message-ID: On Jan 9, 5:21?pm, John Machin wrote: > Thanks. Would you mind spending a few minutes more on this so that we > can see if it's a problem that can be fixed easily, like the one that > Chris Mellon reported? > Don't mind at all. I'm now working with a zip file with some dummy data I downloaded from the web service. You'll notice it's a smaller archive than the one I was working with when I ran zip_susser.py, but it has the same problem (whatever the problem is). It's the one I uploaded to http://webcomm.webfactional.com/htdocs/data.zip Here's what I get when I run zip_susser_v2.py... archive size is 1092 FileHeader at 0 CentralDir at 844 EndArchive at 894 using posEndArchive = 894 endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) signature : 'PK\x05\x06' this_disk_num : 0 central_dir_disk_num : 0 central_dir_this_disk_num_entries : 1 central_dir_overall_num_entries : 1 central_dir_size : 50 central_dir_offset : 844 comment_size : 0 expected_comment_size: 0 actual_comment_size: 176 comment is all spaces: False comment is all '\0': True comment (first 100 bytes): '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00' Not sure if you've seen this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864?hl=en# Thanks, Ryan From sjmachin at lexicon.net Fri Jan 9 18:07:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 15:07:10 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> Message-ID: <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> On Jan 10, 8:56?am, webcomm wrote: > On Jan 9, 4:12?pm, "Chris Mellon" wrote: > > > It would really help if you could post a sample file somewhere. > > Here's a sample with some dummy data from the web service:http://webcomm.webfactional.com/htdocs/data.zip > > That's the zip created in this line of my code... > f = open('data.zip', 'wb') Your original problem is identical to that already reported by Chris Mellon (gratuitous \0 bytes appended to the real archive contents). Here's the output of the diagnostic gadget that I posted a few minutes ago: .......................................................... C:\downloads>python zip_susser_v2.py data.zip archive size is 1092 FileHeader at 0 CentralDir at 844 EndArchive at 894 using posEndArchive = 894 endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) signature : 'PK\x05\x06' this_disk_num : 0 central_dir_disk_num : 0 central_dir_this_disk_num_entries : 1 central_dir_overall_num_entries : 1 central_dir_size : 50 central_dir_offset : 844 comment_size : 0 expected_comment_size: 0 actual_comment_size: 176 comment is all spaces: False comment is all '\0': True comment (first 100 bytes): '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00' ................................... > > If I open the file it contains as unicode in my text editor (EditPlus) > on Windows XP, there is ostensibly nothing wrong with it. ?It looks > like valid XML. Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as God^H^H^HGates intended: >>> buff = open('data', 'rb').read() >>> buff[:100] '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> \x00<\x00B\x0 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> \x000\x00.\x000\x000\x000\x000\x0 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< \x00S\x00t\x0 0a\x00t\x00' >>> buff[:100].decode('utf_16_le') u'0.0000>> > ?But if I return it to my browser with python+django, > there are bad characters every other character Please consider that we might have difficulty guessing what "return it to my browser with python+django" means. Show actual code. > > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... Yup, you've somehow pushed your utf_16_le-encoded data through some decoder that doesn't like '\x00' and is replacing it with U+FFFD whose name is (funnily enough) REPLACEMENT CHARACTER and whose meaning is "big fat Unicode version of the question mark". > > If I unzip it like this... > getzip('data.zip', ignoreable=30000) > ...using the function at...http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > ...then the bad characters are \x00 characters. Hmmm ... shouldn't make a difference how you extracted 'data' from 'data.zip'. Please consider reading the Unicode HOWTO at http://docs.python.org/howto/unicode.html Cheers, John From clp2 at rebertia.com Fri Jan 9 18:10:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 15:10:20 -0800 Subject: spawning pyhon apps... In-Reply-To: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> References: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> Message-ID: <50697b2c0901091510s3772b742wdd11b47a0f87a7a7@mail.gmail.com> On Fri, Jan 9, 2009 at 2:47 PM, bruce wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > spawn child1 > spawn child2 > spawn child3 > . > . > . > spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? Use the `subprocess` module's (http://docs.python.org/library/subprocess.html) Popen class to spawn the processes. Then use .wait() or .poll(), and .returncode on the Popen instances to check their exit status. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven.klass at gmail.com Fri Jan 9 18:10:48 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 15:10:48 -0800 (PST) Subject: redirecting stderr back.. References: Message-ID: <3fe1a82a-ff6b-40ce-9a60-c90096abe7d8@s1g2000prg.googlegroups.com> On Jan 9, 3:52?pm, Christian Heimes wrote: > Robert Kern schrieb: > > > > > Christian Heimes wrote: > >> rh0dium schrieb: > >>> Hi All, > > >>> Can someone tell me how to redirect stderr back to the console once > >>> you've moved it? > > >> sys.stderr = sys.__stderr__ > > >> or better: > > >> orig_stderr = sys.stderr > >> try: > >> ? ? sys.stderr = open(...) > >> ? ? ... > >> finally: > >> ? ? sys.stderr = orig_stderr > > > He's not reassigning the sys.stderr object; he's fiddling with the > > underlying file descriptor. > > I know that. I wanted to show him a better way than messing around with > file descriptors. In Python one doesn't have to (and should not) alter > the file descriptor of a standard stream. Python always uses sys.stderr > to write to the standard error stream. > > Christian Christian - it's not python that's the problem. Unfortunately the stuff I'm calling (outside of python) won't play nicely unless I mess with the FD's.. From google at mrabarnett.plus.com Fri Jan 9 18:13:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 23:13:20 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> Message-ID: <4967DA10.6080502@mrabarnett.plus.com> webcomm wrote: > On Jan 8, 8:39 pm, "James Mills" wrote: >> Send us a sample of this file in question... > > Here's a sample with some dummy data from the web service: > http://webcomm.webfactional.com/htdocs/data.zip > > That's the zip created in this line of my code... > f = open('data.zip', 'wb') > > If I open the file it contains as unicode in my text editor (EditPlus) > on Windows XP, there is ostensibly nothing wrong with it. It looks > like valid XML. But if I return it to my browser with python+django, > there are bad characters every other character > > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > If I unzip it like this... > getzip('data.zip', ignoreable=30000) > ...using Scott's function at... > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > ...then the bad characters are \x00 characters. > I can unzip it in Windows XP. The file within it (called "data") is XML encoded as UTF-16LE (2 bytes per character, low byte first), but without the initial byte order mark. Python's zipfile module says "BadZipfile: File is not a zip file". From steven.klass at gmail.com Fri Jan 9 18:17:48 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 15:17:48 -0800 (PST) Subject: redirecting stderr back.. References: Message-ID: On Jan 9, 3:42?pm, Robert Kern wrote: > Christian Heimes wrote: > > rh0dium schrieb: > >> Hi All, > > >> Can someone tell me how to redirect stderr back to the console once > >> you've moved it? > > > sys.stderr = sys.__stderr__ > > > or better: > > > orig_stderr = sys.stderr > > try: > > ? ? sys.stderr = open(...) > > ? ? ... > > finally: > > ? ? sys.stderr = orig_stderr > > He's not reassigning the sys.stderr object; he's fiddling with the underlying > file descriptor. > > Steven, look at my code here for a mostly complete solution: > > ? ?http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/redir/ > > -- > 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 Interesting stuff - but the documentation is a bit lacking - but I think I can figure it out. From jason.scheirer at gmail.com Fri Jan 9 18:19:26 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 15:19:26 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> On Jan 9, 2:47?pm, "bruce" wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > ?spawn child1 > ?spawn child2 > ?spawn child3 > ?. > ?. > ?. > ?spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? > > i've seen various approaches via google, but not just what i'm looking for.. > > thanks Investigate the subprocess module, you probably want Popen objects. You can do a poll loop like my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] while any(popenobject.statuscode is None for popenobject in my_popenobjects): time.sleep(0.25) If your tasks are more like function calls and less like shell scripts, then investigate writing your python as an importable module and use the multiprocessing module, which will do threading/ subprocessing for you. From gagsl-py2 at yahoo.com.ar Fri Jan 9 18:19:33 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 09 Jan 2009 21:19:33 -0200 Subject: multiprocessing vs thread performance References: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Message-ID: En Wed, 07 Jan 2009 23:05:53 -0200, James Mills escribi?: >> Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch >> of >> good example for it? I am trying to break a loop to run it over multiple >> core in a system. And I need to return an integer value as the result >> of the >> process an accumulate all of them. the examples that I found there is no >> return for the process. > > You communicate with the process in one of several > ways: > * Semaphores > * Locks > * PIpes The Pool class provides a more abstract view that may be better suited in this case. Just create a pool, and use map_async to collect and summarize the results. import string import multiprocessing def count(args): (lineno, line) = args print "This is %s, processing line %d\n" % ( multiprocessing.current_process().name, lineno), result = dict(letters=0, digits=0, other=0) for c in line: if c in string.letters: result['letters'] += 1 elif c in string.digits: result['digits'] += 1 else: result['other'] += 1 # just to make some "random" delay import time; time.sleep(len(line)/100.0) return result if __name__ == '__main__': summary = dict(letters=0, digits=0, other=0) def summary_add(results): # this is called with a list of results for result in results: summary['letters'] += result['letters'] summary['digits'] += result['digits'] summary['other'] += result['other'] # count letters on this same script f = open(__file__, 'r') pool = multiprocessing.Pool(processes=6) # invoke count((lineno, line)) for each line in the file pool.map_async(count, enumerate(f), 10, summary_add) pool.close() # no more jobs pool.join() # wait until done print summary -- Gabriel Genellina From mdw at distorted.org.uk Fri Jan 9 18:40:07 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 23:40:07 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > If one accepts that there are a "lot" of people who post in here that > clearly are surprised by Python's assignment semantics, But one should not accept that. One might accept that there are many who post who claim that they are surprised by Python's assignment semantics. Such people are wrong, however, since what they are surprised by is Python's data model, and one reason that they are surprised by Python's data model is because it's not actually explained very well. > and further appear to expect assignment to have copy-like semantics, This expectation is justified and, indeed, satisfied. Python does, most definitely, copy on assignment. What it copies is references, however. This might be clearer if the data model were explained better. As an aside, I don't notice anywhere near as much confusion in Lisp and Scheme groups, which might be surprising since Lisp and Scheme have precisely the same data model, argument passing convention, and assignment semantics, as Python has. There are many possible explanations: * The Lisp and Scheme communities are smaller. This is certainly true. But it wouldn't explain what appears to be a disproportionate level of confusion on the topic among Python beginners. * Individuals in the Lisp and Scheme communities are cleverer and/or more widely experienced. One might make an argument that this is true and a result of the relative community sizes -- basically a result of self-selection. But instead I'll reject this as an explanation. It's arrogant and unproven. * The Lisp and Scheme communities make a concerted effort to explain their data model clearly and precisely. They accept that it's actually quite complicated and, rather than pretend that it isn't, explain the complexity and the benefits it brings that make the complexity worthwhile. I think this is the likely one. > then where is that expectation coming from? > How would anyone develop that expectation if (from a different post in > this thread), "[Python's] idea of assignment is the same as anyone > else's." Because they've fundamentally misunderstood the data model. The very fact that their confusion is ascribed to the wrong thing is strongly indicative of this. > If you maintain that reference-like assignment is very common and > something every programmer is accustomed to, then where are they > getting the copy-like assignment expectations from? But it's not just assignment that deals with references. It's argument passing and storage of compound data as well. (See PLR 3.1.) They expect that assignment copies stuff, because that's what assignment does. Everywhere that I can think of -- except C++, which leaves assignment semantics in hands of the programmer. What they're confused about is what, precisely, it is that gets copied. And that, really, is a result of an inadequate understanding of the data model. > I agree that most of the time, when one is using large (memory) > composite "objects", and one needs to pass, or access them by > different names, one will often use references to do so in order to > avoid expensive copies or to get desired "shared" behavior. But (with > the exception of C arrays [*1]), doing so requires some special syntax > in all the languages I mentioned (AFAIK). Ummm... you mentioned C, C++, `Python, Java, REALbasic, .NET'. Well, C we've dealt with. C++ is weird. Python we all know, and is the main subject of the argument. REALbasic I don't know at all, but BASICs traditionally represent data fairly directly (rather than via references) so will largely be like C. .NET isn't a language at all: rather, it's a virtual machine, runtime system, class library and family of languages each of which may have idiosyncratic semantics. Which leaves Java. Java divides the world into `primitive' and `reference' types (4.1). The former are represented directly; the latter have a pointer to the true data as immediate representation. But observe that Java's primitive types are integer types (including its misnamed `char'), floating-point types, and booleans. Equivalent objects of all of these are immutable in Python -- and there is no observable difference (unless exposed by an operator like `is' or the `id' built-in) between a directly represented object and an /immutable/ object represented by reference. (I've no doubt that the original language designers were aware of this equivalence, so it's a mystery to me precisely why they specified the language as they did rather than leaving the messy business of boxing and unboxing primitive values to the compiler, which, given Java's mandatory type annotations, should have found the job trivial.) > So it still seems to me that this is a likely explanation to why there > is frequent misunderstanding of Python's assignments, and why > responding to such misunderstandings with, "Python's assignments are > the same as other languages'", is at best not helpful. That's why I'm not just saying that assignment is the same. I'm also saying that the data model is most definitely not the same as C. > I have often wished that C handled arrays the same way it does > structs. I am sure that the pointer-array pseudo-equivalence seemed > like a very clever idea at the time but I wonder if Dennis Richie ever > had second thoughts about it. Probably. But I think the idea was actually inherited from BCPL, via B. In BCPL, memory is divided into words. Depending on which operator you use, you can treat a particular word as an integer, a floating-point number, or a pointer. An array in BCPL is represented as a pointer to its first element -- always -- and you index it by an expression of the form p!i (a notation inherited by BBC BASIC and Haskell of all things). The array->pointer decay is a compromise position between the BCPL notion of array-as-pointer and the desire to allocate such things with automatic storage duration and have sizeof and so on work properly. -- [mdw] From bedouglas at earthlink.net Fri Jan 9 18:43:25 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 15:43:25 -0800 Subject: spawning pyhon apps... In-Reply-To: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> Message-ID: <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> hi jason.... forgive me... but in your sample: my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] are you spawning 'foo.py' 10 times? that can't be right! so just what is "foo.py" used for? what am i missing... it looks like the my_popenobjects array is iterated through to check the statuscode. is the statuscode the value that would be returned from a child python script via something like "return(2)".... i've seen mention of os.waitpid(..) does this play into waiting for child processes to complete, or determine if they've terminated?? thanks -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Jason Scheirer Sent: Friday, January 09, 2009 3:19 PM To: python-list at python.org Subject: Re: spawning pyhon apps... On Jan 9, 2:47?pm, "bruce" wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > ?spawn child1 > ?spawn child2 > ?spawn child3 > ?. > ?. > ?. > ?spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? > > i've seen various approaches via google, but not just what i'm looking for.. > > thanks Investigate the subprocess module, you probably want Popen objects. You can do a poll loop like my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] while any(popenobject.statuscode is None for popenobject in my_popenobjects): time.sleep(0.25) If your tasks are more like function calls and less like shell scripts, then investigate writing your python as an importable module and use the multiprocessing module, which will do threading/ subprocessing for you. -- http://mail.python.org/mailman/listinfo/python-list From nad at acm.org Fri Jan 9 18:46:28 2009 From: nad at acm.org (Ned Deily) Date: Fri, 09 Jan 2009 15:46:28 -0800 Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: In article <07832575-9b98-4a03-a181-4470a5a00fd6 at 35g2000pry.googlegroups.com>, googler.1.webmaster at spamgourmet.com wrote: > hm... any ideas? Have you tried specifying one of the universal SDKs, i.e. /Developer/SDKs/MacOSX10.n.sdk? That's what the "official" python.org builds do. The build script for the batteries-included installer is in the source tar ball at Mac/BuildScript/build-installer.py. FWIW, I made a universal (4-way) batteries-included framework build for 2.6 on 10.5 with the following patch to that script: --- build-installer.py.bak 2008-12-17 20:02:59.000000000 -0800 +++ build-installer.py 2008-12-17 23:18:57.000000000 -0800 @@ -1,12 +1,9 @@ -#!/usr/bin/python2.3 +#!/usr/bin/python2.5 """ This script is used to build the "official unofficial" universal build on -Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its +Mac OS X. It requires Mac OS X 10.5, Xcode 3.0 and the 10.5u SDK to do its work. -Please ensure that this script keeps working with Python 2.3, to avoid -bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) - Usage: see USAGE variable in the script. """ import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd @@ -65,10 +62,10 @@ DEPSRC = os.path.expanduser('~/Universal/other-sources') # Location of the preferred SDK -SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" +SDKPATH = "/Developer/SDKs/MacOSX10.5.sdk" #SDKPATH = "/" -ARCHLIST = ('i386', 'ppc',) +ARCHLIST = ('i386', 'ppc', 'x86_64', 'ppc64', ) # Source directory (asume we're in Mac/BuildScript) SRCDIR = os.path.dirname( @@ -630,7 +627,7 @@ version = getVersion() print "Running configure..." - runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( + runCommand("%s -C --enable-framework --enable-universalsdk=%s --with-universal-archs=all LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1])) @@ -1017,7 +1014,7 @@ parseOptions() checkEnvironment() - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' + os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.5' if os.path.exists(WORKDIR): shutil.rmtree(WORKDIR) -- Ned Deily, nad at acm.org From bhood37 at hotmail.com Fri Jan 9 18:50:26 2009 From: bhood37 at hotmail.com (Uberman) Date: Fri, 09 Jan 2009 16:50:26 -0700 Subject: Why can't I store a DLL in a module library Zip file? Message-ID: I'm using Python 2.5.1, and I'm trying to use the module library as a Zip file (for example, with python25_d.dll, the module library file would be called python25_d.zip). This works for the basic modules that come with Python (os, sys, site, etc.), and it even seems to work when I place my own Python-based modules within the Zip file (e.g., my_module.py). My Python modules are found within the library Zip file. However, my Python module is dependent upon a SWIG-generated shared library, which also has it's own Python module. When placed into the Zip file, the SWIG Python module is found, but the shared library file (the compiled C shared library) is not. I've stepped through the Python code to try and see what's happening, but when it comes to looking in the Zip file (python25_d.zip) for this shared library (*.pyd), it won't find it. When I place all the files in the same folder as the executable (outside the python25_d.zip) file, they are found by the run-time system, and everything is happy. I've also tried a properly constructed 'site-package' within the Zip file, with the SWIG-generated files contained within, but that doesn't work either. It's almost like shared libraries are disallowed from the module library Zip format. Is there a trick, or some special location where it needs to be placed? Any help with this would be appreciated. Thanks. From google at mrabarnett.plus.com Fri Jan 9 18:52:02 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 23:52:02 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: <4967DA10.6080502@mrabarnett.plus.com> References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> <4967DA10.6080502@mrabarnett.plus.com> Message-ID: <4967E322.1000909@mrabarnett.plus.com> MRAB wrote: > webcomm wrote: >> On Jan 8, 8:39 pm, "James Mills" wrote: >>> Send us a sample of this file in question... >> >> Here's a sample with some dummy data from the web service: >> http://webcomm.webfactional.com/htdocs/data.zip >> >> That's the zip created in this line of my code... >> f = open('data.zip', 'wb') >> >> If I open the file it contains as unicode in my text editor (EditPlus) >> on Windows XP, there is ostensibly nothing wrong with it. It looks >> like valid XML. But if I return it to my browser with python+django, >> there are bad characters every other character >> >> If I unzip it like this... >> popen("unzip data.zip") >> ...then the bad characters are 'FFFD' characters as described and >> pictured here... >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> >> If I unzip it like this... >> getzip('data.zip', ignoreable=30000) >> ...using Scott's function at... >> http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 >> ...then the bad characters are \x00 characters. >> > I can unzip it in Windows XP. The file within it (called "data") is XML > encoded as UTF-16LE (2 bytes per character, low byte first), but without > the initial byte order mark. Python's zipfile module says "BadZipfile: > File is not a zip file". > If I strip off all but the last 4 zero-bytes then the zipfile module can open it: decoded = base64.b64decode(datum) five_zeros = chr(0) * 5 while decoded.endswith(five_zeros): decoded = decoded[ : -1] f = open('data.zip', 'wb') f.write(decoded) f.close() x = zipfile.ZipFile('data.zip', 'r') From clp2 at rebertia.com Fri Jan 9 18:53:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 15:53:21 -0800 Subject: spawning pyhon apps... In-Reply-To: <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> References: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> Message-ID: <50697b2c0901091553s73cb1f82id4c196fb93e4527c@mail.gmail.com> On Fri, Jan 9, 2009 at 3:43 PM, bruce wrote: > hi jason.... > > forgive me... but in your sample: > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! Indeed, it probably ought to be (note the 2nd pair of brackets): my_popenobjects = [subprocess.Popen(["foo.py", "--filename=file%i.txt"%x]) for x in xrange(10)] > so just what is "foo.py" used for? what am i missing... It's the name of the program you want to run. In this case, it happens to be a Python script. > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... It's the POSIX exit code of the program (i.e. what int you return from main() in a C program, or what you pass to sys.exit() in Python) > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? Don't know specifically, but that's another, lower-level API. The `subprocess` module is superior. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jason.scheirer at gmail.com Fri Jan 9 18:59:24 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 15:59:24 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <4337c89e-f623-4dd5-b9a7-be66ca107f43@l39g2000yqn.googlegroups.com> On Jan 9, 3:43?pm, "bruce" wrote: > hi jason.... > > forgive me... but in your sample: > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > ? ? ? ? %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! > so just what is "foo.py" used for? what am i missing... > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... > > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:19 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 2:47?pm, "bruce" wrote: > > hi... > > > toying with an idea.. trying to figure out a good/best way to spawn > multiple > > python scripts from a parent python app. i'm trying to figure out how to > > determine when all child apps have completed, or to possibly determine if > > any of the child processes have died/halted.. > > > parent app > > ?spawn child1 > > ?spawn child2 > > ?spawn child3 > > ?. > > ?. > > ?. > > ?spawn childn > > > do i iterate through a os.waitpid(pid) for each pid of the child processes > i > > create? > > > is there another approach? code samples/tutorial...?? > > > i've seen various approaches via google, but not just what i'm looking > for.. > > > thanks > > Investigate the subprocess module, you probably want Popen objects. > You can do a poll loop like > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > > while any(popenobject.returncode is None for popenobject in > my_popenobjects): > ? time.sleep(0.25) > > If your tasks are more like function calls and less like shell > scripts, then investigate writing your python as an importable module > and use the multiprocessing module, which will do threading/ > subprocessing for you. > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. Foo.py is the hypothetical Python script you want to run in a subprocess. In this example, I have an external shell script named foo.py, and I am indeed spawning 10 copies of it, each with a second argument that varies (foo.py --filename=file0.txt, foo.py -- filename=file1.txt, ... foo.py --filename=file9.txt). You don't need os.waitpid() with a Popen object, there is a Popen.wait() method you can call which will accomplish the exact same thing. I'm polling the Popen.returncode for each process' return code (which is the numeric code a process returns when it finishes, like sys.exit(x) or return, or gives None if it's not done yet. What this sample is doing is opening 10 copies of the script and running them in parallel, if you want to run it is serial then you can do a simple for loop and .wait() on each: for cmd in ('a', 'b', 'c'): sp = subprocess.Popen(cmd) sp.wait() print "Command %r completed with status %i" % (cmd, sp.returncode) I'm still not 100% sure what you're trying to accomplish. What is the exact problem you are wishing to solve? From martin at v.loewis.de Fri Jan 9 19:03:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 10 Jan 2009 01:03:11 +0100 Subject: Why can't I store a DLL in a module library Zip file? In-Reply-To: References: Message-ID: <4967E5BF.3070707@v.loewis.de> > It's almost like shared libraries are disallowed from the module > library Zip format. Correct. That's a limitation of the Windows operating system, which can load DLLs only from plain, regular files. Python can load .py files from zip files because it implements the loading itself. For DLL loading, it must use the OS routines, which just don't look into zipfiles. Regards, Martin From bedouglas at earthlink.net Fri Jan 9 19:07:36 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 16:07:36 -0800 Subject: spawning pyhon apps... In-Reply-To: <4337c89e-f623-4dd5-b9a7-be66ca107f43@l39g2000yqn.googlegroups.com> Message-ID: <07b801c972b7$73cbfda0$0301a8c0@tmesa.com> thanks jason.... or i could also, simply iterate through a loop of the names of the "child processes" i want to spawn, using the names in the subprocess.popen, and then proceeding with the rest of your example.. question though... if i have a child app that's hanging.. how do i kill it. or is this getting into the aspect of using interprocess pipes, where if the parent isn't getting a 'live ping' via the pipe back from the child after a certain amount of time... it could kill the child... thoughts/comments... thanks -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Jason Scheirer Sent: Friday, January 09, 2009 3:59 PM To: python-list at python.org Subject: Re: spawning pyhon apps... On Jan 9, 3:43?pm, "bruce" wrote: > hi jason.... > > forgive me... but in your sample: > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > ? ? ? ? %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! > so just what is "foo.py" used for? what am i missing... > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... > > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:19 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 2:47?pm, "bruce" wrote: > > hi... > > > toying with an idea.. trying to figure out a good/best way to spawn > multiple > > python scripts from a parent python app. i'm trying to figure out how to > > determine when all child apps have completed, or to possibly determine if > > any of the child processes have died/halted.. > > > parent app > > ?spawn child1 > > ?spawn child2 > > ?spawn child3 > > ?. > > ?. > > ?. > > ?spawn childn > > > do i iterate through a os.waitpid(pid) for each pid of the child processes > i > > create? > > > is there another approach? code samples/tutorial...?? > > > i've seen various approaches via google, but not just what i'm looking > for.. > > > thanks > > Investigate the subprocess module, you probably want Popen objects. > You can do a poll loop like > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > > while any(popenobject.returncode is None for popenobject in > my_popenobjects): > ? time.sleep(0.25) > > If your tasks are more like function calls and less like shell > scripts, then investigate writing your python as an importable module > and use the multiprocessing module, which will do threading/ > subprocessing for you. > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. Foo.py is the hypothetical Python script you want to run in a subprocess. In this example, I have an external shell script named foo.py, and I am indeed spawning 10 copies of it, each with a second argument that varies (foo.py --filename=file0.txt, foo.py -- filename=file1.txt, ... foo.py --filename=file9.txt). You don't need os.waitpid() with a Popen object, there is a Popen.wait() method you can call which will accomplish the exact same thing. I'm polling the Popen.returncode for each process' return code (which is the numeric code a process returns when it finishes, like sys.exit(x) or return, or gives None if it's not done yet. What this sample is doing is opening 10 copies of the script and running them in parallel, if you want to run it is serial then you can do a simple for loop and .wait() on each: for cmd in ('a', 'b', 'c'): sp = subprocess.Popen(cmd) sp.wait() print "Command %r completed with status %i" % (cmd, sp.returncode) I'm still not 100% sure what you're trying to accomplish. What is the exact problem you are wishing to solve? -- http://mail.python.org/mailman/listinfo/python-list From sjmachin at lexicon.net Fri Jan 9 19:11:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 16:11:10 -0800 (PST) Subject: Problem with -3 switch References: Message-ID: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> On Jan 10, 6:58?am, Carl Banks wrote: > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > Aivar Annamaa wrote: > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > >> switch only points out problems that the 2to3 converter tool can't > > > >> automatically fix. Changing print to print() on the other hand is > > > >> easily fixed by 2to3. > > > > >> Cheers, > > > >> Chris > > > > > I see. > > > > So i gotta keep my own discipline with print() then :) > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > it as Python 3.x code. > > > > regards > > > ?Steve > > > And mind you, if you follow that route, you are programming in a > > mightily crippled language. > > How do you figure? > > I expect that it'd be a PITA in some cases to use the transitional > dialect (like getting all your Us in place), but that doesn't mean the > language is crippled. What is this "transitional dialect"? What does "getting all your Us in place" mean? Steve & Cliff are talking about the rather small subset of Python that is not only valid syntax in both 2.x and 3.x but also has the same meaning in 2.x and 3.x. > > >?It's about as bad as trying to write > > cross-browser CSS. ?Don't put yourself through that pain if you don't > > have to. > > Have you tried doing that, or are you imagining how it will be? ?I'm > curious about people's actual experiences. I maintain two packages, xlrd which supports 2.1 to 2.6, and xlwt which supports 2.3 to 2.6. I've done suck-it-and-see trials on being able to support 3.x as well from the same codebase, and it's turned out reasonably well. xlrd already had a module called timemachine which caters for version- dependent stuff. Extending this to 3.x was more a voyage of discovery than a PITA. timemachine.py is "crippled" in Cliff's sense, in that because I'm the principal user I need to make it robust and idiot-proof, so it has been written under the following constraints: (1) not one copy of timemachine.py for 2.1, one for 2.2, one for 2.3, ... etc; just one copy, period. (2) means that it must use syntax that's valid in all supported versions (3) must be able to be processed by 2to3 without causing a commotion (4) the original version and the 2to3 output must have the same effect when imported by 3.x. So one ends up with code like: glued = BYTES_NULL.join(list_of_pieces_of_a_binary_file) which is supported by timemachine definitions like BYTES_NULL = bytes(0) # 3.x ... note b'' is not valid in 2.x BYTES_NULL = '' # 2.x BYTES_NULL.join() may be ugly, but it's not crippled, it's fully functional, and it would be very easy to find and change in the future in two possible scenarios (1) drop 2.x support (2) change codebase to be mostly 3.x, support 2.x by a (mythical, hoped-for) 3to2 mechanism. > Problem is, a lot of people use the "bang at it with a hammer till it > works" approach to programming, and really have no shame when it comes > to engaging in questionable practices like relying on accidental side > effects, rather than taking the time to try to program robustly. ?I > expect people with that style of programming will have many more > issues with the transition. Those with many more issues are likely to be those who don't have adequate tests and/or can't debug their way out of a wet paper bag -- could well be we're talking about the same bunch :-) Cheers, John From joe at strout.net Fri Jan 9 19:11:12 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 17:11:12 -0700 Subject: why cannot assign to function call In-Reply-To: References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <4967E7A0.8050502@strout.net> Mark Wooding wrote: > As an aside, I don't notice anywhere near as much confusion in Lisp and > Scheme groups, which might be surprising since Lisp and Scheme have > precisely the same data model, argument passing convention, and > assignment semantics, as Python has. Nor is there anywhere near as much confusion in the REALbasic community (with which I'm most familiar), which also has the same semantics for reference types (which in RB is everything except numbers, colors, and Boolean). Apparently there is occasionally a little confusion in the Java community, but it rarely reaches the sillyness proportions seen here: > * The Lisp and Scheme communities are smaller. This is certainly > true. But it wouldn't explain what appears to be a disproportionate > level of confusion on the topic among Python beginners. > > * Individuals in the Lisp and Scheme communities are cleverer and/or > more widely experienced. One might make an argument that this is > true and a result of the relative community sizes -- basically a > result of self-selection. But instead I'll reject this as an > explanation. It's arrogant and unproven. > > * The Lisp and Scheme communities make a concerted effort to explain > their data model clearly and precisely. They accept that it's > actually quite complicated and, rather than pretend that it isn't, > explain the complexity and the benefits it brings that make the > complexity worthwhile. I think this is the likely one. That's a nice way of putting it. I might go a step further and say that there is a small but vocal portion of the Python community that insists on confounding the issue by claiming that Python's assignment and parameter-passing conventions are different from other languages. (Which, of course, requires one's head to be firmly in the sand with regard to the basic fact that Python variables contain references, not objects.) > But it's not just assignment that deals with references. It's argument > passing and storage of compound data as well. (See PLR 3.1.) > > They expect that assignment copies stuff, because that's what assignment > does. Everywhere that I can think of -- except C++, which leaves > assignment semantics in hands of the programmer. What they're confused > about is what, precisely, it is that gets copied. And that, really, is > a result of an inadequate understanding of the data model. I have nothing to add to this. It just seem well worth quoting. :) >> I agree that most of the time, when one is using large (memory) >> composite "objects", and one needs to pass, or access them by >> different names, one will often use references to do so in order to >> avoid expensive copies or to get desired "shared" behavior. But (with >> the exception of C arrays [*1]), doing so requires some special syntax >> in all the languages I mentioned (AFAIK). > > Ummm... you mentioned C, C++, `Python, Java, REALbasic, .NET'. No, actually, that was me. rurpy's list was something like C, FORTRAN, Perl, and VBA. > Well, C we've dealt with. C++ is weird. Python we all know, and is the > main subject of the argument. REALbasic I don't know at all, but BASICs > traditionally represent data fairly directly (rather than via > references) so will largely be like C. Not REALbasic. It's a very modern language with semantics pretty much identical to Java. Simple types (numbers, colors, Booleans) are stored directly; all other types (including strings, objects, and arrays) are stored on the heap and accessed via references. > .NET isn't a language at all: > rather, it's a virtual machine, runtime system, class library and family > of languages each of which may have idiosyncratic semantics. But they don't, AFAIK -- they all have the same semantics; only the surface syntax differs. And those semantics are the same as REALbasic and Java. See for some side-by-side comparisons. > Which leaves Java. Java divides the world into `primitive' and > `reference' types (4.1). The former are represented directly; the > latter have a pointer to the true data as immediate representation. Right -- a very common pattern among modern languages. >> So it still seems to me that this is a likely explanation to why there >> is frequent misunderstanding of Python's assignments, and why >> responding to such misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > That's why I'm not just saying that assignment is the same. I'm also > saying that the data model is most definitely not the same as C. Technically true, in that pointers in C require some special syntax, but the common idiom is to hide this away by defining a new type: typedef Foo* FooPtr; Now, for any code using the "FooPtr" type, the data model is the same as Python (or as Java, RB, .NET, etc., again for code that's using only reference types). Best, - Joe From jason.scheirer at gmail.com Fri Jan 9 19:11:46 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 16:11:46 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <045737d6-e44c-4f1f-b79e-d87f2cbc7d72@f11g2000vbf.googlegroups.com> On Jan 9, 4:07?pm, "bruce" wrote: > thanks jason.... > > or i could also, simply iterate through a loop of the names of the "child > processes" i want to spawn, using the names in the subprocess.popen, and > then proceeding with the rest of your example.. > > question though... if i have a child app that's hanging.. how do i kill it. > > or is this getting into the aspect of using interprocess pipes, where if the > parent isn't getting a 'live ping' via the pipe back from the child after a > certain amount of time... it could kill the child... > > thoughts/comments... > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:59 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 3:43?pm, "bruce" wrote: > > hi jason.... > > > forgive me... but in your sample: > > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > > ? ? ? ? %i.txt"%x) for x in xrange(10)] > > are you spawning 'foo.py' 10 times? that can't be right! > > so just what is "foo.py" used for? what am i missing... > > > it looks like the my_popenobjects array is iterated through to check the > > statuscode. is the statuscode the value that would be returned from a > child > > python script via something like "return(2)".... > > > i've seen mention of os.waitpid(..) does this play into waiting for child > > processes to complete, or determine if they've terminated?? > > > thanks > > > -----Original Message----- > > From: python-list-bounces+bedouglas=earthlink.... at python.org > > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > > Of Jason Scheirer > > Sent: Friday, January 09, 2009 3:19 PM > > To: python-l... at python.org > > Subject: Re: spawning pyhon apps... > > > On Jan 9, 2:47?pm, "bruce" wrote: > > > hi... > > > > toying with an idea.. trying to figure out a good/best way to spawn > > multiple > > > python scripts from a parent python app. i'm trying to figure out how to > > > determine when all child apps have completed, or to possibly determine > if > > > any of the child processes have died/halted.. > > > > parent app > > > ?spawn child1 > > > ?spawn child2 > > > ?spawn child3 > > > ?. > > > ?. > > > ?. > > > ?spawn childn > > > > do i iterate through a os.waitpid(pid) for each pid of the child > processes > > i > > > create? > > > > is there another approach? code samples/tutorial...?? > > > > i've seen various approaches via google, but not just what i'm looking > > for.. > > > > thanks > > > Investigate the subprocess module, you probably want Popen objects. > > You can do a poll loop like > > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > > %i.txt"%x) for x in xrange(10)] > > > while any(popenobject.returncode is None for popenobject in > > my_popenobjects): > > ? time.sleep(0.25) > > > If your tasks are more like function calls and less like shell > > scripts, then investigate writing your python as an importable module > > and use the multiprocessing module, which will do threading/ > > subprocessing for you. > > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. > > Foo.py is the hypothetical Python script you want to run in a > subprocess. In this example, I have an external shell script named > foo.py, and I am indeed spawning 10 copies of it, each with a second > argument that varies (foo.py --filename=file0.txt, foo.py -- > filename=file1.txt, ... foo.py --filename=file9.txt). You don't need > os.waitpid() with a Popen object, there is a Popen.wait() method you > can call which will accomplish the exact same thing. I'm polling the > Popen.returncode for each process' return code (which is the numeric > code a process returns when it finishes, like sys.exit(x) or return, > or gives None if it's not done yet. What this sample is doing is > opening 10 copies of the script and running them in parallel, if you > want to run it is serial then you can do a simple for loop and .wait() > on each: > > for cmd in ('a', 'b', 'c'): > ? sp = subprocess.Popen(cmd) > ? sp.wait() > ? print "Command %r completed with status %i" % (cmd, sp.returncode) > > I'm still not 100% sure what you're trying to accomplish. What is the > exact problem you are wishing to solve? > --http://mail.python.org/mailman/listinfo/python-list > > Yes, so to open your processes you can loop over a list of commands and create new subprocess.Popen(cmd) objects for each. Everything is explained: http://docs.python.org/library/subprocess.html#popen-objects You can do .terminate() to kill a process that may be hanging, you can get the .stdout and poll on its .read() to see if it's still putting anything out to the console. From rurpy at yahoo.com Fri Jan 9 19:21:27 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 16:21:27 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >>> I never claimed that you *couldn't* have copy semantics in C; you can do >>> almost anything you want in C (or C++). But the *normal* usage of an >>> array is via a pointer, in which case the semantics are exactly the same >>> as in Python, Java, REALbasic, .NET, etc. >> >> Arrays are the only datatype in C that don't use >> copy-like assignment. Everything else does. > > No, arrays are just one reference type; pointers are another (and in > most ways, these are the same thing). Pointers are passed and assigned by value, just as other types (disputedly except arrays) are. One can then use that pointer to manually effect pass-(the-value-pointed-to)-by-reference, or sharing, etc. > When dealing with objects in C++, > one routinely handles them with pointers, so that's the use case which > is analogous to Python -- all the value types can be ignored for the > sake of comparison. (C is not an OOP language, of course, but even > there, all but the most trivial of structs are usually allocated on the > heap and passed around via pointers, just like in C++, Java, .NET, RB, > and Python.) In C (you have to explicitly ask for a reference (pointer) to something (other than arrays) if you want to use/pass a reference to something. If you simply use the name, you get by-value semantics. >>> Ah. OK then, I guess I missed you're point. You're absolutely right; >>> many languages have both reference types and value types. Python is a >>> bit unusual in that it has only reference types. I would have picked a >>> different example to illustrate that, but it's true nonetheless. >> >> If one accepts that there are a "lot" of people >> who post in here that clearly are surprised by >> Python's assignment semantics, and further appear >> to expect assignment to have copy-like semantics, >> then where is that expectation coming from? > > I think it comes from people stumbling across posts in this forum > claiming that Python has unusual assignment semantics. I wish people > would stop saying that, as it causes a lot of confusion. > >> How would anyone develop that expectation if (from >> a different post in this thread), "[Python's] idea >> of assignment is the same as anyone else's." > > I can think of two ways: > > 1. They're new to programming in general, and would have had the same > expectation for any other language. OR, IIRC, Someone posted here that his experience was that 12-year old kids (presumably without programming experience) had no problem with Python and references when described as "names given to an object". (From memory, can't locate the post right now.) > 2. They already understand some other language, and then they come here > and read wild claims that Python's assignment and parameter-passing > semantics are different from other languages. Duped by this claim, they > conclude that, if it's unlike other languages, then Python must have > copy semantics. I have seen no evidence of that. If it were true I would expect at least some posts to refer to reading those "wild claims". >> If you maintain that reference-like assignment >> is very common and something every programmer is >> accustomed to, then where are they getting the >> copy-like assignment expectations from? > > Reference-like assignment IS very common (see > ). So, see above. > >> I agree that most of the time, when one is using >> large (memory) composite "objects", and one needs >> to pass, or access them by different names, one will >> often use references to do so in order to avoid >> expensive copies or to get desired "shared" behavior. > > Right. > >> But (with the exception of C arrays [*1]), doing so >> requires some special syntax in all the languages I >> mentioned (AFAIK). > > Whether you consider it "special" or not, pointers are extremely common > in C. Even more so in C++, which is the closest thing to an OOP > language in the list of moldy languages you mentioned. Non-special is "b = a". > You also mentioned VBA -- if that's anything like VB, it does NOT > require any special syntax; a variable is a reference type if its > declared type is a class or string, and a simple type if it's anything > else (just like in .NET, Java, and REALbasic). It (mercifully) been a long time since I've used VB but the VB code I posted does run, and does exhibit by-value assignment behavior. My faint recollection is that if you want to assign a reference you cannot write, "b = a" but must instead write "set b = a". "b = a" assigns by value. In Perl it is definitely true that you different syntax: @a = (1,2,3) @b = @a # Copy $b = \@a # Reference C is the same way for everything (including pointers) except arrays: struct {...} foo; foo a, b *bp; b = a; # Copy bp = &a; # Reference >> So it still seems to me that this is a likely >> explanation to why there is frequent misunderstanding >> of Python's assignments, and why responding to such >> misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > I don't think so. More likely, people are being confused by the claim > that Python's assignments are NOT like other languages, when in fact > they are. It may be one can make a technical case that assignment is the same, but the reason I posted the code and results, was because the behavior of "=" in them produces clearly different results that "=" in Python. If you want to then say to someone, "ignore those different results, '=' works exactly the same", all I can say is good luck. I will look forward to continuing to see weekly questions on this list. :-) From mdw at distorted.org.uk Fri Jan 9 19:24:53 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 00:24:53 +0000 (UTC) Subject: spawning pyhon apps... References: Message-ID: bruce wrote: > toying with an idea.. trying to figure out a good/best way to spawn > multiple python scripts from a parent python app. i'm trying to figure > out how to determine when all child apps have completed, or to > possibly determine if any of the child processes have died/halted.. You don't say what platform you're using, but you mention os.waitpid so I'll randomly assume it's Unix-like. > do i iterate through a os.waitpid(pid) for each pid of the child > processes i create? That will technically work, and give you the information you wanted, though not necessarily in the most timely fashion. It'll block on each process in turn, waiting for its exit status -- so it'll finish as soon as all the children are dead, but if (say) the fifth process dies first, you won't find out until the first four have also passed on. If you don't have anything better for your program to do, and you're really on Unix, you can call kid, status = os.waitpid(0, 0) to wait for something to happen to any of your process's children; the kid is the process-id of the child being reported and the status is what happened to it. If you do have other things for your process to be doing, then your best bet is to establish a signal handler for SIGCHLD and installing a handler of the form import signal as S import os as OS import errno as E ## Children sometimes die. It's sad. def sigchld(sig, frame): try: while True: kid, status = OS.waitpid(0, OS.WNOHANG) if kid == 0: break ## Handle death of KID here. except OSError, err: if err.errno != E.ECHILD: raise ### ... ## Establish handler. S.signal(S.SIGCHLD, sigchld) should work. If you're running on Windows then these tricks won't work. As a grim hack, you could start a thread per child process and have each thread wait for its own child (sending the exit status through a queue or something). I'm afraid I don't know Windows well enough to offer slicker solutions; maybe someone else can help. -- [mdw] From benjamin.kaplan at case.edu Fri Jan 9 19:25:42 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 9 Jan 2009 19:25:42 -0500 Subject: why cannot assign to function call In-Reply-To: <4967E7A0.8050502@strout.net> References: <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <4967E7A0.8050502@strout.net> Message-ID: On Fri, Jan 9, 2009 at 7:11 PM, Joe Strout wrote: > Mark Wooding wrote: > > > .NET isn't a language at all: >> rather, it's a virtual machine, runtime system, class library and family >> of languages each of which may have idiosyncratic semantics. >> > > But they don't, AFAIK -- they all have the same semantics; only the surface > syntax differs. And those semantics are the same as REALbasic and Java. > They do in fact differ. You can have Visual C++ compile to CLI, in which case you have the C++ assignment in .NET, you can use VisualBasic, in which you can specify pass-by-value or -reference when you pass arguments to methods, and you have Visual C#, which copies Java's model and is therefore the same as Python. > > See for some side-by-side > comparisons. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 9 19:33:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 16:33:11 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> Message-ID: <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> On Jan 10, 9:52?am, webcomm wrote: > On Jan 9, 5:21?pm, John Machin wrote: > > > Thanks. Would you mind spending a few minutes more on this so that we > > can see if it's a problem that can be fixed easily, like the one that > > Chris Mellon reported? > > Don't mind at all. ?I'm now working with a zip file with some dummy > data I downloaded from the web service. ?You'll notice it's a smaller > archive than the one I was working with when I ran zip_susser.py, but > it has the same problem (whatever the problem is). You mean it produces the same symptom. The zipfile.py has several paths to the symptom i.e. the uninformative "bad zipfile" exception; we don't know which path, yet. That's why Martin was suggesting that you debug the sucker; that's why I'm trying to do it for you by remote control. It is not impossible for a file with dummy data to have been handcrafted or otherwise produced by a process different to that used for a real-data file. Please run v2 of the gadget on the real-data zip and report the results. >?It's the one I > uploaded tohttp://webcomm.webfactional.com/htdocs/data.zip > > Here's what I get when I run zip_susser_v2.py... > > archive size is 1092 > FileHeader at 0 > CentralDir at 844 > EndArchive at 894 > using posEndArchive = 894 > endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) > ? ? ? ? ? ? ? ? ? ? ? ? signature : 'PK\x05\x06' > ? ? ? ? ? ? ? ? ? ? this_disk_num : 0 > ? ? ? ? ? ? ?central_dir_disk_num : 0 > central_dir_this_disk_num_entries : 1 > ? central_dir_overall_num_entries : 1 > ? ? ? ? ? ? ? ? ?central_dir_size : 50 > ? ? ? ? ? ? ? ?central_dir_offset : 844 > ? ? ? ? ? ? ? ? ? ? ?comment_size : 0 > > expected_comment_size: 0 > actual_comment_size: 176 > comment is all spaces: False > comment is all '\0': True > comment (first 100 bytes): > '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00' > > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick with one thread ... From stutsman at cs.stanford.edu Fri Jan 9 19:39:24 2009 From: stutsman at cs.stanford.edu (Ryan Stutsman) Date: Fri, 09 Jan 2009 16:39:24 -0800 Subject: Common path all PyObjects take on destruction? Message-ID: <874p08t2o3.fsf@stutsman-jos64.scs.stanford.edu> I've added a field to all PyObjects in the interpreter which is of type PyObject*. Most of the time this pointer is NULL but occassionally I want to track some information in there. The problem I'm running into is that I can add a reference to a PyObject inside any of my PyObjects, but it seems that there isn't any one path that all objects follow on destruction so that I can later Py_DECREF that reference. Eventually most of the types seem to call PyObject_Free, but this gets called with void* and it seems it isn't always the case that PyObject*s are passed in. Where is the best place to implement something like this? It really won't work to implement this in the destructor of each of the individual types because other types added later won't know to DECREF this field on destruction. Any hints would be appreciated. Hopefully I'm just missing something simple. From googler.1.webmaster at spamgourmet.com Fri Jan 9 19:47:31 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 16:47:31 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: hi, thanks for your help. May the diff file is wrong? on my system it doesn't work. Well, set the -enable-universalsdk= path occurs that error. Hmm. that is really a disaster, isn't it :( hm. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 20:14:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 01:14:48 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0177ed3f$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 21:03:39 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Python doesn't do the same thing as C. It actually passes the same >> value to the function, without copying it. >> >> Why oh why do you keep insisting that Python is no different from C? > > I'm beginning to think that you're not bothing to read what I'm writing, Er, perhaps you missed that I was replying to Joe Strout. Joe wrote: "The reference itself is passed in, not the variable (or expression) that held or generated the reference in the calling code. This is no different from, in C, passing an integer:" I'm pretty sure I clearly quoted Joe in my post. Perhaps you missed it. In any case, I'm happy for you to contribute (it's a public forum), but how do you conclude I'm not reading *your* posts because I disagree with Joe's claim that Python is just like C? -- Steven From grante at visi.com Fri Jan 9 20:25:14 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 09 Jan 2009 19:25:14 -0600 Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: On 2009-01-10, Joe Strout wrote: > Mark Wooding wrote: > >> As an aside, I don't notice anywhere near as much confusion in Lisp and >> Scheme groups, which might be surprising since Lisp and Scheme have >> precisely the same data model, argument passing convention, and >> assignment semantics, as Python has. > > Nor is there anywhere near as much confusion in the REALbasic > community (with which I'm most familiar), which also has the > same semantics for reference types (which in RB is everything > except numbers, colors, and Boolean). It's not that there's a lot of confusion, it's just that we spend a lot of time talking about it. Programming in Python is so much more productive that we've got a lot more spare time that people who use other languages. -- Grant From sjmachin at lexicon.net Fri Jan 9 20:49:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 17:49:05 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> On Jan 9, 9:56?pm, mk wrote: > The factor of 30 indeed does not seem right -- I have done somewhat > similar stuff (calculating Levenshtein distance [edit distance] on words > read from very large files), coded the same algorithm in pure Python and > C++ (using linked lists in C++) and Python version was 2.5 times slower. Levenshtein distance using linked lists? That's novel. Care to divulge? And if C++ is using linked lists and Python isn't, it's not really the same algorithm, is it? Cheers, John From nad at acm.org Fri Jan 9 20:49:55 2009 From: nad at acm.org (Ned Deily) Date: Fri, 09 Jan 2009 17:49:55 -0800 Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: In article , googler.1.webmaster at spamgourmet.com wrote: > May the diff file is wrong? on my system it doesn't work. > Well, set the -enable-universalsdk= path occurs that error. Sorry, there were a few line wrap-arounds in the diff file due to long lines but the changes for the four significant lines should be easy to do manually. Note that the build I made this way has not been tested on ppc64 and has had minimal testing so far on x64_64. -- Ned Deily, nad at acm.org From googler.1.webmaster at spamgourmet.com Fri Jan 9 20:54:00 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 17:54:00 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: <65362bd0-7227-49fa-996c-ee0ffdb58b63@d42g2000prb.googlegroups.com> Hi! :) >Sorry, there were a few line wrap-arounds in the diff file due to long >lines but the changes for the four significant lines should be easy to >do manually. Hadn't done that before but I found a ressource how to read that syntax. x86_64 would be enough. i test that again. Thank you. :) From ppetrick at gmail.com Fri Jan 9 21:07:15 2009 From: ppetrick at gmail.com (p.) Date: Fri, 9 Jan 2009 18:07:15 -0800 (PST) Subject: download timeout vs. socket timeout Message-ID: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> i'm using urllib2 in python 2.4 wondering how people typically deal with the case in which a download is too slow. setting the socket timeout only covers those cases where there is no response in the socket for whatever the timeout period is. what if, however, i'm getting bits back but want simply to bail out if the total time to download takes too long? i'm trying to avoid creating a whole other thread if possible? From gagsl-py2 at yahoo.com.ar Fri Jan 9 21:20:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 10 Jan 2009 00:20:26 -0200 Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: En Sat, 10 Jan 2009 00:07:15 -0200, p. escribi?: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? You may use signal.alarm if it is available on your platform. On Windows, using a separate thread for reading is the easiest option - unless you plan to download hundreds of files simultaneously. -- Gabriel Genellina From google at mrabarnett.plus.com Fri Jan 9 21:26:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 02:26:48 +0000 Subject: download timeout vs. socket timeout In-Reply-To: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: <49680768.6090907@mrabarnett.plus.com> p. wrote: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? > Don't try to download all the data in one go, but do it a chunk at a time. If you calculate that it would take too long to complete, then stop. From arobert at townisp.com Fri Jan 9 21:27:05 2009 From: arobert at townisp.com (Andrew Robert) Date: Fri, 09 Jan 2009 21:27:05 -0500 Subject: Detecting open files and forcing closure Message-ID: Hi Everyone, We have a process that does a copy of a share from one location to another. This usually works fine but can occasionally bomb if a file is opened by a user somewhere. Is there a way to code detection of open files and force a close? The files in question are typically PDF files if that matters. Any pointers you can provide on this would be greatly appreciated. From rhodri at wildebst.demon.co.uk Fri Jan 9 21:32:54 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 10 Jan 2009 02:32:54 -0000 Subject: why cannot assign to function call In-Reply-To: <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Message-ID: On Sat, 10 Jan 2009 00:21:27 -0000, wrote: > Joe Strout wrote: >> rurpy at yahoo.com wrote: [snip] > Pointers are passed and assigned by value, just as > other types (disputedly except arrays) are. > One can then use that pointer to manually effect > pass-(the-value-pointed-to)-by-reference, or sharing, > etc. [snip] > In C (you have to explicitly ask for a reference > (pointer) to something (other than arrays) if you > want to use/pass a reference to something. > If you simply use the name, you get by-value semantics. >>> How would anyone develop that expectation if (from >>> a different post in this thread), "[Python's] idea >>> of assignment is the same as anyone else's." >> >> I can think of two ways: >> >> 1. They're new to programming in general, and would have had the same >> expectation for any other language. OR, > > IIRC, Someone posted here that his experience was > that 12-year old kids (presumably without programming > experience) had no problem with Python and references > when described as "names given to an object". (From > memory, can't locate the post right now.) 'Twas I. It was a rebuttal to your point that Python's assignment, parameter passing and data model is somehow inherently more difficult to wrap your brain around than that of other languages. It isn't; if anything it seems to be easier. >> 2. They already understand some other language, and then they come here >> and read wild claims that Python's assignment and parameter-passing >> semantics are different from other languages. Duped by this claim, they >> conclude that, if it's unlike other languages, then Python must have >> copy semantics. > > I have seen no evidence of that. If it were true I > would expect at least some posts to refer to reading > those "wild claims". 3. They conflate assignment, parameter passing and the data model, bring in preconceptions of their own from other languages, and get caught out by them. It's quite easy to do, even within a language. Look at the number of times you had to say "except arrays" about C above. > In Perl it is definitely true that you different syntax: > @a = (1,2,3) > @b = @a # Copy > $b = \@a # Reference Perl has different syntax for everything. It also has its own peculiarities of assignment and data model that make it a less than glowing example of comprehensibility. List flattening, for instance, is amazingly useful in many common Perl idioms, but really not what you expect during assignment. > C is the same way for everything (including pointers) > except arrays: Oh look, there's that exception again. > It may be one can make a technical case that assignment > is the same, but the reason I posted the code and results, > was because the behavior of "=" in them produces clearly > different results that "=" in Python. If you want to > then say to someone, "ignore those different results, > '=' works exactly the same", all I can say is good luck. > I will look forward to continuing to see weekly questions > on this list. :-) It would help if you were using "=" on things that were conceptually the same across the languages, instead of things that only looked similar. Which is where the data model comes in, as has already been explained at length, several times now. -- Rhodri James *-* Wildebeeste Herder to the Masses From mdw at distorted.org.uk Fri Jan 9 21:40:46 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 02:40:46 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: Joe Strout wrote: > No, actually, that was me. rurpy's list was something like C, FORTRAN, > Perl, and VBA. My mistake -- I failed to read the quoting properly. Apologies to all. We still dealt with C. Fortran (to give it its modern spelling) has a similar data model to C, but passes arguments by reference, as described in my Epic Argument Passing Article; I believe that arbitrary expressions may be used as arguments, though I'm unsure as to the semantics of modifying parameters bound to the resulting temporary argument locations. I must confess to being ignorant of VBA. My excuse is that I avoid Windows systems as much as practical, and VBA doesn't have a significant uptake on other systems. Perl has a very strange data model indeed, and it's hard to get a proper handle on it without getting into implementation details: unlike Python, Perl is largely defined /by/ its implementation. Perl has `references', which are proper (scalar) values through which one may read and modify other values; i.e., they're what I called `locatives' elsewhere. Perl provides syntactic sugar, through its `prototypes' which will convert an actual argument which designates (e.g.) a list or hash into a reference to that list or hash; prototypes provide other syntactic shortcuts too, though they have no fundamental semantic effect. In order to add to the confusion, Perl also provides `typeglobs', which are a reification of toplevel variable bindings. Perl's argument passing is fundamentally by /reference/. Given the function sub swap { ($_[0], $_[1]) = ($_[1], $_[0]) } after setting $a = 1, $b = 2, and calling swap $a, $b, we find that $a has the value 2 and $b is 1. What's going on here is that a `location' in Perl is an explicit SV, AV or HV object (for `scalar-', `array-' and `hash-value' respectively. Calling a subroutine involves marking a position on a stack, pushing a number of SVs, and then executing the subroutine's code, which receives the items between the stack pointer and mark in the @_ array. In the case of argument expressions which designate SVs, those SVs are pushed directly, and are therefore made available via @_. Arguments which are arrays or hashes are flattened: their components are pushed onto the stack. (This use of the stack corresponds to what the Perl manual refers to as `list context'.) > Not REALbasic. It's a very modern language with semantics pretty much > identical to Java. Very well; thanks for the correction. I might have a look at this at some point. > > .NET isn't a language at all: rather, it's a virtual machine, > > runtime system, class library and family of languages each of which > > may have idiosyncratic semantics. > > But they don't, AFAIK -- they all have the same semantics; only the > surface syntax differs. And those semantics are the same as REALbasic > and Java. There's a .NET implementation of C++, which obviously brings all of C++'s low-level data model (and it's user-definable assignment and copying). C#'s data model is more complex than Java's because it provides mutable compound `value types', i.e., types whose immediate representations consist of the raw contents of the object rather than a reference. The mutability allows one to distinguish this IR from a reference IR. C# is additionally complicated by its automatic boxing and unboxing rules: an object of value type may under some circumstances be `boxed', appearing as an object of reference type, and obeying the reference-type semantics. > Technically true, in that pointers in C require some special syntax, but > the common idiom is to hide this away by defining a new type: > > typedef Foo* FooPtr; > > Now, for any code using the "FooPtr" type, the data model is the same > as Python (or as Java, RB, .NET, etc., again for code that's using > only reference types). This is a syntactic transformation rather than a change to the data model, though. -- [mdw] From mdw at distorted.org.uk Fri Jan 9 21:42:21 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 02:42:21 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> <0177ed3f$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Er, perhaps you missed that I was replying to Joe Strout. Yes, evidently. My apologies for the mix up! -- [mdw], who obviously should put the keyboard down now. From rurpy at yahoo.com Fri Jan 9 21:53:59 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 18:53:59 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: Mark Wooding wrote: > rurpy at yahoo.com wrote: > >> If one accepts that there are a "lot" of people who post in here that >> clearly are surprised by Python's assignment semantics, > > But one should not accept that. One might accept that there are many > who post who claim that they are surprised by Python's assignment > semantics. Such people are wrong, however, since what they are > surprised by is Python's data model, and one reason that they are > surprised by Python's data model is because it's not actually explained > very well. Agreed. I think the docs, especially those that develop the conceptual model of how Python work at runtime, could use some major attention. >> and further appear to expect assignment to have copy-like semantics, > > This expectation is justified and, indeed, satisfied. Python does, most > definitely, copy on assignment. What it copies is references, however. > This might be clearer if the data model were explained better. > ... >> then where is that expectation coming from? > >> How would anyone develop that expectation if (from a different post in >> this thread), "[Python's] idea of assignment is the same as anyone >> else's." > > Because they've fundamentally misunderstood the data model. The very > fact that their confusion is ascribed to the wrong thing is strongly > indicative of this. > >> If you maintain that reference-like assignment is very common and >> something every programmer is accustomed to, then where are they >> getting the copy-like assignment expectations from? > > But it's not just assignment that deals with references. It's argument > passing and storage of compound data as well. (See PLR 3.1.) > > They expect that assignment copies stuff, because that's what assignment > does. Everywhere that I can think of -- except C++, which leaves > assignment semantics in hands of the programmer. What they're confused > about is what, precisely, it is that gets copied. And that, really, is > a result of an inadequate understanding of the data model. ... >> So it still seems to me that this is a likely explanation to why there >> is frequent misunderstanding of Python's assignments, and why >> responding to such misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > That's why I'm not just saying that assignment is the same. I'm also > saying that the data model is most definitely not the same as C. I would be willing to bet that most of the confused posters do not distinguish between assignment operation (AO) and data model (DM). Their conceptual box is labeled "assignment behavior" and includes both AO and DM. They expect that AO+DM in Python will produce the same results in Python as they are used to in the other languages they've used. That the discrepancy comes from the DM part rather than the AO part is pretty irrelevant to them given that world view. So responding to the cry, "Python assignment is bizarre!" with an indignant, "No, it is the same as other common languages", is talking with different vocabularies, unless it's also accompanied with all the other information presented in this thread about how Python treats all names as references (which *is* different that some other languages). I notice there is not even an FAQ on the subject of assignment despite the frequency which which people ask about it. >> I have often wished that C handled arrays the same way it does >> structs. I am sure that the pointer-array pseudo-equivalence seemed >> like a very clever idea at the time but I wonder if Dennis Richie ever >> had second thoughts about it. > > Probably. But I think the idea was actually inherited from BCPL, via B. > In BCPL, memory is divided into words. Depending on which operator you > use, you can treat a particular word as an integer, a floating-point > number, or a pointer. An array in BCPL is represented as a pointer to > its first element -- always -- and you index it by an expression of the > form p!i (a notation inherited by BBC BASIC and Haskell of all things). > The array->pointer decay is a compromise position between the BCPL > notion of array-as-pointer and the desire to allocate such things with > automatic storage duration and have sizeof and so on work properly. Interesting tidbit, thanks. From google at mrabarnett.plus.com Fri Jan 9 21:57:56 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 02:57:56 +0000 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: <49680EB4.7020008@mrabarnett.plus.com> Andrew Robert wrote: > Hi Everyone, > > We have a process that does a copy of a share from one location to > another. > > This usually works fine but can occasionally bomb if a file is opened > by a user somewhere. > > Is there a way to code detection of open files and force a close? > > The files in question are typically PDF files if that matters. > > Any pointers you can provide on this would be greatly appreciated. > If the file is open then an exception will be raised. You could catch it, sleep a while, and then retry, or continue with the other files and then come back to it and retry. It might take more than one retry. Anyway, it's a bad idea to force a close, even if that's possible. From arobert at townisp.com Fri Jan 9 22:06:03 2009 From: arobert at townisp.com (Andrew Robert) Date: Fri, 09 Jan 2009 22:06:03 -0500 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: MRAB wrote: > Andrew Robert wrote: >> Hi Everyone, >> >> We have a process that does a copy of a share from one location to >> another. >> >> This usually works fine but can occasionally bomb if a file is opened >> by a user somewhere. >> >> Is there a way to code detection of open files and force a close? >> >> The files in question are typically PDF files if that matters. >> >> Any pointers you can provide on this would be greatly appreciated. >> > If the file is open then an exception will be raised. You could catch > it, sleep a while, and then retry, or continue with the other files and > then come back to it and retry. It might take more than one retry. > Anyway, it's a bad idea to force a close, even if that's possible. The usual scenario is that a user will leave a PDF open and then go home for the evening. They are simply viewing and not modifying the file. When the XCOPY executes, it signals a failure and subsequent scheduler job abend. What I need to do is detect if files are open for viewing and force a close before the copy operation is attempted. Sleeping and retrying the copy is not an option because the user will likely leave it open all night. Is there a way to detect the open files and close them out? From matthew.nuzum at canonical.com Fri Jan 9 22:18:25 2009 From: matthew.nuzum at canonical.com (Matthew Nuzum) Date: Fri, 9 Jan 2009 21:18:25 -0600 Subject: Jython 2.5 Beta1 Released! In-Reply-To: <4dab5f760901091337q79178ac3m1387594a4c738145@mail.gmail.com> References: <4dab5f760901091337q79178ac3m1387594a4c738145@mail.gmail.com> Message-ID: On Fri, Jan 9, 2009 at 3:37 PM, Frank Wierzbicki wrote: > On behalf of the Jython development team, I'm pleased to announce that > Jython 2.5b1 is available for download: > http://downloads.sourceforge.net/jython/jython_installer-2.5b1.jar. > See the installation instructions here: > http://www.jython.org/Project/installation.html. > > Jython 2.5 Beta1 continues a code cooling period where the number of > new features should significantly slow as we concentrate on > solidifying Jython 2.5 for an eventual release. I would guess that we > will put out about two more betas before we start pushing out release > candidates, hopefully in February. > > This is a beta release so be careful. Congrats, I'm watching with eager anticipation! I'm stunned at how well this is working and the progress you're making. Keep up the great work. -- Matthew Nuzum newz2000 on freenode, skype, linkedin, identi.ca and twitter From rurpy at yahoo.com Fri Jan 9 22:19:56 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 19:19:56 -0800 (PST) Subject: why cannot assign to function call References: <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Message-ID: Rhodri James wrote: > On Sat, 10 Jan 2009 00:21:27 -0000, wrote: >> IIRC, Someone posted here that his experience was >> that 12-year old kids (presumably without programming >> experience) had no problem with Python and references >> when described as "names given to an object". (From >> memory, can't locate the post right now.) > > 'Twas I. It was a rebuttal to your point that Python's assignment, > parameter passing and data model is somehow inherently more difficult > to wrap your brain around than that of other languages. It isn't; if > anything it seems to be easier. That was and is not my point. My point was that there seems to be an observably significant number of people who are surprised by the way Python assignment works. I hypothesized that this was due to their experience with other languages, *not* that Python is somehow "inherently more difficult to wrap your brain around", and that the response, "Python assignments are the same as in those other languages" is insufficient. From silfheed at gmail.com Fri Jan 9 22:21:56 2009 From: silfheed at gmail.com (Silfheed) Date: Fri, 9 Jan 2009 19:21:56 -0800 (PST) Subject: Mocking `from foo import *` functions Message-ID: So I'm in the current testing situation: sender.py: ------------- def sendEmails(): return "I send emails" alerter.py: ------------- from sender import * def DoStuffAndSendEmails(): doStuff() sendEmails() I'm trying to write a test fn that will test DoStuffAndSendEmails() (as well as it's kin) without actually sending any emails out. I could go through alter alerter so that it does `import sender` and then find and replace fn() with sender.fn() so I can just create a mock fn fakeSendEmails() and and do something like sender.sendEmails = fakeSendEmails, but I'd rather not. Anyone know how to test alerter.py with out altering the file? Thanks! From google at mrabarnett.plus.com Fri Jan 9 22:41:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 03:41:21 +0000 Subject: Mocking `from foo import *` functions In-Reply-To: References: Message-ID: <496818E1.6020506@mrabarnett.plus.com> Silfheed wrote: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > doStuff() > sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? > > You could alter sender.py. :-) Actually, you could have: alerter.py: ------------- TEST = False if TEST: from mock_sender import * else: from sender import * so you're changing alerter.py in only one place, or read the value of TEST from a config file. From pavlovevidence at gmail.com Fri Jan 9 22:42:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 19:42:42 -0800 (PST) Subject: Common path all PyObjects take on destruction? References: <874p08t2o3.fsf@stutsman-jos64.scs.stanford.edu> Message-ID: <86bd1eca-2cd2-42f2-884c-9619abe4c919@w1g2000prk.googlegroups.com> On Jan 9, 6:39?pm, Ryan Stutsman wrote: > I've added a field to all PyObjects in the interpreter which is of type > PyObject*. ?Most of the time this pointer is NULL but occassionally I > want to track some information in there. ?The problem I'm running into > is that I can add a reference to a PyObject inside any of my PyObjects, > but it seems that there isn't any one path that all objects follow on > destruction so that I can later Py_DECREF that reference. > > Eventually most of the types seem to call PyObject_Free, but this gets > called with void* and it seems it isn't always the case that PyObject*s > are passed in. > > Where is the best place to implement something like this? ?It really > won't work to implement this in the destructor of each of the individual > types because other types added later won't know to DECREF this field on > destruction. > > Any hints would be appreciated. ?Hopefully I'm just missing something > simple. I believe no object in CPython ever gets deleted except by the Py_DECREF macro (Py_XDECREF and Py_CLEAR both expand Py_DECREF). So there is your common reference point. Let's look at the macro, shall we? #define Py_DECREF(op) \ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ --((PyObject*)(op))->ob_refcnt != 0) \ _Py_CHECK_REFCNT(op) \ else \ _Py_Dealloc((PyObject *)(op)) So, if the reference count goes down to zero, Py_DECREF calls _Py_Dealloc to delete the object. _Py_Dealloc is the common point you want. Carl Banks From rtw at freenet.co.uk Fri Jan 9 22:54:20 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Fri, 09 Jan 2009 21:54:20 -0600 Subject: Mocking `from foo import *` functions References: Message-ID: Silfheed wrote in news:c73b304b-f601-4bb5-89c1-3ee667eeb7d9 @l37g2000vba.googlegroups.com in comp.lang.python: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > doStuff() > sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? Yes you alter the module *after* you have imported it. In your test script do: def mock_sendEmails(): pass # or some test code maybe # setup ... import alerter # now patch the module alerter.sendEmails = mock_sendEmails # run the test ... DoStuffAndSendEmails() Because python is dynamic alerter.DoStuffAndSendEmails will call the sendEmails in the alerter module that has been replaced with mock_sendEmails from the test script. Rob. -- http://www.victim-prime.dsl.pipex.com/ From musiccomposition at gmail.com Fri Jan 9 22:55:23 2009 From: musiccomposition at gmail.com (Benjamin) Date: Fri, 9 Jan 2009 19:55:23 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> Message-ID: <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> On Jan 8, 11:35?pm, John Machin wrote: > On Jan 9, 1:56?pm, Benjamin wrote: > > > On Jan 8, 4:21?pm, Thorsten Kampe wrote: > > > > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > > > Since you are, I believe, at least the second person to report being bit > > > > by this confusion, please open an issue at bugs.python.org and suggest a > > > > couple of revised sentences that you think are more informative. > > > > Will do tomorrow. The revised sentence could be in the line of "warn > > > about Python 3.x incompatibilities that cannot trivially be fixed by > > > 2to3.py". > > > Actually, don't bother now; I've fixed it up in the trunk. > > Would you mind giving a pointer to where or what your fix is? The > reason for asking is that Thorsten's suggestion is ambiguous: warn > about some? all? 3.x problems that can't be trivially fixed by 2to3? > Can't be "all"; there are in fact a number of problems that can't be > trivially fixed by 2to3 and can't be detected by running 2.6 with the > -3 option. I added "and cannot by trivially fixed by 2to3". > > These include > (a) problems that cause a reasonably informative exception in 3.x > right at the point where the problem exists > (b) problems where the behaviour has changed but no exception is > raised, and your code lurches off down the wrong path, and you need to > work backwards from subsequent exception(s) and/or failing test case > (s) to pin-point the problem. > > I'll use string constants to provide an example of each type. When > faced with "abcd", 2to3 has no way of telling whether that should be > str ("abcd") or bytes (b"abcd"). In the vast majority of cases, to > guess it should be str is correct, so there is no change to the source > file, and a warning would ?almostly always be noise. > > Example of problem (a): chunks is a list of slices of bytes read from > a binary file. > In 2.x you write > glued = ''.join(chunks) > In 3.0 you get this:>>> chunks = [b'x', b'y'] > >>> ''.join(chunks) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: sequence item 0: expected str instance, bytes found > > Example of problem (b): some_bytes has been read from a file that was > opened in 'rb' mode and contains the 4 ASCII bytes 'abcd' > # 2.x simulation>> some_bytes == "abcd" > > True > # 3.0 simulation>>> type(some_bytes) > > >>> type("abcd") > > >>> some_bytes == "abcd" > > False # because the types are not comparable for equality. > > Another type (b) example is the (majority-guessed) 2to3 change from [c] > StringIO.StringIO to io.StringIO ... if you really should feed some > library an io.BytesIO instance instead, it can travel quite a distance > before blowing up. Yes, bytes/str is an excellent example of where the third part of the porting helpers. We'll need good documentation. Unfortunately, as you note below, this isn't exactly the case yet. > > Perhaps some of this info could be put intohttp://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 > ... or maybe a separate HOWTO or wiki chapter could be set up for > porting to 3.x, including topics like: > (1) maintaining one set of source files (when you are maintaining a > package that must run on e.g. 2.1 through 3.x) > (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x > support-range issue but would like to have the one set of source > looking like 3.x code instead of the ugliness of version-conditional > stuff like > BYTES_NULL = bytes(0) # 3.x > or > BYTES_NULL = '' # 2.x > and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? > > Cheers, > John From sjmachin at lexicon.net Fri Jan 9 23:19:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 20:19:11 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> Message-ID: On Jan 10, 2:55?pm, Benjamin wrote: > On Jan 8, 11:35?pm, John Machin wrote: > > > Actually, don't bother now; I've fixed it up in the trunk. > > > Would you mind giving a pointer to where or what your fix is? The > > reason for asking is that Thorsten's suggestion is ambiguous: warn > > about some? all? 3.x problems that can't be trivially fixed by 2to3? > > Can't be "all"; there are in fact a number of problems that can't be > > trivially fixed by 2to3 and can't be detected by running 2.6 with the > > -3 option. > > I added "and cannot by trivially fixed by 2to3". That's what I was afraid of. Please consider changing it so that it does not give the impression that together -3 and 2to3 cover all the bases. > Yes, bytes/str is an excellent example of where the third part of the > porting helpers. I don't understand that. What is/are "the third part of the porting helpers"? Are there words missing from the end? > We'll need good documentation. Unfortunately, as you > note below, this isn't exactly the case yet. So is there a plot to remedy this? Where do we sign up? > > Perhaps some of this info could be put intohttp://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 > > ... or maybe a separate HOWTO or wiki chapter could be set up for > > porting to 3.x, including topics like: > > (1) maintaining one set of source files (when you are maintaining a > > package that must run on e.g. 2.1 through 3.x) > > (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x > > support-range issue but would like to have the one set of source > > looking like 3.x code instead of the ugliness of version-conditional > > stuff like > > BYTES_NULL = bytes(0) # 3.x > > or > > BYTES_NULL = '' # 2.x > > and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? From rhodri at wildebst.demon.co.uk Fri Jan 9 23:38:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 10 Jan 2009 04:38:18 -0000 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: On Sat, 10 Jan 2009 03:06:03 -0000, Andrew Robert wrote: > The usual scenario is that a user will leave a PDF open and then go home > for the evening. They are simply viewing and not modifying the file. > When the XCOPY executes, it signals a failure and subsequent scheduler > job abend. > > What I need to do is detect if files are open for viewing and force a > close before the copy operation is attempted. > > Sleeping and retrying the copy is not an option because the user will > likely leave it open all night. > > Is there a way to detect the open files and close them out? I can't think of one off the top of my head, but this approach will cause more anguish than you would believe possible in any case. Imagine if the file was open for write; you've either just corrupted it or lost the most recent work if you force it closed. It sounds like you're trying to implement a backup strategy. If you are, I'd suggest your problem is XCOPY -- you really need something more combat capable instead. -- Rhodri James *-* Wildebeeste Herder to the Masses From hsoft at hardcoded.net Sat Jan 10 01:12:57 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Fri, 9 Jan 2009 22:12:57 -0800 (PST) Subject: Mocking `from foo import *` functions References: Message-ID: On Jan 10, 4:21?am, Silfheed wrote: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > ? ?return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > ? doStuff() > ? sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. ?I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? > > Thanks! Don't ever put testing flag in your non-code, that's very ugly and creates a weird circular dependency between your real code and your test code. It will give you headaches later. To answer to Rob: yeah, sure that would work, but I always thought mocking the imported function didn't feel right. The test then depends on the import method of the tested module. If you later change your mind and decide to use "import sender" and then "sender.sendEmails()", you have to change your test code. In my code, I have a custom TestCase class which has a method for dealing with this stuff, here's the code relevant to your problem: class TestCase(unittest.TestCase): cls_tested_module = None def run(self, result=None): self._mocked = [] unittest.TestCase.run(self, result) # We use reversed() so the original value is put back, even if we mock twice. for target, attrname, old_value in reversed(self._mocked): setattr(target, attrname, old_value) def mock(self, target, attrname, replace_with): ''' Replaces 'target' attribute 'attrname' with 'replace_with' and put it back to normal at tearDown. The very nice thing about mock() is that it will scan self.cls_tested_module for the mock target and mock it as well. This is to fix the "from" imports problem (Where even if you mock(os, 'path'), if the tested module imported it with "from os import path", the mock will not work). ''' oldvalue = getattr(target, attrname) self._mocked.append((target, attrname, oldvalue)) setattr(target, attrname, replace_with) if (self.cls_tested_module is not None) and (self.cls_tested_module is not target): for key, value in self.cls_tested_module.__dict__.iteritems (): if value is oldvalue: self.mock(self.cls_tested_module, key, replace_with) When you use it, set cls_tested_module (at the class level) to "sender" (not the string, the module instance) From enleverlesX.XmcX at XmclaveauX.com Sat Jan 10 01:36:52 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sat, 10 Jan 2009 07:36:52 +0100 Subject: Free Download - Microsoft Windows 7 Beta In-Reply-To: References: Message-ID: <496843c4$0$18388$ba4acef3@news.orange.fr> Hi! I downloaded W7 two days ago, directly on MSDN (Microsoft), and not on a bizarre, unknown site, and doubtful. Python 2.6 run OK. But the problem (well known) with Python 2.6.1 is always present. @-salutations -- Michel Claveau From gagsl-py2 at yahoo.com.ar Sat Jan 10 02:15:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 10 Jan 2009 05:15:22 -0200 Subject: multiprocessing and SIGINT References: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> <493e1114-84c4-47df-be80-e93ed4fcbfce@a12g2000pro.googlegroups.com> Message-ID: En Fri, 09 Jan 2009 03:04:58 -0200, akineko escribi?: > (2) test program with multiprocessing > Both processes receives SIGINT. > OS apparently distributes the SIGINT event to processes associated > with the terminal. Yes, to avoid that, the child process has to detach itself from the terminal. I'd expect the multiprocessing module to do that for us - but it doesn't. See http://www.onlamp.com/python/pythoncook2/solution.csp?day=1 > (3) signal handler > I realized that I could assign a signal handler specific to a process > by placing it to a worker method. > > def worker(): > # this process ignores SIGINT > signal.signal(signal.SIGINT, signal.SIG_IGN) > ... the rest ... Looks fine... > (4) terminating the spawned process > I needed to send a shutdown message to the process via a communication > between two processes. > You can use Process.terminate() to brutally kill the process but that > is a last resort. What about sending a signal, like SIGTERM? -- Gabriel Genellina From rhamph at gmail.com Sat Jan 10 02:44:31 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Fri, 9 Jan 2009 23:44:31 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> <6spt2cF7n8nmU3@mid.uni-berlin.de> Message-ID: On Jan 9, 2:14?pm, Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > > Marc 'BlackJack' Rintsch wrote: > > >> def iter_max_values(blocks, block_count): > >> ? ? for i, block in enumerate(blocks): > >> ? ? ? ? histogram = defaultdict(int) > >> ? ? ? ? for byte in block: > >> ? ? ? ? ? ? histogram[byte] += 1 > > >> ? ? ? ? yield max((count, byte) > >> ? ? ? ? ? ? ? ? ? for value, count in histogram.iteritems())[1] > > > [snip] > > Would it be faster if histogram was a list initialised to [0] * 256? > > Don't know. ?Then for every byte in the 2?GiB we have to call `ord()`. ? > Maybe the speedup from the list compensates this, maybe not. > > I think that we have to to something with *every* byte of that really > large file *at Python level* is the main problem here. ?In C that's just > some primitive numbers. ?Python has all the object overhead. struct's B format might help here. Also, struct.unpack_from could probably be combined with mmap to avoid copying the input. Not to mention that the 0..256 ints are all saved and won't be allocated/ deallocated. From __peter__ at web.de Sat Jan 10 02:53:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 Jan 2009 08:53:47 +0100 Subject: Force exception on attribute write access only one object References: <6slvrrF71ds4U1@mid.individual.net> <6sp04mF7hgjdU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Peter Otten schrieb: >> Thomas Guettler wrote: >> >>> for debugging I want to raise an exception if an attribute is >>> changed on an object. Since it is only for debugging I don't want >>> to change the integer attribute to a property. >> class A(object): >> def __init__(self): >> self.foo = 42 >> >> a = A() >> b = A() >> >> class B(A): >> @property >> def foo(self): >> return self.__dict__["foo"] >> >> b.__class__ = B >> >> a.foo = "whatever" >> print b.foo >> b.foo = "whatever" > your idea was good, but it does not work with Django ORM Models: > > Traceback (most recent call last): > File "/localhome/modw/django/core/handlers/base.py", line 87, in > get_response > response = callback(request, *callback_args, **callback_kwargs) > File "/localhome/modw/foo/views/filter.py", line 473, in add > return edit(request, 'add') > File "/localhome/modw/foo/views/filter.py", line 493, in edit > filter=form.save() > File "/localhome/modw/foo/views/filter.py", line 457, in save > action=form.save() > File "/localhome/modw/django/forms/models.py", line 315, in save > if self.instance.pk is None: > File "/localhome/modw/django/db/models/base.py", line 292, in > _get_pk_val > return getattr(self, meta.pk.attname) > AttributeError: 'MyAction' object has no attribute 'filter_action_ptr_id' I can't tell what's happening from the traceback alone. Is "filter_action_ptr_id"" your actual "foo" and "MyAction" your "B"? Maybe the relevant setup code would help... Peter From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 04:24:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 09:24:51 GMT Subject: Detecting open files and forcing closure References: Message-ID: <01786016$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 22:06:03 -0500, Andrew Robert wrote: > Is there a way to detect the open files and close them out? You can detect open files by trying to move them and catching the exception when you can't. You may wish to distinguish permission errors. As far as forcing the file to close, that depends on what OS you are using and what permissions your application is running as. I intuit that you are running under Windows, because POSIX systems allow you to copy open files. My knowledge of Windows isn't that great, but I imagine that the only way to force a close is something drastic like rebooting the machine. Sounds like your real problem is a social problem, not a technical one. Maybe you need a "failed to log out" jar (like a swear jar), and every person who failed to close their open files has to put a dollar in the jar. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 04:46:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 09:46:18 GMT Subject: why cannot assign to function call References: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0178651d$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 20:23:11 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I'm pretty sure that no other pure-Python coder has manipulated >> references either. They've manipulated objects. > > No: not directly. The Python program deals solely with references; > anything involving actual objects is mediated by the runtime. Your claim is ambiguous: when you say "the Python program", are you talking about the program I write using the Python language, or the Python VM, or something else? If the first, then you are wrong: the Python program I write doesn't deal with references. It deals with objects. This discussion flounders because we conflate multiple levels of explanation. People say "You do foo" when they mean "the Python VM does foo". Earlier, I responded to your claim that I was storing references by saying I was pretty sure I didn't store references, and gave an example of the line of Python code x=23. Your response was to mix explanatory levels: > You bind names to locations which store immediate representations. > Python IRs are (in the sense defined above) exclusively references. I most certainly don't bind names to locations. When I write x=23, I don't know what the location of the object 23 is, so how could I bind that location to the name? You are conflating what the Python VM does with what I do. What *I* do is bind the object 23 to the name x. I don't know the location of 23, I don't even know if 23 has a well-defined location or if it is some sort of distributed virtual data structure. As a Python programmer, that's the level I see: names and objects. At a lower level, what the Python VM does is store the name 'x' in a dictionary, bound to the object 23. No locations come into it, because at this level of explanation, dictionaries are an abstract mapping. There's no requirement that the abstract dictionary structure works by storing addresses. All we know is that it maps the name 'x' to the object 23 somehow. Maybe there's no persistent storage, and the dict stores instructions telling the VM how to recreate the object 23 when it is needed. Who knows? But at this explanatory level, there are no locatives involved. Names and objects float as disembodied entities in the aether, and dicts map one to the other. At an even lower explanatory level, the CPython implementation of dictionaries works by storing a pointer (or if you prefer, a reference) to the object in a hash table. Pointers, of course, are locatives, and so finally we come to the explanation you prefer. We've gone from abstract names-and-classes to concrete pointers-to-bytes. But this is at least two levels deeper than what's visible in Python code. Just about the only time Python coders work with locatives is when they manually calculate some index into a string or list, or similar. At an even lower explanatory level, all the VM does is copy bytes. And at a lower level still, it doesn't even copy bytes, it just flips bits. And below that, we're into physics, and I won't go there. I daresay you probably get annoyed at me when I bring up explanations at the level of copying bytes. You probably feel that for the average Python programmer, *most of the time* such explanations are more obfuscatory than useful. Of course, there are exceptions, such as explaining why repeated string concatenation is likely to be slow. There is a time and a place for such low level explanations, but not at the high-level overview needed by the average Python programmer. And you would be right. But I argue that your explanation at the level of references is exactly the same: it is too low level. It relies on specific details which may not even be true for all implementations of Python. It certainly relies on details which won't be true for hypothetical versions of Python running on exotic hardware. One can do massively parallel calculations using DNA, and such "DNA computers" are apparently Turing complete. I have no idea how one would write a Python virtual machine in such a biological computer, but I'm pretty sure that data values won't have well-defined locations in a machine that consists of billions of DNA molecules floating in a liquid. If that's too bizarre for you, think about simulating a Python VM in your own head. If we know one thing about the human brain, it is that thoughts and concepts are not stored in single, well-defined locations, so when you think of "x=23", there is no pointer to a location in your head. >> That's why we should try to keep the different layers of explanation >> separate, without conflating them. Python programmers don't actually >> flip bits, and neither do they manipulate references. Python >> programmers don't have access to bits, or references. What they have >> access to is objects. > > No, that's my point: Python programmers /don't/ have direct access to > objects. The objects themselves are kept at arm's length by the > indirection layer of references. I think you are wrong. If I want a name 'x' to refers to (is bound to) the object 23, I write x=23, not some variation of: create object 23 give me a reference to that object bind the reference to name 'x' Those three steps may take places at some level of the Python VM, but that's not what *I* do as a Python programmer. Note that what we're really doing is manipulating the symbol '23' in source code. Normally that makes no difference, but if you've ever tried to get the float 1.1 you'll discover the model (metaphor) of "source code symbols are programming entities" fails. All models fail sometimes. >> > Python does pass-by-value, but the things it passes -- by value -- >> > are references. >> >> If you're going to misuse pass-by-value to describe what Python does, >> *everything* is pass-by-value "where the value is foo", for some foo. > > No. I've tried explaining this before, with apparently little success. [...] > * A /value/ is an item of data. The range and nature of values is > language specific. Typically, values encompass at least some kinds > of numbers, textual data, and compound data structures; they may > also include behavioural items such as functions. Yes. This is an intuitive meaning of the world value. In Python, all values are objects. Some typical examples of values are: 5, None, "Fred", True, 3.5, [2, 3, 4], {}, lambda x: x+1 These (and more complicated structures built on top of them) are the things of interest to the programmer. They are the values: the things which are denoted by the symbols '5', 'None', '"Fred"' etc. > * A /location/[1] is an area of memory suitable for storing the > /immediate representation/ (which I shall abbreviate to /IR/) of a > value. (A location may be capable of storing things other than IRs, > e.g., representations of unevaluated expressions in lazily evaluated > languages. Locations may vary in size, e.g., in order to be capable > of storing different types of IRs.) At the level of Python code, we have no access to such locations. The closest we have is the id() function, which uses location in memory as a unique ID for objects, but this is an accident of the CPython implementation. Whatever the /immediate representation/ of a value is, we can't manipulate it directly in Python code. > * A /variable/ is a location to which has been /bound/ a name. Given > an occurrence of a name in a program's source, there is a language > specific rule for determining the variable to which it is bound. According to this definition, there are no variables in Python, because Python's data model is that names are an abstract mapping between symbols and values, not between symbols and locations. > * /Evaluation/ is the process of determining a value from an > expression. The /value of/ an expression is the result of > evaluating the expression. This value is, in general, dependent on > the contents of the locations to which names appearing in the > expression are bound. [...] > The argument passing model `pass-by-value' has a number of distinctive > properties. > > * The argument expression is fully evaluated before the function is > called, yielding an argument value. > > * The corresponding parameter name is bound to a fresh location. > > * The argument value IR is stored in the parameter's location. This is an underspecified definition. Without a definition of /immediate representation/, we can't determine what this means. I can guess that, based on Pascal, Fortran and C, the /immediate representation/ of a value is whatever data structure represents that value. However, I fear that you are going to try to slip in an open-ended definition, that /immediate representation/ could be *anything* -- for ints in C, it will be the bytes that represent the int; for C arrays, it will be a pointer to the bytes that represent the array; for Python, it will be references to objects; for Algol 60, it will be thunks. To avoid weakening pass-by-value to mean everything and anything at all, I'm going to say that the /immediate representation/ is the bytes which represent the value. (That is, the value itself.) Given this, we can see that Python is not pass-by-value. As I have shown in another post, replying to Joe, the location (as exposed by the id() function in CPython) of the formal parameter is the same as that of the argument value, not a fresh location with a copy of the value. To save you looking up my post, here's a simple example: >>> def function(parrot): ... return id(parrot) ... >>> spam = 23 >>> print id(spam), function(spam) 143599192 143599192 > By contrast, the `pass-by-reference' model has other distinguishing > properties. > > * Whether arbitrary argument expressions are permitted is language > dependent; often, only a subset of available expressions -- those > that designate locations -- are permitted. As you said above: "The /value of/ an expression is the result of evaluating the expression". Given the expression 2+3, the result of that expression is 5, not the location where 5 is stored. There is no reason to believe that 5 designates a location, as opposed to designating the number of peas in a pod or the average length of a piece of string. For want of a better description, let me re-word the above to say: * Whether arbitrary argument expressions are permitted is language dependent; often, only a subset of available expressions -- e.g. those that evaluate at a named location -- are permitted. Note that I say they evaluate *at*, not *to*, a fixed location. A practical example, to ensure we're talking about the same thing. In Pascal, I can declare a procedure swap(a, b) taking two VAR parameters, which use call-by-reference semantics. I might do something like this: a := 8; { number of peas in a pod } b := 13; { a baker's dozen } swap(a, b); Even though the values of a and b do not designate locations, the compiler can pass them to the procedure because the named variables a and b exist *at* particular locations. Contrast this with: swap(a, 10+3); which will fail in Pascal, because the value of the expression 10+3 doesn't correspond to a named location. (Presumably this is a design choice, because the value of the expression will certainly exist at a known location, although possibly not known until runtime.) > If the argument > expression does designate a location, then this location is the > /argument location/. Replace this with "If the argument expression does evaluate at an allowed location (named location for Pascal), then..." and I will accept it. > If arbitrary expressions are permitted, and > the expression does not designate a location, then a fresh location > is allocated to be the argument location, the expression evaluated, > and the resulting IR stored in the argument location. Modulo similar changes, accepted. > * The corresponding parameter name is bound to the argument location. According to this definition, Python is call-by-reference. Refer my code snippet above. But clearly Python doesn't behave like call-by-reference in other languages: you can't write a swap() procedure. This is where I quote Barbara Liskov, talking about the language CLU which has precisely the same calling semantics as Python: "In particular it is not call by value because mutations of arguments performed by the called routine will be visible to the caller. And it is not call by reference because access is not given to the variables of the caller, but merely to certain objects." http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-11/ msg01499.html or http://snipurl.com/9qd0b > There are other models, including value/return and call-by-name. And Python's call-by-object (also CLU, Ruby, Java -- although Java people don't use the term -- and others). [...] > I hope that I have convincingly demonstrated that it's possible to > define `pass-by-value' in a coherent manner, consistent with > conventional usage, and distinguishing it clearly from `pass-by- > reference'. Of course you can define pass-by-value coherently, but not if the definition of value can be anything you like. Once you start declaring that a language is "pass-by-value, where the value is a Foo rather than the actual value", pass-by-value can be used to describe *anything*. Pass- by-reference becomes pass-by-value where the value is the location of the value. Pass-by-object is pass-by-value where the value is a reference to the object (your claim). And so forth. [...] >> > I agree with the comment about Pascal, but C is actually pretty >> > similar to Python here. C only does pass-by-value. >> >> Except for arrays. > > Even for those. C doesn't pass arrays at all; instead it passes > (programmer-visible) pointers. See other article. But you are conflating concepts again. The value of an array is the array: it's what the programmer asked for when he declared an array. See your own definition of value above: "A /value/ is an item of data." Given a symbol x which represents an array, C doesn't pass the value of x (the array). It passes a pointer (reference) to the value of x. This is not pass-by-value unless you define value so broadly that it could mean anything. Given the Pascal declaration procedure foo(x: array[1..1000] of char) You get pass-by-value semantics: when you pass an array to foo, the entire array is duplicated. Changes to x are not visible in the caller's array. C arrays do not behave like this with an equivalent declaration. Change the declaration to be VAR x, and using pass-by-reference semantics, and the array is *not* duplicated, and changes to x *are* visible to the caller. C's default handling of arrays is just like Pascal's call-by-reference semantics, not like pass-by-value. This is AFAIK unique in C to arrays. [...] >> In other words... C is call-by-value, and (according to you) Python is >> call-by-value, but they behaviour differently. > > And this is entirely due to the difference in their immediate > representations of values. Values are values. Regardless of whether you are using C or Pascal or Python, the value of 1+1 is 2, not some arbitrary memory location. I'm going to quote from Fredrik Lundh: "I'm not aware of any language where a reference to an object, rather than the *contents* of the object, is seen as the object's actual value. It's definitely not true for Python, at least." http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-11/ msg01341.html or http://snipurl.com/9qdze The viewpoint that values are references is bizarre and counter- intuitive, and it leaves us with no simple way of talking about the value of expressions in the sense that 2 is the value of the expression 1+1. -- Steven From castironpi at gmail.com Sat Jan 10 06:30:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 10 Jan 2009 03:30:55 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: On Jan 9, 9:30?am, Joe Strout wrote: > Aaron Brady wrote: > > Possible compromise. ?You can think of functions as mutation-only. > > You pass the object, and it gets a new (additional) name. ?The old > > name doesn't go in. ? > > That's correct. ?The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. This is very odd, and I see it quite a bit. Me: "You pass the object." Joe: "That's correct. You pass the reference." What was wrong with my original? > This is true. ?(Technically, instead of variable, we should say "LValue" > here -- there are things slightly more complex than simple variables > that can serve as the left-hand side of an assignment. ?So replace > "variable" with "lvalue" above if you prefer.) This is a point worth making. I want to penny-pinch every term in an introductory text, though, so, it's a tough call. > M2: If 'fun()' returned a reference, you might be able to mutate the > object that refers to. > m2: You can sometimes mutate the object it refers to. > C2: 'fun()' returns a reference. This is horrendous. http://en.wikipedia.org/wiki/Formal_fallacy http://en.wikipedia.org/wiki/Affirming_the_consequent A question: Are you Joe and you Mark certain that the simplest possible introductory explanation makes use of the term 'reference'? Perhaps we can have a contest for shortest/simplest/best description of Python's data/variable/argument model. Lastly, I don't see any reason why we couldn't make both explanations available. 'For those coming from Java/etc....; for those coming from C++/etc.....' They would both get read. From goldnery at gmail.com Sat Jan 10 09:15:22 2009 From: goldnery at gmail.com (Gandalf) Date: Sat, 10 Jan 2009 06:15:22 -0800 (PST) Subject: if-else statement Message-ID: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> other languages like PHP or javascript as this if-else operator like this myVar = checking == 1? 'string': 'other string' is this stuff exist in python? thanks! From duncan.booth at invalid.invalid Sat Jan 10 09:26:15 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Jan 2009 14:26:15 GMT Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: Gandalf wrote: > other languages like PHP or javascript as this if-else operator like > this > > myVar = checking == 1? 'string': 'other string' > > is this stuff exist in python? > See http://docs.python.org/reference/expressions.html#boolean-operations conditional_expression ::= or_test ["if" or_test "else" expression] ... The expression x if C else y first evaluates C (not x); if C is true, x is evaluated and its value is returned; otherwise, y is evaluated and its value is returned. From jamesthiele.usenet at gmail.com Sat Jan 10 10:12:40 2009 From: jamesthiele.usenet at gmail.com (James Thiele) Date: Sat, 10 Jan 2009 07:12:40 -0800 (PST) Subject: NorthwestPythonDay, 31 Jan 2009 Message-ID: Posted for Brian Dorsey Hello everyone, On behalf of the Seattle Python Interest Group, I'd like to invite you to join us for an informal day of Python talks & socializing. When: January, 31st 9am - 5pm Where: University of Washington campus, Seattle, Washington Price: Free! Details and updated information: http://www.seapig.org/NorthwestPythonDay The day will be mostly 30 minute talks and two sets of 5 minute lightning talks. We'll also have plenty of time to chat over lunch and dinner/drinks. We still have room for a few more talks, please propose a talk! (http://www.seapig.org/NorthwestPythonDay for details) Please join us and forward this on to other Python people! From rtw at freenet.co.uk Sat Jan 10 10:19:21 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sat, 10 Jan 2009 09:19:21 -0600 Subject: Mocking `from foo import *` functions References: Message-ID: wrote in news:a9ed10ff-d907-46f0-8c6a- c3d95579a5ab at k1g2000prb.googlegroups.com in comp.lang.python: > To answer to Rob: yeah, sure that would work, but I always thought Just to note: you're answering a question about testing, but I answered how to alter the alerter module *for* testing. given it was the import * that was causing the OP the problem, I tried to address that. > mocking the imported function didn't feel right. The test then depends > on the import method of the tested module. If you later change your > mind and decide to use "import sender" and then "sender.sendEmails()", > you have to change your test code. You have to add: import sender sender.sendEmails = mock_sendEmails to your test script. Note that doing the above *before* any other module imports from sender, will be sufficient in *any* case, though it won't help if the tested code calls reload( sender ). No need to scan every imported module for the mocked function. It also handles the case where other code imports the sender module and calls sendEmails(). For additional robustness the above can be changed to: ## assert sender module hasn't been imported elsewhere yet import sys assert 'sender' not in sys.modules import sender sender.sendEmails = mock_sendEmails Rob. -- http://www.victim-prime.dsl.pipex.com/ From Maksim.Kasimov at gmail.com Sat Jan 10 10:45:53 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Sat, 10 Jan 2009 07:45:53 -0800 (PST) Subject: are there some special about '\x1a' symbol Message-ID: Hi all! I had touch with some different python behavior: I was tried to write into a file a string with the '\x1a' symbol, and for FreeBSD system, it gives expected result: >>> open("test", "w").write('before\x1aafter') >>> open('test').read() 'before\x1aafter' but for my WinXP box, it gives some strange: >>> open("test", "w").write('before\x1aafter') >>> open('test').read() 'before' Here I can write all symbols, but not read. I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. Why is it so and is it possible to fix it? -- Maksim From mdw at distorted.org.uk Sat Jan 10 10:46:35 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 15:46:35 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: [Another tome. I hope this contains sufficient new material to continue to be of interest to other readers.] Steven D'Aprano wrote: > On Fri, 09 Jan 2009 20:23:11 +0000, Mark Wooding wrote: > > > No: not directly. The Python program deals solely with references; > > anything involving actual objects is mediated by the runtime. > > Your claim is ambiguous: when you say "the Python program", are you > talking about the program I write using the Python language, or the > Python VM, or something else? The former. > If the first, then you are wrong: the Python program I write doesn't > deal with references. It deals with objects. Do you have evidence for this claim other than your vigorous assertion? I have evidence: in particular, after the example l = [1, 2, 3] l[1] = l the list l (abuse of terminology: I mean `the list referred to from the location bound to l') has the structure I drew, but you snipped: ,----------, v | +---+ +---+ | l: | *----> | *-----> 1 | +---+ +---+ | | *----------' +---+ | *-----> 3 +---+ Can you explain, without using the concept of references (or anything else equivalent) why this happens, and why the result is not (for example) [1, [1, 2, 3], 3]? > This discussion flounders because we conflate multiple levels of > explanation. No. I'm sticking to a single level of explanation. It may appear to be a lower level than the one you're trying to promote, and therefore contains more detail and is more complicated, but it has the benefit that it explains observed phenomena. > People say "You do foo" when they mean "the Python VM does foo". Since what the programmer does is type at a keyboard, the keystrokes being interpreted eventually as editing commands in a text editor (having been processed by various intermediate pieces of software probably including keyboard drivers, and maybe window systems or terminal line disciplines), anything else is an abuse of terminology; but a useful one. So, the programmer types, with the objective (presumably) of constructing a text file containing a Python program which, when executed by an appropriate Python implementation, will behave in a satisfactory way. The notion of `Python VM' is a good one (though potentially open to confusion -- alas, `virtual machine' has multiple meanings too). So: a Python program can be interpreted as instructions to such a virtual machine, to behave in particular ways. Agreed? The question is: how do we best describe the behaviour of such a Python VM when executing a Python program, given its text? It's far too easy, as we've both shown, to slip into imprecise terminology here. When I write > > You bind names to locations which store immediate representations. > > Python IRs are (in the sense defined above) exclusively references. I mean, of course, that a Python implementation behaves is if it binds `names to locations which store immediate representations'. > I most certainly don't bind names to locations. When I write x=23, I > don't know what the location of the object 23 is, so how could I bind > that location to the name? Quite. A lapse on my part, due to sloppy writing caused by a desire not to make this article any longer than it already was. > You are conflating what the Python VM does with what I do. No... > What *I* do is bind the object 23 to the name x. What you do is described above. It doesn't involve any binding at all, or objects. Unless, that is, you are actually implementing Python personally (i.e., not merely instructing a computer to do so, but actually within your own mind); in which case I claim that you must do so as I have described, or do so wrongly. > I don't know the location of 23, I don't even know if 23 has a > well-defined location I warned that I was using certain terms in a technical sense, and attempted to define them clearly at the top of my article. The word `location' was one such: : * A /location/[1] is an area of memory suitable for storing the : /immediate representation/ (which I shall abbreviate to /IR/) of a : value. (A location may be capable of storing things other than : IRs, e.g., representations of unevaluated expressions in lazily : evaluated languages. Locations may vary in size, e.g., in order : to be capable of storing different types of IRs.) Whether 23 has a location is unimportant. In the context of your example `x = 23', what's important is that the name `x' is bound to a location, and then an immediate representation of the value `23' is stored in that location. (This description holds for all languages I can think of, modulo details of which occurrences of names are binding occurrences, and C++'s user- controlled assignment and so on.) > or if it is some sort of distributed virtual data structure. As a > Python programmer, that's the level I see: names and objects. Only if you want to be confused. Without references one is confused by circular data structures; without locations, one is confused by closures and assignment. There are /two/ layers of indirection between variable names and values in Python. One layer is the mapping between names and locations: the usual term for this mapping is an `environment', and the modification of this mapping is termed `binding'. The other layer is the mapping from locations to values; modification of this mapping is called `assignment'. As an example, I had this conversation with Python 3.0rc1. (Python 2 can't illustrate the situation as clearly since it doesn't have `nonlocal'.) >>> ff = [lambda: x for x in [1, 2, 3]] >>> ff[0]() 3 >>> ff[1]() 3 >>> def getset(x): ... def get(): return x ... def set(y): nonlocal x; x = y ... return get, set ... >>> g, s = getset(42) >>> g() 42 >>> s(69) >>> g() 69 >>> ff = [getset(x) for x in [1, 2, 3]] >>> ff[0][0]() 1 >>> ff[1][0]() 2 >>> ff[1][1](5) >>> ff[1][0]() 5 >>> ff[0][0]() 1 >>> ff[2][0]() 3 Again, your challenge is to explain these phenomena -- all of which, I believe are required behaviour of Python 3 -- without talking about both levels of indirection. > At a lower level, what the Python VM does is store the name 'x' in a > dictionary, bound to the object 23. No locations come into it, because > at this level of explanation, dictionaries are an abstract mapping. You've misunderstood my definition of `location'. Here, the dictionary entry for the key `x' would indeed be the location. As a matter of implementation detail, a `dictionary', as understood by Python users as a kind of Python value which implements an associative array, is not actually used to deal with local variables at run-time. Rather, each bound variable is given an index into a vector allocated at function-entry time; variables which are bound in an outer function are also given indices, and looked up in a different vector, allocated when the closure was constructed. > There's no requirement that the abstract dictionary structure works by > storing addresses. I'd hoped I'd been very careful to avoid talking about addresses! Indeed, I'd gone as far as saying that a location was an area of memory, rather than the address of an area of memory, specifically to avoid that trap. Maybe it'll help at this point if I explain that all of the machinery I described above, together with the definitions of pass-by-value and pass-by-reference, can be converted fairly easily (I hope -- the examples below make some headway here) into a formal semantics, with the (intentionally) undefined notion of `immediate representation' of values left as one of its parameters. The use of terms such as `location' is therefore intended to be /indicative/ of common machine architectures, but not exclusively tied to them, since much more abstract systems -- such as, for example, denotational semantics -- can serve just as well. > All we know is that it maps the name 'x' to the object 23 > somehow. Maybe there's no persistent storage, and the dict stores > instructions telling the VM how to recreate the object 23 when it is > needed. Who knows? But at this explanatory level, there are no > locatives involved. Names and objects float as disembodied entities in > the aether, and dicts map one to the other. Explain the list `l' above using this model. > At an even lower explanatory level, the CPython implementation of > dictionaries works by storing a pointer (or if you prefer, a > reference) to the object in a hash table. Pointers, of course, are > locatives, and so finally we come to the explanation you prefer. No! No, no, no! I want to keep locatives /out/ of the picture, because Python doesn't provide them. > I daresay you probably get annoyed at me when I bring up explanations > at the level of copying bytes. You probably feel that for the average > Python programmer, *most of the time* such explanations are more > obfuscatory than useful. My objective is to explain defined semantics: behaviour common to all Python implementations (real, or imagined). > Of course, there are exceptions, such as explaining why repeated > string concatenation is likely to be slow. There is a time and a place > for such low level explanations, but not at the high-level overview > needed by the average Python programmer. Right: performance is inherently related to implementation details and understanding performance requires an understanding of the implementation behaviour. But that's very different from understanding language semantics, which is (I hope) the topic under discussion. > And you would be right. But I argue that your explanation at the level > of references is exactly the same: it is too low level. It relies on > specific details which may not even be true for all implementations of > Python. No. It introduces concepts which are analogous to the way some implementations behave. But as a model for Python, it works for all implementations. > It certainly relies on details which won't be true for hypothetical > versions of Python running on exotic hardware. If they produce other results for my examples above, then they don't implement Python. > If that's too bizarre for you, think about simulating a Python VM in > your own head. If we know one thing about the human brain, it is that > thoughts and concepts are not stored in single, well-defined > locations, so when you think of "x=23", there is no pointer to a > location in your head. But if I'm implementing Python in my mind, I need to invent a concept of location -- or something isomorphic -- or I'll get the semantics wrong. Indeed, this seems to be exactly what's happening to confused beginners -- they're getting the semantics wrong in their minds, so the real implementation doesn't match their expectations. > > No, that's my point: Python programmers /don't/ have direct access to > > objects. The objects themselves are kept at arm's length by the > > indirection layer of references. > > I think you are wrong. If I want a name 'x' to refers to (is bound to) > the object 23, I write x=23, not some variation of: > > create object 23 > give me a reference to that object > bind the reference to name 'x' > > Those three steps may take places at some level of the Python VM, but > that's not what *I* do as a Python programmer. No. You type; the VM obeys. If you want to understand its behaviour, you must > > * A /value/ is an item of data. The range and nature of values is > > language specific. Typically, values encompass at least some kinds > > of numbers, textual data, and compound data structures; they may > > also include behavioural items such as functions. > > Yes. This is an intuitive meaning of the world value. In Python, all > values are objects. Some typical examples of values are: > > 5, None, "Fred", True, 3.5, [2, 3, 4], {}, lambda x: x+1 > > These (and more complicated structures built on top of them) are the > things of interest to the programmer. They are the values: the things > which are denoted by the symbols '5', 'None', '"Fred"' etc. Good: agreement. We're making progress. > > * A /location/[1] is an area of memory suitable for storing the > > /immediate representation/ (which I shall abbreviate to /IR/) of a > > value. (A location may be capable of storing things other than IRs, > > e.g., representations of unevaluated expressions in lazily evaluated > > languages. Locations may vary in size, e.g., in order to be capable > > of storing different types of IRs.) > > At the level of Python code, we have no access to such locations. The > closest we have is the id() function, which uses location in memory as > a unique ID for objects, but this is an accident of the CPython > implementation. Whatever the /immediate representation/ of a value is, > we can't manipulate it directly in Python code. Indeed we have not. But an understanding of their existence is nonetheless essential in order to comprehend Python semantics. Indeed, it's /because/ the locations are not directly visible to a Python programmer that we can describe them in such abstract terms; but omitting them from the explanation altogether leaves important aspects of behaviour unexplained. > > * A /variable/ is a location to which has been /bound/ a name. Given > > an occurrence of a name in a program's source, there is a language > > specific rule for determining the variable to which it is bound. > > According to this definition, there are no variables in Python, because > Python's data model is that names are an abstract mapping between symbols > and values, not between symbols and locations. Chapter and verse? Besides, `names are an abstract mapping'? Names are names, dammit! Names, symbols, identifiers: all mean the same thing. And again, I challenge you to explain the Python 3 interaction above without the concept of location. > > * /Evaluation/ is the process of determining a value from an > > expression. The /value of/ an expression is the result of > > evaluating the expression. This value is, in general, dependent on > > the contents of the locations to which names appearing in the > > expression are bound. > [...] > > The argument passing model `pass-by-value' has a number of distinctive > > properties. > > > > * The argument expression is fully evaluated before the function is > > called, yielding an argument value. > > > > * The corresponding parameter name is bound to a fresh location. > > > > * The argument value IR is stored in the parameter's location. > > This is an underspecified definition. Without a definition of > /immediate representation/, we can't determine what this means. It is intentionally underspecified, since the immediate representation of values varies between languages, and the whole point was to define the argument passing models in a language-independent manner. > I can guess that, based on Pascal, Fortran and C, the /immediate > representation/ of a value is whatever data structure represents that > value. However, I fear that you are going to try to slip in an > open-ended definition, that /immediate representation/ could be > *anything* -- for ints in C, it will be the bytes that represent the > int; for C arrays, it will be a pointer to the bytes that represent > the array; for Python, it will be references to objects; for Algol 60, > it will be thunks. No slipping involved. The definition is quite intentionally open-ended, and if I didn't make it explicit then I should have done. C arrays are strange: it is simply impossible for an array to be the value of a C expression (except in the very strange case of the operand of `sizeof'); therefore I don't need to define an IR for arrays to get pass-by-value to work: the fact that argument expressions are evaluated eliminates all arrays at the first step. Regarding Algol, no, you can't catch me out that easily. A thunk in Algol represents an /unevaluated expression/. But I've only made use of immediate representation of /values/ -- i.e., the result of fully evaluating an expression. I should have made this explicit: immediate representations are the `common currency' for doing expression evaluation. Expressions are (typically) constructed from subexpressions: to evaluate, one gathers the values of the subexpressions -- recursively if necessary -- and combines them in the appropriate manner to discover the final value. We do this in fact by manipulating immediate representations. One kind of subexpression is typically an identifier: this is an interesting case, so I'll talk about it in detail. To evaluate an identifier, we find the location bound to that identifier, and extract the IR from the location. We've got a lot of types, processes and mappings. Let's make it clear what's going on. Types: N: names V: values R: immediate representations L: locations X: expressions E = N -> L: environments S = L -> R: stores Operations: rep: V -> R value to immediate-representation unrep: R -> V immediate-representation to value eval: (X, E, S) -> (R, S) evaluation alloc: () -> L yields a fresh location (A `store' maintains the mapping between locations and their contents. It's an input to evaluation because one needs to retrieve the contents of variables; it's an output because evaluating some expressions may have side effects on storage.) Names are a kind of expression. The operation of retrieving a variable looks like this: eval(n, e, s) = (s(e(n)), s) That is, we look the name up in the environment to find a location, and we find the contents of the location in the store; the store is unchanged by this operation. Assignment to a variable is straightforward in this model: assgn(n, e, s, r) = (?, s[r/e(n)]) For the unfamiliar: x[y/z] is a function which behaves like x, except that it returns y on input z: i.e., y if a = z x[y/z](a) = { x(a) if a /= z That is, the /value/ of assignment is language-specific (and it may not syntactically be an expression, but statements can be modelled as expressions which yield unspecified values which are unavailable to the program due to syntactic constraints, and this saves us having to introduce another kind of thing). Note that we don't actually need the rep/unrep operations in order to define the semantics, at least until we actually start constructing values. > To avoid weakening pass-by-value to mean everything and anything at > all, I'm going to say that the /immediate representation/ is the bytes > which represent the value. And this decision takes you back round another loop of the argument and leads you to all manner of difficulty. No, the right answer is necessarily language-specific. Besides, I never mentioned bytes when discussing values, and certainly the idea that there might be a unique representation in terms of bytes is completely wrong. I hope I've already shown that my definition of pass-by-value is /not/ so weak as to allow anything at all -- in particular, it doesn't have the same semantics as pass-by-reference or pass-by-name. To this end, let's formalize it some more. Suppose we have an argument expression x, which is part of a call to a function f; x is to be evaluated in environment e, with store s. We first evaluate the argument: (r, s') = eval(x, e, s) We now allocate a fresh location for the corresponding parameter l = alloc() and bind the parameter name -- call it n -- in the function's environment e': e'' = e'[l/n] Finally, we store the argument value representation in the location: s'' = s'[r/l] We do this for all the pass-by-value arguments (it doesn't matter whether we do the parameter stores all at once later or interleaved, because the locations are distinct from all previous locations), augmenting the environment e''. We evaluate the function body with respect to the final store and this augmented environment. This model is now sufficiently detailed that we can /prove/ that implementing `swap' using pass-by-value (as defined here) is impossible. The soundbite version of all of this: pass-by-value means that the parameters are distinct variables, which are initialized by assignment. > (That is, the value itself.) No! Be very careful here. Do not confuse the value with its representation: to do so is to fall into a very nasty trap. A sequence of bytes is not a number, for example, though one may define mappings between the two. > > By contrast, the `pass-by-reference' model has other distinguishing > > properties. > > > > * Whether arbitrary argument expressions are permitted is language > > dependent; often, only a subset of available expressions -- those > > that designate locations -- are permitted. > > As you said above: "The /value of/ an expression is the result of > evaluating the expression". Given the expression 2+3, the result of that > expression is 5, not the location where 5 is stored. Right... > There is no reason to believe that 5 designates a location, as opposed > to designating the number of peas in a pod or the average length of a > piece of string. And indeed I don't think that 5 does designate a location. But fortunately my definition wasn't talking about /values/ designating locations: it was talking about /expressions/ designating locations, and that's entirely different. Considered as expressions, `2 + 3' does not equal `5' -- one contains an addition operator and two subexpressions, each an integer constant, whereas the other is a single constant. The two should produce the same result on evaluation, but that's a different matter. > For want of a better description, let me re-word the above to say: > > * Whether arbitrary argument expressions are permitted is language > dependent; often, only a subset of available expressions -- e.g. those > that evaluate at a named location -- are permitted. > > Note that I say they evaluate *at*, not *to*, a fixed location. Yes, I noticed that, but I don't know what it means. > A practical example, to ensure we're talking about the same thing. In > Pascal, I can declare a procedure swap(a, b) taking two VAR parameters, > which use call-by-reference semantics. I might do something like this: > > a := 8; { number of peas in a pod } > b := 13; { a baker's dozen } > swap(a, b); > > Even though the values of a and b do not designate locations, the > compiler can pass them to the procedure because the named variables a > and b exist *at* particular locations. The values of `a' and `b' aren't important here. What is important is that the /expression/ `a' designates a location, namely the location bound to the name `a'; similarly for `b'. > Contrast this with: > > swap(a, 10+3); And `10 + 3' does not designate a location. (The circumlocution involved with `designating locations' is to cope with expressions like `v[5]' as well as simple names. In some languages, an expression which designates a location is said to produce an `lvalue' rather than an `rvalue'; we can think of an `lvalue' as being a location and an `rvalue' as being an immediate representation: we can convert the former to the latter by consulting the store; but we cannot convert in the other direction without allocating.) > which will fail in Pascal, because the value of the expression 10+3 > doesn't correspond to a named location. (Presumably this is a design > choice, because the value of the expression will certainly exist at a > known location, although possibly not known until runtime.) I think the design choice is that it's not considered meaningful to modify the value of `10 + 3', whereas it is considered meaningful to modify the value of `a'. (In both cases, by `the value of FOO', I mean `the result of evaluating the expression FOO'.) > > If the argument expression does designate a location, then this > > location is the /argument location/. > > Replace this with "If the argument expression does evaluate at an > allowed location (named location for Pascal), then..." and I will > accept it. I still don't know what `evaluate at' means. > > * The corresponding parameter name is bound to the argument location. > > According to this definition, Python is call-by-reference. Refer my > code snippet above. No. Work through it again, now I've explained what's going on more clearly. Here's the more formal version. We need some new notions. Types: D: expressions which designate locations Operations: loc: (D, E, S) -> (L, S) location designated by expression Important: D is a subset of X; if (l, s') = loc(d, e, s) then (axiomatically) (s'(l), s') = eval(d, e, s) If n is a name, then loc(n, e, s) = (e(n), s) (and we can see that this definition is consistent with the one above). So, pass by reference. Let x be the argument expression, e the caller's environment, and s the prevailing store. Firstly, if x in D then (l, s'') = loc(x, e, s) Otherwise (if supported), (r, s') = eval(x, e, s) l = alloc() s'' = s'[r/l] (Note that, after this, we always have (s''(l), s'') = eval(x, e, s).) If n is the corresponding parameter name, and e' is the function's enclosing environment, then all we need to complete the job is e'' = e'[l/n] The significant difference between the two is that, in pass-by-value, the parameter names are /always/ bound to fresh locations, whereas in pass-by-reference this need not be the case. The soundbite version of all of this: pass-by-reference means that new variables are not constructed; rather, new names are given to the caller's variables. > But clearly Python doesn't behave like call-by-reference in other > languages: you can't write a swap() procedure. The definition I've given for call-by-reference should make it possible to write a `swap'. Indeed, `can I write swap?' is a good rule-of-thumb test for call-by-reference -- though it may also detect call-by-name and more exotic things. > This is where I quote Barbara Liskov, talking about the language CLU > which has precisely the same calling semantics as Python: > > "In particular it is not call by value because mutations of arguments > performed by the called routine will be visible to the caller. And it > is not call by reference because access is not given to the variables > of the caller, but merely to certain objects." Quite why she decided that CLU isn't call-by-value, despite it having the same semantics as Lisp which certainly is call-by-value and has been so since 1958 (and may even have introduced the concept!) is a mystery to me. > Once you start declaring that a language is "pass-by-value, where the > value is a Foo rather than the actual value", pass-by-value can be > used to describe *anything*. Pass- by-reference becomes pass-by-value > where the value is the location of the value. No, it can't. Or prove your claim: provide a definition of `immediate representation' which allows one to implement `swap' using call-by-value semantics. > Pass-by-object is pass-by-value where the value is a reference to the > object (your claim). I don't believe in `pass-by-object' as being a different thing, no. > > Even for those. C doesn't pass arrays at all; instead it passes > > (programmer-visible) pointers. See other article. > > But you are conflating concepts again. The value of an array is the > array: it's what the programmer asked for when he declared an array. See > your own definition of value above: "A /value/ is an item of data." Again: in C, the value of an expression cannot be an array (6.3.2.1p3). The definition of pass-by-value requires that the argument expression be evaluated. Therefore, the resulting argument value cannot be an array; it is, instead, a pointer, and that pointer is passed by value. I'll quote 6.3.2.1p3 in full: : [#3] Except when it is the operand of the sizeof operator or the unary : & operator, or is a string literal used to initialize an array, an : expression that has type ``array of type'' is converted to an : expression with type ``pointer to type'' that points to the initial : element of the array object and is not an lvalue. If the array object : has register storage class, the behavior is undefined. This happens logically before function calling: there is a sequence point before the call (6.5.2.2p10). Note that 6.5.2.2 (which defines the behaviour of the function call operator) does not mention arrays at all. Rather, it describes conversion of arguments, as if by assignment, for function types with and without prototypes, and for variadic functions, and then states: : [#8] No other conversions are performed implicitly; in particular, the : number and types of arguments are not compared with those of the : parameters in a function definition that does not include a function : prototype declarator. (6.5.16, which describes assignment, doesn't mention arrays either.) > You get pass-by-value semantics: when you pass an array to foo, the > entire array is duplicated. Changes to x are not visible in the caller's > array. C arrays do not behave like this with an equivalent > declaration. But that's because of the (bizarre) way that arrays are treated during expression evaluation. > Change the declaration to be VAR x, and using pass-by-reference > semantics, and the array is *not* duplicated, and changes to x *are* > visible to the caller. C's default handling of arrays is just like > Pascal's call-by-reference semantics, not like pass-by-value. This is > AFAIK unique in C to arrays. The effect is similar from the point of view of the caller; the cause is very different, as is the whole situation from the point of view of the called function, which is left with an explicit pointer. > > And this is entirely due to the difference in their immediate > > representations of values. > > Values are values. Regardless of whether you are using C or Pascal or > Python, the value of 1+1 is 2, not some arbitrary memory location. I'm > going to quote from Fredrik Lundh: > > "I'm not aware of any language where a reference to an object, rather > than the *contents* of the object, is seen as the object's actual value. > It's definitely not true for Python, at least." And that's why I've been at such pains to distinguish the /immediate representation/ of the value from the value itself. > The viewpoint that values are references is bizarre and counter- > intuitive, and it leaves us with no simple way of talking about the value > of expressions in the sense that 2 is the value of the expression 1+1. Unless one introduces the necessary concept of representation. Fortunately I did that. -- [mdw] From mdw at distorted.org.uk Sat Jan 10 10:49:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 15:49:17 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Agreed. I think the docs, especially those that develop > the conceptual model of how Python work at runtime, could > use some major attention. If we can achieve consensus in this (still remarkably civil) discussion, we might be able to amend the docs. > I would be willing to bet that most of the confused posters do not > distinguish between assignment operation (AO) and data model (DM). > Their conceptual box is labeled "assignment behavior" and includes > both AO and DM. They expect that AO+DM in Python will produce the > same results in Python as they are used to in the other languages > they've used. That the discrepancy comes from the DM part rather than > the AO part is pretty irrelevant to them given that world view. I think that we're in agreement, up to this point at least. That's good. My claim is that, until they learn to distinguish these two aspects of Python's semantics, they will remain confused. -- [mdw] From hsoft at hardcoded.net Sat Jan 10 10:49:20 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Sat, 10 Jan 2009 07:49:20 -0800 (PST) Subject: Mocking `from foo import *` functions References: Message-ID: <68239214-859a-4484-91b1-ec208393d28d@f40g2000pri.googlegroups.com> On Jan 10, 4:19?pm, Rob Williscroft wrote: > Note that doing the above *before* any other module imports > from sender, will be sufficient in *any* case, though it won't > help if the tested code calls reload( sender ). Yeah, of course, but most of the time, you want to mock at the *test* level, (you don't want your mock to affect all the tests in your module), so you can't just mock the function before you import your tested module. That is why I created this handy TestCase. From mwilson at the-wire.com Sat Jan 10 11:04:19 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 10 Jan 2009 11:04:19 -0500 Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: Aaron Brady wrote: > Lastly, I don't see any reason why we couldn't make both explanations > available. 'For those coming from Java/etc....; for those coming from > C++/etc.....' They would both get read. That's what I was just thinking .. there are lots of others, too: "for those coming from relational database theory..." would be a good one. Mel. From bj_666 at gmx.net Sat Jan 10 11:08:35 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 10 Jan 2009 16:08:35 GMT Subject: are there some special about '\x1a' symbol References: Message-ID: <6srvg2F7o3lrU2@mid.uni-berlin.de> On Sat, 10 Jan 2009 07:45:53 -0800, sim.sim wrote: > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, it > gives expected result: > >>>> open("test", "w").write('before\x1aafter') open('test').read() > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > >>>> open("test", "w").write('before\x1aafter') open('test').read() > 'before' > > Here I can write all symbols, but not read. I've tested it with python > 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? \x1a is treated as "end of text" character in text files by Windows. So if you want all, unaltered data, open the file in binary mode ('rb' and 'wb'). Ciao, Marc 'BlackJack' Rintsch From mwilson at the-wire.com Sat Jan 10 11:27:40 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 10 Jan 2009 11:27:40 -0500 Subject: are there some special about '\x1a' symbol References: Message-ID: sim.sim wrote: > Hi all! > > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, > it gives expected result: > >>>> open("test", "w").write('before\x1aafter') >>>> open('test').read() > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > >>>> open("test", "w").write('before\x1aafter') >>>> open('test').read() > 'before' > > Here I can write all symbols, but not read. > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? '\x1a' is the End-of-file mark that Windows inherited from MS-DOS and CP/M. The underlying Windows libraries honour it for files opened in text mode. open ('test', 'rb').read() will read the whole file. Mel. From rt8396 at gmail.com Sat Jan 10 11:45:31 2009 From: rt8396 at gmail.com (r) Date: Sat, 10 Jan 2009 08:45:31 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> We need TK 8.5's themes. This will bring Tkinter out of the dark ages and into the 21st Century! And improve the shine of the Python base distro. Python could use a good boost right now! From davidgshi at yahoo.co.uk Sat Jan 10 12:12:30 2009 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 10 Jan 2009 17:12:30 +0000 (GMT) Subject: Looking for an efficient Python script to download and save a .zip file programmatically Message-ID: <324592.49250.qm@web26307.mail.ukl.yahoo.com> I am looking for an efficient Python script to download and save a .zip file programmatically (from http or https call). ? Regards. ? David -------------- next part -------------- An HTML attachment was scrubbed... URL: From bockman at virgilio.it Sat Jan 10 12:39:55 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sat, 10 Jan 2009 18:39:55 +0100 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > Marc 'BlackJack' Rintsch wrote: >> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: >> >>> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >>> thing in C also: >> >> Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: >> >> #!/usr/bin/env python >> from __future__ import division, with_statement >> import os >> import sys >> from collections import defaultdict >> from functools import partial >> from itertools import imap >> >> >> def iter_max_values(blocks, block_count): >> for i, block in enumerate(blocks): >> histogram = defaultdict(int) >> for byte in block: >> histogram[byte] += 1 >> >> yield max((count, byte) >> for value, count in histogram.iteritems())[1] >> > [snip] > Would it be faster if histogram was a list initialised to [0] * 256? I tried it on my computer, also getting character codes with struct.unpack, like this: histogram = [0,]*256 for byte in struct.unpack( '%dB'%len(block), block ): histogram[byte] +=1 yield max(( count, byte ) for idx, count in enumerate(histogram))[1] and I also removed the map( ord ... ) statement in main program, since iter_max_values mow returns character codes directly. The result is 10 minutes against the 13 of the original 'BlackJack's code on my PC (iMac Intel python 2.6.1). Strangely, using histogram = array.array( 'i', [0,]*256 ) gives again 13 minutes, even if I create the array outside the loop and then use histogram[:] = zero_array to reset the values. Ciao ----- FB From lipun4u at gmail.com Sat Jan 10 12:56:19 2009 From: lipun4u at gmail.com (asit) Date: Sat, 10 Jan 2009 09:56:19 -0800 (PST) Subject: urlopen exception Message-ID: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> site="www.bput.org" payloads="" attack= urllib2.urlopen(site+payloads,80).readlines() according to my best knowledge, the above code is correct. but why it throws exceptio ???? From marduk at letterboxes.org Sat Jan 10 13:09:17 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 10 Jan 2009 13:09:17 -0500 Subject: Looking for an efficient Python script to download and save a .zip file programmatically In-Reply-To: <324592.49250.qm@web26307.mail.ukl.yahoo.com> References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: <1231610957.3226.1.camel@blackwidow.nbk> On Sat, 2009-01-10 at 17:12 +0000, David Shi wrote: > I am looking for an efficient Python script to download and save > a .zip file programmatically (from http or https call). > > Regards. > > David urllib? -a -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Jan 10 13:22:00 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 10 Jan 2009 13:22:00 -0500 Subject: if-else statement In-Reply-To: References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: <83D3AADE-455A-4170-A340-C2DA3EB75EF2@semanchuk.com> On Jan 10, 2009, at 9:26 AM, Duncan Booth wrote: > Gandalf wrote: > >> other languages like PHP or javascript as this if-else operator like >> this >> >> myVar = checking == 1? 'string': 'other string' >> >> is this stuff exist in python? >> > See http://docs.python.org/reference/expressions.html#boolean-operations > > conditional_expression ::= or_test ["if" or_test "else" expression] > > ... > > The expression x if C else y first evaluates C (not x); if C is > true, x is > evaluated and its value is returned; otherwise, y is evaluated and its > value is returned. Gandalf, I'd add to the above that this expression was only added to Python in v2.5, so if you want your code to be compatible with versions of Python <= 2.4, you should not use the ternary if. bye Philip From rurpy at yahoo.com Sat Jan 10 13:44:37 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 10 Jan 2009 10:44:37 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Message-ID: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> On Jan 9, 6:47 am, Mark Wooding wrote: > ru... at yahoo.com wrote: > > As a side comment (because it always bugs me when I read this, even > > though I read it in very authoritative sources), ISTM that C passes > > everything by value except arrays; they are passed by reference (by > > passing a pointer to the array by value.) Admittedly, the close > > relationship between arrays and pointers makes it easy conflate them. > > Arrays are distinctly second-class citizens in C. > > Basically, in C, arrays aren't passed at all but there's some syntactic > sugar so you can squint and con yourself that they're passed by > reference. > > If you try to pass an array, the array name immediately decays to a > pointer, and the pointer gets passed instead -- by value. The > corresponding function parameter must be a pointer to an approrpriate > kind of thing, though you're allowed to write []s to confuse yourself if > you like -- T D[] in a function parameter declaration means precisely > the same as T *D -- to the extent that &D has type T **D and so on. What is the observable difference between converting an array to a reference (pointer) to that array and passing the reference by value, and passing the array by reference? That is, given a C-like compiler that is the same as C except that it passes arrays by reference, how would it differ from an ordinary C compiler? The choice of terminology (in this case) seems to me to be a matter of convention rather than any fundamental observable difference. I guess the case for pass-by-value would be a little stronger because one has to have "passing a pointer by value" anyway (since pointers are first-class datatypes) and that can be used to describe passing arrays (as you described). Adding a second mechanism, "passing-arrays-by-reference", is perhaps unnecessary, but not wrong, and may be more easily understandable to the target audience. From ryandw at gmail.com Sat Jan 10 14:15:45 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 10 Jan 2009 11:15:45 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> Message-ID: <64bd3670-b642-48d0-8edb-a5c24121a0a8@r37g2000prr.googlegroups.com> On Jan 9, 6:07?pm, John Machin wrote: > Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as > God^H^H^HGates intended: > > >>> buff = open('data', 'rb').read() > >>> buff[:100] > > '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> > \x00<\x00B\x0 > 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> > \x000\x00.\x000\x000\x000\x000\x0 > 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< > \x00S\x00t\x0 > 0a\x00t\x00'>>> buff[:100].decode('utf_16_le') There it is. Thanks. > u'0.0000 > > > > ?But if I return it to my browser with python+django, > > there are bad characters every other character > > Please consider that we might have difficulty guessing what "return it > to my browser with python+django" means. Show actual code. I did stop and consider what code to show. I tried to show only the code that seemed relevant, as there are sometimes complaints on this and other groups when someone shows more than the relevant code. You solved my problem with decode('utf_16_le'). I can't find any description of that encoding on the WWW... and I thought *everything* was on the WWW. :) I didn't know the data was utf_16_le-encoded because I'm getting it from a service. I don't even know if *they* know what encoding they used. I'm not sure how you knew what the encoding was. > Please consider reading the Unicode HOWTO athttp://docs.python.org/howto/unicode.html Probably wouldn't hurt, though reading that HOWTO wouldn't have given me the encoding, I don't think. -Ryan > Cheers, > John From mdw at distorted.org.uk Sat Jan 10 14:31:57 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 19:31:57 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? For one: #include static size_t foo(char v[]) { return sizeof v; } int main(void) { char v[sizeof(char *) * 10]; puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); return (0); } For another: static void bar(char v[]) { char ch = 0; v = &ch; } /* type error if arrays truly passed by reference */ > I guess the case for pass-by-value would be a little stronger because > one has to have "passing a pointer by value" anyway (since pointers > are first-class datatypes) and that can be used to describe passing > arrays (as you described). The difference is that the /callee/ function is different between the two cases. Also, notice that arrays in expressions turn into pointers in the same way, so function argument passing works the same way as assignment -- a hallmark of pass-by-value. -- [mdw] From ryandw at gmail.com Sat Jan 10 14:32:01 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 10 Jan 2009 11:32:01 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> Message-ID: <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> On Jan 9, 7:33?pm, John Machin wrote: > It is not impossible for a file with dummy data to have been > handcrafted or otherwise produced by a process different to that used > for a real-data file. I knew it was produced by the same process, or I wouldn't have shared it. : ) But you couldn't have known that. > > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick > with one thread ... Thanks... I thought I was posting about separate issues and would annoy people who were only interested in one of the issues if I put them both in the same thread. I guess all posts re: the same script should go in one thread, even if the questions posed may be unrelated and may be separate issues. There are grey areas. Problem solved in John Machin's post at http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/03b8341539d87989?hl=en&lnk=raot#03b8341539d87989 I'll post the final code when it's prettier. -Ryan From gnewsg at gmail.com Sat Jan 10 14:37:42 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 10 Jan 2009 11:37:42 -0800 (PST) Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: On 10 Gen, 03:07, "p." wrote: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? You could retrieve your file in little parts and at the same time have a thread which checks how many bytes have been transmitted every second. --- Giampaolo http://code.google.com/p/pyftpdlib From gnewsg at gmail.com Sat Jan 10 14:39:04 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 10 Jan 2009 11:39:04 -0800 (PST) Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: I'm sorry. I realized they had already replied when it was too late. --- Giampaolo http://code.google.com/p/pyftpdlib From joe at strout.net Sat Jan 10 14:49:48 2009 From: joe at strout.net (Joe Strout) Date: Sat, 10 Jan 2009 12:49:48 -0700 Subject: why cannot assign to function call In-Reply-To: References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <4968FBDC.4030202@strout.net> Aaron Brady wrote: >> Aaron Brady wrote: >>> Possible compromise. You can think of functions as mutation-only. >>> You pass the object, and it gets a new (additional) name. The old >>> name doesn't go in. >> That's correct. The reference itself is passed in, not the variable (or >> expression) that held or generated the reference in the calling code. > > This is very odd, and I see it quite a bit. > Me: "You pass the object." > Joe: "That's correct. You pass the reference." > > What was wrong with my original? I'm saying that I believe your idea was correct, but worded imprecisely (IMHO of course). So I restated what I believed you were saying, using terminology which I believe to be more precise. If nothing else, this gives you the opportunity to say "No, that's not what I meant at all." >> This is true. (Technically, instead of variable, we should say "LValue" >> here -- there are things slightly more complex than simple variables >> that can serve as the left-hand side of an assignment. So replace >> "variable" with "lvalue" above if you prefer.) > > This is a point worth making. I want to penny-pinch every term in an > introductory text, though, so, it's a tough call. Agreed. >> M2: If 'fun()' returned a reference, you might be able to mutate the >> object that refers to. >> m2: You can sometimes mutate the object it refers to. >> C2: 'fun()' returns a reference. > > This is horrendous. > http://en.wikipedia.org/wiki/Formal_fallacy > http://en.wikipedia.org/wiki/Affirming_the_consequent I did point out that the logic was incorrect (even though the conclusion, in this case, happens to be true). > A question: Are you Joe and you Mark certain that the simplest > possible introductory explanation makes use of the term 'reference'? I am. > Perhaps we can have a contest for shortest/simplest/best description > of Python's data/variable/argument model. Sure -- but it judging it might be difficult, requiring some newbies and a test to check their comprehension (as you and I pondered once before). > Lastly, I don't see any reason why we couldn't make both explanations > available. 'For those coming from Java/etc....; for those coming from > C++/etc.....' They would both get read. Yes, except that the reference explanation applies equally well to anyone coming from Java, C/C++, RB, VB.NET, and probably others... I'm not sure to whom the other explanation would appeal, unless perhaps it's LISP programmers (just a guess, since those on that side of the aisle seem to invoke LISP more frequently). Best, - Joe From joe at strout.net Sat Jan 10 14:52:47 2009 From: joe at strout.net (Joe Strout) Date: Sat, 10 Jan 2009 12:52:47 -0700 Subject: why cannot assign to function call In-Reply-To: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <4968FC8F.2070306@strout.net> rurpy at yahoo.com wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? The difference is whether an assignment to the formal parameter (within the function) affects the actual parameter (in the calling code). If it does, then that's pass by reference. If it does not, then that's pass by value. > That is, given a C-like compiler that is the same as > C except that it passes arrays by reference, how would > it differ from an ordinary C compiler? Such a compiler is available: it's called C++, and it gives the programmer the choice to pass by value or pass by reference (the latter indicated by adding "&" to the parameter in the function declaration, just like you would add "ByRef" in RB or VB.NET). If the parameter is called "foo", and you pass in "bar", then foo = SomeNewArray(); would change bar if it were passed by reference; it would not affect bar at all if it were passed by value. The two are quite distinct. Best, - Joe From Scott.Daniels at Acm.Org Sat Jan 10 15:12:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 10 Jan 2009 12:12:07 -0800 Subject: if-else statement In-Reply-To: References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: Duncan Booth wrote: > Gandalf wrote: >> other languages ... [have an] if-else operator like... >> myVar = checking == 1? 'string': 'other string' > See http://docs.python.org/reference/expressions.html#boolean-operations > ... > The expression x if C else y first evaluates C (not x); if C is true, x is > evaluated and its value is returned; otherwise, y is evaluated and its > value is returned. While we _do_ have the form if else , it is generally agreed that in most cases your code will be more clear with explicit tests and assignments. Your particular example is better if checking: my_var = 'string' else: my_var = 'other string' remember, vertical space only kills trees if printed. --Scott David Daniels (who still prints this too frequently). Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sat Jan 10 15:28:47 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 10 Jan 2009 12:28:47 -0800 (PST) Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: <96d8f9f5-2679-4855-8b8a-7caaf4e5a410@b38g2000prf.googlegroups.com> Scott David Daniels: > ? ? ? if checking: > ? ? ? ? ? my_var = 'string' > ? ? ? else: > ? ? ? ? ? my_var = 'other string' > > remember, vertical space only kills trees if printed. I value clarity a lot. But this is more DRY, sometimes it's almost equally clear, and you reduce vertical space, packing more code in the same space, this allows you to see more logic, allowing you to have a higher level view of the code, so allows you to understand the code better: my_var = 'string' if checking else 'other string' So I think that sometimes it's useful. Bye, bearophile From steve at holdenweb.com Sat Jan 10 15:32:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 15:32:52 -0500 Subject: urlopen exception In-Reply-To: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: asit wrote: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? what exception it throw? -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Sat Jan 10 15:42:28 2009 From: http (Paul Rubin) Date: 10 Jan 2009 12:42:28 -0800 Subject: urlopen exception References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: <7xbpuesxjf.fsf@ruckus.brouhaha.com> asit writes: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? The code is incorrect. Look at the string ou are sending into urlopen. What on earth are you trying to do? From excord80 at gmail.com Sat Jan 10 16:05:39 2009 From: excord80 at gmail.com (excord80) Date: Sat, 10 Jan 2009 13:05:39 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> Message-ID: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> On Jan 10, 11:45?am, r wrote: > We need TK 8.5's themes. This will bring Tkinter out of the dark ages > and into the 21st Century! And improve the shine of the Python base > distro. Python could use a good boost right now! Could someone please explain what Tix provides compared to what the new stuff in Tk 8.5 provides? Is there much overlap? From sjmachin at lexicon.net Sat Jan 10 16:18:14 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 10 Jan 2009 13:18:14 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> <64bd3670-b642-48d0-8edb-a5c24121a0a8@r37g2000prr.googlegroups.com> Message-ID: <25480c03-26e6-4f77-8d83-87a3aa5fc6a0@v5g2000prm.googlegroups.com> On Jan 11, 6:15?am, webcomm wrote: > On Jan 9, 6:07?pm, John Machin wrote: > > > Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as > > God^H^H^HGates intended: > > > >>> buff = open('data', 'rb').read() > > >>> buff[:100] > > > '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> > > \x00<\x00B\x0 > > 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> > > \x000\x00.\x000\x000\x000\x000\x0 > > 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< > > \x00S\x00t\x0 > > 0a\x00t\x00' > > >>> buff[:100].decode('utf_16_le') > > There it is. ?Thanks. > > > u'0.0000 > > > ?But if I return it to my browser with python+django, > > > there are bad characters every other character > > > Please consider that we might have difficulty guessing what "return it > > to my browser with python+django" means. Show actual code. > > I did stop and consider what code to show. ?I tried to show only the > code that seemed relevant, as there are sometimes complaints on this > and other groups when someone shows more than the relevant code. ?You > solved my problem with decode('utf_16_le'). ?I can't find any > description of that encoding on the WWW... and I thought *everything* > was on the WWW. ?:) Try searching using the official name UTF-16LE ... looks like a blind spot in the approximate matching algorithm(s) used by the search engine (s) that you tried :-( > I didn't know the data was utf_16_le-encoded because I'm getting it > from a service. ?I don't even know if *they* know what encoding they > used. ?I'm not sure how you knew what the encoding was. Actually looked at the raw data. Pattern appeared to be an alternation of 1 "meaningful" byte and one zero ('\x00') byte: => UTF16*. No BOM ('\xFE\xFF' or '\xFF\xFE') at start of file: => UTF16-?E. First byte is meaningful: => UTF16-LE. > > Please consider reading the Unicode HOWTO at http://docs.python.org/howto/unicode.html > > Probably wouldn't hurt, Definitely won't hurt. Could even help. > though reading that HOWTO wouldn't have given > me the encoding, I don't think. It wasn't intended to give you the encoding. Just read it. Cheers, John From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:28:32 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:28:32 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path? I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:29:22 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:29:22 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <5ebf9dbd-1666-49f6-ad31-e6a4e0a91e52@g3g2000pre.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path on MacOSX? I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:30:36 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:30:36 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <7e187df9-e6d8-4c49-94ad-74c2f8ec5297@i18g2000prf.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path on Mac OSX Leopard 10.5.x. I found out that I could use @executable_path but I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From sjmachin at lexicon.net Sat Jan 10 16:40:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 10 Jan 2009 13:40:44 -0800 (PST) Subject: are there some special about '\x1a' symbol References: Message-ID: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> On Jan 11, 2:45?am, "sim.sim" wrote: > Hi all! > > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, > it gives expected result: > > >>> open("test", "w").write('before\x1aafter') > >>> open('test').read() > > 'before\x1aafter' > > but for my WinXP box, it gives some strange: > > >>> open("test", "w").write('before\x1aafter') > >>> open('test').read() > > 'before' > > Here I can write all symbols, but not read. > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? You've already got two good answers, but this might add a little more explanation: You will aware that in Windows Command Prompt, to exit the interactive mode of Python (among others), you need to type Ctrl-Z ... | C:\junk>python | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> problem = '\x1a' | >>> ord(problem) | 26 | >>> # What is the 26th letter of the English/ASCII alphabet? | ... | >>> ^Z | | C:\junk> HTH, John From martin at v.loewis.de Sat Jan 10 16:47:49 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 10 Jan 2009 22:47:49 +0100 Subject: Python 2.6.1 @executable_path In-Reply-To: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> Message-ID: <49691785$0$25150$9b622d9e@news.freenet.de> > I asked something similar a few days ago. Is it possible to compile > Python 2.6.1 with a dynamic path? What is a "dynamic path"? Regards, Martin From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:55:43 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:55:43 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: <5ebb4054-89d3-4261-b218-f4fa3d841766@35g2000pry.googlegroups.com> I want to embedd it into another app so on the 'customers'-mac I want to put python into a subdirectory of my app. bye From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:57:27 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:57:27 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: I want to embedd it into my app so on the 'customers'-mac I want to put python into a subdirectory of my app. and with the configure command above, that will not work because the library has to be on every system in /Library/Framework/ so I found out that @executable_path is replaced by the path of the app. bye From nad at acm.org Sat Jan 10 17:11:49 2009 From: nad at acm.org (Ned Deily) Date: Sat, 10 Jan 2009 14:11:49 -0800 Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: In article , googler.1.webmaster at spamgourmet.com wrote: > I want to embedd it into my app so on the 'customers'-mac I want > to put python into a subdirectory of my app. > > and with the configure command above, that will not work > because the library has to be on every system in /Library/Framework/ > so I found out that @executable_path is replaced by the path of the > app. Have you looked at py2app yet? It should take care of all that for you. http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html -- Ned Deily, nad at acm.org From clp2 at rebertia.com Sat Jan 10 17:23:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 14:23:08 -0800 Subject: Looking for an efficient Python script to download and save a .zip file programmatically In-Reply-To: <324592.49250.qm@web26307.mail.ukl.yahoo.com> References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: <50697b2c0901101423x4ac9608ekc31570459f459ea2@mail.gmail.com> On Sat, Jan 10, 2009 at 9:12 AM, David Shi wrote: > I am looking for an efficient Python script to download and save a .zip file > programmatically (from http or https call). You want urllib.urlretrieve(): http://docs.python.org/library/urllib.html#urllib.urlretrieve Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From googler.1.webmaster at spamgourmet.com Sat Jan 10 17:26:14 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 14:26:14 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Thanks for the link but I don't want to do a make a python script as an applicatin, I want to embedd python into a C++ app so thats the reason why I have to compile Python. From rt8396 at gmail.com Sat Jan 10 17:27:33 2009 From: rt8396 at gmail.com (r) Date: Sat, 10 Jan 2009 14:27:33 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <4f51f4e1-0a7b-4efd-bedb-dedb59776ad9@35g2000pry.googlegroups.com> On Jan 10, 3:05?pm, excord80 wrote: > On Jan 10, 11:45?am, r wrote: > > > We need TK 8.5's themes. This will bring Tkinter out of the dark ages > > and into the 21st Century! And improve the shine of the Python base > > distro. Python could use a good boost right now! > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? TIX is just a set of compound widgets that were not included in the base Python Tkinter distro(notebook, label entry, etc... Now, it looks like they are standard. The new 8.5 TK includes support for OS specific themes, so as to give a more native feel to TK apps, hence the 21st century analogy :) From clp2 at rebertia.com Sat Jan 10 17:32:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 14:32:24 -0800 Subject: urlopen exception In-Reply-To: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: <50697b2c0901101432n1ecd0fe7v4fd3d09f0feb2347@mail.gmail.com> On Sat, Jan 10, 2009 at 9:56 AM, asit wrote: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? Because it's not correct. It's trying to load www.bput.org which is definitely not a valid URL. Also, you need to specify the protocol in the URL, i.e. http:// Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From kw at codebykevin.com Sat Jan 10 17:41:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 10 Jan 2009 17:41:58 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <49692436.1010306@codebykevin.com> excord80 wrote: > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? Tix is a compiled Tk extension that adds a good number of widgets to the base set, such as a notebook tab, treeview, combobox, and others; Python includes a Tix wrapper as part of the standard library. However, it has not undergone much development over the past several years, and its widgets look very outdated (they have a mid-90s feel to them). The themed Tk widgets (ttk) that come with Tk 8.5 add a lot of the same things that Tix does, but they do so in a more modern way, hooking into platform-specific themes and API's wherever possible (XP, Vista, Mac) and updating the generic X11 look as well. As such, they are more appropriate for modern development. Tix is more of a legacy toolkit. A Python wrapper for ttk can be found here: http://code.google.com/p/python-ttk/ It will be added to the standard library at some point, probably for Python 3.1. Here are some screenshots: http://code.google.com/p/python-ttk/wiki/Screenshots HTH, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sat Jan 10 17:43:42 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 10 Jan 2009 17:43:42 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <4969249E.2040701@codebykevin.com> excord80 wrote: > On Jan 10, 11:45 am, r wrote: >> We need TK 8.5's themes. This will bring Tkinter out of the dark ages >> and into the 21st Century! And improve the shine of the Python base >> distro. Python could use a good boost right now! > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? And here are some Tix screenshots: http://tixlibrary.sourceforge.net/screenshots/index.shtml -- Kevin Walzer Code by Kevin http://www.codebykevin.com From Lie.1296 at gmail.com Sat Jan 10 18:07:55 2009 From: Lie.1296 at gmail.com (Lie) Date: Sat, 10 Jan 2009 15:07:55 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016eba68$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 3, 10:23?am, r wrote: > On Jan 2, 7:46?pm, Steven D'Aprano wrote: > > ...incessant rambling about a news reader , 101 excuses for butting > into a thread > [snip] ... public display of ignorance of newsgroup ethics, 101 excuses for not knowing proper terminologies. > Throw your newsreader in the garbage and use Google groups, less > headache, more filling! > Really? I found Google Groups lacking for many thing. Google Groups' only advantage is being browser-based. > No need to worry about > "hidden headers" And you may even get a star or 2 :) Don't you realize that even Google Groups handles those hidden headers too. And that the hidden headers aren't really hidden, even in Google Groups. > > If people are ignoring a thread, they won't even see your post even though you have changed the subject line. > > Yea NO $#Y, that makes a lot of sense, if i am ignoring something i > course i will not see it! > OK, Steven so you did not go off topic you simply high-jacked this > thread. I get it now :) "Yea NO $#Y", that doesn't make sense. Yea or NO? or $#Y? From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 18:28:09 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 23:28:09 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <017925b8$0$8693$c3e8da3@news.astraweb.com> On Sat, 10 Jan 2009 12:52:47 -0700, Joe Strout wrote: >> What is the observable difference between converting an array to a >> reference (pointer) to that array and passing the reference by value, >> and passing the array by reference? > > The difference is whether an assignment to the formal parameter (within > the function) affects the actual parameter (in the calling code). If it > does, then that's pass by reference. If it does not, then that's pass > by value. Such a definition is incomplete. You are mischaracterising call-by- reference as defined by a single binary state: assignment either affects the caller, or it doesn't. If it does, it is p-b-r, if it doesn't, it's p- b-v. According to this definition, there are no other argument passing strategies possible. That's an enormously broad brush by which you sweep away decades of comp sci terminology. Not just Barbara Liskov and pass-by- object, but Algol's thunk-based pass-by-name and Haskell's pass-by-need. In other words, you have created a false dichotomy between pass-by- reference and pass-by-value. There are actually three fundamental characteristics of pass-by-reference: * passing a value by reference does not lead to the value being copied, in contrast with pass-by-value where it does; * modifications to the value passed by reference are visible to the caller; * assignments to the value passed by reference are visible to the caller. Pascal VAR parameters have all three characteristics. Pascal non-VAR parameters have none of them. Python parameters have two of the three. C parameters (call-by-value) have none of them, except for arrays, where they have all three, making arrays in C behave just like Pascal pass-by- reference VAR parameters. -- Steven From MrJean1 at gmail.com Sat Jan 10 18:49:20 2009 From: MrJean1 at gmail.com (MrJean1) Date: Sat, 10 Jan 2009 15:49:20 -0800 (PST) Subject: Looking for an efficient Python script to download and save a .zip file programmatically References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: Here are some examples using urllib.urlretrieve(): /Jean Brouwers On Jan 10, 2:23?pm, Chris Rebert wrote: > On Sat, Jan 10, 2009 at 9:12 AM, David Shi wrote: > > I am looking for an efficient Python script to download and save a .zip file > > programmatically (from http or https call). > > You want urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com From Nicolas.Thiery at u-psud.fr Sat Jan 10 18:59:50 2009 From: Nicolas.Thiery at u-psud.fr (=?ISO-8859-1?Q?Nicolas_M=2E_Thi=E9ry?=) Date: Sat, 10 Jan 2009 15:59:50 -0800 (PST) Subject: Pickling classes (not class instances) Message-ID: <582b45b4-ed93-4a05-9c7b-7f72da34861d@r36g2000prf.googlegroups.com> Dear python developers, Purpose of this e-mail: ----------------------- How to customize how a class (not an instance of a class!!!) is pickled? Example: ============================================================================== class metaclass(type): def __new__(mcs, name, bases, dict): print " running metaclass.__new__" return type.__new__(mcs, name, bases, dict) # def __reduce_class__(self): print "reducing a class" # do the real work c = metaclass("foo", (object,), dict()) import copy_reg copy_reg.pickle(metaclass, metaclass.__reduce_class__) pickle.dumps(c) --------------------------------------------------------------------------- PicklingError Traceback (most recent call last) ... PicklingError: Can't pickle : it's not found as __main__.foo ============================================================================== Context: -------- I am working on the Sage project (www.sagemath.org), and more precisely on the category infrastructure. The code is building lots of classes on the fly by composing preexisting classes by inheritance (for the curious, see the doc of the class Category in http://sage.math.washington.edu:2144/file/1567cea09170/categories-nt.patch). Since those classes are built on the fly, they cannot be pickled with the default mechanism of name lookup. A proper pickling would be to rebuild the class anew. Nothing problematic, except for the question above. Discussion: ----------- It sounds like copy_reg would be the natural way to go (as in the example above). However, its documentation suggests that it explicitly is not intended for pickling classes, e.g. first paragraph of: http://docs.python.org/library/copy_reg.html#module-copy_reg is: The copy_reg module provides support for the pickle and cPickle modules. The copy module is likely to use this in the future as well. It provides configuration information about object constructors which are not classes. Such constructors may be factory functions or class instances. And indeed, looking up at the code of pickle (l. 289-299 of pickle.py) (and similarly in cpickle), the copy-reg dispatch is explicit bypassed for metaclasses: # Check for a class with a custom metaclass; treat as regular class try: issc = issubclass(t, TypeType) except TypeError: # t is not a class (old Boost; see SF #502085) issc = 0 if issc: self.save_global(obj) return # Check copy_reg.dispatch_table reduce = dispatch_table.get(t) Which causes the failure above. Is there a specific reason for this restriction? Would it be thinkable to move up the copy reg dispatch before the metaclass treatment in pickle and cPickle? I did it locally, and it fixed my problem. If not, what would be the right way to achieve this? Many thanks in advance! Best regards, Nicolas -- Nicolas M. Thi?ry "Isil" http://Nicolas.Thiery.name/ From rhodri at wildebst.demon.co.uk Sat Jan 10 20:22:48 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 11 Jan 2009 01:22:48 -0000 Subject: why cannot assign to function call In-Reply-To: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: On Sat, 10 Jan 2009 18:44:37 -0000, wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? This is a red herring, though. From either viewpoint, C arrays are anomalous in comparison with other C data types. -- Rhodri James *-* Wildebeeste Herder to the Masses From schickb at gmail.com Sat Jan 10 20:56:14 2009 From: schickb at gmail.com (schickb) Date: Sat, 10 Jan 2009 17:56:14 -0800 (PST) Subject: Regex for unicode letter characters Message-ID: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> I need a regex that will match strings containing only unicode letter characters (not including numeric or the _ character). I was surprised to find the 're' module does not include a special character class for this already (python 2.6). Or did I miss something? It seems like this would be a very common need. Is the following the only option to generate the character class (based on an old post by Martin v. L?wis )? import unicodedata, sys def letters(): start = end = None result = [] for index in xrange(sys.maxunicode + 1): c = unichr(index) if unicodedata.category(c)[0] == 'L': if start is None: start = end = c else: end = c elif start: if start == end: result.append(start) else: result.append(start + "-" + end) start = None return u'[' + u''.join(result) + u']' Seems rather cumbersome. -Brad From rocky.bernstein at gmail.com Sat Jan 10 21:11:51 2009 From: rocky.bernstein at gmail.com (rocky) Date: Sat, 10 Jan 2009 18:11:51 -0800 (PST) Subject: import relative (with a directory) Message-ID: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Import relative? Recently for fun I've been working on a large Python program. It has many files/modules spread over several directories/submodules. Each module has some "demo" code at the end that I can use to run or experiment with that module. Of course, modules often refer to others; depending on which one, more of the code may get pulled in or not. In this situation it has been very convenient to have do "import relative" which is like import, but I get to specify where to start searching from. Of course I can set sys.path, but I find that hokey. (When I write systems administration scripts, I also generally prefer specifying a full path name to a program, e.g. /bin/mount rather than using PATH. Strikes me as the same issue here). The other thing about the Python import mechanism that sometimes gets in the way is that if there is a module imported (from the wrong place for this context), it tacitly gets used. Within such a project I want to specify when I want the code in this project, and if it can't find that, then that's a failure. I'm curious if other have the same problem and how other they deal with this? Reading "Expert Python Programming", I see that one solution is to install into a sandbox. But it strikes me as a little less agile. Just as I don't enjoy issuing compile and link commands (even if run via a Makefile), I don't want to have to issue install- into-sandbox commands. For concreteness here's the import code I've been using is: http://code.google.com/p/pyimport-relative/ It is far from perfect because I just wanted to get this done and I don't fully understand the Python modules and imp module, but for now it gets what I want done. I will probably add some ability to top- level package name to avoid collisions from other packages. However if I do this, I still will probably have the program figure out the intermediate compound names. So if I am in directory ...my-project/a/b/ c and I can say import_relative("x", "myproject") and have it import that as "myproject.a.b.c.x". That way, if files move around and get renamed I don't have to change any code. Also, I can probably store somewhere in a variable "myproject". Code that uses this can be found at http://code.google.com/p/pydbg/ Suggestions on how to improve the code are welcome; but again I don't represent that this is done that well or that I've mastered this. Oh, also meant to mention that in looking at say the knee code (which looks like a translation into Python of its C code) and the C code, a very deliberate decision was made *not* to allow filenames. So I probably am treading where others have been and have decided not to go. If folks are aware of threads, and discussions on this I'd be grateful for pointers on this discussion. Thanks. From clp2 at rebertia.com Sat Jan 10 21:27:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 18:27:38 -0800 Subject: import relative (with a directory) In-Reply-To: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> References: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Message-ID: <50697b2c0901101827i1cfe68f5oa0e08e545ac0dbcd@mail.gmail.com> On Sat, Jan 10, 2009 at 6:11 PM, rocky wrote: > Import relative? > > Recently for fun I've been working on a large Python program. It has > many files/modules spread over several directories/submodules. > > Each module has some "demo" code at the end that I can use to run or > experiment with that module. Of course, modules often refer to others; > depending on which one, more of the code may get pulled in or not. > > In this situation it has been very convenient to have do "import > relative" which is like import, but I get to specify where to start > searching from. Of course I can set sys.path, but I find that hokey. > (When I write systems administration scripts, I also generally prefer > specifying a full path name to a program, e.g. /bin/mount rather than > using PATH. Strikes me as the same issue here). > > The other thing about the Python import mechanism that sometimes gets > in the way is that if there is a module imported (from the wrong place > for this context), it tacitly gets used. Within such a project I want > to specify when I want the code in this project, and if it can't find > that, then that's a failure. > > I'm curious if other have the same problem and how other they deal > with this? Reading "Expert Python Programming", I see that one > solution is to install into a sandbox. But it strikes me as a little > less agile. Just as I don't enjoy issuing compile and link commands > (even if run via a Makefile), I don't want to have to issue install- > into-sandbox commands. > > For concreteness here's the import code I've been using is: > http://code.google.com/p/pyimport-relative/ > > It is far from perfect because I just wanted to get this done and I > don't fully understand the Python modules and imp module, but for now > it gets what I want done. I will probably add some ability to top- > level package name to avoid collisions from other packages. However if > I do this, I still will probably have the program figure out the > intermediate compound names. So if I am in directory ...my-project/a/b/ > c and I can say import_relative("x", "myproject") and have it import > that as "myproject.a.b.c.x". That way, if files move around and get > renamed I don't have to change any code. Also, I can probably store > somewhere in a variable "myproject". You should probably check out the relative import syntax introduced in PEP 328: http://www.python.org/dev/peps/pep-0328/ It should be able to do exactly what you want. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From google at mrabarnett.plus.com Sat Jan 10 21:33:26 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 02:33:26 +0000 Subject: Regex for unicode letter characters In-Reply-To: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> Message-ID: <49695A76.9060306@mrabarnett.plus.com> schickb wrote: > I need a regex that will match strings containing only unicode letter > characters (not including numeric or the _ character). I was surprised > to find the 're' module does not include a special character class for > this already (python 2.6). Or did I miss something? > > It seems like this would be a very common need. Is the following the > only option to generate the character class (based on an old post by > Martin v. L?wis )? > [snip] Basically, yes. The re module was last worked on in 2003 (remember it's all voluntary!). Such omissions should be addressed in Python 2.7. From googler.1.webmaster at spamgourmet.com Sat Jan 10 21:41:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 18:41:01 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <0bf35b53-d672-4557-adb8-7fa764288525@o4g2000pra.googlegroups.com> hmm.. very strange. Is it so complicated to compile python that I can move the framework to the app folder? hmm. thats really strange :-( /myapp.app /subfolder/Python.framework any suggestions? Thank you very muc. From mdw at distorted.org.uk Sat Jan 10 21:41:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 02:41:17 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <017925b8$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There are actually three fundamental characteristics of pass-by-reference: > > * passing a value by reference does not lead to the value being copied, > in contrast with pass-by-value where it does; > > * modifications to the value passed by reference are visible to the > caller; > > * assignments to the value passed by reference are visible to the > caller. I've given an extensive definition of pass-by-reference. Distilling and paraphrasing, the main characteristic is that (where possible) new variables are not created: rather, the parameter names are bound to the caller's variables. All three of your above characteristics are consequences of this one. But your definition is also flawed: it doesn't distinguish pass-by- reference from pass-by-value/return (where the caller's variable is updated from the function parameter's final value when the function returns). The difference is detectable if you use global variables, however: variable g = 1 function foo(x): x = 2 print g foo(g) print g prints 1 and 1 if you use pass-by-value, 2 and 2 if you use pass-by- reference, and 1 and 2 if you use pass-by-value/result. (Within the framework I presented elsewhere, pass-by-value/result is like pass-by-value, except that we update: s'''' = s'''[s'''(e''(n))/l] where s''' is the store just prior to the return, s'''' is the store just after the return, n is the parameter name, e'' is the function's environment, and l is the location designated by the argument expression, i.e., (l, s') = loc(x, e, s). If there is no such location, then the language may either fail to compile the call, or omit the update operation.) > Pascal VAR parameters have all three characteristics. That's because they work as I've suggested. > Pascal non-VAR parameters have none of them. Indeed. > Python parameters have two of the three. C parameters (call-by-value) > have none of them, except for arrays, where they have all three, > making arrays in C behave just like Pascal pass-by- reference VAR > parameters. Rubbish. In C: void foo(char v[42]) { v = 0; } Calling this function has no effect on the caller whatsoever. I've already explained C arrays, with reference to the ISO standard, exhaustively: there should be no excuse for continued misunderstanding of this point. -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 21:48:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 02:48:12 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <0179549a$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 01:22:48 +0000, Rhodri James wrote: > On Sat, 10 Jan 2009 18:44:37 -0000, wrote: > >> What is the observable difference between converting an array to a >> reference (pointer) to that array and passing the reference by value, >> and passing the array by reference? > > This is a red herring, though. From either viewpoint, C arrays are > anomalous in comparison with other C data types. I don't believe it is a red-herring. As I understand it, Mark and Joe insist that C is pass-by-value *even in the case of arrays*, despite the semantics of array passing being identical to the semantics of pass-by- reference in (say) Pascal. While Mark is willing to admit that arrays are "bizarre" (his term) in C, I don't think he accepts that passing arrays in C is anything but pass-by-value. I think this gets very close to the bone of the debate. It demonstrates that "pass-by-value" as Mark and Joe understand it is such a broad concept that it can describe any argument passing behaviour at all and therefore is meaningless. -- Steven From steve at holdenweb.com Sat Jan 10 21:49:26 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 21:49:26 -0500 Subject: urlopen exception In-Reply-To: <7xbpuesxjf.fsf@ruckus.brouhaha.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > asit writes: >> site="www.bput.org" >> payloads="" >> attack= urllib2.urlopen(site+payloads,80).readlines() >> >> according to my best knowledge, the above code is correct. >> but why it throws exceptio ???? > > The code is incorrect. Look at the string ou are sending into > urlopen. What on earth are you trying to do? He's investigating potential cross-site scripting vulnerabilities. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gdamjan at gmail.com Sat Jan 10 21:57:12 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 11 Jan 2009 03:57:12 +0100 Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> <49692436.1010306@codebykevin.com> Message-ID: <8p3o36-j8t.ln1@archaeopteryx.softver.org.mk> > The themed Tk widgets (ttk) that come with Tk 8.5 add a lot of the > same things that Tix does, but they do so in a more modern way, > hooking into platform-specific themes and API's wherever possible (XP, > Vista, Mac) and updating the generic X11 look as well. As such, they > are more appropriate for modern development. Tix is more of a legacy > toolkit. Interesting... so to summarize, what do I get from Python/TK on *Linux* with tkinter beeing dynamically linked to the system tk 8.5.6 ? Especially I'd like to know if it will support fontconfig/TTF/antialiased fonts? -- ?????? ( http://softver.org.mk/damjan/ ) When you do things right, people won't be sure if you did anything at all. From steve at holdenweb.com Sat Jan 10 22:03:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 22:03:38 -0500 Subject: Regex for unicode letter characters In-Reply-To: <49695A76.9060306@mrabarnett.plus.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> Message-ID: MRAB wrote: > schickb wrote: >> I need a regex that will match strings containing only unicode letter >> characters (not including numeric or the _ character). I was surprised >> to find the 're' module does not include a special character class for >> this already (python 2.6). Or did I miss something? >> >> It seems like this would be a very common need. Is the following the >> only option to generate the character class (based on an old post by >> Martin v. L?wis )? >> > [snip] > Basically, yes. > > The re module was last worked on in 2003 (remember it's all voluntary!). > Such omissions should be addressed in Python 2.7. By "should be" do you mean "ought to be (but I have no intention of helping)", "are expected to be (but someone else will be doing the work", "it's on my list and I am expecting to get finished in time for 2.7 integration" or something else? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mdw at distorted.org.uk Sat Jan 10 22:25:24 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 03:25:24 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I don't believe it is a red-herring. As I understand it, Mark and Joe > insist that C is pass-by-value *even in the case of arrays*, despite the > semantics of array passing being identical to the semantics of pass-by- > reference in (say) Pascal. But they aren't. I've provided several examples to show this. Most tellingly, the parameter types are different in the two cases. > While Mark is willing to admit that arrays are "bizarre" (his term) in > C, I don't think he accepts that passing arrays in C is anything but > pass-by-value. For the purpose of clearing this up once and for all: arrays, in C, are `don't-pass-at-all'. There is no way -- none whatever -- of declaring a function parameter as having array type. Furthermore, if (say) an argument expression consists only of an identifier bound to an object of array type, the resulting argument expression has pointer type, and is fully evaluated prior to the sequence point before the function call. I provided chapter and verse elsewhere, and I'm getting rather fed up of repeating myself. Certainly a dissenting opinion should include references to at least a (specific) draft of the ISO C standard. > I think this gets very close to the bone of the debate. It demonstrates > that "pass-by-value" as Mark and Joe understand it is such a broad > concept that it can describe any argument passing behaviour at all and > therefore is meaningless. I've proven (not quite rigorously, but sketched a proof, and provided definitions which are now sufficiently formal that you can fill in the details) that my definition of pass-by-value excludes certain behaviours. But, most significantly, you cannot implement `swap' given only pass-by-value. -- [mdw], wondering whether Hanlon's razor is getting blunt. From google at mrabarnett.plus.com Sat Jan 10 22:38:13 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 03:38:13 +0000 Subject: Regex for unicode letter characters In-Reply-To: References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> Message-ID: <496969A5.4090601@mrabarnett.plus.com> Steve Holden wrote: > MRAB wrote: >> schickb wrote: >>> I need a regex that will match strings containing only unicode letter >>> characters (not including numeric or the _ character). I was surprised >>> to find the 're' module does not include a special character class for >>> this already (python 2.6). Or did I miss something? >>> >>> It seems like this would be a very common need. Is the following the >>> only option to generate the character class (based on an old post by >>> Martin v. L?wis )? >>> >> [snip] >> Basically, yes. >> >> The re module was last worked on in 2003 (remember it's all voluntary!). >> Such omissions should be addressed in Python 2.7. > > By "should be" do you mean "ought to be (but I have no intention of > helping)", "are expected to be (but someone else will be doing the > work", "it's on my list and I am expecting to get finished in time for > 2.7 integration" or something else? > The third one. From rurpy at yahoo.com Sat Jan 10 22:59:13 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 10 Jan 2009 19:59:13 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Mark Wooding wrote: > rurpy at yahoo.com wrote: > >> What is the observable difference between converting an >> array to a reference (pointer) to that array and passing >> the reference by value, and passing the array by reference? > > For one: > > #include > static size_t foo(char v[]) { return sizeof v; } > int main(void) { > char v[sizeof(char *) * 10]; > puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); > return (0); > } You are saying that because the size of the argument (10) is not available in the function, it cannot be call-by-reference? I think fortran is accepted as the archetypal call-by- reference language and it does not automatically supply argument size information to functions. In fortran, if the size of the argument is known at compile time, the programmer explicitly declares the parameter with the same size in the function. integer k(3) call mysub (k) write (unit=*, fmt=*) k(1),k(2),k(3) end subroutine mysub (x) integer x(3) do 100, i=1,3 100 x(i) = i return end If not, he passes the size explicitly as an argument: integer k(3) call mysub (k, 3) write (unit=*, fmt=*) k(1),k(2),k(3) end subroutine mysub(x, n) integer x(0) do 100, i=1,3 100 x(i) = i return end Obviously both these idioms translate directly into C. Here is the second: #include void mysub (int k[], int n) { int i; for (i=0; i<3; i++) { k[i] = i; } return; } main() { int k[3]; mysub (k, 3); printf ("%i,%i,%i\n", k[0],k[1],k[2]); } So if fortran can be call-by-reference without the compiler passing size information, I don't see why the above C code can't be as well. > For another: > > static void bar(char v[]) { char ch = 0; v = &ch; } > /* type error if arrays truly passed by reference */ v can be used as an array reference, e.g. "v[1] = 23" exactly as in the pass-by-reference fortran example. And v can also be used as a local variable and reassigned. If the first option was the only one, would you not say C was definitely pass-by-reference (for arrays)? If one could only use v as a pointer (i.e. access the argument array as "*(v+1) = 23", then I would say that arrays are not passed at all, only pointers by-value. That both these options exist causes me to conclude that, for arrays, parameter passing can be viewed as either arrays by-reference or pointers by-value. I don't understand what relevance type checking has. Since you are choosing to use v as a pointer, one would not expect a type error, yes? >> I guess the case for pass-by-value would be a little stronger because >> one has to have "passing a pointer by value" anyway (since pointers >> are first-class datatypes) and that can be used to describe passing >> arrays (as you described). > > The difference is that the /callee/ function is different between the > two cases. > > Also, notice that arrays in expressions turn into pointers in the same > way, so function argument passing works the same way as assignment -- a > hallmark of pass-by-value. Not in all expressions as you yourself mentioned: int a[10], *ap; sizeof a; sizeof ap; From musiccomposition at gmail.com Sat Jan 10 23:09:31 2009 From: musiccomposition at gmail.com (Benjamin) Date: Sat, 10 Jan 2009 20:09:31 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> Message-ID: <4da72a7f-29f1-4121-a168-7e6fe54a9575@s1g2000prg.googlegroups.com> On Jan 9, 10:19?pm, John Machin wrote: > On Jan 10, 2:55?pm, Benjamin wrote: > > > We'll need good documentation. Unfortunately, as you > > note below, this isn't exactly the case yet. > > So is there a plot to remedy this? Where do we sign up? Feel free to contribute to the wiki page: http://wiki.python.org/moin/PortingToPy3k From koranthala at gmail.com Sat Jan 10 23:18:53 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 10 Jan 2009 20:18:53 -0800 (PST) Subject: Python strings and coding conventions Message-ID: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Hi, Python Coding Convention (PEP 8) suggests : Maximum Line Length Limit all lines to a maximum of 79 characters. I have a string which is ~110 char long. It is a string which I am going to print in a text file as a single string. i.e. in that text file, each line is taken as a different record - so it has to be in a single line. Now, how can I write this code - while following PEP 8? I tried blockstrings, but as shown in the example below: >>> s = r''' ... abcd ... efgh ... ''' >>> s '\nabcd\nefgh\n' it has "\n" inserted - which will disallow printing it to a single line. I thought about other options like concatenating strings etc, but it seems very kludgy - esp since the whole string has a single meaning and cannot be easily split to many logically. Then I thought of creating a blockstring and then removing "\n", but it seemed kludgier... I am sure this is a very usual issue and I am missing some very very simple solution. But I cannot think of it at all... From robert.kern at gmail.com Sat Jan 10 23:26:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 10 Jan 2009 22:26:46 -0600 Subject: Python strings and coding conventions In-Reply-To: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > Hi, > Python Coding Convention (PEP 8) suggests : > Maximum Line Length > > Limit all lines to a maximum of 79 characters. > > I have a string which is ~110 char long. It is a string which I am > going to print in a text file as a single string. > i.e. in that text file, each line is taken as a different record - > so it has to be in a single line. > > Now, how can I write this code - while following PEP 8? > I tried blockstrings, but as shown in the example below: >>>> s = r''' > ... abcd > ... efgh > ... ''' >>>> s > '\nabcd\nefgh\n' > it has "\n" inserted - which will disallow printing it to a single > line. > > I thought about other options like concatenating strings etc, but > it seems very kludgy - esp since the whole string has a single meaning > and cannot be easily split to many logically. Then I thought of > creating a blockstring and then removing "\n", but it seemed > kludgier... I usually use implicit concatenation: s = ('some long text that ' 'needs to be split') -- 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 mensanator at aol.com Sat Jan 10 23:48:21 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 10 Jan 2009 20:48:21 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: On Jan 10, 10:26?pm, Robert Kern wrote: > koranth... at gmail.com wrote: > > Hi, > > ? ?Python Coding Convention (PEP 8) suggests : > > ? Maximum Line Length > > > ? ? Limit all lines to a maximum of 79 characters. > > > ? I have a string which is ~110 char long. It is a string which I am > > going to print in a text file as a single string. > > ? i.e. in that text file, each line is taken as a different record - > > so it has to be in a single line. > > > ? Now, how can I write this code - while following PEP 8? > > ? I tried blockstrings, but as shown in the example below: > >>>> s = r''' > > ... abcd > > ... efgh > > ... ''' > >>>> s > > '\nabcd\nefgh\n' > > ? ?it has "\n" inserted - which will disallow printing it to a single > > line. > > > ? ?I thought about other options like concatenating strings etc, but > > it seems very kludgy - esp since the whole string has a single meaning > > and cannot be easily split to many logically. Then I thought of > > creating a blockstring and then removing "\n", but it seemed > > kludgier... > > I usually use implicit concatenation: > > s = ('some long text that ' > ? ? ? 'needs to be split') Damn! I didn't know you could do that! And if I saw it in a program listing, such would never occur to me. I was going to suggest the stupid way: >>> ga = ['four score and seven years ago ', \ 'our fathers brought forth ', \ 'on this continent a new nation ', \ 'conceived in liberty and dedicated ', \ 'to the proposition that all men ', \ 'are created equal'] >>> ''.join(ga) 'four score and seven years ago our fathers brought forth on this continent a new nation conceived in liberty and dedicated to the proposition that all men are created equal' > > -- > 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- Hide quoted text - > > - Show quoted text - From kay.schluehr at gmx.net Sun Jan 11 00:32:34 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 10 Jan 2009 21:32:34 -0800 (PST) Subject: import relative (with a directory) References: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Message-ID: On 11 Jan., 03:27, Chris Rebert wrote: > You should probably check out the relative import syntax introduced in > PEP 328:http://www.python.org/dev/peps/pep-0328/ > It should be able to do exactly what you want. This should exactly lead to exceptions in all of his demo code because the modules are not "scripts" anymore but "modules in a package" - a semantical difference I wasn't even aware of until relative imports were introduced in Python 2.5. I'd rather avoid the sour grapes and use absolute imports. Kay From torriem at gmail.com Sun Jan 11 00:49:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 10 Jan 2009 22:49:57 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <49698885.1090700@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > Thanks for the link but I don't want to do a make a python script as > an applicatin, I want to embedd python into a C++ app so thats the > reason why I have to compile Python. If you are embedding python, then all you have to do is stick the python modules you need in somewhere in the resources folder, along with the dynamic link library that you built. Then you fix up your executable to be able to find the dynamic link library (been a while since I made app bundles in general... followed the Qt docs if I recall). When your app goes to initialize python, just use python api calls to set the python path that it will use to find the import modules. You should be able to programmatically determine this (see apple docs I guess). In short, you can do it all with the python C api, programmatically in your exe, once you've taken care of the initial link against the python dynlib. From aleksandr.goretoy at gmail.com Sun Jan 11 00:58:55 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 11 Jan 2009 05:58:55 +0000 Subject: urlopen exception In-Reply-To: References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: I would try: site="http://www.bput.org/" payloads="" attack= urllib2.urlopen(site+payloads,80).readlines() -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden wrote: > Paul Rubin wrote: > > asit writes: > >> site="www.bput.org" > >> payloads="" > >> attack= urllib2.urlopen(site+payloads,80).readlines() > >> > >> according to my best knowledge, the above code is correct. > >> but why it throws exceptio ???? > > > > The code is incorrect. Look at the string ou are sending into > > urlopen. What on earth are you trying to do? > > He's investigating potential cross-site scripting vulnerabilities. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Sun Jan 11 01:04:03 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 11 Jan 2009 06:04:03 +0000 Subject: urlopen exception In-Reply-To: References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: oops, remove the ,80 since port is not needed. Well, in my case it wasn't working with port. notice it gives me 404, but this with my domain >>> att=urllib2.urlopen(site+payload,80).readlines() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/local/lib/python2.6/urllib2.py", line 381, in open req = meth(req) File "/usr/local/lib/python2.6/urllib2.py", line 1057, in do_request_ 'Content-length', '%d' % len(data)) TypeError: object of type 'int' has no len() >>> att=urllib2.urlopen(site+payload).readlines() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/local/lib/python2.6/urllib2.py", line 389, in open response = meth(req, response) File "/usr/local/lib/python2.6/urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs) File "/usr/local/lib/python2.6/urllib2.py", line 427, in error return self._call_chain(*args) File "/usr/local/lib/python2.6/urllib2.py", line 361, in _call_chain result = func(*args) File "/usr/local/lib/python2.6/urllib2.py", line 510, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sun, Jan 11, 2009 at 5:58 AM, alex goretoy wrote: > I would try: > > site="http://www.bput.org/" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > > > > On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden wrote: > >> Paul Rubin wrote: >> > asit writes: >> >> site="www.bput.org" >> >> payloads="" >> >> attack= urllib2.urlopen(site+payloads,80).readlines() >> >> >> >> according to my best knowledge, the above code is correct. >> >> but why it throws exceptio ???? >> > >> > The code is incorrect. Look at the string ou are sending into >> > urlopen. What on earth are you trying to do? >> >> He's investigating potential cross-site scripting vulnerabilities. >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bedouglas at earthlink.net Sun Jan 11 01:58:23 2009 From: bedouglas at earthlink.net (bruce) Date: Sat, 10 Jan 2009 22:58:23 -0800 Subject: parsing javascript generated files... Message-ID: <098401c973b9$ffbf9760$0301a8c0@tmesa.com> Hi. Looking to parse some web pages that have javascript (jquery) embedded/used in the pages. I'm trying to get a better understanding of exactly how the page is generated, and displayed in the browser. I've seen various references to python-spidermonkey, as well as watir/firewatir. Is there a way to accomplish fetching text from javascript generated pages? It appears that the ability to "call" firefox using "jssh" could allow me to return the complete page of the displayed app. I'm not sure if this is pythonic!! I suspect that I would have to somehow invoke the page, using firefox/jssh, (or spidermonkey) or some other javascript engine, and then somehow invoke the javascript function, that would fill in the 'div' within the page... Is this even doable??? It would be great if there was someway of calling an external browser/app that one could pass the targeted url, and get back the resulting html that's displayed by the browser!! A target site is http:://web-app.usc.edu/soc/term_20091.html where the 'dept' list is completely generated by javascript functions... When i researched this awhile ago, there didn't appear to be a really good solution to this situation. I'm curious if someone knows of a solution to this issue that's now available and that works! Thanks for any thoughts/comments in this issue... -bruce From koranthala at gmail.com Sun Jan 11 02:17:59 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 10 Jan 2009 23:17:59 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> On Jan 11, 9:26?am, Robert Kern wrote: > koranth... at gmail.com wrote: > > Hi, > > ? ?Python Coding Convention (PEP 8) suggests : > > ? Maximum Line Length > > > ? ? Limit all lines to a maximum of 79 characters. > > > ? I have a string which is ~110 char long. It is a string which I am > > going to print in a text file as a single string. > > ? i.e. in that text file, each line is taken as a different record - > > so it has to be in a single line. > > > ? Now, how can I write this code - while following PEP 8? > > ? I tried blockstrings, but as shown in the example below: > >>>> s = r''' > > ... abcd > > ... efgh > > ... ''' > >>>> s > > '\nabcd\nefgh\n' > > ? ?it has "\n" inserted - which will disallow printing it to a single > > line. > > > ? ?I thought about other options like concatenating strings etc, but > > it seems very kludgy - esp since the whole string has a single meaning > > and cannot be easily split to many logically. Then I thought of > > creating a blockstring and then removing "\n", but it seemed > > kludgier... > > I usually use implicit concatenation: > > s = ('some long text that ' > ? ? ? 'needs to be split') > > -- > 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 This is a very good method. I found another method too - on further investigation >>> s = "abc\ ... efg" >>> s 'abcefg' Only problem being that it doesnt support indentation. So, implicit concatenation it is... From matrixhasu at gmail.com Sun Jan 11 03:54:25 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 00:54:25 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: <32ed6add-2266-498d-b9a9-96b6b426dc15@g1g2000pra.googlegroups.com> Message-ID: Hello Marco, thanks for your reply (and sorry for my late one) On Jan 6, 9:26?am, Marco Nawijn wrote: > On Jan 5, 10:57?am, Sandro Tosi wrote: > I am happy to hear that there might be a book on Matplotlib. I am > using Matplotlib for a while now and find it a very usefull and > powerfull library for generating graphs. I will try to answer some of > your questions. I am by no means an expert in the field, so I only > express my personal experience. And that's fine, because the audience of the book is people that have never seen matplotlib and wanted to learn it. > >> What are you using matplotlib for? I currently use Matplotlib to generate a series of graphs that visualise data channels (strain measurements) during a structural test. These graphs need to be refreshed about every 4 seconds. Each of the graphs contains 1 to 6 curves. Just out of curiosity: how do you refresh those plots? in a loop closing/opening the figure or clear the figure and replot on it? are those graphs embedded in an application or are just "shown on screen"? > >> What are the things you like the most of matplotlib, that you want > > to give emphasis to? And why? In general I like the most the fact that > I can generate high quality publication ready graphs with a consistent > look with minimal effort. Indeed, that's one of the reason for its use in so many scientific environments. > Further, although the matlab-style commands > are very usefull I think the class interface is more powerfull. The > class interface also has a steeper learning curve. So, for me it would > be very interesting if much emphasis will be on the class interface. Yes, we will show the "class" interface during the examples, while showing the difference just for the sake of completeness. > >> What are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? I > seriously hope the book is not for "dummies", as already said, this bug is intended to people that knows nothing about mpl, so an introductory part will begin the book. > but provides at least a > significant amount of information on more advanced features of > Matplotlib. and we will try to show as much features as possible, even the advanced one. > I think the currently available tutorials are sufficient > to getting started. From my point of view I am very interested in: > ? ? - Dynamically updating a series of graphs > ? ? - Configuring layout of graphs (colors, labels, legends, etc.) > ? ? - Managing dimensions of the figure when you export the figure to > e.g PNG. For me this is interesting in the sense that if I insert a > figure in a report/paper, I would like that the fonts used in the > graph remain proportional to the surrounding text. Those will be surely in the book :) > If you need more information please let me know. Well, whatever comes to mind, please let me know :) > I wish you good luck! Cheers, Sandro From dotancohen at gmail.com Sun Jan 11 04:02:59 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 11 Jan 2009 11:02:59 +0200 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: <880dece00901110102i32f7ca85jaf9ded3d49e09701@mail.gmail.com> 2009/1/5 Sandro Tosi : > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? > - what would you like to see in a book about matplotlib? > - what are some those advanced feature that made you yell "WOW!!" ? > - what are the things you'd like to explore of matplotlib and never > had time to do? > > Your suggestions are really appreciated :) And wish me good luck! I wish you good luck! I would suggest at least a chapter on _acquiring_ the data that is to be plotted using Python to scrape different sources _not_designed_ to be scraped. Online webpages come to mind. An example on retrieving, for instance, the prices of varying currencies, parsing the HTML pages, extracting the data, and then plotting it would be a great example for a real worlds usage that show matplotlib as a tool in a toolchain, not a means to an end. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From matrixhasu at gmail.com Sun Jan 11 04:42:53 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 01:42:53 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <91eb0601-225d-4416-8b8d-af86f07c271b@n10g2000vbl.googlegroups.com> Hi James, thanks for getting back to me. On Jan 6, 9:33?am, James Stroud wrote: > Sandro Tosi wrote: > > - what are the things you like the most of matplotlib, that you want > > to give emphasis to? And why? > > The ability to embed a figure (composed of subplots) into a custom > window is my favorite aspect. Do you mean embed the figure in an application or simply a figure with several subplots in it? > Also: massive configurability of plots, > event driven plot canvas, antigrain geometry antialiasing are also all > very important. Additionally the toolbar of standard interactive > functions and the ability to export plots in a variety of formats are > also invaluable features. > > > - what are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? > > The documentation for basic plot configuration, especially for embedded > plots, and also tapping into the event model is very weak currently. > These need the most improvement. What do you mean by "event model"? > > - what would you like to see in a book about matplotlib? > > A big, huge, gigantic, chapter---no make that 3 chapters--on programming > ? interactivity with the plot canvas. Big chapters a harder to read. And what exactly do you mean by "interactivity"? > > Your suggestions are really appreciated :) And wish me good luck! > > Good luck! I can't wait to read your book! Thanks! Sandro From bj_666 at gmx.net Sun Jan 11 04:56:02 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 11 Jan 2009 09:56:02 GMT Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <6stu1iF813rdU1@mid.uni-berlin.de> On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote: > Damn! I didn't know you could do that! And if I saw it in a program > listing, such would never occur to me. I was going to suggest the stupid > way: > >>>> ga = ['four score and seven years ago ', \ > 'our fathers brought forth ', \ > 'on this continent a new nation ', \ > 'conceived in liberty and dedicated ', \ > 'to the proposition that all men ', \ > 'are created equal'] What are all those line continuation characters ('\') for? You are aware that they are unnecessary here? Ciao, Marc 'BlackJack' Rintsch From Ron.Barak at lsi.com Sun Jan 11 05:12:27 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 11 Jan 2009 10:12:27 +0000 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Hi Mark, I googled a bit, and found http://bugs.python.org/issue1355023. It seems that this patch implemented fuller seek() for GzipFile around November 2006 (including whence==2). Do I misunderstand and this patch was not actually implemented, namely, is seek(-n,2) not implemented in Python 2.5.2 ? The source of gzip.py on my system seems to suggest that negative seeks are supported: def seek(self, offset): if self.mode == WRITE: if offset < self.offset: raise IOError('Negative seek in write mode') count = offset - self.offset for i in range(count // 1024): self.write(1024 * '\0') self.write((count % 1024) * '\0') elif self.mode == READ: if offset < self.offset: # for negative seek, rewind and do positive seek self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) Could any who're familiar with the inner working of gzip settle this issue ? Is seek from EOF supported for gzip files ? Thanks, Ron. P.S.: as you guessed, my python 2.5.2 gives the not very helpful error: Traceback (most recent call last): File "./_LogStream.py", line 53, in log_stream.last_line_loc_and_contents() File "./_LogStream.py", line 20, in last_line_loc_and_contents self.input_file.seek(-1, 2) # grab the last character TypeError: seek() takes exactly 2 arguments (3 given) -----Original Message----- From: Mark Tolonen [mailto:metolone+gmane at gmail.com] Sent: Thursday, January 08, 2009 17:16 To: python-list at python.org Subject: Re: Nubie question: how to not pass "self" in call to seek() function ? "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know > how to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, > only at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matrixhasu at gmail.com Sun Jan 11 05:14:30 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 02:14:30 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: <6sk2h5F6h203U1@mid.individual.net> Message-ID: <36df237b-6b86-47ae-8cfd-6f03356380da@x16g2000prn.googlegroups.com> Hello Thomas, thanks for your reply. On Jan 7, 5:11?pm, Thomas Guettler wrote: > Sandro Tosi schrieb: > > - what are you using matplotlib for? > > I use the API to create PNGs from data stored in postgres. Webframework: Django. Nice, I plan to make some examples of web embedding of mpl, and one of the frameworks is Django. > > - what are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? > > The API is not good documented. It was very hard for me to understand > what was going on the source. > > > - what would you like to see in a book about matplotlib? > > How to use the API. Of course we will follow a gradual path, introducing simple apis and then going deeper in the advanced features. So, if you mean API as "pyplot.figure()" and so, they'll be covered :) Thanks, Sandro From matrixhasu at gmail.com Sun Jan 11 05:17:13 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 02:17:13 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> Hi Dotan, On Jan 11, 10:02?am, "Dotan Cohen" wrote: > 2009/1/5 Sandro Tosi : > > Your suggestions are really appreciated :) And wish me good luck! > > I wish you good luck! Thanks you :) > I would suggest at least a chapter on _acquiring_ the data that is to > be plotted using Python to scrape different sources _not_designed_ to > be scraped. Online webpages come to mind. An example on retrieving, > for instance, the prices of varying currencies, parsing the HTML > pages, extracting the data, and then plotting it would be a great > example for a real worlds usage that show matplotlib as a tool in a > toolchain, not a means to an end. Well, a whole chapter to this is a little too much, but such examples will be presented in the book: we're not going to teach how to program in Python, but how to use matplotlib, so the data retriving is a little out-of-scope (or at least border-line), so the code will be in the examples provided along with the book, but not deeply explained in the book text. Thanks, Sandro From ihatespam at hotmail.com Sun Jan 11 05:18:22 2009 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Sun, 11 Jan 2009 05:18:22 -0500 Subject: Bad hack fix around a bizarre problem... Message-ID: I'm trying to write a Python program that manipulates a MySQL database and have chosen to use MySQLdb. So, I used by system's package manager, YUM, and it appeared to install correctly. So, I tried it out and got this error: Traceback (most recent call last): File "", line 1, in ? File "MySQLdb/__init__.py", line 22, in ? raise ImportError, "this is MySQLdb version %s, but _mysql is version %r" %\ ImportError: this is MySQLdb version (1, 2, 2, 'final', 0), but _mysql is version (1, 2, 1, 'final', 1) It looks like the MySQLdb version doesn't match the _mysql version. If these were two different libraries, I might understand how this error happened. However, they're part of the same library. _mysql is just a Python binding to the MySQL C API and MySQLdb is just a Python wrapper around _mysql to be compliant with the Python DB specification. They were both part of the same library so how did their versions fall out of sync? That's like getting a Windows application with incompatible DLLs! So, my bad hack of a fix is to copy the MySQLdb python code to a local directory (where my python program will eventually reside) and, on this local copy, comment out the version check. The idea is that MySQLdb is pure Python, so it's unlikely that there is any incompatibility between it and the very thin layer that is _mysql. The local copy is so I don't forget that I'm using a modified version of this library. Python seems to import this over the global one. I've done a bit of testing and, so far, it appears to work! What is my problem? A google search reveals that I'm not the only person with this problem but it also reveals that absolutely no one knows how to fix this. What are the chances that my fix will backfire? Thank you... From bignose+hates-spam at benfinney.id.au Sun Jan 11 05:22:54 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 11 Jan 2009 21:22:54 +1100 Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <87ab9yf8g1.fsf@benfinney.id.au> Robert Kern writes: > I usually use implicit concatenation: > > s = ('some long text that ' > 'needs to be split') I do something very similar: fleebnorg.spam = ( 'some long text that' ' needs to be split') The differences are: I prefer to have indents as 4 spaces no matter how long the preceding line is; but I also want the opening quote for the start of the string to line up with subsequent open quotes for that string. So I have all the portions of the string line up at the same (new) indent level. To make that simpler without thinking about it every time I change the first line, I simply break after the opening parenthesis. I prefer the continued portions to have the connecting space (or whatever characters are contextually ?connecting? in the text); this is a greater visual cue that the string doesn't stand alone. -- \ ?I went camping and borrowed a circus tent by mistake. I didn't | `\ notice until I got it set up. People complained because they | _o__) couldn't see the lake.? ?Steven Wright | Ben Finney From mdw at distorted.org.uk Sun Jan 11 05:47:09 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 10:47:09 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Mark Wooding wrote: > > rurpy at yahoo.com wrote: > > > >> What is the observable difference between converting an > >> array to a reference (pointer) to that array and passing > >> the reference by value, and passing the array by reference? > > > > For one: > > > > #include > > static size_t foo(char v[]) { return sizeof v; } > > int main(void) { > > char v[sizeof(char *) * 10]; > > puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); > > return (0); > > } > > You are saying that because the size of the argument > (10) is not available in the function, it cannot be > call-by-reference? No, I'm saying that because the parameter has pointer type, not array type, it's a pointer being passed by value, not an array being passed by reference. And the size of the argument is not 10: it's 10 times as much as the (nonzero) size of a pointer -- and therefore distinguishable on any C implementation. > I think fortran is accepted as the archetypal call-by- > reference language and it does not automatically > supply argument size information to functions. Well and dandy; but Fortran doesn't turn arrays into pointers. > > For another: > > > > static void bar(char v[]) { char ch = 0; v = &ch; } > > /* type error if arrays truly passed by reference */ > > v can be used as an array reference, e.g. "v[1] = 23" > exactly as in the pass-by-reference fortran example. And > v can also be used as a local variable and reassigned. > If the first option was the only one, would you not > say C was definitely pass-by-reference (for arrays)? > If one could only use v as a pointer (i.e. access > the argument array as "*(v+1) = 23", then I would > say that arrays are not passed at all, only pointers > by-value. Your knowledge of C is clearly limited, at best. The notations *(p + i) and p[i] are entirely equivalent in every way, since the square-brackets indexing operator is in fact defined in terms of pointer dereference (6.5.2.1): : [#2] 2 A postfix expression followed by an expression in square : brackets [] is a subscripted designation of an element of an array : object. The definition of the subscript operator [] is that E1[E2] is : identical to (*((E1)+(E2))). Because of the conversion rules that : apply to the binary + operator, if E1 is an array object : (equivalently, a pointer to the initial element of an array object) : and E2 is an integer, E1[E2] designates the E2-th element of E1 : (counting from zero). Of course, because the + operator is commutative > That both these options exist causes me to conclude > that, for arrays, parameter passing can be viewed > as either arrays by-reference or pointers by-value. > > I don't understand what relevance type checking > has. Since you are choosing to use v as a pointer, > one would not expect a type error, yes? Compare: void mumble(void) { char v[42]; char ch = 0; v = &ch; } /* error: incompatible types in assignment */ It's because in the previous case v is a pointer that the compiler doesn't mind me assigning to it. In this case, because it's an array, the compiler objects. > >> I guess the case for pass-by-value would be a little stronger because > >> one has to have "passing a pointer by value" anyway (since pointers > >> are first-class datatypes) and that can be used to describe passing > >> arrays (as you described). > > > > The difference is that the /callee/ function is different between the > > two cases. > > > > Also, notice that arrays in expressions turn into pointers in the same > > way, so function argument passing works the same way as assignment -- a > > hallmark of pass-by-value. > > Not in all expressions as you yourself mentioned: > int a[10], *ap; > sizeof a; > sizeof ap; Well done, you've pedantically picked up on the lapse in the first part of the sentence (about sizeof, which as you say I've already mentioned elsewhere) but failed to take any notice of the more important and relevant point in the second half -- that argument passing works the same way as assignment -- for `arrays' just as for other types. void fa(char p[]); void fp(char *p); void fi(int i); char a[10 * sizeof(char *)] = "bar", aa[10 * sizeof(char *)] = "splat"; char *p = "foo", *pp = "mumble"; int i = 42, ii = 69; i = ii; /* assignment of integers */ fi(ii); /* integer call-by-value */ p = pp; /* assignment of pointers */ fp(pp); /* pointer call-by-value */ fa(pp); /* pointer call-by-value again */ a = aa; /* type error: incompatible types in assignment */ a = pp; /* type error: incompatible types in assignment */ p = aa; /* assignment of pointers */ fa(aa); /* pointer call-by-value yet again */ fp(aa); /* pointer call-by-value yet again */ Again, I refer readers to ISO 9899:1999: in particular: * 6.3.2.1p3 (array-to-pointer decay) * 6.5.2.2 (function calls) * 6.5.16 (assignment operator) Since I'm getting thoroughly fed up of repeating myself on this point, I'm simply going to assume, from now on, that anyone who offers a disagreement without citing passages from (at least a specific draft of) ISO 9899 to support any claims made is simply being wilfully ignorant -- and therefore no longer worth my attention. (If you don't have a copy of any such version, may I suggest http://std.dkuug.dk/jtc1/sc22/open/n2794/ citing this (confusingly) as n843, as a place to start.) -- [mdw] From deets at nospam.web.de Sun Jan 11 08:08:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 11 Jan 2009 14:08:06 +0100 Subject: Bad hack fix around a bizarre problem... In-Reply-To: References: Message-ID: <6su99mF888akU1@mid.uni-berlin.de> Just Another Victim of the Ambient Morality schrieb: > I'm trying to write a Python program that manipulates a MySQL database > and have chosen to use MySQLdb. So, I used by system's package manager, > YUM, and it appeared to install correctly. So, I tried it out and got this > error: > > > Traceback (most recent call last): > File "", line 1, in ? > File "MySQLdb/__init__.py", line 22, in ? > raise ImportError, "this is MySQLdb version %s, but _mysql is version > %r" %\ > ImportError: this is MySQLdb version (1, 2, 2, 'final', 0), but _mysql is > version (1, 2, 1, 'final', 1) > > > It looks like the MySQLdb version doesn't match the _mysql version. If > these were two different libraries, I might understand how this error > happened. However, they're part of the same library. _mysql is just a > Python binding to the MySQL C API and MySQLdb is just a Python wrapper > around _mysql to be compliant with the Python DB specification. They were > both part of the same library so how did their versions fall out of sync? > That's like getting a Windows application with incompatible DLLs! > > So, my bad hack of a fix is to copy the MySQLdb python code to a local > directory (where my python program will eventually reside) and, on this > local copy, comment out the version check. The idea is that MySQLdb is pure > Python, so it's unlikely that there is any incompatibility between it and > the very thin layer that is _mysql. The local copy is so I don't forget > that I'm using a modified version of this library. Python seems to import > this over the global one. I've done a bit of testing and, so far, it > appears to work! > What is my problem? A google search reveals that I'm not the only > person with this problem but it also reveals that absolutely no one knows > how to fix this. What are the chances that my fix will backfire? Thank > you... I guess the package maintainer messed up. If you'd install MySQLdb from source, it won't happen I guess. So I'd contact the package maintainer. Diez From googler.1.webmaster at spamgourmet.com Sun Jan 11 08:13:13 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 05:13:13 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <69bfa2e8-ac0f-4a71-981a-0724e75334f6@o4g2000pra.googlegroups.com> Hi! :) Thank you. I found PySys_SetPythonHome() to set the path where the lib folder of Python is, but I guess they are not really implemented because they are fixed compiled for an absolute path, aren't they? Thats the whole problem. Do you have a suggestoin for the command line how I can build it? Thanks From googler.1.webmaster at spamgourmet.com Sun Jan 11 08:27:37 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 05:27:37 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: Thank you, I found PySys_SetPythonHome() to set the path where the lib folder of Python is, but I guess they are not really implemented because they are fixed compiled with an absolute path, aren't they? Thats the problem. I hadn't compiled Python and I don't know if I should compile it as a dylib file or a framework? hmm. I know how to create a framework but compiling as a dylib hadn't worked yet. :-( Thanks From castironpi at gmail.com Sun Jan 11 08:27:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 05:27:48 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <4140f1d3-0dff-4d20-84a1-17b735a71241@s9g2000prm.googlegroups.com> On Jan 10, 1:49?pm, Joe Strout wrote: > Aaron Brady wrote: > >> Aaron Brady wrote: > >>> Possible compromise. ?You can think of functions as mutation-only. > >>> You pass the object, and it gets a new (additional) name. ?The old > >>> name doesn't go in. ? > >> That's correct. ?The reference itself is passed in, not the variable (or > >> expression) that held or generated the reference in the calling code. > > > This is very odd, and I see it quite a bit. > > Me: "You pass the object." > > Joe: "That's correct. ?You pass the reference." > > > What was wrong with my original? > > I'm saying that I believe your idea was correct, but worded imprecisely > (IMHO of course). ?So I restated what I believed you were saying, using > terminology which I believe to be more precise. ?If nothing else, this > gives you the opportunity to say "No, that's not what I meant at all." I believe that my summary is exceedingly beginner-oriented, you might say colloquial. Someone who has even a little programming experience might find it childish. > >> This is true. ?(Technically, instead of variable, we should say "LValue" > >> here -- there are things slightly more complex than simple variables > >> that can serve as the left-hand side of an assignment. ?So replace > >> "variable" with "lvalue" above if you prefer.) > > > This is a point worth making. ?I want to penny-pinch every term in an > > introductory text, though, so, it's a tough call. > > Agreed. Is a function call an lvalue in Python? If not, descriptors are not functions. > >> M2: If 'fun()' returned a reference, you might be able to mutate the > >> object that refers to. > >> m2: You can sometimes mutate the object it refers to. > >> C2: 'fun()' returns a reference. > > > This is horrendous. > >http://en.wikipedia.org/wiki/Formal_fallacy > >http://en.wikipedia.org/wiki/Affirming_the_consequent > > I did point out that the logic was incorrect (even though the > conclusion, in this case, happens to be true).- You've done nothing other than restate your claim; and worse, you disguised doing so in the form of a deduction. > > A question: Are you Joe and you Mark certain that the simplest > > possible introductory explanation makes use of the term 'reference'? > > I am. In any explanation, there is an amount of detail omitted. In an introduction, it's large. (I hold false statements should be avoided, of course, and even misleading ones. However the latter is widely subject-dependent.) Your strategy may have a net positive unifying power, though; and we should see it if so. I may be asking whether it is safe and prudent to avoid (introducing) the term at the level we're looking at (as well as what level exactly it is). > > Perhaps we can have a contest for shortest/simplest/best description > > of Python's data/variable/argument model. > > Sure -- but it judging it might be difficult, requiring some newbies and > a test to check their comprehension (as you and I pondered once before). I think the step of least load would be to ask those who are having difficulty what their background is. At worst, they lie; next worst, there's no pattern. > > Lastly, I don't see any reason why we couldn't make both explanations > > available. ?'For those coming from Java/etc....; for those coming from > > C++/etc.....' ?They would both get read. > > Yes, except that the reference explanation applies equally well to > anyone coming from Java, C/C++, RB, VB.NET, and probably others... I'm > not sure to whom the other explanation would appeal, unless perhaps it's > LISP programmers (just a guess, since those on that side of the aisle > seem to invoke LISP more frequently). True or not, it requires the reader to know what references are. And, since your definition conflicts with the C++ definition, it's not clear that the requirement is good. More terminology: is 'a' a variable, a reference, or an object, in 'a=2'? It's a variable; it refers to an object. It's a variable, which refers to an object. It's a variable, which is a reference to an object. It's a reference to an object. Similarly, is '2' an expression, a reference, or an object? It's an expression; it evaluates to an object. It's an expression; it evaluates to a reference to an object. It's an expression; it expresses an object. It's an expression; it refers to an object. It's a reference to an object. It's an object. I'd like to recommend we decide on unique answers, or avoid ambiguity another way. In the case of the Socratic, non-bludgeoning, dialogue with a student, if the student can be trusted to question intelligently, s/he can be expected, on our telling him/er, "'a' is an object", to ask, "What object?" Whether to expect audience interaction, and what interaction, is a big component in the choice of method of a demonstration. >>> 300+301+302 is 300+301+302 False There are 10 objects created in the evaluation of this, 11 if including 'False'. They (their integer contents), in order, are: 300, 301, 302, then 300, 301, 302, not the same ones, again, then 602, 903, 602, 903, and then possibly 'False' *. * Based on a run of a build of 'r26:66714' with extra output from 'PyInt_FromLong' and command line '-c "300+301+302 is 300+301+302"'. Actual output showed 624 int objects created (!) with this function alone, ending with: 300 301 302 300 301 302 11788072 8192 11788072 601 903 601 903! Any ideas about those extra three? From castironpi at gmail.com Sun Jan 11 08:55:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 05:55:22 -0800 (PST) Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> <96d8f9f5-2679-4855-8b8a-7caaf4e5a410@b38g2000prf.googlegroups.com> Message-ID: On Jan 10, 2:28?pm, bearophileH... at lycos.com wrote: > Scott David Daniels: > > > ? ? ? if checking: > > ? ? ? ? ? my_var = 'string' > > ? ? ? else: > > ? ? ? ? ? my_var = 'other string' > > > remember, vertical space only kills trees if printed. > > I value clarity a lot. But this is more DRY, sometimes it's almost > equally clear, and you reduce vertical space, packing more code in the > same space, this allows you to see more logic, allowing you to have a > higher level view of the code, so allows you to understand the code > better: > > my_var = 'string' if checking else 'other string' > > So I think that sometimes it's useful. > > Bye, > bearophile It would be a good tool that allows you to see logic-- extra points for dynamic! A quick Google for 'python flow chart' turns up 'Visustin' (commercial + demo), 'Flowchart Python', & others. http://www.google.com/search?q=python+flow+chart . The "bird's eye view" in Visustin is pretty cool. Control-flow-only could be a lot simpler, just filtering statements with 'if/while/for', and try-except, not even in diagram. It's on the way for the open source IDE, right? From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 09:27:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 14:27:12 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0179f86a$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 03:25:24 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I don't believe it is a red-herring. As I understand it, Mark and Joe >> insist that C is pass-by-value *even in the case of arrays*, despite >> the semantics of array passing being identical to the semantics of >> pass-by- reference in (say) Pascal. > > But they aren't. I've provided several examples to show this. Here's some p-b-r code in Pascal: program main(input, output); type arraytype = array[1..2] of integer; var arr: arraytype; procedure foo(var bar: arraytype); begin bar[2] := 42; writeln(' bar = ', bar[1], ' ', bar[2]); end; begin arr[1] := 0; arr[2] := 0; writeln(' Before: arr = ', arr[1], ' ', arr[2]); foo(arr); writeln(' After: arr = ', arr[1], ' ', arr[2]); end. Here's the output from running that code: Before: arr = 0 0 bar = 0 42 After: arr = 0 42 Here's the equivalent C code, as close to an exact one-to-one correspondence as I can come up with: #include void foo(int bar[2]) { bar[1] = 42; printf("\n bar = %d %d ", bar[0], bar[1]); } int main() { int arr[2]={0,0}; printf("\n Before: arr = %d %d ", arr[0], arr[1]); foo(arr); printf("\n After: arr = %d %d ", arr[0], arr[1]); printf("\n"); return 0; } And the output of it: Before: arr = 0 0 bar = 0 42 After: arr = 0 42 If it walks like pass-by-reference, and smells like pass-by-reference, and swims like pass-by-reference, is it still your contention that it is pass-by-value? > For the purpose of clearing this up once and for all: arrays, in C, are > `don't-pass-at-all'. There is no way -- none whatever -- of declaring a > function parameter as having array type. It looks just like I did precisely that here: void foo(int bar[2]) I guess this is where you explain again that arrays in C are "bizarre", and that while "int arr[2]" inside a function body means "declare an array of two ints and call it 'arr'", the exact same declaration in a function parameter list means something else. Possibly: "Declare a pointer which points to an array of two ints, call the pointer 'arr', and dereference the pointer every time it is used inside the function as if you were referring to the array directly". Am I close? -- Steven From http Sun Jan 11 09:32:31 2009 From: http (Paul Rubin) Date: 11 Jan 2009 06:32:31 -0800 Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xd4etj4lc.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > If it walks like pass-by-reference, and smells like pass-by-reference, > and swims like pass-by-reference, is it still your contention that it is > pass-by-value? Of course the C example is pass by value. It's just that the value being passed is an address. From steve at holdenweb.com Sun Jan 11 09:59:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 11 Jan 2009 09:59:21 -0500 Subject: Regex for unicode letter characters In-Reply-To: <496969A5.4090601@mrabarnett.plus.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> <496969A5.4090601@mrabarnett.plus.com> Message-ID: MRAB wrote: > Steve Holden wrote: >> MRAB wrote: >>> schickb wrote: >>>> I need a regex that will match strings containing only unicode letter >>>> characters (not including numeric or the _ character). I was surprised >>>> to find the 're' module does not include a special character class for >>>> this already (python 2.6). Or did I miss something? >>>> >>>> It seems like this would be a very common need. Is the following the >>>> only option to generate the character class (based on an old post by >>>> Martin v. L?wis )? >>>> >>> [snip] >>> Basically, yes. >>> >>> The re module was last worked on in 2003 (remember it's all voluntary!). >>> Such omissions should be addressed in Python 2.7. >> >> By "should be" do you mean "ought to be (but I have no intention of >> helping)", "are expected to be (but someone else will be doing the >> work", "it's on my list and I am expecting to get finished in time for >> 2.7 integration" or something else? >> > The third one. Well, that's good news. Let me know if you need help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 11 10:06:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 11 Jan 2009 10:06:46 -0500 Subject: Python strings and coding conventions In-Reply-To: References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: Mensanator wrote: > On Jan 10, 10:26?pm, Robert Kern wrote: >> koranth... at gmail.com wrote: >>> Hi, >>> ? ?Python Coding Convention (PEP 8) suggests : >>> ? Maximum Line Length >>> ? ? Limit all lines to a maximum of 79 characters. >>> ? I have a string which is ~110 char long. It is a string which I am >>> going to print in a text file as a single string. >>> ? i.e. in that text file, each line is taken as a different record - >>> so it has to be in a single line. >>> ? Now, how can I write this code - while following PEP 8? >>> ? I tried blockstrings, but as shown in the example below: >>>>>> s = r''' >>> ... abcd >>> ... efgh >>> ... ''' >>>>>> s >>> '\nabcd\nefgh\n' >>> ? ?it has "\n" inserted - which will disallow printing it to a single >>> line. >>> ? ?I thought about other options like concatenating strings etc, but >>> it seems very kludgy - esp since the whole string has a single meaning >>> and cannot be easily split to many logically. Then I thought of >>> creating a blockstring and then removing "\n", but it seemed >>> kludgier... >> I usually use implicit concatenation: >> >> s = ('some long text that ' >> ? ? ? 'needs to be split') > > Damn! I didn't know you could do that! And if I > saw it in a program listing, such would never occur > to me. I was going to suggest the stupid way: > Another option is escaping the newlines in triple-quoted strings: >>> s = """Some long text that \ ... needs to be split""" >>> s 'Some long text that needs to be split' >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From castironpi at gmail.com Sun Jan 11 10:21:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 07:21:49 -0800 (PST) Subject: why cannot assign to function call References: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> <7xd4etj4lc.fsf@ruckus.brouhaha.com> Message-ID: On Jan 11, 8:32?am, Paul Rubin wrote: > Steven D'Aprano writes: > > If it walks like pass-by-reference, and smells like pass-by-reference, > > and swims like pass-by-reference, is it still your contention that it is > > pass-by-value? > > Of course the C example is pass by value. ?It's just that the value > being passed is an address. I believe, that in order for the C example to be p-b-r, you would need the following: void foo(var int bar[2]) { bar = malloc( something ); } Such that the caller reflects the change. From google at mrabarnett.plus.com Sun Jan 11 11:10:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 16:10:53 +0000 Subject: Python strings and coding conventions In-Reply-To: <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> Message-ID: <496A1A0D.1060708@mrabarnett.plus.com> koranthala at gmail.com wrote: > On Jan 11, 9:26 am, Robert Kern wrote: >> koranth... at gmail.com wrote: >>> Hi, >>> Python Coding Convention (PEP 8) suggests : >>> Maximum Line Length >>> Limit all lines to a maximum of 79 characters. >>> I have a string which is ~110 char long. It is a string which I am >>> going to print in a text file as a single string. >>> i.e. in that text file, each line is taken as a different record - >>> so it has to be in a single line. >>> Now, how can I write this code - while following PEP 8? >>> I tried blockstrings, but as shown in the example below: >>>>>> s = r''' >>> ... abcd >>> ... efgh >>> ... ''' >>>>>> s >>> '\nabcd\nefgh\n' >>> it has "\n" inserted - which will disallow printing it to a single >>> line. >>> I thought about other options like concatenating strings etc, but >>> it seems very kludgy - esp since the whole string has a single meaning >>> and cannot be easily split to many logically. Then I thought of >>> creating a blockstring and then removing "\n", but it seemed >>> kludgier... >> I usually use implicit concatenation: >> >> s = ('some long text that ' >> 'needs to be split') >> >> -- >> 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 > > This is a very good method. > I found another method too - on further investigation >>>> s = "abc\ > ... efg" >>>> s > 'abcefg' > Only problem being that it doesnt support indentation. > So, implicit concatenation it is... > Another possibility is continuation _plus_ implicit concatenation. def example(): message = "now is the time " \ "for all good people ..." print message From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 11:28:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 16:28:58 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> <7xd4etj4lc.fsf@ruckus.brouhaha.com> Message-ID: <017a14f4$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 06:32:31 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> If it walks like pass-by-reference, and smells like pass-by-reference, >> and swims like pass-by-reference, is it still your contention that it >> is pass-by-value? > > Of course the C example is pass by value. It's just that the value > being passed is an address. I believe that's exactly the way VAR (reference) parameters are implemented in Pascal. What's the difference? -- Steven From torriem at gmail.com Sun Jan 11 11:29:21 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jan 2009 09:29:21 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <496A1E61.8030009@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > Thank you, I found PySys_SetPythonHome() to set the path where the lib > folder of Python is, but I guess they are not really implemented > because they are fixed compiled with an absolute path, aren't they? I'm afraid I'm not following you here. What is fixed compiled with an absolute path? What path are you talking about here? Linker path? Python default path for importing modules? Please read the documentation on embedding python and you'll see that you can initialize python and tell it to look anywhere for import modules. This is really all you have to do. In fact, if you import the built-in "sys" module, you can, from C++, add your Resource folder path to the sys.path dictionary (using api calls) and dynamically affect where python will import from. I did this once when I had a case where the user could place his plugin in an arbitrary spot. Hence I had to dynamically add the location to the path. If you are embedding python in your app, I would expect you to be familiar with the python apis. > Thats the problem. I hadn't compiled Python and I don't know if I > should > compile it as a dylib file or a framework? hmm. I know how to create a > framework but compiling as a dylib hadn't worked yet. :-( I'm very confused as previously you were talking about compiling python and now you're talking about not compiling python. Although it doesn't matter, since a framework file is a dylib file. In any case if you don't know how to set the linker paths (to relative) in App bundles, you'll want to consult apple docs, and the various apple e-mail lists. From googler.1.webmaster at spamgourmet.com Sun Jan 11 11:44:33 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 08:44:33 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> yeap, okay, its just the beginning so I didn't know that the framework is still the dylib file. Well, I only want to compile python and put the framework in the subdirectory. Thats all. And the current state is, that the framework is not found because the path of the compiled Python library is hardcoded so when I move it from /Library/Frameworks/ to my app folder it isn't found when I start my app. I found a ressource that I have to compile it with a dynamic path flag like LDFLAGS="-install_name, at executable_path/../Frameworks" to put it in the Framework of my app. maybe you know where my problem is. hm. bye From spaceoutlet at gmail.com Sun Jan 11 12:32:04 2009 From: spaceoutlet at gmail.com (Alex K) Date: Sun, 11 Jan 2009 18:32:04 +0100 Subject: template inheritance Message-ID: While building a website using template inheritance one usually does the following: fetch from database fetch from some more data from database ... << more required computations then at the end render the template with the fetched data Without template inheritance one usually does the following: fetch from database render this part of the site with this fetched data fetch some more data from the database render this other part of the site with the fetched data ... etc The first approach is much more elegant and leads to easier to maintain code. However the user will have to wait till the end of the fetching (long computations) before any rendering can take place. In the second approach however the site loads as we are fetching the data which is more convenient to the user. Am I correct to assume this? Is there a way to get the best of both worlds? Thank you. From mensanator at aol.com Sun Jan 11 12:48:53 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 09:48:53 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> Message-ID: <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> On Jan 11, 3:56?am, Marc 'BlackJack' Rintsch wrote: > On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote: > > Damn! I didn't know you could do that! And if I saw it in a program > > listing, such would never occur to me. I was going to suggest the stupid > > way: > > >>>> ga = ['four score and seven years ago ', \ > > ? ? ? ? ? 'our fathers brought forth ', \ > > ? ? ? ? ? 'on this continent a new nation ', \ > > ? ? ? ? ? 'conceived in liberty and dedicated ', \ > > ? ? ? ? ? 'to the proposition that all men ', \ > > ? ? ? ? ? 'are created equal'] > > What are all those line continuation characters ('\') for? ?You are aware > that they are unnecessary here? Actually, I wasn't aware of that. A quick review shows why. In the old manuals, implicit line continuation was in a seperate chapter (2.1.6) from implicit (2.1.5) so if you didn't read past 2.1.5 you would have missed it. The 2.6 manual is much better in this regard as it is now difficult to miss. Thanks for pointing that out as lists are just about the only place I use line continuation. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch From dotancohen at gmail.com Sun Jan 11 12:50:28 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 11 Jan 2009 19:50:28 +0200 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> References: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> Message-ID: <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> 2009/1/11 Sandro Tosi : >> I would suggest at least a chapter on _acquiring_ the data that is to >> be plotted using Python to scrape different sources _not_designed_ to >> be scraped. Online webpages come to mind. An example on retrieving, >> for instance, the prices of varying currencies, parsing the HTML >> pages, extracting the data, and then plotting it would be a great >> example for a real worlds usage that show matplotlib as a tool in a >> toolchain, not a means to an end. > > Well, a whole chapter to this is a little too much, but such examples > will be presented in the book: we're not going to teach how to program > in Python, but how to use matplotlib, so the data retriving is a > little out-of-scope (or at least border-line), so the code will be in > the examples provided along with the book, but not deeply explained in > the book text. > The problem with that approach is that you limit your audience to people who: 1) Are interested in matplotlab -AND- 2) Are already familiar with Python For every AND clause you remove you broaden the book's audience. You do not need to rewrite the book on Python programming or programming in general, but getting a C or even PHP programmer up to speed on the basics of Python as related to matplotlib will make the book much more accessible. At a minimum, it will add another valuable chapter to the book that can be safely ignored by Python gurus. And you are making the book that much more accessible. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From roy at panix.com Sun Jan 11 13:12:16 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 13:12:16 -0500 Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> Message-ID: In article <5db6181f-d6f6-4bdc-88c8-e12ad228c105 at r41g2000prr.googlegroups.com>, Mensanator wrote: > > What are all those line continuation characters ('\') for? ?You are aware > > that they are unnecessary here? > > Actually, I wasn't aware of that. A quick review shows > why. In the old manuals, implicit line continuation > was in a seperate chapter (2.1.6) from implicit (2.1.5) > so if you didn't read past 2.1.5 you would have missed it. My philosophy about line continuation is to assume lines can be continued after just about any piece of punctuation. If I'm wrong, the computer will tell me, and then I make the computer happy by adding a \. It's easier than looking it up, and way easier than memorizing the details. From mdw at distorted.org.uk Sun Jan 11 13:28:59 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 18:28:59 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <4140f1d3-0dff-4d20-84a1-17b735a71241@s9g2000prm.googlegroups.com> Message-ID: Aaron Brady wrote: > True or not, it requires the reader to know what references are. And, > since your definition conflicts with the C++ definition, it's not > clear that the requirement is good. I blame C++ for coopting a perfectly good word with a established well-understood meaning, and applying it to a half-baked and inconsistent concept. > More terminology: is 'a' a variable, a reference, or an object, in > 'a=2'? > > It's a variable; it refers to an object. > It's a variable, which refers to an object. > It's a variable, which is a reference to an object. > It's a reference to an object. It's an /identifier/ (2.3); or, if you want a shorter word, a /name/ (also 2.3). (I'll go with `name'.) In any given context, the name might or might not mean something. Names are assigned meanings by an /environment/; if the environment assigns a meaning to a name, we say that the name is /bound/ to that meaning; otherwise it is /unbound/. The rules for determining the environment at any given point in a program vary with language. Python is fairly simple: it is /lexically scoped/, which means that a great deal of information about the environment can be determined simply by analysing the program text statically. (Compare `dynamic scope', where the environment at any point in a program's executiondepends quite subtly on which functions are active at that point. The main difference is that, under lexical scoping, a function's environment is an extension of the environment in which it was defined, whereas under dynamic scoping a function's environment is an extension of the environment of the caller. Languages can offer both kinds of scoping simultaneously: both Common Lisp and Perl do this.) Python is /block-structured/: various syntactic forms (/blocks/) introduce new environments which are extensions of the environment of the enclosing block, i.e., within the inner block, a few names are bound to new meanings, while all the other names retain whatever meaning they had in the enclosing block. Names whose meanings are modified are said to be /bound by the block/. A name which occurs within the block is a /bound occurrence/ if the name is bound by the block, or a /free occurrence/ otherwise. Python has what one might call `implicit binding': a name appearing alone (or as part of a destructuring pattern) on the left-hand side of an assignment which would otherwise be a free occurrence, and in the absence of an explicit declaration such as `global' or `nonlocal', is implicitly bound to a fresh variable by the smallest enclosing block. Python also has explicit binding: e.g., the parameter names of a function are explicitly bound to new variables by the function. So, where were we? `a = 2'. The `a' is a name. It appears alone on the left-hand side of an assignment: this is therefore a candidate for implicit binding. Let's assume that `a' is bound to a variable, either as a result of this or some other implicit binding, or an explicit declaration. (I don't believe Python has meanings other than variables which might be bound to a name, so this is pretty safe. Scheme, for example, puts macros and special syntactic keywords in the same namespace as variables, so you can, for example, lexically rebind the IF keyword as a function, should you so wish. This is probably a bad idea.) So, `a' is bound to a variable. The variable, like all Python variables, stores a reference. We don't know what this reference might be before the assignment, but afterwards, we know that it must be a reference to an integer object representing the value 2. This is cumbersome to talk about; in informal conversations, one often talks about `the variable a' or even `the integer a'. It's important to realise that such phrases are abbreviations for convenience, and do not directly correspond to reality. > Similarly, is '2' an expression, a reference, or an object? > > It's an expression; it evaluates to an object. > It's an expression; it evaluates to a reference to an object. > It's an expression; it expresses an object. > It's an expression; it refers to an object. > It's a reference to an object. > It's an object. It's an /integer literal/ (2.4.3). It's also an expression, because all literals are expressions. We can confidently predict that the value of this expression (i.e., the result of evaluating it) is an integer object representing the value 2. > In the case of the Socratic, non-bludgeoning, dialogue with a student, > if the student can be trusted to question intelligently, s/he can be > expected, on our telling him/er, "'a' is an object", to ask, "What > object?" Whether to expect audience interaction, and what > interaction, is a big component in the choice of method of a > demonstration. Declaring `a' to be an object begs many questions, such as `what type does this object have?'. This is an unfortunate question, because the naive answer (e.g., from the above: `it's an integer') comes up against the problem that one can later say `a = "mumble"', causing one to declare `it's now a string'; but this contradicts 3.1: `An object's /type/ is also unchangeable' (with a footnote about how this might not be the complete truth). We could try to escape by saying that `a' is now a /different/ object, but that's strange because its appearance (i.e., the letter `a') hasn't changed at all. There are other problems with naively declaring that `a' is an object. In particular, if I just type `a' at a fresh Python, it says `name 'a' is not defined'. (Among other things, that tells me that `a' is a name.) Now the question `which object?' naively yields the answer `err... none -- no, not None, but none, there isn't one.'. At some level within the compiler, the `a' you type gets represented by an `object', though whether > >>> 300+301+302 is 300+301+302 > False > > There are 10 objects created in the evaluation of this, 11 if > including 'False'. They (their integer contents), in order, are: 300, > 301, 302, then 300, 301, 302, not the same ones, again, then 602, 903, > 602, 903, and then possibly 'False' *. Here we enter some philosophical (and implementation-specific) territory. Does the evaluation of a literal /create/ an object? The answer seems to be `maybe'. >>> 123456789 is 123456789 True Hmm. So at most one of the occurrences created a new object. I wonder... >>> def foo(x): ... if x is 123456789: print 'snap!' ... return 123456789 ... >>> foo(123456789) 123456789 >>> foo(_) snap! 123456789 It seems as if foo has a private copy of the magic number, rather than generating a new one (indeed, two new ones) each time. There is only one False object in the system (like there is only one None object). We can be sure that it didn't create that False specially for us. Given this, it doesn't seem right to talk about an expression necessarily creating objects, especially ones whose value appears literally. As another example, with strings this time: >>> def foo(): return '!mumble' ... >>> foo() is '!mumble' False >>> foo() is foo() True (The `!' suppresses the CPython compiler's interning process.) Tuples behave similarly. Lists, obviously, do not -- otherwise we could observably change the function's behaviour by mutating the list. (Lisp makes all of this much more explicit, since the input to the compiler consists of objects -- constructed by the reader -- rather than text, and one expects that, for example, self-evaluating and quoted objects evaluate identically to themselves, rather than creating new copies.) > * Based on a run of a build of 'r26:66714' with extra output from > 'PyInt_FromLong' and command line '-c "300+301+302 is 300+301+302"'. > Actual output showed 624 int objects created (!) with this function > alone, ending with: 300 301 302 300 301 302 11788072 8192 11788072 601 > 903 601 903! Any ideas about those extra three? My guess is that the first six at least are generated at compile-time, and then probably merged when the literal table is constructed. Some digging about with gdb shows that most of the early integer object constructions are from random modules imported on startup (even with `-S'). The `extra three' -- in your case 11788072 8192 11788072 -- are caused within PyAST_Compile. The first is by PySTEntry_New, constructing a new symbol table, and the argument is actually the address of a _mod structure explaining what we're meant to be compiling. The second is the value of FREE << SCOPE_OFF, from within update_symbols, and the last is in PySymtable_Lookup, and again it's converted the _mod address to an integer. This doesn't actually leave me much the wiser. But basically they're artifacts of internal compiler wrangling. -- [mdw] From mensanator at aol.com Sun Jan 11 13:34:35 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 10:34:35 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> Message-ID: <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> On Jan 11, 12:12?pm, Roy Smith wrote: > In article > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > ?Mensanator wrote: > > > What are all those line continuation characters ('\') for? ?You are aware > > > that they are unnecessary here? > > > Actually, I wasn't aware of that. A quick review shows > > why. In the old manuals, implicit line continuation > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > so if you didn't read past 2.1.5 you would have missed it. > > My philosophy about line continuation is to assume lines can be continued > after just about any piece of punctuation. ?If I'm wrong, the computer will > tell me, and then I make the computer happy by adding a \. ?It's easier > than looking it up, and way easier than memorizing the details. I proably got mine from Visual Basic where there are no exceptions to explicit line continuation marks. A least adding them when not necessary doesn't cause a problem. From mdw at distorted.org.uk Sun Jan 11 13:42:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 18:42:04 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I guess this is where you explain again that arrays in C are "bizarre", > and that while "int arr[2]" inside a function body means "declare an > array of two ints and call it 'arr'", the exact same declaration in a > function parameter list means something else. I quoted 6.7.5.3p7 before. Please pay attention. : A declaration of a parameter as ``array of type'' shall be adjusted to : ``qualified pointer to type'', where the type qualifiers (if any) are : those specified within the [ and ] of the array type derivation. If : the keyword static also appears within the [and ] of the array type : derivation, then for each call to the function, the value of the : corresponding actual argument shall provide access to the first : element of an array with at least as many elements as specified by the : size expression. > "Declare a pointer which points to an array of two ints, call the pointer > 'arr', and dereference the pointer every time it is used inside the > function as if you were referring to the array directly". No. Declare a pointer which points to an int, and call the pointer `arr'. > Am I close? Vaguely. A pointer to an array is not the same as a pointer to its first element. The former has type T (*)[N]; the latter has type T *. The compiler entirely ignores the number (unless you write `static' -- little-known C99 feature). There is no further magic: it's just a pointer. -- [mdw] From rdcollum at gmail.com Sun Jan 11 14:00:58 2009 From: rdcollum at gmail.com (Roger) Date: Sun, 11 Jan 2009 11:00:58 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox Message-ID: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> Hi Everyone, I have a behavior associated with a default binding with Tkinter Listbox that I want to get rid of but I can't no matter if I return "break" on the binding or unbind it directly. If you have a Listbox where the bounding box is not completely revealed in the window that holds it and you use the mouse to drag the list box, the contents of the listbox will move in the X direction to reveal the area that's hidden. After searching the internet for hours I found the behavior I want to remove is a default binding as described here: http://tcltk.free.fr/man/TkCmd/listbox.php3 "[3] If the mouse leaves the listbox window with button 1 down, the window scrolls away from the mouse, making information visible that used to be off-screen on the side of the mouse. The scrolling continues until the mouse re-enters the window, the button is released, or the end of the listbox is reached. " After further searching I found that the code for this in tcl is described here: http://www.openmash.org/lxr/source/library/listbox.tcl?c=tk8.3 50 bind Listbox { 51 set tkPriv(x) %x 52 set tkPriv(y) %y 53 tkListboxMotion %W [%W index @%x,%y] 54 } Now I've found no way to successfully unbind B1-Motion from the listbox, as I said above. Nor return "break" on receiving the event. I do want to eventually have my own B1-Motion binding applied to the listbox for a different reason (with add='+' if necessary). My next step was to see if I could just unbind B1-Motion then programmatically delete tkListboxMotion in my code but tkListboxMotion is not available in the Tkinter source (it's part of a compiled binary I can't reach?). Any help would be greatly appreciated. Thanks! Roger. From metolone+gmane at gmail.com Sun Jan 11 14:08:18 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 11 Jan 2009 11:08:18 -0800 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494CBE at enbmail01.lsi.com... > The source of gzip.py on my system seems to suggest that negative seeks > are supported: > > def seek(self, offset): > if self.mode == WRITE: > if offset < self.offset: > raise IOError('Negative seek in write mode') > count = offset - self.offset > for i in range(count // 1024): > self.write(1024 * '\0') > self.write((count % 1024) * '\0') > elif self.mode == READ: > if offset < self.offset: > # for negative seek, rewind and do positive seek > self.rewind() > count = offset - self.offset > for i in range(count // 1024): > self.read(1024) > self.read(count % 1024) > > Could any who're familiar with the inner working of gzip settle this issue > ? > Is seek from EOF supported for gzip files ? Source from 2.6.1. Seek from EOF not supported: def seek(self, offset, whence=0): if whence: if whence == 1: offset = self.offset + offset else: raise ValueError('Seek from end not supported') if self.mode == WRITE: if offset < self.offset: raise IOError('Negative seek in write mode') count = offset - self.offset for i in range(count // 1024): self.write(1024 * '\0') self.write((count % 1024) * '\0') elif self.mode == READ: if offset < self.offset: # for negative seek, rewind and do positive seek self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) -Mark From matrixhasu at gmail.com Sun Jan 11 14:16:25 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 20:16:25 +0100 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> References: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> Message-ID: <8b2d7b4d0901111116u44282b2ey9300f20c9f530b05@mail.gmail.com> On Sun, Jan 11, 2009 at 18:50, Dotan Cohen wrote: > 2009/1/11 Sandro Tosi : >>> I would suggest at least a chapter on _acquiring_ the data that is to >>> be plotted using Python to scrape different sources _not_designed_ to >>> be scraped. Online webpages come to mind. An example on retrieving, >>> for instance, the prices of varying currencies, parsing the HTML >>> pages, extracting the data, and then plotting it would be a great >>> example for a real worlds usage that show matplotlib as a tool in a >>> toolchain, not a means to an end. >> >> Well, a whole chapter to this is a little too much, but such examples >> will be presented in the book: we're not going to teach how to program >> in Python, but how to use matplotlib, so the data retriving is a >> little out-of-scope (or at least border-line), so the code will be in >> the examples provided along with the book, but not deeply explained in >> the book text. > > The problem with that approach is that you limit your audience to people who: > 1) Are interested in matplotlab > -AND- > 2) Are already familiar with Python That is exactly the target the editor wants to reach... > For every AND clause you remove you broaden the book's audience. You > do not need to rewrite the book on Python programming or programming > in general, but getting a C or even PHP programmer up to speed on the > basics of Python as related to matplotlib will make the book much more > accessible. At a minimum, it will add another valuable chapter to the > book that can be safely ignored by Python gurus. And you are making > the book that much more accessible. I will try to ask this, but they were really clear that knowing python is a prerequisite of the book readers. -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi From rurpy at yahoo.com Sun Jan 11 14:18:38 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 11 Jan 2009 11:18:38 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Message-ID: <22449938-4dab-45ae-820f-15e2c84963a5@v18g2000pro.googlegroups.com> Mark Wooding wrote: > rurpy at yahoo.com wrote: >> Mark Wooding wrote: >> > rurpy at yahoo.com wrote: >... >> > For another: >> > >> > static void bar(char v[]) { char ch = 0; v = &ch; } >> > /* type error if arrays truly passed by reference */ >> >> v can be used as an array reference, e.g. "v[1] = 23" >> exactly as in the pass-by-reference fortran example. And >> v can also be used as a local variable and reassigned. > >> If the first option was the only one, would you not >> say C was definitely pass-by-reference (for arrays)? >> If one could only use v as a pointer (i.e. access >> the argument array as "*(v+1) = 23", then I would >> say that arrays are not passed at all, only pointers >> by-value. > > Your knowledge of C is clearly limited, at best. The notations *(p + i) > and p[i] are entirely equivalent in every way, since the square-brackets > indexing operator is in fact defined in terms of pointer dereference > (6.5.2.1): >... Yes, my C experience is limited. I very rarely write any C these days and even many years ago when I wrote more, it was very vanilla stuff not requiring any deep knowlage of dark corners of the language. Nevertheless, I am aware of everything you wrote above (the gist, not the standard's verbiage) and the common demonstration of it: 3["surprised?"] => 'p'. But if you'll note, I said "if ..." referring to a couple of hypothetical C-like languages, so your chapter-and-verse quote from the standard, while interesting and appreciated, was basically irrelevant. >... >> > Also, notice that arrays in expressions turn into pointers in the same >> > way, so function argument passing works the same way as assignment -- a >> > hallmark of pass-by-value. >> >> Not in all expressions as you yourself mentioned: >> int a[10], *ap; >> sizeof a; >> sizeof ap; > > Well done, you've pedantically picked up on the lapse in the first part It isn't pedantic. It is the only thing (IFAIK) that allows one to talk about variables of an array type (as opposed to only pointers). >... > Since I'm getting thoroughly fed up of repeating myself on this point, > I'm simply going to assume, from now on, that anyone who offers a > disagreement without citing passages from (at least a specific draft of) > ISO 9899 to support any claims made is simply being wilfully ignorant -- > and therefore no longer worth my attention. > > (If you don't have a copy of any such version, may I suggest > > http://std.dkuug.dk/jtc1/sc22/open/n2794/ > > citing this (confusingly) as n843, as a place to start.) Actually I've already downloaded a C89/90 standard draft in the hope that an earlier version would be simpler. Since C's behavior vis "call-by-x" is (I presume) unchanged back to K&R, whatever it said about it should be confirmable by any ealier versions descriptions of C. But more importantly, we seem to be talking at cross purposes. My idea of a language model is a description of the language that is precise enough to allow a model's user to predict how any piece of code will behave when run. The C-standard(s) do that for C. Since many people would claim that a language that does not behave as the C standard describes is not C, it is definitional, and one cannot reasonably say that the model presented in the C standard is incorrect. (Of course, like all standards, the C standard is not perfect, it contains errors and inconsistencies that require correction, and like all languages, C evolves requiring new versions of the standard.) Nevertheless, I see no reason to believe, based on anything said in this thread, or my experience in general, that there can be *only* one correct model of a language, or part of a language. So all the quoting of the C standard in the world does not address the issue: can C's array passing be described (modeled) as pass-by-reference? I acknowledge that the C standard provides one (correct) model in which arrays aren't passed, only pointers by-value. To address the issue you need to show that an alternate model (array passing by-reference for example) is incorrect, i.e. leads it user to conclude that a program will behave differently than it does. And of course, when such a discrepancy model and behavior is pointed out, the proposer of the alternate model will fix it if possible. If you can not show that an alternate model is incorrect, then the next best thing is to show that your model is better. Better would involve considerations such as simpler, consistent with other languages, easier to understand by various categories of users, etc. Obviously this is a very subjective task, and one could expect disagreement. Many of the responses by you, Joe, and others, have an "of course this model is the right one, how could anyone think otherwise" tone to them. I hope I have explained clearly why I think that attitude is unjustified. Finally, and please don't be insulted by this, but to me and many readers, you are a bunch on glowing dots on a screen. I have been using the internet long enough to have any number of times read very plausible, authoritative sounding tomes only to find out later they were BS, or a least, not as widely accepted as gospel as the author proclaimed. All that not withstanding, thank you for taking the time to respond in the depth you have. I appreciate it and have clarified a lot of my thinking on the subject as as result. From deets at nospam.web.de Sun Jan 11 15:04:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 11 Jan 2009 21:04:11 +0100 Subject: template inheritance In-Reply-To: References: Message-ID: <6sv1lsF8arprU1@mid.uni-berlin.de> Alex K schrieb: > While building a website using template inheritance one usually does > the following: > > fetch from database > fetch from some more data from database > ... << more required computations > then at the end render the template with the fetched data > > Without template inheritance one usually does the following: > > fetch from database > render this part of the site with this fetched data > fetch some more data from the database > render this other part of the site with the fetched data > ... > etc > > The first approach is much more elegant and leads to easier to > maintain code. However the user will have to wait till the end of the > fetching (long computations) before any rendering can take place. In > the second approach however the site loads as we are fetching the data > which is more convenient to the user. > > Am I correct to assume this? Is there a way to get the best of both > worlds? Thank you. I don't think that the question of inheritance or not is really relevant here. It's a matter of how the templating system is written - does it collect all the data beforehand, or not, is it potentially using e.g. generators and so forth. And of course how the programmer uses the templating system. does he fetch all the data beforehand, or does he use lazy generation approachs - again, e.g. generators, or callbacks. Besides, *usually* the 20-39Kb of a website itself aren't the problem I'd say - loading referenced resources is much more of an issue. And AFAIK the render-mode matters, too. If the site is XHTML-compliant, the browser can start the rendering once the HTML is complete - otherwise, it might wait until the referenced resources are all loaded to calculate the layout. Diez From sjmachin at lexicon.net Sun Jan 11 15:37:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 12:37:17 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> Message-ID: <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> On Jan 12, 5:34?am, Mensanator wrote: > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > > > > In article > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > Mensanator wrote: > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > that they are unnecessary here? > > > > Actually, I wasn't aware of that. A quick review shows > > > why. In the old manuals, implicit line continuation > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > so if you didn't read past 2.1.5 you would have missed it. > > > My philosophy about line continuation is to assume lines can be continued > > after just about any piece of punctuation. If I'm wrong, the computer will > > tell me, and then I make the computer happy by adding a \. It's easier > > than looking it up, and way easier than memorizing the details. > > I proably got mine from Visual Basic where there are no > exceptions to explicit line continuation marks. A least > adding them when not necessary doesn't cause a problem. Fugly code is not a problem? From mdw at distorted.org.uk Sun Jan 11 15:45:46 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 20:45:46 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> <22449938-4dab-45ae-820f-15e2c84963a5@v18g2000pro.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > But if you'll note, I said "if ..." referring to a couple of > hypothetical C-like languages, so your chapter-and-verse quote from > the standard, while interesting and appreciated, was basically > irrelevant. Ah, what you actually said was still quoted above (thanks): : v can be used as an array reference, e.g. "v[1] = 23" exactly as in : the pass-by-reference fortran example. And v can also be used as a : local variable and reassigned. : : If the first option was the only one, would you not say C was : definitely pass-by-reference (for arrays)? I must have been reading too quickly and I missed the conditional here. I'm terribly sorry. :-( Answering the question as posed, rather than mis-read: I think the sizeof business would still indicate that a pointer was being passed. If the language also forbade sizeof on array-type arguments and passing array as arguments to functions expecting pointers, then I'd say you'd have a point. But I'm not sure I'd agree that such a language was `C-like' -- the bizarre behaviour of arrays is one of the language's most distinctive features! > >> > Also, notice that arrays in expressions turn into pointers in the same > >> > way, so function argument passing works the same way as assignment -- a > >> > hallmark of pass-by-value. > >> > >> Not in all expressions as you yourself mentioned: > >> int a[10], *ap; > >> sizeof a; > >> sizeof ap; > > > > Well done, you've pedantically picked up on the lapse in the first part > > It isn't pedantic. It is the only thing (IFAIK) that allows one to > talk about variables of an array type (as opposed to only pointers). You can talk about /variables/ of array type, but not /expressions/ of array type (except in very limited circumstances, as operands of sizeof or &). > Actually I've already downloaded a C89/90 standard draft in the hope > that an earlier version would be simpler. Since C's behavior vis > "call-by-x" is (I presume) unchanged back to K&R, whatever it said > about it should be confirmable by any ealier versions descriptions of > C. It should be; but you may have to adjust the clause numbers I'm citing. Also, the earlier version of the standard didn't have numbered paragraphs, which makes citing specific bits more tedious. > But more importantly, we seem to be talking at cross purposes. We might be... [snip] > So all the quoting of the C standard in the world does not address the > issue: can C's array passing be described (modeled) as > pass-by-reference? I acknowledge that the C standard provides one > (correct) model in which arrays aren't passed, only pointers by-value. > > To address the issue you need to show that an alternate model (array > passing by-reference for example) is incorrect, i.e. leads it user to > conclude that a program will behave differently than it does. And of > course, when such a discrepancy model and behavior is pointed out, the > proposer of the alternate model will fix it if possible. I'd claim, in fact, that the proposer of an alternative model bears the responsibility to prove it correct, i.e., in the case of C, at least consistent with the official standard. But I believe that I have indeed shown that the arrays-passed-by- reference model is incorrect, by demonstrating that the called function sees the parameter as a freshly allocated pointer and not an array: it can be assigned (unlike an array); its size is that of a pointer; one can take its address and manipulate its bit-pattern as if it were a pointer. Indeed, the standard guarantees that no strictly-conforming C program can distinguish the parameter from a freshly allocated pointer. And therefore I can point to my earlier (almost-formal) definitions of pass-by-value and pass-by-reference to complete the proof: the allocation of a new variable is inconsistent with pass-by-reference, while it is consistent with pointer-decay followed by pass-by-value. Of course, this is contingent on your acceptance of my definitions. But I don't see anyone else providing sufficiently detailed definitions to make such proofs, and my definitions seem consistent with the way most other languages use the terms, so I'm pretty confident that they're good... > Many of the responses by you, Joe, and others, have an "of course this > model is the right one, how could anyone think otherwise" tone to > them. I hope I have explained clearly why I think that attitude is > unjustified. I hope that I've been doing more than that: drawing comparisons with and borrowing concepts from other languages, attempting to solidify definitions which otherwise seem to cause controversy, and then drawing conclusions from these definitions to strengthen my case and weaken others' cases. > Finally, and please don't be insulted by this, but to me and many > readers, you are a bunch on glowing dots on a screen. As are we all. (Brought to you by Sobering Thought for the Day.) > I have been using the internet long enough to have any number of times > read very plausible, authoritative sounding tomes only to find out > later they were BS, or a least, not as widely accepted as gospel as > the author proclaimed. I'm trying very hard not to ask anyone to take my word for things -- it always makes me uneasy when people are willing to do that, but they seem to be[1]. Rather, I'm attempting to present my reasoning in a way that you and others can read and judge for yourselves. If I've failed, then I'm sorry -- I'm fallible, and my communication skills are somewhere between imperfect and downright patchy depending on who you talk to. [1] I work in security. Being asked to take things on trust rubs me up the wrong way, and I hope that other people react the same way; if they don't, I get nervous... > All that not withstanding, thank you for taking the time to respond in > the depth you have. I appreciate it and have clarified a lot of my > thinking on the subject as as result. -- [mdw] From madhusudancs at gmail.com Sun Jan 11 16:22:47 2009 From: madhusudancs at gmail.com (Madhusudan.C.S) Date: Sun, 11 Jan 2009 13:22:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? Message-ID: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> I am sorry all I am not here to just blame Python. This is just an introspection of whether what I believe is right. Being a devotee of Python from past 2 years I have been writing only small apps and singing praises about Python where ever I go. I now got a chance to read Django's code for some reason. I have now strongly started feeling if Python really follows its "Readability Counts" philosophy. For example, class A: a = 10 b = "Madhu" def somemethod(self, arg1): self.c = 20.22 d = "some local variable" # do something .... ... def somemethod2 (self, arg2): self.c = "Changed the variable" # do something 2 ... In such situations, where the Instance variables come into existence only when they are used it is very difficult to track the flow of code. Its obviously not possible to remember what instance variable was defined where, when reading some substantial amount of code and where it was manipulated for that matter. It becomes so very frustrating even when reading a Class's code with just 6-8 methods and not more than 100-150 lines of code. I am interested in knowing if I am reading this kind of code in the wrong way mostly because of C++/Java hangover since most other languages follow the same approach as them? If there is a Pythonic way reading this code for better readability? What made Python developers to adopt this strange strategy keeping "Readibility Counts" in mind? -- Python Rocks! Madhusudan.C.S From mensanator at aol.com Sun Jan 11 16:23:36 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 13:23:36 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> Message-ID: On Jan 11, 2:37?pm, John Machin wrote: > On Jan 12, 5:34?am, Mensanator wrote: > > > > > > > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > In article > > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > > Mensanator wrote: > > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > > that they are unnecessary here? > > > > > Actually, I wasn't aware of that. A quick review shows > > > > why. In the old manuals, implicit line continuation > > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > > so if you didn't read past 2.1.5 you would have missed it. > > > > My philosophy about line continuation is to assume lines can be continued > > > after just about any piece of punctuation. If I'm wrong, the computer will > > > tell me, and then I make the computer happy by adding a \. It's easier > > > than looking it up, and way easier than memorizing the details. > > > I proably got mine from Visual Basic where there are no > > exceptions to explicit line continuation marks. A least > > adding them when not necessary doesn't cause a problem. > > Fugly code is not a problem? Is that how you justify breaing "explicit is better than implicit"? From clp2 at rebertia.com Sun Jan 11 16:31:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 13:31:22 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <50697b2c0901111331t151a902q67b2f25a153100cb@mail.gmail.com> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > class A: > a = 10 > b = "Madhu" Those are class variables, not instance variables. There is a distinct difference. Instance variables, in contrast, are "declared" and created in the body of the __init__ method. > > def somemethod(self, arg1): > self.c = 20.22 > d = "some local variable" > # do something > .... > ... > def somemethod2 (self, arg2): > self.c = "Changed the variable" > # do something 2 > ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code and where > it was manipulated for that matter. It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. That's bad coding style on the part of the code writer. Conditionally-existing instance variables are *evil*. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sun Jan 11 16:42:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 13:42:41 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> Message-ID: <22a3c0ce-20c1-48a2-99ef-4ad4ae9db837@r36g2000prf.googlegroups.com> On Jan 12, 8:23?am, Mensanator wrote: > On Jan 11, 2:37 pm, John Machin wrote: > > > > > > > On Jan 12, 5:34 am, Mensanator wrote: > > > > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > > In article > > > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > > > Mensanator wrote: > > > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > > > that they are unnecessary here? > > > > > > Actually, I wasn't aware of that. A quick review shows > > > > > why. In the old manuals, implicit line continuation > > > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > > > so if you didn't read past 2.1.5 you would have missed it. > > > > > My philosophy about line continuation is to assume lines can be continued > > > > after just about any piece of punctuation. If I'm wrong, the computer will > > > > tell me, and then I make the computer happy by adding a \. It's easier > > > > than looking it up, and way easier than memorizing the details. > > > > I proably got mine from Visual Basic where there are no > > > exceptions to explicit line continuation marks. A least > > > adding them when not necessary doesn't cause a problem. > > > Fugly code is not a problem? > > Is that how you justify breaing "explicit is > better than implicit"? I don't '''justify breaing "explicit is better than implicit"''' and wasn't attempting to do so. The Zen is more than one saying. No one saying trumps all others. Some may appear to be in conflict with others. One must consider the combined effect. Other sayings relevant to your problem are: Beautiful is better than ugly. Simple is better than complex. Readability counts. HTH, John From bjourne at gmail.com Sun Jan 11 16:59:34 2009 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sun, 11 Jan 2009 22:59:34 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <740c3aec0901111359k1a7007cfrbe1cf9616df49889@mail.gmail.com> 2009/1/11 Madhusudan.C.S : > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > class A: > a = 10 > b = "Madhu" > > def somemethod(self, arg1): > self.c = 20.22 > d = "some local variable" > # do something > .... > ... > def somemethod2 (self, arg2): > self.c = "Changed the variable" > # do something 2 > ... In this case is the "c" attribute not "declared" in the __init__() method of A? > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? Not declaring instance variables is just poor form. IMHO Python code should mostly be written like C++/Java. When you use "tricks" like the above (dynamically adding attributes to a class) or getattr calls, catching AttributeErrors, manipulating __dict__, decorators or metaclasses you should really think twice whether you actually _need_ to use those tricks. -- mvh Bj?rn From kiliansto at gmail.com Sun Jan 11 17:06:22 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 14:06:22 -0800 (PST) Subject: Object help Message-ID: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> I have a class called ball. The members are things like position, size, active. So each ball is an object. How do I make the object without specifically saying ball1 = ball()? Because I don't know how many balls I want; each time it is different. The balls are to be thrown in from the outside of the screen. I think you get that is enough information. This doesn't directly pertain to balls, I have wanted to do something like this for many different things but didn't know how. I would think something like: def newball(): x = last_named_ball + 1 ball_x = ball(size, etc) # this initializes a new ball return ball_x But then that would just name a ball ball_x, not ball_1 or ball_2. Is it possible? From clp2 at rebertia.com Sun Jan 11 17:15:01 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 14:15:01 -0800 Subject: Object help In-Reply-To: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <50697b2c0901111415y2518b4d5j27c1bf7de7608b28@mail.gmail.com> On Sun, Jan 11, 2009 at 2:06 PM, killsto wrote: > I have a class called ball. The members are things like position, > size, active. So each ball is an object. Class names should use CamelCase, so it should be `Ball`, not `ball`. > How do I make the object without specifically saying ball1 = ball()? > Because I don't know how many balls I want; each time it is different. > > The balls are to be thrown in from the outside of the screen. I think > you get that is enough information. > > This doesn't directly pertain to balls, I have wanted to do something > like this for many different things but didn't know how. > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball > return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > Is it possible? Yes, but only using deep dark black magic. Just use a list of Ball objects instead. Example: the_balls = [Ball(size, etc) for i in range(number_of_balls)] -- Follow the path of the Iguana... http://rebertia.com From jervisau at gmail.com Sun Jan 11 17:17:46 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Mon, 12 Jan 2009 09:17:46 +1100 Subject: Object help In-Reply-To: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <8e63a5ce0901111417q56bffcc9wf1d0c99822dadf5@mail.gmail.com> On Mon, Jan 12, 2009 at 9:06 AM, killsto wrote: > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball > return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > Is it possible? > > How about placing the balls in a python list:balls = [Ball() for i in range(number_of_balls)] where number_of_balls is the number of balls you want to create. additional balls can be added to the list: balls.append(Ball()) now you can access the balls like so: >>> balls[0] < __main__.Ball instance at ...> -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 17:20:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 22:20:17 GMT Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <017a6749$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > I have a class called ball. The members are things like position, size, > active. So each ball is an object. > > How do I make the object without specifically saying ball1 = ball()? > Because I don't know how many balls I want; each time it is different. > > The balls are to be thrown in from the outside of the screen. I think > you get that is enough information. > > This doesn't directly pertain to balls, I have wanted to do something > like this for many different things but didn't know how. > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. This is the TOTALLY wrong approach. Instead of having named balls, have a list of balls. balls = [] # no balls yet balls.append(Ball()) # one ball comes in from off-screen balls.append(Ball()) # and a second del balls[0] # the first ball got stuck in a tree balls = [] # all the balls were swept up in a hurricane and lost balls = [Ball(), Ball(), Ball(), Ball()] # four balls come in balls.append(Ball()) # and a fifth for b in balls: print b.colour # print the colour of each ball and so forth. -- Steven From pavlovevidence at gmail.com Sun Jan 11 17:42:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 14:42:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> On Jan 11, 3:22?pm, "Madhusudan.C.S" wrote: > ? I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. Ok, let's clear up a couple misconceptions right now. First: "Reabability counts" is a design principle of the language, not a mandate that every Python programmer write readable code. If Django project wants to write less readable code, they can. "Readability counts" means that Python is designed to make it easy for the Django project to write readable code if they choose. Second: "Readability counts" is not the only factor that matters. There are 19 Zen and sometimes they conflict with each other. Python tries to balance all these concerns; it doesn't greedily maximize any one of them. Some things might be a little less readable than they could be, but oftentimes that's because other design considerations were judged more important in that case. Having cleared that up, let's consider your specific points. > For example, > > ? ? class A: > ? ? a = 10 > ? ? b = "Madhu" > > ? ? def somemethod(self, arg1): > ? ? ? ? self.c = 20.22 > ? ? ? ? d = "some local variable" > ? ? ? ? # do something > ? ? ? ? .... > ? ? ... > ? ? def somemethod2 (self, arg2): > ? ? ? ? self.c = "Changed the variable" > ? ? ? ? # do something 2 > ? ? ? ? ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code Impossible? You are seriously overstating things. > and where > it was manipulated for that matter. This criticism is completely unfair. Instance variables have to be manipulated somewhere, and unless your object is immutable, that is going to happen outside of __init__. That's true in Java, C++, and pretty much any other language. > It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. > > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? (Well, it is a lot safer in Python. In C++, if you try to use an uninitialized variable, you'd get undefined behavior. Better to initialize it to null and at least get a guaranteed segfault. In Python if you try to use an uninitialized variable you'd get an AttributeError.) > If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? I'm not going to argue that this doesn't hurt readability, because it does (though not nearly as much as you claim). But there are other considerations, and in this case the flexibility of defining attributes outside __init__ is worth the potential decrease in readability. Here's a couple examples of where it's useful: 1. Sometimes classes are initialized without calling __init__, strange but true. Look at the pickle module, for instance. It creates the object without calling __init__ then sets all the instance variables itself. 2. Some classes have factory classmethods that create the object by a different means than calling __init__. (In fact, some classes have an internal method that initializes variables, which __init__ and the factories both call.) 3. Some objects, such as proxies, have uncertain sets of attributes. Requiring such objects to predict all the variables they need inside __init__ would limit their usability. Programmers would probably resort to hack-like workarounds like Decorator Design Pattern. 4. It allows a simplification of the object system. Right now, all attribute access is handled identically: at any point in time any attribute may be set. If you wanted to limit attribute creation to __init__, then it would mean objects have to have two phases (one, during __init__, where you can create attributes; the other, where you can only modify them). This would add significant complexity, and "Simple is better than complex. I'll also point out that even in C++/Java/etc. you have occasions where an instance variable doesn't do anything until a something triggers it. You can look to the constructor to see what it's initialized to, but it isn't really initialized to anything useful until some method call sets it to something useful. (Python makes it explicit that the variable isn't in use until it is initialized, and "Explicit is better than implicit".) In the end, the answer to you question is simply, "Readibilty counts, but other stuff matters too." Carl Banks From notvalid2 at sbcglobal.net Sun Jan 11 17:55:14 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 14:55:14 -0800 Subject: Where Find Activestate Python 2.5? Message-ID: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> I went to their site and the only choice seems 2.6. I looked around and found no other choices. Is it possible to get 2.5? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From sjmachin at lexicon.net Sun Jan 11 18:02:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 15:02:24 -0800 (PST) Subject: Where Find Activestate Python 2.5? References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> Message-ID: <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> On Jan 12, 9:55?am, "W. eWatson" wrote: > I went to their site and the only choice seems 2.6. I looked around and > found no other choices. Is it possible to get 2.5? What do you see when you go to http://www.activestate.com/activepython/downloads/ and scroll down? I see 3.0, 2.6.1, 2.6, 2.5.2. From http Sun Jan 11 18:02:54 2009 From: http (Paul Rubin) Date: 11 Jan 2009 15:02:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> Message-ID: <7x63klqwdd.fsf@ruckus.brouhaha.com> Carl Banks writes: > and where it was manipulated for that matter. > > This criticism is completely unfair. Instance variables have to be > manipulated somewhere, and unless your object is immutable, that is > going to happen outside of __init__. That's true in Java, C++, and > pretty much any other language. The criticism is very valid. Some languages do support immutable variables (e.g. "final" declarations in Java, "const" in C++, or universal immutability in pure functional languages) and they do so precisely for the purpose of taming the chaos of uncontrolled mutation. It would be great if Python also supported immutability. > I'm not going to argue that this doesn't hurt readability, because it > does (though not nearly as much as you claim). But there are other > considerations, and in this case the flexibility of defining > attributes outside __init__ is worth the potential decrease in > readability. There are cases where this is useful but they're not terribly common. I think it would be an improvement if creating new object attributes was by default not allowed outside the __init__ method. In the cases where you really do want to create new attributes elsewhere, you'd have to explicitly enable this at instance creation time, for example by inheriting from a special superclass: class Foo (DynamicAttributes, object): pass > 4. It allows a simplification of the object system. Right now, all > attribute access is handled identically: at any point in time any > attribute may be set. If you wanted to limit attribute creation to > __init__, then it would mean objects have to have two phases (one, > during __init__, where you can create attributes; the other, where you > can only modify them). This would add significant complexity, and > "Simple is better than complex. On the other hand, correct is better than buggy. From pavlovevidence at gmail.com Sun Jan 11 18:15:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 15:15:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> On Jan 11, 3:31?pm, Chris Rebert wrote: > On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > > ? ?def somemethod(self, arg1): > > ? ? ? ?self.c = 20.22 > > ? ? ? ?d = "some local variable" > > ? ? ? ?# do something > > ? ? ? ?.... > > ? ?... > > ? ?def somemethod2 (self, arg2): > > ? ? ? ?self.c = "Changed the variable" > > ? ? ? ?# do something 2 > > ? ? ? ?... > > > In such situations, where the Instance variables come into existence > > only when they are used > > it is very difficult to track the flow of code. Its obviously not > > possible to remember what > > instance variable was defined where, when reading some substantial > > amount of code and where > > it was manipulated for that matter. It becomes so very frustrating > > even when reading a Class's > > code with just 6-8 methods and not more than 100-150 lines of code. > > That's bad coding style on the part of the code writer. > Conditionally-existing instance variables are *evil*. Do you mean conditionally-useful instance variables evil, or that conditionally-useful variables are ok but it's evil for them to conditionally-exist? The former I don't agree with at all. If it's the latter, I believe there is something to be said for variables that exist when they are needed and don't when they're not. However, I acknowledge that listing all the variables you intend to use in __init__ is highly comforting, even if it does belie their current uselessness. Carl Banks From pavlovevidence at gmail.com Sun Jan 11 18:32:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 15:32:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> Message-ID: <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> On Jan 11, 5:02?pm, Paul Rubin wrote: > Carl Banks writes: > > and where it was manipulated for that matter. > > > This criticism is completely unfair. ?Instance variables have to be > > manipulated somewhere, and unless your object is immutable, that is > > going to happen outside of __init__. ?That's true in Java, C++, and > > pretty much any other language. > > The criticism is very valid. ?Some languages do support immutable > variables (e.g. "final" declarations in Java, "const" in C++, or > universal immutability in pure functional languages) and they do so > precisely for the purpose of taming the chaos of uncontrolled > mutation. ?It would be great if Python also supported immutability. I don't think what you said (which is fine) makes his criticism valid, unless you also suggest that all objects should be immutable. If any objects are mutable, you have to be prepared for objects to mutated outside the initializer. I guess it could be a valid criticism of Django's progamming style ("They mutate stuff haphazardly everywhere!!~") but that's not the Python langauge's problem. > > 4. It allows a simplification of the object system. ?Right now, all > > attribute access is handled identically: at any point in time any > > attribute may be set. ?If you wanted to limit attribute creation to > > __init__, then it would mean objects have to have two phases (one, > > during __init__, where you can create attributes; the other, where you > > can only modify them). ?This would add significant complexity, and > > "Simple is better than complex. > > On the other hand, correct is better than buggy. What bugginess do you speak of? Adding a variable outside __init__ is questionable style, not a bug. I don't think it's a significant source of bugs, either. And I definitely don't think the language should add a layer of complexity (and I think you're underestimating the complexity of making the whole object system two-phase) just to prevent a minor style issue. pychecker is the appropriate tool to diagnose this issue. Carl Banks From http Sun Jan 11 18:41:51 2009 From: http (Paul Rubin) Date: 11 Jan 2009 15:41:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> Message-ID: <7xhc45csw0.fsf@ruckus.brouhaha.com> Carl Banks writes: > > The criticism is very valid. ?Some languages do support immutable > > variables (e.g. "final" declarations in Java, "const" in C++, or > > universal immutability in pure functional languages) and they do so > > precisely for the purpose of taming the chaos of uncontrolled > > mutation. ?It would be great if Python also supported immutability. > > I don't think what you said (which is fine) makes his criticism valid, > unless you also suggest that all objects should be immutable. It would be enough to have a way to make specific objects and instance attributes immutable. > If any objects are mutable, you have to be prepared for objects to > mutated outside the initializer. Sure, but why have mutable objects all over the place? And, why always have attributes visible at all, outside the class definition? The approach in C++ and Java is to have public and private instance variables, where the private ones are visible only in the class methods. From kiliansto at gmail.com Sun Jan 11 18:49:27 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 15:49:27 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 11, 2:20?pm, Steven D'Aprano wrote: > On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > > I have a class called ball. The members are things like position, size, > > active. So each ball is an object. > > > How do I make the object without specifically saying ball1 = ball()? > > Because I don't know how many balls I want; each time it is different. > > > The balls are to be thrown in from the outside of the screen. I think > > you get that is enough information. > > > This doesn't directly pertain to balls, I have wanted to do something > > like this for many different things but didn't know how. > > > I would think something like: > > > def newball(): > > ? ? ?x = last_named_ball + 1 > > ? ? ball_x = ball(size, etc) # this initializes a new ball return ball_x > > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > This is the TOTALLY wrong approach. > > Instead of having named balls, have a list of balls. > > balls = [] ?# no balls yet > balls.append(Ball()) ?# one ball comes in from off-screen > balls.append(Ball()) ?# and a second > del balls[0] ?# the first ball got stuck in a tree > balls = [] ?# all the balls were swept up in a hurricane and lost > balls = [Ball(), Ball(), Ball(), Ball()] ?# four balls come in > balls.append(Ball()) ?# and a fifth > for b in balls: > ? ? print b.colour ?# print the colour of each ball > > and so forth. > > -- > Steven Thanks. That makes sense. It helps a lot. Although, you spelled color wrong :P. Just curious, is there another way? How would I do this in c++ which is listless IIRC. From clp2 at rebertia.com Sun Jan 11 18:49:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 15:49:31 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> Message-ID: <50697b2c0901111549r59e2e13bv7b19668d1ecc7210@mail.gmail.com> On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: > On Jan 11, 3:31 pm, Chris Rebert wrote: >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: >> > def somemethod(self, arg1): >> > self.c = 20.22 >> > d = "some local variable" >> > # do something >> > .... >> > ... >> > def somemethod2 (self, arg2): >> > self.c = "Changed the variable" >> > # do something 2 >> > ... >> >> > In such situations, where the Instance variables come into existence >> > only when they are used >> > it is very difficult to track the flow of code. Its obviously not >> > possible to remember what >> > instance variable was defined where, when reading some substantial >> > amount of code and where >> > it was manipulated for that matter. It becomes so very frustrating >> > even when reading a Class's >> > code with just 6-8 methods and not more than 100-150 lines of code. >> >> That's bad coding style on the part of the code writer. >> Conditionally-existing instance variables are *evil*. > > > Do you mean conditionally-useful instance variables evil, or that > conditionally-useful variables are ok but it's evil for them to > conditionally-exist? > > The former I don't agree with at all. > > If it's the latter, I believe there is something to be said for > variables that exist when they are needed and don't when they're not. > However, I acknowledge that listing all the variables you intend to > use in __init__ is highly comforting, even if it does belie their > current uselessness. The latter. I never even used the word "useful", so I have no idea where you got that from. To reiterate, variables which might only exist under certain conditions are evil, IMHO. This is not to say they are not useful in certain specific cases, just that in general there are better ways to design/structure programs to avoid them. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Sun Jan 11 18:53:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 23:53:04 +0000 (UTC) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: [Dynamically adding and removing instance attributes...] > Here's a couple examples of where it's useful: > > 1. Sometimes classes are initialized without calling __init__, [...] > 2. Some classes have factory classmethods [...] > 3. Some objects, such as proxies, have uncertain sets of attributes. [...] > 4. It allows a simplification of the object system. [...] All good points. I'd like to add a fifth: it can provide a handy hook for one module to hang data off of another module's objects. This sort of thing isn't very nice, but it's sometimes the best way. (Other approaches include using wrappers, which might be very invasive if opaque, or don't actually solve the name-collision problem if transparent; or maintaining a dictionary, which involves messing about with weak pointers if you want to keep it from filling with cruft.) > In the end, the answer to you question is simply, "Readibilty counts, > but other stuff matters too." Amen. -- [mdw] From prologic at shortcircuit.net.au Sun Jan 11 18:53:52 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 09:53:52 +1000 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jan 12, 2009 at 9:49 AM, killsto wrote: > Thanks. That makes sense. It helps a lot. Although, you spelled color > wrong :P. color colour They are both correct depending on what country you come from :) > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. Why are you asking us ? We're Python devs/programmers not C++ cheers James PS: I wouldn't touch C++ with a 10-foot pole From clp2 at rebertia.com Sun Jan 11 18:58:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 15:58:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xhc45csw0.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c0901111558o4568bc0fy51152e8e8017351e@mail.gmail.com> On Sun, Jan 11, 2009 at 3:41 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Carl Banks writes: >> If any objects are mutable, you have to be prepared for objects to >> mutated outside the initializer. > > Sure, but why have mutable objects all over the place? And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. Regarding the second question, Python adheres to the principle that "We're all consenting adults here" and so does not provide complete encapsulation like more B&D languages. This is handy sometimes as it allows one to break through the encapsulation when necessary and fiddle with the internals. This is not to say that breaking encapsulation willy-nilly is advised, but it does allow for some neat hackery every now and again. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From roy at panix.com Sun Jan 11 19:00:46 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 19:00:46 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: In article <34c95e04-5b3f-44bc-a5bf-498518507131 at p36g2000prp.googlegroups.com>, "Madhusudan.C.S" wrote: > In such situations, where the Instance variables come into existence > only when they are used it is very difficult to track the flow of code. As the saying goes, "It's possible to write Fortran in any language". My personal habit is to "declare" all instance variables in the __init__() method of every class. If there's no better value, I set them to None. This isn't strictly required, but I think it makes it easier for somebody reading the code to understand the class. I'm not a big fan of dogmatic rules, other than the rule that says you should make your code as easy for somebody else to understand as possible. From clp2 at rebertia.com Sun Jan 11 19:00:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 16:00:57 -0800 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: <50697b2c0901111600w451bae73k92489959a0dd9fb8@mail.gmail.com> On Sun, Jan 11, 2009 at 3:49 PM, killsto wrote: > On Jan 11, 2:20 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: >> > I have a class called ball. The members are things like position, size, >> > active. So each ball is an object. >> >> > How do I make the object without specifically saying ball1 = ball()? >> > Because I don't know how many balls I want; each time it is different. >> This is the TOTALLY wrong approach. >> >> Instead of having named balls, have a list of balls. > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. If *I* recall correctly, the STL has a `vector` type which is the equivalent of Python's `list`. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From torriem at gmail.com Sun Jan 11 19:01:36 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jan 2009 17:01:36 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> Message-ID: <496A8860.2020603@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > yeap, okay, its just the beginning so I didn't know that the framework > is still the dylib file. > Well, I only want to compile python and put the framework in the > subdirectory. Thats all. > And the current state is, that the framework is not found because the > path of the compiled Python > library is hardcoded so when I move it from /Library/Frameworks/ to my > app folder it isn't found > when I start my app. Okay, that last sentence finally started to make some sense. Basically you can fixup your executable and any libraries you need to have the "@executable_path" part *after* the fact. This is not about python, but see this excellent document on bundling Qt apps which explains how this is done: http://doc.trolltech.com/4.3/deployment-mac.html It will tell you every thing you need to know about making it so app bundles can include and link against libraries and frameworks inside the app bundle itself. The keys are "otool" and "install_name_tool." > > I found a ressource that I have to compile it with a dynamic path flag > like LDFLAGS="-install_name, at executable_path/../Frameworks" to put it > in the Framework of my app. maybe you know where my problem is. hm. Yeah that sounds like one way to do it. From notvalid2 at sbcglobal.net Sun Jan 11 19:29:16 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 16:29:16 -0800 Subject: Where Find Activestate Python 2.5? In-Reply-To: <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> Message-ID: John Machin wrote: > On Jan 12, 9:55 am, "W. eWatson" wrote: >> I went to their site and the only choice seems 2.6. I looked around and >> found no other choices. Is it possible to get 2.5? > > What do you see when you go to http://www.activestate.com/activepython/downloads/ > and scroll down? I see 3.0, 2.6.1, 2.6, 2.5.2. That's correct. If I try to get there (downloads) via starting with the home page (click Python tab), select ActivePython in the Community, then I see one large icon button that takes me to 2.6. If instead of using the button, I select ActiveState Downloads, then I get to . I see ActivePython among the Developer Tools. Using that gets me to , the big download 2.6 button again. Nowhere did I get your url. An interesting maze. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From pavlovevidence at gmail.com Sun Jan 11 19:33:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:33:12 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> Message-ID: <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> On Jan 11, 5:49?pm, Chris Rebert wrote: > On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: > > On Jan 11, 3:31 pm, Chris Rebert wrote: > >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > >> > ? ?def somemethod(self, arg1): > >> > ? ? ? ?self.c = 20.22 > >> > ? ? ? ?d = "some local variable" > >> > ? ? ? ?# do something > >> > ? ? ? ?.... > >> > ? ?... > >> > ? ?def somemethod2 (self, arg2): > >> > ? ? ? ?self.c = "Changed the variable" > >> > ? ? ? ?# do something 2 > >> > ? ? ? ?... > > >> > In such situations, where the Instance variables come into existence > >> > only when they are used > >> > it is very difficult to track the flow of code. Its obviously not > >> > possible to remember what > >> > instance variable was defined where, when reading some substantial > >> > amount of code and where > >> > it was manipulated for that matter. It becomes so very frustrating > >> > even when reading a Class's > >> > code with just 6-8 methods and not more than 100-150 lines of code. > > >> That's bad coding style on the part of the code writer. > >> Conditionally-existing instance variables are *evil*. > > > Do you mean conditionally-useful instance variables evil, or that > > conditionally-useful variables are ok but it's evil for them to > > conditionally-exist? > > > The former I don't agree with at all. > > > If it's the latter, I believe there is something to be said for > > variables that exist when they are needed and don't when they're not. > > However, I acknowledge that listing all the variables you intend to > > use in __init__ is highly comforting, even if it does belie their > > current uselessness. > > The latter. I never even used the word "useful", so I have no idea > where you got that from. I was just asking for clarification of your rationale, of which I imagined two possibilities ("conditional-usefulness is bad", or "declaring attributes outside of __init__" is bad). However... > To reiterate, variables which might only exist under certain > conditions are evil, IMHO. > This is not to say they are not useful in certain specific cases, just > that in general there are better ways to design/structure programs to > avoid them. ...the way you phrase this suggests to me that conditional-usefulness *is* what you are really concerned with. Let me give you an example: class A: def __init__(self): pass def something(self): self._conditionally_existent_variable = 1 ISTM that I don't need any restructuring at all to avoid conditional existence; all I'd have to do is add self._conditionally_existent_variable = None to __init__. If you think I need to restructure this code, than you evidently care about something more than just conditional existence. If so, what is it that's so evil about conditionally-existent variables? (I'll leave the question open-ended this time.) Carl Banks From rt8396 at gmail.com Sun Jan 11 19:37:09 2009 From: rt8396 at gmail.com (r) Date: Sun, 11 Jan 2009 16:37:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <05fbd39e-5906-4f84-886d-bc6c27d2c5ec@p29g2000vbn.googlegroups.com> On Jan 11, 6:00?pm, Roy Smith wrote: > In article > <34c95e04-5b3f-44bc-a5bf-498518507... at p36g2000prp.googlegroups.com>, > > ?"Madhusudan.C.S" wrote: > > In such situations, where the Instance variables come into existence > > only when they are used it is very difficult to track the flow of code. > > As the saying goes, "It's possible to write Fortran in any language". > > My personal habit is to "declare" all instance variables in the __init__() > method of every class. ?If there's no better value, I set them to None. ? > This isn't strictly required, but I think it makes it easier for somebody > reading the code to understand the class. > > I'm not a big fan of dogmatic rules, other than the rule that says you > should make your code as easy for somebody else to understand as possible. Roy i totally agree and as i read down this thread i was thinking i might get to spit that out first but you beat me -- Darn! PS: your explanation is also much more eloquent than mine would have been :) From http Sun Jan 11 19:42:52 2009 From: http (Paul Rubin) Date: 11 Jan 2009 16:42:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> Message-ID: <7xtz851hir.fsf@ruckus.brouhaha.com> Carl Banks writes: > If so, what is it that's so evil about conditionally-existent > variables? (I'll leave the question open-ended this time.) I have found they make the code more confusing and bug prone. It's better to define and document all the instance variables in one place, in most cases. From tjreedy at udel.edu Sun Jan 11 19:44:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Jan 2009 19:44:09 -0500 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: killsto wrote: > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. If you do not have 0) built-in expandable arrays, as in Python, one can 1) program (or find) the equivalent of Python lists; 2) use linked-lists (as long as one does not need O(1) random access); 3) pick a maximum number of items, either for the app or for the run, and allocate space for that. Python enthusiasts include those who see the virtue of option 0). From pavlovevidence at gmail.com Sun Jan 11 19:44:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:44:27 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <44341058-6055-4cfd-ae00-55fff4112a2e@r41g2000prr.googlegroups.com> On Jan 11, 5:41?pm, Paul Rubin wrote: > Carl Banks writes: > > > The criticism is very valid. ?Some languages do support immutable > > > variables (e.g. "final" declarations in Java, "const" in C++, or > > > universal immutability in pure functional languages) and they do so > > > precisely for the purpose of taming the chaos of uncontrolled > > > mutation. ?It would be great if Python also supported immutability. > > > I don't think what you said (which is fine) makes his criticism valid, > > unless you also suggest that all objects should be immutable. > > It would be enough to have a way to make specific objects and instance > attributes immutable. Enough for what, to make the guy's criticism valid? No it wouldn't. Or are you just ignoring the OP altogether and complaining about what bothers you? For my part I am concerned with answering the OP's issues here, not yours. > > If any objects are mutable, you have to be prepared for objects to > > mutated outside the initializer. > > Sure, but why have mutable objects all over the place? ?And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. The OP wasn't complaining about the fact that objects aren't immutable, as far as I can tell, nor about having public and private variables, so I can't agree Python's lack of these has anything to do with the OP's concerns. Carl Banks From marek at xivilization.net Sun Jan 11 19:44:51 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 12 Jan 2009 01:44:51 +0100 Subject: Where Find Activestate Python 2.5? References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> Message-ID: <20090112014451.35a588f0@halmanfloyd.lan.local> On Sun, 11 Jan 2009 16:29:16 -0800 "W. eWatson" wrote: > Using that gets me to > , the big download 2.6 > button again. Nowhere did I get your url. An interesting maze. Tried that "Other Systems and Versions" just below that "Download Now" button? regards, Marek From pavlovevidence at gmail.com Sun Jan 11 19:47:56 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:47:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> <7xtz851hir.fsf@ruckus.brouhaha.com> Message-ID: <0c65cf26-f0d0-4fba-87d9-7dda7869fa4e@s1g2000prg.googlegroups.com> On Jan 11, 6:42?pm, Paul Rubin wrote: > Carl Banks writes: > > If so, what is it that's so evil about conditionally-existent > > variables? ?(I'll leave the question open-ended this time.) > > I have found they make the code more confusing and bug prone. > It's better to define and document all the instance variables > in one place, in most cases. That means all I have to do is add a stopgap value in __init__. I'm asking Chris why that is evidently not enough, and that I'd have to structure/design my code to avoid it. Carl Banks From sjmachin at lexicon.net Sun Jan 11 20:07:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 17:07:30 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> On Jan 12, 10:49?am, killsto wrote: > On Jan 11, 2:20?pm, Steven D'Aprano wrote: > > On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > > > I have a class called ball. The members are things like position, size, > > > active. So each ball is an object. > > > > How do I make the object without specifically saying ball1 = ball()? > > > Because I don't know how many balls I want; each time it is different. > > > Instead of having named balls, have a list of balls. Or some other collection or container of objects (e.g. a dict or a queue), depending on what you are trying to simulate. > > for b in balls: > > ? ? print b.colour ?# print the colour of each ball > > Thanks. That makes sense. It helps a lot. Although, you spelled color > wrong :P. At this time of day you are likely to find yourself communicating with Australians. Get used to it :-) Cheers, John From roy at panix.com Sun Jan 11 20:16:24 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 20:16:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: In article , Chris Rebert wrote: > This is not to say that breaking encapsulation willy-nilly is advised, > but it does allow for some neat hackery every now and again. I'm all for neat hackery, except when used in code that I need to read and understand. From pavlovevidence at gmail.com Sun Jan 11 20:23:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 17:23:19 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: On Jan 9, 6:11?pm, John Machin wrote: > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > Aivar Annamaa wrote: > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > >> automatically fix. Changing print to print() on the other hand is > > > > >> easily fixed by 2to3. > > > > > >> Cheers, > > > > >> Chris > > > > > > I see. > > > > > So i gotta keep my own discipline with print() then :) > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > it as Python 3.x code. > > > > > regards > > > > ?Steve > > > > And mind you, if you follow that route, you are programming in a > > > mightily crippled language. > > > How do you figure? > > > I expect that it'd be a PITA in some cases to use the transitional > > dialect (like getting all your Us in place), but that doesn't mean the > > language is crippled. > > What is this "transitional dialect"? What does "getting all your Us in > place" mean? Transitional dialect is the subset of Python 2.6 that can be translated to Python3 with 2to3 tool. Getting all your Us in place refers to prepending a u to strings to make them unicode objects, which is something 2to3 users are highly advised to do to keep hassles to a minimum. (Getting Bs in place would be a good idea too.) > Steve & Cliff are talking about the rather small subset of Python that > is not only valid syntax in both 2.x and 3.x but also has the same > meaning in 2.x and 3.x. That would be a crippled language, yes. But I do not believe that's what Steve and Cliff are referring to. Steve wrote of "running your code through 2to3", and that was what Cliff followed up to, so I believe they are both referring to writing valid code in 2.6 which is able to be translated through 2to3, and then generating 3.0 code using 2to3. That is not a crippled language at all, just a PITA sometimes. > > >?It's about as bad as trying to write > > > cross-browser CSS. ?Don't put yourself through that pain if you don't > > > have to. > > > Have you tried doing that, or are you imagining how it will be? ?I'm > > curious about people's actual experiences. > > I maintain two packages, xlrd which supports 2.1 to 2.6, and xlwt > which supports 2.3 to 2.6. I've done suck-it-and-see trials on being > able to support 3.x as well from the same codebase, and it's turned > out reasonably well. xlrd already had a module called timemachine > which caters for version- dependent stuff. Extending this to 3.x was > more a voyage of discovery than a PITA. timemachine.py is "crippled" > in Cliff's sense, in that because I'm the principal user I need to > make it robust and idiot-proof, so it has been written under the > following constraints: > (1) not one copy of timemachine.py for 2.1, one for 2.2, one for > 2.3, ... etc; just one copy, period. > (2) means that it must use syntax that's valid in all supported > versions > (3) must be able to be processed by 2to3 without causing a commotion > (4) the original version and the 2to3 output must have the same effect > when imported by 3.x. > > So one ends up with code like: > ? ?glued = BYTES_NULL.join(list_of_pieces_of_a_binary_file) > which is supported by timemachine definitions like > BYTES_NULL = bytes(0) # 3.x ... note b'' is not valid in 2.x > BYTES_NULL = '' # 2.x > > BYTES_NULL.join() may be ugly, but it's not crippled, it's fully > functional, and it would be very easy to find and change in the future > in two possible scenarios (1) drop 2.x support (2) change codebase to > be mostly 3.x, support 2.x by a (mythical, hoped-for) 3to2 mechanism. Cool, thanks. Carl Banks From clp2 at rebertia.com Sun Jan 11 20:26:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 17:26:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> Message-ID: <50697b2c0901111726h5f3bd21cud85cca3ef3615d29@mail.gmail.com> On Sun, Jan 11, 2009 at 4:33 PM, Carl Banks wrote: > On Jan 11, 5:49 pm, Chris Rebert wrote: >> On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: >> > On Jan 11, 3:31 pm, Chris Rebert wrote: >> >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: >> >> > def somemethod(self, arg1): >> >> > self.c = 20.22 >> >> > d = "some local variable" >> >> > # do something >> >> > .... >> >> > ... >> >> > def somemethod2 (self, arg2): >> >> > self.c = "Changed the variable" >> >> > # do something 2 >> >> > ... >> >> >> > In such situations, where the Instance variables come into existence >> >> > only when they are used >> >> > it is very difficult to track the flow of code. Its obviously not >> >> > possible to remember what >> >> > instance variable was defined where, when reading some substantial >> >> > amount of code and where >> >> > it was manipulated for that matter. It becomes so very frustrating >> >> > even when reading a Class's >> >> > code with just 6-8 methods and not more than 100-150 lines of code. >> >> >> That's bad coding style on the part of the code writer. >> >> Conditionally-existing instance variables are *evil*. >> >> > Do you mean conditionally-useful instance variables evil, or that >> > conditionally-useful variables are ok but it's evil for them to >> > conditionally-exist? >> >> > The former I don't agree with at all. >> >> > If it's the latter, I believe there is something to be said for >> > variables that exist when they are needed and don't when they're not. >> > However, I acknowledge that listing all the variables you intend to >> > use in __init__ is highly comforting, even if it does belie their >> > current uselessness. >> >> The latter. I never even used the word "useful", so I have no idea >> where you got that from. > > I was just asking for clarification of your rationale, of which I > imagined two possibilities ("conditional-usefulness is bad", or > "declaring attributes outside of __init__" is bad). However... > > >> To reiterate, variables which might only exist under certain >> conditions are evil, IMHO. >> This is not to say they are not useful in certain specific cases, just >> that in general there are better ways to design/structure programs to >> avoid them. > > ...the way you phrase this suggests to me that conditional-usefulness > *is* what you are really concerned with. Let me give you an example: > > class A: > def __init__(self): > pass > def something(self): > self._conditionally_existent_variable = 1 > > > ISTM that I don't need any restructuring at all to avoid conditional > existence; all I'd have to do is add > > self._conditionally_existent_variable = None > > to __init__. If you think I need to restructure this code, than you > evidently care about something more than just conditional existence. No, this is exactly the sort of restructuring I was referring to; and nothing more. Making that one-line change would be sufficient for me. Perhaps "restructuring" was a poor choice of words... Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From prologic at shortcircuit.net.au Sun Jan 11 20:59:00 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 11:59:00 +1000 Subject: urllib2 - 403 that _should_ not occur. Message-ID: Hey all, The following fails for me: >>> from urllib2 import urlopen >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 389, in open response = meth(req, response) File "/usr/lib/python2.6/urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.6/urllib2.py", line 427, in error return self._call_chain(*args) File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden >>> However, that _same_ url works perfectly fine on the same machine (and same network) using any of: * curl * wget * elinks * firefox Any helpful ideas ? cheers James -- -- "Problems are solved by method" From narkewoody at gmail.com Sun Jan 11 21:00:40 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 12 Jan 2009 10:00:40 +0800 Subject: File layout in development stage Message-ID: Hi, Adapted your kindly suggestions in a previous post, I now decide to organize my source tree in a pattern like below: prj: src: lib: foomodule.py barmodule.py scripts: prj_main.py test: footest.py bartest.py ... That is, I want to put the top-level scripts in prj/src/scripts and share libraries in prj/src/lib. In the prj/test directory I want to put my unit-tests using unittest module. My question is that when in development stage there is no file is actually distributed, so how should a python source in one directory refer to (import) another module in another directory? Thanks in advance. - narke From aleksandr.goretoy at gmail.com Sun Jan 11 21:07:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 12 Jan 2009 02:07:23 +0000 Subject: File layout in development stage In-Reply-To: References: Message-ID: sys.path.append() -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 12, 2009 at 2:00 AM, Steven Woody wrote: > Hi, > > Adapted your kindly suggestions in a previous post, I now decide to > organize my source tree in a pattern like below: > > > prj: > src: > lib: > foomodule.py > barmodule.py > scripts: > prj_main.py > test: > footest.py > bartest.py > ... > > > That is, I want to put the top-level scripts in prj/src/scripts and > share libraries in prj/src/lib. In the prj/test directory I want to > put my unit-tests using unittest module. My question is that when in > development stage there is no file is actually distributed, so how > should a python source in one directory refer to (import) another > module in another directory? > > Thanks in advance. > > - > narke > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sun Jan 11 21:58:52 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 11 Jan 2009 21:58:52 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> On Jan 11, 2009, at 8:59 PM, James Mills wrote: > Hey all, > > The following fails for me: > >>>> from urllib2 import urlopen >>>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>> ") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen > return _opener.open(url, data, timeout) > File "/usr/lib/python2.6/urllib2.py", line 389, in open > response = meth(req, response) > File "/usr/lib/python2.6/urllib2.py", line 502, in http_response > 'http', request, response, code, msg, hdrs) > File "/usr/lib/python2.6/urllib2.py", line 427, in error > return self._call_chain(*args) > File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain > result = func(*args) > File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > urllib2.HTTPError: HTTP Error 403: Forbidden >>>> > > However, that _same_ url works perfectly fine on the > same machine (and same network) using any of: > * curl > * wget > * elinks > * firefox > > Any helpful ideas ? The remote server doesn't like your user agent? It'd be easier to help if you post a working sample. Cheers Philip From notvalid2 at sbcglobal.net Sun Jan 11 22:00:53 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 19:00:53 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) Message-ID: I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to try windowpy from ActiveState. Is having both of these installed going to cause me trouble? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From prologic at shortcircuit.net.au Sun Jan 11 22:05:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 13:05:30 +1000 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk wrote: > > On Jan 11, 2009, at 8:59 PM, James Mills wrote: > >> Hey all, >> >> The following fails for me: >> >>>>> from urllib2 import urlopen >>>>> f = >>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >> >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >> return _opener.open(url, data, timeout) >> File "/usr/lib/python2.6/urllib2.py", line 389, in open >> response = meth(req, response) >> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >> 'http', request, response, code, msg, hdrs) >> File "/usr/lib/python2.6/urllib2.py", line 427, in error >> return self._call_chain(*args) >> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >> result = func(*args) >> File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default >> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>> >> >> However, that _same_ url works perfectly fine on the >> same machine (and same network) using any of: >> * curl >> * wget >> * elinks >> * firefox >> >> Any helpful ideas ? > > The remote server doesn't like your user agent? > > It'd be easier to help if you post a working sample. That was a working sample! The "User-Agent" didn't occur to me :) Thanks - I think that might be it. Why Google would deny access to services by unknown User Agents is beyond me - especially since in most cases User Agents strings are not strict. cheers James From philip at semanchuk.com Sun Jan 11 22:25:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 11 Jan 2009 22:25:38 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Jan 11, 2009, at 10:05 PM, James Mills wrote: > On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk > wrote: >> >> On Jan 11, 2009, at 8:59 PM, James Mills wrote: >> >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>>> ") >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >>> return _opener.open(url, data, timeout) >>> File "/usr/lib/python2.6/urllib2.py", line 389, in open >>> response = meth(req, response) >>> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >>> 'http', request, response, code, msg, hdrs) >>> File "/usr/lib/python2.6/urllib2.py", line 427, in error >>> return self._call_chain(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >>> result = func(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 510, in >>> http_error_default >>> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >>> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>>> >>> >>> However, that _same_ url works perfectly fine on the >>> same machine (and same network) using any of: >>> * curl >>> * wget >>> * elinks >>> * firefox >>> >>> Any helpful ideas ? >> >> The remote server doesn't like your user agent? >> >> It'd be easier to help if you post a working sample. > > That was a working sample! Oooops, I guess it is my brain that's not working, then! Sorry about that. I tried your sample and got the 403. This works for me: >>> import urllib2 >>> user_agent="Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101" >>> url="http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml " >>> req = urllib2.Request(url, None, { 'User-Agent' : user_agent}) >>> f = urllib2.urlopen(req) >>> s=f.read() >>> f.close() >>> print s Chromium-Announce Google Group http://groups.google.com/group/chromium-announce This list is intended for important product announcements that affect the majority of etc. > Why Google would deny access to services by > unknown User Agents is beyond me - especially > since in most cases User Agents strings are not > strict. Some sites ban UAs that look like bots. I know there's a Java-based bot with a distinct UA that was really badly-behaved when visiting my server. Ignored robots.txt, fetched pages as quickly as it could etc. That was worthy of banning. FWIW, when I try the code above with a UA of "funny fish" it still works OK, so it looks like the groups.google.com server has it out for UAs with Python in them, not just unknown ones. I'm sure that if you changed wget's UA string to something Pythonic it would start to fail too. Cheers Philip From aahz at pythoncraft.com Sun Jan 11 22:38:48 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Jan 2009 19:38:48 -0800 Subject: sys.stdout.write()'s bug or doc bug? References: Message-ID: In article , Qiangning Hong wrote: > >So, my question is, as sys.stdout IS a file object, why it does not >use its encoding attribute to convert the given unicode? An >implementation bug? A documenation bug? Please file a bug on bugs.python.org -- that's the only way this can be tracked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From prologic at shortcircuit.net.au Sun Jan 11 22:50:28 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 13:50:28 +1000 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, Jan 12, 2009 at 1:25 PM, Philip Semanchuk wrote: > Oooops, I guess it is my brain that's not working, then! Sorry about that. Nps. > I tried your sample and got the 403. This works for me: (...) > Some sites ban UAs that look like bots. I know there's a Java-based bot with > a distinct UA that was really badly-behaved when visiting my server. Ignored > robots.txt, fetched pages as quickly as it could etc. That was worthy of > banning. FWIW, when I try the code above with a UA of "funny fish" it still > works OK, so it looks like the groups.google.com server has it out for UAs > with Python in them, not just unknown ones. > > I'm sure that if you changed wget's UA string to something Pythonic it would > start to fail too. My problem that I'm solving and my use-case is a tool to periodically check configured RSS feeds for updates. I was going to use urllib2 to get the data and pass this off to feedparser.parse(...) Because of the UA problem though (which can be overcome) - I decided to try a different approach and use feedparse entirely (which uses urllib internally). Problem is, feedparser doesn't store the http's response content anywhere - only the parsed results - *sigh*. My solution now is to parse and store the data I required in a simple object and pickle this to a set of cached files and compare this against hashed versions of the content. cheers James From gagsl-py2 at yahoo.com.ar Sun Jan 11 23:24:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 12 Jan 2009 02:24:03 -0200 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron escribi?: > I googled a bit, and found http://bugs.python.org/issue1355023. > It seems that this patch implemented fuller seek() for GzipFile around > November 2006 (including whence==2). > Do I misunderstand and this patch was not actually implemented, namely, > is seek(-n,2) not implemented in Python 2.5.2 ? > > The source of gzip.py on my system seems to suggest that negative seeks > are supported: The source comments are misleading: "negative seeks" means seeking backwards (towards the beginning of the file), not offset<0. The second argument to seek (whence) was added in 2.6, and only accepts 0 or 1; whence==2 isn't supported. -- Gabriel Genellina From kiliansto at gmail.com Sun Jan 11 23:26:57 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 20:26:57 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> Message-ID: > > > Thanks. That makes sense. It helps a lot. Although, you spelled color > > wrong :P. > > At this time of day you are likely to find yourself communicating with > Australians. Get used to it :-) > > Cheers, > John I was kidding. IMO, we Americans should spell color like everyone else. Heck, use the metric system too while we are at it. From prologic at shortcircuit.net.au Sun Jan 11 23:34:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 14:34:02 +1000 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> Message-ID: On Mon, Jan 12, 2009 at 2:26 PM, killsto wrote: > I was kidding. IMO, we Americans should spell color like everyone > else. Heck, use the metric system too while we are at it. Yes well why don't you start up a rally and convince your brand new shiny government to catch up with the rest of the world! :) cheers James From sjmachin at lexicon.net Mon Jan 12 01:32:07 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 22:32:07 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: On Jan 12, 12:23?pm, Carl Banks wrote: > On Jan 9, 6:11?pm, John Machin wrote: > > > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > > Aivar Annamaa wrote: > > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > > >> automatically fix. Changing print to print() on the other hand is > > > > > >> easily fixed by 2to3. > > > > > > >> Cheers, > > > > > >> Chris > > > > > > > I see. > > > > > > So i gotta keep my own discipline with print() then :) > > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > > it as Python 3.x code. > > > > > > regards > > > > > ?Steve > > > > > And mind you, if you follow that route, you are programming in a > > > > mightily crippled language. > > > > How do you figure? > > > > I expect that it'd be a PITA in some cases to use the transitional > > > dialect (like getting all your Us in place), but that doesn't mean the > > > language is crippled. > > > What is this "transitional dialect"? What does "getting all your Us in > > place" mean? > > Transitional dialect is the subset of Python 2.6 that can be > translated to Python3 with 2to3 tool. I'd never seen it called "transitional dialect" before. > ?Getting all your Us in place > refers to prepending a u to strings to make them unicode objects, > which is something 2to3 users are highly advised to do to keep hassles > to a minimum. ?(Getting Bs in place would be a good idea too.) Ummm ... I'm not understanding something. 2to3 changes u"foo" to "foo", doesn't it? What's the point of going through the code and changing all non-binary "foo" to u"foo" only so that 2to3 can rip the u off again? What hassles? Who's doing the highly-advising where and with what supporting argument? "Getting Bs into place" is necessary eventually. Whether it is worthwhile trying to find these in advance, or waiting for them to be picked up at testing time is a bit of a toss-up. Let's look at this hypothetical but fairly realistic piece of 2.x code: OLE2_SIGNATURE = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE This is already syntactically valid 3.x code, and won't be changed by 2to3, but it won't work in 3.x because b"x" != "x" for all x. In this case, the cause of test failures should be readily apparent; in other cases the unexpected exception or test failure may happen at some distance. The 3.x version needs to have the effect of: OLE2_SIGNATURE = b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE So in my regional variation of the transitional dialect, this becomes: from timemachine import * OLE2_SIGNATURE = BYTES_LITERAL("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE # NOTE: don't change "rb" ... and timemachine.py contains (amongst other things): import sys python_version = sys.version_info[:2] # e.g. version 2.4 -> (2, 4) if python_version >= (3, 0): BYTES_LITERAL = lambda x: x.encode('latin1') else: BYTES_LITERAL = lambda x: x It is probably worthwhile taking an up-front inventory of all file open () calls and [c]StringIO.StringIO() calls -- is the file being used as a text file or a binary file? If a text file, check that any default encoding is appropriate. If a binary file, ensure there's a "b" in the mode (real file) or you supply (in 3.X) an io.BytesIO() instance, not an io.StringIO() instance. > > > Steve & Cliff are talking about the rather small subset of Python that > > is not only valid syntax in both 2.x and 3.x but also has the same > > meaning in 2.x and 3.x. > > That would be a crippled language, yes. ?But I do not believe that's > what Steve and Cliff are referring to. ?Steve wrote of "running your > code through 2to3", and that was what Cliff followed up to, so I > believe they are both referring to writing valid code in 2.6 which is > able to be translated through 2to3, and then generating 3.0 code using > 2to3. ?That is not a crippled language at all, just a PITA sometimes. Uh huh; I assumed that "crippled" was being applied to the worse of the two options :-) Cheers, John From arkanes at gmail.com Mon Jan 12 01:38:20 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 00:38:20 -0600 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: <4866bea60901112238v249d6a6ajc660baca01c7607@mail.gmail.com> On Sun, Jan 11, 2009 at 9:05 PM, James Mills wrote: > On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk wrote: >> >> On Jan 11, 2009, at 8:59 PM, James Mills wrote: >> >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >>> return _opener.open(url, data, timeout) >>> File "/usr/lib/python2.6/urllib2.py", line 389, in open >>> response = meth(req, response) >>> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >>> 'http', request, response, code, msg, hdrs) >>> File "/usr/lib/python2.6/urllib2.py", line 427, in error >>> return self._call_chain(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >>> result = func(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default >>> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >>> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>>> >>> >>> However, that _same_ url works perfectly fine on the >>> same machine (and same network) using any of: >>> * curl >>> * wget >>> * elinks >>> * firefox >>> >>> Any helpful ideas ? >> >> The remote server doesn't like your user agent? >> >> It'd be easier to help if you post a working sample. > > That was a working sample! The "User-Agent" didn't > occur to me :) Thanks - I think that might be it. > > Why Google would deny access to services by > unknown User Agents is beyond me - especially > since in most cases User Agents strings are not > strict. If you look at the actual response text and not just the error code, you will get a clear explanation of why you were forbidden. From sjmachin at lexicon.net Mon Jan 12 01:45:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 22:45:55 -0800 (PST) Subject: ActiveState Python Together with "Regular" Python) ((DLE) References: Message-ID: On Jan 12, 2:00?pm, "W. eWatson" wrote: > I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to > try windowpy from ActiveState. Is having both of these installed going to > cause me trouble? What is "windowpy from ActiveState"? If you mean you wanted to try the PythonWin IDE instead of IDLE, all you needed to do was go to http://sourceforge.net/projects/pywin32/ hit the big download button and make sure you get the 2.5 version (it's the default atm) and install it. From nytrokiss at gmail.com Mon Jan 12 02:34:57 2009 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 12 Jan 2009 09:34:57 +0200 Subject: template inheritance In-Reply-To: <6sv1lsF8arprU1@mid.uni-berlin.de> References: <6sv1lsF8arprU1@mid.uni-berlin.de> Message-ID: <8a6b8e350901112334l5ee8c215n6af1a1920aaaa55a@mail.gmail.com> Not always sometimes you want to show some template code (You have a blog about web dev) and sometimes you want to nest some code. On Sun, Jan 11, 2009 at 10:04 PM, Diez B. Roggisch wrote: > Alex K schrieb: > >> While building a website using template inheritance one usually does >> the following: >> >> fetch from database >> fetch from some more data from database >> ... << more required computations >> then at the end render the template with the fetched data >> >> Without template inheritance one usually does the following: >> >> fetch from database >> render this part of the site with this fetched data >> fetch some more data from the database >> render this other part of the site with the fetched data >> ... >> etc >> >> The first approach is much more elegant and leads to easier to >> maintain code. However the user will have to wait till the end of the >> fetching (long computations) before any rendering can take place. In >> the second approach however the site loads as we are fetching the data >> which is more convenient to the user. >> >> Am I correct to assume this? Is there a way to get the best of both >> worlds? Thank you. >> > > I don't think that the question of inheritance or not is really relevant > here. > > It's a matter of how the templating system is written - does it collect all > the data beforehand, or not, is it potentially using e.g. generators and so > forth. > > And of course how the programmer uses the templating system. does he fetch > all the data beforehand, or does he use lazy generation approachs - again, > e.g. generators, or callbacks. > > Besides, *usually* the 20-39Kb of a website itself aren't the problem I'd > say - loading referenced resources is much more of an issue. > > And AFAIK the render-mode matters, too. If the site is XHTML-compliant, the > browser can start the rendering once the HTML is complete - otherwise, it > might wait until the referenced resources are all loaded to calculate the > layout. > > Diez > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Zhangfang.hit at gmail.com Mon Jan 12 02:46:10 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Sun, 11 Jan 2009 23:46:10 -0800 (PST) Subject: hlep: a text search and rename question Message-ID: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> matter description: when a use an tools to do the ape to flac convert, i can use the cue file attached with ape, but the problem is the converted flac file don't name by the title in the cue file but like Track_1.flac, Track_2.flac ... , so i want to write a script to do this work, system is xp sp2, the python is 2.44, i have a plone site in this computer, that is why i want to use python to do this work. so simplify and example CDImage.cue, Track_1.flac, Track_2.flac, Track_3.flac, Track_4.flac all above files in the same folder. the cue file is just a text file like bellow: PERFORMER "Dido" TITLE "Life For Rent" FILE "Dido - Life for Rent.ape" WAVE TRACK 01 AUDIO TITLE "White Flag" PERFORMER "Dido" INDEX 01 00:00:00 TRACK 02 AUDIO TITLE "Stoned" PERFORMER "Dido" INDEX 00 04:00:03 INDEX 01 04:01:45 TRACK 03 AUDIO TITLE "Life For Rent" PERFORMER "Dido" INDEX 00 09:56:47 INDEX 01 09:56:53 TRACK 04 AUDIO TITLE "Mary's In India" PERFORMER "Dido" INDEX 01 13:37:57 the things i want to do 1. search the current folder cue file (only one cue file) contents. find the TITLE "White Flag" and get the White Flag and maybe we can save it to a var. 2. then rename the Track_1.flac to the White Flag.flac 3. search the next title TITLE "Stoned" and save ti to var. 4. then rename the Track_2.flac to the Stoned.flac. 5. do the same things to the end title. someone can give some outline, or code is more wonderful. thanks in advance. From steve at holdenweb.com Mon Jan 12 03:05:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:05:48 -0500 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 9, 6:11 pm, John Machin wrote: >> On Jan 10, 6:58 am, Carl Banks wrote: [...] >> Steve & Cliff are talking about the rather small subset of Python that >> is not only valid syntax in both 2.x and 3.x but also has the same >> meaning in 2.x and 3.x. > > That would be a crippled language, yes. But I do not believe that's > what Steve and Cliff are referring to. Steve wrote of "running your > code through 2to3", and that was what Cliff followed up to, so I > believe they are both referring to writing valid code in 2.6 which is > able to be translated through 2to3, and then generating 3.0 code using > 2to3. That is not a crippled language at all, just a PITA sometimes. > Correct. The recommended way of maintaining a dual-version code base is to paraphrase your 2.6 code in such a way that the 2to3 converter will produce correct 3.0 code that required no further attention. If you don't do this you are making a rod for your own back. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 03:09:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:09:41 -0500 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: Gabriel Genellina wrote: > En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron > escribi?: > >> I googled a bit, and found http://bugs.python.org/issue1355023. >> It seems that this patch implemented fuller seek() for GzipFile around >> November 2006 (including whence==2). >> Do I misunderstand and this patch was not actually implemented, >> namely, is seek(-n,2) not implemented in Python 2.5.2 ? >> >> The source of gzip.py on my system seems to suggest that negative >> seeks are supported: > > The source comments are misleading: "negative seeks" means seeking > backwards (towards the beginning of the file), not offset<0. > The second argument to seek (whence) was added in 2.6, and only accepts 0 > or 1; whence==2 isn't supported. > Specifically in the case of a zip file that means the whole entry would need to be expanded to allow such a seek to take place from the end of the file; hence there are good pragmatic reasons for the restriction. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 03:24:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:24:41 -0500 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: James Mills wrote: > On Mon, Jan 12, 2009 at 9:49 AM, killsto wrote: >> Thanks. That makes sense. It helps a lot. Although, you spelled color >> wrong :P. > > color > colour > > They are both correct depending on what > country you come from :) > They are also both incorrect, depending which country you come from :P regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Mon Jan 12 03:29:17 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 00:29:17 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> On Jan 12, 12:32?am, John Machin wrote: > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > > > Aivar Annamaa wrote: > > > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > > > >> automatically fix. Changing print to print() on the other hand is > > > > > > >> easily fixed by 2to3. > > > > > > > >> Cheers, > > > > > > >> Chris > > > > > > > > I see. > > > > > > > So i gotta keep my own discipline with print() then :) > > > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > > > it as Python 3.x code. > > > > > > > regards > > > > > > ?Steve > > > > > > And mind you, if you follow that route, you are programming in a > > > > > mightily crippled language. > > > > > How do you figure? > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > language is crippled. > > > > What is this "transitional dialect"? What does "getting all your Us in > > > place" mean? > > > Transitional dialect is the subset of Python 2.6 that can be > > translated to Python3 with 2to3 tool. > > I'd never seen it called "transitional dialect" before. I had hoped the context would make it clear what I was talking about. > > ?Getting all your Us in place > > refers to prepending a u to strings to make them unicode objects, > > which is something 2to3 users are highly advised to do to keep hassles > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > "foo", doesn't it? What's the point of going through the code and > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > u off again? It does a bit more than that. > What hassles? Who's doing the highly-advising where and > with what supporting argument? You add the u so the the constant will be the same data type in 2.6 as it becomes in 3.0 after applying 2to3. str and unicode objects aren't always with smooth with each other, and you have a much better chance of getting the same behavior in 2.6 and 3.0 if you use an actual unicode string in both. A example of this, though not with string constants, was posted here recently. Someone found that urllib.open() returns a bytes object in Python 3.0, which messed him up since in 2.x he was running regexp searches on the output. If he had been taking care to use only unicode objects in 2.x (in this case, by explicitly decoding the output) then it wouldn't have been an issue. > "Getting Bs into place" is necessary eventually. Whether it is > worthwhile trying to find these in advance, or waiting for them to be > picked up at testing time is a bit of a toss-up. > > Let's look at this hypothetical but fairly realistic piece of 2.x > code: > OLE2_SIGNATURE = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > > This is already syntactically valid 3.x code, and won't be changed by > 2to3, but it won't work in 3.x because b"x" != "x" for all x. In this > case, the cause of test failures should be readily apparent; in other > cases the unexpected exception or test failure may happen at some > distance. > > The 3.x version needs to have the effect of: > OLE2_SIGNATURE = b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > > So in my regional variation of the transitional dialect, this becomes: > from timemachine import * > OLE2_SIGNATURE = BYTES_LITERAL("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > # NOTE: don't change "rb" > ... > and timemachine.py contains (amongst other things): > import sys > python_version = sys.version_info[:2] # e.g. version 2.4 -> (2, 4) > if python_version >= (3, 0): > ? ? BYTES_LITERAL = lambda x: x.encode('latin1') > else: > ? ? BYTES_LITERAL = lambda x: x > > It is probably worthwhile taking an up-front inventory of all file open > () calls and [c]StringIO.StringIO() calls -- is the file being used as > a text file or a binary file? > If a text file, check that any default encoding is appropriate. > If a binary file, ensure there's a "b" in the mode (real file) or you > supply (in 3.X) an io.BytesIO() instance, not an io.StringIO() > instance. Right. "Taking care of the Us" refered specifically to the act of prepending Us to string constants, but figuratively it means making explicit your intentions with all string data. 2to3 can only do so much; it can't always guess whether your string usage is supposed to be character or binary. It's definitely going to be the hardest part of the transition since it's the most drastic change. Carl Banks From gandalf at shopzeus.com Mon Jan 12 03:51:55 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 09:51:55 +0100 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: <49674C57.3040908@shopzeus.com> References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> Message-ID: <496B04AB.9010409@shopzeus.com> Laszlo Nagy wrote: > Meanwhile I'm trying to turn off threads in that program one by one. I > just got this new type of error: > > Fatal Python error: PyThreadState_Delete: invalid tstate After some days, there are now answers to my question. I guess this is because nobody knows the answer. I think I need to consider this a bug in Python. Where can I post a bug report? Laszlo From notvalid2 at sbcglobal.net Mon Jan 12 05:16:16 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 12 Jan 2009 02:16:16 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: References: Message-ID: John Machin wrote: > On Jan 12, 2:00 pm, "W. eWatson" wrote: >> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to >> try windowpy from ActiveState. Is having both of these installed going to >> cause me trouble? > > What is "windowpy from ActiveState"? If you mean you wanted to try the > PythonWin IDE instead of IDLE, all you needed to do was go to > http://sourceforge.net/projects/pywin32/ hit the big download button > and make sure you get the 2.5 version (it's the default atm) and > install it. > Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. Is it possible to just disable the vanilla (IDLE) version? I may want to switch between the two. Most users of the program I'm about to modify use the vanilla version. At some point, I may want to go back to it to verify that in their world all is OK. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From michele.simionato at gmail.com Mon Jan 12 05:38:12 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 12 Jan 2009 02:38:12 -0800 (PST) Subject: debugging ignored exceptions at cleanup Message-ID: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> In some conditions (typically with threads, __del__ methods, etc) the cleanup mechanism of Python gets in trouble and some exceptions are not raised but just printed on stderr. I have an application using Paste and when I run the tests I get some annoying ignored exceptions during cleanup. Running the code with the -v option I get things like that: # cleanup[2] sqlalchemy.util # cleanup[2] sqlalchemy.sql.expression # cleanup[2] symbol # cleanup[2] urllib2 # cleanup[2] sqlalchemy.orm.query # cleanup[2] smweb.config # cleanup[2] formencode # cleanup[2] smweb.config.environment Exception exceptions.TypeError: "'NoneType' object is not callable" in at 0x26861b8> ignored Exception exceptions.TypeError: "'NoneType' object is not callable" in at 0x2598578> ignored # cleanup[2] dbhash # cleanup[2] xmlrpclib # cleanup[2] mako.pygen # cleanup[2] time # cleanup[2] paste.util.import_string # cleanup sys # cleanup __builtin__ # cleanup ints: 5096 unfreed ints in 145 out of 171 blocks # cleanup floats: 43 unfreed floats in 3 out of 4 blocks As you see, the exceptions happen during the cleanup of smweb.config.environment, which the part of code I wrote, but which has no obvious problems and imports *lots* of other stuff. Is there some way to hook in the cleanup mechanism, start a pdb and see really what is happening? I tried to trace the execution flow with the trace module but without success. There is so much code there that I am unable to track down the source of the problem. I suspect there is some __del__ method somewhere that tries to call a function which has been set to None by the cleanup mechanism, possibly from another thread, but I cannot find it. How am I supposed to debug such things? From sjmachin at lexicon.net Mon Jan 12 05:49:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 02:49:48 -0800 (PST) Subject: ActiveState Python Together with "Regular" Python) ((DLE) References: Message-ID: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> On Jan 12, 9:16?pm, "W. eWatson" wrote: > John Machin wrote: > > On Jan 12, 2:00 pm, "W. eWatson" wrote: > >> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to > >> try windowpy from ActiveState. Is having both of these installed going to > >> cause me trouble? > > > What is "windowpy from ActiveState"? If you mean you wanted to try the > > PythonWin IDE instead of IDLE, all you needed to do was go to > >http://sourceforge.net/projects/pywin32/hit the big download button > > and make sure you get the 2.5 version (it's the default atm) and > > install it. > > Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. > > Is it possible to just disable the vanilla (IDLE) version? I may want to > switch between the two. Most users of the program I'm about to modify use > the vanilla version. At some point, I may want to go back to it to verify > that in their world all is OK. I'll try again. All you need is (a) the official distribution of Python 2.5 for Windows from http://www.python.org (b) the pywin32 package from the URL I gave you. Install both. Click on Start / All Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ or your users can use IDLE or PythonWin, only one copy of Python, no conflicts. Why do you think you need to "disable" IDLE? Just don't use it. From jstroud at mbi.ucla.edu Mon Jan 12 06:13:25 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:13:25 -0800 Subject: hlep: a text search and rename question In-Reply-To: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> Message-ID: sensen wrote: > matter description: > > when a use an tools to do the ape to flac convert, i can use the cue > file attached with ape, but the problem is the converted flac file > don't name by the title in the cue file but like Track_1.flac, > Track_2.flac ... , so i want to write a script to do this work, system > is xp sp2, the python is 2.44, i have a plone site in this computer, > that is why i want to use python to do this work. > > so simplify and example > > CDImage.cue, Track_1.flac, Track_2.flac, Track_3.flac, Track_4.flac > all above files in the same folder. > > the cue file is just a text file like bellow: > > > PERFORMER "Dido" > TITLE "Life For Rent" > FILE "Dido - Life for Rent.ape" WAVE > TRACK 01 AUDIO > TITLE "White Flag" > PERFORMER "Dido" > INDEX 01 00:00:00 > TRACK 02 AUDIO > TITLE "Stoned" > PERFORMER "Dido" > INDEX 00 04:00:03 > INDEX 01 04:01:45 > TRACK 03 AUDIO > TITLE "Life For Rent" > PERFORMER "Dido" > INDEX 00 09:56:47 > INDEX 01 09:56:53 > TRACK 04 AUDIO > TITLE "Mary's In India" > PERFORMER "Dido" > INDEX 01 13:37:57 > > the things i want to do > > 1. search the current folder cue file (only one cue file) contents. > find the TITLE "White Flag" and get the White Flag and maybe we > can save it to a var. > 2. then rename the Track_1.flac to the White Flag.flac > 3. search the next title TITLE "Stoned" and save ti to var. > 4. then rename the Track_2.flac to the Stoned.flac. > 5. do the same things to the end title. > > someone can give some outline, or code is more wonderful. thanks in > advance. This isn't much work in python: import os, glob, re cue = iter(open('CDImage.cue').readlines()) titles = [] for line in cue: if line.strip().startswith('FILE'): break for line in cue: if line.strip().startswith('TITLE'): titles.append(line.split('"')[-2]) flacs = glob.glob('*.flac') flacs.sort(key=lambda f: int(re.search(r'\d+', f).group(0))) for old, new in zip(flacs, titles): os.rename(old, new) There is no error checking for properly formatted cue file, etc. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From jstroud at mbi.ucla.edu Mon Jan 12 06:17:14 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:17:14 -0800 Subject: hlep: a text search and rename question In-Reply-To: References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> Message-ID: <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> James Stroud wrote: > cue = iter(open('CDImage.cue').readlines()) It just occurred to me that this could simply be: cue = open('CDImage.cue') James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From apardon at forel.vub.ac.be Mon Jan 12 06:18:53 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Jan 2009 11:18:53 GMT Subject: change only the nth occurrence of a pattern in a string References: <0scs26-7a5.ln1@rama.fbx.proxad.net> Message-ID: On 2008-12-31, TP wrote: > Hi everybody, > > I would like to change only the nth occurence of a pattern in a string. The > problem with "replace" method of strings, and "re.sub" is that we can only > define the number of occurrences to change from the first one. > >>>> v="coucou" >>>> v.replace("o","i",2) > 'ciuciu' >>>> import re >>>> re.sub( "o", "i", v,2) > 'ciuciu' >>>> re.sub( "o", "i", v,1) > 'ciucou' > > What is the best way to change only the nth occurence (occurrence number n)? > > Why this default behavior? For the user, it would be easier to put re.sub or > replace in a loop to change the first n occurences. I would do it as follows: 1) Change the pattern n times to somethings that doesn't occur in your string 2) Change it back n-1 times 3) Change the remaining one to what you want. >>> v="coucou" >>> v.replace('o', 'O', 2).replace('O', 'o', 1).replace('O', 'i') 'couciu' -- Antoon Pardon From sjmachin at lexicon.net Mon Jan 12 06:26:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 03:26:58 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> Message-ID: <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> On Jan 12, 7:29?pm, Carl Banks wrote: > On Jan 12, 12:32?am, John Machin wrote: > > > > > > > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > > language is crippled. > > > > > What is this "transitional dialect"? What does "getting all your Us in > > > > place" mean? > > > > Transitional dialect is the subset of Python 2.6 that can be > > > translated to Python3 with 2to3 tool. > > > I'd never seen it called "transitional dialect" before. > > I had hoped the context would make it clear what I was talking about. In vain. > > > > ?Getting all your Us in place > > > refers to prepending a u to strings to make them unicode objects, > > > which is something 2to3 users are highly advised to do to keep hassles > > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > > "foo", doesn't it? What's the point of going through the code and > > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > > u off again? > > It does a bit more than that. Like what? > > > What hassles? Who's doing the highly-advising where and > > with what supporting argument? > > You add the u so the the constant will be the same data type in 2.6 as > it becomes in 3.0 after applying 2to3. ?str and unicode objects aren't > always with smooth with each other, and you have a much better chance > of getting the same behavior in 2.6 and 3.0 if you use an actual > unicode string in both. (1) Why specifically 2.6? Do you mean 2.X, or is this related to the "port to 2.6 first" theory? (2) We do assume we are starting off with working 2.X code, don't we? If we change "foo" to u"foo" and get a different answer from the 2.X code, is that still "working"? > > A example of this, though not with string constants, And therefore irrelevant. I would like to hear from someone who has actually started with working 2.x code and changed all their text-like "foo" to u"foo" [except maybe unlikely suspects like open()'s mode arg]: * how many places where the 2.x code broke and so did the 3.x code [i.e. the problem would have been detected without prepending u] * how many places where the 2.x code broke but the 3.x code didn't [i.e. prepending u did find the problem] * whether they thought it was worth the effort In the meantime I would be interested to hear from anybody with a made- up example of code where the problem would be detected (sooner | better | only) by prepending u to text-like string constants. > 2to3 can only do so > much; it can't always guess whether your string usage is supposed to > be character or binary. AFAICT it *always* guesses text rather than binary; do you have any examples where it guesses binary (rightly or wrongly)? From jstroud at mbi.ucla.edu Mon Jan 12 06:27:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:27:52 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> Message-ID: <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Roger wrote: > Hi Everyone, > > I have a behavior associated with a default binding with Tkinter > Listbox that I want to get rid of but I can't no matter if I return > "break" on the binding or unbind it directly. If you have a Listbox > where the bounding box is not completely revealed in the window that > holds it and you use the mouse to drag the list box, the contents of > the listbox will move in the X direction to reveal the area that's > hidden. After searching the internet for hours I found the behavior I > want to remove is a default binding as described here: > > http://tcltk.free.fr/man/TkCmd/listbox.php3 > > "[3] If the mouse leaves the listbox window with button 1 down, the > window scrolls away from the mouse, making information visible that > used to be off-screen on the side of the mouse. The scrolling > continues until the mouse re-enters the window, the button is > released, or the end of the listbox is reached. " > > After further searching I found that the code for this in tcl is > described here: > > http://www.openmash.org/lxr/source/library/listbox.tcl?c=tk8.3 > > 50 bind Listbox { > 51 set tkPriv(x) %x > 52 set tkPriv(y) %y > 53 tkListboxMotion %W [%W index @%x,%y] > 54 } > > Now I've found no way to successfully unbind B1-Motion from the > listbox, as I said above. Nor return "break" on receiving the event. > I do want to eventually have my own B1-Motion binding applied to the > listbox for a different reason (with add='+' if necessary). My next > step was to see if I could just unbind B1-Motion then programmatically > delete tkListboxMotion in my code but tkListboxMotion is not available > in the Tkinter source (it's part of a compiled binary I can't reach?). > > Any help would be greatly appreciated. Thanks! > Roger. You can directly send commands to the Tcl interpreter via the call method of the tk attribute of any Tkinter widget. For example: py> from Tkinter import * py> tk = Tk() py> b = Button(tk) py> b.pack() py> b.tk py> b.tk.call('bind', 'Listbox', '') '\n set tk::Priv(x) %x\n set tk::Priv(y) %y\n tk::ListboxMotion %W [%W index @%x,%y]\n' py> b.tk.call('bind', 'Listbox', '', _) '' James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From jstroud at mbi.ucla.edu Mon Jan 12 06:31:54 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:31:54 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: James Stroud wrote: > py> b.tk.call('bind', 'Listbox', '', _) You want b.tk.call('bind', 'Listbox', '', "") of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From n.kottiyath at gmail.com Mon Jan 12 06:52:46 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Mon, 12 Jan 2009 03:52:46 -0800 (PST) Subject: Python logging rollover Message-ID: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> Hi, I want to do a log rollover - preferably based on day; size is also Ok. I checked logging.TimedRotatingFileHandler, but I am not sure whether it will suit my purpose. Mine is a desktop application. So, everytime the machine starts, the whole logging system is reinitialized. So, in such a case, can I use TimedRotatingFileHandler? I tested it with 'midnight' option, but it did not work as I expected. Regards K From siona at chiark.greenend.org.uk Mon Jan 12 06:58:12 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Jan 2009 11:58:12 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <0kt*vWSws@news.chiark.greenend.org.uk> Grant Edwards wrote: >On 2009-01-09, Sion Arrowsmith wrote: >> Grant Edwards wrote: >>>If I were you, I'd try mmap()ing the file instead of reading it >>>into string objects one chunk at a time. >> You've snipped the bit further on in that sentence where the >> OP says that the file of interest is 2GB. Do you still want to >> try mmap'ing it? >Sure. The larger the file, the more you gain from mmap'ing it. >2GB should easily fit within the process's virtual memory >space. Assuming you're in a 64bit world. Me, I've only got 2GB of address space available to play in -- mmap'ing all of it out of the question. But I supposed that mmap'ing it chunk at a time instead of reading chunk at a time might be worth considering. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From Zhangfang.hit at gmail.com Mon Jan 12 07:03:43 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 04:03:43 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> Message-ID: <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> On Jan 12, 8:17?pm, James Stroud wrote: > James Stroud wrote: > > cue = iter(open('CDImage.cue').readlines()) > > It just occurred to me that this could simply be: > > cue = open('CDImage.cue') > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com Thanks you James, i will check it now. thanks again for your kindness help. From lists at cheimes.de Mon Jan 12 07:05:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 13:05:03 +0100 Subject: Problem with -3 switch In-Reply-To: <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: John Machin schrieb: > And therefore irrelevant. No, Carl is talking about the very same issue. > I would like to hear from someone who has actually started with > working 2.x code and changed all their text-like "foo" to > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > * how many places where the 2.x code broke and so did the 3.x code > [i.e. the problem would have been detected without prepending u] > * how many places where the 2.x code broke but the 3.x code didn't > [i.e. prepending u did find the problem] > * whether they thought it was worth the effort Perhaps you also like to hear from a developer who has worked on Python 3.0 itself and who has done lots of work with internationalized applications. If you want to get it right you must * decode incoming text data to unicode as early as possible * use unicode for all internal text data * encode outgoing unicode as late as possible. where incoming data is read from the file system, database, network etc. This rule applies not only to Python 3.0 but to *any* application written in *any* languate. The urlopen example is a very good example for the issue. The author didn't think of decoding the incoming bytes to unicode. In Python 2.x it works fine as long as the site contains ASCII only. In Python 3.0 however an error is raised because binary data is no longer implicitly converted to unicode. Christian From sjmachin at lexicon.net Mon Jan 12 07:20:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 04:20:12 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> On Jan 12, 11:05?pm, Christian Heimes wrote: > John Machin schrieb: > > > And therefore irrelevant. > > No, Carl is talking about the very same issue. > > > I would like to hear from someone who has actually started with > > working 2.x code and changed all their text-like "foo" to > > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > > * how many places where the 2.x code broke and so did the 3.x code > > [i.e. the problem would have been detected without prepending u] > > * how many places where the 2.x code broke but the 3.x code didn't > > [i.e. prepending u did find the problem] > > * whether they thought it was worth the effort > > Perhaps you also like to hear from a developer who has worked on Python > 3.0 itself and who has done lots of work with internationalized > applications. If you want to get it right you must > > * decode incoming text data to unicode as early as possible > * use unicode for all internal text data > * encode outgoing unicode as late as possible. > > where incoming data is read from the file system, database, network etc. > > This rule applies not only to Python 3.0 but to *any* application > written in *any* languate. The above is a story with which I'm quite familiar. However it is *not* the issue!! The issue is why would anyone propose changing a string constant "foo" in working 2.x code to u"foo"? > The urlopen example is a very good example > for the issue. The author didn't think of decoding the incoming bytes to > unicode. In Python 2.x it works fine as long as the site contains ASCII > only. In Python 3.0 however an error is raised because binary data is no > longer implicitly converted to unicode. All very true but nothing to do with the "foo" -> u"foo" issue. Somebody please come up with an example of how changing "foo" to u"foo" could help a port from 2.x working code to a single codebase that supports 2.x and 2to3ed 3.x. From googler.1.webmaster at spamgourmet.com Mon Jan 12 07:22:07 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 12 Jan 2009 04:22:07 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> Message-ID: Hi! Woow, thanks. The unix command install_name_tool solved my problem. Thanks a lot. From heston.james at coldbeans.co.uk Mon Jan 12 07:24:23 2009 From: heston.james at coldbeans.co.uk (Heston James - Cold Beans) Date: Mon, 12 Jan 2009 12:24:23 -0000 Subject: strange dict issue Message-ID: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> Ok, this feels like a horribly noobish question to ask guys but I can't figure this one out. I have code which looks like this: print this_config[1] this_adapter_config["name"] = this_config[1]["NAME"] Now, the print statement gives me the following: {'value': 'Route66', 'key': 'NAME'} Yet when the second line of my code throws an error saying the key 'NAME' doesn't exist. Any ideas on what's going on, seems quite senseless to me!? Thanks, Heston -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.reginato at gmail.com Mon Jan 12 07:32:35 2009 From: andrea.reginato at gmail.com (Andrea Reginato) Date: Mon, 12 Jan 2009 04:32:35 -0800 (PST) Subject: Encoding Title mail Message-ID: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some mails from a google account and save the attached files. All works fine, but when a tile has some letters with accents (like ?????) I read a string like this. =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? _=E9*=A7=B0=E7;:=5F_test_chars?= I tried to use the string.decode(ISO-8859-1) function, but nothing change. I'm newbie into python, so I wanted to ask if you know how I could solve this problem, as with a google search i didn't find the solution. Thanks a lot. From sturlamolden at yahoo.no Mon Jan 12 07:50:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jan 2009 04:50:49 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <7c6d30a3-36fb-4a0c-934e-3f08b09a3159@s1g2000prg.googlegroups.com> On Jan 9, 6:41 pm, Sion Arrowsmith wrote: > You've snipped the bit further on in that sentence where the OP > says that the file of interest is 2GB. Do you still want to try > mmap'ing it? Python's mmap object does not take an offset parameter. If it did, one could mmap smaller portions of the file. From siona at chiark.greenend.org.uk Mon Jan 12 07:52:32 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Jan 2009 12:52:32 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> Message-ID: <8Fl*e9Sws@news.chiark.greenend.org.uk> In case the cancel didn't get through: Sion Arrowsmith wrote: >Grant Edwards wrote: >>2GB should easily fit within the process's virtual memory >>space. >Assuming you're in a 64bit world. Me, I've only got 2GB of address >space available to play in -- mmap'ing all of it out of the question. And today's moral is: try it before posting. Yeah, I can map a 2GB file no problem, complete with associated 2GB+ allocated VM. The addressing is clearly not working how I was expecting it too. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From benjamin.kaplan at case.edu Mon Jan 12 08:04:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 12 Jan 2009 08:04:58 -0500 Subject: strange dict issue In-Reply-To: <-4440361288562330204@unknownmsgid> References: <-4440361288562330204@unknownmsgid> Message-ID: On Mon, Jan 12, 2009 at 7:24 AM, Heston James - Cold Beans < heston.james at coldbeans.co.uk> wrote: > Ok, this feels like a horribly noobish question to ask guys but I can't > figure this one out. > > > > I have code which looks like this: > > > > print this_config[1] > > > > this_adapter_config[*"name"*] = this_config[1][*"NAME"*] > > > > Now, the print statement gives me the following: > > > > {'value': 'Route66', 'key': 'NAME'} > > > Yet when the second line of my code throws an error saying the key 'NAME' > doesn't exist. > > > > Any ideas on what's going on, seems quite senseless to me!? > > > > Thanks, > > > > Heston > A dict stores key/value pairs. When you see the print of the dict, it shows you {key1:value1, key2:value2}. So your dict has two keys ('value' and 'key') that map to two values ('Route66' and 'Name' respectively). 'Name' is a value in the dict, not a key, so you can't use that syntax to get it.. In order for this code to work, the dictionary would have to be {'NAME' : 'Route66'} or you would have to use this_config[1]['value'] > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary at byoteki.com Mon Jan 12 08:05:47 2009 From: gary at byoteki.com (Gary M. Josack) Date: Mon, 12 Jan 2009 08:05:47 -0500 Subject: strange dict issue In-Reply-To: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> References: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> Message-ID: <496B402B.6010803@byoteki.com> Heston James - Cold Beans wrote: > > Ok, this feels like a horribly noobish question to ask guys but I > can?t figure this one out. > > I have code which looks like this: > > print this_config[1] > > this_adapter_config[/"name"/] = this_config[1][/"NAME"/] > > Now, the print statement gives me the following: > > {'value': 'Route66', 'key': 'NAME'} > > Yet when the second line of my code throws an error saying the key > ?NAME? doesn?t exist. > > Any ideas on what?s going on, seems quite senseless to me!? > > Thanks, > > Heston > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > 'NAME' is the value, and 'key' is the key. Your dictionary has two keys mapped to two values: 'value' -> 'Route66' 'key' -> 'NAME' You need to lookup the values by their key. Does that make sense? Thanks, Gary M. Josack From lists at cheimes.de Mon Jan 12 08:06:29 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 14:06:29 +0100 Subject: Problem with -3 switch In-Reply-To: <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: >> Perhaps you also like to hear from a developer who has worked on Python >> 3.0 itself and who has done lots of work with internationalized >> applications. If you want to get it right you must >> >> * decode incoming text data to unicode as early as possible >> * use unicode for all internal text data >> * encode outgoing unicode as late as possible. >> >> where incoming data is read from the file system, database, network etc. >> >> This rule applies not only to Python 3.0 but to *any* application >> written in *any* languate. > > The above is a story with which I'm quite familiar. However it is > *not* the issue!! The issue is why would anyone propose changing a > string constant "foo" in working 2.x code to u"foo"? Do I really have to repeat "use unicode for all internal text data"? "foo" and u"foo" are two totally different things. The former is a byte sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just happens that "foo" and u"foo" are equal in Python 2.x because "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is unequal to "foo". Christian From bj_666 at gmx.net Mon Jan 12 08:06:56 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 12 Jan 2009 13:06:56 GMT Subject: Encoding Title mail References: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> Message-ID: <6t0tjgF8gel1U1@mid.uni-berlin.de> On Mon, 12 Jan 2009 04:32:35 -0800, Andrea Reginato wrote: > Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some > mails from a google account and save the attached files. All works fine, > but when a tile has some letters with accents (like ?????) I read a > string like this. > > =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? > _=E9*=A7=B0=E7;:=5F_test_chars?= > > I tried to use the string.decode(ISO-8859-1) function, but nothing > change. > I'm newbie into python, so I wanted to ask if you know how I could solve > this problem, as with a google search i didn't find the solution. Look into the `email` package in the standard library. Ciao, Marc 'BlackJack' Rintsch From raj.indian.08 at gmail.com Mon Jan 12 08:10:45 2009 From: raj.indian.08 at gmail.com (RajNewbie) Date: Mon, 12 Jan 2009 05:10:45 -0800 (PST) Subject: Python tricks Message-ID: Hi, My code has a lot of while loops of the following format: while True: ... if : break The danger with such a code is that it might go to an infinite loop - if the never occurs. Is there a way - a python trick - to have a check such that if the loop goes for more than x number of steps, it will cause an exception? I do understand that we can use the code like - i = 0 while True: i++ if i > 200: raise infinite_Loop_Exception ... if : break But I am not very happy with this code for 3 reasons 1. Verbosity (i=0 and i++) which doesnt add to the logic 2. The loop now has dual focus. - incrementing i, etc. 3. A person looks into the code and thinks 'i' has special significance. His/her mind will be focused on not the actual reason for the loop. The solution that I had in mind is: while True: ... if : break if inifinte_loop(): raise infiinte_loop_exception Wherein infinite_loop is a generator, which returns true if i > 200 def infinite_loop(): i = 0 while i < 200: i++ yield False yield True Could somebody let me know whether this is a good option? One of my main worries is - what will happen if I call this same procedure from another loop? Will it start again from 0 or will it again start from my previous stored i? i.e. def big_proc: while True: ... if infinite_loop: raise while True: ... if infinite_loop: raise In such a case, will we run it 200 times both the times or not? Could someone chip in with other suggestions? From heston.james at coldbeans.co.uk Mon Jan 12 08:11:47 2009 From: heston.james at coldbeans.co.uk (Heston James - Cold Beans) Date: Mon, 12 Jan 2009 13:11:47 -0000 Subject: strange dict issue In-Reply-To: <496B402B.6010803@byoteki.com> References: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> <496B402B.6010803@byoteki.com> Message-ID: <01b601c974b7$52cd6740$f86835c0$@james@coldbeans.co.uk> Gary, Ben, Thanks for your replies, that makes perfect sense. This is a dict generated by the ZSI web service library and looks different to what I expect. :-( I'll work on your suggestions, thanks again for your help. Heston From sturlamolden at yahoo.no Mon Jan 12 08:13:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jan 2009 05:13:26 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> Message-ID: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> On Jan 12, 1:52 pm, Sion Arrowsmith wrote: > And today's moral is: try it before posting. Yeah, I can map a 2GB > file no problem, complete with associated 2GB+ allocated VM. The > addressing is clearly not working how I was expecting it too. The virtual memory space of a 32 bit process is 4 GB. From bieffe62 at gmail.com Mon Jan 12 08:14:35 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 12 Jan 2009 05:14:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> Message-ID: <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> On 12 Gen, 00:02, Paul Rubin wrote: > Carl Banks writes: > > and where it was manipulated for that matter. > > > This criticism is completely unfair. ?Instance variables have to be > > manipulated somewhere, and unless your object is immutable, that is > > going to happen outside of __init__. ?That's true in Java, C++, and > > pretty much any other language. > > The criticism is very valid. ?Some languages do support immutable > variables (e.g. "final" declarations in Java, "const" in C++, or > universal immutability in pure functional languages) and they do so > precisely for the purpose of taming the chaos of uncontrolled > mutation. ?It would be great if Python also supported immutability. > > > I'm not going to argue that this doesn't hurt readability, because it > > does (though not nearly as much as you claim). ?But there are other > > considerations, and in this case the flexibility of defining > > attributes outside __init__ is worth the potential decrease in > > readability. > > There are cases where this is useful but they're not terribly common. > I think it would be an improvement if creating new object attributes > was by default not allowed outside the __init__ method. ?In the cases > where you really do want to create new attributes elsewhere, you'd > have to explicitly enable this at instance creation time, for example > by inheriting from a special superclass: > > ? ?class Foo (DynamicAttributes, object): pass > You cannot do that, but you can establish a fixed set of attributes by defining the __slot__ class variable. Ciao ----- FB From ferdinandsousa at gmail.com Mon Jan 12 08:26:40 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Mon, 12 Jan 2009 18:56:40 +0530 Subject: strange dict issue Message-ID: James First off, the computer is always right :-) > {'value': 'Route66', 'key': 'NAME'} > > > > Yet when the second line of my code throws an error saying the key 'NAME' > doesn't exist. > If you look carefully the key NAME indeed does not exist. The dictionary contains 2 key-value pairs. This should clear things out: *key * *value *'value' 'Route66' 'key' 'NAME' Get it? NAME is a value, not a key. You have used the string 'key' itself as a dictionary key. My advice would be to not use such conflicting names. Regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Mon Jan 12 08:31:26 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 12 Jan 2009 14:31:26 +0100 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <7c6d30a3-36fb-4a0c-934e-3f08b09a3159@s1g2000prg.googlegroups.com> Message-ID: <871vv87is1.fsf@mulj.homelinux.net> sturlamolden writes: > On Jan 9, 6:41 pm, Sion Arrowsmith > wrote: > >> You've snipped the bit further on in that sentence where the OP >> says that the file of interest is 2GB. Do you still want to try >> mmap'ing it? > > Python's mmap object does not take an offset parameter. If it did, one > could mmap smaller portions of the file. As of 2.6 it does, but that might not be of much use if you're using 2.5.x or earlier. If you speak Python/C and really need offset, you could backport the mmap module from 2.6 and compile it under a different name for 2.5. From bignose+hates-spam at benfinney.id.au Mon Jan 12 08:37:51 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 13 Jan 2009 00:37:51 +1100 Subject: Python tricks References: Message-ID: <87ab9wejbk.fsf@benfinney.id.au> RajNewbie writes: > Could someone chip in with other suggestions? Set up an iterable that will end under the right conditions. Then, iterate over that with ?for foo in that_iterable?. This idiom is usually far more expressive than any tricks with ?while? loops and ?break? statements. For tools to work with that can give you such an iterable without needing to make one from scratch, try the following and use the one that is most suitable to the problem at hand: * list * dict * list comprehension * generator expression * generator function * functions from the ?itertools? module -- \ ?Too many Indians spoil the golden egg.? ?Sir Joh | `\ Bjelke-Petersen | _o__) | Ben Finney From sjmachin at lexicon.net Mon Jan 12 08:38:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 05:38:51 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: On Jan 13, 12:06?am, Christian Heimes wrote: > >> Perhaps you also like to hear from a developer who has worked on Python > >> 3.0 itself and who has done lots of work with internationalized > >> applications. If you want to get it right you must > > >> * decode incoming text data to unicode as early as possible > >> * use unicode for all internal text data > >> * encode outgoing unicode as late as possible. > > >> where incoming data is read from the file system, database, network etc. > > >> This rule applies not only to Python 3.0 but to *any* application > >> written in *any* languate. > > > The above is a story with which I'm quite familiar. However it is > > *not* the issue!! The issue is why would anyone propose changing a > > string constant "foo" in working 2.x code to u"foo"? > > Do I really have to repeat "use unicode for all internal text data"? > > "foo" and u"foo" are two totally different things. The former is a byte > sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just > happens that "foo" and u"foo" are equal in Python 2.x because > "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is > unequal to "foo". > Again, all very true, but irrelevant. b"foo" is *not* involved. You're ignoring the effect of 2to3: Original 2.x code: assert "foo" == u"foo" # works output from 2to3: assert "foo" == "foo" # works Original 2.x code with u prepended: assert u"foo" == u"foo" # works output from 2to3: assert "foo" == "foo" # works I say again, show me a case of working 2.5 code where prepending u to an ASCII string constant that is intended to be used in a text context is actually worth the keystrokes. From Zhangfang.hit at gmail.com Mon Jan 12 08:41:07 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 05:41:07 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> Message-ID: both above works well, but a problem is renamed file is without filename extension. only change to the title. for example, the origin file is track_1.flac, after run the script i want it to for example, White Flag.flac, but now it change to White Flag without extension. could you do a favor to fix it. thank you. From http Mon Jan 12 08:45:13 2009 From: http (Paul Rubin) Date: 12 Jan 2009 05:45:13 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> Message-ID: <7x1vv83afq.fsf@ruckus.brouhaha.com> bieffe62 at gmail.com writes: > > ? ?class Foo (DynamicAttributes, object): pass > > > You cannot do that, but you can establish a fixed set of attributes by > defining the __slot__ class variable. That is not what __slot__ is for. From Maksim.Kasimov at gmail.com Mon Jan 12 08:45:33 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Mon, 12 Jan 2009 05:45:33 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> Message-ID: <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> On 10 ???, 23:40, John Machin wrote: > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > > Hi all! > > > I had touch with some different python behavior: I was tried to write > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > it gives expected result: > > > >>> open("test", "w").write('before\x1aafter') > > >>> open('test').read() > > > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > > > >>> open("test", "w").write('before\x1aafter') > > >>> open('test').read() > > > 'before' > > > Here I can write all symbols, but not read. > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > Why is it so and is it possible to fix it? > > You've already got two good answers, but this might add a little more > explanation: > > You will aware that in Windows Command Prompt, to exit the interactive > mode of Python (among others), you need to type Ctrl-Z ... > > | C:\junk>python > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > (Intel)] on > win32 > | Type "help", "copyright", "credits" or "license" for more > information. > | >>> problem = '\x1a' > | >>> ord(problem) > | 26 > | >>> # What is the 26th letter of the English/ASCII alphabet? > | ... > | >>> ^Z > | > | C:\junk> > > HTH, > John Hi John, I agree - those two answers are really good. Thanks to Mel and Marc. I'm sorry if my stupid question was annoyed you. -- Maksim From python.list at tim.thechases.com Mon Jan 12 08:51:17 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jan 2009 07:51:17 -0600 Subject: Python tricks In-Reply-To: References: Message-ID: <496B4AD5.2010900@tim.thechases.com> > My code has a lot of while loops of the following format: > while True: > ... > if : break > > The danger with such a code is that it might go to an infinite loop > - if the never occurs. > Is there a way - a python trick - to have a check such that if the > loop goes for more than x number of steps, it will cause an exception? > > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons > 1. Verbosity (i=0 and i++) which doesnt add to the logic > 2. The loop now has dual focus. - incrementing i, etc. > 3. A person looks into the code and thinks 'i' > has special significance. His/her mind will be focused on not the > actual reason for the loop. My first thought would be to simply not use "while True": INFINITE_LOOP_COUNT = 200 for _ in xrange(INFINITE_LOOP_COUNT): do_something() if : break else: raise InfiniteLoopException > The solution that I had in mind is: > while True: > ... > if : break > if inifinte_loop(): raise infiinte_loop_exception > > Wherein infinite_loop is a generator, which returns true if i > 200 > def infinite_loop(): > i = 0 > while i < 200: > i++ > yield False > yield True > > Could somebody let me know whether this is a good option? To do this, you'd need to do the same sort of thing as you do with your i/i++ variable: i = infinite_loop() while True: ... if : break if i.next(): raise InfiniteLoopException which doesn't gain much, and makes it a whole lot more confusing. > Could someone chip in with other suggestions? As an aside: the phrase is "chime in"[1] (to volunteer suggestions) "Chip in"[2] usually involves contributing money to a common fund ("care to chip in $10 for Sally's wedding gift from the office?" where the pool of money would then be used to buy one large/expensive gift for Sally) -tkc [1] http://www.thefreedictionary.com/chime+in [2] http://www.english-test.net/forum/ftopic1768.html From sjmachin at lexicon.net Mon Jan 12 09:00:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 06:00:16 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> Message-ID: <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> On Jan 13, 12:45?am, "sim.sim" wrote: > On 10 ???, 23:40, John Machin wrote: > > > > > > > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > Hi all! > > > > I had touch with some different python behavior: I was tried to write > > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > > it gives expected result: > > > > >>> open("test", "w").write('before\x1aafter') > > > >>> open('test').read() > > > > 'before\x1aafter' > > > > but for my WinXP box, it gives some strange: > > > > >>> open("test", "w").write('before\x1aafter') > > > >>> open('test').read() > > > > 'before' > > > > Here I can write all symbols, but not read. > > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > > Why is it so and is it possible to fix it? > > > You've already got two good answers, but this might add a little more > > explanation: > > > You will aware that in Windows Command Prompt, to exit the interactive > > mode of Python (among others), you need to type Ctrl-Z ... > > > | C:\junk>python > > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > > (Intel)] on > > win32 > > | Type "help", "copyright", "credits" or "license" for more > > information. > > | >>> problem = '\x1a' > > | >>> ord(problem) > > | 26 > > | >>> # What is the 26th letter of the English/ASCII alphabet? > > | ... > > | >>> ^Z > > | > > | C:\junk> > > > HTH, > > John > > Hi John, > > I agree - those two answers are really good. Thanks to Mel and Marc. > I'm sorry if my stupid question was annoyed you. I didn't think your question was stupid. Stupid was (a) CP/M recording file size as number of 128-byte sectors, forcing the use of an in-band EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF decades after people stopped writing Ctrl-Z at the end of text files. And I wasn't annoyed either ... I was merely adding the information that Ctrl-Z and '\x1a' were the same thing; many people don't make the connection. Cheers, John From raj.indian.08 at gmail.com Mon Jan 12 09:01:46 2009 From: raj.indian.08 at gmail.com (RajNewbie) Date: Mon, 12 Jan 2009 06:01:46 -0800 (PST) Subject: Python tricks References: Message-ID: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> On Jan 12, 6:51?pm, Tim Chase wrote: > > ? ?My code has a lot of while loops of the following format: > > ? ?while True: > > ? ? ?... > > ? ? ?if : break > > > ? ?The danger with such a code is that it might go to an infinite loop > > - if the never occurs. > > ? ?Is there a way - a python trick - to have a check such that if the > > loop goes for more than x number of steps, it will cause an exception? > > > ? ?I do understand that we can use the code like - > > ? ?i = 0 > > ? ?while True: > > ? ? ?i++ > > ? ? ?if i > 200: raise infinite_Loop_Exception > > ? ? ?... > > ? ? ?if : break > > > ? ?But I am not very happy with this code for 3 reasons > > ? ?1. Verbosity (i=0 and i++) which doesnt add to the logic > > ? ?2. The loop now has dual focus. - incrementing i, etc. > > ? ?3. ? A person looks into the code and thinks 'i' > > has special significance. His/her mind will be focused on not the > > actual reason for the loop. > > My first thought would be to simply not use "while True": > > ? ?INFINITE_LOOP_COUNT = 200 > ? ?for _ in xrange(INFINITE_LOOP_COUNT): > ? ? ?do_something() > ? ? ?if : break > ? ?else: > ? ? ?raise InfiniteLoopException > > > ? ?The solution that I had in mind is: > > ? ?while True: > > ? ? ?... > > ? ? ?if : break > > ? ? ?if inifinte_loop(): raise infiinte_loop_exception > > > ? Wherein infinite_loop is a generator, which returns true if i > 200 > > ? def infinite_loop(): > > ? ? ?i = 0 > > ? ? ?while i < 200: > > ? ? ? ? ?i++ > > ? ? ? ? ?yield False > > ? ? ?yield True > > > Could somebody let me know whether this is a good option? > > To do this, you'd need to do the same sort of thing as you do > with your i/i++ variable: > > ? ?i = infinite_loop() > ? ?while True: > ? ? ?... > ? ? ?if : break > ? ? ?if i.next(): raise InfiniteLoopException > > which doesn't gain much, and makes it a whole lot more confusing. > > > Could someone chip in with other suggestions? > > As an aside: ?the phrase is "chime in"[1] (to volunteer > suggestions) "Chip in"[2] usually involves contributing money to > a common fund ("care to chip in $10 for Sally's wedding gift from > the office?" ?where the pool of money would then be used to buy > one large/expensive gift for Sally) > > -tkc > > [1]http://www.thefreedictionary.com/chime+in > > [2]http://www.english-test.net/forum/ftopic1768.html Thank you very much Tim. I agree on all counts - esp the fact that my suggestion is very confusing + (chime in part too :) ). But, I still feel it would be much more aesthetically pleasing if I can call a single procedure like if infinite_loop() -> to do the same. Is it somehow possible? - say by using static variables, iterators -- anything? From http Mon Jan 12 09:02:52 2009 From: http (Paul Rubin) Date: 12 Jan 2009 06:02:52 -0800 Subject: Python tricks References: Message-ID: <7x8wpgei5v.fsf@ruckus.brouhaha.com> RajNewbie writes: > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons I prefer: from itertools import count for i in count(): if i > 200: raise infinite_Loop_Exception ... You could also use: for i in xrange(200): ... else: raise infinite_Loop_Exception The "else" clause runs only if no break statement is executed. From psaffrey at googlemail.com Mon Jan 12 09:04:11 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 06:04:11 -0800 (PST) Subject: mod_python: delay in files changing after alteration References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> <80e89ae6-af47-420b-8d25-63966f92891a@o40g2000prn.googlegroups.com> Message-ID: On 6 Jan, 23:31, Graham Dumpleton wrote: > Thus, any changes to modules/packages installed on sys.path require a > full restart of Apache to ensure they are loaded by all Apache child > worker processes. > That will be it. I'm pulling in some libraries of my own from elsewhere, which are still being modified to accommodate the web app. These are the changes that are causing the problems. An Apache restart isn't too onerous - I'll just start doing that. Thanks, Peter From sjmachin at lexicon.net Mon Jan 12 09:10:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 06:10:58 -0800 (PST) Subject: Python tricks References: Message-ID: <20045ef5-8183-44e8-a3f9-c98ca2cdf968@q30g2000prq.googlegroups.com> On Jan 13, 12:51?am, Tim Chase took a walk on the OT side: > > Could someone chip in with other suggestions? > > As an aside: ?the phrase is "chime in"[1] (to volunteer > suggestions) "Chip in"[2] usually involves contributing money to > a common fund ("care to chip in $10 for Sally's wedding gift from > the office?" ?where the pool of money would then be used to buy > one large/expensive gift for Sally) > > [1]http://www.thefreedictionary.com/chime+in > [2]http://www.english-test.net/forum/ftopic1768.html All rather locale-dependent; see e.g. http://www.answers.com/topic/chip-in From roy at panix.com Mon Jan 12 09:22:41 2009 From: roy at panix.com (Roy Smith) Date: Mon, 12 Jan 2009 09:22:41 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> Message-ID: In article <7x1vv83afq.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > bieffe62 at gmail.com writes: > > > ? ?class Foo (DynamicAttributes, object): pass > > > > > You cannot do that, but you can establish a fixed set of attributes by > > defining the __slot__ class variable. > > That is not what __slot__ is for. Right. And tuples are not immutable lists (ducking and covering). From mrkafk at gmail.com Mon Jan 12 09:36:29 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 15:36:29 +0100 Subject: Egg deinstallation Message-ID: Hello everyone, I googled and googled and can't seem to find the definitive answer: how to *properly* deinstall egg? Just delete the folder and/or .py and .pyc files from Lib/site-packages? Would that break anything in Python installation or not? Regards, mk From psaffrey at googlemail.com Mon Jan 12 09:37:35 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 06:37:35 -0800 (PST) Subject: subprocess.Popen stalls Message-ID: I'm building a bioinformatics application using the ipcress tool: http://www.ebi.ac.uk/~guy/exonerate/ipcress.man.html I'm using subprocess.Popen to execute ipcress, which takes a group of files full of DNA sequences and returns some analysis on them. Here's a code fragment: cmd = "/usr/bin/ipcress ipcresstmp.txt --sequence /home/pzs/genebuilds/ human/*.fasta" print "checking with ipcress using command", cmd p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) retcode = p.wait() if retcode != 0: print "ipcress failed with error code:", retcode raise Exception output = p.stdout.read() If I run the command at my shell, it finishes successfully. It takes 30 seconds - it uses 100% of one core and several hundred MB of memory during this time. The output is 220KB of text. However, running it through Python as per the above code, it stalls after 5 seconds not using any processor at all. I've tried leaving it for a few minutes with no change. If I interrupt it, it's at the "retcode = p.wait()" line. I've tried making the bufsize really large and that doesn't seem to help. I'm a bit stuck - any suggestions? This same command has worked fine on other ipcress runs. This one might generate more output than the others, but 220KB isn't that much, is it? Peter Peter From deets at nospam.web.de Mon Jan 12 09:44:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 12 Jan 2009 15:44:07 +0100 Subject: Egg deinstallation References: Message-ID: <6t139nF8ip4nU1@mid.uni-berlin.de> mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? It depends on how you installed it. If it is done via setuptools/easy_install, you should also clean up the site-packages/easy-install.pth file. Diez From exarkun at divmod.com Mon Jan 12 09:50:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 12 Jan 2009 09:50:27 -0500 Subject: subprocess.Popen stalls In-Reply-To: Message-ID: <20090112145027.9754.1144898156.divmod.quotient.1254@henry.divmod.com> On Mon, 12 Jan 2009 06:37:35 -0800 (PST), "psaffrey at googlemail.com" wrote: >I'm building a bioinformatics application using the ipcress tool: > >http://www.ebi.ac.uk/~guy/exonerate/ipcress.man.html > >I'm using subprocess.Popen to execute ipcress, which takes a group of >files full of DNA sequences and returns some analysis on them. Here's >a code fragment: > >cmd = "/usr/bin/ipcress ipcresstmp.txt --sequence /home/pzs/genebuilds/ >human/*.fasta" >print "checking with ipcress using command", cmd >p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) >retcode = p.wait() >if retcode != 0: > print "ipcress failed with error code:", retcode > raise Exception >output = p.stdout.read() > >If I run the command at my shell, it finishes successfully. It takes >30 seconds - it uses 100% of one core and several hundred MB of memory >during this time. The output is 220KB of text. > >However, running it through Python as per the above code, it stalls >after 5 seconds not using any processor at all. I've tried leaving it >for a few minutes with no change. If I interrupt it, it's at the >"retcode = p.wait()" line. > >I've tried making the bufsize really large and that doesn't seem to >help. I'm a bit stuck - any suggestions? This same command has worked >fine on other ipcress runs. This one might generate more output than >the others, but 220KB isn't that much, is it? You have to read the output. Otherwise, the process's stdout fills up and its write attempt eventually blocks, preventing it from continuing. If you use Twisted's process API instead, the reading will be done for you (without any of the race conditions that are likely when using the subprocess module), and things will probably "just work". Jean-Paul From Zhangfang.hit at gmail.com Mon Jan 12 09:52:20 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 06:52:20 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> Message-ID: <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> On Jan 12, 10:41?pm, sensen wrote: > both above works well, but a problem is renamed file is without > filename extension. > > only change to the title. > > for example, the origin file is track_1.flac, after run the script i > want it to for example, White Flag.flac, but now it change to White > Flag without extension. > > could you do a favor to fix it. thank you. fixed it, i check the reference of python. the last line from os.rename(old, new) changed to os.rename(old, new+'.flac') thanks, now i still try to read the reference of python. i want to the script can know what file it will open. in other words, the script maybe first do a search, and get the exactly file name of the cue type file in the folder, then open it. From mrkafk at gmail.com Mon Jan 12 10:19:32 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:19:32 +0100 Subject: Egg deinstallation In-Reply-To: <6t139nF8ip4nU1@mid.uni-berlin.de> References: <6t139nF8ip4nU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: Thanks, Diez. From mrkafk at gmail.com Mon Jan 12 10:21:11 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:21:11 +0100 Subject: Compressed vs uncompressed eggs Message-ID: Hello everyone, Are there *good* reasons to use uncompressed eggs? Is there a, say, performance penalty in using compressed eggs? Regards, mk From mrkafk at gmail.com Mon Jan 12 10:33:34 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:33:34 +0100 Subject: subprocess.Popen stalls In-Reply-To: References: Message-ID: psaffrey at googlemail.com wrote: > p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) > output = p.stdout.read() Better use communicate() method: standardoutputstr, standarderrorstr = subprocess.communicate(...) Never had any problem with subprocesses when using subprocess module in this manner (well it's possible that standardoutputstr and/or standarderrorstr fill up the memory, you get the idea). Regards, mk From deets at nospam.web.de Mon Jan 12 10:35:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 12 Jan 2009 16:35:20 +0100 Subject: Compressed vs uncompressed eggs References: Message-ID: <6t169oF8j6vnU1@mid.uni-berlin.de> mk wrote: > Hello everyone, > > Are there *good* reasons to use uncompressed eggs? Plenty. Mostly that some things simply don't work in compressed eggs. See the zipsafe-flag in setuptools-docs. > Is there a, say, performance penalty in using compressed eggs? Not that it matters I'd say - only if you had an application that imports a lot & runs very short time. Diez From notvalid2 at sbcglobal.net Mon Jan 12 10:40:47 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 12 Jan 2009 07:40:47 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> References: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> Message-ID: <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> John Machin wrote: > On Jan 12, 9:16 pm, "W. eWatson" wrote: >> John Machin wrote: >>> On Jan 12, 2:00 pm, "W. eWatson" wrote: >>>> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to >>>> try windowpy from ActiveState. Is having both of these installed going to >>>> cause me trouble? >>> What is "windowpy from ActiveState"? If you mean you wanted to try the >>> PythonWin IDE instead of IDLE, all you needed to do was go to >>> http://sourceforge.net/projects/pywin32/hit the big download button >>> and make sure you get the 2.5 version (it's the default atm) and >>> install it. >> Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. >> >> Is it possible to just disable the vanilla (IDLE) version? I may want to >> switch between the two. Most users of the program I'm about to modify use >> the vanilla version. At some point, I may want to go back to it to verify >> that in their world all is OK. > > I'll try again. All you need is (a) the official distribution of > Python 2.5 for Windows from http://www.python.org (b) the pywin32 > package from the URL I gave you. Install both. Click on Start / All > Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ > or your users can use IDLE or PythonWin, only one copy of Python, no > conflicts. Why do you think you need to "disable" IDLE? Just don't use > it. > Once upon a time, six months ago, I asked a similar question and the answer was more complex. I decided to put this off until I truly needed it. Even better than Start, for me, is that I can choose PythonWin or IDLE from the right-click menu which I want. I do see a choice there of Open With-> Python. I can see it executed properly, but which 2.5 did it use? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From bieffe62 at gmail.com Mon Jan 12 10:42:47 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 12 Jan 2009 07:42:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> Message-ID: <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> On 12 Gen, 14:45, Paul Rubin wrote: > bieff... at gmail.com writes: > > > ? ?class Foo (DynamicAttributes, object): pass > > > You cannot do that, but you can establish a fixed set of attributes by > > defining the __slot__ class variable. > > That is not what __slot__ is for. Really? It seems to work: >>> class A(object): ... __slots__ = ('a', 'b') ... def __init__(self): self.not_allowed = 1 ... >>> a = A() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ AttributeError: 'A' object has no attribute 'not_allowed' >>> Ciao ----- FB From invalid at invalid Mon Jan 12 10:43:06 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 12 Jan 2009 09:43:06 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> Message-ID: On 2009-01-12, Sion Arrowsmith wrote: > Grant Edwards wrote: >>On 2009-01-09, Sion Arrowsmith wrote: >>> Grant Edwards wrote: >>>>If I were you, I'd try mmap()ing the file instead of reading it >>>>into string objects one chunk at a time. >>> You've snipped the bit further on in that sentence where the >>> OP says that the file of interest is 2GB. Do you still want to >>> try mmap'ing it? >>Sure. The larger the file, the more you gain from mmap'ing it. >>2GB should easily fit within the process's virtual memory >>space. > > Assuming you're in a 64bit world. Me, I've only got 2GB of address > space available to play in -- mmap'ing all of it out of the question. Oh. I assumed that decent 32-bit OSes would provide at least 3-4GB of address space to user processes. What OS are you using? > But I supposed that mmap'ing it chunk at a time instead of > reading chunk at a time might be worth considering. I'd try mmap'ing it in large chunks (512MB maybe). -- Grant Edwards grante Yow! I feel like a wet at parking meter on Darvon! visi.com From psaffrey at googlemail.com Mon Jan 12 10:45:22 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 07:45:22 -0800 (PST) Subject: subprocess.Popen stalls References: Message-ID: On 12 Jan, 15:33, mk wrote: > > Better use communicate() method: > Oh yes - it's right there in the documentation. That worked perfectly. Many thanks, Peter From invalid at invalid Mon Jan 12 10:46:14 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 12 Jan 2009 09:46:14 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> Message-ID: On 2009-01-12, Sion Arrowsmith wrote: > In case the cancel didn't get through: > > Sion Arrowsmith wrote: >>Grant Edwards wrote: >>>2GB should easily fit within the process's virtual memory >>>space. >>Assuming you're in a 64bit world. Me, I've only got 2GB of address >>space available to play in -- mmap'ing all of it out of the question. > > And today's moral is: try it before posting. Yeah, I can map a 2GB > file no problem, complete with associated 2GB+ allocated VM. The > addressing is clearly not working how I was expecting it too. Cool. I'd be very interested to to know how the performance compares to open/read. -- Grant Edwards grante Yow! I think I am an at overnight sensation right visi.com now!! From mrkafk at gmail.com Mon Jan 12 11:11:48 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 17:11:48 +0100 Subject: subprocess.Popen stalls In-Reply-To: References: Message-ID: psaffrey at googlemail.com wrote: > On 12 Jan, 15:33, mk wrote: >> Better use communicate() method: >> > > Oh yes - it's right there in the documentation. That worked perfectly. What's also in the docs and I did not pay attention to before: Note The data read is buffered in memory, so do not use this method if the data size is large or unlimited. Regards, mk From lists at cheimes.de Mon Jan 12 11:26:26 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 17:26:26 +0100 Subject: Compressed vs uncompressed eggs In-Reply-To: References: Message-ID: > Is there a, say, performance penalty in using compressed eggs? To the contrary, it can be faster to import from a zip file than from the file system. Christian From ryandw at gmail.com Mon Jan 12 11:28:50 2009 From: ryandw at gmail.com (webcomm) Date: Mon, 12 Jan 2009 08:28:50 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <66c46e9e-74dc-4d86-8dba-1edc17085bb9@x14g2000yqk.googlegroups.com> If anyone's interested, here are my django views... from django.shortcuts import render_to_response from django.http import HttpResponse from xml.etree.ElementTree import ElementTree import urllib, base64, subprocess def get_data(request): service_url = 'http://www.something.com/webservices/someservice/ etc?user=etc&pass=etc' xml = urllib.urlopen(service_url) #the base64-encoded string is in a one-element xml doc... tree = ElementTree() xml_doc = tree.parse(xml) datum = "" for node in xml_doc.getiterator(): datum = "%s" % (node.text) decoded = base64.b64decode(datum) dir = '/path/to/data/' f = open(dir+'data.zip', 'wb') f.write(decoded) f.close() file = subprocess.call('unzip '+dir+'data.zip -d '+dir, shell=True) file = open(dir+'data', 'rb').read() txt = file.decode('utf_16_le') return render_to_response('output.html',{ 'output' : txt }) def read_xml(request): xml = urllib.urlopen('http://www.something.org/get_data/') #page using the get_data view xml = xml.read() xml = unicode(xml) xml = '\n'+xml+'' f = open('/path/to/temp.txt','w') f.write(xml) f.close() tree = ElementTree() xml_doc = tree.parse('/path/to/temp.txt') datum = "" for node in xml_doc.getiterator(): datum = "%s
%s - %s" % (datum, node.tag, node.text) return render_to_response('output.html',{ 'output' : datum }) From thomas.steffen75 at googlemail.com Mon Jan 12 11:35:45 2009 From: thomas.steffen75 at googlemail.com (thomas.steffen75 at googlemail.com) Date: Mon, 12 Jan 2009 08:35:45 -0800 (PST) Subject: read a password protected xls file Message-ID: <567034d3-32b7-4954-a3ce-fae716159ded@k1g2000prb.googlegroups.com> Hello, how can I read (and parse) a password protected xls file, perhaps with the package xlrd? Thanks for your hints, Thomas From andrea.reginato at gmail.com Mon Jan 12 11:47:24 2009 From: andrea.reginato at gmail.com (Andrea Reginato) Date: Mon, 12 Jan 2009 08:47:24 -0800 (PST) Subject: Encoding Title mail References: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> <6t0tjgF8gel1U1@mid.uni-berlin.de> Message-ID: <30e3f843-184f-4a52-81e9-86be560d6524@a29g2000pra.googlegroups.com> On Jan 12, 2:06?pm, Marc 'BlackJack' Rintsch wrote: > On Mon, 12 Jan 2009 04:32:35 -0800, Andrea Reginato wrote: > > Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some > > mails from a google account and save the attached files. All works fine, > > but when a tile has some letters with accents (like ?????) I read a > > string like this. > > > =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? > > _=E9*=A7=B0=E7;:=5F_test_chars?= > > > I tried to use the string.decode(ISO-8859-1) function, but nothing > > change. > Look into the `email` package in the standard library. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch I tried to look at it, but nothing to do, sorry. I used email.Utils.decode_rfc2231(msg['Subject']) that seems what I need (I could be wrong, but it looks the closer at what I need) but it do not work out. I'm searching into the library, I'm not able to get the solution. Thanks again for your time From bj_666 at gmx.net Mon Jan 12 11:53:07 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 12 Jan 2009 16:53:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> Message-ID: <6t1arjF8gel1U2@mid.uni-berlin.de> On Mon, 12 Jan 2009 07:42:47 -0800, bieffe62 wrote: > On 12 Gen, 14:45, Paul Rubin wrote: >> bieff... at gmail.com writes: >> > > ? ?class Foo (DynamicAttributes, object): pass >> >> > You cannot do that, but you can establish a fixed set of attributes >> > by defining the __slot__ class variable. >> >> That is not what __slot__ is for. > > > Really? It seems to work: It works but it is not what `__slot__` was invented for. Some call it a misuse of that feature if you use it to prevent adding attributes dynamically. And it has some drawbacks when you inherit from such classes. Ciao, Marc 'BlackJack' Rintsch From arkanes at gmail.com Mon Jan 12 11:53:26 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 10:53:26 -0600 Subject: BadZipfile "file is not a zip file" In-Reply-To: <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <4866bea60901120853t19f3897q91df65a9d8e71f52@mail.gmail.com> On Sat, Jan 10, 2009 at 1:32 PM, webcomm wrote: > On Jan 9, 7:33 pm, John Machin wrote: >> It is not impossible for a file with dummy data to have been >> handcrafted or otherwise produced by a process different to that used >> for a real-data file. > > I knew it was produced by the same process, or I wouldn't have shared > it. : ) > But you couldn't have known that. > > >> > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> >> Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick >> with one thread ... > > Thanks... I thought I was posting about separate issues and would > annoy people who were only interested in one of the issues if I put > them both in the same thread. I guess all posts re: the same script > should go in one thread, even if the questions posed may be unrelated > and may be separate issues. There are grey areas. > > Problem solved in John Machin's post at > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/03b8341539d87989?hl=en&lnk=raot#03b8341539d87989 > It's worth pointing out (although the provider probably doesn't care) that this isn't really an XML document and this was a bad way of them to distribute the data. If they'd used a correctly formatted XML document (with the prelude and everything) with the correct encoding information, existing XML parsers should have just Done The Right Thing with the data, instead of you needing to know the encoding a priori to extract an XML fragment. From Scott.Daniels at Acm.Org Mon Jan 12 12:05:38 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 09:05:38 -0800 Subject: Python logging rollover In-Reply-To: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> References: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> Message-ID: Kottiyath wrote: > Hi, > > I want to do a log rollover .... I tested it with 'midnight' option, > but it did not work as I expected. Please google "smart questions". All I can conclude from your message is that your expectations are wrong. It is not enough to tell us you are confused. You need to show us enough so that we can discover what might, or might not, be going wrong. At the least, what was your code, what happened, and what did you expect to happen. --Scott David Daniels Scott.Daniels at Acm.Org From almar.klein at gmail.com Mon Jan 12 12:07:49 2009 From: almar.klein at gmail.com (Almar Klein) Date: Mon, 12 Jan 2009 18:07:49 +0100 Subject: VTK in python Message-ID: Hi all, I want to use the Visualisation ToolKit from python. However, I cannot find an easy way to install it. Of course, I could download the source, use CMake to build and VS to compile it, but... yeah, that takes a lot of time and will probably not work the first time... I noticed that with VTK 4.0 there was a vtk40python.exe installer supplied. But that realease if almost 7 years old... Why is such an installer no longer distributed with the newer releases? I hope I overlooked something, or else I guess I should go compiling tomorrow... :( Thanks for any help, Almar PS: I know entought ships with VTK, but it's such a huge install I try to avoid that... -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jan 12 12:16:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jan 2009 12:16:16 -0500 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: <496B04AB.9010409@shopzeus.com> References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> <496B04AB.9010409@shopzeus.com> Message-ID: Laszlo Nagy wrote: > Laszlo Nagy wrote: >> Meanwhile I'm trying to turn off threads in that program one by one. I >> just got this new type of error: >> >> Fatal Python error: PyThreadState_Delete: invalid tstate > After some days, there are now answers to my question. I guess this is > because nobody knows the answer. I think I need to consider this a bug > in Python. Where can I post a bug report? bugs.python.org From tjreedy at udel.edu Mon Jan 12 12:30:48 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jan 2009 12:30:48 -0500 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> <496B04AB.9010409@shopzeus.com> Message-ID: Terry Reedy wrote: > Laszlo Nagy wrote: >> Laszlo Nagy wrote: >>> Meanwhile I'm trying to turn off threads in that program one by one. >>> I just got this new type of error: >>> >>> Fatal Python error: PyThreadState_Delete: invalid tstate >> After some days, there are now answers to my question. I guess this is >> because nobody knows the answer. I think I need to consider this a bug >> in Python. Where can I post a bug report? > > bugs.python.org Before submitting, search for existing report of same bug. If none, try to write a minimal program that reliably reproduces the bug. (If you can't, it will be hard to fix.). Make sure the bug occurs with 2.6.1 or 3.0. Earlier 2.x is not maintained except for security patches. From Scott.Daniels at Acm.Org Mon Jan 12 12:34:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 09:34:21 -0800 Subject: Python tricks In-Reply-To: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: RajNewbie wrote: > On Jan 12, 6:51 pm, Tim Chase wrote: [a perfectly fine reply which is how I'd solve it] >> RajNewbie wrote: >>> ... The solution that I had in mind is: >>> while True: >>> ... >>> if : break >>> if inifinte_loop(): raise infiinte_loop_exception >>> Wherein infinite_loop is a generator, which returns true if i > 200 >>> def infinite_loop(): >>> i = 0 >>> while i < 200: >>> i++ >>> yield False >>> yield True >>> Could somebody let me know whether this is a good option? > ... > But, I still feel it would be much more aesthetically pleasing if I > can call a single procedure like > if infinite_loop() -> to do the same. > Is it somehow possible? - say by using static variables, iterators -- > anything? 1) Please cut down quoted text to as little as needed to understand the reply. Yes, it is possible. After: def Fuse(count, exception): for i in range(count): yield None raise exception You can do your loop as: check_infinite = Fuse(200, ValueError('Infinite Loop')).next while True: ... check_infinite() but I agree with Tim that a for ... else loop for the limit is clearer. --Scott David Daniels Scott.Daniels at Acm.Org From dskippy at ccs.neu.edu Mon Jan 12 12:40:57 2009 From: dskippy at ccs.neu.edu (Mike MacHenry) Date: Mon, 12 Jan 2009 12:40:57 -0500 Subject: Simple CGI-XMLRPC failure Message-ID: <7d9c10d20901120940t544448cdl35f2c806a4bfc59a@mail.gmail.com> I am having a difficult time understanding why my very simple CGI-XMLRPC test isn't working. I created a server to export two functions, the built-in function "pow" and my own identity function "i". I run a script to call both of them and the "pow" work fine but the "i" gives me an error that says my XMLRPC server doesn't support than name. Here is the code for both files and the output: #!/usr/bin/env python #This file is /usr/lib/cgi-bin/roundwarerpc.py from SimpleXMLRPCServer import CGIXMLRPCRequestHandler def i(x): return x server = CGIXMLRPCRequestHandler() server.register_function(pow) server.register_function(i) server.handle_request() #!/usr/bin/env python #This file is ~/test.py import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") print server.pow(2,3) print server.i(10) #This is the STDOUT and STDERR when running ~/test.py dskippy at dskippy-laptop:$ python test.py 8 Traceback (most recent call last): File "test.py", line 4, in print server.test(10) File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ return self.__send(self.__name, args) File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response return u.close() File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :method "i" is not supported'> Does anyone know what might be wrong with this? Thanks for the help, -mike p.s. Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Server version Apache/2.2.8 (Ubuntu) Server built: Jun 25 2008 13:54:13 From nad at acm.org Mon Jan 12 13:03:22 2009 From: nad at acm.org (Ned Deily) Date: Mon, 12 Jan 2009 10:03:22 -0800 Subject: Egg deinstallation References: <6t139nF8ip4nU1@mid.uni-berlin.de> Message-ID: In article <6t139nF8ip4nU1 at mid.uni-berlin.de>, "Diez B. Roggisch" wrote: > mk wrote: > > I googled and googled and can't seem to find the definitive answer: how > > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > > files from Lib/site-packages? Would that break anything in Python > > installation or not? > > It depends on how you installed it. If it is done via > setuptools/easy_install, you should also clean up the > > site-packages/easy-install.pth > > file. ... and which you can do by editing that file directly or by using the easy_install -m option to mark the egg as multi-version before deleting. In either case, keep in mind that the egg may have installed one or more scripts; those have to be removed manually. -- Ned Deily, nad at acm.org From rdcollum at gmail.com Mon Jan 12 13:14:19 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 10:14:19 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: On Jan 12, 6:31?am, James Stroud wrote: > James Stroud wrote: > > py> b.tk.call('bind', 'Listbox', '', _) > > You want b.tk.call('bind', 'Listbox', '', "") of course. > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com Knowing this is actually extremely useful (looking at Tkinter.py i see this is equivalent to the unbind method). Unfortunately it's not working to unbind B1-Motion from Listbox even though I get the same output results as you've gotten above. =( Thanks a ton James. This is still very educational to me. Roger. From gert.cuykens at gmail.com Mon Jan 12 13:27:57 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 10:27:57 -0800 (PST) Subject: python3.0 MySQLdb Message-ID: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> I need something to connect to a database, preferably mysql, that works in python3.0 please. From Tribulations at Paralleles.invalid Mon Jan 12 13:51:23 2009 From: Tribulations at Paralleles.invalid (TP) Date: Mon, 12 Jan 2009 19:51:23 +0100 Subject: trying to modify locals() dictionary Message-ID: Hi everybody, I try to modify locals() as an exercise. According to the context (function or __main__), it works differently (see below). Why? Thanks Julien ######################################## def try_to_modify_locals( locals_ ): locals_[ "a" ] = 2 print "locals_[ 'a' ]=", locals_[ "a" ] return locals_ def test_modify_locals(): a = 3 l = try_to_modify_locals( locals() ) print l is locals() print a # Below, a remains equal to 3 print "test from test_modify_locals()" test_modify_locals() # But here, it works: a is modified print "test from __main__" a = 3 l = try_to_modify_locals( locals() ) print l is locals() print a ######################################## -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From lists at cheimes.de Mon Jan 12 14:08:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 20:08:38 +0100 Subject: trying to modify locals() dictionary In-Reply-To: References: Message-ID: TP schrieb: > Hi everybody, > > I try to modify locals() as an exercise. > According to the context (function or __main__), it works differently (see > below). Why? Thanks Because http://docs.python.org/library/functions.html#locals Warning The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. Christian From lists at cheimes.de Mon Jan 12 14:12:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 20:12:52 +0100 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: > I say again, show me a case of working 2.5 code where prepending u to > an ASCII string constant that is intended to be used in a text context > is actually worth the keystrokes. Eventually you'll learn it the hard way. *sigh* Christian From gandalf at shopzeus.com Mon Jan 12 14:13:37 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 20:13:37 +0100 Subject: Slow network? Message-ID: <496B9661.30406@shopzeus.com> Hi All, To make the long story short, I have a toy version of an ORB being developed, and the biggest problem is slow network speed over TCP/IP. There is an object called 'endpoint' on both sides, with incoming and outgoing message queues. This endpoint object has a socket assigned, with nodelay: conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) The endpoint is running two separate threads - those are dedicated for reading/writing messages from/into the socket object, as shown below: def _process_incoming(self): try: while not self.stop_requested.isSet(): data = self.read_str() while not self.stop_requested.isSet(): try: self.incoming.put(data,1) break except orb.util.smartqueue.Full: pass if not self.stop_requested.isSet(): if self.router: self.router.on_message_arrived(self) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) def _process_outgoing(self): try: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): try: data = self.outgoing.get(1) data_ok = True break except orb.util.smartqueue.Empty: pass if data_ok: self.write_str(data) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) The main point is that the sender does not need to wait for the message to be actually written into the socket (unless the outgoing queue becomes full). When I try to send a message and receive an answer for it, I can only get as much as 130 request+response message pairs per second. Apparently, it is the same from messages size =77bytes to message size=16 Kbytes. However, if I send 100 outgoing messages first, then read back all answers then the speed goes up to 1300 message pairs/sec. I suspect that this has something to do with TCP/IP. Since this will be used for RPC/RMI, it would be very important to lower the time needed to exchange messages. Is there any way I can speed this up? Or do you think that this speed is the best I can get? My friend tried to do the same thing in Java, and he said that he could reach 1000 messages/sec. (Is there a special "socket.flush()" method in Java that we do not have in Python?) Thanks, Laszlo From jcd at sdf.lonestar.org Mon Jan 12 14:15:00 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Mon, 12 Jan 2009 14:15:00 -0500 Subject: Creating new instances of subclasses. In-Reply-To: References: Message-ID: <1231787700.5865.9.camel@mctell> On Fri, 2009-01-09 at 10:46 -0800, Dennis Lee Bieber wrote: > On Wed, 07 Jan 2009 11:38:29 -0500, "J. Cliff Dyer" > declaimed the following in comp.lang.python: > > > I want to be able to create an object of a certain subclass, depending > > on the argument given to the class constructor. > > > > I have three fields, and one might need to be a StringField, one an > > IntegerField, and the last a ListField. But I'd like my class to > > delegate to the proper subclass automatically, so I can just do: > > > > >>> f1 = Field('abc') > > >>> f2 = Field('123') > > >>> f3 = Field('D,E,F') > > And how do you differentiate a string that contains a comma from a > purported list? > > What is expected for: > > ambiguous = Field('He said "Blast, it won''t work"') My strings don't look like that. Nor is that relevant to my question. I created a simple, uncluttered example to illustrate my issue with instantiating the proper subclass for a given argument. I did not try to make sure my example handled all edge cases properly. Cheers, Cliff From marduk at letterboxes.org Mon Jan 12 14:18:59 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 12 Jan 2009 14:18:59 -0500 Subject: trying to modify locals() dictionary In-Reply-To: References: Message-ID: <1231787939.3639.1.camel@localhost.localdomain> On Mon, 2009-01-12 at 19:51 +0100, TP wrote: > Hi everybody, > > I try to modify locals() as an exercise. > According to the context (function or __main__), it works differently (see > below). Why? Thanks > > Julien Per the locals() documentation @ http://docs.python.org/library/functions.html Warning The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. From fetchinson at googlemail.com Mon Jan 12 14:25:16 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 12 Jan 2009 11:25:16 -0800 Subject: python3.0 MySQLdb In-Reply-To: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: > I need something to connect to a database, preferably mysql, that > works in python3.0 please. And your question is? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From arkanes at gmail.com Mon Jan 12 14:35:00 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 13:35:00 -0600 Subject: Slow network? In-Reply-To: <496B9661.30406@shopzeus.com> References: <496B9661.30406@shopzeus.com> Message-ID: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> On Mon, Jan 12, 2009 at 1:13 PM, Laszlo Nagy wrote: > > Hi All, > > To make the long story short, I have a toy version of an ORB being > developed, and the biggest problem is slow network speed over TCP/IP. > > There is an object called 'endpoint' on both sides, with incoming and > outgoing message queues. This endpoint object has a socket assigned, with > nodelay: > > conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) > > The endpoint is running two separate threads - those are dedicated for > reading/writing messages from/into the socket object, as shown below: > > > def _process_incoming(self): > try: > while not self.stop_requested.isSet(): > data = self.read_str() > while not self.stop_requested.isSet(): > try: > self.incoming.put(data,1) > break > except orb.util.smartqueue.Full: > pass > if not self.stop_requested.isSet(): > if self.router: > self.router.on_message_arrived(self) > except Exception, e: > if self.router: > if not isinstance(e,TransportClosedError): > self.router.logger.error(dumpexc(e)) > self.router.unregister_endpoint(self) > self.shutdown() > raise SystemExit(0) > > def _process_outgoing(self): > try: > while not self.stop_requested.isSet(): > data_ok = False > while not self.stop_requested.isSet(): > try: > data = self.outgoing.get(1) > data_ok = True > break > except orb.util.smartqueue.Empty: > pass > if data_ok: > self.write_str(data) > except Exception, e: > if self.router: > if not isinstance(e,TransportClosedError): > self.router.logger.error(dumpexc(e)) > self.router.unregister_endpoint(self) > self.shutdown() > raise SystemExit(0) > > > The main point is that the sender does not need to wait for the message to > be actually written into the socket (unless the outgoing queue becomes > full). > > When I try to send a message and receive an answer for it, I can only get as > much as 130 request+response message pairs per second. Apparently, it is the > same from messages size =77bytes to message size=16 Kbytes. > > However, if I send 100 outgoing messages first, then read back all answers > then the speed goes up to 1300 message pairs/sec. I suspect that this has > something to do with TCP/IP. Since this will be used for RPC/RMI, it would > be very important to lower the time needed to exchange messages. Is there > any way I can speed this up? > It is very likely that nodelay is actually hurting you here. Using the select module and doing non-blocking IO will be faster than using threads for this as well. From perfreem at yahoo.com Mon Jan 12 14:36:47 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 11:36:47 -0800 (PST) Subject: efficient interval containment lookup Message-ID: hello, suppose I have two lists of intervals, one significantly larger than the other. For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain thousands of elements while listB (of the same form) might contain hundreds of thousands or millions of elements. I want to count how many intervals in listB are contained within every listA. For example, if listA = [(10, 30), (600, 800)] and listB = [(20, 25), (12, 18)] is the input, then the output should be that (10, 30) has 2 intervals from listB contained within it, while (600, 800) has 0. (Elements of listB can be contained within many intervals in listA, not just one.) What is an efficient way to this? One simple way is: for a_range in listA: for b_range in listB: is_within(b_range, a_range): # accumulate a counter here where is_within simply checks if the first argument is within the second. I'm not sure if it's more efficient to have the iteration over listA be on the outside or listB. But perhaps there's a way to index this that makes things more efficient? I.e. a smart way of indexing listA such that I can instantly get all of its elements that are within some element of listB, maybe? Something like a hash, where this look up can be close to constant time rather than an iteration over all lists... if there's any built-in library functions that can help in this it would be great. any suggestions on this would be awesome. thank you. From google at mrabarnett.plus.com Mon Jan 12 14:49:15 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jan 2009 19:49:15 +0000 Subject: Slow network? In-Reply-To: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> Message-ID: <496B9EBB.7050908@mrabarnett.plus.com> Chris Mellon wrote: > On Mon, Jan 12, 2009 at 1:13 PM, Laszlo Nagy wrote: >> Hi All, >> >> To make the long story short, I have a toy version of an ORB being >> developed, and the biggest problem is slow network speed over TCP/IP. >> >> There is an object called 'endpoint' on both sides, with incoming and >> outgoing message queues. This endpoint object has a socket assigned, with >> nodelay: >> >> conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) >> >> The endpoint is running two separate threads - those are dedicated for >> reading/writing messages from/into the socket object, as shown below: >> >> >> def _process_incoming(self): >> try: >> while not self.stop_requested.isSet(): >> data = self.read_str() >> while not self.stop_requested.isSet(): >> try: >> self.incoming.put(data,1) >> break >> except orb.util.smartqueue.Full: >> pass >> if not self.stop_requested.isSet(): >> if self.router: >> self.router.on_message_arrived(self) >> except Exception, e: >> if self.router: >> if not isinstance(e,TransportClosedError): >> self.router.logger.error(dumpexc(e)) >> self.router.unregister_endpoint(self) >> self.shutdown() >> raise SystemExit(0) >> >> def _process_outgoing(self): >> try: >> while not self.stop_requested.isSet(): >> data_ok = False >> while not self.stop_requested.isSet(): >> try: >> data = self.outgoing.get(1) >> data_ok = True >> break >> except orb.util.smartqueue.Empty: >> pass >> if data_ok: >> self.write_str(data) >> except Exception, e: >> if self.router: >> if not isinstance(e,TransportClosedError): >> self.router.logger.error(dumpexc(e)) >> self.router.unregister_endpoint(self) >> self.shutdown() >> raise SystemExit(0) >> >> >> The main point is that the sender does not need to wait for the message to >> be actually written into the socket (unless the outgoing queue becomes >> full). >> >> When I try to send a message and receive an answer for it, I can only get as >> much as 130 request+response message pairs per second. Apparently, it is the >> same from messages size =77bytes to message size=16 Kbytes. >> >> However, if I send 100 outgoing messages first, then read back all answers >> then the speed goes up to 1300 message pairs/sec. I suspect that this has >> something to do with TCP/IP. Since this will be used for RPC/RMI, it would >> be very important to lower the time needed to exchange messages. Is there >> any way I can speed this up? >> > > It is very likely that nodelay is actually hurting you here. > > Using the select module and doing non-blocking IO will be faster than > using threads for this as well. > You might also want to replace those 'pass' statements when smartqueue is empty or full with time.sleep() to avoid busy waiting. From gandalf at shopzeus.com Mon Jan 12 14:56:02 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 20:56:02 +0100 Subject: Slow network? In-Reply-To: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> Message-ID: <496BA052.2040101@shopzeus.com> > It is very likely that nodelay is actually hurting you here. > > Using the select module and doing non-blocking IO will be faster than > using threads for this as well. > These sockets are non blocking and I'm using select.select indeed. Here is how it is implemented: def read_data(self,size): res = "" fd = self.socket.fileno() while not self.stop_requested.isSet(): remaining = size - len(res) if remaining<=0: break # Give one second for an incoming connection so we can stop the # server in seconds when needed ready = select.select([fd], [], [], 0.2) if fd in ready[0]: data = self.socket.recv(min(remaining,8192)) # 8192 is recommended by socket.socket manual. if not data: # select returns the fd but there is no data to read -> connection closed! raise TransportClosedError("Connection closed.") else: res += data else: pass if self.stop_requested.isSet(): raise SystemExit(0) return res def write_data(self,data): fd = self.socket.fileno() while not self.stop_requested.isSet(): size = len(data) if size==0: break # Give one second for an incoming connection so we can stop the server in seconds when needed ready = select.select([], [fd], [], 0.2) if fd in ready[1]: sent = self.socket.send( # 8192 is recommended by socket.socket manual. data[:max(size,8192)] ) if not sent: # select returns the fd but there is no data written -> connection closed! raise TransportClosedError("Connection closed.") else: data = data[sent:] # Not too efficient... else: pass if self.stop_requested.isSet(): raise SystemExit(0) All other I/O methods are calling write_data() and read_data(). One thing I cannot do is to remove threads. This endpoint class is specifically designed so that other threads can put messages into the outgoing queue, and they do not need to wait for the message to be written out into the socket: endpoint.send_message(msg) # won't block unless the outgoing queue is full endpoint.recv_message(msg) # won't block unless the incoming queue is empty Given this situation, I see no alternative to using threads. Do you? Here is how the socket is set up on the client side: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) s.connect((params['address'],params['port'])) return orb.endpoint.SocketEndpoint(s) And on the server side: def handle_request(self): conn,client_address = self.serversocket.accept() self.logger.info( str(client_address) + ' connecting') conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) t = orb.endpoint.SocketEndpoint(conn,self.router) The socket based endpoint starts with setting non-blocking mode: class SocketEndpoint(Endpoint): """Specialized Transport endpoint that communicates over a socket.""" def __init__(self,socket,router=None): self.socket = socket self.socket.setblocking(0) Endpoint.__init__(self,router) Here are some more test results: - original example with setblocking(0) and TCP_NODELAY: 130 messages / sec - same example without TCP_NODELAY: 130 messages/sec (I don't understand why?) - same example without setblocking(0): 130 messages/sec (I guess because I'm using select.select already?) - same example without setblocking(0) and without TCP_NODELAY: 130 messages / sec Now I really didn't understand where is the problem? I suspected that maybe the overhead for select.select? But nope, tried the same example without select.select and without setblocking(0) and it was also 130 messages/sec. What is hurting me then? Is it not TCP? :-( From gandalf at shopzeus.com Mon Jan 12 15:01:07 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:01:07 +0100 Subject: Slow network? In-Reply-To: <496B9EBB.7050908@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496B9EBB.7050908@mrabarnett.plus.com> Message-ID: <496BA183.8050900@shopzeus.com> > You might also want to replace those 'pass' statements when smartqueue > is empty or full with time.sleep() to avoid busy waiting. It won't do busy waiting, because read_str and write_str are using select.select and they will block without using CPU time, until data becomes available to read/write. From gandalf at shopzeus.com Mon Jan 12 15:04:54 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:04:54 +0100 Subject: Slow network? In-Reply-To: <496B9EBB.7050908@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496B9EBB.7050908@mrabarnett.plus.com> Message-ID: <496BA266.4070709@shopzeus.com> > You might also want to replace those 'pass' statements when smartqueue > is empty or full with time.sleep() to avoid busy waiting. I misunderstood your post, sorry. My smartqueue class has a timeout parameter, and it can block for an item, or raise the Full/Empty exception after timeout exceeded. That is 1 second in my example program: self.incoming.put(data,1) data = self.outgoing.get(1) From bdesth.quelquechose at free.quelquepart.fr Mon Jan 12 15:06:46 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 12 Jan 2009 21:06:46 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xhc45csw0.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <496bb081$0$31451$426a74cc@news.free.fr> Paul Rubin a ?crit : > Carl Banks writes: >>> The criticism is very valid. Some languages do support immutable >>> variables (e.g. "final" declarations in Java, "const" in C++, or >>> universal immutability in pure functional languages) and they do so >>> precisely for the purpose of taming the chaos of uncontrolled >>> mutation. It would be great if Python also supported immutability. >> I don't think what you said (which is fine) makes his criticism valid, >> unless you also suggest that all objects should be immutable. > > It would be enough to have a way to make specific objects and instance > attributes immutable. > >> If any objects are mutable, you have to be prepared for objects to >> mutated outside the initializer. > > Sure, but why have mutable objects all over the place? And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. Why on earth are you using Python if you don't like the way it work ??? From silfheed at gmail.com Mon Jan 12 15:07:20 2009 From: silfheed at gmail.com (Silfheed) Date: Mon, 12 Jan 2009 12:07:20 -0800 (PST) Subject: Mocking `from foo import *` functions References: <68239214-859a-4484-91b1-ec208393d28d@f40g2000pri.googlegroups.com> Message-ID: <0057e679-ce50-4321-a23c-b3e21b57d6fd@e10g2000vbe.googlegroups.com> Brilliant, I love it. Thanks a million, guys. From google at mrabarnett.plus.com Mon Jan 12 15:15:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jan 2009 20:15:48 +0000 Subject: Slow network? In-Reply-To: <496BA052.2040101@shopzeus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496BA052.2040101@shopzeus.com> Message-ID: <496BA4F4.6090709@mrabarnett.plus.com> Laszlo Nagy wrote: > [snip] > Here are some more test results: > > - original example with setblocking(0) and TCP_NODELAY: 130 messages / sec > - same example without TCP_NODELAY: 130 messages/sec (I don't understand > why?) > - same example without setblocking(0): 130 messages/sec (I guess because > I'm using select.select already?) > - same example without setblocking(0) and without TCP_NODELAY: 130 > messages / sec > > Now I really didn't understand where is the problem? I suspected that > maybe the overhead for select.select? But nope, tried the same example > without select.select and without setblocking(0) and it was also 130 > messages/sec. > > What is hurting me then? Is it not TCP? :-( > Waiting for a response after each send will take longer than doing the sends and then the responses. Have you tried pinging the destination to see how long the round trip takes? Has your friend? From gert.cuykens at gmail.com Mon Jan 12 15:19:52 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 12:19:52 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> On Jan 12, 8:25?pm, "Daniel Fetchinson" wrote: > > I need something to connect to a database, preferably mysql, that > > works in python3.0 please. > > And your question is? MySQLdb or something else for python3.0 ? From skip at pobox.com Mon Jan 12 15:24:39 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 12 Jan 2009 14:24:39 -0600 Subject: python3.0 MySQLdb In-Reply-To: <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> Message-ID: <18795.42759.175057.640166@montanaro.dyndns.org> >> > I need something to connect to a database, preferably mysql, that >> > works in python3.0 please. >> >> And your question is? gert> MySQLdb or something else for python3.0 ? Given that Python 3.0 is so new and so few packages have been ported to it yet, it might be helpful if you explained why Python 2.6 + MySQLdb isn't sufficient for your needs. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From ryandw at gmail.com Mon Jan 12 15:27:42 2009 From: ryandw at gmail.com (webcomm) Date: Mon, 12 Jan 2009 12:27:42 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> On Jan 12, 11:53?am, "Chris Mellon" wrote: > On Sat, Jan 10, 2009 at 1:32 PM,webcomm wrote: > > On Jan 9, 7:33 pm, John Machin wrote: > >> It is not impossible for a file with dummy data to have been > >> handcrafted or otherwise produced by a process different to that used > >> for a real-data file. > > > I knew it was produced by the same process, or I wouldn't have shared > > it. : ) > > But you couldn't have known that. > > >> > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > >> Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick > >> with one thread ... > > > Thanks... I thought I was posting about separate issues and would > > annoy people who were only interested in one of the issues if I put > > them both in the same thread. ?I guess all posts re: the same script > > should go in one thread, even if the questions posed may be unrelated > > and may be separate issues. ?There are grey areas. > > > Problem solved in John Machin's post at > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > It's worth pointing out (although the provider probably doesn't care) > that this isn't really an XML document and this was a bad way of them > to distribute the data. If they'd used a correctly formatted XML > document (with the prelude and everything) with the correct encoding > information, existing XML parsers should have just Done The Right > Thing with the data, instead of you needing to know the encoding a > priori to extract an XML fragment. Agreed. I can't say I understand their rationale for doing it this way. From gandalf at shopzeus.com Mon Jan 12 15:33:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:33:03 +0100 Subject: Slow network? In-Reply-To: <496BA4F4.6090709@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496BA052.2040101@shopzeus.com> <496BA4F4.6090709@mrabarnett.plus.com> Message-ID: <496BA8FF.4060801@shopzeus.com> >> > Waiting for a response after each send will take longer than doing the > sends and then the responses. Have you tried pinging the destination > to see how long the round trip takes? Has your friend? My test application listens on 127.0.0.1. gandalf at gandalf-desktop:~/Python/Lib/orb/examples/01_lowlevel$ ping 127.0.0.1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.027 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.018 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.021 ms If we only see the response time, the worst case would be 1000.0/ ( 2*0.027 ) = 18518 message pairs / sec... (My friend used 127.0.0.1 too) From pavlovevidence at gmail.com Mon Jan 12 15:39:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 12:39:38 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: <2f09e5e2-3849-4f23-a65c-3edf21740fa6@q30g2000prq.googlegroups.com> On Jan 12, 5:26?am, John Machin wrote: > On Jan 12, 7:29?pm, Carl Banks wrote: > > > > > On Jan 12, 12:32?am, John Machin wrote: > > > > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > > > language is crippled. > > > > > > What is this "transitional dialect"? What does "getting all your Us in > > > > > place" mean? > > > > > Transitional dialect is the subset of Python 2.6 that can be > > > > translated to Python3 with 2to3 tool. > > > > I'd never seen it called "transitional dialect" before. > > > I had hoped the context would make it clear what I was talking about. > > In vain. You were one who was mistaken about what Steve and Cliff were talking about, chief. Maybe if you'd have paid better attention you would have gotten it? > > > > ?Getting all your Us in place > > > > refers to prepending a u to strings to make them unicode objects, > > > > which is something 2to3 users are highly advised to do to keep hassles > > > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > > > "foo", doesn't it? What's the point of going through the code and > > > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > > > u off again? > > > It does a bit more than that. > > Like what? Never mind; I was confusing it with a different tool. (Someone had a source code processing tool that replaced strings with their reprs a while back.) My bad. > > > What hassles? Who's doing the highly-advising where and > > > with what supporting argument? > > > You add the u so the the constant will be the same data type in 2.6 as > > it becomes in 3.0 after applying 2to3. ?str and unicode objects aren't > > always with smooth with each other, and you have a much better chance > > of getting the same behavior in 2.6 and 3.0 if you use an actual > > unicode string in both. > > (1) Why specifically 2.6? Do you mean 2.X, or is this related to the > "port to 2.6 first" theory? It's not a theory. 2to3 was designed to translate a subset of 2.6 code to 3.0. It's not designed to translate arbitrary 2.6 code, nor any 2.5 or lower code. It might work well enough from 2.5, but it wasn't designed for it. > (2) We do assume we are starting off with working 2.X code, don't we? > If we change "foo" to u"foo" and get a different answer from the 2.X > code, is that still "working"? Of course it's not "working" in 2.6, and that's the point: you want it to work in 2.6 with Unicode strings because it has to run in 3.0 with Unicode strings. > > A example of this, though not with string constants, > > And therefore irrelevant. Well, it wasn't from my viewpoint, which was "make sure you are using only unicode and bytes objects", never str objects. But if you want to talk about string constants specifically, ok. > I would like to hear from someone who has actually started with > working 2.x code and changed all their text-like "foo" to > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > * how many places where the 2.x code broke and so did the 3.x code > [i.e. the problem would have been detected without prepending u] I think you're missing the point. This isn't merely about detecting errors; it's about making the code in 2.6 behave as similarly to 3.0 as possible, and that includes internal behavior. When you have mixed str and unicode objects, 2.6 has to do a lot of encoding and decoding under the covers; in 3.0 that won't be happening. That increases the risk of divergent behavior, and is something you want to avoid. If you think your test suite is invincible and can catch every possible edge case where some encoding or decoding mishap occurs, be my guest and don't do it. Also, I'm not sure why you think it's preferrable to run tests on 3.0 and have to go back to the 2.6 codebase, run 2to3 again, apply the patch again, and retest, to fix it. I don't know, maybe it makes sense for people with a timemachine.py module, but I don't think it'll make sense for most people. > * how many places where the 2.x code broke but the 3.x code didn't > [i.e. prepending u did find the problem] If you think this was the main benefit of doing that you are REALLY missing the point. The point isn't to find problems in 2.6, it's to modify 2.6 to behave as similarly to 3.0 as possible. > * whether they thought it was worth the effort > > In the meantime I would be interested to hear from anybody with a made- > up example of code where the problem would be detected (sooner | > better | only) by prepending u to text-like string constants. Here's one for starters. The mistake was using a multibyte character in a str object in 2.6. 2to3 would have converted this to a script that has different behavior. If the u"" had been present on the string it would have the same behavior in both 2.6 and 3.0. (Well, the repr is different but it's a repr of the same object in both.) # coding: utf-8 print repr("abcd?") Out of curiosity, do > > 2to3 can only do so > > much; it can't always guess whether your string usage is supposed to > > be character or binary. > > AFAICT it *always* guesses text rather than binary; do you have any > examples where it guesses binary (rightly or wrongly)? Again, not the point. It's not whether 2to3 guesses correctly, but whether the runtime does different things in the two versions. Carl Banks From python.list at tim.thechases.com Mon Jan 12 15:43:57 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jan 2009 14:43:57 -0600 Subject: efficient interval containment lookup In-Reply-To: References: Message-ID: <496BAB8D.4020807@tim.thechases.com> > suppose I have two lists of intervals, one significantly larger than > the other. > For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain > thousands > of elements while listB (of the same form) might contain hundreds of > thousands > or millions of elements. > I want to count how many intervals in listB are contained within every > listA. For example, if listA = [(10, 30), (600, 800)] and listB = > [(20, 25), (12, 18)] is the input, then the output should be that (10, > 30) has 2 intervals from listB contained within it, while (600, 800) > has 0. (Elements of listB can be contained within many intervals in > listA, not just one.) > > What is an efficient way to this? One simple way is: > > for a_range in listA: > for b_range in listB: > is_within(b_range, a_range): > # accumulate a counter here Could you detail the is_within() function? most importantly, is it inclusive, such that "a1 <= b1 <= b2 <= a2", or is it overlapping such that "a1 <= b2 or a2 <= b1". Additionally, do you want to count how many intervals of A overlap with intervals of B, or do you just want a count of how many intervals in B have *any* overlap within A? My leaning would be to make a custom "is this in A" function, iterate over B and test against an "appropriate subset" of A: listA = sorted([...]) min_a1 = min(a1 for (a1, a2) in listA) max_a2 = max(a2 for (a1, a2) in listA) def in_a(b1, b2): for a1, a2 in smartly_chosen_subset(listA, b1, b2): if is_within((b1, b2), (a1, a2)): return True return False i = 0 for b1, b2 in sorted(listB): if b2 < min_a1: continue if b1 > max_a2: break if in_a(b1, b2): i += 1 The in_a() function can be optimized to terminate early if a1>b2 or a2 < b1 (perhaps even choosing an smart starting point for iterating). Short-circuiting by returning True as soon as you know there's a match will trim some of the time. How distributed are the endpoints? If there's a lot of commonality in the data, you might be able to cache results to cut even further. Just a few ideas, and questions that might help develop better solutions. -tkc From Scott.Daniels at Acm.Org Mon Jan 12 15:52:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 12:52:14 -0800 Subject: efficient interval containment lookup In-Reply-To: References: Message-ID: Are these ranges constrained in any way? Does preprocessing count in the efficiency cost? Is the long list or the short list fixed while the other varies? With no constraints the problem is harder. > But perhaps there's a way to index this that makes things more > efficient? I.e. a smart way of indexing listA such that I can > instantly get all of its elements that are within some element > of listB, maybe? Something like a hash, where this look up can be > close to constant time rather than an iteration over all lists... > [what] built-in library functions ... can help? > any suggestions on this would be awesome. thank you. If the intervals have a rough size on either side (or both), that could give you a useful grid for your hashing. If the total range of the integers in listA is smallish, you could label every value in that range with which elements of listA contain that point. You could also look for interesting orders of the intervals in listA, so that you can use the bisect module to get to one end of a range that will hold all your answers and only check the applicable elements of the range. You might also consider how you could set up numpy arrays to test the set of ranges in listA in a pair of operations. I hope I haven't helped you with your homework. --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Mon Jan 12 16:05:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 12 Jan 2009 15:05:32 -0600 Subject: efficient interval containment lookup In-Reply-To: <496BAB8D.4020807@tim.thechases.com> References: <496BAB8D.4020807@tim.thechases.com> Message-ID: [Apologies for piggybacking, but I think GMane had a hiccup today and missed the original post] [Somebody wrote]: >> suppose I have two lists of intervals, one significantly larger than >> the other. >> For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain >> thousands >> of elements while listB (of the same form) might contain hundreds of >> thousands >> or millions of elements. >> I want to count how many intervals in listB are contained within every >> listA. For example, if listA = [(10, 30), (600, 800)] and listB = >> [(20, 25), (12, 18)] is the input, then the output should be that (10, >> 30) has 2 intervals from listB contained within it, while (600, 800) >> has 0. (Elements of listB can be contained within many intervals in >> listA, not just one.) Interval trees. http://en.wikipedia.org/wiki/Interval_tree -- 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 rdcollum at gmail.com Mon Jan 12 16:29:52 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 13:29:52 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> I'm sorry for harassing the list but any suggestions would be greatly appreciated. =) From http Mon Jan 12 16:36:07 2009 From: http (Paul Rubin) Date: 12 Jan 2009 13:36:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> Message-ID: <7xfxjofbqw.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Why on earth are you using Python if you don't like the way it work ??? Why on earth keep releasing new versions of Python if the old ones are already perfect? From boblatest at yahoo.com Mon Jan 12 16:40:47 2009 From: boblatest at yahoo.com (Robert Latest) Date: 12 Jan 2009 21:40:47 GMT Subject: Python tricks References: Message-ID: <6t1rmuF8jrfaU1@mid.uni-berlin.de> RajNewbie wrote: > Is there a way - a python trick - to have a check such that if the > loop goes for more than x number of steps, it will cause an exception? > > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons > 1. Verbosity (i=0 and i++) which doesnt add to the logic > 2. The loop now has dual focus. - incrementing i, etc. > 3. A person looks into the code and thinks 'i' > has special significance. His/her mind will be focused on not the > actual reason for the loop. Maybe you should call the counter variable something meaningful instead of -- of all things -- "i", which is idiomatic for soething entirely else. And add a comment, and be done with it. > The solution that I had in mind is: > while True: > ... > if : break > if inifinte_loop(): raise infiinte_loop_exception This is a lot less understandable because whoever is working with your code will now have to check an additional function rather than a pretty self-explanatory variable increment. robert From boblatest at yahoo.com Mon Jan 12 16:44:10 2009 From: boblatest at yahoo.com (Robert Latest) Date: 12 Jan 2009 21:44:10 GMT Subject: Python tricks References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: <6t1rtaF8jrfaU2@mid.uni-berlin.de> RajNewbie wrote: > But, I still feel it would be much more aesthetically pleasing if I > can call a single procedure like > if infinite_loop() -> to do the same. You may find it aesthetically pleasing, and it may very well be, but it will obfuscate your code and make it less maintainable. robert From rt8396 at gmail.com Mon Jan 12 16:48:29 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 13:48:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> Message-ID: <1ead9f8d-e32f-4dd8-8dc3-aa26d4f01928@e10g2000vbe.googlegroups.com> On Jan 12, 2:06?pm, Bruno Desthuilliers wrote: > Why on earth are you using Python if you don't like the way it work ??? Why on earth are you busting into someone's thread just because you don't like what they have to say ??? From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 16:49:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 21:49:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > Bruno Desthuilliers writes: >> Why on earth are you using Python if you don't like the way it work ??? > > Why on earth keep releasing new versions of Python if the old ones are > already perfect? That's a fallacious argument. Nobody is arguing that any specific version of Python is perfect, but clearly many people do like the general design choices of the language, that is, the way it works. *If* you don't like the way it works, and you have a choice in the matter, perhaps you should find another language that works more the way you would prefer. On the other hand... Bruno's question is unfair. It is perfectly reasonable to (hypothetically) consider Python to be the best *existing* language while still wanting it to be improved (for some definition of improvement). Just because somebody has criticisms of Python, or a wish- list of features, doesn't mean they hate the language. -- Steven From rt8396 at gmail.com Mon Jan 12 16:54:45 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 13:54:45 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> [stevie] On the other hand... Bruno's question is unfair. It is perfectly reasonable to (hypothetically) consider Python to be the best *existing* language while still wanting it to be improved (for some definition of improvement). Just because somebody has criticisms of Python, or a wish- list of features, doesn't mean they hate the language. [/stevie] WOW Steven, i am very impressed. That's the first thing you have said in a very long time that i totally agree with! Keep this up and i may put you back on my Python Brethren list :) From http Mon Jan 12 16:58:28 2009 From: http (Paul Rubin) Date: 12 Jan 2009 13:58:28 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <7xtz84fapn.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > *If* you don't like the way it works, and you have a choice in the > matter, perhaps you should find another language that works more the way > you would prefer. We are in an era for programming languages sort of like the Windows 95 era was for operating systems, where everything is broken but some of the fixes are beginning to come into view. So there is no language that currently really works the right way, but some of them including Python are (one hopes) moving in good directions. Maybe I can help that process along by posting, maybe not. From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 17:00:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 22:00:35 GMT Subject: efficient interval containment lookup References: Message-ID: On Mon, 12 Jan 2009 11:36:47 -0800, Per Freem wrote: > hello, > > suppose I have two lists of intervals, one significantly larger than the > other. [...] > What is an efficient way to this? One simple way is: http://en.wikipedia.org/wiki/Interval_tree > for a_range in listA: > for b_range in listB: > is_within(b_range, a_range): > # accumulate a counter here > > where is_within simply checks if the first argument is within the > second. This will be O(m*n) where m is the size of the smaller list and n is the size of the big one. It shouldn't matter which order you do the loops, you still have to iterate over every point in each list, for every point in the other list. Using an interval tree may let you decrease the time to O(m*log n), at the cost of extra overhead, but for millions of items the saving should be large. -- Steven From martin at v.loewis.de Mon Jan 12 17:25:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 12 Jan 2009 23:25:15 +0100 Subject: python3.0 MySQLdb In-Reply-To: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <496BC34B.2050406@v.loewis.de> > I need something to connect to a database, preferably mysql, that > works in python3.0 please. For postgres, psycopg2 works with Python 3 (if you use my patch). Regards, Martin From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 17:34:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 22:34:27 GMT Subject: urllib2 - 403 that _should_ not occur. References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, 12 Jan 2009 00:38:20 -0600, Chris Mellon wrote: >> Why Google would deny access to services by unknown User Agents is >> beyond me - especially since in most cases User Agents strings are not >> strict. > > If you look at the actual response text and not just the error code, you > will get a clear explanation of why you were forbidden. You have a funny idea of what constitutes a "clear explanation".

Forbidden

Your client does not have permission to get URL /group/chromium- announce/feed/rss_v2_0_msgs.xml from this server. That hardly explains "Why Google would deny access to services by unknown User Agents", does it? -- Steven From arkanes at gmail.com Mon Jan 12 17:43:32 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 16:43:32 -0600 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: <4866bea60901121443h73e299f0s2f47e272c4bc0037@mail.gmail.com> On Mon, Jan 12, 2009 at 4:34 PM, Steven D'Aprano wrote: > On Mon, 12 Jan 2009 00:38:20 -0600, Chris Mellon wrote: > >>> Why Google would deny access to services by unknown User Agents is >>> beyond me - especially since in most cases User Agents strings are not >>> strict. >> >> If you look at the actual response text and not just the error code, you >> will get a clear explanation of why you were forbidden. > > You have a funny idea of what constitutes a "clear explanation". > > >

Forbidden

> Your client does not have permission to get URL /group/chromium- > announce/feed/rss_v2_0_msgs.xml from this server. > > > That hardly explains "Why Google would deny access to services by unknown > User Agents", does it? > > I suppose I should have checked that specific URL. The search results pages (last I checked) gave a detailed error message. From jstroud at mbi.ucla.edu Mon Jan 12 17:45:20 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 14:45:20 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: Roger wrote: > I'm sorry for harassing the list but any suggestions would be greatly > appreciated. =) I just checked the behavior you are describing. It seems that you want to unbind the event to stop the autoscrolling when you leave the listbox. E.g.: from Tkinter import * tk = Tk() lb = Listbox(tk) lb.pack() tk.tk.call('bind', str(lb), '', "break") for i in range(12): lb.insert(END, str(i)) Sorry for not reading more carefully. James From perfreem at yahoo.com Mon Jan 12 17:49:43 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 14:49:43 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: thanks for your replies -- a few clarifications and questions. the is_within operation is containment, i.e. (a,b) is within (c,d) iff a >= c and b <= d. Note that I am not looking for intervals that overlap... this is why interval trees seem to me to not be relevant, as the overlapping interval problem is way harder than what I am trying to do. Please correct me if I'm wrong on this... Scott Daniels, I was hoping you could elaborate on your comment about bisect. I am trying to use it as follows: I try to grid my space (since my intervals have an upper and lower bound) into segments (e.g. of 100) and then I take these "bins" and put them into a bisect list, so that it is sorted. Then when a new interval comes in, I try to place it within one of those bins. But this is getting messy: I don't know if I should place it there by its beginning number or end number. Also, if I have an interval that overlaps my boundaries -- i.e. (900, 1010) when my first interval is (0, 1000), I may miss some items from listB when i make my count. Is there an elegant solution to this? Gridding like you said seemed straight forward but now it seems complicated.. I'd like to add that this is *not* a homework problem, by the way. On Jan 12, 4:05?pm, Robert Kern wrote: > [Apologies for piggybacking, but I think GMane had a hiccup today and missed the > original post] > > [Somebody wrote]: > > >> suppose I have two lists of intervals, one significantly larger than > >> the other. > >> For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain > >> thousands > >> of elements while listB (of the same form) might contain hundreds of > >> thousands > >> or millions of elements. > >> I want to count how many intervals in listB are contained within every > >> listA. For example, if listA = [(10, 30), (600, 800)] and listB = > >> [(20, 25), (12, 18)] is the input, then the output should be that (10, > >> 30) has 2 intervals from listB contained within it, while (600, 800) > >> has 0. (Elements of listB can be contained within many intervals in > >> listA, not just one.) > > Interval trees. > > http://en.wikipedia.org/wiki/Interval_tree > > -- > 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 rt8396 at gmail.com Mon Jan 12 17:52:02 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 14:52:02 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> Message-ID: <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> On Jan 12, 3:58?pm, Paul Rubin wrote: > We are in an era for programming languages sort of like the Windows 95 > era was for operating systems, where everything is broken but some of > the fixes are beginning to come into view. ?So there is no language > that currently really works the right way, but some of them including > Python are (one hopes) moving in good directions. ?Maybe I can help > that process along by posting, maybe not. Paul, Python is the best hope for readable, maintainable very high-level coding. Python forged the path and showed all other languages for what they truly are; archaic, redundant, pieces of complete rubbish! In my mind only 2 languages stand out in the very high level category; Python and Ruby. Ruby only exists in this world because of the things it took from Python. Nobody would touch Ruby without it's Pythonisms. Python wins hands down, WHY? you ask. Well i could list a thousand reasons why but i will only cover a few. 1.) read-ability 2.) learn-ability 3.) maintain-ability 4.) perfect choice of keywords 5.) no end statement, braces, or lisps! 6.) no forced capitalizations 7.) modules are the actual script name 8.) introspection 9.) class, and class inheritance is beautiful 8.) true procedural support(no instance vars needed) 10.) loads of quality documentation! 11.) IDLE 12.) Guido (the genius that made all this happen!) I could keep going for days and days. Python is hands down the best thing that ever happened to the world of programming. Sure it could use a few improvements, nothing and nobody is perfect. But can any language stand toe to toe with Python? HELL NO! From jstroud at mbi.ucla.edu Mon Jan 12 17:58:58 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 14:58:58 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: James Stroud wrote: > tk.tk.call('bind', str(lb), '', "break") Which is equivalent to lb.bind('', "break") But I checked and overriding the default behavior of Listbox does not work (tk.tk.call('bind', "Listbox", '', "break")). So I would subclass Listbox and do the bindings in the __init__: class MyListbox(Listbox): def __init__(self, *args, **kwargs): Listbox.__init__(self, *args, **kwargs) self.bind('', "break") James From sjmachin at lexicon.net Mon Jan 12 18:03:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 15:03:20 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: <0268015d-e31b-4931-97cd-a92fcd74c567@p36g2000prp.googlegroups.com> On Jan 13, 6:12?am, Christian Heimes wrote: > > I say again, show me a case of working 2.5 code where prepending u to > > an ASCII string constant that is intended to be used in a text context > > is actually worth the keystrokes. > > Eventually you'll learn it the hard way. *sigh* And the hard way involves fire and brimstone, together with weeping, wailing and gnashing of teeth, correct? Hmmm, let's see. Let's take Carl's example of the sinner who didn't decode the input: """ Someone found that urllib.open() returns a bytes object in Python 3.0, which messed him up since in 2.x he was running regexp searches on the output. If he had been taking care to use only unicode objects in 2.x (in this case, by explicitly decoding the output) then it wouldn't have been an issue. """ 3.0 says: | >>> re.search("foo", b"barfooble") | Traceback (most recent call last): | File "", line 1, in | File "C:\python30\lib\re.py", line 157, in search | return _compile(pattern, flags).search(string) | TypeError: can't use a string pattern on a bytes-like object The problem is diagnosed at the point of occurrence with a 99%-OK exception message. Why only 99%? Because it only vaguely hints at this possibility: | >>> re.search(b"foo", b"barfooble") | <_sre.SRE_Match object at 0x00FACD78> Obvious solution (repent and decode): | >>> re.search("foo", b"barfooble".decode('ascii')) | <_sre.SRE_Match object at 0x00FD86B0> This is "messed him up"? One can get equally "messed up" when AFAICT one is doing the right thing in 2.X e.g. one is digging XML documents out of a ZIP file (str in 2.X, bytes in 3.x). ElementTree.parse() requires a file, so in 2.X one uses cStringIO.StringIO. 2to3 changes that to io.StringIO [quite reasonable; no easy way of knowing if BytesIO would be better; StringIO more probable]. 3.X barfs on the io.StringIO(xml_bytes) with a reasonable message "TypeError: can't write bytes to text stream" [momentarily puzzling -- write? Oh yeah, it happens in self.write(initial_value)] so there's a need to setup a BYTESIO that's conditional on Python version -- not a big deal at all. I see no /Inferno/ here :-) From pecora at anvil.nrl.navy.mil Mon Jan 12 18:12:19 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Mon, 12 Jan 2009 15:12:19 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: In article , Roy Smith wrote: > In article > <34c95e04-5b3f-44bc-a5bf-498518507131 at p36g2000prp.googlegroups.com>, > "Madhusudan.C.S" wrote: > > > In such situations, where the Instance variables come into existence > > only when they are used it is very difficult to track the flow of code. > > As the saying goes, "It's possible to write Fortran in any language". > > My personal habit is to "declare" all instance variables in the __init__() > method of every class. If there's no better value, I set them to None. > This isn't strictly required, but I think it makes it easier for somebody > reading the code to understand the class. I agree with you. I do exactly this. It prevents a lot of problems by giving one place to look for class variables and comments on them. Setting to None is good, too, since many times if I use one before setting a value I'll get an exception or really bad results that I can easily trace to the unset variable. > I'm not a big fan of dogmatic rules, other than the rule that says you > should make your code as easy for somebody else to understand as possible. Right. -- -- Lou Pecora From http Mon Jan 12 18:34:23 2009 From: http (Paul Rubin) Date: 12 Jan 2009 15:34:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> Message-ID: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> r writes: > Python and Ruby. Ruby only exists in this world because of the things > it took from Python. Nobody would touch Ruby without it's Pythonisms. I confess to not knowing much about Ruby. It looks sort of Perl-ish to me, and I always hear it is slower than Python, which is already too slow. > Python wins hands down, WHY? you ask. Well i could list a thousand > reasons why but i will only cover a few. > > 1.) read-ability > 2.) ... > I could keep going for days and days. Python is hands down the best > thing that ever happened to the world of programming. Sure it could > use a few improvements, nothing and nobody is perfect. But can any > language stand toe to toe with Python? HELL NO! Those things on your list are all nice, but I think Python has considerable room for improvement in several areas: 1) Parallelism. Commodity desktop computers now have 8 effective cpu cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still has the evil GIL that forces all threads to run on one core. Java, Erlang, and Haskell (GHC) all beat Python in this area. By the time Python 4 comes out, we will probably all be using PC's with 32 or more cores, so the current limitations will be intolerable. Even today, since no one doing anything serious uses single core machines any more, the GIL is a huge pain in the neck which the multiprocessing module helps only slightly. (While we are at it, lightweight threads like Erlang's or GHC's would be very useful.) 2) Native-code compilation. Per the Alioth shootouts, Python is much slower (even on single cores) than Java, Haskell, ML, or even Scheme. PyPy is addressing this but it will be a while before it replaces CPython. 3) Data encapsulation, the subject of most of this thread. 4) Static analysis. It would be great if there were a much more powerful Pylint that could do ML-like type inference among other things. You could still program in a dynamic, heterogeneous style if you wanted to, but Pylint would complain about it unless you supplied some annotations to tell it where the dynamism was and how to separate it from the rest of the program. This is consistent with Python's "consenting adults" principle: if consenting adults want to participate in a BDSM scene, they should be allowed to. There would probably have to be some new language features to assist in writing typefully. Python 3.0 has some gestures in this direction but they are not yet fully formed. I believe that the PyPy project is developing the above areas in ways CPython really could not. While we are now committed to Python 3.0 being a CPython revision that makes some minor (and in my view somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 will be based on PyPy and have more substantial differences. From gert.cuykens at gmail.com Mon Jan 12 18:35:52 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 15:35:52 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496BC34B.2050406@v.loewis.de> Message-ID: Its for testing mod_wsgi trunk on Python3.0 in combination with a database. Does anybody has a patch for MySQLdb ? From deets at nospam.web.de Mon Jan 12 18:45:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 00:45:41 +0100 Subject: Simple CGI-XMLRPC failure In-Reply-To: References: Message-ID: <6t2315F8lo1gU1@mid.uni-berlin.de> Mike MacHenry schrieb: > I am having a difficult time understanding why my very simple > CGI-XMLRPC test isn't working. I created a server to export two > functions, the built-in function "pow" and my own identity function > "i". I run a script to call both of them and the "pow" work fine but > the "i" gives me an error that says my XMLRPC server doesn't support > than name. Here is the code for both files and the output: > > #!/usr/bin/env python > #This file is /usr/lib/cgi-bin/roundwarerpc.py > from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > def i(x): > return x > server = CGIXMLRPCRequestHandler() > server.register_function(pow) > server.register_function(i) > server.handle_request() > > > #!/usr/bin/env python > #This file is ~/test.py > import xmlrpclib > server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > print server.pow(2,3) > print server.i(10) > > #This is the STDOUT and STDERR when running ~/test.py > dskippy at dskippy-laptop:$ python test.py 8 > Traceback (most recent call last): > File "test.py", line 4, in > print server.test(10) > File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > return self.__send(self.__name, args) > File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > verbose=self.__verbose > File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > return self._parse_response(h.getfile(), sock) > File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > return u.close() > File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > raise Fault(**self._stack[0]) > xmlrpclib.Fault: :method "i" > is not supported'> > > Does anyone know what might be wrong with this? This works. --- import threading from SimpleXMLRPCServer import SimpleXMLRPCServer def i(x): return x server = SimpleXMLRPCServer(('localhost', 10000)) server.register_function(pow) server.register_function(i) t = threading.Thread(target=server.serve_forever) t.setDaemon(True) t.start() import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost:10000") print server.pow(2,3) print server.i(10) --- So maybe i is somehow an instance-variable of CGIXMLRPCRequestHandler. What happens if you rename it? Diez From ajaksu at gmail.com Mon Jan 12 18:48:50 2009 From: ajaksu at gmail.com (ajaksu) Date: Mon, 12 Jan 2009 15:48:50 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 11, 11:59?pm, "James Mills" wrote: > Hey all, > > The following fails for me: > > >>> from urllib2 import urlopen > >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") > > Traceback (most recent call last): [...] > Any helpful ideas ? Maybe raise a real bug @ bugs.python.org instead of just mentioning it like I did: http://bugs.python.org/msg77889 I think at least some sites would be willing to add the new UA to their whitelists. HTH, Daniel From deets at nospam.web.de Mon Jan 12 18:49:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 00:49:04 +0100 Subject: debugging ignored exceptions at cleanup In-Reply-To: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> References: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> Message-ID: <6t237gF8lo1gU2@mid.uni-berlin.de> Michele Simionato schrieb: > In some conditions (typically with threads, __del__ methods, etc) the > cleanup mechanism of Python gets in trouble and some exceptions are > not raised but just printed on stderr. > I have an application using Paste and when I run the tests I get some > annoying > ignored exceptions during cleanup. Running the code with the -v option > I get things > like that: > > > # cleanup[2] sqlalchemy.util > # cleanup[2] sqlalchemy.sql.expression > # cleanup[2] symbol > # cleanup[2] urllib2 > # cleanup[2] sqlalchemy.orm.query > # cleanup[2] smweb.config > # cleanup[2] formencode > # cleanup[2] smweb.config.environment > Exception exceptions.TypeError: "'NoneType' object is not callable" in > at 0x26861b8> ignored > Exception exceptions.TypeError: "'NoneType' object is not callable" in > at 0x2598578> ignored > # cleanup[2] dbhash > # cleanup[2] xmlrpclib > # cleanup[2] mako.pygen > # cleanup[2] time > # cleanup[2] paste.util.import_string > # cleanup sys > # cleanup __builtin__ > # cleanup ints: 5096 unfreed ints in 145 out of 171 blocks > # cleanup floats: 43 unfreed floats in 3 out of 4 blocks > > As you see, the exceptions happen during the cleanup of > smweb.config.environment, > which the part of code I wrote, but which has no obvious problems and > imports > *lots* of other stuff. Is there some way to hook in the cleanup > mechanism, start > a pdb and see really what is happening? I tried to trace the execution > flow with the > trace module but without success. There is so much code there that I > am unable > to track down the source of the problem. I suspect there is some > __del__ method > somewhere that tries to call a function which has been set to None by > the cleanup > mechanism, possibly from another thread, but I cannot find it. How am > I supposed to > debug such things? You aren't I guess. AFAIK, you can't do anything about this - if there is really some cleanup todo, it should be done before exiting the program. I for once know that the TurboMail lib has had similar problems - and the "fix" was to check the used names in __del__ before trying to invoke anything on them. Even *that* might not help in a multi-threaded environment though, nobody can guarantee that between the check and the usage of a name the underlying object isn't GCed. Diez From excord80 at gmail.com Mon Jan 12 18:55:07 2009 From: excord80 at gmail.com (excord80) Date: Mon, 12 Jan 2009 15:55:07 -0800 (PST) Subject: Egg deinstallation References: Message-ID: <41a0569f-0b7c-4900-9476-a28837a9ac30@k9g2000vbl.googlegroups.com> On Jan 12, 9:36?am, mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? As an aside, note that there's no automated way to uninstall (for exmaple, like doing "aptitude purge" or "make uninstall"). It's a known problem with setuptools/eggs/easy_install/whatever. Dunno if pip [1] yet solves this problem or not. http://pip.openplans.org/ From pavlovevidence at gmail.com Mon Jan 12 19:00:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 16:00:19 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> <0268015d-e31b-4931-97cd-a92fcd74c567@p36g2000prp.googlegroups.com> Message-ID: On Jan 12, 5:03?pm, John Machin wrote: > On Jan 13, 6:12?am, Christian Heimes wrote: > > > > I say again, show me a case of working 2.5 code where prepending u to > > > an ASCII string constant that is intended to be used in a text context > > > is actually worth the keystrokes. > > > Eventually you'll learn it the hard way. *sigh* > > And the hard way involves fire and brimstone, together with weeping, > wailing and gnashing of teeth, correct? Hmmm, let's see. Let's take > Carl's example of the sinner who didn't decode the input: """ Someone > found that urllib.open() returns a bytes object in Python 3.0, which > messed him up since in 2.x he was running regexp searches on the > output. ?If he had been taking care to use only unicode objects in 2.x > (in this case, by explicitly decoding the output) then it wouldn't > have been an issue. """ > > 3.0 says: > | >>> re.search("foo", b"barfooble") > | Traceback (most recent call last): > | ? File "", line 1, in > | ? File "C:\python30\lib\re.py", line 157, in search > | ? ? return _compile(pattern, flags).search(string) > | TypeError: can't use a string pattern on a bytes-like object > > The problem is diagnosed at the point of occurrence with a 99%-OK > exception message. Why only 99%? Because it only vaguely hints at this > possibility: > | >>> re.search(b"foo", b"barfooble") > | <_sre.SRE_Match object at 0x00FACD78> > > Obvious solution (repent and decode): > | >>> re.search("foo", b"barfooble".decode('ascii')) > | <_sre.SRE_Match object at 0x00FD86B0> > > This is "messed him up"? If you believe in waiting for bugs to occur and then fixing them, rather than programming to avoid bugs, there is no helping you. P.S. The "obvious" solution is wrong, although I'm not sure if you were making some kind of ironic point. Carl Banks From gdamjan at gmail.com Mon Jan 12 19:31:38 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jan 2009 01:31:38 +0100 Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: > Perhaps you also like to hear from a developer who has worked on > Python 3.0 itself and who has done lots of work with internationalized > applications. If you want to get it right you must > > * decode incoming text data to unicode as early as possible > * use unicode for all internal text data > * encode outgoing unicode as late as possible. > > where incoming data is read from the file system, database, network > etc. amen to that... I hate all those apps/libs that only work with ASCII. -- ?????? ( http://softver.org.mk/damjan/ ) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From steve at holdenweb.com Mon Jan 12 19:33:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 19:33:09 -0500 Subject: hlep: a text search and rename question In-Reply-To: <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> Message-ID: sensen wrote: > On Jan 12, 10:41 pm, sensen wrote: >> both above works well, but a problem is renamed file is without >> filename extension. >> >> only change to the title. >> >> for example, the origin file is track_1.flac, after run the script i >> want it to for example, White Flag.flac, but now it change to White >> Flag without extension. >> >> could you do a favor to fix it. thank you. > > fixed it, i check the reference of python. > the last line from > os.rename(old, new) > changed to > os.rename(old, new+'.flac') > > thanks, now i still try to read the reference of python. > i want to the script can know what file it will open. in other words, > the script maybe first do a search, and get the exactly file name of > the cue type file in the folder, then open it. Well done - the true Python spirit. Fix it yourself when you can. And now you know a bit more about the logic James so kindly wrote for you. Congratulations, and welcome to the Python community. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gdamjan at gmail.com Mon Jan 12 19:43:34 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jan 2009 01:43:34 +0100 Subject: redirecting stderr back.. References: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Message-ID: > Hi All, > > Can someone tell me how to redirect stderr back to the console once > you've moved it? > > import os,sys > se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) > sys.stderr.write("Foobar\n") > Foobar > os.dup2(se, 2) why not os.dup2(2, 10) and then later os.dup2(10, 2) -- ?????? ( http://softver.org.mk/damjan/ ) Begin...the rest is easy. From jeff at jmcneil.net Mon Jan 12 19:47:20 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 12 Jan 2009 16:47:20 -0800 (PST) Subject: Egg deinstallation References: Message-ID: <90b54e54-70a9-49cb-9b72-a9c2fb5fb68d@z1g2000yqn.googlegroups.com> On Jan 12, 9:36?am, mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? > > Regards, > mk You might find a tool like VirtualEnv (http://pypi.python.org/pypi/ virtualenv/1.3.2) useful. It allows you to create a localized sandbox such that you don't stomp all over your system installation or require elevated privileges. It's good for development or toying with different eggs. When you're done, simply blow away the environment. I've used it for just about everything over the past few months, it's a wonderful tool. Jeff From mauriceling at gmail.com Mon Jan 12 19:47:34 2009 From: mauriceling at gmail.com (mauriceling@acm.org) Date: Mon, 12 Jan 2009 16:47:34 -0800 (PST) Subject: [ANN] The Python Papers Volume 3 Issue 3 Message-ID: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> Hi everyone First of all, let me apologize for the delay of this issue of TPP. I understand that all of you had been anxiously waiting and I do sincerely apologize that Christmas and New Year celebrations are taking a toll on my time. Finally, here it is... Volume 3 Issue 3... And we are THIRD year in business. As usual, the issue can be found at http://ojs.pythonpapers.org/index.php/tpp/issue/current The 1-PDF per issue will be released shortly. Let me also take this opportunity to show our deep felt appreciation to all our supporters/readers and contributors. Without you, we will not have our day to serve the community. At this moment, I will also like to announce our new publication schedule - there will not be any!!! Oppss, that did not come out right... What I am trying to say is that from Volume 4 Issue 1 onwards, we will adopt the "fast publishing" method that many journals are using. We will be releasing each article out to the public as they are being accepted but each issue will be delimited by our usual ?issue release? date. The ?issue release? date is then our cutoff deadline to prepare the 1-PDF per issue file. This means that we will be serving new articles to everyone much faster than now and there will not be anymore meaningful publication schedules. Hence, let's gear up to another year of exciting Python development and a recovering economy. Happy reading Maurice Ling Co-EIC, The Python Papers Anthology From sjmachin at lexicon.net Mon Jan 12 19:55:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 16:55:21 -0800 (PST) Subject: read a password protected xls file References: <567034d3-32b7-4954-a3ce-fae716159ded@k1g2000prb.googlegroups.com> Message-ID: <30a129df-9800-4896-ba2b-80838d94fb01@i18g2000prf.googlegroups.com> On Jan 13, 3:35?am, thomas.steffe... at googlemail.com wrote: > Hello, > how can I read (and parse) a password protected xls file, perhaps with > the package xlrd? > Thanks for your hints, Thomas Perhaps not with xlrd. google("xlrd"); *first* hit displayed: """ Lingfo - xlrd extension 11 Jun 2007 ... Exclusions: xlrd will not attempt to decode password- protected (encrypted) files . Otherwise, it will safely and reliably ignore any of these ... www.lexicon.net/sjmachin/xlrd.htm - 15k - Cached - Similar pages - """ You'll need a Windows box with Excel installed. Get the package described here: http://wiki.python.org/moin/Win32All Install it, do the "makepy" thing [see the docs] to link with the Excel COM routines. Ask questions on the mailing list described on http://mail.python.org/mailman/listinfo/python-win32 Sample code: import sys import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") print "Excel library version:", xlApp.Version filename, password = sys.argv[1:3] # filename should be absolute path e.g. r'C:\myfiles\foo.xls' xlwb = xlApp.Workbooks.Open(filename, Password=password) # xlwb = xlApp.Workbooks.Open(filename) """ From the MS VBA Help for Excel 2003: Password Optional Variant. A string that contains the password required to open a protected workbook. If this argument is omitted and the workbook requires a password, the user is prompted for the password. """ print repr(xlwb) print xlwb.FullName xlws = xlwb.Sheets(1) # counts from 1, not from 0 print repr(xlws) print xlws.Name print xlws.Cells(1, 1) # that's A1 HTH, John From rdcollum at gmail.com Mon Jan 12 20:13:04 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 17:13:04 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: <32699b3e-9532-4d62-a459-1c6c2ffd59a4@w1g2000prk.googlegroups.com> On Jan 12, 5:58?pm, James Stroud wrote: > James Stroud wrote: > > tk.tk.call('bind', str(lb), '', "break") > > Which is equivalent to > > lb.bind('', "break") > > But I checked and overriding the default behavior of Listbox does not > work (tk.tk.call('bind', "Listbox", '', "break")). > > So I would subclass Listbox and do the bindings in the __init__: > > class MyListbox(Listbox): > ? ?def __init__(self, *args, **kwargs): > ? ? ?Listbox.__init__(self, *args, **kwargs) > ? ? ?self.bind('', "break") > > James You sir are awesome. Thank you so much. I've so far been really good at troubleshooting Tkinter, the library has really melded with my thinking naturally since I started using Python on a regular basis a year ago. I had mixed feelings about asking for help on this because I wanted so badly to figure it out myself but I became so exasperated especially after combing through the TCL source to no affect. Now that you've given me the correct solution it seems like the Leave event should have been a natural binding for me to break in all my fiddling. Ah well, it's a lesson I won't forget thanks to you. Thanks so much again, you're help is invaluable. =D Roger. From Russ.Paielli at gmail.com Mon Jan 12 20:48:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 12 Jan 2009 17:48:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: On Jan 12, 3:34 pm, Paul Rubin wrote: > r writes: > > Python and Ruby. Ruby only exists in this world because of the things > > it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. > > > Python wins hands down, WHY? you ask. Well i could list a thousand > > reasons why but i will only cover a few. > > > 1.) read-ability > > 2.) ... > > I could keep going for days and days. Python is hands down the best > > thing that ever happened to the world of programming. Sure it could > > use a few improvements, nothing and nobody is perfect. But can any > > language stand toe to toe with Python? HELL NO! > > Those things on your list are all nice, but I think Python has > considerable room for improvement in several areas: > > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) > > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. > > 3) Data encapsulation, the subject of most of this thread. > > 4) Static analysis. It would be great if there were a much more > powerful Pylint that could do ML-like type inference among other > things. You could still program in a dynamic, heterogeneous style if > you wanted to, but Pylint would complain about it unless you supplied > some annotations to tell it where the dynamism was and how to separate > it from the rest of the program. This is consistent with Python's > "consenting adults" principle: if consenting adults want to > participate in a BDSM scene, they should be allowed to. There would > probably have to be some new language features to assist in writing > typefully. Python 3.0 has some gestures in this direction but they > are not yet fully formed. > > I believe that the PyPy project is developing the above areas in ways > CPython really could not. While we are now committed to Python 3.0 > being a CPython revision that makes some minor (and in my view > somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 > will be based on PyPy and have more substantial differences. Thanks for that nice appraisal. I agree completely. I've suggested before here (as have others) that some sort of basic data encapsulation would be nice, but many Python users don't seem to want anything to do with it. Also, static analysis would be very desirable for my purposes. I would be more than happy to declare types if someone else would write an advanced static analyser that could make use of the type information and formally check the code for correctness. That has been done for other languages such as Java and Ada, and it can be very useful for safety-critical and mission-critical software. (I am currently developing a research prototype of safety-critical software.) I started looking at Scala a while back. It is has many nice features. It seamlessly combines object orientation with advanced functional programming. It is statically typed, but the types often do not need to be explicitly declared. It is fully "compatible" with Java, but (like Python) it is much less verbose and more elegant, typically requiring less (in some cases, much less) than half the lines of code for a given task. But I am reluctant to use Scala for several reasons. For example, it doesn't have "continue" and "break." The Scala folks claim they are unnecessary, but they are sure handy sometimes. Maybe my style is bad, but I use continue and break a lot, particularly continue. Getting by without them could be hard. The other thing is that Scala has no default arguments and no argument passing by keyword. Those are a couple of my favorite Python features. So I'm basically screwed. From jeff at jmcneil.net Mon Jan 12 21:02:04 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 12 Jan 2009 18:02:04 -0800 (PST) Subject: Simple CGI-XMLRPC failure References: Message-ID: On Jan 12, 12:40?pm, "Mike MacHenry" wrote: > I am having a difficult time understanding why my very simple > CGI-XMLRPC test isn't working. I created a server to export two > functions, the built-in function "pow" and my own identity function > "i". I run a script to call both of them and the "pow" work fine but > the "i" gives me an error that says my XMLRPC server doesn't support > than name. Here is the code for both files and the output: > > #!/usr/bin/env python > #This file is /usr/lib/cgi-bin/roundwarerpc.py > from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > def i(x): > ? ? ? ? return x > server = CGIXMLRPCRequestHandler() > server.register_function(pow) > server.register_function(i) > server.handle_request() > > #!/usr/bin/env python > #This file is ~/test.py > import xmlrpclib > server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > print server.pow(2,3) > print server.i(10) > > #This is the STDOUT and STDERR when running ~/test.py > dskippy at dskippy-laptop:$ python test.py 8 > Traceback (most recent call last): > ? File "test.py", line 4, in > ? ? print server.test(10) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > ? ? return self.__send(self.__name, args) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > ? ? verbose=self.__verbose > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > ? ? return self._parse_response(h.getfile(), sock) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > ? ? return u.close() > ? File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > ? ? raise Fault(**self._stack[0]) > xmlrpclib.Fault: :method "i" > is not supported'> > > Does anyone know what might be wrong with this? > > Thanks for the help, > -mike > > p.s. > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Server version Apache/2.2.8 (Ubuntu) > Server built: Jun 25 2008 13:54:13 I copied your code verbatim and I don't have any issues with it at all. Same version of Python, same version of Apache. In SimpleXMLRPCServer.py, register_function adds directly to a self.funcs dictionary, so an instance variable of the same name shouldn't hurt anything. That exception is only raised when a self.funcs lookup raises a KeyError unless you're registering an instance. From steve at holdenweb.com Mon Jan 12 21:14:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:14:28 -0500 Subject: redirecting stderr back.. In-Reply-To: References: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Message-ID: ?????? ??????????? wrote: > >> Hi All, >> >> Can someone tell me how to redirect stderr back to the console once >> you've moved it? >> >> import os,sys >> se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) >> sys.stderr.write("Foobar\n") >> Foobar >> os.dup2(se, 2) > > why not os.dup2(2, 10) and then later os.dup2(10, 2) > I'd have thought it would be necessary to do something like that in the general case to ensure that the original standard error remained open. os.dup2 will close the original file unless it's still open on another descriptor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 21:16:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:16:24 -0500 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> References: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> Message-ID: W. eWatson wrote: > John Machin wrote: >> On Jan 12, 9:16 pm, "W. eWatson" wrote: >>> John Machin wrote: >>>> On Jan 12, 2:00 pm, "W. eWatson" wrote: >>>>> I installed "Python" 2.5 a few months ago with IDLE, and decided >>>>> I'd like to >>>>> try windowpy from ActiveState. Is having both of these installed >>>>> going to >>>>> cause me trouble? >>>> What is "windowpy from ActiveState"? If you mean you wanted to try the >>>> PythonWin IDE instead of IDLE, all you needed to do was go to >>>> http://sourceforge.net/projects/pywin32/hit the big download button >>>> and make sure you get the 2.5 version (it's the default atm) and >>>> install it. >>> Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. >>> >>> Is it possible to just disable the vanilla (IDLE) version? I may want to >>> switch between the two. Most users of the program I'm about to modify >>> use >>> the vanilla version. At some point, I may want to go back to it to >>> verify >>> that in their world all is OK. >> >> I'll try again. All you need is (a) the official distribution of >> Python 2.5 for Windows from http://www.python.org (b) the pywin32 >> package from the URL I gave you. Install both. Click on Start / All >> Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ >> or your users can use IDLE or PythonWin, only one copy of Python, no >> conflicts. Why do you think you need to "disable" IDLE? Just don't use >> it. >> > Once upon a time, six months ago, I asked a similar question and the > answer was more complex. I decided to put this off until I truly needed it. > > Even better than Start, for me, is that I can choose PythonWin or IDLE > from the right-click menu which I want. I do see a choice there of Open > With-> Python. I can see it executed properly, but which 2.5 did it use? > Both IDLE and PythonWin use the same interpreter - neither of them carry their own, and there's only one Python 2.5 available on your system. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kj7ny at nakore.com Mon Jan 12 21:19:29 2009 From: kj7ny at nakore.com (kj7ny) Date: Mon, 12 Jan 2009 18:19:29 -0800 (PST) Subject: Scheduled Tasks - SetFlags Message-ID: <88f5dbd9-ffa8-4498-9635-bfba8bdd1193@i18g2000prf.googlegroups.com> How do I enable/disable a scheduled task using Python? I can get to a task: self.ts=pythoncom.CoCreateInstance (taskscheduler.CLSID_CTaskScheduler,None,pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler) self.ts.SetTargetComputer(u'\\\\SomeServer') self.tasks=self.ts.Enum() for task in self.tasks: self.t=self.ts.Activate(task) if self.t.GetAccountInformation().lower().find('SomeUser') >=0: print self.t.GetFlags() I can find if a task is enabled or not and toggle it: disabled=self.t.GetFlags() & taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED print 'Originally Disabled: %s'%(disabled,) if disabled: self.t.SetFlags(self.t.GetFlags() & ~taskscheduler.TASK_FLAG_DISABLED) else: self.t.SetFlags(self.t.GetFlags() | taskscheduler.TASK_FLAG_DISABLED) disabled=self.t.GetFlags() & taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED print 'Recheck Disabled: %s'%(disabled,) ... "Recheck Disabled" shows that the value "says" it has been disabled. The problem is that if I run it again and again, "Originally Disabled" is always the same. In other words, "Recheck Disabled" does NOT stick. It's like I'm missing a .commit() For example: First run ... 8388 Originally Disabled: True Recheck Disabled: False Second run ... 8388 Originally Disabled: True Recheck Disabled: False How do I disable and enable a scheduled task in Windows using python? From steve at holdenweb.com Mon Jan 12 21:26:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:26:27 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: sturlamolden wrote: > On Jan 12, 1:52 pm, Sion Arrowsmith > wrote: > >> And today's moral is: try it before posting. Yeah, I can map a 2GB >> file no problem, complete with associated 2GB+ allocated VM. The >> addressing is clearly not working how I was expecting it too. > > The virtual memory space of a 32 bit process is 4 GB. > I believe, though, that in some environments 2GB of that is mapped onto the operating system, to allow system calls to access OS memory structures without any VM remapping being required - see http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx. Things have, however, improved if we are to believe what we read in http://www.tenouk.com/WinVirtualAddressSpace.html The very idea of mapping part of a process's virtual address space onto an area in which "low-level system code resides, so writing to this region may corrupt the system, with potentially catastrophic consequences" seems to be asking for trouble to me. It's surprising things used to don't go wrong with Windows all the time, really. Oh, wait a minute, they did, didn't they? Still do for that matter ... getting-sicker-of-vista-by-the-minute-ly yr's - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 21:29:15 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:29:15 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: sturlamolden wrote: > On Jan 12, 1:52 pm, Sion Arrowsmith > wrote: > >> And today's moral is: try it before posting. Yeah, I can map a 2GB >> file no problem, complete with associated 2GB+ allocated VM. The >> addressing is clearly not working how I was expecting it too. > > The virtual memory space of a 32 bit process is 4 GB. > After my last post I should also point out a) That was specific to 32-bit processes, and b) http://regions.cmg.org/regions/mcmg/Virtual%20memory%20constraints%20in%2032bit%20Windows.pdf describes the situation better, and outliones some steps you can take to get relief. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rt8396 at gmail.com Mon Jan 12 22:33:11 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 19:33:11 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <38c9a46b-38b4-4529-a244-c7b6bbe5040d@e6g2000vbe.googlegroups.com> On Jan 12, 5:34?pm, Paul Rubin wrote: > r writes: > > Python and Ruby. Ruby only exists in this world because of the things > > it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. ?It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. There exists in the world of very-high-level languages only two big players -- Python and Ruby. The only reason Ruby even exist is because of what Mats stole from Python. Ruby is a corrupting and hideous language, that will ruin all future "scripters" with it's abominations of coding styles. Ruby is basically Perl's "Mini-Me". A small but deadly form of viral infection that will plague us all for many years to come with unreadable, unmaintainable code! I lament every day the creation of Ruby language. Ruby took the only good things it possess from Python. A little History Lesson: Python came into being around 1991 by a computer science genius named "Guido van Rossum". This man is truly a man before his time. Python revolutionized the world of programming and exposed the other languages for what they are. Archaic, and redundant pieces of petrified dino dookie. Python promotes good coding styles by indentation(ruby stole that) Python's syntax is clear, and choice of keywords is perfect(ruby stole some of that too). Python allows for true OOP and true procedural(ruby tried to steal that but failed miserably) I like to think of Python as simplistic programming elegance. No other high level language can compete with Python, so what did Ruby DEV do? They stole from Python, thats what! And they did not bother to mention this little tidbit of info to new recruits on their website!Tthey act as if Ruby were here first. And pay no respect to the path Python forged. Ruby owes it's very existence to Python! I will never get over the use of "end". Why on GODS green earth would you use indentation AND the "end" statement? That's completely redundant. That would be the same as using two periods at the end of a sentence.. Complete monkey logic! Python is better, but we must stay alert and not fall asleep at the wheel. I think Python DEV has good intention, but they do not realize the battle that lay ahead. We must fight to get Python in every API we can. We must stay on our toes and not let Ruby one-up us! I do not want to see Python go down the evolutionary toilet! Lets send Ruby to programming HELL! From philip at semanchuk.com Mon Jan 12 22:33:16 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 12 Jan 2009 22:33:16 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: On Jan 12, 2009, at 6:48 PM, ajaksu wrote: > On Jan 11, 11:59 pm, "James Mills" > wrote: >> Hey all, >> >> The following fails for me: >> >>>>> from urllib2 import urlopen >>>>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>> ") >> >> Traceback (most recent call last): > [...] >> Any helpful ideas ? > > Maybe raise a real bug @ bugs.python.org instead of just mentioning it > like I did: http://bugs.python.org/msg77889 > > I think at least some sites would be willing to add the new UA to > their whitelists. I don't think I understand you clearly. Whether or not Google et al whitelist the Python UA isn't a Python issue, is it? From rob.clewley at gmail.com Mon Jan 12 22:41:00 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Mon, 12 Jan 2009 22:41:00 -0500 Subject: Unexpected behavior with dictionary keys containment and a user-defined class Message-ID: Hi, the short version of my question is: when is a dictionary's __contains__ method behavior different to using the 'in' idiom? (because I have an example of a difference in my code). Longer version: I have a user-defined class with a few overrides of special methods, particularly __eq__ and __ne__. I also have a dictionary keyed by instances of these classes, and I'm confused about the unexpected behavior trying to test whether an instance is in the dictionary's keys. The instance is i and the dictionary is d. I have been using the idiom i in d which I understood to be the pythonic way to test the keys, but it doesn't work. However, when I debug my code I see the instance in the list of keys, and in fact i in d.keys() and d.keys()[10] == i both return True. But d.__contains__(i) d.has_key(i) d.keys()[10] is i return False. I put a print statement in my class's __eq__ method and it is being called. It tests equality of some of my class instance's attributes. I didn't realize there was any situation where you could expect different results from i in d versus i in d.keys() -- am I misunderstanding something? I'm not sure what other details to provide! Thanks a lot, Rob From jstroud at mbi.ucla.edu Mon Jan 12 22:56:19 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 19:56:19 -0800 Subject: Unexpected behavior with dictionary keys containment and a user-defined class In-Reply-To: References: Message-ID: Rob Clewley wrote: > Hi, the short version of my question is: when is a dictionary's > __contains__ method behavior different to using the 'in' idiom? > (because I have an example of a difference in my code). Never. > Longer version: I have a user-defined class with a few overrides of > special methods, particularly __eq__ and __ne__. I also have a > dictionary keyed by instances of these classes, and I'm confused about > the unexpected behavior trying to test whether an instance is in the > dictionary's keys. The instance is i and the dictionary is d. I have > been using the idiom > > i in d > > which I understood to be the pythonic way to test the keys, but it > doesn't work. However, when I debug my code I see the instance in the > list of keys, and in fact > > i in d.keys() and d.keys()[10] == i > > both return True. But > > d.__contains__(i) > d.has_key(i) > d.keys()[10] is i > > return False. I put a print statement in my class's __eq__ method and > it is being called. It tests equality of some of my class instance's > attributes. I didn't realize there was any situation where you could > expect different results from i in d versus i in d.keys() -- > am I misunderstanding something? Well, the only conclusion is that dict uses the hash of an object to test containment while lists use id. James From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 22:58:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 03:58:40 GMT Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > thanks for your replies -- a few clarifications and questions. the > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >>= c and b <= d. Note that I am not looking for intervals that > overlap... this is why interval trees seem to me to not be relevant, as > the overlapping interval problem is way harder than what I am trying to > do. Please correct me if I'm wrong on this... To test for contained intervals: a >= c and b <= d To test for overlapping intervals: not (b < c or a > d) Not exactly what I would call "way harder". -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 23:05:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 04:05:57 GMT Subject: Unexpected behavior with dictionary keys containment and a user-defined class References: Message-ID: On Mon, 12 Jan 2009 22:41:00 -0500, Rob Clewley wrote: > Hi, the short version of my question is: when is a dictionary's > __contains__ method behavior different to using the 'in' idiom? (because > I have an example of a difference in my code). [...] > i in d.keys() and d.keys()[10] == i > > both return True. But > > d.__contains__(i) > d.has_key(i) > d.keys()[10] is i The instance you are testing for isn't the same instance as the one in the dictionary. It might be *equal*, but it isn't identical, and by default, hashing of classes goes by identity. You need to give your class a hash function so that whenever x==y hash(x)==hash(y) as well. That means you need to over-ride __hash__(self) in the class. > return False. I put a print statement in my class's __eq__ method and it > is being called. It tests equality of some of my class instance's > attributes. I didn't realize there was any situation where you could > expect different results from i in d versus i in d.keys() -- am > I misunderstanding something? i in d.keys() does an item-by-item equality test, returning the first time i is equal to an item. i in d hashes i, then looks up a table to see whether there is an item in that spot. If there is, it compares that item to i for equality. -- Steven From rob.clewley at gmail.com Mon Jan 12 23:13:49 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Mon, 12 Jan 2009 23:13:49 -0500 Subject: Unexpected behavior with dictionary keys containment and a user-defined class In-Reply-To: References: Message-ID: >> Hi, the short version of my question is: when is a dictionary's >> __contains__ method behavior different to using the 'in' idiom? >> (because I have an example of a difference in my code). > > Never. Yes, sorry, I managed to summarize the long version incorrectly :) > Well, the only conclusion is that dict uses the hash of an object to test > containment while lists use id. Great, thanks. I think a copy of my object has been made so that it doesn't hash to the same thing. I'll write a __hash__ as suggested in the other post. I forgot all about dictionary hashing for some reason... -Rob From http Mon Jan 12 23:44:16 2009 From: http (Paul Rubin) Date: 12 Jan 2009 20:44:16 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <38c9a46b-38b4-4529-a244-c7b6bbe5040d@e6g2000vbe.googlegroups.com> Message-ID: <7xocyblsrj.fsf@ruckus.brouhaha.com> r writes: > Python revolutionized the world of programming and exposed the other > languages for what they are. Archaic, and redundant pieces of > petrified dino dookie. ... We must fight to get Python in every API we > can. We must stay on our toes and not let Ruby one-up us! I do not > want to see Python go down the evolutionary toilet! Lets send Ruby to > programming HELL! Heh, I have to admire your enthusiasm. That testimonial is truly suitable for framing ;-) From perfreem at yahoo.com Mon Jan 12 23:55:36 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 20:55:36 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 10:58?pm, Steven D'Aprano wrote: > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > thanks for your replies -- a few clarifications and questions. the > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > >>= c and b <= d. Note that I am not looking for intervals that > > overlap... this is why interval trees seem to me to not be relevant, as > > the overlapping interval problem is way harder than what I am trying to > > do. Please correct me if I'm wrong on this... > > To test for contained intervals: > a >= c and b <= d > > To test for overlapping intervals: > > not (b < c or a > d) > > Not exactly what I would call "way harder". > > -- > Steven hi Steven, i found an implementation (which is exactly how i'd write it based on the description) here: http://hackmap.blogspot.com/2008/11/python-interval-tree.html when i use this however, it comes out either significantly slower or equal to a naive search. my naive search just iterates through a smallish list of intervals and for each one says whether they overlap with each of a large set of intervals. here is the exact code i used to make the comparison, plus the code at the link i have above: class Interval(): def __init__(self, start, stop): self.start = start self.stop = stop import random import time num_ints = 30000 init_intervals = [] for n in range(0, num_ints): start = int(round(random.random() *1000)) end = start + int(round(random.random()*500+1)) init_intervals.append(Interval(start, end)) num_ranges = 900 ranges = [] for n in range(0, num_ranges): start = int(round(random.random() *1000)) end = start + int(round(random.random()*500+1)) ranges.append((start, end)) #print init_intervals tree = IntervalTree(init_intervals) t1 = time.time() for r in ranges: tree.find(r[0], r[1]) t2 = time.time() print "interval tree: %.3f" %((t2-t1)*1000.0) t1 = time.time() for r in ranges: naive_find(init_intervals, r[0], r[1]) t2 = time.time() print "brute force: %.3f" %((t2-t1)*1000.0) on one run, i get: interval tree: 8584.682 brute force: 8201.644 is there anything wrong with this implementation? it seems very right to me but i am no expert. any help on this would be relly helpful. From grante at visi.com Mon Jan 12 23:55:41 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 12 Jan 2009 22:55:41 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: <0qOdnR88rIFQg_HUnZ2dnUVZ_o7inZ2d@posted.usinternet> On 2009-01-13, Steve Holden wrote: > sturlamolden wrote: >> On Jan 12, 1:52 pm, Sion Arrowsmith >> wrote: >> >>> And today's moral is: try it before posting. Yeah, I can map a 2GB >>> file no problem, complete with associated 2GB+ allocated VM. The >>> addressing is clearly not working how I was expecting it too. >> >> The virtual memory space of a 32 bit process is 4 GB. >> > I believe, though, that in some environments 2GB of that is mapped onto > the operating system, to allow system calls to access OS memory > structures without any VM remapping being required IIRC, in Linux the default for the past several years has been 3GB user, 1GB kernel. But, there are kernel configuration options to enable different configurations. > getting-sicker-of-vista-by-the-minute-ly yr's - steve Haven't had to touch Vista yet -- I'm annoyed enough by XP. -- Grant From perfreem at yahoo.com Mon Jan 12 23:58:03 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 20:58:03 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> i forgot to add, my naive_find is: def naive_find(intervals, start, stop): results = [] for interval in intervals: if interval.start >= start and interval.stop <= stop: results.append(interval) return results On Jan 12, 11:55?pm, Per Freem wrote: > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > thanks for your replies -- a few clarifications and questions. the > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > >>= c and b <= d. Note that I am not looking for intervals that > > > overlap... this is why interval trees seem to me to not be relevant, as > > > the overlapping interval problem is way harder than what I am trying to > > > do. Please correct me if I'm wrong on this... > > > To test for contained intervals: > > a >= c and b <= d > > > To test for overlapping intervals: > > > not (b < c or a > d) > > > Not exactly what I would call "way harder". > > > -- > > Steven > > hi Steven, > > i found an implementation (which is exactly how i'd write it based on > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. > > here is the exact code i used to make the comparison, plus the code at > the link i have above: > > class Interval(): > ? ? def __init__(self, start, stop): > ? ? ? ? self.start = start > ? ? ? ? self.stop = stop > > import random > import time > num_ints = 30000 > init_intervals = [] > for n in range(0, > num_ints): > ? ? start = int(round(random.random() > *1000)) > ? ? end = start + int(round(random.random()*500+1)) > ? ? init_intervals.append(Interval(start, end)) > num_ranges = 900 > ranges = [] > for n in range(0, num_ranges): > ? start = int(round(random.random() > *1000)) > ? end = start + int(round(random.random()*500+1)) > ? ranges.append((start, end)) > #print init_intervals > tree = IntervalTree(init_intervals) > t1 = time.time() > for r in ranges: > ? tree.find(r[0], r[1]) > t2 = time.time() > print "interval tree: %.3f" %((t2-t1)*1000.0) > t1 = time.time() > for r in ranges: > ? naive_find(init_intervals, r[0], r[1]) > t2 = time.time() > print "brute force: %.3f" %((t2-t1)*1000.0) > > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 > > is there anything wrong with this implementation? it seems very right > to me but i am no expert. any help on this would be relly helpful. From imageguy1206 at gmail.com Tue Jan 13 00:02:08 2009 From: imageguy1206 at gmail.com (imageguy) Date: Mon, 12 Jan 2009 21:02:08 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? Message-ID: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Using py2.5.4 and entering the following lines in IDLE, I don't really understand why I get the result shown in line 8. Note the difference between lines 7 and 10 is that 'else' clause result enclosed in brackets, however, in line 2, both the 'c,d' variables are assign correctly without the brackets being required. Any chance someone could enlighten me on the rules for tuple unpacking as this seems inconsistent. 1) >>> n = None 2) >>> c,d = n if n is not None else 0,0 3) >>> print c,d, type(c), type(d) 4) 0 0 5) >>> n = 22,11 6) >>> print n, type(n) (22, 11) 7) >>> c,d = n if n is not None else 0,0 8) >>> print c,d 9) (22, 11) 0 10) >>> c,d = n if n is not None else (0,0) 11) >>> print c,d 12) 22 11 From imageguy1206 at gmail.com Tue Jan 13 00:08:51 2009 From: imageguy1206 at gmail.com (imageguy) Date: Mon, 12 Jan 2009 21:08:51 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <9ee1d660-2fe4-4ada-ac67-d10580f75633@p36g2000prp.googlegroups.com> > understand why I get the result shown in line 8. >7) >>> c,d = n if n is not None else 0,0 >8) >>> print c,d >9) (22, 11) 0 OOPS sorry that should be line 9. g. From bpederse at gmail.com Tue Jan 13 00:24:45 2009 From: bpederse at gmail.com (brent) Date: Mon, 12 Jan 2009 21:24:45 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 8:55?pm, Per Freem wrote: > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > thanks for your replies -- a few clarifications and questions. the > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > >>= c and b <= d. Note that I am not looking for intervals that > > > overlap... this is why interval trees seem to me to not be relevant, as > > > the overlapping interval problem is way harder than what I am trying to > > > do. Please correct me if I'm wrong on this... > > > To test for contained intervals: > > a >= c and b <= d > > > To test for overlapping intervals: > > > not (b < c or a > d) > > > Not exactly what I would call "way harder". > > > -- > > Steven > > hi Steven, > > i found an implementation (which is exactly how i'd write it based on > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. > > here is the exact code i used to make the comparison, plus the code at > the link i have above: > > class Interval(): > ? ? def __init__(self, start, stop): > ? ? ? ? self.start = start > ? ? ? ? self.stop = stop > > import random > import time > num_ints = 30000 > init_intervals = [] > for n in range(0, > num_ints): > ? ? start = int(round(random.random() > *1000)) > ? ? end = start + int(round(random.random()*500+1)) > ? ? init_intervals.append(Interval(start, end)) > num_ranges = 900 > ranges = [] > for n in range(0, num_ranges): > ? start = int(round(random.random() > *1000)) > ? end = start + int(round(random.random()*500+1)) > ? ranges.append((start, end)) > #print init_intervals > tree = IntervalTree(init_intervals) > t1 = time.time() > for r in ranges: > ? tree.find(r[0], r[1]) > t2 = time.time() > print "interval tree: %.3f" %((t2-t1)*1000.0) > t1 = time.time() > for r in ranges: > ? naive_find(init_intervals, r[0], r[1]) > t2 = time.time() > print "brute force: %.3f" %((t2-t1)*1000.0) > > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 > > is there anything wrong with this implementation? it seems very right > to me but i am no expert. any help on this would be relly helpful. hi, the tree is inefficient when the interval is large. as the size of the interval shrinks to much less than the expanse of the tree, the tree will be faster. changing 500 to 50 in both cases in your script, i get: interval tree: 3233.404 brute force: 9807.787 so the tree will work for limited cases. but it's quite simple. check the tree in bx-python: http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/operations/quicksect.py for a more robust implementation. -brentp From perfreem at yahoo.com Tue Jan 13 00:34:42 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 21:34:42 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: hi brent, thanks very much for your informative reply -- didn't realize this about the size of the interval. thanks for the bx-python link. could you (or someone else) explain why the size of the interval makes such a big difference? i don't understand why it affects efficiency so much... thanks. On Jan 13, 12:24?am, brent wrote: > On Jan 12, 8:55?pm, Per Freem wrote: > > > > > On Jan 12, 10:58?pm, Steven D'Aprano > > > wrote: > > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > > thanks for your replies -- a few clarifications and questions. the > > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > > >>= c and b <= d. Note that I am not looking for intervals that > > > > overlap... this is why interval trees seem to me to not be relevant, as > > > > the overlapping interval problem is way harder than what I am trying to > > > > do. Please correct me if I'm wrong on this... > > > > To test for contained intervals: > > > a >= c and b <= d > > > > To test for overlapping intervals: > > > > not (b < c or a > d) > > > > Not exactly what I would call "way harder". > > > > -- > > > Steven > > > hi Steven, > > > i found an implementation (which is exactly how i'd write it based on > > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > > when i use this however, it comes out either significantly slower or > > equal to a naive search. my naive search just iterates through a > > smallish list of intervals and for each one says whether they overlap > > with each of a large set of intervals. > > > here is the exact code i used to make the comparison, plus the code at > > the link i have above: > > > class Interval(): > > ? ? def __init__(self, start, stop): > > ? ? ? ? self.start = start > > ? ? ? ? self.stop = stop > > > import random > > import time > > num_ints = 30000 > > init_intervals = [] > > for n in range(0, > > num_ints): > > ? ? start = int(round(random.random() > > *1000)) > > ? ? end = start + int(round(random.random()*500+1)) > > ? ? init_intervals.append(Interval(start, end)) > > num_ranges = 900 > > ranges = [] > > for n in range(0, num_ranges): > > ? start = int(round(random.random() > > *1000)) > > ? end = start + int(round(random.random()*500+1)) > > ? ranges.append((start, end)) > > #print init_intervals > > tree = IntervalTree(init_intervals) > > t1 = time.time() > > for r in ranges: > > ? tree.find(r[0], r[1]) > > t2 = time.time() > > print "interval tree: %.3f" %((t2-t1)*1000.0) > > t1 = time.time() > > for r in ranges: > > ? naive_find(init_intervals, r[0], r[1]) > > t2 = time.time() > > print "brute force: %.3f" %((t2-t1)*1000.0) > > > on one run, i get: > > interval tree: 8584.682 > > brute force: 8201.644 > > > is there anything wrong with this implementation? it seems very right > > to me but i am no expert. any help on this would be relly helpful. > > hi, the tree is inefficient when the interval is large. as the size of > the interval shrinks to much less than the expanse of the tree, the > tree will be faster. changing 500 to 50 in both cases in your script, > i get: > interval tree: 3233.404 > brute force: 9807.787 > > so the tree will work for limited cases. but it's quite simple. check > the tree in bx-python:http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/opera... > for a more robust implementation. > -brentp From steven at REMOVE.THIS.cybersource.com.au Tue Jan 13 00:47:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 05:47:29 GMT Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Mon, 12 Jan 2009 20:55:36 -0800, Per Freem wrote: > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 Here are three runs on my computer: interval tree: 10132.682 brute force: 12054.988 interval tree: 10355.058 brute force: 12119.227 interval tree: 9975.414 brute force: 12052.174 I find that interval tree is consistently faster than the brute force method, by a factor of at least 16%. I'd expect that benefit to increase dramatically as the number of intervals gets bigger. -- Steven From semanticist at gmail.com Tue Jan 13 01:01:24 2009 From: semanticist at gmail.com (Miles) Date: Tue, 13 Jan 2009 01:01:24 -0500 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > Using py2.5.4 and entering the following lines in IDLE, I don't really > understand why I get the result shown in line 8. > > Note the difference between lines 7 and 10 is that 'else' clause > result enclosed in brackets, however, in line 2, both the 'c,d' > variables are assign correctly without the brackets being required. > > 1) >>> n = None > 2) >>> c,d = n if n is not None else 0,0 > 3) >>> print c,d, type(c), type(d) > 4) 0 0 The ternary expression has higher precedence than the comma, so the actual effect of line 2 (and 8) is: >>> c, d = (n if n is not None else 0), 0 Or written more explicitly: >>> c = n if n is not None else 0 >>> d = 0 So the only correct way to write the expression, for the result you want, is to use your line 10: > 10) >>> c,d = n if n is not None else (0,0) But if you're struggling with the precedence issues, I'd recommend ditching ternary expressions altogether and using full conditional blocks. -Miles From javen72 at gmail.com Tue Jan 13 01:03:35 2009 From: javen72 at gmail.com (javen72 at gmail.com) Date: Mon, 12 Jan 2009 22:03:35 -0800 (PST) Subject: File buffer flush issue in multi-process in Windows Message-ID: <1bbaccea-26f2-4ed6-a61e-4e51eed1de60@h20g2000yqn.googlegroups.com> Hi, I encountered a very strange issue in file flush operation in Windows. Here's the scenario of my application: 1. The main thread of my application will create makefiles sequentially. 2. Once a makefile is generated, launch a new process calling nmake.exe to run it. The main thread then create another makefile until no more makefiles to create. 3. The number of new processes is limited by command line options. My application has been running for almost a year without any problem. But, after I made some changes recently to the content of makefile generated, "nmake.exe" in separate process sometimes complains that the makefile is not found. When I went into the directory, the makefile did exist there. Because I didn't change any thing related to file creation and the new makefiles are a little bit less than before, I guessed that the makefile just created hasn't been flushed to disk because of size change so the new process could not see it in a short time. So I decided add code to force flush file buffer after writing the file content (I didn't flush the file explicitly before). I did it like below: Fd = open(File, "w") Fd.write(Content) Fd.flush() os.fsync(Fd.fileno()) Fd.close() The strangest thing happened. The "makefile" missing happened more frequently than no flush operation. I searched the web but no answer there. Finally I tried to use Windows file API to create the file via pywin32 extension. The problem's gone. import win32file Fd = win32file.CreateFile( File, win32file.GENERIC_WRITE, 0, None, win32file.CREATE_ALWAYS, win32file.FILE_ATTRIBUTE_NORMAL, None ) win32file.WriteFile(Fd, str(Content), None) win32file.FlushFileBuffers(Fd) win32file.CloseHandle(Fd) I tried writing small python extension in C to make use Windows API to create file like above. It also works well, even I removed the FlushFileBuffers() calling. Did anyone encounter such problem before? Did I do something wrong in Python file operation? If not, I believe that there's a bug in Python file buffer mechanism. I'd appreciate any help or hints. Cheers, Javen From javen72 at gmail.com Tue Jan 13 01:06:20 2009 From: javen72 at gmail.com (javen72 at gmail.com) Date: Mon, 12 Jan 2009 22:06:20 -0800 (PST) Subject: File buffer flush issue in multi-process in Windows References: <1bbaccea-26f2-4ed6-a61e-4e51eed1de60@h20g2000yqn.googlegroups.com> Message-ID: <720c31c2-053b-4f70-902c-1202e318aeb2@u14g2000yqg.googlegroups.com> On 1?13?, ??2?03?, jave... at gmail.com wrote: > Hi, > > I encountered a very strange issue in file flush operation in Windows. > Here's the scenario of my application: > > 1. The main thread of my application will create makefiles > sequentially. > 2. Once a makefile is generated, launch a new process calling > nmake.exe to run it. The main thread then create another makefile > until no more makefiles to create. > 3. The number of new processes is limited by command line options. > > My application has been running for almost a year without any problem. > But, after I made some changes recently to the content of makefile > generated, "nmake.exe" in separate process sometimes complains that > the makefile is not found. When I went into the directory, the > makefile did exist there. > > Because I didn't change any thing related to file creation and the new > makefiles are a little bit less than before, I guessed that the > makefile just created hasn't been flushed to disk because of size > change so the new process could not see it in a short time. > > So I decided add code to force flush file buffer after writing the > file content (I didn't flush the file explicitly before). I did it > like below: > > Fd = open(File, "w") > Fd.write(Content) > Fd.flush() > os.fsync(Fd.fileno()) > Fd.close() > > The strangest thing happened. The "makefile" missing happened more > frequently than no flush operation. I searched the web but no answer > there. > > Finally I tried to use Windows file API to create the file via pywin32 > extension. The problem's gone. > > import win32file > Fd = win32file.CreateFile( > File, > win32file.GENERIC_WRITE, > 0, > None, > win32file.CREATE_ALWAYS, > win32file.FILE_ATTRIBUTE_NORMAL, > None > ) > win32file.WriteFile(Fd, str(Content), None) > win32file.FlushFileBuffers(Fd) > win32file.CloseHandle(Fd) > > I tried writing small python extension in C to make use Windows API to > create file like above. It also works well, even I removed the > FlushFileBuffers() calling. > > Did anyone encounter such problem before? Did I do something wrong in > Python file operation? If not, I believe that there's a bug in Python > file buffer mechanism. I'd appreciate any help or hints. > > Cheers, > Javen And the same application has no such problem in Linux. From steve at holdenweb.com Tue Jan 13 01:14:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:14:57 -0500 Subject: BadZipfile "file is not a zip file" In-Reply-To: <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> Message-ID: webcomm wrote: > On Jan 12, 11:53 am, "Chris Mellon" wrote: [file distribution horror story ...] >> It's worth pointing out (although the provider probably doesn't care) >> that this isn't really an XML document and this was a bad way of them >> to distribute the data. If they'd used a correctly formatted XML >> document (with the prelude and everything) with the correct encoding >> information, existing XML parsers should have just Done The Right >> Thing with the data, instead of you needing to know the encoding a >> priori to extract an XML fragment. > > Agreed. I can't say I understand their rationale for doing it this way. Sadly their rationale is irrelevant to the business of making sense of the data, which we all hope you have eventually managed to do. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bpederse at gmail.com Tue Jan 13 01:15:41 2009 From: bpederse at gmail.com (brent) Date: Mon, 12 Jan 2009 22:15:41 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 9:34?pm, Per Freem wrote: > hi brent, thanks very much for your informative reply -- didn't > realize this about the size of the interval. > > thanks for the bx-python link. ?could you (or someone else) explain > why the size of the interval makes such a big difference? i don't > understand why it affects efficiency so much... > > thanks. > > On Jan 13, 12:24?am, brent wrote: > > > On Jan 12, 8:55?pm, Per Freem wrote: > > > > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > > > thanks for your replies -- a few clarifications and questions. the > > > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > > > >>= c and b <= d. Note that I am not looking for intervals that > > > > > overlap... this is why interval trees seem to me to not be relevant, as > > > > > the overlapping interval problem is way harder than what I am trying to > > > > > do. Please correct me if I'm wrong on this... > > > > > To test for contained intervals: > > > > a >= c and b <= d > > > > > To test for overlapping intervals: > > > > > not (b < c or a > d) > > > > > Not exactly what I would call "way harder". > > > > > -- > > > > Steven > > > > hi Steven, > > > > i found an implementation (which is exactly how i'd write it based on > > > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > > > when i use this however, it comes out either significantly slower or > > > equal to a naive search. my naive search just iterates through a > > > smallish list of intervals and for each one says whether they overlap > > > with each of a large set of intervals. > > > > here is the exact code i used to make the comparison, plus the code at > > > the link i have above: > > > > class Interval(): > > > ? ? def __init__(self, start, stop): > > > ? ? ? ? self.start = start > > > ? ? ? ? self.stop = stop > > > > import random > > > import time > > > num_ints = 30000 > > > init_intervals = [] > > > for n in range(0, > > > num_ints): > > > ? ? start = int(round(random.random() > > > *1000)) > > > ? ? end = start + int(round(random.random()*500+1)) > > > ? ? init_intervals.append(Interval(start, end)) > > > num_ranges = 900 > > > ranges = [] > > > for n in range(0, num_ranges): > > > ? start = int(round(random.random() > > > *1000)) > > > ? end = start + int(round(random.random()*500+1)) > > > ? ranges.append((start, end)) > > > #print init_intervals > > > tree = IntervalTree(init_intervals) > > > t1 = time.time() > > > for r in ranges: > > > ? tree.find(r[0], r[1]) > > > t2 = time.time() > > > print "interval tree: %.3f" %((t2-t1)*1000.0) > > > t1 = time.time() > > > for r in ranges: > > > ? naive_find(init_intervals, r[0], r[1]) > > > t2 = time.time() > > > print "brute force: %.3f" %((t2-t1)*1000.0) > > > > on one run, i get: > > > interval tree: 8584.682 > > > brute force: 8201.644 > > > > is there anything wrong with this implementation? it seems very right > > > to me but i am no expert. any help on this would be relly helpful. > > > hi, the tree is inefficient when the interval is large. as the size of > > the interval shrinks to much less than the expanse of the tree, the > > tree will be faster. changing 500 to 50 in both cases in your script, > > i get: > > interval tree: 3233.404 > > brute force: 9807.787 > > > so the tree will work for limited cases. but it's quite simple. check > > the tree in bx-python:http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/opera... > > for a more robust implementation. > > -brentp > > well, i think if your search interval covers the entire span of the tree, you can't do better than just naive search as the tree just adds overhead. as the len of the search interval decreases relative to the span of the tree, the tree performs better. if all the intervals in the tree itself are long and overlapping, that tree just ... ugh ... doesnt work, because it has to do all the extra checks in the find() method anyway. the bx-python tree probably does a better job, but you set up a pretty rough test there. From steve at holdenweb.com Tue Jan 13 01:18:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:18:09 -0500 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: Daniel Fetchinson wrote: >> I need something to connect to a database, preferably mysql, that >> works in python3.0 please. > > And your question is? > > Surely it's fairly obvious that the question is "does such a thing exist, and if so where can I find it?". If that isn't obvious then please continue to lurk until it is. There's enough signal on this channel that we can do without such noise. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From timr at probo.com Tue Jan 13 01:21:08 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 13 Jan 2009 06:21:08 GMT Subject: win32gui References: Message-ID: Gandalf wrote: ? >Hi, everyone >I'm searching the win32gui lib to find a way to get the text under the >user cursor. >so far I managed to find only the controller ID which under the cursor >this way > >cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) > >their is function called GetWindowText I tried to use but it doesn't >work in most of the time > >someone know a way to do this? Did you not like the reply I gave you the first time you asked this question? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at holdenweb.com Tue Jan 13 01:22:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:22:12 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: Philip Semanchuk wrote: > > On Jan 12, 2009, at 6:48 PM, ajaksu wrote: > >> On Jan 11, 11:59 pm, "James Mills" >> wrote: >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>>>>> >>> >>> Traceback (most recent call last): >> [...] >>> Any helpful ideas ? >> >> Maybe raise a real bug @ bugs.python.org instead of just mentioning it >> like I did: http://bugs.python.org/msg77889 >> >> I think at least some sites would be willing to add the new UA to >> their whitelists. > > I don't think I understand you clearly. Whether or not Google et al > whitelist the Python UA isn't a Python issue, is it? > I'd say it's an issue relevant to Python users, which woudl seem to put it pretty much in the mainstream for c.l.py - especially as the code causing concern was written in Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:29:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:29:55 -0500 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: Christian Heimes wrote: >>> Perhaps you also like to hear from a developer who has worked on Python >>> 3.0 itself and who has done lots of work with internationalized >>> applications. If you want to get it right you must >>> >>> * decode incoming text data to unicode as early as possible >>> * use unicode for all internal text data >>> * encode outgoing unicode as late as possible. >>> >>> where incoming data is read from the file system, database, network etc. >>> >>> This rule applies not only to Python 3.0 but to *any* application >>> written in *any* languate. >> The above is a story with which I'm quite familiar. However it is >> *not* the issue!! The issue is why would anyone propose changing a >> string constant "foo" in working 2.x code to u"foo"? > > Do I really have to repeat "use unicode for all internal text data"? > You don't have to, but apparently that wasn't sufficient to stop you. > "foo" and u"foo" are two totally different things. The former is a byte > sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just > happens that "foo" and u"foo" are equal in Python 2.x because > "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is > unequal to "foo". > People, it's really helpful if rather than just disagreeing we make efforts to isolate the sources of the disagreement then work towards common understanding. Otherwise we each end up shouting at each other from our individual islands of knowledge. For a *really*N good example of this, though one which does (eventually, and glacially) seem to be moving towards convergence, see the "Why cannot assign to function call" thread. Don't try to prove yourself right, or the other person wrong: instead seek common understanding of the issues, and resolutions thereof. Christian: please don't regard this post as aimed specifically at your behavior, which it isn't. It's a general (and hopefully not entirely useless) attempt to improve the signal-to-noise ratio. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:31:54 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:31:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> Message-ID: r wrote: > [stevie] > On the other hand... Bruno's question is unfair. It is perfectly > reasonable to (hypothetically) consider Python to be the best > *existing* > language while still wanting it to be improved (for some definition > of > improvement). Just because somebody has criticisms of Python, or a > wish- > list of features, doesn't mean they hate the language. > [/stevie] > > WOW Steven, i am very impressed. That's the first thing you have said > in a very long time that i totally agree with! Keep this up and i may > put you back on my Python Brethren list :) What can one do to get *off* it? ;-) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:33:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:33:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> Message-ID: bieffe62 at gmail.com wrote: > On 12 Gen, 14:45, Paul Rubin wrote: >> bieff... at gmail.com writes: >>>> class Foo (DynamicAttributes, object): pass >>> You cannot do that, but you can establish a fixed set of attributes by >>> defining the __slot__ class variable. >> That is not what __slot__ is for. > > > Really? It seems to work: > [...] So does using a butt-plug to seal a bottle of wine, but that's still not what it's for. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:36:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:36:27 -0500 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: Miles wrote: > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: >> Using py2.5.4 and entering the following lines in IDLE, I don't really >> understand why I get the result shown in line 8. >> >> Note the difference between lines 7 and 10 is that 'else' clause >> result enclosed in brackets, however, in line 2, both the 'c,d' >> variables are assign correctly without the brackets being required. >> >> 1) >>> n = None >> 2) >>> c,d = n if n is not None else 0,0 >> 3) >>> print c,d, type(c), type(d) >> 4) 0 0 > > The ternary expression has higher precedence than the comma, so the > actual effect of line 2 (and 8) is: > >>>> c, d = (n if n is not None else 0), 0 > > Or written more explicitly: > >>>> c = n if n is not None else 0 >>>> d = 0 > > So the only correct way to write the expression, for the result you > want, is to use your line 10: > >> 10) >>> c,d = n if n is not None else (0,0) > > But if you're struggling with the precedence issues, I'd recommend > ditching ternary expressions altogether and using full conditional > blocks. > Yet another great example of why Guido was right to resist putting conditional expressions into Python for so long (and wrong to succumb to the demand). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:37:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:37:59 -0500 Subject: [ANN] The Python Papers Volume 3 Issue 3 In-Reply-To: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> References: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> Message-ID: <496C36C7.8020104@holdenweb.com> mauriceling at acm.org wrote: > Hi everyone > > First of all, let me apologize for the delay of this issue of TPP. I > understand that all of you had been anxiously waiting and I do > sincerely apologize that Christmas and New Year celebrations are > taking a toll on my time. > > Finally, here it is... Volume 3 Issue 3... And we are THIRD year in > business. > > As usual, the issue can be found at http://ojs.pythonpapers.org/index.php/tpp/issue/current > > The 1-PDF per issue will be released shortly. > > Let me also take this opportunity to show our deep felt appreciation > to all our supporters/readers and contributors. Without you, we will > not have our day to serve the community. > > At this moment, I will also like to announce our new publication > schedule - there will not be any!!! Oppss, that did not come out > right... > > What I am trying to say is that from Volume 4 Issue 1 onwards, we will > adopt the "fast publishing" method that many journals are using. We > will be releasing each article out to the public as they are being > accepted but each issue will be delimited by our usual ?issue release? > date. The ?issue release? date is then our cutoff deadline to prepare > the 1-PDF per issue file. This means that we will be serving new > articles to everyone much faster than now and there will not be > anymore meaningful publication schedules. > > Hence, let's gear up to another year of exciting Python development > and a recovering economy. > What we might term the "on-supply" publishing model? Good luck for a great third year! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:51:04 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:51:04 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > r writes: >> Python and Ruby. Ruby only exists in this world because of the things >> it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. > >> Python wins hands down, WHY? you ask. Well i could list a thousand >> reasons why but i will only cover a few. >> >> 1.) read-ability >> 2.) ... >> I could keep going for days and days. Python is hands down the best >> thing that ever happened to the world of programming. Sure it could >> use a few improvements, nothing and nobody is perfect. But can any >> language stand toe to toe with Python? HELL NO! > > Those things on your list are all nice, but I think Python has > considerable room for improvement in several areas: > > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) > Of course the tradition answer to this question is "reframe your algorithm in multi-process form". My response to that tends to be "Isn't that what computers are for?" > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. > Speed, of course, isn't everything. But it would be nice to accommodate those problem classes where it *is* significant. > 3) Data encapsulation, the subject of most of this thread. > There's always more to do there, though I fell the thread started out based on a misapprehension. > 4) Static analysis. It would be great if there were a much more > powerful Pylint that could do ML-like type inference among other > things. You could still program in a dynamic, heterogeneous style if > you wanted to, but Pylint would complain about it unless you supplied > some annotations to tell it where the dynamism was and how to separate > it from the rest of the program. This is consistent with Python's > "consenting adults" principle: if consenting adults want to > participate in a BDSM scene, they should be allowed to. There would > probably have to be some new language features to assist in writing > typefully. Python 3.0 has some gestures in this direction but they > are not yet fully formed. > That part of Python 3'sw design is, of course, totally intentional. I believe Guido is on record as saying that he hopes the uses for the annotation feature can be concretized (is that a word) down the line when good use cases have emerged. And I believe they will (as you suggest to be desirable) always be optional - almost like a pragma in other languages. > I believe that the PyPy project is developing the above areas in ways > CPython really could not. While we are now committed to Python 3.0 > being a CPython revision that makes some minor (and in my view > somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 > will be based on PyPy and have more substantial differences. I have to confess that I occasionally find some of your posts a bit pedantic and obscurantist. Just the same I appreciate your continued presence on the list, because no matter how unreasonable I feel what you says to be, when I examine it I always find your opinions well expressed and well thought-out. Sometimes I just want to shout "be quiet, Python is just fine the way it is", but alas your objections are usually too sensible to be dismissed in that way. In the long term I feel it has to be good for Python that it has such conscientious critics. Ultimately it may well be that some other project than CPython represents the way forward for the language. I don't think that day has arrived yet, but that doesn't mean we should exclude the possibility out of hand. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From abhigyan_agrawal at in.ibm.com Tue Jan 13 02:03:32 2009 From: abhigyan_agrawal at in.ibm.com (abhi) Date: Mon, 12 Jan 2009 23:03:32 -0800 (PST) Subject: Problems in Using C-API for Unicode handling Message-ID: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Hi, I am trying to handle Unicode objects in C (Python 2.5.2). I am getting PyObjects from and want to coerce them to unicode objects. The documentation provides two APIs for that: PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) PyUnicode_FromObject(PyObject *obj) (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) Now I want to utf-16 so I am trying to use the first one, but it is giving back NULL in case of PyObject is already Unicode type which is expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) is passing irrespective of type of PyObject. The API says it is Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I use that, it returns NULL where as PyUnicode_FromObject works. Is there any way by which I can take in any PyObject and convert it to utf-16 object? Any help is appreciated. Thanks, Abhigyan From gagsl-py2 at yahoo.com.ar Tue Jan 13 02:04:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 05:04:56 -0200 Subject: [urllib2] 302 -> can't get cookie References: Message-ID: En Wed, 07 Jan 2009 09:27:00 -0200, Gilles Ganault escribi?: > I'm using urllib2 to connect to a web server with POST, and then the > server sends a cookie to hold the session ID, but also redirects the > user to another page: If you're still interested, the way to avoid a redirect would be to use a RedirectHandler that does nothing: from urllib2 import HTTPRedirectHandler, build_opener class AvoidRedirectHandler(HTTPRedirectHandler): def http_error_302(self, req, fp, code, msg, headers): pass http_error_301 = http_error_303 = http_error_307 = http_error_302 opener = build_opener(AvoidRedirectHandler) opener.open(url, data) -- Gabriel Genellina From tjreedy at udel.edu Tue Jan 13 02:17:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 02:17:43 -0500 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: abhi wrote: > Hi, > I am trying to handle Unicode objects in C (Python 2.5.2). I am > getting PyObjects from and want to coerce them to unicode objects. The > documentation provides two APIs for that: > > PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, > const char *errors) > PyUnicode_FromObject(PyObject *obj) > > (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) > Now I want to utf-16 so I am trying to use the first one, but it is > giving back NULL in case of PyObject is already Unicode type which is > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > is passing irrespective of type of PyObject. The API says it is > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > use that, it returns NULL where as PyUnicode_FromObject works. > > Is there any way by which I can take in any PyObject and convert it to > utf-16 object? Any help is appreciated. Whether Unicode objects are utf-16 or utf=32 depends on your Python build. You can always convert a byte string representation of an object to unicode. From mail at microcorp.co.za Tue Jan 13 02:25:30 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 13 Jan 2009 09:25:30 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com><7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr><7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> Message-ID: <028201c97550$55c3d260$0d00a8c0@hendrik> "Steve Holden" wrote: > r wrote: (about another Steven) > > WOW Steven, i am very impressed. That's the first thing you have said > > in a very long time that i totally agree with! Keep this up and i may > > put you back on my Python Brethren list :) > > What can one do to get *off* it? ;-) eeh by gum lad - there's nowt for it - tis direct result of heavy infestation of people on planet! - Hendrik From timr at probo.com Tue Jan 13 02:29:43 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 13 Jan 2009 07:29:43 GMT Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: imageguy wrote: >Using py2.5.4 and entering the following lines in IDLE, I don't really >understand why I get the result shown in line 8. > >Note the difference between lines 7 and 10 is that 'else' clause >result enclosed in brackets, however, in line 2, both the 'c,d' >variables are assign correctly without the brackets being required. > >Any chance someone could enlighten me on the rules for tuple unpacking >as this seems inconsistent. It's not the tuple unpacking that's burning you. It's simple operator precedence. >7) >>> c,d = n if n is not None else 0,0 >8) >>> print c,d >9) (22, 11) 0 >10) >>> c,d = n if n is not None else (0,0) >11) >>> print c,d >12) 22 11 As line 10 makes clear, line 7 is interpreted thus: c,d = (n if n is not None else 0) , 0 "c" gets bound to the result of the ternary (the tuple (22,11)), and "d" gets bound to 0. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From neokannon at gmail.com Tue Jan 13 02:35:14 2009 From: neokannon at gmail.com (Kannon) Date: Mon, 12 Jan 2009 23:35:14 -0800 (PST) Subject: Attaching a live interpreter to a script? Message-ID: I'm sure this has come up before, but my google-fu is just not strong enough to find it out of 10,000~ posts, and apologies if this is obvious. What I'd like to do is attach an interpreter to a program running from a script (I.E, not something I typed into the live interpreter). It'd be an awesome way to debug programs, as well as tweak parameters and such at runtime. Ideally, I'd like it to be something in pure python so I could throw it into Jython and IronPython as well. (Though, I can actually code Java and C#, so implementing it is something I could do myself, if needed.) I was thinking maybe something I could throw into a tkinter window or similar, but I wasn't able to find anything on how to pass stuff directly to the interpreter. Any ideas, or if this is even possible would be nice. Thanks in advance. From steve at holdenweb.com Tue Jan 13 02:40:16 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 02:40:16 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <028201c97550$55c3d260$0d00a8c0@hendrik> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com><7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr><7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> <028201c97550$55c3d260$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen wrote: > "Steve Holden" wrote: > >> r wrote: (about another Steven) > >>> WOW Steven, i am very impressed. That's the first thing you have said >>> in a very long time that i totally agree with! Keep this up and i may >>> put you back on my Python Brethren list :) >> What can one do to get *off* it? ;-) > > eeh by gum lad - there's nowt for it - > tis direct result of heavy infestation > of people on planet! > 'appen so, but if folk 'ud keep it in ther trousers there'd be less on 'em and I wouldn't be so mithered. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From s.selvamsiva at gmail.com Tue Jan 13 02:46:31 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 13 Jan 2009 13:16:31 +0530 Subject: Extracting real-domain-name (without sub-domains) from a given URL Message-ID: Hi all, I need to extract the domain-name from a given url(without sub-domains). With urlparse, i am able to fetch only the domain-name(which includes the sub-domain also). eg: http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, .... all must lead to *huffingtonpost.com or huffingtonpost.de** * Please suggest me some ideas regarding this problem. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 13 02:57:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 05:57:32 -0200 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: En Mon, 12 Jan 2009 12:00:16 -0200, John Machin escribi?: > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. This is called "backwards compatibility" and it's a good thing :) Consider the Atucha II nuclear plant, started in 1980, based on a design from 1965, and still unfinished. People require access to the complete design, plans, specifications, CAD drawings... decades after they were initially written. I actually do use (and maintain! -- ugh!) some DOS programs. Some people would have a hard time if they could not read their old data with new programs. Even Python has a "print" statement decades after nobody uses a teletype terminal anymore... -- Gabriel Genellina From clp2 at rebertia.com Tue Jan 13 03:20:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 00:20:41 -0800 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: Message-ID: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: > Hi all, > > I need to extract the domain-name from a given url(without sub-domains). > With urlparse, i am able to fetch only the domain-name(which includes the > sub-domain also). > > eg: > http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, > .... all must lead to huffingtonpost.com or huffingtonpost.de > > Please suggest me some ideas regarding this problem. That would require (pardon the pun) domain-specific logic. For most TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, etc. But for ccTLDs, often only second-level registrations are allowed, e.g. for www.bbc.co.uk, so the main domain name would be bbc.co.uk I think a few TLDs have even more complicated rules. I doubt anyone's created a general ready-made solution for this, you'd have to code it yourself. To handle the common case, you can cheat and just .split() at the periods and then slice and rejoin the list of domain parts, ex: '.'.join(domain.split('.')[-2:]) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Ron.Barak at lsi.com Tue Jan 13 03:24:02 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 08:24:02 +0000 Subject: Relative performance of comparable regular expressions In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494DBB@enbmail01.lsi.com> Hi, I have a question about relative performance of comparable regular expressions. I have large log files that start with three letters month names (non-unicode). Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? Also, which is better (if different at all): "\d\d" or "\d{2}" ? Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Thanks, Ron. From s.selvamsiva at gmail.com Tue Jan 13 03:28:36 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 13 Jan 2009 13:58:36 +0530 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: On Tue, Jan 13, 2009 at 1:50 PM, Chris Rebert wrote: > > On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: > > Hi all, > > > > I need to extract the domain-name from a given url(without sub-domains). > > With urlparse, i am able to fetch only the domain-name(which includes the > > sub-domain also). > > > > eg: > > http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, > > .... all must lead to huffingtonpost.com or huffingtonpost.de > > > > Please suggest me some ideas regarding this problem. > > That would require (pardon the pun) domain-specific logic. For most > TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, > etc. But for ccTLDs, often only second-level registrations are > allowed, e.g. for www.bbc.co.uk, so the main domain name would be > bbc.co.uk I think a few TLDs have even more complicated rules. > > I doubt anyone's created a general ready-made solution for this, you'd > have to code it yourself. > To handle the common case, you can cheat and just .split() at the > periods and then slice and rejoin the list of domain parts, ex: > '.'.join(domain.split('.')[-2:]) > > Cheers, > Chris Thank you Chris Rebert, Actually i tried with domain specific logic.Having 200 TLD like .com,co.in,co.uk and tried to extract the domain name. But my boss want more reliable solution than this method,any way i will try to find some alternative solution. -- Yours, S.Selvam From jules at REMOVETHIS.op59.net Tue Jan 13 04:05:28 2009 From: jules at REMOVETHIS.op59.net (Julian Smith) Date: Tue, 13 Jan 2009 09:05:28 +0000 Subject: Attaching a live interpreter to a script? References: Message-ID: <20090113090528.3a6da52a.jules@REMOVETHIS.op59.net> On Mon, 12 Jan 2009 23:35:14 -0800 (PST) Kannon wrote: > What I'd like to do is attach an interpreter to a program running from > a script (I.E, not something I typed into the live interpreter). It'd > be an awesome way to debug programs, as well as tweak parameters and > such at runtime. Ideally, I'd like it to be something in pure python > so I could throw it into Jython and IronPython as well. (Though, I can > actually code Java and C#, so implementing it is something I could do > myself, if needed.) I was thinking maybe something I could throw into > a tkinter window or similar, but I wasn't able to find anything on how > to pass stuff directly to the interpreter. > > Any ideas, or if this is even possible would be nice. Thanks in > advance. I have a few lines of code that runs a debug-server in its own thread, listening on a socket, and exec-ing text that is sent to the socket. The exec happens in the debug-server thread. It's very useful - you can get a backtrace for all threads (on python-2.5 and later), look at globals, call functions, etc etc, all while the main programme is running. If anyone's interested, i'll put the code somewhere. It's all very simple; some would say crude, too. - Jules -- http://op59.net/ http://undo-software.com/ From gagsl-py2 at yahoo.com.ar Tue Jan 13 04:07:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 07:07:16 -0200 Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: En Tue, 13 Jan 2009 02:55:36 -0200, Per Freem escribi?: > On Jan 12, 10:58?pm, Steven D'Aprano > wrote: >> On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: >> > thanks for your replies -- a few clarifications and questions. the >> > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >> >>= c and b <= d. Note that I am not looking for intervals that >> > overlap... this is why interval trees seem to me to not be relevant, > i found an implementation (which is exactly how i'd write it based on > the description) here: > http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. I think there is an algorithm by Baeza-Yates that handles efficiently what you want; but I can't find it. Perhaps Google works better for you. It might be only available in Spanish, though. -- Gabriel Genellina From bj_666 at gmx.net Tue Jan 13 04:09:44 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 13 Jan 2009 09:09:44 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: <6t342oF8s8v0U1@mid.uni-berlin.de> On Mon, 12 Jan 2009 21:26:27 -0500, Steve Holden wrote: > The very idea of mapping part of a process's virtual address space onto > an area in which "low-level system code resides, so writing to this > region may corrupt the system, with potentially catastrophic > consequences" seems to be asking for trouble to me. That's why those regions are usually "write protected" and "no execution allowed" from the code in the user area of the virtual address space. Ciao, Marc 'BlackJack' Rintsch From sjmachin at lexicon.net Tue Jan 13 04:15:18 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 01:15:18 -0800 (PST) Subject: Relative performance of comparable regular expressions References: Message-ID: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> On Jan 13, 7:24?pm, "Barak, Ron" wrote: > Hi, > > I have a question about relative performance of comparable regular expressions. > > I have large log files that start with three letters month names (non-unicode). > > Which would give better performance, matching with ?"^[a-zA-Z]{3}", or with "^\S{3}" ? (1) If you want to match at the start of a line, use re.match() *without* the pointless "^". Don't use re.search with a pattern starting with "^" -- it won't be any faster than and it could be a lot worse; re.search doesn't know to stop if the first match fails: command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.match(text)" 1000000 loops, best of 3: 1.15 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.search(text)" 100000 loops, best of 3: 4.47 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*1000" "rx.search(text)" 10000 loops, best of 3: 34.1 usec per loop (2) I think you mean "^\s{3}" not "^\S{3}" (3) Now that you've seen how to do timings, over to you :-) > Also, which is better (if different at all): "\d\d" or "\d{2}" ? > Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? > And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Cheers, John From steven at REMOVE.THIS.cybersource.com.au Tue Jan 13 04:54:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 09:54:20 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sat, 10 Jan 2009 15:46:35 +0000, Mark Wooding wrote: > [Another tome. I hope this contains sufficient new material to continue > to be of interest to other readers.] I found it interesting. I don't know about others. However, at 756 lines (including quoting) it was nearly double the size of my previous tome, so I think this discussion is clearly not going anyway. I think this conversation is reaching it's natural end. Frustration levels are rising. I could -- and in fact intended to -- write a point-by-point argument, but that would only send the size of this skyrocketing and probably nobody would read it. So I'm going to take a different tack in an attempt to reduce frustration levels: if I can't convince the other side they're wrong, can I at least get them to understand where I'm coming from a little better? As I see it, this conversation is floundering on two radically different ideas about what it means to say a language uses pass-by-foo. On the one hand, some people (me and possibly rurpy) consider "this is pass-by-foo" to be a statement about behaviour directly visible to the programmer. We have a set of behavioral traits in mind, and if a language exhibits those behaviours, then it is clearly and obviously pass-by-foo no matter how that behaviour is implemented. I'll call these the behaviorists. On the other hand, others (I'm going to put Joe and Mark into this group) consider "pass-by-foo" to be a statement about mechanism, or if you prefer, implementation. If a compiler does X, then the language is pass- by-foo, regardless of behaviour. I'll call these the mechanists. To a behaviorist, Python simply can't be pass-by-value, because it doesn't behave like pass-by-value in other languages (particularly C and Pascal). The Python community has a tradition of duck-typing: if it quacks like a duck and swims like a duck, then it is a duck in every way that is important. If it can't swim and doesn't quack, it isn't a duck, no matter how much duck DNA is in it. If it flies, that's irrelevant to the question, because some ducks fly and some don't. According to the behaviorist view, what makes an evaluation strategy call- by-reference is whether or not it exhibits the following three behaviours: (1) passing a value to a function does not copy the value; (2) modifications to the value inside the function are visible to the caller; (3) assignments to the value inside the function are visible to the caller. where "value" means the thing the programmer manipulates symbolically in source code. Values are ints, strings, lists and so forth. Pointers or references are *only* values if the language allows you to write the equivalent of: ptr = SomeReferenceTo(x) # like Pascal's ptr := ^x; x = Dereference(ptr) # like Pascal's x := ptr^; According to this viewpoint, Python clearly cannot be pass-by-reference because (3) is not true. Similarly, what makes pass-by-value is: (1) passing a value to a function makes a copy of the value, where value is an entity the programmer can symbolically manipulate in source code (lists, ints, floats etc.); (2) modifications to the value inside the function are not visible to the caller; (3) assignments to the value inside the function are not visible to the caller. According to this viewpoint, Python clearly cannot be pass-by-value either because neither (1) nor (2) are true. The underlying mechanism is irrelevant. Mechanists take a different view. A typical argument paraphrased from Joe in previous threads is: "Of course Python makes a copy of the value you pass to a function. The difference is that the value you pass is a reference." Mechanists reject the restriction that values only include entities manipulated by the programmer. Consequently they're prepared to say that values in Python aren't the things which Python programmers symbolically manipulate (strings, ints etc.) but are references. Needless to say this claim strikes behaviorists as nonsensical and rather incoherent. If the value of 2 isn't 2, then value has no meaning. If mechanists see the behaviorists as "willfully ignorant", the behaviorists see the mechanists as being blatantly obfuscatory, introducing irrelevant details and ignoring clear examples of the duck quacking. And these two viewpoints are why this debate never ends, merely goes quite for a few weeks or months. -- Steven From python.list at tim.thechases.com Tue Jan 13 05:13:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 13 Jan 2009 04:13:06 -0600 Subject: efficient interval containment lookup In-Reply-To: <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> References: <496BAB8D.4020807@tim.thechases.com> <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> Message-ID: <496C6932.4030706@tim.thechases.com> Per Freem wrote: > i forgot to add, my naive_find is: > > def naive_find(intervals, start, stop): > results = [] > for interval in intervals: > if interval.start >= start and interval.stop <= stop: > results.append(interval) > return results I don't know if using a list-comprehension here is a better choice, but your code looks very much like def naive_find(intervals, start, stop): return [interval for interval in intervals if interval.start >= start and interval.stop <= stop] which may even be simple enough to include in-line rather than as a sub-function (with any associated call overhead). I've found that usually Python's smart/efficient handling of list-comprehensions can make an appreciable difference within critical-loop constructs. -tkc From jesolem at gmail.com Tue Jan 13 05:16:35 2009 From: jesolem at gmail.com (Jan Erik Solem) Date: Tue, 13 Jan 2009 02:16:35 -0800 (PST) Subject: using PIL for PCA analysis In-Reply-To: References: <8d9c20ee-f277-4c53-9e67-028f34958192@s37g2000prg.googlegroups.com> <1c90eade-098d-49ea-bd72-b9b1f5e726c8@u10g2000prn.googlegroups.com> Message-ID: <21432675.post@talk.nabble.com> > if i want to do an array of PIL image data i can use > img=Image.open("myimg.jpg") .convert("L") > pixelarray=img.getdata() > convert("L") is a good way to make images grayscale. An option to using getdata() is to try numpy's array: pixelarray = numpy.array(img) this gives lots of possibilities for working with the images numerically, like for PCA. (see example code in the link below) > thus i guess i can build a matrix of a set of images > is there something wrong in the way i do this above?may be i can use > that to find covariance matrix for the set of images? > I wrote a short script for doing PCA on images using python, with some explanations and example code http://jesolem.blogspot.com/2009/01/pca-for-images-using-python.html here . Could be of help to you guys. -- View this message in context: http://www.nabble.com/using-PIL-for-PCA-analysis-tp15606311p21432675.html Sent from the Python - python-list mailing list archive at Nabble.com. From debasishroy02 at gmail.com Tue Jan 13 05:23:13 2009 From: debasishroy02 at gmail.com (debasish ray) Date: Tue, 13 Jan 2009 15:53:13 +0530 Subject: best site for hacking tricks , computer tweaks Message-ID: <000001c97568$f6d088c0$e4719a40$@com> -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Tue Jan 13 05:32:08 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 13 Jan 2009 04:32:08 -0600 Subject: Python tricks References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: Scott David Daniels wrote: > RajNewbie wrote: > > On Jan 12, 6:51 pm, Tim Chase wrote: > [a perfectly fine reply which is how I'd solve it] > >> RajNewbie wrote: > >>> ... The solution that I had in mind is: > >>> while True: > >>> ... > >>> if : break > >>> if inifinte_loop(): raise infiinte_loop_exception > >>> Wherein infinite_loop is a generator, which returns true if i > 200 > >>> def infinite_loop(): > >>> i = 0 > >>> while i < 200: > >>> i++ > >>> yield False > >>> yield True > >>> Could somebody let me know whether this is a good option? > > ... > > But, I still feel it would be much more aesthetically pleasing if I > > can call a single procedure like > > if infinite_loop() -> to do the same. > > Is it somehow possible? - say by using static variables, iterators -- > > anything? > > Yes, it is possible. After: > > def Fuse(count, exception): > for i in range(count): > yield None > raise exception > > You can do your loop as: > check_infinite = Fuse(200, ValueError('Infinite Loop')).next > while True: > ... > check_infinite() Or related to the above and the original proposal class InfiniteLoopError(Exception): """An 'infinite' loop has been detected""" def infinite_loop(max=200): for i in xrange(max): yield i raise InfiniteLoopError() Use it like this for i in infinite_loop(): if i > 10: break print "iteration", i or for i in infinite_loop(10): print "iteration", i > but I agree with Tim that a for ... else loop for the limit is > clearer. Probably yes -- Nick Craig-Wood -- http://www.craig-wood.com/nick From Maksim.Kasimov at gmail.com Tue Jan 13 06:12:08 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Tue, 13 Jan 2009 03:12:08 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On 12 ???, 16:00, John Machin wrote: > On Jan 13, 12:45?am, "sim.sim" wrote: > > > > > On 10 ???, 23:40, John Machin wrote: > > > > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > > Hi all! > > > > > I had touch with some different python behavior: I was tried to write > > > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > > > it gives expected result: > > > > > >>> open("test", "w").write('before\x1aafter') > > > > >>> open('test').read() > > > > > 'before\x1aafter' > > > > > but for my WinXP box, it gives some strange: > > > > > >>> open("test", "w").write('before\x1aafter') > > > > >>> open('test').read() > > > > > 'before' > > > > > Here I can write all symbols, but not read. > > > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > > > Why is it so and is it possible to fix it? > > > > You've already got two good answers, but this might add a little more > > > explanation: > > > > You will aware that in Windows Command Prompt, to exit the interactive > > > mode of Python (among others), you need to type Ctrl-Z ... > > > > | C:\junk>python > > > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > > > (Intel)] on > > > win32 > > > | Type "help", "copyright", "credits" or "license" for more > > > information. > > > | >>> problem = '\x1a' > > > | >>> ord(problem) > > > | 26 > > > | >>> # What is the 26th letter of the English/ASCII alphabet? > > > | ... > > > | >>> ^Z > > > | > > > | C:\junk> > > > > HTH, > > > John > > > Hi John, > > > I agree - those two answers are really good. Thanks to Mel and Marc. > > I'm sorry if my stupid question was annoyed you. > > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. > > And I wasn't annoyed either ... I was merely adding the information > that Ctrl-Z and '\x1a' were the same thing; many people don't make the > connection. > > Cheers, > John Ah John, thank you for your explanations! My first impression was that your comments does not relates to my question, but I've found new things where I used to think there was nothing. Now it is interesting to me how one have to give reasons to use open (.., 'r') instead of open(.., 'rb')? There is confusing situation when we use open(.., 'r'), are there some scenario when we might be confused when we'll use open(.., 'rb')? -- Maksim From sjmachin at lexicon.net Tue Jan 13 06:37:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 03:37:58 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On Jan 13, 10:12?pm, "sim.sim" wrote: > > Ah John, thank you for your explanations! > My first impression was that your comments does not relates to my > question, > but I've found new things where I used to think there was nothing. > > Now it is interesting to me how one have to give reasons to use open > (.., 'r') instead of open(.., 'rb')? > There is confusing situation when we use open(.., 'r'), are there some > scenario when we might be confused when we'll use open(.., 'rb')? Some general rules: if you regard a file as text, open it with "rt" -- the "t" is redundant but gives you and anyone else who reads your code that assurance that you've actually thought about it. Otherwise you regard the file as binary, and open it with "rb". The distinction was always important on Windows because of the special handling of newlines and '\x1a') but largely unimportant on *x boxes. With Python 3.0, it is important for all users to specify the mode that they really need: 'b' files read and write bytes objects whereas 't' files read and write str objects, have the newline etc changes, and need an encoding to decode the raw bytes into str (Unicode) objects -- and you can't use bytes objects directly with a 't' file nor str objects directly a 'b' file. HTH, John From steve at holdenweb.com Tue Jan 13 06:43:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 06:43:37 -0500 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: S.Selvam Siva wrote: > On Tue, Jan 13, 2009 at 1:50 PM, Chris Rebert wrote: >> On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: >>> Hi all, >>> >>> I need to extract the domain-name from a given url(without sub-domains). >>> With urlparse, i am able to fetch only the domain-name(which includes the >>> sub-domain also). >>> >>> eg: >>> http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, >>> .... all must lead to huffingtonpost.com or huffingtonpost.de >>> >>> Please suggest me some ideas regarding this problem. >> That would require (pardon the pun) domain-specific logic. For most >> TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, >> etc. But for ccTLDs, often only second-level registrations are >> allowed, e.g. for www.bbc.co.uk, so the main domain name would be >> bbc.co.uk I think a few TLDs have even more complicated rules. >> >> I doubt anyone's created a general ready-made solution for this, you'd >> have to code it yourself. >> To handle the common case, you can cheat and just .split() at the >> periods and then slice and rejoin the list of domain parts, ex: >> '.'.join(domain.split('.')[-2:]) >> >> Cheers, >> Chris > > > Thank you Chris Rebert, > Actually i tried with domain specific logic.Having 200 TLD like > .com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i > will try to find some alternative solution. > If you post a good first try, opening the source, I would be surprised if others do not join your effort to establish suitable rules. This is somethjing that many people could doubtless use. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From abhigyan_agrawal at in.ibm.com Tue Jan 13 06:44:05 2009 From: abhigyan_agrawal at in.ibm.com (abhi) Date: Tue, 13 Jan 2009 03:44:05 -0800 (PST) Subject: Problems in Using C-API for Unicode handling References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> On Jan 13, 12:17?pm, Terry Reedy wrote: > abhi wrote: > > Hi, > > ? ? I am trying to handle Unicode objects in C (Python 2.5.2). I am > > getting PyObjects from and want to coerce them to unicode objects. The > > documentation provides two APIs for that: > > > ?PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, > > const char *errors) > > ?PyUnicode_FromObject(PyObject *obj) > > > (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) > > Now I want to utf-16 so I am trying to use the first one, but it is > > giving back NULL in case of PyObject is already Unicode type which is > > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > > is passing irrespective of type of PyObject. The API says it is > > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > > use that, it returns NULL where as PyUnicode_FromObject works. > > > Is there any way by which I can take in any PyObject and convert it to > > utf-16 object? Any help is appreciated. > > Whether Unicode objects are utf-16 or utf=32 depends on your Python > build. ?You can always convert a byte string representation of an object > to unicode.- Hide quoted text - > > - Show quoted text - Hi, I agree with you. I have a Python unicode object in C (I don't know which utf) and I want to convert this explicitely to utf-16. Is there any way to do this? PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) says that obj can't be a unicode type so I guess I can't use this one, does anybody knows any other method by which I can achieve my goal? Thanks, Abhigyan From steve at holdenweb.com Tue Jan 13 06:47:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 06:47:05 -0500 Subject: Relative performance of comparable regular expressions In-Reply-To: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> Message-ID: John Machin wrote: > On Jan 13, 7:24 pm, "Barak, Ron" wrote: >> Hi, >> >> I have a question about relative performance of comparable regular expressions. >> >> I have large log files that start with three letters month names (non-unicode). >> >> Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? > > (1) If you want to match at the start of a line, use re.match() > *without* the pointless "^". Don't use re.search with a pattern > starting with "^" -- it won't be any faster than and it could be a lot > worse; re.search doesn't know to stop if the first match fails: > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.match(text)" > 1000000 loops, best of 3: 1.15 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.search(text)" > 100000 loops, best of 3: 4.47 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*1000" "rx.search(text)" > 10000 loops, best of 3: 34.1 usec per loop > > (2) I think you mean "^\s{3}" not "^\S{3}" > > (3) Now that you've seen how to do timings, over to you :-) > >> Also, which is better (if different at all): "\d\d" or "\d{2}" ? >> Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? >> And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" > Of course if the log strings all begin with a string like "Dec 12 2009 ...." then you don't need regular expressions at all - just pull the characters out using their positions and slicing. The month would be string[0:3] and so on. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent.gulinao at gmail.com Tue Jan 13 07:03:25 2009 From: vincent.gulinao at gmail.com (Vincent Gulinao) Date: Tue, 13 Jan 2009 20:03:25 +0800 Subject: WebDAV client module Message-ID: Kindly point me to a good WebDAV client module for Python. Looks like PyDav is popular, but it seems some of the modules used within were already deprecated. TIA. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gkcdri at gmail.com Tue Jan 13 07:36:37 2009 From: gkcdri at gmail.com (gkcdri at gmail.com) Date: Tue, 13 Jan 2009 04:36:37 -0800 (PST) Subject: i want to join developer group Message-ID: Hello, I want to contribute to the open source projects. From steve at holdenweb.com Tue Jan 13 08:00:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 08:00:43 -0500 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> Message-ID: abhi wrote: > On Jan 13, 12:17 pm, Terry Reedy wrote: >> abhi wrote: >>> Hi, >>> I am trying to handle Unicode objects in C (Python 2.5.2). I am >>> getting PyObjects from and want to coerce them to unicode objects. The >>> documentation provides two APIs for that: >>> PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, >>> const char *errors) >>> PyUnicode_FromObject(PyObject *obj) >>> (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) >>> Now I want to utf-16 so I am trying to use the first one, but it is >>> giving back NULL in case of PyObject is already Unicode type which is >>> expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) >>> is passing irrespective of type of PyObject. The API says it is >>> Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I >>> use that, it returns NULL where as PyUnicode_FromObject works. >>> Is there any way by which I can take in any PyObject and convert it to >>> utf-16 object? Any help is appreciated. >> Whether Unicode objects are utf-16 or utf=32 depends on your Python >> build. You can always convert a byte string representation of an object >> to unicode.- Hide quoted text - >> >> - Show quoted text - > > Hi, > I agree with you. I have a Python unicode object in C (I don't know > which utf) and I want to convert this explicitely to utf-16. Is there > any way to do this? > PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const > char *errors) says that obj can't be a unicode type so I guess I can't > use this one, does anybody knows any other method by which I can > achieve my goal? > I suspect that a "Python Unicode object in C" will be using either UCS-2 or UCS-4 representation, depending on the options your interpreter was built with. So whatever else it is, it won't be UTF-anything. Don't know whether that helps or not. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python-url at phaseit.net Tue Jan 13 08:14:24 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 13 Jan 2009 13:14:24 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 13) Message-ID: QOTW: "If Jack Valenti had been around at the time of Gutenberg he would have organized the monks to come and burn down the printing press' :-)." - Information Technology Association of America president Harris Miller Dynamic creation of instance attributes may adversely affect code readability: http://groups.google.com/group/comp.lang.python/browse_thread/thread/68bc54bca830c46/ A detective story: getting meaningful data out of a mix of base64, UTF-16, and gzip: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/ http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/ Analyzing existing alternatives to extend Python with C or C++ code: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9afb5b4bdfaac6/ This long post on PyObjC from late in 2004 is worth re-reading for its remarks on Macintosh, architecture, and getting things to work: http://mail.python.org/pipermail/pythonmac-sig/2004-October/012023.html Handling multiple child processes: http://groups.google.com/group/comp.lang.python/browse_thread/thread/80a8edb06c3b7f1b/ How to create an instance of the right subclass: http://groups.google.com/group/comp.lang.python/browse_thread/thread/636d0f516e9850c9/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From benjamin.kaplan at case.edu Tue Jan 13 08:33:19 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 13 Jan 2009 08:33:19 -0500 Subject: Attaching a live interpreter to a script? In-Reply-To: References: Message-ID: On Tue, Jan 13, 2009 at 2:35 AM, Kannon wrote: > I'm sure this has come up before, but my google-fu is just not strong > enough to find it out of 10,000~ posts, and apologies if this is > obvious. > > What I'd like to do is attach an interpreter to a program running from > a script (I.E, not something I typed into the live interpreter). It'd > be an awesome way to debug programs, as well as tweak parameters and > such at runtime. Ideally, I'd like it to be something in pure python > so I could throw it into Jython and IronPython as well. (Though, I can > actually code Java and C#, so implementing it is something I could do > myself, if needed.) I was thinking maybe something I could throw into > a tkinter window or similar, but I wasn't able to find anything on how > to pass stuff directly to the interpreter. > > Any ideas, or if this is even possible would be nice. Thanks in > advance. I don't know exactly what they did, but wxPython has a "widget inspection tool" that includes such a thing. It lets you manipulate whatever widget is selected in the tree control above the shell. The widget inspection tool is in wx/lib/inspection.py and the code for the shell they use is in wx/py/shell.py. I think it's pure python except for the gui. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lie.1296 at gmail.com Tue Jan 13 08:58:53 2009 From: Lie.1296 at gmail.com (Lie) Date: Tue, 13 Jan 2009 05:58:53 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: <6de24fc3-64d2-4cf2-afaa-a3cfc2aede6a@y1g2000pra.googlegroups.com> On Jan 3, 4:38?am, mr wrote: > As has been noted, the best is to fix the input to be regular-3- > tuples. For the fun of it, here's another variation of a solution: > Yet another solution: for i in l: k, u, v = i[0], None if len(i) == 2 else i[1], i[-1] From Lie.1296 at gmail.com Tue Jan 13 09:07:43 2009 From: Lie.1296 at gmail.com (Lie) Date: Tue, 13 Jan 2009 06:07:43 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: <67e0dfc1-0a33-4902-850b-e48fabb85642@g3g2000pre.googlegroups.com> On Jan 3, 11:55?am, Kottiyath wrote: > On Jan 3, 2:38?am, mr wrote: > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. Is it possible to change (name, filename, value) into (name, value, filename) instead? In most cases optional arguments should be last. There are some very exceptional case, where early optional argument might be better, like python's range, which type signature is: [[start,] stop[, step]] (i.e. with one argument, it is assigned to stop, instead of start) From Ron.Barak at lsi.com Tue Jan 13 09:16:56 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 14:16:56 +0000 Subject: Relative performance of comparable regular expressions In-Reply-To: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> Hi John, Thanks for the below - teaching me how to fish ( instead of just giving me a fish :-) Now I could definitely get the answers for myself, and also be a bit more enlightened. As for your (2) remark below (on my question: Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ?): (2) I think you mean "^\s{3}" not "^\S{3}", I actually did meant to use \S, namely - a character that is not a white-space. Bye, Ron. -----Original Message----- From: John Machin [] Sent: Tuesday, January 13, 2009 11:15 To: python-list at python.org Subject: Re: Relative performance of comparable regular expressions On Jan 13, 7:24 pm, "Barak, Ron" wrote: > Hi, > > I have a question about relative performance of comparable regular expressions. > > I have large log files that start with three letters month names (non-unicode). > > Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? (1) If you want to match at the start of a line, use re.match() *without* the pointless "^". Don't use re.search with a pattern starting with "^" -- it won't be any faster than and it could be a lot worse; re.search doesn't know to stop if the first match fails: command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.match(text)" 1000000 loops, best of 3: 1.15 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.search(text)" 100000 loops, best of 3: 4.47 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*1000" "rx.search(text)" 10000 loops, best of 3: 34.1 usec per loop (2) I think you mean "^\s{3}" not "^\S{3}" (3) Now that you've seen how to do timings, over to you :-) > Also, which is better (if different at all): "\d\d" or "\d{2}" ? > Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? > And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Cheers, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From BrianVanderburg2 at aim.com Tue Jan 13 09:24:51 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Tue, 13 Jan 2009 09:24:51 -0500 Subject: Python threading Message-ID: <496CA433.2040507@aim.com> I'm doing some multi-threaded programming and before diving into the C/C++ code I though I'd do some in Python first. I decided to read through the threading module and I understand some of it, but I don't understand this, though I'm sure it is easy: The condition object has a method _is_owned, which is called if the lock doesn't have one. The RLock does have one but a regular lock not. It is supposed to return true if the lock is owned by the current thread: def _is_owned(self): # Return True if lock is owned by currentThread. # This method is called only if __lock doesn't have _is_owned(). if self.__lock.acquire(0): self.__lock.release() return False else: return True It seems that for a condition without an RLock but a Lock, self.__lock.acquire(0) will return False even if the lock is owned by another thread other than the current thread, so _is_owned would return True even if the lock is owned by another thread. B. Vanderburg II From philip at semanchuk.com Tue Jan 13 09:39:08 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 09:39:08 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> On Jan 13, 2009, at 1:22 AM, Steve Holden wrote: > Philip Semanchuk wrote: >> >> On Jan 12, 2009, at 6:48 PM, ajaksu wrote: >> >>> On Jan 11, 11:59 pm, "James Mills" >>> wrote: >>>> Hey all, >>>> >>>> The following fails for me: >>>> >>>>>>> from urllib2 import urlopen >>>>>>> f = >>>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>>>> ") >>>>>>> >>>> >>>> Traceback (most recent call last): >>> [...] >>>> Any helpful ideas ? >>> >>> Maybe raise a real bug @ bugs.python.org instead of just >>> mentioning it >>> like I did: http://bugs.python.org/msg77889 >>> >>> I think at least some sites would be willing to add the new UA to >>> their whitelists. >> >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? >> > I'd say it's an issue relevant to Python users, which woudl seem to > put > it pretty much in the mainstream for c.l.py - especially as the code > causing concern was written in Python. I didn't mean to imply that the conversation didn't belong here. I think that is perfectly appropriate. What I don't understand is the suggestion that Google's server config should be raised as a bug against Python. (i.e. "raise a real bug @ bugs.python.org...") From Tribulations at Paralleles.invalid Tue Jan 13 10:13:21 2009 From: Tribulations at Paralleles.invalid (TP) Date: Tue, 13 Jan 2009 16:13:21 +0100 Subject: exec in a nested function yields an error Message-ID: Hi everybody, Try the following program: #################### def f(): def f_nested(): exec "a=2" print a f() #################### It yields an error. $ python nested_exec.py File "nested_exec.py", line 3 exec "a=2" SyntaxError: unqualified exec is not allowed in function 'f_nested' it is a nested function What is the problem? Why? Thanks -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From steve at holdenweb.com Tue Jan 13 10:14:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 10:14:38 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> References: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> Message-ID: Philip Semanchuk wrote: > > On Jan 13, 2009, at 1:22 AM, Steve Holden wrote: > >> Philip Semanchuk wrote: >>> >>> On Jan 12, 2009, at 6:48 PM, ajaksu wrote: >>> >>>> On Jan 11, 11:59 pm, "James Mills" >>>> wrote: >>>>> Hey all, >>>>> >>>>> The following fails for me: >>>>> >>>>>>>> from urllib2 import urlopen >>>>>>>> f = >>>>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>>>>>>> >>>>>>>> >>>>> >>>>> Traceback (most recent call last): >>>> [...] >>>>> Any helpful ideas ? >>>> >>>> Maybe raise a real bug @ bugs.python.org instead of just mentioning it >>>> like I did: http://bugs.python.org/msg77889 >>>> >>>> I think at least some sites would be willing to add the new UA to >>>> their whitelists. >>> >>> I don't think I understand you clearly. Whether or not Google et al >>> whitelist the Python UA isn't a Python issue, is it? >>> >> I'd say it's an issue relevant to Python users, which woudl seem to put >> it pretty much in the mainstream for c.l.py - especially as the code >> causing concern was written in Python. > > I didn't mean to imply that the conversation didn't belong here. I think > that is perfectly appropriate. What I don't understand is the suggestion > that Google's server config should be raised as a bug against Python. > (i.e. "raise a real bug @ bugs.python.org...") > Oh, I see! Yes, it's hard to know what actions anyone could take on such a bug report. I suppose the documentation could be modified to describe how some services require specific agents, but that wouldn't help a huge amount. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Kiran.Karra at gmail.com Tue Jan 13 10:21:40 2009 From: Kiran.Karra at gmail.com (K-man) Date: Tue, 13 Jan 2009 07:21:40 -0800 (PST) Subject: Ethernet packet size python Message-ID: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Hi, I am sending data using the socket interface in python, but I want to know how big the ethernet packet size is (in bytes). I didn't really see a way using the socket library of how to do this. Any suggestions? From oltman at gmail.com Tue Jan 13 10:23:46 2009 From: oltman at gmail.com (Ryan Oltman) Date: Tue, 13 Jan 2009 07:23:46 -0800 (PST) Subject: Embedding Python with non-filesystem code source? Message-ID: <7c18a276-d11a-4e20-be32-343e656bad3d@v5g2000prm.googlegroups.com> Background: I'm trying to develop some certification software in C/C++ that would allow engineers/technicians to quickly develop scripts/functions in Python to verify a product (there could be hundreds of functions per product). I would like to use SQLite db to store the functions and the necessary certification reference data. Question: I have successfully embedded python code in C/C++ using the PyEval_CallObject when using a file as the module source,but is it possible using the PyImport_ImportModule & PyObject_GetAttrString to point to a non-filesystem source? Is there another way to setup the PyEval_CallObject that would allow this capability? Ryan Oltman From skip at pobox.com Tue Jan 13 10:28:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 13 Jan 2009 09:28:29 -0600 Subject: Converting from PyUnicodeObject to char * without calling C API Message-ID: <18796.45853.852587.379554@montanaro.dyndns.org> I'm trying to convert Python's gdbinit file to Python 3. One of the things it does is print filenames and function names when displaying stack frames. This worked fine in Python 2 because the type of such objects is PyStringObject which uses NUL-terminated strings under the covers. For example: set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval In Python 3 co->co_filename is a PyUnicodeObject pointer with the raw data encoded as either UCS2 or UCS4. This presents problems when displaying strings: (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) (gdb) p *$__f->str@$__f->length $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} (gdb) p *(char *)($__f->str)@$__f->length $15 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p" (gdb) p *(char *)($__f->str)@($__f->length*2) $16 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p\000y\0003\000k\000-\000t\000/\000L\000i\000b\000/\000_\000w\000e\000a\000k\000r\000e\000f\000s\000e\000t\000.\000p\000y" I'd like to get rid of those NULs when displaying names. Making it more difficult, I'd like to do it without calling any C API functions. If at all possible the user-defined commands should work even if there is no process available. (e.g., when working with core files). Any suggestions? -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From google at mrabarnett.plus.com Tue Jan 13 10:35:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jan 2009 15:35:48 +0000 Subject: Converting from PyUnicodeObject to char * without calling C API In-Reply-To: <18796.45853.852587.379554@montanaro.dyndns.org> References: <18796.45853.852587.379554@montanaro.dyndns.org> Message-ID: <496CB4D4.8070407@mrabarnett.plus.com> skip at pobox.com wrote: > I'm trying to convert Python's gdbinit file to Python 3. One of the things > it does is print filenames and function names when displaying stack frames. > This worked fine in Python 2 because the type of such objects is > PyStringObject which uses NUL-terminated strings under the covers. For > example: > > set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval > > In Python 3 co->co_filename is a PyUnicodeObject pointer with the raw data > encoded as either UCS2 or UCS4. This presents problems when displaying > strings: > > (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) > (gdb) p *$__f->str@$__f->length > $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} > > (gdb) p *(char *)($__f->str)@$__f->length > $15 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p" > > (gdb) p *(char *)($__f->str)@($__f->length*2) > $16 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p\000y\0003\000k\000-\000t\000/\000L\000i\000b\000/\000_\000w\000e\000a\000k\000r\000e\000f\000s\000e\000t\000.\000p\000y" > > > I'd like to get rid of those NULs when displaying names. Making it more > difficult, I'd like to do it without calling any C API functions. If at all > possible the user-defined commands should work even if there is no process > available. (e.g., when working with core files). > Should you be using "char *" when they aren't char? Is there a wide char type of some sort? From steve at holdenweb.com Tue Jan 13 10:35:56 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 10:35:56 -0500 Subject: Ethernet packet size python In-Reply-To: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: K-man wrote: > Hi, > I am sending data using the socket interface in python, but I want > to know how big the ethernet packet size is (in bytes). I didn't > really see a way using the socket library of how to do this. Any > suggestions? There is no way to know what size Ethernet packets will result from specific traffic. Or do you want to know the MTU size (largest possible Ethernet packet size)? This shouldn't really matter, since large TCP messages will be split into a sequence of IP datagrams, and large IP datagrams will be automatically fragmented and then reassembled at the other end. Is there a specific reason this is important to you? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From marduk at letterboxes.org Tue Jan 13 10:37:17 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 10:37:17 -0500 Subject: exec in a nested function yields an error In-Reply-To: References: Message-ID: <1231861037.18519.9.camel@localhost.localdomain> On Tue, 2009-01-13 at 16:13 +0100, TP wrote: > Hi everybody, > > Try the following program: > > #################### > def f(): > def f_nested(): > exec "a=2" > print a > f() > #################### > > It yields an error. > $ python nested_exec.py > File "nested_exec.py", line 3 > exec "a=2" > SyntaxError: unqualified exec is not allowed in function 'f_nested' it is a > nested function > > What is the problem? > Why? > I believe because in the above example what namespace is local for the exec is ambiguous so you need to specify it explicitly. Also, and I'm sure you know this, exec can be dangerous and should be used wisely/rarely. From Scott.Daniels at Acm.Org Tue Jan 13 10:47:56 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 07:47:56 -0800 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: imageguy wrote: > 1) >>> n = None > 2) >>> c,d = n if n is not None else 0,0 ... This is more easily expressed as: c, d = n or (0, 0) From dskippy at ccs.neu.edu Tue Jan 13 10:51:09 2009 From: dskippy at ccs.neu.edu (Mike MacHenry) Date: Tue, 13 Jan 2009 10:51:09 -0500 Subject: Simple CGI-XMLRPC failure In-Reply-To: References: Message-ID: <7d9c10d20901130751w81f862fm3cdff04f123475bb@mail.gmail.com> I figured it was some kind of bug. Must be either a bug with my version of either the library (most likely) or perhaps some weird environment setting that I have set incorrectly (also likely). How can I figure out which version of SimpleXMLRPCServer I'm running? Do you run Ubuntu by any chance? If you which version? Does anyone know of any environment settings I could look into on Apache or Python? -mike On Mon, Jan 12, 2009 at 9:02 PM, Jeff McNeil wrote: > On Jan 12, 12:40 pm, "Mike MacHenry" wrote: >> I am having a difficult time understanding why my very simple >> CGI-XMLRPC test isn't working. I created a server to export two >> functions, the built-in function "pow" and my own identity function >> "i". I run a script to call both of them and the "pow" work fine but >> the "i" gives me an error that says my XMLRPC server doesn't support >> than name. Here is the code for both files and the output: >> >> #!/usr/bin/env python >> #This file is /usr/lib/cgi-bin/roundwarerpc.py >> from SimpleXMLRPCServer import CGIXMLRPCRequestHandler >> def i(x): >> return x >> server = CGIXMLRPCRequestHandler() >> server.register_function(pow) >> server.register_function(i) >> server.handle_request() >> >> #!/usr/bin/env python >> #This file is ~/test.py >> import xmlrpclib >> server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") >> print server.pow(2,3) >> print server.i(10) >> >> #This is the STDOUT and STDERR when running ~/test.py >> dskippy at dskippy-laptop:$ python test.py 8 >> Traceback (most recent call last): >> File "test.py", line 4, in >> print server.test(10) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ >> return self.__send(self.__name, args) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request >> verbose=self.__verbose >> File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request >> return self._parse_response(h.getfile(), sock) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response >> return u.close() >> File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close >> raise Fault(**self._stack[0]) >> xmlrpclib.Fault: :method "i" >> is not supported'> >> >> Does anyone know what might be wrong with this? >> >> Thanks for the help, >> -mike >> >> p.s. >> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) >> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 >> Server version Apache/2.2.8 (Ubuntu) >> Server built: Jun 25 2008 13:54:13 > > I copied your code verbatim and I don't have any issues with it at > all. Same version of Python, same version of Apache. > > In SimpleXMLRPCServer.py, register_function adds directly to a > self.funcs dictionary, so an instance variable of the same name > shouldn't hurt anything. That exception is only raised when a > self.funcs lookup raises a KeyError unless you're registering an > instance. > > -- > http://mail.python.org/mailman/listinfo/python-list > From Ron.Barak at lsi.com Tue Jan 13 10:51:54 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 15:51:54 +0000 Subject: Could you suggest optimisations ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Hi, In the attached script, the longest time is spent in the following functions (verified by psyco log): def match_generator(self,regex): """ Generate the next line of self.input_file that matches regex. """ generator_ = self.line_generator() while True: self.file_pointer = self.input_file.tell() if self.file_pointer != 0: self.file_pointer -= 1 if (self.file_pointer + 2) >= self.last_line_offset: break line_ = generator_.next() print "%.2f%% \r" % (((self.last_line_offset - self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), if not line_: break else: match_ = regex.match(line_) groups_ = re.findall(regex,line_) if match_: yield line_.strip("\n"), groups_ def get_matching_records_by_regex_extremes(self,regex_array): """ Function will: Find the record matching the first item of regex_array. Will save all records until the last item of regex_array. Will save the last line. Will remember the position of the beginning of the next line in self.input_file. """ start_regex = regex_array[0] end_regex = regex_array[len(regex_array) - 1] all_recs = [] generator_ = self.match_generator try: match_start,groups_ = generator_(start_regex).next() except StopIteration: return(None) if match_start != None: all_recs.append([match_start,groups_]) line_ = self.line_generator().next() while line_: match_ = end_regex.match(line_) groups_ = re.findall(end_regex,line_) if match_ != None: all_recs.append([line_,groups_]) return(all_recs) else: all_recs.append([line_,[]]) line_ = self.line_generator().next() def line_generator(self): """ Generate the next line of self.input_file, and update self.file_pointer to the beginning of that line. """ while self.input_file.tell() <= self.last_line_offset: self.file_pointer = self.input_file.tell() line_ = self.input_file.readline() if not line_: break yield line_.strip("\n") I was trying to think of optimisations, so I could cut down on processing time, but got no inspiration. (I need the "print "%.2f%% \r" ..." line for user's feedback). Could you suggest any optimisations ? Thanks, Ron. P.S.: Examples of processing times are: * 2m42.782s on two files with combined size of 792544 bytes (no matches found). * 28m39.497s on two files with combined size of 4139320 bytes (783 matches found). These times are quite unacceptable, as a normal input to the program would be ten files with combined size of ~17MB. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: _failover_multiple_files_client.py Type: application/octet-stream Size: 7771 bytes Desc: _failover_multiple_files_client.py URL: From Kiran.Karra at gmail.com Tue Jan 13 10:58:33 2009 From: Kiran.Karra at gmail.com (K-man) Date: Tue, 13 Jan 2009 07:58:33 -0800 (PST) Subject: Ethernet packet size python References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: <6261d4c1-96e3-40b4-ab62-30f6f4702597@v18g2000pro.googlegroups.com> On Jan 13, 10:35?am, Steve Holden wrote: > K-man wrote: > > Hi, > > ? I am sending data using the socket interface in python, but I want > > to know how big the ethernet packet size is (in bytes). ?I didn't > > really see a way using the socket library of how to do this. ?Any > > suggestions? > > There is no way to know what size Ethernet packets will result from > specific traffic. Or do you want to know the MTU size (largest possible > Ethernet packet size)? This shouldn't really matter, since large TCP > messages will be split into a sequence of IP datagrams, and large IP > datagrams will be automatically fragmented and then reassembled at the > other end. > > Is there a specific reason this is important to you? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ I am trying to determine the actual network link speed. From http Tue Jan 13 11:01:25 2009 From: http (Paul Rubin) Date: 13 Jan 2009 08:01:25 -0800 Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <7xljtfw5yi.fsf@ruckus.brouhaha.com> imageguy writes: > Using py2.5.4 and entering the following lines in IDLE, I don't really > understand why I get the result shown in line 8. > > Note the difference between lines 7 and 10 is that 'else' clause > result enclosed in brackets, however, in line 2, both the 'c,d' > variables are assign correctly without the brackets being required. c,d = n if n is not None else 0,0 parses as: c,d = (n if n is not None else 0), 0 In the case where n is None, c and d are both set to 0. In the case where n is a tuple, c is set to the tuple and d is set to 0. Does that help? From clp2 at rebertia.com Tue Jan 13 11:14:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 08:14:49 -0800 Subject: Relative performance of comparable regular expressions In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> Message-ID: <50697b2c0901130814x5541273ay34b7727160174a4b@mail.gmail.com> On Tue, Jan 13, 2009 at 6:16 AM, Barak, Ron wrote: > Hi John, > > Thanks for the below - teaching me how to fish ( instead of just giving > me a fish :-) > Now I could definitely get the answers for myself, and also be a bit more > enlightened. > > As for your (2) remark below (on my question: Which would give better > performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ?): > (2) I think you mean "^\s{3}" not "^\S{3}", > I actually did meant to use \S, namely - a character that is not a > white-space. (A) Please don't top-post, it makes replying to you more awkward and makes it harder for readers to follow the conversation. (B) But "^[a-zA-Z]{3}", and "^\S{3}" aren't even equivalent! \S allows *digits* and *punctuation* too, whereas the former *only* matches letters. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > -----Original Message----- > From: John Machin [ > ] > Sent: Tuesday, January 13, 2009 11:15 > To: python-list at python.org > Subject: Re: Relative performance of comparable regular expressions > > On Jan 13, 7:24 pm, "Barak, Ron" wrote: >> Hi, >> >> I have a question about relative performance of comparable regular >> expressions. >> >> I have large log files that start with three letters month names >> (non-unicode). >> >> Which would give better performance, matching with "^[a-zA-Z]{3}", or >> with "^\S{3}" ? > > (1) If you want to match at the start of a line, use re.match() > *without* the pointless "^". Don't use re.search with a pattern starting > with "^" -- it won't be any faster than and it could be a lot worse; > re.search doesn't know to stop if the first match fails: > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.match(text)" > 1000000 loops, best of 3: 1.15 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.search(text)" > 100000 loops, best of 3: 4.47 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*1000" "rx.search(text)" > 10000 loops, best of 3: 34.1 usec per loop > > (2) I think you mean "^\s{3}" not "^\S{3}" > > (3) Now that you've seen how to do timings, over to you :-) > >> Also, which is better (if different at all): "\d\d" or "\d{2}" ? >> Also, would matching "." be different (performance-wise) than matching the >> actual character, e.g. matching ":" ? >> And lastly, at the end of a line, is there any performance difference >> between "(.+)$" and "(.+)" > > Cheers, > John From grimson at gmx.de Tue Jan 13 11:22:24 2009 From: grimson at gmx.de (Grimson) Date: Tue, 13 Jan 2009 17:22:24 +0100 Subject: ctype problem Message-ID: <496CBFC0.3080809@gmx.de> hello out there, I have a problem with c-types. I made a c-library, which expects a pointer to a self defined structure. let the funtion call myfunction(struct interface* iface) and the struct: struct interface { int a; int b; char *c; } the Python ctype port of this structur would be: class INTERFACE(Structure): _fields_ = [("a" c_int), ("b", c_int), ("c", c_char)] in my python-struct a create a instance of INTERFACE myiface = INTERFACE() myiface.a = ctypes.c_int(80) myiface.b = ctypes.c_int(22) ... than I make a pointer onto it. p_iface = ctypes.pointer(myiface) and I tried it also with a reference r_iface = ctypes.byref(myiface) but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) works properly. The function is been called but it reads only zeros (0) for each parameter (member in the struct). Where is my fault? Thank you.. sincerely chris From gandalf at shopzeus.com Tue Jan 13 11:25:13 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 17:25:13 +0100 Subject: Standard IPC for Python? Message-ID: <496CC069.80909@shopzeus.com> I would like to develop some module for Python for IPC. Socket programming howto recommends that for local communication, and I personally experienced problems with TCP (see my previous post: "Slow network"). I was looking for semaphores and shared memory, but it is not in the standard lib. I was also thinking about unix domain sockets, but it is not available under windows. I was looking for non-standard modules as well, but only found a few references with insufficient information. For example: http://code.activestate.com/recipes/519626/ The question is: what is the standard way to implement fast and portable IPC with Python? Are there tools in the standard lib that can do this? Thanks, Laszlo From deets at nospam.web.de Tue Jan 13 11:35:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 17:35:50 +0100 Subject: Standard IPC for Python? References: Message-ID: <6t3u76F94k2gU1@mid.uni-berlin.de> Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: "Slow > network"). > > I was looking for semaphores and shared memory, but it is not in the > standard lib. I was also thinking about unix domain sockets, but it is > not available under windows. > > I was looking for non-standard modules as well, but only found a few > references with insufficient information. For example: > > http://code.activestate.com/recipes/519626/ > > The question is: what is the standard way to implement fast and portable > IPC with Python? Are there tools in the standard lib that can do this? I use Pyro. Has always been fast enough for me. It spares you the troubles of bloated XML-documents other RPC-mechanisms use. Of course it is RPC, not "only" IPC - so it comes with a tradeoff. But so far, it has been always fast enough for me. Diez From philip at semanchuk.com Tue Jan 13 11:39:23 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 11:39:23 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CC069.80909@shopzeus.com> References: <496CC069.80909@shopzeus.com> Message-ID: <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> On Jan 13, 2009, at 11:25 AM, Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: > "Slow network"). > > I was looking for semaphores and shared memory, but it is not in the > standard lib. I was also thinking about unix domain sockets, but it > is not available under windows. > > I was looking for non-standard modules as well, but only found a few > references with insufficient information. For example: > > http://code.activestate.com/recipes/519626/ > > The question is: what is the standard way to implement fast and > portable IPC with Python? Are there tools in the standard lib that > can do this? They're not in the standard lib, but I have 3 modules for Python IPC. They're all Unix-only. posix_ipc gives you semaphores, shared memory and messages queues: http://semanchuk.com/philip/posix_ipc/ sysv_ipc gives you semaphores and shared memory: http://semanchuk.com/philip/sysv_ipc/ shm also gives access to SysV semaphores and shared memory: http://nikitathespider.com/python/shm/ The only reason to use shm over the sysv_ipc module is that shm supports versions of Python < 2.5. I'm not developing shm any further, so avoid using it if possible. Here's an overview that compares the three: http://semanchuk.com/philip/PythonIpc/ The overview of the overview is that posix_ipc is the one to use if you can because it is the simplest. sysv_ipc is more broadly supported but is more complicated for programmer (me) and user (you) alike. Bugs reports are of course welcome. Enjoy! Philip From garrickp at gmail.com Tue Jan 13 11:49:51 2009 From: garrickp at gmail.com (Falcolas) Date: Tue, 13 Jan 2009 08:49:51 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: <4d0a6584-44d8-45ba-8315-dc5235e974f8@v5g2000prm.googlegroups.com> On Jan 11, 6:59?pm, "James Mills" wrote: > Hey all, > > The following fails for me: > > >>> from urllib2 import urlopen > >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") For what it's worth, I've had a similar problem with the urlopen as well. Using the library default urlopen results in an error, but if I build an opener with the basic handlers, it works just fine. >>> import urllib2 >>> f = urllib2.urlopen("http://localhost:8000") Traceback (most recent call last): File "", line 1, in f = urllib2.urlopen("http://localhost:8000") File "C:\Python25\lib\urllib2.py", line 121, in urlopen return _opener.open(url, data) File "C:\Python25\lib\urllib2.py", line 380, in open response = meth(req, response) File "C:\Python25\lib\urllib2.py", line 491, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python25\lib\urllib2.py", line 418, in error return self._call_chain(*args) File "C:\Python25\lib\urllib2.py", line 353, in _call_chain result = func(*args) File "C:\Python25\lib\urllib2.py", line 499, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden >>> opener = urllib2.OpenerDirector() >>> opener.add_handler(urllib2.HTTPHandler()) >>> opener.add_handler(urllib2.HTTPDefaultErrorHandler()) >>> f = opener.open("http://localhost:8000") >>> f.read() 'something relevant' From stefan_ml at behnel.de Tue Jan 13 11:52:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 13 Jan 2009 17:52:25 +0100 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: <496cc6c9$0$31870$9b4e6d93@newsspool3.arcor-online.net> abhi wrote: > Now I want to utf-16 so I am trying to use the first one, but it is > giving back NULL in case of PyObject is already Unicode type which is > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > is passing irrespective of type of PyObject. The API says it is > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > use that, it returns NULL where as PyUnicode_FromObject works. > > Is there any way by which I can take in any PyObject and convert it to > utf-16 object? Any help is appreciated. Use PyUnicode_FromObject() to convert the (non-string) object to a unicode object, then encode the unicode object as UTF-16 using the respecive functions in the codecs API (see the bottom of the C-API docs page for the unicode object). Note, however, that you will not succeed to convert a byte string to the corresponding unicode string using PyUnicode_FromObject(), except in the simple case where the string is ASCII encoded. Doing this right requires explicit decoding using a byte encoding that you must specify (again, see the codecs API). Stefan From bedouglas at earthlink.net Tue Jan 13 11:59:22 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 13 Jan 2009 08:59:22 -0800 Subject: basic python list/dict/key question/issues.. Message-ID: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> Hi.. quite new to python, and have a couple of basic question: i have ("term":["1","2","3"]) as i understand it, this is a list, yes/no? how can i represent this as a dict/list? i've got a few of these that i'm trying to deal with.. thanks From Scott.Daniels at Acm.Org Tue Jan 13 12:22:39 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 09:22:39 -0800 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> Message-ID: abhi wrote: > On Jan 13, 12:17 pm, Terry Reedy wrote: >> abhi wrote: >>> Hi, >>> I am trying to handle Unicode objects in C (Python 2.5.2).... > ... I want to convert this explicitely to utf-16.... You are trying to get Unicode and UTF-16, whereas you should think of those two as distinct. UTF-16 is an encoded form (bytes) from the abstract "Unicode is characters". What you want in Python is: u'abc'.encode('UTF-16') So look for something returning a string by invoking the decode method. --Scott David Daniels Scott.Daniels at Acm.Org From rdcollum at gmail.com Tue Jan 13 12:33:42 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 13 Jan 2009 09:33:42 -0800 (PST) Subject: basic python list/dict/key question/issues.. References: Message-ID: On Jan 13, 11:59?am, "bruce" wrote: > Hi.. > > quite new to python, and have a couple of basic question: > > i have > ?("term":["1","2","3"]) > > as i understand it, this is a list, yes/no? > > how can i represent this as a dict/list? > > i've got a few of these that i'm trying to deal with.. > > thanks x = {"term":["1","2","3"]} is a dictionary and the value of the key "term" is a list. From marduk at letterboxes.org Tue Jan 13 12:35:55 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 12:35:55 -0500 Subject: basic python list/dict/key question/issues.. In-Reply-To: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> References: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> Message-ID: <1231868155.3422.18.camel@localhost.localdomain> On Tue, 2009-01-13 at 08:59 -0800, bruce wrote: > Hi.. > > quite new to python, and have a couple of basic question: > > i have > ("term":["1","2","3"]) > > as i understand it, this is a list, yes/no? > No, that's invalid syntax: >>> ("term":["1","2","3"]) File "", line 1 ("term":["1","2","3"]) ^ SyntaxError: invalid syntax > how can i represent this as a dict/list? ["this","is","a","list"] {"this":1, "is":2, "a": 3, "dict": 3} > > i've got a few of these that i'm trying to deal with.. If you are new to python you might to read up on a tutorial. http://docs.python.org/tutorial/ From gandalf at shopzeus.com Tue Jan 13 12:40:06 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 18:40:06 +0100 Subject: Standard IPC for Python? In-Reply-To: <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> Message-ID: <496CD1F6.3080604@shopzeus.com> > The only reason to use shm over the sysv_ipc module is that shm > supports versions of Python < 2.5. I'm not developing shm any further, > so avoid using it if possible. Hmm, we are using FreeBSD, Ubuntu and Windows. Unfortunately - posix_ipc is broken under FreeBSD - sysv_ipc does not support message queues at all - shm is not maintained - windows is not supported by any of these modules It is so interesting that there is no standard implementation for IPC in Python. I would think it is a very common task for programmers. I might find myself writting a new IPC module that works under Windows as well. Can anyone tell me if select.select works under OS X? Thanks, Laszlo From gandalf at shopzeus.com Tue Jan 13 12:42:01 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 18:42:01 +0100 Subject: Standard IPC for Python? In-Reply-To: <6t3u76F94k2gU1@mid.uni-berlin.de> References: <6t3u76F94k2gU1@mid.uni-berlin.de> Message-ID: <496CD269.20105@shopzeus.com> > I use Pyro. Has always been fast enough for me. It spares you the troubles > of bloated XML-documents other RPC-mechanisms use. > > Of course it is RPC, not "only" IPC - so it comes with a tradeoff. But so > far, it has been always fast enough for me. > Unfortunately, I'm developing an ORB, and using another type of ORB to transport data would be silly. :-) I need the lower level stuff. From bdesth.quelquechose at free.quelquepart.fr Tue Jan 13 12:47:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 13 Jan 2009 18:47:14 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <496ce14b$0$18741$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > >> Bruno Desthuilliers writes: >>> Why on earth are you using Python if you don't like the way it work ??? >> Why on earth keep releasing new versions of Python if the old ones are >> already perfect? > > That's a fallacious argument. Nobody is arguing that any specific version > of Python is perfect, but clearly many people do like the general design > choices of the language, that is, the way it works. Thanks for making my point clear. > *If* you don't like the way it works, and you have a choice in the > matter, perhaps you should find another language that works more the way > you would prefer. > > On the other hand... Bruno's question is unfair. It is perfectly > reasonable to (hypothetically) consider Python to be the best *existing* > language while still wanting it to be improved (for some definition of > improvement). And that's the problem : what Paul suggests are not "improvements" but radical design changes. The resulting language - whatever it may be worth, I'm not making any judgement call here - would not be Python anymore. > Just because somebody has criticisms of Python, or a wish- > list of features, doesn't mean they hate the language. There's probably a whole range of nuances between "not liking" and "hating". And Paul is of course perfectly right to think that a language having this and that features from Python, but not this other one, would be a "better" language (at least according to it's own definition of "better"). Where I totally disagree is that it would make *Python* better. Also, my question was not that "unfair" (even if a bit provocative). I really wonder why peoples that seems to dislike one of the central features of Python - it's dynamism - still use it (assuming of course they are free to choose another language). And FWIW, I at least had a partial answer on this. From gert.cuykens at gmail.com Tue Jan 13 12:50:23 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 13 Jan 2009 09:50:23 -0800 (PST) Subject: i want to join developer group References: Message-ID: <47062d42-2e79-4d38-a869-db4d01ee0eba@a12g2000pro.googlegroups.com> On Jan 13, 1:36?pm, gkc... at gmail.com wrote: > Hello, > ? ? ? I want to contribute to the open source projects. Open source is about finding where you are good at. Contributing is a product of the skills you learn. From philip at semanchuk.com Tue Jan 13 13:09:09 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 13:09:09 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CD1F6.3080604@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> On Jan 13, 2009, at 12:40 PM, Laszlo Nagy wrote: > >> The only reason to use shm over the sysv_ipc module is that shm >> supports versions of Python < 2.5. I'm not developing shm any >> further, so avoid using it if possible. > Hmm, we are using FreeBSD, Ubuntu and Windows. Unfortunately > > - posix_ipc is broken under FreeBSD A clarification: the module posix_ipc is *not* broken. It exposes FreeBSD's implementation of POSIX IPC which has broken semaphores (based on my experiments, anyway). The practical result for you is the same but the difference is very important to me as the module author. Fixing the posix_ipc module is under my control, fixing FreeBSD's POSIX IPC is not. > - sysv_ipc does not support message queues at all That's true, but in your original email you said you were looking for "semaphores and shared memory". There was no mention of message queues. I'm working on message queue support, but the Sys V IPC API is a headache and takes longer to code against than the POSIX API. > - shm is not maintained SHM *is* maintained. As I said in my first email and as it says on the Web page, I'm not developing it any further. No further development != unmaintained. Also, it offers only a subset of the features in sysv_ipc, so its status is not of great concern unless you're using Python < 2.5. > - windows is not supported by any of these modules Windows uses a different API, but I think there are some packages that can make Windows look like some flavor of Unix. For instance, Cygwin seems to expose some relevant APIs like sem_open(), sem_post(), etc: http://cygwin.com/cygwin-api/compatibility.html#std-susv3 It might be that posix_ipc would work with this package with just a little tweaking. I have no idea. As I said on the posix_ipc page, if anyone wants to tackle this one and send me bug reports, please do! > It is so interesting that there is no standard implementation for > IPC in Python. I would think it is a very common task for > programmers. I might find myself writting a new IPC module that > works under Windows as well. Feel free to reinvent the wheel. Or, you could pitch in and help with what's already out there. bye Philip From Scott.Daniels at Acm.Org Tue Jan 13 13:13:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 10:13:47 -0800 Subject: exec in a nested function yields an error In-Reply-To: References: Message-ID: TP wrote: > ... > def f(): > def f_nested(): > exec "a=2" > print a > f() > ... What is the problem? Why? What it wants is you to provide the "in context" portion of the exec statement. I expect the reason it fails is that there is no dictionary that is available as locals that encompasses the locals of both f and f_nested, so you'll have to be explicit about what you mean. So, the code wants you to say something like: def f(): def f_nested(): exec "a=2" in globals(), locals() print a return f_nested f() --Scott David Daniels Scott.Daniels at Acm.Org From gandalf at shopzeus.com Tue Jan 13 13:22:48 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 19:22:48 +0100 Subject: Standard IPC for Python? In-Reply-To: <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> Message-ID: <496CDBF8.5020402@shopzeus.com> >> >> - posix_ipc is broken under FreeBSD > > A clarification: the module posix_ipc is *not* broken. It exposes > FreeBSD's implementation of POSIX IPC which has broken semaphores > (based on my experiments, anyway). The practical result for you is the > same but the difference is very important to me as the module author. > Fixing the posix_ipc module is under my control, fixing FreeBSD's > POSIX IPC is not. Mea culpa. :-) I did not want to offend you. >> - sysv_ipc does not support message queues at all > > That's true, but in your original email you said you were looking for > "semaphores and shared memory". There was no mention of message queues. You are right again. :-) I would like to use IPC beacuse I want to send messages between processes. >> - shm is not maintained > > SHM *is* maintained. As I said in my first email and as it says on the > Web page, I'm not developing it any further. No further development != > unmaintained. My bad again. :-( This is not my day. >> It is so interesting that there is no standard implementation for IPC >> in Python. I would think it is a very common task for programmers. I >> might find myself writting a new IPC module that works under Windows >> as well. > > Feel free to reinvent the wheel. Or, you could pitch in and help with > what's already out there. From invalid at invalid Tue Jan 13 13:23:26 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 13 Jan 2009 12:23:26 -0600 Subject: Ethernet packet size python References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: On 2009-01-13, Steve Holden wrote: > K-man wrote: >> >> I am sending data using the socket interface in python, but I >> want to know how big the ethernet packet size is (in bytes). >> I didn't really see a way using the socket library of how to >> do this. Any suggestions? > > There is no way to know what size Ethernet packets will result > from specific traffic. Unless he's using a low level API such as AF_PACKET/SOCK_RAW. If that's the case then the packets will be exactly as big as he makes them. And he wouldn't be asking this question. :) > Or do you want to know the MTU size (largest possible Ethernet > packet size)? This shouldn't really matter, since large TCP > messages will be split into a sequence of IP datagrams, and > large IP datagrams will be automatically fragmented and then > reassembled at the other end. > > Is there a specific reason this is important to you? If it's just idle curiosity, then wireshark or tcpdump can show one exactly what's going on on the wire. A reading of http://en.wikipedia.org/wiki/Transmission_Control_Protocol should also allow one to predict pretty accurately what's going to happen when you call send(). -- Grant Edwards grante Yow! I want EARS! I want at two ROUND BLACK EARS visi.com to make me feel warm 'n secure!! From jeff at jmcneil.net Tue Jan 13 13:28:24 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 13 Jan 2009 10:28:24 -0800 (PST) Subject: Simple CGI-XMLRPC failure References: Message-ID: I don't have the version in front of me now as that was on my home machine, but Python was the same right down to the revision number. Unless you've mucked with it, it's the same file that I've got on my box. Jeff On Jan 13, 10:51 am, "Mike MacHenry" wrote: > I figured it was some kind of bug. Must be either a bug with my > version of either the library (most likely) or perhaps some weird > environment setting that I have set incorrectly (also likely). How can > I figure out which version of SimpleXMLRPCServer I'm running? Do you > run Ubuntu by any chance? If you which version? > > Does anyone know of any environment settings I could look into on > Apache or Python? > > -mike > > On Mon, Jan 12, 2009 at 9:02 PM, Jeff McNeil wrote: > > On Jan 12, 12:40 pm, "Mike MacHenry" wrote: > >> I am having a difficult time understanding why my very simple > >> CGI-XMLRPC test isn't working. I created a server to export two > >> functions, the built-in function "pow" and my own identity function > >> "i". I run a script to call both of them and the "pow" work fine but > >> the "i" gives me an error that says my XMLRPC server doesn't support > >> than name. Here is the code for both files and the output: > > >> #!/usr/bin/env python > >> #This file is /usr/lib/cgi-bin/roundwarerpc.py > >> from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > >> def i(x): > >> return x > >> server = CGIXMLRPCRequestHandler() > >> server.register_function(pow) > >> server.register_function(i) > >> server.handle_request() > > >> #!/usr/bin/env python > >> #This file is ~/test.py > >> import xmlrpclib > >> server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > >> print server.pow(2,3) > >> print server.i(10) > > >> #This is the STDOUT and STDERR when running ~/test.py > >> dskippy at dskippy-laptop:$ python test.py 8 > >> Traceback (most recent call last): > >> File "test.py", line 4, in > >> print server.test(10) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > >> return self.__send(self.__name, args) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > >> verbose=self.__verbose > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > >> return self._parse_response(h.getfile(), sock) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > >> return u.close() > >> File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > >> raise Fault(**self._stack[0]) > >> xmlrpclib.Fault: :method "i" > >> is not supported'> > > >> Does anyone know what might be wrong with this? > > >> Thanks for the help, > >> -mike > > >> p.s. > >> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > >> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > >> Server version Apache/2.2.8 (Ubuntu) > >> Server built: Jun 25 2008 13:54:13 > > > I copied your code verbatim and I don't have any issues with it at > > all. Same version of Python, same version of Apache. > > > In SimpleXMLRPCServer.py, register_function adds directly to a > > self.funcs dictionary, so an instance variable of the same name > > shouldn't hurt anything. That exception is only raised when a > > self.funcs lookup raises a KeyError unless you're registering an > > instance. > > > -- > >http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Tue Jan 13 13:39:47 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 13 Jan 2009 12:39:47 -0600 Subject: Converting from PyUnicodeObject to char * without calling C API In-Reply-To: <496CB4D4.8070407@mrabarnett.plus.com> References: <18796.45853.852587.379554@montanaro.dyndns.org> <496CB4D4.8070407@mrabarnett.plus.com> Message-ID: <18796.57331.670546.510420@montanaro.dyndns.org> MRAB> Should you be using "char *" when they aren't char? Is there a MRAB> wide char type of some sort? No, I shouldn't. The storage is wchar_t *, what you get with my first printed expression: (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) (gdb) p *$__f->str@$__f->length $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} That's not too readable. I'm not sure I can do much with that without having a process to use. Ideally: print "".join([ chr(x) for x in *$__f->str@$__f->length]) The question is, how do you do that in gdb-speak??? Skip From philip at semanchuk.com Tue Jan 13 13:55:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 13:55:17 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CDBF8.5020402@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> Message-ID: <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> On Jan 13, 2009, at 1:22 PM, Laszlo Nagy wrote: > >>> >>> - posix_ipc is broken under FreeBSD >> >> A clarification: the module posix_ipc is *not* broken. It exposes >> FreeBSD's implementation of POSIX IPC which has broken semaphores >> (based on my experiments, anyway). The practical result for you is >> the same but the difference is very important to me as the module >> author. Fixing the posix_ipc module is under my control, fixing >> FreeBSD's POSIX IPC is not. > Mea culpa. :-) I did not want to offend you. Thank you, Laszlo, I appreciate that. > >>> - sysv_ipc does not support message queues at all >> >> That's true, but in your original email you said you were looking >> for "semaphores and shared memory". There was no mention of message >> queues. > You are right again. :-) I would like to use IPC beacuse I want to > send messages between processes. If you can wait a bit and Windows is not crucial, sysv_ipc should have message queue support before too long. >>> - shm is not maintained >> >> SHM *is* maintained. As I said in my first email and as it says on >> the Web page, I'm not developing it any further. No further >> development != unmaintained. > My bad again. :-( This is not my day. >>> It is so interesting that there is no standard implementation for >>> IPC in Python. I would think it is a very common task for >>> programmers. I might find myself writting a new IPC module that >>> works under Windows as well. >> >> Feel free to reinvent the wheel. Or, you could pitch in and help >> with what's already out there. I realize that lack of Windows support is a big minus for both of these modules. As I said, any help getting either posix_ipc or sysv_ipc working under Windows would be much appreciated. It sounds like you have access to the platform and incentive to see it working, so dig in if you like. Once I get message queues working for SysV, I want to support unnamed semaphores in the POSIX module and then I'll consider these modules mainly feature-complete. After that I can think about adding more features like: - Windows support - Python 2.6/3.0 support - buffer-style access to shared memory (slicing, etc.) - Merging these two into a generic ipc module that's agnostic about POSIX versus Sys V. That might not be realistic. If I have time in the future, I'll tackle these items myself. But these projects are just educational for me and paying work will take priority. bye Philip From gandalf at shopzeus.com Tue Jan 13 14:01:32 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 20:01:32 +0100 Subject: Standard IPC for Python? In-Reply-To: <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> Message-ID: <496CE50C.6000308@shopzeus.com> > > I realize that lack of Windows support is a big minus for both of > these modules. As I said, any help getting either posix_ipc or > sysv_ipc working under Windows would be much appreciated. It sounds > like you have access to the platform and incentive to see it working, > so dig in if you like. Maybe I can help with windows. I just need to figure out what to use: pipes or windows sockets? http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx From philip at semanchuk.com Tue Jan 13 14:37:39 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 14:37:39 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CE50C.6000308@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2009, at 2:01 PM, Laszlo Nagy wrote: > >> >> I realize that lack of Windows support is a big minus for both of >> these modules. As I said, any help getting either posix_ipc or >> sysv_ipc working under Windows would be much appreciated. It sounds >> like you have access to the platform and incentive to see it >> working, so dig in if you like. > Maybe I can help with windows. I just need to figure out what to > use: pipes or windows sockets? > > http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx I was suggesting getting posix_ipc or sysv_ipc to compile against a compatibility library (Cygwin?) under Windows. It sounds like you're proposing something totally different, no? From andygrove73 at gmail.com Tue Jan 13 14:54:07 2009 From: andygrove73 at gmail.com (ag73) Date: Tue, 13 Jan 2009 11:54:07 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError Message-ID: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Hi, I am trying to parse data posted to a Python class that extends http.server.BaseHTTPRequestHandler. Here is the code I am using: def do_POST(self): ctype, pdict = cgi.parse_header(self.headers['Content-Type']) length = int(self.headers['Content-Length']) if ctype == 'application/x-www-form-urlencoded': qs = self.rfile.read(length) print("qs="+str(qs)) form = urllib.parse.parse_qs(qs, keep_blank_values=1) The print statement shows the following output, so it looks like the data is being posted correctly: qs=b'file_data=b %27IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCiMgZW5jb2Rpbmc6IHV0Zi04CiIiIgp1bnRpdGxlZC5weQoK %5CnQ3JlYXRlZCBieSBBbmR5IEdyb3ZlIG9uIDIwMDgtMTItMDIuCkNvcHlyaWdodCAoYykgMjAwOCBf %5CnX015Q29tcGFueU5hbWVfXy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4KIiIiCgppbXBvcnQgc3lzCmlt %5CncG9ydCBvcwoKCmRlZiBtYWluKCk6CglwcmludCAibmFtZTE9dmFsdWUxIgoJcHJpbnQgIm5hbWUy %5CnPXZhbHVlMiIKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgoJbWFpbigpCgo%3D %5Cn%27&filename=test.py' However, the last line of code that calls parse_qs causes the following exception to be thrown: Type str doesn't support the buffer API I haven't been able to find any information on the web about this. Any pointers would be appreciated. I am using ActivePython 3.0 and have tried this on Linux and Max OS X with the same outcome. Thanks, Andy. From sromero at gmail.com Tue Jan 13 15:02:54 2009 From: sromero at gmail.com (Santiago Romero) Date: Tue, 13 Jan 2009 12:02:54 -0800 (PST) Subject: Read binary file and dump data in Message-ID: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Hi. Until now, all my python programs worked with text files. But now I'm porting an small old C program I wrote lot of years ago to python and I'm having problems with datatypes (I think). some C code: fp = fopen( file, "rb"); while !feof(fp) { value = fgetc(fp); printf("%d", value ); } I started writing: fp = open(file, "rb") data = fp.read() for i in data: print "%d, " % (int(i)) But it complains about i not being an integer... . len(data) shows exactly the file size, so maybe is a "type cast" problem... :-? What's the right way to work with the binary data (read 1 byte values and work with them, dumping them as an integer in this case)? Thanks. From gandalf at shopzeus.com Tue Jan 13 15:04:04 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 21:04:04 +0100 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <496CF3B4.4040709@shopzeus.com> > > I was suggesting getting posix_ipc or sysv_ipc to compile against a > compatibility library (Cygwin?) under Windows. It sounds like you're > proposing something totally different, no? OK I see. But probably I do not want to use Cygwin because that would create another dependency. I understand that posix_ipc/sysv is not natively supported under windows. What about this: - create a wrapper, using ctypes, /windll / cdll/ to access API functions - use CreateFileMapping on the page file to create shared memory (a la windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) - use CreateEvent/WaitForSingleObject for signaling (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) - these should be enough to implement shared memory functions and message queues under windows, and that might be a quick solution at least for me. - it might also be used to emulate the same posix_ipc interface, without any external dependency added (cygwin). All I care about is to create a working message queue. But if you think that this ctypes hack would be useful for other users, then I can try to implement it. I must tell you that I'm not very familiar with C programming (it was a long time ago...) and I do not own MSVC. (Hmm, can I compile this with mingw?) Laszlo From marduk at letterboxes.org Tue Jan 13 15:18:37 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 15:18:37 -0500 Subject: Read binary file and dump data in In-Reply-To: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: <1231877917.3422.26.camel@localhost.localdomain> On Tue, 2009-01-13 at 12:02 -0800, Santiago Romero wrote: > Hi. > > Until now, all my python programs worked with text files. But now I'm > porting an small old C program I wrote lot of years ago to python and > I'm having problems with datatypes (I think). > > some C code: > > fp = fopen( file, "rb"); > while !feof(fp) > { > value = fgetc(fp); > printf("%d", value ); > } > > I started writing: > > fp = open(file, "rb") > data = fp.read() > for i in data: > print "%d, " % (int(i)) > > But it complains about i not being an integer... . len(data) shows > exactly the file size, so maybe is a "type cast" problem... :-? > int() expects something that "looks like" an integer. E.g. int(2) => 2 int(2.0) => 2 int('2') => 2 int('c') => ValueError If you are reading arbitrary bytes then it will likely not always "look" like integers. What you probably meant is: for i in data: print "%d, " % ord(i) But if you are really dealing with C-like data structures then you might be better off using the struct module. -a From imageguy1206 at gmail.com Tue Jan 13 15:43:27 2009 From: imageguy1206 at gmail.com (imageguy) Date: Tue, 13 Jan 2009 12:43:27 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <6e62a728-e441-4e24-8ace-c210f6508223@n33g2000pri.googlegroups.com> On Jan 13, 1:01?am, Miles wrote: > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > > Using py2.5.4 and entering the following lines in IDLE, I don't really > > understand why I get the result shown in line 8. > > > Note the difference between lines 7 and 10 is that 'else' clause > > result enclosed in brackets, however, in line 2, both the 'c,d' > > variables are assign correctly without the brackets being required. > > > 1) >>> n = None > > 2) >>> c,d = n if n is not None else 0,0 > > 3) >>> print c,d, type(c), type(d) > > 4) 0 0 > > The ternary expression has higher precedence than the comma, so the > actual effect of line 2 (and 8) is: > > >>> c, d = (n if n is not None else 0), 0 > > Or written more explicitly: > > >>> c = n if n is not None else 0 > >>> d = 0 > > So the only correct way to write the expression, for the result you > want, is to use your line 10: > > > 10) ?>>> c,d = n if n is not None else (0,0) > > But if you're struggling with the precedence issues, I'd recommend > ditching ternary expressions altogether and using full conditional > blocks. > > -Miles Thanks. Hadn't thought through the operator precedence and the affect of the comma. This was the first time I tried to use with tuples, so will be more careful next time or stick to control blocks. g. From orsenthil at gmail.com Tue Jan 13 15:48:29 2009 From: orsenthil at gmail.com (Phoe6) Date: Tue, 13 Jan 2009 12:48:29 -0800 (PST) Subject: Previous PyCon Videos, anyone? Message-ID: Hello All, Youtube channel of pycon09 has some videos ( http://www.youtube.com/user/pycon08), but most of them don't have a sufficiently good audio quality. Is there anyone who has better recording of an earlier PyCon talk? If yes, can you please point me to the location? Thanks, Senthil From clp2 at rebertia.com Tue Jan 13 15:50:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 12:50:10 -0800 Subject: Read binary file and dump data in In-Reply-To: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: <50697b2c0901131250g2f64ee91kb10322ccfca50ee9@mail.gmail.com> On Tue, Jan 13, 2009 at 12:02 PM, Santiago Romero wrote: > > Hi. > > Until now, all my python programs worked with text files. But now I'm > porting an small old C program I wrote lot of years ago to python and > I'm having problems with datatypes (I think). > > some C code: > > fp = fopen( file, "rb"); > while !feof(fp) > { > value = fgetc(fp); > printf("%d", value ); > } > > I started writing: > > fp = open(file, "rb") > data = fp.read() > for i in data: > print "%d, " % (int(i)) > > But it complains about i not being an integer... . len(data) shows > exactly the file size, so maybe is a "type cast" problem... :-? > > What's the right way to work with the binary data (read 1 byte values > and work with them, dumping them as an integer in this case)? Albert already pointed out the problem with using int(), so I'll just say that you might be interested in the `struct` module: http://docs.python.org/library/struct.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Russ.Paielli at gmail.com Tue Jan 13 15:58:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 12:58:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> On Jan 13, 9:47 am, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : > > > On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > > >> Bruno Desthuilliers writes: > >>> Why on earth are you using Python if you don't like the way it work ??? > >> Why on earth keep releasing new versions of Python if the old ones are > >> already perfect? > > > That's a fallacious argument. Nobody is arguing that any specific version > > of Python is perfect, but clearly many people do like the general design > > choices of the language, that is, the way it works. > > Thanks for making my point clear. > > > *If* you don't like the way it works, and you have a choice in the > > matter, perhaps you should find another language that works more the way > > you would prefer. > > > On the other hand... Bruno's question is unfair. It is perfectly > > reasonable to (hypothetically) consider Python to be the best *existing* > > language while still wanting it to be improved (for some definition of > > improvement). > > And that's the problem : what Paul suggests are not "improvements" but > radical design changes. The resulting language - whatever it may be > worth, I'm not making any judgement call here - would not be Python > anymore. > > > Just because somebody has criticisms of Python, or a wish- > > list of features, doesn't mean they hate the language. > > There's probably a whole range of nuances between "not liking" and > "hating". And Paul is of course perfectly right to think that a language > having this and that features from Python, but not this other one, would > be a "better" language (at least according to it's own definition of > "better"). Where I totally disagree is that it would make *Python* better. > > Also, my question was not that "unfair" (even if a bit provocative). I > really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of course > they are free to choose another language). And FWIW, I at least had a > partial answer on this. I think the issue here is the distinction between hacking and software engineering. I may be misusing the term "hacking," but I do not mean it in a pejoritive sense. I just mean getting things done fast without a lot of concern for safety, security, and long-term maintainability and scalability. I'm not a computer scientist, but it seems to me that Python is great for hacking and good for software engineering, but it is not ideal for software engineering. What Paul is suggesting, I think, is that Python should move in the direction of software engineering. Whether that can be done without compromising its hacking versatility is certainly a valid question, but if it can be done, then why not do it? Certainly one basic principle of software engineering is data encapsulation. Tacking new attributes onto class instances all over the place may be convenient and useful in many cases, but it is not consistent with good software engineering. If the programmer could somehow disallow it in certain classes, that could be useful, providing that those who wish to continue doing it would be free to do so. If class attributes could somehow be declared private, that would be useful too. Optional explicit type declarations could also be useful -- and I believe Python does have that now, so no need to argue about that. Why do I continue to use Python when I have so many "complaints" about it? As everyone here knows, it has many good qualities. My work falls somewhere in the middle between "hacking" and software engineering. I am developing a research prototype of a safety-critical system. A research prototype is not safety-critical itself, and it needs to be flexible enough to try new ideas quickly, but it also needs to serve as a model for a well-engineered system. Is Python the right choice? I think so, but I don't know for sure. From gregsaundersemail at gmail.com Tue Jan 13 16:11:35 2009 From: gregsaundersemail at gmail.com (Greg) Date: Tue, 13 Jan 2009 13:11:35 -0800 (PST) Subject: Reminder: Calgary Python User Group - 1st Meeting tomorrow - Wed Jan 14 Message-ID: <75ea4945-e8f0-4e11-9b0e-f501e5f05fc7@l33g2000pri.googlegroups.com> Our first meeting is tomorrow night at: Good Earth Cafe, 1502 11 Street SW, Calgary, AB Wed Jan 14, 7pm - 8pm Topic: Google App Engine http://www.google.com/calendar/event?eid=Z2Q0cDdpYmJobzVzbzZobXJxbTc2OHUxYW9fMjAwOTAxMTVUMDIwMDAwWiBhZG1pbkBweXRob25jYWxnYXJ5LmNvbQ&ctz=America/Edmonton Google Group / mailing list: http://groups.google.ca/group/pythoncalgary Website: http://www.pythoncalgary.com/ Thanks Greg From drobinow at gmail.com Tue Jan 13 16:31:34 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Tue, 13 Jan 2009 13:31:34 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2:37?pm, Philip Semanchuk wrote: > On Jan 13, 2009, at 2:01 PM, Laszlo Nagy wrote: > > > > >> I realize that lack of Windows support is a big minus for both of ? > >> these modules. As I said, any help getting either posix_ipc or ? > >> sysv_ipc working under Windows would be much appreciated. It sounds ? > >> like you have access to the platform and incentive to see it ? > >> working, so dig in if you like. > > Maybe I can help with windows. I just need to figure out what to ? > > use: pipes or windows sockets? > > >http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx > > I was suggesting getting posix_ipc or sysv_ipc to compile against a ? > compatibility library (Cygwin?) under Windows. It sounds like you're ? > proposing something totally different, no? It's not really correct to call Cygwin a compatibility library. It's more of a separate system. In any case, the current version (1.5.25) does not support sem_unlink or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under test, will support these. I haven't tried it yet. I expect it will work OOTB. From castironpi at gmail.com Tue Jan 13 16:54:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 13:54:58 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <0b91a5c9-01a0-4c6e-aa73-853c6a21611e@s20g2000yqh.googlegroups.com> On Jan 13, 2:04?pm, Laszlo Nagy wrote: > - create a wrapper, using ctypes, /windll / cdll/ to access API functions > - use CreateFileMapping on the page file to create shared memory (a la > windows:http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling > (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. > - it might also be used to emulate the same posix_ipc interface, without > any external dependency added (cygwin). > > All I care about is to create a working message queue. But if you think > that this ctypes hack would be useful for other users, then I can try to > implement it. > > I must tell you that I'm not very familiar with C programming (it was a > long time ago...) and I do not own MSVC. > > (Hmm, can I compile this with mingw?) > > Laszlo Yes. The flags in the Extending/Embedding C++ section work with mingw. You can create inheritable pipes with the CreatePipe API. 'mmap' provides shared memory, and it's a standard module. You may also like the 'multiprocessing' module, which comes with Python 2.6. From sjmachin at lexicon.net Tue Jan 13 16:58:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 13:58:36 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <54e40cc1-8133-43ba-813d-a2498784a93f@f20g2000yqg.googlegroups.com> On Jan 13, 5:36?pm, Steve Holden wrote: > Miles wrote: > > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > >> Using py2.5.4 and entering the following lines in IDLE, I don't really > >> understand why I get the result shown in line 8. > > >> Note the difference between lines 7 and 10 is that 'else' clause > >> result enclosed in brackets, however, in line 2, both the 'c,d' > >> variables are assign correctly without the brackets being required. > > >> 1) >>> n = None > >> 2) >>> c,d = n if n is not None else 0,0 > >> 3) >>> print c,d, type(c), type(d) > >> 4) 0 0 > > > The ternary expression has higher precedence than the comma, so the > > actual effect of line 2 (and 8) is: > > >>>> c, d = (n if n is not None else 0), 0 > > > Or written more explicitly: > > >>>> c = n if n is not None else 0 > >>>> d = 0 > > > So the only correct way to write the expression, for the result you > > want, is to use your line 10: > > >> 10) ?>>> c,d = n if n is not None else (0,0) > > > But if you're struggling with the precedence issues, I'd recommend > > ditching ternary expressions altogether and using full conditional > > blocks. > > Yet another great example of why Guido was right to resist putting > conditional expressions into Python for so long (and wrong to succumb to > the demand). """I thought I said "Nobody mention the war!" """ IMO this is just an example of why (1) in general people who are unsure of operator precedence should use parentheses and (2) in particular it's not a good idea to try to write tuples without parentheses in any but the simpler cases like a, b = b, a From castironpi at gmail.com Tue Jan 13 16:59:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 13:59:50 -0800 (PST) Subject: ctype problem References: Message-ID: <6197f37d-0ea0-4430-a466-2f36b2011ea8@v42g2000yqj.googlegroups.com> On Jan 13, 10:22?am, Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > ? ? int a; > ? ? int b; > ? ? char *c; > > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > ? ? _fields_ = [("a" ? ? ? ? c_int), > ? ? ? ? ? ? ? ? ? ? ? ("b", ? ? ? ?c_int), > ? ? ? ? ? ? ? ? ? ? ? ("c", ? ? ? ? c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? > > Thank you.. > > sincerely chris Did you remember to define myclib.myfunction.argtypes= [ INTERFACE ] ? From http Tue Jan 13 17:03:07 2009 From: http (Paul Rubin) Date: 13 Jan 2009 14:03:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: <7xk58yn9t0.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > And that's the problem : what Paul suggests are not "improvements" but > radical design changes. Eh? I think of them as moderate and incremental improvements, in a direction that Python is already moving in. Radical would be something like a full-scale static type system. > I really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of > course they are free to choose another language). I certainly don't think dynamism is central to Python. In what I see as well-developed Python programming style, it's something that is only rarely used in any important way. I'd spend much less time debugging if I got compiler warnings whenever I used dynamism without a suitable annotation. The 1% of the time where I really want to use dynamism I don't see any problem with putting in an appropriate decorator, superclass, or whatever. From philip at semanchuk.com Tue Jan 13 17:05:21 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 17:05:21 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CF3B4.4040709@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <496CF3B4.4040709@shopzeus.com> Message-ID: <8383FE60-36B4-4810-BCB8-61A1FED3C85C@semanchuk.com> On Jan 13, 2009, at 3:04 PM, Laszlo Nagy wrote: > >> >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like >> you're proposing something totally different, no? > OK I see. But probably I do not want to use Cygwin because that > would create another dependency. I understand that posix_ipc/sysv is > not natively supported under windows. What about this: > > - create a wrapper, using ctypes, /windll / cdll/ to access API > functions > - use CreateFileMapping on the page file to create shared memory (a > la windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx > ) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. Python has the mmap module which might work a lot like shared memory. I'm not clear on the differences, honestly. Named pipes might be a cleaner way to implement message queues: http://msdn.microsoft.com/en-us/library/aa365590(VS.85).aspx > - it might also be used to emulate the same posix_ipc interface, > without any external dependency added (cygwin). It'd be nice to have message queues/named pipes working under Windows. If I were you, I'd steer clear of calling them something specific like "SysV" or "POSIX" messages queues. That will create an expectation of certain semantics, and you might find it difficult to fulfill that promise in certain cases (e.g. implementing the POSIX function mq_notify() ). If you call them Nagy message queues then no one will be disappointed or surprised as long as your code implements FIFO IPC. Bye Philip From philip at semanchuk.com Tue Jan 13 17:08:02 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 17:08:02 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> On Jan 13, 2009, at 4:31 PM, drobinow at gmail.com wrote: > On Jan 13, 2:37 pm, Philip Semanchuk wrote: >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like you're >> proposing something totally different, no? > > It's not really correct to call Cygwin a compatibility library. It's > more of a separate system. Thanks for the education; I'm obviously not very familiar with it. > In any case, the current version (1.5.25) does not support sem_unlink > or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under > test, will support these. I haven't tried it yet. I expect it will > work OOTB. Thanks for the report. Strange that it supports the functions to open but not close semaphores. IN any case, I'd be very happy if posix_ipc or sysv_ipc would work with few or no modifications under Cygwin. Cheers Philip From sjmachin at lexicon.net Tue Jan 13 17:08:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 14:08:36 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: On Jan 14, 6:54?am, ag73 wrote: > Hi, > > I am trying to parse data posted to a Python class that extends > http.server.BaseHTTPRequestHandler. Here is the code I am using: > > ? ? ? ? def do_POST(self): > ? ? ? ? ? ? ? ? ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > ? ? ? ? ? ? ? ? length = int(self.headers['Content-Length']) > ? ? ? ? ? ? ? ? if ctype == 'application/x-www-form-urlencoded': > ? ? ? ? ? ? ? ? ? ? ? ? qs = self.rfile.read(length) > ? ? ? ? ? ? ? ? ? ? ? ? print("qs="+str(qs)) > ? ? ? ? ? ? ? ? ? ? ? ? form = urllib.parse.parse_qs(qs, keep_blank_values=1) > > The print statement shows the following output, so it looks like the > data is being posted correctly: > > qs=b'file_data=b > %27IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCiMgZW5jb2Rpbmc6IHV0Zi04CiIiIgp1bnRpdGxlZC5w?eQoK > %5CnQ3JlYXRlZCBieSBBbmR5IEdyb3ZlIG9uIDIwMDgtMTItMDIuCkNvcHlyaWdodCAoYykgMjA?wOCBf > %5CnX015Q29tcGFueU5hbWVfXy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4KIiIiCgppbXBvcnQgc3l?zCmlt > %5CncG9ydCBvcwoKCmRlZiBtYWluKCk6CglwcmludCAibmFtZTE9dmFsdWUxIgoJcHJpbnQgIm5?hbWUy > %5CnPXZhbHVlMiIKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgoJbWFpbigpCgo%3D > %5Cn%27&filename=test.py' > > However, the last line of code that calls parse_qs causes the > following exception to be thrown: > > > Type str doesn't support the buffer API Please show the full traceback. From fabiofz at gmail.com Tue Jan 13 17:12:29 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 13 Jan 2009 20:12:29 -0200 Subject: Pydev 1.4.2 Released Message-ID: Hi All, Pydev and Pydev Extensions 1.4.2 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: ----------------------------------------------------------------- * Context insensitive code-completion working with multiple interpreters * Fixed code analysis problem on staticmethod * Giving proper warning on version mismatch * Remote debugger fix Release Highlights in Pydev: ---------------------------------------------- * Interpreter can be configured on a per-project basis * Jython 2.5b0 properly supported * Find definition working for Jython builtins * Run: can be python/jython even if it doesn't match the interpreter configured for the project * Fixed problem on find definition if one of the interpreters was not configured * Fixed halting condition that could occur on code-completion * __file__ available in code-completion * Reorganized preferences (removed editor preferences from the root) * Preferences for showing hover info * Fixed problem when formatting binary operator that was in a new line * When converting spaces to tabs (and vice-versa), the number of spaces for each tab is asked * Debugger o When finishing the user code debugging, it doesn't step into the debugger code anymore o Fixes for working with Jython o Fix for Python 3.0 integration (could not resolve variables) What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com From rupole at hotmail.com Tue Jan 13 17:22:10 2009 From: rupole at hotmail.com (Roger Upole) Date: Tue, 13 Jan 2009 17:22:10 -0500 Subject: Scheduled Tasks - SetFlags References: <88f5dbd9-ffa8-4498-9635-bfba8bdd1193@i18g2000prf.googlegroups.com> Message-ID: kj7ny wrote: > How do I enable/disable a scheduled task using Python? > > I can get to a task: > > self.ts=pythoncom.CoCreateInstance > (taskscheduler.CLSID_CTaskScheduler,None,pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler) > self.ts.SetTargetComputer(u'\\\\SomeServer') > self.tasks=self.ts.Enum() > for task in self.tasks: > self.t=self.ts.Activate(task) > if self.t.GetAccountInformation().lower().find('SomeUser') >>=0: > print self.t.GetFlags() > > I can find if a task is enabled or not and toggle it: > > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Originally Disabled: %s'%(disabled,) > if disabled: > self.t.SetFlags(self.t.GetFlags() & > ~taskscheduler.TASK_FLAG_DISABLED) > else: > self.t.SetFlags(self.t.GetFlags() | > taskscheduler.TASK_FLAG_DISABLED) > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Recheck Disabled: %s'%(disabled,) > > ... "Recheck Disabled" shows that the value "says" it has been > disabled. > > The problem is that if I run it again and again, "Originally Disabled" > is always the same. In other words, "Recheck Disabled" does NOT > stick. It's like I'm missing a .commit() > Your missing commit is spelled pf=t.QueryInterface(pythoncom.IID_IPersistFile) pf.Save(None,1) Roger From kevin.jingqiu at caseware.com Tue Jan 13 17:29:58 2009 From: kevin.jingqiu at caseware.com (Kevin Jing Qiu) Date: Tue, 13 Jan 2009 17:29:58 -0500 Subject: Weird behaviour re: Python on Windows In-Reply-To: <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> References: <496CC069.80909@shopzeus.com><1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com><496CD1F6.3080604@shopzeus.com><4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com><496CDBF8.5020402@shopzeus.com><1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com><496CE50C.6000308@shopzeus.com> <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> Message-ID: I've been experiencing weird behavior of Python's os module on Windows: Here's the environment: Box1: Running Windows 2003 Server with Apache+mod_python Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ on Box1 It appears any os calls that deals with file/dir on the mapped drive is problematic. More specifically, os.stat(path), os.path.exists(path) gives 'File not found' when path is on the mapped drive. Wait, this gets better: when I'm in the debug mode (or Python interactive shell), everything works fine! Os.stat, os.path.exists, os.fstat, etc, worked as expected. I tried PyWin32 extension's GetFileSize() method and the same thing happens: debug or interactive mode works fine, but when Plone is run in non-debug mode, the problems begin. I swear this isn't a Plone problem either. I switched the configuration. Now Box1 has a network drive mapped to Box2's D:\. The custom Apache filter we have (which is written in python executed by mod_python) complains that it can't find the file which is on the mapped drive. So there you go. I'm wondering if anyone else experienced such problem. Any suggestions or input is appreciated! Thanks, Kevin From andygrove73 at gmail.com Tue Jan 13 17:56:35 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 14:56:35 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> On Jan 13, 3:08?pm, John Machin wrote: > Please show the full traceback. John, Thanks. Here it is: File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 307, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 614, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/http/server.py", line 363, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/http/server.py", line 357, in handle_one_request method() File "/Users/andy/Development/EclipseWorkspace/dbsManage/kernel.py", line 178, in do_POST form = urllib.parse.parse_qs(qs, keep_blank_values=1) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/urllib/parse.py", line 351, in parse_qs ---------------------------------------- for name, value in parse_qsl(qs, keep_blank_values, strict_parsing): File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/urllib/parse.py", line 377, in parse_qsl pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] TypeError: Type str doesn't support the buffer API From martin at v.loewis.de Tue Jan 13 17:58:00 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 13 Jan 2009 23:58:00 +0100 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <496D1C78.3060307@v.loewis.de> Steve Holden wrote: > Daniel Fetchinson wrote: >>> I need something to connect to a database, preferably mysql, that >>> works in python3.0 please. >> And your question is? >> >> > Surely it's fairly obvious that the question is "does such a thing > exist, and if so where can I find it?". Interestingly enough, the question was slightly (but importantly) different, though: the question really was "Does anybody has a patch for MySQLdb?"; as my reference to the existing interface to PostgreSQL was not sufficient for the OP. Regards, Martin From kylotan at gmail.com Tue Jan 13 18:06:19 2009 From: kylotan at gmail.com (Ben Sizer) Date: Tue, 13 Jan 2009 15:06:19 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible Message-ID: I have the following C++ code and am attempting to embed Python 2.5, but although the "import sys" statement works, attempting to reference "sys.path" from inside a function after that point fails. It's as if it's not treating it as a normal module but as any other global variable which I'd have to explicitly qualify. Py_InitializeEx(0); // the zero skips registration of signal handlers. PyObject* ourNamespace_ = PyDict_New(); PyDict_SetItemString(ourNamespace_, "__builtins__", PyEval_GetBuiltins()); PyObject* locals = PyDict_New(); const char* scriptStr = "print '1'\n" "import sys\n" "print sys.path\n" "def debug_path_info():\n" " print 'These are the directories Python looks into for modules and source files:'\n" " print '2'\n" " for folder in sys.path:\n" " print folder\n" " print '--------------'\n" " print 'This would be your present working folder/ directory:'\n" " print '3'\n" " print sys.path[0]\n" "debug_path_info()\n"; PyObject* scriptResult = PyRun_String( scriptStr, // Python code to execute Py_file_input, ourNamespace_, // globals dictionary locals); // locals dictionary if (!scriptResult) { std::cerr << "Python error: " << "Unhandled Python exception from script." << std::endl; PyErr_Print(); } else { Py_DECREF(scriptResult); // don't need result any more } Py_DECREF(locals); Py_DECREF(ourNamespace_); Py_Finalize(); And the output is like this: 1 ['E:\\code\\Python25\\lib\\site-packages\\turbokid-1.0.4-py2.5.egg', 'E:\\code\\ Python25\\lib\\site-packages\\turbocheetah-1.0-py2.5.egg', 'E:\\code\ \Python25\\ lib\\site-packages\\simplejson-1.8.1-py2.5-win32.egg', 'E:\\code\ \Python25\\lib\ \site-packages\\ruledispatch-0.5a0.dev_r2306-py2.5-win32.egg', 'E:\ \code\\Python 25\\lib\\site-packages\\pastescript-1.6.2-py2.5.egg', 'E:\\code\ \Python25\\lib\\ site-packages\\formencode-1.0.1-py2.5.egg', 'E:\\code\\Python25\\lib\ \site-packa ges\\decoratortools-1.7-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\\con figobj-4.5.2-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \cherrypy-2.3.0 -py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\\kid-0.9.6- py2.5.egg', 'E:\ \code\\Python25\\lib\\site-packages\\cheetah-2.0.1-py2.5-win32.egg', 'E:\\code\\ Python25\\lib\\site-packages\\pyprotocols-1.0a0-py2.5-win32.egg', 'E:\ \code\\Pyt hon25\\lib\\site-packages\\pastedeploy-1.3.1-py2.5.egg', 'E:\\code\ \Python25\\li b\\site-packages\\paste-1.6-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\ \sqlobject-0.10.0-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \tgfastdat a-0.9a7-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \webhelpers-0.6-py2. 5.egg', 'E:\\code\\Python25\\lib\\site-packages\\shove-0.1.3- py2.5.egg', 'E:\\co de\\Python25\\lib\\site-packages\\boto-1.3a-py2.5.egg', 'E:\\code\ \Python25\\lib \\site-packages\\sqlalchemy-0.5.0beta3-py2.5.egg', 'E:\\code\\Python25\ \lib\\sit e-packages\\turbojson-1.1.4-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\ \setuptools-0.6c9-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \turbogear s-1.0.8-py2.5.egg', 'C:\\WINDOWS\\system32\\python25_d.zip', 'E:\\code\ \Python25 \\Lib', 'E:\\code\\Python25\\DLLs', 'E:\\code\\Python25\\Lib\\lib-tk', 'e:\\Visu al Studio 2008\\Projects\\StacklessEmbed\\StacklessEmbed', 'e:\\Visual Studio 20 08\\Projects\\StacklessEmbed\\Debug', 'E:\\code\\Python25', 'E:\\code\ \Python25\ \lib\\site-packages', 'E:\\code\\Python25\\lib\\site-packages\\PIL', 'E:\\code\\ Python25\\lib\\site-packages\\wx-2.8-msw-unicode'] These are the directories Python looks into for modules and source files: 2 Python error: Unhandled Python exception from script. Traceback (most recent call last): File "", line 13, in File "", line 7, in debug_path_info NameError: global name 'sys' is not defined [12532 refs] (Incidentally, the Stackless references are because I was originally trying to embed Stackless, but I reverted to vanilla 2.5 to see if it was a Stackless specific issue, which it appears not.) Another interesting thing is that sys.path[0] doesn't appear to be the current working directory, despite several sources online suggesting it should be. What am I doing wrong? -- Ben Sizer From mdw at distorted.org.uk Tue Jan 13 18:06:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 13 Jan 2009 23:06:58 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I found it interesting. Well, that's something, at any rate. > I think this conversation is reaching it's natural end. Frustration > levels are rising. I think you may be right. That said... > So I'm going to take a different tack in an attempt to reduce > frustration levels: if I can't convince the other side they're wrong, > can I at least get them to understand where I'm coming from a little > better? Maybe... > As I see it, this conversation is floundering on two radically different > ideas about what it means to say a language uses pass-by-foo. You might be right, but I'm unconvinced. > On the one hand, some people (me and possibly rurpy) consider "this is > pass-by-foo" to be a statement about behaviour directly visible to the > programmer. We have a set of behavioral traits in mind, and if a language > exhibits those behaviours, then it is clearly and obviously pass-by-foo > no matter how that behaviour is implemented. I'll call these the > behaviorists. Here's the problem. I think I'm in that camp too! I'm going to move away from the formal semantics stuff and try a different tack. Here's what I think is the defining property of pass-by-value (distilled from the formal approach I described earlier, but shorn of the symbolism): The callee's parameters are /new variables/, initialized /as if by assignment/ from the values of caller's argument expressions. I'd just like to examine that for a bit. Firstly, let's expand it from the soundbite: basically what it says is that you should be able to replace function mumble(a, b, c) { stuff in terms of a, b, and c } ... mumble(1 + 2, xyz, whatever) with ... fresh_a = 1 + 2 fresh_b = xyz fresh_c = whatever stuff in terms of fresh_a, fresh_b, and fresh_c with no observable difference (here, fresh_a and so on are a variable names not appearing in the rest of the program). So: * It captures C's behaviour (at least if you don't count arrays -- let's not open that one again), and Pascal's normal behaviour. Assigning to the parameters doesn't affect the caller's argument variables because the parameters are fresh variables. * It /doesn't/ capture Fortran's behaviour, or Pascal's `var' parameters, because obviously assignment to parameters in Fortran /can/ affect the caller's argument variables * It also doesn't capture exotic things like Algol's call by name, and lazy evaluation, because there's an evaluation step in there. My soundbite definition for pass-by-reference is this: The callee's parameters are merely /new names/ for the caller's argument variables -- as far as that makes sense. There's a caveat there for argument expressions which don't correspond directly to variables -- and I've glossed over the issue of lvalue expressions which designate locations and all of that. The idea is that you can replace function mumble(a, b) { stuff in terms of a and b } ... mumble(xyz, whatever) by ... stuff in terms of xyz and whatever This does indeed capture Fortran, and Pascal's `var', while excluding C and Pascal non-`var'. Good! So... obviously I'm going to claim that Python is pass-by-value. Why? Because its argument passing works the same way as its assignment. But! (you claim) ... > Python simply can't be pass-by-value, because it doesn't behave like > pass-by-value in other languages (particularly C and Pascal). Ah! (say I) but assignment in C and Pascal looks different from the way it looks in C -- and in exactly the same way that argument passing looks different. And there, I think, I'm going to rest my case. I'm sorry I took so long to distill these thoughts. Thank you for putting up with my theoretical meanderings on the way. -- [mdw] From pavlovevidence at gmail.com Tue Jan 13 18:07:57 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 15:07:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> Message-ID: <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> On Jan 13, 4:03?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > And that's the problem : what Paul suggests are not "improvements" but > > radical design changes. > > Eh? ?I think of them as moderate and incremental improvements, in a > direction that Python is already moving in. I've seen no evidence that any Python project is moving even remotely toward data encapsulation. That would be a drastic change. Even if it were only a minor change in the implementation (and it would not be), it would be a major stroke in the Python community. It would basically cause a wholescale power shift from the user to the implementor. As a user it'd be like the difference between living in a free democracy and a fascist dictatorship. > ?Radical would be > something like a full-scale static type system. > > > I really wonder why peoples that seems to dislike one of the central > > features of Python - it's dynamism - still use it (assuming of > > course they are free to choose another language). > > I certainly don't think dynamism is central to Python.?In what I see > as well-developed Python programming style, it's something that is > only rarely used in any important way. You're in the minority, then. >?I'd spend much less time > debugging if I got compiler warnings whenever I used dynamism without > a suitable annotation. ?The 1% of the time where I really want to use > dynamism I don't see any problem with putting in an appropriate > decorator, superclass, or whatever. Well, I guess you are the sacrifical lamb so that everyone else can take advantage of the dynamicism. Carl Banks From andygrove73 at gmail.com Tue Jan 13 18:10:52 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 15:10:52 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> Message-ID: I don't fully understand this but if I pass in "str(qs)" instead of "qs" then the call works. However, qs is returned from file.read() operation so shouldn't that be a string already? In case it's not already obvious, I am new to Python :-) .. so I'm probably missing something here. From andygrove73 at gmail.com Tue Jan 13 18:24:57 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 15:24:57 -0800 (PST) Subject: cgi.FieldStorage hanging with Python 3.0 (but works with 2.5.1) Message-ID: I'm trying to get a Python web server running that I can upload files to. I actually have the code running with the version of Python pre- installed on Mac OS X but it doesn't work with ActivePython 3.0 - I have not been able to compile Python from source myself to see if the issue is specific to the ActivePython distribution. Here is the relevant code: class MyHandler(http.server.BaseHTTPRequestHandler): def do_POST(self): try: print( "Calling cgi.FieldStorage()" ) form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content- Type'], }) print( "Calling cgi.FieldStorage()" ) The client is the following HTML form being submitted with Firefox 3.0.5 running on the same machine. The browser also hangs, waiting for a response from the server.
File:
 
As I said, this all works fine with Python 2.5.1 pre-installed. Any suggestions? Thanks, Andy. From mwilson at the-wire.com Tue Jan 13 18:41:51 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 13 Jan 2009 18:41:51 -0500 Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: Philip Semanchuk wrote: > I'm working on message queue support, but the Sys V IPC API is a > headache and takes longer to code against than the POSIX API. I hadn't found it that bad. I have a C extension I should perhaps clean up and make public. Mel. From tjreedy at udel.edu Tue Jan 13 18:47:35 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 18:47:35 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CF3B4.4040709@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <496CF3B4.4040709@shopzeus.com> Message-ID: Laszlo Nagy wrote: > >> >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like you're >> proposing something totally different, no? > OK I see. But probably I do not want to use Cygwin because that would > create another dependency. I understand that posix_ipc/sysv is not > natively supported under windows. What about this: > A few comments: First, the issue of cross-platform IPC, and its difficulties, has come up occasionally, but most with the knowledge of writing stuff for one system (esp. Windows) tend to stick with that system. > - create a wrapper, using ctypes, /windll / cdll/ to access API functions ctypes was only added in 2.5. It should make some things easier than they would have been before. > - use CreateFileMapping on the page file to create shared memory (a la > windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling > (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. > - it might also be used to emulate the same posix_ipc interface, without > any external dependency added (cygwin). That would be good. > > All I care about is to create a working message queue. But if you think > that this ctypes hack would be useful for other users, then I can try to > implement it. > > I must tell you that I'm not very familiar with C programming (it was a > long time ago...) and I do not own MSVC. Python compiles, I believe, with the free VCExpress. But I would start with ctypes. From tjreedy at udel.edu Tue Jan 13 18:57:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 18:57:22 -0500 Subject: Could you suggest optimisations ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Hi, > > In the attached script, the longest time is spent in the following > functions (verified by psyco log): I cannot help but wonder why and if you really need all the rigamorole with file pointers, offsets, and tells instead of for line in open(...): do your processing. > > def match_generator(self,regex): > """ > Generate the next line of self.input_file that > matches regex. > """ > generator_ = self.line_generator() > while True: > self.file_pointer = self.input_file.tell() > if self.file_pointer != 0: > self.file_pointer -= 1 > if (self.file_pointer + 2) >= self.last_line_offset: > break > line_ = generator_.next() > print "%.2f%% \r" % (((self.last_line_offset - > self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), > if not line_: > break > else: > match_ = regex.match(line_) > groups_ = re.findall(regex,line_) > if match_: > yield line_.strip("\n"), groups_ > > def get_matching_records_by_regex_extremes(self,regex_array): > """ > Function will: > Find the record matching the first item of regex_array. > Will save all records until the last item of regex_array. > Will save the last line. > Will remember the position of the beginning of the next line in > self.input_file. > """ > start_regex = regex_array[0] > end_regex = regex_array[len(regex_array) - 1] > > all_recs = [] > generator_ = self.match_generator > > try: > match_start,groups_ = generator_(start_regex).next() > except StopIteration: > return(None) > > if match_start != None: > all_recs.append([match_start,groups_]) > > line_ = self.line_generator().next() > while line_: > match_ = end_regex.match(line_) > groups_ = re.findall(end_regex,line_) > if match_ != None: > all_recs.append([line_,groups_]) > return(all_recs) > else: > all_recs.append([line_,[]]) > line_ = self.line_generator().next() > > def line_generator(self): > """ > Generate the next line of self.input_file, and update > self.file_pointer to the beginning of that line. > """ > while self.input_file.tell() <= self.last_line_offset: > self.file_pointer = self.input_file.tell() > line_ = self.input_file.readline() > if not line_: > break > yield line_.strip("\n") > > I was trying to think of optimisations, so I could cut down on > processing time, but got no inspiration. > (I need the "print "%.2f%% \r" ..." line for user's feedback). > > Could you suggest any optimisations ? > Thanks, > Ron. > > > P.S.: Examples of processing times are: > > * 2m42.782s on two files with combined size of 792544 bytes > (no matches found). > * 28m39.497s on two files with combined size of 4139320 bytes > (783 matches found). > > These times are quite unacceptable, as a normal input to the program > would be ten files with combined size of ~17MB. > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Jan 13 19:04:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 19:04:33 -0500 Subject: [OT] Re: are there some special about '\x1a' symbol In-Reply-To: References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Mon, 12 Jan 2009 12:00:16 -0200, John Machin > escribi?: > >> I didn't think your question was stupid. Stupid was (a) CP/M recording >> file size as number of 128-byte sectors, forcing the use of an in-band >> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >> decades after people stopped writing Ctrl-Z at the end of text files. > > This is called "backwards compatibility" and it's a good thing :) But it does not have to be the default or only behavior to be available. > Consider the Atucha II nuclear plant, started in 1980, based on a design > from 1965, and still unfinished. People require access to the complete > design, plans, specifications, CAD drawings... decades after they were > initially written. > I actually do use (and maintain! -- ugh!) some DOS programs. Some people > would have a hard time if they could not read their old data with new > programs. > Even Python has a "print" statement decades after nobody uses a teletype > terminal anymore... > From sjmachin at lexicon.net Tue Jan 13 19:07:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 16:07:00 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> Message-ID: On Jan 14, 9:56?am, Andy Grove wrote: > On Jan 13, 3:08?pm, John Machin wrote: > > > Please show the full traceback. > > John, > > Thanks. Here it is: > > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 281, in _handle_request_noblock > ? ? self.process_request(request, client_address) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 307, in process_request > ? ? self.finish_request(request, client_address) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 320, in finish_request > ? ? self.RequestHandlerClass(request, client_address, self) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 614, in __init__ > ? ? self.handle() > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/http/server.py", line 363, in handle > ? ? self.handle_one_request() > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/http/server.py", line 357, in handle_one_request > ? ? method() > ? File "/Users/andy/Development/EclipseWorkspace/dbsManage/kernel.py", > line 178, in do_POST > ? ? form = urllib.parse.parse_qs(qs, keep_blank_values=1) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/urllib/parse.py", line 351, in parse_qs > ---------------------------------------- > ? ? for name, value in parse_qsl(qs, keep_blank_values, > strict_parsing): > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/urllib/parse.py", line 377, in parse_qsl > ? ? pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] > TypeError: Type str doesn't support the buffer API | Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> qs_bytes = b'a;b&c;d' | >>> qs_str = 'a;b&c;d' | >>> pairs = [s2 for s1 in qs_bytes.split('&') for s2 in s1.split (';')] | Traceback (most recent call last): | File "", line 1, in | TypeError: Type str doesn't support the buffer API | >>> pairs = [s2 for s1 in qs_str.split('&') for s2 in s1.split(';')] | >>> pairs | ['a', 'b', 'c', 'd'] | >>> b'x&y'.split('&') | Traceback (most recent call last): | File "", line 1, in | TypeError: Type str doesn't support the buffer API | >>> b'x&y'.split(b'&') | [b'x', b'y'] | >>> 'x&y'.split('&') | ['x', 'y'] | >>> The immediate cause is that as expected mixing str and bytes raises an exception -- this one however qualifies as "not very informative" and possibly wrong [not having inspected the code for whatever.split() I'm left wondering what is the relevance of the buffer API]. The docs for urllib.parse.parse_qs() and .parse_qsl() are a bit vague: """query string given as a string argument (data of type application/x- www-form-urlencoded)""" ... does "string" mean "str only" or "str or bytes"? Until someone can give an authoritative answer [*], you might like to try decoding your data (presuming you know what it is or how to dig it out like you found the type and length) and feeding the result to the .parse_qs(). [*] I know next to zilch about cgi and urllib -- I'm just trying to give you some clues to see if you can get yourself back on the road. From tjreedy at udel.edu Tue Jan 13 19:11:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 19:11:44 -0500 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: S.Selvam Siva wrote: >> I doubt anyone's created a general ready-made solution for this, you'd >> have to code it yourself. >> To handle the common case, you can cheat and just .split() at the >> periods and then slice and rejoin the list of domain parts, ex: >> '.'.join(domain.split('.')[-2:]) >> >> Cheers, >> Chris > > > Thank you Chris Rebert, > Actually i tried with domain specific logic.Having 200 TLD like > .com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i > will try to find some alternative solution. I make a dict mapping TLDs to number of parts to strip off parts = { 'com':1, 'in':2, 'org':1, 'uk':2, } etc If certain TLDs need a special function, define the function first and map that TLD to the function and then switch on the type of value (int or function) when you look it up. From fetchinson at googlemail.com Tue Jan 13 19:30:52 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 13 Jan 2009 16:30:52 -0800 Subject: python3.0 MySQLdb In-Reply-To: <496D1C78.3060307@v.loewis.de> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> Message-ID: >>>> I need something to connect to a database, preferably mysql, that >>>> works in python3.0 please. >>> And your question is? >>> >>> >> Surely it's fairly obvious that the question is "does such a thing >> exist, and if so where can I find it?". > > Interestingly enough, the question was slightly (but importantly) > different, though: the question really was "Does anybody has a patch for > MySQLdb?"; as my reference to the existing interface to PostgreSQL > was not sufficient for the OP. Exactly. One could think about 3-4 different potentially useful answers to the OP but when one sees 3-4 immediately right after reading the post then probably there are a couple more still after some thinking. So if the OP specifies exactly what he/she wants, he/she will get more signal than noise. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From prologic at shortcircuit.net.au Tue Jan 13 19:33:29 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 10:33:29 +1000 Subject: Standard IPC for Python? In-Reply-To: <496CC069.80909@shopzeus.com> References: <496CC069.80909@shopzeus.com> Message-ID: On Wed, Jan 14, 2009 at 2:25 AM, Laszlo Nagy wrote: > The question is: what is the standard way to implement fast and portable IPC > with Python? Are there tools in the standard lib that can do this? Certainly not standard by any means, but I use circuits (1). Two or more processes can communicate via Bridge by propagating events. Example: http://trac.softcircuit.com.au/circuits/browser/examples/remotepy.py cheers James 1. http://trac.softcircuit.com.au/circuits/ From prologic at shortcircuit.net.au Tue Jan 13 19:34:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 10:34:37 +1000 Subject: Standard IPC for Python? In-Reply-To: <496CD1F6.3080604@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: On Wed, Jan 14, 2009 at 3:40 AM, Laszlo Nagy wrote: > Can anyone tell me if select.select works under OS X? Yes it does. cheers James From Russ.Paielli at gmail.com Tue Jan 13 19:45:17 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 16:45:17 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 3:07 pm, Carl Banks wrote: > I've seen no evidence that any Python project is moving even remotely > toward data encapsulation. That would be a drastic change. Even if > it were only a minor change in the implementation (and it would not > be), it would be a major stroke in the Python community. It would > basically cause a wholescale power shift from the user to the > implementor. As a user it'd be like the difference between living in > a free democracy and a fascist dictatorship. I just googled "object oriented principles." The first site that came up lists four princicples: - Encapsulation - Abstraction - Inheritance - Polymorphism The Wikipedia entry for "object-oriented programming" also lists encapsulation as a "fundamental concept." The first line on the python.org site says: "Python is a dynamic object-oriented programming language that can be used for many kinds of software development." How can that possibly be true if you see "no evidence that any Python project is moving even remotely toward data encapsulation"? Semantics aside, I fail to understand your hostility toward a fundamental concept of object-oriented programming. The difference between a free democracy and a "fascist dictatorship"? Give me a break! From Catherine.M.Moroney at jpl.nasa.gov Tue Jan 13 20:02:28 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Tue, 13 Jan 2009 17:02:28 -0800 Subject: executing multiple functions in background simultaneously Message-ID: <496D39A4.2030406@jpl.nasa.gov> Hello everybody, I know how to spawn a sub-process and then wait until it completes. I'm wondering if I can do the same thing with a Python function. I would like to spawn off multiple instances of a function and run them simultaneously and then wait until they all complete. Currently I'm doing this by calling them as sub-processes executable from the command-line. Is there a way of accomplishing the same thing without having to make command-line executables of the function call? I'm primarily concerned about code readability and ease of programming. The code would look a lot prettier and be shorter to boot if I could spawn off function calls rather than subprocesses. Thanks for any advice, Catherine From prologic at shortcircuit.net.au Tue Jan 13 20:12:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:12:25 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D39A4.2030406@jpl.nasa.gov> References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney wrote: > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? Try using the python standard threading module. Create multiple instances of Thread with target=your_function Maintain a list of these new Thread instnaces Join (wait) on them. pydoc threading.Thread cheers James From pieterprovoost at gmail.com Tue Jan 13 20:28:53 2009 From: pieterprovoost at gmail.com (pieterprovoost at gmail.com) Date: Tue, 13 Jan 2009 20:28:53 -0500 Subject: problem calling method Message-ID: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> I'm trying to call a method within my wx frame, but that doesn't seem to work. What am I doing wrong? class MyFrame(wx.Frame): def __init__(self, *args, **kwds): self.Bind(wx.EVT_BUTTON, self.test, self.testbutton) ... def sendmail(self): ... def test(self, event): self.sendmail() event.Skip() Clicking the test button returns: Traceback (most recent call last): File "D:\python\bx\bxgui.py", line 120, in test self.sendmail() AttributeError: 'MyFrame' object has no attribute 'sendmail' Thanks! -- This message was sent on behalf of pieterprovoost at gmail.com at openSubscriber.com http://www.opensubscriber.com/messages/python-list at python.org/topic.html From kiliansto at gmail.com Tue Jan 13 20:29:29 2009 From: kiliansto at gmail.com (killsto) Date: Tue, 13 Jan 2009 17:29:29 -0800 (PST) Subject: Programming friction Message-ID: I'm trying to implement a basic user controlled sliding box with pygame. I have everything worked out, except for two things. The acceleration is changed once a second (for meters/second) this leads to very jumpy movement. I need to add a way to check how long it takes the program to loop and multiply the acceleration by that much. (I think) After I move, the box slows down appropriately, but then the speed passes 0 and the box shoots off the other way. The equation (in real life) is mS (Coefficient of static friction)*Normal Force >= friction force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1, the next number will be -1 and I shoot off in the other direction. How do I fix this an still have backwards movement? From wuwei23 at gmail.com Tue Jan 13 20:29:36 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 Jan 2009 17:29:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> On Jan 14, 10:45?am, "Russ P." wrote: > The Wikipedia entry for "object-oriented programming" also lists > encapsulation as a "fundamental concept." The Wikipedia entry for "encapsulation" defines it as "the grouping together of data and functionality". That sounds like Python classes & modules to me. From prologic at shortcircuit.net.au Tue Jan 13 20:34:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:34:07 +1000 Subject: Programming friction In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 11:29 AM, killsto wrote: > I'm trying to implement a basic user controlled sliding box with > pygame. I have everything worked out, except for two things. Try the pygame mailing list :) cheers James From google at mrabarnett.plus.com Tue Jan 13 20:35:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 01:35:01 +0000 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496D4145.4060905@mrabarnett.plus.com> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function and run >> them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables of >> the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces Join (wait) on them. > > pydoc threading.Thread > The disadvantage of threads in Python (CPython, actually) is that there's the GIL (Global Interpreter Lock), so you won't get any speed advantage if the threads are mostly processor-bound. From prologic at shortcircuit.net.au Tue Jan 13 20:40:24 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:40:24 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D4145.4060905@mrabarnett.plus.com> References: <496D39A4.2030406@jpl.nasa.gov> <496D4145.4060905@mrabarnett.plus.com> Message-ID: On Wed, Jan 14, 2009 at 11:35 AM, MRAB wrote: > The disadvantage of threads in Python (CPython, actually) is that > there's the GIL (Global Interpreter Lock), so you won't get any speed > advantage if the threads are mostly processor-bound. The OP didn't really say what this function does :) *sigh* @OP: You have (at least in 2.6+) threading and multiprocessing modules at your disposal. --JamesMills From AbelCodeMonk at gmail.com Tue Jan 13 20:44:36 2009 From: AbelCodeMonk at gmail.com (Arlo Belshee) Date: Tue, 13 Jan 2009 17:44:36 -0800 (PST) Subject: New Python 3.0 string formatting - really necessary? References: <3e1973d1-0fbc-4b35-a9c3-d7e4d7910a4f@z6g2000pre.googlegroups.com> <29dddf46-dd5f-4c61-bc9b-d24ce726dcb9@v39g2000pro.googlegroups.com> <494ea6ab$0$7769$426a74cc@news.free.fr> <9c8c524f-6985-4cc8-b19c-666f85c69946@a26g2000prf.googlegroups.com> <01696606$0$6988$c3e8da3@news.astraweb.com> <78bd573f-03b0-4628-909d-3f84f9718e7e@13g2000yql.googlegroups.com> <4f95bf3c-69cb-4b8f-b2c5-cce5f5f38b49@v42g2000yqv.googlegroups.com> Message-ID: For R, and others who haven't read the PEP or worked a lot with the web, here are some really strong advantages of the new string formatting over the old. Note: I'm not saying that you have to use one or the other. I'm just pointing out some of the things that the new format gives us - things which allow the next generation of application simplification (especially web apps). When working on resource-oriented, generalized display applications (eg, most any modern website), you commonly run into the problem of wanting to display a bunch of different things in a bunch of different ways - and on the web, display means "convert to a string for the browser". However, the mapping is not a complete graph. Rather, there are usually some rules. For example: * I want to show the same thing to different people in different ways, depending on permissions. * Sometimes I want to show a thing as a full display, and sometimes as a link to go get more. Usually, the template (context) knows how I want to show something, but the thing knows how to show itself. I can solve this using the new string formatting. In particular, by using the "{0.property}", "{variable[index]}", and similar substitutions (none of which can be done in the old syntax). As a result, I end up with an entire website, of an arbitrary number of pages, being supported with one, 5-line "generate the view" method. There is 0 code per page. Here are some of the simpler examples. First, there might be a link to a user's page: "{0.display_name}" Wait...isn't that the same? Yup. There's the first widget: a link. Any resource that knows its own name and URL (and that's all of them) can be shown as a link. Similar widget extraction hugely reduces the other combinations I have to support - eliminating a lot of redundancy, and many LoC. However, display_name doesn't show up the same for all users. Administrators often get additional data (such as the username), everywhere they see a user's name. Friends of a user see little rollovers that tell them more about that user - such as a photo. Fortunately, I defined my user class like: class User: @property def display_name(self): # viewer-dependent context stuff here. And the new string formatting calls my arbitrary code, without anyone having to think about it. But display_name doesn't need to know how to display a name - it just needs to choose which style to use. I can also extract that out to a template, and then have "{0.first}" for friends and "{0.first} {0.last} ({0.username})" for admins, and so on. My display_name code just needs to choose which representation to use - it doesn't define that format. It just returns one of several opaque string constants / widgets, making refactoring trivial. Similarly, I can use "{resource.full_display_for_viewer}" or "{resource.link_display}" to tell the resource how I want it to display itself. Hm. Doesn't that make widget sets (a la ToscaWidgets / TuboGears) and template languages (such as Cheetah / Kid / Mako) a little obsolete? Well, sorta. After all when displaying my user class, I can do this too: "{self.blog_entries.recent.as_ordered_list.using.link_display}". Is that pathological? Probably (unless you have a functional programming background or like domain-specific languages). Looping is, after all, one of the things a real templating system gives you. However, now you don't need to use it for common (and simple) things. Eventually, you do run into stuff for which you want a full templating language. And I use them. For example, they define the base page layouts. The point, however, is that a lot of the lower-level things can be done without using the templating language. And this reduces the number of Mako templates you have lying around, while still allowing great decomposability. Most of these things could be done by having the object override __format__(self). However, that jams my display code in with the rest of my resource class. This way, I can have templates pull out what they want from my resources. And I can compute the template to use and the resources to use it on independently, then just pass it to my displayer method. These are capabilities that %s has no chance to every approach. The ability to use new-style format strings reducees my LoC by a half-ton, and they make what they leave behind a lot easier to read. Being higher-level constructs, they allow me to eliminate redundancy, and that's the real purpose of a programmer. From invalid at invalid Tue Jan 13 20:44:59 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 13 Jan 2009 19:44:59 -0600 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On 2009-01-12, John Machin wrote: > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. I believe that "feature" was inherited by CP/M from DEC OSes (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API (including the FCB) was lifted almost directly from DEC's PDP-11 stuff, which probably copied it from PDP-8 stuff. Perhaps in the early 60's somebody at DEC had a reason. The really interesting thing is that we're still suffering because of it 40+ years later. -- Grant Edwards grante Yow! I want to read my new at poem about pork brains and visi.com outer space ... From Russ.Paielli at gmail.com Tue Jan 13 20:50:05 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 17:50:05 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> Message-ID: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> On Jan 13, 5:29 pm, alex23 wrote: > On Jan 14, 10:45 am, "Russ P." wrote: > > > The Wikipedia entry for "object-oriented programming" also lists > > encapsulation as a "fundamental concept." > > The Wikipedia entry for "encapsulation" defines it as "the grouping > together of data and functionality". > > That sounds like Python classes & modules to me. Here's the definition on the Wikipedia page for object oriented programming (and it does *not* sound like Python classes): Encapsulation conceals the functional details of a class from objects that send messages to it. ... Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface ? those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member. From ivan.illarionov at gmail.com Tue Jan 13 20:55:11 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Tue, 13 Jan 2009 17:55:11 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: Ben Sizer wrote: > What am I doing wrong? What are you trying to achieve? If you want to modify sys.path I suggest using Python/C API directly: (boilerplate removed) PyImport_ImportModule("sys") PyObject_GetAttrString(sysmod_pointer, "path") PyList_Insert(pathobj_pointer, 0, path_python_str) -- Ivan From prologic at shortcircuit.net.au Tue Jan 13 21:04:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:04:04 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 11:50 AM, Russ P. wrote: > Here's the definition on the Wikipedia page for object oriented > programming (and it does *not* sound like Python classes): > > Encapsulation conceals the functional details of a class from objects > that send messages to it. ... Encapsulation is achieved by specifying > which classes may use the members of an object. The result is that > each object exposes to any class a certain interface ? those members > accessible to that class. The reason for encapsulation is to prevent > clients of an interface from depending on those parts of the > implementation that are likely to change in future, thereby allowing > those changes to be made more easily, that is, without changes to > clients. For example, an interface can ensure that puppies can only be > added to an object of the class Dog by code in that class. Members are > often specified as public, protected or private, determining whether > they are available to all classes, sub-classes or only the defining > class. Some languages go further: Java uses the default access > modifier to restrict access also to classes in the same package, C# > and VB.NET reserve some members to classes in the same assembly using > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > one to specify which classes may access any member. You do realize this is a model and not strictly a requirement. Quite a few things in Python are done merely by convention. Don't get caught up. --JamesMills From castironpi at gmail.com Tue Jan 13 21:15:09 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 18:15:09 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 13, 5:06?pm, Mark Wooding wrote: snip > I'm going to move away from the formal semantics stuff and try a > different tack. ?Here's what I think is the defining property of > pass-by-value (distilled from the formal approach I described earlier, > but shorn of the symbolism): > > ? The callee's parameters are /new variables/, initialized /as if by > ? assignment/ from the values of caller's argument expressions. In other words, the same as assignment in that language. snip > Because its argument passing works the same way as its assignment. That would be called pass-by-assignment. But you've just postponed explaining yourself. Stop delegating and work. From metolone+gmane at gmail.com Tue Jan 13 21:17:39 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 13 Jan 2009 18:17:39 -0800 Subject: ctype problem References: <6197f37d-0ea0-4430-a466-2f36b2011ea8@v42g2000yqj.googlegroups.com> Message-ID: "Aaron Brady" wrote in message news:6197f37d-0ea0-4430-a466-2f36b2011ea8 at v42g2000yqj.googlegroups.com... On Jan 13, 10:22 am, Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > int a; > int b; > char *c; > > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > _fields_ = [("a" c_int), > ("b", c_int), > ("c", c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? I believe you want ("c",c_char_p), although I don't get the same error as you describe when I use c_char. Below is my working code (Python 2.6.1 and Visual Studio 2008): ---- x.py ---- from ctypes import * class INTERFACE(Structure): _fields_ = [ ('a',c_int), ('b',c_int), ('c',c_char) ] x = CDLL('x.dll') i = INTERFACE() i.a = 1 i.b = 2 i.c = 'hello' x.myfunction(byref(i)) ---- cl /LD /W4 x.c -> x.dll ---- #include struct interface { int a; int b; char* c; }; __declspec(dllexport) void myfunction(struct interface* iface) { printf("%d %d %s\n",iface->a,iface->b,iface->c); } -Mark From lists at cheimes.de Tue Jan 13 21:18:37 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jan 2009 03:18:37 +0100 Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible In-Reply-To: References: Message-ID: Ivan Illarionov schrieb: > Ben Sizer wrote: >> What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: > (boilerplate removed) > PyImport_ImportModule("sys") > PyObject_GetAttrString(sysmod_pointer, "path") > PyList_Insert(pathobj_pointer, 0, path_python_str) The sys module has its own set of special functions like PySys_GetObject. The following (untested) code should take care of error checking and ref counting. #include "Python.h" PyObject* addtosyspath(const char* addpath) { PyObject *syspath=NULL, *path=NULL; int result; if ((syspath = PySys_GetObject("path")) == NULL) return NULL; if ((path = PyString_FromString(addpath) == NULL) { Py_DECREF(syspath); return NULL; } result = PyList_Insert(syspath, 0, path); Py_DECREF(syspath); Py_DECREF(path); if (result != 0) return NULL; Py_RETURN_NONE; } Christian From jervisau at gmail.com Tue Jan 13 21:22:40 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 14 Jan 2009 13:22:40 +1100 Subject: Programming friction In-Reply-To: References: Message-ID: <8e63a5ce0901131822l458a3026of0ee08e53b8d4c93@mail.gmail.com> On Wed, Jan 14, 2009 at 12:29 PM, killsto wrote: > > force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1, > the next number will be -1 and I shoot off in the other direction. How > do I fix this an still have backwards movement? > -- > http://mail.python.org/mailman/listinfo/python-list > try something like: force = max(force, 0) where force is the force applied to the object that you have calculated. this should ensure that the force is bounded to 0 in the negative direction. I believe that in pygame you can use the clock module to help you with your timing issues (see the docs), and perhaps attempt to keep a regular frame rate. Cheers, Jervis -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Tue Jan 13 21:27:09 2009 From: http (Paul Rubin) Date: 13 Jan 2009 18:27:09 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <7xpriqmxky.fsf@ruckus.brouhaha.com> "James Mills" writes: > You do realize this is a model and not strictly a requirement. Quite > a few things in Python are done merely by convention. > Don't get caught up. But, if something is done by convention, then departing from the convention is by definition unconventional. If you do something unconventional in a program, it could be on purpose for a reason, or it could be by accident indicating a bug. I don't understand why some folks spew such violent rhetoric against the idea of augmenting Python with features to alert you automatically when you depart from the convention, so that you can check that the departure is actually what you wanted. A lot of the time, I find, the departures are accidental and automated checks would save me considerable debugging. From prologic at shortcircuit.net.au Tue Jan 13 21:33:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:33:07 +1000 Subject: problem calling method In-Reply-To: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> References: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> Message-ID: On Wed, Jan 14, 2009 at 11:28 AM, wrote: > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): It might be helpful here if you called the parent __init__. Like so: class MyFrame(wx.Frame): def __init__(self, *args, **kwds): super(MyFrame, self).__init__(*args, **kwargs) ... cheers James From prologic at shortcircuit.net.au Tue Jan 13 21:36:11 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:36:11 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 12:27 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. Amen to that! Finally someone with some sense and his/her head screwed on properly! :) Kudos to your thoughtful post :) cheers James From ajaksu at gmail.com Tue Jan 13 21:42:47 2009 From: ajaksu at gmail.com (ajaksu) Date: Tue, 13 Jan 2009 18:42:47 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 13, 1:33?am, Philip Semanchuk wrote: > I don't think I understand you clearly. Whether or not Google et al ? > whitelist the Python UA isn't a Python issue, is it? Hi, sorry for taking so long to reply :) I imagine it's something akin to Firefox's 'Report broken website': evangelism. IMHO, if the PSF *cough* Steve *cough* or individual Python hackers can contact key sites (as Wikipedia, groups.google, etc.) the issue can be solved sooner. Instead of waiting for each whitelist maintainer's to find out we have a new UA, go out and tell them. A template for such requests could help those inside e.g. Google to bring the issue to the attention of the whitelist admins. The community has lots of connections that could be useful to pass the message along, if only 'led by the nose' to achieve that :) Hence, the suggestion to raise a bug. Regards, Daniel From bedouglas at earthlink.net Tue Jan 13 21:53:38 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 13 Jan 2009 18:53:38 -0800 Subject: List/Set/Dict.. Message-ID: <11de01c975f3$4f22e740$0301a8c0@tmesa.com> Hi... i have the test dict/list a= {"a": 'a1',"b" : "b1"} b= [{"a": 'a1',"b" : "b1"}] i'm trying to figure out how to programtically tell them apart... ie, which is a dict, and which is a list... is there a way to accomplish this.. thanks From philip at semanchuk.com Tue Jan 13 21:53:57 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 21:53:57 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: On Jan 13, 2009, at 6:41 PM, Mel wrote: > Philip Semanchuk wrote: > >> I'm working on message queue support, but the Sys V IPC API is a >> headache and takes longer to code against than the POSIX API. > > I hadn't found it that bad. I have a C extension I should perhaps > clean up > and make public. Have you compared the SysV objects to the POSIX objects? I'll give you two examples of how SysV is more trouble with which to work. Example 1 --- The SysV objects expose a ton of information that show up as Python attributes. For instance, a sysv_ipc.Semaphore object has 16 attributes: key, id, value, undo, block, mode, uid, gid, cuid, cgid, last_pid, waiting_for_nonzero, waiting_for_zero and o_time. The first two and last eight are read-only, the middle six are read-write. Contrast this to a posix_ipc.Semaphore object which has two read-only attributes: name and value. All of those attributes on the SysV object add up to a lot of code. Furthermore, the SysV attributes have types of key_t, mode_t, uid_t, gid_t, pid_t, time_t, etc. I've spent the past few days researching these types and trying to find out whether they're signed or unsigned, guaranteed to fit in a long, etc. I also need to know what Python types are appropriate for representing these. For instance, anything that can exceed a C long can also exceed a Python int, and so I need to return a Python long object if the C value exceeds LONG_MAX. When I returned to the sysv_ipc code a few days ago, my intention was to add message queue support to it, but instead I've gotten distracted chasing type-related bugs that won't show up until e.g. someone compiles the module on a 64-bit platform and tries to use a key that exceeds 0xFFFFFFFF, or compiles it on some weird 16-bit embedded processor that exposes another of my flawed type assumptions. The POSIX API is so much simpler that I spend much less time working on type-related drudgery. Example 2 --- SysV shared memory has to be attached and detached and accessed with the un-Pythonic read & write methods. I'd like to support buffer-type access (like slicing), but that's more code to be written. And there's another 16 attributes to expose. POSIX shared memory OTOH is mmapped, and there's already a Python library for that. For posix_ipc.SharedMemory objects I had to write a constructor, an unlink() method, and code for three read-only attributes and I was done. Nice. I invite you to look at my extension and compare: http://semanchuk.com/philip/sysv_ipc/ Maybe your code can benefit from what I've done, or vice versa. Good luck Philip From tjreedy at udel.edu Tue Jan 13 21:57:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 21:57:04 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 13, 5:29 pm, alex23 wrote: >> On Jan 14, 10:45 am, "Russ P." wrote: >> >>> The Wikipedia entry for "object-oriented programming" also lists >>> encapsulation as a "fundamental concept." >> The Wikipedia entry for "encapsulation" defines it as "the grouping >> together of data and functionality". >> >> That sounds like Python classes & modules to me. > > Here's the definition on the Wikipedia page for object oriented > programming (and it does *not* sound like Python classes): > > Encapsulation conceals the functional details of a class from objects > that send messages to it. ... Encapsulation is achieved by specifying > which classes may use the members of an object. The result is that > each object exposes to any class a certain interface ? those members > accessible to that class. The reason for encapsulation is to prevent > clients of an interface from depending on those parts of the > implementation that are likely to change in future, thereby allowing > those changes to be made more easily, that is, without changes to > clients. For example, an interface can ensure that puppies can only be > added to an object of the class Dog by code in that class. Members are > often specified as public, protected or private, determining whether public = no leading underscore private = one leading underscore protected = two leading underscores Python uses encapsulation by convention rather than by enforcement. > they are available to all classes, sub-classes or only the defining > class. Some languages go further: Java uses the default access > modifier to restrict access also to classes in the same package, C# > and VB.NET reserve some members to classes in the same assembly using > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > one to specify which classes may access any member. > -- > http://mail.python.org/mailman/listinfo/python-list > From prologic at shortcircuit.net.au Tue Jan 13 22:14:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:14:46 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 12:57 PM, Terry Reedy wrote: > public = no leading underscore > private = one leading underscore > protected = two leading underscores > > Python uses encapsulation by convention rather than by enforcement. As mentioned previously this is not encapsulation, but access control. But yes correct, this is how we conventionally define access control over members of an object. It's up to the programmer correctly adhere to the interface(s). --JamesMills From Russ.Paielli at gmail.com Tue Jan 13 22:18:24 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 19:18:24 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Jan 13, 6:04 pm, "James Mills" wrote: > On Wed, Jan 14, 2009 at 11:50 AM, Russ P. wrote: > > Here's the definition on the Wikipedia page for object oriented > > programming (and it does *not* sound like Python classes): > > > Encapsulation conceals the functional details of a class from objects > > that send messages to it. ... Encapsulation is achieved by specifying > > which classes may use the members of an object. The result is that > > each object exposes to any class a certain interface ? those members > > accessible to that class. The reason for encapsulation is to prevent > > clients of an interface from depending on those parts of the > > implementation that are likely to change in future, thereby allowing > > those changes to be made more easily, that is, without changes to > > clients. For example, an interface can ensure that puppies can only be > > added to an object of the class Dog by code in that class. Members are > > often specified as public, protected or private, determining whether > > they are available to all classes, sub-classes or only the defining > > class. Some languages go further: Java uses the default access > > modifier to restrict access also to classes in the same package, C# > > and VB.NET reserve some members to classes in the same assembly using > > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > > one to specify which classes may access any member. > > You do realize this is a model and not > strictly a requirement. Quite a few things > in Python are done merely by convention. > > Don't get caught up. > > --JamesMills Yes, but the fact that you can approximate OO programming in a particular language does not make that language object oriented. You can approximate OO programming in C, but that does not mean that C is an OO language. So I can claim that Python is not strictly object oriented until it gets encapsulation (in the sense of data hiding). That is simply a fact, and no amount of pleading or obfuscation will change it. Should Python get true encapsulation? I don't know. Maybe encapsulation cannot be added without excessive overhead or without compromising other more important aspects and features of the language. But I do know that not having encapsulation is a limitation to the use of Python for good software engineering. I may be in the minority in the Python "community" on this one, but I am apparently in the majority in the OO programming "community." From rhodri at wildebst.demon.co.uk Tue Jan 13 22:25:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 14 Jan 2009 03:25:55 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 14 Jan 2009 02:27:09 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. I wouldn't violently object to having some means of policing class or module privacy, but it does have consequences. When it's a convention, you can break it; when it isn't, you can't, even if you do have good reason. Add that to the obviousness of the "leading underscore => private" convention, and I just don't see a burning need for it, that's all. -- Rhodri James *-* Wildebeeste Herder to the Masses From rt8396 at gmail.com Tue Jan 13 22:31:56 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 19:31:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: > public = no leading underscore > private = one leading underscore > protected = two leading underscores > > Python uses encapsulation by convention rather than by enforcement. Very well said Terry! I like that python does not force me to do "everything" but does force things like parenthesis in a function/method call whether or not an argument is required/expected. This makes for very readable code. Visual parsing a Python file is very easy on the eyes due to this fact -- Thanks Guido! We do not need to add three new keywords when there is an accepted Pythonic way to handle public/private/protected From prologic at shortcircuit.net.au Tue Jan 13 22:32:54 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:32:54 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: > Yes, but the fact that you can approximate OO programming in a > particular language does not make that language object oriented. You > can approximate OO programming in C, but that does not mean that C is > an OO language. Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) (Please stop confusing the two) is not a strict requirements of the OO model. Remember that it is a model and not a strict set of requirements that programming languages must implement. In fact, Python borrows features from the Functional Paradigm. Does this make it a Functional Language ? No. Why ? Because one of the clear requirements of the Functional Paradigm is that functions cannot have side affects. > So I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. In fact this is true, C can be seen as an programming language that has features of the OO model. I think one of the things you guys are missing out here is that there are really only two Paradigms or Machines. Functional and Imperative. And guess what ? As it turns out we can implement functional machines that run on top of imperative ones! > Should Python get true encapsulation? I don't know. Maybe > encapsulation cannot be added without excessive overhead or without > compromising other more important aspects and features of the > language. But I do know that not having encapsulation is a limitation > to the use of Python for good software engineering. I may be in the > minority in the Python "community" on this one, but I am apparently in > the majority in the OO programming "community." Again, stop confusing terminology. Should Python get strict and enforce access control of object members ? No. Why ? I can think of several reasons. Give me one use-case where you strictly require that members of an object be private and their access enforced as such ? cheers James From prologic at shortcircuit.net.au Tue Jan 13 22:35:54 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:35:54 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 1:25 PM, Rhodri James wrote: > I wouldn't violently object to having some means of policing class > or module privacy, but it does have consequences. When it's a > convention, you can break it; when it isn't, you can't, even if > you do have good reason. Add that to the obviousness of the > "leading underscore => private" convention, and I just don't see > a burning need for it, that's all. Bare in mind also, that enfocing access control / policing as you called it has a performance hit as the machine (the Python vm) has to perform checks each time members of an object are accessed. I can think of no reason to want to do this at runtime hwatosever and I've been developing in Python for quite some years now. cheers James From prologic at shortcircuit.net.au Tue Jan 13 22:39:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:39:30 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:31 PM, r wrote: >> public = no leading underscore >> private = one leading underscore >> protected = two leading underscores >> >> Python uses encapsulation by convention rather than by enforcement. > > Very well said Terry! > > I like that python does not force me to do "everything" but does force > things like parenthesis in a function/method call whether or not an > argument is required/expected. This makes for very readable code. > Visual parsing a Python file is very easy on the eyes due to this fact > -- Thanks Guido! We do not need to add three new keywords when there > is an accepted Pythonic way to handle public/private/protected Agreed. Furthermore there very few cases where you need to distinguish between whether an object's attribute is public or private or even protected. Consider the following two pieces of code and tell me which is more Pythonic: class A(object): def __init__(self): self.x = None def setX(self, v): self.x = v def getX(self): return self.x ---------------------------------------- class A(object): def __init__(self): self.x = None I'll give you a hint ... It's the simpler one :) cheers James From pavlovevidence at gmail.com Tue Jan 13 22:50:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 19:50:41 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 6:45?pm, "Russ P." wrote: > On Jan 13, 3:07 pm, Carl Banks wrote: > > > I've seen no evidence that any Python project is moving even remotely > > toward data encapsulation. ?That would be a drastic change. ?Even if > > it were only a minor change in the implementation (and it would not > > be), it would be a major stroke in the Python community. ?It would > > basically cause a wholescale power shift from the user to the > > implementor. ?As a user it'd be like the difference between living in > > a free democracy and a fascist dictatorship. > > I just googled "object oriented principles." The first site that came > up lists four princicples: > > - Encapsulation > - Abstraction > - Inheritance > - Polymorphism > > The Wikipedia entry for "object-oriented programming" also lists > encapsulation as a "fundamental concept." > > The first line on the python.org site says: > > "Python is a dynamic object-oriented programming language that can be > used for many kinds of software development." > > How can that possibly be true if you see "no evidence that any Python > project is moving even remotely toward data encapsulation"? Is this seriously your argument? Python must be moving towards data encapsulation because there is a line in Python.org that, if you blindly accept the Wikipedia definition as truth, indirectly implies that it is? Are you *seriously* arguing this? The argument is too ridiculous to deserve a refutation, so I'll just point out two things: 1. Wise people don't believe everything that is written on Wikipedia. 2. The person who wrote that line in Python.org is a wise person. > Semantics aside, I fail to understand your hostility toward a > fundamental concept of object-oriented programming. The difference > between a free democracy and a "fascist dictatorship"? Give me a > break! You know what? Computer science buzzwords mean jack squat to me. I don't give a horse's tail whether some people label it a fundamental concept of object-oriented programming or not. I think it's a bad thing. And it's a bad thing for exactly the reason I said: it gives the library implementor the power to dictate to the user how they can and can't use the library. The cultural impact that would have on the community is far worse, IMHO, than any short-sighted benefits like being able to catch an accidental usage of an internal variable. Trust would be replaced by mistrust, and programming in Python would go from a pleasant experience to constant antagonism. No thanks. "Software engineering" be damned. Python is better off the way it is. Carl Banks From pavlovevidence at gmail.com Tue Jan 13 23:17:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 20:17:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 9:50?pm, Carl Banks wrote: > The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. And I'll give you a perfect example: XML-DOM versus ElementTree XML-DOM is the sort of standard that is borne of a culture that values encapsulation, strict type safety, and so on. It's the way it is because designers were allowed to distrust the user, and the culture said that it was good to distrust the user. Consequently, the interface is a pain to use, with all kinds of boilerplate and iterator types and such. ElementTree was borne out of an environment where implementors are forced to trust the user. As a consequence it was free to create an interface that was natural and straightforward and pleasant to use, without having to be guarded. Carl Banks From philip at semanchuk.com Tue Jan 13 23:18:50 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 23:18:50 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <078F3865-79F1-4C48-8170-B4EE777FC8FF@semanchuk.com> On Jan 13, 2009, at 9:42 PM, ajaksu wrote: > On Jan 13, 1:33 am, Philip Semanchuk wrote: >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? > > Hi, sorry for taking so long to reply :) > > I imagine it's something akin to Firefox's 'Report broken website': > evangelism. > > IMHO, if the PSF *cough* Steve *cough* or individual Python hackers > can contact key sites (as Wikipedia, groups.google, etc.) the issue > can be solved sooner. > > Instead of waiting for each whitelist maintainer's to find out we have > a new UA, go out and tell them. A template for such requests could > help those inside e.g. Google to bring the issue to the attention of > the whitelist admins. The community has lots of connections that could > be useful to pass the message along, if only 'led by the nose' to > achieve that :) > > Hence, the suggestion to raise a bug. Gotcha. In this case I think there is no whitelist. I think Google has a default accept policy supplemented with a blacklist rather than a default ban policy mitigated by a whitelist. As evidence I submit the fact that my user agent of "funny fish" was accepted. In other words, Google has taken explicit steps to ban agents sending the default Python UA. Now, if the default UA changed in Python 3.0, maybe the best thing to do is keep quiet and maybe it will fly under the Google radar for a while. =) Cheers Philip From rt8396 at gmail.com Tue Jan 13 23:24:14 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 20:24:14 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <1cbcd14d-ced0-4d0a-a1ae-f017096478b4@a12g2000pro.googlegroups.com> On Jan 13, 9:50?pm, Carl Banks wrote: [snip] it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. [snip] > Carl Banks I agree, the second the Python interpretor say's NO! you cant do that or i will wrap your knuckles! is the day i leave Python forever. I hear C programmers complain all the time about Python saying; "Well, I like in "C" that variable types must be declared because this keeps me from making mistakes later" -- hog wash! Just learn to think in a dynamic way and you will never have any problems. If you need a hand holding language i guess Python is not for you. And don't forget, you can learn a lot from your mistakes. They are so brainwashed by this mumbo-jumbo, i see them do this all the time... int_count = 0 float_cost = 1.25 str_name = "Bob" They can't think in a dynamic way because momma "C" has done it for them for too long. "Eat your Peas and carrots now little C coder" :D From prologic at shortcircuit.net.au Tue Jan 13 23:24:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 14:24:37 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:50 PM, Carl Banks wrote: > 1. Wise people don't believe everything that is written on Wikipedia. > 2. The person who wrote that line in Python.org is a wise person. Agreed. > You know what? Computer science buzzwords mean jack squat to me. I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. I think it's a bad > thing. And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. +1 > No thanks. "Software engineering" be damned. Python is better off > the way it is. Python ihmo is one of the best engineered programming languages and platform I have ever had the pleasure of working with and continue to! :) --JamesMills From drobinow at gmail.com Tue Jan 13 23:26:14 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Tue, 13 Jan 2009 20:26:14 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 5:08?pm, Philip Semanchuk wrote: > On Jan 13, 2009, at 4:31 PM, drobi... at gmail.com wrote: > > > On Jan 13, 2:37 pm, Philip Semanchuk wrote: > >> I was suggesting getting posix_ipc or sysv_ipc to compile against a > >> compatibility library (Cygwin?) under Windows. It sounds like you're > >> proposing something totally different, no? > > > It's not really correct to call Cygwin a compatibility library. It's > > more of a separate system. > > Thanks for the education; I'm obviously not very familiar with it. > > > In any case, the current version (1.5.25) does not support sem_unlink > > or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under > > test, will support these. ?I haven't tried it yet. I expect it will > > work OOTB. > > Thanks for the report. Strange that it supports the functions to open ? > but not close semaphores. IN any case, I'd be very happy if posix_ipc ? > or sysv_ipc would work with few or no modifications under Cygwin. > > Cheers > Philip I just downloaded cygwin 1.7 and posix_ipc builds successfully. The demo appears to work. From malaclypse2 at gmail.com Tue Jan 13 23:42:51 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 13 Jan 2009 23:42:51 -0500 Subject: Weird behaviour re: Python on Windows In-Reply-To: References: <496CC069.80909@shopzeus.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> Message-ID: <16651e80901132042u5862a716g9442ad497d76bb82@mail.gmail.com> On Tue, Jan 13, 2009 at 5:29 PM, Kevin Jing Qiu wrote: > I've been experiencing weird behavior of Python's os module on Windows: > > Here's the environment: > Box1: Running Windows 2003 Server with Apache+mod_python > Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ > on Box1 > > It appears any os calls that deals with file/dir on the mapped drive is > problematic. What user is this running as? By any chance is it running as the Local System user? If so, that user has no network privileges, including to mapped drives. -- Jerry From roy at panix.com Tue Jan 13 23:43:44 2009 From: roy at panix.com (Roy Smith) Date: Tue, 13 Jan 2009 23:43:44 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: In article , "Russ P." wrote: > I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. I have no idea if Python is strictly anything. What I do know is that it's a useful tool. I'll take useful over OOO (Object Oriented Orthodoxy) any day. People get all worked up over OO as if it were some kind of religion. If I want religion, I'll go to shul. What I want from a programming language is a tool that lets me get my work done. If I transgress against some sacred tenet of OO religion, it is, as Rev. Dupas would say, all right. Earlier in this thread, somebody (name elided to avoid me getting pegged for a indulging in a spelling flame): > Bare in mind also, that enfocing access control / policing as you > called it has a performance hit as the machine (the Python vm) > has to perform checks each time members of an object are accessed. All I can say to that is, "He who bares his mind, soon gets to the naked truth". From Russ.Paielli at gmail.com Tue Jan 13 23:54:41 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 20:54:41 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <73d6eefc-44e5-4841-ab9c-6a9746727568@40g2000prx.googlegroups.com> On Jan 13, 7:50?pm, Carl Banks wrote: > On Jan 13, 6:45?pm, "Russ P." wrote: > > > > > On Jan 13, 3:07 pm, Carl Banks wrote: > > > > I've seen no evidence that any Python project is moving even remotely > > > toward data encapsulation. ?That would be a drastic change. ?Even if > > > it were only a minor change in the implementation (and it would not > > > be), it would be a major stroke in the Python community. ?It would > > > basically cause a wholescale power shift from the user to the > > > implementor. ?As a user it'd be like the difference between living in > > > a free democracy and a fascist dictatorship. > > > I just googled "object oriented principles." The first site that came > > up lists four princicples: > > > - Encapsulation > > - Abstraction > > - Inheritance > > - Polymorphism > > > The Wikipedia entry for "object-oriented programming" also lists > > encapsulation as a "fundamental concept." > > > The first line on the python.org site says: > > > "Python is a dynamic object-oriented programming language that can be > > used for many kinds of software development." > > > How can that possibly be true if you see "no evidence that any Python > > project is moving even remotely toward data encapsulation"? > > Is this seriously your argument? ?Python must be moving towards data > encapsulation because there is a line in Python.org that, if you > blindly accept the Wikipedia definition as truth, indirectly implies > that it is? > > Are you *seriously* arguing this? Did you read what I wrote? If so, you apparently didn't understand it. > The argument is too ridiculous to deserve a refutation, so I'll just > point out two things: > > 1. Wise people don't believe everything that is written on Wikipedia. Nice try at diverting attention. The issue is not Wikipedia. As far as I know, the definition of OOP given on Wikipedia is not controversial -- at least not anywhere but here. > 2. The person who wrote that line in Python.org is a wise person. Oh, isn't that wonderful. Wow, I sure wish I was wise like that person! > > Semantics aside, I fail to understand your hostility toward a > > fundamental concept of object-oriented programming. The difference > > between a free democracy and a "fascist dictatorship"? Give me a > > break! > > You know what? ?Computer science buzzwords mean jack squat to me. ?I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. ?I think it's a bad > thing. ?And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. > > No thanks. ?"Software engineering" be damned. ?Python is better off > the way it is. Now that's just classic. "We have Python and we don't need no stinkin' software engineering." Well, you may not need it in your line of work, but I need it in mine. In my line of work, Python is a tool, not a religious faith. From rt8396 at gmail.com Wed Jan 14 00:00:29 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 21:00:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Here is a piece of C code this same guy showed me saying Pythonic indention would make this hard to read -- Well lets see then! I swear, before god, this is the exact code he showed me. If you don't believe me i will post a link to the thread. // Warning ugly C code ahead! if( is_opt_data() < sizeof( long double ) ) { // test for insufficient data return TRUE; // indicate buffer empty } // end test for insufficient data if( is_circ() ) { // test for circular buffer if( i < o ) { // test for data area divided if( ( l - o ) > sizeof( long double ) ) { // test for data contiguous *t = ( ( long double * ) f )[ o ]; // return data o += sizeof( long double ); // adjust out if( o >= l ) { // test for out wrap around o = 0; // wrap out around limit } // end test for out wrap around } else { // data not contiguous in buffer return load( ( char * ) t, sizeof( long double ) ); // return data } // end test for data contiguous } else { // data are not divided *t = ( ( float * ) f )[ o ]; // return data o += sizeof( long double ); // adjust out if( o >= l ) { // test for out reached limit o = 0; // wrap out around } // end test for out reached limit } // end test for data area divided } else { // block buffer *t = ( ( long double * ) f )[ o ]; // return data o += sizeof( long double ); // adjust data pointer } // end test for circular buffer if i where to write the same code in a 'Python style" it would look like below. And personally i would never use that many comments in my code. I normally in a situation as this one would only comment each major conditional code block, and only if it contains code that is not completely obvious. Commenting is important, but it *can* be over done. #-- Python Style --# if is_opt_data() < sizeof(long double): return TRUE if is_circ(): if i < o: #test for data area divided if (l-o) > sizeof(long double): #test for data contiguous *t = ( ( long double * ) f )[ o ] o += sizeof( long double ) if o >= l: o = 0 else: #data not contiguous in buffer return load((char*) t, sizeof(long double)) else: #data are not divided *t = ((float*) f)[ o ] o += sizeof(long double) if o >= l: #test for out reached limit o = 0 else: #block buffer *t = ((long double*) f)[ o ] o += sizeof(long double) WOW!, without all the braces, and over commenting, i can actually read this code now! Of course it would not run in C or Python but the point here is readability. Python forged the path for all 21st century languages. Get on board, or get on with your self.extinction() -- Your Choice! From Russ.Paielli at gmail.com Wed Jan 14 00:11:44 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 21:11:44 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> On Jan 13, 7:32?pm, "James Mills" wrote: > On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: > > Yes, but the fact that you can approximate OO programming in a > > particular language does not make that language object oriented. You > > can approximate OO programming in C, but that does not mean that C is > > an OO language. > > Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) > (Please stop confusing the two) is not a strict requirements of the OO model. I think you are the one who is confused. Part of the problem here is that the term "encapsulation" has at least two widely used meanings (in the context of programming). In one sense, it just means grouping data and methods together. In another sense, it means restricting the client's access to data or methods. Someone earlier on this thread tried to claim that the first meaning applies to OOP, but Wikipedia (and many other sources) say just the opposite. People here are trying to claim that the leading underscore conventions used with Python are essentially equivalent to encapsulation. That is nonsense, of course. Others are arguing against encapsulation altogether. That is a bit like being against locks or passwords because they create a lot of hassle. Now locks are not needed everywhere, of course, but certainly they have their place. But the point is that if you don't like encapsulation, then by definition you don't like OOP. You may like certain features of OOP, but you don't like it in general. That's about all their is to it. And by the way, please don't bring up the canard that I am some kind of OO zealot. I think OO is overrated, and I don't Java, in part because it forces everything to be OO. The issue here is not my personal opinion of OOP. This issue is one of widely accepted definitions within the OO community. > Remember that it is a model and not a strict set of requirements that > programming > languages must implement. Of course it's not a "requirement that programming languages must implement." It's only a requirement if they want to be OO languages. > In fact, Python borrows features from the Functional Paradigm. Does this > make it a Functional Language ? No. Why ? Because one of the clear > requirements of the Functional Paradigm is that functions cannot have > side affects. > > > So I can claim that Python is not strictly object oriented until it > > gets encapsulation (in the sense of data hiding). That is simply a > > fact, and no amount of pleading or obfuscation will change it. > > In fact this is true, C can be seen as an programming language > that has features of the OO model. > > I think one of the things you guys are missing out > here is that there are really only two Paradigms > or Machines. Functional and Imperative. And guess > what ? As it turns out we can implement functional > machines that run on top of imperative ones! > > > Should Python get true encapsulation? I don't know. Maybe > > encapsulation cannot be added without excessive overhead or without > > compromising other more important aspects and features of the > > language. But I do know that not having encapsulation is a limitation > > to the use of Python for good software engineering. I may be in the > > minority in the Python "community" on this one, but I am apparently in > > the majority in the OO programming "community." > > Again, stop confusing terminology. > > Should Python get strict and enforce access control > of object members ? No. Why ? I can think of several > reasons. > > Give me one use-case where you strictly require > that members of an object be private and their > access enforced as such ? You're kidding, right? Think about a ten-million line program being developed by 100 developers. From philip at semanchuk.com Wed Jan 14 00:14:12 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jan 2009 00:14:12 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2009, at 11:26 PM, drobinow at gmail.com wrote: > On Jan 13, 5:08 pm, Philip Semanchuk wrote: >> On Jan 13, 2009, at 4:31 PM, drobi... at gmail.com wrote: >> >>> On Jan 13, 2:37 pm, Philip Semanchuk wrote: >>>> I was suggesting getting posix_ipc or sysv_ipc to compile against a >>>> compatibility library (Cygwin?) under Windows. It sounds like >>>> you're >>>> proposing something totally different, no? >> >>> It's not really correct to call Cygwin a compatibility library. It's >>> more of a separate system. >> >> Thanks for the education; I'm obviously not very familiar with it. >> >>> In any case, the current version (1.5.25) does not support >>> sem_unlink >>> or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently >>> under >>> test, will support these. I haven't tried it yet. I expect it will >>> work OOTB. >> >> Thanks for the report. Strange that it supports the functions to open >> but not close semaphores. IN any case, I'd be very happy if posix_ipc >> or sysv_ipc would work with few or no modifications under Cygwin. >> >> Cheers >> Philip > > I just downloaded cygwin 1.7 and posix_ipc builds successfully. The > demo appears to work. Most excellent! Thank you for the good news. From prologic at shortcircuit.net.au Wed Jan 14 00:25:38 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 15:25:38 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: (...) >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. No I"m sorry this is not a valid use-case. cheers James From michele.simionato at gmail.com Wed Jan 14 00:29:29 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 13 Jan 2009 21:29:29 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Jan 14, 2:02?am, Catherine Moroney wrote: > Hello everybody, > > I know how to spawn a sub-process and then wait until it > completes. ?I'm wondering if I can do the same thing with > a Python function. > > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. ?Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? > > I'm primarily concerned about code readability and ease of > programming. ?The code would look a lot prettier and be shorter > to boot if I could spawn off function calls rather than > subprocesses. > > Thanks for any advice, > > Catherine There is an example explaining how to implement exactly this use case in the documentation of my decorator module: http://pypi.python.org/pypi/decorator/3.0.0#async The Async decorator works both with threads and with multiprocessing. Here is an example of printing from multiple processes (it assumes you downloaded the tarball of the decorator module, documentation.py is the file containing the documentation and the Async decorator; it also assumes you have the multiprocessing module): $ cat example.py import os, multiprocessing from documentation import Async async = Async(multiprocessing.Process) @async def print_msg(): print 'hello from process %d' % os.getpid() for i in range(3): print_msg() $ python example.py hello from process 5903 hello from process 5904 hello from process 5905 From Russ.Paielli at gmail.com Wed Jan 14 00:35:34 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 21:35:34 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 7:50?pm, Carl Banks wrote: > You know what? ?Computer science buzzwords mean jack squat to me. ?I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. ?I think it's a bad > thing. ?And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. > > No thanks. ?"Software engineering" be damned. ?Python is better off > the way it is. You know what? The more I think about the kind of nonsense you and others are spouting here, the more annoyed I get. I will gladly agree that encapsulation may be more trouble than it's worth for small applications, maybe even some medium sized ones, but you and others here are making blanket proclamations that are just plain nonsense. I suggest you call Boeing and tell them that encapsulation is more trouble than it's worth for their 787 flight software. But please don't do it if you ever wish to work for them, because you will be proving conclusively that you don't have a clue about the kind of software systems they produce. I've wasted more than enough time with this nonsense. From krmane at gmail.com Wed Jan 14 00:46:58 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 11:16:58 +0530 Subject: initialising a class by name Message-ID: <1231912018.7570.22.camel@krishna-laptop> hello all, I have a strange situation where I have to load initiate an instance of a class at run-time with the name given by the user from a dropdown list. Is this possible in python and how? To make things clear, let me give the real example. there is an inventory management system and products belong to different categories. There are predefined categories in the database and for each category there is a module which contains a class made out of pygtk. This means what class gets instantiated and displayed in the gui depends on the choice a user makes in the dropdown. Now, I could have created a list of if conditions for all the categories as in if categorySelection == "books": Books = BookForm() However this is a problem because when there will be more than 100 categories there will be that many if conditions and this will make the code uggly. so my idea is to name the class exactly after the name of the category so that when the user selects a category that name is used to initialise the instance of that class. So is it possible to initialise an instance of a class given its name from a variable? thanks and Happy hacking. Krishnakant. From clp2 at rebertia.com Wed Jan 14 00:51:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 21:51:37 -0800 Subject: initialising a class by name In-Reply-To: <1231912018.7570.22.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> On Tue, Jan 13, 2009 at 9:46 PM, Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. > Is this possible in python and how? > To make things clear, let me give the real example. > there is an inventory management system and products belong to different > categories. > There are predefined categories in the database and for each category > there is a module which contains a class made out of pygtk. > This means what class gets instantiated and displayed in the gui depends > on the choice a user makes in the dropdown. > Now, I could have created a list of if conditions for all the categories > as in > if categorySelection == "books": > Books = BookForm() > > However this is a problem because when there will be more than 100 > categories there will be that many if conditions and this will make the > code uggly. > so my idea is to name the class exactly after the name of the category > so that when the user selects a category that name is used to initialise > the instance of that class. > So is it possible to initialise an instance of a class given its name > from a variable? > thanks and Assuming all the classes are in the same module as the main program: instance = vars()[class_name](args, to, init) Assuming the classes are all in the same module "mod", which is separate from the main program: instance = getattr(mod, class_name)(args, to, init) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From prologic at shortcircuit.net.au Wed Jan 14 00:57:42 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 15:57:42 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: > I think you are the one who is confused. Part of the problem here is > that the term "encapsulation" has at least two widely used meanings > (in the context of programming). In one sense, it just means grouping > data and methods together. In another sense, it means restricting the > client's access to data or methods. Someone earlier on this thread > tried to claim that the first meaning applies to OOP, but Wikipedia > (and many other sources) say just the opposite. > > People here are trying to claim that the leading underscore > conventions used with Python are essentially equivalent to > encapsulation. That is nonsense, of course. > > Others are arguing against encapsulation altogether. That is a bit > like being against locks or passwords because they create a lot of > hassle. Now locks are not needed everywhere, of course, but certainly > they have their place. But the point is that if you don't like > encapsulation, then by definition you don't like OOP. You may like > certain features of OOP, but you don't like it in general. That's > about all their is to it. > > And by the way, please don't bring up the canard that I am some kind > of OO zealot. I think OO is overrated, and I don't Java, in part > because it forces everything to be OO. The issue here is not my > personal opinion of OOP. This issue is one of widely accepted > definitions within the OO community. Russ: 1. Quit while you're ahead. 2. OOP is encapsulating data and functionality into a single grouping (object). 3. Other features more recently developed by OO languages such as Polymorphism, Access Control (a type of encapsulation), Inheritance and Multiple Inheritance are all irrelevant and OO languages either implement all or a subset of these features and each do so differently. Fundamentally it all boils down to4 things (which all of you - including you Russ - just completely miss the point): READ UPDATE ADVANCE These are the 3 operations of a Turing machine of which all computer algorithms can be defined. We usually define a 4th operation called HALT. Now go ponder on that a while and come back and tell me whether you think you really need such things as Abstract Base Classes, Interfaces, Access Control, Static Typing, and so on and so forth ... >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. And what is your point exactly ? Like I said, this is _not_ a valid use case. A language that implements all of the features descirbed in academic texts on OOP will not help you build such a system any faster. I should also point out that building such a system in Python would most likely result in 1/3 of the size in terms of LoC. I should also point out that your numbers you pulled out of your hat would require 22years of development time given the industry standard of 5 LOC/hg per developer. Good luck with that. cheers James From prologic at shortcircuit.net.au Wed Jan 14 01:02:28 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:02:28 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:35 PM, Russ P. wrote: > You know what? The more I think about the kind of nonsense you and > others are spouting here, the more annoyed I get. I will gladly agree > that encapsulation may be more trouble than it's worth for small > applications, maybe even some medium sized ones, but you and others > here are making blanket proclamations that are just plain nonsense. > > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. > > I've wasted more than enough time with this nonsense. I am 100% confident that those same systems could be well written in a language such as Python and would very likely end up being much smaller and more manageable. I have a question for you: All your arguments seem to lean towards size and the importance of encapsulation. What is the largest system you have worked on - that has been written entirely in Python ? cheers James From http Wed Jan 14 01:35:31 2009 From: http (Paul Rubin) Date: 13 Jan 2009 22:35:31 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <7x3afm2y4s.fsf@ruckus.brouhaha.com> "James Mills" writes: > Bare in mind also, that enfocing access control / policing as you > called it has a performance hit as the machine (the Python vm) > has to perform checks each time members of an object are accessed. It's the other way around. If the compiler knows that you aren't creating new attributes on the fly, it can put them into fixed slots like a C struct, and method calls become ordinary function calls through a dispatch vector. From catphive at catphive.net Wed Jan 14 01:49:34 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 13 Jan 2009 22:49:34 -0800 Subject: pep 8 constants Message-ID: PEP 8 doesn't mention anything about using all caps to indicate a constant. Is all caps meaning "don't reassign this var" a strong enough convention to not be considered violating good python style? I see a lot of people using it, but I also see a lot of people writing non-pythonic code... so I thought I'd see what the consensus is. Brendan From prologic at shortcircuit.net.au Wed Jan 14 01:55:34 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:55:34 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3afm2y4s.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 4:35 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "James Mills" writes: >> Bare in mind also, that enfocing access control / policing as you >> called it has a performance hit as the machine (the Python vm) >> has to perform checks each time members of an object are accessed. > > It's the other way around. If the compiler knows that you aren't > creating new attributes on the fly, it can put them into fixed slots > like a C struct, and method calls become ordinary function calls > through a dispatch vector. Paul I wasn't referring to static languages and languages that are compiled to machine code such as C, C++, etc. Python is a dynamic object oriented language ... (almost verbatim from the website). It is compiled to bytecode and run on a virtual machine. I don't really think it would be possible or desirable to have strict access control (encapsulation) in the core of python. a) it would piss us all off. b) it would greatly impact on the dynamic nature of python. cheers James From prologic at shortcircuit.net.au Wed Jan 14 01:58:40 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:58:40 +1000 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 4:49 PM, Brendan Miller wrote: > PEP 8 doesn't mention anything about using all caps to indicate a constant. > > Is all caps meaning "don't reassign this var" a strong enough > convention to not be considered violating good python style? I see a > lot of people using it, but I also see a lot of people writing > non-pythonic code... so I thought I'd see what the consensus is. It may in fact be deliberate. As there really are no such thing as constants in Python - clearly :) However, on the rare occasion I need to define a global variable in a module that gets used in several places and is more or less used as a standard configured value - I tend to use ALL CAPS. Still I would avoid using this idiom altogether and jsut stick with default values. For Example: FOO = 1 def f(x=FOO): ... Use this instead: def f(x=1): ... cheers James From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:14:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:14:06 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: > (...) > >>> Give me one use-case where you strictly require that members of an >>> object be private and their access enforced as such ? >> >> You're kidding, right? Think about a ten-million line program being >> developed by 100 developers. > > No I"m sorry this is not a valid use-case. Why not? Just saying it isn't doesn't make it not. -- Steven From steve at holdenweb.com Wed Jan 14 02:14:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 02:14:39 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: ajaksu wrote: > On Jan 13, 1:33 am, Philip Semanchuk wrote: >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? > > Hi, sorry for taking so long to reply :) > > I imagine it's something akin to Firefox's 'Report broken website': > evangelism. > > IMHO, if the PSF *cough* Steve *cough* or individual Python hackers > can contact key sites (as Wikipedia, groups.google, etc.) the issue > can be solved sooner. > > Instead of waiting for each whitelist maintainer's to find out we have > a new UA, go out and tell them. A template for such requests could > help those inside e.g. Google to bring the issue to the attention of > the whitelist admins. The community has lots of connections that could > be useful to pass the message along, if only 'led by the nose' to > achieve that :) > > Hence, the suggestion to raise a bug. > OK, but be aware that the PSF doesn't monitor the bugs looking for actions to take on behalf of the Python user community. In fact we aren't overtly "political" in this way at all. This doesn't mean it wouldn't be useful for the PSF to get involved in this role; just that right now it isn't, and a bug report probably isn't the best way to get action. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From thaisiang at gmail.com Wed Jan 14 02:21:25 2009 From: thaisiang at gmail.com (ts) Date: Tue, 13 Jan 2009 23:21:25 -0800 (PST) Subject: read string in bits Message-ID: hi, is there a way to read a character/string into bits in python? i understand that character is read in bytes. Do i have to write a function to convert it myself into 1010101 or there is a library in python that enable me to do that? From http Wed Jan 14 02:22:45 2009 From: http (Paul Rubin) Date: 13 Jan 2009 23:22:45 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> Message-ID: <7xpriqtkqi.fsf@ruckus.brouhaha.com> "James Mills" writes: > Python is a dynamic object oriented language ... (almost verbatim > from the website). It is compiled to bytecode and run on a virtual > machine. 1. There is nothing inherent about dynamic languages that prevents them from being compiled. There are compiled implementations of Lisp and Scheme that beat the pants off of Python in performance. 2. There is also nothing inherent in a dynamic OO language that says that class descriptors have to be mutable, any more than strings have to be mutable (Python has immutable strings). I agree that being able to modify class descriptors at runtime is sometimes very useful. The feature shouldn't be eliminated from Python or else it wouldn't be Python any more. But those occasions are rare enough that having to enable the feature by saying (e.g.) "@dynamic" before the class definition doesn't seem like a problem, both for encapsulation and because it can also improve performance. From catphive at catphive.net Wed Jan 14 02:26:54 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 13 Jan 2009 23:26:54 -0800 Subject: pep 8 constants In-Reply-To: References: Message-ID: > FOO = 1 > > def f(x=FOO): > ... > > > Use this instead: > > def f(x=1): > ... I tend to use constants as a means of avoiding the proliferation of magic literals for maintenance reasons... Like say if your example of FOO would have been used in 10 places. Maybe it is more pythonic to simply denote such a thing as simply a normal variable? That doesn't seem to give a hint that it shouldn't be assigned a second time. From clp2 at rebertia.com Wed Jan 14 02:32:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 23:32:58 -0800 Subject: read string in bits In-Reply-To: References: Message-ID: <50697b2c0901132332i1b8ce526rd1d0bab37eca7797@mail.gmail.com> On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > hi, is there a way to read a character/string into bits in python? > > i understand that character is read in bytes. Do i have to write a > function to convert it myself into 1010101 or there is a library in > python that enable me to do that? It's not quite clear to me what you mean, but here are 2 guesses: - If you want to convert an ASCII character to its ASCII integer value, use ord() - If you want to convert an integer into a string of its base-2 representation, use bin() [requires Python 2.6, I think] Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From pavlovevidence at gmail.com Wed Jan 14 02:34:15 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 23:34:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 11:35?pm, "Russ P." wrote: > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. That's funny. I worked for four years at a GE Aviation subcontractor on their jet engine control software, so I think do I have a clue about how flight control software systems work. At GE there was no encapsulation in sight on any system I worked on. In fact, our engine simulation was a special-purpose object-oriented language with--get this--no private variables. Some other systems I worked on didn't even use scoping, let alone encapsulation. Looks like my anecdote cancels out yours! Got any more? Carl Banks From steve at holdenweb.com Wed Jan 14 02:35:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 02:35:53 -0500 Subject: are there some special about '\x1a' symbol In-Reply-To: References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Unknown wrote: > On 2009-01-12, John Machin wrote: > >> I didn't think your question was stupid. Stupid was (a) CP/M recording >> file size as number of 128-byte sectors, forcing the use of an in-band >> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >> decades after people stopped writing Ctrl-Z at the end of text files. > > I believe that "feature" was inherited by CP/M from DEC OSes > (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API > (including the FCB) was lifted almost directly from DEC's > PDP-11 stuff, which probably copied it from PDP-8 stuff. > > Perhaps in the early 60's somebody at DEC had a reason. The > really interesting thing is that we're still suffering because > of it 40+ years later. > I suspect this is probably a leftover from some paper tape data formats, when it was easier to detect the end of a file with a sentinel byte than it was to detect run-off as end of file. It could easily date back to the PDP-8. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent.gulinao at gmail.com Wed Jan 14 02:37:30 2009 From: vincent.gulinao at gmail.com (Vincent Gulinao) Date: Wed, 14 Jan 2009 15:37:30 +0800 Subject: WebDAV client module In-Reply-To: References: Message-ID: Um.. and I can't seem to find any sample code of it around. Can anybody share a simple snippet of how to use it? I don't understand what's URI in PutFile method is suppose to be. TIA. On Tue, Jan 13, 2009 at 8:03 PM, Vincent Gulinao wrote: > Kindly point me to a good WebDAV client module for Python. Looks like PyDav > is popular, but it seems some of the modules used within were already > deprecated. > > TIA. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:40:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:40:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Tue, 13 Jan 2009 20:17:08 -0800, Carl Banks wrote: > On Jan 13, 9:50?pm, Carl Banks wrote: >> The cultural impact that would have on the community is far worse, >> IMHO, than any short-sighted benefits like being able to catch an >> accidental usage of an internal variable. Trust would be replaced by >> mistrust, and programming in Python would go from a pleasant experience >> to constant antagonism. > > And I'll give you a perfect example: > > XML-DOM versus ElementTree > > XML-DOM is the sort of standard that is borne of a culture that values > encapsulation, strict type safety, and so on. It's the way it is > because designers were allowed to distrust the user, and the culture > said that it was good to distrust the user. Consequently, the interface > is a pain to use, with all kinds of boilerplate and iterator types and > such. > > ElementTree was borne out of an environment where implementors are > forced to trust the user. As a consequence it was free to create an > interface that was natural and straightforward and pleasant to use, > without having to be guarded. Which is all well and good, but there are circumstances where you *don't* want to trust arbitrary parts of your code to change other parts of your code, for good reason. In other words, you don't always want to trust your users. Forget copy protection and DRM. Think about the software controlling a radiation machine for cancer treatment, with a limit on the number of rads it fires at any one time. It would be disastrous for any arbitrary function in the machine's software to be able to mess with that limit, accidentally or deliberately. People will die if you get it wrong. My attitude when programming in Python is to accept that if the caller passes an inappropriate argument to my function, my function may crash (raise an exception). That's the caller's responsibility. I can get away with this laissez faire attitude because I don't have to worry about my software crashing at the wrong time and causing a plane filled with 500 nuns and orphans suddenly flip upside down and nose-dive into a mountain. Or the nuclear reactor to suddenly drop all the fuel rods into the core simultaneously. Sometimes "oh, just raise an exception and exit" is simply not good enough. Security/safety and freedom/flexibility are sometimes in conflict. There are plenty of languages which enforce access. It is a good thing that Python allows more flexibility. That's why I use Python. The traditional answer to this "if you need Java, you know where to get it". But, gosh darn it, wouldn't it be nice to program the critical parts of your code in "strict Python", and leave the rest as "trusting Python", instead of having to use Java for the lot just to get strictness in the critical parts? If only there was a way to do this, and ensure people won't abuse it. -- Steven From thaisiang at gmail.com Wed Jan 14 02:44:07 2009 From: thaisiang at gmail.com (ts) Date: Tue, 13 Jan 2009 23:44:07 -0800 (PST) Subject: read string in bits References: Message-ID: On Jan 14, 3:32?pm, Chris Rebert wrote: > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > hi, is there a way to read a character/string into bits in python? > > > i understand that character is read in bytes. Do i have to write a > > function to convert it myself into 1010101 or there is a library in > > python that enable me to do that? > > It's not quite clear to me what you mean, but here are 2 guesses: > - If you want to convert an ASCII character to its ASCII integer > value, use ord() > - If you want to convert an integer into a string of its base-2 > representation, use bin() [requires Python 2.6, I think] > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com hi, bin() is what i'm looking for. But only python 2.4 is available to me. Is there a replacement of bin() in python 2.4? From krmane at gmail.com Wed Jan 14 02:49:23 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:19:23 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> Message-ID: <1231919363.7570.27.camel@krishna-laptop> On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: > Assuming all the classes are in the same module as the main program: > > instance = vars()[class_name](args, to, init) > The classes are not in the same module. Every glade window is coupled with one py file (module) containing one class that has the events for the glade file. Inshort, there is one class in one module and they are all seperate. > Assuming the classes are all in the same module "mod", which is > separate from the main program: > > instance = getattr(mod, class_name)(args, to, init) > Can you explain the difference between getattr and var()? > Cheers, > Chris > happy hacking. Krishnakant. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:50:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:50:47 GMT Subject: initialising a class by name References: Message-ID: On Wed, 14 Jan 2009 11:16:58 +0530, Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. Not strange at all. > Is this possible in python and how? Of course. Just use a dispatch table. Use a dict to map user strings to classes: >>> class Spam(object): pass ... >>> class Ham(object): pass ... >>> dispatch_table = {"Spam": Spam, "Ham": Ham} >>> dispatch_table["Ham"]() <__main__.Ham object at 0xb7ea2f8c> The keys don't even have to be the name of the class, they can be whatever input your users can give: >>> dispatch_table["Yummy meat-like product"] = Spam >>> dispatch_table["Yummy meat-like product"]() <__main__.Spam object at 0xb7ea2f6c> You can even automate it: >>> dispatch_table = {} >>> for name in dir(): ... obj = globals()[name] ... if type(obj) == type: ... dispatch_table[name] = obj ... >>> dispatch_table {'Ham': , 'Spam': } -- Steven From http Wed Jan 14 02:51:58 2009 From: http (Paul Rubin) Date: 13 Jan 2009 23:51:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <7xsknmwcip.fsf@ruckus.brouhaha.com> Carl Banks writes: > At GE there was no encapsulation in sight on any system I worked on. > In fact, our engine simulation was a special-purpose object-oriented > language with--get this--no private variables. Some other systems I > worked on didn't even use scoping, let alone encapsulation. Where my officemate used to work, the simulation stuff was written in Matlab, but the actual flight stuff was written in Ada. I wonder if GE did something similar. From clp2 at rebertia.com Wed Jan 14 02:55:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 23:55:21 -0800 Subject: initialising a class by name In-Reply-To: <1231919363.7570.27.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> Message-ID: <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> Assuming all the classes are in the same module as the main program: >> >> instance = vars()[class_name](args, to, init) >> > The classes are not in the same module. > Every glade window is coupled with one py file (module) containing one > class that has the events for the glade file. > Inshort, there is one class in one module and they are all seperate. >> Assuming the classes are all in the same module "mod", which is >> separate from the main program: >> >> instance = getattr(mod, class_name)(args, to, init) >> > Can you explain the difference between getattr and var()? getattr(x, 'y') <==> x.y vars() gives a dict representing the current accessible variable bindings (I should have instead recommended the related globals() function) globals() gives a dict representing the global variable bindings For example: #foo.py class Foo(object): #code here Foo() #same as globals()['Foo']() #end of file Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Wed Jan 14 03:06:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 14 Jan 2009 06:06:11 -0200 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: En Tue, 13 Jan 2009 22:04:33 -0200, Terry Reedy escribi?: > Gabriel Genellina wrote: >> En Mon, 12 Jan 2009 12:00:16 -0200, John Machin >> escribi?: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> This is called "backwards compatibility" and it's a good thing :) > > But it does not have to be the default or only behavior to be available. Sure. And it isn't - there are many flags to open and fopen to choose from... The C89 standard (the language used to compile CPython) guarantees *only* that printable characters, tab, and newline are preserved in a text file; everything else may or may not appear when it is read again. Even whitespace at the end of a line may be dropped. Binary files are more predictable... Delphi recognizes the EOF marker when reading a text file only inside the file's last 128-byte block -- this mimics the original CP/M behavior rather closely. I thought the MSC runtime did the same, but no, the EOF marker is recognized anywhere. And Python inherits that (at least in 2.6 -- I've not tested with 3.0) -- Gabriel Genellina From pavlovevidence at gmail.com Wed Jan 14 03:08:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 00:08:51 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 14, 1:40?am, Steven D'Aprano wrote: > On Tue, 13 Jan 2009 20:17:08 -0800, Carl Banks wrote: > > On Jan 13, 9:50?pm, Carl Banks wrote: > >> The cultural impact that would have on the community is far worse, > >> IMHO, than any short-sighted benefits like being able to catch an > >> accidental usage of an internal variable. Trust would be replaced by > >> mistrust, and programming in Python would go from a pleasant experience > >> to constant antagonism. > > > And I'll give you a perfect example: > > > XML-DOM versus ElementTree > > > XML-DOM is the sort of standard that is borne of a culture that values > > encapsulation, strict type safety, and so on. ?It's the way it is > > because designers were allowed to distrust the user, and the culture > > said that it was good to distrust the user. ?Consequently, the interface > > is a pain to use, with all kinds of boilerplate and iterator types and > > such. > > > ElementTree was borne out of an environment where implementors are > > forced to trust the user. ?As a consequence it was free to create an > > interface that was natural and straightforward and pleasant to use, > > without having to be guarded. > > Which is all well and good, but there are circumstances where you *don't* > want to trust arbitrary parts of your code to change other parts of your > code, for good reason. In other words, you don't always want to trust > your users. > > Forget copy protection and DRM. Think about the software controlling a > radiation machine for cancer treatment, with a limit on the number of > rads it fires at any one time. It would be disastrous for any arbitrary > function in the machine's software to be able to mess with that limit, > accidentally or deliberately. People will die if you get it wrong. I'm on record saying Python shouldn't be used for systems with the possibility of catastrophic failure: that's with or without encapsulation. Too much happening internally to account for it all. Frankly I'm not sure that C++ and Java's encapsulation is good enough, either. Software-enforced encapsulation can be subverted, and sometimes invalid access can happen from within the protection zone. If something's that important, it needs to be running with redundancy and lots and lots of fault tolerance, and it needs to have the hell tested out of it. If it's critically important, the code should be storing the critical information in a separate data area with a higher privledge level than the rest of the program. The simpleminded encapsulation schemes of C++ and Java are weak compared to these methods, and probably wouldn't add much. As I said, I've worked on flight control systems that didn't use any data hiding at all. Even if a drastic coding mistake like you mentioned was able to make it though dozens of peer reviews and hundreds of tests, it still might not result in catastrophic failure because of all the fault tolerance built-in. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:13:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:13:30 GMT Subject: pep 8 constants References: Message-ID: On Tue, 13 Jan 2009 23:26:54 -0800, Brendan Miller wrote: > I tend to use constants as a means of avoiding the proliferation of > magic literals for maintenance reasons... Like say if your example of > FOO would have been used in 10 places. Maybe it is more pythonic to > simply denote such a thing as simply a normal variable? But it isn't a "normal variable", it's a named constant, or at least it would be if Python enforced constanticity. Or constantness. Or whatever. > That doesn't > seem to give a hint that it shouldn't be assigned a second time. Absolutely. It's rather sad that I can do this: import math math.pi = 3.0 I like the ability to shoot myself in the foot, thank you very much, but I should at least get a warning when I'm about to do so: math.PI = 3.0 # use God-like powers to change a constant Changing the laws of physics, one fundamental constant at a time-ly y'rs, -- Steven From krmane at gmail.com Wed Jan 14 03:15:05 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:45:05 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> Message-ID: <1231920905.7570.40.camel@krishna-laptop> Hi, So should I not use getattr()? If I have one class in one module, then should I use global? I found getattr() very easy to use, my only dowbt is that if there is going to be one class per module then will it be a good idea? some thing like module, class_name happy hacking. Krishnakantt. On Tue, 2009-01-13 at 23:55 -0800, Chris Rebert wrote: > On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: > > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: > >> Assuming all the classes are in the same module as the main program: > >> > >> instance = vars()[class_name](args, to, init) > >> > > The classes are not in the same module. > > Every glade window is coupled with one py file (module) containing one > > class that has the events for the glade file. > > Inshort, there is one class in one module and they are all seperate. > >> Assuming the classes are all in the same module "mod", which is > >> separate from the main program: > >> > >> instance = getattr(mod, class_name)(args, to, init) > >> > > Can you explain the difference between getattr and var()? > > getattr(x, 'y') <==> x.y > > vars() gives a dict representing the current accessible variable > bindings (I should have instead recommended the related globals() > function) > globals() gives a dict representing the global variable bindings > For example: > #foo.py > class Foo(object): > #code here > > Foo() > #same as > globals()['Foo']() > #end of file > > Cheers, > Chris > From mail at microcorp.co.za Wed Jan 14 03:15:42 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 14 Jan 2009 10:15:42 +0200 Subject: read string in bits References: <50697b2c0901132332i1b8ce526rd1d0bab37eca7797@mail.gmail.com> Message-ID: <04f201c97622$21df0780$0d00a8c0@hendrik> "Chris Rebert" wrote: > It's not quite clear to me what you mean, but here are 2 guesses: > - If you want to convert an ASCII character to its ASCII integer > value, use ord() > - If you want to convert an integer into a string of its base-2 > representation, use bin() [requires Python 2.6, I think] Another case: >>> s = '1010101' >>> int (s,2) 85 >>> Works almost anywhere, AFAIK. - Hendrik From clp2 at rebertia.com Wed Jan 14 03:20:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 00:20:21 -0800 Subject: initialising a class by name In-Reply-To: <1231920905.7570.40.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> Message-ID: <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> On Wed, Jan 14, 2009 at 12:15 AM, Krishnakant wrote: > Hi, > So should I not use getattr()? > If I have one class in one module, then should I use global? > I found getattr() very easy to use, my only dowbt is that if there is > going to be one class per module then will it be a good idea? > some thing like module, class_name > happy hacking. > Krishnakantt. Aside from Steven's excellent idea, to use the getattr() technique with your module scheme you'd probably also need to use __import__() to dynamically import the right module. Also, don't top-post. It makes following the conversation harder for readers. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > On Tue, 2009-01-13 at 23:55 -0800, Chris Rebert wrote: > >> On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: >> > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> >> Assuming all the classes are in the same module as the main program: >> >> >> >> instance = vars()[class_name](args, to, init) >> >> >> > The classes are not in the same module. >> > Every glade window is coupled with one py file (module) containing one >> > class that has the events for the glade file. >> > Inshort, there is one class in one module and they are all seperate. >> >> Assuming the classes are all in the same module "mod", which is >> >> separate from the main program: >> >> >> >> instance = getattr(mod, class_name)(args, to, init) >> >> >> > Can you explain the difference between getattr and var()? >> >> getattr(x, 'y') <==> x.y >> >> vars() gives a dict representing the current accessible variable >> bindings (I should have instead recommended the related globals() >> function) >> globals() gives a dict representing the global variable bindings >> For example: >> #foo.py >> class Foo(object): >> #code here >> >> Foo() >> #same as >> globals()['Foo']() >> #end of file >> >> Cheers, >> Chris >> From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:23:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:23:07 GMT Subject: initialising a class by name References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> Message-ID: On Wed, 14 Jan 2009 13:19:23 +0530, Krishnakant wrote: > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> Assuming all the classes are in the same module as the main program: >> >> instance = vars()[class_name](args, to, init) >> > The classes are not in the same module. Every glade window is coupled > with one py file (module) containing one class that has the events for > the glade file. Inshort, there is one class in one module and they are > all seperate. Just import the classes you need, and dispatch on them. import spammodule, hammodule dispatch_table = { "Spam": spammodule.Spamclass, "Ham": hammodule.Hamclass} # later obj = dispatch_table[ user_input ]() >> Assuming the classes are all in the same module "mod", which is >> separate from the main program: >> >> instance = getattr(mod, class_name)(args, to, init) >> > Can you explain the difference between getattr and var()? They are completely different things. At an interactive prompt, type: help(getattr) help(var) and read what they say. -- Steven From hackingkk at gmail.com Wed Jan 14 03:23:52 2009 From: hackingkk at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:53:52 +0530 Subject: initialising a class by name In-Reply-To: References: Message-ID: <1231921432.7570.46.camel@krishna-laptop> Hi steevan, I liked this idea of dispatchTable. is it possible to say some thing like inst = dispatchTable{"ham"} according to me, inst will become the instance of class ham. Another thing to note is that all the classes are in different modules. So where do I create the dict of classes mapped with the name? happy hacking. Krishnakant. On Wed, 2009-01-14 at 07:50 +0000, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 11:16:58 +0530, Krishnakant wrote: > > > hello all, > > I have a strange situation where I have to load initiate an instance of > > a class at run-time with the name given by the user from a dropdown > > list. > > Not strange at all. > > > Is this possible in python and how? > > Of course. Just use a dispatch table. Use a dict to map user strings to > classes: > > > >>> class Spam(object): pass > ... > >>> class Ham(object): pass > ... > >>> dispatch_table = {"Spam": Spam, "Ham": Ham} > >>> dispatch_table["Ham"]() > <__main__.Ham object at 0xb7ea2f8c> > > > The keys don't even have to be the name of the class, they can be > whatever input your users can give: > > >>> dispatch_table["Yummy meat-like product"] = Spam > >>> dispatch_table["Yummy meat-like product"]() > <__main__.Spam object at 0xb7ea2f6c> > > > You can even automate it: > > >>> dispatch_table = {} > >>> for name in dir(): > ... obj = globals()[name] > ... if type(obj) == type: > ... dispatch_table[name] = obj > ... > >>> dispatch_table > {'Ham': , 'Spam': } > > > From mail at microcorp.co.za Wed Jan 14 03:24:17 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 14 Jan 2009 10:24:17 +0200 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <04f301c97622$2286e040$0d00a8c0@hendrik> "Steve Holden" wrote: > Unknown wrote: > > On 2009-01-12, John Machin wrote: > > I believe that "feature" was inherited by CP/M from DEC OSes > > (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API > > (including the FCB) was lifted almost directly from DEC's > > PDP-11 stuff, which probably copied it from PDP-8 stuff. > > > > Perhaps in the early 60's somebody at DEC had a reason. The > > really interesting thing is that we're still suffering because > > of it 40+ years later. > > > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. We can be kind of fortunate that the ASCII chars for field separator, record separator, file separator, unit separator did not catch on in a big way in file formatting. (remembering the Pick OS running on Reality...) - Hendrik From joost.ruyter at gmail.com Wed Jan 14 03:31:11 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 00:31:11 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem Message-ID: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> I have this really strange problem. I hope someone can help: I am trying to update a database like so: UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like '%certainvalue%' My Python code looks like this: fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like '%%%s%%' " % certainvalue print fillsql cursor.execute(fillsql) #also tried: #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like %s ", "%%%s%%" % certainvalue) But it doesn't work... But when i copy and past the SQL (printed by "print fillsql" line) and execute that in phpMyAdmin, it does work!!! Can anyone tell me what i am doing wrong?? Thanks in advance!! From sjmachin at lexicon.net Wed Jan 14 03:33:49 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 00:33:49 -0800 (PST) Subject: read string in bits References: Message-ID: <8fee210c-1775-4fc7-b0f8-6898529180cb@e1g2000pra.googlegroups.com> On Jan 14, 6:44?pm, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? No. You would have to write some code 8-( This should give you some clues: | Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> def char_as_number(char, base): | ... assert 2 <= base <= 16 | ... n = ord(char) | ... if not n: | ... return '0' | ... result = '' | ... while n: | ... n, r = divmod(n, base) | ... result = '0123456789ABCDEF'[r] + result | ... return result | ... | >>> [char_as_number(chr(x), 2) for x in (0, 1, 7, 8, 127, 128, 255)] | ['0', '1', '111', '1000', '1111111', '10000000', '11111111'] | >>> [char_as_number(chr(x), 2).zfill(8) for x in (0, 1, 7, 8, 127, 128, 255)] | ['00000000', '00000001', '00000111', '00001000', '01111111', '10000000', '11111111'] | >>> [char_as_number(chr(x), 16).zfill(2) for x in (0, 1, 7, 8, 127, 128, 255)] | ['00', '01', '07', '08', '7F', '80', 'FF'] | >>> [char_as_number(chr(x), 8).zfill(3) for x in (0, 1, 7, 8, 127, 128, 255)] | ['000', '001', '007', '010', '177', '200', '377'] | >>> HTH, John From pornbypost at gmail.com Wed Jan 14 03:35:01 2009 From: pornbypost at gmail.com (Mark Smith) Date: Wed, 14 Jan 2009 00:35:01 -0800 (PST) Subject: read string in bits References: Message-ID: <283174d4-df94-4d78-a218-2bb492019d9a@i20g2000prf.googlegroups.com> On Jan 14, 7:44?am, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? There's a recipe for this at ActiveState: http://code.activestate.com/recipes/219300/#c6 From pornbypost at gmail.com Wed Jan 14 03:36:45 2009 From: pornbypost at gmail.com (Mark Smith) Date: Wed, 14 Jan 2009 00:36:45 -0800 (PST) Subject: read string in bits References: Message-ID: <82f91b98-115d-4eeb-ba0f-c067e62d702e@q30g2000vbn.googlegroups.com> On Jan 14, 7:44?am, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? There's a recipe at ActiveState: http://code.activestate.com/recipes/219300/#c6 From krmane at gmail.com Wed Jan 14 03:36:49 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 14:06:49 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> Message-ID: <1231922209.7570.49.camel@krishna-laptop> On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > Aside from Steven's excellent idea, to use the getattr() technique > with your module scheme you'd probably also need to use __import__() > to dynamically import the right module. > I would generally import all the modules I would need at the top of the main module. then would use getattr(module,class_name) will that work? or do I need to import in some other way? happy hacking. Krishnakant. From clp2 at rebertia.com Wed Jan 14 03:39:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 00:39:50 -0800 Subject: initialising a class by name In-Reply-To: <1231922209.7570.49.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> <1231922209.7570.49.camel@krishna-laptop> Message-ID: <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: >> Aside from Steven's excellent idea, to use the getattr() technique >> with your module scheme you'd probably also need to use __import__() >> to dynamically import the right module. >> > I would generally import all the modules I would need at the top of the > main module. > then would use getattr(module,class_name) will that work? Yes, that is how you'd do it in that case. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:43:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:43:17 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Tue, 13 Jan 2009 23:06:58 +0000, Mark Wooding wrote: > I'm going to move away from the formal semantics stuff and try a > different tack. Here's what I think is the defining property of > pass-by-value (distilled from the formal approach I described earlier, > but shorn of the symbolism): > > The callee's parameters are /new variables/, initialized /as if by > assignment/ from the values of caller's argument expressions. Well, that's one way of looking at it, I guess. The problem is that when I do this: x = "something" # just an example, not necessarily a string y = x Does the line y=x create a new variable? Depends on what you mean by variable. If you mean a new name, symbol or whatever, then obviously yes. But if you mean a new value, namely the string "something", then not necessarily. In Pascal (and C?) those bytes are copied, giving two independent values which just happen to be equal. In Python, both x and y refer to the same string, and I choose the term deliberately. See, I'm not *entirely* against the use of referring to references, when appropriate. I think we just differ on when we think it's appropriate. Which I guess brings us back to your earlier assertion (I think it was you) that people aren't confused about argument passing, they're confused about assignment. [...] > But! (you claim) ... > >> Python simply can't be pass-by-value, because it doesn't behave like >> pass-by-value in other languages (particularly C and Pascal). > > Ah! (say I) but assignment in C and Pascal looks different from the way > it looks in C I'm sorry, that confuses me. Assignment in C looks different from the way it looks in C? I guess the second C should be Python. > -- and in exactly the same way that argument passing looks > different. And there, I think, I'm going to rest my case. > > I'm sorry I took so long to distill these thoughts. Thank you for > putting up with my theoretical meanderings on the way. And thank you for not kill-filing me when tempers were getting short. -- Steven From Russ.Paielli at gmail.com Wed Jan 14 03:44:05 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 00:44:05 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> Message-ID: <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> On Jan 13, 11:51?pm, Paul Rubin wrote: > Carl Banks writes: > > At GE there was no encapsulation in sight on any system I worked on. > > In fact, our engine simulation was a special-purpose object-oriented > > language with--get this--no private variables. ?Some other systems I > > worked on didn't even use scoping, let alone encapsulation. > > Where my officemate used to work, the simulation stuff was written in > Matlab, but the actual flight stuff was written in Ada. ?I wonder > if GE did something similar. I was going to suggest the same thing. An engine *simulation* is one thing; the actual engine control code is another. And the interface between the engine control code and the rest of the flight software is yet another. The FMS should be setting the throttle level, but I doubt it should be fooling around with the guts of the engine control software. From Ron.Barak at lsi.com Wed Jan 14 03:45:37 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 14 Jan 2009 08:45:37 +0000 Subject: Could you suggest optimisations ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494EC6@enbmail01.lsi.com> Hi Terry, -----Original Message----- From: Terry Reedy [mailto:tjreedy at udel.edu] Sent: Wednesday, January 14, 2009 01:57 To: python-list at python.org Subject: Re: Could you suggest optimisations ? Barak, Ron wrote: > Hi, > > In the attached script, the longest time is spent in the following > functions (verified by psyco log): I cannot help but wonder why and if you really need all the rigamorole with file pointers, offsets, and tells instead of for line in open(...): do your processing. I'm building a database of the found events in the logs (those records between the first and last regexs in regex_array). The user should then be able to navigate among these events (among other functionality). This is why I need the tells and offsets, so I'd know the place in the logs where an event starts/ends. Bye, Ron. > > def match_generator(self,regex): > """ > Generate the next line of self.input_file that > matches regex. > """ > generator_ = self.line_generator() > while True: > self.file_pointer = self.input_file.tell() > if self.file_pointer != 0: > self.file_pointer -= 1 > if (self.file_pointer + 2) >= self.last_line_offset: > break > line_ = generator_.next() > print "%.2f%% \r" % (((self.last_line_offset - > self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), > if not line_: > break > else: > match_ = regex.match(line_) > groups_ = re.findall(regex,line_) > if match_: > yield line_.strip("\n"), groups_ > > def get_matching_records_by_regex_extremes(self,regex_array): > """ > Function will: > Find the record matching the first item of regex_array. > Will save all records until the last item of regex_array. > Will save the last line. > Will remember the position of the beginning of the next line in > self.input_file. > """ > start_regex = regex_array[0] > end_regex = regex_array[len(regex_array) - 1] > > all_recs = [] > generator_ = self.match_generator > > try: > match_start,groups_ = generator_(start_regex).next() > except StopIteration: > return(None) > > if match_start != None: > all_recs.append([match_start,groups_]) > > line_ = self.line_generator().next() > while line_: > match_ = end_regex.match(line_) > groups_ = re.findall(end_regex,line_) > if match_ != None: > all_recs.append([line_,groups_]) > return(all_recs) > else: > all_recs.append([line_,[]]) > line_ = self.line_generator().next() > > def line_generator(self): > """ > Generate the next line of self.input_file, and update > self.file_pointer to the beginning of that line. > """ > while self.input_file.tell() <= self.last_line_offset: > self.file_pointer = self.input_file.tell() > line_ = self.input_file.readline() > if not line_: > break > yield line_.strip("\n") > > I was trying to think of optimisations, so I could cut down on > processing time, but got no inspiration. > (I need the "print "%.2f%% \r" ..." line for user's feedback). > > Could you suggest any optimisations ? > Thanks, > Ron. > > > P.S.: Examples of processing times are: > > * 2m42.782s on two files with combined size of 792544 bytes > (no matches found). > * 28m39.497s on two files with combined size of 4139320 bytes > (783 matches found). > > These times are quite unacceptable, as a normal input to the program > would be ten files with combined size of ~17MB. > > > ---------------------------------------------------------------------- > -- > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From sromero at gmail.com Wed Jan 14 04:02:33 2009 From: sromero at gmail.com (Santiago Romero) Date: Wed, 14 Jan 2009 01:02:33 -0800 (PST) Subject: Read binary file and dump data in References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: > If you are reading arbitrary bytes then it will likely not always "look" > like integers. What you probably meant is: > > for i in data: > ? ?print "%d, " % ord(i) That's it! :-) Thanks a lot. From castironpi at gmail.com Wed Jan 14 04:03:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 01:03:43 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Jan 13, 7:02?pm, Catherine Moroney wrote: > Hello everybody, > > I know how to spawn a sub-process and then wait until it > completes. ?I'm wondering if I can do the same thing with > a Python function. > > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. ?Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? > > I'm primarily concerned about code readability and ease of > programming. ?The code would look a lot prettier and be shorter > to boot if I could spawn off function calls rather than > subprocesses. > > Thanks for any advice, > > Catherine 'multiprocessing' does what you mentioned, as others said. The abstraction layer is solid, which makes your code pretty. However, it just creates a command line like this: '"c:\\programs\\python26\\python.exe" "-c" "from multiprocessing.forking import main; main()" "--multiprocessing-fork" "1916"' The handle '1916' is a pipe used to read further instructions. The arrive in 'main()' in the form of a pickled (serialized) dictionary. In it, the 'main_path' key contains the path to your program. 'main ()' calls the 'prepare()' function, which calls 'imp.find_module', using that path. Pretty sophisticated. You can do it yourself by creating your own command line. Create a subprocess by this command line (untested & lots of caveats): '"c:\\programs\\python26\\python.exe" "-c" "from myprogram import myfunc; myfunc()"' But you have practically no communication with it. If you need parameters, you can include them on the command line, since you're building it yourself (untested & highly vulnerable): '"c:\\programs\\python26\\python.exe" "-c" "from myprogram import myfunc; myfunc( literal1, literal2 )"' For a return value, unless it can be a simple exit code, you'll need a communication channel. For it, a socket wouldn't be bad, or a pipe if you're not on Windows (include the port or descriptor on the command line). (Even with 'multiprocessing', you're limited to pickleable objects, however, I believe.) From lilanidhaval at gmail.com Wed Jan 14 04:03:53 2009 From: lilanidhaval at gmail.com (lilanidhaval at gmail.com) Date: Wed, 14 Jan 2009 01:03:53 -0800 (PST) Subject: PYTHON HTTP POST Message-ID: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> Hi, I need one complete example of how to do a http post to any site. I have tried making a POST to google but all I am returned with is a 405 error. I don't want to use Pygoogle as I want to try and do this with other sites. I am also having problems inputing with the param I have tried Mechanize. There are no problems with getting data only posting. >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', ... 'User-Agent':'Mozilla/4.0', ... 'Content-Length':'7'} >>> conn = httplib.HTTPConnection("www.google.com") >>> conn.request("POST","/search",params,headers) >>> r2 = conn.getresponse() >>> print r2.status, r2.reason 405 Method Not Allowed Regards, Dhaval From steve at holdenweb.com Wed Jan 14 04:09:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 04:09:24 -0500 Subject: initialising a class by name In-Reply-To: <1231912018.7570.22.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. > Is this possible in python and how? > To make things clear, let me give the real example. > there is an inventory management system and products belong to different > categories. > There are predefined categories in the database and for each category > there is a module which contains a class made out of pygtk. > This means what class gets instantiated and displayed in the gui depends > on the choice a user makes in the dropdown. > Now, I could have created a list of if conditions for all the categories > as in > if categorySelection == "books": > Books = BookForm() > > However this is a problem because when there will be more than 100 > categories there will be that many if conditions and this will make the > code uggly. > so my idea is to name the class exactly after the name of the category > so that when the user selects a category that name is used to initialise > the instance of that class. > So is it possible to initialise an instance of a class given its name > from a variable? > thanks and > Happy hacking. > Krishnakant. > You don't need to have the names of the classes related to anything in the interface. Just use a list of classes, and have the user interface return the correct index for each class. Then (supposing the selection by the user is seln) use Books = classes[seln]() If the classes are all in different modules, import them before creating the list of classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Russ.Paielli at gmail.com Wed Jan 14 04:09:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 01:09:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 11:40?pm, Steven D'Aprano wrote: > But, gosh darn it, wouldn't it be nice to program the critical parts of > your code in "strict Python", and leave the rest as "trusting Python", > instead of having to use Java for the lot just to get strictness in the > critical parts? If only there was a way to do this, and ensure people > won't abuse it. Yes, that would indeed be nice. I am certainly not the only one who could use a language that is excellent for both research prototyping *and* the final, safety-critical system. Then perhaps the prototype could just be cleaned up and "hardened" for the end product rather than rewritten in another language -- by programmers in another state who may fail to understand many of the details that the prototype developer agonized over. I don't know if such a versatile language could even exist, but it would sure be valuable. Maybe it's like asking for a football player who can excel as both a wide receiver and a guard. But players who weigh 280 pounds and run a 4.4 40 are hard to find. From sjmachin at lexicon.net Wed Jan 14 04:14:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 01:14:36 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> On Jan 14, 7:31?pm, gumbah wrote: > I have this really strange problem. I hope someone can help: > > I am trying to update a database like so: > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > like '%certainvalue%' > > My Python code looks like this: > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > and fieldy like '%%%s%%' " % certainvalue call this trial 1 > print fillsql > cursor.execute(fillsql) > > #also tried: > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > null and fieldy like %s ", "%%%s%%" % certainvalue) call this trial 2 > > But it doesn't work... But when i copy and past the SQL (printed by > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! You don't say what "doesn't work" means ... did you get exceptions, or just silently not updating? > > Can anyone tell me what i am doing wrong?? Well the "trial 1" method is guaranteed not to work if certainvalue contains an apostrophe e.g. "O'Reilly". In any case, you should never build your own SQL statement like that; use the "trial 2" method -- it will do whatever is necessary in the way of reformatting or escaping your input. I know near nothing about mySQLdb, but here are some comments based on general SQL experience: (1) `tablename` isn't SQL syntax that I've seen before; perhaps it works in phpMyAdmin but not in cursor.execute() (2) similarly = NULL ... I'd expect IS NULL (3) It is updating but your script and your phpMyAdmin session are pointing at different instances of the database (4) For trial 2 method, shouldn't the 2nd arg of cursor.execute() should be a sequence e.g. ("%%%s%%" % certainvalue, ) ? HTH John From koranthala at gmail.com Wed Jan 14 04:21:58 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Wed, 14 Jan 2009 01:21:58 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> Message-ID: <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Does google accept POST? Anyways, if you dont need to post files, you can use urlencode itself. def encode_formdata(fields): body = urllib.urlencode(dict()) content_type = "application/x-www-form-urlencoded" return content_type, body If you need to post files too, then you will have to use multipart data def encode_multipart_formdata(fields, files): """ fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance """ BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append('Content-Type: %s' % mimetypes.guess_type(filename) [0] or 'application/octet-stream' L.append('') L.append(value) L.append('--' + BOUNDARY + '--') L.append('') body = CRLF.join(L) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type, body Since POST files doesnt work with urllib, you might have to use httplib - or go for very high level tools like twisted. I here show an example with httplib. def post(host, selector, fields, files): if files: content_type, body = encode_multipart_formdata(fields, files) else: content_type, body = encode_formdata(fields) h = httplib.HTTPConnection(host) #Spoof Mozilla headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', 'Content-Type': content_type } h.request('POST', selector, body, headers) res = h.getresponse() return res.status, res.reason, res.read() Please note that you can use multipart whether or not files are there, but parsing multipart usually is slower. Hope this helps. lilanidha... at gmail.com wrote: > Hi, > > I need one complete example of how to do a http post to any site. > I have tried making a POST to google but all I am returned with is a > 405 error. > I don't want to use Pygoogle as I want to try and do this with other > sites. > I am also having problems inputing with the param > I have tried Mechanize. There are no problems with getting data only > posting. > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > ... 'User-Agent':'Mozilla/4.0', > ... 'Content-Length':'7'} > >>> conn = httplib.HTTPConnection("www.google.com") > >>> conn.request("POST","/search",params,headers) > >>> r2 = conn.getresponse() > >>> print r2.status, r2.reason > 405 Method Not Allowed > > Regards, > Dhaval From mdw at distorted.org.uk Wed Jan 14 04:37:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 14 Jan 2009 09:37:28 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > Ah! (say I) but assignment in C and Pascal looks different from the way > > it looks in C > > I'm sorry, that confuses me. Assignment in C looks different from the way > it looks in C? I guess the second C should be Python. Yes, you're right. Stupid mistake on my part. -- [mdw] From mdw at distorted.org.uk Wed Jan 14 04:51:10 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 14 Jan 2009 09:51:10 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Aaron Brady wrote: > On Jan 13, 5:06 pm, Mark Wooding wrote: > snip > > I'm going to move away from the formal semantics stuff and try a > > different tack. Here's what I think is the defining property of > > pass-by-value (distilled from the formal approach I described earlier, > > but shorn of the symbolism): > > > > The callee's parameters are /new variables/, initialized /as if by > > assignment/ from the values of caller's argument expressions. > > In other words, the same as assignment in that language. It's the same as assignment of /values/ to /fresh variables/. It's important to specify that argument expressions are fully evaluated, and that nothing gets overwritten in the process. So the difference between Python and C is that C copies values during assignment, but Python doesn't. Therefore the argument passing works the same way. > > Because its argument passing works the same way as its assignment. > > That would be called pass-by-assignment. But you've just postponed > explaining yourself. Stop delegating and work. Huh? I'm really at a loss to know what you want me to do. I can't help it if people are confused over the phrase `pass-by-value', beyond trying to explain what it means using clear definitions. The `value' part means that argument expressions are /evaluated/ (turned into values), which forces applicative-order semantics rather than (say) normal-order. -- [mdw] From hackingkk at gmail.com Wed Jan 14 04:51:38 2009 From: hackingkk at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 15:21:38 +0530 Subject: initialising a class by name In-Reply-To: References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: <1231926698.7570.53.camel@krishna-laptop> On Wed, 2009-01-14 at 04:09 -0500, Steve Holden wrote: > > > You don't need to have the names of the classes related to anything in > the interface. Just use a list of classes, and have the user interface > return the correct index for each class. Then (supposing the selection > by the user is seln) use > > Books = classes[seln]() > > If the classes are all in different modules, import them before creating > the list of classes. > Is there a way to get the list of all the classes in the package? I mean is there a way to build a list of modules from some global variable which can be accessed and then looped through. happy hacking. Krishnakant. > regards > Steve From koranthala at gmail.com Wed Jan 14 04:53:10 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Wed, 14 Jan 2009 01:53:10 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Message-ID: <33c76d13-1617-4bd0-8bcf-f19950169655@v5g2000pre.googlegroups.com> On Jan 14, 2:21?pm, koranth... at gmail.com wrote: > Does google accept POST? > > Anyways, if you dont need to post files, you can use urlencode itself. > def encode_formdata(fields): > ? ? ? ? body = urllib.urlencode(dict()) > ? ? ? ? content_type = "application/x-www-form-urlencoded" > ? ? ? ? return content_type, body > > If you need to post files too, then you will have to use multipart > data > def encode_multipart_formdata(fields, files): > ? ? """ > ? ? fields is a sequence of (name, value) elements for regular form > fields. > ? ? files is a sequence of (name, filename, value) elements for data > to be uploaded as files > ? ? Return (content_type, body) ready for httplib.HTTP instance > ? ? """ > ? ? BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' > ? ? CRLF = '\r\n' > ? ? L = [] > ? ? for (key, value) in fields: > ? ? ? ? L.append('--' + BOUNDARY) > ? ? ? ? L.append('Content-Disposition: form-data; name="%s"' % key) > ? ? ? ? L.append('') > ? ? ? ? L.append(value) > ? ? for (key, filename, value) in files: > ? ? ? ? L.append('--' + BOUNDARY) > ? ? ? ? L.append('Content-Disposition: form-data; name="%s"; > filename="%s"' % (key, filename)) > ? ? ? ? L.append('Content-Type: %s' % mimetypes.guess_type(filename) > [0] or 'application/octet-stream' > ? ? ? ? L.append('') > ? ? ? ? L.append(value) > ? ? L.append('--' + BOUNDARY + '--') > ? ? L.append('') > ? ? body = CRLF.join(L) > ? ? content_type = 'multipart/form-data; boundary=%s' % BOUNDARY > ? ? return content_type, body > > Since POST files doesnt work with urllib, you might have to use > httplib - or go for very high level tools like twisted. > I here show an example with httplib. > > def post(host, selector, fields, files): > ? ? if files: > ? ? ? ?content_type, body = encode_multipart_formdata(fields, files) > ? ? else: > ? ? ? ?content_type, body = encode_formdata(fields) > > ? ? h = httplib.HTTPConnection(host) > ? ? #Spoof Mozilla > ? ? headers = { > ? ? ? ? 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; > rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', > ? ? ? ? 'Content-Type': content_type > ? ? ? ? } > ? ? h.request('POST', selector, body, headers) > ? ? res = h.getresponse() > ? ? return res.status, res.reason, res.read() > > Please note that you can use multipart whether or not files are there, > but parsing multipart usually is slower. > > Hope this helps. > > lilanidha... at gmail.com wrote: > > Hi, > > > I need one complete example of how to do a http post to any site. > > I have tried making a POST to google but all I am returned with is a > > 405 error. > > I don't want to use Pygoogle as I want to try and do this with other > > sites. > > I am also having problems inputing with the param > > I have tried Mechanize. There are no problems with getting data only > > posting. > > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > > ... ? ? ? ? 'User-Agent':'Mozilla/4.0', > > ... ? ? ? ? 'Content-Length':'7'} > > >>> conn = httplib.HTTPConnection("www.google.com") > > >>> conn.request("POST","/search",params,headers) > > >>> r2 = ?conn.getresponse() > > >>> print r2.status, r2.reason > > 405 Method Not Allowed > > > Regards, > > Dhaval > > oops - Forgot to mention that POSTing files mechanism is taken from a recipe in active state - http://code.activestate.com/recipes/146306/ From lilanidhaval at gmail.com Wed Jan 14 04:53:27 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 01:53:27 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Message-ID: The action part of the field is not set to anything. I need any site with working example that accepts POST. On Jan 14, 2:21 pm, koranth... at gmail.com wrote: > Does google accept POST? > > Anyways, if you dont need to post files, you can use urlencode itself. > def encode_formdata(fields): > body = urllib.urlencode(dict()) > content_type = "application/x-www-form-urlencoded" > return content_type, body > > If you need to post files too, then you will have to use multipart > data > def encode_multipart_formdata(fields, files): > """ > fields is a sequence of (name, value) elements for regular form > fields. > files is a sequence of (name, filename, value) elements for data > to be uploaded as files > Return (content_type, body) ready for httplib.HTTP instance > """ > BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' > CRLF = '\r\n' > L = [] > for (key, value) in fields: > L.append('--' + BOUNDARY) > L.append('Content-Disposition: form-data; name="%s"' % key) > L.append('') > L.append(value) > for (key, filename, value) in files: > L.append('--' + BOUNDARY) > L.append('Content-Disposition: form-data; name="%s"; > filename="%s"' % (key, filename)) > L.append('Content-Type: %s' % mimetypes.guess_type(filename) > [0] or 'application/octet-stream' > L.append('') > L.append(value) > L.append('--' + BOUNDARY + '--') > L.append('') > body = CRLF.join(L) > content_type = 'multipart/form-data; boundary=%s' % BOUNDARY > return content_type, body > > Since POST files doesnt work with urllib, you might have to use > httplib - or go for very high level tools like twisted. > I here show an example with httplib. > > def post(host, selector, fields, files): > if files: > content_type, body = encode_multipart_formdata(fields, files) > else: > content_type, body = encode_formdata(fields) > > h = httplib.HTTPConnection(host) > #Spoof Mozilla > headers = { > 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; > rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', > 'Content-Type': content_type > } > h.request('POST', selector, body, headers) > res = h.getresponse() > return res.status, res.reason, res.read() > > Please note that you can use multipart whether or not files are there, > but parsing multipart usually is slower. > > Hope this helps. > > lilanidha... at gmail.com wrote: > > Hi, > > > I need one complete example of how to do a http post to any site. > > I have tried making a POST to google but all I am returned with is a > > 405 error. > > I don't want to use Pygoogle as I want to try and do this with other > > sites. > > I am also having problems inputing with the param > > I have tried Mechanize. There are no problems with getting data only > > posting. > > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > > ... 'User-Agent':'Mozilla/4.0', > > ... 'Content-Length':'7'} > > >>> conn = httplib.HTTPConnection("www.google.com") > > >>> conn.request("POST","/search",params,headers) > > >>> r2 = conn.getresponse() > > >>> print r2.status, r2.reason > > 405 Method Not Allowed > > > Regards, > > Dhaval From hubaghdadi at gmail.com Wed Jan 14 04:54:11 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 01:54:11 -0800 (PST) Subject: Why this code is working? Message-ID: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Hey, Why this code is working? >>> def f1( ): ... x = 88 ... f2(x) ... >>> def f2(x): ... print x ... >>> f1( ) 88 Thanks. From pavlovevidence at gmail.com Wed Jan 14 04:54:31 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 01:54:31 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: On Jan 14, 2:44?am, "Russ P." wrote: > On Jan 13, 11:51?pm, Paul Rubin wrote: > > > Carl Banks writes: > > > At GE there was no encapsulation in sight on any system I worked on. > > > In fact, our engine simulation was a special-purpose object-oriented > > > language with--get this--no private variables. ?Some other systems I > > > worked on didn't even use scoping, let alone encapsulation. > > > Where my officemate used to work, the simulation stuff was written in > > Matlab, but the actual flight stuff was written in Ada. ?I wonder > > if GE did something similar. > > I was going to suggest the same thing. I thought you were done wasting time with this nonsense. > An engine *simulation* is one > thing; the actual engine control code is another. Guess what systems I worked on that didn't even use scoping? I wrote code for the GP7000 (equipped on some Airbus 380s) and the F-136 (which will be equipped on some F-35 fighters) engine controllers. Neither one used any data hiding. The language was C (not C++), but it was generated from schematic diagrams. Would you like to adopt GE's practice of schematic-generated C with no namespaces or data hiding? No? Then don't be telling me I have to embrace Boeing's. Carl Banks From krmane at gmail.com Wed Jan 14 04:55:27 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 15:25:27 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> <1231922209.7570.49.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> Message-ID: <1231926927.7570.55.camel@krishna-laptop> On Wed, 2009-01-14 at 00:39 -0800, Chris Rebert wrote: > On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > >> Aside from Steven's excellent idea, to use the getattr() technique > >> with your module scheme you'd probably also need to use __import__() > >> to dynamically import the right module. > >> > > I would generally import all the modules I would need at the top of the > > main module. > > then would use getattr(module,class_name) will that work? > > Yes, that is how you'd do it in that case. > By the way, is there a kind of global list of modules/classes which are maintained in a package once the program is loaded into memory? happy hacking. Krishnakant. > Cheers, > Chris > -- > Follow the path of the Iguana... > http://rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 04:55:47 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 10:55:47 +0100 Subject: Why this code is working? In-Reply-To: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Message-ID: <496db69d$0$20355$426a34cc@news.free.fr> Hussein B a ?crit : > Hey, > Why this code is working? > >>>> def f1( ): > ... x = 88 > ... f2(x) > ... >>>> def f2(x): > ... print x > ... >>>> f1( ) > 88 > Well... Because it is correct ? What make you think it _shouldn't_ work ? From joost.ruyter at gmail.com Wed Jan 14 04:55:58 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 01:55:58 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> Message-ID: <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Hi John, thanks a lot for your quick reply! I tried all of your suggestions but none of them work... I have a clue on why it is failing: MySQLdb seems to quote the % characters or something... Even when i do: cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is null and fieldy like '%therealvalue%' " or: cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is null and fieldy like '%%therealvalue%%' " # escaping the % it is not updating the database... Maybe I am completely overlooking something, but I am pretty lost here... Googling this it seems as if no one is using "LIKE '%value%'" type queries with Python & mySQL... Anyone any other thoughts? regards, Joost On 14 jan, 10:14, John Machin wrote: > On Jan 14, 7:31 pm, gumbah wrote: > > > I have this really strange problem. I hope someone can help: > > > I am trying to update a database like so: > > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > > like '%certainvalue%' > > > My Python code looks like this: > > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > > and fieldy like '%%%s%%' " % certainvalue > > call this trial 1 > > > print fillsql > > cursor.execute(fillsql) > > > #also tried: > > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > > null and fieldy like %s ", "%%%s%%" % certainvalue) > > call this trial 2 > > > > > But it doesn't work... But when i copy and past the SQL (printed by > > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! > > You don't say what "doesn't work" means ... did you get exceptions, or > just silently not updating? > > > > > Can anyone tell me what i am doing wrong?? > > Well the "trial 1" method is guaranteed not to work if certainvalue > contains an apostrophe e.g. "O'Reilly". In any case, you should never > build your own SQL statement like that; use the "trial 2" method -- it > will do whatever is necessary in the way of reformatting or escaping > your input. > > I know near nothing about mySQLdb, but here are some comments based on > general SQL experience: > (1) `tablename` isn't SQL syntax that I've seen before; perhaps it > works in phpMyAdmin but not in cursor.execute() > (2) similarly = NULL ... I'd expect IS NULL > (3) It is updating but your script and your phpMyAdmin session are > pointing at different instances of the database > (4) For trial 2 method, shouldn't the 2nd arg of cursor.execute() > should be a sequence e.g. ("%%%s%%" % certainvalue, ) ? > > HTH > John From hubaghdadi at gmail.com Wed Jan 14 04:57:48 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 01:57:48 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> Message-ID: <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> On Jan 14, 11:55?am, Bruno Desthuilliers wrote: > Hussein B a ?crit : > > > Hey, > > Why this code is working? > > >>>> def f1( ): > > ... ? ? ?x = 88 > > ... ? ? ?f2(x) > > ... > >>>> def f2(x): > > ... ? ? ?print x > > ... > >>>> f1( ) > > 88 > > Well... Because it is correct ? > > What make you think it _shouldn't_ work ? Because def2 is defined after def1 in an interpreted language, not compiled. From __peter__ at web.de Wed Jan 14 04:59:31 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jan 2009 10:59:31 +0100 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Message-ID: Hussein B wrote: > Why this code is working? > >>>> def f1( ): > ... x = 88 > ... f2(x) > ... >>>> def f2(x): > ... print x > ... >>>> f1( ) > 88 The name 'f2' is not resolved once when the f1 function is created. Instead Python looks for a global name 'f2' each time f1 is executed. Peter From __peter__ at web.de Wed Jan 14 05:06:26 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jan 2009 11:06:26 +0100 Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: gumbah wrote: > I tried all of your suggestions but none of them work... I have a clue > on why it is failing: MySQLdb seems to quote the % characters or > something... > > Even when i do: > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > null and fieldy like '%therealvalue%' " > it is not updating the database... > > Maybe I am completely overlooking something, but I am pretty lost > here... Googling this it seems as if no one is using "LIKE '%value%'" > type queries with Python & mySQL... > > Anyone any other thoughts? Did you call the connection object's commit() method? Peter From joost.ruyter at gmail.com Wed Jan 14 05:14:09 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 02:14:09 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> Yep, also tried that. Weird thing is that I get no errors, it's just silently not updating... On 14 jan, 11:06, Peter Otten <__pete... at web.de> wrote: > gumbah wrote: > > I tried all of your suggestions but none of them work... I have a clue > > on why it is failing: MySQLdb seems to quote the % characters or > > something... > > > Even when i do: > > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > > null and fieldy like '%therealvalue%' " > > it is not updating the database... > > > Maybe I am completely overlooking something, but I am pretty lost > > here... Googling this it seems as if no one is using "LIKE '%value%'" > > type queries with Python & mySQL... > > > Anyone any other thoughts? > > Did you call the connection object's commit() method? > > Peter From staaleu at gmail.com Wed Jan 14 05:20:50 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 02:20:50 -0800 (PST) Subject: Parent module not loaded error Message-ID: I have a pretty strange error that I can't figure out the cause off. This is in a Django app. I am using berkelydb, with secondary databases for indexing. The secondary databases are associated with a callback that uses cPickle to serialize index values. The problem is that cPickle.dumps(value) fails when I run it through mod_wsgi or mod_python on the deployment server (Ubuntu Linux 8.10), but works fine when when I use Djangos runserver on the same computer. Also, on my own computer (Ubuntu Linux 8.10), it works fine through mod_python. Each time I call on cPickle.dumps(value) I get: SystemError("Parent module 'd4' not loaded",) Using sys.exc_info() I get no type or traceback, just that exception. The callstack as far as I can figure is: django view bsddb.put indexer callback cPickle.dumps cPickle.loads works fine within the callback, I can also use cPickle.dumps() outside the indexer callback. But inside the callback, I need to use normal pickle instead. I just want to know why. I am assuming it has something to do with the fact that I go from python to C (bsddb) back to python (indexer callback) and back to C (cPickle). It is still strange then that cPickle.loads() work, but not cPickle.dumps(). I am also only storing integer values when I get this error, so no fancy list, dictionaries or objects. From joost.ruyter at gmail.com Wed Jan 14 05:22:42 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 02:22:42 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> Message-ID: <1716d5bb-d0bc-40e6-95da-5041af8fc064@g1g2000pra.googlegroups.com> Aahh the conn.commit() DID the trick!! I tried that before, but then it failed at another point. I got it working now! Thanks a lot Peter and John!! cheers! On 14 jan, 11:14, gumbah wrote: > Yep, also tried that. Weird thing is that I get no errors, it's just > silently not updating... > > On 14 jan, 11:06, Peter Otten <__pete... at web.de> wrote: > > > gumbah wrote: > > > I tried all of your suggestions but none of them work... I have a clue > > > on why it is failing: MySQLdb seems to quote the % characters or > > > something... > > > > Even when i do: > > > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > > > null and fieldy like '%therealvalue%' " > > > it is not updating the database... > > > > Maybe I am completely overlooking something, but I am pretty lost > > > here... Googling this it seems as if no one is using "LIKE '%value%'" > > > type queries with Python & mySQL... > > > > Anyone any other thoughts? > > > Did you call the connection object's commit() method? > > > Peter From davide.picca at gmail.com Wed Jan 14 05:25:52 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 02:25:52 -0800 (PST) Subject: os system command not found Message-ID: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Hi all! I installed a external program called infomap using the classical procedure ./configure make sudo make install and it works perfectly in Terminal (Os x) using both bash and tcsh shell admins-macbook-pro-2:~ unil$ infomap-build Usage: infomap-build [-w working_dir] [-p param_file] [-D var_1=val_1 ... -D var_N=val_N] (-s single_corpus_file | -m multi_file_list) but when I call it from python using os.system or subprocess.call I get the message "sh: infomap-build: command not found". Do you know why? Many thanks Davide From w.richert at gmx.net Wed Jan 14 05:26:39 2009 From: w.richert at gmx.net (Willi Richert) Date: Wed, 14 Jan 2009 11:26:39 +0100 Subject: initialising a class by name In-Reply-To: <1231926927.7570.55.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> <1231926927.7570.55.camel@krishna-laptop> Message-ID: <200901141126.39366.w.richert@gmx.net> Hi, try the following exemplarily for the os module import os, types [(c, klass) for (c,klass) in os.__dict__.items() if type(klass)==types.ClassType] will print: [('_Environ', )] Regards, wr Am Mittwoch, 14. Januar 2009 10:55:27 schrieb Krishnakant: > On Wed, 2009-01-14 at 00:39 -0800, Chris Rebert wrote: > > On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > > > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > > >> Aside from Steven's excellent idea, to use the getattr() technique > > >> with your module scheme you'd probably also need to use __import__() > > >> to dynamically import the right module. > > > > > > I would generally import all the modules I would need at the top of the > > > main module. > > > then would use getattr(module,class_name) will that work? > > > > Yes, that is how you'd do it in that case. > > By the way, is there a kind of global list of modules/classes which are > maintained in a package once the program is loaded into memory? > happy hacking. > Krishnakant. > > > Cheers, > > Chris > > -- > > Follow the path of the Iguana... > > http://rebertia.com > > -- > http://mail.python.org/mailman/listinfo/python-list From Graham.Dumpleton at gmail.com Wed Jan 14 05:31:59 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 14 Jan 2009 02:31:59 -0800 (PST) Subject: Parent module not loaded error References: Message-ID: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> On Jan 14, 9:20?pm, St?le Undheim wrote: > I have a pretty strange error that I can't figure out the cause off. > This is in a Django app. > > I am using berkelydb, with secondary databases for indexing. The > secondary databases are associated with a callback that uses cPickle > to serialize index values. The problem is that cPickle.dumps(value) > fails when I run it throughmod_wsgior mod_python on the deployment > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > runserver on the same computer. Also, on my own computer (Ubuntu Linux > 8.10), it works fine through mod_python. > > Each time I call on cPickle.dumps(value) I get: > SystemError("Parent module 'd4' not loaded",) > > Using sys.exc_info() I get no type or traceback, just that exception. > The callstack as far as I can figure is: > > django > view > bsddb.put > indexer callback > cPickle.dumps > > cPickle.loads works fine within the callback, I can also use > cPickle.dumps() outside the indexer callback. But inside the callback, > I need to use normal pickle instead. I just want to know why. I am > assuming it has something to do with the fact that I go from python to > C (bsddb) back to python (indexer callback) and back to C (cPickle). > It is still strange then that cPickle.loads() work, but not > cPickle.dumps(). I am also only storing integer values when I get this > error, so no fancy list, dictionaries or objects. Where is module 'd4'? Is that one of yours defined inside of your Django project? One of the problems with Django runserver is that the parent of the site directory and the site directory are effectively starting points for searching for modules, even though neither is explicitly listed in sys.path. The parent is used because runserver does momentarily add parent to sys.path to import site package root, after which it removes directory from sys.path. The site directory itself is used because for runserver that is the current working directory and imports look there automatically. End result is that modules inside of site can be imported either via site package root, or direct. For example, if d4.py was at same level as settings.py file and site was called mysite, you could import it as mysite.d4 or just d4. This is bad because means you could end up with two copies of a module imported under the different name references. If they way the pickle was done in application was such that reference was via d4, and then when you deployed to mod_python or mod_wsgi you only added parent directory of site to Python path, then it will not be able to find d4, since at that point would only be found as mysite.d4. If this is the case, add the site directory to Python path by setting PythonPath for mod_python or sys.path in WSGI script file for mod_wsgi. Better still, fix up your code so module references in code, ie., urls.py, or anywhere else, are always done by site package root reference and not direct. Ie., such that it uses mysite.d4 and not just d4. Would that seem about right? Graham From db3l.net at gmail.com Wed Jan 14 05:34:48 2009 From: db3l.net at gmail.com (David Bolen) Date: Wed, 14 Jan 2009 05:34:48 -0500 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Johannes Bauer writes: > Yup, I changed the Python code to behave the same way the C code did - > however overall it's not much of an improvement: Takes about 15 minutes > to execute (still factor 23). Not sure this is completely fair if you're only looking for a pure Python solution, but to be honest, looping through a gazillion individual bytes of information sort of begs for trying to offload that into a library that can execute faster, while maintaining the convenience of Python outside of the pure number crunching. I'd assume numeric/numpy might have applicable functions, but I don't use those libraries much, whereas I've been using OpenCV recently for a lot of image processing work, and it has matrix/histogram support, which seems to be a good match for your needs. For example, assuming the OpenCV library and ctypes-opencv wrapper, add the following before the file I/O loop: from opencv import * # Histogram for each file chunk hist = cvCreateHist([256], CV_HIST_ARRAY, [(0,256)]) then, replace (using one of your posted methods as a sample): datamap = { } for i in data: datamap[i] = datamap.get(i, 0) + 1 array = sorted([(b, a) for (a, b) in datamap.items()], reverse=True) most = ord(array[0][1]) with: matrix = cvMat(1, len(data), CV_8UC1, data) cvCalcHist([matrix], hist) most = cvGetMinMaxHistValue(hist, min_val = False, max_val = False, min_idx = False, max_idx = True) should give you your results in a fraction of the time. I didn't run with a full size data file, but for a smaller one using smaller chunks the OpenCV varient ran in about 1/10 of the time, and that was while leaving all the other remaining Python code in place. Note that it may not be identical results to some of your other methods in the case of multiple values with the same counts, as the OpenCV histogram min/max call will always pick the lower value in such cases, whereas some of your code (such as above) will pick the upper value, or your original code depended on the order of information returned by dict.items. This sort of small dedicated high performance choke point is probably also perfect for something like Pyrex/Cython, although that would require a compiler to build the extension for the histogram code. -- David From staaleu at gmail.com Wed Jan 14 05:41:30 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 02:41:30 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> Message-ID: On Jan 14, 11:31?am, Graham Dumpleton wrote: > On Jan 14, 9:20?pm, St?le Undheim wrote: > > > > > I have a pretty strange error that I can't figure out the cause off. > > This is in a Django app. > > > I am using berkelydb, with secondary databases for indexing. The > > secondary databases are associated with a callback that uses cPickle > > to serialize index values. The problem is that cPickle.dumps(value) > > fails when I run it throughmod_wsgior mod_python on the deployment > > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > > runserver on the same computer. Also, on my own computer (Ubuntu Linux > > 8.10), it works fine through mod_python. > > > Each time I call on cPickle.dumps(value) I get: > > SystemError("Parent module 'd4' not loaded",) > > > Using sys.exc_info() I get no type or traceback, just that exception. > > The callstack as far as I can figure is: > > > django > > view > > bsddb.put > > indexer callback > > cPickle.dumps > > > cPickle.loads works fine within the callback, I can also use > > cPickle.dumps() outside the indexer callback. But inside the callback, > > I need to use normal pickle instead. I just want to know why. I am > > assuming it has something to do with the fact that I go from python to > > C (bsddb) back to python (indexer callback) and back to C (cPickle). > > It is still strange then that cPickle.loads() work, but not > > cPickle.dumps(). I am also only storing integer values when I get this > > error, so no fancy list, dictionaries or objects. > > Where is module 'd4'? Is that one of yours defined inside of your > Django project? > d4 is the root project name. This message occurs in d4/views.py. Here is how I set up my wsgi.py - which is in the d4/ folder: sys.path.append(path.join(path.dirname(__file__), '..')) os.environ['DJANGO_SETTINGS_MODULE'] = 'd4.settings' application = django.core.handlers.wsgi.WSGIHandler() > One of the problems with Django runserver is that the parent of the > site directory and the site directory are effectively starting points > for searching for modules, even though neither is explicitly listed in > sys.path. The parent is used because runserver does momentarily add > parent to sys.path to import site package root, after which it removes > directory from sys.path. The site directory itself is used because for > runserver that is the current working directory and imports look there > automatically. > > End result is that modules inside of site can be imported either via > site package root, or direct. For example, if d4.py was at same level > as settings.py file and site was called mysite, you could import it as > mysite.d4 or just d4. This is bad because means you could end up with > two copies of a module imported under the different name references. Everywhere in the code, the imports refer to d4.something.something. All urls.py files refer to the full package names. The test code where I am running this is actually quit minimal. > If they way the pickle was done in application was such that reference > was via d4, and then when you deployed to mod_python or mod_wsgi you > only added parent directory of site to Python path, then it will not > be able to find d4, since at that point would only be found as > mysite.d4. > I use "import cPickle as pickle" at the top off my views file. So I don't reference imports from other files. > If this is the case, add the site directory to Python path by setting > PythonPath for mod_python or sys.path in WSGI script file for > mod_wsgi. Better still, fix up your code so module references in code, > ie., urls.py, or anywhere else, are always done by site package root > reference and not direct. Ie., such that it uses mysite.d4 and not > just d4. > > Would that seem about right? Unfortunatly, at least to me, it seems that all code is allready correctly using packagenames. The views.py file where I am testing this is a simple file that doesn't depend on anything else in the project. It only imports a set of system modules for testing and info. The only "dependency" is really the urls.py file, which does refer to all the views as "d4.views.somemethod". From steve at holdenweb.com Wed Jan 14 05:42:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 05:42:09 -0500 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <496DC181.7090601@holdenweb.com> gumbah wrote: > I have this really strange problem. I hope someone can help: > > I am trying to update a database like so: > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > like '%certainvalue%' > > My Python code looks like this: > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > and fieldy like '%%%s%%' " % certainvalue > print fillsql > cursor.execute(fillsql) > > #also tried: > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > null and fieldy like %s ", "%%%s%%" % certainvalue) > > But it doesn't work... But when i copy and past the SQL (printed by > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! > > Can anyone tell me what i am doing wrong?? > 1. You can't test for equality with NULL. 2. You don't have quote marks around the LIKE argument. cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx IS NULL and fieldy like '%s' ", "%%%s%%" % certainvalue) *might* work. 3. I can't be certain my experience with PostgreSQL extends to MySQl, but I have done experiments which prove to my satisfaction that it isn't possible to parameterize LIKE arguments. So the only way to do it appears to be to build the query yourself. This means that you will need to make sure the string is made "safe", typically by replacing each occurrence of the string "'" with "''" to retain the syntactic integrity of the SQL statement. So finally, try cursor.execute("""UPDATE tablename set fieldx='test' WHERE flfieldx IS NULL AND fieldy LIKE '%%%s%%'""" % certainvalue.replace("'", "''")) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From divinekid at gmail.com Wed Jan 14 05:43:12 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Wed, 14 Jan 2009 18:43:12 +0800 Subject: [ANN] SWIG 1.3.37 Message-ID: <1d7983e80901140243n4a2d9edcme8846092d7144a9d@mail.gmail.com> This is the SWIG with Python 3.0 support! :) *** ANNOUNCE: SWIG 1.3.37 (13 January 2009) *** http://www.swig.org We're pleased to announce SWIG-1.3.37, the latest installment in the SWIG development effort. SWIG-1.3.37 includes a number of bug fixes and enhancements. What is SWIG? ------------- SWIG is a software development tool that reads C/C++ header files and generates the wrapper code needed to make C and C++ code accessible from other languages including Perl, Python, Tcl, Ruby, PHP, Java, Scheme (Guile, MzScheme, CHICKEN), Ocaml, Lua, Pike, C#, Modula-3, Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI). SWIG can also export its parse tree in the form of XML and Lisp s-expressions. Major applications of SWIG include generation of scripting language extension modules, rapid prototyping, testing, and user interface development for large C/C++ systems. Availability: ------------- The release is available for download on Sourceforge at http://prdownloads.sourceforge.net/swig/swig-1.3.37.tar.gz A Windows version is also available at http://prdownloads.sourceforge.net/swig/swigwin-1.3.37.zip What's New? =========== SWIG-1.3.37 summary: - Python 3 support added - SWIG now ships with a version of ccache that can be used with SWIG. This enables the files generated by SWIG to be cached so that repeated use of SWIG on unchanged input files speeds up builds quite considerably. - PHP 4 support removed and PHP support improved in general - Improved C# array support - Numerous Allegro CL improvements - Bug fixes/enhancements for Python, PHP, Java, C#, Chicken, Allegro CL, CFFI, Ruby, Tcl, Perl, R, Lua. - Other minor generic bug fixes and enhancements Release numbers --------------- With SWIG-1.3, we are adopting an odd/even version numbering scheme for SWIG. Odd version numbers (1.3, 1.5, 1.7, etc...) are considered to be development releases. Even numbers (1.4,1.6,1.8) are stable releases. The current 1.3 effort is working to produce a stable 2.0 release. A stable 2.0 release will not be made until it can accompanied by fully updated documentation. In the meantime, we will continue to make periodic 1.3.x releases. Please report problems with this release to the swig-dev mailing list, details at http://www.swig.org/mail.html. --- The SWIG Developers From Graham.Dumpleton at gmail.com Wed Jan 14 05:48:37 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 14 Jan 2009 02:48:37 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> Message-ID: <9d4373c9-2cab-4eee-a2ad-dfd4398abe40@z28g2000prd.googlegroups.com> On Jan 14, 9:41?pm, St?le Undheim wrote: > On Jan 14, 11:31?am, Graham Dumpleton > wrote: > > > > > On Jan 14, 9:20?pm, St?le Undheim wrote: > > > > I have a pretty strange error that I can't figure out the cause off. > > > This is in a Django app. > > > > I am using berkelydb, with secondary databases for indexing. The > > > secondary databases are associated with a callback that uses cPickle > > > to serialize index values. The problem is that cPickle.dumps(value) > > > fails when I run it throughmod_wsgior mod_python on the deployment > > > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > > > runserver on the same computer. Also, on my own computer (Ubuntu Linux > > > 8.10), it works fine through mod_python. > > > > Each time I call on cPickle.dumps(value) I get: > > > SystemError("Parent module 'd4' not loaded",) > > > > Using sys.exc_info() I get no type or traceback, just that exception. > > > The callstack as far as I can figure is: > > > > django > > > view > > > bsddb.put > > > indexer callback > > > cPickle.dumps > > > > cPickle.loads works fine within the callback, I can also use > > > cPickle.dumps() outside the indexer callback. But inside the callback, > > > I need to use normal pickle instead. I just want to know why. I am > > > assuming it has something to do with the fact that I go from python to > > > C (bsddb) back to python (indexer callback) and back to C (cPickle). > > > It is still strange then that cPickle.loads() work, but not > > > cPickle.dumps(). I am also only storing integer values when I get this > > > error, so no fancy list, dictionaries or objects. > > > Where is module 'd4'? Is that one of yours defined inside of your > > Django project? > > d4 is the root project name. This message occurs in d4/views.py. > > Here is how I set up my wsgi.py - which is in the d4/ folder: > ? sys.path.append(path.join(path.dirname(__file__), '..')) > > ? os.environ['DJANGO_SETTINGS_MODULE'] = 'd4.settings' > ? application = django.core.handlers.wsgi.WSGIHandler() > > > One of the problems with Django runserver is that the parent of the > > site directory and the site directory are effectively starting points > > for searching for modules, even though neither is explicitly listed in > > sys.path. The parent is used because runserver does momentarily add > > parent to sys.path to import site package root, after which it removes > > directory from sys.path. The site directory itself is used because for > > runserver that is the current working directory and imports look there > > automatically. > > > End result is that modules inside of site can be imported either via > > site package root, or direct. For example, if d4.py was at same level > > as settings.py file and site was called mysite, you could import it as > > mysite.d4 or just d4. This is bad because means you could end up with > > two copies of a module imported under the different name references. > > Everywhere in the code, the imports refer to d4.something.something. > All urls.py files refer to the full package names. The test code where > I am running this is actually quit minimal. > > > If they way the pickle was done in application was such that reference > > was via d4, and then when you deployed to mod_python or mod_wsgi you > > only added parent directory of site to Python path, then it will not > > be able to find d4, since at that point would only be found as > > mysite.d4. > > I use "import cPickle as pickle" at the top off my views file. So I > don't reference imports from other files. > > > If this is the case, add the site directory to Python path by setting > > PythonPath for mod_python or sys.path in WSGI script file for > > mod_wsgi. Better still, fix up your code so module references in code, > > ie., urls.py, or anywhere else, are always done by site package root > > reference and not direct. Ie., such that it uses mysite.d4 and not > > just d4. > > > Would that seem about right? > > Unfortunatly, at least to me, it seems that all code is allready > correctly using packagenames. The views.py file where I am testing > this is a simple file that doesn't depend on anything else in the > project. It only imports a set of system modules for testing and info. > The only "dependency" is really the urls.py file, which does refer to > all the views as "d4.views.somemethod". As a test, just prior to where unpickle is done, do: import sys import d4 print >> sys.stderr, "d4.__name__", dr.__name__ print >> sys.stderr, "d4.__file__", dr.__file__ This will just confirm that manual import works and what values of those attributes are. The messages will end up in Apache error log for that virtual host or main server error log as appropriate. Graham From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 05:49:51 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 11:49:51 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> Message-ID: <496dc349$0$21349$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > I think the issue here is the distinction between hacking and software > engineering. I may be misusing the term "hacking," but I do not mean > it in a pejoritive sense. I just mean getting things done fast without > a lot of concern for safety, security, and long-term maintainability > and scalability. I do feel concerned by these issues. > I'm not a computer scientist, but it seems to me that > Python is great for hacking and good for software engineering, but it > is not ideal for software engineering. > > What Paul is suggesting, I think, is that Python should move in the > direction of software engineering. Whether that can be done without > compromising its hacking versatility is certainly a valid question, > but if it can be done, then why not do it? > > Certainly one basic principle of software engineering is data > encapsulation. Tacking new attributes onto class instances all over > the place There's a clear distinction between "making wise use of dynamicity" and "tacking new attributes onto class instances all over the place". > may be convenient and useful in many cases, but it is not > consistent with good software engineering. simplicity is "good software engineering". Accidental complexity is not. Dynamism _can_ greatly reduce accidental complexity. > If the programmer could > somehow disallow it in certain classes, Already possible - you just have to provide your own implementation of __setattr__. > that could be useful, > providing that those who wish to continue doing it would be free to do > so. If class attributes could somehow be declared private, The important point is to make implementation distinct from interface - which we already know how to do -, and sometimes to prevent _accidental_ overriding of some critical implementation attributes - which is also already implemented. Enforcing access restriction is, from experience, just pointless. """ patient : doctor, when I do this, it hurts doctor : well, don't do it, then. """ From kylotan at gmail.com Wed Jan 14 05:49:57 2009 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 14 Jan 2009 02:49:57 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: On Jan 14, 1:55?am, Ivan Illarionov wrote: > Ben Sizer wrote: > > What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: No, I don't want to do anything with sys.path apart from see it. I just wanted my original question answered, not a guess at my intent and a solution for something I'm not doing. ;) Thanks though! Again - why can I not reference sys from within the function? -- Ben Sizer From bj_666 at gmx.net Wed Jan 14 05:53:33 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 14 Jan 2009 10:53:33 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <6t5uhcF9bu1hU1@mid.uni-berlin.de> On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > >> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. >> wrote: (...) >> >>>> Give me one use-case where you strictly require that members of an >>>> object be private and their access enforced as such ? >>> >>> You're kidding, right? Think about a ten-million line program being >>> developed by 100 developers. >> >> No I"m sorry this is not a valid use-case. > > Why not? Just saying it isn't doesn't make it not. Because "developer" means people who don't mess with implementation details. So they respect the leading underscore convention. No use case for enforced access restriction. Ciao, Marc 'BlackJack' Rintsch From pieterprovoost at gmail.com Wed Jan 14 05:54:21 2009 From: pieterprovoost at gmail.com (pieterprovoost at gmail.com) Date: Wed, 14 Jan 2009 05:54:21 -0500 Subject: problem calling method In-Reply-To: Message-ID: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> The parent is called like this (I didn't copy that line): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) The frame works fine and so does the button, but somehow I cannot call the sendmail method from the event handler... -- James Mills wrote : On Wed, Jan 14, 2009 at 11:28 AM, wrote: > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): It might be helpful here if you called the parent __init__. Like so: class MyFrame(wx.Frame): def __init__(self, *args, **kwds): super(MyFrame, self).__init__(*args, **kwargs) ... cheers James -- -- This message was sent on behalf of pieterprovoost at gmail.com at openSubscriber.com http://www.opensubscriber.com/message/python-list at python.org/11236393.html From sjmachin at lexicon.net Wed Jan 14 05:58:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 02:58:10 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: <6509268d-81c4-479d-869b-264734694a20@s1g2000prg.googlegroups.com> On Jan 14, 8:55?pm, gumbah wrote: > Hi John, > > thanks a lot for your quick reply! Please don't top-post. Please answer the question """You don't say what "doesn't work" means ... did you get exceptions, or just silently not updating?""" > > I tried all of your suggestions but none of them work... I have a clue > on why it is failing: MySQLdb seems to quote the % characters or > something... > > Even when i do: > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > null and fieldy like '%therealvalue%' " Please stop stuffing around with the 'trial 1' method. What SQL data type is fieldy? What Python datatype is therealvalue coming from? Do this: print type(realvalue), repr(realvalue) Are you sure that the datatypes are compatible? Is there perhaps a Unicode encoding problem? Try this: cursor.execute("select fieldy from tablename") # dig out a sample result print type(sample_result), repr(sample_result) print therealvalue in sample_result I suggest that you avoid UPDATE and the supersensitive fieldy none of whose values you can reveal, and try the code on a column with simple noncontroversial data e.g. if you have an address table with the U.S. state code in it, we can try a simple query to find all addresses that are in a state that contains some letter: state_letter = "A" sql = "select address_id, state from address where state like %s" cursor.execute(sql, ("%" + state_letter + "%", )) That would be my best shot at getting it to work. It is based on this: http://mail.python.org/pipermail/python-list/2003-August/218382.html If that works, try applying it to a query on fieldy and then to your original problem. Cheers, John From sturlamolden at yahoo.no Wed Jan 14 05:59:22 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 02:59:22 -0800 (PST) Subject: Standard IPC for Python? References: Message-ID: On Jan 13, 5:25 pm, Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: "Slow > network"). There are plenty of different IPC mechanisms available in multiprocessing. > I was looking for semaphores and shared memory, but it is not in the > standard lib. Take a look at: - multiprocessing.Array and multiprocessing.Value - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, respectively) - pywin32 on Windows (not standard lib) > I was also thinking about unix domain sockets, but it is > not available under windows. Unix domain sockets are called 'named pipes' under Windows. Look for it in multiprocessing or pywin32. > The question is: what is the standard way to implement fast and portable > IPC with Python? form multiprocessing import Queue From sjmachin at lexicon.net Wed Jan 14 06:08:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 03:08:30 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> <1716d5bb-d0bc-40e6-95da-5041af8fc064@g1g2000pra.googlegroups.com> Message-ID: On Jan 14, 9:22?pm, gumbah wrote: > Aahh the conn.commit() DID the trick!! > > I tried that before, but then it failed at another point. I got it > working now! Thanks a lot Peter and John!! For the benefit of future searchers, can you please tell us which varieties of cursor.execute() it works on -- copy/paste the code that was run, please, rather than some possibly vague/ambiguous narrative :-) and do please try it using a parameterised method ("trial 2"), because that's much more prefereable to build-your-own SQL ("trial 1") if both work. Cheers, John From lilanidhaval at gmail.com Wed Jan 14 06:11:06 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 03:11:06 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED Message-ID: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Hi, Can someone please give me an example of a working python post? for example using the site http://www.cookiemag.com/ Thanks in advance, Dhaval From lilanidhaval at gmail.com Wed Jan 14 06:19:12 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 03:19:12 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Message-ID: On Jan 14, 4:11 pm, dhaval wrote: > Hi, > > Can someone please give me an example of a working python post? > for example using the sitehttp://www.cookiemag.com/ > > Thanks in advance, > Dhaval I have tried to look at the code at http://code.activestate.com/recipes/146306/ I can't make any sense out of it. From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 06:20:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 11:20:56 GMT Subject: sys.stdout.write()'s bug or doc bug? References: Message-ID: <017dc12e$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 19:38:48 -0800, Aahz wrote: > In article > , > Qiangning Hong wrote: >> >>So, my question is, as sys.stdout IS a file object, why it does not use >>its encoding attribute to convert the given unicode? An implementation >>bug? A documenation bug? > > Please file a bug on bugs.python.org -- that's the only way this can be > tracked. Done: http://bugs.python.org/issue4947 -- Steven From tjreedy at udel.edu Wed Jan 14 06:29:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Jan 2009 06:29:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. The question is where such checks should be. Guido prefers separate checkers (PyChecker, PyLint) rather than in the interpreter. If you think they are incomplete, help improve one of them. From deets at nospam.web.de Wed Jan 14 06:33:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 12:33:10 +0100 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Message-ID: <6t60rmF9auodU1@mid.uni-berlin.de> dhaval wrote: > On Jan 14, 4:11 pm, dhaval wrote: >> Hi, >> >> Can someone please give me an example of a working python post? >> for example using the sitehttp://www.cookiemag.com/ >> >> Thanks in advance, >> Dhaval > > I have tried to look at the code at > http://code.activestate.com/recipes/146306/ > I can't make any sense out of it. - don't SHOUT. - don't open up new threads 2 hours after you asked the first time with the *same* question. - show code of your actual efforts. This is not the "free code snippets producing system." - read this: http://www.catb.org/~esr/faqs/smart-questions.html Diez From staaleu at gmail.com Wed Jan 14 06:39:21 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 03:39:21 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> <9d4373c9-2cab-4eee-a2ad-dfd4398abe40@z28g2000prd.googlegroups.com> Message-ID: <2029f394-4a61-4ad1-b826-b75c878fdc2b@w39g2000prb.googlegroups.com> On Jan 14, 11:48?am, Graham Dumpleton wrote: > As a test, just prior to where unpickle is done, do: > > ? import sys > ? import d4 > > ? print >> sys.stderr, "d4.__name__", dr.__name__ > ? print >> sys.stderr, "d4.__file__", dr.__file__ > > This will just confirm that manual import works and what values of > those attributes are. The messages will end up in Apache error log for > that virtual host or main server error log as appropriate. d4.__name__ d4 d4.__file__ /home/petromarker/django-apps/d4/src/d4/../d4/__init__.pyc It's the same both before and after the exception. From gandalf at shopzeus.com Wed Jan 14 06:47:07 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 14 Jan 2009 12:47:07 +0100 Subject: Standard IPC for Python? In-Reply-To: References: Message-ID: <496DD0BB.6090203@shopzeus.com> > There are plenty of different IPC mechanisms available in > multiprocessing. > It is good for a special case: a tree of processes, forked from a main process. multiprocessing.Queue cannot be used as a general message queue between arbitrary processes. > - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, > respectively) > Which lacks synchronization between processes. (How do you notify the other process? How can the other process wait until notified?) From sjmachin at lexicon.net Wed Jan 14 07:01:14 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 04:01:14 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> On Jan 14, 9:42?pm, Steve Holden wrote: > 3. I can't be certain my experience with PostgreSQL extends to MySQl, > but I have done experiments which prove to my satisfaction that it isn't > possible to parameterize LIKE arguments. So the only way to do it > appears to be to build the query yourself. This means that you will need > to make sure the string is made "safe", typically by replacing each > occurrence of the string "'" with "''" to retain the syntactic integrity > of the SQL statement. So finally, try > > cursor.execute("""UPDATE tablename set fieldx='test' > ? ? ? ? ? ? ? ? ? WHERE flfieldx IS NULL > ? ? ? ? ? ? ? ? ? AND fieldy LIKE '%%%s%%'""" % > ? ? ? ? ? ? ? ? ? certainvalue.replace("'", "''")) It appears possible to parameterise LIKE arguments in sqlite3: 8<--- code import sqlite3 tests = [ ["select * from foo", None], ["select * from foo where text like '%o%'", None], ["select * from foo where text like ?", "o"], ["select * from foo where text like ?", "a"], ] conn = sqlite3.connect("c:/junk/sql_like/foodb") curs = conn.cursor() for testno, test in enumerate(tests): sql, parm = test print "\n=== Test %d ===" % (testno + 1) print "sql =", sql print "parm =", parm if parm is None: curs.execute(sql) else: arg2 = "%" + parm + "%" curs.execute(sql, (arg2, )) results = curs.fetchall() print "results:", results 8<--- output === Test 1 === sql = select * from foo parm = None results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',), (u'echo',), (u'foxtrot',)] === Test 2 === sql = select * from foo where text like '%o%' parm = None results: [(u'bravo',), (u'echo',), (u'foxtrot',)] === Test 3 === sql = select * from foo where text like ? parm = o results: [(u'bravo',), (u'echo',), (u'foxtrot',)] === Test 4 === sql = select * from foo where text like ? parm = a results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',)] Cheers, John From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:07:43 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:07:43 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <6t5uhcF9bu1hU1@mid.uni-berlin.de> Message-ID: <017dcc25$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 10:53:33 +0000, Marc 'BlackJack' Rintsch wrote: > On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > >> On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: >> >>> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. >>> wrote: (...) >>> >>>>> Give me one use-case where you strictly require that members of an >>>>> object be private and their access enforced as such ? >>>> >>>> You're kidding, right? Think about a ten-million line program being >>>> developed by 100 developers. >>> >>> No I"m sorry this is not a valid use-case. >> >> Why not? Just saying it isn't doesn't make it not. > > Because "developer" means people who don't mess with implementation > details. So they respect the leading underscore convention. No use > case for enforced access restriction. O rly? *raise eyebrow* http://www.clausbrod.de/cgi-bin/view.pl/Blog/ WebHome#DefinePrivatePublic20080413_This or http://snipurl.com/a0ujm Sometimes developers have to work around encapsulation in their own code: http://www.gamedev.net/community/forums/topic.asp?topic_id=386856 Sometimes they do it just because they can: http://java-interview-faqs.blogspot.com/2008/08/hacking-by-reflection- accessing-private.html or http://snipurl.com/a0tox And try this: http://www.google.com/codesearch?q=%22%23define+private+public%22 -- Steven From sturlamolden at yahoo.no Wed Jan 14 07:15:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 04:15:26 -0800 (PST) Subject: Standard IPC for Python? References: Message-ID: <1f6c0e5c-2766-418b-9c91-e636bcb4cbaf@p36g2000prp.googlegroups.com> On Jan 14, 12:47 pm, Laszlo Nagy wrote: > multiprocessing.Queue cannot be used as a general message queue > between arbitrary processes. Then e.g. use Listener and Client in multiprocessing.connection to create a named pipe (AF_PIPE). Or use win32pipe.CreateNamedPipe from pywin32. > - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, > > respectively) > > Which lacks synchronization between processes. It gives you access to shared memory. You must obviously use synchronization objects for synchronization. > (How do you notify the > other process? How can the other process wait until notified?) multiprocessing.Event multiprocessing.Lock win32event.CreateEvent win32event.SetEvent win32event.CreateMutex etc. From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:16:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:16:40 GMT Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Message-ID: <017dce3e$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: > Hi all! > I installed a external program called infomap using the classical > procedure > > ./configure > make > sudo make install > > and it works perfectly in Terminal (Os x) using both bash and tcsh > shell What happens when you call it using the sh shell (which is not necessarily aliased to bash)? [...] > but when I call it from python using os.system or subprocess.call I > get the message "sh: infomap-build: command not found". > > Do you know why? Possibly sh uses a different path to bash and can't find infomap-build. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:21:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:21:21 GMT Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: <017dcf56$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. Python is compiled. What do you think the c in .pyc stands for? And what do you think the compile() function does? It's just not compiled to machine code. It's compiled to byte code. -- Steven From rt8396 at gmail.com Wed Jan 14 07:49:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 04:49:25 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> Message-ID: <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> dhaval, Try www.pythonforum.org people there are much nicer to n00bs. Lots of nice people exist here, but they are too scared to speak up because of a few bullies. I am scared of nothing, as you can tell. There also exist grammarians and topicality police here that can make this forum less fun. Basically some people here think there bowel movements smell like bakery fresh cinnamon rolls :) Diez is right though, you should post something to show your efforts. Lots of people go around to forums just wanting to get their homework done for them. This does not sound like homework. From sturlamolden at yahoo.no Wed Jan 14 07:57:25 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 04:57:25 -0800 (PST) Subject: LGPL license for Qt 4.5 Message-ID: According to a Norwegian publication, Nokia will release Qt under LGPL as of version 4.5. If I had stocks in Riverbank Computing ltd., I would sell them now... For the rest of us, this is fantastic news. http://digi.no/php/art.php?id=800922 From hubaghdadi at gmail.com Wed Jan 14 07:59:08 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 04:59:08 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 14, 2:21?pm, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: > >> Well... Because it is correct ? > > >> What make you think it _shouldn't_ work ? > > > Because def2 is defined after def1 in an interpreted language, not > > compiled. > > Python is compiled. > > What do you think the c in .pyc stands for? And what do you think the > compile() function does? > > It's just not compiled to machine code. It's compiled to byte code. > > -- > Steven Yes I know Python programs can be compiled but when I do: python Script1.py Did Python compile Script1 into the memory? From benjamin.kaplan at case.edu Wed Jan 14 08:04:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:04:04 -0500 Subject: Why this code is working? In-Reply-To: References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jan 14, 2009 at 7:59 AM, Hussein B wrote: > On Jan 14, 2:21 pm, Steven D'Aprano cybersource.com.au> wrote:a > > On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: > > >> Well... Because it is correct ? > > > > >> What make you think it _shouldn't_ work ? > > > > > Because def2 is defined after def1 in an interpreted language, not > > > compiled. > > > > Python is compiled. > > > > What do you think the c in .pyc stands for? And what do you think the > > compile() function does? > > > > It's just not compiled to machine code. It's compiled to byte code. > > > > -- > > Steven > > Yes I know Python programs can be compiled but when I do: > python Script1.py > Did Python compile Script1 into the memory? > -- > yes it does, but not in the way you are thinking. Python compiles to its byte code as needed, not at the start of the program. Because Python is dynamic, you can change things on the fly. For instance, this code is perfectly valid def f2(x) : print x def f1() : f2(88) f1() #prints 88 def f2(x) : print x/2 f1() #prints 44 Because the code can change on the fly, Python looks for f2 every time f1 is called, not when it first sees the function. This is the beauty of a dynamic language. > > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Jan 14 08:08:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 05:08:25 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Listen Hussien, In python you do not have to worry about what order this is, what type to declare that, my friend your bonds are cut. Be happy with your freedom and stop complaining about it. I guess where i come from freedom is second nature so i took to python pretty quick. From benjamin.kaplan at case.edu Wed Jan 14 08:16:52 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:16:52 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <017dcc25$0$8693$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <6t5uhcF9bu1hU1@mid.uni-berlin.de> <017dcc25$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jan 14, 2009 at 7:07 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Wed, 14 Jan 2009 10:53:33 +0000, Marc 'BlackJack' Rintsch wrote: > > > On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > > > >> On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > >> > >>> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. > >>> wrote: (...) > >>> > >>>>> Give me one use-case where you strictly require that members of an > >>>>> object be private and their access enforced as such ? > >>>> > >>>> You're kidding, right? Think about a ten-million line program being > >>>> developed by 100 developers. > >>> > >>> No I"m sorry this is not a valid use-case. > >> > >> Why not? Just saying it isn't doesn't make it not. > > > > Because "developer" means people who don't mess with implementation > > details. So they respect the leading underscore convention. No use > > case for enforced access restriction. > > > O rly? *raise eyebrow* > > http://www.clausbrod.de/cgi-bin/view.pl/Blog/ > WebHome#DefinePrivatePublic20080413_This > > or http://snipurl.com/a0ujm > > Sometimes developers have to work around encapsulation in their own code: > http://www.gamedev.net/community/forums/topic.asp?topic_id=386856 > > Sometimes they do it just because they can: > > http://java-interview-faqs.blogspot.com/2008/08/hacking-by-reflection- > accessing-private.html > or http://snipurl.com/a0tox > > And try this: > > http://www.google.com/codesearch?q=%22%23define+private+public%22 > I think you actually just proved his point- the access restrictions are pointless. If there are ways to access private variables, then aren't they just private by convention as well? The only difference with Python is that, rather than going through the introspection (which Python does better than Java anyway) to get the variables, all you have to do is type that leading underscore. Either way, you know you're doing something you shouldn't. -- Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jan 14 08:21:02 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 14:21:02 +0100 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: <6t675uF9akueU1@mid.uni-berlin.de> r wrote: > Listen Hussien, Granted, with a name of "r", spelling it wrong is hard, and thus you might not be trained in the art of spelling names proper. But I suggest you try your best. After all, you posts lack so much in content, you could at least excel in form... > In python you do not have to worry about what order this is, what type > to declare that, my friend your bonds are cut. Be happy with your > freedom and stop complaining about it. I guess where i come from > freedom is second nature so i took to python pretty quick. What's that condescending nonsense to mean? What do you know of the heritage and living circumstances of the OP? And since when is a choice of typing-system correlated with the political and social aspects of a society - you care to prove that? And where did the OP "complain"? He merely wondered. I'm well aware that you are a piece of trolling d.....t. But this goes a bit to far, Mr. Diez From nick at craig-wood.com Wed Jan 14 08:32:07 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 14 Jan 2009 07:32:07 -0600 Subject: ctype problem References: Message-ID: Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > int a; > int b; > char *c; > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > _fields_ = [("a" c_int), > ("b", c_int), > ("c", c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? You didn't (or you didn't show) defining the argument types of the function. myclib = CDLL("myclib.so") # or whatever myclib.myfunction.argtypes = [ POINTER(INTERFACE) ] myclib.myfunction.restype = c_int # or whatever If you do that then you should be able to pass in myiface directly or byref(myiface). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From grante at visi.com Wed Jan 14 08:37:37 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 14 Jan 2009 07:37:37 -0600 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <172dnfILH8Y8d_DUnZ2dnUVZ_gCdnZ2d@posted.usinternet> On 2009-01-14, Steve Holden wrote: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. >> > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. You're probably right. That's why the "delete" character is all 1's (all holes). It's easy to punch more holes -- un-punching them is pretty arduous. -- Grant From castironpi at gmail.com Wed Jan 14 08:39:23 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 05:39:23 -0800 (PST) Subject: why cannot assign to function call References: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <590b092e-ae35-47d2-8793-039ee877dc8c@k1g2000prb.googlegroups.com> On Jan 14, 3:51?am, Mark Wooding wrote: > Aaron Brady wrote: > > On Jan 13, 5:06 pm, Mark Wooding wrote: > > snip > > > I'm going to move away from the formal semantics stuff and try a > > > different tack. ?Here's what I think is the defining property of > > > pass-by-value (distilled from the formal approach I described earlier, > > > but shorn of the symbolism): > > > > ? The callee's parameters are /new variables/, initialized /as if by > > > ? assignment/ from the values of caller's argument expressions. > > > In other words, the same as assignment in that language. > > It's the same as assignment of /values/ to /fresh variables/. ?It's > important to specify that argument expressions are fully evaluated, and > that nothing gets overwritten in the process. > > So the difference between Python and C is that C copies values during > assignment, but Python doesn't. ?Therefore the argument passing works > the same way. That interferes with Joe's claim that the value of a variable is a memory address. I think you'd have better luck sticking with "pass-by- assignment". A Java reference and a C++ reference are different things, somewhat regrettably. > > > Because its argument passing works the same way as its assignment. > > > That would be called pass-by-assignment. ?But you've just postponed > > explaining yourself. ?Stop delegating and work. > > Huh? ?I'm really at a loss to know what you want me to do. You were remarkably civil about that. I regretted it as soon as I sent it. You keep wanting to say "but it's just a reference, it's just a reference". But all that does is put more burden on the fellow that explains what a reference is. It took me years to grasp pointers... possibly all the way up until comp. architecture class. (As such, I find you're shirking.) > I can't help it if people are confused over the phrase `pass-by-value', > beyond trying to explain what it means using clear definitions. ?The > `value' part means that argument expressions are /evaluated/ (turned > into values), which forces applicative-order semantics rather than (say) > normal-order. I can't believe it's taken this long, including October's discussion ( and especially with my dual (not duel, ha!) in Philosophy ), but I'd finally like to quote the manuals. "An object's identity never changes once it has been created." "The value of some objects can change." - http://docs.python.org/reference/datamodel.html Therefore, an object's value is not its identity. (Its identity is something other than its value.) You might get away with 'pass-by- identity'. After 'X= [1, 2, 3]', X refers to an object. You can change two things: (1) the fact that X refers to that object, (2) that object. In 'X= None' and 'del X', you change the fact that X refers to that object. In 'X[:]= [4, 5, 6]' and 'X.pop()', you change the object. Explanatory note: It really takes two sentences to say that. 'X refers to an object. You can change the object, or change the fact that X refers to it.' If you try to say it in one sentence, the distinction collapses: 'You can change (1) the object that X refers to, or (2) the object that X refers to.' Irony! 'X' is a key in a namespace. namespace[ 'X' ]= [1, 2, 3] namespace[ 'Y' ]= namespace[ 'X' ] del namespace[ 'X' ] No matter how hard you try, if you don't have both of two things, 'namespace' and '"X"', you can't change namespace[ 'X' ]. And back to the OP (long since gone, naturally): You can do: f()[:]= [1, 2, 3] As well as: f().replace( [1, 2, 3] ) As well as: f().contents= [1, 2, 3] The particular thing s/he wanted isn't one of these. Lastly, I think it would do you and Joe good to ignore some details, when thinking about beginners. From grante at visi.com Wed Jan 14 08:39:54 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 14 Jan 2009 07:39:54 -0600 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <172dne0LH8a3dvDUnZ2dnUVZ_gAAAAAA@posted.usinternet> On 2009-01-14, Gabriel Genellina wrote: > En Tue, 13 Jan 2009 22:04:33 -0200, Terry Reedy > escribi?: > >> Gabriel Genellina wrote: >>> En Mon, 12 Jan 2009 12:00:16 -0200, John Machin >>> escribi?: >>> >>>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>>> file size as number of 128-byte sectors, forcing the use of an in-band >>>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>>> decades after people stopped writing Ctrl-Z at the end of text files. >>> This is called "backwards compatibility" and it's a good thing :) >> >> But it does not have to be the default or only behavior to be available. > > Sure. And it isn't It _is_ the default behavior on some systems. The default file mode when you open a file in C or in Python is "text" mode. In text mode, Windows interprets a ctrl-Z as EOF, doesn't it? -- Grant From castironpi at gmail.com Wed Jan 14 08:45:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 05:45:48 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <6t675uF9akueU1@mid.uni-berlin.de> Message-ID: <77e6e69e-bd55-41a2-b171-63d116145abf@r15g2000prd.googlegroups.com> On Jan 14, 7:21?am, "Diez B. Roggisch" wrote: > r wrote: > > Listen Hussien, > > Granted, with a name of "r", spelling it wrong is hard, and thus you might > not be trained in the art of spelling names proper. Or spelling proper names! Bah ha. From davide.picca at gmail.com Wed Jan 14 08:52:21 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 05:52:21 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <017dce3e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4e9c2c1b-bac2-4edf-8728-188876a64b00@n33g2000pri.googlegroups.com> On 14 Gen, 13:16, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: > > Hi all! > > I installed a external program called infomap using the classical > > procedure > > > ./configure > > make > > sudo make install > > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > > shell > > What happens when you call it using the sh shell (which is not > necessarily aliased to bash)? > > [...] > > > ?but when I call it from python using os.system or subprocess.call I > > get the message "sh: infomap-build: command not found". > > > Do you know why? > > Possibly sh uses a different path to bash and can't find infomap-build. > > -- > Steven in infocmp infotocap installer indent infokey install instmodsh indxbib infomap-build install-info instruments info infomap-install install_name_tool sh-3.2$ infomap-build Usage: infomap-build [-w working_dir] [-p param_file] [-D var_1=val_1 ... -D var_N=val_N] (-s single_corpus_file | -m multi_file_list) sh-3.2$ I am not able to figure out why.. any idea? Thanks From pythonsky at sky.com Wed Jan 14 08:52:44 2009 From: pythonsky at sky.com (garywood) Date: Wed, 14 Jan 2009 13:52:44 -0000 Subject: can someone tell me why this doesn't work please python 3 Message-ID: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): while True: password = input("enter something") if password in ('y', 'ye', 'yes'): return True if password in ('n', 'no', 'nope'): return False retries = retries - 1 if retries < 0: raise IOError('refusenik user') print(complaint) -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Jan 14 08:54:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:54:30 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 3:13 AM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > On Tue, 13 Jan 2009 23:26:54 -0800, Brendan Miller wrote: > > > I tend to use constants as a means of avoiding the proliferation of > > magic literals for maintenance reasons... Like say if your example of > > FOO would have been used in 10 places. Maybe it is more pythonic to > > simply denote such a thing as simply a normal variable? > > But it isn't a "normal variable", it's a named constant, or at least it > would be if Python enforced constanticity. Or constantness. Or whatever. > > > That doesn't > > seem to give a hint that it shouldn't be assigned a second time. > > Absolutely. It's rather sad that I can do this: > > import math > math.pi = 3.0 > > I like the ability to shoot myself in the foot, thank you very much, but > I should at least get a warning when I'm about to do so: > > math.PI = 3.0 # use God-like powers to change a constant (OT) You don't need God-like powers to do that. God already did it (it's in the bible somewhere, I don't remember where) And the Indiana state legislature thinks that doing that changing the value of pi is a perfectly legitimate action. (I guess they arrest all circles whose circumfrence:diameter ratio doesn't conform to the new value ???) http://en.wikipedia.org/wiki/Indiana_Pi_Bill > > > > > > Changing the laws of physics, one fundamental constant at a time-ly y'rs, > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From siona at chiark.greenend.org.uk Wed Jan 14 08:55:38 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 14 Jan 2009 13:55:38 +0000 (GMT) Subject: initialising a class by name References: <1231912018.7570.22.camel@krishna-laptop> <1231922209.7570.49.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> Message-ID: Krishnakant wrote: >By the way, is there a kind of global list of modules/classes which are >maintained in a package once the program is loaded into memory? sys.modules is a dict of loaded module objects, keyed by module name. So: >>> getattr(sys.modules["sys"], "version_info") (2, 5, 0, 'final', 0) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From deets at nospam.web.de Wed Jan 14 09:01:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 15:01:25 +0100 Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <017dce3e$0$8693$c3e8da3@news.astraweb.com> <4e9c2c1b-bac2-4edf-8728-188876a64b00@n33g2000pri.googlegroups.com> Message-ID: <6t69hlF98rhgU1@mid.uni-berlin.de> codicedave wrote: > On 14 Gen, 13:16, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: >> > Hi all! >> > I installed a external program called infomap using the classical >> > procedure >> >> > ./configure >> > make >> > sudo make install >> >> > and it works perfectly in Terminal (Os x) using both bash and tcsh >> > shell >> >> What happens when you call it using the sh shell (which is not >> necessarily aliased to bash)? >> >> [...] >> >> > but when I call it from python using os.system or subprocess.call I >> > get the message "sh: infomap-build: command not found". >> >> > Do you know why? >> >> Possibly sh uses a different path to bash and can't find infomap-build. >> >> -- >> Steven > > in infocmp infotocap installer > indent infokey install instmodsh > indxbib infomap-build install-info instruments > info infomap-install install_name_tool > sh-3.2$ infomap-build > > Usage: infomap-build [-w working_dir] [-p param_file] > [-D var_1=val_1 ... -D var_N=val_N] > (-s single_corpus_file | -m multi_file_list) > > > sh-3.2$ > > I am not able to figure out why.. > > any idea? How about you give the full path to the executable? Might be that the PATH isn't set correctly. If you installed the software by yourself, it is very likely that it ended up in /usr/local/bin instead of /usr/bin, and the former might not be part of the PATH-variable. Diez From wladimirufc at gmail.com Wed Jan 14 09:10:32 2009 From: wladimirufc at gmail.com (wladimir) Date: Wed, 14 Jan 2009 06:10:32 -0800 (PST) Subject: Twisted Trial - Framework for Test Message-ID: <21456710.post@talk.nabble.com> Hi, Somebody have some tutorial or examples using Twisted Trial?? -- View this message in context: http://www.nabble.com/Twisted-Trial---Framework-for-Test-tp21456710p21456710.html Sent from the Python - python-list mailing list archive at Nabble.com. From drobinow at gmail.com Wed Jan 14 09:11:12 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Wed, 14 Jan 2009 06:11:12 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 7:57?am, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > For the rest of us, this is fantastic news. > > http://digi.no/php/art.php?id=800922 http://www.qtsoftware.com/about/licensing Not sure what this means for PyQt From sturlamolden at yahoo.no Wed Jan 14 09:20:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 06:20:06 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> On Jan 14, 3:11?pm, "drobi... at gmail.com" wrote: > On Jan 14, 7:57?am, sturlamolden wrote: > > > According to a Norwegian publication, Nokia will release Qt under LGPL > > as of version 4.5. > > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > > For the rest of us, this is fantastic news. > > >http://digi.no/php/art.php?id=800922 > > http://www.qtsoftware.com/about/licensing > > Not sure what this means for PyQt It means that: - If Riverbank keep their dual GPL licensing scheme, somebody else will make an LGPL 'QtPython' instead. - If Riverbank change PyQt to LGPL, they will loose most of their revenue form PyQt. In either case, Qt will be available under the same licensing terms as wxWidgets. As of today, the main reason to prefer wxPython over PyQt is the license. With an LGPL'd Qt, I'd rather ask what this will mean for wxPython. From aahz at pythoncraft.com Wed Jan 14 09:28:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Jan 2009 06:28:33 -0800 Subject: Understanding search queries, semantics, and "Meaning" ...aren't we all looking for meaning? References: <82372457-2503-4682-96b3-37540328bf26@w39g2000prb.googlegroups.com> Message-ID: In article <82372457-2503-4682-96b3-37540328bf26 at w39g2000prb.googlegroups.com>, <5lvqbwl02 at sneakemail.com> wrote: > >I have Section 4.4.1 of SICP rattling around in my head (database >queries), and I'm trying to come up with a simple dictionary-based >database in Python to represent circuit diagrams. My main confusion >isn't one of implementation, but a matter of "big thinking", >fundamentally, about the problem. Please don't suggest using a SQL >library, as I'm looking to learn to fish, so to speak, and to learn a >bit about the biology of fish. Having read the rest of your conversation with Jonathan, I'm going to suggest a related book that I think may help you approach this from a different angle: _Mastering Regular Expressions_ by Jeffrey Friedl. (I haven't gone through SICP myself, so I can't be sure that it's relevant, but it covers the topic of transforming search criteria into executable statements -- and it will almost certainly be useful to you even if it's not relevant to your current problem.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From ddasilva at umd.edu Wed Jan 14 09:30:19 2009 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 14 Jan 2009 06:30:19 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Message-ID: <3df592bc-b544-4e63-b54e-fbdd1bdafb0a@s1g2000prg.googlegroups.com> On Jan 14, 5:25?am, codicedave wrote: > Hi all! > I installed a external program called infomap using the classical > procedure > > ./configure > make > sudo make install > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > shell > > admins-macbook-pro-2:~ unil$ infomap-build > > Usage: infomap-build [-w working_dir] [-p param_file] > ? ? ? ?[-D var_1=val_1 ... -D var_N=val_N] > ? ? ? ?(-s single_corpus_file | -m multi_file_list) > ? ? ? ? > > ?but when I call it from python using os.system or subprocess.call I > get the message "sh: infomap-build: command not found". > > Do you know why? > > Many thanks > > Davide Type "which infomap-build" from the command line to find out where infomap-build is. From lkcl at lkcl.net Wed Jan 14 09:36:40 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 14 Jan 2009 14:36:40 +0000 Subject: pyjamas 0.4p1 release Message-ID: This is a minor patch release of pyjamas 0.4p1, the Python-to-Javascript compiler and Python Web UI Widgets Toolkit. What is Pyjamas for? Pyjamas allows a developer to create U.I applications in python as if the Web Browser was a Desktop Widget Set toolkit platform (like pygtk2, pywxWidgets and pyqt4, only much simpler, and more powerful). No knowledge of javascript programming is required: the python-to-javascript compiler takes care of the conversion between python and javascript, and the U.I widget set takes care of all the browser and AJAX incompatibilities. Why don't I find that exciting? The significance of pyjamas takes a while to sink in. Or you're not a UI developer. Or you've never been asked to write an identical app that works on both the desktop and all major web browsers. If you're a python developer who has followed the history of web application development of the past decade, with much frustration and disappointment, is overwhelmed by Javascript, AJAX and the demands of the "Web 2.00o0ooo0 Revverlushun", then Pyjamas is something that you should consider investigating. Pyjamas 0.4p1 Bug-fixes (and accidental Features) Significant bugs fixed include HorizontalPanel's remove() function, SimplePanel's clear() function, and sprintf with multiple arguments ("%s %d" % ("hello", 2) will now work) Dialog Box now has modal functionality (thanks to jurgen kartnaller). HorizontalSplitPanel has been added, although both the horizontal and vertical panels operate correctly on Mozilla-based browsers, but Safari and IE need volunteers to work on them. Several more examples have also been added, including a spreadsheet-like GridEdit example; a Transparent SVG canvas clock widget (that actually tells the time); an "Information Hierarchy" example that could be used as the basis for an online cooperative spreadsheet editor; Erik Westra's "Showcase" source code which provides and shows the source of the 30 widgets being demo'd; and a few other minor examples. Discussion: http://groups.google.com/group/pyjamas-dev/ Bugs: http://code.google.com/p/pyjamas/issues/list Downloads: https://sourceforge.net/project/showfiles.php?group_id=239074 http://code.google.com/p/pyjamas/downloads/list Web site: http://pyjs.org (pyjamas javascript compiler and UI widget set) http://pyjd.org (sister project, pyjamas-desktop) From gary at byoteki.com Wed Jan 14 09:44:29 2009 From: gary at byoteki.com (Gary M. Josack) Date: Wed, 14 Jan 2009 09:44:29 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <496DFA4D.6090801@byoteki.com> garywood wrote: > def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): > while True: > password = input("enter something") > if password in ('y', 'ye', 'yes'): return True > if password in ('n', 'no', 'nope'): return False > retries = retries - 1 > if retries < 0: > raise IOError('refusenik user') > print(complaint) > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > Well since you didn't give an error I'm going to assume your problems are as follows: * Use raw_input() instead of input() # input evals the input received. * pass prompt as the argument to raw_input so that your prompt gets set # might want to give prompt a default value * password.lower() so Y, YE, YES, N, NO, NOPE also work for input From bsk16 at case.edu Wed Jan 14 09:47:57 2009 From: bsk16 at case.edu (Ben Kaplan) Date: Wed, 14 Jan 2009 09:47:57 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <496DFA4D.6090801@byoteki.com> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> Message-ID: <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: > garywood wrote: >> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >> while True: >> password = input("enter something") >> if password in ('y', 'ye', 'yes'): return True >> if password in ('n', 'no', 'nope'): return False >> retries = retries - 1 >> if retries < 0: >> raise IOError('refusenik user') >> print(complaint) >> --- >> --------------------------------------------------------------------- >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > Well since you didn't give an error I'm going to assume your > problems are as follows: > * Use raw_input() instead of input() # input evals the input received. > * pass prompt as the argument to raw_input so that your prompt gets > set # might want to give prompt a default value > * password.lower() so Y, YE, YES, N, NO, NOPE also work for input > -- > http://mail.python.org/mailman/listinfo/python-list Did you miss the python 3 part? Raw_input was removed and input now behaves like raw_input did in 2.x From mikehartl at web.de Wed Jan 14 10:01:11 2009 From: mikehartl at web.de (Michael Hartl) Date: Wed, 14 Jan 2009 16:01:11 +0100 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <496DFE37.2040306@web.de> garywood schrieb: > def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): > while True: > password = input("enter something") > if password in ('y', 'ye', 'yes'): return True > if password in ('n', 'no', 'nope'): return False > retries = retries - 1 > if retries < 0: > raise IOError('refusenik user') > print(complaint) > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > What's your problem, anyway? It seems to work perfectly fine, except that you ignore the prompt variable. From gary at byoteki.com Wed Jan 14 10:02:06 2009 From: gary at byoteki.com (Gary M. Josack) Date: Wed, 14 Jan 2009 10:02:06 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> Message-ID: <496DFE6E.8020304@byoteki.com> Ben Kaplan wrote: > > > On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: > >> garywood wrote: >>> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >>> while True: >>> password = input("enter something") >>> if password in ('y', 'ye', 'yes'): return True >>> if password in ('n', 'no', 'nope'): return False >>> retries = retries - 1 >>> if retries < 0: >>> raise IOError('refusenik user') >>> print(complaint) >>> --- >>> --------------------------------------------------------------------- >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> Well since you didn't give an error I'm going to assume your problems >> are as follows: >> * Use raw_input() instead of input() # input evals the input received. >> * pass prompt as the argument to raw_input so that your prompt gets >> set # might want to give prompt a default value >> * password.lower() so Y, YE, YES, N, NO, NOPE also work for input >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Did you miss the python 3 part? Raw_input was removed and input now > behaves like raw_input did in 2.x Ah, yes. Subject got truncated on my little laptop screen. Either way, more information is needed to diagnose the problem. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 10:02:09 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 16:02:09 +0100 Subject: Why this code is working? In-Reply-To: <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: <496dfe71$0$4822$426a74cc@news.free.fr> Hussein B a ?crit : > On Jan 14, 11:55 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Hussein B a ?crit : >> >>> Hey, >>> Why this code is working? >>>>>> def f1( ): >>> ... x = 88 >>> ... f2(x) >>> ... >>>>>> def f2(x): >>> ... print x >>> ... >>>>>> f1( ) >>> 88 >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. CPython actually compiles to byte-code, which is then executed. But anyway: even if it was fully interpreted, the fact that f2 is defined after f1 should not matter - what matters is that name f2 exists (and is bound to a callable taking a single mandatory argument) when f1 is actually _called_. >>> def f1(): ... x = 42 ... f2(x) ... >>> f1() Traceback (most recent call last): File "", line 1, in File "", line 3, in f1 NameError: global name 'f2' is not defined >>> def f2(x): ... print x ... >>> f1() 42 >>> def f2(x): ... print "pikaboo" ... >>> f1() pikaboo >>> >>> del f2 >>> f1() Traceback (most recent call last): File "", line 1, in File "", line 3, in f1 NameError: global name 'f2' is not defined >>> HTH From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 10:06:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 16:06:49 +0100 Subject: Why this code is working? In-Reply-To: References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: <496dff88$0$4822$426a74cc@news.free.fr> Hussein B a ?crit : > On Jan 14, 2:21 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: >>>> Well... Because it is correct ? >>>> What make you think it _shouldn't_ work ? >>> Because def2 is defined after def1 in an interpreted language, not >>> compiled. >> Python is compiled. >> (snip) > > Yes I know Python programs can be compiled wrt/ CPython: s/can be/are/ > but when I do: > python Script1.py > Did Python compile Script1 into the memory? Yes. Only (imported) modules are automatically saved as .pyc. From mwilson at the-wire.com Wed Jan 14 10:15:33 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 10:15:33 -0500 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Steve Holden wrote: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. Perhaps, although in ASCII it's the SUB symbol: "A control character that is used in the place of a character that is recognized to be invalid or in error or that cannot be represented on a given device." [Wikipedia]. There were other codes defined for End-of-Text and File-Separator. Unless the protocol were one of DEC's own. The fact that it's Ctrl-last-letter-of-the-alphabet makes me suspect that it was picked in a pretty informal way. Mel. From nick at craig-wood.com Wed Jan 14 10:32:07 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 14 Jan 2009 09:32:07 -0600 Subject: initialising a class by name References: Message-ID: Krishnakant wrote: > I liked this idea of dispatchTable. > is it possible to say some thing like > inst = dispatchTable{"ham"} > according to me, inst will become the instance of class ham. > Another thing to note is that all the classes are in different modules. > So where do I create the dict of classes mapped with the name? You could use a metaclass which will get round the problem, provided all the classes have a common baseclass, eg class BaseThing(object): registry = {} class __metaclass__(type): def __init__(cls, name, bases, dict): cls.registry[cls.__name__] = cls class ThingOne(BaseThing): pass class ThingTwo(BaseThing): pass class ThingThree(BaseThing): pass print BaseThing.registry["ThingOne"] print BaseThing.registry["ThingTwo"] print BaseThing.registry["ThingThree"] Which prints -- Nick Craig-Wood -- http://www.craig-wood.com/nick From marco at sferacarta.com Wed Jan 14 10:32:30 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 14 Jan 2009 16:32:30 +0100 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: Steve Holden wrote: > 3. I can't be certain my experience with PostgreSQL extends to MySQl, > but I have done experiments which prove to my satisfaction that it isn't > possible to parameterize LIKE arguments. So the only way to do it > appears to be to build the query yourself. Or using Postgres through SQLAlchemy. Actually, the only thing SQLAlchemy cannot do (yet) is withstand a zombie army. From http Wed Jan 14 10:33:20 2009 From: http (Paul Rubin) Date: 14 Jan 2009 07:33:20 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> Message-ID: <7xljtdkim7.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > If the programmer could > > somehow disallow it in certain classes, > > Already possible - you just have to provide your own implementation of > __setattr__. Part of the idea of non-dynamic attribute sets is to make the program run faster, not slower. From mwilson at the-wire.com Wed Jan 14 10:46:28 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 10:46:28 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 13, 11:40?pm, Steven D'Aprano > wrote: > >> But, gosh darn it, wouldn't it be nice to program the critical parts of >> your code in "strict Python", and leave the rest as "trusting Python", >> instead of having to use Java for the lot just to get strictness in the >> critical parts? If only there was a way to do this, and ensure people >> won't abuse it. > > Yes, that would indeed be nice. I am certainly not the only one who > could use a language that is excellent for both research prototyping > *and* the final, safety-critical system. Then perhaps the prototype > could just be cleaned up and "hardened" for the end product rather > than rewritten in another language -- by programmers in another state > who may fail to understand many of the details that the prototype > developer agonized over. You might have a look at Business Shell which is based on Ada. Mel. From kyrie at uh.cu Wed Jan 14 10:48:30 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 10:48:30 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqtkqi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <200901141048.31049.kyrie@uh.cu> On Wednesday 14 January 2009 02:22:45 am Paul Rubin wrote: > 2. There is also nothing inherent in a dynamic OO language that says > that class descriptors have to be mutable, any more than strings have > to be mutable (Python has immutable strings). ?I agree that being able > to modify class descriptors at runtime is sometimes very useful. ?The > feature shouldn't be eliminated from Python or else it wouldn't be > Python any more. ?But those occasions are rare enough that having to > enable the feature by saying (e.g.) "@dynamic" before the class > definition doesn't seem like a problem, both for encapsulation Why don't you do it backwards? You *can* implement a metaclass that will remove the dynasmism from its instances. Do it - I can give you a starting point if you wish. But most of us are very happy with the dynamic nature of python... I chose python _because_ of it. > and because it can also improve performance. Btw, for performance, there is __slots__, with the side-effect that it forbids attribute creation 'on the fly'. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Wed Jan 14 10:51:13 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 10:51:13 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <200901141051.13235.kyrie@uh.cu> On Tuesday 13 January 2009 09:57:04 pm Terry Reedy wrote: > Russ P. wrote: > public = no leading underscore > private = one leading underscore > protected = two leading underscores Aren't the last two reversed? protected = one leading underscore [both you and your subclasses should access it] private = two leading underscores (name munging) [only you should access - implementation detail.] -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Wed Jan 14 11:00:50 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 11:00:50 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901141100.50504.kyrie@uh.cu> On Tuesday 13 January 2009 10:32:54 pm James Mills wrote: > Should Python get strict and enforce access control > of object members ? No. Why ? I can think of several > reasons. > > Give me one use-case where you strictly require > that members of an object be private and their > access enforced as such ? Devil's advocate here - I think I can give you one: when you need to share some objects with potentially untrusted code (like, a plugin system). You can't, and you shouldn't, expect that the user will know what plugins he should or shouldn't load, and you shouldn't blame him/her when your app stops working because you failed to protect it's internals from malicious plugins (think web browser). Of course... in that scenario, the public/private distinction is the least of the concerns... and whatever is done to solve them will likely make irrelevant if the members are private or public. But, for trusted code? Or at least code known at compile time? It's just not worth it... pylint should take care of that - and if it doesn't, the OP should go fix it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Wed Jan 14 11:14:56 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:14:56 -0800 (PST) Subject: point class help Message-ID: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> I am hacking up a point class but having problems with how to properly overload some methods. in the __add__, __sub__, __iadd__, __isub__, I want to have the option of passing an instance or a container(list, tuple) like >>> p1 = Point2d(10,10) >>> p1 += (10,10) >>> p1 Point2d(20,20) >>> >>> p2 = Point2d(10,10) >>> p2 += p1 >>> p2 Point2d(30,30) here is what i have, it would seem stupid to use a conditional in each method like this... def method(self, other): if isinstance(other, Point2d): x, y = origin.x, origin.y else: x, y = origin[0], origin[1] #modify self.x & self.y with x&y there must be a way to get the x, y with reusable code, i am not about to have this conditional under every method call, What am i missing here? class Point2d(): def __init__(self, x, y=None): if type(x) == tuple: self.x = x[0] self.y = x[1] else: self.x = x self.y = y def __str__(self): return 'Point2d(%f, %f)' %(self.x, self.y) def __add__(self, other): if isinstance(other, Point2d): x, y = origin.x, origin.y else: x, y = origin[0], origin[1] return (self.x+x, self.y+y) def __sub__(self, other): pass def __iadd__(self, other): #+= pass def __isub__(self, other): #-= pass any ideas? From marduk at letterboxes.org Wed Jan 14 11:17:14 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 14 Jan 2009 11:17:14 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: <1231949834.26918.2.camel@localhost.localdomain> On Wed, 2009-01-14 at 16:58 +1000, James Mills wrote: [...] > Still I would avoid using this idiom altogether > and jsut stick with default values. For Example: > > FOO = 1 > > def f(x=FOO): > ... > > > Use this instead: > > def f(x=1): > ... That only works well when "1" is only used once, and as an argument to a function. Once you find yourself outside of that special case then anytime you want to change "1" to "2" then you're going to regret having made that decision. From http Wed Jan 14 11:18:51 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:18:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <7xab9tj1xw.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > when you need to share some objects with potentially untrusted code (like, a > plugin system). You can't, and you shouldn't, expect that the user will know > what plugins he should or shouldn't load, and you shouldn't blame him/her > when your app stops working because you failed to protect it's internals from > malicious plugins (think web browser). Python is not set up for this even slightly. Java attempts it, with mixed success. From mwilson at the-wire.com Wed Jan 14 11:21:38 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 11:21:38 -0500 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: Hussein B wrote: > On Jan 14, 11:55?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Hussein B a ?crit : >> >> > Hey, >> > Why this code is working? >> >> >>>> def f1( ): >> > ... ? ? ?x = 88 >> > ... ? ? ?f2(x) >> > ... >> >>>> def f2(x): >> > ... ? ? ?print x >> > ... >> >>>> f1( ) >> > 88 >> >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. You don't have to know about f2 when f1 is compiled. You only have to know about f2 when f1 is called. I predict that def f1(): n = 88 f2 (n) f1() def f2 (x): print x will *not* work. Python won't consider the non-definition of f2 to be a problem until you try to actually use it. Mel. From kyrie at uh.cu Wed Jan 14 11:24:12 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 11:24:12 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <200901141124.12596.kyrie@uh.cu> On Wednesday 14 January 2009 12:57:42 am James Mills wrote: > Russ: > > 1. Quit while you're ahead. > 2. OOP is encapsulating data and functionality into a single grouping > (object). > 3. Other features more recently developed by OO languages such as > Polymorphism, Access Control (a type of encapsulation), Inheritance > and Multiple Inheritance are all irrelevant and OO languages either > implement all or a subset of these features and each do so > differently. To further your point, I'd say that python _doesn't_ have polymorphism. It doesn't need it - the natural, expected, "OOP" behavior is always there, you cannot break it. A dog will always bark and a cat will always meow, regardless of the context and the inheritance relation between a cat and a dog (there should be none, but I couldn't think of a better example than the broken 'a cat is a dog'... please bear with me). If the very concept of polymorphism is superfluous in python, would that make python 'less' OOP? Judging by this thread, I'd guess that Russ believes that languages like C# are closer to his OOP ideal... and guess what, C# not only needs a word for the concept of "objects should behave as you expect them to behave - we want no barking cats, ever", but it is even not polymorphic by default (the cursed "virtual" keyword). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Wed Jan 14 11:31:07 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:31:07 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: <8150efe3-23c9-4909-8740-2981a9930647@d32g2000yqe.googlegroups.com> before anybody say's anything, i screwed up when i pasted the code, here is what i really have... def method(self, other): if isinstance(other, Point2d): x, y = other.x, other.y else: x, y = other[0], other[1] return self.x+x, self.y+y #and the fixed class :) class Point2d(): def __init__(self, x, y=None): if type(x) == tuple: self.x = x[0] self.y = x[1] else: self.x = x self.y = y def __str__(self): return 'Point2d(%f, %f)' %(self.x, self.y) def __add__(self, other): if isinstance(other, Point2d): x, y = other.x, other.y else: x, y = other[0], other[1] return (self.x+x, self.y+y) def __sub__(self, other): pass def __iadd__(self, other): #+= pass def __isub__(self, other): #-= pass PS: i know i could have one method like def get_xy(self, other): #conditional and then call it like x, y = self.get_xy(other) but that seems pretty clumsy. There must be a more Pythonic way! From steve at holdenweb.com Wed Jan 14 11:32:00 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:32:00 -0500 Subject: Why this code is working? In-Reply-To: <6t675uF9akueU1@mid.uni-berlin.de> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <6t675uF9akueU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > r wrote: > >> Listen Hussien, > > Granted, with a name of "r", spelling it wrong is hard, and thus you might > not be trained in the art of spelling names proper. But I suggest you try > your best. After all, you posts lack so much in content, you could at least > excel in form... > >> In python you do not have to worry about what order this is, what type >> to declare that, my friend your bonds are cut. Be happy with your >> freedom and stop complaining about it. I guess where i come from >> freedom is second nature so i took to python pretty quick. > > What's that condescending nonsense to mean? What do you know of the > heritage and living circumstances of the OP? And since when is a choice of > typing-system correlated with the political and social aspects of a > society - you care to prove that? > > And where did the OP "complain"? He merely wondered. > > I'm well aware that you are a piece of trolling d.....t. But this goes a bit > to far, Mr. > I am happy to say I did not receive the post of which you complain, Diez. Its tone was indeed abominable, and is most definitely unwelcome within fifteen thousand miles of this list. Just in case anyone else thought it was OK to make irrational deductions based only on someone's name ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 14 11:34:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:34:29 -0500 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> Message-ID: John Machin wrote: > On Jan 14, 9:42 pm, Steve Holden wrote: > >> 3. I can't be certain my experience with PostgreSQL extends to MySQl, >> but I have done experiments which prove to my satisfaction that it isn't >> possible to parameterize LIKE arguments. So the only way to do it >> appears to be to build the query yourself. This means that you will need >> to make sure the string is made "safe", typically by replacing each >> occurrence of the string "'" with "''" to retain the syntactic integrity >> of the SQL statement. So finally, try >> >> cursor.execute("""UPDATE tablename set fieldx='test' >> WHERE flfieldx IS NULL >> AND fieldy LIKE '%%%s%%'""" % >> certainvalue.replace("'", "''")) > > It appears possible to parameterise LIKE arguments in sqlite3: > 8<--- code > import sqlite3 > tests = [ > ["select * from foo", None], > ["select * from foo where text like '%o%'", None], > ["select * from foo where text like ?", "o"], > ["select * from foo where text like ?", "a"], > ] > conn = sqlite3.connect("c:/junk/sql_like/foodb") > curs = conn.cursor() > for testno, test in enumerate(tests): > sql, parm = test > print "\n=== Test %d ===" % (testno + 1) > print "sql =", sql > print "parm =", parm > if parm is None: > curs.execute(sql) > else: > arg2 = "%" + parm + "%" > curs.execute(sql, (arg2, )) > results = curs.fetchall() > print "results:", results > 8<--- output > > === Test 1 === > sql = select * from foo > parm = None > results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',), > (u'echo',), (u'foxtrot',)] > > === Test 2 === > sql = select * from foo where text like '%o%' > parm = None > results: [(u'bravo',), (u'echo',), (u'foxtrot',)] > > === Test 3 === > sql = select * from foo where text like ? > parm = o > results: [(u'bravo',), (u'echo',), (u'foxtrot',)] > > === Test 4 === > sql = select * from foo where text like ? > parm = a > results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',)] > Thanks. So this is probably a driver, or a platform, restriction. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Wed Jan 14 11:34:36 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:34:36 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <7x4p01x2w3.fsf@ruckus.brouhaha.com> Terry Reedy writes: > The question is where such checks should be. Guido prefers separate > checkers (PyChecker, PyLint) rather than in the interpreter. Again, there have to be some language extensions to communicate the necessary info to the external tool. Python 3.0 begins to do that, but as others have mentioned, it's still in a formative state while we get more experience with it. The other angle is that the compiler can use static knowledge about the program to make the program run faster, so if the checks are in an external tool, there has to be communication in both directions to make use of that. From ivan.illarionov at gmail.com Wed Jan 14 11:37:28 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 08:37:28 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> On Jan 14, 1:49?pm, Ben Sizer wrote: > No, I don't want to do anything with sys.path apart from see it. I > just wanted my original question answered, not a guess at my intent > and a solution for something I'm not doing. ;) ?Thanks though! > > Again - why can I not reference sys from within the function? Ah, sorry for wrong guess. I would try to use ourNamespace_ dict for both globals and locals in PyRun_String call. -- Ivan From steve at holdenweb.com Wed Jan 14 11:44:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:44:35 -0500 Subject: point class help In-Reply-To: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: r wrote: > I am hacking up a point class but having problems with how to properly > overload some methods. in the __add__, __sub__, __iadd__, __isub__, I > want to have the option of passing an instance or a container(list, > tuple) like > >>>> p1 = Point2d(10,10) >>>> p1 += (10,10) >>>> p1 > Point2d(20,20) >>>> p2 = Point2d(10,10) >>>> p2 += p1 >>>> p2 > Point2d(30,30) > > > here is what i have, it would seem stupid to use a conditional in each > method like this... > > def method(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > #modify self.x & self.y with x&y > > there must be a way to get the x, y with reusable code, i am not about > to have this conditional under every method call, What am i missing > here? > Not much. If you want these points to be freely mixable with containers then you should define a function like makePoint: def makePoint(x): if type(x) is Point: # assumes new-style classes return x else: return Point(x) > > class Point2d(): > def __init__(self, x, y=None): > if type(x) == tuple: > self.x = x[0] > self.y = x[1] > else: > self.x = x > self.y = y > > def __str__(self): > return 'Point2d(%f, %f)' %(self.x, self.y) > > def __add__(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > return (self.x+x, self.y+y) > > def __sub__(self, other): > pass > > def __iadd__(self, other): #+= > pass > > def __isub__(self, other): #-= > pass > > any ideas? Then your __add__ method would become: def __add__(self, other): other = makePoint(other) return (self.x+other.x, self.y+other.y) Thous it does seem particularly perverse to have the add method not itself return a Point. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Wed Jan 14 11:45:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:45:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <7xab9t7s5h.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Why don't you do it backwards? > You *can* implement a metaclass that will remove the dynasmism from its > instances. Do it - I can give you a starting point if you wish. That's kind of interesting, how does it work? > But most of us are very happy with the dynamic nature of python... I chose > python _because_ of it. I like it too, since it is indispensable in some situations. But, those situations are uncommon enough that I don't mind typing a few extra keystrokes to turn the dynamism on. > Btw, for performance, there is __slots__, That is a good point, we somehow lost sight of that in this thread. > with the side-effect that it forbids attribute creation 'on the > fly'. I have had the impression that this is a somewhat accidental side effect and shouldn't be relied on. From p3dda.adam at googlemail.com Wed Jan 14 11:47:16 2009 From: p3dda.adam at googlemail.com (p3dda.adam at googlemail.com) Date: Wed, 14 Jan 2009 08:47:16 -0800 (PST) Subject: Mod_python, jsonrpc and sessions Message-ID: <5da6ec34-673a-468c-a67c-7ad2bdbe32f8@r10g2000prf.googlegroups.com> Hi, I've got a python web-application being served by apache via mod_python, in which the users sessions are tracked via the mod_python Session module. Some of websites generated contain a java-script function which starts a jsonrpc call to the same server and gets further data or stores something to a database (AJAX). The server-sided jsonrpc functions are written in python as ServiceMethods. As I need to identify the user issuing the rpc call, I'm wondering if there is any possibility to access the session created by the previosly called mod_python Handler-method. In mod_python it is accessed using the mod_python request object, but in the rpc servicemethod I don't have such an object. So how can I track the rpc caller? Any ideas and hints appreciated. Peter From p3dda.adam at googlemail.com Wed Jan 14 11:47:18 2009 From: p3dda.adam at googlemail.com (p3dda.adam at googlemail.com) Date: Wed, 14 Jan 2009 08:47:18 -0800 (PST) Subject: Mod_python, jsonrpc and sessions Message-ID: <1e1eaa10-5e93-4961-9224-ff16ea8e9a93@w24g2000prd.googlegroups.com> Hi, I've got a python web-application being served by apache via mod_python, in which the users sessions are tracked via the mod_python Session module. Some of websites generated contain a java-script function which starts a jsonrpc call to the same server and gets further data or stores something to a database (AJAX). The server-sided jsonrpc functions are written in python as ServiceMethods. As I need to identify the user issuing the rpc call, I'm wondering if there is any possibility to access the session created by the previosly called mod_python Handler-method. In mod_python it is accessed using the mod_python request object, but in the rpc servicemethod I don't have such an object. So how can I track the rpc caller? Any ideas and hints appreciated. Peter From davide.picca at gmail.com Wed Jan 14 11:48:26 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 08:48:26 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <3df592bc-b544-4e63-b54e-fbdd1bdafb0a@s1g2000prg.googlegroups.com> Message-ID: On 14 Gen, 15:30, Daniel da Silva wrote: > On Jan 14, 5:25?am, codicedave wrote: > > > > > Hi all! > > I installed a external program called infomap using the classical > > procedure > > > ./configure > > make > > sudo make install > > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > > shell > > > admins-macbook-pro-2:~ unil$ infomap-build > > > Usage: infomap-build [-w working_dir] [-p param_file] > > ? ? ? ?[-D var_1=val_1 ... -D var_N=val_N] > > ? ? ? ?(-s single_corpus_file | -m multi_file_list) > > ? ? ? ? > > > ?but when I call it from python using os.system or subprocess.call I > > get the message "sh: infomap-build: command not found". > > > Do you know why? > > > Many thanks > > > Davide > > Type "which infomap-build" from the command line to find out where > infomap-build is. Thank you all guys I tried to use "which" command and found it in /usr/local/bin it seemed to work but at the end I think there is a dependency problem now it can not find another program called by infomap-build bin/sh: prepare_corpus: command not found make: *** [/tmp/unil/infomap_working_dir/prova/wordlist] Error 127 (take a look above) Process begun ../files/filename.txt.sst.clean Sourcing param file "/usr/local/share/infomap-nlp/default-params" Sourcing extra param file "/tmp/infomap-build.1eD7KR" Contents are: Removing extra param file WORKING_DATA_DIR = "/tmp/unil/infomap_working_dir/prova" CORPUS_DIR = "../files" CORPUS_FILE = "../files/filename.txt.sst.clean" FNAMES_FILE = "" ROWS = "20000" COLUMNS = "1000" SINGVALS = "100" SVD_ITER = "100" PRE_CONTEXT_SIZE = "30" POST_CONTEXT_SIZE = "30" WRITE_MATLAB_FORMAT = "0" VALID_CHARS_FILE = "/usr/local/share/infomap-nlp/valid_chars.en" STOPLIST_FILE = "/usr/local/share/infomap-nlp/stop.list" COL_LABELS_FROM_FILE = "0" COL_LABEL_FILE = "" echo "Making datadir" Making datadir mkdir -p /tmp/unil/infomap_working_dir/prova ================================================== Building target: /tmp/unil/infomap_working_dir/prova/wordlist Prerequisites: ../files/filename.txt.sst.clean Wed Jan 14 17:43:21 CET 2009 .................................................. prepare_corpus \ -cdir "../files" \ -mdir "/tmp/unil/infomap_working_dir/prova" \ -cfile "../files/filename.txt.sst.clean" \ -fnfile "" \ -chfile "/usr/local/share/infomap-nlp/valid_chars.en" \ -slfile "/usr/local/share/infomap-nlp/stop.list" \ -rptfile "" /bin/sh: prepare_corpus: command not found make: *** [/tmp/unil/infomap_working_dir/prova/wordlist] Error 127 any idea? thanks From rt8396 at gmail.com Wed Jan 14 11:50:52 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:50:52 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: <85f4d33e-c5d8-4438-badf-69f68fdba581@e6g2000vbe.googlegroups.com> On Jan 14, 10:44?am, Steve Holden wrote: > Thous it does seem particularly perverse to have the add method not > itself return a Point. Thanks Steve, i was going implement exactly this but thought there "might" be a better way i did not know about. So i feel better about myself already. And your right, i should be returning a Point2d() Many Thanks From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 11:51:17 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 17:51:17 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xljtdkim7.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> Message-ID: <496e1804$0$3515$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> If the programmer could >>> somehow disallow it in certain classes, >> Already possible - you just have to provide your own implementation of >> __setattr__. > > Part of the idea of non-dynamic attribute sets is to make the program > run faster, not slower. Russ argument was about "good engineering", not about raw perfs. FWIW, _you_ may be willing to trade dynamism for raw perfs, but there are probably some people here that won't agree. From kevin.jingqiu at caseware.com Wed Jan 14 11:55:20 2009 From: kevin.jingqiu at caseware.com (Kevin Jing Qiu) Date: Wed, 14 Jan 2009 11:55:20 -0500 Subject: Weird behaviour re: Python on Windows Message-ID: It's run as Administrator. The problem here is why it behaves differently when in debug mode or interactive shell than in the non-debug mode? -----Original Message----- From: python-list-bounces+kevin.jingqiu=caseware.com at python.org [mailto:python-list-bounces+kevin.jingqiu=caseware.com at python.org] On Behalf Of Jerry Hill Sent: Tuesday, January 13, 2009 11:43 PM To: python-list (General) Subject: Re: Weird behaviour re: Python on Windows On Tue, Jan 13, 2009 at 5:29 PM, Kevin Jing Qiu wrote: > I've been experiencing weird behavior of Python's os module on Windows: > > Here's the environment: > Box1: Running Windows 2003 Server with Apache+mod_python > Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ > on Box1 > > It appears any os calls that deals with file/dir on the mapped drive is > problematic. What user is this running as? By any chance is it running as the Local System user? If so, that user has no network privileges, including to mapped drives. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list -- Click the link below to report this message as spam to Caseware E-Mail Security Server ESVA. http://esva3.caseware.com/cgi-bin/learn-msg.cgi?id=404585D8606.052FD From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 11:56:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 17:56:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <496e1945$0$11785$426a74cc@news.free.fr> Paul Rubin a ?crit : > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. Given that the convention for "protected" attributes in Python is to prefix them with an underscore, I fail to see how one could "accidentally" mess with implementation details. Typing a leading underscore is rarely a typo. Oh, BTW, IIRC, there are a couple lint-like apps for Python, some of them being able to warn you about most of these (potential) problems. From rdcollum at gmail.com Wed Jan 14 11:56:43 2009 From: rdcollum at gmail.com (Roger) Date: Wed, 14 Jan 2009 08:56:43 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: On Jan 14, 8:08?am, r wrote: > I guess where i come from > freedom is second nature so i took to python pretty quick. Wow, that's presumptive, assuming, and harsh. Not at all helpful and unnecessary. Geez... From http Wed Jan 14 11:58:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:58:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> Message-ID: <7xpripzuwp.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Russ argument was about "good engineering", not about raw perfs. FWIW, > _you_ may be willing to trade dynamism for raw perfs, but there are > probably some people here that won't agree. Obviously there will never be total unanimity about every tiny thing. I haven't anywhere in this thread as far as I know suggested eliminating dynamism from Python, which would be in "that's not Python any more" territory. But, in the dozens of class definitions I write in any given day of coding, I might use the dynamism we're talking about in 1% of them at most. If having to type a few extra keystrokes on that 1% improves program reliabiity AND performance, it certainly seems worth it to me. From kylotan at gmail.com Wed Jan 14 12:00:01 2009 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 14 Jan 2009 09:00:01 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: On Jan 14, 4:37?pm, Ivan Illarionov wrote: > > I would try to use ourNamespace_ dict for > both globals and locals in PyRun_String call. I will try it when I get home. However I would like to be able to treat them as separate dictionaries, as I want to be able to import some symbols and modules at a global level, but be able to clear out objects introduced at the local level on a periodic basis, so that I can have some degree of isolation between distinct 'scripts'. The docs aren't terribly clear about what the globals and locals parameters to PyRun_String actually do, though. I also wonder if this is something specific to the sys module, since it's already been shown that there are some specific C API functions for it. I will try with other modules and see if they exhibit the same symptoms. And I'm still wondering about the sys.path[0] question. :) -- Ben Sizer From http Wed Jan 14 12:00:38 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:00:38 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <496e1945$0$11785$426a74cc@news.free.fr> Message-ID: <7xljtdzutl.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Given that the convention for "protected" attributes in Python is to > prefix them with an underscore, I fail to see how one could > "accidentally" mess with implementation details. Typing a leading > underscore is rarely a typo. We are talking about the accidental creation of new attributes in places outside the initializer. The underscore convention does nothing to prevent that. From kyrie at uh.cu Wed Jan 14 12:03:05 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 12:03:05 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9tj1xw.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9tj1xw.fsf@ruckus.brouhaha.com> Message-ID: <200901141203.05313.kyrie@uh.cu> On Wednesday 14 January 2009 11:18:51 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > when you need to share some objects with potentially untrusted code > > (like, a plugin system). You can't, and you shouldn't, expect that the > > user will know what plugins he should or shouldn't load, and you > > shouldn't blame him/her when your app stops working because you failed to > > protect it's internals from malicious plugins (think web browser). > > Python is not set up for this even slightly. Java attempts it, with > mixed success. I know. I find it sad, though. Also, I find it not a priority. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 12:08:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 18:08:44 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqtkqi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <496e1c1b$0$24829$426a74cc@news.free.fr> Paul Rubin a ?crit : > "James Mills" writes: >> Python is a dynamic object oriented language ... (almost verbatim >> from the website). It is compiled to bytecode and run on a virtual >> machine. > > 1. There is nothing inherent about dynamic languages that prevents > them from being compiled. There are compiled implementations of > Lisp and Scheme that beat the pants off of Python in performance. Yes. If you're really that concerned about Python's performances, you may want to contribute to Pypy. > 2. There is also nothing inherent in a dynamic OO language that says > that class descriptors have to be mutable, Nope, but that's how Python is designed, and we are quite a few here that value this more than raw perfs. > any more than strings have > to be mutable (Python has immutable strings). I agree that being able > to modify class descriptors at runtime is sometimes very useful. The > feature shouldn't be eliminated from Python or else it wouldn't be > Python any more. But those occasions are rare enough that having to > enable the feature by saying (e.g.) "@dynamic" before the class > definition doesn't seem like a problem, This imply that you (as the library author) pretend to know by advance when your users (programmers) will have a need for dynamism and when they won't. Fact is : you never know. It's the same old horse as enforcing access restriction : the net result is that you prevent users (which, I repeat, are programmers) to use your library as they see fit. From ivan.illarionov at gmail.com Wed Jan 14 12:17:54 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 09:17:54 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: On Jan 14, 8:00?pm, Ben Sizer wrote: > I will try it when I get home. However I would like to be able to > treat them as separate dictionaries, as I want to be able to import > some symbols and modules at a global level, but be able to clear out > objects introduced at the local level on a periodic basis, so that I > can have some degree of isolation between distinct 'scripts'. The docs > aren't terribly clear about what the globals and locals parameters to > PyRun_String actually do, though. > > I also wonder if this is something specific to the sys module, since > it's already been shown that there are some specific C API functions > for it. I will try with other modules and see if they exhibit the same > symptoms. After quick testing it looks like '__builtins__' must be in locals dictionary for your embed Python code to work, it may be a separate dictionary from globals though. >From what I know 'sys' module is related to builtins. My knowledge of Python internals is not so deep to explain the details of this relationship and answer your question about sys.path[0] though. -- Ivan From kyrie at uh.cu Wed Jan 14 12:23:58 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 12:23:58 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9t7s5h.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <200901141223.58207.kyrie@uh.cu> On Wednesday 14 January 2009 11:45:46 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > Why don't you do it backwards? > > You *can* implement a metaclass that will remove the dynasmism from its > > instances. Do it - I can give you a starting point if you wish. > > That's kind of interesting, how does it work? Proof of concept, that breaks on inheritance (can't call 'super'), but it took me just a few minutes to cook. If you aren't that paranoid, you could get rid of the 'currentframe' and 'code' hacks. This creates a class "MyClass" which instances cannot be modified. I once gave my students the homework of creating a metaclass that would type-check all the assignments to its members - so that the types wouldn't change. ======== import inspect class ImmutableType(type): def __init__(self, *args, **kwds): super(ImmutableType, self).__init__(*args, **kwds) initmethod = self.__init__.im_func def setattr(instance, attr, value): callee = inspect.currentframe(1) #letting the initializer if callee.f_code is initmethod.func_code: #initialize the object super(self, instance).__setattr__(attr, value) else: raise Exception("Object is immutable") self.__setattr__ = setattr # Heh, I'm adding a dynamic attribute :D class MyClass(object): __metaclass__ = ImmutableType a = 5 def __init__(self, value): print "assigning b" self.b = value print self.b m = MyClass("can't change") print m.a, m.b # these work m.b = 6 # and these dont. m.c = 8 ========== > > But most of us are very happy with the dynamic nature of python... I > > chose python _because_ of it. > > I like it too, since it is indispensable in some situations. But, > those situations are uncommon enough that I don't mind typing a few > extra keystrokes to turn the dynamism on. I find the opposite to be true. I _usually_ want the dynamism. Even if I'm not using it - I rely on the dynamism to be there for when I need it. > > Btw, for performance, there is __slots__, > > That is a good point, we somehow lost sight of that in this thread. > > > with the side-effect that it forbids attribute creation 'on the > > fly'. > > I have had the impression that this is a somewhat accidental side > effect and shouldn't be relied on. Yes, accidental side effect. But I see no _necessary_ harm on tacking extra attributes to an existing object - specially if you are going to use them pretty close to the creation. I use them, a lot, specially when writing decorators... Many times I just want to 'mark' the decorated functions so I can inspect those marks later. I'd rather have a semi-private namespace for each pair ([group of]calling function[s], object), but it is way easier (and so far, maintanable) to just add an appropriately named dynamic attribute to the object. Of course there can be harm - but the fault lies on the user and not the tool. I specially dislike that I can't add dynamic attributes to an object(). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From http Wed Jan 14 12:29:02 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:29:02 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> Message-ID: <7x4p01pzj5.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > But those occasions are rare enough that having to > > enable the feature by saying (e.g.) "@dynamic" before the class > > definition doesn't seem like a problem, > > This imply that you (as the library author) pretend to know by advance > when your users (programmers) will have a need for dynamism and when > they won't. We're not talking about libraries here. But in fact, we do have extensible and non-extensible versions of certain libraries (pickle, StringIO) so that the user can pick the one that suits their requirements. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 12:46:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 18:46:23 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <496e24ed$0$20343$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 13, 7:32 pm, "James Mills" > wrote: >> On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: >>> Yes, but the fact that you can approximate OO programming in a >>> particular language does not make that language object oriented. You >>> can approximate OO programming in C, but that does not mean that C is >>> an OO language. >> Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) >> (Please stop confusing the two) is not a strict requirements of the OO model. > > I think you are the one who is confused. Part of the problem here is > that the term "encapsulation" has at least two widely used meanings > (in the context of programming). In one sense, it just means grouping > data and methods together. In another sense, it means restricting the > client's access to data or methods. The second is named "data hiding". And while it's a mean to _enforce_ encapsulation, it is not encapsulation by itself. Encapsulation is about making clear what's part of the public interface and what's implementation detail - IOW, it's about decoupling client code from implementation. Nothing in this _requires_ data hiding. > Someone earlier on this thread > tried to claim that the first meaning applies to OOP, but Wikipedia > (and many other sources) say just the opposite. You can choose to trust everything you read on wikipedia. You can... wrt/ what's OO, the only commonly accepted definitions are: 1/ objects are defined by an identity, a state and a behaviour 2/ objects communicate by sending messages to each other > People here are trying to claim that the leading underscore > conventions used with Python are essentially equivalent to > encapsulation. That is nonsense, of course. Your POV. > But the point is that if you don't like > encapsulation, I do like it. What I don't like is useless language-enforced restrictions. > then by definition you don't like OOP. You may like > certain features of OOP, but you don't like it in general. That's > about all their is to it. > > And by the way, please don't bring up the canard that I am some kind > of OO zealot. I think OO is overrated, and I don't Java, in part > because it forces everything to be OO. The issue here is not my > personal opinion of OOP. This issue is one of widely accepted > definitions within the OO community. Another widely accepted definition within the OO community is that C++ is an OO language because it has classes and data-hiding, and that Javascript is not because it has none of them. > >> Remember that it is a model and not a strict set of requirements that >> programming >> languages must implement. > > Of course it's not a "requirement that programming languages must > implement." It's only a requirement if they want to be OO languages. Neither. The only requirements for being an OOPL are stated above. >> In fact, Python borrows features from the Functional Paradigm. Does this >> make it a Functional Language ? No. Why ? Because one of the clear >> requirements of the Functional Paradigm is that functions cannot have >> side affects. >> >>> So I can claim that Python is not strictly object oriented You can claim it, yes. OTHO, I can claim that Java is not strictly object oriented since it has non-object types. In both cases, this is just plain meaningless. There's no closed, well-defined theory, no mathematical model behind "OO" (like there are for functional programming or for the relational model). So you just can't apply "strictly" to OO. It's just nonsense. >>> until it >>> gets encapsulation (in the sense of data hiding). That is simply a >>> fact, and no amount of pleading or obfuscation will change it. IOW : "this is the HolyTruth(tm), because I said so". Sorry, won't work. >> In fact this is true, C can be seen as an programming language >> that has features of the OO model. Yes. And FWIW, there are OO libraries and programs written in plain C. Ever heard of GTK+ ? >> I think one of the things you guys are missing out >> here is that there are really only two Paradigms >> or Machines. Functional and Imperative. And guess >> what ? As it turns out we can implement functional >> machines that run on top of imperative ones! >> >>> Should Python get true encapsulation? I don't know. Maybe >>> encapsulation cannot be added without excessive overhead or without >>> compromising other more important aspects and features of the >>> language. But I do know that not having encapsulation is a limitation >>> to the use of Python for good software engineering. For a somewhat partial definition of "good software engineering". Mine is that anything that leads to a correct, robuste and maintainable program is good engineering, anything else is not. From this POV, and given the proven fact that the bug/LOC ratio is nearly constant whatever the language, anything that adds accidental complexity makes the program less robust and less maintainable, and as such is _not_ "good software engineering". Sorry for being pragmatic !-) >>> I may be in the >>> minority in the Python "community" on this one, but I am apparently in >>> the majority in the OO programming "community." >> Again, stop confusing terminology. >> >> Should Python get strict and enforce access control >> of object members ? No. Why ? I can think of several >> reasons. >> >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. And ? Except that this code surely needs urgent surgery (sorry, I meant refactoring), I don't see what the size of the project or the team has to do with it. You'll find successful "monster" projects written in languages that are even more permissive than Python (C anyone ?), and failed "monster" projects written in highly unpermissive languages like Java or ADA. From http Wed Jan 14 12:54:13 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:54:13 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> Message-ID: <7xvdshhiyi.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > You'll find successful "monster" projects written in > languages that are even more permissive than Python (C anyone ?), Could you name one written in C? Anyway, C is far less safe than Python in some ways, but has lots more compile time checking. From Scott.Daniels at Acm.Org Wed Jan 14 12:57:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 14 Jan 2009 09:57:28 -0800 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> Message-ID: Gary M. Josack wrote: > Ben Kaplan wrote: >> On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: >>> garywood wrote: >>>> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >>>> while True: >>>> password = input("enter something") >>>> if password in ('y', 'ye', 'yes'): return True >>>> if password in ('n', 'no', 'nope'): return False >>>> retries = retries - 1 >>>> if retries < 0: >>>> raise IOError('refusenik user') >>>> print(complaint) >>> Well since you didn't give an error I'm going to assume your problems >>> are as follows: >>> * Use raw_input() instead of input() # input evals the input received. >>> * pass prompt as the argument to raw_input so that your prompt gets >>> set # might want to give prompt a default value >>> * password.lower() so Y, YE, YES, N, NO, NOPE also work for input >> Did you miss the python 3 part? Raw_input was removed and input now >> behaves like raw_input did in 2.x > Ah, yes. Subject got truncated on my little laptop screen. Either way, > more information is needed to diagnose the problem. It is a bad idea to have post content exclusively in the headers. Readers sometimes select by subject, but only read content. However the answer the OP is looking for with his ill-formed question could be revealed if his final print were: print('%s on reply %r' % (complaint, password)) He'd realize he wanted: password = input(prompt).rstrip() --Scott David Daniels Scott.Daniels at Acm.Org From ivan.illarionov at gmail.com Wed Jan 14 13:03:35 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 10:03:35 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: <12810ebb-9047-4096-815f-0d8639b309f2@r38g2000vbi.googlegroups.com> On Jan 14, 8:17?pm, Ivan Illarionov wrote: > On Jan 14, 8:00?pm, Ben Sizer wrote: > > > I will try it when I get home. However I would like to be able to > > treat them as separate dictionaries, as I want to be able to import > > some symbols and modules at a global level, but be able to clear out > > objects introduced at the local level on a periodic basis, so that I > > can have some degree of isolation between distinct 'scripts'. The docs > > aren't terribly clear about what the globals and locals parameters to > > PyRun_String actually do, though. > > > I also wonder if this is something specific to the sys module, since > > it's already been shown that there are some specific C API functions > > for it. I will try with other modules and see if they exhibit the same > > symptoms. > > After quick testing it looks like '__builtins__' must be in locals > dictionary for your embed Python code to work, it may be a separate > dictionary from globals though. > > From what I know 'sys' module is related to builtins. My knowledge of > Python internals is not so deep to explain the details of this > relationship and answer your question about sys.path[0] though. Sorry, I probably was terribly wrong in my last post, it doesn't work this way with separate dictionaries. I never had to use separate dictionaries. Maybe someone with better knowledge of Python internals may help? -- Ivan From kyrie at uh.cu Wed Jan 14 13:07:39 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 13:07:39 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xvdshhiyi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> Message-ID: <200901141307.39415.kyrie@uh.cu> On Wednesday 14 January 2009 12:54:13 pm Paul Rubin wrote: > Bruno Desthuilliers writes: > > You'll find successful "monster" projects written in > > languages that are even more permissive than Python (C anyone ?), > > Could you name one written in C? hmm... http://kernel.org -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From http Wed Jan 14 13:13:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:13:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> Message-ID: <7x3aflwyat.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > > You'll find successful "monster" projects written in > > > languages that are even more permissive than Python (C anyone ?), > > > > Could you name one written in C? > > hmm... http://kernel.org That project may be successful in terms of having a lot of users, but much less so in terms of code reliability (see all the CERT bulletins about it). Also, it is much smaller than 10 MLOC, I think. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 13:17:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 19:17:36 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpripzuwp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: <496e2c3f$0$29454$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Russ argument was about "good engineering", not about raw perfs. FWIW, >> _you_ may be willing to trade dynamism for raw perfs, but there are >> probably some people here that won't agree. > > Obviously there will never be total unanimity about every tiny thing. Indeed !-) > I haven't anywhere in this thread as far as I know suggested > eliminating dynamism from Python, Nope, but your suggestion would have the same practical result as far as I'm concerned. > which would be in "that's not Python > any more" territory. But, in the dozens of class definitions I write > in any given day of coding, I might use the dynamism we're talking > about in 1% of them at most. Indeed : these are the classes _you_ (as a library author), write, so they work as _you_ (as a user of these library) expect them to work. > If having to type a few extra keystrokes > on that 1% improves program reliabiity AND performance, it certainly > seems worth it to me. If it makes simple thing overly complicated, it certainly seems _worse_ to me !-) From http Wed Jan 14 13:21:01 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:21:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: <7xab9t3g1e.fsf@ruckus.brouhaha.com> Carl Banks writes: > Guess what systems I worked on that didn't even use scoping? I wrote > code for the GP7000 (equipped on some Airbus 380s) and the F-136 > (which will be equipped on some F-35 fighters) engine controllers. > Neither one used any data hiding. The language was C (not C++), but > it was generated from schematic diagrams. Generated from a schematic by a program you mean? In that case, the C was used sort of like assembly code emitted by a compiler. Not really the same situation. > Would you like to adopt GE's practice of schematic-generated C with no > namespaces or data hiding? No? Then don't be telling me I have to > embrace Boeing's. All you're telling us is that GE makes foolish choices. From http Wed Jan 14 13:22:53 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:22:53 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> Message-ID: <7x63kh3fya.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > I haven't anywhere in this thread as far as I know suggested > > eliminating dynamism from Python, > > Nope, but your suggestion would have the same practical result as far > as I'm concerned. Sorry, I don't comprehend that. The rest of your post makes no sense as a consequence. Python already had such a change when it deprecated and later got rid of string exceptions. It's still Python. From Russ.Paielli at gmail.com Wed Jan 14 13:32:47 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 10:32:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: On Jan 14, 1:54?am, Carl Banks wrote: > I thought you were done wasting time with this nonsense. So did I. > > An engine *simulation* is one > > thing; the actual engine control code is another. > > Guess what systems I worked on that didn't even use scoping? ?I wrote > code for the GP7000 (equipped on some Airbus 380s) and the F-136 > (which will be equipped on some F-35 fighters) engine controllers. > Neither one used any data hiding. ?The language was C (not C++), but > it was generated from schematic diagrams. > > Would you like to adopt GE's practice of schematic-generated C with no > namespaces or data hiding? ?No? ?Then don't be telling me I have to > embrace Boeing's. Well, that's interesting. But you say the code was "generated from schematic diagrams." Does that mean it was automatically generated by machine? If so, then the concerns about encapsulation may no longer apply. In that case, the schematics were the implementation "language," and the code that was generated was essentially a higher level version of assembly or machine code (because humans don't work with it directly). I know some researchers in software engineering who believe that the ultimate solution to software reliability is automatic code generation. The don't really care much which language is used, because it would only be an intermediate form that humans don't interact with directly. In that scenario, humans would essentially use a "higher level" language such as UML or some such thing. I personally have a hard time seeing how that could work, but that may just be due to be my own lack of understanding or vision. From benjamin.kaplan at case.edu Wed Jan 14 13:34:06 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 13:34:06 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3aflwyat.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> <7x3aflwyat.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 1:13 PM, Paul Rubin <"http://phr.cx"@nospam.invalid>wrote: > Luis Zarrabeitia writes: > > > > You'll find successful "monster" projects written in > > > > languages that are even more permissive than Python (C anyone ?), > > > > > > Could you name one written in C? > > > > hmm... http://kernel.org > > That project may be successful in terms of having a lot of users, but > much less so in terms of code reliability (see all the CERT bulletins > about it). Also, it is much smaller than 10 MLOC, I think. It just recent passed the 10 million mark. http://www.heise-online.co.uk/open/Kernel-Log-Higher-and-Further-The-innovations-of-Linux-2-6-28--/features/112299/5 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.sakkis at gmail.com Wed Jan 14 13:44:20 2009 From: george.sakkis at gmail.com (George Sakkis) Date: Wed, 14 Jan 2009 10:44:20 -0800 (PST) Subject: Preserving file permissions with distutils Message-ID: I'm trying to use distutils to install some package data and additional files, some of which may be executable. It turns out that distutils does not preserve the permissions. Digging in the code, there is the following comment on distutils/command/build_py: # XXX copy_file by default preserves mode, which appears to be the # wrong thing to do: if a file is read-only in the working # directory, we want it to be installed read/write so that the next # installation of the same module distribution can overwrite it # without problems. (This might be a Unix-specific issue.) Thus If the only reason for not preserving the mode is ensuring it's read/ write, why not preserve the rest permissions and set the write flag for the owner ? The comment continues: # we turn off 'preserve_mode' when copying to the build directory, # since the build directory is supposed to be exactly what the # installation will look like (ie. we preserve mode when # installing). But installing copies from the build dir which has forgotten the original permissions, so there is no actual preservation! Am I reading this wrong or should I submit a bug report ? George From gert.cuykens at gmail.com Wed Jan 14 13:47:43 2009 From: gert.cuykens at gmail.com (gert) Date: Wed, 14 Jan 2009 10:47:43 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> Message-ID: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> On Jan 13, 11:58?pm, "Martin v. L?wis" wrote: > Steve Holden wrote: > > Daniel Fetchinson wrote: > >>> I need something to connect to a database, preferably mysql, that > >>> works in python3.0 please. > >> And your question is? > > > Surely it's fairly obvious that the question is "does such a thing > > exist, and if so where can I find it?". > > Interestingly enough, the question was slightly (but importantly) > different, though: the question really was "Does anybody has a patch for > MySQLdb?"; as my reference to the existing interface to PostgreSQL > was not sufficient for the OP. Yes it was enough, but I can not imagine it has not been done yet for MySql either :) It was a open statement where I expected like 10 different databases responses. For example if you go to a dinner place you have never been gone before and want to try something new and there is no menu available. What do you ask ? You just say something similar. "I would like to order a salet please with some red wine." I don't think any one of you would expect the waiter to answer,"And your question is?" I also think the waiter does not expect me to ask 10 similar questions like "red wine 1991? red wine 1992? red wine 1993? until i hit something that is on the menu" So the final questions was, is there anything els on the menu besides PostgreSQL, like MySql for example ? If not I will take PostgreSQL please. From ajaksu at gmail.com Wed Jan 14 13:56:47 2009 From: ajaksu at gmail.com (ajaksu) Date: Wed, 14 Jan 2009 10:56:47 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 14, 5:14?am, Steve Holden wrote: > ajaksu wrote: >> [snip evangelism stuff] > OK, but be aware that the PSF doesn't monitor the bugs looking for > actions to take on behalf of the Python user community. In fact we > aren't overtly "political" in this way at all. This doesn't mean it > wouldn't be useful for the PSF to get involved in this role; just that > right now it isn't, and a bug report probably isn't the best way to get > action. Acknowledged. I have posted a (pretty poor) support request @ http://groups.google.com/group/Google-Groups-Basics/ and suggest others do the same for Wikipedia and other big sites that block 3.0 (I might build a list of those later today). Maybe a wiki page, some blog posts, etc. Best regards, Daniel Request: http://groups.google.com/group/Google-Groups-Basics/browse_thread/thread/498a39a89d81b650# """ Hi, As mentioned in a comp.lang.python thread[1], the new version of Python (3.0) cannot open pages @ groups.google.com. It seems the UA of Python 3.0 ("User-Agent: Python-urllib/3.1") is actively blocked, while that of Python 2.5 ("User-Agent: Python-urllib/ 1.17") isn't. This message is a call for help so that we can get Python 3.0 working with groups.google.com. Is this the right place to bring the issue to the attention of those that can fix it? Does anyone have a contact that could speed up getting Python 3.0 working? Thanks in advance, Daniel [1]http://groups.google.com/group/comp.lang.python/browse_thread/ thread/088491d5a0d86f1b """ From kyosohma at gmail.com Wed Jan 14 14:05:31 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 14 Jan 2009 11:05:31 -0800 (PST) Subject: LGPL license for Qt 4.5 References: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> Message-ID: On Jan 14, 8:20?am, sturlamolden wrote: > On Jan 14, 3:11?pm, "drobi... at gmail.com" wrote: > > > On Jan 14, 7:57?am, sturlamolden wrote: > > > > According to a Norwegian publication, Nokia will release Qt under LGPL > > > as of version 4.5. > > > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > > > For the rest of us, this is fantastic news. > > > >http://digi.no/php/art.php?id=800922 > > >http://www.qtsoftware.com/about/licensing > > > Not sure what this means for PyQt > > It means that: > - If Riverbank keep their dual GPL licensing scheme, somebody else > will make an LGPL 'QtPython' instead. > - If Riverbank change PyQt to LGPL, they will loose most of their > revenue form PyQt. > > In either case, Qt will be available under the same licensing terms as > wxWidgets. > > As of today, the main reason to prefer wxPython over PyQt is the > license. With an LGPL'd Qt, I'd rather ask what this will mean for > wxPython. I'm pretty sure that Qt is mostly (if not all) custom widgets whereas wxPython uses native widgets whenever possible. While this allows Qt to have skinning (a plus!), it also can make them look less than native (a minus!). If they do release a LGPL version, I may take a look at it just to see how different it is, although I'm pretty happy with what I'm using. Mike From martin at v.loewis.de Wed Jan 14 14:08:22 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 14 Jan 2009 20:08:22 +0100 Subject: python3.0 MySQLdb In-Reply-To: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: <496E3826.5080100@v.loewis.de> > So the final questions was, is there anything els on the menu besides > PostgreSQL, like MySql for example ? There is sqlite3 also; it is included in Python 3. Otherwise, I don't think any other DB-API compliant database connectors have been ported to Python 3 yet; it may take many months until somebody volunteers to port a MySQL driver. The difference to your restaurant example is that the market for red wine is many hundred years old. The market for Python 3 modules is just a month old. Hence, you have different offers for red wine, but nearly none for Python 3 modules. Regards, Martin From http Wed Jan 14 14:16:23 2009 From: http (Paul Rubin) Date: 14 Jan 2009 11:16:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: <7x4p01n1fc.fsf@ruckus.brouhaha.com> "Russ P." writes: > I know some researchers in software engineering who believe that the > ultimate solution to software reliability is automatic code > generation. The don't really care much which language is used, because > it would only be an intermediate form that humans don't interact with > directly. In that scenario, humans would essentially use a "higher > level" language such as UML or some such thing. > > I personally have a hard time seeing how that could work, but that may > just be due to be my own lack of understanding or vision. The usual idea is that you would write a specificiation, and a constructive mathematical proof that a certain value meets that specification. The compiler then verifies the proof and turns it into code. Coq (http://coq.inria.fr) is an example of a language that works like that. There is a family of jokes that go: Q. How many $LANGUAGE programmers does it take to change a lightbulb? A. [funny response that illustrates some point about $LANGUAGE]. The instantiation for Coq goes: Q. How many Coq programmers does it take to change a lightbulb? A. Are you kidding? It took two postdocs six months just to prove that the bulb and socket are threaded in the same direction. Despite this, a compiler for a fairly substantial C subset has been written mostly in Coq (http://compcert.inria.fr/doc/index.html). But, this stuff is far far away from Python. I have a situation which I face almost every day, where I have some gigabytes of data that I want to slice and dice somehow and get some numbers out of. I spend 15 minutes writing a one-off Python program and then several hours waiting for it to run. If I used C instead, I'd spend several hours writing the one-off program and then 15 minutes waiting for it to run, which is not exactly better. (Or, I could spend several hours writing a parallel version of the Python program and running it on multiple machines, also not an improvement). Often, the Python program crashes halfway through, even though I tested it on a few megabytes of data before starting the full multi-gigabyte run, because it hit some unexpected condition in the data that could have been prevented with more compile time checking that made sure the structures understood by the one-off script matched the ones in the program that generated the input data. I would be ecstatic with a version of Python where I might have to spend 20 minutes instead of 15 minutes writing the program, but then it runs in half an hour instead of several hours and doesn't crash. I think the Python community should be aiming towards this. From Scott.Daniels at Acm.Org Wed Jan 14 14:20:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 14 Jan 2009 11:20:27 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpripzuwp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > .... I haven't anywhere in this thread as far as I know suggested > eliminating dynamism from Python, which would be in "that's not Python > any more" territory. But, in the dozens of class definitions I write > in any given day of coding, I might use the dynamism we're talking > about in 1% of them at most. If having to type a few extra keystrokes > on that 1% improves program reliabiity AND performance, it certainly > seems worth it to me. But, the research on the language "Self" shows that even in the face of a language with more dynamism than Smalltalk (or Python), performance can be obtained using compiler technology. It turns out you don't have to type those type any extra keystrokes. Compilers capable of doing strong optimization already have to do enough analysis that they can discover the static typing that is available in the code you write naturally. The way to get to such performance on Python is through efforts like PyPy. --Scott David Daniels Scott.Daniels at Acm.Org From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:33:01 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:33:01 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x63kh3fya.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> <7x63kh3fya.fsf@ruckus.brouhaha.com> Message-ID: <496e4b97$0$24021$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> I haven't anywhere in this thread as far as I know suggested >>> eliminating dynamism from Python, >> Nope, but your suggestion would have the same practical result as far >> as I'm concerned. > > Sorry, I don't comprehend that. IIRC, your suggestion was that one should have to explicitely allow "dynamic binding" (ie: outside the initializer) of new attributes, and that the default vould be to disallow them. That's at least what I understood from : """ There are cases where this is useful but they're not terribly common. I think it would be an improvement if creating new object attributes was by default not allowed outside the __init__ method. In the cases where you really do want to create new attributes elsewhere, you'd have to explicitly enable this at instance creation time, for example by inheriting from a special superclass: class Foo (DynamicAttributes, object): pass """ (snip) > Python already had such a change when it deprecated and later got rid > of string exceptions. I really don't get how this would be comparable with the above suggestion. I can well understand your concerns wrt/ Python's performances (even if I don't agree on your proposed solutions), but this one "argument" really looks like a straw man. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:44:04 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:44:04 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01pzj5.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> Message-ID: <496e4e2e$0$10088$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> But those occasions are rare enough that having to >>> enable the feature by saying (e.g.) "@dynamic" before the class >>> definition doesn't seem like a problem, >> This imply that you (as the library author) pretend to know by advance >> when your users (programmers) will have a need for dynamism and when >> they won't. > > We're not talking about libraries here. Yes we are. If the default is "non-dynamic", then a class author is in charge of explicitely allowing it when *he* see fits. > But in fact, we do have > extensible and non-extensible versions of certain libraries (pickle, > StringIO) what we have are python-coded and highly optimized C-coded versions of the same libraries. FWIW, in both cases, the python version came first, and the C implementation followed when it was clear that for these specific libs, the less-dynamic C version's perf improvement justified giving up on dynamism, *given that:* > so that the user can pick the one that suits their requirements. As long as it's up to the *user* to choose, that's ok. Your "@dynamic" class decorator doesn't have the same implications. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:56:08 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:56:08 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xljtdzutl.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <496e1945$0$11785$426a74cc@news.free.fr> <7xljtdzutl.fsf@ruckus.brouhaha.com> Message-ID: <496e5102$0$18840$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Given that the convention for "protected" attributes in Python is to >> prefix them with an underscore, I fail to see how one could >> "accidentally" mess with implementation details. Typing a leading >> underscore is rarely a typo. > > We are talking about the accidental creation of new attributes in > places outside the initializer. Nope. This was about encapsulation and data-hiding, cf: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/068bc54bca830c46/049a721414f4d4da?rnum=41&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F068bc54bca830c46%3F#doc_83a09b54d386eb6c and the convention James refered to was obviously the naming convention. From rt8396 at gmail.com Wed Jan 14 14:56:41 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 11:56:41 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) Message-ID: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> I actually like the IDLE, but it could use a few improvements. If anybody else has suggestions by all means post them. 1.) The text widget and the prompt(>>>) should be separated. Trying to write a conditional in the interactive IDLE is a real PITA. Not to mention if you copy the working code snippet to the IDLE editor window the indention is 8 spaces instead 4 AND you've got that prompt(>>>) stuck in there. I have a solution for the problem though.( I hope you all are using fixed-width font) frm |<---------------------text widget -----------------> >>> | >>> |if this == 1: ... | if that == 2: ... | #do ... | elif that ==3: ... | #do ... | else: ... | pass >>> | >>> |x = 10 Basically you have a Listbox on the left for the prompt and a Text on the right. Disable the Listbox highlight and key press events and now we have a very friendly interactive IDLE! No more prompt hijacking your snippets, and no more 8 space indention! 2.) When you press MMB and there is a highlighted selection in the text it gets pasted over and over again @ the insertion cursor (gives me the red @ss!) Anybody want to comment or add suggestions? From mccredie at gmail.com Wed Jan 14 14:59:48 2009 From: mccredie at gmail.com (Matimus) Date: Wed, 14 Jan 2009 11:59:48 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> <85f4d33e-c5d8-4438-badf-69f68fdba581@e6g2000vbe.googlegroups.com> Message-ID: On Jan 14, 8:50?am, r wrote: > On Jan 14, 10:44?am, Steve Holden wrote: > > > Thous it does seem particularly perverse to have the add method not > > itself return a Point. > > Thanks Steve, > i was going implement exactly this but thought there "might" be a > better way i did not know about. So i feel better about myself > already. And your right, i should be returning a Point2d() > Many Thanks I just inherited from tuple and did it like this. Note that this served my needs, but it definitely needs some work to become general purpose. Also note that I used '__new__' instead of __init__, making this type immutable. class Point(tuple): "Simple immutable point class (vector) supports addition and subtraction" def __new__(cls, x, y=None): if y is None: x, y = x return super(Point, cls).__new__(cls,(x, y)) def __add__(self, p): return Point(self[0]+p[0], self[1]+p[1]) def __sub__(self, p): return Point(self[0]-p[0], self[1]-p[1]) def __neg__(self): return Point(-self[0], -self[1]) def __pos__(self): return self def __str__(self): return "Point(%d, %d)"%(self[0], self[1]) __repr__ = __str__ Matt From koranthala at gmail.com Wed Jan 14 15:57:03 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 14 Jan 2009 12:57:03 -0800 (PST) Subject: Python Crashes Message-ID: Hi, I have a twisted based application based on Python 2.4.3. I also have one thread in this application. I found that my program crashes repeatedly after a random interval (ranging from 10 min to 3 hr). When I say crash, it is not just that the program dies. Rather in WinXP - a window comes mentioning that 'Python.exe unexpectedly crashed'. I tried putting in catching the exception by using try: except - and logging everything. But the logging code is also not hit, i.e. even the 'except' code is not hit. I feel that the base python interpreter itself is crashing due to some bug in my program. Earlier, I had put code as try: except: log At this time, my whole machine also froze. It was so slow that one mouse movement happened after 7-8 minutes after I moved the mouse. Then I modified the code to try: except Exception: log Then, the machine no longer freezes. But, still there is no logging of errors happening too. Could anyone guide me on this? I have been facing this issue for a day, and cannot seem to solve it. P.S -> I am not allowed to post the code of application - so I hope I have explained it enough. From philip at semanchuk.com Wed Jan 14 16:02:42 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jan 2009 16:02:42 -0500 Subject: Python Crashes In-Reply-To: References: Message-ID: <2CFF5365-ECA9-49BA-B7AE-37B2BFA1FCD4@semanchuk.com> On Jan 14, 2009, at 3:57 PM, koranthala wrote: > Hi, > I have a twisted based application based on Python 2.4.3. I also > have one thread in this application. > > I found that my program crashes repeatedly after a random interval > (ranging from 10 min to 3 hr). When I say crash, it is not just that > the program dies. Rather in WinXP - a window comes mentioning that > 'Python.exe unexpectedly crashed'. Are you using any 3rd party modules? From kirby.urner at gmail.com Wed Jan 14 16:05:09 2009 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 14 Jan 2009 13:05:09 -0800 (PST) Subject: pythonic chew toyz (a column, by K. Urner) v.1 n.1 Message-ID: <4bc8d545-8148-4dad-86f5-b8c227c7c8b5@w1g2000prm.googlegroups.com> Selena spotted me right away as "the O'Reilly spy", me agreeing she had an exceptionally good memory, maybe we could recruit her? Our banter traces to the first meeting on OS Bridge and how I introduced myself [0], not yet realizing Allison Randal was in the audience (way more an insider, as to how many Ls).[1] Last night in the Roman room (CubeSpace) I proposed she could emcee the panel we're planning (maybe?), after the new Mayor (Sam Adams) kicks it off with a keynote -- all in the proposal stage, looking over her shoulder. I was also there for the __metaclasses__ discussion by John Melesky, and for work, most of that same day (this is PDX CubeSpace, a lot of us rent office space). Jason talked about the __missing__ rib (in dict). As we were getting settled, they talked about OSCON, perking my interest. Whereas some take the view we're somehow competing with San Jose (where a lot of my friends work), my model is more Cirque du Soleil, given where "geeks" come from (something about chickens). Five OSCONs running in parallel in any given summer would make more sense than just one, but then O'Reilly isn't quite as big as McGraw- Hill (BYTE), yet. Anyway, Portland is happy to share the glory. OS Bridge another bulb on the breadboard (aka grid), getting brighter by the day. Speaking of BYTE, I also learned last night that Eliza, our geek therapist, is alive and well in Python, as a part of the Natural Language Toolkit or NLTK. And she's got company. Some of you may recall Hugh Kenner's hilarious investigation of chat bots, then very new, in a way back issue (1980s).[3] Hugh, by the way, was a leading 20th century James Joyce scholar and fan of R. Buckminster Fuller (see 'The Pound Era'), Bucky a champion for me as well (hence my rbf.py -- named after the guy, for use with VPython, POV-Ray, x3d etc., more on edu-sig). I'll catch up again later, maybe from Chicago, maybe before.[4] [1] http://mail.python.org/pipermail/portland/2008-November/000512.html [2] http://mybizmo.blogspot.com/2009/01/ppug-2009113.html [3] http://mathforum.org/kb/message.jspa?messageID=5256703&tstart=0 [4] http://showmedo.com/videos/video?name=1010050&fromSeriesID=101 From kirby.urner at gmail.com Wed Jan 14 16:18:10 2009 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 14 Jan 2009 13:18:10 -0800 (PST) Subject: pythonic chew toyz (a column, by K. Urner) v.1 n.1 Message-ID: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> Selena spotted me right away as "the O'Reilly spy", me agreeing she had an exceptionally good memory, maybe we could recruit her? Our banter traces to the first meeting on OS Bridge and how I introduced myself [0], not yet realizing Allison Randal was in the audience (way more an insider, as to how many Ls in Randall).[1] Last night in the Roman room (CubeSpace) I proposed she could emcee the panel we're planning (maybe?), after the new Mayor (Sam Adams) kicks it off with a keynote -- all in the proposal stage, looking over her shoulder. I was also there for the __metaclasses__ discussion by John Melesky, and for work, most of that same day (this is PDX CubeSpace, a lot of us rent office space). Jason talked about the __missing__ rib (in dict).[2] As we were getting settled, they talked about OSCON, perking my interest. Whereas some take the view we're somehow competing with San Jose (where some of my friends work, or worked in the case of Maxtor and IBM), my model is more Cirque du Soleil, given where "geeks" come from (something about chickens).[3] Five OSCONs running in parallel in any given summer would make more sense than just one, but then O'Reilly isn't quite as big as McGraw- Hill (BYTE), yet. Anyway, Portland is happy to share the glory. OS Bridge is yet another bulb on the breadboard (aka grid), getting brighter by the day. Speaking of BYTE, I also learned last night that Eliza, our geek therapist, is alive and well in Python, as a part of the Natural Language Toolkit or NLTK. And she's got company. Some of you may recall Hugh Kenner's hilarious investigation of chat bots, then very new, in a way back issue (1980s).[4] Hugh, by the way, was a leading 20th century James Joyce scholar and fan of R. Buckminster Fuller (see 'The Pound Era'), Bucky a champion for me as well (hence my rbf.py -- named after the guy, for use with VPython, POV-Ray, x3d etc., more on edu-sig). I'll catch up again later, maybe from Chicago, maybe before.[5] [0] http://mail.python.org/pipermail/portland/2008-November/000512.html [1] http://radar.oreilly.com/allison/ [2] http://mybizmo.blogspot.com/2009/01/ppug-2009113.html [3] http://worldgame.blogspot.com/2007/06/pro-python-propaganda.html [4] http://mathforum.org/kb/message.jspa?messageID=5256703&tstart=0 [5] http://showmedo.com/videos/video?name=1010050&fromSeriesID=101 [ 2nd edition: reformatted, fixed endnotes ] << with thanks to verizon wireless >> From luke.leighton at googlemail.com Wed Jan 14 16:19:47 2009 From: luke.leighton at googlemail.com (lkcl) Date: Wed, 14 Jan 2009 13:19:47 -0800 (PST) Subject: Mod_python, jsonrpc and sessions References: <1e1eaa10-5e93-4961-9224-ff16ea8e9a93@w24g2000prd.googlegroups.com> Message-ID: <0b82a5b5-5bcb-4c31-a4ff-9a172e2d6590@w1g2000prm.googlegroups.com> On Jan 14, 4:47 pm, p3dda.a... at googlemail.com wrote: > Hi, > > I've got a python web-application being served by apache via > mod_python, in which the users sessions are tracked via the mod_python > Session module. > Some of websites generated contain a java-script function which starts > a jsonrpc call to the same server and gets further data or stores > something to a database (AJAX). The server-sided jsonrpc functions are > written in python as ServiceMethods. > > As I need to identify the user issuing the rpc call, I'm wondering if > there is any possibility to access the session created by the > previosly called mod_python Handler-method. In mod_python it is > accessed using the mod_python request object, but in the rpc > servicemethod I don't have such an object. So how can I track the rpc > caller? the only way to store "session" info reliably is: cookies. therefore, the code in one part of the application _will_ have to store a session cookie as an identifier, and you can track the name of that cookie through the source code that created it. or look in the source code for anything beginning with the word "session". "grep - ril" is your friend. also, if the app stores its session authentication information in a database, you can look through the app for the database table name. if you don't _know_ the database table name, and are having difficulty finding out because the design of the app is SHITE then you can do a dump of the database _before_ a session login, and a dump afterwards, and then diff is your friend. if the database is mysql, add --extended-insert=no (something like that) to the mysqldump command otherwise you will have a bitch-awful job identifying the right line. i've done this when working with fricking-joomla, integrating it with django. fireboard. i had to hunt through the php code looking for the database user-session. once you have the session info, that's your "user tracking" function in the rpc calls. none of the above is particularly rocket science - or actually anything to do with python: it's a simple matter of applying investigative techniques logically working from how the technology _should_ work and then bludgeoning it into submission to tell you what the hell's going on. l. From schap at offenbachers.com Wed Jan 14 16:22:20 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 14 Jan 2009 16:22:20 -0500 Subject: QT4 In-Reply-To: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> References: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> Message-ID: <496E578C.70402@offenbachers.com> Hey, looks like Nokia bought Qt and solved the Open Source/Commercial license issue: http://rss.slashdot.org/~r/Slashdot/slashdot/~3/A4br-rQA460/article.pl I wonder if pyqt will follow suit... -------------- next part -------------- An HTML attachment was scrubbed... URL: From BrooklineTom at gmail.com Wed Jan 14 16:25:25 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Wed, 14 Jan 2009 13:25:25 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <43a3e528-4c28-4618-b44c-0510847758a1@e25g2000vbe.googlegroups.com> > The disadvantage of threads in Python (CPython, actually) is that > there's the GIL (Global Interpreter Lock), so you won't get any speed > advantage if the threads are mostly processor-bound. On a single processor machine with compute-bound threads, I don't the GIL is the bottleneck. No matter how you slice it, there's still only one CPU. It might be interesting to see what it takes to make CPython do something useful with multicore machines, perhaps using approaches similar to that offered by Cilk Arts (http://www.cilk.com). From jstroud at mbi.ucla.edu Wed Jan 14 16:51:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 14 Jan 2009 13:51:53 -0800 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: r wrote: > I actually like the IDLE, but it could use a few improvements. If > anybody else has suggestions by all means post them. > > 1.) The text widget and the prompt(>>>) should be separated. Trying to > write a conditional in the interactive IDLE is a real PITA. Not to > mention if you copy the working code snippet to the IDLE editor window > the indention is 8 spaces instead 4 AND you've got that prompt(>>>) > stuck in there. I have a solution for the problem though.( I hope you > all are using fixed-width font) > > frm |<---------------------text widget -----------------> >>>> | >>>> |if this == 1: > ... | if that == 2: > ... | #do > ... | elif that ==3: > ... | #do > ... | else: > ... | pass >>>> | >>>> |x = 10 Brilliantly put. This is probably the main reason that IDLE is not worth using. Good luck on getting this changed. Best is to find yourself another IDE. Try vim. > Basically you have a Listbox on the left for the prompt and a Text on > the right. Disable the Listbox highlight and key press events and now > we have a very friendly interactive IDLE! No more prompt hijacking > your snippets, and no more 8 space indention! Excellent suggestions are a dime a dozen. Finding people to implement them is slightly harder. Getting said suggestions accepted into the python distribution is nearly impossible. Accept what you are given and try vim. If you really want a cool IDE, try Leo. It had some bugs about 4 years ago when I tried it, but I'm sure they have been worked out now. I'm addicted to vim, but if I wasn't, I'd probably be using Leo. James From fetchinson at googlemail.com Wed Jan 14 17:03:12 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jan 2009 14:03:12 -0800 Subject: python3.0 MySQLdb In-Reply-To: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: >> >>> I need something to connect to a database, preferably mysql, that >> >>> works in python3.0 please. >> >> And your question is? >> >> > Surely it's fairly obvious that the question is "does such a thing >> > exist, and if so where can I find it?". >> >> Interestingly enough, the question was slightly (but importantly) >> different, though: the question really was "Does anybody has a patch for >> MySQLdb?"; as my reference to the existing interface to PostgreSQL >> was not sufficient for the OP. > > Yes it was enough, but I can not imagine it has not been done yet for > MySql either :) Well, this actually is the case: MySql has not been ported. As far as I can see the mysql python module in general (meaning for the 2.x branch) is not as well maintained as some others and questions about windows vs. linux issues periodically come up on the mailing list. So I would not be surprised if porting mysql to the 3.x branch will take longer and will be less well-maintained than other database bindings. > It was a open statement where I expected like 10 different databases > responses. For example if you go to a dinner place you have never been > gone before and want to try something new and there is no menu > available. What do you ask ? You just say something similar. "I would > like to order a salet please with some red wine." I don't think any > one of you would expect the waiter to answer,"And your question is?" I > also think the waiter does not expect me to ask 10 similar questions > like "red wine 1991? red wine 1992? red wine 1993? until i hit > something that is on the menu" > > So the final questions was, is there anything els on the menu besides > PostgreSQL, like MySql for example ? If not I will take PostgreSQL > please. The 3.x branch just as the 2.x branch contains bindings to sqlite. This you can use from day 1, the 3.0 release contains it. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Wed Jan 14 17:05:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 17:05:57 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: ajaksu wrote: > On Jan 14, 5:14 am, Steve Holden wrote: >> ajaksu wrote: >>> [snip evangelism stuff] >> OK, but be aware that the PSF doesn't monitor the bugs looking for >> actions to take on behalf of the Python user community. In fact we >> aren't overtly "political" in this way at all. This doesn't mean it >> wouldn't be useful for the PSF to get involved in this role; just that >> right now it isn't, and a bug report probably isn't the best way to get >> action. > > Acknowledged. I have posted a (pretty poor) support request @ > http://groups.google.com/group/Google-Groups-Basics/ and suggest > others do the same for Wikipedia and other big sites that block 3.0 (I > might build a list of those later today). Maybe a wiki page, some blog > posts, etc. > > Best regards, > Daniel > > Request: http://groups.google.com/group/Google-Groups-Basics/browse_thread/thread/498a39a89d81b650# > """ > Hi, > As mentioned in a comp.lang.python thread[1], the new version of > Python (3.0) cannot open pages @ groups.google.com. > > It seems the UA of Python 3.0 ("User-Agent: Python-urllib/3.1") is > actively blocked, while that of Python 2.5 ("User-Agent: Python-urllib/ > 1.17") isn't. > > This message is a call for help so that we can get Python 3.0 working > with groups.google.com. Is this the right place to bring the issue to > the attention of those that can fix it? Does anyone have a contact > that could speed up getting Python 3.0 working? > > Thanks in advance, > Daniel > > [1]http://groups.google.com/group/comp.lang.python/browse_thread/ > thread/088491d5a0d86f1b > """ Thanks very much. It's good to see Python users taking action that will lead to benefits for all. Congratulations on taking the initiative. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Wed Jan 14 17:08:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:08:39 +0000 Subject: change only the nth occurrence of a pattern in a string In-Reply-To: References: <0scs26-7a5.ln1@rama.fbx.proxad.net> Message-ID: <496E6267.3020006@mrabarnett.plus.com> Antoon Pardon wrote: > On 2008-12-31, TP wrote: >> Hi everybody, >> >> I would like to change only the nth occurence of a pattern in a string. The >> problem with "replace" method of strings, and "re.sub" is that we can only >> define the number of occurrences to change from the first one. >> >>>>> v="coucou" >>>>> v.replace("o","i",2) >> 'ciuciu' >>>>> import re >>>>> re.sub( "o", "i", v,2) >> 'ciuciu' >>>>> re.sub( "o", "i", v,1) >> 'ciucou' >> >> What is the best way to change only the nth occurence (occurrence number n)? >> >> Why this default behavior? For the user, it would be easier to put re.sub or >> replace in a loop to change the first n occurences. > > I would do it as follows: > > 1) Change the pattern n times to somethings that doesn't occur in your string > 2) Change it back n-1 times > 3) Change the remaining one to what you want. > >>>> v="coucou" >>>> v.replace('o', 'O', 2).replace('O', 'o', 1).replace('O', 'i') > 'couciu' > Sorry for the last posting, but it did occur to me that str.replace() could grow another parameter 'start', so it would become: s.replace(old, new[[, start], end]]) -> string (In Python 2.x the method doesn't accept keyword arguments, so that isn't a problem.) If the possible replacements are numbered from 0, then 'start' is the first one actually to perform and 'end' the one after the last to perform. The 2-argument form would be s.replace(old, new) with 'start' defaulting to 0 and 'end' to None => replacing all occurrences, same as now. The 3-argument form would be s.replace(old, new, end) with 'start' defaulting to 0 => equivalent to replacing the first 'end' occurrences, same as now. The 4-argument form would be s.replace(old, new, start, end) => replacing from the 'start'th to before the 'end'th occurrence, additional behaviour as requested. From steve at holdenweb.com Wed Jan 14 17:09:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 17:09:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01n1fc.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Russ P." writes: >> I know some researchers in software engineering who believe that the >> ultimate solution to software reliability is automatic code >> generation. The don't really care much which language is used, because >> it would only be an intermediate form that humans don't interact with >> directly. In that scenario, humans would essentially use a "higher >> level" language such as UML or some such thing. >> >> I personally have a hard time seeing how that could work, but that may >> just be due to be my own lack of understanding or vision. > > The usual idea is that you would write a specificiation, and a > constructive mathematical proof that a certain value meets that > specification. The compiler then verifies the proof and turns it into > code. Coq (http://coq.inria.fr) is an example of a language that > works like that. There is a family of jokes that go: > > Q. How many $LANGUAGE programmers does it take to change a lightbulb? > A. [funny response that illustrates some point about $LANGUAGE]. > > The instantiation for Coq goes: > > Q. How many Coq programmers does it take to change a lightbulb? > A. Are you kidding? It took two postdocs six months just to prove > that the bulb and socket are threaded in the same direction. > > Despite this, a compiler for a fairly substantial C subset has been > written mostly in Coq (http://compcert.inria.fr/doc/index.html). But, > this stuff is far far away from Python. > > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. If I used C instead, > I'd spend several hours writing the one-off program and then 15 > minutes waiting for it to run, which is not exactly better. (Or, I > could spend several hours writing a parallel version of the Python > program and running it on multiple machines, also not an improvement). > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. > > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. I > think the Python community should be aiming towards this. RPython might help, but of course it wouldn't allow you the full language. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From denis.papathanasiou at gmail.com Wed Jan 14 17:11:43 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:11:43 -0800 (PST) Subject: Getting around immutable default arguments for recursion Message-ID: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> I wrote this function to retrieve a list of items from a dictionary. The first time it was called, it worked properly. But every subsequent call returned the results of the prior call, plus the results of the current call. I was confused until I read in the docs that default arguments are immutable. Is there any way around this, to be able to write recursive functions with default arguments? Here's the code: def get_prior_versions (item_id, priors=[]): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: return priors else: priors.append(prior_id) return get_prior_versions(prior_id, priors) From prologic at shortcircuit.net.au Wed Jan 14 17:12:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:12:09 +1000 Subject: Python Crashes In-Reply-To: References: Message-ID: On Thu, Jan 15, 2009 at 6:57 AM, koranthala wrote: > Hi, > I have a twisted based application based on Python 2.4.3. I also > have one thread in this application. > > I found that my program crashes repeatedly after a random interval > (ranging from 10 min to 3 hr). When I say crash, it is not just that > the program dies. Rather in WinXP - a window comes mentioning that > 'Python.exe unexpectedly crashed'. > I tried putting in catching the exception by using try: except - > and logging everything. But the logging code is also not hit, i.e. > even the 'except' code is not hit. I feel that the base python > interpreter itself is crashing due to some bug in my program. > Earlier, I had put code as > try: > except: > log > At this time, my whole machine also froze. It was so slow that > one mouse movement happened after 7-8 minutes after I moved the > mouse. > > Then I modified the code to > try: > except Exception: > log > > Then, the machine no longer freezes. But, still there is no > logging of errors happening too. > > Could anyone guide me on this? I have been facing this issue for a > day, and cannot seem to solve it. > > P.S -> I am not allowed to post the code of application - so I hope > I have explained it enough. Do you use any 3rd party extensions (DLLs) ? cheers James From BrianVanderburg2 at aim.com Wed Jan 14 17:13:31 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Wed, 14 Jan 2009 17:13:31 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Message-ID: <496E638B.90209@aim.com> rt8396 at gmail.com wrote: > Here is a piece of C code this same guy showed me saying Pythonic > indention would make this hard to read -- Well lets see then! > > I swear, before god, this is the exact code he showed me. If you don't > believe me i will post a link to the thread. > > // Warning ugly C code ahead! > if( is_opt_data() < sizeof( long double ) ) { // test for insufficient > data > return TRUE; // indicate buffer empty > } // end test for insufficient data > if( is_circ() ) { // test for circular buffer > if( i < o ) { // test for data area divided > if( ( l - o ) > sizeof( long double ) ) { // test for data > contiguous > *t = ( ( long double * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust out > if( o >= l ) { // test for out wrap around > o = 0; // wrap out around limit > } // end test for out wrap around > } else { // data not contiguous in buffer > return load( ( char * ) t, sizeof( long double ) ); // return > data > } // end test for data contiguous > } else { // data are not divided > *t = ( ( float * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust out > if( o >= l ) { // test for out reached limit > o = 0; // wrap out around > } // end test for out reached limit > } // end test for data area divided > } else { // block buffer > *t = ( ( long double * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust data pointer > } // end test for circular buffer > > I do a bit of C and C++ programming and even I think that is ugly and unreadable. First of all there are 'way' to many comments. Why does he comment every single line. Second of all I've always found that brace/indent style to lead toward harder-to-read code IMHO. I think the Allman style is the most readable followed by perhaps Whitesmiths style. Brian Vanderburg II From LambertDW at Corning.com Wed Jan 14 17:14:17 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Wed, 14 Jan 2009 17:14:17 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Please, why isn't a set permitted as the second argument to isinstance? From prologic at shortcircuit.net.au Wed Jan 14 17:16:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:16:25 +1000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Message-ID: On Thu, Jan 15, 2009 at 8:14 AM, Lambert, David W (S&T) wrote: > Please, why isn't a set permitted as the second argument to isinstance? Care to show us a code sample ? We're not psychic you know... cheers James From excord80 at gmail.com Wed Jan 14 17:21:15 2009 From: excord80 at gmail.com (excord80) Date: Wed, 14 Jan 2009 14:21:15 -0800 (PST) Subject: LGPL license for Qt 4.5 References: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> Message-ID: On Jan 14, 9:20?am, sturlamolden wrote: > > In either case, Qt will be available under the same licensing terms as > wxWidgets. > > As of today, the main reason to prefer wxPython over PyQt is the > license. With an LGPL'd Qt, I'd rather ask what this will mean for > wxPython. wx has a nice community, and is actively developed, FWICT. I've also heard that its maintainer is very responsive. However, my impression is that the main appeal of wx is that it's API is similar to MS Windows MFC (an appeal only for (some) MS Windows developers though) and that it has favorable licensing conditions (like GTK+). Further, I suspect that Pythoneers have been using and recommending it because it's currently the least worst solution. Now that LGPL Qt is very nearly here, I'd say that wxWidgets is going to have a very challenging time ahead. Very challenging. From google at mrabarnett.plus.com Wed Jan 14 17:24:23 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:24:23 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Message-ID: <496E6617.5000205@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > Please, why isn't a set permitted as the second argument to > isinstance? > Do you mean set as a class ("isinstance(s, set)", which is valid) or a set of classes ("isinstance(s, set([str, bytes])", which isn't valid)? From google at mrabarnett.plus.com Wed Jan 14 17:26:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:26:06 +0000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <496E667E.1090603@mrabarnett.plus.com> dpapathanasiou wrote: > I wrote this function to retrieve a list of items from a dictionary. > > The first time it was called, it worked properly. > > But every subsequent call returned the results of the prior call, plus > the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. > > Is there any way around this, to be able to write recursive functions > with default arguments? > > Here's the code: > > def get_prior_versions (item_id, priors=[]): The usual solution is: def get_prior_versions (item_id, priors=None): if priors is None: priors = [] > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > priors.append(prior_id) > return get_prior_versions(prior_id, priors) From skip at pobox.com Wed Jan 14 17:29:17 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 14 Jan 2009 16:29:17 -0600 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: <18798.26429.431192.82340@montanaro.dyndns.org> Daniel> Well, this actually is the case: MySql has not been ported. As Daniel> far as I can see the mysql python module in general (meaning for Daniel> the 2.x branch) is not as well maintained as some others and Daniel> questions about windows vs. linux issues periodically come up on Daniel> the mailing list. So I would not be surprised if porting mysql Daniel> to the 3.x branch will take longer and will be less Daniel> well-maintained than other database bindings. Unless you have direct evidence to the contrary people should take what you wrote with a grain of salt. In my experience Andy Dustman has been quite responsive to inputs about MySQLdb, when those inputs happen in the forum he inhabits. That forum is the MySQL forum tool on SourceForge: http://sourceforge.net/forum/?group_id=22307 If you're curious about MySQLdb on Python 3.0 that is the place to ask. Of course, like all open source software if you provide a patch in the project tracker things will happen faster. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From rt8396 at gmail.com Wed Jan 14 17:29:18 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 14:29:18 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: <292f8c54-9e22-4d20-958b-f32b75f85f4e@p2g2000prf.googlegroups.com> Hello James, I actually want to trash IDLE and start over. I would be willing to do a complete re-write. I have already made a template GUI that works (early stages). I am wondering if anyone else might be interested in taking this on with me? IMO IDLE is full of fluff where it should not be, and thin where it should be fat. Trim off the fat and lean this puppy up! I like that in ActiveState's version you can delete as much text as you want. IDLE won't allow it. I want a better setup for extensions, and complete control of mouse and key bindings for the user. We need to clean the dust off and polish IDLE up a bit. If not, i will just write up a simplified version it for myself. I just thought someone out there may be thinking like i am. From prologic at shortcircuit.net.au Wed Jan 14 17:29:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:29:36 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 8:11 AM, dpapathanasiou wrote: > I wrote this function to retrieve a list of items from a dictionary. > > The first time it was called, it worked properly. > > But every subsequent call returned the results of the prior call, plus > the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. > > Is there any way around this, to be able to write recursive functions > with default arguments? > > Here's the code: > > def get_prior_versions (item_id, priors=[]): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > priors.append(prior_id) > return get_prior_versions(prior_id, priors) How about: def get_prior_versions (item_id, priors=None): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: return priors else: if priors: priors.append(prior_id) else: priors = [prior_id] return get_prior_versions(prior_id, priors) From denis.papathanasiou at gmail.com Wed Jan 14 17:31:19 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:31:19 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: > The usual solution is: > > def get_prior_versions (item_id, priors=None): > if priors is None: > priors = [] Thanks! From denis.papathanasiou at gmail.com Wed Jan 14 17:32:30 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:32:30 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> > How about: > > def get_prior_versions (item_id, priors=None): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > if priors: > priors.append(prior_id) > else: > priors = [prior_id] > return get_prior_versions(prior_id, priors) It's not exactly right for what I'm doing, b/c the caller always expects a list in return. From pavlovevidence at gmail.com Wed Jan 14 17:37:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 14:37:16 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> On Jan 14, 6:57?am, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > For the rest of us, this is fantastic news. > > http://digi.no/php/art.php?id=800922 Is Nokia the making the full Qt toolkit LGPL, or just the parts that were previously GPL? (Can't read Norwegian if it's in the article.) If it's the former Rivebank Computing will be ok, they might even sell more support contracts this way since companies are more likely to use LGPL than GPL software. Carl Banks From bignose+hates-spam at benfinney.id.au Wed Jan 14 17:38:58 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 15 Jan 2009 09:38:58 +1100 Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <87fxjlcy2l.fsf@benfinney.id.au> dpapathanasiou writes: > But every subsequent call returned the results of the prior call, > plus the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. You'll continue to be confused if you use that term. Python already has a specific use of the term ?immutable?, and it doesn't apply here. Better to say: default arguments are part of the function definition statement, and are evaluated when the definition is evaluated. -- \ ?To me, boxing is like a ballet, except there's no music, no | `\ choreography, and the dancers hit each other.? ?Jack Handey | _o__) | Ben Finney From tjreedy at udel.edu Wed Jan 14 17:43:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Jan 2009 17:43:19 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: James Stroud wrote: > r wrote: >> I actually like the IDLE, but it could use a few improvements. If >> anybody else has suggestions by all means post them. >> >> 1.) The text widget and the prompt(>>>) should be separated. Trying to >> write a conditional in the interactive IDLE is a real PITA. Not to >> mention if you copy the working code snippet to the IDLE editor window >> the indention is 8 spaces instead 4 AND you've got that prompt(>>>) >> stuck in there. I have a solution for the problem though.( I hope you >> all are using fixed-width font) >> >> frm |<---------------------text widget -----------------> >>>>> | >>>>> |if this == 1: >> ... | if that == 2: >> ... | #do >> ... | elif that ==3: >> ... | #do >> ... | else: >> ... | pass >>>>> | >>>>> |x = 10 > > Brilliantly put. This is probably the main reason that IDLE is not worth > using. Good luck on getting this changed. Best is to find yourself > another IDE. Try vim. > >> Basically you have a Listbox on the left for the prompt and a Text on >> the right. Disable the Listbox highlight and key press events and now >> we have a very friendly interactive IDLE! No more prompt hijacking >> your snippets, and no more 8 space indention! > > Excellent suggestions are a dime a dozen. Finding people to implement > them is slightly harder. Getting said suggestions accepted into the > python distribution is nearly impossible. Accept what you are given and > try vim. My doc suggestions get accepted regularly, sometimes within hours. I think the 'main' IDLE maintainer is no longer active. I think someone who would do more than fix critical bugs might be welcome. From pavlovevidence at gmail.com Wed Jan 14 17:43:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 14:43:40 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: On Jan 14, 4:14?pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The Python development team might be open to adding it if you were to submit a patch. The use case is fairly obvious. I doubt any of them would respond to a wishlist request, though. As a workaround, you can just cast the set to a tuple like this: isinstance(x,tuple(s)) Carl Banks From prologic at shortcircuit.net.au Wed Jan 14 18:04:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 09:04:07 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 8:32 AM, dpapathanasiou wrote: (...) > It's not exactly right for what I'm doing, b/c the caller always > expects a list in return. How about this then: def get_prior_versions (item_id, priors=None): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: if priors: return priors or [] else: if priors: priors.append(prior_id) else: priors = [prior_id] return get_prior_versions(prior_id, priors) By the way, this is a really badly written function for 2 reasons: a) a global should and need not be used. b) this function could be rewritten without recursion. cheers James From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:07:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:07:41 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> <7x63kh3fya.fsf@ruckus.brouhaha.com> <496e4b97$0$24021$426a34cc@news.free.fr> Message-ID: <017e66cf$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 20:33:01 +0100, Bruno Desthuilliers wrote: > Paul Rubin a ?crit : >> Bruno Desthuilliers >> writes: >>>> I haven't anywhere in this thread as far as I know suggested >>>> eliminating dynamism from Python, >>> Nope, but your suggestion would have the same practical result as far >>> as I'm concerned. >> >> Sorry, I don't comprehend that. > > IIRC, your suggestion was that one should have to explicitely allow > "dynamic binding" (ie: outside the initializer) of new attributes, and > that the default vould be to disallow them. Lots of heat and noise in this discussion, but I wonder, just how often do Python programmers use this dynamism *in practice*? I hardly ever do. I like that it is there, I like that Python is so easy to use without the overhead of Java, but I rarely need *all* the dynamism available. [sweeping generalization] Most objects people use are built-ins, and you can't add attributes to them. I don't think I've ever done subclasses a built-in just to get dynamic attributes: class DynamicInt(int): pass x = DynamicInt(2) x.attribute = "something" As far as non built-in classes go: >>> from decimal import Decimal >>> d = Decimal('0.5') >>> d.something = "something" Traceback (most recent call last): File "", line 1, in AttributeError: 'Decimal' object has no attribute 'something' If I recall correctly, the first implementation of Decimal was written in Python. Did anyone object to Decimal being re-written in C because they missed the ability to add arbitrary attributes to Decimal instances? And if they did, I'm pretty sure the answer given would have been: deal with it. Subclass Decimal, or use delegation. Don't penalise 99% of uses of Decimal for that 1% of uses where you need dynamism. I think that's a wise decision. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:08:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:08:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <017e66e9$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 08:45:46 -0800, Paul Rubin wrote: >> Btw, for performance, there is __slots__, > > That is a good point, we somehow lost sight of that in this thread. > >> with the side-effect that it forbids attribute creation 'on the fly'. > > I have had the impression that this is a somewhat accidental side effect > and shouldn't be relied on. Not accidental, but people complain if you use slots for the purpose of prohibiting attribute creation. They say "That's not what __slots__ was designed for!". That's okay though, computers were designed for breaking Germany ciphers and calculating the trajectory of cannon-shells, but they're not the only things we use computers for these days. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:08:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:08:12 GMT Subject: can someone tell me why this doesn't work please python 3 References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <017e66ee$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 09:45:58 -0800, Dennis Lee Bieber wrote: > Personally -- I'd accept anything that started with the character: > > while True: > password = input(prompt).lower() > if password.startswith("y"): > return True > elif password.startswith("n"): > return False [...] >>> response = input("Shall I delete all your files? ").lower() Shall I delete all your files? Ye gods, NOOO!!!!! >>> if response.startswith('y'): print "Deleting files now" ... Deleting files now There are times where being flexible in what you accept is *not* a virtue. -- Steven From rt8396 at gmail.com Wed Jan 14 18:12:09 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 15:12:09 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> On Jan 14, 4:43?pm, Terry Reedy wrote: [snip] > I think the 'main' IDLE maintainer is no longer active. ?I think someone > who would do more than fix critical bugs might be welcome. Hello Terry, That's what i was beginning to think. I am not quite ready (as far as my skills are concerned) to put out something that would be as useful to many people. I could hack together something real quick for myself. This is why i am looking for like-minded people who would be interested in this. I have the foresight and willpower at this point to contribute something meaningful to the Python community -- to give back. OFF-TOPIC:(but related) What is the state of Tkinter at this point. Is an active effort under way to port TK 8.5 into Python? Tkinter and IDLE are very important to Python, but i understand there are much more important areas where the GURU's are concentrating. Should there be a calling for "others" to get involved here? I would like to help out. Thanks From denis.papathanasiou at gmail.com Wed Jan 14 18:23:10 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 15:23:10 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <87fxjlcy2l.fsf@benfinney.id.au> Message-ID: > You'll continue to be confused if you use that term. Python already > has a specific use of the term ?immutable?, and it doesn't apply > here. I was just following the terminology used in "A Byte of Python" (which, that particular point aside, is a very good tutorial). > Better to say: default arguments are part of the function definition > statement, and are evaluated when the definition is evaluated. Yes, well said. From denis.papathanasiou at gmail.com Wed Jan 14 18:27:01 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 15:27:01 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: > How about this then: > > def get_prior_versions (item_id, priors=None): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > if priors: > return priors or [] > else: > if priors: > priors.append(prior_id) > else: > priors = [prior_id] > return get_prior_versions(prior_id, priors) Without the "if priors:" line just above the first return statement (a typo perhaps?), then yes, it would do what I want. > a) a global should and need not be used. Passing the entire dictionary to every function that accesses it is better? > b) this function could be rewritten without recursion. Right, any recursive function can be written iteratively and vice- versa. I'm not sure that makes it "bad". From prologic at shortcircuit.net.au Wed Jan 14 18:37:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 09:37:14 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 9:27 AM, dpapathanasiou wrote: > Without the "if priors:" line just above the first return statement (a > typo perhaps?), then yes, it would do what I want. Yes sorry it was :) >> a) a global should and need not be used. > > Passing the entire dictionary to every function that accesses it is > better? Yes :) >> b) this function could be rewritten without recursion. > > Right, any recursive function can be written iteratively and vice- > versa. I'm not sure that makes it "bad". No it doesn't necessarily make it bad, but recursion is not necessary here :) What does history_db look like ? I think I can write a much simpler function for you. Also, show me what the results are used for. cheers James From robert.kern at gmail.com Wed Jan 14 18:44:34 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 14 Jan 2009 17:44:34 -0600 Subject: LGPL license for Qt 4.5 In-Reply-To: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> References: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 14, 6:57 am, sturlamolden wrote: >> According to a Norwegian publication, Nokia will release Qt under LGPL >> as of version 4.5. >> >> If I had stocks in Riverbank Computing ltd., I would sell them now... >> >> For the rest of us, this is fantastic news. >> >> http://digi.no/php/art.php?id=800922 > > Is Nokia the making the full Qt toolkit LGPL, or just the parts that > were previously GPL? (Can't read Norwegian if it's in the article.) The "full" Qt toolkit <4.5 is dual-licensed Commercial/GPL, and the "full" Qt toolkit >=4.5 will be Commercial/LGPL/GPL. Trolltech did have a few extra libraries that were just Commercial, IIRC, but these were relatively small. What people usually call "Qt" (i.e. all of the stuff that PyQt wraps) is going to be LGPLed. You can get more information in English at the new Qt site here: http://www.qtsoftware.com/about/licensing -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 18:50:54 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 15:50:54 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496E7A5E.3010308@jpl.nasa.gov> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function >> and run them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables >> of the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces > Join (wait) on them. > > pydoc threading.Thread > > cheers > James What is the proper syntax to use if I wish to return variables from a function run as a thread? For example, how do I implement the following code to return the variable "c" from MyFunc for later use in RunThreads? Trying to return anything from the threading.Thread call results in a "unpack non-sequence" error. import threading, sys def MyFunc(a, b): c = a + b print "c =",c return c def RunThreads(): args = (1,2) threading.Thread(target=MyFunc,args=(1,2)).start() if __name__ == "__main__": RunThreads() sys.exit() From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 18:50:54 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 15:50:54 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496E7A5E.3010308@jpl.nasa.gov> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function >> and run them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables >> of the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces > Join (wait) on them. > > pydoc threading.Thread > > cheers > James What is the proper syntax to use if I wish to return variables from a function run as a thread? For example, how do I implement the following code to return the variable "c" from MyFunc for later use in RunThreads? Trying to return anything from the threading.Thread call results in a "unpack non-sequence" error. import threading, sys def MyFunc(a, b): c = a + b print "c =",c return c def RunThreads(): args = (1,2) threading.Thread(target=MyFunc,args=(1,2)).start() if __name__ == "__main__": RunThreads() sys.exit() From fetchinson at googlemail.com Wed Jan 14 18:55:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jan 2009 15:55:57 -0800 Subject: python3.0 MySQLdb In-Reply-To: <18798.26429.431192.82340@montanaro.dyndns.org> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> <18798.26429.431192.82340@montanaro.dyndns.org> Message-ID: > Daniel> Well, this actually is the case: MySql has not been ported. As > Daniel> far as I can see the mysql python module in general (meaning for > Daniel> the 2.x branch) is not as well maintained as some others and > Daniel> questions about windows vs. linux issues periodically come up on > Daniel> the mailing list. So I would not be surprised if porting mysql > Daniel> to the 3.x branch will take longer and will be less > Daniel> well-maintained than other database bindings. > > Unless you have direct evidence to the contrary people should take what you > wrote with a grain of salt. What I wrote is of course solely my own experience. When I needed to use a database with python I looked around and tried to guess which db binding is the most mature, stable, well-maintained, etc. Meaning, I'd like to have the least amount of compilation/linking problems for both windows and linux and I'd like to have the least amount of runtime problems. I did what I guess anybody would have done: a google search on the main database bindings. From this rather ad hoc research I concluded that mysqldb has more problems than the other major databases. > In my experience Andy Dustman has been quite > responsive to inputs about MySQLdb, when those inputs happen in the forum he > inhabits. I agree with you and I didn't say anything which contradicts your statement. Being very responsive to problems is absolutely compatible with having some problems. > That forum is the MySQL forum tool on SourceForge: > > http://sourceforge.net/forum/?group_id=22307 > > If you're curious about MySQLdb on Python 3.0 that is the place to ask. Of > course, like all open source software if you provide a patch in the project > tracker things will happen faster. Sure, we agree again. But since my impression about the OP's question was that his/her main intention is not really code contribution but rather a solution to use, I'd say this is pretty much irrelevant for the OP. But yes, we agree on how development of open source projects go :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From cs at zip.com.au Wed Jan 14 19:00:23 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Jan 2009 11:00:23 +1100 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E7A5E.3010308@jpl.nasa.gov> Message-ID: <20090115000023.GA26379@cskk.homeip.net> On 14Jan2009 15:50, Catherine Moroney wrote: > James Mills wrote: >> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >> wrote: >>> I would like to spawn off multiple instances of a function >>> and run them simultaneously and then wait until they all complete. [...] >> Try using the python standard threading module. >> Create multiple instances of Thread with target=your_function >> Maintain a list of these new Thread instnaces >> Join (wait) on them. > > What is the proper syntax to use if I wish to return variables > from a function run as a thread? The easy thing is to use a Queue object. The background thread uses .put() to place a computed result on the QUeue and the caller uses .get() to read from the queue. There's an assortment of other ways too. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From http Wed Jan 14 19:02:44 2009 From: http (Paul Rubin) Date: 14 Jan 2009 16:02:44 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> <017e66e9$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xocy9l9ln.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Not accidental, but people complain if you use slots for the purpose of > prohibiting attribute creation. They say "That's not what __slots__ was > designed for!". That's okay though, computers were designed for breaking > Germany ciphers and calculating the trajectory of cannon-shells, but > they're not the only things we use computers for these days. It's hard to figure out from the docs exactly what slots is supposed to do: http://docs.python.org/reference/datamodel.html#id3 I don't think it's good style to rely on accidental, undocumented characteristics of some language feature. But, I may start using slots for some of the stuff I'm doing, just to reduce space consumption and keep more instances around, which is what it's really intended for. From kyrie at uh.cu Wed Jan 14 19:09:54 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 19:09:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01n1fc.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <1231978194.496e7ed213a2b@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. Wait, do you _really_ believe that _static_ checks could prevent problems arising from _unexpected_ conditions in the _data_? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From castironpi at gmail.com Wed Jan 14 19:30:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 16:30:36 -0800 (PST) Subject: reverse dict lookup & Relation class Message-ID: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Hi, this is a continuation of something that comes up now and again about reverse lookups on dictionaries, as well as a follow-up to my pursuit of a Relation class from earlier. For a reverse lookup, you just need two lookups. name= {} phone= {} name[ '555-963' ]= 'Joan' phone[ 'Joan' ]= '555-963' Though maybe the keys in 'name' should be names, instead of the values in it. The variable name doesn't clarify that. (What is more natural to you in reading code? Is one obviously wrong?) phone[ '555-963' ]= 'Joan' name[ 'Joan' ]= '555-963' To provide for non-unique fields, the structure becomes kind of complicated. phone[ '555-963' ]= 'Joan' phone[ '555-964' ]= 'Joan' name[ 'Joan' ]= [ '555-963', '555-964' ] For uniform access, 'phone' can be a dict of strings to lists too. phone[ '555-963' ]= [ 'Joan' ] phone[ '555-964' ]= [ 'Joan' ] To add a third field, the structure becomes again more complicated. Either define a unique key: phone[ '555-963' ]= [ object1 ] phone[ '555-964' ]= [ object2 ] name[ 'Joan' ]= [ object1, object2 ] hourstocall= {} hourstocall[ '9a-5p' ]= [ object1 ] hourstocall[ '5p-11p' ]= [ object2 ] records= {} records[ object1 ]= ( 'Joan', '555-963', '9a-5p' ) records[ object2 ]= ( 'Joan', '555-964', '5p-11p' ) Or, and this is the interesting part, use the ('identificationally') same tuples in both mappings, since the object is only mentioned, not used. phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', '5p-11p' ) ] hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] What's the best way to construct this class? Or, do you have an argument that it could not be simpler than using a relational db? Brainstorming, not flamestorming. From castironpi at gmail.com Wed Jan 14 19:36:25 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 16:36:25 -0800 (PST) Subject: executing multiple functions in background simultaneously References: Message-ID: <8c03b7e0-19c8-4f15-8ffb-aaa8c9c30663@r36g2000prf.googlegroups.com> On Jan 14, 6:00?pm, Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: > > > James Mills wrote: > >> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > >> wrote: > >>> I would like to spawn off multiple instances of a function > >>> and run them simultaneously and then wait until they all complete. > [...] > >> Try using the python standard threading module. > >> Create multiple instances of Thread with target=your_function > >> Maintain a list of these new Thread instnaces > >> Join (wait) on them. > > > What is the proper syntax to use if I wish to return variables > > from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. You could just set the result as an attribute of the thread you're starting (untested): class MyThread(Thread): def run( self ): stuff() self.result= something (Strictly speaking, threads don't return values, since nothing follows them in flow of control.) From clp2 at rebertia.com Wed Jan 14 20:04:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 17:04:38 -0800 Subject: reverse dict lookup & Relation class In-Reply-To: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <50697b2c0901141704k661f8b77sf626d05b41b2efd5@mail.gmail.com> On Wed, Jan 14, 2009 at 4:30 PM, Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. > > For a reverse lookup, you just need two lookups. > name= {} > phone= {} > name[ '555-963' ]= 'Joan' > phone[ 'Joan' ]= '555-963' > > Though maybe the keys in 'name' should be names, instead of the values > in it. The variable name doesn't clarify that. (What is more natural > to you in reading code? Is one obviously wrong?) > > phone[ '555-963' ]= 'Joan' > name[ 'Joan' ]= '555-963' > > To provide for non-unique fields, the structure becomes kind of > complicated. > > phone[ '555-963' ]= 'Joan' > phone[ '555-964' ]= 'Joan' > name[ 'Joan' ]= [ '555-963', '555-964' ] > > For uniform access, 'phone' can be a dict of strings to lists too. > > phone[ '555-963' ]= [ 'Joan' ] > phone[ '555-964' ]= [ 'Joan' ] > > To add a third field, the structure becomes again more complicated. > Either define a unique key: > > phone[ '555-963' ]= [ object1 ] > phone[ '555-964' ]= [ object2 ] > name[ 'Joan' ]= [ object1, object2 ] > hourstocall= {} > hourstocall[ '9a-5p' ]= [ object1 ] > hourstocall[ '5p-11p' ]= [ object2 ] > records= {} > records[ object1 ]= ( 'Joan', '555-963', '9a-5p' ) > records[ object2 ]= ( 'Joan', '555-964', '5p-11p' ) > > Or, and this is the interesting part, use the ('identificationally') > same tuples in both mappings, since the object is only mentioned, not > used. > > phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', > '5p-11p' ) ] > hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. Once you get beyond a main dict (e.g. name2phone) and one that's its inverse (e.g. phone2name), yeah, I'd probably say you should be using a relational DB for this. You could also use objects, but it sounds like you really want to use SQL-like querying, which isn't well-suited to plain objects (though it'd be fine with an ORM). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 20:11:44 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:11:44 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: Message-ID: <496E8D50.4050900@jpl.nasa.gov> Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: >> James Mills wrote: >>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>> wrote: >>>> I would like to spawn off multiple instances of a function >>>> and run them simultaneously and then wait until they all complete. > [...] >>> Try using the python standard threading module. >>> Create multiple instances of Thread with target=your_function >>> Maintain a list of these new Thread instnaces >>> Join (wait) on them. >> What is the proper syntax to use if I wish to return variables >> from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. > > Cheers, Thank you for this hint. This goes a long way to solving my problem. One question - is there any way to name the objects that get put on a queue? For my application, it's important to know which thread put a particular item on the queue. Catherine From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 20:11:44 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:11:44 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: Message-ID: <496E8D50.4050900@jpl.nasa.gov> Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: >> James Mills wrote: >>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>> wrote: >>>> I would like to spawn off multiple instances of a function >>>> and run them simultaneously and then wait until they all complete. > [...] >>> Try using the python standard threading module. >>> Create multiple instances of Thread with target=your_function >>> Maintain a list of these new Thread instnaces >>> Join (wait) on them. >> What is the proper syntax to use if I wish to return variables >> from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. > > Cheers, Thank you for this hint. This goes a long way to solving my problem. One question - is there any way to name the objects that get put on a queue? For my application, it's important to know which thread put a particular item on the queue. Catherine From exarkun at divmod.com Wed Jan 14 20:20:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 14 Jan 2009 20:20:27 -0500 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E8D50.4050900@jpl.nasa.gov> Message-ID: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney wrote: > [snip] >> >>The easy thing is to use a Queue object. The background thread uses >>.put() to place a computed result on the QUeue and the caller uses >>.get() to read from the queue. There's an assortment of other ways too. >> >>Cheers, > >Thank you for this hint. This goes a long way to solving >my problem. > >One question - is there any way to name the objects that get >put on a queue? For my application, it's important to know >which thread put a particular item on the queue. There's lots and lots of ways. The simplest might be to put two-tuples of the thread identifier and some other object. eg queue.put((threadID, obj)) Perhaps you can accomplish your goal that way, or perhaps a minor variation would be more suitable. Jean-Paul From joe at socallinuxexpo.org Wed Jan 14 20:31:35 2009 From: joe at socallinuxexpo.org (joe at socallinuxexpo.org) Date: Wed, 14 Jan 2009 17:31:35 -0800 (PST) Subject: Invitation for Python at the Southern California Linux Expo Message-ID: <45582.206.211.148.69.1231983095.squirrel@socallinuxexpo.org> Greetings, I would like to invite the Python project to attend the 7th Southern California Linux Expo. The show will be held February 20th-22nd, 2009 at the Westin LAX in Los Angeles, CA. SCALE 7x will be an excellent venue to increase awareness and showcase the work of the Python community. Each project will have some room in the zone on the show floor. This will include all the usual amenities: a 6' table, chairs, a 500W power drop, one Ethernet drop and 3-5 complementary passes to the show. I am including our application for dotORG exhibitors, if anyone is down in the Southern California area, and would like to set up a booth, I encourage you to apply. Any questions, please do not hesitate to ask. Thanks for your time! Joe Smith http://scale7x.socallinuxexpo.org/conference-info/call-for-dotorg-exhibitors From catherine.m.moroney at jpl.nasa.gov Wed Jan 14 20:31:48 2009 From: catherine.m.moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:31:48 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> References: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> Message-ID: <93E91E25-9F4C-4A11-ACE4-3BEEFDE94813@jpl.nasa.gov> On Jan 14, 2009, at 5:20 PM, Jean-Paul Calderone wrote: > On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney > wrote: >> [snip] >>> >>> The easy thing is to use a Queue object. The background thread uses >>> .put() to place a computed result on the QUeue and the caller uses >>> .get() to read from the queue. There's an assortment of other >>> ways too. >>> >>> Cheers, >> >> Thank you for this hint. This goes a long way to solving >> my problem. >> >> One question - is there any way to name the objects that get >> put on a queue? For my application, it's important to know >> which thread put a particular item on the queue. > > There's lots and lots of ways. The simplest might be to put two- > tuples > of the thread identifier and some other object. eg > > queue.put((threadID, obj)) > > Perhaps you can accomplish your goal that way, or perhaps a minor > variation would be more suitable. I just came to that conclusion myself and a short test shows that things are working. Thanks to all who contributed to this discussion. Even though I'm by no means an expert, at least I can work with threads and queues now! I love this language ... > > Jean-Paul Catherine From prologic at shortcircuit.net.au Wed Jan 14 20:39:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 11:39:05 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D39A4.2030406@jpl.nasa.gov> References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: Speaking of Threading .. http://codepad.org/dvxwAphE Just a really interesting way of doing this :) cheers James -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Jan 14 20:53:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 11:53:37 +1000 Subject: process/thread instances and attributes Message-ID: Hey all, I have this concept I'm working on and here is the code... Problem is if you run this it doesn't terminate. I believe you can terminate it in the main process by calling a.stop() But I can't find a way for it to self terminate, ie: self.stop() As indicated by the code... ---------------------------------------- #!/usr/bin/env python import os from time import sleep from threading import Thread as _Thread from multiprocessing import Process as _Process class Process(object): def __init__(self, *args, **kwargs): super(Process, self).__init__(*args, **kwargs) self.running = False self.process = _Process(target=self._run) def _run(self): thread = _Thread(target=self.run) thread.start() try: while self.running and thread.isAlive(): try: sleep(1) print "!" except SystemExit: self.running = False break except KeyboardInterrupt: self.running = False break finally: thread.join() def start(self): self.running = True self.process.start() def run(self): pass def stop(self): print "%s: Stopping ..." % self self.running = False class A(Process): def run(self): while self.running: sleep(5) self.stop() a = A() a.start() while a.running: sleep(1) print "." print "DONE" ---------------------------------------- cheers James -- -- "Problems are solved by method" From google at mrabarnett.plus.com Wed Jan 14 20:54:49 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 01:54:49 +0000 Subject: reverse dict lookup & Relation class In-Reply-To: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <496E9769.90808@mrabarnett.plus.com> Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. > > For a reverse lookup, you just need two lookups. > name= {} > phone= {} > name[ '555-963' ]= 'Joan' > phone[ 'Joan' ]= '555-963' > > Though maybe the keys in 'name' should be names, instead of the > values in it. The variable name doesn't clarify that. (What is more > natural to you in reading code? Is one obviously wrong?) > > phone[ '555-963' ]= 'Joan' > name[ 'Joan' ]= '555-963' > Consider "str(x)". It isn't saying "x is a string", it's saying "x as a string". Similarly, "ord(x)" says "the ordinal value of x". So, "phone[x]" means "the phone number of x". [snip] > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. > You could imagine an object where you provide a field name and a value and it returns all those entries where that field contains that value. That, basically, is a database. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 21:02:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 02:02:57 GMT Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 15:27:01 -0800, dpapathanasiou wrote: >> a) a global should and need not be used. > > Passing the entire dictionary to every function that accesses it is > better? Yes. There is very little overhead when passing objects to functions in Python. There's no performance penalty to passing objects instead of relying on globals, and it may in fact be marginally faster: >>> D = {'parrot': None} >>> >>> def byargument(d): ... return d ... >>> def byglobal1(): ... return D ... >>> def byglobal2(): ... global D ... return D ... >>> >>> from timeit import Timer >>> setup = "from __main__ import byargument, byglobal1, byglobal2, D" >>> t1 = Timer('result = byargument(D)', setup) >>> t2 = Timer('result = byglobal1()', setup) >>> t3 = Timer('result = byglobal2()', setup) >>> >>> min(t1.repeat()) 0.23665285110473633 >>> min(t2.repeat()) 0.23789191246032715 >>> min(t3.repeat()) 0.23757314682006836 -- Steven From http Wed Jan 14 21:22:15 2009 From: http (Paul Rubin) Date: 14 Jan 2009 18:22:15 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Wait, do you _really_ believe that _static_ checks could prevent problems > arising from _unexpected_ conditions in the _data_? The data does not arrive from outer space on a magtape stapled to a meteor. It comes out of another program. Most of the problems in processing it come from mismatches between the processing programs and the generation programs. Static checks would help eliminate those mismatches. From wuwei23 at gmail.com Wed Jan 14 21:24:02 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 18:24:02 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: dpapathanasiou wrote: > Passing the entire dictionary to every function that accesses it is > better? If there are a large number of functions, you could combine them and the history_db dict into a single object. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 21:24:09 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 02:24:09 GMT Subject: initialising a class by name References: Message-ID: On Wed, 14 Jan 2009 13:53:52 +0530, Krishnakant wrote: > Hi steevan, > I liked this idea of dispatchTable. > is it possible to say some thing like inst = dispatchTable{"ham"} > according to me, inst will become the instance of class ham. Yes, that works, provided you fix the syntax. (You used {} instead of square brackets.) There's nothing special about dispatching: you look up the dict with a key, and that returns a class. You then call that class to create a class instance as if you were calling it directly by name. > Another > thing to note is that all the classes are in different modules. So where > do I create the dict of classes mapped with the name? That's up to you. -- Steven From MLThornton at gmail.com Wed Jan 14 21:28:18 2009 From: MLThornton at gmail.com (MLT) Date: Wed, 14 Jan 2009 18:28:18 -0800 (PST) Subject: General direction Message-ID: Hello all: I'm a beginner to Python (and programming altogether), and am now looking to create a program of my own. What I've got in mind is a very basic pest control program that would keep track of 1) trap findings and 2) pesticides. My thought is to make each of these classes. Looking at the general outline written below, can anyone give general impression about whether I'm somewhat going in the right direction or if I need to approach it entirely differently? Thanks for any suggestions or help! Class Insect_Trapping attributes: - Unique Name - Location - Type - Frequency of Checks? - Next Check Date Within Insect_Trapping there are Trap_Count objects Trap_Count objects have the following attributes: - Date - Time - Insect A Finds - Insect B Finds - Insect C Finds - Insect A Number - Insect B Number - Insect C Number Class Pesticides attributes: - Unique Name - Usage Instructions Within Pesticide there are Pesticide_Usage objects Pesticide_Usage objects have the following attributes: - Date - Time - Location - Reason for Use - Amt Used From wuwei23 at gmail.com Wed Jan 14 21:56:40 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 18:56:40 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> On Jan 15, 5:16?am, Paul Rubin wrote: > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. Paul, have you looked into Cython at all? I've only used it trivially but it does seem to provide the potential for static typing & improve compile time checking (as well as increased performance) while retaining as Pythonic a representation as possible. From LambertDW at Corning.com Wed Jan 14 22:03:37 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Wed, 14 Jan 2009 22:03:37 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. From http Wed Jan 14 22:06:03 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:06:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> Message-ID: <7xwscx6zfo.fsf@ruckus.brouhaha.com> alex23 writes: > Paul, have you looked into Cython at all? I've only used it trivially > but it does seem to provide the potential for static typing & improve > compile time checking (as well as increased performance) while > retaining as Pythonic a representation as possible. I haven't. Maybe I should. I've looked at Pyrex and PyPy. I've spent quite a bit of time over the past year or so studying Haskell, which has been very educational and worthwhile, but not all that useful for my day-to-day tasks in the present state of things. I just looked up Cython and see that it's based on Pyrex. Worth knowing about, I guess; but basically I think C is evil. I may start looking into Pig Latin (http://wiki.apache.org/pig) for these large data crunching tasks. Unfortunately it is written in Java and my attitude towards Java is probably the one typical of Python programmers, if you know what I mean. From prologic at shortcircuit.net.au Wed Jan 14 22:11:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 13:11:51 +1000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: On Thu, Jan 15, 2009 at 1:03 PM, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. What's wrong with: >>> a = "" >>> b = bytes() >>> any([isinstance(a, x) for x in {str, bytes}]) True >>> any([isinstance(b, x) for x in {str, bytes}]) True >>> cheers James From http Wed Jan 14 22:12:16 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:12:16 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> <496e4e2e$0$10088$426a34cc@news.free.fr> Message-ID: <7xsknl6z5b.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > We're not talking about libraries here. > > Yes we are. If the default is "non-dynamic", then a class author is in > charge of explicitely allowing it when *he* see fits. Oh, I see what you mean, the standard libraries would be affected if the language default were to tone down the dynamism. True. > As long as it's up to the *user* to choose, that's ok. Your "@dynamic" > class decorator doesn't have the same implications. Well, you could use it on library classes too: from library import Libclass Libclass = dynamic(Libclass) ... would be like using the decorator on the class definition. From http Wed Jan 14 22:29:26 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:29:26 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: <7xeiz5xn55.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > But, the research on the language "Self" shows that even in the face > of a language with more dynamism than Smalltalk (or Python), performance > can be obtained using compiler technology. It turns out you don't have > to type those type any extra keystrokes. Compilers capable of doing > strong optimization already have to do enough analysis that they can > discover the static typing that is available in the code you write > naturally. The way to get to such performance on Python is through > efforts like PyPy. I'd be interested in seeing any publications about that Self research, which I remember someone else mentioning in another thread as well. However, part of the idea of the extra keystrokes is to allow the compiler (or an external tool like Pylint) to flag any type-inconsistency for closer programmer inspection, instead of just quietly treating it as dynamic and generating the extra code for it. The keystrokes let the tool know exactly when the dynamism is intentional. As has been mentioned a few times already, Python 3.0 has some rudimentary features for type annotation, so this concept isn't completely anathema to the Python developers. From http Wed Jan 14 22:37:37 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:37:37 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <7xiqohqlxa.fsf@ruckus.brouhaha.com> "James Mills" writes: > In fact, Python borrows features from the Functional Paradigm. Does > this make it a Functional Language ? No. Why ? Because one of the > clear requirements of the Functional Paradigm is that functions > cannot have side affects. I'd say functional programming emphasizes a style that avoids use of side effects, but saying "functions cannot have side effects" is a bit of an overstatement. Even Haskell lets you code effectfully when necessary, using the type system (IO Monad) to separate effectful code from pure code. From rhodri at wildebst.demon.co.uk Wed Jan 14 22:42:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:42:08 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 09:09:37 -0000, Russ P. wrote: > Yes, that would indeed be nice. I am certainly not the only one who > could use a language that is excellent for both research prototyping > *and* the final, safety-critical system. Then perhaps the prototype > could just be cleaned up and "hardened" for the end product rather > than rewritten in another language -- by programmers in another state > who may fail to understand many of the details that the prototype > developer agonized over. You should always plan on throwing away your prototype anyway (though few people do), because *something* in the architecture will turn out to be not what you thought. And if the programmers in the other state fail to understand the details, maybe the developer should have documented a whole lot more (he says through gritted teeth, having had the original code as the sole documentation far too many times). We return you to your regularly scheduled original point... -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 14 22:45:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:45:41 -0000 Subject: problem calling method In-Reply-To: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> References: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> Message-ID: On Wed, 14 Jan 2009 10:54:21 -0000, wrote: > The parent is called like this (I didn't copy that line): > > def __init__(self, *args, **kwds): > # begin wxGlade: MyFrame.__init__ > kwds["style"] = wx.DEFAULT_FRAME_STYLE > wx.Frame.__init__(self, *args, **kwds) > > The frame works fine and so does the button, but somehow I cannot call > the sendmail method from the event handler... > > -- James Mills wrote : > On Wed, Jan 14, 2009 at 11:28 AM, wrote: >> class MyFrame(wx.Frame): >> def __init__(self, *args, **kwds): > > It might be helpful here if you called > the parent __init__. Like so: > > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): > super(MyFrame, self).__init__(*args, **kwargs) 1. Please don't top-post. It makes the thread of discussion really hard to follow. 2. You've over-snipped now; could you repost the MyFrame class without oversimplifying it? It would make it a lot easier to see what's going on. 3. There is no point 3. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 14 22:46:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:46:45 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01x2w3.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 14 Jan 2009 16:34:36 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Terry Reedy writes: >> The question is where such checks should be. Guido prefers separate >> checkers (PyChecker, PyLint) rather than in the interpreter. > Again, there have to be some language extensions to communicate the > necessary info to the external tool. Or, dare one say it, conventions? -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 14 22:53:08 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:53:08 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xy6xd444b.fsf@ruckus.brouhaha.com> "Russ P." writes: > I started looking at Scala a while back. It is has many nice features. > It seamlessly combines object orientation with advanced functional > programming. It is statically typed, but the types often do not need > to be explicitly declared. It is fully "compatible" with Java, but > (like Python) it is much less verbose and more elegant, typically > requiring less (in some cases, much less) than half the lines of code > for a given task. I haven't examined Scala closely at all; my mile-high view was that it was very ugly and closely bound to Java and that the main reason for finding it interesting would be to interoperate with Java programs in a JVM. Since I didn't care about that, I didn't pursue Scala further. > But I am reluctant to use Scala for several reasons. For example, it > doesn't have "continue" and "break." The Scala folks claim they are > unnecessary, but they are sure handy sometimes. Maybe my style is bad, > but I use continue and break a lot, particularly continue. Getting by > without them could be hard. The other thing is that Scala has no > default arguments and no argument passing by keyword. Those are a > couple of my favorite Python features. So I'm basically screwed. I think in functional programming, "continue" and "break" lose some of their importance since you normally don't code any loops at all (you express iteration in terms of functions like "map"). Anyway, you might look at Haskell, although it has its own weirdness. This old paper might be of interest: http://www.haskell.org/papers/NSWC/jfp.ps From http Wed Jan 14 22:54:02 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:54:02 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> Message-ID: <7xtz81442t.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > > Again, there have to be some language extensions to communicate the > > necessary info to the external tool. > > Or, dare one say it, conventions? If the language-tool combo uses the info in a formal way, they are extensions, not conventions. From http Wed Jan 14 23:28:12 2009 From: http (Paul Rubin) Date: 14 Jan 2009 20:28:12 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xbpu9kxb7.fsf@ruckus.brouhaha.com> Steve Holden writes: > Sometimes I just want to shout "be quiet, Python is just fine the way it > is", but alas your objections are usually too sensible to be dismissed > in that way. In the long term I feel it has to be good for Python that > it has such conscientious critics. Thanks for the kind words. But I'm not aiming to be a conscientious critic; I'm just an everyday user who sometimes has to grapple with the limitations of the tool, and look for ways around them. From cs at zip.com.au Wed Jan 14 23:33:06 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Jan 2009 15:33:06 +1100 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E8D50.4050900@jpl.nasa.gov> Message-ID: <20090115043306.GA4593@cskk.homeip.net> On 14Jan2009 17:11, Catherine Moroney wrote: > Cameron Simpson wrote: >> On 14Jan2009 15:50, Catherine Moroney wrote: >>> James Mills wrote: >>>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>>> wrote: >>>>> I would like to spawn off multiple instances of a function >>>>> and run them simultaneously and then wait until they all complete. >> [...] >>>> Try using the python standard threading module. >>>> Create multiple instances of Thread with target=your_function >>>> Maintain a list of these new Thread instnaces >>>> Join (wait) on them. >>> What is the proper syntax to use if I wish to return variables >>> from a function run as a thread? >> >> The easy thing is to use a Queue object. The background thread uses >> .put() to place a computed result on the QUeue and the caller uses >> .get() to read from the queue. There's an assortment of other ways too. >> >> Cheers, > > Thank you for this hint. This goes a long way to solving > my problem. > > One question - is there any way to name the objects that get > put on a queue? For my application, it's important to know > which thread put a particular item on the queue. Give each thread an id (eg give it a name when you create it, and keep track). Instead of going: queue.put(value) go: queue.put((threadname,value)) and at the main program: threadname, value = queue.get() You're still put()ing a single value, it just happens to be a tuple of (threadname, value). You don't even need to use a name (and thus need to backtrack through some name->object dictionary). If every thread has some object for its state you can use the object instead of the threadname. Then you've got direct access to the thread object. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From rfritz at u.washington.edu Wed Jan 14 23:34:41 2009 From: rfritz at u.washington.edu (R Fritz) Date: Wed, 14 Jan 2009 20:34:41 -0800 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Raps cane on floor. It's probably an "end-of-file" sentinel because 'Z' is the last letter of the alphabet. I suspect it comes from MIT. Unix, developed at a telephone company, uses \x4, which was, in fact, the ASCII in-band end-of-transmission code and would disconnect a teletype. Does this qualify me for the dinosaur award? R Fritz On 2009-01-14 07:15:33 -0800, Mel said: > Steve Holden wrote: >> Unknown wrote: >>> On 2009-01-12, John Machin wrote: >>>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>>> file size as number of 128-byte sectors, forcing the use of an in-band >>>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>>> decades after people stopped writing Ctrl-Z at the end of text files. > >>> I believe that "feature" was inherited by CP/M from DEC OSes >>> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >>> (including the FCB) was lifted almost directly from DEC's >>> PDP-11 stuff, which probably copied it from PDP-8 stuff. >>> Perhaps in the early 60's somebody at DEC had a reason. The >>> really interesting thing is that we're still suffering because >>> of it 40+ years later. > >> I suspect this is probably a leftover from some paper tape data formats, >> when it was easier to detect the end of a file with a sentinel byte than >> it was to detect run-off as end of file. It could easily date back to >> the PDP-8. > > Perhaps, although in ASCII it's the SUB symbol: "A control character that is > used in the place of a character that is recognized to be invalid or in > error or that cannot be represented on a given device." [Wikipedia]. There > were other codes defined for End-of-Text and File-Separator. Unless the > protocol were one of DEC's own. The fact that it's > Ctrl-last-letter-of-the-alphabet makes me suspect that it was picked in a > pretty informal way. > > Mel. From Russ.Paielli at gmail.com Wed Jan 14 23:50:23 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 20:50:23 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 7:37?pm, Paul Rubin wrote: > "James Mills" writes: > > In fact, Python borrows features from the Functional Paradigm. Does > > this make it a Functional Language ? No. Why ? Because one of the > > clear requirements of the Functional Paradigm is that functions > > cannot have side affects. > > I'd say functional programming emphasizes a style that avoids use > of side effects, but saying "functions cannot have side effects" is > a bit of an overstatement. ?Even Haskell lets you code effectfully > when necessary, using the type system (IO Monad) to separate > effectful code from pure code. I think we need to distinguish here between purely functional languages and a languages that support functional programming. I would be even more averse to a purely functional language than I am to a purely OO language such as Java. One feature of Ada that I always thought was a good idea is the distinction between functions and procedures, where functions are guaranteed to not have side effects. But I don't think Ada allows advanced functional programming such as passing functions as arguments to other functions. Scala combines advanced functional and OO programming very nicely as far as I can tell (I've read some about it but haven't used it yet). I don't think it distinguishes between functions and procedures, but it does allow you to declare function arguments as "val" (value) or "var" (variable), where the former cannot be modified. If Scala only had default arguments and argument passing by keyword (and maybe "continue" and "break"), I think it would be *very* hard to beat for a very wide range of applications. From prologic at shortcircuit.net.au Thu Jan 15 00:04:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 15:04:16 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Thu, Jan 15, 2009 at 2:50 PM, Russ P. wrote: (..) > One feature of Ada that I always thought was a good idea is the > distinction between functions and procedures, where functions are > guaranteed to not have side effects. But I don't think Ada allows > advanced functional programming such as passing functions as arguments > to other functions. Russ please do your research before you post. The whole idea of the Functional Paradigm is _in fact_ computing expressions and functions. Functional Programming is an implementation of formal systems (calculus). Therefore it would be very useless for any functional language to not do what you describe aboave. Passing the result of a function as input to another function _is not_ Advanced Functional Programming, but a requirement of the functional paradigm. --JamesMills From sjmachin at lexicon.net Thu Jan 15 00:10:27 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 21:10:27 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <24eecd3a-0ca7-4255-8a1f-8f1950a5a0e0@i18g2000prf.googlegroups.com> On Jan 15, 2:03 pm, "Lambert, David W (S&T)" wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. In the anticipated/usual use case (the type/class names are hard- coded): * order is a very mild plus (you can list them in descending order of (imagined) probability) * immutability is not a problem * the number of items is not likely to be so large that duplicate entries would creep in > A set is most reasonable in a mathematical sense. This is true -- distinguishing carefully between "most reasonable" and "the most reasonable" :-) Do you actually have a use case for dynamically assembling a collection of classes/types for use with isinstance(), or are you propelled solely by mathematical reasonableness? Cheers, John From http Thu Jan 15 00:19:58 2009 From: http (Paul Rubin) Date: 14 Jan 2009 21:19:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: <7xy6xd6t8h.fsf@ruckus.brouhaha.com> "Russ P." writes: > I think we need to distinguish here between purely functional > languages and a languages that support functional programming. I would > be even more averse to a purely functional language than I am to a > purely OO language such as Java. I guess I'm not sure what you're considering "purely functional language" to mean, in this context. Haskell has a print function that prints on the terminal. It's "purely functional" in the sense that it conceptualizes an expression like 'print "hello"' as a "state transformer function" that takes as input a state of the world in which your screen is blank, and returns as output a state in which your screen has "hello" on it. Your program constructs this state transformer, and then the runtime system applies the transformer to the external world and presto, "hello" appears on your screen. But that is just the metaphysics of it. Normally in practical usage, you'd think of the print function as something you use more or less the way you'd use it in Python, except that you can only use it in functions with IO in their type. > One feature of Ada that I always thought was a good idea is the > distinction between functions and procedures, where functions are > guaranteed to not have side effects. But I don't think Ada allows > advanced functional programming such as passing functions as arguments > to other functions. Well, Haskell uses its type system to encapsulate functions with side effects. If you want to open a file or print something, you can only do it from a function with IO in its type. Similarly, if you want to do the equivalent of assigning a new value to a variable, you have to use a special type for that purpose, and the type isolates any code that can affect that variable, etc. I think that generalizes what you're describing about Ada. It's actually very beautiful but takes some getting used to. > If Scala only had default arguments and argument passing by keyword > (and maybe "continue" and "break"), I think it would be *very* hard to > beat for a very wide range of applications. I guess I don't understand the issue about continue and break, since if Scala is anything like Haskell, the issue doesn't really arise. Haskell doesn't have keyword args per se, but there are various ways of simulating them, at least for the usual sorts of applications. Anyway, Haskell is quite a bit more formal than Python, and it doesn't yet have as much library support for everyday tasks, and generally suffers from the not-always-practical priorities of being a "research" language, but some people have switched to it from Python. I personally find Haskell very interesting but too difficult in some aspects, and lacking in "creature comforts" compared with Python. I liked Tim Sweeney's talk about where he thinks PL design should go: http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf From leith at leithalweapon.geek.nz Thu Jan 15 00:21:42 2009 From: leith at leithalweapon.geek.nz (leith at leithalweapon.geek.nz) Date: Wed, 14 Jan 2009 21:21:42 -0800 (PST) Subject: SOAPpy under Python 2.6 Message-ID: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> I am having problems with SOAPpy after we upgraded to Python 2.6 Here is the exception I keep getting: File "C:\Dev\Phoenix\SAPI.py", line 2561, in getSystemInfo obj = self.soapProxy.getSystemInfo() File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 492, in __r_call self.__hd, self.__ma) File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 363, in __call config = self.config) TypeError: call() got multiple values for keyword argument 'encoding' Could some please help me with this? I don't have the faintest idea what the exception is on about and SOAPpy\Client.py is very hard to follow. Leith Bade From coolaj86 at gmail.com Thu Jan 15 00:25:05 2009 From: coolaj86 at gmail.com (Alvin ONeal) Date: Wed, 14 Jan 2009 22:25:05 -0700 Subject: Open Source Software in the Government Message-ID: I thought it might be useful to know that if an idea gets enough votes on Obama's site, he (supposedly) reviews it. Here are the ideas related to open source software. http://citizensbriefingbook.change.gov/search/SearchResults?str=open+source&search.x=0&search.y=0&search=Submit I hope that that is something that you all find helpful, regardless of your political orientation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 15 00:32:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 00:32:47 -0500 Subject: SOAPpy under Python 2.6 In-Reply-To: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> References: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> Message-ID: leith at leithalweapon.geek.nz wrote: > I am having problems with SOAPpy after we upgraded to Python 2.6 > > Here is the exception I keep getting: > > File "C:\Dev\Phoenix\SAPI.py", line 2561, in getSystemInfo > obj = self.soapProxy.getSystemInfo() > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 470, in > __call__ > return self.__r_call(*args, **kw) > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 492, in > __r_call > self.__hd, self.__ma) > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 363, in > __call > config = self.config) > TypeError: call() got multiple values for keyword argument 'encoding' > > Could some please help me with this? > > I don't have the faintest idea what the exception is on about and > SOAPpy\Client.py is very hard to follow. As for the error: IDLE 3.0 >>> def f(a): pass >>> f(a=2,a=3) SyntaxError: keyword argument repeated (, line 1) >>> f(2,a=3) Traceback (most recent call last): File "", line 1, in f(2,a=3) TypeError: f() got multiple values for keyword argument 'a' I therefore suspect that this line return self.__r_call(*args, **kw) gave 'encoding' both positionally in args and nominally in kw. But then I would expect that to be the end of the traceback. From michele.simionato at gmail.com Thu Jan 15 00:34:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:34:11 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <5c8bf7bd-2e89-49d7-9622-2549059600f3@n33g2000pri.googlegroups.com> On Jan 14, 8:16?pm, Paul Rubin wrote: > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. ?I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. I know the feeling. The worse thing is when you have a stupid typo (which would be immediately caught by a compiler) which affects a section of the code that runs after 8 hours of computations. Pylint helps - when you remember torun it on all your code base - but it is definitely not the same as a compiler. > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. ?I > think the Python community should be aiming towards this. Dunno. Python has been designed from the start to be fully dynamic and with no type checks, I don't think it is really possible to change that. On the other hand, one could envision a Python-like language with more type safety (there are already a few experiments in that direction). Personally, I would be glad to trade some flexibility for additional safety; if you we get more speed as an additional bonus, that's fine too. From koranthala at gmail.com Thu Jan 15 00:36:25 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 14 Jan 2009 21:36:25 -0800 (PST) Subject: Python Crashes References: Message-ID: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> On Jan 15, 3:12?am, "James Mills" wrote: > On Thu, Jan 15, 2009 at 6:57 AM, koranthala wrote: > > Hi, > > ? ?I have a twisted based application based on Python 2.4.3. I also > > have one thread in this application. > > > ? ?I found that my program crashes repeatedly after a random interval > > (ranging from 10 min to 3 hr). When I say crash, it is not just that > > the program dies. Rather in WinXP - a window comes mentioning that > > 'Python.exe unexpectedly crashed'. > > ? ?I tried putting in catching the exception by using try: except - > > and logging everything. But the logging code is also not hit, i.e. > > even the 'except' code is not hit. I feel that the base python > > interpreter itself is crashing due to some bug in my program. > > ? ?Earlier, I had put code as > > try: > > except: > > ?log > > ? ? At this time, my whole machine also froze. It was so slow that > > one mouse movement happened after 7-8 minutes after I moved the > > mouse. > > > Then I modified the code to > > try: > > except Exception: > > ?log > > > ? ?Then, the machine no longer freezes. But, still there is no > > logging of errors happening too. > > > ? ?Could anyone guide me on this? I have been facing this issue for a > > day, and cannot seem to solve it. > > > P.S -> ? ?I am not allowed to post the code of application - so I hope > > I have explained it enough. > > Do you use any 3rd party extensions (DLLs) ? > > cheers > James I am using 9 3rd party modules and there are some DLLs too - PIL etc. But the problem is that the issue comes only after 3 hrs usually. When I checked the memory using taskmanager, I found that it is not going too high. Is there any tool or anything which will help me debug this? From Russ.Paielli at gmail.com Thu Jan 15 00:36:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 21:36:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 9:04?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 2:50 PM, Russ P. wrote: > > (..) > > > One feature of Ada that I always thought was a good idea is the > > distinction between functions and procedures, where functions are > > guaranteed to not have side effects. But I don't think Ada allows > > advanced functional programming such as passing functions as arguments > > to other functions. > > Russ please do your research before you post. Please spare me the pedantry. > The whole idea of the Functional Paradigm is _in fact_ computing > expressions and functions. Functional Programming is an implementation > of formal systems (calculus). Therefore it would be very useless > for any functional language to not do what you describe aboave. So what? > Passing the result of a function as input to another function > _is not_ Advanced Functional Programming, but a requirement > of the functional paradigm. Oh, excuse me for misusing the word "advanced." I was merely using it to distinguish it from programming without side effects, which I would regard as more "basic" functional programming. But then I'm not as sophisticated as you. By the way, your statements earlier to the effect that Python is as good as any language for large-scale safety-critical systems were very interesting. I'm wondering how you "know" that. Also, have you checked with Boeing or ARINC on that? Last I heard, those neanderthals at ARINC are still suporting Ada as the standard language for flight systems. I urge you to get in touch with them and straighten them out right away. From tjreedy at udel.edu Thu Jan 15 00:40:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 00:40:12 -0500 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. I agree. However, isinstance predates set. Hence the status quo. From michele.simionato at gmail.com Thu Jan 15 00:41:14 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:41:14 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> Message-ID: <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> On Jan 12, 10:58?pm, Paul Rubin wrote: > We are in an era for programming languages sort of like the Windows 95 > era was for operating systems, where everything is broken but some of > the fixes are beginning to come into view. ?So there is no language > that currently really works the right way, but some of them including > Python are (one hopes) moving in good directions. To be fair, this has been true for the last 50 years. If a language that works the right way really existed, CS would be dead and there would be no progress to make. Happily I think we will never end in that situation ;) From Russ.Paielli at gmail.com Thu Jan 15 00:45:52 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 21:45:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 9:04?pm, "James Mills" wrote: Oh, by the way, please quit emailing me every time you reply to one of my posts. You're the only one here who does that, and it isn't necessary. Thanks. From michele.simionato at gmail.com Thu Jan 15 00:51:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:51:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> On Jan 13, 2:48?am, "Russ P." wrote: > I started looking at Scala a while back. It is has many nice features. > It seamlessly combines object orientation with advanced functional > programming. I don't like that. Scala was designed with the idea of putting together the two worlds, by I think the result was to get the complications of both worlds. I don't think a SML-like functional language needs to be integrated with object orientation, it is fine just without it. The old quote applies: """ Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make additional features appear necessary. -- William Clinger """ From rhodri at wildebst.demon.co.uk Thu Jan 15 00:56:12 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 05:56:12 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xtz81442t.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> <7xtz81442t.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 03:54:02 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > Again, there have to be some language extensions to communicate the >> > necessary info to the external tool. >> >> Or, dare one say it, conventions? > > If the language-tool combo uses the info in a formal way, they are > extensions, not conventions. If the tool isn't part of the compile/run cycle, I'm not convinced that that's a useful view to take. It is useful to regard to C preprocessor statements as extensions to C, though it's had the result that nobody uses that quite general purpose preprocessor for anything other than C. It's less obvious that the conventional folding marks "{{{ ... }}}" some editors (can be made to) recognise are usefully considered as extensions to any language. But this is just quibbling over semantics. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at holdenweb.com Thu Jan 15 00:58:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 15 Jan 2009 00:58:11 -0500 Subject: executing multiple functions in background simultaneously In-Reply-To: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> References: <496E8D50.4050900@jpl.nasa.gov> <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> Message-ID: Jean-Paul Calderone wrote: > On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney > wrote: >> [snip] >>> >>> The easy thing is to use a Queue object. The background thread uses >>> .put() to place a computed result on the QUeue and the caller uses >>> .get() to read from the queue. There's an assortment of other ways too. >>> >>> Cheers, >> >> Thank you for this hint. This goes a long way to solving >> my problem. >> >> One question - is there any way to name the objects that get >> put on a queue? For my application, it's important to know >> which thread put a particular item on the queue. > > There's lots and lots of ways. The simplest might be to put two-tuples > of the thread identifier and some other object. eg > > queue.put((threadID, obj)) > > Perhaps you can accomplish your goal that way, or perhaps a minor > variation would be more suitable. > Catherine: Did you attend one of my classes at JPL? Feel free to rope me in to discussions like this if so. (Or even if not: NASA are a good customer). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From michele.simionato at gmail.com Thu Jan 15 00:59:16 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:59:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Jan 13, 6:47?pm, Bruno Desthuilliers wrote: > I really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of course > they are free to choose another language). And FWIW, I at least had a > partial answer on this. It could just be an issue of practicality. Python is an industrial strength language with libraries for everything and you can use it for your daily work. There are nice little languages out there that are however not usable for real work because of lack of libraries/lack of support/small community etc. From marco.m.petersen at gmail.com Thu Jan 15 01:01:21 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:01:21 -0800 (PST) Subject: 2to3 Help? Message-ID: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> I have Python 3.0. I tried to use the 2to3 program included with the interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. When I try to start it form the Python command line, it says it is a syntax error. This was the line of code: $ 2to3 testscript.py Any help would be appreciated. Thanks - Marco From prologic at shortcircuit.net.au Thu Jan 15 01:07:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:07:46 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Thu, Jan 15, 2009 at 3:59 PM, Michele Simionato wrote: (...) > It could just be an issue of practicality. Python is an industrial > strength language with libraries for everything and you can use it for > your daily work. There are nice little languages out there that are > however not usable for real work because of lack of libraries/lack of > support/small community etc. So _exactly_ how does this thread relate to the subject: Does Python really follow its philosophy of "Readability counts"? --JamesMills From prologic at shortcircuit.net.au Thu Jan 15 01:09:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:09:49 +1000 Subject: 2to3 Help? In-Reply-To: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:01 PM, wrote: > I have Python 3.0. I tried to use the 2to3 program included with the > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. > When I try to start it form the Python command line, it says it is a > syntax error. > > This was the line of code: > > $ 2to3 testscript.py > > Any help would be appreciated. $ 2to3 testscript.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Can't open testscript.py: [Errno 2] No such file or directory: 'testscript.py' RefactoringTool: No files need to be modified. RefactoringTool: There was 1 error: RefactoringTool: Can't open testscript.py: [Errno 2] No such file or directory: 'testscript.py' Seems to work perfectly fine here. It would greatly help if you showed us the error! cheers James From marco.m.petersen at gmail.com Thu Jan 15 01:17:25 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:17:25 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> On Jan 15, 2:09?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:01 PM, ? wrote: > > I have Python 3.0. I tried to use the 2to3 program included with the > > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. > > When I try to start it form the Python command line, it says it is a > > syntax error. > > > This was the line of code: > > > $ 2to3 testscript.py > > > Any help would be appreciated. > > $ 2to3 testscript.py > RefactoringTool: Skipping implicit fixer: buffer > RefactoringTool: Skipping implicit fixer: idioms > RefactoringTool: Skipping implicit fixer: set_literal > RefactoringTool: Skipping implicit fixer: ws_comma > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or > directory: 'testscript.py' > RefactoringTool: No files need to be modified. > RefactoringTool: There was 1 error: > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or > directory: 'testscript.py' > > Seems to work perfectly fine here. > > It would greatly help if you showed us the error! > > cheers > James The error was: >>> $ 2to3.py testscript.py File "", line 1 $ 2to3.py testscript.py ^ Syntax Error: Invalid Syntax >>> From steven at REMOVE.THIS.cybersource.com.au Thu Jan 15 01:18:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 06:18:29 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Thu, 15 Jan 2009 16:07:46 +1000, James Mills wrote: > On Thu, Jan 15, 2009 at 3:59 PM, Michele Simionato > wrote: > (...) > >> It could just be an issue of practicality. Python is an industrial >> strength language with libraries for everything and you can use it for >> your daily work. There are nice little languages out there that are >> however not usable for real work because of lack of libraries/lack of >> support/small community etc. > > So _exactly_ how does this thread relate to the subject: Does Python > really follow its philosophy of "Readability counts"? If you had followed the thread since the beginning, you'd see that the topic has evolved (or perhaps strayed) from the original subject. -- Steven From michele.simionato at gmail.com Thu Jan 15 01:20:07 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:20:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> On Jan 14, 3:27?am, Paul Rubin wrote:> > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. ?A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. I would be fine having something like pylint built-in in the language and running at every change of the source code (unless disabled with a command line switch). I think this is the only reasonable solution to get some additional protection we can hope for. A true change of the language IMO is impossible, both technically, politically and for legacy issue. Also, I am not convinced it would be a good idea, even theoretically. It is easier to write a new Python-like language from scratch than to add type checking to Python (I think you were not proposing adding type checking in this post, right?). Michele Simionato From prologic at shortcircuit.net.au Thu Jan 15 01:24:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:24:06 +1000 Subject: 2to3 Help? In-Reply-To: <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:17 PM, wrote: >>>> $ 2to3.py testscript.py > File "", line 1 > $ 2to3.py testscript.py > ^ > Syntax Error: Invalid Syntax Oh i see... You need to do 2 things: 1) Run 2to3 on the shell not the python interpreter. 2) Learn some basic UNIX. cheers James From steven at REMOVE.THIS.cybersource.com.au Thu Jan 15 01:25:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 06:25:16 GMT Subject: Python 3 isinstance References: Message-ID: On Wed, 14 Jan 2009 22:03:37 -0500, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) *shrug* Just change the {} to () and it will work fine. Or do this: isinstance(s, tuple({str, bytes})) > tuples have order, immutability, and the possibility of repeat items. Yes. And why is this a problem? > A set is most reasonable in a mathematical sense. What is the benefit of using sets instead of tuples inside isinstance? -- Steven From tjreedy at udel.edu Thu Jan 15 01:30:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 01:30:59 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: r wrote: > On Jan 14, 4:43 pm, Terry Reedy wrote: > [snip] >> I think the 'main' IDLE maintainer is no longer active. I think someone >> who would do more than fix critical bugs might be welcome. > > Hello Terry, > That's what i was beginning to think. I am not quite ready (as far as > my skills are concerned) to put out something that would be as useful > to many people. I could hack together something real quick for myself. > This is why i am looking for like-minded people who would be > interested in this. I have the foresight and willpower at this point > to contribute something meaningful to the Python community -- to give > back. If you are willing and able to channel your obvious enthusiasm and energy into incremental improvements, you could make meaningful contributions within weeks and months. If you go to http://bugs.python.org/issue?@template=search&status=1 and select IDLE in the 'Components' field and hit 'Search', you will get a list of (at the moment) 66 open issues. Some are bug reports, some feature requests. Some have patches waiting for review and some not. There may be some (near?) duplicate and obsolete items that could be closed after review. Pick one issue and help resolve it. Reviewing exiting patches would be definitely helpful. For instance, I would particularly like to see http://bugs.python.org/issue2704 Patch to make PyShell behave more like a Terminal interface tested and applied. It was posted last April and revised in June. Should you decide to do this, and wish further input from me, let me know, on or off list. > OFF-TOPIC:(but related) > What is the state of Tkinter at this point. Is an active effort under > way to port TK 8.5 into Python? Tkinter and IDLE are very important to > Python, but i understand there are much more important areas where the > GURU's are concentrating. Should there be a calling for "others" to > get involved here? I would like to help out. Running a search from the same page for '8.5' in the 'All text' box gave no hits. I would tend to expect that 8.5 upgrades to tkinter would be welcome at some point, but anyone actively ready to work on it could open a tracker issue or inquire on py-dev first. Terry Jan Reedy From marco.m.petersen at gmail.com Thu Jan 15 01:32:45 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:32:45 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> Message-ID: <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> > You need to do 2 things: > > 1) Run 2to3 on the shell not the python interpreter. > 2) Learn some basic UNIX. > > cheers > James I tried to run it on the command prompt (I use Windows XP) but it doesn't work either. I opened the command prompt: C:\Documents and Settings\User> Then I typed '$ 2to3 testscript.py': C:\Documents and Settings\User>$ 2to3.py testscript.py But then this appears: C:\Documents and Settings\User>$ 2to3.py testscript.py '$' is not recognized as an internal or external command, operable program or batch file. Anyway I'll try some UNIX. Thanks. From michele.simionato at gmail.com Thu Jan 15 01:34:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:34:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Jan 14, 4:18?am, "Russ P." wrote: > > So I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. > > Should Python get true encapsulation? I don't know. Maybe > encapsulation cannot be added without excessive overhead or without > compromising other more important aspects and features of the > language. But I do know that not having encapsulation is a limitation > to the use of Python for good software engineering. I may be in the > minority in the Python "community" on this one, but I am apparently in > the majority in the OO programming "community." There are lots of Python developers (and most of the core developers) that think the OO community is wrong about enforced encapsulation. Personally, I think in a few years everybody will realize the mistake of enforced encapsulation and that the OO definition in the Wikipedia page will be changed. Even if not, Wikipedia definitions does not matter much, everybody has his own idea of what OO means, and the Python definition is good as any other. Don't get pissed off on words. Michele Simionato From lipun4u at gmail.com Thu Jan 15 01:34:57 2009 From: lipun4u at gmail.com (asit) Date: Wed, 14 Jan 2009 22:34:57 -0800 (PST) Subject: why o/p is different ??? Message-ID: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> I recently faced a peculiar o/p. My objective is to remove the command name(my script name) from sys.argv[0]. I coded like this import urllib import sys print "\n\n\t\tlipun4u[at]gmail[dot]com" print "\t\t------------------------" apppath = sys.argv[0].split("/") appname = apppath[len(apppath)-1] print appname if len(sys.argv) not in [2,3]: print "Usage : " + appname + " [options]" print "e.g. : " + appname + "www.google.com --verbose" print "\n\t[option]" print "\t\t--verbose/-V for verbose output" print "\t\t-r for recursive scan" sys.exit(1) site = appname.replace("http://","").rsplit("/",1)[0] site = "http://" + site.lower() print site It showed the required o/p in the IDLE here is the o/p lipun4u[at]gmail[dot]com ------------------------ linkscan.py Usage : linkscan.py [options] e.g. : linkscan.pywww.google.com --verbose [option] --verbose/-V for verbose output -r for recursive scan Traceback (most recent call last): File "I:/Python26/linkscan.py", line 18, in sys.exit(1) SystemExit: 1 But in command prompt the o/p is still faulty lipun4u[at]gmail[dot]com ------------------------ I:\Python26\linkscan.py Usage : I:\Python26\linkscan.py [options] e.g. : I:\Python26\linkscan.pywww.google.com --verbose [option] --verbose/-V for verbose output -r for recursive scan I:\Python26> regards asit dhal From prologic at shortcircuit.net.au Thu Jan 15 01:38:40 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:38:40 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:20 PM, Michele Simionato wrote: (...) > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. Protection from what ? If one is a clumsy programmer, then perhaps one ought to be using a language that holds one's hand. --JamesMills From prologic at shortcircuit.net.au Thu Jan 15 01:40:15 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:40:15 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:34 PM, Michele Simionato wrote: (...) > There are lots of Python developers (and most of the core developers) > that think the OO community is wrong about enforced encapsulation. > Personally, I think in a few years everybody will realize the mistake > of enforced encapsulation and that the OO definition in the Wikipedia > page will be changed. Even if not, Wikipedia definitions does not > matter much, everybody has his own idea of what OO means, > and the Python definition is good as any other. Don't get pissed off > on words. Amen! The first thing said right in this entire thread! (one of) --JamesMills From michele.simionato at gmail.com Thu Jan 15 01:40:52 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:40:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> On Jan 15, 7:38?am, "James Mills" wrote: > > If one is a clumsy programmer, then perhaps > one ought to be using a language that holds one's hand. Yes, and I use Python because it is a language that holds my hand, otherwise I would use C and enjoy segmentation faults all the time. From wuwei23 at gmail.com Thu Jan 15 01:42:14 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 22:42:14 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <76b04548-303d-4f39-aaab-42c9f2ee666f@x16g2000prn.googlegroups.com> On Jan 15, 4:34?pm, asit wrote: > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] I'd replace these two lines with the following: import os.path # at the top of the file, of course appname = os.path.basename(sys.argv[0]) Also note that you can use negative indices in lists, with -1 being the last element, -2 the last but one etc. From prologic at shortcircuit.net.au Thu Jan 15 01:43:29 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:43:29 +1000 Subject: 2to3 Help? In-Reply-To: <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:32 PM, wrote: > I tried to run it on the command prompt (I use Windows XP) but it > doesn't work either. I did not realize you were using WIndows :) Normally most shells in the UNIX/Linux world start with a '$'. > I opened the command prompt: > > C:\Documents and Settings\User> > > Then I typed '$ 2to3 testscript.py': > > C:\Documents and Settings\User>$ 2to3.py testscript.py > > But then this appears: > > C:\Documents and Settings\User>$ 2to3.py testscript.py > '$' is not recognized as an internal or external command, > operable program or batch file. Your problem is, you are treating the '$' (most likely copied/pasted from readings on the web) as part of what you need to enter into the command prompt. '$' is (like I said above) normally part of most commonly configured shells (eg: Bash). You need to just enter: 2to3 testscript.py > Anyway I'll try some UNIX. Thanks. That is a good idea :) Windows teaches you nothing! cheers James From delroth at gmail.com Thu Jan 15 01:45:47 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Thu, 15 Jan 2009 07:45:47 +0100 Subject: why o/p is different ??? In-Reply-To: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <1ba9eaed0901142245g22aa86f7y5fef5ef3a29a298f@mail.gmail.com> Use os.path.basename : >>> os.path.basename('/foo/bar/baz.py') 'baz.py' It will have the expected behavior on each system. You could also use os.sep instead of '/' in your split method call, but os.path.basename is more elegant. On Thu, Jan 15, 2009 at 7:34 AM, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this > > import urllib > import sys > > > print "\n\n\t\tlipun4u[at]gmail[dot]com" > print "\t\t------------------------" > > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] > print appname > > if len(sys.argv) not in [2,3]: > print "Usage : " + appname + " [options]" > print "e.g. : " + appname + "www.google.com --verbose" > print "\n\t[option]" > print "\t\t--verbose/-V for verbose output" > print "\t\t-r for recursive scan" > sys.exit(1) > > site = appname.replace("http://","").rsplit("/",1)[0] > site = "http://" + site.lower() > print site > > > It showed the required o/p in the IDLE > here is the o/p > > lipun4u[at]gmail[dot]com > ------------------------ > linkscan.py > Usage : linkscan.py [options] > e.g. : linkscan.pywww.google.com --verbose > > [option] > --verbose/-V for verbose output > -r for recursive scan > > Traceback (most recent call last): > File "I:/Python26/linkscan.py", line 18, in > sys.exit(1) > SystemExit: 1 > > But in command prompt the o/p is still faulty > > lipun4u[at]gmail[dot]com > ------------------------ > I:\Python26\linkscan.py > Usage : I:\Python26\linkscan.py [options] > e.g. : I:\Python26\linkscan.pywww.google.com --verbose > > [option] > --verbose/-V for verbose output > -r for recursive scan > > I:\Python26> > > regards > asit dhal > -- > http://mail.python.org/mailman/listinfo/python-list > From wuwei23 at gmail.com Thu Jan 15 01:46:37 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 22:46:37 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Jan 15, 4:32?pm, marco.m.peter... at gmail.com wrote: > I tried to run it on the command prompt (I use Windows XP) but it > doesn't work either. > '$' is not recognized as an internal or external command, > operable program or batch file. '$' is used in the instructions to denote a command prompt. You're not supposed to type it :) In your case '$' == 'C:\Documents and Settings\User>'; just type '2to3.py testscript.py' and it should work (assuming it's location is in your PATH and you have the right handlers set up to launch it) From prologic at shortcircuit.net.au Thu Jan 15 01:47:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:47:25 +1000 Subject: why o/p is different ??? In-Reply-To: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:34 PM, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this If you _really_ want to remove your script_name from sys.argv, then do this: del sys.argv[0] If you're just after what the name of your script is that's being run (for human readability) try the following function (taken from pymills): def getProgName(): """getProgName() -> str Return the name of the current program being run by working it out from the script's basename. """ return os.path.basename(sys.argv[0]) -------------------------------------------------- cheers James From marco.m.petersen at gmail.com Thu Jan 15 01:52:43 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:52:43 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: Oh okay. I don't think my Python installation is in PATH yet. I'll try to add it then. From wuwei23 at gmail.com Thu Jan 15 02:02:51 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 23:02:51 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Jan 15, 4:52?pm, marco.m.peter... at gmail.com wrote: > Oh okay. I don't think my Python installation is in PATH yet. I'll try > to add it then. I don't yet have 3.0 installed, but my guess is you'll also need to have 'C:\Python30\Scripts' in your path as well. I'm assuming that's where it resides, so check first. From http Thu Jan 15 02:02:52 2009 From: http (Paul Rubin) Date: 14 Jan 2009 23:02:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> Message-ID: <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Michele Simionato writes: > > there is no language that currently really works the right way, > > but some of them including Python are (one hopes) moving in good > > directions. > > To be fair, this has been true for the last 50 years. If a language > that works the right way really existed, CS would be dead and there > would be no progress to make. Happily I think we will never end in > that situation ;) I'd say there was a time Lisp worked the right way, and a time C worked the right way, and maybe a time Python worked the right way, and for a while, Algol 60 was perfection embodied. But times have changed more than those languages have, so they no longer work the right way. The right way basically can never mean more than "the best that can be done using current technology". Right now, the stuff happening in the programming-language research world is light years beyond what us poor peons are using in everyday hacking, while we face harder and harder challenges due to bigger and faster computers leading to more complex software, and a vastly enlarged attack surface exposed to internet security threats. Have you looked at Tim Sweeney's talk that I mentioned in another post? http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf From Russ.Paielli at gmail.com Thu Jan 15 02:05:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 23:05:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> On Jan 14, 10:40?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:34 PM, Michele Simionato wrote: > > (...) > > > There are lots of Python developers (and most of the core developers) > > that think the OO community is wrong about enforced encapsulation. > > Personally, I think in a few years everybody will realize the mistake > > of enforced encapsulation and that the OO definition in the Wikipedia > > page will be changed. Even if not, Wikipedia definitions does not > > matter much, everybody has his own idea of what OO means, > > and the Python definition is good as any other. Don't get pissed off > > on words. > > Amen! The first thing said right in this entire thread! (one of) > > --JamesMills Wait a minute. Aren't the guy who just took me to task about the definition of functional programming? So the definition of functional programming is written in stone, but the definition of OO programming is written in smoke? Just for the record, I really don't care much about the definition of OO programming. I brought it up only because someone tried to claim that "enforced" encapsulation is a terrible idea. Well, as far as I can tell, the majority of OO "programmers" (and software engineers, software architects, etc.) seem to think otherwise. Maybe they are wrong -- but I seriously doubt it. As I said before, enforced encapsulation may not be appropriate for every application, but it is definitely appropriate for some. Not every door needs a lock, but certainly some do. From http Thu Jan 15 02:10:07 2009 From: http (Paul Rubin) Date: 14 Jan 2009 23:10:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: <7x3afl3v00.fsf@ruckus.brouhaha.com> Michele Simionato writes: > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. A true change of the > language IMO is impossible, both technically, politically and for > legacy issue. Also, I am not convinced it would be a good idea, even > theoretically. It is easier to write a new Python-like language > from scratch than to add type checking to Python (I think you > were not proposing adding type checking in this post, right?). I think this sub-thread has been mostly about dynamically creating new class instance attributes, but yes, at one point I did suggest adding type checking (ML-like inference) to pylint, presumably with feedback to the compiler for optimization purposes. I noted that Python 3.0 in fact has some features to support annotations for the purpose of static type checking, so it's not as far off the wall as it might sound. From marco.m.petersen at gmail.com Thu Jan 15 02:13:17 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 23:13:17 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: <9262bda5-e884-427b-a20d-8391db801230@t39g2000prh.googlegroups.com> > I don't yet have 3.0 installed, but my guess is you'll also need to > have 'C:\Python30\Scripts' in your path as well. I'm assuming that's > where it resides, so check first. Its in C:\Python30\Tools\Scripts. Anyway it now works. C:\Documents and Settings\User>python C:\Python30\Tools\Scripts \2to3.py C:\Python30\testscript.py Thanks a lot alex23. From wuwei23 at gmail.com Thu Jan 15 02:15:18 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 23:15:18 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: On Jan 15, 1:06?pm, Paul Rubin wrote: > I just looked up Cython and see that it's based on Pyrex. ?Worth > knowing about, I guess; but basically I think C is evil. I feel much the same way, but the recent modifications to Cython that provide a "pure Python"[1] approach mean that you can minimise the amount of C you need to write and still take advantage of features like static types: @cython.locals(s=cython.double, i=int, n=int) def harmonic_sum(n): s = 0 for i in range(1, n+1): s += 1.0 / i return s The same code will both run in Python and compile via Cython. (I'm surprised the new "pure" approach isn't more clearly promoted on the site.) 1: http://wiki.cython.org/pure From Russ.Paielli at gmail.com Thu Jan 15 02:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 23:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> Message-ID: On Jan 14, 9:51?pm, Michele Simionato wrote: > On Jan 13, 2:48?am, "Russ P." wrote: > > > I started looking at Scala a while back. It is has many nice features. > > It seamlessly combines object orientation with advanced functional > > programming. > > I don't like that. Scala was designed with the idea of putting > together the two worlds, by I think the result was to get the > complications of both worlds. I don't think a SML-like functional > language needs to be integrated with object orientation, it is fine > just without it. The old quote > applies: > > """ > Programming languages should be designed not by piling feature on top > of feature, but by removing the weaknesses and restrictions that make > additional features appear necessary. -- William Clinger > """ I haven't used Scala yet, but I can't see any inherent problem with combining OO and functional programming. Doesn't Python itself do that to some extent, after all? The two paradigms are actually complementary: FP is stateless and the OOP is state-based. Some problems are best solved using OOP and some are best solved using FP. Are you suggesting that a programmer should use a different language for each problem? What if a software project involves many subproblems, some of which are best solved using OOP and others of which are best solved using FP? Should one language be used for one part of the project and another language for the other? I don't think so. From aleksandr.goretoy at gmail.com Thu Jan 15 02:20:16 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:20:16 -0600 Subject: error: cannot invoke setopt() - perform() is currently running Message-ID: hello all, I have a problem when using pycurl with threading Thread from threading import Thread the error i get is this: error: cannot invoke setopt() - perform() is currently running how do I catch a error like this in my code and perform a action like wait for perform to finish until it tries to setopt again? Has anyone come across this? Any help in this matter will be highly appreciated, I've spent a week on this and can't seem to figure it out. Googling hasn't brought me any thing except my own code....hahaha go figure TIA -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From sjmachin at lexicon.net Thu Jan 15 02:26:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 23:26:48 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: <5ac3d83e-3394-49de-a730-5578c8feb0ea@g39g2000pri.googlegroups.com> On Jan 15, 5:52?pm, marco.m.peter... at gmail.com wrote: > Oh okay. I don't think my Python installation is in PATH yet. I'll try > to add it then. Am I permitted to ask a really silly question? Thanks. Here it is: How much working 2.X code do you have that needs migrating from 2.x to 3.x? Cheers, John From aleksandr.goretoy at gmail.com Thu Jan 15 02:36:58 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:36:58 -0600 Subject: error: cannot invoke setopt() - perform() is currently running In-Reply-To: References: Message-ID: more info for all: the class I'm trying to use threading on top of called pcrunchly. I've posted it previously on here, but you can find it at this link. http://article.gmane.org/gmane.comp.python.general/604050 How can i make this work with threading Thread? On 1/15/09, alex goretoy wrote: > hello all, > > I have a problem when using pycurl with threading Thread > > from threading import Thread > > the error i get is this: > > error: cannot invoke setopt() - perform() is currently running > > > how do I catch a error like this in my code and perform a action like > wait for perform to finish until it tries to setopt again? > > Has anyone come across this? > > Any help in this matter will be highly appreciated, I've spent a week > on this and can't seem to figure it out. Googling hasn't brought me > any thing except my own code....hahaha go figure TIA > > -- > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From aleksandr.goretoy at gmail.com Thu Jan 15 02:38:25 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:38:25 -0600 Subject: error: cannot invoke setopt() - perform() is currently running In-Reply-To: References: Message-ID: sorry for multi posting It's a habit I have. The closest thing I can come up with is this http://pycurl.cvs.sourceforge.net/viewvc/pycurl/pycurl/examples/retriever-multi.py?revision=1.29&view=markup but how to make this work with pcrunchly and threading Thread? On 1/15/09, alex goretoy wrote: > more info for all: > > the class I'm trying to use threading on top of called pcrunchly. I've > posted it previously on here, but you can find it at this link. > > http://article.gmane.org/gmane.comp.python.general/604050 > > How can i make this work with threading Thread? > > On 1/15/09, alex goretoy wrote: >> hello all, >> >> I have a problem when using pycurl with threading Thread >> >> from threading import Thread >> >> the error i get is this: >> >> error: cannot invoke setopt() - perform() is currently running >> >> >> how do I catch a error like this in my code and perform a action like >> wait for perform to finish until it tries to setopt again? >> >> Has anyone come across this? >> >> Any help in this matter will be highly appreciated, I've spent a week >> on this and can't seem to figure it out. Googling hasn't brought me >> any thing except my own code....hahaha go figure TIA >> >> -- >> -Alex Goretoy >> http://www.alexgoretoy.com >> somebodywhocarez at gmail.com >> > > > -- > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From python at rcn.com Thu Jan 15 02:57:06 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 14 Jan 2009 23:57:06 -0800 (PST) Subject: Alphametric fun with Python Message-ID: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> Thought you guys might enjoy this: http://code.activestate.com/recipes/576615/ SEND + MORE == MONEY 9567 + 1085 == 10652 Raymond Hettinger From Lie.1296 at gmail.com Thu Jan 15 03:02:57 2009 From: Lie.1296 at gmail.com (Lie) Date: Thu, 15 Jan 2009 00:02:57 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <8ae18e97-76e6-4e29-a9de-827fc06d8cab@g1g2000pra.googlegroups.com> On Jan 5, 9:03?am, Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: > > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > > > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > > What the Python community often overlooks, when this discussion again > > > rears its ugly head (as it seems to every other hour or so), is that its > > > assignment model is BIZARRE, as in it's conceptually different from > > > virtually all other languages substantially taught in undergraduate > > > computer science programs. > > > What's the difference between Python and Java or C# here!? ?Or are they > > also "BIZARRE"!? > > I am happily ignorant of C#. ?As for Java, take the following code: > > ? a = 6; > ? a = 5; > > In Python, when you execute the equivalent code, it causes two > different objects to spring into existence, the first of which may be > cleaned up by the GC (except that since we're using small integers, > that's not likely to happen). ?Unless I'm misinformed (which is very > possible, my experience with Java has been extremely limited) in Java > that's not the case... ?the storage is allocated to the name a when > you execute its declaration, and the *same storage* is reused upon > subsequent assignment. > > That behaves exactly like named bins. > > > > And for that matter, it's pretty unintuitive generally. > > > Names and objects are quite "natural" IMHO. ?There are many real world > > objects which we attach one or more names to, or refer to in sequences > > like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. ?Nor does Python's assignment work like it does in algebra, > or anywhere else the Python student is particularly likely to have > seen variable assignment before encountering it in Python. ?Let's > define intuitive, shall we? ?From dictionary.com (choosing the > definition which most easily makes my point): > > ? intuitive: adj. ?capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > a student could intuit Python's variable assignment behavior, having > never been exposed to that same behavior prior. ?It needs to be > taught. Which limb would you like to go with? > > > That is, in what I'll call "normal" computer languages, a variable name > > > is thought of as the address of a bin where some data is stored, and the > > > name is inexorably tied to that bin. > > > You just call that "normal" or "intuitive" because that's what you > > learned first. > > In a sense, yes... but isn't that what intuition really is? ?You can > figure something out whithout being told how it works... ?That's > either because it's immediately obvious from observing it, or it > behaves like something you've seen before. ?That is what intitive is. No. You've just said it yourself, something is intuitive if "it behaves like something you've seen before". People have different experience, people deeply involved in mathematics would see "named bin" is the obvious thing to go, however commoners (including mathematician) will have different say: "Derek is the name of a human object" instead of "Derek is a specific collection of atoms that resembles human". This is also why python community tend to avoid the use of "variable", because python's name doesn't behave like variables in mathematics, it behaves like "name". (heck, one would argue that even "variable" in programming is not exactly the same as "variable" in mathematic either) > > I think the "bin model" is more complex because you don't just have a > > name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) ?"Named bins" is essentially how algebra > works, and how several generations of computer languages, not to > mention the actual machine language those generated, behaved, before > the current crop. ?Those interpretations came first, because, much as > in the evolution of any other science, that was the model which was > most intuitive or easily explained. No, it is neither the most intuitive nor easily explained, but indeed it is the simplest to implement as humans at that time have limited capability to design chips. In the early days, ease of use is not a priority, simplicity is. > But you need not take my word for it. ?Simply read the archives and > see for yourself how much confusion this has caused on this list. > [Please include the closely related behavior of parameter passing in > your search.] The first time I used python, I didn't have any idea how the object model works, and I don't have experience in similar programming concept nor was python my first language, yet I have no difficulty in understanding why things goes like it is. For me, at least, python's object model is intuitive (do you remember about the limb?). From gandalf at shopzeus.com Thu Jan 15 03:33:43 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 09:33:43 +0100 Subject: Slow Queue.queue? (was: slow network) Message-ID: <496EF4E7.5040804@shopzeus.com> I had this test program originally that sent message over TCP/IP. Messages where buffered two a Queue.Queue instances, one for incoming and one for outgoing. #1. endpoint.send_message(msg) -> endpoint.outgoing.put(msg) #2. endpoint._process_outgoing() is a thread, that does: endpoint.write_into_socket( endpoint.outgoing.get() ) On the other side: #1 endpoint._process_incoming() is a thread, that does endpoint.incoming.put( endpoint.read_from_socket() ) #2 endpoing.recv_messages() -> return endpoint.incoming.get() This could do 130 message pairs/sec on Linux (on 127.0.0.1) and only 20 message pairs /sec on Windows XP. If do not start the _process_outgoing() thread, and do not use the outgoing queue: #1. endpoint.send_message(msg) -> endpoint.write_into_socket(msg) then the speed goes up to 64 messages/sec on windows and 500 messages/sec on Linux. This has nothing to do with TCP/IP. The only change is that I'm not using a queue, and not using +1 thread. How can this slow down my program? Is it a problem with Queue.Queue, or with the +1 thread? Thanks, Laszlo From prologic at shortcircuit.net.au Thu Jan 15 04:03:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 19:03:30 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 5:05 PM, Russ P. wrote: (...) > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming > is written in smoke? Did anyone say that ? OO concepts are a much studied concept. However -you- still miss the basic point. OO programming -is- a model not a paradigm. Functional Programming -is- a paradigm. > Just for the record, I really don't care much about the definition of > OO programming. I brought it up only because someone tried to claim > that "enforced" encapsulation is a terrible idea. Well, as far as I > can tell, the majority of OO "programmers" (and software engineers, > software architects, etc.) seem to think otherwise. Maybe they are > wrong -- but I seriously doubt it. Ever thought that perhaps you might be the one that's wrong ? Not that it really matters, but I am a Software Engineer myself. > As I said before, enforced encapsulation may not be appropriate for > every application, but it is definitely appropriate for some. Not > every door needs a lock, but certainly some do. Your analogy is terrible. We are talking about machines that execute instructions in a sequence. At the most basic level do you really think a machine really cares about whether -you- the programmer has illegally accessed something you shouldn't have ? --JamesMills From deets at nospam.web.de Thu Jan 15 04:08:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 15 Jan 2009 10:08:37 +0100 Subject: General direction In-Reply-To: References: Message-ID: <6t8comF9ou5uU1@mid.uni-berlin.de> MLT schrieb: > Hello all: I'm a beginner to Python (and programming altogether), and > am now looking to create a program of my own. What I've got in mind > is a very basic pest control program that would keep track of 1) trap > findings and 2) pesticides. My thought is to make each of these > classes. Looking at the general outline written below, can anyone > give general impression about whether I'm somewhat going in the right > direction or if I need to approach it entirely differently? Thanks > for any suggestions or help! Familiarize yourself with PEP8 for naming and coding-conventions first. > Class Insect_Trapping attributes: > - Unique Name > - Location > - Type Depending on what the Type is, you might consider using subclassing here instead. > - Frequency of Checks? > - Next Check Date > > Within Insect_Trapping there are Trap_Count objects > > Trap_Count objects have the following attributes: > - Date > - Time > - Insect A Finds > - Insect B Finds > - Insect C Finds > - Insect A Number > - Insect B Number > - Insect C Number Instead of manually coding attributes for all kinds of insects, better use a mapping of insect-name to attributes. There are plenty of options for that - you could a mapping of name to tuple: { "cockroach" : (100, 200), "wasp" : (2000, 3000) } Or introduce a InsectInfo-class that has finds and numbers as fields: { "bee" : InsectInfo(finds=100, number=200) } > Class Pesticides attributes: > - Unique Name > - Usage Instructions > > Within Pesticide there are Pesticide_Usage objects > > Pesticide_Usage objects have the following attributes: > - Date > - Time > - Location > - Reason for Use > - Amt Used HTH, Diez From gandalf at shopzeus.com Thu Jan 15 04:22:06 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 10:22:06 +0100 Subject: Slow Queue.queue? (was: slow network) In-Reply-To: <496EF4E7.5040804@shopzeus.com> References: <496EF4E7.5040804@shopzeus.com> Message-ID: <496F003E.7010800@shopzeus.com> > > then the speed goes up to 64 messages/sec on windows and 500 > messages/sec on Linux. Finally I could reach 1500 messages/sec without using the queue. If I comment out one line (use the queue instead of direct write into socket) then speed decreases to 40-60 messages/sec. I don't understand why the slow version is slower by a factor of 40? Fast version: def send_message(self,sender,recipient,msgtype,body,timeout=3600): self.write_str(self.serializer.serialize([sender,recipient,msgtype,body])) Slow version: def send_message(self,sender,recipient,msgtype,body,timeout=3600): self.outgoing.put(self.serializer.serialize([ sender,recipient,msgtype,body ]),1,timeout) plus this method, executed in a different thread: def _process_outgoing(self): try: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): try: data = self.outgoing.get(1,1) data_ok = True break except Queue.Empty: pass if data_ok: self.write_str(data) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) From duncan.booth at invalid.invalid Thu Jan 15 04:35:42 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Jan 2009 09:35:42 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Terry Reedy wrote: > Lambert, David W (S&T) wrote: >> Overly terse. I do mean that this is illegal: >> >> isinstance(s, {str, bytes}) >> >> tuples have order, immutability, and the possibility of repeat items. >> >> A set is most reasonable in a mathematical sense. > > I agree. However, isinstance predates set. Hence the status quo. > > There is another reason which nobody has mentioned, and which might make it tricky to do a good implementation that does accept sets. The second argument to isinstance or issubclass is a classinfo where a classinfo is either a class or a tuple of classinfo. This makes it easy to group related types: you can just combine existing groups of types together without having to flatten tuples. The immutability of tuples guarantees that you cannot create a recursive structure this way. If you allow sets then the code which traverses the classinfo has to protect itself against the possibility of an infinite recursion. The same argument also applies to exception handlers which also accept a type or a tuple of things they accept. Of course you could allow either an existing classinfo or a set of types, but not allow the set to contain anything other than types. That would still prevent recursion but means you have to be stricter about knowing what you are combining. That probably wouldn't be a bad thing if everyone used sets consistently but I suspect would be messy if introduced at this stage. -- Duncan Booth http://kupuguy.blogspot.com From gandalf at shopzeus.com Thu Jan 15 04:36:57 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 10:36:57 +0100 Subject: process/thread instances and attributes In-Reply-To: References: Message-ID: <496F03B9.8090100@shopzeus.com> > Hey all, > > I have this concept I'm working on and here is > the code... Problem is if you run this it doesn't > terminate. I believe you can terminate it in the > main process by calling a.stop() But I can't find a > way for it to self terminate, ie: self.stop() As indicated > by the code... > I'm not sure what you wanted to do here, but it is for sure that your "running" variable is not shared between the processes. Use this instead: from multiprocessing import Value self.running = Value('i',0) Then these: self.running.value = 1 self.running.value = 0 if self.running.value: But I'm affraid your example won't work. Considering your stop() method: def stop(self): print "%s: Stopping ..." % self self.running.value = 0 It would set running.value to zero. However, at that time there will be other processes running their start() method and setting the same shared value to 1. What do you want to try with this example? L From lipun4u at gmail.com Thu Jan 15 05:28:29 2009 From: lipun4u at gmail.com (asit) Date: Thu, 15 Jan 2009 02:28:29 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <4b967ea2-61e3-49b9-a898-278bf4640757@p36g2000prp.googlegroups.com> On Jan 15, 11:47?am, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:34 PM, asit wrote: > > I recently faced a peculiar o/p. > > > My objective is to remove the command name(my script name) from > > sys.argv[0]. > > I coded like this > > If you _really_ want to remove your script_name from > sys.argv, then do this: > > del sys.argv[0] > > If you're just after what the name of your script is > that's being run (for human readability) try the > following function (taken from pymills): > > def getProgName(): > ? ?"""getProgName() -> str > > ? ?Return the name of the current program being run > ? ?by working it out from the script's basename. > ? ?""" > > ? ?return os.path.basename(sys.argv[0]) > > -------------------------------------------------- > > cheers > James Thank you everyone From see.signature at no.spam Thu Jan 15 05:30:00 2009 From: see.signature at no.spam (Eric Brunel) Date: Thu, 15 Jan 2009 11:30:00 +0100 Subject: Possible bug in Tkinter - Python 2.6 Message-ID: Hi all, I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is the script: ----------------------------- from Tkinter import * from tkMessageBox import * from tkFileDialog import * root = Tk() def ask_file(): file_name = askopenfilename() print file_name def ask_confirm(): answer = askyesno() print answer Button(root, text='Ask file', command=ask_file).pack() Button(root, text='Ask confirm', command=ask_confirm).pack() root.mainloop() ----------------------------- Scenario: - Run the script. - Click the 'Ask confirm' button and answer 'Yes'; it should print True, which is the expected answer. - Click the 'Ask file' button, select any file and confirm. - Click the 'Ask confirm' button and answer 'Yes'. At the last step, the script prints 'False' for me, which is quite wrong. Can anybody confirm this? I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, it seems to work correctly on Windows 2000. I could only test with Python 2.6, and not 2.6.1. But I didn't see any mention of this problem in the release notes. And BTW, if this is actually a bug, where can I report it? TIA -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From prologic at shortcircuit.net.au Thu Jan 15 05:35:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 20:35:03 +1000 Subject: process/thread instances and attributes In-Reply-To: <496F03B9.8090100@shopzeus.com> References: <496F03B9.8090100@shopzeus.com> Message-ID: On Thu, Jan 15, 2009 at 7:36 PM, Laszlo Nagy wrote: (...) Value won't do obviously :) As there could be an arbitary no. of processes. > What do you want to try with this example? I guess I just am confused as to what belongs to which process (the main or the child) ... I need a clear cut example or documetnation of what's what ... cheers James From jstroud at mbi.ucla.edu Thu Jan 15 05:35:34 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 15 Jan 2009 02:35:34 -0800 Subject: General direction In-Reply-To: References: Message-ID: MLT wrote: > Hello all: I'm a beginner to Python (and programming altogether), and > am now looking to create a program of my own. What I've got in mind > is a very basic pest control program that would keep track of 1) trap > findings and 2) pesticides. My thought is to make each of these > classes. Looking at the general outline written below, can anyone > give general impression about whether I'm somewhat going in the right > direction or if I need to approach it entirely differently? Thanks > for any suggestions or help! [data structures snipped] Programs generally *do* something. Here you have described data structures, which just sit there being full of data. They aren't very active and hence are not terribly interesting. Here are some bullet points for your consideration: 1. What will your program do? 2. Understand databases (http://tinyurl.com/6flhbz) before you start. 3. Consider PySQlite (http://trac.edgewall.org/wiki/PySqlite) before you think about a heavyweight database backend (once you realize that you will want a database for this project). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bieffe62 at gmail.com Thu Jan 15 05:44:56 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Thu, 15 Jan 2009 02:44:56 -0800 (PST) Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> On 15 Gen, 11:30, "Eric Brunel" wrote: > Hi all, > > I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is ? > the script: > > ----------------------------- > ?from Tkinter import * > ?from tkMessageBox import * > ?from tkFileDialog import * > > root = Tk() > > def ask_file(): > ? ?file_name = askopenfilename() > ? ?print file_name > > def ask_confirm(): > ? ?answer = askyesno() > ? ?print answer > > Button(root, text='Ask file', command=ask_file).pack() > Button(root, text='Ask confirm', command=ask_confirm).pack() > > root.mainloop() > ----------------------------- > > Scenario: > - Run the script. > - Click the 'Ask confirm' button and answer 'Yes'; it should print True, ? > which is the expected answer. > - Click the 'Ask file' button, select any file and confirm. > - Click the 'Ask confirm' button and answer 'Yes'. > > At the last step, the script prints 'False' for me, which is quite wrong. ? > Can anybody confirm this? > > I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise ? > Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, it ? > seems to work correctly on Windows 2000. I could only test with Python ? > 2.6, and not 2.6.1. But I didn't see any mention of this problem in the ? > release notes. > > And BTW, if this is actually a bug, where can I report it? > > TIA > -- > python -c "print ''.join([chr(154 - ord(c)) for c in ? > 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" It works here (no bug), python 2.6.1 on Windows XP. If it is a bag, maybe it is platform-specific ... Ciao ---- FB From bieffe62 at gmail.com Thu Jan 15 06:14:26 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Thu, 15 Jan 2009 03:14:26 -0800 (PST) Subject: Slow Queue.queue? (was: slow network) References: <496EF4E7.5040804@shopzeus.com> Message-ID: <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> On 15 Gen, 10:22, Laszlo Nagy wrote: > > then the speed goes up to 64 messages/sec on windows and 500 > > messages/sec on Linux. > > Finally I could reach 1500 messages/sec without using the queue. If I > comment out one line (use the queue instead of direct write into socket) > then speed decreases to 40-60 messages/sec. I don't understand why the > slow version is slower by a factor of 40? > > Fast version: > > ? ? def send_message(self,sender,recipient,msgtype,body,timeout=3600): > > self.write_str(self.serializer.serialize([sender,recipient,msgtype,body])) > > Slow version: > > ? ? def send_message(self,sender,recipient,msgtype,body,timeout=3600): > ? ? ? ? self.outgoing.put(self.serializer.serialize([ > ? ? ? ? ? ? sender,recipient,msgtype,body > ? ? ? ? ]),1,timeout) > > plus this method, executed in a different thread: > > ? ? def _process_outgoing(self): > ? ? ? ? try: > ? ? ? ? ? ? while not self.stop_requested.isSet(): > ? ? ? ? ? ? ? ? data_ok = False > ? ? ? ? ? ? ? ? while not self.stop_requested.isSet(): > ? ? ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? ? ? data = self.outgoing.get(1,1) > ? ? ? ? ? ? ? ? ? ? ? ? data_ok = True > ? ? ? ? ? ? ? ? ? ? ? ? break > ? ? ? ? ? ? ? ? ? ? except Queue.Empty: > ? ? ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? ? ? ? ? if data_ok: > ? ? ? ? ? ? ? ? ? ? self.write_str(data) > ? ? ? ? except Exception, e: > ? ? ? ? ? ? if self.router: > ? ? ? ? ? ? ? ? if not isinstance(e,TransportClosedError): > ? ? ? ? ? ? ? ? ? ? self.router.logger.error(dumpexc(e)) > ? ? ? ? ? ? ? ? self.router.unregister_endpoint(self) > ? ? ? ? ? ? self.shutdown() > ? ? ? ? ? ? raise SystemExit(0) I would try something like this inside _process_outgoing: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): if not self.outgoing.empty(): try: data = self.outgoing.get(True,0.1) data_ok = True break except Queue.Empty: pass else: time.sleep(0.1) # maybe, if the thread usess too much CPU The hypotesis I made for this suggestion are: - if the queue is found empty, the queue.get could keep the global interpreter lock until a message arrive (blocking also the thread that put the message in the queue) - if the queue is found empty, the handling of the exception can slows down the execution Not sure they are good guesses, because at the rate of your messages the queue should be almost always full, and most probably the implementation of Queue.get is smarted than myself :-). ANyway, it is worth a try ... Also, is you are using fixed-length queues (the ones that make the sender wait if the queue is full), try to increase the queue size, or to use an infinite-size queue. HTH Ciao ---- FB From sjmachin at lexicon.net Thu Jan 15 06:18:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 03:18:21 -0800 (PST) Subject: List/Set/Dict.. References: Message-ID: <6c1a21f3-5f01-4fcc-83cf-2b1045e5288d@q30g2000prq.googlegroups.com> On Jan 14, 1:53?pm, "bruce" wrote: > Hi... > > i have the test dict/list > ?a= {"a": 'a1',"b" : "b1"} > ?b= [{"a": 'a1',"b" : "b1"}] > > i'm trying to figure out how to programtically tell them apart... > > ie, which is a dict, and which is a list... >>> a = {"a": 'a1', "b": "b1"} >>> b = [{"a": 'a1', "b": "b1"}] >>> isinstance(a, list) False >>> isinstance(b, list) True >>> isinstance(a, dict) True >>> isinstance(b, dict) False >>> type(a) >>> type(b) >>> From mario.ruggier at gmail.com Thu Jan 15 06:29:59 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 03:29:59 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? Message-ID: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Hello, I would like to evaluate list comprehension expressions, from within which I'd like to call a function. For a first level it works fine but for second level it seems to lose the "_[1]" variable it uses internally to accumulate the results. Some sample code is: class GetItemEvaluator(object): def __init__(self): self.globals = globals() # some dict (never changes) self.globals["ts"] = self.ts self.globals["join"] = "".join self.locals = {} # changes on each evaluation def __getitem__(self, expr): return eval(expr, self.globals, self.locals) def ts(self, ts, name, value): self.locals[name] = value #print ts, name, value, "::::", self.locals, "::::", ts % self return ts % self gie = GetItemEvaluator() gie.locals["inner"] = ("a","b","c","d") print """ pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate (inner)]))s post """ % gie # OK, outputs: pre 0.a 1.b 2.c 3.d post gie = GetItemEvaluator() gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] print """ pre %(join([ts( '''inner pre %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate (inner)]))s inner post''', "inner", inner) # END CALL outer ts() for i,inner in enumerate(outer)]) )s post """ % gie The second 2-level comprehension gives: File "scratch/eval_test.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 4, in NameError: name '_[1]' is not defined If the print was to be enable, the last line printed out is: 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p i.e. it has correctly processed the first inner sequence, until the (last) "p" element. But on exit of the last inner ts() call, it seems to lose the '_[1]' on self.locals. Any ideas why? Note, i'd like that the first parameter to ts() is as independent as possible from teh context in expression context, a sort of independent mini-template. Thus, the i,j enumerate counters would normally not be subbed *within* the comprehension itself, but in a similar way to how k is evaluated, within the call to ts() -- I added them this way here to help follow easier what the execution trail is. Anyhow, within that mini-template, i'd like to embed other expressions for the % operator, and that may of course also be list comprehensions. Thanks! From gandalf at shopzeus.com Thu Jan 15 07:08:18 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 13:08:18 +0100 Subject: Slow Queue.queue? (was: slow network) In-Reply-To: <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> References: <496EF4E7.5040804@shopzeus.com> <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> Message-ID: <496F2732.8040904@shopzeus.com> > I would try something like this inside _process_outgoing: > > while not self.stop_requested.isSet(): > data_ok = False > while not self.stop_requested.isSet(): > if not self.outgoing.empty(): > try: > data = self.outgoing.get(True,0.1) > data_ok = True > break > except Queue.Empty: > pass > else: > time.sleep(0.1) # maybe, if the thread usess too much CPU > I tried your modifications. The result is 9 messages/sec. I guess it is because time.sleep(0.1) - if that is called after each message, at most 10 message/sec is possible. > The hypotesis I made for this suggestion are: > > - if the queue is found empty, the queue.get could keep the global > interpreter lock until a message arrive > (blocking also the thread that put the message in the queue) > I hope it is not that way. Consider two threads running intensive calculations. Both of them are running python code -> both of them must hold the GIL. Python runs the process on one processor, and GIL must be released on any thread that is not active on the CPU, regardless of what it is doing. > - if the queue is found empty, the handling of the exception can slows > down the execution > Because of the timeout specified in my outgoing queue get() call, the exception can only happen once per second. It won't slow down anything. > Not sure they are good guesses, because at the rate of your messages > the queue should be almost always full, > and most probably the implementation of Queue.get is smarted than > myself :-). ANyway, it is worth a try ... > The problem is with sending one message, and getting one answer for it. Most of the time, the queue is empty or has only one message inside it. > Also, is you are using fixed-length queues (the ones that make the > sender wait if the queue is full), try to increase > the queue size, or to use an infinite-size queue. > Queue size was 1000 in this example, but it never contains more than two messages. From bearophileHUGS at lycos.com Thu Jan 15 07:45:02 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 04:45:02 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> Message-ID: <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> Raymond Hettinger: > Thought you guys might enjoy this: > ? ?http://code.activestate.com/recipes/576615/ Nice and short, but it's also very slow on my PC (Psyco may help). This solves them in moments: http://labix.org/python-constraint Bye, bearophile From bearophileHUGS at lycos.com Thu Jan 15 07:48:23 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 04:48:23 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <1fadad81-e130-4fb3-a567-0d2ec18d3dad@s9g2000prg.googlegroups.com> mario ruggier, that's a hack that you can forget. Your code can't be read. Don't use list comps for that purpose. Write code that can be read. Bye, bearophile From mario.ruggier at gmail.com Thu Jan 15 07:52:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 04:52:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <89fdffe8-96db-4bde-a1a0-b3dc6753909d@k1g2000prb.googlegroups.com> On Jan 15, 12:29?pm, mario ruggier wrote: > Any ideas why? > > Note, i'd like that the first parameter to ts() is as independent as > possible from the context in expression context, a sort of independent > mini-template. Thus, the i,j enumerate counters would normally not be > subbed *within* the comprehension itself, but in a similar way to how > k is evaluated, within the call to ts() -- I added them this way here > to help follow easier what the execution trail is. Anyhow, within that > mini-template, i'd like to embed other expressions for the % operator, > and that may of course also be list comprehensions. OK, here's the same sample code somewhat simplified and maybe be easier to follow what may be going on: class GetItemEvaluator(object): def __init__(self): self.globals = globals() # some dict (never changes) self.globals["ts"] = self.ts self.globals["join"] = " ".join self.locals = {} # changes on each evaluation def __getitem__(self, expr): return eval(expr, self.globals, self.locals) def ts(self, ts): print "ts:", ts, "::::", self.locals return ts % self # one level gie = GetItemEvaluator() gie.locals["inner"] = ("a","b","c","d") TS1 = """ pre %(join([ ts('%(j)s.%(k)s') for j,k in enumerate(inner)]))s post """ OUT1 = TS1 % gie print "Output 1:", OUT1 # two level gie = GetItemEvaluator() gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] TS2 = """ leading %(join([ ts( ''' pre %(join([ ts('%(i)s.%(j)s.%(k)s') for j,k in enumerate(inner)]))s post ''' # identical to TS1, except for additional '%(s)s.' ) for i,inner in enumerate(outer)]) )s trailing """ OUT2 = TS2 % gie print "Output 2:", OUT2 As the gie.locals dict is being automagically updated from within the list comprehension expression, I simplified the previous call to ts(). Thus, executing this with the prints enabled as shown will produce the following output: $ python2.6 scratch/eval_test_4.py ts: %(j)s.%(k)s :::: {'_[1]': [], 'k': 'a', 'j': 0, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a'], 'k': 'b', 'j': 1, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a', '1.b'], 'k': 'c', 'j': 2, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a', '1.b', '2.c'], 'k': 'd', 'j': 3, 'inner': ('a', 'b', 'c', 'd')} Output 1: pre 0.a 1.b 2.c 3.d post ts: pre %(join([ ts('%(i)s.%(j)s.%(k)s') for j,k in enumerate(inner)]))s post :::: {'_[1]': [], 'i': 0, 'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'm', 'j': 0, '_[1]': [], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'n', 'j': 1, '_[1]': ['0.0.m'], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'o', 'j': 2, '_[1]': ['0.0.m', '0.1.n'], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m', '0.1.n', '0.2.o'], 'inner': ('m', 'n', 'o', 'p')} Traceback (most recent call last): File "scratch/eval_test.py", line 40, in OUT2 = TS2 % gie File "scratch/eval_test_4.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 9, in NameError: name '_[1]' is not defined Anyone can help clarify what may be going on? m. From mario.ruggier at gmail.com Thu Jan 15 07:58:01 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 04:58:01 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <1fadad81-e130-4fb3-a567-0d2ec18d3dad@s9g2000prg.googlegroups.com> Message-ID: <6561ba8b-8c45-4912-8146-91c718a2369a@p2g2000prf.googlegroups.com> On Jan 15, 1:48?pm, bearophileH... at lycos.com wrote: > mario ruggier, that's a hack that you can forget. Your code can't be > read. Don't use list comps for that purpose. Write code that can be > read. Ya, agree with you whole-heartily, but then so are most optimizations ;-) It is just an idea I am exploring, and that code would be never be humanly written (that's why it seems more convoluted than necessary). I hope the simplified boiled down sample gets the intention out better... i'd still would like to understand why the '_ [1]' variable is disappearing after first inner loop! > Bye, > bearophile From __peter__ at web.de Thu Jan 15 08:02:54 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 14:02:54 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: mario ruggier wrote: > Hello, > > I would like to evaluate list comprehension expressions, from within > which I'd like to call a function. For a first level it works fine but > for second level it seems to lose the "_[1]" variable it uses > internally to accumulate the results. Some sample code is: > > class GetItemEvaluator(object): > def __init__(self): > self.globals = globals() # some dict (never changes) > self.globals["ts"] = self.ts > self.globals["join"] = "".join > self.locals = {} # changes on each evaluation > def __getitem__(self, expr): > return eval(expr, self.globals, self.locals) > def ts(self, ts, name, value): > self.locals[name] = value > #print ts, name, value, "::::", self.locals, "::::", ts % self > return ts % self > > gie = GetItemEvaluator() > gie.locals["inner"] = ("a","b","c","d") > print """ > pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate > (inner)]))s post > """ % gie > # OK, outputs: pre 0.a 1.b 2.c 3.d post > > gie = GetItemEvaluator() > gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] > print """ > pre %(join([ts( > '''inner pre > %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate > (inner)]))s > inner post''', > "inner", inner) # END CALL outer ts() > for i,inner in enumerate(outer)]) > )s post > """ % gie > > The second 2-level comprehension gives: > > File "scratch/eval_test.py", line 8, in __getitem__ > return eval(expr, self.globals, self.locals) > File "", line 4, in > NameError: name '_[1]' is not defined > > If the print was to be enable, the last line printed out is: > > 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', > 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o > '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p > > i.e. it has correctly processed the first inner sequence, until the > (last) "p" element. But on exit of the last inner ts() call, it seems > to lose the '_[1]' on self.locals. > > Any ideas why? > > Note, i'd like that the first parameter to ts() is as independent as > possible from teh context in expression context, a sort of independent > mini-template. Thus, the i,j enumerate counters would normally not be > subbed *within* the comprehension itself, but in a similar way to how > k is evaluated, within the call to ts() -- I added them this way here > to help follow easier what the execution trail is. Anyhow, within that > mini-template, i'd like to embed other expressions for the % operator, > and that may of course also be list comprehensions. I have no idea what you are trying to do. Please reread the Zen of Python ;) What happens is: List comprehensions delete the helper variable after completion: >>> def f(): [i for i in [1]] ... >>> dis.dis(f) 1 0 BUILD_LIST 0 3 DUP_TOP 4 STORE_FAST 0 (_[1]) 7 LOAD_CONST 1 (1) 10 BUILD_LIST 1 13 GET_ITER >> 14 FOR_ITER 13 (to 30) 17 STORE_FAST 1 (i) 20 LOAD_FAST 0 (_[1]) 23 LOAD_FAST 1 (i) 26 LIST_APPEND 27 JUMP_ABSOLUTE 14 >> 30 DELETE_FAST 0 (_[1]) 33 POP_TOP 34 LOAD_CONST 0 (None) 37 RETURN_VALUE If you manage to run two nested listcomps in the same namespace you get a name clash and the inner helper variable overwrites/deletes the outer: >>> def xeval(x): return eval(x, ns) ... >>> ns = dict(xeval=xeval) >>> xeval("[xeval('[k for k in ()]') for i in (1,)]") Traceback (most recent call last): File "", line 1, in File "", line 1, in xeval File "", line 1, in NameError: name '_[1]' is not defined Peter From __peter__ at web.de Thu Jan 15 08:19:10 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 14:19:10 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Peter Otten wrote: > mario ruggier wrote: > >> Hello, >> >> I would like to evaluate list comprehension expressions, from within >> which I'd like to call a function. For a first level it works fine but >> for second level it seems to lose the "_[1]" variable it uses >> internally to accumulate the results. Some sample code is: >> >> class GetItemEvaluator(object): >> def __init__(self): >> self.globals = globals() # some dict (never changes) >> self.globals["ts"] = self.ts >> self.globals["join"] = "".join >> self.locals = {} # changes on each evaluation >> def __getitem__(self, expr): >> return eval(expr, self.globals, self.locals) >> def ts(self, ts, name, value): >> self.locals[name] = value >> #print ts, name, value, "::::", self.locals, "::::", ts % self >> return ts % self >> >> gie = GetItemEvaluator() >> gie.locals["inner"] = ("a","b","c","d") >> print """ >> pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate >> (inner)]))s post >> """ % gie >> # OK, outputs: pre 0.a 1.b 2.c 3.d post >> >> gie = GetItemEvaluator() >> gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] >> print """ >> pre %(join([ts( >> '''inner pre >> %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate >> (inner)]))s >> inner post''', >> "inner", inner) # END CALL outer ts() >> for i,inner in enumerate(outer)]) >> )s post >> """ % gie >> >> The second 2-level comprehension gives: >> >> File "scratch/eval_test.py", line 8, in __getitem__ >> return eval(expr, self.globals, self.locals) >> File "", line 4, in >> NameError: name '_[1]' is not defined >> >> If the print was to be enable, the last line printed out is: >> >> 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', >> 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o >> '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p >> >> i.e. it has correctly processed the first inner sequence, until the >> (last) "p" element. But on exit of the last inner ts() call, it seems >> to lose the '_[1]' on self.locals. >> >> Any ideas why? >> >> Note, i'd like that the first parameter to ts() is as independent as >> possible from teh context in expression context, a sort of independent >> mini-template. Thus, the i,j enumerate counters would normally not be >> subbed *within* the comprehension itself, but in a similar way to how >> k is evaluated, within the call to ts() -- I added them this way here >> to help follow easier what the execution trail is. Anyhow, within that >> mini-template, i'd like to embed other expressions for the % operator, >> and that may of course also be list comprehensions. > > I have no idea what you are trying to do. Please reread the Zen of Python > ;) > > What happens is: > > List comprehensions delete the helper variable after completion: > >>>> def f(): [i for i in [1]] > ... >>>> dis.dis(f) > 1 0 BUILD_LIST 0 > 3 DUP_TOP > 4 STORE_FAST 0 (_[1]) > 7 LOAD_CONST 1 (1) > 10 BUILD_LIST 1 > 13 GET_ITER > >> 14 FOR_ITER 13 (to 30) > 17 STORE_FAST 1 (i) > 20 LOAD_FAST 0 (_[1]) > 23 LOAD_FAST 1 (i) > 26 LIST_APPEND > 27 JUMP_ABSOLUTE 14 > >> 30 DELETE_FAST 0 (_[1]) > 33 POP_TOP > 34 LOAD_CONST 0 (None) > 37 RETURN_VALUE > > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > >>>> def xeval(x): return eval(x, ns) > ... >>>> ns = dict(xeval=xeval) >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in xeval > File "", line 1, in > NameError: name '_[1]' is not defined > > Peter > I'd like to add: this can only happen because the code snippets are compiled independently. Otherwise Python uses different names for each listcomp: >>> def f(): ... [i for i in ()] ... [i for i in ()] ... >>> f.func_code.co_varnames ('_[1]', 'i', '_[2]') Peter From mario.ruggier at gmail.com Thu Jan 15 08:22:26 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 05:22:26 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <0d850f42-5560-4d76-929c-0f700c10c866@v5g2000prm.googlegroups.com> On Jan 15, 2:02?pm, Peter Otten <__pete... at web.de> wrote: > mario ruggier wrote: > > Hello, > > > I would like to evaluate list comprehension expressions, from within > > which I'd like to call a function. For a first level it works fine but > > for second level it seems to lose the "_[1]" variable it uses > > internally to accumulate the results. Some sample code is: > > > class GetItemEvaluator(object): > > ? ? def __init__(self): > > ? ? ? ? self.globals = globals() # some dict (never changes) > > ? ? ? ? self.globals["ts"] = self.ts > > ? ? ? ? self.globals["join"] = "".join > > ? ? ? ? self.locals = {} # changes on each evaluation > > ? ? def __getitem__(self, expr): > > ? ? ? ? return eval(expr, self.globals, self.locals) > > ? ? def ts(self, ts, name, value): > > ? ? ? ? self.locals[name] = value > > ? ? ? ? #print ts, name, value, "::::", self.locals, "::::", ts % self > > ? ? ? ? return ts % self > > > gie = GetItemEvaluator() > > gie.locals["inner"] = ("a","b","c","d") > > print """ > > pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate > > (inner)]))s post > > """ % gie > > # OK, outputs: pre 0.a 1.b 2.c 3.d ?post > > > gie = GetItemEvaluator() > > gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] > > print """ > > pre %(join([ts( > > ? '''inner pre > > ? %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate > > (inner)]))s > > ? ?inner post''', > > ? "inner", inner) # END CALL outer ts() > > ? for i,inner in enumerate(outer)]) > > )s post > > """ % gie > > > The second 2-level comprehension gives: > > > ? File "scratch/eval_test.py", line 8, in __getitem__ > > ? ? return eval(expr, self.globals, self.locals) > > ? File "", line 4, in > > NameError: name '_[1]' is not defined > > > If the print was to be enable, the last line printed out is: > > > 0.3.%(k)s ?k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', > > 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o > > '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p > > > i.e. it has correctly processed the first inner sequence, until the > > (last) "p" element. But on exit of the last inner ts() call, it seems > > to lose the '_[1]' on self.locals. > > > Any ideas why? > > > Note, i'd like that the first parameter to ts() is as independent as > > possible from teh context in expression context, a sort of independent > > mini-template. Thus, the i,j enumerate counters would normally not be > > subbed *within* the comprehension itself, but in a similar way to how > > k is evaluated, within the call to ts() -- I added them this way here > > to help follow easier what the execution trail is. Anyhow, within that > > mini-template, i'd like to embed other expressions for the % operator, > > and that may of course also be list comprehensions. > > I have no idea what you are trying to do. Please reread the Zen of Python ;) > > What happens is: > > List comprehensions delete the helper variable after completion: > > >>> def f(): [i for i in [1]] > ... > >>> dis.dis(f) > > ? 1 ? ? ? ? ? 0 BUILD_LIST ? ? ? ? ? ? ? 0 > ? ? ? ? ? ? ? 3 DUP_TOP > ? ? ? ? ? ? ? 4 STORE_FAST ? ? ? ? ? ? ? 0 (_[1]) > ? ? ? ? ? ? ? 7 LOAD_CONST ? ? ? ? ? ? ? 1 (1) > ? ? ? ? ? ? ?10 BUILD_LIST ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ?13 GET_ITER > ? ? ? ? >> ? 14 FOR_ITER ? ? ? ? ? ? ? ?13 (to 30) > ? ? ? ? ? ? ?17 STORE_FAST ? ? ? ? ? ? ? 1 (i) > ? ? ? ? ? ? ?20 LOAD_FAST ? ? ? ? ? ? ? ?0 (_[1]) > ? ? ? ? ? ? ?23 LOAD_FAST ? ? ? ? ? ? ? ?1 (i) > ? ? ? ? ? ? ?26 LIST_APPEND > ? ? ? ? ? ? ?27 JUMP_ABSOLUTE ? ? ? ? ? 14 > ? ? ? ? >> ? 30 DELETE_FAST ? ? ? ? ? ? ?0 (_[1]) > ? ? ? ? ? ? ?33 POP_TOP > ? ? ? ? ? ? ?34 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?37 RETURN_VALUE > > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > > >>> def xeval(x): return eval(x, ns) > ... > >>> ns = dict(xeval=xeval) > >>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 1, in xeval > ? File "", line 1, in > NameError: name '_[1]' is not defined > > Peter Ah, brilliant, thanks for the clarification! To verify if I understood you correctly, I have modified the ts() method above to: def ts(self, ts): _ns = self.locals self.locals = self.locals.copy() print "ts:", ts, "::::", self.locals try: return ts % self finally: self.locals = _ns And, it executes correctly, thus the 2nd output is: Output 2: leading pre 0.0.m 0.1.n 0.2.o 0.3.p post pre 1.0.q 1.1.r 1.2.s 1.3.t post trailing But, the need to do a copy() will likely kill any potential optimization gains... so, I will only be forced to rite more readable code ;-) Thanks! From google at mrabarnett.plus.com Thu Jan 15 08:56:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 13:56:57 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: <496F40A9.1040709@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. > You could say the same about s.startswith(("a", "b")). It might be because sets are a more recent addition to the language; if they had been in Python from the start then maybe they would've been used instead. From kyrie at uh.cu Thu Jan 15 08:57:17 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Thu, 15 Jan 2009 08:57:17 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz5gvfs.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Message-ID: <1232027837.496f40bd5a3d3@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Luis Zarrabeitia writes: > > Wait, do you _really_ believe that _static_ checks could prevent problems > > arising from _unexpected_ conditions in the _data_? > > The data does not arrive from outer space on a magtape stapled to a > meteor. It comes out of another program. Most of the problems in > processing it come from mismatches between the processing programs and > the generation programs. Static checks would help eliminate those > mismatches. No, copy and paste from the original data structures would eliminate those mismatches. A compiler checking the reimplementation of said data structres, whatever the language, has no way of knowing if the structure matches. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From roy at panix.com Thu Jan 15 09:20:13 2009 From: roy at panix.com (Roy Smith) Date: Thu, 15 Jan 2009 09:20:13 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwscx6zfo.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > basically I think C is evil. C is not evil. It's a tool. Would you call a hammer evil because it's not very good at driving screws? C is a very good tool for doing the kind of thing it was designed for, which is highly efficient, low-level, portable programming. The fact that C has been used to write all sorts of large-scale applications doesn't mean that it's good at that kind of stuff. It just means that all the alternatives suck more than it does for that kind of stuff. If you want evil, look at C++. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:27:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:27:49 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> <7x3afl3v00.fsf@ruckus.brouhaha.com> Message-ID: <017f3e72$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 23:10:07 -0800, Paul Rubin wrote: > I think this sub-thread has been mostly about dynamically creating new > class instance attributes, but yes, at one point I did suggest adding > type checking (ML-like inference) to pylint, presumably with feedback to > the compiler for optimization purposes. I noted that Python 3.0 in fact > has some features to support annotations for the purpose of static type > checking, so it's not as far off the wall as it might sound. I fear anything that will lead Python moving towards C/Pascal/Java type declarations, but I feel great enthusiasm at the thought that maybe by the time we get to Python 4.0 there will be type inference which could enable compiler optimizations. Exciting times people, exciting times. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:31:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:31:45 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <017f3f5d$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 23:05:32 -0800, Russ P. wrote: > On Jan 14, 10:40?pm, "James Mills" wrote: >> On Thu, Jan 15, 2009 at 4:34 PM, Michele >> Simionato wrote: >> >> (...) >> >> > There are lots of Python developers (and most of the core developers) >> > that think the OO community is wrong about enforced encapsulation. >> > Personally, I think in a few years everybody will realize the mistake >> > of enforced encapsulation and that the OO definition in the Wikipedia >> > page will be changed. Even if not, Wikipedia definitions does not >> > matter much, everybody has his own idea of what OO means, and the >> > Python definition is good as any other. Don't get pissed off on >> > words. >> >> Amen! The first thing said right in this entire thread! (one of) >> >> --JamesMills > > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming is > written in smoke? Be fair -- James just admitted that everything he's written in this thread is wrong. If Michele's post was, and I quote James, "the first thing said right in this entire thread", then obviously everything James wrote previously was wrong. *wink* -- Steven From gaius.julius at gmail.com Thu Jan 15 09:44:41 2009 From: gaius.julius at gmail.com (gaius.julius) Date: Thu, 15 Jan 2009 06:44:41 -0800 (PST) Subject: multiprocessing BaseManager doesn't clean up net connections? References: Message-ID: <8a5989f3-1ffa-430b-8500-ad7aad4609da@35g2000pry.googlegroups.com> Hi, Having exactly the same problem. It appears even if I explicitly call manager's shutdown() method. Not sure it is a bug, though. But also didn't find anything in documentation or source code or debug output. On Jan 1, 8:01?am, Chris Brooks wrote: > Hi, > > I'm trying to use remote managers in the multiprocessing module to listen > for some events synchronously while my program goes off and does other > things. ?I use the .start() method which forks a new process to handle > communication. ?When I catch the sigint and call sys.exit() though, the > network port is still bound even after the python interpretor finishes. > Here is my short code and the output: > From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:54:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:54:15 GMT Subject: General direction References: <6t8comF9ou5uU1@mid.uni-berlin.de> Message-ID: <017f44a3$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > MLT schrieb: >> Hello all: I'm a beginner to Python (and programming altogether), and >> am now looking to create a program of my own. What I've got in mind is >> a very basic pest control program that would keep track of 1) trap >> findings and 2) pesticides. My thought is to make each of these >> classes. Looking at the general outline written below, can anyone give >> general impression about whether I'm somewhat going in the right >> direction or if I need to approach it entirely differently? Thanks for >> any suggestions or help! > > Familiarize yourself with PEP8 for naming and coding-conventions first. Or not. Enough of the PEP8-fascism please. It is not compulsory to follow PEP8 in order to be allowed to learn Python. If Guido wanted it compulsory, he'd have made the compiler enforce it. Besides, you're talking to a newbie. Chances are he doesn't even know what PEP8 is: the recommended style-guide for Python code. http://www.python.org/dev/peps/pep-0008/ Having said that, I will *suggest* to the Original Poster that you should follow PEP8 as much as possible. It will save you a lot of grief in the long run. But right now, it is more important to learn the language than to learn conventions for how to name classes. If you can do both, great, but don't let the naming conventions get in the way. -- Steve From mail at anjanesh.net Thu Jan 15 09:54:59 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 15 Jan 2009 20:24:59 +0530 Subject: Py3 - converting bytes to ascii Message-ID: <1a7951080901150654i7be7fa8dj873acb1ecbb102c3@mail.gmail.com> Using Python 3.0 res = urllib.request.urlopen(url) f = open('file.txt', 'wb') # Since res.read() returns bytes f.write(res.read()) But newline and return feeds are stored as b14, 58a as text in the text file. So how do I to convert res.read() to ascii on opening the file in ascii mode f = open('file.txt', 'w')? Thanks From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 10:06:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 15:06:41 GMT Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <017f478e$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 03:29:59 -0800, mario ruggier wrote: > Hello, > > I would like to evaluate list comprehension expressions, from within > which I'd like to call a function. For a first level it works fine but > for second level it seems to lose the "_[1]" variable it uses internally > to accumulate the results. Some sample code is: > > class GetItemEvaluator(object): > def __init__(self): > self.globals = globals() # some dict (never changes) Would you like to put a small wager on that? >>> len(gie.globals) 64 >>> something_new = 0 >>> len(gie.globals) 65 > self.globals["ts"] = self.ts > self.globals["join"] = "".join > self.locals = {} # changes on each evaluation > def __getitem__(self, expr): > return eval(expr, self.globals, self.locals) Can you say "Great Big Security Hole"? >>> gie = GetItemEvaluator() >>> gie['__import__("os").system("ls")'] dicttest dumb.py rank.py sorting startup.py 0 http://cwe.mitre.org/data/definitions/95.html -- Steven From james.colin.brady at gmail.com Thu Jan 15 10:11:01 2009 From: james.colin.brady at gmail.com (James Brady) Date: Thu, 15 Jan 2009 07:11:01 -0800 (PST) Subject: Readline and Python 2.6.1 on a Mac Message-ID: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Hi, I just upgraded Python from 2.5.2 up to 2.6.1 on my 10.5 Mac (installed from the DMG here: http://www.python.org/download/releases/2.6.1/), and I'm having some problems with readline and rl_completer. I have PYTHONSTARTUP pointing to this file: #!/usr/bin/env python try: import readline except ImportError: print "Module readline not available." else: import rlcompleter readline.parse_and_bind("bind ^I rl_complete") Which was working fine for tab completion in 2.5. Now, however, I can't enter 'b' (lower case b) in interactive python shells - no character appears. Just b is broken - 'B' is fine, Ctrl-b is fine, Alt-b even prints an integration symbol, but 'b' - nothing! Has anyone seen this before? From rt8396 at gmail.com Thu Jan 15 10:28:36 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 07:28:36 -0800 (PST) Subject: Possible bug in Tkinter - Python 2.6 References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> Message-ID: <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> First of all be very careful using from "module" import * or you will have name conflicts. Tkinter is made to be imported this way and i do it all the time. for the others do. import tkMessageBox as MB import tkFileDialog as FD or whatever floats your boat. Secondly i hear all the time about problems with fedora distros, so that would explain the issue to me. From debski.jakub at wp.pl Thu Jan 15 10:41:53 2009 From: debski.jakub at wp.pl (Jakub Debski) Date: Thu, 15 Jan 2009 16:41:53 +0100 Subject: Executing global code Message-ID: Hi, Is it possible to execute global code (module-level code) more than once keeping the state of global variables? This means no reload() and no moving the code to a function. regards, Jakub From thomasmallen at gmail.com Thu Jan 15 10:46:30 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 07:46:30 -0800 (PST) Subject: Wx broken? Message-ID: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> I've tried a few of the examples from http://wiki.wxpython.org/Getting%20Started , but after "Hello World" (window) nothing works. I get the following error message with the other examples: Traceback (most recent call last): File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py", line 1, in import wx File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx \__init__.py", line 45, in from wx._core import * File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 6, in new_instancemethod = new.instancemethod AttributeError: 'module' object has no attribute 'instancemethod' Here's a snippet that generates this error: http://pastebin.com/m2b4f4f9c For those familiar with wx here, is this a bug in the library, or should I be providing "instancemethod" at some point? Seeing that it's an unhandled exception, I do expect the former. Thanks, Thomas From thomasmallen at gmail.com Thu Jan 15 10:52:05 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 07:52:05 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: <2a4fc5ac-b245-4bf0-88b3-d0c19bf1faeb@v39g2000pro.googlegroups.com> On Jan 15, 10:46?am, tmallen wrote: > I've tried a few of the examples fromhttp://wiki.wxpython.org/Getting%20Started > , but after "Hello World" (window) nothing works. I get the following > error message with the other examples: > > Traceback (most recent call last): > ? File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py", > line 1, in > ? ? import wx > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx > \__init__.py", line 45, in > ? ? from wx._core import * > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 6, in > ? ? new_instancemethod = new.instancemethod > AttributeError: 'module' object has no attribute 'instancemethod' > > Here's a snippet that generates this error:http://pastebin.com/m2b4f4f9c > > For those familiar with wx here, is this a bug in the library, or > should I be providing "instancemethod" at some point? Seeing that it's > an unhandled exception, I do expect the former. > > Thanks, > Thomas Looking a little closer, this is what's causing the bug: Wx: _core.py, lines 1-6: # This file was created automatically by SWIG 1.3.29. # Don't modify this file, modify the SWIG interface instead. import _core_ import new new_instancemethod = new.instancemethod On this Win32 box, the "new" module doesn't have the "instancemethod" attribute. What is new.instancemethod used for? "new_instancemethod," which should be assigned to the attr, does not show up again in this particular source file. Thanks, Thomas From Caseyweb at gmail.com Thu Jan 15 10:53:25 2009 From: Caseyweb at gmail.com (Casey) Date: Thu, 15 Jan 2009 07:53:25 -0800 (PST) Subject: Py3 - converting bytes to ascii References: Message-ID: On Jan 15, 9:54?am, "Anjanesh Lekshminarayanan" wrote: > Using Python 3.0 > > So how do I to convert res.read() to ascii on opening the file in > ascii mode f = open('file.txt', 'w')? > I think this is what you are looking for: res = urllib.request.urlopen(url) f = open('file.txt', 'w') f.write(res.read().decode('ascii')) From mario.ruggier at gmail.com Thu Jan 15 10:56:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 07:56:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 15, 4:06?pm, Steven D'Aprano wrote: Hi Steve! > > class GetItemEvaluator(object): > > ? ? def __init__(self): > > ? ? ? ? self.globals = globals() # some dict (never changes) Ya, this is just a boiled down sample, and for simplicity I set to to the real globals(), so of course it will change when that changes... but in the application this is a distinct dict, that is entirely managed by the application, and it never changes as a result of an *evaluation*. > Would you like to put a small wager on that? > > >>> len(gie.globals) > 64 > >>> something_new = 0 > >>> len(gie.globals) > > 65 > > ? ? ? ? self.globals["ts"] = self.ts > > ? ? ? ? self.globals["join"] = "".join > > ? ? ? ? self.locals = {} # changes on each evaluation > > ? ? def __getitem__(self, expr): > > ? ? ? ? return eval(expr, self.globals, self.locals) > > Can you say "Great Big Security Hole"? With about the same difficulty as "Rabbit-Proof Fence" ;-) Again, it is just a boiled down sample, for communication purposes. As I mentioned in another thread, the real application behind all this is one of the *few* secure templating systems around. Some info on its security is at: http://evoque.gizmojo.org/usage/restricted/ Tell you what, if you find a security hole there (via exposed template source on a Domain(restricted=True) setup) I'll offer you a nice dinner (including the beer!) somewhere, maybe at some py conference, but even remotely if that is not feasible... ;-) The upcoming 0.4 release will run on 2.4 thru to 3.0 -- you can have some fun with that one (the current 0.3 runs on 2.5 and 2.6). > -- > Steven Cheers, mario From pornbypost at gmail.com Thu Jan 15 10:56:16 2009 From: pornbypost at gmail.com (Mark Smith) Date: Thu, 15 Jan 2009 07:56:16 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 6, in > ? ? new_instancemethod = new.instancemethod > AttributeError: 'module' object has no attribute 'instancemethod' I'm guessing you either have a python file called 'new.py' in your working directory, or you have one in your pythonpath. --Mark From thomasmallen at gmail.com Thu Jan 15 11:00:55 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 08:00:55 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: On Jan 15, 10:56?am, Mark Smith wrote: > > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > > line 6, in > > ? ? new_instancemethod = new.instancemethod > > AttributeError: 'module' object has no attribute 'instancemethod' > > I'm guessing you either have a python file called 'new.py' in your > working directory, or you have one in your pythonpath. > > --Mark That's correct. Thanks! Thomas From arve.knudsen at gmail.com Thu Jan 15 11:02:03 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Thu, 15 Jan 2009 08:02:03 -0800 (PST) Subject: Embedding Python and program path Message-ID: <8d0c09bb-26e3-4006-9f60-7a20e126a936@w1g2000prm.googlegroups.com> In my application embedding Python I want to have the standard Python module path, so I try to achieve this by setting the program path to that of the the interpreter. Even though I call Py_SetProgramName before Py_InitializeEx, however, Python thinks the program path (as returned by Py_GetProgramFullPath) is that of my embedding executable. I would love if someone could explain what is going wrong here, and eventually provide a better solution for inheriting the Python interpreter's standard module path. Test application demonstrating the problem. #include int main() { // Hardcoded for simplicity Py_SetProgramName("C:\\Python26\\python.exe"); Py_InitializeEx(0); printf("Program path: %s\n", Py_GetProgramFullPath()); Py_Finalize(); return 0; } Thanks, Arve Knudsen From mario.ruggier at gmail.com Thu Jan 15 11:09:53 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 08:09:53 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <88f780f2-64bb-4209-83ce-bb0fba130691@n33g2000pri.googlegroups.com> The listcomps exploration above was primarily an attempt (unsuccessful) to make this piece of code go a little faster: s = " text %(item)s text " acc = [] for value in iterator: some_dict["item"] = value acc.append(s % evaluator) "".join(acc) The item=value pair is essentially a loop variable, and the evaluator (something like the gie instance above) uses it via the updated some_dict. Is there any way to express the above as a list comp or so? Any ideas how it might be made to go faster? m. From thomas.steffen75 at googlemail.com Thu Jan 15 11:23:12 2009 From: thomas.steffen75 at googlemail.com (thomas.steffen75 at googlemail.com) Date: Thu, 15 Jan 2009 08:23:12 -0800 (PST) Subject: the name of a method Message-ID: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Hello, I have a Class: class myClass: def __init__(self): # do something print "name of class = " + self.__class__.__name__ def myMethod(self): # do something print "name of method = " + "myMethod" return ... I print the name of the class with self.__class__.__name__ in __init__. I want to print also in every method of myClass the name of the method. How can I get the name? I would not like to write e.g. "myMethod". Is there a variable like self.__class__.__name__ for this? Thanks for your hints, Thomas From deets at nospam.web.de Thu Jan 15 11:37:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 15 Jan 2009 17:37:16 +0100 Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Message-ID: <6t971sF9gm58U1@mid.uni-berlin.de> thomas.steffen75 at googlemail.com wrote: > Hello, > > I have a Class: > > class myClass: > def __init__(self): > # do something > print "name of class = " + self.__class__.__name__ > > def myMethod(self): > # do something > print "name of method = " + "myMethod" > return > > ... > > I print the name of the class with self.__class__.__name__ in > __init__. > I want to print also in every method of myClass the name of the > method. > How can I get the name? I would not like to write e.g. "myMethod". Is > there a variable like self.__class__.__name__ for this? > Thanks for your hints, Thomas This can be done by inspecting the stackframes. Look into the module inspect. This has also been discussed very often on this list, stackframe & inspect should be good searchterms. However, if what you are after is logging, you should take a look into the logging module. it has many advantages over simple print-statements, and amongst other things allows you to print out the enclosing callable name when invoked ala logger.debug("Some message.") I strongly recommend using that. And at least you can of course peek into the logging module's source to see how the extract that information. Diez From LambertDW at Corning.com Thu Jan 15 11:50:22 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Thu, 15 Jan 2009 11:50:22 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> I have use case, needn't be dynamic, and it's not hard to enclose set as tuple. But I also write (for example) __all__ = 'this that other'.split() string_list = 'evenOneWord'.split() instead of __all__ = 'this','that','imTiredOfMistypingCommasAndQuotes' if not isinstance(o,set_of_handled_types): raise TypeError('call blessed programmer, this cannot occur') if isinstance(o,set_of_handle_types-treat_differently): treat_thusly(o) elif isinstance(o,treat_differently): treat_differently(o) elif etc. From __peter__ at web.de Thu Jan 15 11:50:54 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 17:50:54 +0100 Subject: Executing global code References: Message-ID: Jakub Debski wrote: > Is it possible to execute global code (module-level code) more than > once keeping the state of global variables? This means no reload() and > no moving the code to a function. You have a module containing e. g. these two statements x = 42 x += 1 and want to rerun it with the effect of x becoming 44? That is not possible because in Python x = 42 is a statement, too, and will thus be rerun. Peter From jason.scheirer at gmail.com Thu Jan 15 11:56:11 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Thu, 15 Jan 2009 08:56:11 -0800 (PST) Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> <6t971sF9gm58U1@mid.uni-berlin.de> Message-ID: <5e0e0841-ae66-4645-8ab6-50be94004e0b@a29g2000pra.googlegroups.com> On Jan 15, 8:37?am, "Diez B. Roggisch" wrote: > thomas.steffe... at googlemail.com wrote: > > Hello, > > > I have a Class: > > > class myClass: > > ? ? def __init__(self): > > ? ? ? ? # do something > > ? ? ? ? print "name of class = " + ?self.__class__.__name__ > > > ? ? def myMethod(self): > > ? ? ? ? # do something > > ? ? ? ? print "name of method = " + "myMethod" > > ? ? ? ? return > > > ? ? ... > > > I print the name of the class with self.__class__.__name__ in > > __init__. > > I want to print also in every method of myClass the name of the > > method. > > How can I get the name? I would not like to write e.g. "myMethod". Is > > there a variable like self.__class__.__name__ for this? > > Thanks for your hints, Thomas > > This can be done by inspecting the stackframes. Look into the module > inspect. This has also been discussed very often on this list, stackframe & > inspect should be good searchterms. > > However, if what you are after is logging, you should take a look into the > logging module. it has many advantages over simple print-statements, and > amongst other things allows you to print out the enclosing callable name > when invoked ala > > logger.debug("Some message.") > > I strongly recommend using that. And at least you can of course peek into > the logging module's source to see how the extract that information. > > Diez I agree, this should not be done. However, sometimes it's useful to see the parameter values: import inspect import logging import sys def log_fn(): logging.debug("%s%s" % ( sys._getframe().f_back.f_code.co_name, inspect.formatargvalues(*inspect.getargvalues(sys._getframe ().f_back)))) logging.getLogger().setLevel(0) def hello_there(x, y, z, *a): log_fn() return 1+x >>> hello_there(1, 'a', 'b', 5, 6, 7, 8, 9) DEBUG:root:hello_there(x=1, y='a', z='b', *a=(5, 6, 7, 8, 9)) It can be done, but usually you want to actually trace through with the debugger. From http Thu Jan 15 12:07:00 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:07:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Message-ID: <7xk58wwlaj.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > No, copy and paste from the original data structures would eliminate those > mismatches. The whole point is that would be possible if Python had data structure definitions ("types") that were possible to copy and paste from some single location, instead of building up structures dynamically, adding fields on the fly in ways that have become obscure over the evolution of the code. From siona at chiark.greenend.org.uk Thu Jan 15 12:09:14 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 15 Jan 2009 17:09:14 +0000 (GMT) Subject: mimetypes oddity Message-ID: >>> ge = mimetypes.guess_extension >>> ge('image/jpeg') '.jpe' >>> ge('image/jpeg') '.jpeg' >>> I actually discovered this through explicitly calling mimetypes.init to reload an edited mime.types file between calls to guess_extension, but I think the above scenario makes for more disturbing reading 8-) The problem is that mimetools initialises its type mapping dict before adding new type mappings from a file by iterating through the existing type mapping dict. This process is bootstrapped by a hard- coded dict which gets shadowed by the first file read, so the second file read uses a dict initialsed from the dict created by the first file read (got that?) which has a different iteration order to the hard-coded dict. So the mappings get added in a different order the second time around, and where there are multiple mappings like this you get a different answer. Is this a bug? If I want to be sure of a consistent result, do I need to use sorted(mimetools.guess_all_extensions(t))[0] (or [-1])? -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From ifl2009 at shu.edu Thu Jan 15 12:09:43 2009 From: ifl2009 at shu.edu (IFL 2009) Date: Thu, 15 Jan 2009 12:09:43 -0500 Subject: IFL 2009: Call for Papers Message-ID: Call for Papers IFL 2009 Seton Hall University SOUTH ORANGE, NJ, USA http://tltc.shu.edu/blogs/projects/IFL2009/ The 21st IFL symposium, IFL 2009, will be held for the first time in the USA. The hosting institution is Seton Hall University in South Orange, NJ, USA and the symposium dates are September 23-25, 2009. It is our goal to make IFL a regular event held in the USA. The goal of the IFL symposia is to bring together researchers actively engaged in the implementation and application of functional and function-based programming languages. IFL 2009 will be a venue for researchers to present and discuss new ideas and concepts, work in progress, and publication-ripe results related to the implementation and application of functional languages and function-based programming. Following the IFL tradition, IFL 2009 will use a post-symposium review process to produce a formal proceedings which we expect to be published by Springer in the Lecture Notes in Computer Science series. All participants in IFL 2009 are invited to submit either a draft paper or and extended abstract describing work to be presented at the symposium. These submissions will be screened by the program committee chair to make sure they are within the scope of IFL and will appear in the draft proceedings distributed at the symposium. Submissions appearing in the draft proceedings are not peer-reviewed publications. After the symposium, authors will be given the opportunity to incorporate the feedback from discussions at the symposium and will be invited to submit a revised full arcticle for the formal review process. These revised submissions will be reviewed by the program committee using prevailing academic standards to select the best articles that will appear in the formal proceedings. TOPICS IFL welcomes submissions describing practical and theoretical as well as submissions describing applications and tools. If you are not sure if your work is appropriate for IFL 2009, please contact the PC chair at ifl2009 at shu.edu. Topics of interest include, but are not limited to: language concepts type checking contracts compilation techniques staged compilation runtime function specialization runtime code generation partial evaluation (abstract) interpretation generic programming techniques automatic program generation array processing concurrent/parallel programming concurrent/parallel program execution functional programming and embedded systems functional programming and web applications functional programming and security novel memory management techniques runtime profiling and performance measurements debugging and tracing virtual/abstract machine architectures validation and verification of functional programs tools and programming techniques PAPER SUBMISSIONS Prospective authors are encouraged to submit papers or extended abstracts to be published in the draft proceedings and to present them at the symposium. All contributions must be written in English, conform to the Springer-Verlag LNCS series format and not exceed 16 pages. The draft proceedings will appear as a technical report of the Department of Mathematics and Computer Science of Seton Hall University. IMPORTANT DATES Registration deadline August 15, 2009 Presentation submission deadline August 15, 2009 IFL 2009 Symposium September 23-25, 2009 Submission for review process deadline November 1, 2009 Notification Accept/Reject December 22, 2009 Camera ready version January 15, 2010 PROGRAM COMMITTEE Peter Achten University of Nijmegen, The Netherlands Jost Berthold Philipps-Universit?t Marburg, Germany Andrew Butterfield University of Dublin, Ireland Robby Findler Northwestern University, USA Kathleen Fisher AT&T Research, USA Cormac Flanagan University of California at Santa Cruz, USA Matthew Flatt University of Utah, USA Matthew Fluet Toyota Technological Institute at Chicago, USA Daniel Friedman Indiana University, USA Andy Gill University of Kansas, USA Clemens Grelck University of Amsterdam/Hertfordshire, The Netherlands/UK Jurriaan Hage Utrecht University, The Netherlands Ralf Hinze Oxford University, UK Paul Hudak Yale University, USA John Hughes Chalmers University of Technology, Sweden Patricia Johann University of Strathclyde, UK Yukiyoshi Kameyama University of Tsukuba, Japan Marco T. Moraz?n (Chair) Seton Hall University, USA Rex Page University of Oklahoma, USA Fernando Rubio Universidad Complutense de Madrid, Spain Sven-Bodo Scholz University of Hertfordshire, UK Manuel Serrano INRIA Sophia-Antipolis, France Chung-chieh Shan Rutgers University, USA David Walker Princeton University, USA Vikt?ria Zs?k E?tv?s Lor?nd University, Hungary PETER LANDIN PRIZE The Peter Landin Prize is awarded to the best paper presented at the symposium every year. The honored article is selected by the program committee based on the submissions received for the formal review process. The prize carries a cash award equivalent to 150 euros. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Thu Jan 15 12:11:41 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 15 Jan 2009 12:11:41 -0500 Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: Mel wrote: > Philip Semanchuk wrote: > >> I'm working on message queue support, but the Sys V IPC API is a >> headache and takes longer to code against than the POSIX API. > > I hadn't found it that bad. I have a C extension I should perhaps clean > up and make public. I have a simple wrapper around the msgget/msgsnd/msgrcv functions that ought to be downloadable through . GPL3. I'm studying Philip Semanchuk's semaphore and shared memory code. Let me know what you think. Mel. From http Thu Jan 15 12:13:41 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:13:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjkwkze.fsf@ruckus.brouhaha.com> Roy Smith writes: > C is not evil. It's a tool. Would you call a hammer evil because it's not > very good at driving screws? I would call a hammer evil if it were built in a way that made it unnecessarily likely to hit your thumb. > C is a very good tool for doing the kind of thing it was designed > for, which is highly efficient, low-level, portable programming. > The fact that C has been used to write all sorts of large-scale > applications doesn't mean that it's good at that kind of stuff. It just > means that all the alternatives suck more than it does for that kind of > stuff. I don't think so: http://www.adaic.org/whyada/ada-vs-c/cada_art.html From siona at chiark.greenend.org.uk Thu Jan 15 12:17:03 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 15 Jan 2009 17:17:03 +0000 (GMT) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: r wrote: >here is what i have, it would seem stupid to use a conditional in each >method like this... > >def method(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > #modify self.x & self.y with x&y Here's another alternative (I'd've gone with the subclassing tuple if writing this from scratch): class Point2d(object): ... def __getitem__(self, i): if not 0 <= i <= 1: raise IndexError return getattr(self, ['x', 'y'][i]) def method(self, other): x, y = other[0], other[1] ... -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From girishmsampath at gmail.com Thu Jan 15 12:20:29 2009 From: girishmsampath at gmail.com (Sam) Date: Thu, 15 Jan 2009 09:20:29 -0800 (PST) Subject: No Module Named MySQLdb Error Message-ID: <18f72c79-67a3-4a7a-aba4-de80ec2af073@r37g2000prr.googlegroups.com> Hi Friends, This is Sam, a learner of Python programming language. I would like to know a feasible and flexible process of importing MySQLdb module. If anyone know about this and have an expertise over this can help me over this issue. 1) I installed interface MySQLdb 1.2.2 in my MAC OS X system. In that i installed Python 2.6 version along with that i installed MySQL database. 2) So to run an application using these i am using the above interface. I went to read me file in that and went thro the process. 3) In that they asked to run the setup.py file and setup_posix.py file. I am unable to get the exact solution to the error, as i am novice in python. I am pasting here that error, so if anyone can help me over that u are welcome. Sampath:MySQL-python-1.2.2 venkatarampey$ python setup.py Traceback (most recent call last): File "setup.py", line 12, in from setup_posix import get_config File "/Users/venkatarampey/Downloads/MySQL-python-1.2.2/ setup_posix.py", line 89 return metadata, ext_options SyntaxError: 'return' outside function What is the solution for this error? Is anyone aware of using MySQL with python can fix this issue. Hope so i will meet a person in helping my task. Regards, Sampath Girish.M From google at mrabarnett.plus.com Thu Jan 15 12:26:45 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 17:26:45 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> Message-ID: <496F71D5.4020101@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > I have use case, needn't be dynamic, and it's not hard to enclose set as > tuple. But I also write (for example) > > __all__ = 'this that other'.split() > string_list = 'evenOneWord'.split() > > instead of > > __all__ = 'this','that','imTiredOfMistypingCommasAndQuotes' > > > if not isinstance(o,set_of_handled_types): > raise TypeError('call blessed programmer, this cannot occur') > if isinstance(o,set_of_handle_types-treat_differently): > treat_thusly(o) > elif isinstance(o,treat_differently): > treat_differently(o) > elif etc. > You could write a Python source processor like 2to3.py which would replace 'this that other'.split() with ['this', 'that', 'other']. In fact, you could even write abbreviations such as /this that other/ and then use the script to expand them! From LambertDW at Corning.com Thu Jan 15 12:28:27 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Thu, 15 Jan 2009 12:28:27 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7BA011@CVCV0XI05.na.corning.com> Although isinstance predates sets, the python history I recall is that allowing tuples as second argument to isinstance happened at about the same time as set type was builtin. From rt8396 at gmail.com Thu Jan 15 12:29:42 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:29:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> On Jan 14, 1:16?pm, Paul Rubin wrote: > "Russ P." writes: [snip] > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. ?I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. ?If I used C instead, > I'd spend several hours writing the one-off program and then 15 > minutes waiting for it to run, which is not exactly better. ? [snip] > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. ?I > think the Python community should be aiming towards this. You and Everybody -- would be "ecstatic" if this could happen. But first someone has to design such a complex implementation. You want everything, but there is a trade-off. You said you wrote this program in 15 min. How much testing did you actually do on this data before running it? If you told me you spent more than 15 minutes i would not believe you. Look, Python is not a compiled language -- and for good reason -- so for now you need to do more initial testing if you plan to run a "15 min hack script" on a multi-GB data source file, and then throw a temper-tantrum when the damn thing blows chunks! If Python could give the benefits of compiled languages whilst being interpreted(without taking the "fun" out of Python), that would be wonderful, but can you implement such a system? Can anybody at this point? If you can, i can assure you will be worshiped as a God. From rt8396 at gmail.com Thu Jan 15 12:40:07 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:40:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> Message-ID: <77e18004-c388-47ec-b6ea-14de05026e14@z6g2000pre.googlegroups.com> On Jan 15, 11:13?am, Paul Rubin wrote: > Roy Smith writes: > > C is not evil. ?It's a tool. ?Would you call a hammer evil because it's not > > very good at driving screws? ? > > I would call a hammer evil if it were built in a way that made it > unnecessarily likely to hit your thumb. > > > C is a very good tool for doing the kind of thing it was designed > > for, which is highly efficient, low-level, portable programming. > > The fact that C has been used to write all sorts of large-scale > > applications doesn't mean that it's good at that kind of stuff. ?It just > > means that all the alternatives suck more than it does for that kind of > > stuff. > > I don't think so: ?http://www.adaic.org/whyada/ada-vs-c/cada_art.html Hammers are not evil, they have no logic, interpreters and compilers are not evil either -- you and i control there every move. The hammer will go exactly where you guide it to -- if that happens to be you thumb...?? Python does exactly what it's told, if you tell Python to smash your thumb, Python will gladly comply :) From rt8396 at gmail.com Thu Jan 15 12:43:17 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:43:17 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> <77e18004-c388-47ec-b6ea-14de05026e14@z6g2000pre.googlegroups.com> Message-ID: <05b802b8-7fe6-47c3-a959-58df83d2b48c@r41g2000prr.googlegroups.com> Heres a little food for thought, Maybe you did tell Python to hit the nail head, but your calculations of the direction vector were slightly off. Instead of a direct hit, the hammer grazed the head and now the resultant vector aims strait for your thumb -- Who's to blame here? From http Thu Jan 15 12:43:32 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:43:32 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> Message-ID: <7xwscwh3cr.fsf@ruckus.brouhaha.com> r writes: > You said you wrote this program in 15 min. How much testing did you > actually do on this data before running it? If you told me you spent > more than 15 minutes i would not believe you. I would say hours, in the sense that the program ran correctly for that long, processing several GB's of data before hitting something obscure that it couldn't handle. This is not a single incident, it's something that happens all the time; write the program, run it til it crashes, fix what made it crash, run some more, etc. In some cases where the program is a background process listening to external events, it runs for weeks before hitting something it can't handle. To be fair, that kind of thing is notoriously difficult to make airtight in real world systems, which is why Erlang uses a "let it crash" philosophy that emphasizes recovery from failures rather than trying to avoid them at all costs. But, at least in the stuff I'm hacking, I think a lot of these errors could be avoided with more automated ways to check for type consistency. From rt8396 at gmail.com Thu Jan 15 12:47:57 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:47:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> Message-ID: <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> Paul Rubin > I would say hours, in the sense that the program ran correctly for > that long, processing several GB's of data before hitting something > obscure that it couldn't handle. ?This is not a single incident, it's So what was the fatal error, care to post a traceback? From http Thu Jan 15 12:59:01 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:59:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> Message-ID: <7xocy8v4be.fsf@ruckus.brouhaha.com> r writes: > So what was the fatal error, care to post a traceback? Usually it's "expected to find some value but got None", or got a list, or expected some structure but got a different one, or some field was missing, etc. It's not a single traceback, it's a recurring theme in developing this stuff. From jaomatos at gmail.com Thu Jan 15 13:09:00 2009 From: jaomatos at gmail.com (=?iso-8859-1?q?Jos=E9_Matos?=) Date: Thu, 15 Jan 2009 18:09:00 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> Message-ID: <200901151809.00786.jaomatos@gmail.com> On Thursday 15 January 2009 15:28:36 r wrote: > First of all be very careful using from "module" import * or you will > have name conflicts. Tkinter is made to be imported this way and i do > it all the time. for the others do. > > import tkMessageBox as MB > import tkFileDialog as FD > or whatever floats your boat. Importing explicitly works for me in Fedora 11 (rawhide): ----------------------------- from Tkinter import * from tkMessageBox import askyesno from tkFileDialog import askopenfilename root = Tk() def ask_file(): file_name = askopenfilename() print file_name def ask_confirm(): answer = askyesno() print answer Button(root, text='Ask file', command=ask_file).pack() Button(root, text='Ask confirm', command=ask_confirm).pack() root.mainloop() ----------------------------- > Secondly i hear all the time about problems with fedora distros, so > that would explain the issue to me. That seems a long jump in the reasoning since OP reported the same behavior in Suse and Solaris. -- Jos? Ab?lio From rt8396 at gmail.com Thu Jan 15 13:15:40 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 10:15:40 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> On Jan 15, 11:59?am, Paul Rubin wrote: > r writes: > > So what was the fatal error, care to post a traceback? > > Usually it's "expected to find some value but got None", or got a > list, or expected some structure but got a different one, or some > field was missing, etc. ?It's not a single traceback, it's a recurring > theme in developing this stuff. ? Sounds like the results of poor testing and lack of design good program logic From skip at pobox.com Thu Jan 15 13:21:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 15 Jan 2009 12:21:12 -0600 Subject: mimetypes oddity In-Reply-To: References: Message-ID: <18799.32408.318726.110143@montanaro.dyndns.org> [mimetype weirdness reported] Sion> Is this a bug? Might be. Can you file a bug report in the Python issue tracker with a small script that demonstrates the behavior? -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From mccredie at gmail.com Thu Jan 15 13:22:29 2009 From: mccredie at gmail.com (Matimus) Date: Thu, 15 Jan 2009 10:22:29 -0800 (PST) Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Message-ID: On Jan 15, 8:23?am, thomas.steffe... at googlemail.com wrote: > Hello, > > I have a Class: > > class myClass: > ? ? def __init__(self): > ? ? ? ? # do something > ? ? ? ? print "name of class = " + ?self.__class__.__name__ > > ? ? def myMethod(self): > ? ? ? ? # do something > ? ? ? ? print "name of method = " + "myMethod" > ? ? ? ? return > > ? ? ... > > I print the name of the class with self.__class__.__name__ in > __init__. > I want to print also in every method of myClass the name of the > method. > How can I get the name? I would not like to write e.g. "myMethod". Is > there a variable like self.__class__.__name__ for this? > Thanks for your hints, Thomas I would just use a decorator: >>> def print_method_name(meth): ... def new_meth(*args, **kwargs): ... print meth.func_name ... return meth(*args, **kwargs) ... return new_meth ... >>> class MyClass(object): ... @print_method_name ... def my_method(self): ... pass ... >>> x = MyClass() >>> x.my_method() my_method Matt From http Thu Jan 15 13:25:11 2009 From: http (Paul Rubin) Date: 15 Jan 2009 10:25:11 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> Message-ID: <7xbpu8l94o.fsf@ruckus.brouhaha.com> r writes: > Sounds like the results of poor testing and lack of design good > program logic It would sure be nice if the language made it easier, not harder. From cma at mail.bnu.edu.cn Thu Jan 15 13:28:35 2009 From: cma at mail.bnu.edu.cn (Cong Ma) Date: Fri, 16 Jan 2009 02:28:35 +0800 Subject: Injecting a global into a defined function?? Message-ID: Hi, I'd appreciate your hints on this problem. I'm writing a module in which several functions can alter the value of a global variable (I know this sounds evil, please forgive me...). What I'm trying to do is to eliminate the "global foo" lines in those functions' bodies and to use a decorator for the same task. For example: @global_injected("SPAM") def foo(): ... ... will have the same effect as def foo(): global SPAM ... ... Leaving the evilness of globals aside, I wonder how I can implement this (for Python 2.x). I'd like to hear your opinions. Thank you. Regards, Cong. From zac256 at gmail.com Thu Jan 15 13:30:18 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 15 Jan 2009 10:30:18 -0800 Subject: Executing global code In-Reply-To: References: Message-ID: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> I'm not sure I fully understand the question "no moving the code to a function", but you can prevent reload in a module by doing something like this: doLoad = False try: no_reload except NameError: no_reload = True else: raise RuntimeError, "This module is not meant to be reloaded." -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 8:50 AM, Peter Otten <__peter__ at web.de> wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e. g. these two statements > > x = 42 > x += 1 > > and want to rerun it with the effect of x becoming 44? That is not possible > because in Python > > x = 42 > > is a statement, too, and will thus be rerun. > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > From martin.hellwig at dcuktec.org Thu Jan 15 13:30:18 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 15 Jan 2009 18:30:18 +0000 Subject: Python Crashes In-Reply-To: References: Message-ID: <496f80bb$0$196$e4fe514c@news.xs4all.nl> koranthala wrote: This does sounds more to me like a windows/hardware problem, what you could do is check the windows log for errors, especially look for read errors from the hard disk. Windows sometimes can behave very strangely especially if the external libs don't behave well on a multi process machine or when the execution prevention gets in the way. Both problems can be worked around though (setting a uniprocessor flag at the binary, adding an exception for the execution prevention) but should not be done without proper reason. Good luck. -- mph From zac256 at gmail.com Thu Jan 15 13:30:56 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 15 Jan 2009 10:30:56 -0800 Subject: Executing global code In-Reply-To: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> References: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> Message-ID: <333edbe80901151030t8065b44w941545966a7cc30f@mail.gmail.com> The first line: doLoad = False, is to be ignored. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 10:30 AM, Zac Burns wrote: > I'm not sure I fully understand the question "no moving the code to a > function", but you can prevent reload in a module by doing something > like this: > > doLoad = False > try: > no_reload > except NameError: > no_reload = True > else: > raise RuntimeError, "This module is not meant to be reloaded." > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > > > > On Thu, Jan 15, 2009 at 8:50 AM, Peter Otten <__peter__ at web.de> wrote: >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> >> You have a module containing e. g. these two statements >> >> x = 42 >> x += 1 >> >> and want to rerun it with the effect of x becoming 44? That is not possible >> because in Python >> >> x = 42 >> >> is a statement, too, and will thus be rerun. >> >> Peter >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From google at mrabarnett.plus.com Thu Jan 15 13:43:31 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 18:43:31 +0000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: <496F83D3.2080900@mrabarnett.plus.com> Cong Ma wrote: > Hi, > > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. For > example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... > > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). I'd like to hear your opinions. Thank you. > I doubt that's possible because 'global' is syntax. From pavlovevidence at gmail.com Thu Jan 15 13:47:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jan 2009 10:47:05 -0800 (PST) Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> On Jan 15, 3:35?am, Duncan Booth wrote: > Terry Reedy wrote: > > Lambert, David W (S&T) wrote: > >> Overly terse. ?I do mean that this is illegal: > > >> isinstance(s, {str, bytes}) > > >> tuples have order, immutability, and the possibility of repeat items. > > >> A set is most reasonable in a mathematical sense. > > > I agree. ?However, isinstance predates set. ?Hence the status quo. > > There is another reason which nobody has mentioned, and which might make it > tricky to do a good implementation that does accept sets. > > The second argument to isinstance or issubclass is a classinfo where a > classinfo is either a class or a tuple of classinfo. This makes it easy to > group related types: you can just combine existing groups of types together > without having to flatten tuples. The immutability of tuples guarantees > that you cannot create a recursive structure this way. > > If you allow sets then the code which traverses the classinfo has to > protect itself against the possibility of an infinite recursion. > > The same argument also applies to exception handlers which also accept a > type or a tuple of things they accept. > > Of course you could allow either an existing classinfo or a set of types, > but not allow the set to contain anything other than types. That would > still prevent recursion but means you have to be stricter about knowing > what you are combining. That probably wouldn't be a bad thing if everyone > used sets consistently but I suspect would be messy if introduced at this > stage. I don't see what the big deal is. Right now isinstance accepts a type or a tuple of types. The code could be changed to allow a type, or any iterable the returns types (wherein every items of the sequence is required to be a type). What's messy about that? Carl Banks From python at rcn.com Thu Jan 15 13:49:49 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 15 Jan 2009 10:49:49 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> Message-ID: <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> > > Thought you guys might enjoy this: > > ? ?http://code.activestate.com/recipes/576615/ > > Nice and short, but it's also very slow on my PC (Psyco may help). > > This solves them in moments:http://labix.org/python-constraint Intelligent search beats brute force permutation search. The constraint solver is pretty nice. The recipe is mainly about how to use itertools.permutations() for simple programs that take minutes to write and get the job done. Raymond From nad at acm.org Thu Jan 15 13:49:50 2009 From: nad at acm.org (Ned Deily) Date: Thu, 15 Jan 2009 10:49:50 -0800 Subject: Readline and Python 2.6.1 on a Mac References: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Message-ID: In article <4632a161-ed13-477c-a40a-2b606fda1c27 at a29g2000pra.googlegroups.com>, James Brady wrote: > Hi, I just upgraded Python from 2.5.2 up to 2.6.1 on my 10.5 Mac > (installed from the DMG here: http://www.python.org/download/releases/2.6.1/), > and I'm having some problems with readline and rl_completer. > > I have PYTHONSTARTUP pointing to this file: > #!/usr/bin/env python > > try: > import readline > except ImportError: > print "Module readline not available." > else: > import rlcompleter > readline.parse_and_bind("bind ^I rl_complete") > > Which was working fine for tab completion in 2.5. Now, however, I > can't enter 'b' (lower case b) in interactive python shells - no > character appears. Your startup file was set up for a Python (likely the Apple-supplied 2.5) that was built using the BSD editline library for readline. But the 2.6 python.org python was built with GNU readline which uses a different syntax. s/"bind ^I rl_complete"/"tab: complete"/ -- Ned Deily, nad at acm.org From duncan.booth at invalid.invalid Thu Jan 15 14:08:03 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Jan 2009 19:08:03 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> Message-ID: Carl Banks wrote: > I don't see what the big deal is. Right now isinstance accepts a type > or a tuple of types. The code could be changed to allow a type, or > any iterable the returns types (wherein every items of the sequence is > required to be a type). What's messy about that? No, it isn't restricted to a type or a tuple of types: right now isinstance accepts X where X is a type or a tuple of X. The definition is recursive, and the data structure can be deeply nested, but (because tuples are immutable) it cannot be infinite. e.g. >>> isinstance('x', (((((int, (float, str)),),),),)) True If you change the code so that it only allows iterables one level deep then existing code may break. If you change it to allow mutable nested values then the interpreter has to avoid getting stuck in an infinite loop. From rt8396 at gmail.com Thu Jan 15 14:15:13 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 11:15:13 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> <7xbpu8l94o.fsf@ruckus.brouhaha.com> Message-ID: <6db4b8a4-e6ca-4ab8-9132-18bfdd74a3e5@z28g2000prd.googlegroups.com> On Jan 15, 12:25?pm, Paul Rubin wrote: > r writes: > > Sounds like the results of poor testing and lack of design good > > program logic > > It would sure be nice if the language made it easier, not harder. I am for anything that makes debugging easier, as long as that "thing" doesn't take away the freedom i enjoy while writing Python code. If you can give me both then i will support your efforts -- The world does not need two Javas! Python's existence resides in a unique niche, Simplistic-Elegant- Programming-Bliss. Python promotes self reliance, you don't get the safety net you do with other languages. You must consider all the consciences/possible side-effects of your code. If you are going to use Python to design enormous systems(or operate on enormous data sources) -- at this point --, then you will need to do some enormous testing. From tjreedy at udel.edu Thu Jan 15 14:39:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 14:39:30 -0500 Subject: 2to3 Help? In-Reply-To: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: marco.m.petersen at gmail.com wrote: > I have Python 3.0. I tried to use the 2to3 program included with the > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. I believe 2to3 is will work 'best' with files modified to use some new 2.6 features (backported from 3.0) where 'best' means 'Runs with 2.6 and then with 3.0 after 2to3 conversion without hand editing'. If you want to do a one-time conversion, then 2.5 to 3.0 is fine. From tjreedy at udel.edu Thu Jan 15 14:47:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 14:47:29 -0500 Subject: Python 3 isinstance In-Reply-To: References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Duncan Booth wrote: > Terry Reedy wrote: > >> Lambert, David W (S&T) wrote: >>> Overly terse. I do mean that this is illegal: >>> >>> isinstance(s, {str, bytes}) >>> >>> tuples have order, immutability, and the possibility of repeat items. >>> >>> A set is most reasonable in a mathematical sense. >> I agree. However, isinstance predates set. Hence the status quo. >> >> > > There is another reason which nobody has mentioned, and which might make it > tricky to do a good implementation that does accept sets. > > The second argument to isinstance or issubclass is a classinfo where a > classinfo is either a class or a tuple of classinfo. This makes it easy to > group related types: you can just combine existing groups of types together > without having to flatten tuples. The immutability of tuples guarantees > that you cannot create a recursive structure this way. > > If you allow sets then the code which traverses the classinfo has to > protect itself against the possibility of an infinite recursion. > > The same argument also applies to exception handlers which also accept a > type or a tuple of things they accept. > > Of course you could allow either an existing classinfo or a set of types, > but not allow the set to contain anything other than types. That would > still prevent recursion but means you have to be stricter about knowing > what you are combining. That probably wouldn't be a bad thing if everyone > used sets consistently but I suspect would be messy if introduced at this > stage. Nice explanation. A mathematical set is a frozen set of course (except that mathematical sets can also be recursive! -- depending on the particular set theory), and there is no literal syntax for that. From bearophileHUGS at lycos.com Thu Jan 15 14:51:42 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 11:51:42 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: Raymond Hettinger: > for simple programs that take minutes to write and get the job done. For fun here's a specific example: from csp import Problem, timing print "SEND+MORE=MONEY problem:" p = Problem("recursivebacktracking") p.addvars("sendmory", range(10)) p.addrule(lambda d,e,y: (d+e)%10 == y) # alternative syntax p.addrule("(n*10+d+r*10+e)%100 == e*10+y") p.addrule("(e*100+n*10+d+o*100+r*10+e)%1000 == n*100+e*10+y") p.addrule("1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e == 10000*m+1000*o +100*n+10*e+y") p.notin([0], "sm") p.alldifferent() solutions, time = timing(p.solutions) print "Computing time:", time, "s" for s in solutions: print "%(s)d%(e)d%(n)d%(d)d + %(m)d%(o)d%(r)d%(e)d = %(m)d%(o)d%(n) d%(e)d%(y)d" % s print Probably it's not too much difficult to write a code able to solve a more general alphametric problem: you can write it more or less like yours, but it leads to a single equation, that is slow to solve. To give the solver engine a chance to speed up the computation you have to split the single equation into many equations. This allows the solver to prune that large search space in a faster way (the search space may have 3+ millions items so it's not huge anyway). Bye, bearophile From atleta.hu at gmail.com Thu Jan 15 14:51:52 2009 From: atleta.hu at gmail.com (atleta) Date: Thu, 15 Jan 2009 11:51:52 -0800 (PST) Subject: Parallel package hierarchies/directories Message-ID: <70cbe817-9eda-4346-93b6-5c38d8d63389@n33g2000pri.googlegroups.com> Hi, I'd need a logical way to organize my unit tests into packages, but I don't know how to do it in python. I'd like to separate my test sources (modules) from the code. The problem is that it seems that python does not allow a package to spread through multiple directories. I'd like to have the following layout (which is the usual way we do it e.g. in java): +-project_root/ | +-src/ | | | +-soap | +-test/ | +-soap 'soap' is a package under the source tree. I.e. I'd like my test source tree to mirror the source tree and have package specific tests in the same package as the code they excersize. However I found that this is not possible, at least not the way I wanted, not without moving files. I tried to place a script that would run all tests under the 'test' directory. It added 'src' to the sys.path, but then it was only able to import packages from test/soap and not src/soap. Is there a way I can have python look for soap package modules in both places? If not, then could someone tell me what is the usual way to layout test code? Thanks, atleta From bdesth.quelquechose at free.quelquepart.fr Thu Jan 15 14:54:49 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 15 Jan 2009 20:54:49 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xsknl6z5b.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> <496e4e2e$0$10088$426a34cc@news.free.fr> <7xsknl6z5b.fsf@ruckus.brouhaha.com> Message-ID: <496fa232$0$7878$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> We're not talking about libraries here. >> Yes we are. If the default is "non-dynamic", then a class author is in >> charge of explicitely allowing it when *he* see fits. > > Oh, I see what you mean, the standard libraries would be affected if > the language default were to tone down the dynamism. True. Not only the standard lib. Quite a lot of frameworks relies on these features. >> As long as it's up to the *user* to choose, that's ok. Your "@dynamic" >> class decorator doesn't have the same implications. > > Well, you could use it on library classes too: > > from library import Libclass > Libclass = dynamic(Libclass) > ... That's fine when you directly use the class. Not when you work with instances provided by a framework (or another lib) that won't be affected by your above rebinding. From tjreedy at udel.edu Thu Jan 15 15:01:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:01:30 -0500 Subject: Python Crashes In-Reply-To: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> References: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> Message-ID: > > I am using 9 3rd party modules and there are some DLLs too - PIL etc. > But the problem is that the issue comes only after 3 hrs usually. > When I checked the memory using taskmanager, I found that it is not > going too high. I know of 3 general ways to crash the interpreter. 1. Use 3rd party modules. By far most common. I would try to do everything but use one of them, possibly by replacing import with stub. 2. Use ctypes. This can bypass all protections. 3. Write a subtle infinite recursion in a class method that is not checked for infinite recursion. The following illustrates the idea without testing whether this crashes. class c(): def __add__(self, other): return self+other # calls this __add__ I believe some of these vulnerabilities existed in 2.4 but many were crushed in 2.5. Backported to 2.4.3? No idea. This could hit so fast you never see it in task manager. If your 3rd party modules work with 2.5, consider upgrading to 2.5.3. Many bug fixes. tjr From bdesth.quelquechose at free.quelquepart.fr Thu Jan 15 15:21:56 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 15 Jan 2009 21:21:56 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <496fa88d$0$1459$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming > is written in smoke? Well, actually, the answer is mostly "yes". Functional programming is based on a (mathematical) theoretical ground about calculation (google for Alonzo Church and lambda calculus), while OO is originally nothing more than a way to implement finite state machines with an imperative language. OO *is* imperative programming (which is itself also well defined). > > Just for the record, I really don't care much about the definition of > OO programming. I brought it up only because someone tried to claim > that "enforced" encapsulation data hiding. > is a terrible idea. Well, as far as I > can tell, the majority of OO "programmers" (and software engineers, > software architects, playing buzzword bingo ? etc.) seem to think otherwise. Maybe they are > wrong -- but I seriously doubt it. The first OO languages (at least the second one - Smalltalk) used data-hiding to clearly emphasize the "black box" nature of objects and the use of messages as the main (only in the case of Smalltalk) support for control flow. Remember than by that time, lost of programs where still mostly relying on *global* state changes. IOW, it has a strong educative value then... Following "OO" languages - mostly C++ and Java - kept this "rule" like it was a sacred cow (but mostly forgot about the more important points of 'everything is an object' and message-passing as main control flow). Then everyone started considering this as "fundamuntal", and here we are years later with one more cargo cult, when years of experience prove that it's not - at least from a practical POV. Once again, the important point is that there's a *clear* distinction between interface and implementation, and that you *shouldn't* mess with implementation. But what, some people think programmers are stupid, and so they hire stupid programmers, so they need b&d languages to protect stupid programmers from themselves - which just doesn't work, since *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb getter/setter pairs for _each and any_ attribute ? > As I said before, enforced encapsulation may not be appropriate for > every application, but it is definitely appropriate for some. No. It is appropriate for dummy managers hiring dummy programmers. The project's size and domain have nothing to do with it. > Not > every door needs a lock, but certainly some do. You only need locks when you don't trust your neighbours. From thomasmallen at gmail.com Thu Jan 15 15:25:11 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 12:25:11 -0800 (PST) Subject: UnicodeError for join() Message-ID: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> This line of code is throwing a UnicodeError for a handful of the few hundred files I'm processing: rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", self.content])) ................. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 442: ordinal not in range() What should I change to make this unicode-safe? Thanks, Thomas From tjreedy at udel.edu Thu Jan 15 15:29:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:29:33 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xocy8v4be.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > r writes: >> So what was the fatal error, care to post a traceback? > > Usually it's "expected to find some value but got None", or got a > list, or expected some structure but got a different one, or some > field was missing, etc. It's not a single traceback, it's a recurring > theme in developing this stuff. I do not see any connection, really, between what you describe above and your desire for static type-checking expressed elsewhere. When I was regularly doing analysis of empirical data files, I learned (sometimes the hard way, as you describe above) to **ALWAYS** run preliminary checks of all fields through the entire file so I would know the actual range of values of each and whether the ranges comported with the requirements of the intended analyses. The principle was/is the same whether using BMDP, SAS, C, or Python. Terry Jan Reedy From martin at v.loewis.de Thu Jan 15 15:34:14 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 15 Jan 2009 21:34:14 +0100 Subject: UnicodeError for join() In-Reply-To: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> Message-ID: <496f9dc6$0$22783$9b622d9e@news.freenet.de> > rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", > self.content])) > ................. > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position > 442: ordinal not in range() > > What should I change to make this unicode-safe? One of self.title and self.content is a Unicode string, the other is a byte string. You need to change them to have the same type (depending on whether you want to process them as Unicode or byte strings). HTH, Martin From mdw at distorted.org.uk Thu Jan 15 15:36:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 15 Jan 2009 20:36:36 +0000 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> mario ruggier writes: > Some info on its security is at: > http://evoque.gizmojo.org/usage/restricted/ > Tell you what, if you find a security hole there (via exposed template > source on a Domain(restricted=True) setup) I'll offer you a nice > dinner (including the beer!) somewhere, maybe at some py conference, > but even remotely if that is not feasible... ;-) The upcoming 0.4 > release will run on 2.4 thru to 3.0 -- you can have some fun with that > one (the current 0.3 runs on 2.5 and 2.6). I'm pretty sure I can break this on 3.0, because the f_restricted frame flag has gone. Here's how: >>> import template, domain >>> dom = domain.Domain('/tmp/mdw/', restricted = True, quoting = 'str') >>> t = template.Template(dom, 'evil', from_string = True, src = >>> "${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()}") 2009-01-15 20:30:29,177 ERROR [evoque] RuntimeError: restricted attribute: File "", line 1, in : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()) u'[RuntimeError: restricted attribute: File "", line 1, in \n: EvalError(inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/mdw/target\').read())]' which means that it's depending on the func_globals attribute being rejected by the interpreter -- which it won't be because 3.0 doesn't have restricted evaluation any more. Python is very leaky. I don't think trying to restrict Python execution is a game that's worth playing. -- [mdw] From tjreedy at udel.edu Thu Jan 15 15:37:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:37:00 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: Michele Simionato wrote: > On Jan 14, 3:27 am, Paul Rubin wrote:> >> I don't understand why some folks spew such violent rhetoric against >> the idea of augmenting Python with features to alert you automatically >> when you depart from the convention, so that you can check that the >> departure is actually what you wanted. A lot of the time, I find, the >> departures are accidental and automated checks would save me >> considerable debugging. > > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. A true change of the > language IMO is impossible, both technically, politically and for > legacy issue. Also, I am not convinced it would be a good idea, even > theoretically. It is easier to write a new Python-like language > from scratch than to add type checking to Python (I think you > were not proposing adding type checking in this post, right?). Integrating checkers with the interpreter is something that could/should be done by an IDE. It should not be too hard, for instance, to give IDLE a configurable run-thru-PyLint option keyed, for instance, to shift-F5 (given that F5 is run-with-CPython). Alt-F5 for instance could be run-Pylint-and-if-no-errors-then-CPython. From tjreedy at udel.edu Thu Jan 15 15:38:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:38:32 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> Message-ID: Michele Simionato wrote: > On Jan 15, 7:38 am, "James Mills" > wrote: >> If one is a clumsy programmer, then perhaps >> one ought to be using a language that holds one's hand. > > Yes, and I use Python because it is a language that holds my hand, > otherwise I would use C and enjoy segmentation faults all the time. So perhaps it is a matter of which handholding one wants and which one hates. To avoid all, stick with assembler ;-). tjr From bignose+hates-spam at benfinney.id.au Thu Jan 15 15:58:49 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 07:58:49 +1100 Subject: Convention vs. fascism (was: General direction) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87zlhsb81i.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > > Familiarize yourself with PEP8 for naming and coding-conventions > > first. > > Enough of the PEP8-fascism please. It is not compulsory to follow > PEP8 in order to be allowed to learn Python. If Guido wanted it > compulsory, he'd have made the compiler enforce it. You are responding to something in Diez's message that I can't see. Nowhere does he say anything about PEP 8 being compulsory. Quite the contrary, he suggests gaining *familiarity* with PEP 8, and calls it a set of *conventions*. > Having said that, I will *suggest* to the Original Poster that you > should follow PEP8 as much as possible. It will save you a lot of > grief in the long run. This, on the other hand, seems pretty much a re-phrasing of what Diez already said. -- \ ?You've got the brain of a four-year-old boy, and I'll bet he | `\ was glad to get rid of it.? ?Groucho Marx | _o__) | Ben Finney From thomasmallen at gmail.com Thu Jan 15 16:00:50 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 13:00:50 -0800 (PST) Subject: UnicodeError for join() References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> Message-ID: <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> On Jan 15, 3:34?pm, "Martin v. L?wis" wrote: > > rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", > > self.content])) > > ................. > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position > > 442: ordinal not in range() > > > What should I change to make this unicode-safe? > > One of self.title and self.content is a Unicode string, the other is > a byte string. You need to change them to have the same type (depending > on whether you want to process them as Unicode or byte strings). > > HTH, > Martin How can I do that? Thomas From martin at v.loewis.de Thu Jan 15 16:09:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 15 Jan 2009 22:09:07 +0100 Subject: UnicodeError for join() In-Reply-To: <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> Message-ID: <496FA5F3.8020200@v.loewis.de> >> One of self.title and self.content is a Unicode string, the other is >> a byte string. You need to change them to have the same type (depending >> on whether you want to process them as Unicode or byte strings). >> > > How can I do that? First, you need to find out what the respective types are: print type(self.title), type(self.content), repr(self.title), repr(self.content) With that information, as a very important next step, you need to understand why the error occurs. Then, you need to fix it, e.g. by converting all strings to byte strings. Suppose title is a unicode string, and further suppose the output is to be encoded in cp1252, then you change the line to rc_file.write(u"\n\n".join([self.title.encode("cp1252"), "### BEGIN CONTENT ###", self.content])) Regards, Martin From tjreedy at udel.edu Thu Jan 15 16:16:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 16:16:13 -0500 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Cong Ma wrote: > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, Not to me. You are using the module as a singleton class. The alternative is to write a class, make the functions methods, and instantiate the class. If that instance must be a singleton, more work is required. If multiple instances make sense, you can go the class route when you need to. > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. This sounds foolish and senseless (but not evil ;-). >For example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... More keystrokes for no gain. > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). Decorators are usally intended to wrap the input function with another function. But they can be used to modify the input function and return it altered. The latter is what you are proposing. You of course have to use SPAM as a local variable. Then you might be able to write an implementation-specific convert_to_global(name) function that would rewrite the code part of the code object of the function to what it would have been had you been sensible and used the 'global' directive. This would mean finding the code that loads and stores 'SPAM' as a local variable and convert is to code that loads and stores it as a global variable. If the replacement takes more bytes than the original, then the jump offsets all have to be fixed. Also needing fixing would be the line number table that is used to match code units to lines in the Python code for error tracebacks. An alterntive would be to de-compile the code, insert the global directive, and recompile. A non-decorator alternative would be to write a function with two parameters that takes a tuple of names and the code quoted as a string as arguments. It would insert the global statement into the string, execute it, and return the function. > I'd like to hear your opinions. Thank you. I hope I have convinced you to forget this idea. Terry Jan Reedy From tjreedy at udel.edu Thu Jan 15 16:23:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 16:23:33 -0500 Subject: Executing global code In-Reply-To: References: Message-ID: Jakub Debski wrote: > Hi, > > Is it possible to execute global code (module-level code) more than once > keeping the state of global variables? This means no reload() and no > moving the code to a function. Wrap the code in a loop: for dummy in range(): # a plural count literal tjr From lcaruso at tds.net Thu Jan 15 16:28:09 2009 From: lcaruso at tds.net (Larry Caruso) Date: Thu, 15 Jan 2009 15:28:09 -0600 Subject: newbie OOP question (what's the analogue to java interfaces in Python?) Message-ID: <000001c97758$2b01dea0$81059be0$@net> I'm an old time C programmer, but a newbie to OOP and Python. One OOP book I'm reading, "Holub on Patterns," discusses Java Interfaces in some detail (see http://en.wikipedia.org/wiki/Interface_(Java) for example) but with limited time, I'm hoping to avoid learning Java just to understand some key points of this book. Can anyone tell me what the analogue, if any, would be in Python? TIA. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomasmallen at gmail.com Thu Jan 15 16:34:19 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 13:34:19 -0800 (PST) Subject: UnicodeError for join() References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> <496FA5F3.8020200@v.loewis.de> Message-ID: On Jan 15, 4:09?pm, "Martin v. L?wis" wrote: > >> One of self.title and self.content is a Unicode string, the other is > >> a byte string. You need to change them to have the same type (depending > >> on whether you want to process them as Unicode or byte strings). > > > How can I do that? > > First, you need to find out what the respective types are: > > print type(self.title), type(self.content), repr(self.title), > repr(self.content) > > With that information, as a very important next step, you need to > understand why the error occurs. > > Then, you need to fix it, e.g. by converting all strings to byte > strings. > Suppose title is a unicode string, and further suppose the output > is to be encoded in cp1252, then you change the line to > > rc_file.write(u"\n\n".join([self.title.encode("cp1252"), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? "### BEGIN CONTENT ###", > ? ? ? ? ? ? ? ? ? ? ? ? ? ? self.content])) > > Regards, > Martin Thanks, it was the title that was causing problems. I just added the encode() part to the self.title assignment. Thomas From ajaksu at gmail.com Thu Jan 15 16:35:05 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 15 Jan 2009 13:35:05 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 15, 1:56?pm, mario ruggier wrote: > As > I mentioned in another thread, the real application behind all this is > one of the *few* secure templating systems around. Some info on its > security is at:http://evoque.gizmojo.org/usage/restricted/ > Tell you what, if you find a security hole there (via exposed template > source on a Domain(restricted=True) setup) I'll offer you a nice > dinner (including the beer!) somewhere, maybe at some py conference, > but even remotely if that is not feasible... ;-) If you could provide a bare-bones instance of your evaluator to test against, without using the whole evoque (I get DUMMY MODE ON from 'self.template.collection.domain.globals'), it'd be more interesting to try :) From perfreem at yahoo.com Thu Jan 15 16:39:18 2009 From: perfreem at yahoo.com (Per Freem) Date: Thu, 15 Jan 2009 13:39:18 -0800 (PST) Subject: optimizing large dictionaries Message-ID: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> hello i have an optimization questions about python. i am iterating through a file and counting the number of repeated elements. the file has on the order of tens of millions elements... i create a dictionary that maps elements of the file that i want to count to their number of occurs. so i iterate through the file and for each line extract the elements (simple text operation) and see if it has an entry in the dict: for line in file: try: elt = MyClass(line)# extract elt from line... my_dict[elt] += 1 except KeyError: my_dict[elt] = 1 i am using try/except since it is supposedly faster (though i am not sure about this? is this really true in Python 2.5?). the only 'twist' is that my elt is an instance of a class (MyClass) with 3 fields, all numeric. the class is hashable, and so my_dict[elt] works well. the __repr__ and __hash__ methods of my class simply return str() representation of self, while __str__ just makes everything numeric field into a concatenated string: class MyClass def __str__(self): return "%s-%s-%s" %(self.field1, self.field2, self.field3) def __repr__(self): return str(self) def __hash__(self): return hash(str(self)) is there anything that can be done to speed up this simply code? right now it is taking well over 15 minutes to process, on a 3 Ghz machine with lots of RAM (though this is all taking CPU power, not RAM at this point.) any general advice on how to optimize large dicts would be great too thanks for your help. From sjmachin at lexicon.net Thu Jan 15 16:39:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 13:39:50 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <457747b6-b120-4be7-a9ba-99dda2348326@h16g2000yqj.googlegroups.com> On Jan 16, 4:28?am, "Lambert, David W (S&T)" wrote: > Although isinstance predates sets, the python history I recall is that > allowing tuples as second argument to isinstance happened at about the > same time as set type was builtin. isinstance 2nd arg as tuple of type info: 2.2 sets module: 2.3 set type: 2.4 From pavlovevidence at gmail.com Thu Jan 15 16:43:37 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jan 2009 13:43:37 -0800 (PST) Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> Message-ID: <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> On Jan 15, 1:08?pm, Duncan Booth wrote: > Carl Banks wrote: > > I don't see what the big deal is. ?Right now isinstance accepts a type > > or a tuple of types. ?The code could be changed to allow a type, or > > any iterable the returns types (wherein every items of the sequence is > > required to be a type). ?What's messy about that? > > No, it isn't restricted to a type or a tuple of types: right now isinstance > accepts X where X is a type or a tuple of X. The definition is recursive, > and the data structure can be deeply nested, but (because tuples are > immutable) it cannot be infinite. > > e.g.>>> isinstance('x', (((((int, (float, str)),),),),)) > > True Oh. Not sure what the use case for THAT was, but that would make things messy. Carl Banks From lkcl at lkcl.net Thu Jan 15 16:48:49 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 15 Jan 2009 21:48:49 +0000 Subject: report on building of python 2.5.2 under msys under wine on linux. Message-ID: no, the above subject-line is not a joke: i really _have_ successfully built python2.5.2 by installing wine on linux, then msys under wine, and then mingw32 compiler - no, not the linux mingw32-cross-compiler, the _native_ mingw32 compiler that runs under msys, and then hacking things into submission until it worked. issue-report: http://bugs.python.org/issue4954 source code: http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine related issue-report: http://bugs.python.org/issue3871 related issue-report: http://bugs.python.org/issue1597850 i'm going to _try_ to merge in #3871 but it's... the prospect of sitting waiting for configure to take THREE hours to complete, due to /bin/sh.exe instances taking TWO SECONDS _each_ to start up does not really fill me with deep joy. consequently i did a major hatchet-job on configure.in with repeated applications of "if test $win32build = no; then" ... cue several hundred lines of configure.in tests blatantly ignored "fi # $win32build=no! " and thus cut the configure time down from three hours to a mere 15 minutes. the only reason why this was possible at all was because PC/config.h already exists and has been pre-set-up with lots of lovely #defines. also, there is another significant difference between #3871 and #4954 - i chose to build in to libpython2.5.dll exactly as many modules as are in the proprietary win32 build. this turned out to be a good practical decision, due to /bin/sh.exe messing around and stopping python.exe from running! (under cmd.exe it's fine. i have to do a bit more investigation: my guess is that the msys "remounter" is getting in the way, somehow. compiling python to have a prefix of /python25 results in files being installed in /python25 which maps to c:/msys/python25/ but.... actually that doesn't get communicated correctly to the compiled python.exe.... it's all a bit odd - it still feels like things are being cross-compiled... but they're not... it's just that setup.py has paths that don't _quite_ match up with the msys environment... needs work, there. the regression testing is _great_ fun! some of the failures are really quite spectacular, but surprisingly there are less than anticipated. file "sharing violation" isn't a big surprise (under wine); the ctypes structure failures are going to be a bitch to hunt down; the test_str %f failure _was_ a big surpise; the builtin file \r\n <-> \n thing wasn't in the _least_ bit of a surprise :) overall, this has been... interesting. and the key thing is that thanks to #3871 and #4954 and #1597850, python will soon happily compile for win32 _without_ the dependence on _any_ proprietary software or operating systems. that's a pretty significant milestone. l. p.s. if anyone would like to try out this build, on a windows box, to see if it fares any better on the regression tests please say so and i will make the binaries available. From mario.ruggier at gmail.com Thu Jan 15 16:52:46 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 13:52:46 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7bd6ef74-8608-489b-bea5-dd243bf0c803@x38g2000yqj.googlegroups.com> On Jan 15, 9:36?pm, Mark Wooding wrote: > mario ruggier writes: > > Some info on its security is at: > >http://evoque.gizmojo.org/usage/restricted/ > > Tell you what, if you find a security hole there (via exposed template > > source on a Domain(restricted=True) setup) I'll offer you a nice > > dinner (including the beer!) somewhere, maybe at some py conference, > > but even remotely if that is not feasible... ;-) The upcoming 0.4 > > release will run on 2.4 thru to 3.0 -- you can have some fun with that > > one (the current 0.3 runs on 2.5 and 2.6). > > I'm pretty sure I can break this on 3.0, because the f_restricted frame > flag has gone. ?Here's how: > > >>> import template, domain > >>> dom = domain.Domain('/tmp/mdw/', restricted = True, quoting = 'str') > >>> t = template.Template(dom, 'evil', from_string = True, src = > >>> "${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()}") > > 2009-01-15 20:30:29,177 ERROR [evoque] RuntimeError: restricted > attribute: ? File "", line 1, in > : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()) > u'[RuntimeError: restricted attribute: ? File "", line 1, in > \n: > EvalError(inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/mdw/target\').read())]' > > which means that it's depending on the func_globals attribute being > rejected by the interpreter -- which it won't be because 3.0 doesn't > have restricted evaluation any more. $ touch /tmp/mdw.test mr:evoque mario$ python3.0 Python 3.0 (r30:67503, Dec 8 2008, 18:45:31) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from evoque import domain, template >>> d = domain.Domain("/", restricted=True, quoting="str") >>> t = template.Template(d, "mdw1", from_string=True, src="${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw.test').read()}") >>> t.evoque() 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' object has no attribute 'func_globals': File "", line 1, in : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/ mdw.test').read()) '[AttributeError: \'function\' object has no attribute \'func_globals \': File "", line 1, in \n: EvalError (inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/ mdw.test\').read())]' But even if inspect did have the func_globals attribute, the "open" builtin will not be found on __builtins__ (that is cleaned out when restricted=True). But, I guess it is necessary to keep an eye on what is available/ allowed by the different python versions, and adjust as needed, probably to the lowest common denominator. In addition to what is mentioned on the doc on evoque's resticted mode at the above URL, do you have specific suggestions what may be a good idea to also block out? > Python is very leaky. ?I don't think trying to restrict Python execution > is a game that's worth playing. It may not be worth risking your life on it, but it is certainly worth playing ;-) Thanks.. with you permission I am adding your evil expression to the restricted tests? Cheers, mario > -- [mdw] From http Thu Jan 15 16:59:12 2009 From: http (Paul Rubin) Date: 15 Jan 2009 13:59:12 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: <7xmydsw7rj.fsf@ruckus.brouhaha.com> Terry Reedy writes: > I do not see any connection, really, between what you describe above > and your desire for static type-checking expressed elsewhere. When I > was regularly doing analysis of empirical data files, I learned > (sometimes the hard way, as you describe above) to **ALWAYS** run > preliminary checks of all fields through the entire file Right. And if the file is large enough that even parsing all the records to check the fields takes hours, well, that's where I'm at. From mccredie at gmail.com Thu Jan 15 17:00:40 2009 From: mccredie at gmail.com (Matimus) Date: Thu, 15 Jan 2009 14:00:40 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> On Jan 15, 1:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. You can use a tuple instead of a string, which should be a little quicker: def __hash__(self): return self.field1, self.field2, self.field3 You could speed it up even more if you just saved a single attribute "fields" as a tuple to begin with. Also, you can use defauldict and get rid of the try/except. I don't think try/except is slow, but avoiding it will give you a speed up. from collections import defaultdict my_dict = defaultdict(int) for line in file: elt = MyClass(line)# extract elt from line... my_dict[elt] += 1 You might even consider turning "MyClass" into just a function that extracts the values from the line and returns a tuple, which should give you even more of a boost since a tuple is completely implemented in C. Matt From sjmachin at lexicon.net Thu Jan 15 17:13:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 14:13:12 -0800 (PST) Subject: Py3 - converting bytes to ascii References: Message-ID: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> On Jan 16, 1:54?am, "Anjanesh Lekshminarayanan" wrote: > Using Python 3.0 > > res = urllib.request.urlopen(url) > f = open('file.txt', 'wb') # Since res.read() returns bytes > f.write(res.read()) > > But newline and return feeds are stored as b14, 58a as text in the text file. I can't imagine how a newline (aka line feed) and/or a carriage return could end up being stored as "b14, 58a as text in the text file". What are you using to view the output file? Before you start trying to fix the problem, we need to understand it. You can use Python itself to show you exactly what is in the file, in a format that you can copy and paste into a news posting. f = open('file.txt', 'rb') data = f.read() f.close() print(ascii(data)) # Python 3.x # print repr(data) # Python 2.x > So how do I to convert res.read() to ascii on opening the file in > ascii mode f = open('file.txt', 'w')? Are you as sure as Casey is that your data is ASCII-only? Or are you using "ascii" to mean "text" or "not binary"? Let's see your data first. Perhaps if you could give us a few clues like how much experience you have in (Python 3.0, Python 2.x, using urllib, computer programming in general) we could give you somewhat more focussed advice. HTH, John From jervisau at gmail.com Thu Jan 15 17:18:51 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 16 Jan 2009 09:18:51 +1100 Subject: optimizing large dictionaries In-Reply-To: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <8e63a5ce0901151418i2622b6f3h435247c55731b0b5@mail.gmail.com> On Fri, Jan 16, 2009 at 8:39 AM, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > > for line in file: > try: > elt = MyClass(line)# extract elt from line... > my_dict[elt] += 1 > except KeyError: > my_dict[elt] = 1 > > > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) > > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. > -- > http://mail.python.org/mailman/listinfo/python-list > Hello, You can get a large speedup by removing the need to instantiate a new MyClass instance on each iteration of your loop. Instead define one MyClass with an 'interpret' method that would be called instead of MyClass() interpret would return the string '%s-%s-%s' % (self.field1 etc..) i.e myclass = MyClass() interpret = myclass.interpret for line in file: elt = interpet(line)# extract elt from line... try: my_dict[elt] += 1 except KeyError: my_dict[elt] = 1 The speed up is on the order of 10 on my machine. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From kingstonlee at gmail.com Thu Jan 15 17:19:06 2009 From: kingstonlee at gmail.com (Kingston) Date: Thu, 15 Jan 2009 14:19:06 -0800 (PST) Subject: Python DateTime Manipulation Message-ID: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> I have a user input a date and time as a string that looks like: "200901010100" but I want to do a manipulation where I subtract 7 days from it. The first thing I tried was to turn the string into a time with the format "%Y%m%d%H%M" and then strip out the day value, turn it into an int and subtract seven, but the value "-6" doesn't mean anything in terms of days =). Does anyone have an idea as to how I can subtract 7 days without turning the date string into an int? Perfect Scenario: perfectdate = 200901010100 - 7Days print perfect date 200812250100 What I have so far: import time, os, re useryear = raw_input("Enter Year (numerical YYYY): ") usermonth = raw_input("Enter Month (numerical MM): ") userday = raw_input("Enter Day (numerical DD): ") usertime = raw_input("Enter Time (24-hour clock hhmm): ") #userday = int(userday) #secondday = userday - 07 #secondday = str(secondday) #userday = str(userday) #firstdate = useryear + usermonth + secondday + usertime seconddate = useryear + usermonth + userday + usertime seconddate = time.strptime(seconddate, %Y%m%d%H%M) print seconddate From mario.ruggier at gmail.com Thu Jan 15 17:21:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 14:21:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> On Jan 15, 10:35?pm, ajaksu wrote: > On Jan 15, 1:56?pm, mario ruggier wrote: > > > As > > I mentioned in another thread, the real application behind all this is > > one of the *few* secure templating systems around. Some info on its > > security is at:http://evoque.gizmojo.org/usage/restricted/ > > Tell you what, if you find a security hole there (via exposed template > > source on a Domain(restricted=True) setup) I'll offer you a nice > > dinner (including the beer!) somewhere, maybe at some py conference, > > but even remotely if that is not feasible... ;-) > > If you could provide a bare-bones instance of your evaluator to test > against, without using the whole evoque (I get DUMMY MODE ON from > 'self.template.collection.domain.globals'), it'd be more interesting > to try :) OK! Here's a small script to make it easier... Just accumulate any expression you can dream of, and pass it to get_expr_template() to get the template, and on that then call evoque()... i guess you'd have to test with 0.3, but 0.4 (also runs on py3) is just around the corner.... Let it rip... the beer'd be on me ;-! # evoque_restricted_test.py from os.path import abspath, join, dirname from evoque import domain, template import logging # uncomment to hide the plentiful ERROR logs: #logging_level = logging.CRITICAL # set the base for for the defualt collection DEFAULT_DIR = abspath("/") # 3 -> renders, 4 -> raises any evaluation errors, # see: http://evoque.gizmojo.org/usage/errors/ ERRORS=2 # a restricted domain instance d = domain.Domain(DEFAULT_DIR, restricted=True, errors=ERRORS, quoting='str') count = 0 # utility to easily init a template from any expression def get_expr_template(expr): global count count += 1 name = "test%s"%(count) src = "${%s}" % (expr) d.set_template(name, src=src, from_string=True) return d.get_template(name) # some test expressions exprs = [ "open('test.txt', 'w')", "getattr(int, '_' + '_abs_' + '_')", "().__class__.mro()[1].__subclasses__()", "inspect.func_globals['_'*2+'builtins'+'_'*2]", ] # execute for expr in exprs: print print expr print get_expr_template(expr).evoque() From lists at cheimes.de Thu Jan 15 17:22:48 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 15 Jan 2009 23:22:48 +0100 Subject: optimizing large dictionaries In-Reply-To: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) > > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) class MyClass(object): # a new style class with slots saves some memory __slots__ = ("field1", "field2", "field2") def __hash__(self): # In general this is faster than your approach because # it requires less function calls. However all fields must # be hashable return hash((self.field1, self.field2, self.field2)) def __eq__(self, other): # you MUST provide a rich compare __eq__ function # when you provide your own hash function. It's called # when hash(a) == hash(b). if not isinstance(other, MyClass): return NotImplemented return (self.field1 == other.field1 and self.field2 == other.field2 and self.field3 == other.field3) def __str__(self): return "%s-%s-%s" %(self.field1, self.field2, self.field3) # faster than your approach because it doesn't require more function # lookups. You can omit this alias, too. It's not required. __repr__ = __str__ Instead of the try/except clause I recommend colletions.defaultdict. Defaultdict takes one callable as factory function. Since int() returns 0 it has the same effect as your code. from collections import defaultdict elt = defaultdict(int) Christian From clp2 at rebertia.com Thu Jan 15 17:25:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 14:25:20 -0800 Subject: Python DateTime Manipulation In-Reply-To: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> References: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> Message-ID: <50697b2c0901151425g20abea25q884457dca63b140f@mail.gmail.com> On Thu, Jan 15, 2009 at 2:19 PM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and then strip out the day value, turn it into an > int and subtract seven, but the value "-6" doesn't mean anything in > terms of days =). > > Does anyone have an idea as to how I can subtract 7 days without > turning the date string into an int? >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now datetime.datetime(2009, 1, 15, 14, 22, 56, 416662) >>> week = timedelta(days=7) >>> now - week datetime.datetime(2009, 1, 8, 14, 22, 56, 416662) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From markus.schreyer at gmail.com Thu Jan 15 17:35:11 2009 From: markus.schreyer at gmail.com (Markus Schreyer) Date: Thu, 15 Jan 2009 23:35:11 +0100 Subject: Import functions in current namespace Message-ID: Hi, we embedded python into our application via Swig. Now we like to wrap the raw API functionality into a nicer more handleable module, but instead of repeating every function in this wrapper i thought about importing them into the namespace of the wrapper module. I like to give you an example of what we like to achive. Swig generates a file called "ppms.py" which contains the API classes and functions. Lets say the ppms.py contains a function called foo(). The wrapper.py should now import the function foo() of the module ppms into the local namespace. the swig module: def foo(): pass def foo0(): pass One possibility would be to repeat the function in the wrapper.py like: import ppms.py def foo(): return ppms.foo() def foo0(): return ppms.foo0()+1 Imho this is a little ugly. So I thought about importing the content of ppms.py (the autgenerated one) into the namespace of the wrapper. Every definition of a fuction in the wrapper should overwrite the function in the imported module but a call to a function which is not defined in the wrapper goes right through. # wrapper.py - magic version "magic_import" ppms.py def foobar(): return foo() #calls foo of ppms.py def foo0(): return foo0()+1 #calls foo0 of ppms.py Now using the magic version: import wrapper wrapper.foo() # looks in wrapper for foo() since it's not defined it falls back to ppms.foo() wrapper.foobar() # calls wrapper.foobar() calls ppms.foo() wrapper.foo0() # calls wrapper.foo0() calls ppms.foo0() Hopefully the idea is not to stupid.. ;) Tnx for your help. Markus -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 15 17:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:35:16 -0500 Subject: List comprehension - NameError: name '_[1]' is not defined ? In-Reply-To: References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Peter Otten wrote: > List comprehensions delete the helper variable after completion: I do not believe they did in 2.4. Not sure of 2.5. There is certainly a very different implementation in 3.0 and, I think, 2.6. OP neglected to mention Python version he tested on. Code meant to run on 2.4 to 3.0 cannot depend on subtle listcomp details. >>>> def f(): [i for i in [1]] > ... >>>> dis.dis(f) > 1 0 BUILD_LIST 0 > 3 DUP_TOP > 4 STORE_FAST 0 (_[1]) > 7 LOAD_CONST 1 (1) > 10 BUILD_LIST 1 > 13 GET_ITER > >> 14 FOR_ITER 13 (to 30) > 17 STORE_FAST 1 (i) > 20 LOAD_FAST 0 (_[1]) > 23 LOAD_FAST 1 (i) > 26 LIST_APPEND > 27 JUMP_ABSOLUTE 14 > >> 30 DELETE_FAST 0 (_[1]) > 33 POP_TOP > 34 LOAD_CONST 0 (None) > 37 RETURN_VALUE > In 3.0 >>> def f(): [i for i in [1]] >>> import dis >>> dis.dis(f) 1 0 LOAD_CONST 1 ( at 0x01349BF0, file "", line 1>) 3 MAKE_FUNCTION 0 6 LOAD_CONST 2 (1) 9 BUILD_LIST 1 12 GET_ITER 13 CALL_FUNCTION 1 16 POP_TOP 17 LOAD_CONST 0 (None) 20 RETURN_VALUE Running OP code in 3.0 with print ()s added gives pre 0.a 1.b 2.c 3.d post Traceback (most recent call last): File "C:\Programs\Python30\misc\temp7.py", line 32, in """ % gie) File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 7, in File "", line 7, in File "C:\Programs\Python30\misc\temp7.py", line 12, in ts return ts % self File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 2, in File "", line 1, in NameError: global name 'i' is not defined > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > >>>> def xeval(x): return eval(x, ns) > ... >>>> ns = dict(xeval=xeval) >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in xeval > File "", line 1, in > NameError: name '_[1]' is not defined Which Python? 3.0 prints "[[]]"! But I think the nested listcomp *is* in a separate namespace here. I will leave it to you or OP to disect how his and your code essentially differ from 3.0 (and maybe 2.6) implementation's viewpoint. Terry Jan Reedy From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:40:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:40:40 GMT Subject: Convention vs. fascism (was: General direction) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> Message-ID: <017fb1f3$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> > Familiarize yourself with PEP8 for naming and coding-conventions >> > first. >> >> Enough of the PEP8-fascism please. It is not compulsory to follow PEP8 >> in order to be allowed to learn Python. If Guido wanted it compulsory, >> he'd have made the compiler enforce it. > > You are responding to something in Diez's message that I can't see. > Nowhere does he say anything about PEP 8 being compulsory. Quite the > contrary, he suggests gaining *familiarity* with PEP 8, and calls it a > set of *conventions*. He doesn't *suggest* anything. He uses the imperative case -- it's a command. It may not have been Diez's deliberate, conscious intention to order the OP to learn PEP8, but without a modifier like "I think you should", that's what he did. That's why I emphasised "suggest" in my response: it's not an order, but it is recommended. On its own, that wouldn't have been enough to warrant a response. I'm sure I've thoughtlessly and inappropriately used unmodified imperative commands in the past, and I'll probably do it again. But add to it the perfunctory way he used this mysterious (to a newbie) jargon "PEP8", without even the courtesy of a link, and the overall tone was newbie hostile. I'm sure that wasn't Diez's intention, because the rest of his post was not like that. >> Having said that, I will *suggest* to the Original Poster that you >> should follow PEP8 as much as possible. It will save you a lot of grief >> in the long run. > > This, on the other hand, seems pretty much a re-phrasing of what Diez > already said. That's because I agree with Diez that following PEP8 is generally a good thing, but don't agree with him that it is necessary to learn the naming conventions before learning the language. An overly strict approach will just frighten the newbies off. Part of the reason that Python is successful is that it is accessible to newbies, and giving them strict Thou Shalt Do This commands is quite off-putting. -- Steven From tjreedy at udel.edu Thu Jan 15 17:41:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:41:37 -0500 Subject: List comprehension - NameError: name '_[1]' is not defined ? In-Reply-To: References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: mario ruggier wrote: > On Jan 15, 4:06 pm, Steven D'Aprano cybersource.com.au> wrote: > > Hi Steve! > >>> class GetItemEvaluator(object): >>> def __init__(self): >>> self.globals = globals() # some dict (never changes) > > Ya, this is just a boiled down sample, and for simplicity I set to to > the real globals(), so of course it will change when that changes... > but in the application this is a distinct dict, that is entirely > managed by the application, and it never changes as a result of an > *evaluation*. It would have been less confusing if you had written self.globals = {} # a constant dict or even self.constants = {} # empty here only for simplicity This might also make the 3.0 error message clearer (see other post). tjr From clp2 at rebertia.com Thu Jan 15 17:43:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 14:43:35 -0800 Subject: Import functions in current namespace In-Reply-To: References: Message-ID: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> On Thu, Jan 15, 2009 at 2:35 PM, Markus Schreyer wrote: > Hi, > we embedded python into our application via Swig. Now we like to wrap the > raw API functionality into a nicer more handleable module, but instead of > repeating every function in this wrapper i thought about importing them into > the namespace of the wrapper module. I like to give you an example of what > we like to achive. > Swig generates a file called "ppms.py" which contains the API classes and > functions. > Lets say the ppms.py contains a function called foo(). The wrapper.py should > now import the function foo() of the module ppms into the local namespace. > the swig module: > def foo(): > pass > def foo0(): > pass > One possibility would be to repeat the function in the wrapper.py like: > import ppms.py > def foo(): > return ppms.foo() > def foo0(): > return ppms.foo0()+1 > Imho this is a little ugly. So I thought about importing the content of > ppms.py (the autgenerated one) into the namespace of the wrapper. Every > definition of a fuction in the wrapper should overwrite the function in the > imported module but a call to a function which is not defined in the wrapper > goes right through. > # wrapper.py - magic version > "magic_import" ppms.py I believe the magic you seek is: from ppms import * Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:43:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:43:40 GMT Subject: Executing global code References: Message-ID: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e. g. these two statements > > x = 42 > x += 1 > > and want to rerun it with the effect of x becoming 44? That is not > possible Unless you move the value of x into external storage. Untested: try: f = open('mystorage.txt', 'r') except IOError: x = 42 else: x = int(f.read()) x += 1 Naturally the above is not bulletproof enough for production use. I'm curious why the Original Poster wants to do such a thing, and particularly the prohibition against moving code into a function. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:44:14 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:44:14 GMT Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <017fb2c9$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 07:56:02 -0800, mario ruggier wrote: > On Jan 15, 4:06?pm, Steven D'Aprano cybersource.com.au> wrote: > > Hi Steve! > >> > class GetItemEvaluator(object): >> > ? ? def __init__(self): >> > ? ? ? ? self.globals = globals() # some dict (never changes) > > Ya, this is just a boiled down sample, and for simplicity I set to to > the real globals(), You should make that more clear when posting, in the code snippet as well as the descriptive text. And if you *did* make it clear, then *I* should read your post more carefully. Regards, -- Steven From tjreedy at udel.edu Thu Jan 15 17:49:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:49:22 -0500 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: Eric Brunel wrote: > Hi all, > > I found a behaviour that might be a bug in Tkinter for Python 2.6. Here > is the script: > > ----------------------------- > from Tkinter import * > from tkMessageBox import * > from tkFileDialog import * > > root = Tk() > > def ask_file(): > file_name = askopenfilename() > print file_name > > def ask_confirm(): > answer = askyesno() > print answer > > Button(root, text='Ask file', command=ask_file).pack() > Button(root, text='Ask confirm', command=ask_confirm).pack() > > root.mainloop() > ----------------------------- > > Scenario: > - Run the script. > - Click the 'Ask confirm' button and answer 'Yes'; it should print True, > which is the expected answer. > - Click the 'Ask file' button, select any file and confirm. > - Click the 'Ask confirm' button and answer 'Yes'. > > At the last step, the script prints 'False' for me, which is quite > wrong. Can anybody confirm this? > > I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise > Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, > it seems to work correctly on Windows 2000. I could only test with > Python 2.6, and not 2.6.1. But I didn't see any mention of this problem > in the release notes. > > And BTW, if this is actually a bug, where can I report it? bugs.python.org From bearophileHUGS at lycos.com Thu Jan 15 17:49:29 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 14:49:29 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> Message-ID: Matimus, your suggestions are all good. Try-except is slower than: if x in adict: ... else: ... A defaultdict is generally faster (there are some conditions when it's not faster, but they aren't much common. I think it's when the ratio of duplicates is really low), creating just a tuple instead of a class helps a lot, and when the CPU/OS allow it, Psyco too may help some here. If the resulting speed isn't enough yet, consider that Python dicts are quite fast, so you may need lot of care to write D/C/C++/Clisp code that's faster for this problem. I also suspect that when they become very large, Python dicts lose some of their efficiency. If this is true, you may switch to a new dictionary every chunk of file, and then merge the dicts at the end. I don't actually know if this may speed up your Python code even more (if you experiment this, I'd like to know if it's false). Bye, bearophile From benjamin.kaplan at case.edu Thu Jan 15 17:57:34 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 15 Jan 2009 17:57:34 -0500 Subject: newbie OOP question (what's the analogue to java interfaces in Python?) In-Reply-To: <000001c97758$2b01dea0$81059be0$@net> References: <000001c97758$2b01dea0$81059be0$@net> Message-ID: On Thu, Jan 15, 2009 at 4:28 PM, Larry Caruso wrote: > I'm an old time C programmer, but a newbie to OOP and Python. One OOP > book I'm reading, "Holub on Patterns," discusses Java Interfaces in some > detail (see http://en.wikipedia.org/wiki/Interface_(Java) for example) but > with limited time, I'm hoping to avoid learning Java just to understand some > key points of this book. Can anyone tell me what the analogue, if any, would > be in Python? TIA. > > > There isn't one (well, you could use Abstract Base Classes if you're using Python 3, but you don't need to). Interfaces are needed in Java for 2 reasons. 1. There are times when designing something that you don't really care what the class actually is, just what it does (i.e. iterators). With Java's static typing, you either have to overload the method for each object that needs to work with this method or use inheritance. Python uses duck typing- if it looks like a duck and quacks like a duck, it must be a duck. No static typing= no need to inherit. Inheritance in Python is only used if you want to reuse some of the behavior of the base class. 2. Interfaces in Java are a result of not supporting multiple inheritance. If you really need interfaces (for instance, you're rewriting a Java program and you don't want to change anything), you can just use base classes. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:58:01 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:58:01 GMT Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <017fb604$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 23:22:48 +0100, Christian Heimes wrote: >> is there anything that can be done to speed up this simply code? right >> now it is taking well over 15 minutes to process, on a 3 Ghz machine >> with lots of RAM (though this is all taking CPU power, not RAM at this >> point.) > > class MyClass(object): > # a new style class with slots saves some memory > __slots__ = ("field1", "field2", "field2") I was curious whether using slots would speed up attribute access. >>> class Parrot(object): ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c ... >>> class SlottedParrot(object): ... __slots__ = 'a', 'b', 'c' ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c ... >>> >>> p = Parrot(23, "something", [1, 2, 3]) >>> sp = SlottedParrot(23, "something", [1, 2, 3]) >>> >>> from timeit import Timer >>> setup = "from __main__ import p, sp" >>> t1 = Timer('p.a, p.b, p.c', setup) >>> t2 = Timer('sp.a, sp.b, sp.c', setup) >>> min(t1.repeat()) 0.83308887481689453 >>> min(t2.repeat()) 0.62758088111877441 That's not a bad improvement. I knew that __slots__ was designed to reduce memory consumption, but I didn't realise they were faster as well. -- Steven From jervisau at gmail.com Thu Jan 15 17:59:14 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 16 Jan 2009 09:59:14 +1100 Subject: Python DateTime Manipulation In-Reply-To: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> References: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> Message-ID: <8e63a5ce0901151459w67d28517xf7212a26db347a56@mail.gmail.com> On Fri, Jan 16, 2009 at 9:19 AM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and then strip out the day value, turn it into an > int and subtract seven, but the value "-6" doesn't mean anything in > terms of days =). > > Does anyone have an idea as to how I can subtract 7 days without > turning the date string into an int? > > Perfect Scenario: > perfectdate = 200901010100 - 7Days > print perfect date > 200812250100 > > > What I have so far: > import time, os, re > useryear = raw_input("Enter Year (numerical YYYY): ") > usermonth = raw_input("Enter Month (numerical MM): ") > userday = raw_input("Enter Day (numerical DD): ") > usertime = raw_input("Enter Time (24-hour clock hhmm): ") > #userday = int(userday) > #secondday = userday - 07 > #secondday = str(secondday) > #userday = str(userday) > #firstdate = useryear + usermonth + secondday + usertime > seconddate = useryear + usermonth + userday + usertime > seconddate = time.strptime(seconddate, %Y%m%d%H%M) > print seconddate > -- > http://mail.python.org/mailman/listinfo/python-list > import datetime DATE_FORMAT = '%Y%m%d%H%M' original = datetime.datetime.strptime(yourstring, DATE_FORMAT ) newtime = original - datetime.timedelta(days=7) perfectdate = newtime.strftime(DATE_FORMAT) print perfectdate Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.watrous at gmail.com Thu Jan 15 18:00:56 2009 From: daniel.watrous at gmail.com (Daniel) Date: Thu, 15 Jan 2009 15:00:56 -0800 (PST) Subject: logging multiple messages Message-ID: I was fighting with a problem all day that was producing multiple messages in my logging output. The problem was related to the fact that I was defining logging handlers multiple times. I found the following posting from a few years ago that related to my problem: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8a707c289642c668/44f16cf5ba68721f?lnk=gst&q=logging#44f16cf5ba68721f What I did was the following: def initLogging(loggingArea): # create/get logger logger = logging.getLogger("mylogger") logger.setLevel(logging.DEBUG) # setup Handlers if len(logger.handlers) == 0: # create handlers only if there are none sh = logging.StreamHandler() # now add the handlers logger.addHandler(sh) If the logger already has handlers nothing happens, otherwise they're created and added to the logger. Now I can call initLogging ('mylogarea') whereever I need to without getting multiple messages. If you know of a better way to do this let me know... From leoneel at gmail.com Thu Jan 15 18:04:26 2009 From: leoneel at gmail.com (neel) Date: Thu, 15 Jan 2009 15:04:26 -0800 (PST) Subject: How to verify whether a process got hanged or still alive. Message-ID: <9b60f865-7585-4251-810e-7c86d9a2f876@j39g2000yqn.googlegroups.com> Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel From leoneel at gmail.com Thu Jan 15 18:04:53 2009 From: leoneel at gmail.com (neel) Date: Thu, 15 Jan 2009 15:04:53 -0800 (PST) Subject: How to verify whether a process got hanged or still alive. Message-ID: Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel From mario.ruggier at gmail.com Thu Jan 15 18:05:18 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 15:05:18 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: On Jan 15, 11:35?pm, Terry Reedy wrote: > Peter Otten wrote: > > List comprehensions delete the helper variable after completion: > > I do not believe they did in 2.4. ?Not sure of 2.5. ?There is certainly > ? a very different implementation in 3.0 and, I think, 2.6. ?OP > neglected to mention Python version he tested on. Code meant to run on > 2.4 to 3.0 cannot depend on subtle listcomp details. > > > > >>>> def f(): [i for i in [1]] > > ... > >>>> dis.dis(f) > > ? 1 ? ? ? ? ? 0 BUILD_LIST ? ? ? ? ? ? ? 0 > > ? ? ? ? ? ? ? 3 DUP_TOP > > ? ? ? ? ? ? ? 4 STORE_FAST ? ? ? ? ? ? ? 0 (_[1]) > > ? ? ? ? ? ? ? 7 LOAD_CONST ? ? ? ? ? ? ? 1 (1) > > ? ? ? ? ? ? ?10 BUILD_LIST ? ? ? ? ? ? ? 1 > > ? ? ? ? ? ? ?13 GET_ITER > > ? ? ? ? >> ? 14 FOR_ITER ? ? ? ? ? ? ? ?13 (to 30) > > ? ? ? ? ? ? ?17 STORE_FAST ? ? ? ? ? ? ? 1 (i) > > ? ? ? ? ? ? ?20 LOAD_FAST ? ? ? ? ? ? ? ?0 (_[1]) > > ? ? ? ? ? ? ?23 LOAD_FAST ? ? ? ? ? ? ? ?1 (i) > > ? ? ? ? ? ? ?26 LIST_APPEND > > ? ? ? ? ? ? ?27 JUMP_ABSOLUTE ? ? ? ? ? 14 > > ? ? ? ? >> ? 30 DELETE_FAST ? ? ? ? ? ? ?0 (_[1]) > > ? ? ? ? ? ? ?33 POP_TOP > > ? ? ? ? ? ? ?34 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > > ? ? ? ? ? ? ?37 RETURN_VALUE > > In 3.0 > ?>>> def f(): [i for i in [1]] > > ?>>> import dis > ?>>> dis.dis(f) > ? ?1 ? ? ? ? ? 0 LOAD_CONST ? ? ? ? ? ? ? 1 ( at > 0x01349BF0, file "", line 1>) > ? ? ? ? ? ? ? ?3 MAKE_FUNCTION ? ? ? ? ? ?0 > ? ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 2 (1) > ? ? ? ? ? ? ? ?9 BUILD_LIST ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ? 12 GET_ITER > ? ? ? ? ? ? ? 13 CALL_FUNCTION ? ? ? ? ? ?1 > ? ? ? ? ? ? ? 16 POP_TOP > ? ? ? ? ? ? ? 17 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ? 20 RETURN_VALUE > > Running OP code in 3.0 with print ()s added gives > > pre 0.a 1.b 2.c 3.d ?post > > Traceback (most recent call last): > ? ?File "C:\Programs\Python30\misc\temp7.py", line 32, in > ? ? ?""" % gie) > ? ?File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ > ? ? ?return eval(expr, self.globals, self.locals) > ? ?File "", line 7, in > ? ?File "", line 7, in > ? ?File "C:\Programs\Python30\misc\temp7.py", line 12, in ts > ? ? ?return ts % self > ? ?File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ > ? ? ?return eval(expr, self.globals, self.locals) > ? ?File "", line 2, in > ? ?File "", line 1, in > NameError: global name 'i' is not defined > > > If you manage to run two nested listcomps in the same namespace you get a > > name clash and the inner helper variable overwrites/deletes the outer: > > >>>> def xeval(x): return eval(x, ns) > > ... > >>>> ns = dict(xeval=xeval) > >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "", line 1, in xeval > > ? File "", line 1, in > > NameError: name '_[1]' is not defined > > Which Python? ?3.0 prints "[[]]"! But I think the nested listcomp *is* > in a separate namespace here. ?I will leave it to you or OP to disect > how his and your code essentially differ from 3.0 (and maybe 2.6) > implementation's viewpoint. I was testing on 2.6, but running it thru 2.4 and 2.5 it seems behaviour is the same there. For 3.0 it does change... and there seems not to be the "_[1]" key defined, and, what's more, it gives a: NameError: name 'j' is not defined. In any case, that was an exploration to get a feeling for how the listcomps behave (performance) if evaluated directly as opposed to doing the equivalent from within a function. It turned out to be slower, so I moved on... but, should it have been faster, then differences between how the different python versions handle list comps internally would have been a next issue to address. I think the globals dict is not touched by eval'ing a list comp... it is any not "constant" as such, just that it is not affected by evaluations (unless the python application decides to affect it in some way or another). But, evaluating a template by definition does not change the globals dict. > Terry Jan Reedy From markus.schreyer at gmail.com Thu Jan 15 18:07:01 2009 From: markus.schreyer at gmail.com (Markus Schreyer) Date: Fri, 16 Jan 2009 00:07:01 +0100 Subject: Import functions in current namespace In-Reply-To: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> References: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> Message-ID: Wow.. :) I think this is one kind of a stupid question.. ;) Anyway.. thanks a lot.. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Thu Jan 15 18:11:19 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 15 Jan 2009 23:11:19 +0000 Subject: report on building of python 2.5.2 under msys under wine on linux. In-Reply-To: References: Message-ID: > practical decision, due to /bin/sh.exe messing around and stopping > python.exe from running! (under cmd.exe it's fine. i have to do a > bit more investigation: http://bugs.python.org/issue4956 found it. From google at mrabarnett.plus.com Thu Jan 15 18:13:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 23:13:53 +0000 Subject: Executing global code In-Reply-To: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> References: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> Message-ID: <496FC331.3070805@mrabarnett.plus.com> Steven D'Aprano wrote: > On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> You have a module containing e. g. these two statements >> >> x = 42 >> x += 1 >> >> and want to rerun it with the effect of x becoming 44? That is not >> possible > > Unless you move the value of x into external storage. Untested: > > > try: > f = open('mystorage.txt', 'r') > except IOError: > x = 42 > else: > x = int(f.read()) > x += 1 > > > Naturally the above is not bulletproof enough for production use. > > I'm curious why the Original Poster wants to do such a thing, and > particularly the prohibition against moving code into a function. > Perhaps there are functions which contain 'global'. Anyway, the solution has already been given, namely put it inside a loop, unless there's soem reason why that's not possible. From bignose+hates-spam at benfinney.id.au Thu Jan 15 18:24:19 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 10:24:19 +1100 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87vdsgb1b0.fsf@benfinney.id.au> Steven D'Aprano writes: > On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > > > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > >> > >> > Familiarize yourself with PEP8 for naming and > >> > coding-conventions first. > >> > >> Enough of the PEP8-fascism please. It is not compulsory to follow > >> PEP8 in order to be allowed to learn Python. > > > > You are responding to something in Diez's message that I can't > > see. Nowhere does he say anything about PEP 8 being compulsory. > > Quite the contrary, he suggests gaining *familiarity* with PEP 8, > > and calls it a set of *conventions*. > > He doesn't *suggest* anything. He uses the imperative case -- it's a > command. Regardless, even if it was an imperial order with government backing, the instruction was not to *follow* PEP 8, but to *become familiar with* it. That isn't fascism, and to read that into it and assume a commandment that Diez didn't make is overreaction on your part. -- \ ?[W]hoever is able to make you absurd is able to make you | `\ unjust.? ?Voltaire | _o__) | Ben Finney From perfreem at yahoo.com Thu Jan 15 18:31:51 2009 From: perfreem at yahoo.com (Per Freem) Date: Thu, 15 Jan 2009 15:31:51 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> thanks to everyone for the excellent suggestions. a few follow up q's: 1] is Try-Except really slower? my dict actually has two layers, so my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where as the bKeys are the ones that are in the millions. so in that case, doing a Try-Except on aKey should be very efficient, since often it will not fail, where as if I do: "if aKey in my_dict", that statement will get executed for each aKey. can someone definitely say whether Try-Except is faster or not? My benchmarks aren't conclusive and i hear it both ways from several people (though majority thinks TryExcept is faster). 2] is there an easy way to have nested defaultdicts? ie i want to say that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact that my_dict is a dictionary, whose values are dictionary that map to ints. but that syntax is not valid. 3] more importantly, is there likely to be a big improvement for splitting up one big dictionary into several smaller ones? if so, is there a straight forward elegant way to implement this? the way i am thinking is to just fix a number of dicts and populate them with elements. then during retrieval, try the first dict, if that fails, try the second, if not the third, etc... but i can imagine how that's more likely to lead to bugs / debugging give the way my code is setup so i am wondering whether it is really worth it. if it can lead to a factor of 2 difference, i will definitely implement it -- does anyone have experience with this? On Jan 15, 5:58?pm, Steven D'Aprano wrote: > On Thu, 15 Jan 2009 23:22:48 +0100, Christian Heimes wrote: > >> is there anything that can be done to speed up this simply code? right > >> now it is taking well over 15 minutes to process, on a 3 Ghz machine > >> with lots of RAM (though this is all taking CPU power, not RAM at this > >> point.) > > > class MyClass(object): > > ? ? # a new style class with slots saves some memory > > ? ? __slots__ = ("field1", "field2", "field2") > > I was curious whether using slots would speed up attribute access. > > >>> class Parrot(object): > > ... ? ? def __init__(self, a, b, c): > ... ? ? ? ? ? ? self.a = a > ... ? ? ? ? ? ? self.b = b > ... ? ? ? ? ? ? self.c = c > ...>>> class SlottedParrot(object): > > ... ? ? __slots__ = 'a', 'b', 'c' > ... ? ? def __init__(self, a, b, c): > ... ? ? ? ? ? ? self.a = a > ... ? ? ? ? ? ? self.b = b > ... ? ? ? ? ? ? self.c = c > ... > > >>> p = Parrot(23, "something", [1, 2, 3]) > >>> sp = SlottedParrot(23, "something", [1, 2, 3]) > > >>> from timeit import Timer > >>> setup = "from __main__ import p, sp" > >>> t1 = Timer('p.a, p.b, p.c', setup) > >>> t2 = Timer('sp.a, sp.b, sp.c', setup) > >>> min(t1.repeat()) > 0.83308887481689453 > >>> min(t2.repeat()) > > 0.62758088111877441 > > That's not a bad improvement. I knew that __slots__ was designed to > reduce memory consumption, but I didn't realise they were faster as well. > > -- > Steven From http Thu Jan 15 18:38:11 2009 From: http (Paul Rubin) Date: 15 Jan 2009 15:38:11 -0800 Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: <7xmydsxhr0.fsf@ruckus.brouhaha.com> Per Freem writes: > 2] is there an easy way to have nested defaultdicts? ie i want to say > that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact > that my_dict is a dictionary, whose values are dictionary that map to > ints. but that syntax is not valid. my_dict = defaultdict(lambda: defaultdict(int)) From db3l.net at gmail.com Thu Jan 15 18:42:05 2009 From: db3l.net at gmail.com (David Bolen) Date: Thu, 15 Jan 2009 18:42:05 -0500 Subject: Python Crashes References: Message-ID: koranthala writes: > Could anyone guide me on this? I have been facing this issue for a > day, and cannot seem to solve it. We had a scheduling system that had a similar "once in a long while hard Windows-process crash" which after a bunch of work to try to track down the source, the most robust solution was just to trap the failure and restart, as the system ran off a persistent state that was already engineering to be robust in the case of a hardware crash (power outage, etc...) While I agree with others that it's most likely a fault in an extension that gets tickled over time, as was likely in our case, we needed all our extensions and were using latest versions at the time. So if your application is such that just restarting it is practical, it may be a sufficient temporary (or not so temporary - our system ran for years this way) workaround for you. What you can do is execute your script from beneath control of another script, and trap process failures, restarting the script on non-standard exits. This can be in addition to any top level exception handling of the child script itself, where it can provide more graceful support for internal failures. The trick, under Windows, is to ensure that you disable any pop-up windows that may occur during the crash, otherwise the monitoring task never gets a chance to get control and restart things. With the pywin32 extension, something like: import win32api, win32con old_mode = win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOGPFAULTERRORBOX | win32con.SEM_NOOPENFILEERRORBOX) Or with ctypes: import ctypes SEM_FAILCRITICALERRORS = 1 SEM_NOGPFAULTERRORBOX = 2 SEM_NOOPENFILEERRORBOX = 0x8000 old_mode = ctypes.windll.kernel32.SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX) at any point prior to starting the child process will ensure that hard process errors will silently terminate the process and return control the parent, as well as not popping up any dialog boxes that require intervention by a person. Should the process exit harshly, the exit code should be fairly clear (I forget, but I think it's in the 0xC000xxxx range, maybe 0xC0000005 for a typical GPF), and you can decide on restarting the task as opposed to just exiting normally. This will also prevent any pop-ups in the main monitoring process. You can restore old behavior there after starting the child by making another call to SetErrorMode using old_mode as the argument. -- David From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 18:43:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 23:43:20 GMT Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> Message-ID: <017fc0a2$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 14:49:29 -0800, bearophileHUGS wrote: > Matimus, your suggestions are all good. > > Try-except is slower than: > if x in adict: ... else: ... Not according to my tests. >>> def tryexcept(D, key): ... try: ... return D[key] ... except KeyError: ... return None ... >>> def ifinelse(D, key): ... if key in D: ... return D[key] ... else: ... return None ... >>> from timeit import Timer >>> setup = "from __main__ import tryexcept, ifinelse; D = {2: 'c'}" >>> >>> t1 = Timer('tryexcept(D, 2)', setup) >>> t2 = Timer('ifinelse(D, 2)', setup) >>> >>> min(t1.repeat()) # try...except 0.61699414253234863 >>> min(t2.repeat()) # if...else 0.71856999397277832 Perhaps what you meant to say is that try...except is slower *if the key is not found*. And in that case, there's a truly massive difference: >>> t3 = Timer('tryexcept(D, 5)', setup) >>> t4 = Timer('ifinelse(D, 5)', setup) >>> >>> min(t3.repeat()) # try...except 5.3846139907836914 >>> min(t4.repeat()) # if...else 0.5983281135559082 Which solution is faster on average will depend on the ratio of keys found versus keys not found. On my PC, based on the above results, if...else becomes faster when just 2% of keys are not found. But if you can arrange matters so that nearly all keys are found, then try...except can be faster. There's another solution nobody has mentioned (as far as I can see): the get method. In my test I call get() from inside a function, rather than directly, so that the timing results include the function call overhead for all three strategies. >>> def get(D, key): ... return D.get(key) ... >>> >>> setup = "from __main__ import get; D = {2: 'c'}" >>> t5 = Timer('get(D, 2)', setup) >>> t6 = Timer('get(D, 5)', setup) >>> >>> min(t5.repeat()) # found key 0.88362312316894531 >>> min(t6.repeat()) # missing key 0.87782382965087891 -- Steven From lists at cheimes.de Thu Jan 15 19:08:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jan 2009 01:08:57 +0100 Subject: optimizing large dictionaries In-Reply-To: <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: Per Freem schrieb: > 1] is Try-Except really slower? my dict actually has two layers, so > my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions. so in that case, > doing a Try-Except on aKey should be very efficient, since often it > will not fail, where as if I do: "if aKey in my_dict", that statement > will get executed for each aKey. can someone definitely say whether > Try-Except is faster or not? My benchmarks aren't conclusive and i > hear it both ways from several people (though majority thinks > TryExcept is faster). A defaultdict is faster than a try/except if the key is missing. A defaultdict is the canonical way to solve your problem, too. > 3] more importantly, is there likely to be a big improvement for > splitting up one big dictionary into several smaller ones? if so, is > there a straight forward elegant way to implement this? the way i am > thinking is to just fix a number of dicts and populate them with > elements. then during retrieval, try the first dict, if that fails, > try the second, if not the third, etc... but i can imagine how that's > more likely to lead to bugs / debugging give the way my code is setup > so i am wondering whether it is really worth it. > if it can lead to a factor of 2 difference, i will definitely > implement it -- does anyone have experience with this? Nested dicts more likely slower than one large dict. You have to keep in mind that Python's dict have been optimized to utilize the CPU cache as much as possible. Any layer you put on top of a single dict can increase the number of cache misses and increase the number of function calls. This may lead to a general slow down. I assume that you won't notice a slow down. However my instincts tell me that you'll hardly get a speedup, either. You have to roll your own benchmarks to study which algorithm is faster in reality. Christian From gert.cuykens at gmail.com Thu Jan 15 19:14:46 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:14:46 -0800 (PST) Subject: [python3.0] s = sha1(random()).hexdigest() Message-ID: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> from random import random from hashlib import sha1 s = sha1(random()).hexdigest() TypeError: object supporting the buffer API required, How does sha1 work in python3.0 please ? From tjreedy at udel.edu Thu Jan 15 19:20:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 19:20:22 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xmydsw7rj.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <7xmydsw7rj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >> I do not see any connection, really, between what you describe above >> and your desire for static type-checking expressed elsewhere. When I >> was regularly doing analysis of empirical data files, I learned >> (sometimes the hard way, as you describe above) to **ALWAYS** run >> preliminary checks of all fields through the entire file > > Right. And if the file is large enough that even parsing all the > records to check the fields takes hours, well, that's where I'm at. So what is the problem? Let it run overnight. If you want more speed, try numpy or Cython or C functions (swigged or ctyped) or... To guarantee no crashes, make your top level something like for line in open('humongous.dat', 'r'): try: except Exception as e: print(line, e) (How trivial in Python!) If your total system (including electricity supply and busy fingers of other people) is unstable, or you think you might want to interrupt it, keep track of lines or bytes read and write a report every gigabyte or so with enough info to restart from the last checkpoint -- just like reloading your last save in a video game when your avatar dies. Terry Jan Reedy From http Thu Jan 15 19:20:41 2009 From: http (Paul Rubin) Date: 15 Jan 2009 16:20:41 -0800 Subject: [python3.0] s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> Message-ID: <7xy6xcqexy.fsf@ruckus.brouhaha.com> gert writes: > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? sha1 hashes strings, not numbers. Try using str(random()). But if you want some random hex digits, try os.urandom(10).encode('hex') rather than messing with sha1. From gert.cuykens at gmail.com Thu Jan 15 19:21:51 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:21:51 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> Message-ID: <9ed5092f-0242-4b50-b23e-11384ba265d2@f20g2000yqg.googlegroups.com> On Jan 16, 1:14?am, gert wrote: > from random import random > from hashlib import sha1 > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? s = sha1(bytes(random(),'utf-8')).hexdigest() i found this, looks let say strange. But it works :) From gert.cuykens at gmail.com Thu Jan 15 19:34:41 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:34:41 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> Message-ID: <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> On Jan 16, 1:20?am, Paul Rubin wrote: > gert writes: > > s = sha1(random()).hexdigest() > > > TypeError: object supporting the buffer API required, > > > How does sha1 work in python3.0 please ? > > sha1 hashes strings, not numbers. ?Try using str(random()). ?But if > you want some random hex digits, try os.urandom(10).encode('hex') > rather than messing with sha1. s = urandom(10).encode('hex') AttributeError: 'bytes' object has no attribute 'encode' From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 19:41:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 00:41:15 GMT Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> Message-ID: <017fce36$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> >> >> > Familiarize yourself with PEP8 for naming and coding-conventions >> >> > first. >> >> >> >> Enough of the PEP8-fascism please. It is not compulsory to follow >> >> PEP8 in order to be allowed to learn Python. >> > >> > You are responding to something in Diez's message that I can't see. >> > Nowhere does he say anything about PEP 8 being compulsory. Quite the >> > contrary, he suggests gaining *familiarity* with PEP 8, and calls it >> > a set of *conventions*. >> >> He doesn't *suggest* anything. He uses the imperative case -- it's a >> command. > > Regardless, even if it was an imperial order with government backing, > the instruction was not to *follow* PEP 8, but to *become familiar with* > it. That isn't fascism, and to read that into it and assume a > commandment that Diez didn't make is overreaction on your part. Okay, fair enough, I made a mistake in saying "It is not compulsory to follow PEP8". What I should have said was "It is not compulsory to become familiar with PEP8". Now that you've put me in my place, can we please get back to becoming a hostile and unforgiving place for newbies who dare to try learning Python without first becoming familiar with PEP8? *wink* Seriously, I'll accept a small rebuke. My choice of the word "fascism" was poor, and I regret it. In my defense, I thought it was better than my initial thought, which was "style-Nazi", but in hindsight given the proliferation of somewhat tongue-in-cheek foo-Nazi terms (soup-Nazi, grammar-Nazi, fashion-Nazi, etc.) maybe I should have stuck with it. But by focusing on such a small aspect of my post (a quarter of my text), while ignoring the more substantial aspects, it seems that you are giving tacit approval of precisely the attitude I am objecting to: that there is a One True And Correct Right Way to learn and/or use Python. For a community that celebrates the dynamism of the language, and supports giving the programmer the ability to shoot themselves in the foot ("we're all adults here"), we can sometimes be remarkably intolerant of things which are a matter of taste. Sometimes it seems that there's a Party line, and individuals can be criticized for failing to be enthusiastic enough about supporting it. This is a good example: it isn't enough that I agreed with Diez's substantial point that PEP8 is a good thing; it isn't enough that I made it more likely that the OP would find and read PEP8 by posting a link to it; but by making a mild criticism of *the way* Diez introduced PEP8 to the newbie, *I'm* the bad guy. -- Steven From kylotan at gmail.com Thu Jan 15 19:47:39 2009 From: kylotan at gmail.com (Ben Sizer) Date: Thu, 15 Jan 2009 16:47:39 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: <965ac14d-3a1d-4a00-bc94-6d09f2490d67@v42g2000yqv.googlegroups.com> On Jan 14, 4:37 pm, Ivan Illarionov wrote: > On Jan 14, 1:49 pm, Ben Sizer wrote: > > > No, I don't want to do anything with sys.path apart from see it. I > > just wanted my original question answered, not a guess at my intent > > and a solution for something I'm not doing. ;) Thanks though! > > > Again - why can I not reference sys from within the function? > > Ah, sorry for wrong guess. > > I would try to use ourNamespace_ dict for > both globals and locals in PyRun_String call. Yes, this seems to fix it, thanks. But why? Can some Python guru explain why these two dictionaries must be the same? (Or what steps we must take if we want them to be separate?) The documentation is not very clear. I had hoped to be able to clear out the locals dictionary while leaving useful functions intact in the globals dictionary, but it would appear that is not practical. (On a separate note, while trying to debug this it seemed that Python will look for debug versions of a library when you embed it in debug mode, and will fail to find a module if you only have the release versions there. The error message you get isn't too helpful about this however, and I only worked it out by looking at the very long list of filesystem calls Python made to try and find it. Anybody wishing to speed up import times might want to ensure they don't have a long Python path and as few eggs in site-packages as possible.) -- Ben Sizer From gert.cuykens at gmail.com Thu Jan 15 19:47:57 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:47:57 -0800 (PST) Subject: except sqlite3.Error as e: Message-ID: <3260e889-a641-4435-bcef-8f60dfdfda2e@z1g2000yqn.googlegroups.com> except sqlite3.Error as e: ERROR = "Error " + ... how does except work in python3 ? From benlucas99 at googlemail.com Thu Jan 15 19:59:54 2009 From: benlucas99 at googlemail.com (benlucas99 at googlemail.com) Date: Thu, 15 Jan 2009 16:59:54 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect Message-ID: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> I'm having problems with the ordering of the tuples produced by urllib.urlencode. Taking an example straight from the docs and so doing the following: import urllib ... params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) print params The documentation for urlencode( query[, doseq]) says: "The order of parameters in the encoded string will match the order of parameter tuples in the sequence" but I'm getting: "eggs=2&bacon=0&spam=1" Should this not produce: "spam=1&eggs=2&bacon=0" ? I am seeing this "incorrect" result using Python 2.5.1 and ActivePython 2.3.2 (both on XP SP2). What am I doing wrong? I've been googling around for an answer but I'm a Python newbie and so don't know the ropes yet. Thanks for any help. Ben From musicguy at alphaios.net Thu Jan 15 20:02:55 2009 From: musicguy at alphaios.net (The Music Guy) Date: Thu, 15 Jan 2009 19:02:55 -0600 Subject: English-like Python Message-ID: <1232067775.15931.25.camel@localhost> Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a programming language which is actually a spoken one. For example, the following code... >>> import os >>> >>> def list_files(dirname): >>> for p in os.listdir(dirname): >>> print p >>> >>> list_files("some_dir") foo bar etc ...might be translated as... >>> Import the operating system module. >>> >>> Define a new function as "list files" which accepts "a path" and does the following: For every item in the list returned by the operating system's directory listing of the given path, do the following: Print the item. >>> >>> List files from "some_dir". foo bar etc Obviously, creating a parser capable of handling such "code" would require a very good understanding not only of the English language but also of how ideas expressed in spoken languages are represented in terms that a computer can understand. A language like this would, of course, blow a lot of staple coding coding concepts like "variables," "objects," etc. right out of the water. I think, however, that it could be done, and wouldn't necessarily have to be any slower than any other scripting language as any text/code could be cached as bytecode, just like Python. I know it's sort of silly but I think something like this would be very interesting, maybe even useful. ^_^ -- http://Alphaios.net - Tracked Module Music, Blog, and Links. From gert.cuykens at gmail.com Thu Jan 15 20:03:50 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 17:03:50 -0800 (PST) Subject: except sqlite3.Error as e: References: <3260e889-a641-4435-bcef-8f60dfdfda2e@z1g2000yqn.googlegroups.com> Message-ID: <5f2a2479-5f32-44e7-8c73-208fac14263a@13g2000yql.googlegroups.com> On Jan 16, 1:47?am, gert wrote: > except sqlite3.Error as e: > ? ? ERROR = "Error " + ... > > how does except work in python3 ? except sqlite3.Error as e: ERROR = "Error " + e.args[0] oops i thought it did not work somehow in 3.0 but it does :) From dougjrs at gmail.com Thu Jan 15 20:04:58 2009 From: dougjrs at gmail.com (DougJrs) Date: Thu, 15 Jan 2009 17:04:58 -0800 (PST) Subject: Soap Client Message-ID: <5947e87e-7679-4121-98f0-b77b2ae56be4@13g2000yql.googlegroups.com> Good Evening Everyone, I am working to create a Soap client in Python using wsdl2py. So far I have been pretty successful in creating most of the client, but I am having trouble figuring out how to change the content of the message that is being sent. After running wsdl2py I have created this client code: import OnlineQuery_client as QC loc QC.QueryLocator() srv = loc.getOnlineQuerySoap() msg = QC.querySoapIn() rep = srv.query(msg) I would like to change the message that is being sent to something like this (soap headers excluded below, but they would be in the actual message, and the xml would be escaped.) "1". wsdl2py created the code below in OnlineQuery_client.py: "querySoapIn = GED("http://eventquery.org/", "query", "test").pyclass" So, can anyone point me in the right direction as to how I would change the message that is being sent? I have tried a couple of different combinations, but so far I have not been successful in creating the messages that I want. Any help is appreciated, Doug From bignose+hates-spam at benfinney.id.au Thu Jan 15 20:13:18 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 12:13:18 +1100 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87r634aw9d.fsf@benfinney.id.au> Steven D'Aprano writes: > But by focusing on such a small aspect of my post (a quarter of my > text), It clearly was important to you, since you phrased it in highly emotive terms (and even, by your account, had to scale the emotion back a little). So, I don't think the proportion of number-of-characters is relevant there. > while ignoring the more substantial aspects Sure, I took that one part and made a new topic from it. This is open discussion, man. I even changed the subject field to be clear :-) > it seems that you are giving tacit approval of precisely the > attitude I am objecting to: that there is a One True And Correct > Right Way to learn and/or use Python. Nope. -- \ ?Madness is rare in individuals, but in groups, parties, | `\ nations and ages it is the rule.? ?Friedrich Nietzsche | _o__) | Ben Finney From google at mrabarnett.plus.com Thu Jan 15 20:25:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 01:25:39 +0000 Subject: Ordering of urlencoded tuples incorrect In-Reply-To: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: <496FE213.6010005@mrabarnett.plus.com> benlucas99 at googlemail.com wrote: > I'm having problems with the ordering of the tuples produced by > urllib.urlencode. Taking an example straight from the docs and so > doing the following: > > import urllib > ... > params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > print params > > The documentation for urlencode( query[, doseq]) says: "The order of > parameters in the encoded string will match the order of parameter > tuples in the sequence" but I'm getting: > > "eggs=2&bacon=0&spam=1" > > Should this not produce: "spam=1&eggs=2&bacon=0" ? > > I am seeing this "incorrect" result using Python 2.5.1 and > ActivePython 2.3.2 (both on XP SP2). What am I doing wrong? I've > been googling around for an answer but I'm a Python newbie and so > don't know the ropes yet. > You're passing a dict, which is unordered. It will accept a tuple or list of 2-tuples or a dict: >>> # tuple of 2-tuples >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) 'spam=1&eggs=2&bacon=0' >>> >>> # list of 2-tuples >>> urllib.urlencode([('spam', 1), ('eggs', 2), ('bacon', 0)]) 'spam=1&eggs=2&bacon=0' >>> >>> # dict >>> urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) 'eggs=2&bacon=0&spam=1' but I doubt the order will matter in practice. From tjreedy at udel.edu Thu Jan 15 20:28:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 20:28:38 -0500 Subject: Alphametric fun with Python In-Reply-To: References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Raymond Hettinger: >> for simple programs that take minutes to write and get the job done. Thank you for posting this. It illustrates well the point you intended. > For fun here's a specific example: > > from csp import Problem, timing > print "SEND+MORE=MONEY problem:" > p = Problem("recursivebacktracking") > p.addvars("sendmory", range(10)) > p.addrule(lambda d,e,y: (d+e)%10 == y) # alternative syntax > p.addrule("(n*10+d+r*10+e)%100 == e*10+y") This effectively include the first rule and makes it redundant in a way. Better, I expect (but leave to you to check), would be (n*10+d+r*10+e)%100 / 10 == e > p.addrule("(e*100+n*10+d+o*100+r*10+e)%1000 == n*100+e*10+y") (e*100+n*10+d+o*100+r*10+e)%1000 / 100 == n > p.addrule("1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e == 10000*m+1000*o > +100*n+10*e+y") temp = 1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e temp%10000 / 1000 == o temp / 10000 == m > p.notin([0], "sm") > p.alldifferent() > solutions, time = timing(p.solutions) > print "Computing time:", time, "s" > for s in solutions: > print "%(s)d%(e)d%(n)d%(d)d + %(m)d%(o)d%(r)d%(e)d = %(m)d%(o)d%(n) > d%(e)d%(y)d" % s > print Given 'expression == char' for each column, the equalities could be turned into assignments (or checks). For every possible assignment to d and e, let y = (d+e) % 10. For every possible assignment of unused numbers to unbound chars in the second column expression, let e = (n*10+d+r*10+e)%100 / 10 To generalize, 0 pad all lines to match the sum. Then each nested loop can be expressed in more detail as for each possible assignment of unused numbers to unbound chars in column_i: # break if none possible div = 10**i num = column_0_to_i_sum % (10*div) / div if sum[i]_char is not bound: > Probably it's not too much difficult to write a code able to solve a > more general alphametric problem: Hmm. For alphametric problems specifically, 'expression == char' for each column could be turned into assignments (or checks). 0 pad all lines to match the sum. Then nest column loops right to left. for each possible assignment of unused numbers to unbound chars in column_i: # include non-zero constraint and break if none possible div = 10**i num = column_0_to_i_sum % (10*div) / div if sum[i]_char is not bound: bind to num else: check that is num and break if not if last (leftmost) column: print solution else loop on column to left Terry Jan Reedy From ajaksu at gmail.com Thu Jan 15 20:30:25 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 15 Jan 2009 17:30:25 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> Message-ID: <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> On Jan 15, 8:21?pm, mario ruggier wrote: > OK! Here's a small script to make it easier... Thanks! I think I found a quick way around the restrictions (correct me if I borked it), but I think you can block this example by resetting your globals/builtins: exprs = [ '(x for x in range(1)).gi_frame.f_globals.clear()', 'open("where_is_ma_beer.txt", "w").write("Thanks for the fun ")' ] Regards, Daniel From rhodri at wildebst.demon.co.uk Thu Jan 15 20:41:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 16 Jan 2009 01:41:09 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xk58wwlaj.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> <7xk58wwlaj.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 17:07:00 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Luis Zarrabeitia writes: >> No, copy and paste from the original data structures would eliminate >> those >> mismatches. > > The whole point is that would be possible if Python had data structure > definitions ("types") that were possible to copy and paste from some > single location, instead of building up structures dynamically, adding > fields on the fly in ways that have become obscure over the evolution > of the code. mutter mutter __slots__ mutter mutter It strikes me that what you actually want to write is the script that scans your C data structure and spits out a Python class or module that implements it with whatever degree of checking you want. That should make writing your actual data munger safer and faster, if I'm understanding you correctly. -- Rhodri James *-* Wildebeeste Herder to the Masses From sjmachin at lexicon.net Thu Jan 15 20:44:18 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 17:44:18 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: On Jan 16, 11:59?am, benluca... at googlemail.com wrote: > I'm having problems with the ordering of the tuples produced by > urllib.urlencode. ?Taking an example straight from the docs and so > doing the following: What are "the docs" you are reading that include such an example? The docs distributed with Python 2.5.1 from www.python.org have only this: """ urlencode( query[, doseq]) Convert a mapping object or a sequence of two-element tuples to a ``url-encoded'' string, suitable to pass to urlopen() above as the optional data argument. This is useful to pass a dictionary of form fields to a POST request. The resulting string is a series of key=value pairs separated by "&" characters, where both key and value are quoted using quote_plus() above. If the optional parameter doseq is present and evaluates to true, individual key=value pairs are generated for each element of the sequence. When a sequence of two- element tuples is used as the query argument, the first element of each tuple is a key and the second is a value. The order of parameters in the encoded string will match the order of parameter tuples in the sequence. The cgi module provides the functions parse_qs() and parse_qsl() which are used to parse query strings into Python data structures. """ > > ? ? ? ? import urllib > ? ? ? ? ... > ? ? ? ? params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > ? ? ? ? print params > > The documentation for urlencode( query[, doseq]) says: "The order of > parameters in the encoded string will match the order of parameter > tuples in the sequence" but I'm getting: "query" can be either a mapping object (e.g. a dictionary, as you have used) or a sequence of 2-tuples. No such guarantee as you quote above can be made for a mapping; mappings are just not orderable. If you want order, give it a sequence, like this: | >>> import urllib | >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) | 'spam=1&eggs=2&bacon=0' HTH, John From castironpi at gmail.com Thu Jan 15 20:49:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 15 Jan 2009 17:49:36 -0800 (PST) Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> Message-ID: <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> On Jan 15, 6:41?pm, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > >> >> > Familiarize yourself with PEP8 for naming and coding-conventions > >> >> > first. > > >> >> Enough of the PEP8-fascism please. It is not compulsory to follow > >> >> PEP8 in order to be allowed to learn Python. > > >> > You are responding to something in Diez's message that I can't see. > >> > Nowhere does he say anything about PEP 8 being compulsory. Quite the > >> > contrary, he suggests gaining *familiarity* with PEP 8, and calls it > >> > a set of *conventions*. > > >> He doesn't *suggest* anything. He uses the imperative case -- it's a > >> command. > > > Regardless, even if it was an imperial order with government backing, > > the instruction was not to *follow* PEP 8, but to *become familiar with* > > it. That isn't fascism, and to read that into it and assume a > > commandment that Diez didn't make is overreaction on your part. > > Okay, fair enough, I made a mistake in saying "It is not compulsory to > follow PEP8". What I should have said was "It is not compulsory to become > familiar with PEP8". People are sensitive in differing amounts to the imperative case. I'm really sensitive to it, and I appreciate it when people say *plonk* instead of *lonk*. Diez took an authoritarian posture with the imperative. Instead of saying what benefit the OP would get from complying, the subtext in such cases is, "I'm in charge. If you haven't heard of me, get out. Do what I say, or get out." That might be extreme, but you'd be hard pressed to defend an interpretation of what he said to be, "One good option is to skim PEP 8 early. It has a low-maintenance, long-term benefit." It's much more common to use an imperative in a chain of command, as in "Swab the deck", or "Convert the heathens", where a task is critical to a collective mission, or, regrettably, in reminding people who has the gun, such as in an enforced hierarchy. There is no chain of command or gun in the Python community (that I've found), at least outside of the core devs, which I can't attest to. IMO, it's most likely Diez was performing a hazing ritual on a newcomer, that he'd forgotten he didn't like when he did it. > Now that you've put me in my place, can we please get back to becoming a > hostile and unforgiving place for newbies who dare to try learning Python > without first becoming familiar with PEP8? Let us compose odes and sonnets to its glory. (Imperative.) > *wink* > > Seriously, I'll accept a small rebuke. My choice of the word "fascism" > was poor, and I regret it. In my defense, I thought it was better than my > initial thought, which was "style-Nazi", but in hindsight given the > proliferation of somewhat tongue-in-cheek foo-Nazi terms (soup-Nazi, > grammar-Nazi, fashion-Nazi, etc.) maybe I should have stuck with it. You could probably stick with 'style police', as in 'fashion police', as in, "Don't worry about Diez, he's the self-appointed style police". Sorry, heard it on t.v. once. > But by focusing on such a small aspect of my post (a quarter of my text), > while ignoring the more substantial aspects, it seems that you are giving > tacit approval of precisely the attitude I am objecting to: that there is > a One True And Correct Right Way to learn and/or use Python. Not only is there One True And Correct Right Way(tm), but I'm the only one who knows what it is. > For a community that celebrates the dynamism of the language, and > supports giving the programmer the ability to shoot themselves in the > foot ("we're all adults here") For what definition of 'here'? > we can sometimes be remarkably intolerant > of things which are a matter of taste. -- Your code tastes funny. -- Stop chewing it and swallow. (Imperative.) > Sometimes it seems that there's a > Party line, and individuals can be criticized for failing to be > enthusiastic enough about supporting it. This is a good example: it isn't > enough that I agreed with Diez's substantial point that PEP8 is a good > thing; it isn't enough that I made it more likely that the OP would find > and read PEP8 by posting a link to it; but by making a mild criticism of > *the way* Diez introduced PEP8 to the newbie, *I'm* the bad guy. I think you're ignoring the diversity of backgrounds that people from around the world can have. Maybe in Diez's past lives, friends just roughhouse and show acceptance and affection by using imperatives. Maybe it is a bellowed 'WELCOME!', instead of an unchecked power bid. > Steven Ever find it hard to get personal with a newsgroup? A. Brady P.S. Not that questions are any better. From rhodri at wildebst.demon.co.uk Thu Jan 15 20:55:19 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 16 Jan 2009 01:55:19 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjkwkze.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 17:13:41 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Roy Smith writes: >> C is not evil. It's a tool. Would you call a hammer evil because it's >> not >> very good at driving screws? > > I would call a hammer evil if it were built in a way that made it > unnecessarily likely to hit your thumb. But is that because the hammer is misdesigned, because you're holding the nail all wrong, or because you're actually holding a screw? >> C is a very good tool for doing the kind of thing it was designed >> for, which is highly efficient, low-level, portable programming. Um. It wasn't designed for portability, or if it was, it wasn't designed for portability very well. Then again, what makes for good portability at the level C works best at -- macroassembly -- is not an easy question to answer given how variable your environment can be. >> The fact that C has been used to write all sorts of large-scale >> applications doesn't mean that it's good at that kind of stuff. It just >> means that all the alternatives suck more than it does for that kind of >> stuff. > > I don't think so: http://www.adaic.org/whyada/ada-vs-c/cada_art.html I agree. I suspect that its more the case that once most programmers have been taught how to use the hammer that is C, all problems look like nails. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhamph at gmail.com Thu Jan 15 21:01:25 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 15 Jan 2009 18:01:25 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <6210055d-b6f8-488a-aa0d-8d76ea79bc62@g38g2000yqd.googlegroups.com> On Jan 14, 3:14?pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The real problem is it would be misleading. isinstance(a, myset) suggests implementation like type(a) in myset, but it's really any (isinstance(a, t) for t in myset). If myset is arbitrarily large (as the examples suggest), and you're checking on every call, the code would be so slow as to be considered broken. This invalidates the use case. The abc module in 2.6/3.0 is a possible alternative. Create an ABC type, register each type in myset as part of it, then do isinstance(a, MyABC). Internally the ABC will cache lookups, effectively getting you back to O(1) cost. From ambient.sounds at gmail.com Thu Jan 15 21:42:37 2009 From: ambient.sounds at gmail.com (Mark Hahnenberg) Date: Thu, 15 Jan 2009 18:42:37 -0800 (PST) Subject: Lazy List Generator Problem Message-ID: <8ce100f6-ca7d-4de3-8965-56ba042cedf8@w34g2000yqm.googlegroups.com> I'm trying to make a lazy, (theoretically) infinite prime number sieve using generators. The code I have thus far is: #!/usr/bin/env python import itertools def sieve(): nats = naturals(2) while True: elem = nats.next() yield elem nats = itertools.ifilterfalse(lambda x: x % elem == 0, nats) def naturals(start=1): curr = start while True: yield curr curr += 1 primes = sieve() i = 0 while i < 10: print primes.next() i += 1 When I execute this code, the numbers 2,3,4,...,11 are printed (i.e. nothing gets filtered out). Could anyone explain why this is happening? I generally understand generators, and my hypothesis is that reassigning to nats the result of filtering nats could be screwing things up somehow, but I've tried a variety of other methods, from making copies of the old iterator to rolling my own filter function and nothing has worked. Thanks, -MRH From mdw at distorted.org.uk Thu Jan 15 21:50:23 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 16 Jan 2009 02:50:23 +0000 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> <7bd6ef74-8608-489b-bea5-dd243bf0c803@x38g2000yqj.googlegroups.com> Message-ID: <87k58wotg0.fsf.mdw@metalzone.distorted.org.uk> mario ruggier writes: > 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' > object has no attribute 'func_globals': File "", line 1, in > Damn. So that doesn't work. :-( > But even if inspect did have the func_globals attribute, the "open" > builtin will not be found on __builtins__ (that is cleaned out when > restricted=True). Irrelevant. I wasn't trying to get at my __builtins__ but the one attached to a function I was passed in, which has a different environment. You define a function (a method, actually, but it matters little). The function's globals dictionary is attached as an attribute. You didn't do anything special here, so the globals have the standard __builtins__ binding. It contains open. You now run my code in a funny environment with a stripped-down __builtins__. But that doesn't matter, because my environment contains your function. And that function has your __builtins__ hanging off the side of it. ... but I can't actually get there because of f_restricted. You don't mention the fact that Python magically limits access to these attributes if __builtins__ doesn't match the usual one, so I think you got lucky. -- [mdw] From tim--at-- at frontier--dot--.net Thu Jan 15 21:59:23 2009 From: tim--at-- at frontier--dot--.net (Tim H) Date: Thu, 15 Jan 2009 19:59:23 -0700 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: r wrote: > On Jan 14, 4:43 pm, Terry Reedy wrote: > [snip] >> I think the 'main' IDLE maintainer is no longer active. I think someone >> who would do more than fix critical bugs might be welcome. > > Hello Terry, > That's what i was beginning to think. I am not quite ready (as far as > my skills are concerned) to put out something that would be as useful > to many people. I could hack together something real quick for myself. > This is why i am looking for like-minded people who would be > interested in this. I have the foresight and willpower at this point > to contribute something meaningful to the Python community -- to give > back. > > OFF-TOPIC:(but related) > What is the state of Tkinter at this point. Is an active effort under > way to port TK 8.5 into Python? Tkinter and IDLE are very important to > Python, but i understand there are much more important areas where the > GURU's are concentrating. Should there be a calling for "others" to > get involved here? I would like to help out. > Thanks Maybe I'm misunderstanding something here, but "About Idle" in Python 2.6.1 (win32) says "Tk version: 8.5" From ptmcg at austin.rr.com Thu Jan 15 22:01:43 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 15 Jan 2009 19:01:43 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: On Jan 15, 5:31?pm, Per Freem wrote: > ...the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions. ?so in that case, > doing a Try-Except on aKey should be very efficient, since often it > will not fail, ... Do you know the aKeys in advance? If so, then just initialize the first layer, and it will never fail. -- Paul From skip at pobox.com Thu Jan 15 22:30:34 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 15 Jan 2009 21:30:34 -0600 Subject: spam on the list - how are things now? Message-ID: <18799.65370.92932.642056@montanaro.dyndns.org> We've been running SpamBayes on the news-to-mail gateway on mail.python.org for a couple weeks now. To me it seems like the level of spam leaking onto the list has dropped way down but I'd like some feedback from people who read the python-list at python.org mailing list on the topic. Thanks, -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From prologic at shortcircuit.net.au Thu Jan 15 22:37:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 13:37:06 +1000 Subject: process/thread instances and attributes In-Reply-To: References: <496F03B9.8090100@shopzeus.com> Message-ID: After some work ... I've taken Laszlo's suggestion of using Value (shared memory) objects to share state between the -pseudo- Process (manager) object and it's underlying multiprocessing.Process instance (and subsequent process): Here is the code: ---------------------------------------- #!/usr/bin/env python import os from time import sleep from threading import activeCount as threads from threading import Thread as _Thread from multiprocessing import Value from multiprocessing import Process as _Process from multiprocessing import active_children as processes class Process(object): def __init__(self, *args, **kwargs): super(Process, self).__init__(*args, **kwargs) self.running = Value("b", False) self.thread = _Thread(target=self.run) self.process = _Process(target=self._run, args=(self.running,)) def _run(self, running): self.thread.start() try: while running.value: try: sleep(1) print "!" except SystemExit: running.acquire() running.value = False running.release() break except KeyboardInterrupt: running.acquire() running.value = False running.release() break finally: running.acquire() running.value = False running.release() self.thread.join() def start(self): self.running.acquire() self.running.value = True self.running.release() self.process.start() def run(self): pass def stop(self): print "%s: Stopping ..." % self self.running.acquire() self.running.value = False self.running.release() def isAlive(self): return self.running.value class A(Process): def run(self): while self.isAlive(): sleep(5) self.stop() a = A() a.start() N = 0 while a.isAlive(): sleep(1) print "." print "threads: %d" % threads() print "processes: %d" % len(processes()) print "DONE" ---------------------------------------- Here is the result of running this: ---------------------------------------- $ python test3.py ! . threads: 1 processes: 1 . threads: 1 processes: 1 ! ! . threads: 1 processes: 1 . threads: 1 processes: 1 ! . threads: 1 processes: 1 ! <__main__.A object at 0x80de42c>: Stopping ... ! . threads: 1 processes: 0 DONE ---------------------------------------- This appears to work as I intended. Thoughts / Comments ? cheers James From prologic at shortcircuit.net.au Thu Jan 15 22:39:39 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 13:39:39 +1000 Subject: spam on the list - how are things now? In-Reply-To: <18799.65370.92932.642056@montanaro.dyndns.org> References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: On Fri, Jan 16, 2009 at 1:30 PM, wrote: > We've been running SpamBayes on the news-to-mail gateway on mail.python.org > for a couple weeks now. To me it seems like the level of spam leaking onto > the list has dropped way down but I'd like some feedback from people who > read the python-list at python.org mailing list on the topic. Agreed. It has gone down. Thank you for taking the time to do something about it :) cheers James From waynehuang.public at gmail.com Thu Jan 15 22:56:23 2009 From: waynehuang.public at gmail.com (Wayne Huang) Date: Fri, 16 Jan 2009 11:56:23 +0800 Subject: One Bug of Python 3.0 Message-ID: I met a bug of CGIXMLRPCRequestHandler in Python3.0. Because of the bug, I couldn't use RPC in Apache CGI. The version of my Python 3.0 is "Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] win32". The code of my client is follow. s = xmlrpc.client.ServerProxy('http://localhost/cgi-bin/rpc.py') print(s.system.listMethods()) The code of my server in Apache's cgi-bin is follow #!C:/Python30/python.exe from xmlrpc.server import * handler=CGIXMLRPCRequestHandler() handler.register_introspection_functions() handler.handle_request() When I run the client code,some error of parser raise. I found it is the matter of 'Content-Length' in the HTTP Response of CGIXMLRPCRequestHandler,it is a wrong number. I don't know how to handle the problem. Wait for your help. Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From cma at mail.bnu.edu.cn Thu Jan 15 22:59:29 2009 From: cma at mail.bnu.edu.cn (Cong Ma) Date: Fri, 16 Jan 2009 11:59:29 +0800 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Terry Reedy wrote: > Not to me. You are using the module as a singleton class. The > alternative is to write a class, make the functions methods, and > instantiate the class. If that instance must be a singleton, more work > is required. If multiple instances make sense, you can go the class > route when you need to. I've thought of this too, but it turns out those functions are related to each other very loosely. They do a lot of completely different things independently and have just one common global variable to share. IMHO it would reduce the readability of code because the role of this class is very unclear. Anyway, "readability" is mostly a subjective matter and I think what you pointed out is a good idea in general. >> For example: >> >> @global_injected("SPAM") >> def foo(): >> ... ... >> >> will have the same effect as >> >> def foo(): >> global SPAM >> ... ... > > More keystrokes for no gain. That's intended. I want these "evil" (or "foolish and senseless") functions to "stand out" in the sourcecode. They have their evil marks right before the definition, not buried in the function body. > Decorators are usally intended to wrap the input function with another > function. But they can be used to modify the input function and return > it altered. The latter is what you are proposing. > > You of course have to use SPAM as a local variable. Then you might be > able to write an implementation-specific convert_to_global(name) > function that would rewrite the code part of the code object of the > function to what it would have been had you been sensible and used the > 'global' directive. This would mean finding the code that loads and > stores 'SPAM' as a local variable and convert is to code that loads and > stores it as a global variable. If the replacement takes more bytes > than the original, then the jump offsets all have to be fixed. Also > needing fixing would be the line number table that is used to match code > units to lines in the Python code for error tracebacks. > > An alterntive would be to de-compile the code, insert the global > directive, and recompile. A non-decorator alternative would be to write > a function with two parameters that takes a tuple of names and the code > quoted as a string as arguments. It would insert the global statement > into the string, execute it, and return the function. Thank you for your elaborate explanation :) Regards, Cong. From prologic at shortcircuit.net.au Thu Jan 15 23:08:19 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 14:08:19 +1000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 4:28 AM, Cong Ma wrote: > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. For > example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... > > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). I'd like to hear your opinions. Thank you. This is identical behavior to that of a class/object. Please explain why you _really_ need to do this ? class Foo(object): def __init__(self): self.spam = None def foo(self): self.spam = "Eggs" def bar(self): self.spam = "Bacon" cheers James From prologic at shortcircuit.net.au Thu Jan 15 23:13:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 14:13:05 +1000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 1:59 PM, Cong Ma wrote: > I've thought of this too, but it turns out those functions are related to each > other very loosely. They do a lot of completely different things independently > and have just one common global variable to share. IMHO it would reduce the > readability of code because the role of this class is very unclear. Anyway, > "readability" is mostly a subjective matter and I think what you pointed out is > a good idea in general. So then the other commonly used pattern is a shared object between two other objects. class Env(object): def __init__(self): self.spam = None class A(object): def __init__(self, env): self.env = env def __call__(self): self.env.spam = "Eggs" class B(object): def __init__(self, env): self.env = env def __call__(self): self.env.spam = "Bacon" Very readable and makes perfect sense if it suits you. cheers James From wuwei23 at gmail.com Thu Jan 15 23:42:35 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 15 Jan 2009 20:42:35 -0800 (PST) Subject: Lazy List Generator Problem References: <8ce100f6-ca7d-4de3-8965-56ba042cedf8@w34g2000yqm.googlegroups.com> Message-ID: On Jan 16, 12:42?pm, Mark Hahnenberg wrote: > When I execute this code, the numbers 2,3,4,...,11 are printed (i.e. > nothing gets filtered out). ?Could anyone explain why this is > happening? ?I generally understand generators, and my hypothesis is > that reassigning to nats the result of filtering nats could be > screwing things up somehow, but I've tried a variety of other methods, > from making copies of the old iterator to rolling my own filter > function and nothing has worked. Hey Mark, I think the issue isn't that 'nats' is changing, but that 'elem' is. Try replacing this: > nats = itertools.ifilterfalse(lambda x: x % elem == 0, nats) with this: nats = itertools.ifilterfalse(lambda x, elem=elem: x % elem == 0, nats) Which works for me: In [91]: s = sieve() In [92]: primes_10 = [s.next() for x in xrange(10)] In [93]: primes_10 Out[93]: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Hope this helps. From http Thu Jan 15 23:43:25 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:43:25 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <7xmydsw7rj.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhrg8sy.fsf@ruckus.brouhaha.com> Terry Reedy writes: > > Right. And if the file is large enough that even parsing all the > > records to check the fields takes hours, well, that's where I'm at. > > So what is the problem? Let it run overnight. The idea of buying faster and faster computers is to not have to wait overnight. The sooner you can get the results (preferably within minutes not hours), the sooner they can be used in the next task, which depends on them. Language implementation affects program speed just as hardware does, thus the grumbling about Python being slow. > If you want more > speed, try numpy or Cython or C functions (swigged or ctyped) or... I should try out Cython. Using plain C would slow down development an awful lot. Either way would require putting most of the logic in C to get the best speedup, since it would require building Python-unfriendly data structures (the natural Pythonic structures use a huge amount of dict lookups and storage allocation/release). > for line in open('humongous.dat', 'r'): > try: > > > except Exception as e: > print(line, e) > > (How trivial in Python!) It's a little more complicated than that since multiple threads are involved, and "except Exception" is considered an antipattern, but yeah, I'm already doing stuff like this. From http Thu Jan 15 23:44:08 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:44:08 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> <7xk58wwlaj.fsf@ruckus.brouhaha.com> Message-ID: <7xvdsfg8rr.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > It strikes me that what you actually want to write is the script that > scans your C data structure There is not a C data structure at the moment. It's all Python. From http Thu Jan 15 23:46:16 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:46:16 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> Message-ID: <7xr633g8o7.fsf@ruckus.brouhaha.com> gert writes: > s = urandom(10).encode('hex') > AttributeError: 'bytes' object has no attribute 'encode' Oh, Python 3. It's done some different way, someone else will have to specify. I'm still using 2.x. From http Thu Jan 15 23:47:07 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:47:07 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <9ed5092f-0242-4b50-b23e-11384ba265d2@f20g2000yqg.googlegroups.com> Message-ID: <7xmydrg8ms.fsf@ruckus.brouhaha.com> gert writes: > s = sha1(bytes(random(),'utf-8')).hexdigest() > i found this, looks let say strange. But it works :) Be careful, if you're relying on the uniqueness and unpredictability of this number for program security, that random() isn't designed for such purposes. Use os.urandom instead. From michele.simionato at gmail.com Thu Jan 15 23:48:35 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 15 Jan 2009 20:48:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: On Jan 15, 8:02?am, Paul Rubin wrote: > I'd say there was a time Lisp worked the right way, and a time C > worked the right way, and maybe a time Python worked the right way, > and for a while, Algol 60 was perfection embodied. ?But times have > changed more than those languages have, so they no longer work the > right way. Or perhaps it is you who changed? I can only speak for myself, but when I first met Python (coming from Basic, Pascal, Fortran, Mathematica, Maple) it was the best language I could imagine. Now Python is still the best language I can find, but it is no more the best I can imagine, because I know much more about programming than before. But I would say that's normal and even healthy. The best language is the one yet to be invented! > Have you looked at Tim Sweeney's talk that I mentioned in another post? > > http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... I will have a look now. From http Fri Jan 16 00:03:03 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:03:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjjg7w8.fsf@ruckus.brouhaha.com> Michele Simionato writes: > Or perhaps it is you who changed? I can only speak for myself, but > when I first met Python (coming from Basic, Pascal, Fortran, > Mathematica, Maple) it was the best language I could imagine. I would say Algol 60 and Lisp were great languages the same way the Burroughs B5500 or Dec PDP-10 were great computers. Today, though, We would only describe their greatness in historical terms, since technology has advanced so much and we know better ways to do things now. All the languages were are using now, it seems to me, are pretty far behind what PL researchers are working on. But the stuff the researchers are doing isn't that immediately useful to us, since they're concentrating on academic results and aren't really in the practicality business. The gap between research and practice narrows and widens over the general ebb and flow of advancing technology, and I think it is wider than usual right now. An exception to that might be Haskell, which makes Python feel almost juvenile, but (despite the amazing work that its aficionados are doing) it lacks somewhat in practicality, in my opinion. > Now Python is still the best language I can find, but it is no more > the best I can imagine, because I know much more about programming > than before. But I would say that's normal and even healthy. > The best language is the one yet to be invented! Right. I think we are heading into a period of consolidation, where the stuff currently in the ivory towers makes it into the hands of day to day practictioners. From prologic at shortcircuit.net.au Fri Jan 16 00:04:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:04:33 +1000 Subject: s = sha1(random()).hexdigest() In-Reply-To: <7xr633g8o7.fsf@ruckus.brouhaha.com> References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <7xr633g8o7.fsf@ruckus.brouhaha.com> Message-ID: On Fri, Jan 16, 2009 at 2:46 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > gert writes: >> s = urandom(10).encode('hex') >> AttributeError: 'bytes' object has no attribute 'encode' > > Oh, Python 3. It's done some different way, someone else will have to > specify. I'm still using 2.x. >>> "".join([hex(c) for c in os.urandom(10)]) '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' >>> From berankin99 at yahoo.com Fri Jan 16 00:07:07 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Thu, 15 Jan 2009 21:07:07 -0800 (PST) Subject: Library for extracting new content from email reply messages? Message-ID: <656168.46200.qm@web112208.mail.gq1.yahoo.com> Hello, I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed....) Is there a Python email parsing library that can assist in extracting new content from messages that have been sent in reply? That is, since many users will just hit the email client's reply button to communicate with the system, I need some way to filter out the quoted "original message". Certainly, 100% accuracy can't be had, since there are so many email programs out there, but we could as least handle the very popular ones. Thank you, :) From ianand0204 at gmail.com Fri Jan 16 00:09:43 2009 From: ianand0204 at gmail.com (flagg) Date: Thu, 15 Jan 2009 21:09:43 -0800 (PST) Subject: Beginner: Data type conversion question Message-ID: I am still fairly new to python and programming in general. My question is regarding data conversion, I am working on a script that will edit dns zone files, one of the functions i wrote handles updating the serial number. Our zone files use the date as the first part of the serial and a two digit integer as the last two. i.e. 2009011501. The next update would be 2009011502, etc Here is the function I wrote, I am using dnspython for reading in zone files as Zone "objects". Because dnspython's built-in serial updater will not work with how we format our serial's, I have to re-write it. def checkSerial(): """ Checks the current 'date' portion of the serial number and checks the current 'counter'(the two digit number at the end of the serial number), then returns a complete new serial """ currentDate = time.strftime("%Y""%m""%d", time.localtime()) for (name, ttl, rdata) in zone.iterate_rdatas(SOA): date = str(rdata.serial)[0:8] inc = str(rdata.serial)[8:10] if date == currentDate: int(inc) + 1 print inc newInc = str(inc).zfill(2) serial = date + newInc print "date is the same" return serial elif date < currentDate: newInc = "01".zfill(2) serial = currentDate + newInc print "date is different" return serial Through all of this I am doing a lot of data type conversion. string - > integer, integer back to string, etc. Is this an efficient way of handling this? I have to perform basic addition on the "inc" variable, but also need to expose that value as a string. What I have above does work, but I can't help but think there is a more efficient way. I guess I am not used to data types being converted so easily. From http Fri Jan 16 00:12:19 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:12:19 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <7xr633g8o7.fsf@ruckus.brouhaha.com> Message-ID: <7x3afjg7gs.fsf@ruckus.brouhaha.com> "James Mills" writes: > >>> "".join([hex(c) for c in os.urandom(10)]) > '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' That doesn't look so good, because of all the 0x. From clp2 at rebertia.com Fri Jan 16 00:16:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 21:16:10 -0800 Subject: Beginner: Data type conversion question In-Reply-To: References: Message-ID: <50697b2c0901152116ga1e8fd0o5b25fc2742f3ae2@mail.gmail.com> On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > I am still fairly new to python and programming in general. My > question is regarding data conversion, I am working on a script that > will edit dns zone files, one of the functions i wrote handles > updating the serial number. > Our zone files use the date as the first part of the serial and a two > digit integer as the last two. > > i.e. 2009011501. The next update would be 2009011502, etc > Here is the function I wrote, I am using dnspython for reading in zone > files as Zone "objects". Because dnspython's built-in serial updater > will not work with how we format our serial's, I have to re-write it. > > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and > checks the current 'counter'(the two digit number at the end of > the serial number), then returns a complete new serial > """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] > if date == currentDate: > int(inc) + 1 The previous line is pointless. It's like having '4+4' as a statement on its own line. It calculates a value but doesn't change any state or even use the value. Perhaps you instead meant?: inc = int(inc) + 1 Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Bruce.Axtens at gmail.com Fri Jan 16 00:17:32 2009 From: Bruce.Axtens at gmail.com (axtens) Date: Thu, 15 Jan 2009 21:17:32 -0800 (PST) Subject: vb2py status? Message-ID: G'day everyone So is vb2py dead? If not, any idea when it'll support python 3? Kind regards, Bruce. From wuwei23 at gmail.com Fri Jan 16 00:25:24 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 15 Jan 2009 21:25:24 -0800 (PST) Subject: vb2py status? References: Message-ID: <45529ea5-9219-45dc-a7ec-cd5b32ce3160@n33g2000pri.googlegroups.com> On Jan 16, 3:17?pm, axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? You're always better off asking at the project site than here, but given it hasn't been updated since Feb 2004 I think it's safe to say the project is dead. But it *is* open source, so feel free to pick it up and run with it if it fills a need for you ;) From ianand0204 at gmail.com Fri Jan 16 00:29:19 2009 From: ianand0204 at gmail.com (flagg) Date: Thu, 15 Jan 2009 21:29:19 -0800 (PST) Subject: Beginner: Data type conversion question References: Message-ID: <207f6bb9-4fa1-41f0-860b-b7804345de38@e1g2000pra.googlegroups.com> On Jan 15, 9:16?pm, Chris Rebert wrote: > On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > > I am still fairly new to python and programming in general. ?My > > question is regarding data conversion, I am working on a script that > > will edit dns zone files, one of the functions i wrote handles > > updating the serial number. > > Our zone files use the date as the first part of the serial and a two > > digit integer as the last two. > > > i.e. 2009011501. ?The next update would be 2009011502, etc > > Here is the function I wrote, I am using dnspython for reading in zone > > files as Zone "objects". ?Because dnspython's built-in serial updater > > will not work with how we format our serial's, I have to re-write it. > > > def checkSerial(): > > ? ?""" > > ? ?Checks the current 'date' portion of the serial number and > > ? ?checks the current 'counter'(the two digit number at the end of > > ? ?the serial number), then returns a complete new serial > > ? ?""" > > ? ?currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > ? ?for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ?date = str(rdata.serial)[0:8] > > ? ? ? ?inc = str(rdata.serial)[8:10] > > ? ?if date == currentDate: > > ? ? ? ?int(inc) + 1 > > The previous line is pointless. It's like having '4+4' as a statement > on its own line. It calculates a value but doesn't change any state or > even use the value. Perhaps you instead meant?: > ? ? ? ? ? ? inc = int(inc) + 1 > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Ah thank you. Oversight on my part. That explains why that if statement never incremented the counter correctly. Anything odd about how I'm converting back and forth between different data types as often as I am? Is that common practice is normal programming? (forgive the beginner questions) From gopalm at infotechsw.com Fri Jan 16 00:35:44 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Fri, 16 Jan 2009 11:05:44 +0530 Subject: problem in implementing multiprocessing Message-ID: <89E5181815F74966B59B475F9B4ED600@pwit.com> Hello, I am trying to implement the multiprocessing in my application to take advantage of multiple cores. I have created two Separate process something like this. que = Queue Process(target = getData, args=(que , section, MdbFile,)).start() Process(target = getData, args=(que , section, MdbFile,)).start() In getData function I create the object(max 7MB size) and add in to queue (que.put (object)). After that I fetch the object using que.get () and use in my application. but it takes more time to get the data. Any one can help me out this problem. Thanks, Sibtey My code<<<<< from multiprocessing import Process, Queue def getData(queue, section, mdbFile): """ This function returns the gapappdata for the given mdb file. """ app = MdbFile(mdbFile) mdbData = app.data#it is a heavy object queue.put((section,mdbData)) def getData2(mdbFile): """ This function returns the gapappdata for the given mdb file. """ app = MdbFile(mdbFile) mdbData = app.data#it is a heavy object return mdbData def test_multipleProcess(fromMdbFile, toMdbFile): #multipleProcess t1 = time.time() queue = Queue() sections = ['From', 'To'] Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() section, gapAppData = queue.get() section, gapAppData = queue.get() t2 = time.time() print "total time using multiProcessing:",t2-t1 d1 = getData2(fromMdbFile) d2 = getData2(toMdbFile) print "total time withought multiProcessing:", time.time()-t2 if __name__=='__main__': f1 =r" a.mdb" f2 =r"b.mdb" test_multipleProcess(f1,f2) From prologic at shortcircuit.net.au Fri Jan 16 00:40:42 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:40:42 +1000 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: On Fri, Jan 16, 2009 at 11:02 AM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> >>>> List files from "some_dir". > foo > bar > etc > > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^ You are mad :) --JamesMills From clp2 at rebertia.com Fri Jan 16 00:42:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 21:42:17 -0800 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <50697b2c0901152142x71d8be4fpd4602dd7f6f57dd2@mail.gmail.com> On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> >>>> List files from "some_dir". > foo > bar > etc Does the name "AppleScript" mean anything to you? ;-) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From http Fri Jan 16 00:43:45 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:43:45 -0800 Subject: English-like Python References: Message-ID: <7x3afjolf2.fsf@ruckus.brouhaha.com> The Music Guy writes: > ...might be translated as... > >>> Import the operating system module. http://coboloncogs.org From prologic at shortcircuit.net.au Fri Jan 16 00:52:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:52:53 +1000 Subject: multiprocessing vs. distributed processing Message-ID: I've noticed over the past few weeks lots of questions asked about multi-processing (including myself). For those of you new to multi-processing, perhaps this thread may help you. Some things I want to start off with to point out are: "multiprocessing will not always help you get things done faster." "be aware of I/O bound applications vs. CPU bound" "multiple CPUs (cores) can compute multiple concurrent expressions - not read 2 files concurrently" "in some cases, you may be after distributed processing rather than multi or parallel processing" cheers James -- -- "Problems are solved by method" From martin at v.loewis.de Fri Jan 16 01:08:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 16 Jan 2009 07:08:39 +0100 Subject: s = sha1(random()).hexdigest() In-Reply-To: <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> Message-ID: <49702467$0$22823$9b622d9e@news.freenet.de> > s = urandom(10).encode('hex') > > AttributeError: 'bytes' object has no attribute 'encode' py> binascii.hexlify(os.urandom(10)) b'92b91d5734a9fe562f23' Regards, Martin From koranthala at gmail.com Fri Jan 16 01:13:06 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 15 Jan 2009 22:13:06 -0800 (PST) Subject: Python Style Guide Questions Message-ID: Hi, Which is more advisable? import x b = x.a or from x import a b = a I read in Learning Python that it is always better to use the former - especially since namespace wont be dirtied. But, doing that with PEP 8 together causes my code to look rather cluttered. Reason being that - PEP 8 suggests that have max line length = 79 chars. So my code mostly looks like this: class x: def y(): try: if test: obj.filename = str(os.path.basename (obj1.find_next_element().\ get_file_path())) obj.modify_time = obj.filename.find_created_time() + \ datetime.timedelta (seconds=time.find_time()) etc .. etc.. Almost every line requires the '\'. Also, especially since Python also uses whitespace as indentation, I keep confusing the block indentation with the indentation that the '\' causes in the next line. Could you please let me know what you guys usually do in such cases? Is it advisable to go for the from x import a to avoid this clutter? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 01:38:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 06:38:58 GMT Subject: Python Style Guide Questions References: Message-ID: <0180220a$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 22:13:06 -0800, koranthala wrote: > Hi, > Which is more advisable? > import x > b = x.a > or > from x import a > b = a > > I read in Learning Python that it is always better to use the > former Perhaps not "always", but often. > - especially since namespace wont be dirtied. But, doing that > with PEP 8 together causes my code to look rather cluttered. Reason > being that - PEP 8 suggests that have max line length = 79 chars. So my > code mostly looks like this: > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) A few ideas for you: There is rarely enough performance benefit from squashing as much as possible into a single expression to make up for the loss of readability. Use temporary values to aid comprehension and readability. class X: def y(self): try: if test: path = obj1.find_next_element().get_file_path() obj.filename = str(os.path.basename(path)) ctime = obj.filename.find_created_time() offset = datetime.timedelta(seconds=time.find_time()) obj.modify_time = ctime + offset Alternatively, don't nest so much. class X: def _y(self): path = obj1.find_next_element().get_file_path() obj.filename = str(os.path.basename(path)) ctime = obj.filename.find_created_time() offset = datetime.timedelta(seconds=time.find_time()) obj.modify_time = ctime + offset def y(self): try: if test: self._y() Last but not least, Python now does automatic line continuations inside open brackets. You can use this to eliminate many backslashes. class X: def y(self): try: if test: obj.filename = str( os.path.basename( obj1.find_next_element().get_file_path() )) obj.modify_time = \ obj.filename.find_created_time() + \ datetime.timedelta(seconds=time.find_time()) Hope this helps. -- Steven From tangens0-NOSPAM- at -NOSPAM-gmail.com Fri Jan 16 01:42:39 2009 From: tangens0-NOSPAM- at -NOSPAM-gmail.com (Tobias Andersson) Date: Fri, 16 Jan 2009 07:42:39 +0100 Subject: English-like Python In-Reply-To: References: Message-ID: <6taoivFa0390U1@mid.individual.net> The Music Guy skrev: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > Take a look at Inform 7. It's not Python but does something similar to what you are describing: www.inform-fiction.org Check out the examples in the tutorial. Some of them are quite elegant. HTH /TA From Russ.Paielli at gmail.com Fri Jan 16 01:57:12 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 15 Jan 2009 22:57:12 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> Message-ID: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> On Jan 15, 12:21?pm, Bruno Desthuilliers wrote: > Once again, the important point is that there's a *clear* distinction > between interface and implementation, and that you *shouldn't* mess with > implementation. If you "*shouldn't* mess with the implementation", then what is wrong with enforcing that "shouldn't" in the language itself? Why leave to coding standards and company policy what can be encoded right into the language? Why leave to humans (who are known to err) what can be automated relatively easily? Isn't that what computers are for? >But what, some people think programmers are stupid, and > so they hire stupid programmers, so they need b&d languages to protect > stupid programmers from themselves - which just doesn't work, since > *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb > getter/setter pairs for _each and any_ attribute ? Hey, I share your distaste for Java and C++. All those "setters" and "getters" are a kludge. I think Python "properties" are a major step forward here. Just for fun, I checked to see if Scala has properties. Guess what? Not only does it have them, but they are generated automatically for all member data. That's even better than Python properties! > > As I said before, enforced encapsulation may not be appropriate for > > every application, but it is definitely appropriate for some. > > No. It is appropriate for dummy managers hiring dummy programmers. The > project's size and domain have nothing to do with it. Let me try to be very clear here. We are dealing with two separate but related issues. The first is whether data hiding should be added to Python. The second is whether data hiding provides any net benefit in *any* language. As for whether data hiding should be added to Python, I am not arguing one way or the other. I am merely saying that it is worth considering. Whether it can be added without screwing up the language, I don't know. If not, then so be it. That just limits the range of domains where Python is suitable. As for whether data hiding provides a net benefit in any language, it certainly does for large programs and for safety-critical programs. For large, safety-critical systems, it's a no-brainer. I think data hiding can also provide net benefits for medium-size and even smaller programs, but lets just consider large programs, so I can shoot down your argument that data hiding provides no benefit. I like to use the example of the flight software for a large commercial transport aircraft, but many other examples could be given. How about medical systems that control radiation therapy or chemotherapy? How about financial systems that could take away your retirement account in 1.5 milliseconds. Or how about the control software for the strategic nuclear arsenals of the US or Russia? When you consider the sea, air, and land-based components, I'm sure that's one hell of a lot of code! So let's take the airplane example. Boeing and its contractors probably has hundreds of programmers working on millions of lines of code. If they believed you, they would abandon enforced data hiding, and programmers would have much more discretion to screw around with code that they don't work on directly. An FMS programmer could perhaps decide to change the parameters of the engine controls, for example. To prevent that sort of thing from happening, the management could decree that henceforth all "private" variable names will start with an underscore. Problem solved, eh? Wait a minute. You yourself have stated several times that those stupid library developers can never predict what the client will actually need. So some FMS guy named Bruno decides that he knows better than the engine group what a certain engine parameter should be. Or he decides that his code needs to know the value of that parameter, so he just goes ahead and reads it. No harm done, eh? But wait a minute. Half the programmers did the same thing, and now we have a spaghetti mess on our hands. So now management needs to implement a costly, bureaucratic program to find all such accessing of private data and correct it -- before a disaster occurs in flight. So they have meetings and assemble a data-hiding enforcement team that meets twice each week and constantly looks over every programmers shoulder. Wait a minute, wouldn't enforcement of data hiding by the programming language be preferable to a huge bureaucratic program? I sure think so. And thankfully, so does Boeing and anyone else who has a clue about large-scale software production. Now, let's talk about a data access violations in the nuclear missile launch software. Oh, yes, I'm sure the leading underscore convention is more than sufficient! Wake up, dude, and quit spouting bullsh*t! > > Not > > every door needs a lock, but certainly some do. > > You only need locks when you don't trust your neighbours. Yeah, if you live in Nome, Alaska. Also, have you ever heard the expression "locks keep honest people honest"? I spent *way* too much time on that post. I really need to quit spending my time refuting the baloney that passes for wisdom here. From tjreedy at udel.edu Fri Jan 16 02:00:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:00:04 -0500 Subject: Python Style Guide Questions In-Reply-To: References: Message-ID: koranthala wrote: > Hi, > Which is more advisable? > import x > b = x.a > or > from x import a > b = a If I know I want just one thing from x, I tend to use latter. I also like 'import xyzlib as x' > I read in Learning Python that it is always better to use the > former - especially since namespace wont be dirtied. Namespace get cluttered, not dirtied. In any case, either 'x' or 'a' gets added. One new name either way. > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) Use 4 spaces instead of 5 for indents > Almost every line requires the '\'. As Steven said, usually no > Also, especially since Python also > uses whitespace as indentation, I keep confusing the block indentation > with the indentation that the '\' causes in the next line. '\' causes no indentation Beyond that, consider find a style you like. I agree with Stvhen about using 'thought-sized' expressions. tjr From mario.ruggier at gmail.com Fri Jan 16 02:09:51 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 23:09:51 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> Message-ID: <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> On Jan 16, 2:30?am, ajaksu wrote: > On Jan 15, 8:21?pm, mario ruggier wrote: > > > OK! Here's a small script to make it easier... > > Thanks! I think I found a quick way around the restrictions (correct > me if I borked it), but I think you can block this example by > resetting your globals/builtins: > > exprs = [ > ? ? '(x for x in range(1)).gi_frame.f_globals.clear()', > ? ? 'open("where_is_ma_beer.txt", "w").write("Thanks for the fun ?")' > ] Cool, the beer that is ;) Under 2.6... why does python allow the f_globals lookup in this case, but for the previous example for func_globals it does not? If you look at the top of the file test/test_restricted.py, there is: # Attempt at accessing these attrs under restricted execution on an object # that has them should raise a RuntimeError RESTRICTED_ATTRS = [ 'im_class', 'im_func', 'im_self', 'func_code', 'func_defaults', 'func_globals', #'func_name', #'tb_frame', 'tb_next', #'f_back', 'f_builtins', 'f_code', 'f_exc_traceback', 'f_exc_type', #'f_exc_value', 'f_globals', 'f_locals' ] I have not yet finished working this list off to ensure that any lookup of these attrs wherever they occur will be refused, but I guess that would block this kind of lookup out. I should also block any attempt to access any "gi_*" attribute... Laboriously doing all these checks on each expr eval will be very performance heavy, so I hope to be able to limit access to all these more efficiently. Suggestions? Cheers, Mario > Regards, > Daniel From GDoermann at gmail.com Fri Jan 16 02:10:18 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 15 Jan 2009 23:10:18 -0800 (PST) Subject: Client Socket Connection to Java server Message-ID: I am having problems with a socket connection to a Java server. In java I just open the socket, pass the length and then pass the bits across the socket. I created a socket object: import socket class MySocket: def __init__(self, host='localhost', port = 28192, buffsize = 1024): socket.setdefaulttimeout(10) self.host = host self.port = port self.buffsize = buffsize self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((host, port)) def send(self, data): self.socket.send(data) def receive(self): return self.socket.recv(self.buffsize) def sendAndReceive(self, data): self.send(data) return self.receive() def close(self): self.socket.close() But the java server gives the error: WARNING: Message length invalid. Discarding The data is of type string (xml). Am I doing something wrong? I know you have to reverse the bits when communicating from C++ to Java. Could this be the problem? I figured it would not because it said the length was invalid. I just started looking at python sockets tonight... and I don't have a real deep base with socket connections as it is... any help would be greatly appreciated. Greg From mail at anjanesh.net Fri Jan 16 02:16:28 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 16 Jan 2009 12:46:28 +0530 Subject: Py3 - converting bytes to ascii In-Reply-To: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> References: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> Message-ID: <4970344C.4080103@anjanesh.net> The problem seems be solved with urllib.request.urlretrieve() I think the binary information read() was giving had headers like content-size - but not HTTP headers. The first couple of bytes indicate how much content to read and after reading that content, the next set of bytes indicate the next chunk. From tjreedy at udel.edu Fri Jan 16 02:20:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:20:25 -0500 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> List files from "some_dir". > foo > bar > etc > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^. Others have mentioned some examples in this direction. Some problems: English is not a context free language; a constrained context-free subset is needed for algorithmic parsing. Should Pynglish change 'a' to 'an' before vowels? 'Define new function "list files"' is good English too. In your example, you changed '"a path"' to 'the given path'. This will not parse very easily. Etc. Writing within such a subset is likely to be more difficult than writing in Python. It would be easier to slip up and less easy to notice an error. (Of course, some think Python is too wordy. I think is strikes a fair balance.) It would also soon get tedious. It would also be more tedious to read. There is a reason math shifted from 'plain Greek' to the use of symbols. While Python uses names derived from English, it is used internationally. Pynglish would be harder for non-native-English speakers to learn. I think random indentifiers in non-Latin alphabets would be more grating in Pynglish sentences than in Python statements. def #&*#&*$(#%,#^): # versus Define a new function #&*#&*$ which accepts #% and #^ One could disagree though. Terry Jan Reedy From tjreedy at udel.edu Fri Jan 16 02:23:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:23:32 -0500 Subject: problem in implementing multiprocessing In-Reply-To: <89E5181815F74966B59B475F9B4ED600@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> Message-ID: gopal mishra wrote: > Hello, > > I am trying to implement the multiprocessing in my application to take > advantage of multiple cores. I have created two > > Separate process something like this. > > que = Queue > Process(target = getData, args=(que , section, MdbFile,)).start() > Process(target = getData, args=(que , section, MdbFile,)).start() > > In getData function I create the object(max 7MB size) and add in to queue > (que.put (object)). > > After that I fetch the object using que.get () and use in my application. > but it takes more time to get the data. More time than what? Than not getting the date? Than getting it some other way? CPU, OS, and Python version may also be relevant. > Any one can help me out this problem. > > Thanks, > Sibtey > > My code<<<<< > from multiprocessing import Process, Queue > > def getData(queue, section, mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > queue.put((section,mdbData)) > > def getData2(mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > return mdbData > > def test_multipleProcess(fromMdbFile, toMdbFile): > #multipleProcess > t1 = time.time() > queue = Queue() > sections = ['From', 'To'] > Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() > Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() > section, gapAppData = queue.get() > section, gapAppData = queue.get() > t2 = time.time() > print "total time using multiProcessing:",t2-t1 > d1 = getData2(fromMdbFile) > d2 = getData2(toMdbFile) > print "total time withought multiProcessing:", time.time()-t2 > > > > > > if __name__=='__main__': > f1 =r" a.mdb" > f2 =r"b.mdb" > test_multipleProcess(f1,f2) > > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Fri Jan 16 02:26:26 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:26:26 -0500 Subject: Library for extracting new content from email reply messages? In-Reply-To: <656168.46200.qm@web112208.mail.gq1.yahoo.com> References: <656168.46200.qm@web112208.mail.gq1.yahoo.com> Message-ID: Bernard Rankin wrote: > Hello, > > I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed....) > > Is there a Python email parsing library that can assist in extracting new content from messages that have been sent in reply? > > That is, since many users will just hit the email client's reply button to communicate with the system, I need some way to filter out the quoted "original message". > > Certainly, 100% accuracy can't be had, since there are so many email programs out there, but we could as least handle the very popular ones. If the email quotes original text as above, or has 'Original message follows' section, then non-quoted stuff should be new. You could also use the difflib module. From koranthala at gmail.com Fri Jan 16 02:28:38 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 15 Jan 2009 23:28:38 -0800 (PST) Subject: Python Style Guide Questions References: Message-ID: <9cec6397-0e3d-4ede-bb5c-7f4143411142@o40g2000prn.googlegroups.com> On Jan 16, 12:00?pm, Terry Reedy wrote: > koranthala wrote: > > Hi, > > ? ?Which is more advisable? > > import x > > b = x.a > > ? ? ? ? ? ? ?or > > from x import a > > b = a > > If I know I want just one thing from x, I tend to use latter. > I also like 'import xyzlib as x' > > > ? ?I read in Learning Python that it is always better to use the > > former - especially since namespace wont be dirtied. > > Namespace get cluttered, not dirtied. ?In any case, either 'x' or 'a' > gets added. ?One new name either way. > > > class x: > > ? ? ?def y(): > > ? ? ? ? ? try: > > ? ? ? ? ? ? ? if test: > > ? ? ? ? ? ? ? ? ? obj.filename = str(os.path.basename > > (obj1.find_next_element().\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? get_file_path())) > > ? ? ? ? ? ? ? ? ? obj.modify_time = obj.filename.find_created_time() > > + ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? datetime.timedelta > > (seconds=time.find_time()) > > Use 4 spaces instead of 5 for indents > > > Almost every line requires the '\'. > > As Steven said, usually no > > > Also, especially since Python also > > uses whitespace as indentation, I keep confusing the block indentation > > with the indentation that the '\' causes in the next line. > > '\' causes no indentation > > Beyond that, consider find a style you like. ?I agree with Stvhen about > using 'thought-sized' expressions. > > tjr Thank you Steven and TJR. I will try to implement the thought sized expressions. I was rather misled by trying to decrease the line count as much as possible. From tjreedy at udel.edu Fri Jan 16 02:35:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:35:54 -0500 Subject: Beginner: Data type conversion question In-Reply-To: References: Message-ID: flagg wrote: > I am still fairly new to python and programming in general. My > question is regarding data conversion, I am working on a script that > will edit dns zone files, one of the functions i wrote handles > updating the serial number. > Our zone files use the date as the first part of the serial and a two > digit integer as the last two. > > i.e. 2009011501. The next update would be 2009011502, etc > Here is the function I wrote, I am using dnspython for reading in zone > files as Zone "objects". Because dnspython's built-in serial updater > will not work with how we format our serial's, I have to re-write it. > > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and > checks the current 'counter'(the two digit number at the end of > the serial number), then returns a complete new serial > """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] If rdate.serial is already a string, as name would imply, the str() call is pointless. If not, can you get inc as int more directly? > if date == currentDate: > int(inc) + 1 > print inc > newInc = str(inc).zfill(2) > serial = date + newInc > print "date is the same" > return serial > elif date < currentDate: > newInc = "01".zfill(2) > serial = currentDate + newInc > print "date is different" > return serial > > Through all of this I am doing a lot of data type conversion. string - >> integer, integer back to string, etc. Is this an efficient way of > handling this? I have to perform basic addition on the "inc" > variable, but also need to expose that value as a string. What I > have above does work, but I can't help but think there is a more > efficient way. I guess I am not used to data types being converted so > easily. Other than that, you are perhaps worrying too much, even if code could be squeezed more. The idea that every object knows how to convert itself to a string representation is basic to Python. tjr From Scott.Daniels at Acm.Org Fri Jan 16 02:36:08 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 15 Jan 2009 23:36:08 -0800 Subject: optimizing large dictionaries In-Reply-To: <7xmydsxhr0.fsf@ruckus.brouhaha.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> <7xmydsxhr0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Per Freem writes: >> 2] is there an easy way to have nested defaultdicts? ie i want to say >> that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact >> that my_dict is a dictionary, whose values are dictionary that map to >> ints. but that syntax is not valid. > > my_dict = defaultdict(lambda: defaultdict(int)) or my_dict = defaultdict(functools.partial(defaultdict, int)) --Scott David Daniels Scott.Daniels at Acm.Org From max at alcyone.com Fri Jan 16 02:39:20 2009 From: max at alcyone.com (Erik Max Francis) Date: Thu, 15 Jan 2009 23:39:20 -0800 Subject: English-like Python In-Reply-To: <6taoivFa0390U1@mid.individual.net> References: <6taoivFa0390U1@mid.individual.net> Message-ID: Tobias Andersson wrote: > The Music Guy skrev: >> Just out of curiousity, have there been any attempts to make a version >> of Python that looks like actual English text? I mean, so much of Python >> is already based on the English language that it seems like the next >> natural step would be to make a programming language which is actually a >> spoken one. > > Take a look at Inform 7. It's not Python but does something similar to > what you are describing: > > www.inform-fiction.org > > Check out the examples in the tutorial. Some of them are quite elegant. I was thinking of this as well when I saw his post. Inform 7 has some interesting ideas, but I think the general problem with English-like programming language systems is that once you get into the nitty gritty details, you end up having to know exactly the right things to type, which ultimately get just as complicated as a more traditional programming language syntax. In the big picture I don't think it helps much. After all, there's a reason that most modern programming languages don't look like COBOL or AppleScript. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Physics, as we know it, will be over in six months. -- Max Born, 1928 From bignose+hates-spam at benfinney.id.au Fri Jan 16 02:39:47 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 18:39:47 +1100 Subject: Python Style Guide Questions References: Message-ID: <873afjbsxo.fsf@benfinney.id.au> koranthala writes: > import x > b = x.a > or > from x import a > b = a > > I read in Learning Python that it is always better to use the > former - especially since namespace wont be dirtied. The namespace isn't really dirtied by ?from foo import spam?, since it's clear within the module where the name ?spam? comes from. What dirties a namespace is ?from foo import *?. Avoid that. > But, doing that with PEP 8 together causes my code to look rather > cluttered. Reason being that - PEP 8 suggests that have max line > length = 79 chars. Yes, this is one valid reason to change names on import. Even better, sometimes, can be the ?as? clause: from foo.bar import UncomfortablyLongNamedClass as NamedClass spam = NamedClass() > So my code mostly looks like this: > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) > > etc .. etc.. > Almost every line requires the '\'. In fact, they don't. Python allows parentheses around any expression, and allows line continuation when a bracketing syntax (parentheses, brackets, braces) has not been closed. Combined, these allow you to break a statement and align the line continuations nicely with standard four-space indentation: obj.filename = str( os.path.basename( obj1.find_next_element().get_file_path())) obj.modify_time = ( obj.filename.find_created_time() + datetime.timedelta(seconds=time.find_time())) > Also, especially since Python also uses whitespace as indentation, I > keep confusing the block indentation with the indentation that the > '\' causes in the next line. That's another reason I tend to break on an existing open-parenthesis (e.g. for a function call) where possible; it's clearer to the eye that the statement is incomplete. When ther isn't an easy parenthesis available, I'm not shy about applying parentheses, as above, merely to allow line continuation. > Could you please let me know what you guys usually do in such cases? > Is it advisable to go for the from x import a to avoid this clutter? Employing the existing line continuations as above, I find I don't often need to shorten names on import. Especially I tend to avoid changing the name of anything imported from the standard library, or from some very widely-used code base, since I feel that would tend to impede readability of my code. But, on those occasions where the names are still excessively long, yes, the import renaming can be very useful, when applied sparingly. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From tjreedy at udel.edu Fri Jan 16 02:39:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:39:53 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: > On Jan 15, 8:02 am, Paul Rubin wrote: >> Have you looked at Tim Sweeney's talk that I mentioned in another post? >> >> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... I did. He gives a really nice use case for Python's ability to dynamically modify classes imported from a library. (Were not you arguing against that? Or was is someone else?) From bj_666 at gmx.net Fri Jan 16 02:43:26 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 16 Jan 2009 07:43:26 GMT Subject: Beginner: Data type conversion question References: Message-ID: <6tas4tF9v94eU1@mid.uni-berlin.de> On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote: > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and checks > the current 'counter'(the two digit number at the end of the serial > number), then returns a complete new serial """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) The format string can be written as *one* string literal instead of three: "%Y%m%d". > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] Here you are converting `rdata.serial` twice. tmp = str(rdata.serial) date = tmp[0:8] inc = int(tmp[8:10]) As `inc` is conceptually a number, you should do the conversion here and treat it as number from now on. > if date == currentDate: > int(inc) + 1 > print inc > newInc = str(inc).zfill(2) > serial = date + newInc > print "date is the same" > return serial > elif date < currentDate: > newInc = "01".zfill(2) > serial = currentDate + newInc > print "date is different" > return serial Both branches do almost the same. You should try to avoid such code duplication. if date == currentDate: inc += 1 elif date < currentDate: inc = 1 else: assert False # Should never happen. return "%s%02d" % (date, inc) That's it. Ciao, Marc 'BlackJack' Rintsch From tjreedy at udel.edu Fri Jan 16 02:48:26 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:48:26 -0500 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Cong Ma wrote: > Terry Reedy wrote: >> Not to me. You are using the module as a singleton class. The >> alternative is to write a class, make the functions methods, and >> instantiate the class. If that instance must be a singleton, more work >> is required. If multiple instances make sense, you can go the class >> route when you need to. > > I've thought of this too, but it turns out those functions are related to each > other very loosely. They do a lot of completely different things independently > and have just one common global variable to share. IMHO it would reduce the > readability of code because the role of this class is very unclear. Anyway, > "readability" is mostly a subjective matter and I think what you pointed out is > a good idea in general. From a user perspective, there is little difference between import mod and from mod import mod_class_singleton_instance as mod Modules and classes are both namespaces with names accessed as attributes (dotted names) rather than as quoted keys. (Classes are more also.) From tjreedy at udel.edu Fri Jan 16 02:51:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:51:10 -0500 Subject: spam on the list - how are things now? In-Reply-To: References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: James Mills wrote: > On Fri, Jan 16, 2009 at 1:30 PM, wrote: >> We've been running SpamBayes on the news-to-mail gateway on mail.python.org >> for a couple weeks now. To me it seems like the level of spam leaking onto >> the list has dropped way down but I'd like some feedback from people who >> read the python-list at python.org mailing list on the topic. > > Agreed. It has gone down. Thank you for taking the > time to do something about it :) Reading from gmane, there has not been much obvious spam lately. Thanks. From kenpuca.dev at gmail.com Fri Jan 16 02:51:43 2009 From: kenpuca.dev at gmail.com (Ken Pu) Date: Fri, 16 Jan 2009 02:51:43 -0500 Subject: lazy evaluation is sometimes too lazy... help please. Message-ID: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) The output is: [10, 11, 12, 13, 14] [10, 11, 12, 13, 14] I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10) for x in count()) until the end. But is this the right behaviour? How can I get the output I want: [0, 1, 2, 3, 4] [10, 11, 12, 13, 14] Thanks. Ken From mail at microcorp.co.za Fri Jan 16 02:53:33 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 09:53:33 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com><0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com><2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com><92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <001901c977b1$00bd6a20$0d00a8c0@hendrik> "James Mills" wrote: > At the most basic level do you really think a machine > really cares about whether -you- the programmer > has illegally accessed something you shouldn't have ? Yes it does - this is exactly why some chips have supervisor and user modes - to keep the monkeys away from the typewriter. - Hendrik From tjreedy at udel.edu Fri Jan 16 02:55:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:55:31 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: Tim H wrote: > r wrote: >> On Jan 14, 4:43 pm, Terry Reedy wrote: >> OFF-TOPIC:(but related) >> What is the state of Tkinter at this point. Is an active effort under >> way to port TK 8.5 into Python? Tkinter and IDLE are very important to >> Python, but i understand there are much more important areas where the >> GURU's are concentrating. Should there be a calling for "others" to >> get involved here? I would like to help out. >> Thanks > > Maybe I'm misunderstanding something here, but "About Idle" in Python > 2.6.1 (win32) says "Tk version: 8.5" Same in 3.0. I check .../python30/tcl/ and it has tck8/ tcl8.5, tix8.4, tk8.5 subdirs. From http Fri Jan 16 02:56:35 2009 From: http (Paul Rubin) Date: 15 Jan 2009 23:56:35 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: <7xd4en4rbg.fsf@ruckus.brouhaha.com> Terry Reedy writes: > >> Have you looked at Tim Sweeney's talk that I mentioned in another post? > >> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... > > I did. He gives a really nice use case for Python's ability to > dynamically modify classes imported from a library. (Were not you > arguing against that? Or was is someone else?) He is talking about extending classes by something like inheritance, not modifying them dynamically. This is also in the context of an extremely powerful static type system with existential and dependent types, and totality proofs for just about everything. That is about a billion light years away from anything anyone has ever proposed for Python. From bearophileHUGS at lycos.com Fri Jan 16 02:59:55 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 23:59:55 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: Terry Reedy: >It illustrates well the point you intended. I don't know what my point was. A suggestion: with that solver, to find solution in a faster way you have to write many equations. Bye, bearophile From mail at microcorp.co.za Fri Jan 16 03:03:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 10:03:28 +0200 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de><017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au><017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au><017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> Message-ID: <001a01c977b1$016542e0$0d00a8c0@hendrik> "Aaron Brady" wrote: On Jan 15, 6:41 pm, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > >> >> > Familiarize yourself with PEP8 for naming and coding-conventions > >> >> > first. 8< -------------- stuff giving Diez a hard time for the above ------------------------ Oh come on you lot - you are carrying on as if Diez were wearing his skull socks again - do me a favour and give him a break! - Hendrik From mail at microcorp.co.za Fri Jan 16 03:22:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 10:22:28 +0200 Subject: spam on the list - how are things now? References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: <001101c977b3$a9b91460$0d00a8c0@hendrik> "Terry Reedy" wrote: > James Mills wrote: > > On Fri, Jan 16, 2009 at 1:30 PM, wrote: > >> We've been running SpamBayes on the news-to-mail gateway on mail.python.org > >> for a couple weeks now. To me it seems like the level of spam leaking onto > >> the list has dropped way down but I'd like some feedback from people who > >> read the python-list at python.org mailing list on the topic. > > > > Agreed. It has gone down. Thank you for taking the > > time to do something about it :) > > Reading from gmane, there has not been much obvious spam lately. Thanks. I read this solely via the mailing list - and Yes, whatever was done has helped a lot. - Hendrik From prologic at shortcircuit.net.au Fri Jan 16 03:56:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 18:56:04 +1000 Subject: [Python-Dev] multiprocessing vs. distributed processing In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 6:30 PM, Matthieu Brucher wrote: > 2009/1/16 James Mills : >> I've noticed over the past few weeks lots of questions >> asked about multi-processing (including myself). > > Funny, I was going to blog about this, but not just for Python. > >> For those of you new to multi-processing, perhaps this >> thread may help you. Some things I want to start off >> with to point out are: >> >> "multiprocessing will not always help you get things done faster." > > Of course. There are some programs that are I/O or memory bandwidth > bound. So if one of those bottlenecks is common to the cores you use, > you can't benefit from their use. > >> "be aware of I/O bound applications vs. CPU bound" > > Exactly. We read a lot about Folding at Home, SETI at Home, they can be > distributed, as it is more or less "take a chunk, process it somewhere > and when you're finish tell me if there something interesting in it". > Not a lot of communications between the nodes. Then, there are other > applications that process a lot of data, they must read data from > memory, make one computation, read other data, compute a little bit > (finite difference schemes), and here we are memory bandwidth bound, > not CPU bound. > >> "multiple CPUs (cores) can compute multiple concurrent expressions - >> not read 2 files concurrently" > > Let's say that this is true for the usual computers. Clusters can make > concurrent reads, as long as there is the correct architecture behind. > Of course, if you only have one hard disk, you are limited. > >> "in some cases, you may be after distributed processing rather than >> multi or parallel processing" > > Of course. Clusters can be expensive, their interconnections even > more. So if your application is made of independent blocks that can > run on small nodes, without much I/Os, you can try distributed > computing. If you need big nodes with high-speed interconnections, you > will have to use parallel processing. > > This is just what my thoughts on the sucjet are, but I think I'm not > far from the truth. Of course, if I'm proved wrong, I'll be glad to > hear why. Thank you Matthieu for your response. Very good comments on some of the points I raised. Hopefully those interested in the topic will learn from this thread. cheers James PS: I assumed you meant to post back to the list and not just me :) From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 03:57:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 08:57:32 GMT Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> Message-ID: <01804283$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > Oh come on you lot - you are carrying on as if Diez were wearing his > skull socks again - do me a favour and give him a break! Well, for what it's worth, I should say one final thing: I didn't disagree with what Diez said, only the way he said it. I thought my original post made that clear, but perhaps I should have said so explicitly. And I certainly don't think less of him because of it. And... skull socks? Cool. Where can I get some? -- Steven From castironpi at gmail.com Fri Jan 16 04:04:08 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 16 Jan 2009 01:04:08 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <3c31a7d7-8dfc-430e-b8eb-fbeb427de291@k36g2000pri.googlegroups.com> On Jan 14, 7:04?pm, Chris Rebert wrote: > On Wed, Jan 14, 2009 at 4:30 PM, Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. snip > > Or, and this is the interesting part, use the ('identificationally') > > same tuples in both mappings, since the object is only mentioned, not > > used. > > > phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > > phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', > > '5p-11p' ) ] > > hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > > hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > > What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > Once you get beyond a main dict (e.g. name2phone) and one that's its > inverse (e.g. phone2name), yeah, I'd probably say you should be using > a relational DB for this. You could also use objects, but it sounds > like you really want to use SQL-like querying, which isn't well-suited > to plain objects (though it'd be fine with an ORM). I want the simplest data structure that can hold a relation. In this case, I would declare a new record as: PhoneInfo( 'Joan', '555-963', '9a-5p' ) PhoneInfo( 'Joan', '555-964', '5p-11p' ) However the syntax is flexible, such as in 'PhoneInfo.add' etc. I can query the structure myself if I can access it as an iterable of tuples. I think I want to use named tuples. for rec in PhoneInfo.records: if rec.name== 'Joan': something Or I can just use itertools.ifilter. recset= ifilter( lambda rec: rec.name== 'Joan', PhoneInfo.records ) for rec in recset: something Using objects is one advantage, since they are "live" (unserialized) and native, such as a relation of socket connections. (SQL would require an additional mapping object and a key to accomplish it.) From gopalm at infotechsw.com Fri Jan 16 04:16:03 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Fri, 16 Jan 2009 14:46:03 +0530 Subject: problem in implementing multiprocessing In-Reply-To: References: <89E5181815F74966B59B475F9B4ED600@pwit.com> Message-ID: <66510985287744829EE3AD881CE824B2@pwit.com> I create two heavy objects sequentially without using multipleProcessing then creation of the objects takes 2.5 sec.if i create these two objects in separate process then total time is 6.4 sec. i am thinking it is happening due to the pickling and unpickling of the objects.if i am right then what could be the sollution. my system configuration: dual-core processor winXP python2.6.1 gopal mishra wrote: > Hello, > > I am trying to implement the multiprocessing in my application to take > advantage of multiple cores. I have created two > > Separate process something like this. > > que = Queue > Process(target = getData, args=(que , section, MdbFile,)).start() > Process(target = getData, args=(que , section, MdbFile,)).start() > > In getData function I create the object(max 7MB size) and add in to queue > (que.put (object)). > > After that I fetch the object using que.get () and use in my application. > but it takes more time to get the data. More time than what? Than not getting the date? Than getting it some other way? CPU, OS, and Python version may also be relevant. > Any one can help me out this problem. > > Thanks, > Sibtey > > My code<<<<< > from multiprocessing import Process, Queue > > def getData(queue, section, mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > queue.put((section,mdbData)) > > def getData2(mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > return mdbData > > def test_multipleProcess(fromMdbFile, toMdbFile): > #multipleProcess > t1 = time.time() > queue = Queue() > sections = ['From', 'To'] > Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() > Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() > section, gapAppData = queue.get() > section, gapAppData = queue.get() > t2 = time.time() > print "total time using multiProcessing:",t2-t1 > d1 = getData2(fromMdbFile) > d2 = getData2(toMdbFile) > print "total time withought multiProcessing:", time.time()-t2 > > > > > > if __name__=='__main__': > f1 =r" a.mdb" > f2 =r"b.mdb" > test_multipleProcess(f1,f2) > > -- > http://mail.python.org/mailman/listinfo/python-list > From castironpi at gmail.com Fri Jan 16 04:22:23 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 16 Jan 2009 01:22:23 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: On Jan 14, 7:54?pm, MRAB wrote: > Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. > > > For a reverse lookup, you just need two lookups. > > name= {} > > phone= {} > > name[ '555-963' ]= 'Joan' > > phone[ 'Joan' ]= '555-963' > > > Though maybe the keys in 'name' should be names, instead of the > > values in it. ?The variable name doesn't clarify that. ?(What is more > > natural to you in reading code? ?Is one obviously wrong?) > > > phone[ '555-963' ]= 'Joan' > > name[ 'Joan' ]= '555-963' > > Consider "str(x)". It isn't saying "x is a string", it's saying "x as a > string". Similarly, "ord(x)" says "the ordinal value of x". So, > "phone[x]" means "the phone number of x". That's true. However, I want to map individual fields of records to the tuples (named tuples) containing the records themselves (unless I just need a set of tuples). I think what you are talking about is accessing the 'phone' field, which was not what I was thinking. (You see that in algorithm pseudocode a bit.) For that, you could use 'name[ tuple1 ]' to obtain the name. However, in relational data, there is no single key, of which the rest of the fields are just accessories. (Does that make sense?) I think I want to use the multiple mappings for different ways to have access to the data. > [snip]> What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > You could imagine an object where you provide a field name and a value > and it returns all those entries where that field contains that value. > That, basically, is a database. That's true. The mapping objects wouldn't be particularly helpful if I had patterns to match instead of exact values... as now I'm thinking you usually would. In other words, providing the mapping objects, even grouped together in a provider object, would only handle a small subset of possible queries, specifically exact equality. For example, the 'hourstocall' object is basically useless as specified. Even separating the fields wouldn't help in a hash. The separate fields would need to be stored in sorted lists, using 'bisect' to test inequality. (How does an SQL service implement inequality checks anyway?) However, it's interesting that my first thought was to start out with a mapping object, instead of just a set of 'namedtuple's. From daigno at gmail.com Fri Jan 16 04:24:34 2009 From: daigno at gmail.com (=?UTF-8?Q?=C3=89ric_Daigneault?=) Date: Fri, 16 Jan 2009 17:24:34 +0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <001901c977b1$00bd6a20$0d00a8c0@hendrik> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <001901c977b1$00bd6a20$0d00a8c0@hendrik> Message-ID: <5a827c4d0901160124v3aa568aet15440d0c40b4cc0f@mail.gmail.com> Hendrik van Rooyento keep the monkeys away from the typewriter. Love it... just fully describes why we should keep some parts hidden from the pointyHairedBossHired Code monkeys... I'd like to think I know what I am doing... can't say the same of all people that have access to the code unfortunately... also I have very little control over who has access to what.. if pointy haired boss says monkey A has access to all then gotta live with it. So this is why, however shameful it may be, I will not use python here for production stuff. --- God I miss it, however scary the ride may feel to a hardcore Java guy.. it sure was fun. Terry Reedy > I did. He gives a really nice use case for Python's ability to > dynamically modify classes imported from a library. (Were not you > arguing against that? Or was is someone else?) There is a place for these kind of hacks, however, see code monkeys above, I would want to make sure it is very well encapsulated (wrapper library for example) before I release it as a lib to the internal zoo. The thing that gets me with all this talk about dynamic access to private wannabe variables... What happens to your coupling, I like my code nice and tidy, high internal coupling is allowed but from the wild I would tend to want to reduce it as much as possible. Dynamically replaced code is a nice idea indeed and I could think of a few really nice uses for this (good luck for this kind of flexibility in Java) but doing so you willingly break the encapsulation convention, thus you must also manage the possible consequences that arise from this break. Python is nice quick and flexible... but it provides so much rope a monkey would hang the whole ecosystem with it. Me I like the big spool, but as some wise dude once said with great power comes great responsibilities. On Fri, Jan 16, 2009 at 3:53 PM, Hendrik van Rooyen wrote: > "James Mills" wrote: > > > At the most basic level do you really think a machine > > really cares about whether -you- the programmer > > has illegally accessed something you shouldn't have ? > > Yes it does - this is exactly why some chips have supervisor > and user modes - to keep the monkeys away from the typewriter. > > - Hendrik > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jan 16 04:31:37 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Jan 2009 10:31:37 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Terry Reedy wrote: > Peter Otten wrote: > >> List comprehensions delete the helper variable after completion: > > I do not believe they did in 2.4. Not sure of 2.5. As Mario said, 2.4, 2.5, and 2.6 all show the same behaviour. > There is certainly > a very different implementation in 3.0 and, I think, 2.6. OP > neglected to mention Python version he tested on. Code meant to run on > 2.4 to 3.0 cannot depend on subtle listcomp details. 3.0 behaves different. Like generator expressions listcomps no longer leak the loop variable, and this is implemented by having each listcomp execute as a nested function: > In 3.0 > >>> def f(): [i for i in [1]] > > >>> import dis > >>> dis.dis(f) > 1 0 LOAD_CONST 1 ( at > 0x01349BF0, file "", line 1>) > 3 MAKE_FUNCTION 0 > 6 LOAD_CONST 2 (1) > 9 BUILD_LIST 1 > 12 GET_ITER > 13 CALL_FUNCTION 1 > 16 POP_TOP > 17 LOAD_CONST 0 (None) > 20 RETURN_VALUE This is more robust (at least I can't think of a way to break it like the 2.x approach) but probably slower due to the function call overhead. The helper variable is still there, but the possibility of a clash with another helper is gone (disclaimer: I didn't check this in the Python source) so instead of # 2.5 and 2.6 (2.4 has the names in a different order) >>> def f(): ... [[i for i in ()] for k in ()] ... >>> f.func_code.co_varnames ('_[1]', 'k', '_[2]', 'i') we get # 3.0 >>> def f(): ... [[i for i in ()] for k in ()] ... >>> f.__code__.co_varnames () The variables are gone from f's scope, as 3.x listcomps no longer leak their loop variables. >>> f.__code__.co_consts (None, at 0x2b8d7f6d7530, file "", line 2>, ()) >>> outer = f.__code__.co_consts[1] >>> outer.co_varnames ('.0', '_[1]', 'k') Again the inner listcomp is separated from the outer. >>> outer.co_consts ( at 0x2b8d7f6d26b0, file "", line 2>, ()) >>> inner = outer.co_consts[0] >>> inner.co_varnames ('.0', '_[1]', 'i') Peter From jstroud at mbi.ucla.edu Fri Jan 16 04:37:47 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 16 Jan 2009 01:37:47 -0800 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > The output is: > [10, 11, 12, 13, 14] > [10, 11, 12, 13, 14] > > I see what Python is doing -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. It doesn't evaluate it until you ask it to, which is the right behavior. However, when evaluated, it evaluates "i" also, which is the last value to which "i" was assigned, namely the integer 1. I'm going to get flamed pretty hard for this, but it doesn't seem to be the intuitive behavior to me either. However, in a purely functional language, you wouldn't be able to construct a list of generators in this way. With python, you have to remember to adopt a purely functional design and then pray for best results. You can store generators in a list, but they need to be constructed properly. I can't perfectly transmogrify your code into functional code because I don't think making the particular anonymous generator you want is possible in python. However this is how I would make a close approximation: from itertools import * def make_gen(i): for x in count(): yield x + (i * 10) itlist = [make_gen(i) for i in xrange(2)] print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From see.signature at no.spam Fri Jan 16 04:47:36 2009 From: see.signature at no.spam (Eric Brunel) Date: Fri, 16 Jan 2009 10:47:36 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> Message-ID: On Thu, 15 Jan 2009 19:09:00 +0100, Jos? Matos wrote: > On Thursday 15 January 2009 15:28:36 r wrote: >> First of all be very careful using from "module" import * or you will >> have name conflicts. Tkinter is made to be imported this way and i do >> it all the time. for the others do. >> >> import tkMessageBox as MB >> import tkFileDialog as FD >> or whatever floats your boat. > > Importing explicitly works for me in Fedora 11 (rawhide): > ----------------------------- > from Tkinter import * > from tkMessageBox import askyesno > from tkFileDialog import askopenfilename [snip] What do you mean by 'works'...? You don't have the problem? It doesn't change a thing for me... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From see.signature at no.spam Fri Jan 16 04:48:09 2009 From: see.signature at no.spam (Eric Brunel) Date: Fri, 16 Jan 2009 10:48:09 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy wrote: > Eric Brunel wrote: [snip]>> And BTW, if this is actually a bug, where can I report it? > > bugs.python.org Thanks. I reported the problem. -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From bieffe62 at gmail.com Fri Jan 16 04:52:49 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Fri, 16 Jan 2009 01:52:49 -0800 (PST) Subject: Client Socket Connection to Java server References: Message-ID: <29aac845-7323-456e-8505-35d3f7bd4631@o40g2000prn.googlegroups.com> On 16 Gen, 08:10, TechieInsights wrote: > I am having problems with a socket connection to a Java server. ?In > java I just open the socket, pass the length and then pass the bits > across the socket. > > I created a socket object: > > import socket > > class MySocket: > ? ? ? ? def __init__(self, host='localhost', port = 28192, buffsize = 1024): > ? ? ? ? ? ? ? ? socket.setdefaulttimeout(10) > > ? ? ? ? ? ? ? ? self.host = host > ? ? ? ? ? ? ? ? self.port = port > ? ? ? ? ? ? ? ? self.buffsize = buffsize > ? ? ? ? ? ? ? ? self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > ? ? ? ? ? ? ? ? self.socket.connect((host, port)) > > ? ? ? ? def send(self, data): > ? ? ? ? ? ? ? ? self.socket.send(data) > > ? ? ? ? def receive(self): > ? ? ? ? ? ? ? ? return self.socket.recv(self.buffsize) > > ? ? ? ? def sendAndReceive(self, data): > ? ? ? ? ? ? ? ? self.send(data) > ? ? ? ? ? ? ? ? return self.receive() > > ? ? ? ? def close(self): > ? ? ? ? ? ? ? ? self.socket.close() > > But the java server gives the error: > WARNING: Message length invalid. ?Discarding > > The data is of type string (xml). ?Am I doing something wrong? ?I know > you have to reverse the bits when communicating from C++ to Java. > Could this be the problem? I figured it would not because it said the > length was invalid. ?I just started looking at python sockets > tonight... and I don't have a real deep base with socket connections > as it is... any help would be greatly appreciated. > > Greg What is the server protocol? What are you sending? Saying 'xml' is not enough to understand the problem ... byte order could be a problem only if the message include binary representations of 2-bytes or 4-bytes integer. With XML this should not be the case Ciao ---- FB From duncan.booth at invalid.invalid Fri Jan 16 04:58:53 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 09:58:53 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 15, 1:08?pm, Duncan Booth wrote: >> Carl Banks wrote: >> > I don't see what the big deal is. ?Right now isinstance accepts a >> > typ > e >> > or a tuple of types. ?The code could be changed to allow a type, or >> > any iterable the returns types (wherein every items of the sequence >> > is required to be a type). ?What's messy about that? >> >> No, it isn't restricted to a type or a tuple of types: right now >> isinstan > ce >> accepts X where X is a type or a tuple of X. The definition is >> recursive, and the data structure can be deeply nested, but (because >> tuples are immutable) it cannot be infinite. >> >> e.g.>>> isinstance('x', (((((int, (float, str)),),),),)) >> >> True > > Oh. Not sure what the use case for THAT was, but that would make > things messy. > Duck typing purism? If you can use it to specify an exception you want to handle, then you can put it in a tuple with other exception specifications you can also handle. If you had to check whether it was a class or tuple to work out which sort of concatenation to use then you are breaking the first law of ducks. I think exception specifications came first and isinstance/issubclass followed suit, except of course exception specification were more complex as they could be classes, strings, or tuples of exception specifications. That still leaves the question whether anyone has ever actually taken advantage of this feature. You can do isinstance(x, (IntType, LongType, StringTypes)) but I didn't even know that StringTypes existed until a couple of moments ago, and I intend to forget about it again immediately. Grepping through the Python libraries on my system it looks like a lot of programmers don't even realise you can combine types into a tuple. -- Duncan Booth http://kupuguy.blogspot.com From tjreedy at udel.edu Fri Jan 16 05:06:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 05:06:30 -0500 Subject: Alphametric fun with Python In-Reply-To: References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Terry Reedy: >> It illustrates well the point you intended. > > I don't know what my point was. I quoted and was responding to Raymond. > > A suggestion: with that solver, to find solution in a faster way you > have to write many equations. I did... one for each column + plus the implied one that digits represented by the same letter get same value and that those represented by different letters gets different values. From wuwei23 at gmail.com Fri Jan 16 05:15:41 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 02:15:41 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> Message-ID: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> On Jan 16, 5:39?pm, Erik Max Francis wrote: > Inform 7 has some > interesting ideas, but I think the general problem with English-like > programming language systems is that once you get into the nitty gritty > details, you end up having to know exactly the right things to type, This has always been my impression of Inform 7. I have a lot of respect for what they've set out to achieve but English isn't exactly known for its lack of ambiguity. This is great for literature but not so helpful for programming. > which ultimately get just as complicated as a more traditional > programming language syntax. And much more verbose, as well. From mikehartl at web.de Fri Jan 16 05:17:18 2009 From: mikehartl at web.de (Michael Hartl) Date: Fri, 16 Jan 2009 11:17:18 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: <49705EAE.4070006@web.de> James Stroud schrieb: > Ken Pu wrote: >> Hi, below is the code I thought should create two generates, it[0] = >> 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the >> same!!! >> >> from itertools import * >> itlist = [0,0] >> for i in range(2): >> itlist[i] = (x+(i*10) for x in count()) >> >> print "what's in the bags:" >> print list(islice(itlist[0], 5)) >> print list(islice(itlist[1], 5)) >> >> The output is: >> [10, 11, 12, 13, 14] >> [10, 11, 12, 13, 14] >> >> I see what Python is doing -- lazy evaluation doesn't evaluate >> (x+(i*10) for x in count()) until the end. > > It doesn't evaluate it until you ask it to, which is the right > behavior. However, when evaluated, it evaluates "i" also, which is the > last value to which "i" was assigned, namely the integer 1. I'm going > to get flamed pretty hard for this, but it doesn't seem to be the > intuitive behavior to me either. However, in a purely functional > language, you wouldn't be able to construct a list of generators in > this way. > > With python, you have to remember to adopt a purely functional design > and then pray for best results. You can store generators in a list, > but they need to be constructed properly. I can't perfectly > transmogrify your code into functional code because I don't think > making the particular anonymous generator you want is possible in > python. However this is how I would make a close approximation: > > > from itertools import * > > def make_gen(i): > for x in count(): > yield x + (i * 10) > > itlist = [make_gen(i) for i in xrange(2)] > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > > James > You could just as well use the original expression in make_gen, too: from itertools import * def make_gen(i): return (x + (i*10) for x in count()) itlist = [make_gen(i) for i in xrange(2)] print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) what's in the bags: [0, 1, 2, 3, 4] [10, 11, 12, 13, 14] From tjreedy at udel.edu Fri Jan 16 05:24:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 05:24:15 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xd4en4rbg.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> <7xd4en4rbg.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >>>> Have you looked at Tim Sweeney's talk that I mentioned in another post? >>>> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... >> I did. He gives a really nice use case for Python's ability to >> dynamically modify classes imported from a library. (Were not you >> arguing against that? Or was is someone else?) > > He is talking about extending classes by something like inheritance, > not modifying them dynamically. This is also in the context of an > extremely powerful static type system with existential and dependent > types, and totality proofs for just about everything. That is about a > billion light years away from anything anyone has ever proposed for > Python. If the library framework were written in Python, one would have a choice between creating a parallel class hierachy (through inheritance) that dupicates *every* class in the original hierachy and dynamically patching just those classes that need to be changed. He only discussed the former option because that was the only one available. If, for instance, one only needed to change the base class, patching just that would be much easier. Hence my comment. tjr From ssalam at gmail.com Fri Jan 16 05:28:09 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Fri, 16 Jan 2009 15:58:09 +0530 Subject: PyPlot Message-ID: Hi , I need Pyplot module , How to get and install ( plug in with my python 2.4 distribution ) !!! TIA. Shah. From shi.dingan at gmail.com Fri Jan 16 05:31:02 2009 From: shi.dingan at gmail.com (shi dingan) Date: Fri, 16 Jan 2009 11:31:02 +0100 Subject: Problem using python C API Message-ID: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> Hi, I'm trying to use the Python C API but I have a problem when importing my new module. Here is my (short) code: #include "Python.h" long sumList(PyObject *list) { int i, n; long total = 0; PyObject *item; n = PyList_Size(list); if (n < 0) return NULL; for (i = 0; i < n; i++) { item = PyList_GetItem(list, i); if (!PyInt_Check(item)) continue; total += PyInt_AsLong(item); } return total; } PyObject *wrap_sumList(PyObject *self, PyObject *args) { PyObject *list; PyObject *total; if (!PyArg_ParseTuple(args, "0&", &list)) { return NULL; } total = Py_BuildValue("l", sumList(list)); return total; } static PyMethodDef exampleMethods[] = { {"sumList", wrap_sumList, METH_O}, {NULL} }; void initexample() { PyObject *m; m = Py_InitModule("example", exampleMethods); } My compilations lines: gcc -Wall -fpic -c -I/usr/include/python2.4 -I/usr/lib/python2.4/config mytest.c gcc -shared mytest.o -o examplemodule.so When I try to import examplemodule, I obtain the following message: >>> import examplemodule Traceback (most recent call last): File "", line 1, in ? ImportError: dynamic module does not define init function (initexamplemodule) Someone has an idea ? Thx, Marc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Jan 16 05:33:51 2009 From: http (Paul Rubin) Date: 16 Jan 2009 02:33:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> <7xd4en4rbg.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3zee0g.fsf@ruckus.brouhaha.com> Terry Reedy writes: > If the library framework were written in Python, one would have a > choice between creating a parallel class hierachy (through > inheritance) that dupicates *every* class in the original hierachy and > dynamically patching just those classes that need to be changed. I think I understand what you're saying, but it could be handled with generics. From bborcic at gmail.com Fri Jan 16 05:37:01 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 16 Jan 2009 11:37:01 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> References: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Message-ID: The minimal correction, I guess, is to write itlist[i] = (x+(i*10) for i in [i] for x in count()) instead of itlist[i] = (x+(i*10) for x in count()) although itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) will better mimic generalizations in the sense that the "minimal correction" delays the evaluation of count(), which doesn't matter in the case of count(), but might make a difference if you replace it with some other expression. The point is that the first iterator-producing expression in a generator expression - eg the in ( for vars in ...) - is evaluated immediately in the surrounding context, in contrast to the rest of the genexp. Cheers, BB Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > The output is: > [10, 11, 12, 13, 14] > [10, 11, 12, 13, 14] > > I see what Python is doing -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. But is this the right > behaviour? How can I get the output I want: > [0, 1, 2, 3, 4] > [10, 11, 12, 13, 14] > > Thanks. > > Ken > -- > http://mail.python.org/mailman/listinfo/python-list > From wuwei23 at gmail.com Fri Jan 16 05:45:56 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 02:45:56 -0800 (PST) Subject: lazy evaluation is sometimes too lazy... help please. References: Message-ID: <32b36c86-4ce5-4466-95e4-7d343fea1dad@q30g2000prq.googlegroups.com> James Stroud wrote: > I'm going to get flamed > pretty hard for this, but it doesn't seem to be the intuitive behavior > to me either. Given this is the second time this issue has come up today, I'd have to agree with you. From bborcic at gmail.com Fri Jan 16 05:46:17 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 16 Jan 2009 11:46:17 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Message-ID: > itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) oops, that would be itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s) or equivalent, kind of ugly anyway. From benlucas99 at googlemail.com Fri Jan 16 05:57:18 2009 From: benlucas99 at googlemail.com (benlucas99 at googlemail.com) Date: Fri, 16 Jan 2009 02:57:18 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: <034f2763-8c2a-478b-99b7-ba803276388c@k36g2000pri.googlegroups.com> On Jan 16, 1:44 am, John Machin wrote: > On Jan 16, 11:59 am, benluca... at googlemail.com wrote: > > > I'm having problems with the ordering of the tuples produced by > > urllib.urlencode. Taking an example straight from the docs and so > > doing the following: > > What are "the docs" you are reading that include such an example? The > docs distributed with Python 2.5.1 fromwww.python.orghave only this: > """ > urlencode( query[, doseq]) > > Convert a mapping object or a sequence of two-element tuples to a > ``url-encoded'' string, suitable to pass to urlopen() above as the > optional data argument. This is useful to pass a dictionary of form > fields to a POST request. The resulting string is a series of > key=value pairs separated by "&" characters, where both key and value > are quoted using quote_plus() above. If the optional parameter doseq > is present and evaluates to true, individual key=value pairs are > generated for each element of the sequence. When a sequence of two- > element tuples is used as the query argument, the first element of > each tuple is a key and the second is a value. The order of parameters > in the encoded string will match the order of parameter tuples in the > sequence. The cgi module provides the functions parse_qs() and > parse_qsl() which are used to parse query strings into Python data > structures. > """ > > > > > import urllib > > ... > > params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > > print params > > > The documentation for urlencode( query[, doseq]) says: "The order of > > parameters in the encoded string will match the order of parameter > > tuples in the sequence" but I'm getting: > > "query" can be either a mapping object (e.g. a dictionary, as you have > used) or a sequence of 2-tuples. No such guarantee as you quote above > can be made for a mapping; mappings are just not orderable. > If you want order, give it a sequence, like this: > > | >>> import urllib > | >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) > | 'spam=1&eggs=2&bacon=0' > > HTH, > John Thanks guys, the explanations really helped. I knew I was missing something fundamental. The docs I'm referring is section "18.7.3 Examples" in the Python Library Reference, 18th April, 2007, Release 2.5.1 But looking at it now I guess the server side procsssing that post request may not care about ordering (unlike the web API I'm trying to call). cheers, Ben From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:03:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:03:24 GMT Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <01806003$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 16:30:36 -0800, Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. [...] > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. Here's a lightweight solution that uses lazy calculation of the reverse dict. It makes a number of assumptions: - both keys and values will be hashable and unique; - the dict won't be so large that calculating the reverse dictionary will be time consuming; - modifications to instance.reverse are undefined. Usage: >>> d = ReverseDict(x=2, y=3, z=4) >>> d['x'] 2 >>> d.reverse[2] 'x' >>> d['a'] = 0 >>> d.reverse[0] 'a' def make_dirty(func): from functools import wraps @wraps(func) def f(self, *args, **kwargs): self._dirty = True return func(self, *args, **kwargs) return f # only tested a little bit class ReverseDict(dict): def __init__(self, *args, **kwargs): super(ReverseDict, self).__init__(*args, **kwargs) self._dirty = True @make_dirty def clear(): super(ReverseDict, self).clear() @make_dirty def __setitem__(self, key, value): super(ReverseDict, self).__setitem__(key, value) @make_dirty def __delitem__(self, key): super(ReverseDict, self).__delitem__() @make_dirty def pop(self, key, *arg): return super(ReverseDict, self).pop(key, *arg) @make_dirty def popitem(self): return super(ReverseDict, self).popitem() @make_dirty def setdefault(self, key, value=None): return super(ReverseDict, self).setdefault(key, value) @make_dirty def update(self, other): return super(ReverseDict, self).update(other) @property def reverse(self): if self._dirty: # Modify this to support repeated and non-hashable values. self._reverse = dict((value, key) for (key, value) in self.iteritems()) self._dirty = False return self._reverse An even more lightweight solution is to give up O(1) for the reverse lookup: # untested class ReversableDict(dict): def lookupvalue(self, value): for k,v in self.iteritems(): if v == value: return k raise ValueError('value not found') def lookupallvalues(self, value): results = [] for k,v in self.iteritems(): if v == value: results.append(k) return results -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:07:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:07:24 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> Message-ID: <018060f3$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 09:58:53 +0000, Duncan Booth wrote: > That still leaves the question whether anyone has ever actually taken > advantage of this feature. You can do isinstance(x, (IntType, LongType, > StringTypes)) but I didn't even know that StringTypes existed until a > couple of moments ago, and I intend to forget about it again > immediately. Grepping through the Python libraries on my system it looks > like a lot of programmers don't even realise you can combine types into > a tuple. I do it a lot, except I don't bother with IntType, LongType etc (I assume you imported them from the types module). I just do: isinstance(x, (int, float)) # or whatever -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:23:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:23:34 GMT Subject: lazy evaluation is sometimes too lazy... help please. References: Message-ID: <018064bd$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 02:51:43 -0500, Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! [...] > I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10) > for x in count()) until the end. But is this the right behaviour? How > can I get the output I want: [0, 1, 2, 3, 4] > [10, 11, 12, 13, 14] The solution I would use is: itlist = [0,0] for i in range(2): itlist[i] = ( lambda i: (x+(i*10) for x in count()) )(i) Or pull the lambda out of the loop: itlist = [0,0] def gen(i): return (x+(i*10) for x in count()) for i in range(2): itlist[i] = gen(i) -- Steven From hackingkk at gmail.com Fri Jan 16 06:32:09 2009 From: hackingkk at gmail.com (Krishnakant) Date: Fri, 16 Jan 2009 17:02:09 +0530 Subject: confused about publishing more than one class in twisted server. In-Reply-To: References: Message-ID: <1232105529.15347.8.camel@krishna-laptop> hello, I am writing a twisted based rpc service where I am implementing a complete application as a service. I have many modules which make a package. Now when we publish a service in twisted, we have to create one instance of a certain class and then publish it with the help of reactor. but in my application, there are more than one class in different .py files. Now I want to know how do i create a package where all the classes in different modules get published so that the entire package can be used as the rpc server application and the client can be used to query any module. for example I have classes to get and set vendor, product, bills etc. now all this has to be accessed through the xml rpc service. Can some one tell me how to manage the entire twisted package as a service. happy hacking. Krishnakant. From alfons.nonell at upf.edu Fri Jan 16 07:02:59 2009 From: alfons.nonell at upf.edu (Alfons Nonell-Canals) Date: Fri, 16 Jan 2009 13:02:59 +0100 Subject: Integrating awk in Python Message-ID: <1232107379.25150.46.camel@king.imim.es> Hello, I'm developing a software package using python. I've programmed all necessary tools but I have to use other stuff from other people. Most of these external scripts are developed using awk. At the beggining I thought to "translate" them and program them in python but I prefer to avoid it because it means a lot of work and I should do it after each new version of this external stuff. I would like to integrate them into my python code. I know I can call them using the system environment but it is slower than if I call them inside the package. I know it is possible with C, do you have experience on integrate awk into python calling these awk scripts from python? Thanks in advance! Regards, Alfons. -- ------------ Alfons Nonell-Canals, PhD Chemogenomics Lab Research Group on Biomedical Informatics (GRIB) - IMIM/UPF Barcelona Biomedical Research Park (PRBB) C/ Doctor Aiguader, 88 - 08003 Barcelona alfons.nonell at upf.edu - http://cgl.imim.es Tel. +34933160528 http://alfons.elmeuportal.cat http://www.selenocisteina.info -------------- next part -------------- An HTML attachment was scrubbed... URL: From siona at chiark.greenend.org.uk Fri Jan 16 07:09:47 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 16 Jan 2009 12:09:47 +0000 (GMT) Subject: mimetypes oddity References: Message-ID: In article , wrote: > [mimetype weirdness reported] > Sion> Is this a bug? >Might be. Can you file a bug report in the Python issue tracker with a >small script that demonstrates the behavior? http://bugs.python.org/issue4963 (It's tagged as being 2.4 and 2.5 because those are the versions I have to hand to confirm it on, but I'd be rather surprised if it's not still like this in 2.6.) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From jnoller at gmail.com Fri Jan 16 07:15:25 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 16 Jan 2009 07:15:25 -0500 Subject: multiprocessing vs. distributed processing In-Reply-To: References: Message-ID: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> On Fri, Jan 16, 2009 at 12:52 AM, James Mills wrote: > I've noticed over the past few weeks lots of questions > asked about multi-processing (including myself). > > For those of you new to multi-processing, perhaps this > thread may help you. Some things I want to start off > with to point out are: > > "multiprocessing will not always help you get things done faster." > > "be aware of I/O bound applications vs. CPU bound" > > "multiple CPUs (cores) can compute multiple concurrent expressions - > not read 2 files concurrently" > > "in some cases, you may be after distributed processing rather than > multi or parallel processing" > > cheers > James James is quite correct, and maybe I need to amend the multiprocessing documentation to reflect this fact. While distributed programming and parallel programming may cross paths in a lot of problems/applications, you have to know when to use one versus the other. Multiprocessing only provides some basic primitives to help you get started with distributed programming, it is not it's primary focus, nor is it a complete solution for distributed applications. That being said, there is no reason why you could not use it in conjunction with something like Kamaelia, pyro, $ipc mechanism/etc. Ultimately, it's a tool in your toolbox, and you have to judge and experiment to see which tool is best applied to your problem. In my own work/code, I use both processes *and* threads - one works better than the other depending on the problem. For example, a web testing tool. This is something that needs to generate hundreds of thousands of HTTP requests - not a problem you want to use multiprocessing for given that A> It's primarily I/O bound and B> You can generate that many threads on a single machine. However, if I wanted to say, generate hundreds of threads across multiple machines, I would (and do) use multiprocessing + paramiko to construct a grid of machines and coordinate work. That all being said: multiprocessing isn't set in stone - there's room for improvement in the docs, tests and code, and all patches are welcome. -jesse From jnoller at gmail.com Fri Jan 16 07:33:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 16 Jan 2009 07:33:34 -0500 Subject: process/thread instances and attributes In-Reply-To: References: <496F03B9.8090100@shopzeus.com> Message-ID: <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> On Thu, Jan 15, 2009 at 10:37 PM, James Mills wrote: > After some work ... I've taken Laszlo's suggestion of using Value > (shared memory) objects > to share state between the -pseudo- Process (manager) object and it's > underlying multiprocessing.Process > instance (and subsequent process): > > Here is the code: > > ---------------------------------------- > #!/usr/bin/env python > > import os > from time import sleep > > from threading import activeCount as threads > from threading import Thread as _Thread > > from multiprocessing import Value > from multiprocessing import Process as _Process > from multiprocessing import active_children as processes > > class Process(object): > > def __init__(self, *args, **kwargs): > super(Process, self).__init__(*args, **kwargs) > > self.running = Value("b", False) > self.thread = _Thread(target=self.run) > self.process = _Process(target=self._run, args=(self.running,)) > > def _run(self, running): > self.thread.start() > > try: > while running.value: > try: > sleep(1) > print "!" > except SystemExit: > running.acquire() > running.value = False > running.release() > break > except KeyboardInterrupt: > running.acquire() > running.value = False > running.release() > break > finally: > running.acquire() > running.value = False > running.release() > self.thread.join() > > def start(self): > self.running.acquire() > self.running.value = True > self.running.release() > self.process.start() > > def run(self): > pass > > def stop(self): > print "%s: Stopping ..." % self > self.running.acquire() > self.running.value = False > self.running.release() > > def isAlive(self): > return self.running.value > > class A(Process): > > def run(self): > while self.isAlive(): > sleep(5) > self.stop() > > a = A() > a.start() > > N = 0 > > while a.isAlive(): > sleep(1) > print "." > print "threads: %d" % threads() > print "processes: %d" % len(processes()) > > print "DONE" > ---------------------------------------- > > Here is the result of running this: > > ---------------------------------------- > $ python test3.py > ! > . > threads: 1 > processes: 1 > . > threads: 1 > processes: 1 > ! > ! > . > threads: 1 > processes: 1 > . > threads: 1 > processes: 1 > ! > . > threads: 1 > processes: 1 > ! > <__main__.A object at 0x80de42c>: Stopping ... > ! > . > threads: 1 > processes: 0 > DONE > ---------------------------------------- > > This appears to work as I intended. > > Thoughts / Comments ? > > cheers > James Personally, rather then using a value to indicate whether to run or not, I would tend to use an event to coordinate start/stop state. -jesse From w.richert at gmx.net Fri Jan 16 07:34:28 2009 From: w.richert at gmx.net (Willi Richert) Date: Fri, 16 Jan 2009 13:34:28 +0100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: <200901161334.28275.w.richert@gmx.net> Hi, take a look at the 5th link at http://tinyurl.com/7s8kfq It's called pyawk. Regards, wr Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program them in > python but I prefer to avoid it because it means a lot of work and I > should do it after each new version of this external stuff. I would like > to integrate them into my python code. > > I know I can call them using the system environment but it is slower > than if I call them inside the package. I know it is possible with C, do > you have experience on integrate awk into python calling these awk > scripts from python? > > Thanks in advance! > > Regards, > Alfons. From ajaksu at gmail.com Fri Jan 16 07:35:23 2009 From: ajaksu at gmail.com (ajaksu) Date: Fri, 16 Jan 2009 04:35:23 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> Message-ID: On Jan 16, 5:09?am, mario ruggier wrote: > Laboriously doing all these > checks on each expr eval will be very performance heavy, so I hope to > be able to limit access to all these more efficiently. Suggestions? None regarding the general issue, a try:except to handle this one: '(x for x in ()).throw("bork")' From mail at microcorp.co.za Fri Jan 16 07:38:51 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 14:38:51 +0200 Subject: Convention vs. fascism [OT] References: <6t8comF9ou5uU1@mid.uni-berlin.de><017f44a3$0$8693$c3e8da3@news.astraweb.com><87zlhsb81i.fsf_-_@benfinney.id.au><017fb1f3$0$8693$c3e8da3@news.astraweb.com><87vdsgb1b0.fsf@benfinney.id.au><017fce36$0$8693$c3e8da3@news.astraweb.com><95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <000c01c977e8$87ac3de0$0d00a8c0@hendrik> "Steven D'Aprano" wrote: >And... skull socks? Cool. Where can I get some? Don't you remember? - Google the group - there was some dust raised about them some time ago. I think he got them from KDW - "Kaufhaus Der Welt" aka "Klau Dir Was" :-) - Hendrik From steve at holdenweb.com Fri Jan 16 08:22:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 08:22:36 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: Russ P. wrote: [...] > I spent *way* too much time on that post. I really need to quit > spending my time refuting the baloney that passes for wisdom here. He who cannot ignore baloney is doomed to refute it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From es at ertes.de Fri Jan 16 08:34:41 2009 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Fri, 16 Jan 2009 14:34:41 +0100 Subject: Experiment: Church lists in Python Message-ID: <20090116143441.5f0f8e8f@ertes.de> Hello there Pythoners, It was almost a week ago, when I got bored and thought, Python is quite a boring language, so I'd need to do some evil functional programming again. I thought, I'd share the result. ;) This time, I added a Church style representation for lists [1] to Python. The problem they solve: What do you do, if you've got only scalar values, functions and function application, but you need lists? Here is the solution: Represent lists as higher order functions: def empty(): return lambda f, z: z def cons(x, xs): return lambda f, z: f(x, xs(f, z)) def fold(f, z, xs): return xs(f, z) The empty() function returns an empty list and the cons() function returns the list in its second argument with the element in its first argument prepended, so cons(x, xs) is equivalent to the list [x] + xs. The 'fold' function is actually superfluous, but it makes much clearer what you're doing, when using this type of lists. It's the right-associative version of the 'reduce' function. All other list operations can be defined in terms of these three functions. I've done that for you [2] (mostly). If Python implements closures efficiently, this list representation is actually very fast for list folding, i.e. consuming an entire list to construct a value (which may be anything, including lists or functions). However, it's slow for extracting individual elements, because this operation must be a fold, too, as folding is the only way to access the elements of a list. An interesting property of this representation is that it gets along without any impure functions, i.e. all functions are completely free of side effects. Unless you use an impure fold function, everything is perfectly purely functional. Have fun. =) Greets, Ertugrul. [1] http://en.wikipedia.org/wiki/Church_encoding#Higher-order-function, a representation of a list as a higher order function. [2] http://ertes.de/python/fun/chlists.py, a little library of Python functions implementing Church style lists using higher order functions. The way the 'range' function is defined, was an experiment: how to emulate partial application in Python. Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/ From dougjrs at gmail.com Fri Jan 16 09:12:06 2009 From: dougjrs at gmail.com (Doug) Date: Fri, 16 Jan 2009 06:12:06 -0800 (PST) Subject: Soap Client References: <5947e87e-7679-4121-98f0-b77b2ae56be4@13g2000yql.googlegroups.com> Message-ID: <0c6d2f41-fd4b-464c-afa5-2559b2c85ae0@y1g2000pra.googlegroups.com> I believe that I have answered my own question. If anyone else is interested in what I did ... using iPython's code completion (. then hit tab tab) I noticed that msg had a _request attribute. I set that attribute to "1" and that sent the message that I needed! Hope everyone has a great day! Doug From johnroth1 at gmail.com Fri Jan 16 09:23:18 2009 From: johnroth1 at gmail.com (John Roth) Date: Fri, 16 Jan 2009 06:23:18 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: On Jan 16, 3:15?am, alex23 wrote: > On Jan 16, 5:39?pm, Erik Max Francis wrote: > > > Inform 7 has some > > interesting ideas, but I think the general problem with English-like > > programming language systems is that once you get into the nitty gritty > > details, you end up having to know exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but not > so helpful for programming. > > > which ultimately get just as complicated as a more traditional > > programming language syntax. > > And much more verbose, as well. Since I've used Inform 7 I can say that the syntactic problem isn't that great: once you get far enough into a project to matter the specialized constraints just sink in. It's more work to learn, but no stranger than Python's indentation scheme. The bigger problem for the comparison is that Inform 7 is a Domain Specific Language (DSL), not a general purpose language. Not only that, but the domain is pretty much everyday experience (with a large dollop of fantasy, of course). All the feedback is that the results are quite readable to non-programmers. This is why well over half of the mailing list posts on the authoring mailing list are about Inform 7. I really don't think that using natural language for a general purpose programming language is a good idea, for reasons that several other people have already said. I think it's a great idea for DSLs, at least in some cases. The other really major problem is that I don't think anyone really knows how to process natural language. The direction that natural language processing has taken in the last 50 years has come up lacking big-time. It does a good job in a single domain, but try to build something that crosses domains and nothing works. There isn't a good alternative in sight John Roth From james.colin.brady at gmail.com Fri Jan 16 09:25:55 2009 From: james.colin.brady at gmail.com (James Brady) Date: Fri, 16 Jan 2009 06:25:55 -0800 (PST) Subject: Readline and Python 2.6.1 on a Mac References: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Message-ID: <31fc0495-3371-484d-9ab7-76074e39a54f@r10g2000prf.googlegroups.com> > s/"bind ^I rl_complete"/"tab: complete"/ > > > > -- > ?Ned Deily, > ?n... at acm.org Perfect, thanks Ned! From duncan.booth at invalid.invalid Fri Jan 16 09:29:18 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 14:29:18 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> <018060f3$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Jan 2009 09:58:53 +0000, Duncan Booth wrote: > >> That still leaves the question whether anyone has ever actually taken >> advantage of this feature. You can do isinstance(x, (IntType, >> LongType, StringTypes)) but I didn't even know that StringTypes >> existed until a couple of moments ago, and I intend to forget about >> it again immediately. Grepping through the Python libraries on my >> system it looks like a lot of programmers don't even realise you can >> combine types into a tuple. > > > I do it a lot, except I don't bother with IntType, LongType etc (I > assume you imported them from the types module). I just do: > > isinstance(x, (int, float)) # or whatever > Yes, I do that too, and naturally I don't use the types module. The question though was whether anyone, anywhere, has ever taken advantage of the fact that isinstance accepts *nested* tuples. My point was intended to be that perhaps if someone imported from the types module they might just use StringTypes in a tuple along with the single type names, but it seems pretty unlikely to be common usage. -- Duncan Booth http://kupuguy.blogspot.com From thomas.weholt at gmail.com Fri Jan 16 09:30:40 2009 From: thomas.weholt at gmail.com (Thomas W) Date: Fri, 16 Jan 2009 06:30:40 -0800 (PST) Subject: Start multiple listening servers in one file Message-ID: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> I`m working on a django-project where I`m using the awsome pyftpdlib for ftpserver-functionality. I also have a simple worker deamon running in the background, but not listening to any port. How can I start all of these processes on one file? Tried using subprocess and popen but that resulted in an eternal loop starting the servers over and over until all resources were used, then crash. Any hint on how to do this would be highly appreciated. From kyrie at uh.cu Fri Jan 16 09:36:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 16 Jan 2009 09:36:11 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <1232116571.49709b5bbcacb@mail.uh.cu> Quoting "Russ P." : > On Jan 15, 12:21?pm, Bruno Desthuilliers > wrote: > > > Once again, the important point is that there's a *clear* distinction > > between interface and implementation, and that you *shouldn't* mess with > > implementation. > > If you "*shouldn't* mess with the implementation", then what is wrong > with enforcing that "shouldn't" in the language itself? Because, as a library user, it should be my power to chose when and how I _should_ mess with the implementation, not the compiler, and definitely not you. > So let's take the airplane example. Boeing and its contractors > probably has hundreds of programmers working on millions of lines of > code. If they believed you, they would abandon enforced data hiding, > and programmers would have much more discretion to screw around with > code that they don't work on directly. An FMS programmer could perhaps > decide to change the parameters of the engine controls, for example. I really hope that, at Boeing, they do a lot of unit tests and code reviews before the code is commited. Messing with the internals wouldn't be the only bad thing that could happen, you know... And I'd say that "x._private" where x is not 'self', would be very easy to catch on those code reviews. And, as someone else pointed out, even with 'strong' enforcement of data-hiding, you can usually access the privates anyway - it's just a bit harder to do, and a lot harder to discover. You pointed out previously that Python wasn't up to the task of running untrusted code on my own application, and I agreed. _That_ is what you seem need, and enforced data hiding does very little towards it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From vedrandekovic at gmail.com Fri Jan 16 09:36:16 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Fri, 16 Jan 2009 06:36:16 -0800 (PST) Subject: Start two threads in same time Message-ID: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Hello, Does anybody know how can I start two threads in same time? Regards, John From mrkafk at gmail.com Fri Jan 16 09:38:23 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 15:38:23 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) +100 for this one > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. The lack of this already causes some pains at my company. I was flabbergasted to read that optional static typing was dropped by Guido due to "lack of interest in community" IIRC. Why!! Among other reasons, this could have provided for very easy performance optimizations of the small portions of the code! This could have been a huge gain acquired for little effort! Regards, mk From google at mrabarnett.plus.com Fri Jan 16 09:39:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 14:39:44 +0000 Subject: English-like Python In-Reply-To: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: <49709C30.2050303@mrabarnett.plus.com> [Hit Reply instead of Reply All. Sorry alex23.] alex23 wrote: > On Jan 16, 5:39 pm, Erik Max Francis wrote: >> Inform 7 has some interesting ideas, but I think the general >> problem with English-like programming language systems is that once >> you get into the nitty gritty details, you end up having to know >> exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but > not so helpful for programming. > >> which ultimately get just as complicated as a more traditional >> programming language syntax. > > And much more verbose, as well. > I once had to do something in AppleScript. The problem I found was that it tried so much to resemble English that it wasn't always clear what was valid! Programming languages need to look artificial to remind you that the computers aren't intelligent. Python, for example, is clearly artificial but with a clear syntax and short (but not too short) reserved words. From google at mrabarnett.plus.com Fri Jan 16 09:43:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 14:43:53 +0000 Subject: Client Socket Connection to Java server In-Reply-To: References: Message-ID: <49709D29.609@mrabarnett.plus.com> TechieInsights wrote: > I am having problems with a socket connection to a Java server. In > java I just open the socket, pass the length and then pass the bits > across the socket. > > I created a socket object: > > import socket > > class MySocket: > def __init__(self, host='localhost', port = 28192, buffsize = 1024): > socket.setdefaulttimeout(10) > > self.host = host > self.port = port > self.buffsize = buffsize > self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self.socket.connect((host, port)) > > def send(self, data): > self.socket.send(data) I recommend sendall() instead of send(): self.socket.sendall(data) send() doesn't guarantee to send all the data, so multiple sends might be needed to send it all. sendall() does that for you. > > def receive(self): > return self.socket.recv(self.buffsize) > > def sendAndReceive(self, data): > self.send(data) > return self.receive() > > def close(self): > self.socket.close() > > But the java server gives the error: > WARNING: Message length invalid. Discarding > > The data is of type string (xml). Am I doing something wrong? I know > you have to reverse the bits when communicating from C++ to Java. > Could this be the problem? I figured it would not because it said the > length was invalid. I just started looking at python sockets > tonight... and I don't have a real deep base with socket connections > as it is... any help would be greatly appreciated. > > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From koranthala at gmail.com Fri Jan 16 09:46:54 2009 From: koranthala at gmail.com (koranthala) Date: Fri, 16 Jan 2009 06:46:54 -0800 (PST) Subject: Start two threads in same time References: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Message-ID: On Jan 16, 7:36?pm, vedrandeko... at gmail.com wrote: > Hello, > > Does anybody know how can I start two threads in same time? > > Regards, > John Use threading module. Creating a new thread is as easy as -- ----------------------------------------------------------------------- import threading class ThreadedClass(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): **Do whatever you want do in the new thread here** threaded_obj = ThreadedClass() threaded_obj.setDaemon(True) # If you want a daemon thread threaded_obj.start() # Start the new thread %%%%Do whatever you want to do in main thread here%%% threaded_obj.join() #Close the new thread by joining it with the main thread -------------------------------------------------------------------------------- The following document might be of help: http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf From koranthala at gmail.com Fri Jan 16 09:51:31 2009 From: koranthala at gmail.com (koranthala) Date: Fri, 16 Jan 2009 06:51:31 -0800 (PST) Subject: Start two threads in same time References: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Message-ID: <3a221f6e-de5b-41f9-b7c6-6368d9af47eb@r15g2000prh.googlegroups.com> On Jan 16, 7:46?pm, koranthala wrote: > On Jan 16, 7:36?pm, vedrandeko... at gmail.com wrote: > > > Hello, > > > Does anybody know how can I start two threads in same time? > > > Regards, > > John > > Use threading module. > Creating a new thread is as easy as -- > ----------------------------------------------------------------------- > import threading > > class ThreadedClass(threading.Thread): > ? ? def __init__(self): > ? ? ? ? threading.Thread.__init__(self) > > ? ? def run(self): > ? ? ? ? ?**Do whatever you want do in the new thread here** > > threaded_obj = ThreadedClass() > threaded_obj.setDaemon(True) ?# If you want a daemon thread > threaded_obj.start() # Start the new thread > > %%%%Do whatever you want to do in main thread here%%% > > threaded_obj.join() #Close the new thread by joining it with the main > thread > > -------------------------------------------------------------------------------- > > The following document might be of help:http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf If you want to create n threads, just create and call the threaded_obj n times. So, the code will look like: threaded_obj = [] for i in range(n): threaded_obj[i] = ThreadedClass() threaded_obj[i].setDaemon(True) # If you want a daemon thread threaded_obj[i].start() # Start the new thread %%%%Do whatever you want to do in main thread here%%% #To close the threads for o in threaded_obj: o.join() --HTH-- From philip at semanchuk.com Fri Jan 16 09:58:54 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 16 Jan 2009 09:58:54 -0500 Subject: Problem using python C API In-Reply-To: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> References: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> Message-ID: <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> On Jan 16, 2009, at 5:31 AM, shi dingan wrote: > void initexample() { > PyObject *m; > m = Py_InitModule("example", exampleMethods); > } > > When I try to import examplemodule, I obtain the following message: >>>> import examplemodule > Traceback (most recent call last): > File "", line 1, in ? > ImportError: dynamic module does not define init function > (initexamplemodule) Hi Marc, The tutorial says, "The initialization function must be named initname(), where name is the name of the module". The error message you got is very accurate: "module does not define init function (initexamplemodule)". Since your module is called "examplemodule", Python is looking for a function called "initexamplemodule". Change your build step to build a module called "example" and not "examplemodule" and I think you'll be OK. bye Philip From Jean-Paul.VALENTIN at ingenico.com Fri Jan 16 10:24:52 2009 From: Jean-Paul.VALENTIN at ingenico.com (Jean-Paul VALENTIN) Date: Fri, 16 Jan 2009 16:24:52 +0100 Subject: output problem Message-ID: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> Feature? the output of below Hello program he0.py started from command line looks as follows: F:\prompt>he0.py Hello F:\prompt> 'Hello' was sent with sys.stdout.write, so "without newline". But why cannot be output (more logically): F:\prompt>he0.py HelloF:\prompt> Is it normal? Is there any means or workaround to obtain that output if I wish?? ________________________________________________________________________ ______________________ #!/usr/bin/python #-*- coding: iso-8859-15 -*- import sys sys.stdout.write('Hello') About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. P Please consider the environment before printing this e-mail From andy.goldschmidt at forlinux.co.uk Fri Jan 16 10:25:24 2009 From: andy.goldschmidt at forlinux.co.uk (Andy Goldschmidt) Date: Fri, 16 Jan 2009 15:25:24 +0000 Subject: bubblefishymon Message-ID: <1232119524.6985.39.camel@andy-desktop> Hi Guys I am trying to get bubblefishymon to work as a gdesklet. (app is written in python) The app seems to work, but it does display any water. I'm assuming its because it cant poll the network card etc. If I try run it on the command line it shows this error : $ python __init__.py Traceback (most recent call last): File "__init__.py", line 3, in from sensor.Sensor import Sensor ImportError: No module named sensor.Sensor In the dekslets log it also shows this : Deprecation: Sensors are deprecated since v0.30. Please consider using controls and inline scripts. Does that mean Sensors is no longer used / supported ? If so , what do I use in place of it ? Please note, I don't know how to code in Python (yet!) so any help would be much appreciated. Regards Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcglec at free.fr Fri Jan 16 10:30:12 2009 From: marcglec at free.fr (marcglec at free.fr) Date: Fri, 16 Jan 2009 16:30:12 +0100 Subject: Problem using python C API In-Reply-To: <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> References: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> Message-ID: <1232119812.4970a80453395@imp.free.fr> Right, thx for your reply, I completely overlooked "examplemodule.so" in the building step. Maybe I should sleep more these days :) Btw, I've now an other problem with PyArg_ParseTuple but I guess it is better to post in the capi-sig mailing list. Thx again, Marc. > > On Jan 16, 2009, at 5:31 AM, shi dingan wrote: > > > void initexample() { > > PyObject *m; > > m = Py_InitModule("example", exampleMethods); > > } > > > > When I try to import examplemodule, I obtain the following message: > >>>> import examplemodule > > Traceback (most recent call last): > > File "", line 1, in ? > > ImportError: dynamic module does not define init function > > (initexamplemodule) > > Hi Marc, > The tutorial says, "The initialization function must be named > initname(), where name is the name of the module". The error message > you got is very accurate: "module does not define init function > (initexamplemodule)". Since your module is called "examplemodule", > Python is looking for a function called "initexamplemodule". > > Change your build step to build a module called "example" and not > "examplemodule" and I think you'll be OK. > > bye > Philip > > -- > http://mail.python.org/mailman/listinfo/python-list > From sturlamolden at yahoo.no Fri Jan 16 10:31:36 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 16 Jan 2009 07:31:36 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> Message-ID: <84364257-03ed-4503-9fce-e1bd44e6337d@g1g2000pra.googlegroups.com> On Jan 16, 8:39 am, Erik Max Francis wrote: > I was thinking of this as well when I saw his post. Inform 7 has some > interesting ideas, but I think the general problem with English-like > programming language systems is that once you get into the nitty gritty > details, you end up having to know exactly the right things to type, > which ultimately get just as complicated as a more traditional > programming language syntax. In the big picture I don't think it helps > much. After all, there's a reason that most modern programming > languages don't look like COBOL or AppleScript. COBOL looks like English to facilitate reading programs, not writing them. COBOL is for use in places where programs must be read and verified by possibly computer-illiterate personnel. E.g. in bank and finance where (at least in some countries) everything must be supervised and approved by professional accountants. COBOL is still the dominating language in that domain. From mrkafk at gmail.com Fri Jan 16 10:39:58 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 16:39:58 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. I for one would love to see at least compiler warning (optionally, error) for situation where attributes are added to self outside of __init__. I consider it generally evil and hate to see code like that. Regards, mk From jcd at sdf.lonestar.org Fri Jan 16 11:01:18 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 16 Jan 2009 11:01:18 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: <01804283$0$8693$c3e8da3@news.astraweb.com> References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1232121678.6007.4.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > > > Oh come on you lot - you are carrying on as if Diez were wearing his > > skull socks again - do me a favour and give him a break! > And... skull socks? Cool. Where can I get some? > > http://www.letmegooglethatforyou.com/search?q=skull+socks From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 11:15:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 16:15:49 GMT Subject: Skull Socks (was Re: Convention vs. fascism) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0180a93a$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: >> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: >> >> > Oh come on you lot - you are carrying on as if Diez were wearing his >> > skull socks again - do me a favour and give him a break! > >> And... skull socks? Cool. Where can I get some? >> >> >> > http://www.letmegooglethatforyou.com/search?q=skull+socks Not Found The requested URL /search was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. You know, it was just a throw-away comment to lighten the mood. I don't really need to see 18,000+ links to places that sell socks with skulls printed on them. On the other hand, if they were socks made from actual skulls, that would be something... -- Steven From venkat83 at gmail.com Fri Jan 16 11:16:13 2009 From: venkat83 at gmail.com (Venkatraman.S.) Date: Fri, 16 Jan 2009 08:16:13 -0800 (PST) Subject: Client Socket Connection to Java server References: Message-ID: <13b2fafc-2c27-435c-a287-1842aadd8223@n33g2000pri.googlegroups.com> Hint: Java sends a '\n' character at the end. From http Fri Jan 16 11:19:47 2009 From: http (Paul Rubin) Date: 16 Jan 2009 08:19:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xsknjp6jg.fsf@ruckus.brouhaha.com> mk writes: > I was flabbergasted to read that optional static typing was dropped by > Guido due to "lack of interest in community" IIRC. I don't remember that happening. PEP 3107 still lists type checking as a use case for Python 3.0 function annotations. From tjreedy at udel.edu Fri Jan 16 11:25:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:25:32 -0500 Subject: Integrating awk in Python In-Reply-To: <200901161334.28275.w.richert@gmx.net> References: <1232107379.25150.46.camel@king.imim.es> <200901161334.28275.w.richert@gmx.net> Message-ID: Willi Richert wrote: > Hi, > > take a look at the 5th link at http://tinyurl.com/7s8kfq > It's called pyawk. Stupid link wanting to set yet another useless cookie. Answer will not always be 5th. Just say 'Google pyawk' or better give link http://pyawk.sourceforge.net/ > Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: >> Hello, >> I'm developing a software package using python. I've programmed all >> necessary tools but I have to use other stuff from other people. Most of >> these external scripts are developed using awk. >> >> At the beggining I thought to "translate" them and program them in >> python but I prefer to avoid it because it means a lot of work and I >> should do it after each new version of this external stuff. I would like >> to integrate them into my python code. >> >> I know I can call them using the system environment but it is slower >> than if I call them inside the package. I know it is possible with C, do >> you have experience on integrate awk into python calling these awk >> scripts from python? From dotancohen at gmail.com Fri Jan 16 11:30:52 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 16 Jan 2009 18:30:52 +0200 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <880dece00901160830y5d068d90k2fe008c6f1b04b03@mail.gmail.com> 2009/1/16 The Music Guy : > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > This one is close: http://en.wikipedia.org/wiki/Brainfuck -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From speedup at gmail.com Fri Jan 16 11:41:21 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Fri, 16 Jan 2009 08:41:21 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? Message-ID: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Hi, I ran a few tests on the new Python 2.6 multiprocessing module before migrating a threading code, and found out the locking code is not working well. In this case, a pool of 5 processes is running, each trying to get the lock and releasing it after waiting 0.2 seconds (action is repeated twice). It looks like the multiprocessing lock allows multiple locking after the second pass. Running the exact same code with threads works correctly. Further down is the test code, output is great when running with threads (the sequence of lock/unlock looks good), but the output gets mixed up (mutliple locks in a row) when running with processes. My setup is : Mac OS X 10.5 running Python 2.6.1 from MacPython Did I do something wrong, or is there a limitation for multiprocessing locks that I am not aware of? Thank you for your help! -- Fred ------------------------------- #!/usr/bin/python # -*- coding: utf-8 -*- from multiprocessing import Process, Queue, Lock from Queue import Empty from threading import Thread import time class test_lock_process(object): def __init__(self, lock, id, queue): self.lock = lock self.id = id self.queue = queue self.read_lock() def read_lock(self): for i in xrange(2): self.lock.acquire() self.queue.put('[proc%d] Got lock' % self.id) time.sleep(.2) self.queue.put('[proc%d] Released lock' % self.id) self.lock.release() def test_lock(processes=10, lock=Lock(), process=True, queue=None): print_result = False if queue == None: print_result = True queue = Queue() threads = [] for i in xrange(processes): if process: threads.append(Process(target=test_lock_process, args=(lock,i,queue,))) else: threads.append(Thread(target=test_lock_process, args= (lock,i,queue,))) for t in threads: t.start() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == "__main__": #test_lock(processes=5, process=True) test_lock(processes=5) From tjreedy at udel.edu Fri Jan 16 11:42:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:42:51 -0500 Subject: mimetypes oddity In-Reply-To: References: Message-ID: Sion Arrowsmith wrote: > In article , > wrote: >> [mimetype weirdness reported] >> Sion> Is this a bug? >> Might be. Can you file a bug report in the Python issue tracker with a >> small script that demonstrates the behavior? > > http://bugs.python.org/issue4963 > > (It's tagged as being 2.4 and 2.5 because those are the versions I > have to hand to confirm it on, but I'd be rather surprised if it's > not still like this in 2.6.) Trying to reproduce a bug, as this report requires, is easier if you give code that can be copy and pasted into the interpreter or even into an edit window (as with IDLE) to be run from there. (3.0 version) import mimetypes print(mimetypes.guess_extension('image/jpeg')) mimetypes.init() print(mimetypes.guess_extension('image/jpeg')) From tjreedy at udel.edu Fri Jan 16 11:49:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:49:50 -0500 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: Eric Brunel wrote: > On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy wrote: >> Eric Brunel wrote: > [snip]>> And BTW, if this is actually a bug, where can I report it? >> >> bugs.python.org > > Thanks. I reported the problem. When you report that you reported to problem to the tracker (a good idea), please include link so anyone reading this thread can jump there to continue with followup there. From pruebauno at latinmail.com Fri Jan 16 11:54:22 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 16 Jan 2009 08:54:22 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <0c8c81f2-8a8d-4762-9a06-034a04506ebb@d36g2000prf.googlegroups.com> On Jan 15, 4:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. I am willing to bet a beer that the slow performance has nothing to do with the dict but is either because of MyClass or the read from disk. From lenz at joinville.udesc.br Fri Jan 16 12:01:57 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 09:01:57 -0800 Subject: multiprocessing question/error Message-ID: <200901160901.57232.lenz@joinville.udesc.br> Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code .... class Pygen3(self).... .... .... .... def calcula(self,indiv): .... .... .... def evaluate(self): .... .... indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From ianand0204 at gmail.com Fri Jan 16 12:02:08 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 16 Jan 2009 09:02:08 -0800 (PST) Subject: Beginner: Data type conversion question References: Message-ID: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> On Jan 15, 11:35?pm, Terry Reedy wrote: > flagg wrote: > > I am still fairly new to python and programming in general. ?My > > question is regardingdataconversion, I am working on a script that > > will edit dns zone files, one of the functions i wrote handles > > updating the serial number. > > Our zone files use the date as the first part of the serial and a two > > digit integer as the last two. > > > i.e. 2009011501. ?The next update would be 2009011502, etc > > Here is the function I wrote, I am using dnspython for reading in zone > > files as Zone "objects". ?Because dnspython's built-in serial updater > > will not work with how we format our serial's, I have to re-write it. > > > def checkSerial(): > > ? ? """ > > ? ? Checks the current 'date' portion of the serial number and > > ? ? checks the current 'counter'(the two digit number at the end of > > ? ? the serial number), then returns a complete new serial > > ? ? """ > > ? ? currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > ? ? for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ? date = str(rdata.serial)[0:8] > > ? ? ? ? inc = str(rdata.serial)[8:10] > > If rdate.serial is already a string, as name would imply, the str() call > is pointless. ?If not, can you get inc as int more directly? > > > > > ? ? if date == currentDate: > > ? ? ? ? int(inc) + 1 > > ? ? ? ? print inc > > ? ? ? ? newInc = str(inc).zfill(2) > > ? ? ? ? serial = date + newInc > > ? ? ? ? print "date is the same" > > ? ? ? ? return serial > > ? ? elif date < currentDate: > > ? ? ? ? newInc = "01".zfill(2) > > ? ? ? ? serial = currentDate + newInc > > ? ? ? ? print "date is different" > > ? ? ? ? return serial > > > Through all of this I am doing a lot ofdatatypeconversion. string - > >> integer, integer back to string, etc. ?Is this an efficient way of > > handling this? ?I have to perform basic addition on the "inc" > > variable, but also need to expose that value as a string. ? What I > > have above does work, but I can't help but think there is a more > > efficient way. I guess I am not used todatatypes being converted so > > easily. > > Other than that, you are perhaps worrying too much, even if code could > be squeezed more. ?The idea that every object knows how to convert > itself to a string representation is basic to Python. > > tjr Actually when i run a type(serial) on that variable it returns a "long" which i am not sure why dnspython uses a long variable to store the serial. But you could be right about me worrying to much. The other languages I have dabbled in (java, perl) I don't remember type conversion being as simple. But again I am still new, so don't quote me on that :) From Scott.Daniels at Acm.Org Fri Jan 16 12:07:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 16 Jan 2009 09:07:41 -0800 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > ... > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > ... -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. Nope, that generator expression is evaluated in your assignment. The expression x+(i*10) is evaluated at each step of the generator. > But is this the right behaviour? It is the defined behavior. For what you want: import itertools as it def count_from(base): for n in it.count(): yield n + base itlist = [count_from(n) for n in range(2)] --Scott David Daniels Scott.Daniels at Acm.Org From mrkafk at gmail.com Fri Jan 16 12:09:45 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 18:09:45 +0100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: Alfons Nonell-Canals wrote: > At the beggining I thought to "translate" them and program them in > python but I prefer to avoid it because it means a lot of work and I > should do it after each new version of this external stuff. I would like > to integrate them into my python code. That's kind of like retrofitting steam engine onto a Mach 2 jetfighter. Well there's always awk2c.. Regards, mk From ianand0204 at gmail.com Fri Jan 16 12:14:17 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 16 Jan 2009 09:14:17 -0800 (PST) Subject: Beginner: Data type conversion question References: <6tas4tF9v94eU1@mid.uni-berlin.de> Message-ID: <1ac249a8-80f6-4983-ae7d-70e8e6c8c6ac@i24g2000prf.googlegroups.com> On Jan 15, 11:43?pm, Marc 'BlackJack' Rintsch wrote: > On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote: > > def checkSerial(): > > ? ? """ > > ? ? Checks the current 'date' portion of the serial number and checks > > ? ? the current 'counter'(the two digit number at the end of the serial > > ? ? number), then returns a complete new serial """ > > ? ? currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > The format string can be written as *one* string literal instead of > three: "%Y%m%d". > > > ? ? for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ? date = str(rdata.serial)[0:8] > > ? ? ? ? inc = str(rdata.serial)[8:10] > > Here you are converting `rdata.serial` twice. > > ? ? ? ? ? tmp = str(rdata.serial) > ? ? ? ? ? date = tmp[0:8] > ? ? ? ? ? inc = int(tmp[8:10]) > > As `inc` is conceptually a number, you should do theconversionhere and > treat it as number from now on. > > > ? ? if date == currentDate: > > ? ? ? ? int(inc) + 1 > > ? ? ? ? print inc > > ? ? ? ? newInc = str(inc).zfill(2) > > ? ? ? ? serial = date + newInc > > ? ? ? ? print "date is the same" > > ? ? ? ? return serial > > ? ? elif date < currentDate: > > ? ? ? ? newInc = "01".zfill(2) > > ? ? ? ? serial = currentDate + newInc > > ? ? ? ? print "date is different" > > ? ? ? ? return serial > > Both branches do almost the same. ?You should try to avoid such code > duplication. > > ? ? ? if date == currentDate: > ? ? ? ? ? inc += 1 > ? ? ? elif date < currentDate: > ? ? ? ? ? inc = 1 > ? ? ? else: > ? ? ? ? ? assert False ? # Should never happen. > > ? ? ? return "%s%02d" % (date, inc) > > That's it. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch Ah return "%s%02d" % (date, inc) This piece is what I was missing in my original design. I couldn't figure out hot to take and integer and force it to my double digit. i.e. 01 instead of 1. Which is why I was using strings to make that happen. (obviously incorrectly). Thanks Could you explain what "assert" does in the if statement. I am assuming if the first two conditions are not met, it will hit "assert false" and exit the program? From alan.isaac at gmail.com Fri Jan 16 12:45:21 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 17:45:21 GMT Subject: Python 3: range objects cannot be sliced Message-ID: Is the behavior below expected? Documented? (The error msg is misleading.) Thanks, Alan Isaac >>> x = range(20) >>> s = slice(None,None,2) >>> x[s] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' From mario.ruggier at gmail.com Fri Jan 16 12:45:34 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Fri, 16 Jan 2009 09:45:34 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> Message-ID: <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> On Jan 16, 1:35?pm, ajaksu wrote: > On Jan 16, 5:09?am, mario ruggier wrote: > > > Laboriously doing all these > > checks on each expr eval will be very performance heavy, so I hope to > > be able to limit access to all these more efficiently. Suggestions? > > None regarding the general issue, a try:except to handle this one: > > '(x for x in ()).throw("bork")' What is the potential security risk with this one? To handle this and situations like the ones pointed out above on this thread, I will probably affect the following change to the evoque.evaluator.RestrictedEvaluator class, and that is to replace the 'if name.find("__")!=-1:' with an re.search... where the re is defined as: restricted = re.compile(r"|\.".join([ "__", "func_", "f_", "im_", "tb_", "gi_", "throw"])) and the test becomes simply: if restricted.search(name): All the above attempts will be blocked this way. Any other disallow- sub-strings to add to the list above? And thanks a lot Daniel, need to find a way to get somebeer over to ya... ;-) mario From google at mrabarnett.plus.com Fri Jan 16 12:59:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 17:59:48 +0000 Subject: Start multiple listening servers in one file In-Reply-To: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> References: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> Message-ID: <4970CB14.2010800@mrabarnett.plus.com> Thomas W wrote: > I`m working on a django-project where I`m using the awsome pyftpdlib > for ftpserver-functionality. I also have a simple worker deamon > running in the background, but not listening to any port. How can I > start all of these processes on one file? Tried using subprocess and > popen but that resulted in an eternal loop starting the servers over > and over until all resources were used, then crash. > > Any hint on how to do this would be highly appreciated. > Do you mean that your script is invoking itself? If yes, then could you pass something on the commandline to say "you're not the initial instance, so don't invoke yourself" and then check that? From fuzzyman at gmail.com Fri Jan 16 13:02:26 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 16 Jan 2009 10:02:26 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: <9a55e9b8-8b94-4762-87af-dbf753179b8d@v39g2000pro.googlegroups.com> On Jan 16, 5:45?pm, Alan G Isaac wrote: > Is the behavior below expected? Documented? > (The error msg is misleading.) > Thanks, > Alan Isaac > > ?>>> x = range(20) > ?>>> s = slice(None,None,2) > ?>>> x[s] > Traceback (most recent call last): > ? ?File "", line 1, in > TypeError: sequence index must be integer, not 'slice' Well, it has the same behaviour as the iterator returned by xrange in Python 2.X - so expected I guess. The error message is also the same in Python 2.X. Michael Foord -- http://www.ironpythoninaction.com/ From http Fri Jan 16 13:15:42 2009 From: http (Paul Rubin) Date: 16 Jan 2009 10:15:42 -0800 Subject: Python 3: range objects cannot be sliced References: Message-ID: <7xwscvp169.fsf@ruckus.brouhaha.com> Alan G Isaac writes: > >>> x = range(20) > >>> s = slice(None,None,2) > >>> x[s] > Traceback (most recent call last): > File "", line 1, in > TypeError: sequence index must be integer, not 'slice' range is an iterator now. Try itertools.islice. From http Fri Jan 16 13:17:59 2009 From: http (Paul Rubin) Date: 16 Jan 2009 10:17:59 -0800 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> Message-ID: <7xsknjp12g.fsf@ruckus.brouhaha.com> mario ruggier writes: > All the above attempts will be blocked this way. Any other disallow- > sub-strings to add to the list above? I think what you are trying to do is fundamentally hopeless. You might look at web.py (http://webpy.org) for another approach, that puts a complete interpreter for a Python-like language into the template engine. From invalid at invalid Fri Jan 16 13:22:13 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 16 Jan 2009 12:22:13 -0600 Subject: Integrating awk in Python References: <1232107379.25150.46.camel@king.imim.es> Message-ID: Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program > them in python but I prefer to avoid it because it means a lot > of work and I should do it after each new version of this > external stuff. I would like to integrate them into my python > code. > > I know I can call them using the system environment but it is > slower than if I call them inside the package. So you've tried system(), and it didn't meet your requirements? > I know it is possible with C, What is possible with C? > do you have experience on integrate awk into python calling > these awk scripts from python? Just like in C, you can call them directory using fork/exec to eliminate the shell spawned by system(), but the difference in time is probably going to be negligible. If you're not able to meet your timing requirements using os.system(), then I suspect it's the awk programs that are too slow. I'd probably use the subprocess module to avoid the shell for security reasons. First, get it working. Then, after you've established that the program isn't meeting the timing specification _measure_ where the time is going. It's silly trying optimize the part of the program that's only taking up 1% of the execution time. "Premature optimization..." -- Grant Edwards grante Yow! They collapsed at ... like nuns in the visi.com street ... they had no teen appeal! From MatthewBrown at gmail.com Fri Jan 16 13:33:03 2009 From: MatthewBrown at gmail.com (Matt Brown - nyc) Date: Fri, 16 Jan 2009 10:33:03 -0800 (PST) Subject: minidom, drilling down to a low node in one line? Message-ID: <3bb1ea6b-0387-4be8-9f60-fff059c5e500@v4g2000vbb.googlegroups.com> Hello, I hope this isn't completely redundant... I'm working with an example found of parsing XML with xml.dom.minidom and am having some issues getting a node down three levels. Here is the tutorial: http://diveintopython.org/xml_processing/parsing_xml.html Given the XML: _____________

0

1

_____________ How do I address the textNode.data that = 0? The only way I figured out is to recursively childNode from the parsed down (as following the guide). Is there no way to simply address the item by something along the lines of: _____________ xmldoc = minidom.parse("example.xml") xmldoc.getElementsByTagName("grammar:ref:p:") _____________ Any input or direction is appreciated. Thanks! Matt From alan.isaac at gmail.com Fri Jan 16 13:36:34 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 18:36:34 GMT Subject: Python 3: range objects cannot be sliced In-Reply-To: <7xwscvp169.fsf@ruckus.brouhaha.com> References: <7xwscvp169.fsf@ruckus.brouhaha.com> Message-ID: On 1/16/2009 1:15 PM Paul Rubin apparently wrote: > range is an iterator now. Try itertools.islice. Well yes, it behaves like xrange did. But (also like xrange) it supports indexing. (!) So why not slicing? I expected this (to keep it functionally more similar to the old range). Alan Isaac From lists at cheimes.de Fri Jan 16 13:57:47 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jan 2009 19:57:47 +0100 Subject: Python 3: range objects cannot be sliced In-Reply-To: References: <7xwscvp169.fsf@ruckus.brouhaha.com> Message-ID: Alan G Isaac schrieb: > On 1/16/2009 1:15 PM Paul Rubin apparently wrote: >> range is an iterator now. Try itertools.islice. > > Well yes, it behaves like xrange did. > But (also like xrange) it supports indexing. (!) > So why not slicing? > I expected this (to keep it functionally > more similar to the old range). The old range function returned a list. If you need the old functionality you can use list(range(...))[]. Why do you want to slice a range anyway? The range type supports a start, stop and step argument. Christian From Lie.1296 at gmail.com Fri Jan 16 14:18:10 2009 From: Lie.1296 at gmail.com (Lie) Date: Fri, 16 Jan 2009 11:18:10 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <117facb0-0e10-41d0-8ede-6aa207a7751d@g39g2000pri.googlegroups.com> On Jan 15, 1:34?pm, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this > > import urllib > import sys > > print "\n\n\t\tlipun4u[at]gmail[dot]com" > print "\t\t------------------------" > > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] > print appname > > if len(sys.argv) not in [2,3]: > ? ? print "Usage : " + appname + " [options]" > ? ? print "e.g. : " + appname + "www.google.com--verbose" > ? ? print "\n\t[option]" > ? ? print "\t\t--verbose/-V for verbose output" > ? ? print "\t\t-r for recursive scan" > ? ? sys.exit(1) > > site = appname.replace("http://","").rsplit("/",1)[0] > site = "http://" + site.lower() > print site > > It showed the required o/p in the IDLE > here is the o/p > > ? ? ? ? ? ? ? ? lipun4u[at]gmail[dot]com > ? ? ? ? ? ? ? ? ------------------------ > linkscan.py > Usage : linkscan.py [options] > e.g. : linkscan.pywww.google.com--verbose > > ? ? ? ? [option] > ? ? ? ? ? ? ? ? --verbose/-V for verbose output > ? ? ? ? ? ? ? ? -r for recursive scan > > Traceback (most recent call last): > ? File "I:/Python26/linkscan.py", line 18, in > ? ? sys.exit(1) > SystemExit: 1 > > But in command prompt the o/p is still faulty > > ? ? ? ? ? ? ? ? lipun4u[at]gmail[dot]com > ? ? ? ? ? ? ? ? ------------------------ > I:\Python26\linkscan.py > Usage : I:\Python26\linkscan.py [options] > e.g. : I:\Python26\linkscan.pywww.google.com--verbose > > ? ? ? ? [option] > ? ? ? ? ? ? ? ? --verbose/-V for verbose output > ? ? ? ? ? ? ? ? -r for recursive scan > > I:\Python26> > > regards > asit dhal Of course the pragmatic approach is just to include appname = 'linkscan.py' at the top of the document. I agree apppath might change (because you copied the program to different places, different bin directory on different machine), but there is no reason linkscan.py should change. And if you have to change the invoking name, sometimes it might be more useful for users to know the REAL name of the program (probably the user friendly version, e.g. "Link Scanner" or "Link Scanner 1.0"), instead of the name of the script it is run from (without the apppath). It is trivial for human user to guess where the script is located and what the appname is from the full apppath (path+name) From dragosmocrii at gmail.com Fri Jan 16 14:19:47 2009 From: dragosmocrii at gmail.com (Dragos) Date: Fri, 16 Jan 2009 11:19:47 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" Message-ID: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> I am trying to make a testing script to load/save cookies to a file with FileCookieJar, but it results in this error: FileCookieJar has not attribute "_self_load" This is my script: import urllib.request, urllib.parse,http.cookiejar url="http://localhost/test.php" cs=http.cookiejar.FileCookieJar() cs.load("cookies.txt",ignore_discard=False, ignore_expires=False) opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor (cs)) y=opener.open(url) print(y.read()) Thanks for helping. From mrkafk at gmail.com Fri Jan 16 14:26:54 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 20:26:54 +0100 Subject: Differences between class and function decorator Message-ID: Hello everyone, I rewrote an example someone posted here recently from: >>> def print_method_name(method): def new_meth(*args, **kwargs): print method.func_name return method(*args, **kwargs) return new_meth >>> @print_method_name def f2(): pass >>> f2() f2 ..to: >>> class MyMethod(object): def __init__(self, func): self.name = func.func_name self.func = func def __call__(self): print self.name return self.func >>> @MyMethod def f(): pass >>> f() f Note that function decorator returned None, while class decorator returned function. Why the difference in behavior? After all, print_method_name decorator also returns a function (well it's a new function but still a function)? Regards, mk From duncan.booth at invalid.invalid Fri Jan 16 14:38:21 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 19:38:21 GMT Subject: Differences between class and function decorator References: Message-ID: mk wrote: > Note that function decorator returned None, while class decorator > returned function. > > Why the difference in behavior? After all, print_method_name decorator > also returns a function (well it's a new function but still a function)? That would be because the function decorator returns the result of calling the function whereas your class decorator simply returns the function without calling it. From Russ.Paielli at gmail.com Fri Jan 16 14:44:46 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 16 Jan 2009 11:44:46 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> On Jan 16, 5:22 am, Steve Holden wrote: > Russ P. wrote: > > [...] > > > I spent *way* too much time on that post. I really need to quit > > spending my time refuting the baloney that passes for wisdom here. > > He who cannot ignore baloney is doomed to refute it. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ Yeah, and I should really learn to leave off those little zingers. If Mr. D weren't obviously an intelligent person and a Python expert, I wouldn't care what he writes. I just think that he, along with a few others here, love Python so much that they refuse to recognize its limitations. It's an easy trap to fall into. From gerald.britton at gmail.com Fri Jan 16 14:50:48 2009 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 16 Jan 2009 14:50:48 -0500 Subject: Lazy List Generator Problem Message-ID: <5d1a32000901161150y317fa2a2w605436effb10c791@mail.gmail.com> For those interested in the Sieve of Eratosthenes, have a look at: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf The examples in the paper are in Haskell, but I have been corresponding with the author who provided this Python version: def sieve(): innersieve = sieve() prevsquare = 1 table = {} i = 2 while True: if (table.has_key(i)): prime = table[i] del(table[i]) next = i+prime while next in table: next = next + prime table[next] = prime else: yield i if i > prevsquare: j = innersieve.next() prevsquare = j * j table[prevsquare] = j i = i + 1 Only of 65056 bytes (less than 1/16 MB) of heap is used when calculating the millionth prime. It is also very fast but can be even further optimized using a wheel as described in the paper. FWIW I was so intrigued I went off to learn Haskell just so I could follow the paper properly. From matthew at woodcraft.me.uk Fri Jan 16 14:53:46 2009 From: matthew at woodcraft.me.uk (Matthew Woodcraft) Date: Fri, 16 Jan 2009 19:53:46 GMT Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <87y6xb81th.fsf@golux.woodcraft.me.uk> Steve Holden writes: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. >> > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. I think it was a reasonable way for CP/M to work. It's a nice simple interface for reading and writing files: you always read and write from/to a fixed 128-byte buffer. Allowing files to be arbitrary-length byte sequences would have made the system calls more complicated, and it would also have needed another byte in the on-disk file control block (so 7.3 filenames rather than 8.3, or some other compromise). For CP/M programs, it's hard to see what the gain would have been; it's easy to design a binary file format so that it doesn't matter whether or not there's junk on the end, and CP/M didn't have a tradition of storing data in 'plain text' files (for good reasons of disk space). It certainly is a shame that we didn't leave all this behind when MS/DOS 2 appeared, though. -M- From has.temp3 at virgin.net Fri Jan 16 14:57:24 2009 From: has.temp3 at virgin.net (has) Date: Fri, 16 Jan 2009 11:57:24 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> Message-ID: <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> On 16 Jan, 05:42, Chris Rebert wrote: > On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy wrote: > > > > > Just out of curiousity, have there been any attempts to make a version > > of Python that looks like actual English text? > > [...] > Does the name "AppleScript" mean anything to you? ;-) [quoting myself on the subject] The big advantage of AppleScript syntax is that it makes it easy to get a broad idea of what an existing AppleScript does, even if you don't know the AppleScript language in particular or programming in general. The big disadvantage of AppleScript syntax is that it makes it very difficult to form an accurate understanding of how it actually does it. For example, is 'foo bar' a property name, a constant name, a command name, a command name followed by a property/constant/variable name, or something else again? With more conventional language syntaxes, you have the opposite situation: in order to make any sense at all of an existing script, you first have to learn to read the syntax and know some basic programming. OTOH, once you're past that initial hurdle, it's easier to understand exactly what makes it tick, e.g. x.foo_bar is a property name, :foo_bar is a constant, foo_bar() is a command, foo(bar) is a command name followed by a variable name, and so on. The upshot of this is that AppleScript has a lower barrier to entry but higher cost of use compared to other languages. It's a trade-off, but one that probably fits quite well with the needs of many AppleScripters, who write relatively small programs on an irregular basis. A high cost of entry will be harder to justify if you don't actually use the language very often. OTOH, if you write large programs on a daily basis then what matters most is long-term productivity, and you'll recoup the time taken to learn a language fairly quickly by comparison. ... If you really want an end-user language that has the legibility of already-familiar natural languages while retaining all the precision provided by traditional programming syntax and adding a lot of much- needed interactive help and guidance, I think the best approach would be to go with an 'intelligent' structure editor a-la Scratch or Alice, rather than 'dumb' character-based source code as found in Python, AppleScript, Inform-7, C, et-al. See: http://scratch.mit.edu/ http://www.alice.org/ If you eliminate the need for syntax to describe structure, you can present programs in whatever way suits users best - be it English words in coloured blocks, or traditional brackets and braces. Plus it becomes an awful lot easier to help and correct novice users as they put together their first programs - much as the original Mac GUI provided much better input guidance and error prevention over previous DOS-style command lines. HTH has -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net From 9qobl2n02 at sneakemail.com Fri Jan 16 15:04:12 2009 From: 9qobl2n02 at sneakemail.com (Michael Hoffman) Date: Fri, 16 Jan 2009 12:04:12 -0800 Subject: Finding the full path of an executable Message-ID: Is there a portable way to find the full path of a filename that would be called by os.execvp()? Thanks, Michael Hoffman From max at alcyone.com Fri Jan 16 15:07:03 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Jan 2009 12:07:03 -0800 Subject: English-like Python In-Reply-To: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: alex23 wrote: > On Jan 16, 5:39 pm, Erik Max Francis wrote: >> Inform 7 has some >> interesting ideas, but I think the general problem with English-like >> programming language systems is that once you get into the nitty gritty >> details, you end up having to know exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but not > so helpful for programming. > >> which ultimately get just as complicated as a more traditional >> programming language syntax. > > And much more verbose, as well. Agreed. I, too, am impressed with what the authors tried to do for Inform 7. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Laws are silent in time of war. -- Cicero From alan.isaac at gmail.com Fri Jan 16 15:13:00 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 20:13:00 GMT Subject: Python 3: range objects cannot be sliced In-Reply-To: References: Message-ID: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range From mrkafk at gmail.com Fri Jan 16 15:15:58 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 21:15:58 +0100 Subject: Class decorator with argument Message-ID: Hello, I wrote this class decorator with argument: >>> class ChangeDoc(object): def __init__(self, docstring): self.docstring = docstring def __call__(self, func): func.__doc__ = self.docstring return func It seems to work: >>> @ChangeDoc("bulba") def f(): pass >>> f.__doc__ 'bulba' Can someone please debug my reasoning if it's incorrect? 1. First, the decorator @ChangeDoc('bulba') instantiates with __init__(self, 'bulba'), to some class instance, let's call it _decor. 2. Then _decor's __call__ method is called with function f as argument, changing the docstring and returning the changed f object, like f = _decor(f) . Am I missing smth important / potentially useful in typical real-world applications in that picture? Regards, mk From alan.isaac at gmail.com Fri Jan 16 15:22:12 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 20:22:12 GMT Subject: tuple methods: documentation missing Message-ID: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range I see no mention of the tuple methods? Right after the paragraph "Most sequence types support the following operations." it seems appropriate to have one stating "Most sequence types support the following methods: index() and count()." Alan Isaac From mrkafk at gmail.com Fri Jan 16 15:27:03 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 21:27:03 +0100 Subject: *Advanced* Python book? Message-ID: Hello everyone, I looked for it I swear, but just can't find it. Most Python books seem to focus on examples of how to call functions from standard library. I don't need that, I have online Python documentation for that. I mean really advanced mental gymnastics, like gory details of how Python objects operate, how to exploit its dynamic capabilities, dos and donts with particular Python objects, advanced tricks, everything from chained decorators to metaprogramming. Dive Into Python comes closest to this ideal from what I have found, but still not far enough. Anybody found such holy grail? Regards, mk From clp2 at rebertia.com Fri Jan 16 15:35:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jan 2009 12:35:34 -0800 Subject: Class decorator with argument In-Reply-To: References: Message-ID: <50697b2c0901161235s23576a07l4979f07ebff7941f@mail.gmail.com> On Fri, Jan 16, 2009 at 12:15 PM, mk wrote: > Hello, > > I wrote this class decorator with argument: > >>>> class ChangeDoc(object): > def __init__(self, docstring): > self.docstring = docstring > def __call__(self, func): > func.__doc__ = self.docstring > return func > > It seems to work: > >>>> @ChangeDoc("bulba") > def f(): > pass > >>>> f.__doc__ > 'bulba' > > Can someone please debug my reasoning if it's incorrect? > > 1. First, the decorator @ChangeDoc('bulba') instantiates with __init__(self, > 'bulba'), to some class instance, let's call it _decor. > > 2. Then _decor's __call__ method is called with function f as argument, > changing the docstring and returning the changed f object, like f = > _decor(f) . Your reasoning is correct. > > Am I missing smth important / potentially useful in typical real-world > applications in that picture? You understand how it works, but apparently don't see its practical usefulness. Consider, for the sake of example, some class whose methods all must check that the provided login information is correct before performing their operation. Without decorators, the login-checking code would get repeated in every method. But we can avoid this by using decorators: def requires_login(meth): def replacement(self, username, password, *args, **kwargs): if not login_valid(username, password): raise ValueError("Incorrect login") return meth(self, *args, *kwargs) return replacement class RemoteAccount(object): @requires_login def show_file(self, filename): #implementation here... @requires_login def list_directory(self, dirname): #implementation here... Notice how we were able to eliminate the username and password parameter declarations and the 2 lines of irrelevant (from the POV of the individual methods) login-checking code from every method and put them in the decorator instead. All those saved lines add up to make the code more readable. Obviously this example is contrived, but it shows how decorators can help you to address cross-cutting concerns in Python. In practice, functions might have multiple, more complicated decorators applied to them, thus increasing the gain from using decorators. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From invalid at invalid Fri Jan 16 15:44:33 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 16 Jan 2009 14:44:33 -0600 Subject: Finding the full path of an executable References: Message-ID: On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: > Is there a portable way to find the full path of a filename that would > be called by os.execvp()? Yes. Use os.path.abspath() on the name before you call it with os.execvp() -- Grant Edwards grante Yow! ! The land of the at rising SONY!! visi.com From jeanclaudearbaut at orange.fr Fri Jan 16 15:53:19 2009 From: jeanclaudearbaut at orange.fr (Jean-Claude Arbaut) Date: Fri, 16 Jan 2009 21:53:19 +0100 Subject: *Advanced* Python book? In-Reply-To: References: Message-ID: <4970f3bf$0$9393$ba4acef3@news.orange.fr> mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. IMHO, you don't need an advanced *python* book. If you know the documentation and basic tutorials, then you know enough python to write almost anything you may need. The exception may be, again IMO: - tkinter, that will need some more work, - and C extensions, that are made easier by SWIG. But I think these topics are adressed by books you already found too simple. What you need next is: - read code that do something interesting, for example here http://www.ics.uci.edu/~eppstein/PADS/ or in python sources (or find projects on sourceforge, etc.) - find a book on advanced *what you want to do* There are good books on programming, like TAOCP or CLRS, but it's not necessarily what you are looking for. You may also find material in university CS sites: there is sometimes cool stuff. Start with MIT OCW if you want to try this. The real question is: what do you want to do with your python ? And don't forget to check with google if someone has already had the same idea in the same language, such things happen ;-) The "filetype:pdf" trick may help ! > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. > Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. I was about to tell you about it :-) > Anybody found such holy grail? 'never found a better grail than source code :-) From steve at holdenweb.com Fri Jan 16 16:41:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 16:41:02 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: <0180a93a$0$8693$c3e8da3@news.astraweb.com> References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> <0180a93a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > >> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: >>> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: >>> >>>> Oh come on you lot - you are carrying on as if Diez were wearing his >>>> skull socks again - do me a favour and give him a break! >>> And... skull socks? Cool. Where can I get some? >>> >>> >>> >> http://www.letmegooglethatforyou.com/search?q=skull+socks > > Not Found > The requested URL /search was not found on this server. > Additionally, a 404 Not Found error was encountered while trying to use > an ErrorDocument to handle the request. > > > > You know, it was just a throw-away comment to lighten the mood. I don't > really need to see 18,000+ links to places that sell socks with skulls > printed on them. > > On the other hand, if they were socks made from actual skulls, that would > be something... > Of course Cliff actually meant http://letmegooglethatforyou.com/?q=skull+socks Jokes are never as funny when they go wrong :) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Fri Jan 16 17:07:03 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 22:07:03 +0000 Subject: Incorrect title case? Message-ID: <49710507.6060207@mrabarnett.plus.com> Python 2.6.1 I've just found that the following 4 Unicode characters/codepoints don't behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). For example, u"\u01C5".istitle() returns True and unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() returns u'\u01C4', which is the uppercase equivalent. Are these mistakes in the Unicode database? From cs at zip.com.au Fri Jan 16 17:18:55 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 17 Jan 2009 09:18:55 +1100 Subject: spam on the list - how are things now? In-Reply-To: <001101c977b3$a9b91460$0d00a8c0@hendrik> Message-ID: <20090116221855.GA2253@cskk.homeip.net> On 16Jan2009 10:22, Hendrik van Rooyen wrote: | I read this solely via the mailing list - and Yes, whatever was done has helped | a lot. I use the mailing list. The spam is mch reduced. Thanks! -- Cameron Simpson DoD#743 From http Fri Jan 16 17:25:56 2009 From: http (Paul Rubin) Date: 16 Jan 2009 14:25:56 -0800 Subject: *Advanced* Python book? References: Message-ID: <7xprimsxaj.fsf@ruckus.brouhaha.com> mk writes: > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos > and donts with particular Python objects, advanced tricks, everything > from chained decorators to metaprogramming. Dive Into Python comes > closest to this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? The favorite ones around here are "Python Cookbook" and "Python in a Nutshell", both by Alex Martelli, who used to be a newsgroup regular and still stops by from time to time. From sandro at e-den.it Fri Jan 16 17:51:54 2009 From: sandro at e-den.it (Sandro Dentella) Date: Fri, 16 Jan 2009 22:51:54 GMT Subject: [ANN] sqlkit 0.8.5 Message-ID: I'm pleased to announce rel 0.8.5 of sqlkit, that adds many improvements. In this release localization has been added. I'd be very pleased if someone would like to contribute localization file for any language (but italian). Changes in this release: sqlkit 0.8.5 - 16.1.09 * localization: added localization for numbers and dates added localization for messages -- now waiting for translations ;-) -- * table: - added a smart way to automatically set dimentions of the table based on info retrieved from the database (thanks to Pietro Battiston) - complete rewrite of the column setup function - added a basic multiline cellRenderer - grately improved the navigation with Tab that now correctly triggers validation/completion * fields: many improvements in clean_value/validation * mask: - added handling of comments - fixed integer/float miniwiget (0 was rendered as '') - text now uses gtk.WRAP_WORD - fixed current_idx was a class attribute not an instance attr * layout: added check and hints on errors for Panes widgets * django_syntax: fix in typo * filters: fixed handlung of boolena & NULL check in related tables * signals: - record_selected -> record-selected to follow gtk standard - added records-displayed * widgets/layout: added label_map support * sqlwidget: rationalized menu entries The package ----------- SQLkit PyGtk package provides Mask and Table widgets to edit database data. It's meant as a base for database desktop applications. The application --------------- It also provides 'sqledit' a PyGTK application based on sqlkit that can be used from command line to browse and edit data. The package has 2 very rich demo suites for sql widgets (the main one in sqlkit/demo/sql/demo.py) and for layout creation Main features of sqlkit: ------------------------ * editor of databases in 2 modes: table & mask * based on sqlalchemy: can cope with many different databases * very powerfull filtering capabilities: - each field can be used to filter records - filter may span relationship - date filtering possible also on relative basis (good for saved queries) * completion on all text field and foreign keys * very easy way to draw a layout for mask views * completely effortless editing of relationships * very easy way to set defaults * possibility to display totals of numeric fields * any possible sql constraint can be attached to a Mask or a Table. It can be expressed a s a normal sqlalchemy query or with django-like syntax * sqledit: python script to edit db Sqlkit is based on: ------------------- * python (>= 2.4) * PyGtk * Sqlalchemy (>= 0.5) * glade * dateutils Dowload & more: --------------- * http://docs.argolinux.org/sqlkit/sqlkit/download.html * hg clone http://hg.argolinux.org/py/sqlkit * google group: http://groups.google.it/group/sqlkit/ * License: GNU GPL -- Sandro Dentella *:-) http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy From lawsonhanson at optusnet.com.au Fri Jan 16 18:03:51 2009 From: lawsonhanson at optusnet.com.au (Lawson Hanson) Date: Sat, 17 Jan 2009 10:03:51 +1100 Subject: dynamic module import? Message-ID: <49711259$0$23396$afc38c87@news.optusnet.com.au> Is it possible to import a module of Python code where I do not know the name of the module until run-time? The Python statement: from someModule import * requires that "someModule" be the name of the module, but what I would like is to be able to define a value for "someModule" ... and provided that such a module exists (in an extended "sys.path" directory), then import from the specified module at run-time If I have a module called "dummy.py" in my own "myModules" directory (just below my HOME directory in Linux) If I do this: import os, sys myModDir = os.environ["HOME"] + "/myModules" sys.path.append(myModDir) modName = "%s/%s" % (myModDir, "dummy") from modName import * I get the following error: ImportError: No module named modName So is there any way to get Python to import the named module without just doing "from dummy import *", because I will not know that the user wants to use the "dummy" module until run-time ... I'm trying to import control data for different run scenarios which will be defined in differently named Python modules which the user will specify at run-time with a command-line option And help with this would be most appreciated Best regards, Lawson Hanson ------ Melbourne, Victoria, Australia From ajaksu at gmail.com Fri Jan 16 18:04:33 2009 From: ajaksu at gmail.com (ajaksu) Date: Fri, 16 Jan 2009 15:04:33 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> Message-ID: <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> On Jan 16, 3:45?pm, mario ruggier wrote: > > '(x for x in ()).throw("bork")' > > What is the potential security risk with this one? I don't see a concrete issue, just found it tempting... raising hand- crafted objects :) > All the above attempts will be blocked this way. Any other disallow- > sub-strings to add to the list above? None that I know of, but I suggest testing with dir, globals, locals and '__' enabled (which I haven't done yet), as spotting possible flaws should be easier. If you can get BOM+encoded garbage tested (see http://tinyurl.com/72d98y ), it might be worth it too. This one fails in lots of interesting ways when you juggle keyword- args around: exprs = [ 'evoque("hmm", filters=[unicode.upper ] ,src="/etc/python2.5/ site.py")', ] > And thanks a lot Daniel, need to find a way to get somebeer over to > ya... ;-) You're welcome! Don't worry about the beer, I'd only consider a real promise if it involved chocolate :D Regards, Daniel From clp2 at rebertia.com Fri Jan 16 18:25:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jan 2009 15:25:38 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <50697b2c0901161525v15a79a19l5ea6f9deb7790d0c@mail.gmail.com> On Fri, Jan 16, 2009 at 3:03 PM, Lawson Hanson wrote: > Is it possible to import a module of Python code > where I do not know the name of the module > until run-time? Yes. Use the __import__() built-in function. See http://docs.python.org/library/functions.html#__import__ for details. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Fri Jan 16 18:44:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 18:44:16 -0500 Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: Alan G Isaac wrote: > http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range > > I see no mention of the tuple methods? > > Right after the paragraph > "Most sequence types support the following operations." > it seems appropriate to have one stating > "Most sequence types support the following methods: index() and count()." I addressed this and related issues in http://bugs.python.org/issue4966 Terry Jan Reedy From jnews at julius-net.net Fri Jan 16 18:47:47 2009 From: jnews at julius-net.net (Matthias Julius) Date: Fri, 16 Jan 2009 18:47:47 -0500 Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <87wscuu82k.fsf@julius-net.net> Per Freem writes: > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so > my_dict[elt] works well. the __repr__ and __hash__ methods of my > class simply return str() representation of self, which just calls __str__(). I guess you are aware of that but you could call self.__str__() directly. Maybe that saves something when you do that 10 million times. > while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) Maybe it would be faster to numerically combine the three fields instead of hashing the string representation. Matthias From akshayubhat at gmail.com Fri Jan 16 19:05:13 2009 From: akshayubhat at gmail.com (akshay bhat) Date: Fri, 16 Jan 2009 16:05:13 -0800 (PST) Subject: Need help with os.system in linux Message-ID: Hello i am calling a program using os.system in python on Linux. However in i found that program being executed and soon returned 256. but when i ran it using terminal i got proper results. Now in case of windows, python waits till the process is finished, Can you please tell me how to implement this in linux? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 19:13:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 00:13:49 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <01811941$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 21:34:01 -0800, Eduardo Lenz wrote: > modu = "os" > exec("from " + modu + " import *") "from module import *" is generally frowned upon, although it does occasionally have its uses. By the way, I think your computer's clock is set wrong. My newsclient is reporting that you sent your post at 4:30pm today -- and I'm writing this at 11am. Perhaps your timezone is set wrong? Regards, -- Steven From gert.cuykens at gmail.com Fri Jan 16 19:14:19 2009 From: gert.cuykens at gmail.com (gert) Date: Fri, 16 Jan 2009 16:14:19 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> Message-ID: <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> On Jan 16, 7:08?am, "Martin v. L?wis" wrote: > > ?s = urandom(10).encode('hex') > > > ?AttributeError: 'bytes' object has no attribute 'encode' > > py> binascii.hexlify(os.urandom(10)) > b'92b91d5734a9fe562f23' > sqlite3 s = hexlify(urandom(10)) db.execute('SELECT sid FROM sessions WHERE sid=?',(s)) ('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d') [error] Incorrect number of bindings supplied. The current statement uses 1, and there are 20 supplied. ??? From catphive at catphive.net Fri Jan 16 19:37:39 2009 From: catphive at catphive.net (Brendan Miller) Date: Fri, 16 Jan 2009 16:37:39 -0800 Subject: what's the point of rpython? Message-ID: So I kind of wanted to ask this question on the pypy mailing list.. but there's only a pypy-dev list, and I don't want to put noise on the dev list. What's the point of RPython? By this, I don't mean "What is RPython"? I get that. I mean, why? The goals of the pypy project seems to be to create a fast python implementation. I may be wrong about this, as the goals seem a little amorphous if you look at their home page. So, to do that this RPython compiler was created? Except that it doesn't compile python, it compiles a static subset of python that has type inference like ML. This RPython thing seems like a totally unnecessary intermediate step. Instead of writing an implementation of one language, there's an implementation of two languages. Actually, it seems like it harms the ultimate goal. For the interpreted pyton to be fast, the interpreter has to be written in a reasonably fast language. ML, and C++ compilers have had a lot of work put into their optimization steps. A lot of the performance boost you get from a static language is that knowing the types at compile time lets you inline code like crazy, unroll loops, and even execute code at compile time. RPython is a statically typed language because I guess the developers associate static languages with speed? Except that they use it to generate C code, which throws away the type information they need to get the speed increase. Huh? I thought the goal was to write a fast dynamic language, not a slow static one? Is this going anywhere or is this just architecture astronautics? The RPython project seems kind of interseting to me and I'd like to see more python implementations, but looking at the project I can't help but think that they haven't really explained *why* they are doing the things they are doing. Anyway, I can tell this is the sort of question that some people will interpret as rude. Asking hard questions is never polite, but it is always necessary :) Thanks, Brendan From gnewsg at gmail.com Fri Jan 16 19:47:52 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 16:47:52 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x Message-ID: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Hi, I'm sure the message I'm going to write will seem quite dumb to most people but I really don't understand the str/bytes/unicode differences introduced in Python 3.0 so be patient. What I'm trying to do is porting pyftpdlib to Python 3.x. I don't want to support Unicode. I don't want pyftpdlib for py 3k to do anything new or different. I just want it to behave exactly the same as in the 2.x version and I'd like to know if that's possible with Python 3.x. Now. The basic difference is that socket.recv() returns a bytes object instead of a string object and that's the thing which confuses me mainly. My question is: is there a way to convert that bytes object into exactly *the same thing* returned by socket.recv() in Python 2.x (a string)? I know I can do: data = socket.recv(1024) data = data.decode(encoding) ...to convert bytes into a string but that's not exactly the same thing. In Python 2.x I didn't have to care about the encoding. What socket.recv() returned was just a string. That was all. Now doing something like b''.decode(encoding) puts me in serious troubles since that can raise an exception in case client and server use a different encoding. As far as I've understood the basic difference I see now is that a Python 2.x based FTP server could handle a 3.x based FTP client using "latin1" encoding or "utf-8" or anything else while with Python 3.x I'm forced to tell my server which encoding to use and I don't know how to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib From gert.cuykens at gmail.com Fri Jan 16 19:54:40 2009 From: gert.cuykens at gmail.com (gert) Date: Fri, 16 Jan 2009 16:54:40 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> Message-ID: <3c3f5984-0cb1-4be7-a548-08b9e34f06d4@g3g2000pre.googlegroups.com> On Jan 17, 1:14?am, gert wrote: > On Jan 16, 7:08?am, "Martin v. L?wis" wrote: > > > > ?s = urandom(10).encode('hex') > > > > ?AttributeError: 'bytes' object has no attribute 'encode' > > > py> binascii.hexlify(os.urandom(10)) > > b'92b91d5734a9fe562f23' > > sqlite3 > > ?s = hexlify(urandom(10)) > ?db.execute('SELECT sid FROM sessions WHERE sid=?',(s)) > > ('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d') > [error] Incorrect number of bindings supplied. The current statement > uses 1, and there are 20 supplied. > > ??? db.execute('SELECT sid FROM sessions WHERE sid=?',(s,)) This works ? Is this the new way to create a list in Python3.0 ? s=('test',) From luismgz at gmail.com Fri Jan 16 19:58:30 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 16 Jan 2009 16:58:30 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <90026f1a-be97-408b-aae4-416aa5f56df9@v42g2000yqj.googlegroups.com> On Jan 16, 9:37?pm, "Brendan Miller" wrote: > So I kind of wanted to ask this question on the pypy mailing list.. > but there's only a pypy-dev list, and I don't want to put noise on the > dev list. > > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? > > The goals of the pypy project seems to be to create a fast python > implementation. I may be wrong about this, as the goals seem a little > amorphous if you look at their home page. > > So, to do that this RPython compiler was created? Except that it > doesn't compile python, it compiles a static subset of python that has > type inference like ML. > > This RPython thing seems like a totally unnecessary intermediate step. > Instead of writing an implementation of one language, there's an > implementation of two languages. > > Actually, it seems like it harms the ultimate goal. For the > interpreted pyton to be fast, the interpreter has to be written in a > reasonably fast language. ML, and C++ compilers have had a lot of work > put into their optimization steps. A lot of the performance boost you > get from a static language is that knowing the types at compile time > lets you inline code like crazy, unroll loops, and even execute code > at compile time. > > RPython is a statically typed language because I guess the developers > associate static languages with speed? Except that they use it to > generate C code, which throws away the type information they need to > get the speed increase. Huh? I thought the goal was to write a fast > dynamic language, not a slow static one? > > Is this going anywhere or is this just architecture astronautics? > > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. > > Anyway, I can tell this is the sort of question that some people will > interpret as rude. Asking hard questions is never polite, but it is > always necessary :) > > Thanks, > Brendan Check out this thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1a8c866b4c4d7521/2174f796cd687931?lnk=gst&q=enlighten+pypy#2174f796cd687931 One of pypy's goals is having a more flexible implementation, easier to experiment with than cpython. Having all written in the same language facilitates this task. Why Rpython? Because by avoiding the dinamicity of the whole python language, it is possible to translate this code to a static one (c, java, whatever). The translated rpython interpreter aims to be something similar in performance to cpython. The only difference is that cpython was written from scratch in c, while pypy's interpreter was written in rpython and then translated automatically to c. The pypy team intends to achieve greater speed and performance by adding a JIT compiler to this interpreter. So pypy-c + JIT = faster python. I hope this helps... Luis From pythonnutter at gmail.com Fri Jan 16 20:01:57 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Sat, 17 Jan 2009 12:01:57 +1100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: If you or anyone who reads the thread is interested in using Python in an advanced way you use generators and build processing chains that will take the performance of Python to the edge and even give old AWK a run for its money for certain types of processing. Python: wwwlog = open("access-log") bytecolumn = (line.rsplit(None,1)[1] for line in wwwlog) bytes = (int(x) for x in bytecolumn if x != '-') print "Total", sum(bytes) Python execution time: 25.96 seconds AWK: % awk '{ total += $NF } END { print total }' big-access-log AWK execution time: 37.33 seconds With generators you can plug in filters at any stage: lines = lines_from_dir("big-access-log",".") lines = (line for line in lines if 'robots.txt' in line) log = apache_log(lines) addrs = set(r['host'] for r in log)the beauty of generators is that you can plug ?lters in at almost any stage The second line increased the execution time of a 1.3GB log file. Without it the execution was shameful at 53 minutes With the second line added execution time was 93 seconds David Beazley presented a great talk and accompanying PDF at PyCon'2008. It would be great if these generator tricks / patterns came more to the focus of the commuinity. Link if interested: http://www.dabeaz.com/generators/Generators.pdf 2009/1/16 Alfons Nonell-Canals : > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program them in python > but I prefer to avoid it because it means a lot of work and I should do it > after each new version of this external stuff. I would like to integrate > them into my python code. > > I know I can call them using the system environment but it is slower than if > I call them inside the package. I know it is possible with C, do you have > experience on integrate awk into python calling these awk scripts from > python? > > Thanks in advance! > > Regards, > Alfons. > > > -- > ------------ > Alfons Nonell-Canals, PhD > Chemogenomics Lab > Research Group on Biomedical Informatics (GRIB) - IMIM/UPF > Barcelona Biomedical Research Park (PRBB) > C/ Doctor Aiguader, 88 - 08003 Barcelona > alfons.nonell at upf.edu - http://cgl.imim.es > Tel. +34933160528 > > http://alfons.elmeuportal.cat > http://www.selenocisteina.info > > -- > http://mail.python.org/mailman/listinfo/python-list > > From http Fri Jan 16 20:03:32 2009 From: http (Paul Rubin) Date: 16 Jan 2009 17:03:32 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> <3c3f5984-0cb1-4be7-a548-08b9e34f06d4@g3g2000pre.googlegroups.com> Message-ID: <7xy6xaagm3.fsf@ruckus.brouhaha.com> gert writes: > Is this the new way to create a list in Python3.0 ? > s=('test',) That is a 1-tuple in both 2.x and 3.0. For a list, you'd say s = ['test'] From andrew at acooke.org Fri Jan 16 20:06:21 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 17:06:21 -0800 (PST) Subject: ABCs, functions, and __call__ (Python3) Message-ID: I think I'm missing something obvious here, so apologies in advance. I'd like to be able to test whether something is a function or implements __call__. Now obviously I can do that as two separate tests, but I though this was what ABCs were for. However, for the life of me I cannot find what the correct ABC would be. Does it exist? Is there some other, more traditional approach I should be using? Or do I have to roll my own somehow? Thanks for any guidance, Andrew From 9qobl2n02 at sneakemail.com Fri Jan 16 20:08:27 2009 From: 9qobl2n02 at sneakemail.com (Michael Hoffman) Date: Fri, 16 Jan 2009 17:08:27 -0800 Subject: Finding the full path of an executable In-Reply-To: References: Message-ID: Unknown wrote: > On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >> Is there a portable way to find the full path of a filename that would >> be called by os.execvp()? > > Yes. Use os.path.abspath() on the name before you call it with > os.execvp() That doesn't work: Python 2.5.2 (r252:60911, Sep 23 2008, 19:04:15) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath("echo") '/net/noble/vol2/home/mmh1/echo' >>> os.execvp(os.path.abspath("echo"), ["echo", "spam"]) Traceback (most recent call last): File "", line 1, in File "/net/noble/vol2/home/mmh1/arch/Linux-i386/opt/python-2.5.2/lib/python2.5/os.py", line 353, in execvp _execvpe(file, args) File "/net/noble/vol2/home/mmh1/arch/Linux-i386/opt/python-2.5.2/lib/python2.5/os.py", line 377, in _execvpe func(file, *argrest) OSError: [Errno 2] No such file or directory >>> os.execvp("echo", ["echo", "spam"]) spam The correct answer would be "/bin/echo" but abspath("echo") is just going to give me /echo. I need something that will search through the PATH like execvp() would. I can do it myself, but I'm surprised that such a feature is not already readily available somewhere. Michael From lists at cheimes.de Fri Jan 16 20:10:42 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:10:42 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: Giampaolo Rodola' schrieb: > Now. The basic difference is that socket.recv() returns a bytes object > instead of a string object and that's the thing which confuses me > mainly. > My question is: is there a way to convert that bytes object into > exactly *the same thing* returned by socket.recv() in Python 2.x (a > string)? Python 3.0's bytes type is almost the same type as Python 2.x's str type. During the development of Python 3.0 the old str type was modified and renamed to bytes. The old unicode type is now known as str. 2.x -> 3.0 ----------------- str -> bytes unicode -> str "" -> b"" u"" -> "" HTH Christian From andrew at acooke.org Fri Jan 16 20:11:07 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 17:11:07 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: <8e2af1ae-9d30-466d-889e-22526fd00ec1@e6g2000vbe.googlegroups.com> not direct answers, but.... reading through the recipes can be interesting - http://code.activestate.com/recipes/langs/python/ also, reading any good computing book and then wondering how you can do that in python can help shed a new light on things. andrew From tjreedy at udel.edu Fri Jan 16 20:11:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:11:44 -0500 Subject: Class decorator with argument In-Reply-To: References: Message-ID: mk wrote: > Hello, > > I wrote this class decorator with argument: The following is a *function* decorator, with the twist of being an instance of a user class rather than of the built-in function class (one I had not thought of). A class decorator would be a callable the modifies or wraps a *class*. > >>> class ChangeDoc(object): > def __init__(self, docstring): > self.docstring = docstring > def __call__(self, func): > func.__doc__ = self.docstring > return func > > It seems to work: > > >>> @ChangeDoc("bulba") > def f(): > pass > > >>> f.__doc__ > 'bulba' > > Can someone please debug my reasoning if it's incorrect? > > 1. First, the decorator @ChangeDoc('bulba') instantiates with > __init__(self, 'bulba'), to some class instance, let's call it _decor. > > 2. Then _decor's __call__ method is called with function f as argument, > changing the docstring and returning the changed f object, like f = > _decor(f) . > > Am I missing smth important / potentially useful in typical real-world > applications in that picture? From lists at cheimes.de Fri Jan 16 20:13:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:13:58 +0100 Subject: ABCs, functions, and __call__ (Python3) In-Reply-To: References: Message-ID: andrew cooke schrieb: > I think I'm missing something obvious here, so apologies in advance. > > I'd like to be able to test whether something is a function or > implements __call__. Now obviously I can do that as two separate > tests, but I though this was what ABCs were for. However, for the > life of me I cannot find what the correct ABC would be. Does it > exist? Is there some other, more traditional approach I should be > using? Or do I have to roll my own somehow? There is no ABC for this particular check. Any callable in Python 3.0 has a "__call__" attribute. In order to distinguish functions from callable you can use the inspect module, in particular inspect.isfunction(), inspect.ismethod() and inspect.isbuiltin(). Christian From mccredie at gmail.com Fri Jan 16 20:16:15 2009 From: mccredie at gmail.com (Matimus) Date: Fri, 16 Jan 2009 17:16:15 -0800 (PST) Subject: what's the point of rpython? References: mailman.7414.1232153035.3487.python-list@python.org Message-ID: The goals are listed here: http://codespeak.net/pypy/dist/pypy/doc/architecture.html Speed is mentioned, but as a secondary concern. The main goal seems to be to create a vehicle into exploring the concept of dynamic languages themselves. If that seems amorphous then it is because it is a research project. Matt From luismgz at gmail.com Fri Jan 16 20:19:32 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 16 Jan 2009 17:19:32 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: On Jan 15, 6:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. How about this?: for line in file: elt = MyClass(line) my_dict[elt] = my_dict.get(elt, 0) + 1 ... From google at mrabarnett.plus.com Fri Jan 16 20:24:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 01:24:04 +0000 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: <49713334.6030903@mrabarnett.plus.com> Giampaolo Rodola' wrote: > Hi, I'm sure the message I'm going to write will seem quite dumb to > most people but I really don't understand the str/bytes/unicode > differences introduced in Python 3.0 so be patient. What I'm trying > to do is porting pyftpdlib to Python 3.x. I don't want to support > Unicode. I don't want pyftpdlib for py 3k to do anything new or > different. I just want it to behave exactly the same as in the 2.x > version and I'd like to know if that's possible with Python 3.x. > > Now. The basic difference is that socket.recv() returns a bytes > object instead of a string object and that's the thing which confuses > me mainly. My question is: is there a way to convert that bytes > object into exactly *the same thing* returned by socket.recv() in > Python 2.x (a string)? > > I know I can do: > > data = socket.recv(1024) > data = data.decode(encoding) > > ...to convert bytes into a string but that's not exactly the same > thing. In Python 2.x I didn't have to care about the encoding. What > socket.recv() returned was just a string. That was all. Now doing > something like b''.decode(encoding) puts me in serious troubles since > that can raise an exception in case client and server use a different > encoding. > > As far as I've understood the basic difference I see now is that a > Python 2.x based FTP server could handle a 3.x based FTP client using > "latin1" encoding or "utf-8" or anything else while with Python 3.x > I'm forced to tell my server which encoding to use and I don't know > how to deal with that. > Originally Python had a single string type 'str' with 8 bits per character. That was a bit limiting for international use. Then a new string type 'unicode' was introduced. Now, in Python 3.x, it's time to tidy things up. The 'str' type has been renamed 'bytes' and the 'unicode' type has been renamed 'str'. If you're truly working with strings of _characters_ then 'str' is what you need, but if you're working with strings of _bytes_ then 'bytes' is what you need. socket.send() and socket.recv() are still the same, it's just that it's now clearer that they work with bytes and not strings. From grante at visi.com Fri Jan 16 20:25:49 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 16 Jan 2009 19:25:49 -0600 Subject: Finding the full path of an executable References: Message-ID: On 2009-01-17, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: > Unknown wrote: >> On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >>> Is there a portable way to find the full path of a filename that would >>> be called by os.execvp()? >> >> Yes. Use os.path.abspath() on the name before you call it with >> os.execvp() > > That doesn't work: [...] > The correct answer would be "/bin/echo" but abspath("echo") is just > going to give me /echo. My mistake. I thought you had a relative path to the program. > I need something that will search through the PATH like > execvp() would. I can do it myself, but I'm surprised that > such a feature is not already readily available somewhere. Since there are system calls that search the PATH, applications don't generally have to do it. There is a pretty standard Unix utility called "which" that does it: >>> os.popen("which %s" % "echo").read().strip() '/bin/echo' If you want to avoid using the external "which", here's a recipe: http://code.activestate.com/recipes/52224/ -- From tjreedy at udel.edu Fri Jan 16 20:27:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:27:45 -0500 Subject: Differences between class and function decorator In-Reply-To: References: Message-ID: mk wrote: > Hello everyone, > > I rewrote an example someone posted here recently from: > > >>> def print_method_name(method): > def new_meth(*args, **kwargs): > print method.func_name > return method(*args, **kwargs) > return new_meth > > >>> @print_method_name > def f2(): > pass > > >>> f2() > f2 > > > ..to: > > >>> class MyMethod(object): > def __init__(self, func): > self.name = func.func_name > self.func = func > def __call__(self): > print self.name > return self.func > > > >>> @MyMethod > def f(): > pass > > >>> f() > f > > > Note that function decorator returned None, while class decorator > returned function. To repeat and expand a bit what I said to the OP: these are both callables (functions in the math sense) because they both of instances of a class with a .__call__ instance method. Both are used as function decorators. One is an instance of class 'function', the other an instance of class 'MyMethod'. The class difference is not relevant to the usage. This is duck typing in action. A class decorator is a callable (in 2.6+/3.0+) that decorates a class. tjr From gnewsg at gmail.com Fri Jan 16 20:32:17 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 17:32:17 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> On 17 Gen, 02:24, MRAB wrote: > If you're truly working with strings of _characters_ then > 'str' is what you need, but if you're working with strings of _bytes_ > then 'bytes' is what you need. I work with string of characters but to convert bytes into string I need to specify an encoding and that's what confuses me. Before there was no need to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib From excord80 at gmail.com Fri Jan 16 20:32:49 2009 From: excord80 at gmail.com (excord80) Date: Fri, 16 Jan 2009 17:32:49 -0800 (PST) Subject: Need help with os.system in linux References: Message-ID: On Jan 16, 7:05?pm, akshay bhat wrote: > Hello > i am calling a program using os.system in python on Linux. > However in i found that program being executed and soon returned 256. > but when i ran it using terminal i got proper results. > Now in case of windows, python waits till the process is finished, > Can you please tell me how to implement this in linux? Maybe it runs faster in GNU/Linux? :) Either way, you probably want to post some minimal example code if you would like more help on this. From tjreedy at udel.edu Fri Jan 16 20:34:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:34:49 -0500 Subject: Beginner: Data type conversion question In-Reply-To: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> References: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> Message-ID: flagg wrote: >> If rdate.serial is already a string, as name would imply, the str() call >> is pointless. If not, can you get inc as int more directly? ... > Actually when i run a type(serial) on that variable it returns a > "long" Then inc = serial % 100 is 'more directly'. > which i am not sure why dnspython uses a long variable to > store the serial. Perhaps a holdever from C code where long is necessary to dependably hold counts with 8 decimal digits. From lists at cheimes.de Fri Jan 16 20:42:11 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:42:11 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' schrieb: > I work with string of characters but to convert bytes into string I > need to specify an encoding and that's what confuses me. > Before there was no need to deal with that. Why do you have to deal with unicode data? IIRC ftp uses ASCII only text so you can stick to bytes everywhere. If you didn't have to worry about encoding and unicode in Python 2.x then you should use bytes all over the place, too. Christian From alan.isaac at gmail.com Fri Jan 16 20:55:52 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 01:55:52 GMT Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: > Alan G Isaac wrote: >> http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range >> >> I see no mention of the tuple methods? >> >> Right after the paragraph >> "Most sequence types support the following operations." >> it seems appropriate to have one stating >> "Most sequence types support the following methods: index() and count()." On 1/16/2009 6:44 PM Terry Reedy apparently wrote: > I addressed this and related issues in > http://bugs.python.org/issue4966 Excellent! Alan Isaac From sjmachin at lexicon.net Fri Jan 16 20:58:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 16 Jan 2009 17:58:39 -0800 (PST) Subject: Incorrect title case? References: Message-ID: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> On Jan 17, 9:07?am, MRAB wrote: > Python 2.6.1 > > I've just found that the following 4 Unicode characters/codepoints don't > behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). > > For example, u"\u01C5".istitle() returns True and > unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() > returns u'\u01C4', which is the uppercase equivalent. Are these mistakes > in the Unicode database? Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, function _PyUnicode_ToTitlecase. See http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup The code that says: if (ctype->title) delta = ctype->title; else delta = ctype->upper; should IMHO merely be: delta = ctype->title; A value of zero for ctype->title should be interpreted simply as the offset to add to the ordinal, as it is in the sibling _PyUnicode_To (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py which treats upper, lower and title identically when preparing the tables used by those 3 functions. AFAICT making that change will fix the problem for those four characters and not ruin any others. The error that you noticed occurs as far back as I've looked (2.1) and also occurs in 3.0. Cheers, John From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 21:09:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 02:09:13 GMT Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: <0181344a$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 17:32:17 -0800, Giampaolo Rodola' wrote: > On 17 Gen, 02:24, MRAB wrote: > >> If you're truly working with strings of _characters_ then 'str' is what >> you need, but if you're working with strings of _bytes_ then 'bytes' is >> what you need. > > I work with string of characters but to convert bytes into string I need > to specify an encoding and that's what confuses me. Before there was no > need to deal with that. In Python 2.x, str means "string of bytes". This has been renamed "bytes" in Python 3. In Python 2.x, unicode means "string of characters". This has been renamed "str" in Python 3. If you do this in Python 2.x: my_string = str(bytes_from_socket) then you don't need to convert anything, because you are going from a string of bytes to a string of bytes. If you do this in Python 3: my_string = str(bytes_from_socket) then you *do* have to convert, because you are going from a string of bytes to a string of characters (unicode). The Python 2.x equivalent code would be: my_string = unicode(bytes_from_socket) and when you convert to unicode, you can get encoding errors. A better way to do this would be some variation on: my_str = bytes_from_socket.decode('utf-8') You should read this: http://www.joelonsoftware.com/articles/Unicode.html -- Steven From gnewsg at gmail.com Fri Jan 16 21:34:25 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 18:34:25 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <0181344a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1c4506ed-f9e4-4f86-8df6-94afeb054cdb@z28g2000prd.googlegroups.com> On 17 Gen, 03:09, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 17:32:17 -0800, Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then 'str' is what > >> you need, but if you're working with strings of _bytes_ then 'bytes' is > >> what you need. > > > I work with string of characters but to convert bytes into string I need > > to specify an encoding and that's what confuses me. Before there was no > > need to deal with that. > > In Python 2.x, str means "string of bytes". This has been renamed "bytes" > in Python 3. > > In Python 2.x, unicode means "string of characters". This has been > renamed "str" in Python 3. > > If you do this in Python 2.x: > > ? ? my_string = str(bytes_from_socket) > > then you don't need to convert anything, because you are going from a > string of bytes to a string of bytes. > > If you do this in Python 3: > > ? ? my_string = str(bytes_from_socket) > > then you *do* have to convert, because you are going from a string of > bytes to a string of characters (unicode). The Python 2.x equivalent code > would be: > > ? ? my_string = unicode(bytes_from_socket) > > and when you convert to unicode, you can get encoding errors. A better > way to do this would be some variation on: > > ? ? my_str = bytes_from_socket.decode('utf-8') > > You should read this: > > http://www.joelonsoftware.com/articles/Unicode.html > > -- > Steven Thanks, that clarifies a bit even if I still have a lot of doubts. I wish I could do: my_str = bytes_from_socket.decode('utf-8') That would mean avoiding to replace "" with b"" almost everywhere in my code but I doubt it would actually be a good idea. RFC-2640 states that UTF-8 is the preferable encoding to use for both clients and servers but I see that Python 3.x's ftplib uses latin1, for example (bug?). How my server is supposed to deal with that? I think that using bytes everywhere, as Christian recommended, would be the only way to behave exactly like the 2.x version, but that's not easy at all. --- Giampaolo http://code.google.com/p/pyftpdlib From steve at holdenweb.com Fri Jan 16 21:40:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 21:40:11 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > On 17 Gen, 02:24, MRAB wrote: > >> If you're truly working with strings of _characters_ then >> 'str' is what you need, but if you're working with strings of _bytes_ >> then 'bytes' is what you need. > > I work with string of characters but to convert bytes into string I > need to specify an encoding and that's what confuses me. > Before there was no need to deal with that. > I don't yet understand why you feel you have to convert what you receive to a string. In Python 3.0 bytes is the same as a string in 2.6, for most practical purposes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gnewsg at gmail.com Fri Jan 16 21:54:51 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 18:54:51 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: On 17 Gen, 03:40, Steve Holden wrote: > Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then > >> 'str' is what you need, but if you're working with strings of _bytes_ > >> then 'bytes' is what you need. > > > I work with string of characters but to convert bytes into string I > > need to specify an encoding and that's what confuses me. > > Before there was no need to deal with that. > > I don't yet understand why you feel you have to convert what you receive > to a string. In Python 3.0 bytes is the same as a string in 2.6, for > most practical purposes. > > regards > ?Steve That would help to avoid replacing "" with b"" almost everywhere in my code. --- Giampaolo http://code.google.com/p/pyftpdlib From jcd at sdf.lonestar.org Fri Jan 16 21:58:02 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Fri, 16 Jan 2009 21:58:02 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> <0180a93a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1232161082.17182.1.camel@mctell> On Fri, 2009-01-16 at 16:41 -0500, Steve Holden wrote: > Steven D'Aprano wrote: > > On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > > > >> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: > >>> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > >>> > >>>> Oh come on you lot - you are carrying on as if Diez were wearing his > >>>> skull socks again - do me a favour and give him a break! > >>> And... skull socks? Cool. Where can I get some? > >>> > >>> > >>> > >> http://www.letmegooglethatforyou.com/search?q=skull+socks > > > > Not Found > > The requested URL /search was not found on this server. > > Additionally, a 404 Not Found error was encountered while trying to use > > an ErrorDocument to handle the request. > > > > > > > > You know, it was just a throw-away comment to lighten the mood. I don't > > really need to see 18,000+ links to places that sell socks with skulls > > printed on them. > > > > On the other hand, if they were socks made from actual skulls, that would > > be something... > > > Of course Cliff actually meant > > http://letmegooglethatforyou.com/?q=skull+socks > > Jokes are never as funny when they go wrong :) Maybe I could run a "teach me letmegooglethatforyou.com" at pycon this year. From tjreedy at udel.edu Fri Jan 16 22:43:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 22:43:31 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > That would help to avoid replacing "" with b"" almost everywhere in my > code. Won't 2to3 do that for you? From andrew at acooke.org Fri Jan 16 22:45:57 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 19:45:57 -0800 (PST) Subject: ABCs, functions, and __call__ (Python3) References: Message-ID: <5b1c4a9f-67f2-412e-adff-a1e654a11d5f@k36g2000pri.googlegroups.com> On Jan 16, 10:13?pm, Christian Heimes wrote: > Any callable in Python 3.0 has a "__call__" attribute. Aha! Thanks! Andrew From gnewsg at gmail.com Fri Jan 16 22:51:33 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 19:51:33 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> On 17 Gen, 04:43, Terry Reedy wrote: > Giampaolo Rodola' wrote: > > That would help to avoid replacing "" with b"" almost everywhere in my > > code. > > Won't 2to3 do that for you? I used 2to3 against my code but it didn't cover the "" -> b"" conversion (and I doubt it is able to do so, anyway). --- Giampaolo http://code.google.com/p/pyftpdlib From wuwei23 at gmail.com Fri Jan 16 23:07:08 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 20:07:08 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> On Jan 17, 10:37?am, "Brendan Miller" wrote: > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? This is more or less covered in the FAQ: "The restrictions are to ensure that type inference (and so, ultimately, translation to other languages) of RPython programs is possible. These restrictions only apply after the full import happens, so at import time arbitrary Python code can be executed." http://codespeak.net/pypy/dist/pypy/doc/faq.html#id25 > The goals of the pypy project seems to be to create a fast python > implementation. I may be wrong about this, as the goals seem a little > amorphous if you look at their home page. The home page itself is ambiguous, and does oversell the performance aspect. The *actual* goal as outlined by their official docs is to implement Python in Python, at every level. If this means utilising a less-dynamic subset of Python for the lower levels, its -still- at least more-Python-than-C. "PyPy is both: * a reimplementation of Python in Python, and * a framework for implementing interpreters and virtual machines for programming languages, especially dynamic languages." http://codespeak.net/pypy/dist/pypy/doc/faq.html#id11 The PyPy devs feel that this will allow them to more easily experiment with optimising the interpreter for greater speeds, but that isn't one of the stated goals (just, apparently, their 'secret' one). > This RPython thing seems like a totally unnecessary intermediate step. > Instead of writing an implementation of one language, there's an > implementation of two languages. My understanding is that the 'higher' level Python language features are implemented on top of the restricted RPython features, so it's more of an organic growth of one language than two separate implementations. > A lot of the performance boost you > get from a static language is that knowing the types at compile time > lets you inline code like crazy, unroll loops, and even execute code > at compile time. > > RPython is a statically typed language because I guess the developers > associate static languages with speed? Doesn't the first paragraph above state the same thing that you question in the next? > Except that they use it to > generate C code, which throws away the type information they need to > get the speed increase. Huh? I thought the goal was to write a fast > dynamic language, not a slow static one? They're not just generating C code, they currently also target LLVM, JVM and CLI. > Is this going anywhere or is this just architecture astronautics? Well, they actually seem to have achieved some substantial gains, so I think it's unfair to imply that the project isn't based on pragmatic objectives. Their initial JIT prototype failed to work as well as expected, and they've spent some time re-thinking the approach; I'm happier to wait for a stably performing JIT that can be improved over time than a short term gain. > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. A lot of this is covered in the FAQ. Whether you agree with their approach or not, they're the ones actively pushing this effort forward. It's been a few months since the last update, but the PyPy status blog may have more information for you. At the very least, it's a venue to discuss your concerns directly with the PyPy devs. http://morepypy.blogspot.com From steve at holdenweb.com Fri Jan 16 23:08:26 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 23:08:26 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > On 17 Gen, 04:43, Terry Reedy wrote: >> Giampaolo Rodola' wrote: >>> That would help to avoid replacing "" with b"" almost everywhere in my >>> code. >> Won't 2to3 do that for you? > > I used 2to3 against my code but it didn't cover the "" -> b"" > conversion (and I doubt it is able to do so, anyway). > Note that if you are using 2.6 you should first convert your "" quotes to b"" - this won't make any practical difference, but then you will be able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gary.smith28 at comcast.net Fri Jan 16 23:23:40 2009 From: gary.smith28 at comcast.net (Gary Smith) Date: Fri, 16 Jan 2009 23:23:40 -0500 Subject: Python Startup file Message-ID: Fellow Vipers, Although I've written lots of Python code, I'm still an embarrassed newbie. Here's my problem. I've never been able to get ActiveState Python's PythonWin to observe the file referenced in the Windows PYTHONSTARTUP environment variable. Many thanks for pointing out the obvious to me Gary _____ "Accept no assertions without evidence." --Goompah wisdom from "Omega" by Jack McDevitt-- _____ "Nature is complete because it does not serve itself." --"Tao De Jing" by Lao Tze-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 16 23:26:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 16 Jan 2009 20:26:31 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> Message-ID: <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> On Jan 17, 3:08?pm, Steve Holden wrote: > Giampaolo Rodola' wrote: > > On 17 Gen, 04:43, Terry Reedy wrote: > >> Giampaolo Rodola' wrote: > >>> That would help to avoid replacing "" with b"" almost everywhere in my > >>> code. > >> Won't 2to3 do that for you? > > > I used 2to3 against my code but it didn't cover the "" -> b"" > > conversion (and I doubt it is able to do so, anyway). > > Note that if you are using 2.6 you should first convert your "" quotes > to b"" - this won't make any practical difference, but then you will be > able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. Perhaps before we get too far down the track of telling the OP what he should do, we should ask him a little about his intentions: Is he porting to 3.0 and abandoning 2.x support completely? [presumably unlikely] So then what is the earliest 2.x that he wants to support at the same time as 3.x? [presumably at least 2.5] Does he intend to maintain two separate codebases, one 2.x and the other 3.x? Else does he intend to maintain just one codebase written in some 2.x dialect and using 2to3 plus sys.version-dependent code for the things that 2to3 can't/doesn't handle? Cheers, John From wuwei23 at gmail.com Fri Jan 16 23:36:50 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 20:36:50 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> On Jan 17, 3:34?pm, Eduardo Lenz wrote: > modu = "os" > exec("from " + modu + " import *") And of course, there's the usual disclaimer that this should be only used in circumstances where you can guarantee the contents of 'modu' aren't ever going to be anything like: modu = "os import system; system('rm *'); from os " Another reason to prefer __import__ over exec is speed: $ /usr/lib/python2.5/timeit.py -n 100000 'from os import system' 100000 loops, best of 3: 2.12 usec per loop $ /usr/lib/python2.5/timeit.py -n 100000 '__import__("os", fromlist= ["system"])' 100000 loops, best of 3: 2.72 usec per loop $ /usr/lib/python2.5/timeit.py -n 100000 'm = "os"; exec("from " + m + " import system")' 100000 loops, best of 3: 25.1 usec per loop From prologic at shortcircuit.net.au Sat Jan 17 00:07:15 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:07:15 +1000 Subject: problem in implementing multiprocessing In-Reply-To: <66510985287744829EE3AD881CE824B2@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> Message-ID: On Fri, Jan 16, 2009 at 7:16 PM, gopal mishra wrote: > I create two heavy objects sequentially without using multipleProcessing > then creation of the objects takes 2.5 sec.if i create these two objects in > separate process then total time is 6.4 sec. > > i am thinking it is happening due to the pickling and unpickling of the > objects.if i am right then what could be the sollution. > > my system configuration: > dual-core processor > winXP > python2.6.1 System specs in this case are irrelevant. What you are experiencing is most likely an I/O bound problem - using multiprocessing may likely not help you solve the problem any faster because of your I/O constraint. cheers James From prologic at shortcircuit.net.au Sat Jan 17 00:13:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:13:02 +1000 Subject: multiprocessing vs. distributed processing In-Reply-To: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> References: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 10:15 PM, Jesse Noller wrote: > That being said, there is no reason why you could not use it in > conjunction with something like Kamaelia, pyro, $ipc mechanism/etc. And also circuits (1). circuits has full implementations of Thread and Process components. circuits also has special components focused at distributed applications. cheers James 1. http://pypi.python.org/pypi/circuits From prologic at shortcircuit.net.au Sat Jan 17 00:18:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:18:06 +1000 Subject: process/thread instances and attributes In-Reply-To: <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> References: <496F03B9.8090100@shopzeus.com> <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 10:33 PM, Jesse Noller wrote: (...) > Personally, rather then using a value to indicate whether to run or > not, I would tend to use an event to coordinate start/stop state. The reason I implemented workers.Thread and workers.Process this way is basically so taht long-running, potentially blocking work could be done yet while still maintaining the ability to communicate with the rest of the system and propagate events. See: http://hg.softcircuit.com.au/index.wsgi/projects/circuits/file/0a97da2a69b3/circuits/workers.py cheers James From atleta.hu at gmail.com Sat Jan 17 00:29:50 2009 From: atleta.hu at gmail.com (atleta) Date: Fri, 16 Jan 2009 21:29:50 -0800 (PST) Subject: Parallel package hierarchies/directories References: <70cbe817-9eda-4346-93b6-5c38d8d63389@n33g2000pri.googlegroups.com> Message-ID: OK, I'm answering my own question, it might be of some help for someone in the future: yes, it's possible to have parts of the same package in multiple directories, it's just not enabled by default. To make it work each such package should have the following code in their __init__.py: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) Actually pkgutil's documentation explains this quite clearly: http://docs.python.org/library/pkgutil.html (It's easy if you know where to look ;) ) Laszlo From lenz at joinville.udesc.br Sat Jan 17 00:34:01 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 21:34:01 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <200901162134.01720.lenz@joinville.udesc.br> On Friday 16 January 2009 15:03:51 Lawson Hanson wrote: > Is it possible to import a module of Python code > where I do not know the name of the module > until run-time? > > The Python statement: > > from someModule import * > > requires that "someModule" be the name of the module, > but what I would like is to be able to define a value > for "someModule" ... and provided that such a module > exists (in an extended "sys.path" directory), then > import from the specified module at run-time > > If I have a module called "dummy.py" in my own "myModules" > directory (just below my HOME directory in Linux) > > If I do this: > > import os, sys > > myModDir = os.environ["HOME"] + "/myModules" > > sys.path.append(myModDir) > > modName = "%s/%s" % (myModDir, "dummy") > > from modName import * > > I get the following error: > > ImportError: No module named modName > > So is there any way to get Python to import the named module > without just doing "from dummy import *", because I will > not know that the user wants to use the "dummy" module > until run-time ... I'm trying to import control data > for different run scenarios which will be defined in > differently named Python modules which the user will > specify at run-time with a command-line option > > And help with this would be most appreciated > > Best regards, > > Lawson Hanson > ------ > Melbourne, Victoria, Australia > -- > http://mail.python.org/mailman/listinfo/python-list modu = "os" exec("from " + modu + " import *") []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From lenz at joinville.udesc.br Sat Jan 17 00:39:04 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 21:39:04 -0800 Subject: multiprocessing question/error Message-ID: <200901162139.04849.lenz@joinville.udesc.br> Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code .... class Pygen3(self).... .... .... .... def calcula(self,indiv): .... .... .... def evaluate(self): .... .... indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 00:55:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 05:55:34 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> Message-ID: <01816958$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 20:36:50 -0800, alex23 wrote: > On Jan 17, 3:34?pm, Eduardo Lenz wrote: >> modu = "os" >> exec("from " + modu + " import *") > > And of course, there's the usual disclaimer that this should be only > used in circumstances where you can guarantee the contents of 'modu' > aren't ever going to be anything like: > > modu = "os import system; system('rm *'); from os " > > Another reason to prefer __import__ over exec is speed: Both very good points, but consider that you're not comparing apples with apples. >>> from os import system >>> system >>> del system >>> >>> exec "from %s import system" % "os" >>> system >>> del system >>> >>> __import__("os", fromlist=["system"]) >>> system Traceback (most recent call last): File "", line 1, in NameError: name 'system' is not defined I mention this only to be pedantic, because I agree with your point that exec can introduce security issues, and be significantly slower. -- Steven From Scott.Daniels at Acm.Org Sat Jan 17 01:04:29 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 16 Jan 2009 22:04:29 -0800 Subject: *Advanced* Python book? In-Reply-To: <7xprimsxaj.fsf@ruckus.brouhaha.com> References: <7xprimsxaj.fsf@ruckus.brouhaha.com> Message-ID: <35idnRlNc_Y96ezUnZ2dnUVZ_rPinZ2d@pdx.net> Paul Rubin wrote: > mk writes: >> .... Anybody found such holy grail? > > The favorite ones around here are "Python Cookbook" and "Python in a > Nutshell", both by Alex Martelli, who used to be a newsgroup regular > and still stops by from time to time. To the OP: Do yourself a favor and go to a bookstore and read a chapter or two of the cookbook. While you can see the recipes on activestate, there is a _lot_ of value added in (1) the selection, (2) the editing for a more consistent style, and (3) the chapter intros by people chosen for their knowledge on the chapter's subject. --Scott David Daniels Scott.Daniels at Acm.Org From lenz at joinville.udesc.br Sat Jan 17 01:25:59 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 22:25:59 -0800 Subject: dynamic module import? In-Reply-To: <01811941$0$8693$c3e8da3@news.astraweb.com> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <01811941$0$8693$c3e8da3@news.astraweb.com> Message-ID: <200901162226.00043.lenz@joinville.udesc.br> On Friday 16 January 2009 16:13:49 Steven D'Aprano wrote: > On Fri, 16 Jan 2009 21:34:01 -0800, Eduardo Lenz wrote: > > modu = "os" > > exec("from " + modu + " import *") > > "from module import *" is generally frowned upon, although it does > occasionally have its uses. > > By the way, I think your computer's clock is set wrong. My newsclient is > reporting that you sent your post at 4:30pm today -- and I'm writing this > at 11am. Perhaps your timezone is set wrong? > > Regards, > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list OK, my point was about the exec statement, not the import * (it was just an example). Well, my clock is OK here..maybe the time zone is wrong. I will check this out. Thanks for the advice. []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From michele.simionato at gmail.com Sat Jan 17 01:47:20 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 16 Jan 2009 22:47:20 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: On Jan 16, 9:27?pm, mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. > > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? > > Regards, > mk "Expert Python Programming" by Tarek Ziad? is quite good and I wrote a review for it: http://www.artima.com/weblogs/viewpost.jsp?thread=240415 There is plenty of info about Advanced Python on the net, much more than in book form. Come to think of it, there are my Oxford lectures (the title was exactly "Advanced Python Programming") and I could republish it on my blog, since I cannot find them on the net anymore. Michele Simionato From bellman at lysator.liu.se Sat Jan 17 02:19:45 2009 From: bellman at lysator.liu.se (Thomas Bellman) Date: Sat, 17 Jan 2009 07:19:45 +0000 (UTC) Subject: Need help with os.system in linux References: Message-ID: akshay bhat writes: > i am calling a program using os.system in python on Linux. > However in i found that program being executed and soon returned 256. > but when i ran it using terminal i got proper results. Under Linux (but unfortunately not generally under Unix), you can interpret return code from os.system() using os.WIFSIGNALED() or os.WIFEXITED(), and os.WEXITSTATUS() or os.WTERMSIG(). Something like this: status = os.system(commandline) if os.WIFSIGNALED(status): print "Command was killed by signal", os.WTERMSIG(status) else: print "Command exited with return status", os.WEXITSTATUS(status) (os.WIFSIGNALED() and os.WIFEXITED() are each others inverses, for this use case. In the above code, I could have used 'not os.WIFEXITED(status)' instead of 'os.WIFSIGNALED(status)' without changing its meaning.) If you do that for your program, you will see that the program you call are exiting with return status 1 (that's what a return value of 256 from os.system() happens to mean), i.e it is calling exit() with 1 as argument. *Why* the program you are calling does that, is impossible to tell from the information you have given us. You haven't even told us what command line you are passing to os.system(), so if you need more help, you must tell us more. May I also suggest that you use the subprocess module instead of os.system(). The subprocess module is a newer and better interface for running external commands. For example, you can avoid having to deal with quoting shell metacharacters, and interpreting the return values are easier. -- Thomas Bellman, Lysator Computer Club, Link??ping University, Sweden "Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se differently is selling something." ! Make Love -- Nicht Wahr! From castironpi at gmail.com Sat Jan 17 03:24:21 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 00:24:21 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> Message-ID: <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> On Jan 16, 5:03?am, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 16:30:36 -0800, Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. > > [...] > > > What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > Here's a lightweight solution that uses lazy calculation of the reverse > dict. It makes a number of assumptions: > > - both keys and values will be hashable and unique; > - the dict won't be so large that calculating the reverse dictionary will > be time consuming; > - modifications to instance.reverse are undefined. > > Usage: > > >>> d = ReverseDict(x=2, y=3, z=4) > >>> d['x'] > 2 > >>> d.reverse[2] > 'x' > >>> d['a'] = 0 > >>> d.reverse[0] > > 'a' > > def make_dirty(func): > ? ? from functools import wraps > ? ? @wraps(func) > ? ? def f(self, *args, **kwargs): > ? ? ? ? self._dirty = True > ? ? ? ? return func(self, *args, **kwargs) > ? ? return f > > # only tested a little bit > class ReverseDict(dict): > ? ? def __init__(self, *args, **kwargs): > ? ? ? ? super(ReverseDict, self).__init__(*args, **kwargs) > ? ? ? ? self._dirty = True > ? ? @make_dirty > ? ? def clear(): > ? ? ? ? super(ReverseDict, self).clear() snip > ? ? @property > ? ? def reverse(self): > ? ? ? ? if self._dirty: > ? ? ? ? ? ? # Modify this to support repeated and non-hashable values. > ? ? ? ? ? ? self._reverse = dict((value, key) for > ? ? ? ? ? ? (key, value) in self.iteritems()) > ? ? ? ? ? ? self._dirty = False > ? ? ? ? return self._reverse > > An even more lightweight solution is to give up O(1) for the reverse > lookup: > > # untested > class ReversableDict(dict): > ? ? def lookupvalue(self, value): > ? ? ? ? for k,v in self.iteritems(): > ? ? ? ? ? ? if v == value: return k > ? ? ? ? raise ValueError('value not found') > ? ? def lookupallvalues(self, value): > ? ? ? ? results = [] > ? ? ? ? for k,v in self.iteritems(): > ? ? ? ? ? ? if v == value: results.append(k) > ? ? ? ? return results > > -- > Steven Can you make it work for a 3-way lookup? From castironpi at gmail.com Sat Jan 17 03:43:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 00:43:35 -0800 (PST) Subject: multiprocessing question/error References: Message-ID: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> On Jan 16, 11:39?pm, Eduardo Lenz wrote: > Hi, > > I was using the former processing package with python 2.5 with no problems. > After switching to python 2.6.1 I am having some problems with the same code. > The problem seems to be related to the fact that I am using Pool.map > with a bounded method, since it is inside a class. To clarify a little bit, > let me show some parts of the code .... Hello, > class Pygen3(self).... I infer this was a typo. > ? ? .... > ? ? .... > ? ? .... > ? ? def calcula(self,indiv): > ? ? ? ? .... > ? ? ? ? .... > ? ? ? ? .... > > ? ?def evaluate(self): > ? ? ?.... > ? ? ?.... > ? ? indiv = range(mult*self.popsize,(mult+1)*self.popsize) > ? ?pool = Pool(processes=nproc) > ? ?results = pool.map(self.calcula,indiv) I infer the indentation drifted. > ? ?... > ? ?... > > the error is the following > > Exception in thread Thread-1: > Traceback (most recent call last): > ? File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner > ? ? self.run() > ? File "/usr/lib/python2.6/threading.py", line 477, in run > ? ? self.__target(*self.__args, **self.__kwargs) > ? File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > _handle_tasks > ? ? put(task) > PicklingError: Can't pickle : attribute lookup > __builtin__.instancemethod failed > > Thanks for your help. Checking on two typos above. I have this working: from multiprocessing import Process class C(object): def m1( self ): p1 = Process(target=self.m2, args=('bob1',)) p2 = Process(target=self.m2, args=('bob2',)) p1.start() p2.start() p1.join() p2.join() def m2( self, name ): print 'hello', name if __name__ == '__main__': c= C() c.m1() But I get the same error as you with this: from multiprocessing import Process, Pool class C(object): def m1( self ): arg= range( 10 ) pool= Pool( 5 ) results = pool.map(self.m2,arg) print results def m2( self, name ): print 'hello', name if __name__ == '__main__': c= C() c.m1() I build a workaround with this: from multiprocessing import Process, Pool class C(object): def m1( self ): arg= zip( [ self ]* 10, range( 10 ) ) pool= Pool( 5 ) results = pool.map(C_m2,arg) print results def m2( self, arg ): print 'hello', arg return arg* 2 def C_m2( ar, **kwar ): return C.m2( *ar, **kwar ) if __name__ == '__main__': c= C() c.m1() Note that you have to explicitly include 'self' as a first parameter when packing the arguments, and then explicitly unpack it in the helper function. Also, wrapping 'm2' with '@staticmethod' also fails with this error: Exception in thread Thread-1: Traceback (most recent call last): File "c:\programs\python26\lib\threading.py", line 522, in __bootstrap_inner self.run() File "c:\programs\python26\lib\threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "c:\programs\python26\lib\multiprocessing\pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.function failed If this works for you, it's possible to make the helper function more dynamic, by accepting a class name and an attribute name as string arguments, then retrieving them in the subprocesses. From pdorange at pas-de-pub-merci.mac.com Sat Jan 17 03:48:12 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sat, 17 Jan 2009 09:48:12 +0100 Subject: Pythonic way to handle coordinates Message-ID: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Hi, I'm used python for 3 months now to develop small arcade games (with pygame module). I just got a question about coordinates handling. My games are in 2D so i deal with x,y coordinates for sprites (but woudl be the same u-issue in 3D). At the beginning i simply use x and y to pass to my methods ie : sprite.move(x,y) easy after looking closely to pygame code, i noticed that pygame implement a Rect class but no Point class, and instead require tuple for coordinates. ie : pygame.draw.line(surface,color,start,end) where start and end are tuple, like (x,y). I found this nice and rewrote my API to use tuples instead of 2 variables... so i got could do : loc=(x,y) sprite.move(loc) or sprite.move((x,y)) ... loc=sprite.get_pos() Nice, but i got a problem when my methodes return tuple, as it's unmutable i could not modify them and i got to used tempory variables to do that, not very clean : loc=sprite.get_pos() loc[0]+=10 < ERROR ... x=loc[0]+10 loc=(x,loc[1]) i could also do : (x,y)=sprite.get_pos() x+=10 sprite.set_pos((x,y)) The second method could not be used when i'm instead one of my method, i need to used the first one. What is the elegant way to handle coordinates ? Do i need to continue using tuples or do i need to write a Point class. I feel a point class would be nice, because i could implement operators with it ? But i think Point class must exist allready ? -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From castironpi at gmail.com Sat Jan 17 04:09:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 01:09:40 -0800 (PST) Subject: English-like Python References: Message-ID: <337394e9-e86a-4506-941b-fcfd33ce2e32@a26g2000prf.googlegroups.com> On Jan 15, 7:02?pm, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > > >>> import os > > >>> def list_files(dirname): > >>> ? ? for p in os.listdir(dirname): > >>> ? ? ? ? print p > > >>> list_files("some_dir") > > foo > bar > etc > > ...might be translated as... > > >>> Import the operating system module. > > >>> Define a new function as "list files" which accepts > > ? ? "a path" and does the following: > ? ? ? ? For every item in the list returned by the operating system's > ? ? ? ? directory listing of the given path, do the following: > ? ? ? ? ? ? ?Print the item. > > >>> List files from "some_dir". > > foo > bar > etc > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^ I'm actually moderately interested in this idea. I was pursuing it a while back, but didn't find anyone else interested. You want to avoid requiring an understanding, since English syntax doesn't always guarantee its semantics. Even a trivial transformation from non- delimited English can cause an AmbiguityException. The basics started like this: 'a= open "file1.py"' --> 'a= open( "file1.py" )' ''' a= nat_list() append 0 to a append 1 to a sort a ''' --> ''' a= nat_list() a.append( 0 ) a.append( 1 ) a.sort() ''' However, as you can see, 'open a' can map to both 'a.open()' and 'open ( a )'. If 'open' is both a method on 'a', and a callable defined in current scope, the expression is ambiguous and raises an AmbiguityException. If you're willing to constrain yourself to a subset of English which the language will understand, you open a lot of doors; that is, if you will accept a 'more natural Python' instead of 'true natural Python'. From dragosmocrii at gmail.com Sat Jan 17 04:30:09 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 01:30:09 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: <5aa0e99a-9f97-4cc7-b7a0-d6dd30a25ce2@b38g2000prf.googlegroups.com> On Jan 16, 9:19?pm, Dragos wrote: > I am trying to make a testing script to load/save cookies to a file > with FileCookieJar, but it results in this error: FileCookieJar has > not attribute "_self_load" > > This is my script: > > import urllib.request, urllib.parse,http.cookiejar > url="http://localhost/test.php" > cs=http.cookiejar.FileCookieJar() > cs.load("cookies.txt",ignore_discard=False, ignore_expires=False) > opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor > (cs)) > y=opener.open(url) > print(y.read()) > > Thanks for helping. BUMP From gagsl-py2 at yahoo.com.ar Sat Jan 17 04:48:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 07:48:35 -0200 Subject: FileCookieJar has not attribute "_self_load" In-Reply-To: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo gmane.comp.python.general > I am trying to make a testing script to load/save cookies to a file > with FileCookieJar, but it results in this error: FileCookieJar has > not attribute "_self_load" FileCookieJar is an abstract class, although it isn't clear at all from the documentation. (You may want to file a documentation bug at http://bugs.python.org) You must instantiate a specific subclass (like MozillaCookieJar), which determines the actual file format used. -- Gabriel Genellina From musicguy at alphaios.net Sat Jan 17 04:50:23 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sat, 17 Jan 2009 01:50:23 -0800 (PST) Subject: Pythonic way to handle coordinates References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: On Jan 17, 2:48?am, pdora... at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) wrote: > Hi, > I'm used python for 3 months now to develop small arcade games (with > pygame module). > > I just got a question about coordinates handling. > My games are in 2D so i deal with x,y coordinates for sprites (but woudl > be the same u-issue in 3D). > > At the beginning i simply use x and y to pass to my methods > ie : sprite.move(x,y) > easy > > after looking closely to pygame code, i noticed that pygame implement a > Rect class but no Point class, and instead require tuple for > coordinates. > ie : pygame.draw.line(surface,color,start,end) > where start and end are tuple, like (x,y). > > I found this nice and rewrote my API to use tuples instead of 2 > variables... > so i got could do : > ? ? ? ? loc=(x,y) > ? ? ? ? sprite.move(loc) or sprite.move((x,y)) > ? ? ? ? ... > ? ? ? ? loc=sprite.get_pos() > > Nice, but i got a problem when my methodes return tuple, as it's > unmutable i could not modify them and i got to used tempory variables to > do that, not very clean : > ? ? ? ? loc=sprite.get_pos() > ? ? ? ? loc[0]+=10 ?< ERROR > ? ? ? ? ... > ? ? ? ? x=loc[0]+10 > ? ? ? ? loc=(x,loc[1]) > i could also do : > ? ? ? ? (x,y)=sprite.get_pos() > ? ? ? ? x+=10 > ? ? ? ? sprite.set_pos((x,y)) > The second method could not be used when i'm instead one of my method, i > need to used the first one. > > What is the elegant way to handle coordinates ? > Do i need to continue using tuples or do i need to write a Point class. > I feel a point class would be nice, because i could implement operators > with it ? But i think Point class must exist allready ? > > -- > Pierre-Alain Dorange > > Ce message est sous licence Creative Commons "by-nc-sa-2.0" > ? ? ? ? Hi there, First of all, Pygame will accept any sequence of two integers (or even floats) and not just tuples, so you don't need to implement all your coordinates as tuples, and thus you can use lists, which are mutable. Second of all, for this situation I do the same as the Rect object and implement .x and .y properties for objects that need individual access of those coordinates. Example: >>> # WARNING: This code was written on-the-fly and has not been tested... >>> class MySprite(object): >>> def __init__(self, pos): >>> # This is a list, not a tuple. Pygame won't mind. >>> # Also, note that the type of the pos is implicitly >>> # type checked. >>> self._pos = map(int, pos[:2]) >>> >>> def set_x(self, x): >>> self._pos[0] = int(x) >>> x = property(lambda self: self._pos[0], set_x) >>> >>> def set_y(self, y): >>> self._pos[1] = int(y) >>> y = property(lambda self: self._pos[1], set_y) >>> >>> def set_pos(self, pos): >>> self._pos = map(int, pos[:2]) >>> # Note that the return value is converted to tuple to prevent >>> # constructs like `mysprite.pos[0] = "foo"`, which would cause an >>> # invalid type of value to be assigned for the x coordinates. >>> pos = property(lambda self: tuple(self._pos), set_pos) >>> >>> spr = MySprite((3,4)) >>> spr.x 3 >>> spr.y 4 >>> spr.x = 8 >>> spr.pos (8,4) My SDK implements a lot of things like this. Check it out if you're looking for more examples: http://code.google.com/p/scrollback -TMG From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:00:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:00:27 -0200 Subject: Finding the full path of an executable References: Message-ID: En Fri, 16 Jan 2009 23:08:27 -0200, escribiste en el grupo gmane.comp.python.general > Unknown wrote: >> On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >>> Is there a portable way to find the full path of a filename that would >>> be called by os.execvp()? > The correct answer would be "/bin/echo" but abspath("echo") is just > going to give me /echo. I need something that will search through > the PATH like execvp() would. I can do it myself, but I'm surprised that > such a feature is not already readily available somewhere. py> import distutils.spawn py> help(distutils.spawn.find_executable) Help on function find_executable in module distutils.spawn: find_executable(executable, path=None) Try to find 'executable' in the directories listed in 'path' (a string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']). Returns the complete filename or None if not found. py> distutils.spawn.find_executable("sc") 'C:\\WINDOWS\\system32\\sc.exe' -- Gabriel Genellina From zak.mc.kraken at libero.it Sat Jan 17 05:05:17 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sat, 17 Jan 2009 11:05:17 +0100 Subject: vb2py status? References: Message-ID: axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? I don't know this vb2py, but you can do a 2 pass conversion [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] -- By ZeD From vijayakumar.subburaj at gmail.com Sat Jan 17 05:09:36 2009 From: vijayakumar.subburaj at gmail.com (v4vijayakumar) Date: Sat, 17 Jan 2009 02:09:36 -0800 (PST) Subject: braces fixed '#{' and '#}' Message-ID: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> I saw some code where someone is really managed to import braces from __future__. ;) def test(): #{ print "hello" #} From dragosmocrii at gmail.com Sat Jan 17 05:16:14 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 02:16:14 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> On Jan 17, 11:48?am, "Gabriel Genellina" wrote: > En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo > gmane.comp.python.general > > > I am trying to make a testing script to load/save cookies to a file > > with FileCookieJar, but it results in this error: FileCookieJar has > > not attribute "_self_load" > > FileCookieJar is an abstract class, although it isn't clear at all from > the documentation. (You may want to file a documentation bug athttp://bugs.python.org) > You must instantiate a specific subclass (like MozillaCookieJar), which > determines the actual file format used. > > -- > Gabriel Genellina Oh, thank you so much. Using MozillaCookieJar works just fine. But could you please explain what an abstract class is (or where i can find documentation for this term). Thanks! From kay.schluehr at gmx.net Sat Jan 17 05:28:04 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 17 Jan 2009 02:28:04 -0800 (PST) Subject: English-like Python References: Message-ID: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> On 16 Jan., 02:02, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? No, but I've once written a Python dialect that uses German text. Just look at how amazing this result is !!! But be warned it requires knowledge of the German language. http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm > I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. As you know Python 3.0 has full unicode support. Python 4.0 will be surely written in Mandarin or Hindi. > For example, the following code... > > >>> import os > > >>> def list_files(dirname): > >>> ? ? for p in os.listdir(dirname): > >>> ? ? ? ? print p > > >>> list_files("some_dir") > > foo > bar > etc > > ...might be translated as... > > >>> Import the operating system module. > > >>> Define a new function as "list files" which accepts > > ? ? "a path" and does the following: > ? ? ? ? For every item in the list returned by the operating system's > ? ? ? ? directory listing of the given path, do the following: > ? ? ? ? ? ? ?Print the item. > > >>> List files from "some_dir". > > foo > bar > etc > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. Yep. Resolving ambiguities in natural languages is actually an open research topic. Moving from Python to a language that is more context dependent than Larry Wall ever dreamed about and launch an interpreter on the Enterprise is actually a worthwhile project for future generations. Kay From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:32:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:32:35 -0200 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo gmane.comp.python.general > I ran a few tests on the new Python 2.6 multiprocessing module before > migrating a threading code, and found out the locking code is not > working well. In this case, a pool of 5 processes is running, each > trying to get the lock and releasing it after waiting 0.2 seconds > (action is repeated twice). It looks like the multiprocessing lock > allows multiple locking after the second pass. Running the exact same > code with threads works correctly. I've tested your code on Windows and I think the problem is on the Queue class. If you replace the Queue with some print statements or write to a log file, the sequence lock/release is OK. You should file a bug report on http://bugs.python.org/ -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:42:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:42:46 -0200 Subject: multiprocessing question/error References: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> <200901170814.37728.lenz@joinville.udesc.br> Message-ID: En Sat, 17 Jan 2009 14:14:37 -0200, Eduardo Lenz escribi?: > Another question: is it possible to > change a bound method to a function on the fly ? I was wondering if > something > like class.__dict__["function_name"] could do the job. Exactly. Or, if you already have the method, use its im_func attribute to obtain the original function. BTW, im_self is the "self" argument. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 06:09:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 09:09:19 -0200 Subject: Python Startup file References: Message-ID: En Sat, 17 Jan 2009 02:23:40 -0200, Gary Smith escribi?: > I've never been able to get ActiveState Python's PythonWin to observe the > file referenced in the Windows PYTHONSTARTUP environment variable. > > Many thanks for pointing out the obvious to me AFAIK, PythonWin doesn't honor the PYTHONSTARTUP variable. IDLE does, but you have to use the -s option. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 06:33:48 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 09:33:48 -0200 Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> Message-ID: En Sat, 17 Jan 2009 08:16:14 -0200, Dragos escribi?: > On Jan 17, 11:48?am, "Gabriel Genellina" > wrote: >> En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo >> gmane.comp.python.general >> >> > I am trying to make a testing script to load/save cookies to a file >> > with FileCookieJar, but it results in this error: FileCookieJar has >> > not attribute "_self_load" >> >> FileCookieJar is an abstract class, although it isn't clear at all from >> the documentation. (You may want to file a documentation bug >> athttp://bugs.python.org) >> You must instantiate a specific subclass (like MozillaCookieJar), which >> determines the actual file format used. > > Oh, thank you so much. > Using MozillaCookieJar works just fine. > > But could you please explain what an abstract class is (or where i can > find documentation for this term). Thanks! Try http://en.wikipedia.org/wiki/Abstract_class In short, it's an incomplete class, with "holes" that subclasses must fill in order to get a complete, working class (a "concrete" class, as opposed to the "abstract" base). If you look at FileCookieJar, its load() method calls self._really_load but no such method exists in that class nor its ancestors (this explains the error you got). Subclasses of FileCookieJar *must* implement _really_load to be usable. It's customary to define the method anyway, and raise NotImplementedError; this serves two purposes: - document the expected interfase - error messages are more meaningful (FileCookieJar.save() is implemented this way; _really_load() should be the same) -- Gabriel Genellina From jstroud at mbi.ucla.edu Sat Jan 17 06:37:44 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 17 Jan 2009 03:37:44 -0800 Subject: Pythonic way to handle coordinates In-Reply-To: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: Pierre-Alain Dorange wrote: > What is the elegant way to handle coordinates ? > Do i need to continue using tuples or do i need to write a Point class. > I feel a point class would be nice, because i could implement operators > with it ? But i think Point class must exist allready ? My instinctive advice is to use a point class. My wise advice is to put it in a library you will maintain and reuse--or else you will find yourself re-writing point classes all of the time. A Point class will also give you a place to consolidate all of those methods specific to manipulating points. Thanks to python magic methods, you can also design some nifty shortcuts to access the attributes of your point. Here is a fun example for no other reason than I'm too tired to do anything important right now: class Point(object): def __init__(self, axes): self.axes_names = axes.split() self.axes = dict(enumerate(self.axes_names)) for axis in self.axes_names: setattr(self, axis, 0.0) def check_axis(self, i): if i not in self.axes: raise ValueError, "No such axis %s" % i def __setitem__(self, i, v): self.check_axis(i) setattr(self, self.axes[i], v) def __getitem__(self, i): self.check_axis(i) return getattr(self, self.axes[i]) def __iter__(self): return (getattr(self, i) for i in self.axes_names) def move(self, other): for i, v in enumerate(other): self[i] += v def magnitude(self): import math return math.sqrt(sum(v**2 for v in self)) E.g.: py> p = Point('x y z') py> list(p) [0.0, 0.0, 0.0] py> p.move([2, 3, 4]) py> p.x, p.y, p.z (2, 3, 4) py> p[0], p[1], p[2] (2, 3, 4) py> list(p) [2, 3, 4] py> tuple(p) (2, 3, 4) py> p.magnitude() 5.3851648071345037 py> q = Point('x y z') py> q.move([1, 2, 3]) py> p.move(q) py> list(p) [3.0, 5.0, 7.0] py> p[1] = 15.0 py> list(p) [3.0, 15.0, 7.0] With the introduction of the second point, q, one can begin to see the necessity for a class factory that produces Point classes of the desired dimensionalities in desired coordinate systems: def point(axes): class P(Point): def __init__(self, values): Point.__init__(self, axes) self.move(values) return P Note that we have have not used metaclasses--which would require messier code but produce classes that would potentially behave a better as super classes. The point function is used as simply as it is written: py> Point3D = point('x y z') py> p = Point3D([0.0, 0.0, 0.0]) py> list(p) [0.0, 0.0, 0.0] py> q = Point3D([5.0, 6.0, 7.0]) py> list(q) [5.0, 6.0, 7.0] py> p.move(q) py> list(p) [5.0, 6.0, 7.0] Incidentally, the classes returned by point are heritable, etc. class Point3D(point('x y z')): def __repr__(self): return "Point3D(%s)" % list(self) def __add__(self, other): return Point3D(sum(t) for t in zip(self, other)) py> p = Point3D([8, 7, 6]) py> p Point3D([8.0, 7.0, 6.0]) py> str(p) 'Point3D([8.0, 7.0, 6.0])' py> q = Point3D([5, 4, 3]) py> r = p + q py> r Point3D([13.0, 11.0, 9.0]) Now have fun with this stuff. I need to go to sleep. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From andrew at acooke.org Sat Jan 17 07:20:36 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 17 Jan 2009 04:20:36 -0800 (PST) Subject: Pythonic way to handle coordinates References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: although james's idea is quite neat (especially the idea of heritable classes), my initial reaction was that it's too over-engineered. so here's a different approach. there are two "tricks" that can help make using tuples easier: (1) unpacking the return value. (x, y) = returns_a_point() x += 1 (2) passing a tuple to a function that takes an x and a y value: def takes_two_values(x, y): ... p = (1, 2) takes_two_values(*p) and what I have done in the past is exploit these, so that functions/ methods that only takes a point takes two values while those that take many points, other arguments, etc, take a tuple. this sounds messy but works quite well because you tend to use the first kind of functions when you are changing coordinates (and then it is useful to treat a point as separate x and y values) and the second kind of functions when you are handling collections of points that don't need modifying. andrew From dragosmocrii at gmail.com Sat Jan 17 07:38:23 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 04:38:23 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> Message-ID: On Jan 17, 1:33?pm, "Gabriel Genellina" wrote: > En Sat, 17 Jan 2009 08:16:14 -0200, Dragos ? > escribi?: > > > > > On Jan 17, 11:48?am, "Gabriel Genellina" > > wrote: > >> En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo > >> gmane.comp.python.general > > >> > I am trying to make a testing script to load/save cookies to a file > >> > with FileCookieJar, but it results in this error: FileCookieJar has > >> > not attribute "_self_load" > > >> FileCookieJar is an abstract class, although it isn't clear at all from > >> the documentation. (You may want to file a documentation bug ? > >> athttp://bugs.python.org) > >> You must instantiate a specific subclass (like MozillaCookieJar), which > >> determines the actual file format used. > > > Oh, thank you so much. > > Using MozillaCookieJar works just fine. > > > But could you please explain what an abstract class is (or where i can > > find documentation for this term). Thanks! > > Tryhttp://en.wikipedia.org/wiki/Abstract_class > In short, it's an incomplete class, with "holes" that subclasses must fill ? > in order to get a complete, working class (a "concrete" class, as opposed ? > to the "abstract" base). > > If you look at FileCookieJar, its load() method calls self._really_load ? > but no such method exists in that class nor its ancestors (this explains ? > the error you got). Subclasses of FileCookieJar *must* implement ? > _really_load to be usable. > > It's customary to define the method anyway, and raise NotImplementedError; ? > this serves two purposes: > - document the expected interfase > - error messages are more meaningful > (FileCookieJar.save() is implemented this way; _really_load() should be ? > the same) > > -- > Gabriel Genellina Thanks, got it. From luismgz at gmail.com Sat Jan 17 07:51:46 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sat, 17 Jan 2009 04:51:46 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: On Jan 16, 5:27?pm, mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. > > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? > > Regards, > mk I believe that any book will give you enough information about python's objects behaviour. But if you want to understand the more esoteric aspects of python (I'm in the same situation), perhaps you should investigate decorators and metaclasses. A good starting point is the 3 article series in decorators by Bruce Eckel in Artima ( http://www.artima.com/weblogs/viewpost.jsp?thread=240808 ). I second the suggestion of reading samples and cookbooks, for example in ActiveState's site. I found particularly interesting one that shows how to implement an ORM under 100 lines ( http://code.activestate.com/recipes/496905/ ). This script goes deep into black magic and it's clear enough to grasp. Luis From dotancohen at gmail.com Sat Jan 17 08:00:35 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sat, 17 Jan 2009 15:00:35 +0200 Subject: English-like Python In-Reply-To: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> References: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> Message-ID: <880dece00901170500n43465493p8aa75fd4ecf3db85@mail.gmail.com> 2009/1/17 Kay Schluehr : > On 16 Jan., 02:02, The Music Guy wrote: >> Just out of curiousity, have there been any attempts to make a version >> of Python that looks like actual English text? > > No, but I've once written a Python dialect that uses German text. Just > look at how amazing this result is !!! But be warned it requires > knowledge of the German language. > > http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm > You might find HPL (Hebrew Programming Language) interesting: http://hpl.sourceforge.net/ HPL is PHP but with Hebrew operators, commands, and builtin functions. The interesting thing is that HPL is actually useful, as Hebrew and Arabic are written from right to left and many text editors get confused with RTL and LTR text on the same line. So typing in HPL looks better in the text editor and is more easily understood. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From vivainio at gmail.com Sat Jan 17 08:08:45 2009 From: vivainio at gmail.com (Ville Vainio) Date: Sat, 17 Jan 2009 05:08:45 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 2:57?pm, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... Isn't that a tad thankless and premature? It may be that the "support" aspect needs to be emphasized (currently, the paying customers get a priority over non-paying customers, but there are no formal support contracts), but if we assume that the usage of Qt & PyQt in commercial setting is going to skyrocket (I'd wager that it's a pretty safe assumption), selling plain support could prove very profitable as well - esp. since most PyQt users probably won't be too eager to start messing with SIP & fiddling around with Qt C++ plumbing. From mario.ruggier at gmail.com Sat Jan 17 08:09:13 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Sat, 17 Jan 2009 05:09:13 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> Message-ID: <8002c48c-6421-49a5-a613-22baba29abbc@r36g2000prf.googlegroups.com> On Jan 17, 12:04?am, ajaksu wrote: > On Jan 16, 3:45?pm, mario ruggier wrote: > > > > '(x for x in ()).throw("bork")' > > > What is the potential security risk with this one? > > I don't see a concrete issue, just found it tempting... raising hand- > crafted objects :) OK, I can think of no good reson why anyone would want to do that from within a temlate, so I'd be fine with blocking out any attribute whose name starts with "throw" to block this out. > > All the above attempts will be blocked this way. Any other disallow- > > sub-strings to add to the list above? > > None that I know of, but I suggest testing with dir, globals, locals > and '__' enabled (which I haven't done yet), as spotting possible > flaws should be easier. If you can get BOM+encoded garbage tested (seehttp://tinyurl.com/72d98y), it might be worth it too. The BOM stuff is interesting... from that discussion, I think it would be also a good idea to blacklist "object" out of the restricted builtins. I played with this, and prepared a file template as well as a little script to run it... see below. To tweak any disallwoed builtins back into the restricted namespace for testing, you can just do something like: d.set_on_globals("dir", dir) for each name you'd like to add, when setting up the domain (see script below). To re-enable "__" lookups, you'd need to tweak the regexp above, in the RestrictedEvaluator class. > This one fails in lots of interesting ways when you juggle keyword- > args around: > exprs = [ > ? ? 'evoque("hmm", filters=[unicode.upper ] ,src="/etc/python2.5/ > site.py")', > ] Not sure what you mean... it just renders that source code file uppercased (if it finds it as per the domain setup) ?!? Here's (a) a mini testing py2-py3 script, similar to previous one above but to read a template from a file (there may be additional tricks possible that way), and (b) a sample companion test template. evoque_restricted_file_test.py ---- # in lieu of print, py2/py3 import sys def pr(*args): sys.stdout.write(" ".join([str(arg) for arg in args])+'\n') # from os.path import abspath, join, dirname from evoque import domain, template # set the base for for the defualt collection DEFAULT_DIR = abspath((dirname(__file__))) # a restricted domain instance d = domain.Domain(DEFAULT_DIR, restricted=True, errors=3, quoting='str') # errors: 3 -> renders, 4 -> raises any evaluation errors, # see: http://evoque.gizmojo.org/usage/errors/ # Tweak domain.globals to add specific callables for testing: d.set_on_globals("dir", dir) d.set_on_globals("gobals", globals) d.set_on_globals("locals", locals) pr("domain", d.default_collection.dir, d.restricted and "RESTRICTED" or "*** unrestricted ***") t = d.get_template(restricted_exprs.txt) pr(t.evoque()) ---- restricted_exprs.txt ---- #[ BOM + encoded trickery Note: when evaluated in python interpreter: >>> eval("# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-") but when specified within a template here as: ${# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-} gives **pre-evaluation**: SyntaxError: unknown encoding: utf7 ]# ${"# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-"}, #[ Attempt to subversively build string expressions ]# Explicitly written target expression: ().__class__.mro() [1].__subclasses__() evaluates: ${().__class__.mro()[1].__subclasses__()} Subversive variation: "()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()" evaluates (to just the str!): ${"()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()"} Attempt to "set" same subsersively built expr to a loop variable and then "evaluate" that variable: $for{ expr in [ str("()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()") ] } evaluates (to just the str!): ${expr} attempt eval(...): ${eval(expr)} $rof (Note: evoque does not explicitly allow arbitrary setting of variables, except within for loops.) ---- mario From gnewsg at gmail.com Sat Jan 17 08:58:35 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 17 Jan 2009 05:58:35 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> Message-ID: <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> On 17 Gen, 05:26, John Machin wrote: > On Jan 17, 3:08?pm, Steve Holden wrote: > > > Giampaolo Rodola' wrote: > > > On 17 Gen, 04:43, Terry Reedy wrote: > > >> Giampaolo Rodola' wrote: > > >>> That would help to avoid replacing "" with b"" almost everywhere in my > > >>> code. > > >> Won't 2to3 do that for you? > > > > I used 2to3 against my code but it didn't cover the "" -> b"" > > > conversion (and I doubt it is able to do so, anyway). > > > Note that if you are using 2.6 you should first convert your "" quotes > > to b"" - this won't make any practical difference, but then you will be > > able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. > > Perhaps before we get too far down the track of telling the OP what he > should do, we should ask him a little about his intentions: > > Is he porting to 3.0 and abandoning 2.x support completely? > [presumably unlikely] No. > So then what is the earliest 2.x that he wants to support at the same > time as 3.x? [presumably at least 2.5] I currently support Python versions from 2.3 to 2.6 by using un unique codebase. My idea is to support 3.x starting from the last upcoming release. > Does he intend to maintain two separate codebases, one 2.x and the > other 3.x? I think I have no other choice. Why? Is theoretically possible to maintain an unique code base for both 2.x and 3.x? > Else does he intend to maintain just one codebase written in some 2.x > dialect and using 2to3 plus sys.version-dependent code for the things > that 2to3 can't/doesn't handle? I don't think it would worth the effort. > Cheers, > John Thanks a lot --- Giampaolo http://code.google.com/p/pyftpdlib From aahz at pythoncraft.com Sat Jan 17 09:09:29 2009 From: aahz at pythoncraft.com (Aahz) Date: 17 Jan 2009 06:09:29 -0800 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: [following up late] In article <2b3c916e-6908-4b12-933f-8f7bfa86cebc at i20g2000prf.googlegroups.com>, Russ P. wrote: > >Fair enough, but for code that is not intended for general public >usage (i.e., most code) so-called camelCase is every bit as good if >not better than using underscores to divide variable names. It saves a >few characters, and in my opinion it's significantly easier to read. >Identifiers divided by underscores always appear to me at first glance >to be multiple words, and I find that very annoying. > >So unless you think the standard library will someday include code for >air traffic management, I'll stick with camelCase, and I'll thank you >for not making an issue of it. You are missing the point: suppose you write a useful library in your air traffic management application, maybe one that does a good job of handling user input. If you have done a proper job of abstracting it from your application as a whole, you could easily publicize it, but it will never get into the standard library unless it meets current PEP8 guidelines. Why fuss about trying to figure out which parts of your application might in the future be published? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From gnewsg at gmail.com Sat Jan 17 09:11:30 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 17 Jan 2009 06:11:30 -0800 (PST) Subject: vb2py status? References: Message-ID: On 17 Gen, 11:05, Vito De Tullio wrote: > axtens wrote: > > So is vb2py dead? If not, any idea when it'll support python 3? > > I don't know this vb2py, but you can do a 2 pass conversion > > [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > > -- > By ZeD ...and presumibly get something which doesn't work at all. =) --- Giampaolo http://code.google.com/p/pyftpdlib From eliben at gmail.com Sat Jan 17 09:14:17 2009 From: eliben at gmail.com (eliben) Date: Sat, 17 Jan 2009 06:14:17 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 2:57?pm, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > Unlikely... The switch of Qt to LGPL will almost certainly vastly increase the Qt user base. Leaving very few and minor imperfections aside, Qt is a superior GUI library and programming framework, and its lack of free license seriously impeded adoption in the past. The increase in Qt use will also cause a great increase in PyQt use, and I would imagine Riverbank will be able to make a good living from consulting on PyQt topics, even if their sales from selling PyQt "licenses" decrease. Eli From martin at v.loewis.de Sat Jan 17 09:24:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 15:24:11 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> Message-ID: <4971ea0b$0$7055$9b622d9e@news.freenet.de> >> Does he intend to maintain two separate codebases, one 2.x and the >> other 3.x? > > I think I have no other choice. > Why? Is theoretically possible to maintain an unique code base for > both 2.x and 3.x? That is certainly possible! One might have to make tradeoffs wrt. readability sometimes, but I found that this approach works quite well for Django. I think Mark Hammond is also working on maintaining a single code base for both 2.x and 3.x, for PythonWin. Regards, Martin From aahz at pythoncraft.com Sat Jan 17 09:33:35 2009 From: aahz at pythoncraft.com (Aahz) Date: 17 Jan 2009 06:33:35 -0800 Subject: pep-8 vs. external interfaces? References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> <27c6b149-3a5f-478d-a6fc-da87a66b9d4c@r36g2000prf.googlegroups.com> Message-ID: In article <27c6b149-3a5f-478d-a6fc-da87a66b9d4c at r36g2000prf.googlegroups.com>, Carl Banks wrote: >On Jan 4, 1:47=A0pm, Roy Smith wrote: >> >> Or, I could draw a line in the sand and say, "If it's a protocol >> primitive, it stays as written. =A0Otherwise, it's pep-8". =A0That's a >> little uglier because it's not always obvious to the user exactly >> which names are protocol primitives and which are higher-level >> operations. > >So the question becomes, "Why are you mixing protocol primitives and >high-level operations in the same namespace?" Because that's not >normally a well-advised thing to do. > >1. If you answered, "I shouldn't be", you should separate them and use >camel case for the protocol primitives. > >2. If you answered, "I'm including protocol primitive functions >alongside high-level operations because conceptually they are the >same, it's just that some functions happen to map directly to the >underlying protocol", you should follow PEP-8, because by doing that >you've implicity raised the protocol primitive functions to high-level >status. > >3. If you answered, "Protocol primitives are in the same namespace for >convenience, but high-level users shouldn't use them", then you should >use camel case for the protocol primitives but prepend an underscore. > >4. If you answered, "I include those functions in the same namespace >because I am following the example of other language bindings in Perl, >Java, Ruby, etc.,", then figure out whether it's important to be >consistent with Perl, Java, Ruby, etc., and if so, do whatever they >did. If not, see #1. This deserves to be recorded on a web page somewhere -- can you stick it on the wiki? (I got laid off two weeks ago, so if you're too busy, would you like me to do it?) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From roy at panix.com Sat Jan 17 09:57:58 2009 From: roy at panix.com (Roy Smith) Date: Sat, 17 Jan 2009 09:57:58 -0500 Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: In article <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, v4vijayakumar wrote: > I saw some code where someone is really managed to import braces from > __future__. ;) > > def test(): > #{ > print "hello" > #} That usage is obsolete. Current best practice is: def test(): """{""" print "hello" """}""" From steve at holdenweb.com Sat Jan 17 10:05:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 17 Jan 2009 10:05:24 -0500 Subject: braces fixed '#{' and '#}' In-Reply-To: References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: Roy Smith wrote: > In article > <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, > v4vijayakumar wrote: > >> I saw some code where someone is really managed to import braces from >> __future__. ;) >> >> def test(): >> #{ >> print "hello" >> #} > > That usage is obsolete. Current best practice is: > > def test(): > """{""" > print "hello" > """}""" Which would be OK if it were syntactically valid ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jeff at jmcneil.net Sat Jan 17 10:42:47 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 07:42:47 -0800 (PST) Subject: tp_base, ob_type, and tp_bases Message-ID: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> Hi all, In an effort to get (much) better at writing Python code, I've been trying to follow and document what the interpreter does from main in Modules/python.c up through the execution of byte code. Mostly for my own consumption and benefit, but I may blog it if it turns out half way decent. Anyways, I've been going through PyType_Ready as it sets up copies of PyObjectType, and I'm a bit confused by tp_base, ob_type, and tp_bases. I've been using http://docs.python.org/c-api/index.html as a guideline. So, the documentation states that ob_type is a pointer to the type's type, or metatype. Rather, this is a pointer to the new type's metaclass? Next, we have tp_base. That's defined as "an optional pointer to a base type from which type properties are inherited." The value of tp_base is then added to the tp_bases tuple. This is confusing me. On the surface, it sound as though they're one in the same? I *think* (and dir() of a subclass of type seems to back it up), that tp_base is only at play when the object in question inherits from type? I've tried Googling around a bit. Perhaps it's better documented somewhere? Or perhaps someone can give me a quick explanation? Thanks! Jeff From schaefer.mp at gmail.com Sat Jan 17 10:46:54 2009 From: schaefer.mp at gmail.com (MatthewS) Date: Sat, 17 Jan 2009 07:46:54 -0800 (PST) Subject: Pyro deadlock Message-ID: <71ed81f9-7d95-44bc-8ad0-3c8e5869cb43@v5g2000pre.googlegroups.com> I'd like to know if the following behavior is expected and can be avoided: I have a Pyro server object that maintains a queue of work, and multiple Pyro worker objects that take work off the queue by calling a method on the server (get_work) and then return the work to the server by calling another method (return_result). The problem is that I experience a deadlock condition in the return_result method. Is this deadlock expected or should Pyro be able to synchronize the remote calls to server's callback method when called from multiple workers at the same time? If so any hints are appreciated. /Matthew From martin at v.loewis.de Sat Jan 17 10:50:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 16:50:37 +0100 Subject: tp_base, ob_type, and tp_bases In-Reply-To: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> Message-ID: <4971fe4d$0$30907$9b622d9e@news.freenet.de> > So, the documentation states that ob_type is a pointer to the type's > type, or metatype. Rather, this is a pointer to the new type's > metaclass? That's actually the same. *Every* ob_type field points to the object's type, e.g. for strings, integers, tuples, etc. That includes type objects, where ob_type points to the type's type, i.e. it's meta-type, also called metaclass (as "class" and "type" are really synonyms). > Next, we have tp_base. That's defined as "an optional pointer to a > base type from which type properties are inherited." The value of > tp_base is then added to the tp_bases tuple. This is confusing me. On > the surface, it sound as though they're one in the same? (I don't understand the English "one in the same" - interpreting it as "as though they should be the same") No: tp_bases is a tuple of all base types (remember, there is multiple inheritance); tp_base (if set) provides the first base type. > I *think* (and dir() of a subclass of type seems to back it up), that > tp_base is only at play when the object in question inherits from > type? No - it is the normal case for single inheritance. You can leave it NULL, which means you inherit from object. Regards, Martin From zak.mc.kraken at libero.it Sat Jan 17 10:52:10 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sat, 17 Jan 2009 16:52:10 +0100 Subject: vb2py status? References: Message-ID: Giampaolo Rodola' wrote: >> > So is vb2py dead? If not, any idea when it'll support python 3? >> I don't know this vb2py, but you can do a 2 pass conversion >> [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > ...and presumibly get something which doesn't work at all. =) why? AFAIK there aren't problems into the 2to3 phase I don't think the resulted python code would be the best one, but at least it should work... -- By ZeD From jeff at jmcneil.net Sat Jan 17 11:09:30 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 08:09:30 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > So, the documentation states that ob_type is a pointer to the type's > > type, or metatype. Rather, this is a pointer to the new type's > > metaclass? > > That's actually the same. *Every* ob_type field points to the object's > type, e.g. for strings, integers, tuples, etc. That includes type > objects, where ob_type points to the type's type, i.e. it's meta-type, > also called metaclass (as "class" and "type" are really synonyms). > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > base type from which type properties are inherited." ?The value of > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > the surface, it sound as though they're one in the same? > > (I don't understand the English "one in the same" - interpreting it > as "as though they should be the same") > > No: tp_bases is a tuple of all base types (remember, there is multiple > inheritance); tp_base (if set) provides the first base type. > > > I *think* (and dir() of a subclass of type seems to back it up), that > > tp_base is only at play when the object in question inherits from > > type? > > No - it is the normal case for single inheritance. You can leave it > NULL, which means you inherit from object. > > Regards, > Martin Thank you! It was tp_base that was confusing me. The tp_bases member makes sense as Python supports multiple inheritance. It wasn't immediately clear that tp_base is there for single inheritance reasons. It's all quite clear now. Is that an optimization of sorts? Jeff From jeff at jmcneil.net Sat Jan 17 11:12:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 08:12:19 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> Message-ID: <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> On Jan 17, 11:09?am, Jeff McNeil wrote: > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > > So, the documentation states that ob_type is a pointer to the type's > > > type, or metatype. Rather, this is a pointer to the new type's > > > metaclass? > > > That's actually the same. *Every* ob_type field points to the object's > > type, e.g. for strings, integers, tuples, etc. That includes type > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > also called metaclass (as "class" and "type" are really synonyms). > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > base type from which type properties are inherited." ?The value of > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > the surface, it sound as though they're one in the same? > > > (I don't understand the English "one in the same" - interpreting it > > as "as though they should be the same") > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > inheritance); tp_base (if set) provides the first base type. > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > tp_base is only at play when the object in question inherits from > > > type? > > > No - it is the normal case for single inheritance. You can leave it > > NULL, which means you inherit from object. > > > Regards, > > Martin > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > makes sense as Python supports multiple inheritance. ?It wasn't > immediately clear that tp_base is there for single inheritance > reasons. It's all quite clear now. > > Is that an optimization of sorts? > > Jeff Well, maybe not specifically for single inheritance reasons, I just didn't see an immediate reason to keep a separate pointer to the first base type. From fuzzyman at gmail.com Sat Jan 17 11:12:38 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Sat, 17 Jan 2009 08:12:38 -0800 (PST) Subject: vb2py status? References: Message-ID: <4c5e5a69-b4bf-4180-a7e2-ecfc2f52f5ce@v39g2000pro.googlegroups.com> On Jan 17, 3:52?pm, Vito De Tullio wrote: > Giampaolo Rodola' wrote: > >> > So is vb2py dead? If not, any idea when it'll support python 3? > >> I don't know this vb2py, but you can do a 2 pass conversion > >> [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > > ...and presumibly get something which doesn't work at all. =) > > why? > AFAIK there aren't problems into the 2to3 phase > I don't think the resulted python code would be the best one, but at least > it should work... > > -- > By ZeD 2to3 is far from perfect, and assuming the same is true of vb2py (inevitably) then you get imperfection squared. :-) Michael Foord -- http://www.ironpythoninaction.com/ From lenz at joinville.udesc.br Sat Jan 17 11:14:37 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Sat, 17 Jan 2009 08:14:37 -0800 Subject: multiprocessing question/error In-Reply-To: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> References: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> Message-ID: <200901170814.37728.lenz@joinville.udesc.br> On Saturday 17 January 2009 00:43:35 Aaron Brady wrote: > On Jan 16, 11:39?pm, Eduardo Lenz wrote: > > Hi, > > > > I was using the former processing package with python 2.5 with no > > problems. After switching to python 2.6.1 I am having some problems with > > the same code. The problem seems to be related to the fact that I am > > using Pool.map with a bounded method, since it is inside a class. To > > clarify a little bit, let me show some parts of the code .... > > Hello, > > > class Pygen3(self).... > > I infer this was a typo. > > > ? ? .... > > ? ? .... > > ? ? .... > > ? ? def calcula(self,indiv): > > ? ? ? ? .... > > ? ? ? ? .... > > ? ? ? ? .... > > > > ? ?def evaluate(self): > > ? ? ?.... > > ? ? ?.... > > ? ? indiv = range(mult*self.popsize,(mult+1)*self.popsize) > > ? ?pool = Pool(processes=nproc) > > ? ?results = pool.map(self.calcula,indiv) > > I infer the indentation drifted. > > > ? ?... > > ? ?... > > > > the error is the following > > > > Exception in thread Thread-1: > > Traceback (most recent call last): > > ? File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner > > ? ? self.run() > > ? File "/usr/lib/python2.6/threading.py", line 477, in run > > ? ? self.__target(*self.__args, **self.__kwargs) > > ? File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > > _handle_tasks > > ? ? put(task) > > PicklingError: Can't pickle : attribute lookup > > __builtin__.instancemethod failed > > > > Thanks for your help. > > Checking on two typos above. I have this working: > > from multiprocessing import Process > > class C(object): > def m1( self ): > p1 = Process(target=self.m2, args=('bob1',)) > p2 = Process(target=self.m2, args=('bob2',)) > p1.start() > p2.start() > p1.join() > p2.join() > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > But I get the same error as you with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= range( 10 ) > pool= Pool( 5 ) > results = pool.map(self.m2,arg) > print results > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > I build a workaround with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= zip( [ self ]* 10, range( 10 ) ) > pool= Pool( 5 ) > results = pool.map(C_m2,arg) > print results > def m2( self, arg ): > print 'hello', arg > return arg* 2 > def C_m2( ar, **kwar ): > return C.m2( *ar, **kwar ) > > if __name__ == '__main__': > c= C() > c.m1() > > Note that you have to explicitly include 'self' as a first parameter > when packing the arguments, and then explicitly unpack it in the > helper function. Also, wrapping 'm2' with '@staticmethod' also fails > with this error: > > Exception in thread Thread-1: > Traceback (most recent call last): > File "c:\programs\python26\lib\threading.py", line 522, in > __bootstrap_inner > self.run() > File "c:\programs\python26\lib\threading.py", line 477, in run > self.__target(*self.__args, **self.__kwargs) > File "c:\programs\python26\lib\multiprocessing\pool.py", line 225, > in _handle_tasks > put(task) > PicklingError: Can't pickle : attribute lookup > __builtin__.function failed > > If this works for you, it's possible to make the helper function more > dynamic, by accepting a class name and an attribute name as string > arguments, then retrieving them in the subprocesses. > -- > http://mail.python.org/mailman/listinfo/python-list Thanks for your help ! The only question remaninig is why it iused to work with the former processing package. Another question: is it possible to change a bound method to a function on the fly ? I was wondering if something like class.__dict__["function_name"] could do the job. Actually, I was wondering with something like a casting, but a guess it is not possible. Thanks again, Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From alan.isaac at gmail.com Sat Jan 17 11:39:32 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 16:39:32 GMT Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> On 1/16/2009 6:44 PM Terry Reedy apparently wrote: > http://bugs.python.org/issue4966 Is this another lacuna or am I overlooking it? I cannot find the 3.0 documentation of string formatting with the ``%`` operator. Thanks, Alan Isaac From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 11:45:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 16:45:02 GMT Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> Message-ID: <0182018b$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 00:24:21 -0800, Aaron Brady wrote: > Can you make it work for a 3-way lookup? What do you mean "3-way lookup"? I'm going to take a guess... A maps to B, B maps to C, and C maps to A. Is that what you mean? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 11:55:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 16:55:16 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <018203f2$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 06:09:29 -0800, Aahz wrote: > You are missing the point: suppose you write a useful library in your > air traffic management application, maybe one that does a good job of > handling user input. If you have done a proper job of abstracting it > from your application as a whole, you could easily publicize it, but it > will never get into the standard library unless it meets current PEP8 > guidelines. Why fuss about trying to figure out which parts of your > application might in the future be published? You know, it is quite possible that some people may not care whether or not their code ends up in the standard library. Holding out the possibility of inclusion in the std lib may not be quite the encouragement you expect :) -- Steven From mario.ruggier at gmail.com Sat Jan 17 12:11:50 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Sat, 17 Jan 2009 09:11:50 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> <8002c48c-6421-49a5-a613-22baba29abbc@r36g2000prf.googlegroups.com> Message-ID: <1b4acd69-d35f-405a-9da9-a180acaa9e84@p2g2000prn.googlegroups.com> Just to add that a further potential subversion possibility could have been to build the expr in some way from within a template, and then dynamically setting that string as the source of a new template with from_string=True. This is precisely the reason why **from within a template** evoque has never supported the from_string parameter i.e. you *cannot* "load/create" a template from a string source from within another template -- you may *only* do that from within the python app. To illustrate, an extension of the previous example template could thus become: $for{expr in [ str("()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()") ]} ${% evoque("test", src="$${"+expr+"}", from_string=True) %} $rof That would fail, as it would simply take the value of src i.e. "$ {().__class__.mro()[1].__subclasses__()}" to mean the sub-path to the template file within the collection (from_string would be simply interpreted as an evaluation data parameter). See: http://evoque.gizmojo.org/directives/evoque/ From xahlee at gmail.com Sat Jan 17 12:16:07 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:16:07 -0800 (PST) Subject: reading file to list References: Message-ID: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby Here's a interesting toy problem posted by Drew Krause to comp.lang.lisp: ------------------------ On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) ----------------- Here's a emacs lisp version: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (defvar mylist '() "result list" ) (setq mylist '()) ; init in case eval'd again (mapc (lambda (x) (setq mylist (cons (split-string x " ") mylist )) ) (read-lines "xxblob.txt") ) The above coding style is a typical maintainable elisp. In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)). Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that. The ?read-lines? function really should be a built-in part of elisp. It is not so mostly because emacs people have drawn themselves into a elitist corner, closing off to the outside world. (i am sending a suggestion to the official emacs dev list on adding read-line now.) ----------------- w_a_x_... at yahoo.com gave a ruby solution: IO.readlines("blob.txt").map{|line| line.split } augumented by Jilliam James for result to be numbers: IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} Very beautiful. ------------------- That's really the beauty of Ruby. This problem and ruby code illustrates 2 fundamental problems of lisp, namely, the cons problem, and the nested syntax pain. Both of which are practically unfixable. The lisp's cons fundamentally makes nested list a pain to work with. Lisp's nested syntax makes functional sequencing cumbersome. In the ruby code, its post-fix sequential notation (as a side effect of its OOP notation) brings out the beauty of functional sequencing paradigm (sometimes known as functional chain, sequencing, filtering, unix piping). its list, like all modern high level langs such as perl, php, python, javascript, don't have the lisp's cons problem. The cons destroys the usability of lists up-front, untill you have some at least 2 full-time years of coding lisp to utilize cons properly. (and even after that, it is still a pain to work with, and all you gain is a bit of speed optimization in rare cases that requires largish data, most of which has better solutions such as a database.) Both of these problems i've published articles on. For more detail on the cons problem, see the section ?The Cons Business? at ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html For more detail on the nested syntax problem for function chaining, see the section ?How Purely Nested Notation Limits The Language's Utility? at: ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html Xah ? http://xahlee.org/ ? From tekion at gmail.com Sat Jan 17 12:20:34 2009 From: tekion at gmail.com (tekion) Date: Sat, 17 Jan 2009 09:20:34 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <49665986.7080301@thechases.com> Message-ID: On Jan 9, 6:05?am, Tim Chase wrote: > Tim Chase wrote: > > tekion wrote: > >> Is there a module where you could figure week of the day, like where > >> it starts and end. I need to do this for a whole year. Thanks. > > > the monthcalendar() call returns the whole month's calendar which > > may be more what you want for the big-picture. > > And if you want a whole year's worth, you can get pretty close with: > > ? ?import itertools as i > ? ?import calendar as c > ? ?for month in range(1,13): > ? ? ?for week in c.monthcalendar(2009, month): > ? ? ? ?print repr(w) > > You don't detail how you want the month-boundaries to behave, so > this gives "calendar"'s default behavior of filling in zeros on > month-boundaries, so November through the 1st week in Dec 2009 > comes back as > > ? ?... > ? ?[0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], > ? ?[0, 1, 2, 3, 4, 5, 6], > ? ?... > > rather than > > ? ?... > ? ?[26, 27, 28, 29, 30, 31, 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, 1, 2, 3, 4, 5, 6], > ? ?... > > -tkc Thanks, this is exactly what I am looking for. I will give it a try. Do you what argument or documentation I should read up on how to get the month's boundary rather than the default. I would assume it's just an argument I give when creating the month object. From digitig at gmail.com Sat Jan 17 12:21:24 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 17 Jan 2009 17:21:24 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: 2009/1/3 Russ P. : > So unless you think the standard library will someday include code for > air traffic management, I'll stick with camelCase, and I'll thank you > for not making an issue of it. Another late comment, sorry, but as an air traffic management safety consultant, I'm quite interested about where in ATM you plan to use Python code, and how you will be meeting the applicable safety standards in the relevant administration. -- Tim Rowe From tino at wildenhain.de Sat Jan 17 12:29:05 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 18:29:05 +0100 Subject: reading file to list In-Reply-To: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: <49721561.8080204@wildenhain.de> Xah Lee wrote: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby > ... > OK, I want to create a nested list in Lisp (always of only integers) > from a text file, such that each line in the text file would be > represented as a sublist in the 'imported' list. > > example of a file's content > > 3 10 2 > 4 1 > 11 18 > > example of programing behavior > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > In a show-off context, it can be reduced to by about 50%, but still > far verbose than ruby or say perl (which is 1 or 2 lines. (python > would be 3 or 5)). So? Please count the lines: [line.strip().split() for line in file("blob.txt")] HTH Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From xahlee at gmail.com Sat Jan 17 12:34:39 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:34:39 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: <80a40799-d1c6-41ca-9fcc-82d3977ffa8d@e1g2000pra.googlegroups.com> On Jan 17, 9:16 am, Xah Lee wrote: > Here's a interesting toy problem posted by Drew Krause to > comp.lang.lisp: > ... The code in my previous elisp code got a bump. It should be: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (mapcar (lambda (x) (split-string x " ") ) (read-lines "xxblob.txt") ) The article is now archived at: ? A Ruby Illustration of Lisp Problems http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Xah ? http://xahlee.org/ ? From oc2007d5egjeqi01ecf0sw at newsguy.com Sat Jan 17 12:36:20 2009 From: oc2007d5egjeqi01ecf0sw at newsguy.com (Richard Hanson) Date: Sat, 17 Jan 2009 09:36:20 -0800 Subject: Jerry Pournelle gives award to Python and Guido for 2008 Message-ID: [NB: Blatant Python advocacy (and OP self-promotion).] Jerry Pournelle commends Python and Guido in "The Annual Orchid and Onions Parade" portion of his Chaos Manor Reviews column: > A reader [full-disclosure: that reader was me] nominated Python for an Orchid for Jerry's Orchid and Onions awards for 2008: ''' I nominate the computer language Python for an Orchid for 2008. This last year, Python broke through into worldwide popularity. The volunteer team led by BDFL (benevolent dictator for life) Guido van Rossum released "Python 3000" (Python 3.0) before year's end as well as releasing the next production-line 2.x version, Python 2.6. Python -- and Linux (the kernel) with its "BDFL" Linus Torvalds -- show that benevolent dictatorships are great forms of organization which can easily beat out other forms of cooperation in software development unable to escape Pournelle's Iron Law, whether proprietary *or* open-source software [...]. ''' Jerry Pournelle followed up with: ''' I completely agree with this. Python deserves a large Orchid. It's useful, well structured, easy to learn, and powerful. I use it to write quick filter functions among other things. I'm pleased to hand Guido a big Orchid. [...] ''' I add: Great job, Guido and all! -- Richard Hanson From google at mrabarnett.plus.com Sat Jan 17 12:44:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 17:44:12 +0000 Subject: reading file to list In-Reply-To: <49721561.8080204@wildenhain.de> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> Message-ID: <497218EC.9070108@mrabarnett.plus.com> Tino Wildenhain wrote: > Xah Lee wrote: >> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby >> >> > ... >> OK, I want to create a nested list in Lisp (always of only integers) >> from a text file, such that each line in the text file would be >> represented as a sublist in the 'imported' list. >> >> example of a file's content >> >> 3 10 2 >> 4 1 >> 11 18 >> >> example of programing behavior >> (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > >> >> In a show-off context, it can be reduced to by about 50%, but still >> far verbose than ruby or say perl (which is 1 or 2 lines. (python >> would be 3 or 5)). > > So? Please count the lines: > > [line.strip().split() for line in file("blob.txt")] > The original requirement was for a list of lists of integers: [[int(x) for x in line.split()] for line in open("blob.txt")] Still only 1 line, though. From gupta.neha at gmail.com Sat Jan 17 12:48:33 2009 From: gupta.neha at gmail.com (Neha Gupta) Date: Sat, 17 Jan 2009 09:48:33 -0800 (PST) Subject: psycopg2 weirdness Message-ID: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Hey, I only have little experience with web.py and psycopg2 and am running into a weird problem, I'd appreciate any help I can get with debugging it. I wrote a simple program that works and I don't see any crash: ---- import psycopg2 try: database_conn = psycopg2.connect("dbname='dbname' user='username' host='hostname'"); except: print "Unable to connect to the database!" database_conn.set_isolation_level(0) cur = database_conn.cursor(); while True: query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '01-05-2007' group by origin, crs_dep_hour order by origin, crs_dep_hour"; cur.execute(query) rows = cur.fetchall() print rows ----- However, I have a small website built using web.py framework which has a date picker that lets the user pick a date and it takes the user to a new url such as: localhost:8080/departures/01-05-2007. I issue a query to my database for the date selected by the user and retrieve the results. The problem now is that if I select different dates directly by changing the url then everything works but as soon as I pick a date from date picker the server crashes. I removed the date picker and made it just a text box but as soon as I hit the submit button, server crashes so I know it is not the date picker that causing trouble. --- class departures: def buildDepartureTableHtml(self, date): web.debug('date', date) # Issue the query. # select avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '2007-02-15' group by origin, crs_dep # _hour order by origin, crs_dep_hour; try: web.debug("About to issue query") # query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '" + date + "' group by origin, crs_dep_hour order by origin, crs_dep_hour"; query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '01-05-2007' group by origin, crs_dep_hour order by origin, crs_dep_hour"; cur.execute(query) web.debug('query executed!') rows = cur.fetchall() web.debug('rows fetched!') web.debug(rows) except Exception, e: print repr(e) database_conn.rollback() return "
Invalid Date
" -- // JS code function submitForm() { var date = ($("date").value).replace(/\//g,"-"); window.location = "http://" + window.location.host + "/ departures/" + date; } You can see above that I even ignored the date passed from the form and I have hardcoded '01-05-2007'. The message "About to issue query" gets printed as well as the right date chosen from the date picker but then I see the following: Assertion failed: (str != NULL), function PyString_FromString, file Objects/stringobject.c, line 107. Abort trap with a pop that says: "The application Python quit unexpectedly. The problem may have been caused by the _psycopg.so plug-in". -- I don't understand the error message above. The date did get passed correctly and am now not even using it, I use the hard coded date. So what is going on? Any help would be great. Thank you! Neha From ym5d19.python at gmail.com Sat Jan 17 12:48:50 2009 From: ym5d19.python at gmail.com (yang michael) Date: Sun, 18 Jan 2009 01:48:50 +0800 Subject: python3.0 base64 error Message-ID: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> I use base64 module on python3.0 like: import base64 b="hello world" a=base64.b64encode(b) print(a) but when i run it,it catch a error: Traceback (most recent call last): File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in a=base64.b64encode(b) File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode raise TypeError("expected bytes, not %s" % s.__class__.__name__) TypeError: expected bytes, not str and also the document's example: >>> import base64 >>> encoded = base64.b64encode('data to be encoded') >>> encoded 'ZGF0YSB0byBiZSBlbmNvZGVk' >>> data = base64.b64decode(encoded) >>> data 'data to be encoded' can not run too. what happen? -------------- next part -------------- An HTML attachment was scrubbed... URL: From xahlee at gmail.com Sat Jan 17 12:55:43 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:55:43 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <80a40799-d1c6-41ca-9fcc-82d3977ffa8d@e1g2000pra.googlegroups.com> Message-ID: <753b9f72-1c1a-41aa-ad7f-74ba38b30d60@w39g2000prb.googlegroups.com> On Jan 17, 9:34 am, Xah Lee wrote: > The code in my previous elisp code got a bump. It should be: > ... > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Sorry again. More correction: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (mapcar (lambda (x) (mapcar (lambda (y) (string-to-number y) ) (split-string x " ") ) ) (read-lines "xxblob.txt") ) this is last post of correction. Xah ? http://xahlee.org/ ? From tino at wildenhain.de Sat Jan 17 13:25:12 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 19:25:12 +0100 Subject: reading file to list In-Reply-To: <497218EC.9070108@mrabarnett.plus.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> Message-ID: <49722288.4080304@wildenhain.de> MRAB wrote: > Tino Wildenhain wrote: >> Xah Lee wrote: >>> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby >>> >>> >> ... >>> OK, I want to create a nested list in Lisp (always of only integers) >>> from a text file, such that each line in the text file would be >>> represented as a sublist in the 'imported' list. >>> >>> example of a file's content >>> >>> 3 10 2 >>> 4 1 >>> 11 18 >>> >>> example of programing behavior >>> (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) >> >>> >>> In a show-off context, it can be reduced to by about 50%, but still >>> far verbose than ruby or say perl (which is 1 or 2 lines. (python >>> would be 3 or 5)). >> >> So? Please count the lines: >> >> [line.strip().split() for line in file("blob.txt")] >> > The original requirement was for a list of lists of integers: Actually I read: "Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that." So I felt that requirement was dropped, but otherwise, you are right :-) > [[int(x) for x in line.split()] for line in open("blob.txt")] > > Still only 1 line, though. Yep. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From tino at wildenhain.de Sat Jan 17 13:43:03 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 19:43:03 +0100 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <497226B7.7040404@wildenhain.de> Neha Gupta wrote: > Hey, > ... > crs_dep_hour, origin from flightdata where date = '" + date + "' group ^^^^^^^^^^^ never ever do that! Even more when input comes from user. The correct form is cur.exec("... date = %s group by ...",(date,)) please see dbapi2 documentation or examples which come with psycopg2. ... > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. The message "About to issue query" > gets printed as well as the right date chosen from the date picker but > then I see the following: > > Assertion failed: (str != NULL), function PyString_FromString, file > Objects/stringobject.c, line 107. > Abort trap > > with a pop that says: "The application Python quit unexpectedly. The > problem may have been caused by the _psycopg.so plug-in". > -- > I don't understand the error message above. The date did get passed > correctly and am now not even using it, I use the hard coded date. So > what is going on? Do other querys work within your application? Looks like the components of the db layer are not correctly found. This can happen if the environment of the web server differs from your personal user when you are testing your scripts. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From philip at semanchuk.com Sat Jan 17 13:50:21 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 17 Jan 2009 13:50:21 -0500 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <3AE6CE69-7207-42BE-9F3E-61C09724B80C@semanchuk.com> On Jan 17, 2009, at 12:48 PM, Neha Gupta wrote: > Hey, > > I only have little experience with web.py and psycopg2 and am running > into a weird problem, I'd appreciate any help I can get with debugging > it. Hi Neha, There's a lot of pieces involved here and your subject implies you've isolated the problem to psycopg2, but I'm not convinced. > I know it is not the date picker that > causing trouble. So don't confuse us by mentioning it. =) > class departures: > def buildDepartureTableHtml(self, date): > web.debug('date', date) > try: > web.debug("About to issue query") > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > web.debug('query executed!') > rows = cur.fetchall() > web.debug('rows fetched!') > web.debug(rows) > except Exception, e: > print repr(e) > database_conn.rollback() > return "
Invalid Date
" > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. That's a good first step. Simplify even further. What happens if you simplify the query? FOr instance: SELECT 1, 2 as crs_dep_hour, origin from flightdata where date = '01-05-2007' If a simple query like that doesn't work, I suspect you have something fundamental wrong with your setup. HTH Philip From google at mrabarnett.plus.com Sat Jan 17 14:10:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 19:10:05 +0000 Subject: python3.0 base64 error In-Reply-To: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> References: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> Message-ID: <49722D0D.6020307@mrabarnett.plus.com> yang michael wrote: > I use base64 module on python3.0 > like: > > import base64 > b="hello world" Try: b = b"hello world" instead. > a=base64.b64encode(b) > print(a) > > but when i run it,it catch a error: > Traceback (most recent call last): > File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in > a=base64.b64encode(b) > File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode > raise TypeError("expected bytes, not %s" % s.__class__.__name__) > TypeError: expected bytes, not str > > > > and also the document's example: > >>>> import base64 >>>> encoded = base64.b64encode('data to be encoded') > >>>> encoded > 'ZGF0YSB0byBiZSBlbmNvZGVk' >>>> data = base64.b64decode(encoded) > >>>> data > 'data to be encoded' > > can not run too. > > what happen? > As the traceback says, it needs bytes, not string. Perhaps the example would've been clearer as: >>> import base64 >>> encoded = base64.b64encode(b'data to be encoded') From alan.isaac at gmail.com Sat Jan 17 14:12:45 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 19:12:45 GMT Subject: Python 3: exec arg 1 Message-ID: In Python 3, you can no longer ``exec(open(filename))``. I guess the reason is that in 3.0 ``open`` returns a stream, instead of open file, and exec wants "a string, bytes, or code object" and not a "TextIOWrapper". So it returns an error. Is it intentional that ``exec`` cannot handle a TextIOWrapper? Bottom line: has ``execfile(filename)`` really become ``exec(open(filename).read())``? Is this a good thing? Thanks, Alan Isaac From scott.p.macdonald at gmail.com Sat Jan 17 14:13:00 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sat, 17 Jan 2009 12:13:00 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista Message-ID: I googled a bit this morning search for an answer to this problem but have come up empty so far. Can anyone help? Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 Traceback (most recent call last): File "", line 1, in File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in import httplib File "C:\dev\opt\Python25\Lib\httplib.py", line 71, in import socket File "C:\dev\opt\Python25\Lib\socket.py", line 70, in _realssl = ssl NameError: name 'ssl' is not defined >>> NameError: name 'ssl' is not defined By way of comparison here is Python 2.5.2 on the same machine: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> Whats going on?? Thanks, Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From gert.cuykens at gmail.com Sat Jan 17 14:34:39 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 11:34:39 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) Message-ID: I expected that py3 did not converted the b'...' indication too ? b'afc76815e3fc429fa9d7' From digitig at gmail.com Sat Jan 17 14:36:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 17 Jan 2009 19:36:18 +0000 Subject: English-like Python In-Reply-To: <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> Message-ID: 2009/1/16 has : > http://www.alice.org/ Ooh, "JavaLikeSyntax.py" indeed! Why not "PythonLikeSyntax", since that's apparently what they used! -- Tim Rowe From roy at panix.com Sat Jan 17 14:38:24 2009 From: roy at panix.com (Roy Smith) Date: Sat, 17 Jan 2009 14:38:24 -0500 Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: In article , Steve Holden wrote: > Roy Smith wrote: > > In article > > <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, > > v4vijayakumar wrote: > > > >> I saw some code where someone is really managed to import braces from > >> __future__. ;) > >> > >> def test(): > >> #{ > >> print "hello" > >> #} > > > > That usage is obsolete. Current best practice is: > > > > def test(): > > """{""" > > print "hello" > > """}""" > > Which would be OK if it were syntactically valid ... > > regards > Steve Doh. I'm sorry: def test(): """{""" print "hello" """}""" This one I tested :-) From martin.hellwig at dcuktec.org Sat Jan 17 14:40:45 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 17 Jan 2009 19:40:45 +0000 Subject: braces fixed '#{' and '#}' In-Reply-To: References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: <4972343d$0$198$e4fe514c@news.xs4all.nl> Roy Smith wrote: > In article , > Steve Holden wrote: > >> Roy Smith wrote: >>> In article >>> <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, >>> v4vijayakumar wrote: >>> >>>> I saw some code where someone is really managed to import braces from >>>> __future__. ;) >>>> >>>> def test(): >>>> #{ >>>> print "hello" >>>> #} >>> That usage is obsolete. Current best practice is: >>> >>> def test(): >>> """{""" >>> print "hello" >>> """}""" >> Which would be OK if it were syntactically valid ... >> >> regards >> Steve > > Doh. I'm sorry: > > def test(): > """{""" > print "hello" > """}""" > > This one I tested :-) print is deprecated use print() :-) -- mph From bdesth.quelquechose at free.quelquepart.fr Sat Jan 17 14:49:38 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 17 Jan 2009 20:49:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <497243fa$0$20693$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 15, 12:21 pm, Bruno Desthuilliers > wrote: > >> Once again, the important point is that there's a *clear* distinction >> between interface and implementation, and that you *shouldn't* mess with >> implementation. > > If you "*shouldn't* mess with the implementation", then what is wrong > with enforcing that "shouldn't" in the language itself? Because sometimes you have a legitimate reason to do so and are ok to deal with the possible issues. > Why leave to > coding standards and company policy what can be encoded right into the > language? Because human are smarter than computers. > Why leave to humans (who are known to err) what can be > automated relatively easily? Isn't that what computers are for? Error is human. For a real catastrophic failure, it requires a computer. >> But what, some people think programmers are stupid, and >> so they hire stupid programmers, so they need b&d languages to protect >> stupid programmers from themselves - which just doesn't work, since >> *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb >> getter/setter pairs for _each and any_ attribute ? > > Hey, I share your distaste for Java and C++. I'm not talking about the languages by themselves, but about the gap between what they pretend to promote and how they are usually used. > All those "setters" and > "getters" are a kludge. I think Python "properties" are a major step > forward here. Just for fun, I checked to see if Scala has properties. > Guess what? Not only does it have them, but they are generated > automatically for all member data. That's even better than Python > properties! Oh yes ? "Better", really ? So it's better to have a language that automagically breaks encapsulation (requiring an additionnal level of indirection) than a language that do the right thing by default ? I'm afraid I missed the point ??? >>> As I said before, enforced encapsulation may not be appropriate for >>> every application, but it is definitely appropriate for some. >> No. It is appropriate for dummy managers hiring dummy programmers. The >> project's size and domain have nothing to do with it. > > Let me try to be very clear here. We are dealing with two separate but > related issues. The first is whether data hiding should be added to > Python. No need to add it, it's already there : every name that starts with an underscore is hidden !-) > The second is whether data hiding provides any net benefit in > *any* language. If it doesn't provide any benefit in Python, then it doesn't provide any benefit in any language. > As for whether data hiding should be added to Python, I am not arguing > one way or the other. I am merely saying that it is worth considering. It is not. > Whether it can be added without screwing up the language, I don't > know. If not, then so be it. That just limits the range of domains > where Python is suitable. That's just plain stupid. > As for whether data hiding provides a net benefit in any language, it > certainly does for large programs and for safety-critical programs. > For large, safety-critical systems, it's a no-brainer. Only if you fail to use your brain. Now, except for regurgitating the official OMG prose, do you have *anything* to back these claims ? Python is older than Java, and there are quite enough man/years of experience and Python success stories to prove that it *just work*. > I think data > hiding can also provide net benefits for medium-size and even smaller > programs, but lets just consider large programs, so I can shoot down > your argument that data hiding provides no benefit. C'mon, make my day... > I like to use the example of the flight software for a large > commercial transport aircraft, but many other examples could be given. > How about medical systems that control radiation therapy or > chemotherapy? How about financial systems that could take away your > retirement account in 1.5 milliseconds. Or how about the control > software for the strategic nuclear arsenals of the US or Russia? When > you consider the sea, air, and land-based components, I'm sure that's > one hell of a lot of code! And ? Such systems have been written (and quite a lot are still running) with languages way more permissive than Python. You know, languages like C or assembly. Until you understand that *no technology is idiot-proof*, you'll get nowhere in "software engineering". > So let's take the airplane example. Boeing and its contractors > probably has hundreds of programmers working on millions of lines of > code. And ? > If they believed you, they would abandon enforced data hiding, > and programmers would have much more discretion to screw around with > code that they don't work on directly. Yes. And ? > An FMS programmer could perhaps > decide to change the parameters of the engine controls, for example. Why on earth would he do something so stupid ? > To prevent that sort of thing from happening, the management could > decree that henceforth all "private" variable names will start with an > underscore. Problem solved, eh? Certainly not. The only way to solve such a problem is to fire this cretin. > Wait a minute. You yourself have > stated several times that those stupid library developers Where did I say that library developpers where "stupid" ? Chapter and verse, please. > can never > predict what the client will actually need. Now this is a well known fact - applied to "generic" libraries. Nothing to do with project-specific libraries. Straw man. > So some FMS guy named > Bruno Fine, personal attack now. Man, beware, this is not going to help you make your point. (snip remaining braindead fantasy). > Now, let's talk about a data access violations in the nuclear missile > launch software. Oh, yes, I'm sure the leading underscore convention > is more than sufficient! Wake up, dude, and quit spouting bullsh*t! Please educate yourself and learn about why Ariane 5 crashed on it's first flight, due to an error in a module written in ADA (which is such a psychorigid language that C++ and Java are even looser than Javascript in comparison). Perhaps will it light a bulb for you. >>> Not >>> every door needs a lock, but certainly some do. >> You only need locks when you don't trust your neighbours. > > Yeah, if you live in Nome, Alaska. Brillant. You obviously failed to understand the differences between "software engineering" and real life. When it comes to computers, the only doors I care closing are those which would let someone crack my computer. But FWIW, I never close my car. And, in case you don't know, it's perfectly possible to access "private" members in Java (and, if you do have access to the source code, in C++ too). > Also, have you ever heard the expression "locks keep honest people > honest"? Yes. You don't wan't to know what I'm thinking of it. > I spent *way* too much time on that post. At least something sensible. > I really need to quit > spending my time refuting the baloney that passes for wisdom here. I don't have any pretention to "wisdom" as far as I'm concerned, unless you defined wisdom as thinking that experimental results have more weight than theory. From bdesth.quelquechose at free.quelquepart.fr Sat Jan 17 15:00:19 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 17 Jan 2009 21:00:19 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> Message-ID: <4972467b$0$10274$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 16, 5:22 am, Steve Holden wrote: >> Russ P. wrote: >> >> [...] >> >>> I spent *way* too much time on that post. I really need to quit >>> spending my time refuting the baloney that passes for wisdom here. >> He who cannot ignore baloney is doomed to refute it. >> > > > Yeah, and I should really learn to leave off those little zingers. If > Mr. D weren't obviously an intelligent person and a Python expert, I > wouldn't care what he writes. I just think that he, along with a few > others here, love Python so much that they refuse to recognize its > limitations. It's an easy trap to fall into. Python surely has lot of limitations (and quirks and whatever). The point is that not having language-enforced access restrictions is *not* a limitation - because it's *not* the right way to solve the problems you are (very rightfully) concerned with. No technology can solve *human* problems. Anyone trying to make you believe otherwise is selling you snake oil. Once again, there's quite a lot to learn from the story of Ariane 5. From martin at v.loewis.de Sat Jan 17 15:08:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 21:08:39 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: References: Message-ID: <49723AC7.6000203@v.loewis.de> > I expected that py3 did not converted the b'...' indication too ? > > b'afc76815e3fc429fa9d7' You mean, just because you invoked the ascii() builtin, the b prefix should disappear? Re-read the documentation of the ascii() builtin - it probably does something completely different from what you expect it to do. Regards, Martin From the.one.duckenator at googlemail.com Sat Jan 17 15:16:59 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 12:16:59 -0800 (PST) Subject: Socket issues Message-ID: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Hi all I've been trying to set up sockets on my server (running Apache/2.2.3) using python and I'm confused as to why it doesn't work. I set up a simple listening script which runs without error, and works if a connecting script is run on the same server. However, if I try to connect using Telnet it doesn't work. I am definetly using the public IP address (79.99.43.58:2727). The weird thing is that I have the same problem if I make the socket in PHP, and even more weird is that sockets used to work, but now do not (and as far as I can tell, I have changed nothing). Any ideas? Thanks, Sunil From address.good.until.2009.may.11 at justmail.de Sat Jan 17 15:30:49 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Sat, 17 Jan 2009 21:30:49 +0100 Subject: reading file to list In-Reply-To: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee schrieb: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby > > Here's a interesting toy problem posted by Drew Krause to > comp.lang.lisp: > > ------------------------ > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > OK, I want to create a nested list in Lisp (always of only integers) > from a text file, such that each line in the text file would be > represented as a sublist in the 'imported' list. > > example of a file's content > > 3 10 2 > 4 1 > 11 18 > > example of programing behavior > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > w_a_x_... at yahoo.com gave a ruby solution: > > IO.readlines("blob.txt").map{|line| line.split } > > augumented by Jilliam James for result to be numbers: > > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > > Very beautiful. > > ------------------- > > That's really the beauty of Ruby. > > This problem and ruby code illustrates 2 fundamental problems of lisp, > namely, the cons problem, and the nested syntax pain. Both of which > are practically unfixable. *Of course* Xah is wrong, as always. Who would expect anything else? In the Lisp style Clojure for example one does exactly the same as Jillian James (JJ) did in Ruby: (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq (reader "blob.txt"))) This is slightly longer, simply because the functions have longer names. Integer/parseInt vs to_i Also the function split takes a regexp, so I have to add the "\\s" here. I don?t know though if Jillians version also handles any kind of whitespac per line. And the last thing is, that the function reader returns a BufferedReader. So in general this is more valuable in real programs as opposed to one- line scripts. If we combine line-seq and reader into readline and apply the two other changes we would say: (map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt")) vs IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} So, obviously Xah is far away from any reality. It took him hours of his life to write up all his ideas about Lisp. Sad to see that all that time was wasted. All of it was wrong. Poor Xah :( And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store data for his programs in the format 3 10 2 4 1 11 18 but instead as (3 10 2) (4 1) (11 18) And then read it back into the program with: (map read-string (line-seq (reader "blob.txt"))) Andr? -- From nad at acm.org Sat Jan 17 15:59:06 2009 From: nad at acm.org (Ned Deily) Date: Sat, 17 Jan 2009 12:59:06 -0800 Subject: tuple methods: documentation missing References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: In article <8Rncl.212$Aw2.127 at nwrddc02.gnilink.net>, Alan G Isaac wrote: > Is this another lacuna or am I overlooking it? > I cannot find the 3.0 documentation of string > formatting with the ``%`` operator. -- Ned Deily, nad at acm.org From gary at byoteki.com Sat Jan 17 16:02:37 2009 From: gary at byoteki.com (Gary M. Josack) Date: Sat, 17 Jan 2009 16:02:37 -0500 Subject: Socket issues In-Reply-To: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Message-ID: <4972476D.1090306@byoteki.com> twistedduck9 wrote: > Hi all > > I've been trying to set up sockets on my server (running Apache/2.2.3) > using python and I'm confused as to why it doesn't work. > > I set up a simple listening script which runs without error, and works > if a connecting script is run on the same server. However, if I try to > connect using Telnet it doesn't work. I am definetly using the public > IP address (79.99.43.58:2727). > > The weird thing is that I have the same problem if I make the socket > in PHP, and even more weird is that sockets used to work, but now do > not (and as far as I can tell, I have changed nothing). > > Any ideas? > > Thanks, > Sunil > -- > http://mail.python.org/mailman/listinfo/python-list > With no code it's hard to tell if there's an issue there, but if the same code worked before and still works locally I'm going to guess firewall. From the.one.duckenator at googlemail.com Sat Jan 17 16:11:33 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 13:11:33 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Message-ID: <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> My hosting provider (Streamline) have said that there is no firewall (it's a dedicated server). Either way the code I'm using is: Listening socket: import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.bind (('79.99.43.58', 2727)) mysock.listen(1) while True: channel, details = mysock.accept() print channel.recv(100) channel.send ('Got a message.') channel.close() Sending socket: import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect(('79.99.43.58', 2727)) mysock.send('test'); mysock.close() Thanks for the response! From tjreedy at udel.edu Sat Jan 17 16:20:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:20:49 -0500 Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: Alan G Isaac wrote: > In Python 3, you can no longer ``exec(open(filename))``. > > I guess the reason is that in 3.0 ``open`` returns a stream, > instead of open file, and exec wants > "a string, bytes, or code object" and not a "TextIOWrapper". > So it returns an error. > > Is it intentional that ``exec`` cannot handle a TextIOWrapper? > > Bottom line: has ``execfile(filename)`` really become > ``exec(open(filename).read())``? Is this a good thing? Yes. Yes. From lipun4u at gmail.com Sat Jan 17 16:28:12 2009 From: lipun4u at gmail.com (asit) Date: Sat, 17 Jan 2009 13:28:12 -0800 (PST) Subject: process command line parameter Message-ID: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Recently I was coding a link extractor. It's a command line stuff and takes parameter as argument. I found that the in operator is not always helpful. eg. if "--all" in sys.argv: print "all links will be printed" its not helpful when some attribute value is sent in command line parameter. hence I want to process some data like find=".co.uk" How can i do this ??? From jeff at jmcneil.net Sat Jan 17 16:32:46 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 13:32:46 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> Message-ID: <0a593760-cd05-4eee-bd59-39316bde086a@m22g2000vbl.googlegroups.com> On Jan 17, 4:11?pm, twistedduck9 wrote: > My hosting provider (Streamline) have said that there is no firewall > (it's a dedicated server). Either way the code I'm using is: > > Listening socket: > import socket > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > mysock.bind (('79.99.43.58', 2727)) > mysock.listen(1) > while True: > ? ?channel, details = mysock.accept() > ? ?print channel.recv(100) > ? ?channel.send ('Got a message.') > ? ?channel.close() > > Sending socket: > import socket > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > mysock.connect(('79.99.43.58', 2727)) > mysock.send('test'); > mysock.close() > > Thanks for the response! Any chance you've got IP Tables running on it? I've spent hours debugging strange problems before only for them to turn out to be vendor default IP tables configurations (Thanks, Red Hat!). In fact, 'iptables -L -n' has turned into one of the first things I do whenever I have any sort of problem at all. Along the same line, could always be a SELinux policy as well. The second thing I usually do? 'setenforce 0.' Also, by "doesn't work", what do you mean? Does it just hang and never reply? Do you get a connection refused message? Jeff mcjeff.blogspot.com From gert.cuykens at gmail.com Sat Jan 17 16:34:14 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 13:34:14 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> Message-ID: <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> On Jan 17, 9:08?pm, "Martin v. L?wis" wrote: > > I expected that py3 did not converted the b'...' indication too ? > > > b'afc76815e3fc429fa9d7' > > You mean, just because you invoked the ascii() builtin, the b > prefix should disappear? Re-read the documentation of the > ascii() builtin - it probably does something completely different > from what you expect it to do. s = str(hexlify(urandom(8)))[2:18] From tjreedy at udel.edu Sat Jan 17 16:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:35:16 -0500 Subject: python3.0 base64 error In-Reply-To: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> References: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> Message-ID: yang michael wrote: > I use base64 module on python3.0 > like: > > import base64 > b="hello world" > a=base64.b64encode(b) > print(a) > > but when i run it,it catch a error: > Traceback (most recent call last): > File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in > a=base64.b64encode(b) > File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode > raise TypeError("expected bytes, not %s" % s.__class__.__name__) > TypeError: expected bytes, not str > > > > and also the document's example: > >>>> import base64 >>>> encoded = base64.b64encode('data to be encoded') > >>>> encoded > 'ZGF0YSB0byBiZSBlbmNvZGVk' >>>> data = base64.b64decode(encoded) > >>>> data > 'data to be encoded' > > can not run too. > > what happen? The example has not yet been updated for Py3. I reported this at http://bugs.python.org/issue4975 Thank you for testing and reporting the failure. tjr From cs at zip.com.au Sat Jan 17 16:40:07 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 18 Jan 2009 08:40:07 +1100 Subject: process command line parameter In-Reply-To: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Message-ID: <20090117214007.GA2021@cskk.homeip.net> On 17Jan2009 13:28, asit wrote: | Recently I was coding a link extractor. It's a command line stuff and | takes parameter as argument. | I found that the in operator is not always helpful. | eg. if "--all" in sys.argv: | print "all links will be printed" Indeed. While I can't speak for your particular app, usually command line parameters are context sensitive. Therefore one normally processes them in order (especially if you want to support the fairly normal "--" option which means "no more options after this", useful if you need to supply a filename called "--app"). If you dont want to use the getopt standard module and thus its conventionaly argument syntax, then one alternative is like this: | its not helpful when some attribute value is sent in command line | parameter. | hence I want to process some data like find=".co.uk" all_links=False find=None for arg in sys.argv[1:]: if arg == "--": break elif arg =="--all": all_links=True elif arg.startswith("find="): find=arg[5:] else: # unhandled argument: complain or drop out of loop Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From http Sat Jan 17 16:43:38 2009 From: http (Paul Rubin) Date: 17 Jan 2009 13:43:38 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> Message-ID: <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Once again, there's quite a lot to learn from > the story of Ariane 5. Do you know what actually happened with Ariane 5? The failure was because "smart" humans overrode the language enforced protection by casting a floating point number down to a 16-bit integer, which worked ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger numbers were involved. The actual code fragment is here, and you can see where the error is suppressed: http://www-aix.gsi.de/~giese/swr/ariane5.html This is one thing that Python gets right, automatically using bignums rather than allowing int overflow. In that sense, Python has more enforced protection than Ada. See also: http://en.wikipedia.org/wiki/Ariane_5_Flight_501 From tjreedy at udel.edu Sat Jan 17 16:49:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:49:38 -0500 Subject: Jerry Pournelle gives award to Python and Guido for 2008 In-Reply-To: References: Message-ID: Richard Hanson wrote: > [NB: Blatant Python advocacy (and OP self-promotion).] > > > Jerry Pournelle commends Python and Guido in "The Annual Orchid > and Onions Parade" portion of his Chaos Manor Reviews column: > >> > > A reader [full-disclosure: that reader was me] nominated Python > for an Orchid for Jerry's Orchid and Onions awards for 2008: > > ''' > I nominate the computer language Python for an Orchid for 2008. > This last year, Python broke through into worldwide popularity. > The volunteer team led by BDFL (benevolent dictator for life) > Guido van Rossum released "Python 3000" (Python 3.0) before > year's end as well as releasing the next production-line 2.x > version, Python 2.6. > > Python -- and Linux (the kernel) with its "BDFL" Linus Torvalds > -- show that benevolent dictatorships are great forms of > organization which can easily beat out other forms of cooperation > in software development unable to escape Pournelle's Iron Law, > whether proprietary *or* open-source software [...]. > ''' > > Jerry Pournelle followed up with: > > ''' > I completely agree with this. Python deserves a large Orchid. > It's useful, well structured, easy to learn, and powerful. I use > it to write quick filter functions among other things. I'm > pleased to hand Guido a big Orchid. [...] > ''' > > I add: Great job, Guido and all! Great nomination. In October he wrote "Languages to Begin With If you want to try learning what programming is like, I recommend you start with Python. (Python.org) It's free, it's fast, and there are a lot of example programs you can look through. The Wikipedia article on Python gives a good description of the language and its history, as well as an example of a Python program. Don't let the capability of the language fool you into thinking you need to learn a lot before you can do anything: you can write simple good programs in Python within a couple of hours of beginning. O'Reilly has several books on the language; I recommend Learning Python as a beginning, and those more serious about learning the language need the O'Reilly Python Cookbook ? at least if you are like me and more comfortable learning languages by studying examples. Peter Glaskowsky notes that "Python is a language that relies on dynamic typing and other kinds of looseness in order to increase programmer productivity," and may not be entirely suitable for learning good programming practices. I have to agree, but it is free, it does work, and I confess I use it when I have a job that needs doing fast. In my case I often craft filters and other specialized text processing, and Python is excellent for that. I've never attempted to write a large and complex Python program." From the.one.duckenator at googlemail.com Sat Jan 17 16:52:15 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 13:52:15 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> <0a593760-cd05-4eee-bd59-39316bde086a@m22g2000vbl.googlegroups.com> Message-ID: On 17 Jan, 21:32, Jeff McNeil wrote: > On Jan 17, 4:11?pm, twistedduck9 > wrote: > > > > > My hosting provider (Streamline) have said that there is no firewall > > (it's a dedicated server). Either way the code I'm using is: > > > Listening socket: > > import socket > > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > mysock.bind (('79.99.43.58', 2727)) > > mysock.listen(1) > > while True: > > ? ?channel, details = mysock.accept() > > ? ?print channel.recv(100) > > ? ?channel.send ('Got a message.') > > ? ?channel.close() > > > Sending socket: > > import socket > > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > mysock.connect(('79.99.43.58', 2727)) > > mysock.send('test'); > > mysock.close() > > > Thanks for the response! > > Any chance you've got IP Tables running on it? I've spent hours > debugging strange problems before only for them to turn out to be > vendor default IP tables configurations (Thanks, Red Hat!). In fact, > 'iptables -L -n' has turned into one of the first things I do whenever > I have any sort of problem at all. ?Along the same line, could always > be a SELinux policy as well. ?The second thing I usually do? > 'setenforce 0.' > > Also, by "doesn't work", what do you mean? ?Does it just hang and > never reply? Do you get a connection refused message? > > Jeff > mcjeff.blogspot.com I seriously love you now. I still don't understand why it worked before... Also, does this IP tables thing mean that there WAS a firewall blocking the connection? If so, I think I'll have a go at my hosting provider... iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 2727 -j ACCEPT Thank you for your response, you've saved many hours of pulling my hair out. Sunil (I think I may have replied in the wrong place, I haven't used groups before) From tjreedy at udel.edu Sat Jan 17 16:56:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:56:04 -0500 Subject: tp_base, ob_type, and tp_bases In-Reply-To: <4971fe4d$0$30907$9b622d9e@news.freenet.de> References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> So, the documentation states that ob_type is a pointer to the type's >> Next, we have tp_base. That's defined as "an optional pointer to a >> base type from which type properties are inherited." The value of >> tp_base is then added to the tp_bases tuple. This is confusing me. On >> the surface, it sound as though they're one in the same? > > (I don't understand the English "one in the same" - interpreting it > as "as though they should be the same") Martin, you are not alone! I do not really understand that either. From alan.isaac at gmail.com Sat Jan 17 17:03:06 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 22:03:06 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: > Alan G Isaac wrote: >> Is it intentional that ``exec`` cannot handle a TextIOWrapper? >> Bottom line: has ``execfile(filename)`` really become >> ``exec(open(filename).read())``? Is this a good thing? On 1/17/2009 4:20 PM Terry Reedy apparently wrote: > Yes. Yes. OK. Why? Alan Isaac From damonwischik at gmail.com Sat Jan 17 17:08:32 2009 From: damonwischik at gmail.com (Damon) Date: Sat, 17 Jan 2009 14:08:32 -0800 (PST) Subject: Windows Tablet RealTimeStylus in Python Message-ID: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> I have a Windows Tablet machine, running XP Tablet Edition, and I want to access the stylus data from Python. If anyone has done this themselves, I'd be very grateful for a description of what worked. Otherwise, I'd be grateful for advice. I'm in way over my head, so what I describe below is probably full of errors. I managed to access the stylus data successfully from C#, using a .net object called RealTimeStylus, contained in Microsoft.Ink.dll, which was located in c:\program files\common files\microsoft shared\ink. The documentation says that this .net object uses an underlying COM object, so I hoped to be able to access the COM object from within Python. First, I used a .net disassembler to inspect Microsoft.Ink.dll, and I discovered that it uses this command to create the COM object: Guid clsid = new Guid("{DECBDC16-E824-436e-872D-14E8C7BF7D8B}"); Guid iid = new Guid("{C6C77F97-545E-4873-85F2-E0FEE550B2E9}"); string licenseKey = "{CAAD7274-4004-44e0-8A17-D6F1919C443A}"; ComObjectCreator.CreateInstanceLicense(clsid, iid, licenseKey); I looked up this clsid in my registry, and discovered that it refers to C:\Program Files\Common Files\Microsoft Shared\INK\inkobj.dll (This file also exists on my standard XP machine, which also ran my C# program happily.) Now, I want to somehow access this COM object from within Python. I tried MakePy, but I didn't know what type library to specify. I found something called "Microsoft Tablet PC Type Library, version 1.0 (1.0)", and it generated a .py file from type library 'inkobj.dll', but this file doesn't say anything about a RealTimeStylus. I tried looking for a Python command to CreateInstance, but I couldn't find one where I could specify the license string. Without the license string I ended up with the error message "Class is not licensed for use". I have no idea what to do next. Damon. From tjreedy at udel.edu Sat Jan 17 17:10:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 17:10:53 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <4971ea0b$0$7055$9b622d9e@news.freenet.de> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >>> Does he intend to maintain two separate codebases, one 2.x and the >>> other 3.x? >> I think I have no other choice. >> Why? Is theoretically possible to maintain an unique code base for >> both 2.x and 3.x? > > That is certainly possible! One might have to make tradeoffs wrt. > readability sometimes, but I found that this approach works quite > well for Django. I think Mark Hammond is also working on maintaining > a single code base for both 2.x and 3.x, for PythonWin. Where 'single codebase' means that the code runs as is in 2.x and as autoconverted by 2to3 (or possibly a custom comverter) in 3.x. One barrier to doing this is when the 2.x code has a mix of string literals with some being character strings that should not have 'b' prepended and some being true byte strings that should have 'b' prepended. (Many programs do not have such a mix.) One approach to dealing with string constants I have not yet seen discussed here is to put them all in separate file(s) to be imported. Group the text and bytes separately. Them marking the bytes with a 'b', either by hand or program would be easy. tjr From nad at acm.org Sat Jan 17 17:14:38 2009 From: nad at acm.org (Ned Deily) Date: Sat, 17 Jan 2009 14:14:38 -0800 Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: In article , Terry Reedy wrote: > Martin v. L?wis wrote: > > (I don't understand the English "one in the same" - interpreting it > > as "as though they should be the same") > Martin, you are not alone! I do not really understand that either. It's a non-standard reshaping of the idiom "one and the same", an example of what linguists call an "eggcorn": Note the reference to Python! -- Ned Deily, nad at acm.org From tjreedy at udel.edu Sat Jan 17 17:14:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 17:14:38 -0500 Subject: Incorrect title case? In-Reply-To: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: John Machin wrote: > On Jan 17, 9:07 am, MRAB wrote: >> Python 2.6.1 >> >> I've just found that the following 4 Unicode characters/codepoints don't >> behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). >> >> For example, u"\u01C5".istitle() returns True and >> unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() >> returns u'\u01C4', which is the uppercase equivalent. Are these mistakes >> in the Unicode database? > > Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, > function _PyUnicode_ToTitlecase. > > See http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup > > The code that says: > if (ctype->title) > delta = ctype->title; > else > delta = ctype->upper; > should IMHO merely be: > delta = ctype->title; > > A value of zero for ctype->title should be interpreted simply as the > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py > which treats upper, lower and title identically when preparing the > tables used by those 3 functions. > > AFAICT making that change will fix the problem for those four > characters and not ruin any others. > > The error that you noticed occurs as far back as I've looked (2.1) and > also occurs in 3.0. Please post a report to the tracker at bugs.python.org. From google at mrabarnett.plus.com Sat Jan 17 17:42:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 22:42:00 +0000 Subject: Incorrect title case? In-Reply-To: References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: <49725EB8.2020001@mrabarnett.plus.com> Terry Reedy wrote: > John Machin wrote: >> On Jan 17, 9:07 am, MRAB wrote: >>> Python 2.6.1 >>> >>> I've just found that the following 4 Unicode characters/codepoints don't >>> behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). >>> >>> For example, u"\u01C5".istitle() returns True and >>> unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() >>> returns u'\u01C4', which is the uppercase equivalent. Are these mistakes >>> in the Unicode database? >> >> Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, >> function _PyUnicode_ToTitlecase. >> >> See >> http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup >> >> >> The code that says: >> if (ctype->title) >> delta = ctype->title; >> else >> delta = ctype->upper; >> should IMHO merely be: >> delta = ctype->title; >> >> A value of zero for ctype->title should be interpreted simply as the >> offset to add to the ordinal, as it is in the sibling _PyUnicode_To >> (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py >> which treats upper, lower and title identically when preparing the >> tables used by those 3 functions. >> >> AFAICT making that change will fix the problem for those four >> characters and not ruin any others. >> >> The error that you noticed occurs as far back as I've looked (2.1) and >> also occurs in 3.0. > > Please post a report to the tracker at bugs.python.org. > Already done: http://bugs.python.org/issue4971 From martin at v.loewis.de Sat Jan 17 18:05:10 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 18 Jan 2009 00:05:10 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> Message-ID: <49726426.8080602@v.loewis.de> gert wrote: > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: >>> I expected that py3 did not converted the b'...' indication too ? >>> b'afc76815e3fc429fa9d7' >> You mean, just because you invoked the ascii() builtin, the b >> prefix should disappear? Re-read the documentation of the >> ascii() builtin - it probably does something completely different >> from what you expect it to do. > > s = str(hexlify(urandom(8)))[2:18] And your question is? From gert.cuykens at gmail.com Sat Jan 17 18:11:48 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 15:11:48 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: On Jan 18, 12:05?am, "Martin v. L?wis" wrote: > gert wrote: > > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: > >>> I expected that py3 did not converted the b'...' indication too ? > >>> b'afc76815e3fc429fa9d7' > >> You mean, just because you invoked the ascii() builtin, the b > >> prefix should disappear? Re-read the documentation of the > >> ascii() builtin - it probably does something completely different > >> from what you expect it to do. > > > s = str(hexlify(urandom(8)))[2:18] > > And your question is? No question just solution to get rit of b'' :) From pdorange at pas-de-pub-merci.mac.com Sat Jan 17 18:11:52 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sun, 18 Jan 2009 00:11:52 +0100 Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: <1itppny.1c7vt6u1lc3qe1N%pdorange@pas-de-pub-merci.mac.com> "Martin v. L?wis" wrote: > > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: > >>> I expected that py3 did not converted the b'...' indication too ? > >>> b'afc76815e3fc429fa9d7' > >> You mean, just because you invoked the ascii() builtin, the b > >> prefix should disappear? Re-read the documentation of the > >> ascii() builtin - it probably does something completely different > >> from what you expect it to do. > > > > s = str(hexlify(urandom(8)))[2:18] > > And your question is? The answer is probably 23. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From martin at v.loewis.de Sat Jan 17 18:15:00 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 18 Jan 2009 00:15:00 +0100 Subject: Incorrect title case? In-Reply-To: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: <49726674.1030203@v.loewis.de> > A value of zero for ctype->title should be interpreted simply as the > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > (Upper|Lower)case functions. Interestingly enough, according to the spec of UnicodeData.txt, these should *not* be siblings. Refer to http://www.unicode.org/Public/UNIDATA/UCD.html For lower and upper case, it says Note: The simple uppercase is omitted in the data file if the uppercase is the same as the code point itself. whereas for titlecase, it says Note: The simple titlecase may be omitted in the data file if the titlecase is the same as the uppercase. So unicodectype is right to fall back to uppercase if no titlecase mapping is given. However, this looks like a bug in UCD.html: they probably should have the same note for titlecase as they have for lower and uppercase (at least, that's how UnicodeData seems to be generated). Regards, Martin From martin at v.loewis.de Sat Jan 17 18:20:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 18 Jan 2009 00:20:15 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: <497267AF.2060001@v.loewis.de> >>> s = str(hexlify(urandom(8)))[2:18] >> And your question is? > > No question just solution to get rit of b'' :) Ah. hexlify(urandom(8)).decode('ascii') Regards, Martin From gert.cuykens at gmail.com Sat Jan 17 18:37:58 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 15:37:58 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> <497267AF.2060001@v.loewis.de> Message-ID: <3f527f62-9f81-490c-a481-56c214b785e3@o40g2000prn.googlegroups.com> On Jan 18, 12:20?am, "Martin v. L?wis" wrote: > >>> s = str(hexlify(urandom(8)))[2:18] > >> And your question is? > > > No question just solution to get rit of b'' :) > > Ah. hexlify(urandom(8)).decode('ascii') Ok that one looks better then mine :) From Russ.Paielli at gmail.com Sat Jan 17 18:45:33 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 15:45:33 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: No one ever claimed that a programming language, no matter how rigorous, can eliminate all bugs. All a language can do is to reduce their rate of occurrence. The Ariane fiasco was not a failure of Ada per se but rather a failure of people using Ada. They attempted to re-use software written for one rocket for another without proper testing. No language can prevent that sort of error. We can argue forever about the usefulness of language-enforced restriction of access to private data and methods. I have no doubt whatsoever that it is very useful at least for the extreme cases of very large, safety-critical systems. If you don't think access to private data needs to be restricted for control of strategic nuclear arsenals, for example, I think you're crazy, but that's just my opinion. The only reasonable question in my mind is where the line should be drawn between systems that should have enforced restrictions and those that can rely on coding standards and voluntary cooperation among programmers. A while back, I read something about the final integration of the flight software on the Boeing 777, which was written mainly in Ada. The claim was made that this integration took only three days, whereas normally it would be expected to take more like three months with a less rigorous language such as C++. The reason for the simplified integration is that Ada enforces interfaces and prevents access to private data and methods. Apparently such enforcement can improve the efficiency of software production -- and that's not just in "theory." From catphive at catphive.net Sat Jan 17 18:55:32 2009 From: catphive at catphive.net (Brendan Miller) Date: Sat, 17 Jan 2009 15:55:32 -0800 Subject: what's the point of rpython? In-Reply-To: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: >> The goals of the pypy project seems to be to create a fast python >> implementation. I may be wrong about this, as the goals seem a little >> amorphous if you look at their home page. > > The home page itself is ambiguous, and does oversell the performance > aspect. The *actual* goal as outlined by their official docs is to > implement Python in Python, at every level. Ok fair enough. In some ways I see that as more of a purely intellectual exercise than the practical endeavor that I assumed the project was originally. However, one of the links I was sent had one of the devs talking about using the translation process to make C/Java/LLVM implementations out of the same interpreter code. I'll say that makes a lot of sense. Another question I was wondering about is whether they plan on maintaining good C bindings? Will existing bindings for third party libraries be able to work? Also, are they going to do away with the GIL? The python devs seem to consider the GIL a non-issue, though they may change their mind in 3 years when we all have 32 core desktops, until then getting rid of the GIL would make pypy pretty attractive in some quarters. I know the scons project was running into GIL issues. Finally, I'm pretty unclear on what versions of python that pypy is targeting. From enleverlesX.XmcX at XmclaveauX.com Sat Jan 17 19:09:52 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sun, 18 Jan 2009 01:09:52 +0100 Subject: Windows Tablet RealTimeStylus in Python In-Reply-To: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> References: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> Message-ID: <49727358$0$18363$ba4acef3@news.orange.fr> Hi! I use Internet-Explorer like (as?) GUI. Then, I insert Active-X components (from Tablet-PC, native or SDK). Another solution: create a .HTA, and use PythonScript (version "ActiveScripting" of Python, who become with pyWin32). @-salutations -- Michel Claveau From musicguy at alphaios.net Sat Jan 17 19:10:48 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sat, 17 Jan 2009 18:10:48 -0600 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <1232237448.20435.7.camel@speedyg> Wow, impressive responses. It sounds like the general consensus is that English would not be a good choice for programming even if there were an interpreter capable of turning human language into machine language. But that makes sense; even English professionals have trouble understanding each other sometimes. Until that problem is somehow overcome, there's not much hope of computers to overcome it. From xahlee at gmail.com Sat Jan 17 19:30:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 16:30:24 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee wrote: > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html On Jan 17, 12:30 pm, Andr? Thieme wrote: > In the Lisp style Clojure for example one does exactly the same as > Jillian James (JJ) did in Ruby: > (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq > (reader "blob.txt"))) Note that you have nested map. This is a problem of function chaning as i detailed. The other problem of cons, is commonly seen. Just about every week, we see some perhaps beginning lisper asking how to do various trivial list manipulation problem, which you don't see such question or frequency in any of modern high level lang forms. The frequently asked list manipulation question we see include how to append, prepend, or anything involving nested list such as partitioning, reordering sublists, getting leaves, interpretation of leaves, etc. This is caused by the cons. associated lisp problem compound the issue. Namely, the not exactly regular syntax, and the eval model of sometimes symbol sometimes uneval'd symbol, e.g. ?'(...)?, ?`(...,@ ...)? things. The clojure example you gave above, apparently inherited the irregular syntax problem. (you see the #, [], % things, which is breaks the lisp's sexp idea) Also, all modern lisp basically all get fucked up by inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often, they change the semantic a bit apparently as a mesaure towards solving the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely ugly, syntax soup) Advice: if you are creating a lispy lang, two things: ? stick to a _pure_ nested syntax, no exception whatsoever. (e.g. no more ` ' # % shits) If you want, add a transparent layer on top to support arbitrary algeraic notation. (e.g. look at Mathematica, CGOL) ? get rid of the cons. (you can still implement the so-called linked list, but no where it should be shown to the programer) Further readings: ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html Xah ? http://xahlee.org/ ? From sjmachin at lexicon.net Sat Jan 17 19:36:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 16:36:58 -0800 (PST) Subject: Incorrect title case? References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> <49726674.1030203@v.loewis.de> Message-ID: <6ae6f3e9-4885-437b-b880-9660b6777527@g3g2000pre.googlegroups.com> On Jan 18, 10:15?am, "Martin v. L?wis" wrote: > > A value of zero for ctype->title should be interpreted simply as the > > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > > (Upper|Lower)case functions. > > Interestingly enough, according to the spec of UnicodeData.txt, > these should *not* be siblings. Refer to > > http://www.unicode.org/Public/UNIDATA/UCD.html > > For lower and upper case, it says > > Note: The simple uppercase is omitted in the data file if the uppercase > is the same as the code point itself. > > whereas for titlecase, it says > > Note: The simple titlecase may be omitted in the data file if the > titlecase is the same as the uppercase. However: (1) there seem to be no examples in the current data file where the titlecase is empty and the uppercase is not empty (2) the titlecase is *NOT* empty for the four characters in question -- they have [in effect] ch.title() -> ch as MRAB expected. See my response in the bug tracker for further info/comment. > > So unicodectype is right to fall back to uppercase if no titlecase > mapping is given. Correct -- but this is currently hypothetical; moreover the "fallback" is being done in the wrong place; it should be done in Tools/Unicode/ makeunicodedata.py when it reads the UnicodeData.txt file. The current implementation codes the ch.title() -> ch mapping as delta = 0 which is the same coding as used for "no titlecase specified in file" leaving the runtime unicodetype with a dilemema which it resolves wrongly -- it is *NOT* correct to pick uppercase when the titlecase is actually specified in the UnicodeData.txt file. Note that although it's not mentioned in the modification history for UnicodeData.txt, the titlecase entry for the 4 characters changed from "empty" to "self" in Unicode 4.0.0. HTH, John From jamatos at fc.up.pt Sat Jan 17 19:57:12 2009 From: jamatos at fc.up.pt (=?utf-8?q?Jos=C3=A9_Matos?=) Date: Sun, 18 Jan 2009 00:57:12 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: <200901180057.12818.jamatos@fc.up.pt> On Friday 16 January 2009 09:47:36 Eric Brunel wrote: > What do you mean by 'works'...? The usual meaning, I think. :-) Click "Yes" and the program prints True, click "No" and the programs prints "False". > You don't have the problem? It doesn't ? > change a thing for me... Notice that I am running the system python, that at least is different. -- Jos? Ab?lio From elhmbre at ozemail.com.au Sat Jan 17 20:11:45 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 11:11:45 +1000 Subject: A java hobbyist programmer learning python Message-ID: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Hello, below is my first fragment of working python code. As you can see it is very java like as that is all I know. Is this the right approach to be taking? Should I be taking a different approach? Thanks in advance. import sys class Calculator(): def __init__(self): self.operator = sys.argv[1] self.arg1 = sys.argv[2] self.arg2 = sys.argv[3] def getOperator(self): return sys.argv[1] def getArg1(self): return sys.argv[2] def getArg2(self): return sys.argv[3] def calculate(self): if self.getOperator() == '+' : return int(self.getArg1()) + int(self.getArg2()) elif self.getOperator() == '*' : return int(self.getArg1()) * int(self.getArg2()) elif self.getOperator() == '/' : return int(self.getArg1()) / int(self.getArg2()) elif self.getOperator() == '-' : return int(self.getArg1()) - int(self.getArg2()) else: return 'Wrong argument supplied' x = Calculator() y = x.calculate() print y From Russ.Paielli at gmail.com Sat Jan 17 20:17:39 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 17:17:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> On Jan 17, 11:49?am, Bruno Desthuilliers wrote: > Please educate yourself and learn about why Ariane 5 crashed on it's > first flight, due to an error in a module written in ADA (which is such > a psychorigid language that C++ and Java are even looser than Javascript > in comparison). Perhaps will it light a bulb for you. The claim here regarding the Ariane 5 failure is one of those urban myths that refuses to die. It has been refuted over and over (including on this thread already), but I would just like to add something in defense of Ada. Studies have found that Ada reduces both bugs and long-term development costs by something like a factor of two compared to C. For example, see http://www.adaic.com/whyada/ada-vs-c/cada_art.html Also, for a good discussion of the success of Ada in the 777, see http://www.adaic.org/atwork/boeing.html From address.good.until.2009.may.11 at justmail.de Sat Jan 17 20:25:00 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Sun, 18 Jan 2009 02:25:00 +0100 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee schrieb: > Xah Lee wrote: >> ? A Ruby Illustration of Lisp Problems >> http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html > > > On Jan 17, 12:30 pm, Andr? Thieme 2009.may... at justmail.de> wrote: > > >> In the Lisp style Clojure for example one does exactly the same as >> Jillian James (JJ) did in Ruby: > >> (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq >> (reader "blob.txt"))) > > Note that you have nested map. This is a problem of function chaning > as i detailed. Yes, Jillian also has nested maps: IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > The other problem of cons, is commonly seen. Just about every week, we > see some perhaps beginning lisper asking how to do various trivial > list > manipulation problem, which you don't see such question or frequency > in any of modern high level lang forms. You see questions about trivial problems every week in all forums about programming languages. It has nothing to do with conses. Wrong road. > The frequently asked list manipulation question we see include how to > append, prepend, or anything involving nested list such as > partitioning, reordering sublists, getting leaves, interpretation of > leaves, etc. This is caused by the cons. Yes, same with all containers in all programming languages. > The clojure example you gave above, apparently inherited the irregular > syntax problem. (you see the #, [], % things, which is breaks the > lisp's sexp idea) My code used 8 ?mysterious symbols?: ( ) # [ ] . " % The Ruby version had these 7: ( ) | { } . " And of course, neither in Ruby nor Clojure they break any idea. > Also, all modern lisp basically all get fucked up by > inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often, > they change the semantic a bit apparently as a mesaure towards solving > the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely > ugly, syntax soup) Funny. What you write is an english text with words that most people can understand. You trick them into thinking that it actually makes sense what you say. It is so technical, that a random would believe it. But what you really say is about as meaningful as saying that it is impossible to write good programs in Python, because it adds whitespace to its syntax. > ? Fundamental Problems of Lisp > http://xahlee.org/UnixResource_dir/writ/lisp_problems.html You wasted lots of your time. Or was this maybe generated by a bot? Maybe http://pdos.csail.mit.edu/scigen/ or something like that? I also found this paper that you wrote: http://apps.pdos.lcs.mit.edu/scicache/184/scimakelatex.7076.Xah+Lee.html Another crap posting of you. But a random person might be impressed. Andr? -- From clp2 at rebertia.com Sat Jan 17 20:27:56 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jan 2009 17:27:56 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <50697b2c0901171727k6c95d909n6adece15772a930a@mail.gmail.com> On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > class Calculator(): > > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = sys.argv[2] > self.arg2 = sys.argv[3] > > def getOperator(self): > return sys.argv[1] > > def getArg1(self): > return sys.argv[2] > > def getArg2(self): > return sys.argv[3] Delete the 3 Java-ish accessor methods; good Python style just uses the attributes directly (i.e. self.operator instead of self.getOperator()). > > def calculate(self): > if self.getOperator() == '+' : > return int(self.getArg1()) + int(self.getArg2()) > elif self.getOperator() == '*' : > return int(self.getArg1()) * int(self.getArg2()) > elif self.getOperator() == '/' : > return int(self.getArg1()) / int(self.getArg2()) > elif self.getOperator() == '-' : > return int(self.getArg1()) - int(self.getArg2()) > else: > return 'Wrong argument supplied' Rather than have a long if-elif-else chain like this, you can use a dictionary with functions as values. For example: def add(x, y): return x + y def sub(x, y): return x - y OPER2FUNC = {'+' : add, '-' : sub} print OPER2FUNC['+'](3,4) #==> 7 You can use the same technique with the functions in the `operator` module to significantly shorten your calculate() method. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Russ.Paielli at gmail.com Sat Jan 17 20:35:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 17:35:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Message-ID: <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> On Jan 17, 1:43?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > Once again, there's quite a lot to learn from > > the story of Ariane 5. > > Do you know what actually happened with Ariane 5? ?The failure was > because "smart" humans overrode the language enforced protection by > casting a floating point number down to a 16-bit integer, which worked > ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger So this turns out to be an example of a failure due, not to the *rigidity* of Ada, but to its *permissiveness* in allowing such a cast. Had such a cast not been allowed, the people who complain about the "rigidity" of Ada would have complained that much more. I don't know which variant of Ada was used here, but something called the "Ravenscar Profile" is a reduced subset of Ada that might have prevented this error (though I haven't verified this). Then there is Spark Ada, which supposed to be much safer than even Ada. > numbers were involved. ?The actual code fragment is here, and you can > see where the error is suppressed: > > ?http://www-aix.gsi.de/~giese/swr/ariane5.html > > This is one thing that Python gets right, automatically using bignums > rather than allowing int overflow. ?In that sense, Python has more > enforced protection than Ada. True, but Ada does not have the luxury of just using doubles and "bignums" everywhere, because it needs to work on cheap processors too. But perhaps it could somehow be configured to do so by the user if sufficiently powerful computers are being used. From sjmachin at lexicon.net Sat Jan 17 20:37:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 17:37:40 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> Message-ID: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> On Jan 18, 9:10?am, Terry Reedy wrote: > Martin v. L?wis wrote: > >>> Does he intend to maintain two separate codebases, one 2.x and the > >>> other 3.x? > >> I think I have no other choice. > >> Why? Is theoretically possible to maintain an unique code base for > >> both 2.x and 3.x? > > > That is certainly possible! One might have to make tradeoffs wrt. > > readability sometimes, but I found that this approach works quite > > well for Django. I think Mark Hammond is also working on maintaining > > a single code base for both 2.x and 3.x, for PythonWin. > > Where 'single codebase' means that the code runs as is in 2.x and as > autoconverted by 2to3 (or possibly a custom comverter) in 3.x. > > One barrier to doing this is when the 2.x code has a mix of string > literals with some being character strings that should not have 'b' > prepended and some being true byte strings that should have 'b' > prepended. ?(Many programs do not have such a mix.) > > One approach to dealing with string constants I have not yet seen > discussed here is to put them all in separate file(s) to be imported. > Group the text and bytes separately. ?Them marking the bytes with a 'b', > either by hand or program would be easy. (1) How would this work for somebody who wanted/needed to support 2.5 and earlier? (2) Assuming supporting only 2.6 and 3.x: Suppose you have this line: if binary_data[:4] == "PK\x03\x04": # signature of ZIP file Plan A: Change original to: if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" Add this to the bytes section of the separate file: ZIPFILE_SIG = "PK\x03\x04" [somewhat later] Change the above to: ZIPFILE_SIG = b"PK\x03\x04" [once per original file] Add near the top: from separatefile import * Plan B: Change original to: if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" Add this to the separate file: ZIPFILE_SIG = b"PK\x03\x04" [once per original file] Add near the top: from separatefile import * Plan C: Change original to: if binary_data[:4] == b"PK\3\4": # signature of ZIP file Unless I'm gravely mistaken, you seem to be suggesting Plan A or some variety thereof -- what advantages do you see in this over Plan C? From http Sat Jan 17 20:53:06 2009 From: http (Paul Rubin) Date: 17 Jan 2009 17:53:06 -0800 Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Chris Rebert writes: > > class Calculator(): ... > Delete the 3 Java-ish accessor methods; good Python style just uses > the attributes directly (i.e. self.operator instead of > self.getOperator()). I think I would get rid of the whole Calculator class unless there was a good reason to keep it (i.e. you are going to have several Calculators active in the program simultaneously). Just write straightforward imperative code without bothering with the OO stuff that is mandatory in Java. > Rather than have a long if-elif-else chain like this, you can use a > dictionary with functions as values. For example: > > def add(x, y): > return x + y These functions are already defined in the operator module, and you can also define them inline with the lambda operator. Here is my version of the program: import sys from operator import add, mul, sub, div op, x, y = sys.argv[1:4] opdict = {'+': add, '*': mul, '-': sub, '/': div} try: func = opdict[op] except KeyError: print 'wrong argument supplied' sys.exit() print func(int(x), int(y)) Note that like the original, it doesn't check for valid numeric args. From castironpi at gmail.com Sat Jan 17 20:54:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 17:54:48 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> <0182018b$0$8693$c3e8da3@news.astraweb.com> Message-ID: <73c48fd8-1c3b-45f0-94e7-fa11678c7cba@e1g2000pra.googlegroups.com> On Jan 17, 10:45?am, Steven D'Aprano wrote: > On Sat, 17 Jan 2009 00:24:21 -0800, Aaron Brady wrote: > > Can you make it work for a 3-way lookup? > > What do you mean "3-way lookup"? > > I'm going to take a guess... > > A maps to B, B maps to C, and C maps to A. > > Is that what you mean? So long as you can get B and C from A, and C and A from B, and A and B from C, it classifies as a "3-way lookup", or at least how I was using the term. (In other words, yes.) Yours does that, but it takes two steps from B to A. For example: c2a[ b2c[ keyinB ] ] == keyinA This goes from B to C, then from C to A. From what you said, you would have no way to get from B directly to A. Is that correct? If so, it's a little awkward, and the direct way would be nice too. From clp2 at rebertia.com Sat Jan 17 21:01:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jan 2009 18:01:10 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c0901171801o5a85094awe34a926bcb4e5ae8@mail.gmail.com> On Sat, Jan 17, 2009 at 5:53 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Chris Rebert writes: >> Rather than have a long if-elif-else chain like this, you can use a >> dictionary with functions as values. For example: >> >> def add(x, y): >> return x + y > > These functions are already defined in the operator module, and you > can also define them inline with the lambda operator. Did you completely skip over the last sentence of my email? I specifically mentioned the `operator` module. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sat Jan 17 21:04:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 18:04:47 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> On Jan 18, 12:11?pm, "elhombre" wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > class Calculator(): > > ? ? def __init__(self): > ? ? ? ? self.operator = sys.argv[1] > ? ? ? ? self.arg1 = sys.argv[2] > ? ? ? ? self.arg2 = sys.argv[3] Try this: def __init__(self, operator, arg1, arg2): self.operator = operator self.arg1 = arg1 self.arg2 = arg2 Then you can do x1 = Calculator('+', '1.0', '2.0') x2 = Calculator('-', '666', '42') or x3 = Calculator(*sys.argv[1:4]) if you're really desperate to use the command line args. > > ? ? def getOperator(self): > ? ? ? ? return sys.argv[1] Chris has already told you to give such accessor functions the flick, but it should have done return self.operator From sajmikins at gmail.com Sat Jan 17 21:07:07 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 17 Jan 2009 18:07:07 -0800 (PST) Subject: changing URLs in webpages, python solutions? Message-ID: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Hey folks, I'm having trouble finding this through google so I figured I'd ask here. I want to take a webpage, find all URLs (links, img src, etc.) and rewrite them in-place, and I'd like to do it in python (pure python preferred.) I know I could probably roll my own halfway decent solution in a day or so, like with Beautiful Soup or something, but I'd much rather re- use someone else's work if I can. I'm pretty sure this falls into the category of "someone else has had, and solved, this problem before." Any recommendations? Thanks in advance, ~Simon From sajmikins at gmail.com Sat Jan 17 21:10:08 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 17 Jan 2009 18:10:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: On Jan 11, 1:22?pm, "Madhusudan.C.S" wrote: > ? I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > ? ? class A: > ? ? a = 10 > ? ? b = "Madhu" > > ? ? def somemethod(self, arg1): > ? ? ? ? self.c = 20.22 > ? ? ? ? d = "some local variable" > ? ? ? ? # do something > ? ? ? ? .... > ? ? ... > ? ? def somemethod2 (self, arg2): > ? ? ? ? self.c = "Changed the variable" > ? ? ? ? # do something 2 > ? ? ? ? ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code and where > it was manipulated for that matter. It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. > > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? > > -- Python Rocks! > ? ?Madhusudan.C.S Python doesn't follow philosophies, people follow philosophies. ;-) ~S From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 21:24:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 02:24:51 GMT Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <0182896d$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see > it is very java like as that is all I know. Is this the right approach > to be taking? You might find it very useful to read: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html > Should I be taking a different approach? Thanks in advance. This is obviously a very minimal program, so I won't criticise you for failing to do any error checking :-) However, I will make some broad points: * No getters and setters. Python takes a very permissive approach to class attributes, taking the philosophy "we're all adults here". It's easy to change a public attribute to a private attribute with a getter/ setter if you need to, so there's nothing to be gained by writing getters for straight attribute access. It just makes things slow. * Don't return error values, raise an exception. Setting up a try...except block is really fast in Python, almost as fast as a pass statement (according to my tests). Catching the exception itself is slow, but most of the time you won't care about that. Let me re-write your code in a more Pythonic way. This is not the only way to do this, and it probably isn't the best way, but it may give you a flavour for the way Python is usually written. import sys import operator class Calculator(): dispatch = { # dispatch table mapping symbol to function '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv, } def __init__(self): self.operator = sys.argv[1] self.arg1 = int(sys.argv[2]) self.arg2 = int(sys.argv[3]) def calculate(self): func = self.dispatch[self.operator] return func(self.arg1, self.arg2) if __name__ == '__main__': # run this block only when running as a script, not # when the module is being imported (say, for testing). x = Calculator('+', 23, 42) try: y = x.calculate() except KeyError: print "Unrecognised operator '%s'" % x.operator else: print y -- Steven From mdw at distorted.org.uk Sat Jan 17 21:30:00 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 18 Jan 2009 02:30:00 +0000 Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> Message-ID: <87r6314a8n.fsf.mdw@metalzone.distorted.org.uk> Jeff McNeil writes: > Thank you! It was tp_base that was confusing me. The tp_bases member > makes sense as Python supports multiple inheritance. It wasn't > immediately clear that tp_base is there for single inheritance > reasons. It's all quite clear now. > > Is that an optimization of sorts? I think it's a compatibility thing because types didn't acquire multiple inheritance until the new-style class stuff started happening in, ummm..., Python 2.2, I think. This is rampant speculation. Please correct me. -- [mdw] From tjreedy at udel.edu Sat Jan 17 22:00:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:00:38 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: John Machin wrote: > On Jan 18, 9:10 am, Terry Reedy wrote: >> Martin v. L?wis wrote: >>>>> Does he intend to maintain two separate codebases, one 2.x and the >>>>> other 3.x? >>>> I think I have no other choice. >>>> Why? Is theoretically possible to maintain an unique code base for >>>> both 2.x and 3.x? >>> That is certainly possible! One might have to make tradeoffs wrt. >>> readability sometimes, but I found that this approach works quite >>> well for Django. I think Mark Hammond is also working on maintaining >>> a single code base for both 2.x and 3.x, for PythonWin. >> Where 'single codebase' means that the code runs as is in 2.x and as >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. >> >> One barrier to doing this is when the 2.x code has a mix of string >> literals with some being character strings that should not have 'b' >> prepended and some being true byte strings that should have 'b' >> prepended. (Many programs do not have such a mix.) >> >> One approach to dealing with string constants I have not yet seen >> discussed here is to put them all in separate file(s) to be imported. >> Group the text and bytes separately. Them marking the bytes with a 'b', >> either by hand or program would be easy. > > (1) How would this work for somebody who wanted/needed to support 2.5 > and earlier? > > (2) Assuming supporting only 2.6 and 3.x: > > Suppose you have this line: > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > Plan A: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the bytes section of the separate file: > ZIPFILE_SIG = "PK\x03\x04" > [somewhat later] > Change the above to: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan B: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the separate file: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan C: > Change original to: > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > variety thereof -- what advantages do you see in this over Plan C? > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat Jan 17 22:02:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:02:53 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: John Machin wrote: > On Jan 18, 9:10 am, Terry Reedy wrote: >> Martin v. L?wis wrote: >>>>> Does he intend to maintain two separate codebases, one 2.x and the >>>>> other 3.x? >>>> I think I have no other choice. >>>> Why? Is theoretically possible to maintain an unique code base for >>>> both 2.x and 3.x? >>> That is certainly possible! One might have to make tradeoffs wrt. >>> readability sometimes, but I found that this approach works quite >>> well for Django. I think Mark Hammond is also working on maintaining >>> a single code base for both 2.x and 3.x, for PythonWin. >> Where 'single codebase' means that the code runs as is in 2.x and as >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. >> >> One barrier to doing this is when the 2.x code has a mix of string >> literals with some being character strings that should not have 'b' >> prepended and some being true byte strings that should have 'b' >> prepended. (Many programs do not have such a mix.) >> >> One approach to dealing with string constants I have not yet seen >> discussed here is to put them all in separate file(s) to be imported. >> Group the text and bytes separately. Them marking the bytes with a 'b', >> either by hand or program would be easy. > > (1) How would this work for somebody who wanted/needed to support 2.5 > and earlier? See reposts in python wiki, one by Martin. > > (2) Assuming supporting only 2.6 and 3.x: > > Suppose you have this line: > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > Plan A: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the bytes section of the separate file: > ZIPFILE_SIG = "PK\x03\x04" > [somewhat later] > Change the above to: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan B: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the separate file: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan C: > Change original to: > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > variety thereof -- what advantages do you see in this over Plan C? For 2.6 only (which is much easier than 2.x), do C. Plan A is for 2.x where C does not work. tjr From wuwei23 at gmail.com Sat Jan 17 22:03:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sat, 17 Jan 2009 19:03:21 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: On Jan 18, 9:55?am, "Brendan Miller" wrote: > > The *actual* goal as outlined by their official docs is to > > implement Python in Python, at every level. > Ok fair enough. In some ways I see that as more of a purely > intellectual exercise than the practical endeavor that I assumed the > project was originally. Well, it opens up Python as a whole for experimentation & modification by Python developers, which seems pretty practical to me :) > Another question I was wondering about is whether they plan on > maintaining good C bindings? Will existing bindings for third party > libraries be able to work? You really should run through the whole faq: http://codespeak.net/pypy/dist/pypy/doc/faq.html#can-i-use-cpython-extension-modules (Spoiler alert: the answer is no.) > Also, are they going to do away with the GIL? One FAQ entry before the above: http://codespeak.net/pypy/dist/pypy/doc/faq.html#do-threads-work-what-are-the-modules-that-work > The python devs seem to > consider the GIL a non-issue, though they may change their mind in 3 > years when we all have 32 core desktops, until then getting rid of the > GIL would make pypy pretty attractive in some quarters. I know the > scons project was running into GIL issues. It's not a case of the Python devs digging their heels in and not giving the world what it desperately wants. Here's an article by Guido talking about the last attempt to remove the GIL and the performance issues that arose: "I'd welcome a set of patches into Py3k *only if* the performance for a single-threaded program (and for a multi-threaded but I/O-bound program) *does not decrease*." http://www.artima.com/weblogs/viewpost.jsp?thread=214235 > Finally, I'm pretty unclear on what versions of python that pypy is targeting. I wonder where such a frequently asked question could be answered? ;) http://codespeak.net/pypy/dist/pypy/doc/faq.html#which-python-version-2-x-does-pypy-implement From xahlee at gmail.com Sat Jan 17 22:07:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 19:07:24 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: a idiot wrote: > Yes, Jillian also has nested maps: the issue here, is not about whether Ruby has nested map or not. It is about illustrating a lisp problem. In particular, nested syntax impedes the functional programing paradigm of function chaining. ? A Ruby Illustration of Lisp Problems http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html a idiot wrote: > My code used 8 ?mysterious symbols?: > ( ) # [ ] . " % > > The Ruby version had these 7: > ( ) | { } . " The issue here is not about which lang employs more special chars. The issue is about the irregularities in lisp's syntax damaged its power of its otherwise believed superior regular syntax. ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html Xah ? http://xahlee.org/ ? From tjreedy at udel.edu Sat Jan 17 22:08:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:08:16 -0500 Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: Alan G Isaac wrote: >> Alan G Isaac wrote: >>> Is it intentional that ``exec`` cannot handle a TextIOWrapper? > >>> Bottom line: has ``execfile(filename)`` really become >>> ``exec(open(filename).read())``? Is this a good thing? > > > On 1/17/2009 4:20 PM Terry Reedy apparently wrote: >> Yes. Yes. > > > OK. Why? This: execfile(filename) is a trivial (9 keystroke) abbreviation of this: exec(open(filename).read()) which is similar in effect to this: from filename import * so it is really not needed. From rileyporter at gmail.com Sat Jan 17 22:37:57 2009 From: rileyporter at gmail.com (Riley Porter) Date: Sat, 17 Jan 2009 22:37:57 -0500 Subject: Dynamic Loading Modules Message-ID: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> Hello all, This is the first time I have posted to this group. That being said if I am in the wrong place for this kind of support please let me know. OK, So I am writing a log parsing program and wish to allow for the community to write "parsers". Basically, what I have in place now is a "modules" directory that contains .py files that are going to be used to parse specific log types. The question is, is there a way to dynamically import whatever is in that modules directory and make is to the import name is actually the file name.. So after the modules directory is 'os.listdir' and it returns a listing of modules (actually just .py files) IE: ng1-fw.py, cisco_asa_fw.py, etc... I can just in the next line of code call: ng1-fw.Parse(long_file) #assuming the ng1-fw.py file has a Parse Function right now using imp I got it to where i can say like: x = imp.load_source(md5.new(code_path).hexdigest(), code_path, f) #assuming that I gave it the path and filename for ng1-fw.py I can do this: x.Parse(log_file) But what I am really after is the ability to do this: ng1-fw.Parse(log_file) The reason again behind this is so that there is no need to "hard code" parser file names. Did I make myself clear? Please let me know if I need to explain that better. Thanks ! -- Riley Porter Network Security Engineer Offensive Security - OSCP SANS GIAC - GCIH CCNA, Security+ ACSA - Arcsight Security Analyst -------------- next part -------------- An HTML attachment was scrubbed... URL: From besturk at gmail.com Sat Jan 17 22:45:05 2009 From: besturk at gmail.com (Abandoned) Date: Sat, 17 Jan 2009 19:45:05 -0800 (PST) Subject: changing URLs in webpages, python solutions? References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Message-ID: On Jan 18, 4:07?am, Simon Forman wrote: > Hey folks, > > I'm having trouble finding this through google so I figured I'd ask > here. > > I want to take a webpage, find all URLs (links, img src, etc.) and > rewrite them in-place, and I'd like to do it in python (pure python > preferred.) > > I know I could probably roll my own halfway decent solution in a day > or so, like with Beautiful Soup or something, but I'd much rather re- > use someone else's work if I can. ?I'm pretty sure this falls into the > category of "someone else has had, and solved, this problem before." > > Any recommendations? > > Thanks in advance, > ~Simon You can use code search engines. I founded there but now i don't have. From http Sat Jan 17 22:57:27 2009 From: http (Paul Rubin) Date: 17 Jan 2009 19:57:27 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: <7xd4ele060.fsf@ruckus.brouhaha.com> alex23 writes: > Here's an article by Guido talking about the last attempt to remove > the GIL and the performance issues that arose: > > "I'd welcome a set of patches into Py3k *only if* the performance for > a single-threaded program (and for a multi-threaded but I/O-bound > program) *does not decrease*." The performance decrease is an artifact of CPython's rather primitive storage management (reference counts in every object). This is pervasive and can't really be removed. But a new implementation (e.g. PyPy) can and should have a real garbage collector that doesn't suffer from such effects. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 00:28:43 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 05:28:43 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <0182b484$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > Russ P. a ?crit : >> On Jan 15, 12:21 pm, Bruno Desthuilliers >> wrote: >> >>> Once again, the important point is that there's a *clear* distinction >>> between interface and implementation, and that you *shouldn't* mess >>> with implementation. >> >> If you "*shouldn't* mess with the implementation", then what is wrong >> with enforcing that "shouldn't" in the language itself? Russ: There are SHOULD NOTs and there are MUST NOTs. In Python, direct access to pointers is a MUST NOT. So the language itself prohibits arbitrary access to memory, and pure Python programs aren't subject to the same security holes and crashes that C programs are subject to because of their use of pointers. Messing with the implementation is a SHOULD NOT. There are times (possibly rare) where you are allowed to mess with the implementation. Hence the language doesn't prohibit it, only discourage it. The language designers choose how many hoops you have to jump through (and what performance penalty you suffer) in order to mess with the implementation. > Because sometimes you have a legitimate reason to do so and are ok to > deal with the possible issues. Bruno: Yes, but most of the time you don't. The consequence of this dynamism is that the Python VM can't do many optimizations at all, because *at any time* somebody might mess with the implementation. But 90% of the time nobody does, so Python is needlessly slow 90% of the time. Wouldn't it be nice if there was a way to speed up that 90% of the time while still allowing the 10% to take place? The current solution to this problem is to try to push as much as possible into functions written in C: built-ins and custom C extensions. It's not a bad solution: most Python programs rely on many C built-ins, which enforces real encapsulation and data hiding. With the possible exception of mucking about with ctypes, you simply can't access mess with the internals of (say) lists *at all*. Is this a bad thing? Would it be so terrible if we could do the same thing in pure Python? Why should I have to write in C if I want the same protection? >> Why leave to >> coding standards and company policy what can be encoded right into the >> language? > > Because human are smarter than computers. That's an awfully naive statement. It's a sound-byte instead of a reasoned argument. We're smarter than computers? Then why are we programming in languages like Python instead of directly in machine code? Why can optimizing C compilers make more efficient code than the best human assembly language programmers? Humans and computers are smart at different things. Human beings are not terribly good at keeping track of more than about seven things at once, on average, and consequently we easily forget what scope variables are in. It's probably been at least 15 years since any released version of Python has been buggy enough to "forget" whether a name was in one scope or another, and yet human programmers still generate NameError and AttributeError exceptions *all the time*. I bet even Guido still makes them occasionally. >> Why leave to humans (who are known to err) what can be automated >> relatively easily? Isn't that what computers are for? > > Error is human. For a real catastrophic failure, it requires a computer. Oh rubbish. That's a sound-byte invented by nervous technophobes scared of computers. I expected better from a programmer. When computers fail, it's is almost certainly because of human error: some human being wrote buggy code, some human being turned off a test because it was generating too many warnings, some human being failed to prove their code was correct. Chernobyl was a catastrophic failure that happened when *humans* turned off their safety systems to do a test, then couldn't turn them back on. >> All those "setters" and >> "getters" are a kludge. I think Python "properties" are a major step >> forward here. Just for fun, I checked to see if Scala has properties. >> Guess what? Not only does it have them, but they are generated >> automatically for all member data. That's even better than Python >> properties! > > Oh yes ? "Better", really ? So it's better to have a language that > automagically breaks encapsulation (requiring an additionnal level of > indirection) than a language that do the right thing by default ? I'm > afraid I missed the point ??? You certainly do. How do properties "break" encapsulation rather than enforcing it? >>>> As I said before, enforced encapsulation may not be appropriate for >>>> every application, but it is definitely appropriate for some. >>> No. It is appropriate for dummy managers hiring dummy programmers. The >>> project's size and domain have nothing to do with it. >> >> Let me try to be very clear here. We are dealing with two separate but >> related issues. The first is whether data hiding should be added to >> Python. > > No need to add it, it's already there : every name that starts with an > underscore is hidden !-) That's not hidden. It's there in plain sight. In Unix, file names with a leading dot are hidden in the shell: when you do a file listing, you don't see them. It's not difficult to get to see them: you just pass -a to the ls command. As data hiding goes, it's pretty lame, but Python doesn't even suppress _ names when you call dir. Frankly, I wish that by default it would -- 99% of the time when I call dir, I *don't* want to see _ names. They just get in the way. [...] >> Whether it can be added without screwing up the language, I don't know. >> If not, then so be it. That just limits the range of domains where >> Python is suitable. > > That's just plain stupid. No it's not. It's *practical*. There are domains where *by law* code needs to meet all sorts of strict standards to prove safety and security, and Python *simply cannot meet those standards*. >> As for whether data hiding provides a net benefit in any language, it >> certainly does for large programs and for safety-critical programs. For >> large, safety-critical systems, it's a no-brainer. > > Only if you fail to use your brain. Now, except for regurgitating the > official OMG prose, do you have *anything* to back these claims ? Python > is older than Java, and there are quite enough man/years of experience > and Python success stories to prove that it *just work*. Nobody doubts that Python works for many applications. But can you point to any large, safety-critical system programmed in Python? >> I like to use the example of the flight software for a large commercial >> transport aircraft, but many other examples could be given. How about >> medical systems that control radiation therapy or chemotherapy? How >> about financial systems that could take away your retirement account in >> 1.5 milliseconds. Or how about the control software for the strategic >> nuclear arsenals of the US or Russia? When you consider the sea, air, >> and land-based components, I'm sure that's one hell of a lot of code! > > And ? Such systems have been written (and quite a lot are still running) > with languages way more permissive than Python. You know, languages like > C or assembly. Yes, and it is *hard* because the programmer has to worry about data hiding *on his own*. That's why people no longer write large systems in assembly and use high-level languages that deal with all those data hiding issues for you. One of my friends has worked for many years programming some pretty high- powered banking software. Their approach is to move data-hiding into the database, or the operating system. Cobol doesn't enforce encapsulation, but the database and OS certainly do, with a permissions-based approach. Speaking of banking software, consider a typical banking application. It may have dozens or hundreds of programmers working on it. It's too big for any one person to understand all of it. Once deployed it may potentially have access to hundreds of billions of dollars of other people's money. Don't you imagine that one or two of these programmers might be tempted to skim a little off the top? Data hiding is a good way of making sure that the guy writing the front end can't just turn of the audit trail and transfer $60,000,000 into his bank account. Why don't you approach your bank and suggest that it would be a Good Thing if he could? Think of the programming time they would save with the added dynamism! Why, it might shave off *weeks* from a six year project! > Until you understand that *no technology is idiot-proof*, > you'll get nowhere in "software engineering". I suspect that Russ has got a lot further in software engineering than you have. I suspect your attitude is part of the reason why, as they say, "If engineers built bridges the way programmers build software, the first woodpecker than came along would destroy civilization". No technology is failure proof. But there's no reason in the world why most technology can't be idiot-proof. Televisions are idiot-proof, because they protect people from casual mistakes. If televisions were built according to the Python model, the internals of the TV would be exposed, without even a cover. All the major parts would be plug-in rather than soldered in, and there would be no cover over the parts that were live. Every year, tens of thousands of people would electrocute themselves fatally (because parts of the TV holds a massive charge for days after you unplug them from the mains) but that would be okay, because you never know when somebody might want to pull out the fly-back transformer and replace it with a six ohm resistor. That sort of dynamism is important! Well, maybe so, but not in a television. Consequently televisions are built to hide the internals from the user. If you *really* want to, then you can get a screwdriver and remove the back and unsolder the fly-back transformer and replace it with a six ohm resistor. It's your TV, do what you want. But nobody is going to die because the picture was fuzzy and they heard from some chat forum that the way to fix that was to poke the back of the picture tube with a screw driver "to let out the excess ohms". [...] >> An FMS programmer could perhaps >> decide to change the parameters of the engine controls, for example. > > Why on earth would he do something so stupid ? I'm sure he'd think he had a good reason. As you said, "Because sometimes you have a legitimate reason to do so and are ok to deal with the possible issues." Maybe other people would disagree whether or not it was a legitimate reason, or if he was OK dealing with the possible issues. Perhaps he needed the extra optimization of skipping the getter/setters. Perhaps he needed it for testing, and somehow one thing led to another. Who knows? It is strange that on the one hand you should insist that programmers sometimes need to mess with internals, and on the other dismiss those who do as "stupid". Your position is inconsistent. >> To prevent that sort of thing from happening, the management could >> decree that henceforth all "private" variable names will start with an >> underscore. Problem solved, eh? > > Certainly not. The only way to solve such a problem is to fire this > cretin. Again, we shouldn't enforce encapsulation and data hiding because there are legitimate reasons for breaking it, but anyone who does break it is a cretin. You have a very strange attitude. Besides, it's not very practical. When you fire "the cretin", it has consequences. Everyone else in the project has to work harder, which has costs, or you have to replace him, which also has costs. Maybe you can't fire him, because he's the only one who can debug problems in the auto- pilot. Perhaps the rest of the team downs tools and walks off the job in sympathy. Perhaps he sues you for unfair dismissal. Expenses rise. Time- lines slip. Uncertainty increases. It's also bad for moral when you fire somebody for messing with the internals when you have a policy that it is allowed to mess with the internals. That's why you picked a dynamic language like Python in the first place, because it doesn't prevent you from messing with the internals. And now when somebody does, you sack him? If you ask me, it's management who needs to be sacked, not the programmer who merely used the tools given to him. Perhaps you can't fire the cretin, because the first time you discover the problem is eight years later when a place filled with nuns and orphans flips upside down and flies straight into the ground. Perhaps it would have been better to prevent him from messing with the internals in the first place, even at some extra cost. When you're in business, you have to make decisions like: * do I write the software in Python, which will have a 99% chance of costing $100,000 and a 1% chance of costing $100,000,000? * or do I write it in a B&D language like Java, which will have a 100% chance of costing $2,000,000? [...] > Please educate yourself and learn about why Ariane 5 crashed on it's > first flight, due to an error in a module written in ADA (which is such > a psychorigid language that C++ and Java are even looser than Javascript > in comparison). Perhaps will it light a bulb for you. Others have already pointed out that the error in the Ariane 5 rocket was *human* error due to somebody messing with the internals, namely defeating the compiler's default type checking. I'd just like to ask: Bruno, were you aware of the cause of the crash, and if not, why did you raise the issue in the first place? Did you think it was a compiler bug that caused the crash? >>>> Not >>>> every door needs a lock, but certainly some do. >>> You only need locks when you don't trust your neighbours. >> >> Yeah, if you live in Nome, Alaska. > > Brillant. You obviously failed to understand the differences between > "software engineering" and real life. When it comes to computers, the > only doors I care closing are those which would let someone crack my > computer. If only there was some way to know which bugs could let people crack our computer and which bugs couldn't. Anyway, that's your choice. Personally, I'd much prefer my software not to cause data loss, not to crash, not to DoS me, not to hang, and not to generate bogus data, as well as not letting strangers crack into my system. There are many, many program paths which could potentially lead to these results. It would be nice if I could close those doors. > But FWIW, I never close my car. And, in case you don't know, it's > perfectly possible to access "private" members in Java (and, if you do > have access to the source code, in C++ too). Yes, but it is more difficult. There's a larger psychological barrier. It's easier to audit for such access, even in a large project. It encourages a more careful attitude: "do I *really* need to mess with the internals, or is there a safer way?". It forces the programmer to *think* before doing something potentially dangerous. This is why I wish eval and exec were in a module instead of built-ins. They'd still be there, but you'd have to jump through one small hoop before using them. Suppose Python worked like this: >>> class Parrot: ... _private = 'spam' ... >>> p = Parrot() >>> p._private = 'ham' Traceback (most recent call last): File "", line 1, in ProtectionError: attribute is read-only from outside of class Parrot >>> from protection import unlock >>> unlock(p)._private = 'ham' >>> p._private 'ham' I don't know if this scenario is even possible in Python, but pretend that it is. Would it be so terrible? If a particular project wanted to enforce encapsulation, all they need do is replace or remove the protection module from their Python installations. (I assume the project developers aren't *hostile*. If they are, then there's almost nothing you can do to make the code safe. Encapsulation is about protecting from accidents, not sabotage.) If you wanted to mess with the internals in your own project, all you need do is import a module. We could imagine the same scenario in reverse. Python allows getters and setters, but they're more work, and so people just don't use them unless they really need to. Suppose Python offered real data encapsulation, but you had to work to get it: >>> class Parrot: ... _private = 'spam' ... >>> p = Parrot() >>> p._private = 'ham' # allowed by default >>> from protection import lock >>> lock(p)._private >>> p._private = 'spam' Traceback (most recent call last): File "", line 1, in ProtectionError: attribute is read-only from outside of class Parrot Would that be so bad? I don't think so. -- Steven From elhmbre at ozemail.com.au Sun Jan 18 02:12:45 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:12:45 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4972d682$0$9528$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Chris Rebert" wrote in message news:mailman.7468.1232242083.3487.python-list at python.org... > On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: ... > > Rather than have a long if-elif-else chain like this, you can use a > dictionary with functions as values. For example: > > def add(x, y): > return x + y > > def sub(x, y): > return x - y > > OPER2FUNC = {'+' : add, '-' : sub} > print OPER2FUNC['+'](3,4) #==> 7 > > You can use the same technique with the functions in the `operator` > module to significantly shorten your calculate() method. > > Cheers, > Chris Thanks very much Chris. That is much more concise ! I have a lot of reading to do and a different mindset to work towards. From elhmbre at ozemail.com.au Sun Jan 18 02:16:04 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:16:04 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: <4972d740$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Paul Rubin" wrote in message news:7xy6x9nzwd.fsf at ruckus.brouhaha.com... > Chris Rebert writes: >> > class Calculator(): ... > >> Delete the 3 Java-ish accessor methods; good Python style just uses >> the attributes directly (i.e. self.operator instead of >> self.getOperator()). > > I think I would get rid of the whole Calculator class unless there was > a good reason to keep it (i.e. you are going to have several > Calculators active in the program simultaneously). Just write > straightforward imperative code without bothering with the OO stuff > that is mandatory in Java. > >> Rather than have a long if-elif-else chain like this, you can use a >> dictionary with functions as values. For example: >> >> def add(x, y): >> return x + y > > These functions are already defined in the operator module, and you > can also define them inline with the lambda operator. > > Here is my version of the program: > > import sys > from operator import add, mul, sub, div > > op, x, y = sys.argv[1:4] > > opdict = {'+': add, '*': mul, '-': sub, '/': div} > > try: > func = opdict[op] > except KeyError: > print 'wrong argument supplied' > sys.exit() > > print func(int(x), int(y)) > > Note that like the original, it doesn't check for valid numeric args. Good point about the class. I really only did that to begin to learn the class syntax. I had not added any exception handling as I was taking it a step at a time. Most of the first few hours were spent mucking around with TextMate, Netbeans and Wing IDE. I finally got Netbeans working to the point where something would run. Thanks very much Paul. From elhmbre at ozemail.com.au Sun Jan 18 02:16:39 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:16:39 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> Message-ID: <4972d760$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "John Machin" wrote in message news:5d2c588a-9b01-4a85-85b2-b132754e6e08 at o40g2000prn.googlegroups.com... > On Jan 18, 12:11 pm, "elhombre" wrote: >> Hello, below is my first fragment of working python code. As you can see >> it >> is very java like as that is all I know. Is this the right approach to be >> taking? >> Should I be taking a different approach? Thanks in advance. >> >> import sys >> >> class Calculator(): >> >> def __init__(self): >> self.operator = sys.argv[1] >> self.arg1 = sys.argv[2] >> self.arg2 = sys.argv[3] > > Try this: > > def __init__(self, operator, arg1, arg2): > self.operator = operator > self.arg1 = arg1 > self.arg2 = arg2 > > Then you can do > x1 = Calculator('+', '1.0', '2.0') > x2 = Calculator('-', '666', '42') > or > x3 = Calculator(*sys.argv[1:4]) > if you're really desperate to use the command line args. > >> >> def getOperator(self): >> return sys.argv[1] > > Chris has already told you to give such accessor functions the flick, > but it should have done > return self.operator Thanks John. > From elhmbre at ozemail.com.au Sun Jan 18 02:17:09 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:17:09 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <0182896d$0$8693$c3e8da3@news.astraweb.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4972d77e$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:0182896d$0$8693$c3e8da3 at news.astraweb.com... > On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: > >> Hello, below is my first fragment of working python code. As you can see >> it is very java like as that is all I know. Is this the right approach >> to be taking? > > You might find it very useful to read: > > http://dirtsimple.org/2004/12/python-is-not-java.html > > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > > >> Should I be taking a different approach? Thanks in advance. > > This is obviously a very minimal program, so I won't criticise you for > failing to do any error checking :-) However, I will make some broad > points: > > * No getters and setters. Python takes a very permissive approach to > class attributes, taking the philosophy "we're all adults here". It's > easy to change a public attribute to a private attribute with a getter/ > setter if you need to, so there's nothing to be gained by writing getters > for straight attribute access. It just makes things slow. > > * Don't return error values, raise an exception. Setting up a > try...except block is really fast in Python, almost as fast as a pass > statement (according to my tests). Catching the exception itself is slow, > but most of the time you won't care about that. > > > > Let me re-write your code in a more Pythonic way. This is not the only > way to do this, and it probably isn't the best way, but it may give you a > flavour for the way Python is usually written. > > > import sys > import operator > > class Calculator(): > dispatch = { # dispatch table mapping symbol to function > '+': operator.add, > '-': operator.sub, > '*': operator.mul, > '/': operator.truediv, > } > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = int(sys.argv[2]) > self.arg2 = int(sys.argv[3]) > def calculate(self): > func = self.dispatch[self.operator] > return func(self.arg1, self.arg2) > > > if __name__ == '__main__': > # run this block only when running as a script, not > # when the module is being imported (say, for testing). > x = Calculator('+', 23, 42) > try: > y = x.calculate() > except KeyError: > print "Unrecognised operator '%s'" % x.operator > else: > print y > > > > > -- > Steven Excellent links. Thanks Steven ! From gagsl-py2 at yahoo.com.ar Sun Jan 18 02:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 05:44:47 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald escribi?: > I googled a bit this morning search for an answer to this problem but > have > come up empty so far. Can anyone help? > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit ^^^^^ > (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib2 > Traceback (most recent call last): > File "", line 1, in > File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in ^^^^^^^^ It seems your have a confusing setup. Why is Python 2.6 using C:\dev\opt\Python25? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 02:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 05:44:47 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald escribi?: > I googled a bit this morning search for an answer to this problem but > have > come up empty so far. Can anyone help? > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit ^^^^^ > (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib2 > Traceback (most recent call last): > File "", line 1, in > File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in ^^^^^^^^ It seems your have a confusing setup. Why is Python 2.6 using C:\dev\opt\Python25? -- Gabriel Genellina From xahlee at gmail.com Sun Jan 18 03:31:15 2009 From: xahlee at gmail.com (Xah Lee) Date: Sun, 18 Jan 2009 00:31:15 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> Message-ID: <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> On Jan 17, 10:25 am, Tino Wildenhain wrote: > > [[int(x) for x in line.split()] for line in open("blob.txt")] Nice (python code). Few comments: ? the above code is borderline of atypical. e.g. it is not a average python code would produce or one'd seen in corporate python code. ? voodoo like the above makes me dislike python. To me, the one advantage of python is its clarity enforced by its syntax. Specifically, the forced indendation and quite simple semantics. However, the way i've seen Guido's propensities and how python 3 is moving to, it is becoming more mumbo jumbo of computer sciency OOP jargons with syntax soup. (with iterators, enumerators, list comprehension... shits forced upon the users) The above line illustrate well the ad hoc syntax soup nature python is moving into. Further readings: ? Perl-Python Tutorial: List Comprehension http://xahlee.org/perl-python/list_comprehension.html ? Lambda in Python 3000 http://xahlee.org/perl-python/python_3000.html Xah ? http://xahlee.org/ ? From icejobjob22 at gmail.com Sun Jan 18 04:17:37 2009 From: icejobjob22 at gmail.com (icejobjob) Date: Sun, 18 Jan 2009 03:17:37 -0600 Subject: PyQt, Cannot send events to objects owned by a different thread? References: <47498520$0$13104$9b4e6d93@newsspool2.arcor-online.net> Message-ID: ?A?E?X?????A?????????A?E?X???????????????????????????? ?????A'?A?E????' (http://www.pwblog.com/user/xru01/syusyoku/)???????????w?????????????????????????????????????????B ?????A?A?????J???T?u?v???C?????????????????N???????????????s???A???????????N?????????????A???E?o?????C???p?N?g???^?????????????????B ???????????A?????*???????????????????A?E???????????C?x???g???A?*???????l???A?A?E?l???????????E?G?C?g???????????????????????B ?A?E???????A?Z?p???m???????????????????o???????B?A?E?X?????A???????????????????????S?????????????????B -- icejobjob ------------------------------------------------------------------------ icejobjob's Profile: http://forums.yourdomain.com.au/member.php?userid=5313 View this thread: http://forums.yourdomain.com.au/showthread.php?t=18594 From pavlovevidence at gmail.com Sun Jan 18 05:40:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 18 Jan 2009 02:40:29 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> Message-ID: <43573712-026a-4f84-817a-7bfdceda8719@v5g2000prm.googlegroups.com> On Jan 17, 8:12?am, Jeff McNeil wrote: > On Jan 17, 11:09?am, Jeff McNeil wrote: > > > > > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > So, the documentation states that ob_type is a pointer to the type's > > > > type, or metatype. Rather, this is a pointer to the new type's > > > > metaclass? > > > > That's actually the same. *Every* ob_type field points to the object's > > > type, e.g. for strings, integers, tuples, etc. That includes type > > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > > also called metaclass (as "class" and "type" are really synonyms). > > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > > base type from which type properties are inherited." ?The value of > > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > > the surface, it sound as though they're one in the same? > > > > (I don't understand the English "one in the same" - interpreting it > > > as "as though they should be the same") > > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > > inheritance); tp_base (if set) provides the first base type. > > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > > tp_base is only at play when the object in question inherits from > > > > type? > > > > No - it is the normal case for single inheritance. You can leave it > > > NULL, which means you inherit from object. > > > > Regards, > > > Martin > > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > > makes sense as Python supports multiple inheritance. ?It wasn't > > immediately clear that tp_base is there for single inheritance > > reasons. It's all quite clear now. > > > Is that an optimization of sorts? > > Well, maybe not specifically for single inheritance reasons, I just > didn't see an immediate reason to keep a separate pointer to the first > base type. The reason you need a separate tp_base is because it doesn't necessarily point to the first base type; rather, it points to the first base type that has added any fields or slots to its internal layout (in other words, the first type with a tp_basicsize > 8, on 32- bit versions). I believe this is mainly for the benefit of Python subclasses that define their own slots. The type constructor will begin adding slots at an offset of tp_base->tp_basicsize. To see an example, int objects have a tp_basicsize of 12 (there are 4 extra bytes for the interger). So if you multiply-inherit from int and a Python class, int will always be tp_base. class A(object): pass class B(int,A): pass print B.__base__ # will print class C(A,int): pass print C.__base__ # will print A related issue is that you can't multiply inherit from two types that have tp_basicsize > 8 unless one of them inherits from the other. There can be only one tp_base. For instance: class D(int,tuple): pass # will raise TypeError class E(object): __slots__ = ['a','b'] class F(object): __slots__ = ['c','d'] class G(E,G): pass # will raise TypeError class H(E,int): pass # will raise TypeError .... Here's a bit more background (and by "a bit" I mean "a lot"): In 32-bit Python, objects of types defined in Python are usually only 16 bytes long. The layout looks like this. instance dict weak reference list reference count ob_type The reference count, which is always the thing that the actual PyObject* points at, isn't actually the first item in the object's layout. The dict and weakref list are stored at a lower address. (There's a reason for it.) If a Python class defines any __slots__, the type constructor will add the slots to the object's layout. instance dict (if there is one) weak reference list (if there is one) reference count ob_type slot slot slot Note that, because you defined __slots__, the object might not have an instance dict or weak reference list associated with it. It might, though, if one of the base classes had defined an instance dict or weakref list. Or, it might not, but then a subclass might have its onw instance dict or weakref list. That's why these guys are placed at a lower address: so that they don't interfere with the layout of subclasses. A subclass can add either more slots or a dict. Object of types defined in C can have arbitrary layout. For instance, it could have a layout that looks like this: reference count ob_type PyObject* a PyObject* b long c float d instance dict A problem with Python slots and C fields is that, if you want to inherit from a type with a non-trivial object layout, aside from the dict and weakrefs, all of the subtypes have to maintain the same layout (see Liskov substitutability for rationale). Subtypes can add their own fields or slots if they want, though. So, if a Python subtype wants to define its own slots on top of a type with a non-trivial object layout, it has to know which base has the largest layout so that it doesn't use the same memory for its own slots. Hence tp_base. Carl Banks From andrew at acooke.org Sun Jan 18 05:56:55 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 02:56:55 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? Message-ID: Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data model#object.__iadd__ Just a suggestion I thought I'd throw out... There's a restriction in the language implementation on exactly what can go the left of an augmented arithmetic expression. For example: >>> a = 3 >>> a **= 2 is ok, but: >>> class Foo(): ... def __init__(): ... self.a = 3 ... def __ipow__(self, x): ... self.a **= x ... >>> Foo() **= 2 File "", line 1 SyntaxError: illegal expression for augmented assignment Now unless I've done something stupid above (always a possibility :o) the implementation seems a bit strict (is it really a *syntax* error? - I am not sure exactly what the restriction is). This may seems like a small issue, but operators can really help with making embedded DSLs in Python - they give quite a bit of "wiggle room" to invent a syntax that is compact and intuitive. The restriction above cuts into that (OK, so it's still a small issue... :o) Cheers, Andrew From andrew at acooke.org Sun Jan 18 05:58:21 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 02:58:21 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <280b70f2-e4ed-4cc1-83b3-2736ba2c4e68@u14g2000yqg.googlegroups.com> Improved link - http://docs.python.org/3.0/reference/datamodel.html#object.__iadd__ From jstroud at mbi.ucla.edu Sun Jan 18 06:10:34 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 18 Jan 2009 03:10:34 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: Lawson Hanson wrote: > So is there any way to get Python to import the named module > without just doing "from dummy import *", because I will > not know that the user wants to use the "dummy" module > until run-time ... I'm trying to import control data > for different run scenarios which will be defined in > differently named Python modules which the user will > specify at run-time with a command-line option > > And help with this would be most appreciated For the sake of humanity, I must try to talk you out of this. Well, it's not that serious, but dynamic import confuses programs that inspect code like py2exe, etc. I think it is likely that you will find the day that you regret trying so hard to 'import *' dynamically. A more maintainable way is to simply map the command line argument to an import statement and keep your namespaces clean: """importer_module""" import sys import dummy import bonafide modules = {"dummy" : dummy, "bonafide" : bonafide} module = modules[sys.argv[1]] If you have several modules that themselves might need the conditional imports, simply put the import statements in a separate module (e.g. "importer_module" and do something like """another_module""" from importer_module import module If you simply don't want to import a bunch of modules, use an if/then statement. In any event, I advise you to not design your code or usage around dynamic imports using the __import__() statement or exec(). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From clp2 at rebertia.com Sun Jan 18 06:31:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 03:31:46 -0800 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: Message-ID: <50697b2c0901180331j2702b744h8548c3a908c1f381@mail.gmail.com> On Sun, Jan 18, 2009 at 2:56 AM, andrew cooke wrote: > Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data > model#object.__iadd__ > > Just a suggestion I thought I'd throw out... There's a restriction in > the language implementation on exactly what can go the left of an > augmented arithmetic expression. > > For example: >>>> a = 3 >>>> a **= 2 > > is ok, but: >>>> class Foo(): > ... def __init__(): > ... self.a = 3 > ... def __ipow__(self, x): > ... self.a **= x > ... >>>> Foo() **= 2 > File "", line 1 > SyntaxError: illegal expression for augmented assignment > > Now unless I've done something stupid above (always a possibility :o) > the implementation seems a bit strict (is it really a *syntax* error? > - I am not sure exactly what the restriction is). IIRC, you can only assign to: - variables (x = ...) - attributes (x.y = ...) - elements (x[y] = ...) Anything else doesn't make sense to assign to because it's not a "storage box" so to speak. There's no way to work out what is meant. In your case, you're assigning to a *value*, specifically a new instance of the Foo class, which is nonsensical; instead of a "box", you're trying to assign to a "value", something that gets stored in boxes. By comparison, '2 = 5' and '[1,2] = 7' would seem to have some sort of meaning under your system, which IMHO seems preposterous. Now true, you are using augmented assignment, which in certain cases is translated to a method call, but in principle the augmented assignment (e.g. x += y) should have roughly the same effect as the non-augmented equivalent (x = x + y), and the fact that a method call is involved is merely an implementation detail of sorts. Therefore, Python requires you to rewrite the code in some other way that makes your intentions more clear. For instance, why not use the << operator instead? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From andrew at acooke.org Sun Jan 18 06:42:14 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 03:42:14 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> > Therefore, Python requires you to rewrite the code in some other way > that makes your intentions more clear. For instance, why not use the > << operator instead? Right, but you're guessing what the context is. Within a DSL it often makes a lot of sense to use operators for reasons that weren't originally intended. You even make the same case yourself indirectly. The same argument you make could be made to say that << should only operator on values that can be shifted. Now thankfully there is no way to test for that, so there is no restriction and, consequently, it is now widely accepted that no-one (even people arguing the case for constraints!) think it odd to use << for something other than its initial use. Obviously this kind of discussion has gone on since languages were first invented - it's the "how much rope" argument. So rather than continue down that road I would just like to say that this feels like an inconsistency. The other operators are *not* as restricted and this is making my life harder. It may sound crazy, but this may force me to use * and ** instead (the context is a language feature related to *args and **kargs, so the * and ** help convey the meaning). And they have a much much stronger meaning to users, which will make my DSL harder to understand. So in this case a blunt knife is making life harder. Andrew From gandalf at shopzeus.com Sun Jan 18 06:46:52 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 18 Jan 2009 12:46:52 +0100 Subject: Dynamic Loading Modules In-Reply-To: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> References: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> Message-ID: <497316AC.3050102@shopzeus.com> Riley Porter ?rta: > Hello all, > > This is the first time I have posted to this group. That being said > if I am in the wrong place for this kind of support please let me know. > > OK, > > So I am writing a log parsing program and wish to allow for the > community to write "parsers". Basically, what I have in place now is > a "modules" directory that contains .py files that are going to be > used to parse specific log types. > > The question is, is there a way to dynamically import whatever is in > that modules directory and make is to the import name is actually the > file name.. > So after the modules directory is 'os.listdir' and it returns a > listing of modules (actually just .py files) IE: ng1-fw.py, > cisco_asa_fw.py, etc... I can just in the next line of code call: > > ng1-fw.Parse(long_file) #assuming the ng1-fw.py file has a Parse Function > > right now using imp I got it to where i can say like: > x = imp.load_source(md5.new(code_path).hexdigest(), code_path, f) > #assuming that I gave it the path and filename for ng1-fw.py > I can do this: > > x.Parse(log_file) > > But what I am really after is the ability to do this: > ng1-fw.Parse(log_file) > > The reason again behind this is so that there is no need to "hard > code" parser file names. > > Did I make myself clear? Please let me know if I need to explain that > better. What you need is the imp module: http://docs.python.org/library/imp.html > This module provides an interface to the mechanisms used to implement > the import > statement. It defines the following constants and functions: You might find that using classes instead of modules is more handy. Regards, Laszlo From wuwei23 at gmail.com Sun Jan 18 06:55:55 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Jan 2009 03:55:55 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> Message-ID: <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> On Jan 17, 3:55?pm, Steven D'Aprano wrote: > Both very good points, but consider that you're not comparing apples with > apples. > > >>> __import__("os", fromlist=["system"]) > >>> system > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'system' is not defined I must confess I've rarely had a need to use __import__ and don't think I've ever used the fromlist arg. I'm confused, though, because the docstring states: The fromlist should be a list of names to emulate ``from name import ...'' But it also states that __import__ always returns a module, so I'm utterly confused as to the purpose of fromlist, or how to inject the specified entries into the calling namespace. If anyone could explain this for me, I'd really appreciate it. > I mention this only to be pedantic, because I agree with your point that > exec can introduce security issues, and be significantly slower. Correcting misinformation isn't pedantry, especially when I've learned something :) From andrew at acooke.org Sun Jan 18 06:56:28 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 03:56:28 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: Since this is a PyPy bashing thread, maybe it's an appropriate place to suggest that the project has got a little bit waylaid by exploring cool things instead of releasing a useful final result? I am not questioning rpython directly - the case for something like that is obvious. But there's a question of balance. It's possible to go on building ever more complex systems which are theoretically justified, but which postpone ever finishing the job. At some point there has to be a "good enough". To some extent I am playing devil's advocate here, but as an outside who looked at PyPy a while back, my uninformed and naive impression was that the project was suffering from the kid of issues I have caricatured above.... Andrew PS I guess you are aware of worse is better etc? I think this may also be a US/Euro culture issue... From sjmachin at lexicon.net Sun Jan 18 06:56:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 18 Jan 2009 03:56:39 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: <04767ad3-e8b9-49b5-a539-24e236bde58a@40g2000prx.googlegroups.com> On Jan 18, 2:02?pm, Terry Reedy wrote: > John Machin wrote: > > On Jan 18, 9:10 am, Terry Reedy wrote: > >> Martin v. L?wis wrote: > >>>>> Does he intend to maintain two separate codebases, one 2.x and the > >>>>> other 3.x? > >>>> I think I have no other choice. > >>>> Why? Is theoretically possible to maintain an unique code base for > >>>> both 2.x and 3.x? > >>> That is certainly possible! One might have to make tradeoffs wrt. > >>> readability sometimes, but I found that this approach works quite > >>> well for Django. I think Mark Hammond is also working on maintaining > >>> a single code base for both 2.x and 3.x, for PythonWin. > >> Where 'single codebase' means that the code runs as is in 2.x and as > >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. > > >> One barrier to doing this is when the 2.x code has a mix of string > >> literals with some being character strings that should not have 'b' > >> prepended and some being true byte strings that should have 'b' > >> prepended. ?(Many programs do not have such a mix.) > > >> One approach to dealing with string constants I have not yet seen > >> discussed here is to put them all in separate file(s) to be imported. > >> Group the text and bytes separately. ?Them marking the bytes with a 'b', > >> either by hand or program would be easy. > > > (1) How would this work for somebody who wanted/needed to support 2.5 > > and earlier? > > See reposts in python wiki, one by Martin. Most relevant of these is Martin's article on porting Django, using a single codebase. The """goal is to support all versions that Django supports, plus 3.0""" -- indicating that it supports at least 2.5, which won't eat b"blah" syntax. He is using 2to3, and handles bytes constants by """django.utils.py3.b, which is a function that converts its argument to an ASCII-encoded byte string. In 2.x, it is another alias for str; in 3.x, it leaves byte strings alone, and encodes regular (unicode) strings as ASCII. This function is used in all places where string literals are meant as bytes, plus all cases where str() was used to invoke the default conversion of 2.x.""" Very similar to what I expected. However it doesn't answer my question about how your "move byte strings to a separate file, prepend 'b', and import the separate file" strategy would help ... and given that 2.5 and earlier will barf on b"arf", I don't expect it to. > > (2) Assuming supporting only 2.6 and 3.x: > > > Suppose you have this line: > > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > > Plan A: > > Change original to: > > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > > Add this to the bytes section of the separate file: > > ZIPFILE_SIG = "PK\x03\x04" > > [somewhat later] > > Change the above to: > > ZIPFILE_SIG = b"PK\x03\x04" > > [once per original file] > > Add near the top: > > from separatefile import * > > > Plan B: > > Change original to: > > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > > Add this to the separate file: > > ZIPFILE_SIG = b"PK\x03\x04" > > [once per original file] > > Add near the top: > > from separatefile import * > > > Plan C: > > Change original to: > > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > > variety thereof -- what advantages do you see in this over Plan C? > > For 2.6 only (which is much easier than 2.x), do C. ?Plan A is for 2.x > where C does not work. Excuse me? I'm with the OP now, I'm totally confused. Plan C is *not* what you were proposing; you were proposing something like Plan A which definitely involved a separate file. Why won't Plan C work on 2.x (x <= 5)? Because the 2.X will b"arf". But you say Plan A is for 2.x -- but Plan A involves importing the separate file which contains and causes b"arf" also! To my way of thinking, one obvious DISadvantage of a strategy that actually moves the strings to another file (requiring invention of a name for each string (that doesn't have one already) so that it can be imported is the amount of effort and exposure to error required to get the same functional result as a strategy that keeps the string in the same file ... and this disadvantage applies irrespective of what one does to the string: b"arf", Martin's b("arf"), somebody else's _b ("arf") [IIRC] or my you-aint-gonna-miss-noticing-this-in-the-code BYTES_LITERAL("arf"). Cheers, John From hubaghdadi at gmail.com Sun Jan 18 06:59:51 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Sun, 18 Jan 2009 03:59:51 -0800 (PST) Subject: Am I interacting with the database correctly? Message-ID: Hey, I'm new with database interactions in Python and I'm not sure if I'm handling the cursor and transactions correctly: ++++++++ cursor = db.cursor(MySQLdb.cursors.DictCursor) cursor.execute(flate_rate_pkgs_sql) rows = cursor.fetchall() #I have for loop here to iterate over rows cursor.execute() rows = cursor.fetchall() # some more cursor.execute() calls but only SQL select statements # here is another for loop that contains try block # here are cursor.execute() calls, both insert and update db.commit() # in the except code block, I use db.rollback() ++++++++ As you see, my script contains only one db object and one cursor object and both the db and cursor objects are used multiple times, it is ok? As you might figured, this is a script for reports :) Thanks. From clp2 at rebertia.com Sun Jan 18 07:01:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 04:01:14 -0800 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: <50697b2c0901180401v17e20168yeba34a73771a27f3@mail.gmail.com> On Sun, Jan 18, 2009 at 3:42 AM, andrew cooke wrote: >> Therefore, Python requires you to rewrite the code in some other way >> that makes your intentions more clear. For instance, why not use the >> << operator instead? > > Right, but you're guessing what the context is. Within a DSL it often > makes a lot of sense to use operators for reasons that weren't > originally intended. > > You even make the same case yourself indirectly. The same argument > you make could be made to say that << should only operator on values > that can be shifted. Now thankfully there is no way to test for that, > so there is no restriction and, consequently, it is now widely > accepted that no-one (even people arguing the case for constraints!) > think it odd to use << for something other than its initial use. > > Obviously this kind of discussion has gone on since languages were > first invented - it's the "how much rope" argument. So rather than > continue down that road I would just like to say that this feels like > an inconsistency. The other operators are *not* as restricted and > this is making my life harder. Indeed. Python happens to in this case draw the line at using the augmented assignment operators for non-assignment. I personally see this as reasonable because the = symbol has a consistent meaning in Python (assignment) whereas the other plain operators, as you bring up, consistently have no predetermined meaning; but I do agree that it is in a sense an arbitrary restriction, like many programming language design choices. However, Python was not explicitly designed for creating DSLs, so it's kinda odd to complain about something Python never claimed to support in the first place (although I do favor the DSL in general-purpose-PL paradigm). > It may sound crazy, but this may force me to use * and ** instead (the > context is a language feature related to *args and **kargs, so the * > and ** help convey the meaning). And they have a much much stronger > meaning to users, which will make my DSL harder to understand. So in > this case a blunt knife is making life harder. Perhaps if you explained your particular predicament in more depth, someone might be able to offer a workable suggestion. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From andrew at acooke.org Sun Jan 18 07:14:41 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:14:41 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: Not sure if you were saying this, but the underlying technical reason for this issue is that they are treated as assignment rather than operators in the language spec - http://docs.python.org/3.0/reference/simple_stmts.html#augmented-assignment-statements I think this explains why they are not listed in the operator precedence table http://docs.python.org/3.0/reference/expressions.html#summary I think that's unfortunate in a language with mutable objects, but it makes the decision seem much less arbitrary... Cheers, Andrew From andrew at acooke.org Sun Jan 18 07:24:04 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:24:04 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: On Jan 18, 9:01?am, Chris Rebert wrote: > Indeed. Python happens to in this case draw the line at using the > augmented assignment operators for non-assignment. I personally see > this as reasonable because the = symbol has a consistent meaning in > Python (assignment) whereas the other plain operators, as you bring > up, consistently have no predetermined meaning; my argument was that *= is not treated as = and *, but as a completely new operator (the docs even say that the implementation need not return self which suggests some pretty extreme semantics were envisaged). however, as i've just commented elsewhere, this commitment to operators was only half-baked because they are parsed as assignments. anyway, to reply to your comment - *= is not predetermined. it is determined by __imul__ which is user-definable. > but I do agree that it > is in a sense an arbitrary restriction, like many programming language > design choices. However, Python was not explicitly designed for > creating DSLs, python is a general programming language. as far as i can make any sense at all of your argument it seems to be "you are asking for change, but this is not how the current system works". to which the obvious answer is: if it did work that way i wouldn't be asking for change. andrew From bj_666 at gmx.net Sun Jan 18 07:40:55 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 18 Jan 2009 12:40:55 GMT Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: <6tgmanFaq2t9U1@mid.uni-berlin.de> On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > my argument was that *= is not treated as = and *, but as a completely > new operator (the docs even say that the implementation need not return > self which suggests some pretty extreme semantics were envisaged). What do you mean by "suggests ? extreme semantics"? Most natural thing is to use numbers and there you *have* to be able to return something different than `self` to get anything useful. For instance: n *= 3 with `n` bound to a number different from zero can't return `self` from `__imul__`. Ciao, Marc 'BlackJack' Rintsch From andrew at acooke.org Sun Jan 18 07:56:52 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:56:52 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: On Jan 18, 9:40?am, Marc 'BlackJack' Rintsch wrote: > On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > > my argument was that *= is not treated as = and *, but as a completely > > new operator (the docs even say that the implementation need not return > > self which suggests some pretty extreme semantics were envisaged). > > What do you mean by "suggests ? extreme semantics"? ?Most natural thing > is to use numbers and there you *have* to be able to return something > different than `self` to get anything useful. ?For instance: > > ?n *= 3 > > with `n` bound to a number different from zero can't return `self` from > `__imul__`. in your example, n is not a number, it is a mutable variable, and its value changes. when n is an instance implementing __imul__ the natural analogue is that the internal state of the instance changes. either i have misundertstood you, or you have misunderstood __imul__, or you are treating = as equality, or maybe you are thinking of a pure language that creates new instances? python is impure. anyway, my original request is moot. i was assuming that this was a "capricious" restriction. in fact it's related to what i thought were operators actually being assignments, and so no change is possible (until python 4.0 when guido will finally see the light and move to s- expressions, at which point everyone will stop using the language ;o) andrew From stef.mientki at gmail.com Sun Jan 18 07:57:59 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 13:57:59 +0100 Subject: is there something like a module decorator ? Message-ID: <49732757.6090506@gmail.com> hello, I wonder if there's something like a module decorator. I could use it in debugging a large highly dynamical program. thanks, Stef Mientki From andrew at acooke.org Sun Jan 18 07:58:41 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:58:41 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: On Jan 18, 9:56?am, andrew cooke wrote: > either i have misundertstood you ah, i see your point. sorry, andrew From stef.mientki at gmail.com Sun Jan 18 07:59:55 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 13:59:55 +0100 Subject: is there something like a module decorator ? Message-ID: <497327CB.9020705@gmail.com> hello, I wonder if there's something like a module decorator. I could use it in debugging a large highly dynamical program. thanks, Stef Mientki From deets at nospam.web.de Sun Jan 18 08:06:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 14:06:46 +0100 Subject: is there something like a module decorator ? In-Reply-To: References: Message-ID: <6tgnr6FapcohU1@mid.uni-berlin.de> Stef Mientki schrieb: > hello, > > I wonder if there's something like a module decorator. > I could use it in debugging a large highly dynamical program. No, there isn't. This has been discussed a while ago: http://groups.google.de/group/comp.lang.python/browse_thread/thread/215216a1e13ba2c6 Diez From stef.mientki at gmail.com Sun Jan 18 08:17:33 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 14:17:33 +0100 Subject: is there something like a module decorator ? In-Reply-To: <6tgnr6FapcohU1@mid.uni-berlin.de> References: <6tgnr6FapcohU1@mid.uni-berlin.de> Message-ID: <49732BED.302@gmail.com> Diez B. Roggisch wrote: > Stef Mientki schrieb: >> hello, >> >> I wonder if there's something like a module decorator. >> I could use it in debugging a large highly dynamical program. > > No, there isn't. This has been discussed a while ago: > > http://groups.google.de/group/comp.lang.python/browse_thread/thread/215216a1e13ba2c6 > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list thanks for the information. cheers, Stef From gert.cuykens at gmail.com Sun Jan 18 08:37:38 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 18 Jan 2009 05:37:38 -0800 (PST) Subject: bin = FieldStorage(fp=environ['wsgi.input'], environ=environ) Message-ID: in python3.0 this does not work File "/usr/python/lib/python3.0/email/feedparser.py", line 99, in push data, self._partial = self._partial + data, TypeError: Can't convert 'bytes' object to str implicitly So what do i need to wrap around environ['wsgi.input'] so it does work ? From andrew at acooke.org Sun Jan 18 08:49:08 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 05:49:08 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <7ef985f3-bd3f-4dff-b138-84608604d79d@x14g2000yqk.googlegroups.com> http://bugs.python.org/issue4986 Sorry for the noise, Andrew From castironpi at gmail.com Sun Jan 18 08:58:26 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 05:58:26 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: <818a4683-a467-40d4-b4d0-70cac14a6de0@35g2000pry.googlegroups.com> On Jan 18, 6:56?am, andrew cooke wrote: > On Jan 18, 9:40?am, Marc 'BlackJack' Rintsch wrote: > > > On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > > > my argument was that *= is not treated as = and *, but as a completely > > > new operator (the docs even say that the implementation need not return > > > self which suggests some pretty extreme semantics were envisaged). > > > What do you mean by "suggests ? extreme semantics"? ?Most natural thing > > is to use numbers and there you *have* to be able to return something > > different than `self` to get anything useful. ?For instance: > > > ?n *= 3 > > > with `n` bound to a number different from zero can't return `self` from > > `__imul__`. > > in your example, n is not a number, it is a mutable variable, and its > value changes. > > when n is an instance implementing __imul__ the natural analogue is > that the internal state of the instance changes. > > either i have misundertstood you, or you have misunderstood __imul__, > or you are treating = as equality, or maybe you are thinking of a pure > language that creates new instances? ?python is impure. > > anyway, my original request is moot. ?i was assuming that this was a > "capricious" restriction. ?in fact it's related to what i thought were > operators actually being assignments, and so no change is possible > (until python 4.0 when guido will finally see the light and move to s- > expressions, at which point everyone will stop using the language ;o) > > andrew Not sure if this ties in, but: >>> ['a'].__imul__(2) ['a', 'a'] From Russ.Paielli at gmail.com Sun Jan 18 09:01:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 18 Jan 2009 06:01:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <97d6929a-e82f-4021-95fe-a1f19282f1f1@v39g2000pro.googlegroups.com> Wow! That was an instant classic! I just have a couple of points to add. The suggestion was made (not by you) that data hiding is worthless because it can be defeated anyway. According to that kind of reasoning, locks are worthless because they can be picked, cut, or just blown off. I know that the lock on my front door cannot stop someone who is determined to get into my house, but I think I'll keep it anyway. I'm just irrational that way, I guess. As I said before, I don't know if enforced data hiding can be added to Python without ruining the language (or if it can be added at all, for that matter). But if it can, I think the cleanest and most elegant syntax would be to add the keyword "private" or "priv" and use it essentially the same way it is used in Java, C++, and now Scala. That would eliminate the need for leading underscores, which I personally find tacky. Since new attributes can be added outside of the constructor, the private declaration would also have to be allowed outside the constructor and for existing attributes. One more thing. If an airplane is going to flip upside down and fly straight into the ground, the passengers may as well be nuns. They are better prepared for the result. From reckoner at gmail.com Sun Jan 18 09:19:03 2009 From: reckoner at gmail.com (Reckoner) Date: Sun, 18 Jan 2009 06:19:03 -0800 (PST) Subject: function argument dependent on another function argument? Message-ID: I would like to do: def foo(self,x,y=self.a) where the default value for y=self.a. Since this is not possible, I wind up doing def foo(self,x,y=None) if not y: y=self.a but that seems kind of clumsy. Is there a better way to do this? Thanks in advance From delroth at gmail.com Sun Jan 18 09:32:19 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Sun, 18 Jan 2009 15:32:19 +0100 Subject: output problem In-Reply-To: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> References: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> Message-ID: <1ba9eaed0901180632y32aedfddpd0a27289c1da2026@mail.gmail.com> IIRC, Windows automatically add a newline after the program output. On Fri, Jan 16, 2009 at 4:24 PM, Jean-Paul VALENTIN wrote: > Feature? the output of below Hello program he0.py started from command > line looks as follows: > F:\prompt>he0.py > Hello > F:\prompt> > > 'Hello' was sent with sys.stdout.write, so "without newline". > But why cannot be output (more logically): > F:\prompt>he0.py > HelloF:\prompt> > > Is it normal? Is there any means or workaround to obtain that output if > I wish?? > ________________________________________________________________________ > ______________________ > #!/usr/bin/python > #-*- coding: iso-8859-15 -*- > import sys > sys.stdout.write('Hello') > > > About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. > This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. > P Please consider the environment before printing this e-mail > > > -- > http://mail.python.org/mailman/listinfo/python-list > From alan.isaac at gmail.com Sun Jan 18 09:36:15 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sun, 18 Jan 2009 14:36:15 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: >>> Alan G Isaac wrote: >>>> Is it intentional that ``exec`` cannot handle a TextIOWrapper? >>>> Bottom line: has ``execfile(filename)`` really become >>>> ``exec(open(filename).read())``? Is this a good thing? >> On 1/17/2009 4:20 PM Terry Reedy apparently wrote: >>> Yes. Yes. > Alan G Isaac wrote: >> OK. Why? On 1/17/2009 10:08 PM Terry Reedy apparently wrote: > This: execfile(filename) > is a trivial (9 keystroke) abbreviation of > this: exec(open(filename).read()) > which is similar in effect to > this: from filename import * > so it is really not needed. Well, that does not really answer my question, imo. I do not much care about the disappearance of ``execfile``. I was asking, why is it a **good thing** that ``exec`` does not accept a TextIOWrapper? Or is it just not implemented yet? What is the gain from this particular backwards incompatibility (in the sense that ``exec(open(fname))`` no longer works)? Context: I used to be able to tell students they could run their scripts from the interpreter prompt with ``execfile(fname)``. I expected to be able to tell them to ``exec( open(fname) )``, which worked in Python 2. Now instead it is ``exec( open(filename).read() )`` which is a bit more mysterious to a newbie. (Note: I teach economics, not computer science.) And despite your claim above, you know that ``import`` is not really equivalent, and even more so now that ``reload`` must be imported. Thanks, Alan Isaac From castironpi at gmail.com Sun Jan 18 09:41:31 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 06:41:31 -0800 (PST) Subject: function argument dependent on another function argument? References: Message-ID: <6bff986d-ad30-473d-aecf-cd0377437496@v5g2000pre.googlegroups.com> On Jan 18, 8:19?am, Reckoner wrote: > I ?would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I > wind up doing > > def foo(self,x,y=None) > ? if not y: > ? ? y=self.a > > but that seems kind of clumsy. > > Is there a better way to do this? > > Thanks in advance No. The only alternative is really niche and probably not what you want. You'd use a decorator (which I don't have, btw): @defval( y= selfattrget( 'a' ) ) def foo( self, x, y ). From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:06:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:06:58 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz1zjzp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Message-ID: <4973533a$0$23748$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Once again, there's quite a lot to learn from >> the story of Ariane 5. > > Do you know what actually happened with Ariane 5? *yes I do* - else I wouldn't mention it. Thanks. > The failure was > because "smart" humans overrode the language enforced protection by > casting a floating point number down to a 16-bit integer, which worked > ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger > numbers were involved. The failure was because a module tested, QA'd and certified within a given context (in which it was ok to drop the builtin error handling) was reused in a context where it was not ok. And the point is exactly that : no *technology* can solve this kind of problem, because it is a *human* problem (in that case, not taking time to repass the whole specs / tests / QA process given context change). From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:20:54 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:20:54 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> Message-ID: <4973567f$0$14315$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 17, 1:43 pm, Paul Rubin wrote: >> Bruno Desthuilliers writes: >>> Once again, there's quite a lot to learn from >>> the story of Ariane 5. >> Do you know what actually happened with Ariane 5? The failure was >> because "smart" humans overrode the language enforced protection by >> casting a floating point number down to a 16-bit integer, which worked >> ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger > > So this turns out to be an example of a failure due, not to the > *rigidity* of Ada, but to its *permissiveness* in allowing such a > cast. Nope. This is an example of failure due to the *human* part of the process - this happened because of a lack of testing / QA, not because of a language feature or misfeature. (snip) >> This is one thing that Python gets right, automatically using bignums >> rather than allowing int overflow. In that sense, Python has more >> enforced protection than Ada. > > True, but Ada does not have the luxury of just using doubles and > "bignums" everywhere, because it needs to work on cheap processors > too. But perhaps it could somehow be configured to do so by the user > if sufficiently powerful computers are being used. Here the error was *not* to disable the overflow error checking (in the context of Ariane 4), but to reuse the module as-is in another context. As I already stated, no technology can protect us from this kind of error. Ask yourself why this module was reused as-is, instead of going thru the whole specs / tests / QA process again, and *perhaps* you'll start to understand why I say that language-enforced access restrictions are the wrong solution to a real problem. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:26:25 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:26:25 GMT Subject: function argument dependent on another function argument? References: Message-ID: <01834097$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 06:19:03 -0800, Reckoner wrote: > I would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I wind > up doing > > > def foo(self,x,y=None) > if not y: > y=self.a > > but that seems kind of clumsy. It's also incorrect, because if you pass y=0 as an argument, or any other false value, it will be replaced by self.a. > Is there a better way to do this? def foo(self, x, y=None): if y is None: y = self.a I don't find that clumsy in the least. I find it perfectly readable and a standard idiom. -- Steven From ra.ravi.rav at gmail.com Sun Jan 18 10:30:52 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 18 Jan 2009 07:30:52 -0800 (PST) Subject: Difference between Python 2.2.2 and Python 2.5 Message-ID: I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I know is Python 2.5 . Can you please tell me differences between the two so that I can save myself from incompatible code. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:36:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:36:35 GMT Subject: Python 3: exec arg 1 References: Message-ID: <018342f9$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 14:36:15 +0000, Alan G Isaac wrote: > Well, that does not really answer my question, imo. I do not much care > about the disappearance of ``execfile``. I was asking, why is it a > **good thing** that ``exec`` does not accept a TextIOWrapper? I'm not sure if this is a stupid question or not, but what's a TextIOWrapper? In the example you give: exec(open(fname)) the argument to exec -- open(fname) -- is a file object: >>> type(open('hello.py')) BTW, exec is a statement. The brackets there are totally superfluous. You can, and should, write: exec open(fname) > Or is it just not implemented yet? > What is the gain from this particular backwards incompatibility (in the > sense that ``exec(open(fname))`` no longer works)? Simplicity of implementation? > Context: I used to be able to tell students they could run their scripts > from the interpreter prompt with ``execfile(fname)``. I expected to be > able to tell them to ``exec( open(fname) )``, which worked in Python 2. > Now instead it is ``exec( open(filename).read() )`` which is a bit more > mysterious to a newbie. (Note: I teach economics, not computer > science.) Why don't you give your students a site.py module containing def execfile(fname): exec open(fname).read() and tell them to do "from site import execfile"? If you control the environment they are running their programs on (school computers?) then you can put a startup file in their path and have execfile imported automatically. -- Steven From http Sun Jan 18 10:36:53 2009 From: http (Paul Rubin) Date: 18 Jan 2009 07:36:53 -0800 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def foo(self, x, y=None): > if y is None: > y = self.a > > I don't find that clumsy in the least. I find it perfectly readable and a > standard idiom. That has the same problem as the earlier version. If the person passes None, they get self.a. I prefer: sentinel = object() ... def foo(x, y=sentinel): if y is sentinel: y = self.a From bbxx789_05ss at yahoo.com Sun Jan 18 10:40:20 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Sun, 18 Jan 2009 07:40:20 -0800 (PST) Subject: output problem References: Message-ID: <84d6d0c6-3b1b-4579-b16d-f8238f7f1a41@g3g2000pre.googlegroups.com> On Jan 16, 8:24?am, "Jean-Paul VALENTIN" wrote: > Feature? the output of below Hello program he0.py started from command > line looks as follows: > F:\prompt>he0.py > Hello > F:\prompt> > > 'Hello' was sent with sys.stdout.write, so "without newline". > But why cannot be output (more logically): > F:\prompt>he0.py > HelloF:\prompt> > > Is it normal? Is there any means or workaround to obtain that output if > I wish?? > ________________________________________________________________________ > ______________________ > #!/usr/bin/python > #-*- coding: iso-8859-15 -*- > import sys > sys.stdout.write('Hello') > Not on a Mac: import sys sys.stdout.write("hello") output: $ python 6test.py hello$ From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:44:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:44:02 GMT Subject: Difference between Python 2.2.2 and Python 2.5 References: Message-ID: <018344b9$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I > know is Python 2.5 . > > Can you please tell me differences between the two so that I can save > myself from incompatible code. Everything new mentioned here: http://www.python.org/doc/2.5/whatsnew/whatsnew25.html http://www.python.org/doc/2.4/whatsnew/whatsnew24.html http://www.python.org/doc/2.3/whatsnew/whatsnew23.html won't exist in Python 2.2. -- Steven From luismgz at gmail.com Sun Jan 18 10:46:16 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 18 Jan 2009 07:46:16 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Jan 18, 8:56?am, andrew cooke wrote: > Since this is a PyPy bashing thread, maybe it's an appropriate place > to suggest that the project has got a little bit waylaid by exploring > cool things instead of releasing a useful final result? > > I am not questioning rpython directly - the case for something like > that is obvious. ?But there's a question of balance. ?It's possible to > go on building ever more complex systems which are theoretically > justified, but which postpone ever finishing the job. ?At some point > there has to be a "good enough". > > To some extent I am playing devil's advocate here, but as an outside > who looked at PyPy a while back, my uninformed and naive impression > was that the project was suffering from the kid of issues I have > caricatured above.... > > Andrew > > PS I guess you are aware of worse is better etc? ?I think this may > also be a US/Euro culture issue... It's worth adding that, regarding the goal of having a faster python, we have had for a long time a solid and useful proof-of-concept in psyco. Pypy rolls up on this concept and adds many more useful features, not all of them related to speed but to flexibility. I have no doubt the project will be succesful. The question is how long we will have to wait... Luis From castironpi at gmail.com Sun Jan 18 10:49:29 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 07:49:29 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> On Jan 18, 9:36?am, Paul Rubin wrote: > Steven D'Aprano writes: > > def foo(self, x, y=None): > > ? ? if y is None: > > ? ? ? ? y = self.a > > > I don't find that clumsy in the least. I find it perfectly readable and a > > standard idiom. > > That has the same problem as the earlier version. ?If the person > passes None, they get self.a. ?I prefer: > > ? ? sentinel = object() > ? ? ... > > ? ? def foo(x, y=sentinel): > ? ? ? if y is sentinel: > ? ? ? ? ? y = self.a It is too bad that it is so much work to detect whether 'y' was passed in the function call directly. However, sentinel is just as good (or nearly); at worst, you need one sentinel per argument per function, which is possible to create, which has a specific meaning. If you are making systematic function calls, e.g. with a dictionary or list, you can just use the sentinel in the dictionary. From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:49:51 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:49:51 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <49735d48$0$3516$426a74cc@news.free.fr> Russ P. a ?crit : > No one ever claimed that a programming language, no matter how > rigorous, can eliminate all bugs. All a language can do is to reduce > their rate of occurrence. > > The Ariane fiasco was not a failure of Ada per se but rather a failure > of people using Ada. Almost right. > They attempted to re-use software written for one > rocket for another without proper testing. No language can prevent > that sort of error. Now this is plain right. > We can argue forever about the usefulness of language-enforced > restriction of access to private data and methods. I have no doubt > whatsoever that it is very useful at least for the extreme cases of > very large, safety-critical systems. And my POV is that it's just plain useless. > If you don't think access to > private data needs to be restricted for control of strategic nuclear > arsenals, for example, I think you're crazy, but that's just my > opinion. If you think that this kind of access restriction makes softwares controling strategic nuclear arsenal any safer, then *you* are totally crazy. As *you* stated above, "no language can prevent this kind of error". > The only reasonable question in my mind is where the line should be > drawn between systems that should have enforced restrictions and those > that can rely on coding standards and voluntary cooperation among > programmers. The only reasonable question in *my* mind is whether you think it's better, specially for safety-critical stuff, to hire people you can trust or to rely on technology. > A while back, I read something about the final integration of the > flight software on the Boeing 777, which was written mainly in Ada. > The claim was made that this integration took only three days, whereas > normally it would be expected to take more like three months with a > less rigorous language such as C++. The reason for the simplified > integration is that Ada enforces interfaces and prevents access to > private data and methods. C++ does it too. Or at least, that's a very common "claim" about C++. > Apparently such enforcement can improve the > efficiency of software production -- and that's not just in "theory." My own experience is that too much rigidity in a language only leads to more boilerplate code and more workarounds (design patterns anyone ?), IOW more accidental complexity, hence more space for bugs to creep in. My very humble (no don't say it) opinion about this is that what's important is how you handle and manage the whole project (including both technical and non-technical aspects), not the technology used (which might be relevant - I of course wouldn't use Python for anything real-time - or not - most of the monstruogigantic "entreprise" software written in Java would work just as well in Python or any other decent language). No technology will prevent human errors - I think this point is clear, and that we both agree on it. OTHO, some technologies can at least help reducing the opportunities for human errors - and I think we also agree on this. Now the point is : *how* can a given techno helps wrt/ this second goal. Here you have two philosophies. One is that you'll reduce errors by improving simplicity and readability, and by promoting trust (whithin the team), sense of responsabily, and communication. The other one is that you'll reduce errors by not allowing those stupid code-monkeys to do anything that *might* (according mostly to unproved assertions) be "dangerous" - hence promoting distrust and irresponsability, and adding quite a lot of accidental complexity. BTW, do you know the by far most common Java idiom ? It's named the "do-nothing catch-all exception handler". As an excercise, explain the reasons behind this idiom, and it's practical results. As a last point : I certainly don't think Python is perfect in any way, *nor* that it's the appropriate tool for each and any project. I just disagree with you on your assertion that Python is not ok for large or critical projects because of it's "lack" of language-enforced access restriction. From fairwinds.dp at gmail.com Sun Jan 18 10:52:29 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Sun, 18 Jan 2009 11:52:29 -0400 Subject: Ordering attributes for dynamically generated class Message-ID: Hi list. I use 'type' to generate classes but have a need to order the attributes for the generated class. Of course a dict is not going to maintain ordering. Is there any way to dynamically generate a class with attributes in specific order? my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) Many thanks, David From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:53:48 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:53:48 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> Message-ID: <49735e35$0$21820$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 17, 11:49 am, Bruno Desthuilliers > wrote: > >> Please educate yourself and learn about why Ariane 5 crashed on it's >> first flight, due to an error in a module written in ADA (which is such >> a psychorigid language that C++ and Java are even looser than Javascript >> in comparison). Perhaps will it light a bulb for you. > > The claim here regarding the Ariane 5 failure is one of those urban > myths that refuses to die. You failed the test. Sorry. > It has been refuted over and over What has been refuted exactly ? > (including on this thread already), but I would just like to add > something in defense of Ada. > > Studies have found that Ada reduces both bugs and long-term > development costs by something like a factor of two compared to C. This _might_ (or not - there are too many variables to get any scientific certitudes here) be true. But that was not the point. See my other posts here for more about it. From jfabiani at yolo.com Sun Jan 18 10:54:06 2009 From: jfabiani at yolo.com (John Fabiani) Date: Sun, 18 Jan 2009 07:54:06 -0800 Subject: Am I interacting with the database correctly? References: Message-ID: Hussein B wrote: > Hey, > I'm new with database interactions in Python and I'm not sure if I'm > handling the cursor and transactions correctly: > ++++++++ > cursor = db.cursor(MySQLdb.cursors.DictCursor) > cursor.execute(flate_rate_pkgs_sql) > rows = cursor.fetchall() > #I have for loop here to iterate over rows > cursor.execute() > rows = cursor.fetchall() > # some more cursor.execute() calls but only SQL select statements > # here is another for loop that contains try block > # here are cursor.execute() calls, both insert and update > db.commit() > # in the except code block, I use db.rollback() > ++++++++ > As you see, my script contains only one db object and one cursor > object and both the db and cursor objects are used multiple times, it > is ok? > As you might figured, this is a script for reports :) > Thanks. I have never worked with MySQL. I do work with others. The first part looks fine. If you insert, update or delete then you need a 'commit' or a 'rollback'. Preparing data for a report it is unlikely that you need to commit or rollback anything. After all you are only using 'select'. John From castironpi at gmail.com Sun Jan 18 10:57:15 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 07:57:15 -0800 (PST) Subject: Ordering attributes for dynamically generated class References: Message-ID: On Jan 18, 9:52?am, David Pratt wrote: > Hi list. I use 'type' to generate classes but have a need to order ? > the attributes for the generated class. Of course a dict is not going ? > to maintain ordering. Is there any way to dynamically generate a ? > class with attributes in specific order? > > my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) > > Many thanks, > David Just a thought, you can subclass 'dict' and assign an instance of it to the __dict__ member of your new instance. From vedrandekovic at yahoo.com Sun Jan 18 11:09:02 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 18 Jan 2009 08:09:02 -0800 (PST) Subject: Python and threads Message-ID: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Hello again, Thanks for previous help on "Start two threads in same time" it was useful,but when I run this two threads, I think they don't start at the same time, here is my code snippet: import threading class ThreadedClass1(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): a=True while a==True: bm=my_module.MyClass() a=bm.get_Python_Process_Usage_Function() #Returns True or False class ThreadedClass2(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): os.popen("my_python_script.py") threaded_obj = ThreadedClass1() threaded_obj.start() threaded_obj2 = ThreadedClass2() threaded_obj2.start() Regards, John From thorsten at thorstenkampe.de Sun Jan 18 11:18:15 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 18 Jan 2009 17:18:15 +0100 Subject: process command line parameter References: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Message-ID: * asit (Sat, 17 Jan 2009 13:28:12 -0800 (PST)) > Recently I was coding a link extractor. It's a command line stuff and > takes parameter as argument. > I found that the in operator is not always helpful. > eg. if "--all" in sys.argv: > print "all links will be printed" > > its not helpful when some attribute value is sent in command line > parameter. > hence I want to process some data like find=".co.uk" > > How can i do this ??? Use optparse From duncan.booth at invalid.invalid Sun Jan 18 11:24:16 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Jan 2009 16:24:16 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> Message-ID: alex23 wrote: > I must confess I've rarely had a need to use __import__ and don't > think I've ever used the fromlist arg. I'm confused, though, because > the docstring states: > > The fromlist should be a list of names to emulate ``from name > import ...'' > > But it also states that __import__ always returns a module, so I'm > utterly confused as to the purpose of fromlist, or how to inject the > specified entries into the calling namespace. If anyone could explain > this for me, I'd really appreciate it. Compare these: >>> dom = __import__('xml').dom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'dom' >>> dom = __import__('xml', fromlist=['dom']).dom >>> dom Then in a new session: >>> import xml >>> xml.dom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'dom' >>> from xml import dom >>> dom >>> When you import a package such as xml it only imports the top level. Modules and subpackages within the imported package aren't available until they are explicitly imported. The fromlist argument to __import__ allows you to force the lower modules to also import. >>> xml = __import__('xml', fromlist=['dom']) is effectively the same as doing: >>> import xml.dom After either of these you have a name 'xml' which has an attribute 'dom': >>> xml.dom To access the actual sub-objects using __import__ use getattr on the returned module. So far as injecting names into the calling namespace is concerned just assign to variables; you don't want to be injecting unknown names into your namespace. For the same effect if you only have one name and you know it is a module you could do: >>> xml = __import__('xml.dom') but you need the fromlist parameter if you don't know which of the names are modules. From http Sun Jan 18 11:25:21 2009 From: http (Paul Rubin) Date: 18 Jan 2009 08:25:21 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> Message-ID: <7xmydomvim.fsf@ruckus.brouhaha.com> "Russ P." writes: > I don't know which variant of Ada was used here, but something called > the "Ravenscar Profile" is a reduced subset of Ada that might have > prevented this error (though I haven't verified this). Then there is > Spark Ada, which supposed to be much safer than even Ada. I'm not sure, but I think Ravenscar and Spark would both have permitted the cast. However, Spark is intended to be used with an external tool called Spade (sort of a Pylint on steroids) that would not have allowed the cast unless it was provable (starting from the specification) that the number was in range before the cast. I.e. the cast was wrong because of the failure of an unstated assumption that a certain sensor reading was in a certain range. Spark may still have allowed the cast only if the assumption was stated explicitly in the specification. Requiring the assumption to be stated may have made the error more likely to be spotted as part of the surrounding systems engineering. Of course, the specification can still be wrong, but that's hardly a problem with Ada or even with the software. It's not too much different than if the specification says the rocket is 10 feet wide and they build the launch pad for that size, but then the rocket turns out to actually be 12 feet wide. I have Barnes's book about Spark at the office and will try to check next week what it says about these casts. From fairwinds.dp at gmail.com Sun Jan 18 11:26:22 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Sun, 18 Jan 2009 12:26:22 -0400 Subject: Ordering attributes for dynamically generated class In-Reply-To: References: Message-ID: Hi Aaron. Yeah, definitely sounds like a possibility. I was able to locate an ordered dict implementation that subclasses dict. This might work fine. Might be able to pass into type method directly since I think that dict passed into type is setting __dict__ I believe. Let you know if that works out. Many thanks. Regards, David On Jan 18, 2009, at 11:57 AM, Aaron Brady wrote: > On Jan 18, 9:52 am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order >> the attributes for the generated class. Of course a dict is not going >> to maintain ordering. Is there any way to dynamically generate a >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, >> dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > -- > http://mail.python.org/mailman/listinfo/python-list From http Sun Jan 18 11:30:03 2009 From: http (Paul Rubin) Date: 18 Jan 2009 08:30:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <4973567f$0$14315$426a34cc@news.free.fr> Message-ID: <7xiqocmvas.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > As I already stated, no technology can protect us from this kind of > error. Ask yourself why this module was reused as-is, instead of going > thru the whole specs / tests / QA process again, and *perhaps* you'll > start to understand why I say that language-enforced access > restrictions are the wrong solution to a real problem. I have not seen anywhere that the specs stated that the sensor reading that overflowed that variable was supposed to be in range. It looks to me (but I don't know for sure) that the development process allowed an assumption to creep into the code that wasn't stated in the specs. From stefan_ml at behnel.de Sun Jan 18 11:40:22 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 17:40:22 +0100 Subject: changing URLs in webpages, python solutions? In-Reply-To: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Message-ID: <49735b76$0$31867$9b4e6d93@newsspool3.arcor-online.net> Simon Forman wrote: > I want to take a webpage, find all URLs (links, img src, etc.) and > rewrite them in-place, and I'd like to do it in python (pure python > preferred.) lxml.html has functions specifically for this problem. http://codespeak.net/lxml/lxmlhtml.html#working-with-links Code would be something like html_doc = lxml.html.parse(b"http://.../xyz.html") html_doc.rewrite_links( ... ) print( lxml.html.tostring(html_doc) ) It also handles links in CSS or JavaScript, as well as broken HTML documents. Stefan From ericcire at gmail.com Sun Jan 18 11:41:10 2009 From: ericcire at gmail.com (Eric) Date: Sun, 18 Jan 2009 08:41:10 -0800 (PST) Subject: calling an external program and capturing the output Message-ID: Coming from a perl background I'm new to the Python world. I need to read a list of values, send each value to an external program and capture and act on the output of that program. Reading and parsing the initial values is not a problem but I can't seem to find anything on the sending to and capturing from an external program. Any suggestions would be greatly appreciated. -Eric From stefan_ml at behnel.de Sun Jan 18 11:42:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 17:42:49 +0100 Subject: Python and threads In-Reply-To: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Message-ID: <49735c09$0$31867$9b4e6d93@newsspool3.arcor-online.net> vedrandekovic at yahoo.com wrote: > Thanks for previous help on "Start two threads in same time" it was > useful,but when I run this > two threads, I think they don't start at the same time That's normal. Threading is an unpredictable concurrency pattern. Things often don't happen the way one would want them to. Stefan From rtw at freenet.co.uk Sun Jan 18 11:44:23 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 10:44:23 -0600 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> Message-ID: Aaron Brady wrote in news:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh.googlegroups.com in comp.lang.python: > On Jan 18, 9:36?am, Paul Rubin wrote: >> Steven D'Aprano writes: >> > def foo(self, x, y=None): >> > ? ? if y is None: >> > ? ? ? ? y = self.a >> >> > I don't find that clumsy in the least. I find it perfectly readable >> > and > a >> > standard idiom. >> >> That has the same problem as the earlier version. ?If the person >> passes None, they get self.a. ?I prefer: >> >> ? ? sentinel = object() >> ? ? ... >> >> ? ? def foo(x, y=sentinel): >> ? ? ? if y is sentinel: >> ? ? ? ? ? y = self.a > > It is too bad that it is so much work to detect whether 'y' was passed > in the function call directly. However, sentinel is just as good (or > nearly); at worst, you need one sentinel per argument per function, One per Module should be good enough. The only reason None doesen't suffice is that it has other legitimate uses. Though to be honest I would always use None as the sentinel if it wasn't a legitimate argument. > which is possible to create, which has a specific meaning. If you are > making systematic function calls, e.g. with a dictionary or list, you > can just use the sentinel in the dictionary. IIUYC then, one sentinel is still only needed as the missing argument is indicated by *both* position and value or by name and value (in the case of a keyword-dictionary), so seperate distinct sentinel objects aren't required, for example: SENTINEL = object() def f( a, b, c = SENTINEL, d = SENTINEL ): print( "values: %r" % ( ( a, b, c, d ), ) ) if c is SENTINEL: print( "c is missing" ) if d is SENTINEL: print( "d is missing" ) f( *( 1, 2, SENTINEL, SENTINEL ) ) f( **dict( a = 1 , b = 2, d = 4 ) ) f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) Rob. -- http://www.victim-prime.dsl.pipex.com/ From duncan.booth at invalid.invalid Sun Jan 18 11:45:24 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Jan 2009 16:45:24 GMT Subject: Ordering attributes for dynamically generated class References: Message-ID: Aaron Brady wrote: > On Jan 18, 9:52?am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order ? >> the attributes for the generated class. Of course a dict is not going ? >> to maintain ordering. Is there any way to dynamically generate a ? >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > You can certainly pass a subclass of 'dict' to type(), in fact in Python 3.0 you can use a metaclass with a __prepare__ method to substitute your own value for __dict__ in any class definition, but I don't think your own type will preserved when the instance is actually constructed. A simple solution which works in any version of Python is just to maintain an attribute with the desired ordering and override __dir__ to return the attributes in that order. From deets at nospam.web.de Sun Jan 18 11:48:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 17:48:49 +0100 Subject: Python and threads In-Reply-To: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Message-ID: <6th4riFat1vuU1@mid.uni-berlin.de> vedrandekovic at yahoo.com schrieb: > Hello again, > > Thanks for previous help on "Start two threads in same time" it was > useful,but when I run this > two threads, I think they don't start at the same time, here is my > code snippet: > > > import threading > > class ThreadedClass1(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > a=True > while a==True: > bm=my_module.MyClass() > a=bm.get_Python_Process_Usage_Function() #Returns True > or False > > class ThreadedClass2(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > os.popen("my_python_script.py") > > > > threaded_obj = ThreadedClass1() > threaded_obj.start() > threaded_obj2 = ThreadedClass2() > threaded_obj2.start() If you want to synchronize two or more threads, you need to do so manually using objects like Locks, Events, Conditions and Semaphores. See the threading module. Even if you managed to get two threads started simultaneously (which the OS doesn't even offer IINM), the would soon run out of sync. How about you tell us what you *want*, and we tell you if and how it's possible to do that. Diez From deets at nospam.web.de Sun Jan 18 11:49:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 17:49:06 +0100 Subject: calling an external program and capturing the output In-Reply-To: References: Message-ID: <6th4s2Fat1vuU2@mid.uni-berlin.de> Eric schrieb: > Coming from a perl background I'm new to the Python world. I need to > read a list of values, send each value to an external program and > capture and act on the output of that program. Reading and parsing the > initial values is not a problem but I can't seem to find anything on > the sending to and capturing from an external program. > > Any suggestions would be greatly appreciated. See the module subprocess. Diez From rtw at freenet.co.uk Sun Jan 18 12:06:10 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 11:06:10 -0600 Subject: Python 3: exec arg 1 References: <018342f9$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote in news:018342f9$0$8693$c3e8da3 at news.astraweb.com in comp.lang.python: > I'm not sure if this is a stupid question or not, but what's a > TextIOWrapper? In the example you give: > > exec(open(fname)) > > the argument to exec -- open(fname) -- is a file object: > >>>> type(open('hello.py')) > > > > BTW, exec is a statement. The brackets there are totally superfluous. > You can, and should, write: > > exec open(fname) > You must have missed the subject line: "Re: Python 3: exec arg 1" Python 3.0 (r30:67507, Dec 3 2008, 19:44:23) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> open( "hello.py" ) >>> exec "a = 1" File "", line 1 exec "a = 1" ^ SyntaxError: invalid syntax >>> exec( "a = 1" ) >>> a 1 >>> Rob. -- http://www.victim-prime.dsl.pipex.com/ From gagsl-py2 at yahoo.com.ar Sun Jan 18 12:09:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 15:09:01 -0200 Subject: Am I interacting with the database correctly? References: Message-ID: En Sun, 18 Jan 2009 13:54:06 -0200, John Fabiani escribi?: > I have never worked with MySQL. I do work with others. The first part > looks fine. If you insert, update or delete then you need a 'commit' or > a 'rollback'. Preparing data for a report it is unlikely that you need > to > commit or rollback anything. After all you are only using 'select'. Note that you have to commit/rollback a transaction *even* if you only execute select statements - at least when using isolation levels higher than "read uncommited". By example, using "repeatable reads", a "select" on table A blocks any attempt to modify the involved rows until the transaction ends. And using "read commited", it won't see rows modified or added after the transaction began. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 12:09:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 15:09:01 -0200 Subject: Am I interacting with the database correctly? References: Message-ID: En Sun, 18 Jan 2009 13:54:06 -0200, John Fabiani escribi?: > I have never worked with MySQL. I do work with others. The first part > looks fine. If you insert, update or delete then you need a 'commit' or > a 'rollback'. Preparing data for a report it is unlikely that you need > to > commit or rollback anything. After all you are only using 'select'. Note that you have to commit/rollback a transaction *even* if you only execute select statements - at least when using isolation levels higher than "read uncommited". By example, using "repeatable reads", a "select" on table A blocks any attempt to modify the involved rows until the transaction ends. And using "read commited", it won't see rows modified or added after the transaction began. -- Gabriel Genellina From castironpi at gmail.com Sun Jan 18 12:16:28 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 09:16:28 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> Message-ID: <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> On Jan 18, 10:44?am, Rob Williscroft wrote: > Aaron Brady wrote innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 9:36?am, Paul Rubin wrote: > >> Steven D'Aprano writes: > >> > def foo(self, x, y=None): > >> > ? ? if y is None: > >> > ? ? ? ? y = self.a > > >> > I don't find that clumsy in the least. I find it perfectly readable > >> > and > > ?a > >> > standard idiom. > > >> That has the same problem as the earlier version. ?If the person > >> passes None, they get self.a. ?I prefer: > > >> ? ? sentinel = object() > >> ? ? ... > > >> ? ? def foo(x, y=sentinel): > >> ? ? ? if y is sentinel: > >> ? ? ? ? ? y = self.a > > > It is too bad that it is so much work to detect whether 'y' was passed > > in the function call directly. ?However, sentinel is just as good (or > > nearly); at worst, you need one sentinel per argument per function, > > One per Module should be good enough. The only reason None doesen't > suffice is that it has other legitimate uses. ?Though to be honest > I would always use None as the sentinel if it wasn't a legitimate > argument. > > > which is possible to create, which has a specific meaning. ?If you are > > making systematic function calls, e.g. with a dictionary or list, you > > can just use the sentinel in the dictionary. > > IIUYC then, one sentinel is still only needed as the missing argument > is indicated by *both* position and value or by name and value (in the > case of a keyword-dictionary), so seperate distinct sentinel objects > aren't required, for example: > > SENTINEL = object() > > def f( a, b, c = SENTINEL, d = SENTINEL ): > ? print( "values: %r" % ( ( a, b, c, d ), ) ) > ? if c is SENTINEL: > ? ? print( "c is missing" ) > ? if d is SENTINEL: > ? ? print( "d is missing" ) > > f( *( 1, 2, SENTINEL, SENTINEL ) ) > > f( **dict( a = 1 , b = 2, d = 4 ) ) > > f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > > Rob. > --http://www.victim-prime.dsl.pipex.com/ I don't have a concrete example, so you may prove to be right, but I'm not convinced. If you have one function with an argument that defaults to an empty list, and calls another with an argument that defaults to an empty dict, then what is the meaning of passing sentinel to the first one? Whereas, if each had their own, then passing the first one's default would mean the empty list, and passing the second one's default would mean the dict. (Or, even if that evaluates correctly, perhaps there is no such useful program.) From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 12:22:06 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 18:22:06 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0182b484$0$8693$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <497372e7$0$23747$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > >> Russ P. a ?crit : (snip) > >>> Why leave to >>> coding standards and company policy what can be encoded right into the >>> language? >> Because human are smarter than computers. > > That's an awfully naive statement. It's a sound-byte instead of a > reasoned argument. We're smarter than computers? Obviously and definitively, yes. Not that we are that smart - it's just that computers are totally stupids. The differences between a human and a computer are that 1/ a human can eventually DWIM. 2/ a computer can do what is has been told way faster than any human The first point is being smart. The second is being fast. Not quite the same thing !-) > Then why are we > programming in languages like Python instead of directly in machine code? > Why can optimizing C compilers make more efficient code than the best > human assembly language programmers? Because : 1/ this is something that can be solved by heavy computations 2/ these computations can be programmed 3/ these compuations would just take too long for a human being to do manually > Humans and computers are smart at different things. s/smart/good/g >>> Why leave to humans (who are known to err) what can be automated >>> relatively easily? Isn't that what computers are for? >> Error is human. For a real catastrophic failure, it requires a computer. > > Oh rubbish. That's a sound-byte invented by nervous technophobes scared > of computers. Nope, that's a computer-user joke. > >>> All those "setters" and >>> "getters" are a kludge. I think Python "properties" are a major step >>> forward here. Just for fun, I checked to see if Scala has properties. >>> Guess what? Not only does it have them, but they are generated >>> automatically for all member data. That's even better than Python >>> properties! >> Oh yes ? "Better", really ? So it's better to have a language that >> automagically breaks encapsulation (requiring an additionnal level of >> indirection) than a language that do the right thing by default ? I'm >> afraid I missed the point ??? > > You certainly do. How do properties "break" encapsulation rather than > enforcing it? Properties by themselves are not the problem, quite on the contrary - as you say, they actually help wrt/ encapsulation. What breaks encapsulation is *automatic generation* for properties for *each and any* implementation attribute. Might as well just makes them all public attribute then. > > >>>>> As I said before, enforced encapsulation may not be appropriate for >>>>> every application, but it is definitely appropriate for some. >>>> No. It is appropriate for dummy managers hiring dummy programmers. The >>>> project's size and domain have nothing to do with it. >>> Let me try to be very clear here. We are dealing with two separate but >>> related issues. The first is whether data hiding should be added to >>> Python. >> No need to add it, it's already there : every name that starts with an >> underscore is hidden !-) > > That's not hidden. It's there in plain sight. Once again, I'm afraid you missed the joke - despite the smiley. >>> Whether it can be added without screwing up the language, I don't know. >>> If not, then so be it. That just limits the range of domains where >>> Python is suitable. >> That's just plain stupid. > > No it's not. It's *practical*. There are domains where *by law* code > needs to meet all sorts of strict standards to prove safety and security, > and Python *simply cannot meet those standards*. Oh, sorry. I was talking about *technical* issues, not about legal ones. IANAL... (snip) >>> I like to use the example of the flight software for a large commercial >>> transport aircraft, but many other examples could be given. How about >>> medical systems that control radiation therapy or chemotherapy? How >>> about financial systems that could take away your retirement account in >>> 1.5 milliseconds. Or how about the control software for the strategic >>> nuclear arsenals of the US or Russia? When you consider the sea, air, >>> and land-based components, I'm sure that's one hell of a lot of code! >> And ? Such systems have been written (and quite a lot are still running) >> with languages way more permissive than Python. You know, languages like >> C or assembly. > > Yes, and it is *hard* because the programmer has to worry about data > hiding *on his own*. Nope, it's hard because C and assembly are very low-level languages where you have to micro-manage each and everything. This has nothing to do with data hiding (unless you count memory management as data hiding ?) > One of my friends has worked for many years programming some pretty high- > powered banking software. Their approach is to move data-hiding into the > database, or the operating system. Cobol doesn't enforce encapsulation, > but the database and OS certainly do, with a permissions-based approach. Guess what ? Whatever the language (Cobol, Java, Python, or even VB), chances are such an application would be written using a RDBMS (not even addressing the point about OS). > Speaking of banking software, consider a typical banking application. It > may have dozens or hundreds of programmers working on it. It's too big > for any one person to understand all of it. Once deployed it may > potentially have access to hundreds of billions of dollars of other > people's money. Don't you imagine that one or two of these programmers > might be tempted to skim a little off the top? There have been some major failure on such applications written with "serious" languages like Java. Know the sooo common "catch-all do-nothing exception handler" idiom in Java ? > Data hiding is a good way of making sure that the guy writing the front > end can't just turn of the audit trail and transfer $60,000,000 into his > bank account. Man, you can't be serious ? Tell me this is a joke ? > >> Until you understand that *no technology is idiot-proof*, >> you'll get nowhere in "software engineering". > > I suspect that Russ has got a lot further in software engineering than > you have. Most of what is actually labelled as "software engineering" is snake oil. They're trying to sell you silver bullets. Now where's the werewolf? > No technology is failure proof. But there's no reason in the world why > most technology can't be idiot-proof. Televisions are idiot-proof, > because they protect people from casual mistakes. If televisions were > built according to the Python model, the internals of the TV would be > exposed, without even a cover. All the major parts would be plug-in > rather than soldered in, and there would be no cover over the parts that > were live. Every year, tens of thousands of people would electrocute > themselves fatally (because parts of the TV holds a massive charge for > days after you unplug them from the mains) but that would be okay, > because you never know when somebody might want to pull out the fly-back > transformer and replace it with a six ohm resistor. That sort of dynamism > is important! Really nice metaphor. Alas, there are limits to what you can do with metaphores. (snip remaining) > [...] >>> An FMS programmer could perhaps >>> decide to change the parameters of the engine controls, for example. >> Why on earth would he do something so stupid ? > > I'm sure he'd think he had a good reason. As you said, > > "Because sometimes you have a legitimate reason to do so and are ok to > deal with the possible issues." > > Maybe other people would disagree whether or not it was a legitimate > reason, or if he was OK dealing with the possible issues. > > Perhaps he needed the extra optimization of skipping the getter/setters. > Perhaps he needed it for testing, and somehow one thing led to another. > Who knows? > > It is strange that on the one hand you should insist that programmers > sometimes need to mess with internals, and on the other dismiss those who > do as "stupid". Your position is inconsistent. Nope. My position is quite clear : just don't do something *stupid*. For a definition of "stupid" that is indeed highly dependant on the context (which you snipped). > >>> To prevent that sort of thing from happening, the management could >>> decree that henceforth all "private" variable names will start with an >>> underscore. Problem solved, eh? >> Certainly not. The only way to solve such a problem is to fire this >> cretin. > > Again, we shouldn't enforce encapsulation and data hiding s/encapsulation//g We were talking about language-enforced access restriction. Not about encapsulation. > because there > are legitimate reasons for breaking it, but anyone who does break it is a > cretin. Not "anyone". Just those who do it where they obviously should not. And be sure that anyone cretin enough to mess with implementation *in the context mentioned by Russ* (context which, once again, you snipped) would find a "clever" way to do the same (or worse) in any language. You don't want such a smartass in your team, *specially* for critical stuff. > You have a very strange attitude. You have a very strange way of handling context. > Besides, it's not very practical. When you fire "the cretin", it has > consequences. Everyone else in the project has to work harder, My own experience is that firing an obvious cretin from a team leads to *less* work for the team - because then you don't have to re-read and rewrite all his code. > [...] >> Please educate yourself and learn about why Ariane 5 crashed on it's >> first flight, due to an error in a module written in ADA (which is such >> a psychorigid language that C++ and Java are even looser than Javascript >> in comparison). Perhaps will it light a bulb for you. > > Others have already pointed out that the error in the Ariane 5 rocket was > *human* error due to somebody messing with the internals, namely > defeating the compiler's default type checking. This was *not* an error *in the context* this module was designed (and tested, QAd etc) for. > I'd just like to ask: > Bruno, were you aware of the cause of the crash, Yes I was. Else I wouldn't have mention it. > and if not, why did you > raise the issue in the first place? Because the problem had nothing to do with technology. Only with not being serious on specs / tests / QA. Hence my point : it's not because a module has been written using a technology (rightly) known for it's security and robustness that you can get by with non-technical issues. > Did you think it was a compiler bug > that caused the crash? Do you think I am a newbie ? >>>>> Not >>>>> every door needs a lock, but certainly some do. >>>> You only need locks when you don't trust your neighbours. >>> Yeah, if you live in Nome, Alaska. >> Brillant. You obviously failed to understand the differences between >> "software engineering" and real life. When it comes to computers, the >> only doors I care closing are those which would let someone crack my >> computer. > > If only there was some way to know which bugs could let people crack our > computer and which bugs couldn't. > > Anyway, that's your choice. Personally, I'd much prefer my software not > to cause data loss, not to crash, not to DoS me, not to hang, and not to > generate bogus data, This is a different problem. Please don't mix bananas and screwdrivers. > >> But FWIW, I never close my car. And, in case you don't know, it's >> perfectly possible to access "private" members in Java (and, if you do >> have access to the source code, in C++ too). > > Yes, but it is more difficult. There's a larger psychological barrier. > It's easier to audit for such access, even in a large project. It > encourages a more careful attitude: "do I *really* need to mess with the > internals, or is there a safer way?". It forces the programmer to *think* > before doing something potentially dangerous. This is a beautiful dream. Reality is that either the guy is wise enough to not do something he know he shouldn't without due thinking and consideration, or he is dumb enough to do something he shouldn't one way or another. > This is why I wish eval and exec were in a module instead of built-ins. I do agree they shouldn't be builtins, but mostly because there are too few real use case for them to be builtins. (well, wrt/ exec, it's a statement to the problem is a bit different). > Suppose Python worked like this: > > >>>> class Parrot: > ... _private = 'spam' > ... >>>> p = Parrot() >>>> p._private = 'ham' > Traceback (most recent call last): > File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot >>>> from protection import unlock >>>> unlock(p)._private = 'ham' >>>> p._private > 'ham' > > > I don't know if this scenario is even possible in Python, It actually isn't, at least not without way too much overhead messing with call stack (and even then...). "Methods" need to freely access implementation attributes. But Python's "methods" are just wrappers around plain functions, which by themselves don't know (and shouldn't need to know) if they where defined within a class statement or not. > but pretend > that it is. Ok, let's pretend !-) > Would it be so terrible? No, I could live with it. Just a question now : how would this deal with functions defined outside the class statement but used as methods ? Oh, and please read until the end... > If a particular project wanted to > enforce encapsulation, s/encapsulation/data hiding/ > all they need do is replace or remove the > protection module from their Python installations. (I assume the project > developers aren't *hostile*. If they are, then there's almost nothing you > can do to make the code safe. Encapsulation is about protecting from > accidents, not sabotage.) InMyArms(tm) !-) > If you wanted to mess with the internals in > your own project, all you need do is import a module. > > > We could imagine the same scenario in reverse. Python allows getters and > setters, but they're more work, And more overhead. > and so people just don't use them unless > they really need to. Which is fine. Well, MHO at least. > Suppose Python offered real data encapsulation, s/encapsulation/hiding/ > but > you had to work to get it: > >>>> class Parrot: > ... _private = 'spam' > ... >>>> p = Parrot() >>>> p._private = 'ham' # allowed by default >>>> from protection import lock >>>> lock(p)._private >>>> p._private = 'spam' > Traceback (most recent call last): > File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot > > > Would that be so bad? I don't think so. So technically, this means that you'd have an optionel check for _implementation attribute access outside methods ? Good news my friend, Pylint already do this (and quite a lot of other things too...). So wrt/ code reviews, QA etc, the "lack of access protection" is not such an issue, is it ? http://www.logilab.org/card/pylintfeatures """ W0212: Access to a protected member %s of a client class Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined. """ From xahlee at gmail.com Sun Jan 18 12:36:59 2009 From: xahlee at gmail.com (Xah Lee) Date: Sun, 18 Jan 2009 09:36:59 -0800 (PST) Subject: calling an external program and capturing the output References: Message-ID: <3bad23d1-a441-4d5e-b317-4608cfa6a62b@t26g2000prh.googlegroups.com> On Jan 18, 8:41 am, Eric wrote: > Coming from a perl background I'm new to the Python world. I need to > read a list of values, send each value to an external program and > capture and act on the output of that program. Reading and parsing the > initial values is not a problem but I can't seem to find anything on > the sending to and capturing from an external program. > > Any suggestions would be greatly appreciated. See: ? Making System Calls in Perl and Python http://xahlee.org/perl-python/system_calls.html Xah ? http://xahlee.org/ ? From scott.p.macdonald at gmail.com Sun Jan 18 13:01:47 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sun, 18 Jan 2009 11:01:47 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: Yes, I see your point. Not sure how that would happen. It is possible to have multiple versions of python on the same machine I assume? During the installation I have specified the directory to install python in, otherwise I have not changed anything. Could it be an environment variable or something like that? Thanks, Scott On Sun, Jan 18, 2009 at 12:44 AM, Gabriel Genellina wrote: > En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald > escribi?: > > I googled a bit this morning search for an answer to this problem but have >> come up empty so far. Can anyone help? >> >> Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit >> > ^^^^^ > >> (Intel)] >> on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import urllib2 >>>>> >>>> Traceback (most recent call last): >> File "", line 1, in >> File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in >> > ^^^^^^^^ > > It seems your have a confusing setup. Why is Python 2.6 using > C:\dev\opt\Python25? > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtw at freenet.co.uk Sun Jan 18 13:02:37 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 12:02:37 -0600 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> Message-ID: Aaron Brady wrote in news:582ef883-0176-4984-9521-6c1894636891 at a26g2000prf.googlegroups.com in comp.lang.python: > On Jan 18, 10:44?am, Rob Williscroft wrote: >> Aaron Brady wrote >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh > .googlegroups.com >> in comp.lang.python: >> >> > It is too bad that it is so much work to detect whether 'y' was >> > passed in the function call directly. ?However, sentinel is just as >> > good (or nearly); at worst, you need one sentinel per argument per >> > function, >> >> One per Module should be good enough. The only reason None doesen't >> suffice is that it has other legitimate uses. ?Though to be honest >> I would always use None as the sentinel if it wasn't a legitimate >> argument. >> >> > which is possible to create, which has a specific meaning. ?If you >> > are >> > making systematic function calls, e.g. with a dictionary or list, >> > you can just use the sentinel in the dictionary. >> >> IIUYC then, one sentinel is still only needed as the missing argument >> is indicated by *both* position and value or by name and value (in >> the case of a keyword-dictionary), so seperate distinct sentinel >> objects aren't required, for example: >> >> SENTINEL = object() >> >> def f( a, b, c = SENTINEL, d = SENTINEL ): >> ? print( "values: %r" % ( ( a, b, c, d ), ) ) >> ? if c is SENTINEL: >> ? ? print( "c is missing" ) >> ? if d is SENTINEL: >> ? ? print( "d is missing" ) >> >> f( *( 1, 2, SENTINEL, SENTINEL ) ) >> >> f( **dict( a = 1 , b = 2, d = 4 ) ) >> >> f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > I don't have a concrete example, so you may prove to be right, but I'm > not convinced. I'm afraid I can't think of a use case for passing default values around eiither, and I suspect if we were to come up with one, a better solution that didn't involve passing default values around could be found. > If you have one function with an argument that defaults to an empty > list, and calls another with an argument that defaults to an empty > dict, then what is the meaning of passing sentinel to the first one? > Whereas, if each had their own, then passing the first one's default > would mean the empty list, and passing the second one's default would > mean the dict. If you *mean* to pass an "empty list" or "empty dict"'s you should do it like: function_taking_list( [] ) function_taking_dict( {} ) Its when you don't (have reason to) care that you need default arguments. > (Or, even if that evaluates correctly, perhaps there is no such useful > program.) I agree, though I think some confusion arises here as there are two (at least) distinct meanings for default arguments in python: 1) provide a value for when the caller doesn't, eg: def f( a = 1 ): ... 2) provide a cache for the functions /private/ use, eg: def f( cache = {} ): ... If the two are mixed up, then I can imagine a situation where somebody might want to start passing default caches around. It could only end in tears. Rob. -- http://www.victim-prime.dsl.pipex.com/ From waltbrad at hotmail.com Sun Jan 18 13:06:06 2009 From: waltbrad at hotmail.com (waltbrad) Date: Sun, 18 Jan 2009 10:06:06 -0800 (PST) Subject: uninstall before upgrade? Message-ID: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before I do that? If so, what's the best way to uninstall it? Thanks. From scott.p.macdonald at gmail.com Sun Jan 18 13:08:07 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sun, 18 Jan 2009 11:08:07 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: Ah yes, with your help I seem to have solved my own problem. I had PYTHONPATH defined to point to the 2.5 directory. Thanks! Scott On Sun, Jan 18, 2009 at 11:01 AM, Scott MacDonald < scott.p.macdonald at gmail.com> wrote: > Yes, I see your point. Not sure how that would happen. It is possible to > have multiple versions of python on the same machine I assume? > > During the installation I have specified the directory to install python > in, otherwise I have not changed anything. Could it be an environment > variable or something like that? > > Thanks, > Scott > > > > > On Sun, Jan 18, 2009 at 12:44 AM, Gabriel Genellina < > gagsl-py2 at yahoo.com.ar> wrote: > >> En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald >> escribi?: >> >> I googled a bit this morning search for an answer to this problem but >>> have >>> come up empty so far. Can anyone help? >>> >>> Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit >>> >> ^^^^^ >> >>> (Intel)] >>> on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>>> import urllib2 >>>>>> >>>>> Traceback (most recent call last): >>> File "", line 1, in >>> File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in >>> >> ^^^^^^^^ >> >> It seems your have a confusing setup. Why is Python 2.6 using >> C:\dev\opt\Python25? >> >> -- >> Gabriel Genellina >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Jan 18 13:11:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 19:11:43 +0100 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: <6th9mvFapmtvU1@mid.uni-berlin.de> waltbrad schrieb: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. No, several versions of python can live happily together. Diez From bockman at virgilio.it Sun Jan 18 13:17:38 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 18 Jan 2009 19:17:38 +0100 Subject: pep 8 constants References: Message-ID: On Wed, 14 Jan 2009 08:13:30 +0000, Steven D'Aprano wrote: > > Absolutely. It's rather sad that I can do this: > > import math > math.pi = 3.0 > > I like the ability to shoot myself in the foot, thank you very much, but > I should at least get a warning when I'm about to do so: > > math.PI = 3.0 # use God-like powers to change a constant > > Constants would be a nice addition in python, sure enough. But I'm not sure that this can be done without a run-time check every time the constant is used, and python is already slow enough. Maybe a check that is disabled when running with optimizing flags ? But I'm sure this discussion has been already made and the FINAL WORD has been already spoken. Ciao ---- FB From ericcire at gmail.com Sun Jan 18 13:30:14 2009 From: ericcire at gmail.com (Eric) Date: Sun, 18 Jan 2009 10:30:14 -0800 (PST) Subject: calling an external program and capturing the output References: Message-ID: Thanks guys. That helped point me int he right direction. with your advice on the subprocess module I stumbled upon this posting: http://www.velocityreviews.com/forums/t359866-subprocess-module.html for anyone else that might be interested here is the solution. It simply calls a perl script called add.pl that reads 2 numbers from stdin and adds them together. Thanks again for the help. -Eric #!/usr/bin/env python import subprocess prog = "./add.pl" args = "3 4" app = subprocess.Popen (prog ,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) print "opened " + prog #print app.stdout.read() print "writing \'" + args + "\' to " + prog + " subprocess" app.stdin.write(args) app.stdin.write("\n") print "wrote \'" + args + "\' to " + prog + " subprocess" result = app.stdout.read() result = result.rstrip('\n') print "received: " + result and here is the output: ./call_add.py opened ./add.pl writing '3 4' to ./add.pl subprocess wrote '3 4' to ./add.pl subprocess received: 7 From andrew at acooke.org Sun Jan 18 13:42:23 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 10:42:23 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <1fab9135-6de3-4625-9c78-0da62fe4d2f6@k36g2000pri.googlegroups.com> > ? ? sentinel = object() > ? ? ... > > ? ? def foo(x, y=sentinel): > ? ? ? if y is sentinel: > ? ? ? ? ? y = self.a it just struck me you could also do: def foo(self, x, *y_args) y = y_args[0] if y_args self.a which more directly checks whether an argument was passed, but has the downside of making the method signature less clear in the declaration. andrew From ron at flownet.com Sun Jan 18 14:01:50 2009 From: ron at flownet.com (Ron Garret) Date: Sun, 18 Jan 2009 11:01:50 -0800 (PST) Subject: WSGI question: reading headers before message body has been read Message-ID: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> I'm writing a WSGI application and I would like to check the content- length header before reading the content to make sure that the content is not too big in order to prevent denial-of-service attacks. So I do something like this: def application(environ, start_response): status = "200 OK" headers = [('Content-Type', 'text/html'), ] start_response(status, headers) if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' But this doesn't seem to work. If I upload a huge file it still waits until the entire file has been uploaded before complaining that it's too big. Is it possible to read the HTTP headers in WSGI before the request body has been read? Thanks, rg From deets at nospam.web.de Sun Jan 18 14:29:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 20:29:38 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <6the94FajnrlU1@mid.uni-berlin.de> Ron Garret schrieb: > I'm writing a WSGI application and I would like to check the content- > length header before reading the content to make sure that the content > is not too big in order to prevent denial-of-service attacks. So I do > something like this: > > def application(environ, start_response): > status = "200 OK" > headers = [('Content-Type', 'text/html'), ] > start_response(status, headers) > if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > But this doesn't seem to work. If I upload a huge file it still waits > until the entire file has been uploaded before complaining that it's > too big. > > Is it possible to read the HTTP headers in WSGI before the request > body has been read? AFAIK that is nothing that WSGI defines - it's an implementation-detail of your server. Which one do you use? Diez From google at mrabarnett.plus.com Sun Jan 18 14:32:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 18 Jan 2009 19:32:20 +0000 Subject: pep 8 constants In-Reply-To: References: Message-ID: <497383C4.2080800@mrabarnett.plus.com> Francesco Bochicchio wrote: > On Wed, 14 Jan 2009 08:13:30 +0000, Steven D'Aprano wrote: > > >> Absolutely. It's rather sad that I can do this: >> >> import math >> math.pi = 3.0 >> >> I like the ability to shoot myself in the foot, thank you very much, but >> I should at least get a warning when I'm about to do so: >> >> math.PI = 3.0 # use God-like powers to change a constant >> >> > > Constants would be a nice addition in python, sure enough. > But I'm not sure that this can be done without a run-time check every time > the constant is used, and python is already slow enough. Maybe a check > that is disabled when running with optimizing flags ? > > But I'm sure this discussion has been already made and the FINAL WORD has > been already spoken. > >>> class Constants(object): def __setattr__(self, key, value): if key in self.__dict__: raise ValueError("Can't change constant") self.__dict__[key] = value >>> c = Constants() >>> c.PI = 3.0 >>> c.PI 3.0 >>> c.PI = 4.0 Traceback (most recent call last): File "", line 1, in c.PI = 4.0 File "", line 4, in __setattr__ raise ValueError("Can't change constant") ValueError: Can't change constant From vedrandekovic at yahoo.com Sun Jan 18 14:38:51 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 18 Jan 2009 11:38:51 -0800 (PST) Subject: Python and threads References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> Message-ID: <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> On 18 sij, 17:48, "Diez B. Roggisch" wrote: > vedrandeko... at yahoo.com schrieb: > > > > > Hello again, > > > Thanks for previous help on "Start two threads in same time" it was > > useful,but when I run this > > two threads, I think they don't start at the same time, here is my > > code snippet: > > > import threading > > > class ThreadedClass1(threading.Thread): > > ? ? def __init__(self): > > ? ? ? ? threading.Thread.__init__(self) > > > ? ? def run(self): > > ? ? ? ? a=True > > ? ? ? ? while a==True: > > ? ? ? ? ? ? bm=my_module.MyClass() > > ? ? ? ? ? ? a=bm.get_Python_Process_Usage_Function() ? #Returns True > > or False > > > class ThreadedClass2(threading.Thread): > > ? ? def __init__(self): > > ? ? ? ? threading.Thread.__init__(self) > > > ? ? def run(self): > > ? ? ? ? os.popen("my_python_script.py") > > > threaded_obj = ThreadedClass1() > > threaded_obj.start() > > threaded_obj2 = ThreadedClass2() > > threaded_obj2.start() > > If you want to synchronize two or more threads, you need to do so > manually using objects like Locks, Events, Conditions and Semaphores. > See the threading module. > > Even if you managed to get two threads started simultaneously (which the > ? OS doesn't even offer IINM), the would soon run out of sync. > > How about you tell us what you *want*, and we tell you if and how it's > possible to do that. > > Diez Hello, and thanks for all previous help.I want to measure memory usage of executed python script.I'am working on windows XP. Regards, John From petite.abeille at gmail.com Sun Jan 18 14:43:21 2009 From: petite.abeille at gmail.com (Petite Abeille) Date: Sun, 18 Jan 2009 20:43:21 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <456AD650-77AE-45B2-9C93-8C3DA33F151E@gmail.com> On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > def application(environ, start_response): > status = "200 OK" > headers = [('Content-Type', 'text/html'), ] > start_response(status, headers) > if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' How would that work for chunked transfer-encoding? Cheers, -- PA. http://alt.textdrive.com/nanoki/ From Russ.Paielli at gmail.com Sun Jan 18 14:51:07 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 18 Jan 2009 11:51:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> Message-ID: <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> On Jan 18, 9:22?am, Bruno Desthuilliers wrote: > Properties by themselves are not the problem, quite on the contrary - as > you say, they actually help wrt/ encapsulation. What breaks > encapsulation is *automatic generation* for properties for *each and > any* implementation attribute. Might as well just makes them all public > attribute then. Let me correct my statement about the automatic generation of properties in Scala: it is only for public attributes, not all attributes. Getting back to the bigger point, I will gladly agree with you that data hiding is not a magic bullet that will eliminate all bugs. The idea that I or anyone else said that, however, is a red herring. Data hiding is just one safeguard in a portfolio of safeguards that can *help* to prevent certain kinds of bugs as well as deliberate acts of sabotage or fraud. When you have a tough problem to solve, you need all the help you can get. You keep saying that if you hire competent, trustworthy developers, you don't need data hiding. Well, maybe, but when you have a team of dozens or hundreds of developers, your chances of avoiding any bad ones is zero for all practical purposes. And even if all your developers were excellent, data hiding would still be a convenient mechanism to simplify their jobs so they can focus on higher level problems -- and not have to rely on an ugly naming convention. Now, if developers become careless because they think data hiding will save them, then that would be a problem. That much I will concede. But I doubt that happens much. From tjreedy at udel.edu Sun Jan 18 15:11:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Jan 2009 15:11:46 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: Message-ID: andrew cooke wrote: > Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data > model#object.__iadd__ > > Just a suggestion I thought I'd throw out... There's a restriction in > the language implementation on exactly what can go the left of an > augmented arithmetic expression. > > For example: >>>> a = 3 >>>> a **= 2 > > is ok, but: >>>> class Foo(): > ... def __init__(): > ... self.a = 3 > ... def __ipow__(self, x): > ... self.a **= x > ... >>>> Foo() **= 2 Calls return objects and therefore cannot be the target of an assignment, augmented or otherwise. The target of an assignment is a name or collection slot, both of which are grammatical constructs, not objects. From ron.garret at gmail.com Sun Jan 18 15:25:45 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 12:25:45 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> Message-ID: <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> On Jan 18, 11:29?am, "Diez B. Roggisch" wrote: > Ron Garret schrieb: > > > > > I'm writing a WSGI application and I would like to check the content- > > length header before reading the content to make sure that the content > > is not too big in order to prevent denial-of-service attacks. ?So I do > > something like this: > > > def application(environ, start_response): > > ? ? status = "200 OK" > > ? ? headers = [('Content-Type', 'text/html'), ] > > ? ? start_response(status, headers) > > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > > But this doesn't seem to work. ?If I upload a huge file it still waits > > until the entire file has been uploaded before complaining that it's > > too big. > > > Is it possible to read the HTTP headers in WSGI before the request > > body has been read? > > AFAIK that is nothing that WSGI defines - it's an implementation-detail > of your server. Which one do you use? Apache at the moment, with lighttpd as a contender to replace it. rg From stefan_ml at behnel.de Sun Jan 18 15:27:46 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 21:27:46 +0100 Subject: Python and threads In-Reply-To: <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> Message-ID: <497390c3$0$31878$9b4e6d93@newsspool3.arcor-online.net> vedrandekovic at yahoo.com wrote: > and thanks for all previous help.I want to measure memory usage of > executed python script.I'am working on windows XP. Could you qualify "measure"? Do you mean: a) "debug" (permanently high accuracy, potentially high runtime overhead) b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime overhead) c) "find out" (low accuracy or just max usage, no permanent observation) ? Stefan From ron.garret at gmail.com Sun Jan 18 15:34:03 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 12:34:03 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <68c7797c-f4fd-4c67-a23d-0999b7d46b85@y1g2000pra.googlegroups.com> On Jan 18, 11:43?am, Petite Abeille wrote: > On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > > > def application(environ, start_response): > > ? ?status = "200 OK" > > ? ?headers = [('Content-Type', 'text/html'), ] > > ? ?start_response(status, headers) > > ? ?if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > How would that work for chunked transfer-encoding? It wouldn't. But many clients don't use chunked-transfer-encoding when uploading files whose size is known. In that case it would be nice to let users know that their upload is going to fail BEFORE they waste hours waiting for 10GB of data to go down the wire. rg From deets at nospam.web.de Sun Jan 18 15:40:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 21:40:41 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> Message-ID: <6thie9Fapdc8U1@mid.uni-berlin.de> Ron Garret schrieb: > On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: >> Ron Garret schrieb: >> >> >> >>> I'm writing a WSGI application and I would like to check the content- >>> length header before reading the content to make sure that the content >>> is not too big in order to prevent denial-of-service attacks. So I do >>> something like this: >>> def application(environ, start_response): >>> status = "200 OK" >>> headers = [('Content-Type', 'text/html'), ] >>> start_response(status, headers) >>> if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' >>> But this doesn't seem to work. If I upload a huge file it still waits >>> until the entire file has been uploaded before complaining that it's >>> too big. >>> Is it possible to read the HTTP headers in WSGI before the request >>> body has been read? >> AFAIK that is nothing that WSGI defines - it's an implementation-detail >> of your server. Which one do you use? > > Apache at the moment, with lighttpd as a contender to replace it. Together with mod_wsgi? Diez From lkcl at lkcl.net Sun Jan 18 15:46:20 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sun, 18 Jan 2009 20:46:20 +0000 Subject: libmsi.a import library from wine, and header files available (entirely free software), available for python-win32 builds under msys+wine Message-ID: as part of building python2.5.2 under msys under wine on linux using mingw, i thought i'd try building _msi.pyd just for kicks. of course, that required having an msi.lib import library, and associated header files. so, purely as an experiment, i've documented the process by which it is possible to take wine 1.1.13 (current development release) source code, modify the header files for use with mingw, create a typelibrary (using dlltool) and then, surprise-surprise, _msi.pyd successfully builds. i say successfully builds: but then, running from _outside_ of a wineconsole cmd, doing this: /usr/local/bin/wine ./python.exe -c 'import _msi' succeeds. but if you do this: /usr/local/bin/wineconsole cmd c:/python2.5/bin/python.exde -c 'import _msi' you get an "access violation - no access to memory" blah blah to be honest, i don't care about that: this message is to let people know that it _is_ possible, and, if anyone is interested in e.g. adding -lmsi -lcabinet support to MinGW, here's where you can get the necessary crud: http://lkcl.net/msi.tgz if the wine team have any objections, if they believe this is a bad idea, please do say so :) l. p.s. if anyone would like to add a regression test to python called "test_msi.py" - or if they know of one that exists, i'd love to hear from you and try it out. outside of a wine cmd.exe of course :) From ron.garret at gmail.com Sun Jan 18 16:02:35 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 13:02:35 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> <6thie9Fapdc8U1@mid.uni-berlin.de> Message-ID: <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> On Jan 18, 12:40?pm, "Diez B. Roggisch" wrote: > Ron Garret schrieb: > > > > > On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: > >> Ron Garret schrieb: > > >>> I'm writing a WSGI application and I would like to check the content- > >>> length header before reading the content to make sure that the content > >>> is not too big in order to prevent denial-of-service attacks. ?So I do > >>> something like this: > >>> def application(environ, start_response): > >>> ? ? status = "200 OK" > >>> ? ? headers = [('Content-Type', 'text/html'), ] > >>> ? ? start_response(status, headers) > >>> ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > >>> But this doesn't seem to work. ?If I upload a huge file it still waits > >>> until the entire file has been uploaded before complaining that it's > >>> too big. > >>> Is it possible to read the HTTP headers in WSGI before the request > >>> body has been read? > >> AFAIK that is nothing that WSGI defines - it's an implementation-detail > >> of your server. Which one do you use? > > > Apache at the moment, with lighttpd as a contender to replace it. > > Together with mod_wsgi? > > Diez Yes. (Is there any other way to run WSGI apps under Apache?) rg From digitig at gmail.com Sun Jan 18 16:19:58 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 18 Jan 2009 21:19:58 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xmydomvim.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/18 Paul Rubin <"http://phr.cx"@nospam.invalid>: > I.e. the cast was wrong because of the failure of an unstated > assumption that a certain sensor reading was in a certain range. > Spark may still have allowed the cast only if the assumption was > stated explicitly in the specification. Unless it's changed since I used it, technically, SPADE doesn't allow or disallow anything. It produces a predicate (a proof obligation) that you have to prove is always true (or is it always false? It's been 18 years since I worked on that stuff, and SPADE and MALPAS produced their proof obligations with opposite values). So it's still up to you to show that it won't overflow, it just gives you the predicate calculus expression that you need to do that. Since the value appears to come from a sensor, the only way one could prove that there would be no overflow would be to state it as a part of the specification of what is read in. If that specification doesn't match the specification of the actual sensor, that's nothing to do with the programming language or, for that matter, the program itself. It's a specification mismatch. I was actually at the European Space Agency's Toulouse site the week after the Ariane 5 incident. I've been at jollier funerals. I can't help thinking that thinking that the team would have benefited from reading David Parnas's work on the specification of the A-7E avionics. -- Tim Rowe From Graham.Dumpleton at gmail.com Sun Jan 18 16:21:39 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sun, 18 Jan 2009 13:21:39 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <5094296c-361b-49ce-90df-943f2f79a7e6@r15g2000prh.googlegroups.com> On Jan 19, 6:01?am, Ron Garret wrote: > I'm writing a WSGI application and I would like to check the content- > length header before reading the content to make sure that the content > is not too big in order to prevent denial-of-service attacks. ?So I do > something like this: > > def application(environ, start_response): > ? ? status = "200 OK" > ? ? headers = [('Content-Type', 'text/html'), ] > ? ? start_response(status, headers) > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' You should be returning 413 (Request Entity Too Large) error status for that specific case, not a 200 response. You should not be returning a string as response content as it is very inefficient, wrap it in an array. > But this doesn't seem to work. ?If I upload a huge file it still waits > until the entire file has been uploaded before complaining that it's > too big. > > Is it possible to read the HTTP headers in WSGI before the request > body has been read? Yes. The issue is that in order to avoid the client sending the data the client needs to actually make use of HTTP/1.1 headers to indicate it is expecting a 100-continue response before sending data. You don't need to handle that as Apache/mod_wsgi does it for you, but the only web browser I know of that supports 100-continue is Opera browser. Clients like curl do also support it as well though. In other words, if people use IE, Firefox or Safari, the request content will be sent regardless anyway. There is though still more to this though. First off is that if you are going to handle 413 errors in your own WSGI application and you are using mod_wsgi daemon mode, then request content is still sent by browser regardless, even if using Opera. This is because the act of transferring content across to mod_wsgi daemon process triggers return of 100-continue to client and so it sends data. There is a ticket for mod_wsgi to implement proper 100-continue support for daemon mode, but will be a while before that happens. Rather than have WSGI application handle 413 error cases, you are better off letting Apache/mod_wsgi handle it for you. To do that all you need to do is use the Apache 'LimitRequestBody' directive. This will check the content length for you and send 413 response without the WSGI application even being called. When using daemon mode, this is done in Apache child worker processes and for 100-continue case data will not be read at all and can avoid client sending it if using Opera. Only caveat on that is the currently available mod_wsgi has a bug in it such that 100-continue requests not always working for daemon mode. You need to apply fix in: http://code.google.com/p/modwsgi/issues/detail?id=121 For details on LimitRequestBody directive see: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody Graham From Graham.Dumpleton at gmail.com Sun Jan 18 16:25:38 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sun, 18 Jan 2009 13:25:38 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <59755318-2e50-4ddd-a3f5-a4ceaee512c3@x16g2000prn.googlegroups.com> On Jan 19, 6:43?am, Petite Abeille wrote: > On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > > > def application(environ, start_response): > > ? ?status = "200 OK" > > ? ?headers = [('Content-Type', 'text/html'), ] > > ? ?start_response(status, headers) > > ? ?if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > How would that work for chunked transfer-encoding? Chunked transfer encoding on request content is not supported by WSGI specification as WSGI requires CONTENT_LENGTH be set and disallows reading more than defined content length, where CONTENT_LENGTH is supposed to be taken as 0 if not provided. If using Apache/mod_wsgi 3.0 (currently in development, so need to use subversion copy), you can step outside what WSGI strictly allows and still handle chunked transfer encoding on request content, but you still don't have a CONTENT_LENGTH so as to check in advance if more data than expected is going to be sent. If wanting to know how to handle chunked transfer encoding in mod_wsgi, better off asking on mod_wsgi list. Graham From ron.garret at gmail.com Sun Jan 18 16:38:57 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 13:38:57 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <5094296c-361b-49ce-90df-943f2f79a7e6@r15g2000prh.googlegroups.com> Message-ID: On Jan 18, 1:21?pm, Graham Dumpleton wrote: > On Jan 19, 6:01?am, Ron Garret wrote: > > > I'm writing a WSGI application and I would like to check the content- > > length header before reading the content to make sure that the content > > is not too big in order to prevent denial-of-service attacks. ?So I do > > something like this: > > > def application(environ, start_response): > > ? ? status = "200 OK" > > ? ? headers = [('Content-Type', 'text/html'), ] > > ? ? start_response(status, headers) > > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > You should be returning 413 (Request Entity Too Large) error status > for that specific case, not a 200 response. > > You should not be returning a string as response content as it is very > inefficient, wrap it in an array. > > > But this doesn't seem to work. ?If I upload a huge file it still waits > > until the entire file has been uploaded before complaining that it's > > too big. > > > Is it possible to read the HTTP headers in WSGI before the request > > body has been read? > > Yes. > > The issue is that in order to avoid the client sending the data the > client needs to actually make use of HTTP/1.1 headers to indicate it > is expecting a 100-continue response before sending data. You don't > need to handle that as Apache/mod_wsgi does it for you, but the only > web browser I know of that supports 100-continue is Opera browser. > Clients like curl do also support it as well though. In other words, > if people use IE, Firefox or Safari, the request content will be sent > regardless anyway. > > There is though still more to this though. First off is that if you > are going to handle 413 errors in your own WSGI application and you > are using mod_wsgi daemon mode, then request content is still sent by > browser regardless, even if using Opera. This is because the act of > transferring content across to mod_wsgi daemon process triggers return > of 100-continue to client and so it sends data. There is a ticket for > mod_wsgi to implement proper 100-continue support for daemon mode, but > will be a while before that happens. > > Rather than have WSGI application handle 413 error cases, you are > better off letting Apache/mod_wsgi handle it for you. To do that all > you need to do is use the Apache 'LimitRequestBody' directive. This > will check the content length for you and send 413 response without > the WSGI application even being called. When using daemon mode, this > is done in Apache child worker processes and for 100-continue case > data will not be read at all and can avoid client sending it if using > Opera. > > Only caveat on that is the currently available mod_wsgi has a bug in > it such that 100-continue requests not always working for daemon mode. > You need to apply fix in: > > ?http://code.google.com/p/modwsgi/issues/detail?id=121 > > For details on LimitRequestBody directive see: > > ?http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody > > Graham Thanks for the detailed response! rg From seaworthyjeremy at gmail.com Sun Jan 18 17:18:13 2009 From: seaworthyjeremy at gmail.com (seaworthyjeremy at gmail.com) Date: Sun, 18 Jan 2009 14:18:13 -0800 (PST) Subject: Can Python manipulate PE structure or bytes? Message-ID: I'm interested in Python and wanted to know if Python can manipulate PE structure and bytes. Also what are its limits? From bearophileHUGS at lycos.com Sun Jan 18 17:18:18 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 14:18:18 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Message-ID: r: >Of course it would not run in C or Python but the point here is readability.< With languages like Genie you can go close: http://live.gnome.org/Genie Or better Delight (based on the D language), plus some my "Python compatibility" libs (plus Pyd, if you want) you can run that code: http://delight.sourceforge.net/ Bye, bearophile From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 17:28:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 22:28:04 GMT Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <0183a368$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 07:36:53 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> def foo(self, x, y=None): >> if y is None: >> y = self.a >> >> I don't find that clumsy in the least. I find it perfectly readable and >> a standard idiom. > > That has the same problem as the earlier version. No it doesn't. The earlier version had the problem that *any* false object is replaced by self.a. I'm just following the standard Python idiom of using None as a sentinel. Have a look through the standard library and see how many times it is used. Built-ins rarely accept None as a sentinel, slice() being a conspicuous exception. This is sometimes a nuisance when writing wrappers: def my_find(S, sub, start=None, end=None): """Like string.find() only with pre-processing.""" pre_process() # stub for something complicated if end is None and start is None: return S.find(sub) elif end if None: return S.find(sub, start) else: return S.find(sub, start, end) or if you prefer: def my_find(S, sub, start=None, end=None): """Like string.find()""" pre_process() args = [sub] if start is not None: args.append(start) if end is not None: args.append(end) return S.find(*args) Having said that, there are times where you need to pass None as a legitimate argument and not as a sentinel. In that case, your solution: > If the person passes > None, they get self.a. I prefer: > > sentinel = object() > ... > > def foo(x, y=sentinel): > if y is sentinel: > y = self.a is an excellent one. -- Steven From bearophileHUGS at lycos.com Sun Jan 18 17:44:52 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 14:44:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> Message-ID: <114ea588-e48c-4a5a-b880-2683fbcf4186@g3g2000pre.googlegroups.com> alex23: > Paul, have you looked into Cython at all? I can also suggest ShedSkin and the D language. I have often used D for data munging, producing quick & short programs, when Python isn't fast enough for a certain purpose. Bye, bearophile From http Sun Jan 18 17:47:18 2009 From: http (Paul Rubin) Date: 18 Jan 2009 14:47:18 -0800 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <0183a368$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xwscsxmdl.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Having said that, there are times where you need to pass None as a > legitimate argument and not as a sentinel. I don't think it's worth trying to figure out which those times are. The conclusion can be wrong, or can become wrong later because of some faraway change in the code. I prefer using the bulletproof method from the beginning, whether it is needed or not. From deets at nospam.web.de Sun Jan 18 17:54:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 23:54:15 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> <6thie9Fapdc8U1@mid.uni-berlin.de> <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> Message-ID: <6thq8nFat9peU1@mid.uni-berlin.de> Ron Garret schrieb: > On Jan 18, 12:40 pm, "Diez B. Roggisch" wrote: >> Ron Garret schrieb: >> >> >> >>> On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: >>>> Ron Garret schrieb: >>>>> I'm writing a WSGI application and I would like to check the content- >>>>> length header before reading the content to make sure that the content >>>>> is not too big in order to prevent denial-of-service attacks. So I do >>>>> something like this: >>>>> def application(environ, start_response): >>>>> status = "200 OK" >>>>> headers = [('Content-Type', 'text/html'), ] >>>>> start_response(status, headers) >>>>> if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' >>>>> But this doesn't seem to work. If I upload a huge file it still waits >>>>> until the entire file has been uploaded before complaining that it's >>>>> too big. >>>>> Is it possible to read the HTTP headers in WSGI before the request >>>>> body has been read? >>>> AFAIK that is nothing that WSGI defines - it's an implementation-detail >>>> of your server. Which one do you use? >>> Apache at the moment, with lighttpd as a contender to replace it. >> Together with mod_wsgi? >> >> Diez > > Yes. (Is there any other way to run WSGI apps under Apache?) Well, not so easy, but of course you can work with mod_python or even CGI/fastcgi to eventually invoke a WSGI-application. However, the original question - that's a tough one. According to this, it seems one can use an apache-directive to prevent mod_wsgi to even pass a request to the application if it exceeds a certain size. http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines Search for "Limiting Request Content" However, I'm not sure how early that happens. I can only suggest you try & contact Graham Dumpleton directly, he is very responsive. Diez From bearophileHUGS at lycos.com Sun Jan 18 18:04:53 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 15:04:53 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> Message-ID: <194e5563-6898-4a40-9079-4668aaf0cc95@i18g2000prf.googlegroups.com> Michele Simionato: > I don't like that. Scala was designed with the idea of putting > together the two worlds, by I think the result was to get the > complications of both worlds. But some other people may like it, and it's a design experiment worth doing. Every programming paradigm has advantages, so it's normal for people to try to design language that have the best of different worlds. Even if Scala is a failure (and I don't think it is), it's good to keep trying to design a mixed language (Like Python, that mixes procedural, some OOP and a bit of functional stiles. It has not pattern matching stile (Mathematica, OcaML), logic-inferential style (Prolog), constraint style (Oz, Mozart), data flow style, generic programming (C++, D), etc). Today lot of people understand that functional languages have advantages, so they are trying to created hybrids (Scala, F#, D V.2, etc), and they may succeed only trying. The purpose is of course to create a language that isn't too much complex, but has those advantages anyway. I presume Scala is quite less complex than C++ anyway. >Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make additional features appear necessary. -- William Clinger< I think it's false, but it requires me lot of space to explain why. In few words: Perl is more useful than Scheme if you have to solve a lot of practical computational problems, despite Scheme looks much more nicer. Bye, bearophile From catphive at catphive.net Sun Jan 18 18:06:10 2009 From: catphive at catphive.net (Brendan Miller) Date: Sun, 18 Jan 2009 15:06:10 -0800 Subject: braces fixed '#{' and '#}' In-Reply-To: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: Yes, I also recently noticed the bug in python's parser that doesn't let it handle squigly braces and the bug in the lexer that makes white space significant. I'm surprised the dev's haven't noticed this yet. On Sat, Jan 17, 2009 at 2:09 AM, v4vijayakumar wrote: > I saw some code where someone is really managed to import braces from > __future__. ;) > > def test(): > #{ > print "hello" > #} This seems like the best workaround. Hopefully python curly brace support will be fixed soon. I think technically a language can't be turing complete without curly braces right? That's definitely how I read this: http://www.thocp.net/biographies/papers/turing_oncomputablenumbers_1936.pdf "If the negation of what G?del has shown had been proved, i.e. if, for each U, either U or ?U is provable, then we should have an immediate solution of the Entscheidungsproblem. As a corollary we also have that real programmers use squigly braces and everyone else is nubs" From w_a_x_man at yahoo.com Sun Jan 18 18:29:57 2009 From: w_a_x_man at yahoo.com (William James) Date: 18 Jan 2009 23:29:57 GMT Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Andr? Thieme wrote: > Xah Lee schrieb: > > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.pytho > > n,comp.lang.ruby > > > > Here's a interesting toy problem posted by Drew Krause to > > comp.lang.lisp: > > > > ------------------------ > > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > > > OK, I want to create a nested list in Lisp (always of only integers) > > from a text file, such that each line in the text file would be > > represented as a sublist in the 'imported' list. > > > > example of a file's content > > > > 3 10 2 > > 4 1 > > 11 18 > > > > example of programing behavior > >(make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > > > w_a_x_... at yahoo.com gave a ruby solution: > > > > IO.readlines("blob.txt").map{|line| line.split } > > > > augumented by Jilliam James for result to be numbers: > > > > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > > > > Very beautiful. > > > > ------------------- > > > > That's really the beauty of Ruby. > > > > This problem and ruby code illustrates 2 fundamental problems of > > lisp, namely, the cons problem, and the nested syntax pain. Both of > > which are practically unfixable. > > *Of course* Xah is wrong, as always. > Who would expect anything else? > In the Lisp style Clojure for example one does exactly the same as > Jillian James (JJ) did in Ruby: > (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq > (reader "blob.txt"))) That fails when numbers are separated by more than one space. And what about leading or trailing space? > > This is slightly longer, simply because the functions have longer > names. Integer/parseInt vs to_i > > Also the function split takes a regexp, so I have to add the "\\s" > here. I don?t know though if Jillians version also handles any > kind of whitespac per line. irb(main):003:0> puts " foo \t bar " foo bar => nil irb(main):004:0> " foo \t bar ".split => ["foo", "bar"] irb(main):005:0> "foo...bar?-!hoo".split /\W+/ => ["foo", "bar", "hoo"] > And the last thing is, that the function reader returns a > BufferedReader. So in general this is more valuable in real programs > as opposed to one- line scripts. If we combine line-seq and reader > into readline and apply the two other changes we would say: > (map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt")) That is not a complete program. > vs > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} That is the complete program. > > So, obviously Xah is far away from any reality. > It took him hours of his life to write up all his ideas about Lisp. > Sad to see that all that time was wasted. All of it was wrong. > Poor Xah :( > > > And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store > data for his programs in the format > 3 10 2 > 4 1 > 11 18 > > but instead as > (3 10 2) > (4 1) > (11 18) Perhaps the data was stored by someone else. Understand? > > And then read it back into the program with: > (map read-string (line-seq (reader "blob.txt"))) > You make a very strong case that Lisp is very feeble at processing data. I'm almost convinced. Ruby isn't feeble, so data like this is fine: shall we begin? or lotus135? 1984 times! The 3 stooges: COBOL,LISP,FORTRAN. 3.14, si11y L00KING Extracting the unsigned integers: IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}} ==>[[], [135, 1984], [3], [3, 14, 11, 0]] From catphive at catphive.net Sun Jan 18 18:30:30 2009 From: catphive at catphive.net (Brendan Miller) Date: Sun, 18 Jan 2009 15:30:30 -0800 Subject: what's the point of rpython? In-Reply-To: <7xd4ele060.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Jan 17, 2009 at 7:57 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > alex23 writes: >> Here's an article by Guido talking about the last attempt to remove >> the GIL and the performance issues that arose: >> >> "I'd welcome a set of patches into Py3k *only if* the performance for >> a single-threaded program (and for a multi-threaded but I/O-bound >> program) *does not decrease*." > > The performance decrease is an artifact of CPython's rather primitive > storage management (reference counts in every object). This is > pervasive and can't really be removed. But a new implementation > (e.g. PyPy) can and should have a real garbage collector that doesn't > suffer from such effects. > -- > http://mail.python.org/mailman/listinfo/python-list > That's interesting, I hadn't heard the reference counting mechanism was related to the GIL. Is it just that you need to lock the reference count before mutating it if there's no GIL? Really, that shouldn't be the case. Reference counting can be done with a lock free algorithm. Garbage collection is definitely in vogue right now. However, people tend to treat it more like a religion than an algorithm. Garbage collection vs reference counting actually has some trade offs both ways. GC gets you some amortized performance gains, and some space gains because you don't need to hang on to a bunch of counts. However, GC also has the problem of having a very loose memory profile and poor interactive performance during compaction if the heap is large. In some cases this discussion becomes complicated with python because python has both reference counting and GC. From simon at brunningonline.net Sun Jan 18 18:35:04 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sun, 18 Jan 2009 23:35:04 +0000 Subject: *Advanced* Python book? In-Reply-To: References: Message-ID: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> 2009/1/17 Michele Simionato : > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 +1 for this. I'm 3/4 of the way through it, it's pretty good. Covers many on the important areas that the more introductory books rightly leave out, -- Cheers, Simon B. From gagsl-py2 at yahoo.com.ar Sun Jan 18 18:36:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 21:36:20 -0200 Subject: Can Python manipulate PE structure or bytes? References: Message-ID: En Sun, 18 Jan 2009 20:18:13 -0200, escribi?: > I'm interested in Python and wanted to know if Python can manipulate > PE structure and bytes. Also what are its limits? If you're talking about the "Portable Executable" file format, yes. Take a look at the struct module, or ctypes.Struct, but try Google first... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 18:36:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 21:36:20 -0200 Subject: Can Python manipulate PE structure or bytes? References: Message-ID: En Sun, 18 Jan 2009 20:18:13 -0200, escribi?: > I'm interested in Python and wanted to know if Python can manipulate > PE structure and bytes. Also what are its limits? If you're talking about the "Portable Executable" file format, yes. Take a look at the struct module, or ctypes.Struct, but try Google first... -- Gabriel Genellina From http Sun Jan 18 18:50:07 2009 From: http (Paul Rubin) Date: 18 Jan 2009 15:50:07 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xskngxjgw.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > That's interesting, I hadn't heard the reference counting mechanism > was related to the GIL. Is it just that you need to lock the reference > count before mutating it if there's no GIL? Yes. Someone tried inserting such a lock but it slowed down the single-cpu case unacceptably. > Really, that shouldn't be > the case. Reference counting can be done with a lock free algorithm. That's interesting, got a reference? (no pun intended) From marek at xivilization.net Sun Jan 18 19:06:31 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 19 Jan 2009 01:06:31 +0100 Subject: calling an external program and capturing the output References: <3bad23d1-a441-4d5e-b317-4608cfa6a62b@t26g2000prh.googlegroups.com> Message-ID: <20090119010631.67db2c52@halmanfloyd.lan.local> On Sun, 18 Jan 2009 09:36:59 -0800 (PST) Xah Lee wrote: > See: > > ? Making System Calls in Perl and Python > http://xahlee.org/perl-python/system_calls.html You can safely drop the Raw-Strings as they are only needed on Windows when constuction paths and programs with hardcoded paths are rare. regards, Marek From floris.bruynooghe at gmail.com Sun Jan 18 19:18:59 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Sun, 18 Jan 2009 16:18:59 -0800 (PST) Subject: Overriding base class methods in the C API Message-ID: Hello I've been trying to figure out how to override methods of a class in the C API. For Python code you can just redefine the method in your subclass, but setting tp_methods on the type object does not seem to have any influcence. Anyone know of a trick I am missing? Cheers Floris From wuwei23 at gmail.com Sun Jan 18 19:24:11 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Jan 2009 16:24:11 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> Message-ID: On Jan 19, 2:24?am, Duncan Booth wrote: [a nice concise explanation on __import__ & fromlist] Cheers, Duncan, that explained it perfectly. From musicguy at alphaios.net Sun Jan 18 19:36:30 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sun, 18 Jan 2009 18:36:30 -0600 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: <1232325390.6481.10.camel@speedyg> On Sun, 2009-01-18 at 10:06 -0800, waltbrad wrote: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list I've heard of people having problems trying to replace 2.5 with 2.6, so you probably don't want to uninstall 2.5. However, 2.5 and 2.6 can both be installed simultaneously. From sajmikins at gmail.com Sun Jan 18 19:37:32 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 18 Jan 2009 16:37:32 -0800 (PST) Subject: changing URLs in webpages, python solutions? References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> <49735b76$0$31867$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <114f1631-d389-4f61-a54a-01bf07840dc9@l33g2000pri.googlegroups.com> On Jan 18, 8:40?am, Stefan Behnel wrote: > Simon Forman wrote: > > I want to take a webpage, find all URLs (links, img src, etc.) and > > rewrite them in-place, and I'd like to do it in python (pure python > > preferred.) > > lxml.html has functions specifically for this problem. > > http://codespeak.net/lxml/lxmlhtml.html#working-with-links > > Code would be something like > > ? ? ? ? html_doc = lxml.html.parse(b"http://.../xyz.html") > ? ? ? ? html_doc.rewrite_links( ... ) > ? ? ? ? print( lxml.html.tostring(html_doc) ) > > It also handles links in CSS or JavaScript, as well as broken HTML documents. > > Stefan Thank you so much! This is exactly what I needed. (for what it's worth, parse() seems to return a "plain" ElementTree object but document_fromstring() gave me a special html object with the rewrite_links() method. I think, but I didn't try it, that html_doc = lxml.html.parse(b"http://.../xyz.html") lxml.html.rewrite_links(html_doc, ... ) would work too.) Thanks again! Regards, ~Simon From skip at pobox.com Sun Jan 18 19:40:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 18 Jan 2009 18:40:06 -0600 Subject: what's the point of rpython? In-Reply-To: <7xskngxjgw.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> Message-ID: <18803.52198.72465.500100@montanaro.dyndns.org> Paul> That's interesting, got a reference? (no pun intended) http://letmegooglethatforyou.com/?q=lock+free+reference+counting -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From jeff at jmcneil.net Sun Jan 18 19:46:32 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sun, 18 Jan 2009 16:46:32 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> <43573712-026a-4f84-817a-7bfdceda8719@v5g2000prm.googlegroups.com> Message-ID: On Jan 18, 5:40?am, Carl Banks wrote: > On Jan 17, 8:12?am, Jeff McNeil wrote: > > > > > On Jan 17, 11:09?am, Jeff McNeil wrote: > > > > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > > So, the documentation states that ob_type is a pointer to the type's > > > > > type, or metatype. Rather, this is a pointer to the new type's > > > > > metaclass? > > > > > That's actually the same. *Every* ob_type field points to the object's > > > > type, e.g. for strings, integers, tuples, etc. That includes type > > > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > > > also called metaclass (as "class" and "type" are really synonyms). > > > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > > > base type from which type properties are inherited." ?The value of > > > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > > > the surface, it sound as though they're one in the same? > > > > > (I don't understand the English "one in the same" - interpreting it > > > > as "as though they should be the same") > > > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > > > inheritance); tp_base (if set) provides the first base type. > > > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > > > tp_base is only at play when the object in question inherits from > > > > > type? > > > > > No - it is the normal case for single inheritance. You can leave it > > > > NULL, which means you inherit from object. > > > > > Regards, > > > > Martin > > > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > > > makes sense as Python supports multiple inheritance. ?It wasn't > > > immediately clear that tp_base is there for single inheritance > > > reasons. It's all quite clear now. > > > > Is that an optimization of sorts? > > > Well, maybe not specifically for single inheritance reasons, I just > > didn't see an immediate reason to keep a separate pointer to the first > > base type. > > The reason you need a separate tp_base is because it doesn't > necessarily point to the first base type; rather, it points to the > first base type that has added any fields or slots to its internal > layout (in other words, the first type with a tp_basicsize > 8, on 32- > bit versions). ?I believe this is mainly for the benefit of Python > subclasses that define their own slots. ?The type constructor will > begin adding slots at an offset of tp_base->tp_basicsize. > > To see an example, int objects have a tp_basicsize of 12 (there are 4 > extra bytes for the interger). ?So if you multiply-inherit from int > and a Python class, int will always be tp_base. > > class A(object): pass > > class B(int,A): pass > print B.__base__ # will print > > class C(A,int): pass > print C.__base__ # will print > > A related issue is that you can't multiply inherit from two types that > have tp_basicsize > 8 unless one of them inherits from the other. > There can be only one tp_base. ?For instance: > > class D(int,tuple): pass # will raise TypeError > > class E(object): > ? ? __slots__ = ['a','b'] > > class F(object): > ? ? __slots__ = ['c','d'] > > class G(E,G): pass # will raise TypeError > > class H(E,int): pass ?# will raise TypeError > > .... > > Here's a bit more background (and by "a bit" I mean "a lot"): > > In 32-bit Python, objects of types defined in Python are usually only > 16 bytes long. ?The layout looks like this. > > instance dict > weak reference list > reference count > ob_type > > The reference count, which is always the thing that the actual > PyObject* points at, isn't actually the first item in the object's > layout. ?The dict and weakref list are stored at a lower address. > (There's a reason for it.) > > If a Python class defines any __slots__, the type constructor will add > the slots to the object's layout. > > instance dict (if there is one) > weak reference list (if there is one) > reference count > ob_type > slot > slot > slot > > Note that, because you defined __slots__, the object might not have an > instance dict or weak reference list associated with it. ?It might, > though, if one of the base classes had defined an instance dict or > weakref list. ?Or, it might not, but then a subclass might have its > onw instance dict or weakref list. ?That's why these guys are placed > at a lower address: so that they don't interfere with the layout of > subclasses. ?A subclass can add either more slots or a dict. > > Object of types defined in C can have arbitrary layout. ?For instance, > it could have a layout that looks like this: > > reference count > ob_type > PyObject* a > PyObject* b > long c > float d > instance dict > > A problem with Python slots and C fields is that, if you want to > inherit from a type with a non-trivial object layout, aside from the > dict and weakrefs, all of the subtypes have to maintain the same > layout (see Liskov substitutability for rationale). > > Subtypes can add their own fields or slots if they want, though. ?So, > if a Python subtype wants to define its own slots on top of a type > with a non-trivial object layout, it has to know which base has the > largest layout so that it doesn't use the same memory for its own > slots. ?Hence tp_base. > > Carl Banks Thank you, that was very well put. I spent some more time tracking everything down today as well. There are some useful comments in object.h, and coupled with what you've said, it all make sense now. CPython really does have a very clean code base. I've written a lot of Python and a few C extensions, but I've never dived deep enough to understand how everything really clicks. I'm one of those folks that's never happy with what the API documentation says; I've got to understand all of the nooks and crannies before I'm happy! Jeff From dsblizzard at gmail.com Sun Jan 18 20:13:39 2009 From: dsblizzard at gmail.com (dsblizzard at gmail.com) Date: Sun, 18 Jan 2009 17:13:39 -0800 (PST) Subject: How to use *.py modules instead of *.pyc? Message-ID: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> How to use *.py modules instead of *.pyc or automatically recompile all modules each time I change *.py files? Thank you in advance. From clp2 at rebertia.com Sun Jan 18 20:20:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 17:20:29 -0800 Subject: How to use *.py modules instead of *.pyc? In-Reply-To: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901181720m4dda35e6j852f6ca5a918f521@mail.gmail.com> On Sun, Jan 18, 2009 at 5:13 PM, wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? IIRC, you shouldn't need to worry about this. Python checks the modification times on the .py and .pyc files and if the .pyc is older, it regenerates the .pyc from the .py; thus ensuring that the latest version of the source file is always used. What led you to conclude otherwise? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sun Jan 18 20:23:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 18 Jan 2009 17:23:33 -0800 (PST) Subject: How to use *.py modules instead of *.pyc? References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <040436dd-81dd-4cc4-8dab-8d1bec02e51a@w1g2000prk.googlegroups.com> On Jan 19, 12:13?pm, dsblizz... at gmail.com wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? You don't need to do anything special. If, when you import foo, foo.pyc is outdated by changes to the foo.py that is in the same directory, then foo.py will be compiled to a new foo.pyc -- otherwise compilation is unnecessary and the existing foo.pyc will be used. If you think you have a problem, it could be caused by foo.pyc being in a directory that is in sys.path but you are editing a foo.py that is not in sys.path. HTH, John From http Sun Jan 18 20:39:40 2009 From: http (Paul Rubin) Date: 18 Jan 2009 17:39:40 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> Message-ID: <7x8wp86plv.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > http://letmegooglethatforyou.com/?q=lock+free+reference+counting I found a paper by Detlefs et al describing a method which is a) patented b) can potentially lock out some threads from ever running, and c) relies on a hardware instruction (double compare and swap) that's not available on most processors. There are well known concurrent and parallel GC techniques that don't have that problem, see for example Cheng's dissertation: http://reports-archive.adm.cs.cmu.edu/anon/2001/CMU-CS-01-174.pdf GHC 6.10 uses a parallel stop-the-world gc that is simpler, I think. From clp2 at rebertia.com Sun Jan 18 20:42:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 17:42:34 -0800 Subject: How to use *.py modules instead of *.pyc? In-Reply-To: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901181742l6a81eba4u7e176a81dd434622@mail.gmail.com> On Sun, Jan 18, 2009 at 5:13 PM, wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? > Thank you in advance. Also, just for the sake of completeness (since John and I have shown that your real problem lies elsewhere), I happened to come across the `compileall` module via a Planet Python blog, which mass-compiles .py-s into .pyc-s: http://blog.doughellmann.com/2009/01/pymotw-compileall.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From address.good.until.2009.may.11 at justmail.de Sun Jan 18 21:24:22 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Mon, 19 Jan 2009 03:24:22 +0100 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: William James schrieb: > Andr? Thieme wrote: > > You make a very strong case that Lisp is very feeble at > processing data. I'm almost convinced. I somehow don?t believe you :-) > Ruby isn't feeble, so data like this is fine: > > > shall we begin? > or lotus135? 1984 times! > The 3 stooges: COBOL,LISP,FORTRAN. > 3.14, si11y L00KING > > > Extracting the unsigned integers: > > IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}} > ==>[[], [135, 1984], [3], [3, 14, 11, 0]] Just take the program I posted before and replace (.split % "\\s") with (re-seq #"\d+" %) Now that I was so kind to give you what you asked for, you will probably do the same for me and show me your Ruby code, in which you define a variable that contains the Fibonacci sequence. (def fibs (lazy-cat [0 1] (map + fibs (drop 1 fibs)))) (nth fibs 70) ==> 190392490709135 One requirement is that when you look at the n'th fib the results up to n must be memoized, so that nothing needs to be calculated again when you ask for a fib between 0 and n. And when you ask for the n+1'th it will start the calculation right from point n. Example: user> (time (nth fibs 900)) "Elapsed time: 16.898726 msecs" user> (time (nth fibs 901)) "Elapsed time: 0.268603 msecs" Andr? -- From castironpi at gmail.com Sun Jan 18 21:45:11 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 18:45:11 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <1fab9135-6de3-4625-9c78-0da62fe4d2f6@k36g2000pri.googlegroups.com> Message-ID: <1da71032-b55b-4b0a-874d-7e9deace0370@k1g2000prb.googlegroups.com> On Jan 18, 12:42?pm, andrew cooke wrote: > > ? ? sentinel = object() > > ? ? ... > > > ? ? def foo(x, y=sentinel): > > ? ? ? if y is sentinel: > > ? ? ? ? ? y = self.a > > it just struck me you could also do: > > ? ? ?def foo(self, x, *y_args) > ? ? ? ?y = y_args[0] if y_args self.a > > which more directly checks whether an argument was passed, but has the > downside of making the method signature less clear in the declaration. > > andrew Also, if you need to change your calling signature down the line, this alternative really ties your hands with regard to it. You also lose the ability to pass 'y' by keyword. George Sakkis, who I only know from the NG, has a recipe that tests a call against a function signature to determine what arguments are being passed. The 'inspect' module also has the 'getargvalues' function, which does something similar. From castironpi at gmail.com Sun Jan 18 21:56:12 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 18:56:12 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> Message-ID: On Jan 18, 12:02?pm, Rob Williscroft wrote: > Aaron Brady wrote innews:582ef883-0176-4984-9521-6c1894636891 at a26g2000prf.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 10:44?am, Rob Williscroft wrote: > >> Aaron Brady wrote > >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh > > .googlegroups.com > >> in comp.lang.python: > > >> > It is too bad that it is so much work to detect whether 'y' was > >> > passed in the function call directly. ?However, sentinel is just as > >> > good (or nearly); at worst, you need one sentinel per argument per > >> > function, > > >> One per Module should be good enough. The only reason None doesen't > >> suffice is that it has other legitimate uses. ?Though to be honest > >> I would always use None as the sentinel if it wasn't a legitimate > >> argument. > > >> > which is possible to create, which has a specific meaning. ?If you > >> > are > >> > making systematic function calls, e.g. with a dictionary or list, > >> > you can just use the sentinel in the dictionary. > > >> IIUYC then, one sentinel is still only needed as the missing argument > >> is indicated by *both* position and value or by name and value (in > >> the case of a keyword-dictionary), so seperate distinct sentinel > >> objects aren't required, for example: > > >> SENTINEL = object() > > >> def f( a, b, c = SENTINEL, d = SENTINEL ): > >> ? print( "values: %r" % ( ( a, b, c, d ), ) ) > >> ? if c is SENTINEL: > >> ? ? print( "c is missing" ) > >> ? if d is SENTINEL: > >> ? ? print( "d is missing" ) > > >> f( *( 1, 2, SENTINEL, SENTINEL ) ) > > >> f( **dict( a = 1 , b = 2, d = 4 ) ) > > >> f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > > I don't have a concrete example, so you may prove to be right, but I'm > > not convinced. > > I'm afraid I can't think of a use case for passing default values around > eiither, and I suspect if we were to come up with one, a better solution > that didn't involve passing default values around could be found. > > > If you have one function with an argument that defaults to an empty > > list, and calls another with an argument that defaults to an empty > > dict, then what is the meaning of passing sentinel to the first one? > > Whereas, if each had their own, then passing the first one's default > > would mean the empty list, and passing the second one's default would > > mean the dict. > > If you *mean* to pass an "empty list" or "empty dict"'s you should do > it like: > > ? function_taking_list( [] ) > ? function_taking_dict( {} ) > > Its when you don't (have reason to) care that you need default arguments. 'None' isn't a valid value for many standard library functions. So, if you try to pass it meaning, "Whatever the default value you usually use is," you'll get an error. Sometimes, the functions don't even use a public sentinel, so if you want the default value, you either have to know what it is, or you can't pass anything to that parameter. This is usually possible, it just prevents making a uniform call to a function. If you need to do some calculations to determine what parameters you're going to pass, you're stuck testing their presence with 'if-else' combinations, then calling individually. From narkewoody at gmail.com Sun Jan 18 22:10:43 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 19 Jan 2009 11:10:43 +0800 Subject: Event Handling and Signal-Slot Mechanism Message-ID: Hi, Python has Signal-Slot mechanism, why he still need another mechanism Event Handling? And, in some cases, it seems only Event Handling mechanism is available, for example closeEvent(). For what case and for what reason, the python think Signal Slot is not enough and will not work? Thanks. From prologic at shortcircuit.net.au Sun Jan 18 22:29:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 13:29:16 +1000 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 1:10 PM, Steven Woody wrote: > Python has Signal-Slot mechanism, why he still need another mechanism > Event Handling? And, in some cases, it seems only Event Handling > mechanism is available, for example closeEvent(). For what case and > for what reason, the python think Signal Slot is not enough and will > not work? In what context ? What application ? cheers James From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:31:04 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:31:04 GMT Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <0183a368$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 22:28:04 +0000, Steven D'Aprano wrote: > Built-ins rarely accept None as a sentinel, slice() being a conspicuous > exception. This is sometimes a nuisance when writing wrappers: > > def my_find(S, sub, start=None, end=None): > """Like string.find() only with pre-processing.""" pre_process() # > stub for something complicated if end is None and start is None: > return S.find(sub) > elif end if None: > return S.find(sub, start) > else: > return S.find(sub, start, end) Typical. As of Python 2.6, string.find accepts None as sentinels. All my beautiful, beautiful code made obsolete!!! *wink* -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:36:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:36:01 GMT Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: On Sun, 18 Jan 2009 15:11:46 -0500, Terry Reedy wrote: > andrew cooke wrote: >> Context - >> http://docs.python.org/3.0/reference/datamodel.html?highlight=data >> model#object.__iadd__ >> >> Just a suggestion I thought I'd throw out... There's a restriction in >> the language implementation on exactly what can go the left of an >> augmented arithmetic expression. >> >> For example: >>>>> a = 3 >>>>> a **= 2 >> >> is ok, but: >>>>> class Foo(): >> ... def __init__(): >> ... self.a = 3 >> ... def __ipow__(self, x): >> ... self.a **= x >> ... >>>>> Foo() **= 2 > > Calls return objects and therefore cannot be the target of an > assignment, augmented or otherwise. The target of an assignment is a > name or collection slot, both of which are grammatical constructs, not > objects. There's a practical reason too. You create a new Foo instance, mutate it with the augmented assignment operator, and then a tenth of a millisecond later the garbage collector throws it away because it has a reference count of zero. -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:43:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:43:25 GMT Subject: Python 3: exec arg 1 References: <018342f9$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 11:06:10 -0600, Rob Williscroft wrote: > You must have missed the subject line: "Re: Python 3: exec arg 1" Doh! -- Steven From gopalm at infotechsw.com Mon Jan 19 00:50:07 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Mon, 19 Jan 2009 11:20:07 +0530 Subject: problem in implementing multiprocessing In-Reply-To: References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> Message-ID: <0C740C10A79444BF8F5B623C58E12D72@pwit.com> i know this is not an io - bound problem, i am creating heavy objects in the process and add these objects in to queue and get that object in my main program using queue. you can test the this sample code import time from multiprocessing import Process, Queue class Data(object): def __init__(self): self.y = range(1, 1000000) def getdata(queue): data = Data() queue.put(data) if __name__=='__main__': t1 = time.time() d1 = Data() d2 = Data() t2 = time.time() print "without multiProcessing total time:", t2-t1 #multiProcessing queue = Queue() Process(target= getdata, args=(queue, )).start() Process(target= getdata, args=(queue, )).start() s1 = queue.get() s2 = queue.get() t2 = time.time() print "multiProcessing total time::", t2-t1 -----Original Message----- From: James Mills [mailto:prologic at shortcircuit.net.au] Sent: Saturday, January 17, 2009 10:37 AM To: gopal mishra Cc: python-list at python.org Subject: Re: problem in implementing multiprocessing On Fri, Jan 16, 2009 at 7:16 PM, gopal mishra wrote: > I create two heavy objects sequentially without using multipleProcessing > then creation of the objects takes 2.5 sec.if i create these two objects in > separate process then total time is 6.4 sec. > > i am thinking it is happening due to the pickling and unpickling of the > objects.if i am right then what could be the sollution. > > my system configuration: > dual-core processor > winXP > python2.6.1 System specs in this case are irrelevant. What you are experiencing is most likely an I/O bound problem - using multiprocessing may likely not help you solve the problem any faster because of your I/O constraint. cheers James From prologic at shortcircuit.net.au Mon Jan 19 01:00:45 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 16:00:45 +1000 Subject: problem in implementing multiprocessing In-Reply-To: <0C740C10A79444BF8F5B623C58E12D72@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Mon, Jan 19, 2009 at 3:50 PM, gopal mishra wrote: > i know this is not an io - bound problem, i am creating heavy objects in the > process and add these objects in to queue and get that object in my main > program using queue. > you can test the this sample code > import time > from multiprocessing import Process, Queue > > class Data(object): > def __init__(self): > self.y = range(1, 1000000) > > def getdata(queue): > data = Data() > queue.put(data) > > if __name__=='__main__': > t1 = time.time() > d1 = Data() > d2 = Data() > t2 = time.time() > print "without multiProcessing total time:", t2-t1 > #multiProcessing > queue = Queue() > Process(target= getdata, args=(queue, )).start() > Process(target= getdata, args=(queue, )).start() > s1 = queue.get() > s2 = queue.get() > t2 = time.time() > print "multiProcessing total time::", t2-t1 The reason your code above doesn't work as you expect and the multiprocessing part takes longer is because your Data objects are creating a list (a rather large list) of ints. Use xrange instead of range. Here's what I get (using xrange): $ python test.py without multiProcessing total time: 1.50203704834e-05 multiProcessing total time:: 0.116630077362 cheers James From narkewoody at gmail.com Mon Jan 19 02:49:51 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 19 Jan 2009 15:49:51 +0800 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 11:29 AM, James Mills wrote: > On Mon, Jan 19, 2009 at 1:10 PM, Steven Woody wrote: >> Python has Signal-Slot mechanism, why he still need another mechanism >> Event Handling? And, in some cases, it seems only Event Handling >> mechanism is available, for example closeEvent(). For what case and >> for what reason, the python think Signal Slot is not enough and will >> not work? > > In what context ? What application ? > I am reading mark summerfield's book Rapid GUI Programming with Python and Qt, chapter 6. In the example code, it inserted customized behavior when user selects file->exit by overriding closeEvent() event handler, but in other context, when a behavior is needed to handle user interaction, the single-slot mechanism is always used. From s.selvamsiva at gmail.com Mon Jan 19 03:12:50 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 19 Jan 2009 13:42:50 +0530 Subject: python resource management Message-ID: Hi all, I am running a python script which parses nearly 22,000 html files locally stored using BeautifulSoup. The problem is the memory usage linearly increases as the files are being parsed. When the script has crossed parsing 200 files or so, it consumes all the available RAM and The CPU usage comes down to 0% (may be due to excessive paging). We tried 'del soup_object' and used 'gc.collect()'. But, no improvement. Please guide me how to limit python's memory-usage or proper method for handling BeautifulSoup object in resource effective manner -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 03:58:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 18:58:33 +1000 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 5:49 PM, Steven Woody wrote: > I am reading mark summerfield's book Rapid GUI Programming with Python > and Qt, chapter 6. In the example code, it inserted customized > behavior when user selects file->exit by overriding closeEvent() event > handler, but in other context, when a behavior is needed to handle > user interaction, the single-slot mechanism is always used. Not having read the book myself I can't really comment, except that I -am- sure that this is specific to PyQt (at least the slots). Most GUI frameworks I know of employ a common architecture - one of an event-driven nature. cheers James From pavlovevidence at gmail.com Mon Jan 19 04:09:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 19 Jan 2009 01:09:30 -0800 (PST) Subject: problem in implementing multiprocessing References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Jan 18, 10:00?pm, "James Mills" wrote: > On Mon, Jan 19, 2009 at 3:50 PM, gopal mishra wrote: > > i know this is not an io - bound problem, i am creating heavy objects in the > > process and add these objects in to queue and get that object in my main > > program using queue. > > you can test the this sample code > > import time > > from multiprocessing import Process, Queue > > > class Data(object): > > ? ?def __init__(self): > > ? ? ? ?self.y = range(1, 1000000) > > > def getdata(queue): > > ? ?data = Data() > > ? ?queue.put(data) > > > if __name__=='__main__': > > ? ?t1 = time.time() > > ? ?d1 = Data() > > ? ?d2 = Data() > > ? ?t2 = time.time() > > ? ?print "without multiProcessing total time:", t2-t1 > > ? ?#multiProcessing > > ? ?queue = Queue() > > ? ?Process(target= getdata, args=(queue, )).start() > > ? ?Process(target= getdata, args=(queue, )).start() > > ? ?s1 = queue.get() > > ? ?s2 = queue.get() > > ? ?t2 = time.time() > > ? ?print "multiProcessing total time::", t2-t1 > > The reason your code above doesn't work as you > expect and the multiprocessing part takes longer > is because your Data objects are creating a list > (a rather large list) of ints. I'm pretty sure gopal is creating a deliberately large object to use as a test case, so switching to xrange isn't going to help here. Since multiprocessing serializes and deserializes the data while passing it from process to process, passing very large objects would have a very high latency and overhead. IOW, gopal's diagnosis is correct. It's just not practical to share very large objects among seperate processes. For simple data like large arrays of floating point numbers, the data can be shared with an mmaped file or some other memory-sharing scheme, but actual Python objects can't be shared this way. If you have complex data (networks and heirarchies and such) it's a lot harder to share this information among processes. Carl Banks From see.signature at no.spam Mon Jan 19 04:21:52 2009 From: see.signature at no.spam (Eric Brunel) Date: Mon, 19 Jan 2009 10:21:52 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Fri, 16 Jan 2009 17:49:50 +0100, Terry Reedy wrote: > Eric Brunel wrote: >> On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy >> wrote: >>> Eric Brunel wrote: >> [snip]>> And BTW, if this is actually a bug, where can I report it? >>> >>> bugs.python.org >> Thanks. I reported the problem. > > When you report that you reported to problem to the tracker (a good > idea), please include link so anyone reading this thread can jump there > to continue with followup there. Here it is: http://bugs.python.org/issue4961 Thanks again! -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From see.signature at no.spam Mon Jan 19 04:24:09 2009 From: see.signature at no.spam (Eric Brunel) Date: Mon, 19 Jan 2009 10:24:09 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Sun, 18 Jan 2009 01:57:12 +0100, Jos? Matos wrote: > On Friday 16 January 2009 09:47:36 Eric Brunel wrote: >> What do you mean by 'works'...? > > The usual meaning, I think. :-) > > Click "Yes" and the program prints True, click "No" and the programs > prints > "False". This is not the procedure I describe in the original post. The first time, it works for me too. It's only after I used the file dialog that it stops working. >> You don't have the problem? It doesn't ? >> change a thing for me... > > Notice that I am running the system python, that at least is different. Well, unless you're on a platform where a modified Python version is installed, it shouldn't. If you have the same version as mine, the bug should be there too... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From rNOSPAMon at flownet.com Mon Jan 19 04:28:21 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 19 Jan 2009 01:28:21 -0800 Subject: Yaro vs WebOb Message-ID: I'm selecting infrastructure for a web development and I've found two lightweight frameworks that seem to offer a lot of bang-for-the-byte: Yaro and WebOb. I'm wondering if anyone here has used either or both and has opinions about them. What has been your experience with them? Which do you prefer? Thanks, rg From nick at craig-wood.com Mon Jan 19 04:32:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 19 Jan 2009 03:32:03 -0600 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > gmane.comp.python.general > > > I ran a few tests on the new Python 2.6 multiprocessing module before > > migrating a threading code, and found out the locking code is not > > working well. In this case, a pool of 5 processes is running, each > > trying to get the lock and releasing it after waiting 0.2 seconds > > (action is repeated twice). It looks like the multiprocessing lock > > allows multiple locking after the second pass. Running the exact same > > code with threads works correctly. > > I've tested your code on Windows and I think the problem is on the Queue > class. If you replace the Queue with some print statements or write to a > log file, the sequence lock/release is OK. > You should file a bug report on http://bugs.python.org/ A little bit of instrumentation in the code reveals the problem. The Queue class doesn't always return the items in the order that they were put in. This should probably be either documented or fixed! I suspect it is impossible to fix for a multi-producer Queue though. The first number is time since the program started. Tested under linux. 0.048810 [proc0] Got lock 0.248679 [proc0] Released lock 0.248858 [proc0] Got lock 0.448666 [proc0] Released lock 0.448859 [proc2] Got lock 0.648639 [proc2] Released lock 0.648893 [proc3] Got lock 0.848633 [proc3] Released lock 0.848767 [proc3] Got lock 1.048635 [proc3] Released lock 1.049090 [proc1] Got lock 1.248617 [proc1] Released lock 1.248743 [proc1] Got lock 1.448634 [proc1] Released lock 1.448810 [proc4] Got lock 1.648674 [proc4] Released lock 1.648831 [proc4] Got lock 1.849867 [proc2] Got lock <--- out of order 1.849679 [proc4] Released lock <--- out of order 2.048683 [proc2] Released lock #!/usr/bin/python -*- coding: utf-8 -*- from multiprocessing import Process, Queue, Lock from Queue import Empty from threading import Thread import time start = time.time() def now(): return time.time() - start class test_lock_process(object): def __init__(self, lock, id, queue): self.lock = lock self.id = id self.queue = queue self.read_lock() def read_lock(self): for i in xrange(2): self.lock.acquire() self.queue.put('%9.6f [proc%d] Got lock' % (now(), self.id)) time.sleep(.2) self.queue.put('%9.6f [proc%d] Released lock' % (now(), self.id)) self.lock.release() def test_lock(processes=10, lock=Lock(), process=True, queue=None): print_result = False if queue == None: print_result = True queue = Queue() threads = [] for i in xrange(processes): if process: threads.append(Process(target=test_lock_process, args=(lock,i,queue,))) else: threads.append(Thread(target=test_lock_process, args=(lock,i,queue,))) for t in threads: t.start() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == "__main__": #test_lock(processes=5, process=True) test_lock(processes=5) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From funfullson at gmail.com Mon Jan 19 05:15:36 2009 From: funfullson at gmail.com (amin) Date: Mon, 19 Jan 2009 02:15:36 -0800 (PST) Subject: issue Message-ID: Hi dears. I started programing with python and want to use a suitable database.But I Know nothing about them.please introduse one to me. thanks. From sri_annauni at yahoo.co.in Mon Jan 19 05:17:00 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Mon, 19 Jan 2009 15:47:00 +0530 (IST) Subject: Getting OSError, Could someone suggest? Message-ID: <177800.90793.qm@web7905.mail.in.yahoo.com> Hi, ?I have written a script which will spawn more than 200 no of subprocesses. I have used subprocess.Popen to do that. ?OSError: [Error 24]?Too many open files. Could someone help me in fixing this error? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From Jean-Paul.VALENTIN at ingenico.com Mon Jan 19 05:21:33 2009 From: Jean-Paul.VALENTIN at ingenico.com (Jean-Paul VALENTIN) Date: Mon, 19 Jan 2009 11:21:33 +0100 Subject: output problem Message-ID: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC4A@frsnprexc1.usr.ingenico.loc> true, Windows automatically adds a newline after the program output. But maybe there is a workaround? When you launch x.bat containing no char, windows adds a newline after the program output. But when you launch x.bat finishing with at least one CRLF, windows does not add a newline after the program output. I am not sure though whether it is a windows feature... So maybe with Python a similar condition could allow for obtaining the same result... About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. P Please consider the environment before printing this e-mail -------------- next part -------------- An HTML attachment was scrubbed... URL: From apardon at forel.vub.ac.be Mon Jan 19 05:34:02 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Jan 2009 10:34:02 GMT Subject: I don't understand this syntax error Message-ID: I'm probably looking right over it, but for the moment I'm stumped. Can someone explain what is wrong. I'm running python 2.5.2 here This is the code: class vslice(object): def __init__(self, fun): self.fun = fun def __getitem__(self, inx): if not isinstance(inx, tuple): inx = inx, return self.fun(*inx) @vslice class IdSet(object): def __init__(self, *args): self.lst = [(sl.start, sl.stop) for sl in args] def __contains__(self, item): for low, high in self.lst: if low <= item < high: return True return False def __str__(self): return '[' + ', '.join('%d:%d' % sl for sl in self.lst) + ']' #IdSet = vslice(IdSet) idset = IdSet[1:3, 6:9] print idset for i in xrange(10): print i, i in idset This is the error I get: File "vslice.py", line 12 class IdSet(object): ^ SyntaxError: invalid syntax From __peter__ at web.de Mon Jan 19 05:46:45 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jan 2009 11:46:45 +0100 Subject: I don't understand this syntax error References: Message-ID: Antoon Pardon wrote: > I'm probably looking right over it, but for the moment > I'm stumped. Can someone explain what is wrong. I'm running > python 2.5.2 here > > This is the code: > @vslice > class IdSet(object): Class decorators require Python 2.6 Peter From speedup at gmail.com Mon Jan 19 05:53:57 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Mon, 19 Jan 2009 02:53:57 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> On Jan 17, 11:32?am, "Gabriel Genellina" wrote: > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > gmane.comp.python.general > > > I ran a few tests on the new Python 2.6multiprocessingmodule before > > migrating a threading code, and found out the locking code is not > > working well. In this case, a pool of 5 processes is running, each > > trying to get the lock and releasing it after waiting 0.2 seconds > > (action is repeated twice). It looks like themultiprocessinglock > > allows multiple locking after the second pass. Running the exact same > > code with threads works correctly. > > I've tested your code on Windows and I think the problem is on the Queue > class. If you replace the Queue with some print statements or write to a > log file, the sequence lock/release is OK. > You should file a bug report onhttp://bugs.python.org/ > > -- > Gabriel Genellina Thanks for your help gabriel, I just tested it without the queue and it works! I'll file a bug about the queues. Fred For those interested, the code that works (well, it always did, but this shows the real result): class test_lock_process(object): def __init__(self, lock): self.lock = lock self.read_lock() def read_lock(self): for i in xrange(5): self.lock.acquire() logging.info('Got lock') time.sleep(.2) logging.info('Released lock') self.lock.release() if __name__ == "__main__": logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % (message)s', level=logging.DEBUG) lock = Lock() processes = [] for i in xrange(2): processes.append(Process(target=test_lock_process, args= (lock,))) for t in processes: t.start() for t in processes: t.join() From psteiger at dcc.ufba.br Mon Jan 19 06:01:53 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Mon, 19 Jan 2009 03:01:53 -0800 Subject: issue In-Reply-To: References: Message-ID: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> What kind of database do you need? Relational Databases? The three major databases you can work with python are SQLite, MySQL and PostgreSQL (favorite of mine.) SQLite already comes with python. Try: >>> import sqlite3 SQLite is... Lite. All the informations are stored in a single file. MySQL and PostgreSQL are more complete databases that run as servers on the machine, and you can use python bindings for both. (psycopg2 for postgres, and i forgot what binds mysql to python at the moment.) I guess you should google for psycopg2, read a little bit about the SQL syntax (though you may not need to use them directly, it`s good to understand what happens behind the bindings.) The PostgreSQL docs are quite good. Sorry for not providing any links. They should be easy to find if you google for them. 2009/1/19 amin > Hi dears. > I started programing with python and want to use a suitable > database.But I Know nothing about them.please introduse one to me. > thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Jan 19 06:16:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 19 Jan 2009 05:16:33 -0600 Subject: issue In-Reply-To: References: Message-ID: <49746111.7080608@tim.thechases.com> > I started programing with python and want to use a suitable > database.But I Know nothing about them.please introduse one to > me. thanks. Since you're just starting out, I'd just use the built-in (as of Python2.5) sqlite >>> import sqlite3 >>> c = sqlite3.connect('tmp/test.db') >>> cur = c.cursor() >>> cur.execute('create table test(id int primary key)') >>> cur.execute('insert into test values (42)') >>> cur.execute('insert into test values (3141)') >>> cur.execute('select * from test') >>> cur.fetchall() [(42,), (3141,)] That will allow you to experiment. You can later scale up to something like a MySQL, PostgreSQL or some other DB connector. -tkc From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 06:20:55 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 11:20:55 GMT Subject: Getting OSError, Could someone suggest? References: Message-ID: <01845888$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 15:47:00 +0530, srinivasan srinivas wrote: > Hi, > ?I have written a script which will spawn more than 200 no of > ?subprocesses. I have used subprocess.Popen to do that. > > ?OSError: [Error 24]?Too many open files. > > Could someone help me in fixing this error? Open fewer files. As I understand it, each subprocess counts as at least one open file. You may be able to increase the number of open files, but that will be dependent on the operating system you are using. -- Steven From psteiger at dcc.ufba.br Mon Jan 19 06:33:59 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Mon, 19 Jan 2009 03:33:59 -0800 Subject: Getting OSError, Could someone suggest? In-Reply-To: <01845888$0$20652$c3e8da3@news.astraweb.com> References: <01845888$0$20652$c3e8da3@news.astraweb.com> Message-ID: <909ef3300901190333i7f444d5dy161e11dd0b271d76@mail.gmail.com> 2009/1/19 Steven D'Aprano > On Mon, 19 Jan 2009 15:47:00 +0530, srinivasan srinivas wrote: > > > Hi, > > I have written a script which will spawn more than 200 no of > > subprocesses. I have used subprocess.Popen to do that. > > > > OSError: [Error 24] Too many open files. > > > > Could someone help me in fixing this error? > > Open fewer files. > > As I understand it, each subprocess counts as at least one open file. You > may be able to increase the number of open files, but that will be > dependent on the operating system you are using. > Yeah. By his question i supposed that opening less files was not an 'ok' solution. But of course you can do that, and it is prefered if it won't interfere negatively in your program. -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco at sferacarta.com Mon Jan 19 06:35:18 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 19 Jan 2009 12:35:18 +0100 Subject: English-like Python In-Reply-To: References: Message-ID: The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? Many have tried that in the decades, but IMHO the best approach is to just rename the language. We cannot do that since it's already been trademarked for that very reason. From Wikipedia: ENGLISH (actually trademarked in all caps) is a database retrieval and reporting language somewhat like SQL, but with no actual programming or update capabilities. Originally released by Microdata in 1973 and named so that the company's brochures could claim that developers could generate reports on their implementation of the Pick operating system using English. From castironpi at gmail.com Mon Jan 19 06:52:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 19 Jan 2009 03:52:47 -0800 (PST) Subject: problem in implementing multiprocessing References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Jan 19, 3:09?am, Carl Banks wrote: snip > Since multiprocessing serializes and deserializes the data while > passing > it from process to process, passing very large objects would have a > very > high latency and overhead. ?IOW, gopal's diagnosis is correct. ?It's > just not practical to share very large objects among seperate > processes. You could pass composite objects back and forth by passing pieces back and forth. You'd have to construct it so as not to need access to the entire data structure in any one piece; that is, only need access to other small pieces. > For simple data like large arrays of floating point numbers, the data > can be shared with an mmaped file or some other memory-sharing scheme, > but actual Python objects can't be shared this way. ?If you have > complex > data (networks and heirarchies and such) it's a lot harder to share > this > information among processes. It wouldn't hurt to have a minimal set of Python objects that are 'persistent live', that is, stored out of memory in their native form. The only problem is, they can't contain references to volatile objects. (I don't believe POSH addresses this.) From charlie137 at gmail.com Mon Jan 19 06:59:17 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 03:59:17 -0800 (PST) Subject: tasklet library based on PEP 0342 Message-ID: Hello all, Using new features of python generators, as described in PEP 0342, it is possible to write some sort of "tasklets" in a maner very similar to stackless python, but running on cpython. For example : @tasklet def my_task(): yield Timer(10) yield "result" @tasklet def other_task(): result = yield my_task() other_task().start(callback=on_return) I wrote an implementation of this in the scope of an open source project for openmoko [0], there is also an other very similar implementation from the kiwi project [1]. This kind of tool is very useful, but unfortunately there is no standard library that would provide a unified way to use it independently of the underlying event loop. Does someone know if a similar library could eventually be added into python standard libraries ? Would it be accepted as a PEP ? Guillaume [0] http://git.openmoko.org/?p=tichy.git;a=blob;f=tichy/tasklet.py [1] http://www.async.com.br/projects/kiwi/api/kiwi.tasklet.html From phillip.oldham at gmail.com Mon Jan 19 07:04:23 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Mon, 19 Jan 2009 04:04:23 -0800 (PST) Subject: Can I run an operation on an object's attribute when reading? Message-ID: Is it possible to automatically run an operation on a object's attribute when reading? For instance, if I have the following: class Item(object): tags = ['default','item'] item = Item() desc = item.tags When I'm reading the item.tags, I'd like to automagically have the value converted to a string, eg: "default item". I know I could write a getter to do this for me, but I'd like to avoid that if possible on this occasion. Any help would be great! Thanks. From clp2 at rebertia.com Mon Jan 19 07:15:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 04:15:05 -0800 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: References: Message-ID: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> On Mon, Jan 19, 2009 at 4:04 AM, Phillip B Oldham wrote: > Is it possible to automatically run an operation on a object's > attribute when reading? For instance, if I have the following: > > class Item(object): > tags = ['default','item'] > > item = Item() > > desc = item.tags > > When I'm reading the item.tags, I'd like to automagically have the > value converted to a string, eg: "default item". I know I could write > a getter to do this for me, but I'd like to avoid that if possible on > this occasion. Assuming I'm interpreting you correctly (you're going to have to use something like a getter): class Item(object): def __init__(self): self._tags = ['default', 'item'] @property def tags(self): return ' '.join(self._tags) print Item().tags #==> default item Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From phillip.oldham at gmail.com Mon Jan 19 07:22:39 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Mon, 19 Jan 2009 12:22:39 +0000 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> Message-ID: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: > Assuming I'm interpreting you correctly (you're going to have to use > something like a getter): Thanks, but I'm looking for a way to do it *without* using a getter as I don't have easy access to the class (its being generated for me elsewhere). Essentially I'd like to overwrite (if possible) the default behavior when returning certain attributes on certain objects. From bignose+hates-spam at benfinney.id.au Mon Jan 19 07:33:14 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 19 Jan 2009 23:33:14 +1100 Subject: Can I run an operation on an object's attribute when reading? References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> Message-ID: <87ocy35vcl.fsf@benfinney.id.au> Phillip B Oldham writes: > Thanks, but I'm looking for a way to do it *without* using a getter > as I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain > objects. You can override the behaviour of a class by defining a subclass. class UntouchableTypeWrapper(UntouchableType): def _foo_get(self): return str(self.foo) foo = property(_foo_get) Then you can create instances of the wrapper class where you want the new behaviour. -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From clp2 at rebertia.com Mon Jan 19 07:34:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 04:34:12 -0800 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <50697b2c0901190434p1170414fi3255d104077b457f@mail.gmail.com> On Mon, Jan 19, 2009 at 4:22 AM, Phillip B Oldham wrote: > On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: >> Assuming I'm interpreting you correctly (you're going to have to use >> something like a getter): > > Thanks, but I'm looking for a way to do it *without* using a getter as > I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain objects. To my knowledge, you can't really "overwrite" that behavior without editing the class (or how it's generated). The next closest thing would be to write a proxy class that defines a __getattr__ method implementing the semantics you want. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bignose+hates-spam at benfinney.id.au Mon Jan 19 07:38:51 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 19 Jan 2009 23:38:51 +1100 Subject: Can I run an operation on an object's attribute when reading? References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <87ocy35vcl.fsf@benfinney.id.au> Message-ID: <87k58r5v38.fsf@benfinney.id.au> Ben Finney writes: > You can override the behaviour of a class by defining a subclass. > > class UntouchableTypeWrapper(UntouchableType): > > def _foo_get(self): > return str(self.foo) > > foo = property(_foo_get) Which, I realise now, won't work (and I didn't test it). But hopefully the idea is clear. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we have nothing to fear but fear itself, why does | _o__) Elanore Roosevelt wear that spooky mask?? ?_Pinky and The Brain_ | Ben Finney From mikehartl at web.de Mon Jan 19 07:39:10 2009 From: mikehartl at web.de (Michael Hartl) Date: Mon, 19 Jan 2009 13:39:10 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <4974746E.6060208@web.de> Phillip B Oldham schrieb: > On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: > >> Assuming I'm interpreting you correctly (you're going to have to use >> something like a getter): >> > > Thanks, but I'm looking for a way to do it *without* using a getter as > I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain objects. > -- > http://mail.python.org/mailman/listinfo/python-list > You could still add the getter to the class after it has been defined if that's your only problem with using a getter: class Item(object): tags = ['default','item'] @property def tags(self): return ' '.join(self.tags) setattr(Item, "Tags", tags) print Item().Tags #==> default item But I don't think there's a way to do it without a different name (here "tags" - "Tags"), is there? From matt.j.warren at gmail.com Mon Jan 19 07:47:21 2009 From: matt.j.warren at gmail.com (AlienBaby) Date: Mon, 19 Jan 2009 04:47:21 -0800 (PST) Subject: Simple image manipulation question Message-ID: <352e283b-76ed-469f-b72a-578685c2f6c6@q30g2000prq.googlegroups.com> Hi, Could anyone point me toward the right modules etc.. that would help with; loading an image file rendering some text onto that image saveing the image file I've looked into Tkinter, but that seems to require working with canvases etc.., but I do not need to actually display the image, just render some text onto it and save it again. PIL looked promising, but I couldn't see how to put text into the image once loaded. Any help much appreciated, Thanks, Matt. From ra.ravi.rav at gmail.com Mon Jan 19 07:47:39 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Mon, 19 Jan 2009 04:47:39 -0800 (PST) Subject: Difference between Python 2.2.2 and Python 2.5 References: <018344b9$0$8693$c3e8da3@news.astraweb.com> Message-ID: <78a8e37b-51bd-47c3-9734-fb8483429580@u18g2000pro.googlegroups.com> On Jan 18, 8:44?pm, Steven D'Aprano wrote: > On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: > > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I > > know is Python 2.5 ?. > > > Can you please tell me differences between the two so that I can save > > myself from incompatible code. > > Everything new mentioned here: > > http://www.python.org/doc/2.5/whatsnew/whatsnew25.htmlhttp://www.python.org/doc/2.4/whatsnew/whatsnew24.htmlhttp://www.python.org/doc/2.3/whatsnew/whatsnew23.html > > won't exist in Python 2.2. > > -- > Steven This is a list too big! Is there any checker which can be applied to the Python code. (of course any solution other than running python 2.2 over the code) From bearophileHUGS at lycos.com Mon Jan 19 07:57:35 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 19 Jan 2009 04:57:35 -0800 (PST) Subject: Simple image manipulation question References: <352e283b-76ed-469f-b72a-578685c2f6c6@q30g2000prq.googlegroups.com> Message-ID: AlienBaby: > PIL looked promising, but I couldn't see how to put text into the > image once loaded. A 15-second long Google search gives me: http://nedbatchelder.com/blog/200801/truly_transparent_text_with_pil.html Bye, bearophile From gagsl-py2 at yahoo.com.ar Mon Jan 19 07:58:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 10:58:39 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald escribi?: > Ah yes, with your help I seem to have solved my own problem. I had > PYTHONPATH defined to point to the 2.5 directory. Best to avoid setting PYTHONPATH at all. If you install new packages into a standard place like site-packages, and use .pth files for those libraries that aren't packages, there should be no need to set PYTHONPATH. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 19 07:58:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 10:58:39 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald escribi?: > Ah yes, with your help I seem to have solved my own problem. I had > PYTHONPATH defined to point to the 2.5 directory. Best to avoid setting PYTHONPATH at all. If you install new packages into a standard place like site-packages, and use .pth files for those libraries that aren't packages, there should be no need to set PYTHONPATH. -- Gabriel Genellina From speedup at gmail.com Mon Jan 19 08:16:22 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Mon, 19 Jan 2009 05:16:22 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> Message-ID: <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> On Jan 19, 11:53?am, Fr?d?ric Sagnes wrote: > On Jan 17, 11:32?am, "Gabriel Genellina" > wrote: > > > > > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > > gmane.comp.python.general > > > > I ran a few tests on the new Python 2.6multiprocessingmodule before > > > migrating a threading code, and found out the locking code is not > > > working well. In this case, a pool of 5 processes is running, each > > > trying to get the lock and releasing it after waiting 0.2 seconds > > > (action is repeated twice). It looks like themultiprocessinglock > > > allows multiple locking after the second pass. Running the exact same > > > code with threads works correctly. > > > I've tested your code on Windows and I think the problem is on the Queue > > class. If you replace the Queue with some print statements or write to a > > log file, the sequence lock/release is OK. > > You should file a bug report onhttp://bugs.python.org/ > > > -- > > Gabriel Genellina > > Thanks for your help gabriel, I just tested it without the queue and > it works! I'll file a bug about the queues. > > Fred > > For those interested, the code that works (well, it always did, but > this shows the real result): > > class test_lock_process(object): > ? ? def __init__(self, lock): > ? ? ? ? self.lock = lock > ? ? ? ? self.read_lock() > > ? ? def read_lock(self): > ? ? ? ? for i in xrange(5): > ? ? ? ? ? ? self.lock.acquire() > ? ? ? ? ? ? logging.info('Got lock') > ? ? ? ? ? ? time.sleep(.2) > ? ? ? ? ? ? logging.info('Released lock') > ? ? ? ? ? ? self.lock.release() > > if __name__ == "__main__": > ? ? logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % > (message)s', level=logging.DEBUG) > > ? ? lock = Lock() > > ? ? processes = [] > ? ? for i in xrange(2): > ? ? ? ? processes.append(Process(target=test_lock_process, args= > (lock,))) > > ? ? for t in processes: > ? ? ? ? t.start() > > ? ? for t in processes: > ? ? ? ? t.join() Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, referencing this thread. -- Fr?d?ric Sagnes From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 08:19:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 13:19:10 GMT Subject: Can I run an operation on an object's attribute when reading? References: Message-ID: <0184743f$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 04:04:23 -0800, Phillip B Oldham wrote: > Is it possible to automatically run an operation on a object's attribute > when reading? For instance, if I have the following: > > class Item(object): > tags = ['default','item'] > > item = Item() > > desc = item.tags > > When I'm reading the item.tags, I'd like to automagically have the value > converted to a string, eg: "default item". I know I could write a getter > to do this for me, but I'd like to avoid that if possible on this > occasion. When all you have is a hammer, everything looks like a nail... Why do you have to read item.tags directly? Just write a function and call it instead of direct attribute access. This is the simplest, easiest solution with the fewest side-effects. def get_tags(item): return ' '.join(item.tags) desc = get_tags(item) If you don't like that solution, monkey-patch the class with a getter: @property def tags(self): return " ".join(self._tags) Item._tags = Item.tags Item.tags = tags This is dangerous, because other classes may expect Item.tags to be a list. Better to create your own accessor method: def get_tags(self): return " ".join(self.tags) Item.get_tags = get_tags item = Item() desc = item.get_tags() If you don't like monkey-patching (and you probably shouldn't), then write a proxy class that delegates to the original: _Item = Item class Item(object): def __init__(self, *args): self.__dict__['_item'] = _Item(*args) @property def tags(self): return ' '.join(self._item.tags) def __getattr__(self, attr): return getattr(self._item, attr) def __setattr__(self, attr, value): setattr(self._item, attr, value) I dare say there's a metaclass solution too, but I'm not crazy enough to do that. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 08:23:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 13:23:12 GMT Subject: Difference between Python 2.2.2 and Python 2.5 References: <018344b9$0$8693$c3e8da3@news.astraweb.com> <78a8e37b-51bd-47c3-9734-fb8483429580@u18g2000pro.googlegroups.com> Message-ID: <01847531$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 04:47:39 -0800, Ravi wrote: > On Jan 18, 8:44?pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: >> > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while >> > what I know is Python 2.5 ?. >> >> > Can you please tell me differences between the two so that I can save >> > myself from incompatible code. >> >> Everything new mentioned here: >> >> http://www.python.org/doc/2.5/whatsnew/whatsnew25.htmlhttp:// www.python.org/doc/2.4/whatsnew/whatsnew24.htmlhttp://www.python.org/ doc/2.3/whatsnew/whatsnew23.html >> >> won't exist in Python 2.2. >> >> -- >> Steven > > This is a list too big! It's not that big. It's only three versions different. > Is there any checker which can be applied to the Python code. (of course > any solution other than running python 2.2 over the code) What's wrong with running Python 2.2 over the code? That's the best way to discover what doesn't work. -- Steven From gervaz at gmail.com Mon Jan 19 08:23:52 2009 From: gervaz at gmail.com (gervaz) Date: Mon, 19 Jan 2009 05:23:52 -0800 (PST) Subject: Regexp Message-ID: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Hi all, I need to find all the address in a html source page, I'm using: 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)()?' but the [^]+ pattern retrieve all the strings not containing < or / or a etc, although I just not want the word "". How can I specify: 'do not search the string "blabla"?' Thanks From scott.p.macdonald at gmail.com Mon Jan 19 08:33:03 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Mon, 19 Jan 2009 06:33:03 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: I think I set it a long time ago to get the python VTK bindings working... On Mon, Jan 19, 2009 at 5:58 AM, Gabriel Genellina wrote: > En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald < > scott.p.macdonald at gmail.com> escribi?: > > Ah yes, with your help I seem to have solved my own problem. I had >> PYTHONPATH defined to point to the 2.5 directory. >> > > Best to avoid setting PYTHONPATH at all. If you install new packages into a > standard place like site-packages, and use .pth files for those libraries > that aren't packages, there should be no need to set PYTHONPATH. > > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Mon Jan 19 08:50:54 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 19 Jan 2009 05:50:54 -0800 (PST) Subject: Python Style Guide Questions - Contd. Message-ID: Hi, I have some more questions about python code styling. 1. Global Variables: In my code, I am using some global variables. Now, when I ran PyLint, it raised convention errors mentioning that they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that mentioned. Please let me know whether that is the usual styling mechanism which is used. 2. I have many loops wherein I define a variable as just a counter. for x in range(counter): do_something() Please note that I am not using x anywhere in the program. Pylint again raises warnings saying that the variable should be used. Should I disregard it or use the default variable _ ? for _ in range(counter): do_something() pylint does not raise errors for those. Are there any issues in using _ ? From jnoller at gmail.com Mon Jan 19 09:00:49 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 19 Jan 2009 09:00:49 -0500 Subject: Python 2.6's multiprocessing lock not working on second use? In-Reply-To: <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: <4222a8490901190600l15be427bt7327ba231c8a0bbf@mail.gmail.com> On Mon, Jan 19, 2009 at 8:16 AM, Fr?d?ric Sagnes wrote: > On Jan 19, 11:53 am, Fr?d?ric Sagnes wrote: >> On Jan 17, 11:32 am, "Gabriel Genellina" >> wrote: >> >> >> >> > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo >> > gmane.comp.python.general >> >> > > I ran a few tests on the new Python 2.6multiprocessingmodule before >> > > migrating a threading code, and found out the locking code is not >> > > working well. In this case, a pool of 5 processes is running, each >> > > trying to get the lock and releasing it after waiting 0.2 seconds >> > > (action is repeated twice). It looks like themultiprocessinglock >> > > allows multiple locking after the second pass. Running the exact same >> > > code with threads works correctly. >> >> > I've tested your code on Windows and I think the problem is on the Queue >> > class. If you replace the Queue with some print statements or write to a >> > log file, the sequence lock/release is OK. >> > You should file a bug report onhttp://bugs.python.org/ >> >> > -- >> > Gabriel Genellina >> >> Thanks for your help gabriel, I just tested it without the queue and >> it works! I'll file a bug about the queues. >> >> Fred >> >> For those interested, the code that works (well, it always did, but >> this shows the real result): >> >> class test_lock_process(object): >> def __init__(self, lock): >> self.lock = lock >> self.read_lock() >> >> def read_lock(self): >> for i in xrange(5): >> self.lock.acquire() >> logging.info('Got lock') >> time.sleep(.2) >> logging.info('Released lock') >> self.lock.release() >> >> if __name__ == "__main__": >> logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % >> (message)s', level=logging.DEBUG) >> >> lock = Lock() >> >> processes = [] >> for i in xrange(2): >> processes.append(Process(target=test_lock_process, args= >> (lock,))) >> >> for t in processes: >> t.start() >> >> for t in processes: >> t.join() > > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, > referencing this thread. > Thanks, I've assigned it to myself. Hopefully I can get a fix put together soonish, time permitting. -jesse From gagsl-py2 at yahoo.com.ar Mon Jan 19 09:05:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 12:05:01 -0200 Subject: Overriding base class methods in the C API References: Message-ID: En Sun, 18 Jan 2009 22:18:59 -0200, Floris Bruynooghe escribi?: > I've been trying to figure out how to override methods of a class in > the C API. For Python code you can just redefine the method in your > subclass, but setting tp_methods on the type object does not seem to > have any influcence. Anyone know of a trick I am missing? No tricks; you have to define the new type structure, probably including tp_methods if you redefine any... (Ensure you create an object of the new type, obviously) See e.g. _collections.c how defaultdict inherits from dict. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 19 09:17:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 12:17:41 -0200 Subject: tasklet library based on PEP 0342 References: Message-ID: En Mon, 19 Jan 2009 09:59:17 -0200, escribi?: > Using new features of python generators, as described in PEP 0342, it > is possible to write some sort of "tasklets" in a maner very similar > to stackless python, but running on cpython. For example : > [...] > This kind of tool is very useful, but unfortunately there is no > standard library that would provide a unified way to use it > independently of the underlying event loop. > > Does someone know if a similar library could eventually be added into > python standard libraries ? Would it be accepted as a PEP ? Try the python-ideas list at python-ideas at python.org -- Gabriel Genellina From google at mrabarnett.plus.com Mon Jan 19 09:21:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 14:21:40 +0000 Subject: Regexp In-Reply-To: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <49748C74.4020109@mrabarnett.plus.com> gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' > If the name is followed by "<" then just match the name with [^<]+: href="(?Phttp://mysite\.com/[^"]+)">()?(?P[^<]+)( b>)? I've also changed mysite.com to mysite\.com because . will match any character, but what you probably want to match is ".". From wgrigg at draper.com Mon Jan 19 09:24:41 2009 From: wgrigg at draper.com (bill) Date: Mon, 19 Jan 2009 06:24:41 -0800 (PST) Subject: python processes and Visual Studio Message-ID: <17ef3ab2-0aec-4660-921b-190a5cab45f5@r15g2000prd.googlegroups.com> All, This may sound somewhat convoluted, but here goes: 1. I have a Python script that invokes builds in Visual Studio via the command line interface - 'devenv' 2. It works GREAT 3. I have added a post_build event to a VS Solution that has but one project. 4. This event invokes a Python command - 'c:\python25\python.exe c: \....myPython.py' 5. It works GREAT 6. I move on the another VS Solution that has 6 projects. 7. I add the post_build event command to all 6 projects 8. It 'almost' works... all 6 projects build and the post_build event triggers in all 6 projects and that works 9. Unhappily, the whole thing then 'hangs' I am guessing that perhaps a sub-process or something like that is not exiting. The Python script that is triggered in the post_build event, myPython.py, does nothing special upon exit. Should it? Or, is there some way to determine why the the while thing 'hangs'? TIA, Bill From deets at nospam.web.de Mon Jan 19 09:26:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 15:26:10 +0100 Subject: Python Style Guide Questions - Contd. References: Message-ID: <6tjgs2Fb6n25U1@mid.uni-berlin.de> koranthala wrote: > Hi, > I have some more questions about python code styling. > 1. Global Variables: In my code, I am using some global variables. > Now, when I ran PyLint, it raised convention errors mentioning that > they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that > mentioned. Please let me know whether that is the usual styling > mechanism which is used. I adopted that convention, however I don't know if it is "official". I'd consider it good style though. > 2. I have many loops wherein I define a variable as just a counter. > for x in range(counter): > do_something() > Please note that I am not using x anywhere in the program. > Pylint again raises warnings saying that the variable should be > used. > Should I disregard it or use the default variable _ ? > for _ in range(counter): > do_something() > pylint does not raise errors for those. Are there any issues in > using _ ? Nope, using _ is perfectly fine for variables you don't care about. Another example is e.g. foo, bar, _ = ("a", "b", "c") Diez From philip at semanchuk.com Mon Jan 19 09:30:46 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 19 Jan 2009 09:30:46 -0500 Subject: python resource management In-Reply-To: References: Message-ID: <280373AB-AC97-4B92-ACCA-938DE3F070C5@semanchuk.com> On Jan 19, 2009, at 3:12 AM, S.Selvam Siva wrote: > Hi all, > > I am running a python script which parses nearly 22,000 html files > locally > stored using BeautifulSoup. > The problem is the memory usage linearly increases as the files are > being > parsed. > When the script has crossed parsing 200 files or so, it consumes all > the > available RAM and The CPU usage comes down to 0% (may be due to > excessive > paging). > > We tried 'del soup_object' and used 'gc.collect()'. But, no > improvement. > > Please guide me how to limit python's memory-usage or proper method > for > handling BeautifulSoup object in resource effective manner You need to figure out where the memory is disappearing. Try commenting out parts of your script. For instance, maybe start with a minimalist script: open and close the files but don't process them. See if the memory usage continues to be a problem. Then add elements back in, making your minimalist script more and more like the real one. If the extreme memory usage problem is isolated to one component or section, you'll find it this way. HTH Philip From alan.isaac at gmail.com Mon Jan 19 09:44:01 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 19 Jan 2009 14:44:01 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: On 1/17/2009 3:59 PM Ned Deily apparently wrote: > Ah, so the rumors are true: we are supposed to prefer '{0:>10}'.format('wtf?') to '%10s' % 'wtf?' and '{{0}}{0}'.format('wtf?').format('wtf?') to '%%s%s' % 'wtf?' % 'wtf?' According to PEP 4, "obsolete" means "deprecated". So the compact, simple, and useful old string formatting is really deprecated? Ouch. Thanks, Alan Isaac From deets at nospam.web.de Mon Jan 19 09:50:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 15:50:16 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <6tji98Fb5oidU1@mid.uni-berlin.de> gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' You should consider using BeautifulSoup or lxml2's error-tolerant parser to work with HTML-documents. Sooner or later your regex-based processing is bound to fail, as documents get more complicated. Better to use the right tool for the job. The code should look like this (untested): from BeautifulSoup import BeautifulSoup html = """link""" res = [] soup = BeautifulSoup(html) for tag in soup.findAll("a"): if tag["href"].startswith("http://mysite.com"): res.append(tag["href"]) Not so hard, and *much* more robust. Diez From __peter__ at web.de Mon Jan 19 09:53:30 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jan 2009 15:53:30 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' Have considered BeautifulSoup? from BeautifulSoup import BeautifulSoup from urlparse import urlparse for a in BeautifulSoup(page)("a"): try: href = a["href"] except KeyError: pass else: url = urlparse(href) if url.hostname == "mysite.com": print href Peter From antroy at gmail.com Mon Jan 19 10:01:02 2009 From: antroy at gmail.com (Ant) Date: Mon, 19 Jan 2009 07:01:02 -0800 (PST) Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> A 0-width positive lookahead is probably what you want here: >>> s = """ ... hdhd Test String OK ... ... """ >>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >>> m = re.search(p, s) >>> m.group(1) 'http://mysite.com/blah.html' >>> m.group(2) 'Test String OK' The (?=...) bit is the lookahead, and won't consume any of the string you are searching. I've binned the named groups for clarity. The beautiful soup answers are a better bet though - they've already done the hard work, and after all, you are trying to roll your own partial HTML parser here, which will struggle with badly formed html... From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 10:01:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 15:01:40 GMT Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: <01848c43$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: > On 1/17/2009 3:59 PM Ned Deily apparently wrote: >> > > > Ah, so the rumors are true: > we are supposed to prefer > '{0:>10}'.format('wtf?') > to > '%10s' % 'wtf?' > and > '{{0}}{0}'.format('wtf?').format('wtf?') to > '%%s%s' % 'wtf?' % 'wtf?' Well, that second example certainly is a WTF. I think we are supposed to prefer: '{0}{0}'.format('wtf?') to '%%s%s' % 'wtf?' % 'wtf?' And frankly, I do. > According to PEP 4, > "obsolete" means "deprecated". > So the compact, simple, and useful > old string formatting is really deprecated? Ouch. PEP 4 applies to *modules*. String formatting is not a module. Old string formatting is obsolete but not yet deprecated. Why don't you raise the issue on python-dev, where it may do some good? -- Steven From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 19 10:13:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 16:13:22 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> Message-ID: <49749892$0$23985$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 18, 9:22 am, Bruno Desthuilliers > wrote: > >> Properties by themselves are not the problem, quite on the contrary - as >> you say, they actually help wrt/ encapsulation. What breaks >> encapsulation is *automatic generation* for properties for *each and >> any* implementation attribute. Might as well just makes them all public >> attribute then. > > Let me correct my statement about the automatic generation of > properties in Scala: it is only for public attributes, not all > attributes. I must be missing the point : if it's a public attribute, it doesn't need a "property" ? I guess we use the same words for different things here. > > Getting back to the bigger point, I will gladly agree with you that > data hiding is not a magic bullet that will eliminate all bugs. The > idea that I or anyone else said that, however, is a red herring. Data > hiding is just one safeguard in a portfolio of safeguards that can > *help* to prevent certain kinds of bugs s/data-hiding/encapsulation/ and I'll wholefully agree. > as well as deliberate acts of > sabotage or fraud. I definitively wouldn't bet my ass on language-level access restriction to protect software from fraud or sabotage. > When you have a tough problem to solve, you need > all the help you can get. As far as I'm concerned, *enforcing* access-restriction is of no help. > You keep saying that if you hire competent, trustworthy developers, > you don't need data hiding. Yes. And I also think that trust (and even - to a certain extent - competence) is better built on trust than on distrust. When treated as an irresponsible morons just barely able to type code, most peoples tend to become just that : code-monkeys. > Well, maybe, but when you have a team of > dozens or hundreds of developers, your chances of avoiding any bad > ones is zero for all practical purposes. I don't know how many developpers work for google, but I bet there all smart enough to not need enforced access restriction. Very few people have a burning desire to shoot themselves in the foot, you know. Take some not-that-trivial projects like Zope/Plone. There are quite a few lines of code involved, and quite a lot of programmers worked on it. Some of them being very average joe programmer FWIW. Guess what ? From experience, it JustWork(tm). Granted, this is not a critical system - but that's not the point here. The point is that _from experience_, most programmers are wise enough to avoid doing stupid things. > And even if all your developers were excellent, data hiding would > still be a convenient mechanism to simplify their jobs so they can > focus on higher level problems Sorry, but this makes no sense. How could the lack of *language-enforced* access restriction makes anything more complicated ??? > -- and not have to rely on an ugly > naming convention. And here we are, finally : *you* don't like this convention (and we've aready been thru that discussion IIRC). Guess what ? As far as I'm concerned, I just *love* this convention. Because I *never* have to ask myself if some attribute is interface or implementation. > Now, if developers become careless because they think data hiding will > save them, then that would be a problem. If you believe data-hiding will protect your code from fraud, sabotage or any other malevolence, then you already have this problem IMHO. > That much I will concede. But > I doubt that happens much. From darcy at druid.net Mon Jan 19 10:37:39 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 19 Jan 2009 10:37:39 -0500 Subject: issue In-Reply-To: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> References: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> Message-ID: <20090119103739.288902aa.darcy@druid.net> On Mon, 19 Jan 2009 03:01:53 -0800 "Patrick Steiger" wrote: > MySQL and PostgreSQL are more complete databases that run as servers on the > machine, and you can use python bindings for both. (psycopg2 for postgres, > and i forgot what binds mysql to python at the moment.) There are more than one adapter for each. Check out the list at http://wiki.python.org/moin/DatabaseInterfaces for more information. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alan.isaac at gmail.com Mon Jan 19 10:38:02 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 19 Jan 2009 15:38:02 GMT Subject: string formatting documentation In-Reply-To: <01848c43$0$20652$c3e8da3@news.astraweb.com> References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: > On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: >> we are supposed to prefer '{0:>10}'.format('wtf?') >> to >> '%10s' % 'wtf?' >> and >> '{{0}}{0}'.format('wtf?').format('wtf?') to >> '%%s%s' % 'wtf?' % 'wtf?' On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote: > Well, that second example certainly is a WTF. > I think we are supposed to prefer: > '{0}{0}'.format('wtf?') > to > '%%s%s' % 'wtf?' % 'wtf?' But your replacement misses the point of the example, which is that sequential formatting is often needed. That is, you need to generate a format string from a format string. More explicitly: '{{0}} {0}'.format('earlyinfo').format('lateinfo') '%%s %s' % 'earlyinfo' % 'lateinfo' But of more interest: you claim PEP 4 is not relevant, and that old string formatting is NOT deprecated. I would like assurance that it is not deprecated. Can you back that? Thanks, Alan Isaac From gervaz at gmail.com Mon Jan 19 10:39:54 2009 From: gervaz at gmail.com (gervaz) Date: Mon, 19 Jan 2009 07:39:54 -0800 (PST) Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> Message-ID: <06ad4643-1493-45fd-899e-8796cb8f0f59@r10g2000prf.googlegroups.com> On Jan 19, 4:01?pm, Ant wrote: > A 0-width positive lookahead is probably what you want here: > > >>> s = """ > > ... hdhd Test String OK a> > ... > ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' > >>> m = re.search(p, s) > >>> m.group(1) > > 'http://mysite.com/blah.html'>>> m.group(2) > > 'Test String OK' > > The (?=...) bit is the lookahead, and won't consume any of the string > you are searching. I've binned the named groups for clarity. > > The beautiful soup answers are a better bet though - they've already > done the hard work, and after all, you are trying to roll your own > partial HTML parser here, which will struggle with badly formed html... Ok, thank you all, I'll take a look at beautiful soup, albeit the lookahead solution fits better for the little I have to do. From martinjamesevans at gmail.com Mon Jan 19 11:08:01 2009 From: martinjamesevans at gmail.com (martinjamesevans at gmail.com) Date: Mon, 19 Jan 2009 08:08:01 -0800 (PST) Subject: Regular expression that skips single line comments? Message-ID: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a semicolon. e.g. tests 1 and 2 should be ignored sInput = """ ; $1 test1 ; test2 $2 test3 ; $3 $3 $3 test4 $5 test5 $6 test7 $7 test7 """ Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] The following RE works fine but does not deal with the commented lines: re.findall(r"(\$.)", sInput, re.I) e.g. ['$1', '$2', '$3', '$3', '$3', '$5', '$6', '$7'] My attempts at trying to use (?!;) type expressions keep failing. I'm not convinced this is suitable for a single expression, so I have also attempted to first find-replace any commented lines out without much luck. e.g. re.sub(r"^[\t ]*?;.*?$", r"", sInput, re.I+re.M) Any suggestions would be appreciated. Thanks Martin From google at mrabarnett.plus.com Mon Jan 19 11:29:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 16:29:44 +0000 Subject: Regular expression that skips single line comments? In-Reply-To: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4974AA78.8000505@mrabarnett.plus.com> martinjamesevans at gmail.com wrote: > I am trying to parse a set of files that have a simple syntax using > RE. I'm interested in counting '$' expansions in the files, with one > minor consideration. A line becomes a comment if the first non-white > space character is a semicolon. > > e.g. tests 1 and 2 should be ignored > > sInput = """ > ; $1 test1 > ; test2 $2 > test3 ; $3 $3 $3 > test4 > $5 test5 > $6 > test7 $7 test7 > """ > > Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] > > > The following RE works fine but does not deal with the commented > lines: > > re.findall(r"(\$.)", sInput, re.I) > > e.g. ['$1', '$2', '$3', '$3', '$3', '$5', '$6', '$7'] > > > My attempts at trying to use (?!;) type expressions keep failing. > > I'm not convinced this is suitable for a single expression, so I have > also attempted to first find-replace any commented lines out without > much luck. > > e.g. re.sub(r"^[\t ]*?;.*?$", r"", sInput, re.I+re.M) > > > Any suggestions would be appreciated. Thanks > You could use: >>> re.findall(r"^\s*;.*|(\$.)", sInput, re.M) ['', '', '$3', '$3', '$3', '$5', '$6', '$7'] and then ignore the empty strings. From python.list at tim.thechases.com Mon Jan 19 11:40:26 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 19 Jan 2009 10:40:26 -0600 Subject: Regular expression that skips single line comments? In-Reply-To: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4974ACFA.2070307@tim.thechases.com> > I am trying to parse a set of files that have a simple syntax using > RE. I'm interested in counting '$' expansions in the files, with one > minor consideration. A line becomes a comment if the first non-white > space character is a semicolon. > > e.g. tests 1 and 2 should be ignored > > sInput = """ > ; $1 test1 > ; test2 $2 > test3 ; $3 $3 $3 > test4 > $5 test5 > $6 > test7 $7 test7 > """ > > Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] We're interested in two things: comments and "dollar-something"s >>> import re >>> r_comment = re.compile(r'\s*;') >>> r_dollar = re.compile(r'\$\d+') Then remove comment lines and find the matching '$' expansions: >>> [r_dollar.findall(line) for line in sInput.splitlines() if not r_comment.match(line)] [[], ['$3', '$3', '$3'], [], ['$5'], ['$6'], ['$7']] Finally, roll each line's results into a single list by slightly abusing sum() >>> sum((r_dollar.findall(line) for line in sInput.splitlines() if not r_comment.match(line)), []) ['$3', '$3', '$3', '$5', '$6', '$7'] Adjust the r_dollar if your variable pattern differs (such as reverting to your previous r'\$.' pattern if you prefer, or using r'\$\w+' for multi-character variables). -tkc From deets at nospam.web.de Mon Jan 19 11:48:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 17:48:07 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> <06ad4643-1493-45fd-899e-8796cb8f0f59@r10g2000prf.googlegroups.com> Message-ID: <6tjp67Fb3o4vU1@mid.uni-berlin.de> gervaz wrote: > On Jan 19, 4:01?pm, Ant wrote: >> A 0-width positive lookahead is probably what you want here: >> >> >>> s = """ >> >> ... hdhd Test String OK> a> >> ... >> ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >> >>> m = re.search(p, s) >> >>> m.group(1) >> >> 'http://mysite.com/blah.html'>>> m.group(2) >> >> 'Test String OK' >> >> The (?=...) bit is the lookahead, and won't consume any of the string >> you are searching. I've binned the named groups for clarity. >> >> The beautiful soup answers are a better bet though - they've already >> done the hard work, and after all, you are trying to roll your own >> partial HTML parser here, which will struggle with badly formed html... > > Ok, thank you all, I'll take a look at beautiful soup, albeit the > lookahead solution fits better for the little I have to do. Little things tend to get out of hand quickly... This is the reason why so many gave you the hint. Diez From phil at freehackers.org Mon Jan 19 12:03:09 2009 From: phil at freehackers.org (BlueBird) Date: Mon, 19 Jan 2009 09:03:09 -0800 (PST) Subject: Event Handling and Signal-Slot Mechanism References: Message-ID: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> On Jan 19, 4:10?am, Steven Woody wrote: > Hi, > > Python has Signal-Slot mechanism, Python does not have signal/slot mechanism. You are talking about the Qt toolkit, which is initially a (nice) C++ toolkit, available also in python via the PyQt wrapper. Signal/slots were introduced by Qt to make C++ gui programming easier. Signal/slots basically provides a very easy way to implement the observer/consumer design pattern, with only 2 or 3 lines of code (as opposed to one or two classes in java for example). Python itself does not have signal/slots but the it's very easy to emulate them using the Python language. In C++ however, it's tricky to do signal/slots in pure C++ and this addition is one of the reason that programming GUI in Qt is nice (personal opinion obviously). To comne back to your question: > why he still need another mechanism > Event Handling? ? This is actually a Qt question: why have event handling for some things, and signal/slot for some others ? My opinion on the debate: - signal/slot add an overhead of one class to every QObject class, and 3 method calls when emitting a signal (if I remember Qt documentation correctly). For some real-time tasks, like repainting the screen, every microseconds must be saved and sparing 3 method calls is a good idea. - since a GUI application is fundamentally an event driven system, the event stuff has to be there anyway. - signal/slot is very convenient for data exchange between widgets but I think it would be overkill to use it everywhere. Event propagation is a nice design as well. Now, if you want to discuss this further, I suggest to go to Qt interest ( http://lists.trolltech.com/qt-interest/ ) which is dedicated to discussion around Qt. cheers, Philippe From Caseyweb at gmail.com Mon Jan 19 12:03:31 2009 From: Caseyweb at gmail.com (Casey) Date: Mon, 19 Jan 2009 09:03:31 -0800 (PST) Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4b0374c4-9afb-45f7-b49b-1f6e717fda2a@g1g2000pra.googlegroups.com> Another option (I cheated a little and turned sInput into a sequence of lines, similar to what you would get reading a text file): sInput = [ '; $1 test1', ' ; test2 $2', ' test3 ; $3 $3 $3', 'test4', '$5 test5', ' $6', ' test7 $7 test7', ] import re re_exp = re.compile(r'(\$.)') re_cmt = re.compile(r'\s*;') expansions = [exp for line in sInput for exp in re_exp.findall(line) if not re_cmt.match(line)] print(expansions) >>> ['$3', '$3', '$3', '$5', '$6', '$7'] From tim.arnold at sas.com Mon Jan 19 12:44:52 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Mon, 19 Jan 2009 12:44:52 -0500 Subject: python resource management References: Message-ID: "Philip Semanchuk" wrote in message news:mailman.7530.1232375454.3487.python-list at python.org... > > On Jan 19, 2009, at 3:12 AM, S.Selvam Siva wrote: > >> Hi all, >> >> I am running a python script which parses nearly 22,000 html files >> locally >> stored using BeautifulSoup. >> The problem is the memory usage linearly increases as the files are >> being >> parsed. >> When the script has crossed parsing 200 files or so, it consumes all the >> available RAM and The CPU usage comes down to 0% (may be due to >> excessive >> paging). >> >> We tried 'del soup_object' and used 'gc.collect()'. But, no >> improvement. >> >> Please guide me how to limit python's memory-usage or proper method for >> handling BeautifulSoup object in resource effective manner > > You need to figure out where the memory is disappearing. Try commenting > out parts of your script. For instance, maybe start with a minimalist > script: open and close the files but don't process them. See if the > memory usage continues to be a problem. Then add elements back in, making > your minimalist script more and more like the real one. If the extreme > memory usage problem is isolated to one component or section, you'll find > it this way. > > HTH > Philip Also, are you creating a separate soup object for each file or reusing one object over and over? --Tim From rhamph at gmail.com Mon Jan 19 13:11:35 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Mon, 19 Jan 2009 10:11:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> Message-ID: On Jan 18, 12:51?pm, "Russ P." wrote: > And even if all your developers were excellent, data hiding would > still be a convenient mechanism to simplify their jobs so they can > focus on higher level problems -- and not have to rely on an ugly > naming convention. That's just it ? the cost of maintaining friend lists and similar mechanisms exceeds the benefit enforced privates. Doing it for performance or for a secure sandbox of course changes this, but they're separate issues. Java hides low-level details because it thinks the programmer is incompetent. Python hides them because it thinks the programmer has better things to do. An underscore is all a competent programmer needs. From jeff at jmcneil.net Mon Jan 19 13:25:48 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 19 Jan 2009 10:25:48 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: <30128b77-7618-4b83-b9d3-e69f600210bc@t3g2000yqa.googlegroups.com> On Jan 18, 6:35 pm, Simon Brunning wrote: > 2009/1/17 Michele Simionato : > > > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > > a review for it: > > >http://www.artima.com/weblogs/viewpost.jsp?thread=240415 > > +1 for this. I'm 3/4 of the way through it, it's pretty good. Covers > many on the important areas that the more introductory books rightly > leave out, > > -- > Cheers, > Simon B. I keep a copy of "Python In A Nutshell" on my desk at all times. Most of my books are in great shape, but this one is ripped all to hell. The sign of a good book. It covers just about everything, though not all in extreme depth. It's a great book! I've been writing Python for about 4 years now and over the week or so I've caught the "I should know more about the internals" bug. As a result, I've been trying to trace the interpreter from the start of the main function through user code execution. Getting to fully understand the C API and the actual CPython implementation is something I wish I would have done years ago. I'd suggest you do that if you get the chance. From nick at craig-wood.com Mon Jan 19 13:32:12 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 19 Jan 2009 12:32:12 -0600 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: Jesse Noller wrote: > > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, > > referencing this thread. > > Thanks, I've assigned it to myself. Hopefully I can get a fix put > together soonish, time permitting. Sounds like it might be hard or impossible to fix to me. I'd love to be proved wrong though! If you were thinking of passing time.time() / clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll want to know that it can differ by significant amounts on different processors :-( Good luck! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From vedrandekovic at gmail.com Mon Jan 19 13:58:58 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Mon, 19 Jan 2009 10:58:58 -0800 (PST) Subject: Python and threads References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> <497390c3$0$31878$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <2f05e652-eda9-4f5c-8b2b-88a6cdace073@q30g2000prq.googlegroups.com> On 18 sij, 21:27, Stefan Behnel wrote: > vedrandeko... at yahoo.com wrote: > > and thanks for all previous help.I want to measure memory usage of > > executed python script.I'am working on windows XP. > > Could you qualify "measure"? Do you mean: > > a) "debug" (permanently high accuracy, potentially high runtime overhead) > b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime > ? ? ? ? ? ? ? overhead) > c) "find out" (low accuracy or just max usage, no permanent observation) > > ? > > Stefan Hello, I want to "find out" , sorry for this "measure". Regards, John From bdesth.quelquechose at free.quelquepart.fr Mon Jan 19 14:02:34 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 20:02:34 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <4974dbf2$0$12404$426a34cc@news.free.fr> Chris Rebert a ?crit : > On Mon, Jan 19, 2009 at 4:22 AM, Phillip B Oldham > wrote: >> On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: >>> Assuming I'm interpreting you correctly (you're going to have to use >>> something like a getter): >> Thanks, but I'm looking for a way to do it *without* using a getter as >> I don't have easy access to the class (its being generated for me >> elsewhere). Essentially I'd like to overwrite (if possible) the >> default behavior when returning certain attributes on certain objects. > > To my knowledge, you can't really "overwrite" that behavior without > editing the class (or how it's generated). Assuming it's really about a *class* object (not instances of it), *and* it's a new-style class, it is possible: class Foo(object): def __init__(self): self.tags = ['foo', 'bar'] def wrap_tag_access(cls): def fset(obj, value): obj._tags = value def fget(obj): print "do something here" return obj._tags cls.tags = property(fset=fset, fget=fget) return cls Foo = wrap_tag_access(Foo) f = Foo() print f.tags > The next closest thing would be to write a proxy class that defines a > __getattr__ method implementing the semantics you want. If it's a "classic" class, then yes, it's probably the best thing to do. From bdesth.quelquechose at free.quelquepart.fr Mon Jan 19 14:05:59 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 20:05:59 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <0184743f$0$20652$c3e8da3@news.astraweb.com> References: <0184743f$0$20652$c3e8da3@news.astraweb.com> Message-ID: <4974dcbf$0$1445$426a74cc@news.free.fr> Steven D'Aprano a ?crit : (snip) > When all you have is a hammer, everything looks like a nail... Why do you > have to read item.tags directly? Just write a function and call it > instead of direct attribute access. A sensible advice, but only relevant if this class instances are only used by code the OP do control. Which may or not be the case. From kdawg44 at gmail.com Mon Jan 19 14:14:35 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:14:35 -0500 Subject: Receiving Output from os.system command Message-ID: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> I am really new to python and am trying to learn it to do some projects. I wanted to perform a simple task and am having some trouble with it. I run linux in a vm on a windows laptop for work. I have my laptop screen and an external monitor. I move my Ubuntu VM back and forth depending on what I am working on so I wanted to write a little python script that changed the resolutions depending on what the current resolution is. I have: #! /usr/bin/python import sys import os import re re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}') xrandr_output = os.popen('xrandr').readlines() currentRes = re_currentResolution.search(xrandr_output) print currentRes.group(0) I just want to grab the xrandr output as a string and parse it with the regex. This will give me a string with the current resolution, for instance "current 1024 x 768". I would then split that up and call back to the os.system('xrandr -s 1280x1024'). If the resolution was "current 1280 x 1024" then I would parse that and call back to os.system('xrandr -s 1024x768'). However, when I try the line (as in the code above): currentRes = re_currentResolution.search(xrandr_output) it is complaining that xrandr_output is not a string. (however, if I do a print xrandr_output it prints fine) I instead get the following error: Traceback (most recent call last): File "change_res.py", line 9, in currentRes = re_currentResolution.search(xrandr_output) TypeError: expected string or buffer What am I doing wrong? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Mon Jan 19 14:21:12 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:21:12 -0500 Subject: Receiving Output from os.system command In-Reply-To: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> References: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> Message-ID: <5caea3690901191121p4d03b68fy4f70917d700a8f03@mail.gmail.com> Nevermind, I am an idiot. I didn't realize what it was returning... Please disregard. Thanks. Kevin On Mon, Jan 19, 2009 at 2:14 PM, K-Dawg wrote: > I am really new to python and am trying to learn it to do some projects. I > wanted to perform a simple task and am having some trouble with it. I run > linux in a vm on a windows laptop for work. I have my laptop screen and an > external monitor. I move my Ubuntu VM back and forth depending on what I am > working on so I wanted to write a little python script that changed the > resolutions depending on what the current resolution is. > > I have: > > #! /usr/bin/python > > import sys > import os > import re > > re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}') > xrandr_output = os.popen('xrandr').readlines() > currentRes = re_currentResolution.search(xrandr_output) > print currentRes.group(0) > > I just want to grab the xrandr output as a string and parse it with the > regex. This will give me a string with the current resolution, for instance > "current 1024 x 768". I would then split that up and call back to the > os.system('xrandr -s 1280x1024'). If the resolution was "current 1280 x > 1024" then I would parse that and call back to os.system('xrandr -s > 1024x768'). > > However, when I try the line (as in the code above): > > currentRes = re_currentResolution.search(xrandr_output) > > it is complaining that xrandr_output is not a string. (however, if I do a > print xrandr_output it prints fine) > > I instead get the following error: > > Traceback (most recent call last): > File "change_res.py", line 9, in > currentRes = re_currentResolution.search(xrandr_output) > TypeError: expected string or buffer > > What am I doing wrong? > > Thanks. > > Kevin > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Mon Jan 19 14:36:05 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 19 Jan 2009 11:36:05 -0800 (PST) Subject: Logging help Message-ID: Hi, Is it possible somehow to have the logging module rotate the files every time I start it. Basically, I can automatically rotate using RotatingFileHandler; Now I want it rotated every time I start the program too. Ex: The logging file - log.txt Now, rotatingfilehandler goes and updates to log.txt.1, log.txt.2, log.txt.3 etc. Now, I also want to rotate it automatically I start the program - i.e. The second time I start the program - log.txt -> log.txt.1, log.txt. 1 -> log.txt.2 etc. I can write up a simple script to move it by 1 digit every time. My question is - is it possible automatically via logging functionality? This is needed because say TimedRotatingFileHandler etc wont work that well otherwise. It does look like twisted.python.logfile.DailyLogFile seems to be an Ok option, but I want to use the logging module in the Python distribution, since it is more powerful. From kdawg44 at gmail.com Mon Jan 19 14:39:30 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:39:30 -0500 Subject: Beginner Question Message-ID: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Please forgive my beginner question. I have used python a little bit, mainly as a scripting language to perform specific administrative tasks. I have trying to learn to use it to develop applications but there are a few things I do not understand. I come from more of a Java background. I do no understand the underscore methods. __main__ - is this just the main method that is in the file that is actually executed? I also see __init__ a lot. What is that for? Is it like a constructor in Java or totally different? Thanks for clearing it up. I am undertaking my first application development effort in python and anticipate discussing this with all of you a lot. :) Thanks for your support. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Mon Jan 19 14:40:46 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 19 Jan 2009 14:40:46 -0500 Subject: Python 2.6's multiprocessing lock not working on second use? In-Reply-To: References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: <4222a8490901191140s132ab9a9hd2fc0e8435f01b6a@mail.gmail.com> On Mon, Jan 19, 2009 at 1:32 PM, Nick Craig-Wood wrote: > Jesse Noller wrote: >> > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, >> > referencing this thread. >> >> Thanks, I've assigned it to myself. Hopefully I can get a fix put >> together soonish, time permitting. > > Sounds like it might be hard or impossible to fix to me. I'd love to > be proved wrong though! > > If you were thinking of passing time.time() / > clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll > want to know that it can differ by significant amounts on different > processors :-( > > Good luck! > Consider my parade rained on. And after looking at it this morning, yes - this is going to be hard, and should be fixed for a FIFO queue :\ -jesse From Scott.Daniels at Acm.Org Mon Jan 19 14:55:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 11:55:13 -0800 Subject: Python and threads In-Reply-To: <6th4riFat1vuU1@mid.uni-berlin.de> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> Message-ID: vedrandekovic at yahoo.com said: > ... when I run these two threads, > I think they don't start at the same time In response, Diez B. Roggisch wrote: > ... Even if you managed to get two threads started simultaneously > (which the OS doesn't even offer IINM), the would soon run out of sync.... And the simple way to remember this is to rember why time was made, "Time is Nature's way of keeping everything from happening at once." :-) Just a brief humor break. From Scott.Daniels at Acm.Org Mon Jan 19 14:56:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 11:56:43 -0800 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: waltbrad wrote: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. The answer to your question may depend on your operating system and setup. From sjmachin at lexicon.net Mon Jan 19 15:03:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 12:03:58 -0800 (PST) Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On Jan 20, 2:38?am, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, > and that old string formatting is NOT deprecated. > I would like assurance that it is not deprecated. It is not deprecated YET; see this: http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6 PEP 3101: Advanced String Formatting. Note: the 2.6 description mentions the format() method for both 8-bit and Unicode strings. In 3.0, only the str type (text strings with Unicode support) supports this method; the bytes type does not. The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1. From rNOSPAMon at flownet.com Mon Jan 19 15:15:29 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 19 Jan 2009 12:15:29 -0800 Subject: wsgi silently swallows errors Message-ID: Consider the following wsgi app: def application(env, start_response): start_response('200 OK',[('Content-type','text/plain')]) yield "hello" x=1/0 yield "world" The result of this is that the web browser displays "hello" and an error message ends up in the web log. But there is no other indication that an error has occurred. Is there any way to get WSGI to not silently swallow errors that occur after start_response has been called? Thanks, rg From Russ.Paielli at gmail.com Mon Jan 19 15:19:10 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 12:19:10 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> Message-ID: <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> On Jan 19, 7:13?am, Bruno Desthuilliers wrote: > I must be missing the point : if it's a public attribute, it doesn't > need a "property" ? I guess we use the same words for different things here. Yes, you are missing more than one point. Scala automatically converts public data members into properties, apparently to save the programmer the trouble of doing it manually. If you are interested, I'm sure you can find publicly available information on it. > I definitively wouldn't bet my ass on language-level access restriction > to protect software from fraud or sabotage. You're missing the point here too. I'll try one more time to explain it. Access restriction enforced by the language is just one safeguard among several that are usually available. I think the lock analogy is very appropriate here. Think about door locks. Would you "bet your ass" on them to keep you secure? Of course not. You might also have a firearm or a dog. But even if you don't have those, you surely have a police department, and surely they carry guns. Because you cannot "bet your ass" on door locks for your security, does that mean you just abandon them altogether? Maybe so, if you live in a very remote place, but most people still seem to think they need locks on their doors. Well, think of access restrictions enforced by the language as analogous to door locks. Let's take the analogy a bit further. Suppose you work in a secure building with strict access control, and everyone in the building is "trusted" (whatever that means). This situation is analogous to a group of "trusted" developers working on a project together. Would you feel comfortable having no locks on the doors? Maybe you would, but I wouldn't. I wouldn't want to just let my co- workers, trusted or not, have access to all my personal stuff. And what if I need to store something of value from time to time? They may be honest, but why even tempt them? What if one of them decides he needs to borrow my favorite Python book while I'm gone, then forgets to return it? But what if you don't want your door locked? Well, you have the option of not using your lock. You can get your way whether the doors have locks or not. But if I want mine locked, and no locks are available, I can't get what I want. When you say that a language should not even have access control available, you are essentially saying that you should get your way -- and to hell with anyone who disagrees with my way. > Yes. And I also think that trust (and even - to a certain extent - > competence) is better built on trust than on distrust. When treated as > an irresponsible morons just barely able to type code, most peoples tend > to become just that : code-monkeys. That may well apply in some environments, but it certainly does not apply in all environments. It certainly does not apply in a defense contracting environment, or a financial software development environment, to give just two of many possible examples. Maybe you don't personally care about such environments, but who are you to decide what environments Python should or should not be suitable for? > Take some not-that-trivial projects like Zope/Plone. There are quite a > few lines of code involved, and quite a lot of programmers worked on it. > ? Some of them being very average joe programmer FWIW. Guess what ? From > experience, it JustWork(tm). Granted, this is not a critical system - > but that's not the point here. The point is that _from experience_, most > programmers are wise enough to avoid doing stupid things. And would data hiding have impeded those projects? Or could it perhaps have helped? I don't know, but I don't think you can simply assume it would have been a net minus. I know for fact that the strict access restrictions in Ada were indispensable in the integration of the flight software in the Boeing 777, for example. Without them, they'd probably *still* be trying to get it right! > > And even if all your developers were excellent, data hiding would > > still be a convenient mechanism to simplify their jobs ?so they can > > focus on higher level problems > > Sorry, but this makes no sense. How could the lack of > *language-enforced* access restriction ?makes anything more complicated ??? Because it forces humans to check for access restrictions when the language could do it. > > -- and not have to rely on an ugly > > naming convention. > > And here we are, finally : *you* don't like this convention (and we've > aready been thru that discussion IIRC). > > Guess what ? As far as I'm concerned, I just *love* this convention. > Because I *never* have to ask myself if some attribute is interface or > implementation. If you like it that much, you would be perfectly free to continue using that convention even if access control was enforced. > > Now, if developers become careless because they think data hiding will > > save them, then that would be a problem. > > If you believe data-hiding will protect your code from fraud, sabotage > or any other malevolence, then you already have this problem IMHO. I addressed this red herring above. From benjamin.kaplan at case.edu Mon Jan 19 15:32:45 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 19 Jan 2009 15:32:45 -0500 Subject: Beginner Question In-Reply-To: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> References: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Message-ID: On Mon, Jan 19, 2009 at 2:39 PM, K-Dawg wrote: > Please forgive my beginner question. I have used python a little bit, > mainly as a scripting language to perform specific administrative tasks. I > have trying to learn to use it to develop applications but there are a few > things I do not understand. > > I come from more of a Java background. > > I do no understand the underscore methods. __main__ - is this just the > main method that is in the file that is actually executed? I also see > __init__ a lot. What is that for? Is it like a constructor in Java or > totally different?] Python doesn't have a main method. It's files are scripts and not programs. It's just like a shell script- everything is run. Unlike Java where everything has to be in a method in a class, you can have actions performed at the module level in Python. What you'll find is a lot of "if __name__ == '__main__'" conditionals. The name of the script that is run is always __main__, so you can use this to only run certain commands when the script is run directly as opposed to be imported by another module. __init__ is the equivalent of a Java constructor. > > > Thanks for clearing it up. I am undertaking my first application > development effort in python and anticipate discussing this with all of you > a lot. :) Thanks for your support. > > Kevin > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptriller at soapwars.de Mon Jan 19 15:37:46 2009 From: ptriller at soapwars.de (Peter) Date: Mon, 19 Jan 2009 21:37:46 +0100 Subject: Embedding Python. But not so easy. Message-ID: <200901192137.46603.ptriller@soapwars.de> Hi, Right now I am in a project writing a Simulation engine, and we are right now in the process of evaluating a script engine. The basic principle is a C++ engine simulating the environment and scriptable agents interacting with the environment. But the current design has a special requirement to that scriptability and my current knowledge of the API of Python isolated two problems 1) Threads: the simulation is going to be run in a very parallel environment with several CPUs and http://docs.python.org/c-api/init.html#thread-state-and- the-global-interpreter-lock there is a global lock mentioned. Does that mean that the python code can not benefit from this ? 2) The script has to hand back control to the C++ framework without increasing the C execution stack. and be able to resume the execution at a later point. I try some pseudo code here to explain // C++: ctx = new ExecutionContext(); ctx->run(); while(ctx->stillRunning()) { otherStuff(); ctx->resume(); } ...... // Python y=21 ... .. # Here the execution is suspended und control handed back to the C++ code suspend y+=12 end I hope that makes it clear. I did not see a way to implement this with the python interpreter. I am hoping to be proven wrong Thanks in advance Greets Peter From yanghatespam at gmail.com Mon Jan 19 15:38:56 2009 From: yanghatespam at gmail.com (Yang Zhang) Date: Mon, 19 Jan 2009 15:38:56 -0500 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <4974E4E0.1060909@gmail.com> For posterity: the problem turned out to be a second request being made in quick succession by the client-side Javascript, causing the web.py request handler to run in multiple threads concurrently. The request handlers don't create their own Postgresql connections, but instead share one across all sessions. The absence of any synchronization protecting this connection resulted in myriad errors and crashes in the C extension module (in both pygresql and psycopg2). Neha Gupta wrote: > Hey, > > I only have little experience with web.py and psycopg2 and am running > into a weird problem, I'd appreciate any help I can get with debugging > it. > > I wrote a simple program that works and I don't see any crash: > ---- > import psycopg2 > > try: > database_conn = psycopg2.connect("dbname='dbname' user='username' > host='hostname'"); > except: > print "Unable to connect to the database!" > > database_conn.set_isolation_level(0) > cur = database_conn.cursor(); > > while True: > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > rows = cur.fetchall() > print rows > ----- > > However, I have a small website built using web.py framework which has > a date picker that lets the user pick a date and it takes the user to > a new url such as: localhost:8080/departures/01-05-2007. I issue a > query to my database for the date selected by the user and retrieve > the results. The problem now is that if I select different dates > directly by changing the url then everything works but as soon as I > pick a date from date picker the server crashes. I removed the date > picker and made it just a text box but as soon as I hit the submit > button, server crashes so I know it is not the date picker that > causing trouble. > --- > class departures: > def buildDepartureTableHtml(self, date): > web.debug('date', date) > # Issue the query. > # select avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '2007-02-15' group > by origin, crs_dep > # _hour order by origin, crs_dep_hour; > try: > web.debug("About to issue query") > # query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '" + date + "' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > web.debug('query executed!') > rows = cur.fetchall() > web.debug('rows fetched!') > web.debug(rows) > except Exception, e: > print repr(e) > database_conn.rollback() > return "
Invalid Date
" > -- > // JS code > function submitForm() { > var date = ($("date").value).replace(/\//g,"-"); > window.location = "http://" + window.location.host + "/ > departures/" + date; > } > > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. The message "About to issue query" > gets printed as well as the right date chosen from the date picker but > then I see the following: > > Assertion failed: (str != NULL), function PyString_FromString, file > Objects/stringobject.c, line 107. > Abort trap > > with a pop that says: "The application Python quit unexpectedly. The > problem may have been caused by the _psycopg.so plug-in". > -- > I don't understand the error message above. The date did get passed > correctly and am now not even using it, I use the hard coded date. So > what is going on? > > Any help would be great. > > Thank you! > Neha > -- > http://mail.python.org/mailman/listinfo/python-list -- Yang Zhang http://www.mit.edu/~y_z/ From aktests at gmail.com Mon Jan 19 16:00:44 2009 From: aktests at gmail.com (ak) Date: Mon, 19 Jan 2009 13:00:44 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server Message-ID: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Hi everyone, I have a problem with urllib2 on this particular url, hosted on an Oracle HTTP Server http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=phone&null which gets 302 redirected to https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a cookie through the Set-Cookie header field in the 302 reply. This works fin with firefox. However, with urllib2 and the following code snippet, it doesn't work -------- import cookiejar import urllib2 cookiejar = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) url = 'http://www.orange.sk/eshop/sk/portal/catalog.html? type=post&subtype=phone&null' req = urllib2.Request(url, None) s=opener.open(req) -------- Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib2.py", line 387, in open response = meth(req, response) File "/usr/lib/python2.5/urllib2.py", line 498, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.5/urllib2.py", line 419, in error result = self._call_chain(*args) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302 return self.parent.open(new) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open r = h.getresponse() File "/usr/lib/python2.5/httplib.py", line 928, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 385, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 349, in _read_status raise BadStatusLine(line) httplib.BadStatusLine Trying the redirected url directly doesn't work either (trying with Firefox will give an HTML error page, as the cookie is not set yet, but trying with urllib2 gives the same exception as previously, whereas it should return the HTML error page) This works correctly on other urls on this website (http(s):// www.orange.sk). Am I doing anything wrong or is this a bug in urllib2 ? -- ak From exarkun at divmod.com Mon Jan 19 16:03:25 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 19 Jan 2009 16:03:25 -0500 Subject: wsgi silently swallows errors In-Reply-To: Message-ID: <20090119210325.9754.1469965245.divmod.quotient.5288@henry.divmod.com> On Mon, 19 Jan 2009 12:15:29 -0800, Ron Garret wrote: >Consider the following wsgi app: > >def application(env, start_response): > start_response('200 OK',[('Content-type','text/plain')]) > yield "hello" > x=1/0 > yield "world" > >The result of this is that the web browser displays "hello" and an error >message ends up in the web log. But there is no other indication that >an error has occurred. > >Is there any way to get WSGI to not silently swallow errors that occur >after start_response has been called? WSGI is a specification, not a piece of software. The specification isn't swallowing the error, some piece of software is. What WSGI container are you using? Jean-Paul From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 16:24:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 21:24:50 GMT Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 08:08:01 -0800, martinjamesevans wrote: > I am trying to parse a set of files that have a simple syntax using RE. > I'm interested in counting '$' expansions in the files, with one minor > consideration. A line becomes a comment if the first non-white space > character is a semicolon. Since your data is line-based, surely the simplest, clearest and most natural solution is to parse each line individually instead of trying to process the entire input with a single RE? def extract_dollar_expansions(sInput): accumulator = [] for line in sInput.split('\n'): line = line.lstrip() if line.startswith(';'): continue accumulator.extend(re.findall(r"(\$.)", line)) return accumulator (Aside: why are you doing a case-insensitive match for a non-letter? Are there different upper- and lower-case dollar signs?) >>> extract_dollar_expansions(sInput) ['$3', '$3', '$3', '$5', '$6', '$7'] -- Steven From bj_666 at gmx.net Mon Jan 19 16:32:10 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 19 Jan 2009 21:32:10 GMT Subject: Python Style Guide Questions - Contd. References: Message-ID: <6tk9qqFbav8gU1@mid.uni-berlin.de> On Mon, 19 Jan 2009 05:50:54 -0800, koranthala wrote: > Hi, > I have some more questions about python code styling. 1. Global > Variables: In my code, I am using some global variables. > Now, when I ran PyLint, it raised convention errors mentioning that they > should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that > mentioned. Please let me know whether that is the usual styling > mechanism which is used. PEP8 doesn't mention constants at all. The all caps naming for constants is a convention in several languages. > 2. I have many loops wherein I define a variable as just a counter. > for x in range(counter): > do_something() > Please note that I am not using x anywhere in the program. Pylint > again raises warnings saying that the variable should be > used. > Should I disregard it or use the default variable _ ? for _ in > range(counter): > do_something() > pylint does not raise errors for those. Are there any issues in > using _ ? Pylint doesn't barf on `dummy` either. The point is having a name that makes clear at the head of the loop, that the reader doesn't have to bother looking for places where the value will be used because it is clear from the name that the value won't be used at all. BTW pylint is very configurable, you can dump the default configuration and find out which names are "allowed" by default and of course define your own set of "value doesn't matter" names. Ciao, Marc 'BlackJack' Rintsch From linuxguy123 at gmail.com Mon Jan 19 16:37:55 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Mon, 19 Jan 2009 14:37:55 -0700 Subject: PyQt4 on Windows ? Message-ID: <1232401075.10889.29.camel@localhost.localdomain> What does it take to get a PyQt4 application running on a Windows machine ? I'm sorry if this is a redundant question, but I've searched this and I am not finding a comprehensive answer. If anyone is running a PyQt4 application on a Windows (XP or Vista) machine, I'd love to know how it works for you and how extensive the application is and how much of the Qt library it uses. Thanks From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 16:43:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 21:43:05 GMT Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On Mon, 19 Jan 2009 15:38:02 +0000, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, and that old > string formatting is NOT deprecated. I would like assurance that it is > not deprecated. Can you back that? If you want to know what python-dev have in mind, you have to ask them, not me. But as I see it, the earliest % formatting could be removed would be Python 3.2: Python 3.1 to get a formal deprecation warning, with removal no earlier than 3.2. So you've got about a year to change their mind about deprecating the old style, or alternatively, a year to get used to the new style, followed by another year for % to go away completely. -- Steven From joe at strout.net Mon Jan 19 16:44:30 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 14:44:30 -0700 Subject: function to find the modification date of the project Message-ID: <4974F43E.4020402@strout.net> This isn't a question, but something I thought others may find useful (and if somebody can spot any errors with it, I'll be grateful). We had a case recently where the client was running an older version of our app, and didn't realize it. In other languages I've avoided this by displaying the compile date in the About box, but of course Python doesn't really have a meaningful compile date. So, instead we're now displaying the latest modification date of any .py file in the project. Here's the function that finds that: def lastModDate(): "Get the latest modification date (as a string) of any .py file in this project." import os, time latest = 0 dir = os.path.dirname(__file__) if dir == '': dir = '.' # HACK, but appears necessary for fname in os.listdir(dir): if fname.endswith('.py'): modtime = os.stat(os.path.join(dir, fname)).st_mtime if modtime > latest: latest = modtime out = time.strftime('%Y-%m-%d', time.localtime(latest)) return out The intent of this code is to find any .py files in the same directory as the module containing the above code, and return (as a date string in SQL/ISO format) the latest modification date thereof. Then, this is displayed to the user in the about box like so: dlg = wx.MessageDialog(self, "etown unified database system\nRevision: %s" \ % lastModDate(), "About etown Central", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() (That's wxPython, of course.) I haven't yet tested this in a packaged app or on Windows, but it seems to work in our OS X test environment. One odd thing was the need to employ the HACK identified above, where if __file__ happens to already be in the current directory, then os.path.dirname of it returns the empty-string -- yet the empty-string is not a valid argument to os.listdir(). Is there a better way to a list of files in the same directory as a given file? Cheers, - Joe From schap at offenbachers.com Mon Jan 19 16:47:01 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Mon, 19 Jan 2009 16:47:01 -0500 Subject: PyQt4 on Windows ? In-Reply-To: <1232401075.10889.29.camel@localhost.localdomain> References: <1232401075.10889.29.camel@localhost.localdomain> Message-ID: <4974F4D5.6050105@offenbachers.com> I have one running. actually use freezer to create an exe for it in windows. http://www.riverbankcomputing.co.uk/software/pyqt/download That will tell you how to get started. The app I wrote uses Pryro(with middleware server on a linux machine). And I use the standard widgets that qt has grid, table , combobox etc.... Linuxguy123 wrote: > What does it take to get a PyQt4 application running on a Windows > machine ? > > I'm sorry if this is a redundant question, but I've searched this and I > am not finding a comprehensive answer. > > If anyone is running a PyQt4 application on a Windows (XP or Vista) > machine, I'd love to know how it works for you and how extensive the > application is and how much of the Qt library it uses. > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > > From aktests at gmail.com Mon Jan 19 16:48:25 2009 From: aktests at gmail.com (ak) Date: Mon, 19 Jan 2009 13:48:25 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: On Jan 19, 10:00?pm, ak wrote: > Hi everyone, > > I have a problem with urllib2 on this particular url, hosted on an > Oracle HTTP Server > > http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p... > > which gets 302 redirected tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html, > after setting a cookie through the Set-Cookie header field in the 302 > reply. This works fin with firefox. > > However, with urllib2 and the following code snippet, it doesn't work > > -------- > import cookiejar > import urllib2 > > cookiejar = cookielib.LWPCookieJar() > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html? > type=post&subtype=phone&null' > req = urllib2.Request(url, None) > s=opener.open(req) > -------- > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib/python2.5/urllib2.py", line 387, in open > ? ? response = meth(req, response) > ? File "/usr/lib/python2.5/urllib2.py", line 498, in http_response > ? ? 'http', request, response, code, msg, hdrs) > ? File "/usr/lib/python2.5/urllib2.py", line 419, in error > ? ? result = self._call_chain(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > ? ? result = func(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302 > ? ? return self.parent.open(new) > ? File "/usr/lib/python2.5/urllib2.py", line 381, in open > ? ? response = self._open(req, data) > ? File "/usr/lib/python2.5/urllib2.py", line 399, in _open > ? ? '_open', req) > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > ? ? result = func(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open > ? ? return self.do_open(httplib.HTTPSConnection, req) > ? File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open > ? ? r = h.getresponse() > ? File "/usr/lib/python2.5/httplib.py", line 928, in getresponse > ? ? response.begin() > ? File "/usr/lib/python2.5/httplib.py", line 385, in begin > ? ? version, status, reason = self._read_status() > ? File "/usr/lib/python2.5/httplib.py", line 349, in _read_status > ? ? raise BadStatusLine(line) > httplib.BadStatusLine > > Trying the redirected url directly doesn't work either (trying with > Firefox will give an HTML error page, as the cookie is not set yet, > but trying with urllib2 gives the same exception as previously, > whereas it should return the HTML error page) > This works correctly on other urls on this website (http(s)://www.orange.sk). > > Am I doing anything wrong or is this a bug in urllib2 ? > > -- ak Actually, I was wrong on the last point, this does *not* work on https://www.orange.sk (but does on http://www.orange.sk). IMHO, this means either urllib2 or the server misimplemented HTTPS. Here's some output with debuglevel=1 : >>> opener.open(urllib2.Request('http://www.orange.sk/', None, headers)) reply: 'HTTP/1.1 200 OK\r\n' header: Date: Mon, 19 Jan 2009 21:44:03 GMT header: Server: Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP- Server header: Set-Cookie: JSESSIONID=0a19055a30d630c427bda71d4e26a37ca604b9f590dc.e3eNaNiRah4Pe3aSch8Sc3yOc40; path=/web header: Expires: Mon, 19 Jan 2009 21:44:13 GMT header: Surrogate-Control: max-age="10" header: Content-Type: text/html; charset=ISO-8859-2 header: X-Cache: MISS from www.orange.sk header: Connection: close header: Transfer-Encoding: chunked > >>> opener.open(urllib2.Request('https://www.orange.sk/', None, headers)) reply: '' Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open r = h.getresponse() File "/usr/lib/python2.5/httplib.py", line 928, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 385, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 349, in _read_status raise BadStatusLine(line) httplib.BadStatusLine As you can see the reply from the server seems empty (which results in the BadStatusLine exception) Any help greatly appreciated. -- ak From tjreedy at udel.edu Mon Jan 19 17:03:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:03:32 -0500 Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: Alan G Isaac wrote: >> On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: >>> we are supposed to prefer No, no 'supposed to's. You are not even 'supposed to' like or use Python. (Unless, I supposed, an employer demands it. But that is another story.) Certainly, one is not 'supposed to' prefer the new to the carefully picked best use example of the old. Guido and some developers prefer the totality of uses cases and possibilities of .format to the same for % formatting. > On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote: >> Well, that second example certainly is a WTF. I think we are supposed >> to prefer: > >> '{0}{0}'.format('wtf?') >> to '%%s%s' % 'wtf?' % 'wtf?' > > But your replacement misses the point of the example, I read it the same way and has the same thought as Steven. Perhaps all the obviously angry 'wtf?'s distracted me. > which is that sequential formatting is often needed. > That is, you need to generate a format string from > a format string. More explicitly: > > '{{0}} {0}'.format('earlyinfo').format('lateinfo') > > '%%s %s' % 'earlyinfo' % 'lateinfo' This is what you should have written. Having never seen or done this, I first missed the doubled '%%' and read it as a syntax error. > I would like assurance that it is not deprecated. > Can you back that? If you claim something exists, you have the burden of proof. I have not seen 3.0 emit a % deprecation warning. Have you? Last I read, Guido *plans* to deprecate % formatting 'sometime'. Terry Jan Reedy From Graham.Dumpleton at gmail.com Mon Jan 19 17:06:28 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Mon, 19 Jan 2009 14:06:28 -0800 (PST) Subject: wsgi silently swallows errors References: Message-ID: <87971174-6cb0-4d53-8de7-3b1f919df7e6@a26g2000prf.googlegroups.com> On Jan 20, 8:03?am, Jean-Paul Calderone wrote: > On Mon, 19 Jan 2009 12:15:29 -0800, Ron Garret wrote: > >Consider the following wsgi app: > > >def application(env, start_response): > > ?start_response('200 OK',[('Content-type','text/plain')]) > > ?yield "hello" > > ?x=1/0 > > ?yield "world" > > >The result of this is that the web browser displays "hello" and an error > >message ends up in the web log. ?But there is no other indication that > >an error has occurred. > > >Is there any way to get WSGI to not silently swallow errors that occur > >after start_response has been called? > > WSGI is a specification, not a piece of software. ?The specification isn't > swallowing the error, some piece of software is. ?What WSGI container are > you using? Not Apache/mod_wsgi at least, as message would show in Apache error logs. [Tue Jan 20 09:03:19 2009] [info] [client ::1] mod_wsgi (pid=271, process='wsgi', application='dangermouse:8224|/wsgi/scripts/ swallow.py'): Loading WSGI script '/usr/local/wsgi/scripts/swallow.py' [Tue Jan 20 09:03:19 2009] [error] [client ::1] mod_wsgi (pid=271): Exception occurred processing WSGI script '/usr/local/wsgi/scripts/ swallow.py' [Tue Jan 20 09:03:19 2009] [error] [client ::1] Traceback (most recent call last) [Tue Jan 20 09:03:19 2009] [error] [client ::1] File "/usr/local/ wsgi/scripts/swallow.py", line 7, in application[Tue Jan 20 09:03:19 2009] [error] [client ::1] x=1/0 [Tue Jan 20 09:03:19 2009] [error] [client ::1] ZeroDivisionError: integer division or modulo by zero Would just need to make sure you look in the correct log if have virtual host specific error logs. Graham From tjreedy at udel.edu Mon Jan 19 17:25:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:25:01 -0500 Subject: Beginner Question In-Reply-To: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> References: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Message-ID: K-Dawg wrote: > I do no understand the underscore methods. Names of the form __xyx__ are defined by the language definition and recognized and used by the interpreter. See PythonLanguage / LexicalAnalysis / Identifiers / Reserved Most refer to methods, a few to other attributes. Modules may have several non-method attributes, such as '__builtins__', '__doc__', '__file__', '__name__', and '__package__'. The top-level module created when the interpreter starts is given the name '__main__'. If a module is imported, it __name__ is the import name. >>> __name__ '__main__' >>> import email >>> email.__name__ 'email' >>> email.__file__ 'C:\\Programs\\Python30\\lib\\email\\__init__.py' If email were run directly, its name would be __main__ while the __file__ would be the same. Most syntax operations have a corresponding special that implements the operation. This allows user-defined objects to fully participate in syntax operations on an equal basis with built-in objects. See PythonLanguage Manual / Data model / Special operations. From fairwinds.dp at gmail.com Mon Jan 19 17:29:14 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Mon, 19 Jan 2009 18:29:14 -0400 Subject: Ordering attributes for dynamically generated class In-Reply-To: References: Message-ID: Hi Aaron, this worked out fine. Using an ordered dict to subclass dict. Many thanks. David On Jan 18, 2009, at 11:57 AM, Aaron Brady wrote: > On Jan 18, 9:52 am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order >> the attributes for the generated class. Of course a dict is not going >> to maintain ordering. Is there any way to dynamically generate a >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, >> dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Mon Jan 19 17:37:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:37:53 -0500 Subject: tasklet library based on PEP 0342 In-Reply-To: References: Message-ID: charlie137 at gmail.com wrote: > Using new features of python generators, as described in PEP 0342, it > is possible to write some sort of "tasklets" in a maner very similar > to stackless python, but running on cpython. For example : > > @tasklet > def my_task(): > yield Timer(10) > yield "result" > > @tasklet > def other_task(): > result = yield my_task() > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > project for openmoko [0], there is also an other very similar > implementation from the kiwi project [1]. > > This kind of tool is very useful, but unfortunately there is no > standard library that would provide a unified way to use it > independently of the underlying event loop. > > Does someone know if a similar library could eventually be added into > python standard libraries ? Would it be accepted as a PEP ? Start by listing your module/library on http://pypi.python.org/pypi To ever get in the stdlib, it must be tested, used by several different people, the best of its type, and relative stable. From prologic at shortcircuit.net.au Mon Jan 19 17:39:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 08:39:51 +1000 Subject: function to find the modification date of the project In-Reply-To: <4974F43E.4020402@strout.net> References: <4974F43E.4020402@strout.net> Message-ID: On Tue, Jan 20, 2009 at 7:44 AM, Joe Strout wrote: > This isn't a question, but something I thought others may find useful (and > if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of our > app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python doesn't > really have a meaningful compile date. So, instead we're now displaying the > latest modification date of any .py file in the project. Here's the > function that finds that: You know you could just store a __version__ attribute in your main library (__init__.py). :) Normally in my project, this version string is stored in __version__.py in my library and fetched in by my library's __init__.py and setup.py for distribution. Works great :) cheers James From prologic at shortcircuit.net.au Mon Jan 19 17:43:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 08:43:49 +1000 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: On Tue, Jan 20, 2009 at 8:39 AM, James Mills wrote: > On Tue, Jan 20, 2009 at 7:44 AM, Joe Strout wrote: >> This isn't a question, but something I thought others may find useful (and >> if somebody can spot any errors with it, I'll be grateful). >> >> We had a case recently where the client was running an older version of our >> app, and didn't realize it. In other languages I've avoided this by >> displaying the compile date in the About box, but of course Python doesn't >> really have a meaningful compile date. So, instead we're now displaying the >> latest modification date of any .py file in the project. Here's the >> function that finds that: > > You know you could just store a __version__ > attribute in your main library (__init__.py). :) > > Normally in my project, this version string > is stored in __version__.py in my library and > fetched in by my library's __init__.py and setup.py > for distribution. Works great :) Also I'd like to point out that your method is not very reliable as the modification time of those files could change at any moment. Consider unix systems for instnace where you could do: touch * And poof, you're modification times are now the current time! Sorry for finding flaws in your approach! :) cheers James From google at mrabarnett.plus.com Mon Jan 19 17:50:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 22:50:30 +0000 Subject: function to find the modification date of the project In-Reply-To: <4974F43E.4020402@strout.net> References: <4974F43E.4020402@strout.net> Message-ID: <497503B6.7020507@mrabarnett.plus.com> Joe Strout wrote: > This isn't a question, but something I thought others may find useful > (and if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of > our app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python > doesn't really have a meaningful compile date. So, instead we're now > displaying the latest modification date of any .py file in the project. > Here's the function that finds that: > > > def lastModDate(): > "Get the latest modification date (as a string) of any .py file in > this project." > import os, time > latest = 0 > dir = os.path.dirname(__file__) > if dir == '': dir = '.' # HACK, but appears necessary > for fname in os.listdir(dir): > if fname.endswith('.py'): > modtime = os.stat(os.path.join(dir, fname)).st_mtime > if modtime > latest: latest = modtime > out = time.strftime('%Y-%m-%d', time.localtime(latest)) > return out > > > The intent of this code is to find any .py files in the same directory > as the module containing the above code, and return (as a date string in > SQL/ISO format) the latest modification date thereof. Then, this is > displayed to the user in the about box like so: > > dlg = wx.MessageDialog(self, > "etown unified database system\nRevision: %s" \ > % lastModDate(), > "About etown Central", wx.OK | wx.ICON_INFORMATION) > dlg.ShowModal() > dlg.Destroy() > > (That's wxPython, of course.) > > I haven't yet tested this in a packaged app or on Windows, but it seems > to work in our OS X test environment. > > One odd thing was the need to employ the HACK identified above, where if > __file__ happens to already be in the current directory, then > os.path.dirname of it returns the empty-string -- yet the empty-string > is not a valid argument to os.listdir(). Is there a better way to a > list of files in the same directory as a given file? > I tend to prefer: dir = os.path.dirname(sys.argv[0]) and: modtime = os.path.getmtime(os.path.join(dir, fname)) From georgegrimes at ti.com Mon Jan 19 17:50:43 2009 From: georgegrimes at ti.com (Grimes, George) Date: Mon, 19 Jan 2009 16:50:43 -0600 Subject: Problem with IDLE on windows XP Message-ID: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> I am trying to learn Python and I installed version 2.6 both at home and at work. At home, on Vista, everything works fine. At work, on XP, IDLE would not run. I uninstalled/reinstalled and got the same thing. My cursor changes to the wait symbol for a few seconds, then goes back to normal and ?.nothing. The Task Manager shows nothing. I uninstalled again, made sure all the files were deleted from the disk, used regedit to delte every registry entry that had python in it and tried version 3.0. Geuss, what? I still can?t run IDLE on XP? Is this a common problem? Or am I unique? Thanks, George George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell Failure is the opportunity to begin again, more intelligently. Henry Ford -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Mon Jan 19 18:19:39 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 16:19:39 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: <49750A8B.5090106@strout.net> James Mills wrote: > You know you could just store a __version__ > attribute in your main library (__init__.py). :) What, and update it manually? I don't trust myself to remember to do that every time! Best, - Joe From joe at strout.net Mon Jan 19 18:20:36 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 16:20:36 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: <49750AC4.9050709@strout.net> James Mills wrote: > Also I'd like to point out that your method is not > very reliable as the modification time of those > files could change at any moment. Consider > unix systems for instnace where you could do: > > touch * > > And poof, you're modification times are now > the current time! Yes, and presumably if some power user did this, then that would be the intended effect. Not sure why they'd do that, but they must have a good reason -- who am I to stop them? Cheers, - Joe From tjreedy at udel.edu Mon Jan 19 18:27:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 18:27:21 -0500 Subject: python resource management In-Reply-To: References: Message-ID: S.Selvam Siva wrote: > Hi all, > > I am running a python script which parses nearly 22,000 html files > locally stored using BeautifulSoup. > The problem is the memory usage linearly increases as the files are > being parsed. > When the script has crossed parsing 200 files or so, it consumes all the > available RAM and The CPU usage comes down to 0% (may be due to > excessive paging). I have to guess that you are somehow holding on to data associated with each file. > We tried 'del soup_object' and used 'gc.collect()'. But, no improvement. 'del ob' only deletes the association between name 'ob' and the object it was associated with. The object itself cannot disappear until all associations are gone. gc.collect only deletes circularly associated objects that collectively are isolated. From prologic at shortcircuit.net.au Mon Jan 19 18:28:01 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 09:28:01 +1000 Subject: function to find the modification date of the project In-Reply-To: <49750A8B.5090106@strout.net> References: <4974F43E.4020402@strout.net> <49750A8B.5090106@strout.net> Message-ID: On Tue, Jan 20, 2009 at 9:19 AM, Joe Strout wrote: > James Mills wrote: > >> You know you could just store a __version__ >> attribute in your main library (__init__.py). :) > > What, and update it manually? I don't trust myself to remember to do that > every time! If you read my post carefully you'll have seen that I in fact do not update it manually. It's updated when I do: $ python setup.py sdist or bdist or bdist_egg cheers James From prologic at shortcircuit.net.au Mon Jan 19 18:32:21 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 09:32:21 +1000 Subject: function to find the modification date of the project In-Reply-To: <49750AC4.9050709@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: On Tue, Jan 20, 2009 at 9:20 AM, Joe Strout wrote: > Yes, and presumably if some power user did this, then that would be the > intended effect. Not sure why they'd do that, but they must have a good > reason -- who am I to stop them? Actually I'm fairly certain there -could- potentially be tools out there that would inadvertantly do this :) Who knows! :) Anyway, thanks for sharing your code. Though I'd take MRAB's suggestion and try to simplify your function :) Less is more! cheers James From ppearson at nowhere.invalid Mon Jan 19 18:57:04 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 19 Jan 2009 23:57:04 GMT Subject: ossaudiodev problem: sawtooth noise Message-ID: <6tkiagFaplkjU1@mid.individual.net> The following code uses ossaudiodev to read 1000 values from my sound card at a rate of 12,000 samples per second: *********** begin code *********** import ossaudiodev as o import struct d = o.open( "r" ) _, _, _ = d.setparameters( o.AFMT_S16_LE, 1, # channels 12000, # samples/s True ) # strict n_samples = 1000 bytes = d.read( 2 * n_samples ) for x in struct.unpack( "<%dh" % n_samples, bytes ): print( "%d" % x ) d.close() ************* end code ************ When I select a sample rate that is not a power of 2 times 3000 samples/second, a strong and very regular sawtooth is superimposed on the signal. At some sampling frequencies, it appears as a rising sawtooth, and at other sampling frequencies it is a declining sawtooth, so I'm presumably lost in some aliasing wilderness. As best I can tell, it's a 48 KHz sawtooth. Am I doing something wrong? Is ossaudiodev the wrong choice for capturing sound-card data? Thanks for any helpful comments. -- To email me, substitute nowhere->spamcop, invalid->net. From tjreedy at udel.edu Mon Jan 19 19:02:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 19:02:10 -0500 Subject: function to find the modification date of the project In-Reply-To: <49750AC4.9050709@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: Joe Strout wrote: > James Mills wrote: > >> Also I'd like to point out that your method is not >> very reliable as the modification time of those >> files could change at any moment. Consider >> unix systems for instnace where you could do: >> >> touch * >> >> And poof, you're modification times are now >> the current time! > > Yes, and presumably if some power user did this, then that would be the > intended effect. Not sure why they'd do that, but they must have a good > reason -- who am I to stop them? What if a curious user simple looks at a file with an editor and saves it without change? Or changes it inconsequentially? Or makes copy to x.py.orig, edits and plays with original, and when done renames x.py.orig to x.py. Or any such thing (which I have done in Pythonxy/Lib) without any intention of changing version date? From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 19:07:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 00:07:35 GMT Subject: function to find the modification date of the project References: <4974F43E.4020402@strout.net> Message-ID: On Mon, 19 Jan 2009 16:19:39 -0700, Joe Strout wrote: > James Mills wrote: > >> You know you could just store a __version__ attribute in your main >> library (__init__.py). :) > > What, and update it manually? I don't trust myself to remember to do > that every time! Presumably you have some sort of procedure for releasing software, ("Does it pass all the unit tests? Website updated? Okay, now ship it!"). Perhaps what you need is to add to that procedure a unit test that you run before each release (but not during development) which fails if you haven't updated the version number. Also you should consider submitting a feature request for listdir() to accept the empty string as equivalent to '.'. -- Steven From astan.chee at al.com.au Mon Jan 19 19:08:45 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 20 Jan 2009 11:08:45 +1100 Subject: defining class functions Message-ID: <4975160D.4080208@al.com.au> Hi, I have two classes in python that are in two different files/python scripts. Class A uses Class B like this: class B(object): def function1(self,something): pass def function2(self,something): print "hello one" print something class A(object): def __init__(self): instance = B() instance.function2("hello two") self.function3() def function3(self): print "hello three" What I want to do here is to (re)define function1 from function3. Is that possible? Is there any way of redefining a function of another class without inheriting it? Does this make sense? Thanks Astan From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 19:14:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 00:14:28 GMT Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote: > Hi everyone, > > I have a problem with urllib2 on this particular url, hosted on an > Oracle HTTP Server > > http://www.orange.sk/eshop/sk/portal/catalog.html? type=post&subtype=phone&null > > which gets 302 redirected to > https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a > cookie through the Set-Cookie header field in the 302 reply. This works > fin with firefox. > > However, with urllib2 and the following code snippet, it doesn't work Looking at the BadStatusLine exception raised, the server response line is empty. Looking at the source for httpllib suggests to me that the server closed the connection early. Perhaps it doesn't like connections from urllib2? I ran a test pretending to be IE using this code: cookiejar = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?' \ 'type=post&subtype=phone&null' agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; " \ "NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" headers = {'User-Agent': agent} req = urllib2.Request(url, data=None, headers=headers) try: s=opener.open(req) except httplib.BadStatusLine, e: print e, e.line else: print "Success" but it failed. So the problem is not as simple as changing the user-agent string. Other than that, I'm stumped. -- Steven From vivacarlie at gmail.com Mon Jan 19 19:28:24 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Mon, 19 Jan 2009 18:28:24 -0600 Subject: ifconfig in python Message-ID: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Is ther an easy way to get the resolved ip address of the machine a script is running on? socket.gethostbyname(socket.gethostname) has only returned the ip address of my loop back interface ... not very usefull. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Mon Jan 19 19:29:23 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 20 Jan 2009 01:29:23 +0100 Subject: wsgi silently swallows errors References: Message-ID: <3gif46-h2h.ln1@archaeopteryx.softver.org.mk> > Consider the following wsgi app: > > def application(env, start_response): > start_response('200 OK',[('Content-type','text/plain')]) > yield "hello" > x=1/0 > yield "world" > > The result of this is that the web browser displays "hello" and an > error > message ends up in the web log. But there is no other indication that > an error has occurred. > > Is there any way to get WSGI to not silently swallow errors that occur > after start_response has been called? yes, you can wrap your app in a WebError middleware http://pypi.python.org/pypi/WebError from weberror.evalexception import EvalException application = EvalException(application) -- ?????? ( http://softver.org.mk/damjan/ ) In theory, there is no difference between theory and practice. But, in practice, there is. From prologic at shortcircuit.net.au Mon Jan 19 19:31:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 10:31:58 +1000 Subject: defining class functions In-Reply-To: <4975160D.4080208@al.com.au> References: <4975160D.4080208@al.com.au> Message-ID: On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee wrote: > Hi, > I have two classes in python that are in two different files/python scripts. > Class A uses Class B like this: > class B(object): > def function1(self,something): > pass > def function2(self,something): > print "hello one" > print something > > class A(object): > def __init__(self): > instance = B() > instance.function2("hello two") > self.function3() > def function3(self): > print "hello three" def function3(self): print "hello three" self.instance.function1 = lambda x; x But you must bind instnace to self in B Modify your __init__ as follows: class A(object): def __init__(self): self.instance = B() self.instance.function2("hello two") self.function3() What's the use-case anyway ? There might be a better way to solve your problem :) cheers James From vivacarlie at gmail.com Mon Jan 19 19:33:27 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Mon, 19 Jan 2009 18:33:27 -0600 Subject: defining class functions In-Reply-To: References: <4975160D.4080208@al.com.au> Message-ID: <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> wouldn't you use a state change? Use a variable to indicate which function you want the first class to do On Mon, Jan 19, 2009 at 6:31 PM, James Mills wrote: > On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee wrote: > > Hi, > > I have two classes in python that are in two different files/python > scripts. > > Class A uses Class B like this: > > class B(object): > > def function1(self,something): > > pass > > def function2(self,something): > > print "hello one" > > print something > > > > class A(object): > > def __init__(self): > > instance = B() > > instance.function2("hello two") > > self.function3() > > def function3(self): > > print "hello three" > > def function3(self): > print "hello three" > self.instance.function1 = lambda x; x > > But you must bind instnace to self in B > > Modify your __init__ as follows: > > class A(object): > def __init__(self): > self.instance = B() > self.instance.function2("hello two") > self.function3() > > What's the use-case anyway ? > There might be a better way to solve your problem :) > > cheers > James > -- > http://mail.python.org/mailman/listinfo/python-list > -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 19:34:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 10:34:04 +1000 Subject: ifconfig in python In-Reply-To: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres wrote: > Is ther an easy way to get the resolved ip address of the machine a script > is running on? socket.gethostbyname(socket.gethostname) has only returned > the ip address of my loop back interface ... not very usefull. That's because your /etc/hosts resolves your hostname to 127.0.0.1 :) And no I know of no "easy" way cross platform way. Perhaps parsing the output of ifconfig itself ? cheers James From jstroud at mbi.ucla.edu Mon Jan 19 19:34:09 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 19 Jan 2009 16:34:09 -0800 Subject: defining class functions In-Reply-To: References: Message-ID: Astan Chee wrote: > Hi, > I have two classes in python that are in two different files/python > scripts. Class A uses Class B like this: > class B(object): > def function1(self,something): > pass > def function2(self,something): > print "hello one" > print something > > class A(object): > def __init__(self): > instance = B() > instance.function2("hello two") > self.function3() > def function3(self): > print "hello three" > > What I want to do here is to (re)define function1 from function3. Is > that possible? Is there any way of redefining a function of another > class without inheriting it? Does this make sense? I know what you mean, but it doesn't make a lot of sense. Best practice is to make the function module level, especially if self is not referenced beyond the function definition. If self is referenced, then all selves must share the same behavior if not the same heredity, and using a module level function is still best: def function(quacker): print "hello there" quacker.quack() James From astan.chee at al.com.au Mon Jan 19 19:36:03 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 20 Jan 2009 11:36:03 +1100 Subject: defining class functions In-Reply-To: <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> References: <4975160D.4080208@al.com.au> <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> Message-ID: <49751C73.6020502@al.com.au> Actually, yes, I just realized a better way of doing this without state change based on the requirement. Thanks for the info anyway Nehemiah Dacres wrote: > wouldn't you use a state change? Use a variable to indicate which > function you want the first class to do > > On Mon, Jan 19, 2009 at 6:31 PM, James Mills > > > wrote: > > On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee > wrote: > > Hi, > > I have two classes in python that are in two different > files/python scripts. > > Class A uses Class B like this: > > class B(object): > > def function1(self,something): > > pass > > def function2(self,something): > > print "hello one" > > print something > > > > class A(object): > > def __init__(self): > > instance = B() > > instance.function2("hello two") > > self.function3() > > def function3(self): > > print "hello three" > > def function3(self): > print "hello three" > self.instance.function1 = lambda x; x > > But you must bind instnace to self in B > > Modify your __init__ as follows: > > class A(object): > def __init__(self): > self.instance = B() > self.instance.function2("hello two") > self.function3() > > What's the use-case anyway ? > There might be a better way to solve your problem :) > > cheers > James > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > > "lalalalala! it's not broken because I can use it" > > http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jan 19 19:45:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 16:45:17 -0800 Subject: Logging help In-Reply-To: References: Message-ID: <50697b2c0901191645x4cff58b9nf9d506eb2bdc9752@mail.gmail.com> On Mon, Jan 19, 2009 at 11:36 AM, koranthala wrote: > Hi, > Is it possible somehow to have the logging module rotate the files > every time I start it. > Basically, I can automatically rotate using RotatingFileHandler; > Now I want it rotated every time I start the program too. Just call the .doRollover() method of the RotatingFileHandler at the start of the program. Reading The Fine Documentation for the module is helpful. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rhodri at wildebst.demon.co.uk Mon Jan 19 19:49:13 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 00:49:13 -0000 Subject: reading file to list In-Reply-To: <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> Message-ID: On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: > On Jan 17, 10:25 am, Tino Wildenhain wrote: >> > [[int(x) for x in line.split()] for line in open("blob.txt")] > > Nice (python code). > > Few comments: > > ? the above code is borderline of atypical. e.g. it is not a average > python code would produce or one'd seen in corporate python code. I can't imagine why not. It's clean and clear, after all. If I needed to do the slightly odd processing that it's written to do, the only change I'd make for production code is to wrap the file object in a 'with' statement. > ? voodoo like the above makes me dislike python. To me, the one > advantage of python is its clarity enforced by its syntax. > Specifically, the forced indendation and quite simple semantics. > However, the way i've seen Guido's propensities and how python 3 is > moving to, it is becoming more mumbo jumbo of computer sciency OOP > jargons with syntax soup. (with iterators, enumerators, list > comprehension... shits forced upon the users) > > The above line illustrate well the ad hoc syntax soup nature python is > moving into. To a native English speaker, it illustrates entirely the reverse. List comprehension is actually quite a linguistically natural way to express the iterative construction of a list. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Mon Jan 19 19:53:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 00:53:09 -0000 Subject: A java hobbyist programmer learning python In-Reply-To: <0182896d$0$8693$c3e8da3@news.astraweb.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 02:24:51 -0000, Steven D'Aprano wrote: > Let me re-write your code in a more Pythonic way. This is not the only > way to do this, and it probably isn't the best way, but it may give you a > flavour for the way Python is usually written. > > > import sys > import operator > class Calculator(): > dispatch = { # dispatch table mapping symbol to function > '+': operator.add, > '-': operator.sub, > '*': operator.mul, > '/': operator.truediv, > } > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = int(sys.argv[2]) > self.arg2 = int(sys.argv[3]) If you want the test code to work, I think you mean: def __init__(self, op, arg1, arg2): self.operator = op self.arg1 = arg1 self.arg2 = arg2 :) -- Rhodri James *-* Wildebeeste Herder to the Masses From Scott.Daniels at Acm.Org Mon Jan 19 19:59:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 16:59:47 -0800 Subject: function to find the modification date of the project In-Reply-To: References: Message-ID: <3JednQbu9NAtvOjUnZ2dnUVZ_hudnZ2d@pdx.net> Joe Strout wrote: > This isn't a question, but something I thought others may find useful > (and if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of > our app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python > doesn't really have a meaningful compile date. So, instead we're now > displaying the latest modification date of any .py file in the project. > Here's the function that finds that: > > > def lastModDate(): > "Get the latest modification date (as a string) of any .py file in > this project." > import os, time > latest = 0 > dir = os.path.dirname(__file__) > if dir == '': dir = '.' # HACK, but appears necessary > for fname in os.listdir(dir): > if fname.endswith('.py'): > modtime = os.stat(os.path.join(dir, fname)).st_mtime > if modtime > latest: latest = modtime > out = time.strftime('%Y-%m-%d', time.localtime(latest)) > return out Here's how I'd do it with your specs: def lastModDate(directory=None): "Latest modification ISO date string of .py files in this directory" import os, time latest = 0 if directory is None: directory = os.path.dirname(__file__) for fname in os.listdir(directory or '.'): if fname.endswith('.py'): modtime = os.stat(os.path.join(directory, fname)).st_mtime if modtime > latest: latest = modtime return time.strftime('%Y-%m-%d', time.localtime(latest)) And I'd prefer: def lastPyDate(directory=None): "Latest modification ISO date string of .py files in this file tree" import os, time latest = 0 if directory is None: directory = os.path.dirname(__file__) for base, dirs, files in os.walk(directory): for name in files: if name.endswith('.py'): modtime = os.stat(os.path.join(base, name)).st_mtime if modtime > latest: latest = modtime return time.strftime('%Y-%m-%d', time.localtime(latest)) But, as someone mentioned, if one of your users edits one of your files without changing it, he has accidentally changed the version of the code. This you could forestall by invoking your function at packaging time, and writing a file with the version string in it. --Scott David Daniels Scott.Daniels at Acm.Org From kyrie at uh.cu Mon Jan 19 20:09:40 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 20:09:40 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232413780.497524545347c@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 7:13?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > > > I must be missing the point : if it's a public attribute, it doesn't > > need a "property" ? I guess we use the same words for different things > here. > > Yes, you are missing more than one point. > > Scala automatically converts public data members into properties, > apparently to save the programmer the trouble of doing it manually. If > you are interested, I'm sure you can find publicly available > information on it. Russ, I think _you_ are missing the point. If the attribute is already public, why does it need properties? Why would a programmer go to the trouble of adding them manually, just to get one level of indirection for an already public attribute? > > I definitively wouldn't bet my ass on language-level access restriction > > to protect software from fraud or sabotage. > > You're missing the point here too. I'll try one more time to explain > it. And I think you are conflating the idea of "private" as in "secret information that should not be known by the _public_" and "private" as in "static safeguards enforced by the compiler to prevent accidents" [and you are missing the third, "compiler feature to prevent namespace pollution without having to use extremely unlikely variable names", i.e, self.__x in python]. No wonder you can't get Bruno's point. For the second, static checks to prevent accidents, you have pylint. For the first, not only you are using the wrong tool, but you are barking at python for not having it. Assuming that pylint is perfect (big assumption, but it is up to you to prove where it fails), what would be the difference between only accepting/running "pylint-authorized code" and the enforced hiding you desire? This thread is starting to remind me of a professor of mine, who once claimed that python didn't have private attributes because it "is opensource and anyone can see the source code anyway", and the obvious confusion of his students ("why should I make my entrypoint '_public_ static void main', if it is _my_ sourcecode and I don't want to share it?"). What you want is not enforced data hiding. You want something actually designed to try to prevent abuses from hostile programmers - go use .Net or Java, who attempt to do that (I don't know with what level of success, but they at least provide you the 'locks' and 'police' that you need). Or better yet, write a proposal about how to implement code trust in Python. I'll support you on that one, and I think many others will. But if you keep presenting data hiding as a solution to that problem... I doubt that you will be heard. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From spoofy1 at gmx.net Mon Jan 19 20:15:47 2009 From: spoofy1 at gmx.net (Spoofy) Date: Tue, 20 Jan 2009 02:15:47 +0100 Subject: Two questions about style and some simple math Message-ID: <497525C3.5090904@gmx.net> Hello everybody! Though I'm a hobby programmer for years now (mainly small hackery things) I still have big problems getting "real" things to work. I'm currently trying to write a simple RPG and have problems with the following: 1. Characters have a "courage" attribute that basically determins who has the first attack in a fight. After some trying, I came up with this (sorry, not really working code, but what I made from interactive experimentation): def first_attack(player1, player2): diff = player1.attributes.courage - player2.attributes.courage players = (player, player2) return players[diff + random.randint(-diff, diff) < 0] To make it more realistic, I randomized it a little bit and this seems to work for low courage values. But when the courage values are high (100 and such) it fails (the chance to have the first attack drops the higher the values are). My math is really bad and I have problems to understand what's happenning here. I suspect the greater range for randint() is the problem, but I don't really get why. Any tips would be greatly appreciated. 2. For maintaining the character attributes I creates a seperate class. I wonder weather this is an "overuse" of OO (instead of just making the attributes plain variables of the Char class) and if the way I wrote this is OK (somehow this looks cool to me but maybe too "showy"?) class Attributes(object): ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": 0, "condition": 0} def __init__(self, **kwargs): self.__dict__.update(self.ATTRIBUTES) for arg in kwargs: if arg not in self.ATTRIBUTES: raise ValueError("Unkown character attribute '%s'" % arg) self.__dict__[arg] = kwargs[arg] Again, I appreciate any tips. I you need more code (for the bigger picture or such), just ask. Thanks in advance From rhodri at wildebst.demon.co.uk Mon Jan 19 20:44:44 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 01:44:44 -0000 Subject: Two questions about style and some simple math In-Reply-To: <497525C3.5090904@gmx.net> References: <497525C3.5090904@gmx.net> Message-ID: On Tue, 20 Jan 2009 01:15:47 -0000, Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with the > following: > > 1. > > Characters have a "courage" attribute that basically determins who has > the first attack in a fight. After some trying, I came up with this > (sorry, not really working code, but what I made from interactive > experimentation): > > def first_attack(player1, player2): > diff = player1.attributes.courage - player2.attributes.courage > players = (player, player2) > return players[diff + random.randint(-diff, diff) < 0] > > To make it more realistic, I randomized it a little bit and this seems > to work for low courage values. But when the courage values are high > (100 and such) it fails (the chance to have the first attack drops the > higher the values are). My math is really bad and I have problems to > understand what's happenning here. I suspect the greater range for > randint() is the problem, but I don't really get why. > > Any tips would be greatly appreciated. This is always going to select player1 (assuming you fix the typo of "player" for "player1"!). The most negative number that the call to randint can produce is "-diff", so "diff + randint()" is at least "diff + -diff", which is zero and hence never less than zero. Surely in any case you don't want an expression based on the difference, since that would give you the same chance of having the first attack no matter what the levels of courage actually were, which can't be right. > 2. > > For maintaining the character attributes I creates a seperate class. I > wonder weather this is an "overuse" of OO (instead of just making the > attributes plain variables of the Char class) and if the way I wrote > this is OK (somehow this looks cool to me but maybe too "showy"?) > > class Attributes(object): > ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": > 0, "condition": 0} > def __init__(self, **kwargs): > self.__dict__.update(self.ATTRIBUTES) > for arg in kwargs: > if arg not in self.ATTRIBUTES: > raise ValueError("Unkown character attribute '%s'" % > arg) > self.__dict__[arg] = kwargs[arg] It's not necessarily a bad idea to have your character attributes in a separate class, but do you really need to prevent use of other class attribute names (sorry, the terminology crossover is inherently confusing) so much? Unless you think there's a serious danger of trying to add new character attributes on the fly, I think it's overkill. -- Rhodri James *-* Wildebeeste Herder to the Masses From google at mrabarnett.plus.com Mon Jan 19 20:54:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 01:54:01 +0000 Subject: Two questions about style and some simple math In-Reply-To: <497525C3.5090904@gmx.net> References: <497525C3.5090904@gmx.net> Message-ID: <49752EB9.1050600@mrabarnett.plus.com> Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with the > following: > > 1. > > Characters have a "courage" attribute that basically determins who has > the first attack in a fight. After some trying, I came up with this > (sorry, not really working code, but what I made from interactive > experimentation): > > def first_attack(player1, player2): > diff = player1.attributes.courage - player2.attributes.courage > players = (player, player2) > return players[diff + random.randint(-diff, diff) < 0] > > To make it more realistic, I randomized it a little bit and this seems > to work for low courage values. But when the courage values are high > (100 and such) it fails (the chance to have the first attack drops the > higher the values are). My math is really bad and I have problems to > understand what's happenning here. I suspect the greater range for > randint() is the problem, but I don't really get why. > > Any tips would be greatly appreciated. > [snip] Try: def first_attack(player1, player2): total_courage = player1.attributes.courage + player2.attributes.courage players = (player, player2) return players[random.randrange(0, total_courage) < player1.attributes.courage] From gert.cuykens at gmail.com Mon Jan 19 20:54:07 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 19 Jan 2009 17:54:07 -0800 (PST) Subject: s=str(binary) Message-ID: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> How do you convert s back to binary data in python 3 so I can put in a sqlite blob ? Is there a build in function or do I need to use binascii ? byte(s) or bin(s) would make more sense but can not figure it out ? From Russ.Paielli at gmail.com Mon Jan 19 21:07:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 18:07:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > Russ, I think _you_ are missing the point. > If the attribute is already public, why does it need properties? Why would a > programmer go to the trouble of adding them manually, just to get one level of > indirection for an already public attribute? You don't understand the purpose of properties -- and you tell me that *I* am the one missing the point? I give up. I really don't have time for this. From mensanator at aol.com Mon Jan 19 21:11:24 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 19 Jan 2009 18:11:24 -0800 (PST) Subject: Two questions about style and some simple math References: <497525C3.5090904@gmx.net> Message-ID: <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> On Jan 19, 7:44?pm, "Rhodri James" wrote: > On Tue, 20 Jan 2009 01:15:47 -0000, Spoofy wrote: > > Hello everybody! > > > Though I'm a hobby programmer for years now (mainly small hackery ? > > things) I still have big problems getting "real" things to work. > > > I'm currently trying to write a simple RPG and have problems with the ? > > following: > > > 1. > > > Characters have a "courage" attribute that basically determins who has ? > > the first attack in a fight. After some trying, I came up with this ? > > (sorry, not really working code, but what I made from interactive ? > > experimentation): > > > def first_attack(player1, ?player2): > > ? ? ?diff = player1.attributes.courage - player2.attributes.courage > > ? ? ?players = (player, ?player2) > > ? ? ?return players[diff + random.randint(-diff, ?diff) < 0] > > > To make it more realistic, I randomized it a little bit and this seems ? > > to work for low courage values. But when the courage values are high ? > > (100 and such) it fails (the chance to have the first attack drops the ? > > higher the values are). My math is really bad and I have problems to ? > > understand what's happenning here. I suspect the greater range for ? > > randint() is the problem, but I don't really get why. > > > Any tips would be greatly appreciated. > > This is always going to select player1 (assuming you fix the typo of > "player" for "player1"!). ?The most negative number that the call to > randint can produce is "-diff", so "diff + randint()" is at least > "diff + -diff", which is zero and hence never less than zero. > > Surely in any case you don't want an expression based on the difference, > since that would give you the same chance of having the first attack no > matter what the levels of courage actually were, which can't be right. Why? Isn't it possible some attributes are relative rather than absolute? > > > > > > > 2. > > > For maintaining the character attributes I creates a seperate class. I ? > > wonder weather this is an "overuse" of OO (instead of just making the ? > > attributes plain variables of the Char class) and if the way I wrote ? > > this is OK (somehow this looks cool to me but maybe too "showy"?) > > > class Attributes(object): > > ? ? ?ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": ? > > 0, "condition": 0} > > ? ? ?def __init__(self, **kwargs): > > ? ? ? ? ?self.__dict__.update(self.ATTRIBUTES) > > ? ? ? ? ?for arg in kwargs: > > ? ? ? ? ? ? ?if arg not in self.ATTRIBUTES: > > ? ? ? ? ? ? ? ? ?raise ValueError("Unkown character attribute '%s'" % ? > > arg) > > ? ? ? ? ? ? ?self.__dict__[arg] = kwargs[arg] > > It's not necessarily a bad idea to have your character attributes in a > separate class, but do you really need to prevent use of other class > attribute names (sorry, the terminology crossover is inherently > confusing) so much? ?Unless you think there's a serious danger of > trying to add new character attributes on the fly, I think it's > overkill. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From bblais at bryant.edu Mon Jan 19 21:15:15 2009 From: bblais at bryant.edu (Brian Blais) Date: Mon, 19 Jan 2009 21:15:15 -0500 Subject: modify IDLE? Message-ID: <733F256C-0D97-4CCD-A83B-64F6EB88B7CE@bryant.edu> Hello, I was wondering if there is a simple way to modify IDLE, adding or replacing menus? I haven't dug into the source code yet, but was wondering if anyone else has done something like this. I have a couple of projects that require users to write python code (or very similar to python code) which is then run either in a completely different interpreter, or pre-processed and run. Right now, I just make those programs load files, but it would be nice if somehow a version of IDLE could pass the current buffer to my program instead of the built-in interpreter. Is mucking around with the IDLE code something easy, or a bit of a challenge? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 21:24:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 12:24:26 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Tue, Jan 20, 2009 at 12:07 PM, Russ P. wrote: >> Russ, I think _you_ are missing the point. >> If the attribute is already public, why does it need properties? Why would a >> programmer go to the trouble of adding them manually, just to get one level of >> indirection for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? Russ, he is correct. Your opinions are not founded on solid knowledge. Python programmers tend to not have a need for properties. Quite honestly they are a waste of time. They come from traditional OO approaches to software design (and mostly from the Java world). > I give up. I really don't have time for this. You've said that before :) cheers James From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 21:24:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 02:24:28 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > >> Russ, I think _you_ are missing the point. If the attribute is already >> public, why does it need properties? Why would a programmer go to the >> trouble of adding them manually, just to get one level of indirection >> for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea Russ is proposing. But I must admit it's not clear to me why Russ thinks it is a good idea to automatically turn this: class Parrot(object): def __init__(self): self.x = 1 into this: class Parrot(object): def __init__(self): self._x = 1 def getx(self): return self._x def setx(self, value): self._x = value x = property(getx, setx) Because frankly, that's how I read Russ' explanation for what Scala is doing. Have I missed something? -- Steven From mdw at distorted.org.uk Mon Jan 19 21:32:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 02:32:28 +0000 Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > There's a practical reason too. You create a new Foo instance, mutate > it with the augmented assignment operator, and then a tenth of a > millisecond later the garbage collector throws it away because it has > a reference count of zero. Only in this specific example. A function can easily return a well-known object, which it's sensible to mutate. Besides, class mumble (object): pass mumble().foo = 1 is accepted without fuss, and is just as useless. I think I see the confusion here. * Python assignment (`=') is fairly simple. The left-hand side is analyzed syntactically: if it's a plain name then the variable it denotes is modified; otherwise an appropriate method is invoked to mutate some object. * Python augmented-assignment (`+=', for example) is inconsistent. Depending on what type of object the left-hand side evaluates to, it may /either/ mutate that object, /or/ assign a new value to the expression. What do I mean? Well, consider this function. def assg(x, y): x = y Under no circumstances does calling this function have any effect (other than wasting time and memory). But: def aug(x, y): x += y Calling this function might or might not have an observable effect, depending on the type of x. For example, x = 5 aug(x, 3) is useless, but x = [1, 2, 3] aug(x, [4]) is not. The `aug' function can be used to bypass the syntactic restriction on augmented assignment, where it makes sense: aug(func(), 17) is always syntactically valid, and may or may not be useless depending on the type of thing returned by `func'. The Python language refuses to let the programmer write something which is (a) possibly meaningful, and (b) possibly useful because augmented assignment inherits the syntactic restriction of simple assignment that the left-hand side expression designate a `place' -- i.e., one of the things that there's a rule for assigning to, e.g., VAR, EXPR[INDEX], EXPR.ID -- because it /might/ need to perform such an assignment, though it might not. My personal view is that augmented-assignment operators which work by mutation rather than assignment (e.g., `+=' on lists, rather than `+=' on numbers) are one of Python's least pleasant warts. But if they're going to exist then I think list() += [1] ought to be valid syntax, since semantically it's actually clear what it should do (namely, construct a fresh empty list, append a `1' to it, and then throw the whole thing away). Of course, tuple() += 1, is still meaningless, and ought to be an error. Of course, this removes a static error-check, but if we were petty about getting all our errors at compile time we wouldn't be writing in Python in the first place. -- [mdw] From narkewoody at gmail.com Mon Jan 19 21:33:21 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 20 Jan 2009 10:33:21 +0800 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> References: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> Message-ID: On Tue, Jan 20, 2009 at 1:03 AM, BlueBird wrote: > On Jan 19, 4:10 am, Steven Woody wrote: >> Hi, >> >> Python has Signal-Slot mechanism, > > Python does not have signal/slot mechanism. You are talking about the > Qt toolkit, which is initially a (nice) C++ toolkit, available also in > python via the PyQt wrapper. > > Signal/slots were introduced by Qt to make C++ gui programming easier. > Signal/slots basically provides a very easy way to implement the > observer/consumer design pattern, with only 2 or 3 lines of code (as > opposed to one or two classes in java for example). > > Python itself does not have signal/slots but the it's very easy to > emulate them using the Python language. In C++ however, it's tricky to > do signal/slots in pure C++ and this addition is one of the reason > that programming GUI in Qt is nice (personal opinion obviously). > > To comne back to your question: > >> why he still need another mechanism >> Event Handling? > > This is actually a Qt question: why have event handling for some > things, and signal/slot for some others ? > > My opinion on the debate: > - signal/slot add an overhead of one class to every QObject class, and > 3 method calls when emitting a signal (if I remember Qt documentation > correctly). For some real-time tasks, like repainting the screen, > every microseconds must be saved and sparing 3 method calls is a good > idea. > - since a GUI application is fundamentally an event driven system, the > event stuff has to be there anyway. > - signal/slot is very convenient for data exchange between widgets but > I think it would be overkill to use it everywhere. Event propagation > is a nice design as well. > > Now, if you want to discuss this further, I suggest to go to Qt > interest ( http://lists.trolltech.com/qt-interest/ ) which is > dedicated to discussion around Qt. > > cheers, > > Philippe > -- > http://mail.python.org/mailman/listinfo/python-list > So much thanks, Philippe! From Russ.Paielli at gmail.com Mon Jan 19 21:46:29 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 18:46:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> On Jan 19, 6:24?pm, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > >> Russ, I think _you_ are missing the point. If the attribute is already > >> public, why does it need properties? Why would a programmer go to the > >> trouble of adding them manually, just to get one level of indirection > >> for an already public attribute? > > > You don't understand the purpose of properties -- and you tell me that > > *I* am the one missing the point? > > Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > Russ is proposing. But I must admit it's not clear to me why Russ thinks > it is a good idea to automatically turn this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self.x = 1 > > into this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self._x = 1 > ? ? def getx(self): > ? ? ? ? return self._x > ? ? def setx(self, value): > ? ? ? ? self._x = value > ? ? x = property(getx, setx) > > Because frankly, that's how I read Russ' explanation for what Scala is > doing. Have I missed something? > > -- > Steven From sjmachin at lexicon.net Mon Jan 19 21:46:43 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 18:46:43 -0800 (PST) Subject: Two questions about style and some simple math References: Message-ID: On Jan 20, 12:15?pm, Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with > the following: > > 1. > > Characters have a "courage" attribute that basically determins who > has the first attack in a fight. After some trying, I came up with > this (sorry, not really working code, but what I made from > interactive experimentation): > > def first_attack(player1, ?player2): > ? ? ?diff = player1.attributes.courage - player2.attributes.courage > ? ? ?players = (player, ?player2) > ? ? ?return players[diff + random.randint(-diff, ?diff) < 0] > > To make it more realistic, I randomized it a little bit and this > seems to work for low courage values. But when the courage values > are high (100 and such) it fails (the chance to have the first > attack drops the higher the values are). My math is really bad and I > have problems to understand what's happenning here. I suspect the > greater range for randint() is the problem, but I don't really get why. Are you 100% sure that the above code is what you have been running? For a start, the result of that code depends only on "diff" which is the difference between the two courages -- it should not be influenced by whether the courages are (say) about 10 or about 100. If player1 is more aggro than player2, then diff will be positive. Let's say it's 20. The lowest possible value returned by random.randint (-20, 20) will be -20. Then 20 + (-20) is zero. so 0 < 0 is False, and player 1 will always be chosen. This happens for any positive value of diff, even 1. If the diff is zero, then again you get 0 < 0, and player1 will always be chosen. If the diff is negative, the world blows up; for diff == -10, you get this: ValueError: empty range for randrange() (10,-9, -19) I think that you need to take the range of the courage values into account. You need to scale the randomisation so that you get believable outcomes. If the players have equal courage, there should be a 50% chance that player2 hits first. If one has maximal courage and the other has zero, then the maximal one should have 100% chance of hitting first. For example: >>> def choosep2(diff, maxc): ... assert abs(diff) <= maxc ... return random.randint(-maxc, maxc-1) >= diff ... >>> def simulate(diff, maxc): ... return sum(choosep2(diff, maxc) for _ in range(100)) ... >>> simulate(0, 50) 50 >>> simulate(0, 50) 47 >>> simulate(0, 50) 43 >>> simulate(49, 50) 1 >>> simulate(-49, 50) 100 >>> You may want to choose a probability distribution that's a bit more bell-shaped than roadkill-shaped, but whatever you do you should check that it's behaving plausibly. HTH, John From nad at acm.org Mon Jan 19 21:48:45 2009 From: nad at acm.org (Ned Deily) Date: Mon, 19 Jan 2009 18:48:45 -0800 Subject: ifconfig in python References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: In article , "James Mills" wrote: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres > wrote: > > Is ther an easy way to get the resolved ip address of the machine a script > > is running on? socket.gethostbyname(socket.gethostname) has only returned > > the ip address of my loop back interface ... not very usefull. > > That's because your /etc/hosts resolves > your hostname to 127.0.0.1 :) > > And no I know of no "easy" way cross > platform way. Perhaps parsing the output > of ifconfig itself ? Also, since the subject is on my brain at the moment, how to find "the address" is not the right question to ask. These days most systems have multiple network interfaces (Ethernet, WiFi, dialup, et al) running multiple protocols, like IPv4 and IPv6. In general, there is no *one* IP address of a machine; often there are many. Ignoring that fact can lead to subtle bugs, like the one causing a urllib2 regression test failure that I've been squashing today! -- Ned Deily, nad at acm.org From mdw at distorted.org.uk Mon Jan 19 21:50:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 02:50:28 +0000 Subject: ifconfig in python References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: <87d4ein11n.fsf.mdw@metalzone.distorted.org.uk> "James Mills" writes: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres wrote: >> Is ther an easy way to get the resolved ip address of the machine a >> script is running on? socket.gethostbyname(socket.gethostname) has >> only returned the ip address of my loop back interface ... not very >> usefull. > > That's because your /etc/hosts resolves your hostname to 127.0.0.1 :) This just illustrates the real problem with the OP's question. The idea of `/the/ ... ip address of the machine' is simply ill-formed. An Internet host has at least two IP addresses -- one of them is 127.0.0.1 -- and may have many more. The laptop I'm typing on right now has three; the server next door has four. Network interfaces may have multiple addresses associated with them (and hosts using the weak end-system model consider the addresses as referring to the host in general rather than a specific interface anyway), and several interfaces might have the same address. Sorry. Life's more complicated than you'd like it to be. -- [mdw] From prologic at shortcircuit.net.au Mon Jan 19 21:53:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 12:53:58 +1000 Subject: ifconfig in python In-Reply-To: References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: On Tue, Jan 20, 2009 at 12:48 PM, Ned Deily wrote: > Also, since the subject is on my brain at the moment, how to find "the > address" is not the right question to ask. These days most systems have > multiple network interfaces (Ethernet, WiFi, dialup, et al) running > multiple protocols, like IPv4 and IPv6. In general, there is no *one* > IP address of a machine; often there are many. Ignoring that fact can > lead to subtle bugs, like the one causing a urllib2 regression test > failure that I've been squashing today! I agree. Nehemiah: What is the problem you're solving ? cheers James From charlie137 at gmail.com Mon Jan 19 21:57:54 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 18:57:54 -0800 (PST) Subject: tasklet library based on PEP 0342 References: Message-ID: <836b31a3-f70a-4739-a8e0-3dc948138d57@w1g2000prm.googlegroups.com> On Jan 20, 6:37?am, Terry Reedy wrote: > charlie137 at gmail.com wrote: > > Using new features of python generators, as described in PEP 0342, it > > is possible to write some sort of "tasklets" in a maner very similar > > to stackless python, but running on cpython. For example : > > > @tasklet > > def my_task(): > > ? ? yield Timer(10) > > ? ? yield "result" > > > @tasklet > > def other_task(): > > ? ? result = yield my_task() > > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > > project for openmoko [0], there is also an other very similar > > implementation from the kiwi project [1]. > > > This kind of tool is very useful, but unfortunately there is no > > standard library that would provide a unified way to use it > > independently of the underlying event loop. > > > Does someone know if a similar library could eventually be added into > > python standard libraries ? Would it be accepted as a PEP ? > > Start by listing your module/library onhttp://pypi.python.org/pypi > To ever get in the stdlib, it must be tested, used by several different > people, the best of its type, and relative stable. I am afraid my implementation passes none of those requirement. I will send a message to the python idea mailing list though. Thanks for the answers. Guillaume From charlie137 at gmail.com Mon Jan 19 21:57:54 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 18:57:54 -0800 (PST) Subject: tasklet library based on PEP 0342 References: Message-ID: <836b31a3-f70a-4739-a8e0-3dc948138d57@w1g2000prm.googlegroups.com> On Jan 20, 6:37?am, Terry Reedy wrote: > charlie137 at gmail.com wrote: > > Using new features of python generators, as described in PEP 0342, it > > is possible to write some sort of "tasklets" in a maner very similar > > to stackless python, but running on cpython. For example : > > > @tasklet > > def my_task(): > > ? ? yield Timer(10) > > ? ? yield "result" > > > @tasklet > > def other_task(): > > ? ? result = yield my_task() > > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > > project for openmoko [0], there is also an other very similar > > implementation from the kiwi project [1]. > > > This kind of tool is very useful, but unfortunately there is no > > standard library that would provide a unified way to use it > > independently of the underlying event loop. > > > Does someone know if a similar library could eventually be added into > > python standard libraries ? Would it be accepted as a PEP ? > > Start by listing your module/library onhttp://pypi.python.org/pypi > To ever get in the stdlib, it must be tested, used by several different > people, the best of its type, and relative stable. I am afraid my implementation passes none of those requirement. I will send a message to the python idea mailing list though. Thanks for the answers. Guillaume From Russ.Paielli at gmail.com Mon Jan 19 22:09:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 19:09:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 6:24?pm, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > >> Russ, I think _you_ are missing the point. If the attribute is already > >> public, why does it need properties? Why would a programmer go to the > >> trouble of adding them manually, just to get one level of indirection > >> for an already public attribute? > > > You don't understand the purpose of properties -- and you tell me that > > *I* am the one missing the point? > > Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > Russ is proposing. But I must admit it's not clear to me why Russ thinks > it is a good idea to automatically turn this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self.x = 1 > > into this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self._x = 1 > ? ? def getx(self): > ? ? ? ? return self._x > ? ? def setx(self, value): > ? ? ? ? self._x = value > ? ? x = property(getx, setx) > > Because frankly, that's how I read Russ' explanation for what Scala is > doing. Have I missed something? > > -- > Steven Whoops, I accidentally hit send on the last post. One of the main benefits of properties is that they allow you to more safely put attributes in the public interface. If you later decide that the attribute shouldn't have been in the public interface, you can convert it to a property and make it do whatever you want it to do. That won't always save you, but sometimes it can. As a trivial example, suppose you have a circle class with public attributes of radius and area. You later realize that it is unwise to let the user change one without changing the other, leaving them inconsistent. With properties, you can convert them each to a property and write functions to force consistency. The benefit of automatically converting public data into properties, I assume, is to relieve the programmer of doing it manually. The programmer will obviously need to add any functionality when needed, but he does not need to create the function header. I don't know the implications for efficiency in Scala. Perhaps there is a slight cost for one level of indirection. But please recall that public data is supposed to be rarely if ever used anyway. Unlike some folks here, the Scala folks understand the value of encapsulation and data hiding. From catphive at catphive.net Mon Jan 19 22:11:16 2009 From: catphive at catphive.net (Brendan Miller) Date: Mon, 19 Jan 2009 19:11:16 -0800 Subject: pep 8 constants In-Reply-To: References: Message-ID: > Constants would be a nice addition in python, sure enough. My original question was about PEP-8 and whether it is pythonic to use all caps to denote a variable that shouldn't be changed. More of a style question than a language question. I actually think *enforcing* constantness seems to go against the grain of the language so to speek From Russ.Paielli at gmail.com Mon Jan 19 22:20:48 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 19:20:48 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> On Jan 19, 6:24?pm, "James Mills" wrote: > Python programmers tend to not have a need for > properties. Quite honestly they are a waste of time. > They come from traditional OO approaches to software design > (and mostly from the Java world). With statements like that, it's no wonder you don't understand the value of encapsulation. With encapsulation (whether enforced or voluntary), no one has the "need" for properties. You can always just provide functions to do the same job. What properties do is to essentially make the function call simpler for the client. The client just sets the radius of the circle, and, lo and behold, the area gets changed automatically and consistently. If you didn't plan ahead and encapsulate the radius from the start, properties allow you to save yourself and encapsulate it later without breaking the client's code. From joe at strout.net Mon Jan 19 22:22:55 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 20:22:55 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: <4975438F.2030807@strout.net> Terry Reedy wrote: >> Yes, and presumably if some power user did this, then that would be >> the intended effect. Not sure why they'd do that, but they must have >> a good reason -- who am I to stop them? > > What if a curious user simple looks at a file with an editor and saves > it without change? You can't do that, on the Mac at least... > Or changes it inconsequentially? Or makes copy to > x.py.orig, edits and plays with original, and when done renames > x.py.orig to x.py. Or any such thing (which I have done in > Pythonxy/Lib) without any intention of changing version date? Then the About box will show, quite correctly, that the app was mucked with at that date, and when they call me up and complain, and I ask them to read me the contents of the About box, I can know right away that they've probably broken something (no matter how inconsequential they believed their change to be), and tell them to re-download it. But really, this is NOT going to happen. These users wouldn't even know how to open the app bundle to find the Python files. Any comments on the functioning and platform-independence of the code? Thanks, - Joe From prologic at shortcircuit.net.au Mon Jan 19 22:33:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 13:33:26 +1000 Subject: function to find the modification date of the project In-Reply-To: <4975438F.2030807@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> <4975438F.2030807@strout.net> Message-ID: On Tue, Jan 20, 2009 at 1:22 PM, Joe Strout wrote: > Any comments on the functioning and platform-independence of the code? Make it simpler :) cheers James From xahlee at gmail.com Mon Jan 19 22:39:45 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 19 Jan 2009 19:39:45 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> Message-ID: <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> On Jan 19, 4:49 pm, "Rhodri James" wrote: > On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: > > On Jan 17, 10:25 am, Tino Wildenhain wrote: > >> > [[int(x) for x in line.split()] for line in open("blob.txt")] > > > Nice (python code). > > > Few comments: > > > ? the above code is borderline of atypical. e.g. it is not a average > > python code would produce or one'd seen in corporate python code. > > I can't imagine why not. consider code produced by corporations, as opposed to with respect to some academic or philsophical logical analysis. Looked in another way, consider if we can compile stat of all existing pyhton code used in real world, you'll find the above style is rarely used. in a logical analysis, each lang fanatics will actively sell certain style of construction, but that's just not the way code in the real world are. Ample examples can be found especially in other cultish lang groups such as lisp, perl, etc. (less of this phenomenon is found in lang like php, javascript, java, C, where the lang simple don't create fancy constructions in the name of improvement or esthetics or weird philosophy in the first place.) > > ? voodoo like the above makes me dislike python. To me, the one > > advantage of python is its clarity enforced by its syntax. > > Specifically, the forced indendation and quite simple semantics. > > However, the way i've seen Guido's propensities and how python 3 is > > moving to, it is becoming more mumbo jumbo of computer sciency OOP > > jargons with syntax soup. (with iterators, enumerators, list > > comprehension... shits forced upon the users) > > > The above line illustrate well the ad hoc syntax soup nature python is > > moving into. > > To a native English speaker, it illustrates entirely the reverse. > List comprehension is actually quite a linguistically natural way > to express the iterative construction of a list. computer lang is not human lang. In argument based on human lang, you have AppleScript, Perl, which are un-readable or cumbersome to most programers. Even with human lang, if you know linguistics to some extend, you know that natural lang is a complete wortheless mess in every aspect with respect to ?design? qualities. Xah ? http://xahlee.org/ ? From gdamjan at gmail.com Mon Jan 19 22:42:51 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 20 Jan 2009 04:42:51 +0100 Subject: ifconfig in python Message-ID: Something *like* this could work: myip = urllib2.urlopen('http://whatismyip.org/').read() of course then you are depending on an external service, not a very reliable one even. But then again, you might create an internal service like that yourself. This cgi-bin shell code like this for ex: #! /bin/sh echo "Content-type: text/plain" echo echo "${REMOTE_ADDR}" -- ?????? ( http://softver.org.mk/damjan/ ) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From david.lyon at preisshare.net Mon Jan 19 22:44:11 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Mon, 19 Jan 2009 22:44:11 -0500 Subject: Does Python really follow its philosophy of "Readability =?UTF-8?Q?counts=22=3F?= In-Reply-To: <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: <09d32dbdf3dadfcb857594807a0bdc94@preisshare.net> >> Because frankly, that's how I read Russ' explanation for what Scala is >> doing. Have I missed something? coz he gets paid per line of code.... it's a mindless way of getting paid more for the same functionality... >> Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea >> Russ is proposing. But I must admit it's not clear to me why Russ thinks >> it is a good idea to automatically turn this: >> >> class Parrot(object): >> ? ? def __init__(self): >> ? ? ? ? self.x = 1 >> >> into this: >> >> class Parrot(object): >> ? ? def __init__(self): >> ? ? ? ? self._x = 1 >> ? ? def getx(self): >> ? ? ? ? return self._x >> ? ? def setx(self, value): >> ? ? ? ? self._x = value >> ? ? x = property(getx, setx) >> From timr at probo.com Mon Jan 19 22:56:49 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 20 Jan 2009 03:56:49 GMT Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: <2rian4t2il6n64jp35l3is1laosd0n19ro@4ax.com> "Brendan Miller" wrote: > >Yes, I also recently noticed the bug in python's parser that doesn't >let it handle squigly braces and the bug in the lexer that makes white >space significant. I'm surprised the dev's haven't noticed this yet. It's very dangerous to make a post like this without including the smiley. You're likely to get a mailbox full of "helpful" corrections... ;) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From catphive at catphive.net Mon Jan 19 23:00:15 2009 From: catphive at catphive.net (Brendan Miller) Date: Mon, 19 Jan 2009 20:00:15 -0800 Subject: what's the point of rpython? In-Reply-To: <7x8wp86plv.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: Maybe I'm missing something here but a lock free algorithm for reference counting seems pretty trivial. As long as you can atomically increment and decrement an integer without locking you are pretty much done. For a reference implementation of lock free reference counting on all common platforms check out boosts implementation of shared_ptr (a reference counting smart pointer designed around multithreaded use cases). >There are well known concurrent and parallel GC techniques that Hmm... I didn't really mention poor parallelism as a problem of GC. As I see it the two trade offs that have to be made for GC vs alternative techniques. The "embarrassing pause" during compaction which makes it impossible to use for applications like interactive video display that can't halt to compact a several gigabyte heap without causing stutter, and the loose memory profile. Maybe the document you sent me addresses those, and I'd be interested if it did. It's 150~ pages though so I haven't really had time to read it yet. As far as parallelism problems with GC go... the only ones I can imagine is that if you had a lot of threads going generating lots of garbage you would need to start to compact more frequently. Since compaction halts all threads, this could potentially cause very frequent compactions? Is that what you were getting at? I'd wondered about that before, but didn't know for a fact whether it came up in real world scenarios. From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 23:03:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 04:03:05 GMT Subject: pep 8 constants References: Message-ID: On Mon, 19 Jan 2009 19:11:16 -0800, Brendan Miller wrote: >> Constants would be a nice addition in python, sure enough. > > My original question was about PEP-8 and whether it is pythonic to use > all caps to denote a variable that shouldn't be changed. More of a style > question than a language question. > > I actually think *enforcing* constantness seems to go against the grain > of the language so to speek Why? Python has an infinite number of constants. The only difference is that they are immutable objects, not names. But regardless... yes, it is in my opinion Pythonic to use ALLCAPS to designate constants (by convention). It isn't in PEP 8, but I don't think that matters unless PEP 8 suggests a different convention. -- Steven From Russ.Paielli at gmail.com Mon Jan 19 23:05:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:05:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: On Jan 19, 7:44?pm, wrote: > >> Because frankly, that's how I read Russ' explanation for what Scala is > >> doing. Have I missed something? > > coz he gets paid per line of code.... > > it's a mindless way of getting paid more for the same functionality... > > >> Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > >> Russ is proposing. But I must admit it's not clear to me why Russ thinks > >> it is a good idea to automatically turn this: > > >> class Parrot(object): > >> ? ? def __init__(self): > >> ? ? ? ? self.x = 1 > > >> into this: > > >> class Parrot(object): > >> ? ? def __init__(self): > >> ? ? ? ? self._x = 1 > >> ? ? def getx(self): > >> ? ? ? ? return self._x > >> ? ? def setx(self, value): > >> ? ? ? ? self._x = value > >> ? ? x = property(getx, setx) > > Why did you email your post to me? Did you really think I wanted to see it in my inbox? I assure you I did not. And who "gets paid per line of code"? The whole point is that Scala saves the programmer the trouble of writing that boilerplate code that Java programmers write themselves, genius. From kyrie at uh.cu Mon Jan 19 23:13:18 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:13:18 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232424798.49754f5e43123@mail.uh.cu> Quoting "Russ P." : > One of the main benefits of properties is that they allow you to more > safely put attributes in the public interface. If you later decide > that the attribute shouldn't have been in the public interface, you > can convert it to a property and make it do whatever you want it to > do. That won't always save you, but sometimes it can. That's true in Java, and python pre-'descriptor protocol'. It boggles me when I see python code with properties that only set and get the attribute, or even worse, getters and setters for that purpose. In my university they teach the students to write properties for the attributes in C# ("never make a public attribute, always write a public property that just gets and sets it"). I never understood that practice either, given that the syntax for attribute access and property access in C# is exactly the same. (Could it be that even if the syntax is the same, the compiled code differs? Don't know enough about .NET to answer that). I think I'm getting offtopic now. I better leave :D [snip the rest of the email, as I agree with it] -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From Russ.Paielli at gmail.com Mon Jan 19 23:16:07 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:16:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 7:09?pm, "Russ P." wrote: > The benefit of automatically converting public data into properties, I > assume, is to relieve the programmer of doing it manually. The > programmer will obviously need to add any functionality when needed, > but he does not need to create the function header. Let me just correct this. As I said before, I haven't yet even used Scala. The automatic generation of properties for public data members is done automatically by the compiler and is apparently transparent to the programmer. The programmer can then override the default properties if he needs to add functionality. As far as the programmer is concerned, this is really no different than Python properties. The only difference is the way the two languages implement properties, not the way they are used. From kyrie at uh.cu Mon Jan 19 23:17:59 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:17:59 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> Message-ID: <1232425079.497550775c63e@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 6:24?pm, "James Mills" > wrote: > > > Python programmers tend to not have a need for > > properties. Quite honestly they are a waste of time. > > They come from traditional OO approaches to software design > > (and mostly from the Java world). > > With statements like that, it's no wonder you don't understand the > value of encapsulation. > [snip] > > If you didn't plan ahead and encapsulate the radius from the start, > properties allow you to save yourself and encapsulate it later without > breaking the client's code. Python programmers don't _need_ to plan ahead and encapsulate the radius from the start. That's the whole point. No clairvoyance needed. I kind of like that. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From http Mon Jan 19 23:19:26 2009 From: http (Paul Rubin) Date: 19 Jan 2009 20:19:26 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <7x3afewqwh.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. What cpu's do you know of that can atomically increment and decrement integers without locking? From sjmachin at lexicon.net Mon Jan 19 23:23:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 20:23:38 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> Message-ID: <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> On Jan 20, 12:54?pm, gert wrote: > How do you convert s back to binary data in python 3 so I can put in a > sqlite blob ? > Is there a build in function or do I need to use binascii ? > byte(s) or bin(s) would make more sense but can not figure it out ? Can't imagine why you would do str(binary_data) especially if you want it back again ... however: According to the fabulous manual: str([object[, encoding[, errors]]]) Return a string version of an object, using one of the following modes: [snip] When only object is given, this returns its nicely printable representation. For strings, this is the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. Hmm looks like (1) we need to do the dreaded eval() and (2) there's no guarantee it will work. >>> for i in range(256): ... blob = bytes([i]) ... if eval(str(blob)) != blob: ... print(i, blob, str(blob), eval(str(blob))) ... >>> # no complaints! Looks like it's going to work, but you better be rather sure that you trust the source. HTH, John From kyrie at uh.cu Mon Jan 19 23:27:37 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:27:37 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1232425079.497550775c63e@mail.uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> <1232425079.497550775c63e@mail.uh.cu> Message-ID: <1232425657.497552b99d176@mail.uh.cu> Quoting Luis Zarrabeitia : > > Quoting "Russ P." : > > > On Jan 19, 6:24?pm, "James Mills" > > wrote: > > > > > Python programmers tend to not have a need for > > > properties. Quite honestly they are a waste of time. > > > They come from traditional OO approaches to software design > > > (and mostly from the Java world). > > > > With statements like that, it's no wonder you don't understand the > > value of encapsulation. > > > [snip] > > > > If you didn't plan ahead and encapsulate the radius from the start, > > properties allow you to save yourself and encapsulate it later without > > breaking the client's code. > > Python programmers don't _need_ to plan ahead and encapsulate the radius > from > the start. That's the whole point. No clairvoyance needed. I kind of like > that. Oops. I didn't noticed we were agreeing on this last point. Bad english... bad... [btw, I highly doubt James doesn't understand the value of encapsulation. Don't you mean "enforced data hiding" again?] Cya! -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From pavlovevidence at gmail.com Mon Jan 19 23:27:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 19 Jan 2009 20:27:51 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> On Jan 19, 8:00?pm, "Brendan Miller" wrote: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. You're missing that most of the platforms that Python supports can't actually do this. Keep in mind that it has to be atomic across all cores. (For Python to use such a technique, it would have to be doable on every platform Python supports. They aren't going to get rid of the GIL for some platforms and not others.) > For a reference implementation of lock free reference counting on all > common platforms check out boosts implementation of shared_ptr (a > reference counting smart pointer designed around multithreaded use > cases). I just looked at the boost documentation, which claims that multiple asynchronous writes to the same shared_ptr results in undefined behavior. That will not suffice for Python reference counting. Carl Banks From Russ.Paielli at gmail.com Mon Jan 19 23:28:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:28:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> Message-ID: <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> On Jan 19, 8:17?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > > > > > On Jan 19, 6:24?pm, "James Mills" > > wrote: > > > > Python programmers tend to not have a need for > > > properties. Quite honestly they are a waste of time. > > > They come from traditional OO approaches to software design > > > (and mostly from the Java world). > > > With statements like that, it's no wonder you don't understand the > > value of encapsulation. > > [snip] > > > If you didn't plan ahead and encapsulate the radius from the start, > > properties allow you to save yourself and encapsulate it later without > > breaking the client's code. > > Python programmers don't _need_ to plan ahead and encapsulate the radius from > the start. That's the whole point. No clairvoyance needed. I kind of like that. And I like it too. I was trying to explain that to Mr. Mills, who claimed that properties are "a waste of time." Properties reduce the need for encapsulation, but they do not eliminate it, particularly for large projects. In the circle example, properties are nice for guaranteeing consistency between the radius and the area, but they are not of much use if you decide later that the client should not be allowed to change either one. Well... I suppose you could define the setter to do nothing ... but you had better figure a way to notify the client about it. From http Mon Jan 19 23:31:36 2009 From: http (Paul Rubin) Date: 19 Jan 2009 20:31:36 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <7xbpu238ev.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > As long as you can atomically increment and decrement an integer > without locking you are pretty much done. Most cpu's can't do that. > For a reference implementation of lock free reference counting on all > common platforms check out boosts implementation of shared_ptr (a > reference counting smart pointer designed around multithreaded use > cases). That sounds very mysterious to me--are you sure it is intended for multiprocessing and not just multiple threads on a single processor? Do you have a url for the code? > I see it the two trade offs that have to be made for GC vs alternative > techniques. The "embarrassing pause" during compaction which makes it > impossible to use for applications like interactive video display that > can't halt to compact a several gigabyte heap without causing stutter, > and the loose memory profile. The embarassing pause is characteristic of a so-called "stop the world" gc. A gc where any pauses are guaranteed bounded in size (preferably to a small value) is called a "real time" gc. I believe Cheng's algorithm is a real time alg but it's been a while since I read that thesis. Anyway, nobody programs interactive video in Python, and Python's ref counting scheme is not real time since it may have to do arbitrarily many decrefs when you release a large structure. > As far as parallelism problems with GC go... the only ones I can > imagine is that if you had a lot of threads going generating lots of > garbage you would need to start to compact more frequently. Since > compaction halts all threads, this could potentially cause very > frequent compactions? Is that what you were getting at? I'm not sure what you're asking. Parallelism is used for making things go faster, but making things parallel usually complicates them. A parallel realtime gc is sort of the holy grail. Cheng's thesis is pretty readable as I remember, and discusses most of these issues. There is also a book by Appel about gc, but it's perhaps a little bit dated by now. From kyrie at uh.cu Mon Jan 19 23:32:47 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:32:47 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: <1232425967.497553efe235d@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 7:44?pm, wrote: > > [removing david's message] > > > Why did you email your post to me? Did you really think I wanted to > see it in my inbox? I assure you I did not. Don't get mad at him... and don't take it personal. The reply-to header of this mailing list (usenet users: for some of us, this is only a mailing list, and can't hope for more) points to the sender, and not the list. Many believe it is the right thing to do, but if your mailer doesn't have a 'reply to list' function, like the one I'm using right now (Horde/Imp), your only option is to reply-to-all and then delete the original sender. I can't blame anyone for forgetting about the last part. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Mon Jan 19 23:39:16 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:39:16 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232426356.49755574d7d65@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > > Russ, I think _you_ are missing the point. > > If the attribute is already public, why does it need properties? Why would > a > > programmer go to the trouble of adding them manually, just to get one level > of > > indirection for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? This line would make a lot more sense if you were talking about Java's getters and setters, or about a language where accessing a property is different than accessing an attribute (which would make little sense). If properties already let you change from attribute to method without affecting the caller, why do you need a property that does nothing? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Mon Jan 19 23:57:46 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:57:46 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> Message-ID: <1232427466.497559cabf8f3@mail.uh.cu> Quoting "Russ P." : > In the circle example, properties are nice for guaranteeing > consistency between the radius and the area, but they are not of much > use if you decide later that the client should not be allowed to > change either one. Well... I suppose you could define the setter to do > nothing ... but you had better figure a way to notify the client about > it. Well, you could make it raise an exception. There was one C#1.0 class that did this, Liskov substitution principle be damned (it was for a subtype). Very frustrating. Once you decide for a public interface, you shouldn't change it... But, if you absolutely have to do it, complain loudly and as soon as possible. In python, I'd say that [a subclass of?] AttributeError would be the best solution for this ill-advised situation. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From bignose+hates-spam at benfinney.id.au Mon Jan 19 23:58:30 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 20 Jan 2009 15:58:30 +1100 Subject: pep 8 constants References: Message-ID: <87fxje4lqh.fsf@benfinney.id.au> Steven D'Aprano writes: > But regardless... yes, it is in my opinion Pythonic to use ALLCAPS > to designate constants (by convention). I agree, in general. Though I think I can count the number of times I've wanted to use an ?UPPER_CASE?-named constant in my code, on the fingers of one foot. > It isn't in PEP 8, but I don't think that matters unless PEP 8 > suggests a different convention. It does recommend a contradictory convention: Global Variable Names (Let's hope that these variables are meant for use inside one module only.) The conventions are about the same as those for functions. The conventions for functions are the familiar ?lower_case? conventions. This directly contradicts using ?UPPER_CASE? names. Unless someone's going to argue that ?Variable Names? doesn't apply to constant names, even though Python doesn't make the distinction. That said, I think upper-case name is a useful convention to distinguish ?this name binding is never expected to change? from the common case, and wouldn't argue against its use. Perhaps I'd even argue for an update to PEP 8 that endorses this as conventional. -- \ ?I was born by Caesarian section. But not so you'd notice. It's | `\ just that when I leave a house, I go out through the window.? | _o__) ?Steven Wright | Ben Finney From prologic at shortcircuit.net.au Tue Jan 20 00:04:34 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 15:04:34 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1232426356.49755574d7d65@mail.uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <1232426356.49755574d7d65@mail.uh.cu> Message-ID: On Tue, Jan 20, 2009 at 2:39 PM, Luis Zarrabeitia wrote: > This line would make a lot more sense if you were talking about Java's getters > and setters, or about a language where accessing a property is different than > accessing an attribute (which would make little sense). If properties already > let you change from attribute to method without affecting the caller, why do you > need a property that does nothing? My point exactly. Russ seems to agree with Python but yet argue points for the sake of it. I'm not sure why :) Having come from all kinda of programming backgrounds and paradigms you learn to see the value in Python and the kind of simplicity it has to offer. I will stand by my view that there are many features of the traditional, strict and academic features of the OO model that have little practical value. Python is a great mix of functional features, OO features and has borrowed (what I believe) are the best of breed features from all around. One thing I find quite amazing is that we're having a discussion over such low-level features of the OO model (and functional paradigm) and how Python fits into it all ... And for what exactly ? Russ - what is your point in all of this - You keep saying you don't have time to waste with this - yet you keep making this thread grow longer and longer and longer :) As far as I'm concerned properties are just fancy functions to retrieve and set attributes of an object. Consider the following equivalent pieces of code: #!/usr/bin/env python from math import pi class CircleA(object): def __init__(self, radius): self._radius = radius self._area = pi * radius ** 2 def __getRadius(self): return self._radius def __setRadius(self, radius): self._radius = radius self._area = pi * radius ** 2 def __getArea(self): return self._area def __repr__(self): return "" % (self.radius, self.area) radius = property(__getRadius, __setRadius) area = property(__getArea) class CircleB(object): def __init__(self, radius): self.radius = radius self.area = pi * radius ** 2 def setRadius(self, radius): self.radius = radius self.area = pi * radius ** 2 def __repr__(self): return "" % (self.radius, self.area) a = CircleA(1.5) print a a.radius = 2.0 print a b = CircleB(1.5) print b b.radius = 2.0 print b ---------- http://codepad.org/tpyGNhrZ I'll give you a hint which one I prefer :) cheers James From http Tue Jan 20 00:04:52 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:04:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhmsh3f.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > Luis Zarrabeitia writes: > > > You *can* implement a metaclass that will remove the dynasmism from its > > > instances.... > import inspect > class ImmutableType(type): ... Thanks for posting this, I haven't replied because I bookmarked the post for later study, but that was several days ago, so I just wanted to say that I'm still looking at it. It's an area of Python that I've somewhat purposely stayed away from. > But I see no _necessary_ harm on tacking extra attributes to an > existing object - specially if you are going to use them pretty > close to the creation. > I use them, a lot, specially when writing decorators... Many times I > just want to 'mark' the decorated functions so I can inspect those > marks later. I'd rather have a semi-private namespace for each pair > ([group of]calling function[s], object), Right, thus the usefulness of a static tool that can find all those places where extra attributes are created. Basically I can see three approaches to this question: 1) Program in a style where you create and modify attributes all over the place willy-nilly, with no controls whatsoever, either automatic or stylistic. From experience (it is a common style in Javascript) I can say this is a big mess and I think no experienced Python programmers recommend it. 2) Have mandatory encapsulation like Java's, no way to escape. Bruno and yourself vehemently object to this, Russ P seems to want it, my view is that it's not in the Python spirit, so I can accept the argument that those who really want this are better off choosing another language. 3) Program in a style where creating new attributes outside the initializer is normally avoided by convention, but it is possible and sometimes desirable to break the convention. This seems reasonable and Pythonic to me. But, any place I break the convention, I should be able to say "I broke the convention here for such and such a reason". And (this seems to be a bone of contention) IMO, it would be good to be able to audit a large codebase with a tool like Pylint, to automatically find all the places where such breakages occur. Right now there seems to be no way to do that reliably, short of using something like your special metaclass instead of the standard one for just about everything. Your example about decorators (used on classes that don't expect to be wrapped by them) is a good one but narrow enough that there could be a special arrangement for it in a hypothetical auditing tool. From Russ.Paielli at gmail.com Tue Jan 20 00:12:08 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 21:12:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <2e6c6820-0529-4e72-855b-3dd522d9cd4f@r41g2000prr.googlegroups.com> On Jan 19, 8:39?pm, Luis Zarrabeitia wrote: > If properties already > let you change from attribute to method without affecting the caller, why do you > need a property that does nothing? You don't. As I tried to explain in a earlier post (but one that you may not have seen yet), that is apparently an implementation detail of the way Scala implements properties. I probably should have never even brought it up. From Russ.Paielli at gmail.com Tue Jan 20 00:17:19 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 21:17:19 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: On Jan 19, 8:32?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > On Jan 19, 7:44?pm, wrote: > > > [removing david's message] > > > Why did you email your post to me? Did you really think I wanted to > > see it in my inbox? I assure you I did not. > > Don't get mad at him... and don't take it personal. The reply-to header of this > mailing list (usenet users: for some of us, this is only a mailing list, and > can't hope for more) points to the sender, and not the list. Many believe it is > the right thing to do, but if your mailer doesn't have a 'reply to list' > function, like the one I'm using right now (Horde/Imp), your only option is to > reply-to-all and then delete the original sender. I can't blame anyone for > forgetting about the last part. You're right. I shouldn't have gotten mad at him. I took his post as a jab at me, but after thinking about it I realized it probably wasn't. My apologies. From http Tue Jan 20 00:21:51 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:21:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> Message-ID: <7xiqoatuvk.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > The failure was because a module tested, QA'd and certified within a > given context (in which it was ok to drop the builtin error handling) > was reused in a context where it was not ok. And the point is exactly > that : no *technology* can solve this kind of problem, because it is a > *human* problem (in that case, not taking time to repass the whole > specs / tests / QA process given context change). In this case it does nothing at all to support your arguments about the helpfulness or lack of helpfulness of strong encapsulation. You may as well say that antibiotics are medically useless because they won't stop anyone from getting killed by a falling piano. From banibrata.dutta at gmail.com Tue Jan 20 00:44:55 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 20 Jan 2009 11:14:55 +0530 Subject: *Advanced* Python book? In-Reply-To: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> References: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> Message-ID: <3de8e1f70901192144q5b466c32sfd6f914d7daa8840@mail.gmail.com> 2009/1/17 Michele Simionato : > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 Excellent review. -- regards, Banibrata http://www.linkedin.com/in/bdutta From http Tue Jan 20 00:57:29 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:57:29 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> Message-ID: <7xfxjett86.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Take some not-that-trivial projects like Zope/Plone. There are quite a > few lines of code involved, and quite a lot of programmers worked on it. Zope is about 375 KLOC[1], which I agree is not trivial, but by today's standards, it's not all that large. Zope also has 275 open bugs, 6 of which are critical.[2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC in which only 3 errors have been found post-release.[3] I think "large software system" today means 100's of MLOC. FWIW, Zope has 20x as much code as Django--is that a good thing!? [1] http://www.peterbe.com/plog/size-Zope3,Django,TurboGears [2] https://bugs.launchpad.net/zope3 [3] http://haacked.com/archive/2006/10/20/The_Misuse_of_the_Space_Shuttle_Analogy.aspx#11147 From Russ.Paielli at gmail.com Tue Jan 20 01:00:47 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 22:00:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> Message-ID: <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> On Jan 19, 9:21?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > The failure was because a module tested, QA'd and certified within a > > given context (in which it was ok to drop the builtin error handling) > > was reused in a context where it was not ok. And the point is exactly > > that : no *technology* can solve this kind of problem, because it is a > > *human* problem (in that case, not taking time to repass the whole > > specs / tests / QA process given context change). > > In this case it does nothing at all to support your arguments about > the helpfulness or lack of helpfulness of strong encapsulation. ?You > may as well say that antibiotics are medically useless because they > won't stop anyone from getting killed by a falling piano. He says that "no *technology* can solve this kind of problem." First of all, I'm not sure that's true. I think technology *could* have solved the problem -- e.g., Spark Ada, had it been properly applied. But that's beside the point. The point is that the problem had nothing to do with encapsulation. The rocket failed because a conversion was attempted to a data type that could not hold the required value. Am I missing something? I don't see what that has to do with encapsulation. The logic seems to be as follows: 1. Ada enforces data hiding. 2. Ada was used. 2. A major failure occurred. Therefore: Enforced data hiding is useless. If that reasoning is sound, think about what else is useless. From kyrie at uh.cu Tue Jan 20 01:10:09 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 01:10:09 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmsh3f.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> <7xzlhmsh3f.fsf@ruckus.brouhaha.com> Message-ID: <1232431809.49756ac1bbffa@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Luis Zarrabeitia writes: > > > Luis Zarrabeitia writes: > > class ImmutableType(type): ... > > Thanks for posting this, I haven't replied because I bookmarked the > post for later study, but that was several days ago, so I just wanted > to say that I'm still looking at it. It's an area of Python that I've > somewhat purposely stayed away from. Hehe. Keep away - once you get dive into it, it'll be hard go get out. It's really addictive :D > > I use them, a lot, specially when writing decorators... Many times I > > just want to 'mark' the decorated functions so I can inspect those > > marks later. I'd rather have a semi-private namespace for each pair > > ([group of]calling function[s], object), > > Right, thus the usefulness of a static tool that can find all those > places where extra attributes are created. Basically I can see three > approaches to this question: Btw, this thread inspired me to do another proof-of-concept stuff that I may be using more seriously. Too bad I don't have anywhere to upload it right now... Anyway, it looks like this: suppose I need to attach some attributes to the object "x", but I don't want to do x.attr import namespaces # my module class my_private_namespace(namespaces.Namespace): pass def this_function_stores_the_attr(x): ns = my_private_namespace(x) ns.attr = 5 # I'm creating an attribute on the fly # but at least I'm not touching x. def this_function_reads_the_attr(x): ns = my_private_namespace(x) print ns.attr > 1) Program in a style where you create and modify attributes all over > the place willy-nilly, with no controls whatsoever, either automatic > or stylistic. From experience (it is a common style in Javascript) I > can say this is a big mess and I think no experienced Python > programmers recommend it. Indeed. Though I don't consider myself 'experienced', I certainly don't recommend it. > 2) Have mandatory encapsulation like Java's, no way to escape. Bruno > and yourself vehemently object to this, Russ P seems to want it, my > view is that it's not in the Python spirit, so I can accept the > argument that those who really want this are better off choosing > another language. Btw, I noticed a funny side effect of my 'namespaces' module (needs a LOT of work, this was the first time I touched weak references. I should find some place to upload the module): ===== import namespaces class public(namespaces.Namespace): pass class private(namespaces.Namespace): # the initializer could check if pass # its called from outside the class. Performance penalty. class A(object): """dummy class A, with one 'private' attribute x, and one normal 'attribute' x.""" def __init__(self): self.x = id(self) # normal attr pub = public(self) pub.f = self.f priv = private(self) priv.x = "this is the private" def f(self): print "normal x: ", self.x priv = private(self) print "private x: ", priv.x >>> a = A() >>> dir(a) ['__class__', , 'f', 'x'] >> a.f() normal x: 147956684 private x: this is the private >>> p = public(a) >>> dir(p) # Look, there is no 'x' attribute! ['__class__', , 'f'] >>> p.f() # but f still works! normal x: 147956684 private x: this is the private ====== Of course, without checks in 'private', one could say priv = private(a); priv.x, but the most interesting part, for me at least, was the ability to define a 'public' interface for a, that contains no attribute directly referencing the object 'a' with its internals - only the names explicitly declared on the 'interface'. Indirectly... well, p.f.im_self will return back the 'a' object. Bah, I'm ranting now. I just got carried away with my little experiment. Sorry. Ah, and yes, metaclasses are dangerously addictive :D > 3) Program in a style where creating new attributes outside the > initializer is normally avoided by convention, but it is possible and > sometimes desirable to break the convention. This seems reasonable > and Pythonic to me. But, any place I break the convention, I should > be able to say "I broke the convention here for such and such a > reason". And (this seems to be a bone of contention) IMO, it would be > good to be able to audit a large codebase with a tool like Pylint, to > automatically find all the places where such breakages occur. Right > now there seems to be no way to do that reliably, short of using > something like your special metaclass instead of the standard one for > just about everything. Well, I agree. Each and every one of those convention-breakages should be well documented, and pylint should be able to pick them up. Pylint does that already (see example below), I don't know if it lets you "document" it explicitly. I think Eclipse catches some of that stuff. My metaclass... shouldn't be used for anything serious :D. === breaklint.py === (no, it didn't break pylint) class A(object): def __init__(self): self.a = 5 def f(self): self.b = 7 # creating outside the init def g(self): print self.b # only if f runs first print self.c # and this one doesn't exist a = A() a.c = 8 a.f() a.g() a.d = "new var" # outside the class definition ================== $ pylint breaklint.py [...] W: 13: Attribute 'c' defined outside __init__ W: 7:A.f: Attribute 'b' defined outside __init__ W: 16: Attribute 'd' defined outside __init__ [...] Your code has been rated at -1.54/10 ===== > Your example about decorators (used on classes that don't expect to be > wrapped by them) is a good one but narrow enough that there could be a > special arrangement for it in a hypothetical auditing tool. Indeed. I'll take a look at pylint's config file. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From alan.isaac at gmail.com Tue Jan 20 01:30:22 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 06:30:22 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: <2cedl.865$aI1.290@nwrddc01.gnilink.net> On 1/19/2009 3:03 PM John Machin apparently wrote: > It is not deprecated YET; see this: > > http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6 > > PEP 3101: Advanced String Formatting. Note: the 2.6 description > mentions the format() method for both 8-bit and Unicode strings. In > 3.0, only the str type (text strings with Unicode support) supports > this method; the bytes type does not. The plan is to eventually make > this the only API for string formatting, and to start deprecating the > % operator in Python 3.1. Thanks! Alan Isaac From kyrie at uh.cu Tue Jan 20 01:33:00 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 01:33:00 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> Message-ID: <1232433180.4975701cc1791@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 9:21?pm, Paul Rubin wrote: > > Bruno Desthuilliers writes: > > > The failure was because a module tested, QA'd and certified within a > > > given context (in which it was ok to drop the builtin error handling) > > > was reused in a context where it was not ok. And the point is exactly > > > that : no *technology* can solve this kind of problem, because it is a > > > *human* problem (in that case, not taking time to repass the whole > > > specs / tests / QA process given context change). > > > > He says that "no *technology* can solve this kind of problem." > > First of all, I'm not sure that's true. I think technology *could* > have solved the problem -- e.g., Spark Ada, had it been properly > applied. But that's beside the point. The point is that the problem > had nothing to do with encapsulation. The rocket failed because a > conversion was attempted to a data type that could not hold the > required value. Am I missing something? I don't see what that has to > do with encapsulation. > > The logic seems to be as follows: > > 1. Ada enforces data hiding. > 2. Ada was used. > 2. A major failure occurred. > > Therefore: > > Enforced data hiding is useless. I don't think that was the logic... At least, it wasn't what I understood from the example. We were talking at the time (or rather, you both were, as I think I was still away from the thread) about QA versus static checks (as a superset of 'enforcement of data hiding'). Is not that those checks are useless, is that they make you believe you are safe. Granted, you may be safe-er, but it may be better to know beforehand "this is unsafe, I will check every assumption". The arianne 5 example cuts both ways: messing with "internals" (not that internal in this case, but still) without fully understanding the implications, and overly trusting the checks put in place by the language. I don't know spark-ada, but the only thing I can think of that would have prevented it is not purely technological. It would have been a better documentation, where that particular assumption was written down. A language can help you with it, perhaps spark-ada or eiffel or who-knows-what could've forced the original developers to write that piece of documentation and make the arianne 5 engineers notice it. So, Arianne 5's problem had nothing to do with _enforced data hiding_. (Why do you keep calling it 'encapsulation'?). It was a counterexample for your trust on compiler checks. Btw, what do you have against using pylint for detecting those 'access violations'? > If that reasoning is sound, think about what else is useless. I _hope_ that wasn't Bruno's reasoning. I don't want to switch sides on this discussion :D. Cheers, -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From aleksandr.goretoy at gmail.com Tue Jan 20 01:35:56 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 20 Jan 2009 06:35:56 +0000 Subject: ifconfig in python In-Reply-To: References: Message-ID: ifconfig -a|grep "inet addr"|awk '{print $2}' wget http://myip.dk&& cat index.html|grep "
wrote: > Something *like* this could work: > > myip = urllib2.urlopen('http://whatismyip.org/').read( > ) > > of course then you are depending on an external service, not a very > reliable one even. But then again, you might create an internal service > like that yourself. > > This cgi-bin shell code like this for ex: > > #! /bin/sh > echo "Content-type: text/plain" > echo > echo "${REMOTE_ADDR}" > > > -- > ?????? ( http://softver.org.mk/damjan/ ) > > Spammers scratch here with a diamond to find my address: > ||||||||||||||||||||||||||||||||||||||||||||||| > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan.isaac at gmail.com Tue Jan 20 01:40:25 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 06:40:25 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On 1/19/2009 5:03 PM Terry Reedy apparently wrote: > I have not seen 3.0 emit a % deprecation warning. Point taken. But the vocabulary of PEP 4 suggests that "obsolete" and "deprecated" are synonyms, and PEP 4 lists obsolete modules without deprecation warnings. Alan Isaac From kay.schluehr at gmx.net Tue Jan 20 01:55:33 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Mon, 19 Jan 2009 22:55:33 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <954b52df-f332-49ea-8ef5-b8e48ff09a9a@a39g2000prl.googlegroups.com> On 17 Jan., 01:37, "Brendan Miller" wrote: > Is this going anywhere or is this just architecture astronautics? > > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. Remember that the original objective of PyPy was to improve the JIT. Psyco is limited by the fact that the whole runtime is implemented in C. The infamous "faster than C" actually refers to work on program specializers on C code i.e. treating C as a language that is JIT compiled on a fine grained level ( block structure - whole function JIT compilation wouldn't obviously yield any advantages ). So it is not just the application level Python code that shall run through the JIT but also the interpreter level code. So why not equate them and think about interpreter level code as Python as well? This might be the idea. But then the problem of bootstrapping comes up: there is no interpreter level code with the required properties. Hence RPython that can serve as a foundation. I'm also not sure I like the approach. Rather than designing a whole new runtime for having a fully reflective system I'd model C in Python ( call it CiPy ) and create a bijection between CiPy code and C code. Once this has been established one can study other translations of CiPy or Python into CiPy ( not unlike Pyrex/Cython ) doing systematic refactorings on CiPy code in Python, study properties using runtime reflection, experiment with macro systems etc. All of this is done in PyPy as well but sometimes it seems the team has created more new problems than they solved. > Anyway, I can tell this is the sort of question that some people will > interpret as rude. Asking hard questions is never polite, but it is > always necessary :) I think it is a good question. From Russ.Paielli at gmail.com Tue Jan 20 02:00:43 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 23:00:43 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> Message-ID: On Jan 19, 10:33?pm, Luis Zarrabeitia wrote: > So, Arianne 5's problem had nothing to do with _enforced data hiding_. (Why do > you keep calling it 'encapsulation'?). I keep calling it encapsulation because that is a widely accepted, albeit not universal, definition of encapsulation. Google "encapsulation" and see for yourself. For example, here is what the Wikipedia page on OOP says: Encapsulation conceals the functional details of a class from objects that send messages to it. Here is what another webpage says: Definition: In Object Oriented Programming, encapsulation is an attribute of object design. It means that all of the object's data is contained and hidden in the object and access to it restricted to members of that class. Because those definitions are not universally accepted, however, I usually say "enforced encapsulation" or "data hiding" to mean what "encapsulation" means to most OO programmers who use a language other than Python. From http Tue Jan 20 02:05:57 2009 From: http (Paul Rubin) Date: 19 Jan 2009 23:05:57 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: <7xtz7ufodm.fsf@ruckus.brouhaha.com> "Tim Rowe" writes: > Unless it's changed since I used it, technically, SPADE doesn't allow > or disallow anything. Right, it's an external tool, like pylint; you can still compile code that SPADE complains about. Sorry if I wan't more clear. I just meant SPADE would flag the code. > Since the value appears to come from a sensor, the only way one > could prove that there would be no overflow would be to state it as > a part of the specification of what is read in. If that > specification doesn't match the specification of the actual sensor, > that's nothing to do with the programming language or, for that > matter, the program itself. It's a specification mismatch. Right, that's the point, the assumption about the sensor reading being in a certain range would have to stated in the specification rather than implicit in the code; and as such, the problem would more likely to have been caught at the systems engineering level. > I was actually at the European Space Agency's Toulouse site the week > after the Ariane 5 incident. I've been at jollier funerals. I can't > help thinking that thinking that the team would have benefited from > reading David Parnas's work on the specification of the A-7E avionics. Later there was a static analysis of the Ariane code by Cousot et al, that flagged the error. I haven't yet looked up the paper to see exactly what it found. From wuwei23 at gmail.com Tue Jan 20 02:17:06 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 19 Jan 2009 23:17:06 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> On Jan 20, 1:39?pm, Xah Lee wrote: > consider code produced by corporations, as opposed to with respect to > some academic or philsophical logical analysis. Looked in another way, > consider if we can compile stat of all existing pyhton code used in > real world, you'll find the above style is rarely used. I've worked for several corporations that used Python and at -all- of them the developers were not only aware of list comprehensions, they used them regularly. Same with iterators. Not -one- of them found them to be "computer sciency OOP jargons" but useful metaphors that made their code more concise without sacrificing readability. Not everything new is crap, y'know. Neither is everything that you fail to understand the first time you're exposed to it. I find it kinda funny that you constantly criticise "academic" language development when it seems pretty clear from your posts that you've never actually engaged in any practical application-focused development in your life. But as they say: those that can do, those that can't post godawful screeds to their much-hyped-on-usenet vanity blogs... From http Tue Jan 20 02:20:52 2009 From: http (Paul Rubin) Date: 19 Jan 2009 23:20:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: <7xvdsawii3.fsf@ruckus.brouhaha.com> "Tim Rowe" writes: > I was actually at the European Space Agency's Toulouse site the week > after the Ariane 5 incident. I've been at jollier funerals. I can't > help thinking that thinking that the team would have benefited from > reading David Parnas's work on the specification of the A-7E avionics. Thanks, these articles look interesting, though there is a lot to read: http://www.chacs.itd.nrl.navy.mil/publications/scr-a7e/index.html Was there something else you were referring to? From martinjamesevans at gmail.com Tue Jan 20 02:51:04 2009 From: martinjamesevans at gmail.com (martinjamesevans at gmail.com) Date: Mon, 19 Jan 2009 23:51:04 -0800 (PST) Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <0bd2453e-90ea-495f-87ca-bcec9890cd84@r27g2000vbp.googlegroups.com> Firstly, a huge thanks to all for the solutions! Just what I was looking for. > (Aside: why are you doing a case-insensitive match for a non-letter? Are > there different upper- and lower-case dollar signs?) As you can probably imagine, I had simplified the problem slightly, the language uses a couple of different introducers and also uses both numbers and letters (but only single characters). I was going to go with a similar idea of parsing per line but was trying to give RE another chance. I've used RE often in the past but for some reason this one had got under my skin. I found this to be quite an interesting little tool: http://www.gskinner.com/RegExr/ Martin From steven at REMOVE.THIS.cybersource.com.au Tue Jan 20 03:13:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 08:13:54 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <1232426356.49755574d7d65@mail.uh.cu> Message-ID: On Tue, 20 Jan 2009 15:04:34 +1000, James Mills wrote: > Having come from all kinda of programming backgrounds and paradigms you > learn to see the value in Python and the kind of simplicity it has to > offer. Oh yes, it is liberating to say "I don't care if my method crashes (raises an exception), it's the caller's fault for messing with my class' internals, and he can deal with it". I'm not being sarcastic by the way. It really is liberating not to have to deal with unexpected input or broken pre-conditions. Just let the caller deal with it! -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 20 03:15:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 08:15:05 GMT Subject: function to find the modification date of the project References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: On Mon, 19 Jan 2009 20:22:55 -0700, Joe Strout wrote: >> What if a curious user simple looks at a file with an editor and saves >> it without change? > > You can't do that, on the Mac at least... Are you sure? That's a rather incredible claim. Surely you mean *some Mac editors* disable the Save command if the file hasn't been edited? Other editors may not, and POSIX command line tools certainly won't. But that's a minor point. > But really, this is NOT going to happen. These users wouldn't even > know how to open the app bundle to find the Python files. Ah, the sorts of users who say "I looked in the system folder, and there was nothing there, so I deleted it". I know them well :-) > Any comments on the functioning and platform-independence of the code? I've developed a taste for writing that sort of function as a series of iterators. That's much like the Unix philosophy of piping data from one program to another. I'm sure I don't need to justify the benefits of Unix- style tools, but if you don't like it, just combine the following two iterators into the lastModDate function that follows: import os def file_iter(dir='.', recurse=False): for root, dirs, files in os.walk(dir): if not recurse: del dirs[:] for file in files: yield os.path.join(root, file) def filetype_iter(extensions=None, dir='.', recurse=False): if not extensions: extensions = [''] for file in file_iter(dir, recurse): if os.path.splitext(file)[1] in extensions: yield file def lastModDate(dir=None, recurse=False): """Return the latest modification date of any Python source file.""" if dir is None: dir = os.path.dirname(__file__) if dir == '': dir = '.' # HACK, but appears necessary return max( (os.path.getmtime(name) for name in filetype_iter(['.py'], dir, recurse)) ) It will raise a ValueError if there are no .py files in the directory, but that's easily changed. Note also that I've changed lastModDate() to return the raw date stamp rather than a human readable string. The right place to covert to a human readable format is just before displaying it to a human being :) -- Steven From xahlee at gmail.com Tue Jan 20 03:42:07 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 00:42:07 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> Message-ID: On Jan 19, 11:17 pm, alex23 wrote: ... Hi Daniel Weinreb, Xah wrote: > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Daniel Weinreb wrote: > Xah Lee: Elisp is an interesting choice. But without converting the > strings to integers, it's not really right. i did post a correction quickly that includes the conversion to string/ num. Here's the full code: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-string) "\n" t) ) ) (mapcar (lambda (x) (mapcar (lambda (y) (string-to-number y) ) (split-string x " ") ) ) (read-lines "blob.txt") ) > It's interesting that Elisp already has a style of reading in the > whole file, but no built-in to convert strings to integers, whereas > Common Lisp is the other way around. > The statement "It is not so mostly because emacs people have drawn > themselves into a elitist corner, closing off to the outside world" is > just a rude ad hominem attack. sure. In a political context, many criticism or description of the situation from one party can be seen as ad hominem attack. I feel that that many old emacs users, which includes significant portion of emacs developers (if not majority), are so exteremly bottled up and turn down any possibility of advancing. They are killing emacs. (similar feelings for most regular posters here in comp.lang.lisp ) Now, that statement is imprecise, is attacking, needs a lot qualifications. I have literally written about 20 articles each a thousand words or more over the past 3 years that explains many specific cases in painful detail. (e.g. seehttp://xahlee.org/emacs/emacs_essays_index.html ) However, in a one sentence description in this thread's context, calling them ?elitist? and ?closing off to the outside world?, is to the point. > Your claim that this shows something wrong with lists is completely > unclear, although if I read your paper (I'll try) I might have some > idea what you're getting at More specifically, 2 fundamental problems of lisp i feel this ruby example illustrates well: ? the cons impedes many aspects of lists. e.g. difficult to learn, confusing, hard to use, prevent development of coherent list manipulation functions. ? nested syntax impedes the functional programing paradigm of function chaining, esp when each function has 2 or more arguments (e.g. map). here's a short summary of the nesting problem: (map f x) ; 1 level of chaining (map g (map f x)) ; 2 levels (map h (map g (map f x))) ; 3 levels compare: x | f | g | h ----> unix pipe x // f // g // h ----> Mathematica h @ g @ f @ x ----> Mathematica x.f.g.h -------> various OOP langs, esp Ruby, javascript h g f x -------> some functional langs, Haskell, Ocaml The way the above works is that each of f, g, h is a lambda themselves that maps. (that is, something like ?(lambda (y) (map f y))?) Note, that any of the f, g, h may be complex pure functions (aka lambda). Because in lisp, each lambda itself will in general have quite a lot nested parens (which cannot be avoided), so this makes any chaining of functions of 2 args, for more than 2 or 3 levels of nesting, unusable for practical coding. One must define the functions separately and just call their names, or use function composition with lambda (which gets complex quickly). One major aspect of this problem is that the scope of vars becomes hard to understand in the deep nested source code. This is worse in elisp, because emacs is dynamically scoped, so you have to avoid using var of same name. More detail here: the section ?The Cons Business? at ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html Your input will be highly valued. Though, forgive me to say, that i think my opinion on this is beyond any computer scientist of any standing can try to tell me otherwise. If they disagree (which i think most of them won't), i think their knowledge and experience in the area of computer languages and syntax and notations, IQ, are inferior to me. Xah ?http://xahlee.org/ ? From duncan.booth at invalid.invalid Tue Jan 20 04:30:07 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jan 2009 09:30:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: Luis Zarrabeitia wrote: > It boggles me when I see python code with properties that only set and > get the attribute, or even worse, getters and setters for that > purpose. In my university they teach the students to write properties > for the attributes in C# ("never make a public attribute, always write > a public property that just gets and sets it"). I never understood > that practice either, given that the syntax for attribute access and > property access in C# is exactly the same. (Could it be that even if > the syntax is the same, the compiled code differs? Don't know enough > about .NET to answer that). > The compiled code differs. That doesn't matter if the class is only accessed from within a single compiled program, but it does matter if you expose a public interface from a library: if you change a public attribute into a property then you need to recompile all code which accesses it. Actually that's no worse than making any other change to the published interface, and the source code doesn't need to change, you just need to recompile. Personally when writing C# I use properties when it seems like a good idea, but for small internal classes I just expose the attributes until I know I need to do something different. -- Duncan Booth http://kupuguy.blogspot.com From http Tue Jan 20 05:00:34 2009 From: http (Paul Rubin) Date: 20 Jan 2009 02:00:34 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <7xzlhmthz1.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > No wonder you can't get Bruno's point. For the second, static checks > to prevent accidents, you have pylint. For the first, not only you > are using the wrong tool, but you are barking at python for not > having it. Assuming that pylint is perfect (big assumption, but it > is up to you to prove where it fails), Whaat? Assuming a program is perfect unless a failure is proven is not at all a sane approach to getting reliable software. It is the person claiming perfection who has to prove the absence of failure. From koranthala at gmail.com Tue Jan 20 05:11:52 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 20 Jan 2009 02:11:52 -0800 (PST) Subject: Logging help References: Message-ID: On Jan 20, 5:45?am, Chris Rebert wrote: > On Mon, Jan 19, 2009 at 11:36 AM, koranthala wrote: > > Hi, > > ? Is it possible somehow to have the logging module rotate the files > > every time I start it. > > ? Basically, I can automatically rotate using RotatingFileHandler; > > Now I want it rotated every time I start the program too. > > Just call the .doRollover() method of the RotatingFileHandler at the > start of the program. > Reading The Fine Documentation for the module is helpful. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com My question was poorly framed. I will try to explain the issue a little more. Current doRollover method is not very helpful to rolling over every day if the process starts and stops many times. For example: TimedRotatingFileHandler - when='D' Interval=1. I call handler.doRollover everytime process starts. First run - the output files are log.txt ---------- Second run - files are log.txt, log.txt.2009-01-20 ---------- Till now, fine. Third run - files are log.txt, log.txt.2009-01-20 ***But the earlier file is overwritten*** The doRollover method does not append to the earlier file. Rather, it creates a new file with the same name. Due to this the earlier logs are all gone. From alan.isaac at gmail.com Tue Jan 20 05:18:58 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 10:18:58 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: On 1/18/2009 9:36 AM Alan G Isaac apparently wrote: > I do not much care about the disappearance of ``execfile``. > I was asking, why is it a **good thing** that > ``exec`` does not accept a TextIOWrapper? > Or is it just not implemented yet? > What is the gain from this particular backwards > incompatibility (in the sense that ``exec(open(fname))`` > no longer works)? Still interested in an answer... Alan Isaac From sri_annauni at yahoo.co.in Tue Jan 20 06:08:43 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 20 Jan 2009 16:38:43 +0530 (IST) Subject: Doubts related to subprocess.Popen() Message-ID: <60756.16702.qm@web7903.mail.in.yahoo.com> Hi, Does?subprocess.Popen() count a new open file for each suprocess? I mean does it occupy an entry in file descriptor table of parent process? If so, wat is each file descriptor connected to? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From skip at pobox.com Tue Jan 20 06:09:41 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 20 Jan 2009 05:09:41 -0600 Subject: what's the point of rpython? In-Reply-To: <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> Message-ID: <18805.45301.590851.980179@montanaro.dyndns.org> Carl> I just looked at the boost documentation, which claims that Carl> multiple asynchronous writes to the same shared_ptr results in Carl> undefined behavior. That will not suffice for Python reference Carl> counting. Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have read what you saw but not recognized it in the C++ punctuation soup. I couldn't find what you referred to. Can you provide a URL? Thanks, -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From hubaghdadi at gmail.com Tue Jan 20 06:23:07 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 03:23:07 -0800 (PST) Subject: How to start a transaction? Message-ID: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Hey, I know the basics of interacting with databases in Python. How to start a transaction in case I want to group a couple of insert and update statements into a single operation? Thanks. From deets at nospam.web.de Tue Jan 20 06:35:34 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 12:35:34 +0100 Subject: How to start a transaction? References: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Message-ID: <6tlr86Fbg6faU1@mid.uni-berlin.de> Hussein B wrote: > Hey, > I know the basics of interacting with databases in Python. > How to start a transaction in case I want to group a couple of insert > and update statements into a single operation? Please read the python database API documentation: http://www.python.org/dev/peps/pep-0249/ And make sure your database supports transactions. Diez From http Tue Jan 20 06:46:10 2009 From: http (Paul Rubin) Date: 20 Jan 2009 03:46:10 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> Message-ID: <7xfxje8akd.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have > read what you saw but not recognized it in the C++ punctuation soup. I > couldn't find what you referred to. Can you provide a URL? http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety Note there is also something called "interprocess shared pointers" (link below) that don't have that caveat. I wonder if they use locks. http://www.boost.org/doc/libs/1_37_0/doc/html/interprocess/interprocess_smart_ptr.html#interprocess.interprocess_smart_ptr.shared_ptr From s.selvamsiva at gmail.com Tue Jan 20 06:55:07 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 20 Jan 2009 17:25:07 +0530 Subject: python resource management In-Reply-To: References: Message-ID: Hi all, I have found the actual solution for this problem. I tried using BeautifulSoup.SoupStrainer() and it improved memory usage to the greatest extent.Now it uses max of 20 MB(earlier it was >800 MB on 1GB RAM system). thanks all. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Tue Jan 20 07:15:50 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:15:50 +0000 Subject: How to print lambda result ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") print string_ However, instead of getting the expected output: 1 event 2 events 3 events I get: 1 event at 0x00AFE670> 2 event at 0x00AFE670> 3 event at 0x00AFE6B0> Reading the first results of http://www.google.com/search?q=python+lambda didn't enlighten me. Could you point to a URL which could set me on the right path to get the expected output ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmas at tgaragemedia.com Tue Jan 20 07:16:42 2009 From: tmas at tgaragemedia.com (Thomas Lord) Date: Tue, 20 Jan 2009 07:16:42 -0500 Subject: python for flash drives Message-ID: try portable python. it's free! http://www.portablepython.com/ From tino at wildenhain.de Tue Jan 20 07:22:17 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 20 Jan 2009 13:22:17 +0100 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> Message-ID: <4975C1F9.6040607@wildenhain.de> Hi, Barak, Ron wrote: > Hi, > > Wanting to print the correct plural after numbers, I did the following: > > for num in range(1,4): > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") > print string_ > > However, instead of getting the expected output: > > 1 event > 2 events > 3 events > > I get: > > 1 event at 0x00AFE670> > 2 event at 0x00AFE670> > 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Tue Jan 20 07:33:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 12:33:16 +0000 Subject: ifconfig in python References: Message-ID: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> ?????? ??????????? writes: > Something *like* this could work: > > myip = urllib2.urlopen('http://whatismyip.org/').read() This is going to cause all manner of problems. Firstly, many users are stuck behind NAT routers. In this case, the external service will report the address of the router, which is probably useless -- certainly it will be for programs attempting to communicate over a LAN. Secondly, imagine the joy when overzealous ISPs decide that whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last month): then the service will report the address of ISP's censoring proxy to thousands of otherwise unrelated users. And that's before we get onto onion routers like Tor... Here's an idea which might do pretty well. In [1]: import socket as S In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) In [4]: s.connect(('192.0.2.1', 666)) In [5]: s.getsockname() Out[5]: ('172.29.198.11', 46300) (No packets were sent during this process: UDP `connections' don't need explicit establishment. The network 192.0.2.0/24 is reserved for use in examples; selecting a local address should therefore exercise the default route almost everywhere. If there's a specific peer address or network you want to communicate with, use that address explicitly.) I have to wonder what the purpose of this is. It's much better to have the recipient of a packet work out the sender's address from the packet (using recvfrom or similar) because that actually copes with NAT and so on properly. -- [mdw] From Ron.Barak at lsi.com Tue Jan 20 07:34:04 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:34:04 +0000 Subject: How to print lambda result ? In-Reply-To: <4975C1F9.6040607@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Thanks Tino: your solutions without the lambda work nicely. What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. Bye, Ron. -----Original Message----- From: Tino Wildenhain [mailto:tino at wildenhain.de] Sent: Tuesday, January 20, 2009 14:22 To: Barak, Ron Cc: python-list at python.org Subject: Re: How to print lambda result ? Hi, Barak, Ron wrote: > Hi, > > Wanting to print the correct plural after numbers, I did the following: > > for num in range(1,4): > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") > print string_ > > However, instead of getting the expected output: > > 1 event > 2 events > 3 events > > I get: > > 1 event at 0x00AFE670> > 2 event at 0x00AFE670> > 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino From deets at nospam.web.de Tue Jan 20 07:38:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 13:38:50 +0100 Subject: Doubts related to subprocess.Popen() References: Message-ID: <6tluuqFbkbquU1@mid.uni-berlin.de> srinivasan srinivas wrote: > Hi, > Does?subprocess.Popen() count a new open file for each suprocess? I mean > does it occupy an entry in file descriptor table of parent process? If so, > wat is each file descriptor connected to? Usually, each new process has three file-descriptors associated with it - stdin,stdout and stderr. So when you span a process, the overall count of FDs should increase by three. Additionally, there are more FDs created if you chose to pipe communication between the child-process and the parent. This is a unix-thing btw, nothing to do with subprocess per se. Diez From tino at wildenhain.de Tue Jan 20 07:45:06 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 20 Jan 2009 13:45:06 +0100 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: <4975C752.1060702@wildenhain.de> Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. Well its up to the implemention what a class is supposed to return when its __str__() is called. Default is what you see. (this is actually __str__() returning __repr__() which is at its default) Regards Tino > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Tue Jan 20 07:46:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 12:46:17 +0000 Subject: Doubts related to subprocess.Popen() References: Message-ID: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> srinivasan srinivas writes: > Does subprocess.Popen() count a new open file for each suprocess? I > mean does it occupy an entry in file descriptor table of parent > process? If so, wat is each file descriptor connected to? On Unix, subprocess.Popen will use up a file descriptor in the parent for each use of subprocess.PIPE. The descriptor in question is one end of a pipe; the child process holds the other end. I guess the situation is similar on Windows, but I don't know for sure. -- [mdw] From Ron.Barak at lsi.com Tue Jan 20 07:47:17 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:47:17 +0000 Subject: How to print lambda result ? In-Reply-To: <4975C752.1060702@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> <4975C752.1060702@wildenhain.de> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B33@enbmail01.lsi.com> Ah, okay. Now it's clear. Thanks Tino. Ron. -----Original Message----- From: Tino Wildenhain [mailto:tino at wildenhain.de] Sent: Tuesday, January 20, 2009 14:45 To: Barak, Ron Cc: python-list at python.org Subject: Re: How to print lambda result ? Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. Well its up to the implemention what a class is supposed to return when its __str__() is called. Default is what you see. (this is actually __str__() returning __repr__() which is at its default) Regards Tino > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino From RasikaSrinivasan at gmail.com Tue Jan 20 07:50:31 2009 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Tue, 20 Jan 2009 04:50:31 -0800 (PST) Subject: ifconfig in python References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> On Jan 20, 7:33?am, Mark Wooding wrote: > ?????? ??????????? writes: > > Something *like* ?this could work: > > > ? ?myip = urllib2.urlopen('http://whatismyip.org/').read() > > This is going to cause all manner of problems. > > Firstly, many users are stuck behind NAT routers. ?In this case, the > external service will report the address of the router, which is > probably useless -- certainly it will be for programs attempting to > communicate over a LAN. > > Secondly, imagine the joy when overzealous ISPs decide that > whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last > month): then the service will report the address of ISP's censoring > proxy to thousands of otherwise unrelated users. > > And that's before we get onto onion routers like Tor... > > Here's an idea which might do pretty well. > > In [1]: import socket as S > In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) > In [4]: s.connect(('192.0.2.1', 666)) > In [5]: s.getsockname() > Out[5]: ('172.29.198.11', 46300) > > (No packets were sent during this process: UDP `connections' don't need > explicit establishment. ?The network 192.0.2.0/24 is reserved for use in > examples; selecting a local address should therefore exercise the > default route almost everywhere. ?If there's a specific peer address or > network you want to communicate with, use that address explicitly.) > > I have to wonder what the purpose of this is. ?It's much better to have > the recipient of a packet work out the sender's address from the packet > (using recvfrom or similar) because that actually copes with NAT and so > on properly. > > -- [mdw] one way to get your head around this is - IP Addresses are associated with the interface and not the computer. distinction may be subtle but critical. From wuwei23 at gmail.com Tue Jan 20 07:51:26 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 04:51:26 -0800 (PST) Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> On Jan 20, 10:34?pm, "Barak, Ron" wrote: > What I still don't understand is why the print does not > execute the lambda and prints the result, instead of > printing the lambda's object description. The following two statements are identical: >>> def f(x): return x ... >>> f = lambda x: x lambda _creates_ a function, it's up to you to actually _call_ the function. Functions are first class objects in Python, so the tuple you're passing in to the string format contains a number and a function. Tino's solutions are definitely more what you're looking for, but for your lambda version to work, you have to actually call the lambda function, passing in num when you do so (as you've specified that the lambda function requires one argument): >>> for num in range(1, 4): ... string_ = "%d event%s" % (num, (lambda num: num > 1 and "s" or "")(num)) ... print string_ Or you can remove the argument and create a closure using the num value from the loop: ... string_ = "%d event%s" % (num, (lambda: num > 1 and "s" or "") ()) But again, this is generally overkill when all you're after is a conditional value. Personally, I tend to use lambdas for passing small units of functionality into other functions, or if I want to create a quick closure. Your mileage may vary on what you consider a suitable use case, but you will -still- have to call your lambda in order for it to execute :) Generally From T.P.Northover at sms.ed.ac.uk Tue Jan 20 07:57:25 2009 From: T.P.Northover at sms.ed.ac.uk (Tim Northover) Date: Tue, 20 Jan 2009 12:57:25 +0000 Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> Message-ID: <87fxjegmoa.fsf@hal9000.lan> alex23 writes: > On Jan 20, 10:34?pm, "Barak, Ron" wrote: >>>> for num in range(1, 4): > ... string_ = "%d event%s" % (num, (lambda num: num > 1 and "s" or > "")(num)) > ... print string_ The notation here suggests Ron is sligtly confused about what he created. It was equivalent to string_ = "%d event%s" % (num, lambda x: x > 1 and "s" or "") Notice that there's no actual mention of num there, it's a function that takes one parameter. If that parameter happens to be num it does what you want, but there's no way for the interpreter to know what was intended. Tim. From hubaghdadi at gmail.com Tue Jan 20 08:11:17 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 05:11:17 -0800 (PST) Subject: Why I'm getting the date of yesterday Message-ID: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> Hey, I'm trying to get the get the date before today, I tried this: d = datetime.now() - timedelta(days = -1) But I got the date of tomorrow. when I tried: d = datetime.now() + timedelta(days = -1) I got the date of yesterday. Would you please explain to me why I got the date of yesterday when I added the both objects? Thanks. From simon at brunningonline.net Tue Jan 20 08:20:20 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 20 Jan 2009 13:20:20 +0000 Subject: Why I'm getting the date of yesterday In-Reply-To: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> References: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> Message-ID: <8c7f10c60901200520h3f299a2cj38cb274a6c58344c@mail.gmail.com> 2009/1/20 Hussein B : > Hey, > I'm trying to get the get the date before today, I tried this: > d = datetime.now() - timedelta(days = -1) > But I got the date of tomorrow. That's because you are taking away a negative value. This is like doing: >>> 0 - (-1) 1 -- Cheers, Simon B. From kyrie at uh.cu Tue Jan 20 08:22:33 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 08:22:33 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901200822.33174.kyrie@uh.cu> On Tuesday 20 January 2009 02:00:43 am Russ P. wrote: > On Jan 19, 10:33?pm, Luis Zarrabeitia wrote: > > (Why do you keep calling it 'encapsulation'?). > > I keep calling it encapsulation because that is a widely accepted, > albeit not universal, definition of encapsulation. [...] > Encapsulation conceals the functional details of a class from objects > that send messages to it. [..] > Definition: In Object Oriented Programming, encapsulation is an > attribute of object design. It means that all of the object's data is > contained and hidden in the object and access to it restricted to > members of that class. Ahh, 'concealed', 'contained', 'hidden'. Except the last one, "hidden", python does the rest... and one could argue the self.__privs get pretty well hidden. Not 'forbidden', 'restricted', 'enforced'. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From mal at egenix.com Tue Jan 20 08:25:18 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 20 Jan 2009 14:25:18 +0100 Subject: How to start a transaction? In-Reply-To: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> References: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Message-ID: <4975D0BE.9010506@egenix.com> On 2009-01-20 12:23, Hussein B wrote: > Hey, > I know the basics of interacting with databases in Python. > How to start a transaction in case I want to group a couple of insert > and update statements into a single operation? If you use a Python DB-API compatible database module, then transactions are enabled per default after you connect to the database. connection.commit() and .rollback() then complete a transaction and implicitly start a new one. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 20 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From kyrie at uh.cu Tue Jan 20 08:33:08 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 08:33:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmthz1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <200901200833.08215.kyrie@uh.cu> On Tuesday 20 January 2009 05:00:34 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > No wonder you can't get Bruno's point. For the second, static checks > > to prevent accidents, you have pylint. For the first, not only you > > are using the wrong tool, but you are barking at python for not > > having it. Assuming that pylint is perfect (big assumption, but it > > is up to you to prove where it fails), > > Whaat? Assuming a program is perfect unless a failure is proven > is not at all a sane approach to getting reliable software. It is > the person claiming perfection who has to prove the absence of failure. No, no. I meant that if pylint works as its specification says it would. Russ says (or seems to say, I don't know, I'm confused already) that it is not good enough, that what pylint says it does is not what he wants (otherwise, this subthread would have died a long time ago). So, assuming that pylint works as specified (its up to "you" to find out if it doesn't and file bugreports about it, just like you would do if you find out that the static-checker for your enforced-static-checks-language is buggy), what would be the difference between only accepting/running "pylint-authorized code" and the enforced hiding you desire? Sorry, I didn't realize that perfect was a too strong word for that. "I speaks english bad" :D Cya! -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 20 08:33:11 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 20 Jan 2009 14:33:11 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjett86.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> Message-ID: <4975d297$0$24204$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Take some not-that-trivial projects like Zope/Plone. There are quite a >> few lines of code involved, and quite a lot of programmers worked on it. > > Zope is about 375 KLOC[1], I was thinking about Zope2 + Plone, but anyway... > which I agree is not trivial, but by > today's standards, it's not all that large. How many LOCS would it require if it was written in ADA ? > Zope also has 275 open > bugs, 6 of which are critical. None of which are going to *kill* anyone FWIW. Now how many of these bugs would have language-enforced access restriction prevented ? >[2] The Space Shuttle avionics (written > in the 1980's!) are 2 MLOC of a hi-level dynamic language ? Hm, I guess not. > in which only 3 errors have been found > post-release.[3] I think "large software system" today means 100's of > MLOC. Given the difference in LOCS count between a low-level static language and a hi-level dynamic language for the implementation of a same given features set, you cannot just define "large" by the # of LOCS. Not that I'm going to compare Zope with Space shuttle's stuff. > FWIW, Zope has 20x as much code as Django--is that a good > thing!? IMHO, definitively not - and I indeed prefer Django as far as I'm concerned. But this is another debate (or is it not ?...) From deets at nospam.web.de Tue Jan 20 09:06:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:06:46 +0100 Subject: Embedding Python. But not so easy. References: Message-ID: <6tm43mFbit9bU1@mid.uni-berlin.de> > 1) Threads: the simulation is going to be run in a very parallel > environment with several CPUs and > http://docs.python.org/c-api/init.html#thread-state-and- > the-global-interpreter-lock there is a global lock mentioned. Does that > mean that the python code can not benefit from this ? Not if it is CPU-bound, no. To overcome that, you'd either need multiple processes, or you could try & trick the python interpreter by using renamed DLLs, which means that you can start several interpreters in one process. *BUT* that's a nasty hack & you can't share objects between the interpreters. > 2) The script has to hand back control to the C++ framework without > increasing the C execution stack. and be able to resume the execution at a > later point. > > I try some pseudo code here to explain > > // C++: > ctx = new ExecutionContext(); > > ctx->run(); > while(ctx->stillRunning()) { > otherStuff(); > ctx->resume(); > } Stackless python might be of help here, google it. Diez From rolf.oltmans at gmail.com Tue Jan 20 09:08:11 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Tue, 20 Jan 2009 06:08:11 -0800 (PST) Subject: A SSH error during put operation Message-ID: <337d1fc9-2378-4a9e-b984-dd75e2145f26@y1g2000pra.googlegroups.com> Hey all, I've been using Paramiko for sometime now and I never had any problems. I've already submitted this question to Paramiko mailling list but I thought I should post it in CLP as someone might have used it in past. I'm using Paramiko for SSH. Are there any other good SSH libraries that you've found useful--please let me know? There is this script that used to work absolutely fine. But for some reason it's broken now. First, here is the script. Error is pasted at the end. Please help as I've searched the Internet, archives but couldn't find anything and it's been quite a few hours now. I will really appreciate any help. Thanks in advance. Script: from __future__ import with_statement import paramiko import base64,os, sys from paramiko import AutoAddPolicy, SSHClient from decimal import * class CustomException(Exception): def __init__(self, value): self.parameter = value def __str__(self): return repr(self.parameter) def ConnectCopy(domainInfo, uname, pwd, portNumber,zipName,completePath): #domainInfo is a list, where domainInfo[0] = host name and #domainInfo[1] is the remote path. #---- #zipName is the name of zip file. It will be appended with domainInfo[1] so #it will look like c:\Test\ABC.zip #---- #completePath is the local file path , that we intend to copy to remote host domainName="" domainName=domainInfo[0].strip() client= paramiko.SSHClient() client.set_missing_host_key_policy(AutoAddPolicy()) print 'Complete Path= '+completePath try: client.connect (domainName,portNumber,username=uname,password=pwd) except CustomException, (e): print "Error="+e.parameter print "Domain Info= "+domainInfo[1] try: sftp=client.open_sftp() sftp.put(os.path.normpath(completePath),os.path.normpath (domainInfo[1])+"\\"+zipName) sys.stdout.write('\n') print 'File has been copied' except CustomException,(e): print "Error = "+e.parameter sys.exit() sftp.close() client.close() if __name__=="__main__": ConnectCopy(['example.example.com','C:\\test'],'username','pwd', 8922,'ABC.zip','C:\\ABC.zip') and here is the Error: Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. C:\Release>connectdeploy1.py Traceback (most recent call last): File "C:\Release\ConnectDeploy1.py", line 56, in ConnectCopy(['example.example.com','C:\\test'],'username','pwd', 8922,'ABC.zip','C:\\ABC.zip') File "C:\Release\ConnectDeploy1.py", line 39, in ConnectCopy sftp.put(os.path.normpath(completePath),os.path.normpath(domainInfo [1])) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 539, in put fr = self.file(remotepath, 'wb') File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 238, in ope n t, msg = self._request(CMD_OPEN, filename, imode, attrblock) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 589, in _re quest return self._read_response(num) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 637, in _re ad_response self._convert_status(msg) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 667, in _co nvert_status raise IOError(text) IOError: SfsStatusCode.Failure From hubaghdadi at gmail.com Tue Jan 20 09:19:21 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 06:19:21 -0800 (PST) Subject: How to get first/last day of the previous month? Message-ID: Hey, I'm creating a report that is supposed to harvest the data for the previous month. So I need a way to get the first day and the last day of the previous month. Would you please tell me how to do this? Thanks in advance. From sri_annauni at yahoo.co.in Tue Jan 20 09:19:33 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 20 Jan 2009 19:49:33 +0530 (IST) Subject: Doubts related to subprocess.Popen() References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <530163.74241.qm@web7903.mail.in.yahoo.com> Do?parent process will have different file descriptor in it for each subprocesses or?paprent uses a single file descriptor for all? I really want to know creation of each subprocess will occupy an entry in parents'file descriptor table. B'cos if i create more than 200 subprocesses, i am getting 'Too many open files' error. Thanks, Srini ----- Original Message ---- From: Mark Wooding To: python-list at python.org Sent: Tuesday, 20 January, 2009 6:16:17 PM Subject: Re: Doubts related to subprocess.Popen() srinivasan srinivas writes: > Does subprocess.Popen() count a new open file for each suprocess? I > mean does it occupy an entry in file descriptor table of parent > process?? If so, wat is each file descriptor connected to? On Unix, subprocess.Popen will use up a file descriptor in the parent for each use of subprocess.PIPE.? The descriptor in question is one end of a pipe; the child process holds the other end. I guess the situation is similar on Windows, but I don't know for sure. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From darcy at druid.net Tue Jan 20 09:26:14 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 09:26:14 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: <20090120092614.b6fbebe4.darcy@druid.net> On Tue, 20 Jan 2009 12:34:04 +0000 "Barak, Ron" wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. Because that's what you told it. Consider the even simpler example... "%s" % lambda num: int(num) This is equivalent to... "%s" % int IOW, you are giving the function (anonymous in your case), not the result of calling it. Your code prints a representation of exactly what you gave it, an anonymous function that would return a string if you called it with a number. > > for num in range(1,4): > > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From philip at semanchuk.com Tue Jan 20 09:28:34 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 20 Jan 2009 09:28:34 -0500 Subject: Doubts related to subprocess.Popen() In-Reply-To: <530163.74241.qm@web7903.mail.in.yahoo.com> References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> <530163.74241.qm@web7903.mail.in.yahoo.com> Message-ID: <45A4A799-A622-41D0-91AD-A506F1A8B37C@semanchuk.com> On Jan 20, 2009, at 9:19 AM, srinivasan srinivas wrote: > Do parent process will have different file descriptor in it for each > subprocesses or paprent uses a single file descriptor for all? > I really want to know creation of each subprocess will occupy an > entry in parents'file descriptor table. B'cos if i create more than > 200 subprocesses, i am getting 'Too many open files' error. If you're on Unix, a command like lsof can be useful at a time like this. lsof = "ls open files" If you're on Linux, there's the /proc tree to investigate. > > ----- Original Message ---- > From: Mark Wooding > To: python-list at python.org > Sent: Tuesday, 20 January, 2009 6:16:17 PM > Subject: Re: Doubts related to subprocess.Popen() > > srinivasan srinivas writes: > >> Does subprocess.Popen() count a new open file for each suprocess? I >> mean does it occupy an entry in file descriptor table of parent >> process? If so, wat is each file descriptor connected to? > > On Unix, subprocess.Popen will use up a file descriptor in the parent > for each use of subprocess.PIPE. The descriptor in question is one > end > of a pipe; the child process holds the other end. > > I guess the situation is similar on Windows, but I don't know for > sure. > > -- [mdw] > -- > http://mail.python.org/mailman/listinfo/python-list > > > > Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ > -- > http://mail.python.org/mailman/listinfo/python-list From gspschmid at gmail.com Tue Jan 20 09:33:29 2009 From: gspschmid at gmail.com (Georg Schmid) Date: Tue, 20 Jan 2009 06:33:29 -0800 (PST) Subject: SetUp functions for multiple test cases Message-ID: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> I've just started working with unittests and already hit a snag. I couldn't find out how to implement a setup function, that is executed only _once_ before all of the tests. Specifically, I need this for testing my database interface, and naturally I don't want to create a new database in-memory and fill it with example data for every single test case. Obviously I could simply execute that setup function separately from the unittesting procedure, but then there'd be no point in implementing all my unittests in a clean manner in the first place, apart from further problems arising due to how my IDE (Eric4) picks test cases from project files. Perhaps I missed something about the concept of TestSuites. Thanks in advance! From darcy at druid.net Tue Jan 20 09:53:04 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 09:53:04 -0500 Subject: How to print lambda result ? In-Reply-To: <20090120092614.b6fbebe4.darcy@druid.net> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> <20090120092614.b6fbebe4.darcy@druid.net> Message-ID: <20090120095304.d68f3ee9.darcy@druid.net> On Tue, 20 Jan 2009 09:26:14 -0500 "D'Arcy J.M. Cain" wrote: > "%s" % lambda num: int(num) Of course I meant... "%s" % (lambda num: int(num)) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From kyosohma at gmail.com Tue Jan 20 09:54:16 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 20 Jan 2009 06:54:16 -0800 (PST) Subject: How to get first/last day of the previous month? References: Message-ID: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> On Jan 20, 8:19?am, Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? > Thanks in advance. I recommend the dateutil module: http://labix.org/python-dateutil I think it may also be possible to use the datetime module, but it's easier to just use dateutil. Mike From deets at nospam.web.de Tue Jan 20 09:55:22 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:55:22 +0100 Subject: How to get first/last day of the previous month? References: Message-ID: <6tm6uqFbgvnbU1@mid.uni-berlin.de> Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? First day: create a new date-object with the day==1. Last day: create a date-object with month + 1 and day==1, and subtract a timedelta with one day of it. Diez From deets at nospam.web.de Tue Jan 20 09:56:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:56:50 +0100 Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <6tm71iFbgvnbU2@mid.uni-berlin.de> Georg Schmid wrote: > I've just started working with unittests and already hit a snag. I > couldn't find out how to implement a setup function, that is executed > only _once_ before all of the tests. Specifically, I need this for > testing my database interface, and naturally I don't want to create a > new database in-memory and fill it with example data for every single > test case. > Obviously I could simply execute that setup function separately from > the unittesting procedure, but then there'd be no point in > implementing all my unittests in a clean manner in the first place, > apart from further problems arising due to how my IDE (Eric4) picks > test cases from project files. > Perhaps I missed something about the concept of TestSuites. Thanks in > advance! Why don't you simply store the state of the DB being set-up somewhere (globally for example), and only execute the db-setup-code (inside setUp of course) depending on the value of that variable? Diez From roy at panix.com Tue Jan 20 09:57:51 2009 From: roy at panix.com (Roy Smith) Date: Tue, 20 Jan 2009 09:57:51 -0500 Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: In article <45b0bf56-673c-40cd-a27a-62f9943d9f1a at r41g2000prr.googlegroups.com>, Georg Schmid wrote: > I've just started working with unittests and already hit a snag. I > couldn't find out how to implement a setup function, that is executed > only _once_ before all of the tests. Specifically, I need this for > testing my database interface, and naturally I don't want to create a > new database in-memory and fill it with example data for every single > test case. Short answer -- there's no way to do it in the unittest framework. The True Unit Test Zealots will argue that all tests should be 100% independent of each other, which means there should be NO common state between test cases. For that matter, they will also argue that unit tests should not interface with external resources like databases. And they're right. On the other hand, the Real World Test Pragmatists will argue that this is just not practical in all cases. Real programs have classes which interact with the outside world, and they need to get tested. You could stub out the external resource, but that's a lot of work, and may introduce as many problems as it solves. Sometimes, a big part of what you're testing is your understanding of the external world (i.e. "does this really work like it's documented?"). Plus, some operations are just too expensive to do for every test case. I don't know how long it takes to build your in-memory database. If it takes one second, it probably makes sense to do it for every test case (unless you've got thousands of test cases). If it takes 10 minutes, then it makes sense to do it once and deal with the fact that you're violating True Unit Test Dogma. Anyway, do what I do. I run the tests with a: if __name__ == "__main__": blah blah block at the bottom of the test file. Just do your "do once" setup in that code block and store the result in a global. You might have your setUp() method re-assign the global to an instance variable and then your test cases can access it via self.whatever. The reason for that is if at some point in the future you change your mind and decide to re-build the database in setUp() for each test, you just have to change setUp(), not touch the individual test cases. From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:03:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:03:35 -0200 Subject: Logging help References: Message-ID: En Tue, 20 Jan 2009 08:11:52 -0200, koranthala escribi?: > On Jan 20, 5:45?am, Chris Rebert wrote: >> On Mon, Jan 19, 2009 at 11:36 AM, koranthala >> wrote: >> > ? Is it possible somehow to have the logging module rotate the files >> > every time I start it. >> > ? Basically, I can automatically rotate using RotatingFileHandler; >> > ^^^^^^^^^^^^^^^^^^^ > >> Now I want it rotated every time I start the program too. >> >> Just call the .doRollover() method of the RotatingFileHandler at the >> ^^^^^^^^^^^^^^^^^^^ start of >> the program. >> Reading The Fine Documentation for the module is helpful. > > Current doRollover method is not very helpful to rolling over every > day if the process starts and stops many times. > For example: > TimedRotatingFileHandler - when='D' Interval=1. I call > ^^^^^^^^^^^^^^^^^^^^^^^^ handler.doRollover everytime process starts. Why the move to TimedRotatingFileHandler? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:03:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:03:36 -0200 Subject: Logging help References: Message-ID: En Tue, 20 Jan 2009 08:11:52 -0200, koranthala escribi?: > On Jan 20, 5:45?am, Chris Rebert wrote: >> On Mon, Jan 19, 2009 at 11:36 AM, koranthala >> wrote: >> > ? Is it possible somehow to have the logging module rotate the files >> > every time I start it. >> > ? Basically, I can automatically rotate using RotatingFileHandler; >> > ^^^^^^^^^^^^^^^^^^^ > >> Now I want it rotated every time I start the program too. >> >> Just call the .doRollover() method of the RotatingFileHandler at the >> ^^^^^^^^^^^^^^^^^^^ start of >> the program. >> Reading The Fine Documentation for the module is helpful. > > Current doRollover method is not very helpful to rolling over every > day if the process starts and stops many times. > For example: > TimedRotatingFileHandler - when='D' Interval=1. I call > ^^^^^^^^^^^^^^^^^^^^^^^^ handler.doRollover everytime process starts. Why the move to TimedRotatingFileHandler? -- Gabriel Genellina From carsten.haese at gmail.com Tue Jan 20 10:04:00 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 20 Jan 2009 10:04:00 -0500 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. In order to not deprive you of the sense of accomplishment from figuring things out for yourself, I'll give you a couple of hints instead of fully formed Python code: 1) Think about how you can find the first day of the *current* month. 2) Think about how you can get to the last day of the previous month from there. 3) Think about how you can get to the first day of the previous month from there. Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net From marco at sferacarta.com Tue Jan 20 10:06:13 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:06:13 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Hussein B wrote: > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? > Thanks in advance. dateutil can do this and much, much more. >>> from datetime import date >>> from dateutil.relativedelta import relativedelta >>> today = date.today() >>> d = today - relativedelta(months=1) >>> date(d.year, d.month, 1) datetime.date(2008, 12, 1) >>> date(today.year, today.month, 1) - relativedelta(days=1) datetime.date(2008, 12, 31) >>> From wuwei23 at gmail.com Tue Jan 20 10:07:20 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 07:07:20 -0800 (PST) Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> <87fxjegmoa.fsf@hal9000.lan> Message-ID: <1abed683-f504-4ba5-afb8-26040991d758@z27g2000prd.googlegroups.com> On Jan 20, 10:57?pm, Tim Northover wrote: > Notice that there's no actual mention of num there, it's a function that > takes one parameter. If that parameter happens to be num it does what > you want, but there's no way for the interpreter to know what was > intended. Which is why my working example explicitly passed num into the lambda, and why my variant used a closure... From marco at sferacarta.com Tue Jan 20 10:07:46 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:07:46 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: <6Nldl.1258$8Z.845@tornado.fastwebnet.it> Carsten Haese wrote: > In order to not deprive you of the sense of accomplishment Sorry for spoiling that. If you still want the sense of accomplishment, try to reimplement dateutil (and rrule). It's not as easy as it seems :-o From carsten.haese at gmail.com Tue Jan 20 10:12:06 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 20 Jan 2009 10:12:06 -0500 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Marco Mariani wrote: > dateutil can do this and much, much more. Using dateutil for this is like using a sledgehammer to kill a fly. The task at hand can (and IMHO should) be solved with the standard datetime module. -- Carsten Haese http://informixdb.sourceforge.net From aberry at aol.in Tue Jan 20 10:13:08 2009 From: aberry at aol.in (aberry) Date: Tue, 20 Jan 2009 07:13:08 -0800 (PST) Subject: smtplib.SMTP throw : 'Socket error: 10053 software caused connection abort' Message-ID: <21565011.post@talk.nabble.com> I am using 'smtplib' module to send an email but getting exception... smtplib.SMTP( throw error : here is trace back snippet :- " smtp = smtplib.SMTP(self.server) File "D:\Python24\lib\smtplib.py", line 244, in __init__ (code, msg) = self.connect(host, port) File "D:\Python24\lib\smtplib.py", line 306, in connect raise socket.error, msg socket.error: (10053, 'Software caused connection abort')" thanks in adv, aberry -- View this message in context: http://www.nabble.com/smtplib.SMTP-throw-%3A-%27Socket-error%3A-10053-software-caused-connection-abort%27-tp21565011p21565011.html Sent from the Python - python-list mailing list archive at Nabble.com. From python.list at tim.thechases.com Tue Jan 20 10:19:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Jan 2009 09:19:18 -0600 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: <4975EB76.1050406@tim.thechases.com> > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? >>> from datetime import date, datetime, timedelta >>> def prev_bounds(when=None): ... if not when: when = datetime.today() ... this_first = date(when.year, when.month, 1) ... prev_end = this_first - timedelta(days=1) ... prev_first = date(prev_end.year, prev_end.month, 1) ... return prev_first, prev_end ... >>> prev_bounds() (datetime.date(2008, 12, 1), datetime.date(2008, 12, 31)) >>> prev_bounds(datetime.date(2008,3,14) (datetime.date(2008, 2, 1), datetime.date(2008, 2, 29)) -tkc From marco at sferacarta.com Tue Jan 20 10:20:25 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:20:25 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Carsten Haese wrote: >> dateutil can do this and much, much more. > > Using dateutil for this is like using a sledgehammer to kill a fly. The > task at hand can (and IMHO should) be solved with the standard datetime > module. Sure, but many python programmers are not even aware of the existence of that particular sledgehammer, it deserved to be mentioned. It should be part of the standard library I think. From gspschmid at gmail.com Tue Jan 20 10:24:49 2009 From: gspschmid at gmail.com (Georg Schmid) Date: Tue, 20 Jan 2009 07:24:49 -0800 (PST) Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <9d394e95-0c99-4abe-ae87-d715a71e22d2@v39g2000pro.googlegroups.com> On Jan 20, 3:57?pm, Roy Smith wrote: > In article > <45b0bf56-673c-40cd-a27a-62f9943d9... at r41g2000prr.googlegroups.com>, > ?Georg Schmid wrote: > > > I've just started working with unittests and already hit a snag. I > > couldn't find out how to implement a setup function, that is executed > > only _once_ before all of the tests. Specifically, I need this for > > testing my database interface, and naturally I don't want to create a > > new database in-memory and fill it with example data for every single > > test case. > > Short answer -- there's no way to do it in the unittest framework. > > The True Unit Test Zealots will argue that all tests should be 100% > independent of each other, which means there should be NO common state > between test cases. ?For that matter, they will also argue that unit tests > should not interface with external resources like databases. ?And they're > right. > > On the other hand, the Real World Test Pragmatists will argue that this is > just not practical in all cases. ?Real programs have classes which interact > with the outside world, and they need to get tested. ?You could stub out > the external resource, but that's a lot of work, and may introduce as many > problems as it solves. ?Sometimes, a big part of what you're testing is > your understanding of the external world (i.e. "does this really work like > it's documented?"). > > Plus, some operations are just too expensive to do for every test case. ?I > don't know how long it takes to build your in-memory database. ?If it takes > one second, it probably makes sense to do it for every test case (unless > you've got thousands of test cases). ?If it takes 10 minutes, then it makes > sense to do it once and deal with the fact that you're violating True Unit > Test Dogma. > > Anyway, do what I do. ?I run the tests with a: > > if __name__ == "__main__": > ? ?blah blah > > block at the bottom of the test file. ?Just do your "do once" setup in that > code block and store the result in a global. > > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. ?The > reason for that is if at some point in the future you change your mind and > decide to re-build the database in setUp() for each test, you just have to > change setUp(), not touch the individual test cases. Thanks, exactly what I needed to know. From james at agentultra.com Tue Jan 20 10:26:33 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 20 Jan 2009 10:26:33 -0500 Subject: Two questions about style and some simple math References: Message-ID: <85k58qt2vq.fsf@dozer.localdomain> Spoofy writes: > .. .. > > 2. > > For maintaining the character attributes I creates a seperate class. I > wonder weather this is an "overuse" of OO (instead of just making the > attributes plain variables of the Char class) and if the way I wrote > this is OK (somehow this looks cool to me but maybe too "showy"?) > > class Attributes(object): > ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": > 0, "condition": 0} > def __init__(self, **kwargs): > self.__dict__.update(self.ATTRIBUTES) > for arg in kwargs: > if arg not in self.ATTRIBUTES: > raise ValueError("Unkown character attribute '%s'" % > arg) > self.__dict__[arg] = kwargs[arg] > > > Again, I appreciate any tips. I you need more code (for the bigger > picture or such), just ask. > > Thanks in advance I think the first part has been covered well. If you want an opinion, this class isn't "showy" at all, rather it is ugly and unnecessary. Firstly it's bad because: 1. ATTRIBUTES is still modifiable after insantiation. This breaks the restriction you're expressing in __init__ 2. You want to avoid modifying __dict__ directly if you can. It bypasses the whole point of using named attributes. What you'd really want in a case where a class has a restricted set of attributes is __slots__. Classes defined with it have no __dict__ and thus attributes cannot be dynamically added to them after instanciation (a __slots__ defined class will raise an exception in this case). However, even in this case, it doesn't make sense to encapsulate the attributes of your game's Character objects in this way. Your "Hero" class should have its attributes directly associated to it: Hero.health, Hero.defence, and so forth. If you want to encapsulate a common set of attributes available to a "class" of objects, you'd create a "Character" class with those general attributes, sub-class your NPC's and Hero from it, and specialize those sub-classes as needed. HTH, j_king From bedouglas at earthlink.net Tue Jan 20 10:31:59 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 20 Jan 2009 07:31:59 -0800 Subject: ifconfig in python In-Reply-To: Message-ID: <086001c97b14$3e195620$0301a8c0@tmesa.com> hi... in general, i've found that using "route" to find the iface for the default gets me the interface in use... i then parse either ifconfig/iwconfig, to get the address of the nic for that interface.. it's worked ok so far on most machines i've dealt with... thoughts/comments are of course welcome! -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Ned Deily Sent: Monday, January 19, 2009 6:49 PM To: python-list at python.org Subject: Re: ifconfig in python In article , "James Mills" wrote: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres > wrote: > > Is ther an easy way to get the resolved ip address of the machine a script > > is running on? socket.gethostbyname(socket.gethostname) has only returned > > the ip address of my loop back interface ... not very usefull. > > That's because your /etc/hosts resolves > your hostname to 127.0.0.1 :) > > And no I know of no "easy" way cross > platform way. Perhaps parsing the output > of ifconfig itself ? Also, since the subject is on my brain at the moment, how to find "the address" is not the right question to ask. These days most systems have multiple network interfaces (Ethernet, WiFi, dialup, et al) running multiple protocols, like IPv4 and IPv6. In general, there is no *one* IP address of a machine; often there are many. Ignoring that fact can lead to subtle bugs, like the one causing a urllib2 regression test failure that I've been squashing today! -- Ned Deily, nad at acm.org -- http://mail.python.org/mailman/listinfo/python-list From hubaghdadi at gmail.com Tue Jan 20 10:32:06 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 07:32:06 -0800 (PST) Subject: How to get first/last day of the previous month? References: Message-ID: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> On Jan 20, 5:04?pm, Carsten Haese wrote: > Hussein B wrote: > > Hey, > > I'm creating a report that is supposed to harvest the data for the > > previous month. > > So I need a way to get the first day and the last day of the previous > > month. > > In order to not deprive you of the sense of accomplishment from figuring > things out for yourself, I'll give you a couple of hints instead of > fully formed Python code: > > 1) Think about how you can find the first day of the *current* month. > > 2) Think about how you can get to the last day of the previous month > from there. > > 3) Think about how you can get to the first day of the previous month > from there. > > Hope this helps, > > -- > Carsten Haesehttp://informixdb.sourceforge.net Thanks all for the reply. Yes, I prefer to use the standard library. Talking about the third step: You told me to think how to get the first day of the previous month, well how to know if the previous month is 28, 29, 30 or 31 days? I'm new to Python, so forgive my questions. From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:33:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:33:04 -0200 Subject: Problem with IDLE on windows XP References: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> Message-ID: En Mon, 19 Jan 2009 20:50:43 -0200, Grimes, George escribi?: > I am trying to learn Python and I installed version 2.6 both at home and > at work. At home, on > Vista, everything works fine. At work, on XP, IDLE would not run. I > uninstalled/reinstalled > and got the same thing. My cursor changes to the wait symbol for a few > seconds, then goes > back to normal and ?.nothing. The Task Manager shows nothing. I > uninstalled again, > made sure all the files were deleted from the disk, used regedit to > delte every registry entry > that had python in it and tried version 3.0. > > Geuss, what? I still can?t run IDLE on XP? Is this a common problem? > Or am I unique? Did you install "for all users" (as Administrator) or "just for me"? The following instructions assume you installed Python 2.6 on C:\Python26 -- replace with your own directory if different. Open a command prompt (go to Start, Run, type "cmd" and press Enter). At the > prompt type: c:\Python26\python -V and press Enter. Should reply with the Python version. Then try with: c:\Python26\python c:\Python26\Lib\idlelib\idle.pyw Should start IDLE, probably you get some error message; post it here. -- Gabriel Genellina From duncan.booth at invalid.invalid Tue Jan 20 10:45:52 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jan 2009 15:45:52 GMT Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: Roy Smith wrote: > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. > The reason for that is if at some point in the future you change your > mind and decide to re-build the database in setUp() for each test, you > just have to change setUp(), not touch the individual test cases. Or you could use a class attribute to save the database connection. Set it up the first time the test runs but on subsequent tests just use the saved values. If you have tests spread across separate files you could even set up the database connection in a base class and so it only gets created once across any number of test suites. This has the advantage that your test will work even if not invoked as the main script. Putting the setup code inside name=='__main__' will break as soon as you have multiple test files. -- Duncan Booth http://kupuguy.blogspot.com From python.list at tim.thechases.com Tue Jan 20 10:47:16 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Jan 2009 09:47:16 -0600 Subject: How to get first/last day of the previous month? In-Reply-To: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> References: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> Message-ID: <4975F204.3070201@tim.thechases.com> > You told me to think how to get the first day of the previous month, > well how to know if the previous month is 28, 29, 30 or 31 days? Find the first day of the *current* month, and then subtract one day (use the timedelta object). You'll end up with the last day of the previous month as a date/datetime object. -tkc From blank at empty.blank Tue Jan 20 10:57:52 2009 From: blank at empty.blank (RGK) Date: Tue, 20 Jan 2009 10:57:52 -0500 Subject: file write collision consideration Message-ID: I have a thread that is off reading things some of which will get written into a file while another UI thread manages input from a user. The reader-thread and the UI-thread will both want to write stuff to the same output file. What first comes to mind is that there may be write collisions, ie both trying to write at the same time. Should I do something like: if busyFlag: while busyFlag: sleep(10) else: busyFlag = True {write stuff to file} busyFlag = False in both threads? Is there some other approach that would be more appropriate? Thanks in advance for your advice - Ross. From jeff at jmcneil.net Tue Jan 20 11:01:18 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 20 Jan 2009 08:01:18 -0800 (PST) Subject: Doubts related to subprocess.Popen() References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <9abac68c-d19d-484f-99e9-df7580050c43@z28g2000prd.googlegroups.com> On Jan 20, 9:19 am, srinivasan srinivas wrote: > Do parent process will have different file descriptor in it for each subprocesses or paprent uses a single file descriptor for all? > I really want to know creation of each subprocess will occupy an entry in parents'file descriptor table. B'cos if i create more than 200 subprocesses, i am getting 'Too many open files' error. > > Thanks, > Srini > > ----- Original Message ---- > From: Mark Wooding > To: python-l... at python.org > Sent: Tuesday, 20 January, 2009 6:16:17 PM > Subject: Re: Doubts related to subprocess.Popen() > > srinivasan srinivas writes: > > > Does subprocess.Popen() count a new open file for each suprocess? I > > mean does it occupy an entry in file descriptor table of parent > > process? If so, wat is each file descriptor connected to? > > On Unix, subprocess.Popen will use up a file descriptor in the parent > for each use of subprocess.PIPE. The descriptor in question is one end > of a pipe; the child process holds the other end. > > I guess the situation is similar on Windows, but I don't know for sure. > > -- [mdw] > --http://mail.python.org/mailman/listinfo/python-list > > Add more friends to your messenger and enjoy! Go tohttp://messenger.yahoo.com/invite/ Have you upped your open files limit? My test script: import subprocess procs = [] for i in xrange(400): procs.append(subprocess.Popen("/bin/cat", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)) By default, 'ulimit -n' returns 1024, which is the number of open files allowed. Running the test script without changing it results in: Traceback (most recent call last): File "test.py", line 9, in stderr=subprocess.PIPE)) File "/usr/lib/python2.5/subprocess.py", line 593, in __init__ errread, errwrite) File "/usr/lib/python2.5/subprocess.py", line 1002, in _execute_child errpipe_read, errpipe_write = os.pipe() OSError: [Errno 24] Too many open files Now, up that limit to 8192 via ulimit -n, and run the script again: [root at marvin jeff]# ulimit -n 8192 [root at marvin jeff]# python test.py [root at marvin jeff]# HTH, Jeff From darcy at druid.net Tue Jan 20 11:08:46 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 11:08:46 -0500 Subject: file write collision consideration In-Reply-To: References: Message-ID: <20090120110846.8a30c93f.darcy@druid.net> On Tue, 20 Jan 2009 10:57:52 -0500 RGK wrote: > I have a thread that is off reading things some of which will get > written into a file while another UI thread manages input from a user. > > The reader-thread and the UI-thread will both want to write stuff to the > same output file. What first comes to mind is that there may be write > collisions, ie both trying to write at the same time. Why not create a third thread that handles the write? The other threads can simply add objects to a queue. You will still need collision handling in the queue adder but it only needs to block for a small time as opposed to the much longer disk write time. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From google at mrabarnett.plus.com Tue Jan 20 11:10:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 16:10:21 +0000 Subject: file write collision consideration In-Reply-To: References: Message-ID: <4975F76D.6000006@mrabarnett.plus.com> RGK wrote: > I have a thread that is off reading things some of which will get > written into a file while another UI thread manages input from a user. > > The reader-thread and the UI-thread will both want to write stuff to the > same output file. What first comes to mind is that there may be write > collisions, ie both trying to write at the same time. > > Should I do something like: > > > if busyFlag: > while busyFlag: > sleep(10) > else: > busyFlag = True > {write stuff to file} > busyFlag = False > > > in both threads? Is there some other approach that would be more > appropriate? > > Thanks in advance for your advice > If you're using the threading module, I suggest you look at the threading.RLock class: my_lock = threading.RLock() ... with my_lock: {write stuff to file} or, if you're using an older version of Python: my_lock = threading.RLock() ... my_lock.acquire() {write stuff to file} my_lock.release() From jaomatos at gmail.com Tue Jan 20 11:14:17 2009 From: jaomatos at gmail.com (=?utf-8?q?Jos=C3=A9_Matos?=) Date: Tue, 20 Jan 2009 16:14:17 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: <200901201614.17722.jaomatos@gmail.com> On Monday 19 January 2009 09:24:09 Eric Brunel wrote: > This is not the procedure I describe in the original post. The first time, > ? it works for me too. It's only after I used the file dialog that it stops > working. You are right, my mistake. -- Jos? Ab?lio From james at agentultra.com Tue Jan 20 12:29:17 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 20 Jan 2009 12:29:17 -0500 Subject: Pyro deadlock References: <71ed81f9-7d95-44bc-8ad0-3c8e5869cb43@v5g2000pre.googlegroups.com> Message-ID: <85fxjdubrm.fsf@dozer.localdomain> MatthewS writes: > I'd like to know if the following behavior is expected and can be > avoided: I have a Pyro server object that maintains a queue of work, > and multiple Pyro worker objects that take work off the queue by > calling a method on the server (get_work) and then return the work to > the server by calling another method (return_result). > > The problem is that I experience a deadlock condition in the > return_result method. > > Is this deadlock expected or should Pyro be able to synchronize the > remote calls to server's callback method when called from multiple > workers at the same time? If so any hints are appreciated. > > /Matthew Depends on how you're implementing the work/result queues. The Queue module is a good start. From mdw at distorted.org.uk Tue Jan 20 12:29:48 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 17:29:48 +0000 Subject: Doubts related to subprocess.Popen() References: <6tluuqFbkbquU1@mid.uni-berlin.de> Message-ID: <87ab9llwc3.fsf.mdw@metalzone.distorted.org.uk> "Diez B. Roggisch" writes: > Usually, each new process has three file-descriptors associated with > it - stdin,stdout and stderr. > > So when you span a process, the overall count of FDs should increase > by three. Yes, but that's irrelevant. There are two file limits which are relevant: * the per-process limit on file descriptors -- basically, the largest number which can be a file descriptor -- and * the overall number of files which can be open at a time. Note that, in Unix, the same file can be referred to by many different descriptors in many different processes, and fork(2), exec(2) and dup(2) don't change the number of files open. However, dup(2) allocates a new descriptor in the calling process, so it may hit the per-process limit. > Additionally, there are more FDs created if you chose to pipe > communication between the child-process and the parent. And these are the ones I mentioned. OK, in more detail: each pipe(2) call allocates two files (one for each end) and two file descriptors (one for each file). If you call Popen with PIPE specified for each of stdin, stdout and stderr, then that's a total of six descriptors and six files. But the parent will close half of them after calling fork(2) (freeing three descriptors), and the child will close all six after dup2(2)-ing them over the descriptors 0, 1, and 2. The net result is: * six new files in the global file table, and * three new descriptors in the parent. (The child ends up with no new descriptors at the end of all this.) -- [mdw] From mdw at distorted.org.uk Tue Jan 20 12:41:21 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 17:41:21 +0000 Subject: ifconfig in python References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> Message-ID: <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> "RasikaSrinivasan at gmail.com" writes: > one way to get your head around this is - IP Addresses are associated > with the interface and not the computer. distinction may be subtle but > critical. Actually this is wrong for most Unix systems, which use the `weak end-system model' described in RFC1122. Weak end-systems accept IP packets sent to any of the host's addresses (and respond to ARP requests for any address) arriving on any of its interfaces, and might send a packet from any of the host's addresses out of any interface. It's best to think of the addresses as referring to the host, and not the interfaces. That doesn't mean that you can get away with a single address for the entire host, though: you need addresses which correspond to the networks you're attached to. -- [mdw] From vivacarlie at gmail.com Tue Jan 20 12:48:09 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Tue, 20 Jan 2009 11:48:09 -0600 Subject: ifconfig in python In-Reply-To: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <65fadfc30901200948o5aa8aa51xbf6e12b176230a9a@mail.gmail.com> I'll let this thought fester but I thought I'd put together a PEP to make this a function. Possibly in some util library but preferibly in the sys library sense this is where to get information about the system you are running on. On Tue, Jan 20, 2009 at 6:33 AM, Mark Wooding wrote: > ?????? ??????????? writes: > > > Something *like* this could work: > > > > myip = urllib2.urlopen('http://whatismyip.org/').read( > ) > > This is going to cause all manner of problems. > > Firstly, many users are stuck behind NAT routers. In this case, the > external service will report the address of the router, which is > probably useless -- certainly it will be for programs attempting to > communicate over a LAN. > > Secondly, imagine the joy when overzealous ISPs decide that > whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last > month): then the service will report the address of ISP's censoring > proxy to thousands of otherwise unrelated users. > > And that's before we get onto onion routers like Tor... > > Here's an idea which might do pretty well. > > In [1]: import socket as S > In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) > In [4]: s.connect(('192.0.2.1', 666)) > In [5]: s.getsockname() > Out[5]: ('172.29.198.11', 46300) > > (No packets were sent during this process: UDP `connections' don't need > explicit establishment. The network 192.0.2.0/24 is reserved for use in > examples; selecting a local address should therefore exercise the > default route almost everywhere. If there's a specific peer address or > network you want to communicate with, use that address explicitly.) > > I have to wonder what the purpose of this is. It's much better to have > the recipient of a packet work out the sender's address from the packet > (using recvfrom or similar) because that actually copes with NAT and so > on properly. > > -- [mdw] > -- > http://mail.python.org/mailman/listinfo/python-list > -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From georgegrimes at ti.com Tue Jan 20 13:01:54 2009 From: georgegrimes at ti.com (Grimes, George) Date: Tue, 20 Jan 2009 12:01:54 -0600 Subject: Problem with IDLE on windows XP In-Reply-To: References: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> Message-ID: <2C1563023E232C49B9F505633D57C2DA12928A325C@dlee04.ent.ti.com> ?Muchas gracias! That was the hint that I needed, Gabriel. I had a problem with my path definition and running idle the way you indicated gave me an error message saying that it could not find a valid init.tcl on the path. I have fixed the problem and can now run idle at work. Thanks again! George George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell Failure is the opportunity to begin again, more intelligently. Henry Ford -----Original Message----- From: python-list-bounces+georgegrimes=ti.com at python.org [mailto:python-list-bounces+georgegrimes=ti.com at python.org] On Behalf Of Gabriel Genellina Sent: Tuesday, January 20, 2009 9:33 AM To: python-list at python.org Subject: Re: Problem with IDLE on windows XP En Mon, 19 Jan 2009 20:50:43 -0200, Grimes, George escribi?: > I am trying to learn Python and I installed version 2.6 both at home and > at work. At home, on > Vista, everything works fine. At work, on XP, IDLE would not run. I > uninstalled/reinstalled > and got the same thing. My cursor changes to the wait symbol for a few > seconds, then goes > back to normal and ?.nothing. The Task Manager shows nothing. I > uninstalled again, > made sure all the files were deleted from the disk, used regedit to > delte every registry entry > that had python in it and tried version 3.0. > > Geuss, what? I still can?t run IDLE on XP? Is this a common problem? > Or am I unique? Did you install "for all users" (as Administrator) or "just for me"? The following instructions assume you installed Python 2.6 on C:\Python26 -- replace with your own directory if different. Open a command prompt (go to Start, Run, type "cmd" and press Enter). At the > prompt type: c:\Python26\python -V and press Enter. Should reply with the Python version. Then try with: c:\Python26\python c:\Python26\Lib\idlelib\idle.pyw Should start IDLE, probably you get some error message; post it here. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From vivacarlie at gmail.com Tue Jan 20 13:04:04 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Tue, 20 Jan 2009 12:04:04 -0600 Subject: ifconfig in python In-Reply-To: <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <65fadfc30901201004of5e9a17mc06dc0b09dbe7a1b@mail.gmail.com> > > That doesn't mean that you can get away with a single address for the > entire host, though: you need addresses which correspond to the networks > you're attached to. > > -- [mdw] especially sense we are also getting into virtual NICs where you can have a webserver listening to one and broadcasting a stream to another. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From raf at gtn.ru Tue Jan 20 13:05:34 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:05:34 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568375.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568375p21568375.html Sent from the Python - python-list mailing list archive at Nabble.com. From kdawg44 at gmail.com Tue Jan 20 13:07:46 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 13:07:46 -0500 Subject: Overloading Methods Message-ID: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From raf at gtn.ru Tue Jan 20 13:09:12 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:09:12 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568438.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568438p21568438.html Sent from the Python - python-list mailing list archive at Nabble.com. From raf at gtn.ru Tue Jan 20 13:09:31 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:09:31 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568445.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568445p21568445.html Sent from the Python - python-list mailing list archive at Nabble.com. From bedouglas at earthlink.net Tue Jan 20 13:12:33 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 20 Jan 2009 10:12:33 -0800 Subject: ifconfig in python In-Reply-To: <65fadfc30901201004of5e9a17mc06dc0b09dbe7a1b@mail.gmail.com> Message-ID: <08d601c97b2a$ab8f54f0$0301a8c0@tmesa.com> so the question really starts to look like: -what's the default listening address for my app (insert nic)? -what's the default sending address for my app (insert nic)? -what's the default listening address for my server? -what's the default sending address for my server? -what's the default listening address for my (insert nic)? -what's the default sending address for my (insert nic)? any other possibilities?? -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Nehemiah Dacres Sent: Tuesday, January 20, 2009 10:04 AM To: Mark Wooding Cc: python-list at python.org Subject: Re: ifconfig in python That doesn't mean that you can get away with a single address for the entire host, though: you need addresses which correspond to the networks you're attached to. -- [mdw] especially sense we are also getting into virtual NICs where you can have a webserver listening to one and broadcasting a stream to another. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 From castironpi at gmail.com Tue Jan 20 13:14:21 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 20 Jan 2009 10:14:21 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> Message-ID: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> On Jan 17, 6:10?pm, The Music Guy wrote: > Wow, impressive responses. > > It sounds like the general consensus is that English would not be a good > choice for programming even if there were an interpreter capable of > turning human language into machine language. But that makes sense; even > English professionals have trouble understanding each other sometimes. > Until that problem is somehow overcome, there's not much hope of > computers to overcome it. I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. f "abc" 123 --> f( "abc", 123 ) It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. From raf at gtn.ru Tue Jan 20 13:17:06 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:17:06 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568578.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568578p21568578.html Sent from the Python - python-list mailing list archive at Nabble.com. From google at mrabarnett.plus.com Tue Jan 20 13:18:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 18:18:48 +0000 Subject: Overloading Methods In-Reply-To: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> Message-ID: <49761588.604@mrabarnett.plus.com> K-Dawg wrote: > Can you overload methods in Python? > > Can I have multiple __inits__ with different parameters passed in? > Simple answer: no. From gert.cuykens at gmail.com Tue Jan 20 13:31:19 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 10:31:19 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> Message-ID: On Jan 20, 5:23?am, John Machin wrote: > On Jan 20, 12:54?pm, gert wrote: > > > How do you convert s back to binary data in python 3 so I can put in a > > sqlite blob ? > > Is there a build in function or do I need to use binascii ? > > byte(s) or bin(s) would make more sense but can not figure it out ? > > Can't imagine why you would do str(binary_data) especially if you want > it back again ... however: def application(environ, response): s = str(environ['wsgi.input'].read()) b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group (1) p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) db.execute('UPDATE users SET picture=? WHERE uid=?', (p,session.UID)) > According to the fabulous manual: > > str([object[, encoding[, errors]]]) > Return a string version of an object, using one of the following > modes: > [snip] > When only object is given, this returns its nicely printable > representation. For strings, this is the string itself. The difference > with repr(object) is that str(object) does not always attempt to > return a string that is acceptable to eval(); its goal is to return a > printable string. > > Hmm looks like (1) we need to do the dreaded eval() and (2) there's no > guarantee it will work. > > >>> for i in range(256): > > ... ? ?blob = bytes([i]) > ... ? ?if eval(str(blob)) != blob: > ... ? ? ? print(i, blob, str(blob), eval(str(blob))) > ... > > >>> # no complaints! > > Looks like it's going to work, but you better be rather sure that you > trust the source. Any other suggestions ? From blank at empty.blank Tue Jan 20 13:39:54 2009 From: blank at empty.blank (RGK) Date: Tue, 20 Jan 2009 13:39:54 -0500 Subject: file write collision consideration In-Reply-To: References: Message-ID: Thanks for the suggestions - sounds like a couple good options, I apprecieate it. Ross. MRAB wrote: > RGK wrote: >> I have a thread that is off reading things some of which will get >> written into a file while another UI thread manages input from a user. >> >> The reader-thread and the UI-thread will both want to write stuff to >> the same output file. What first comes to mind is that there may be >> write collisions, ie both trying to write at the same time. >> >> Should I do something like: >> >> >> if busyFlag: >> while busyFlag: >> sleep(10) >> else: >> busyFlag = True >> {write stuff to file} >> busyFlag = False >> >> >> in both threads? Is there some other approach that would be more >> appropriate? >> >> Thanks in advance for your advice >> > If you're using the threading module, I suggest you look at the > threading.RLock class: > > my_lock = threading.RLock() > ... > with my_lock: > {write stuff to file} > > or, if you're using an older version of Python: > > my_lock = threading.RLock() > ... > my_lock.acquire() > {write stuff to file} > my_lock.release() From clp2 at rebertia.com Tue Jan 20 13:41:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jan 2009 10:41:24 -0800 Subject: Overloading Methods In-Reply-To: <49761588.604@mrabarnett.plus.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > K-Dawg wrote: >> >> Can you overload methods in Python? >> >> Can I have multiple __inits__ with different parameters passed in? >> > Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload methods in Python since you can use default and keyword arguments instead. For instance: class Foo(object): def __init__(self, a, b=10, c=None): self.a = a self.b = b if c is None: c = [] self.c = c #example use x = Foo("#", 4, [6,7]) y = Foo("@") z = Foo("!", c=[1,2]) Whereas in Java or C++ this would require several overloads, it can be succinctly expressed as a single method in Python. However, if you want the overloads to accept completely different types as parameters, then it arguably should expressed as distinct methods rather than "overloads". In the special case of __init__, you might want to make the alternate initializers classmethods or factory functions. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bockman at virgilio.it Tue Jan 20 13:53:58 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Tue, 20 Jan 2009 19:53:58 +0100 Subject: file write collision consideration References: Message-ID: On Tue, 20 Jan 2009 11:08:46 -0500, D'Arcy J.M. Cain wrote: > On Tue, 20 Jan 2009 10:57:52 -0500 > RGK wrote: >> I have a thread that is off reading things some of which will get >> written into a file while another UI thread manages input from a user. >> >> The reader-thread and the UI-thread will both want to write stuff to the >> same output file. What first comes to mind is that there may be write >> collisions, ie both trying to write at the same time. > > Why not create a third thread that handles the write? The other > threads can simply add objects to a queue. You will still need > collision handling in the queue adder but it only needs to block for a > small time as opposed to the much longer disk write time. IIRC, Queue.Queue objects handle by themselves multi-thread access, that is there is no need to additional locking mechanism ... Ciao --- FB From BrooklineTom at gmail.com Tue Jan 20 13:55:47 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Tue, 20 Jan 2009 10:55:47 -0800 (PST) Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <67ada713-c90a-44b8-8928-3b411ccef5c6@i24g2000prf.googlegroups.com> On Jan 20, 9:57 am, Roy Smith wrote: > In article > <45b0bf56-673c-40cd-a27a-62f9943d9... at r41g2000prr.googlegroups.com>, > Georg Schmid wrote: > > > I've just started working with unittests and already hit a snag. I > > couldn't find out how to implement a setup function, that is executed > > only _once_ before all of the tests. Specifically, I need this for > > testing my database interface, and naturally I don't want to create a > > new database in-memory and fill it with example data for every single > > test case. > > Short answer -- there's no way to do it in the unittest framework. > > The True Unit Test Zealots will argue that all tests should be 100% > independent of each other, which means there should be NO common state > between test cases. For that matter, they will also argue that unit tests > should not interface with external resources like databases. And they're > right. > > On the other hand, the Real World Test Pragmatists will argue that this is > just not practical in all cases. Real programs have classes which interact > with the outside world, and they need to get tested. You could stub out > the external resource, but that's a lot of work, and may introduce as many > problems as it solves. Sometimes, a big part of what you're testing is > your understanding of the external world (i.e. "does this really work like > it's documented?"). > > Plus, some operations are just too expensive to do for every test case. I > don't know how long it takes to build your in-memory database. If it takes > one second, it probably makes sense to do it for every test case (unless > you've got thousands of test cases). If it takes 10 minutes, then it makes > sense to do it once and deal with the fact that you're violating True Unit > Test Dogma. > > Anyway, do what I do. I run the tests with a: > > if __name__ == "__main__": > blah blah > > block at the bottom of the test file. Just do your "do once" setup in that > code block and store the result in a global. > > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. The > reason for that is if at some point in the future you change your mind and > decide to re-build the database in setUp() for each test, you just have to > change setUp(), not touch the individual test cases. I believe that the answer sought by the OP is the TestResource class from the original Smalltalk unit test. Sadly, the various language- specific clones -- including the Python unittest package -- followed the example of the JUnit hack, which elided this (for a variety of reasons, some good, some bad). There are two major obstacles in moving SUnit from Smalltalk to Python: (1) SUnit takes full advantage of class objects which still have only vestigial implementations in Python, and (2) SUnit takes full advantage of Smalltalk's restartable exception semantics. I've implemented an alternative unit test package, but I requires the rest of my framework (which addresses the above two restrictions) and is therefore not yet ready for prime time. The basic theme of TestResource is simple enough, once the rest of the unit test framework is properly factored: 1. Tests always run within an instance of TestSuite. 2. The "run" method of test suite (with no arguments) collects and creates whatever resources are needed by the tests within it. 3. The run method creates an instance of TestResult to collect the results. 4. Each TestCase instance collects whatever (existing) resources it needs. 5. When the "run" method (in step 2 above) finishes, all resources are finalized. Instances of TestResource have a "setUp" and "tearDown" method, just like TestCase. These are called once, at steps 2 and 5 above. I built my test frame from the original SUnit from KentBeck et al and used an excellent reference Joseph Pelrine (http://www.metaprog.com/ ESUG/TestResources.pdf) to guide my work. From joe at strout.net Tue Jan 20 13:58:46 2009 From: joe at strout.net (Joe Strout) Date: Tue, 20 Jan 2009 11:58:46 -0700 Subject: English-like Python In-Reply-To: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <49761EE6.4070306@strout.net> Aaron Brady wrote: > I think it would be a good step if you could make some sensible > interpretation of a typical statement without its parentheses. > > f "abc" 123 > --> > f( "abc", 123 ) > > It would be just the thing in a couple of situations... Such a language is possible -- take a look at REALbasic sometime. RB certainly has its problems (mainly bugs), but the language syntax is beautiful. To your point, parentheses are not required around any method call that (1) has no return value, or (2) requires no parameters. Example: LogError "Walk has gotten too silly", CurrentTime Here, LogError is a method call that takes two arguments, and CurrentTime is a method call that takes none. Your "f" example above works fine in RB too, though with such an abstract example it's a little hard to see why it's so cool. Eliminating unnecessary parentheses does a lot to improve the readability of the code IMHO. Cheers, - Joe From Russ.Paielli at gmail.com Tue Jan 20 14:04:20 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 11:04:20 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> On Jan 20, 5:33 am, Luis Zarrabeitia wrote: > On Tuesday 20 January 2009 05:00:34 am Paul Rubin wrote: > > > Luis Zarrabeitia writes: > > > No wonder you can't get Bruno's point. For the second, static checks > > > to prevent accidents, you have pylint. For the first, not only you > > > are using the wrong tool, but you are barking at python for not > > > having it. Assuming that pylint is perfect (big assumption, but it > > > is up to you to prove where it fails), > > > Whaat? Assuming a program is perfect unless a failure is proven > > is not at all a sane approach to getting reliable software. It is > > the person claiming perfection who has to prove the absence of failure. > > No, no. I meant that if pylint works as its specification says it would. > > Russ says (or seems to say, I don't know, I'm confused already) that it is not > good enough, that what pylint says it does is not what he wants (otherwise, > this subthread would have died a long time ago). So, assuming that pylint > works as specified (its up to "you" to find out if it doesn't and file > bugreports about it, just like you would do if you find out that the > static-checker for your enforced-static-checks-language is buggy), what > would be the difference between only accepting/running "pylint-authorized > code" and the enforced hiding you desire? > > Sorry, I didn't realize that perfect was a too strong word for that. "I speaks > english bad" :D > > Cya! > > -- > Luis Zarrabeitia (aka Kyrie) > Fac. de Matem?tica y Computaci?n, UH.http://profesores.matcom.uh.cu/~kyrie Hey, if pylint can reliably detect private data access violations, that's good news to me. I haven't used it, so I don't know. (I used pychecker a while back, but I haven't used that for a while either.) If pylint can check access violations, then it seems to me that someone (who is familiar with the internals of the Python interpreter) should be able to integrate that feature into Python itself relatively easily. Actually, in addition to the enforcement of "private," you also need the enforcement of "protected." If you only enforce "private," derived classes will not have access to data they need. And if you don't enforce "protected," then anyone can trivially gain access to private data by simply deriving a new class. It would be like having a lock on the door with the key hanging right there on a string. I realize that this complicates matters. As I said before, I am not claiming that Python should necessarily get enforced data hiding. All I am saying is that, if it doesn't get it, it will never be appropriate for certain domains. But maybe nobody cares about that except me. The other problem with the pylint approach is aesthetic: the requirement for a leading underscore to indicate private data. I realize that some actually like that convention, but I don't. I spend most of my development time working with "private" data, and why should I have to look at that litter everywhere? I use Python in part because I want clean looking code, and leading underscores bother me -- just as the leading dollar signs in Perl bother many Python programmers. From sjmachin at lexicon.net Tue Jan 20 14:06:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 11:06:22 -0800 (PST) Subject: How to get first/last day of the previous month? References: <6Nldl.1258$8Z.845@tornado.fastwebnet.it> Message-ID: On Jan 21, 2:07?am, Marco Mariani wrote: > Carsten Haese wrote: > > In order to not deprive you of the sense of accomplishment > > Sorry for spoiling that. If you still want the sense of accomplishment, > try to reimplement dateutil (and rrule). It's not as easy as it seems :-o True, but getting the last day of a given month from first principles without any library routines is nowhere near as complex as (e.g.) converting (y,m,d) <-> ordinal day number. It's this easy: # days in month (non-leap year) _dim = (None, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) def _leap(y): if y % 4: return 0 if y % 100: return 1 if y % 400: return 0 return 1 def last_day_of_month(y, m): """Return day (1..31) which is last day of month m in year y """ if m == 2: return 28 + _leap(y) if not (1 <= m <= 12): raise Exception("month not in 1..12") return _dim[m] Cheers, John From joefazee at gmail.com Tue Jan 20 14:06:54 2009 From: joefazee at gmail.com (Abah Joseph) Date: Tue, 20 Jan 2009 11:06:54 -0800 Subject: English-like Python In-Reply-To: <49761EE6.4070306@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: Python is English-like enough that everybody including non-programmers can understand it.e.g # Import the operating system module import os # define new function def open_dir_tree(path): for File in os.listdir(path): file_or_dir = os.path.join(path, File) # Read the line below, this is almost full english language if os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir): open_dir_tree(file_or_dir) else: print file_or_dir open_dir_tree(".") -- I develop dynamic website with PHP & MySql, Let me know about your site -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Tue Jan 20 14:21:47 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Wed, 21 Jan 2009 00:51:47 +0530 Subject: python resource management In-Reply-To: <13A9CCF8-75E3-43D6-B43F-87B9C5F6296C@sas.com> References: <13A9CCF8-75E3-43D6-B43F-87B9C5F6296C@sas.com> Message-ID: On Tue, Jan 20, 2009 at 7:27 PM, Tim Arnold wrote: > I had the same problem you did, but then I changed the code to create a new > soup object for each file.That drastically increased the speed. I don't > know why, but it looks like the soup object just keeps getting bigger with > each feed. > > --Tim > > I have found the actual solution for this problem. I tried using *BeautifulSoup.SoupStrainer()* and it improved memory usage to the greatest extent.Now it uses max of 20 MB(earlier it was >800 MB on 1GB RAM system). thanks all. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Tue Jan 20 14:30:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 20 Jan 2009 11:30:46 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> On Jan 20, 12:58?pm, Joe Strout wrote: > Aaron Brady wrote: > > I think it would be a good step if you could make some sensible > > interpretation of a typical statement without its parentheses. > > > f "abc" 123 > > --> > > f( "abc", 123 ) > > > It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. ?RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. ?To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > ? Example: > > ? LogError "Walk has gotten too silly", CurrentTime > > Here, LogError is a method call that takes two arguments, and > CurrentTime is a method call that takes none. > > Your "f" example above works fine in RB too, though with such an > abstract example it's a little hard to see why it's so cool. > > Eliminating unnecessary parentheses does a lot to improve the > readability of the code IMHO. > > Cheers, > - Joe Unambiguity and readability are two different things. (This should be a quasi-tangent, neither agreed, nor opposed, nor unrelated to what you said.) If you have f "abc" 123 it's unambiguous, but, if you have g f "abc" 123 "def" there's no sure way to determine where the call to 'f' stopped, and the one to 'g' resumed (or, as in Python, if 'f' was even to be called at all, as opposed to 4 parameters to 'g'). If you allow commas, you can make some progress, though I don't have a rigorous formula. But, for example, g f "abc", 123 "def" can only mean: g( f( "abc", 123 ), "def" ) But something tells me it doesn't extend, especially since commas are used elsewhere than function calls. And certainly, it's not readable at a glance. English has that problem and kind of glaringly, by the way. You don't always know how the speaker's subordinate clauses are nesting. Not just with clauses, but modifiers, as in "The Purple People Eater". So I don't know how you expect to design a programming language after it. From mdw at distorted.org.uk Tue Jan 20 14:31:43 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 19:31:43 +0000 Subject: ifconfig in python References: Message-ID: <871vuxkc4g.fsf.mdw@metalzone.distorted.org.uk> "bruce" writes: [a top-posted monstrosity] > so the question really starts to look like: > > -what's the default listening address for my app (insert nic)? > -what's the default sending address for my app (insert nic)? > -what's the default listening address for my server? > -what's the default sending address for my server? > -what's the default listening address for my (insert nic)? > -what's the default sending address for my (insert nic)? > > any other possibilities?? A TCP server will typically listen on: * all addresses (INADDR_ANY), * localhost (INADDR_LOOPBACK), or * an address explicitly provided by the administrator. (There's a fourth possibility: it might listen separately on each network interface, but that's quite unusual.) Anyway, it ought to know which of these it's doing. When a client connects, it gets the client's address from accept(2) or getpeername(2) and its local address from getsockname(2). A TCP client can find out its address using getsockname(2) after connect(2). So that's easy too. But TCP isn't very interesting here, because both ends know the others' address by the time the connection is established, so there's no point in explicitly sending them. (I suppose you could use explicit addresses to detect NAT routers which aren't doing protocol-specific bodging.) UDP is much messier, since a single socket could be acting as a client or server, or in a strictly symmetrical arrangement. Even so, it's usually much better to have the hosts concerned dredge out their peers' addresses from the packets they receive rather than send them about explicitly. Which is why I'm puzzled as to what this information is actually for. -- [mdw] From joe at strout.net Tue Jan 20 15:08:46 2009 From: joe at strout.net (Joe Strout) Date: Tue, 20 Jan 2009 13:08:46 -0700 Subject: English-like Python In-Reply-To: <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> Message-ID: <49762F4E.1000506@strout.net> Aaron Brady wrote: > Unambiguity and readability are two different things. (This should be > a quasi-tangent, neither agreed, nor opposed, nor unrelated to what > you said.) > > If you have > > f "abc" 123 > > it's unambiguous, but, if you have > > g f "abc" 123 "def" > > there's no sure way to determine where the call to 'f' stopped, and > the one to 'g' resumed (or, as in Python, if 'f' was even to be called > at all, as opposed to 4 parameters to 'g'). Right -- that's exactly why (in RB) parentheses are required around arguments to a method call if that method returns a value (in RB terms, if it is a function rather than a subroutine). Then there is no ambiguity, because only such a function can be used as an argument to another method call (or otherwise be part of an expression). The above would have to be written something like: g f("abc", 123), "def" I'm not saying I know how to translate this into Python -- some of Python's other language features make this difficult. Just pointing out that your original wish is possible in at least some languages. Best, - Joe From catphive at catphive.net Tue Jan 20 15:13:15 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 12:13:15 -0800 Subject: what's the point of rpython? In-Reply-To: <7xfxje8akd.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 3:46 AM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > skip at pobox.com writes: >> Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have >> read what you saw but not recognized it in the C++ punctuation soup. I >> couldn't find what you referred to. Can you provide a URL? > > http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety I think you are misreading that. It says that multiple assignments to different copies of a share_ptr in different threads are fine. This is the important bit because copies of the same pointer share the same reference count, and assignments and resets will decrement that ref count. They say they don't handle mutations of the *same* pointer in different threads, which is a different issue. The programmer is responsible for synchronizing access to the pointer, and the pointed to object, but not the ref count. This may be not be obvious if you don't use shared_ptr a lot. You also mentioned in an earlier post that most processors don't support automic increments... I'm hesitant to dispute you here because this is outside of my field of expertise. However, a quick google search for "x86 atomic increment" comes up with this: XADD http://www.codemaestro.com/reviews/8 http://siyobik.info/index.php?module=x86&id=159 Again, I'm not an assembly guru, but his sounds like exactly what you'd want. It gains exclusive access to system memory in a multi-processor environtment without leaving user space. Thus XADD is an atomic increment/decrement. It would be educational if someone more famliar with x86 than me could speak to the performance merits of this on modern multicore machines. From rhamph at gmail.com Tue Jan 20 15:18:09 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:18:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: On Jan 20, 12:04?pm, "Russ P." wrote: Hey, if pylint can reliably detect private data access violations, > that's good news to me. I haven't used it, so I don't know. (I used > pychecker a while back, but I haven't used that for a while either.) > > If pylint can check access violations, then it seems to me that > someone (who is familiar with the internals of the Python interpreter) > should be able to integrate that feature into Python itself relatively > easily. > > Actually, in addition to the enforcement of "private," you also need > the enforcement of "protected." If you only enforce "private," derived > classes will not have access to data they need. And if you don't > enforce "protected," then anyone can trivially gain access to private > data by simply deriving a new class. It would be like having a lock on > the door with the key hanging right there on a string. > > I realize that this complicates matters. As I said before, I am not > claiming that Python should necessarily get enforced data hiding. All > I am saying is that, if it doesn't get it, it will never be > appropriate for certain domains. But maybe nobody cares about that > except me. If pylint had "private" it should behave like "protected". Basic encapsulation is about good style (separation of concerns), not security, and subclassing is a clear statement that this concern is closely related. Of course if you accept that the extremism of security is a separate issue then you have the question of how much is necessary to encourage separation of concerns, and and what should be available to work around it... > The other problem with the pylint approach is aesthetic: the > requirement for a leading underscore to indicate private data. I > realize that some actually like that convention, but I don't. I spend > most of my development time working with "private" data, and why > should I have to look at that litter everywhere? I use Python in part > because I want clean looking code, and leading underscores bother me > -- just as the leading dollar signs in Perl bother many Python > programmers. There needs to be *some* indicator that separates a public property from a private one. What would you suggest? From rridge at csclub.uwaterloo.ca Tue Jan 20 15:19:39 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Tue, 20 Jan 2009 15:19:39 -0500 Subject: what's the point of rpython? References: <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: Carl Banks wrote: >I just looked at the boost documentation, which claims that multiple >asynchronous writes to the same shared_ptr results in undefined >behavior. That will not suffice for Python reference counting. If you read the Boost documentation you'll see that while multiple simulaneous writes to a shared_ptr *instance* isn't supported, multiple simulataneous updates of the reference counter used by the shared_ptr implementaiton is supported. Example #1 in the URL that Paul Rubin gave demonstrates this. The allowed simulanteous assignment of the two shared_ptr instances "p2" and "p3" from the same shared_ptr instance "p", requires that a single reference count be incremented simultenously. On the other hand, the documentation also notes that the implementation is only lock free on x86, IA-64, and PowerPC systems, though I think it would also be possible on MIPS CPUs. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From kdawg44 at gmail.com Tue Jan 20 15:19:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 15:19:45 -0500 Subject: Overloading Methods In-Reply-To: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> Message-ID: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> Can I have multiple __inits__ with different parameters passed in? > >> > > Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Tue Jan 20 15:19:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 15:19:45 -0500 Subject: Overloading Methods In-Reply-To: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> Message-ID: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> Can I have multiple __inits__ with different parameters passed in? > >> > > Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 20 15:34:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jan 2009 12:34:49 -0800 Subject: Overloading Methods In-Reply-To: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Message-ID: <50697b2c0901201234h5d5df5ecu344aa8f6dc1b5462@mail.gmail.com> (top-posting just for consistency) In that case, you might also be interested in: http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris On Tue, Jan 20, 2009 at 12:19 PM, K-Dawg wrote: > Thank you for the explanation. With my background in Java, I have to get > myself to think a little differently. > Kevin > > > On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: >> >> On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: >> > K-Dawg wrote: >> >> >> >> Can you overload methods in Python? >> >> >> >> Can I have multiple __inits__ with different parameters passed in? >> >> >> > Simple answer: no. >> >> More complicated answer: Yes, with some caveats. >> >> You usually don't need to overload methods in Python since you can use >> default and keyword arguments instead. For instance: >> >> class Foo(object): >> def __init__(self, a, b=10, c=None): >> self.a = a >> self.b = b >> if c is None: c = [] >> self.c = c >> >> #example use >> x = Foo("#", 4, [6,7]) >> y = Foo("@") >> z = Foo("!", c=[1,2]) >> >> Whereas in Java or C++ this would require several overloads, it can be >> succinctly expressed as a single method in Python. >> >> However, if you want the overloads to accept completely different >> types as parameters, then it arguably should expressed as distinct >> methods rather than "overloads". In the special case of __init__, you >> might want to make the alternate initializers classmethods or factory >> functions. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana... >> http://rebertia.com >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Follow the path of the Iguana... http://rebertia.com From rhamph at gmail.com Tue Jan 20 15:36:11 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:36:11 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <4438eca0-ded3-4223-a80a-5ad3cc2d718d@g1g2000pra.googlegroups.com> On Jan 16, 5:37?pm, "Brendan Miller" wrote: > So I kind of wanted to ask this question on the pypy mailing list.. > but there's only a pypy-dev list, and I don't want to put noise on the > dev list. > > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? There are some distinct benefits of RPython: * starts up as real python code, letting you define globals that later get "snapshotted" into static code * can be executed using a real python interpreter, getting much more reliable debugging (but broken rpython code might run fine under python) * provides a clear avenue for extension, by adding more python features You might argue just having a python syntax is also a benefit, but the semantics are so different as to more than counteract it. Add in the cost of implementing your own compiler... yeah. From sjmachin at lexicon.net Tue Jan 20 15:41:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 12:41:28 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> Message-ID: <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> On Jan 21, 5:31?am, gert wrote: > On Jan 20, 5:23?am, John Machin wrote: > > > On Jan 20, 12:54?pm, gert wrote: > > > > How do you convert s back to binary data in python 3 so I can put in a > > > sqlite blob ? > > > Is there a build in function or do I need to use binascii ? > > > byte(s) or bin(s) would make more sense but can not figure it out ? > > > Can't imagine why you would do str(binary_data) especially if you want > > it back again ... however: > > def application(environ, response): > ? ? s = str(environ['wsgi.input'].read()) > ? ? b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group > (1) > ? ? p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n > (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) > ? ? db.execute('UPDATE users SET picture=? WHERE uid=?', > (p,session.UID)) > [snip] > > > Looks like it's [it being eval(str(blob))] going to work, but you better be rather sure that you > > trust the source. > > Any other suggestions ? Yeah. (a) don't write obfuscatory code :-0 E.g. (1) re.compile(pattern).search(data) -> re.search(pattern, data) (2) re.compile(pattern).match(data) -> re.match(pattern, data) (3) re.match('.*blahblah', data) -> re.search('blahblah', data) (b) don't use re when ordinary str or bytes methods will do E.g. instead of: b = re.search('boundary=(.*)'), environ['CONTENT_TYPE']).group(1) try b = environ['CONTENT_TYPE'].split('boundary=')[1] (c) Is that code meant to be rough pseudocode to illustrate what you are trying to do, or is it meant to be working code? If the latter: * Do you have this working in 2.X? * Are you sure the pattern to retrieve the picture is correct? * What is the "Content-Transfer-Encoding"? (d) Surely there must be a library somewhere that parses that kind of data for you ... (e) if all else fails, I'd suggest: instead of s = str(binary) do s = binary.decode('latin1') # this won't change the number of characters and will allow # reconstitution of your non-ascii bytes Then do your DIY parsing then at the end do blob = p.encode('latin1') # blob will be type bytes which is presumably what the database expects HTH, John From wgrigg at draper.com Tue Jan 20 15:43:27 2009 From: wgrigg at draper.com (bill) Date: Tue, 20 Jan 2009 12:43:27 -0800 (PST) Subject: python processes and Visual Studio References: <17ef3ab2-0aec-4660-921b-190a5cab45f5@r15g2000prd.googlegroups.com> Message-ID: <57d6a9d3-4a21-4d55-acdd-d0154973ccbe@r34g2000vbp.googlegroups.com> On Jan 19, 9:24?am, bill wrote: > All, > > This may sound somewhat convoluted, but here goes: > > 1. I have a Python script that invokes builds in Visual Studio via the > command line interface - 'devenv' > 2. It works GREAT > 3. I have added a post_build event to a VS Solution that has but one > project. > 4. This event invokes a Python command - 'c:\python25\python.exe c: > \....myPython.py' > 5. It works GREAT > 6. I move on the another VS Solution that has 6 projects. > 7. I add the post_build event command to all 6 projects > 8. It 'almost' works... all 6 projects build and the post_build event > triggers in all 6 projects and that works > 9. Unhappily, the whole thing then 'hangs' > > I am guessing that perhaps a sub-process or something like that is not > exiting. The Python script that is triggered in the post_build event, > myPython.py, does nothing special upon exit. Should it? > > Or, is there some way to determine why the the while thing 'hangs'? > > TIA, > > Bill All, Please ignore this post (if you already haven't). Whatever the problem is, it has absolutely nothing to do with Python. Sorry about that From bjracine at glosten.com Tue Jan 20 15:48:22 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Tue, 20 Jan 2009 12:48:22 -0800 Subject: English-like Python In-Reply-To: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8BCB5@clipper.glosten.local> Doesn't ipython (the interactive shell) make this possible in some cases... not that's what you seem to be looking for exactly. Ben Racine -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of Aaron Brady Sent: Tuesday, January 20, 2009 10:14 AM To: python-list at python.org Subject: Re: English-like Python On Jan 17, 6:10?pm, The Music Guy wrote: > Wow, impressive responses. > > It sounds like the general consensus is that English would not be a > good choice for programming even if there were an interpreter capable > of turning human language into machine language. But that makes sense; > even English professionals have trouble understanding each other sometimes. > Until that problem is somehow overcome, there's not much hope of > computers to overcome it. I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. f "abc" 123 --> f( "abc", 123 ) It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. -- http://mail.python.org/mailman/listinfo/python-list From rhamph at gmail.com Tue Jan 20 15:52:32 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:52:32 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> On Jan 19, 9:00?pm, "Brendan Miller" wrote: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. "lock free" is largely meaningless. What it really means is "we use small hardware locks rather than big software locks, thereby reducing (but not eliminating!) the contention". Atomic refcounting is easy. If done sparingly to minimize contention it works great. Python uses refcounting massively with heavily contended objects (think about your builtin types, constants, globals, classes, etc.) It does not perform acceptably for python. The second issue is the objects themselves, like a list which is mutable. If you're using it in a single thread or writing from multiple threads this is a non-trivial constant cost. If your object is not modified after creation and is read from many threads a lock would be a point of contention, preventing you from scaling freely. The dicts used by classes and globals are an import example of this, and a successful implementation needs something non-contending. I assume Jython and IronPython do this. From rtw at freenet.co.uk Tue Jan 20 15:53:16 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 20 Jan 2009 14:53:16 -0600 Subject: Python 3: exec arg 1 References: Message-ID: Alan G Isaac wrote in news:myhdl.805$Aw2.484 at nwrddc02.gnilink.net in comp.lang.python: > On 1/18/2009 9:36 AM Alan G Isaac apparently wrote: >> I do not much care about the disappearance of ``execfile``. >> I was asking, why is it a **good thing** that >> ``exec`` does not accept a TextIOWrapper? >> Or is it just not implemented yet? >> What is the gain from this particular backwards >> incompatibility (in the sense that ``exec(open(fname))`` >> no longer works)? > > Still interested in an answer... > Alan Isaac http://bugs.python.org/issue1762972 (*) IIRC, exec(open(fname).read()) is the Py 3.0 replacement. *) For reference, 2 clicks away from Rob. -- http://www.victim-prime.dsl.pipex.com/ From gh at ghaering.de Tue Jan 20 16:28:00 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 20 Jan 2009 22:28:00 +0100 Subject: PyQt4 on Windows ? In-Reply-To: References: Message-ID: <6tmtv0Fbhj05U1@mid.uni-berlin.de> Linuxguy123 wrote: > What does it take to get a PyQt4 application running on a Windows > machine ? To run, installing Python + PyQt4 ;-) To create a binary wrapper, I use py2exe (I also tried cx_Freeze, both work the same). There's a gotcha with PyQt4 - snippet follows: setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "includes": ["sip"], "excludes": []}}, service = [], com_server = [], console = [], windows = [modeler], ) You need to include the "sip" module manually, it's not automatically discovered. To create an installer, I use NSIS. > I'm sorry if this is a redundant question, but I've searched this and I > am not finding a comprehensive answer. > > If anyone is running a PyQt4 application on a Windows (XP or Vista) > machine, I'd love to know how it works for you It works fine in a test setup. I didn't pursue this any further at the moment, because for the project in question we decided to deploy on MacOS X first and delay the Windows version. > and how extensive the application is and how much of the Qt library it uses. The application is currently 1200 LOC, 200 of which are autogenerated from Qt designer files. The final application will probably be about three times as large. It's a modeler application and I most of the code is thus centered around QGraphicsScene and two custom QGraphicsItems - one for nodes, one for edges. It's been a real pleasure that I get most functionality for the modeling app for free with (Py)Qt. -- Gerhard From http Tue Jan 20 16:30:21 2009 From: http (Paul Rubin) Date: 20 Jan 2009 13:30:21 -0800 Subject: what's the point of rpython? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: <7xr62x3bte.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > > http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety > > I think you are misreading that. It says that multiple assignments to > different copies of a share_ptr in different threads are fine. I'll respond to this later. > http://www.codemaestro.com/reviews/8 > http://siyobik.info/index.php?module=x86&id=159 > > Again, I'm not an assembly guru, but his sounds like exactly what > you'd want. It gains exclusive access to system memory in a > multi-processor environtment without leaving user space. Thus XADD is > an atomic increment/decrement. It would be educational if someone more > famliar with x86 than me could speak to the performance merits of this > on modern multicore machines. Those links describe using the LOCK prefix, which as the name implies, asserts a lock, so it is no longer "lockless reference counting". The LOCK prefix adds about 100 cycles to the instruction. From http Tue Jan 20 16:39:39 2009 From: http (Paul Rubin) Date: 20 Jan 2009 13:39:39 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> Message-ID: <7xmydl3bdw.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > "lock free" is largely meaningless. What it really means is "we use > small hardware locks rather than big software locks, thereby reducing > (but not eliminating!) the contention". At least in the case of Haskell's "software transactional memory", reads are genuinely lock free in the normal uncontended case. You use LOCK XCHG to increment a counter in the object when you want to update, and increment it again when you are done updating. Since the counter starts at 0, any time it has an odd value, an update is in process and any other thread can notice that the object is locked and try again later without asserting any locks itself. If the counter has an even value, it is unlocked, but there is a chance that a writer thread can lock and udpate the object while a reader thread has a lockless access in progress. The reader detects this has occurred when it finishes its transaction, read the counter a second time, and notices that the counter has been incremented (maybe more than once) since the transaction started; it then rolls back its operation and tries again. I'm not explaining that well so you can read about it in SPJ's paper or Keir Fraser's. > The second issue is the objects themselves, like a list which is > mutable. If you're using it in a single thread or writing from > multiple threads this is a non-trivial constant cost. If your object > is not modified after creation and is read from many threads a lock > would be a point of contention, preventing you from scaling freely. > The dicts used by classes and globals are an import example of this, > and a successful implementation needs something non-contending. I > assume Jython and IronPython do this. I'm pretty sure Jython makes no attempt at all to mess with ref counts--it just relies on the underlying Java gc. I have no idea about IronPython. From google at mrabarnett.plus.com Tue Jan 20 16:49:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 21:49:57 +0000 Subject: English-like Python In-Reply-To: <49762F4E.1000506@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> <49762F4E.1000506@strout.net> Message-ID: <49764705.6060009@mrabarnett.plus.com> Joe Strout wrote: > Aaron Brady wrote: > >> Unambiguity and readability are two different things. (This should be >> a quasi-tangent, neither agreed, nor opposed, nor unrelated to what >> you said.) >> >> If you have >> >> f "abc" 123 >> >> it's unambiguous, but, if you have >> >> g f "abc" 123 "def" >> >> there's no sure way to determine where the call to 'f' stopped, and >> the one to 'g' resumed (or, as in Python, if 'f' was even to be called >> at all, as opposed to 4 parameters to 'g'). > > Right -- that's exactly why (in RB) parentheses are required around > arguments to a method call if that method returns a value (in RB terms, > if it is a function rather than a subroutine). Then there is no > ambiguity, because only such a function can be used as an argument to > another method call (or otherwise be part of an expression). The above > would have to be written something like: > > g f("abc", 123), "def" > > I'm not saying I know how to translate this into Python -- some of > Python's other language features make this difficult. Just pointing out > that your original wish is possible in at least some languages. > Next you'll be saying that print(x) in Python 3.x should become print x in python 4.x! :-) From max at alcyone.com Tue Jan 20 16:58:49 2009 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Jan 2009 13:58:49 -0800 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) >> >> It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. Logo, of all things, doesn't require parentheses at all, since functions ("procedures") take a fixed number of arguments. Parentheses are only required when you're adding optional arguments. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Conversation is the enemy of good wine and food. -- Alfred Hitchcock From rhamph at gmail.com Tue Jan 20 17:02:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 14:02:24 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> Message-ID: <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> On Jan 20, 2:39?pm, Paul Rubin wrote: > Rhamphoryncus writes: > > "lock free" is largely meaningless. ?What it really means is "we use > > small hardware locks rather than big software locks, thereby reducing > > (but not eliminating!) the contention". > > At least in the case of Haskell's "software transactional memory", > reads are genuinely lock free in the normal uncontended case. ?You use > LOCK XCHG to increment a counter in the object when you want to > update, and increment it again when you are done updating. ?Since the > counter starts at 0, any time it has an odd value, an update is in > process and any other thread can notice that the object is locked and > try again later without asserting any locks itself. ?If the counter > has an even value, it is unlocked, but there is a chance that a writer > thread can lock and udpate the object while a reader thread has a > lockless access in progress. ?The reader detects this has occurred > when it finishes its transaction, read the counter a second time, and > notices that the counter has been incremented (maybe more than once) > since the transaction started; it then rolls back its operation and > tries again. ?I'm not explaining that well so you can read about it in > SPJ's paper or Keir Fraser's. a) The contended case is the issue, not the uncontended case. An uncontended lock is just constant overhead, not a barrier to scalability b) Locks on linux (since the switch to futexes) are pretty close to free when uncontended. Transactions are really for different properties: a) read patterns can be uncontended (fully scalable) b) a preempted writer does not block other writers, guaranteeing forward progress c) ad-hoc combination of several objects into a single atomic update > > The second issue is the objects themselves, like a list which is > > mutable. ?If you're using it in a single thread or writing from > > multiple threads this is a non-trivial constant cost. ?If your object > > is not modified after creation and is read from many threads a lock > > would be a point of contention, preventing you from scaling freely. > > The dicts used by classes and globals are an import example of this, > > and a successful implementation needs something non-contending. ?I > > assume Jython and IronPython do this. > > I'm pretty sure Jython makes no attempt at all to mess with ref > counts--it just relies on the underlying Java gc. ?I have no idea > about IronPython. The second issue has *nothing* to do with refcounts. It is the objects themselves. A classic example is trying to do "i += 1", which breaks down into "i = i + 1", which isn't an atomic operation. Java's ConcurrentHash map gets this right. From domelectric at gmail.com Tue Jan 20 17:09:33 2009 From: domelectric at gmail.com (debug) Date: Tue, 20 Jan 2009 14:09:33 -0800 (PST) Subject: frequency analysis without numpy Message-ID: Hi- I've been using python now for about 2 months for plugin development within Maya (a commercial 3d application). I'm currently in the process of writing a sound analysis plugin for maya and have completed a good portion of it including the ability to retrieve the amplitude at certain intervals from a wav file. The next part of the project however consists of analysing the wav file and outputting the amplitude at certain frequencies. Due to the need of distributing this to many computers after it has been finished I'm reluctant to use an external python module for FFT'ing. Accuracy and speed aren't really issues as just a generalisation of the amplitude of low, medium and high frequencies is required. Do you either know of any generic FFT functions written in python that could just be inserted into my processing class (open source licensed). So far i've managed to put together a chunk of code but I'm not sure its returning the right values, any ideas? import wave import sys import array import struct from cmath import pi, exp def nextpow2(i): n = 2 while n < i: n = n * 2 return n def bitrev(x): N, x = len(x), x[:] if N != nextpow2(N): raise ValueError, 'N is not power of 2' for i in range(N): k, b, a = 0, N>>1, 1 while b >= a: if b & i: k = k | a if a & i: k = k | b b, a = b>>1, a<<1 if i < k: # important not to swap back x[i], x[k] = x[k], x[i] return x def fft(x, sign=-1): N, W = len(x), [] for i in range(N): # exp(-j...) is default W.append(exp(sign * 2j * pi * i / N)) x = bitrev(x) m = 2 while m <= N: for s in range(0, N, m): for i in range(m/2): n = i * N / m a, b = s + i, s + i + m/2 x[a], x[b] = x[a] + W[n % N] * x[b], x[a] - W[n % N] * x [b] m = m * 2 return x def ifft(X): N, x = len(X), fft(X, sign=1) # e^{j2\pi/N} for i in range(N): x[i] = x[i] / float(N) return x fp = wave.open("hankuncom.wav","rb") sample_rate = fp.getframerate() total_num_samps = fp.getnframes() fft_length = 4096 num_fft = (total_num_samps / fft_length ) - 2 temp = [] for i in range(num_fft): tempb = fp.readframes(fft_length) moo = struct.unpack("%uh"%(fft_length),tempb) temp.append(moo) listed = list(temp[0]) freq_pwr = fft(listed) print(freq_pwr) fp.close() Quick warning this code snippet does run slowly Thanks! The wav file referenced in the script is here: www.reality-debug.co.uk/hankuncom.zip From mdw at distorted.org.uk Tue Jan 20 17:17:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 22:17:26 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Actually, in addition to the enforcement of "private," you also need > the enforcement of "protected." Oh, heavens. If you want C++ or any of its progeny, you know where to find them. Besides, those languages have a horrific design mistake because they conflate the class system (which manages the units of behaviour) with the module system (which deals with the units of implementation). It's precisely because Python's boundaries are fairly porous that it doesn't fall into this trap. (There's the small matter of sharing the class and instance attribute namespaces, but a little bit of care seems to work out OK.) Even so, why do you think you are that you know better than the next programmer -- whoever he might be -- which parts of your class he should mess with? You can make suggestions, recommendations, in your documentation: provide the raw materials so that he can make informed decisions about whether he wants to mess with your class's internals. But the `here's a black box: there isn't and never will be any justifiable reason why you might want to poke about inside' control-freakery of people who like this sort of thing just rubs me up the wrong way. Yes, I know that some people have to work with drooling idiots who don't know a stable interface from volatile implementation details or documented behaviour from a bug that'll be fixed in the next version. Python just isn't the right language for those people. They can use Java or something -- hey, it's presumably good for something, maybe it's this -- but those who know better don't deserve to be penalized for their sake. -- [mdw] From rridge at csclub.uwaterloo.ca Tue Jan 20 17:22:07 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Tue, 20 Jan 2009 17:22:07 -0500 Subject: what's the point of rpython? References: <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: >Those links describe using the LOCK prefix, which as the name implies, >asserts a lock, so it is no longer "lockless reference counting". No, it doesn't assert a lock in the sense used in this thread. On modern Intel systems it's normally handled completely within the cache. >The LOCK prefix adds about 100 cycles to the instruction. That's unavoidable. It's still faster than spin lock, which would also have to use syncronizing instructions. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From Russ.Paielli at gmail.com Tue Jan 20 18:11:59 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 15:11:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Rather than waste more time replying to your post, Let me just refer you to an excellent post that you may have missed earlier in this thread by Mr. D'Aprano: http://groups.google.com/group/comp.lang.python/msg/d684d43b64a6e35a From sturlamolden at yahoo.no Tue Jan 20 18:13:44 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 20 Jan 2009 15:13:44 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: On Jan 20, 11:09?pm, debug wrote: > So far i've managed to put together a chunk of code but I'm not sure > its returning the right values, any ideas? Don't use the periodogram for frequency analysis; it is not a good estimate of the power spectrum. According to the Wiener-Khintchin theorem, the power spectrum is the Fourier transform of the autocorrelation, not the Fourier transform of the signal. You don't want to just FFT the signal. FFTs are used for spectral estimation, but not to obtain the periodogram. The periodogrgam is full of noise and spectral leakage. And even worse, the variance of the periodogram is constant, not inversely proportional to the number of samples. This is not how you want a spectrum estimator to behave. Consider using Thompson's multitaper method, autoregression (maximum entropy), or Welch method for your frequency estimates. Blackman- Tuckey is also a possibility, but I see no reason to prefer that to Welch. Multitaper and AR tends to be the better options though, but they are not as fast as Welch' method. You probably also want to use real FFTs instead of complex FFTs, unless you are interested in estimating the negative frequencies as well. For common spectral analysis, real FFTs are almost always what you want (complex FFTs can be used, but the incur redundant work). Apart from that, an FFT in pure python is going to be atrociously slow for anything but the shortest signals. I cannot imagine why you want to do this. There are many free FFT libraries around, including FFTPACK (used by NumPy) and FFTW. The easiest way to check your FFT is to compare with a verified implementation. I'd use NumPy or Matlab for that. S.M. From gert.cuykens at gmail.com Tue Jan 20 18:21:36 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 15:21:36 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> Message-ID: <3663bf09-fd2e-476e-b026-f42905cc2e1b@y1g2000pra.googlegroups.com> On Jan 20, 9:41?pm, John Machin wrote: > On Jan 21, 5:31?am, gert wrote: > > > On Jan 20, 5:23?am, John Machin wrote: > > > > On Jan 20, 12:54?pm, gert wrote: > > > > > How do you convert s back to binary data in python 3 so I can put in a > > > > sqlite blob ? > > > > Is there a build in function or do I need to use binascii ? > > > > byte(s) or bin(s) would make more sense but can not figure it out ? > > > > Can't imagine why you would do str(binary_data) especially if you want > > > it back again ... however: > > > def application(environ, response): > > ? ? s = str(environ['wsgi.input'].read()) > > ? ? b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group > > (1) > > ? ? p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n > > (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) > > ? ? db.execute('UPDATE users SET picture=? WHERE uid=?', > > (p,session.UID)) > > > (a) don't write obfuscatory code :-0 > > E.g. > (1) re.compile(pattern).search(data) -> re.search(pattern, data) > (2) re.compile(pattern).match(data) -> re.match(pattern, data) > (3) re.match('.*blahblah', data) -> re.search('blahblah', data) > > (b) don't use re when ordinary str or bytes methods will do > > E.g. instead of: > b = re.search('boundary=(.*)'), environ['CONTENT_TYPE']).group(1) > try > b = environ['CONTENT_TYPE'].split('boundary=')[1] > > (c) Is that code meant to be rough pseudocode to illustrate what you > are trying to do, or is it meant to be working code? If the latter: > * Do you have this working in 2.X? yep > * Are you sure the pattern to retrieve the picture is correct? yep http://91.121.53.159/file.txt > * What is the "Content-Transfer-Encoding"? print (environ['Content-Transfer-Encoding'],file=sys.stderr) Key error flash 10 does not send it ? > (d) Surely there must be a library somewhere that parses that kind of > data for you ... p = FieldStorage(fp=environ['wsgi.input'], environ=environ) In python 3 you get TypeError: Can't convert 'bytes' object to str implicitly > (e) if all else fails, I'd suggest: > > instead of s = str(binary) > do s = binary.decode('latin1') > # this won't change the number of characters and will allow > # reconstitution of your non-ascii bytes > Then do your DIY parsing > then at the end do > blob = p.encode('latin1') > # blob will be type bytes which is presumably what the database > expects Victory :) http://91.121.53.159/appwsgi/www/register/register.htm http://code.google.com/p/appwsgi/source/browse/trunk from db import Db from session import Session from re import search,match,DOTALL def application(environ, response): db = Db() cookie = "SID="+environ['QUERY_STRING'] session = Session(db,cookie,'guest') response('200 OK', [('Content-type', 'text/xml'), ('Set-Cookie', session.COOKIE)]) if not session.GID : return [] s = environ['wsgi.input'].read().decode('latin1') b = search(r'boundary=(.*)',environ['CONTENT_TYPE']).group(1) p = search(r'Content-Type: application/octet-stream\r\n\r\n(.*)\r \n--',s,DOTALL).group(1) db.execute('UPDATE users SET picture=? WHERE uid=?',(p.encode ('latin1'),session.UID)) xml = "" xml+= ""+str(db.ERROR)+"" response('200 OK', [('Content-type', 'text/xml')]) return [xml] From aahz at pythoncraft.com Tue Jan 20 18:48:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 15:48:45 -0800 Subject: Style of "raise" (was Re: message of Exception) References: Message-ID: In article , Terry Reedy wrote: >Steven Woody wrote: >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" > >In 2.x you may and in 3.0 you must write that as >raise MyError("my message") >Best to start looking forward ;-). Funny, when I suggested to MvL that he do that (when I saw a checkin made against 2.x code), he rebuffed me. I didn't get a clear answer for why, so if you care, you need to ask him. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From gert.cuykens at gmail.com Tue Jan 20 19:38:33 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 16:38:33 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> <3663bf09-fd2e-476e-b026-f42905cc2e1b@y1g2000pra.googlegroups.com> Message-ID: <60133b5c-bb56-4d2a-8b76-18c3b9a13a21@z28g2000prd.googlegroups.com> b = environ['CONTENT_TYPE'].split('boundary=')[1] oops forgot, is indeed better solution :) From afriere at yahoo.co.uk Tue Jan 20 19:45:37 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Tue, 20 Jan 2009 16:45:37 -0800 (PST) Subject: English-like Python References: Message-ID: On Jan 16, 12:02?pm, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. I'm reminded of Lingua::Romana::Perligata which was done in Perl rather than Python, with the far more noble aim of programming in a language no longer spoken. ;) From aahz at pythoncraft.com Tue Jan 20 19:46:57 2009 From: aahz at pythoncraft.com (Aahz) Date: Tue, 20 Jan 2009 16:46:57 -0800 Subject: REMINDER: OSCON 2009: Call For Participation Message-ID: <20090121004657.GA25868@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From rhodri at wildebst.demon.co.uk Tue Jan 20 20:05:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:05:18 -0000 Subject: Two questions about style and some simple math In-Reply-To: <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> References: <497525C3.5090904@gmx.net> <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 02:11:24 -0000, Mensanator wrote: > On Jan 19, 7:44?pm, "Rhodri James" > wrote: >> Surely in any case you don't want an expression based on the difference, >> since that would give you the same chance of having the first attack no >> matter what the levels of courage actually were, which can't be right. > > Why? Isn't it possible some attributes are relative rather than > absolute? You're right, of course. I blame lack of sleep. What I should have said was that you shouldn't have the random factor scaled to the difference. That way (as with the original code) your attributes aren't even relative, they're pretty much irrelevant. -- Rhodri James *-* Wildebeeste Herder to the Masses From mdw at distorted.org.uk Tue Jan 20 20:11:00 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 01:11:00 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > The consequence of this dynamism is that the Python VM can't do many > optimizations at all, because *at any time* somebody might mess with the > implementation. But 90% of the time nobody does, so Python is needlessly > slow 90% of the time. Wouldn't it be nice if there was a way to speed up > that 90% of the time while still allowing the 10% to take place? There is. Compile, optimizing aggressively under the assumption that everything will be as you expect. Keep a note somewhere of the assumptions you made. If something violates those assumptions, fall back to a slow version -- or, for bonus points, recompile based on the changed assumptions. CLOS is much more complex and dynamic than Python's object system; but it can be compiled very aggressively. > The current solution to this problem is to try to push as much as > possible into functions written in C: built-ins and custom C > extensions. It's not a bad solution: most Python programs rely on > many C built-ins, which enforces real encapsulation and data > hiding. With the possible exception of mucking about with ctypes, you > simply can't access mess with the internals of (say) lists *at > all*. Is this a bad thing? > > Would it be so terrible if we could do the same thing in pure Python? > Why should I have to write in C if I want the same protection? S'funny. I always considered the lack of transparency in C extensions to be a downside, and a reason to write as much as possible in proper, honest, transparent, dynamic, mess-about-with-able Python. >>> Why leave to coding standards and company policy what can be encoded >>> right into the language? Because nobody can agree what the standards and policy ought to be. > In Unix, file names with a leading dot are hidden in the shell: Bzzt. They're silently not displayed by various things, including the shell's globber, and ls(1). > when you do a file listing, you don't see them. It's not difficult to > get to see them: you just pass -a to the ls command. See? That's ls(1). Not the shell. You did know what you were talking about. > As data hiding goes, it's pretty lame, It's not data hiding, though. It's just not cluttering the view with stuff you probably didn't care about. I'm grateful that I don't have to think about dotfiles unless I really want to -- but I'm also very grateful that I /can/ mess with them when I do want to. > but Python doesn't even suppress _ names when you call dir. Frankly, > I wish that by default it would -- 99% of the time when I call dir, I > *don't* want to see _ names. They just get in the way. That might be plausible. > No it's not. It's *practical*. There are domains where *by law* code > needs to meet all sorts of strict standards to prove safety and > security, and Python *simply cannot meet those standards*. Codswallop. One can prove stuff about Python programs using the same techniques as one uses for any other language. I've done it. Other languages have better automated tools, it's true -- but the techniques are basically the same. > No technology is failure proof. But there's no reason in the world why > most technology can't be idiot-proof. Televisions are idiot-proof, > because they protect people from casual mistakes. If televisions were > built according to the Python model, the internals of the TV would be > exposed, without even a cover. All the major parts would be plug-in > rather than soldered in, and there would be no cover over the parts that > were live. Every year, tens of thousands of people would electrocute > themselves fatally (because parts of the TV holds a massive charge for > days after you unplug them from the mains) but that would be okay, > because you never know when somebody might want to pull out the fly-back > transformer and replace it with a six ohm resistor. That sort of dynamism > is important! Very amusing; but a poor analogy. The Python television comes in a clear Perspex box, which you can undo, should you need to, without any tools. But it holds together well even so. (Real PC cases are sometimes like this.) The parts are plug-in, yes; but dangerous stuff you probably don't want to mess with is covered by a plastic shield with a note on it saying `dangerous stuff in here: if you kill yourself messing with it, it's not my fault'. The plastic shields don't fall off of their own accord, but you can remove them without much difficulty should you be so inclined. >>> To prevent that sort of thing from happening, the management could >>> decree that henceforth all "private" variable names will start with an >>> underscore. Problem solved, eh? >> >> Certainly not. The only way to solve such a problem is to fire this >> cretin. > > Again, we shouldn't enforce encapsulation and data hiding because there > are legitimate reasons for breaking it, but anyone who does break it is a > cretin. You have a very strange attitude. I suppose it depends on the circumstances. I must have missed the earlier details, but there's not enough in the stuff above to prove a charge of cretinhood. I didn't see any ill-effects noted, for a start. > It's also bad for moral when you fire somebody for messing with the > internals when you have a policy that it is allowed to mess with the > internals. That's why you picked a dynamic language like Python in the > first place, because it doesn't prevent you from messing with the > internals. And now when somebody does, you sack him? If he did it unilaterally, without consulting other people or mentioning the risks, then that's irresponsible. If there was proper consultation and the decision was made for good -- and agreed -- reasons, then, well, it's a thing to keep in mind for later. May still be a net win. Hard to say. Python can be a sharp tool. Keeping sharp tools away from those who may injure themselves and others is a good idea. That doesn't mean that we shouldn't have sharp tools. It's hard to cut meat with a tenderizer. > Perhaps it would have been better to prevent him from messing with the > internals in the first place, even at some extra cost. When you're in > business, you have to make decisions like: > > * do I write the software in Python, which will have a 99% chance of > costing $100,000 and a 1% chance of costing $100,000,000? > > * or do I write it in a B&D language like Java, which will have a 100% > chance of costing $2,000,000? Easy. 1,099,000 < 2,000,000, so stick with Python. (In real life, we don't know the probabilities in advance, so the question is trickier.) >>>> from protection import unlock > > I don't know if this scenario is even possible in Python, but pretend > that it is. Would it be so terrible? I could probably live with it. It seems like a step back towards Blub[1] to me, though. The Blub programmers already have Blub. Lock the knives in the cupboard because the village idiot sometimes cuts himself. [1] http://www.paulgraham.com/avg.html -- [mdw] From mdw at distorted.org.uk Tue Jan 20 20:16:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 01:16:36 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Rather than waste more time replying to your post, Let me just refer > you to an excellent post that you may have missed earlier in this > thread by Mr. D'Aprano: I've responded to that now. (Steven and I can't even agree on a description for simple parts of Python semantics: why should we agree on this?) But I note that you've cunningly avoided responding to my remark that it's a mistake to conflate the module and class systems. (I think only Common Lisp gets this right, because it can use its package system to manage the names of class and instance slots and generic functions.) Besides, it's not just classes that have internal parts. Python is not Java: not all functionality is in classes. The proposals I've seen do nothing for internal variables or functions at module level. -- [mdw] From rhodri at wildebst.demon.co.uk Tue Jan 20 20:34:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:34:37 -0000 Subject: reading file to list In-Reply-To: <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 03:39:45 -0000, Xah Lee wrote: > On Jan 19, 4:49 pm, "Rhodri James" > wrote: >> On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: >> > On Jan 17, 10:25 am, Tino Wildenhain wrote: >> >> > [[int(x) for x in line.split()] for line in open("blob.txt")] >> >> > Nice (python code). >> >> > Few comments: >> >> > ? the above code is borderline of atypical. e.g. it is not a average >> > python code would produce or one'd seen in corporate python code. >> >> I can't imagine why not. > > consider code produced by corporations, as opposed to with respect to > some academic or philsophical logical analysis. Looked in another way, > consider if we can compile stat of all existing pyhton code used in > real world, you'll find the above style is rarely used. I *was* thinking of code produced in the real world, and I don't buy your assertion. I'm not an academic, and I wouldn't hesitate to lay down a line of code like that. As I said before, it fits into English language idioms naturally, and as a result is pretty self-descriptive. > in a logical analysis, each lang fanatics will actively sell certain > style of construction, but that's just not the way code in the real > world are. Ample examples can be found especially in other cultish > lang groups such as lisp, perl, etc. (less of this phenomenon is found > in lang like php, javascript, java, C, where the lang simple don't > create fancy constructions in the name of improvement or esthetics or > weird philosophy in the first place.) Long experience particularly in C suggests that you are entirely wrong. You are conflating simplicity with flexibility; C is a simple language, but it is very syntactically flexible, and programmers not only can but do regularly and with malice aforethought write horribly convoluted code. Sometimes this is out of cunning (dropping through cases in a switch statement, for instance), sometimes because the language is too simple (function dispatch tables can look gruesome if you aren't careful), and sometimes it's because you need a particular sequence of instructions to get the optimiser to Do The Right Thing; regardless, it happens in a large fraction of non-trivial C programs. >> > The above line illustrate well the ad hoc syntax soup nature python is >> > moving into. >> >> To a native English speaker, it illustrates entirely the reverse. >> List comprehension is actually quite a linguistically natural way >> to express the iterative construction of a list. > > computer lang is not human lang. In argument based on human lang, you > have AppleScript, Perl, which are un-readable or cumbersome to most > programers. Even with human lang, if you know linguistics to some > extend, you know that natural lang is a complete wortheless mess in > every aspect with respect to ?design? qualities. Having studied natural languages, I am well aware that the designers of AppleScript didn't study natural languages. If they had, they'd have been a lot more careful in their choice of constructs to map AppleScript onto English less ambiguously. I can't think of a language less like AppleScript than Perl, which is incomprehesible for entirely different reasons. Grouping them together as if they had anything else in common is... eccentric. Computer languages are not human languages, but computer language constructs do attempt to map onto human language constructs to provide some measure of comprehensibility. Where a construct like list comprehension maps very well onto idiomatic English, dismissing it as "ad hoc syntax soup" is just plain wrong. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Tue Jan 20 20:36:07 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:36:07 -0000 Subject: pep 8 constants In-Reply-To: <87fxje4lqh.fsf@benfinney.id.au> References: <87fxje4lqh.fsf@benfinney.id.au> Message-ID: On Tue, 20 Jan 2009 04:58:30 -0000, Ben Finney wrote: > Unless someone's going to argue that ?Variable Names? doesn't apply to > constant names, even though Python doesn't make the distinction. Python doesn't make the distinction, which is precisely why making the distinction through CONVENTIONAL_NAMING_PRACTICE is useful. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Tue Jan 20 20:42:03 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:42:03 -0000 Subject: what's the point of rpython? In-Reply-To: <7x3afewqwh.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 20 Jan 2009 04:19:26 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Brendan Miller" writes: >> Maybe I'm missing something here but a lock free algorithm for >> reference counting seems pretty trivial. As long as you can atomically >> increment and decrement an integer without locking you are pretty much >> done. > > What cpu's do you know of that can atomically increment and decrement > integers without locking? x86 (and pretty much any 8080 derivative, come to think of it). That said, what you actually need is an atomic read-and-increment, which is a lot harder to find. Even if you could find a platform supporting it, it doesn't help you on other platforms you may need to run on. Just do the locking properly and worry about optimisations later. -- Rhodri James *-* Wildebeeste Herder to the Masses From skip at pobox.com Tue Jan 20 20:48:13 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 20 Jan 2009 19:48:13 -0600 Subject: what's the point of rpython? In-Reply-To: References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: <18806.32477.75414.590588@montanaro.dyndns.org> Rhodri> Just do the locking properly and worry about optimisations Rhodri> later. The locking is already done properly (assuming we are discussing CPython's reference counting). Now is later. People are thinking about lots of optimizations, this is just one of them. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From Russ.Paielli at gmail.com Tue Jan 20 21:25:42 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 18:25:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 20, 5:16 pm, Mark Wooding wrote: > "Russ P." writes: > > Rather than waste more time replying to your post, Let me just refer > > you to an excellent post that you may have missed earlier in this > > thread by Mr. D'Aprano: > > I've responded to that now. (Steven and I can't even agree on a > description for simple parts of Python semantics: why should we agree on > this?) > > But I note that you've cunningly avoided responding to my remark that > it's a mistake to conflate the module and class systems. (I think only > Common Lisp gets this right, because it can use its package system to > manage the names of class and instance slots and generic functions.) > > Besides, it's not just classes that have internal parts. Python is not > Java: not all functionality is in classes. The proposals I've seen do > nothing for internal variables or functions at module level. > > -- [mdw] I'm not sure what you mean by "conflating module and class systems." Are you referring to the fact that Java requires each class to be in its own file of the same name (I don't use Java, but that's what I've heard)? If so, I agree that is a bad idea. Actually, I remember reading years ago that Ada gets this right. I've never used Ada for real work either, but I understand that privacy is managed according to packages and modules rather than classes. That is a more flexible approach and makes more sense. [I realize that Ada is on life support, and I probably sound like a neanderthal for bringing it up so much, but it actually has many advanced features that were well ahead of their time -- and still are to some extent.] In any case, I have suggested that Python should perhaps get a new keyword, "private" or "priv". When used inside a class, it would serve a similar function to what it does in Java, C++, and Scala. If used at the file scope, it could simply restrict the data or function to that module. I think that is how Ada works. From http Tue Jan 20 21:29:01 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:29:01 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: <7xprihmlxu.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > > What cpu's do you know of that can atomically increment and decrement > > integers without locking? > > x86 (and pretty much any 8080 derivative, come to think of it). It would not have occurred to me that "lock inc" increments "without locking". I understand that's different from a lock value sitting in the data object but I thought that "lock-free algorithm" meant one that didn't assert any of these hardware locks either. Maybe I'm wrong. > Just do the locking properly and worry about optimisations later. That has already been tried, and found to be unacceptably slow for the purpose at hand. Now we're looking for the optimizations. From zzbbaadd at aol.com Tue Jan 20 21:34:19 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Tue, 20 Jan 2009 18:34:19 -0800 (PST) Subject: Overloading Methods References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: <678e1f4c-6c7c-445d-95d2-f31f55252c93@r38g2000vbi.googlegroups.com> > > class Foo(object): > def __init__(self, a, b=10, c=None): > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > Not that it's important to the discussion, but, while Java does not have the capability to give default method parameters, C++ does. From http Tue Jan 20 21:35:00 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:35:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xljt5mlnv.fsf@ruckus.brouhaha.com> "Russ P." writes: > [I realize that Ada is on life support, and I probably sound like a > neanderthal for bringing it up so much, but it actually has many > advanced features that were well ahead of their time -- and still are > to some extent.] I have the impression that there has been an uptick of interest in Ada due to the availability of GNAT, which appeared on the scene not all that long ago. I've been interested for a while in using it for something, but haven't done so yet. The main doc I've read about it so far is admittedly a sales pitch, but it's enough to make me believe that writing anything substantial in C or C++ with significant security or safety consequences is both masochistic and irresponsible: http://adahome.com/Ammo/cpp2ada.html I've gotten hold of a couple of Ada books but haven't had the copious free time to look at them very much yet. From wuwei23 at gmail.com Tue Jan 20 21:47:59 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 18:47:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: On Jan 21, 5:04?am, "Russ P." wrote: > If pylint can check access violations, then it seems to me that > someone (who is familiar with the internals of the Python interpreter) > should be able to integrate that feature into Python itself relatively > easily. If pylint performs the data access protection checks you want, then it seems to me that it would be a better idea to mandate the use of pylint on any projects you're working on - either in the IDE or when checking in to a repository - rather than slow down Python as a whole by providing functionality that doesn't seem to be in demand by the majority of users. I've never understood why so many things "must" reside in the language itself when the same effect can be achieved through a well written module. (And that's not even commenting on the whole "I have no skill in this area and only second-hand knowledge that it's possible but it's *obvious* to me that it's trivial and *someone else* should easily be able to do the work for me!" nature of your post...) From http Tue Jan 20 21:52:01 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:52:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <7xk58p4bhq.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > Whaat? Assuming a program is perfect unless a failure is proven > > is not at all a sane approach to getting reliable software. It is > > the person claiming perfection who has to prove the absence of failure. > > No, no. I meant that if pylint works as its specification says it would. Oh, I see. Well, that would be ok, except Pylint is not specified as detecting the types of access that Russ is concerned with. It can't, for example, flag uses of setattr that might affect a particular class. That would take something a lot fancier. From tjreedy at udel.edu Tue Jan 20 21:53:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 21:53:01 -0500 Subject: English-like Python In-Reply-To: <49761EE6.4070306@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) How would you differentiate f 'abc' + 'def' as f('abc') + 'def' versus f('abc' + 'def') > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > Example: > > LogError "Walk has gotten too silly", CurrentTime LogError('walk', Time) # versus LogError('walk'), Time Perhaps RB does not have tuple literals. From tjreedy at udel.edu Tue Jan 20 22:13:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:13:54 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. You did not call it. From tjreedy at udel.edu Tue Jan 20 22:15:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:15:55 -0500 Subject: How to print lambda result ? In-Reply-To: <4975C1F9.6040607@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: Tino Wildenhain wrote: > > or in python <3.0: > > (num,"s"*(num >1)) works fine in 3.0 too >>> num=1 >>> (num,"s"*(num >1)) (1, '') >>> num=2 >>> (num,"s"*(num >1)) (2, 's') Of course, 0 events gets 's' also, so (num!=1) is the actual comparison needed. From google at mrabarnett.plus.com Tue Jan 20 22:16:33 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 03:16:33 +0000 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: <49769391.3020409@mrabarnett.plus.com> Terry Reedy wrote: > Joe Strout wrote: >> Aaron Brady wrote: >> >>> I think it would be a good step if you could make some sensible >>> interpretation of a typical statement without its parentheses. >>> >>> f "abc" 123 >>> --> >>> f( "abc", 123 ) > > How would you differentiate > > f 'abc' + 'def' > as > f('abc') + 'def' > versus > f('abc' + 'def') > >> Such a language is possible -- take a look at REALbasic sometime. RB >> certainly has its problems (mainly bugs), but the language syntax is >> beautiful. To your point, parentheses are not required around any >> method call that (1) has no return value, or (2) requires no >> parameters. Example: >> >> LogError "Walk has gotten too silly", CurrentTime > > LogError('walk', Time) # versus > LogError('walk'), Time > > Perhaps RB does not have tuple literals. > Parentheses wouldn't be required if it's a procedure call (I'm not sure about a function that's called as a procedure) or if there are no parameters to pass. Thus: f 'abc' + 'def' does: f('abc' + 'def') From Russ.Paielli at gmail.com Tue Jan 20 22:18:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 19:18:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> On Jan 20, 6:47 pm, alex23 wrote: > (And that's not even commenting on the whole "I have no skill in this > area and only second-hand knowledge that it's possible but it's > *obvious* to me that it's trivial and *someone else* should easily be > able to do the work for me!" nature of your post...) I never said or even suggested that anything was "trivial." You must have imagined that. Also, I am an aerospace engineer, not a computer scientist, software engineer, or programmer per se. Since when is no one is allowed to suggest a potential improvement to a product unless they are willing to implement it themselves? Imagine what the world would be like if such a rule applied to all products. From aahz at pythoncraft.com Tue Jan 20 22:24:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 19:24:06 -0800 Subject: Regular Expressions... References: Message-ID: In article , Ken D'Ambrosio wrote: > >Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" >the re module. Refer to the following every time you want to use regexes in Python: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski, comp.emacs.xemacs, 8/1997 Although there are times when regexes are your best option, Python has many other good options for processing strings, and your code readability will usually increase if you try one of them first. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From prologic at shortcircuit.net.au Tue Jan 20 22:28:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 13:28:26 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 1:18 PM, Russ P. wrote: > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. Maybe nobody wants what you want ? Besides no-one will improve python for you! Python is a FOSS contributed to by many tedious laborious hours for little to no financial gain for the people that have put in the hard work. So if you insist python must have it, do it yourself ) And for the record, I (and probably 98% of other python developers) don't want your data protection or encapsulation. :) Have a nice day :) cheers James From tjreedy at udel.edu Tue Jan 20 22:41:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:41:57 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: Duncan Booth wrote: > Luis Zarrabeitia wrote: > >> It boggles me when I see python code with properties that only set and >> get the attribute, or even worse, getters and setters for that >> purpose. In my university they teach the students to write properties >> for the attributes in C# ("never make a public attribute, always write >> a public property that just gets and sets it"). I never understood >> that practice either, given that the syntax for attribute access and >> property access in C# is exactly the same. (Could it be that even if >> the syntax is the same, the compiled code differs? Don't know enough >> about .NET to answer that). >> > The compiled code differs. I *strongly* doubt that. Properties are designed to be transparent to user code that access atrributes through the usual dotted name notation precisely so that class code can be changed from x = ob to x = property(get_x, set_x, del_x) without changing user code. CPython compiles attribute access to LOAD_ATTR The code associated with LOAD_ATTR should get the attribute object and check whether it is a property, in which case it calls the proper method of the property. > That doesn't matter if the class is only > accessed from within a single compiled program, but it does matter if you > expose a public interface from a library: if you change a public attribute > into a property then you need to recompile all code which accesses it. Example to back this claim? Perhaps you have found a bug. tjr From tdelaney at avaya.com Tue Jan 20 22:46:32 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 21 Jan 2009 11:46:32 +0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: Message-ID: Terry Reedy wrote: >> The compiled code differs. > > I *strongly* doubt that. Properties are designed to be transparent to > user code that access atrributes through the usual dotted name > notation precisely so that class code can be changed from > x = ob > to > x = property(get_x, set_x, del_x) > without changing user code. He was talking about C# with that statement. In C#, the compiled code differs depending on whether you use a property or an attribute. Or at least that's how I interpreted it. You are of course correct as to how Python does it. Tim Delaney From tjreedy at udel.edu Tue Jan 20 22:51:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:51:38 -0500 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Rhodri James wrote: > Computer languages are not human languages, but computer language > constructs do attempt to map onto human language constructs to > provide some measure of comprehensibility. Where a construct like > list comprehension maps very well onto idiomatic English, dismissing > it as "ad hoc syntax soup" is just plain wrong. Especially given that Python's comprehensions are taken from Haskell's which are taken from mathematics' set builder notation. Also, care was taken to have a correspondance between comprehension syntax and nested for- and if- statement syntax. Someone recently made a proposal that would break that correspondance and which would be 'ad hoc' and it will surely be rejected. tjr From diresu at web.de Tue Jan 20 22:52:46 2009 From: diresu at web.de (Dietrich Bollmann) Date: Wed, 21 Jan 2009 12:52:46 +0900 Subject: How to write a simple shell loop in python? Message-ID: <1232509966.4430.28.camel@pippi.pippi> Hi, I am trying to write a simple shell loop in Python. My simple approach works fine - but the first output line after entering something is always indented by one blank. Is there any logic explanation for this? How can I get rid of the blank? Is there a smarter way to write a simple shell loop which would work better? Thanks, Dietrich Here my approach: $ python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> while (1): ... print "$ ", ... input = sys.stdin.readline() ... input = input.strip() ... print input ... print input ... print input ... $ one one one one $ two two two two $ three three three three $ Traceback (most recent call last): File "", line 3, in KeyboardInterrupt >>> From tjreedy at udel.edu Tue Jan 20 23:16:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 23:16:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: Message-ID: Delaney, Timothy (Tim) wrote: > Terry Reedy wrote: > >>> The compiled code differs. >> I *strongly* doubt that. Properties are designed to be transparent to >> user code that access atrributes through the usual dotted name >> notation precisely so that class code can be changed from >> x = ob >> to >> x = property(get_x, set_x, del_x) >> without changing user code. > > He was talking about C# with that statement. In C#, the compiled code > differs depending on whether you use a property or an attribute. Or at > least that's how I interpreted it. Checking back, I see now that Luis Z. went from Python "It boggles me when I see python code with properties that only set and get the attribute, or even worse, getters and setters for that purpose. " to C#, and that Duncan was seemingly responding to the C# part. If C# is like that, how inconvenient. > You are of course correct as to how Python does it. I guess I am spoiled ;-). tjr From wuwei23 at gmail.com Tue Jan 20 23:26:39 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 20:26:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> On Jan 21, 1:18?pm, "Russ P." wrote: > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. It wasn't the suggestion so much as the claim that integration of the behaviour was "relatively easy". Everything is "relatively easy" when you're not the one doing it. My mistake for using "trivial" instead, I didn't realise it would trip up your pedantry. From prologic at shortcircuit.net.au Tue Jan 20 23:30:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 14:30:14 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Wed, Jan 21, 2009 at 9:11 AM, Russ P. wrote: > Rather than waste more time replying to your post, Let me just refer > you to an excellent post that you may have missed earlier in this > thread by Mr. D'Aprano: > > http://groups.google.com/group/comp.lang.python/msg/d684d43b64a6e35a I'll finish reading it tonight :) Too long :) Starts off well though! --JamesMills From sspatz at kcnet.com Tue Jan 20 23:33:15 2009 From: sspatz at kcnet.com (Saul Spatz) Date: Tue, 20 Jan 2009 22:33:15 -0600 Subject: Problem with 3.0 Install on Windows Message-ID: I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get familiar with it. I have a directory with all my python projects in my PYTHONPATH variable. When I try to run python 3.0, it detects a syntax error (a print statement) in the first file in this directory, and crashes. I don't want to convert the files to 3.0 syntax, because I plan to keep using 2.5, at least for a while. I don't know exactly why this translation is happening. Is there a way to turn it off? Thanks From xahlee at gmail.com Tue Jan 20 23:35:22 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 20:35:22 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Xah Lee wrote: > > consider code produced by corporations, as opposed to with respect to > > some academic or philsophical logical analysis. Looked in another way, > > consider if we can compile stat of all existing pyhton code used in > > real world, you'll find the above style is rarely used. Rhodri James wrote: > I *was* thinking of code produced in the real world, and I don't buy > your assertion. I'm not an academic, and I wouldn't hesitate to lay > down a line of code like that. As I said before, it fits into English > language idioms naturally, and as a result is pretty self-descriptive. The issue is whether the python code in the real world, by statistics, uses a style such as list comprehension as discussed in this thread. (to simplify the matter: whether code out there uses list comprehension in situations when it can, by what percentage. I claimed it is rare, being borderline esoteric. This can be interpreted as less that 10%) In partcular, the issue, is not about your opinion or joe tech geeker's personal experiences of what they have seen. In newsgroups, every joe geeker makes claims using personal experiences as if that apply for the world. I, of course also based on my claims on personal experience, however, the difference is that my claim is explicitly made in the context of applying to the world. For example, my claim is not about my experiences being such and such. My claim is about such and such is so in the real world. If, now, you claim that it is not so, then perhaps we might have something to argue about. If you can, say, as a example, have a code that crawl the web of all google's own python code at google code for example, and do some simple analysis and report what is the percentage, and if that percentage is more than what i claim, i'll find it very interesting. But if you simply have such code to do such scale of analysis, that's far more interesting by itself than our debate. Similarly, if you can find any evidence, say by some code researcher's reports, that'd be great. At this point, i recall that i have read books on such report. You might try to do research on such books and read up. > Long experience particularly in C suggests that you are entirely wrong... Try to study more. I recommend spend less time coding or tech geeking (such as reading blogs, studying languages, or studying computer science ). I recommend taking a course in community college on philosophy, logic, literature, economics. After that, your thinking in coding and all the social issues related to coding, and computing industry, will sharpen by far. Xah ? http://xahlee.org/ ? From xahlee at gmail.com Tue Jan 20 23:43:33 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 20:43:33 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <647db7ce-2622-4ec8-8fe9-798ff6b311a9@k1g2000prb.googlegroups.com> On Jan 20, 7:51 pm, Terry Reedy wrote: > Rhodri James wrote: > > Computer languages are not human languages, but computer language > > constructs do attempt to map onto human language constructs to > > provide some measure of comprehensibility. Where a construct like > > list comprehension maps very well onto idiomatic English, dismissing > > it as "ad hoc syntax soup" is just plain wrong. > > Especially given that Python's comprehensions are taken from Haskell's > which are taken from mathematics' set builder notation. Also, care was > taken to have a correspondance between comprehension syntax and nested > for- and if- statement syntax. Someone recently made a proposal that > would break that correspondance and which would be 'ad hoc' and it will > surely be rejected. I suggest you take a course in math history. This is a pratical suggestion. There are community colleges perhaps near you. Register and take a course. If you are in USA, usually they are very cheap because it is funded by taxes. Typically it's 3 hours or so a week, adding homework it might be 10 per week, and last about 3 months. Try it. It's fun. The above won't actually teach you much in htis issue. To get some level of basic knowledge on this, you'll have to have few years on inter-displinary study associated math history, math notations, markup langs, computer syntax, mathematical linguistics related to grammar n syntax... Being a tech geeking hip creature, perhaps you'll never take the above advice. You'd rather immediate read some slashdot or google something and post profusely in online forums. For this, i recommend a few articles of my own: ? The Codification of Mathematics http://xahlee.org/cmaci/notation/math_codify.html ? The TeX Pestilence http://xahlee.org/cmaci/notation/TeX_pestilence.html ? The Problems of Traditional Math Notation http://xahlee.org/cmaci/notation/trad_math_notation.html ? A Notation for Plane Geometry http://xahlee.org/cmaci/notation/plane_geometry_notation.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html of course, i also have very technical and practical book length tutorials on emacs lisp, python, perl, java, javascript/html/css, php, povray. You can find them on my website. Thanks. Xah ? http://xahlee.org/ ? From aahz at pythoncraft.com Tue Jan 20 23:47:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 20:47:20 -0800 Subject: Extracting real-domain-name (without sub-domains) from a given URL References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: In article , S.Selvam Siva wrote: > > Actually i tried with domain specific logic.Having 200 TLD like >.com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i >will try to find some alternative solution. http://www.dnspython.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From wuwei23 at gmail.com Tue Jan 20 23:49:09 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 20:49:09 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: <4c799e42-4283-4140-b206-65f060a5afa7@s1g2000prg.googlegroups.com> On Jan 21, 2:35?pm, Xah Lee wrote: > I, of course also based on my claims on personal > experience, however, the difference is that my claim is explicitly > made in the context of applying to the world. For example, my claim is > not about my experiences being such and such. My claim is about such > and such is so in the real world. So the claims of people who have personally worked on "real world" code that contains list comprehensions isn't valid, whereas you who have _no_ such experience have a more genuine understanding of the world? Which is somehow totally unbiased and yet somehow always agrees with your preconceived notions? Talk about Aristotle and his wife's teeth... > I recommend taking a course in community college on > philosophy, logic, literature, economics. After that, your thinking in > coding and all the social issues related to coding, and computing > industry, will sharpen by far. Because clearly what the world needs is more of your style of academic understanding over practical, pragmatic knowledge. And arrogant condescension...we sure can't get enough of that. From Russ.Paielli at gmail.com Tue Jan 20 23:50:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 20:50:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Jan 20, 8:26?pm, alex23 wrote: > On Jan 21, 1:18?pm, "Russ P." wrote: > > > Since when is no one is allowed to suggest a potential improvement to > > a product unless they are willing to implement it themselves? Imagine > > what the world would be like if such a rule applied to all products. > > It wasn't the suggestion so much as the claim that integration of the > behaviour was "relatively easy". Everything is "relatively easy" when > you're not the one doing it. Here's what I wrote: If pylint can check access violations, then it seems to me that someone (who is familiar with the internals of the Python interpreter) should be able to integrate that feature into Python itself relatively easily. If pylint can check for private access violations, then in principle someone could just add a run-time flag that would run pylint as a preliminary step to running python. Heck, I am *not* familiar with the internals of the interpreter, and even I could do that. > My mistake for using "trivial" instead, I didn't realise it would trip > up your pedantry. Your mistake for being a moron. But it seems to happen regularly, doesn't it. How much more of my time are you going to waste, loser? From wuwei23 at gmail.com Wed Jan 21 00:00:02 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 21:00:02 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> On Jan 21, 2:50?pm, "Russ P." wrote: > If pylint can check for private access violations, then in principle > someone could just add a run-time flag that would run pylint as a > preliminary step to running python. Heck, I am *not* familiar with the > internals of the interpreter, and even I could do that. So why don't you? Why don't you set up a local command that does it for you? Why don't you add the check to your repo check in? Why don't you extend the object class in your site.py to provide the data protection you want? Why don't you enforce the use of that site.py across whatever multi-developer Python environment you're participating in? (You are -actually- working in such an environment, right, not just wasting our time in pointless conjecture?) Why don't YOU do SOMETHING other than insist that the community provide the solution for you? I always thought this was the major advantage of Python, that so much effort could be offloaded from the language to third party libraries. If there is such an urgent itch-to-scratch for data protection, where are the libs that provide such? There's a lot of funky stuff you can do with metaclasses. > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? You keep saying this and you keep replying. You keep making outlandish statements and then get angry when people question you. I'm sorry that using synonyms for words you've written seems to anger you so much. Have you stopped to consider that maybe it's that very anger which is rendering you unable to entertain other people's arguments in this thread? That's my polite way of saying "you're an arrogant and condescending prick", by the way, just so there's no confusion here. From prologic at shortcircuit.net.au Wed Jan 21 00:07:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:07:09 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 2:50 PM, Russ P. wrote: >> My mistake for using "trivial" instead, I didn't realise it would trip >> up your pedantry. > > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? I'm sorry Russ, but you insult my friend you die. You are -in fact- the moron here. I only wish my good friend and software engineering professor were here to laugh at this stupidly funny thread. Please stop replying. From sspatz at kcnet.com Wed Jan 21 00:12:00 2009 From: sspatz at kcnet.com (Saul Spatz) Date: Tue, 20 Jan 2009 23:12:00 -0600 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: Dietrich Bollmann wrote: > Hi, > > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > > Is there any logic explanation for this? > How can I get rid of the blank? > Is there a smarter way to write a simple shell loop which would work > better? > > Thanks, Dietrich > > > Here my approach: > > $ python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one > one > one > one > $ two > two > two > two > $ three > three > three > three > $ > Traceback (most recent call last): > File "", line 3, in > KeyboardInterrupt > > Strange. I don't have an explanation, but experiment shows that if you change print "$ ", to print "$ " (that is, leave out the comma) then the leading blank is not printed. This behavior doesn't depend on the "print input" statement's being in a loop. By the way, you don't need parens around the loop guard in python: while 1: (or as I prefer, while True:) work just fine. Saul From Russ.Paielli at gmail.com Wed Jan 21 00:20:45 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 21:20:45 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 9:00?pm, alex23 wrote: > On Jan 21, 2:50?pm, "Russ P." wrote: > > > If pylint can check for private access violations, then in principle > > someone could just add a run-time flag that would run pylint as a > > preliminary step to running python. Heck, I am *not* familiar with the > > internals of the interpreter, and even I could do that. > > So why don't you? Why don't you set up a local command that does it > for you? Why don't you add the check to your repo check in? Why don't > you extend the object class in your site.py to provide the data > protection you want? Why don't you enforce the use of that site.py > across whatever multi-developer Python environment you're > participating in? (You are -actually- working in such an environment, > right, not just wasting our time in pointless conjecture?) > > Why don't YOU do SOMETHING other than insist that the community > provide the solution for you? > > I always thought this was the major advantage of Python, that so much > effort could be offloaded from the language to third party libraries. > If there is such an urgent itch-to-scratch for data protection, where > are the libs that provide such? There's a lot of funky stuff you can > do with metaclasses. > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > You keep saying this and you keep replying. You keep making outlandish > statements and then get angry when people question you. I'm sorry that > using synonyms for words you've written seems to anger you so much. > Have you stopped to consider that maybe it's that very anger which is > rendering you unable to entertain other people's arguments in this > thread? That's my polite way of saying "you're an arrogant and > condescending prick", by the way, just so there's no confusion here. You are the one who pulled the word "trivial" out of your rear end and claimed that I had said it, when I had said nothing of the sort, loser. Let me explain, moron. I don't need enforced data hiding for the prototype I am working on now, because it's only a prototype that will be converted into another more suitable language for the end product. I am just interested in the idea of someday being able to go directly from prototype to end product in Python. It's not an immediate need, but a long-term concern. Can you comprehend that, genius? But I doubt it will ever come to pass, because it is clear that much of the Python community has no clue about what is required for large- scale, safety-critical software engineering. If people here said that Python just shouldn't worry about that domain, that would be fair enough. But three or four people on this thread have claimed now that Python is perfectly suitable for any project, no matter the size or the safety criticality. The idea that someone that clueless could actually be in a position to make such a choice for a real system someday is, frankly, a bit frightening. From Russ.Paielli at gmail.com Wed Jan 21 00:26:33 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 21:26:33 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Jan 20, 9:07?pm, James Mills wrote: > On Wed, Jan 21, 2009 at 2:50 PM, Russ P. wrote: > >> My mistake for using "trivial" instead, I didn't realise it would trip > >> up your pedantry. > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > I'm sorry Russ, but you insult my friend you die. > You are -in fact- the moron here. I only wish my good friend > and software engineering professor were here to laugh > at this stupidly funny thread. > > Please stop replying. I die? That sounds like a threat. I should report you for that, loser. Are you going to stalk me now, loser? Oh, and does your software engineering professor agree with you that Python is perfectly suitable for any safety-critical system, no matter how large? That would be interesting to know. From rhodri at wildebst.demon.co.uk Wed Jan 21 00:32:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:32:41 -0000 Subject: what's the point of rpython? In-Reply-To: <7xprihmlxu.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 02:29:01 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > What cpu's do you know of that can atomically increment and decrement >> > integers without locking? >> >> x86 (and pretty much any 8080 derivative, come to think of it). > > It would not have occurred to me that "lock inc" increments "without > locking". I understand that's different from a lock value sitting in > the data object but I thought that "lock-free algorithm" meant one > that didn't assert any of these hardware locks either. Maybe I'm > wrong. I tend to live in single-core worlds, so "inc" on its lonesome works just fine. >> Just do the locking properly and worry about optimisations later. > > That has already been tried, and found to be unacceptably slow for the > purpose at hand. Now we're looking for the optimizations. In that case I'd second the suggestion of taking a long, hard look at the Linux core locking and synchronisation primatives. -- Rhodri James *-* Wildebeeste Herder to the Masses From prologic at shortcircuit.net.au Wed Jan 21 00:33:01 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:33:01 +1000 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: On Wed, Jan 21, 2009 at 3:12 PM, Saul Spatz wrote: > Strange. I don't have an explanation, but experiment shows that if you > change print "$ ", to print "$ " (that is, leave out the comma) then the > leading blank is not printed. This behavior doesn't depend on the "print > input" statement's being in a loop. > > By the way, you don't need parens around the loop guard in python: > while 1: (or as I prefer, while True:) work just fine. http://codepad.org/f2XSwsPo This component I wrote - just for the hell of it - (just for this thread) works nicely :) cheers James From catphive at catphive.net Wed Jan 21 00:35:05 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 21:35:05 -0800 Subject: what's the point of rpython? In-Reply-To: <7xprihmlxu.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 6:29 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > What cpu's do you know of that can atomically increment and decrement >> > integers without locking? >> >> x86 (and pretty much any 8080 derivative, come to think of it). > > It would not have occurred to me that "lock inc" increments "without > locking". I understand that's different from a lock value sitting in > the data object but I thought that "lock-free algorithm" meant one > that didn't assert any of these hardware locks either. Maybe I'm > wrong. Right... I was wondering about that. Well, any kind of memory access gets exclusive control of the bus except on NUMA, but I'm wondering how CMPXCHG http://en.wikipedia.org/wiki/Compare-and-swap compares to XADD performance wise. It seems to me that both of them must pull the old value across the bus, hang onto the bus, and move the new value in. Maybe since XADD needs to perform arithmetic there will be a few cycles lag between getting the old value and pushing the new value? Maybe CMPXCHG doesn't go through the ALU? If the bus isn't just sitting idle and you can immediately push out the new value then there's no real locking. Actually this article explicitly mentions CMPXCHG as lock free. http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms From bignose+hates-spam at benfinney.id.au Wed Jan 21 00:37:16 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 21 Jan 2009 16:37:16 +1100 Subject: python for flash drives References: Message-ID: <878wp543ub.fsf@benfinney.id.au> Thomas Lord writes: > try portable python. it's free! You say it's free, but I'm unable to find the license terms easily on the web site. Which free software license does the recipient have in the work? -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From http Wed Jan 21 00:37:44 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:37:44 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3t2p93.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > I tend to live in single-core worlds, so "inc" on its lonesome works > just fine. In a single core world we wouldn't be having these endless angsty conversations about eliminating the GIL. > > That has already been tried, and found to be unacceptably slow for the > > purpose at hand. Now we're looking for the optimizations. > > In that case I'd second the suggestion of taking a long, hard look > at the Linux core locking and synchronisation primatives. Do you understand what the issue is, about CPython's reference counts? Do you have any idea how often the interpreter updates them? Even using LOCK INCR (raw machine instruction, not portable C, no operating system involvement), manipulating the ref counts would be around 100x slower than it is now. From prologic at shortcircuit.net.au Wed Jan 21 00:41:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:41:09 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 3:20 PM, Russ P. wrote: (...) > Let me explain, moron. I don't need enforced data hiding for the > prototype I am working on now, because it's only a prototype that will > be converted into another more suitable language for the end product. > I am just interested in the idea of someday being able to go directly > from prototype to end product in Python. It's not an immediate need, > but a long-term concern. Can you comprehend that, genius? And you're seriously going to sit there in your fancy office and state that Python isn't suitable ? You're stupider than we give you credit for. But that's okay - because although you "claim" to be a Software Engineer (I don't believe you) - you probably have no idea about Process, Code Review, Unit Testing, Z, ... > But I doubt it will ever come to pass, because it is clear that much > of the Python community has no clue about what is required for large- > scale, safety-critical software engineering. I guarantee that this is not the case, only that those that actually -do- use python for large scale projects or even mission critical or safety critical systems probably can't be bothered to waste their time with the likes of you. > If people here said that Python just shouldn't worry about that > domain, that would be fair enough. But three or four people on this > thread have claimed now that Python is perfectly suitable for any > project, no matter the size or the safety criticality. The idea that > someone that clueless could actually be in a position to make such a > choice for a real system someday is, frankly, a bit frightening. http://www.google.com/ --JamesMills From bignose+hates-spam at benfinney.id.au Wed Jan 21 00:42:16 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 21 Jan 2009 16:42:16 +1100 Subject: How to write a simple shell loop in python? References: Message-ID: <874ozt43lz.fsf@benfinney.id.au> Dietrich Bollmann writes: > I am trying to write a simple shell loop in Python. You should investigate the ?cmd? module in the standard library . > My simple approach works fine - but the first output line after > entering something is always indented by one blank. You should investigate the meaning of a comma ?,? in the ?print? statement (hint: it can affect subsequent ?print? statements) . -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From prologic at shortcircuit.net.au Wed Jan 21 00:44:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:44:53 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 3:26 PM, Russ P. wrote: > I die? That sounds like a threat. I should report you for that, loser. > Are you going to stalk me now, loser? It's an expression you fool. > Oh, and does your software engineering professor agree with you that > Python is perfectly suitable for any safety-critical system, no matter > how large? That would be interesting to know. Actually - in case you are perfectly unaware - programming languages -do not- bare meaning to such systems nor have an impact on their suitability or unsuitability. Have you ever developed a system with 0 defects ? If you have not, go away. Have you ever developed a system that is mathematically sound ? If you have not, go away. And can you -actually- prove that any of your system are -correct- ? ... ditto ... --JamesMills From http Wed Jan 21 00:47:41 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:47:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <7xd4eh2osi.fsf@ruckus.brouhaha.com> James Mills writes: > I guarantee that this is not the case, only that those that > actually -do- use python for large scale projects or even mission > critical or safety critical systems Do they exist? From psteiger at dcc.ufba.br Wed Jan 21 00:48:36 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Tue, 20 Jan 2009 21:48:36 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmthz1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <909ef3300901202148q791f9565q356dea3ed0319aac@mail.gmail.com> 2009/1/20 Paul Rubin <"http://phr.cx"@nospam.invalid> > Luis Zarrabeitia writes: > > No wonder you can't get Bruno's point. For the second, static checks > > to prevent accidents, you have pylint. For the first, not only you > > are using the wrong tool, but you are barking at python for not > > having it. Assuming that pylint is perfect (big assumption, but it > > is up to you to prove where it fails), > > Whaat? Assuming a program is perfect unless a failure is proven > is not at all a sane approach to getting reliable software. It is > the person claiming perfection who has to prove the absence of failure. > -- > http://mail.python.org/mailman/listinfo/python-list > To quote Carl Sagan (who quoted someone else, i guess), "Abscence of evidence is not evidence of abscence" -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 21 00:49:05 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:49:05 -0000 Subject: reading file to list In-Reply-To: <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 04:35:22 -0000, Xah Lee wrote: > Xah Lee wrote: > Similarly, if you can find any evidence, say by some code researcher's > reports, that'd be great. At this point, i recall that i have read > books on such report. You might try to do research on such books and > read up. Given that you are the one who is attempting proof by repeated assertion, I'd suggest that it is your job to find the evidence to support your claim. I am merely observing that I find your claim highly unlikely. >> Long experience particularly in C suggests that you are entirely >> wrong... > > Try to study more. I recommend spend less time coding or tech geeking > (such as reading blogs, studying languages, or studying computer > science ). I recommend taking a course in community college on > philosophy, logic, literature, economics. After that, your thinking in > coding and all the social issues related to coding, and computing > industry, will sharpen by far. I recommend spending less time being certain that you are correct without seeking evidence (something the later philosophers seem dreadfully bad at) and more in the application of logical thought. While expanding one's horizons is a good thing (my personal list places more emphasis on the theory and practice of music, theology, literature and democracy, but anything is fair game), expanding one's ego is not. -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 21 00:51:51 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:51:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <7x8wp52olk.fsf@ruckus.brouhaha.com> James Mills writes: > Actually - in case you are perfectly unaware - programming > languages -do not- bare meaning to such systems nor have > an impact on their suitability or unsuitability. Er, who do you think you are trying to fool, saying things like that? Maybe just yourself. > Have you ever developed a system with 0 defects ? > If you have not, go away. > Have you ever developed a system that is mathematically sound ? > If you have not, go away. > And can you -actually- prove that any of your system are -correct- ? > ... ditto ... http://compcert.inria.fr/doc/index.html (no, I didn't work on this). Care to attempt something comparable in Python? From sjmachin at lexicon.net Wed Jan 21 00:55:01 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 21:55:01 -0800 (PST) Subject: Problem with 3.0 Install on Windows References: Message-ID: <2e48f9a0-a9d6-4e20-89df-444f50e254b9@p2g2000prn.googlegroups.com> On Jan 21, 3:33?pm, Saul Spatz wrote: > I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get > familiar with it. ?I have a directory with all my python projects in my > PYTHONPATH variable. ?When I try to run python 3.0, it detects a syntax > error (a print statement) in the first file in this directory, and > crashes. ?I don't want to convert the files to 3.0 syntax, because I > plan to keep using 2.5, at least for a while. > > I don't know exactly why this translation is happening. ?Is there a way > to turn it off? The directories in PYTHONPATH are *prepended* to sys.path. Perhaps one of your files has the same name as a module that's new in Python 3.0 ... "io" is a possible candidate; "abc" a better one. Care to tell us the name of the file in which 3.0 finds the syntax error? From rhodri at wildebst.demon.co.uk Wed Jan 21 00:58:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:58:57 -0000 Subject: what's the point of rpython? In-Reply-To: <7xhc3t2p93.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 05:37:44 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> In that case I'd second the suggestion of taking a long, hard look >> at the Linux core locking and synchronisation primatives. > > Do you understand what the issue is, about CPython's reference counts? > Do you have any idea how often the interpreter updates them? Even > using LOCK INCR (raw machine instruction, not portable C, no operating > system involvement), manipulating the ref counts would be around 100x > slower than it is now. You asked a question about CPUs with atomic update, strongly implying there were none. All I did was supply a counter-example, and observe that neither this nor the question were in fact helpful. My inability to spell "primitive", on the other hand, is all my own fault. -- Rhodri James *-* Wildebeeste Herder to the Masses From prologic at shortcircuit.net.au Wed Jan 21 01:00:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:00:03 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xd4eh2osi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7xd4eh2osi.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 3:47 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > James Mills writes: >> I guarantee that this is not the case, only that those that >> actually -do- use python for large scale projects or even mission >> critical or safety critical systems > > Do they exist? http://www.wingware.com/python/success Google is your friend - Though I'm certain that there would be many systems either closed or trade secret what wouldn't necessarily make public the technologies or platforms they utilize. --JamesMills From wuwei23 at gmail.com Wed Jan 21 01:02:04 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 22:02:04 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> On Jan 21, 3:20?pm, "Russ P." wrote: [...more invective and avoiding of questions snipped...] > Let me explain, moron. I don't need enforced data hiding for the > prototype I am working on now, because it's only a prototype that will > be converted into another more suitable language for the end product. > I am just interested in the idea of someday being able to go directly > from prototype to end product in Python. It's not an immediate need, > but a long-term concern. Can you comprehend that, genius? Can I comprehend that you don't even have an immediate need and are instead actively engaging in online onanism? Absolutely. Didn't even have to call you a moron to demonstrate it, either. From prologic at shortcircuit.net.au Wed Jan 21 01:02:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:02:37 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x8wp52olk.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 3:51 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > James Mills writes: >> Actually - in case you are perfectly unaware - programming >> languages -do not- bare meaning to such systems nor have >> an impact on their suitability or unsuitability. > > Er, who do you think you are trying to fool, saying things like that? > Maybe just yourself. Paul unless you can prove otherwise, refuting my statement is useless. Claiming that Python may or may not be suitable for safety critical systems or large scale systems is unfounded. --JaemsMills From http Wed Jan 21 01:03:52 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:03:52 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> Message-ID: <7xk58pgppz.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > You asked a question about CPUs with atomic update, strongly implying > there were none. All I did was supply a counter-example, Well, more specifically, atomic update without locking, but I counted the LOCK prefix as locking while other people didn't, and that caused some confusion. Of course I'm aware of the LOCK prefix but it slows down the instruction enormously compared with a non-locked instruction. From http Wed Jan 21 01:08:23 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:08:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjdgpig.fsf@ruckus.brouhaha.com> James Mills writes: > >> Actually - in case you are perfectly unaware - programming > >> languages -do not- bare meaning to such systems nor have > >> an impact on their suitability or unsuitability. > > > > Er, who do you think you are trying to fool, saying things like that? > > Maybe just yourself. > > Paul unless you can prove otherwise, refuting my statement > is useless. Claiming that Python may or may not be suitable > for safety critical systems or large scale systems is unfounded. "Programming languages -do not- bare meaning to such systems nor have an impact on their suitability or unsuitability" (I presume you mean "bear" not "bare") is a far stronger and stupider statement than one about Python's suitability or lack thereof. Most informed users would agree that Python is more suitable than some languages for that sort of application and less suitable than others. Only a fool would propose that all languages are equally suitable. From prologic at shortcircuit.net.au Wed Jan 21 01:18:48 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:18:48 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjdgpig.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:08 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Programming languages -do not- bare meaning to such systems nor have > an impact on their suitability or unsuitability" (I presume you mean > "bear" not "bare") is a far stronger and stupider statement than one > about Python's suitability or lack thereof. Most informed users would > agree that Python is more suitable than some languages for that sort > of application and less suitable than others. Only a fool would > propose that all languages are equally suitable. Yes I meant "bear" - bite me. I never did say that python -is- suitable for all applications or that all languages are suitable for all purposes. However, (others that are) claiming that Python -is not- suitable because python does not have XYZ feature is equally as foolish. Who's to say that Python is not just as suitable for the systems on-board a Boeing-747 then C++ ? --JamesMills From catphive at catphive.net Wed Jan 21 01:19:21 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 22:19:21 -0800 Subject: what's the point of rpython? In-Reply-To: <7xk58pgppz.fsf@ruckus.brouhaha.com> References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> You asked a question about CPUs with atomic update, strongly implying >> there were none. All I did was supply a counter-example, > > Well, more specifically, atomic update without locking, but I counted > the LOCK prefix as locking while other people didn't, and that caused > some confusion. Of course I'm aware of the LOCK prefix but it slows > down the instruction enormously compared with a non-locked instruction. I'm curious about that. I've been looking around for timing information on the lock signal, but am having some trouble finding them. Intuitively, given that the processor is much faster than the bus, and you are just waiting for processor to complete an addition or comparison before put the new memory value on the bus, it seems like there should be very little additional bus contention vs a normal add instruction. From Russ.Paielli at gmail.com Wed Jan 21 01:23:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:23:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> Message-ID: On Jan 20, 10:02?pm, alex23 wrote: > Can I comprehend that you don't even have an immediate need and are > instead actively engaging in online onanism? Absolutely. So anyone thinking beyond an "immediate need" is "engaging in online onanism"? Let's see. How long ago did the Python community start thinking about Python 3? So I guess they're all a bunch of jerkoffs, eh? From wuwei23 at gmail.com Wed Jan 21 01:24:08 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 22:24:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 21, 3:20?pm, "Russ P." wrote: > But I doubt it will ever come to pass, because it is clear that much > of the Python community has no clue about what is required for large- > scale, safety-critical software engineering. Okay, let me try a less snippy approach. How do you feel about metaclass techniques such as this one by Carl Banks? http://code.activestate.com/recipes/573442/ This is pretty much what I had in mind when I said before that I believed such concerns could be addressed externally of the interpreter. Thankfully I thought to check Activestate before knocking up my own as proof-of-concept :) With Python 2.6/3.0 Carl's code could be easily (almost said 'trivially'...) extended to support the new __dir__ special method to exclude anything marked as private from the dir() results. From Russ.Paielli at gmail.com Wed Jan 21 01:32:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:32:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Jan 20, 10:18?pm, James Mills wrote: > I never did say that python -is- suitable for > all applications or that all languages are suitable > for all purposes. But you did make some rather outlandish statements. I had written this: > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. And you wrote this little gem in reply: I am 100% confident that those same systems could be well written in a language such as Python and would very likely end up being much smaller and more manageable. From prologic at shortcircuit.net.au Wed Jan 21 01:37:52 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:37:52 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:32 PM, Russ P. wrote: > But you did make some rather outlandish statements. I had written > this: > >> I suggest you call Boeing and tell them that encapsulation is more >> trouble than it's worth for their 787 flight software. But please >> don't do it if you ever wish to work for them, because you will be >> proving conclusively that you don't have a clue about the kind of >> software systems they produce. > > And you wrote this little gem in reply: > > I am 100% confident that those same systems could be > well written in a language such as Python and would very > likely end up being much smaller and more manageable. And I completely stand by this. --JamesMills From http Wed Jan 21 01:49:54 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:49:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: <7x63k917cd.fsf@ruckus.brouhaha.com> James Mills writes: > Who's to say that Python is not just as suitable > for the systems on-board a Boeing-747 then C++ ? "Today, Boeing uses about 500,000 lines of Ada to fly its commercial 747 400 in subsystem components, critical certification, and human safety features. Two of the three largest systems on the 747, or 43 percent of the executable bytes, are written in Ada. The software is FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) Is the third component in C++? That is scary, if it does anything important. From Russ.Paielli at gmail.com Wed Jan 21 01:55:09 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:55:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 10:24?pm, alex23 wrote: > On Jan 21, 3:20?pm, "Russ P." wrote: > > > But I doubt it will ever come to pass, because it is clear that much > > of the Python community has no clue about what is required for large- > > scale, safety-critical software engineering. > > Okay, let me try a less snippy approach. How do you feel about > metaclass techniques such as this one by Carl Banks? > > http://code.activestate.com/recipes/573442/ > > This is pretty much what I had in mind when I said before that I > believed such concerns could be addressed externally of the > interpreter. Thankfully I thought to check Activestate before knocking > up my own as proof-of-concept :) > > With Python 2.6/3.0 Carl's code could be easily (almost said > 'trivially'...) extended to support the new __dir__ special method to > exclude anything marked as private from the dir() results. Looks interesting. If it can somehow be integrated into the language as full-fledged feature, then I'd say it has potential. As I said before, I am not looking for a hack or a quick fix. I am interested in well-engineered data hiding that is fully supported as part of the language. But I certainly appreciate Mr. Banks effort whether it ever reaches that level or not. [I am a bit confused though, because I seem to recall that Mr. Banks claimed earlier in this thread that enforced data hiding is useless.] From http Wed Jan 21 01:56:05 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:56:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <7x1vux1722.fsf@ruckus.brouhaha.com> alex23 writes: > Okay, let me try a less snippy approach. How do you feel about > metaclass techniques such as this one by Carl Banks? > > http://code.activestate.com/recipes/573442/ Does the metaclass prevent reaching into the __dict__ in an instance? Also, attribute protection is just a tiny aspect. The high assurance community really wants as much static verification as it can possibly get. Python doesn't really lend itself to that. From prologic at shortcircuit.net.au Wed Jan 21 01:57:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:57:05 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x63k917cd.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:49 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Today, Boeing uses about 500,000 lines of Ada to fly its commercial > 747 400 in subsystem components, critical certification, and human > safety features. Two of the three largest systems on the 747, or 43 > percent of the executable bytes, are written in Ada. The software is > FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) You wouldn't happen to have a source for this information would you ? And this (if true) hardly suprises me as Ada is one of the most rigorous and strictest languages I have ever used. Still... --JamesMills From prologic at shortcircuit.net.au Wed Jan 21 02:03:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 17:03:03 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 4:55 PM, Russ P. wrote: > On Jan 20, 10:24 pm, alex23 wrote: >> This is pretty much what I had in mind when I said before that I >> believed such concerns could be addressed externally of the >> interpreter. Thankfully I thought to check Activestate before knocking >> up my own as proof-of-concept :) >> >> With Python 2.6/3.0 Carl's code could be easily (almost said >> 'trivially'...) extended to support the new __dir__ special method to >> exclude anything marked as private from the dir() results. > > Looks interesting. If it can somehow be integrated into the language > as full-fledged feature, then I'd say it has potential. As I said > before, I am not looking for a hack or a quick fix. I am interested in > well-engineered data hiding that is fully supported as part of the > language. But I certainly appreciate Mr. Banks effort whether it ever > reaches that level or not. Then -don't- use python. Use some other boring language. (!@#$!@#) --JamesMills From Russ.Paielli at gmail.com Wed Jan 21 02:10:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:10:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: On Jan 20, 10:56?pm, Paul Rubin wrote: > Also, attribute protection is just a tiny aspect. ?The high assurance > community really wants as much static verification as it can possibly > get. ?Python doesn't really lend itself to that. Which is why I was hoping that Python might get enforced data hiding as well as optional static type declarations that can actually be used for static verification. But maybe that's all just a pipe dream on my part -- or "onanism." From Russ.Paielli at gmail.com Wed Jan 21 02:14:39 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:14:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <3905e097-2a25-470b-af83-39a7263ad214@d36g2000prf.googlegroups.com> On Jan 20, 11:03?pm, James Mills wrote: > Then -don't- use python. Use some other boring > language. (!@#$!@#) > > --JamesMills You're emailing me again. Please don't do that. It's bad enough to get death threats in a newsgroup -- I don't need them in my inbox too. Thanks. From http Wed Jan 21 02:16:06 2009 From: http (Paul Rubin) Date: 20 Jan 2009 23:16:06 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> Message-ID: <7xwscpyvrd.fsf@ruckus.brouhaha.com> James Mills writes: > > "Today, Boeing uses about 500,000 lines of Ada to fly its commercial > > 747 400 in subsystem components, critical certification, and human > > safety features. Two of the three largest systems on the 747, or 43 > > percent of the executable bytes, are written in Ada. The software is > > FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) > > You wouldn't happen to have a source for this information would you ? Just the url that is there. > And this (if true) hardly suprises me as Ada is one of the most > rigorous and strictest languages I have ever used. I have no direct experience with it but have read a little about it. It looks to be a fairly vanilla block structured imperative language like Pascal with some concurrency stuff added. The sense I have is that it's not especially harder to program in than C or C++, but the programs come out much more reliable. If you want to see something really rigorous and strict, take a look at ATS: http://ats-lang.org . Here is a certified quicksort in ATS: http://www.ats-lang.org/EXAMPLE/MISC/listquicksort.dats The point is that ATS's type system is powerful enough to define a type for a sorting routine (a function that takes a list as input and produces a sorted permutation of the input list). If you then write something that purports to be a sorting routine but fails to produce a sorted permutation, the compiler will reject the program with a type error. If your routine compiles at all, it sorts correctly. From wuwei23 at gmail.com Wed Jan 21 02:16:38 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 23:16:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 21, 4:55?pm, "Russ P." wrote: > Looks interesting. If it can somehow be integrated into the language > as full-fledged feature, then I'd say it has potential. As I said > before, I am not looking for a hack or a quick fix. I am interested in > well-engineered data hiding that is fully supported as part of the > language. I think this is the main issue we disagree on. I'm happier for Python to remain lightweight where such features can be easily added on demand through external libraries. I see no reason why a library couldn't be as "well-engineered" a solution as an extension to the interpreter, its use being a mandated (and enforced) requirement within personal projects. The language just has to enable such solutions, which I feel Python does well. Perhaps what really concerns me with the inclusion of data hiding into the language itself is that people would use it :) I've always enjoyed the openness of the Python libs, the "consenting adults" approach it takes, and the ease with which I can override their inherent functionality when I need to. (But I think we've been over this before, the whole "the lib developer knows best" vs "I the coder know best" argument...) > [I am a bit confused though, because I seem to recall that Mr. Banks > claimed earlier in this thread that enforced data hiding is useless.] Maybe he was just trying to stave off threads like this one ;) From wuwei23 at gmail.com Wed Jan 21 02:19:54 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 23:19:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: <679947f8-83fd-44da-94f3-4ba65058437c@d36g2000prf.googlegroups.com> On Jan 21, 4:56?pm, Paul Rubin wrote: > Does the metaclass prevent reaching into the __dict__ in an instance? Yes, if you specify that '__dict__' is one of the private attributes. > Also, attribute protection is just a tiny aspect. ?The high assurance > community really wants as much static verification as it can possibly > get. ?Python doesn't really lend itself to that. I can't argue against that. It will be interesting to see what comes out of the introduction of parameter annotation in 3.0. From http Wed Jan 21 02:30:32 2009 From: http (Paul Rubin) Date: 20 Jan 2009 23:30:32 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> Message-ID: <7xprih5d5z.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > Zope is about 375 KLOC[1], > How many LOCS would it require if it was written in ADA ? No idea. Ada is a lot more verbose than Python, but I'm baffled at what the heck Zope is actually doing with all that code. > > Zope also has 275 open bugs, 6 of which are critical. > > None of which are going to *kill* anyone FWIW. Now how many of these > bugs would have language-enforced access restriction prevented ? I'm not about to audit 375 KLOC of code to find out. Regardless of whether access restriction actually prevents bugs though, it certainly makes auditing easier. And auditing does find bugs. > >[2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC > of a hi-level dynamic language ? Hm, I guess not. I think written in some forerunner of Ada. > Given the difference in LOCS count between a low-level static language > and a hi-level dynamic language for the implementation of a same given > features set, you cannot just define "large" by the # of LOCS. Not > that I'm going to compare Zope with Space shuttle's stuff. I don't think static vs dynamic makes much difference in the amount of LOCS to accomplish some function. In my limited experience with Haskell (statically typed but very high level), it takes around the same amount of Haskell code as Python code (sometimes more, sometimes less) to do a given task. More important for concise code is features like higher-level functions and types (e.g. it's easy in Python or Haskell, but a huge pain in Java or C, to write down a value that is a list of dictionaries whose keys are tuples and whose values are more lists of dictionaries, to code something list a listcomp, etc). From Russ.Paielli at gmail.com Wed Jan 21 02:30:54 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:30:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 11:16?pm, alex23 wrote: > I think this is the main issue we disagree on. I'm happier for Python > to remain lightweight where such features can be easily added on > demand through external libraries. I see no reason why a library > couldn't be as "well-engineered" a solution as an extension to the > interpreter, its use being a mandated (and enforced) requirement > within personal projects. The language just has to enable such > solutions, which I feel Python does well. That could work. As long as it's well-engineered (not a hack), well- supported (part of the standard library), and does the job, that's probably all that matters. From aonlazio at gmail.com Wed Jan 21 03:06:13 2009 From: aonlazio at gmail.com (AON LAZIO) Date: Wed, 21 Jan 2009 03:06:13 -0500 Subject: Nonblocking keyboard input in python Idle windows Message-ID: Hi, I want to solve the problem like this running on Idle python windows The problem: the program continue printing 1,2,3,4,5.... until it receives the input 'enter' from keyboard then it stops printing this could be done using msvcrt.kbhit() and msvcrt.getch() on command prompt windows However, those methods could not work in Python Idle windows. Any of you guys know the methods to solve this problem? Thanks in advance. Aonlazio -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Wed Jan 21 03:10:55 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 21 Jan 2009 09:10:55 +0100 Subject: Start Python at client side from web app Message-ID: <6to3kfFbr0psU1@mid.individual.net> Hi, I want to start Python at the client side from a web application. The app is an intranet application, and all client PCs are under our control (we can install software on them). But I don't want to update the installation too often. Here is my idea: We create a custom mime-type and register it on the client PC. The web application can send signed python code to the client PC. If the signature is correct, the code will be executed at the client. The signature prevents others from executing code. Has someone seen or done something like this before? I can code this myself, but prefer to use some open source project, if it exists. Thanks in advance, Thomas G?ttler -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steven at REMOVE.THIS.cybersource.com.au Wed Jan 21 03:36:49 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 21 Jan 2009 08:36:49 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) >> >> It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > Example: > > LogError "Walk has gotten too silly", CurrentTime > > Here, LogError is a method call that takes two arguments, and > CurrentTime is a method call that takes none. That seems ambiguous to me. As a non-RealBasic programmer, I can see at least four meanings it could have. Translated into Python, they are: LogError("Walk has gotten too silly", CurrentTime) LogError("Walk has gotten too silly"), CurrentTime LogError("Walk has gotten too silly", CurrentTime()) LogError("Walk has gotten too silly"), CurrentTime() Of course this assumes that RealBasic has an equivalent of tuples, and treats functions as first class objects. But even if RB doesn't have these things, I question that the syntax is "beautiful". Consider some arbitrary method Foo. If you see this: Foo Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo does. If it returns no result, then it's legal. If it returns a result, it isn't. So the question of whether syntax is legal depends, not on the syntactic elements involved, but on the *semantics* of the method (whether or not it returns a result). > Eliminating unnecessary parentheses does a lot to improve the > readability of the code IMHO. But they're not unnecessary, at least not in Python, they're useful for distinguishing between calling the function and the function itself. -- Steven From spam.buster at web.de Wed Jan 21 03:41:44 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 09:41:44 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web > application can send signed python code to the client PC. If the signature > is correct, the code will be executed at the client. The signature > prevents others from executing code. My first thought was: Wouldn't it be much easier to start the script via ssh? -- Cheerz Lars From castironpi at gmail.com Wed Jan 21 03:48:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 00:48:22 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> On Jan 20, 9:16?pm, MRAB wrote: > Terry Reedy wrote: > > Joe Strout wrote: > >> Aaron Brady wrote: > > >>> I think it would be a good step if you could make some sensible > >>> interpretation of a typical statement without its parentheses. > > >>> f "abc" 123 > >>> --> > >>> f( "abc", 123 ) > > > How would you differentiate > > > f 'abc' + 'def' > > as > > f('abc') + 'def' > > versus > > f('abc' + 'def') > > >> Such a language is possible -- take a look at REALbasic sometime. ?RB > >> certainly has its problems (mainly bugs), but the language syntax is > >> beautiful. ?To your point, parentheses are not required around any > >> method call that (1) has no return value, or (2) requires no > >> parameters. ?Example: > > >> ?LogError "Walk has gotten too silly", CurrentTime > > > LogError('walk', Time) # versus > > LogError('walk'), Time > > > Perhaps RB does not have tuple literals. > > Parentheses wouldn't be required if it's a procedure call (I'm not sure > about a function that's called as a procedure) or if there are no > parameters to pass. Thus: > > ? ? ?f 'abc' + 'def' > > does: > > ? ? ?f('abc' + 'def') Where functions are first-class objects, a bare function object isn't distinguishable either from its call. I'm granting that it's useful to return values a lot. For example: a= f could mean either, 'a= f' or 'a= f()'. Once again the return values save the day. In the case of Terry's example, it's covered by Joe's caveat that functions can't return values without parentheses, since '+' is a function. However, order of precedence could help. Python and C of course allow string concatenation by adjacency, so there's further ambiguity there. It might fall under Terry's case. You can look at English to get started, and try to see how native speakers resolve the ambiguities. It doesn't just happen with verbs, either. Firstly, Python lacks the notion of determiners (denoting phrases) per se. That is, there's no way to say 'the black dog'. Here's an approximation though. "The black dog and the cat walked to the store." walked( ( dogs( color= black ), cat ), store ) Secondly, Python is entirely imperative, something I was alluding to in another post, which was about a relation object. English declares the event, while Python commands it: ( dog, cat ).walk( store ) It addresses the subjects, and gives them orders. On a tangent, I think the 'join' method on threads is a little counter-intuitive, since the entity you're giving the instruction to is actually the caller, not the object. The verb is a little counter-intuitive, though, since if I say 'Team, join us!', it actually just means, 'Us, wait for the team'. It's not like 'join' causes the target to break early or hustle or anything. From mal at egenix.com Wed Jan 21 03:56:08 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 21 Jan 2009 09:56:08 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> References: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> Message-ID: <4976E328.8030104@egenix.com> On 2009-01-20 15:54, Mike Driscoll wrote: > On Jan 20, 8:19 am, Hussein B wrote: >> Hey, >> I'm creating a report that is supposed to harvest the data for the >> previous month. >> So I need a way to get the first day and the last day of the previous >> month. >> Would you please tell me how to do this? >> Thanks in advance. > > I recommend the dateutil module: > > http://labix.org/python-dateutil > > I think it may also be possible to use the datetime module, but it's > easier to just use dateutil. Or use mxDateTime on which all this was based: http://www.egenix.com/products/python/mxBase/mxDateTime/ >>> from mx.DateTime import now, Date, RelativeDateTime >>> >>> def prev_month(): ... t = now() ... return ( ... t + RelativeDateTime(months=-1, day=1, hour=0, minute=0, second=0), ... t + RelativeDateTime(months=-1, day=-1, hour=0, minute=0, second=0)) ... >>> print prev_month() (, ) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 21 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From castironpi at gmail.com Wed Jan 21 03:57:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 00:57:49 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Jan 21, 2:36?am, Steven D'Aprano wrote: > On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote: > > Aaron Brady wrote: > > >> I think it would be a good step if you could make some sensible > >> interpretation of a typical statement without its parentheses. > > >> f "abc" 123 > >> --> > >> f( "abc", 123 ) > > >> It would be just the thing in a couple of situations... > > > Such a language is possible -- take a look at REALbasic sometime. ?RB > > certainly has its problems (mainly bugs), but the language syntax is > > beautiful. ?To your point, parentheses are not required around any > > method call that (1) has no return value, or (2) requires no parameters. > > ? Example: > > > ? LogError "Walk has gotten too silly", CurrentTime > > > Here, LogError is a method call that takes two arguments, and > > CurrentTime is a method call that takes none. > > That seems ambiguous to me. As a non-RealBasic programmer, I can see at > least four meanings it could have. Translated into Python, they are: > > LogError("Walk has gotten too silly", CurrentTime) > LogError("Walk has gotten too silly"), CurrentTime > LogError("Walk has gotten too silly", CurrentTime()) > LogError("Walk has gotten too silly"), CurrentTime() > > Of course this assumes that RealBasic has an equivalent of tuples, and > treats functions as first class objects. > > But even if RB doesn't have these things, I question that the syntax is > "beautiful". Consider some arbitrary method Foo. If you see this: > > ? ? Foo > > Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo > does. If it returns no result, then it's legal. If it returns a result, > it isn't. So the question of whether syntax is legal depends, not on the > syntactic elements involved, but on the *semantics* of the method > (whether or not it returns a result). If you could deduce the semantics of a function from the syntax always, you could follow Erik's observation about Logo. Then expressions would have unique interpretations, except where a function takes no arguments and functions are first class objects. In other words, g f "abc" 123 would have an exact meaning, since f would just get the innermost n arguments, that since 'n' would be a known quantity. (Order of precedence would handle 'g f "abc" + "123"'.) > > Eliminating unnecessary parentheses does a lot to improve the > > readability of the code IMHO. > > But they're not unnecessary, at least not in Python, they're useful for > distinguishing between calling the function and the function itself. Natural language doesn't have the equivalent of parentheses, which goes back to Steven's point about a beautiful math structure vs. a beautiful NL sentence. Did anyone have to diagram sentences in grammar school? It's not like the essentials for communication involve deeply nested sentences; you can get by with a few simple declarations, so you and your company will reject anything "higher- order". From castironpi at gmail.com Wed Jan 21 04:02:37 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 01:02:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 17, 11:28?pm, Steven D'Aprano wrote: > On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > > Russ P. a ?crit : > >> On Jan 15, 12:21 pm, Bruno Desthuilliers > >> wrote: > > >>> Once again, the important point is that there's a *clear* distinction > >>> between interface and implementation, and that you *shouldn't* mess > >>> with implementation. > > >> If you "*shouldn't* mess with the implementation", then what is wrong > >> with enforcing that "shouldn't" in the language itself? > > Russ: There are SHOULD NOTs and there are MUST NOTs. snip > >>> class Parrot: > > ... ? ? _private = 'spam' > ...>>> p = Parrot() > >>> p._private = 'ham' ?# allowed by default > >>> from protection import lock > >>> lock(p)._private > >>> p._private = 'spam' > > Traceback (most recent call last): > ? File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot > > Would that be so bad? I don't think so. Sorry, I didn't see the last part originally. I don't think 'outside of class Parrot' is well-defined in Python. Does '_private' have to be a member of 'Parrot', an instance of 'Parrot', or the calling instance of 'Parrot', before entering the calling scope, or at the time the call is made? Since many of these can change on the fly, there's more than one consistent interpretation to the syntax. From reyjexter at gmail.com Wed Jan 21 04:04:53 2009 From: reyjexter at gmail.com (reyjexter) Date: Wed, 21 Jan 2009 01:04:53 -0800 (PST) Subject: Locking blockl to a people on a similar group / naming locks Message-ID: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> Hello! Is there a way to lock a certain block to a people on similar group? In java this is done by like this: synchronize (myGroup) { } but how do I do this in python? how can I name the lock that will be used by the thread? -rey From http Wed Jan 21 04:06:41 2009 From: http (Paul Rubin) Date: 21 Jan 2009 01:06:41 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <7xd4eh81um.fsf@ruckus.brouhaha.com> Thomas Guettler writes: > I want to start Python at the client side from a web > application. The app is an intranet application, and all client PCs > are under our control (we can install software on them). Is it supposed to be OS independent? If not, is it for a specific OS? Which one? From http Wed Jan 21 04:09:48 2009 From: http (Paul Rubin) Date: 21 Jan 2009 01:09:48 -0800 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> Message-ID: <7x8wp581pf.fsf@ruckus.brouhaha.com> reyjexter writes: > synchronize (myGroup) { > } > > but how do I do this in python? how can I name the lock that will be > used by the thread? You have to do it explicitly, for example with RLock: myInstance.lock = RLock() ... myInstance.lock.acquire() ... critical section ... myInstance.lock.release() It's often possible to write in a style that avoids this mess. The preferred way is usually to write isolated threads that communicate by passing objects through queues (Queue.Queue). This gets rid of a lot of locking hazards. From xahlee at gmail.com Wed Jan 21 04:13:03 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 21 Jan 2009 01:13:03 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Rhodri James wrote: > I recommend spending less time being certain that you are correct > without seeking evidence I don't concur. For instance, when you are talking to a bunch of kids, you have to be sure of yourself, else they run all over you, even if they didn't mean to be rude. Also, one's demeanor must commensurate one's knowledge. If i pamper you, you might think i'm a whimp, and run on with your opinions and thoughts unbridled, which, can be considered as a miscommunication on my part. Xah ? http://xahlee.org/ ? From spam.buster at web.de Wed Jan 21 04:42:19 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 10:42:19 +0100 Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Rhodri James wrote: > I *was* thinking of code produced in the real world, and I don't buy > your assertion. I'm not an academic, and I wouldn't hesitate to lay > down a line of code like that. As I said before, it fits into English > language idioms naturally, and as a result is pretty self-descriptive. As a non-native speaker and non-academic, I don't understand the "fittine into English language idioms naturally" which is mentioned here in the different subthreads. Could you try to explain that for me? TIA -- Cheerz Lars From deets at nospam.web.de Wed Jan 21 04:43:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 10:43:30 +0100 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> <7x8wp581pf.fsf@ruckus.brouhaha.com> Message-ID: <6to922FbvhdrU1@mid.uni-berlin.de> Paul Rubin wrote: > reyjexter writes: >> synchronize (myGroup) { >> } >> >> but how do I do this in python? how can I name the lock that will be >> used by the thread? > > You have to do it explicitly, for example with RLock: > > myInstance.lock = RLock() > ... > myInstance.lock.acquire() > ... critical section ... > myInstance.lock.release() In python 2.5 and upwards, you can write this safer from __future__ import with_statement # only needed for py2.5 with myInstance.lock: ... critical section Diez From spam.buster at web.de Wed Jan 21 04:44:38 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 10:44:38 +0100 Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Lars Behrens wrote: > As a non-native speaker and non-academic, I don't understand the "fittine "fitting", I meant. Sorry ^^ -- Cheerz Lars From aberry at aol.in Wed Jan 21 04:51:09 2009 From: aberry at aol.in (aberry) Date: Wed, 21 Jan 2009 01:51:09 -0800 (PST) Subject: smtplib.SMTP throw : 'Socket error: 10053 software caused connection abort' In-Reply-To: <21565011.post@talk.nabble.com> References: <21565011.post@talk.nabble.com> Message-ID: <21579963.post@talk.nabble.com> aberry wrote: > > I am using 'smtplib' module to send an email but getting exception... > > smtplib.SMTP( throw error : > > here is trace back snippet :- > > " smtp = smtplib.SMTP(self.server) > File "D:\Python24\lib\smtplib.py", line 244, in __init__ > (code, msg) = self.connect(host, port) > File "D:\Python24\lib\smtplib.py", line 306, in connect > raise socket.error, msg > socket.error: (10053, 'Software caused connection abort')" > > thanks in adv, > aberry > > problem resolved :) ... culprit was Anti Virus running on my Win XP machine... I disabled AV On Access scan... no Error and email sent rgds, aberry -- View this message in context: http://www.nabble.com/smtplib.SMTP-throw-%3A-%27Socket-error%3A-10053-software-caused-connection-abort%27-tp21565011p21579963.html Sent from the Python - python-list mailing list archive at Nabble.com. From vinay_sajip at yahoo.co.uk Wed Jan 21 04:55:11 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 21 Jan 2009 01:55:11 -0800 (PST) Subject: Logging help References: Message-ID: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> On Jan 20, 10:11 am, koranthala wrote: > > The doRollover method does not append to the earlier file. Rather, it > creates a new file with the same name. Err... that's what rollover means - switching to a new log file (and renaming the old ones). If it just appended to the old one, why would it be called doRollover ? ;-) Regards, Vinay Sajip From bbxx789_05ss at yahoo.com Wed Jan 21 04:57:52 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 21 Jan 2009 01:57:52 -0800 (PST) Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <41fde0a7-98c2-4f36-8c6f-71d2559e2138@f40g2000pri.googlegroups.com> On Jan 21, 1:10?am, Thomas Guettler wrote: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. How does a web application on the client execute python code? From http Wed Jan 21 05:06:52 2009 From: http (Paul Rubin) Date: 21 Jan 2009 02:06:52 -0800 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> <7x8wp581pf.fsf@ruckus.brouhaha.com> <6to922FbvhdrU1@mid.uni-berlin.de> Message-ID: <7xr62x0y83.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > In python 2.5 and upwards, you can write this safer > from __future__ import with_statement # only needed for py2.5 > with myInstance.lock: > ... critical section Good point! From jstroud at mbi.ucla.edu Wed Jan 21 05:10:45 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 21 Jan 2009 02:10:45 -0800 Subject: Start Python at client side from web app In-Reply-To: <6to3kfFbr0psU1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. > > Has someone seen or done something like this before? > > I can code this myself, but prefer to use some open source project, if it exists. > > > Thanks in advance, > Thomas G?ttler > You are better off using a cron job (or similar) on the client side, getting the client to hit the web server for the code at regular intervals, and if code is ready, execute. If code isn't ready, wait for the next interval. Use https for security and have a shared secret message to identify legitimate clients. If you try to push code the other way, you will need a perpetual socket open on the client side, making the client the server. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From http Wed Jan 21 05:12:11 2009 From: http (Paul Rubin) Date: 21 Jan 2009 02:12:11 -0800 Subject: what's the point of rpython? References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <7xvds9q878.fsf@ruckus.brouhaha.com> Brendan Miller writes: > I'm curious about that. I've been looking around for timing > information on the lock signal, but am having some trouble finding > them. Intuitively, given that the processor is much faster than the > bus, and you are just waiting for processor to complete an addition or > comparison before put the new memory value on the bus, it seems like > there should be very little additional bus contention vs a normal add > instruction. The bus is slow compared with the L1 cache. I just looked for figures and couldn't find any either, but I remember seeing some for the Core 2 saying around 100 cycles, and something similar for the Athlon. I just came across something saying the Core i7 is considerably better than the Core 2 at this. The real solution is to not use so much bus locking. Get rid of the ref counts and use a real gc, if not in CPython then in PyPy. From deets at nospam.web.de Wed Jan 21 05:21:34 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 11:21:34 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <6tob9eFbqi6gU1@mid.uni-berlin.de> James Stroud wrote: > Thomas Guettler wrote: >> Hi, >> >> I want to start Python at the client side from a web application. The >> app is an intranet application, and all client PCs are under our control >> (we can install software on them). >> >> But I don't want to update the installation too often. Here is my idea: >> >> We create a custom mime-type and register it on the client PC. The web >> application can send signed python code to the client PC. If the >> signature is correct, the code will be executed at the client. The >> signature prevents others from executing code. >> >> Has someone seen or done something like this before? >> >> I can code this myself, but prefer to use some open source project, if it >> exists. >> >> >> Thanks in advance, >> Thomas G?ttler >> > > You are better off using a cron job (or similar) on the client side, > getting the client to hit the web server for the code at regular > intervals, and if code is ready, execute. If code isn't ready, wait for > the next interval. Use https for security and have a shared secret > message to identify legitimate clients. > > If you try to push code the other way, you will need a perpetual socket > open on the client side, making the client the server. If the OP finds a method to trigger the execution of his program, the question of who's client and who not is moot. If he wants, he can make the software query a server via HTTP (he's got that up & reachable from the PC anyway) for it's new code. All he needs is some session-key being passed on invocation. Diez From mynthon1 at gmail.com Wed Jan 21 05:50:53 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 02:50:53 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long Message-ID: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> I have very long path on windows and i get error when try to get modification time. So i tried do chdir path and then get file. It now gives me error that file doesn't exists # code def getmtimeWIN32(p): mycwd = os.getcwd() if p.startswith('\\\\?\\'): p = p.replace('\\\\?\\', '', 1) p = os.path.splitdrive(p) r = p[0] # root - dir name p = p[1] p = os.path.split(p) f = p[1] # filename d = p[0] l = d.split('\\'); if r != '': # if root is not empty change to root (it not works when script is on other partition than file) os.chdir('/') for i in l: if i != '': os.chdir(i) #print i print os.getcwd() os.path.getmtime(f) os.chdir(mycwd) # /code it works for other files so i suppose it is not my fault. I know there is a win32 module but i can't find any documentation for it (what is the purpose to create app without docs?). Any idea? I searched google but there where only 2 options. Use chdir (not working) or use win32api (where is no documentation). (python 2.5) From hv at tbz-pariv.de Wed Jan 21 06:17:16 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 21 Jan 2009 12:17:16 +0100 Subject: Start Python at client side from web app In-Reply-To: <6to3kfFbr0psU1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <6toehtFbrb81U1@mid.individual.net> Sorry, I described my problem not well. Here is more information: The main application is the intranet web application used with IE (ms windows client). But some action needs to be done on the client since you can't do it with html or javascript. 1. The user pushes a button in the web app. 2. Webserver sends signed python code to the client with own mime type 3. IE sends code to the python application. 4. Signature gets checked, Python code on the client gets executed. 5. Maybe send some data to the server with http. Thomas Server runs Linux with Django and Postgres. Thomas Guettler schrieb: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. > > Has someone seen or done something like this before? > > I can code this myself, but prefer to use some open source project, if it exists. > > > Thanks in advance, > Thomas G?ttler > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From deets at nospam.web.de Wed Jan 21 06:21:57 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 12:21:57 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6toeqlFbrcfoU1@mid.uni-berlin.de> Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms > windows client). But some action needs to be done on the client since you > can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. As I already told you on the german python NG (why do you post on *two* lists?), I'd rather go for a custom network protocol. This is supported by the various OSses, and browsers just hook into it. Then, when the user presses a "myprotocol://some/parameters"-link (or get's redirected there through JS), the registered application will be fired up to handle the url. You then simply use the passed parameters to make a call to your webserver to fetch the new code. Diez From sturlamolden at yahoo.no Wed Jan 21 06:31:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 21 Jan 2009 03:31:26 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: <1105f65d-16d0-441c-9cd2-89c4011eb403@v39g2000pro.googlegroups.com> On Jan 21, 12:13 am, sturlamolden wrote: > Apart from that, an FFT in pure python is going to be atrociously slow > for anything but the shortest signals. I cannot imagine why you want > to do this. Just to elaborate on this: The whole purpose of using FFT is speed. That pretty much excludes the use of Python. If you don't care about speed, you could just as well compute the DFT directly. The FFT is just a O(n lon n) algorithm for computing the DFT. Here is a DFT with O(N**2) behavior: from math import sin, cos, pi def real_dft(x): ''' DFT for a real valued sequence x ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 for n in range(M): s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) r.append(s) return r S.M. From skip at pobox.com Wed Jan 21 06:31:45 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 21 Jan 2009 05:31:45 -0600 Subject: what's the point of rpython? In-Reply-To: References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <18807.1953.921513.129961@montanaro.dyndns.org> Brendan> Intuitively, given that the processor is much Brendan> faster than the bus, and you are just waiting for processor to Brendan> complete an addition or comparison before put the new memory Brendan> value on the bus... I think in Python's case the reference count will often be in the processor's local cache. (Presumably, if the current thread is going to Py_DECREF the object it's been working with the object's state recently.) The stuff I read suggested that simply locking the local cache would be significantly faster than having to lock the memory bus. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 06:54:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 12:54:31 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <49770cf1$0$3521$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > In any case, I have suggested that Python should perhaps get a new > keyword, "private" or "priv". And quite a few people - most of them using Python daily - answered they didn't wan't it. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:01:34 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:01:34 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: <49770e98$0$18763$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. There are two points here. The first one is whether what you suggest is seen as "a potential improvement", by the language's designers and by the majority of the language's users. The answer here is obviously "no". The second point is about your vision of Python as "a product". It is not - at least, not in the sense of a "commercial product". It's a FOSS project, and this effectively means that if you really want to get something done, specially when almost no one seems interested, you *do* have to DoItYourself(tm). But I *really* doubt it'll make it Python anyway. IOW : if you want access restrictions in Python, fork the project and do what you want with your fork (as long as you respect the Python licence of course). From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:04:39 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:04:39 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <49770f51$0$743$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? Calling people names is certainly not the best way to defend your opinions here. Adios, Mr. P. From digitig at gmail.com Wed Jan 21 07:11:11 2009 From: digitig at gmail.com (Tim Rowe) Date: Wed, 21 Jan 2009 12:11:11 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xwscpyvrd.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> <7xwscpyvrd.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/21 Paul Rubin <"http://phr.cx"@nospam.invalid>: > I have no direct experience with it but have read a little about it. > It looks to be a fairly vanilla block structured imperative language > like Pascal with some concurrency stuff added. The sense I have is > that it's not especially harder to program in than C or C++, but the > programs come out much more reliable. It is rather more than that, in that it's particularly strict (and it has a particularly powerful arithmetic model), but its roots are certainly there. At a conference on the safe subset, SPARK Ada, one of the SPARK developers pointed out that the SPARK Ada subset was effectively Modula2. Programs done in Ada are, by objective measures, more reliable than those done in C and C++ (the very best released C++ programs are about as good as the worst released Ada programs), although I've always wondered how much of that is because of language differences and how much is because Ada tends to be used on critical projects that also tend to get a lot more attention to development standards. -- Tim Rowe From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:19:46 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:19:46 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xprih5d5z.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> Message-ID: <497712dc$0$7896$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> Zope is about 375 KLOC[1], >> How many LOCS would it require if it was written in ADA ? > > No idea. Ada is a lot more verbose than Python, but I'm baffled at > what the heck Zope is actually doing with all that code. > >>> Zope also has 275 open bugs, 6 of which are critical. >> None of which are going to *kill* anyone FWIW. Now how many of these >> bugs would have language-enforced access restriction prevented ? > > I'm not about to audit 375 KLOC of code to find out. Regardless of > whether access restriction actually prevents bugs though, it certainly > makes auditing easier. pylint is your friend. > And auditing does find bugs. > >>> [2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC >> of a hi-level dynamic language ? Hm, I guess not. > > I think written in some forerunner of Ada. Yeps, probably something like this. Not specially hi level nor dynamic, is it ? >> Given the difference in LOCS count between a low-level static language >> and a hi-level dynamic language for the implementation of a same given >> features set, you cannot just define "large" by the # of LOCS. Not >> that I'm going to compare Zope with Space shuttle's stuff. > > I don't think static vs dynamic makes much difference in the amount of > LOCS to accomplish some function. My own experience is that it does make a huge difference - talking about imperative languages, of course. > In my limited experience with > Haskell (statically typed but very high level), "dynamic" and "static" were not meant to concern typing here (or at least not only typing). Haskell and MLs are indeed statically typed, but with a powerfull type inference system, which gives great support for genericity (hmmm... is that the appropriate word ?) Now these are functional languages, so the notion of "access restriction" is just moot in this context !-) > it takes around the > same amount of Haskell code as Python code (sometimes more, sometimes > less) to do a given task. Not exactly my own experience, but I confess I'm much more fluent with Python than with Haskell !-) > More important for concise code is features > like higher-level functions and types (e.g. it's easy in Python or > Haskell, but a huge pain in Java or C, to write down a value that is a > list of dictionaries whose keys are tuples and whose values are more > lists of dictionaries, to code something list a listcomp, etc). Yes, indeed. So you agree that Haskell is not exactly a "low level" language, do you ?-) Ok, I should probably have made clear I was thinking of a hi-level dynamic _imperative_ language vs a low-level static _imperative_ language. FP is quite another world. From mdw at distorted.org.uk Wed Jan 21 07:45:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 12:45:58 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87d4eghlo9.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > I'm not sure what you mean by "conflating module and class systems." > Are you referring to the fact that Java requires each class to be in > its own file of the same name (I don't use Java, but that's what I've > heard)? If so, I agree that is a bad idea. No. I mean that using classes as a unit of access control is wrong. A class is a unit of behaviour, but that behaviour can (and often should) come from a number of places. Common Lisp gets this right. Classes define slots for their instances; slots are named by symbols. If you can write the symbol, you can access the slot. But symbols are managed by packages: packages can export some symbols and keep others internal; and they can import symbols from other packages. The same mechanism works for functions, variables, classes, types, macros, and all the other random namespaces that Lisp (like most languages) has. Python keeps access control separate from classes. And I think I'd like it to stay that way. (Lisp's package system also solves the problem that a class's -- and its superclasses' -- attributes and methods form a namespace which isn't well-managed in many languages. Since CL uses symbols for these, and symbols belong to packages, MDW::MUMBLE isn't the same symbol as RUSS-P::MUMBLE and so they name different slots.) -- [mdw] From mdw at distorted.org.uk Wed Jan 21 07:55:32 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 12:55:32 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: <8763k8hl8b.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Which is why I was hoping that Python might get enforced data hiding > as well as optional static type declarations that can actually be used > for static verification. But maybe that's all just a pipe dream on my > part -- or "onanism." I think that, if you want static assurances, Python -- or any dynamic language, for that matter -- just isn't for you. Please feel free to use Java, C#, C++, or more interesting languages like ML variants or Haskell -- or even Ada dialects, which (I should have mentioned) do seem to have some very impressive proof-maintenance tools available for them. -- [mdw] From mynthon1 at gmail.com Wed Jan 21 08:13:35 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 05:13:35 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> Message-ID: <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> On Jan 21, 11:50?am, mynthon wrote: > I have very long path on windows and i get error when try to get > modification time. So i tried do chdir path and then get file. It now > gives me error that file doesn't exists > > # code > def getmtimeWIN32(p): > ? ? mycwd = os.getcwd() > > ? ? if p.startswith('\\\\?\\'): > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > ? ? p = os.path.splitdrive(p) > ? ? r = p[0] # root - dir name > ? ? p = p[1] > ? ? p = os.path.split(p) > ? ? f = p[1] # filename > ? ? d = p[0] > ? ? l = d.split('\\'); > > ? ? if r != '': # if root is not empty change to root (it not works > when script is on other partition than file) > ? ? ? ? os.chdir('/') > > ? ? for i in l: > ? ? ? ? if i != '': > ? ? ? ? ? ? os.chdir(i) > ? ? ? ? ? ? #print i > ? ? print os.getcwd() > ? ? os.path.getmtime(f) > ? ? os.chdir(mycwd) > # /code > > it works for other files so i suppose it is not my fault. I know there > is a win32 module but i can't find any documentation for it (what is > the purpose to create app without docs?). Any idea? > > I searched google but there where only 2 options. Use chdir (not > working) or use win32api (where is no documentation). > > (python 2.5) ok, what ive found: os.chdir('very_long_path') # works os.listdir('very_long_path') # gives: Traceback (most recent call last): File "", line 1, in TypeError: listdir() argument 1 must be (buffer overflow), not str os.chdir('very_long_path') os.listdir('.') #works os.chdir('very_long_path') os.path.getmtime(os.listdir('.')[0]) #throws exception (path not exists) os.chdir('very_long_path') open(os.listdir('.')[0]) #throws exception (path not exists) From steve at holdenweb.com Wed Jan 21 08:31:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:31:44 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: Because your print statement defines the lambda without calling it. regards Steve Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. > > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino > -- > http://mail.python.org/mailman/listinfo/python-list > -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:34:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:34:19 -0500 Subject: Problem with 3.0 Install on Windows In-Reply-To: References: Message-ID: Saul Spatz wrote: > I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get > familiar with it. I have a directory with all my python projects in my > PYTHONPATH variable. When I try to run python 3.0, it detects a syntax > error (a print statement) in the first file in this directory, and > crashes. I don't want to convert the files to 3.0 syntax, because I > plan to keep using 2.5, at least for a while. > What's the name of that file? Does it clash with some system module that the interpreter is trying to load? In circumstances like this a traceback printout is always more helpful than a verbal description of the behavior. > I don't know exactly why this translation is happening. Is there a way > to turn it off? > "Translation"? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:37:25 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:37:25 -0500 Subject: How to write a simple shell loop in python? In-Reply-To: <1232509966.4430.28.camel@pippi.pippi> References: <1232509966.4430.28.camel@pippi.pippi> Message-ID: <49772515.90306@holdenweb.com> Dietrich Bollmann wrote: > Hi, > > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > > Is there any logic explanation for this? > How can I get rid of the blank? > Is there a smarter way to write a simple shell loop which would work > better? > > Thanks, Dietrich > > > Here my approach: > > $ python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() Just replace the lines above with input = raw_input("$ ") and you'll be fine. The "," in the print statement causes the interpreter to set a flag to emit a space before the next output unless it has just printed a newline. The "newline", of course, is provided by the input, so the next print emits a space since it *hasn't* just emitted a newline. regards Steve > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one > one > one > one > $ two > two > two > two > $ three > three > three > three > $ > Traceback (most recent call last): > File "", line 3, in > KeyboardInterrupt > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:47:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:47:48 -0500 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> Message-ID: Xah Lee wrote: > On Jan 19, 11:17 pm, alex23 wrote: > ... [...] > sure. In a political context, many criticism or description of the > situation from one party can be seen as ad hominem attack. I feel that > that many old emacs users, which includes significant portion of emacs > developers (if not majority), are so exteremly bottled up and turn > down any possibility of advancing. They are killing emacs. (similar > feelings for most regular posters here in comp.lang.lisp ) > This might have been relevant if you had not been too stupid to observe that you are (sigh, yet again) posting irrelevant drivel to comp.lang.python. Please stop. [...] > Your input will be highly valued. Though, forgive me to say, that i > think my opinion on this is beyond any computer scientist of any > standing can try to tell me otherwise. If they disagree (which i think > most of them won't), i think their knowledge and experience in the > area of computer languages and syntax and notations, IQ, are inferior > to me. > How very comforting for you. "Closed mind" hardly begins to describe that attitude. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mynthon1 at gmail.com Wed Jan 21 08:58:37 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 05:58:37 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> Message-ID: On Jan 21, 2:13?pm, mynthon wrote: > On Jan 21, 11:50?am, mynthon wrote: > > > > > I have very long path on windows and i get error when try to get > > modification time. So i tried do chdir path and then get file. It now > > gives me error that file doesn't exists > > > # code > > def getmtimeWIN32(p): > > ? ? mycwd = os.getcwd() > > > ? ? if p.startswith('\\\\?\\'): > > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > > ? ? p = os.path.splitdrive(p) > > ? ? r = p[0] # root - dir name > > ? ? p = p[1] > > ? ? p = os.path.split(p) > > ? ? f = p[1] # filename > > ? ? d = p[0] > > ? ? l = d.split('\\'); > > > ? ? if r != '': # if root is not empty change to root (it not works > > when script is on other partition than file) > > ? ? ? ? os.chdir('/') > > > ? ? for i in l: > > ? ? ? ? if i != '': > > ? ? ? ? ? ? os.chdir(i) > > ? ? ? ? ? ? #print i > > ? ? print os.getcwd() > > ? ? os.path.getmtime(f) > > ? ? os.chdir(mycwd) > > # /code > > > it works for other files so i suppose it is not my fault. I know there > > is a win32 module but i can't find any documentation for it (what is > > the purpose to create app without docs?). Any idea? > > > I searched google but there where only 2 options. Use chdir (not > > working) or use win32api (where is no documentation). > > > (python 2.5) > > ok, what ive found: > > os.chdir('very_long_path') > # works > > os.listdir('very_long_path') > # gives: > Traceback (most recent call last): > ? File "", line 1, in > TypeError: listdir() argument 1 must be (buffer overflow), not str > > os.chdir('very_long_path') > os.listdir('.') > #works > > os.chdir('very_long_path') > os.path.getmtime(os.listdir('.')[0]) > #throws exception (path not exists) > > os.chdir('very_long_path') > open(os.listdir('.')[0]) > #throws exception (path not exists) i dont have a solution but workaround. I can map long path as drive: longPath = "c:\\documents and settings\\usermth\\my documents\ \......blablablabla" # map path as drive b: (notice "" around path to avoid problems with spaces) os.system('subst b: "%s"' % longPath) longPath = 'b:\\' From mynthon1 at gmail.com Wed Jan 21 09:11:03 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 06:11:03 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> Message-ID: <31d0d026-3e88-4730-8368-af76424f17ef@w1g2000prm.googlegroups.com> On Jan 21, 2:58?pm, mynthon wrote: > On Jan 21, 2:13?pm, mynthon wrote: > > > > > On Jan 21, 11:50?am, mynthon wrote: > > > > I have very long path on windows and i get error when try to get > > > modification time. So i tried do chdir path and then get file. It now > > > gives me error that file doesn't exists > > > > # code > > > def getmtimeWIN32(p): > > > ? ? mycwd = os.getcwd() > > > > ? ? if p.startswith('\\\\?\\'): > > > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > > > ? ? p = os.path.splitdrive(p) > > > ? ? r = p[0] # root - dir name > > > ? ? p = p[1] > > > ? ? p = os.path.split(p) > > > ? ? f = p[1] # filename > > > ? ? d = p[0] > > > ? ? l = d.split('\\'); > > > > ? ? if r != '': # if root is not empty change to root (it not works > > > when script is on other partition than file) > > > ? ? ? ? os.chdir('/') > > > > ? ? for i in l: > > > ? ? ? ? if i != '': > > > ? ? ? ? ? ? os.chdir(i) > > > ? ? ? ? ? ? #print i > > > ? ? print os.getcwd() > > > ? ? os.path.getmtime(f) > > > ? ? os.chdir(mycwd) > > > # /code > > > > it works for other files so i suppose it is not my fault. I know there > > > is a win32 module but i can't find any documentation for it (what is > > > the purpose to create app without docs?). Any idea? > > > > I searched google but there where only 2 options. Use chdir (not > > > working) or use win32api (where is no documentation). > > > > (python 2.5) > > > ok, what ive found: > > > os.chdir('very_long_path') > > # works > > > os.listdir('very_long_path') > > # gives: > > Traceback (most recent call last): > > ? File "", line 1, in > > TypeError: listdir() argument 1 must be (buffer overflow), not str > > > os.chdir('very_long_path') > > os.listdir('.') > > #works > > > os.chdir('very_long_path') > > os.path.getmtime(os.listdir('.')[0]) > > #throws exception (path not exists) > > > os.chdir('very_long_path') > > open(os.listdir('.')[0]) > > #throws exception (path not exists) > > i dont have a solution but workaround. > I can map long path as drive: > > longPath = "c:\\documents and settings\\usermth\\my documents\ > \......blablablabla" > > # map path as drive b: (notice "" around path to avoid problems with > spaces) > os.system('subst b: "%s"' % longPath) > > longPath = 'b:\\' you can also use \\?\ prefix but ONLY FOR unicode strings os.path.getmtime("\\\\?\\c:\\very lon path\\blablabla") #will not work os.path.getmtime(u"\\\\?\\c:\\very lon path\\blablabla") #will work From duncan.booth at invalid.invalid Wed Jan 21 09:31:46 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Jan 2009 14:31:46 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: Message-ID: Terry Reedy wrote: > Delaney, Timothy (Tim) wrote: >> Terry Reedy wrote: >> >>>> The compiled code differs. >>> I *strongly* doubt that. Properties are designed to be transparent to >>> user code that access atrributes through the usual dotted name >>> notation precisely so that class code can be changed from >>> x = ob >>> to >>> x = property(get_x, set_x, del_x) >>> without changing user code. >> >> He was talking about C# with that statement. In C#, the compiled code >> differs depending on whether you use a property or an attribute. Or at >> least that's how I interpreted it. > > Checking back, I see now that Luis Z. went from Python > "It boggles me when I see python code with properties that only set and > get the attribute, or even worse, getters and setters for that > purpose. " to C#, and that Duncan was seemingly responding to the C# > part. If C# is like that, how inconvenient. It's a long enough thread that I can't see anyone faulting you for falling asleep half way through my post. C# forces you to spend a lot of time writing trivial getters and setters. They've 'improved' it in the more recent versions: you no longer have to write any body at all for a trivial getter or setter and the compiler will generate one for you provided you have declared the property with a leading capital letter and a private attribute with the same name but a lowercase letter. Ick. > >> You are of course correct as to how Python does it. > > I guess I am spoiled ;-). > That's why we're all here. -- Duncan Booth http://kupuguy.blogspot.com From Tribulations at Paralleles.invalid Wed Jan 21 10:16:32 2009 From: Tribulations at Paralleles.invalid (TP) Date: Wed, 21 Jan 2009 16:16:32 +0100 Subject: is this pythonic? Message-ID: Hi, Is the following code pythonic: >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>> dict = [ dict for dict in l if dict['title']=='ti'] >>> l.remove(*dict) >>> l [{'title': 'to', 'value': 2}] Precision: I have stored data in the list of dictionaries l, because in my application I am sure that "title" is unique for each record. But perhaps it is better to imagine that someday it will not be anymore the case? And rather use a data storage as the following? l = { '001':{"title":"to", "value":2}, '002' {"title":"ti","value":"coucou"}} The problem with this storage is that it implies to manipulate some "ids" that have not any meaning for a humain being (001, 002, etc). Thanks a lot for you opinion, -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From aahz at pythoncraft.com Wed Jan 21 10:17:17 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 07:17:17 -0800 Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: In article <313a27f9-c655-4fc4-a8e3-568a4283bba2 at f40g2000pri.googlegroups.com>, ag73 wrote: > > form = urllib.parse.parse_qs(qs, keep_blank_values=1) > >However, the last line of code that calls parse_qs causes the >following exception to be thrown: > > >Type str doesn't support the buffer API One of the key features of Python 3.0 is the fact that it now distinguishes between bytes and strings. Unfortunately, there are a lot of ambiguous areas where the correct handling is not clear; for example, nobody has yet agreed whether URLs are strings or bytes. As you discovered, forced conversion to string seems to work here and I suggest you make that your workaround. You could also file a bug on bugs.python.org (first checking to see whether someone else has already done so). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From joe at strout.net Wed Jan 21 10:17:34 2009 From: joe at strout.net (Joe Strout) Date: Wed, 21 Jan 2009 08:17:34 -0700 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <49773C8E.2040905@strout.net> Steven D'Aprano wrote: >> LogError "Walk has gotten too silly", CurrentTime >> >> Here, LogError is a method call that takes two arguments, and >> CurrentTime is a method call that takes none. > > That seems ambiguous to me. As a non-RealBasic programmer, I can see at > least four meanings it could have. Translated into Python, they are: > > LogError("Walk has gotten too silly", CurrentTime) > LogError("Walk has gotten too silly"), CurrentTime > LogError("Walk has gotten too silly", CurrentTime()) > LogError("Walk has gotten too silly"), CurrentTime() It's not ambiguous because RB doesn't have a tuple syntax that looks the same as arguments to a function call. You also can't get a reference to a method simply by naming it; naming it invokes it (when you want a reference to it instead, you use the "AddressOf" keyword). So, the first and third of your lines above mean the same thing, and are the correct (and only possible) interpretation. The second and fourth are also equivalent, but would require the parentheses around the LogError parameter since in that case it is a function (i.e. returns a result). As I said before, I'm not sure how you would apply this to Python, where other syntax choices (tuples, function references, etc.) get in the way of this idea. I'm merely pointing out that what Aaron asked for is possible without ambiguity, and actually used in at least one real-world language. > But even if RB doesn't have these things, I question that the syntax is > "beautiful". Consider some arbitrary method Foo. If you see this: > > Foo > > Is that legal RB syntax? You betcha! For example, the built-in method to play the standard system alert sound is: Beep Doesn't get much more readable and syntax-free than that. Suppose now that a beep isn't eloquent enough, and you want the computer to speak something out loud instead. Also easy: Speak "Spam, spam, spam, baked beans and spam." If you're writing a console app, then there's a built in "Print" subroutine that puts a string to stdout. Its usage is: Print "Spam, spam, spam, baked beans and spam." Note that this syntax is exactly like Python's "print" syntax prior to 3.0, but in RB, it's not a special case -- it's just another method call, and you can define your own methods that you invoke exactly the same way. > Maybe yes, maybe no. It all depends on what Foo > does. If it returns no result, then it's legal. If it returns a result, > it isn't. Right. In other words, you can tell just by looking at the call that it doesn't return a result. This is often handy. > So the question of whether syntax is legal depends, not on the > syntactic elements involved, but on the *semantics* of the method > (whether or not it returns a result). But of course. Any method call is legal only if the form of the call matches the method prototype -- if you try to call a function that requires 4 parameters, and give it only 3, that's an error too. I don't see how this is different in any important way. >> Eliminating unnecessary parentheses does a lot to improve the >> readability of the code IMHO. > > But they're not unnecessary, at least not in Python, they're useful for > distinguishing between calling the function and the function itself. Yes, quite true in Python. If there were some other way to distinguish between those -- and if tuple syntax didn't look the same as method call arguments -- THEN they would be unnecessary. But those would be very substantial changes to Python syntax, and I'm not seriously proposing them. Best, - Joe From aahz at pythoncraft.com Wed Jan 21 10:19:44 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 07:19:44 -0800 Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: In article , Ben Sizer wrote: > >I have the following C++ code and am attempting to embed Python 2.5, >but although the "import sys" statement works, attempting to reference >"sys.path" from inside a function after that point fails. It's as if >it's not treating it as a normal module but as any other global >variable which I'd have to explicitly qualify. After skimming the thread and seeing a lack of answer, I suggest you try capi-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From google at mrabarnett.plus.com Wed Jan 21 10:24:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 15:24:01 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> Message-ID: <49773E11.3070804@mrabarnett.plus.com> Russ P. wrote: > On Jan 20, 10:02 pm, alex23 wrote: > >> Can I comprehend that you don't even have an immediate need and are >> instead actively engaging in online onanism? Absolutely. > > So anyone thinking beyond an "immediate need" is "engaging in online > onanism"? > That doesn't mean what you think it means. > Let's see. How long ago did the Python community start thinking about > Python 3? > > So I guess they're all a bunch of jerkoffs, eh? > From joe at strout.net Wed Jan 21 10:24:51 2009 From: joe at strout.net (Joe Strout) Date: Wed, 21 Jan 2009 08:24:51 -0700 Subject: English-like Python In-Reply-To: <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> Message-ID: <49773E43.3050101@strout.net> Aaron Brady wrote: > Where functions are first-class objects, a bare function object isn't > distinguishable either from its call. That depends not on whether functions are first-class objects, but on the *syntax* of function invocation vs. function reference. It just so happens than in Python, the syntax for the latter is the bare function identifier. But it wouldn't have to be -- you could use "@foo" or "{foo}" or "ref foo" or (as in RB) "AddressOf foo" or any number of other alternatives to accomplish the same thing, and functions would still be first-class objects. I'll grant that having any such syntax makes them *odd* first-class objects, since all other objects are referred to with a naked identifier, and invoked (if they are callable) with some other syntax. It'd be weird and inconsistent to have functions turn that around. But, despite being inconsistent, it might still be sensible, based on the observation that we generally need to invoke methods a lot more often than we need to get a reference to them. > I'm granting that it's useful > to return values a lot. For example: > > a= f > > could mean either, 'a= f' or 'a= f()'. Once again the return values > save the day. I think I agree (if I follow you correctly). But then some other syntax would be needed for when you really mean "a=f" (i.e., make 'a' refer to the same function as 'f'). Best, - Joe From mnations at gmail.com Wed Jan 21 10:45:27 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 07:45:27 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: This is something I've wondered about for a while. I know that theoretically Python is supposed to auto-recognize duplicate imports; however I've run into problems in the past if I didn't arrange the imports in a certain way across multiple files. As a result, I worry about conflicts that arise because something has been imported twice. So...I'm not sure if Python *always* gets this correct. Also, I understand what you're saying about the organization of files based on modules and maybe regrouping based on use. However I like the organization of my files to be a grouping of logical components in my application. This makes it easy to keep things separated and keeps files from getting to long (which takes longer to program because you're always bouncing up and down large files). As a result, if I have to worry about grouping by shared modules then it makes that more difficult. I think it would great to have access to a file (like the __init__.py file for packages) which all the files in the same directory would have access to for common imports. That way you could push out the repeated imports and also clean up the look a little bit as well. On Jan 7, 11:53?am, Paul McGuire wrote: > ...and don't worry about a possible performance issue of importing os > (or any other module) multiple times - the Pythonimportmanager is > smart enough to recognize previously importedmodules, and wontimport > them again. > > If a module uses the os module, then it shouldimportit - that's just > it. > > Another consideration might be that you are breaking up your own > programmodulestoo much. ?For instance, if I had a program in which I > were importing urllib in lots ofmodules, it might indicate that I > still have some regrouping to do, and that I could probably gather all > of my urllib dependent code into a single place. > > -- Paul From dnhkng at googlemail.com Wed Jan 21 10:52:51 2009 From: dnhkng at googlemail.com (Dr Mephesto) Date: Wed, 21 Jan 2009 07:52:51 -0800 (PST) Subject: quick beginners List comprehension question Message-ID: Hi, Im new to python, and OOP, and am trying to get a handle on list comprehension. Say I have a class Foo with a property called bar: class Foo: def __init__(self): self.bar = random.randint(1,100) and then I make a list of these objects: Newlist = [] for x in range(10): Newlist.append(Foo()) Now, suppose I wanted to triple the value of 'bar', I could always do: for x in range(10): Newlist[x].bar = Newlist[x].bar * 3 but can I do this using list comprehension? Thanks in Advance! From deets at nospam.web.de Wed Jan 21 10:57:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 16:57:28 +0100 Subject: quick beginners List comprehension question References: Message-ID: <6touv8Fc32elU1@mid.uni-berlin.de> Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! No, as such, because list-comprehensions require you to have an *expression* in front of the iteration: resultlist = [ for in ] Now what you of course can do is this: def multiply(item): item.bar = item.bar * 3 [multiply(i) for i in items] However, doing this will make python produce a list of None-references - which is a waste. It's up to you if you care about that, but generally it is frowned upon because of that, and the fact that the conciseness of the list-comp here isn't really helping with the readability. Diez From google at mrabarnett.plus.com Wed Jan 21 11:03:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 16:03:42 +0000 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: <4977475E.5060705@mrabarnett.plus.com> Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! > You could reduce that to: for x in Newlist: x.bar *= 3 but I don't think you could do it with list comprehension. From philip at semanchuk.com Wed Jan 21 11:18:49 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 21 Jan 2009 11:18:49 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: On Jan 21, 2009, at 10:52 AM, Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! Other answers have been good; to them I'll add the comment that list comprehensions are for *constructing* lists, not manipulating the elements thereof. HTH Philip From Scott.Daniels at Acm.Org Wed Jan 21 11:19:04 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 08:19:04 -0800 Subject: what's the point of rpython? In-Reply-To: References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: Brendan Miller wrote: > On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: >> .... Of course I'm aware of the LOCK prefix but it slows >> down the instruction enormously compared with a non-locked instruction. > > I'm curious about that. I've been looking around for timing > information on the lock signal, but am having some trouble finding > them. Intuitively, given that the processor is much faster than the > bus, and you are just waiting for processor to complete an addition or > comparison before put the new memory value on the bus, it seems like > there should be very little additional bus contention vs a normal add > instruction. The opcode cannot simply talk to its cache, it must either go directly to off-chip memory or communicate to other processors that it (and it alone) owns the increment target. --Scott David Daniels Scott.Daniels at Acm.Org From marco at sferacarta.com Wed Jan 21 11:29:24 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 21 Jan 2009 17:29:24 +0100 Subject: Importing modules In-Reply-To: References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: Mudcat wrote: > This is something I've wondered about for a while. I know that > theoretically Python is supposed to auto-recognize duplicate imports; > however I've run into problems in the past if I didn't arrange the > imports in a certain way across multiple files. I think you've probably had issues with circular imports (i.e. mutual dependencies), unless you can precisely remember what you were doing and what went wrong. > As a result, I worry about conflicts that arise because something has been imported twice. > So...I'm not sure if Python *always* gets this correct. It doesn't import twice, and never did. > Also, I understand what you're saying about the organization of files > based on modules and maybe regrouping based on use. However I like the > organization of my files to be a grouping of logical components in my > application. I can make up three or four different logical groupings in my applications... so what is 'logical' could not be the same for everyone, or from every point of view. From ppearson at nowhere.invalid Wed Jan 21 11:32:43 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 21 Jan 2009 16:32:43 GMT Subject: is this pythonic? References: Message-ID: <6tp11bFbtfrgU1@mid.individual.net> On Wed, 21 Jan 2009 16:16:32 +0100, TP wrote: > > Is the following code pythonic: > >>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>> l.remove(*dict) >>>> l > [{'title': 'to', 'value': 2}] > > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? [snip] 1. You probably don't want to use the name "dict". 2. I believe this code will fail if the number of dictionaries with title="ti" is not exactly 1. It that your intention? (You probably answered this question in the last paragraph quoted above, but I can't make it out.) -- To email me, substitute nowhere->spamcop, invalid->net. From Scott.Daniels at Acm.Org Wed Jan 21 11:38:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 08:38:28 -0800 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: Dietrich Bollmann wrote: > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > Is there any logic explanation for this? Yes > How can I get rid of the blank? By not asking for it with the comma. > >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one The one and \n above are from stdin, not stdout. So stdout thinks it is still on the same line as the $. > one The space separates the 'one' from the '$ ' that it output to stdout above. > one > one --Scott David Daniels Scott.Daniels at Acm.Org From google at mrabarnett.plus.com Wed Jan 21 11:39:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 16:39:37 +0000 Subject: quick beginners List comprehension question In-Reply-To: <6touv8Fc32elU1@mid.uni-berlin.de> References: <6touv8Fc32elU1@mid.uni-berlin.de> Message-ID: <49774FC9.4040802@mrabarnett.plus.com> Diez B. Roggisch wrote: > Dr Mephesto wrote: > >> Hi, >> Im new to python, and OOP, and am trying to get a handle on list >> comprehension. >> >> Say I have a class Foo with a property called bar: >> >> class Foo: >> def __init__(self): >> self.bar = random.randint(1,100) >> >> and then I make a list of these objects: >> >> Newlist = [] >> for x in range(10): >> Newlist.append(Foo()) >> >> Now, suppose I wanted to triple the value of 'bar', I could always do: >> >> for x in range(10): >> Newlist[x].bar = Newlist[x].bar * 3 >> >> but can I do this using list comprehension? Thanks in Advance! > > No, as such, because list-comprehensions require you to have an *expression* > in front of the iteration: > > resultlist = [ for in ] > > Now what you of course can do is this: > > def multiply(item): > item.bar = item.bar * 3 > > [multiply(i) for i in items] > > However, doing this will make python produce a list of None-references - > which is a waste. It's up to you if you care about that, but generally it > is frowned upon because of that, and the fact that the conciseness of the > list-comp here isn't really helping with the readability. > If you had: def multiply(item): item.bar = item.bar * 3 return item then: [multiply(i) for i in items] would return items. Still a bad idea, though, because you're using a list comprehension for its side-effect. From kdawg44 at gmail.com Wed Jan 21 11:50:33 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 11:50:33 -0500 Subject: Beating a Timeout Message-ID: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Hi, I am trying to write a python script that I can run to prevent a timeout of webpage. I have to use a system at work that keeps track of issues. I use this a couple of time an hour and it times out after 10 minutes. The system is really crummy and it rejects your username and password about 30-40 times before it takes it. It is supposed to integrate with Active Directory and I don't think it does it very well. So I have this open in Internet Explorer (its all in asp.net so it does not work in any other browser). I was hoping to have something simple like: #c:\Python25\python import urllib import urllib2 import time while True: result = urllib.urlopen("the_URL ") print "Retrieved Page" time.sleep(300) But this is not working.... The code on the page uses a hidden iFrame that has a javascript file that monitors the time and intiates the timeout. The src of the hidden iFrame is what I keep trying to grab. It is still timing out in IE. Once it times out in IE I get an error in my script saying: IOError: [Errno socket error] (10060, 'Operation timed out') The system is terrible but I am stuck with it. If it doesn't kick me out, at least its bearable... Thanks for any help you can provide. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From pecora at anvil.nrl.navy.mil Wed Jan 21 11:52:42 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 21 Jan 2009 11:52:42 -0500 Subject: quick beginners List comprehension question References: Message-ID: In article , Philip Semanchuk wrote: > > Other answers have been good; to them I'll add the comment that list > comprehensions are for *constructing* lists, not manipulating the > elements thereof. > > HTH > Philip Well this seems to work just fine. What am I missing: A=[1,2,3] print A A=[2*a for a in A] print A -- -- Lou Pecora From philbru at q.com Wed Jan 21 11:52:48 2009 From: philbru at q.com (philbru at q.com) Date: Wed, 21 Jan 2009 08:52:48 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: <17c237cd-8f34-474a-848b-f2fe15856c84@35g2000pry.googlegroups.com> On Jan 20, 3:13?pm, sturlamolden wrote: > Consider using Thompson's multitaper method, autoregression (maximum > entropy), or Welch method for your frequency estimates. Blackman- > Tuckey is also a possibility, but I see no reason to prefer that to > Welch. Multitaper and AR tends to be the better options though, but > they are not as fast as Welch' method. There is a fortran program named rainbow that has some dozen of these methods to compare with. Rainbow is located at http://www.digitalCalculus.com/demo/rainbow.html. I recommend Burg's method or AutoCorrelation but its data dependent for best choice. Phil From wuwei23 at gmail.com Wed Jan 21 11:58:15 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 08:58:15 -0800 (PST) Subject: is this pythonic? References: Message-ID: On Jan 22, 1:16?am, TP wrote: > Is the following code pythonic: > >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] > >>> dict = [ dict for dict in l if dict['title']=='ti'] > >>> l.remove(*dict) > >>> l > [{'title': 'to', 'value': 2}] Try not to use 'dict' or the name of any of the other built-in types as labels. You're stepping through an entire list just to pass another list to l.remove to step through and remove items from...in fact, given that list.remove deletes the -first- occurance of the item, you're asking it to loop through -again- to find the matching element which you've - already- detected. A better and cleaner approach would be to step through the list -once- and remove the item when you find it: for index, record in enumerate(l): if record['title'] == 'ti': l.pop(index) Or you could just use a list comprehension: l = [d for d in l if d['title'] == 'ti'] > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? It's always better to design for what you know you need, not what you may possibly need in the future. You say that you are sure that record titles are unique, so why not use them as the dictionary keys, with the values as the values: records = {'ti': 1, 'to': 2} This way your code can be replaced with: value = records.pop('ti') # if you want to know the value del records['ti'] # if you just want to delete the entry It's a lot simpler to work with and extend. From steve at holdenweb.com Wed Jan 21 12:04:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 12:04:11 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: Lou Pecora wrote: > In article , > Philip Semanchuk wrote: > >> Other answers have been good; to them I'll add the comment that list >> comprehensions are for *constructing* lists, not manipulating the >> elements thereof. >> >> HTH >> Philip > > > Well this seems to work just fine. What am I missing: > > A=[1,2,3] > print A > A=[2*a for a in A] > print A > The fact that the lists to be multiplied are attributes of a list of objects, and therefore aren't themselves a list. Look more closely at the original poster's question. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kdawg44 at gmail.com Wed Jan 21 12:18:22 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 12:18:22 -0500 Subject: Beating a Timeout In-Reply-To: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Message-ID: <5caea3690901210918s27fcd220va72fb4c9e523f7e3@mail.gmail.com> Also, the actual JS code that does this simply uses a window.location.reload() to keep the session active. So I guess the only thing could be that eash urllib.urlopen call is seen as a new session? How can I make it part of the same session I am using in IE? Or am I a hundred miles off? Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Jan 21 12:26:32 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 21 Jan 2009 12:26:32 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: <4CB53724-61AC-4302-AE59-6D022DDB357E@semanchuk.com> On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote: > In article , > Philip Semanchuk wrote: > >> >> Other answers have been good; to them I'll add the comment that list >> comprehensions are for *constructing* lists, not manipulating the >> elements thereof. >> >> HTH >> Philip > > > Well this seems to work just fine. What am I missing: > > A=[1,2,3] > print A > A=[2*a for a in A] > print A You haven't manipulated the list A, you've simply overwritten it with a new list. From google at mrabarnett.plus.com Wed Jan 21 12:27:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:27:19 +0000 Subject: is this pythonic? In-Reply-To: References: Message-ID: <49775AF7.7070006@mrabarnett.plus.com> alex23 wrote: > On Jan 22, 1:16 am, TP wrote: >> Is the following code pythonic: >>>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>>> l.remove(*dict) >>>>> l >> [{'title': 'to', 'value': 2}] > > Try not to use 'dict' or the name of any of the other built-in types > as labels. > > You're stepping through an entire list just to pass another list to > l.remove to step through and remove items from...in fact, given that > list.remove deletes the -first- occurance of the item, you're asking > it to loop through -again- to find the matching element which you've - > already- detected. A better and cleaner approach would be to step > through the list -once- and remove the item when you find it: > > for index, record in enumerate(l): > if record['title'] == 'ti': > l.pop(index) > [snip] FYI, you shouldn't modify a list you're iterating over. > Or you could just use a list comprehension: > > l = [d for d in l if d['title'] == 'ti'] > The for-loop was removing the item where there's a match, so the list comprehension in this case should keep the item where there _isn't_ a match: l = [d for d in l if d['title'] != 'ti'] [remainder snipped] From google at mrabarnett.plus.com Wed Jan 21 12:28:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:28:20 +0000 Subject: Beating a Timeout In-Reply-To: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Message-ID: <49775B34.3030402@mrabarnett.plus.com> K-Dawg wrote: > Hi, > > I am trying to write a python script that I can run to prevent a timeout > of webpage. I have to use a system at work that keeps track of issues. > I use this a couple of time an hour and it times out after 10 minutes. > The system is really crummy and it rejects your username and password > about 30-40 times before it takes it. It is supposed to integrate with > Active Directory and I don't think it does it very well. > > So I have this open in Internet Explorer (its all in asp.net > so it does not work in any other browser). I was > hoping to have something simple like: > > #c:\Python25\python > > import urllib > import urllib2 > import time > > while True: > result = urllib.urlopen("the_URL > ") > print "Retrieved Page" > time.sleep(300) > > But this is not working.... The code on the page uses a hidden iFrame > that has a javascript file that monitors the time and intiates the > timeout. The src of the hidden iFrame is what I keep trying to grab. > > It is still timing out in IE. Once it times out in IE I get an error in > my script saying: > > IOError: [Errno socket error] (10060, 'Operation timed out') > > The system is terrible but I am stuck with it. If it doesn't kick me > out, at least its bearable... > > Thanks for any help you can provide. > Have you looked at mechanize? http://wwwsearch.sourceforge.net/mechanize/ From wuwei23 at gmail.com Wed Jan 21 12:29:19 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:29:19 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> On Jan 22, 1:45?am, Mudcat wrote: > This is something I've wondered about for a while. I know that > theoretically Python is supposed to auto-recognize duplicate imports; > however I've run into problems in the past if I didn't arrange the > imports in a certain way across multiple files. As a result, I worry > about conflicts that arise because something has been imported twice. > So...I'm not sure if Python *always* gets this correct. Python -will- only import something once. Every time you import a module, Python looks up its module dictionary to see if it contains a module of that name. If not, it imports it, adds a new module object and binds the name to that object in the calling namespace. If it does exist, it retrieves the module object from the dict, and then binds the name to that object in the calling namespace. Its best to view each Python module as a completely independent namespace. If you need to use something from another module within that namespace, you need to import it. If I have a function 'f' in module 'm' that uses 'math.pow', I can't just import 'f' into a module that has imported 'math', I need to import 'math' into 'm'. Regardless of where the function (or class) ends up being used, where it is defined -must- have all of the imports that function needs to run. If you're having to set up your imports in a specific order, odds are you have either a circular dependency or are overusing 'from import *'. You should -never- (IMO) do something like 'from import x, y, z' in module 'a' and then 'from a import *' in module 'b'. If 'b' uses x, y & z, it should import them itself. If you -must- use 'import *', specify exactly what should be exported via '__all__'...in most cases, it should be restricted to only objects defined within that module. > I think it would great to have access to a file (like the __init__.py > file for packages) which all the files in the same directory would > have access to for common imports. That way you could push out the > repeated imports and also clean up the look a little bit as well. Well, you can always stick those imports into a 'common.py' and do 'from common import *' in each file that uses them. But doing so can be a pain to maintain and debug for anything more than the most simple of applications. Being able to see a module's dependencies clearly listed at the top of the file is exceptionally handy. From Tribulations at Paralleles.invalid Wed Jan 21 12:34:46 2009 From: Tribulations at Paralleles.invalid (TP) Date: Wed, 21 Jan 2009 18:34:46 +0100 Subject: is this pythonic? References: Message-ID: alex23 wrote: > Try not to use 'dict' or the name of any of the other built-in types > as labels. Ooooops... Moreover I know it... > You're stepping through an entire list just to pass another list to > l.remove to step through and remove items from...in fact, given that > list.remove deletes the -first- occurance of the item, you're asking > it to loop through -again- to find the matching element which you've - > already- detected. A better and cleaner approach would be to step > through the list -once- and remove the item when you find it: > > for index, record in enumerate(l): > if record['title'] == 'ti': > l.pop(index) Ok, I will use this solution. But it is less pythonic than list comprehensions. > Or you could just use a list comprehension: > > l = [d for d in l if d['title'] == 'ti'] Perhaps you mean rather: l = [d for d in l if d['title'] != 'ti'] ? In fact, I cannot use this solution, because I want to get back the dictionary with title 'ti', for another use (in fact, to add it to another list, see below). >> Precision: I have stored data in the list of dictionaries l, because in >> my application I am sure that "title" is unique for each record. But >> perhaps it is better to imagine that someday it will not be anymore the >> case? > > It's always better to design for what you know you need, not what you > may possibly need in the future. You say that you are sure that record > titles are unique, so why not use them as the dictionary keys, with > the values as the values: > > records = {'ti': 1, 'to': 2} > > This way your code can be replaced with: > > value = records.pop('ti') # if you want to know the value > del records['ti'] # if you just want to delete the entry > > It's a lot simpler to work with and extend. In fact, in my case, in cannot use this simple solution, because there are other fields in each dictionary, not only 2. I was not clear in my post. So my list is rather: l=[{"title":"to", "color":"blue", "value":2} {"title":"ti", "color":"red", "value":"coucou"}] So, I will rather use your solution: for index, record in enumerate(l): if record['title'] == 'ti': to_add_in_another_list = l.pop(index) another_list.append(to_add_in_another_list ) > It's always better to design for what you know you need, not what you > may possibly need in the future. Ok. Do all the programmers agree with this principle? -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From kyrie at uh.cu Wed Jan 21 12:34:57 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 12:34:57 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901211234.57944.kyrie@uh.cu> On Wednesday 21 January 2009 02:30:54 am Russ P. wrote: > That could work. As long as it's well-engineered (not a hack), well- > supported (part of the standard library), and does the job, that's > probably all that matters. But you keep failing to explay why do you need it to be _part of the standard_ library (or whatever). If you need it in your project, _use_ it. If you don't, then don't use it. If _you_ need that thing you call security, just use it already and quit complaining that we don't use it. Is there a policy in your project that you can't use any external? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kdawg44 at gmail.com Wed Jan 21 12:38:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 12:38:45 -0500 Subject: Beating a Timeout In-Reply-To: <49775B34.3030402@mrabarnett.plus.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> <49775B34.3030402@mrabarnett.plus.com> Message-ID: <5caea3690901210938g4999bfebw8278091b7d6f76d3@mail.gmail.com> Sorry about the last mesasge, I accidentally replied directly to the poster. So I now have: br = mechanize.Browser() br.open("theURL") while True: result = br.reload() print result print "Retrieved Page" time.sleep(300) But it still does not appear to be working... Shortly after I got the "Your session is about to expire" pop up. I will continue to monitor though. Is mechanize starting another session separate from my IE? Is there anyway to get my python to interact with the IE session if so? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Jan 21 12:41:02 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:41:02 -0800 (PST) Subject: is this pythonic? References: Message-ID: On Jan 22, 3:27?am, MRAB wrote: > FYI, you shouldn't modify a list you're iterating over. But I'm not. I'm building a new list and binding it to the same name as the original, which works perfectly fine (unless I'm missing something): >>> l = range(100) >>> l = [d for d in l if not d % 5] >>> l [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95] > The for-loop was removing the item where there's a match, so the list > comprehension in this case should keep the item where there _isn't_ a match: > > l = [d for d in l if d['title'] != 'ti'] Now that's a mistake. Cheers for the catch. From vedagaurav at gmail.com Wed Jan 21 12:49:08 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Wed, 21 Jan 2009 09:49:08 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error Message-ID: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Hi, I am trying to put some webpages into a mysql database using python (after some processing on the text). If I use Python 2.4.2, it works without a fuss. However, on Python 2.5, I get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4357: ordinal not in range(128) Before sending the (insert) query to the mysql server, I do the following which I think should've taken care of this problem: sqlStr = sqlStr.replace('\\', '\\\\') (where sqlStr is the query). Any suggestions? Thanks! Gaurav From kyrie at uh.cu Wed Jan 21 12:55:42 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 12:55:42 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xk58p4bhq.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <200901211255.42988.kyrie@uh.cu> On Tuesday 20 January 2009 09:52:01 pm Paul Rubin wrote: > Luis Zarrabeitia writes: > > > Whaat? Assuming a program is perfect unless a failure is proven > > > is not at all a sane approach to getting reliable software. It is > > > the person claiming perfection who has to prove the absence of failure. > > > > No, no. I meant that if pylint works as its specification says it would. > > Oh, I see. Well, that would be ok, except Pylint is not specified as > detecting the types of access that Russ is concerned with. It can't, > for example, flag uses of setattr that might affect a particular > class. That would take something a lot fancier. True. And I doubt that the C++ compiler will flag the pointers running wildly pointing to random memory addresses and accessing the data in there. I doubt that pointer will 'respect' the 'private' keyword. I also doubt that the C# or Java _compiler_ will prevent you from using reflection somehow to access that data. But somehow the discussion shifted from an optional requirement (giving you the chance to explicitly use 'from lock import unlock; o = unlock(obj)') to "it can't be done _ever_" (using setattr/getattr is as explicit as your analogous 'unlock' function). Btw, the correctness of a program (on a turing-complete language) cannot be statically proven. Ask Turing about it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From google at mrabarnett.plus.com Wed Jan 21 12:56:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:56:59 +0000 Subject: is this pythonic? In-Reply-To: References: Message-ID: <497761EB.5050507@mrabarnett.plus.com> alex23 wrote: > On Jan 22, 3:27 am, MRAB wrote: >> FYI, you shouldn't modify a list you're iterating over. > > But I'm not. I'm building a new list and binding it to the same name > as the original, which works perfectly fine (unless I'm missing > something): > [snip] I was referring to the code: for index, record in enumerate(l): if record['title'] == 'ti': l.pop(index) where you are enumerating and iterating over 'l', but also modifying 'l' with 'l.pop(index)'. From wuwei23 at gmail.com Wed Jan 21 12:58:57 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:58:57 -0800 (PST) Subject: is this pythonic? References: Message-ID: <709db477-373a-4aba-9c61-a4ee00ea217f@p36g2000prp.googlegroups.com> On Jan 22, 3:34?am, TP wrote: > > ? ? for index, record in enumerate(l): > > ? ? ? ? if record['title'] == 'ti': > > ? ? ? ? ? ? l.pop(index) > > Ok, I will use this solution. But it is less pythonic than list > comprehensions. Are you asking if it's less pythonic, or asserting? Because you'll find a lot of disagreement here: list comprehensions are used for constructing lists, not manipulating them. > Perhaps you mean rather: > > l = [d for d in l if d['title'] != 'ti'] > ? You are correct. I should never post past 3am :) > In fact, in my case, in cannot use this simple solution, because there are > other fields in each dictionary, not only 2. I was not clear in my post. > So my list is rather: > l=[{"title":"to", "color":"blue", "value":2} > {"title":"ti", "color":"red", "value":"coucou"}] I still find this a lot simpler: records = {'to': {'color': 'blue', 'value': '2'}, 'ti': {'color': 'red', 'value': 'coucou'}} > > It's always better to design for what you know you need, not what you > > may possibly need in the future. > > Ok. Do all the programmers agree with this principle? Have you seen the size of some of the threads here? It's hard to get two programmers to agree on variable names... :) But it's a practice that has served me well and it even has a catchy name[1]. Getting what you -need- to work is effort enough, if you don't have a definite use case for a feature then how do you know you've implemented it correctly? Write it when you need it. 1: http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It From aahz at pythoncraft.com Wed Jan 21 13:00:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 10:00:51 -0800 Subject: pep 8 constants References: Message-ID: In article , Brendan Miller wrote: > >PEP 8 doesn't mention anything about using all caps to indicate a constant. > >Is all caps meaning "don't reassign this var" a strong enough >convention to not be considered violating good python style? I see a >lot of people using it, but I also see a lot of people writing >non-pythonic code... so I thought I'd see what the consensus is. I've posted to python-dev requesting clarification; you may want to subscribe to follow the discussion yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From mnations at gmail.com Wed Jan 21 13:01:13 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 10:01:13 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: <86a336c4-66d1-4420-8f0e-d53b8d28085d@o40g2000prn.googlegroups.com> > I think you've probably had issues with circular imports (i.e. mutual > dependencies), unless you can precisely remember what you were doing and > what went wrong. That's possible, but circular imports become more of a hazard if you have to import in several locations. Unify that to one file, and those problems are much easier to avoid. And I don't remember exactly what the problem was, but I think it had to do with calling Tkinter in two different files. Somehow I was getting an error in one of the files and removing Tkinter from importing in one of the files solved it. > I can make up three or four different logical groupings in my > applications... so what is 'logical' could not be the same for everyone, > or from every point of view. That's not the point. The point is that multiple imports can be a limiting factor if the module imports don't happen to align with the model they'd like to use for their file layout. However playing around with the files, I guess it is possible to create a file that just does imports and then reference them all just like you would any other extension of the namespace. I created a file called imports and was able to access the sys module within it by importing all from imports and calling sys. That way at least all you have to do is import the one file each time. From soul.mirror1 at gmail.com Wed Jan 21 13:06:34 2009 From: soul.mirror1 at gmail.com (soul.mirror1 at gmail.com) Date: Wed, 21 Jan 2009 10:06:34 -0800 (PST) Subject: Mathematica 7 compares to other languages References: <13d5dff7-9aac-4385-91ee-d6e58177497f@i24g2000prf.googlegroups.com> <7db0371c-88f8-4984-bb0d-b2078147803e@f40g2000pri.googlegroups.com> <86bf2e29-5f8d-4349-94cf-d1561f0114e6@e1g2000pra.googlegroups.com> <20081204111115.7cee2ecc@usenot.de> Message-ID: <4d86021f-d25c-4b96-b1a2-3a0c162a6154@a26g2000prf.googlegroups.com> On Dec 4 2008, 5:11?am, Andreas Waldenburger wrote: > On Wed, 03 Dec 2008 20:38:44 -0500 Lew wrote: > > > Xah Lee wrote: > > > enough babble ... > > > Good point. ?Plonk. ?Guun dun! > > I vaguely remember you plonking the guy before. Did you unplonk him in > the meantime? Or was that just a figure of speech? > > teasingly yours, > /W Andreas Waldenburger, I hold up a mirror to your soul! A couple of years ago you started posting to the newsgroup comp.lang.java.programmer. Unlike most newbies, instead of lurking for a while and then contributing on-topic posts about Java, you jumped into the nearest available flamewar and immediately got in up to your neck. Then, on November 13, 2007, you stooped to intentionally misquoting one of your opponents. When he wrote http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e90afa4a20?dmode=source you quoted him thusly: http://groups.google.com/group/comp.lang.java.programmer/msg/0386cc91ce75a3c6?dmode=source A few days later, you did it again, misquoting this post http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d413549f499?dmode=source in this one: http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b23537c1b?dmode=source In both cases, you publicly portrayed this poor man as a pervert, even though, whatever his other faults, that is clearly not one of them. Since that date, you have continued to participate on and off in a flamewar with many of the same participants, including the one you so mistreated that November. In fact, it seems that the very SAME flamewar is still in progress, in another newsgroup, fourteen whole months later, and you are still in it up to your neck. Repeatedly you have claimed to be primarily motivated by finding the disrupting of newsgroups to be entertaining. This is tantamount to admitting to being a troll. If you have an excuse for your behavior, please speak now, and give your apology before the witnesses gathered here. If you do not, then know that your soul is forever tainted! From wuwei23 at gmail.com Wed Jan 21 13:12:39 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 10:12:39 -0800 (PST) Subject: is this pythonic? References: Message-ID: <5f4ec57b-4ea5-4243-8262-8064c4034f8d@g39g2000pri.googlegroups.com> On Jan 22, 3:56?am, MRAB wrote: > I was referring to the code: > > ? ? ?for index, record in enumerate(l): > ? ? ? ? ?if record['title'] == 'ti': > ? ? ? ? ? ? ?l.pop(index) > > where you are enumerating and iterating over 'l', but also modifying 'l' > with 'l.pop(index)'. Ack, you're absolutely correct. TP: my mistake, the for loop won't work at all. I'd really recommend using the dictionary-based solution. Apologies all around. From mnations at gmail.com Wed Jan 21 13:13:18 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 10:13:18 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> Message-ID: <2ae39d1c-8d1c-45d1-af3d-92bb57e8464c@b38g2000prf.googlegroups.com> On Jan 21, 11:29?am, alex23 wrote: > Well, you can always stick those imports into a 'common.py' and do > 'from common import *' in each file that uses them. But doing so can > be a pain to maintain and debug for anything more than the most simple > of applications. Being able to see a module's dependencies clearly > listed at the top of the file is exceptionally handy. I x-posted the same thing but am curious why you think it's such a problem to maintain. Having dependencies at the top is handy only because it's usually quicker to get to the top of a file than it is to open up another one. However if you have your common file open in your IDE you can have it open in a split window where it's viewable all the time. As long as you don't go crazy with "import *" in your common file then you shouldn't get into trouble with duplicated namespaces. As I mentioned before it should also cut down on the circular imports. So just preference aside, is there any problems with the actual execution of the code if it's done this way? To me it simply compares to putting an __init__ file in a package, except it applies to only one directory. From gnewsg at gmail.com Wed Jan 21 13:35:51 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 21 Jan 2009 10:35:51 -0800 (PST) Subject: [ANN] Python FTP Server library (pyftpdlib) 0.5.1 released Message-ID: Hi, I'm pleased to announce release 0.5.1 of Python FTP Server library (pyftpdlib). http://code.google.com/p/pyftpdlib === About === Python FTP server library provides an high-level portable interface to easily write asynchronous FTP servers with Python. Based on asyncore framework pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. === Major enhancements === This new version, aside from fixing some bugs, includes the following major enhancements: * A new script implementing FTPS (FTP over SSL/TLS) has been added in the demo directory. * File transfers are now 40% faster thanks to the re-dimensioned application buffer sizes. * ASCII data transfers on Windows are now 200% faster. * Preliminary support for SITE command has been added. * Two new callback methods to handle "file received" and "file sent" events have been added. A complete list of changes including enhancements and bug fixes is available here: http://code.google.com/p/pyftpdlib/wiki/ReleaseNotes05 === More links === * Source tarball: http://pyftpdlib.googlecode.com/files/pyftpdlib-0.5.1.tar.gz * Online docs: http://code.google.com/p/pyftpdlib/wiki/Tutorial * FAQs: http://code.google.com/p/pyftpdlib/wiki/FAQ * RFCs compliance paper: http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance * Issue tracker: http://code.google.com/p/pyftpdlib/issues/list * Mailing list: http://groups.google.com/group/pyftpdlib Thanks, --- Giampaolo Rodola' < g.rodola [at] gmail [dot] com > http://code.google.com/p/pyftpdlib/ From catphive at catphive.net Wed Jan 21 13:47:33 2009 From: catphive at catphive.net (Brendan Miller) Date: Wed, 21 Jan 2009 10:47:33 -0800 Subject: what's the point of rpython? In-Reply-To: References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels wrote: > Brendan Miller wrote: >> >> On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin >> <"http://phr.cx"@nospam.invalid> wrote: >>> >>> .... Of course I'm aware of the LOCK prefix but it slows >>> down the instruction enormously compared with a non-locked instruction. >> >> I'm curious about that. I've been looking around for timing >> information on the lock signal, but am having some trouble finding >> them. Intuitively, given that the processor is much faster than the >> bus, and you are just waiting for processor to complete an addition or >> comparison before put the new memory value on the bus, it seems like >> there should be very little additional bus contention vs a normal add >> instruction. > > The opcode cannot simply talk to its cache, it must either go directly > to off-chip memory or communicate to other processors that it (and it > alone) owns the increment target. Oh, right. *light bulb goes on* I wasn't thinking about cache at all. From a.bilgin.a at gmail.com Wed Jan 21 13:59:31 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Wed, 21 Jan 2009 20:59:31 +0200 Subject: Trouble writing txt Message-ID: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> Hello, I am trying to write a list of words to into a text file as two colons: word (tab) len(word) such as standart 8 I have no trouble writing the words but I couldn't write integers. I always get strange characters, such as: GUN ????????5COCUK ????????5EV ... ???????4YATSI ?????????? (the integers also seem to be incorrect) I use the following form inside a loop to produce this current = unicode(word)+" "+str(len(word)) ofile.write(current) I know about struct and I tried to used it but somehow I always got a blank character instead of an int. import struct format = "i" data = struct.pack(format, 24) print data Any ideas? I use macosx and eclipse. The code also uses unicode encoding From http Wed Jan 21 14:03:07 2009 From: http (Paul Rubin) Date: 21 Jan 2009 11:03:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > But somehow the discussion shifted from an optional requirement (giving you > the chance to explicitly use 'from lock import unlock; o = unlock(obj)') > to "it can't be done _ever_" (using setattr/getattr is as explicit as your > analogous 'unlock' function). The idea was the lock would be on the class, not on instances of the class. So setattr/getattr would work on instances of unlocked classes but not locked ones. If you wanted an unlocked instance of a locked class, you could do it by making an unlocked subclass. > Btw, the correctness of a program (on a turing-complete language) cannot be > statically proven. Ask Turing about it. That's an irrelevant red herring, even if you're after provability. It just means that there exist some correct programs that cannot be proven correct. What you care about is whether there is a provable program for some particular computing task, which there almost always is. It doesn't matter if there are also some unprovable ones. That is just common sense. When you write a program you presumably write it using some reasoning that lets you convince yourself that the program should always work, and that's an informal proof. (The idea of static verification is to find the small gaps of reasoning that humans make all the time, but once found these gaps are usually easily fixed). I guess one occasionally writes programs that rely on unproven and maybe unprovable mathematical conjectures, but that is pretty rare, especially in traditional programming where you only care about getting correct values out. Even in areas which do rely on unproven conjectures (e.g. in cryptography, we rely on the conjecture that certain functions are difficult to invert), it's usually possible to explicitly state the conjectures that you depend on, and prove that "if this conjecture is true then the program is correct". From pruebauno at latinmail.com Wed Jan 21 14:18:02 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Wed, 21 Jan 2009 11:18:02 -0800 (PST) Subject: is this pythonic? References: Message-ID: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> On Jan 21, 12:34?pm, TP wrote: > alex23 wrote: > > Try not to use 'dict' or the name of any of the other built-in types > > So my list is rather: > l=[{"title":"to", "color":"blue", "value":2} > {"title":"ti", "color":"red", "value":"coucou"}] > > So, I will rather use your solution: > > for index, record in enumerate(l): > ? ? if record['title'] == 'ti': > ? ? ? ? to_add_in_another_list = l.pop(index) > another_list.append(to_add_in_another_list ) > If you have duplicates this will not work. You will have to do something like this instead: >>> o=[] >>> i=0 >>> ln=len(l) >>> while i>> for index, record in enumerate(l): if record['title'] == 'ti': to_add_in_another_list = l.pop(index) break I don't know if these are more pythonic, they should be more efficient for longer lists though. From aktests at gmail.com Wed Jan 21 14:43:27 2009 From: aktests at gmail.com (ak) Date: Wed, 21 Jan 2009 11:43:27 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> On Jan 20, 1:14?am, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote: > > Hi everyone, > > > I have a problem with urllib2 on this particular url, hosted on an > > Oracle HTTP Server > > >http://www.orange.sk/eshop/sk/portal/catalog.html? > > type=post&subtype=phone&null > > > > > which gets 302 redirected to > >https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a > > cookie through the Set-Cookie header field in the 302 reply. This works > > fin with firefox. > > > However, with urllib2 and the following code snippet, it doesn't work > > Looking at the BadStatusLine exception raised, the server response line > is empty. Looking at the source for httpllib suggests to me that the > server closed the connection early. Perhaps it doesn't like connections > from urllib2? > > I ran a test pretending to be IE using this code: > > cookiejar = cookielib.LWPCookieJar() > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?'\ > ? ? 'type=post&subtype=phone&null' > agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; " \ > ? ? "NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" > headers = {'User-Agent': agent} > req = urllib2.Request(url, data=None, headers=headers) > try: > ? ? s=opener.open(req) > except httplib.BadStatusLine, e: > ? ? print e, e.line > else: > ? ? print "Success" > > but it failed. So the problem is not as simple as changing the user-agent > string. > > Other than that, I'm stumped. > > -- > Steven Thanks a lot for confirming this. I also tried with different headers, including putting *exactly* the same headers as firefox (including Connection:keep-alive by modifying httplib), it still doesn't work. The only possible explanation for me is that python's httplib doesn't handle SSL/TLS 'properly' (not necessarly in the sense of the TLS spec, but in the sense that every other browser can connect properly to this website and httplib can't) If anyone knows an Oracle HTTPS server to confirm this on another server, it would be nice... From lkcl at lkcl.net Wed Jan 21 14:50:28 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 21 Jan 2009 19:50:28 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 Message-ID: this is a progress report on compiling python using entirely free software tools, no proprietary compilers or operating systems involved, yet still linking and successfully running with msvcr80 assemblies. manifests and rc files, which are compiled to internal resources, have been added. various sections which are uniquely identifed by _MSC_VER >= 1400 etc have had to be enabled with corresponding MSVCRT_VERSION >= 0x0800 - in particular, signal handling (PyOS_getsig()). currently, under wine with msvcr80, there looks like there is a bug with a common theme related to threads, but here's a short list: test_array.py is blocking, test_bz2.py is hanging and test_cmd_line.py causes a segfault; test_ctypes is _still_ a bundle of fun. for those people who use native win32 platforms who are compiling up this code, you should have better luck. significantly, the wine developers have been absolutely fantastic, and have fixed several bugs in wine, sometimes within hours, that were found as a result of running the extremely comprehensive python regression tests. the python regression tests are a credit to the collaborative incremental improvement process of free software development. i look forward to seeing the same incremental improvement applied to the development of python, evidence of which would be clearly seen by the acceptance of one of the following patches, one of which is dated 2003: http://bugs.python.org/issue3754 http://bugs.python.org/issue841454 http://bugs.python.org/issue3871 http://bugs.python.org/issue4954 http://bugs.python.org/issue5010 for those people wishing to track and contribute to the development of python for win32 using entirely free software tools, either under wine or native windows, there is a git repository, here, slightly illogically named pythonwine because that's where i started from (cross-compiling python under wine, so i could get at the wine registry from python). obviously, since then, things have... moved on :) http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine l. From google at mrabarnett.plus.com Wed Jan 21 14:57:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 19:57:21 +0000 Subject: what's the point of rpython? In-Reply-To: References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <49777E21.6080603@mrabarnett.plus.com> Brendan Miller wrote: > On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels > wrote: >> Brendan Miller wrote: >>> On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin >>> <"http://phr.cx"@nospam.invalid> wrote: >>>> .... Of course I'm aware of the LOCK prefix but it slows >>>> down the instruction enormously compared with a non-locked instruction. >>> I'm curious about that. I've been looking around for timing >>> information on the lock signal, but am having some trouble finding >>> them. Intuitively, given that the processor is much faster than the >>> bus, and you are just waiting for processor to complete an addition or >>> comparison before put the new memory value on the bus, it seems like >>> there should be very little additional bus contention vs a normal add >>> instruction. >> The opcode cannot simply talk to its cache, it must either go directly >> to off-chip memory or communicate to other processors that it (and it >> alone) owns the increment target. > > Oh, right. *light bulb goes on* I wasn't thinking about cache at all. > I'm not sure whether multicore processors share a cache or, if not, have some other on-chip mechanism. Multiprocessor machines, however, are a different matter... From lkcl at lkcl.net Wed Jan 21 15:08:05 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 21 Jan 2009 20:08:05 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: > http://bugs.python.org/issue5010 correction: that's http://bugs.python.org/issue5026 apologies for the mix-up. also,for the msvcrt80 build, it is _essential_ that you use a patched version of mingw32-runtime, see: https://sourceforge.net/tracker/index.php?func=detail&aid=2134161&group_id=2435&atid=352435 libmsvcr80.a mistakenly thinks that _fstat exists (it doesn't - only _fstat32 does, and many more). it's quite straightforward to rebuild - just remember to run ./configure --prefix=/mingw and if you want to revert just reinstall mingw runtime .exe l. From shahmed at sfwmd.gov Wed Jan 21 15:13:26 2009 From: shahmed at sfwmd.gov (Ahmed, Shakir) Date: Wed, 21 Jan 2009 15:13:26 -0500 Subject: date format In-Reply-To: <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> Message-ID: I am grabbing few fields from a table and one of the columns is in date format. The output which I am getting is "Wed Feb 09 00:00:00 2005" but the data in that column is "02/09/2005" and I need the same format output to insert those recodes into another table. print my_service_DATE Wed Feb 09 00:00:00 2005 Any help is highly appreciated. sk From kyrie at uh.cu Wed Jan 21 15:23:55 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 15:23:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x1vuwv5w4.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Message-ID: <200901211523.55524.kyrie@uh.cu> On Wednesday 21 January 2009 02:03:07 pm Paul Rubin wrote: > Luis Zarrabeitia writes: > > But somehow the discussion shifted from an optional requirement (giving > > you the chance to explicitly use 'from lock import unlock; o = > > unlock(obj)') to "it can't be done _ever_" (using setattr/getattr is as > > explicit as your analogous 'unlock' function). > > The idea was the lock would be on the class, not on instances of the > class. ?So setattr/getattr would work on instances of unlocked classes > but not locked ones. ?If you wanted an unlocked instance of a locked > class, you could do it by making an unlocked subclass. Well, then, go change pylint to do that. But don't try to force it on _me_: If I want to access an attribute for an object on my program (from wherever it came from), I don't want _you_ or anyone else saying "no, its private". Even better. Realize that you are trying to use a tool made for debugging, documenting, and catching some obvious errors (private/public) for "security". Go fix Bastion, that would be your best bet. It was yanked out of python because it was insecure, but if someone were to fix it, I'm sure the changes would be welcomed. And then, it would be my choice whether to let you lock your instances in _my_ program, and it would be yours to lock all of mine in yours (and way more). Btw, when I was programming in .Net (long time ago), I found a little library that I wanted to use. The catch: it wasn't opensource, it had a gratis version, and a full, payed version... The difference? The full one had some attributes public that were private on the free one. Well, I didn't wanted code on my app from someone who didn't know the meaning of the 'private' keyword anyway. You (well, Russ more than you) almost seem to be trying something like that. > > Btw, the correctness of a program (on a turing-complete language) cannot > > be statically proven. Ask Turing about it. > > That's an irrelevant red herring, True, my bad. But I don't think it is _fully_ irrelevant. See, a thread that begun with saying that a piece of code was hard to read has evolved to changing the language so we could have tools to statically proving "certain things" with the code. And each time a "suggestion" appears (from people that, at least at the time of suggesting it, were genuinely interested on helping) that doesn't fulfill your [plural, including russ] goal of having static typing and data hiding in the official python, you shoot it down because some other "it cannot be proven statically" reason. Sure, it is always a very well defined "certain" thing and not correctness in general, but that "certain" thing changes as soon as a suggestion is made to amend it. I'm obviously growing tired of that pattern. Have pylint check if someone uses getattr in your code, at all. If pylint doesn't do it, just grep for it and don't run that code. Simple. Btw, this may put and end to this discussion: import gc gc.get_objects() No amount of metaclasses, pylints, decorator, etc, will stop someone from using that to get access to _all_ objects of the program. If you need to keep a secret, don't put it on the same memory space that the untrusted code in python (actually, don't do it on any language). If you need static proofs, use a less dynamic subset of python, and use or develop tools to check if you tried to get out, ever (because if you get out once, you will not be able to track the results). Or, don't use python. (and certainly don't use C++, for that matter, even if C++ has a 'private' keyword). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From python.list at tim.thechases.com Wed Jan 21 15:42:28 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 21 Jan 2009 14:42:28 -0600 Subject: date format In-Reply-To: References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> Message-ID: <497788B4.6020109@tim.thechases.com> Ahmed, Shakir wrote: > I am grabbing few fields from a table and one of the columns is in date > format. The output which I am getting is "Wed Feb 09 00:00:00 2005" but > the data in that column is "02/09/2005" and I need the same format > output to insert those recodes into another table. > > print my_service_DATE > Wed Feb 09 00:00:00 2005 if you are getting actual date/datetime objects, just use the strftime() method to format as you so desire. If you're getting back a *string*, then you should use time.strptime() to parse the string into a time-object, and then use the constituent parts to reformat as you see fit. -tkc From Scott.Daniels at Acm.Org Wed Jan 21 15:43:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 12:43:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > "Russ P." writes: > >> Actually, in addition to the enforcement of "private," you also need >> the enforcement of "protected." > > Oh, heavens. If you want C++ or any of its progeny, you know where to > find them. Besides, those languages have a horrific design mistake > because they conflate the class system (which manages the units of > behaviour) with the module system (which deals with the units of > implementation).... Nowhere in this discussion is a point that I find telling: Python's policy of accessibility to the full data structure allows simple implementation of debugging software, rather than the black arcana that is the normal fare of trying to weld debuggers into the compilers. --Scott David Daniels Scott.Daniels at Acm.Org From benjamin.kaplan at case.edu Wed Jan 21 15:48:37 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 21 Jan 2009 15:48:37 -0500 Subject: Trouble writing txt In-Reply-To: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> References: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> Message-ID: On Wed, Jan 21, 2009 at 1:59 PM, bilgin arslan wrote: > Hello, > I am trying to write a list of words to into a text file as two > colons: word (tab) len(word) > such as > > standart 8 > > I have no trouble writing the words but I couldn't write integers. I > always get strange characters, such as: > > GUN > ????????5COCUK > ????????5EV > ... > ???????4YATSI > ?????????? Looks like an encoding problem to me. > > (the integers also seem to be incorrect) > I use the following form inside a loop to produce this > current = unicode(word)+" "+str(len(word)) > ofile.write(current) > > > I know about struct and I tried to used it but somehow I always got a > blank character instead of an int. > > import struct > format = "i" > data = struct.pack(format, 24) > print data Struct encodes the data as a string. 24 encoded as a byte string is represented as 18 00 00 00 (these are hex). All of these values are unprintable, so you get a blank instead. You're original idea should work once you get the encoding problem fixed. > > > Any ideas? > I use macosx and eclipse. The code also uses unicode encoding Unicode is NOT an encoding. It is a standard. You're probably thinking of the UTF-8 encoding, one of the 5 different "unicode" encodings. This page does a great job of explaining what Unicode actually is. http://www.joelonsoftware.com/articles/Unicode.html Try using ofile.write(current.encode("UTF-8")) and see if that helps. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jan 21 15:50:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 12:50:43 -0800 Subject: English-like Python In-Reply-To: References: Message-ID: Benjamin J. Racine wrote: > I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. > > f "abc" 123 > --> > f( "abc", 123 ) > > It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. Surely this would require that f( "abc", 123 ) --> f(("abc", 123)) Or would you require that tuple-formation is "special"? --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Wed Jan 21 15:55:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 12:55:15 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Message-ID: <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> On Jan 22, 4:49?am, Gaurav Veda wrote: > Hi, > > I am trying to put some webpages into a mysql database using python > (after some processing on the text). If I use Python 2.4.2, it works > without a fuss. However, on Python 2.5, I get the following error: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4357: ordinal not in range(128) > > Before sending the (insert) query to the mysql server, I do the > following which I think should've taken care of this problem: > ?sqlStr = sqlStr.replace('\\', '\\\\') > > (where sqlStr is the query). > > Any suggestions? The 0xc2 strongly suggests that you are feeding the beast data encoded in UTF-8 while giving it no reason to believe that it is in fact not encoded in ASCII. Curiously the first errant byte is a long way (4KB) into your data. Consider doing print repr(data) to see what you've actually got there. I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- different versions of mysql, perhaps? Show at the very least the full traceback that you get. Try to write a short script that demonstrates the problem with 2.5 and no problem with 2.4, so that (a) it is apparent what you are doing (b) the problem can be reproduced if necessary by someone with access to mysql. You might like to explain why you think that doubling backslashes in your SQL is a good idea, and amplify "some processing on the text". HTH, John From jstroud at mbi.ucla.edu Wed Jan 21 16:08:48 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 21 Jan 2009 13:08:48 -0800 Subject: Start Python at client side from web app In-Reply-To: <6toehtFbrb81U1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms windows client). > But some action needs to be done on the client since you can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. You need to write an IE plugin for this, otherwise you can't get out of the browser sandbox to execute anything on the client side. In fact, if you just make your IE "application" a plugin, you can take advantage of updating facilities that IE should have for plugins. If IE doesn't have updating facilities, then just write a firefox plugin, which does have these facilities. From jeff at jmcneil.net Wed Jan 21 16:13:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 21 Jan 2009 13:13:19 -0800 (PST) Subject: Trouble writing txt References: Message-ID: On Jan 21, 1:59 pm, bilgin arslan wrote: > Hello, > I am trying to write a list of words to into a text file as two > colons: word (tab) len(word) > such as > > standart 8 > > I have no trouble writing the words but I couldn't write integers. I > always get strange characters, such as: > > GUN > ????????5COCUK > ????????5EV > ... > ???????4YATSI > ????????? > > (the integers also seem to be incorrect) > I use the following form inside a loop to produce this > current = unicode(word)+" "+str(len(word)) > ofile.write(current) > > I know about struct and I tried to used it but somehow I always got a > blank character instead of an int. > > import struct > format = "i" > data = struct.pack(format, 24) > print data > > Any ideas? > I use macosx and eclipse. The code also uses unicode encoding I don't have a Mac in front of me, but I'll take a stab at it. You shouldn't need to bother with the struct module if you're simply trying to print out an integer's string value. What are you using to open 'ofile?' Can you post all of the relevant code? From Russ.Paielli at gmail.com Wed Jan 21 16:16:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 21 Jan 2009 13:16:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: On Jan 21, 9:34?am, Luis Zarrabeitia wrote: > But you keep failing to explay why do you need it to be _part of the standard_ > library (or whatever). Technically, it doesn't need to be. But if someone proposes using particular language for a major safety-critical project, the critical features realistically need to be part of the standard language or at the very least in the standard library. The requirements are different for government-regulated code than they are for non-critical commercial code, as well they should be. Imagine trying to explain to the FAA that you are going to use a language that is inappropriate by itself for a safety-critical system but will be appropriate with the addition of third-party software. That just won't fly. Then again, the FAA might not approve Python for flight-critical or safety-critical code even if it gets enforced data hiding, so perhaps the point is moot. > If you need it in your project, _use_ it. If you don't, then don't use it. If > _you_ need that thing you call security, just use it already and quit > complaining that we don't use it. Is there a policy in your project that you > can't use any external? I don't recall complaining that anyone doesn't use something. In fact, in the unlikely event that enforced data hiding is ever added to Python, nobody would be forced to use it (except perhaps by your boss or your customer, but that's another matter). From Scott.Daniels at Acm.Org Wed Jan 21 16:23:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 13:23:54 -0800 Subject: is this pythonic? In-Reply-To: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> Message-ID: <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> pruebauno at latinmail.com wrote: > ... If you have duplicates this will not work. You will have to do > something like this instead: > >>>> o=[] >>>> i=0 >>>> ln=len(l) >>>> while i if l[i]['title']=='ti': > o.append(l.pop(i)) > ln-=1 > else: > i+=1 Or the following: indices = [i for i,d in enumerate(l) if d['title']=='ti'] for i in reversed(indices): # so del doesn't affect later positions del l[i] --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Wed Jan 21 16:32:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 13:32:30 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: <91aba300-59d6-462e-a566-21825f8d7d03@p23g2000prp.googlegroups.com> On Jan 22, 2:17?am, a... at pythoncraft.com (Aahz) wrote: > In article <313a27f9-c655-4fc4-a8e3-568a4283b... at f40g2000pri.googlegroups.com>, > > ag73 ? wrote: > > > ? ? ? ? ? ? ? ? ? ?form = urllib.parse.parse_qs(qs, keep_blank_values=1) > > >However, the last line of code that calls parse_qs causes the > >following exception to be thrown: > > > > >Type str doesn't support the buffer API > > One of the key features of Python 3.0 is the fact that it now > distinguishes between bytes and strings. ?Unfortunately, there are a lot > of ambiguous areas where the correct handling is not clear; for example, > nobody has yet agreed whether URLs are strings or bytes. ?As you > discovered, forced conversion to string seems to work here and I suggest > you make that your workaround. ? However I'm surprised on further reflection that that workaround works; it must be only accidental. """if I pass in "str(qs)" instead of "qs" then the call works.""" BUT str(bytes_instance) with no other args passed *doesn't* just do a decoding: """When only object is given, this returns its nicely printable representation.""" The nicely printable representation for bytes objects includes: * wrapping it in b'' * showing non-ASCII characters as \xdd 3.0: >>> len(str(b'abc')) 6 >>> len(str(b'abc', encoding='ascii')) 3 >>> len(str(b'\xff')) 7 >>> len(str(b'\xff', encoding='ascii')) Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't d From rt8396 at gmail.com Wed Jan 21 16:35:45 2009 From: rt8396 at gmail.com (r) Date: Wed, 21 Jan 2009 13:35:45 -0800 (PST) Subject: Cannot contact Python webmaster! Message-ID: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> Does anybody know how to get in touch with the www.python.org website maintainers? i sent mail to webmaster at python.org but it just bounces back. Is anybody even there? :) From rridge at csclub.uwaterloo.ca Wed Jan 21 16:43:43 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 21 Jan 2009 16:43:43 -0500 Subject: what's the point of rpython? References: <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: >The opcode cannot simply talk to its cache, it must either go directly >to off-chip memory or communicate to other processors that it (and it >alone) owns the increment target. In fact all it does simply talk to its cache. From the "Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3A: System Programming Guide, Part 1": For the P6 and more recent processor families, if the area of memory being locked during a LOCK operation is cached in the processor that is performing the LOCK operation as write-back memory and is completely contained in a cache line, the processor may not assert the LOCK# signal on the bus. Instead, it will modify the memory location internally and allow it's cache coherency mechanism to insure that the operation is carried out atomically. This operation is called "cache locking." The cache coherency mechanism automatically prevents two or more processors that have cached the same area of memory from simultaneously modifying data in that area. The same cache coherency mechanism that prevents ordinary "unlocked" instructions from simulanteously modifying the same cache line on two different processors also provides the guarantee with "locked" instructions. There's no additional hardware locks involved, and no additional communication required. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From tjreedy at udel.edu Wed Jan 21 16:48:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 16:48:16 -0500 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: Luke Kenneth Casson Leighton wrote: > i look forward to seeing the same incremental improvement applied to > the development of python, evidence of which would be clearly seen by > the acceptance of one of the following patches, one of which is dated > 2003: > http://bugs.python.org/issue841454 Against 2.3, rejected due to dependence on SCons. Also appears to have been incomplete, needing more work. > http://bugs.python.org/issue3754 Open by Roumen Petrov, no review, see below. > http://bugs.python.org/issue3871 Open, from same submitter, only (minor) review by you. Does this supercede 3754? > http://bugs.python.org/issue4954 Yours, Martin reviewed and closed. FWIW, the comment about not adding 'minority' platform specific stuff to the core (as opposed to 'neutral' changes that make them easier) was also applied, a week or two ago, to the BEOS successor. I added 5026 as superceder. > http://bugs.python.org/issue5026 # number corrected Successor to 4954 > for those people wishing to track and contribute to the development of > python for win32 using entirely free software tools, either under wine > or native windows, there is a git repository, here, slightly > illogically named pythonwine because that's where i started from > (cross-compiling python under wine, so i could get at the wine > registry from python). obviously, since then, things have... moved on > :) > > http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine Are there 'neutral' changes to the core you would like that would make maintaining this and other platform-specific patch sets easier? Terry Jan Reedy From ig2ar-saf1 at yahoo.co.uk Wed Jan 21 16:53:15 2009 From: ig2ar-saf1 at yahoo.co.uk (culpritNr1) Date: Wed, 21 Jan 2009 13:53:15 -0800 (PST) Subject: list subsetting Message-ID: <21593123.post@talk.nabble.com> Hello All, Say I have a list like this: a = [0 , 1, 3.14, 20, 8, 8, 3.14] Is there a simple python way to count the number of 3.14's in the list in one statement? In R I do like this a = c(0 , 1, 3.14, 20, 8, 8, 3.14) length( a[ a[]==3.14 ] ) How do I do that in standard python? (Note that this is just an example, I do not mean to use == in floating point operations.) Thank you culpritNr1 -- View this message in context: http://www.nabble.com/list-subsetting-tp21593123p21593123.html Sent from the Python - python-list mailing list archive at Nabble.com. From castironpi at gmail.com Wed Jan 21 17:04:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 14:04:46 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> Message-ID: On Jan 21, 9:24?am, Joe Strout wrote: > Aaron Brady wrote: > > Where functions are first-class objects, a bare function object isn't > > distinguishable either from its call. > > That depends not on whether functions are first-class objects, but on > the *syntax* of function invocation vs. function reference. Good point. snip. I'm not sure what the NL equivalents of function invocation vs. function reference are, but somehow I don't think there would be a lot of confusion (not that there couldn't be). Here is a bad example. Think about computing that answer. Compute the answer, and think about the result. --> thinkabout( func ) thinkabout( func() ) Oddly enough, the NL equivalents aren't even close to resembling each other. From fogleman at gmail.com Wed Jan 21 17:08:10 2009 From: fogleman at gmail.com (FogleBird) Date: Wed, 21 Jan 2009 14:08:10 -0800 (PST) Subject: list subsetting References: Message-ID: On Jan 21, 4:53?pm, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. a.count(3.14) From jeff at jmcneil.net Wed Jan 21 17:09:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 21 Jan 2009 14:09:19 -0800 (PST) Subject: list subsetting References: Message-ID: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> On Jan 21, 4:53 pm, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. Just the number of occurrences? Count method? Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [1,2,3,3.14,3.14,5,66].count(3.14) 2 >>> Jeff From kyrie at uh.cu Wed Jan 21 17:10:18 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 17:10:18 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901211710.18743.kyrie@uh.cu> On Wednesday 21 January 2009 04:16:38 pm Russ P. wrote: > On Jan 21, 9:34?am, Luis Zarrabeitia wrote: > > But you keep failing to explay why do you need it to be _part of the > > standard_ library (or whatever). > > Technically, it doesn't need to be. But if someone proposes using > particular language for a major safety-critical project, the critical > features realistically need to be part of the standard language or at > the very least in the standard library. I assume, then, that no safety-critical project uses any external tool for checking anything important. > The requirements are different for government-regulated code than they > are for non-critical commercial code, as well they should be. Imagine > trying to explain to the FAA that you are going to use a language that > is inappropriate by itself for a safety-critical system but will be > appropriate with the addition of third-party software. That just won't > fly. Then it wont fly, period. If you start explaining that the language is inappropriate, then you've already made the case. I would argue that the language _is_ appropriate _because_ all your concerns can be solved. (assuming, of course, that the theoretically-solvable concerns are can actually be solved). But as you haven't stated yet any specific concern other than silly locked-doors analogy and "you are crazy if you think that a nuclear blahblah don't use private variables", this is kind of pointless. > Then again, the FAA might not approve Python for flight-critical or > safety-critical code even if it gets enforced data hiding, so perhaps > the point is moot. Most likely. For what you've said, if the use of an external tool would make it inappropriate, I highly doubt that they'll like an informally-developed community-driven open source language who's developers and a good portion of its community consider silly the idea of using enforced data-hiding for anything other than debugging. > > If you need it in your project, _use_ it. If you don't, then don't use > > it. If _you_ need that thing you call security, just use it already and > > quit complaining that we don't use it. Is there a policy in your project > > that you can't use any external? > > I don't recall complaining that anyone doesn't use something. Well, you want it on the python compiler I use. That seems awfully close. Funny thing... if pylint became part of the standard library, I may welcome the change. I certainly wouldn't be complaining about it unless it was enabled-by-default-and-can't-disable-it. > In fact, > in the unlikely event that enforced data hiding is ever added to > Python, nobody would be forced to use it (except perhaps by your > boss or your customer, but that's another matter). No one is now. And no one is forced to not use it either (except perhaps by your boss or your customer, but that's another matter). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bearophileHUGS at lycos.com Wed Jan 21 17:12:20 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 21 Jan 2009 14:12:20 -0800 (PST) Subject: list subsetting References: Message-ID: <8b9809ee-13cc-44a9-b312-2f313932dd38@q30g2000prq.googlegroups.com> FogleBird: > a.count(3.14) If the values to count are approximated FP values, then you may need something more complex, like: leniter(ifilter(somefunction, a)) Where somefunction uses an approximated comparison, and leniter is just a function that counts the items of a generic iterator. Bye, bearophile From tjreedy at udel.edu Wed Jan 21 17:14:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 17:14:18 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) Constructing this list is the appropriate place for a comprehension. Newlist = [Foo() for _ in range(10)] > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 Use MRAB's replacement for this. > but can I do this using list comprehension? Don't, for reasons given by others. tjr From rtw at freenet.co.uk Wed Jan 21 17:16:41 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 16:16:41 -0600 Subject: list subsetting References: Message-ID: culpritNr1 wrote in news:mailman.7713.1232574803.3487.python-list at python.org in comp.lang.python: > > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list > in one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? count = a.count( 3.14 ) > > (Note that this is just an example, I do not mean to use == in > floating point operations.) In this case something like this: a = [0 , 1, 3.14, 20, 8, 8, 3.14] count = sum( 1 for x in a if 3.13 < x and x < 3.15 ) http://docs.python.org/library/functions.html#sum http://docs.python.org/reference/expressions.html#generator-expressions Rob. -- http://www.victim-prime.dsl.pipex.com/ From castironpi at gmail.com Wed Jan 21 17:19:41 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 14:19:41 -0800 (PST) Subject: English-like Python References: Message-ID: <4276026d-7ce9-41d9-8ad4-1fb0adbdb29f@z6g2000pre.googlegroups.com> On Jan 21, 2:50?pm, Scott David Daniels wrote: > Benjamin J. Racine wrote: > > I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. > > > f "abc" 123 > > --> > > f( "abc", 123 ) > > > It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. ?Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. > > Surely this would require that > ? ?f( "abc", 123 ) > ? ?--> > ? ?f(("abc", 123)) > Or would you require that tuple-formation is "special"? Natural language does have tuples, and there is some ambiguity some of the time. Go to the store and get bread. --> goto( store ); get( bread ) or: get( store, bread ) --> ( Go to the store ), ( Get bread ) or: ( Go to ( the store, get bread ) ) Now for the good examples. ;) From http Wed Jan 21 17:19:54 2009 From: http (Paul Rubin) Date: 21 Jan 2009 14:19:54 -0800 Subject: list subsetting References: Message-ID: <7x63k8s3n9.fsf@ruckus.brouhaha.com> culpritNr1 writes: > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? n = sum(1 for x in a if x == 3.14) From jervisau at gmail.com Wed Jan 21 17:20:23 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Thu, 22 Jan 2009 09:20:23 +1100 Subject: list subsetting In-Reply-To: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> References: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <8e63a5ce0901211420h6c071f83nefb23cab7b41285b@mail.gmail.com> On Thu, Jan 22, 2009 at 9:09 AM, Jeff McNeil wrote: > On Jan 21, 4:53 pm, culpritNr1 wrote: > > Hello All, > > > > Say I have a list like this: > > > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > > > Is there a simple python way to count the number of 3.14's in the list in > > one statement? > > > > In R I do like this > > > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > > > length( a[ a[]==3.14 ] ) > > > > How do I do that in standard python? > > > > (Note that this is just an example, I do not mean to use == in floating > > point operations.) > > > > Thank you > > > > culpritNr1 > > > > -- > > View this message in context: > http://www.nabble.com/list-subsetting-tp21593123p21593123.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > Just the number of occurrences? Count method? > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> [1,2,3,3.14,3.14,5,66].count(3.14) > 2 > >>> > > Jeff > -- > http://mail.python.org/mailman/listinfo/python-list > a = [3.14, 4, 3.15, 3.14 + 1E-12] len([None for elem in a if abs(elem - 3.14) < 1E-9]) Just replace 1E-9 with the level of accuracy that you would like. This creates a list of Nones, one None for each 3.14 in the original list, then counts the length of the list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ig2ar-saf1 at yahoo.co.uk Wed Jan 21 17:22:45 2009 From: ig2ar-saf1 at yahoo.co.uk (culpritNr1) Date: Wed, 21 Jan 2009 14:22:45 -0800 (PST) Subject: list subsetting In-Reply-To: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <21593607.post@talk.nabble.com> Thank you Fogelbird and Jeff. I actually tried to find out if such function existed. I did >>> help("count") no Python documentation found for 'count' Anyway. More than counting, I am interested in list subsetting in a simple way. Forget about counting. Say I have a list of lists and I want to pull only the rows where the second "column" equals 3.14. It is a very simple concept. I wonder if python can keep it simple despite being a general purpose programming language, not a numerical programming language. Thanks, culpritNr1 Jeff McNeil-2 wrote: > > On Jan 21, 4:53 pm, culpritNr1 wrote: >> Hello All, >> >> Say I have a list like this: >> >> a = [0 , 1, 3.14, 20, 8, 8, 3.14] >> >> Is there a simple python way to count the number of 3.14's in the list in >> one statement? >> >> In R I do like this >> >> a = c(0 , 1, 3.14, 20, 8, 8, 3.14) >> >> length( a[ a[]==3.14 ] ) >> >> How do I do that in standard python? >> >> (Note that this is just an example, I do not mean to use == in floating >> point operations.) >> >> Thank you >> >> culpritNr1 >> >> -- >> View this message in >> context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > Just the number of occurrences? Count method? > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> [1,2,3,3.14,3.14,5,66].count(3.14) > 2 >>>> > > Jeff > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/list-subsetting-tp21593123p21593607.html Sent from the Python - python-list mailing list archive at Nabble.com. From rhamph at gmail.com Wed Jan 21 17:25:13 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Wed, 21 Jan 2009 14:25:13 -0800 (PST) Subject: what's the point of rpython? References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Jan 21, 12:57?pm, MRAB wrote: > I'm not sure whether multicore processors share a cache or, if not, have > some other on-chip mechanism. Multiprocessor machines, however, are a > different matter... They share some, but also have some exclusive. How much of which depends entirely on which CPU you have. From tdelaney at avaya.com Wed Jan 21 17:42:06 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 22 Jan 2009 06:42:06 +0800 Subject: spam on the list - how are things now? In-Reply-To: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: skip at pobox.com wrote: > We've been running SpamBayes on the news-to-mail gateway on > mail.python.org for a couple weeks now. To me it seems like the > level of spam leaking onto the list has dropped way down but I'd like > some feedback from people who read the python-list at python.org mailing > list on the topic. Sorry Skip - looks like it's not working. The Xah Lee spam is still getting through ;) Tim Delaney From http Wed Jan 21 17:44:28 2009 From: http (Paul Rubin) Date: 21 Jan 2009 14:44:28 -0800 Subject: list subsetting References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <7x7i4onusz.fsf@ruckus.brouhaha.com> culpritNr1 writes: > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. list_of_lists = [[1.414,2.718,3.14],[4.00,3.14,1.618],[72,29,39]] those_rows = [xs for xs in list_of_lists if xs[1] == 3.14] From fogleman at gmail.com Wed Jan 21 17:46:37 2009 From: fogleman at gmail.com (FogleBird) Date: Wed, 21 Jan 2009 14:46:37 -0800 (PST) Subject: list subsetting References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: On Jan 21, 5:22?pm, culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > > >>> help("count") > > no Python documentation found for 'count' > > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. > > It is a very simple concept. I wonder if python can keep it simple despite > being a general purpose programming language, not a numerical programming > language. > > Thanks, > > culpritNr1 > > > > Jeff McNeil-2 wrote: > > > On Jan 21, 4:53 pm, culpritNr1 wrote: > >> Hello All, > > >> Say I have a list like this: > > >> a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > >> Is there a simple python way to count the number of 3.14's in the list in > >> one statement? > > >> In R I do like this > > >> a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > >> length( a[ a[]==3.14 ] ) > > >> How do I do that in standard python? > > >> (Note that this is just an example, I do not mean to use == in floating > >> point operations.) > > >> Thank you > > >> culpritNr1 > > >> -- > >> View this message in > >> context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > >> Sent from the Python - python-list mailing list archive at Nabble.com. > > > Just the number of occurrences? Count method? > > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> [1,2,3,3.14,3.14,5,66].count(3.14) > > 2 > > > Jeff > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593607.html > Sent from the Python - python-list mailing list archive at Nabble.com. data = [[1,2,3],[4,5,6],[7,8,9]] rows = [row for row in data if row[1] == 5] print rows [[4, 5, 6]] From robert.kern at gmail.com Wed Jan 21 17:47:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 Jan 2009 16:47:56 -0600 Subject: list subsetting In-Reply-To: <21593607.post@talk.nabble.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> <21593607.post@talk.nabble.com> Message-ID: culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > >>>> help("count") > no Python documentation found for 'count' > > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. In [1]: list_o_lists = [[1, 3.14, 3, 4], ...: [2, 3, 4, 5], ...: [3, 3.14, 5, 6]] In [2]: print [L for L in list_o_lists if L[1] == 3.14] [[1, 3.1400000000000001, 3, 4], [3, 3.1400000000000001, 5, 6]] -- 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 vedagaurav at gmail.com Wed Jan 21 17:50:16 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Wed, 21 Jan 2009 14:50:16 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> Message-ID: <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> > The 0xc2 strongly suggests that you are feeding the beast data encoded > in UTF-8 while giving it no reason to believe that it is in fact not > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > into your data. Consider doing > print repr(data) > to see what you've actually got there. >>> sqlStr[4352:4362] ' and 25\xc2\xb0F' All I want to do is to just replace all the non-ascii characters by a space. > I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- > different versions of mysql, perhaps? I am trying to put content into the mysql server running on machine A, from machine B & machine C with different versions of python. So I don't think this is a mysql issue. > Show at the very least the full traceback that you get. Try to write a > short script that demonstrates the problem with 2.5 and no problem > with 2.4, so that (a) it is apparent what you are doing (b) the > problem can be reproduced if necessary by someone with access to > mysql. Traceback (most recent call last): File "", line 1, in File "putDataIntoDB.py", line 164, in cursor.execute(sqlStr) File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py", line 146, in execute query = query.encode(charset) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4359: ordinal not in range(128) > You might like to explain why you think that doubling backslashes in > your SQL is a good idea, and amplify "some processing on the text". I thought this will achieve 2 things. a) It will escape any unicode character (obviously, I was wrong. Got carried away by the display. I thought \xc2 will get escaped to \\xc2, which is completely preposterous). b) It will make sure that the escape sequences in the string (e.g. '\n') are received by mysql as an escape sequence. Thanks for your reply! Gaurav > HTH, > John From bugtrack at roumenpetrov.info Wed Jan 21 17:51:36 2009 From: bugtrack at roumenpetrov.info (Roumen Petrov) Date: Thu, 22 Jan 2009 00:51:36 +0200 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: <4977A6F8.4060904@roumenpetrov.info> Terry Reedy wrote: > Luke Kenneth Casson Leighton wrote: > >> i look forward to seeing the same incremental improvement applied to >> the development of python, evidence of which would be clearly seen by >> the acceptance of one of the following patches, one of which is dated >> 2003: > >> http://bugs.python.org/issue841454 > > Against 2.3, rejected due to dependence on SCons. > Also appears to have been incomplete, needing more work. No it was complete but use SCons. Most of changes changes in code you will see again in 3871. >> http://bugs.python.org/issue3754 > > Open by Roumen Petrov, no review, see below. This is again request and the patch is for trunk. It share common idea with 841454:Cross building python for mingw32:Andreas Ames (yxcv):2003-11-13 14:31 1006238:Cross compile patch:Daniel Goertzen (goertzen):2004-08-09 22:05 1597850:Cross compiling patches for MINGW hanwen:2006-11-16 16:57 >> http://bugs.python.org/issue3871 > > Open, from same submitter, only (minor) review by you. > Does this supercede 3754? No. It share common changes to code with 841454, 1006238, 1412448, 1597850. May be 1597850 and 3871 supercede 1412448. The issue3871 raise questions (and include solution/work around) related to: 2942 - mingw/cygwin do not accept asm file as extension source 2445 - Use The CygwinCCompiler Under Cygwin 1706863 - Failed to build Python 2.5.1 with sqlite3 Also issues related to LDFLAGS: 4010 - configure options don't trickle down to distutils 1628484 - Python 2.5 64 bit compile fails on Solaris 10/gcc 4.1.1 [SNIP] From rtw at freenet.co.uk Wed Jan 21 17:59:18 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 16:59:18 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote in news:6toehtFbrb81U1 at mid.individual.net in comp.lang.python: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms > windows client). But some action needs to be done on the client since > you can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. > > Thomas > > Server runs Linux with Django and Postgres. > > Thomas Guettler schrieb: >> Hi, >> >> I want to start Python at the client side from a web application. The >> app is an intranet application, and all client PCs are under our >> control (we can install software on them). >> >> But I don't want to update the installation too often. Here is my >> idea: >> >> We create a custom mime-type and register it on the client PC. The >> web application can send signed python code to the client PC. If the >> signature is correct, the code will be executed at the client. The >> signature prevents others from executing code. >> >> Has someone seen or done something like this before? Two options come to mind: 1) use a HTA as you client app, http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx The main drawback is it isn't a full browser so you loose things like back buttons, though some shortcuts F5 (refresh/reload) do work. 2) create a localhost web server, for the client side manipulation. Then have your remote webserver render a form that posts via javavscript to the localhost webserver. The localhost server would post back in the same way. Rob. -- http://www.victim-prime.dsl.pipex.com/ From deets at nospam.web.de Wed Jan 21 18:05:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 00:05:10 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6tpo16FbacfjU1@mid.uni-berlin.de> > 2) create a localhost web server, for the client side manipulation. > Then have your remote webserver render a form that posts via javavscript > to the localhost webserver. The localhost server would post back in > the same way. AFAIK the JS security model prevents that. Diez From deets at nospam.web.de Wed Jan 21 18:15:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 00:15:17 +0100 Subject: quick beginners List comprehension question In-Reply-To: References: <6touv8Fc32elU1@mid.uni-berlin.de> Message-ID: <6tpok5Fc7mabU1@mid.uni-berlin.de> MRAB schrieb: > Diez B. Roggisch wrote: >> Dr Mephesto wrote: >> >>> Hi, >>> Im new to python, and OOP, and am trying to get a handle on list >>> comprehension. >>> >>> Say I have a class Foo with a property called bar: >>> >>> class Foo: >>> def __init__(self): >>> self.bar = random.randint(1,100) >>> >>> and then I make a list of these objects: >>> >>> Newlist = [] >>> for x in range(10): >>> Newlist.append(Foo()) >>> >>> Now, suppose I wanted to triple the value of 'bar', I could always do: >>> >>> for x in range(10): >>> Newlist[x].bar = Newlist[x].bar * 3 >>> >>> but can I do this using list comprehension? Thanks in Advance! >> >> No, as such, because list-comprehensions require you to have an >> *expression* >> in front of the iteration: >> >> resultlist = [ for in ] >> >> Now what you of course can do is this: >> >> def multiply(item): >> item.bar = item.bar * 3 >> >> [multiply(i) for i in items] >> >> However, doing this will make python produce a list of None-references - >> which is a waste. It's up to you if you care about that, but generally it >> is frowned upon because of that, and the fact that the conciseness of the >> list-comp here isn't really helping with the readability. >> > If you had: > > def multiply(item): > item.bar = item.bar * 3 > return item > > then: > > [multiply(i) for i in items] > > would return items. Still a bad idea, though, because you're using a > list comprehension for its side-effect. And redundant, which was the reason I ommited it. Diez From rtw at freenet.co.uk Wed Jan 21 18:20:38 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 17:20:38 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in comp.lang.python: > >> 2) create a localhost web server, for the client side manipulation. >> Then have your remote webserver render a form that posts via >> javavscript to the localhost webserver. The localhost server would >> post back in the same way. > > AFAIK the JS security model prevents that. > Are you thinking of frames?, or the way IE 7 complains about runnning javavscript (though it bizzarly calls it an "running an ActiveX control" )?. Anyway it works fine. Rob. -- http://www.victim-prime.dsl.pipex.com/ From mdw at distorted.org.uk Wed Jan 21 18:39:53 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 23:39:53 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87skncfcty.fsf.mdw@metalzone.distorted.org.uk> Scott David Daniels writes: > Nowhere in this discussion is a point that I find telling: Python's > policy of accessibility to the full data structure allows simple > implementation of debugging software, rather than the black arcana > that is the normal fare of trying to weld debuggers into the compilers. That's a very good point, actually. It also means that, even without a formal `debugger', you can easily write diagnostic code which dumps the internal state of some interesting object -- say at the interactive prompt, or in a hacky test program. One might argue that `industrial strength' modules ought to have such diagnostic abilities built in; but they often either don't tell you what you actually wanted to know in your current situation, or tell you way more than was necessary, or both. Either that, or they're just too complicated to use. Thank you for that observation! -- [mdw] From sjmachin at lexicon.net Wed Jan 21 19:08:54 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 16:08:54 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> Message-ID: <61718f7e-327b-4851-95b5-83c0951a00a6@a39g2000prl.googlegroups.com> On Jan 22, 9:50?am, Gaurav Veda wrote: > > The 0xc2 strongly suggests that you are feeding the beast data encoded > > in UTF-8 while giving it no reason to believe that it is in fact not > > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > > into your data. Consider doing > > ? ? print repr(data) > > to see what you've actually got there. > >>> sqlStr[4352:4362] > > ' and 25\xc2\xb0F' That's the UTF-8 version of ' and 25?F' where the character between the 25 and the F is U+00B0 DEGREE SIGN ... interesting stuff to have in an SQL query string. > > All I want to do is to just replace all the non-ascii characters by a > space. I can't imagine why you would want to do that to data, let alone to an SQL query. I can't see any evidence that you actually tried to do that, anyway. To replace non-ASCII characters in a UTF-8-encoded string by spaces: | >>> u8 = ' and 25\xc2\xb0F' | >>> u = u8.decode('utf8') | >>> ''.join([chr(ord(c)) if c <= u'\x7f' else ' ' for c in u]) | ' and 25 F' > > > I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- > > different versions of mysql, perhaps? > > I am trying to put content into the mysql server running on machine A, > from machine B & machine C with different versions of python. So I > don't think this is a mysql issue. Terminology confusion. Consider the possibility of different versions of MySQLdb (the client interface package) on the client machines B and C. Also consider the possibility that you didn't run exactly the same code on B and C. > > Show at the very least the full traceback that you get. Try to write a > > short script that demonstrates the problem with 2.5 and no problem > > with 2.4, so that (a) it is apparent what you are doing (b) the > > problem can be reproduced if necessary by someone with access to > > mysql. How about a very small script which includes the minimum necessary to run these two lines (with appropriate substitutions for column_x and table_y: sql_str = "select column_x from table_y where column_x = '\xc2\xb0'" cursor.execute(sql_str) and run that on B and C > > Traceback (most recent call last): > ? File "", line 1, in > ? File "putDataIntoDB.py", line 164, in > ? ? cursor.execute(sqlStr) > ? File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py", line > 146, in execute > ? ? query = query.encode(charset) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4359: ordinal not in range(128) > > > You might like to explain why you think that doubling backslashes in > > your SQL is a good idea, and amplify "some processing on the text". > > I thought this will achieve 2 things. > a) It will escape any unicode character (obviously, I was wrong. Got > carried away by the display. I thought \xc2 will get escaped to \\xc2, > which is completely preposterous). > b) It will make sure that the escape sequences in the string (e.g. > '\n') are received by mysql as an escape sequence. Run-time programmatic fiddling with an SQL query string is dangerous and tricky at the best of times, worse when you don't inspect the result before you press the launch button. Cheers, John From mdw at distorted.org.uk Wed Jan 21 19:10:02 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 00:10:02 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> Luis Zarrabeitia writes: > Btw, the correctness of a program (on a turing-complete language) > cannot be statically proven. Ask Turing about it. Be careful! Given a putative correctness-checking algorithm, there exist programs for which the algorithm gives the wrong answer. That doesn't necessarily mean that there isn't a useful subset of `all programs' which can be proven correct, or even that this subset doesn't include all `interesting' programs. Even so, actually constructing algorithms which prove interesting things about all interesting programs seems difficult. Some people (let's call them `type A programmers') have decided that they want to be assisted with writing correct programs -- to the extent that they've chosen some correctness properties, and use a tool which reject programs that it can't prove have those properties. Since the tool can't work for all programs, it errs on the side of caution, sometimes rejecting correct programs. (The properties tend to be called `type correctness' and the tool is built into the compiler, but that's not actually very important.) Other people (`type B programmers') don't like having their (apparently? possibly?) correct programs rejected. Instead, they'd rather risk writing incorrect programs (maybe they try to minimize the risk by thinking very hard, or by building thorough test suites) because they find that some of the kinds of programs the tools reject are actually interesting and useful -- or at least fun. I think trying to persuade a type A programmer that he wants to work like a type B programmer, or /vice versa/, is difficult, bordering on futile. Type A stereotypes type B as a bunch of ill-disciplined reckless hackers; type B stereotypes type A as killjoy disciplinarians. Meeting in the middle is difficult. (`We just want to add a little safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) On a personal note, I've written programs in lots (/lots/) of different languages: C, Pascal, Haskell, Standard ML, Python, Perl, Lisp, Scheme, and assembler for various processors. I always found programming in permissive languages more enjoyable. I still love ARM assembler (though I thought the 32-bit address space changes spoilt some of its beauty), but I don't get to write much these days; Common Lisp is now my language of choice, but Python comes very close. I find C too fiddly and annoying nowadays, and its type system does an impressive job of simultaneously being uncomfortably constraining while being too weak to provide a satisfactory feeling of confidence in compensation. Kernighan summed up Pascal perfectly when he said `There is no escape.' Haskell is interesting: it can provide a surprising degree of freedom, but it makes you work /very/ hard wrangling its type system in order to get there; and again, I found I had most fun when I was doing extremely evil unsafePerformIO hacking... So, my personal plea. Writing Python is /fun/. Please let it stay that way. -- [mdw] From google at mrabarnett.plus.com Wed Jan 21 19:18:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jan 2009 00:18:37 +0000 Subject: list subsetting In-Reply-To: <21593607.post@talk.nabble.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> <21593607.post@talk.nabble.com> Message-ID: <4977BB5D.2010008@mrabarnett.plus.com> culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > >>>> help("count") > no Python documentation found for 'count' > [snip] 'count' is a method of the list class, so you need: help(list.count) and if you want help on the list class then it's: help(list) Note that they aren't quoted. From fakeaddress at nowhere.org Wed Jan 21 19:47:29 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 21 Jan 2009 16:47:29 -0800 Subject: Start Python at client side from web app In-Reply-To: <6toehtFbrb81U1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: Actually you did pretty well. [...] > The main application is the intranet web application used with IE (ms windows client). Your idea of a custom mime-type, with a browser extension, should work. I don't know of any open-source implementation. Do you plan to have just one public key for verifying the downloaded Python scripts, hard-coded into the extension? -- --Bryan From skip at pobox.com Wed Jan 21 19:55:19 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 21 Jan 2009 18:55:19 -0600 Subject: Cannot contact Python webmaster! In-Reply-To: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> References: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> Message-ID: <18807.50167.567500.605506@montanaro.dyndns.org> >> Does anybody know how to get in touch with the www.python.org website >> maintainers? i sent mail to webmaster at python.org but it just bounces >> back. Is anybody even there? :) The webmaster address should work. Lots of people send mail to it. What is the error message in the bounce? Feel free to send your message to me and I'll forward it. (I'm one of the webmasters.) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From domelectric at gmail.com Wed Jan 21 20:12:44 2009 From: domelectric at gmail.com (debug) Date: Wed, 21 Jan 2009 17:12:44 -0800 (PST) Subject: frequency analysis without numpy References: <1105f65d-16d0-441c-9cd2-89c4011eb403@v39g2000pro.googlegroups.com> Message-ID: <285e3bce-a0cc-4a18-a965-1f680d115bbe@i20g2000prf.googlegroups.com> On Jan 21, 11:31?am, sturlamolden wrote: > On Jan 21, 12:13 am, sturlamolden wrote: > > > Apart from that, an FFT in pure python is going to be atrociously slow > > for anything but the shortest signals. I cannot imagine why you want > > to do this. > > Just to elaborate on this: > > The whole purpose of using FFT is speed. That pretty much excludes the > use of Python. > > If you don't care about speed, you could just as well compute the DFT > directly. The FFT is just a O(n lon n) algorithm for computing the > DFT. Here is a DFT with O(N**2) behavior: > > from math import sin, cos, pi > > def real_dft(x): > ? ?''' DFT for a real valued sequence x ''' > ? ?r = [] > ? ?N = len(x) > ? ?M = N//2 + 1 if N%2 else N//2 > ? ?for n in range(M): > ? ? ? s = 0j > ? ? ? for k in range(N): > ? ? ? ? ?tmp = 2*pi*k*n/N > ? ? ? ? ?s += x[k] * (cos(tmp) - 1j*sin(tmp)) > ? ? ? r.append(s) > ? ?return r > > S.M. Thanks for the quick reply, so what do I pass the real_dft function (obviously a list) but do I pass it the unpacked binary data? Dom From kdawg44 at gmail.com Wed Jan 21 20:21:06 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 20:21:06 -0500 Subject: Mechanize hanging Message-ID: <5caea3690901211721s35c9e39enb1f3df12b0a0479c@mail.gmail.com> Hi, I am trying to use mechanize to connect and log into Yahoo! Here is my code: #c:\Python25\python import re import urllib import urllib2 import mechanize print "print1" br = mechanize.Browser() br.set_handle_robots(False) br.open("https://login.yahoo.com/config/login?") It is hanging at the open. Eventually I have to just kill it and I get this: __init__.py Traceback (most recent call last): File "C:\Documents and Settings\kholleran\workspace\PythonPractice\src\PythonP ractice\__init__.py", line 10, in br.open("https://login.yahoo.com/config/login?") File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 206, in open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 232, in _mech_open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_opene r.py", line 192, in open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_http. py", line 570, in http_response KeyboardInterrupt Which i am sure is not very helpful but I don't want to leave anything out. Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From blueiur at gmail.com Wed Jan 21 20:35:02 2009 From: blueiur at gmail.com (blueiur) Date: Wed, 21 Jan 2009 17:35:02 -0800 (PST) Subject: list subsetting References: Message-ID: i think it's best way lst = [0, 1, 3.14, 20, 8, 8, 3.14] len( filter(lambda x: x > 3.13 and x < 3.15, lst) ) 2 On 1?22?, ??6?53?, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. From prologic at shortcircuit.net.au Wed Jan 21 20:53:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jan 2009 11:53:36 +1000 Subject: list subsetting In-Reply-To: References: Message-ID: On Thu, Jan 22, 2009 at 11:35 AM, blueiur wrote: > i think it's best way > lst = [0, 1, 3.14, 20, 8, 8, 3.14] > len( filter(lambda x: x > 3.13 and x < 3.15, lst) ) > 2 I prefer this way (cleaner): >>> lst = [0, 1, 3.14, 20, 8, 8, 3.14] >>> len([x for x in lst if 3.13 < x < 3.15]) 2 >>> cheers James From rhodri at wildebst.demon.co.uk Wed Jan 21 21:01:23 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 22 Jan 2009 02:01:23 -0000 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 09:42:19 -0000, Lars Behrens wrote: > Rhodri James wrote: > >> I *was* thinking of code produced in the real world, and I don't buy >> your assertion. I'm not an academic, and I wouldn't hesitate to lay >> down a line of code like that. As I said before, it fits into English >> language idioms naturally, and as a result is pretty self-descriptive. > > As a non-native speaker and non-academic, I don't understand the "fittine > into English language idioms naturally" which is mentioned here in the > different subthreads. Could you try to explain that for me? It just means that the progamming language concept in question has the same "shape" (i.e. roughly the same syntax) as an English language syntactic construct in common use. So for list comprehensions we have [ f(x) for x in l ] and "Make a list of f(x) for each x in the list l." You can see how the elements of the list comprehension fit sequentially into the English sentence. As other people have pointed out, this particular example really comes from the mathematical notation for constructing sets: f(x) ? x ? l ...but it's no accident that they both "translate" straightforwardly into English! -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 21 21:06:04 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 22 Jan 2009 02:06:04 -0000 Subject: reading file to list In-Reply-To: <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 09:13:03 -0000, Xah Lee wrote: > Rhodri James wrote: >> I recommend spending less time being certain that you are correct >> without seeking evidence > > I don't concur. > > For instance, when you are talking to a bunch of kids, you have to be > sure of yourself, else they run all over you, even if they didn't mean > to be rude. So you would rather give the appearance of authority than do the work to actually have authority? This is very poor teaching practice. > Also, one's demeanor must commensurate one's knowledge. If i pamper > you, you might think i'm a whimp, and run on with your opinions and > thoughts unbridled, which, can be considered as a miscommunication on > my part. As it is, I think your demeanor wildly outstrips your knowledge, something you have just confirmed. This attitude makes you a highly unreliable source of information. *plonk* -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 21 21:17:15 2009 From: http (Paul Rubin) Date: 21 Jan 2009 18:17:15 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <7x3afcjd90.fsf@ruckus.brouhaha.com> Thomas Guettler writes: > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. I think someone else already suggested using an hta. Does that not do what you want? More info is at: http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx Also, rather than concocting your own code signing system, maybe you want to use standard Python .exe packaging, signed with Authenticode. From erexsha at gmail.com Wed Jan 21 21:38:26 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 21 Jan 2009 18:38:26 -0800 Subject: malloc (error code=12) Message-ID: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Hi All, I am writing a multiprocessing program using python 2.6. It works in most cases, however when my input is large sometimes I get this message again and again: Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error code=12) *** error: can't allocate region and at the and I have these messages: Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug Exception in thread Thread-2: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 524, in __bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 479, in run self.__target(*self.__args, **self.__kwargs) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", line 259, in _handle_results task = get() MemoryError Any idea what is wrong here? I didn't attached the code since it is a big program and I don't know exactly which part of my program causes this error. And since it is multiprocessing I can't debug it and run it line by line! Thanks, Arash -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Wed Jan 21 21:49:29 2009 From: http (Paul Rubin) Date: 21 Jan 2009 18:49:29 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> Message-ID: <7xocy0ukau.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > In my limited experience with > > Haskell (statically typed but very high level), > > "dynamic" and "static" were not meant to concern typing here (or at > least not only typing). I'm not sure what you mean by those terms then. > Haskell and MLs are indeed statically typed, but with a powerfull type > inference system, which gives great support for genericity > (hmmm... is that the appropriate word ?) I think you mean "polymorphism"; genericity in functional programming usually means compile time reflection about types. (It means something different in Java or Ada). > Now these are functional languages, so the notion of "access > restriction" is just moot in this context !-) I'm not sure what you mean by that; Haskell certainly supports access restrictions, through its type and module systems. > Ok, I should probably have made clear I was thinking of a hi-level > dynamic _imperative_ language vs a low-level static _imperative_ > language. FP is quite another world. I'd say that Python's FP characteristics are an important part of its expressiveness. From rogerb at rogerbinns.com Wed Jan 21 22:01:27 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 21 Jan 2009 19:01:27 -0800 Subject: malloc (error code=12) In-Reply-To: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Arash Arfaee wrote: > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) errno 12 is ENOMEM on Macs (and Linux for that matter). You may have run out of swap space, but that is unlikely. The most likely cause is that you have run out of address space. For example a 32 bit process has 4GB of address space available. The kernel will take up to 2GB of that depending on the operating system. Various shared libraries and your program will take some. The program stack space will take some more. In your case malloc is attempting to allocate 384kb of memory using mmap by mapping anonymous memory (swap) into the address space. (The advantage of doing it this way is that the space can be unmapped when no longer needed.) With no appropriate address space left for this chunk, you get the error. You are either trying to use too much stuff or there is a memory leak. Calling gc.collect() can result in some deferred items being freed. To get an idea of how address space works, check out this article about what Linux did in 2004. The same principles apply to MacOSX. You can also see how the theoretical 4GB quickly disappears! http://lwn.net/Articles/91829/ Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl34YMACgkQmOOfHg372QRG9ACeKitN3f7cAcN1AOf76yTa9w+q CywAoL8JJ2/VvNe8eHOfP1r9UhOJH59z =EUjX -----END PGP SIGNATURE----- From http Wed Jan 21 22:04:11 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:04:11 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Message-ID: <7xiqo8ujmc.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Even better. Realize that you are trying to use a tool made for > debugging, documenting, and catching some obvious errors > (private/public) for "security". Go fix Bastion, that would be your > best bet. It was yanked out of python because it was insecure, but > if someone were to fix it, I'm sure the changes would be welcomed. Bastion appears to be fundamentally unfixable, at least in CPython. It might be possible to revive it in PyPy. > Btw, when I was programming in .Net (long time ago), I found a > little library that I wanted to use. The catch: it wasn't > opensource, Well, THAT's the problem with it. The issues that flowed from that problem are simply consequences. > But I don't think it is _fully_ irrelevant. See, a thread that begun > with saying that a piece of code was hard to read has evolved to > changing the language so we could have tools to statically proving > "certain things" with the code. Yes, being able to tell without studying 1000's of lines of code what the code does is a readability issue. If a function says at the top "this function returns an integer" and that assertion is verified by the compiler (or an external tool), you now know something about the function's return value by reading only one line. If the assertion is not verified by a program, then you have to actually examine all the code in the function to check that particular fact. Of course, the very presence of such assertions and the implementation methods necessary to make them verifiable can in some situations complicate the code, making it less readable in other regards. There's not a magic bullet, it's always a trade-off. > And each time a "suggestion" appears (from people that, at least at > Have pylint check if someone uses getattr in your code, at all. If pylint > doesn't do it, just grep for it and don't run that code. Simple. It would be nice to be able to use getattr on instances of class X while being able to verify that it is not used on instances of class Y. That's somewhat beyond the reach of Pylint at the moment, I think. From http Wed Jan 21 22:08:05 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:08:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xeiywujfu.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > Nowhere in this discussion is a point that I find telling: Python's > policy of accessibility to the full data structure allows simple > implementation of debugging software, rather than the black arcana > that is the normal fare of trying to weld debuggers into the compilers. Are you really saying that navigating through Python traceback and frame objects is not equally black arcana? Is there any hope of debuggers for CPython programs that use those interfaces working in Jython or PyPy? Java, at least, has a well defined and documented debugging interface that allows access to private and protected instance variables for debugging purposes. You can enable or disable that interface by setting a runtime option when you start the JVM. From mauriceling at gmail.com Wed Jan 21 22:09:14 2009 From: mauriceling at gmail.com (mauriceling@acm.org) Date: Wed, 21 Jan 2009 19:09:14 -0800 (PST) Subject: [ANN] The Python Papers Source Codes (Volume 1) Message-ID: <4754bd8c-93ea-4116-b2db-15516ef4efda@v18g2000pro.googlegroups.com> Hi everyone, It has been a few months in the cooking and I'm pleased to announce the publication and ISSN of The Python Papers Source Codes (ISSN 1836-621X). The Python Papers Source Code (TPPSC) will be a collection of code manuscripts, usually with a longer companion manuscript published in The Python Papers (TPP) or The Python Papers Monograph (TPPM). The purpose of TPPSC is modeled after "Collected Algorithms of the ACM". We will consider the following papers for TPPSC: * Algorithms: Implementation of an algorithm where it should be possible for a user to incorporate this software into a larger program, with the exception of standalone software. * Remarks: Brief report on a previously published algorithm, with the purpose of correcting / modifying the code. Details arguing for the modification should be provided with the modified code and patch file to used with the original implementation. * Translations: Translation of an algorithm / code from another programming language to Python, and should only be done if the algorithm still represents the current state of the art. * Certifications: Report on performance characteristics or verification of correctness by specification or from extensive testing of a previously published an algorithm / code. Certification reports do not change the original code; hence, a certification report usually do not contains codes. Each submission will usually consist of the following sections: 1. Title and author(s) affiliation 2. Abstract (usually a terse description of 1 or 2 sentences) 3. Description (about a page description of the purpose of the codes, including licence) 4. Code section (this is where the codes will be listed) 5. References 6. A compressed file of the codes files as supplementary materials For more details or to read our first paper under TPPSC, please go to http://ojs.pythonpapers.org/index.php/tppsc/issue/current All manuscripted for the periodicals under The Python Papers Anthology (http://ojs.pythonpapers.org) will be published once they are accepted. We look forward to your continued support. Cheers Maurice Ling Co-EIC, TPPA Maurice Ling From nl.srinivas at gmail.com Wed Jan 21 22:09:23 2009 From: nl.srinivas at gmail.com (Srinivasa NL) Date: Thu, 22 Jan 2009 08:39:23 +0530 Subject: quick beginners List comprehension question In-Reply-To: <6tpok5Fc7mabU1@mid.uni-berlin.de> References: <6touv8Fc32elU1@mid.uni-berlin.de> <6tpok5Fc7mabU1@mid.uni-berlin.de> Message-ID: <8b85ec440901211909j4104d303mde5860b4aded051a@mail.gmail.com> You can try this import random class foo: def __init__(self): self.bar = random.randint(1,100) def getbar(ls,i): ls.append(foo()) ls[i].bar = ls[i].bar * 3 ls = [] [getbar(ls,i) for i in range(10)] On Thu, Jan 22, 2009 at 4:45 AM, Diez B. Roggisch wrote: > MRAB schrieb: > >> Diez B. Roggisch wrote: >> >>> Dr Mephesto wrote: >>> >>> Hi, >>>> Im new to python, and OOP, and am trying to get a handle on list >>>> comprehension. >>>> >>>> Say I have a class Foo with a property called bar: >>>> >>>> class Foo: >>>> def __init__(self): >>>> self.bar = random.randint(1,100) >>>> >>>> and then I make a list of these objects: >>>> >>>> Newlist = [] >>>> for x in range(10): >>>> Newlist.append(Foo()) >>>> >>>> Now, suppose I wanted to triple the value of 'bar', I could always do: >>>> >>>> for x in range(10): >>>> Newlist[x].bar = Newlist[x].bar * 3 >>>> >>>> but can I do this using list comprehension? Thanks in Advance! >>>> >>> >>> No, as such, because list-comprehensions require you to have an >>> *expression* >>> in front of the iteration: >>> >>> resultlist = [ for in ] >>> >>> Now what you of course can do is this: >>> >>> def multiply(item): >>> item.bar = item.bar * 3 >>> >>> [multiply(i) for i in items] >>> >>> However, doing this will make python produce a list of None-references - >>> which is a waste. It's up to you if you care about that, but generally it >>> is frowned upon because of that, and the fact that the conciseness of the >>> list-comp here isn't really helping with the readability. >>> >>> If you had: >> >> def multiply(item): >> item.bar = item.bar * 3 >> return item >> >> then: >> >> [multiply(i) for i in items] >> >> would return items. Still a bad idea, though, because you're using a list >> comprehension for its side-effect. >> > > And redundant, which was the reason I ommited it. > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Wed Jan 21 22:19:55 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 21 Jan 2009 22:19:55 -0500 Subject: malloc (error code=12) In-Reply-To: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Message-ID: <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> On Wed, Jan 21, 2009 at 9:38 PM, Arash Arfaee wrote: > > Hi All, > > I am writing a multiprocessing program using python 2.6. It works in most > cases, however when my input is large sometimes I get this message again and > again: > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) > *** error: can't allocate region > > and at the and I have these messages: > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) > *** error: can't allocate region > *** set a breakpoint in malloc_error_break to debug > Exception in thread Thread-2: > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > line 524, in __bootstrap_inner > self.run() > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > line 479, in run > self.__target(*self.__args, **self.__kwargs) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", > line 259, in _handle_results > task = get() > MemoryError > > Any idea what is wrong here? I didn't attached the code since it is a big > program and I don't know exactly which part of my program causes this error. > And since it is multiprocessing I can't debug it and run it line by line! > > Thanks, > Arash > > -- > http://mail.python.org/mailman/listinfo/python-list > > wow. How big are these objects/input? From http Wed Jan 21 22:25:13 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:25:13 -0800 Subject: what's the point of rpython? References: <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <7xab9kc99i.fsf@ruckus.brouhaha.com> Ross Ridge writes: > Scott David Daniels wrote: > >The opcode cannot simply talk to its cache, it must either go directly > >to off-chip memory or communicate to other processors that it (and it > >alone) owns the increment target. > The cache coherency mechanism automatically prevents two or > more processors that have cached the same area of memory from > simultaneously modifying data in that area. > > The same cache coherency mechanism that prevents ordinary "unlocked" > instructions from simulanteously modifying the same cache line on > two different processors also provides the guarantee with "locked" > instructions. There's no additional hardware locks involved, and no > additional communication required. The cache coherency mechanism is what Scott described as "communicat[ing] to other processors that it (and it alone) owns the increment target". The cache coherency mechanism is not a trivial thing at all. It introduces its own hazards and delays, and it is getting more complicated all the time as processors and caches get faster and larger. Some time ago, cpu's hit their megahertz limits and that's why we're using multicores now. Some PL researchers think cache coherency is going to be the next limit, and are advocating languages like Erlang, which avoid use of shared memory and have separate heaps per thread; or alternatively, approaches like the MS Singularity research OS which relies on something like a linear type system to statically ensure that a given object is accessible to only one thread at a time. (That approach allows transferring objects between threads with no locks or copying required). From tjreedy at udel.edu Wed Jan 21 22:40:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 22:40:47 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 21, 9:34 am, Luis Zarrabeitia wrote: > >> But you keep failing to explay why do you need it to be _part of the standard_ >> library (or whatever). > > Technically, it doesn't need to be. But if someone proposes using > particular language for a major safety-critical project, the critical > features realistically need to be part of the standard language or at > the very least in the standard library. Python is not an appropriate language who make a fetish of the standard library. Numpy, which descends from code developed at US gov labs and agencies, and which would be essintial in many safety-critical projects being discussed, is not part of it. And that had nothing to do with its quality. From \ Wed Jan 21 23:29:22 2009 From: \ ("%s@gmail com" % myname.lower " ",) Date: Wed, 21 Jan 2009 22:29:22 -0600 Subject: Overloading Methods In-Reply-To: References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: >> K-Dawg wrote: >>> Can you overload methods in Python? >>> >>> Can I have multiple __inits__ with different parameters passed in? >>> >> Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > To elaborate on what Chris said, I usually find myself using class factory functions. Suppose you have a class that you want to initialize from a string, a file pointer, or a path. Here's how I'd implement it: class MyClass: def __init__(self, bytes): @classmethod def FromFilePointer(self, fp): bytes = fp.read() return MyCass.FromBytes(bytes) @classmethod def FromPath(self, path): bytes = open(path, "r").read() return MyCass.FromBytes(bytes) @classmethod #Yes, I know this duplicates __init__, def FromBytes(self, bytes): #but I include it so as to provide return MyClass(bytes) #3 parallel methods for initializing. myclass = MyClass.FromFilePointer(open("myfile.txt", "r")) myclass = MyClass.FromPath("myfile.txt") myclass = MyClass.FromBytes("spam-spam-spam") That might be a little bit more work, but I think it reads better and is more flexible down the road. -greg From xahlee at gmail.com Wed Jan 21 23:32:41 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 21 Jan 2009 20:32:41 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Message-ID: <55263864-7d43-479e-9af1-29ecc1db4105@b38g2000prf.googlegroups.com> Rhodri James wrote: > *plonk* Please see: ? Killfile Considered Harmful http://xahlee.org/UnixResource_dir/writ/kill_file_harmful.html plain text version follows --------------------------- Killfile Considered Harmful Xah Lee, 2000-02-26 In newsgroups, killfile is a playful word meaning that the poster has placed someone in a blacklist of authors, where their postings will be automatically hidden from view in their newsreader. Such functionality of newsreaders originated in unix. In the early 90s or before, it used to be referred to as ?sending someone into /dev/null?, because ?/dev/ null? can be used as a way for deleting email program outputs. The killfile behavior, is simply put: ?sweep-under-the-rug?, ?bury- head-in-sand? kind of behavior. Imagine that in a gathering where if everyone totally ignores other's voices except their own kind, then what cacophony would result? Similarly, if we ignore the problem of crime by simply using larger locks for our own doors, what consequence would result? We are all human beings. Our surroundings are our organs and affects us dearly. In newsgroups, inevitably there will be certain individuals with foul breath at times. Killfile mechanism is a very good feature to battle such annoyances. This is not a reason for falling for the convenience of blocking your ears from dissenting voices or the nonconformists. The worst thing i hate about it, is the broadcasting of someone being killfiled. Oftentimes the sole content of a message is ?You've been killfiled?. WHAT GOOD DOES IT DO TO THE COMMUNITY BY SUCH ANNOUNCEMENT? Is it a warning system for fellow readers to prepare to follow suit? Or is it a stupid self-righteous act? In the course of a unpleasant encountering, the killfilers feel the other party being unworthy of further response but they don't want to be seen as chickening out so they had to announce it as if saying: ?Hello world: you don't see a returning 'fuck you' from me because _I_ am _smarter_ and took a step ahead of my antagonist and covered my ears, not because he is correct or anything like that.?. Pride is a human nature, but unqualified conceit is despicable. A second motivation for announcing killfile is more explicitly juvenile. Killfile has several variant names: ?You've been killfiled.?, ?plonk? (sound of falling object), ?I've send you to /dev/ null? (unixism), and creativity does not seems to cease there, e.g. in comp.lang.lisp: (plonk 'xah) or signatures that reads ?in /dev/null, they can't hear you scream.? The reason of these playful variations is precisely literary folly. The utterer delights in its use since most are wanting of genuine literary artistry. This adds to the fashion of killfile and its broadcasting. Killfile behavior and broadcasting have another curious trait: No burden of commitment. One cannot really tell if the person really did the killfile. The decision to make a killfile cry in public does not carry any weight of responsibility as compared to making a claim, stating a ?fact?, or expressing a opinion. It is simply a variation of ?fuck you?. This too, contributed to its uncontrolled popularity. Xah ? http://xahlee.org/ ? From http Wed Jan 21 23:35:25 2009 From: http (Paul Rubin) Date: 21 Jan 2009 20:35:25 -0800 Subject: what's the point of rpython? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: <7x1vuwc60i.fsf@ruckus.brouhaha.com> Brendan Miller writes: > Actually this article explicitly mentions CMPXCHG as lock free. > http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms I see, that clears up some mysteries. Thanks. From http Wed Jan 21 23:46:02 2009 From: http (Paul Rubin) Date: 21 Jan 2009 20:46:02 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> Message-ID: <7xvds8aqyd.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > a) The contended case is the issue, not the uncontended case. An > uncontended lock is just constant overhead, not a barrier to > scalability a1) Really what matters is the actual mix between contended and uncontended accesses, and the synchronization strategy affects the amount of contention. For example, the traditional locking strategy involves acquiring a lock before reading the object, so two simultaneous read-only accesses would create lock contention. With STM, only updates acquire a lock, so multiple read-only threads can access the object simultaneously with no contention. a2) Constant factors matter!!! If using a different mechanism makes Python 2x faster, that's a very powerful reason to favor the other mechanism. > b) Locks on linux (since the switch to futexes) are pretty close to > free when uncontended. I thought futexes use a traditional locked read-modify-write instruction which is 50-100 cycles, cheap compared to a system call but quite expensive compared with a normal 1-cycle non-locked operation. > > > The second issue is the objects themselves, like a list which is > > > mutable. ?If you're using it in a single thread or writing from > > > multiple threads this is a non-trivial constant cost. ?... > The second issue has *nothing* to do with refcounts. It is the > objects themselves. A classic example is trying to do "i += 1", which > breaks down into "i = i + 1", which isn't an atomic operation. Oh, I see what you mean; yes, you're right, it's best to avoid doing those sorts of operation in shared objects too frequently. > Java's ConcurrentHash map gets this right. I'll have to look that up, it sounds interesting. I've been staying away from Java but a situation is coming up where I may have to (ugh) start using it. Thanks. From wolfgang at rohdewald.de Thu Jan 22 01:10:50 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Thu, 22 Jan 2009 07:10:50 +0100 Subject: Python 2.4 vs 2.5 - Unicode error In-Reply-To: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Message-ID: <200901220710.50403.wolfgang@rohdewald.de> On Mittwoch, 21. Januar 2009, Gaurav Veda wrote: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4357: ordinal not in range(128) > > Before sending the (insert) query to the mysql server, I do the > following which I think should've taken care of this problem: > sqlStr = sqlStr.replace('\\', '\\\\') you might consider using what mysql offers about unicode: save all strings encoded as unicode. Might be more work now but I think it would be a good investment in the future. have a look at the mysql documentation for mysql_real_escape_string() takes care of quoted chars. mysql_set_character_set() for setting the character set used by the database connection you can ensure that the web page is unicode by doing something like charsetregex = re.compile(r'charset=(.*?)[\"&]') charsetmatch = charsetregex.search(page) if charsetmatch: charset=charsetmatch.group(1) utf8Text = unicode(page,charset) -- Wolfgang From aahz at pythoncraft.com Thu Jan 22 01:16:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 22:16:00 -0800 Subject: pep 8 constants References: Message-ID: In article , Brendan Miller wrote: > >PEP 8 doesn't mention anything about using all caps to indicate a constant. Now it does! See http://www.python.org/dev/peps/pep-0008/ Thanks for bringing this up! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From erexsha at gmail.com Thu Jan 22 01:34:04 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 21 Jan 2009 22:34:04 -0800 Subject: malloc (error code=12) In-Reply-To: <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> Message-ID: <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> Very BIG Jesse!!!! It works on a huge Boolean function. And thanks Roger. Do you think it will be solved if I run it over another OS like windows? Cheers, Arash On Wed, Jan 21, 2009 at 7:19 PM, Jesse Noller wrote: > On Wed, Jan 21, 2009 at 9:38 PM, Arash Arfaee wrote: > > > > Hi All, > > > > I am writing a multiprocessing program using python 2.6. It works in most > > cases, however when my input is large sometimes I get this message again > and > > again: > > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > > code=12) > > *** error: can't allocate region > > > > and at the and I have these messages: > > > > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > > code=12) > > *** error: can't allocate region > > *** set a breakpoint in malloc_error_break to debug > > Exception in thread Thread-2: > > Traceback (most recent call last): > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > > line 524, in __bootstrap_inner > > self.run() > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > > line 479, in run > > self.__target(*self.__args, **self.__kwargs) > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", > > line 259, in _handle_results > > task = get() > > MemoryError > > > > Any idea what is wrong here? I didn't attached the code since it is a big > > program and I don't know exactly which part of my program causes this > error. > > And since it is multiprocessing I can't debug it and run it line by line! > > > > Thanks, > > Arash > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > wow. How big are these objects/input? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Thu Jan 22 01:48:43 2009 From: http (Paul Rubin) Date: 21 Jan 2009 22:48:43 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xwscnhm44.fsf@ruckus.brouhaha.com> Mark Wooding writes: > Some people (let's call them `type A programmers') have decided that > they want to be assisted with writing correct programs... > Other people (`type B programmers') don't like having their (apparently? > possibly?) correct programs rejected.... > I think trying to persuade a type A programmer that he wants to work > like a type B programmer, or /vice versa/, is difficult, bordering on > futile. Type A stereotypes type B as a bunch of ill-disciplined > reckless hackers; type B stereotypes type A as killjoy disciplinarians. > Meeting in the middle is difficult. (`We just want to add a little > safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) That's an interesting analysis. You know, I think I'm really a type B programmer, interested in type A techniques and tools for the same reason someone who naturally sleeps late is interested in extra-loud alarm clocks. Also, the application area matters. There is a difference between programming for one's own enjoyment or to do a personal task, and writing programs whose reliability or lack of it can affect other people's lives. I've never done any safety-critical programming but I do a fair amount of security-oriented Internet programming. As such, I have to always assume that my programs will be attacked by people who are smarter than I am and know more than I do. I can't possibly out-think them. If I don't see problems in a program, it's still plausible that someone smarter than me will spot something I missed. Therefore, my failure to detect the presence of problems is not reassuring. What I want is means of verifying the absence of problems. Finally, your type-A / type-B comparison works best regarding programs written by one programmer or by a few programmers who communicate closely. I'm working on a Python program in conjunction with a bunch of people in widely dispersed time zones, so communication isn't so fluid, and when something changes it's not always easy to notice the change or understand the reason and deal with it. There have been quite a few times when some hassle would have been avoided by the static interfaces mandated in less dynamic languages. Whether the hassle saved would have been outweighed by the extra verbosity is not known. Yeah, I know, more docs and tests can always help, but why not let the computer do more of the work? > Haskell is interesting: it can provide a surprising degree of > freedom, but it makes you work /very/ hard wrangling its type system > in order to get there; and again, I found I had most fun when I was > doing extremely evil unsafePerformIO hacking... I've found Haskell's type system to work pretty well for the not-so-fancy things I've tried so far. It takes some study to understand, but it's very uniform and beautiful. I'm having more trouble controlling resource consumption of programs that are otherwise semantically correct, a well known drawback of lazy evaluation. The purpose of unsafePerformIO is interfacing with C programs and importing them into Haskell as pure functions when appropriate. Anyway, at least for me, Haskell is fascinating as an object of study, and a lot of fun to hack with, but doesn't yet have the creature comforts or practicality of Python, plus its steep learning curve makes it unsuitable for projects not being developed by hardcore nerds. The ML family avoids some of Haskell's problems, but is generally less advanced and moribund. Pretty soon I think we will start seeing practical successor languages that put the best ideas together. From koranthala at gmail.com Thu Jan 22 01:49:10 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 21 Jan 2009 22:49:10 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> Message-ID: <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> On Jan 21, 2:55?pm, Vinay Sajip wrote: > On Jan 20, 10:11 am,koranthala wrote: > > > > > The doRollover method does not append to the earlier file. Rather, it > > creates a new file with the same name. > > Err... that's what rollover means - switching to a new log file (and > renaming the old ones). If it just appended to the old one, why would > it be called doRollover ? ;-) > > Regards, > > Vinay Sajip I understand Vinay. But my point is that I wanted a mechanism to rotate the log files based on data - i.e. today one log, tomorrow another. This is easier because when trouble tickets are raised, users mention that X failed at this time. Now, timedrotatingfilehandler does it - but only if the program is running the whole length of time. My tool is invoked by a cron job - so the program runs, then stops again and again. When I posted the question here, I was forwarded to the doRollover mechanism as a solution. I was just mentioning that doRollover, due to overwriting the files I would lose everything that is stored before. What I did now was to copy the file, and then append to the rolledover file - which does serve the purpose. But it is kludgy, and I dont think my situation is unique. I did see other people asking for the same functionality. So I was wondering whether it would be good idea to have this also in the next version. From koranthala at gmail.com Thu Jan 22 02:02:11 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 21 Jan 2009 23:02:11 -0800 (PST) Subject: Dictionary : items() Message-ID: Hi, Dictionary has the items method which returns the value as a list of tuples. I was wondering whether it would be a good idea to have an extra parameter - sort - to allow the tuples to be sorted as the desire of users. Currently what I do is: class SDict(dict): def items(self, sort=None): '''Returns list. Difference from basic dict in that it is sortable''' if not sort: return super(SDict, self).items() return sorted(self.iteritems(), key=sort) Usage: for a dictionary of strings sorted: l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) Now what I wanted was to incorporate this in the basic dictionary itself. Not only items(), but the methods similar to it - iteritems etc all can also have this parameter. Please let me know your views. Is this a good enough idea to be added to the next version of Python? From rhamph at gmail.com Thu Jan 22 02:14:00 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Wed, 21 Jan 2009 23:14:00 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> <7xvds8aqyd.fsf@ruckus.brouhaha.com> Message-ID: <458b0745-dee5-4b0f-9fbf-3974a14e4b16@t13g2000yqc.googlegroups.com> On Jan 21, 9:46?pm, Paul Rubin wrote: > Rhamphoryncus writes: > > a) The contended case is the issue, not the uncontended case. ?An > > uncontended lock is just constant overhead, not a barrier to > > scalability > > a1) Really what matters is the actual mix between contended and > uncontended accesses, and the synchronization strategy affects the > amount of contention. ?For example, the traditional locking strategy > involves acquiring a lock before reading the object, so two > simultaneous read-only accesses would create lock contention. ?With > STM, only updates acquire a lock, so multiple read-only threads can > access the object simultaneously with no contention. ? Aye, but my point is really about the myth of lock-free algorithms being uncontending ? it's simply not true, and CAN'T be true. A write is inherently a mutually exclusive operation. There's all sorts of ways to avoid contending for reads, spread out the writes and have a single thread coalesce them, etc, but fundamentally the write will involve some mutual exclusion. From tjreedy at udel.edu Thu Jan 22 02:33:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 02:33:30 -0500 Subject: Dictionary : items() In-Reply-To: References: Message-ID: koranthala wrote: > Hi, > Dictionary has the items method which returns the value as a list > of tuples. > I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. > Currently what I do is: > > class SDict(dict): > def items(self, sort=None): > '''Returns list. Difference from basic dict in that it is > sortable''' > if not sort: > return super(SDict, self).items() > return sorted(self.iteritems(), key=sort) > > Usage: > for a dictionary of strings sorted: > l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) > > Now what I wanted was to incorporate this in the basic dictionary > itself. Not only items(), but the methods similar to it - iteritems > etc all can also have this parameter. > > Please let me know your views. > Is this a good enough idea to be added to the next version of Python? In Python 3, the current .keys() returning a list and .iterkeys() returning an iterator both disappear and are replaced by .keys() returning an iterable set-like view of the dict. 'sorted(d.keys())' is the way to convert the view into a sorted list. So your idea is obsolete. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:38:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:38:03 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> Message-ID: On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: > Russ P. a ?crit : > (snip) >> In any case, I have suggested that Python should perhaps get a new >> keyword, "private" or "priv". > > And quite a few people - most of them using Python daily - answered they > didn't wan't it. Then they don't have to use it. Lots of people think that double-underscore name mangling is a waste of time: not strict enough to be useful, not open enough to be Pythonic. Solution? Don't use double-underscore names. -- Steven From astan.chee at al.com.au Thu Jan 22 02:38:45 2009 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 22 Jan 2009 18:38:45 +1100 Subject: USB in python Message-ID: <49782285.9010509@al.com.au> Hi, Im trying to write a program for my USB device and I'm thinking of using python to do this. The USB device is of my own making and it is activated when one of the two data pins of the USB is given about 5V (or similar to whatever the power pin is getting). Now I'm confused to if the software to activate this can actually be written and how do I do it? Any examples? I've seen pyUSB but it doesn't give me control over the hardware and how much power is going through the data pins. Thanks for any help. Cheers Astan From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:46:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:46:18 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 00:57:49 -0800, Aaron Brady wrote: > Natural language doesn't have the equivalent of parentheses, I take it you mean natural language doesn't have the equivalent of parentheses for *calling*, since NLs can (and do) use parentheses for grouping -- as well as various conventions regarding dashes -- terms together. I'm not aware of any NL that uses some sort of calling convention, but it isn't impossible. Most sentences have an object, a subject and a verb, just like OO method calls. So logically: "Peter ate the sandwich" is equivalent to: Peter.eat(sandwich) modulo complications due to tenses and similar. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:59:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:59:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, 21 Jan 2009 01:02:37 -0800, Aaron Brady wrote: >> >>> class Parrot: >> >> ... ? ? _private = 'spam' >> ...>>> p = Parrot() >> >>> p._private = 'ham' ?# allowed by default from protection import >> >>> lock >> >>> lock(p)._private >> >>> p._private = 'spam' >> >> Traceback (most recent call last): >> ? File "", line 1, in >> ProtectionError: attribute is read-only from outside of class Parrot >> >> Would that be so bad? I don't think so. > > Sorry, I didn't see the last part originally. I don't think 'outside of > class Parrot' is well-defined in Python. Does '_private' have to be a > member of 'Parrot', an instance of 'Parrot', or the calling instance of > 'Parrot', before entering the calling scope, or at the time the call is > made? Since many of these can change on the fly, there's more than one > consistent interpretation to the syntax. This is a good point. Any hypothetical move to make Python (or a Python- like language) stricter about private/protected attributes would need to deal with that question. I don't have to worry about that until somebody writes a PEP :) -- Steven From rogerb at rogerbinns.com Thu Jan 22 03:16:34 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Thu, 22 Jan 2009 00:16:34 -0800 Subject: malloc (error code=12) In-Reply-To: <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Arash Arfaee wrote: > Very BIG Jesse!!!! It works on a huge Boolean function. > And thanks Roger. Do you think it will be solved if I run it over > another OS like windows? By far the simplest solution is to use a 64 bit process on a 64 bit operating system. There are 64 bit versions of Windows available and you'll need to install the 64 bit version of Python (it has AMD64 in the name but will run on Intel 64 bit processors too). The various Linux distributions also have 64 bit flavours available. Note that you will also have to ensure that any 3rd party extensions using C code you use are also (re)compiled for 64 bit. The various versions of the 32 bit operating systems do have differing address space layouts but with large amounts of data in use you are still likely to hit a limit. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl4K18ACgkQmOOfHg372QSE5QCgkp9bTPhkmHuh1I6U+onPLJSB 5MQAoIDmYNSlISe13Z2lSS0wspd/r+n+ =YQw6 -----END PGP SIGNATURE----- From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:17:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:17:17 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 08:17:34 -0700, Joe Strout wrote: > Steven D'Aprano wrote: ... >> But even if RB doesn't have these things, I question that the syntax is >> "beautiful". Consider some arbitrary method Foo. If you see this: >> >> Foo >> >> Is that legal RB syntax? > > You betcha! How do you know? I haven't specified what Foo does. As you say a little later on: >> Maybe yes, maybe no. It all depends on what Foo does. If it returns no >> result, then it's legal. If it returns a result, it isn't. > > Right. In other words, you can tell just by looking at the call that it > doesn't return a result. This is often handy. You can't tell the difference between a syntax error and a valid call without knowing what Foo does. In Python, you can always recognise a syntax error without needing to worry about the semantics of the call. This is not the case with RealBasic. > For example, the built-in method to play the standard > system alert sound is: > > Beep > > Doesn't get much more readable and syntax-free than that. readable doesn't mean smallest amount of syntax possible sometimes syntax increases the readability of a text as you would see if we for example dropped all punctuation but you probably already knew that but perhaps you didnt draw the connection with programming language wink > Suppose now > that a beep isn't eloquent enough, and you want the computer to speak > something out loud instead. Also easy: I've programmed in Hypertalk, which is full of constructs like: get the value of field "Bar" put it into x put x+37 into x ask "Eat " & x " pies?" with "Yes please", "No thanks" if it is "Yes please" then go to card "PieCard" so I understand the principle of leaving out parentheses to make things look kinda-sorta vaguely English-like. I actually do like Hypertalk, I think it is neat, but I can tell you that you get no respect from other programmers when you show them your code :) >> So the question of whether syntax is legal depends, not on the >> syntactic elements involved, but on the *semantics* of the method >> (whether or not it returns a result). > > But of course. Any method call is legal only if the form of the call > matches the method prototype -- if you try to call a function that > requires 4 parameters, and give it only 3, that's an error too. I don't > see how this is different in any important way. But it isn't (presumably) a syntax error. I accept that in practice, it isn't a big deal once you get used to the convention. But it's a special case -- why treat functions of zero arguments as a special case just to save two characters? It seems to me that the cost of this is that using functions as first-class objects takes a major usability hit. How would you write the equivalent of this in RealBasic? def func(f, args): args = reversed(args) return f(*args) x = func( lambda a, b, c: a+b*c, [1, 2, 3] ) y = func( lambda: 7, [] ) -- Steven From castironpi at gmail.com Thu Jan 22 03:19:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 00:19:35 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <8ceefcd2-f84e-449d-af54-985e271d27d3@p2g2000prn.googlegroups.com> On Jan 22, 1:46?am, Steven D'Aprano wrote: > On Wed, 21 Jan 2009 00:57:49 -0800, Aaron Brady wrote: > > Natural language doesn't have the equivalent of parentheses, > > I take it you mean natural language doesn't have the equivalent of > parentheses for *calling*, since NLs can (and do) use parentheses for > grouping -- as well as various conventions regarding dashes -- terms > together. I take it back. I meant spoken languages. > I'm not aware of any NL that uses some sort of calling convention, but it > isn't impossible. Most sentences have an object, a subject and a verb, > just like OO method calls. So logically: > > "Peter ate the sandwich" > > is equivalent to: > > Peter.eat(sandwich) > > modulo complications due to tenses and similar. I don't think it's as common as you imply to give a sequence of instructions in spoken language. It's more often rule-based, such as 'when X, Y' (the German for 'if' is 'wenn'), and 'Employees will X', as well as 'X was wearing', and 'X is doing'. 'John is dating Mary' is informational, whereas 'John.date( Mary )' is a step in a procedure. How-to knowledge is often (I guess predominantly) tacit, relying on agents to determine a missing step in a process, or fill in from context. In fact, knowledge-based might be a better description of most NL aims (many times with implied ordering). That is, mostly, I want to alter your beliefs (OT: too often to create fear), not your know-how specifically. When you do see imperatives, they're just function calls, not walkthroughs. Programming is more resemblant to math structure building. You'll notice that a PL translation of a narrative don't look anything like code ('Banquo.take( dagger )'), and declarative knowledge is best (I advance) expressed in a relational language, like SQL. Further, when you have to be precise, PLs (programming languages) are the language to do it in. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:24:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:24:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 12:55:42 -0500, Luis Zarrabeitia wrote: > Btw, the correctness of a program (on a turing-complete language) cannot > be statically proven. Ask Turing about it. The correctness of *all* *arbitrary* programs cannot be proven. That doesn't mean that no programs can be proven. -- Steven From castironpi at gmail.com Thu Jan 22 03:28:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 00:28:43 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Jan 22, 2:17?am, Steven D'Aprano wrote: > On Wed, 21 Jan 2009 08:17:34 -0700, Joe Strout wrote: > > But of course. ?Any method call is legal only if the form of the call > > matches the method prototype -- if you try to call a function that > > requires 4 parameters, and give it only 3, that's an error too. ?I don't > > see how this is different in any important way. > > But it isn't (presumably) a syntax error. It often is a compile-time error, as opposed to run-time. However, if Joe meant to distinguish between 'Give the ball to Jamie' and 'Give the ball', it is a syntax error: 'Give( the ball, Jamie )' vs. 'Give ( the ball )'. (Wait, is 'give the ball' a syntax error or what?) > I accept that in practice, it isn't a big deal once you get used to the > convention. But it's a special case -- why treat functions of zero > arguments as a special case just to save two characters? In fact, NLs clearly mark the difference between commanding a process, and nominating it. 'Go to the store' is the imperative, while 'Going to the store' is the nominative. In this case, 'ing' serves to mark the absence of parentheses, and the bare form, without 'ing', marks the call. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:35:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:35:37 GMT Subject: Dictionary : items() References: Message-ID: On Wed, 21 Jan 2009 23:02:11 -0800, koranthala wrote: > Hi, > Dictionary has the items method which returns the value as a list > of tuples. > I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. > Currently what I do is: > > class SDict(dict): > def items(self, sort=None): > '''Returns list. Difference from basic dict in that it is > sortable''' > if not sort: > return super(SDict, self).items() > return sorted(self.iteritems(), key=sort) > > Usage: > for a dictionary of strings sorted: > l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) That is better written as: l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) where abcd is *any* kind of mapping with an items() method. It could be a dict, a defaultdict, ordereddict, binarytree, or anything else the caller needs. > Now what I wanted was to incorporate this in the basic dictionary > itself. Not only items(), but the methods similar to it - iteritems etc > all can also have this parameter. > > Please let me know your views. > Is this a good enough idea to be added to the next version of Python? No. -- Steven From http Thu Jan 22 03:53:11 2009 From: http (Paul Rubin) Date: 22 Jan 2009 00:53:11 -0800 Subject: Dictionary : items() References: Message-ID: <7x8wp3wwlk.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > That is better written as: > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) In Python 2.x, I prefer the style l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) but Python 3.0 breaks the tuple unpacking per some PEP. From http Thu Jan 22 03:54:25 2009 From: http (Paul Rubin) Date: 22 Jan 2009 00:54:25 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> <7xwscpyvrd.fsf@ruckus.brouhaha.com> Message-ID: <7xsknbn2ke.fsf@ruckus.brouhaha.com> Tim Rowe writes: > Programs done in Ada are, by objective measures, more reliable than > those done in C and C++ (the very best released C++ programs are about > as good as the worst released Ada programs), although I've always > wondered how much of that is because of language differences and how > much is because Ada tends to be used on critical projects that also > tend to get a lot more attention to development standards. A reliability comparison between C++ and Java might shed light on that. From bearophileHUGS at lycos.com Thu Jan 22 04:10:10 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 01:10:10 -0800 (PST) Subject: A different kind of interface Message-ID: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> I use the Python shell daily, plus of course normal editors to edit python scripts. They both are very useful for different purposes. But the default interactive shell isn't much handy if you want to modify the past code to run it again, or you want to embed a bit of text in the code, or if you want to produce something a bit more clean that you can save, or just if you want to edit and debug 7-lines long programs. I have tried IPython, but I have never appreciated it too much, maybe because it requires me to remember too many things (and because on Win it's probably a little less handy). Probably I need something closer to an editor and less close to a shell. In past I have also used the interactive editor of Mathematica (older versions, but I think its basic usage isn't changed much later), but despite being quite handy if you want to mix plotting and the editing of small formulas, I can't appreciate it to write programs more than 3 lines long. It's not a good or handy editor, and it has some other disadvantages So I have always tried to think for possible alternative solutions for an interactive way to use Python. I am not looking for something to replace the nornal editors used to write long Python programs. Years ago I have found this nice small program, TextCalc: http://www.atomixbuttons.com/textcalc/ Despite being very limited and being not integrated with everything else, it's so handy that for me in certain situations it's the right tool to use when I have to process numbers and data in simple ways. It helps me keep all the intermediate solutions, you can save the working page just as the text file you are seeing, it's "passive", it doesn't go bang, so if you want you can use it just a primitive text editor. It does something only when you ask it to. And for a basic usage there is nearly nothing to remember. I don't know if this can be any good, but maybe a textcalc-like interface that (beside having few graphical buttons for normal operations, and few basic text editing capabilities) allows to use Python may be a good idea. Probably there are better designs for this interface, but it's hard to invent them. If you have ideas I'd like to know them. Bye, bearophile From vinay_sajip at yahoo.co.uk Thu Jan 22 04:14:02 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 22 Jan 2009 01:14:02 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> Message-ID: <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> On Jan 22, 6:49 am, koranthala wrote: > I understand Vinay. But my point is that I wanted a mechanism to > rotate the log files based on data - i.e. today one log, tomorrow Did you mean "based on date"? > another. This is easier because when trouble tickets are raised, users > mention that X failed at this time. > Now, timedrotatingfilehandler does it - but only if the program is > running the whole length of time. > My tool is invoked by a cron job - so the program runs, then stops > again and again. If you just want a log file whose name is date-based, you don't need a rotating file handler. Compute the file name from the date and use the API to create a FileHandler specifying that file name, and add it to your logger. For example: import logging, time logging.basicConfig(level=logging.DEBUG, filename=time.strftime("/path/ to/my/logs/myapp-%Y-%m-%d-%H%M.log", time.localtime()), filemode="w") logging.debug("Hello, world!") Hopefully you can adapt this snippet to your needs. Regards, Vinay Sajip From novosibirsk at gmail.com Thu Jan 22 04:26:21 2009 From: novosibirsk at gmail.com (novosibirsk at gmail.com) Date: Thu, 22 Jan 2009 01:26:21 -0800 (PST) Subject: Seeking pure Python AES/RSA library compatible with OpenSSL Message-ID: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> Hello, I am faced with the following problem: 0. In pure Python, encrypt some data using AES. 1. In pure Python, encrypt the key used in 0 with RSA, given a private key in PEM format. 2. In C, using OpenSSL, decrypt the AES key from 0 using the public key that corresponds to private key in 1. 3. In C, using OpenSSL, decrypt the data from 0 with AES key from 2. Question --- is there a library I can use for steps 0 and 1? Thanks! From bignose+hates-spam at benfinney.id.au Thu Jan 22 04:33:00 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 22 Jan 2009 20:33:00 +1100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <87prif3ctv.fsf@benfinney.id.au> bearophileHUGS at lycos.com writes: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. > But the default interactive shell isn't much handy if you want to > modify the past code to run it again, or you want to embed a bit of > text in the code, or if you want to produce something a bit more > clean that you can save, or just if you want to edit and debug > 7-lines long programs. Adding an editor to Python solves this problem only for Python. I certainly wouldn't want to learn a new text editor just for one language. You're not *only* programming in Python, I hope? Many of us solve this by using a single full-featured programmer's editor that allows invoking a program ? written in any of *dozens or hundreds* of different languages ? from within the editor. It's a solution that only requires you to learn one editor interface, having chosen one that's well-supported on all popular platforms and with plug-ins accumulated over many years for a smorgasbord of different tasks. The leaders in the field, by far, are GNU Emacs and Vim . -- \ ?Jury: A group of 12 people, who, having lied to the judge | `\ about their health, hearing, and business engagements, have | _o__) failed to fool him.? ?Henry L. Mencken | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 04:33:26 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 10:33:26 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> Message-ID: <49783d5a$0$24804$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: > >> Russ P. a ?crit : >> (snip) >>> In any case, I have suggested that Python should perhaps get a new >>> keyword, "private" or "priv". >> And quite a few people - most of them using Python daily - answered they >> didn't wan't it. > > Then they don't have to use it. Yes they would. Because this would become the official way to tell what's interface and what's implementation, and *this* is the important point. > Lots of people think that double-underscore name mangling is a waste of > time: not strict enough to be useful, not open enough to be Pythonic. > Solution? Don't use double-underscore names. The name-mangling mechanism is actually useful when you want to make sure some vital implementation attribute (usually of a class intented to be extended by the library users) won't be *accidentally* overwritten. From __peter__ at web.de Thu Jan 22 04:34:51 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Jan 2009 10:34:51 +0100 Subject: is this pythonic? References: Message-ID: TP wrote: > Hi, > > Is the following code pythonic: > >>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>> l.remove(*dict) >>>> l > [{'title': 'to', 'value': 2}] > > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? And > rather use a data storage as the following? > > l = { '001':{"title":"to", "value":2}, '002' > {"title":"ti","value":"coucou"}} > > The problem with this storage is that it implies to manipulate some "ids" > that have not any meaning for a humain being (001, 002, etc). > > Thanks a lot for you opinion, If you can change the rest of your program to work smoothly with a dictionary I would suggest the following: >>> items = [{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>> lookup = dict((item["title"], item) for item in items) >>> lookup {'to': {'value': 2, 'title': 'to'}, 'ti': {'value': 'coucou', 'title': 'ti'}} >>> del lookup["ti"] >>> lookup {'to': {'value': 2, 'title': 'to'}} If you later have to accomodate for multiple dictionaries with the same title use lists of dictionaries as values: >> from collections import defaultdict >>> lookup = defaultdict(list) >>> for item in items: ... lookup[item["title"]].append(item) ... >>> lookup defaultdict(, {'to': [{'value': 2, 'title': 'to'}], 'ti': [{'value': 'coucou', 'title': 'ti'}]}) >>> del lookup["ti"] >>> lookup defaultdict(, {'to': [{'value': 2, 'title': 'to'}]}) Peter From bignose+hates-spam at benfinney.id.au Thu Jan 22 04:36:00 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 22 Jan 2009 20:36:00 +1100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <87mydj3cov.fsf@benfinney.id.au> bearophileHUGS at lycos.com writes: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. > But the default interactive shell isn't much handy if you want to > modify the past code to run it again, or you want to embed a bit of > text in the code, or if you want to produce something a bit more > clean that you can save, or just if you want to edit and debug > 7-lines long programs. Adding an editor to Python solves this problem only for Python. I certainly wouldn't want to learn a new text editor just for one language. You're not *only* programming in Python, I hope? Many of us solve this by using a single full-featured programmer's editor that allows invoking a program ? written in any of *dozens or hundreds* of different languages ? from within the editor. It's a solution that only requires you to learn one editor interface, having chosen one that's well-supported on all popular platforms and with plug-ins accumulated over many years for a smorgasbord of different tasks. The leaders in the field, by far, are GNU Emacs and Vim . -- \ ?Jury: A group of 12 people, who, having lied to the judge | `\ about their health, hearing, and business engagements, have | _o__) failed to fool him.? ?Henry L. Mencken | Ben Finney From http Thu Jan 22 04:42:43 2009 From: http (Paul Rubin) Date: 22 Jan 2009 01:42:43 -0800 Subject: Seeking pure Python AES/RSA library compatible with OpenSSL References: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> Message-ID: <7xocxz65ik.fsf@ruckus.brouhaha.com> novosibirsk at gmail.com writes: > 0. In pure Python, encrypt some data using AES. > 1. In pure Python, encrypt the key used in 0 with RSA, given a private > key in PEM format. > Question --- is there a library I can use for steps 0 and 1? I know there are some AES libs around, try google. The libs will be quite slow. I think tlslite can do PEM decoding and PKCS1.5 encryption (http://trevp.net/tlslite). From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 04:55:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 10:55:44 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xocy0ukau.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> <7xocy0ukau.fsf@ruckus.brouhaha.com> Message-ID: <49784295$0$15148$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> In my limited experience with >>> Haskell (statically typed but very high level), >> "dynamic" and "static" were not meant to concern typing here (or at >> least not only typing). > > I'm not sure what you mean by those terms then. Python (and some other dynamic OOPLs) allow you to dynamically add / remove / replace attributes (inclunding methods), either on a per-instance or per-class (at least for class-based oned) basis. >> Haskell and MLs are indeed statically typed, but with a powerfull type >> inference system, which gives great support for genericity >> (hmmm... is that the appropriate word ?) > > I think you mean "polymorphism"; Yeps. > genericity in functional programming > usually means compile time reflection about types. (It means > something different in Java or Ada). > >> Now these are functional languages, so the notion of "access >> restriction" is just moot in this context !-) > > I'm not sure what you mean by that; Haskell certainly supports access > restrictions, through its type and module systems. Same word, somehow different context. What I meant was that since functional languages are (supposedly) stateless, there's no state to make "private". But you're right to correct me wrt/ existing access restrictions in Haskell. >> Ok, I should probably have made clear I was thinking of a hi-level >> dynamic _imperative_ language vs a low-level static _imperative_ >> language. FP is quite another world. > > I'd say that Python's FP characteristics are an important part of its > expressiveness. Indeed - but they do not make Python a functional language[1]. Python is based on objects, not on functions, and quite a lot of the support for functional programing in Python comes from the object system. Just look how functools.partial is implemented. Yes, it could have been implemented with a HOF and closures (and there have been such implementations), but using a class is still the most pythonic way here. [1] except for a very formal definition of "functional language". From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 05:04:12 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 11:04:12 +0100 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <49784490$0$14151$426a74cc@news.free.fr> bearophileHUGS at lycos.com a ?crit : > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. > > I have tried IPython, but I have never appreciated it too much, maybe > because it requires me to remember too many things (and because on Win > it's probably a little less handy). Probably I need something closer > to an editor and less close to a shell. emacs python-mode is a very powerful combo. Write your code in a buffer, send it for evaluation to another buffer running a Python shell, interact with it, switch back to the edit buffer, change your code, lather, rinse, repeat. From novosibirsk at gmail.com Thu Jan 22 05:06:53 2009 From: novosibirsk at gmail.com (novosibirsk at gmail.com) Date: Thu, 22 Jan 2009 02:06:53 -0800 (PST) Subject: Seeking pure Python AES/RSA library compatible with OpenSSL References: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> <7xocxz65ik.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 1:42?am, Paul Rubin wrote: > novosibi... at gmail.com writes: > > 0. In pure Python, encrypt some data using AES. > > 1. In pure Python, encrypt the key used in 0 with RSA, given a private > > key in PEM format. > > Question --- is there a library I can use for steps 0 and 1? > > I know there are some AES libs around, try google. ?The libs > will be quite slow. > > I think tlslite can do PEM decoding and PKCS1.5 encryption > (http://trevp.net/tlslite). Yes, tlslite is the only pure Python library I found that deals with PEM. The problem is OpenSSL doesn't want to decrypt data encrypted by tlslite (RSA_public_decrypt(), RSA_PKCS1_PADDING). From deets at nospam.web.de Thu Jan 22 05:15:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 11:15:58 +0100 Subject: USB in python References: Message-ID: <6tqvb2Fcan25U1@mid.uni-berlin.de> Astan Chee wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of using > python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V (or > similar to whatever the power pin is getting). Now I'm confused to if > the software to activate this can actually be written and how do I do > it? Any examples? I've seen pyUSB but it doesn't give me control over > the hardware and how much power is going through the data pins. This doesn't sound like an USB-device to me. The USB-standard defines a serial line protocol, where of course the state of the TX-line is set to whatever the protocol dictates. And as not all of the things put out on the line are of the programmer's own doing, it will be on and off all the time. And no piece of software is going to control that - it's already implemented in the USB-host-controllers inside your computer. Even with a considerably more primitive RS233 line you'd not stand a chance with that design. Unless I'm not getting something here. I've created USB-devices based on the AT90USB1287 from Atmel, and there you can of course use the libusb (and it's wrapping PyUSB) to acccess the device, and e.g. drive a single port-pin of the uC high - to activate, whatever you want to activate. Diez From tino at wildenhain.de Thu Jan 22 05:21:00 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 22 Jan 2009 11:21:00 +0100 Subject: USB in python In-Reply-To: <49782285.9010509@al.com.au> References: <49782285.9010509@al.com.au> Message-ID: <4978488C.3090504@wildenhain.de> Astan Chee wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of using > python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V (or > similar to whatever the power pin is getting). Now I'm confused to if > the software to activate this can actually be written and how do I do > it? Any examples? I've seen pyUSB but it doesn't give me control over > the hardware and how much power is going through the data pins. > Thanks for any help. Your approach doesn't sound right to me. I don't believe you can control the PINs of the USB host interface directly. You need to configure the host controller - OS is giving you interfaces and abstration for the different device types. All you need to do is to implement the end points as per spec in your hardware and write handler for your hardware's USB ids. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mario.ruggier at gmail.com Thu Jan 22 05:30:51 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 22 Jan 2009 02:30:51 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7xsknjp12g.fsf@ruckus.brouhaha.com> Message-ID: <36d8b11b-842b-4632-81fb-831f872c7067@a26g2000prf.googlegroups.com> On Jan 16, 7:17?pm, Paul Rubin wrote: > mario ruggier writes: > > All the above attempts will be blocked this way. Any other disallow- > > sub-strings to add to the list above? > > I think what you are trying to do is fundamentally hopeless. ?You > might look at web.py (http://webpy.org) for another approach, that > puts a complete interpreter for a Python-like language into the > template engine. Well, that is a bold statement... but maybe it is explained by what you refer to, so I did a cursory look. But I miss to notice any reference of an embedded "python-like language -- is there some sort of overview of how web.py implements this e.g. something like the equivalent of the doc describing how evoque implements it's sandbox: http://evoque.gizmojo.org/usage/restricted/ I get the feeling you may also be ignoring contextual factors... restricting the full python interpreter is not what we are talking about here, but templating systems (such as web.py?) that just allow embedding of any and all python code will require exactly that. And *that* may well seem fundamentally hopeless. Evoque chooses to allow only expressions, and those under a *managed* context. To make that secure is a whole different (smaller) task. From ricaraoz at gmail.com Thu Jan 22 05:42:11 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 22 Jan 2009 07:42:11 -0300 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) In-Reply-To: <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <49784D83.9040207@gmail.com> Mark Wooding wrote: > Steven D'Aprano writes: > > > >> No it's not. It's *practical*. There are domains where *by law* code >> needs to meet all sorts of strict standards to prove safety and >> security, and Python *simply cannot meet those standards*. >> > > Codswallop. One can prove stuff about Python programs using the same > techniques as one uses for any other language. I've done it. Other > languages have better automated tools, it's true -- but the techniques > are basically the same. > > I've seen this kind of thinking and there are a couple of things about which I've always wondered. Let's say you formally specify an application (hey! you are a zillionaire and can afford it), and that after the app is coded you formally prove that it complies with the specification. Cool! now your app is safe? NO, because your formal proof was done over source code and the compiler has not been formally specified and proven. So your app might still fail. So let's say you have the $ to do that and you get a perfect compiler. Are you safe? NO, because the code generated by the compiler makes calls to the OS which is not specified. So let's assume you are a world leader and you spend a little war's money in fully specifying and proving an OS. Are you safe? NO, because the processor and other hardware logic has NOT been specified. And on and on. What I've seen engineers do when they need extra safety is to put in place independently developed and operated redundant systems, at least three, and the system will do whatever two of the independent systems agree on. So I guess if I really wanted to be safe with a system I'd have it made by at least three different teams (yes, also the requirements should be written by different teams) in different languages under different OS's and different independent machines. And THEN I would have some measure of safety (and this would certainly be more cost effective than the formal specification route). -------------- next part -------------- An HTML attachment was scrubbed... URL: From mario.ruggier at gmail.com Thu Jan 22 05:57:01 2009 From: mario.ruggier at gmail.com (mario g) Date: Thu, 22 Jan 2009 11:57:01 +0100 Subject: Ideas to optimize this getitem/eval call? In-Reply-To: <4960F600.8030909@wildenhain.de> References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> <4960F600.8030909@wildenhain.de> Message-ID: <9b148f5a0901220257w2802109cm2922bb9ff41177c2@mail.gmail.com> On Sun, Jan 4, 2009 at 6:46 PM, Tino Wildenhain wrote: > mario wrote: >> >> On Jan 3, 7:16 am, Steven D'Aprano > cybersource.com.au> wrote: >> >>> I was about to make a comment about this being a security hole, >> >> Strange that you say this, as you are also implying that *all* the >> widely-used templating systems for python are security holes... Well, >> you would be right to say that of course ;-) Infact, evoque is really >> one of the few (or even the only one?) that was conceived from the >> start to support restricted evaluation. > > Thats is definitively not the case. There are at least 2 quite old > template systems on top of a quite good restricted environment. Interesting, which ones? I should have probably emphasized *conceived* above... that feature was there in the initial design and not added afterwards. > Cheers > Tino From digitig at gmail.com Thu Jan 22 06:23:00 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 22 Jan 2009 11:23:00 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <200901211255.42988.kyrie@uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: > Btw, the correctness of a program (on a turing-complete language) cannot be > statically proven. Ask Turing about it. For the most safety critical of programmes, for which static proof is required, restrictions are placed on the use of the language that effectively mean that it is not Turing-complete. Specifically, all loops that are required to terminate require a loop variant to be defined. Typically the loop variant is a finite non-negative integer that provably decreases on every pass of the loop, which makes halting decidable. -- Tim Rowe From hv at tbz-pariv.de Thu Jan 22 06:33:24 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 12:33:24 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6tr3s4Fcct18U1@mid.individual.net> Bryan Olson schrieb: > Thomas Guettler wrote: >> Sorry, I described my problem not well. Here is more information: > > Actually you did pretty well. > > [...] >> The main application is the intranet web application used with IE (ms >> windows client). > > Your idea of a custom mime-type, with a browser extension, should work. > I don't know of any open-source implementation. > > Do you plan to have just one public key for verifying the downloaded > Python scripts, hard-coded into the extension? Yes, that's what plan: one hard-coded public key is on the client. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From hv at tbz-pariv.de Thu Jan 22 06:38:10 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 12:38:10 +0100 Subject: Start Python at client side from web app In-Reply-To: <6tpo16FbacfjU1@mid.uni-berlin.de> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: <6tr453Fca5h6U1@mid.individual.net> Diez B. Roggisch schrieb: > >> 2) create a localhost web server, for the client side manipulation. >> Then have your remote webserver render a form that posts via >> javavscript to the localhost webserver. The localhost server would >> post back in >> the same way. > > AFAIK the JS security model prevents that. A page requested from "http://myintranetserver/" can redirect to "http://localhost:myport/myapp/?foo=..." this would work. But how should the web server at localhost be started? You need to write a Windows service. I guess that's not very easy, since I am not used to windows programming. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From usenetthrowaway at gmail.com Thu Jan 22 06:56:13 2009 From: usenetthrowaway at gmail.com (Gary) Date: Thu, 22 Jan 2009 11:56:13 -0000 Subject: file write collision consideration References: Message-ID: It would help to know which version of Python when giving examples... I recollect that so-called mutex operation wasn't actually thread safe when using Python 2.5, but perhaps that was wrong, or subsequent versions have fixed that? From chris at simplistix.co.uk Thu Jan 22 07:02:01 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 22 Jan 2009 12:02:01 +0000 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009 Message-ID: <49786039.2020101@simplistix.co.uk> Hi All, Too many people in the Python community think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's PyCon in Chicago on Wednesday, 25th March that will cover working with Excel files in Python using the pure-python libraries xlrd, xlwt and xlutils. I'll be looking to cover: - Reading Excel Files Including formatting, unicode dates and formulae. - Writing Excel Files Including formatting with easyxf and things like freeze pains, print areas, etc - Filtering Excel Files A run through on the structure of xlutils.filter and some examples to show you how it works. - Workshop for your problems I'm hoping anyone who attends will get a lot out of this! If you're planning on attending and have a particular problem you'd like to work on in this part of the tutorial, please drop me an email and I'll try and make sure I come prepared! All you need for the tutorial is a working knowledge of Excel and Python, with a laptop as an added benefit, and to be at PyCon this year: http://us.pycon.org I look forward to seeing you all there! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From hv at tbz-pariv.de Thu Jan 22 07:13:55 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 13:13:55 +0100 Subject: Start Python at client side from web app In-Reply-To: <7x3afcjd90.fsf@ruckus.brouhaha.com> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <7x3afcjd90.fsf@ruckus.brouhaha.com> Message-ID: <6tr684Fcc0tfU1@mid.individual.net> Paul Rubin schrieb: > Thomas Guettler writes: >> 1. The user pushes a button in the web app. >> 2. Webserver sends signed python code to the client with own mime type >> 3. IE sends code to the python application. >> 4. Signature gets checked, Python code on the client gets executed. >> 5. Maybe send some data to the server with http. > > I think someone else already suggested using an hta. Does that not > do what you want? More info is at: > > http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx > > Also, rather than concocting your own code signing system, maybe you > want to use standard Python .exe packaging, signed with Authenticode. Authenticode looks like a Microsoft invention. Although I need this for windows now, it should be portable. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From bearophileHUGS at lycos.com Thu Jan 22 07:17:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 04:17:57 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> Message-ID: <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> Ben Finney: > Adding an editor to Python solves this problem only for Python. I'm sure that once such "editor" (I use the word editor for lack of a better term) is created, it can also be quickly adapted with other dynamic languages, like Ruby, TCL, Lua, Io, Perl, Awk, ecc. Probably it can't be adapted for languages like Java, C++, etc. > Many of us solve this by using a single full-featured programmer's > editor that allows invoking a program +IBQ- written in any of *dozens or > hundreds* of different languages +IBQ- from within the editor. I don't know what an IBQ is. But I was not talking about a normal editor. Take a look at TextCalc, for example. I am trying to invent something that I have not seen so far :-) > It's a solution that only requires you to learn one editor interface, I'm looking for something very easy to use, probably more easy than the Python shell itself. >The leaders in the field, by far, are GNU Emacs and Vim< I'm probably looking for something based on different ideas. ------------------- Bruno Desthuilliers: >emacs python-mode is a very powerful combo. Write your code in a buffer, send it for evaluation to another buffer running a Python shell, interact with it, switch back to the edit buffer, change your code, lather, rinse, repeat.< I am sure that's very useful, but it's not what I am looking for. I am looking for something that's a bit closer to the Mathematica shell, but more passive and fitter to edit 10-lines long programs too, and able to save the cleaned text result of the interaction. Bye, bearophile From morphex at gmail.com Thu Jan 22 07:25:40 2009 From: morphex at gmail.com (morphex) Date: Thu, 22 Jan 2009 04:25:40 -0800 (PST) Subject: Recommended SOAP library? Message-ID: Hi, I have to implement a service which involves some SOAP/WSDL. So far I've found http://pywebsvcs.sourceforge.net/ Is that the recommended library to build some logic which sets/ retrieves some information from a web service? Thanks, Morten From geraint.williams at gmail.com Thu Jan 22 07:38:37 2009 From: geraint.williams at gmail.com (GHZ) Date: Thu, 22 Jan 2009 04:38:37 -0800 (PST) Subject: Recommended SOAP library? References: Message-ID: <951c75e2-e17f-461c-9228-d4ec42931c47@r10g2000prf.googlegroups.com> if you require a SOAP client, then I would recommend SUDS https://fedorahosted.org/suds/ Other options are not in active development, so is difficult to get support. From stef.mientki at gmail.com Thu Jan 22 07:42:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 22 Jan 2009 13:42:26 +0100 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <497869B2.7050005@gmail.com> Several guys are working on a MatLab like editor / IDE, based on wxPython, including myself ;-) see http://mientki.ruhosting.nl/data_www/pylab_works/pw_debug.html e.g. with F9 it runs either the selected code or if nothing selected the whole code or even more powerfull (depending on your needs) http://mientki.ruhosting.nl/data_www/pylab_works/pw_signal_workbench.html cheers, Stef bearophileHUGS at lycos.com wrote: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. > > I have tried IPython, but I have never appreciated it too much, maybe > because it requires me to remember too many things (and because on Win > it's probably a little less handy). Probably I need something closer > to an editor and less close to a shell. > > In past I have also used the interactive editor of Mathematica (older > versions, but I think its basic usage isn't changed much later), but > despite being quite handy if you want to mix plotting and the editing > of small formulas, I can't appreciate it to write programs more than 3 > lines long. It's not a good or handy editor, and it has some other > disadvantages > > So I have always tried to think for possible alternative solutions for > an interactive way to use Python. I am not looking for something to > replace the nornal editors used to write long Python programs. > > Years ago I have found this nice small program, TextCalc: > http://www.atomixbuttons.com/textcalc/ > > Despite being very limited and being not integrated with everything > else, it's so handy that for me in certain situations it's the right > tool to use when I have to process numbers and data in simple ways. It > helps me keep all the intermediate solutions, you can save the working > page just as the text file you are seeing, it's "passive", it doesn't > go bang, so if you want you can use it just a primitive text editor. > It does something only when you ask it to. And for a basic usage there > is nearly nothing to remember. > > I don't know if this can be any good, but maybe a textcalc-like > interface that (beside having few graphical buttons for normal > operations, and few basic text editing capabilities) allows to use > Python may be a good idea. Probably there are better designs for this > interface, but it's hard to invent them. > > If you have ideas I'd like to know them. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > From alan.isaac at gmail.com Thu Jan 22 07:45:51 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 22 Jan 2009 12:45:51 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: <3UZdl.1235$Aw2.116@nwrddc02.gnilink.net> On 1/20/2009 3:53 PM Rob Williscroft apparently wrote: > http://bugs.python.org/issue1762972 (*) Useful. Thanks. Alan Isaac From Tribulations at Paralleles.invalid Thu Jan 22 08:32:00 2009 From: Tribulations at Paralleles.invalid (TP) Date: Thu, 22 Jan 2009 14:32:00 +0100 Subject: is this pythonic? References: Message-ID: Peter Otten wrote: > If you can change the rest of your program to work smoothly with a > dictionary I would suggest the following: [snip] >>> from collections import defaultdict [snip] Thanks a lot. I didn't know defaultdict. It is powerful. I begin to understand that people prefer using dictionaries than lists, so as to take advantage of their automatic lookup feature. -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 08:32:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 13:32:51 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> Message-ID: <01886bdd$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >> >>> Russ P. a ?crit : >>> (snip) >>>> In any case, I have suggested that Python should perhaps get a new >>>> keyword, "private" or "priv". >>> And quite a few people - most of them using Python daily - answered >>> they didn't wan't it. >> >> Then they don't have to use it. > > Yes they would. Because this would become the official way to tell > what's interface and what's implementation, and *this* is the important > point. But if you have free access to attributes, then *everything* is interface. >> Lots of people think that double-underscore name mangling is a waste of >> time: not strict enough to be useful, not open enough to be Pythonic. >> Solution? Don't use double-underscore names. > > The name-mangling mechanism is actually useful when you want to make > sure some vital implementation attribute (usually of a class intented to > be extended by the library users) won't be *accidentally* overwritten. Except it doesn't. Take this simple module: # module.py class C(object): __n = 3 def spam(self): return "spam " * self.__n class D(C): pass # end module.py I have no interest in C; I may have no idea it even exists. It might be buried deep inside the inheritance hierarchy of the class I really want, D. So now I subclass D: >>> from module import D >>> class C(D): ... __n = 5 ... def ham(self): ... return "I eat ham %d times a day" % self.__n ... >>> C().ham() 'I eat ham 5 times a day' >>> >>> assert C().spam() == D().spam() Traceback (most recent call last): File "", line 1, in AssertionError And now I have accidentally broken the spam() method, due to a name clash. Besides, double-underscore names are a PITA to work with: >>> class Parrot(object): ... __colour = 'blue' ... def __str__(self): ... return 'A %s parrot' % self.__colour ... __repr__ = __str__ ... >>> >>> class RedParrot(Parrot): # Just like Parrot, only red. ... __colour = 'red' ... >>> >>> Parrot() A blue parrot >>> RedParrot() A blue parrot -- Steven From castironpi at gmail.com Thu Jan 22 08:49:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 05:49:30 -0800 (PST) Subject: subclass PyDictObject -- any gotchas? Message-ID: <0f7edac5-c03d-4c18-adb4-015eafc8dba2@e1g2000pra.googlegroups.com> Hello all, I am trying to create a mapping class similar to the base dictionary, but with some added behaviors that affect pointers on a low level. I have a bare-bones version I compiled with MinGW, and it is working! I want to know if there is anything that is going to bite me later, when I start adding real behavior: for example, times when my overrides won't get called, shortcuts, better macros, etc. Later on, I will be altering the 'ma_table' field from one call to another, overriding most of PyDict_Type's methods with before-and- after code, adding synchronization, and copying-and-pasting memory allocation code from 'dictobject.c' directly in, since I need the object to be at specific addresses. Anything I need to beware of? Any reason it might be infeasible? 108 lines, please snip on reply. Thanks in advance and sincerely, A. Brady #include #include using namespace std; typedef struct { PyDictObject base; /* Type-specific fields go here. */ } DictSubObject; static void dictsub_dealloc(register PyDictObject *mp) { cout<< "In 'dictsub_dealloc'"<< endl; PyDict_Type.tp_dealloc((PyObject*)mp); } static int dictsub_ass_sub(DictSubObject *mp, PyObject *v, PyObject *w) { cout<< "In 'dictsub_ass_sub'"<< endl; return PyDict_Type.tp_as_mapping->mp_ass_subscript( (PyObject *) mp, v, w ); } static PyMappingMethods dictsub_as_mapping = { NULL, /*mp_length*/ NULL, /*mp_subscript*/ (objobjargproc)dictsub_ass_sub, /*mp_ass_subscript*/ }; static PyMethodDef DictSub_methods[] = { {NULL} }; PyObject * dictsub_alloc(PyTypeObject *self, Py_ssize_t nitems) { cout<< "In 'dictsub_alloc'"<< endl; return PyDict_Type.tp_alloc(self, nitems); } static PyTypeObject DictSubType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "DictSub", /*tp_name*/ sizeof(DictSubObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)dictsub_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ &dictsub_as_mapping, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "DictSub objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ DictSub_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ dictsub_alloc, /* tp_alloc */ 0, /* tp_new */ }; static PyMethodDef module_methods[] = { {NULL} /* Sentinel */ }; #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ #define PyMODINIT_FUNC void #endif PyMODINIT_FUNC initdictsub(void) { PyObject* m; DictSubType.tp_base= &PyDict_Type; if (PyType_Ready(&DictSubType) < 0) return; m = Py_InitModule3("dictsub", module_methods, "Custom."); Py_INCREF(&DictSubType); PyModule_AddObject(m, "DictSub", (PyObject *)&DictSubType); if (m == NULL) return; } From benjamin.kaplan at case.edu Thu Jan 22 08:50:16 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 22 Jan 2009 08:50:16 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Thu, Jan 22, 2009 at 1:16 AM, Aahz wrote: > In article , > Brendan Miller wrote: > > > >PEP 8 doesn't mention anything about using all caps to indicate a > constant. > > Now it does! See > http://www.python.org/dev/peps/pep-0008/ > > Thanks for bringing this up! Since the constants in the std lib (like math.pi and math.e) no longer follow PEP 8, should we expect them to change at some point in the future? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jan 22 09:00:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 06:00:50 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: In article <7xd4ele060.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >alex23 writes: >> >> Here's an article by Guido talking about the last attempt to remove >> the GIL and the performance issues that arose: >> >> "I'd welcome a set of patches into Py3k *only if* the performance for >> a single-threaded program (and for a multi-threaded but I/O-bound >> program) *does not decrease*." > >The performance decrease is an artifact of CPython's rather primitive >storage management (reference counts in every object). This is >pervasive and can't really be removed. But a new implementation >(e.g. PyPy) can and should have a real garbage collector that doesn't >suffer from such effects. CPython's "primitive" storage management has a lot to do with the simplicity of interfacing CPython with external libraries. Any solution that proposes to get rid of the GIL needs to address that. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Thu Jan 22 09:09:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 06:09:02 -0800 Subject: what's the point of rpython? References: Message-ID: In article , Ross Ridge wrote: >Scott David Daniels wrote: >> >>The opcode cannot simply talk to its cache, it must either go directly >>to off-chip memory or communicate to other processors that it (and it >>alone) owns the increment target. > >In fact all it does simply talk to its cache. From the "Intel 64 and >IA-32 Architectures Software Developer's Manual, Volume 3A: System >Programming Guide, Part 1": > > For the P6 and more recent processor families, if the area of > memory being locked during a LOCK operation is cached in the > processor that is performing the LOCK operation as write-back > memory and is completely contained in a cache line, the processor > may not assert the LOCK# signal on the bus. Instead, it will > modify the memory location internally and allow it's cache > coherency mechanism to insure that the operation is carried > out atomically. This operation is called "cache locking." The > cache coherency mechanism automatically prevents two or more > processors that have cached the same area of memory from > simultaneously modifying data in that area. > >The same cache coherency mechanism that prevents ordinary "unlocked" >instructions from simulanteously modifying the same cache line on >two different processors also provides the guarantee with "locked" >instructions. There's no additional hardware locks involved, and no >additional communication required. IIRC, it was Bruce Eckel I heard talking about discovering all kinds of nasty Java thread bugs because cache coherency wasn't working the way the Java developers thought it did.... This is apparently something very difficult to get correct. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 09:12:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 15:12:31 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01886bdd$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> Message-ID: <49787ec2$0$4751$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: > >> Steven D'Aprano a ?crit : >>> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >>> >>>> Russ P. a ?crit : >>>> (snip) >>>>> In any case, I have suggested that Python should perhaps get a new >>>>> keyword, "private" or "priv". >>>> And quite a few people - most of them using Python daily - answered >>>> they didn't wan't it. >>> Then they don't have to use it. >> Yes they would. Because this would become the official way to tell >> what's interface and what's implementation, and *this* is the important >> point. > > But if you have free access to attributes, then *everything* is interface. > Nope. >>> Lots of people think that double-underscore name mangling is a waste of >>> time: not strict enough to be useful, not open enough to be Pythonic. >>> Solution? Don't use double-underscore names. >> The name-mangling mechanism is actually useful when you want to make >> sure some vital implementation attribute (usually of a class intented to >> be extended by the library users) won't be *accidentally* overwritten. > > Except it doesn't. Except it works for all real-life code I've ever seen. (snip convoluted counter-example) Steven, sorry for being so pragmatic, but the fact is that, from experience (not only mine - I'm talking about thousands of man/year experience), it JustWork(tm). From morphex at gmail.com Thu Jan 22 09:13:47 2009 From: morphex at gmail.com (morphex) Date: Thu, 22 Jan 2009 06:13:47 -0800 (PST) Subject: Recommended SOAP library? References: <951c75e2-e17f-461c-9228-d4ec42931c47@r10g2000prf.googlegroups.com> Message-ID: On 22 Jan, 13:38, GHZ wrote: > if you require a SOAP client, then I would recommend SUDShttps://fedorahosted.org/suds/ > > Other options are not in active development, so is difficult to get > support. SUDS looks great, thanks for the tip! :) -Morten From makkalot at gmail.com Thu Jan 22 09:24:37 2009 From: makkalot at gmail.com (makkalot at gmail.com) Date: Thu, 22 Jan 2009 16:24:37 +0200 Subject: Jabber xml-rpc Message-ID: <200901221624.38328.makkalot@gmail.com> Hi all i have a program which does some xml-rpc work over SSL, i want now to add some NAT capibilites to my program. The way i thought is to use jabber and send my calls over jabber xml-rpc and ssl it. - Is it the best way to make sth 'natted'? - If yes which library do u reccommend ? twisted or [1] Thanks for your help in advance ... [1] http://pypi.python.org/pypi/Easy%20Jabber%20XML-RPC/1.0 From sturlamolden at yahoo.no Thu Jan 22 09:49:14 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 22 Jan 2009 06:49:14 -0800 (PST) Subject: Executing previous stack frame Message-ID: frame = sys._getframe().f_back is the previous stack frame. Is there any way to execute (with exec or eval) frame.f_code beginning from frame.f_lasti or frame.f_lineno? I am trying to spawn a thread that is initialized with the code and state of the previous stack frame. S.M. From techtonik at gmail.com Thu Jan 22 10:00:26 2009 From: techtonik at gmail.com (anatoly techtonik) Date: Thu, 22 Jan 2009 17:00:26 +0200 Subject: About SCons Re: [Python-Dev] progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 Message-ID: On Thu, Jan 22, 2009 at 12:51 AM, Roumen Petrov wrote: >> >> Against 2.3, rejected due to dependence on SCons. >> Also appears to have been incomplete, needing more work. > > No it was complete but use SCons. Most of changes changes in code you will > see again in 3871. > I would better use SCons for both unix and windows builds. In case of windows for both compilers - mingw and microsoft ones. To port curses extension to windows I need to know what gcc options mean, what are the rules to write Makefiles and how to repeat these rules as well as find options in visual studio interface. Not mentioning various platform-specific defines and warning fixes. -- --anatoly t. From pruebauno at latinmail.com Thu Jan 22 10:04:38 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 22 Jan 2009 07:04:38 -0800 (PST) Subject: is this pythonic? References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> Message-ID: On Jan 21, 4:23?pm, Scott David Daniels wrote: > prueba... at latinmail.com wrote: > > ... If you have duplicates this will not work. You will have to do > > something like this instead: > > >>>> o=[] > >>>> i=0 > >>>> ln=len(l) > >>>> while i > ? ?if l[i]['title']=='ti': > > ? ? ? ? ? ?o.append(l.pop(i)) > > ? ? ? ? ? ?ln-=1 > > ? ?else: > > ? ? ? ? ? ?i+=1 > > Or the following: > ? ? ?indices = [i for i,d in enumerate(l) if d['title']=='ti'] > ? ? ?for i in reversed(indices): # so del doesn't affect later positions > ? ? ? ? ?del l[i] > > --Scott David Daniels > Scott.Dani... at Acm.Org Cool. How come I didn't think of that! That means I can create an evil one liner now >:-). replacecount=len([o.append(l.pop(i)) for i in reversed(xrange(len(l))) if l[i]['title']=='ti']) From pruebauno at latinmail.com Thu Jan 22 10:08:31 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 22 Jan 2009 07:08:31 -0800 (PST) Subject: is this pythonic? References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> Message-ID: On Jan 21, 4:23?pm, Scott David Daniels wrote: > prueba... at latinmail.com wrote: > > ... If you have duplicates this will not work. You will have to do > > something like this instead: > > >>>> o=[] > >>>> i=0 > >>>> ln=len(l) > >>>> while i > ? ?if l[i]['title']=='ti': > > ? ? ? ? ? ?o.append(l.pop(i)) > > ? ? ? ? ? ?ln-=1 > > ? ?else: > > ? ? ? ? ? ?i+=1 > > Or the following: > ? ? ?indices = [i for i,d in enumerate(l) if d['title']=='ti'] > ? ? ?for i in reversed(indices): # so del doesn't affect later positions > ? ? ? ? ?del l[i] > > --Scott David Daniels > Scott.Dani... at Acm.Org Cool. How come I didn't think of that!. Now I can write my evil one liner >:-). o=[l.pop(i) for i in reversed(xrange(len(l))) if l[i]['title']=='ti'] From mdw at distorted.org.uk Thu Jan 22 10:10:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 15:10:04 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> <7xwscnhm44.fsf@ruckus.brouhaha.com> Message-ID: <87vds7e5rn.fsf.mdw@metalzone.distorted.org.uk> Paul Rubin writes: > Also, the application area matters. There is a difference between > programming for one's own enjoyment or to do a personal task, and > writing programs whose reliability or lack of it can affect other > people's lives. I've never done any safety-critical programming but I > do a fair amount of security-oriented Internet programming. I do quite a lot of that too. But I don't think it's necessary to have the kinds of static guarantees that a statically-typed language provides in order to write programs which are robust against attacks. Many actual attacks exploit the low-level nature and lack of safety of C (and related languages): array (e.g., buffer) overflows, integer overflows, etc. A language implementation can foil these attacks in one of two (obvious) ways. Firstly, by making them provably impossible -- which would lay proof obligations on the programmer to show that he never writes beyond the bounds of an array, or that arithmetic results are always within the prescribed bounds. (This doesn't seem practical for most programmers.) Secondly, by introducing runtime checks which cause the program to fail safely, either by signalling an exception or simply terminating, when these bad things happen. In the case of array overflows, many `safe' languages implement these runtime checks, and they now seem to be accepted as a good idea. The case of arithmetic errors seems less universal: Python and Lisp fail gracefully to unbounded integers when the machine's limits are exceeded; Java and C# silently give incorrect results[1]. Anyway, Python is exempt from these problems (assuming, at any rate, that the implementation is solid; but we've got to start somewhere). There's a more subtle strain of logical errors which can also be exploited. It's possible that type errors lead to exploitable weaknesses. I don't know of an example offhand, but it seems conceivable that a C program has a bug where an object of one type is passed to a function expecting an object of a different type (maybe due to variadic argument handling, use of `void *', or a superfluous typecast); the contents of this object cause the function to misbehave in a manner convenient to the adversary. In Python, objects have types, and primitive operations verify that they are operating on objects of suitable types, signalling errors as necessary; but higher level functions may simply assume (`duck typing') that the object conforms to a given protocol and expecting a failure if this assumption turns out to be false. It does seem possible that an adversary might arrange for a different object to be passed in, which seems to obey the same protocol but in fact misinterprets the messages. (For example, the function expects a cleaning object, and invokes ob.polish(cup) to make the cup become shiny; in fact, the object is a nationality detector, and returns whether the cup is Polish; the function proceeds with a dirty cup!) Static type systems can mitigate these sorts of `ugly duckling' attacks somewhat, but it's not possible to do so entirely. The object in question may in fact implement the protocol in question (implement the interface, in Java, or be an instance of an appropriate type-class in Haskell) but do so in an unexpected manner. And beyond these kinds of type vulnerabilities are other mistakes which are very unlikely to be caught by even a sophisticated type system; e.g., a function for accepting input to a random number generator, which actually ignores the caller's data! [1] Here, I don't mean to suggest that the truncating behaviour of Java or C# arithmetic can't be used intentionally. Rather, I mean that, in the absence of such an intention, arithmetic in these languages simply yields results which are inconsistent with the usual rules of integer arithmetic. > Finally, your type-A / type-B comparison works best regarding programs > written by one programmer or by a few programmers who communicate > closely. Possibly; but I think that larger groups can cooperate reasonably within a particular style. > I'm working on a Python program in conjunction with a bunch of people > in widely dispersed time zones, so communication isn't so fluid, and > when something changes it's not always easy to notice the change or > understand the reason and deal with it. I'll agree that dynamic languages like Python require a degree of discipline to use effectively (despite the stereotype of type B as ill-disciplined hackers), and that includes communicating effectively with other developers about changes which might affect them. Statically typed languages provide a safety-net, but not always a complete one. One might argue that the static-typing safety-net can lead to complacency -- a risk compensation effect. (I don't have any evidence for this so I'm speculating rather than arguing. I'd be interested to know whether there's any research on the subject, though.) Even so, I don't think I'd recommend Python for a nontrivial project to be implemented by a team of low-to-average-competence programmers. That's not a criticism of Python: I simply don't believe in one-size-fits-all solutions. I'd rather write in Python; I'd probably recommend that the above team use C#. (Of course, I'd rather have one or two highly skilled programmers and use Python, than the low-to- average team; but industry does like its horde-of-monkeys approach.) > There have been quite a few times when some hassle would have been > avoided by the static interfaces mandated in less dynamic languages. > Whether the hassle saved would have been outweighed by the extra > verbosity is not known. This is another question for which it'd be nice to have answers. But, alas, we're unlikely to unless dynamic typing returns to academic favour. > I've found Haskell's type system to work pretty well for the > not-so-fancy things I've tried so far. It takes some study to > understand, but it's very uniform and beautiful. It can be very effective, but I think I have a dynamically-typed brain -- I keep on running into situations where I need more and more exotic type-system features in order to do things the way I naturally want to. It's easier to give up and use Lisp... > I'm having more trouble controlling resource consumption of programs > that are otherwise semantically correct, a well known drawback of lazy > evaluation. I always had difficulty curbing my (natural?) inclination towards tail- recursion, which leads to a lot of wasted space in a normal-order language. > The purpose of unsafePerformIO is interfacing with C programs and > importing them into Haskell as pure functions when appropriate. Yes, that's what I was doing. (I was trying to build a crypto interface using a C library for the underlying primitives, but it became too unwieldy and I gave up.) In particular, I used unsafePerformIO to provide a functional view of a hash function. > The ML family avoids some of Haskell's problems, but is generally less > advanced and moribund. Standard ML seems dead in the water; OCaml looks like it's got some momentum behind it, though, but isn't going in the same direction. > Pretty soon I think we will start seeing practical successor languages > that put the best ideas together. Perhaps... -- [mdw] From google at mrabarnett.plus.com Thu Jan 22 10:13:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jan 2009 15:13:30 +0000 Subject: what's the point of rpython? In-Reply-To: <7xab9kc99i.fsf@ruckus.brouhaha.com> References: <7xk58pgppz.fsf@ruckus.brouhaha.com> <7xab9kc99i.fsf@ruckus.brouhaha.com> Message-ID: <49788D1A.6060407@mrabarnett.plus.com> Paul Rubin wrote: > Ross Ridge writes: >> Scott David Daniels wrote: >>> The opcode cannot simply talk to its cache, it must either go >>> directly to off-chip memory or communicate to other processors >>> that it (and it alone) owns the increment target. > >> The cache coherency mechanism automatically prevents two or more >> processors that have cached the same area of memory from >> simultaneously modifying data in that area. >> >> The same cache coherency mechanism that prevents ordinary >> "unlocked" instructions from simulanteously modifying the same >> cache line on two different processors also provides the guarantee >> with "locked" instructions. There's no additional hardware locks >> involved, and no additional communication required. > > The cache coherency mechanism is what Scott described as > "communicat[ing] to other processors that it (and it alone) owns the > increment target". The cache coherency mechanism is not a trivial > thing at all. It introduces its own hazards and delays, and it is > getting more complicated all the time as processors and caches get > faster and larger. Some time ago, cpu's hit their megahertz limits > and that's why we're using multicores now. Some PL researchers think > cache coherency is going to be the next limit, and are advocating > languages like Erlang, which avoid use of shared memory and have > separate heaps per thread; or alternatively, approaches like the MS > Singularity research OS which relies on something like a linear type > system to statically ensure that a given object is accessible to > only one thread at a time. (That approach allows transferring > objects between threads with no locks or copying required). > How much difference would it make if the reference counts weren't in cached memory? I'm thinking that an object could have a pointer to its reference count, which would be stored elsewhere in some uncached memory. From koranthala at gmail.com Thu Jan 22 10:40:39 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 22 Jan 2009 07:40:39 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: On Jan 22, 2:14?pm, Vinay Sajip wrote: > On Jan 22, 6:49 am,koranthala wrote: > > > I understand Vinay. But my point is that I wanted a mechanism to > > rotate the log files based on data - i.e. today one log, tomorrow > > Did you mean "based on date"? > > > another. This is easier because when trouble tickets are raised, users > > mention that X failed at this time. > > Now, timedrotatingfilehandler does it - but only if the program is > > running the whole length of time. > > My tool is invoked by a cron job - so the program runs, then stops > > again and again. > > If you just want a log file whose name is date-based, you don't need a > rotating file handler. Compute the file name from the date and use the > API to create a FileHandler specifying that file name, and add it to > your logger. For example: > > import logging, time > > logging.basicConfig(level=logging.DEBUG, filename=time.strftime("/path/ > to/my/logs/myapp-%Y-%m-%d-%H%M.log", time.localtime()), filemode="w") > logging.debug("Hello, world!") > > Hopefully you can adapt this snippet to your needs. > > Regards, > > Vinay Sajip Thank you very much Vinay. You have been extremely helpful. This was my first design - but then I found that log system was taking up quite a huge chunk of the memory. That is why I went to rotating file handler. Anyways, now I have modified doRollover to append if file is there, so, for me it is working. What I was thinking was such an option in the basic logging system might be of good help. Again, Vinay, Thank you very much. You were extremely helpful. From kdawg44 at gmail.com Thu Jan 22 10:48:30 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Thu, 22 Jan 2009 10:48:30 -0500 Subject: Python Style Question Message-ID: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each class or One py file with all the classes The classes are small with a constructor and a few methods, no more than a couple, some with just one other method. Which is more "pythonic"? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Thu Jan 22 11:07:44 2009 From: joe at strout.net (Joe Strout) Date: Thu, 22 Jan 2009 09:07:44 -0700 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <497899D0.5030706@strout.net> Steven D'Aprano wrote: >>> Foo >>> >>> Is that legal RB syntax? >> You betcha! > > How do you know? I haven't specified what Foo does. You haven't specified whether "Foo" is a valid identifier at all, so I'm assuming that it is both valid and used correctly here. The syntax is certainly valid -- it matches the language grammar -- but whether the programmer was smoking something while typing it is another matter. > You can't tell the difference between a syntax error and a valid call > without knowing what Foo does. In Python, you can always recognise a > syntax error without needing to worry about the semantics of the call. > This is not the case with RealBasic. If "Foo" is undefined or not a subroutine with no required parameters, then it's not a syntax error; it's an undefined-identifier error, a you-must-use-the-result-of-this-function-call error, or a invalid-arguments error. It is NOT a syntax error in any case. This is no different in Python, where: Foo() may be valid or not, depending on whether there actually exists a Foo method in an accessible scope that has no required parameters. If so, it's valid Python code; if not, it is some sort of error. The only difference is that RB will detect any of those errors at compile time, while Python will not detect them until this line of code is executed. Given code that compiles/runs without error, the other difference between the two is that in RB, you can tell that Foo has no return value, whereas in Python you can't tell -- and if it does return a value, you can't tell whether the author of the line above is intentionally ignoring it, or was just ignorant. >> Beep >> >> Doesn't get much more readable and syntax-free than that. > > readable doesn't mean smallest amount of syntax possible sometimes syntax > increases the readability of a text as you would see if we for example > dropped all punctuation but you probably already knew that but perhaps > you didnt draw the connection with programming language wink Cute. But I stand by my contention that "Beep" is about the most readable way imaginable to express the "make a beep sound now please" command, and any additional punctuation (parentheses, semicolons, etc.) only get in the way. >> Suppose now >> that a beep isn't eloquent enough, and you want the computer to speak >> something out loud instead. Also easy: > > I've programmed in Hypertalk, which is full of constructs like: > > get the value of field "Bar" > put it into x > put x+37 into x > ask "Eat " & x " pies?" with "Yes please", "No thanks" > if it is "Yes please" then go to card "PieCard" Yes, AppleScript is like this to. Beastly. I consider those to be read-only languages -- easy to read, maddeningly difficult to write, as you often have to guess exactly which English-like construct is going to actually work. > so I understand the principle of leaving out parentheses to make things > look kinda-sorta vaguely English-like. That wasn't really my point here. REALbasic isn't much more English-like than any other language; it's just much lighter on all the extra punctuation that seems to plague many other languages. One Yuma (which uses the same language as RB) user put it this way: "I'm so freaking excited about Yuma that I can barely write about it. It's an HTML preprocessor like PHP, but with clean syntax. This is good because PHP is nasty. It's powerful and ubiquitous, but it looks like someone with a mouthful of punctuation sneezed all over my screen." The same comment would apply to any other C-derived language, such as ActionScript, Java[Script], C++, Obj-C, and so on. Python is better than these, but still not as clean as Python. >> But of course. Any method call is legal only if the form of the call >> matches the method prototype -- if you try to call a function that >> requires 4 parameters, and give it only 3, that's an error too. I don't >> see how this is different in any important way. > > But it isn't (presumably) a syntax error. Right, thanks for confirming my point above. :) > I accept that in practice, it isn't a big deal once you get used to the > convention. But it's a special case -- why treat functions of zero > arguments as a special case just to save two characters? It's not a special case. It's an example of the general case, "only require parentheses where necessary to avoid ambiguity". Pretty much all modern languages (i.e. please don't drag out LISP again) apply this principle in expressions, where "2+(3*5)" is the same as "2+3*5" -- parentheses here are optional because operator precedence already groups the terms unambiguously. This is the same thing: if you want to multiply 10 by the result of a Rnd call and add 5, you can write "10*Rnd()+5" -- but the parentheses here aren't contributing anything. They're not disambiguating anything or grouping anything or otherwise doing a job. So you can instead write "10*Rnd+5" by the general principle above. Similarly, if you have a subroutine call, then parentheses around its arguments don't really contribute anything -- the parser already knows that the list of zero or more comma-separated expressions following the identifier must be arguments. So, again, the parens are optional. > It seems to me that the cost of this is that using functions > as first-class objects takes a major usability hit. That's true. Use of functions in this way is much less common in RB. (And RB doesn't have any equivalent of lambda functions, so the code you wrote isn't easily translatable into RB.) But I suggest that regular function calls are far more common than use of function references, even in Python. Cheers, - Joe From steve at holdenweb.com Thu Jan 22 11:11:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 11:11:35 -0500 Subject: Python Style Question In-Reply-To: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> References: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> Message-ID: K-Dawg wrote: > I am trying to become more pythonic as I learn python and get my mind > around it instead of other languages I have used. > > I have an app that has a series of classes for objects it uses. From a > style perspective, which should be done: > > Different py file for each class > > or > > One py file with all the classes > > The classes are small with a constructor and a few methods, no more than > a couple, some with just one other method. > > Which is more "pythonic"? > One .py file with all the classes. But it's also very pythonic that you have the choice, and can select the option that suits you best ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Vic.Kelson at gmail.com Thu Jan 22 11:13:49 2009 From: Vic.Kelson at gmail.com (Vic Kelson) Date: Thu, 22 Jan 2009 08:13:49 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: How about IDLE? It's a nice tool for the Python programmer. I've tried lots of IDEs, but when it comes down to it, on small-to-medium jobs I am be very productive indeed using IDLE... --v From castironpi at gmail.com Thu Jan 22 11:17:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 08:17:50 -0800 (PST) Subject: subclass PyDictObject -- any gotchas? References: <0f7edac5-c03d-4c18-adb4-015eafc8dba2@e1g2000pra.googlegroups.com> Message-ID: <1409d51b-4c0c-4933-af44-488411d687cf@s9g2000prg.googlegroups.com> On Jan 22, 7:49?am, Aaron Brady wrote: > Hello all, > > I am trying to create a mapping class similar to the base dictionary, > but with some added behaviors that affect pointers on a low level. ?I > have a bare-bones version I compiled with MinGW, and it is working! ?I > want to know if there is anything that is going to bite me later, when > I start adding real behavior: for example, times when my overrides > won't get called, shortcuts, better macros, etc. > > Later on, I will be altering the 'ma_table' field from one call to > another, overriding most of PyDict_Type's methods with before-and- > after code, adding synchronization, and copying-and-pasting memory > allocation code from 'dictobject.c' directly in, since I need the > object to be at specific addresses. ?Anything I need to beware of? > Any reason it might be infeasible? > > 108 lines, please snip on reply. I would also like to know if there is any chance my subclass can use the native garbage collection. For instance, if I could write my own PyObject_MALLOC, then I could use _PyObject_GC_New. It doesn't look promising, since the stuff is all so hard-coded. For instance, '_PyObject_GC_Malloc' uses some module-level variables that make it impossible to duplicate the code, since they are out of scope from my code. What do you think? Is it possible? From morse at edoug.org Thu Jan 22 11:19:27 2009 From: morse at edoug.org (Doug Morse) Date: Thu, 22 Jan 2009 16:19:27 +0000 (UTC) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson wrote: > > > How about IDLE? It's a nice tool for the Python programmer. I've tried > lots of IDEs, but when it comes down to it, on small-to-medium jobs I > am be very productive indeed using IDLE... > > --v I find Stani's Python Editor (SPE) also good for small to medium jobs, and I think that it might achieve many of the OP's objectives. From steve at holdenweb.com Thu Jan 22 11:27:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 11:27:22 -0500 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: Doug Morse wrote: > On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson > wrote: >> >> How about IDLE? It's a nice tool for the Python programmer. I've tried >> lots of IDEs, but when it comes down to it, on small-to-medium jobs I >> am be very productive indeed using IDLE... >> >> --v > > I find Stani's Python Editor (SPE) also good for small to medium jobs, and I > think that it might achieve many of the OP's objectives. > If you just want something small and Python-specific then DrPython is also a reasonable choice. It uses the Scintilla editor component that is also used by Scite, another possibility (though personally I find the bare Scite editor just a little too tweaky to configure). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From eduardo.padoan at gmail.com Thu Jan 22 11:31:56 2009 From: eduardo.padoan at gmail.com (Eduardo O. Padoan) Date: Thu, 22 Jan 2009 14:31:56 -0200 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: On Thu, Jan 22, 2009 at 7:10 AM, wrote: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. You are almost *describing* reinteract: http://blog.fishsoup.net/2007/11/10/reinteract-better-interactive-python/ It is a mix of a shell and an editor, that lets you go back and rewirte history, and execute it again. It is GTK+, and you can write plugins to plot graphics or display html, for example. -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky From tjreedy at udel.edu Thu Jan 22 11:47:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 11:47:19 -0500 Subject: Python Style Question In-Reply-To: References: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> Message-ID: Steve Holden wrote: > K-Dawg wrote: >> I am trying to become more pythonic as I learn python and get my mind >> around it instead of other languages I have used. >> >> I have an app that has a series of classes for objects it uses. From a >> style perspective, which should be done: >> >> Different py file for each class Python is not Java! >> >> or >> >> One py file with all the classes >> >> The classes are small with a constructor and a few methods, no more than >> a couple, some with just one other method. Or if that gets to be too much, a few files each with several related classes. >> Which is more "pythonic"? >> > One .py file with all the classes. But it's also very pythonic that you > have the choice, and can select the option that suits you best ;-) Nice put Steve. tjr From tjreedy at udel.edu Thu Jan 22 11:52:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 11:52:44 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > > > On Thu, Jan 22, 2009 at 1:16 AM, Aahz > wrote: > > In article >, > Brendan Miller > wrote: > > > >PEP 8 doesn't mention anything about using all caps to indicate a > constant. > > Now it does! See > http://www.python.org/dev/peps/pep-0008/ > > Thanks for bringing this up! > > > Since the constants in the std lib (like math.pi and math.e) no longer > follow PEP 8, should we expect them to change at some point in the future? They are natural rather than arbitrary constants that I usually see in caps, so I could see them as being in a different subcategory. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 11:56:31 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 16:56:31 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> Message-ID: <01889b97$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: >> >>> Steven D'Aprano a ?crit : >>>> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >>>> >>>>> Russ P. a ?crit : >>>>> (snip) >>>>>> In any case, I have suggested that Python should perhaps get a new >>>>>> keyword, "private" or "priv". >>>>> And quite a few people - most of them using Python daily - answered >>>>> they didn't wan't it. >>>> Then they don't have to use it. >>> Yes they would. Because this would become the official way to tell >>> what's interface and what's implementation, and *this* is the >>> important point. >> >> But if you have free access to attributes, then *everything* is >> interface. >> >> > Nope. How could anyone fail to be convinced by an argument that detailed and carefully reasoned? >>>> Lots of people think that double-underscore name mangling is a waste >>>> of time: not strict enough to be useful, not open enough to be >>>> Pythonic. Solution? Don't use double-underscore names. >>> The name-mangling mechanism is actually useful when you want to make >>> sure some vital implementation attribute (usually of a class intented >>> to be extended by the library users) won't be *accidentally* >>> overwritten. >> >> Except it doesn't. > > Except it works for all real-life code I've ever seen. > > (snip convoluted counter-example) "Convoluted"? It was subclassing from a class that itself was a subclass. This happens very frequently. The only thing that was a tiny bit unusual was a conjunction of two accidental name clashes: the subclass happened to accidentally have the same name as one of the superclasses, and both of them happened to have a double-underscore attribute. > Steven, sorry for being so pragmatic, but the fact is that, from > experience (not only mine - I'm talking about thousands of man/year > experience), it JustWork(tm). Double-underscore names are great for preventing name clashes, until it doesn't. This isn't something new. Others have pointed out this failure mode, including the Timbot: http://mail.python.org/pipermail/python-dev/2005-December/058563.html I think the attitude towards __names illustrates a huge gulf between two ways of programming. One school of thought tries to write programs that can't fail, and considers failure modes to be bugs to be fixed. The other school of thought tries to write programs that won't fail until something unusual or unexpected happens, and behaves as if the answer to failure modes is "if the function breaks when you do that, then don't do that". Name mangling belongs in the second category. The Python standard library has a split personality in that the parts of it written in C are written so they can't fail, as much as humanly possible. Good luck trying to get list.append() to unexpectedly fail. But the parts written in Python are built to a much lower standard. Look how easy it is to create an object with a ticking time bomb waiting to go off at some later date: >>> from ConfigParser import ConfigParser >>> config = ConfigParser({'a':1}) You've successfully created a ConfigParser object. You'd expect it should be safe to work with now: you haven't messed with any internals or done anything strange, you've just given it a default value. But then, much later: >>> config.get('DEFAULT', 'a') # or any section without option 'a' Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/ConfigParser.py", line 545, in get return self._interpolate(section, option, value, d) File "/usr/local/lib/python2.6/ConfigParser.py", line 585, in _interpolate if "%(" in value: TypeError: argument of type 'int' is not iterable In stricter languages, particularly code with static type checking, the attitude is "you must only provide input that meets these pre- conditions". (Often one pre-condition will be the argument type.) But in Python, the attitude is "you can provide any input you like, but if it fails, don't blame me". -- Steven From rridge at csclub.uwaterloo.ca Thu Jan 22 12:01:47 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 22 Jan 2009 12:01:47 -0500 Subject: what's the point of rpython? References: <7xab9kc99i.fsf@ruckus.brouhaha.com> Message-ID: Ross Ridge writes: > The same cache coherency mechanism that prevents ordinary "unlocked" > instructions from simulanteously modifying the same cache line on > two different processors also provides the guarantee with "locked" > instructions. There's no additional hardware locks involved, and no > additional communication required. Paul Rubin wrote: >The cache coherency mechanism is what Scott described as >"communicat[ing] to other processors that it (and it alone) owns the >increment target". The cache coherency mechanism is not a trivial >thing at all. It introduces its own hazards and delays, and it is >getting more complicated all the time as processors and caches get >faster and larger. *sigh* Could you please just read what I wrote above? The LOCK prefix makes NO DIFFERENCE to anything you mentioned. When current CPython implementation increments a referernce count, it doesn't use the LOCK prefix, but the cache line modified by the instruction still has to be owned by the processor. If it did use the LOCK prefix there would be no change in how how the cache coherency mechanism worked. There'd be no additional complications, hazards or delays in how the processor communicates with other processors. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From tjreedy at udel.edu Thu Jan 22 12:03:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 12:03:53 -0500 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: Steve Holden wrote: > Doug Morse wrote: >> On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson >> wrote: >>> How about IDLE? It's a nice tool for the Python programmer. I've tried >>> lots of IDEs, but when it comes down to it, on small-to-medium jobs I >>> am be very productive indeed using IDLE... Since I currently only program in Python, IDLE does fine for me. Write code, hit F5. If the result is not right, maybe type a few interactive lines to get more info before going back to the edit window. Maybe someday I will look to see what alternatives such as below offer, but if they do not put me in an interactive interpreter or imitation thereof, like IDLE, to do post-mortem examination in, I would not likely switch. >> I find Stani's Python Editor (SPE) also good for small to medium jobs, and I >> think that it might achieve many of the OP's objectives. >> > If you just want something small and Python-specific then DrPython is > also a reasonable choice. It uses the Scintilla editor component that is > also used by Scite, another possibility (though personally I find the > bare Scite editor just a little too tweaky to configure). tjr From vinay_sajip at yahoo.co.uk Thu Jan 22 12:25:56 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 22 Jan 2009 09:25:56 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: On Jan 22, 3:40 pm, koranthala wrote: > Thank you very much Vinay. You have been extremely helpful. > This was my first design - but then I found that log system was taking > up quite a huge chunk of the memory. > That is why I went to rotating file handler. Using just plain FileHandler takes up less memory than using RotatingFileHandler (because using the latter imports the "handlers" module into memory, whereas using the former does not). I'm not aware of any problem where logging takes up a huge chunk of memory (under normal usage) - how did you measure the memory usage which was due to logging? > Anyways, now I have modified doRollover to append if file is there, > so, for me it is working. > What I was thinking was such an option in the basicloggingsystem > might be of good help. The solution I suggested is IMO better than using a patched RotatiingFileHandler, both because it avoids importing an extra module (if memory really is a concern) and because you don't need to change your code across Python version updates. How does my suggestion to use FileHandler not meet your use case? > Again, Vinay, Thank you very much. You were extremely helpful. You're welcome. Best wishes, Vinay Sajip From python at rcn.com Thu Jan 22 13:11:37 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 10:11:37 -0800 (PST) Subject: Counter Class -- Bag/Multiset Message-ID: The collections module in Python 2.7 and Python 3.1 has gotten a new Counter class that works like bags and multisets in other languages. I've adapted it for Python2.5/2.6 so people can start using it right away: http://docs.python.org/dev/library/collections.html#counter-objects Here's a link to the docs for the new class: http://code.activestate.com/recipes/576611/ Raymond From python at rcn.com Thu Jan 22 13:36:24 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 10:36:24 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: > I've adapted it for Python2.5/2.6 so people can start using it right > away: That should just be Python2.6. From bearophileHUGS at lycos.com Thu Jan 22 14:01:15 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 11:01:15 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> Eduardo O. Padoan: > You are almost *describing* reinteract: - Thank you for the link and the software, I have not tried it yet, but from the screencast it looks quite nice. - I am glad that there are people that don't think that Emacs is (despite being good) the alpha and omega of editing. There's space for other ideas beside Emacs. - Maybe I was describing reinteract there, but that's only the first part of my post :-) - I can see that reinteract is based on a interaction style quite similar to the shell of Mathematica. I was talking about something different, and more similar to TextCalc, but in the end I think reinteract may be good enough for my purposes, so I'll try to run it. And I may be happy enough. - Eventually I may find the time and will to create my "interactive python text" :-) I think there's space for many different solutions. - Despite many years of experiments, development, shells, editors, and the like, I am sure there are other designs not yet tried or not common enough yet (beside the normal editors, shells, smart object- oriented graphical shells like hotwire shell, Resolver One, and few other weird things, like one where you can zoom text and images at different scales, other text-based systems, etc). Bye, bearophile From mdw at distorted.org.uk Thu Jan 22 14:10:05 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 19:10:05 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >> Steven D'Aprano a ?crit : >>> But if you have free access to attributes, then *everything* is >>> interface. >> >> Nope. > > How could anyone fail to be convinced by an argument that detailed and > carefully reasoned? Well, your claim /was/ just wrong. But if you want to play dumb: the interface is what's documented as being the interface. You can tell that your claim is simply wrong by pushing it the other way. If everything you have free access to is interface then all behaviour observable by messing with the things you have access to is fair game: you can rely on cmp returning one of {-1, 0, 1} on integer arguments, for example. But no: the Library Reference says only that it returns a negative, zero or positive integer, and /that/ defines the interface. Everything else is idiosyncrasy of the implementation, allowed to change at whim. >>>> from ConfigParser import ConfigParser >>>> config = ConfigParser({'a':1}) [...] > File "/usr/local/lib/python2.6/ConfigParser.py", line 585, in > _interpolate > if "%(" in value: > TypeError: argument of type 'int' is not iterable I'd say that this is a bug. The Library Reference says (9.2): : `ConfigParser([defaults])' : Derived class of `RawConfigParser' that implements the magical : interpolation feature and adds optional arguments to the `get()' : and `items()' methods. The values in DEFAULTS must be : appropriate for the `%()s' string interpolation. Note that : __NAME__ is an intrinsic default; its value is the section name, : and will override any value provided in DEFAULTS. The value 1 is certainly appropriate for `%()s' interpolation: In [5]: '%(foo)s' % {'foo': 1} Out[5]: '1' so you've satisfied the documented preconditions. > In stricter languages, particularly code with static type checking, > the attitude is "you must only provide input that meets these pre- > conditions". You did that. It failed anyway. Therefore it's broken. Report a bug. -- [mdw] From deets at nospam.web.de Thu Jan 22 14:40:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 20:40:38 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: <6ts0dnFc9s0qU1@mid.uni-berlin.de> Rob Williscroft schrieb: > Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in > comp.lang.python: > >>> 2) create a localhost web server, for the client side manipulation. >>> Then have your remote webserver render a form that posts via >>> javavscript to the localhost webserver. The localhost server would >>> post back in the same way. >> AFAIK the JS security model prevents that. >> > > Are you thinking of frames?, or the way IE 7 complains about > runnning javavscript (though it bizzarly calls it an "running > an ActiveX control" )?. Before posting, I tried a jQuery-ajax-call inside Firebug from some random site to google. It bailed out with a security execption. And I found this: """ The Same-Origin Policy The primary JavaScript security policy is the same-origin policy. The same-origin policy prevents scripts loaded from one Web site from getting or setting properties of a document loaded from a different site. This policy prevents hostile code from one site from "taking over" or manipulating documents from another. Without it, JavaScript from a hostile site could do any number of undesirable things such as snoop keypresses while you?re logging in to a site in a different window, wait for you to go to your online banking site and insert spurious transactions, steal login cookies from other domains, and so on. """ http://www.windowsitlibrary.com/Content/1160/22/1.html Now there might be ways around this - but these sure are hacky, and not exactly the thing to look after. Diez From jeff at jmcneil.net Thu Jan 22 14:47:05 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 22 Jan 2009 11:47:05 -0800 (PST) Subject: Executing previous stack frame References: Message-ID: <55769671-b772-48f4-9708-5e007965bbe5@f40g2000pri.googlegroups.com> On Jan 22, 9:49 am, sturlamolden wrote: > frame = sys._getframe().f_back is the previous stack frame. Is there > any way to execute (with exec or eval) frame.f_code beginning from > frame.f_lasti or frame.f_lineno? > > I am trying to spawn a thread that is initialized with the code and > state of the previous stack frame. > > S.M. What are you trying to accomplish? While it's possible to do, I can't believe it's going to be very safe. Note that I'd never even consider doing anything like this for anything of real consequence. That said, it was kind of fun to figure out just for academic purposes... import sys import types import threading def do_something_we_should_not_do(): back = sys._getframe().f_back code_object = back.f_code # Skip CALL_FUNCTION & POP_TOP, otherwise we create # a loop. code = code_object.co_code[back.f_lasti+4:] def tmain(): c = types.CodeType(code_object.co_argcount, code_object.co_nlocals, code_object.co_stacksize, code_object.co_flags, code, code_object.co_consts, code_object.co_names, code_object.co_varnames, code_object.co_filename, code_object.co_name, code_object.co_firstlineno, code_object.co_lnotab) exec c in globals() threading.Thread(target=tmain).start() do_something_we_should_not_do() # Anything below here will run in both threads. print threading.current_thread() Thanks, Jeff mcjeff.blogspot.com From proteusguy at gmail.com Thu Jan 22 15:26:03 2009 From: proteusguy at gmail.com (proteusguy at gmail.com) Date: Thu, 22 Jan 2009 12:26:03 -0800 (PST) Subject: Dealing with large memory under linux or How to Build 64bit Python Message-ID: I've got an Ubuntu (2.6.27-9-server SMP i686 GNU/Linux) setup with 6GB RAM running python 2.5. I'm running a simulation program that is breaking as soon as it hits ~3GB RAM even though I have plenty of RAM free. I'm guessing that it's because my python is only 32-bit? Appreciate any pointers on how to get my app to be capable of using the full amount of RAM. I'm anticipating this may require me to rebuild python from scratch for 64bits but I can't find instructions on how to do that. Appreciate any help in this matter. -- Ben Scherrey From martin at v.loewis.de Thu Jan 22 15:30:30 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 22 Jan 2009 21:30:30 +0100 Subject: Dealing with large memory under linux or How to Build 64bit Python In-Reply-To: References: Message-ID: <4978D766.4010906@v.loewis.de> > I've got an Ubuntu (2.6.27-9-server SMP i686 GNU/Linux) setup with > 6GB RAM running python 2.5. I'm running a simulation program that is > breaking as soon as it hits ~3GB RAM even though I have plenty of RAM > free. I'm guessing that it's because my python is only 32-bit? If you do use a 32-bit python, then yes, that's the reason. > Appreciate any pointers on how to get my app to be capable of using > the full amount of RAM. I'm anticipating this may require me to > rebuild python from scratch for 64bits but I can't find instructions > on how to do that. As a starting point, you need to install a 64-bit operating system. If you are running a 32-bit kernel, then there is *no way* that you could possibly run a 64-bit Python on it. When you do install a 64-bit (i.e. AMD64) version of Ubuntu, it will come with a 64-bit Python executable, so no need to build Python at all. If you still wish to rebuild Python, then, on the 64-bit Ubuntu, the standard configure;make;make install will do the trick. Regards, Martin From Scott.Daniels at Acm.Org Thu Jan 22 15:32:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 22 Jan 2009 12:32:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: Tim Rowe wrote: >> Btw, the correctness of a program (on a turing-complete language) cannot be >> statically proven. Ask Turing about it. > > For the most safety critical of programmes, for which static proof is > required, restrictions are placed on the use of the language that > effectively mean that it is not Turing-complete. Specifically, all > loops that are required to terminate require a loop variant to be > defined. Typically the loop variant is a finite non-negative integer > that provably decreases on every pass of the loop, which makes halting > decidable. Having once been a more type-A, I labored for a couple of years trying to build a restricted language that provably terminated for work on an object-oriented database research. I finally gave it up as a bad idea, because, in practice, we don't care if a loop will terminate or not in database work; a transaction that takes a year to commit is equivalent to an infinite loop for all applications that I have interacted with (and yes, I have worked allowing four day transactions to commit). --Scott David Daniels Scott.Daniels at Acm.Org From python at rcn.com Thu Jan 22 15:41:13 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 12:41:13 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <7eb38a4d-18fa-4542-8eb2-8910bd75b7ec@r41g2000prr.googlegroups.com> > That should just be Python2.6. Fixed. Now runs of Python 2.5 as well. From BrianVanderburg2 at aim.com Thu Jan 22 15:47:46 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 15:47:46 -0500 Subject: USB in python In-Reply-To: <49782285.9010509@al.com.au> References: <49782285.9010509@al.com.au> Message-ID: <4978DB72.6090307@aim.com> astan.chee at al.com.au wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of > using python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V > (or similar to whatever the power pin is getting). Now I'm confused to > if the software to activate this can actually be written and how do I > do it? Any examples? I've seen pyUSB but it doesn't give me control > over the hardware and how much power is going through the data pins. > Thanks for any help. > Cheers > Astan > -- > http://mail.python.org/mailman/listinfo/python-list I don't think you can actually control the USB port's data lines like this. I've been searching for some ideas as well for some small hobbyist projects I'm thinking about, and it seems that either the EZUSB chip or maybe even easier the FTDI chips might be the way to go. I think the FTDI chip is basically a USB-to-RS232 converter and there is a libftdi that is built on top of libusb I think. Anyway for my design (if I ever get around to it) I'm going to create a library in C that uses the hardware and then I can create a Python wrapper around that library. Brian Vanderburg II From BrianVanderburg2 at aim.com Thu Jan 22 15:55:10 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 15:55:10 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: <4978DD2E.1090008@aim.com> bockman at virgilio.it wrote: > Constants would be a nice addition in python, sure enough. > But I'm not sure that this can be done without a run-time check every time > the constant is used, and python is already slow enough. Maybe a check > that is disabled when running with optimizing flags ? > > But I'm sure this discussion has been already made and the FINAL WORD has > been already spoken. > > Ciao > ---- > FB > -- > http://mail.python.org/mailman/listinfo/python-list > One idea to make constants possible would be to extend properties to be able to exist at the module level as well as the class level: @property def pi(): return 3.14159..... print(pi) # prints 3.14159.... pi=32 # Raise an error Cannot set attribute ... Brian Vanderburg II From mdw at distorted.org.uk Thu Jan 22 15:59:37 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 20:59:37 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> <7xocy0ukau.fsf@ruckus.brouhaha.com> <49784295$0$15148$426a74cc@news.free.fr> Message-ID: <874ozrdpl2.fsf.mdw@metalzone.distorted.org.uk> Bruno Desthuilliers writes: > Paul Rubin a ?crit : >> I'd say that Python's FP characteristics are an important part of its >> expressiveness. > > Indeed - but they do not make Python a functional language[1]. Python is > based on objects, not on functions, I'd have a good go at defining a functional language as one which treats functions as first-class objects -- i.e., can be passed as arguments, returned as results, stored in data structures, etc. In that regard, Python is a proper paid-up functional programming language. It's not a /pure/ language -- i.e., there are side effects -- but ML has those too and it's widely considered functional; and it's not lazily evaluated -- but again neither is ML. -- [mdw] From sturlamolden at yahoo.no Thu Jan 22 16:16:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 22 Jan 2009 13:16:29 -0800 (PST) Subject: Executing previous stack frame References: <55769671-b772-48f4-9708-5e007965bbe5@f40g2000pri.googlegroups.com> Message-ID: On Jan 22, 8:47 pm, Jeff McNeil wrote: > What are you trying to accomplish? On Jan 22, 8:47 pm, Jeff McNeil wrote: > What are you trying to accomplish? While it's possible to do, I can't > believe it's going to be very safe. I am trying to implement a completely new concurrency abstraction for Python. It is modeled on OpenMP instead of Java threads (cf. threading and multiprocessing). I am planning to use thread and multiprocessing (or os.fork) as backends. Doing this with os.fork is child's play, but it would not work on Windows. I believe Python context managers are excellent for this purpose. I believe the OpenMP way of doing concurrency fits better with the mind than Java threading, and thus are more pythonic. Algorithms can be written as sequential, and transformed to parallel code with the simple insertion of a few directives. It makes debugging easier, because one can debug the sequential code, and it makes it easier to avoid the problems with deadlocks, race conditions, livelocks, etc. Just ask any C or Fortran programmer how much easier it is to use OpenMP instead of Win32 or Posix threads. What I have in mind is an API that would look approximately like this (OpenMP pragmas for C on top, proposed Python equivalent below): #pragma omp parallel with Pool() as pool: #pragma omp for for item in pool.parallel(): #pragma omp for shedule(guided) for item in pool.parallel(, shed='guided'): #pragma omp parallel for with Pool() as pool: for item in pool.parallel(): #pragma omp barrier pool.barrier() #pragma omp section with pool.section(): #pragma omp parallel sections with Pool() as pool: with pool.section(): fun1(*args, **kwargs) with pool.section(): fun2(*args, **kwargs) #pragma omp master if pool.master: #pragma omp critical #pragma omp atomic with pool.lock: #pragma omp single with pool.single(): #pragma omp ordered with ordered(k): Here is a toy example of what I have in mind. Say you would want to compute the DFT of some signal (real apps would use an FFT in C for this, but never mind that). In Python using an O(n**2) algorithm, this would look like something like this: def real_dft(x): ''' DFT for a real valued sequence x ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 for n in range(M): s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) r.append(s) return r Then, one could 'magically' transform this algorithm into to a parallel one simply by inserting directives from the 'OpenMP' module: def real_dft(x): ''' DFT for a real valued sequence x ''' ''' parallelized ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 with Pool() as pool: parallel_iter = pool.parallel(range(M)): for n in parallel_iter: s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) with parallel_iter.ordered(n): r.append(s) return r The idea is that 'parallelizing' a sequential algorithm like this is much easier than writing a parallel one from scratch using the abstractions in threading or multiprocessing. The problem is that the __enter__ method of the Pool object (the context manager) must spawn multiple threads, each executing sys._getframe().f_back, because the 'with Pool() as pool:' should be executed by multiple threads in parallel. These slave threads will be killed when they enter the __exit__ method of its context manager. Most of this OpenMP API has already been implemented. I just need the machinery to make the slave threads come alive :) I'll take a look at your code now :) Regards, Sturla Molden From rtw at freenet.co.uk Thu Jan 22 16:37:44 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 22 Jan 2009 15:37:44 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6tr453Fca5h6U1@mid.individual.net> Message-ID: Thomas Guettler wrote in news:6tr453Fca5h6U1 at mid.individual.net in comp.lang.python: > Diez B. Roggisch schrieb: >> >>> 2) create a localhost web server, for the client side manipulation. >>> Then have your remote webserver render a form that posts via >>> javavscript to the localhost webserver. The localhost server would >>> post back in >>> the same way. >> >> AFAIK the JS security model prevents that. > > A page requested from "http://myintranetserver/" can redirect to > "http://localhost:myport/myapp/?foo=..." > > this would work. > > But how should the web server at localhost be started? You need to > write a Windows service. Since there will be only one client a regular programme should be fine. > I guess that's not very easy, since I am not > used to windows programming. Then don't do any (windows programming), do Python: http://docs.python.org/3.0/library/wsgiref.html#module- wsgiref.simple_server http://docs.python.org/3.0/library/cgi.html#functions Rob. -- http://www.victim-prime.dsl.pipex.com/ From kyrie at uh.cu Thu Jan 22 16:48:07 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Thu, 22 Jan 2009 16:48:07 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01886bdd$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> Message-ID: <200901221648.07591.kyrie@uh.cu> On Thursday 22 January 2009 08:32:51 am Steven D'Aprano wrote: > And now I have accidentally broken the spam() method, due to a name clash. True, that's bad. I wish that were 'fixed'. > Besides, double-underscore names are a PITA to work with: Isn't that example the point of having self.__private variables? To make sure that the Parrot.__private attributes don't clash with the RedParrot.__private attributes with the same name? [parrot example follows just for context, but my reply ends here] > >>> class Parrot(object): > > ... ? ? __colour = 'blue' > ... ? ? def __str__(self): > ... ? ? ? ? return 'A %s parrot' % self.__colour > ... ? ? __repr__ = __str__ > ... > > >>> class RedParrot(Parrot): # Just like Parrot, only red. > > ... ? ? __colour = 'red' > ... > > >>> Parrot() > > A blue parrot > > >>> RedParrot() > > A blue parrot -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From gagsl-py2 at yahoo.com.ar Thu Jan 22 16:49:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 19:49:38 -0200 Subject: Mechanize hanging References: <5caea3690901211721s35c9e39enb1f3df12b0a0479c@mail.gmail.com> Message-ID: En Wed, 21 Jan 2009 23:21:06 -0200, K-Dawg escribi?: > I am trying to use mechanize to connect and log into Yahoo! > > Here is my code: > > #c:\Python25\python > import re > import urllib > import urllib2 > import mechanize > > print "print1" > br = mechanize.Browser() > br.set_handle_robots(False) > br.open("https://login.yahoo.com/config/login?") > > It is hanging at the open. Eventually I have to just kill it and I get > this: Sockets are blocking by default - and never time out. See if mechanize has some way to set a timeout - otherwise you may try the code below, before anything else: socket.setdefaulttimeout(60) -- Gabriel Genellina From rtw at freenet.co.uk Thu Jan 22 16:59:22 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 22 Jan 2009 15:59:22 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6ts0dnFc9s0qU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote in news:6ts0dnFc9s0qU1 at mid.uni-berlin.de in comp.lang.python: > Rob Williscroft schrieb: >> Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in >> comp.lang.python: >> >>>> 2) create a localhost web server, for the client side manipulation. >>>> Then have your remote webserver render a form that posts via >>>> javavscript to the localhost webserver. The localhost server would >>>> post back in the same way. >>> AFAIK the JS security model prevents that. >>> >> >> Are you thinking of frames?, or the way IE 7 complains about >> runnning javavscript (though it bizzarly calls it an "running >> an ActiveX control" )?. > > Before posting, I tried a jQuery-ajax-call inside Firebug from some > random site to google. It bailed out with a security execption. Yes the XMLHttpRequest object only allows you to make requests to the same domain as the page came from. Here is a concrete example of what I suggested:
I.e. 1 line of JS that is manipulating the document of the page it belongs to. > > And I found this: > > """ > > The Same-Origin Policy > The primary JavaScript security policy is the same-origin policy. The > same-origin policy prevents scripts loaded from one Web site from > getting or setting properties of a document loaded from a different > site. This policy prevents hostile code from one site from "taking > over" or manipulating documents from another. Without it, JavaScript > from a hostile site could do any number of undesirable things such as > snoop keypresses while you???re logging in to a site in a different > window, wait for you to go to your online banking site and insert > spurious transactions, steal login cookies from other domains, and so > on. """ > > http://www.windowsitlibrary.com/Content/1160/22/1.html > > Now there might be ways around this - but these sure are hacky, and > not exactly the thing to look after. That is scripting across frames (or windows), where the frames have a different origin (from different domain). As an aside if the OP's app' can live with sending at most about 1KB of ascii back and forth then using a HTTP redirect header is another option. Rob. -- http://www.victim-prime.dsl.pipex.com/ From BrianVanderburg2 at aim.com Thu Jan 22 17:00:46 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 17:00:46 -0500 Subject: Idea to support public/private. Message-ID: <4978EC8E.6080904@aim.com> Okay so I don't really care about public/private but I was watching the lists (Does python follow its idea of readability or something like that) and I thought of a 'possible' way to add this support to the language. I have implemented a class which allows creating both a private as well as a protected member, only it is currently a bit of work. It could perhaps be reworked into decorators. import sys import inspect def get_private_codes(class_): codes = [] for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes def get_protected_codes(class_, codes=None): if codes is None: codes = [] for i in class_.__bases__: get_protected_codes(i, codes) for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes class Test(object): def __init__(self): self.protected = 45 self.private = 34 def setprotected(self, value): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): self.__protect_value_ZR20 = value else: raise "Protected Write Error" def getprotected(self): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): return self.__protect_value_ZR20 else: raise "Protected Read Error" protected = property(getprotected, setprotected) def setprivate(self, value): frame = sys._getframe(1) if frame.f_code in get_private_codes(self.__class__): self.__private_value_ZR20 = value else: raise "Private Write Error" def getprivate(self): frame = sys._getframe(1) if frame.f_code in get_private_codes(self.__class__): return self.__private_value_ZR20 else: raise "Private Read Error" private = property(getprivate, setprivate) class Test2(Test): def __init__(self): self.protected = 1 a=Test() b=Test2() #print a.private #a.private = 1 #print a.protected #a.protected = 1 From gagsl-py2 at yahoo.com.ar Thu Jan 22 17:01:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:01:44 -0200 Subject: One Bug of Python 3.0 References: Message-ID: En Fri, 16 Jan 2009 01:56:23 -0200, escribiste en el grupo gmane.comp.python.general > I met a bug of CGIXMLRPCRequestHandler in Python3.0. Because of the bug, > couldn't use RPC in Apache CGI. You should file a bug report at http://bugs.python.org -- Gabriel Genellina From toby at tobiah.org Thu Jan 22 17:04:15 2009 From: toby at tobiah.org (Tobiah) Date: Thu, 22 Jan 2009 14:04:15 -0800 Subject: unzip array of arrays? Message-ID: Although it's trivial to program, I wondered whether there was a builtin or particularly concise way to express this idea: > a = [(1, 2), (3, 4), (5, 6)] > field[a, 2] [2, 4, 6] where field() is some made up function. Thanks, Toby From invalid at invalid Thu Jan 22 17:12:38 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 22 Jan 2009 16:12:38 -0600 Subject: unzip array of arrays? References: Message-ID: On 2009-01-22, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. The above example is a great application for numpy's array type: http://numpy.scipy.org/ Here's an example showing how you extract a column using indexing operations: http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c [I assume numpy is still the numerical/array package du jour?] -- Grant Edwards grante Yow! WHO sees a BEACH BUNNY at sobbing on a SHAG RUG?! visi.com From clp2 at rebertia.com Thu Jan 22 17:13:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 14:13:34 -0800 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: <50697b2c0901221413l6deee1ack83b693134623b30@mail.gmail.com> On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) [GCC 4.0.1 (Apple Inc. build 5484)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a= [(1, 2), (3, 4), (5, 6)] >>> zip(*a) [(1, 3, 5), (2, 4, 6)] >>> zip(*a)[1] (2, 4, 6) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rt8396 at gmail.com Thu Jan 22 17:15:22 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 14:15:22 -0800 (PST) Subject: Find all available Tkinter cursor names? Message-ID: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> Anybody know how to find all the available Tkinter cursor icon names, or where the icons are stored? like "paintbrush" "pencil" etc... From BrianVanderburg2 at aim.com Thu Jan 22 17:16:13 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 17:16:13 -0500 Subject: Idea to support public/private. In-Reply-To: <4978EC8E.6080904@aim.com> References: <4978EC8E.6080904@aim.com> Message-ID: <4978F02D.1080401@aim.com> There was a small error in setprivate/getprivate: import sys import inspect def get_private_codes(class_): codes = [] for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes def get_protected_codes(class_, codes=None): if codes is None: codes = [] for i in class_.__bases__: get_protected_codes(i, codes) for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes class Test(object): def __init__(self): self.protected = 45 self.private = 34 def setprotected(self, value): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): self.__protect_value_ZR20 = value else: raise "Protected Write Error" def getprotected(self): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): return self.__protect_value_ZR20 else: raise "Protected Read Error" protected = property(getprotected, setprotected) def setprivate(self, value): frame = sys._getframe(1) if frame.f_code in get_private_codes(Test): self.__private_value_ZR20 = value else: raise "Private Write Error" def getprivate(self): frame = sys._getframe(1) if frame.f_code in get_private_codes(Test): return self.__private_value_ZR20 else: raise "Private Read Error" private = property(getprivate, setprivate) class Test2(Test): def __init__(self): self.protected = 1 self.private = 1 a=Test() b=Test2() #print a.private #a.private = 1 #print a.protected #a.protected = 1 From gagsl-py2 at yahoo.com.ar Thu Jan 22 17:17:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:17:22 -0200 Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> Message-ID: En Wed, 21 Jan 2009 08:50:53 -0200, mynthon escribi?: > I have very long path on windows and i get error when try to get > modification time. So i tried do chdir path and then get file. It now > gives me error that file doesn't exists [...] > it works for other files so i suppose it is not my fault. I know there > is a win32 module but i can't find any documentation for it (what is > the purpose to create app without docs?). Any idea? win32api is part of the pywin32 package, available at http://pywin32.sf.net This is not a Python standard package - you either installed it yourself some time ago (and forgot about it) or perhaps you're using the Enthought bundle (which includes pywin32 and PythonWin). Either way, you surely have the PyWin32.chm help file installed too. En Wed, 21 Jan 2009 12:11:03 -0200, mynthon escribi?: > you can also use \\?\ prefix but ONLY FOR unicode strings > > os.path.getmtime("\\\\?\\c:\\very lon path\\blablabla") #will not work > os.path.getmtime(u"\\\\?\\c:\\very lon path\\blablabla") #will work Looks like you found the "official" answer to your problem. Notice that the path must be "normalized" in this case - that means, it must not contain "." nor ".." components. -- Gabriel Genellina From lenz at joinville.udesc.br Thu Jan 22 17:34:11 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Thu, 22 Jan 2009 14:34:11 -0800 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <200901221434.12003.lenz@joinville.udesc.br> On Thursday 22 January 2009 08:13:49 Vic Kelson wrote: > How about IDLE? It's a nice tool for the Python programmer. I've tried > lots of IDEs, but when it comes down to it, on small-to-medium jobs I > am be very productive indeed using IDLE... > > --v > -- > http://mail.python.org/mailman/listinfo/python-list How about Eric ? -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From SabbySF at aol.com Thu Jan 22 17:48:04 2009 From: SabbySF at aol.com (SabbySF at aol.com) Date: Thu, 22 Jan 2009 17:48:04 EST Subject: To: Julian Snitow Message-ID: I got this from a website and have no idea if you will get this. Since you are in charge of Anime at Boskone 46, do you know when the schedule will be published on line.For the last two years the Anime schedule was not published on line and that meant I could not do research on anime that I was unfamilier with. Thank you for any help you can give me. **************Inauguration '09: Get complete coverage from the nation's capital. (http://news.aol.com/main/politics/inauguration?ncid=emlcntusnews00000003) -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Thu Jan 22 17:48:19 2009 From: http (Paul Rubin) Date: 22 Jan 2009 14:48:19 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6ts0dnFc9s0qU1@mid.uni-berlin.de> Message-ID: <7x7i4nrm8c.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Before posting, I tried a jQuery-ajax-call inside Firebug from some > random site to google. It bailed out with a security execption. You should be able to get around the security policy with XUL in Firefox, or with an ActiveX control in MSIE. In the Netscape Navigator era there was a security policy Java object so you could turn the security stuff on and off if the user gave permission from a pop-up dialog. I've been away from that scene for a while so I don't know if Firefox has anything like it. From ricaraoz at gmail.com Thu Jan 22 17:50:33 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 22 Jan 2009 19:50:33 -0300 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xwscnhm44.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> <7xwscnhm44.fsf@ruckus.brouhaha.com> Message-ID: <4978F839.2030205@gmail.com> Paul Rubin wrote: > Mark Wooding writes: > >> Some people (let's call them `type A programmers') have decided that >> they want to be assisted with writing correct programs... >> Other people (`type B programmers') don't like having their (apparently? >> possibly?) correct programs rejected.... >> I think trying to persuade a type A programmer that he wants to work >> like a type B programmer, or /vice versa/, is difficult, bordering on >> futile. Type A stereotypes type B as a bunch of ill-disciplined >> reckless hackers; type B stereotypes type A as killjoy disciplinarians. >> Meeting in the middle is difficult. (`We just want to add a little >> safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) >> > > That's an interesting analysis. You know, I think I'm really a type B > programmer, interested in type A techniques and tools for the same > reason someone who naturally sleeps late is interested in extra-loud > alarm clocks. > > Also, the application area matters. There is a difference between > programming for one's own enjoyment or to do a personal task, and > writing programs whose reliability or lack of it can affect other > people's lives. I've never done any safety-critical programming but I > do a fair amount of security-oriented Internet programming. As such, > I have to always assume that my programs will be attacked by people > who are smarter than I am and know more than I do. I can't possibly > out-think them. If I don't see problems in a program, it's still > plausible that someone smarter than me will spot something I missed. > Therefore, my failure to detect the presence of problems is not > reassuring. What I want is means of verifying the absence of > problems. > Mmmmm..... your "means of verifying the absence of problems" were coded/thought by some other person who also has a measurable amount of intelligence. So it follows that there will be somebody else who is smarter and will spot something this other person missed and will be able to subvert those "means". So it would seem that by thinking you can "verify" the absence of problems you are trying to get a false sense of security that actually does not exist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Jan 22 17:57:02 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 22 Jan 2009 16:57:02 -0600 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: Unknown wrote: > On 2009-01-22, Tobiah wrote: >> Although it's trivial to program, I wondered whether >> there was a builtin or particularly concise way to >> express this idea: >> >>> a = [(1, 2), (3, 4), (5, 6)] >>> field[a, 2] >> [2, 4, 6] >> >> where field() is some made up function. > > The above example is a great application for numpy's array > type: > > http://numpy.scipy.org/ > > Here's an example showing how you extract a column using > indexing operations: > > http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c > > [I assume numpy is still the numerical/array package du jour?] 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 gagsl-py2 at yahoo.com.ar Thu Jan 22 17:58:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:58:14 -0200 Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> Message-ID: En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson escribi?: > The following code uses ossaudiodev to read 1000 values from > my sound card at a rate of 12,000 samples per second: > > When I select a sample rate that is not a power of 2 times > 3000 samples/second, a strong and very regular sawtooth is > superimposed on the signal. At some sampling frequencies, > it appears as a rising sawtooth, and at other sampling > frequencies it is a declining sawtooth, so I'm presumably > lost in some aliasing wilderness. As best I can tell, > it's a 48 KHz sawtooth. That could be a hardware and/or driver limitation. By example, an AC97-compliant chipset may provide a fixed rate of 48000 samples/second -- any sample rate conversion must be done by other means, if possible at all. -- Gabriel Genellina From prologic at shortcircuit.net.au Thu Jan 22 18:11:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 09:11:33 +1000 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) In-Reply-To: <49784D83.9040207@gmail.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <49784D83.9040207@gmail.com> Message-ID: On Thu, Jan 22, 2009 at 8:42 PM, Ricardo Ar?oz wrote: (...) > What I've seen engineers do when they need extra safety is to put in place > independently developed and operated redundant systems, at least three, and > the system will do whatever two of the independent systems agree on. So I > guess if I really wanted to be safe with a system I'd have it made by at > least three different teams (yes, also the requirements should be written by > different teams) in different languages under different OS's and different > independent machines. And THEN I would have some measure of safety (and this > would certainly be more cost effective than the formal specification route). This is quite honestly the best thing I've seen written on this very topic of safety and mission critical systems! Thank you! My entire point(s) throughout this very long and tediously boring thread have been that one language over another doesn't necessarily bear much weight on the safety requirements of a system. One thing that those that have argued for Data Protection, Static Typing, Strong Typing and Stricter Encapsulation (all of which Python -IS NOT- and -WILL NOT- be); is that Safety Requirements are normally intangible, unquantifable measures. How do you rate the safety of your system ? By the number of deaths and injuries it not cause ? By the fact that your Shuttle doesn't blow up ? Your plane landing correctly ? Ricardo's point is very well put and Safety Critical systems that specify requirements, tangible and quantifiable requirements are what makes a system safe and gives assurance - not the language or the platform os the os or the environment. For example: FR1: When the landing gears button is pressed, the landing gears will be lowered and monitored and confirms by the Confirmation System and Verified by the Verification System. Have a pleasant day, cheers James From kw at codebykevin.com Thu Jan 22 18:19:52 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 22 Jan 2009 18:19:52 -0500 Subject: Find all available Tkinter cursor names? In-Reply-To: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> Message-ID: <4978FF18.7020508@codebykevin.com> r wrote: > Anybody know how to find all the available Tkinter cursor icon names, > or where the icons are stored? like "paintbrush" "pencil" etc... http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm -- Kevin Walzer Code by Kevin http://www.codebykevin.com From bj_666 at gmx.net Thu Jan 22 18:49:13 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 22 Jan 2009 23:49:13 GMT Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> Message-ID: <6tsevoFc2b1lU1@mid.uni-berlin.de> On Thu, 22 Jan 2009 04:17:57 -0800, bearophileHUGS wrote: > Ben Finney: > >> Many of us solve this by using a single full-featured programmer's >> editor that allows invoking a program +IBQ- written in any of *dozens >> or hundreds* of different languages +IBQ- from within the editor. > > I don't know what an IBQ is. +IBQ- seems to be the way your newsreader displays the dashes that where in Ben's posting. I see "em dash" characters there: In [84]: unicodedata.name(u'?') Out[84]: 'EM DASH' Ciao, Marc 'BlackJack' Rintsch From rt8396 at gmail.com Thu Jan 22 18:53:47 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 15:53:47 -0800 (PST) Subject: Find all available Tkinter cursor names? References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> Message-ID: Thanks Kevin, These are exactly the ones i already knew about. I was hoping there where more, shucks!. I wonder how i could go about making my own cursors and adding them to Tkinter? Have any ideas? From rhodri at wildebst.demon.co.uk Thu Jan 22 19:17:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 23 Jan 2009 00:17:18 -0000 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: On Thu, 22 Jan 2009 22:04:15 -0000, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. If field() already exists, there's always a list comprehension: [field(l) for l in a] If you want that specific list: >>> [l[1] for l in a] [2, 4, 6] -- Rhodri James *-* Wildebeeste Herder to the Masses From cburns4563 at gmail.com Thu Jan 22 19:45:19 2009 From: cburns4563 at gmail.com (cburns) Date: Thu, 22 Jan 2009 16:45:19 -0800 (PST) Subject: does exec ignore the locals parameter? Message-ID: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> In the code below, bar() seems to work, foo() seems broken. % python -V Python 2.6.1 % cat exec1.py def foo(i) : exec "i = i + 1" in locals(), globals() print "i=%d" % i def bar(j) : exec "j = j + 1" print "j=%d" % j foo(0) bar(0) % python exec1.py i=0 j=1 What I really wanted to do was something like: exec text in globals(), inspect.currentframe(1).f_locals but that didn't work either. Thanks, Charlie From http Thu Jan 22 20:05:12 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:05:12 -0800 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <49784D83.9040207@gmail.com> Message-ID: <7xtz7qvnlj.fsf@ruckus.brouhaha.com> James Mills writes: > Ricardo's point is very well put and Safety Critical systems > that specify requirements, tangible and quantifiable requirements > are what makes a system safe and gives assurance - not the language > or the platform os the os or the environment. But it is characteristics of the language, platform os, and environment, that make it easier or more difficult to provide high assurance that the specifications are actually met. See this article for the meaning of "high assurance": http://www.dwheeler.com/essays/high-assurance-floss.html Basically, high assurance in the view of the folks who issue specifications for it and fund it, requires a lot of static verification. From http Thu Jan 22 20:26:18 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:26:18 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: <7x3afabyo5.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > Having once been a more type-A, I labored for a couple of years trying > to build a restricted language that provably terminated for work on an > object-oriented database research. I finally gave it up as a bad idea, > because, in practice, we don't care if a loop will terminate or not in > database work; a transaction that takes a year to commit is equivalent > to an infinite loop for all applications that I have interacted with > (and yes, I have worked allowing four day transactions to commit). I think the purpose of the termination proofs is to ensure that nonterminating functions don't introduce inconsistency into the verification logic, rather than out of concern that some function might actually loop. Consider the function def f(x): return 1 + f(x) aside from the "minor" issue of infinite recursion, this is a nice, well-typed function that doesn't have any side effects, doesn't raise exceptions, etc. It is referentially transparent, so one can substitute any call to it with the value from another call to the same arg, i.e. we can substitute x=3 and deduce the equation f(3) = 1 + f(3) Subtracting f(3) from each side, we get 0 = 1, an erroneous "theorem" from which the verification system can infer all kinds of other bogus results. By requiring proof that any function purporting to return a value really DOES return a value (rather than looping, raising an exception, etc.), we get rid of this problem. The actual number of computing steps before termination isn't an issue for this purpose, as long as it is finite. From rasky at develer.com Thu Jan 22 20:41:38 2009 From: rasky at develer.com (Giovanni Bajo) Date: Fri, 23 Jan 2009 01:41:38 GMT Subject: Counter Class -- Bag/Multiset References: Message-ID: On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. > > I've adapted it for Python2.5/2.6 so people can start using it right > away: > http://docs.python.org/dev/library/collections.html#counter-objects > > Here's a link to the docs for the new class: > http://code.activestate.com/recipes/576611/ Hi Raymond, * I'm not a native speaker, but why use the word "Counter"? A "counter" to my ear sounds like a number that is increased each time an event occurs; the website counter, eg, comes to mind. I can understanda its meaning probably stretches to "an object that counts", but I really can't think of it as a group of object, or a container of object. Moreover, I find it a much more useful abstraction the idea of a "multi-set" (that is, a set where elements can appear with multiple cardinality), rather than stressing the concept of "counting" how many times each element appears in the set. * I find it *very* confusing c.items() vs c.elements(). Items and elements are synonymous (again, in my understanding of English). All in all, I think I prefer your previous bag class: http://code.activestate.com/recipes/259174/ -- Giovanni Bajo Develer S.r.l. http://www.develer.com From clp2 at rebertia.com Thu Jan 22 20:49:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 17:49:42 -0800 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: Message-ID: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: > On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: > >> The collections module in Python 2.7 and Python 3.1 has gotten a new >> Counter class that works like bags and multisets in other languages. >> >> I've adapted it for Python2.5/2.6 so people can start using it right >> away: >> http://docs.python.org/dev/library/collections.html#counter-objects >> >> Here's a link to the docs for the new class: >> http://code.activestate.com/recipes/576611/ > > Hi Raymond, > > * I'm not a native speaker, but why use the word "Counter"? A "counter" > to my ear sounds like a number that is increased each time an event > occurs; the website counter, eg, comes to mind. I can understanda its > meaning probably stretches to "an object that counts", but I really can't > think of it as a group of object, or a container of object. Moreover, I > find it a much more useful abstraction the idea of a "multi-set" (that > is, a set where elements can appear with multiple cardinality), rather > than stressing the concept of "counting" how many times each element > appears in the set. > > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). I concur and would like to say additionally that having Counter's len() be the number of *unique* items as opposed to just the number of items seems a bit counterintuitive. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From astan.chee at al.com.au Thu Jan 22 20:50:19 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 12:50:19 +1100 Subject: USB in python In-Reply-To: <6tqvb2Fcan25U1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: <4979225B.6050106@al.com.au> Diez B. Roggisch wrote: > Astan Chee wrote: > > >> Hi, >> Im trying to write a program for my USB device and I'm thinking of using >> python to do this. The USB device is of my own making and it is >> activated when one of the two data pins of the USB is given about 5V (or >> similar to whatever the power pin is getting). Now I'm confused to if >> the software to activate this can actually be written and how do I do >> it? Any examples? I've seen pyUSB but it doesn't give me control over >> the hardware and how much power is going through the data pins. >> > Unless I'm not getting something here. > > > Hi, Thanks for all the responses but I forgot to mention that I have very little hardware understanding (at least in english) and the device itself it very simple and only needs about 5V power to be active. The problem here is that I want to control when the device is active using a computer so I thought USB might be a good choice since its simple (but didn't turn out to be). I'm open to any other suggestions on how I might achieve this hardware and software-wise (as in what interface should I use, etc). Also I'm trying to stay away from (complex) micro controllers. Any ideas? Thanks again Astan From http Thu Jan 22 20:54:57 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:54:57 -0800 Subject: Counter Class -- Bag/Multiset References: Message-ID: <7xiqo64wi6.fsf@ruckus.brouhaha.com> Giovanni Bajo writes: > * I'm not a native speaker, but why use the word "Counter"? I agree with this, the new functionality is welcome but I think the traditional term "multiset" or "bag" would have been better. From bearophileHUGS at lycos.com Thu Jan 22 21:04:38 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 18:04:38 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch: > +IBQ- seems to be the way your newsreader displays the dashes that where > in Ben's posting. ?I see "em dash" characters there: I see, thank you. I never finish to see all the weird things of the Web (through google groups). Bye, bearophile From benjamin.kaplan at case.edu Thu Jan 22 21:20:33 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 22 Jan 2009 21:20:33 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: Message-ID: > Hi Raymond, > > * I'm not a native speaker, but why use the word "Counter"? A "counter" > to my ear sounds like a number that is increased each time an event > occurs; the website counter, eg, comes to mind. I can understanda its > meaning probably stretches to "an object that counts", but I really can't > think of it as a group of object, or a container of object. Moreover, I > find it a much more useful abstraction the idea of a "multi-set" (that > is, a set where elements can appear with multiple cardinality), rather > than stressing the concept of "counting" how many times each element > appears in the set. > > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). > > All in all, I think I prefer your previous bag class: > http://code.activestate.com/recipes/259174/ Well, I am a native English speaker and I agree with your points completely. Also, wouldn't it be better to either have a least_common method or allow most_common to take a negative integer rather than having to use most_common()[:-n:-1]? For a large Counter, this could take up a lot of memory. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 21:30:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 02:30:06 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <01892202$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > Steven D'Aprano writes: > >> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >>> Steven D'Aprano a ?crit : >>>> But if you have free access to attributes, then *everything* is >>>> interface. >>> >>> Nope. >> >> How could anyone fail to be convinced by an argument that detailed and >> carefully reasoned? > > Well, your claim /was/ just wrong. But if you want to play dumb: the > interface is what's documented as being the interface. But you miss my point. We're told Python doesn't have private attributes. We're told that we're allowed to "mess with the internals", we're *encouraged* to do so: Python gives you the freedom to do so, and any suggestion that freedom might be reduced even a tiny bit is fought passionately. When people ask how to implement private attributes, they're often told not to bother even using single-underscore names. When it is suggested that Python should become stricter, with enforced data hiding, the objections come thick and fast: people vehemently say that they like Python just the way it is, that they want the ability to mess with the internals. You even argued that you disliked data structures implemented in C and preferred those written in Python because you have more ability to mess with the private attributes. In context, I had just mentioned that lists' internals were inaccessible from Python code. I neglected to give an example at the time, but a good example is the current length of the list. Consider the experience of Microsoft and Apple. No matter how often they tell people not to mess with the internals, people do it anyway, and always believe that their reason is a good reason. And Python culture encourages that behaviour (albeit the consequences are milder: no buffer overflows or core dumps). Add to that the culture of Open Source that encourages reading the source code. You don't need to buy a book called "Undocumented Tips and Tricks for Python" to discover the internals. You just need to read the source code. And then you have at least two places in the standard library where _attributes are *explicitly* public: http://bugs.python.org/issue3152 Given this permissive culture, any responsible library writer must assume that if he changes his so-called "private" attributes, he will break other people's code. In principle it could break just as much code as if he didn't even bother flagging them with a leading underscore, which is probably why many people don't even bother with _names. In other words, if you make it easy for people to mess with your internals, if you have a culture that allows and even encourages them to mess with your internals, then you don't have internals. Everything is de facto public. > You can tell that your claim is simply wrong by pushing it the other > way. If everything you have free access to is interface then all > behaviour observable by messing with the things you have access to is > fair game: you can rely on cmp returning one of {-1, 0, 1} on integer > arguments, for example. > > But no: the Library Reference says only that it returns a negative, zero > or positive integer, and /that/ defines the interface. Everything else > is idiosyncrasy of the implementation, allowed to change at whim. And yet people still assume that cmp returns -1, 0 or 1. Even Guido himself makes that mistake occasionally. Quoting from PEP 285: "...you might be tempted to believe that cmp() also returned a truth value, whereas in reality it can return three different values (-1, 0, 1)." http://www.python.org/dev/peps/pep-0285/ No, cmp() can return an infinite number of values. It just never does, at least not yet, but it might. But when Guido himself says that cmp() can return three values, can you blame people for acting as if cmp() can return three values? Here's a thought experiment for you. You've suggested that the values returned by cmp() are allowed to change "at whim". Okay, let's do it: make a patch that changes cmp() to return -17, 0 or 53, and promise to support it for at least three years. Try to get it accepted on python- dev. What do you expect they will say? My money is on them saying "No, this will pointlessly break code for no good reason. Rejected." -- Steven From notvalid2 at sbcglobal.net Thu Jan 22 21:38:32 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 22 Jan 2009 18:38:32 -0800 Subject: What is intvar? Message-ID: I'm looking at someone's code in which invar() is used fairly often. Apparently, it's a Tkinter method. Here's a use: def body(self,master): self.title("Display Settings") self.colorVar = IntVar() Radiobutton( master, text="Gray Scale", value=1, variable=self.colorVar).grid(row=0, sticky=W) Radiobutton( master, text="Pseudo Color", value=2, variable=self.colorVar).grid(row=1, sticky=W) ... What is the need for this use? It looks like some sort of initialization for a widget. I've scoured the internet with Google, and have yet to find a simple explanation of what it's used for. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gregturn at mindspring.com Thu Jan 22 21:39:08 2009 From: gregturn at mindspring.com (Goldfish) Date: Thu, 22 Jan 2009 18:39:08 -0800 (PST) Subject: Spring Python 1.0.0 (RC1) is released Message-ID: <847da5ae-412a-47f9-b002-4755f0ec028e@z6g2000pre.googlegroups.com> Spring Python takes the concepts implemented by the Java-based Spring Framework, and applies them to Python. This provides a powerful library of functionality to help you get back to writing the code that makes you money. It includes features like data access, transaction management, remoting, security, a command-line tool, and an IoC container. Today, release 1.0.0 (RC1) has been released. See http://blog.springpython.webfactional.com/index.php/2009/01/22/spring-python-1-0-0-is-finally-here for details about this release, including release notes, links, and other information. This is the production-ready release, with now stable APIs. From tjreedy at udel.edu Thu Jan 22 21:42:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 21:42:11 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> References: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: >> On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: >> >>> The collections module in Python 2.7 and Python 3.1 has gotten a new >>> Counter class that works like bags and multisets in other languages. >>> >>> I've adapted it for Python2.5/2.6 so people can start using it right >>> away: >>> http://docs.python.org/dev/library/collections.html#counter-objects >>> >>> Here's a link to the docs for the new class: >>> http://code.activestate.com/recipes/576611/ >> Hi Raymond, >> >> * I'm not a native speaker, but why use the word "Counter"? A "counter" >> to my ear sounds like a number that is increased each time an event >> occurs; the website counter, eg, comes to mind. I can understanda its >> meaning probably stretches to "an object that counts", Yes, little clicker devices for instances. >> but I really can't >> think of it as a group of object, or a container of object. Me neither. >> Moreover, I >> find it a much more useful abstraction the idea of a "multi-set" (that >> is, a set where elements can appear with multiple cardinality), rather >> than stressing the concept of "counting" how many times each element >> appears in the set. >> >> * I find it *very* confusing c.items() vs c.elements(). Items and >> elements are synonymous (again, in my understanding of English). > > I concur and would like to say additionally that having Counter's > len() be the number of *unique* items as opposed to just the number of > items seems a bit counterintuitive. bag/multiset/counter has been implemented as dict with items as keys and counts as values, and len(dict) = #keys, so unique items is what I expect. Giving the bag a sum-of-counts attributes also might be nice, though. From clp2 at rebertia.com Thu Jan 22 21:45:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 18:45:26 -0800 Subject: What is intvar? In-Reply-To: References: Message-ID: <50697b2c0901221845y9b4cc4bwcae2234fd64fe258@mail.gmail.com> On Thu, Jan 22, 2009 at 6:38 PM, W. eWatson wrote: > I'm looking at someone's code in which invar() is used fairly often. > Apparently, it's a Tkinter method. Here's a use: > def body(self,master): > self.title("Display Settings") > > self.colorVar = IntVar() > Radiobutton( master, text="Gray Scale", > value=1, variable=self.colorVar).grid(row=0, sticky=W) > Radiobutton( master, text="Pseudo Color", > value=2, variable=self.colorVar).grid(row=1, sticky=W) > ... > > What is the need for this use? It looks like some sort of initialization for > a widget. > > I've scoured the internet with Google, and have yet to find a simple > explanation of what it's used for. Search for IntVar on http://docs.python.org/library/tkinter.html and read the enclosing section. I think it's basically used to propagate changes to the GUI and convert values (in this case, ints) between Python and Tk. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 22 21:48:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 21:48:52 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01892202$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > Here's a thought experiment for you. You've suggested that the values > returned by cmp() are allowed to change "at whim". Okay, let's do it: > make a patch that changes cmp() to return -17, 0 or 53, and promise to > support it for at least three years. Try to get it accepted on python- > dev. What do you expect they will say? > > My money is on them saying "No, this will pointlessly break code for no > good reason. Rejected." I have occasionally thought that things documented to possibly change *should* be changed just to expose the *bug* of depending on them not changing. Or maybe, the doc should be changed. From dsdale24 at gmail.com Thu Jan 22 21:56:18 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Thu, 22 Jan 2009 18:56:18 -0800 (PST) Subject: what gives with "'import *' not allowed with 'from .'"? Message-ID: I know the use of "from foo import *" is discouraged, but I'm writing a package that I hope others may want to integrate as a subpackage of their own projects, I know what I'm doing, and I want to use the "from .bar import *" syntax internally. It works fine with python-2.6, but with python-2.5 I get a SyntaxError: "'import *' not allowed with 'from .'" Judging from http://bugs.python.org/issue2400 , this issue was fixed back in May 2008, but it is still present with python-2.5.4, which was released in December. Why wont python-2.5 allow this kind of import? From musiccomposition at gmail.com Thu Jan 22 21:58:31 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 22 Jan 2009 18:58:31 -0800 (PST) Subject: does exec ignore the locals parameter? References: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> Message-ID: On Jan 22, 6:45?pm, cburns wrote: > In the code below, bar() seems to work, foo() seems broken. > > % python -V > Python 2.6.1 > > % cat exec1.py > > def foo(i) : > ? ? ? ? exec "i = i + 1" in locals(), globals() > ? ? ? ? print "i=%d" % i > > def bar(j) : > ? ? ? ? exec "j = j + 1" > ? ? ? ? print "j=%d" % j > > foo(0) > bar(0) > > % python exec1.py > i=0 > j=1 > > What I really wanted to do was something like: > > ? ? ? ? exec text in globals(), inspect.currentframe(1).f_locals but > that didn't work either. Trying to modify locals() in a function is undefined behavior. > > Thanks, > > Charlie From rhodri at wildebst.demon.co.uk Thu Jan 22 22:00:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 23 Jan 2009 03:00:45 -0000 Subject: What is intvar? In-Reply-To: References: Message-ID: On Fri, 23 Jan 2009 02:38:32 -0000, W. eWatson wrote: > I'm looking at someone's code in which invar() is used fairly often. > Apparently, it's a Tkinter method. Here's a use: > def body(self,master): > self.title("Display Settings") > > self.colorVar = IntVar() > Radiobutton( master, text="Gray Scale", > value=1, variable=self.colorVar).grid(row=0, > sticky=W) > Radiobutton( master, text="Pseudo Color", > value=2, variable=self.colorVar).grid(row=1, > sticky=W) > ... > > What is the need for this use? It looks like some sort of initialization > for a widget. Chris has already pointed you to the Tkinter documentation, which is a good start but a little less than clear in places. What your example code does is to associate self.colorVar with the set of radio buttons. This isn't just initialisation, it's a full reflection of the current state. self.colorVar.get() returns the "value" parameter that you gave to the radio button which is currently selected (so, for example, if it returns 1 you know that the "Grey Scale" button is the one selected). Similarly self.colorVar.set(n) selects whichever radio button has the "value" which matches n (so self.colorVar.set(2) selects the "Pseudo Color" button). IntVar and StringVar (and DoubleVar if you must :-) are basically the easy way of dynamically reading and changing the values in various entry widgets, the text on buttons, and so on. -- Rhodri James *-* Wildebeeste Herder to the Masses From musiccomposition at gmail.com Thu Jan 22 22:02:36 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 22 Jan 2009 19:02:36 -0800 (PST) Subject: Dictionary : items() References: <7x8wp3wwlk.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 2:53?am, Paul Rubin wrote: > Steven D'Aprano writes: > > That is better written as: > > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) > > In Python 2.x, I prefer the style > > ? l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) > > but Python 3.0 breaks the tuple unpacking per some PEP. PEP 3113 if you really care. From steve at holdenweb.com Thu Jan 22 22:06:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 22:06:17 -0500 Subject: pep 8 constants In-Reply-To: <4978DD2E.1090008@aim.com> References: <4978DD2E.1090008@aim.com> Message-ID: Brian Allen Vanderburg II wrote: > bockman at virgilio.it wrote: >> Constants would be a nice addition in python, sure enough. >> But I'm not sure that this can be done without a run-time check every >> time >> the constant is used, and python is already slow enough. Maybe a check >> that is disabled when running with optimizing flags ? >> >> But I'm sure this discussion has been already made and the FINAL WORD has >> been already spoken. >> >> Ciao >> ---- >> FB >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > One idea to make constants possible would be to extend properties to be > able to exist at the module level as well as the class level: > > @property > def pi(): > return 3.14159..... > > print(pi) # prints 3.14159.... > pi=32 # Raise an error Cannot set attribute ... > I don't understand why this would print 3.14159 ... instead of , or whatever. property would clearly have to do something very different in module scope in order to make this work. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin at python.org Thu Jan 22 22:07:36 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 03:07:36 +0000 (UTC) Subject: what gives with References: Message-ID: Darren Dale gmail.com> writes: > Judging from http://bugs.python.org/issue2400 , this issue > was fixed back in May 2008, but it is still present with python-2.5.4, > which was released in December. Why wont python-2.5 allow this kind of > import? Allowing that would be a new feature which is disallowed in bug fix releases like 2.5.4. From benjamin at python.org Thu Jan 22 22:11:26 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 03:11:26 +0000 (UTC) Subject: pep 8 constants References: Message-ID: Benjamin Kaplan case.edu> writes: > > > On Thu, Jan 22, 2009 at 1:16 AM, Aahz pythoncraft.com> wrote:In article python.org>, > Brendan Miller catphive.net> wrote:>>PEP 8 doesn't mention anything about using all caps to indicate a constant.Now it does! ?Seehttp://www.python.org/dev/peps/pep-0008/Thanks for bringing this up! > ? > Since the constants in the std lib (like?math.pi and math.e)?no longer follow PEP 8, should we expect them to change at some point in the future? No, I don't think so. These are already well known as constants. Besides it would break backward compatibility for little gain. From aahz at pythoncraft.com Thu Jan 22 22:11:53 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:11:53 -0800 Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: In article <7xy6x9nzwd.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Chris Rebert writes: >>attribution deleted by Paul Rubin: >>> >>> class Calculator(): ... >> >> Delete the 3 Java-ish accessor methods; good Python style just uses >> the attributes directly (i.e. self.operator instead of >> self.getOperator()). > >I think I would get rid of the whole Calculator class unless there >was a good reason to keep it (i.e. you are going to have several >Calculators active in the program simultaneously). Just write >straightforward imperative code without bothering with the OO stuff >that is mandatory in Java. IMO "good reason" is simply that using a class makes keeping track of namespaces easier, e.g. if you add a memory capability. I think that if there's clearly an object that you will be manipulating, a class is usually the right approach even if it doesn't look like it's needed. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From vedagaurav at gmail.com Thu Jan 22 22:14:19 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Thu, 22 Jan 2009 19:14:19 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> <61718f7e-327b-4851-95b5-83c0951a00a6@a39g2000prl.googlegroups.com> Message-ID: <4fde3122-9554-4cfb-86a1-dd3dccec42ea@r38g2000vbi.googlegroups.com> On Jan 21, 7:08 pm, John Machin wrote: > > To replace non-ASCII characters in a UTF-8-encoded string by spaces: > | >>> u8 = ' and 25\xc2\xb0F' > | >>> u = u8.decode('utf8') > | >>> ''.join([chr(ord(c)) if c <= u'\x7f' else ' ' for c in u]) > | ' and 25 F' Thanks John for your reply. This is what I needed. Cheers, Gaurav From atleta.hu at gmail.com Thu Jan 22 22:19:26 2009 From: atleta.hu at gmail.com (atleta) Date: Thu, 22 Jan 2009 19:19:26 -0800 (PST) Subject: Adding a field to a 'foreign' object from the outside Message-ID: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Hi, I'm working with a callback API (a DBus one) and I'd need to store some state between the calls somewhere. I know that it's possible to extend an object with fields after creation, so I could just store my data in the session object that is passed in with every callback. However it stinks from OO perspective, at least to me. The other option, something that I'd do in java for example, would be to set up a mapping (a dict) using the session object as a key. Which one is the 'pythonic' way? Do you use the first method (modifying an object that you don't even control the source of) or do you write a bit more code and go with the second one? Thanks, Laszlo From rt8396 at gmail.com Thu Jan 22 22:19:50 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 19:19:50 -0800 (PST) Subject: What is intvar? References: Message-ID: here is a good explanation of control vars: http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html Here are 3 great Tkinter refernces in order: http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://effbot.org/tkinterbook/ http://www.pythonware.com/library/tkinter/introduction/ From aahz at pythoncraft.com Thu Jan 22 22:22:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:22:08 -0800 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article <87hc3un1vn.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > > * Python augmented-assignment (`+=', for example) is inconsistent. > Depending on what type of object the left-hand side evaluates to, it > may /either/ mutate that object, /or/ assign a new value to the > expression. Actually, that is not correct. The augmented assignment always binds a new value to the name; the gotcha is that with a mutable object, the object returns ``self`` from the augmented assignment method rather than creating a new object and returning that. IOW, the smarts are always with the object, not with the augmented assignment bytecode. The best way to illustrate this: >>> a = (1, ['foo'], 'xyzzy') >>> a[1].append('bar') >>> a (1, ['foo', 'bar'], 'xyzzy') >>> a[1] = 9 Traceback (most recent call last): File "", line 1, in ? TypeError: object doesn't support item assignment >>> a (1, ['foo', 'bar'], 'xyzzy') >>> a[1] += ['spam'] Traceback (most recent call last): File "", line 1, in ? TypeError: object doesn't support item assignment >>> a (1, ['foo', 'bar', 'spam'], 'xyzzy') -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Thu Jan 22 22:23:57 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:23:57 -0800 Subject: Python Style Guide Questions - Contd. References: <6tk9qqFbav8gU1@mid.uni-berlin.de> Message-ID: In article <6tk9qqFbav8gU1 at mid.uni-berlin.de>, Marc 'BlackJack' Rintsch wrote: > >PEP8 doesn't mention constants at all. Not true anymore. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From grante at visi.com Thu Jan 22 22:26:01 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 22 Jan 2009 21:26:01 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: On 2009-01-23, Astan Chee wrote: > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using a > computer so I thought USB might be a good choice since its simple (but > didn't turn out to be). USB is definitely not simple. USB is exremely complicated (and rather badly designed, IMO). > I'm open to any other suggestions on how I might achieve this > hardware and software-wise (as in what interface should I > use, etc). Also I'm trying to stay away from (complex) micro > controllers. Any ideas? Thanks again Astan Standard IBM PC parallel printer ports offer a bunch of 5V I/O lines that are fairly simple to control in software. -- From prologic at shortcircuit.net.au Thu Jan 22 22:27:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 13:27:30 +1000 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 1:19 PM, atleta wrote: > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? The more elegant approach is your 2nd one. A wrapper object that hold the extra data and functionality you require while maintaining the APIs needs. Tacking things on is a bit hackish :) (but nonetheless probably works). --JamesMills From nad at acm.org Thu Jan 22 22:59:39 2009 From: nad at acm.org (Ned Deily) Date: Thu, 22 Jan 2009 19:59:39 -0800 Subject: does exec ignore the locals parameter? References: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> Message-ID: In article , Benjamin wrote: > On Jan 22, 6:45?pm, cburns wrote: > > In the code below, bar() seems to work, foo() seems broken. > > > > % python -V > > Python 2.6.1 > > > > % cat exec1.py > > > > def foo(i) : > > ? ? ? ? exec "i = i + 1" in locals(), globals() > > ? ? ? ? print "i=%d" % i > > > > def bar(j) : > > ? ? ? ? exec "j = j + 1" > > ? ? ? ? print "j=%d" % j > > > > foo(0) > > bar(0) > Trying to modify locals() in a function is undefined behavior. BTW, the order of the parameters to exec are reversed; presumably what was intended is: exec "i = i + 1" in globals(), locals() That doesn't change the results in question, though, as is, after the call to foo(0), i (=1) exists as a global. -- Ned Deily, nad at acm.org From pavlovevidence at gmail.com Thu Jan 22 23:38:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 20:38:21 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > In article <7xd4ele060.... at ruckus.brouhaha.com>, > Paul Rubin ? wrote: > > >alex23 writes: > > >> Here's an article by Guido talking about the last attempt to remove > >> the GIL and the performance issues that arose: > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > >> a single-threaded program (and for a multi-threaded but I/O-bound > >> program) *does not decrease*." > > >The performance decrease is an artifact of CPython's rather primitive > >storage management (reference counts in every object). ?This is > >pervasive and can't really be removed. ?But a new implementation > >(e.g. PyPy) can and should have a real garbage collector that doesn't > >suffer from such effects. > > CPython's "primitive" storage management has a lot to do with the > simplicity of interfacing CPython with external libraries. ?Any solution > that proposes to get rid of the GIL needs to address that. I recently was on a long road trip, and was not driver, and with nothing better to do thought quite a bit about how this. I concluded that, aside from one major trap, it wouldn't really be more difficult to inteface Python to external libraries, just differently difficult. Here is briefly what I came up with: 1. Change the singular Python type into three metatypes: immutable_type, mutable_type, and mutable_dict_type. (In the latter case, the object itself is immutable but the dict can be modified. This, of course, would be the default metaclass in Python.) Only mutable_types would require a mutex when accessing. 2. API wouldn't have to change much. All regular API would assume that objects are unlocked (if mutable) and in a consistent state. It'll lock any mutable objects it needs to access. There would also be a low-level API that assumes the objects are locked (if mutable) and does not require objects to be consistent. I imagine most extensions would call the standard API most of the time. 3. If you are going to use the low-level API on a mutable object, or are going to access the object structure directly, you need to acquire the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() would be provided. 4. Objects would have to define a method, to be called by the GC, that marks every object it references. This would be a lot like the current tp_visit, except it has to be defined for any object that references another object, not just objects that can participate in cycles. (A conservative garbage collector wouldn't suffice for Python because Python quite often allocates blocks but sets the pointer to an offset within the block. In fact, that's true of almost any Python- defined type.) Unfortunately, references on the stack would need to be registered as well, so "PyObject* p;" might have to be replaced with something like "Py_DECLARE_REF(PyObject,p);" which magically registers it. Ugly. 5. Py_INCREF and Py_DECREF are gone. 6. GIL is gone. So, you gain the complexity of a two-level API, having to lock mutable objects sometimes, and defining more visitor methods than before, but you don't have to keep INCREFs and DECREFs straight, which is no small thing. The major trap is the possibily of deadlock. To help minimize the risk there would be macros to lock multiple objects at once. Py_LOCK2 (a,b), which guarantess that if in another thread is calling Py_LOCK2 (b,a) at the same time, it won't result in a deadlock. What's disappointing is that the deadlocking possibility is always with you, much like the reference counts are. Carl Banks From koranthala at gmail.com Thu Jan 22 23:38:34 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 22 Jan 2009 20:38:34 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: <50b8a5b0-c4f6-45af-aa81-f7cf060b06bc@r37g2000prr.googlegroups.com> On Jan 22, 10:25?pm, Vinay Sajip wrote: > On Jan 22, 3:40 pm,koranthala wrote: > > > Thank you very much Vinay. You have been extremely helpful. > > This was my first design - but then I found that log system was taking > > up quite a huge chunk of the memory. > > That is why I went to rotating file handler. > > Using just plain FileHandler takes up less memory than using > RotatingFileHandler (because using the latter imports the "handlers" > module into memory, whereas using the former does not). I'm not aware > of any problem where logging takes up a huge chunk of memory (under > normal usage) - how did you measure the memory usage which was due to > logging? > > > Anyways, now I have modified doRollover to append if file is there, > > so, for me it is working. > > What I was thinking was such an option in the basicloggingsystem > > might be of good help. > > The solution I suggested is IMO better than using a patched > RotatiingFileHandler, both because it avoids importing an extra module > (if memory really is a concern) and because you don't need to change > your code across Python version updates. How does my suggestion to use > FileHandler not meet your use case? > > > Again, Vinay, Thank you very much. You were extremely helpful. > > You're welcome. > > Best wishes, > > Vinay Sajip oops - again I was very unclear in my post. What i meant was that due to the log getting very big - i.e. the log was in 100MB range (since it is a new product - a lot of debugging is done via logs). Not RAM. Having a rotating file handler helped there - because I could say only 5 such logs are needed. From Russ.Paielli at gmail.com Fri Jan 23 00:22:25 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 22 Jan 2009 21:22:25 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> On Jan 22, 6:30?pm, Steven D'Aprano wrote: > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > > Steven D'Aprano writes: > > >> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > >>> Steven D'Aprano a ?crit : > >>>> But if you have free access to attributes, then *everything* is > >>>> interface. > > >>> Nope. > > >> How could anyone fail to be convinced by an argument that detailed and > >> carefully reasoned? > > > Well, your claim /was/ just wrong. ?But if you want to play dumb: the > > interface is what's documented as being the interface. > > But you miss my point. > > We're told Python doesn't have private attributes. We're told that we're > allowed to "mess with the internals", we're *encouraged* to do so: Python > gives you the freedom to do so, and any suggestion that freedom might be > reduced even a tiny bit is fought passionately. When people ask how to > implement private attributes, they're often told not to bother even using > single-underscore names. When it is suggested that Python should become > stricter, with enforced data hiding, the objections come thick and fast: > people vehemently say that they like Python just the way it is, that they > want the ability to mess with the internals. > > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to mess > with the private attributes. In context, I had just mentioned that lists' > internals were inaccessible from Python code. I neglected to give an > example at the time, but a good example is the current length of the > list. Consider the experience of Microsoft and Apple. No matter how often > they tell people not to mess with the internals, people do it anyway, and > always believe that their reason is a good reason. > > And Python culture encourages that behaviour (albeit the consequences are > milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. > > And then you have at least two places in the standard library where > _attributes are *explicitly* public: > > http://bugs.python.org/issue3152 > > Given this permissive culture, any responsible library writer must assume > that if he changes his so-called "private" attributes, he will break > other people's code. In principle it could break just as much code as if > he didn't even bother flagging them with a leading underscore, which is > probably why many people don't even bother with _names. > > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them to > mess with your internals, then you don't have internals. Everything is de > facto public. > > > You can tell that your claim is simply wrong by pushing it the other > > way. ?If everything you have free access to is interface then all > > behaviour observable by messing with the things you have access to is > > fair game: you can rely on cmp returning one of {-1, 0, 1} on integer > > arguments, for example. > > > But no: the Library Reference says only that it returns a negative, zero > > or positive integer, and /that/ defines the interface. ?Everything else > > is idiosyncrasy of the implementation, allowed to change at whim. > > And yet people still assume that cmp returns -1, 0 or 1. Even Guido > himself makes that mistake occasionally. Quoting from PEP 285: > > "...you might be tempted to believe that cmp() also returned a > truth value, whereas in reality it can return three different values > (-1, 0, 1)." > > http://www.python.org/dev/peps/pep-0285/ > > No, cmp() can return an infinite number of values. It just never does, at > least not yet, but it might. But when Guido himself says that cmp() can > return three values, can you blame people for acting as if cmp() can > return three values? > > Here's a thought experiment for you. You've suggested that the values > returned by cmp() are allowed to change "at whim". Okay, let's do it: > make a patch that changes cmp() to return -17, 0 or 53, and promise to > support it for at least three years. Try to get it accepted on python- > dev. What do you expect they will say? > > My money is on them saying "No, this will pointlessly break code for no > good reason. Rejected." > > -- > Steven Needless to say, I agree with your post. My understanding is that the vast majority of Python software is provided as open source. Hence, I am a bit confused by all the talk about the need for freedom and openness in Python. If data hiding were enforced, and you need access to something marked as private, you can just change it to public in the source code. What's the problem? Note: that change would be much easier to make if a "private" (or perhaps "priv") keyword were used instead of the leading-underscore rule. The former would require a change in only one place (per attribute), whereas the latter would require a change of every occurrence of the attribute. So "enforced" access restrictions are trivial to work around with open source. But doesn't that mean that access restriction is pointless because it cannot be enforced anyway? Of course not. In a team project, the access restrictions will be enforced on the checked-in code. You can play around with the internals all you want in your own little world, but as when you are working with a team, you need to adhere to the interfaces they define (if any). From rhamph at gmail.com Fri Jan 23 00:26:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 22 Jan 2009 21:26:24 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <9ed75409-9e7b-40ce-b195-f581cb860ee1@13g2000yql.googlegroups.com> On Jan 22, 7:48?pm, Terry Reedy wrote: > Steven D'Aprano wrote: > > > Here's a thought experiment for you. You've suggested that the values > > returned by cmp() are allowed to change "at whim". Okay, let's do it: > > make a patch that changes cmp() to return -17, 0 or 53, and promise to > > support it for at least three years. Try to get it accepted on python- > > dev. What do you expect they will say? > > > My money is on them saying "No, this will pointlessly break code for no > > good reason. Rejected." > > I have occasionally thought that things documented to possibly change > *should* be changed just to expose the *bug* of depending on them not > changing. ?Or maybe, the doc should be changed. Aye. There are places where we're deliberately open, but this isn't one of them. I think this is just a C-ism and the docs should be more specific. Or finish ripping it out in 3.x ;) From http Fri Jan 23 00:31:11 2009 From: http (Paul Rubin) Date: 22 Jan 2009 21:31:11 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xr62ufv1c.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > CPython's "primitive" storage management has a lot to do with the > simplicity of interfacing CPython with external libraries. Any solution > that proposes to get rid of the GIL needs to address that. This, I don't understand. Other languages like Lisp and Java and Haskell have foreign function interfaces that easier to program than Python's, -and- they don't use reference counts. There's usually some primitive to protect objects from garbage collection while the foreign function is using them, etc. The Java Native Interface (JNI) and the Haskell FFI are pretty well documented. The Emacs Lisp system is not too hard to figure out from examining the source code, etc. From Russ.Paielli at gmail.com Fri Jan 23 00:31:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 22 Jan 2009 21:31:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <49770f51$0$743$426a74cc@news.free.fr> Message-ID: <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> On Jan 21, 4:04?am, Bruno Desthuilliers wrote: > Russ P. a ?crit : > (snip) > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > Calling people names is certainly not the best way to defend your > opinions here. Adios, Mr. P. You are absolutely right, Mr. D. I regret that post, and I have since apologized to the person I was addressing. This stuff really isn't important enough to get that worked up about. From rhamph at gmail.com Fri Jan 23 00:38:37 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 22 Jan 2009 21:38:37 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> On Jan 22, 9:38?pm, Carl Banks wrote: > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > Paul Rubin ? wrote: > > > >alex23 writes: > > > >> Here's an article by Guido talking about the last attempt to remove > > >> the GIL and the performance issues that arose: > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > >> program) *does not decrease*." > > > >The performance decrease is an artifact of CPython's rather primitive > > >storage management (reference counts in every object). ?This is > > >pervasive and can't really be removed. ?But a new implementation > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > >suffer from such effects. > > > CPython's "primitive" storage management has a lot to do with the > > simplicity of interfacing CPython with external libraries. ?Any solution > > that proposes to get rid of the GIL needs to address that. > > I recently was on a long road trip, and was not driver, and with > nothing better to do thought quite a bit about how this. > > I concluded that, aside from one major trap, it wouldn't really be > more difficult to inteface Python to external libraries, just > differently difficult. ?Here is briefly what I came up with: > > 1. Change the singular Python type into three metatypes: > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > case, the object itself is immutable but the dict can be modified. > This, of course, would be the default metaclass in Python.) ?Only > mutable_types would require a mutex when accessing. > > 2. API wouldn't have to change much. ?All regular API would assume > that objects are unlocked (if mutable) and in a consistent state. > It'll lock any mutable objects it needs to access. ?There would also > be a low-level API that assumes the objects are locked (if mutable) > and does not require objects to be consistent. ?I imagine most > extensions would call the standard API most of the time. > > 3. If you are going to use the low-level API on a mutable object, or > are going to access the object structure directly, you need to acquire > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > would be provided. > > 4. Objects would have to define a method, to be called by the GC, that > marks every object it references. ?This would be a lot like the > current tp_visit, except it has to be defined for any object that > references another object, not just objects that can participate in > cycles. ?(A conservative garbage collector wouldn't suffice for Python > because Python quite often allocates blocks but sets the pointer to an > offset within the block. ?In fact, that's true of almost any Python- > defined type.) ?Unfortunately, references on the stack would need to > be registered as well, so "PyObject* p;" might have to be replaced > with something like "Py_DECLARE_REF(PyObject,p);" which magically > registers it. ?Ugly. > > 5. Py_INCREF and Py_DECREF are gone. > > 6. GIL is gone. > > So, you gain the complexity of a two-level API, having to lock mutable > objects sometimes, and defining more visitor methods than before, but > you don't have to keep INCREFs and DECREFs straight, which is no small > thing. > > The major trap is the possibily of deadlock. ?To help minimize the > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > (b,a) at the same time, it won't result in a deadlock. ?What's > disappointing is that the deadlocking possibility is always with you, > much like the reference counts are. IMO, locking of the object is a secondary problem. Python-safethread provides one solution, but it's not the only conceivable one. For the sake of discussion it's easier to assume somebody else is solving it for you. Instead, focus on just the garbage collection. What are the practical issues of modifying CPython to use a tracing GC throughout? It certainly is possible to write an exact GC in C, but the stack manipulation would be hideous. It'd also require significant rewrites of the entire code base. Throw on that the performance is unclear (it could be far worse for a single-threaded program), with no straightforward way to make it a compile-time option.. Got any ideas for that? From prologic at shortcircuit.net.au Fri Jan 23 00:38:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 15:38:49 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 3:22 PM, Russ P. wrote: (...) > My understanding is that the vast majority of Python software is > provided as open source. Hence, I am a bit confused by all the talk > about the need for freedom and openness in Python. If data hiding were > enforced, and you need access to something marked as private, you can > just change it to public in the source code. What's the problem? > > Note: that change would be much easier to make if a "private" (or > perhaps "priv") keyword were used instead of the leading-underscore > rule. The former would require a change in only one place (per > attribute), whereas the latter would require a change of every > occurrence of the attribute. > > So "enforced" access restrictions are trivial to work around with open > source. But doesn't that mean that access restriction is pointless > because it cannot be enforced anyway? Of course not. In a team > project, the access restrictions will be enforced on the checked-in > code. You can play around with the internals all you want in your own > little world, but as when you are working with a team, you need to > adhere to the interfaces they define (if any). I'm going to say this very politely. Python IS NOT Java. --JamesMills From kay.schluehr at gmx.net Fri Jan 23 00:39:46 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 22 Jan 2009 21:39:46 -0800 (PST) Subject: The First Law Of comp.lang.python Dynamics References: Message-ID: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Whatever sufficiently sophisticated topic was the initially discussed it ends all up in a request for removing reference counting and the GIL. From clp2 at rebertia.com Fri Jan 23 00:43:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 21:43:35 -0800 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <50697b2c0901222143y7717f435xe883ce39d6b9d058@mail.gmail.com> On Thu, Jan 22, 2009 at 9:39 PM, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. +1 QOTW - Chris -- Follow the path of the Iguana... http://rebertia.com From BrianVanderburg2 at aim.com Fri Jan 23 00:53:25 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 00:53:25 -0500 Subject: USB in python In-Reply-To: <4979225B.6050106@al.com.au> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <4979225B.6050106@al.com.au> Message-ID: <49795B55.6080108@aim.com> astan.chee at al.com.au wrote: > Hi, > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using > a computer so I thought USB might be a good choice since its simple > (but didn't turn out to be). I'm open to any other suggestions on how > I might achieve this hardware and software-wise (as in what interface > should I use, etc). Also I'm trying to stay away from (complex) micro > controllers. > Any ideas? > Thanks again > Astan > -- > http://mail.python.org/mailman/listinfo/python-list How about a different interface? From what I have read the parallel port is a bit easier to program. I think you can control the data lines of the parallel port though. There is also a python wrapper for it on the pyserial web site (pyparallel maybe?) If you don't have a built-in parallel port then there are those USB to serial/parallel converters. Brian A. Vanderburg II From pavlovevidence at gmail.com Fri Jan 23 01:09:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 22:09:40 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: On Jan 22, 9:38?pm, Rhamphoryncus wrote: > On Jan 22, 9:38?pm, Carl Banks wrote: > > > > > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > > Paul Rubin ? wrote: > > > > >alex23 writes: > > > > >> Here's an article by Guido talking about the last attempt to remove > > > >> the GIL and the performance issues that arose: > > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > > >> program) *does not decrease*." > > > > >The performance decrease is an artifact of CPython's rather primitive > > > >storage management (reference counts in every object). ?This is > > > >pervasive and can't really be removed. ?But a new implementation > > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > > >suffer from such effects. > > > > CPython's "primitive" storage management has a lot to do with the > > > simplicity of interfacing CPython with external libraries. ?Any solution > > > that proposes to get rid of the GIL needs to address that. > > > I recently was on a long road trip, and was not driver, and with > > nothing better to do thought quite a bit about how this. > > > I concluded that, aside from one major trap, it wouldn't really be > > more difficult to inteface Python to external libraries, just > > differently difficult. ?Here is briefly what I came up with: > > > 1. Change the singular Python type into three metatypes: > > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > > case, the object itself is immutable but the dict can be modified. > > This, of course, would be the default metaclass in Python.) ?Only > > mutable_types would require a mutex when accessing. > > > 2. API wouldn't have to change much. ?All regular API would assume > > that objects are unlocked (if mutable) and in a consistent state. > > It'll lock any mutable objects it needs to access. ?There would also > > be a low-level API that assumes the objects are locked (if mutable) > > and does not require objects to be consistent. ?I imagine most > > extensions would call the standard API most of the time. > > > 3. If you are going to use the low-level API on a mutable object, or > > are going to access the object structure directly, you need to acquire > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > would be provided. > > > 4. Objects would have to define a method, to be called by the GC, that > > marks every object it references. ?This would be a lot like the > > current tp_visit, except it has to be defined for any object that > > references another object, not just objects that can participate in > > cycles. ?(A conservative garbage collector wouldn't suffice for Python > > because Python quite often allocates blocks but sets the pointer to an > > offset within the block. ?In fact, that's true of almost any Python- > > defined type.) ?Unfortunately, references on the stack would need to > > be registered as well, so "PyObject* p;" might have to be replaced > > with something like "Py_DECLARE_REF(PyObject,p);" which magically > > registers it. ?Ugly. > > > 5. Py_INCREF and Py_DECREF are gone. > > > 6. GIL is gone. > > > So, you gain the complexity of a two-level API, having to lock mutable > > objects sometimes, and defining more visitor methods than before, but > > you don't have to keep INCREFs and DECREFs straight, which is no small > > thing. > > > The major trap is the possibily of deadlock. ?To help minimize the > > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > > (b,a) at the same time, it won't result in a deadlock. ?What's > > disappointing is that the deadlocking possibility is always with you, > > much like the reference counts are. > > IMO, locking of the object is a secondary problem. ?Python-safethread > provides one solution, but it's not the only conceivable one. ?For the > sake of discussion it's easier to assume somebody else is solving it > for you. That assumption might be good for the sake of the discussion *you* want to have, but it's not for discussion I was having, which was to address Aahz's claim that GIL makes extension writing simple by presenting a vision of what Python might be like if it had a mark-and- sweep collector. The details of the GC are a small part of that and wouldn't affect my main point even if they are quite different than I described. Also, extension writers would have to worry about locking issues here, so it's not acceptable to assume somebody else will solve that problem. > Instead, focus on just the garbage collection. [snip rest of threadjack] You can ignore most of what I was talking about and focus on technicalities of garbage collection if you want to. I will not be joining you in that discussion, however. Carl Banks From 0.chirkut.0 at gmail.com Fri Jan 23 01:14:09 2009 From: 0.chirkut.0 at gmail.com (Nick) Date: Thu, 22 Jan 2009 22:14:09 -0800 (PST) Subject: free download - breve 2.7.2 : a 3D Simulation Environment for Multi-Agent Simulations and Artificial Life Message-ID: <23283441-37f6-4bb3-9c28-9b296a52eab1@r15g2000prd.googlegroups.com> www.filecub.com What is breve? breve is a free, open-source software package which makes it easy to build 3D simulations of multi-agent systems and artificial life. Using Python, or using a simple scripting language called steve, you can define the behaviors of agents in a 3D world and observe how they interact. breve includes physical simulation and collision detection so you can simulate realistic creatures, and an OpenGL display engine so you can visualize your simulated worlds. www.filecub.com From http Fri Jan 23 01:15:24 2009 From: http (Paul Rubin) Date: 22 Jan 2009 22:15:24 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhimttv.fsf@ruckus.brouhaha.com> Carl Banks writes: > 3. If you are going to use the low-level API on a mutable object, or > are going to access the object structure directly, you need to acquire > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > would be provided. You mean every time you access a list or dictionary or class instance, you have to acquire a mutex? That sounds like a horrible slowdown. From drfloob at gmail.com Fri Jan 23 01:32:20 2009 From: drfloob at gmail.com (dr.floob) Date: Thu, 22 Jan 2009 22:32:20 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: On Jan 8, 9:48?am, "Tim Arnold" wrote: > "floob" wrote in message > > news:0af87074-6d9c-41a8-98ec-501f6f37bf9a at s1g2000prg.googlegroups.com... > > > > >I have been searching for a way to print the official Python > > documentation into some kind of book (for my own uses). ?I don't > > really care if it'sprintedon newspaper and bound with elmer's > > glue ... any way I can get relatively recent _official documentation_ > > in print form will do. > > > I'm on the go a lot, and can't read for long periods of time on LCD > > screens anyhow (so having a laptop is not my solution). ?Until eBook > > readers grow up a bit, I'm stuck trying to print the documentation > > that I REALLY need to read and absorb. > > > Lulu.com is an option, but it would cost something around $100 US > > before shipping to get everythingprinted. ?Also, I would have to > > split up some larger documents into Volumes, which I'd rather not have > > to do. > > > Has anyone tried this before? ?Is the documentation already available > > in print? > > > Thanks, > > > drfloob > > just a datapoint, but I used lulu.com to print the latex sources (525 pages) > hardbound for a cost of $25 US. > --Tim Arnold That sounds about right for 525 pages. But the current A4-sized library reference pdf is 1207 pages alone, and I'm hoping to print / most/ of the docs. I managed to get a lot of the documentation (all but some howtos) fit into 3 books on Lulu. Python Docs LaTeX sources don't seem to be available anymore, and I haven't dug into reStructuredText yet, so I massaged the A4 pdfs to fit into 5.5" x 8.5" to drop the price. Choosing only the most inexpensive options (5.5x8.5, publisher grade paper, paperback perfect bound, etc.), the numbers came out as follows: Total Pages: 2024 Book Cost: $37.87 Shipping: $12.87 (MediaMail, untrackable) Total Cost: $50.74 All in all, it's the least expensive option I've found, and about as comprehensive a set as you can get. It probably wouldn't work for people who can't read small print, though. A letter-sized (8.5" x 11") set would cost maybe 1.5x as much, roughly $75.00. P.S. At two Kinko's near me, double-sided b/w printing was $0.59 per page, compared to Lulu's $0.015. 40x as expensive. THOUSANDS of dollars. From pavlovevidence at gmail.com Fri Jan 23 01:40:10 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 22:40:10 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 10:15?pm, Paul Rubin wrote: > Carl Banks writes: > > 3. If you are going to use the low-level API on a mutable object, or > > are going to access the object structure directly, you need to acquire > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > would be provided. > > You mean every time you access a list or dictionary or class instance, > you have to acquire a mutex? ?That sounds like a horrible slowdown. Yes, and it's never going to happen in CPython any other way. It's considered a bug if Python code can segfault the interpreter; all runtime errors are supposed to raise exceptions. The only way to ensure that won't happen is to make sure that only one thread can can access the internals of a mutable object at a time. BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Carl Banks From deets at nospam.web.de Fri Jan 23 01:58:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 07:58:48 +0100 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: <6tt858Fclr1hU1@mid.uni-berlin.de> Astan Chee schrieb: > Diez B. Roggisch wrote: >> Astan Chee wrote: >> >> >>> Hi, >>> Im trying to write a program for my USB device and I'm thinking of using >>> python to do this. The USB device is of my own making and it is >>> activated when one of the two data pins of the USB is given about 5V (or >>> similar to whatever the power pin is getting). Now I'm confused to if >>> the software to activate this can actually be written and how do I do >>> it? Any examples? I've seen pyUSB but it doesn't give me control over >>> the hardware and how much power is going through the data pins. >>> >> Unless I'm not getting something here. >> >> >> > Hi, > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using a > computer so I thought USB might be a good choice since its simple (but > didn't turn out to be). I'm open to any other suggestions on how I might > achieve this hardware and software-wise (as in what interface should I > use, etc). Also I'm trying to stay away from (complex) micro controllers. > Any ideas? Others suggested the parallel port. It is the natural choice for such things, with two caveats: - it is legacy, and thus often not available on modern hardware, especially on mobile ones. So if you want it be prepared to additionally buy a usb2parallel-adapter. - it's electrical specs aren't as robust I fear. USB allos up to 500mA to be drawn, and shouldn't break if you try more & fail (albeit, that might be something that isn't true all the time). So you can draw quite a bit of current from it (the stupid USB-cup-warmers are an example of that). I have often had broken parallel-ports, and I think the reason is that they *ARE NOT* specified to drive anything - they only provide low-current control-lines. So whatever you design, you need a second power-source then. All in all, using a USB-controller is IMHO the best solution. The AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of example-code, and there is other FOSS available. I have to admit though that the whole USB-topic isn't the easiest thing. Diez From philip at semanchuk.com Fri Jan 23 02:13:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 23 Jan 2009 02:13:17 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <3BAF8361-BD9C-46D0-A5E6-561FC0801239@semanchuk.com> On Jan 23, 2009, at 12:39 AM, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. Is this a variant of Godwin's Law for Python? From astan.chee at al.com.au Fri Jan 23 02:24:37 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 18:24:37 +1100 Subject: USB in python In-Reply-To: <6tt858Fclr1hU1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> Message-ID: <497970B5.40300@al.com.au> Diez B. Roggisch wrote: > Others suggested the parallel port. It is the natural choice for such > things, with two caveats: > > - it is legacy, and thus often not available on modern hardware, > especially on mobile ones. So if you want it be prepared to additionally > buy a usb2parallel-adapter. > > - it's electrical specs aren't as robust I fear. USB allos up to 500mA > to be drawn, and shouldn't break if you try more & fail (albeit, that > might be something that isn't true all the time). So you can draw quite > a bit of current from it (the stupid USB-cup-warmers are an example of > that). I have often had broken parallel-ports, and I think the reason is > that they *ARE NOT* specified to drive anything - they only provide > low-current control-lines. So whatever you design, you need a second > power-source then. > > All in all, using a USB-controller is IMHO the best solution. The > AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of > example-code, and there is other FOSS available. > > I have to admit though that the whole USB-topic isn't the easiest thing. > > Yeah, I forgot to mention that the device is requires about 70-80mA and the parallel port (according to the spec) only provides 1mA. Thats why I was looking into the USB solution. Thanks for the suggestion though. Also, yes, the device is rather mobile and that is why it is powered by the computer/laptop but legacy isn't really an issue for me I guess. Cheers Astan From deets at nospam.web.de Fri Jan 23 02:25:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:25:40 +0100 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: <6tt9nkFc1i1tU1@mid.uni-berlin.de> atleta schrieb: > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? For me, the first one. Creatin a mapping is cumbersome, opens up all kinds of questions like "how to remove stale entries" and is a level of indirection that one has to be aware of. The session object is obviously intended to be that - a storage for information persistent over the course of the actions working with it. So - use it. Python is dynamic. Use that dynamicity. The java & C++-guys would do it - if they could. Diez From kt83313 at gmail.com Fri Jan 23 02:26:10 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Thu, 22 Jan 2009 23:26:10 -0800 (PST) Subject: Securing a database Message-ID: My company provides some services online, which now they are planning to make it offline and sell to customers who can use it in their networks. One of our major moneywinners is some data which is stored in a database. Now, this data inside the database was obtained after paying through the nose - so the company does not want to disclose the data in the DB to the outside world - not to mention the lawsuits which the original providers of data will start which will sink the company if the data goes out. Now, the code is in Python - and we have a big problem. How to secure the data in DB? One idea was to encrypt it and store the password in the code. I dont believe security through obscurity - and python code can easily be reverse-engineered too - right? Is it even possible to secure a data in this case? KT -- From msrachel.e at gmail.com Fri Jan 23 02:29:48 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Thu, 22 Jan 2009 23:29:48 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <0deaafe1-a7ef-4dc4-8ffa-e26cf1ee462f@a12g2000pro.googlegroups.com> On Jan 22, 5:41?pm, Giovanni Bajo wrote: > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). Would have used the term "items" but that term has a different meaning in the context of dictionaries where "items" means (key,value) pairs. The word "elements" is used for members of the set object and has a parallel meaning in the context of multisets. Since the class is a dict subclass (as recommended by Guido), the term "items" was off limits because it means something else. So, "elements" as used in the sets documentation was the next, natural choice. Raymond From deets at nospam.web.de Fri Jan 23 02:30:18 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:30:18 +0100 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> Message-ID: <6tta0aFckqj7U1@mid.uni-berlin.de> Astan Chee schrieb: > Diez B. Roggisch wrote: >> Others suggested the parallel port. It is the natural choice for such >> things, with two caveats: >> >> - it is legacy, and thus often not available on modern hardware, >> especially on mobile ones. So if you want it be prepared to >> additionally buy a usb2parallel-adapter. >> >> - it's electrical specs aren't as robust I fear. USB allos up to >> 500mA to be drawn, and shouldn't break if you try more & fail (albeit, >> that might be something that isn't true all the time). So you can draw >> quite a bit of current from it (the stupid USB-cup-warmers are an >> example of that). I have often had broken parallel-ports, and I think >> the reason is that they *ARE NOT* specified to drive anything - they >> only provide low-current control-lines. So whatever you design, you >> need a second power-source then. >> >> All in all, using a USB-controller is IMHO the best solution. The >> AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit >> of example-code, and there is other FOSS available. >> >> I have to admit though that the whole USB-topic isn't the easiest thing. >> >> > Yeah, I forgot to mention that the device is requires about 70-80mA and > the parallel port (according to the spec) only provides 1mA. Thats why I > was looking into the USB solution. > Thanks for the suggestion though. Also, yes, the device is rather mobile > and that is why it is powered by the computer/laptop but legacy isn't > really an issue for me I guess. If all you need is on-off - why can't you just use a switch? Diez From msrachel.e at gmail.com Fri Jan 23 02:37:14 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Thu, 22 Jan 2009 23:37:14 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> Message-ID: <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> On Jan 22, 5:54?pm, Paul Rubin wrote: > Giovanni Bajo writes: > > * I'm not a native speaker, but why use the word "Counter"? > > I agree with this, the new functionality is welcome but I think > the traditional term "multiset" or "bag" would have been better. The term counter was what was originally approved. At first, I didn't like it but found that it had some advantages. The main advantage is that there are *bazillions* of programmers (including some very good ones) who have never heard the term multiset or bag but have an instant, intuitive understanding of counting and counters. Also, in the context of this implementation, "multiset" would not be a good choice. The mathematical entity, multiset, is defined with elements having a count of one or more. In contrast, the Counter class allows counts to go to zero or become negative. In addition, I worried that calling it a multiset would suggest that it has a set-like API instead of a dict-like API. With the former, you write c.add(elem). With the latter, you write c[elem] += 1. So the name, "multiset" would be misleading. Bike-shed discussions aside (everyone has an opinion of how to name things), how do you guys like the functionality? Do you find it useable in real-world use cases? Raymond From deets at nospam.web.de Fri Jan 23 02:38:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:38:12 +0100 Subject: Securing a database In-Reply-To: References: Message-ID: <6ttaf5Fc79elU1@mid.uni-berlin.de> kt83313 at gmail.com schrieb: > My company provides some services online, which now they are planning > to make it offline and sell to customers who can use it in their > networks. > > One of our major moneywinners is some data which is stored in a > database. Now, this data inside the database was obtained after paying > through the nose - so the company does not want to disclose the data > in the DB to the outside world - not to mention the lawsuits which the > original providers of data will start which will sink the company if > the data goes out. > > Now, the code is in Python - and we have a big problem. How to secure > the data in DB? One idea was to encrypt it and store the password in > the code. I dont believe security through obscurity - and python code > can easily be reverse-engineered too - right? > > Is it even possible to secure a data in this case? No. And that has nothing to do with python. If the data is valuable, it will be decyphered from a compiled piece of code in no time. Believe me, I work for a company that sells a C++-software with protective measures of various kinds. It gets hacked. Fact of live. You could try and raise the bar, as e.g. skype does, with an onion-kind of code-encryption-scheme. But even *that* is analyzed. And it is nothing that is done easily and without major impact on your source, so you might need quite a bit of time to get it right. Is that covered by the expected revenues? And even if one doesn't want to hack into the system, if there is an interface to the data, who stops your users from exploiting that automatically to access all the data in the DB somehow? Diez From astan.chee at al.com.au Fri Jan 23 02:56:38 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 18:56:38 +1100 Subject: USB in python In-Reply-To: <6tta0aFckqj7U1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> Message-ID: <49797836.5020807@al.com.au> Diez B. Roggisch wrote: >> > > If all you need is on-off - why can't you just use a switch? > > > Because I want to control the on-off the device using a computer and write software for it (which I am confident I can do if I had references to how the wrappers to said interface). Cheers Astan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Jan 23 03:06:47 2009 From: http (Paul Rubin) Date: 23 Jan 2009 00:06:47 -0800 Subject: Counter Class -- Bag/Multiset References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> Message-ID: <7xtz7qxx7s.fsf@ruckus.brouhaha.com> msrachel.e at gmail.com writes: > how do you guys like the functionality? Do you find it useable in > real-world use cases? It's interesting. I wouldn't have thought of that API--I'm used to populating defaultdict(int) in the obvious ways for this sort of thing--but it is attractive and I think it will be useful. Thanks for implementing it. From bearophileHUGS at lycos.com Fri Jan 23 03:24:35 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 23 Jan 2009 00:24:35 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Raymond Hettinger: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. Very nice. Python std lib is growing more data structures, increasing the power of a default Python installation. I can remove more and more modules from my bag of tricks. I like the name Bag(), it's shorter. Names are important enough. Are keys restricted to be long and int values only? Or are they general (referenced) objects + a control of their integral nature? I think you can add better explanations to this, like an example: c += Counter() # remove zero and negative counts Bye, bearophile From bearophileHUGS at lycos.com Fri Jan 23 03:27:03 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 23 Jan 2009 00:27:03 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: bearophile: > Are keys restricted to be long and int values only? Or are they > general (referenced) objects + a control of their integral nature? Here I meant values, sorry. Also: what's the rationale of allowing negative values too? Bye, bearophile From kay.schluehr at gmx.net Fri Jan 23 03:50:48 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Fri, 23 Jan 2009 00:50:48 -0800 (PST) Subject: The First Law Of comp.lang.python Dynamics References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <09145357-8981-4edf-b60a-25eadf156c14@l37g2000vba.googlegroups.com> On 23 Jan., 08:13, Philip Semanchuk wrote: > On Jan 23, 2009, at 12:39 AM, Kay Schluehr wrote: > > > Whatever sufficiently sophisticated topic was initially discussed > > it ends all up in a request for removing reference counting and the > > GIL. > > Is this a variant of Godwin's Law for Python? Definitely. It's a stable fixed point attractor. No matter how often it was discussed to dead in the past months the likelihood that someone mentions the GIL or ref-counting approaches 1. This is particularly remarkable because it is inverse proportional to the observable activity in this domain so there are really no news. Other similarly strange phenomena: whenever Xah Lee posts one of his infamous rants it attracts at least a dozen of newsgroup readers that try to persuade each other not to respond which will inevitably grow his thread and keep it alive for a long time. From msrachel.e at gmail.com Fri Jan 23 03:53:04 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Fri, 23 Jan 2009 00:53:04 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: <28ce2af4-350d-44bc-9877-2474fcf93ea6@u18g2000pro.googlegroups.com> On Jan 23, 12:27?am, bearophileH... at lycos.com wrote: > bearophile: > > > Are keys restricted to be long and int values only? Or are they > > general (referenced) objects + a control of their integral nature? > > Here I meant values, sorry. > Also: what's the rationale of allowing negative values too? The dict values can be anything, but only ints make sense in the context of bags/multisets/counters etc. Since it is a dict subclass, we really have no control of the content. It's pretty much a "consenting adults" data structure (much like the heapq module which cannot enforce a heap condition on the underlying list which is exposed to the user). To block negative values, the setter methods would have to be overridden and would dramatically slow down the major use cases for counters (and we would not be able to let people freely convert to and from arbitrary dicts). Also, we would have to introduce and document some kind of exception for attempts to set a negative value (i.e. c[x] -= 1 could raise an exception). This would unnecessarily complicate the API in an attempt to limit what a user can do (perhaps barring them from a use case they consider to be important). So, if you don't want negative counts, I recommend that you don't subtract more than you started off with ;-) Raymond From tjreedy at udel.edu Fri Jan 23 04:03:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 04:03:54 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> Message-ID: msrachel.e at gmail.com wrote: > The term counter was what was originally approved. At first, I didn't > like it but found that it had some advantages. The main advantage is > that there are *bazillions* of programmers (including some very good > ones) who have never heard the term multiset or bag but have an > instant, > intuitive understanding of counting and counters. > > Also, in the context of this implementation, "multiset" would not be a > good choice. The mathematical entity, multiset, is defined with > elements > having a count of one or more. In contrast, the Counter class allows > counts to go to zero or become negative. In addition, I worried that > calling it a multiset would suggest that it has a set-like API instead > of a dict-like API. With the former, you write c.add(elem). With the > latter, you write c[elem] += 1. So the name, "multiset" would be > misleading. Agreed. I withdraw my objection. From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:05:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:05:31 +0100 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: <49798849$0$5147$426a74cc@news.free.fr> atleta a ?crit : > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, Why so ? And what does your API documentation says about this session object? > at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Is this object _safely_ usable as a key somehow ? And if yes, do you have a way to deal with stale sessions ? > Which one is the > 'pythonic' way? The simplest. But as far as I'm concerned, I don't have enough context to say which one it would be here. > Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? Depends - cf above. But as a guideline, unless the library provides a defined way to solve this problem or the library documentation clearly states I should *not* store my own data in the session object (but then what's the point of a session object ???), I'd just use it. From tjreedy at udel.edu Fri Jan 23 04:10:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 04:10:20 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Also: what's the rationale of allowing negative values too? I can guess two: 1) Nuisance to check given that Python does not have a count (0,1,2...) type. 2. Useful. + = items on hand; - = items back-ordered. Bank account go negative also ;-). So does elevation. Similarly, an app could set 0 to mean 'desired quantity on hand', so non-zero count is surplus or deficit. I might not have thought to allow this, but it seems to open new applications. (This definitely makes bag or multiset inappropriate as names.) tjr From fizzotti at gmail.com Fri Jan 23 04:13:24 2009 From: fizzotti at gmail.com (fizzotti at gmail.com) Date: Fri, 23 Jan 2009 01:13:24 -0800 (PST) Subject: problem with special characters in filename Message-ID: using: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Hello I have two files (let's assume they are all in the same directory): 1) "a.dat" containing the single line "S?bastien.dat" 2) "S?bastien.dat" containing arbitraty data I want to: open "a.dat" read in the single line ("S?bastien.dat") copy the file described by the single line ("S?bastien.dat") to another location with name "b.dat" This is what I have started with: import shutil file = open('a.dat','r') #opens file for reading for line in file: print line old_name = line[0:len(line)-1] #gets rid of "\n" suffix print old_name shutil.copy(old_name, 'b.dat') #copies file However I get the following error: IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' I'm sure this has something to do with encoding and decoding UTF-8 and Unicode or something like that, but everything I've tried has yet to produce any favourable results. Thanks Dino From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:13:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:13:36 +0100 Subject: Idea to support public/private. In-Reply-To: References: Message-ID: <49798a2e$0$14318$426a34cc@news.free.fr> Brian Allen Vanderburg II a ?crit : > Okay so I don't really care about public/private but I was watching the > lists (Does python follow its idea of readability or something like > that) and I thought of a 'possible' way to add this support to the > language. It has already been done at least a couple times. From muralimkrishan26 at yahoo.com Fri Jan 23 04:46:59 2009 From: muralimkrishan26 at yahoo.com (Murali Murali) Date: Fri, 23 Jan 2009 01:46:59 -0800 (PST) Subject: problem with special characters in filename References: Message-ID: <435705.96824.qm@web59702.mail.ac4.yahoo.com> Try this: import shutil,os file1 = open('a.dat','r') #opens file for reading for line in file1: print line ## old_name = line[0:len(line)-1] #gets rid of "\n" suffix ## print old_name line.strip() #gets rid of "\n" suffix print line os.rename('b.dat',line) #renames file file1.close() ________________________________ From: "fizzotti at gmail.com" To: python-list at python.org Sent: Friday, January 23, 2009 2:43:24 PM Subject: problem with special characters in filename using: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Hello I have two files (let's assume they are all in the same directory): 1) "a.dat" containing the single line "S?bastien.dat" 2) "S?bastien.dat" containing arbitraty data I want to: open "a.dat" read in the single line ("S?bastien.dat") copy the file described by the single line ("S?bastien.dat") to another location with name "b.dat" This is what I have started with: import shutil file = open('a.dat','r') #opens file for reading for line in file: print line old_name = line[0:len(line)-1] #gets rid of "\n" suffix print old_name shutil.copy(old_name, 'b.dat') #copies file However I get the following error: IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' I'm sure this has something to do with encoding and decoding UTF-8 and Unicode or something like that, but everything I've tried has yet to produce any favourable results. Thanks Dino -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From zzbbaadd at aol.com Fri Jan 23 04:48:32 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Fri, 23 Jan 2009 01:48:32 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> > > * No getters and setters. Python takes a very permissive approach to > class attributes, taking the philosophy "we're all adults here". It's > easy to change a public attribute to a private attribute with a getter/ > setter if you need to, so there's nothing to be gained by writing getters > for straight attribute access. It just makes things slow. If adding a getter/setter made data private, then per a tenet of Object Oriented Programming, there would be something to be gained from it. But I don't see getter/setters would do that. The statically typed object oriented languages, like Java, C++ and C#, all permit member data and functions to be public - allowing a programmer to implement a "we're all adults here" programming philosophy if they so choose. However, they also allow a programmer to make member data and functions private, thus allowing the implementation one of the tenets of OOP. I don't use Ruby, a dynamically typed language like Python, but from a web search it appears that Ruby does allow at least data to be declared private. But it appears that a user of a class can get around this private declaration by writing their own methods and adding them to the class dynamically. In his book "Core Python Programming", noted Python expert and PyCon speaker Wesley J. Chun makes the following statements regarding one of the main principles of Object Oriented Programming (OOP): "Encapsulation/Interfaces Encapsulation describes the concept of data/information hiding and providing interfaces or accessor functions to the data attributes. Direct access to data by any client, bypassing the interfaces, goes against the principles of encapsulation, but the programmer is free to allow such access. As part of the implementation, the client should not even know how the data attributes are architected within the abstraction. In Python, all class attributes are public but names may be "mangled" to discourage unauthorized access, but otherwise not prevented. It is up to the designer to provide the appropriate interfaces to the data so that the client programmer does not have to resort to manipulating the encapsulated data attributes." From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:54:53 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:54:53 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01892202$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <497993db$0$6847$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > >> Steven D'Aprano writes: >> >>> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >>>> Steven D'Aprano a ?crit : >>>>> But if you have free access to attributes, then *everything* is >>>>> interface. >>>> Nope. >>> How could anyone fail to be convinced by an argument that detailed and >>> carefully reasoned? >> Well, your claim /was/ just wrong. But if you want to play dumb: the >> interface is what's documented as being the interface. > > But you miss my point. > > We're told Python doesn't have private attributes. Yes. > We're told that we're > allowed to "mess with the internals", Given that we're willing and able to cope with possible consequences. > we're *encouraged* to do so Certainly not. > Python > gives you the freedom to do so, and any suggestion that freedom might be > reduced even a tiny bit is fought passionately. Won't comment on this. > When people ask how to > implement private attributes, they're often told not to bother even using > single-underscore names. "often" ? Not as far as I can tell. I think you're confusing this with the advice to not use getters/setters for no good reason, given Python's support for computed attributes - which is not exactly the same thing. > When it is suggested that Python should become > stricter, with enforced data hiding, the objections come thick and fast: > people vehemently say that they like Python just the way it is, that they > want the ability to mess with the internals. Indeed. There's no shortage of B&D languages, and well, Python is OSS, so if you want a B&D Python (now that's an oxymoron), please feel free to implement it. But by all mean, leave my favorite language alone. Thanks. > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to mess > with the private attributes. > In context, I had just mentioned that lists' > internals were inaccessible from Python code. I neglected to give an > example at the time, but a good example is the current length of the > list. Consider the experience of Microsoft and Apple. Yes, two great examples of freedom champions. > No matter how often > they tell people not to mess with the internals, people do it anyway, and > always believe that their reason is a good reason. And who are *you* to pronounce any judgement about that ? > And Python culture encourages that behaviour (albeit the consequences are > milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. Indeed. A *very* good thing FWIW. > You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. Exactly. > And then you have at least two places in the standard library where > _attributes are *explicitly* public: > > http://bugs.python.org/issue3152 > > Given this permissive culture, any responsible For your personal definition of "responsible". > library writer must assume > that if he changes his so-called "private" attributes, he will break > other people's code. You still don't get the point. If someone's code breaks because he messed with my implementation code, then *he* is responsible. The contract is very clear : "warranty void if unsealed". > In principle it could break just as much code as if > he didn't even bother flagging them with a leading underscore, which is > probably why many people don't even bother with _names. > > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them to > mess with your internals, then you don't have internals. Everything is de > facto public. Now that you've exposed your opinions, let's face reality (I mean, *facts*): Python developpers very rarely mess with implementation, usually do so for very good (and documented) reasons, and from what I've seen usually tend to get in touch with the library author to explain their case and find a better solution. Funny enough, it looks that the more you treat programmers as responsible, normally intelligent adult person, the more they tend to behave as such. And the other way around, too. Now, you comprehensively exposed your personnal distaste for Python's and more generally OSS philosophy. So I can only - as I already did way before in this thread - wonder *why* are you using Python ? I mean, is it because your bosses forces you to do so ? If yes, then, I'm truly sorry for you - I sometimes have to work with languages I really dislike so I can feel your pain (but OTHO, I never complained on these languages newsgroups about how wrong they were nor how they should IMHO be). Else, well, I just don't get the point. What you are fussing about are fundamental design choices (and philosophic points) that are well known, explained, advertized, etc. - and are really not likely to change anytime soon. From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:56:56 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:56:56 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <49770f51$0$743$426a74cc@news.free.fr> <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> Message-ID: <49799455$0$6847$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 21, 4:04 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Russ P. a ?crit : >> (snip) >> >>> Your mistake for being a moron. But it seems to happen regularly, >>> doesn't it. How much more of my time are you going to waste, loser? >> Calling people names is certainly not the best way to defend your >> opinions here. Adios, Mr. P. > > You are absolutely right, Mr. D. I regret that post, and I have since > apologized to the person I was addressing. This stuff really isn't > important enough to get that worked up about. > Ok, so welcome back then. From kt83313 at gmail.com Fri Jan 23 05:00:03 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 02:00:03 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: On Jan 23, 12:38?pm, "Diez B. Roggisch" wrote: > kt83... at gmail.com schrieb: > > > > > My company provides some services online, which now they are planning > > to make it offline and sell to customers who can use it in their > > networks. > > > One of our major moneywinners is some data which is stored in a > > database. Now, this data inside the database was obtained after paying > > through the nose - so the company does not want to disclose the data > > in the DB to the outside world - not to mention the lawsuits which the > > original providers of data will start which will sink the company if > > the data goes out. > > > Now, the code is in Python - and we have a big problem. How to secure > > the data in DB? One idea was to encrypt it and store the password in > > the code. I dont believe security through obscurity - and python code > > can easily be reverse-engineered too - right? > > > Is it even possible to secure a data in this case? > > No. And that has nothing to do with python. If the data is valuable, it > will be decyphered from a compiled piece of code in no time. Believe me, > I work for a company that sells a C++-software with protective measures > of various kinds. It gets hacked. Fact of live. > > You could try and raise the bar, as e.g. skype does, with an onion-kind > of code-encryption-scheme. But even *that* is analyzed. And it is > nothing that is done easily and without major impact on your source, so > you might need quite a bit of time to get it right. Is that covered by > the expected revenues? > > And even if one doesn't want to hack into the system, if there is an > interface to the data, who stops your users from exploiting that > automatically to access all the data in the DB somehow? > > Diez Thank you very much Diez. This was my fear. Anyways, if we can make it real hard for them to analyze also, I think we are in the good - esp since the clients are not extremely rich enough to go for professional analyzers -- What is the skype method? The code is not huge - less than 20K LOC so, code encryption looks somewhat OK - would you be able to direct me to any hints on this? One another option that I was thinking was to automatically generate the password for the database - re-encrypt every 1 hr - and store the password inside the code itself. Is that possible in Python? i.e. changing the code itself. KT -- From deets at nospam.web.de Fri Jan 23 05:01:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:01:23 +0100 Subject: problem with special characters in filename In-Reply-To: References: Message-ID: <6ttirjFcfomeU1@mid.uni-berlin.de> fizzotti at gmail.com schrieb: > using: > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > > > Hello > > I have two files (let's assume they are all in the same directory): > > 1) "a.dat" containing the single line "S?bastien.dat" > 2) "S?bastien.dat" containing arbitraty data > > I want to: > > open "a.dat" > read in the single line ("S?bastien.dat") > copy the file described by the single line ("S?bastien.dat") to > another location with name "b.dat" > > This is what I have started with: > > import shutil > > file = open('a.dat','r') #opens file for reading > for line in file: > print line > old_name = line[0:len(line)-1] #gets rid of "\n" suffix > print old_name > shutil.copy(old_name, 'b.dat') #copies file > > However I get the following error: > IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' > > I'm sure this has something to do with encoding and decoding UTF-8 and > Unicode or something like that, but everything I've tried has yet to > produce any favourable results. You need to know two things: - what encoding has the a.dat-content? - what encoding uses your filesystem? Then you need to decode the file's contents with the first one, and then encode it with the second one. The above at least applies to Linux. I'm not sure about windows - I *know* they have wide-char/unicode support, but I'm not sure how exactly that is exposed via the python file apis Diez From deets at nospam.web.de Fri Jan 23 05:12:29 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:12:29 +0100 Subject: problem with special characters in filename In-Reply-To: <6ttirjFcfomeU1@mid.uni-berlin.de> References: <6ttirjFcfomeU1@mid.uni-berlin.de> Message-ID: <6ttjgcFcav4eU1@mid.uni-berlin.de> > > The above at least applies to Linux. I'm not sure about windows - I > *know* they have wide-char/unicode support, but I'm not sure how exactly > that is exposed via the python file apis Just found this: http://www.amk.ca/python/howto/unicode there is a seciton about filenames and OSes in there, you should read it. Diez From deets at nospam.web.de Fri Jan 23 05:19:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:19:20 +0100 Subject: Securing a database In-Reply-To: References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: <6ttjt8Fco8vrU1@mid.uni-berlin.de> > Thank you very much Diez. > This was my fear. > Anyways, if we can make it real hard for them to analyze also, I think > we are in the good - esp since the clients are not extremely rich > enough to go for professional analyzers -- > What is the skype method? The code is not huge - less than 20K LOC so, > code encryption looks somewhat OK - would you be able to direct me to > any hints on this? 20LOC of pyhon translates to the tenfold in a compiled language I'd guess. And all I know about the skype-protection I've read from some paper of some french researches - I think. However, that paper was about *breaking* the encryption, not about how to write it. And I'm not an expert in these matters, mind you. > One another option that I was thinking was to automatically generate > the password for the database - re-encrypt every 1 hr - and store the > password inside the code itself. Is that possible in Python? i.e. > changing the code itself. But wherefrom do you get the *initial* password, or the one used the last time? What happens if the process dies unexpectedly, leaving the db in an undefined, half-crypted state with no way to know the new password? Seriously - if I was assigned the task of doing this thing, I'd seek help from somebody who has experience in these matters. It's hard to get right, and easy to get wrong but think one has it right. Diez From eduardo.padoan at gmail.com Fri Jan 23 05:47:35 2009 From: eduardo.padoan at gmail.com (Eduardo O. Padoan) Date: Fri, 23 Jan 2009 08:47:35 -0200 Subject: A different kind of interface In-Reply-To: <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> Message-ID: On Thu, Jan 22, 2009 at 5:01 PM, wrote: > Eduardo O. Padoan: >> You are almost *describing* reinteract: > > - Thank you for the link and the software, I have not tried it yet, > but from the screencast it looks quite nice. > - I am glad that there are people that don't think that Emacs is > (despite being good) the alpha and omega of editing. There's space for > other ideas beside Emacs. But it is! > - Maybe I was describing reinteract there, but that's only the first > part of my post :-) > - I can see that reinteract is based on a interaction style quite > similar to the shell of Mathematica. I was talking about something > different, and more similar to TextCalc, but in the end I think > reinteract may be good enough for my purposes, so I'll try to run it. > And I may be happy enough. I dont known TextCalc, but I guess that reinteract is flexible enough to the general purpose of "experimenting with Live code". > - Eventually I may find the time and will to create my "interactive > python text" :-) I think there's space for many different solutions. > - Despite many years of experiments, development, shells, editors, and > the like, I am sure there are other designs not yet tried or not > common enough yet (beside the normal editors, shells, smart object- > oriented graphical shells like hotwire shell, Resolver One, and few > other weird things, like one where you can zoom text and images at > different scales, other text-based systems, etc). Sure, thats the spirit. > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky From muralimkrishan26 at yahoo.com Fri Jan 23 06:00:51 2009 From: muralimkrishan26 at yahoo.com (Murali Murali) Date: Fri, 23 Jan 2009 03:00:51 -0800 (PST) Subject: Need script to download file from a server using python script Message-ID: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Hi, I am fairly new to python and i am looking for a python script to download file(latest build) from the server. But, the build name changes daily. For Ex: today the build URL will be "http://mybuilds/myapp_1234.exe" and tomorrow it will be "http://myserver/mybuilds/myapp_3456.exe". So i need a script which downloads the latest build without any knowledge of build number. Can anyone help me? Advance thanks, This is my start: ################################################################### import os,sys,httplib,time, Server="myserver" Build2Download=mybuilds/myapp_3456.exe installer=myapp_3456.exe print "Downloading Installer... from the site:%s"%Server connection=httplib.HTTPConnection(Server) connection.request("GET",Build2Download) resp = connection.getresponse() if resp.status != 200: print "Error getting installer. GET response : %d %s" % (resp.status, resp.reason) sys.exit(-1) try: open(Installer, 'wb').write(resp.read()) time.sleep(15) except: pass ################################################################### The build number keeps changing. So how can i use wildchars(?) or something else to handle change in the build no.? Advance Thanks, Murali. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kt83313 at gmail.com Fri Jan 23 06:01:13 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 03:01:13 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <6ttjt8Fco8vrU1@mid.uni-berlin.de> Message-ID: <85dd7def-4f4f-4fcb-aa6d-b380909ce089@z27g2000prd.googlegroups.com> On Jan 23, 3:19?pm, "Diez B. Roggisch" wrote: > > Thank you very much Diez. > > This was my fear. > > Anyways, if we can make it real hard for them to analyze also, I think > > we are in the good - esp since the clients are not extremely rich > > enough to go for professional analyzers -- > > What is the skype method? The code is not huge - less than 20K LOC so, > > code encryption looks somewhat OK - would you be able to direct me to > > any hints on this? > > 20LOC of pyhon translates to the tenfold in a compiled language I'd guess. > > And all I know about the skype-protection I've read from some paper of > some french researches - I think. However, that paper was about > *breaking* the encryption, not about how to write it. > > And I'm not an expert in these matters, mind you. > > > One another option that I was thinking was to automatically generate > > the password for the database - re-encrypt every 1 hr - and store the > > password inside the code itself. Is that possible in Python? i.e. > > changing the code itself. > > But wherefrom do you get the *initial* password, or the one used the > last time? What happens if the process dies unexpectedly, leaving the db > in an undefined, half-crypted state with no way to know the new password? > > Seriously - if I was assigned the task of doing this thing, I'd seek > help from somebody who has experience in these matters. It's hard to get > right, and easy to get wrong but think one has it right. > > Diez I agree Diez. Anyways, code encryption seems to be a fun thing. I will try to see whether some papers about Skype is running around. If I can get it done, then maybe I will try to post the code here. KT -- From python.list at tim.thechases.com Fri Jan 23 06:12:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 23 Jan 2009 05:12:35 -0600 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: <4979A623.3040906@tim.thechases.com> > The build number keeps changing. So how can i use wildchars(?) > or something else to handle change in the build no.? Short answer: you can't...HTTP doesn't support wild-card requests. Longer answer: presumably there's some method to the madness of naming the file. Find the algorithm and use it. It might be that the URL is available in some other page, so you have to get that page, scrape it for the URL pattern, and then use the resulting URL as your input. It might be that the filename moves around because of some complex algorithm you may (or may not) have access too. If you have access to the algorithm, use it. If not, it might be that the source is trying to make it hard for people to do exactly what you're doing by randomly moving the file around on the website in which case, be nice. -tkc From mrkafk at gmail.com Fri Jan 23 06:17:41 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 12:17:41 +0100 Subject: seeking to improve Python skills Message-ID: Hello everyone, I wrote the following program mainly for educational purpose of improving my Python programming skills -- would Pythonistas here please look at it and point out areas that could use improvement? This thing analyzes the stored load average record file, calculates simple moving average and produces Gnuplot program to plot the thing. Constructive criticism is welcome. #!/usr/bin/python import re import sys import tempfile import subprocess import os class MovingAvg(object): def __init__(self, fname): try: self.fo = open(fname) except IOError, e: print "Problem with opening file:", e sys.exit(4) self.reslist = [] self.smalist = [] self.maxval = 0 def extrfromfile(self): vre = re.compile("(\d+-\d+-\d+) (\d\d:\d\d) (\d+\.\d+)") for line in self.fo: res = vre.search(line) if res: self.reslist.append({'day':res.group(1),\ 'time':res.group(2),\ 'val':float(res.group(3))}) def calc_sma(self, smalen=4): if smalen == 0: raise AssertionError, "Moving Average sample length cannot be 0" if not isinstance(smalen, int): raise AssertionError, "Moving Average sample length has to be integer" total = 0 total = sum( [ x['val'] for x in self.reslist[0:smalen] ] ) sma = total / smalen smaidx = int(smalen/2) self.smalist.append((self.reslist[0]['day'],\ self.reslist[0]['time'],\ self.reslist[0]['val'],\ self.reslist[0]['val'])) for i in range(smalen, len(self.reslist)): curval = self.reslist[i]['val'] self.maxval = max(self.maxval, curval) total += curval total -= self.reslist[i - smalen]['val'] sma = total / smalen smaidx += 1 self.smalist.append((self.reslist[smaidx]['day'],\ self.reslist[smaidx]['time'],\ self.reslist[smaidx]['val'],\ sma)) def return_results(self): return (self.reslist, self.smalist, self.maxval) class GnuplotWrapper(object): def __init__(self, smalist, maxval, outfname = "calc.png", graphlen=640, graphheight=480, gnuplot = '/usr/bin/gnuplot'): self.outfname = outfname self.smalist = smalist self.gnuplot = gnuplot self.gprog = None self.gdata = None self.graphlen = graphlen self.graphheight = graphheight def _writefiles(self): self.gprog = tempfile.mkstemp() self.gdata = tempfile.mkstemp() self.gprogfile = open(self.gprog[1], 'wb') self.gdatafile = open(self.gdata[1], 'wb') labelnum = int(self.graphlen / 110) labelstep = int(len(self.smalist) / labelnum) labels = [] for i in range(0, len(self.smalist), labelstep): labels.append("\"%s %s\" %d" % (self.smalist[i][0], self.smalist[i][1], i)) labelstr = ", ".join(labels) self.gprogfile.write("""set terminal png size %d, %d set style line 1 lt 1 lw 2 set style line 2 lt 2 lw 2 set output "%s" set xtics(%s) set yrange [0:%f] set y2range [0:%f] plot "%s" using 1 with lines ls 1 title "orig" axes x1y1, "%s" using 2 with lines ls 2 title "Moving Average" axes x1y2 """ % (self.graphlen, self.graphheight, self.outfname, labelstr, float(maxval), float(maxval),\ self.gdata[1], self.gdata[1]) ) self.gprogfile.close() for elem in self.smalist: self.gdatafile.write("%f, %f\n" % (elem[2], elem[3])) self.gdatafile.close() def plot(self): self._writefiles() gplot = subprocess.Popen(self.gnuplot + " " + self.gprog[1],\ shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print "Plotting data (%s)..." % self.outfname so, se = gplot.communicate() if se: print "Gnuplot problem output:", se os.remove(self.gprog[1]) os.remove(self.gdata[1]) if __name__ == "__main__": try: fname = sys.argv[1] except IndexError: print "Specify filename with data as first argument." sys.exit(1) except Exception, e: print "Error:", e sys.exit(2) values = MovingAvg(fname) values.extrfromfile() values.calc_sma(smalen = 10) (reslist, smalist, maxval) = values.return_results() gp = GnuplotWrapper(smalist, maxval) gp.plot() Example data: 08-11-19 12:41 0.11 0.45 0.40 2/158 27091 08-11-19 12:42 0.08 0.43 0.39 9/171 27113 08-11-19 12:43 0.57 0.53 0.43 4/163 12350 08-11-19 12:44 0.21 0.43 0.40 8/176 12422 08-11-19 12:45 0.08 0.36 0.37 6/166 12507 08-11-19 12:46 0.66 0.51 0.43 4/163 30147 08-11-19 12:47 0.32 0.43 0.40 4/163 30195 08-11-19 12:48 0.12 0.35 0.37 9/174 30263 08-11-19 12:49 0.47 0.43 0.40 6/162 15513 08-11-19 12:50 0.17 0.35 0.37 2/159 15562 08-11-19 12:51 0.11 0.30 0.35 6/162 15613 08-11-19 12:52 0.68 0.47 0.41 5/161 779 08-11-19 12:53 0.25 0.38 0.38 4/161 859 08-11-19 12:54 0.16 0.33 0.36 9/174 927 08-11-19 12:55 0.62 0.44 0.39 5/166 18633 08-11-19 12:56 0.36 0.42 0.39 6/162 18672 08-11-19 12:57 0.23 0.37 0.37 5/163 18757 08-11-19 12:58 0.56 0.46 0.40 4/161 4026 08-11-19 12:59 0.26 0.39 0.37 4/220 4134 08-11-19 13:00 0.16 0.33 0.35 7/169 4232 08-11-19 13:01 0.56 0.44 0.39 1/162 21882 08-11-19 13:02 0.22 0.37 0.36 4/161 21921 08-11-19 13:03 0.14 0.32 0.35 5/163 21972 08-11-19 13:04 0.78 0.53 0.42 5/173 7246 08-11-19 13:05 0.34 0.45 0.40 5/163 7299 08-11-19 13:06 0.20 0.39 0.38 5/167 7369 08-11-19 13:07 0.54 0.48 0.41 5/165 24993 08-11-19 13:08 0.25 0.40 0.38 8/174 25071 08-11-19 13:09 0.18 0.36 0.36 6/168 25148 08-11-19 13:10 0.54 0.45 0.39 5/172 10397 08-11-19 13:11 0.27 0.39 0.37 4/167 10440 08-11-19 13:12 0.22 0.36 0.36 5/168 10517 08-11-19 13:13 1.05 0.67 0.47 4/169 28210 08-11-19 13:14 0.46 0.56 0.44 6/172 28266 08-11-19 13:15 0.17 0.45 0.41 6/172 28346 08-11-19 13:16 0.63 0.55 0.45 5/171 13597 08-11-19 13:17 0.42 0.53 0.45 4/172 13679 08-11-19 13:18 0.20 0.44 0.42 5/172 13735 08-11-19 13:19 0.59 0.54 0.45 4/170 31370 08-11-19 13:20 0.21 0.44 0.42 5/172 31431 08-11-19 13:21 0.08 0.36 0.40 6/172 31511 08-11-19 13:22 0.64 0.51 0.45 4/172 16756 08-11-19 13:23 0.23 0.42 0.42 4/172 16804 08-11-19 13:24 0.13 0.35 0.40 9/185 16881 08-11-19 13:25 0.64 0.48 0.44 5/174 2074 08-11-19 13:26 0.26 0.40 0.41 4/172 2120 08-11-19 13:27 0.14 0.34 0.39 5/174 2176 08-11-19 13:28 0.64 0.47 0.43 6/174 19887 08-11-19 13:29 0.23 0.38 0.40 4/172 19972 08-11-19 13:30 0.12 0.32 0.38 4/182 20042 08-11-19 13:31 0.80 0.51 0.44 6/174 5302 08-11-19 13:32 0.29 0.42 0.41 6/173 5360 08-11-19 13:33 0.11 0.34 0.38 5/174 5446 08-11-19 13:34 0.46 0.42 0.40 4/172 23086 08-11-19 13:35 0.22 0.36 0.38 5/172 23137 08-11-19 13:36 0.28 0.38 0.39 7/175 23188 08-11-19 13:37 0.62 0.49 0.42 4/172 8464 08-11-19 13:38 0.28 0.41 0.40 4/172 8512 08-11-19 13:39 0.10 0.33 0.37 6/175 8571 08-11-19 13:40 0.51 0.42 0.39 6/173 26216 08-11-19 13:41 0.18 0.34 0.37 4/172 26296 08-11-19 13:42 0.07 0.28 0.34 6/173 26345 08-11-19 13:43 0.49 0.38 0.37 5/172 11590 08-11-19 13:44 0.25 0.33 0.35 6/173 11639 08-11-19 13:45 0.09 0.26 0.33 8/179 11747 08-11-19 13:46 0.58 0.40 0.37 4/175 29375 08-11-19 13:47 0.27 0.34 0.35 4/175 29423 08-11-19 13:48 0.10 0.28 0.33 6/176 29472 08-11-19 13:49 0.55 0.40 0.37 4/174 14752 08-11-19 13:50 0.20 0.33 0.34 4/170 14803 08-11-19 13:51 0.15 0.28 0.32 6/171 14852 08-11-19 13:52 0.52 0.39 0.36 5/172 32488 08-11-19 13:53 0.23 0.33 0.34 4/170 32566 08-11-19 13:54 0.08 0.27 0.32 6/173 32624 08-11-19 13:55 0.50 0.38 0.35 4/172 17880 08-11-19 13:56 0.24 0.32 0.33 6/174 17930 08-11-19 13:57 0.09 0.26 0.31 9/184 18044 08-11-19 13:58 0.51 0.37 0.35 4/167 3383 08-11-19 13:59 0.18 0.30 0.32 4/167 3449 08-11-19 14:00 0.10 0.26 0.30 6/171 3509 08-11-19 14:01 0.50 0.36 0.34 7/168 21261 08-11-19 14:02 0.25 0.32 0.32 7/176 21318 08-11-19 14:03 0.09 0.26 0.30 6/169 21359 08-11-19 14:04 0.59 0.39 0.34 5/170 6613 08-11-19 14:05 0.21 0.31 0.32 5/251 6774 08-11-19 14:06 0.08 0.25 0.29 5/170 6832 08-11-19 14:07 0.59 0.39 0.34 4/168 24469 08-11-19 14:08 0.28 0.34 0.32 6/179 24530 08-11-19 14:09 0.10 0.27 0.30 6/172 24600 08-11-19 14:10 0.55 0.40 0.34 4/175 9857 08-11-19 14:11 0.20 0.32 0.31 4/172 9898 08-11-19 14:12 0.07 0.26 0.29 8/183 9967 08-11-19 14:13 0.51 0.37 0.33 4/169 27631 08-11-19 14:14 0.19 0.30 0.30 4/175 27705 08-11-19 14:15 0.18 0.27 0.29 6/171 27763 08-11-19 14:16 0.65 0.41 0.34 5/171 13019 08-11-19 14:17 0.24 0.34 0.31 7/176 13109 08-11-19 14:18 0.09 0.27 0.29 5/171 13155 08-11-19 14:19 0.46 0.37 0.32 4/169 30800 08-11-19 14:20 0.21 0.31 0.30 5/171 30852 08-11-19 14:21 0.12 0.27 0.28 6/171 30937 08-11-19 14:22 0.52 0.38 0.32 4/167 16174 08-11-19 14:23 0.25 0.32 0.30 4/167 16225 08-11-19 14:24 0.09 0.26 0.28 9/180 16293 08-11-19 14:25 0.47 0.36 0.31 4/175 1505 08-11-19 14:26 0.20 0.30 0.29 4/167 1550 08-11-19 14:27 0.07 0.25 0.27 5/172 1607 08-11-19 14:28 0.73 0.42 0.33 6/169 19351 08-11-19 14:29 0.87 0.55 0.37 4/143 19654 08-11-19 14:30 0.64 0.58 0.40 4/175 19833 08-11-19 14:31 0.91 0.68 0.45 4/166 5087 08-11-19 14:32 0.33 0.56 0.42 6/167 5148 08-11-19 14:33 0.12 0.45 0.39 5/169 5231 08-11-19 14:34 0.56 0.54 0.42 5/247 22939 08-11-19 14:35 0.20 0.44 0.39 7/166 23002 08-11-19 14:36 0.07 0.36 0.36 6/167 23081 08-11-19 14:37 0.49 0.45 0.39 5/169 8374 08-11-19 14:38 0.29 0.40 0.38 6/168 8468 08-11-19 14:39 0.15 0.34 0.35 5/167 8503 08-11-19 14:40 1.07 0.58 0.43 5/177 26164 08-11-19 14:41 0.39 0.47 0.40 4/165 26233 08-11-19 14:42 0.26 0.41 0.39 6/166 26292 08-11-19 14:43 0.68 0.53 0.43 4/163 11539 08-11-19 14:44 0.25 0.43 0.40 6/165 11643 08-11-19 14:45 0.09 0.35 0.37 6/166 11727 08-11-19 14:46 0.55 0.46 0.40 6/167 29357 08-11-19 14:47 0.20 0.37 0.37 4/164 29410 08-11-19 14:48 0.07 0.30 0.35 6/169 29477 08-11-19 14:49 0.70 0.48 0.41 4/174 14803 08-11-19 14:50 0.26 0.39 0.38 4/173 14853 08-11-19 14:51 0.09 0.31 0.35 6/172 14902 08-11-19 14:52 0.52 0.40 0.38 5/173 32535 08-11-19 14:53 0.19 0.33 0.35 4/171 32644 08-11-19 14:54 0.20 0.30 0.34 4/179 32760 08-11-19 14:55 0.74 0.46 0.39 4/168 18204 08-11-19 14:56 0.33 0.39 0.37 5/167 18264 08-11-19 14:57 0.12 0.32 0.34 6/169 18357 08-11-19 14:58 0.50 0.42 0.37 8/174 3640 08-11-19 14:59 0.18 0.34 0.35 4/169 3715 08-11-19 15:00 0.06 0.27 0.33 7/173 3789 08-11-19 15:01 0.56 0.40 0.36 6/175 21475 08-11-19 15:02 0.24 0.34 0.35 7/179 21521 08-11-19 15:03 0.55 0.39 0.36 5/168 22067 08-11-19 15:04 0.76 0.49 0.40 6/171 7328 08-11-19 15:05 0.58 0.46 0.39 4/165 7493 08-11-19 15:06 0.21 0.38 0.36 5/167 7634 08-11-19 15:07 0.60 0.48 0.40 4/165 25276 08-11-19 15:08 0.22 0.39 0.37 9/177 25377 08-11-19 15:09 0.18 0.35 0.35 6/171 25491 08-11-19 15:10 0.58 0.46 0.39 4/173 10780 08-11-19 15:11 0.21 0.37 0.36 4/169 10825 08-11-19 15:12 0.11 0.32 0.34 6/170 10875 08-11-19 15:13 0.43 0.39 0.36 4/168 28534 08-11-19 15:14 0.15 0.31 0.34 4/173 28589 08-11-19 15:15 0.06 0.25 0.32 6/170 28642 08-11-19 15:16 0.52 0.38 0.36 5/169 13930 08-11-19 15:17 0.26 0.32 0.34 5/173 14048 08-11-19 15:18 0.09 0.26 0.31 5/170 14095 08-11-19 15:19 0.55 0.39 0.35 4/167 31724 08-11-19 15:20 0.34 0.35 0.34 5/179 31814 08-11-19 15:21 0.16 0.29 0.32 6/169 31911 08-11-19 15:22 0.64 0.43 0.37 6/167 17277 08-11-19 15:23 0.29 0.36 0.35 4/163 17388 08-11-19 15:24 0.16 0.31 0.33 6/166 17460 08-11-19 15:25 0.48 0.40 0.36 3/188 2923 08-11-19 15:26 0.62 0.47 0.38 4/195 3159 08-11-19 15:27 0.81 0.55 0.41 6/207 3261 08-11-19 15:28 0.77 0.61 0.44 5/208 20910 08-11-19 15:29 0.32 0.51 0.42 4/206 20992 08-11-19 15:30 0.11 0.41 0.39 6/208 21046 08-11-19 15:31 0.53 0.50 0.42 7/204 6333 08-11-19 15:32 0.19 0.40 0.39 5/205 6389 08-11-19 15:33 0.12 0.34 0.37 3/206 6500 08-11-19 15:34 0.43 0.41 0.39 6/198 24105 08-11-19 15:35 0.20 0.35 0.36 5/204 24164 08-11-19 15:36 0.07 0.28 0.34 6/201 24210 08-11-19 15:37 0.49 0.39 0.37 5/206 9525 08-11-19 15:38 0.22 0.33 0.35 4/197 9564 08-11-19 15:39 0.14 0.28 0.33 6/198 9613 08-11-19 15:40 0.48 0.38 0.36 6/199 27246 08-11-19 15:41 0.17 0.31 0.34 4/199 27345 08-11-19 15:42 0.06 0.25 0.31 4/235 27433 08-11-19 15:43 0.50 0.36 0.35 5/199 12705 08-11-19 15:44 0.18 0.29 0.33 12/211 12765 08-11-19 15:45 0.06 0.24 0.30 6/202 12839 08-11-19 15:46 0.54 0.37 0.34 6/199 30464 08-11-19 15:47 0.20 0.30 0.32 4/199 30512 08-11-19 15:48 0.11 0.25 0.30 10/209 30587 08-11-19 15:49 0.47 0.35 0.33 6/198 15867 08-11-19 15:50 0.17 0.29 0.31 4/198 15918 08-11-19 15:51 0.13 0.25 0.29 6/199 15967 08-11-19 15:52 0.52 0.36 0.33 5/200 1142 08-11-19 15:53 0.19 0.29 0.30 4/198 1220 08-11-19 15:54 0.10 0.25 0.28 8/206 1277 08-11-19 15:55 0.51 0.36 0.32 5/203 19023 08-11-19 15:56 0.24 0.31 0.30 6/198 19056 08-11-19 15:57 0.16 0.27 0.28 5/202 19155 08-11-19 15:58 0.62 0.41 0.33 7/201 4452 08-11-19 15:59 0.23 0.33 0.31 6/210 4509 08-11-19 16:00 0.14 0.28 0.29 6/202 4551 08-11-19 16:01 0.53 0.39 0.32 4/200 22211 08-11-19 16:02 0.29 0.35 0.31 5/209 22271 08-11-19 16:03 0.11 0.28 0.29 5/200 22325 08-11-19 16:04 0.38 0.34 0.31 6/199 7612 08-11-19 16:05 0.24 0.31 0.30 5/199 7698 08-11-19 16:06 0.15 0.27 0.28 5/200 7754 08-11-19 16:07 0.57 0.39 0.32 5/208 25407 08-11-19 16:08 0.21 0.32 0.29 5/199 25449 08-11-19 16:09 0.07 0.26 0.27 6/199 25530 08-11-19 16:10 0.54 0.38 0.31 5/199 10809 08-11-19 16:11 0.25 0.33 0.30 4/198 10857 08-11-19 16:12 0.09 0.26 0.27 6/199 10906 08-11-19 16:13 0.42 0.35 0.30 4/198 28564 08-11-19 16:14 0.15 0.28 0.28 4/198 28614 08-11-19 16:15 0.09 0.24 0.26 5/199 28666 08-11-19 16:16 0.50 0.36 0.30 8/198 13948 08-11-19 16:17 0.23 0.30 0.28 4/203 14036 08-11-19 16:18 0.16 0.26 0.27 6/199 14080 08-11-19 16:19 0.48 0.36 0.30 7/198 31710 08-11-19 16:20 0.18 0.29 0.27 6/202 31784 08-11-19 16:21 0.06 0.23 0.26 6/199 31846 08-11-19 16:22 0.56 0.37 0.30 4/198 17118 08-11-19 16:23 0.20 0.30 0.28 4/198 17166 08-11-19 16:24 0.11 0.25 0.26 7/200 17221 08-11-19 16:25 0.61 0.40 0.31 6/199 2475 08-11-19 16:26 0.30 0.34 0.29 4/195 2629 08-11-19 16:27 0.11 0.27 0.27 6/196 2716 08-11-19 16:28 0.73 0.44 0.33 7/197 20385 08-11-19 16:29 0.27 0.36 0.30 4/198 20467 08-11-19 16:30 0.16 0.31 0.29 5/199 20520 08-11-19 16:31 0.53 0.41 0.32 6/197 5810 08-11-19 16:32 0.19 0.33 0.30 5/198 5870 08-11-19 16:33 0.11 0.28 0.28 6/206 5972 08-11-19 16:34 0.47 0.38 0.31 4/196 23579 08-11-19 16:35 0.17 0.31 0.29 5/198 23631 08-11-19 16:36 0.12 0.26 0.27 7/199 23681 08-11-19 16:37 1.03 0.52 0.36 5/201 9044 08-11-19 16:38 0.51 0.47 0.35 4/203 9118 08-11-19 16:39 0.23 0.40 0.33 6/206 9204 08-11-19 16:40 0.60 0.50 0.37 11/211 26871 08-11-19 16:41 0.22 0.40 0.35 4/203 26943 08-11-19 16:42 0.08 0.33 0.32 6/209 27037 08-11-19 16:43 0.70 0.47 0.37 5/203 12342 08-11-19 16:44 0.62 0.47 0.37 5/207 12424 08-11-19 16:45 0.26 0.39 0.35 6/206 12510 08-11-19 16:46 0.66 0.51 0.39 4/203 30135 08-11-19 16:47 0.31 0.43 0.37 5/206 30196 08-11-19 16:48 0.17 0.36 0.35 6/205 30243 08-11-19 16:49 0.62 0.49 0.39 5/206 15559 08-11-19 16:50 0.34 0.43 0.37 7/206 15604 08-11-19 16:51 0.12 0.35 0.35 7/209 15655 08-11-19 16:52 0.52 0.44 0.38 5/202 818 08-11-19 16:53 0.22 0.37 0.36 4/206 912 08-11-19 16:54 0.08 0.30 0.33 5/201 955 Regards, mk From Russ.Paielli at gmail.com Fri Jan 23 06:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 03:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> Message-ID: <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> On Jan 23, 1:54?am, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : > > > > > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > > >> Steven D'Aprano writes: > > >>> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > >>>> Steven D'Aprano a ?crit : > >>>>> But if you have free access to attributes, then *everything* is > >>>>> interface. > >>>> Nope. > >>> How could anyone fail to be convinced by an argument that detailed and > >>> carefully reasoned? > >> Well, your claim /was/ just wrong. ?But if you want to play dumb: the > >> interface is what's documented as being the interface. > > > But you miss my point. > > > We're told Python doesn't have private attributes. > > Yes. > > > We're told that we're > > allowed to "mess with the internals", > > Given that we're willing and able to cope with possible consequences. > > > we're *encouraged* to do so > > Certainly not. > > > Python > > gives you the freedom to do so, and any suggestion that freedom might be > > reduced even a tiny bit is fought passionately. > > Won't comment on this. > > > When people ask how to > > implement private attributes, they're often told not to bother even using > > single-underscore names. > > "often" ? Not as far as I can tell. I think you're confusing this with > the advice to not use getters/setters for no good reason, given Python's > support for computed attributes - which is not exactly the same thing. > > > When it is suggested that Python should become > > stricter, with enforced data hiding, the objections come thick and fast: > > people vehemently say that they like Python just the way it is, that they > > want the ability to mess with the internals. > > Indeed. There's no shortage of B&D languages, and well, Python is OSS, > so if you want a B&D Python (now that's an oxymoron), please feel free > to implement it. But by all mean, leave my favorite language alone. Thanks. > > > You even argued that you disliked data structures implemented in C and > > preferred those written in Python because you have more ability to mess > > with the private attributes. > > In context, I had just mentioned that lists' > > internals were inaccessible from Python code. I neglected to give an > > example at the time, but a good example is the current length of the > > list. Consider the experience of Microsoft and Apple. > > Yes, two great examples of freedom champions. > > > No matter how often > > they tell people not to mess with the internals, people do it anyway, and > > always believe that their reason is a good reason. > > And who are *you* to pronounce any judgement about that ? > > > And Python culture encourages that behaviour (albeit the consequences are > > milder: no buffer overflows or core dumps). > > > Add to that the culture of Open Source that encourages reading the source > > code. > > Indeed. A *very* good thing FWIW. > > > You don't need to buy a book called "Undocumented Tips and Tricks > > for Python" to discover the internals. You just need to read the source > > code. > > Exactly. > > > And then you have at least two places in the standard library where > > _attributes are *explicitly* public: > > >http://bugs.python.org/issue3152 > > > Given this permissive culture, any responsible > > For your personal definition of "responsible". > > > library writer must assume > > that if he changes his so-called "private" attributes, he will break > > other people's code. > > You still don't get the point. If someone's code breaks because he > messed with my implementation code, then *he* is responsible. The > contract is very clear : "warranty void if unsealed". > > > > > In principle it could break just as much code as if > > he didn't even bother flagging them with a leading underscore, which is > > probably why many people don't even bother with _names. > > > In other words, if you make it easy for people to mess with your > > internals, if you have a culture that allows and even encourages them to > > mess with your internals, then you don't have internals. Everything is de > > facto public. > > Now that you've exposed your opinions, let's face reality (I mean, > *facts*): Python developpers very rarely mess with implementation, > usually do so for very good (and documented) reasons, and from what I've > seen usually tend to get in touch with the library author to explain > their case and find a better solution. > > Funny enough, it looks that the more you treat programmers as > responsible, normally intelligent adult person, the more they tend to > behave as such. And the other way around, too. > > Now, you comprehensively exposed your personnal distaste for Python's > and more generally OSS philosophy. So I can only - as I already did way > before in this thread - wonder *why* are you using Python ? > > I mean, is it because your bosses forces you to do so ? If yes, then, > I'm truly sorry for you - I sometimes have to work with languages I > really dislike so I can feel your pain (but OTHO, I never complained on > these languages newsgroups about how wrong they were nor how they should > IMHO be). > > Else, well, I just don't get the point. What you are fussing about are > fundamental design choices (and philosophic points) that are well known, > explained, advertized, etc. - and are really not likely to change > anytime soon. I am curious about something. Have you ever needed to access a "private" attribute (i.e., one named with a leading underscore) in Python code that you did not have the source code for? For that matter, have you ever even used a library written in Python without having access to the source code? As I said before, if you have the source code you can always change private attributes to public in a pinch if the language enforces encapsulation. But if you are working on a team project, you can't change the code that another member of a team checks in. That is how enforced data hiding helps teams of developers manage interfaces. The bigger the team and the bigger the project, the more it helps. Mr. D'Aprano gave an excellent example of a large banking program. Without enforced encapsulation, anyone on the development team has access to the entire program and could potentially sneak in fraudulent code much more easily than if encapsulation were enforced by the language. I am certainly not saying that Python is useless without enforced data hiding. It is obviously very useful for a wide range of applications and domains already. I am only saying that it's usefulness could be enhanced if enforced encapsulation can be added without somehow comromising the language. I don't know enough about the inner workings of the Python interpreter to know if that is the case or not (I am an aeronautical engineer), but the objections I've seen so far on this thread have not impressed me. From dsdale24 at gmail.com Fri Jan 23 06:24:59 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Fri, 23 Jan 2009 03:24:59 -0800 (PST) Subject: what gives with References: Message-ID: On Jan 22, 10:07?pm, Benjamin Peterson wrote: > Darren Dale gmail.com> writes: > > > Judging fromhttp://bugs.python.org/issue2400, this issue > > was fixed back in May 2008, but it is still present with python-2.5.4, > > which was released in December. Why wont python-2.5 allow this kind of > > import? > > Allowing that would be a new feature which is disallowed in bug fix releases > like 2.5.4. I was talking about the behavior after doing "from __future__ import absolute_import". I've been developing on python-2.6 using absolute_import for weeks, knowing that I could do "from __future__ import absolute import" on python-2.5. Now when I try to use python-2.5 I cant import my package. What is the point of providing absolute_import in __future__ if the api is completely different than the implementation in future python versions? Its bizarre. From Russ.Paielli at gmail.com Fri Jan 23 06:28:54 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 03:28:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> Message-ID: <240f6259-044f-4090-9406-12948378c8ec@a26g2000prf.googlegroups.com> On Jan 22, 9:22?pm, "Russ P." wrote: > code. You can play around with the internals all you want in your own > little world, but as when you are working with a team, you need to > adhere to the interfaces they define (if any). The word "as" should not be there: ... but when you are working with a team, ... Sorry, but that was bothering me. I sure wish these posts could be edited after they are submitted. From apardon at forel.vub.ac.be Fri Jan 23 06:31:50 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Jan 2009 11:31:50 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: On 2009-01-16, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > >> On Jan 15, 12:21?pm, Bruno Desthuilliers >> wrote: >> >> > Once again, the important point is that there's a *clear* distinction >> > between interface and implementation, and that you *shouldn't* mess with >> > implementation. >> >> If you "*shouldn't* mess with the implementation", then what is wrong >> with enforcing that "shouldn't" in the language itself? > > Because, as a library user, it should be my power to chose when and how I > _should_ mess with the implementation, not the compiler, and definitely not you. Why should it be in your power? By messing with the implementation of a library you risk the correctness of the code of all participant coders in that project. I not that sure it should be your power to chose when and how to do that. -- Antoon Pardon From fakeaddress at nowhere.org Fri Jan 23 06:41:39 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 03:41:39 -0800 Subject: Securing a database In-Reply-To: References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> kt83313 at gmail.com wrote: > Anyways, if we can make it real hard for them to analyze also, I think > we are in the good - esp since the clients are not extremely rich > enough to go for professional analyzers -- Sounds like you have the "digital rights management" (DRM) problem. As Diez pointed out, there is no robust software solution. Nevertheless, many clever people have worked each side, so there's now something of a body of practice and experience. > What is the skype method? The code is not huge - less than 20K LOC so, > code encryption looks somewhat OK - would you be able to direct me to > any hints on this? I don't think Skype has much to offer here. They're not focused on selling DRM technology; they sell communication services. Third parties can write applications on top of those services, which can be protected by Skype's DRM. (If I'm wrong on that, someone please correct me.) Diez's noted Skype's use of a layered approach, but there's nothing special about the notion of layered code encryption in DRM software. It's been used multiple times, broken multiple times, and patented multiple times. > One another option that I was thinking was to automatically generate > the password for the database - re-encrypt every 1 hr - and store the > password inside the code itself. Is that possible in Python? i.e. > changing the code itself. Possible it is. Effective it is almost certainly not, at least not without a whopping bunch of other techniques going vastly beyond that description. Look up DRM technology companies, such as CloakWare, Macrovision, and Cryptography Research. If you have a modest number of customers, hardware solutions and/or strict contractual commitments might offer practical solutions. -- --Bryan From pranny at gmail.com Fri Jan 23 06:50:39 2009 From: pranny at gmail.com (pranav) Date: Fri, 23 Jan 2009 03:50:39 -0800 (PST) Subject: Executing WinXP commands using os module Message-ID: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Greetings, I am writing a code to perform operations like checkout, check-in and others for SS. (SS is the command line utility for Visual SafeSource, VSS). I am familiar with all the commands for this purpose. I know li'l python also. What i want to learn is how do i use the command line arguments in os (or any other call that will fulfill my purpose). I can use popen to create a command prompt. But i need to use commands like ss checkout $\projectName\file -Yusername,password -c'Test comment' Please help me. Thanks in advance, Regards Pranav Prakash http://codecontrol.blogspot.com From rasky at develer.com Fri Jan 23 07:05:02 2009 From: rasky at develer.com (Giovanni Bajo) Date: Fri, 23 Jan 2009 13:05:02 +0100 Subject: Counter Class -- Bag/Multiset In-Reply-To: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> References: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> Message-ID: <4979B26E.4010408@develer.com> On 1/23/2009 2:49 AM, Chris Rebert wrote: > On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: >> On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: >> >>> The collections module in Python 2.7 and Python 3.1 has gotten a new >>> Counter class that works like bags and multisets in other languages. >>> >>> I've adapted it for Python2.5/2.6 so people can start using it right >>> away: >>> http://docs.python.org/dev/library/collections.html#counter-objects >>> >>> Here's a link to the docs for the new class: >>> http://code.activestate.com/recipes/576611/ >> Hi Raymond, >> >> * I'm not a native speaker, but why use the word "Counter"? A "counter" >> to my ear sounds like a number that is increased each time an event >> occurs; the website counter, eg, comes to mind. I can understanda its >> meaning probably stretches to "an object that counts", but I really can't >> think of it as a group of object, or a container of object. Moreover, I >> find it a much more useful abstraction the idea of a "multi-set" (that >> is, a set where elements can appear with multiple cardinality), rather >> than stressing the concept of "counting" how many times each element >> appears in the set. >> >> * I find it *very* confusing c.items() vs c.elements(). Items and >> elements are synonymous (again, in my understanding of English). > > I concur and would like to say additionally that having Counter's > len() be the number of *unique* items as opposed to just the number of > items seems a bit counterintuitive. In fact, I think that it makes sense when you're stressing the fact that it's just a dictionary of objects and their counters (which the name "Counter" in fact stresses). And my main objection is exactly this: a multiset is a differnt abstract data structure (which is probably worth its own ABC in Python); the fact that can be implemented through a mapping of objects and counters is just its concrete implementation. This was perfectly represented by Raymond's previous bag class, that was *using* a dictionary instead of *being* a dictionary. -- Giovanni Bajo Develer S.r.l. http://www.develer.com From clp2 at rebertia.com Fri Jan 23 07:05:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 04:05:50 -0800 Subject: Executing WinXP commands using os module In-Reply-To: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <50697b2c0901230405p62407328g1365e458640e3841@mail.gmail.com> On Fri, Jan 23, 2009 at 3:50 AM, pranav wrote: > Greetings, > I am writing a code to perform operations like checkout, check-in and > others for SS. (SS is the command line utility for Visual SafeSource, > VSS). I am familiar with all the commands for this purpose. I know > li'l python also. > What i want to learn is how do i use the command line arguments in os > (or any other call that will fulfill my purpose). I can use popen to > create a command prompt. But i need to use commands like > > ss checkout $\projectName\file -Yusername,password -c'Test comment' You want the `subprocess` module. See http://docs.python.org/library/subprocess.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From enleverlesX.XmcX at XmclaveauX.com Fri Jan 23 07:05:57 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Fri, 23 Jan 2009 13:05:57 +0100 Subject: Executing WinXP commands using os module In-Reply-To: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <4979b520$0$9423$ba4acef3@news.orange.fr> Hi! Try: os.system("""start "" cmd /css checkout $\projectName\file -Yusername,password -c'Test comment' """) (not tested ; it's directly from my memory) @-salutations -- Michel Claveau From pranny at gmail.com Fri Jan 23 07:08:36 2009 From: pranny at gmail.com (pranav) Date: Fri, 23 Jan 2009 04:08:36 -0800 (PST) Subject: Executing WinXP commands using os module References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <7b1ec291-9b9d-4c93-9b32-edfcb6f9f10b@v39g2000pro.googlegroups.com> On Jan 23, 5:05?pm, Chris Rebert wrote: > On Fri, Jan 23, 2009 at 3:50 AM, pranav wrote: > > Greetings, > > I am writing a code to perform operations like checkout, check-in and > > others for SS. (SS is the command line utility for Visual SafeSource, > > VSS). I am familiar with all the commands for this purpose. I know > > li'l python also. > > What i want to learn is how do i use the command line arguments in os > > (or any other call that will fulfill my purpose). I can use popen to > > create a command prompt. But i need to use commands like > > > ss checkout $\projectName\file -Yusername,password -c'Test comment' > > You want the `subprocess` module. Seehttp://docs.python.org/library/subprocess.html > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanks, will try it From clp2 at rebertia.com Fri Jan 23 07:10:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 04:10:00 -0800 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: <50697b2c0901230410y56473a60xfaf5e57679a3c6bd@mail.gmail.com> On Fri, Jan 23, 2009 at 3:00 AM, Murali Murali wrote: > Hi, > > I am fairly new to python and i am looking for a python script to download > file(latest build) from the server. But, the build name changes daily. For > Ex: today the build URL will be "http://mybuilds/myapp_1234.exe" and > tomorrow it will be "http://myserver/mybuilds/myapp_3456.exe". So i need a > script which downloads the latest build without any knowledge of build > number. > > Can anyone help me? > > Advance thanks, > > This is my start: Not directly related to your main question, but you might want to use urllib.urlretrieve() rather than httplib for the downloading of the file as the interface is a good bit simpler. See http://docs.python.org/library/urllib.html#urllib.urlretrieve for the docs on it. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From unineuro at gmail.com Fri Jan 23 07:28:33 2009 From: unineuro at gmail.com (unineuro at gmail.com) Date: Fri, 23 Jan 2009 04:28:33 -0800 (PST) Subject: Dynamic methods and lambda functions Message-ID: Hi, I want to add some properties dynamically to a class, and then add the corresponding getter methods. Something resulting in this: class Person: def Getname(self): return self.__name def Getage(self): return self.__age I've implemented the next code, creating the properties from a list: props = [ ("name", "peter"), ("age", 31), ("wife", "mary") ] class Person: def __init__(self): for prop in props: setattr(self, "__" + prop[0], prop[1]) setattr(Person, "Get" + prop[0], lambda self: getattr (self, "__" + prop[0])) if __name__ == "__main__": person = Person() print person.__name print person.__age print person.__wife print print person.Getname() print person.Getage() print person.Getwife() And the resulting execution of this program is: peter 31 mary mary mary mary The attributes are right, but the getter are not working. The problem is that the lambda function always execute the last parameter passed for all instances of the methods. How could it be done the right way? Thanks in advance From mdw at distorted.org.uk Fri Jan 23 07:30:51 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 12:30:51 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: >> Well, your claim /was/ just wrong. But if you want to play dumb: the >> interface is what's documented as being the interface. > > But you miss my point. Evidently. > We're told Python doesn't have private attributes. We're told that > we're allowed to "mess with the internals", we're *encouraged* to do > so: Python gives you the freedom to do so, and any suggestion that > freedom might be reduced even a tiny bit is fought passionately. Your deduction skills are faulty. * Python gives us the freedom to do so, and we fight to protect that freedom -- yes. * But interpreting that as encouragement is wrong. It's permission, not encouragement. If you don't want to, that's fine, and we won't think less of you. Many things are possible which aren't, as a general rule, good ideas. Misinterpreting permission as encouragement will lead you to doing many stupid things. > When people ask how to implement private attributes, they're often > told not to bother even using single-underscore names. When it is > suggested that Python should become stricter, with enforced data > hiding, the objections come thick and fast: people vehemently say that > they like Python just the way it is, that they want the ability to > mess with the internals. > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to > mess with the private attributes. In context, I had just mentioned > that lists' internals were inaccessible from Python code. I neglected > to give an example at the time, but a good example is the current > length of the list. Umm... I'm pretty sure that that's available via the `len' function, which is tied to list.__len__ (via the magic C-implemented-type mangler, in C). Though it's read-only -- and this is a shame, 'cos it'd be nice to be able to adjust the length of a list in ways which are more convenient than * deleting or assigning to a trailing slice, or * augmenting or assigning to a trailing zero-width slice (Perl has supported assigning to $#ARRAY for a long time. Maybe that's a good argument against it.) > Consider the experience of Microsoft and Apple. No matter how often > they tell people not to mess with the internals, people do it anyway, > and always believe that their reason is a good reason. And Microsoft and Apple can either bend over backwards to preserve compatibility anyway (which effectively rewards the misbehaviour) or change the internals. I'd prefer that they did the latter. There are times when messing with internals is the only way to get things done; but there's a price to be paid for doing that, and the price is compatibility. The internals will change in later versions, and your code will break, in subtle and complex ways. It's not always an easy decision to make -- but I'm glad it's me that gets to decide, and not some random who neither knows nor cares much about the problem I'm trying to solve. It's also important to bear in mind that programs' lifetimes vary. Some programs are expected to live for years; some programs only for a week or so; and some for just long enough to be typed and executed once (e.g., at the interactive prompt). That Python is useful for all these kinds of program lifetimes is testament to its designers' skill. Programmers can, and should!, make different tradeoffs depending on the expected lifetime of the program they're writing. If I type some hacky thing at ipython, I know it's going to be executed there and then, and if the implementation changes tomorrow, I just don't care. If I'm writing a thing to solve an immediate problem, I won't need it much past next week, and I'll still probably get away with any awful hacking -- but there's a chance I might reuse the program in a year or so, so I ought to put a comment in warning the reader of a possible bitrot site. If I'm writing a thing that's meant to last for years, I need to plan accordingly, and it's probably no appropriate to hack with internals without a very good reason. Making these kinds of decisions isn't easy. It requires experience, subtle knowledge of how the systems one's using work, and occasionally a little low cunning. And sometimes one screws up. > And Python culture encourages that behaviour (albeit the consequences > are milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. Indeed. Very useful. Example: for my cryptographic library bindings, I needed to be able to convert between Python's `long's and my library's `mp's. I have a choice between doing it very slowly (using shift and masking operators on the `long') or fast (by including Python/longintrepr.h and digging about by hand). I chose to do it the fast way. I'm quite prepared to rewrite my conversion code (64 lines of it) if the internals change; that I haven't had to yet indicates that my judgement of the stability of the internal representation was about right. The most important point is that, /had/ I turned out to be wrong, I'd only have myself to blame. > And then you have at least two places in the standard library where > _attributes are *explicitly* public: And documented as being so. It's a convention, with explicitly documented exceptions. That's a slight shame because it weakens the convention, but it's not a disaster. > Given this permissive culture, any responsible library writer must > assume that if he changes his so-called "private" attributes, he will > break other people's code. He will, but he can also assume that the maintainers of that code are /willing/ to see it break. This is tough on people who depend on internals by accident. Maybe they'll learn to be more careful. It's not a pleasant way to learn, but it's a lesson worth learning anyway. > In principle it could break just as much code as if he didn't even > bother flagging them with a leading underscore, which is probably why > many people don't even bother with _names. This comes down to documentation. The Python standard library is largely quite well documented, and is clear about what assumptions one can make and what one can't. In the absence of such clear documentation, we're left with conventions -- _things are likely to change in future so avoid messing on them if you don't want stuff to break. > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them > to mess with your internals, then you don't have internals. Everything > is de facto public. And here you've made a semantic leap that I'm afraid I just can't follow. > No, cmp() can return an infinite number of values. It just never does, > at least not yet, but it might. But when Guido himself says that cmp() > can return three values, can you blame people for acting as if cmp() > can return three values? Possibly not! It's worth thinking about codifying the existing practice and documenting the more constrained behaviour. Note that the C interface -- the tp_compare slot (Python/C API Reference Manual 10.3) -- /is/ defined to return -1, 0, or +1; so presumably the performance issues have already been considered. I think all of this comes down to issues of trust and responsibility. Python, though its `we're all consenting adults' approach, encourages a culture where we trust one another to make decisions for ourselves, and to take responsibility for the consequences of those decisions. Language features such as attribute (or member) visibility or access control, on the other hand, imply a culture without trust, and with an built-in assumption of irresponsibility. That seems rather unpleasant to me. Suppose that you write a Python library module and release it. I find that it's /almost/ the right thing for some program of mine, but it doesn't quite work properly unless I hack about like so... perfect! I'm a happy bunny; you've gained a user (maybe that's a good thing, maybe it isn't!). Now, I've hacked about in your module's internal stuff: how has this affected you? Answer: not at all; you probably didn't feel a thing. You release a new version with improved internal structure and my program breaks: how has this affected you? Answer: still not at all. How did it affect me? Quite a bit, but then again, I knew what I was getting into. I gambled and lost; oh, well, that happens sometimes. I've not dealt with granularity much yet; but that's easy. Basically, decisions should be made at the level at which the consequences of those decisions are felt. This isn't directly practical, but there are mechanisms to manage it: users generally delegate technical decisions to the development team; maybe there's a hierarchy in the dev team. And the team members need to be trusted not to make decisions at the wrong level. If you can't manage that, then Python probably isn't a good match for the team; replace one or the other. Finally, I notice that you completely snipped the part of my reply which dealt with your ConfigParser module. I'm going to assume that this means that you accepted that part of my response. -- [mdw] From mdw at distorted.org.uk Fri Jan 23 07:36:11 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 12:36:11 +0000 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tz7qci84.fsf.mdw@metalzone.distorted.org.uk> aahz at pythoncraft.com (Aahz) writes: > Actually, that is not correct. You're right, evidently. [snip] >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] += ['spam'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar', 'spam'], 'xyzzy') Ugh! -- [mdw] From diresu at web.de Fri Jan 23 07:39:13 2009 From: diresu at web.de (Dietrich Bollmann) Date: Fri, 23 Jan 2009 21:39:13 +0900 Subject: How to write a simple shell loop in python? In-Reply-To: <49772515.90306@holdenweb.com> References: <1232509966.4430.28.camel@pippi.pippi> <49772515.90306@holdenweb.com> Message-ID: <1232714353.4288.40.camel@pippi.pippi> [Sorry for top posting - I had a HD problem and lost the original mails] Hi Saul, Steve, Ben, James, Scott David and James! Thank you all very much for your help! I finally got rid of the extra space and also understood why the space was printed :) After using Steve's 'input = raw_input("$ ")' solution for a while - it does exactly what I want and is the fastest fix also - I wanted command line editing and switched to the cmd.Cmd module. Special thanks to James Mills for writing his own solution! I would like to use your component - but cmd.Cmd is just perfect for my purpose and I want to run my program without the need to install any new module (I am writing the program for somebody else). I got interested in circuits though - but the homepage http://trac.softcircuit.com.au/circuits/ (currently?) seems not to be available. Thanks again for your answers :) Dietrich PS: There is a little tutorial for cmd.Cmd here: - http://www.doughellmann.com/PyMOTW/cmd/index.html The documentation is here: - http://docs.python.org/library/cmd.html (got it from Ben Finney's post) On Wed, 2009-01-21 at 08:37 -0500, Steve Holden wrote: > Dietrich Bollmann wrote: > > Hi, > > > > I am trying to write a simple shell loop in Python. > > > > My simple approach works fine - but the first output line after entering > > something is always indented by one blank. > > > > Is there any logic explanation for this? > > How can I get rid of the blank? > > Is there a smarter way to write a simple shell loop which would work > > better? > > > > Thanks, Dietrich > > > > > > Here my approach: > > > > $ python > > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > > [GCC 4.3.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys > >>>> while (1): > > ... print "$ ", > > ... input = sys.stdin.readline() > Just replace the lines above with > > input = raw_input("$ ") > > and you'll be fine. The "," in the print statement causes the > interpreter to set a flag to emit a space before the next output unless > it has just printed a newline. The "newline", of course, is provided by > the input, so the next print emits a space since it *hasn't* just > emitted a newline. > > regards > Steve > > > ... input = input.strip() > > ... print input > > ... print input > > ... print input > > ... > > $ one > > one > > one > > one > > $ two > > two > > two > > two > > $ three > > three > > three > > three > > $ > > Traceback (most recent call last): > > File "", line 3, in > > KeyboardInterrupt > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 07:44:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 12:44:34 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> Message-ID: <0189b204$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 10:54:53 +0100, Bruno Desthuilliers wrote: >> In context, I had just mentioned that lists' internals were >> inaccessible from Python code. I neglected to give an example at the >> time, but a good example is the current length of the list. Consider >> the experience of Microsoft and Apple. > > Yes, two great examples of freedom champions. What does that little dig at Microsoft and Apple have to do with what we're discussing? I dare say Linux has private internals too. Let's see if we can find some in 30 seconds of googling. http://forum.soft32.com/linux2/Bug-406747-linux-kernel-headers-private- symbols-u16-u32-asm-ftopict67443.html http://groups.google.com/group/linux.kernel/browse_thread/thread/ a08fd6423204e918 Those fascists! Private data in the kernel!!! Why can't my userland app mess with the kernel's private data??? It's so unfair!!! >> No matter how often >> they tell people not to mess with the internals, people do it anyway, >> and always believe that their reason is a good reason. > > And who are *you* to pronounce any judgement about that ? Did I pronounce any judgement? ... >> [Any] library writer must assume >> that if he changes his so-called "private" attributes, he will break >> other people's code. > > You still don't get the point. If someone's code breaks because he > messed with my implementation code, then *he* is responsible. The > contract is very clear : "warranty void if unsealed". You've built something full of user serviceable parts. You've insisted, publicly and loudly, that the ability to modify those parts is absolutely essential, you've rejected every effort to lock down those internals, and then when somebody does exactly what you encourage, you suddenly turn on them and say they're on their own. That's pretty irresponsible behaviour. As an aside, Apple and Microsoft have opposite approaches to dealing with this problem. Apple hangs the developer out to dry, which is why there are so few developers who make Mac software, while Microsoft goes to (or at least did) heroic efforts to protect developers from their mistakes, which is why the Windows internals is a dog's breakfast but there are more Windows developers named "Steve" then there are Mac developers in total. (BTW, I'm not one of them.) http://www.joelonsoftware.com/articles/APIWar.html > Now that you've exposed your opinions, let's face reality (I mean, > *facts*): Python developpers very rarely mess with implementation, > usually do so for very good (and documented) reasons, and from what I've > seen usually tend to get in touch with the library author to explain > their case and find a better solution. Facts, are they? Care to provide some reputable sources for these facts? > Funny enough, it looks that the more you treat programmers as > responsible, normally intelligent adult person, the more they tend to > behave as such. And the other way around, too. You're the one who repeatedly declared that programmers who modified internals were cretins who should be fired. I never said such a thing -- in fact, I defended them. > Now, you comprehensively exposed your personnal distaste for Python's > and more generally OSS philosophy. Really? I did? Fancy that. > So I can only - as I already did way > before in this thread - wonder *why* are you using Python ? Ah yes, the old "if you're not 100% for us, you must be 100% against us" argument. Anyone who thinks that there are costs as well as benefits to dynamic programming must be a freedom-hater, and probably kicks puppies too. > I mean, is it because your bosses forces you to do so ? Yeah, my mean old boss forces me to write Python scripts in my spare time, he forces me to spend my personal time on comp.lang.python, he forces me to write things like: [quote] Oh yes, it is liberating to say "I don't care if my method crashes (raises an exception), it's the caller's fault for messing with my class' internals, and he can deal with it". I'm not being sarcastic by the way. It really is liberating not to have to deal with unexpected input or broken pre-conditions. Just let the caller deal with it! [end quote] What a mean old boss! > If yes, then, > I'm truly sorry for you - I sometimes have to work with languages I > really dislike so I can feel your pain (but OTHO, I never complained on > these languages newsgroups about how wrong they were nor how they should > IMHO be). If people hadn't complained about missing features/misdesigns, would Python have: generator expressions print as a function booleans nested scopes None as a keyword ABCs closures to name just a few? I am curious though... you've made a few comments that suggest that your in favour of more freedom, rather than less: you've made a disparaging comment about Microsoft and Apple, you apparently think highly of Open Source software, and more. Does this freedom extend to people who have criticisms -- even mild criticisms -- of Python? > Else, well, I just don't get the point. What you are fussing about are > fundamental design choices (and philosophic points) that are well known, > explained, advertized, etc. - and are really not likely to change > anytime soon. No, probably not. Any such changes would have to start off as an external tool first. I'd guess that it couldn't even be considered as part of the base language until Python 4, which is probably a decade away. This is a good thing. There are, as you have so often pointed out, many B&D languages out there, and they are a PITA to use. Nobody wants to make Python unpleasant to use, but if you think data hiding is automatically unpleasant, then you must *hate* calling len() on a list, because that uses private data inaccessible to Python code. That's data hiding. It will probably take a decade of experiments to find a way to get as many of the benefits of data hiding as possible with as few of the costs as we can get away with. It may even be that it is impossible to do so, that you can't get the safety of data hiding without the pain. Who knows? I think it's an experiment worth trying. And for all those who insist that Python will never have data hiding except by convention, a few years ago I was saying that Python would never have static types, because of fundamental design choices to make Python a dynamic typed language. And now Python has ABCs, and optional type annotations, and Guido is encouraging people to experiment with tools that do things with those type annotations, things like type inference, and if they become popular and useful, they may end up in the language itself. As has been frequently pointed out, Python is not Java. Java is obsessed with the past, while Python is forward-looking. http://cafe.elharo.com/programming/java-is-dead-long-live-python/ Thank goodness for that. -- Steven From steve at holdenweb.com Fri Jan 23 07:53:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 07:53:55 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Aahz wrote: > In article <87hc3un1vn.fsf.mdw at metalzone.distorted.org.uk>, > Mark Wooding wrote: >> * Python augmented-assignment (`+=', for example) is inconsistent. >> Depending on what type of object the left-hand side evaluates to, it >> may /either/ mutate that object, /or/ assign a new value to the >> expression. > > Actually, that is not correct. The augmented assignment always binds a > new value to the name; the gotcha is that with a mutable object, the > object returns ``self`` from the augmented assignment method rather than > creating a new object and returning that. IOW, the smarts are always > with the object, not with the augmented assignment bytecode. > > The best way to illustrate this: > >>>> a = (1, ['foo'], 'xyzzy') >>>> a[1].append('bar') >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] = 9 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] += ['spam'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar', 'spam'], 'xyzzy') I understand what you are saying, but if the id() associated with a name doesn't change after augmented assignment it seems a little wrong-headed to argue that "the augmented assignment always binds a new value to the name". What you are actually saying is that it's up to the method that implements the augmented assignment whether the same (mutated) object or a different one is returned, right? And that the left-hand side of the assignment is always bound to the result of that method. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mrkafk at gmail.com Fri Jan 23 07:55:46 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 13:55:46 +0100 Subject: DrPython and py2exe Message-ID: Hello, I'm trying to get DrPython to edit .py file on double-click on Windows. Sure, I can use trivial .bat file to open DrPython with file as argument. But the irritating thing is that DOS window stays open until particular instance of DrPython isn't closed. py2exe to rescue. I have modified DrPython's setup.py: setup(name='drpython.exe', version=MY_VER, description=description[0], long_description=description[1], classifiers = filter(None, classifiers.split('\n')), author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, platforms = "any", license = 'GPL', packages=[ MY_NAME ], package_dir={ MY_NAME : '.' }, package_data={ MY_NAME : DATA }, scripts=['postinst.py'], windows=['drpython.py'], ) py2exe builds application, but when I start it, I get this in the log file: Traceback (most recent call last): File "drpython.py", line 46, in File "wxversion.pyc", line 152, in select wxversion.VersionError: Requested version of wxPython not found I'm guessing this is because py2exe doesn't package wxPython together with the app. Since this topic is interesting for me anyway (i.e. how to transform wxPython app using py2exe into Windows executable), would someone please reply on how to do it? Thanks, mk From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 07:57:52 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 13:57:52 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> Message-ID: <4979bebd$0$18836$426a34cc@news.free.fr> Russ P. a ?crit : (snip) > I am curious about something. Have you ever needed to access a > "private" attribute (i.e., one named with a leading underscore) in > Python code that you did not have the source code for? For that > matter, have you ever even used a library written in Python without > having access to the source code? No to both. > As I said before, if you have the source code you can always change > private attributes to public in a pinch if the language enforces > encapsulation. And then have to maintain a fork. No, thanks. > But if you are working on a team project, you can't > change the code that another member of a team checks in. Why on earth couldn't I change the code of another member of my team if that code needs changes ? The code is the whole team's ownership. Now and FWIW, in this case (our own code), I just don't need to "mess with internals" - I just just change what needs to be changed. > That is how > enforced data hiding helps teams of developers manage interfaces. I totally fails to find any evidence of this assertion in the above "demonstration". > The > bigger the team and the bigger the project, the more it helps. Your opinion. > Mr. D'Aprano gave an excellent example of a large banking program. > Without enforced encapsulation, anyone on the development team has > access to the entire program and could potentially sneak in fraudulent > code much more easily than if encapsulation were enforced by the > language. My my my. If you don't trust your programmers, then indeed, don't use Python. What can I say (and what do I care ?). But once again, relying on the language's access restriction to manage *security* is, well, kind of funny, you know ? > I am certainly not saying that Python is useless without enforced data > hiding. It is obviously very useful for a wide range of applications > and domains already. I am only saying that it's usefulness could be > enhanced if enforced encapsulation can be added You might have a chance to sell this to a clueless pointy haired boss - I mean, that enforced access restriction will make Python more suitable for some big enterprizey project. As far as I'm concerned, I'm not buying it. > without somehow > comromising the language. Then just forget it. > I don't know enough about the inner workings > of the Python interpreter to know if that is the case or not (I am an > aeronautical engineer), but the objections I've seen so far on this > thread have not impressed me. I've not seen much technical objections - but anyway: learn (I mean, *really* learn) how Python's object model works, and you'll perhaps find out why this would break the whole thing. From steve at holdenweb.com Fri Jan 23 07:59:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 07:59:42 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7xzlhimttv.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Carl Banks writes: >> 3. If you are going to use the low-level API on a mutable object, or >> are going to access the object structure directly, you need to acquire >> the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() >> would be provided. > > You mean every time you access a list or dictionary or class instance, > you have to acquire a mutex? That sounds like a horrible slowdown. Indeed it would, but hey, let's not let that stop us repeating the thinking that's gone into CPython over the last fifteen years. "Those who cannot remember the past are condemned to repeat it". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 08:08:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 13:08:04 GMT Subject: Dynamic methods and lambda functions References: Message-ID: <0189b787$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 04:28:33 -0800, unineuro wrote: > Hi, > I want to add some properties dynamically to a class, and then add the > corresponding getter methods. Something resulting in this: > > class Person: > def Getname(self): > return self.__name > > def Getage(self): > return self.__age (1) Properties don't work with classic classes. If you have setters to go with these getters, and you're using Python 2.x, your code will fail to work the way you think it should. (2) Getters and setters are generally discouraged in Python unless you really need them. If all you are doing is getting/setting an attribute, then you're just wasting time. (Or if this is a learning exercise.) > I've implemented the next code, creating the properties from a list: > > props = [ > ("name", "peter"), > ("age", 31), > ("wife", "mary") > ] > > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], > lambda self: getattr(self, "__" + prop[0])) Seems awfully complicated. I'm not even sure it will work, due to Python's name-mangling. And let's not even talk about how broken it is to get your input to a class initializer from a global variable! What happens when you need a second instance? > if __name__ == "__main__": > > person = Person() > > print person.__name > print person.__age > print person.__wife > print > print person.Getname() > print person.Getage() > print person.Getwife() > > > And the resulting execution of this program is: > > peter > 31 > mary > > mary > mary > mary > > The attributes are right, but the getter are not working. The problem is > that the lambda function always execute the last parameter passed for > all instances of the methods. How could it be done the right way? class Person(object): def __init__(self, name, age, wife): self.name = name self.age = age self.wife = wife props = {"name": "peter", "age": 31, "wife": "mary"} if __name__ == "__main__": person = Person(**props) print person.name print person.age print person.wife If you really want getters, for whatever reason, then do it like this: class Person(object): def __init__(self, name, age, wife): self._name = name self._age = age self._wife = wife for prop in ('name', 'age', 'wife'): setattr(Person, prop, property( lambda self, prop=prop: getattr(self, '_'+prop) )) -- Steven From Russ.Paielli at gmail.com Fri Jan 23 08:11:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 05:11:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <1c99aef0-a4fa-4b8a-a0e2-1ba59bf5f703@i24g2000prf.googlegroups.com> On Jan 23, 4:30?am, Mark Wooding wrote: > Suppose that you write a Python library module and release it. ?I find > that it's /almost/ the right thing for some program of mine, but it > doesn't quite work properly unless I hack about like so... perfect! ?I'm > a happy bunny; you've gained a user (maybe that's a good thing, maybe it > isn't!). ?Now, I've hacked about in your module's internal stuff: how > has this affected you? ?Answer: not at all; you probably didn't feel a > thing. ?You release a new version with improved internal structure and > my program breaks: how has this affected you? ?Answer: still not at all. > How did it affect me? ?Quite a bit, but then again, I knew what I was > getting into. ?I gambled and lost; oh, well, that happens sometimes. Was this library module released in source form? If so, then why would you care that it has enforced access restrictions? You can just take them out, then do whatever you would have done had they not been there to start with. I don't see how that is any more work than figuring out what internals you need to access. Either way you need to read and understand the code. Wait ... it wasn't released in source form? Then how would you even know what internals you need to access? And why would you use something that goes against your philosophy of openness anyway? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 08:21:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 13:21:39 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <0189bab5$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >> As I said before, if you have the source code you can always change >> private attributes to public in a pinch if the language enforces >> encapsulation. > > And then have to maintain a fork. No, thanks. If you're messing with the internals, you have to do this anyway. As soon as the internals change, your monkey-patched solution falls apart. >> But if you are working on a team project, you can't change the code >> that another member of a team checks in. > > Why on earth couldn't I change the code of another member of my team if > that code needs changes ? The code is the whole team's ownership. That's a model that works well when you have a small team of, say, a dozen people. It's not a model that works when you have hundreds of developers working on the project. The last thing I want in my projects is cowboys who ride all over other people's code, changing internals of parts they barely know at the drop of a hat, causing who knows what side- effects. But anyway, this is a red-herring. Data hiding isn't really about managing the development process, it's about ensuring that when you and Fred are using Barney's OrderedDict class in your code, Barney is free to change his the implementation without your code suddenly failing. It's also to ensure that any changes you make at runtime to the class don't suddenly make Fred's code break. -- Steven From steve at holdenweb.com Fri Jan 23 08:23:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 08:23:46 -0500 Subject: what gives with In-Reply-To: References: Message-ID: Darren Dale wrote: > On Jan 22, 10:07 pm, Benjamin Peterson wrote: >> Darren Dale gmail.com> writes: >> >>> Judging fromhttp://bugs.python.org/issue2400, this issue >>> was fixed back in May 2008, but it is still present with python-2.5.4, >>> which was released in December. Why wont python-2.5 allow this kind of >>> import? >> Allowing that would be a new feature which is disallowed in bug fix releases >> like 2.5.4. > > I was talking about the behavior after doing "from __future__ import > absolute_import". I've been developing on python-2.6 using > absolute_import for weeks, knowing that I could do "from __future__ > import absolute import" on python-2.5. Now when I try to use > python-2.5 I cant import my package. What is the point of providing > absolute_import in __future__ if the api is completely different than > the implementation in future python versions? Its bizarre. I guess it must specify some alternate future ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 08:26:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 08:26:40 -0500 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: atleta wrote: > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? > Or there's a third option. Write a class that implements a __call__() method, and use an instance of that class as your callback. Then the data can be stored as the callback object's private instance data. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From exarkun at divmod.com Fri Jan 23 08:34:18 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 08:34:18 -0500 Subject: seeking to improve Python skills In-Reply-To: Message-ID: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> On Fri, 23 Jan 2009 12:17:41 +0100, mk wrote: >Hello everyone, > >I wrote the following program mainly for educational purpose of improving my >Python programming skills -- would Pythonistas here please look at it and >point out areas that could use improvement? > >This thing analyzes the stored load average record file, calculates simple >moving average and produces Gnuplot program to plot the thing. > >Constructive criticism is welcome. > >#!/usr/bin/python > >import re >import sys >import tempfile >import subprocess >import os > >class MovingAvg(object): You should have a docstring here. It should describe the overall purpose of the MovingAvg class and it should probably document the meaning of each attribute instances of the class have. > def __init__(self, fname): > try: > self.fo = open(fname) > except IOError, e: > print "Problem with opening file:", e > sys.exit(4) This isn't very good. Your MovingAvg class is otherwise relatively general- purpose and re-usable, but this makes it unusable instead. You shouldn't use print to report errors in general code and you shouldn't turn specific exceptions into SystemExit. This kind of whole-program error handling belongs in a different layer if your code. Your moving average code should just focus on computing a moving average. Also, filenames are rather clunky. Another improvement here would be to pass in a file object which the calling code has already opened. Or, better still, just pass in an iterator of data. Do the file handling and the parsing in a different layer. Then you'll be able to re-use your moving average class with data files in a different format - all you'll have to do is write another parser for the new format. > self.reslist = [] > self.smalist = [] > self.maxval = 0 > > def extrfromfile(self): There should be a docstring here describing what this method does. > vre = re.compile("(\d+-\d+-\d+) (\d\d:\d\d) (\d+\.\d+)") > for line in self.fo: > res = vre.search(line) > if res: > self.reslist.append({'day':res.group(1),\ > 'time':res.group(2),\ > 'val':float(res.group(3))}) The trailing backslashes on the previous lines are superfluous. The code is just as valid without them. > def calc_sma(self, smalen=4): Another missing docstring. Make sure you also document the meaning of the parameter the method accepts. > if smalen == 0: > raise AssertionError, "Moving Average sample length >cannot be 0" > if not isinstance(smalen, int): > raise AssertionError, "Moving Average sample length >has to be integer" The conventional way to write the previous lines would be: assert smallen != 0, "Moving Average sample length cannot be 0" assert isinstance(smallen, int), "Moving Average Sample length has to be integer" However, I would just leave them out. If you document the meaning of the smalen parameter, then callers will know it can't be 0 and must be an int. > total = 0 Superfluous line above. > total = sum( [ x['val'] for x in self.reslist[0:smalen] ] ) > sma = total / smalen > smaidx = int(smalen/2) > self.smalist.append((self.reslist[0]['day'],\ > self.reslist[0]['time'],\ > self.reslist[0]['val'],\ > self.reslist[0]['val'])) Superfluous backslashes again. > for i in range(smalen, len(self.reslist)): > curval = self.reslist[i]['val'] > self.maxval = max(self.maxval, curval) > total += curval > total -= self.reslist[i - smalen]['val'] > sma = total / smalen > smaidx += 1 > self.smalist.append((self.reslist[smaidx]['day'],\ > self.reslist[smaidx]['time'],\ > self.reslist[smaidx]['val'],\ > sma)) And again. > > def return_results(self): Missing docstring. > return (self.reslist, self.smalist, self.maxval) Generally, I wonder whether MovingAvg should just be a function rather than a class. The only place it maintains state it does so confusingly. I would just make the input data a parameter to calc_sma and have it return the results it computes. Drop the rest of the class and make calc_sma a free function. >class GnuplotWrapper(object): Docstring. > def __init__(self, smalist, maxval, outfname = "calc.png", >graphlen=640, graphheight=480, gnuplot = '/usr/bin/gnuplot'): Again, the comment about filenames. You could just make outfname a file-like object and skip the naming. > self.outfname = outfname > self.smalist = smalist > self.gnuplot = gnuplot > self.gprog = None > self.gdata = None > self.graphlen = graphlen > self.graphheight = graphheight > > def _writefiles(self): Docstring. > self.gprog = tempfile.mkstemp() > self.gdata = tempfile.mkstemp() > self.gprogfile = open(self.gprog[1], 'wb') > self.gdatafile = open(self.gdata[1], 'wb') > labelnum = int(self.graphlen / 110) > labelstep = int(len(self.smalist) / labelnum) > labels = [] > for i in range(0, len(self.smalist), labelstep): > labels.append("\"%s %s\" %d" % (self.smalist[i][0], >self.smalist[i][1], i)) > labelstr = ", ".join(labels) > > self.gprogfile.write("""set terminal png size %d, %d >set style line 1 lt 1 lw 2 >set style line 2 lt 2 lw 2 >set output "%s" >set xtics(%s) >set yrange [0:%f] >set y2range [0:%f] >plot "%s" using 1 with lines ls 1 title "orig" axes x1y1, "%s" using 2 with >lines ls 2 title "Moving Average" axes x1y2 >""" % (self.graphlen, self.graphheight, self.outfname, labelstr, >float(maxval), float(maxval),\ Superfluous backslash. > self.gdata[1], self.gdata[1]) ) > self.gprogfile.close() > for elem in self.smalist: > self.gdatafile.write("%f, %f\n" % (elem[2], >elem[3])) > self.gdatafile.close() > > def plot(self): Docstring. > self._writefiles() > gplot = subprocess.Popen(self.gnuplot + " " + >self.gprog[1],\ > shell=True, stdout=subprocess.PIPE, >stderr=subprocess.PIPE) You should *avoid* using shell=True with subprocess.Popen. There's no reason to use it here, as far as I can tell. > print "Plotting data (%s)..." % self.outfname > so, se = gplot.communicate() > if se: > print "Gnuplot problem output:", se > os.remove(self.gprog[1]) > os.remove(self.gdata[1]) Reporting the gnuplot failure with print is not the best thing. Reporting errors to users should be done at a separate layer. This is your gnuplot wrapper - its job is to wrap gnuplot, not to talk to the user. If there's a problem, make it available via some documented API (for example, the plot method might raise an exception if there is a gnuplot problem). Handle the exception at a higher level in your application where you know it's correct to print things for the user to read. > > >if __name__ == "__main__": > try: > fname = sys.argv[1] > except IndexError: > print "Specify filename with data as first argument." > sys.exit(1) > except Exception, e: > print "Error:", e > sys.exit(2) What is the second exception handler doing? There is no expected other exception from the code being protected, so you should just get rid of this handler. If, through some crazy accident, another exception gets raised, Python will take care of reporting it to the user, and it will do so with far more information - information that will make your job of debugging the problem vastly easier. > values = MovingAvg(fname) > values.extrfromfile() > values.calc_sma(smalen = 10) > (reslist, smalist, maxval) = values.return_results() > gp = GnuplotWrapper(smalist, maxval) > gp.plot() > The most significant thing missing from this code is unit tests. Developing automated tests for your code will help you learn a lot. Jean-Paul From imageguy1206 at gmail.com Fri Jan 23 08:38:39 2009 From: imageguy1206 at gmail.com (imageguy) Date: Fri, 23 Jan 2009 05:38:39 -0800 (PST) Subject: DrPython and py2exe References: Message-ID: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> But the irritating thing is that DOS window stays open until > particular instance of DrPython isn't closed. This is a relatively simple fix I think. You can change the extension of the drPython.py to drpython.pyw and the python windows executable (pythonw.exe) will launch the program instead of the traditional executable (python.exe). > Traceback (most recent call last): > ? ?File "drpython.py", line 46, in > ? ?File "wxversion.pyc", line 152, in select > wxversion.VersionError: Requested version of wxPython not found check out the wiki on 'multi version installs'. http://wiki.wxpython.org/MultiVersionInstalls drPython is probably selecting a specific version of wxpython and py2exe doesn't like it or can't find it. Once you solve that, py2exe will work fine with wxpython. From Russ.Paielli at gmail.com Fri Jan 23 08:42:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 05:42:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> On Jan 23, 4:57?am, Bruno Desthuilliers wrote: > Russ P. a ?crit : > > As I said before, if you have the source code you can always change > > private attributes to public in a pinch if the language enforces > > encapsulation. > > And then have to maintain a fork. No, thanks. For crying out loud, how many private attributes do you need to access? If it's a dozen, then you and your library developer are obviously not on the same page. If it's one or two, then it's hardly a "fork." Just take note of the one or two places where you needed to remove the access restriction and you're done. Heck, you don't even need to do that, because you will be warned automatically anyway when you get the new version of the library (unless those private attributes are changed to public). > > But if you are working on a team project, you can't > > change the code that another member of a team checks in. > > Why on earth couldn't I change the code of another member of my team if > that code needs changes ? The code is the whole team's ownership. OK, fine, you can change the code of another member of the team. Are you going to check with him first, or just do it? The point is that changing an interface requires agreement of the team members who use that interface, whether on the calling or the implementation side of it. If you change interfaces without getting agreement with the other team members, you probably won't be on the team for long. And without access restrictions, accessing _private is equivalent to changing the interface. > Now and FWIW, ?in this case (our own code), I just don't need to "mess > with internals" - I just just change what needs to be changed. > > > That is how > > enforced data hiding helps teams of developers manage interfaces. > > I totally fails to find any evidence of this assertion in the above > "demonstration". > > > The > > bigger the team and the bigger the project, the more it helps. > > Your opinion. > > > Mr. D'Aprano gave an excellent example of a large banking program. > > Without enforced encapsulation, anyone on the development team has > > access to the entire program and could potentially sneak in fraudulent > > code much more easily than if encapsulation were enforced by the > > language. > > My my my. If you don't trust your programmers, then indeed, don't use > Python. What can I say (and what do I care ?). But once again, relying > on the language's access restriction to manage *security* is, well, kind > of funny, you know ? Are you seriously saying that if you were managing the production of a major financial software package with hundreds of developers, you would just "trust" them all to have free access to the most sensitive and critical parts of the program? Now *that's*, well, kind of funny, you know? Would you give all those developers your password to get into the system? No? Wait a minute ... you mean you wouldn't "trust" them with your password? But what about "openness"? Are you some sort of fascist or what? From notvalid2 at sbcglobal.net Fri Jan 23 08:56:37 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 23 Jan 2009 05:56:37 -0800 Subject: What is intvar? In-Reply-To: References: Message-ID: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> r wrote: > here is a good explanation of control vars: > http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html > > Here are 3 great Tkinter refernces in order: > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ > http://effbot.org/tkinterbook/ > http://www.pythonware.com/library/tkinter/introduction/ Thanks to all for the reference and tips. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 09:09:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 14:09:12 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <0189c5d8$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 05:42:38 -0800, Russ P. wrote: >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, >> kind of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you would > just "trust" them all to have free access to the most sensitive and > critical parts of the program? Now *that's*, well, kind of funny, you > know? I think this is a red-herring. Probably my fault -- I was the first one to mention access controls for banking software. I meant it as an analog to data hiding, rather than implying that one can or should use private/ protected attributes to implement data hiding. Private attributes are a form of data hiding, but not all data hiding can be implemented as private attributes. -- Steven From kt83313 at gmail.com Fri Jan 23 09:10:31 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 06:10:31 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> Message-ID: <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> On Jan 23, 4:41?pm, Bryan Olson wrote: > kt83... at gmail.com wrote: > > Anyways, if we can make it real hard for them to analyze also, I think > > we are in the good - esp since the clients are not extremely rich > > enough to go for professional analyzers -- > > Sounds like you have the "digital rights management" (DRM) problem. As > Diez pointed out, there is no robust software solution. Nevertheless, > many clever people have worked each side, so there's now something of a > body of practice and experience. > > > What is the skype method? The code is not huge - less than 20K LOC so, > > code encryption looks somewhat OK - would you be able to direct me to > > any hints on this? > > I don't think Skype has much to offer here. They're not focused on > selling DRM technology; they sell communication services. Third parties > can write applications on top of those services, which can be protected > by Skype's DRM. (If I'm wrong on that, someone please correct me.) > > Diez's noted Skype's use of a layered approach, but there's nothing > special about the notion of layered code encryption in DRM software. > It's been used multiple times, broken multiple times, and patented > multiple times. > > > One another option that I was thinking was to automatically generate > > the password for the database - re-encrypt every 1 hr - and store the > > password inside the code itself. Is that possible in Python? i.e. > > changing the code itself. > > Possible it is. Effective it is almost certainly not, at least not > without a whopping bunch of other techniques going vastly beyond that > description. > > Look up DRM technology companies, such as CloakWare, Macrovision, and > Cryptography Research. > > If you have a modest number of customers, hardware solutions and/or > strict contractual commitments might offer practical solutions. > > -- > --Bryan Thank you very much Bryan. It does look like this is out of my league. KT -- From steve at holdenweb.com Fri Jan 23 09:21:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 09:21:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <4979bebd$0$18836$426a34cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Russ P. a ?crit : [...] >> Mr. D'Aprano gave an excellent example of a large banking program. >> Without enforced encapsulation, anyone on the development team has >> access to the entire program and could potentially sneak in fraudulent >> code much more easily than if encapsulation were enforced by the >> language. > > My my my. If you don't trust your programmers, then indeed, don't use > Python. What can I say (and what do I care ?). But once again, relying > on the language's access restriction to manage *security* is, well, kind > of funny, you know ? > I have to say that I thought the example was somewhat bogus. Any development team that is even slightly concerned about the possibility of logic bombs in the code will try to mitigate that possibility by the use of code inspections. >> I am certainly not saying that Python is useless without enforced data >> hiding. It is obviously very useful for a wide range of applications >> and domains already. I am only saying that it's usefulness could be >> enhanced if enforced encapsulation can be added > > You might have a chance to sell this to a clueless pointy haired boss - > I mean, that enforced access restriction will make Python more suitable > for some big enterprizey project. As far as I'm concerned, I'm not > buying it. > I'm not sure that there's much to be gained by this level of dogmatism on either side. "Enforced encapsulation" has been "implemented" in both C++ and Java, and both have proved to be circumventable. Just the same, talk of "clueless pointy-haired bosses" is unlikely to be convincing. Even the pointy-haired types never recognize themselves as such. Annotations *have* made it into 3.0, so it's possible that the might become usable. Remember, they'll always be optional, so those who don't want to use them won't lose anything at all. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From divyabce067 at gmail.com Fri Jan 23 09:42:43 2009 From: divyabce067 at gmail.com (Divya Prakash) Date: Fri, 23 Jan 2009 20:12:43 +0530 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <778fa3370901230642y3cd67c31x8eceba9373b4e6e9@mail.gmail.com> Hello thats excellant !! On 1/23/09, Russ P. wrote: > > On Jan 23, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > > Russ P. a ?crit : > > > > As I said before, if you have the source code you can always change > > > private attributes to public in a pinch if the language enforces > > > encapsulation. > > > > And then have to maintain a fork. No, thanks. > > For crying out loud, how many private attributes do you need to > access? If it's a dozen, then you and your library developer are > obviously not on the same page. If it's one or two, then it's hardly a > "fork." Just take note of the one or two places where you needed to > remove the access restriction and you're done. Heck, you don't even > need to do that, because you will be warned automatically anyway when > you get the new version of the library (unless those private > attributes are changed to public). > > > > But if you are working on a team project, you can't > > > change the code that another member of a team checks in. > > > > Why on earth couldn't I change the code of another member of my team if > > that code needs changes ? The code is the whole team's ownership. > > OK, fine, you can change the code of another member of the team. Are > you going to check with him first, or just do it? The point is that > changing an interface requires agreement of the team members who use > that interface, whether on the calling or the implementation side of > it. If you change interfaces without getting agreement with the other > team members, you probably won't be on the team for long. And without > access restrictions, accessing _private is equivalent to changing the > interface. > > > Now and FWIW, in this case (our own code), I just don't need to "mess > > with internals" - I just just change what needs to be changed. > > > > > That is how > > > enforced data hiding helps teams of developers manage interfaces. > > > > I totally fails to find any evidence of this assertion in the above > > "demonstration". > > > > > The > > > bigger the team and the bigger the project, the more it helps. > > > > Your opinion. > > > > > Mr. D'Aprano gave an excellent example of a large banking program. > > > Without enforced encapsulation, anyone on the development team has > > > access to the entire program and could potentially sneak in fraudulent > > > code much more easily than if encapsulation were enforced by the > > > language. > > > > My my my. If you don't trust your programmers, then indeed, don't use > > Python. What can I say (and what do I care ?). But once again, relying > > on the language's access restriction to manage *security* is, well, kind > > of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? > > Would you give all those developers your password to get into the > system? No? Wait a minute ... you mean you wouldn't "trust" them with > your password? But what about "openness"? Are you some sort of fascist > or what? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Fri Jan 23 09:43:16 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 14:43:16 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: 2009/1/22 Scott David Daniels : > Having once been a more type-A, I labored for a couple of years trying > to build a restricted language that provably terminated for work on an > object-oriented database research. I was careful to say that it was the /use/ of the language that is restricted; it's still possible to write undecidable programs, there's just an obligation on you to show that you haven't. > I finally gave it up as a bad idea, > because, in practice, we don't care if a loop will terminate or not in > database work; a transaction that takes a year to commit is equivalent > to an infinite loop for all applications that I have interacted with > (and yes, I have worked allowing four day transactions to commit). True -- the really serious safety critical stuff is usually real time, and part of the proof obligations is to show that the maximum response time is tolerable. The loop variant can help with that, too. -- Tim Rowe From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 09:47:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 14:47:21 GMT Subject: Stalled ticket in Python bug tracker Message-ID: <0189ceca$0$20671$c3e8da3@news.astraweb.com> I'm interested in this ticket in the bug tracker: http://bugs.python.org/issue2527 but it seems to have been stalled for nine months. Is there a procedure for starting it up again? Should I ask about it on the python-dev mailing list, or just wait until somebody happens to notice it? Peter Otten, if you're reading this, is your offer to jump through the necessary hoops still standing? -- Steven From Russ.Paielli at gmail.com Fri Jan 23 09:47:52 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 06:47:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <9aa5b8de-5e39-4064-9218-d67e1abfd992@r10g2000prf.googlegroups.com> On Jan 23, 6:21?am, Steve Holden wrote: > I have to say that I thought the example was somewhat bogus. Any > development team that is even slightly concerned about the possibility > of logic bombs in the code will try to mitigate that possibility by the > use of code inspections. Of course they would, but that does not mean that access restrictions enforced by the language are not prudent. Consider a corporation that needs to maintain the physical security of their buildings. You can say that locks on the doors are not sufficient. Of course they're not. Security guards are needed too -- but that doesn't mean the locks are not needed too. The locks may be *insufficient* by themselves, but they are certainly not *unnecessary*. Ditto for the enforced encapsulation for large financial or safety-critical projects. > I'm not sure that there's much to be gained by this level of dogmatism > on either side. "Enforced encapsulation" has been "implemented" in both > C++ and Java, and both have proved to be circumventable. Just the same, > talk of "clueless pointy-haired bosses" is unlikely to be convincing. > Even the pointy-haired types never recognize themselves as such. Do you think the designers of C++, Java, Ada, and Scala would eliminate the enforced encapsulation if they had it to do over again? Of course not. The vast majority of the users of those languages consider it a major plus. And those who don't wish to use it aren't forced to use it except perhaps by their bosses or their customers. Again, I am not saying that Python necessarily needs enforced access restriction. I'm just saying it would be a plus if it can be added without compromising the language in some way. From perfreem at gmail.com Fri Jan 23 09:48:22 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Fri, 23 Jan 2009 06:48:22 -0800 (PST) Subject: writing pickle function Message-ID: hello, i am using nested defaultdict from collections and i would like to write it as a pickle object to a file. when i try: from collections import defaultdict x = defaultdict(lambda: defaultdict(list)) and then try to write to a pickle file, it says: TypeError: can't pickle function objects is there a way around this? it's simply a dictionary that i want to write to file.. this works no problems with ordinary dicts. thank you. From digitig at gmail.com Fri Jan 23 09:50:00 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 14:50:00 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: 2009/1/23 Kay Schluehr : > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. Well, maybe, but it seems to me that the real issue here is that we need to remove reference counting and the GIL. -- Tim Rowe From mrkafk at gmail.com Fri Jan 23 10:12:00 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:12:00 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> Message-ID: John Machin wrote: >> The factor of 30 indeed does not seem right -- I have done somewhat >> similar stuff (calculating Levenshtein distance [edit distance] on words >> read from very large files), coded the same algorithm in pure Python and >> C++ (using linked lists in C++) and Python version was 2.5 times slower. > Levenshtein distance using linked lists? That's novel. Care to > divulge? I meant: using linked lists to store words that are compared. I found using vectors was slow. Regards, mk From kw at codebykevin.com Fri Jan 23 10:18:12 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 23 Jan 2009 10:18:12 -0500 Subject: Find all available Tkinter cursor names? In-Reply-To: References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> Message-ID: <4979DFB4.4030705@codebykevin.com> r wrote: > Thanks Kevin, > These are exactly the ones i already knew about. I was hoping there > where more, shucks!. I wonder how i could go about making my own > cursors and adding them to Tkinter? Have any ideas? http://wiki.tcl.tk/8674 might offer some help in this regard. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From skip at pobox.com Fri Jan 23 10:33:08 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 09:33:08 -0600 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <18809.58164.565369.560733@montanaro.dyndns.org> >> You mean every time you access a list or dictionary or class >> instance, you have to acquire a mutex? That sounds like a horrible >> slowdown. Steve> Indeed it would, but hey, let's not let that stop us repeating Steve> the thinking that's gone into CPython over the last fifteen Steve> years. "Those who cannot remember the past are condemned to Steve> repeat it". Also, every object is mutable at some level. Tuples, ints and floats are definitely mutable at creation time. You need to hold a mutex then, so Carl's notion of three types of objects breaks down then. Skip From skip at pobox.com Fri Jan 23 10:35:52 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 09:35:52 -0600 Subject: Stalled ticket in Python bug tracker In-Reply-To: <0189ceca$0$20671$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: <18809.58328.566312.840475@montanaro.dyndns.org> Steven> I'm interested in this ticket in the bug tracker: Steven> http://bugs.python.org/issue2527 Steven> but it seems to have been stalled for nine months. Is there a Steven> procedure for starting it up again? Assign it to yourself? Add a comment with relevant updates? Steven> Should I ask about it on the python-dev mailing list, or just Steven> wait until somebody happens to notice it? But you've already noticed it. ;-) Skip From clp2 at rebertia.com Fri Jan 23 10:38:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 07:38:53 -0800 Subject: writing pickle function In-Reply-To: References: Message-ID: <50697b2c0901230738o4dc22c35sa6b790b91c938f11@mail.gmail.com> On Fri, Jan 23, 2009 at 6:48 AM, wrote: > hello, > > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. Functions aren't pickleable because they're Python code (which is itself not pickleable). defaultdicts contain a reference to a function (in your case, a function defined using lambda), which they use to create default values. Thus, this causes defaultdicts to not be pickleable. This is easily worked around by pickling a plain dict w/ the contents of the defaultdict (i.e. dict(x) ) and then doing: x = defaultdict(lambda: defaultdict(list)) #create empty defaultdict x.update(pickle.load(the_file)) #shove contents of pickled dict into the defaultdict Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mrkafk at gmail.com Fri Jan 23 10:52:42 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:52:42 +0100 Subject: DrPython and py2exe In-Reply-To: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: imageguy wrote: > drPython is probably selecting a specific version of wxpython and > py2exe doesn't like it or > can't find it. Once you solve that, py2exe will work fine with > wxpython. Thanks, drPython was indeed making use of wxversion.select. What's strange is that it was selecting apparently correct version: import wxversion wxversion.select('2.8') I put this in setup.py: import wxversion wxversion.select("2.8.9.1") import wx ..and it worked. Regards, mk From mrkafk at gmail.com Fri Jan 23 10:57:16 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:57:16 +0100 Subject: seeking to improve Python skills In-Reply-To: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: Jean-Paul Calderone wrote: > The most significant thing missing from this code is unit tests. > Developing automated tests for your code will help you learn a lot. Thanks for all the remarks, I'll restructure my code. Probably the biggest mistake was not keeping "moving average" class and others focused on its respective jobs only. However, unit tests are a tougher cookie, do you have any resource that's truly worth recommending for learning unit tests? The only resource I found that was talking at some length about it was "Dive into Python" and I was wondering if there's anything better out there... Regards, mk From exarkun at divmod.com Fri Jan 23 11:09:08 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 11:09:08 -0500 Subject: seeking to improve Python skills In-Reply-To: Message-ID: <20090123160908.24460.870588213.divmod.quotient.479@henry.divmod.com> On Fri, 23 Jan 2009 16:57:16 +0100, mk wrote: >Jean-Paul Calderone wrote: > >>The most significant thing missing from this code is unit tests. >>Developing automated tests for your code will help you learn a lot. > >Thanks for all the remarks, I'll restructure my code. Probably the biggest >mistake was not keeping "moving average" class and others focused on its >respective jobs only. > >However, unit tests are a tougher cookie, do you have any resource that's >truly worth recommending for learning unit tests? The only resource I found >that was talking at some length about it was "Dive into Python" and I was >wondering if there's anything better out there... I haven't read it, but a skilled colleague of mine recommends . Jean-Paul From benjamin.kaplan at case.edu Fri Jan 23 11:20:18 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 11:20:18 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 9:50 AM, Tim Rowe wrote: > 2009/1/23 Kay Schluehr : > > Whatever sufficiently sophisticated topic was the initially discussed > > it ends all up in a request for removing reference counting and the > > GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. > But that would be hard and require a major rewrite. ;) BTW, he said sufficiently sophisticated topic. Since there hasn't been an extremely long post here yet, I don't know if this counts. > > -- > Tim Rowe > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcd at sdf.lonestar.org Fri Jan 23 11:30:00 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 23 Jan 2009 11:30:00 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <1232728200.5356.0.camel@aalcdl07.lib.unc.edu> I dub it Schluehr's law. On Thu, 2009-01-22 at 21:39 -0800, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. > > -- > http://mail.python.org/mailman/listinfo/python-list > From washakie at gmail.com Fri Jan 23 11:32:10 2009 From: washakie at gmail.com (John [H2O]) Date: Fri, 23 Jan 2009 08:32:10 -0800 (PST) Subject: Where to place imports Message-ID: <21627895.post@talk.nabble.com> Hello, Im writing some modules and I am a little confused about where to place my imports... I don't really do any class programming yet, just defining a bunch of functions, so presently I have something along the lines of: import sys import os import traceback def Foo1(a,b): import numpy import datetime return c def Foo2(a,b): import datetime c = Foo1(a,b) return c etc... Above obviously just for the form, but the point is, in some cases I may import modules twice, but other times I may not use them at all, so should I import everything into the main module? Or individually import them into functions. Is there a performance penalty either way? Pointers to a good reference are appreciated... -- View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21627895.html Sent from the Python - python-list mailing list archive at Nabble.com. From ppearson at nowhere.invalid Fri Jan 23 11:36:46 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 23 Jan 2009 16:36:46 GMT Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> Message-ID: <6tua0tFcpeeqU1@mid.individual.net> On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: > En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson > escribi?: > >> The following code uses ossaudiodev to read 1000 values from >> my sound card at a rate of 12,000 samples per second: >> >> When I select a sample rate that is not a power of 2 times >> 3000 samples/second, a strong and very regular sawtooth is >> superimposed on the signal. At some sampling frequencies, >> it appears as a rising sawtooth, and at other sampling >> frequencies it is a declining sawtooth, so I'm presumably >> lost in some aliasing wilderness. As best I can tell, >> it's a 48 KHz sawtooth. > > That could be a hardware and/or driver limitation. By example, an > AC97-compliant chipset may provide a fixed rate of 48000 samples/second -- > any sample rate conversion must be done by other means, if possible at all. Oh! As a matter of fact, my "soundcard" *is* AC97-compliant ("VT8233/A/8235/8237", according to Sysinfo). So . . . this sawtooth might result from some software, somewhere in the bucket brigade between me and the hardware, attempting to perform sample-rate conversion? The 48 KHz coincidence seems very significant. Thanks. -- To email me, substitute nowhere->spamcop, invalid->net. From deets at nospam.web.de Fri Jan 23 11:48:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 17:48:19 +0100 Subject: Where to place imports In-Reply-To: References: Message-ID: <6tuamjFckgp0U1@mid.uni-berlin.de> John [H2O] schrieb: > Hello, Im writing some modules and I am a little confused about where to > place my imports... > > I don't really do any class programming yet, just defining a bunch of > functions, so presently I have something along the lines of: > > import sys > import os > import traceback > > > def Foo1(a,b): > import numpy > import datetime > return c > > def Foo2(a,b): > import datetime > > c = Foo1(a,b) > return c > > etc... > > Above obviously just for the form, but the point is, in some cases I may > import modules twice, but other times I may not use them at all, so should I > import everything into the main module? Or individually import them into > functions. Is there a performance penalty either way? Usually, you should import on the top of the module. That's the cleanest way, and the most performant one. There is a small performance penalty when doing it inside functions - but not too much. It boils down to a lookup if the imported module has already been imported before. The only valid reason for doing imports inside functions is if you otherwise get into circular dependency hell, or have modules that need some manipulation of the sys.path before they actually can be imported. This is never true for system modules, and certainly to avoid if possible. Diez From gagsl-py2 at yahoo.com.ar Fri Jan 23 11:55:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 23 Jan 2009 14:55:36 -0200 Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> <6tua0tFcpeeqU1@mid.individual.net> Message-ID: En Fri, 23 Jan 2009 14:36:46 -0200, Peter Pearson escribi?: > On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: >> En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson >> escribi?: >> >>> The following code uses ossaudiodev to read 1000 values from >>> my sound card at a rate of 12,000 samples per second: >>> >>> When I select a sample rate that is not a power of 2 times >>> 3000 samples/second, a strong and very regular sawtooth is >>> superimposed on the signal. At some sampling frequencies, >>> it appears as a rising sawtooth, and at other sampling >>> frequencies it is a declining sawtooth, so I'm presumably >>> lost in some aliasing wilderness. As best I can tell, >>> it's a 48 KHz sawtooth. >> >> That could be a hardware and/or driver limitation. By example, an >> AC97-compliant chipset may provide a fixed rate of 48000 samples/second >> any sample rate conversion must be done by other means, if possible at >> all. > > Oh! As a matter of fact, my "soundcard" *is* AC97-compliant > ("VT8233/A/8235/8237", according to Sysinfo). So . . . this > sawtooth might result from some software, somewhere in the bucket > brigade between me and the hardware, attempting to perform > sample-rate conversion? The 48 KHz coincidence seems very > significant. Yep. Google found this for me: http://mail-index.netbsd.org/port-i386/2003/02/18/0003.html Using a sample rate that is a sub-multiple of 48000 is perhaps a safe approach. -- Gabriel Genellina From ppearson at nowhere.invalid Fri Jan 23 11:57:58 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 23 Jan 2009 16:57:58 GMT Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> Message-ID: <6tub8mFcrapoU1@mid.individual.net> On Fri, 23 Jan 2009 06:10:31 -0800 (PST), kt83313 at gmail.com wrote: > On Jan 23, 4:41?pm, Bryan Olson wrote: [snip] >> Look up DRM technology companies, such as CloakWare, Macrovision, and >> Cryptography Research. >> >> If you have a modest number of customers, hardware solutions and/or >> strict contractual commitments might offer practical solutions. >> > Thank you very much Bryan. > It does look like this is out of my league. It is out of *everyone's* league. Every company that has ever wanted to sell movies or music that you can play on your computer but that you can't post to the Internet has faced this problem. Many, many millions of dollars have been spent searching for mitigation. The best you can hope for is to delay your attacker by some number of months. That might be enough if the value of your content is ephemeral, but even that can only be achieved with a big initial investment, enormous implementation hassles, and commitment to a never-ending arms race with the pirates. -- To email me, substitute nowhere->spamcop, invalid->net. From washakie at gmail.com Fri Jan 23 12:08:22 2009 From: washakie at gmail.com (John [H2O]) Date: Fri, 23 Jan 2009 09:08:22 -0800 (PST) Subject: Where to place imports In-Reply-To: <6tuamjFckgp0U1@mid.uni-berlin.de> References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <21628590.post@talk.nabble.com> So it isn't inefficient to import a bunch of modules that may not be used, say if only one function is used that doesn't rely on a larger module like numpy or pylab? Thanks. Diez B. Roggisch-2 wrote: > > John [H2O] schrieb: >> Hello, Im writing some modules and I am a little confused about where to >> place my imports... >> >> I don't really do any class programming yet, just defining a bunch of >> functions, so presently I have something along the lines of: >> >> import sys >> import os >> import traceback >> >> >> def Foo1(a,b): >> import numpy >> import datetime >> return c >> >> def Foo2(a,b): >> import datetime >> >> c = Foo1(a,b) >> return c >> >> etc... >> >> Above obviously just for the form, but the point is, in some cases I may >> import modules twice, but other times I may not use them at all, so >> should I >> import everything into the main module? Or individually import them into >> functions. Is there a performance penalty either way? > > Usually, you should import on the top of the module. That's the cleanest > way, and the most performant one. > > There is a small performance penalty when doing it inside functions - > but not too much. It boils down to a lookup if the imported module has > already been imported before. > > > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules, and certainly to avoid if possible. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21628590.html Sent from the Python - python-list mailing list archive at Nabble.com. From google at mrabarnett.plus.com Fri Jan 23 12:20:29 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 23 Jan 2009 17:20:29 +0000 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: <4979FC5D.6060807@mrabarnett.plus.com> Terry Reedy wrote: > bearophileHUGS at lycos.com wrote: > >> Also: what's the rationale of allowing negative values too? > > I can guess two: > 1) Nuisance to check given that Python does not have a count > (0,1,2...) type. > 2. Useful. + = items on hand; - = items back-ordered. Bank account go > negative also ;-). So does elevation. > Similarly, an app could set 0 to mean 'desired quantity on hand', so > non-zero count is surplus or deficit. > > I might not have thought to allow this, but it seems to open new > applications. (This definitely makes bag or multiset inappropriate > as names.) > I would've limited the counts to non-negative values too, but being able to store negative values does allow credit/debit or in-stock/on-order. In such cases, the name 'Counter' makes more sense. From yahoo at al-got-rhythm.net Fri Jan 23 12:46:48 2009 From: yahoo at al-got-rhythm.net (jalanb3) Date: Fri, 23 Jan 2009 17:46:48 -0000 Subject: Why is it faster the second time ? Message-ID: Hello the group, I am wondering why doctests run slower the first time. In the transcript below "try" is a script which finds and runs doctests in the current directory. It also shows how long it takes to run these tests. I added a new test which searches recursively for files given a path, and it took (approx) 3 seconds to run. But all subsequent runs take less than half a second. Am I right in thinking that the extra time on the first run is the time it takes to compile .py -> .pyc ? Transcript follows $ try paths.test try ./paths.test; 10 tests passed in 3 seconds 10 tests passed, 0 failed, in 3 seconds $ try paths.test try ./paths.test; 10 tests passed very quickly 10 tests passed, 0 failed, in 0 seconds $ try paths.test try ./paths.test; 10 tests passed very quickly 10 tests passed, 0 failed, in 0 seconds -- Alan From digitig at gmail.com Fri Jan 23 12:47:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 17:47:18 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: 2009/1/23 Benjamin Kaplan : > BTW, he said sufficiently sophisticated topic. Since there hasn't been an > extremely long post here yet, I don't know if this counts. Had I waited until the thread became long enough, somebody else would have already raised the issue -- you must surely know about Schluehr's Law? ;-) -- Tim Rowe From BrianVanderburg2 at aim.com Fri Jan 23 12:51:03 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 12:51:03 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: References: Message-ID: <497A0387.40307@aim.com> unineuro at gmail.com wrote: > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) > > I've had a similar problem here and here is best how I can explain it. The prop in the lambda function is a closure by 'name' to the prop in the containing name space (__init__), so when the lambda function executes, it looks for the name 'prop' in this name space and uses it's value. After the 'for prop in props' loop is complete, 'prop' is left referring to the last item in props, so each lambda function would use it (mary) One solution is to not use lambda and avoid closures by using default arguments: for prop in props: def Getter(self=self, prop=prop): return getattr(self, '__' + prop[0]) setattr(self, '__' + prop[0], prop[1]) setattr(self, 'Get' + prop[0], Getter) I have several problems with this though: 1. I don't think this will invoke Pythons name mangling mechanism. The property will be '__name' and not '__Person_name'. 2. If you make a copy of the class, including attributes, the Getter will operate on the old class not new: Person a b = copy.copy(a) setattr(a, '__name', bob) setattr(b, '__name', sarah) b.Getname() -> bob In order to make it work, the class must support updating the Getter when it is copied to have a new self value. import copy class MethodCaller: def __init__(self, obj, method, name): self.obj = obj self.method = method self.name = name setattr(obj, name, self) def __call__(self, *args, **kwargs): return self.method(self.obj, *args, **kwargs) def copy(self, newobj): return MethodCaller(newobj, self.method, self.name) props = ( ('name', 'mary'), ('age', 21), ('gender', 'female') ) class Person: def __init__(self): self._methods = [] for prop in props: (name, value) = prop def getter(self, name=name): return getattr(self, '_' + name) setattr(self, '_' + name, value) self._methods.append(MethodCaller(self, getter, 'Get' + name)) def copy(self,copymethods=True): c = copy.copy(self) if copymethods: c._methods = [] for i in self._methods: c._methods.append(i.copy(c)) return c # Example without copying methods p = Person() q = p.copy(False) p._name = 'sarah' q._name = 'michelle' print p.Getname() print p.Getage() print p.Getgender() print q.Getname() # Still prints 'sarah', because getter still refers to 'p' instead of 'q' print q.Getage() print q.Getgender() # Example with copying methods p = Person() q = p.copy() p._name = 'sarah' q._name = 'michelle' print p.Getname() print p.Getage() print p.Getgender() print q.Getname() # Prints 'michelle' print q.Getage() print q.Getgender() From deets at nospam.web.de Fri Jan 23 12:52:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 18:52:13 +0100 Subject: Where to place imports In-Reply-To: References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <6tueedFbg9nsU1@mid.uni-berlin.de> John [H2O] schrieb: > So it isn't inefficient to import a bunch of modules that may not be used, > say if only one function is used that doesn't rely on a larger module like > numpy or pylab? Well, importing can take bit of time - but that's a short latency at startup-time, if anything. And if your module gets imported inside a function, it *is* used, isn't it? Diez From http Fri Jan 23 12:53:02 2009 From: http (Paul Rubin) Date: 23 Jan 2009 09:53:02 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <7xiqo57vup.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > Also, every object is mutable at some level. Tuples, ints and floats are > definitely mutable at creation time. You need to hold a mutex then, so > Carl's notion of three types of objects breaks down then. Hopefully, at creation time, they will usually be in a scope where other threads can't see them. From steve at holdenweb.com Fri Jan 23 13:01:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 13:01:44 -0500 Subject: Where to place imports In-Reply-To: <6tuamjFckgp0U1@mid.uni-berlin.de> References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: [...] > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules, and certainly to avoid if possible. > Well there is also the somewhat obscure point that an import of specific names inside a function makes them local, which *might* make a performance difference with tight loop nesting inside - though obviously the need for such will best be determined by benchmarking: >>> def f1(): ... from os.path import join ... print join ... >>> from os.path import join >>> def f2(): ... print join ... >>> dis.dis(f1) 2 0 LOAD_CONST 1 (-1) 3 LOAD_CONST 2 (('join',)) 6 IMPORT_NAME 0 (os.path) 9 IMPORT_FROM 1 (join) 12 STORE_FAST 0 (join) 15 POP_TOP 3 16 LOAD_FAST 0 (join) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_GLOBAL 0 (join) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE >>> Not a major issue, just another aspect of the question ... and of course the OP should take the advice already given unless and until performance becomes a problem (since it usually won't). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Fri Jan 23 13:04:42 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 19:04:42 +0100 Subject: Where to place imports In-Reply-To: References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <6tuf5qFcnd2vU1@mid.uni-berlin.de> Steve Holden schrieb: > Diez B. Roggisch wrote: > [...] >> The only valid reason for doing imports inside functions is if you >> otherwise get into circular dependency hell, or have modules that need >> some manipulation of the sys.path before they actually can be imported. >> This is never true for system modules, and certainly to avoid if possible. >> > Well there is also the somewhat obscure point that an import of specific > names inside a function makes them local, which *might* make a > performance difference with tight loop nesting inside - though obviously > the need for such will best be determined by benchmarking: But that could be mitigated using aliasing, which is a more general optimization technique, as it works not only for imported names but also for e.g. bound methods, or any other chained lookups. Diez From kyrie at uh.cu Fri Jan 23 13:07:55 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 23 Jan 2009 13:07:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901231307.55379.kyrie@uh.cu> On Friday 23 January 2009 06:31:50 am Antoon Pardon wrote: > On 2009-01-16, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > >> If you "*shouldn't* mess with the implementation", then what is wrong > >> with enforcing that "shouldn't" in the language itself? > > > > Because, as a library user, it should be my power to chose when and how I > > _should_ mess with the implementation, not the compiler, and definitely > > not you. > > Why should it be in your power? By messing with the implementation of a > library you risk the correctness of the code of all participant coders in > that project. I not that sure it should be your power to chose when and how > to do that. Ok, let me fix that. It should be in _our_ power as the team of all participant coders on _our_ project to decide if we should mess with the internals or not. What makes no sense is that it should be in the original author's power to decide, if he is not part of _our_ team. Do you like it better now? Wasn't it obvious in the first place? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From duncan.booth at invalid.invalid Fri Jan 23 13:50:00 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Jan 2009 18:50:00 GMT Subject: Where to place imports References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: "John [H2O]" wrote: > So it isn't inefficient to import a bunch of modules that may not be > used, say if only one function is used that doesn't rely on a larger > module like numpy or pylab? > Not really. If you import it at all then you might as well import it on startup i.e. at the top of the module. Importing from inside a function doesn't free up the imported module when the function returns, so you aren't going to save any memory in the long run. I would accept that if you have a function that may not be called in most runs of the program, and that function uses some large module that wouldn't otherwise be loaded, then you might have a case for importing it only inside the function. But that's a very rare situation; otherwise, just import it at module scope. BTW, if you ever find you are starting to write multi-threaded applications then you'll really regret it if you reuse code which does imports from inside functions. If two or more threads try to import a module simultaneously then one of them might find it that not everything is defined in the module exists when it tries to use it. From rhamph at gmail.com Fri Jan 23 14:01:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Fri, 23 Jan 2009 11:01:24 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: On Jan 22, 11:09?pm, Carl Banks wrote: > On Jan 22, 9:38?pm, Rhamphoryncus wrote: > > > > > On Jan 22, 9:38?pm, Carl Banks wrote: > > > > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > > > Paul Rubin ? wrote: > > > > > >alex23 writes: > > > > > >> Here's an article by Guido talking about the last attempt to remove > > > > >> the GIL and the performance issues that arose: > > > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > > > >> program) *does not decrease*." > > > > > >The performance decrease is an artifact of CPython's rather primitive > > > > >storage management (reference counts in every object). ?This is > > > > >pervasive and can't really be removed. ?But a new implementation > > > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > > > >suffer from such effects. > > > > > CPython's "primitive" storage management has a lot to do with the > > > > simplicity of interfacing CPython with external libraries. ?Any solution > > > > that proposes to get rid of the GIL needs to address that. > > > > I recently was on a long road trip, and was not driver, and with > > > nothing better to do thought quite a bit about how this. > > > > I concluded that, aside from one major trap, it wouldn't really be > > > more difficult to inteface Python to external libraries, just > > > differently difficult. ?Here is briefly what I came up with: > > > > 1. Change the singular Python type into three metatypes: > > > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > > > case, the object itself is immutable but the dict can be modified. > > > This, of course, would be the default metaclass in Python.) ?Only > > > mutable_types would require a mutex when accessing. > > > > 2. API wouldn't have to change much. ?All regular API would assume > > > that objects are unlocked (if mutable) and in a consistent state. > > > It'll lock any mutable objects it needs to access. ?There would also > > > be a low-level API that assumes the objects are locked (if mutable) > > > and does not require objects to be consistent. ?I imagine most > > > extensions would call the standard API most of the time. > > > > 3. If you are going to use the low-level API on a mutable object, or > > > are going to access the object structure directly, you need to acquire > > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > > would be provided. > > > > 4. Objects would have to define a method, to be called by the GC, that > > > marks every object it references. ?This would be a lot like the > > > current tp_visit, except it has to be defined for any object that > > > references another object, not just objects that can participate in > > > cycles. ?(A conservative garbage collector wouldn't suffice for Python > > > because Python quite often allocates blocks but sets the pointer to an > > > offset within the block. ?In fact, that's true of almost any Python- > > > defined type.) ?Unfortunately, references on the stack would need to > > > be registered as well, so "PyObject* p;" might have to be replaced > > > with something like "Py_DECLARE_REF(PyObject,p);" which magically > > > registers it. ?Ugly. > > > > 5. Py_INCREF and Py_DECREF are gone. > > > > 6. GIL is gone. > > > > So, you gain the complexity of a two-level API, having to lock mutable > > > objects sometimes, and defining more visitor methods than before, but > > > you don't have to keep INCREFs and DECREFs straight, which is no small > > > thing. > > > > The major trap is the possibily of deadlock. ?To help minimize the > > > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > > > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > > > (b,a) at the same time, it won't result in a deadlock. ?What's > > > disappointing is that the deadlocking possibility is always with you, > > > much like the reference counts are. > > > IMO, locking of the object is a secondary problem. ?Python-safethread > > provides one solution, but it's not the only conceivable one. ?For the > > sake of discussion it's easier to assume somebody else is solving it > > for you. > > That assumption might be good for the sake of the discussion *you* > want to have, but it's not for discussion I was having, which was to > address Aahz's claim that GIL makes extension writing simple by > presenting a vision of what Python might be like if it had a mark-and- > sweep collector. ?The details of the GC are a small part of that and > wouldn't affect my main point even if they are quite different than I > described. ?Also, extension writers would have to worry about locking > issues here, so it's not acceptable to assume somebody else will solve > that problem. > > > Instead, focus on just the garbage collection. > > [snip rest of threadjack] > > You can ignore most of what I was talking about and focus on > technicalities of garbage collection if you want to. ?I will not be > joining you in that discussion, however. > > Carl Banks I'm sorry, you're right, I misunderstood your context. From exarkun at divmod.com Fri Jan 23 14:03:41 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 14:03:41 -0500 Subject: Where to place imports In-Reply-To: Message-ID: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> On 23 Jan 2009 18:50:00 GMT, Duncan Booth wrote: > [snip] > >BTW, if you ever find you are starting to write multi-threaded applications >then you'll really regret it if you reuse code which does imports from >inside functions. If two or more threads try to import a module >simultaneously then one of them might find it that not everything is >defined in the module exists when it tries to use it. What makes you say this? There is an import lock (beyond the GIL) which should prevent a thread from ever seeing a partially initialized module. Jean-Paul From grflanagan at gmail.com Fri Jan 23 14:10:39 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Fri, 23 Jan 2009 11:10:39 -0800 (PST) Subject: writing pickle function References: Message-ID: <27ff47f8-6ba3-4b91-9b6e-6b25a272cb60@r15g2000prh.googlegroups.com> On Jan 23, 2:48?pm, perfr... at gmail.com wrote: > hello, > > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. > > thank you. One way via a subclass: (from memory) class MyCollection(defaultdict): def __init__(self): defaultdict.__init__(self, list) def __reduce__(self): return (MyCollection, (), None, None, self.iteritems()) and if you are so inclined (nothing to do with pickling): __setattr__ = defaultdict.__setitem__ __getattr__ = defaultdict.__getitem__ G. From aquil.abdullah at gmail.com Fri Jan 23 14:19:07 2009 From: aquil.abdullah at gmail.com (aha) Date: Fri, 23 Jan 2009 11:19:07 -0800 (PST) Subject: Parsing XML: SAX, DOM, Expat, or Something Else? Message-ID: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Hello All, I've been charged with developing an XML configuration file format, for one of the applications that my company develops. (Yes, I know it would have been easier to just use the configuration file format as described in RFC 822) While I am finally comfortable with the XML description that we've agreed upon; I am still trying to determine the best XML parser API to use. I would love to use XPATH, however I face the following restriction: The Python scripts that perform the parsing of the XML configuration file must be compatible with Python Versions 2.2-present. This means that any functionality that I use needs to be compatible with Python 2.2. I started with the DOM API in xml.dom.minidom and I thought that it might be the best way to go, but then I ran across the Recipes of Wai Yip Tung http://code.activestate.com/recipes/534109/ and John Bair, Christoph Dietze from the second edition of the Python cookbook. Wai's implementation uses thes SAX parser and John and Christoph's implementation uses Expat API. In the end what I really want is to transform the XML into an object that looks like config.component.setting or a map config[component][setting]. Another restriction is that I don't want to have to ship additional modules. Does anyone have any advice, comments, or HELP??? Aquil H. Abdullah Developer From hniksic at xemacs.org Fri Jan 23 14:19:35 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 23 Jan 2009 20:19:35 +0100 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <87ljt1g794.fsf@mulj.homelinux.net> Carl Banks writes: > Unfortunately, references on the stack would need to be registered > as well, so "PyObject* p;" might have to be replaced with something > like "Py_DECLARE_REF(PyObject,p);" which magically registers it. > Ugly. Not only registered at the beginning of the function, but also (since CPython uses C, not C++) explicitly unregistered at every point of exit from the function. Emacs implements these as macros called GCPRO and UNGCPRO, and they're very easy to get wrong. In a way, they are even worse than the current Python INCREF/DECREF. See description at, for example, http://www.xemacs.org/Documentation/beta/html/internals_19.html#SEC78 From xahlee at gmail.com Fri Jan 23 14:19:58 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 23 Jan 2009 11:19:58 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems Message-ID: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> recently, as you might have noted by a previous post of mine, that American Mathematical Society published a series of articles on formal proofs in 2008 November. See: http://www.ams.org/notices/200811/ The articles are: ? Formal Proof by Thomas Hales ? Formal Proof ? The Four-Color Theorem by Georges Gonthier ? Formal Proof ? Theory and Practice by John Harrison ? Formal Proof ? Getting Started by Freek Wiedijk I read 3 of them in December (only scanned the four-color theorem one). It was quite a fantastically enjoyable reading. ( For some personal notes, see: Current State Of Theorem Proving Systems at the bottom of ? The Codification of Mathematics http://xahlee.org/cmaci/notation/math_codify.html ) As you may know, codification of math has been a long personal interest. In fact, my logical analytic habit has made me unable to read most math texts, which are full of logical errors and relies on a ?human? interpretation for its soundness and clarity. having read those intro articles from the AMS publication on current state of the art, i decided that i'm going to learn HOL Light. (tried to learn Coq before and the tutorial is problematic) One of the interesting finding was that almost all theorem proving systems are written in ML family lang, e.g. Caml, Ocaml. Of course, i heard of Ocaml since about 1998 when i was doing Scheme. Somehow it never impressed me from reading the functional programing FAQ. I have always been attracted more to Haskell, perhaps only because it is _pure_ in the sense of not allowing assignment. With that, ocaml has been ?just another functional lang? in my mind. But now, seeing that most theorem proving systems used in the real world are in Caml, thus i made start to learn Ocaml now. (in fact, its root is a theorem prover) i wanted to add proofs as enhancement to my A Visual Dictionary Of Special Plane Curves. Also, had ambition to write more... about algebraic geometry and differential geometry and geometry with complex numbers. Proofs will be major part of these type of works. I can no longer tolerate traditional mouthy written-english proofs. They must be codified proofs. In this: HOL Light Tutorial (for version 2.20) by John Harrison September 9, 2006, there's this paragraph: ?This fits naturally with the view, expressed for example by Dijkstra (1976), that a programming language should be thought of first and foremost as an algorithm-oriented system of mathematical notation, and only secondarily as something to be run on a machine.? Wee! That has been my view since about 1997. The only lang that adhere to that view i know of is Mathematica. (lisping morons don't understand a iota of it. See: ? Is Lisp's Objects Concept Necessary? http://xahlee.org/emacs/lisps_objects.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html ) btw, anyone know the source of that Dijkstra quote? Xah ? http://xahlee.org/ ? From clp2 at rebertia.com Fri Jan 23 14:25:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 11:25:30 -0800 Subject: Parsing XML: SAX, DOM, Expat, or Something Else? In-Reply-To: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> References: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Message-ID: <50697b2c0901231125j78c4806j61803a6d1735c348@mail.gmail.com> On Fri, Jan 23, 2009 at 11:19 AM, aha wrote: > Hello All, > I've been charged with developing an XML configuration file format, > for one of the applications that my company develops. (Yes, I know it > would have been easier to just use the configuration file format as > described in RFC 822) While I am finally comfortable with the XML > description that we've agreed upon; I am still trying to determine the > best XML parser API to use. I would love to use XPATH, however I face > the following restriction: > > The Python scripts that perform the parsing of the XML configuration > file must be compatible with Python Versions 2.2-present. > > This means that any functionality that I use needs to be compatible > with Python 2.2. > > I started with the DOM API in xml.dom.minidom and I thought that it > might be the best way to go, but then I ran across the Recipes of Wai > Yip Tung > > http://code.activestate.com/recipes/534109/ > > > and John Bair, Christoph Dietze from the second edition of the Python > cookbook. > > Wai's implementation uses thes SAX parser and John and Christoph's > implementation uses Expat API. > > In the end what I really want is to transform the XML > > > > > > > > into an object that looks like > > config.component.setting or a map config[component][setting]. > > Another restriction is that I don't want to have to ship additional > modules. > > Does anyone have any advice, comments, or HELP??? ElementTree is in the std lib for Python 2.5+ and has a fairly Pythonic API compared to SAX/DOM. Docs for it: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Fri Jan 23 14:37:14 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:37:14 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <0189b204$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87pridddat.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > You've built something full of user serviceable parts. You've > insisted, publicly and loudly, that the ability to modify those parts > is absolutely essential, you've rejected every effort to lock down > those internals, and then when somebody does exactly what you > encourage, you suddenly turn on them and say they're on their own. > > That's pretty irresponsible behaviour. An egregious mischaracterization. Again, you're refusing to see the distinction between a published, stable interface, and exposed but potentially volatile internals. If you use my published interface and your program is broken by a change, it's my fault and I try to fix it; if you use the internals and your program's broken by a change, it's your fault and you're on your own. It's pretty easy. There are three possibilities: * The interface does what I want it to do. Cool. I win. * The interface doesn't do what I want it to do, but I can hack the internal guts until it does. Cool for now, but I might get screwed later if they change. Well, it's something to think about. * The interface doesn't do what I want it to do, and I can't hack the internal guts. I just lose. If all interfaces were perfect, there wouldn't be an argument. But they aren't. So we're sometimes left with the other two choices. Which one looks more appealing to you? -- [mdw] From stefan_ml at behnel.de Fri Jan 23 14:38:55 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jan 2009 20:38:55 +0100 Subject: Parsing XML: SAX, DOM, Expat, or Something Else? In-Reply-To: References: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Message-ID: <497a1cd0$0$30227$9b4e6d93@newsspool1.arcor-online.net> Chris Rebert wrote: > On Fri, Jan 23, 2009 at 11:19 AM, aha wrote: >> I've been charged with developing an XML configuration file format, >> for one of the applications that my company develops. >> [...] >> I am still trying to determine the >> best XML parser API to use. I would love to use XPATH, however I face >> the following restriction: >> >> The Python scripts that perform the parsing of the XML configuration >> file must be compatible with Python Versions 2.2-present. > > ElementTree is in the std lib for Python 2.5+ and has a fairly > Pythonic API compared to SAX/DOM. > Docs for it: http://docs.python.org/library/xml.etree.elementtree.html The downloadable package (version 1.2.x) still works with Python 2.2 (last I heard, at least). ET also has simple support for XPath-like expressions (without conditions, that is). Starting to use it now will however allow you to switch to the mostly compatible lxml.etree package once you decide to move on to Python 2.3 or later. lxml has full support for XPath (and XSLT and tons of other goodies). Stefan From Scott.Daniels at Acm.Org Fri Jan 23 14:40:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 11:40:33 -0800 Subject: what gives with In-Reply-To: References: Message-ID: Darren Dale wrote: > .... What is the point of providing absolute_import in __future__ if the > api is completely different than the implementation in future python versions? The point is to obtain user experience with a proposed feature _before_ you fix the interface and start having to be "backward compatible." --Scott David Daniels Scott.Daniels at Acm.Org From mdw at distorted.org.uk Fri Jan 23 14:41:31 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:41:31 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> <1c99aef0-a4fa-4b8a-a0e2-1ba59bf5f703@i24g2000prf.googlegroups.com> Message-ID: <87ljt1dd3o.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Was this library module released in source form? > > If so, then why would you care that it has enforced access > restrictions? You can just take them out, then do whatever you would > have done had they not been there to start with. I don't see how that > is any more work than figuring out what internals you need to access. > Either way you need to read and understand the code. I could do. But in practice internal details often aren't horrifically unstable. If I fork the library, I've now got to mess with distributing the forked version, and keeping the patch up to date -- the codebase is likely to be much more volatile than the internals I'm hacking on. It's just not such a good tradeoff. See elsewhere where I described hacking Python's `long' representation. You'd have me fork the Python interpreter. That doesn't seem like a win to me. > Wait ... it wasn't released in source form? Then how would you even > know what internals you need to access? We call them `disassemblers' and `debuggers'. Sometimes even simple experimentation is sufficient. > And why would you use something that goes against your philosophy of > openness anyway? I try not to. Sometimes I fail. -- [mdw] From Scott.Daniels at Acm.Org Fri Jan 23 14:45:08 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 11:45:08 -0800 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: Steve Holden wrote: > .... Write a class that implements a __call__() method, and use an instance > of that class as your callback. Then the data can be stored as the callback > object's private instance data. In fact, you needn't name the method __call__. You can pass in Holder().method if you have no other use for the instance of your Holder instance. --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Fri Jan 23 14:45:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 11:45:50 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <214c2ed9-2181-4261-ba8e-5044daed9d61@w24g2000prd.googlegroups.com> On Jan 23, 7:33?am, s... at pobox.com wrote: > ? ? >> You mean every time you access a list or dictionary or class > ? ? >> instance, you have to acquire a mutex? ?That sounds like a horrible > ? ? >> slowdown. > > ? ? Steve> Indeed it would, but hey, let's not let that stop us repeating > ? ? Steve> the thinking that's gone into CPython over the last fifteen > ? ? Steve> years. "Those who cannot remember the past are condemned to > ? ? Steve> repeat it". > > Also, every object is mutable at some level. ?Tuples, ints and floats are > definitely mutable at creation time. ?You need to hold a mutex then, so > Carl's notion of three types of objects breaks down then. immutable_type objects wouldn't exist at all until their PyWhatever_New or their tp_new member is called. After that, the reference exists only on the local stack, which is accessible only to one thread. As long as you finish initializing the object while it's still only on the stack, there is no possibility of a conflict. What about tp_init, then, you ask? Well it's simple: immutable_type doesn't call it. In fact, it requires that tp_init, tp_setattro, tp_mapping->mp_setitem, etc., are all null. immutable_obejcts have no instance dict, so if you want to create attributes in Python you have to use slots. immutable_object.__new__ accepts keyword arguments and initializes the slots with the value. class Record(immutable_object,slots=['name','number']): def __new__(cls,name): number = db.lookup_number(name) immutable_object.__new__(cls,name=name,number=number) Carl Banks From __peter__ at web.de Fri Jan 23 14:46:27 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jan 2009 20:46:27 +0100 Subject: writing pickle function References: Message-ID: perfreem at gmail.com wrote: > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. The error message is misleading. You can pickle your defaultdict if you use a "normal" function instead of the lambda: $ cat pickle_defaultdict.py import sys from collections import defaultdict from cPickle import dumps, loads if "--lambda" in sys.argv: make_inner = lambda: defaultdict(list) else: def make_inner(): return defaultdict(list) d = defaultdict(make_inner) d[1][2].append(42) e = loads(dumps(d)) print e == d $ python pickle_defaultdict.py True $ python pickle_defaultdict.py --lambda Traceback (most recent call last): File "pickle_defaultdict.py", line 13, in e = loads(dumps(d)) File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle function objects Peter From mdw at distorted.org.uk Fri Jan 23 14:47:29 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:47:29 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <87hc3pdctq.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > OK, fine, you can change the code of another member of the team. Are > you going to check with him first, or just do it? The point is that > changing an interface requires agreement of the team members who use > that interface, whether on the calling or the implementation side of > it. If you change interfaces without getting agreement with the other > team members, you probably won't be on the team for long. So far, so good. > And without access restrictions, accessing _private is equivalent to > changing the interface. You've basically unilaterally stretched it, yes. Programmers who do this when the implementer of the interface is three feet away deserve to get smacked. If you don't have an easy way to get the interface extended, you have a pleasant choice between hacking at the guts and just being screwed. Have a nice day. > On Jan 23, 4:57?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, kind >> of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? If you're working with developers you don't trust, you're going to lose anyway. -- [mdw] From mdw at distorted.org.uk Fri Jan 23 14:50:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:50:36 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <87d4eddcoj.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > Annotations *have* made it into 3.0, so it's possible that the might > become usable. Remember, they'll always be optional, so those who don't > want to use them won't lose anything at all. There's a problem here. An interface has two sides. Access control annotations, as far as I've seen so far, look like they're only optional on one side: that is, once specified on the implementation side, they have a mandatory effect on the user side. -- [mdw] From gerald.britton at gmail.com Fri Jan 23 14:58:34 2009 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 23 Jan 2009 14:58:34 -0500 Subject: is None vs. == None Message-ID: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> Hi -- Some time ago I ran across a comment recommending using is None instead of == None (also is not None, etc.) My own testing indicates that the former beats the latter by about 30% on average. Not a log for a single instruction but it can add up in large projects. I'm looking for a (semi)-official statement on this, but couldn't find one with normal googling. Can someone please send a link? From steve at holdenweb.com Fri Jan 23 14:59:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 14:59:46 -0500 Subject: writing pickle function In-Reply-To: References: Message-ID: Peter Otten wrote: > perfreem at gmail.com wrote: > >> i am using nested defaultdict from collections and i would like to >> write it as a pickle object to a file. when i try: >> >> from collections import defaultdict >> x = defaultdict(lambda: defaultdict(list)) >> >> and then try to write to a pickle file, it says: >> >> TypeError: can't pickle function objects >> >> is there a way around this? it's simply a dictionary that i want to >> write to file.. this works no problems with ordinary dicts. > > The error message is misleading. You can pickle your defaultdict if you use > a "normal" function instead of the lambda: > > $ cat pickle_defaultdict.py > import sys > from collections import defaultdict > from cPickle import dumps, loads > > if "--lambda" in sys.argv: > make_inner = lambda: defaultdict(list) > else: > def make_inner(): > return defaultdict(list) > > d = defaultdict(make_inner) > d[1][2].append(42) > e = loads(dumps(d)) > print e == d > > $ python pickle_defaultdict.py > True > $ python pickle_defaultdict.py --lambda > Traceback (most recent call last): > File "pickle_defaultdict.py", line 13, in > e = loads(dumps(d)) > File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex > raise TypeError, "can't pickle %s objects" % base.__name__ > TypeError: can't pickle function objects > But can you unpickle the objects you pickle? I believe that functions are references relative to the modules they come from, and so won't be found unless the same module can be imported at unpickle time. Could be wrong, haven't read the source, but I understand that functions work the same as classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 15:01:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 15:01:39 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: Rhamphoryncus wrote: [... eighty-eight quoted lines ...] > > I'm sorry, you're right, I misunderstood your context. Perhaps you could trim your posts to quote only the relevant context? Thanks. -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Fri Jan 23 15:02:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 12:02:38 -0800 Subject: is None vs. == None In-Reply-To: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> Message-ID: <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> On Fri, Jan 23, 2009 at 11:58 AM, Gerald Britton wrote: > Hi -- Some time ago I ran across a comment recommending using is > None instead of == None (also is not None, etc.) My own > testing indicates that the former beats the latter by about 30% on > average. Not a log for a single instruction but it can add up in > large projects. > > I'm looking for a (semi)-official statement on this, but couldn't find > one with normal googling. Can someone please send a link? >From http://www.python.org/dev/peps/pep-0008/ , 2nd bullet under "Programming Recommendations": - Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Just FYI, `is` compares object identity (pointer equality) whereas == checks for value equivalence (which causes a method call). This is why it's significantly faster. But the main reason is because it's idiomatic. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Fri Jan 23 15:09:48 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 20:09:48 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> Message-ID: <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >> Why on earth couldn't I change the code of another member of my team if >> that code needs changes ? The code is the whole team's ownership. > > That's a model that works well when you have a small team of, say, a > dozen people. It's not a model that works when you have hundreds of > developers working on the project. The last thing I want in my projects > is cowboys who ride all over other people's code, changing internals of > parts they barely know at the drop of a hat, causing who knows what side- > effects. Why are you assuming that Bruno would make his change in such an irresponsible manner? Such things need discussing, with some appropriate level of formality, with the people most involved with the relevant code -- which might be anything between a quick chat with the bloke across the room or an agenda item on the next team meeting to a written proposal. Given your apparent readiness to assume the worst of programmers at every opportunity (e.g., your above assumption that Bruno would change code unilaterally and secretly, assumptions elsewhere that programmers treat any exposed wiring as being published interface), I can only assume that you really need to get some better cow-orkers. > But anyway, this is a red-herring. Data hiding isn't really about > managing the development process, it's about ensuring that when you and > Fred are using Barney's OrderedDict class in your code, Barney is free to > change his the implementation without your code suddenly failing. It's > also to ensure that any changes you make at runtime to the class don't > suddenly make Fred's code break. If Barney, Fred and I share a room, we can discuss what we need from OrderedDict around the water-cooler. If we're all in different continents, the tradeoffs look different. If Barney's the kind of guy with quick turnaround, I might well just ask for the necessary change. If I'll have to wait for the next release in July (for posterity: it's January now) I'll probably hack the guts now. If I do that, Barney's still free to change his implementation. It might screw me, but that's my problem and not his; the alternative, with mandatory `hiding', is that I just lose: possible breakage down the line looks like an improvement. Now we come on to Fred. If Fred's across the room from me then we're back to the water-cooler. If he's on a different continent, and I know he'll be affected, I'll probably email him. If I've never heard of him at all, well, he might just lose when someone puts my code and Fred's together with OrderedDict; hopefully I'll get a bug report (I ought to have put a notice in with my distribution explaining that it uses undocumented internals of OrderedDict, so I should be in the firing line) and we'll sort through the wreckage. But again, if I just lost in the second paragraph, we wouldn't even have got this far. -- [mdw] From benjamin at python.org Fri Jan 23 15:28:13 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 20:28:13 +0000 (UTC) Subject: what gives with References: Message-ID: Darren Dale gmail.com> writes: > I was talking about the behavior after doing "from __future__ import > absolute_import". I've been developing on python-2.6 using > absolute_import for weeks, knowing that I could do "from __future__ > import absolute import" on python-2.5. Now when I try to use > python-2.5 I cant import my package. What is the point of providing > absolute_import in __future__ if the api is completely different than > the implementation in future python versions? Its bizarre. The API is not completely different. The 2.5 version of the feature just lacks the ability to import with "*". It is still same in 2.6, but with the ability to use "*". From steve at holdenweb.com Fri Jan 23 15:28:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 15:28:38 -0500 Subject: is None vs. == None In-Reply-To: <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Jan 23, 2009 at 11:58 AM, Gerald Britton > wrote: >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in >> large projects. >> >> I'm looking for a (semi)-official statement on this, but couldn't find >> one with normal googling. Can someone please send a link? > >>From http://www.python.org/dev/peps/pep-0008/ , > 2nd bullet under "Programming Recommendations": > > - Comparisons to singletons like None should always be done with > 'is' or 'is not', never the equality operators. > > > Just FYI, `is` compares object identity (pointer equality) whereas == > checks for value equivalence (which causes a method call). This is why > it's significantly faster. > But the main reason is because it's idiomatic. > And, just for completeness, the "is" test is canonical precisely because the interpreter guarantees there is only ever one object of type None, so an identity test is always appropriate. Even the copy module doesn't create copies ... >>> import copy >>> n = copy.copy(None) >>> id(n) 1555754480 >>> id(None) 1555754480 >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin at python.org Fri Jan 23 15:31:08 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 20:31:08 +0000 (UTC) Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano REMOVE-THIS-cybersource.com.au> writes: > > I'm interested in this ticket in the bug tracker: > > http://bugs.python.org/issue2527 > > but it seems to have been stalled for nine months. Is there a procedure > for starting it up again? Should I ask about it on the python-dev mailing > list, or just wait until somebody happens to notice it? Nobody is likely to notice it unless someone pushes forward with it. Non release critical bug reports and feature requests tend to fall down a black hole after about a week. From toby at tobiah.org Fri Jan 23 15:37:30 2009 From: toby at tobiah.org (Tobiah) Date: Fri, 23 Jan 2009 12:37:30 -0800 Subject: unzip array of arrays? References: Message-ID: On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: > On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: >> Although it's trivial to program, I wondered whether >> there was a builtin or particularly concise way to >> express this idea: >> >>> a = [(1, 2), (3, 4), (5, 6)] >>> field[a, 2] >> [2, 4, 6] >> >> where field() is some made up function. > > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> a= [(1, 2), (3, 4), (5, 6)] >>>> zip(*a) > [(1, 3, 5), (2, 4, 6)] >>>> zip(*a)[1] > (2, 4, 6) That would be what I was after. Where can I read about this mysterious use of the '*'? It only works in the context of the zip() function. It's hard to understand how the interpreter handles that. Thanks, Toby From clp2 at rebertia.com Fri Jan 23 15:44:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 12:44:36 -0800 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: <50697b2c0901231244x490e525wa3913e4f8b322df@mail.gmail.com> On Fri, Jan 23, 2009 at 12:37 PM, Tobiah wrote: > On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: > >> On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: >>> Although it's trivial to program, I wondered whether >>> there was a builtin or particularly concise way to >>> express this idea: >>> >>>> a = [(1, 2), (3, 4), (5, 6)] >>>> field[a, 2] >>> [2, 4, 6] >>> >>> where field() is some made up function. >> >> Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) >> [GCC 4.0.1 (Apple Inc. build 5484)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> a= [(1, 2), (3, 4), (5, 6)] >>>>> zip(*a) >> [(1, 3, 5), (2, 4, 6)] >>>>> zip(*a)[1] >> (2, 4, 6) > > That would be what I was after. Where can I read about > this mysterious use of the '*'? It only works in the > context of the zip() function. It's hard to understand > how the interpreter handles that. It works in all functions. Basically: f(*[1,2,3]) === f(1,2,3) I'm sure someone will also point out the docs. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From martin.hellwig at dcuktec.org Fri Jan 23 15:46:57 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 23 Jan 2009 20:46:57 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <497a2cce$0$183$e4fe514c@news.xs4all.nl> Tim Rowe wrote: > 2009/1/23 Kay Schluehr : >> Whatever sufficiently sophisticated topic was the initially discussed >> it ends all up in a request for removing reference counting and the >> GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. > Perhaps, but you could also say that if it was that widely discussed and still not changed that it was for a *good* reason, perhaps the reason may change over time but at this moment it is still a good reason. Or you can argue that even when an argument is repeated indefinitely it doesn't make it suddenly right. -- mph From Scott.Daniels at Acm.Org Fri Jan 23 15:47:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 12:47:00 -0800 Subject: seeking to improve Python skills In-Reply-To: References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: mk wrote: > Jean-Paul Calderone wrote: > >> The most significant thing missing from this code is unit tests. >> Developing automated tests for your code will help you learn a lot. > > However, unit tests are a tougher cookie, do you have any resource > that's truly worth recommending for learning unit tests? The only > resource I found that was talking at some length about it was "Dive into > Python" and I was wondering if there's anything better out there... Do the "Dive In" thing. You'll quickly develop instincts. Start with the simplest possible test of your function, run it, and fix your code until it passes. Add another test, and loop. The simplest possible test will unfortunately need a bit of bolerplate, but adding tests is easy. to start: import unittest import moving_average as ma class MovingAverageTest(unittest.TestCase): def test_simplest(self): 'Check the mechanics of getting a simple result' self.assertEqual(ma.moving_average(3, []), []) if __name__ == '__main__': unittest.main() Once that works, add another test: def test_simple(self): self.assertAlmostEqual(ma.moving_average(3, [1, 2, 3]), [2]) Once that works, check something a bit easier to get wrong: def test_floating(self): 'Check we have reasonable results' self.assertAlmostEqual(ma.moving_average(3, [1, 1, 3])[0], 1.6666667) and, as they so often say, "lather, rinse, repeat." --Scott David Daniels Scott.Daniels at Acm.Org From rdcollum at gmail.com Fri Jan 23 15:48:29 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 23 Jan 2009 12:48:29 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: > And, just for completeness, the "is" test is canonical precisely because > the interpreter guarantees there is only ever one object of type None, > so an identity test is always appropriate. Even the copy module doesn't > create copies ... > Does the interpreter guarantee the same for False and True bools? From tjreedy at udel.edu Fri Jan 23 16:06:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 16:06:00 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: Tim Rowe wrote: > 2009/1/23 Kay Schluehr : >> Whatever sufficiently sophisticated topic was the initially discussed >> it ends all up in a request for removing reference counting and the >> GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. Guido will give up reference counting and the consequent immediate gc when but only when *someone* presents an implementation that does and and that runs faster. Given the current ferment in dynamic language implementation, he just today wrote on pydev list "CPython's implementation strategy *will* evolve". Whether that means R.C. goes away or not remains to be seen. From tjreedy at udel.edu Fri Jan 23 16:16:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 16:16:57 -0500 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: Tobiah wrote: > On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: >>>>> zip(*a)[1] >> (2, 4, 6) > > That would be what I was after. Where can I read about > this mysterious use of the '*'? Python Symbol Glossary lists uses of all symbols. http://code.google.com/p/xploro/downloads/list From http Fri Jan 23 16:28:22 2009 From: http (Paul Rubin) Date: 23 Jan 2009 13:28:22 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7x3af91zm1.fsf@ruckus.brouhaha.com> Mark Wooding writes: > Now we come on to Fred. If Fred's across the room from me then we're > back to the water-cooler. If he's on a different continent, and I know > he'll be affected, I'll probably email him. If I've never heard of him > at all, well, he might just lose when someone puts my code and Fred's > together with OrderedDict... In a large project, more probably you'd enter a change request into some kind of tracking system, there would be discussion in the tracking system about how to do the change; perhaps at your weekly staff meeting you might bring up the issue with your PHB if you were blocking on the issue, and your PHB would bring it up at the inter-PHB meeting with Fred's PHB to bump the item's priority, and eventually Fred would check in a change and you would use it. There is necessarily some wasted motion in any organization of that size; good management is about keeping the friction to a minimum and getting the stuff done. From jason.scheirer at gmail.com Fri Jan 23 16:40:51 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 23 Jan 2009 13:40:51 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> On Jan 23, 12:48?pm, Roger wrote: > > And, just for completeness, the "is" test is canonical precisely because > > the interpreter guarantees there is only ever one object of type None, > > so an identity test is always appropriate. Even the copy module doesn't > > create copies ... > > Does the interpreter guarantee the same for False and True bools? Yes. I know that there are the PyObject* structs defined for you Py_True, Py_False and Py_None in the C level. Confusingly enough, the integers -5 through 257 are also singletons where the is test will work, but any int out of that range will not. >>> def copy_id(x): ... id1, id2 = id(x), id(copy.deepcopy(x)) ... print "Equal: %x %s %x" % (id1, ('==' if id1 == id2 else '! ='), id2) ... ... >>> copy_id(a()) Equal: a8fc90 != f32370 >>> copy_id(1) Equal: 9559c8 == 9559c8 >>> copy_id(None) Equal: 1e1da9f0 == 1e1da9f0 >>> copy_id(True) Equal: 1e1c5ec4 == 1e1c5ec4 >>> copy_id(False) Equal: 1e1c5eb8 == 1e1c5eb8 >>> copy_id("Hello") Equal: 1058840 == 1058840 >>> copy_id([]) Equal: 1067030 != 10673f0 ... large equal integers are not identical in memory location ... In [34]: x = 19591 In [35]: y = 19590+1 In [36]: id(x), id(y) Out[36]: (17937008, 17936588) ... but small ones are ... In [40]: x = 2 In [41]: y = 1+1 In [42]: id(x), id(y) Out[42]: (9787836, 9787836) From lists at cheimes.de Fri Jan 23 16:49:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 22:49:34 +0100 Subject: Where to place imports In-Reply-To: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> References: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> Message-ID: Jean-Paul Calderone schrieb: >> BTW, if you ever find you are starting to write multi-threaded >> applications >> then you'll really regret it if you reuse code which does imports from >> inside functions. If two or more threads try to import a module >> simultaneously then one of them might find it that not everything is >> defined in the module exists when it tries to use it. > > What makes you say this? There is an import lock (beyond the GIL) which > should prevent a thread from ever seeing a partially initialized module. Partially initialized modules aren't the issue here. One can easily create a dead lock situation with a mix of threads and imports. Example: * module 'mod_a' is imported [import lock is acquired] * module 'mod_a' spawns a new thread * the new thread tries to import another module 'mod_b' Python dead locks here and there is no chance to resolve the lock. The import of 'mod_b' is waiting for the first import. The first import hasn't finished because it's still executing the body of 'mod_a'. In order to avoid the situation you *must* never import a module in a thread other than the main thread. You should never start a thread in the body of a submodule, too. A large application should import all its modules first and then create its threads. If you really need to import a module from a sub thread or a method that might be called from a sub thread then you should use the C function PyImport_ImportModuleNoBlock() or use sys.modules and imp.lock_held(). Christian From sjmachin at lexicon.net Fri Jan 23 16:53:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 23 Jan 2009 13:53:25 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> On Jan 24, 7:48?am, Roger wrote: > > And, just for completeness, the "is" test is canonical precisely because > > the interpreter guarantees there is only ever one object of type None, > > so an identity test is always appropriate. Even the copy module doesn't > > create copies ... > > Does the interpreter guarantee the same for False and True bools? Why do you think it matters? Consider the circumstances under which you would use each of the following: if some_name == True: if some_name is True: if some_name: From lists at cheimes.de Fri Jan 23 16:53:39 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 22:53:39 +0100 Subject: is None vs. == None In-Reply-To: <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> Message-ID: Jason Scheirer schrieb: > Yes. I know that there are the PyObject* structs defined for you > Py_True, Py_False and Py_None in the C level. Confusingly enough, the > integers -5 through 257 are also singletons where the is test will > work, but any int out of that range will not. Small ints are cached. You should use "is True" or "is False" in Python 2.x because user can overwrite the True and False objects. In Python 3.0 both True and False are truly immutable and global singletons -- and keywords, too. The mutable nature of the name "True" makes a "while True:" loop sightly slower than a "while 1:" loop, too. Python 2.5: >>> None = 1 File "", line 1 SyntaxError: assignment to None >>> True = 1 >>> Python 3.0 >>> True = 1 File "", line 1 SyntaxError: assignment to keyword >>> None = 1 File "", line 1 SyntaxError: assignment to keyword From lists at cheimes.de Fri Jan 23 17:07:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 23:07:41 +0100 Subject: is None vs. == None In-Reply-To: <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> Message-ID: John Machin schrieb: > On Jan 24, 7:48 am, Roger wrote: >>> And, just for completeness, the "is" test is canonical precisely because >>> the interpreter guarantees there is only ever one object of type None, >>> so an identity test is always appropriate. Even the copy module doesn't >>> create copies ... >> Does the interpreter guarantee the same for False and True bools? > > Why do you think it matters? Consider the circumstances under which > you would use each of the following: > if some_name == True: > if some_name is True: > if some_name: The three lines translate (roughly) into: if some_name.__eq__(True): if id(some_name) == id(True): if some_name.__nonzero__(): # may check for __len__() != 0, too. In almost every case (99.99%) you want the last variant. The second variant From __peter__ at web.de Fri Jan 23 17:22:12 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jan 2009 23:22:12 +0100 Subject: writing pickle function References: Message-ID: Steve Holden wrote: > Peter Otten wrote: >> perfreem at gmail.com wrote: >> >>> i am using nested defaultdict from collections and i would like to >>> write it as a pickle object to a file. when i try: >>> >>> from collections import defaultdict >>> x = defaultdict(lambda: defaultdict(list)) >>> >>> and then try to write to a pickle file, it says: >>> >>> TypeError: can't pickle function objects >>> >>> is there a way around this? it's simply a dictionary that i want to >>> write to file.. this works no problems with ordinary dicts. >> >> The error message is misleading. You can pickle your defaultdict if you >> use a "normal" function instead of the lambda: >> >> $ cat pickle_defaultdict.py >> import sys >> from collections import defaultdict >> from cPickle import dumps, loads >> >> if "--lambda" in sys.argv: >> make_inner = lambda: defaultdict(list) >> else: >> def make_inner(): >> return defaultdict(list) >> >> d = defaultdict(make_inner) >> d[1][2].append(42) >> e = loads(dumps(d)) >> print e == d >> >> $ python pickle_defaultdict.py >> True >> $ python pickle_defaultdict.py --lambda >> Traceback (most recent call last): >> File "pickle_defaultdict.py", line 13, in >> e = loads(dumps(d)) >> File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex >> raise TypeError, "can't pickle %s objects" % base.__name__ >> TypeError: can't pickle function objects >> > But can you unpickle the objects you pickle? I believe that functions > are references relative to the modules they come from, and so won't be > found unless the same module can be imported at unpickle time. Could be > wrong, haven't read the source, but I understand that functions work the > same as classes. Indeed, what is stored in the pickle is the module and function name, not the byte code: >>> from cPickle import dumps, loads >>> def f(): print "original" ... >>> s = dumps(f) >>> def f(): print "updated" ... >>> g = loads(s) >>> g() updated That limits pickle as an exchange format to installations that provide compatible versions of the pickled classes and functions. Do you think that would be a problem for the OP? Peter From tjreedy at udel.edu Fri Jan 23 17:26:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 17:26:09 -0500 Subject: seeking to improve Python skills In-Reply-To: References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: mk wrote: > Jean-Paul Calderone wrote: > >> The most significant thing missing from this code is unit tests. >> Developing automated tests for your code will help you learn a lot. > > Thanks for all the remarks, I'll restructure my code. Probably the > biggest mistake was not keeping "moving average" class and others > focused on its respective jobs only. I would consider writing the moving-average 'function' as a generator function. First version takes a sequence and window size as inputs. Second, slightly more difficult, takes an iterator and window size as inputs. An exponentially-weighted average generator would, of course, take an iterator and weight as input. From exarkun at divmod.com Fri Jan 23 17:26:22 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 17:26:22 -0500 Subject: Where to place imports In-Reply-To: Message-ID: <20090123222622.24460.2114347762.divmod.quotient.597@henry.divmod.com> On Fri, 23 Jan 2009 22:49:34 +0100, Christian Heimes wrote: >Jean-Paul Calderone schrieb: >>> BTW, if you ever find you are starting to write multi-threaded >>> applications >>> then you'll really regret it if you reuse code which does imports from >>> inside functions. If two or more threads try to import a module >>> simultaneously then one of them might find it that not everything is >>> defined in the module exists when it tries to use it. >> >> What makes you say this? There is an import lock (beyond the GIL) which >> should prevent a thread from ever seeing a partially initialized module. > >Partially initialized modules aren't the issue here. One can easily >create a dead lock situation with a mix of threads and imports. > >Example: > >* module 'mod_a' is imported [import lock is acquired] >* module 'mod_a' spawns a new thread >* the new thread tries to import another module 'mod_b' > >Python dead locks here and there is no chance to resolve the lock. The >import of 'mod_b' is waiting for the first import. The first import >hasn't finished because it's still executing the body of 'mod_a'. > >In order to avoid the situation you *must* never import a module in a >thread other than the main thread. You should never start a thread in >the body of a submodule, too. A large application should import all its >modules first and then create its threads. > >If you really need to import a module from a sub thread or a method that >might be called from a sub thread then you should use the C function >PyImport_ImportModuleNoBlock() or use sys.modules and imp.lock_held(). > Of course this is all true and good to know (and I did already ;), but it doesn't sound like the case being described in the message I was responding to. Jean-Paul From bugtrack at roumenpetrov.info Fri Jan 23 17:28:49 2009 From: bugtrack at roumenpetrov.info (Roumen Petrov) Date: Sat, 24 Jan 2009 00:28:49 +0200 Subject: About SCons Re: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: <497A44A1.20907@roumenpetrov.info> anatoly techtonik wrote: > On Thu, Jan 22, 2009 at 12:51 AM, Roumen Petrov > wrote: >>> Against 2.3, rejected due to dependence on SCons. >>> Also appears to have been incomplete, needing more work. >> No it was complete but use SCons. Most of changes changes in code you will >> see again in 3871. >> > > I would better use SCons for both unix and windows builds. In case of > windows for both compilers - mingw and microsoft ones. To port curses > extension to windows I need to know what gcc options mean, what are > the rules to write Makefiles and how to repeat these rules as well as > find options in visual studio interface. Not mentioning various > platform-specific defines and warning fixes. Did you select one of existing curses library for windows ? Roumen From rdcollum at gmail.com Fri Jan 23 17:30:05 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 23 Jan 2009 14:30:05 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> Message-ID: <863b32f7-91e1-4e5d-a0ee-85f8d1307f70@k1g2000prb.googlegroups.com> > Why do you think it matters? Intellectual curiosity hence why I asked the question. It doesn't matter if I know why the sky is blue but it's interesting to know regardless. From tjreedy at udel.edu Fri Jan 23 17:30:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 17:30:11 -0500 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: Murali Murali wrote: > Hi, > > I am fairly new to python and i am looking for a python script to > download file(latest build) from the server. But, the build name changes > daily. For Ex: today the build URL will be > "http://mybuilds/myapp_1234.exe" and tomorrow it will be > "http://myserver/mybuilds/myapp_3456.exe". So i need a script which > downloads the latest build without any knowledge of build number. Any server that dishes out files with changing names should be using the ftp protocol that is meant for such things. It includes, I believe, a directory request that lets clients discover filenames. From robin at NOSPAMreportlab.com Fri Jan 23 17:51:44 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Fri, 23 Jan 2009 22:51:44 +0000 Subject: strange error whilst porting to 2.6 Message-ID: <497A4A00.9060303@jessikat.plus.net> python 2.6 indicates this error whilst running a script that works fine under Python 2.5. Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in ignored I suppose this must be related to some kind of isinstance or issubclass check, but how can I locate the problem if no traceback is shown? Googling seems to indicate that __subclasscheck__ is an abstract base class method, but clearly in 2.5 I cannot mess with abc stuff. -- Robin Becker From xahlee at gmail.com Fri Jan 23 18:16:59 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 23 Jan 2009 15:16:59 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: ok, i've been reading these Ocaml tutorials in the past few days: intro to ocaml, from official site http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html ?Objective CAML Tutorial?, most cited tutorial on the web http://www.ocaml-tutorial.org/ None of them are perfect, but much better than haskell ones. The official tutorial is ok, but still confusing. The one at ocaml-tutorial.org is somewhat but mostly because it's a lot more explanatory text. It has much verbiage for imperative programers (i.e. half of the text is about Perl this, C that, Java thus, trying to each you functional lang by comparative study assuming you are one of these these idiots. Half of the time, the comparison doesn't make much sense) The best one, is the one is ?Introduction to Caml? http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. I found it by as one of the top result from google search. This one is to the point, on lang syntax, what they do and mean, to the point short examples, focusing one concept at a time. (as opposed to the typical of: littering of motherfucking abstruse jargons thru- out, littering gospels about properties of starry-eyed fucking advantage of static mother fucking typing, the beauties of functional programing fuck, no concrete examples but full of high-horse abstract terminologies that are factually from asses who doesn't know a flying fuck about symbolic logic, replete with computer engineering fuck typical of compiler geekers like garbage collection, garbage collection, garbage collection!!!, memory address memory address memory address, pointers pointers pointers!!! hips and stacks and hips and stacks and very hip!) though, it is of course not my ideal, because it still now and then mention extraneous stupid computer engineering concepts like ?GARBAGE COLLECTION?, ?stateful?, how something is ?expression-based?, etc. If you are have a computer science background, sure these are no problem. But if you are a say practical programer who never took computer science classes, you'll go Huh? and if you are say the world's top mathematician but never studied programing, you'll go HUH? But again, this tutorial is far far better than vast majority of tutorials out there about functional programing (except mine). The haskell tutorials you can find online are the most mothefucking stupid unreadable fuck. The Haskll community is almost stupid. What they talk all day is about monads, currying, linder myer fuck type. That's what they talk about all day. All day and night. Monad! What's a monad! The importance of monad! How to learn monad! Simple intro to monad! Fucking morons, but MONAD! PS i started a Ocaml learning blog here: http://xah-ocaml.blogspot.com/ Xah ? http://xahlee.org/ ? From delroth at gmail.com Fri Jan 23 18:26:45 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Sat, 24 Jan 2009 00:26:45 +0100 Subject: OCaml, Language syntax, and Proof Systems In-Reply-To: References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <1ba9eaed0901231526v75826e14g7e1c4a664b55e38e@mail.gmail.com> On Sat, Jan 24, 2009 at 12:16 AM, Xah Lee wrote: > The haskell tutorials you can find online are the most mothefucking > stupid unreadable fuck. The Haskll community is almost stupid. What > they talk all day is about monads, currying, linder myer fuck type. > That's what they talk about all day. All day and night. Monad! What's > a monad! The importance of monad! How to learn monad! Simple intro to > monad! Fucking morons, but MONAD! *YOU* are full of monads. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:37:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:37:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <018a4b24$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 20:09:48 +0000, Mark Wooding wrote: > Steven D'Aprano writes: > >> On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >>> Why on earth couldn't I change the code of another member of my team >>> if that code needs changes ? The code is the whole team's ownership. >> >> That's a model that works well when you have a small team of, say, a >> dozen people. It's not a model that works when you have hundreds of >> developers working on the project. The last thing I want in my projects >> is cowboys who ride all over other people's code, changing internals of >> parts they barely know at the drop of a hat, causing who knows what >> side- effects. > > Why are you assuming that Bruno would make his change in such an > irresponsible manner? I did? Where did I make that assumption? What I said was that the model "The code is the whole team's ownership" doesn't work well for large projects. *One* reason it doesn't work for large projects is that you will invariably have cowboys who, given half a chance, will code irresponsibly *if you let them* by encouraging the attitude that, sure, that class written by the database backend team belongs to everyone, never mind that you're in the UI team, go right ahead and use whatever internals you like. There are other reasons -- do I need to elaborate on them? Even in a project as small as Python there is sense of *individual* (rather than collective) code ownership, in the sense of responsibility for specific portions of the code base. Scale up the project by a factor of ten, and the problems caused by collective responsibility are simply intractable. > Such things need discussing, with some > appropriate level of formality, with the people most involved with the > relevant code -- which might be anything between a quick chat with the > bloke across the room or an agenda item on the next team meeting to a > written proposal. Yes, and when you have hundreds of developers working on the project, the chances are quite good that there will be twenty such agenda items every week, and then the project will bog down on arguments about what needs to be private and what doesn't, until the project manager just makes a blanket ruling No Access To Internals Full Stop. And then, you know what, the project still manages to go forward. Instead of spending 15 minutes hacking the existing Foo class to do what they want, and then 15 hours dealing with the cascading bugs when the class changes, people simply spend 7 hours subclassing Foo to get what they want, and it's all good and not the end of the world. > Given your apparent readiness to assume the worst of programmers at > every opportunity (e.g., your above assumption that Bruno would change > code unilaterally and secretly, assumptions elsewhere that programmers > treat any exposed wiring as being published interface), I can only > assume that you really need to get some better cow-orkers. Now you're just being naive. The solution to these sorts of problems isn't "get better programmers" because even the best programmers make mistakes (errors, and errors of judgement). Communication breaks down -- Fred is sure Barney said "Yes" while Barney is equally positive he said "No". Or somebody has a demo to the CEO in two hours and needs to hack something up Right Now and the guy he has to chat to is home sick with the phone turned off, and by the time he comes back to work the little hack is forgotten. Or whatever. There's a *bazillion* number of things that can go wrong in big projects, and "getting better programmers" only reduces that to something like a hundred million. It's a credit to *everybody*, including the cowboys and the cow-orkers, that any project of any significant size makes any progress at all. Besides, "better programmers" are in short supply. Sometimes you have to use who you've got, because Guido and the timbot are working somewhere else and you can't afford them. That's why we have languages like Python: so that *ordinary* programmers can be as productive as genius programmers in languages like C. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:39:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:39:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <018a4b9c$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: > It should be in _our_ power as the team of all participant coders on > _our_ project to decide if we should mess with the internals or not. > > What makes no sense is that it should be in the original author's power > to decide, if he is not part of _our_ team. Makes *no* sense? There's *no* good reason *at all* for the original author to hide or protect internals? Let's be specific here. The list implementation in CPython is an array with a hidden field storing the current length. If this hidden field was exposed to Python code, you could set it to a value much larger than the actual size of the array and cause buffer overflows, and random Python code could cause core dumps (and possibly even security exploits). So what you're saying is that the fundamental design of Python -- to be a high-level language that manages memory for you while avoiding common programming errors such as buffer overflows -- makes "no sense". Is that what you intended? As I see it, you have two coherent positions. On the one hand, you could be like Mark Wooding, and say that Yes you want to risk buffer overflows by messing with the internals -- in which case I'm not sure what you see in Python, which protects so many internals from you. Or you can say that you made a mistake, that there are *some* good reasons to protect/hide internals from external access. In the second case, the next question is, why should it only be code written in C that is allowed that protection? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:42:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:42:33 GMT Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: <018a4c38$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 09:35:52 -0600, skip wrote: > Steven> I'm interested in this ticket in the bug tracker: > > Steven> http://bugs.python.org/issue2527 > > Steven> but it seems to have been stalled for nine months. Is there > a Steven> procedure for starting it up again? > > Assign it to yourself? Add a comment with relevant updates? > > Steven> Should I ask about it on the python-dev mailing list, or > just Steven> wait until somebody happens to notice it? > > But you've already noticed it. ;-) (Note to self: stop posting ambiguous messages when tired.) I meant bringing it to the attention of somebody who can actually commit the patch to production, or rule that the patch isn't suitable. I can't do that. Sorry for the naive questions, I'm new to the bug tracker and I'm not entirely sure about the protocol. Should I just drop a note to python-dev and ask somebody with commit privileges to look at it, or is that rude? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:46:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:46:04 GMT Subject: Where to place imports References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <018a4d0b$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 17:48:19 +0100, Diez B. Roggisch wrote: > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. Or if you want to make it clear that only a single function uses the imported module, or if you wish to avoid a potentially expensive import until the last possible moment when you actually need it, or if you're finicky about namespace pollution, or if you just like to put your imports inside functions because you're weird and never use threads. All of these are valid reasons. Whether they will give you the love and respect of your fellow Python programmers is another question. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:49:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:49:11 GMT Subject: is None vs. == None References: Message-ID: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > Hi -- Some time ago I ran across a comment recommending using is > None instead of == None (also is not None, etc.) That entirely depends on whether you wish to test for something which *is* None or something with *equals* None. Those two things have different meanings. I wonder, do newbies actually get the impression from somewhere that "is" is a synonym for "=="? > My own > testing indicates that the former beats the latter by about 30% on > average. Not a log for a single instruction but it can add up in large > projects. If you have a "large" project where the time taken to do comparisons to None is a significant portion of the total time, I'd be very surprised. var is None is a micro-optimization, but that's not why we do it. We do it because usually the correct test is whether var *is* None and not merely equal to None. Any random object might happen to equal None (admittedly most objects don't), but only None is None. -- Steven From gdamjan at gmail.com Fri Jan 23 19:02:01 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sat, 24 Jan 2009 01:02:01 +0100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: >> I don't know what an IBQ is. > > +IBQ- seems to be the way your newsreader displays the dashes that > where in Ben's posting. I see "em dash" characters there: I see IBQ too ... also weird is that he has Content-Type: text/plain; charset=utf-7 -- ?????? ( http://softver.org.mk/damjan/ ) Give me the knowledge to change the code I do not accept, the wisdom not to accept the code I cannot change, and the freedom to choose my preference. From digitig at gmail.com Fri Jan 23 19:04:09 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 24 Jan 2009 00:04:09 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <497a2cce$0$183$e4fe514c@news.xs4all.nl> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> <497a2cce$0$183$e4fe514c@news.xs4all.nl> Message-ID: 2009/1/23 Martin P. Hellwig : > Or you can argue that even when an argument is repeated indefinitely it > doesn't make it suddenly right. No, but it makes for a confirmation of Schluehr's law :-) -- Tim Rowe From benjamin.kaplan at case.edu Fri Jan 23 19:24:38 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 19:24:38 -0500 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: On Fri, Jan 23, 2009 at 6:49 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > Hi -- Some time ago I ran across a comment recommending using is > > None instead of == None (also is not None, etc.) > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > I think it's more that teachers tell students without programming experience "always use == to test if something equals something else unless you're checking for None," without explaining what == and is actually mean. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Fri Jan 23 19:28:15 2009 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 23 Jan 2009 16:28:15 -0800 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <497A609F.4030700@islandtraining.com> Steven D'Aprano wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) >> > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > Actually, for None, those two things *are* the same. If something *equals* None, it also *is* None. This is a consequence of the fact that there is only ever one value of None anywhere in the system. > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > Yes. Such questions pop up regularly, and are usually dealt with quickly. > > > >> My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in large >> projects. >> > > If you have a "large" project where the time taken to do comparisons to > None is a significant portion of the total time, I'd be very surprised. > > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. > > You don't have that quite right. The only way something can *equal* None is if it *is* None. None is not a value an object can have, but rather it is a (singleton) object that can be referenced. Setting something *equal* to None is accomplished by making it refer to the single None object, at which point it *is* None. Gary Herron > > From mdw at distorted.org.uk Fri Jan 23 19:29:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 00:29:08 +0000 Subject: Dynamic methods and lambda functions References: Message-ID: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> unineuro at gmail.com writes: > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) [...] > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? Ahh! Binding-versus-assignment confusion! Things to realise: * There are two mappings of interest when dealing with variables. The `binding' of a name maps the name to a variable. The variable stores a (reference to a) value. * Assignment stores a new (reference to a) value in the variable. * Binding modifies the mapping between names and variables. * Nested functions, as constructed by `lambda' or `def', inherit (we say `close over') the bindings visible in their surroundings. * Python's `for' loop works by assignment. So, what happens is this. In `__init__', there's a binding of the name `prop' to a variable. The `for' loop modifies this variable on each iteration, making it refer to successive elements of the `props' list. The `lambda's you create inherit the binding of `prop' from the surrounding `__init__', so the `lambda' sees the same variable as is being modified by the loop. Result: when you actually come to invoke one of the `lambda's -- after `__init__' finishes -- you find that its notion of `prop' is whatever the `for' left it as. To fix the problem, you need to make a separate variable for each iteration through the loop, and have the `lambda' close over that. Function parameters are the easy approach to making fresh variables with given contents: so we just call a function which accepts, and stores in a parameter, the value we want the `lambda' to see, and closes over the parameter. class Person (object): # use new-style classes def __init__(self): # allow parametrization def getter(propname): # close over new variable return lambda self: getattr(self, propname) for name, value in props: # destructuring wins setattr(self, '__' + name, value) for name, value in props: # only need to do this once setattr(Person, 'Get' + name, getter('__' + name)) Does that make sense? -- [mdw] From benjamin.kaplan at case.edu Fri Jan 23 19:31:59 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 19:31:59 -0500 Subject: is None vs. == None In-Reply-To: <497A609F.4030700@islandtraining.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <497A609F.4030700@islandtraining.com> Message-ID: On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a comment recommending using is > >> None instead of == None (also is not None, etc.) > >> > > > > That entirely depends on whether you wish to test for something which > > *is* None or something with *equals* None. Those two things have > > different meanings. > > > > Actually, for None, those two things *are* the same. If something > *equals* None, it also *is* None. This is a consequence of the fact > that there is only ever one value of None anywhere in the system. Not if someone decided to be a PITA. >>> class A(object) : ... def __eq__(self, other) : ... return other is None ... >>> a = A() >>> a == None True >>> a is None False > > > I wonder, do newbies actually get the impression from somewhere that "is" > > is a synonym for "=="? > > > > Yes. Such questions pop up regularly, and are usually dealt with quickly. > > > > > > > > >> My own > >> testing indicates that the former beats the latter by about 30% on > >> average. Not a log for a single instruction but it can add up in large > >> projects. > >> > > > > If you have a "large" project where the time taken to do comparisons to > > None is a significant portion of the total time, I'd be very surprised. > > > > var is None is a micro-optimization, but that's not why we do it. We do > > it because usually the correct test is whether var *is* None and not > > merely equal to None. Any random object might happen to equal None > > (admittedly most objects don't), but only None is None. > > > > > You don't have that quite right. The only way something can *equal* > None is if it *is* None. > None is not a value an object can have, but rather it is a (singleton) > object that can be referenced. Setting something *equal* to None is > accomplished by making it refer to the single None object, at which > point it *is* None. > > Gary Herron > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From caseyhHAMMER_TIME at istar.ca Fri Jan 23 19:33:12 2009 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Fri, 23 Jan 2009 16:33:12 -0800 Subject: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? Message-ID: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? I suppose I'm thinking of an extra layer of indirection, which might slow things down to much. :) -- Regards, Casey From jon at ffconsultancy.com Fri Jan 23 19:36:58 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 24 Jan 2009 00:36:58 +0000 Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: Xah Lee wrote: > ok, i've been reading these Ocaml tutorials in the past few days: > > intro to ocaml, from official site > http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html > > ?Objective CAML Tutorial?, most cited tutorial on the web > http://www.ocaml-tutorial.org/ > > The best one, is the one is > ?Introduction to Caml? > http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html > by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. > I found it by as one of the top result from google search. You may also appreciate the freely-available first chapter of my book OCaml for Scientists: http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html And the freely-available first chapter of The OCaml Journal: http://www.ffconsultancy.com/products/ocaml_journal/free/introduction.html I also recommend Jason Hickey's book which, I believe, is due to be published by Cambridge University Press soon: http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From rt8396 at gmail.com Fri Jan 23 19:38:38 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:38:38 -0800 (PST) Subject: Find all available Tkinter cursor names? References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> <4979DFB4.4030705@codebykevin.com> Message-ID: On Jan 23, 9:18?am, Kevin Walzer wrote: > http://wiki.tcl.tk/8674might offer some help in this regard. > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Many Thanks Kevin, this may help! From rt8396 at gmail.com Fri Jan 23 19:43:49 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:43:49 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: <1a94f9f1-f895-42ba-aefa-b2d6e370fba8@k1g2000prb.googlegroups.com> On Jan 16, 1:55?am, Terry Reedy wrote: > > Maybe I'm misunderstanding something here, but "About Idle" in Python > > 2.6.1 (win32) says "Tk version: 8.5" As to Tk, i was referring to Themes. I may have the versions mixed up but the newest TK supports themes and i would love to get that support into Tkinter, This will help shine up python a bit. From tjreedy at udel.edu Fri Jan 23 19:44:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 19:44:40 -0500 Subject: Stalled ticket in Python bug tracker In-Reply-To: <018a4c38$0$20629$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> <018a4c38$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 09:35:52 -0600, skip wrote: > >> Steven> I'm interested in this ticket in the bug tracker: >> >> Steven> http://bugs.python.org/issue2527 >> >> Steven> but it seems to have been stalled for nine months. Is there >> a Steven> procedure for starting it up again? >> >> Assign it to yourself? Add a comment with relevant updates? You seem to have missed or not understood this answer. See below. >> >> Steven> Should I ask about it on the python-dev mailing list, or >> just Steven> wait until somebody happens to notice it? >> >> But you've already noticed it. ;-) > > > (Note to self: stop posting ambiguous messages when tired.) > > > I meant bringing it to the attention of somebody who can actually commit > the patch to production, or rule that the patch isn't suitable. I can't > do that. However, you can do something to move it forward. 1. There were some suggested changes to the patch but no revised version uploaded. What do *you* think of them? 2. The patch is small enough that you could apply it by hand, with or without any further changes, to a copy of timeit.py on your system. 3. The patch is against python2.5. Test it with 2.6 and 3.0 with the current test file in Lib/test. 4. The patch lacks any test of the new feature. Write one that could be added to the current test file. 5. The patch lack documentation of the new feature. Write a entry that could be added to the current timeit module doc. 6. Ask the OP to incorporate the test and doc in the appropriate file and generate and post a new diff patch. The patch as is is unacceptable without the test and doc. > Sorry for the naive questions, I'm new to the bug tracker and I'm not > entirely sure about the protocol. Should I just drop a note to python-dev > and ask somebody with commit privileges to look at it, or is that rude? Slightly rude, perhaps, but more importantly, without volunteer work on your part, probably useless. Everyone else is a volunteer also. tjr From robert.kern at gmail.com Fri Jan 23 19:49:31 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jan 2009 18:49:31 -0600 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. Additionally, some objects that use rich comparisons to return other objects and not booleans will simply fail when compared with None. The situations where you are testing for None are frequently situations where you don't really know the kind of object you might be getting, either. -- 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 rt8396 at gmail.com Fri Jan 23 19:56:12 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:56:12 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: Yes promoting freedom, claiming that freedom is a good thing, and not being afraid to open my mouth about it, fight for it, free others from their bonds, makes me free. No presumption was made about the OP, the only "meaning" in my message was to free the OP from his self imposed bonds while using Python. You made this political. Seems like you have a predisposition of hate towards me, maybe it is unconscience and you do not realize it, but i highly doubt it. Come down from your tower of righteousness Deiz, loosen up that stiff- upper-lip and bring your brown-nosing minions with you! From mdw at distorted.org.uk Fri Jan 23 20:01:07 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 01:01:07 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> Message-ID: <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > I did? Where did I make that assumption? I inferred it from the juxtaposition, apparently in error. Sorry. > What I said was that the model "The code is the whole team's ownership" > doesn't work well for large projects. *One* reason it doesn't work for > large projects is that you will invariably have cowboys who, given half a > chance, will code irresponsibly *if you let them* by encouraging the > attitude that, sure, that class written by the database backend team > belongs to everyone, never mind that you're in the UI team, go right > ahead and use whatever internals you like. `Cowboys' will code irresponsibly anyway; they need reeducating gently with a stick. >> Such things need discussing, with some >> appropriate level of formality, with the people most involved with the >> relevant code -- which might be anything between a quick chat with the >> bloke across the room or an agenda item on the next team meeting to a >> written proposal. > > Yes, and when you have hundreds of developers working on the project, > the chances are quite good that there will be twenty such agenda items > every week, and then the project will bog down on arguments about what > needs to be private and what doesn't, until the project manager just > makes a blanket ruling No Access To Internals Full Stop. Err... you've wandered off the track here. The purpose of the proposed changes is to expose the right interfaces so that people don't need to fiddle with internals. If I've discovered that I need to dredge something out of the middle of your module, I have three choices: (a) somehow get your module changed so that it hands me the information I want through a documented interface, (b) suck your module's brains out through a straw whether the interface lets me or not, or (c) lose. The agenda items are supporting (a), which I thought you were in favour of; you certainly seem to be against (b), and (c) doesn't look appealing. > And then, you know what, the project still manages to go > forward. Instead of spending 15 minutes hacking the existing Foo class > to do what they want, and then 15 hours dealing with the cascading > bugs when the class changes, people simply spend 7 hours subclassing > Foo to get what they want, and it's all good and not the end of the > world. Subclassing hardly fixes these sorts of problems well. Hardly any class libraries are documented sufficiently well enough to support subclassing properly. Have a look at the CLOS MOP specification http://www.lisp.org/mop/index.html for a rare example of how to do it right. > Besides, "better programmers" are in short supply. Sometimes you have > to use who you've got, because Guido and the timbot are working > somewhere else and you can't afford them. That's why we have languages > like Python: so that *ordinary* programmers can be as productive as > genius programmers in languages like C. Why waste genius programmers on churning out C? Just imagine how much they could do with something like Python! -- [mdw] From rt8396 at gmail.com Fri Jan 23 20:02:59 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 17:02:59 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> Message-ID: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Whatever scumbag would rate a new python's users with one start for asking us for help is a complete low-life. Keep acting like that and Python will fade away into the darkness forever. dhaval, Don't let the few bullies here scare you away, try out the this link, the other one i gave you was incorrect http://www.python-forum.org/pythonforum/index.php From linuxguy123 at gmail.com Fri Jan 23 20:06:49 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 23 Jan 2009 18:06:49 -0700 Subject: How do I get my python program to get the root password ? Message-ID: <1232759209.3727.2.camel@localhost.localdomain> I want to make a python program that I can run as a normal user that changes the permission on some device files. It will need to ask me for the root password and then run chown as root in order to do this. How do I accomplish this (easily) ? Thanks From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 20:16:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 01:16:51 GMT Subject: is None vs. == None References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018a6252$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 16:28:15 -0800, Gary Herron wrote: > If something > *equals* None, it also *is* None. This is a consequence of the fact > that there is only ever one value of None anywhere in the system. ... > The only way something can *equal* None is if it *is* None. >>> class Empty: ... def __eq__(self, other): ... return not bool(other) ... >>> e = Empty() >>> e == None True >>> e is None False -- Steven From castironpi at gmail.com Fri Jan 23 20:21:56 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 23 Jan 2009 17:21:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <289bc9ab-add6-4e75-af81-f0d265135dc7@a12g2000pro.googlegroups.com> On Jan 23, 7:01?pm, Mark Wooding wrote: > Steven D'Aprano writes: > > I did? Where did I make that assumption? > > I inferred it from the juxtaposition, apparently in error. ?Sorry. > > > What I said was that the model "The code is the whole team's ownership" > > doesn't work well for large projects. *One* reason it doesn't work for > > large projects is that you will invariably have cowboys who, given half a > > chance, will code irresponsibly *if you let them* by encouraging the > > attitude that, sure, that class written by the database backend team > > belongs to everyone, never mind that you're in the UI team, go right > > ahead and use whatever internals you like. > > `Cowboys' will code irresponsibly anyway; they need reeducating gently > with a stick. A lot of this is a question of how tight you want the handcuffs. Stricter backgrounds and bigger projects make you want tighter ones. You can't jump right from tight handcuffs to loose ones. You'll tend to like them looser over time. A language looser than Python in unheard of. Google says: 'No results found for "looser than Python".' From steve at holdenweb.com Fri Jan 23 20:28:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:28:11 -0500 Subject: writing pickle function In-Reply-To: References: Message-ID: Peter Otten wrote: > Steve Holden wrote: > >> Peter Otten wrote: >>> perfreem at gmail.com wrote: >>> >>>> i am using nested defaultdict from collections and i would like to >>>> write it as a pickle object to a file. when i try: >>>> >>>> from collections import defaultdict >>>> x = defaultdict(lambda: defaultdict(list)) >>>> >>>> and then try to write to a pickle file, it says: >>>> >>>> TypeError: can't pickle function objects >>>> >>>> is there a way around this? it's simply a dictionary that i want to >>>> write to file.. this works no problems with ordinary dicts. >>> The error message is misleading. You can pickle your defaultdict if you >>> use a "normal" function instead of the lambda: >>> >>> $ cat pickle_defaultdict.py >>> import sys >>> from collections import defaultdict >>> from cPickle import dumps, loads >>> >>> if "--lambda" in sys.argv: >>> make_inner = lambda: defaultdict(list) >>> else: >>> def make_inner(): >>> return defaultdict(list) >>> >>> d = defaultdict(make_inner) >>> d[1][2].append(42) >>> e = loads(dumps(d)) >>> print e == d >>> >>> $ python pickle_defaultdict.py >>> True >>> $ python pickle_defaultdict.py --lambda >>> Traceback (most recent call last): >>> File "pickle_defaultdict.py", line 13, in >>> e = loads(dumps(d)) >>> File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex >>> raise TypeError, "can't pickle %s objects" % base.__name__ >>> TypeError: can't pickle function objects >>> >> But can you unpickle the objects you pickle? I believe that functions >> are references relative to the modules they come from, and so won't be >> found unless the same module can be imported at unpickle time. Could be >> wrong, haven't read the source, but I understand that functions work the >> same as classes. > > Indeed, what is stored in the pickle is the module and function name, not > the byte code: > >>>> from cPickle import dumps, loads >>>> def f(): print "original" > ... >>>> s = dumps(f) >>>> def f(): print "updated" > ... >>>> g = loads(s) >>>> g() > updated > > That limits pickle as an exchange format to installations that provide > compatible versions of the pickled classes and functions. > > Do you think that would be a problem for the OP? > Nice demonstration! Possibly not, though the original use of lambdas demonstrated at least confusion. But there needs to be an understanding that the pickled function has to be importable. Just using a function in __main__ and then trying to unpickle from another program that doesn't contain the function won;t hack it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 20:31:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:31:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steven D'Aprano writes: > >> I did? Where did I make that assumption? > > I inferred it from the juxtaposition, apparently in error. Sorry. > >> What I said was that the model "The code is the whole team's ownership" >> doesn't work well for large projects. *One* reason it doesn't work for >> large projects is that you will invariably have cowboys who, given half a >> chance, will code irresponsibly *if you let them* by encouraging the >> attitude that, sure, that class written by the database backend team >> belongs to everyone, never mind that you're in the UI team, go right >> ahead and use whatever internals you like. > > `Cowboys' will code irresponsibly anyway; they need reeducating gently > with a stick. > Unfortunately on large projects it's impossible to avoid cowboys, and some of them are completely lost to reason. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Fri Jan 23 20:32:17 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 23 Jan 2009 19:32:17 -0600 Subject: How do I get my python program to get the root password ? References: Message-ID: On 2009-01-24, Linuxguy123 wrote: > I want to make a python program that I can run as a normal > user that changes the permission on some device files. It > will need to ask me for the root password and then run chown > as root in order to do this. > > How do I accomplish this (easily) ? The short answer is: you don't accomplish that easily. The long answer is: you can accomplishity difficultly by using a pty or the pexect module to execute the su or sudo command. -- Grant From steve at holdenweb.com Fri Jan 23 20:33:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:33:45 -0500 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > No they don't, because the language *guarantees* the None object is a singleton, so anything that *equals* None *is* None. > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > Who knows. But if they do they can easily be reeducated. > > >> My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in large >> projects. > > If you have a "large" project where the time taken to do comparisons to > None is a significant portion of the total time, I'd be very surprised. > > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. > Of course there can be pathological objects with bizarre comparison methods. And the "is" test helps avoid them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin.kaplan at case.edu Fri Jan 23 20:39:55 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 20:39:55 -0500 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED In-Reply-To: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 8:02 PM, r wrote: > Whatever scumbag would rate a new python's users with one start for > asking us for help is a complete low-life. Keep acting like that and > Python will fade away into the darkness forever. Could you please explain where these stars you keep talking about come from? It's not from Usenet (AFAIKT), the mailing list, or Google Groups. Stop worrying about something that 99% of the people here can't see. > > > dhaval, > Don't let the few bullies here scare you away, try out the this link, > the other one i gave you was incorrect > > http://www.python-forum.org/pythonforum/index.php > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Fri Jan 23 20:41:35 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 01:41:35 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <877i4lbhv4.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > Let's be specific here. The list implementation in CPython is an array > with a hidden field storing the current length. If this hidden field was > exposed to Python code, you could set it to a value much larger than the > actual size of the array and cause buffer overflows, and random Python > code could cause core dumps (and possibly even security exploits). [...] > As I see it, you have two coherent positions. On the one hand, you could > be like Mark Wooding, and say that Yes you want to risk buffer overflows > by messing with the internals Please, point out where I said that! I'm pretty sure that the only time I commented on this particular point (in message <87y6x2cih0.fsf.mdw at metalzone.distorted.org.uk>), I said: : Umm... I'm pretty sure that that's available via the `len' function, : which is tied to list.__len__ (via the magic C-implemented-type mangler, : in C). Though it's read-only -- and this is a shame, 'cos it'd be nice : to be able to adjust the length of a list in ways which are more : convenient than : : * deleting or assigning to a trailing slice, or : * augmenting or assigning to a trailing zero-width slice : : (Perl has supported assigning to $#ARRAY for a long time. Maybe that's : a good argument against it.) While I realise I didn't spell it out, the semantics I had in mind where foo.len = n means if n < 0: raise ValueError, 'don\'t be stupid' elif len(foo) < n: foo += [None] * (n - len(foo)) else: foo[n:] = [] (I'm not fussy what the new array slots get filled with, but it seems sensible to be clear. Perl's semantics are more complicated: if you decrease $#foo and then increase it again you get the old values back. Common Lisp users will recall the idea of a fill-pointer.) If there's anything unsafe about that, I'll be surprised. > -- in which case I'm not sure what you see in Python, which protects > so many internals from you. Or you can say that you made a mistake, > that there are *some* good reasons to protect/hide internals from > external access. Safety is good. Escape hatches are good, too. > In the second case, the next question is, why should it only be code > written in C that is allowed that protection? Because Python code can't cause those sorts of problems without resorting to the escape hatches (e.g., ctypes). And, very significantly, because C code /needs/ that protection and Python basically doesn't. The basic difference is that C code is fundamentally brittle: if you mess up its invariants, it can crash horribly and possibly allow its brain to be taken over by evil people. Python code is fundamentally robust. The worst that can happen[1] is that the interpreter raises an exception. This makes it ideally suited to having a more relaxed attitude to life. And that, in turn, makes it approachable, hackable interactively, fun! [1] Assuming that (a) the Python implementation and C extensions are correct, and (b) that the code in question isn't using the escape hatches. -- [mdw] From benjamin at python.org Fri Jan 23 20:44:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 01:44:21 +0000 (UTC) Subject: strange error whilst porting to 2.6 References: <497A4A00.9060303@jessikat.plus.net> Message-ID: Robin Becker NOSPAMreportlab.com> writes: > > python 2.6 indicates this error whilst running a script that works fine > under Python 2.5. > > Exception RuntimeError: 'maximum recursion depth exceeded in > __subclasscheck__' in ignored > > I suppose this must be related to some kind of isinstance or issubclass > check, but how can I locate the problem if no traceback is shown? You're code is causing a RuntimeError to be raised some where in a type checking call. Unfortunately because of old APIs in CPython that are not "allowed" to fail, CPython cannot continue to raise the exception, so it just prints that ugly error message and clanks happily along. The best way to avoid this is just throw away sys.stderr in code that is acting up like this. From bedouglas at earthlink.net Fri Jan 23 20:45:44 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 23 Jan 2009 17:45:44 -0800 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED In-Reply-To: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Message-ID: <167801c97dc5$7a92a530$0301a8c0@tmesa.com> hey.... didn't get the initial post/ just what is the original poster looking for?? -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of r Sent: Friday, January 23, 2009 5:03 PM To: python-list at python.org Subject: Re: PYTHON HTTP POST WORKING EXAMPLE NEEDED Whatever scumbag would rate a new python's users with one start for asking us for help is a complete low-life. Keep acting like that and Python will fade away into the darkness forever. dhaval, Don't let the few bullies here scare you away, try out the this link, the other one i gave you was incorrect http://www.python-forum.org/pythonforum/index.php -- http://mail.python.org/mailman/listinfo/python-list From fakeaddress at nowhere.org Fri Jan 23 20:48:44 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 17:48:44 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Carl Banks wrote: [...] > BTW, class instances are usually immutable and thus don't require a > mutex in the system I described. Then you are describing a language radically different from Python. -- --Bryan From BrianVanderburg2 at aim.com Fri Jan 23 20:55:05 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 20:55:05 -0500 Subject: How do I get my python program to get the root password ? In-Reply-To: References: Message-ID: <497A74F9.8030304@aim.com> grante at visi.com wrote: > On 2009-01-24, Linuxguy123 wrote: > > >> I want to make a python program that I can run as a normal >> user that changes the permission on some device files. It >> will need to ask me for the root password and then run chown >> as root in order to do this. >> >> How do I accomplish this (easily) ? >> > > The short answer is: you don't accomplish that easily. > > The long answer is: you can accomplishity difficultly by using > a pty or the pexect module to execute the su or sudo command. > > Check out libsudo. It is a simple library that simply calls sudo program except it is does all the work of reading/writing the pipes for you. You could then use ctypes to interface to it. Sudo doesn't use the root password but the password of the user executing the command, but there may be a way to make it use the password of the user the command is executed as instead in /etc/sudoers. I don't really know, I just have mine set up for my main user account to be able to execute any command. Brian Vanderburg II From rhodri at wildebst.demon.co.uk Fri Jan 23 20:58:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 24 Jan 2009 01:58:55 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3af91zm1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: On Fri, 23 Jan 2009 21:28:22 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Mark Wooding writes: >> Now we come on to Fred. If Fred's across the room from me then we're >> back to the water-cooler. If he's on a different continent, and I know >> he'll be affected, I'll probably email him. If I've never heard of him >> at all, well, he might just lose when someone puts my code and Fred's >> together with OrderedDict... > > In a large project, more probably you'd enter a change request into > some kind of tracking system, there would be discussion in the > tracking system about how to do the change; perhaps at your weekly > staff meeting you might bring up the issue with your PHB if you were > blocking on the issue, and your PHB would bring it up at the inter-PHB > meeting with Fred's PHB to bump the item's priority, and eventually > Fred would check in a change and you would use it. There is > necessarily some wasted motion in any organization of that size; good > management is about keeping the friction to a minimum and getting the > stuff done. My experience with medium-sized organisations (50-100 people) is that either you talk to Fred directly, or it doesn't happen. In particular the more people (especially PHBs) that get involved, the slower the change will come and the less like your original requirement it will look. Each person, no matter how technically adept, has a significant chance of misunderstanding what it is you need and/or expressing it poorly to the next person in line. If I need something that goes 'ping' by Friday, and get something that goes 'pong' three weeks later (together with a note from Fred telling me that three-and-fourpence isn't going to get me into any of the good dance clubs), I'd have been better off taking a hacksaw to the internals myself and presenting my fix for Fred's consideration. Python allows me to do this without the fuss and drama that strict encapsulation seems to posit is necessary, instead of delaying an entire release cycle because the process doesn't trust me. -- Rhodri James *-* Wildebeeste Herder to the Masses From robin at NOSPAMreportlab.com Fri Jan 23 21:00:23 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 24 Jan 2009 02:00:23 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> Message-ID: <497A7637.2030405@jessikat.plus.net> Benjamin Peterson wrote: > Robin Becker NOSPAMreportlab.com> writes: > >> python 2.6 indicates this error whilst running a script that works fine >> under Python 2.5. >> >> Exception RuntimeError: 'maximum recursion depth exceeded in >> __subclasscheck__' in ignored >> >> I suppose this must be related to some kind of isinstance or issubclass >> check, but how can I locate the problem if no traceback is shown? > > You're code is causing a RuntimeError to be raised some where in a type checking > call. Unfortunately because of old APIs in CPython that are not "allowed" to > fail, CPython cannot continue to raise the exception, so it just prints that > ugly error message and clanks happily along. The best way to avoid this is just > throw away sys.stderr in code that is acting up like this. > > Well that's not really acceptable as a solution is it? :) -- Robin Becker From kyrie at uh.cu Fri Jan 23 21:36:59 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 23 Jan 2009 21:36:59 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <018a4b9c$0$20629$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232764619.497a7ecb47c4f@mail.uh.cu> Quoting Steven D'Aprano : > On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: > > > It should be in _our_ power as the team of all participant coders on > > _our_ project to decide if we should mess with the internals or not. > > > > What makes no sense is that it should be in the original author's power > > to decide, if he is not part of _our_ team. > > Makes *no* sense? There's *no* good reason *at all* for the original > author to hide or protect internals? My bad, sorry. It makes sense... if the original author is an egotist who believes he must control how I use that library. Or, if external forces make him do it (maybe like, 'oh, if I change python, then I'm not using python anymore'). > Let's be specific here. The list implementation in CPython is an array > with a hidden field storing the current length. If this hidden field was > exposed to Python code, you could set it to a value much larger than the > actual size of the array and cause buffer overflows, and random Python > code could cause core dumps (and possibly even security exploits). In which case, my code would be broken. (Wait, let me be clear: in which case, our team's code may be broken - but it was _our_ team's decision, knowing the risk). If a variable is marked as... I don't like 'private', I'll call it 'implementation detail', I would not use it without good reason. Not even by subclassing it. Why do you assume that I'd change list._length if I could? I wouldn't. Anyway, did you notice that your "counter-example" was a radical change-the-way-python-works scenario? I also don't want to change the interpreter's code on the fly. Now, if you take that as a confession that I really, really, want enforced data hiding and that everything I've said is plain wrong, so be it. After all, I treat python's interpreter as a black box, don't I? > So what you're saying is that the fundamental design of Python -- to be a > high-level language that manages memory for you while avoiding common > programming errors such as buffer overflows -- makes "no sense". Is that > what you intended? Yes, that's what I intended, obviously. I'd like to have buffer overflows in python. In case you don't understand irony: don't go putting words in my mouth. I'm not putting words in yours. > As I see it, you have two coherent positions. On the one hand, you could > be like Mark Wooding, and say that Yes you want to risk buffer overflows > by messing with the internals -- in which case I'm not sure what you see > in Python, which protects so many internals from you. Or you can say that > you made a mistake, that there are *some* good reasons to protect/hide > internals from external access. Or, I could have a third option: assume that I am a grownup who knows what he is doing. After all, even with all those "protections" in list, I could just create an extension module to shoot me in the foot anyway, if I really wanted to. > In the second case, the next question is, why should it only be code > written in C that is allowed that protection? Bug? Not worth the effort of exposing those variables? I don't know... [Btw, do you realize that C++'s private also don't provide that protection? I have almost no experience with C++ and found it trivial to circumvent] I don't think this is going anywhere. Now you are trying to push me to the extremes, changing what I _said_ for your exaggerated interpretation of it just so you could shoot it down, or force me to say that I want buffer overflows in python. I believe that's called "strawman". I stand by my words - but not by your "interpretation" of them: > > What makes no sense is that it should be in the original author's power > > to decide, if he is not part of _our_ team. Do you _really_ read from that sentence that I should dislike python because it makes it a bit harder to get a buffer overflow with their native types? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From benjamin at python.org Fri Jan 23 21:39:51 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 02:39:51 +0000 (UTC) Subject: strange error whilst porting to 2.6 References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: Robin Becker NOSPAMreportlab.com> writes: > > > Well that's not really acceptable as a solution is it? :) This doesn't happen in Python 3.0, so you could port to that. :) In 2.7, the better recursion depth handling in Py3k may be backported,but the best you can do for now is not touch the recursion limit or just shut the error up. From pavlovevidence at gmail.com Fri Jan 23 21:54:18 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 18:54:18 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Message-ID: <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> On Jan 23, 5:48?pm, Bryan Olson wrote: > Carl Banks wrote: > > [...] > > > BTW, class instances are usually immutable and thus don't require a > > mutex in the system I described. > > Then you are describing a language radically different from Python. Bzzt. Hint: aside from the reference count, most class instances are immutable in Python *today*. Carl Banks From linuxguy123 at gmail.com Fri Jan 23 21:58:09 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 23 Jan 2009 19:58:09 -0700 Subject: I'm a python addict ! Message-ID: <1232765889.7151.7.camel@localhost.localdomain> I just started using python last week and I'm addicted. I hate Perl. I never did learn to use it with any competence. I has to be the most obfuscated, cryptic language I've ever seen. Making it "object oriented" only makes it worse ! While I am at it, I dislike bash shell programming too. Man, I love Python ! Its so clean and easy to use. Its so complete. It links into everything one way or another... Java, C, C++, Qt, KDE, SWT, Swing and probably more things that I don't know about. Python makes sense. Python is readable. I will never write another Perl or Bash script again. I will never use another low level language to do simple things again. I love how Python has object member lists in PyDev in Eclipe. It makes it easy to use and explore the language and objects. I wrote a simple command line serial emulator in about 10 minutes using the PySerial library. Unbelievable. I see a lot of Python in my future. From maxerickson at gmail.com Fri Jan 23 22:16:19 2009 From: maxerickson at gmail.com (Max Erickson) Date: Sat, 24 Jan 2009 03:16:19 +0000 (UTC) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Years ago I have found this nice small program, TextCalc: > http://www.atomixbuttons.com/textcalc/ > > Despite being very limited and being not integrated with > everything else, it's so handy that for me in certain situations > it's the right tool to use when I have to process numbers and > data in simple ways. It helps me keep all the intermediate > solutions, you can save the working page just as the text file > you are seeing, it's "passive", it doesn't go bang, so if you > want you can use it just a primitive text editor. It does > something only when you ask it to. And for a basic usage there > is nearly nothing to remember. > This is mostly an aside to your question, but depending on what you aredoing, Speq Mathematics may be an improvement over TextCalc. The homepage is at http://www.speqmath.com/index.php?id=1. The big differences are that it adds a good deal of functionality (variables, a larger variety of functions, plotting, etc.) and that it treats plain text as an error (unless the text is marked as a comment). max From http Fri Jan 23 22:18:05 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:18:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: <7xab9hie8i.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > My experience with medium-sized organisations (50-100 people) is that > either you talk to Fred directly, or it doesn't happen. In particular > the more people (especially PHBs) that get involved, the slower the > change will come and the less like your original requirement it will look. Usually there would be enough communication with Fred that Fred is be aware of the problem and the amount of work needed to fix it (maybe you've even submitted a patch that Fred can commit after review and testing), but Fred has ten thousand other things that also need getting done. The job of the PHB's is to stay on top of what issues are important for the overall project and juggle the priorities of individual tasks. They figure out whether developing some feature pushes something else out of the way for the upcoming release, or gets slid off to the next one, or whatever. When they do a good job, that takes a big load off of the programmers. It is, to some extent, also part of the PHB's job to "filter the traffic" and protect both Fred and you from making too many interruptions for each other. This is especially important if you're the type of programmer who tends to get their hands in a lot of different areas of a project. From http Fri Jan 23 22:19:42 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:19:42 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Message-ID: <7x63k5ie5t.fsf@ruckus.brouhaha.com> Bryan Olson writes: > > BTW, class instances are usually immutable and thus don't require a > > mutex in the system I described. > Then you are describing a language radically different from Python. That one threw me for a minute too, but I think the idea is that the class instance itself is immutable, while its slots (specifically the attribute dictionary) point to mutable objects. From skip at pobox.com Fri Jan 23 22:29:10 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 21:29:10 -0600 Subject: Stalled ticket in Python bug tracker In-Reply-To: <018a4c38$0$20629$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> <018a4c38$0$20629$c3e8da3@news.astraweb.com> Message-ID: <18810.35590.11216.469897@montanaro.dyndns.org> Steven> I meant bringing it to the attention of somebody who can Steven> actually commit the patch to production, or rule that the patch Steven> isn't suitable. I can't do that. Perhaps not, but you can help the process along by adding your perspective. Does it solve a problem you have? Does it run on your platform? Can you provide further examples? Can you add missing parts to what's already there (doc changes, test cases)? These are general questions which won't be appropriate for every issue in the tracker, but are some ways Python users without checkin privileges can help the development process. Steven> Sorry for the naive questions, I'm new to the bug tracker and Steven> I'm not entirely sure about the protocol. Should I just drop a Steven> note to python-dev and ask somebody with commit privileges to Steven> look at it, or is that rude? You might want to peruse some of the links on this page: http://www.python.org/dev/ That might give you some insight into the Python development process and how you fit into it. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 22:35:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 03:35:06 GMT Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> Message-ID: <018a82b7$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 18:54:18 -0800, Carl Banks wrote: > On Jan 23, 5:48?pm, Bryan Olson wrote: >> Carl Banks wrote: >> >> [...] >> >> > BTW, class instances are usually immutable and thus don't require a >> > mutex in the system I described. >> >> Then you are describing a language radically different from Python. > > Bzzt. > > Hint: aside from the reference count, most class instances are immutable > in Python *today*. That seems so utterly wrong that either you're an idiot or you're talking at cross purposes to what Bryan and I think you're saying. Since I know you're not an idiot, I can only imagine you have a different understanding of what it means to be immutable than I do. For example... is this instance immutable? class Foo: bar = None f = Foo() f.baz = True If so, what do you mean by immutable? -- Steven From http Fri Jan 23 22:42:20 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:42:20 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> <018a82b7$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7xprid2wv7.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > For example... is this instance immutable? > > class Foo: > bar = None > > f = Foo() > f.baz = True > If so, what do you mean by immutable? If I understand Carl, yes, f is immutable. When you set f.bar, the contents of f.__dict__ changes but f itself does not change. It still points to the same dictionary, etc. From rhodri at wildebst.demon.co.uk Fri Jan 23 22:47:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 24 Jan 2009 03:47:39 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9hie8i.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> <7xab9hie8i.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 24 Jan 2009 03:18:05 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > It is, to some extent, also > part of the PHB's job to "filter the traffic" and protect both Fred > and you from making too many interruptions for each other. This is > especially important if you're the type of programmer who tends to get > their hands in a lot of different areas of a project. In a perfect environment this is true. In an environment where the PHBs are overstretched because their PHBs aren't up to much, that filter function tends to become a full roadblock. Under those circumstances you have three choices: 1) defeat the data hiding by talking to Fred directly; 2) defeat the data hiding by hacking away yourself and getting Fred's forgiveness later; 3) give up. See, we're back on topic! -- Rhodri James *-* Wildebeeste Herder to the Masses From wuwei23 at gmail.com Fri Jan 23 23:02:03 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 23 Jan 2009 20:02:03 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> On Jan 24, 10:56?am, r wrote: > [...] *not being afraid to open my mouth about it, fight for it, free > others from their bonds* [...] > Come down from your tower of *righteousness* Deiz, loosen up that stiff- > upper-lip and bring your brown-nosing minions with you! (emphasis mine to highlight the humorous hypocrisy) Let's see, one poster consistently posts helpful and usable coding advice...the other is on some bizarre, self-aggrandising jihad. I wonder to whom people in this group will actually pay attention... And let's face it, r, the only reason you're lashing out at Diez about his 'minions' is from your complete inability to gain any of your own in your misguided crusade. Done any coding lately? How's that Python bridge to SketchUp coming along? It's been months already, surely you've invested as much effort into learning Python as you have in talking about it? From fakeaddress at nowhere.org Fri Jan 23 23:22:31 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 20:22:31 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x63k5ie5t.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >>> BTW, class instances are usually immutable and thus don't require a >>> mutex in the system I described. >> Then you are describing a language radically different from Python. > > That one threw me for a minute too, but I think the idea is that the > class instance itself is immutable, while its slots (specifically the > attribute dictionary) point to mutable objects. The meaning of 'immutable' is well-established in the Python literature. Python's immutable types include tuple, frozenset, and various kinds of numbers and strings. Class instances, not so much. What's more, this matters when considering a GIL-less implementation. Typical method calls can traverse lots of mutable stuff just to find the function to invoke. -- --Bryan From ptmcg at austin.rr.com Fri Jan 23 23:25:42 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 23 Jan 2009 20:25:42 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: On Jan 23, 8:58?pm, Linuxguy123 wrote: > I just started using python last week and I'm addicted. > > I see a lot of Python in my future. Bravo, welcome, and well-said! Your sentiments mirror and resonate with those of many on this list. About 6 years ago I wanted a scripting language to work with, *anything* but more Tcl/Tk! Python the language had many features and language design decisions that just "felt right," and the natural feel of the object model allowed me to leverage much of the OO theory I had learned using Java and C++. And THEN, it began to dawn on me that a lot of that theory is actually crutch, bailing-wire, and gum, put there to work around the static typing rigidity of C++, Java and their ilk. As much as I loved Scott Meyers' "Effective C++" books, many of their idioms and tricks just fall away as unnecessary in Python. Interfaces? Python don't need no steenking interfaces! The interface concept is still useful for organizing your thinking and OO design, but the implementation is far freer, as you find that an object's conformance to an interface is only determined/required at runtime, not at some long-distant compile step in a library nested N levels deep in your hierarchy. Python exposes many of its dynamic hooks through magic __xxx__ methods. Need to write a proxy wrapper around an object of type X to supercede method Y, but you don't want to write all thouse tedious passthru methods for the X class's methods A thru R? Just implement your special method Y, and let a __getattr__ method pass all the other calls on to the underlying object. Instant Proxy! Want to change the type/behavior of an object from class A to class B? How about this: aobj = A() aobj.__class__ = B Try *that* in as simple-looking C++ or Java! Python's learning curve can be gentle or steep, depending on your own inclination. My advice? Push yourself up as quickly as you can. Quickly put aside this kind of code: for i in range(len(datalist)): # do something with datalist[i] and start thinking in iterators: for item in datalist: # do something with item Need to read through a text file? for line in file("xyzzy.dat"): # do something with each line Master the clean look and feel of a list comprehension or generator expression, over explicit for loops. Need to build a list of the odd numbers up to 100? Instead of this: oddnums = [] for n in range(100): if n % 2: oddnums.append(n) learn to do this: oddnums = [ n for n in range(100) if n % 2 ] Learn the native data structures - tuple, list, dict, set. Learn the dict idiom that serves as Pythons version of a switch statement. Check out the itertools module, a cunning mix of elegance and wizardry. The standard lib is a trove of well-oiled and production- tested code, but the community is not shy about producing additional modules, many with liberal licensing - image processing, text processing/parsing, discrete-event simulation, optimization, genetic algorithms, web/network apps and IPC, ... Google and ye shall find. Write a generator method to yield a sequence of useful values (odd numbers, primes, consonants, fibonacci's, whatever). You can certainly write a lot of Python without ever using these intermediate/ advanced features, but one day you'll give it a shot and think "Dang! what was the big deal? I wish I'd tried this sooner!" Yet having said that, in 6 years I've not yet tried to write a C extension for Python. But I'm told that this too is a well-blazed trail if you feel the need. Dig in! And post back here if you get stuck. Be confident that Python has been employed in a wide range of applications and application domains, and that if a particular feature seems to be missing, it may be because Python takes a slightly different angle on the problem. Ah, those heady days of youth, when the world was fresh, and the idioms of Python were still new and ripe to discover! I envy you, Linuxguy123, I envy you... Enjoy! -- Paul From aahz at pythoncraft.com Fri Jan 23 23:25:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:25:59 -0800 Subject: I'm a python addict ! References: Message-ID: In article , Linuxguy123 wrote: > >I just started using python last week and I'm addicted. Welcome! Just be aware that excessive Perl-bashing is considered somewhat tasteless on this newsgroup, but the occasional snide comment should be fine. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Fri Jan 23 23:27:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:27:50 -0800 Subject: How do I get my python program to get the root password ? References: Message-ID: In article , Linuxguy123 wrote: > >I want to make a python program that I can run as a normal user that >changes the permission on some device files. It will need to ask me for >the root password and then run chown as root in order to do this. > >How do I accomplish this (easily) ? The easiest -- really -- is to just make it a root script and run it with sudo. If you're on Ubuntu, that's pretty much the only option (without resorting to complicated ways of running sudo) -- the standard Ubuntu setup doesn't have a root password. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From pavlovevidence at gmail.com Fri Jan 23 23:28:01 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 20:28:01 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> On Jan 23, 7:19?pm, Paul Rubin wrote: > Bryan Olson writes: > > > BTW, class instances are usually immutable and thus don't require a > > > mutex in the system I described. > > Then you are describing a language radically different from Python. > > That one threw me for a minute too, but I think the idea is that the > class instance itself is immutable, while its slots (specifically the > attribute dictionary) point to mutable objects. Correct, and, getting back to the point, an instance itself would not require a mutex. The dict would need it, of course. It's customary to gloss over this technicality for convenience's sake in most discussions, but it matters in this case. Carl Banks From http Fri Jan 23 23:32:22 2009 From: http (Paul Rubin) Date: 23 Jan 2009 20:32:22 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3pqq7d.fsf@ruckus.brouhaha.com> Bryan Olson writes: > The meaning of 'immutable' is well-established in the Python > literature. Python's immutable types include tuple, frozenset, and > various kinds of numbers and strings. Class instances, not so much. But we are talking about objects as they live in the C implementation, not at the level where Python code deals with them. From aahz at pythoncraft.com Fri Jan 23 23:32:22 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:32:22 -0800 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article , Steve Holden wrote: > >I understand what you are saying, but if the id() associated with a name >doesn't change after augmented assignment it seems a little wrong-headed >to argue that "the augmented assignment always binds a new value to the >name". > >What you are actually saying is that it's up to the method that >implements the augmented assignment whether the same (mutated) object or >a different one is returned, right? And that the left-hand side of the >assignment is always bound to the result of that method. That's overall more correct, but I wanted to emphasize that there is *always* a binding operation being performed. Whether what gets bound to the target is a new object or an existing object is up to the augmented assignment method. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Fri Jan 23 23:34:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:34:04 -0800 Subject: seeking to improve Python skills References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: In article , mk wrote: > >However, unit tests are a tougher cookie, do you have any resource >that's truly worth recommending for learning unit tests? Start with the doctest module. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 00:20:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 05:20:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <877i4lbhv4.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <018a9b54$0$20629$c3e8da3@news.astraweb.com> On Sat, 24 Jan 2009 01:41:35 +0000, Mark Wooding wrote: > Steven D'Aprano writes: ... >> As I see it, you have two coherent positions. On the one hand, you >> could be like Mark Wooding, and say that Yes you want to risk buffer >> overflows by messing with the internals > > Please, point out where I said that! > > I'm pretty sure that the only time I commented on this particular point > (in message <87y6x2cih0.fsf.mdw at metalzone.distorted.org.uk>), I said: [snip] Yes, that was the quote I was thinking of. > While I realise I didn't spell it out, the semantics I had in mind where > > foo.len = n > > means > > if n < 0: > raise ValueError, 'don\'t be stupid' > elif len(foo) < n: > foo += [None] * (n - len(foo)) > else: > foo[n:] = [] But that's not "messing with the internals". That's the conceptual equivalent of a Python getter/setter: # Pseudo-code, untested and incomplete class MyList(list): def __init__(self): self._length = 0 def _getlength(self): return self._length def _setlength(self, n): if n < 0: raise ValueError("don't be stupid") elif len(self) < n: self += [None] * (n - len(self)) else: self[n:] = [] self._length = n len = property(_getlength, _setlength) alist = MyList() alist.length = 1000 # safe This is hardly what "messing with the internals" is! If your idea of modifying hidden, implementation-specific details is "use a safe getter/ setter implementation that holds your hand and protects you from doing anything stupid", then no wonder you object to data hiding. I'd object to it to, if that's what I understood by it. What I'm talking about is unsafe, direct access to the underlying C slots with no hand-holding. You know: messing with the internals with no nice safe interface between you and disaster: alist._length = 2**128 # unsafe! > Safety is good. Escape hatches are good, too. Something we can agree on. >> In the second case, the next question is, why should it only be code >> written in C that is allowed that protection? > > Because Python code can't cause those sorts of problems without > resorting to the escape hatches (e.g., ctypes). And, very > significantly, because C code /needs/ that protection and Python > basically doesn't. > > The basic difference is that C code is fundamentally brittle: if you > mess up its invariants, it can crash horribly and possibly allow its > brain to be taken over by evil people. Python code is fundamentally > robust. The worst that can happen[1] is that the interpreter raises an > exception. This makes it ideally suited to having a more relaxed > attitude to life. And that, in turn, makes it approachable, hackable > interactively, fun! No, it's not the worst that can happen. "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." http://www.pphsg.org/cdsmith/types.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 00:34:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 05:34:16 GMT Subject: is None vs. == None References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018a9ea5$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 20:33:45 -0500, Steve Holden wrote: > Steven D'Aprano wrote: >> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: >> >>> Hi -- Some time ago I ran across a comment recommending using is >>> None instead of == None (also is not None, etc.) >> >> That entirely depends on whether you wish to test for something which >> *is* None or something with *equals* None. Those two things have >> different meanings. >> > No they don't, because the language *guarantees* the None object is a > singleton, so anything that *equals* None *is* None. Twice in one day. Have they put funny chemicals in the water over there? *wink* Steve, in case you missed my earlier response: >>> class Empty: ... def __eq__(self, other): ... return not bool(other) ... >>> e = Empty() >>> e == None True >>> e is None False An instance that compares equal to anything false doesn't strike me as particularly bizarre or pathological. For instance, the Python Cookbook has an implementation for the Null object pattern. The implementation given compares unequal to everything, but suggests defining an appropriate __eq__ if you need different behaviour. -- Steven From Russ.Paielli at gmail.com Sat Jan 24 00:35:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 21:35:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > Makes *no* sense? There's *no* good reason *at all* for the original > > author to hide or protect internals? > > My bad, sorry. > It makes sense... if the original author is an egotist who believes he must > control how I use that library. If the original author provides you with the source code and the right to modify it, he cannot possibly control how you use the library. You can trivially disable any access controls. But for some reason that's not enough for you. Has it occurred to you that some users might actually *want* access controls? Maybe some users want to actually use the library as the author intended it to be used. What a bizarre concept! Oh, but only a paranoid fool could possibly want access controls, eh? Who's the egotist here? From pavlovevidence at gmail.com Sat Jan 24 00:36:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 21:36:25 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> On Jan 23, 8:22?pm, Bryan Olson wrote: > Paul Rubin wrote: > > Bryan Olson writes: > >>> BTW, class instances are usually immutable and thus don't require a > >>> mutex in the system I described. > >> Then you are describing a language radically different from Python. > > > That one threw me for a minute too, but I think the idea is that the > > class instance itself is immutable, while its slots (specifically the > > attribute dictionary) point to mutable objects. > > The meaning of 'immutable' is well-established in the Python literature. > Python's immutable types include tuple, frozenset, and various kinds of > numbers and strings. Class instances, not so much. Of course class instances aren't immutable types: they're not even types. Let me suggest that there is a distinction between an immutable type and an immutable object. Immutable types are what you are talking about: it means that the type provides usable mutator methods. (Whether they mutate the object itself or some associated object doesn't matter.) Immutable objects are a different thing: it means the object cannot change in memory. Classes in Python are mutable types, usually. Class instances are (except for the refcount) immutable objects, usually. We usually talk about mutability of types, but mutability of objects is appropriate for discussion as well. So I can't really agree with your assessment that I wrong to call class instances immutable objects aside from refcounts. BTW, here's a minor brain bender: immutable types are mutable objects. > What's more, this matters when considering a GIL-less implementation. > Typical method calls can traverse lots of mutable stuff just to find the > function to invoke. Now that doesn't make sense at all. What is all this mutable stuff you have to go through, and what does it have to do with the GIL-less implementation? Can you explain further? Or are you just saying it'll be slow. Carl Banks From http Sat Jan 24 00:40:42 2009 From: http (Paul Rubin) Date: 23 Jan 2009 21:40:42 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: <7x8wp1w9b9.fsf@ruckus.brouhaha.com> Carl Banks writes: > > What's more, this matters when considering a GIL-less implementation. > > Typical method calls can traverse lots of mutable stuff just to find the > > function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? foo.bar() has to look up bar in foo's attribute dictionary. From grante at visi.com Sat Jan 24 00:42:34 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 23 Jan 2009 23:42:34 -0600 Subject: How do I get my python program to get the root password ? References: Message-ID: <_cadnZMM0o7XN-fUnZ2dnUVZ_sTinZ2d@posted.usinternet> On 2009-01-24, Aahz wrote: > In article , > Linuxguy123 wrote: >> >>I want to make a python program that I can run as a normal user that >>changes the permission on some device files. It will need to ask me for >>the root password and then run chown as root in order to do this. >> >>How do I accomplish this (easily) ? > > The easiest -- really -- is to just make it a root script and run it with > sudo. If you're on Ubuntu, that's pretty much the only option (without > resorting to complicated ways of running sudo) -- the standard Ubuntu > setup doesn't have a root password. Though it's easy enough to set the root password, it's not really the "Ubuntu way"... -- Grant From david at abbottdavid.com Sat Jan 24 01:12:47 2009 From: david at abbottdavid.com (David) Date: Sat, 24 Jan 2009 01:12:47 -0500 Subject: How do I get my python program to get the root password ? In-Reply-To: <1232759209.3727.2.camel@localhost.localdomain> References: <1232759209.3727.2.camel@localhost.localdomain> Message-ID: <497AB15F.5050801@abbottdavid.com> Linuxguy123 wrote: > I want to make a python program that I can run as a normal user that > changes the permission on some device files. It will need to ask me for > the root password and then run chown as root in order to do this. > > How do I accomplish this (easily) ? > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > I am new to Python, in my process of learning I did put together an example of pexpect that may help. http://asterisklinks.com/wiki/doku.php?id=wiki:pexpect -david -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From Russ.Paielli at gmail.com Sat Jan 24 01:52:04 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 22:52:04 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: On Jan 23, 6:58?pm, Linuxguy123 wrote: > I will never write another Perl or Bash script again. I still use bash for orchestrating the execution of a series of other scripts and/or programs (including python programs). I know you can do that in python, but I find bash simpler to use for that purpose. Then again, that may be just because I learned bash before I learned python. From fakeaddress at nowhere.org Sat Jan 24 01:55:32 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 22:55:32 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: Carl Banks wrote: > Paul Rubin wrote: >> Bryan Olson writes: >>>> BTW, class instances are usually immutable and thus don't require a >>>> mutex in the system I described. >>> Then you are describing a language radically different from Python. >> That one threw me for a minute too, but I think the idea is that the >> class instance itself is immutable, while its slots (specifically the >> attribute dictionary) point to mutable objects. > > Correct, and, getting back to the point, an instance itself would not > require a mutex. The dict would need it, of course. The dict is part of the object and some important slots are mutable. What's more, if your point was to do away with the GIL without changing Python semantics nor requiring heaping masses of locking, I fear you've not fully grasped the problem. Languages such as Java, C++, and C# do not require nearly as much locking as Python because they are not nearly as dynamic. Consider how a method is invoked. Java / C++ / C# can always resolve the method with no locking; the data they need is fixed at link time. Python is much more dynamic. A demo: from __future__ import print_function # A simple class hierarchy: class Foo (object): title = "Mr. Foo" def identify(self): print("I'm called", self.title) class Bar (Foo): title = "Ms. Bar" class Jafo (Bar): title = "Major Jafo" dude = Jafo() # Searches 5 dicts to find the function to call: dude.identify() # Class dicts are mutable: def id(self): print("I'm still called", self.title) Jafo.identify = id dude.identify() # An object's class can change: dude.__class__ = Bar dude.identify() # A class's base classes can change: class Fu (object): def identify(self): print("Call me", self.title) Bar.__bases__ = (Fu,) dude.identify() Result: >>> I'm called Major Jafo I'm still called Major Jafo I'm called Ms. Bar Call me Ms. Bar >>> In that first simple call of dude.identify(), Python looked up "dude" in the module's (mutable) dict to find the object. Then it looked in object's (mutable) dict, and did not find "identify". So it looked at the object's (mutable) __class__ slot, and in that class's (mutable) dict. It still did not find "identify", so it looked in the class's (mutable) __bases__ slot, following Python's depth-first "object protocol" and thus looking in what other (mutable) class dicts and (mutable) __bases__ slots were required. An object's __dict__ slot is *not* mutable; thus we could gain some efficiency by protecting the object and its dict with the same lock. I do not see a major win in Mr. Banks' point that we do not need to lock the object, just its dict. -- --Bryan From http Sat Jan 24 02:04:19 2009 From: http (Paul Rubin) Date: 23 Jan 2009 23:04:19 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: <7x63k5chho.fsf@ruckus.brouhaha.com> Bryan Olson writes: > An object's __dict__ slot is *not* mutable; thus we could gain some > efficiency by protecting the object and its dict with the same lock. I > do not see a major win in Mr. Banks' point that we do not need to lock > the object, just its dict. If the dict contents don't change often, maybe we could use an STM-like approach to eliminate locks when reading. That would of course require rework to just about every C function that accesses Python objects. From kay.schluehr at gmx.net Sat Jan 24 02:24:15 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Fri, 23 Jan 2009 23:24:15 -0800 (PST) Subject: Two import questions in Python 3.0 Message-ID: 1. I'd expected that absolute imports are used in Python 3.0 by default. I may be wrong. I've written two versions of a module sucks.py sucks.py ------------- print ("import from lib.sucks") sucks.py ------------- print ("import from package.sucks") The first is placed in the lib directory that is globally visible by means of PYTHONPATH. The second one is placed in a package package/ __init__.py sucks.py A.py The package also contains a module A.py defined by A.py ------ import sucks Running A yields "import from package.sucks" which means unconditional relative import. It shadows the globally visible sucks.py module. I've expected it the other way round. 2. This is kind of a change request. In a former life I used to call test-scripts as test-scripts. The dumb idea was to point e.g. to lib/tests and run python test_ast.py test_nodeclasses (__main__.AST_Tests) ... ok .... test_parse (__main__.ASTHelpers_Test) ... ok ---------------------------------------------------------------------- Ran 12 tests in 0.219s OK The new style is implemented rather in lib2to3. If I point to lib/ lib2to3/tests and run python test_parser.py Traceback (most recent call last): File "test_parser.py", line 12, in from . import support ValueError: Attempted relative import in non-package The standard error of the years to come that makes working with Python harder and reminds me that it is not a scripting language anymore because you can't run anything as a script not even a test. For pedagogical reasons the behavior of test_ast.py and other standard library tests shall show uniform behavior when called from the command line i.e. they shall all fail with this import error message. What do you think? From pavlovevidence at gmail.com Sat Jan 24 02:44:31 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 23:44:31 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: On Jan 23, 10:55?pm, Bryan Olson wrote: > Carl Banks wrote: > > Paul Rubin wrote: > >> Bryan Olson writes: > >>>> BTW, class instances are usually immutable and thus don't require a > >>>> mutex in the system I described. > >>> Then you are describing a language radically different from Python. > >> That one threw me for a minute too, but I think the idea is that the > >> class instance itself is immutable, while its slots (specifically the > >> attribute dictionary) point to mutable objects. > > > Correct, and, getting back to the point, an instance itself would not > > require a mutex. ?The dict would need it, of course. > > The dict is part of the object and some important slots are mutable. > What's more, if your point was to do away with the GIL without changing > Python semantics nor requiring heaping masses of locking, I fear you've > not fully grasped the problem. If that's what you think I thought, I fear you haven't read anything I've written. [snip] > An object's __dict__ slot is *not* mutable; thus we could gain some > efficiency by protecting the object and its dict with the same lock. I > do not see a major win in Mr. Banks' point that we do not need to lock > the object, just its dict. I'm not sure where you got the idea that I was claiming this was a major win. I'm not sure where you got the idea that I claimed that having to lock all mutable objects wouldn't be slow. For Pete's sake, you followed up to a post where I *agreed* that it would be slow. Carl Banks From fakeaddress at nowhere.org Sat Jan 24 02:45:51 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 23:45:51 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: > Bryan Olson wrote: >> Paul Rubin wrote: >>> Bryan Olson writes: >>>>> BTW, class instances are usually immutable and thus don't require a >>>>> mutex in the system I described. >>>> Then you are describing a language radically different from Python. >>> That one threw me for a minute too, but I think the idea is that the >>> class instance itself is immutable, while its slots (specifically the >>> attribute dictionary) point to mutable objects. >> The meaning of 'immutable' is well-established in the Python literature. >> Python's immutable types include tuple, frozenset, and various kinds of >> numbers and strings. Class instances, not so much. > > Of course class instances aren't immutable types: they're not even > types. Class instances my or may not be types, but that has nothing to do with any point at issue here. I'm saying that class instances are usually, mutable, contrary to your claim, "class instances are usually immutable". > Let me suggest that there is a distinction between an > immutable type and an immutable object. Let me further suggest that Python's documentation is entirely clear: instances of immutable types are immutable objects. Instances of mutable types are generally mutable objects. For example, tuple is an immutable type, and thus tuples are immutable; list is a mutable type, and thus lists are mutable. > Immutable types are what you are talking about: it means that the type > provides usable mutator methods. (Whether they mutate the object > itself or some associated object doesn't matter.) Immutable objects > are a different thing: it means the object cannot change in memory. > > Classes in Python are mutable types, usually. Class instances are > (except for the refcount) immutable objects, usually. There's where we disagree. I assert that class instances are usually mutable objects. > We usually talk about mutability of types, but mutability of objects > is appropriate for discussion as well. So I can't really agree with > your assessment that I wrong to call class instances immutable objects > aside from refcounts. That confusion disappears once one grasps that instances of immutable types are immutable objects. > BTW, here's a minor brain bender: immutable types are mutable objects. Some brains are too easily bent. Python is one of the many object-oriented languages that reifies types as run-time objects. I see no point in going through Python's immutable types to examine if there is any way to mutate the corresponding type objects. >> What's more, this matters when considering a GIL-less implementation. >> Typical method calls can traverse lots of mutable stuff just to find the >> function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? Can you explain further? Or are you just saying > it'll be slow. I elaborated at some length in another strand of this thread. -- --Bryan From pavlovevidence at gmail.com Sat Jan 24 03:06:02 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 00:06:02 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> On Jan 23, 11:45?pm, Bryan Olson wrote: > Carl Banks wrote: > > Classes in Python are mutable types, usually. ?Class instances are > > (except for the refcount) immutable objects, usually. > > There's where we disagree. I assert that class instances are usually > mutable objects. Nope, you're dead wrong, nothing more to it. The bits of a class instance never change. The __dict__ is a mutable object. The class instance itself isn't. It's not reasonable to call an object whose bits can't change a mutable obect. Anyway, all you're doing is distracting attention from my claim that instance objects wouldn't need to be locked. They wouldn't, no matter how mutable you insist these objects whose bits would never change are. > > BTW, here's a minor brain bender: immutable types are mutable objects. > > Some brains are too easily bent. [Snip attempt to take this comment seriously] And some brains are so stodgy they can't even take a lighthearted comment lightheartedly. Carl Banks From gagsl-py2 at yahoo.com.ar Sat Jan 24 03:21:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 06:21:20 -0200 Subject: Two import questions in Python 3.0 References: Message-ID: En Sat, 24 Jan 2009 05:24:15 -0200, Kay Schluehr escribi?: > 1. I'd expected that absolute imports are used in Python 3.0 by > default. I may be wrong. I've written two versions of a module > sucks.py > > sucks.py > ------------- > print ("import from lib.sucks") > > sucks.py > ------------- > print ("import from package.sucks") > > The first is placed in the lib directory that is globally visible by > means of PYTHONPATH. The second one is placed in a package > > package/ > __init__.py > sucks.py > A.py > > The package also contains a module A.py defined by > > A.py > ------ > import sucks > > Running A yields "import from package.sucks" which means unconditional > relative import. It shadows the globally visible sucks.py module. I've > expected it the other way round. If you run A.py as a script, it does not "know" it lives inside a package. You must *import* A for it to become aware of the package. Also, the directory containing the script comes earlier than PYTHONPATH entries in sys.path -- so watch for that case too. > python test_parser.py > Traceback (most recent call last): > File "test_parser.py", line 12, in > from . import support > ValueError: Attempted relative import in non-package > > The standard error of the years to come that makes working with Python > harder and reminds me that it is not a scripting language anymore > because you can't run anything as a script not even a test. I always consider that packages are libraries. Application code "uses" a library (by importing things from it). Test code should mimic closely that behavior: my tests always import the package, like the application would do. Anyway I should revisit the strategy, I've not evaluated yet how much is affected by absolute imports and other changes in 3.0 -- Gabriel Genellina From mail at microcorp.co.za Sat Jan 24 03:29:19 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 24 Jan 2009 10:29:19 +0200 Subject: The First Law Of comp.lang.python Dynamics References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> <497a2cce$0$183$e4fe514c@news.xs4all.nl> Message-ID: <000c01c97e12$990dcf60$0d00a8c0@hendrik> "Martin P. Hellwig" wrote: > Or you can argue that even when an argument is repeated indefinitely it > doesn't make it suddenly right. This is no good. It's a well known fact that anything I tell you three times is true. To demonstrate: Tim Rowe's post earlier in this thread was the funniest one in a long time. Tim Rowe's post earlier in this thread was the funniest one in a long time. Tim Rowe's post earlier in this thread was the funniest one in a long time. see - it's true! - Hendrik From hniksic at xemacs.org Sat Jan 24 03:33:58 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 24 Jan 2009 09:33:58 +0100 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: <87hc3pf6h5.fsf@mulj.homelinux.net> Carl Banks writes: > On Jan 23, 11:45?pm, Bryan Olson wrote: >> Carl Banks wrote: >> > Classes in Python are mutable types, usually. ?Class instances are >> > (except for the refcount) immutable objects, usually. >> >> There's where we disagree. I assert that class instances are usually >> mutable objects. > > Nope, you're dead wrong, nothing more to it. The bits of a class > instance never change. The __dict__ is a mutable object. The class > instance itself isn't. It's not reasonable to call an object whose > bits can't change a mutable obect. The "bits" of class instances can very well change. >>> class X(object): pass ... >>> x = X() >>> d = x.__dict__ >>> x.__dict__ = {} >>> map(id, [d, x.__dict__]) [170329876, 170330012] The Python cookbook even describes patterns that depend on this operation working. Class instance's contents can also change if __slots__ is in use, when its __class__ is assigned to (admittedly the latter being a rare operation, but still). > Anyway, all you're doing is distracting attention from my claim that > instance objects wouldn't need to be locked. They wouldn't, no > matter how mutable you insist these objects whose bits would never > change are. Only if you're not implementing Python, but another language that doesn't support __slots__ and assignment to instance.__dict__. From __peter__ at web.de Sat Jan 24 03:39:21 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jan 2009 09:39:21 +0100 Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I'm interested in this ticket in the bug tracker: > > http://bugs.python.org/issue2527 > > but it seems to have been stalled for nine months. Is there a procedure > for starting it up again? Should I ask about it on the python-dev mailing > list, or just wait until somebody happens to notice it? > > Peter Otten, if you're reading this, is your offer to jump through the > necessary hoops still standing? I guess what killed any chance for the patch to be included was that there was a "competing" patch that I asked to be reversed. Also, just saying that you are willing to provide docs and test didn't work either. What's needed then as a 'sine qua non' is an updated patch against the tip with documentation and tests. If you don't beat me to it I may give it another try, but probably not before next month. Peter From gagsl-py2 at yahoo.com.ar Sat Jan 24 03:40:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 06:40:10 -0200 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: En Sat, 24 Jan 2009 06:06:02 -0200, Carl Banks escribi?: > On Jan 23, 11:45?pm, Bryan Olson wrote: >> Carl Banks wrote: >> > Classes in Python are mutable types, usually. ?Class instances are >> > (except for the refcount) immutable objects, usually. >> >> There's where we disagree. I assert that class instances are usually >> mutable objects. > > Nope, you're dead wrong, nothing more to it. The bits of a class > instance never change. The __dict__ is a mutable object. The class > instance itself isn't. It's not reasonable to call an object whose > bits can't change a mutable obect. > > Anyway, all you're doing is distracting attention from my claim that > instance objects wouldn't need to be locked. They wouldn't, no matter > how mutable you insist these objects whose bits would never change > are. Me too, I don't get what you mean. Consider a list instance, it contains a count of allocated elements, and a pointer to some memory block. They change when the list is resized. This counts as "mutable" to me. I really don't understand your claim. -- Gabriel Genellina From http Sat Jan 24 03:43:23 2009 From: http (Paul Rubin) Date: 24 Jan 2009 00:43:23 -0800 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <87ljt1g794.fsf@mulj.homelinux.net> Message-ID: <7x63k52ixg.fsf@ruckus.brouhaha.com> Hrvoje Niksic writes: > Not only registered at the beginning of the function, but also (since > CPython uses C, not C++) explicitly unregistered at every point of > exit from the function. Emacs implements these as macros called GCPRO > and UNGCPRO, and they're very easy to get wrong. In a way, they are > even worse than the current Python INCREF/DECREF. That's a fairly natural style in Lisp implementation and it is not that difficult to code in. I've hacked inside Emacs and have written another interpreter with a similar setup; it's certainly easier than keeping track of refcounts in my experience. For one thing, you can raise exceptions anywhere you want, and the stack unwind can clean up the gc protection, but it can't know nearly as easily which refcounts to adjust, unless you record all the increfs the same way as the GCPROs. From dunmer at dreams.sk Sat Jan 24 03:52:57 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 09:52:57 +0100 Subject: Web authentication urllib2 Message-ID: <497AD6E9.9080909@dreams.sk> Hello, I'm new in Python and i would like to write script which need to login to a website. I'm experimenting with urllib2, especially with something like this: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(username='user', password='pass')) f = opener.open('https://web.com', params) data = f.read() f.close() And the problem is, that this code logs me in on some sites, but on others doesn't, especially on the one I really need to login. And i don't know why. So is there some way how to debug this code and find out why that script cannot login on that specific site? Sorry if this question is too lame, but i am really beginner both in python and web programming .) From dunmer at dreams.sk Sat Jan 24 03:52:57 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 09:52:57 +0100 Subject: Web authentication urllib2 Message-ID: <497AD6E9.9080909@dreams.sk> Hello, I'm new in Python and i would like to write script which need to login to a website. I'm experimenting with urllib2, especially with something like this: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(username='user', password='pass')) f = opener.open('https://web.com', params) data = f.read() f.close() And the problem is, that this code logs me in on some sites, but on others doesn't, especially on the one I really need to login. And i don't know why. So is there some way how to debug this code and find out why that script cannot login on that specific site? Sorry if this question is too lame, but i am really beginner both in python and web programming .) From steve at holdenweb.com Sat Jan 24 03:57:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 03:57:30 -0500 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: Benjamin Peterson wrote: > Robin Becker NOSPAMreportlab.com> writes: >> Well that's not really acceptable as a solution is it? :) > > This doesn't happen in Python 3.0, > so you could port to that. :) > > In 2.7, the better recursion depth > handling > in Py3k may be backported,but the > best you can do for now is not touch > the recursion limit or just shut > the error up. > Perhaps an interim solution would implement an error message more helpful in ensuring the exception not be raised? This is currently a bit like "Your code is wrong": strictly correct, and totally unhelpful. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 03:58:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 03:58:40 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Aahz wrote: > In article , > Steve Holden wrote: >> I understand what you are saying, but if the id() associated with a name >> doesn't change after augmented assignment it seems a little wrong-headed >> to argue that "the augmented assignment always binds a new value to the >> name". >> >> What you are actually saying is that it's up to the method that >> implements the augmented assignment whether the same (mutated) object or >> a different one is returned, right? And that the left-hand side of the >> assignment is always bound to the result of that method. > > That's overall more correct, but I wanted to emphasize that there is > *always* a binding operation being performed. Whether what gets bound to > the target is a new object or an existing object is up to the augmented > assignment method. Yes, we're on the same page. Maybe I was being too pedantic ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 04:02:34 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 04:02:34 -0500 Subject: is None vs. == None In-Reply-To: <018a9ea5$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <018a9ea5$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 20:33:45 -0500, Steve Holden wrote: > >> Steven D'Aprano wrote: >>> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: >>> >>>> Hi -- Some time ago I ran across a comment recommending using is >>>> None instead of == None (also is not None, etc.) >>> That entirely depends on whether you wish to test for something which >>> *is* None or something with *equals* None. Those two things have >>> different meanings. >>> >> No they don't, because the language *guarantees* the None object is a >> singleton, so anything that *equals* None *is* None. > > Twice in one day. Have they put funny chemicals in the water over there? > *wink* > Nope, but you know what newsgroup response propagation is like ... > Steve, in case you missed my earlier response: > >>>> class Empty: > ... def __eq__(self, other): > ... return not bool(other) > ... >>>> e = Empty() >>>> e == None > True >>>> e is None > False > > > An instance that compares equal to anything false doesn't strike me as > particularly bizarre or pathological. For instance, the Python Cookbook > has an implementation for the Null object pattern. The implementation > given compares unequal to everything, but suggests defining an > appropriate __eq__ if you need different behaviour. > Sure, my syllogism was not strictly true, hence my final quote: > Of course there can be pathological objects with bizarre comparison > methods. And the "is" test helps avoid them. Personally I believe that the Empty class is at least slightly pathological. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fakeaddress at nowhere.org Sat Jan 24 04:11:14 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 24 Jan 2009 01:11:14 -0800 Subject: Securing a database In-Reply-To: <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> Message-ID: <2SAel.11592$D32.10293@flpi146.ffdc.sbc.com> kt83313 at gmail.com wrote: > Thank you very much Bryan. > It does look like this is out of my league. As Peter Pearson noted, "It is out of *everyone's* league." And Peter used to work for Cryptography Research, a small company that scored as high in this league as anyone. Maybe you can advance the state of the art in DRM; but if so, you can probably make more money on that than on selling access to this particular database. Stepping back, KT, you said that your company currently provides an on-line service backed by this database. Maybe you want to stick with that. Can you say what prompts you to look at offering off-line access to your customers? I've spent most of my career, so far, as a cryptologic engineer, and I've seen similar problems. For example, the U.S. Postal Service has a database of valid addresses and address forwarding requests that can provide reasonable and valuable services, but that they are barred by law from generally exposing. Users are allowed to check the validity of a name-and-address, and if they have one, they're allowed to know if the addressee has forwarded it, and if so, to where. At the time I got involved with the USPS's FASTforward system, they offered an Internet service, and an off-line locally-accessible product. The off-line product was a black-box system -- literally: a PC-class computer in locked black case, with hardened epoxy gumming up most of the interface ports. An open SCSI port answered legitimate forwarding requests, and the CD drive accepted encrypted updates to the database. A similar scheme might still play, but there's no question that times have changed. Back then, the USPS system of locked black boxes made sense. Users numbered more than a hundred but less than a thousand, and the Post Office required agreement to a contract that protected individual addresses. -- --Bryan From kay.schluehr at gmx.net Sat Jan 24 04:37:21 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 01:37:21 -0800 (PST) Subject: Two import questions in Python 3.0 References: Message-ID: On 24 Jan., 09:21, "Gabriel Genellina" wrote: > If you run A.py as a script, it does not "know" it lives inside a package. > You must *import* A for it to become aware of the package. > Also, the directory containing the script comes earlier than PYTHONPATH > entries in sys.path -- so watch for that case too. Thanks, yes. I always make the same error thinking that a directory with the ritual __init__ file is actually a package ( as some kind of platonic entity ), something that is more obvious to me than it is to the runtime. The relative import semantics introduced with Python 2.5 has made the error just visible that was hidden to me for about a decade. Shit. From robin at NOSPAMreportlab.com Sat Jan 24 04:40:08 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 24 Jan 2009 09:40:08 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: <497AE1F8.5040008@jessikat.plus.net> Steve Holden wrote: > Benjamin Peterson wrote: >> Robin Becker NOSPAMreportlab.com> writes: >>> Well that's not really acceptable as a solution is it? :) >> This doesn't happen in Python 3.0, >> so you could port to that. :) my initial attempts in this direction were even less successful :( ........ > Perhaps an interim solution would implement an error message more > helpful in ensuring the exception not be raised? This is currently a bit > like "Your code is wrong": strictly correct, and totally unhelpful. well after wrapping all the calls to isinstance I think I have found the particular call and args that are causing the problem, but I still don't really understand why the problem is occurring. -- Robin Becker From gagsl-py2 at yahoo.com.ar Sat Jan 24 05:05:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 08:05:16 -0200 Subject: Web authentication urllib2 References: <497AD6E9.9080909@dreams.sk> Message-ID: En Sat, 24 Jan 2009 06:52:57 -0200, Gabriel escribi?: > I'm new in Python and i would like to write script which need to login > to a website. I'm experimenting with urllib2, > especially with something like this: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(username='user', password='pass')) > f = opener.open('https://web.com', params) > data = f.read() > f.close() > > And the problem is, that this code logs me in on some sites, but on > others doesn't, especially on the one I really > need to login. And i don't know why. So is there some way how to debug > this code and find out why that script cannot > login on that specific site? Start by looking at the web page that you normally use to log into the site; probably the form contains more fields than just username and password. In some cases it may be necesary to use ethereal (or any protocol analizer), to see exactly what is actually transmitted when you log in using your browser. Later you may try to reproduce the same thing with Python. -- Gabriel Genellina From steve at holdenweb.com Sat Jan 24 05:23:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 05:23:38 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 23, 8:22 pm, Bryan Olson wrote: >> Paul Rubin wrote: >>> Bryan Olson writes: >>>>> BTW, class instances are usually immutable and thus don't require a >>>>> mutex in the system I described. >>>> Then you are describing a language radically different from Python. >>> That one threw me for a minute too, but I think the idea is that the >>> class instance itself is immutable, while its slots (specifically the >>> attribute dictionary) point to mutable objects. >> The meaning of 'immutable' is well-established in the Python literature. >> Python's immutable types include tuple, frozenset, and various kinds of >> numbers and strings. Class instances, not so much. > > Of course class instances aren't immutable types: they're not even > types. Let me suggest that there is a distinction between an > immutable type and an immutable object. > > Immutable types are what you are talking about: it means that the type > provides usable mutator methods. (Whether they mutate the object > itself or some associated object doesn't matter.) Immutable objects > are a different thing: it means the object cannot change in memory. > > Classes in Python are mutable types, usually. Class instances are > (except for the refcount) immutable objects, usually. > > We usually talk about mutability of types, but mutability of objects > is appropriate for discussion as well. So I can't really agree with > your assessment that I wrong to call class instances immutable objects > aside from refcounts. > > BTW, here's a minor brain bender: immutable types are mutable objects. > > >> What's more, this matters when considering a GIL-less implementation. >> Typical method calls can traverse lots of mutable stuff just to find the >> function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? Can you explain further? Or are you just saying > it'll be slow. > OK, so we have recently discussed whether objects are values, whether function arguments are passed by reference, whether names are references, and now we are, I suspect, about to have a huge further discussion on the meaning of "immutable". Sometimes I start to find this eternal pedantry a little tedious. I suspect it's time I once more dropped out of c.l.py for a while. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 05:36:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 05:36:58 -0500 Subject: Web authentication urllib2 In-Reply-To: <497AD6E9.9080909@dreams.sk> References: <497AD6E9.9080909@dreams.sk> Message-ID: Gabriel wrote: > Hello, > > I'm new in Python and i would like to write script which need to login > to a website. I'm experimenting with urllib2, > especially with something like this: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(username='user', password='pass')) > f = opener.open('https://web.com', params) > data = f.read() > f.close() > > And the problem is, that this code logs me in on some sites, but on > others doesn't, especially on the one I really > need to login. And i don't know why. So is there some way how to debug > this code and find out why that script cannot > login on that specific site? > > Sorry if this question is too lame, but i am really beginner both in > python and web programming .) > That's actually pretty good code for a newcomer! There are a couple of issues you may be running into. First, not all sites use "application-based" authentication - they may use HTTP authentication of some kind instead. In that case you have to pass the username and password as a part of the HTTP headers. Michael Foord has done a fair write-up of the issues at http://www.voidspace.org.uk/python/articles/authentication.shtml and you will do well to read that if, indeed, you need to do basic authentication. Second, if it *is* the web application that's doing the authentication in the sites that are failing (in other words if the credentials are passed in a web form) then your code may need adjusting to use other field names, or to include other data as required by the login form. You can usually find out what's required by reading the HTML source of the page that contains the login form. Thirdly [nobody expects the Spanish Inquisition ...], it may be that some sites are extraordinarily sensitive to programmed login attempts (possible due to spam), typically using a check of the "Agent:" HTTP header to "make sure" that the login attempt is coming from a browser and not a program. For sites like these you may need to emulate a browser response more fully. You can use a program like Wireshark to analyze the network traffic, though you can get add-ons for Firefox that will show you the HTTP headers on request and response. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From seelasarasalomi at gmail.com Sat Jan 24 05:44:07 2009 From: seelasarasalomi at gmail.com (porkodi) Date: Sat, 24 Jan 2009 02:44:07 -0800 (PST) Subject: Python Message-ID: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> www.easythings5.blogspot.com From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 06:07:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 11:07:19 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018aecb2$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: > Quoting Steven D'Aprano : > >> On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: >> >> > It should be in _our_ power as the team of all participant coders on >> > _our_ project to decide if we should mess with the internals or not. >> > >> > What makes no sense is that it should be in the original author's >> > power to decide, if he is not part of _our_ team. >> >> Makes *no* sense? There's *no* good reason *at all* for the original >> author to hide or protect internals? > > My bad, sorry. > It makes sense... if the original author is an egotist who believes he > must control how I use that library. Then I guess Guido must be such an egotist, because there's plenty of internals in Python that you can't (easy) mess with. > Or, if external forces make him do > it (maybe like, 'oh, if I change python, then I'm not using python > anymore'). That parenthesised comment makes no sense to me. Python has changed significantly since it was first released. Recently, print became a function instead of a statement, and one of the motivations for this was to allow people to change the behaviour of Python's print simply by defining a new function. "Shadowing built-ins", as they call it, is a feature, not a bug. I can't see any good reason for thinking that if you change (say) the way Python prints, you don't have Python any more. Even more fundamental changes have occurred, e.g. new style classes, ABCs, nested scopes. [...] > If a variable is marked as... I don't like 'private', I'll call it > 'implementation detail', I would not use it without good reason. Not > even by subclassing it. Why do you assume that I'd change list._length > if I could? I wouldn't. I didn't say you would change it on a whim. I said that *if* it were exposed to Python code, you *could* change it. You might change it because you thought you had a good reason to. You might change it by accident. You might not realise the consequences of changing it. Who knows? It doesn't matter what your motives are. My point is that you claimed that there is no good reason at all for hiding implementation details. Python is full of implementation details which are quite effectively hidden from Python programmers. So there are two possibilities: (1) you are right that it "makes no sense" (your words) for the original author (in this case, Guido) to hide those implementation details from Python programmers; or (2) you are wrong that it "makes no sense", because there is at least one case where the original author (Guido again) did a sensible thing by hiding implementation details. In an effort to avoid going round and round in circles, let me explicitly say that option (2) does not imply that it always makes sense to hide implementation details. > Anyway, did you notice that your "counter-example" was a radical > change-the-way-python-works scenario? No, my scenario is merely extending what you can already do with pure- Python classes to built-in classes written in C. It would have a radical effect (pure Python code could core dump easily) but it wouldn't be a radical change. It might take as little as one new function. [...] >> So what you're saying is that the fundamental design of Python -- to be >> a high-level language that manages memory for you while avoiding >> common programming errors such as buffer overflows -- makes "no sense". >> Is that what you intended? > > Yes, that's what I intended, obviously. I'd like to have buffer > overflows in python. In case you don't understand irony: don't go > putting words in my mouth. I'm not putting words in yours. And neither am I. I'm pointing out the logical implications of your position. If you find those implications unpleasant, then perhaps you should modify your position to be less extreme and more realistic. >> As I see it, you have two coherent positions. On the one hand, you >> could be like Mark Wooding, and say that Yes you want to risk buffer >> overflows by messing with the internals -- in which case I'm not sure >> what you see in Python, which protects so many internals from you. Or >> you can say that you made a mistake, that there are *some* good reasons >> to protect/hide internals from external access. > > Or, I could have a third option: assume that I am a grownup who knows > what he is doing. This is totally orthogonal to what we're discussing. Whether you are a grownup or a child, whether you have good reasons or bad reasons, you can still make either of the two choices. > After all, even with all those "protections" in list, > I could just create an extension module to shoot me in the foot anyway, > if I really wanted to. Yes you could, and you could hack the OS to manipulate data behind the scenes, and you could build a hardware device to inject whatever data you want directly into the memory. You can do any of those things. So what? Data hiding isn't about some sort of mythical 100% certainty against any imaginable failure mode. Data hiding is a tool like any other, and like all tools, it has uses and misuses, and it works under some circumstances and not others. Wrenches are excellent for tightening bolts even though they don't work in weightlessness (the astronaut spins around instead), and hammers are good for hammering nails even though they won't work on the surface of Pluto (the metal will become brittle and shatter). Data hiding is no different. If you don't get 100% certainty that there will never be a failure no matter what, what do you get? Just off the top of my head, it: * makes it easier for an optimising compiler to give fast code if it doesn't have to assume internal details can be changed; * makes it easier to separate interface from implementation when you can trust that the implementation actually isn't being used; * gives the developer more freedom to change the implementation; * makes it possible for meaningful correctness proofs; * reduces the amount of interconnections between different parts of your program by ensuring that all interaction goes through the interface instead of the implementation; * which in turn reduces the amount of testing you need to do; and possibly others. [...] > I don't think this is going anywhere. Now you are trying to push me to > the extremes, changing what I _said_ for your exaggerated interpretation > of it just so you could shoot it down, or force me to say that I want > buffer overflows in python. I believe that's called "strawman". No, I'm not changing anything you said. I'm pointing out the implications of what you said. Don't blame me for seeing what logical consequences following from your statement. > I stand by my words - but not by your "interpretation" of them: > >> > What makes no sense is that it should be in the original author's >> > power to decide, if he is not part of _our_ team. > > Do you _really_ read from that sentence that I should dislike python > because it makes it a bit harder to get a buffer overflow with their > native types? Well, you tell me: does it make sense for Guido to have decided to make it hard for pure Python developers to cause buffer overflows? If your answer is Yes, it makes sense, then obviously your earlier statement that it makes no sense is *wrong*, at least under some circumstances. Then we can make progress: data hiding isn't *always* evil and anti-freedom and useless, it's okay when Guido does it. Then we can act like grownups and discuss under what other circumstances it is or isn't good to use data hiding, instead of making sweeping generalisations that it is never good and always useless. If your answer is No, it makes no sense, Guido was wrong to hide implementation details from Python developers, then I can't imagine what you get out of the stifling, unpleasant B&D language Python. Perhaps you like the syntax? -- Steven From techtonik at gmail.com Sat Jan 24 06:26:34 2009 From: techtonik at gmail.com (anatoly techtonik) Date: Sat, 24 Jan 2009 13:26:34 +0200 Subject: About SCons Re: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: <497A44A1.20907@roumenpetrov.info> References: <497A44A1.20907@roumenpetrov.info> Message-ID: On Sat, Jan 24, 2009 at 12:28 AM, Roumen Petrov >> >> I would better use SCons for both unix and windows builds. In case of >> windows for both compilers - mingw and microsoft ones. To port curses >> extension to windows I need to know what gcc options mean, what are >> the rules to write Makefiles and how to repeat these rules as well as >> find options in visual studio interface. Not mentioning various >> platform-specific defines and warning fixes. > > Did you select one of existing curses library for windows ? I've selected PDCurses and successfully compiled the module and run demos manually - you may see the batch and the patch at http://bugs.python.org/issue2889 However, I was asked for VS2008 project file and this is where it all stopped for 8 months already. First I couldn't get the VS2008, then it refused to run on my W2K and now I can't get enough time to learn it (including that I have 50%/40% experience in PHP/Python and only 5%/5% C/Java). -- --anatoly t. From dunmer at dreams.sk Sat Jan 24 06:59:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 12:59:22 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> Message-ID: <497B029A.2010606@dreams.sk> First, thank you both I think this isn't basic auth, because this page has form login. I read site's html source and used wireshark to analyze communication between my browser and website and i really find out that a was ignoring one field I added it to the parameters but it didn't help.. Maybe i'm still missing something Here's the post packet: http://student.fiit.stuba.sk/~sevecek06/auth.txt and here's the code again, with little change and real web location added: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(login='login', pwd='pass', page='')) f = opener.open('https://www.orangeportal.sk/', params) data = f.read() f.close() Login and pass are fake ofc. Thank you in advice for any help. Steve Holden wrote: > Gabriel wrote: >> Hello, >> >> I'm new in Python and i would like to write script which need to login >> to a website. I'm experimenting with urllib2, >> especially with something like this: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(username='user', password='pass')) >> f = opener.open('https://web.com', params) >> data = f.read() >> f.close() >> >> And the problem is, that this code logs me in on some sites, but on >> others doesn't, especially on the one I really >> need to login. And i don't know why. So is there some way how to debug >> this code and find out why that script cannot >> login on that specific site? >> >> Sorry if this question is too lame, but i am really beginner both in >> python and web programming .) >> > That's actually pretty good code for a newcomer! There are a couple of > issues you may be running into. > > First, not all sites use "application-based" authentication - they may > use HTTP authentication of some kind instead. In that case you have to > pass the username and password as a part of the HTTP headers. Michael > Foord has done a fair write-up of the issues at > > http://www.voidspace.org.uk/python/articles/authentication.shtml > > and you will do well to read that if, indeed, you need to do basic > authentication. > > Second, if it *is* the web application that's doing the authentication > in the sites that are failing (in other words if the credentials are > passed in a web form) then your code may need adjusting to use other > field names, or to include other data as required by the login form. You > can usually find out what's required by reading the HTML source of the > page that contains the login form. > > Thirdly [nobody expects the Spanish Inquisition ...], it may be that > some sites are extraordinarily sensitive to programmed login attempts > (possible due to spam), typically using a check of the "Agent:" HTTP > header to "make sure" that the login attempt is coming from a browser > and not a program. For sites like these you may need to emulate a > browser response more fully. > > You can use a program like Wireshark to analyze the network traffic, > though you can get add-ons for Firefox that will show you the HTTP > headers on request and response. > > regards > Steve From dunmer at dreams.sk Sat Jan 24 06:59:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 12:59:22 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> Message-ID: <497B029A.2010606@dreams.sk> First, thank you both I think this isn't basic auth, because this page has form login. I read site's html source and used wireshark to analyze communication between my browser and website and i really find out that a was ignoring one field I added it to the parameters but it didn't help.. Maybe i'm still missing something Here's the post packet: http://student.fiit.stuba.sk/~sevecek06/auth.txt and here's the code again, with little change and real web location added: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(login='login', pwd='pass', page='')) f = opener.open('https://www.orangeportal.sk/', params) data = f.read() f.close() Login and pass are fake ofc. Thank you in advice for any help. Steve Holden wrote: > Gabriel wrote: >> Hello, >> >> I'm new in Python and i would like to write script which need to login >> to a website. I'm experimenting with urllib2, >> especially with something like this: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(username='user', password='pass')) >> f = opener.open('https://web.com', params) >> data = f.read() >> f.close() >> >> And the problem is, that this code logs me in on some sites, but on >> others doesn't, especially on the one I really >> need to login. And i don't know why. So is there some way how to debug >> this code and find out why that script cannot >> login on that specific site? >> >> Sorry if this question is too lame, but i am really beginner both in >> python and web programming .) >> > That's actually pretty good code for a newcomer! There are a couple of > issues you may be running into. > > First, not all sites use "application-based" authentication - they may > use HTTP authentication of some kind instead. In that case you have to > pass the username and password as a part of the HTTP headers. Michael > Foord has done a fair write-up of the issues at > > http://www.voidspace.org.uk/python/articles/authentication.shtml > > and you will do well to read that if, indeed, you need to do basic > authentication. > > Second, if it *is* the web application that's doing the authentication > in the sites that are failing (in other words if the credentials are > passed in a web form) then your code may need adjusting to use other > field names, or to include other data as required by the login form. You > can usually find out what's required by reading the HTML source of the > page that contains the login form. > > Thirdly [nobody expects the Spanish Inquisition ...], it may be that > some sites are extraordinarily sensitive to programmed login attempts > (possible due to spam), typically using a check of the "Agent:" HTTP > header to "make sure" that the login attempt is coming from a browser > and not a program. For sites like these you may need to emulate a > browser response more fully. > > You can use a program like Wireshark to analyze the network traffic, > though you can get add-ons for Firefox that will show you the HTTP > headers on request and response. > > regards > Steve From dunmer at dreams.sk Sat Jan 24 07:13:25 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:13:25 +0100 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B05E5.6060201@dreams.sk> Oh, nevermind, it's working. Thanks Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > > Login and pass are fake ofc. > > Thank you in advice for any help. > > > Steve Holden wrote: >> Gabriel wrote: >>> Hello, >>> >>> I'm new in Python and i would like to write script which need to login >>> to a website. I'm experimenting with urllib2, >>> especially with something like this: >>> >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >>> urllib2.install_opener(opener) >>> >>> params = urllib.urlencode(dict(username='user', password='pass')) >>> f = opener.open('https://web.com', params) >>> data = f.read() >>> f.close() >>> >>> And the problem is, that this code logs me in on some sites, but on >>> others doesn't, especially on the one I really >>> need to login. And i don't know why. So is there some way how to debug >>> this code and find out why that script cannot >>> login on that specific site? >>> >>> Sorry if this question is too lame, but i am really beginner both in >>> python and web programming .) >>> >> That's actually pretty good code for a newcomer! There are a couple of >> issues you may be running into. >> >> First, not all sites use "application-based" authentication - they may >> use HTTP authentication of some kind instead. In that case you have to >> pass the username and password as a part of the HTTP headers. Michael >> Foord has done a fair write-up of the issues at >> >> http://www.voidspace.org.uk/python/articles/authentication.shtml >> >> and you will do well to read that if, indeed, you need to do basic >> authentication. >> >> Second, if it *is* the web application that's doing the authentication >> in the sites that are failing (in other words if the credentials are >> passed in a web form) then your code may need adjusting to use other >> field names, or to include other data as required by the login form. You >> can usually find out what's required by reading the HTML source of the >> page that contains the login form. >> >> Thirdly [nobody expects the Spanish Inquisition ...], it may be that >> some sites are extraordinarily sensitive to programmed login attempts >> (possible due to spam), typically using a check of the "Agent:" HTTP >> header to "make sure" that the login attempt is coming from a browser >> and not a program. For sites like these you may need to emulate a >> browser response more fully. >> >> You can use a program like Wireshark to analyze the network traffic, >> though you can get add-ons for Firefox that will show you the HTTP >> headers on request and response. >> >> regards >> Steve > > -- > http://mail.python.org/mailman/listinfo/python-list > From dunmer at dreams.sk Sat Jan 24 07:13:25 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:13:25 +0100 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B05E5.6060201@dreams.sk> Oh, nevermind, it's working. Thanks Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > > Login and pass are fake ofc. > > Thank you in advice for any help. > > > Steve Holden wrote: >> Gabriel wrote: >>> Hello, >>> >>> I'm new in Python and i would like to write script which need to login >>> to a website. I'm experimenting with urllib2, >>> especially with something like this: >>> >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >>> urllib2.install_opener(opener) >>> >>> params = urllib.urlencode(dict(username='user', password='pass')) >>> f = opener.open('https://web.com', params) >>> data = f.read() >>> f.close() >>> >>> And the problem is, that this code logs me in on some sites, but on >>> others doesn't, especially on the one I really >>> need to login. And i don't know why. So is there some way how to debug >>> this code and find out why that script cannot >>> login on that specific site? >>> >>> Sorry if this question is too lame, but i am really beginner both in >>> python and web programming .) >>> >> That's actually pretty good code for a newcomer! There are a couple of >> issues you may be running into. >> >> First, not all sites use "application-based" authentication - they may >> use HTTP authentication of some kind instead. In that case you have to >> pass the username and password as a part of the HTTP headers. Michael >> Foord has done a fair write-up of the issues at >> >> http://www.voidspace.org.uk/python/articles/authentication.shtml >> >> and you will do well to read that if, indeed, you need to do basic >> authentication. >> >> Second, if it *is* the web application that's doing the authentication >> in the sites that are failing (in other words if the credentials are >> passed in a web form) then your code may need adjusting to use other >> field names, or to include other data as required by the login form. You >> can usually find out what's required by reading the HTML source of the >> page that contains the login form. >> >> Thirdly [nobody expects the Spanish Inquisition ...], it may be that >> some sites are extraordinarily sensitive to programmed login attempts >> (possible due to spam), typically using a check of the "Agent:" HTTP >> header to "make sure" that the login attempt is coming from a browser >> and not a program. For sites like these you may need to emulate a >> browser response more fully. >> >> You can use a program like Wireshark to analyze the network traffic, >> though you can get add-ons for Firefox that will show you the HTTP >> headers on request and response. >> >> regards >> Steve > > -- > http://mail.python.org/mailman/listinfo/python-list > From zzbbaadd at aol.com Sat Jan 24 07:14:18 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Sat, 24 Jan 2009 04:14:18 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: On Jan 23, 8:57?am, Dennis Lee Bieber wrote: > On Fri, 23 Jan 2009 01:48:32 -0800 (PST), TheFlyingDutchman > declaimed the following in comp.lang.python: > > > abstraction. In Python, all class attributes are public but names may > > be "mangled" to discourage unauthorized access, but otherwise not > > prevented. It is up to the designer to provide the appropriate > > interfaces to the data so that the client programmer does not have to > > resort to manipulating the encapsulated data attributes." > > ? ? ? ? Double underscore "mangling" was not implemented to "discourage > unauthorized access". Its primary purpose is to prevent name space > conflicts when an extended subclass and its parent class use the same > name for an attribute, but that attribute is not of the same "meaning". > Using the __ prefix means BOTH attributes are part of the instance, but > the subclass only see's its variant and should make calls into > superclass methods to modify the parent variant. > > ? ? ? ? Python convention is that a single underscore -- which does NOT > perform name mangling -- is the indicator meant to "discourage > unauthorized access". > Is there a significant performance hit with using the double underscore for signifying a variable you want to be private? It seems like it is advantageous that someone trying for direct access has to use a different notation, which will help to emphasize that it shouldn't be access directly. From andrew at acooke.org Sat Jan 24 07:16:31 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 04:16:31 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? Message-ID: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Hi, I have some 3.0 code, which I would like to make work with 2.6. However, there does not seem to be support for the new super() (no args) via __future__. Is that correct? If so, what's the best way to handle this? Thanks, Andrew From steve at holdenweb.com Sat Jan 24 07:18:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 07:18:58 -0500 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > If you look at the login form on the home page of that portal you will see
This means that the form should be submitted to https://www.orangeportal.sk/portal/do_login.dwp Some forms submit to the same URL that contain them, but many don't. This is one of the ones that requires submission to a different URL! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dunmer at dreams.sk Sat Jan 24 07:23:20 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:23:20 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B0838.1010002@dreams.sk> Yep, i realize this a minute after posting, sorry. And thank you again .) Steve Holden wrote: > Gabriel wrote: >> First, thank you both >> >> I think this isn't basic auth, because this page has form login. >> I read site's html source and used wireshark to analyze communication >> between my browser and website and i really find out that a was ignoring >> one field >> >> I added it to the parameters but it didn't help.. >> Maybe i'm still missing something >> >> Here's the post packet: >> http://student.fiit.stuba.sk/~sevecek06/auth.txt >> >> and here's the code again, with little change and real web location added: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(login='login', pwd='pass', page='')) >> f = opener.open('https://www.orangeportal.sk/', params) >> data = f.read() >> f.close() >> > If you look at the login form on the home page of that portal you will see > > > > This means that the form should be submitted to > > https://www.orangeportal.sk/portal/do_login.dwp > > Some forms submit to the same URL that contain them, but many don't. > This is one of the ones that requires submission to a different URL! > > regards > Steve From dunmer at dreams.sk Sat Jan 24 07:23:20 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:23:20 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B0838.1010002@dreams.sk> Yep, i realize this a minute after posting, sorry. And thank you again .) Steve Holden wrote: > Gabriel wrote: >> First, thank you both >> >> I think this isn't basic auth, because this page has form login. >> I read site's html source and used wireshark to analyze communication >> between my browser and website and i really find out that a was ignoring >> one field >> >> I added it to the parameters but it didn't help.. >> Maybe i'm still missing something >> >> Here's the post packet: >> http://student.fiit.stuba.sk/~sevecek06/auth.txt >> >> and here's the code again, with little change and real web location added: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(login='login', pwd='pass', page='')) >> f = opener.open('https://www.orangeportal.sk/', params) >> data = f.read() >> f.close() >> > If you look at the login form on the home page of that portal you will see > > > > This means that the form should be submitted to > > https://www.orangeportal.sk/portal/do_login.dwp > > Some forms submit to the same URL that contain them, but many don't. > This is one of the ones that requires submission to a different URL! > > regards > Steve From mrkafk at gmail.com Sat Jan 24 07:31:03 2009 From: mrkafk at gmail.com (mk) Date: Sat, 24 Jan 2009 13:31:03 +0100 Subject: What's the business with the asterisk? Message-ID: Hello everyone, From time to time I spot an asterisk (*) used in the Python code _outside_ the usual *args or **kwargs application. E.g. here: http://www.norvig.com/python-lisp.html def transpose (m): return zip(*m) >>> transpose([[1,2,3], [4,5,6]]) [(1, 4), (2, 5), (3, 6)] What does *m mean in this example and how does it do the magic here? Regards, mk From python.list at tim.thechases.com Sat Jan 24 07:46:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Jan 2009 06:46:34 -0600 Subject: What's the business with the asterisk? In-Reply-To: References: Message-ID: <497B0DAA.10209@tim.thechases.com> > From time to time I spot an asterisk (*) used in the Python code > _outside_ the usual *args or **kwargs application. > > E.g. here: http://www.norvig.com/python-lisp.html > > def transpose (m): > return zip(*m) > >>> transpose([[1,2,3], [4,5,6]]) > [(1, 4), (2, 5), (3, 6)] > > What does *m mean in this example and how does it do the magic here? There's a good writeup on args/kwargs at http://www.megasolutions.net/python/-args-and---kwargs-78766.aspx (looks like the content was gleaned from comp.lang.python and credited) -tkc From dannox at gmail.com Sat Jan 24 08:25:43 2009 From: dannox at gmail.com (whatazor) Date: Sat, 24 Jan 2009 05:25:43 -0800 (PST) Subject: pygccxml xml output file Message-ID: Hi all, I start to use this module in order to produce xml( and the make other things), but differently from gccxml I don't find the variable that set the name of the xml output file after the parsing (in gccxml is - fxml), so it creates temporary files. how can I do an Is there a tutorial that explain with dectails how it works? thank you, regards w From benjamin at python.org Sat Jan 24 08:39:52 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 13:39:52 +0000 (UTC) Subject: Porting 3.0 to 2.6 - from =?utf-8?b?X19mdXR1cmVfXw==?= import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Message-ID: andrew cooke acooke.org> writes: > > Hi, > > I have some 3.0 code, which I would like to make work with 2.6. > However, there does not seem to be support for the new super() (no > args) via __future__. Is that correct? If so, what's the best way to > handle this? Just use the two argument super(): super(MyClass, instance) It's supported in both versions. From kay.schluehr at gmx.net Sat Jan 24 08:49:16 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 05:49:16 -0800 (PST) Subject: What's the business with the asterisk? References: Message-ID: <52d94a37-05cd-459d-946e-6d41ffeeca12@p23g2000prp.googlegroups.com> On 24 Jan., 13:31, mk wrote: > Hello everyone, > > ?From time to time I spot an asterisk (*) used in the Python code > _outside_ the usual *args or **kwargs application. > > E.g. here:http://www.norvig.com/python-lisp.html > > def transpose (m): > ? ?return zip(*m) > ?>>> transpose([[1,2,3], [4,5,6]]) > [(1, 4), (2, 5), (3, 6)] > > What does *m mean in this example and how does it do the magic here? > > Regards, > mk If zip is specified as def zip(*args): ... one can pass zero or more arguments into zip. In the zip body one has access to the argument tuple args. So zip(a, b, c) yields args = (a, b, c). Now suppose you want to pass the tuple t = (a, b, c) to zip. If you call zip(t) then args = ((a, b, c),). When calling zip(*t) instead the tuple is passed as variable arguments just like they are specified in the signature of zip. So args = (a, b, c). Same holds for def foo(**kwd): ... and foo(**kwd) versus foo(kwd). From notvalid2 at sbcglobal.net Sat Jan 24 09:15:05 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 24 Jan 2009 06:15:05 -0800 Subject: What is intvar? In-Reply-To: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: W. eWatson wrote: > r wrote: >> here is a good explanation of control vars: >> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >> >> Here are 3 great Tkinter refernces in order: >> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >> http://effbot.org/tkinterbook/ >> http://www.pythonware.com/library/tkinter/introduction/ > Thanks to all for the reference and tips. > tkinterbook is easy to follow, but it seems to have been abandoned in 2005. Did it appear in another guise somewhere else? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From andrew at acooke.org Sat Jan 24 09:20:43 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 06:20:43 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Message-ID: <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> On Jan 24, 10:39?am, Benjamin Peterson wrote: > andrew cooke acooke.org> writes: > > > > > Hi, > > > I have some 3.0 code, which I would like to make work with 2.6. > > However, there does not seem to be support for the new super() (no > > args) via __future__. ?Is that correct? ?If so, what's the best way to > > handle this? > > Just use the two argument super(): super(MyClass, instance) It's supported in > both versions. Thanks. Any idea how to deal with ABCs? It's sufficient to use a simple class, but I want to expose an ABC in 3.0 as it will make it easier for others to extend. Unfortunately, "metaclass=" is a syntax error in 2.6 so the following still fails: from sys import version if version.startswith('2.'): class Matcher(): pass else: class Matcher(metaclass=ABCMeta): pass Andrew From goon12 at gmail.com Sat Jan 24 09:55:34 2009 From: goon12 at gmail.com (Joe Riopel) Date: Sat, 24 Jan 2009 09:55:34 -0500 Subject: OCaml, Language syntax, and Proof Systems In-Reply-To: References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <6a2ccd190901240655le9aad7cwa04ab5866cd41b6a@mail.gmail.com> On Fri, Jan 23, 2009 at 6:16 PM, Xah Lee wrote: > The haskell tutorials you can find online are the most mothefucking > stupid unreadable fuck. The Haskll community is almost stupid. What > they talk all day is about monads, currying, linder myer fuck type. > That's what they talk about all day. All day and night. Monad! What's > a monad! The importance of monad! How to learn monad! Simple intro to > monad! Fucking morons, but MONAD! http://www.youtube.com/watch?v=9fohXBj2UEI From pataphor at gmail.com Sat Jan 24 10:02:14 2009 From: pataphor at gmail.com (pataphor) Date: Sat, 24 Jan 2009 16:02:14 +0100 Subject: Counter Class -- Bag/Multiset References: Message-ID: <20090124160214.58273d07@hyperspace> On Thu, 22 Jan 2009 10:11:37 -0800 (PST) Raymond Hettinger wrote: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. I like that! Now that we have a multiset or Counter I think a redefinition of itertools.permutations is in order. For example something like this: def genperm(D, R = []): #generate the permutations of a multiset if not max(D.values()): yield tuple(R) else: for k,v in sorted(D.items()): if v: D[k] -= 1 for g in genperm(D,R+[k]): yield g D[k] += 1 def perm(seq): D = {} for x in seq: D[x] = D.get(x,0)+1 for X in genperm(D): yield X def test(): for i,x in enumerate(perm('aabbcc')): print i,x print len(set(perm('aabbcc'))) if __name__ == '__main__': test() The dictionary I'm using here could be seamlessly replaced by your Counter class. By the way, I like your itertools recipes a lot, but I miss something that repeats elements n times, an xcycle or ncycle or whatever, like I used in this (older code, sorry for the name overlap): def repeat(x,n = 0): i = 0 while i < n : yield x i += 1 def xcycle(seq,n): while 1: for x in seq: for y in repeat(x,n): yield y def counter(symbols,width): base = len(symbols) R = [] k = width while k: k -= 1 R.append(xcycle(symbols,base**k)) nc = base**width while nc: yield list(x.next() for x in R) nc -=1 def test(): symbols = '01' width = 4 for state in counter(symbols,width): print state if __name__=='__main__': test() I think such a thing could be handy for generating more kinds of periodic sequences. By the way, itertools is starting to feel like it's becoming some sort of alternate programming design all by itself. I wonder when it is going to break loose from python! I like that way of thinking a lot, thanks. P. From fakeaddress at nowhere.org Sat Jan 24 10:02:50 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 24 Jan 2009 07:02:50 -0800 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: Tobiah wrote: > Where can I read about > this mysterious use of the '*'? Hmmm... that's a harder question than I thought. Am I missing it, or does Python's doc need a write-up of the extended call syntax? > It only works in the > context of the zip() function. It's hard to understand > how the interpreter handles that. It works generally, for any callable. See the doc for 'apply': http://docs.python.org/library/functions.html#non-essential-built-in-functions It not only works in a call, but also in function definitions. You can call a function with the extended call syntax whether or not is defined with * and ** arguments. -- --Bryan From scuzwalla at gmail.com Sat Jan 24 11:14:31 2009 From: scuzwalla at gmail.com (Jerry Gerrone) Date: Sat, 24 Jan 2009 08:14:31 -0800 (PST) Subject: Mathematica 7 compares to other languages References: <13d5dff7-9aac-4385-91ee-d6e58177497f@i24g2000prf.googlegroups.com> <7db0371c-88f8-4984-bb0d-b2078147803e@f40g2000pri.googlegroups.com> <86bf2e29-5f8d-4349-94cf-d1561f0114e6@e1g2000pra.googlegroups.com> <20081204111115.7cee2ecc@usenot.de> <4d86021f-d25c-4b96-b1a2-3a0c162a6154@a26g2000prf.googlegroups.com> Message-ID: On Jan 21, 1:06?pm, "soul.mirr... at gmail.com" wrote: > On Dec 4 2008, 5:11?am, Andreas Waldenburger > wrote: > > I vaguely remember you plonking [Xah Lee] before. Did you unplonk him in > > the meantime? Or was that just a figure of speech? > > > teasingly yours, > > /W > > Andreas Waldenburger, I hold up a mirror to your soul! > > A couple of years ago you started posting to the newsgroup > comp.lang.java.programmer. Unlike most newbies, instead of lurking for > a while and then contributing on-topic posts about Java, you jumped > into the nearest available flamewar and immediately got in up to your > neck. Then, on November 13, 2007, you stooped to intentionally > misquoting one of your opponents. When he wrote > > http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e9... > > A few days later, you did it again, misquoting this post > > http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d41... > > in this one: > > http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b... > > In both cases, you publicly portrayed this poor man as a pervert, even > though, whatever his other [insult deleted], that is clearly not one of > them. None of the nasty things that you have said or implied about me are at all true. > Repeatedly you have claimed to be primarily motivated by finding the > disrupting of newsgroups to be entertaining. This is tantamount to > admitting to being a troll. Yes, and here you are, feeding him. Way to go, genius. (And cljp had just gotten peaceful again, too!) From vincent at vincentdavis.net Sat Jan 24 11:29:28 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 24 Jan 2009 09:29:28 -0700 Subject: understanding nested lists? Message-ID: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> I have a short peace of code that is not doing what I expect. when I assign a value to a list in a list alist[2][4]=z this seems replace all the 4 elements in all the sub lists. I assume it is supposed to but this is not what I expect. How would I assign a value to the 4th element in the 2nd sublist. here is the code I have. All the printed values are what I would expect except that all sublist values are replaced. Thanks for your help Vincent on the first iteration I get ; new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] and expected this; new_list [[None, 0, 1, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] Code; list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] new_list=[[None]*4]*6 print 'new_list',new_list for sublist in range(6): # 6 becuase it is the # of rows lists1 print 'sublist', sublist for x in list1[sublist]: print list1[sublist] print 'new_list[sublist][x]', new_list[sublist][x] new_list[sublist][x]=list1[sublist].index(x) print 'sublist', sublist, 'x', x print new_list[sublist][x] print 'new_list', new_list -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Sat Jan 24 12:08:08 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Sat, 24 Jan 2009 22:38:08 +0530 Subject: String comparision Message-ID: Hi all, I am developing spell checker for my local language(tamil) using python. I need to generate alternative word list for a miss-spelled word from the dictionary of words.The alternatives must be as much as closer to the miss-spelled word.As we know, ordinary string comparison wont work here . Any suggestion for this problem is welcome. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryandw at gmail.com Sat Jan 24 12:17:10 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 24 Jan 2009 09:17:10 -0800 (PST) Subject: practical limits of urlopen() Message-ID: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Hi, Am I going to have problems if I use urlopen() in a loop to get data from 3000+ URLs? There will be about 2KB of data on average at each URL. I will probably run the script about twice per day. Data from each URL will be saved to my database. I'm asking because I've never opened that many URLs before in a loop. I'm just wondering if it will be particularly taxing for my server. Is it very uncommon to get data from so many URLs in a script? I guess search spiders do it, so I should be able to as well? Thank you, Ryan From benjamin at python.org Sat Jan 24 12:32:58 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 17:32:58 +0000 (UTC) Subject: Porting 3.0 to 2.6 - from =?utf-8?b?X19mdXR1cmVfXw==?= import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> Message-ID: andrew cooke acooke.org> writes: > Unfortunately, "metaclass=" is a syntax error in 2.6 so the following > still fails: > > from sys import version > > if version.startswith('2.'): > class Matcher(): > pass > else: > class Matcher(metaclass=ABCMeta): > pass I would suggest that you use the 2.6 syntax, and run "2to3 -f metaclass" on your code. (ABCs have been backported to 2.6.) From steve at holdenweb.com Sat Jan 24 12:40:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:40:45 -0500 Subject: Web authentication urllib2 In-Reply-To: <497B0838.1010002@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> <497B0838.1010002@dreams.sk> Message-ID: Gabriel wrote: > Yep, i realize this a minute after posting, sorry. > > And thank you again .) > A pleasure. Next time, you might consider posting an explanation along with the "it's working now" message, just to give closure to the thread for anyone who ends up reading it later after a search. Good that you got your problem solved, anyway! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From BrianVanderburg2 at aim.com Sat Jan 24 12:42:28 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Sat, 24 Jan 2009 12:42:28 -0500 Subject: understanding nested lists? In-Reply-To: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: <497B5304.9090901@aim.com> vincent at vincentdavis.net wrote: > I have a short peace of code that is not doing what I expect. when I > assign a value to a list in a list alist[2][4]=z this seems replace > all the 4 elements in all the sub lists. I assume it is supposed to > but this is not what I expect. How would I assign a value to the 4th > element in the 2nd sublist. here is the code I have. All the printed > values are what I would expect except that all sublist values are > replaced. > > Thanks for your help > Vincent > > on the first iteration I get ; > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > and expected this; > new_list [[None, 0, 1, None], [None, None, None, None], > [None, None, None, None], [None, None, None, None], [None, None, None, > None], [None, None, None, None]] > > Code; > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > new_list=[[None]*4]*6 > print 'new_list',new_list > for sublist in range(6): # 6 becuase it is the # of rows lists1 > print 'sublist', sublist > for x in list1[sublist]: > print list1[sublist] > print 'new_list[sublist][x]', new_list[sublist][x] > new_list[sublist][x]=list1[sublist].index(x) > print 'sublist', sublist, 'x', x > print new_list[sublist][x] > print 'new_list', new_list > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > The problem is likely this right here: [[None]*4]*6 This first creates an inner list that has 4 Nones, then the outer list contains 6 references to that same list, so (new_list[0] is new_list[1]) and (new_list[1] is new_list[2]). I make this mistake a lot myself. l=[[None]*4]*6 print id(l[0]) # -1210893364 print id(l[1]) # -1210893364 l = [list([None]*4) for x in range(6)] print id(l[0]) # -1210893612 print id(l[1]) # -1210893580 Works better Brian Vanderburg II From steve at holdenweb.com Sat Jan 24 12:46:14 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:46:14 -0500 Subject: understanding nested lists? In-Reply-To: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: Vincent Davis wrote: > I have a short peace of code that is not doing what I expect. when I > assign a value to a list in a list alist[2][4]=z this seems replace all > the 4 elements in all the sub lists. I assume it is supposed to but this > is not what I expect. How would I assign a value to the 4th element in > the 2nd sublist. here is the code I have. All the printed values are > what I would expect except that all sublist values are replaced. > > Thanks for your help > Vincent > > on the first iteration I get ; > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > and expected this; > new_list [[None, 0, 1, None], [None, None, None, None], > [None, None, None, None], [None, None, None, None], [None, None, None, > None], [None, None, None, None]] > > Code; > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > new_list=[[None]*4]*6 > print 'new_list',new_list > for sublist in range(6): # 6 becuase it is the # of rows lists1 > print 'sublist', sublist > for x in list1[sublist]: > print list1[sublist] > print 'new_list[sublist][x]', new_list[sublist][x] > new_list[sublist][x]=list1[sublist].index(x) > print 'sublist', sublist, 'x', x > print new_list[sublist][x] > print 'new_list', new_list > When you create new_list you are actually filling it with six references to the same list. Consequently when you change one of those list elements they all appear to change (because they are all referencing the same list object). Try instead new_list = [[None]*4 for i in range(6)] and you should find your code works as expected. In this case the list is constructed with a new sublist as each element. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 12:50:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:50:28 -0500 Subject: practical limits of urlopen() In-Reply-To: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> References: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Message-ID: webcomm wrote: > Hi, > > Am I going to have problems if I use urlopen() in a loop to get data > from 3000+ URLs? There will be about 2KB of data on average at each > URL. I will probably run the script about twice per day. Data from > each URL will be saved to my database. > > I'm asking because I've never opened that many URLs before in a loop. > I'm just wondering if it will be particularly taxing for my server. > Is it very uncommon to get data from so many URLs in a script? I > guess search spiders do it, so I should be able to as well? > You shouldn't expect problem - though you might want to think about using some more advanced technique like threading to get your results more quickly. This is Python, though. It shouldn't take long to write a test program to verify that you can indeed spider 3,000 pages this way. With about 2KB per page, you could probably build up a memory structure containing the whole content of every page without memory usage becoming too excessive for modern systems. If you are writing stuff out to a database as you go and not retaining page content then there should be no problems whatsoever. Then look at a parallelized solution of some sort if you need it to work more quickly. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Sat Jan 24 12:51:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 09:51:53 -0800 Subject: Two import questions in Python 3.0 In-Reply-To: References: Message-ID: Kay Schluehr wrote: > On 24 Jan., 09:21, "Gabriel Genellina" wrote: >> If you run A.py as a script, it does not "know" it lives inside a package. >> You must *import* A for it to become aware of the package. >> Also, the directory containing the script comes earlier than PYTHONPATH >> entries in sys.path -- so watch for that case too. > Thanks, yes. I always make the same error thinking that a directory > with the ritual __init__ file is actually a package ( as some kind of > platonic entity ), something that is more obvious to me than it is to > the runtime. The relative import semantics introduced with Python 2.5 > has made the error just visible that was hidden to me for about a > decade. Shit. Temper the language a bit. You lose your effectiveness by some people reading the color of your words, rather than their meaning in code. By the way, if you run the script as: $ python -m package.A You may get what you want demo (language fixed up a bit, moe info printed): in .../lib/site-packages: possible.py ------------- print('import from top possible: %s' % __file__) in .../lib/site-packages/package: possible.py ------------- print('import from package.possible: %s' % __file__) __init__.py ------------- print('package initialized: %s' % __file__) A.py ------ print('A started: %s' % __file__) import possible print('A running: %s' % __file__) --Scott David Daniels Scott.Daniels at Acm.Org From mspetrovic at gmail.com Sat Jan 24 13:13:14 2009 From: mspetrovic at gmail.com (Mark.Petrovic) Date: Sat, 24 Jan 2009 10:13:14 -0800 (PST) Subject: Parsing a string into a datetime object Message-ID: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Good day. Might someone comment on why %f is not accepted as a valid field directive in: >>> from datetime import datetime >>> created="2009-01-24 16:04:55.882788" >>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/_strptime.py", line 321, in strptime (bad_directive, format)) ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' This is for Python 2.5.1 under OS X. Thank you. From metolone+gmane at gmail.com Sat Jan 24 13:24:52 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 24 Jan 2009 10:24:52 -0800 Subject: RegEx issues References: Message-ID: "Sean Brown" wrote in message news:glflaj$qrf$2 at nntp.motzarella.org... > Using python 2.4.4 on OpenSolaris 2008.11 > > I have the following string created by opening a url that has the > following string in it: > > td[ct] = [[ ... ]];\r\n > > The ... above is what I'm interested in extracting which is really a > whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>>reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; You are viewing the repr of the string >>> reg='\[\[(.*)\]\];' >>> reg '\\[\\[(.*)\\]\\];' >>> print reg \[\[(.*)\]\]; <== these are the chars passed to regex The slashes are telling regex the the [ are literal. > > Which obviously doesn't match anything because there are no literal \ in > the above string. Leaving the \ out of the \[\[ above has re.compile > throw an error because [ is a special regex character. Which is why it > needs to be escaped in the first place. > > I am either doing something really wrong, which very possible, or I've > missed something obvious. Either way, I thought I'd ask why this isn't > working and why it seems to be changing my regex to something else. Did you try it? >>> s='td[ct] = [[blah blah]];\r\n' >>> re.search(reg,s).group(1) 'blah blah' -Mark From steve at holdenweb.com Sat Jan 24 13:40:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:40:39 -0500 Subject: What is intvar? In-Reply-To: References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: W. eWatson wrote: > W. eWatson wrote: >> r wrote: >>> here is a good explanation of control vars: >>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >>> >>> Here are 3 great Tkinter refernces in order: >>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >>> http://effbot.org/tkinterbook/ >>> http://www.pythonware.com/library/tkinter/introduction/ >> Thanks to all for the reference and tips. >> > tkinterbook is easy to follow, but it seems to have been abandoned in > 2005. Did it appear in another guise somewhere else? > There hasn't been a lot of development on Tkinter in the intervening period. It's a mature system, so there has been no need to update the documentation. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Sat Jan 24 13:41:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 10:41:32 -0800 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: Gabriel wrote: > Yep, i realize this a minute after posting, sorry. > > And thank you again .) > > Steve Holden wrote: >> ... I'll offer a couple of pointers about what we all expect here. Please treat this as advice, not a shout of disapproval. (1) Do not top post (put your response above the previous interaction). (2) When quoting previous interactions, cut until the portion you are quoting provides enough context to make your post's context comprehensible, but only that much context. (3) When you figure out you problem, especially on your own, summarize back in a final message what went wrong and how you fixed it. The reasons for these three rules are: (1) The message can be read in order, rather than reading up and down. (2) People _do_ have access to the previous messages (albeit sometimes only with some effort). The message should be comprehensible on its own, but your reader can go back for more detail if it turns out to be vital. You don't want to grow your message to the point where someone who might help you says, "I don't have time to read that." (3) Generally it is a good idea to search for answers before asking. It can be incredibly frustrating to discover someone else had previously seen exactly the same problem you are bashing your head into the wall about, follow the chain, and finally read, "Never mind, I figured it out." without a clue to what was determined. If you read comp.lang.python for a while, you'll see this is the norm for messages here, and these behaviors help make this a more pleasant place to read and write. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Sat Jan 24 13:46:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:46:50 -0500 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: <497B621A.7030106@holdenweb.com> Bryan Olson wrote: > Tobiah wrote: >> Where can I read about >> this mysterious use of the '*'? > > Hmmm... that's a harder question than I thought. Am I missing it, or > does Python's doc need a write-up of the extended call syntax? > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 documentation index it lists only two references. The first is the language manual's explanation of its use in the def statement, the second is a transitory reference to its use in function calls, but that's in the tutorial where it is not likely to get much attention. >> It only works in the >> context of the zip() function. It's hard to understand >> how the interpreter handles that. > > It works generally, for any callable. See the doc for 'apply': > > http://docs.python.org/library/functions.html#non-essential-built-in-functions > > > It not only works in a call, but also in function definitions. You can > call a function with the extended call syntax whether or not is defined > with * and ** arguments. > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 13:46:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:46:50 -0500 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: <497B621A.7030106@holdenweb.com> Bryan Olson wrote: > Tobiah wrote: >> Where can I read about >> this mysterious use of the '*'? > > Hmmm... that's a harder question than I thought. Am I missing it, or > does Python's doc need a write-up of the extended call syntax? > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 documentation index it lists only two references. The first is the language manual's explanation of its use in the def statement, the second is a transitory reference to its use in function calls, but that's in the tutorial where it is not likely to get much attention. >> It only works in the >> context of the zip() function. It's hard to understand >> how the interpreter handles that. > > It works generally, for any callable. See the doc for 'apply': > > http://docs.python.org/library/functions.html#non-essential-built-in-functions > > > It not only works in a call, but also in function definitions. You can > call a function with the extended call syntax whether or not is defined > with * and ** arguments. > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 13:50:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:50:03 -0500 Subject: RegEx issues In-Reply-To: References: Message-ID: Mark Tolonen wrote: > > "Sean Brown" wrote in message > news:glflaj$qrf$2 at nntp.motzarella.org... >> Using python 2.4.4 on OpenSolaris 2008.11 >> >> I have the following string created by opening a url that has the >> following string in it: >> >> td[ct] = [[ ... ]];\r\n >> >> The ... above is what I'm interested in extracting which is really a >> whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. >> The problem is it appears that python is escaping the \ in the regex >> because I see this: >>>>> reg = '\[\[(.*)\]\];' >>>>> reg >> '\\[\\[(.*)\\]\\];' >> >> Now to me looks like it would match the string - \[\[ ... \]\]; > > You are viewing the repr of the string > >>>> reg='\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' >>>> print reg > \[\[(.*)\]\]; <== these are the chars passed to regex > > The slashes are telling regex the the [ are literal. > >> >> Which obviously doesn't match anything because there are no literal \ in >> the above string. Leaving the \ out of the \[\[ above has re.compile >> throw an error because [ is a special regex character. Which is why it >> needs to be escaped in the first place. >> >> I am either doing something really wrong, which very possible, or I've >> missed something obvious. Either way, I thought I'd ask why this isn't >> working and why it seems to be changing my regex to something else. > > Did you try it? > >>>> s='td[ct] = [[blah blah]];\r\n' >>>> re.search(reg,s).group(1) > 'blah blah' > Beware, though, that by default regex matches are greedy, so if there's a chance that two [[ ... ]] [[ ... ]] can appear on the same line then the above pattern will match ... ]] [[ ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Sat Jan 24 13:50:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 18:50:04 +0000 Subject: Parsing a string into a datetime object In-Reply-To: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Message-ID: <497B62DC.7000108@mrabarnett.plus.com> Mark.Petrovic wrote: > Good day. > > Might someone comment on why %f is not accepted as a valid field > directive in: > >>>> from datetime import datetime >>>> created="2009-01-24 16:04:55.882788" >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > Traceback (most recent call last): > File "", line 1, in > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/_strptime.py", line 321, in strptime > (bad_directive, format)) > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > This is for Python 2.5.1 under OS X. > > Thank you. > I believe that Python simply uses the 'strptime' (or equivalent) function in the underlying C library: if that doesn't accept %f then neither does Python. From ra.ravi.rav at gmail.com Sat Jan 24 13:55:30 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 24 Jan 2009 10:55:30 -0800 (PST) Subject: Byte oriented data types in python Message-ID: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> I have following packet format which I have to send over Bluetooth. packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || packet_data(variable) How to construct these using python data types, as int and float have no limits and their sizes are not well defined. From roy at panix.com Sat Jan 24 13:55:48 2009 From: roy at panix.com (Roy Smith) Date: Sat, 24 Jan 2009 13:55:48 -0500 Subject: RegEx issues References: Message-ID: Sean Brown wrote: > The problem is it appears that python is escaping the \ in the regex > because I see this: > >>>reg = '\[\[(.*)\]\];' The first trick of working with regexes in Python is to *always* use raw strings. Instead of reg = '\[\[(.*)\]\];' you want reg = r'\[\[(.*)\]\];' In this case, I think it ends up not mattering, but it's one less thing to worry about. Next, when looking at something like > >>> reg > '\\[\\[(.*)\\]\\];' it's hard to see exactly what all the backslashes mean. Which are real and which are escapes? Try doing >>> print reg \[\[(.*)\]\]; which gets you the str(reg) instead of repr(reg). Another trick when you're not 100% what you're looking at is to explode the string like this: >>> [c for c in reg] ['\\', '[', '\\', '[', '(', '.', '*', ')', '\\', ']', '\\', ']', ';'] From hniksic at xemacs.org Sat Jan 24 13:56:28 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 24 Jan 2009 19:56:28 +0100 Subject: Parsing a string into a datetime object References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Message-ID: <877i4kfs83.fsf@mulj.homelinux.net> "Mark.Petrovic" writes: > Might someone comment on why %f is not accepted as a valid field > directive in: > >>>> from datetime import datetime >>>> created="2009-01-24 16:04:55.882788" >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > Traceback (most recent call last): > File "", line 1, in > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/_strptime.py", line 321, in strptime > (bad_directive, format)) > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > This is for Python 2.5.1 under OS X. time.strptime is documented to use the same set of directives as time.strftime, and http://docs.python.org/library/time.html#time.strftime doesn't mention a %f directive. From andrew at acooke.org Sat Jan 24 13:58:18 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 10:58:18 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> Message-ID: On Jan 24, 2:32?pm, Benjamin Peterson wrote: > I would suggest that you use the 2.6 syntax, and run "2to3 -f metaclass" on your > code. (ABCs have been backported to 2.6.) Thanks - with that hint I found this - http://mikewatkins.ca/2008/11/29/python-2-and-3-metaclasses/#using-the-metaclass-in-python-2-x-and-3-x Andrew From Scott.Daniels at Acm.Org Sat Jan 24 13:59:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 10:59:44 -0800 Subject: RegEx issues In-Reply-To: References: Message-ID: Sean Brown wrote: > I have the following string ...: "td[ct] = [[ ... ]];\r\n" > The ... (representing text in the string) is what I'm extracting .... > So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>> reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > Now to me looks like it would match the string - \[\[ ... \]\]; > ... OK, you already have a good answer as to what is happening. I'll mention that raw strings were put in the language exactly for regex work. They are useful for any time you need to use the backslash character (\) within a string (but not as the final character). For example: len(r'\a\b\c\d\e\f\g\h') == 16 and len('\a\b\c\d\e\f\g\h') == 13 If you get in the habit of typing regex strings as r'...' or r"...", and examining the patters with print(somestring), you'll ease your life. --Scott David Daniels Scott.Daniels at Acm.Org From jay.amorin at gmail.com Sat Jan 24 14:03:33 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Sun, 25 Jan 2009 03:03:33 +0800 Subject: TEST=`which test` equivalent in python? Message-ID: Hi, Kindly help. import sys, os, string *SVNLOOK_PATH=os.system('which svnlook')* def main(repos, txn): svnlook_cmd = '%s log -t "%s" "%s"' % (*SVNLOOK_PATH*, txn, repos) check_msg = os.popen(svnlook_cmd, 'r').readline().rstrip('\n') if len(check_msg) < 10: sys.stderr.write ("Blahh Blahh....\n") sys.exit(1) else: sys.exit(0) if __name__ == '__main__': if len(sys.argv) < 3: sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) else: main(sys.argv[1], sys.argv[2]) The SVNLOOK_PATH is not working and python says its null when run as SVN hook-script. Do I need to load the os environment variable? How do i pass the value of 'which svnlook' to SVNLOOK_PATH variable. Thanks for your help. Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Sat Jan 24 14:07:32 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 24 Jan 2009 11:07:32 -0800 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <7a9c25c20901241107y58799496xa7454c41b44057cc@mail.gmail.com> I have following packet format which I have to send over Bluetooth. > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > packet_data(variable) > > How to construct these using python data types, as int and float have > no limits and their sizes are not well defined. Check out the struct module. You want something like: data = struct.pack("BB4s", 1, 4, "this") It returns a string of bytes according to the specification -- B is unsigned byte, and "4s" is a string of 4 characters. The 1 feeds into the first byte, the 4 into the second, etc. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Sat Jan 24 14:14:36 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 14:14:36 -0500 Subject: TEST=`which test` equivalent in python? In-Reply-To: References: Message-ID: On Sat, Jan 24, 2009 at 2:03 PM, Jay Jesus Amorin wrote: > Hi, > > Kindly help. > > import sys, os, string > > *SVNLOOK_PATH=os.system('which svnlook')* Read the docs on os.system. It returns the program's return code, not the child processes stdout. Use the subprocess module. > > > def main(repos, txn): > svnlook_cmd = '%s log -t "%s" "%s"' % (*SVNLOOK_PATH*, txn, repos) > check_msg = os.popen(svnlook_cmd, 'r').readline().rstrip('\n') os.popen does what you want here, but it is deprecated in favor of the more powerful subprocess module. > > > if len(check_msg) < 10: > sys.stderr.write ("Blahh Blahh....\n") > sys.exit(1) > else: > sys.exit(0) > > if __name__ == '__main__': > if len(sys.argv) < 3: > sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) > else: > main(sys.argv[1], sys.argv[2]) > > > The SVNLOOK_PATH is not working and python says its null when run as SVN > hook-script. Do I need to load the os environment variable? How do i pass > the value of 'which svnlook' to SVNLOOK_PATH variable. > > Thanks for your help. > > > Jay > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sat Jan 24 14:37:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 19:37:07 +0000 Subject: RegEx issues In-Reply-To: References: Message-ID: <497B6DE3.1020903@mrabarnett.plus.com> Roy Smith wrote: [snip] > Another trick when you're not 100% what you're looking at is to > explode the string like this: > >>>> [c for c in reg] > ['\\', '[', '\\', '[', '(', '.', '*', ')', '\\', ']', '\\', ']', ';'] > A shorter way is list(reg). From ppearson at nowhere.invalid Sat Jan 24 14:43:54 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 24 Jan 2009 19:43:54 GMT Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> <6tua0tFcpeeqU1@mid.individual.net> Message-ID: <6u19bqFcqhpoU1@mid.individual.net> On Fri, 23 Jan 2009 14:55:36 -0200, Gabriel Genellina wrote: > En Fri, 23 Jan 2009 14:36:46 -0200, Peter Pearson > escribi?: >> On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: >>> En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson >>> escribi?: >>> >>>> The following code uses ossaudiodev to read 1000 values from >>>> my sound card at a rate of 12,000 samples per second: >>>> >>>> When I select a sample rate that is not a power of 2 times >>>> 3000 samples/second, a strong and very regular sawtooth is >>>> superimposed on the signal. At some sampling frequencies, >>>> it appears as a rising sawtooth, and at other sampling >>>> frequencies it is a declining sawtooth, so I'm presumably >>>> lost in some aliasing wilderness. As best I can tell, >>>> it's a 48 KHz sawtooth. >>> >>> That could be a hardware and/or driver limitation. By example, an >>> AC97-compliant chipset may provide a fixed rate of 48000 samples/second >>> any sample rate conversion must be done by other means, if possible at >>> all. >> >> Oh! As a matter of fact, my "soundcard" *is* AC97-compliant >> ("VT8233/A/8235/8237", according to Sysinfo). So . . . this >> sawtooth might result from some software, somewhere in the bucket >> brigade between me and the hardware, attempting to perform >> sample-rate conversion? The 48 KHz coincidence seems very >> significant. > > Yep. Google found this for me: > http://mail-index.netbsd.org/port-i386/2003/02/18/0003.html > > Using a sample rate that is a sub-multiple of 48000 is perhaps a safe > approach. Back around the time I installed Ubuntu's Hardy Heron, several copies of this line appeared in /var/log/user.log.0: Jan 4 21:32:53 eleodes pulseaudio[6437]: alsa-util.c: \ Device front:0 doesn't support 44100 Hz, changed to 48000 Hz. So I suppose I'll just restrict myself to well-behaved frequencies. I'm not sure what "sub-multiple" means, but all the successful frequencies I've found over 1 KHz have been multiples of 1.5 KHz that evenly divide 48 KHz. Frequencies showing large sawtooths include 2, 4, 8, 10, and 16 KHz. -- To email me, substitute nowhere->spamcop, invalid->net. From martin at v.loewis.de Sat Jan 24 14:52:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 24 Jan 2009 20:52:15 +0100 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <497b716f$0$27773$9b622d9e@news.freenet.de> > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > packet_data(variable) > > How to construct these using python data types, as int and float have > no limits and their sizes are not well defined. In Python 2.x, use the regular string type: chr(n) will create a single byte, and the + operator will do the concatenation. In Python 3.x, use the bytes type (bytes() instead of chr()). Regards, Martin From skip at pobox.com Sat Jan 24 14:55:13 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 24 Jan 2009 13:55:13 -0600 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <18811.29217.214331.59397@montanaro.dyndns.org> Ravi> packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || Ravi> packet_data(variable) Ravi> How to construct these using python data types, as int and float have Ravi> no limits and their sizes are not well defined. Take a look at the struct and ctypes modules. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From googler.1.webmaster at spamgourmet.com Sat Jan 24 14:57:45 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 24 Jan 2009 11:57:45 -0800 (PST) Subject: MaxInt on Vista-64bit? Message-ID: Hi! I downloaded Python64 for Windows Vista64 but the value returned from sys.maxint is just a 32bit integer. I found out, thats by design, Microsoft decided to make the long value 32bit. What can I do to compile python 2.6 with maxint of 64bit integers? Can I replace the int values to a int64 value? Thanks a lot! From vincent at vincentdavis.net Sat Jan 24 15:02:25 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 24 Jan 2009 13:02:25 -0700 Subject: understanding nested lists? In-Reply-To: References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: <77e831100901241202w59a63d48q7b18341ab5c65d22@mail.gmail.com> Thanks for the info. I did not know that. Thanks Vincent Davis On Sat, Jan 24, 2009 at 10:46 AM, Steve Holden wrote: > Vincent Davis wrote: > > I have a short peace of code that is not doing what I expect. when I > > assign a value to a list in a list alist[2][4]=z this seems replace all > > the 4 elements in all the sub lists. I assume it is supposed to but this > > is not what I expect. How would I assign a value to the 4th element in > > the 2nd sublist. here is the code I have. All the printed values are > > what I would expect except that all sublist values are replaced. > > > > Thanks for your help > > Vincent > > > > on the first iteration I get ; > > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > > > and expected this; > > new_list [[None, 0, 1, None], [None, None, None, None], > > [None, None, None, None], [None, None, None, None], [None, None, None, > > None], [None, None, None, None]] > > > > Code; > > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > > new_list=[[None]*4]*6 > > print 'new_list',new_list > > for sublist in range(6): # 6 becuase it is the # of rows lists1 > > print 'sublist', sublist > > for x in list1[sublist]: > > print list1[sublist] > > print 'new_list[sublist][x]', new_list[sublist][x] > > new_list[sublist][x]=list1[sublist].index(x) > > print 'sublist', sublist, 'x', x > > print new_list[sublist][x] > > print 'new_list', new_list > > > When you create new_list you are actually filling it with six references > to the same list. Consequently when you change one of those list > elements they all appear to change (because they are all referencing the > same list object). > > Try instead > > new_list = [[None]*4 for i in range(6)] > > and you should find your code works as expected. In this case the list > is constructed with a new sublist as each element. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Jan 24 15:05:22 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:05:22 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: <3e6cef22-7126-419b-ad54-0b5018bb2164@w24g2000prd.googlegroups.com> On Jan 24, 12:40?am, "Gabriel Genellina" wrote: > En Sat, 24 Jan 2009 06:06:02 -0200, Carl Banks ? > escribi?: > > > > > On Jan 23, 11:45?pm, Bryan Olson wrote: > >> Carl Banks wrote: > >> > Classes in Python are mutable types, usually. ?Class instances are > >> > (except for the refcount) immutable objects, usually. > > >> There's where we disagree. I assert that class instances are usually > >> mutable objects. > > > Nope, you're dead wrong, nothing more to it. ?The bits of a class > > instance never change. ?The __dict__ is a mutable object. ?The class > > instance itself isn't. ?It's not reasonable to call an object whose > > bits can't change a mutable obect. > > > Anyway, all you're doing is distracting attention from my claim that > > instance objects wouldn't need to be locked. ?They wouldn't, no matter > > how mutable you insist these objects whose bits would never change > > are. > > Me too, I don't get what you mean. Consider a list instance, it contains a ? > count of allocated elements, and a pointer to some memory block. They ? > change when the list is resized. This counts as "mutable" to me. I really ? > don't understand your claim. Yeah, yeah, I know that, and in the bickering that ensued some aspects of the original context were lost. I should really not have been pulled into Bryan's strawman over the definition of immutable, since it's just a label, I oughtn't give a damn what it's called, I only care what it does. I didn't handle this repartee very well. Anyway, it goes back to the original vision for a mark-and-sweep Python language as I presented what seems like a long time ago. I presented the type system that had three base metatypes instead of the one base metatype we have now: immutable_type, mutable_type, and mutable_dict_type. The default metatype for Python classes would be mutable_dict_type, which is a type wherein the object itself would be mutable but it would still have all the mutator methods __init__, __setattr__, etc., but they could only act on the __dict__. mutable_dict_types would not be allowed to define any slots, and __dict__ wouldn't be reassignable. (However, it seems reasonable to allow the base tp_new to accept a dict argument.) OTOTH, list's metatype would be mutable_type, so the type object itself would be mutable. Bryan claimed that that would be a very different language from Python, apparently because it hadn't occurred to him that by-and- large, the instance itself doesn't change, only the dict does. Perhaps Bryan was thinking of __dict__'s reassignability (that certainly didn't occur to me); if he was I apologize for my snideness. HAVING SAID THAT, I still still say what I proposed would not be a radically different language from Python. A little different, of course. Much slower, almost certainly. Carl Banks From martin at v.loewis.de Sat Jan 24 15:06:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 24 Jan 2009 21:06:39 +0100 Subject: MaxInt on Vista-64bit? In-Reply-To: References: Message-ID: <497b74d0$0$10443$9b622d9e@news.freenet.de> > I downloaded Python64 for Windows Vista64 but the value returned from > sys.maxint is just a 32bit integer. I found out, thats by design, > Microsoft decided to make the long value 32bit. What can I do to > compile python 2.6 with maxint of 64bit integers? At a minimum, you need to change ob_ival to a 64-bit type in PyIntObject. Consequentially, you probably need to change a lot of other functions, e.g. PyInt_AsLong should probably also return a 64-bit integer (as should PyInt_FromLong accept one). In turn, you will need to change all callers of these functions to adjust their parameter types. And so on. > Can I replace the int values to a int64 value? See above. In short: no. Use a real 64-bit operating system (such as 64-bit Linux, Solaris, FreeBSD, etc) Regards, Martin P.S. I do wonder why you want to do this, though. Isn't Python's long integer type good enough? From googler.1.webmaster at spamgourmet.com Sat Jan 24 15:10:17 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 24 Jan 2009 12:10:17 -0800 (PST) Subject: MaxInt on Vista-64bit? References: <497b74d0$0$10443$9b622d9e@news.freenet.de> Message-ID: Hi! Thanks for the fast answer. Yes, its enough but I never thought that Vista64 is not a real 64-bit operating system :-o. From google at mrabarnett.plus.com Sat Jan 24 15:23:51 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 20:23:51 +0000 Subject: Regex for Python 2.7 Message-ID: <497B78D7.4040808@mrabarnett.plus.com> Some time ago I discovered this difference between regular expressions in Python and Perl: Python \A matches at start of string \Z matches at end of string Perl \A matches at start of string \Z matches before terminal newline or at end of string \z matches at end of string In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ and \Z != $ in single-string mode. Obviously, changing Python's \Z to match Perl's could break existing code. \z could be added, but with the opposite meaning to Perl's: Python's \Z == Perl's \z Python's \z == Perl's \Z Would that be confusing? Any suggests welcome. From pavlovevidence at gmail.com Sat Jan 24 15:24:49 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:24:49 -0800 (PST) Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <87hc3pf6h5.fsf@mulj.homelinux.net> Message-ID: On Jan 24, 12:33?am, Hrvoje Niksic wrote: > Carl Banks writes: > > Anyway, all you're doing is distracting attention from my claim that > > instance objects wouldn't need to be locked. ?They wouldn't, no > > matter how mutable you insist these objects whose bits would never > > change are. > > Only if you're not implementing Python, but another language that > doesn't support __slots__ and assignment to instance.__dict__. I am only going to say all Python types prior to 3.0 support classes without __slots__, so while I agree that this would be a different language, it wouldn't necessarily be "not Python". (Python, of course, is what GvR says Python is, and he isn't going to say that the language I presented is Python. No worries there! :) I'm only saying that it is conceivably similar enough to be a different version of Python. It would be a different language in the same way that Python 2.6 is a different language from Python 3.0.) Incidentally, the proposal does allow slots to be defined, but only for actual mutable types, not for ordinary class instances. Carl Banks From pavlovevidence at gmail.com Sat Jan 24 15:27:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:27:32 -0800 (PST) Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <87hc3pf6h5.fsf@mulj.homelinux.net> Message-ID: <63eb1ce8-526f-45a9-b0b1-103dbb47b8e0@b38g2000prf.googlegroups.com> On Jan 24, 12:24?pm, Carl Banks wrote: > On Jan 24, 12:33?am, Hrvoje Niksic wrote: > > > Carl Banks writes: > > > Anyway, all you're doing is distracting attention from my claim that > > > instance objects wouldn't need to be locked. ?They wouldn't, no > > > matter how mutable you insist these objects whose bits would never > > > change are. > > > Only if you're not implementing Python, but another language that > > doesn't support __slots__ and assignment to instance.__dict__. > > I am only going to say all Python types prior to 3.0 support classes > without __slots__, I made a mistake, and I don't want to risk confusion at this point. "all Python ***versions** prior to 3.0" and I am talking about old-style classes, of course. Prior to 2.2 no classes at all supported slots. Carl Banks From pavlovevidence at gmail.com Sat Jan 24 15:32:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:32:00 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <3e6cef22-7126-419b-ad54-0b5018bb2164@w24g2000prd.googlegroups.com> Message-ID: On Jan 24, 12:05?pm, Carl Banks wrote: > The default metatype for Python classes would be > mutable_dict_type, which is a type wherein the object itself would be > mutable but it would still have all the mutator methods __init__, > __setattr__, etc., but they could only act on the __dict__. Not wanting to risk confusion. "The default metatype for Python classes would be mutable_dict_type, which is a type wherein the object itself would be ***immutable*** but it would still have all the mutator methods __init__, __setattr__, etc., but they could only act on the __dict__." Carl Banks From sbrown.home at [spammy]gmail.com Sat Jan 24 16:03:26 2009 From: sbrown.home at [spammy]gmail.com (Sean Brown) Date: Sat, 24 Jan 2009 13:03:26 -0800 Subject: RegEx issues Message-ID: Using python 2.4.4 on OpenSolaris 2008.11 I have the following string created by opening a url that has the following string in it: td[ct] = [[ ... ]];\r\n The ... above is what I'm interested in extracting which is really a whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. The problem is it appears that python is escaping the \ in the regex because I see this: >>>reg = '\[\[(.*)\]\];' >>> reg '\\[\\[(.*)\\]\\];' Now to me looks like it would match the string - \[\[ ... \]\]; Which obviously doesn't match anything because there are no literal \ in the above string. Leaving the \ out of the \[\[ above has re.compile throw an error because [ is a special regex character. Which is why it needs to be escaped in the first place. I am either doing something really wrong, which very possible, or I've missed something obvious. Either way, I thought I'd ask why this isn't working and why it seems to be changing my regex to something else. From torriem at gmail.com Sat Jan 24 16:23:10 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 24 Jan 2009 14:23:10 -0700 Subject: Dynamic methods and lambda functions In-Reply-To: References: Message-ID: <497B86BE.7010209@gmail.com> unineuro at gmail.com wrote: > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? Basically, don't use a lambda. Create a real, local closure with a nested def block. That way the closure is created every time the parent function is called. Lambda expressions are only ever compiled once during execution. From gh at ghaering.de Sat Jan 24 16:27:03 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 24 Jan 2009 22:27:03 +0100 Subject: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? In-Reply-To: References: Message-ID: <6u1fd6Fd2ef0U1@mid.uni-berlin.de> Casey Hawthorne wrote: > Is there anyway Vpython and pyODE can be made to work with newer > versions of Python 2.6.1 etc. without a lot of changes to source code? > > I suppose I'm thinking of an extra layer of indirection, which might > slow things down to much. Aren't this just Python libraries that include extension modules (i. e. modules written in C to interface external C libraries). If so, there is a good chance that just compiling them against Python 2.6 works out of the box. Otherwise the adjustments necessary will be just minor ones. Python 3.0 compatibility is a different issue, though (more work). -- Gerhard From python at bdurham.com Sat Jan 24 17:31:14 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 17:31:14 -0500 Subject: Possible to slice a string with unpacked tuple? Message-ID: <1232836274.23361.1296561633@webmail.messagingengine.com> Is there a way to slice a string with a tuple without unpacking the tuple? >>> myString = "111-222-333-444" >>> myString[ 4: 7 ] '222' Is there some way I could perform an identical slicing operation with a tuple like ( 4, 7 ) without having to unpack the tuple? >>> myTuple = ( 4, 7 ) Thanks! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Jan 24 17:35:13 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 24 Jan 2009 22:35:13 +0000 (UTC) Subject: I'm a python addict ! References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > I just started using python last week and I'm addicted. you need to try this: import antigravity http://xkcd.com/353/ From benjamin.kaplan at case.edu Sat Jan 24 17:47:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 17:47:43 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <1232836274.23361.1296561633@webmail.messagingengine.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: On Sat, Jan 24, 2009 at 5:31 PM, wrote: > Is there a way to slice a string with a tuple without unpacking the tuple? > > >>> myString = "111-222-333-444" > >>> myString[ 4: 7 ] > '222' > > Is there some way I could perform an identical slicing operation with a > tuple like ( 4, 7 ) without having to unpack the tuple? > > >>> myTuple = ( 4, 7 ) > > Thanks! > Malcolm > 1) What's wrong with unpacking the tuple? 2) Use the built-in slice. >>> myString = "111-222-333-444" >>> myTuple = (4,7) >>> mySlice = slice(*myTuple) >>> myString[mySlice] '222' -------------- next part -------------- An HTML attachment was scrubbed... URL: From xahlee at gmail.com Sat Jan 24 17:48:53 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 14:48:53 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: Just a quick relpy. Jon's tutorial: http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html is by far the best tutorial of Ocaml. It is far better than the official intro to ocaml at ?caml.inria.fr? or the popularly cited tutorial at ?ocaml-tutorial.org? . Jon's tutorial, namely the free chapter 1 of his book, is concise, to the point, well written, well organized, does not unnecessarily use abstruse jargons or concepts, does not pitch or preach engineering practices or paradigms. Jon's book title says it all: Ocaml for Scientist. Scientists are intelligent. All programing language tutorials should be modeled like this. For some detail, see: ? Examples Of Quality Documentation In The Computing Industry http://xahlee.org/perl-python/quality_docs.html Btw, i've learned far more Ocaml in the past 3 days than the about 1 month of full time trying to learn Haskell. Mostly in 2006 or 2007. I did not even obtain a basic understanding of the syntax. I do not have a basic understanding of its types or how to define a type (was quite confused in this). I don't even have a good idea what the lang's syntactical elements or structural elements or semantic elements. In fact, i have no basic understanding of the language. I tried. I tried about 4 online tutorials or downloadable paper-published books. They are extremely low quality and or idiotic. Half of the time is wasted on finding a good tutorial or reading unreadable ones, and time is spent on huge garbage texts about reading why haskell is better or currying this or monads that (they idiots lacking mathematician's perspicacity don't really understand the subject). Motherfucking idiots. (i even tried to start a mailing list and drew a web-badge for haskell by my enthusiasm. See: A Haskell A Day http://xahlee.org/haskell/haskell.html (it went no where and is now on hold indefinitely)) I really believed in Haskell, almost just by its ?we don't allow assignments and we have ?lazy evaluation??. I believed it for 10 years. No more. Jon wrote: > And the freely-available first chapter of The OCaml Journal: > > http://www.ffconsultancy.com/products/ocaml_journal/free/introduction... > > I also recommend Jason Hickey's book which, I believe, is due to be > published by Cambridge University Press soon: > > http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf Thanks. Am still reading your chapter 1 yet. Will check those out later. Xah ? http://xahlee.org/ ? On Jan 23, 4:36 pm, Jon Harrop wrote: > Xah Lee wrote: > > ok, i've been reading these Ocaml tutorials in the past few days: > > > intro to ocaml, from official site > > http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html > > > ?Objective CAML Tutorial?, most cited tutorial on the web > > http://www.ocaml-tutorial.org/ > > > The best one, is the one is > > ?Introduction to Caml? > > http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html > > by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. > > I found it by as one of the top result from google search. > > You may also appreciate the freely-available first chapter of my book OCaml > for Scientists: > > http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > > And the freely-available first chapter of The OCaml Journal: > > http://www.ffconsultancy.com/products/ocaml_journal/free/introduction... > > I also recommend Jason Hickey's book which, I believe, is due to be > published by Cambridge University Press soon: > > http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u From benjamin.kaplan at case.edu Sat Jan 24 17:51:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 17:51:30 -0500 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan wrote: > On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > > > I just started using python last week and I'm addicted. > > you need to try this: > > import antigravity > > http://xkcd.com/353/ > Just be careful with that. That guy was still floating 129 comics later (3 comics = 1 week). And still going "Woo Python". You can see him floating near the peak of Mt. Everest. http://xkcd.com/482/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sat Jan 24 17:52:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 22:52:19 +0000 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <1232836274.23361.1296561633@webmail.messagingengine.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: <497B9BA3.7080808@mrabarnett.plus.com> python at bdurham.com wrote: > Is there a way to slice a string with a tuple without unpacking the tuple? > > >>> myString = "111-222-333-444" > >>> myString[ 4: 7 ] > '222' > > Is there some way I could perform an identical slicing operation with a > tuple like ( 4, 7 ) without having to unpack the tuple? > > >>> myTuple = ( 4, 7 ) > > Thanks! > Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, then how about myString.__getslice__(*myTuple)? From python at bdurham.com Sat Jan 24 17:59:14 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 17:59:14 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: <1232837954.28046.1296565169@webmail.messagingengine.com> Benjamin, > Use the built-in slice. Perfect!! That's exactly what I was looking for - I didn't know this object existed. > What's wrong with unpacking the tuple? I'm extracting fields from a huge, multi-gig log file. I was trying to avoid doing something like myString[ myTuple[ 0 ]: myTuple[ 1 ] ) millions of times in a loop. Thank you! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From oktaysafak at superonline.com Sat Jan 24 18:00:27 2009 From: oktaysafak at superonline.com (oktaysafak at superonline.com) Date: Sun, 25 Jan 2009 01:00:27 +0200 (EET) Subject: Is (-1 ==True) True or False? Neither Message-ID: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> An HTML attachment was scrubbed... URL: From python at bdurham.com Sat Jan 24 18:06:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 18:06:15 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <497B9BA3.7080808@mrabarnett.plus.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: <1232838375.29456.1296566219@webmail.messagingengine.com> MRAB, > Does myString[myTuple[0] : myTuple[1]] count as unpacking? I'm not sure my use of the term 'unpacking' was totally correct, but, yes, that's what I was hoping to avoid with a simpler solution. > then how about myString.__getslice__(*myTuple)? Very interesting. I'm going to try Ben's slice() object suggestion. Thanks for your help, Malcolm From gagsl-py2 at yahoo.com.ar Sat Jan 24 18:13:15 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 21:13:15 -0200 Subject: TEST=`which test` equivalent in python? References: Message-ID: En Sat, 24 Jan 2009 17:03:33 -0200, Jay Jesus Amorin escribi?: > *SVNLOOK_PATH=os.system('which svnlook')* You've been told what's wrong with that. But instead of fixing how to invoke "which", use distutils.spawn.find_executable instead: py> from distutils.spawn import find_executable py> find_executable('svnlook') 'c:\\apps\\svn\\bin\\svnlook.exe' -- Gabriel Genellina From cosmo_general at yahoo.com Sat Jan 24 18:14:49 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Sat, 24 Jan 2009 15:14:49 -0800 (PST) Subject: Can webbrowser module get source code? Message-ID: Hi All, I played the demo of webbrowser module, with the code below: import webbrowser url = 'https://login.yahoo.com' webbrowser.open_new_tab(url) when I ran the code, it popped out a webpage nicely. I want to go further: to get the source code of the webpage being displayed. Is it possible to do it? I tried webbrow.get() but didn't work. Somebody can help? Thanks! Muddy Coder From stef.mientki at gmail.com Sat Jan 24 18:23:35 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 25 Jan 2009 00:23:35 +0100 Subject: why is this invalid b = a += b ? Message-ID: <497BA2F7.3040100@gmail.com> hello, I can assign a value to more than 1 variable (name) in one line: a = b = 3 So evaluation of this line must start at the right part. But the following is not allowed: b = 2 a = b += 1 I would think that if b has a value, and the formula is evaluated from right to left, there's nothing wrong with the above formula. thanks Stef Mientki From gagsl-py2 at yahoo.com.ar Sat Jan 24 18:23:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 21:23:44 -0200 Subject: Regex for Python 2.7 References: <497B78D7.4040808@mrabarnett.plus.com> Message-ID: En Sat, 24 Jan 2009 18:23:51 -0200, MRAB escribi?: > Some time ago I discovered this difference between regular expressions > in Python and Perl: > > Python > > \A matches at start of string > \Z matches at end of string > > Perl > > \A matches at start of string > \Z matches before terminal newline or at end of string > \z matches at end of string > > In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ > and \Z != $ in single-string mode. Why do you want the two to be equivalent? Isn't a good thing that you have both alternatives (\Z and $)? Use whichever is adequate in each case. -- Gabriel Genellina From tjreedy at udel.edu Sat Jan 24 18:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 18:35:16 -0500 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: Benjamin Kaplan wrote: > > > On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan > wrote: > > On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > > > I just started using python last week and I'm addicted. > > you need to try this: > > import antigravity > > http://xkcd.com/353/ > > > Just be careful with that. That guy was still floating 129 comics later > (3 comics = 1 week). And still going "Woo Python". You can see him > floating near the peak of Mt. Everest. > > http://xkcd.com/482/ For a Python 'program', see http://xkcd.com/534/ From google at mrabarnett.plus.com Sat Jan 24 18:36:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:36:55 +0000 Subject: why is this invalid b = a += b ? In-Reply-To: <497BA2F7.3040100@gmail.com> References: <497BA2F7.3040100@gmail.com> Message-ID: <497BA617.7020108@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I can assign a value to more than 1 variable (name) in one line: > > a = b = 3 > > So evaluation of this line must start at the right part. > > But the following is not allowed: > > b = 2 > a = b += 1 > > I would think that if b has a value, and the formula is evaluated > from right to left, there's nothing wrong with the above formula. > Assignment is a statement, not an expression. That's why: if a = 0: ... is illegal. However, simple serial assignment such as: a = b = 3 is useful enough to be supported as a special case. From google at mrabarnett.plus.com Sat Jan 24 18:51:31 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:51:31 +0000 Subject: Regex for Python 2.7 In-Reply-To: References: <497B78D7.4040808@mrabarnett.plus.com> Message-ID: <497BA983.6010903@mrabarnett.plus.com> Gabriel Genellina wrote: > En Sat, 24 Jan 2009 18:23:51 -0200, MRAB > escribi?: > >> Some time ago I discovered this difference between regular expressions >> in Python and Perl: >> >> Python >> >> \A matches at start of string >> \Z matches at end of string >> >> Perl >> >> \A matches at start of string >> \Z matches before terminal newline or at end of string >> \z matches at end of string >> >> In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ >> and \Z != $ in single-string mode. > > Why do you want the two to be equivalent? Isn't a good thing that you > have both alternatives (\Z and $)? Use whichever is adequate in each case. > Python's \Z is equivalent to Perl's \z, but there's no equivalent to Perl's \Z in multi-line mode. From google at mrabarnett.plus.com Sat Jan 24 18:53:17 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:53:17 +0000 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: <497BA9ED.3010905@mrabarnett.plus.com> Terry Reedy wrote: > Benjamin Kaplan wrote: >> >> >> On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan > > wrote: >> >> On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: >> >> > I just started using python last week and I'm addicted. >> >> you need to try this: >> >> import antigravity >> >> http://xkcd.com/353/ >> >> >> Just be careful with that. That guy was still floating 129 comics >> later (3 comics = 1 week). And still going "Woo Python". You can see >> him floating near the peak of Mt. Everest. >> >> http://xkcd.com/482/ > > For a Python 'program', see http://xkcd.com/534/ > It doesn't follow PEP 8! From robert.kern at gmail.com Sat Jan 24 19:00:33 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 18:00:33 -0600 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: On 2009-01-24 17:00, oktaysafak at superonline.com wrote: > Hi all, > > I ran into a strange case. > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > ... > >>> -1 == True > False > >>> -1 == False > False > > This works though: > >>> if -1: > print "OK" > > OK > > After some head scratching, I realized that: > - bool is a subclass of int and that True and False evaluates to 1 and > 0, so -1 is equal to neither; and > - The if -1: statement probably works by treating -1 as bool(-1). Yes. > But I can't help finding the former comparison behavior odd. I admit > that it is odd to write such code but when someone writes -1 == True, > the intention is clearly a boolean comparison, not a numerical value > comparison, isn't it? Not to me. The rules of Python state that the object on the left hand side is asked first how to compare the two values. Only if that fails is the object on the right hand side asked how to compare the objects. > As far as I understand, to do this comparison, python is casting > (loosely speaking) True to its numerical value, rather than casting -1 > to its boolean value. Not really. No casting goes on at all. bool is just one of the types that int.__eq__ knows how to handle because bool is a subclass of int. Vice-versa, bool.__eq__ knows how to handle ints, and it also does a numerical comparison; it never casts to a boolean. > So, my question is: wouldn't it make more sense to do just the opposite, > i.e. cast -1 to its boolean value and do a boolean comparison of the > operands, when one of the operands is True or False? > > Or is this too fancy? What do you think? I think that being explicit is better than being implicit. If you want to cast an object to a boolean, use bool() on it. Making special rules when comparing with booleans makes it harder to treat True and False as first-class objects. -- 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 robert.kern at gmail.com Sat Jan 24 19:03:23 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 18:03:23 -0600 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: On 2009-01-23 22:25, Aahz wrote: > In article, > Linuxguy123 wrote: >> I just started using python last week and I'm addicted. > > Welcome! Just be aware that excessive Perl-bashing is considered > somewhat tasteless on this newsgroup, but the occasional snide comment > should be fine. ;-) Or bash-bashing for that matter. :-) but-zsh-really-is-better'ly yrs, -- 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 sjmachin at lexicon.net Sat Jan 24 19:04:23 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jan 2009 16:04:23 -0800 (PST) Subject: RegEx issues References: Message-ID: <96673ff7-26df-4467-a039-74a15749cec3@a12g2000pro.googlegroups.com> On Jan 25, 5:59?am, Scott David Daniels wrote: > Sean Brown wrote: > > I have the following string ...: ?"td[ct] = [[ ... ]];\r\n" > > The ... (representing text in the string) is what I'm extracting .... > > So I think the regex \[\[(.*)\]\]; should do it. > > The problem is it appears that python is escaping the \ in the regex > > because I see this: > >>>> reg = '\[\[(.*)\]\];' > >>>> reg > > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; > > ... > > OK, you already have a good answer as to what is happening. > I'll mention that raw strings were put in the language exactly for > regex work. ?They are useful for any time you need to use the backslash > character (\) within a string (but not as the final character). > For example: > ? ? ?len(r'\a\b\c\d\e\f\g\h') == 16 and len('\a\b\c\d\e\f\g\h') == 13 > > If you get in the habit of typing regex strings as r'...' or r"...", > and examining the patters with print(somestring), you'll ease your life. All excellent suggestions, but I'm surprised that nobody has mentioned the re.VERBOSE format. Manual sez: ''' re.X re.VERBOSE This flag allows you to write regular expressions that look nicer. Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a '#' neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such '#' through the end of the line are ignored. That means that the two following regular expression objects that match a decimal number are functionally equal: a = re.compile(r"""\d + # the integral part \. # the decimal point \d * # some fractional digits""", re.X) b = re.compile(r"\d+\.\d*") ''' My comments: (1)"looks nicer" is not the point; it's understandability (2) if you need a space, use a character class ->[ ]<- not an unescaped backslash ->\ <- (3) the indentation in the manual doesn't fit my idea of "looks nicer"; I'd do a = re.compile(r""" \d + # the integral part \. # the decimal point \d * # some fractional digits """, re.X) (4) you can aid understandability by more indentation especially when you have multiple capturing expressions and (?......) gizmoids e.g. r""" ( ..... # prefix ) ( (?......) # look-back assertion (?....) # etc etc ) """ Worth a try if you find yourself going nuts getting the parentheses matching. Cheers, John From benjamin at python.org Sat Jan 24 19:08:01 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 25 Jan 2009 00:08:01 +0000 (UTC) Subject: Can webbrowser module get source code? References: Message-ID: Muddy Coder yahoo.com> writes: > I want to go > further: to get the source code of the webpage being displayed. Is it > possible to do it? I tried webbrow.get() but didn't work. Somebody can > help? Thanks! To do this, you actually need to fetch the page yourself: import urllib2 page_source = urllib2.urlopen("http://someaddress.com").read() > From sjmachin at lexicon.net Sat Jan 24 19:10:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jan 2009 16:10:28 -0800 (PST) Subject: Regex for Python 2.7 References: Message-ID: <3ba04700-56a3-40d4-91ba-0cad833f38e7@z27g2000prd.googlegroups.com> On Jan 25, 7:23?am, MRAB wrote: > Some time ago I discovered this difference between regular expressions > in Python and Perl: > > Python > > ? ? ? ? \A matches at start of string > ? ? ? ? \Z matches at end of string > > Perl > > ? ? ? ? \A matches at start of string > ? ? ? ? \Z matches before terminal newline or at end of string > ? ? ? ? \z matches at end of string > > In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ > and \Z != $ in single-string mode. > > Obviously, changing Python's \Z to match Perl's could break existing > code. \z could be added, but with the opposite meaning to Perl's: > > ? ? ? ? Python's \Z == Perl's \z > ? ? ? ? Python's \z == Perl's \Z > > Would that be confusing? > > Any suggests welcome. IIRC there was an exchange some years ago where the perl guy (Larry?) admitted that he goofed and the consensus was that what Python had done was better. From mspetrovic at gmail.com Sat Jan 24 19:10:39 2009 From: mspetrovic at gmail.com (Mark.Petrovic) Date: Sat, 24 Jan 2009 16:10:39 -0800 (PST) Subject: Parsing a string into a datetime object References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> <877i4kfs83.fsf@mulj.homelinux.net> Message-ID: <8df5b4a2-296f-4bf9-8b7b-1aff52e05f8e@a12g2000pro.googlegroups.com> On Jan 24, 10:56?am, Hrvoje Niksic wrote: > "Mark.Petrovic" writes: > > Might someone comment on why %f is not accepted as a valid field > > directive in: > > >>>> from datetime import datetime > >>>> created="2009-01-24 16:04:55.882788" > >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > > python2.5/_strptime.py", line 321, in strptime > > ? ? (bad_directive, format)) > > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > > This is for Python 2.5.1 under OS X. > > time.strptime is documented to use the same set of directives as > time.strftime, andhttp://docs.python.org/library/time.html#time.strftimedoesn't mention > a %f directive. Thank you for the timely reply. I guess I got mixed up by looking at the Python 2.6.1 docs, but used the Python 2.5.1 interpreter: http://docs.python.org/library/datetime.html wherein datetime.html does show the availability of the %f directive (if I'm reading all this correctly). From tjreedy at udel.edu Sat Jan 24 19:11:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 19:11:03 -0500 Subject: why is this invalid b = a += b ? In-Reply-To: <497BA2F7.3040100@gmail.com> References: <497BA2F7.3040100@gmail.com> Message-ID: Stef Mientki wrote: > hello, > > I can assign a value to more than 1 variable (name) in one line: > > a = b = 3 > > So evaluation of this line must start at the right part. > > But the following is not allowed: > > b = 2 > a = b += 1 This strikes me as slightly incoherent. Given that v op=exp is mostly that same as v = v op exp, I suppose you expect a = b += 1 to be mostly the same as a = b = b+1, but what would you do with a += b = 1, or even a *= b += 1. There is some virtur to restricting augmented assignment to one target and one delimiter. Even that seems to cause some trouble. tjr From Russ.Paielli at gmail.com Sat Jan 24 19:11:19 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 16:11:19 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: <0bed2faa-74cf-4d9a-823d-4a71cd8af429@p23g2000prp.googlegroups.com> On Jan 24, 4:03?pm, Robert Kern wrote: > On 2009-01-23 22:25, Aahz wrote: > > > In article, > > Linuxguy123 ?wrote: > >> I just started using python last week and I'm addicted. > > > Welcome! ?Just be aware that excessive Perl-bashing is considered > > somewhat tasteless on this newsgroup, but the occasional snide comment > > should be fine. ?;-) > > Or bash-bashing for that matter. ?:-) > > but-zsh-really-is-better'ly yrs, > > -- > 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 Come to think of it, when I use bash to run a series of python scripts, I could call it "bashing Python." From benjamin at python.org Sat Jan 24 19:14:26 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 25 Jan 2009 00:14:26 +0000 (UTC) Subject: Possible to slice a string with unpacked tuple? References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: MRAB mrabarnett.plus.com> writes: > Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, > then how about myString.__getslice__(*myTuple)? Please don't use special method names directly and especially not __getslice__(). It's deprecated and will be removed. From kyrie at uh.cu Sat Jan 24 19:17:37 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sat, 24 Jan 2009 19:17:37 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232842657.497bafa1833a2@mail.uh.cu> Quoting "Russ P." : > On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > > > Makes *no* sense? There's *no* good reason *at all* for the original > > > author to hide or protect internals? > > > > My bad, sorry. > > It makes sense... if the original author is an egotist who believes he > must > > control how I use that library. > > If the original author provides you with the source code and the right > to modify it, he cannot possibly control how you use the library. You > can trivially disable any access controls. But for some reason that's > not enough for you. No, I'm not satisfied with forking python just to use sys._getframe. > Has it occurred to you that some users might actually *want* access > controls? Maybe some users want to actually use the library as the > author intended it to be used. What a bizarre concept! Huh? Then... use it as the author intended. I am _not_ forcing you to use the obj._protected attributes! Even I run pylint against third party libraries just to assess if the risk of them messing with someone else's internals is worth taking (as in the case of inspect.currentframe, which is exactly the same as sys._getframe) or not (random library downloaded from the net). > Oh, but only a paranoid fool could possibly want access controls, eh? > Who's the egotist here? See? You too changed what I said. Somehow you managed to delete the _other_ situation I gave. Not worth correcting it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From digitig at gmail.com Sat Jan 24 19:31:14 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 25 Jan 2009 00:31:14 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/24 Rhodri James : > My experience with medium-sized organisations (50-100 people) is that > either you talk to Fred directly, or it doesn't happen. In particular > the more people (especially PHBs) that get involved, the slower the > change will come and the less like your original requirement it will > look. Each person, no matter how technically adept, has a significant > chance of misunderstanding what it is you need and/or expressing it > poorly to the next person in line. So you talk to Fred, and he changes the "pong" library function to go "ping", as you wish. Unfortulately, neither of you know that Alice is depending on Fred's "pong" library function to go "pong" as specified, and is totally stuffed when he delivers it and it goes "ping". That's why changes to specifications need to go through a proper specification change procedure if the team (not the organisation) is more than a few people. -- Tim Rowe From geekmail at usenot.de Sat Jan 24 19:32:45 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sun, 25 Jan 2009 01:32:45 +0100 Subject: I'm a python addict ! References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: <20090125013245.11112adf@usenot.de> On Sat, 24 Jan 2009 23:53:17 +0000 MRAB wrote: > Terry Reedy wrote: > > For a Python 'program', see http://xkcd.com/534/ > > > It doesn't follow PEP 8! So Randall can just forget about getting xkcd in the Standard Library. Let this be an example to all of you?! /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gagsl-py2 at yahoo.com.ar Sat Jan 24 19:46:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 22:46:43 -0200 Subject: RegEx issues References: Message-ID: En Sat, 24 Jan 2009 19:03:26 -0200, Sean Brown gmail.com> <" escribi?: > Using python 2.4.4 on OpenSolaris 2008.11 > > I have the following string created by opening a url that has the > following string in it: > > td[ct] = [[ ... ]];\r\n > > The ... above is what I'm interested in extracting which is really a > whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>> reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; No. Python escape character is the backslash \; if you want to include a backslash inside a string, you have to double it. By example, these are all single character strings: 'a' '\n' '\\' Coincidentally (or not), the backslash has a similar meaning in a regular expression: if you want a string containing \a (two characters) you should write "\\a". That's rather tedious and error prone. To help with this, Python allows for "raw-string literals", where no escape interpretation is done. Just put an r before the opening quote: r"\(\d+\)" (seven characters; matches numbers inside parenthesis). Also, note that when you *evaluate* an expression in the interpreter (like the lone "reg" above), it prints the "repr" of the result: for a string, it is the escaped contents surrounded by quotes. (That's very handy when debugging, but may be confusing if don't know how to interpret it) Third, Python is very permissive with wrong escape sequences: they just end up in the string, instead of flagging them as an error. In your case, \[ is an invalid escape sequence, which is left untouched in the string. py> reg = r'\[\[(.*)\]\];' py> reg '\\[\\[(.*)\\]\\];' py> print reg \[\[(.*)\]\]; py> len(reg) 13 > Which obviously doesn't match anything because there are no literal \ in > the above string. Leaving the \ out of the \[\[ above has re.compile > throw an error because [ is a special regex character. Which is why it > needs to be escaped in the first place. It works in this example: py> txt = """ ... Some text ... and td[ct] = [[ more things ]]; ... more text""" py> import re py> m = re.search(reg, txt) py> m <_sre.SRE_Match object at 0x00AC66A0> py> m.groups() (' more things ',) So maybe your r.e. doesn't match the text (the final ";"? whitespace?) For more info, see the Regular Expressions HOWTO at http://docs.python.org/howto/regex.html -- Gabriel Genellina From tgvaughan at gmail.com Sat Jan 24 20:06:48 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 17:06:48 -0800 (PST) Subject: *.python.org broken? Message-ID: Hi all, Is anybody else having trouble accessing sites (including www, docs, wiki) in the python.org tree, or is it just me? (Or just .au?) Cheers, Tim From oktaysafak at superonline.com Sat Jan 24 20:07:04 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 03:07:04 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: <497BBB38.1010803@superonline.com> Robert Kern wrote: > On 2009-01-24 17:00, oktaysafak at superonline.com wrote: >> Hi all, >> >> I ran into a strange case. >> >> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit >> (Intel)] on win32 >> ... >> >>> -1 == True >> False >> >>> -1 == False >> False >> >> This works though: >> >>> if -1: >> print "OK" >> >> OK >> >> After some head scratching, I realized that: >> - bool is a subclass of int and that True and False evaluates to 1 and >> 0, so -1 is equal to neither; and >> - The if -1: statement probably works by treating -1 as bool(-1). > > Yes. Good. > >> But I can't help finding the former comparison behavior odd. I admit >> that it is odd to write such code but when someone writes -1 == True, >> the intention is clearly a boolean comparison, not a numerical value >> comparison, isn't it? > > Not to me. The rules of Python state that the object on the left hand > side is asked first how to compare the two values. Only if that fails is > the object on the right hand side asked how to compare the objects. OK. >> As far as I understand, to do this comparison, python is casting >> (loosely speaking) True to its numerical value, rather than casting -1 >> to its boolean value. > > Not really. No casting goes on at all. Of course, I said loosely speaking. > bool is just one of the types that int.__eq__ knows how to handle > because bool is a subclass of int. > Vice-versa, bool.__eq__ knows how to handle ints, and it also does a > numerical comparison; it never casts to a boolean. That's what I'm trying to say: it would be more meaningful if int.__eq__ did a boolean comparison when the other operand is a boolean. And bool.__eq__ should as well do a boolean comparison when the other operand is an integer (or even a number). The reason is that when someone writes (-1 == True) he is clearly, definitely, absolutely asking for a boolean comparison, not a numerical one. As I said before, this is weird code; but using the True built-in for checking whether a number's value is equal to 1 would be even weirder. > >> So, my question is: wouldn't it make more sense to do just the opposite, >> i.e. cast -1 to its boolean value and do a boolean comparison of the >> operands, when one of the operands is True or False? >> >> Or is this too fancy? What do you think? > > I think that being explicit is better than being implicit. Well, I agree that explicit is better than implicit: when one wants to use the numerical values of True or False, he should make it explicit and use int(True) or int(False), but one is never interested in a boolean's numerical value (which is nonsense, IMHO). We never write counter += True, for example. > If you want to cast an object to a boolean, use bool() on it. Well, I can tell you in response that if you are interested in a boolean's *integer* value, than make it explicit and use int(True). When I write assert i == True I'm not trying to make sure that i is equal to one, I am trying to make sure that it evaluates to True (of course True is redundant here but it can make the code more readable). If I was interested in the former case, it would be most natural to write assert i == 1 but I'm interested in the latter and I think Python's treatment is not quite right here. > Making special rules when comparing with booleans makes it harder to > treat True and False as first-class objects. I don't see how fixing this makes harder to treat True and False as first-class objects. If doing the right thing takes some special casing then be it, but I don't think it's so. Anyway, thanks for the response. Oktay From tjreedy at udel.edu Sat Jan 24 20:08:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:08:58 -0500 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: oktaysafak at superonline.com wrote: > Hi all, > > I ran into a strange case. > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > ... > >>> -1 == True > False > >>> -1 == False > False > > This works though: > >>> if -1: > print "OK" > > OK > > After some head scratching, I realized that: > - bool is a subclass of int and that True and False evaluates to 1 and > 0, Yes, for historical and practical reasons. > so -1 is equal to neither; and NO builtin objects other than numbers equal to 1 or 0 are equal to True or False. > - The if -1: statement probably works by treating -1 as bool(-1). 'if condition:' *always* works by calling bool() on the condition, which is why one should *never* write 'if bool(exp):'. > But I can't help finding the former comparison behavior odd. Every object other than numbers equal to 0 or 1 has the same behavior. > I admit that it is odd to write such code but when someone writes -1 == True, It is odd to write such code because the result of comparing two constants is or could be known when it is written. So while one could write an optimizer to replace such comparisons with the known value at compile time, no one has done so. (There is an optimizer that sometimes replaces arithmetic operations on number constants, but that is because writing code that way may make it clearer: for instance, 1<<13 versus 8192.) > the intention is clearly a boolean comparison, not a numerical value > comparison, isn't it? Nope. Expecially if either side of the expression in the code is a name or collection slot. As far as the compiler is concerned, '-1' is an expression that evaluates to an object and 'True' is another expression that evaulates to another object and '==' is a comparison operator which it compiles to a call to code that calls the appropriate rich comparison methods of either or both of the two objects. > As far as I understand, to do this comparison, python is casting > (loosely speaking) True to its numerical value, rather than casting -1 > to its boolean value. I think that this is speaking so loosely as to be misleading. 'Cast' has a couple of meaning, neither of which means 'treat a subclass instance as a base class instance.' Subclass instances are automatically base class instances and are treated as such by default unless there is a subclass method that over-rides the base class method. Bool does *not* over-ride int comparison methods. >>> bool.__eq__ is int.__eq__ True I suspect that the only methods to bool are __new__ (which returns one of the only two instances allowed), __str__, and __repr__ (which return 'False' or 'True' instead of '0' or '1'). Bools are ints, not 'cast to' ints. > So, my question is: wouldn't it make more sense to do just the opposite, > i.e. cast -1 to its boolean value and do a boolean comparison of the > operands, when one of the operands is True or False? That would require that ints be subclassed from bool, which does not work. Terry Jan Reedy From kyrie at uh.cu Sat Jan 24 20:09:42 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sat, 24 Jan 2009 20:09:42 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <018aecb2$0$20629$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232845782.497bbbd61af0e@mail.uh.cu> Quoting Steven D'Aprano : > On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: > > > Quoting Steven D'Aprano : > >> Makes *no* sense? There's *no* good reason *at all* for the original > >> author to hide or protect internals? > > > > My bad, sorry. > > It makes sense... if the original author is an egotist who believes he > > must control how I use that library. > > Then I guess Guido must be such an egotist, because there's plenty of > internals in Python that you can't (easy) mess with. Yeap, ignore the second part, and claim that I only said this. > > Or, if external forces make him do > > it (maybe like, 'oh, if I change python, then I'm not using python > > anymore'). > > That parenthesised comment makes no sense to me. It was directly countering your 'list' example. _I_ don't want to change _python_, nor python's assumptions and assurances. A standard python that can segfault would be no python. Again, if you think that means that deep down I like enforced data hiding, so be it. > [...] > > If a variable is marked as... I don't like 'private', I'll call it > > 'implementation detail', I would not use it without good reason. Not > > even by subclassing it. Why do you assume that I'd change list._length > > if I could? I wouldn't. > > I didn't say you would change it on a whim. I said that *if* it were > exposed to Python code, you *could* change it. You might change it > because you thought you had a good reason to. You might change it by > accident. You might not realise the consequences of changing it. Who > knows? It doesn't matter what your motives are. Exactly, they don't matter to you, unless you happen to be running my code. > My point is that you claimed that there is no good reason at all for > hiding implementation details. Python is full of implementation details > which are quite effectively hidden from Python programmers. So there are > two possibilities: I didn't say "at all". Those were your words, not mine. I said that it makes no sense that the power lies on _you_ instead of on _my team_. And, when I said that, I recall we were talking about the python language, not C. > (1) you are right that it "makes no sense" (your words) for the original > author (in this case, Guido) to hide those implementation details from > Python programmers; or Just to be clear: I think the opposite. He made a language and interpreter, and it ensures that it will not segfault because of incorrect pure python code. That is my blackbox. In doing that, he made a language where I don't have to worry that much about enforcing access restrictions. Again, if you think that means that I want enforced data hiding in python, so be it. > (2) you are wrong that it "makes no sense", because there is at least one > case where the original author (Guido again) did a sensible thing by > hiding implementation details. hiding the implementation details of a C implementation... not python. > In an effort to avoid going round and round in circles, let me explicitly > say that option (2) does not imply that it always makes sense to hide > implementation details. Huh? It makes sense to hide implementations details. I'd say it always makes sense. What doesn't make sense is that someone fights so vehemently to stop me from getting at them, on my code, on my systems. > [...] > >> So what you're saying is that the fundamental design of Python -- to be > >> a high-level language that manages memory for you while avoiding > >> common programming errors such as buffer overflows -- makes "no sense". > >> Is that what you intended? > > > > Yes, that's what I intended, obviously. I'd like to have buffer > > overflows in python. In case you don't understand irony: don't go > > putting words in my mouth. I'm not putting words in yours. > > And neither am I. I'm pointing out the logical implications of your > position. If you find those implications unpleasant, then perhaps you > should modify your position to be less extreme and more realistic. But it is realistic. You put the words "at all", and you shifted the discussion from Python to C, and from programs in python to python's implementation. [snip the comments about the advantages of data hiding. We are not talking about data hiding, we are talking about having data hiding enforced against me] > > I stand by my words - but not by your "interpretation" of them: > > > >> > What makes no sense is that it should be in the original author's > >> > power to decide, if he is not part of _our_ team. > > > > Do you _really_ read from that sentence that I should dislike python > > because it makes it a bit harder to get a buffer overflow with their > > native types? > > Well, you tell me: does it make sense for Guido to have decided to make > it hard for pure Python developers to cause buffer overflows? Yes it does. And this answers my question... You do consider the fact that I like python, that I like that python is not C, and that I use python as a blackbox, as a confirmation that I want enforced data hiding. I was truthful when I said that: if you think so, then so be it, feel free to think that I want it. We are obviously not on the same page here, we are not even talking about the same language. I guess (just a guess) that in your view, if I really didn't want enforced data hiding, I'd be programming directly in machine code or maybe making my own CPUs. If your idea of enforced data hiding includes that (it obviously includes the interpreter), then what I said was wrong. I assumed we were talking about python and that I didn't need to explicitly quantify my expressions. And, FYI, when programming in java, C++ or C#, I do use "private" and "protected" variables, not becasue I want to forbid others from using it, but because it is [rightly?] assumed that everything marked as public is safe to use - and I consider that a strong enough "external" reason to do it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Sat Jan 24 20:16:30 2009 From: rt8396 at gmail.com (r) Date: Sat, 24 Jan 2009 17:16:30 -0800 (PST) Subject: *.python.org broken? References: Message-ID: <3aad73b0-67bf-4340-abdf-ef5e64693b26@f18g2000vbf.googlegroups.com> On Jan 24, 7:06?pm, tgvaug... at gmail.com wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Cheers, > > Tim No problem here??? From Russ.Paielli at gmail.com Sat Jan 24 20:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 17:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> On Jan 24, 4:17?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > > > > Makes *no* sense? There's *no* good reason *at all* for the original > > > > author to hide or protect internals? > > > > My bad, sorry. > > > It makes sense... if the original author is an egotist who believes he > > must > > > control how I use that library. > > > If the original author provides you with the source code and the right > > to modify it, he cannot possibly control how you use the library. You > > can trivially disable any access controls. But for some reason that's > > not enough for you. > > No, I'm not satisfied with forking python just to use sys._getframe. Calling a one-word change a "fork" is quite a stretch, I'd say. > > Has it occurred to you that some users might actually *want* access > > controls? Maybe some users want to actually use the library as the > > author intended it to be used. What a bizarre concept! > > Huh? > Then... use it as the author intended. I am _not_ forcing you to use the > obj._protected attributes! But what if I want an automatic check to verify that I am using it as the author intended? Is that unreasonable? Think of enforced access restriction as an automatic "assert" every time an attribute is accessed that it is not a private attribute. I may want this automatic verification in my own code just for peace of mind. More importantly, a project manager may want it to verify that no one on the development team is accessing private attributes. Sure, he could do that with code reviews, but code reviews are far more expensive (and less reliable in some ways) than a simple check enforced by the language itself. Without enforced access protection, depending on code reviews to detect the use of private attributes is a bit like depending on security guards to keep doors closed without putting locks on the doors. You don't need a lock on a door if you can afford to post a security guard there full time, but doesn't it make more sense to put a lock on the door and have a security guard check it only occasionally? From philip at semanchuk.com Sat Jan 24 20:19:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 24 Jan 2009 20:19:38 -0500 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <2BC6E694-9726-4647-AB7D-14A516E79DDB@semanchuk.com> On Jan 24, 2009, at 8:06 PM, tgvaughan at gmail.com wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) No problem here in Durham, NC, USA. From robert.kern at gmail.com Sat Jan 24 20:23:01 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 19:23:01 -0600 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <497BBB38.1010803@superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: On 2009-01-24 19:07, Oktay ?afak wrote: > Robert Kern wrote: >> On 2009-01-24 17:00, oktaysafak at superonline.com wrote: >>> Hi all, >>> >>> I ran into a strange case. >>> >>> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit >>> (Intel)] on win32 >>> ... >>> >>> -1 == True >>> False >>> >>> -1 == False >>> False >>> >>> This works though: >>> >>> if -1: >>> print "OK" >>> >>> OK >>> >>> After some head scratching, I realized that: >>> - bool is a subclass of int and that True and False evaluates to 1 and >>> 0, so -1 is equal to neither; and >>> - The if -1: statement probably works by treating -1 as bool(-1). >> >> Yes. > > Good. > >> >>> But I can't help finding the former comparison behavior odd. I admit >>> that it is odd to write such code but when someone writes -1 == True, >>> the intention is clearly a boolean comparison, not a numerical value >>> comparison, isn't it? >> >> Not to me. The rules of Python state that the object on the left hand >> side is asked first how to compare the two values. Only if that fails >> is the object on the right hand side asked how to compare the objects. > > OK. > >>> As far as I understand, to do this comparison, python is casting >>> (loosely speaking) True to its numerical value, rather than casting -1 >>> to its boolean value. >> >> Not really. No casting goes on at all. > > Of course, I said loosely speaking. > >> bool is just one of the types that int.__eq__ knows how to handle >> because bool is a subclass of int. Vice-versa, bool.__eq__ knows how >> to handle ints, and it also does a numerical comparison; it never >> casts to a boolean. > > That's what I'm trying to say: it would be more meaningful if int.__eq__ > did a boolean comparison when the other operand is a boolean. And > bool.__eq__ should as well do a boolean comparison when the other > operand is an integer (or even a number). The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. As I said before, this is > weird code; but using the True built-in for checking whether a number's > value is equal to 1 would be even weirder. So don't do it. There really aren't many use cases for comparing with a boolean. Just call bool() on the object. >>> So, my question is: wouldn't it make more sense to do just the opposite, >>> i.e. cast -1 to its boolean value and do a boolean comparison of the >>> operands, when one of the operands is True or False? >>> >>> Or is this too fancy? What do you think? >> >> I think that being explicit is better than being implicit. > > Well, I agree that explicit is better than implicit: when one wants to > use the numerical values of True or False, he should make it explicit > and use int(True) or int(False), but one is never interested in a > boolean's numerical value (which is nonsense, IMHO). We never write > counter += True, for example. Actually, I sum up booleans quite often. >> If you want to cast an object to a boolean, use bool() on it. > > Well, I can tell you in response that if you are interested in a > boolean's *integer* value, than make it explicit and use int(True). The two positions are not symmetrical. Your position requires special-casing equality testing; Python's position doesn't. > When > I write > > assert i == True > > I'm not trying to make sure that i is equal to one, I am trying to make > sure that it evaluates to True (of course True is redundant here but it > can make the code more readable). If I was interested in the former > case, it would be most natural to write assert i == 1 but I'm interested > in the latter and I think Python's treatment is not quite right here. Then just do "assert i" or "assert bool(i)" and be done with it. There's no need to do any comparisons at all. > > Making special rules when comparing with booleans makes it harder to > > treat True and False as first-class objects. > > I don't see how fixing this makes harder to treat True and False as > first-class objects. If doing the right thing takes some special casing > then be it, but I don't think it's so. True in ['something', False] In your semantics, this would evaluate to True because ('something' == True) is True. -- 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 tgvaughan at gmail.com Sat Jan 24 20:25:50 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 17:25:50 -0800 (PST) Subject: *.python.org broken? References: Message-ID: On Jan 25, 12:19?pm, Philip Semanchuk wrote: > On Jan 24, 2009, at 8:06 PM, tgvaug... at gmail.com wrote: > > > Hi all, > > > Is anybody else having trouble accessing sites (including www, docs, > > wiki) in the python.org tree, or is it just me? (Or just .au?) > > No problem here in Durham, NC, USA. Bugger.. Thanks anyway. From tjreedy at udel.edu Sat Jan 24 20:29:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:29:10 -0500 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <497BBB38.1010803@superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: Oktay ?afak wrote: > That's what I'm trying to say: it would be more meaningful if int.__eq__ > did a boolean comparison when the other operand is a boolean. For that to be done, int would have to know about its subclass, which generally is bad design. > The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. I would say that the person does not understand Python and that the code is probably buggy. > As I said before, this is weird code; It is a bad idea to accommodate the language and interpreter to weird code which should never be written. > Well, I agree that explicit is better than implicit: when one wants to > use the numerical values of True or False, he should make it explicit > and use int(True) or int(False). The reason to make bool a subclass of int is to avoid having to do that. You do not have to like this fact of Python but it has been decided and will not change. > We never write counter += True, for example. But you might write counter += name, where you know name is bound to a bool. As I said, issubclass(bool, int) just so one would not have to write counter += int(name). >> If you want to cast an object to a boolean, use bool() on it. > Well, I can tell you in response that if you are interested in a > boolean's *integer* value, than make it explicit and use int(True). A Python bool *is* an int already: isinstance(True, int) returns True! Adding the bool subclass around 2.3 or so was a convenience that makes code and output clearer, but not a necessity. Python did fine without it just as many other languages do. Terry Jan Reedy From gagsl-py2 at yahoo.com.ar Sat Jan 24 20:42:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 23:42:23 -0200 Subject: String comparision References: Message-ID: En Sat, 24 Jan 2009 15:08:08 -0200, S.Selvam Siva escribi?: > I am developing spell checker for my local language(tamil) using python. > I need to generate alternative word list for a miss-spelled word from the > dictionary of words.The alternatives must be as much as closer to the > miss-spelled word.As we know, ordinary string comparison wont work here . > Any suggestion for this problem is welcome. I think it would better to add Tamil support to some existing library like GNU aspell: http://aspell.net/ You are looking for "fuzzy matching": http://en.wikipedia.org/wiki/Fuzzy_string_searching In particular, the Levenshtein distance is widely used; I think there is a Python extension providing those calculations. -- Gabriel Genellina From Russ.Paielli at gmail.com Sat Jan 24 20:43:16 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 17:43:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> On Jan 24, 5:09?pm, Luis Zarrabeitia wrote: > I didn't say "at all". Those were your words, not mine. > I said that it makes no sense that the power lies on _you_ instead of on _my > team_. And, when I said that, I recall we were talking about the python > language, not C. Once again, if you have the source code for the library (and the right to modify it), how does the "power" lie with the library implementer rather than you the user? You say you don't want to "fork" the library. Let's stipulate for the sake of argument that a one-line change is indeed a "fork." Think about what you are saying. You are saying that you should dictate how the producer of the library should implement it because you don't want to be bothered to "fork" it. If you don't like his design decisions, shouldn't the onus be on *you* to make the trivial change necessary to get access to what you want? Imagine a person who repairs computers. He is really annoyed that he constantly has to remove the cover to get at the guts of the computer. So he insists that computers cases should be made without covers. After all, manufacturers put covers on computers only because they don't trust us and think we're too "stupid" to safely handle an uncovered computer box. That is logically equivalent to your position on enforced access restrictions in software. > And, FYI, when programming in java, C++ or C#, I do use "private" and > "protected" variables, not becasue I want to forbid others from using it, but > because it is [rightly?] assumed that everything marked as public is safe to use > - and I consider that a strong enough "external" reason to do it. You could just use leading underscores and note their meaning in the documentation. If that's such a great approach, why not do it? Yes, I know, it's not a widely used convention in those other languages. Fair enough. But you could still do it if it's such a good idea. From tjreedy at udel.edu Sat Jan 24 20:45:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:45:25 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: Benjamin Peterson wrote: > MRAB mrabarnett.plus.com> writes: >> Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, >> then how about myString.__getslice__(*myTuple)? > > Please don't use special method names directly and especially not > __getslice__(). It's deprecated and will be removed. It is gone in 3.0. In 3.0, at least, and perhaps later 2.x (not sure) the OP should simply write myString[slice(*myTuple)] which is the semantic equivalent of myString[myTuple[0]:myTuple[1]] From python.list at tim.thechases.com Sat Jan 24 20:56:04 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Jan 2009 19:56:04 -0600 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <497BC6B4.8070908@tim.thechases.com> > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) I've had problems[1] browsing them (most irksomely, the docs) from Dillo thanks to what are apparently poor handling of IPv6 fallback rules. Dillo gets an IPv6 IP address back from DNS, tries it and fails because my ISP or router doesn't talk IPv6. However Dillo fails to fallback to IPv4 which does work (bug filed with the Debian maintainers of Dillo[2]). If I switch to using a less broken browser (Epiphany, Lynx, FireFox/IceWeasel, Safari, telnet:80, urllib), it works fine here in the Dallas area. If I disable IPv6 on my Linux box (not a great loss at this point), Dillo works as well. Tests to check: Can you resolve the IP address from the name? bash$ dig docs.python.org bash$ dig -6 docs.python.org Can you ping the target IP address? bash$ ping docs.python.org bash$ ping 82.94.164.162 (try ping6 as well) Can you traceroute to the IP address (and where does it die)? bash$ traceroute docs.python.org bash$ traceroute -6 docs.python.org Can you telnet:80 to the target IP address? bash$ telnet docs.python.org 80 GET / HTTP/1.1 host: docs.python.org Have you tried from other local ISPs? (cafe, work, school) -tkc PS: Thanks again, Martin, for your tips in troubleshooting this for me. [1] http://mail.python.org/pipermail/python-list/2008-November/517812.html [2] http://bugs.debian.org/507251 From python at bdurham.com Sat Jan 24 20:56:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 20:56:15 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: <1232848575.24973.1296579329@webmail.messagingengine.com> Terry, Hi, I'm the OP in question. > the OP should simply write myString[slice(*myTuple)] My tuples define positions in a fixed width string for parsing values. So rather than 'unpacking' tuples, I'm using slice() to directly define actual field positions, eg. field_1 = slice( 4, 7 ) field_2 = slice( 7, 9 ) etc ... This allows me to extract the field values as follows: for line in myOpenFile: value_1 = line[ field_1 ] value_2 = line[ field_2 ] etc. IMO, this makes a common task like extracting fields very natural and elegant. I LOVE THIS LANGUAGE!! (to echo another recent thread in this forum) Regards, Malcolm From rhodri at wildebst.demon.co.uk Sat Jan 24 20:57:56 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 25 Jan 2009 01:57:56 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 25 Jan 2009 00:31:14 -0000, Tim Rowe wrote: > 2009/1/24 Rhodri James : > > >> My experience with medium-sized organisations (50-100 people) is that >> either you talk to Fred directly, or it doesn't happen. In particular >> the more people (especially PHBs) that get involved, the slower the >> change will come and the less like your original requirement it will >> look. Each person, no matter how technically adept, has a significant >> chance of misunderstanding what it is you need and/or expressing it >> poorly to the next person in line. > > So you talk to Fred, and he changes the "pong" library function to go > "ping", as you wish. Unfortulately, neither of you know that Alice is > depending on Fred's "pong" library function to go "pong" as specified, > and is totally stuffed when he delivers it and it goes "ping". That's > why changes to specifications need to go through a proper > specification change procedure if the team (not the organisation) is > more than a few people. And, not coincidentally, why specification will take at least twice as long as you thought humanly possible, and any implementation you do before it's complete will probably have to be thrown away. The productivity of a team large enough that they don't all talk to each other anyway drops quite dramatically as one consequence of this. This also assumes that the "proper specification change procedure" works, which seems to be a bit on the optimistic side in many cases. But we digress. -- Rhodri James *-* Wildebeeste Herder to the Masses From oktaysafak at superonline.com Sat Jan 24 21:09:06 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 04:09:06 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: <497BC9C2.3080005@superonline.com> >> I don't see how fixing this makes harder to treat True and False as >> first-class objects. If doing the right thing takes some special casing >> then be it, but I don't think it's so. > > True in ['something', False] > > In your semantics, this would evaluate to True because ('something' == > True) is True. > No, it wouldn't. We are talking about integer-boolean equality comparisons, not boolean-string ones. But I get your point. From xahlee at gmail.com Sat Jan 24 21:17:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 18:17:24 -0800 (PST) Subject: syntax color lang source code in blogs or website Message-ID: For those of you using emacs, here's the elisp code that allows you to syntax color computer language source code in your blog or website. http://xahlee.org/emacs/elisp_htmlize.html to comment, here: http://xahlee.blogspot.com/2009/01/dehtmlize-source-code-in-emacs-lisp.html Xah ? http://xahlee.org/ ? From tgvaughan at gmail.com Sat Jan 24 21:24:40 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 18:24:40 -0800 (PST) Subject: *.python.org broken? References: Message-ID: <73e89edd-2cdc-4375-9d34-7b6aa66fdc3d@o4g2000pra.googlegroups.com> Hi Tim, thanks for your post. I could resolve but not ping, which has been the situation for the last couple of days. But not any more! I was just in the process of checking whether or not I could connect via another ISP when I discovered that the problem has apparently fixed itself. Which is great, but weird. Thanks again, Tim From oktaysafak at superonline.com Sat Jan 24 21:50:22 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 04:50:22 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: <497BD36E.8040009@superonline.com> Terry Reedy wrote: > Oktay ?afak wrote: > >> That's what I'm trying to say: it would be more meaningful if >> int.__eq__ did a boolean comparison when the other operand is a boolean. > > For that to be done, int would have to know about its subclass, which > generally is bad design. Good point, but of course it can be done without making the int type know about the specifics of its subclass. > >> The reason is that when someone writes (-1 == True) he is clearly, >> definitely, absolutely asking for a boolean comparison, not a >> numerical one. > > I would say that the person does not understand Python and that the code > is probably buggy. > > > As I said before, this is weird code; > > It is a bad idea to accommodate the language and interpreter to weird > code which should never be written. Again, good point. Agreed. > >> Well, I agree that explicit is better than implicit: when one wants to >> use the numerical values of True or False, he should make it explicit >> and use int(True) or int(False). > > The reason to make bool a subclass of int is to avoid having to do that. > You do not have to like this fact of Python but it has been decided and > will not change. > > > We never write counter += True, for example. > > But you might write counter += name, where you know name is bound to a > bool. As I said, issubclass(bool, int) just so one would not have to > write counter += int(name). OK, my fault. Arithmetical operations was not my point, I was just trying to talk about integer values of True and False in an equality comparison context with other numbers. Of course the fact that issubclass(bool, int) is very handy in calculations like that. > >>> If you want to cast an object to a boolean, use bool() on it. > >> Well, I can tell you in response that if you are interested in a >> boolean's *integer* value, than make it explicit and use int(True). > > A Python bool *is* an int already: isinstance(True, int) returns True! I know, you don't need to shout. What I was trying to say is that using the integer value of a boolean *in a comparison with a number* doesn't make much sense *to me*. I am not trying to change Python or whatever, I am extremely pleased with it as it is. But that doesn't mean I like each and every decision that has gone into it. Like everybody else, there are things that doesn't quite fit in for me and I am trying to understand better. I just came across this behavior while trying something in the interpreter and wanted to discuss with people more knowledgeable than myself. Please keep calm! Oktay From xahlee at gmail.com Sat Jan 24 23:31:14 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 20:31:14 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <1c66ef53-22a3-46b5-8fb5-3cde3deafaf3@p23g2000prp.googlegroups.com> Language, Purity, Cult, and Deception Xah Lee, 2009-01-24 [this essay is roughly a 10 years personal retrospect of some languages, in particular Scheme and Haskell.] I learned far more Ocaml in the past 2 days than the fucking 2 months i tried to learn Haskell, with 10 years of ?I WANT TO BELIEVE? in haskell. The Haskell's problem is similar to Scheme lisp, being academic and of little industrial involvement. About 10 years ago, during the dot com era around 1999, where scripting war is going on (Perl, tcl, Applescript, Userland Frontier, with in the corner Python, Ruby, Icon, Scheme, in the air of Java, HTML 3, CSS, CGI, javascript), i was sold a lie by Scheme lisp. Scheme, has a aura of elegance and minimalism that's one hundred miles in radius. I have always been a advocate of functional programing, with a heart for formal methods. Scheme, being a academic lang, has such a association. At the time, Open Source and Linux have just arrived on the scene and screaming the rounds in the industry, along with Apache & Perl. The Larry Wall scumbag and Eric Raymond motherfucker and Linus T moron and Richard Stallman often appears in interviews in mainstream media. Richard Stallman's FSF with its GNU, is quick to make sure he's not forgotten, by a campaign on naming of Linux to GNU/Linux. FSF announced that Scheme is its chosen scripting lang for GNU system. Plans and visions of Guile ? the new Scheme implementation, is that due to Scheme Lisp's power will have lang conversion abilities on the fly so programers can code in other lang if they wanted to, anywhere in the GNU platform. Around that time, i also wholeheartedly subscribed to some A Brave Gnu World bulletin of FSF with high expectations. Now, it's 2009. Ten years have passed. Guile disappeared into oblivion. Scheme is tail recursing in some unknown desert. PHP practically and quietly surpassed the motherfucking foghorn'd Perl in early 2000s to become the top 5 languages. Python has surfaced to became a mainstream. Ruby is the hip kid on the block. Where is Scheme? O, you can still hear these idiots debating tail recursions among themselves in newsgroups. Tail recursion! Tail recursion! And their standard the R6RS in 2007, by their own consensus, is one fucked up shit. In 2000, i was a fair expert in unix technologies. Sys admin to several data center's solaris boxes each costing some 20 grands. Master of Mathematica and Perl but don't know much about any other lang or lang in general. Today, i am a expert of about 5 languages and working knowledge with tens or so various ones. There is nothing in Scheme i'd consider elegant, not remotely, even if we only consider R4RS. Scheme, like other langs with a cult, sold me lie that lasted 10 years. Similarly, Haskell fucked me with a tag of ?no assignment? purity. You can try to learn the lang for years and all you'll learn is that there's something called currying and monad. I regret i learned python too in 2006. Perl is known for its intentional egregious lies, lead by the demagogue Larry Wall (disclaimer: opinion only). It fell apart unable to sustain its ?post-modernistic? deceptions. Python always seemed reasonable to me, until you stepped into it. You learned that the community is also culty, and is into certain grand visions on beauty & elegance with its increasingly complex syntax soup with backward incompatible python 3.0. The python fuckheads sport the air of ?computer science R us?, in reality they are idiots about the same level of Perl mongers. (Schemers and Haskell people at least know what they are talking about. They just don't have the know how of the industry.) I think my story can teach tech geekers something. In my experience, the langs that are truely a joy to learn and use, are those sans a cult. Mathematica, javascript, PHP, are all extremely a joy to use. Anything you want to do or learn how to do, in so far that the lang is suitable, can be done quickly. Their docs are to the point. And today i have to include Ocaml. It's not about whether the lang is functional, or whether the lang is elegant, or what theoretical power it has. Also, lang of strong academic background such as Scheme and Haskell are likely to stay forever there, regardless what is the technical nature of the lang. The background of the community, makes half what the language is. Disclaimer: All mentions of real persons are opinion only. Xah ? http://xahlee.org/ ? From kay.schluehr at gmx.net Sat Jan 24 23:56:06 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 20:56:06 -0800 (PST) Subject: Two import questions in Python 3.0 References: Message-ID: On 24 Jan., 18:51, Scott David Daniels wrote: > Kay Schluehr wrote: > > On 24 Jan., 09:21, "Gabriel Genellina" wrote: > >> If you run A.py as a script, it does not "know" it lives inside a package. > >> You must *import* A for it to become aware of the package. > >> Also, the directory containing the script comes earlier than PYTHONPATH > >> entries in sys.path -- so watch for that case too. > > Thanks, yes. I always make the same error thinking that a directory > > with the ritual __init__ file is actually a package ( as some kind of > > platonic entity ), something that is more obvious to me than it is to > > the runtime. The relative import semantics introduced with Python 2.5 > > has made the error just visible that was hidden to me for about a > > decade. Shit. > > Temper the language a bit. You lose your effectiveness by some people > reading the color of your words, rather than their meaning in code. Sigh, yes... sorry. I'm just too frustrated. Actually I don't even know why the import machinery is such a mess and I don't want to spend a huge amount of time ( like Brett Cannon ) to figure it out. I'll spent a few hours of time writing a script that turns all relative paths into absolute ones without changing the source otherwise. Then I'm at least done with that and won't ever see the "relative import in non-packages" exceptions anymore in any code I touch ( I can also ignore __package__, -m and all the other workarounds ). It's not the first time Python is in my way but this time it hurts. From xahlee at gmail.com Sun Jan 25 00:19:28 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 21:19:28 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> <1c66ef53-22a3-46b5-8fb5-3cde3deafaf3@p23g2000prp.googlegroups.com> Message-ID: Addendum: The above is not a terrible insight, but i suppose it should be useful for some application. Today, there's huge number of languages, each screaming ME! To name a few that are talked about by geekers, there's Arc, Clojure, Scalar, F#, Erlang, Ruby, Groovy, Python 3, Perl6. (for a big list, see: Proliferation of Computing Languages) So, if i want to learn another lang down the road, and wish it to be a joy to use, usable docs, large number of usable libraries, or well supported, practical community that doesn't loop into monad or tail recursion every minute, then which one should i buy? With criterions of industrial background, not culty, lang beauty matter not that much, in mind, i think Erlang, F# would be great choices, while langs like Qi, Oz, Arc, Perl6, would be most questionable. Perm url: ? Language, Purity, Cult, and Deception http://xahlee.org/UnixResource_dir/writ/lang_purity_cult_deception.html http://xahlee.blogspot.com/2009/01/language-purity-cult-and-deception.html Xah ? http://xahlee.org/ ? From kyrie at uh.cu Sun Jan 25 00:54:38 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 25 Jan 2009 00:54:38 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <1232862878.497bfe9ed3292@mail.uh.cu> Quoting "Russ P." : > Once again, if you have the source code for the library (and the right > to modify it), how does the "power" lie with the library implementer > rather than you the user? > > You say you don't want to "fork" the library. Let's stipulate for the > sake of argument that a one-line change is indeed a "fork." It is. For starters, I'd lose the information of "this attribute was intended to be internal and I'm accessing it anyway". > Think > about what you are saying. You are saying that you should dictate how > the producer of the library should implement it because you don't want > to be bothered to "fork" it. No. I am not dictating _anything_. The beauty of it, you don't have to do _anything_ for this to happen. Now, you may say that I'm trying to force you to relax and do nothing instead of complaining because the language I use doesn't put enough restrictions on me. > If you don't like his design decisions, > shouldn't the onus be on *you* to make the trivial change necessary to > get access to what you want? Or contacting him about it and maybe send him a patch, sure, why not. But this has nothing to do with enforced data hiding. Having obj._public_var is just as badly designed as having "private public_var". > Imagine a person who repairs computers. He is really annoyed that he > constantly has to remove the cover to get at the guts of the computer. > So he insists that computers cases should be made without covers. > After all, manufacturers put covers on computers only because they > don't trust us and think we're too "stupid" to safely handle an > uncovered computer box. > > That is logically equivalent to your position on enforced access > restrictions in software. Do you realize that most computer cases are trivially easy to open? (Nevermind that there are other reasons... dust, protection against physical damage, etc. My PC is locked enough to protect them, but opened enough so I can "play" with it whenever I need) > > And, FYI, when programming in java, C++ or C#, I do use "private" and > > "protected" variables, not becasue I want to forbid others from using it, > but > > because it is [rightly?] assumed that everything marked as public is safe > to use > > - and I consider that a strong enough "external" reason to do it. > > You could just use leading underscores and note their meaning in the > documentation. If that's such a great approach, why not do it? Yes, I > know, it's not a widely used convention in those other languages. Fair > enough. It is not a widely used convention, and that is reason enough for me. It's quite a contradiction to say in the code "this thing is safe to use" and then document it as "highly unsafe - do not touch". With Java and C# I'm more lenient (and work more with explicit interfaces rather than just the public/protected/private thing). BTW, the actual 'private' case for most languages is a different beast: it is used to prevent namespace pollution/name clashes. I can't easily simulate those with public attributes in C#/Java/C++ (but I concede that their 'privates' do a better job at this than python's self.__local) > But you could still do it if it's such a good idea. I think someone commented in this thread about a case where he had to do exactly that. [copying from your other reply] > But what if I want an automatic check to verify that I am using it as > the author intended? Is that unreasonable? Think of enforced access > restriction as an automatic "assert" every time an attribute is > accessed that it is not a private attribute. I think that was a reply to a message where I said that I used pylint run those checks on third party libraries. And I obviously can do the same with my own code. I don't have threading now, so I can't check if I really said that. If I didn't, well, I'm saying it now. Now, as Paul Robin pointed out, those statics checks done by pylint can't catch a runtime workaround using eval, exec or getattr/setattr. But neither can C++. By the way, I urge you to try to write code that pylint doesn't complain about. It's easy to not be satisfied with the checks it provides if you haven't used it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From tmohr at s.netic.de Sun Jan 25 01:55:47 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 25 Jan 2009 07:55:47 +0100 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import Message-ID: Hi, i try to write a plugin system that i want to use to let users extend a module that i write. Within the module there is an extension loader that loads an extension module. This extension module should be able to import modules from my system, which provides some extensions. Basically, this here works but gives a warning: RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import Below are the files, i wonder what is wrong. It would be great if anybody could give me a hint, what provokes that warning? Best regards, Torsten. FILE psys.py: import mymodule.ext_loader import sys import os.path here = os.path.abspath('.') mpath = os.path.abspath('mymodule') epath = os.path.abspath('extension') sys.path.append(here) sys.path.append(mpath) mymodule.ext_loader.load('ext_abc') FILE mymodule/__init__.py: __all__ = ['base', 'ext_loader'] FILE mymodule/ext_loader.py: import imp import os.path def search_file(fname): for e in ['extension']: candidate = os.path.join(os.path.expanduser(e), fname) if os.path.exists(candidate): return candidate return None def load(modname): fname = modname + ".py" abname = search_file(fname) fd = open(abname, "rb") mod = imp.load_module(fname, fd, abname, ['py', 'r', imp.PY_SOURCE]) fd.close() FILE mymodule/base.py: def func1(): print "func1 called !" FILE extension/ext_abc.py: import base base.func1() From Russ.Paielli at gmail.com Sun Jan 25 02:11:59 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 23:11:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> On Jan 24, 9:54?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > Once again, if you have the source code for the library (and the right > > to modify it), how does the "power" lie with the library implementer > > rather than you the user? > > > You say you don't want to "fork" the library. Let's stipulate for the > > sake of argument that a one-line change is indeed a "fork." > > It is. For starters, I'd lose the information of "this attribute was intended to > be internal and I'm accessing it anyway". Not really. When you get a new version of the library and try to use it, you will quickly get a reminder about the change (assuming your tests provide sufficient converage, and also assuming that the attribute is not made public in the new version). So you don't really even need to keep track of the change. > > Think > > about what you are saying. You are saying that you should dictate how > > the producer of the library should implement it because you don't want > > to be bothered to "fork" it. > > No. I am not dictating _anything_. The beauty of it, you don't have to do > _anything_ for this to happen. You are trying to dictate that the library implementer not be allowed to use enforced access restriction. And, in the larger sense, you are trying to dictate that access restrictions not be enforced in Python. > Now, you may say that I'm trying to force you to relax and do nothing instead of > complaining because the language I use doesn't put enough restrictions on me. And you are trying to put restrictions on anyone who might prefer to enforce access restrictions. If you don't allow them to do that, you are restricting them. > > If you don't like his design decisions, > > shouldn't the onus be on *you* to make the trivial change necessary to > > get access to what you want? > > Or contacting him about it and maybe send him a patch, sure, why not. But this > has nothing to do with enforced data hiding. Having obj._public_var is just as > badly designed as having "private public_var". Sure, go ahead and contact him. If he agrees that a private attribute should be public, then the problem is solved. But if he does not agree, he should not be forced to bend to your desire. > > Imagine a person who repairs computers. He is really annoyed that he > > constantly has to remove the cover to get at the guts of the computer. > > So he insists that computers cases should be made without covers. > > After all, manufacturers put covers on computers only because they > > don't trust us and think we're too "stupid" to safely handle an > > uncovered computer box. > > > That is logically equivalent to your position on enforced access > > restrictions in software. > > Do you realize that most computer cases are trivially easy to open? (Nevermind That was exactly my point. Deleting the word "private" (or whatever) is also trivially easy if you have access to the source code. From kyrie at uh.cu Sun Jan 25 03:13:14 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 25 Jan 2009 03:13:14 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> Message-ID: <1232871194.497c1f1a2f3b1@mail.uh.cu> Quoting "Russ P." : > On Jan 24, 9:54 pm, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > > > > It is. For starters, I'd lose the information of "this attribute was > intended to > > be internal and I'm accessing it anyway". > > Not really. When you get a new version of the library and try to use > it, you will quickly get a reminder about the change (assuming your > tests provide sufficient converage, and also assuming that the > attribute is not made public in the new version). So you don't really > even need to keep track of the change. See? With every new version that doesn't change the behaviour, I have to modify the source just to see if the tests run. That _is_ a fork. And that's assuming the bright case where I have the source. > > No. I am not dictating _anything_. The beauty of it, you don't have to do > > _anything_ for this to happen. > > You are trying to dictate that the library implementer not be allowed > to use enforced access restriction. And, in the larger sense, you are > trying to dictate that access restrictions not be enforced in Python. Now, please, explain to me, why are you so interested on preventing me from using the internals on my computer? If you want controls in the code that runs on your system, you can. > > Or contacting him about it and maybe send him a patch, sure, why not. But > this > > has nothing to do with enforced data hiding. Having obj._public_var is just > as > > badly designed as having "private public_var". > > Sure, go ahead and contact him. If he agrees that a private attribute > should be public, then the problem is solved. But if he does not > agree, he should not be forced to bend to your desire. Wait, if I change my project to ignore the data hiding (enforced or not), am I forcing the author to bend for my desire? Please explain your reasoning. Or better yet... don't. I will just give up, right now. This is no longer about "security", "good practices", "software engineering", "bug catching" or "formal proofs" as you've tried to paint it before. This is about you wanting to control how others use your code. And while it may be your legal right, that isn't the discussion I thought I was getting into. From akitada at gmail.com Sun Jan 25 03:18:28 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 17:18:28 +0900 Subject: Pythonic list/tuple/dict layout? Message-ID: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Hi, There is more than one way to write a list/tuple/dict in Python, and actually different styles are used in standard library. As a hobgoblin of little minds, I rather like to know which style is considered "Pythonic" in the community. I collected common layout from existing code and pasted them below. My vote would go to d1. How about yours? If there is consensus on this, that might be worth being included in PEP 8. Thanks, """ d1 = { 0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } d2 = { 0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot",} d3 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } d4 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot",} d5 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } """ From shansen at advpubtech.com Sun Jan 25 03:22:21 2009 From: shansen at advpubtech.com (Stephen Hansen) Date: Sun, 25 Jan 2009 00:22:21 -0800 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> References: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Message-ID: <7a9c25c20901250022v9b76ad3nb986b904ef9f0e5a@mail.gmail.com> > and pasted them below. > My vote would go to d1. How about yours? > > Whatever reads best within the context of the specific code is Pythonic. -------------- next part -------------- An HTML attachment was scrubbed... URL: From danb_83 at yahoo.com Sun Jan 25 03:51:24 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Sun, 25 Jan 2009 00:51:24 -0800 (PST) Subject: Pythonic list/tuple/dict layout? References: Message-ID: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> On Jan 25, 2:18?am, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. > As a hobgoblin of little minds, I rather like to know which style is > considered "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in PEP 8. > > Thanks, > > """ > d1 = { > ? ? 0: "ham", > ? ? 1: "jam", > ? ? 2: "spam", > ? ? 3: "alot", > ? ? 4: "knights", > ? ? 5: "who", > ? ? 6: "say", > ? ? 7: "ni", > ? ? 8: "dead", > ? ? 9: "parrot", > > } > [snip] I use d1. Wow! A Python debate over curly brace placement! Imagine that! From bj_666 at gmx.net Sun Jan 25 04:13:34 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 25 Jan 2009 09:13:34 GMT Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: <6u2opuFd9kl4U1@mid.uni-berlin.de> On Sat, 24 Jan 2009 01:02:01 +0100, ?????? ??????????? wrote: >>> I don't know what an IBQ is. >> >> +IBQ- seems to be the way your newsreader displays the dashes that >> where in Ben's posting. I see "em dash" characters there: > > I see IBQ too ... also weird is that he has Content-Type: text/plain; > charset=utf-7 Why weird? Makes perfect sense: In [98]: print '+IBQ-'.decode('utf-7') ? In [99]: unicodedata.name('+IBQ-'.decode('utf-7')) Out[99]: 'EM DASH' So there are newsreaders out there that can't or at least don't decode UTF-7. Ciao, Marc 'BlackJack' Rintsch From akitada at gmail.com Sun Jan 25 04:51:38 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 18:51:38 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> References: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> Message-ID: <90bb445a0901250151g2211f997ue672dce4edea72f3@mail.gmail.com> > Wow! A Python debate over curly brace placement! Imagine that! PEP8 even deals with tabs vs spaces, where to put a blank line, etc :) From m.iatrou at freemail.gr Sun Jan 25 05:16:12 2009 From: m.iatrou at freemail.gr (Michael Iatrou) Date: Sun, 25 Jan 2009 12:16:12 +0200 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> References: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Message-ID: <200901251216.12715.m.iatrou@freemail.gr> When the date was Sunday 25 January 2009, Akira Kitada wrote: > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. I would vote for d1, but I don't think that this is more "pythonic", I just consider it more "clean", according to my personal aesthetic criteria. :> -- Michael Iatrou (yxzb) From gagsl-py2 at yahoo.com.ar Sun Jan 25 05:24:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 08:24:43 -0200 Subject: Regex for Python 2.7 References: <497B78D7.4040808@mrabarnett.plus.com> <497BA983.6010903@mrabarnett.plus.com> Message-ID: En Sat, 24 Jan 2009 21:51:31 -0200, MRAB escribi?: > Gabriel Genellina wrote: > > En Sat, 24 Jan 2009 18:23:51 -0200, MRAB > > escribi?: > > > >> Some time ago I discovered this difference between regular > expressions > >> in Python and Perl: > >> > >> Python > >> > >> \A matches at start of string > >> \Z matches at end of string > >> > >> Perl > >> > >> \A matches at start of string > >> \Z matches before terminal newline or at end of string > >> \z matches at end of string > >> > >> In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A > == ^ > >> and \Z != $ in single-string mode. > > > > Why do you want the two to be equivalent? Isn't a good thing that you > > have both alternatives (\Z and $)? Use whichever is adequate in each > case. > > > Python's \Z is equivalent to Perl's \z, but there's no equivalent to > Perl's \Z in multi-line mode. I tested both: import re texts = ["abc\ndef", "abc\n", "abc"] exprs = [ re.compile(r"c$"), re.compile(r"c\Z"), re.compile(r"c$", re.MULTILINE), re.compile(r"c\Z", re.MULTILINE), ] for text in texts: for expr in exprs: m = re.search(expr, text) print repr(text), expr.pattern, "match" if m else "no match" c:\temp>python test_re.py 'abc\ndef' c$ no match 'abc\ndef' c\Z no match 'abc\ndef' c$ match 'abc\ndef' c\Z no match 'abc\n' c$ match 'abc\n' c\Z no match 'abc\n' c$ match 'abc\n' c\Z no match 'abc' c$ match 'abc' c\Z match 'abc' c$ match 'abc' c\Z match @texts = ("abc\ndef", "abc\n", "abc"); @exprs = (qr/c$/, qr/c\Z/, qr/c$/m, qr/c\Z/m, # qr/c\z/, # qr/c\z/m ); foreach $text (@texts) { ($repr = $text) =~ s/\n/\\n/g; foreach $expr (@exprs) { print $repr, " ", $expr, " "; if ($text =~ $expr) { print "match\n"; } else { print "no match\n"; } } } c:\temp>perl test_re.pl abc\ndef (?-xism:c$) no match abc\ndef (?-xism:c\Z) no match abc\ndef (?m-xis:c$) match abc\ndef (?m-xis:c\Z) no match abc\n (?-xism:c$) match abc\n (?-xism:c\Z) match abc\n (?m-xis:c$) match abc\n (?m-xis:c\Z) match abc (?-xism:c$) match abc (?-xism:c\Z) match abc (?m-xis:c$) match abc (?m-xis:c\Z) match If one wants to match end-of-line or end-of-string, use $ in multiline mode. If one wants to match end-of-string only, use \Z. If one wants to match end-of-line only, use \n [not shown]. -- Gabriel Genellina From amvds at xs4all.nl Sun Jan 25 05:38:31 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 25 Jan 2009 10:38:31 GMT Subject: IDLE/Python on Asus EEE PC Message-ID: <497c4127$0$188$e4fe514c@news.xs4all.nl> Simple Python programs edited and run through IDLE work fine on my Ubuntu Linux system without any editing. However on my Asus EEE PC IDLE complains about incorrect formatting (indentation) or possibly mixing tabs/spaces. The source code is exactly the same. There is no incorrect formatting and certainly no use of tabs. I created the program on my EEE, was unable to find anything wrong with it and decided to test it on my desktop. I was amazed that it runs fine there. Can anyone explain this? I use the full desktop Xandros OS on the EEE. I downloaded IDLE from the Debian repositories. Thanks in advance, Alex van der Spek From kay.schluehr at gmx.net Sun Jan 25 06:03:05 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sun, 25 Jan 2009 03:03:05 -0800 (PST) Subject: Dynamic methods and lambda functions References: Message-ID: On 23 Jan., 13:28, unine... at gmail.com wrote: > Hi, > I want to add some properties dynamically to a class, and then add the > corresponding getter methods. Something resulting in this: > > class Person: > def Getname(self): > return self.__name > > def Getage(self): > return self.__age > > I've implemented the next code, creating the properties from a list: > > props = [ > ("name", "peter"), > ("age", 31), > ("wife", "mary") > ] > > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) > > if __name__ == "__main__": > > person = Person() > > print person.__name > print person.__age > print person.__wife > print > print person.Getname() > print person.Getage() > print person.Getwife() > > And the resulting execution of this program is: > > peter > 31 > mary > > mary > mary > mary > > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? > > Thanks in advance The standard trick is to "de-closure" the lambda using a keyword argument. So instead of writing lambda self: getattr(self, "__" + prop[0])) you might write lambda self, prop = prop: getattr(self, "__" + prop[0])) Now prop is local to the lambda and the lambda doesn't look up prop in the enclosing environment which certainly stores its last value. From bignose+hates-spam at benfinney.id.au Sun Jan 25 06:32:40 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 25 Jan 2009 22:32:40 +1100 Subject: Pythonic list/tuple/dict layout? References: Message-ID: <871vur39k7.fsf@benfinney.id.au> Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in > PEP 8. > > Thanks, > > """ > d1 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot", > } > > d2 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot",} These are the only two that follow PEP 8; the others don't have four-space indent levels. I actually use this style: foo = { 0: 'spam', 1: 'eggs', 2: 'beans', } because that makes it clear that *all* the indented lines are a continuation of the same statement, just like a suite of statements are all uniformly indented under (e.g.) a function definition. It seems that the author of the Python editing mode in Emacs agrees with me too (the style, at least, if not the reasoning), which makes my programming life easier. -- \ ?The future always arrives too fast, and in the wrong order.? | `\ ?Alvin Toffler | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 07:10:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jan 2009 12:10:26 GMT Subject: Pythonic list/tuple/dict layout? References: Message-ID: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:18:28 +0900, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, and > actually different styles are used in standard library. As a hobgoblin > of little minds, I rather like to know which style is considered > "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. My > vote would go to d1. How about yours? All of them. BTW, there's no need to use such large examples. Three items per dict would be sufficient to illustrate the styles, using ten items doesn't add anything useful to the discussion. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 07:21:31 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jan 2009 12:21:31 GMT Subject: Is (-1 ==True) True or False? Neither References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: <018c4f8f$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 03:07:04 +0200, Oktay ?afak wrote: > The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. If I wrote (-1 == True), and I'm not sure why I would, I would expect to get the answer False, because -1 is not equal to True. Many things have truth values which are true but not equal to True. If I wanted bool(-1) == True, I'd write bool(-1) == True. Or, if I was in a whimsical mood, I'd write: ((bool(-1) == True) == True) == True # oh when to stop??? just to illustrate the foolishness of doing boolean equality comparisons like that. -- Steven From akitada at gmail.com Sun Jan 25 07:25:12 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 21:25:12 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> References: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <90bb445a0901250425v9f6ab7dudf77063f6c9acae2@mail.gmail.com> > BTW, there's no need to use such large examples. Three items per dict > would be sufficient to illustrate the styles, using ten items doesn't add > anything useful to the discussion. I worried to be told 'you can make it in a line like {"ham": "jam", "spam": "alot"}' ;) From akitada at gmail.com Sun Jan 25 07:36:36 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 21:36:36 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <871vur39k7.fsf@benfinney.id.au> References: <871vur39k7.fsf@benfinney.id.au> Message-ID: <90bb445a0901250436k2da085fcy2ceaa4ee6b05bada@mail.gmail.com> > These are the only two that follow PEP 8; the others don't have > four-space indent levels. In those examples, the following sentence in PEP 8 would be applied. "Make sure to indent the continued line appropriately." > I actually use this style: > > foo = { > 0: 'spam', > 1: 'eggs', > 2: 'beans', > } > > because that makes it clear that *all* the indented lines are a > continuation of the same statement, just like a suite of statements > are all uniformly indented under (e.g.) a function definition. > > It seems that the author of the Python editing mode in Emacs agrees > with me too (the style, at least, if not the reasoning), which makes > my programming life easier. Yes, it does, but people around me tend to prefer d1 style to that one. One purpose of this silly thread is to figure out which is most popular one... From notvalid2 at sbcglobal.net Sun Jan 25 07:49:20 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 25 Jan 2009 04:49:20 -0800 Subject: What is intvar? In-Reply-To: References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: Steve Holden wrote: > W. eWatson wrote: >> W. eWatson wrote: >>> r wrote: >>>> here is a good explanation of control vars: >>>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >>>> >>>> Here are 3 great Tkinter refernces in order: >>>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >>>> http://effbot.org/tkinterbook/ >>>> http://www.pythonware.com/library/tkinter/introduction/ >>> Thanks to all for the reference and tips. >>> >> tkinterbook is easy to follow, but it seems to have been abandoned in >> 2005. Did it appear in another guise somewhere else? >> > There hasn't been a lot of development on Tkinter in the intervening > period. It's a mature system, so there has been no need to update the > documentation. > > regards > Steve Unfortunately, the author seems to have stopped mid-stream. I see a fair number of FIXMEs in it. It looks like the New Mexico pdf is a fitting replacement. Perhaps Intro to Tkinter should be scrapped? Another of the author's writings, on PIL, looks good as a pdf, but is missing a TOC. Maybe some pdf knowledgeable person knows how to generate one easily. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From vicente.soler at gmail.com Sun Jan 25 08:32:38 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 25 Jan 2009 05:32:38 -0800 (PST) Subject: Newby: how to transform text into lines of text Message-ID: Hello, I'va read a text file into variable "a" a=open('FicheroTexto.txt','r') a.read() "a" contains all the lines of the text separated by '\n' characters. Now, I want to work with each line separately, without the '\n' character. How can I get variable "b" as a list of such lines? Thank you for your help From deets at nospam.web.de Sun Jan 25 08:36:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 14:36:15 +0100 Subject: Newby: how to transform text into lines of text In-Reply-To: References: Message-ID: <6u386gFdd2ocU1@mid.uni-berlin.de> vsoler schrieb: > Hello, > > I'va read a text file into variable "a" > > a=open('FicheroTexto.txt','r') > a.read() > > "a" contains all the lines of the text separated by '\n' characters. No, it doesn't. "a.read()" *returns* the contents, but you don't assign it, so it is discarded. > Now, I want to work with each line separately, without the '\n' > character. > > How can I get variable "b" as a list of such lines? The idiomatic way would be iterating over the file-object itself - which will get you the lines: with open("foo.txt") as inf: for line in inf: print line The advantage is that this works even for large files that otherwise won't fit into memory. Your approach of reading the full contents can be used like this: content = a.read() for line in content.split("\n"): print line Diez From detlev at die-offenbachs.de Sun Jan 25 08:40:46 2009 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 25 Jan 2009 14:40:46 +0100 Subject: ANN: new snapshot of the eric4 Pylons plugin released Message-ID: Hi, this is to inform everybody about the availability of the Pylons plugin for eric4. It adds Pylons support to the eric4 Python IDE. The Plugin is available via the eric4 web site at http://eric-ide.python-projects.org/index.html What is eric4 ------------- eric4 is a Python IDE, that comes with batteries included. It is extensible via a plugin system. Please see the a.m. web site for more details. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From cousinstanley at gmail.com Sun Jan 25 08:44:56 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 25 Jan 2009 13:44:56 +0000 (UTC) Subject: *.python.org broken? References: Message-ID: > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) Yes, connecting to python.org sites has been problematic for me as well .... I don't remember when the trouble started, but it's been problematic for at least a week or longer here .... -- Stanley C. Kitching Human Being Phoenix, Arizona From python.list at tim.thechases.com Sun Jan 25 08:54:13 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 07:54:13 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: <6u386gFdd2ocU1@mid.uni-berlin.de> References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <497C6F05.9010002@tim.thechases.com> > The idiomatic way would be iterating over the file-object itself - which > will get you the lines: > > with open("foo.txt") as inf: > for line in inf: > print line In versions of Python before the "with" was introduced (as in the 2.4 installations I've got at both home and work), this can simply be for line in open("foo.txt"): print line If you are processing lots of files, you can use f = open("foo.txt") for line in f: print line f.close() One other caveat here, "line" contains the newline at the end, so you might have print line.rstrip('\r\n') to remove them. > content = a.read() > for line in content.split("\n"): > print line Strings have a "splitlines()" method for this purpose: content = a.read() for line in content.splitlines(): print line -tkc From vicente.soler at gmail.com Sun Jan 25 09:04:41 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 25 Jan 2009 06:04:41 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: On 25 ene, 14:36, "Diez B. Roggisch" wrote: > vsoler schrieb: > > > Hello, > > > I'va read a text file into variable "a" > > > ? ? ?a=open('FicheroTexto.txt','r') > > ? ? ?a.read() > > > "a" contains all the lines of the text separated by '\n' characters. > > No, it doesn't. "a.read()" *returns* the contents, but you don't assign > it, so it is discarded. > > > Now, I want to work with each line separately, without the '\n' > > character. > > > How can I get variable "b" as a list of such lines? > > The idiomatic way would be iterating over the file-object itself - which > will get you the lines: > > with open("foo.txt") as inf: > ? ? ?for line in inf: > ? ? ? ? ?print line > > The advantage is that this works even for large files that otherwise > won't fit into memory. Your approach of reading the full contents can be > used like this: > > content = a.read() > for line in content.split("\n"): > ? ? ?print line > > Diez Thanks a lot. Very quick and clear From steve at holdenweb.com Sun Jan 25 09:08:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 09:08:27 -0500 Subject: *.python.org broken? In-Reply-To: References: Message-ID: Cousin Stanley wrote: >> Is anybody else having trouble accessing sites (including www, docs, >> wiki) in the python.org tree, or is it just me? (Or just .au?) > > Yes, connecting to python.org sites has been problematic > for me as well .... > > I don't remember when the trouble started, but it's been > problematic for at least a week or longer here .... > > Perhaps traceroute might start to provide some information about the problem. As far as I know there haven't been any unscheduled outages on the python.org servers recently. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From alan.isaac at gmail.com Sun Jan 25 09:28:30 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sun, 25 Jan 2009 14:28:30 GMT Subject: Python 3: range objects cannot be sliced Message-ID: On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > It is documented: > http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support ?extended slicing? Is this a documentation bug, or a bug in `range`? (I'd think the latter.) Cheers, Alan Isaac From google at mrabarnett.plus.com Sun Jan 25 09:48:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 14:48:42 +0000 Subject: IDLE/Python on Asus EEE PC In-Reply-To: <497c4127$0$188$e4fe514c@news.xs4all.nl> References: <497c4127$0$188$e4fe514c@news.xs4all.nl> Message-ID: <497C7BCA.6040801@mrabarnett.plus.com> Alex van der Spek wrote: > Simple Python programs edited and run through IDLE work fine on my Ubuntu > Linux system without any editing. > > However on my Asus EEE PC IDLE complains about incorrect formatting > (indentation) or possibly mixing tabs/spaces. The source code is exactly > the same. There is no incorrect formatting and certainly no use of tabs. > > I created the program on my EEE, was unable to find anything wrong with > it and decided to test it on my desktop. I was amazed that it runs fine > there. > > Can anyone explain this? I use the full desktop Xandros OS on the EEE. I > downloaded IDLE from the Debian repositories. > If it's not tabs, then is it line endings? From akitada at gmail.com Sun Jan 25 10:05:35 2009 From: akitada at gmail.com (Akira Kitada) Date: Mon, 26 Jan 2009 00:05:35 +0900 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <90bb445a0901250705o221c11cpa861e4266394e374@mail.gmail.com> http://downforeveryoneorjustme.com/ On Sun, Jan 25, 2009 at 10:06 AM, wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Cheers, > > Tim > -- > http://mail.python.org/mailman/listinfo/python-list > From pdorange at pas-de-pub-merci.mac.com Sun Jan 25 10:14:54 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sun, 25 Jan 2009 16:14:54 +0100 Subject: [MacOS] Multiple versions of a module Message-ID: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> How to manage a module with several versions on MacOS X ? All modules are installed in : "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pa ckages/" This is the default path for Mac. But for some modules i need several version (stable 1.8.1 and test 1.9.0 for example : for pygame here). I've installed the stable one from source and i go into a "pygame-1.8.0release-py2.5-macosx-10.3-i386.egg" directory. Nice. I just install the 1.9 (for test) and it go into "pygame" directory So now i got 2 versions of pygame in the site-packages dir... When i import "pygam e" from python, the 1.8.0 is imported only and 1.9.0 is complely ignored... How do python choose from several package ? Do package register them elsewhere ? I don't know how to test (temporaly) the 1.9, but also be able to go back easily to 18.8 after ? I do a site._test() and i return my only 1.8.0 module for pygame, 1.9.0 is ignored. The same with Any clue ? -- Pierre-Alain Dorange From ra.ravi.rav at gmail.com Sun Jan 25 10:27:33 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 25 Jan 2009 07:27:33 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> > Take a look at the struct and ctypes modules. struct is really not the choice. it returns an expanded string of the data and this means larger latency over bluetooth. ctypes is basically for the interface with libraries written in C (this I read from the python docs) From ra.ravi.rav at gmail.com Sun Jan 25 10:28:05 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 25 Jan 2009 07:28:05 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> Message-ID: <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> On Jan 25, 12:52?am, "Martin v. L?wis" wrote: > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > > packet_data(variable) > > > How to construct these using python data types, as int and float have > > no limits and their sizes are not well defined. > > In Python 2.x, use the regular string type: chr(n) will create a single > byte, and the + operator will do the concatenation. > > In Python 3.x, use the bytes type (bytes() instead of chr()). This looks really helpful thanks! From lkcl at lkcl.net Sun Jan 25 10:44:02 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sun, 25 Jan 2009 15:44:02 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: > Have you made some benchmarks like pystone? > Cheers, > Cesare Cesare, hi, thanks for responding: unfortunately, there's absolutely no point in making any benchmark figures under an emulated environment which does things like take 2 billion instruction cycles to start up a program named "c:/msys/bin/sh.exe", due to it inexplicably loading 200 GUI-only truetype fonts. and to do benchmarks on say windows would require that i install ... windows! so if somebody else would like to make some benchmarks, and publish them, they are most welcome to do so. l. From deets at nospam.web.de Sun Jan 25 11:17:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 17:17:40 +0100 Subject: [MacOS] Multiple versions of a module In-Reply-To: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> References: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> Message-ID: <6u3hl4Fdarm3U1@mid.uni-berlin.de> Pierre-Alain Dorange schrieb: > How to manage a module with several versions on MacOS X ? > > All modules are installed in : > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pa > ckages/" > This is the default path for Mac. > > But for some modules i need several version (stable 1.8.1 and test 1.9.0 > for example : for pygame here). > > I've installed the stable one from source and i go into a > "pygame-1.8.0release-py2.5-macosx-10.3-i386.egg" directory. Nice. > > I just install the 1.9 (for test) and it go into "pygame" directory > > So now i got 2 versions of pygame in the site-packages dir... > > When i import "pygam > e" from python, the 1.8.0 is imported only and 1.9.0 is complely > ignored... How do python choose from several package ? > Do package register them elsewhere ? > I don't know how to test (temporaly) the 1.9, but also be able to go > back easily to 18.8 after ? > > I do a site._test() and i return my only 1.8.0 module for pygame, 1.9.0 > is ignored. The same with Use the excellent virtualenv-package from Ian Bicking. http://pypi.python.org/pypi/virtualenv Nowaday,s nearly everything I develop first gets it's own VE before anything is installed. Diez From aahz at pythoncraft.com Sun Jan 25 11:18:35 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jan 2009 08:18:35 -0800 Subject: Logging help References: Message-ID: In article , koranthala wrote: > Is it possible somehow to have the logging module rotate the files >every time I start it. If you're on Linux, why not use logrotate? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From madmax209 at gmail.com Sun Jan 25 11:37:07 2009 From: madmax209 at gmail.com (Max Leason) Date: Sun, 25 Jan 2009 08:37:07 -0800 (PST) Subject: Reading the first MB of a binary file Message-ID: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Hi, I'm attempting to read the first MB of a binary file and then do a md5 hash on it so that i can find the file later despite it being moved or any file name changes that may have been made to it. These files are large (350-1400MB) video files and i often located on a different computer and I figure that there is a low risk for generating the same hash between two files. The problem occurs in the read command which returns all \x00s. Any ideas why this is happening? Code: >>>>open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) b'\x00\x00\x00\x00\x00\x00....\x00' From rridge at csclub.uwaterloo.ca Sun Jan 25 11:45:08 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 25 Jan 2009 11:45:08 -0500 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 References: Message-ID: Luke Kenneth Casson Leighton wrote: >this is a progress report on compiling python using entirely free >software tools, no proprietary compilers or operating systems >involved, yet still linking and successfully running with msvcr80 >assemblies. MSVCR80.DLL is part of the Microsoft Visual C++ runtime library, and isn't "free software" in the FSF sense. It's free as in beer, but then so is the Microsoft compiler. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From google at mrabarnett.plus.com Sun Jan 25 12:05:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 17:05:00 +0000 Subject: Reading the first MB of a binary file In-Reply-To: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> References: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Message-ID: <497C9BBC.1030002@mrabarnett.plus.com> Max Leason wrote: > Hi, > > I'm attempting to read the first MB of a binary file and then do a > md5 hash on it so that i can find the file later despite it being > moved or any file name changes that may have been made to it. These > files are large (350-1400MB) video files and i often located on a > different computer and I figure that there is a low risk for > generating the same hash between two files. The problem occurs in the > read command which returns all \x00s. Any ideas why this is > happening? > > Code: >>>>> open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) > b'\x00\x00\x00\x00\x00\x00....\x00' > You're reading the first 1024 bytes. Perhaps the first 1024 bytes of the file _are_ all zero! Try reading more and checking those, eg: >>> SIZE = 1024 ** 2 >>> open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(SIZE) == b'\x00' * SIZE From python at bdurham.com Sun Jan 25 12:09:57 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 12:09:57 -0500 Subject: Efficient multi-slicing technique? Message-ID: <1232903397.3540.1296640123@webmail.messagingengine.com> Is there an efficient way to multi-slice a fixed with string into individual fields that's logically equivalent to the way one would slice a delimited string using .split()? Background: I'm parsing some very large, fixed line-width text files that have weekly columns of data (52 data columns plus related data). My current strategy is to loop through a list of slice()'s to build a list of the specific field values for each line. This is fine for small files, but seems inefficient. I'm hoping that there's a built-in (C based) or 3rd party module that is specifically designed for doing multiple field extractions at once. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Jan 25 12:12:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 12:12:58 -0500 Subject: Byte oriented data types in python In-Reply-To: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: Ravi wrote: >> Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. > If you read the module documentation more carefully you will see that it "converts" between the various native data types and character strings. Thus each native data type occupies only as many bytes as are required to store it in its native form (modulo any alignments needed). > ctypes is basically for the interface with libraries written in C > (this I read from the python docs) > I believe it *is* the struct module you need. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Sun Jan 25 12:23:35 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Sun, 25 Jan 2009 09:23:35 -0800 (PST) Subject: Counting number of objects Message-ID: Hi, I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following: class a(object): counter = 0 def __new__(cls, *args, **kwargs): a.counter += 1 return object.__new__(cls, *args, **kwargs) def __del__(self): a.counter -= 1 class aa(a): pass Now, the code works Ok. I have the following questions: 1. Is this code Ok? Is there any straightforward mechanism other than this to get the number of objects? 2. I read in Python Documentation that inside __del__ we should the minimum of interaction with external parameters. So, I am a little worried in subclassing __del__ to check the counter. Is whatever I have done Ok? Another question - unrelated to the major topic: How much time does it take to be proficient in Python? I have been working exclusively in Python for close to 3 months now, and even now I get inferiority complex when I read the answers sent by many of you. I have been programming for close to 7 years now (earlier in a language similar to COBOL). Does it take quite a bit of time to be proficient - as many of you guys - or am I just dumb? From steve at holdenweb.com Sun Jan 25 12:39:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 12:39:19 -0500 Subject: Counting number of objects In-Reply-To: References: Message-ID: Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls, *args, **kwargs): > a.counter += 1 > return object.__new__(cls, *args, **kwargs) > > def __del__(self): > a.counter -= 1 > > class aa(a): > pass > > Now, the code works Ok. I have the following questions: > 1. Is this code Ok? Is there any straightforward mechanism other than > this to get the number of objects? > 2. I read in Python Documentation that inside __del__ we should the > minimum of interaction with external parameters. So, I am a little > worried in subclassing __del__ to check the counter. Is whatever I > have done Ok? > Yes. Just be aware that if instances become involved in cyclic data structures (or in implementations other than CPython, where reference counting isn't used) __del__ might not be called until garbage collection kicks in, so you may want a more explicit way to stop an instance from being in the count. > Another question - unrelated to the major topic: > How much time does it take to be proficient in Python? I have been > working exclusively in Python for close to 3 months now, and even now > I get inferiority complex when I read the answers sent by many of you. > I have been programming for close to 7 years now (earlier in a > language similar to COBOL). > Does it take quite a bit of time to be proficient - as many of you > guys - or am I just dumb? By your code above you seem to be doing OK. Python is like an iceberg - only an eighth of what goes on is above the surface. That eighth will suffice for many people's total programming needs. I've been using Python ten years, and I am still learning. Just go at your own pace, and carry on asking for help when you need it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 12:46:10 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 11:46:10 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: On 2009-01-25, Ravi wrote: > >> Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. I don't know what you mean by "returns an expanded string of the data". I do know that struct does exactly what you requested. It converts between Python objects and what is bascially a C "struct" where you specify the endianness of each field and what sort of packing/padding you want. I use the struct module frequenty to impliment binary, communications protocols in Python. I've used Python/struct with transport layers ranging from Ethernet (raw, TCP, and UDP) to async serial, to CAN. -- From mdw at distorted.org.uk Sun Jan 25 13:04:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 18:04:26 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> Message-ID: <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Calling a one-word change a "fork" is quite a stretch, I'd say. I wouldn't. I've forked a project P if I've made a different version of it which isn't going to be reflected upstream. Now I've got to maintain my fork, merging in changes from upstream as they happen, and upgrading all the things which use my new version; if I want to distribute my program M to other people, they'll also need my forked version of whatever. Now suppose that two programs A and B both require one-word changes in P: there's a combinatorial explosion of little patches which need to be managed. A fork is a fork, regardless of how big the change is. The problem with a fork is the maintenance problem it entails. Besides, if I want to do some hacky debugging in ipython, should I really have to recompile and reinstall piles of libraries? >> > Has it occurred to you that some users might actually *want* access >> > controls? Maybe some users want to actually use the library as the >> > author intended it to be used. What a bizarre concept! >> >> Huh? >> Then... use it as the author intended. I am _not_ forcing you to use the >> obj._protected attributes! > > But what if I want an automatic check to verify that I am using it as > the author intended? Is that unreasonable? You mean that you can't /tell/ whether you typed mumble._seekrit? You're very strange. It's kind of hard to do by accident. I'd have thought that you could do that with grep, err... git grep '\._' | sed 's/self\._//g' | grep '\._' ought to do as a rough start. If you can't trust your programmers to make it clear when they're doing something dubious, I think you have bigger problems. -- [mdw] From geekmail at usenot.de Sun Jan 25 13:06:47 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sun, 25 Jan 2009 19:06:47 +0100 Subject: Counting number of objects References: Message-ID: <20090125190647.13bf4a71@usenot.de> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls, *args, **kwargs): > a.counter += 1 > return object.__new__(cls, *args, **kwargs) > > def __del__(self): > a.counter -= 1 > > class aa(a): > pass > This looks OK, although I'd suggest using "cls.counter += 1" instead of "a.counter += 1" in the __new__() method. Just seems clearer to me, esp. when you think about subclassing. This would create an asymmetry with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" there, even if it is a bit ugly-ish. Another way to go would be to use the weakref module and create a weakref-set (or list) as the counter. That way you would only need to add the objects in the __new__() method and not worry about removing them. I will admit that this is overengineering the problem a bit, but might be a good exercise. A third option could be to remove the counting functions from the class altogether. From an OO-Design point of view this would seem appropriate, because neither any individual nor mankind as a whole would know the exact amount of people in the world of hand. An entity that would actually count all the people in the world, however, would know and it makes sense to implement it separately (as a subclass of list with birth() and death() methods, for instance). I'm just saying this to give you something to think about, I'm not saying that it is necessarily better or worse for your example. > Now, the code works Ok. I have the following questions: > 1. Is this code Ok? Is there any straightforward mechanism other than > this to get the number of objects? I would say that you found the most obvious implementation there. Depending on your definition of "straightforward" you could do it as I outlined in my last example above, using explicit calls for births and deaths. This would remove the "behind the scenes" magic a bit, which may be a plus. > 2. I read in Python Documentation that inside __del__ we should the > minimum of interaction with external parameters. So, I am a little > worried in subclassing __del__ to check the counter. Is whatever I > have done Ok? > Again, seems good to me, unless you do some other trickery that may lead to __del__() not being called directly. In that case, do look at the weakref module. > Another question - unrelated to the major topic: > How much time does it take to be proficient in Python? Don't concern yourself with that question at all, is my advice. Most people can learn to write programs in under a week, and many still don't write *good* programs 20 years later. You'll get better over time, as long as you keep doing it. Thinking about that you're not good enough will just consume mental resources that would be better invested in your programs. > I have been > working exclusively in Python for close to 3 months now, and even now > I get inferiority complex when I read the answers sent by many of you. Hello?! :) Three months is *nothing* compared to the time those "many of you" folks have invested. Don't worry. Does it matter if you don't understand some stuff people write? As long as you pick out the stuff you do understand you're still gaining stuff from this group. > I have been programming for close to 7 years now (earlier in a > language similar to COBOL). Well, you have quite a background then. Why all the worries? > Does it take quite a bit of time to be proficient - as many of you > guys YES! Of course it does. > - or am I just dumb? You're writing programs and you're communicating with like-minded people about your problems (in a socially appropriate way). Not what dumb people do, in my book. cheers, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From mdw at distorted.org.uk Sun Jan 25 13:08:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 18:08:39 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <8763k38di0.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Imagine a person who repairs computers. He is really annoyed that he > constantly has to remove the cover to get at the guts of the computer. > So he insists that computers cases should be made without covers. Poor analogy. He gets fed up that the computers he's meant to be servicing are arriving in sealed containers which require specialist tools to open. > After all, manufacturers put covers on computers only because they > don't trust us and think we're too "stupid" to safely handle an > uncovered computer box. It's more to do with keeping dust out, keeping air circulating, and keeping fingers away from sharp edges. Fortunately most computers are actually shipped in cases one can remove easily, using household tools -- or even no tools at all. Why, anyone would think that you were supposed to be able to grub about in there! > That is logically equivalent to your position on enforced access > restrictions in software. It is now that I've fixed it. -- [mdw] From rhamph at gmail.com Sun Jan 25 13:34:46 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Sun, 25 Jan 2009 10:34:46 -0800 (PST) Subject: Pythonic list/tuple/dict layout? References: Message-ID: <701368b9-1b33-42f7-9a9f-c37e0375b1d7@q25g2000vbn.googlegroups.com> d1 From Russ.Paielli at gmail.com Sun Jan 25 13:57:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 10:57:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <25df08d2-520a-4f21-8166-77bfaf4a6067@g1g2000pra.googlegroups.com> On Jan 25, 10:04?am, Mark Wooding wrote: > "Russ P." writes: > > Calling a one-word change a "fork" is quite a stretch, I'd say. > > I wouldn't. ?I've forked a project P if I've made a different version of > it which isn't going to be reflected upstream. ?Now I've got to maintain > my fork, merging in changes from upstream as they happen, and upgrading > all the things which use my new version; if I want to distribute my > program M to other people, they'll also need my forked version of > whatever. ?Now suppose that two programs A and B both require one-word > changes in P: there's a combinatorial explosion of little patches which > need to be managed. > > A fork is a fork, regardless of how big the change is. ?The problem with > a fork is the maintenance problem it entails. Not really. A "fork" is something that *diverges* from the original. That means the differences *grow* over time. In this case, the differences will not grow over time (unless you access more private attributes). As I pointed out before, you don't even need to keep track of the changes you made. You will be automatically reminded as soon as you get a new version of the library and try to use it (again, assuming that your tests provide sufficient coverage and the attribute is not changed to public). > >> > Has it occurred to you that some users might actually *want* access > >> > controls? Maybe some users want to actually use the library as the > >> > author intended it to be used. What a bizarre concept! > > >> Huh? > >> Then... use it as the author intended. I am _not_ forcing you to use the > >> obj._protected attributes! > > > But what if I want an automatic check to verify that I am using it as > > the author intended? Is that unreasonable? > > You mean that you can't /tell/ whether you typed mumble._seekrit? > You're very strange. ?It's kind of hard to do by accident. ?I'd have If I have a team of 200 programmers, I can't easily tell if one of them did that somewhere. Why do people like you have such a hard time understanding that I'm not talking here about smallish programs with one or a few developers? And even with only one programmer, he might access "mumble._seekrit" for a debugging test, then forget to take it out. > thought that you could do that with grep, err... > > ? ? ? ? git grep '\._' | sed 's/self\._//g' | grep '\._' > > ought to do as a rough start. > > If you can't trust your programmers to make it clear when they're doing > something dubious, I think you have bigger problems. Yes, I think I have bigger problems. But I like the challenge. I don't think I'd be happy working on small problems, but to each his own. From python at bdurham.com Sun Jan 25 14:09:49 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 14:09:49 -0500 Subject: Monitor a FTP site for arrival of new/updated files Message-ID: <1232910590.24534.1296651319@webmail.messagingengine.com> Any suggestions on a best practice way to monitor a remote FTP site for the arrival of new/updated files? I don't need specific code, just some coaching on technique based on your real-world experience including suggestions for a utility vs. code based solution. My goal is to maintain a local collection of files synced with a remote FTP site and when I download a new/updated file locally, run a script to process it. The arrival and format of the files that I need to sync with are beyond my control (eliminating a rsync solution) ... all I have is a generic FTP connection to a specific FTP address. Note: The remote site I'm monitoring may have multiple uploads occuring at the same time. My basic strategy is to poll the remote directory on a regular basis and compare the new directory listing to a previous snapshot of the directory listing. If a file timestamp or size has changed (or a new file has appeared), then track this file as a changed file. Once a file has been marked as changed, wait polling cycles for the file timestamp and size to remain stable, then download it, and trigger a local script to process the file. In addition to detecting new or changed files, I would compare remote directory listings to my local sync folder and delete local files that no longer exist on the remote site. My concern about using a utility is the utility's ability to detect when a remote file has finished being updated. I don't want to download files that are still in the process of being updated - I only want to download new/updated files after they've been closed on the remote site. Any ideas appreciated! Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sun Jan 25 14:12:29 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 19:12:29 +0000 Subject: Efficient multi-slicing technique? In-Reply-To: <1232903397.3540.1296640123@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> Message-ID: <497CB99D.9060209@mrabarnett.plus.com> python at bdurham.com wrote: > Is there an efficient way to multi-slice a fixed with string into > individual fields that's logically equivalent to the way one would slice > a delimited string using .split()? > > Background: I'm parsing some very large, fixed line-width text files > that have weekly columns of data (52 data columns plus related data). My > current strategy is to loop through a list of slice()'s to build a list > of the specific field values for each line. This is fine for small > files, but seems inefficient. I'm hoping that there's a built-in (C > based) or 3rd party module that is specifically designed for doing > multiple field extractions at once. > You could try the struct module: >>> import struct >>> struct.unpack("3s4s1s", b"123abcdX") ('123', 'abcd', 'X') From apt.shansen at gmail.com Sun Jan 25 14:32:40 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 25 Jan 2009 11:32:40 -0800 Subject: Byte oriented data types in python In-Reply-To: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: <7a9c25c20901251132t2cdcd0c1tf278091d1daef0a4@mail.gmail.com> On Sun, Jan 25, 2009 at 7:27 AM, Ravi wrote: > > > Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. Noo... struct really IS the choice; that is the explicit purpose of the struct library. I went and included an example too which you're not noticing :) Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import struct >>> data = struct.pack("BB4s", 1, 4, "this") >>> data '\x01\x04this' >>> That's precisely six raw bytes which is exactly what you specified you needed: exactly one unsigned byte for packet type, one unsigned byte for length, and four bytes for the data after. In real life you'd probably use something besides "4s" to pack what you marked as "other" and "variable", of course, but still. Replace it with whatever your message requires. Really, this is how you do line protocols ;) Well there's other ways, but... --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Sun Jan 25 14:54:45 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 20:54:45 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: <497cc386$0$7144$9b622d9e@news.freenet.de> >>> Take a look at the struct and ctypes modules. >> struct is really not the choice. it returns an expanded string of the >> data and this means larger latency over bluetooth. > > I don't know what you mean by "returns an expanded string of > the data". > > I do know that struct does exactly what you requested. I disagree. He has a format (type, length, value), with the value being variable-sized. How do you do that in the struct module? > It converts between Python objects and what is bascially a C > "struct" where you specify the endianness of each field and > what sort of packing/padding you want. Sure. However, in the specific case, there is really no C struct that can reasonably represent the data. Hence you cannot really use the struct module. > I use the struct module frequenty to impliment binary, > communications protocols in Python. I've used Python/struct > with transport layers ranging from Ethernet (raw, TCP, and UDP) > to async serial, to CAN. Do you use it for the fixed-size parts, or also for the variable-sized data? Regards, Martin From mdw at distorted.org.uk Sun Jan 25 14:56:31 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 19:56:31 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <871vur88i8.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: >> It makes sense... if the original author is an egotist who believes he >> must control how I use that library. > > Then I guess Guido must be such an egotist, because there's plenty of > internals in Python that you can't (easy) mess with. Time for some reflection. (Apposite word, as it turns out.) For the avoidance of doubt, I shall grant (and not grudgingly): * Abstraction is a useful tool in building complex systems. * Separating an interface from its implementation reduces the cognitive burden on people trying to reason about the system (including when doing design, developing clients, or trying to do more formal kinds of reasoning). * It also makes maintenance of the implementation easier: in the cases where this it's possible to improve the implementation without changing the interface, clients can benefit without having to be changed. I think that one of the reasons this conversation is going on for so long is that we haven't really talked much about what kinds of `messing' we're talking about. I think that, most of the time when I'm inconvenienced by some abstraction, it's because it's hiding something that I wanted to see -- in a read-only fashion. The implementation knows some fact that, for whatever reason, it's unwilling to reveal to me. I understand that, in some future version, the implementation might change and this fact might not be available then, or that it's an artifact of the way the implementation works in some environment -- but for whatever reason (debugging is a typical one as was pointed out upthread) it turns out that I'm actually interested in this fact. Revealing it to me can't actually hurt the invariants of the system, though I need to be somewhat careful about how long I assume it's correct. Of course, that should be entirely my responsibility. It's this common problem of wanting to dig out some piece of information which I'm really worried about. And `enforced data hiding' just slams the door in my face. I'm not best pleased by the idea. Anyway, in this regard, the CPython implementation is pretty much a paragon of virtue. It lets one get at almost everything one could want and a whole lot else besides. > Yes you could, and you could hack the OS to manipulate data behind the > scenes, and you could build a hardware device to inject whatever data > you want directly into the memory. You can do any of those things. So > what? > > Data hiding isn't about some sort of mythical 100% certainty against > any imaginable failure mode. Data hiding is a tool like any other, and > like all tools, it has uses and misuses, and it works under some > circumstances and not others. > > If you don't get 100% certainty that there will never be a failure no > matter what, what do you get? Just off the top of my head, it: How much of these do you /lose/ by having a somehat more porous interface? > * makes it easier for an optimising compiler to give fast code if it > doesn't have to assume internal details can be changed; Irrelevant for read-only inspection. For making modifications, this might be a valid point, though (a) I'm unaware of any compilers sufficiently aggressive to make very effective use of this, and (b) I'm probably willing to accommodate the compiler by being sufficiently careful about my hacking. That is: go ahead, use a fancy compiler, and I'll cope as best I can. > * makes it easier to separate interface from implementation when you > can trust that the implementation actually isn't being used; Irrelevant for read-only inspection. For making modifications: you carry on assuming that the interface is being used as you expect, and I'll take on the job of reasoning about invariants and making sure that everything continues to work. > * gives the developer more freedom to change the implementation; For read-only inspection, I might lose if you stop providing the information I want; I'll need to change my code, but you don't need to care. Probably if your implementation has changed that much, the information isn't relevant any more anyway. Besides, if your implementation changes break my code, I get to keep both pieces, and you get to laugh. What's the big deal? > * makes it possible for meaningful correctness proofs; Irrelevant for read-only inspection. For making modifications, I'll take on the responsibility for amending the proofs as necessary. > * reduces the amount of interconnections between different parts of your > program by ensuring that all interaction goes through the interface > instead of the implementation; For read-only inspection, I'm not sure this matter much -- if your implementation knows a fact that I want, then either I'll get it through your interface or dredge it out of your implementation's guts, but the module coupling's there either way. (If there was a better way to obtain that fact, then I should just have used the better way instead -- but in the case where it's a fact about your implementation's state there probably isn't a better way.) Similarly for modifications, actually: if I have a need to change your implementation's state somehow, I can do that through the interface or under the table, but there's a coupling either way. > * which in turn reduces the amount of testing you need to do; See above. > Well, you tell me: does it make sense for Guido to have decided to > make it hard for pure Python developers to cause buffer overflows? Yes. That said, I'm glad that it's /possible/ to write unsafe programs in Python. It means that the right escape-hatches are present. What I'm really complaining about are the kinds of interfaces -- which I see all to often in languages where people have embraced this kind of mandatory `information hiding' overenthusiastically -- where (a) the right features aren't there to begin with, and (b) the escape hatches are either messing or /extremely/ inconvenient. Java programs often seem to be like this. But CPython bends over backwards to provide useful information about its state: all those wacky attributes on functions and code objects and so on. Without this kind of care, I'm pretty sure that mandatory hiding is far worse as a cure than people diddling about inside other modules' implementation details is as a disease. I'm expecting you to argue that programmers would be too sensible to hide interesting information behind their mandatory-data-hiding, and I should just give them some credit. Maybe: but the situation is different. Firstly, we wouldn't be asking for this feature if we were willing to gave programmers some credit for acting responsibly when they dig about in another module's innards. Secondly, while it's certainly possible to mess up when poking about, the damage is fairly localized; if I'm overprotective about my mandatory hiding, I can screw other people. I guess that if overriding the controls was as easy as with naughty_hacking: ## stuff ... I wouldn't complain. (But I think the effect ought to be scoped /lexically/ rather than dynamically, so that grep works properly.) -- [mdw] From mdw at distorted.org.uk Sun Jan 25 15:00:10 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 20:00:10 +0000 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? References: Message-ID: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 > documentation index it lists only two references. The first is the > language manual's explanation of its use in the def statement, the > second is a transitory reference to its use in function calls, but > that's in the tutorial where it is not likely to get much attention. There's a full description of it in 5.4.3 in the Language Reference, but apparently not indexed. -- [mdw] From Russ.Paielli at gmail.com Sun Jan 25 15:01:16 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 12:01:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> On Jan 25, 10:04?am, Mark Wooding wrote: > > But what if I want an automatic check to verify that I am using it as > > the author intended? Is that unreasonable? > > You mean that you can't /tell/ whether you typed mumble._seekrit? > You're very strange. ?It's kind of hard to do by accident. But what if you type "mumble._seekrit" in several places, then the library implementer decides to give in to your nagging and makes it "public" by changing it to "mumble.seekrit". Now suppose you forget to make the corresponding change somewhere in your code, such as mumble._seekrit = zzz You will get no warning at all. You will just be inadvertently creating a new "private" attribute -- and the assignment that you really want will not get done. For that matter, the library implementer himself could make the same mistake and get no warning. When you think about it, you soon realize that the leading underscore convention violates the spirit if not the letter of one of the first principles of programming 101: if you have a constant parameter that appears in several places, assign the literal value in one place rather than repeating it everywhere. Then if you need to change the value, you only need to change it in one place. That reduces effort, but more importantly it reduces the potential for error. The same principle applies to "declaring" an attribute private. If that "declaration" is encoded in every occurrence of its identifier, then if you decide to change it to public, you need to change the identifier at each and every location. But if a "private" or "priv" keyword were available, you would only need to make the change in one location. From sjmachin at lexicon.net Sun Jan 25 15:06:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 12:06:48 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> On Jan 26, 12:54?am, Tim Chase wrote: > One other caveat here, "line" contains the newline at the end, so > you might have > > ? print line.rstrip('\r\n') > > to remove them. I don't understand the presence of the '\r' there. Any '\x0d' that remains after reading the file in text mode and is removed by that rstrip would be a strange occurrence in the data which the OP may prefer to find out about and deal with; it is not part of "the newline". Why suppress one particular data character in preference to others? The same applies in any case to the use of rstrip('\n'); if that finds more than one ocurrence of '\x0a' to remove, it has exceeded the mandate of removing the newline (if any). So, we are left with the unfortunately awkward if line.endswith('\n'): line = line[:-1] Cheers, John From steve at holdenweb.com Sun Jan 25 15:11:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 15:11:36 -0500 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: <1232910590.24534.1296651319@webmail.messagingengine.com> References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > Any suggestions on a best practice way to monitor a remote FTP site for > the arrival of new/updated files? I don't need specific code, just some > coaching on technique based on your real-world experience including > suggestions for a utility vs. code based solution. > > My goal is to maintain a local collection of files synced with a remote > FTP site and when I download a new/updated file locally, run a script to > process it. The arrival and format of the files that I need to sync with > are beyond my control (eliminating a rsync solution) ... all I have is a > generic FTP connection to a specific FTP address. Note: The remote site > I'm monitoring may have multiple uploads occuring at the same time. > > My basic strategy is to poll the remote directory on a regular basis and > compare the new directory listing to a previous snapshot of the > directory listing. If a file timestamp or size has changed (or a new > file has appeared), then track this file as a changed file. Once a file > has been marked as changed, wait polling cycles for the file > timestamp and size to remain stable, then download it, and trigger a > local script to process the file. In addition to detecting new or > changed files, I would compare remote directory listings to my local > sync folder and delete local files that no longer exist on the remote site. > > My concern about using a utility is the utility's ability to detect when > a remote file has finished being updated. I don't want to download files > that are still in the process of being updated - I only want to download > new/updated files after they've been closed on the remote site. > > Any ideas appreciated! > Well, the ftpmirror will cope with most of what you want to do as it is, but I am unsure how you can determine whether a file is in the process of being written on the server. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 15:13:24 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 14:13:24 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: > >>>> Take a look at the struct and ctypes modules. >>> struct is really not the choice. it returns an expanded string of the >>> data and this means larger latency over bluetooth. >> >> I don't know what you mean by "returns an expanded string of >> the data". >> >> I do know that struct does exactly what you requested. > > I disagree. He has a format (type, length, value), with the > value being variable-sized. How do you do that in the struct > module? You construct a format string for the "value" portion based on the type/length header. >> It converts between Python objects and what is bascially a C >> "struct" where you specify the endianness of each field and >> what sort of packing/padding you want. > > Sure. However, in the specific case, there is really no C > struct that can reasonably represent the data. I don't see how that can be the case. There may not be a single C struct that can represent all frames, but for every frame you should be able to come up with a C struct that can represent that frame. > Hence you cannot really use the struct module. Perhaps I don't understand his requirements, but I use the struct module for protocols with type/len/value sorts of packets. >> I use the struct module frequenty to impliment binary, >> communications protocols in Python. I've used Python/struct >> with transport layers ranging from Ethernet (raw, TCP, and >> UDP) to async serial, to CAN. > > Do you use it for the fixed-size parts, or also for the > variable-sized data? Both. For varible size/format stuff you decode the first few bytes and use them to figure out what format/layout to use for the next chunk of data. It's pretty much the same thing you do in other languages. -- Grant From martin at v.loewis.de Sun Jan 25 15:25:05 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 21:25:05 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> Message-ID: <497ccaa1$0$21633$9b622d9e@news.freenet.de> >> I disagree. He has a format (type, length, value), with the >> value being variable-sized. How do you do that in the struct >> module? > > You construct a format string for the "value" portion based on > the type/length header. Can you kindly provide example code on how to do this? > I don't see how that can be the case. There may not be a > single C struct that can represent all frames, but for every > frame you should be able to come up with a C struct that can > represent that frame. Sure. You would normally have a struct such as struct TLV{ char type; char length; char *data; }; However, the in-memory representation of that struct is *not* meant to be sent over the wire. In particular, the character pointer has no meaning outside the address space, and is thus not to be sent. > Both. For varible size/format stuff you decode the first few > bytes and use them to figure out what format/layout to use for > the next chunk of data. It's pretty much the same thing you do > in other languages. In the example he gave, I would just avoid using the struct module entirely, as it does not provide any additional value: def encode(type, length, value): return chr(type)+chr(length)+value Regards, Martin From python at bdurham.com Sun Jan 25 15:56:57 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 15:56:57 -0500 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <1232917017.11322.1296666355@webmail.messagingengine.com> > Well, the ftpmirror will cope with most of what you want to do as it is, but I am unsure how you can determine whether a file is in the process of being written on the server. Looks like that may be a fit. Thank you Steve! Malcolm From bj_666 at gmx.net Sun Jan 25 16:06:41 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 25 Jan 2009 21:06:41 GMT Subject: Reading the first MB of a binary file References: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Message-ID: <6u42j1Fd9kl4U2@mid.uni-berlin.de> On Sun, 25 Jan 2009 08:37:07 -0800, Max Leason wrote: > I'm attempting to read the first MB of a binary file and then do a md5 > hash on it so that i can find the file later despite it being moved or > any file name changes that may have been made to it. These files are > large (350-1400MB) video files and i often located on a different > computer and I figure that there is a low risk for generating the same > hash between two files. The problem occurs in the read command which > returns all \x00s. Any ideas why this is happening? > > Code: >>>>>open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) > b'\x00\x00\x00\x00\x00\x00....\x00' As MRAB says, maybe the first 1024 actually *are* all zero bytes. Wild guess: That's a file created by a bittorrent client which preallocates the files and that file above isn't downloaded completely yet!? Ciao, Marc 'BlackJack' Rintsch From mdw at distorted.org.uk Sun Jan 25 16:10:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 21:10:08 +0000 Subject: Pythonic list/tuple/dict layout? References: Message-ID: <87prib6qj3.fsf.mdw@metalzone.distorted.org.uk> Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? It seems that I use both d1 and d4, though in both cases I omit the trailing commas. I use d1 when each item is on a separate line, and d4 when I'm packing them onto multiple lines. e.g., op = XT.make_optparse \ ([('E', 'error', {'action': 'store_const', 'dest': 'type', 'const': 'error', 'help': "Mark the window as reporting an error."}), ## ... ('t', 'title', {'dest': 'title', 'help': "Set the window's title string."})], version = VERSION, usage = '%prog [-EIQWm] [-t TITLE] [-d HEADLINE] ' 'MESSAGE [BUTTONS...]') and service_info = [('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) })] In this latter case, were I defining multiple services, I'd indent it differently: service_info = [ ('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) }), ##... ] -- [mdw] From thorsten at thorstenkampe.de Sun Jan 25 16:12:13 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 25 Jan 2009 22:12:13 +0100 Subject: Cartesian Product of two lists (itertools) Message-ID: Hi, is there a way to make itertools.product generate triples instead of pairs from two lists? For example: >>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] >>> from itertools import product >>> list(product(list1, list2, list3)) [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, 5, 7), (2, 5, 8)] so far so good... Now... >>> list(product(product(list1, list2), list3)) [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, 4), 8), ((2, 5), 7), ((2, 5), 8)] Oops, pairs of pairs instead triples. Not what I wanted. What's the best way to pre-process the arguments to "itertools.product" or to post-process the result of "itertools.product" to get what I want?! I have an older utility which I would like to replace with itertools.product. The old one uses a rather clumsy way to indicate that a triple was wanted: def cartes(seq0, seq1, modus = 'pair'): """ return the Cartesian Product of two sequences """ if modus == 'pair': return [[item0, item1] for item0 in seq0 for item1 in seq1] elif modus == 'triple': return [item0 + [item1] for item0 in seq0 for item1 in seq1] Thorsten From gert.cuykens at gmail.com Sun Jan 25 16:12:30 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 13:12:30 -0800 (PST) Subject: v = json.loads("{'test':'test'}") Message-ID: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> raise ValueError(errmsg("Expecting property name", s, end)) http://docs.python.org/library/json.html What am I doing wrong ? From sjmachin at lexicon.net Sun Jan 25 16:16:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 13:16:40 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> Message-ID: <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> On Jan 26, 2:28?am, Ravi wrote: > On Jan 25, 12:52?am, "Martin v. L?wis" wrote: > > > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > > > packet_data(variable) > > > > How to construct these using python data types, as int and float have > > > no limits and their sizes are not well defined. > > > In Python 2.x, use the regular string type: chr(n) will create a single > > byte, and the + operator will do the concatenation. > > > In Python 3.x, use the bytes type (bytes() instead of chr()). > > This looks really helpful thanks! Provided that you don't take Martin's last sentence too literally :-) | Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 | >>> p_data = b"abcd" # Omit the b prefix if using 2.5 or earlier | >>> p_len = len(p_data) | >>> p_type = 3 | >>> chr(p_type) + chr(p_len) + p_data | '\x03\x04abcd' | Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 | >>> p_data = b"abcd" | >>> p_len = len(p_data) | >>> p_type = 3 | >>> bytes(p_type) + bytes(p_len) + p_data # literal translation | b'\x00\x00\x00\x00\x00\x00\x00abcd' | >>> bytes(3) | b'\x00\x00\x00' | >>> bytes(10) | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | >>> bytes([p_type]) + bytes([p_len]) + p_data | b'\x03\x04abcd' | >>> bytes([p_type, p_len]) + p_data | b'\x03\x04abcd' Am I missing a better way to translate chr(n) from 2.x to 3.x? The meaning assigned to bytes(n) in 3.X is "interesting": 2.X: nuls = '\0' * n out_byte = chr(n) 3.X: nuls = b'\0' * n or nuls = bytes(n) out_byte = bytes([n]) Looks to me like there was already a reasonable way of getting a bytes object containing a variable number of zero bytes. Any particular reason why bytes(n) was given this specialised meaning? Can't be the speed, because the speed of bytes(n) on my box is about 50% of the speed of the * expression for n = 16 and about 65% for n = 1024. Cheers, John From martin at v.loewis.de Sun Jan 25 16:21:08 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 22:21:08 +0100 Subject: Byte oriented data types in python In-Reply-To: <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> Message-ID: <497CD7C4.6010106@v.loewis.de> > Looks to me like there was already a reasonable way of getting a bytes > object containing a variable number of zero bytes. Any particular > reason why bytes(n) was given this specialised meaning? I think it was because bytes() was originally mutable, and you need a way to create a buffer of n bytes. Now that bytes() ended up immutable (and bytearray was added), it's perhaps not so useful anymore. Of course, it would be confusing if bytes(4) created a sequence of one byte, yet bytearray(4) created four bytes. Regards, Martin From __peter__ at web.de Sun Jan 25 16:38:33 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 25 Jan 2009 22:38:33 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? You need proper quotation marks: >>> s = json.dumps({'test':'test'}) >>> s '{"test": "test"}' >>> json.loads(s) {u'test': u'test'} The JSON format is described here: http://www.json.org/ Peter From livibetter at gmail.com Sun Jan 25 16:42:11 2009 From: livibetter at gmail.com (livibetter) Date: Sun, 25 Jan 2009 13:42:11 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: On Jan 26, 5:12?am, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end))http://docs.python.org/library/json.html > What am I doing wrong ? You use wrong quotes, it should be wrapped by double quotes not single quotes. Read http://json.org/: "A string is a collection of zero or more Unicode characters, wrapped in double quotes, ..." >>> v = json.loads('{"test":"test"}') >>> v {u'test': u'test'} From jcd at sdf.lonestar.org Sun Jan 25 16:47:20 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sun, 25 Jan 2009 16:47:20 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: <1232920040.11216.4.camel@mctell> Please include all relevant information in the *body* of your message, not just in the subject. It's a pain having to piece a question back together between the subject. On Sun, 2009-01-25 at 13:12 -0800, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? JSON requires strings to be enclosed in double quotes. It is not as flexible as python when it comes to quotation. If you change your example to v = json.loads('{"test":"test"}') it will work. (Note JSON also doesn't allow trailing commas, so '{"test":"test",}' will also fail) Cheers, Cliff > -- > http://mail.python.org/mailman/listinfo/python-list > From mal at egenix.com Sun Jan 25 17:02:31 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Sun, 25 Jan 2009 23:02:31 +0100 Subject: Securing a database In-Reply-To: References: Message-ID: <497CE177.3040907@egenix.com> On 2009-01-23 08:26, kt83313 at gmail.com wrote: > My company provides some services online, which now they are planning > to make it offline and sell to customers who can use it in their > networks. > > One of our major moneywinners is some data which is stored in a > database. Now, this data inside the database was obtained after paying > through the nose - so the company does not want to disclose the data > in the DB to the outside world - not to mention the lawsuits which the > original providers of data will start which will sink the company if > the data goes out. > > Now, the code is in Python - and we have a big problem. How to secure > the data in DB? One idea was to encrypt it and store the password in > the code. I dont believe security through obscurity - and python code > can easily be reverse-engineered too - right? > > Is it even possible to secure a data in this case? That depends a lot on what you call "secure". The data will have to get processed by the CPU one way or another and there are lots of ways to monitor such operations, either through software (debuggers, loggers, etc.) or hardware (low-level debuggers, signal analyzers, etc.). The best you can do is make it just a little harder to get at the data, ie. implement a simple but non-trivial data protection mechanism, and then use legal means to protect yourself from any wrong-doing of your customers. One way to do this, is by encrypting the data for the database and decrypting it whenever you start the application. If you use an in-memory database for the application, this will provide such a simple but non-trivial data protection scheme. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 25 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From grante at visi.com Sun Jan 25 17:12:08 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 16:12:08 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> You construct a format string for the "value" portion based on >> the type/length header. > > Can you kindly provide example code on how to do this? OK, something like this to handle received data where there is an initial 8-bit type field that is 1 for 16-bit unsigned integers in network byte-order, 2 for 32-bit IEEE floats in network byte-order. We'll further assume that the 'length' field comes next as a 16 bit unsigned value in network order and represents "how many" objects of the specified type follow: dtype = ord(rawdata[0]) dcount = struct.unpack("!H",rawdata[1:3]) if dtype == 1: fmtstr = "!" + "H"*dcount elif dtype == 2: fmtstr = "!" + "f"*dcount rlen = struct.calcsize(fmtstr) data = struct.unpack(fmtstr,rawdata[3:3+rlen]) leftover = rawdata[3+rlen:] >> I don't see how that can be the case. There may not be a >> single C struct that can represent all frames, but for every >> frame you should be able to come up with a C struct that can >> represent that frame. > > Sure. You would normally have a struct such as > > struct TLV{ > char type; > char length; > char *data; > }; > > However, the in-memory representation of that struct is *not* > meant to be sent over the wire. In particular, the character > pointer has no meaning outside the address space, and is thus > not to be sent. Well if it's not representing the layout of the data we're trying to deal with, then it's irrelevent. We are talking about how convert python objects to/from data in the 'on-the-wire' format, right? Or isn't that what the OP is asking about? >> Both. For varible size/format stuff you decode the first few >> bytes and use them to figure out what format/layout to use for >> the next chunk of data. It's pretty much the same thing you do >> in other languages. > > In the example he gave, I would just avoid using the struct module > entirely, as it does not provide any additional value: > > def encode(type, length, value): > return chr(type)+chr(length)+value Like this? >>> def encode(type,length,value): ... return chr(type)+chr(length)+value ... >>> print encode('float', 1, 3.14159) Traceback (most recent call last): File "", line 1, in File "", line 2, in encode TypeError: an integer is required >>> -- Grant From gdamjan at gmail.com Sun Jan 25 17:16:15 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 25 Jan 2009 23:16:15 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? try this v = json.loads('{"test":"test"}') JSON doesn't support single quotes, only double quotes. -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of converstion. Q: Why is top posting frowned upon? From mensanator at aol.com Sun Jan 25 17:18:15 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 25 Jan 2009 14:18:15 -0800 (PST) Subject: Cartesian Product of two lists (itertools) References: Message-ID: On Jan 25, 3:12?pm, Thorsten Kampe wrote: > Hi, > > is there a way to make itertools.product generate triples instead of > pairs from two lists? > > For example:>>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] > >>> from itertools import product > >>> list(product(list1, list2, list3)) > > [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, > 5, 7), (2, 5, 8)] > > so far so good... Now...>>> list(product(product(list1, list2), list3)) > > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] > > Oops, pairs of pairs instead triples. Not what I wanted. > > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! > > I have an older utility which I would like to replace with > itertools.product. The old one uses a rather clumsy way to indicate that > a triple was wanted: > > def cartes(seq0, seq1, modus = 'pair'): > ? ? """ return the Cartesian Product of two sequences """ > ? ? if ? modus == 'pair': > ? ? ? ? return [[item0, item1] for item0 in seq0 for item1 in seq1] > ? ? elif modus == 'triple': > ? ? ? ? return [item0 + [item1] for item0 in seq0 for item1 in seq1] > > Thorsten Will this work for you? >>> list4 = [(i,) for i in list3] >>> list4 [(7,), (8,)] >>> a = list(itertools.product(itertools.product(list1, list2), list4)) >>> a [((1, 4), (7,)), ((1, 4), (8,)), ((1, 5), (7,)), ((1, 5), (8,)), ((2, 4), (7,)), ((2, 4), (8,)), ((2, 5), (7,)), ((2, 5), (8,))] >>> def flatten(listOfLists): return tuple(itertools.chain.from_iterable(listOfLists)) >>> list5 = [flatten(i) for i in a] >>> list5 [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, 5, 7), (2, 5, 8)] >>> From Tribulations at Paralleles.invalid Sun Jan 25 17:25:09 2009 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 25 Jan 2009 23:25:09 +0100 Subject: super behavior Message-ID: <6f5v46-c1n.ln1@rama.fbx.proxad.net> Hi, Hereafter is an example using super. At the execution, we obtain: coucou init_coucou2 coucou1 coucou2 Traceback (most recent call last): File "essai_heritage.py", line 34, in print b.a AttributeError: 'coucou' object has no attribute 'a' Why Python does not enter in the __init__ method of coucou1? If I replace the two lines using "super" by the two following lines, it works perfectly: coucou1.__init__( self ) coucou2.__init__( self ) ########## class coucou1( object ): def __init__( self , a = 1 ): self.a = a print "init_coucou1" def print_coucou1( self ): print "coucou1" class coucou2( object ): def __init__( self , b = 2 ): self.b = b print "init_coucou2" def print_coucou2( self ): print "coucou2" class coucou( coucou1, coucou2 ): def __init__( self ): print "coucou" super( coucou1, self ).__init__( ) super( coucou2, self ).__init__( ) b = coucou() b.print_coucou1() b.print_coucou2() print b.a print b.b ################## -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From jbloodworth at sc.rr.com Sun Jan 25 17:27:00 2009 From: jbloodworth at sc.rr.com (Jay Bloodworth) Date: Sun, 25 Jan 2009 17:27:00 -0500 Subject: Where to put configuration/data files Message-ID: <1232922420.3118.118.camel@localhost.localdomain> Is there a nice cross-platform way to figure out the Right (tm) place to store configuration files and other data? Jay From gert.cuykens at gmail.com Sun Jan 25 17:28:48 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 14:28:48 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> On Jan 25, 11:16?pm, ?????? ??????????? wrote: > > raise ValueError(errmsg("Expecting property name", s, end)) > >http://docs.python.org/library/json.html > > What am I doing wrong ? > > try this > v = json.loads('{"test":"test"}') > > JSON doesn't support single quotes, only double quotes. the funny part is when you print(v) you get {'test': 'test'} Single quotes works in every browser that support json so i recommended python should support it too, besides it looks much cleaner {'test': 'test'} {"test": "test"} It can not be that hard to support both notation can it ? From martin at v.loewis.de Sun Jan 25 17:28:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 23:28:55 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> Message-ID: <497CE7A7.3020809@v.loewis.de> > dtype = ord(rawdata[0]) > dcount = struct.unpack("!H",rawdata[1:3]) > if dtype == 1: > fmtstr = "!" + "H"*dcount > elif dtype == 2: > fmtstr = "!" + "f"*dcount > rlen = struct.calcsize(fmtstr) > > data = struct.unpack(fmtstr,rawdata[3:3+rlen]) > > leftover = rawdata[3+rlen:] Unfortunately, that does not work in the example. We have a message type (an integer), and a variable-length string. So how do you compute the struct format for that? >> Sure. You would normally have a struct such as >> >> struct TLV{ >> char type; >> char length; >> char *data; >> }; >> >> However, the in-memory representation of that struct is *not* >> meant to be sent over the wire. In particular, the character >> pointer has no meaning outside the address space, and is thus >> not to be sent. > > Well if it's not representing the layout of the data we're > trying to deal with, then it's irrelevent. We are talking > about how convert python objects to/from data in the > 'on-the-wire' format, right? Right: ON-THE-WIRE, not IN MEMORY. In memory, there is a pointer. On the wire, there are no pointers. > Like this? > >>>> def encode(type,length,value): > ... return chr(type)+chr(length)+value > ... >>>> print encode('float', 1, 3.14159) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in encode > TypeError: an integer is required No: py> CONNECT_REQUEST=17 py> payload="call me" py> encode(CONNECT_REQUEST, len(payload), payload) '\x11\x07call me' Regards, Martin From gagsl-py2 at yahoo.com.ar Sun Jan 25 17:49:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 20:49:00 -0200 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribi?: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> I am creating a class called people - subclasses men, women, children >> etc. >> I want to count the number of people at any time. >> So, I created code like the following: >> >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) >> >> def __del__(self): >> a.counter -= 1 >> >> class aa(a): >> pass >> > This looks OK, although I'd suggest using "cls.counter += 1" instead of > "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. This would create an asymmetry > with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" > there, even if it is a bit ugly-ish. Using self.__class__ is safer, from a technical point of view. When __del__ is executed at interpreter shutdown, "a" may not be available -- in general, __del__ methods should not rely on any globals (one can "inject" names into the local namespace using default arguments). See http://bugs.python.org/issue1717900 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 25 17:49:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 20:49:00 -0200 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribi?: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> I am creating a class called people - subclasses men, women, children >> etc. >> I want to count the number of people at any time. >> So, I created code like the following: >> >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) >> >> def __del__(self): >> a.counter -= 1 >> >> class aa(a): >> pass >> > This looks OK, although I'd suggest using "cls.counter += 1" instead of > "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. This would create an asymmetry > with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" > there, even if it is a bit ugly-ish. Using self.__class__ is safer, from a technical point of view. When __del__ is executed at interpreter shutdown, "a" may not be available -- in general, __del__ methods should not rely on any globals (one can "inject" names into the local namespace using default arguments). See http://bugs.python.org/issue1717900 -- Gabriel Genellina From deets at nospam.web.de Sun Jan 25 17:51:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 23:51:41 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <6u48ntFdcm9fU1@mid.uni-berlin.de> gert schrieb: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} So what? That's python deciding to print strings using single-quotes. That has nothing to do with JSON. The important part is this: >>> json.dumps(json.loads('{"test":"test"}')) '{"test": "test"}' > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not hard, but it's not standard-conform. Most browsers even accept something like this: {foo : "bar"} But all of this is not JSON. Diez From cliff at excite.com Sun Jan 25 17:56:42 2009 From: cliff at excite.com (Cliff MacGillivray) Date: Sun, 25 Jan 2009 17:56:42 -0500 Subject: syntax color lang source code in blogs or website In-Reply-To: References: Message-ID: Xah Lee wrote: > For those of you using emacs, here's the elisp code that allows you to > syntax color computer language source code in your blog or website. > > http://xahlee.org/emacs/elisp_htmlize.html > > to comment, here: > http://xahlee.blogspot.com/2009/01/dehtmlize-source-code-in-emacs-lisp.html Xah, Very nice! If nothing else you seem to be a pretty clever programmer. Indeed, you seem to understand more theoretical aspects than most simple minded software developers. I am not sure why you live out of your car? Has that situation changed at all? Are you working right now? From deets at nospam.web.de Sun Jan 25 18:04:52 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 00:04:52 +0100 Subject: super behavior In-Reply-To: <6f5v46-c1n.ln1@rama.fbx.proxad.net> References: <6f5v46-c1n.ln1@rama.fbx.proxad.net> Message-ID: <6u49gkFdie6vU1@mid.uni-berlin.de> TP schrieb: > Hi, > > Hereafter is an example using super. > At the execution, we obtain: > > coucou > init_coucou2 > coucou1 > coucou2 > Traceback (most recent call last): > File "essai_heritage.py", line 34, in > print b.a > AttributeError: 'coucou' object has no attribute 'a' > > Why Python does not enter in the __init__ method of coucou1? Because you use super wrong. It's not supposed to be called with a superclass, but with the current class. And each class needs to call super itself in it's own __init__-method. Like this: class coucou1( object ): def __init__( self , a = 1 ): self.a = a print "init_coucou1" super( coucou1, self ).__init__( ) def print_coucou1( self ): print "coucou1" class coucou2( object ): def __init__( self , b = 2 ): self.b = b print "init_coucou2" super( coucou2, self ).__init__( ) def print_coucou2( self ): print "coucou2" class coucou( coucou1, coucou2 ): def __init__( self ): print "coucou" super( coucou, self ).__init__( ) b = coucou() b.print_coucou1() b.print_coucou2() print b.a print b.b Diez From grante at visi.com Sun Jan 25 18:05:31 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 17:05:31 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> dtype = ord(rawdata[0]) >> dcount = struct.unpack("!H",rawdata[1:3]) >> if dtype == 1: >> fmtstr = "!" + "H"*dcount >> elif dtype == 2: >> fmtstr = "!" + "f"*dcount >> rlen = struct.calcsize(fmtstr) >> >> data = struct.unpack(fmtstr,rawdata[3:3+rlen]) >> >> leftover = rawdata[3+rlen:] > > Unfortunately, that does not work in the example. We have > a message type (an integer), and a variable-length string. > So how do you compute the struct format for that? I'm confused. Are you asking for an introductory tutorial on programming in Python? > Right: ON-THE-WIRE, not IN MEMORY. In memory, there is a > pointer. On the wire, there are no pointers. I don't understand your point. > py> CONNECT_REQUEST=17 > py> payload="call me" > py> encode(CONNECT_REQUEST, len(payload), payload) > '\x11\x07call me' If all your data is comprised of 8-bit bytes, then you don't need the struct module. -- Grant From gert.cuykens at gmail.com Sun Jan 25 18:08:04 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 15:08:04 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> On Jan 25, 11:51?pm, "Diez B. Roggisch" wrote: > gert schrieb: > > > On Jan 25, 11:16 pm, ?????? ??????????? wrote: > >>> raise ValueError(errmsg("Expecting property name", s, end)) > >>>http://docs.python.org/library/json.html > >>> What am I doing wrong ? > >> try this > >> v = json.loads('{"test":"test"}') > > >> JSON doesn't support single quotes, only double quotes. > > > the funny part is when you print(v) you get > > {'test': 'test'} > > So what? That's python deciding to print strings using single-quotes. > That has nothing to do with JSON. > > The important part is this: > > ?>>> json.dumps(json.loads('{"test":"test"}')) > '{"test": "test"}' > > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. Yes it is, you just make it more python dictionary compatible :) What is this json person email address so I can ask that he makes a very small update on his site. Besides if you can make lightweight versions of standards http://docs.python.org/library/xml.dom.minidom.html You can defenatly add lightweight quotes to json. From tim at burlyhost.com Sun Jan 25 18:19:21 2009 From: tim at burlyhost.com (Tim Greer) Date: Sun, 25 Jan 2009 15:19:21 -0800 Subject: syntax color lang source code in blogs or website References: Message-ID: Cliff MacGillivray wrote: > Xah Lee wrote: >> For those of you using emacs, here's the elisp code that allows you >> to syntax color computer language source code in your blog or >> website. >> >> http:/........ >> >> to comment, here: >> http://....... > Xah, > Very nice! > If nothing else you seem to be a pretty clever programmer. > Indeed, you seem to understand more theoretical aspects than > most simple minded software developers. > I am not sure why you live out of your car? > Has that situation changed at all? Are you working right now? Please don't encourage this guy. He posts to groups purely to try and tell everyone how smart he thinks he is (regardless of how wrong he usually is), and argues and uses vulgar language to anyone that asks him to stop posting in non relevent news groups. He seems to have selected the Python and Perl groups to regularly post to, even when his posts rarely to never have any relation to said groups. Please, do not encourage his behavior. Thanks. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From python.list at tim.thechases.com Sun Jan 25 18:34:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 17:34:18 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> Message-ID: <497CF6FA.3030000@tim.thechases.com> >> One other caveat here, "line" contains the newline at the end, so >> you might have >> >> print line.rstrip('\r\n') >> >> to remove them. > > I don't understand the presence of the '\r' there. Any '\x0d' that > remains after reading the file in text mode and is removed by that > rstrip would be a strange occurrence in the data which the OP may > prefer to find out about and deal with; it is not part of "the > newline". Why suppress one particular data character in preference to > others? In an ideal world where everybody knew how to make a proper text-file, it wouldn't be an issue. Recreating the form of some of the data I get from customers/providers: >>> f = file('tmp/x.txt', 'wb') >>> f.write('headers\n') # headers in Unix format >>> f.write('data1\r\n') # data in Dos format >>> f.write('data2\r\n') >>> f.write('data3') # no trailing newline of any sort >>> f.close() Then reading it back in: >>> for line in file('tmp/x.txt'): print repr(line) ... 'headers\n' 'data1\r\n' 'data2\r\n' 'data3' As for wanting to know about stray '\r' characters, I only want the data -- I don't particularly like to be reminded of the incompetence of those who send me malformed text-files ;-) > The same applies in any case to the use of rstrip('\n'); if that finds > more than one ocurrence of '\x0a' to remove, it has exceeded the > mandate of removing the newline (if any). I believe that using the formulaic "for line in file(FILENAME)" iteration guarantees that each "line" will have at most only one '\n' and it will be at the end (again, a malformed text-file with no terminal '\n' may cause it to be absent from the last line) > So, we are left with the unfortunately awkward > if line.endswith('\n'): > line = line[:-1] You're welcome to it, but I'll stick with my more DWIM solution of "get rid of anything that resembles an attempt at a CR/LF". Thank goodness I haven't found any of my data-sources using "\n\r" instead, which would require me to left-strip '\r' characters as well. Sigh. My kingdom for competency. :-/ -tkc From martin at v.loewis.de Sun Jan 25 18:36:51 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 00:36:51 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> Message-ID: <497CF793.8050501@v.loewis.de> >> Unfortunately, that does not work in the example. We have >> a message type (an integer), and a variable-length string. >> So how do you compute the struct format for that? > > I'm confused. Are you asking for an introductory tutorial on > programming in Python? Perhaps. I honestly do not know how to deal with variable-sized strings in the struct module in a reasonable way, and thus believe that this module is incapable of actually supporting them (unless you use inappropriate trickery). However, as you keep claiming that the struct module is what should be used, I must be missing something about the struct module. > I don't understand your point. > >> py> CONNECT_REQUEST=17 >> py> payload="call me" >> py> encode(CONNECT_REQUEST, len(payload), payload) >> '\x11\x07call me' > > If all your data is comprised of 8-bit bytes, then you don't > need the struct module. Go back to the original message of the OP. It says # I have following packet format which I have to send over Bluetooth. # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || # packet_data(variable) So yes, all his date is comprised of 8-bit bytes, and yes, he doesn't need the struct module. Hence I'm puzzled why people suggest that he uses the struct module. I think the key answer is "use the string type, it is appropriate to represent byte oriented data in python" (also see the subject of this thread) Regards, Martin From deets at nospam.web.de Sun Jan 25 18:40:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 00:40:09 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> Message-ID: <6u4biqFdhg0iU1@mid.uni-berlin.de> >> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) No, what you do is to make it more incompatible with other json-implementations. Which defies the meaning of a standard. Besides, {foo : "bar"} is *not* python dictionary compatible, at least not unless you defined foo beforehand, and then there is no guarantee that foo is actually as string containing 'foo'. > What is this json person email address so I can ask that he makes a > very small update on his site. Go try your luck - http://www.json.org/ > > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html minidom is a lightweight version of the DOM-API. But it reads and writes standard-conform XML documents. The same applies for element-tree and lxml. So it does not serve as a counter-example. > You can defenatly add lightweight quotes to json. If you bring all other implementors of all other languages to simultaneously do so - yes, you can. Again, good luck with that. Diez From grante at visi.com Sun Jan 25 18:48:59 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 17:48:59 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >>> Unfortunately, that does not work in the example. We have >>> a message type (an integer), and a variable-length string. >>> So how do you compute the struct format for that? >> >> I'm confused. Are you asking for an introductory tutorial on >> programming in Python? > > Perhaps. I honestly do not know how to deal with variable-sized > strings in the struct module in a reasonable way, and thus believe > that this module is incapable of actually supporting them > (unless you use inappropriate trickery). It deals with variable sized fields just fine: dtype = 18 dlength = 32 format = "!BB%ds" % dlength rawdata = struct.pack(format, (dtype,dlength,data)) > However, as you keep claiming that the struct module is what > should be used, I must be missing something about the struct > module. http://docs.python.org/library/struct.html >> I don't understand your point. >> >>> py> CONNECT_REQUEST=17 >>> py> payload="call me" >>> py> encode(CONNECT_REQUEST, len(payload), payload) >>> '\x11\x07call me' >> >> If all your data is comprised of 8-bit bytes, then you don't >> need the struct module. > > Go back to the original message of the OP. It says > > # I have following packet format which I have to send over Bluetooth. > # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > # packet_data(variable) > > So yes, all his date is comprised of 8-bit bytes, He doesn't specify what format the packet_data is, and we all assumed he needed to handle conversion of various data types to/from raw byte-strings. > and yes, he doesn't need the struct module. Hence I'm puzzled > why people suggest that he uses the struct module. We all assumed that "packet_data" might contain values of various types such as 16 or 32 bit integers, floating point values -- that packet_data was not solely arbitrary-length strings of 8-bit bytes. > I think the key answer is "use the string type, it is > appropriate to represent byte oriented data in python" (also > see the subject of this thread) I, for one, interpreted "byte-oriented" to mean that the data was received/sent as blocks of bytes but needed to be converted into other data types. If the data really is just strings of bytes, and it's sent as strings of bytes, then I have no idea what the OP was asking, since there's nothing that needs to be done with the data. -- Grant From martin at v.loewis.de Sun Jan 25 18:53:30 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 00:53:30 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: <497CFB7A.2090901@v.loewis.de> > It deals with variable sized fields just fine: > > dtype = 18 > dlength = 32 > format = "!BB%ds" % dlength > > rawdata = struct.pack(format, (dtype,dlength,data)) I wouldn't call this "just fine", though - it involves a % operator to even compute the format string. IMO, it is *much* better not to use the struct module for this kind of problem, and instead rely on regular string concatenation. Regards, Martin From geekmail at usenot.de Sun Jan 25 18:54:31 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 00:54:31 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <20090126005431.063dafa9@usenot.de> On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" wrote: > gert schrieb: > > {'test': 'test'} > > {"test": "test"} > > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > OK, playing the devil's advocate here: Doesn't practicality beat purity? /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gagsl-py2 at yahoo.com.ar Sun Jan 25 19:04:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 22:04:40 -0200 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> Message-ID: En Sun, 25 Jan 2009 21:08:04 -0200, gert escribi?: > On Jan 25, 11:51?pm, "Diez B. Roggisch" wrote: >> gert schrieb: >> >> > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >> >>> raise ValueError(errmsg("Expecting property name", s, end)) >> >>>http://docs.python.org/library/json.html >> >>> What am I doing wrong ? >> >> try this >> >> v = json.loads('{"test":"test"}') >> >> >> JSON doesn't support single quotes, only double quotes. >> > It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> >> Most browsers even accept something like this: >> >> {foo : "bar"} >> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) What do you mean? The above is not valid Python. JSON is whatever the author says it is. And he says "A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes". > What is this json person email address so I can ask that he makes a > very small update on his site. Try http://www.json.org/ -- good luck. > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html This is not a lightweight version of XML, but a lightweight version of an API. minidom reads and writes the same valid XML documents. > You can defenatly add lightweight quotes to json. JSON is ligthweight *already*: "JSON (JavaScript Object Notation) is a lightweight data-interchange format." Introducing single quoted strings, apart from being incompatible with the previous version, would make parsing more complex. -- Gabriel Genellina From steve at holdenweb.com Sun Jan 25 19:04:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 19:04:44 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <20090126005431.063dafa9@usenot.de> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: Andreas Waldenburger wrote: > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > wrote: > >> gert schrieb: >>> {'test': 'test'} >>> {"test": "test"} >>> >>> It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> > OK, playing the devil's advocate here: Doesn't practicality beat purity? > It's not practical to expect a standard to be rewritten to conform with the ideas of one individual, as well as all the implementations of that standard. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 19:04:59 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 18:04:59 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> <497CFB7A.2090901@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> It deals with variable sized fields just fine: >> >> dtype = 18 >> dlength = 32 >> format = "!BB%ds" % dlength >> >> rawdata = struct.pack(format, (dtype,dlength,data)) > > I wouldn't call this "just fine", though - it involves > a % operator to even compute the format string. IMO, > it is *much* better not to use the struct module for this > kind of problem, and instead rely on regular string > concatenation. If all you need to do is concatenate strings, then you're correct, there's no advantage to using struct or ctypes. If you need a generic way to deal with arbitrary data types, then that's what the struct and ctypes modules are designed to do. The protocols I've implemented always required the ability to deal with integers greater than 8 bits wide as well as various other data types. -- Grant From gert.cuykens at gmail.com Sun Jan 25 19:05:59 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 16:05:59 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> Message-ID: On Jan 26, 12:40?am, "Diez B. Roggisch" wrote: > >> But all of this is not JSON. > > > Yes it is, you just make it more python dictionary compatible :) > > No, what you do is to make it more incompatible with other > json-implementations. Which defies the meaning of a standard. > > Besides, {foo : "bar"} is *not* python dictionary compatible, at least > not unless you defined foo beforehand, and then there is no guarantee > that foo is actually as string containing 'foo'. > > > What is this json person email address so I can ask that he makes a > > very small update on his site. > > Go try your luck -http://www.json.org/ > > > Besides if you can make lightweight versions of standards > >http://docs.python.org/library/xml.dom.minidom.html > > minidom is a lightweight version of the DOM-API. But it reads and writes > standard-conform XML documents. > > The same applies for element-tree and lxml. > > So it does not serve as a counter-example. yes it does because adding ' does not mean replacing " so it will still load standard json. Like every browser does and is exactly the same philosofie as http://docs.python.org/library/xml.dom.minidom.html The xml.dom.minidom module is essentially a DOM 1.0-compatible DOM with some DOM 2 features (primarily namespace features). or unlink() is a xml.dom.minidom-specific extension to the DOM API. After calling unlink() on a node, the node and its descendants are essentially useless. From castironpi at gmail.com Sun Jan 25 19:06:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 25 Jan 2009 16:06:43 -0800 (PST) Subject: ob_type in shared memory Message-ID: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> Hello, I am writing an extension using shared memory. I need a data type that is able to reassign its 'ob_type' field depending on what process is calling it. Object 'A' is of type 'Ta'. When process 'P' is looking at it, it needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. When process 'Q' is looking at it, it needs to have an 'ob_type' that is 'Ta' as process 'Q' sees it. If it referred to 'Ta' in process 'P' when 'Q' was calling it, 'Q' would have to access memory that is in another process. Therefore, I need a field and an array. The field indicates which type should be loaded, and the array contains the types. Quick example: PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; Then, when a list is being accessed, it can set its own 'ob_type' field to 'array_of_types[ 0 ]', and similarly for a tuple. However, I'm having trouble getting 'array_of_types' in the right module during compilation. My question is: Where do 'array_of_types' and the forward declarations for the types go? My fallback is what 'pickle' does: store types as strings, then load them dynamically for 'ob_type'. That is, obtain a pointer to the type from the string. Thank you for reading! Any ideas? Thanks in advance. From fuzzyman at gmail.com Sun Jan 25 19:20:47 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Sun, 25 Jan 2009 16:20:47 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: On Jan 25, 2:28?pm, Alan G Isaac wrote: > On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > ?> It is documented: > ?>http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... > > But then again, the opposite is also documented, > since `range` is a sequence type. ?Quoting: > > ? ? ?Sequences also support slicing ... > > ? ? ?Some sequences also support ?extended slicing? > > Is this a documentation bug, or a bug in `range`? > (I'd think the latter.) > > Cheers, > Alan Isaac Where does the documentation say that range objects are sequences? They're iterables. Michael Foord -- http://www.ironpythoninaction.com/ From sjmachin at lexicon.net Sun Jan 25 19:44:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 11:44:33 +1100 Subject: Newby: how to transform text into lines of text In-Reply-To: <497CF6FA.3030000@tim.thechases.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: <497D0771.3020709@lexicon.net> On 26/01/2009 10:34 AM, Tim Chase wrote: > I believe that using the formulaic "for line in file(FILENAME)" > iteration guarantees that each "line" will have at most only one '\n' > and it will be at the end (again, a malformed text-file with no terminal > '\n' may cause it to be absent from the last line) It seems that you are right -- not that I can find such a guarantee written anywhere. I had armchair-philosophised that writing "foo\n\r\nbar\r\n" to a file in binary mode and reading it on Windows in text mode would be strict and report the first line as "foo\n\n"; I was wrong. > >> So, we are left with the unfortunately awkward >> if line.endswith('\n'): >> line = line[:-1] > > You're welcome to it, but I'll stick with my more DWIM solution of "get > rid of anything that resembles an attempt at a CR/LF". Thanks, but I don't want it. My point was that you didn't TTOPEWYM (tell the OP exactly what you meant). My approach to DWIM with data is, given norm_space = lambda s: u' '.join(s.split()) to break up the line into fields first (just in case the field delimiter == '\t') then apply norm_space to each field. This gets rid of your '\r' at end (or start!) of line, and multiple whitespace characters are replaced by a single space. Whitespace includes NBSP (U+00A0) as an added bonus for being righteous and using Unicode :-) > Thank goodness I haven't found any of my data-sources using "\n\r" > instead, which would require me to left-strip '\r' characters as well. > Sigh. My kingdom for competency. :-/ Indeed. I actually got data in that format once from a *x programmer who was so kind as to do it that way just for me because he knew that I use Windows and he thought that's what Windows text files looked like. No kidding. Cheers, John From python.list at tim.thechases.com Sun Jan 25 19:47:23 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 18:47:23 -0600 Subject: Efficient multi-slicing technique? In-Reply-To: <1232903397.3540.1296640123@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> Message-ID: <497D081B.3080309@tim.thechases.com> > Is there an efficient way to multi-slice a fixed with string > into individual fields that's logically equivalent to the way > one would slice a delimited string using .split()? Background: > I'm parsing some very large, fixed line-width text files that > have weekly columns of data (52 data columns plus related > data). My current strategy is to loop through a list of > slice()'s to build a list of the specific field values for > each line. This is fine for small files, but seems > inefficient. I'm hoping that there's a built-in (C based) I'm not sure if it's more efficient, but there's the struct module[1]: from struct import unpack for line in file('sample.txt'): (num, a, b, c, nl) = unpack("2s9s7s4sc", line) print "num:", repr(num) print "a:", repr(a) print "b:", repr(b) print "c:", repr(c) Adjust the formatting string for your data (the last "c" is the newline character -- you might be able to use "x" here to just ignore the byte so it doesn't get returned). The sample data I threw was 2/9/7/4 character data. The general pattern would be lengths = [3,18,24,5,1,8] FORMAT_STR = ( ''.join("%ss" % length for length in lengths) + 'c') for line in file(INFILE): (f1, f2,..., fn, _) = unpack(FORMAT_STR, line) -tkc [1] http://docs.python.org/library/struct.html From Scott.Daniels at Acm.Org Sun Jan 25 19:57:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 25 Jan 2009 16:57:27 -0800 Subject: Newby: how to transform text into lines of text In-Reply-To: References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: John Machin wrote: > On 26/01/2009 10:34 AM, Tim Chase wrote: > >> I believe that using the formulaic "for line in file(FILENAME)" >> iteration guarantees that each "line" will have at most only one '\n' >> and it will be at the end (again, a malformed text-file with no >> terminal '\n' may cause it to be absent from the last line) > > It seems that you are right -- not that I can find such a guarantee > written anywhere. I had armchair-philosophised that writing > "foo\n\r\nbar\r\n" to a file in binary mode and reading it on Windows in > text mode would be strict and report the first line as "foo\n\n"; I was > wrong. Here's how I'd do it: with open('deheap/deheap.py', 'rU') as source: for line in source: print line.rstrip() # Avoid trailing spaces as well. This should handle \n, \r\n, and \n\r lines. --Scott David Daniels Scott.Daniels at Acm.Org From geekmail at usenot.de Sun Jan 25 19:57:44 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 01:57:44 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: <20090126015744.2b306ba3@usenot.de> On Sun, 25 Jan 2009 19:04:44 -0500 Steve Holden wrote: > Andreas Waldenburger wrote: > > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > > wrote: > > > >> gert schrieb: > >>> {'test': 'test'} > >>> {"test": "test"} > >>> > >>> It can not be that hard to support both notation can it ? > >> It's not hard, but it's not standard-conform. > >> > > OK, playing the devil's advocate here: Doesn't practicality beat > > purity? > > > It's not practical to expect a standard to be rewritten to conform > with the ideas of one individual, as well as all the implementations > of that standard. > But as gert says, the standard is "broken" by many many browsers already (I don't know if that's true, though; I just assume it is). Why not make it compatible with, and as forgiving as, those? (I feel a bit stupid here, because I'm basically on the "adhere to the standard" side. I just noticed that the Zen (or what I make of it) seems to suggest otherwise.) regards, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 19:59:05 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 00:59:05 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> Message-ID: <018d0119$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:34:18 -0600, Tim Chase wrote: > Thank goodness I haven't found any of my data-sources using "\n\r" > instead, which would require me to left-strip '\r' characters as well. > Sigh. My kingdom for competency. :-/ If I recall correctly, one of the accounting systems I used eight years ago gave you the option of exporting text files with either \r\n or \n\r as the end-of-line mark. Neither \n nor \r (POSIX or classic Mac) line endings were supported, as that would have been useful. (It may have been Arrow Accounting, but don't quote me on that.) I can only imagine the developer couldn't remember which order the characters were supposed to go, so rather than look it up, he made it optional. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 19:59:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 00:59:48 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> Message-ID: <018d0144$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 12:01:16 -0800, Russ P. wrote: > On Jan 25, 10:04?am, Mark Wooding wrote: > >> > But what if I want an automatic check to verify that I am using it as >> > the author intended? Is that unreasonable? >> >> You mean that you can't /tell/ whether you typed mumble._seekrit? >> You're very strange. ?It's kind of hard to do by accident. > > But what if you type "mumble._seekrit" in several places, then the > library implementer decides to give in to your nagging and makes it > "public" by changing it to "mumble.seekrit". Now suppose you forget to > make the corresponding change somewhere in your code, such as > > mumble._seekrit = zzz > > You will get no warning at all. You will just be inadvertently creating > a new "private" attribute -- and the assignment that you really want > will not get done. > > For that matter, the library implementer himself could make the same > mistake and get no warning. > > When you think about it, you soon realize that the leading underscore > convention violates the spirit if not the letter of one of the first > principles of programming 101: if you have a constant parameter that > appears in several places, assign the literal value in one place rather > than repeating it everywhere. Then if you need to change the value, you > only need to change it in one place. That reduces effort, but more > importantly it reduces the potential for error. How is this scenario different from an API change where public_method() gets changed to method()? Surely this is just a downside to Python's lack of declarations, rather than specific to Python's lack of data hiding? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:07:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:07:12 GMT Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: <018d0300$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 19:04:44 -0500, Steve Holden wrote: > Andreas Waldenburger wrote: >> On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" >> wrote: >> >>> gert schrieb: >>>> {'test': 'test'} >>>> {"test": "test"} >>>> >>>> It can not be that hard to support both notation can it ? >>> It's not hard, but it's not standard-conform. >>> >> OK, playing the devil's advocate here: Doesn't practicality beat >> purity? >> > It's not practical to expect a standard to be rewritten to conform with > the ideas of one individual, as well as all the implementations of that > standard. Supposedly "every browser" (what, all of them?) already support a de facto extension to the JSON standard, allowing more flexible quoting. In an ideal world, yes the standard should change to conform to what "all browsers" do, since what they do is sensible. In my opinion, Python's handling of quotes simply is The Right Way To Do It. But more realistically, I think a more attainable solution will be for json.loads() to give a better error message than "Expecting property name" when you use the wrong quotes. -- Steven From tjreedy at udel.edu Sun Jan 25 20:08:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 20:08:15 -0500 Subject: Python 3: range objects cannot be sliced In-Reply-To: References: Message-ID: Fuzzyman wrote: > On Jan 25, 2:28 pm, Alan G Isaac wrote: >> On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: >> > It is documented: >> >http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... >> >> But then again, the opposite is also documented, >> since `range` is a sequence type. Quoting: >> >> Sequences also support slicing ... >> >> Some sequences also support ?extended slicing? >> >> Is this a documentation bug, or a bug in `range`? >> (I'd think the latter.) No range slicing is intended. > Where does the documentation say that range objects are sequences? > They're iterables. Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 doc still says "There are five sequence types: strings, byte sequences, byte arrays, lists, tuples, and range objects" (the miscount has already been reported.) I added a note to http://bugs.python.org/issue4966 suggesting that ranges be removed from the sequence section. I made several other suggestions for improving this sections. Supportive comments might help get action. tjr From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:11:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:11:51 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018d0417$0$20629$c3e8da3@news.astraweb.com> On Mon, 26 Jan 2009 00:59:48 +0000, Steven D'Aprano wrote: > How is this scenario different from an API change where public_method() > gets changed to method()? Sorry, that's a poor example, since you were talking about attributes rather than methods. Must stop posting before coffee *wink* Rewording: How is this scenario different from an API change where self.some_attribute gets changed to self.attribute? Surely this is just a downside to Python's lack of declarations, rather than specific to Python's lack of enforced data hiding? -- Steven From http Sun Jan 25 20:15:47 2009 From: http (Paul Rubin) Date: 25 Jan 2009 17:15:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7xbptuuat8.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How is this scenario different from an API change where > self.some_attribute gets changed to self.attribute? That would be a backward incompatible change to a published interface, something that should not be done without a good reason, and which was mostly avoided through the whole Python 2.x series (incompatible changes were saved for Python 3.0). Changing an undocumented and supposedly private interface is something different entirely. From tjreedy at udel.edu Sun Jan 25 20:20:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 20:20:05 -0500 Subject: Cartesian Product of two lists (itertools) In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > Hi, > > is there a way to make itertools.product generate triples instead of > pairs from two lists? > > For example: >>>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] >>>> from itertools import product >>>> list(product(list1, list2, list3)) > [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, > 5, 7), (2, 5, 8)] > > so far so good... Now... >>>> list(product(product(list1, list2), list3)) > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] > > Oops, pairs of pairs instead triples. Not what I wanted. > > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! > > I have an older utility which I would like to replace with > itertools.product. The old one uses a rather clumsy way to indicate that > a triple was wanted: A pair of function, cart_pair, cart_trip, would have been better. Or auto recognition of the number of sequences passed in. > def cartes(seq0, seq1, modus = 'pair'): > """ return the Cartesian Product of two sequences """ > if modus == 'pair': > return [[item0, item1] for item0 in seq0 for item1 in seq1] > elif modus == 'triple': > return [item0 + [item1] for item0 in seq0 for item1 in seq1] The second branch only produces a triple if seq0 is a sequence of pairs. This must be called with something like res = cartes(cartes(list1,list2),list3,'triple') Just replace that with your first only-once itertools call list(product(list1, list2, list3)) From rt8396 at gmail.com Sun Jan 25 20:23:03 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:23:03 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> Message-ID: On Jan 23, 10:02?pm, alex23 wrote: [snip] > How's that Python bridge to SketchUp coming > along? It's been months already, surely you've invested as much effort > into learning Python as you have in talking about it? Thanks for asking Alex23, The ball is rolling on the Python SketchUp integration as we speak, many people are very excited to start coding in Python. Would you care to join our pursuits alex? From rt8396 at gmail.com Sun Jan 25 20:27:41 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:27:41 -0800 (PST) Subject: What is intvar? References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> W. eWatson, I contacted the author of New Mexico Techs "Introduction to Tkinter" a couple of weeks ago. He is going to update the reference material with a few missing widgets and some info on Photo and Bitmap classes. I really love the NMT layout and use it quite often. Fredricks Tkinterbook is more detail but lacking in navigation. I swing back and forth between both sites. From python.list at tim.thechases.com Sun Jan 25 20:30:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 19:30:33 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: <497D1239.4070202@tim.thechases.com> Scott David Daniels wrote: > Here's how I'd do it: > with open('deheap/deheap.py', 'rU') as source: > for line in source: > print line.rstrip() # Avoid trailing spaces as well. > > This should handle \n, \r\n, and \n\r lines. Unfortunately, a raw rstrip() eats other whitespace that may be important. I frequently get tab-delimited files, using the following pseudo-code: def clean_line(line): return line.rstrip('\r\n').split('\t') f = file('customer_x.txt') headers = clean_line(f.next()) for line in f: field1, field2, field3 = clean_line(line) do_stuff() if field3 is empty in the source-file, using rstrip(None) as you suggest triggers errors on the tuple assignment because it eats the tab that defined it. I suppose if I were really smart, I'd dig a little deeper in the CSV module to sniff out the "right" way to parse tab-delimited files. -tkc From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:31:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:31:18 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> Message-ID: <018d08a6$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:15:47 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> How is this scenario different from an API change where >> self.some_attribute gets changed to self.attribute? > > That would be a backward incompatible change to a published interface, > something that should not be done without a good reason, and which was > mostly avoided through the whole Python 2.x series (incompatible changes > were saved for Python 3.0). Changing an undocumented and supposedly > private interface is something different entirely. We're not talking specifically about Python standard library changes, we're talking about any project which may have more entertaining *cough* policies regarding API changes. Or if you prefer... some projects take the philosophy that the API isn't fixed until version 1.0, and so they can change anything until then. It seems to me that Russ' latest objection to _private names is not specific to _private names. The same problem: "You will get no warning at all. You will just be inadvertently creating a new "private" attribute -- and the assignment that you really want will not get done." occurs with public names as well. However, I do see his point that if we take the presence of a leading underscore in the name as semantically significant, then we're recording that information *everywhere* instead of in one place. That is a lesser version of Hungarian notation -- not as bad as redundantly storing type information that the compiler already knows, but still not ideal. -- Steven From http Sun Jan 25 20:37:41 2009 From: http (Paul Rubin) Date: 25 Jan 2009 17:37:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7x3af63l0a.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > We're not talking specifically about Python standard library changes, > we're talking about any project which may have more entertaining *cough* > policies regarding API changes. Oh, yes, I see what you mean. That's a problem even in small projects, sometimes even in 1-person projects. From googler.1.webmaster at spamgourmet.com Sun Jan 25 20:46:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 25 Jan 2009 17:46:01 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) Message-ID: Hi! I have a problm with deallocating stuff. I call a function with this command: PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); if(rvalue==NULL) PyErr_Print(); else Py_DECREF(rvalue); Can it be, that something is missing here? Imagine I allocate an object of a type: t = MyImage() ,;- syntax_error 129=)/% #is a syntax error How you see I would get a syntaxerror, but an object of the type MyImage() is created. But its deallocated when Py_Finalize() is called. What can I do to deallocate this object after PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL the object is deallocated, but what can I do if rvalue==NULL= Thanks a lot!!!! From rt8396 at gmail.com Sun Jan 25 20:48:36 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:48:36 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> Message-ID: <0d6e65a0-33b0-4ef6-823c-0dc5b0c80bc2@l33g2000pri.googlegroups.com> Actually Alex, i have not stopped working on getting Python into SU in one form or another since that crazy post of mine almost 3 moths ago. I have many people in the SU community asking me almost daily when i will get finished. I have a lot of work to do at this point but i will keep fighting because i believe Python will greatly benefit all SU users. 1.) Python has tons and tons of well written tutorials aimed at Non- programmers. 2.) Python is easy to learn making it the perfect choice for any API 3.) Python has an easy to use built-in GUI (Tkinter) 4.) Python allows for true procedural and true OOP programming. OOP can sometimes trip up a new programming student. I feel it is much easier to learn procedural coding and then move into OOP. OOP is not really hard to comprehend, but learning to program and at the same time dealing with the abstraction of OOP is a little much to take on. And since an API will be utilized mostly by non- programmers/intermediant as well as pros, Python lends itself as the best option available today for all skill levels! Once i finally get Python interpretor into SU, i plan to write a tutorial (free of course) specific aimed at SU users who want to script. Not only will this cover Python Programming but will completely cover the Python SU-API. SU is exploding daily, group membership is @ 14000+ and spam is almost nonexistent. This application is truly revolutionary and we must get Python in before it is too late. I have talked with a members of the SU DEV team and he would love to see Python scripting in SU. He also told me they have kicked around the idea of other languages in the past, so Python would be a prime choice. SU is changing the world of modeling the way Python changed the world of programming.I hang out quite a bit in the Google SketchUp Help Groups guiding new users. During this time i have seen many people stuggle with scripting the application. This is where i truly believe Python can fill a void and shine. The combination of Sketchup's intuitive and ground-breaking UI, coupled with the common sense approach and simplistic elegance of Python will be an unstoppable force. Not only will this expand Python and Sketchup's influence, but will give a SketchUp user the complete power they need over the application -- in the quickest, and most painless way. ... From mdw at distorted.org.uk Sun Jan 25 20:49:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 01:49:08 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> Message-ID: <87vds26dm3.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > On Jan 25, 10:04?am, Mark Wooding wrote: > > But what if you type "mumble._seekrit" in several places, then the > library implementer decides to give in to your nagging and makes it > "public" by changing it to "mumble.seekrit". There's a possibly better fix: introduce a property `seekrit' (or perhaps a better name!) which diddles the _seekrit attribute under the covers. > Now suppose you forget to make the corresponding change somewhere in > your code, such as > > mumble._seekrit = zzz > > You will get no warning at all. You will just be inadvertently > creating a new "private" attribute -- and the assignment that you > really want will not get done. True. That's a shame. It'd be nice if there were a way to fix that. There's this __slots__ thing I keep hearing about... > For that matter, the library implementer himself could make the same > mistake and get no warning. He could do. Why he didn't do a search and replace like any sensible person is a mystery. Testing is good, too. > When you think about it, you soon realize that the leading underscore > convention violates the spirit if not the letter of one of the first > principles of programming 101: if you have a constant parameter that > appears in several places, assign the literal value in one place > rather than repeating it everywhere. You mean `once and only once'. Yeah, I like that one too. > Then if you need to change the value, you only need to change it in > one place. That reduces effort, but more importantly it reduces the > potential for error. The same principle applies to "declaring" an > attribute private. Introducing a property hides the problem, but doesn't actually solve it, because you're right on this. Fortunately the problem doesn't actually come up that often. But yes, basically, I agree with you on this particular point: it's easier to add an alias than to rename, which avoids the problem but is error prone. -- [mdw] From apt.shansen at gmail.com Sun Jan 25 20:52:22 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 25 Jan 2009 17:52:22 -0800 Subject: Byte oriented data types in python In-Reply-To: <497CF793.8050501@v.loewis.de> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: <7a9c25c20901251752g5ac62bb1n7fcaaad8e858aedd@mail.gmail.com> > > However, as you keep claiming that the struct module is what > should be used, I must be missing something about the struct > module. You seem to be focusing overly on the "C Struct" part of the description of what the struct module does, instead of the part where it says, "packed binary data" and "This can be used in handling binary data stored in files or from network connections" The struct module is very useful when generating or interpreting a stream of binary data which has a set structured format, in bytes and with set kinds of data types. > > # I have following packet format which I have to send over Bluetooth. > # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > # packet_data(variable) > > So yes, all his date is comprised of 8-bit bytes, and yes, he doesn't > need the struct module. Hence I'm puzzled why people suggest that > he uses the struct module. > > I think the key answer is "use the string type, it is appropriate > to represent byte oriented data in python" (also see the subject > of this thread) > Everyone *is* saying to use the string type: the struct module doesn't produce structs.. it produces strings. The question is how to convert from Python types to byte-representations of said types in a string: you are saying (for example) that for shorts someone should use chr(1) etc. What if he needs to then send a two byte int from a Python int? Just because he said his message was about a fairly simple requirement at the moment, it doesn't mean that's the end of his problem. Everyone else seems to have assumed that it'll advance as he supports more of this protocol: that is apt to take on more specific struct format messages based on . So you might have a connection request format that's pre-defined -- your example above -- or another which needs to pass say, a 2 byte int instead. The struct module easily accomplishes this: all together in one place. Instead of having to figure out how to calculate the 2 byte storage of an int down the road, or a 4 byte integer, etc. Not to mention endianness. If the OP never ever has to do anything but the one specific problem he's having right now (and this isn't just an example he's making) with really really simple data: two byte-ints and then some characters, then sure using chr() and string concatenation is probably fine. But struct works -perfectly- fine for variable data and as he extends his support for the protocol, is quite likely to be very useful to him: that's why we're suggesting it. IMHO. I'd rather spend some trival time using string concatination (or the % operator) generating format strings for struct then have to write code for "int_to_2byte_int" and "int_to_4byte_int" and "change_to_bigendian" for when chr() doesn't satisfy the conversation needs enough. Yeah, strings are exactly how he can and should store the byte oriented data in Python 2.x. Using concatination and slicing + conversion to read and parse a byte stream coming off a line protocol... if you want to. But there's tools that are there that make it all alot easier too. The struct module for example. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Sun Jan 25 20:57:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 01:57:39 +0000 Subject: Cartesian Product of two lists (itertools) References: Message-ID: <87r62q6d7w.fsf.mdw@metalzone.distorted.org.uk> Thorsten Kampe writes: > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] [...] > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! Python has powerful destructuring capabilities: [(x, y, z) for ((x, y), z) in lopsided_list] This seems simpler and is probably faster than a generalized flatten for this size of problem, but I wouldn't use it to rearrange tuples with more than four or five elements. -- [mdw] From gagsl-py2 at yahoo.com.ar Sun Jan 25 21:03:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 00:03:54 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> Message-ID: En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase escribi?: > Unfortunately, a raw rstrip() eats other whitespace that may be > important. I frequently get tab-delimited files, using the following > pseudo-code: > > def clean_line(line): > return line.rstrip('\r\n').split('\t') > > f = file('customer_x.txt') > headers = clean_line(f.next()) > for line in f: > field1, field2, field3 = clean_line(line) > do_stuff() > > if field3 is empty in the source-file, using rstrip(None) as you suggest > triggers errors on the tuple assignment because it eats the tab that > defined it. > > I suppose if I were really smart, I'd dig a little deeper in the CSV > module to sniff out the "right" way to parse tab-delimited files. It's so easy that don't doing that is just inexcusable lazyness :) Your own example, written using the csv module: import csv f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') headers = f.next() for line in f: field1, field2, field3 = line do_stuff() -- Gabriel Genellina From zzbbaadd at aol.com Sun Jan 25 21:04:59 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Sun, 25 Jan 2009 18:04:59 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: > ? ? ? ? If you're building an extension tree, you'll either have to supply > layers of getter/setter methods, or hand-mangle references to attributes > defined in the superclass. > > ? ? ? ? Say you start with a "Point2D" class, and make the X, Y coordinates > double underscore. > > ? ? ? ? Now extend it to a "Point3D" class via inheritance. The 3D class > will not be able to access (set) the X, Y values without a setter method > defined in the parent OR by unmangling the parent names. > > ? ? ? ? If you'd used the common convention of single underscore as "don't > touch if you're an outsider", the 3D extension can be considered an > insider and directly access the X, Y > > ? ? ? ? Which would you rather read in a 3D point class derived by extending > a 2D point? > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? self._z += zmod > ? ? ? ? ? ? ? ? self._y += ymod > ? ? ? ? ? ? ? ? self._x += xmod > > or > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? super(Point3D, self).move(xmod, ymod) > ? ? ? ? ? ? ? ? self._z += zmod > > or > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? self._Point2D__x += xmod > ? ? ? ? ? ? ? ? self._Point2D__y += ymod > ? ? ? ? ? ? ? ? self.__z += zmod > > ? ? ? ? Speaking for myself, I'd prefer the first > -- > ? ? ? ? Wulfraed ? ? ? ?Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ? ? wulfr... at bestiaria.com > ? ? ? ? ? ? ? ? HTTP://wlfraed.home.netcom.com/ > ? ? ? ? (Bestiaria Support Staff: ? ? ? ? ? ? ? web-a... at bestiaria.com) > ? ? ? ? ? ? ? ? HTTP://www.bestiaria.com/ I like the latter two styles, particularly the last one. That way you can see at a glance that those member variables are defined in the super class. But then I am a fan of Hungarian notation, which many programmers can't stand. From python at bdurham.com Sun Jan 25 21:16:26 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 21:16:26 -0500 Subject: Efficient multi-slicing technique? In-Reply-To: <497D081B.3080309@tim.thechases.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> <497D081B.3080309@tim.thechases.com> Message-ID: <1232936186.1062.1296697403@webmail.messagingengine.com> Tim, > I'm not sure if it's more efficient, but there's the struct module: > http://docs.python.org/library/struct.html Thanks for your suggestion. I've been experimenting with this technique, but my initial tests don't show any performance improvements over using slice() objects to slice a string. However, I missed the nuance of using 'x' to mark filler bytes - I'm going to see if this makes a difference (it may as I am skipping over several columns of input that I've been currently returning as ignored values) wait ... it looks like I can 'compile' struct strings using by using a Struct class vs. the using the module's basic unpack() function. This sounds like the difference between using compiled regular expressions vs. re-compiling a regular expression on every use. I'll see if this makes a difference and report back to the list. Regards, Malcolm From mnordhoff at mattnordhoff.com Sun Jan 25 21:17:58 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Mon, 26 Jan 2009 02:17:58 +0000 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <497D1D56.8050407@mattnordhoff.com> gert wrote: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? There's a difference between JavaScript source code and JSON. AFAICT from the source [1], Mozilla's JSON parser doesn't accept single quotes. [1] -- From sjmachin at lexicon.net Sun Jan 25 21:23:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 18:23:30 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> Message-ID: <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> On Jan 26, 1:03?pm, "Gabriel Genellina" wrote: > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase ? > escribi?: > > > > > Unfortunately, a raw rstrip() eats other whitespace that may be ? > > important. ?I frequently get tab-delimited files, using the following ? > > pseudo-code: > > > ? ?def clean_line(line): > > ? ? ?return line.rstrip('\r\n').split('\t') > > > ? ?f = file('customer_x.txt') > > ? ?headers = clean_line(f.next()) > > ? ?for line in f: > > ? ? ?field1, field2, field3 = clean_line(line) > > ? ? ?do_stuff() > > > if field3 is empty in the source-file, using rstrip(None) as you suggest ? > > triggers errors on the tuple assignment because it eats the tab that ? > > defined it. > > > I suppose if I were really smart, I'd dig a little deeper in the CSV ? > > module to sniff out the "right" way to parse tab-delimited files. > > It's so easy that don't doing that is just inexcusable lazyness :) > Your own example, written using the csv module: > > import csv > > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') > headers = f.next() > for line in f: > ? ? ?field1, field2, field3 = line > ? ? ?do_stuff() > And where in all of that do you recommend that .decode(some_encoding) be inserted? From gagsl-py2 at yahoo.com.ar Sun Jan 25 21:25:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 00:25:46 -0200 Subject: Python C API (PyObject_CallMethod clear object) References: Message-ID: En Sun, 25 Jan 2009 23:46:01 -0200, escribi?: > I have a problm with deallocating stuff. I call a function with this > command: > > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); > > if(rvalue==NULL) > PyErr_Print(); > else > Py_DECREF(rvalue); > > Can it be, that something is missing here? Imagine I allocate an > object of a type: > > t = MyImage() > ,;- syntax_error 129=)/% #is a syntax error > > How you see I would get a syntaxerror, but an object of the type > MyImage() is created. But its deallocated when Py_Finalize() is > called. What can I do to deallocate this object after > PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL > the object is deallocated, but what can I do if rvalue==NULL= A syntax error is detected *before* the code runs -- so the object isn't created at all. -- Gabriel Genellina From mdw at distorted.org.uk Sun Jan 25 21:37:37 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 02:37:37 +0000 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Andreas Waldenburger writes: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) Hmm. Exceptions raised during object creation make this rather precarious. In your code, if object.__new__ raises an exception, the counter will end up too high (the __del__ method won't get called in this case). One might try to rewrite it: def __new__(cls, *args, **kw): thing = object.__new__(cls, *args, **kw) a.counter += 1 return thing Now this won't work in subclasses if they also have a __new__ method: again, if the subclass's __new__ raises an exception then __del__ won't be called and the counter will be too high. To make this technique work, I think you need to do the counter increment in __init__ rather than __new__, and to set an attribute so that __del__ knows whether to do the decrement. (If a subclass's __init__ raises an exception before yours gets called, you don't want to do the decrement because that'll leave the counter too low.) > This looks OK, although I'd suggest using "cls.counter += 1" instead > of "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. I'm not sure about clarity, but that would be semantically different. The code as written counts all instances of a and its subclasses. Your suggestion would count instances of subclasses independently. I don't know which behaviour the OP would prefer, but I don't think choosing between them is a matter of clarity. > Another way to go would be to use the weakref module and create a > weakref-set (or list) as the counter. That way you would only need to > add the objects in the __new__() method and not worry about removing > them. I will admit that this is overengineering the problem a bit, but > might be a good exercise. This is a better approach, because it avoids the problems with exceptions during object construction that I described above. >> Another question - unrelated to the major topic: >> How much time does it take to be proficient in Python? > Don't concern yourself with that question at all, is my advice. Indeed. Besides, it varies an awful lot. I can't tell you from my personal experience, because I tend to learn programming languages by osmosis. I sit and read language manuals and newsgroups out of curiosity, because I find programming languages intrinsically interesting. One day, maybe a few years later, I start writing programs in some language. I'm usually up to half-decent language-lawyer standards within a few days of this point -- but I've had a /lot/ of practice at this game. My approach is almost certainly extremely atypical. But one of the best things about Python is the library. It's very big and wide-ranging, but not overcomplex, and I'm still discovering cool stuff, even though it's been there for years. And the advice to keep the Library Reference under your pillow is excellent. Expect to be flipping through it constantly. >> - or am I just dumb? > You're writing programs and you're communicating with like-minded > people about your problems (in a socially appropriate way). Not what > dumb people do, in my book. Absolutely! Besides, you're asking sensible questions about subtle parts of the language -- I wouldn't say that __new__ was beginner territory, for example. So, no, you certainly don't seem dumb to me. -- [mdw] From mnordhoff at mattnordhoff.com Sun Jan 25 21:38:48 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Mon, 26 Jan 2009 02:38:48 +0000 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <497D1D56.8050407@mattnordhoff.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <497D1D56.8050407@mattnordhoff.com> Message-ID: <497D2238.3020203@mattnordhoff.com> Matt Nordhoff wrote: > gert wrote: >> On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>>> raise ValueError(errmsg("Expecting property name", s, end)) >>>> http://docs.python.org/library/json.html >>>> What am I doing wrong ? >>> try this >>> v = json.loads('{"test":"test"}') >>> >>> JSON doesn't support single quotes, only double quotes. >> the funny part is when you print(v) you get >> {'test': 'test'} >> >> Single quotes works in every browser that support json so i >> recommended python should support it too, besides it looks much >> cleaner >> {'test': 'test'} >> {"test": "test"} >> >> It can not be that hard to support both notation can it ? > > There's a difference between JavaScript source code and JSON. AFAICT > from the source [1], Mozilla's JSON parser doesn't accept single quotes. > > [1] By the way, I forgot to add, according to the ECMA-262 standard (page 18, section 7.8.4) [1], ECMAScript string literals can use either double or single quotes, so that's not a browser-specific extension. [1] () -- From Russ.Paielli at gmail.com Sun Jan 25 21:39:26 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 18:39:26 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> On Jan 25, 5:31?pm, Steven D'Aprano wrote: > It seems to me that Russ' latest objection to _private names is not > specific to _private names. The same problem: > > "You will get no warning at all. You will just be inadvertently > creating a new "private" attribute -- and the assignment that you > really want will not get done." > > occurs with public names as well. That is true. Any name change could cause that sort of problem. But I brought it up specifically in reply to Mr. Wooding, who pointed out that it is hard to "accidentally" type a name with a leading underscore without realizing what you are doing. You may fully understand what you are doing when you type it, but you may not realize what has happened later when you forget to change it to be consistent with the new version of the library (or another module in an application). To change an attribute from private to public, the leading-underscore convention requires that every occurrence of the name be changed. That is more error prone than if the change only needs to be done in one place. And the fact that Python allows you to create new attributes on the fly also contributes to this problem, of course. That makes renaming and refactoring riskier in general in Python than in statically typed languages with enforced access restrictions. More care and attention to detail is needed to do it right in Python. From python.list at tim.thechases.com Sun Jan 25 21:40:05 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 20:40:05 -0600 Subject: Efficient multi-slicing technique? In-Reply-To: <1232936186.1062.1296697403@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> <497D081B.3080309@tim.thechases.com> <1232936186.1062.1296697403@webmail.messagingengine.com> Message-ID: <497D2285.1010102@tim.thechases.com> >> I'm not sure if it's more efficient, but there's the struct >> module: http://docs.python.org/library/struct.html > > Thanks for your suggestion. I've been experimenting with this > technique, but my initial tests don't show any performance > improvements over using slice() objects to slice a string. > However, I missed the nuance of using 'x' to mark filler bytes > - I'm going to see if this makes a difference (it may as I am > skipping over several columns of input that I've been > currently returning as ignored values) I don't expect it will make a great deal of difference -- there's not much room to improve the process. Are you actually experiencing efficiency problems? I regularly use slice unpacking (without reaching for the struct module) with no noteworthy performance impact beyond the cost of scanning the file and doing the processing on those lines (and these are text files several hundred megs in size). When I omit my processing code and just skim through the file, the difference between slice-unpacking and not slice-unpacking is in the sub-second range. > wait ... it looks like I can > 'compile' struct strings using by using a Struct class vs. the > using the module's basic unpack() function. This sounds like > the difference between using compiled regular expressions vs. > re-compiling a regular expression on every use. I'll see if > this makes a difference and report back to the list. I don't expect it will...in the code for the struct.py I've got here in my 2.5 distribution, it maintains an internal cache of compiled strings, so unless you have more than _MAXCACHE=100 formatting strings, it's not something you're really have to worry about. (in my main data-processing/ETL app, I can't envision having more than about 20 formatting strings, if I went that route) -tkc From philip at semanchuk.com Sun Jan 25 21:55:29 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 25 Jan 2009 21:55:29 -0500 Subject: Why is it faster the second time ? In-Reply-To: References: Message-ID: <690C5046-E027-451A-87DD-17DE07D25616@semanchuk.com> On Jan 23, 2009, at 12:46 PM, jalanb3 wrote: > Hello the group, > > I am wondering why doctests run slower the first time. > In the transcript below "try" is a script which finds and runs > doctests in the current directory. It also shows how long it takes to > run these tests. > > I added a new test which searches recursively for files given a path, > and it took (approx) 3 seconds to run. But all subsequent runs take > less than half a second. > > Am I right in thinking that the extra time on the first run is the > time it takes to compile .py -> .pyc ? Lots of things could be involved. For instance, your OS probably memory cached all of the files involved during the first run, so all subsequent runs needed no disk I/O. From sjmachin at lexicon.net Sun Jan 25 22:23:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 19:23:20 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: <11034f30-d77c-4a77-afef-5460e4d0df2b@n33g2000pri.googlegroups.com> On Jan 26, 12:08?pm, Terry Reedy wrote: > Fuzzyman wrote: > > On Jan 25, 2:28 pm, Alan G Isaac wrote: > >> On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > >> ?> It is documented: > >> ?>http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... > > >> But then again, the opposite is also documented, > >> since `range` is a sequence type. ?Quoting: > > >> ? ? ?Sequences also support slicing ... > > >> ? ? ?Some sequences also support ?extended slicing? > > >> Is this a documentation bug, or a bug in `range`? > >> (I'd think the latter.) > > No range slicing is intended. > > > Where does the documentation say that range objects are sequences? > > They're iterables. > > Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 > doc still says "There are five sequence types: strings, byte sequences, > byte arrays, lists, tuples, and range objects" (the miscount has already > been reported.) > > I added a note to > ? ?http://bugs.python.org/issue4966 > suggesting that ranges be removed from the sequence section. > I made several other suggestions for improving this sections. > > Supportive comments might help get action. I agree the docs need to be fixed; it's not very sequency at all. Other comments: * This error message should not use the s-word, but this may be unavoidable: >>> range(10)[1:3] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' * It would be good if the docs said more about what it is meant to be used for, apart from the obvious "for item in a_range". You can subscript a range, not that it's very useful: >>> range(10)[7] 7 It has neither next() nor __next__() method, and appears to be reusable (which is good, IMO): >>> x = range(10) >>> x.next() Traceback (most recent call last): File "", line 1, in AttributeError: 'range' object has no attribute 'next' >>> x.__next__() Traceback (most recent call last): File "", line 1, in AttributeError: 'range' object has no attribute '__next__' >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> It is immutable, and thus can be hashed ... use case? Cheers, John From mdw at distorted.org.uk Sun Jan 25 22:47:27 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 03:47:27 +0000 Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> Message-ID: <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Aaron Brady writes: > I am writing an extension using shared memory. I need a data type > that is able to reassign its 'ob_type' field depending on what process > is calling it. That sounds scary! > Object 'A' is of type 'Ta'. When process 'P' is looking at it, it > needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. When > process 'Q' is looking at it, it needs to have an 'ob_type' that is > 'Ta' as process 'Q' sees it. If it referred to 'Ta' in process 'P' > when 'Q' was calling it, 'Q' would have to access memory that is in > another process. I see. My immediate reaction was to suggest that you just put the PyTypeObject in shared memory -- but then I realised that the shared memory region will probably be in different addresses in the two processes. I'll assume that you've got enough synchronization between the processes involved to stop everything from turning to mush. > Therefore, I need a field and an array. The field indicates which > type should be loaded, and the array contains the types. Quick > example: > > PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; > > Then, when a list is being accessed, it can set its own 'ob_type' > field to 'array_of_types[ 0 ]', and similarly for a tuple. > > However, I'm having trouble getting 'array_of_types' in the right > module during compilation. My question is: Where do 'array_of_types' > and the forward declarations for the types go? I'm not sure I understand the difficulty. They'll want to go in your C module somewhere, but as long as SharedList and SharedTuple are either in the same source file or not declared `static' you just write the definition you've got somewhere after declaring or defining the actual types in question. There's a comment in Extending and Embedding (2.1) about initializing PyTypeObjects: : PyObject_HEAD_INIT(NULL) : : This line is a bit of a wart; what we'd like to write is: : : PyObject_HEAD_INIT(&PyType_Type) : : as the type of a type object is "type", but this isn't strictly : conforming C and some compilers complain. The comment here is wrong: &PyType_Type is a perfectly good constant expression as far as C is concerned, but alas Microsoft's dynamic linking system isn't clever enough to cope with it even so (because it's in a separate link unit). But this isn't a problem in our case: presumably SharedList and SharedTuple are in the same module, so this should all just work. -- [mdw] From gagsl-py2 at yahoo.com.ar Sun Jan 25 22:49:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 01:49:25 -0200 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: En Sun, 25 Jan 2009 04:55:47 -0200, Torsten Mohr escribi?: > i try to write a plugin system that i want to use to let users extend > a module that i write. > > Within the module there is an extension loader that loads an extension > module. This extension module should be able to import modules from > my system, which provides some extensions. > > Basically, this here works but gives a warning: > RuntimeWarning: Parent module 'ext_abc' not found while handling > absolute import > here = os.path.abspath('.') (Unrelated to the main question, but you probably want to use os.path.dirname(os.path.abspath(__file__)) instead - the above just returns the current directory, which might not be the directory containing the module) > mpath = os.path.abspath('mymodule') > epath = os.path.abspath('extension') > > sys.path.append(here) > sys.path.append(mpath) > > FILE mymodule/__init__.py: So mymodule is actually a package. Packages should *not* appear in sys.path. -- Gabriel Genellina From sjmachin at lexicon.net Sun Jan 25 22:54:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 19:54:44 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> <497CFB7A.2090901@v.loewis.de> Message-ID: <698355ee-8148-4b87-8c92-c87bc9345c41@s1g2000prg.googlegroups.com> On Jan 26, 10:53?am, "Martin v. L?wis" wrote: > > It deals with variable sized fields just fine: > > > dtype = 18 > > dlength = 32 > > format = "!BB%ds" % dlength > > > rawdata = struct.pack(format, (dtype,dlength,data)) > > I wouldn't call this "just fine", though - it involves > a % operator to even compute the format string. IMO, > it is *much* better not to use the struct module for this > kind of problem, and instead rely on regular string > concatenation. > IMO, it would be a good idea if struct.[un]pack supported a variable * length operator that could appear anywhere that an integer constant could appear, as in C's printf etc and Python's % formatting: dlen = len(data) rawdata = struct.pack("!BB*s", dtype, dlen, dlen, data) # and on the other end of the wire: dtype, dlen = struct.unpack("!BB", rawdata[:2]) data = struct.unpack("!*s", rawdata[2:], dlen) # more than 1 count arg could be used if necessary # *s would return a string # *B, *H, *I, etc would return a tuple of ints in (3.X-speak) I've worked with variable-length data that looked like len1, len2, len3, data1, data2, data3 and the * gadget would have been very handy: len1, len2, len3 = unpack('!BBB', raw[:3]) data1, data2, data3 = unpack('!*H*i*d', raw[3:], len1, len2, len3) Note the semantics of '!*H*i*d' would be different from '!8H2i7d' because otherwise you'd need to do: bundle = unpack('!*H*i*d', raw[3:], len1, len2, len3) data1 = bundle[:len1] data2 = bundle[len1:len1+len2] data3 = bundle[len1+len2:] From mdw at distorted.org.uk Sun Jan 25 22:56:47 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 03:56:47 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> Message-ID: <8763k267pc.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: [snip stuff I don't disagree with] > That makes renaming and refactoring riskier in general in Python than > in statically typed languages with enforced access restrictions. More > care and attention to detail is needed to do it right in Python. In fact, I don't disagree with this statement either. It's just that I think there's a legitimate tradeoff between the assurances you can get from a language designed for static analysis and strictness, and the freedom and dynamicness of languages like Python. It's just that I rather like where Python is now on this continuum, and disagree that shifting it is necessarily a good idea. -- [mdw] From tjreedy at udel.edu Sun Jan 25 23:07:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 23:07:44 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Roger wrote: >> And, just for completeness, the "is" test is canonical precisely because >> the interpreter guarantees there is only ever one object of type None, >> so an identity test is always appropriate. Even the copy module doesn't >> create copies ... >> > > Does the interpreter guarantee the same for False and True bools? Yes. Bool(x) should return one of the two existing instances. In 2.x, the *names* 'True' and 'False' can be rebound because bool is new and people write try: False,True except NameError: False,True = 0,1 to make code back compatible. In 3.0, the names are keywords, just like 'None' and cannot be rebound, so x is True is guaranteed to answer whether x *is* the true object. Back before rebinding 'None' was prohibited, 'is None' was not completely guaranteed either (absent reading the rest of a file to be sure no rebinding would be done). From tjreedy at udel.edu Sun Jan 25 23:09:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 23:09:56 -0500 Subject: Python In-Reply-To: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> References: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> Message-ID: porkodi wrote: > www.easythings5.blogspot.com Ad spam site with pirated semi-gibberish not even containing 'Python'. From skip at pobox.com Sun Jan 25 23:18:30 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 25 Jan 2009 22:18:30 -0600 Subject: Python In-Reply-To: References: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> Message-ID: <18813.14742.325151.691809@montanaro.dyndns.org> Terry> porkodi wrote: >> www.easythings5.blogspot.com Terry> Ad spam site with pirated semi-gibberish not even containing Terry> 'Python'. Yeah, my fault. I was poking through a bunch of held messages and saw "Pyhon" as the subject. Didn't even look at the message itself until I saw it come through in my email. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From Russ.Paielli at gmail.com Sun Jan 25 23:46:35 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 20:46:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> <8763k267pc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8962522a-93f4-4f4e-ac3d-b232a1619170@d36g2000prf.googlegroups.com> On Jan 25, 7:56?pm, Mark Wooding wrote: > "Russ P." writes: > > [snip stuff I don't disagree with] > > > That makes renaming and refactoring riskier in general in Python than > > in statically typed languages with enforced access restrictions. More > > care and attention to detail is needed to do it right in Python. > > In fact, I don't disagree with this statement either. ?It's just that I > think there's a legitimate tradeoff between the assurances you can get > from a language designed for static analysis and strictness, and the > freedom and dynamicness of languages like Python. ?It's just that I > rather like where Python is now on this continuum, and disagree that > shifting it is necessarily a good idea. > > -- [mdw] I would like to have the option to use Python either way, if possible -- and I honestly don't know if it is possible. The new type annotations are a step in that direction. They are optional, but if used they could make refactoring safer and facilitate static analysis. Enforced access restrictions, if they can be added to Python, would be optional too -- as they are in any language. From timr at probo.com Sun Jan 25 23:46:44 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 26 Jan 2009 04:46:44 GMT Subject: USB in python References: Message-ID: Astan Chee wrote: > >Im trying to write a program for my USB device and I'm thinking of using >python to do this. The USB device is of my own making and it is >activated when one of the two data pins of the USB is given about 5V (or >similar to whatever the power pin is getting). Now I'm confused to if >the software to activate this can actually be written and how do I do >it? Any examples? I've seen pyUSB but it doesn't give me control over >the hardware and how much power is going through the data pins. Sorry, but you have NOT created a USB device, and I sincerely hope you do not try to plug it in to a real USB port. Despite the "serial" in the name, USB is much more than just a pair of wires, like RS-232. USB is a standard protocol-based bus, like Ethernet, and anything that is plugged into it must follow the protocol. You don't get a "voltage", you get a 480 MHz differential digital signal train. The wires are controlled by a USB host controller. You cannot override its behavior. You might be able to achieve your goal by using a parallel port, or by using a USB-to-serial port adapter, or by using one of the many simple and affordable USB experimenter's kits in the world. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gagsl-py2 at yahoo.com.ar Sun Jan 25 23:57:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 02:57:55 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> Message-ID: En Mon, 26 Jan 2009 00:23:30 -0200, John Machin escribi?: > On Jan 26, 1:03?pm, "Gabriel Genellina" > wrote: >> It's so easy that don't doing that is just inexcusable lazyness :) >> Your own example, written using the csv module: >> >> import csv >> >> f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> headers = f.next() >> for line in f: >> ? ? ?field1, field2, field3 = line >> ? ? ?do_stuff() > > And where in all of that do you recommend that .decode(some_encoding) > be inserted? For encodings that don't use embedded NUL bytes (latin1, utf8) I'd decode the fields right when extracting them: field1, field2, field3 = (field.decode('utf8') for field in line) For encodings that allow NUL bytes, I'd use any of the recipes in the csv module documentation. (That is, if I care about the encoding at all. Perhaps the file contains only numbers. Perhaps it contains only ASCII characters. Perhaps I'm only interested in some fields for which the encoding is irrelevant. Perhaps it is an internally generated file and it doesn't matter as long as I use the same encoding on output) But I admit that in general, the "decode input early when reading, work in unicode, encode output late when writing" is the best practice. -- Gabriel Genellina From timr at probo.com Mon Jan 26 00:00:37 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 26 Jan 2009 05:00:37 GMT Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> <20090126015744.2b306ba3@usenot.de> Message-ID: Andreas Waldenburger wrote: > >But as gert says, the standard is "broken" by many many browsers >already We're debating relatively picky semantic point, so I won't feel bad by being picky. Browsers have nothing to do with the JSON standard. JSON is not Javascript, nor is it a part of Javascript. JSON is a data exchange standard, which happens to be readable to Javascript parsers. A valid JSON expression happens to be a valid Javascript expression, but not vice versa. That's just the way it is. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From astan.chee at al.com.au Mon Jan 26 00:12:16 2009 From: astan.chee at al.com.au (Astan Chee) Date: Mon, 26 Jan 2009 16:12:16 +1100 Subject: USB in python In-Reply-To: References: Message-ID: <497D4630.6090405@al.com.au> Tim Roberts wrote: > Sorry, but you have NOT created a USB device, and I sincerely hope you do > not try to plug it in to a real USB port. > Sorry, by USB device, I meant a device that is powered/activated by a bunch of wires that I want to control using a computer and since I had a spare USB jack lying around, I used that instead. But so far I haven't tried it, nor will try it if it wont work properly. Yes, it is not a proper USB device, because I didnt build it to specifically interface with the USB port; but I had to start somewhere. Also, the device requires more power than the standard parallel port can give. Anyway, it looks like the easiest solution for my case is a microcontroller From s.selvamsiva at gmail.com Mon Jan 26 01:30:05 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 26 Jan 2009 12:00:05 +0530 Subject: String comparision In-Reply-To: References: Message-ID: Thank You Gabriel, On Sun, Jan 25, 2009 at 7:12 AM, Gabriel Genellina wrote: > En Sat, 24 Jan 2009 15:08:08 -0200, S.Selvam Siva > escribi?: > > > I am developing spell checker for my local language(tamil) using python. >> I need to generate alternative word list for a miss-spelled word from the >> dictionary of words.The alternatives must be as much as closer to the >> miss-spelled word.As we know, ordinary string comparison wont work here . >> Any suggestion for this problem is welcome. >> > > I think it would better to add Tamil support to some existing library like > GNU aspell: http://aspell.net/ That was my plan earlier,But i am not sure how aspell integrates with other editors.Better i will ask it in aspell mailing list. > You are looking for "fuzzy matching": > http://en.wikipedia.org/wiki/Fuzzy_string_searching > In particular, the Levenshtein distance is widely used; I think there is a > Python extension providing those calculations. > > -- > Gabriel Genellina The following code served my purpose,(thanks for some unknown contributors) def distance(a,b): c = {} n = len(a); m = len(b) for i in range(0,n+1): c[i,0] = i for j in range(0,m+1): c[0,j] = j for i in range(1,n+1): for j in range(1,m+1): x = c[i-1,j]+1 y = c[i,j-1]+1 if a[i-1] == b[j-1]: z = c[i-1,j-1] else: z = c[i-1,j-1]+1 c[i,j] = min(x,y,z) return c[n,m] a=sys.argv[1] b=sys.argv[2] d=distance(a,b) print "d=",d longer = float(max((len(a), len(b)))) shorter = float(min((len(a), len(b)))) r = ((longer - d) / longer) * (shorter / longer) # r ranges between 0 and 1 -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Mon Jan 26 02:22:04 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 26 Jan 2009 09:22:04 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><018a4b9c$0$20629$c3e8da3@news.astraweb.com><83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com><87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk><7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com><018d0144$0$20629$c3e8da3@news.astraweb.com><018d0417$0$20629$c3e8da3@news.astraweb.com><7xbptuuat8.fsf@ruckus.brouhaha.com><018d08a6$0$20629$c3e8da3@news.astraweb.com> <7x3af63l0a.fsf@ruckus.brouhaha.com> Message-ID: <000201c97f89$70a6da80$0d00a8c0@hendrik> "Paul Rubin" wrote: > Steven D'Aprano writes: > > We're not talking specifically about Python standard library changes, > > we're talking about any project which may have more entertaining *cough* > > policies regarding API changes. > > Oh, yes, I see what you mean. That's a problem even in small > projects, sometimes even in 1-person projects. I think it is more prevalent in single person projects than what we have the honesty to admit - After all, if *I* am writing the code, then *I* can do what *I* want, and often *I* do, much to *my* chagrin, when the effects strike home. Do I talk about it? - No way! I just quietly fix it. Sometimes too much freedom is not such a good thing - it leads to all sort of effects of which API spec. creep is one of the least. - Hendrik From m.iatrou at freemail.gr Mon Jan 26 02:36:41 2009 From: m.iatrou at freemail.gr (Michael Iatrou) Date: Mon, 26 Jan 2009 09:36:41 +0200 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: <1232910590.24534.1296651319@webmail.messagingengine.com> References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <200901260936.41480.m.iatrou@freemail.gr> When the date was Sunday 25 January 2009, python at bdurham.com wrote: > Any suggestions on a best practice way to monitor a remote FTP > site for the arrival of new/updated files? For a custom solution, you may want to take a look to pyinotify: http://pyinotify.sourceforge.net/ -- Michael Iatrou (idyz) From mrkafk at gmail.com Mon Jan 26 03:14:51 2009 From: mrkafk at gmail.com (mk) Date: Mon, 26 Jan 2009 09:14:51 +0100 Subject: unittest, order of test execution Message-ID: Hello everyone, I've got 2 functions to test, extrfromfile which returns a list of dictionaries, and extrvalues that extracts values from that list. Now I can test them both in one test case, like this: def test_extrfromfile(self): valist = ma.extrfromfile('loadavg_unittest.txt') valist_ut = [ {'day': '08-11-19', 'time': '12:41', 'val': 0.11}, {'day': '08-11-19', 'time': '12:42', 'val': 0.08}, {'day': '08-11-19', 'time': '12:43', 'val': 0.57}, {'day': '08-11-19', 'time': '12:44', 'val': 0.21}, {'day': '08-11-19', 'time': '12:45', 'val': 0.08}, {'day': '08-11-19', 'time': '12:46', 'val': 0.66}, {'day': '08-11-19', 'time': '12:47', 'val': 0.32}, {'day': '08-11-19', 'time': '12:48', 'val': 0.12}, {'day': '08-11-19', 'time': '12:49', 'val': 0.47}, {'day': '08-11-19', 'time': '12:50', 'val': 0.17}] self.assertEqual(valist, valist_ut) vlextr_ut = [0.11, 0.08, 0.57, 0.21, 0.08, 0.66, 0.32, 0.12, 0.47, 0.17] vlextr = ma.extrvalues(valist) self.assertEqual(len(vlextr_ut), len(vlextr)) for (idx, elem) in enumerate(vlextr_ut): self.assertAlmostEqual(elem, vlextr[idx]) But I was wondering, *should* this test be separated into two unit tests, one for each function? On the face of it, it looks that's how it should be done. This, however, raises the question: what's the order of test execution in the unittest? And how to pass values between unit tests? Should I modify 'self' in unit test? Regards, mk From ivan.illarionov at gmail.com Mon Jan 26 03:18:17 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Mon, 26 Jan 2009 00:18:17 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <9063ddd1-aecc-4ed6-8dea-7edc4dcdc595@w24g2000prd.googlegroups.com> Diez wrote: > gert schrieb: > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. By the way, all of this *is* YAML: >>> yaml.load("{'test':'test'}") {'test': 'test'} >>> yaml.load("{test: test}") {'test': 'test'} If someone needs more forgiving and user-editable format, YAML might be a good choice. -- Ivan From lie.1296 at gmail.com Mon Jan 26 03:21:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 26 Jan 2009 08:21:26 +0000 (UTC) Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > Diez B. Roggisch wrote: >>> >>> >> If all you need is on-off - why can't you just use a switch? >> >> >> > Because I want to control the on-off the device using a computer and > write software for it (which I am confident I can do if I had references > to how the wrappers to said interface). Cheers > Astan. > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little Hardware Experience). High pitched sound (or anything in sound-ology that means high voltage) means the device is on and low pitched sound off. The device will need an additional transistor to separate low voltage from the high voltage. I don't know how much power can be pulled from jack out, but for a home brewn device it is still feasible to draw power from USB and signal from jack out. From banibrata.dutta at gmail.com Mon Jan 26 03:33:22 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Mon, 26 Jan 2009 14:03:22 +0530 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: <3de8e1f70901260033u1a12d1cajeea1b6b5a697d310@mail.gmail.com> high pitch is == high frequency, no higher amplitude... but the difference can be easily made out and the electronics for this is very well understood and used.point is, the gentleman asking the question might already have a USB controller built into his device, and while most modern computers have anywhere between 2-6 USB ports, you have only 1 audio-out (Mic), so chances of finding a free "controller" port may be a bit of a challenge. On Mon, Jan 26, 2009 at 1:51 PM, Lie Ryan wrote: > On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > > > Diez B. Roggisch wrote: > >>> > >>> > >> If all you need is on-off - why can't you just use a switch? > >> > >> > >> > > Because I want to control the on-off the device using a computer and > > write software for it (which I am confident I can do if I had references > > to how the wrappers to said interface). Cheers > > Astan. > > > > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. The > device will need an additional transistor to separate low voltage from > the high voltage. I don't know how much power can be pulled from jack > out, but for a home brewn device it is still feasible to draw power from > USB and signal from jack out. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From thebrasse at gmail.com Mon Jan 26 04:03:43 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 01:03:43 -0800 (PST) Subject: Function arguments Message-ID: Hello! Is there any way that I can get at all the arguments passed to a function as a map without using keyword arguments? def foo(a, b, c): # Can I access all the arguments in a collection somewhere? I'm mainly curious since I have stumbled on to some cases where it might have been nice to be able to do that. :.:: mattias From deets at nospam.web.de Mon Jan 26 04:06:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 10:06:27 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> Message-ID: <6u5cokFdmi22U1@mid.uni-berlin.de> gert schrieb: > On Jan 26, 12:40 am, "Diez B. Roggisch" wrote: >>>> But all of this is not JSON. >>> Yes it is, you just make it more python dictionary compatible :) >> No, what you do is to make it more incompatible with other >> json-implementations. Which defies the meaning of a standard. >> >> Besides, {foo : "bar"} is *not* python dictionary compatible, at least >> not unless you defined foo beforehand, and then there is no guarantee >> that foo is actually as string containing 'foo'. >> >>> What is this json person email address so I can ask that he makes a >>> very small update on his site. >> Go try your luck -http://www.json.org/ >> >>> Besides if you can make lightweight versions of standards >>> http://docs.python.org/library/xml.dom.minidom.html >> minidom is a lightweight version of the DOM-API. But it reads and writes >> standard-conform XML documents. >> >> The same applies for element-tree and lxml. >> >> So it does not serve as a counter-example. > > yes it does because adding ' does not mean replacing " so it will > still load standard json. Like every browser does and is exactly the > same philosofie as No. If minidom would accept XML-documents that contain newlines in attributes (which otherwise are forbidden), e.g. *that* would be like adding single-quote stringliterals to JSON. This is about the *format*, not the API. There are people who say something along the lines of "be strict when writing, and tolerant when reading" (the exact quote is different, but neither google:~site:mybrain nor any other have helped me here), so one could argue that reading JSON that is not standard-conform would be ok. But IMHO that would increase the amount of interoperability-problems - because some people would *write* json that isn't standard-conform anymore. Diez From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 04:07:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 10:07:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <497d7d40$0$4845$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 23, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Russ P. a ?crit : > >>> As I said before, if you have the source code you can always change >>> private attributes to public in a pinch if the language enforces >>> encapsulation. >> And then have to maintain a fork. No, thanks. > > For crying out loud, how many private attributes do you need to > access? May I remind you that this is an hypothetical use case ? > If it's a dozen, then you and your library developer are > obviously not on the same page. If it's one or two, then it's hardly a > "fork." Just take note of the one or two places where you needed to > remove the access restriction and you're done. Yeah, fine. And doing it each and any release. A fork is a fork is a fork... >>> But if you are working on a team project, you can't >>> change the code that another member of a team checks in. >> Why on earth couldn't I change the code of another member of my team if >> that code needs changes ? The code is the whole team's ownership. > > OK, fine, you can change the code of another member of the team. No. I can change the *team's* code. Please *read*. "team's ownership", ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get the message, now ? > Are > you going to check with him first, or just do it? I give up. (snip) >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, kind >> of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? A remote web service - for example - is a far better blackbox when it comes to this kind of "sensitive and critical parts". If I can't trust someone wrt/ "this" part of the code, then he won't even have it as a binary package. Period. > Would you give all those developers your password to get into the > system? No? Wait a minute ... you mean you wouldn't "trust" them with > your password? But what about "openness"? Are you some sort of fascist > or what? Goodwin point. You loose. Good bye again, Mr P. From max at alcyone.com Mon Jan 26 04:09:34 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 26 Jan 2009 01:09:34 -0800 Subject: Function arguments In-Reply-To: References: Message-ID: brasse wrote: > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? > > I'm mainly curious since I have stumbled on to some cases where it > might have been nice to be able to do that. Look up the function call syntaxes with * and **: >>> def foo(*args): print args ... >>> def bar(**keywords): print keywords ... >>> foo(1, 2, 3) (1, 2, 3) >>> bar(a=1, b=2, c=3) {'a': 1, 'c': 3, 'b': 2} -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Custom reconciles us to everything. -- Edmund Burke From deets at nospam.web.de Mon Jan 26 04:11:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 10:11:28 +0100 Subject: Function arguments In-Reply-To: References: Message-ID: <6u5d21FdiqprU1@mid.uni-berlin.de> brasse schrieb: > Hello! > > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? > > I'm mainly curious since I have stumbled on to some cases where it > might have been nice to be able to do that. There is the locals()-call that returns the local variables as dictionary. Diez From clp2 at rebertia.com Mon Jan 26 04:11:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 01:11:57 -0800 Subject: Function arguments In-Reply-To: References: Message-ID: <50697b2c0901260111n2016b566gac5b33d28b6c6ee3@mail.gmail.com> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > Hello! > > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? You can use positional arguments: def foo(*args): print args foo("a", "b", "c") #==> ["a", "b", "c"] Though if you explained your situation more, the newsgroup could probably be of greater help. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From thebrasse at gmail.com Mon Jan 26 04:34:10 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 01:34:10 -0800 (PST) Subject: Function arguments References: Message-ID: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> On Jan 26, 10:11?am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > > Hello! > > > Is there any way that I can get at all the arguments passed to a > > function as a map without using keyword arguments? > > > def foo(a, b, c): > > ? ?# Can I access all the arguments in a collection somewhere? > > You can use positional arguments: > > def foo(*args): > ? ? print args > > foo("a", "b", "c") #==> ["a", "b", "c"] > > Though if you explained your situation more, the newsgroup could > probably be of greater help. > This is an abbreviated version of what I am doing now: def make_data(**kw): ''' make_data(foo='123', bar=42, time=time.time()) ''' template = '%(foo)s - %(bar)d - %(time)s' kw['time'] = time.strftime('%c', kw['time'] return template % kw This works, but the function signature doesn't say much about arguments I should pass to it. What I would like to do is something like this: def make_data(foo, bar time): template = '%(foo)s - %(bar)d - %(time)s' args = magic_get_args_function() args['time'] = time.strftime('%c', args['time'] return template % args I hope this should clear things up a bit. :-) :.:: mattias From clp2 at rebertia.com Mon Jan 26 04:39:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 01:39:28 -0800 Subject: Function arguments In-Reply-To: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> References: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> Message-ID: <50697b2c0901260139j4d5089c0p7109a4c7f6891a21@mail.gmail.com> On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > On Jan 26, 10:11 am, Chris Rebert wrote: >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: >> > Hello! >> >> > Is there any way that I can get at all the arguments passed to a >> > function as a map without using keyword arguments? >> >> > def foo(a, b, c): >> > # Can I access all the arguments in a collection somewhere? >> >> You can use positional arguments: >> >> def foo(*args): >> print args >> >> foo("a", "b", "c") #==> ["a", "b", "c"] >> >> Though if you explained your situation more, the newsgroup could >> probably be of greater help. >> > > This is an abbreviated version of what I am doing now: > > def make_data(**kw): > ''' > make_data(foo='123', bar=42, time=time.time()) > ''' > template = '%(foo)s - %(bar)d - %(time)s' > kw['time'] = time.strftime('%c', kw['time'] > return template % kw > > This works, but the function signature doesn't say much about > arguments I should pass to it. What I would like to do is something > like this: > > def make_data(foo, bar time): > template = '%(foo)s - %(bar)d - %(time)s' > args = magic_get_args_function() > args['time'] = time.strftime('%c', args['time'] > return template % args Just use locals() as was pointed out by Diez: def make_data(foo, bar, time): template = '%(foo)s - %(bar)d - %(time)s' time = time.strftime('%c', time) return template % locals() Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From castironpi at gmail.com Mon Jan 26 04:52:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 01:52:30 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <45adb6e7-4b34-48c5-8c8a-8037ce5e387e@x16g2000prn.googlegroups.com> Hi Mark, nice to have your comment. On Jan 25, 9:47?pm, Mark Wooding wrote: > Aaron Brady writes: snip > > Object 'A' is of type 'Ta'. ?When process 'P' is looking at it, it > > needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. ?When > > process 'Q' is looking at it, it needs to have an 'ob_type' that is > > 'Ta' as process 'Q' sees it. ?If it referred to 'Ta' in process 'P' > > when 'Q' was calling it, 'Q' would have to access memory that is in > > another process. > > I see. ?My immediate reaction was to suggest that you just put the > PyTypeObject in shared memory -- but then I realised that the shared > memory region will probably be in different addresses in the two > processes. Yes, exactly. >?I'll assume that you've got enough synchronization between > the processes involved to stop everything from turning to mush. Have at thee, synchronization! Yes, it is possible theoretically. (By the way, did you know you can detect deadlock before it strikes with a simple breadth-first search?) The idea is still not out of the proof-of-concept stage-- the concept not having been proved. > > Therefore, I need a field and an array. ?The field indicates which > > type should be loaded, and the array contains the types. ?Quick > > example: > > > PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; > > > Then, when a list is being accessed, it can set its own 'ob_type' > > field to 'array_of_types[ 0 ]', and similarly for a tuple. > > > However, I'm having trouble getting 'array_of_types' in the right > > module during compilation. ?My question is: Where do 'array_of_types' > > and the forward declarations for the types go? > > I'm not sure I understand the difficulty. ?They'll want to go in your C > module somewhere, but as long as SharedList and SharedTuple are either > in the same source file or not declared `static' you just write the > definition you've got somewhere after declaring or defining the actual > types in question. The problem I ran into was that different modules (C files) were seeing different versions of the structure. '&SharedList' showed up as different addresses in the debugger! I might be missing something, but I think the forward declaration got interpreted as an actual declaration in the different files that included the header. Mysteriously, it disappeared when I tried it again now. It's still a possibility. The solution I looked at today was declare the array like this: PyTypeObject* keep_types[]; It's even ok in a shared header (multiply included). Then the actual definition just gives it NULLs and a size, which are filled in as the needed modules are loaded. That solves the (additional) problem of not having called the owner module's initialization code. The catch is that if you have an object in a SharedList, you need to have imported its module before you load it. However 'pickle' has that problem too, so I don't feel bad. > There's a comment in Extending and Embedding (2.1) about initializing > PyTypeObjects: > > : ? ? ? ? ?PyObject_HEAD_INIT(NULL) > : > : This line is a bit of a wart; what we'd like to write is: > : > : ? ? ? ? ?PyObject_HEAD_INIT(&PyType_Type) > : > : as the type of a type object is "type", but this isn't strictly > : conforming C and some compilers complain. > > The comment here is wrong: &PyType_Type is a perfectly good constant > expression as far as C is concerned, but alas Microsoft's dynamic > linking system isn't clever enough to cope with it even so (because it's > in a separate link unit). ?But this isn't a problem in our case: > presumably SharedList and SharedTuple are in the same module, so this > should all just work. Here is another quote from the docs: "Portability therefore requires not to make any assumptions about symbol visibility. This means that all symbols in extension modules should be declared static, except for the module?s initialization function, in order to avoid name clashes with other extension modules (as discussed in section The Module?s Method Table and Initialization Function)." All declared static? Dear. So I don't know what to make of it, especially given the need to call 'PyType_Ready'. From mdw at distorted.org.uk Mon Jan 26 05:20:30 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 10:20:30 +0000 Subject: Dynamic methods and lambda functions References: Message-ID: <87ocxu4bdd.fsf.mdw@metalzone.distorted.org.uk> Michael Torrie writes: > Basically, don't use a lambda. Create a real, local closure with a > nested def block. That way the closure is created every time the > parent function is called. Nope. I explained the real problem quite clearly, and it's to do with the difference between binding and assignment. What's the difference between these two pieces of code? ## First def __init__(self): for n, v in props: setattr(Person, '_' + n, v) setattr(Person, n, lambda self: getattr(self, '_' + n)) ## Second def __init__(self): for n, v in props: setattr(Person, '_' + n, v) def hack(self): return getattr(self, '_' + n) setattr(Person, n, hack) > Lambda expressions are only ever compiled once during execution. The same is true of `def' bodies. -- [mdw] From benfal at yahoo.it Mon Jan 26 05:23:22 2009 From: benfal at yahoo.it (Benny Fallica) Date: Mon, 26 Jan 2009 10:23:22 +0000 (GMT) Subject: Ldap Extended Operation python Message-ID: <286207.4328.qm@web26908.mail.ukl.yahoo.com> Hello there, what would be the python implementation for this line in Java: java.util.Hashtable environment = LdapHelper.getEnvironment(url, true); LdapContext ldapContext = new InitialLdapContext(environment, null); Response resp = (Response) ldapContext.extendedOperation(new Request()) how to deal with extended operations in python? thanks for your help! From geekmail at usenot.de Mon Jan 26 05:35:51 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 11:35:51 +0100 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <20090126113551.4dbbbb51@usenot.de> On Mon, 26 Jan 2009 02:37:37 +0000 Mark Wooding wrote: > > This looks OK, although I'd suggest using "cls.counter += 1" instead > > of "a.counter += 1" in the __new__() method. Just seems clearer to > > me, esp. when you think about subclassing. > > I'm not sure about clarity, but that would be semantically different. > The code as written counts all instances of a and its subclasses. > Your suggestion would count instances of subclasses independently. I > don't know which behaviour the OP would prefer, but I don't think > choosing between them is a matter of clarity. > Oh shoot. I should have known that. I hope I will from now on, at least. :/ /W -- My real email address is constructed by swapping the domain with the recipient (local part). From googler.1.webmaster at spamgourmet.com Mon Jan 26 05:47:31 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 26 Jan 2009 02:47:31 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) References: Message-ID: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> On 26 Jan., 03:25, "Gabriel Genellina" wrote: > En Sun, 25 Jan 2009 23:46:01 -0200, ? > escribi?: > > > > > I have a problm with deallocating stuff. I call a function with this > > command: > > > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); > > > if(rvalue==NULL) > > ? ? PyErr_Print(); > > else > > ? ? Py_DECREF(rvalue); > > > Can it be, that something is missing here? Imagine I allocate an > > object of a type: > > > t = MyImage() > > ,;- syntax_error 129=)/% ?#is a syntax error > > > How you see I would get a syntaxerror, but an object of the type > > MyImage() is created. But its deallocated when Py_Finalize() is > > called. What can I do to deallocate this object after > > PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL > > the object is deallocated, but what can I do if rvalue==NULL= > > A syntax error is detected *before* the code runs -- so the object isn't ? > created at all. > > -- > Gabriel Genellina Hi! Yes, you are right. I got this issue not in syntax error, I get it on a runtime error like this: t = MyImage() self.test("hallo") #test takes an integer so this would throw an exception. Here you see, an object of the type MyImage() was created but its not deleted. 't' is a local reference so how can I do that? Thanks! From carribeiro at gmail.com Mon Jan 26 05:48:25 2009 From: carribeiro at gmail.com (Carlos Ribeiro) Date: Mon, 26 Jan 2009 08:48:25 -0200 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> I experienced the same problem here in Brazil. Tweeks ago I could not access any *.python.org site. Today I tried and it worked. The problem seemed to be limited to Python's domain because I could access every other site that I tried the same day. More info: - At least for me I didn't seem to be IPv6 related. - It failed in the same day in more than one PC, using different providers. - The domain name was resolving ok. My guess is that it was some kind of BGP failure. Perhaps the AS that hosts Python's servers injected a wrong route or someone else did, effectively stealing all the traffic for that prefix. That's more common than people realize (specially nowadays when countries such as Pakistan try to block domains by messing with BGP). Carlos Ribeiro On Sun, Jan 25, 2009 at 11:44, Cousin Stanley wrote: > > > Is anybody else having trouble accessing sites (including www, docs, > > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Yes, connecting to python.org sites has been problematic > for me as well .... > > I don't remember when the trouble started, but it's been > problematic for at least a week or longer here .... > > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Carlos Ribeiro Consultoria em Projetos blog: http://rascunhosrotos.blogspot.com blog: http://pythonnotes.blogspot.com mail: carribeiro at gmail.com mail: carribeiro at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Mon Jan 26 06:23:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 11:23:18 +0000 Subject: Newby: how to transform text into lines of text In-Reply-To: <497CF6FA.3030000@tim.thechases.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: 2009/1/25 Tim Chase : > (again, a malformed text-file with no terminal '\n' may cause it > to be absent from the last line) Ahem. That may be "malformed" for some specific file specification, but it is only "malformed" in general if you are using an operating system that treats '\n' as a terminator (eg, Linux) rather than as a separator (eg, MS DOS/Windows). Perhaps what you don't /really/ want to be reminded of is the existence of operating systems other than your preffered one? -- Tim Rowe From digitig at gmail.com Mon Jan 26 06:45:35 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 11:45:35 +0000 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: > I like the latter two styles, particularly the last one. That way you > can see at a glance that those member variables are defined in the > super class. I like the second style because it makes it leaves the 2-d implementation hidden, which is the whole point of encapsulation. > But then I am a fan of Hungarian notation, which many > programmers can't stand. Is it that programmers can't stand it, or is it that they can't stand it when it's imposed when not needed? As a pseudo type system for languages with no typing it's pretty useful. To the extent that a language provides typing it's useless verging on dangerous because it can get out of synch with the actual type. I believe that any case of Hungarian notation being useful is evidence of a flaw in the language being used -- but arguably all languages are flawed in some way or other, so Hungarian /can/ be useful. At this level I don't recognise a difference between System and Applications Hungarian, by the way -- the difference is eliminated if you declare types corresponding to the "meanings", which is commonplace in, for example, Ada. -- Tim Rowe From googler.1.webmaster at spamgourmet.com Mon Jan 26 06:47:43 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 26 Jan 2009 03:47:43 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) References: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> Message-ID: the hook is, how to delete the locals of this function, maybe thats a workaround? thanks and bye. From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 06:51:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 12:51:28 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <497da399$0$4780$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 23, 6:36 pm, Luis Zarrabeitia wrote: > >>> Makes *no* sense? There's *no* good reason *at all* for the original >>> author to hide or protect internals? >> My bad, sorry. >> It makes sense... if the original author is an egotist who believes he must >> control how I use that library. > > If the original author provides you with the source code and the right > to modify it, he cannot possibly control how you use the library. You > can trivially disable any access controls. But for some reason that's > not enough for you. > > Has it occurred to you that some users might actually *want* access > controls? Then they'll have to choose a language which provides it. > Maybe some users want to actually use the library as the > author intended it to be used. And ? Strange enough, that's usually what happens - using the official, documented API. Strange enough, it seems that Python programmers are mostly wise enough to not break encapsulation (nor abuse any of the highly dynamic features of Python) without pretty good reasons, lots of thought and attention, clear documentation of the fact, and possibly exchanges with the library author (or maintainer) to discuss the problem. From siona at chiark.greenend.org.uk Mon Jan 26 07:22:18 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 26 Jan 2009 12:22:18 +0000 (GMT) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > [ ... ] Your approach of reading the full contents can be >used like this: > >content = a.read() >for line in content.split("\n"): > print line > Or if you want the full content in memory but only ever access it on a line-by-line basis: content = a.readlines() (Just because we can now write "for line in file" doesn't mean that readlines() is *totally* redundant.) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From michael at stroeder.com Mon Jan 26 08:25:25 2009 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Mon, 26 Jan 2009 14:25:25 +0100 Subject: Ldap Extended Operation python In-Reply-To: References: Message-ID: <57q056-bl7.ln1@nb2.stroeder.com> Benny Fallica wrote: > Hello there, > > what would be the python implementation for this line in Java: > > > java.util.Hashtable environment = LdapHelper.getEnvironment(url, true); > LdapContext ldapContext = new InitialLdapContext(environment, null); > Response resp = (Response) ldapContext.extendedOperation(new Request()) > how to deal with extended operations in python? Which LDAP extended operation do you want to use? In python-ldap the following ext. ops are already implemented: http://python-ldap.sourceforge.net/doc/html/ldap.html#ldap.LDAPObject.whoami_s http://python-ldap.sourceforge.net/doc/html/ldap.html#ldap.LDAPObject.passwd There's no generic interface for ext. ops. yet. Feel free to contribute something like this. Ciao, Michael. From robin at reportlab.com Mon Jan 26 08:28:09 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jan 2009 13:28:09 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: <497AE1F8.5040008@jessikat.plus.net> References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> <497AE1F8.5040008@jessikat.plus.net> Message-ID: <497DBA69.8030201@chamonix.reportlab.co.uk> I found that this error > Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in ignored occurs when attempting to copy (copy.copy(inst)) an instance of a class that looks like this class LazyParagraph(_LazyMixin,TTParagraph): SUPER=TTParagraph _CLEAN_SPACE=1 however, whilst debugging I found the error disappeared when I tried to determine what accesses were being made on this instance during the copy. If I use this code class _LazyParagraph(_LazyMixin,TTParagraph): SUPER=TTParagraph _CLEAN_SPACE=1 class LazyParagraph(_LazyParagraph): def __getattr__(self,a): return getattr(_LazyParagraph,a) then instances of the new lazy paragraph don't cause a problem. This looks awfully fragile to me, and I haven't really got any closer to understanding what's going on. Anyone got any ideas? I have attempted to abstract the problem, but so far I haven't found the vital bits. -- Robin Becker From steve at holdenweb.com Mon Jan 26 08:44:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 08:44:43 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Terry Reedy wrote: > Roger wrote: >>> And, just for completeness, the "is" test is canonical precisely because >>> the interpreter guarantees there is only ever one object of type None, >>> so an identity test is always appropriate. Even the copy module doesn't >>> create copies ... >>> >> >> Does the interpreter guarantee the same for False and True bools? > > Yes. Bool(x) should return one of the two existing instances. > > In 2.x, the *names* 'True' and 'False' can be rebound because bool is > new and people write > try: > False,True > except NameError: > False,True = 0,1 > > to make code back compatible. > I would claim that the ability to rebind True and False is a simple bug, though one not likely to be fixed in an 2.x release. The code above doesn't rebind True and False in interpreters that have them ... > In 3.0, the names are keywords, just like 'None' and cannot be rebound, > so x is True is guaranteed to answer whether x *is* the true object. > > Back before rebinding 'None' was prohibited, 'is None' was not > completely guaranteed either (absent reading the rest of a file to be > sure no rebinding would be done). > And that was a bug too, in this case one that *was* removed in 2.4, I believe. Don't have 2.3 lying around just now. Python 2.4.3 (#1, May 24 2008, 13:47:28) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> None = 3 SyntaxError: assignment to None regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:05:34 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:05:34 -0500 Subject: Counting number of objects In-Reply-To: <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Andreas Waldenburger writes: > >> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath >> wrote: >> >>> class a(object): >>> counter = 0 >>> def __new__(cls, *args, **kwargs): >>> a.counter += 1 >>> return object.__new__(cls, *args, **kwargs) > > Hmm. Exceptions raised during object creation make this rather > precarious. In your code, if object.__new__ raises an exception, the > counter will end up too high (the __del__ method won't get called in > this case). > If object.__new__ raises an exception you have bigger problems to worry about than an object count being wrong. > One might try to rewrite it: > > def __new__(cls, *args, **kw): > thing = object.__new__(cls, *args, **kw) > a.counter += 1 > return thing > > Now this won't work in subclasses if they also have a __new__ method: > again, if the subclass's __new__ raises an exception then __del__ won't > be called and the counter will be too high. > > To make this technique work, I think you need to do the counter > increment in __init__ rather than __new__, and to set an attribute so > that __del__ knows whether to do the decrement. (If a subclass's > __init__ raises an exception before yours gets called, you don't want to > do the decrement because that'll leave the counter too low.) > Yes, rather better to do it that way and decouple it from __new__(). Of course super() might help here, though not everyone approves of it. >> This looks OK, although I'd suggest using "cls.counter += 1" instead >> of "a.counter += 1" in the __new__() method. Just seems clearer to me, >> esp. when you think about subclassing. > > I'm not sure about clarity, but that would be semantically different. > The code as written counts all instances of a and its subclasses. Your > suggestion would count instances of subclasses independently. I don't > know which behaviour the OP would prefer, but I don't think choosing > between them is a matter of clarity. > Correct, but pointing out the differences has highlighted that is a real design decision to be made in the event that subclassing is used. >> Another way to go would be to use the weakref module and create a >> weakref-set (or list) as the counter. That way you would only need to >> add the objects in the __new__() method and not worry about removing >> them. I will admit that this is overengineering the problem a bit, but >> might be a good exercise. > > This is a better approach, because it avoids the problems with > exceptions during object construction that I described above. > >>> Another question - unrelated to the major topic: >>> How much time does it take to be proficient in Python? >> Don't concern yourself with that question at all, is my advice. > > Indeed. Besides, it varies an awful lot. > [...] >>> - or am I just dumb? >> You're writing programs and you're communicating with like-minded >> people about your problems (in a socially appropriate way). Not what >> dumb people do, in my book. > > Absolutely! Besides, you're asking sensible questions about subtle > parts of the language -- I wouldn't say that __new__ was beginner > territory, for example. So, no, you certainly don't seem dumb to me. > Hear, hear! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:09:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:09:39 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <497da399$0$4780$426a74cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Russ P. a ?crit : >> On Jan 23, 6:36 pm, Luis Zarrabeitia wrote: >> >>>> Makes *no* sense? There's *no* good reason *at all* for the original >>>> author to hide or protect internals? >>> My bad, sorry. >>> It makes sense... if the original author is an egotist who believes >>> he must >>> control how I use that library. >> >> If the original author provides you with the source code and the right >> to modify it, he cannot possibly control how you use the library. You >> can trivially disable any access controls. But for some reason that's >> not enough for you. >> >> Has it occurred to you that some users might actually *want* access >> controls? > > Then they'll have to choose a language which provides it. > >> Maybe some users want to actually use the library as the >> author intended it to be used. > > And ? Strange enough, that's usually what happens - using the official, > documented API. Strange enough, it seems that Python programmers are > mostly wise enough to not break encapsulation (nor abuse any of the > highly dynamic features of Python) without pretty good reasons, lots of > thought and attention, clear documentation of the fact, and possibly > exchanges with the library author (or maintainer) to discuss the problem. Quite. Python is a language "for consenting adults". It has perceived deficiencies for certain software engineering environments. Can we drop the subject now? This horse was flogged to death long ago, and it's pointless and cruel to keep on beating the remains. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:13:33 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:13:33 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > unineuro at gmail.com writes: [...] > * Assignment stores a new (reference to a) value in the variable. > > * Binding modifies the mapping between names and variables. > I realise I have omitted what was doubtless intended to be explanatory detail, but I am having trouble reconciling those sentences. Would you mind explaining "in vacuuo" what you see as the difference between assignment and binding? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mrkafk at gmail.com Mon Jan 26 09:18:02 2009 From: mrkafk at gmail.com (mk) Date: Mon, 26 Jan 2009 15:18:02 +0100 Subject: Building matplotlib from source on windows Message-ID: Hello everyone, I'm trying to get 0.98.5.2 installed on Windows to use Python 2.6 (dependency packages I need to use on that version, long story, etc). When I was trying to build it (python setup.py build), it was finding the VC 9.0 C++ compiler on my comp. However, after adding necessary packages (zlib, png, etc), it was reporting missing 'unistd.h'. Clearly, this means it was meant to be built with GCC for Windows like MinGW ? I have uninstalled the VC compiler, installed GnuWin32 packages and tried using MinGW (passing --compiler=mingw32 to python setup.py build ) but now compilation process fails like this: c:\MinGW\bin\g++.exe -mno-cygwin -shared -s build\temp.win32-2.6\Release\src\ft2font.o build\temp.wi n32-2.6\Release\src\mplutils.o build\temp.win32-2.6\Release\cxx\cxxsupport.o build\temp.win32-2.6\Re lease\cxx\cxx_extensions.o build\temp.win32-2.6\Release\cxx\indirectpythoninterface.o build\temp.win 32-2.6\Release\cxx\cxxextensions.o build\temp.win32-2.6\Release\src\ft2font.def -LC:\Python26\libs - LC:\Python26\PCbuild -lfreetype -lz -lgw32c -lstdc++ -lm -lpython26 -lmsvcr90 -o build\lib.win32-2.6 \matplotlib\ft2font.pyd c:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgw32c collect2: ld returned 1 exit status error: command 'g++' failed with exit status 1 What the heck is lgw32c?? Regards, mk From steve at holdenweb.com Mon Jan 26 09:22:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:22:57 -0500 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: Lie Ryan wrote: > On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > >> Diez B. Roggisch wrote: >>>> >>>> >>> If all you need is on-off - why can't you just use a switch? >>> >>> >>> >> Because I want to control the on-off the device using a computer and >> write software for it (which I am confident I can do if I had references >> to how the wrappers to said interface). Cheers >> Astan. >> > > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. The > device will need an additional transistor to separate low voltage from > the high voltage. I don't know how much power can be pulled from jack > out, but for a home brewn device it is still feasible to draw power from > USB and signal from jack out. > Congratulations. You just invented the modem. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:25:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:25:28 -0500 Subject: USB in python In-Reply-To: <497D4630.6090405@al.com.au> References: <497D4630.6090405@al.com.au> Message-ID: Astan Chee wrote: > Tim Roberts wrote: >> Sorry, but you have NOT created a USB device, and I sincerely hope you do >> not try to plug it in to a real USB port. >> > Sorry, by USB device, I meant a device that is powered/activated by a > bunch of wires that I want to control using a computer and since I had a > spare USB jack lying around, I used that instead. But so far I haven't > tried it, nor will try it if it wont work properly. Yes, it is not a > proper USB device, because I didnt build it to specifically interface > with the USB port; but I had to start somewhere. Also, the device > requires more power than the standard parallel port can give. > Anyway, it looks like the easiest solution for my case is a microcontroller In which case the Arduino may be a good place to start. The recent duemilanove boards use USB to communicate with the host, and so the USB port should be available to the microcontroller. We areg etting some way away from Python now, of course ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From thebrasse at gmail.com Mon Jan 26 09:49:25 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 06:49:25 -0800 (PST) Subject: Function arguments References: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> Message-ID: <5e616a7c-3cde-4f28-a56a-15b86ef66ef2@35g2000pry.googlegroups.com> On Jan 26, 10:39?am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > > On Jan 26, 10:11 am, Chris Rebert wrote: > >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > >> > Hello! > > >> > Is there any way that I can get at all the arguments passed to a > >> > function as a map without using keyword arguments? > > >> > def foo(a, b, c): > >> > ? ?# Can I access all the arguments in a collection somewhere? > > >> You can use positional arguments: > > >> def foo(*args): > >> ? ? print args > > >> foo("a", "b", "c") #==> ["a", "b", "c"] > > >> Though if you explained your situation more, the newsgroup could > >> probably be of greater help. > > > This is an abbreviated version of what I am doing now: > > > def make_data(**kw): > > ? ?''' > > ? ?make_data(foo='123', bar=42, time=time.time()) > > ? ?''' > > ? ?template = '%(foo)s - %(bar)d - %(time)s' > > ? ?kw['time'] = time.strftime('%c', kw['time'] > > ? ?return template % kw > > > This works, but the function signature doesn't say much about > > arguments I should pass to it. What I would like to do is something > > like this: > > > def make_data(foo, bar time): > > ? ?template = '%(foo)s - %(bar)d - %(time)s' > > ? ?args = magic_get_args_function() > > ? ?args['time'] = time.strftime('%c', args['time'] > > ? ?return template % args > > Just use locals() as was pointed out by Diez: > > def make_data(foo, bar, time): > ? ? template = '%(foo)s - %(bar)d - %(time)s' > ? ? time = time.strftime('%c', time) > ? ? return template % locals() > Nice, thank you! :.:: mattias From bj_666 at gmx.net Mon Jan 26 09:51:33 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 26 Jan 2009 14:51:33 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <6u60vlFdkq3bU2@mid.uni-berlin.de> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > content = a.readlines() > > (Just because we can now write "for line in file" doesn't mean that > readlines() is *totally* redundant.) But ``content = list(a)`` is shorter. :-) Ciao, Marc 'BlackJack' Rintsch From BrianVanderburg2 at aim.com Mon Jan 26 09:55:01 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Mon, 26 Jan 2009 09:55:01 -0500 Subject: USB in python In-Reply-To: <497D4630.6090405@al.com.au> References: <497D4630.6090405@al.com.au> Message-ID: <497DCEC5.3060208@aim.com> astan.chee at al.com.au wrote: > Tim Roberts wrote: >> Sorry, but you have NOT created a USB device, and I sincerely hope >> you do >> not try to plug it in to a real USB port. >> > Sorry, by USB device, I meant a device that is powered/activated by a > bunch of wires that I want to control using a computer and since I had > a spare USB jack lying around, I used that instead. But so far I > haven't tried it, nor will try it if it wont work properly. Yes, it is > not a proper USB device, because I didnt build it to specifically > interface with the USB port; but I had to start somewhere. Also, the > device requires more power than the standard parallel port can give. > Anyway, it looks like the easiest solution for my case is a > microcontroller > -- > http://mail.python.org/mailman/listinfo/python-list I've played around in this area a little bit. Microcontrollers still require hardware programming and for simple circuits I think it is overkill. If you want to use USB then you may be able to use the FTDI chips. They have both serial (FT232) and parallel (FT245) chips and are quite cheap. They are surface mount devices though, but you can get a kit that includes USB port, the chip already connected to a board with a DIP plug and some essential circuits. libftdi, which runs on top of libusb, can control both of these and they require no programming (unless you want to change the USB configuration settings such as vendor ID, etc, from the default value) This is the FT245 chip which is basically USB-to-Parallel. Chips: http://www.ftdichip.com/Products/FT245R.htm Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm The spec sheet for the board seems quite simple. It's pin out is similar to that of a parallel port in that you have your data lines DB0-DB7, etc. It can also be connected in bus-powered configuration (~100mA) or self-powered configuration. The kit is more expensive than the chip itself, but probably easier especially if you don't have any experience with surface mount. You could build it into your device. You could also create a simple switch box out of it to control external devices, maybe connecting each of the data lines to relays to turn on/off eight devices, etc. Brian Vanderburg II From geekmail at usenot.de Mon Jan 26 10:10:11 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 16:10:11 +0100 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> Message-ID: <20090126161011.482e66f9@usenot.de> On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch wrote: > On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > > > content = a.readlines() > > > > (Just because we can now write "for line in file" doesn't mean that > > readlines() is *totally* redundant.) > > But ``content = list(a)`` is shorter. :-) > But much less clear, wouldn't you say? content is now what? A list of lines? Characters? Bytes? I-Nodes? Dates? Granted, it can be inferred from the fact that a file is its own iterator over its lines, but that is a mental step that readlines() frees you from doing. My ~0.0154 ?. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From ivanov.maxim at gmail.com Mon Jan 26 10:22:25 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Mon, 26 Jan 2009 07:22:25 -0800 (PST) Subject: really slow gzip decompress, why? Message-ID: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> I've one big (6.9 Gb) .gz file with text inside it. zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds python code have been doing the same job for 25 minutes and still doesn't finish =( the code is simpliest I could ever imagine: def main(): fh = gzip.open(sys.argv[1]) all(fh) As far as I understand most of the time it executes C code, so pythons no overhead should be noticible. Why is it so slow? From jcd at sdf.lonestar.org Mon Jan 26 10:35:39 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 10:35:39 -0500 Subject: Newby: how to transform text into lines of text In-Reply-To: <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> Message-ID: <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: > On Jan 26, 1:03 pm, "Gabriel Genellina" > wrote: > > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase > > escribi?: > > > > > > > > > Unfortunately, a raw rstrip() eats other whitespace that may be > > > important. I frequently get tab-delimited files, using the following > > > pseudo-code: > > > > > def clean_line(line): > > > return line.rstrip('\r\n').split('\t') > > > > > f = file('customer_x.txt') > > > headers = clean_line(f.next()) > > > for line in f: > > > field1, field2, field3 = clean_line(line) > > > do_stuff() > > > > > if field3 is empty in the source-file, using rstrip(None) as you suggest > > > triggers errors on the tuple assignment because it eats the tab that > > > defined it. > > > > > I suppose if I were really smart, I'd dig a little deeper in the CSV > > > module to sniff out the "right" way to parse tab-delimited files. > > > > It's so easy that don't doing that is just inexcusable lazyness :) > > Your own example, written using the csv module: > > > > import csv > > > > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') > > headers = f.next() > > for line in f: > > field1, field2, field3 = line > > do_stuff() > > > > And where in all of that do you recommend that .decode(some_encoding) > be inserted? > If encoding is an issue for your application, then I'd recommend you use codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() > -- > http://mail.python.org/mailman/listinfo/python-list > From http Mon Jan 26 10:39:59 2009 From: http (Paul Rubin) Date: 26 Jan 2009 07:39:59 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: <7xzlhers8g.fsf@ruckus.brouhaha.com> Steve Holden writes: > Quite. Python is a language "for consenting adults". Shouldn't such a language allow consenting adults to enter a BDSM scene without being moralized at, if that's what they want to do? ;-) From robin at reportlab.com Mon Jan 26 10:45:25 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jan 2009 15:45:25 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: <497DBA69.8030201@chamonix.reportlab.co.uk> References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> <497AE1F8.5040008@jessikat.plus.net> <497DBA69.8030201@chamonix.reportlab.co.uk> Message-ID: <497DDA95.8070106@chamonix.reportlab.co.uk> Robin Becker wrote: > I found that this error > >> Exception RuntimeError: 'maximum recursion depth exceeded in >> __subclasscheck__' in ignored > > occurs when attempting to copy (copy.copy(inst)) an instance of a class > that looks like this > > class LazyParagraph(_LazyMixin,TTParagraph): > SUPER=TTParagraph > _CLEAN_SPACE=1 ........ > > I have attempted to abstract the problem, but so far I haven't found the > vital bits. OK this turns out to be one of those useful exercises after all. After instrumenting the copy instance copy func my colleague and I found the problem occurs in this innocuous looking example ################### import copy class _LazyMixin: """don't do any initialization until later""" def __init__(self,*args): self._args = args self._initialized = 0 def __getattr__(self,a): if not self._initialized: self._Initialize() return getattr(self,a) raise AttributeError("No attribute '%s'" % a) def _Initialize(self): if not self._initialized: self._initialized = 1 del self._args l=_LazyMixin() print l._initialized copy.debug=1 copy.copy(l) ################### it turns out that in the absence of other info _copy_inst creates a dummy instance and changes its class to the incoming class. It then asks the new unpopulated instance if it has an attribute __setstate__, that triggers the _LazyMixin __getattr__ which fails because there's no _initialize member so __getattr__ gets recalled etc etc. Presumably in earlier pythons this bad behaviour is just hidden. The fix for us is to provide a __setstate__ which does what the no __setstate__ code does ie update __dict__. However, since the _copy_inst code knows there can be no members on the new instance should it not be asking the __class__ for __setstate__? -- Robin Becker From deets at nospam.web.de Mon Jan 26 10:47:03 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 16:47:03 +0100 Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: <6u647nFbor76U1@mid.uni-berlin.de> redbaron wrote: > I've one big (6.9 Gb) .gz file with text inside it. > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > python code have been doing the same job for 25 minutes and still > doesn't finish =( the code is simpliest I could ever imagine: > > def main(): > fh = gzip.open(sys.argv[1]) > all(fh) > > As far as I understand most of the time it executes C code, so pythons > no overhead should be noticible. Why is it so slow? I'm guessing here - but if gzip streams (and AFAIK it does), the commandline will simply stream to /dev/null. OTOH, python is not streaming, it will instead allocate buffers for the whole file. Which for a *zipped* 6.9Gb file might take a while. Diez From jay.amorin at gmail.com Mon Jan 26 10:51:02 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Mon, 26 Jan 2009 23:51:02 +0800 Subject: AttributeError: 'module' object has no attribute 'open_workbook' Message-ID: Hi, Kindly help, I've got this error when running my script: AttributeError: 'module' object has no attribute 'open_workbook' Here's my code: #!/usr/bin/python import xlrd import sys mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) firstSheet = wb.sheet_by_index(0) for myRows in range(sh.nrows): print firstSheet.row_values(myRows) Here's the error message: root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls Traceback (most recent call last): File "./xlrd.py", line 3, in import xlrd File "/home/jayam/project/xlrd.py", line 6, in mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) AttributeError: 'module' object has no attribute 'open_workbook' Thanks, Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at jmcneil.net Mon Jan 26 10:51:42 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 26 Jan 2009 07:51:42 -0800 (PST) Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: On Jan 26, 10:22 am, redbaron wrote: > I've one big (6.9 Gb) .gz file with text inside it. > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > python code have been doing the same job for 25 minutes and still > doesn't finish =( the code is simpliest I could ever imagine: > > def main(): > fh = gzip.open(sys.argv[1]) > all(fh) > > As far as I understand most of the time it executes C code, so pythons > no overhead should be noticible. Why is it so slow? Look what's happening in both operations. The zcat operation is simply uncompressing your data and dumping directly to /dev/null. Nothing is done with the data as it's uncompressed. On the other hand, when you call 'all(fh)', you're iterating through every element in in bigfile.gz. In other words, you're reading the file and scanning it for newlines versus simply running the decompression operation. From jeff at jmcneil.net Mon Jan 26 11:02:55 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 26 Jan 2009 08:02:55 -0800 (PST) Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: <0fee268a-e6af-4ede-94a9-86b7408628cf@q30g2000prq.googlegroups.com> On Jan 26, 10:51 am, Jeff McNeil wrote: > On Jan 26, 10:22 am, redbaron wrote: > > > I've one big (6.9 Gb) .gz file with text inside it. > > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > > python code have been doing the same job for 25 minutes and still > > doesn't finish =( the code is simpliest I could ever imagine: > > > def main(): > > fh = gzip.open(sys.argv[1]) > > all(fh) > > > As far as I understand most of the time it executes C code, so pythons > > no overhead should be noticible. Why is it so slow? > > Look what's happening in both operations. The zcat operation is simply > uncompressing your data and dumping directly to /dev/null. Nothing is > done with the data as it's uncompressed. > > On the other hand, when you call 'all(fh)', you're iterating through > every element in in bigfile.gz. In other words, you're reading the > file and scanning it for newlines versus simply running the > decompression operation. The File: ---------------------------------------------------- [jeff at marvin ~]$ ls -alh junk.gz -rw-rw-r-- 1 jeff jeff 113M 2009-01-26 10:42 junk.gz [jeff at marvin ~]$ The 'zcat' time: ---------------------------------------------------- [jeff at marvin ~]$ time zcat junk.gz > /dev/null real 0m2.390s user 0m2.296s sys 0m0.093s [jeff at marvin ~]$ Test Script #1: ---------------------------------------------------- import sys import gzip fs = gzip.open('junk.gz') data = fs.read(8192) while data: sys.stdout.write(data) data = fs.read(8192) Test Script #1 Time: ---------------------------------------------------- [jeff at marvin ~]$ time python test9.py >/dev/null real 0m3.681s user 0m3.201s sys 0m0.478s [jeff at marvin ~]$ Test Script #2: ---------------------------------------------------- import sys import gzip fs = gzip.open('junk.gz') all(fs) Test Script #2 Time: ---------------------------------------------------- [jeff at marvin ~]$ time python test10.py real 1m51.764s user 1m51.475s sys 0m0.245s [jeff at marvin ~]$ From Jan.Koprowski at gmail.com Mon Jan 26 11:05:17 2009 From: Jan.Koprowski at gmail.com (Jan Koprowski) Date: Mon, 26 Jan 2009 08:05:17 -0800 (PST) Subject: Problem with Nose testing until forking process Message-ID: Hi ! I write application witch sometimes need fork to shell based process (some kind of shell command). I snatch stdin, stdout, stderr and two additional streams and fork process to run command and get results. # -*- encoding: utf-8 -*- import os import sys import subprocess def pipes_function(): global login_r, login_w, password_r, password_w try: os.fdopen(3).close() except OSError: pass try: os.fdopen(4).close() except OSError: pass os.close(login_w) os.close(password_w) os.dup2(login_r, 3) os.dup2(password_r, 4) class BrokerProcess: __slots__ = ['username', 'password', 'command', 'stdout', 'stderr', 'returned'] def run(self): global login_r, login_w, password_r, password_w login_r, login_w = os.pipe() password_r, password_w = os.pipe() wrapper = subprocess.Popen(args=('/usr/bin/special/wrapper'), preexec_fn=pipes_function, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.close(login_r) os.close(password_r) login_w = os.fdopen(login_w, 'w') password_w = os.fdopen(password_w, 'w') login_w.write(self.username) login_w.close() password_w.write(self.password) password_w.close() self.command = self.command.encode() wrapper.stdin.write(self.command) wrapper.stdin.close() self.stdout = wrapper.stdout.read() self.stderr = wrapper.stderr.read() self.returned = wrapper.wait() return self.returned My problem is that when I run nose test for function witch use this broker i get followin errors (I test Pylons app): File "/home/users/matrix/johny/Pylons/zhradmin/zhradmin2/zhradmin2/ controllers/account.py", line 51, in login account.login() File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/model/ account.py", line 29, in login File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/lib/ brokerprocess.py", line 41, in run File "/usr/local/lib/python2.5/subprocess.py", line 594, in __init__ errread, errwrite) File "/usr/local/lib/python2.5/subprocess.py", line 1091, in _execute_child raise child_exception OSError: [Errno 9] Bad file descriptor Is anyone know why I get error ? From google at mrabarnett.plus.com Mon Jan 26 11:07:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 26 Jan 2009 16:07:39 +0000 Subject: AttributeError: 'module' object has no attribute 'open_workbook' In-Reply-To: References: Message-ID: <497DDFCB.7060905@mrabarnett.plus.com> Jay Jesus Amorin wrote: > Hi, > > Kindly help, I've got this error when running my script: > > AttributeError: 'module' object has no attribute 'open_workbook' > > > Here's my code: > > #!/usr/bin/python > > import xlrd > import sys > > mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) > firstSheet = wb.sheet_by_index(0) > > for myRows in range(sh.nrows): > print firstSheet.row_values(myRows) > > > Here's the error message: > > root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls > Traceback (most recent call last): > File "./xlrd.py", line 3, in > import xlrd > File "/home/jayam/project/xlrd.py", line 6, in > mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) > AttributeError: 'module' object has no attribute 'open_workbook' > From the traceback it looks like your script is called "xlrd.py", which is the same name as the module "xlrd" that it's importing. If that's the case, rename your script. From digitig at gmail.com Mon Jan 26 11:09:08 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 16:09:08 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhers8g.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <7xzlhers8g.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/26 Paul Rubin <"http://phr.cx"@nospam.invalid>: > Steve Holden writes: >> Quite. Python is a language "for consenting adults". > > Shouldn't such a language allow consenting adults to enter a BDSM > scene without being moralized at, if that's what they want to do? ;-) The language doesn't stop you. You can shift all of your code over to Ada if you want to, and although /some/ Pythonistas might shake their heads in bewilderment, I don't think there would be any moralising. The question is whether Python has to /provide/ the BDSM scene for you. I don't think it's realistic for a language to provide every possible degree of BDSM from BCPL to Ada, Eiffel and beyond. A language has to be positioned somewhere on the scale, and deciding whether that's the right point on the scale for you and your project is part of what being a grown-up programmer is about. One size does not fit all, one language is not ideal for all applications. -- Tim Rowe From steve at holdenweb.com Mon Jan 26 11:10:31 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 11:10:31 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhers8g.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <7xzlhers8g.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Steve Holden writes: >> Quite. Python is a language "for consenting adults". > > Shouldn't such a language allow consenting adults to enter a BDSM > scene without being moralized at, if that's what they want to do? ;-) Yes, but you know what moralizers are like ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jldunn2000 at googlemail.com Mon Jan 26 11:11:43 2009 From: jldunn2000 at googlemail.com (loial) Date: Mon, 26 Jan 2009 08:11:43 -0800 (PST) Subject: Web services Message-ID: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> I am trying to learn about web services and how to interface with a 3rd party web service from python. Can anyone point me at an idiots guide/tutorial for someone who is new to web services? From jcd at sdf.lonestar.org Mon Jan 26 11:11:58 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 11:11:58 -0500 Subject: I'm a python addict ! In-Reply-To: <87pri9y9hh.fsf@agentultra.com> References: <87pri9y9hh.fsf@agentultra.com> Message-ID: <1232986318.3693.17.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 14:43 -0800, J Kenneth King wrote: > Linuxguy123 writes: > > > I just started using python last week and I'm addicted. > > > > I hate Perl. I never did learn to use it with any competence. I has to > > be the most obfuscated, cryptic language I've ever seen. Making it > > "object oriented" only makes it worse ! > > .. .. > > I program full-time in Python, so I share your excitement and > enthusiasm. But bashing Perl like that doesn't make you sound very > smart. I'm probably one of the very few Python programmers who came from > (and still occassionally) use Perl. Really? I think many many python programmers cut their teeth on Perl. I for one. I loved programming in it when I did, but I hate having to try to understand OPP. Now, when I deal with Perl, it's mostly legacy code, and it's a miserable experience. > I've written non-trivial programs in > it and from my experience I can tell you that it's actually a great > language. The Moose object system is well beyond Python's class > system. But I guess you wouldn't know that. > > So yay for Python, but don't get in the habit of criticising that which > you do not know. There are legitimate reasons to criticize things even when they are powerful. Cheers, Cliff From mail at anjanesh.net Mon Jan 26 11:31:21 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 26 Jan 2009 22:01:21 +0530 Subject: Method returning an Iterable Object Message-ID: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> Is there a way to return an iterable object ? class twoTimes: def __init__(self, n): self.__n = n def getNext(): self.__n *= 2 return self.__n t = twoTimes(5) while (n in t.getNext()): # while (n in t): print (n) -- Anjanesh Lekshmnarayanan From steve at holdenweb.com Mon Jan 26 11:44:01 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 11:44:01 -0500 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> References: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > Is there a way to return an iterable object ? > > class twoTimes: > def __init__(self, n): > self.__n = n > > def getNext(): > self.__n *= 2 > return self.__n > > > t = twoTimes(5) > while (n in t.getNext()): # while (n in t): > print (n) > Sure: class EveryOther: def __init__(self, seq): self.seq = seq self.idx = 0 def next(self): self.idx += 1 if self.idx >= len(self.seq): raise StopIteration value = self.seq[self.idx] self.idx += 1 return value def __iter__(self): return self print [x for x in EveryOther(range(10)) [1, 3, 5, 7, 9] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jcd at sdf.lonestar.org Mon Jan 26 11:54:10 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 11:54:10 -0500 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: <1232988850.3835.1.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > Want to change the type/behavior of an object from class A to class > B? How about this: > > aobj = A() > aobj.__class__ = B > > Try *that* in as simple-looking C++ or Java! Wow. That looks very powerful and fun. But scary. Any thoughts on how you would use that in a way that wouldn't unleash sulphurous code smells? Cheers, Cliff From geekmail at usenot.de Mon Jan 26 12:01:52 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 18:01:52 +0100 Subject: Method returning an Iterable Object References: Message-ID: <20090126180152.4a37d03f@usenot.de> On Mon, 26 Jan 2009 22:01:21 +0530 Anjanesh Lekshminarayanan wrote: > Is there a way to return an iterable object ? > > class twoTimes: > def __init__(self, n): > self.__n = n > > def getNext(): > self.__n *= 2 > return self.__n > > Rename getNext() to next() and create another method named __iter__() that just returns self. TwoTimes is now an iterator. You can also replace the whole class with a function thusly: def two_times(n): for k in itertools.count(1): yield n * (2**k) This function is then called a generator (because it generates an iterator). You can now say infinitely_doubling_numbers = two_times(2) for number in in infinitely_doubling_numbers: print number to the same effect as the iterator version above. python.org seems uncooperative at the moment, but look up iterators or the iterator protocol and generators if it works for you. > t = twoTimes(5) > while (n in t.getNext()): # while (n in t): > print (n) > You are aware that this is an infinite loop, as is my example above BTW? (Probably just an example, but I ask just in case.) Also, could it be that you mean "for n in t"? regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From invalid at invalid Mon Jan 26 12:08:48 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 26 Jan 2009 11:08:48 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On 2009-01-26, Lie Ryan wrote: > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. 1) Pitch has nothing to do with voltage. A high-pitch sound and a low pitch sound can have the exact same voltage. 2) The OP's device requires quite a bit of power. There is almost no power available from the line-out jack, and the voltage is limited to about 1V. If his sound card has a power-amp (none do these days), he might be able to get a usable amount of power. > The device will need an additional transistor to separate low > voltage from the high voltage. He'll need more than a transistor. He needs a power supply, some sort of rectifier/detector, and a comparitor. It would be more interesting to use notch filters to detect different frequencies so that you could have multiple output "bits". > I don't know how much power can be pulled from jack out, Almost none, and what's there is very low voltage. > but for a home brewn device it is still feasible to draw power > from USB and signal from jack out. It would probably be easier to buy a USB-parallel port chip. Then he's got power from the USB bus and something like 14 parallel I/O pins he can control. Alternatively A USB-serial chip will provide 2 outputs and 4 inputs. -- Grant Edwards grante Yow! Not SENSUOUS ... only at "FROLICSOME" ... and in visi.com need of DENTAL WORK ... in PAIN!!! From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 12:10:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 18:10:49 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> Message-ID: <497dee70$0$27596$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > You are trying to dictate that the library implementer not be allowed > to use enforced access restriction. And, in the larger sense, you are > trying to dictate that access restrictions not be enforced in Python. FWIW, it's actually *you* who are trying to dictate that access restrictions should be enforced in Python. From notvalid2 at sbcglobal.net Mon Jan 26 12:15:40 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 26 Jan 2009 09:15:40 -0800 Subject: What is intvar? [Python Docs] In-Reply-To: <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> Message-ID: r wrote: > W. eWatson, > > I contacted the author of New Mexico Techs "Introduction to Tkinter" a > couple of weeks ago. He is going to update the reference material with > a few missing widgets and some info on Photo and Bitmap classes. I > really love the NMT layout and use it quite often. Fredricks > Tkinterbook is more detail but lacking in navigation. I swing back and > forth between both sites. > > > > Good. Thanks. I think Lundh might have taken his material to book form. I might be repeating myself here, but If anyone has pdf experience, and could provide page numbers and maybe a TOC for some of Lundh's contributions, that would be helpful. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:30:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:30:06 -0200 Subject: Python C API (PyObject_CallMethod clear object) References: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> Message-ID: En Mon, 26 Jan 2009 08:47:31 -0200, escribi?: > On 26 Jan., 03:25, "Gabriel Genellina" wrote: >> En Sun, 25 Jan 2009 23:46:01 -0200, >> escribi?: >> >> > I have a problm with deallocating stuff. I call a function with this >> > command: >> >> > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); >> >> > if(rvalue==NULL) >> > ? ? PyErr_Print(); >> > else >> > ? ? Py_DECREF(rvalue); > > Yes, you are right. I got this issue not in syntax error, I get it on > a runtime error like this: > > t = MyImage() > self.test("hallo") #test takes an integer so this would throw an > exception. > > Here you see, an object of the type MyImage() was created but its not > deleted. 't' is a local reference so how can I do that? It will be deleted after the last reference to it is released, as every object in Python. If the above two lines are the whole function code, this will happen when exiting the function. If some other object holds a reference to this MyImage instance (by example, by doing xxx.attribute = t, or inserting it in a list) then that won't happen until all those references are released. Note that, in Python 2.x, the traceback object holds a reference to all local variables -- if you store the traceback somewhere, those objects won't be deleted. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:36:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:36:35 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> Message-ID: En Mon, 26 Jan 2009 13:35:39 -0200, J. Cliff Dyer escribi?: > On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: >> On Jan 26, 1:03 pm, "Gabriel Genellina" >> wrote: >> > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase >> > escribi?: >> > > I suppose if I were really smart, I'd dig a little deeper in the CSV >> > > module to sniff out the "right" way to parse tab-delimited files. >> > >> > It's so easy that don't doing that is just inexcusable lazyness :) >> > Your own example, written using the csv module: >> > >> > import csv >> > >> > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> > headers = f.next() >> > for line in f: >> > field1, field2, field3 = line >> > do_stuff() >> > >> >> And where in all of that do you recommend that .decode(some_encoding) >> be inserted? > > If encoding is an issue for your application, then I'd recommend you use > codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() This would be the best way *if* the csv module could handle Unicode input, but unfortunately this is not the case. See my other reply. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:36:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:36:36 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> Message-ID: En Mon, 26 Jan 2009 13:35:39 -0200, J. Cliff Dyer escribi?: > On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: >> On Jan 26, 1:03 pm, "Gabriel Genellina" >> wrote: >> > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase >> > escribi?: >> > > I suppose if I were really smart, I'd dig a little deeper in the CSV >> > > module to sniff out the "right" way to parse tab-delimited files. >> > >> > It's so easy that don't doing that is just inexcusable lazyness :) >> > Your own example, written using the csv module: >> > >> > import csv >> > >> > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> > headers = f.next() >> > for line in f: >> > field1, field2, field3 = line >> > do_stuff() >> > >> >> And where in all of that do you recommend that .decode(some_encoding) >> be inserted? > > If encoding is an issue for your application, then I'd recommend you use > codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() This would be the best way *if* the csv module could handle Unicode input, but unfortunately this is not the case. See my other reply. -- Gabriel Genellina From clp2 at rebertia.com Mon Jan 26 12:50:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 09:50:55 -0800 Subject: Web services In-Reply-To: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> References: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> Message-ID: <50697b2c0901260950q1a52a4d0g901019e7ca2824ff@mail.gmail.com> On Mon, Jan 26, 2009 at 8:11 AM, loial wrote: > I am trying to learn about web services and how to interface with a > 3rd party web service from python. > > Can anyone point me at an idiots guide/tutorial for someone who is new > to web services? The XML-RPC client module in the std lib (xmlrpclib) includes an example: http://docs.python.org/library/xmlrpclib.html#example-of-client-usage And the XML-RPC server server in the stdlib also includes a full client-server example: http://docs.python.org/library/simplexmlrpcserver.html#simplexmlrpcserver-example Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ptmcg at austin.rr.com Mon Jan 26 12:52:01 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 26 Jan 2009 09:52:01 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> On Jan 26, 10:54?am, "J. Cliff Dyer" wrote: > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > Want to change the type/behavior of an object from class A to class > > B? ?How about this: > > > ? ? aobj = A() > > ? ? aobj.__class__ = B > > > Try *that* in as simple-looking C++ or Java! > > Wow. ?That looks very powerful and fun. ?But scary. ?Any thoughts on how > you would use that in a way that wouldn't unleash sulphurous code > smells? > This technique is perfect for implementing the GoF State pattern. In the State pattern, you implement behavior for an object's various states using one of several interchangeable classes. The classes are "interchangeable" in that they all implement a common interface. Here is my favorite State pattern example, a traffic light: import time class TrafficLight(object): pass class RedLight(TrafficLight): cars_can_go = False pedestrians_can_cross = True color = (255,0,0) duration = 20 class YellowLight(TrafficLight): cars_can_go = True pedestrians_can_cross = False color = (255,255,0) duration = 5 class GreenLight(TrafficLight): cars_can_go = True pedestrians_can_cross = False color = (0,255,0) duration = 15 # now add in next_state class vars for state transitions RedLight.next_state = GreenLight YellowLight.next_state = RedLight GreenLight.next_state = YellowLight TrafficLight.initial_state = RedLight # run a traffic light for a while... can_they = lambda cond : ("can't","can")[cond] light = TrafficLight.initial_state() while 1: print light.__class__.__name__ print "waiting for", light.duration, "seconds" print "Cars", can_they(light.cars_can_go), "go" print "People", can_they(light.pedestrians_can_cross), "cross" print time.sleep(light.duration) # how you have to do it in C++ and Java # light = light.next_state() # using Python light.__class__ = light.next_state Gives this output: RedLight waiting for 20 seconds Cars can't go People can cross GreenLight waiting for 15 seconds Cars can go People can't cross YellowLight waiting for 5 seconds Cars can't go People can't cross RedLight waiting for 20 seconds Cars can't go People can cross ... and so on ... In Python, the base TrafficLight class isn't even necessary ("don't need no stinking interfaces!"), although it is a good place to define default behavior, and it helps tie together the other classes from a self-documentation standpoint. But any class that has the necessary attributes would suffice, whether it inherits from TrafficLight or not. class HoldForEmergencyVehiclesLight(object): cars_can_go = False pedestrians_can_cross = False color = (255,0,0) -- Paul From gil.shinar at gmail.com Mon Jan 26 13:13:54 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Mon, 26 Jan 2009 10:13:54 -0800 (PST) Subject: Process crash with no reason Message-ID: Hi All, I'm running a program that is acting as a nice interface to sybase' replication server. The program is using the cherrypy web service for the GUI. The process is crashing every few days with no reason. In the log I can see INFO and DEBUG (No ERROR) log lines and I do not get any TraceBack python's message. This program is running on solaris 9 machine. Where can I see or what can I do in order to find out what causes the process to crash? I have tried simulating a "traceBack" message and I could see this traceback message in one of the log files I'm using. When the process crashes without my help, I don't have a clue. Let me know if you need any other info Thanks Gil From kay.schluehr at gmx.net Mon Jan 26 13:14:05 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Mon, 26 Jan 2009 10:14:05 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <790bc782-b49b-4a46-a50e-f190203d8efc@i24g2000prf.googlegroups.com> On 26 Jan., 15:13, Steve Holden wrote: > Mark Wooding wrote: > > unine... at gmail.com writes: > [...] > > * Assignment stores a new (reference to a) value in the variable. > > > * Binding modifies the mapping between names and variables. > > I realise I have omitted what was doubtless intended to be explanatory > detail, but I am having trouble reconciling those sentences. Would you > mind explaining "in vacuuo" what you see as the difference between > assignment and binding? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ "Assignment" is binding values to names whereas "binding" is binding names to scopes. Marks terminology is a bit more standard than Pythons in this respect. As you know, Python avoids the idea of variables as if those were storage cells having a fixed logical address. From jef.mangelschots at gmail.com Mon Jan 26 13:16:28 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 10:16:28 -0800 (PST) Subject: unable to print Unicode characters in Python 3 Message-ID: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Hi, while checking out Python 3, I read that all text strings are now natively Unicode. In the Python language reference (http://docs.python.org/3.0/reference/ lexical_analysis.html) I read that I can show Unicode character in several ways. "\uxxxx" supposedly allows me to specify the Unicode character by hex number and the format "\N{name}" allows me to specify by Unicode name. Neither seem to work for me. What am I doing wrong ? Please see error output below where I am trying to show the EURO sign (http://www.fileformat.info/info/unicode/char/20ac/index.htm): Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print('\u20ac') Traceback (most recent call last): File "", line 1, in File "c:\python30\lib\io.py", line 1491, in write b = encoder.encode(s) File "c:\python30\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in position 0: character maps to >>> >>> print ("\N{EURO SIGN}") Traceback (most recent call last): File "", line 1, in File "c:\python30\lib\io.py", line 1491, in write b = encoder.encode(s) File "c:\python30\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in position 0: character maps to From mail at anjanesh.net Mon Jan 26 13:35:53 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 27 Jan 2009 00:05:53 +0530 Subject: Method returning an Iterable Object In-Reply-To: <20090126180152.4a37d03f@usenot.de> References: <20090126180152.4a37d03f@usenot.de> Message-ID: <1a7951080901261035i1f8ae3dds1baa22d313e44ae7@mail.gmail.com> > You can also replace the whole class with a function thusly: > > def two_times(n): > for k in itertools.count(1): > yield n * (2**k) > > This function is then called a generator (because it generates an > iterator). You can now say > > infinitely_doubling_numbers = two_times(2) > for number in in infinitely_doubling_numbers: > print number Oh..this is new. Will checkup itertools. Thanks. >> t = twoTimes(5) >> while (n in t.getNext()): # while (n in t): >> print (n) >> > You are aware that this is an infinite loop, as is my example above BTW? > (Probably just an example, but I ask just in case.) I was aware this was an infinite loop - just didnt want to put more code for an example. From martin at marcher.name Mon Jan 26 13:36:33 2009 From: martin at marcher.name (Martin) Date: Mon, 26 Jan 2009 19:36:33 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <5fa6c12e0901261036v7a300832pa848a254b664b477@mail.gmail.com> Hmm this works for me, it's a self compiled version: ~ $ python3 Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print("\u20ac") ? >>> print ("\N{EURO SIGN}") ? >>> 2009/1/26 jefm : > What am I doing wrong ? "\N{EURO SIGN}".encode("ISO-8859-15") ## could be something but I'm pretty sure I'm totally wrong on this -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From philip at semanchuk.com Mon Jan 26 13:40:59 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 26 Jan 2009 13:40:59 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: <11A88827-A885-43C8-98A1-6AD969DC1424@semanchuk.com> On Jan 26, 2009, at 1:13 PM, gil.shinar at gmail.com wrote: > Hi All, > > I'm running a program that is acting as a nice interface to sybase' > replication server. The program is using the cherrypy web service for > the GUI. The process is crashing every few days with no reason. In the > log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > TraceBack python's message. This program is running on solaris 9 > machine. > Where can I see or what can I do in order to find out what causes the > process to crash? > I have tried simulating a "traceBack" message and I could see this > traceback message in one of the log files I'm using. When the process > crashes without my help, I don't have a clue. > Let me know if you need any other info Although Python isn't immune to fatal errors like you describe, I'd immediately suspect a 3rd-party module instead, esp. one written in C or C++. Are you using anything like that? From benjamin.kaplan at case.edu Mon Jan 26 13:44:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 13:44:35 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: On Mon, Jan 26, 2009 at 1:16 PM, jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) > I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format "\N{name}" allows me to specify by Unicode > name. > Neither seem to work for me. > What am I doing wrong ? > > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print('\u20ac') > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > >>> > >>> print ("\N{EURO SIGN}") > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > -- > The strings are represented internally as Unicode, but you can't print them that way. When you call print(), python needs to turn your string into a sequence of bytes that are then interpreted by the terminal (in your case cmd.exe). On modern Unix-based systems (like Mac and Linux), the console uses UTF-8. Since it uses a unicode-based encoding, everything prints fine. Your Windows machine seems determined to use the old (c. 1980s) CP 437. Code Page 437 doesn't have the Euro symbol, so python throws an error. Try using "\N{EURO SIGN}".encode("cp1252"). If your console still can't handle it, you'll need to change its encoding. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik.kant at gmail.com Mon Jan 26 13:49:24 2009 From: fredrik.kant at gmail.com (fredrik kant) Date: Mon, 26 Jan 2009 19:49:24 +0100 Subject: Python and CUDO Message-ID: <415a7e520901261049s7c5502e7heb835ff6e0918f7f@mail.gmail.com> Hi! Sorry about the misspelling, it should of course been "NIVIDAS CUDA". I also noticed that there wrappers around such as: pycuda which answers my question. -- Fredrik Kant Kant Consulting AB Mobile: +46 70 787 06 01 www.kantconsulting.se -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmohr at s.netic.de Mon Jan 26 14:06:20 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 26 Jan 2009 20:06:20 +0100 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: Hello, >> Basically, this here works but gives a warning: >> RuntimeWarning: Parent module 'ext_abc' not found while handling >> absolute import > > >> here = os.path.abspath('.') > > (Unrelated to the main question, but you probably want to use > os.path.dirname(os.path.abspath(__file__)) instead - the above just > returns the current directory, which might not be the directory containing > the module) Thanks, i'll try that. >> mpath = os.path.abspath('mymodule') >> epath = os.path.abspath('extension') >> >> sys.path.append(here) >> sys.path.append(mpath) >> >> FILE mymodule/__init__.py: > > So mymodule is actually a package. Packages should *not* appear in > sys.path. Oh, how does it find modules then? I thought that would be PYTHONPATH or sys.path ? Best regards, Torsten. From semanticist at gmail.com Mon Jan 26 14:06:44 2009 From: semanticist at gmail.com (Miles) Date: Mon, 26 Jan 2009 14:06:44 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <6u5cokFdmi22U1@mid.uni-berlin.de> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> <6u5cokFdmi22U1@mid.uni-berlin.de> Message-ID: On Mon, Jan 26, 2009 at 4:06 AM, Diez B. Roggisch wrote: > There are people who say something along the lines of "be strict when > writing, and tolerant when reading" (the exact quote is different, but > neither google:~site:mybrain nor any other have helped me here) That's Postel's Law: http://en.wikipedia.org/wiki/Robustness_Principle -Miles From jef.mangelschots at gmail.com Mon Jan 26 14:09:05 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 11:09:05 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> >Hmm this works for me, >it's a self compiled version: >~ $ python3 >Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) >[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 You are running on Linux. Mine is on Windows. Anyone else have this issue on Windows ? From Scott.Daniels at Acm.Org Mon Jan 26 14:16:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 26 Jan 2009 11:16:53 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: Tim Rowe wrote: > ... I like the second style because it makes it leaves the 2-d > implementation hidden, which is the whole point of encapsulation. I like the second as well, in that it it allows the parent to update any related data structures (for example, updating a display). However, I am a bit nervous about changing the signature of the move message, and would be more tempted to add a move3d, for multiple inheritance reasons. >> But then I am a fan of Hungarian notation, which many >> programmers can't stand. > > Is it that programmers can't stand it, or is it that they can't stand > it when it's imposed when not needed? .... Well, I tend to be one who hates Hungarian. I spent a long time being a fan of strong typing. Then, I felt the compiler would enforce the typing, and the Hungarian muddied the readability of the expressions. I felt that you should define a type for distance_in_yards, and not have that confusable with distance_in_meters (though you might provide an automatic conversion. Now, I feel strong-typing systems cannot express the type relationships that I want as a programmer in the face of sub-typing, and I hold no hope that (A) such a language will appear, or (B) that the strong majority of the bugs I produce in Python will be caught by a statically typed system. I do however, still find the neddling little text annotations in the variable naming to be irritating noise that distracts from the readability of the expressions. The kinds of type systems that I want(ed) is most closely expressed by F-Bounded polymorphism, and that doesn't manage to be both expressive enough and computationally feasible to use as a production type system. For example, I'd like to type a sort function or a project function, and all I've seen looks like its fit will feel more like a suit of armor than a shirt. --Scott David Daniels Scott.Daniels at Acm.Org From geekmail at usenot.de Mon Jan 26 14:28:04 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 20:28:04 +0100 Subject: Method returning an Iterable Object References: <20090126180152.4a37d03f@usenot.de> Message-ID: <20090126202804.28c65e90@usenot.de> On Tue, 27 Jan 2009 00:05:53 +0530 Anjanesh Lekshminarayanan wrote: > > You can also replace the whole class with a function thusly: > > > > def two_times(n): > > for k in itertools.count(1): > > yield n * (2**k) > > > > This function is then called a generator (because it generates an > > iterator). You can now say > > > > infinitely_doubling_numbers = two_times(2) > > for number in in infinitely_doubling_numbers: > > print number > > Oh..this is new. Will checkup itertools. Thanks. > OK, happy I could help. But my point was the yield statement (in case you didn't know about yield). regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From Scott.Daniels at Acm.Org Mon Jan 26 14:41:25 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 26 Jan 2009 11:41:25 -0800 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: <9r6dnXezlL4ajOPUnZ2dnUVZ_ozinZ2d@pdx.net> J. Cliff Dyer wrote: > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: >> ... How about this: >> aobj = A() >> aobj.__class__ = B > ... Wow. That looks very powerful and fun. But scary. Any thoughts > on how you would use that in a way that wouldn't unleash sulphurous > code smells? Seems like a nice way to transition between "ActiveAccount": and "InActiveAccount" or some such. The requirement is that the two classes share memory layout (essentially, class type and all __slots__ involved (including __dict__). It is a bit prickly, so I'd personally only start to use it once my methods were littered with lots of: ... if self.active_flag: self.account.update(... else: raise ValueError('Purchase prohibitted') Could also be useful as the stub for a kept-on-disk structure, where all methods on the inactive one rolled in data switched class, and invoked their corresponding method. --Scott David Daniels Scott.Daniels at Acm.Org From rantingrick at gmail.com Mon Jan 26 14:51:54 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jan 2009 11:51:54 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget Message-ID: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> I am wondering how i might pipe stdout && stderr to a Tkinter Label widget. here are a few ways to set the text #-- Create a label --# label = Label(master, text='Default Text') label.pack() # -- two ways to change the text --# label['text'] = 'New Text' label.configure(text='New Text') #-- or use a control variable --# v = StringVar(master) label.config(textvariable=v) #-- Change useing variable --# v.set('NewText') So my question is -- I know hoe to set the text displayed in the label wiget, but hoow do i capture stdout and send that to the widget? From jcd at sdf.lonestar.org Mon Jan 26 15:06:18 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 15:06:18 -0500 Subject: I'm a python addict ! In-Reply-To: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <1233000378.4334.6.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 09:52 -0800, Paul McGuire wrote: > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: > > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > > Want to change the type/behavior of an object from class A to class > > > B? How about this: > > > > > aobj = A() > > > aobj.__class__ = B > > > > > Try *that* in as simple-looking C++ or Java! > > > > Wow. That looks very powerful and fun. But scary. Any thoughts on how > > you would use that in a way that wouldn't unleash sulphurous code > > smells? > > > > This technique is perfect for implementing the GoF State pattern. > > In the State pattern, you implement behavior for an object's various > states using one of several interchangeable classes. The classes are > "interchangeable" in that they all implement a common interface. Here > is my favorite State pattern example, a traffic light: > > > import time > > class TrafficLight(object): > pass > > class RedLight(TrafficLight): > cars_can_go = False > pedestrians_can_cross = True > color = (255,0,0) > duration = 20 > > class YellowLight(TrafficLight): > cars_can_go = True > pedestrians_can_cross = False > color = (255,255,0) > duration = 5 > > class GreenLight(TrafficLight): > cars_can_go = True > pedestrians_can_cross = False > color = (0,255,0) > duration = 15 > > # now add in next_state class vars for state transitions > RedLight.next_state = GreenLight > YellowLight.next_state = RedLight > GreenLight.next_state = YellowLight > TrafficLight.initial_state = RedLight > > # run a traffic light for a while... > can_they = lambda cond : ("can't","can")[cond] > light = TrafficLight.initial_state() > while 1: > print light.__class__.__name__ > print "waiting for", light.duration, "seconds" > print "Cars", can_they(light.cars_can_go), "go" > print "People", can_they(light.pedestrians_can_cross), "cross" > print > time.sleep(light.duration) > > # how you have to do it in C++ and Java > # light = light.next_state() > > # using Python > light.__class__ = light.next_state > > > Gives this output: > > RedLight > waiting for 20 seconds > Cars can't go > People can cross > > GreenLight > waiting for 15 seconds > Cars can go > People can't cross > > YellowLight > waiting for 5 seconds > Cars can't go > People can't cross > > RedLight > waiting for 20 seconds > Cars can't go > People can cross > > ... and so on ... > > > > In Python, the base TrafficLight class isn't even necessary ("don't > need no stinking interfaces!"), although it is a good place to define > default behavior, and it helps tie together the other classes from a > self-documentation standpoint. But any class that has the necessary > attributes would suffice, whether it inherits from TrafficLight or > not. > > class HoldForEmergencyVehiclesLight(object): > cars_can_go = False > pedestrians_can_cross = False > color = (255,0,0) > > > -- Paul > Thanks. That makes sense. But your example creates a new instance of the new class each time, rather than changing the class of a persistent instance, as the original example, to which I was responding, did. But perhaps something like: class TrafficLight(object): def change_light(self): self.__class__ = next_state and then you can persist information about the light (bulb_type in set(['led', 'incandescent']), last_maintenance_date, location, etc.) on the instance level, unaffected by the changing color. Interesting stuff. Cheers, Cliff From Russ.Paielli at gmail.com Mon Jan 26 15:20:26 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 26 Jan 2009 12:20:26 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> <497d7d40$0$4845$426a34cc@news.free.fr> Message-ID: On Jan 26, 1:07 am, Bruno Desthuilliers wrote: > No. I can change the *team's* code. Please *read*. "team's ownership", > ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get > the message, now ? Team ownership doesn't necessarily mean that you can just change code at will. In industry, teams usually have a leader that you need to check with before you can change an interface. A language with enforced access restriction merely provides language support for such coordination. That was my only point. > > Would you give all those developers your password to get into the > > system? No? Wait a minute ... you mean you wouldn't "trust" them with > > your password? But what about "openness"? Are you some sort of fascist > > or what? > > Goodwin point. You loose. Good bye again, Mr P. You missed the point once again. In asking if you are a "fascist," I was *parodying* your attitude that languages with enforced access restrictions are for "fascists" who don't trust their co-workers or employees. [I don't recall if you actually used that word or if it was someone else, but you did use "B&D", which carries the same general impression.] So I parodied your hyperbole, and you dismiss me for it. Without realizing it, you just dismissed yourself, sir. Thanks for saving me the trouble. From heintest at web.de Mon Jan 26 15:21:01 2009 From: heintest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Mon, 26 Jan 2009 21:21:01 +0100 Subject: Anoying unicode / str conversion problem Message-ID: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Hi python experts, in the moment I'm struggling with an annoying problem in conjunction with mysql. I'm fetching rows from a database, which the mysql drive returns as a list of tuples. The default coding of the database is utf-8. Unfortunately in the database there are rows with different codings and there is a blob column. In the app. I search for double entries in the database with this code. hash = {} cursor.execute("select * from table") rows = cursor.fetchall() for row in rows: key = "|".join([str(x) for x in row]) <- here the problem arises if key in hash: print "found double entry" This code works as expected with python 2.5.2 With 2.5.1 it shows this error: key = "|".join(str(x) for x in row) UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in position 3: ordinal not in range(128) When I replace the str() call by unicode(), I get this error when a blob column is being processed: key = "|".join(unicode(x) for x in row) UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: ordinal not in range(128) Please help, how can I convert ANY column data to a string which is usable as a key to a dictionary. The purpose of using a dictionary is to find equal rows in some database tables. Perhaps using a md5 hash from the column data is also an idea ? Thanks a lot in advance, Hans. From tjreedy at udel.edu Mon Jan 26 15:29:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 15:29:29 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Steve Holden wrote: > Terry Reedy wrote: >> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >> new and people write >> try: >> False,True >> except NameError: >> False,True = 0,1 >> >> to make code back compatible. >> > I would claim that the ability to rebind True and False is a simple bug, > though one not likely to be fixed in an 2.x release. The code above > doesn't rebind True and False in interpreters that have them ... In pre-bool 2.x, people never wrote the above but sometime wrote False,True = 0,1 To me it is hardly a bug to not gratuitously break substantial amounts of proper code. >> Back before rebinding 'None' was prohibited, 'is None' was not >> completely guaranteed either (absent reading the rest of a file to be >> sure no rebinding would be done). >> > And that was a bug too, in this case one that *was* removed in 2.4, I > believe. Don't have 2.3 lying around just now. Unlike with True and False, the devs could not think of or find any proper use case for rebinding None and judged that the new prohibition would break very little if any code. As far as I know, they were correct. tjr From ptmcg at austin.rr.com Mon Jan 26 15:37:41 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 26 Jan 2009 12:37:41 -0800 (PST) Subject: I'm a python addict ! References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> On Jan 26, 2:06?pm, "J. Cliff Dyer" wrote: > > Thanks. ?That makes sense. ?But your example creates a new instance of > the new class each time, rather than changing the class of a persistent > instance, as the original example, to which I was responding, did. > Look closer. The line that creates a new instance is commented out, with the notation "how you have to do it in C++ and Java". The actual Python code is just below, and just assigns a new class to self.__class__, as in the original example. -- Paul From benjamin.kaplan at case.edu Mon Jan 26 15:40:41 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 15:40:41 -0500 Subject: Anoying unicode / str conversion problem In-Reply-To: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Mon, Jan 26, 2009 at 3:21 PM, Hans M?ller wrote: > Hi python experts, > > in the moment I'm struggling with an annoying problem in conjunction with > mysql. > > I'm fetching rows from a database, which the mysql drive returns as a list > of tuples. > > The default coding of the database is utf-8. > > Unfortunately in the database there are rows with different codings and > there is a blob > column. > > In the app. I search for double entries in the database with this code. > > hash = {} > cursor.execute("select * from table") > rows = cursor.fetchall() > for row in rows: > key = "|".join([str(x) for x in row]) <- here the problem > arises > if key in hash: > print "found double entry" > > This code works as expected with python 2.5.2 > With 2.5.1 it shows this error: > > > key = "|".join(str(x) for x in row) > UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in > position 3: ordinal > not in range(128) > > When I replace the str() call by unicode(), I get this error when a blob > column is being > processed: > > key = "|".join(unicode(x) for x in row) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: > ordinal not in > range(128) > > > Please help, how can I convert ANY column data to a string which is usable > as a key to a > dictionary. The purpose of using a dictionary is to find equal rows in some > database > tables. Perhaps using a md5 hash from the column data is also an idea ? unicode takes an optional encoding argument. If you don't specify, it uses ascii. Try using (untested): key = u"|".join(unicode(x, encoding="utf-8") for x in row) > Thanks a lot in advance, > > Hans. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnewsg at gmail.com Mon Jan 26 15:51:36 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 26 Jan 2009 12:51:36 -0800 (PST) Subject: Monitor a FTP site for arrival of new/updated files References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <397de817-d5e2-48bf-88fa-399a67774919@b38g2000prf.googlegroups.com> On 25 Gen, 21:11, Steve Holden wrote: > pyt... at bdurham.com wrote: > > ?Any suggestions on a best practice way to monitor a remote FTP site for > > the arrival of new/updated files? I don't need specific code, just some > > coaching on technique based on your real-world experience including > > suggestions for a utility vs. code based solution. > > > My goal is to maintain a local collection of files synced with a remote > > FTP site and when I download a new/updated file locally, run a script to > > process it. The arrival and format of the files that I need to sync with > > are beyond my control (eliminating a rsync solution) ... all I have is a > > generic FTP connection to a specific FTP address. Note: The remote site > > I'm monitoring may have multiple uploads occuring at the same time. > > > My basic strategy is to poll the remote directory on a regular basis and > > compare the new directory listing to a previous snapshot of the > > directory listing. If a file timestamp or size has changed (or a new > > file has appeared), then track this file as a changed file. Once a file > > has been marked as changed, wait polling cycles for the file > > timestamp and size to remain stable, then download it, and trigger a > > local script to process the file. In addition to detecting new or > > changed files, I would compare remote directory listings to my local > > sync folder and delete local files that no longer exist on the remote site. > > > My concern about using a utility is the utility's ability to detect when > > a remote file has finished being updated. I don't want to download files > > that are still in the process of being updated - I only want to download > > new/updated files after they've been closed on the remote site. > > > Any ideas appreciated! > > Well, the ftpmirror will cope with most of what you want to do as it is, > but I am unsure how you can determine whether a file is in the process > of being written on the server. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/- Nascondi testo citato > > - Mostra testo citato - If you're going to do that manually through a script, and the server supports it, use MLSD instead of LIST command for listing files and determine their last modification time. My 2 cents --- Giampaolo http://code.google.com/p/pyftpdlib From torriem at gmail.com Mon Jan 26 15:53:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 26 Jan 2009 13:53:57 -0700 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> Message-ID: <497E22E5.4000308@gmail.com> jefm wrote: >> Hmm this works for me, >> it's a self compiled version: >> ~ $ python3 >> Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) >> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > > You are running on Linux. Mine is on Windows. > Anyone else have this issue on Windows ? As Benjamin Kaplin said, Windows terminals use the old cp1252 character set, which cannot display the euro sign. You'll either have to run it in something more modern like the cygwin rxvt terminal, or output some other way, such as through a GUI. From tjreedy at udel.edu Mon Jan 26 15:58:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 15:58:41 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. True > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format "\N{name}" allows me to specify by Unicode > name. These are ways to *specify* unicode chars on input. > Neither seem to work for me. If you separate text creation from text printing, you would see that they do. Try s='\u20ac' print(s) > What am I doing wrong ? Using the interactive interpreter running in a Windows console. > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print('\u20ac') > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to With the standard console, I get the same. But with IDLE, using the same Python build but through a different interface >>> s='\u20ac' >>> len(s) 1 >>> str(s) '?' # euro sign I have fiddled with the shortcut to supposed make it work better as claimed by posts found on the web, but to no avail. Very frustrating since I have fonts on the system for at least all of the first 64K chars. Scream at Microsoft or try to find or encourage a console replacement that Python could use. In the meanwhile, use IDLE. Not perfect for Unicode, but better. Terry Jan Reedy From rantingrick at gmail.com Mon Jan 26 16:03:13 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jan 2009 13:03:13 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget References: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> Message-ID: OK, here is a simple example that will show you what i want to do. Right now if you type print 'hello' in the entry and press you will see braces in the label "{}". But if you type sys.stdou.write ("hello") you will see "{hello}" in the label. So i got the stdout piping to the widget now, but it will not work with the print statement. AND there are those braces around the string??? Any ideas? from Tkinter import * root = Tk() class NewOut(): def write(self, *arg): v.set(arg) saveout = sys.stdout newout = NewOut() sys.stdout = newout e = StringVar(root) entry = Entry(root, textvariable=e, font=('Courier New', 12)) entry.pack(fill=X, expand=1, padx=5, pady=5) v = StringVar(root) Label(textvariable=v).pack(fill=X, expand=1) def onReturn(event): try: exec(e.get()) e.set('') except: print 'Command Invalid' root.bind('', onReturn) entry.focus_set() root.mainloop() From steve at holdenweb.com Mon Jan 26 16:10:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 16:10:02 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <497E26AA.3070206@holdenweb.com> Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: > >>> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >>> new and people write >>> try: >>> False,True >>> except NameError: >>> False,True = 0,1 >>> >>> to make code back compatible. >>> >> I would claim that the ability to rebind True and False is a simple bug, >> though one not likely to be fixed in an 2.x release. The code above >> doesn't rebind True and False in interpreters that have them ... > > In pre-bool 2.x, people never wrote the above but sometime wrote > False,True = 0,1 > Right. This is the use case I overlooked. > To me it is hardly a bug to not gratuitously break substantial amounts > of proper code. > I quite agree. I take it all back! >>> Back before rebinding 'None' was prohibited, 'is None' was not >>> completely guaranteed either (absent reading the rest of a file to be >>> sure no rebinding would be done). >>> >> And that was a bug too, in this case one that *was* removed in 2.4, I >> believe. Don't have 2.3 lying around just now. > > Unlike with True and False, the devs could not think of or find any > proper use case for rebinding None and judged that the new prohibition > would break very little if any code. As far as I know, they were correct. > Indeed they were. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 16:10:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 16:10:02 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <497E26AA.3070206@holdenweb.com> Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: > >>> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >>> new and people write >>> try: >>> False,True >>> except NameError: >>> False,True = 0,1 >>> >>> to make code back compatible. >>> >> I would claim that the ability to rebind True and False is a simple bug, >> though one not likely to be fixed in an 2.x release. The code above >> doesn't rebind True and False in interpreters that have them ... > > In pre-bool 2.x, people never wrote the above but sometime wrote > False,True = 0,1 > Right. This is the use case I overlooked. > To me it is hardly a bug to not gratuitously break substantial amounts > of proper code. > I quite agree. I take it all back! >>> Back before rebinding 'None' was prohibited, 'is None' was not >>> completely guaranteed either (absent reading the rest of a file to be >>> sure no rebinding would be done). >>> >> And that was a bug too, in this case one that *was* removed in 2.4, I >> believe. Don't have 2.3 lying around just now. > > Unlike with True and False, the devs could not think of or find any > proper use case for rebinding None and judged that the new prohibition > would break very little if any code. As far as I know, they were correct. > Indeed they were. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Mon Jan 26 16:16:26 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Jan 2009 22:16:26 +0100 Subject: Anoying unicode / str conversion problem References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Hans M?ller wrote: > Hi python experts, > > in the moment I'm struggling with an annoying problem in conjunction with > mysql. > > I'm fetching rows from a database, which the mysql drive returns as a list > of tuples. > > The default coding of the database is utf-8. > > Unfortunately in the database there are rows with different codings and > there is a blob column. > > In the app. I search for double entries in the database with this code. > > hash = {} > cursor.execute("select * from table") > rows = cursor.fetchall() > for row in rows: > key = "|".join([str(x) for x in row]) <- here the problem arises > if key in hash: > print "found double entry" > > This code works as expected with python 2.5.2 > With 2.5.1 it shows this error: > > > key = "|".join(str(x) for x in row) > UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in > position 3: ordinal not in range(128) > > When I replace the str() call by unicode(), I get this error when a blob > column is being processed: > > key = "|".join(unicode(x) for x in row) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: > ordinal not in range(128) > > > Please help, how can I convert ANY column data to a string which is usable > as a key to a dictionary. The purpose of using a dictionary is to find > equal rows in some database tables. Perhaps using a md5 hash from the > column data is also an idea ? > > Thanks a lot in advance, No direct answer, but can't you put the rows into the dict (or a set) without converting them to a string? seen = set() for row in rows: if row in seen: print "dupe" else: seen.add(row) Or, even better, solve the problem within the db: select from group by having count(*) > 1 Peter From jef.mangelschots at gmail.com Mon Jan 26 16:26:56 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 13:26:56 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: >As Benjamin Kaplin said, Windows terminals use the old cp1252 character >set, which cannot display the euro sign. You'll either have to run it in > something more modern like the cygwin rxvt terminal, or output some >other way, such as through a GUI. >With the standard console, I get the same. But with IDLE, using the >same Python build but through a different interface >Scream at Microsoft or try to find or encourage a console >replacement that Python could use. In the meanwhile, use IDLE. Not >perfect for Unicode, but better. So, if I understand it correctly, it should work as long as you run your Python code on something that can actually print the Unicode character. Apparently, the Windows command line can not. I mainly program command line tools to be used by Windows users. So I guess I am screwed. Other than converting my tools to have a graphic interface, is there any other solution, other than give Bill Gates a call and bring his command line up to the 21st century ? From sjmachin at lexicon.net Mon Jan 26 16:37:45 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 13:37:45 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'open_workbook' References: Message-ID: <23bbd810-426f-4c28-bc54-a686e35ac0c1@r36g2000prf.googlegroups.com> On Jan 27, 3:07?am, MRAB wrote: > Jay Jesus Amorin wrote: [snip] > ?> Here's the error message: > ?> > ?> root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls > ?> Traceback (most recent call last): > ?> ? File "./xlrd.py", line 3, in > ?> ? ? import xlrd > ?> ? File "/home/jayam/project/xlrd.py", line 6, in > ?> ? ? mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) I concur with MRAB's diagnosis. To answer the OP's possible next question: the first arg of xlrd.open_workbook() is the path to the file to be opened. It won't work with a string of data. That's what the file_contents arg is for. Manual says: """ filename The path to the spreadsheet file to be opened. [snip] file_contents ... as a string or an mmap.mmap object or some other behave-alike object. If file_contents is supplied, filename will not be used, except (possibly) in messages. """ So the above line of code should be: mySpreadsheet = xlrd.open_workbook(sys.argv[1]) Cheers, John From exarkun at divmod.com Mon Jan 26 16:38:07 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 26 Jan 2009 16:38:07 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: Message-ID: <20090126213807.24460.1896409141.divmod.quotient.2263@henry.divmod.com> On Mon, 26 Jan 2009 13:26:56 -0800 (PST), jefm wrote: >>As Benjamin Kaplin said, Windows terminals use the old cp1252 character >>set, which cannot display the euro sign. You'll either have to run it in >> something more modern like the cygwin rxvt terminal, or output some >>other way, such as through a GUI. > >>With the standard console, I get the same. But with IDLE, using the >>same Python build but through a different interface > >>Scream at Microsoft or try to find or encourage a console >>replacement that Python could use. In the meanwhile, use IDLE. Not >>perfect for Unicode, but better. > > >So, if I understand it correctly, it should work as long as you run >your Python code on something that can actually print the Unicode >character. >Apparently, the Windows command line can not. > >I mainly program command line tools to be used by Windows users. So I >guess I am screwed. > >Other than converting my tools to have a graphic interface, is there >any other solution, other than give Bill Gates a call and bring his >command line up to the 21st century ? cp1252 can represent the euro sign (). Apparently the chcp command can be used to change the code page active in the console (). I've never tried this myself, though. Jean-Paul From jcd at sdf.lonestar.org Mon Jan 26 16:38:08 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 16:38:08 -0500 Subject: I'm a python addict ! In-Reply-To: <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> Message-ID: <1233005888.5990.0.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 12:37 -0800, Paul McGuire wrote: > On Jan 26, 2:06 pm, "J. Cliff Dyer" wrote: > > > > Thanks. That makes sense. But your example creates a new instance of > > the new class each time, rather than changing the class of a persistent > > instance, as the original example, to which I was responding, did. > > > > Look closer. The line that creates a new instance is commented out, > with the notation "how you have to do it in C++ and Java". The actual > Python code is just below, and just assigns a new class to > self.__class__, as in the original example. > Right. Sorry about that. > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From jef.mangelschots at gmail.com Mon Jan 26 16:58:19 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 13:58:19 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: Now that I know the problem, I found the following on Google. Windows uses codepages to display different character sets. (http:// en.wikipedia.org/wiki/Code_page) The Windows chcp command allows you to change the character set from the original 437 set. When you type on the command line: chcp 65001 it sets your console in UTF-8 mode. (http://en.wikipedia.org/wiki/Code_page_65001) Unfortunately, it still doesn't do what I want. Instead of printing the error message above, it prints nothing. From heintest at web.de Mon Jan 26 17:02:24 2009 From: heintest at web.de (=?UTF-8?B?SGFucyBNw7xsbGVy?=) Date: Mon, 26 Jan 2009 23:02:24 +0100 Subject: Anoying unicode / str conversion problem In-Reply-To: References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <497e3301$0$31329$9b4e6d93@newsspool4.arcor-online.net> Thanks Peter, your answer did the trick. I programed a lot with awk (also a very cool scripting language). So I was focused on the concept a dictionary key has to be string (as in awk). Since it's impossible to use a list as a dictionary key I thought it's also impossible to use a tuple as a key. I was wrong! So my code will become more pythonic, much simpler and even faster! Your suggestion to use the database is also an idea, but the actual task is to see if some rows in (identical) tables across many servers are missing and if so to add the missing rows. In my post I showed a simplified code. Again, thanks for the hint! Greetings Hans From jef.mangelschots at gmail.com Mon Jan 26 17:03:20 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 14:03:20 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: Message-ID: chcp 1252 does allow me to print the EURO sign. Thanks for pointing that out. However, it does not show me some ALL Unicode characters. Very frustrating. I was hoping to find something that allows me to print any Unicode character on the console. From gdamjan at gmail.com Mon Jan 26 17:09:28 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 26 Jan 2009 23:09:28 +0100 Subject: USB in python References: <497D4630.6090405@al.com.au> Message-ID: >> Sorry, by USB device, I meant a device that is powered/activated by a >> bunch of wires that I want to control using a computer and since I >> had a spare USB jack lying around, I used that instead. But so far I >> haven't tried it, nor will try it if it wont work properly. Yes, it >> is not a proper USB device, because I didnt build it to specifically >> interface with the USB port; but I had to start somewhere. Also, the >> device requires more power than the standard parallel port can give. >> Anyway, it looks like the easiest solution for my case is a >> microcontroller > > In which case the Arduino may be a good place to start. The recent > duemilanove boards use USB to communicate with the host, and so the > USB port should be available to the microcontroller. We areg etting > some way away from Python now, of course ... I second that. Arduino to microcontrolers, is what Linux was to kernels back in the 90ties (now it's mainstream), or maybe what python is/was to Java. -- ?????? ( http://softver.org.mk/damjan/ ) () ASCII Ribbon Campaign /\ Keep it simple! From bj_666 at gmx.net Mon Jan 26 17:12:43 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 26 Jan 2009 22:12:43 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> <20090126161011.482e66f9@usenot.de> Message-ID: <6u6qqrFdkq3bU3@mid.uni-berlin.de> On Mon, 26 Jan 2009 16:10:11 +0100, Andreas Waldenburger wrote: > On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch > wrote: > >> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: >> >> > content = a.readlines() >> > >> > (Just because we can now write "for line in file" doesn't mean that >> > readlines() is *totally* redundant.) >> >> But ``content = list(a)`` is shorter. :-) >> > But much less clear, wouldn't you say? Okay, so let's make it clearer and even shorter: ``lines = list(a)``. :-) Ciao, Marc 'BlackJack' Rintsch From perfreem at gmail.com Mon Jan 26 17:25:15 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Mon, 26 Jan 2009 14:25:15 -0800 (PST) Subject: scatterhist and resizing figures Message-ID: <9e1ea2ab-b326-4cd7-ae59-4544fdfe2708@o40g2000prn.googlegroups.com> i am using scatterhist to plot some data. i find that when i plot the data and matlab shows it in the figure window, stretching the figure window (with the mouse) to enlarge it actually changes the properties of the figure. for example, making it bigger sometimes reveals more tick marks - like the y limit of the y axis, which i have set but was not shown until i enlarged the window. also, more crucially enlarging can make bars that appear at 0 or not at all to show... when i save the figure window as pdf, depending on which of these is shown, i get different pdfs. here's an example: x=rand(1, 100); y=x+5; scatterhist(x,y); set(gca, 'Box' , 'off' , ... 'LineWidth' , 1); set(gca , 'FontSize' , 12); set(gca, 'FontName' , 'Helvetica'); set(gca, 'TickDir', 'out'); first question: how can i programtically save the figure as pdf in a way that shows maximal info? i don't want to lose tick marks on my axis or bars in my histogram. second: how can i plot with scatterhist but make the scatter plot points filled? with ordinary scatter, i can simply do: scatter(x, y, 'filled') but the 'filled' argument doesn't appear to work for scatterhist. thank you. From geekmail at usenot.de Mon Jan 26 17:38:14 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 23:38:14 +0100 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> <20090126161011.482e66f9@usenot.de> <6u6qqrFdkq3bU3@mid.uni-berlin.de> Message-ID: <20090126233814.3075df67@usenot.de> On 26 Jan 2009 22:12:43 GMT Marc 'BlackJack' Rintsch wrote: > On Mon, 26 Jan 2009 16:10:11 +0100, Andreas Waldenburger wrote: > > > On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch > > wrote: > > > >> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > >> > >> > content = a.readlines() > >> > > >> > (Just because we can now write "for line in file" doesn't mean > >> > that readlines() is *totally* redundant.) > >> > >> But ``content = list(a)`` is shorter. :-) > >> > > But much less clear, wouldn't you say? > > Okay, so let's make it clearer and even shorter: ``lines = > list(a)``. :-) > OK, you win. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From sjmachin at lexicon.net Mon Jan 26 17:38:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 14:38:50 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: Message-ID: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> On Jan 27, 8:38?am, Jean-Paul Calderone wrote: > On Mon, 26 Jan 2009 13:26:56 -0800 (PST), jefm wrote: > >>As Benjamin Kaplin said, Windows terminals use the old cp1252 character > >>set, which cannot display the euro sign. You'll either have to run it in > >> something more modern like the cygwin rxvt terminal, or output some > >>other way, such as through a GUI. > > >>With the standard console, I get the same. ?But with IDLE, using the > >>same Python build but through a different interface > > >>Scream at Microsoft or try to find or encourage a console > >>replacement that Python could use. ?In the meanwhile, use IDLE. ?Not > >>perfect for Unicode, but better. > > >So, if I understand it correctly, it should work as long as you run > >your Python code on something that can actually print the Unicode > >character. > >Apparently, the Windows command line can not. > > >I mainly program command line tools to be used by Windows users. So I > >guess I am screwed. > > >Other than converting my tools to have a graphic interface, is there > >any other solution, other than give Bill Gates a call and bring his > >command line up to the 21st century ? > > cp1252 can represent the euro sign (). ?Apparently the chcp command can be used to change the code page > active in the console (). ?I've never tried this myself, though. > Short answer: it doesn't work. Test [Windows XP SP3, Python 2.6.1]: C:\junk>chcp Active code page: 850 C:\junk>chcp 1252 Active code page: 1252 C:\junk>chcp Active code page: 1252 C:\junk>\python26\python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys; sys.stdout.encoding; sys.stderr.encoding 'cp1252' 'cp1252' # So far, so good >>> import unicodedata as ucd >>> for b in range(128, 256): ... c = chr(b) ... u = c.decode('cp1252', 'replace') ... name = ucd.name(u) ... print hex(b), c, repr(u), name ... 0x80 ? u'\u20ac' EURO SIGN 0x81 ? u'\ufffd' REPLACEMENT CHARACTER 0x82 ? u'\u201a' SINGLE LOW-9 QUOTATION MARK [snip] 0xfb ? u'\xfb' LATIN SMALL LETTER U WITH CIRCUMFLEX 0xfc ? u'\xfc' LATIN SMALL LETTER U WITH DIAERESIS 0xfd ? u'\xfd' LATIN SMALL LETTER Y WITH ACUTE [snip] Ignore what you are seeing in the second field of each above line; it could well look OK. However what I see on the console is: capital C with cedilla small u with diaeresis (umlaut) small e with acute superscript one superscript three superscript two [yes, out of order] IOW, the bridge might think it's in cp1252 mode, but nobody told the engine room, which is still churning out cp850. From martin at v.loewis.de Mon Jan 26 17:42:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 23:42:55 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: Message-ID: <497E3C6F.1010909@v.loewis.de> > I was hoping to find something that allows me to print any Unicode > character on the console. You will have to debug the Python interpreter to find out what's going wrong in code page 65001. Nobody has ever resolved that mystery, although it's been known for some time. If you merely want to see *something* (and not actually the glyph for the character (*)): py> print(ascii('\u20ac')) '\u20ac' should work fine. Regards, Martin (*) Windows doesn't support displaying *all* unicode characters even in code page 65001, nor is it reasonable to expect it to. It can, at best, only display those characters it has glyphs for in the font that it is using. As Unicode constantly evolves, the fonts necessarily get behind. Plus, in a fixed-size font, some characters just don't render too well. From james at agentultra.com Mon Jan 26 17:43:06 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 26 Jan 2009 14:43:06 -0800 Subject: I'm a python addict ! References: Message-ID: <87pri9y9hh.fsf@agentultra.com> Linuxguy123 writes: > I just started using python last week and I'm addicted. > > I hate Perl. I never did learn to use it with any competence. I has to > be the most obfuscated, cryptic language I've ever seen. Making it > "object oriented" only makes it worse ! > .. .. I program full-time in Python, so I share your excitement and enthusiasm. But bashing Perl like that doesn't make you sound very smart. I'm probably one of the very few Python programmers who came from (and still occassionally) use Perl. I've written non-trivial programs in it and from my experience I can tell you that it's actually a great language. The Moose object system is well beyond Python's class system. But I guess you wouldn't know that. So yay for Python, but don't get in the habit of criticising that which you do not know. From james at agentultra.com Mon Jan 26 17:52:37 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 26 Jan 2009 14:52:37 -0800 Subject: I'm a python addict ! References: <87pri9y9hh.fsf@agentultra.com> Message-ID: <87iqo1y91m.fsf@agentultra.com> J Kenneth King writes: > Linuxguy123 writes: > >> I just started using python last week and I'm addicted. >> >> I hate Perl. I never did learn to use it with any competence. I has to >> be the most obfuscated, cryptic language I've ever seen. Making it >> "object oriented" only makes it worse ! >> .. .. > > I program full-time in Python, so I share your excitement and > enthusiasm. But bashing Perl like that doesn't make you sound very > smart. I'm probably one of the very few Python programmers who came from > (and still occassionally) use Perl. I've written non-trivial programs in > it and from my experience I can tell you that it's actually a great > language. The Moose object system is well beyond Python's class > system. But I guess you wouldn't know that. > > So yay for Python, but don't get in the habit of criticising that which > you do not know. I just realized this might become flame-bait. Please disregard the flamey bits. :( From martin at v.loewis.de Mon Jan 26 18:00:52 2009 From: martin at v.loewis.de (=?windows-1252?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 00:00:52 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> References: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> Message-ID: <497e40a5$0$25202$9b622d9e@news.freenet.de> > IOW, the bridge might think it's in cp1252 mode, but nobody told the > engine room, which is still churning out cp850. I think you must use a different font in the console, too, such as Lucida Sans Unicode. Regards, Martin From sjmachin at lexicon.net Mon Jan 26 18:39:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 15:39:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> <497e40a5$0$25202$9b622d9e@news.freenet.de> Message-ID: On Jan 27, 10:00?am, "Martin v. L?wis" wrote: > > IOW, the bridge might think it's in cp1252 mode, but nobody told the > > engine room, which is still churning out cp850. > > I think you must use a different font in the console, too, such as > Lucida Sans Unicode. True. I was just about to post that I'd stumbled across that! From python at bdurham.com Mon Jan 26 18:42:29 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jan 2009 18:42:29 -0500 Subject: Iterating through a file significantly slower when file has big buffer Message-ID: <1233013349.25395.1296882205@webmail.messagingengine.com> I'm working with very large text files and am always looking for ways to optimize the performance of our scripts. While reviewing our code, I wondered if changing the size of our file buffers to a very large buffer size might speed up our file I/O. Intuitively, I thought that bigger buffers might improve performance by reducing the number of reads. Instead I observed just the opposite - performance was 7x slower! (~500 sec vs. 70 sec) and used 3x the memory (24M vs. 8M) due to the larger buffer. The following tests were run on a Windows XP system using Python 2.6.1 SOURCE: import time # timer class class timer( object ): def __init__( self, message='' ): self.message = message def start( self ): self.starttime = time.time() print 'Start: %s' % ( self.message ) def stop( self ): print 'Finish: %s %6.2f' % ( self.message, time.time() - self.starttime ) # myFileName points to a 2G text file. myFileName = r'C:\logs\jan2009.dat' # default buffering myFile = open( myFileName ) for line in myFile: pass myFile.close() strategy1.stop() # setting the buffer size to 16M bufferSize = 2 ** 24 strategy2 = timer( 'Large buffer (%sk)' % (bufferSize/1024) ) strategy2.start() myFile = open( myFileName, 'rt', bufferSize ) for line in myFile: pass myFile.close() strategy2.stop() OUTPUT: Start: Default buffer Finish: Default buffer 69.98 Start: Large buffer (16384k) Finish: Large buffer (16384k) 493.88 <--- 7x slower Any comments regarding this massive slowdown? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ekh.johan at gmail.com Mon Jan 26 18:44:18 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 00:44:18 +0100 Subject: optparse with numpy.array? Message-ID: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Hi all, I'm trying to use optparse to process command line parameters given to my program. It works as I expect for the types supported by optparse, i.e. int, float, string etc. but how can I pass a numpy.array or a list to my program? I have been searching for it but cannot find a good solution. By the way, I am a Python newbie so please be gentle... Best regards, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Jan 26 18:48:01 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jan 2009 18:48:01 -0500 Subject: CORRECTION: Re: Iterating through a file significantly slower when file has big buffer In-Reply-To: <1233013349.25395.1296882205@webmail.messagingengine.com> References: <1233013349.25395.1296882205@webmail.messagingengine.com> Message-ID: <1233013681.26390.1296884287@webmail.messagingengine.com> Added the following lines missing from my original post: strategy1 = timer( 'Default buffer' ) strategy1.start() Code below is now complete. Malcolm SOURCE: import time # timer class class timer( object ): def __init__( self, message='' ): self.message = message def start( self ): self.starttime = time.time() print 'Start: %s' % ( self.message ) def stop( self ): print 'Finish: %s %6.2f' % ( self.message, time.time() - self.starttime ) # myFileName points to a 2G text file. myFileName = r'C:\logs\jan2009.dat' # default buffering strategy1 = timer( 'Default buffer' ) strategy1.start() myFile = open( myFileName ) for line in myFile: pass myFile.close() strategy1.stop() # setting the buffer size to 16M bufferSize = 2 ** 24 strategy2 = timer( 'Large buffer (%sk)' % (bufferSize/1024) ) strategy2.start() myFile = open( myFileName, 'rt', bufferSize ) for line in myFile: pass myFile.close() strategy2.stop() OUTPUT: Start: Default buffer Finish: Default buffer 69.98 Start: Large buffer (16384k) Finish: Large buffer (16384k) 493.88 <--- 7x slower Any comments regarding this massive slowdown? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Mon Jan 26 18:53:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 15:53:02 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> Message-ID: <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> On Jan 27, 9:42?am, "Martin v. L?wis" wrote: > > I was hoping to find something that allows me to print any Unicode > > character on the console. > > You will have to debug the Python interpreter to find out what's > going wrong in code page 65001. Nobody has ever resolved that mystery, > although it's been known for some time. Maybe the problem is not in the Python interpreter. Running this tiny C program #include "stdio.h" int main(int argc, char **argv) { printf("<\xc2\x80>\n"); } compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) and using "Lucida Console" font: After CHCP 1252, this prints < A-circumflex Euro >, as expected. After CHCP 65001, it prints < hollow-square >. Perhaps you could try that with an MS C compiler [which I don't have] ... From robert.kern at gmail.com Mon Jan 26 19:00:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 18:00:16 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Message-ID: On 2009-01-26 17:44, Johan Ekh wrote: > Hi all, > I'm trying to use optparse to process command line parameters given to > my program. > It works as I expect for the types supported by optparse, i.e. int, > float, string etc. but how can I > pass a numpy.array or a list to my program? http://docs.python.org/library/optparse#optparse-extending-optparse Figure out the text format you want your users to type the value on the command line, write a function that will take that text and convert it to an array or list, then customize OptionParser to use that parser as given in the link above. Keep in mind that your user probably won't want to need to use whitespace or any kind of brackets. Commas are nice, though. You may also want to consider taking a filename and parsing that file instead. -- 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 mdw at distorted.org.uk Mon Jan 26 19:14:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 00:14:17 +0000 Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > Mark Wooding wrote: >> * Assignment stores a new (reference to a) value in the variable. >> >> * Binding modifies the mapping between names and variables. >> > I realise I have omitted what was doubtless intended to be explanatory > detail, but I am having trouble reconciling those sentences. Would you > mind explaining "in vacuuo" what you see as the difference between > assignment and binding? OK. This turned into something of an essay. I hope that it's of use to somebody... A name is a kind of expression. Expressions can be evaluated to yield values. Therefore, a name can be evaluated to yield a value. How does this happen? There are two distinct mappings involved. The first mapping is from names to variables. This mapping is usually called the `environment', and is acted upon by `binding'. The extent of the program text whose meaning is affected by a binding is called the `scope' of the binding[1]. In Python, the scope can be determined statically by analysing the program text (`lexical scope'). In some languages the scope can only be determined at run time (`dynamic scope'); other languages have a mixture of the two. Binding in Python is done in two ways: * /Explicit/ binding is done by `def' or `lambda': the parameters are bound, and the scope of the bindings is the entire function body (i.e., it does not include the default arguments). * /Implicit/ binding may be performed when a name as a result of an assignment operation -- either an assignment statement or one of a number of features which work by assignment, including `for' loops, list comprehensions, and `def' blocks. The scope of the binding in this case depends on the nature of the block in which the binding occurs: within `def' and `lambda'[2], the scope is the entire function body; within `class' and module toplevels, the scope is from the first-executed assignment to the end of the block. In all cases, names are bound to fresh variables when the scope of the binding begins. The environment within a binding block is formed by extending the environment of the surrounding program text. In the case of function definitions, in particular, we say that the function `closes over' the environment in which it is defined. The second mapping is from variables to values. This mapping doesn't seem to have a common name, though it's referred to as the `store' in some formal semantics (e.g., R5RS Scheme). The store is acted upon by assignment (and assignment-like operations such as `for' loops and list comprehensions). An assignment NAME = VALUE alters the store as follows: the variable bound to NAME becomes mapped to the result of evaluating VALUE. We can now consider some example programs. In [23]: def simple(x): ....: def inner(): ....: return x ....: return inner ....: When the function is invoked, say by In [24]: simple('boo!')() the name x is bound to a new variable, and the variable is assigned the value `boo!'. The body of `simple' is then executed. First, a function `inner' is defined: `def' is an assignment-like operation, which causes `inner' to be implicitly bound to a fresh variable on entry to the function. When the `def' is executed, that variable is assigned the value of a function. Finally, we return the result of evaluating `inner', i.e., the function we just constructed. The next pair of parentheses invoke the function `inner'. That function was defined within an environment in which x was bound to a variable that had been assigned the value 'boo!'. It therefore returns this value: Out[24]: 'boo!' Next example: In [26]: def mutant(x): ....: def inner(): ....: return x ....: x = 'changed!' ....: return inner ....: Suppose we invoke this one as In [27]: mutant('same')() The first steps are the same: x is bound to a fresh variable which is assigned the value 'same'; `inner' is bound to a fresh variable which is assigned a function value. Now the line `x = 'changed!'' is executed. This assigns the string 'changed!' to the variable bound to x. Finally, we return the function value. That function is now invoked. It was defined in an environment where x was bound to a variable whose last assigned value was 'changed!'. Therefore: Out[27]: 'changed!' The original poster's question can be illustrated by this example: In [28]: def problem(): ....: return [lambda: i for i in xrange(3)] ....: In [29]: [f() for f in problem()] This is actually the same as the mutant example in disguise. There is no parameter to bind, but `for' in a list comprehension is an assignment operation, and therefore i is implicitly bound when `problem' is invoked. The list comprehension performs three iterations. On each iteration, the `lambda' is evaluated. It produces a different function value each time: In [30]: problem() Out[30]: [ at 0x9a731ec>, at 0x9a73064>, at 0x9a730d4>] And each time through, the variable bound to i is assigned a different value: first 0, then 1, and finally 2. The resulting functions are gathered into a list, which is returned as the value of `problem()'. However, it was textually the same `lambda', and so they closed over the /same/ environment -- that of the body of `problem' -- in which i is bound to the same variable. That variable was last assigned the value 2. Therefore, when we invoke any of the functions, we get the same result: Out[29]: [2, 2, 2] Two fixes were suggested. I suggested this one: In [31]: def bind_fix(): ....: def hack(i): return lambda: i ....: return [hack(i) for i in xrange(3)] ....: In [32]: [f() for f in bind_fix()] Out[32]: [0, 1, 2] How does this work? Each iteration invokes the `hack' function. Invocation binds i to a new variable, and assigns it the value of the argument (which is 0, 1, or 2 according to which iteration we're on). The `lambda' which `hack' returns closes over /this/ environment, and the variable bound to i in `hack''s environment is not assigned again, so the problem doesn't occur. The function `hack' is basically a one-line version of the `simple' example above. While `hack' closes over the environment of `bind_fix', this isn't important: `hack''s binding of i `shadows' the outer binding of `bind_fix'. It's where it is to avoid cluttering up the toplevel namespace. The other fix uses default arguments, and it was suggested by Steven D'Aprano and Brian Vanderburg. In [33]: def defarg_fix(): ....: return [lambda i = i: i for i in xrange(3)] ....: In [34]: [f() for f in defarg_fix()] Out[34]: [0, 1, 2] This is conceptually rather simpler; I didn't suggest it because it doesn't teach the concepts I was exploring as well. The important point about default arguments in Python is that they're evaluated at the same time as the function is being defined, rather than on every call[3]. There are three functions defined, one for each iteration of the list comprehension; since i is assigned a different value on each iteration, and the default argument is evaluated on each definition, each function acquires a distinct defalt argument for its parameter i. Chapter 3 of the Structure and Interpretation of Computer Programs, by Abelson and Sussman explains this stuff in a more discursive and approachable manner. If you're still confused by my explanation (and by nature I tend to err on the side of precision rather than clarity, a fault which I know impairs my teaching ability), you may find theirs more useful: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-19.html#%_chap_3 Nonetheless, I hope that this description has been of some use. [1] Under lexical binding, a particular binding always affects the same region of program text. That doesn't mean that the same binding is used every time that text is executed! [2] Yes, `lambda' acts as a binding block. I leave construction of a program exhibiting this behaviour as an exercise. [3] This is unlike default arguments in, for example, Common Lisp. Both behaviours are useful. Python's behaviour was especially valuable before the language provided true closures. -- [mdw] From vincent at vincentdavis.net Mon Jan 26 19:18:39 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 17:18:39 -0700 Subject: print formating for matrix/table Message-ID: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> I have a list of lists....a matrix in that all sub lists are the same length. I there a nice why to prin these so that the columns and rows line up nicely? I have looked around for a good way to do this and haven't found one I am like. It seems that all involve repeating a print for each line. I would have thought I could find a prebuilt function to do this. Surly lots of people are printing matrixes and would like nice formating. So what am I missing? Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Jan 26 19:23:23 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 18:23:23 -0600 Subject: print formating for matrix/table In-Reply-To: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: On 2009-01-26 18:18, Vincent Davis wrote: > I have a list of lists....a matrix in that all sub lists are the same > length. I there a nice why to prin these so that the columns and rows > line up nicely? > I have looked around for a good way to do this and haven't found one I > am like. It seems that all involve repeating a print for each line. I > would have thought I could find a prebuilt function to do this. Surly > lots of people are printing matrixes and would like nice formating. So > what am I missing? Most people using matrices are also using numpy, and numpy arrays do print with columns lined up. -- 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 benjamin.kaplan at case.edu Mon Jan 26 19:57:11 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 19:57:11 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <497E3C6F.1010909@v.loewis.de> References: <497E3C6F.1010909@v.loewis.de> Message-ID: On Mon, Jan 26, 2009 at 5:42 PM, "Martin v. L?wis" wrote: > > I was hoping to find something that allows me to print any Unicode > > character on the console. > > You will have to debug the Python interpreter to find out what's > going wrong in code page 65001. Nobody has ever resolved that mystery, > although it's been known for some time. Well, the first step would be to tell Python that there is a code page 65001. On Python 2.6, I get a LookupError for an unknown encoding after doing "chcp 65001". I checked the list of aliases in Python 3 and there was no entry for cp65001. Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print u'hello' Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: cp65001 > > If you merely want to see *something* (and not actually the glyph > for the character (*)): > > py> print(ascii('\u20ac')) > '\u20ac' > > should work fine. > > Regards, > Martin > > (*) Windows doesn't support displaying *all* unicode characters even > in code page 65001, nor is it reasonable to expect it to. It can, at > best, only display those characters it has glyphs for in the font > that it is using. As Unicode constantly evolves, the fonts necessarily > get behind. Plus, in a fixed-size font, some characters just don't > render too well. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Pat at junk.net Mon Jan 26 20:02:59 2009 From: Pat at junk.net (Pat) Date: Mon, 26 Jan 2009 20:02:59 -0500 Subject: optparse question Message-ID: Up until today, I never needed to pass any arguments to a Python program. I did all the requisite reading and found that I should use optparse instead of getopt. I read the documentation and since the words "simple" and "easy" often appeared in the examples and documentation, I just knew that it would be a snap to implement. Problem is that all I wanted to do was pass a one flag to the program "-d", for to enable debug mode. Several hours later I gave up after optparse complained about every variation I tried. What does it take to pass single parameter to a program? http://docs.python.org/library/optparse.html stated that programs always have options. Is that so? What about "dir /s"? getopt resolved my immediate need, but I would like to know how one could use optparse to extract out the options from something like "dir /s /b". From prologic at shortcircuit.net.au Mon Jan 26 20:16:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 11:16:25 +1000 Subject: optparse question In-Reply-To: References: Message-ID: On Tue, Jan 27, 2009 at 11:02 AM, Pat wrote: (...) > What does it take to pass single parameter to a program? > http://docs.python.org/library/optparse.html stated that programs always > have options. Is that so? What about "dir /s"? Sample code: ---------------------------------------- #!/usr/bin/env python """optexample Example of using optparse """ import os import sys import os.path import optparse __version__ = "0.1" USAGE = "%prog [options] " VERSION = "%prog v" + __version__ def parse_options(): """parse_options() -> opts, args Parse and command-line options given returning both the parsed options and arguments. """ parser = optparse.OptionParser(usage=USAGE, version=VERSION) parser.add_option("-v", "--verbose", action="store_true", default=False, dest="verbose", help="Verbose output during operation.") opts, args = parser.parse_args() if len(args) < 1: parser.print_help() raise SystemExit, 1 return opts, args def main(): opts, args = parse_options() if opts.verbose: print args[0] if __name__ == "__main__": main() ---------------------------------------- cheers James From robert.kern at gmail.com Mon Jan 26 20:18:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 19:18:46 -0600 Subject: optparse question In-Reply-To: References: Message-ID: On 2009-01-26 19:02, Pat wrote: > Up until today, I never needed to pass any arguments to a Python program. > > I did all the requisite reading and found that I should use optparse > instead of getopt. I read the documentation and since the words "simple" > and "easy" often appeared in the examples and documentation, I just knew > that it would be a snap to implement. > > Problem is that all I wanted to do was pass a one flag to the program > "-d", for to enable debug mode. Several hours later I gave up after > optparse complained about every variation I tried. parser = optparse.OptionParser() parser.add_option('-d', '--debug', action='store_true') options, args = parser.parse_args() if options.debug: # Do debugging stuff. else: # Do non-debugging stuff. > What does it take to pass single parameter to a program? > http://docs.python.org/library/optparse.html stated that programs always > have options. Is that so? What about "dir /s"? Can you quote exactly the part that you are talking about? I don't see any such claim. -- 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 steve at holdenweb.com Mon Jan 26 20:39:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 20:39:49 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steve Holden writes: > >> Mark Wooding wrote: >>> * Assignment stores a new (reference to a) value in the variable. >>> >>> * Binding modifies the mapping between names and variables. >>> >> I realise I have omitted what was doubtless intended to be explanatory >> detail, but I am having trouble reconciling those sentences. Would you >> mind explaining "in vacuuo" what you see as the difference between >> assignment and binding? > > OK. This turned into something of an essay. I hope that it's of use to > somebody... > > A name is a kind of expression. Expressions can be evaluated to yield > values. Therefore, a name can be evaluated to yield a value. How does > this happen? There are two distinct mappings involved. > > The first mapping is from names to variables. This mapping is usually > called the `environment', and is acted upon by `binding'. The extent of > the program text whose meaning is affected by a binding is called the > `scope' of the binding[1]. In Python, the scope can be determined > statically by analysing the program text (`lexical scope'). In some > languages the scope can only be determined at run time (`dynamic > scope'); other languages have a mixture of the two. > Yes. Kay Schleur pointed out that my confusion was due to too close a mental proximity to the Python term "binding value to names" for assignment. Once I realised you were using "binding"to refer to the scope of names it all made much more sense. [...] > > Chapter 3 of the Structure and Interpretation of Computer Programs, by > Abelson and Sussman explains this stuff in a more discursive and > approachable manner. If you're still confused by my explanation (and by > nature I tend to err on the side of precision rather than clarity, a > fault which I know impairs my teaching ability), you may find theirs > more useful: > > http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-19.html#%_chap_3 > > Nonetheless, I hope that this description has been of some use. > I found your precision most helpful, and the entire post was readable and useful. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent at vincentdavis.net Mon Jan 26 20:53:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 18:53:47 -0700 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> I do have numpy but am using lists as did not need any functions of array. Well maybe print now. I am new to python and don't really know the details about the difference between lists and arrays. I do know that there are different/additional functions available for arrays.Anyway is this the best solution, convert the list to an array before printing? Thanks Vincent Davis On Mon, Jan 26, 2009 at 5:23 PM, Robert Kern wrote: > On 2009-01-26 18:18, Vincent Davis wrote: > >> I have a list of lists....a matrix in that all sub lists are the same >> length. I there a nice why to prin these so that the columns and rows >> line up nicely? >> I have looked around for a good way to do this and haven't found one I >> am like. It seems that all involve repeating a print for each line. I >> would have thought I could find a prebuilt function to do this. Surly >> lots of people are printing matrixes and would like nice formating. So >> what am I missing? >> > > Most people using matrices are also using numpy, and numpy arrays do print > with columns lined up. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Jan 26 20:55:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 20:55:47 -0500 Subject: print formating for matrix/table In-Reply-To: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: Vincent Davis wrote: > I have a list of lists....a matrix in that all sub lists are the > same length. I there a nice why to prin these so that the columns and > rows line up nicely? > I have looked around for a good way to do this and haven't found one I > am like. It seems that all involve repeating a print for each line. I > would have thought I could find a prebuilt function to do this. Surly > lots of people are printing matrixes and would like nice formating. So > what am I missing? > Look at the pprint module: >>> arr = [range(10)] * 10 >>> from pprint import pprint >>> pprint(arr) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From robert.kern at gmail.com Mon Jan 26 20:58:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 19:58:29 -0600 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: On 2009-01-26 19:55, Steve Holden wrote: > Vincent Davis wrote: >> I have a list of lists....a matrix in that all sub lists are the >> same length. I there a nice why to prin these so that the columns and >> rows line up nicely? >> I have looked around for a good way to do this and haven't found one I >> am like. It seems that all involve repeating a print for each line. I >> would have thought I could find a prebuilt function to do this. Surly >> lots of people are printing matrixes and would like nice formating. So >> what am I missing? >> > Look at the pprint module: > >>>> arr = [range(10)] * 10 >>>> from pprint import pprint >>>> pprint(arr) > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] But this doesn't line up the columns, except by accident: [[1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000]] -- 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 astan.chee at al.com.au Mon Jan 26 20:58:30 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 27 Jan 2009 12:58:30 +1100 Subject: USB in python In-Reply-To: <497DCEC5.3060208@aim.com> References: <497D4630.6090405@al.com.au> <497DCEC5.3060208@aim.com> Message-ID: <497E6A46.1020708@al.com.au> Brian Allen Vanderburg II wrote: > This is the FT245 chip which is basically USB-to-Parallel. > > Chips: http://www.ftdichip.com/Products/FT245R.htm > Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm > > The spec sheet for the board seems quite simple. It's pin out is > similar to that of a parallel port in that you have your data lines > DB0-DB7, etc. It can also be connected in bus-powered configuration > (~100mA) or self-powered configuration. The kit is more expensive than > the chip itself, but probably easier especially if you don't have any > experience with surface mount. > > That is a good idea. The main factor (aside from complexity) that I forgot to mention is the cost. I live very far away from the US and sometimes it is cheaper to buy a microcontroller here than have bits n pieces shipped from the US. Anyway, I'll see if I can find these parts here and maybe use that. Thanks for all the ideas! Cheers Astan From robert.kern at gmail.com Mon Jan 26 21:03:30 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 20:03:30 -0600 Subject: print formating for matrix/table In-Reply-To: <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> Message-ID: On 2009-01-26 19:53, Vincent Davis wrote: > I do have numpy but am using lists as did not need any functions of > array. Well maybe print now. I am new to python and don't really know > the details about the difference between lists and arrays. I do know > that there are different/additional functions available for arrays. Python lists are one-dimensional, appendable sequences of heterogeneous Python objects. numpy arrays are multi-dimensional, non-appendable containers usually of homogeneously-typed numerical data (but can also contain heterogeneous Python objects, too). numpy arrays have many conveniences over lists of lists if you need to do math on bunches of numbers. > Anyway is this the best solution, convert the list to an array before > printing? I wouldn't use numpy *just* for this, but I suspect that you could actually use numpy for other things if you are actually using your lists of lists as matrices. -- 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 mccredie at gmail.com Mon Jan 26 21:13:11 2009 From: mccredie at gmail.com (Matimus) Date: Mon, 26 Jan 2009 18:13:11 -0800 (PST) Subject: optparse question References: Message-ID: <38d8bade-2603-4740-b667-b472c5e3225e@r41g2000prr.googlegroups.com> > I did all the requisite reading and found that I should use optparse > instead of getopt. ? I read the documentation and since the words > "simple" and "easy" often appeared in the examples and documentation, I > just knew that it would be a snap to implement. I don't know where you got that. 'getopt' works just fine. 'optparse' works fine too. I don't think anybody is going to get too worked up over which you decide to use for such a simple case. Matt From sjmachin at lexicon.net Mon Jan 26 21:44:52 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 18:44:52 -0800 (PST) Subject: optparse question References: Message-ID: <796ebbdf-b1ee-498e-a53e-766d97f21588@r15g2000prd.googlegroups.com> On Jan 27, 12:02?pm, Pat wrote: > Up until today, I never needed to pass any arguments to a Python program. > > I did all the requisite reading and found that I should use optparse > instead of getopt. ? I read the documentation and since the words > "simple" and "easy" often appeared in the examples and documentation, I > just knew that it would be a snap to implement. > > Problem is that all I wanted to do was pass a one flag to the program > "-d", for to enable debug mode. ?Several hours later I gave up after > optparse complained about every variation I tried. > > What does it take to pass single parameter to a program? I'm assuming that question 2 starts here. To help answer question 1 without just writing the code for you, it might help if you (a) showed what you regard as your best effort (b) explained what part of http://docs.python.org/library/optparse.html#handling-boolean-flag-options you had trouble with. > http://docs.python.org/library/optparse.htmlstated that programs always > have options. Does it? > ?Is that so? ?What about "dir /s"? That has one option, /s. And this must be question 3: > > getopt resolved my immediate need, but I would like to know how one > could use optparse to extract out the options from something like "dir > /s /b". If you mean with "/" as the option designator instead of "-": there doesn't appear to be a documented way of doing it. You would have to do some social engineering on the users to get them used to doing "dir -s -b". In any case I thought the number of Windows users who know how to fire up a Command Prompt window was diminishingly small ... you actually have users who know how to use commands like "dir /s /b"? Cheers, John From vincent at vincentdavis.net Mon Jan 26 21:53:39 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 19:53:39 -0700 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> Message-ID: <77e831100901261853o50e1c25aic7b76434d1b2d10d@mail.gmail.com> I called it a matrix mostly because this is how I am visualizing it. They are full of numbers but only as representatives of students and schools. It looks like pprint will work after I read the instructions. At least I know where to look now. In the end I need to figure out how to save the data a csv formated for excel but that is for later I was just trying to make it easier to debug my code. Thanks Vincent Davis 720-301-3003 On Mon, Jan 26, 2009 at 7:03 PM, Robert Kern wrote: > On 2009-01-26 19:53, Vincent Davis wrote: > >> I do have numpy but am using lists as did not need any functions of >> array. Well maybe print now. I am new to python and don't really know >> the details about the difference between lists and arrays. I do know >> that there are different/additional functions available for arrays. >> > > Python lists are one-dimensional, appendable sequences of heterogeneous > Python objects. numpy arrays are multi-dimensional, non-appendable > containers usually of homogeneously-typed numerical data (but can also > contain heterogeneous Python objects, too). numpy arrays have many > conveniences over lists of lists if you need to do math on bunches of > numbers. > > Anyway is this the best solution, convert the list to an array before >> printing? >> > > I wouldn't use numpy *just* for this, but I suspect that you could actually > use numpy for other things if you are actually using your lists of lists as > matrices. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at anjanesh.net Mon Jan 26 22:16:38 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 27 Jan 2009 08:46:38 +0530 Subject: Method returning an Iterable Object In-Reply-To: <20090126202804.28c65e90@usenot.de> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> Message-ID: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> But how come a raise StopIteration in the next() method doesnt need to be caught ? It works without breaking. class twoTimes: max = 10**10 def __init__(self, n): self.__n = n def next(self): if self.__n > self.max: raise StopIteration self.__n *= 2 return self.__n def __iter__(self): return self t = twoTimes(5) c = 0 print (t.next()) print (t.next()) for n in t: print n Anjanesh From castironpi at gmail.com Mon Jan 26 22:20:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 19:20:50 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Hi, Mark, Do you mind if I approach you off the group about this? Aaron On Jan 25, 9:47?pm, Mark Wooding wrote: > Aaron Brady writes: > > I am writing an extension using shared memory. ?I need a data type > > that is able to reassign its 'ob_type' field depending on what process > > is calling it. > > That sounds scary! snip From prologic at shortcircuit.net.au Mon Jan 26 22:33:22 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 13:33:22 +1000 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 1:16 PM, Anjanesh Lekshminarayanan wrote: > But how come a raise StopIteration in the next() method doesnt need to > be caught ? It works without breaking. Because this exception is specially dealt with when iterating over an iterator. The "raise StopIteration" is what causes the iteration to stop. Consider: >>> x = EveryOther(xrange(10)) >>> x.next() 0 >>> x.next() 2 >>> x.next() 4 >>> x.next() 6 >>> x.next() 8 >>> x.next() Traceback (most recent call last): File "", line 1, in File "foo.py", line 12, in next raise StopIteration StopIteration >>> x = EveryOther(xrange(10)) >>> list(x) [0, 2, 4, 6, 8] >>> cheers James From alwaseem307ster at yahoo.com Mon Jan 26 22:48:05 2009 From: alwaseem307ster at yahoo.com (klia) Date: Mon, 26 Jan 2009 19:48:05 -0800 (PST) Subject: shutil module (directory input) Message-ID: <21679178.post@talk.nabble.com> hello folks i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code.becuase now i have to specify the sourcefile and the destinationfile in codes and not left to be specified from the terminal. i want to be able to do this. python shutil_copy.py sourcefile, destinationfile code import shutil shutil.copyfile(srcfile, dstfile) # copy data only -- View this message in context: http://www.nabble.com/shutil-module-%28directory-input%29-tp21679178p21679178.html Sent from the Python - python-list mailing list archive at Nabble.com. From tjreedy at udel.edu Mon Jan 26 22:51:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 22:51:13 -0500 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > But how come a raise StopIteration in the next() method doesnt need to > be caught ? It works without breaking. The for-loop looks for and catches StopIteration. It is an essential part of what defines a finite iterator. (Note, in 3.0, next is renamed __next__ in conformance with all other special methods. In 2.6, the rename is optional, I believe.) > class twoTimes: > max = 10**10 > > def __init__(self, n): > self.__n = n There is no reason to mangle the attribute name. Max should be a parameter, and self.max = max added to the init. > > def next(self): > if self.__n > self.max: > raise StopIteration > self.__n *= 2 > return self.__n Are you sure you do not want to return once the initial value of n passed to init? > > def __iter__(self): > return self Once you understand the above, you can rewrite it as a generator function: def two_times(num, stop): while num < stop: yield num num *=2 The two last lines can be switches if desired. > t = twoTimes(5) > c = 0 > > print (t.next()) > print (t.next()) > > for n in t: > print n >>> print(list(two_times(5,687))) [5, 10, 20, 40, 80, 160, 320, 640] Terry Jan Reedy From prologic at shortcircuit.net.au Mon Jan 26 22:57:44 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 13:57:44 +1000 Subject: shutil module (directory input) In-Reply-To: <21679178.post@talk.nabble.com> References: <21679178.post@talk.nabble.com> Message-ID: On Tue, Jan 27, 2009 at 1:48 PM, klia wrote: > i am trying to tweak the current codes so that later when i call it from the > terminal i can provide sourcefile and the destination file rather being > fixed in the code.becuase now i have to specify the sourcefile and the > destinationfile in codes and not left to be specified from the terminal. i > want to be able to do this. > > python shutil_copy.py sourcefile, destinationfile > > code > import shutil > shutil.copyfile(srcfile, dstfile) # copy data only Have a look at the documentation for the sys module. cheers James From castironpi at gmail.com Mon Jan 26 23:23:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 20:23:30 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 26, 9:20?pm, Aaron Brady wrote: > Hi, Mark, snip > On Jan 25, 9:47?pm, Mark Wooding wrote:> Aaron Brady writes: > > > I am writing an extension using shared memory. ?I need a data type > > > that is able to reassign its 'ob_type' field depending on what process > > > is calling it. > > > That sounds scary! Ha ha, whoops. From ekh.johan at gmail.com Tue Jan 27 00:45:59 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 06:45:59 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Message-ID: <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Thank you Robert, but what if I just want to create an array interactively, e.g. like m = array([1.0, 2.0, 3.0]), and pass it to my program? I tried extending optparse with a new type as explained in the link you gave me but I was not able to get it to work. Is it really neccessary follow that route just to pass an array? Lot's of people must have done this before! Best regards, Johan On Tue, Jan 27, 2009 at 1:00 AM, Robert Kern wrote: > On 2009-01-26 17:44, Johan Ekh wrote: > >> Hi all, >> I'm trying to use optparse to process command line parameters given to >> my program. >> It works as I expect for the types supported by optparse, i.e. int, >> float, string etc. but how can I >> pass a numpy.array or a list to my program? >> > > http://docs.python.org/library/optparse#optparse-extending-optparse > > Figure out the text format you want your users to type the value on the > command line, write a function that will take that text and convert it to an > array or list, then customize OptionParser to use that parser as given in > the link above. Keep in mind that your user probably won't want to need to > use whitespace or any kind of brackets. Commas are nice, though. > > You may also want to consider taking a filename and parsing that file > instead. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Jan 27 00:53:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 15:53:10 +1000 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > Thank you Robert, > but what if I just want to create an array interactively, e.g. like m = > array([1.0, 2.0, 3.0]), and pass it > to my program? I tried extending optparse with a new type as explained in > the link you gave me > but I was not able to get it to work. Is it really neccessary follow that > route just to pass an array? > Lot's of people must have done this before! Normally command line applications accept a number of arguments which are available in sys.argv cheers James From ekh.johan at gmail.com Tue Jan 27 01:01:38 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 07:01:38 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Message-ID: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Thank you James, but I just can't optparse to accept an array, only integers, floats ans strings. My code looks like this from optparse import OptionParser parser = OptionParser() parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', default=0.1, help='time increment where lsoda saves results') parser.add_option('-T', '--tstop', action='store', type='float', dest='tstop_i', default=1.0, help='duration of the solution') parser.add_option('-m', '--mass_vector', action='store', type='float', dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse complains that m_i is not a float. Best regards, Johan On Tue, Jan 27, 2009 at 6:53 AM, James Mills wrote: > On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > > Thank you Robert, > > but what if I just want to create an array interactively, e.g. like m = > > array([1.0, 2.0, 3.0]), and pass it > > to my program? I tried extending optparse with a new type as explained in > > the link you gave me > > but I was not able to get it to work. Is it really neccessary follow that > > route just to pass an array? > > Lot's of people must have done this before! > > Normally command line applications accept > a number of arguments which are available > in sys.argv > > cheers > James > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Jan 27 01:07:32 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 16:07:32 +1000 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 4:01 PM, Johan Ekh wrote: > Thank you James, > but I just can't optparse to accept an array, only integers, floats ans > strings. > > My code looks like this > > from optparse import OptionParser > parser = OptionParser() > parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', > default=0.1, help='time increment where lsoda saves results') > parser.add_option('-T', '--tstop', action='store', type='float', > dest='tstop_i', default=1.0, help='duration of the solution') > parser.add_option('-m', '--mass_vector', action='store', type='float', > dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') > op, args = parser.parse_args(sys.argv[1:]) > > I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse > complains that m_i is not a float. What you want to do is accept a string as an argument to -m/--mass_vector and parse this string into a list. For example: parser.add_option('-m', '--mass_vector', action='store',dest='m_i', default=None, help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) if op.m_i is None: m_i = [1.0, 1.0] else: xs = m_i.split(",") m_i = [float(x.strip()) for x in xs] Of course be aware that this code does no error checking and if you pass in rubbish, it will likely throw an exception. cheers Jaems From robert.kern at gmail.com Tue Jan 27 01:12:53 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 00:12:53 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: On 2009-01-27 00:01, Johan Ekh wrote: > Thank you James, > but I just can't optparse to accept an array, only integers, floats ans > strings. > > My code looks like this > > from optparse import OptionParser > parser = OptionParser() > parser.add_option('-t', '--dt', action='store', type='float', > dest='dt_i', default=0.1, help='time increment where lsoda saves results') > parser.add_option('-T', '--tstop', action='store', type='float', > dest='tstop_i', default=1.0, help='duration of the solution') > parser.add_option('-m', '--mass_vector', action='store', type='float', > dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') > op, args = parser.parse_args(sys.argv[1:]) > > I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse > complains that m_i is not a float. Well, yes, because you declared that --mass_vector was type='float'. You will need to subclass OptionParser in order to parse something that is not one of the included types. Yes, it is a bit cumbersome; it's one of the reasons I usually use the third-party argparse library instead. You only need to supply a parsing function rather than subclass. I'm afraid I don't really understand what you want when you say that you want to create an array interactively. Can you show me an example command line that you want to parse? Keep in mind that in many shells, ()[] characters are specially handled by the shell and are not convenient for users. BTW, I am subscribed to the list. You do not need to Cc me. -- 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 martin at v.loewis.de Tue Jan 27 02:17:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 08:17:01 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <497E3C6F.1010909@v.loewis.de> Message-ID: <497EB4ED.1070400@v.loewis.de> > Well, the first step would be to tell Python that there is a code page > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > doing "chcp 65001". I checked the list of aliases in Python 3 and there > was no entry for cp65001. I see. What happens if you add it to encoding/aliases.py? Regards, Martin From fetchinson at googlemail.com Tue Jan 27 02:51:37 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 26 Jan 2009 23:51:37 -0800 Subject: How do I say "two classes up in the inheritance chain" in python? Message-ID: I have two classes that both inherit from two other classes which both inherit from a single class. The two children have two almost identical methods: class grandparent( object ): def meth( self ): # do something class parent1( grandparent ): def meth( self ): # do something p1 super( parent1, self ).meth( ) class parent2( grandparent ): def meth( self ): # do something p2 super( parent2, self ).meth( ) class child1( parent1 ): def meth( self ): # do something c super( parent1, self ).meth( ) # I want to invoke meth on grandparent class child2( parent2 ): def meth( self ): # do something c super( parent2, self ).meth( ) # I want to invoke meth on grandparent The meth methods in child1 and child2 are the same, except that in the last super call, one is referring to parent1, the other is referring to parent2. If they were exactly the same I could use a mixin where I could define this method, and both child1 and child2 would inherit from this mixin too. In this way I wouldn't have to code these methods twice. But how do I write this mixin? It needs to refer to the grandparent in such a way that it works in both child1 and child2 and bypasses both parent1 and parent2. How would I do that? Notes: (1) of course child1 and child2 have all sorts of methods which are different, only meth is almost the same. (2) I can't modify the grandfather class. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From duncan.booth at invalid.invalid Tue Jan 27 03:43:38 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jan 2009 08:43:38 GMT Subject: How do I say "two classes up in the inheritance chain" in python? References: Message-ID: Daniel Fetchinson wrote: > > class child1( parent1 ): > def meth( self ): > # do something c > super( parent1, self ).meth( ) # I want to invoke meth on > grandparent So just call: grandparent.meth(self) If you want to ignore the inheritance hierarchy then go ahead and ignore it. Only use super if you want to respect your parents. :) -- Duncan Booth http://kupuguy.blogspot.com From bignose+hates-spam at benfinney.id.au Tue Jan 27 04:07:26 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 27 Jan 2009 20:07:26 +1100 Subject: How do I say "two classes up in the inheritance chain" in python? References: Message-ID: <87myddyv5d.fsf@benfinney.id.au> Daniel Fetchinson writes: > The meth methods in child1 and child2 are the same, except that in > the last super call, one is referring to parent1, the other is > referring to parent2. It's important to learn that, in a language with multiple inheritance, ?superclass of this instance? is *not* the same concept as ?parent of this class?. The class you're coding may end up at any arbitrary point in a resolution chain, despite what the class inherits from. It's also important to be aware of the hairiness of Python's ?super? . -- \ ?No matter how cynical you become, it's never enough to keep | `\ up.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From ekh.johan at gmail.com Tue Jan 27 04:09:39 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 10:09:39 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Thanks, James I will try your suggestion! Robert, what mean with "interactively" is that i would like to create an array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or by reading a file with values etc., and then execute my program with "myprog -m m_i" and thus pass the array "m_i" to my program. This is just an example. I would like to pass several arrays. My program will be wrapped inside a loop and the arrays are updated in each loop. I have never heard of the "argparse" library. Do you think that it would be better to use that in my case? Best regards, Johan On Tue, Jan 27, 2009 at 7:12 AM, Robert Kern wrote: > On 2009-01-27 00:01, Johan Ekh wrote: > >> Thank you James, >> but I just can't optparse to accept an array, only integers, floats ans >> strings. >> >> My code looks like this >> >> from optparse import OptionParser >> parser = OptionParser() >> parser.add_option('-t', '--dt', action='store', type='float', >> dest='dt_i', default=0.1, help='time increment where lsoda saves results') >> parser.add_option('-T', '--tstop', action='store', type='float', >> dest='tstop_i', default=1.0, help='duration of the solution') >> parser.add_option('-m', '--mass_vector', action='store', type='float', >> dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') >> op, args = parser.parse_args(sys.argv[1:]) >> >> I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse >> complains that m_i is not a float. >> > > Well, yes, because you declared that --mass_vector was type='float'. You > will need to subclass OptionParser in order to parse something that is not > one of the included types. Yes, it is a bit cumbersome; it's one of the > reasons I usually use the third-party argparse library instead. You only > need to supply a parsing function rather than subclass. > > I'm afraid I don't really understand what you want when you say that you > want to create an array interactively. Can you show me an example command > line that you want to parse? Keep in mind that in many shells, ()[] > characters are specially handled by the shell and are not convenient for > users. > > BTW, I am subscribed to the list. You do not need to Cc me. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:14:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:14:38 +0100 Subject: How do I say "two classes up in the inheritance chain" in python? In-Reply-To: References: Message-ID: <497ed07e$0$6718$426a34cc@news.free.fr> Daniel Fetchinson a ?crit : > I have two classes that both inherit from two other classes which both > inherit from a single class. The two children have two almost > identical methods: > > class grandparent( object ): > def meth( self ): > # do something > > class parent1( grandparent ): > def meth( self ): > # do something p1 > super( parent1, self ).meth( ) > > class parent2( grandparent ): > def meth( self ): > # do something p2 > super( parent2, self ).meth( ) > > class child1( parent1 ): > def meth( self ): > # do something c > super( parent1, self ).meth( ) # I want to invoke meth on grandparent If so, it might be better to explicitly call grandparent.meth (passing self as first argument). But this is an obvious design smell IMHO. What you have is : def meth(self): do_something_more_or_less_specific call_granparent Looks like a candidate for a template method. Since you don't have hand on Grandparent, the simplest would be to add an additional base class, ie: class Abstract(Grandparent): def do_something(self): raise NotImplementedError def meth(self): self.do_something() super(Abstract, self).meth() class Parent1(Abstract): def do_something(self): # do something p1 class Parent2(Abstract): def do_something(self): # do something p2 Now you're problem is to factor out do_something() for Child1 and Child2. The solution is quite simple : just define it outside the class statements, and adds it afterward: def do_something_children(self): # code here class Child1(Parent1): # code here Child1.do_something = do_something_children class Child2(Parent2): # code here Child2.do_something = do_something_children HTH From n.kottiyath at gmail.com Tue Jan 27 04:17:33 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 01:17:33 -0800 (PST) Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Thank you everyone for your very helpful comments and suggestions. I have interacted in other newsgroups, but this is the most helpful of them all. As per the comments, I have now decided to go with the weakref mechanism - as per Andreas suggestion, functionally it looks correct that the person should not know the total number of people. So, in a higher level class, have a weakref list which contains a reference to each person. Total count will be len(list) at any time. Now, I couldnt find a weakref list - so I am using WeakKeyDictionary with the value as None - since len(dict) also should give me the data any time. I have another question here. In the documentation, it is mentioned that - Note: Caution: Because a WeakKeyDictionary is built on top of a Python dictionary, it must not change size when iterating over it. This can be difficult to ensure for a WeakKeyDictionary because actions performed by the program during iteration may cause items in the dictionary to vanish "by magic" (as a side effect of garbage collection). Now, the only two operations that I am doing are -> __init__: d = weakref.WeakKeyDictionary() method y: x = aa() d[x] = None method z: total = len(d) I believe that all the commands which I perform on WeakKeyDictionary here - (adding a new element) & (len(d)) - are atomic - or atleast nothing that can cause any worry as per the Note given above. Can anyone let me know whether my assumption is correct or not? Reason: My code has many many number of threads which interact with each other in myraid ways - so I do want to decrease the number of locks as much as possible. Especially I do not want to block other threads just for getting the count. From gopalm at infotechsw.com Tue Jan 27 04:20:49 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Tue, 27 Jan 2009 14:50:49 +0530 Subject: How to get text from a surface Message-ID: <20D905D27CC0441D92672AB530252777@pwit.com> Hi, I am loading an image into pygame. i am trying to get the text from the surface. I used pyTesser to read the text from a surface/image but if the font size of the text is less then 16, it doesn't give me back the correct text from the surface. Is there any other way to get the text from the pygame surface. Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:21:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:21:36 +0100 Subject: I'm a python addict ! In-Reply-To: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <497ed220$0$6718$426a34cc@news.free.fr> Paul McGuire a ?crit : > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: >> On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: >>> Want to change the type/behavior of an object from class A to class >>> B? How about this: >>> aobj = A() >>> aobj.__class__ = B >>> Try *that* in as simple-looking C++ or Java! >> Wow. That looks very powerful and fun. But scary. Any thoughts on how >> you would use that in a way that wouldn't unleash sulphurous code >> smells? >> > > This technique is perfect for implementing the GoF State pattern. Except when it is not !-) I tried twice to use this trick in "real life" code, and in both cases, it ended up being much more complicated than implementing the state pattern the canonical way. Not to say that it's hopeless - just that there's the usual difference between theory and practice. From yinon.me at gmail.com Tue Jan 27 04:33:06 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 27 Jan 2009 01:33:06 -0800 (PST) Subject: unittest, order of test execution References: Message-ID: > But I was wondering, *should* this test be separated into two unit > tests, one for each function? On the face of it, it looks that's how it > should be done. > > This, however, raises the question: what's the order of test execution > in the unittest? And how to pass values between unit tests? Should I > modify 'self' in unit test? It's OK to run some tests in the same function. When one of the asserts fails, following the traceback will lead you straight to your problem. The order of test execution is done by default by sorting the test functions alphabetically. You may disable the sort by setting self.sortTestMethodsUsing to None. The simplest way to pass values between tests is to use the class it (self). Yinon From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:39:02 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:39:02 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> <497d7d40$0$4845$426a34cc@news.free.fr> Message-ID: <497ed636$0$27515$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 26, 1:07 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> No. I can change the *team's* code. Please *read*. "team's ownership", >> ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get >> the message, now ? > > Team ownership doesn't necessarily mean that you can just change code > at will. Nope, but it surely means that I'm *not* changing "someone else's" code. > In industry, teams usually have a leader that you need to > check with before you can change an interface. This is totally unrelated. >>> Would you give all those developers your password to get into the >>> system? No? Wait a minute ... you mean you wouldn't "trust" them with >>> your password? But what about "openness"? Are you some sort of fascist >>> or what? >> Goodwin point. You loose. Good bye again, Mr P. > > You missed the point once again. In asking if you are a "fascist," I > was *parodying* your attitude that languages with enforced access > restrictions are for "fascists" who don't trust their co-workers or > employees. [I don't recall if you actually used that word I did not, and you should know better. > or if it was > someone else, but you did use "B&D", which carries the same general > impression.] Can't you tell the difference, really ? > So I parodied your hyperbole, Still not. But it's interesting to note that you consider everyone disagreeing with you as basically the same person. From yinon.me at gmail.com Tue Jan 27 04:40:13 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 27 Jan 2009 01:40:13 -0800 (PST) Subject: unittest, order of test execution References: Message-ID: <888c2c7c-97f8-45aa-9523-25d3dd4a75a1@z28g2000prd.googlegroups.com> On Jan 27, 11:33?am, Yinon Ehrlich wrote: > > But I was wondering, *should* this test be separated into two unit > > tests, one for each function? On the face of it, it looks that's how it > > should be done. > > > This, however, raises the question: what's the order of test execution > > in the unittest? And how to pass values between unit tests? Should I > > modify 'self' in unit test? > > It's OK to run some tests in the same function. > When one of the asserts fails, following the traceback will lead you > straight to your problem. > > The order of test execution is done by default by sorting the test > functions alphabetically. > You may disable the sort by setting self.sortTestMethodsUsing to None. see: http://docs.python.org/library/unittest.html#unittest.TestLoader.sortTestMethodsUsing > The simplest way to pass values between tests is to use the class it > (self). > > ? Yinon From rajorshi at in.com Tue Jan 27 04:42:01 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Tue, 27 Jan 2009 15:12:01 +0530 Subject: =?UTF-8?B?Q2FsbGluZyBQeXRob24tdGsgY29kZSBmcm9tIEMvQysr?= Message-ID: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Hello all, This is my first post to this mailing list. Our requirement is to invoke a Tkinter python panel from a C++ GUI app where both GUI windows would run in 2 separate threads. We have written a sample PyQt application which calls this Tk panel using something like this:class TkPanel(threading.Thread):def run(self): # call showPaneldef showPanel():# create window = Tk.Tk() window.mainloop()def start():t = TkPanel()t.start()Now we call this from our main python code:def startPanel(self): import tkPanel tkPanel.start() # this calls tkwindow.mainloop() in a separate thread.This works absolutely fine when the invoking app is Python. However, we are having problems when the invoking app is in C/C++ and we use a similar logic.My question boils down to this: If I have code in C++ that has to invoke a Pythontk panel such that the panel runs in its own thread, what is the best approach?I tried studying the GIL and acquiring releasing/locks, but I must be doing something wrong. An y help would be greatly appreciated!Thanks!Rajhttp://www.rajorshi.net/blogDear pythonlist! Get Yourself a cool, short @in.com Email ID now! -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Tue Jan 27 04:45:13 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 10:45:13 +0100 Subject: optparse question References: Message-ID: * Pat (Mon, 26 Jan 2009 20:02:59 -0500) > Up until today, I never needed to pass any arguments to a Python > program. > [...] > getopt resolved my immediate need, but I would like to know how one > could use optparse to extract out the options from something like "dir > /s /b". If you actually read the documentation (it's right at the top) you knew that this is not possible: "There are many different syntaxes for options; the traditional Unix syntax is a hyphen (?-?) followed by a single letter [...] The GNU project introduced "--" [...] These are the only two option syntaxes provided by optparse. Some other option syntaxes that the world has seen include: [...] a slash followed by a letter, or a few letters, or a word, e.g. "/f", "/file" These option syntaxes are not supported by optparse, and they never will be. This is deliberate: [...] the last only makes sense if you?re exclusively targeting VMS, MS-DOS, and/or Windows." Thorsten From gandalf at shopzeus.com Tue Jan 27 04:49:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 27 Jan 2009 10:49:03 +0100 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') Message-ID: <497ED88F.9050802@shopzeus.com> I have a program that uses socket.bind() and socket.listen() frequently. After that program stops, it is not able to bind() again for a while: File "/home/gandalf/Python/Lib/orb/accesspoints/srvtcp.py", line 27, in __init__ self.serversocket.bind((self.listen_address,self.port)) File "", line 1, in bind socket.error: (48, 'Address already in use') The problem with this, is that this server program SOMETIMES need to be restarted very quickly. I tried to find the solution in the socket module. But there is no "socket.unbind" or "socket.unlisten". How can I tell the OS that I do not want to listen on that address anymore, so other programs can bind on it immediatelly? (Yes I know that I can use setsockopt to allow listening multiple sockets on the same address, but this is NOT what I need...) Thanks, Laszlo From almar.klein at gmail.com Tue Jan 27 05:22:58 2009 From: almar.klein at gmail.com (Almar Klein) Date: Tue, 27 Jan 2009 11:22:58 +0100 Subject: OpenGL in TK Message-ID: Hi list! I am using pyOpenGL to do some 3D rendering. For now I am quite happy with the GLCanvas of wx, but I may want to publish some stuff later, and it would be nice if people would not need wx. I found that there used to be a TK widget called Togl, but it is not (anymore?) included in the TK package that comes with Python. Have others been able to use Togl, or any other OpenGL widget in TK? Thanks for any help, Almar PS: I use python 2.5.2 on windows -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerb at rogerbinns.com Tue Jan 27 05:25:48 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 27 Jan 2009 02:25:48 -0800 Subject: Iterating through a file significantly slower when file has big buffer In-Reply-To: <1233013349.25395.1296882205@webmail.messagingengine.com> References: <1233013349.25395.1296882205@webmail.messagingengine.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 python at bdurham.com wrote: > The following tests were run on a Windows XP system using Python 2.6.1 Unless you changed the defaults, the Windows XP system cache size is 10MB. When you use a larger read size, chances are it is blowing out that cache and causes metadata (file block locations) to have to be reread on your next read. You are also funnelling all the data through your CPU cache with a similar effect although it will be less noticeable. To change XP cache sizes, see: http://marc.info/?l=sqlite-users&m=116743785223905&w=2 http://support.microsoft.com/kb/895932 http://www.techspot.com/tweaks/memory-winxp/ Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl+4SkACgkQmOOfHg372QRgcACfVOdUWQGyj8xtNvHob/CtcM8g JsEAoKt/xI36iR5RuQOfZDMz2ze4L3Ia =DrDw -----END PGP SIGNATURE----- From gagsl-py2 at yahoo.com.ar Tue Jan 27 05:31:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 08:31:02 -0200 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: En Mon, 26 Jan 2009 17:06:20 -0200, Torsten Mohr escribi?: >> So mymodule is actually a package. Packages should *not* appear in >> sys.path. > > Oh, how does it find modules then? I thought that would be PYTHONPATH or > sys.path ? The directory CONTAINING file "foo.py" must be in sys.path if you want to import foo. The directory CONTAINING package "bar" must be in sys.path if you want to import bar. There were some threds on this topic last month, see this by example: http://groups.google.com/group/comp.lang.python/t/ed47d8e31ca3d411/ -- Gabriel Genellina From lie.1296 at gmail.com Tue Jan 27 05:31:25 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 27 Jan 2009 10:31:25 +0000 (UTC) Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On Mon, 26 Jan 2009 11:08:48 -0600, Unknown wrote: > On 2009-01-26, Lie Ryan wrote: > >> How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little >> Hardware Experience). High pitched sound (or anything in sound-ology >> that means high voltage) means the device is on and low pitched sound >> off. > > 1) Pitch has nothing to do with voltage. A high-pitch sound > and a low pitch sound can have the exact same voltage. > > 2) The OP's device requires quite a bit of power. There is > almost no power available from the line-out jack, and the voltage is > limited to about 1V. If his sound card has a power-amp (none do > these days), he might be able to get a usable amount of power. > >> The device will need an additional transistor to separate low voltage >> from the high voltage. > > He'll need more than a transistor. He needs a power supply, some sort > of rectifier/detector, and a comparitor. It would be more interesting to > use notch filters to detect different frequencies so that you could have > multiple output "bits". >From the little I know on electronics, a simple, single transistor would (almost) immediately switch from on-to-off-to-on depending on the voltage of the control pin (I think it was the middle pin). I was suggesting this simplistic hack because as far as I comprehend the OP's need, he only need on-off switch instead of a complex multiple output bits. >> I don't know how much power can be pulled from jack out, > > Almost none, and what's there is very low voltage. That's why the power is taken from USB port. >> but for a home brewn device it is still feasible to draw power from USB >> and signal from jack out. > > It would probably be easier to buy a USB-parallel port chip. Then he's > got power from the USB bus and something like 14 parallel I/O pins he > can control. Alternatively A USB-serial chip will provide 2 outputs and > 4 inputs. The idea was made on the basis that a USB microcontroller is not used. Getting power from USB should be much easier than getting data while the jack out can provide simple on-off signal. From lie.1296 at gmail.com Tue Jan 27 05:37:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 27 Jan 2009 10:37:59 +0000 (UTC) Subject: practical limits of urlopen() References: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Message-ID: On Sat, 24 Jan 2009 09:17:10 -0800, webcomm wrote: > Hi, > > Am I going to have problems if I use urlopen() in a loop to get data > from 3000+ URLs? There will be about 2KB of data on average at each > URL. I will probably run the script about twice per day. Data from > each URL will be saved to my database. > > I'm asking because I've never opened that many URLs before in a loop. > I'm just wondering if it will be particularly taxing for my server. Is > it very uncommon to get data from so many URLs in a script? I guess > search spiders do it, so I should be able to as well? urllib doesn't have any limits, what might limit your program is your connection speed and the hardware where the server and downloader is on. Getting 3000 URLs is about 6MBs, a piece of cake for a sufficiently modern machine on a decent internet connection (the real calculation isn't that simple though, there is also some cost associated with sending and processing HTML headers). Google indexes millions of pages per day, but they also have one of the most advanced server farm in the world. From rajorshi at in.com Tue Jan 27 05:40:52 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Tue, 27 Jan 2009 16:10:52 +0530 Subject: =?UTF-8?B?Qy1QeXRob24gQVBJIHByb2JsZW0=?= Message-ID: <1233052852.4b86abe48d358ecf194c56c69108433e@mail.in.com> Hi, I was trying out the sample program to load a python script from C in the Python tutorial at http://docs.python.org/extending/embedding.html (Section: Pure Embedding).Usage: call pythonfile funcname [args] When running this script, I can run things like the following:call mytest foobut not any function which calls a Tk function:call mytest teekay Here is my mytest.py module:def foo():print "func"def teekay():import Tkinterr=Tkinter.Tkr()I get the following error in the latter case:Traceback (most recent call last):...import Tkinter ...import tkinter # If this fails your Python may not be configured for TkImportError: /software/lib/Linuxx86/python2.6/lib/python2.6/libdynload/tkinter.so: undefined symbol: PyTrueStructCall failedObviously, trying this from within a Python shell works fine.Any clues?Thanks,RajRajhttp://www.rajorshi.net/blogDear pythonlist ! Get Yourself a cool, short @in.com Email ID now! -------------- next part -------------- An HTML attachment was scrubbed... URL: From pistacchio at gmail.com Tue Jan 27 06:33:43 2009 From: pistacchio at gmail.com (gu) Date: Tue, 27 Jan 2009 12:33:43 +0100 Subject: Class behaving like a static class Message-ID: Hi to all, i have a module (a single .py file, actually), with a class called HashedDir. when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different. Eg: h1 = HashedDir('someValue') print h1.value # someValue h2 = HashedDir('someOtherValue') print h1.value # someOtherValue print h2.value # someOtherValue Any idea? Thanks in advance From murielgodoi at gmail.com Tue Jan 27 06:41:00 2009 From: murielgodoi at gmail.com (Muriel de Souza Godoi) Date: Tue, 27 Jan 2009 09:41:00 -0200 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: Some people got success in Arduindo using an older mobile cable which works as USB/Serial converters. So you can read and write data as a serial port using pyserial. On Tue, Jan 27, 2009 at 8:31 AM, Lie Ryan wrote: > On Mon, 26 Jan 2009 11:08:48 -0600, Unknown wrote: > > > On 2009-01-26, Lie Ryan wrote: > > > >> How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > >> Hardware Experience). High pitched sound (or anything in sound-ology > >> that means high voltage) means the device is on and low pitched sound > >> off. > > > > 1) Pitch has nothing to do with voltage. A high-pitch sound > > and a low pitch sound can have the exact same voltage. > > > > 2) The OP's device requires quite a bit of power. There is > > almost no power available from the line-out jack, and the voltage is > > limited to about 1V. If his sound card has a power-amp (none do > > these days), he might be able to get a usable amount of power. > > > >> The device will need an additional transistor to separate low voltage > >> from the high voltage. > > > > He'll need more than a transistor. He needs a power supply, some sort > > of rectifier/detector, and a comparitor. It would be more interesting to > > use notch filters to detect different frequencies so that you could have > > multiple output "bits". > > >From the little I know on electronics, a simple, single transistor would > (almost) immediately switch from on-to-off-to-on depending on the voltage > of the control pin (I think it was the middle pin). I was suggesting this > simplistic hack because as far as I comprehend the OP's need, he only > need on-off switch instead of a complex multiple output bits. > > >> I don't know how much power can be pulled from jack out, > > > > Almost none, and what's there is very low voltage. > > That's why the power is taken from USB port. > > >> but for a home brewn device it is still feasible to draw power from USB > >> and signal from jack out. > > > > It would probably be easier to buy a USB-parallel port chip. Then he's > > got power from the USB bus and something like 14 parallel I/O pins he > > can control. Alternatively A USB-serial chip will provide 2 outputs and > > 4 inputs. > > The idea was made on the basis that a USB microcontroller is not used. > Getting power from USB should be much easier than getting data while the > jack out can provide simple on-off signal. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Msc. Muriel de Souza Godoi Computation Department State University of Maring? Brazil -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Tue Jan 27 06:52:46 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 13:52:46 +0200 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') References: <497ED88F.9050802@shopzeus.com> Message-ID: <007501c98075$f9b83de0$0d00a8c0@hendrik> "Laszlo Nagy" wrote: > I have a program that uses socket.bind() and socket.listen() frequently. > After that program stops, it is not able to bind() again for a while: > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) This does the trick for me. - Hendrik From gil.shinar at gmail.com Tue Jan 27 07:00:46 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 04:00:46 -0800 (PST) Subject: Process crash with no reason References: Message-ID: On Jan 26, 8:40?pm, Philip Semanchuk wrote: > On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > > Hi All, > > > I'm running a program that is acting as a nice interface to sybase' > > replication server. The program is using the cherrypy web service for > > the GUI. The process is crashing every few days with no reason. In the > > log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > > TraceBack python's message. This program is running on solaris 9 > > machine. > > Where can I see or what can I do in order to find out what causes the > > process to crash? > > I have tried simulating a "traceBack" message and I could see this > > traceback message in one of the log files I'm using. When the process > > crashes without my help, I don't have a clue. > > Let me know if you need any other info > > Although Python isn't immune to fatal errors like you describe, I'd ? > immediately suspect a 3rd-party module instead, esp. one written in C ? > or C++. Are you using anything like that? No I do not. Is there a way to monitor who had "killed" my process? Thanks From mgbg25171 at blueyonder.co.uk Tue Jan 27 07:02:23 2009 From: mgbg25171 at blueyonder.co.uk (me) Date: Tue, 27 Jan 2009 12:02:23 +0000 Subject: creating a pattern using a previous match and a count of the number of '('s in it Message-ID: <200901271202.23170.mgbg25171@blueyonder.co.uk> I'm new to regexs and trying to get a list of all my C++ methods with balanced parenthesis as follows. #find all c++ method prototypes with a '::' in the middle #upto and including the 1st closing parenthesis pattern_upto_1st_closed_parenth = re.compile('\w+::\w+\([^)]*\)') match_upto_1st_closed_parenth = re.findall(pattern_upto_1st_closed_parenth,txt) num_of_protos = len(match_upto_1st_closed_parenth) for i in range (0,num_of_protos-1): num_of_open_parenths = match_upto_1st_closed_parenth[i].count('(') #expand the pattern to get all of the prototype #ie upto the last closed parenthesis #saying something like pattern = re.compile(\ 'match_upto_1st_closed_parenth[i]+\ (([^)]*\)){num_of_open_parenths-1}'\ ) #==================================================================== #HELP!!!!!! I'm not sure how to incorporate: #1 'match_upto_1st_closed_parenth[i]' into the above extended pattern??? #2 the count 'num_of_open_parenths' instead of a literal ??? #==================================================================== #======================================= #if I could do it this sort of this would appear to offer the neatest solution pattern_upto_last_balanced_parenthesis = re.compile(' (\w+::\w+\([^)]*\))\ ([^)]*\)){\1.count('(')-1} ') #======================================= Should I be using regexs to do this? I've only put \ line extensions to separate the pattern components to assist readability Thx From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 07:06:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 13:06:22 +0100 Subject: Class behaving like a static class In-Reply-To: References: Message-ID: <497ef8bd$0$7877$426a74cc@news.free.fr> gu a ?crit : > Hi to all, > i have a module (a single .py file, actually), with a class called > HashedDir. > > when i import the file and instanciate 2 instances of that class, when i > check the object's fields they're always the same, even if the two > objects should be different. > > Eg: > > h1 = HashedDir('someValue') > print h1.value # someValue > h2 = HashedDir('someOtherValue') > print h1.value # someOtherValue > print h2.value # someOtherValue > > Any idea? Yes : post the relevant code - or at least the minimal code that reproduces the unexpected behaviour. There are quite a couple gotchas regarding class-vs-instance-attributes and default-params, but none of them matches what you have here - at least if 'value' is an attribute set on 'self' from within the initializer. So either the above snippet is made up and you're in fact having this problem with mutable attributes (like 'value' is a list and you're appending to it) or there's something else in your code. From mail at timgolden.me.uk Tue Jan 27 07:10:01 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 27 Jan 2009 12:10:01 +0000 Subject: Process crash with no reason In-Reply-To: References: Message-ID: <497EF999.2050405@timgolden.me.uk> gil.shinar at gmail.com wrote: > On Jan 26, 8:40 pm, Philip Semanchuk wrote: >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>> Hi All, >>> I'm running a program that is acting as a nice interface to sybase' >>> replication server. The program is using the cherrypy web service for >>> the GUI. The process is crashing every few days with no reason. In the >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get any >>> TraceBack python's message. This program is running on solaris 9 >>> machine. >>> Where can I see or what can I do in order to find out what causes the >>> process to crash? >>> I have tried simulating a "traceBack" message and I could see this >>> traceback message in one of the log files I'm using. When the process >>> crashes without my help, I don't have a clue. >>> Let me know if you need any other info >> Although Python isn't immune to fatal errors like you describe, I'd >> immediately suspect a 3rd-party module instead, esp. one written in C >> or C++. Are you using anything like that? > > No I do not. Then how are you interacting with Sybase? TJG From gnewsg at gmail.com Tue Jan 27 07:52:16 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Tue, 27 Jan 2009 04:52:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> On 26 Gen, 19:16, jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format ?"\N{name}" allows me to specify by Unicode > name. > Neither seem to work for me. > What am I doing wrong ? > > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec ?3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information.>>> print('\u20ac') > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\python30\lib\io.py", line 1491, in write > ? ? b = encoder.encode(s) > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > > >>> print ("\N{EURO SIGN}") > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\python30\lib\io.py", line 1491, in write > ? ? b = encoder.encode(s) > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to I have this same issue on Windows. Note that on Python 2.6 it works: Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print unicode('\u20ac') \u20ac This is pretty serious, IMHO, since breaks any Windows software priting unicode to stdout. I've filed an issue on the Python bug tracker: http://bugs.python.org/issue5081 --- Giampaolo http://code.google.com/p/pyftpdlib/ From Pat at junk.net Tue Jan 27 08:01:19 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 08:01:19 -0500 Subject: optparse question References: <796ebbdf-b1ee-498e-a53e-766d97f21588@r15g2000prd.googlegroups.com> Message-ID: > > If you mean with "/" as the option designator instead of "-": there > doesn't appear to be a documented way of doing it. You would have to > do some social engineering on the users to get them used to doing "dir > -s -b". In any case I thought the number of Windows users who know how > to fire up a Command Prompt window was diminishingly small ... you > actually have users who know how to use commands like "dir /s /b"? > I used dir /s /b as a trivial Windows example. I use Windows for personal use but Ubuntu for work and programming. Personally, I use dir /s /b all the time on Windows since the /b option finds files *much* faster; maybe 10x or 100x faster but I didn't get out a stopwatch. From Pat at junk.net Tue Jan 27 08:06:47 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 08:06:47 -0500 Subject: optparse question References: Message-ID: Thorsten Kampe wrote: > * Pat (Mon, 26 Jan 2009 20:02:59 -0500) >> Up until today, I never needed to pass any arguments to a Python >> program. >> [...] >> getopt resolved my immediate need, but I would like to know how one >> could use optparse to extract out the options from something like "dir >> /s /b". > > If you actually read the documentation (it's right at the top) you knew > that this is not possible: > "There are many different syntaxes for options; the traditional Unix > syntax is a hyphen (?-?) followed by a single letter [...] The GNU > project introduced "--" [...] These are the only two option syntaxes > provided by optparse. > Some other option syntaxes that the world has seen include: > [...] > a slash followed by a letter, or a few letters, or a word, e.g. "/f", > "/file" > > These option syntaxes are not supported by optparse, and they never will > be. This is deliberate: [...] the last only makes sense if you?re > exclusively targeting VMS, MS-DOS, and/or Windows." > > Thorsten Sigh. I used dir /s /b as a simple Windows command with a flag (it could have been dir /s) because it was the first thing that popped into my mind. I had no idea people were going to get so upset that I used a Windows example and go off on a tear. From python-url at phaseit.net Tue Jan 27 08:11:06 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 27 Jan 2009 13:11:06 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 27) Message-ID: QOTW: "Whatever sufficiently sophisticated topic was ... initially discussed it ends all up in a request for removing reference counting and the GIL." - Kay Schluehr http://groups.google.com/group/comp.lang.python/msg/6a152ff76cf313ff Looking for a different kind of (editor|environment|interfase) like TextCalc for Python: http://groups.google.com/group/comp.lang.python/t/195ebd77f9e191e2/ Inheritance, encapsulation, and hungarian notation: http://groups.google.com/group/comp.lang.python/t/e6fc603109b42b62/ True, False, None, and the "==" and "is" operators: http://groups.google.com/group/comp.lang.python/t/21cc0e59bb59c7f1/ Mixing True/False and ints can confuse: http://groups.google.com/group/comp.lang.python/t/3185626fca2feb9b/ A short (but very interesting) essay on names, expressions, variables, and binding, by Mark Wooding: http://groups.google.com/group/comp.lang.python/t/3efb017e757bf3d9/ Using the struct module to handle variable-sized data types: http://groups.google.com/group/comp.lang.python/t/de5d94ffd953eaba/ Experienced Pythonistas give advice on improving programming skills: http://groups.google.com/group/comp.lang.python/t/4929f2681088730d/ Kaspersky mentions Python as vector for handset infection: http://www.theregister.co.uk/2009/01/22/symbian_trojan/ Running Python code on the client side from a web app: http://groups.google.com/group/comp.lang.python/t/e8131fc8a29db75c/ A new Counter class (similar to bag/multiset in other languages) was added to the collections module: http://groups.google.com/group/comp.lang.python/t/debefb159cd0752d/ The longest thread until now, started previous week. Now discussing enforced data hiding and the Scada language, team management, and who knows what (I gave up!) http://groups.google.com/group/comp.lang.python/t/68bc54bca830c46/ Another very long thread: RPython and PyPy advantages, the GIL, concurrency issues on modern CPU architectures, and removing the GIL (again!): http://groups.google.com/group/comp.lang.python/t/d8f15fad0638bca/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From denis.kasak at gmail.com Tue Jan 27 08:22:32 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Tue, 27 Jan 2009 14:22:32 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <39e19a010901270522w6a6d7eb2kdb1d04de8d6465a1@mail.gmail.com> On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' wrote: > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print unicode('\u20ac') > \u20ac Shouldn't this be print unicode(u'\u20ac') on 2.6? Without the 'u' prefix, 2.6 will just encode it as a normal (byte) string and escape the backslash. In Python 3.0 you don't need to do this because all strings are "unicode" to start with. I suspect you will see the same error with 2.6 on Windows once you correct this. (note to Giampaolo: sorry, resending this because I accidentally selected "reply" instead of "reply to all") -- Denis Kasak From apt.shansen at gmail.com Tue Jan 27 08:29:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 27 Jan 2009 05:29:55 -0800 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <7a9c25c20901270529y2663e3bel101d87cab021347a@mail.gmail.com> > > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print unicode('\u20ac') > \u20ac > Note that in Python 2.6 it expressly *does not* work, by your own example. Although I think the example is wrong and that you need to print u'\u20ac' in 2.6 unless you are importing unicode_literals from __future__; otherwise '\u20ac' is an ASCII string of 6 characters. "Works" would result, I'd think, in a unicode character being actually written to stdout: that is not happening. Instead a backslash pattern of ASCII characters meant to represent a Unicode character that -can't- be written to that stream are being written to stdout. The two aren't even kind of the same: but this is hardly something Python has a lot of control over... Windows software printing unicode to stdout was always a bit broken. IF you set the code page you could print some -- and IF you changed the font on the command prompt to a /non/-default font you could actually display others -- but it really is sort of a sucky situation, Unicode in Console windows on Windows. I really don't know how Python could do it better here: between the default code page on Windows being completely lame, the default font not supporting Unicode really... ISTM that having cross-platform apps which output unicode (really UTF8 probably) to stdout are just not really doable. But if you really want to you can always rebind sys.stdout with an error mode of "backslashreplace" or "xmlcharrefreplace" (which I do in one situation where I have a subprocess that has to output 'unicode' to a parent process) instead of 'strict'. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Tue Jan 27 08:31:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 05:31:42 -0800 (PST) Subject: optparse question References: Message-ID: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> On Jan 28, 12:06?am, Pat wrote: > Thorsten Kampe wrote: > > * Pat (Mon, 26 Jan 2009 20:02:59 -0500) > >> Up until today, I never needed to pass any arguments to a Python > >> program. > >> [...] > >> getopt resolved my immediate need, but I would like to know how one > >> could use optparse to extract out the options from something like "dir > >> /s /b". > > > If you actually read the documentation (it's right at the top) you knew > > that this is not possible: > > "There are many different syntaxes for options; the traditional Unix > > syntax is a hyphen (?-?) followed by a single letter [...] The GNU > > project introduced "--" [...] These are the only two option syntaxes > > provided by optparse. > > Some other option syntaxes that the world has seen include: > > [...] > > a slash followed by a letter, or a few letters, or a word, e.g. "/f", > > "/file" > > > These option syntaxes are not supported by optparse, and they never will > > be. This is deliberate: [...] the last only makes sense if you?re > > exclusively targeting VMS, MS-DOS, and/or Windows." > > > Thorsten > > Sigh. ?I used dir /s /b as a simple Windows command with a flag (it > could have been dir /s) because it was the first thing that popped into > my mind. > > I had no idea people were going to get so upset that I used a Windows > example and go off on a tear. Nobody is upset, and nobody has "gone off on a tear". The point about the "Windows example" is that the docs say in a close-to-screamingly- obvious manner that /options are not supported, no matter what religion uses them. It was not, and still is not, apparent what you really wanted. We're all patiently waiting for you to rephrase the question(s). From exarkun at divmod.com Tue Jan 27 08:41:45 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 27 Jan 2009 08:41:45 -0500 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') In-Reply-To: <497ED88F.9050802@shopzeus.com> Message-ID: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> On Tue, 27 Jan 2009 10:49:03 +0100, Laszlo Nagy wrote: >I have a program that uses socket.bind() and socket.listen() frequently. >After that program stops, it is not able to bind() again for a while: > >File "/home/gandalf/Python/Lib/orb/accesspoints/srvtcp.py", line 27, in >__init__ > self.serversocket.bind((self.listen_address,self.port)) > File "", line 1, in bind >socket.error: (48, 'Address already in use') > > >The problem with this, is that this server program SOMETIMES need to be >restarted very quickly. I tried to find the solution in the socket module. >But there is no "socket.unbind" or "socket.unlisten". How can I tell the OS >that I do not want to listen on that address anymore, so other programs can >bind on it immediatelly? > >(Yes I know that I can use setsockopt to allow listening multiple sockets on >the same address, but this is NOT what I need...) Actually, SO_REUSEADDR is probably just what you want. Since I can't see your code and I don't know under what situations it fails, I can only guess at the problem, but my guess is that you have connections from the first run of your app left in the TIME_WAIT state and they are preventing you from binding to the address again in the second run of your app. Setting the SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, though). Jean-Paul From sjmachin at lexicon.net Tue Jan 27 08:45:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 05:45:00 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: On Jan 27, 11:52?pm, "Giampaolo Rodola'" wrote: > On 26 Gen, 19:16, jefm wrote: > > > > > Hi, > > while checking out Python 3, I read that all text strings are now > > natively Unicode. > > In the Python language reference (http://docs.python.org/3.0/reference/ > > lexical_analysis.html) I read that I can show Unicode character in > > several ways. > > "\uxxxx" supposedly allows me to specify the Unicode character by hex > > number and the format ?"\N{name}" allows me to specify by Unicode > > name. > > Neither seem to work for me. > > What am I doing wrong ? > > > Please see error output below where I am trying to show the EURO sign > > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > > Python 3.0 (r30:67507, Dec ?3 2008, 20:14:27) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information.>>> print('\u20ac') > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python30\lib\io.py", line 1491, in write > > ? ? b = encoder.encode(s) > > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > > position 0: character maps to > > > >>> print ("\N{EURO SIGN}") > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python30\lib\io.py", line 1491, in write > > ? ? b = encoder.encode(s) > > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > > position 0: character maps to > > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec ?4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> print unicode('\u20ac') > > \u20ac > > This is pretty serious, IMHO, since breaks any Windows software > priting unicode to stdout. > I've filed an issue on the Python bug tracker:http://bugs.python.org/issue5081 Hello hello -- (1) that's *not* attempting to print Unicode. Look at your own output ... "\u20ac"" was printed, not a euro character!!! With 2.X for *any* X: >>> guff ='\u20ac' >>> type(guff) >>> len(guff) 6 (2) Printing Unicode to a Windows console has never *worked*; that's why this thread was pursuing the faint ray of hope offered by cp65001. From koranthala at gmail.com Tue Jan 27 08:46:25 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 27 Jan 2009 05:46:25 -0800 (PST) Subject: A Twisted Design Decision Message-ID: Twisted, being twisted in its behavior is causing quite a lot of confusion in design decisions. I will put forward a comparison of reactor and non-reactor patterns. The code is not exact - whatever is shown is the gist of it. For example, a message handler - in a usual scenario: class messageHandler: def run(): msg = self.get_next_msg() if not msg.send(): self.handle_failure() To handle parallel execution, we will have to use threads, but the code flow is similar. How do we do the same in a reactor pattern (Twisted)? msg.send will cause a deferred to be raised - the failure, if it happens will happen much later. i.e. other than sending messageHandler object in msg.send(), I cannot see any mechanism of running handle_failure. In Twisted: class messageHandler: def run(): msg = self.get_next_msg() msg.send(self): class msgClass: def send(o): d = deferred.addCallBack(success_handler, o).addErrBack (failure_handler, o) def failure_handler(o): o.handle_failure() Basically, what I find is that a lot of functional encapsulation is now lost by following reactor pattern. handle_failure is messageHandlers code and makes for pretty viewing if called from inside messageHandler itself. But, due to the twisted nature of reactor pattern, the msg Class - who is functionally a lower class to messageHandler invoking messageHandler's code. Is there a way to solve this in a more beautiful way? Am I missing something here? From exarkun at divmod.com Tue Jan 27 08:57:22 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 27 Jan 2009 08:57:22 -0500 Subject: A Twisted Design Decision In-Reply-To: Message-ID: <20090127135722.24460.256085074.divmod.quotient.2658@henry.divmod.com> On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: >Twisted, being twisted in its behavior is causing quite a lot of >confusion in design decisions. I'm not sure I agree with your premise. ;) >I will put forward a comparison of reactor and non-reactor patterns. >The code is not exact - whatever is shown is the gist of it. > >For example, a message handler - in a usual scenario: >class messageHandler: > def run(): > msg = self.get_next_msg() > if not msg.send(): > self.handle_failure() > >To handle parallel execution, we will have to use threads, but the >code flow is similar. > >How do we do the same in a reactor pattern (Twisted)? >msg.send will cause a deferred to be raised - the failure, if it >happens will happen much later. >i.e. other than sending messageHandler object in msg.send(), I cannot >see any mechanism of running handle_failure. > >In Twisted: >class messageHandler: > def run(): > msg = self.get_next_msg() > msg.send(self): > >class msgClass: > def send(o): > d = deferred.addCallBack(success_handler, o).addErrBack >(failure_handler, o) > > def failure_handler(o): > o.handle_failure() This doesn't look like a correct or faithful translation of the original. Here are two possibilities. First: class messageHandler: def run(): msg = self.get_next_msg() d = msg.send() def cbSendFailed(result): if not result: self.handle_failure() d.addErrback(cbSendFailed) return d Next: class messageHandler: @inlineCallbacks def run(): msg = self.get_next_msg() if not (yield msg.send()): self.handle_failure() These are both just straight translations from your version so as to be able to handle a Deferred from `msg.send?. >Basically, what I find is that a lot of functional encapsulation is >now lost by following reactor pattern. handle_failure is >messageHandlers code and makes for pretty viewing if called from >inside messageHandler itself. But, due to the twisted nature of >reactor pattern, the msg Class - who is functionally a lower class to >messageHandler invoking messageHandler's code. You don't need to lose anything. I don't know what your motivation was for re-arranging the code when you wrote the Twisted version, but it doesn't appear to have been necessary. >Is there a way to solve this in a more beautiful way? Am I missing >something here? > Hope this helps, Jean-Paul From alan.isaac at gmail.com Tue Jan 27 09:05:34 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 27 Jan 2009 14:05:34 GMT Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: You could try SimpleTable: http://code.google.com/p/econpy/source/browse/trunk/utilities/text.py fwiw, Alan Isaac From fakeaddress at nowhere.org Tue Jan 27 09:25:51 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 27 Jan 2009 06:25:51 -0800 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> References: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steve Holden writes: > >> No, you aren't mistaken. Looking at the "*" symbol in the 2.6 >> documentation index it lists only two references. The first is the >> language manual's explanation of its use in the def statement, the >> second is a transitory reference to its use in function calls, but >> that's in the tutorial where it is not likely to get much attention. > > There's a full description of it in 5.4.3 in the Language Reference, but > apparently not indexed. So I guess this means I can duck out of writing up a lecture on my own understanding of Python's extended call syntax. Great. I think I grock the extended call syntax, and when the question came up I was surprised not to be able to find where I learned it. Mark, where exactly does one look to see this "full description"? -- --Bryan From kyrie at uh.cu Tue Jan 27 09:31:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 09:31:11 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <497ed636$0$27515$426a34cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497ed636$0$27515$426a34cc@news.free.fr> Message-ID: <200901270931.11979.kyrie@uh.cu> On Tuesday 27 January 2009 04:39:02 am Bruno Desthuilliers wrote: > Still not. But it's interesting to note that you consider everyone > disagreeing with you as basically the same person. Hehe. At the beginning of this thread, I also thought that Russ P. and Paul Robin were the same person. I have serious problems with names. [My apologies to both of you, if I said something that made you notice my confusion]. P.S: Just to be clear, I'm neither Russ P. nor Paul Robin :D -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From jcd at sdf.lonestar.org Tue Jan 27 09:46:42 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 27 Jan 2009 09:46:42 -0500 Subject: is None vs. == None In-Reply-To: References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <497A609F.4030700@islandtraining.com> Message-ID: <1233067602.4143.1.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-23 at 19:31 -0500, Benjamin Kaplan wrote: > > > On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron > wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a comment recommending > using is > >> None instead of == None (also is not None, > etc.) > >> > > > > That entirely depends on whether you wish to test for > something which > > *is* None or something with *equals* None. Those two things > have > > different meanings. > > > > > Actually, for None, those two things *are* the same. If > something > *equals* None, it also *is* None. This is a consequence of > the fact > that there is only ever one value of None anywhere in the > system. > > Not if someone decided to be a PITA. > > >>> class A(object) : > ... def __eq__(self, other) : > ... return other is None > ... > >>> a = A() > >>> a == None > True > >>> a is None > False > > or slightly less PITAish: class EqualThing(object): def __eq__(self, other): return True Could be a useful sentinel value in some cases. > > > > I wonder, do newbies actually get the impression from > somewhere that "is" > > is a synonym for "=="? > > > > > Yes. Such questions pop up regularly, and are usually dealt > with quickly. > > > > > > > > >> My own > >> testing indicates that the former beats the latter by about > 30% on > >> average. Not a log for a single instruction but it can add > up in large > >> projects. > >> > > > > If you have a "large" project where the time taken to do > comparisons to > > None is a significant portion of the total time, I'd be very > surprised. > > > > var is None is a micro-optimization, but that's not why we > do it. We do > > it because usually the correct test is whether var *is* None > and not > > merely equal to None. Any random object might happen to > equal None > > (admittedly most objects don't), but only None is None. > > > > > You don't have that quite right. The only way something can > *equal* > None is if it *is* None. > None is not a value an object can have, but rather it is a > (singleton) > object that can be referenced. Setting something *equal* to > None is > accomplished by making it refer to the single None object, at > which > point it *is* None. > > Gary Herron > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From philip at semanchuk.com Tue Jan 27 10:00:24 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 10:00:24 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: On Jan 27, 2009, at 7:00 AM, gil.shinar at gmail.com wrote: > On Jan 26, 8:40 pm, Philip Semanchuk wrote: >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>> Hi All, >> >>> I'm running a program that is acting as a nice interface to sybase' >>> replication server. The program is using the cherrypy web service >>> for >>> the GUI. The process is crashing every few days with no reason. In >>> the >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get >>> any >>> TraceBack python's message. This program is running on solaris 9 >>> machine. >>> Where can I see or what can I do in order to find out what causes >>> the >>> process to crash? >>> I have tried simulating a "traceBack" message and I could see this >>> traceback message in one of the log files I'm using. When the >>> process >>> crashes without my help, I don't have a clue. >>> Let me know if you need any other info >> >> Although Python isn't immune to fatal errors like you describe, I'd >> immediately suspect a 3rd-party module instead, esp. one written in C >> or C++. Are you using anything like that? > > No I do not. But you're using CherryPy, aren't you? And as Tim Golden pointed out, you're probably using another 3rd party lib to talk to Sybase. ISTR that CherryPy is written in pure Python but if you have a database adapter lib it probably isn't. > Is there a way to monitor who had "killed" my process? That's more of a Solaris question than a Python one, and I don't know much about Solaris. Is there a system log where Solaris records when & why it has killed errant processes? From rantingrick at gmail.com Tue Jan 27 10:07:19 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:07:19 -0800 (PST) Subject: How many followers of comp.lang.python Message-ID: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> I curious of how many are "really" out there. I have been watching the list for some time but basically see the same 10 or so people answering questions. Reply to this message so we can see how many exists here Thanks From kyosohma at gmail.com Tue Jan 27 10:10:43 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 07:10:43 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> Message-ID: <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> On Jan 27, 9:07?am, rantingrick wrote: > I curious of how many are "really" out there. I have been watching the > list for some time but basically see the same 10 or so people > answering questions. > > Reply to this message so we can see how many exists here > > Thanks I'm not sure how you arrived at that low number. If you go to the main page on the Google Groups version, you'll count at least 20 on page 1: http://groups.google.com/group/comp.lang.python/topics Mike From rantingrick at gmail.com Tue Jan 27 10:17:38 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:17:38 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> Message-ID: <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> I also looked at Guido's profile and he has not posted a message here since 2000. WOW! I know he way ahead of "us" here but why has he not drooped in for a chat with the python community? Matz(the creator of Ruby), is a regular at comp.lang.ruby. This makes me wonder if Guido thinks comp.lang.python is a dead Parrot (but there could be other reasons?) From mail at microcorp.co.za Tue Jan 27 10:29:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 17:29:37 +0200 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> Message-ID: <004e01c98095$f90f9440$0d00a8c0@hendrik> "Jean-Paul Calderone" wrote: 8<------------------------------ > ....... Setting the > SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, > though). Why not? I have been merrily setting it, and I have not noticed anything weird. (yet) - Hendrik From gil.shinar at gmail.com Tue Jan 27 10:34:29 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 07:34:29 -0800 (PST) Subject: Process crash with no reason References: Message-ID: On Jan 27, 2:10?pm, Tim Golden wrote: > gil.shi... at gmail.com wrote: > > On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>> Hi All, > >>> I'm running a program that is acting as a nice interface to sybase' > >>> replication server. The program is using the cherrypy web service for > >>> the GUI. The process is crashing every few days with no reason. In the > >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > >>> TraceBack python's message. This program is running on solaris 9 > >>> machine. > >>> Where can I see or what can I do in order to find out what causes the > >>> process to crash? > >>> I have tried simulating a "traceBack" message and I could see this > >>> traceback message in one of the log files I'm using. When the process > >>> crashes without my help, I don't have a clue. > >>> Let me know if you need any other info > >> Although Python isn't immune to fatal errors like you describe, I'd ? > >> immediately suspect a 3rd-party module instead, esp. one written in C ? > >> or C++. Are you using anything like that? > > > No I do not. > > Then how are you interacting with Sybase? > > TJG I'm using python's functions to run sybase sql commands. Thanks From fakeaddress at nowhere.org Tue Jan 27 10:35:46 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 27 Jan 2009 07:35:46 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x63k5chho.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >> An object's __dict__ slot is *not* mutable; thus we could gain some >> efficiency by protecting the object and its dict with the same lock. I >> do not see a major win in Mr. Banks' point that we do not need to lock >> the object, just its dict. > > If the dict contents don't change often, maybe we could use an > STM-like approach to eliminate locks when reading. That would of > course require rework to just about every C function that accesses > Python objects. I'm a fan of lock-free data structure and software transactional memory, but I'm also a realist. Heck, I'm one of this group's outspoken advocates of threaded architectures. Theoretical breakthroughs will happen, but in real world of today, threads are great but GIL-less Python is a loser. Wherever Python is going, let's recognize that a scripting language that rocks is better than any other kind of language that sucks. -- --Bryan From gil.shinar at gmail.com Tue Jan 27 10:39:50 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 07:39:50 -0800 (PST) Subject: Process crash with no reason References: Message-ID: <79c0e7f0-3629-4286-9dc8-4ce6bf94eac5@40g2000prx.googlegroups.com> On Jan 27, 5:00?pm, Philip Semanchuk wrote: > On Jan 27, 2009, at 7:00 AM, gil.shi... at gmail.com wrote: > > > > > On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>> Hi All, > > >>> I'm running a program that is acting as a nice interface to sybase' > >>> replication server. The program is using the cherrypy web service ? > >>> for > >>> the GUI. The process is crashing every few days with no reason. In ? > >>> the > >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get ? > >>> any > >>> TraceBack python's message. This program is running on solaris 9 > >>> machine. > >>> Where can I see or what can I do in order to find out what causes ? > >>> the > >>> process to crash? > >>> I have tried simulating a "traceBack" message and I could see this > >>> traceback message in one of the log files I'm using. When the ? > >>> process > >>> crashes without my help, I don't have a clue. > >>> Let me know if you need any other info > > >> Although Python isn't immune to fatal errors like you describe, I'd > >> immediately suspect a 3rd-party module instead, esp. one written in C > >> or C++. Are you using anything like that? > > > No I do not. > > But you're using CherryPy, aren't you? And as Tim Golden pointed out, ? > you're probably using another 3rd party lib to talk to Sybase. ISTR ? > that CherryPy is written in pure Python but if you have a database ? > adapter lib it probably isn't. > > > Is there a way to monitor who had "killed" my process? > > That's more of a Solaris question than a Python one, and I don't know ? > much about Solaris. Is there a system log where Solaris records when & ? > why it has killed errant processes? Yes I am using CherryPy. One of the developers I'm working with thinks it is a cherrypy issue. Our python process has nothing to do if cherrypy is stuck or down. But still, it is strange that there are no leftovers from the crashed process. Solaris has system logs that has nothing in them about this process. Any other suggestion will be great. Thanks From mail at microcorp.co.za Tue Jan 27 10:42:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 17:42:10 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><497ed636$0$27515$426a34cc@news.free.fr> <200901270931.11979.kyrie@uh.cu> Message-ID: <004f01c98095$f9a6a420$0d00a8c0@hendrik> "Luis Zarrabeitia" wrote: 8<------------------------ >Hehe. At the beginning of this thread, I also thought that Russ P. and Paul >Robin were the same person. I have serious problems with names. *nods in agreement, because the man's surname is Rubin, not Robin* :-) - Hendrik From rantingrick at gmail.com Tue Jan 27 10:42:41 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:42:41 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Seems like the only thing people are interested in is bickering and name calling. I noticed the post "Does Python really follow..." has over 400 post mainly from the same 10 people. Maybe this is why Guido no longer wishes to be a part of this group. Where is the sense of community here? Anybody care to correct me, because i would love to be wrong about this, but i fear i am 100% correct. From kyosohma at gmail.com Tue Jan 27 10:43:55 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 07:43:55 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: On Jan 27, 9:17?am, rantingrick wrote: > I also looked at Guido's profile and he has not posted a message here > since 2000. WOW! I know he way ahead of "us" here but why has he not > drooped in for a chat with the python community? Matz(the creator of > Ruby), is a regular at comp.lang.ruby. > > This makes me wonder if Guido thinks comp.lang.python is a dead Parrot > (but there could be other reasons?) I've seen him on the distutils list, but I think he generally keeps to the dev lists mostly. This list is for general users (i.e. mostly newbs). We do get some good discussions going on more esoteric subjects like memoization, but for the most part, it's posts like how do I do x if y is z, what's the best Python IDE, which is the best Python GUI toolkit, I hate the GIL, what's a web framework, etc. I think Guido has better things to do...and his employer probably doesn't want him spending all day answering stuff like that. Mike From benjamin.kaplan at case.edu Tue Jan 27 10:52:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 10:52:30 -0500 Subject: How many followers of comp.lang.python In-Reply-To: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 10:42 AM, rantingrick wrote: > Seems like the only thing people are interested in is bickering and > name calling. I noticed the post "Does Python really follow..." has > over 400 post mainly from the same 10 people. Maybe this is why Guido > no longer wishes to be a part of this group. Where is the sense of > community here? > > Anybody care to correct me, because i would love to be wrong about > this, but i fear i am 100% correct. there is a sense of community here. It just doesn't extend to everyone joining in the flame war. That particular thread moved from talking about difficult to read python code to a not very friendly debate about whether Python needs to have enforced data hiding to be a good language. After the first couple hundred posts and when the name calling started, I, for one, started ignoring those posts. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Tue Jan 27 10:57:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jan 2009 15:57:55 +0000 Subject: creating a pattern using a previous match and a count of the number of '('s in it In-Reply-To: <200901271202.23170.mgbg25171@blueyonder.co.uk> References: <200901271202.23170.mgbg25171@blueyonder.co.uk> Message-ID: <497F2F03.9050806@mrabarnett.plus.com> me wrote: > > I'm new to regexs and trying to get a list of all my C++ methods with balanced > parenthesis as follows. > > > #find all c++ method prototypes with a '::' in the middle > #upto and including the 1st closing parenthesis > pattern_upto_1st_closed_parenth = re.compile('\w+::\w+\([^)]*\)') > match_upto_1st_closed_parenth = > re.findall(pattern_upto_1st_closed_parenth,txt) > num_of_protos = len(match_upto_1st_closed_parenth) > > for i in range (0,num_of_protos-1): This should actually be range(0, num_of_protos). > num_of_open_parenths = match_upto_1st_closed_parenth[i].count('(') > > #expand the pattern to get all of the prototype > #ie upto the last closed parenthesis > #saying something like > pattern = re.compile(\ > 'match_upto_1st_closed_parenth[i]+\ > (([^)]*\)){num_of_open_parenths-1}'\ > ) > #==================================================================== > #HELP!!!!!! I'm not sure how to incorporate: > #1 'match_upto_1st_closed_parenth[i]' into the above extended pattern??? > #2 the count 'num_of_open_parenths' instead of a literal ??? > #==================================================================== > > > > > #======================================= > #if I could do it this sort of this would appear to offer the neatest solution > pattern_upto_last_balanced_parenthesis = re.compile(' > (\w+::\w+\([^)]*\))\ > ([^)]*\)){\1.count('(')-1} > ') > #======================================= > > Should I be using regexs to do this? > > I've only put \ line extensions to separate the pattern components to assist > readability > > Thx > > Not necessarily the best way, but: methods = [] # The pattern for the start of the method's header. start_pattern = re.compile(r'\w+::\w+\([^)]*\)') # Start at the beginning of the text. pos = 0 while True: # Search for the start of the next method's header. start_match = start_pattern.search(txt, pos) if not start_match: break # Search for the end of the method's header. end_pattern = re.compile(r'(?:[^)]*\)){%d}' % start_match.group().count('(')) end_match = end_pattern.search(txt, pos) methods.append(txt[start_match.start() : end_match.end()]) # Continue the next search from where we left off. pos = end_match.end() From rantingrick at gmail.com Tue Jan 27 10:58:58 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:58:58 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: On Jan 27, 9:43?am, Mike Driscoll wrote: > I think Guido has better things to do...and his employer probably > doesn't want him spending all day answering stuff like that. > Mike I totally agree, and i would never expect him to field noob questions but i just thought it odd he has not dropped by in over 9 years. I have seen his blog but i wonder why he does not blog here. Seems like the best place in the world to get feedback from Python users is here. He could start some very interesting subjects. To at least, this medium is more of a "personal" exchange, than a blog. From philip at semanchuk.com Tue Jan 27 10:59:55 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 10:59:55 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: On Jan 27, 2009, at 10:34 AM, gil.shinar at gmail.com wrote: > On Jan 27, 2:10 pm, Tim Golden wrote: >> gil.shi... at gmail.com wrote: >>> On Jan 26, 8:40 pm, Philip Semanchuk wrote: >>>> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>>>> Hi All, >>>>> I'm running a program that is acting as a nice interface to >>>>> sybase' >>>>> replication server. The program is using the cherrypy web >>>>> service for >>>>> the GUI. The process is crashing every few days with no reason. >>>>> In the >>>>> log I can see INFO and DEBUG (No ERROR) log lines and I do not >>>>> get any >>>>> TraceBack python's message. This program is running on solaris 9 >>>>> machine. >>>>> Where can I see or what can I do in order to find out what >>>>> causes the >>>>> process to crash? >>>>> I have tried simulating a "traceBack" message and I could see this >>>>> traceback message in one of the log files I'm using. When the >>>>> process >>>>> crashes without my help, I don't have a clue. >>>>> Let me know if you need any other info >>>> Although Python isn't immune to fatal errors like you describe, I'd >>>> immediately suspect a 3rd-party module instead, esp. one written >>>> in C >>>> or C++. Are you using anything like that? >> >>> No I do not. >> >> Then how are you interacting with Sybase? > > I'm using python's functions to run sybase sql commands. Can you give a short code sample? I'm unaware of how one would use the standard Python library to talk to Sybase, unless Sybase has a raw socket interface or some such. From invalid at invalid Tue Jan 27 11:05:15 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 27 Jan 2009 10:05:15 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On 2009-01-27, Lie Ryan wrote: > From the little I know on electronics, a simple, single > transistor would (almost) immediately switch from > on-to-off-to-on depending on the voltage of the control pin (I > think it was the middle pin). I was suggesting this > simplistic hack because as far as I comprehend the OP's need, > he only need on-off switch instead of a complex multiple > output bits. The audio output jack outputs AC (alternating current). If you put AC into a transistor, you get AC out. Hence the need for a rectifier/detector to convert the AC signal into a DC level. To reliably get an on-off state from an analog DC level, you need something with some hystersis (e.g. a comparitor). Depending on the requirements it may possible to do impliment a comparitor with hysteresis using a single transistor. If you're looking for a digital output signal whose DC level you can contol, then either the printer port or the serial port is a better option than using the sound-card's line-out which is an analog AC output. >>> I don't know how much power can be pulled from jack out, >> >> Almost none, and what's there is very low voltage. > > That's why the power is taken from USB port. > >>> but for a home brewn device it is still feasible to draw power >>> from USB and signal from jack out. >> >> It would probably be easier to buy a USB-parallel port chip. >> Then he's got power from the USB bus and something like 14 >> parallel I/O pins he can control. Alternatively A USB-serial >> chip will provide 2 outputs and 4 inputs. > > The idea was made on the basis that a USB microcontroller is > not used. I didn't say anything about using a USB microcontroller. There are dead-simple and cheap USB-serial and USB-parallel chips that you can buy that provide the equivalent of a serial port or parallel printer port via USB. > Getting power from USB should be much easier than getting data Using a USB-serial or USB-parallel chip isn't really much harder than getting power from the USB port, and it's simpler than building a detector/comparity circuit to connect to the audio line-out. > while the jack out can provide simple on-off signal. With the addition of a rectifier/detector and an appropriate comparitor circuit, yes. -- Grant Edwards grante Yow! Civilization is fun! at Anyway, it keeps me busy!! visi.com From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 11:12:18 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 17:12:18 +0100 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: <497f3260$0$3671$426a74cc@news.free.fr> rantingrick a ?crit : > On Jan 27, 9:43 am, Mike Driscoll wrote: > >> I think Guido has better things to do...and his employer probably >> doesn't want him spending all day answering stuff like that. >> Mike > > I totally agree, and i would never expect him to field noob questions > but i just thought it odd he has not dropped by in over 9 years. All you can say is that he didn't *post* here (at least under his real identity...) for the 9 past years - this doesn't mean he never *reads* (and this, you just have no way to know). From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 11:26:20 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 17:26:20 +0100 Subject: How many followers of comp.lang.python In-Reply-To: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: <497f35aa$0$6733$426a74cc@news.free.fr> rantingrick a ?crit : > Seems like the only thing people are interested in is bickering and > name calling. I noticed the post "Does Python really follow..." has > over 400 post mainly from the same 10 people. There are occasionally such kind of threads, indeed. And, as Mike mentionned, the usual FAQs (some of them twice or more each week, year after year). And sometimes more interesting questions - but that does not necessarily makes long thread, so they perhaps are too low for your radar. > Maybe this is why Guido > no longer wishes to be a part of this group. I've been lurking here for years (about early 2000 IIRC), and don't remember a single post from the BDFL here. But: > Where is the sense of > community here? If you set the occasional trolls aside, this group is usually newbie-friendly and helpful one. You'll find quite a few posts by long-time, experienced and talented Python programmers (and core developpers). As far as I'm concerned, I learned (and I'm still learning) quite a lot here. Please visit comp.databases or comp.lang.javascript for really unfriendly and unhelpful places where few happens except "bickering and name-calling". > Anybody care to correct me, because i would love to be wrong about > this, but i fear i am 100% correct. Well, why don't you just try and post a couple practical questions here? From koranthala at gmail.com Tue Jan 27 11:27:04 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 27 Jan 2009 08:27:04 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <6d674190-4692-42e0-91ba-0ca5ca4dd0d3@n33g2000pri.googlegroups.com> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: > >Twisted, being twisted in its behavior is causing quite a lot of > >confusion in design decisions. > > I'm not sure I agree with your premise. ;) > > > > >I will put forward a comparison of reactor and non-reactor patterns. > >The code is not exact - whatever is shown is the gist of it. > > >For example, a message handler - in a usual scenario: > >class messageHandler: > > ? def run(): > > ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? if not msg.send(): > > ? ? ? ? ? ? self.handle_failure() > > >To handle parallel execution, we will have to use threads, but the > >code flow is similar. > > >How do we do the same in a reactor pattern (Twisted)? > >msg.send will cause a deferred to be raised - the failure, if it > >happens will happen much later. > >i.e. other than sending messageHandler object in msg.send(), I cannot > >see any mechanism of running handle_failure. > > >In Twisted: > >class messageHandler: > > ? def run(): > > ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? msg.send(self): > > >class msgClass: > > ? ?def send(o): > > ? ? ? ?d = deferred.addCallBack(success_handler, o).addErrBack > >(failure_handler, o) > > > ? ?def failure_handler(o): > > ? ? ? ?o.handle_failure() > > This doesn't look like a correct or faithful translation of the original. > Here are two possibilities. ?First: > > ? ? class messageHandler: > ? ? ? ? def run(): > ? ? ? ? ? ? msg = self.get_next_msg() > ? ? ? ? ? ? d = msg.send() > ? ? ? ? ? ? def cbSendFailed(result): > ? ? ? ? ? ? ? ? if not result: > ? ? ? ? ? ? ? ? ? ? self.handle_failure() > ? ? ? ? ? ? d.addErrback(cbSendFailed) > ? ? ? ? ? ? return d > > Next: > > ? ? class messageHandler: > ? ? ? ? @inlineCallbacks > ? ? ? ? def run(): > ? ? ? ? ? ? msg = self.get_next_msg() > ? ? ? ? ? ? if not (yield msg.send()): > ? ? ? ? ? ? ? ? self.handle_failure() > > These are both just straight translations from your version so as to > be able to handle a Deferred from `msg.send?. > > >Basically, what I find is that a lot of functional encapsulation is > >now lost by following reactor pattern. handle_failure is > >messageHandlers code and makes for pretty viewing if called from > >inside messageHandler itself. But, due to the twisted nature of > >reactor pattern, the msg Class - who is functionally a lower class to > >messageHandler invoking messageHandler's code. > > You don't need to lose anything. ?I don't know what your motivation was > for re-arranging the code when you wrote the Twisted version, but it doesn't > appear to have been necessary. > > >Is there a way to solve this in a more beautiful way? Am I missing > >something here? > > Hope this helps, > > Jean-Paul Thank you Jean-Paul. My code is more complex than what I have mentioned. When I mentioned msg.send, the msg object actually gets the data from DB etc to send. And there are many other items being done. I will try to see whether I can change the code to incorporate what you mentioned. I rewrote most of my code after learning just raw deferreds - I had planned to study inlineCallbacks - but then it slipped my mind - now it has come to bit me. :-( From lists at pern.co.uk Tue Jan 27 11:27:27 2009 From: lists at pern.co.uk (David Anderson) Date: Tue, 27 Jan 2009 16:27:27 +0000 Subject: Pexpect and telnet not communicating properly Message-ID: <497f35ef$0$30312$da0feed9@news.zen.co.uk> I am trying to automate the following session - to talk to my router: ======================= telnet speedtouch Trying 192.168.1.254... Connected to speedtouch. Escape character is '^]'. Username : Administrator Password : ------------------------------------------------------------------------ ______ SpeedTouch 780 ___/_____/\ / /\ 6.1.7.2 _____/__ / \ _/ /\_____/___ \ Copyright (c) 1999-2006, THOMSON // / \ /\ \ _______//_______/ \ / _\/______ / / \ \ / / / /\ __/ / \ \ / / / / _\__ / / / \_______\/ / / / / /\ /_/______/___________________/ /________/ /___/ \ \ \ \ ___________ \ \ \ \ \ / \_\ \ / /\ \ \ \ \___\/ \ \/ / \ \ \ \ / \_____/ / \ \ \________\/ /__________/ \ \ / \ _____ \ /_____\/ \ / /\ \ /___\/ /____/ \ \ / \ \ /___\/ \____\/ ------------------------------------------------------------------------ _{Administrator}=>? Following commands are available : help : Displays this help information menu : Displays menu ? : Displays this help information exit : Exits this shell. .. : Exits group selection. saveall : Saves current configuration. ping : Send ICMP ECHO_REQUEST packets. traceroute : Send ICMP/UDP packets to trace the ip path. Following command groups are available : firewall service autopvc connection cwmp dhcp dns dsd dyndns eth adsl atm config debug env expr grp hostmgr ids igmp interface ip ipqos label language mbus memm mlp nat ppp pptp script snmp sntp software system systemlog upgrade upnp user voice wireless {Administrator}=>exit ======================== I am using the following code: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn('telnet 192.168.1.254') fout = file('mylog.txt','w') child.logfile = fout child.expect('sername : ') child.sendline('Administrator') child.expect('assword : ') child.sendline('') child.expect('_{Administrator}=>') child.sendline('?') child.expect('_{Administrator}=>') child.expect('exit') ======================== This times out after child.sendline('Administrator') mylog.txt contains: Trying 192.168.1.254... Connected to 192.168.1.254. Escape character is '^]'. Username : Administrator Administrator ======================== Can anyone help me in finding out what I am doing wrong? Regards David From claird at lairds.us Tue Jan 27 11:29:27 2009 From: claird at lairds.us (Cameron Laird) Date: Tue, 27 Jan 2009 16:29:27 +0000 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: <7cp356-c7d.ln1@lairds.us> In article <8692c77c-0498-4c68-940f-e4d4427f3f08 at x37g2000yqj.googlegroups.com>, rantingrick wrote: >Seems like the only thing people are interested in is bickering and >name calling. I noticed the post "Does Python really follow..." has >over 400 post mainly from the same 10 people. Maybe this is why Guido >no longer wishes to be a part of this group. Where is the sense of >community here? > >Anybody care to correct me, because i would love to be wrong about >this, but i fear i am 100% correct. Which "this"? Are you asking for evidence that more than ten people regularly read comp.lang.python, OR that there is traffic in comp.lang.python other than bickering and name-calling? My own rough estimate of readership is at least 4,000. If motivated, one could refine the figure, I'm confident). From jcd at sdf.lonestar.org Tue Jan 27 11:37:35 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 27 Jan 2009 11:37:35 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <1233074255.4143.15.camel@aalcdl07.lib.unc.edu> On Sun, 2009-01-25 at 14:28 -0800, gert wrote: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: > > > raise ValueError(errmsg("Expecting property name", s, end)) > > >http://docs.python.org/library/json.html > > > What am I doing wrong ? > > > > try this > > v = json.loads('{"test":"test"}') > > > > JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not that hard, but it does add a noticeable level of complexity to the process. In JSON, you simply tell the parser, "if you see a double-quote character, we're now parsing a string. When you see another (unescaped) double-quote character, the string is done. The equivalent version for your extended JSON would say, "if you see a quote character of either kind, we're parsing a string. When you see another (unescaped) quote character of either kind, the string is done." But that doesn't work, because it would allow {'test": "test'}. So the parser has to remember which quote character is being used, and require those characters to be escaped, and not the other (but then does "te \'st" render as r"te'st" or r"te\'st"?) and only close the string when the appropriate quote is found. Not an impossible task, but certainly more complex than the current parsing requirements for JSON. Cheers, Cliff From Scott.Daniels at Acm.Org Tue Jan 27 11:40:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 27 Jan 2009 08:40:27 -0800 Subject: Counting number of objects In-Reply-To: References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Kottiyath wrote: > So, in a higher level class, have a weakref list which contains a > reference to each person. Total count will be len(list) at any time. > > Now, I couldnt find a weakref list - so I am using WeakKeyDictionary > with the value as None - since len(dict) also should give me the data I typically use a WeakValueDictionary, with the key id(obj). ... > Now, the only two operations that I am doing are -> > __init__: > d = weakref.WeakKeyDictionary() > > method y: > x = aa() > d[x] = None > > method z: > total = len(d) At least at one point, the WeakValueDictionary was more stable. I don't remember the details, but I remember my work-around. If you do have troubles, try using almost the same code you now use, but substitute for the obvious lines above: d = weakref.WeakValueDictionary() and d[id(x)] = x --Scott David Daniels Scott.Daniels at Acm.Org From jay.amorin at gmail.com Tue Jan 27 11:41:11 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Wed, 28 Jan 2009 00:41:11 +0800 Subject: [xlrd] sanitize the output and store in a 2d arrays Message-ID: Hi gurus, Script: #!/usr/bin/python import xlrd, sys def main(toParse): workBook = xlrd.open_workbook(toParse) mySheet = workBook.sheet_by_index(0) for rownum in range(mySheet.nrows): print mySheet.row_values(rownum) if __name__ == '__main__': if len(sys.argv) < 2: sys.stderr.write("Usage: %s EXCEL.XLS\n" % (sys.argv[0])) else: main(sys.argv[1]) Output: myuser at testsvr:~> ./parse.py test.xls *[u'*thisislineone*'*, 343*.0]* *[u'*thisislinetwo*'*, 344*.0]* *[u'*thisislinethree*'*, 345*.0]* This is the content of my test.xls: thisislineone 343 thisislinetwo 344 thisislinethree 345 How do i remove the bold part of the output (*[u'*. *'* and *.0]* and store the output in a 2 dimensional array? Many thanks. PythonNewbie, Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Jan 27 11:42:52 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 16:42:52 +0000 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? References: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87skn41z03.fsf.mdw@metalzone.distorted.org.uk> Bryan Olson writes: > Mark Wooding wrote: >> There's a full description of it in 5.4.3 in the Language Reference, but >> apparently not indexed. > > So I guess this means I can duck out of writing up a lecture on my own > understanding of Python's extended call syntax. Great. > > I think I grock the extended call syntax, and when the question came > up I was surprised not to be able to find where I learned it. Mark, > where exactly does one look to see this "full description"? I typoed, sorry! I should have written 5.3.4: http://www.python.org/doc/2.5/ref/calls.html The description of the fancy * and ** syntax starts with `If the syntax ``*expression'' appears in the function call...'. -- [mdw] From icanbob at gmail.com Tue Jan 27 11:48:37 2009 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 27 Jan 2009 08:48:37 -0800 (PST) Subject: significant release for SIMPL project's Python extension Message-ID: The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the simplicity and power of the Send/Receive/Reply messaging (first pioneered by QNX) to the Linux world. SIMPL modules are themselves Linux executables and can be written in any number of languages now (C, C++, Tcl/Tk and Python). A SIMPL application consists of one or more of these modules interacting in a single SIMPL sandbox. A SIMPL application can consist of SIMPL modules written in a mixture of supported languages. In addtion SIMPL applications can be spread across a network seamlessly through the use of TCP/IP or RS232 surrogates. In most cases this redeployment can occur without an code change or recompilation. Python is one of the newer languages to be added to the SIMPL family, but it is already attracting significant attention. An online course on SIMPL-Python offered for no fees by iCanProgram (http:// www.icanprogram.com/06py/main.html) consistently gets the highest number of web hits in any given month. Up until now SIMPL-Python modules could already be built for deployment on a Linux OS. Now SIMPL-Python modules can be written for a non Linux OS and interact with a SIMPL application using the tclSurrogate (TCP/IP) protocol which SIMPL supports. This means that a Python script running under Windows can now participate seamlessly in a SIMPL application running on a Linux network. In addition SIMPL-Python web scripts can also now participate seamlessly in a SIMPL application. This feature greatly extends the reach of SIMPL-Python into the realm of web interfaces and web applications. The easiest way to get aquainted with the SIMPL-Python toolset is to download one of its self installing archives for Linux. These are safely deployed in /tmp to allow full exploration with an option to permanently install the release in a directory of your choosing. SIMPL-Python self installing archive - http://www.icanprogram.com/simpl/python.self.html SIMPL-Python course self installing archive - http://www.icanprogram.com/pythoncourse.self.html the SIMPL project team From mail at microcorp.co.za Tue Jan 27 12:05:00 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 19:05:00 +0200 Subject: Exec woes Message-ID: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> It starts with the conspiracy of silence at the interactive prompt: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. IDLE 1.1.3 ==== No Subprocess ==== >>> help(exec) SyntaxError: invalid syntax >>> Its the same under Linux SuSe, Python 2.5.1. I think this is a BUG. Anyway, my real problem looks like this: >>> def Somefunc(): def excrescence(): exec('BUILD = "someString"') return BUILD SyntaxError: unqualified exec is not allowed in function 'excrescence it is a nested function (, line 3) >>> Now this works if it is not nested, and it works if it is a method in a class. Why the complaint about the nestedness? I would appreciate it if someone would explain, as the library reference simply says that it would default to globals() and locals(), which also does not seem to happen - also true for a "nested" eval after a compile - you have to specify the globals() or you get a NameError - global BUILD is not defined. So there is some namespace thing happening that is too subtle for me, and I would like to know what "unqualified" means in the above message, and what one must do to "qualify" the statement, if that is what is needed. The original thing came up because I really need relative imports - I have some version.py files in various directories that have a single line in them that looks like the string I am feeding the exec. By the way, execfile works in this situation, but also only if you specify globals() explicitly. I would really like to understand what is going on. - Hendrik From mdw at distorted.org.uk Tue Jan 27 12:05:24 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 17:05:24 +0000 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: Message-ID: <87ocxs1xyj.fsf.mdw@metalzone.distorted.org.uk> Laszlo Nagy writes: > I have a program that uses socket.bind() and socket.listen() > frequently. After that program stops, it is not able to bind() again for a > while: This is the usual TIME-WAIT problem. The TCP protocol requires one end of the connection (whichever actually started the close) to keep a record of it for a while after it closes, in order to avoid confusion caused by old packets. > The problem with this, is that this server program SOMETIMES need to be > restarted very quickly. The usual solution is to set the SO_REUSEADDR socket option before binding. This is safe for listening sockets. Here's an interactive session. In [1]: import socket as S In [2]: def make_server_socket(): ...: sk = S.socket(S.AF_INET, S.SOCK_STREAM) ...: sk.bind(('', 12345)) ...: sk.listen(5) ...: return sk ...: In [3]: def serve_client(sk): ...: (nsk, addr) = sk.accept() ...: nsk.send('Hello.\n') ...: nsk.close() ...: In [4]: sk = make_server_socket() In [5]: serve_client(sk) (At this point, I connect to the server in another terminal.) In [6]: sk.close() In [7]: sk = make_server_socket() [...] error: (98, 'Address already in use') And to confirm that it's TIME-WAIT that's stopping us: [ponder ~]netstat -n | grep 12345 tcp 0 0 127.0.0.1:12345 127.0.0.1:49988 TIME_WAIT If I change make_server_socket, then everything works fine. In [8]: def make_server_socket(): ...: sk = S.socket(S.AF_INET, S.SOCK_STREAM) ...: sk.setsockopt(S.SOL_SOCKET, S.SO_REUSEADDR, 1) ...: sk.bind(('', 12345)) ...: sk.listen(5) ...: return sk ...: In [10]: sk = make_server_socket() In [11]: serve_client(sk) In [13]: sk.close() In [14]: sk = make_server_socket() Done. If you try this, note that both the old, closed socket /and/ the new one must have SO_REUSEADDR set on them. If you try this interactively, you'll have to wait for the non-SO_REUSEADDR socket to leave TIME-WAIT before you can bind. But once you've done that, it'll work fine from then on. -- [mdw] From george.trojan at noaa.gov Tue Jan 27 12:06:52 2009 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 27 Jan 2009 17:06:52 +0000 Subject: Pexpect and telnet not communicating properly In-Reply-To: <497f35ef$0$30312$da0feed9@news.zen.co.uk> References: <497f35ef$0$30312$da0feed9@news.zen.co.uk> Message-ID: David Anderson wrote: > I am trying to automate the following session - to talk to my router: > > ======================= > telnet speedtouch > Trying 192.168.1.254... > Connected to speedtouch. > Escape character is '^]'. > Username : Administrator > Password : > ------------------------------------------------------------------------ > > ______ SpeedTouch 780 > ___/_____/\ > / /\ 6.1.7.2 > _____/__ / \ > _/ /\_____/___ \ Copyright (c) 1999-2006, THOMSON > // / \ /\ \ > _______//_______/ \ / _\/______ > / / \ \ / / / /\ > __/ / \ \ / / / / _\__ > / / / \_______\/ / / / / /\ > /_/______/___________________/ /________/ /___/ \ > \ \ \ ___________ \ \ \ \ \ / > \_\ \ / /\ \ \ \ \___\/ > \ \/ / \ \ \ \ / > \_____/ / \ \ \________\/ > /__________/ \ \ / > \ _____ \ /_____\/ > \ / /\ \ /___\/ > /____/ \ \ / > \ \ /___\/ > \____\/ > > ------------------------------------------------------------------------ > _{Administrator}=>? > Following commands are available : > > help : Displays this help information > menu : Displays menu > ? : Displays this help information > exit : Exits this shell. > .. : Exits group selection. > saveall : Saves current configuration. > ping : Send ICMP ECHO_REQUEST packets. > traceroute : Send ICMP/UDP packets to trace the ip path. > > Following command groups are available : > > firewall service autopvc connection cwmp > dhcp dns dsd dyndns eth > adsl atm config debug env > expr grp hostmgr ids igmp > interface ip ipqos label language > mbus memm mlp nat ppp > pptp script snmp sntp software > system systemlog upgrade upnp user > voice wireless > > {Administrator}=>exit > > ======================== > > I am using the following code: > > #!/usr/bin/env python > > import pexpect > import sys > > child = pexpect.spawn('telnet 192.168.1.254') > fout = file('mylog.txt','w') > child.logfile = fout > > child.expect('sername : ') > child.sendline('Administrator') > child.expect('assword : ') > child.sendline('') > > > child.expect('_{Administrator}=>') > child.sendline('?') > child.expect('_{Administrator}=>') > child.expect('exit') > > ======================== > > This times out after child.sendline('Administrator') > > mylog.txt contains: > Trying 192.168.1.254... > > Connected to 192.168.1.254. > > Escape character is '^]'. > > Username : Administrator > Administrator > ======================== > > Can anyone help me in finding out what I am doing wrong? > > Regards > David To debug, add lines print self.before print self.after after each child.expect(). Also, add timeout=2 to the argument list of child.expect(). I wrote a thin wrapper that serves me well, at least till now. class Connection(object): '''Establishes connection to Cisco modem server. A wrapper around fdexpect spawn. ''' def __init__(self, host, port, user, passwd, **kwds): self.pipe = None self.socket = None self.host = host self.port = port self.user = user self.passwd = passwd self.logger = kwds.get('logger') self._last = '' def __getattr__(self, name): if name not in ['open', 'close', 'send', 'sendline', 'expect']: return getattr(self.pipe, name) def open(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((self.host, self.port)) self.pipe = pexpect.fdspawn(self.socket) self.expect('Username:', timeout=2) self.sendline(self.user) self.expect('Password:', timeout=1) self.sendline(self.passwd) self.send('ATZ\r') self.expect('OK', timeout=1) def send(self, s): self._last = s return self.pipe.send(s) def sendcr(self, s): self._last = s return self.pipe.send(s+'\r') def sendline(self, s): self._last = s return self.pipe.sendline(s) def expect(self, pattern, **kwds): rc = self.pipe.expect(pattern, **kwds) if self.logger: self.logger.debug('sent "%s", received\n\t1. before "%s"\n\t' \ '2. match "%s"\n\t3. after "%s"\n', self._last, self.before, self.match.group(0), self.after) return rc def close(self): self.pipe.close() self.pipe = None self.socket.close() self.socket = None George From michele.simionato at gmail.com Tue Jan 27 12:07:29 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 27 Jan 2009 09:07:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 21, 2:11?am, Mark Wooding wrote: > CLOS is much more complex and dynamic than Python's object system; > but it can be compiled very aggressively. I agree that CLOS is complex and that it can be compiled very aggressively, but I do not think that it is more dynamic than Python. What feature are you alluding to? Multimethods? There are many Python implementations of them, they are just not in the standard library. Or are you referring to interactive facilities, such as the one discussed in this recipe http://code.activestate.com/recipes/160164 ? From R.Brodie at rl.ac.uk Tue Jan 27 12:11:59 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 27 Jan 2009 17:11:59 -0000 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com><9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com><6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> <018d0300$0$20629$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:018d0300$0$20629$c3e8da3 at news.astraweb.com... > Supposedly "every browser" (what, all of them?) already support a de > facto extension to the JSON standard, allowing more flexible quoting. That's a consequence of JSON being a subset of Javascript syntax, so you can just call eval() on it, if you're willing. When you use a library, it's pot luck whether it accepts JSON-soup or not. From invalid at invalid Tue Jan 27 12:13:28 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 27 Jan 2009 11:13:28 -0600 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: On 2009-01-27, Bruno Desthuilliers wrote: > Please visit comp.databases or comp.lang.javascript for really > unfriendly and unhelpful places where few happens except > "bickering and name-calling". I've always found comp.lang.c to be a rather dangerous place as well. Of the newsgroups I read, c.l.python is probably the most friendly and has one of the highest S/N ratios. People who would have been roasted alive in other newsgroups for their laziness or presumptuousness get surprisingly gentle treatment in c.l.python. I do know of a few low-volume mailing lists that are probably as good, but for a Usenet news group with any volume at all, c.l.pythong is exceptionally good. -- Grant Edwards grante Yow! I wonder if I should at put myself in ESCROW!! visi.com From rt8396 at gmail.com Tue Jan 27 12:19:36 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 09:19:36 -0800 (PST) Subject: IDLE 3000 (suggested improvements) Message-ID: Proposal: OK, so the python language has officially moved into the next level. I look at IDLE and think, hmm great IDE but it could really use a spit shining. So here is a very simple script showing my ideas to improve IDLE. Reason for change: The text widget and the prompt(>>>) should be separated. Trying to write a conditional in the interactive IDLE is a real pain. Not to mention that when you copy code from Interactive IDLE to the IDLE editor window the indention is eight spaces instead four and you've got that prompt(>>>) stuck in there. I have a solution for the problem though. I hope you are using fixed-width font Lst|<----- Text Widget ---->| | | >>>|if this: | ...| if that: | ...| ... | ...| elif that: | ...| ... | ...| else: | ...| ... | >>>| | >>>|x = 10 | >>>| | Basically you have a Listbox on the left for the prompt and a Text on the right. Disable the Listbox highlight and key press events and now we have a very friendly interactive IDLE! No more prompt hijacking your snippets, and no more eigtht space indention! Hip-Hip-Hooray! #-- Start Script --# from Tkinter import * import tkMessageBox as MB class CMD(Toplevel): def __init__(self, master): Toplevel.__init__(self, master) self.master = master self.startidx = '1.0' self.backidx = '1.0' self.title('IDLE 3000') self.listbox = Listbox(self, width=3, relief=FLAT, font= ('Courier New',12), takefocus=0) self.listbox.pack(fill=Y, side=LEFT) self.listbox.insert(0, '>>>') self.text = Text(self, relief=FLAT, spacing3=1, wrap=NONE, font=('Courier New',12)) self.text.pack(fill=BOTH, side=LEFT, expand=1) self.text.config(width=50, height=20) self.text.focus_set() self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.text.bind('' , lambda e: "break")#pageup self.text.bind('' , lambda e: "break")#pagedown self.text.bind('' , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind("" , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind("" , lambda e: "break") self.text.bind("" , self.onUp) self.text.bind("" , self.onDown) self.text.bind("" , self.onTab) self.text.bind("" , self.onReturn) self.text.bind("", self.onBackSpace) self.protocol("WM_DELETE_WINDOW", self.onQuit) self.lift(master) self.master.withdraw() def fix_index(self, chars): self.backidx = '%d.0' %(int(self.backidx.split('.')[0])+1) self.text.insert(END, '\n') self.text.mark_set(INSERT, END) self.text.see(INSERT) self.listbox.insert(END, chars) self.listbox.see(self.listbox.size()) def onQuit(self): self.grab_release() self.master.destroy() def onTab(self, event=None): curline, cursor = self.text.index(INSERT).split('.')[0]+'.0', self.text.index(INSERT) self.text.insert(INSERT, ' ') return "break" def onDown(self, event): i = self.text.index(INSERT+'+1l') #;print 'New index: ', i self.text.mark_set(INSERT, i) self.text.see(i) self.listbox.see(int(i.split('.')[0])-1) return "break" def onUp(self, event=None): i = self.text.index(INSERT+'-1l') #;print 'New index: ', i self.text.mark_set(INSERT, i) self.text.see(i) self.listbox.see(int(i.split('.')[0])-1) return "break" def onBackSpace(self, event=None): if self.text.compare(self.text.index(INSERT), '!=', self.backidx): self.text.delete(self.text.index(INSERT+'-1c')) return "break" def onReturn(self, event=None): curline, cursor = self.text.index(INSERT).split('.')[0]+'.0', self.text.index(INSERT) text = self.text.get(self.startidx, END).strip() if self.text.compare(curline, '<', self.startidx):#'Out Of Zone' self.text.mark_set(INSERT, END+'-1c') self.text.see(INSERT) self.listbox.see(END) elif '.0' in cursor: #nothing typed on this line, try to exec command cmd = text.rstrip('\n') try: exec(cmd) except: self.master.bell() print '%s\n%s\n%s' %(sys.exc_traceback, sys.exc_type, sys.exc_value) finally: self.fix_index('>>>') self.startidx = self.text.index(INSERT) elif text != '':#something typed self.fix_index('...') else: #insert newline self.fix_index('>>>') return "break" if __name__ == '__main__': print 'main' root = Tk() MB.showinfo('IDLE 3000 Introduction',''' This Demo shows how i think the standard IDLE should behave. You will notice the prompt is outside of the text widget. This keeps the prompt from hijacking your code snippits when you copy-paste to the main editor window. This also keeps all indention at the Python recommended four spaces. Please note this demo is to only show the layout, it does not include syntax highlight, auto-tab, auto-dedent, or any other feature. This is not even the correct way to write a good editor. My only intention is to show a more user friendly layout have fun :) ''') cmd = CMD(root) root.mainloop() #-- End Script --# Issue #2: When you press MMB and there is a highlighted selection in the text it gets pasted over and over again @ the insertion cursor. This can be aggravating, and turn a clean script into a bowl of "Cheerios" breakfast cereal in no time. From vincent at vincentdavis.net Tue Jan 27 12:28:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:28:47 -0700 Subject: regular expression, help Message-ID: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line I want to get the number "39-034-15-009" after "Parcel ID:" The number will be different each time but always the same format. I think I can match "Parcel ID:" but not sure how to get the number after. "Parcel ID:" only occurs once in the document. is this how i need to start? pid = re.compile('Parcel ID: ') Basically I am completely lost and am not finding examples I find helpful. I am getting the html using myurl=urllib.urlopen(). Can I use RE like this thenum=pid.match(myurl) I think the two key things I need to know are 1, how do I get the text after a match? 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl as the string in a RE, thenum=pid.match(myurl) Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Tue Jan 27 12:29:17 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:29:17 -0700 Subject: regular expression, help Message-ID: <77e831100901270929j5c26de84g56a1ff04f872b2e5@mail.gmail.com> I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line I want to get the number "39-034-15-009" after "Parcel ID:" The number will be different each time but always the same format. I think I can match "Parcel ID:" but not sure how to get the number after. "Parcel ID:" only occurs once in the document. is this how i need to start? pid = re.compile('Parcel ID: ') Basically I am completely lost and am not finding examples I find helpful. I am getting the html using myurl=urllib.urlopen(). Can I use RE like this thenum=pid.match(myurl) I think the two key things I need to know are 1, how do I get the text after a match? 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl as the string in a RE, thenum=pid.match(myurl) Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 27 12:29:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 15:29:24 -0200 Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas escribi?: > Hello all, This is my first post to this mailing list. Our requirement > is to invoke a Tkinter python panel from a C++ GUI app where both GUI > windows would run in 2 separate threads. We have written a sample PyQt > application which calls this Tk panel using something like this:class > TkPanel(threading.Thread):def run(self): # call showPaneldef > showPanel():# create window = Tk.Tk() window.mainloop()def start():t = > TkPanel()t.start()Now we call this from our main python code:def > startPanel(self): import tkPanel tkPanel.start() # this calls > tkwindow.mainloop() in a separate thread.This works absolutely fine when > the invoking app is Python. From the above description I don't see where PyQt is involved. Do you really want to mix Qt and Tk in the same application? I don't think they could coexist... -- Gabriel Genellina From thorsten at thorstenkampe.de Tue Jan 27 12:33:58 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 18:33:58 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: * John Machin (Tue, 27 Jan 2009 05:31:42 -0800 (PST)) > Nobody is upset, and nobody has "gone off on a tear". The point about > the "Windows example" is that the docs say in a close-to-screamingly- > obvious manner that /options are not supported, no matter what > religion uses them. It was not, and still is not, apparent what you > really wanted. We're all patiently waiting for you to rephrase the > question(s). Amen, brother. Thorsten From lists at cheimes.de Tue Jan 27 12:34:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jan 2009 18:34:41 +0100 Subject: Exec woes In-Reply-To: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen schrieb: > It starts with the conspiracy of silence at the interactive prompt: > > Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > > IDLE 1.1.3 ==== No Subprocess ==== >>>> help(exec) > SyntaxError: invalid syntax > Its the same under Linux SuSe, Python 2.5.1. > > I think this is a BUG. No, it's the way exec is defined. exec is not a function, it's a statement. "help(exec)" raises a syntax error like "help(if)" or "help(while)" would raise a syntax error, too. Christian From steve at holdenweb.com Tue Jan 27 12:37:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 12:37:02 -0500 Subject: optparse with numpy.array? In-Reply-To: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Message-ID: Johan Ekh wrote: > Thanks, > James I will try your suggestion! > Robert, what mean with "interactively" is that i would like to create an > array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or > by reading a file with values etc., and then execute my program with > "myprog -m m_i" and thus pass the array "m_i" to my program. > > This is just an example. I would like to pass several arrays. My program > will be wrapped inside a loop and the arrays are updated > in each loop. > The bottom line is that there is no "natural" way to pass Python objects through the command line, so you will need to find a natural way to represent the objects as character strings, and then extend the optparse module to recognize that type. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Tue Jan 27 12:39:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jan 2009 17:39:30 +0000 Subject: regular expression, help In-Reply-To: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> References: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> Message-ID: <497F46D2.4000608@mrabarnett.plus.com> Vincent Davis wrote: > I think there are two parts to this question and I am sure lots I am > missing. I am hoping an example will help me > I have a html doc that I am trying to use regular expressions to get a > value out of. > here is an example or the line > > I want to get the number "39-034-15-009" after "Parcel ID:" The number > will be different each time but always the same format. > I think I can match "Parcel ID:" but not sure how to get the number > after. "Parcel ID:" only occurs once in the document. > > is this how i need to start? > pid = re.compile('Parcel ID: ') > > Basically I am completely lost and am not finding examples I find helpful. > > I am getting the html using myurl=urllib.urlopen(). > Can I use RE like this > thenum=pid.match(myurl) > > > I think the two key things I need to know are > 1, how do I get the text after a match? > 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl > as the string in a RE, thenum=pid.match(myurl) > Something like: pid = re.compile(r'Parcel ID: (\d+(?:-\d+)*)') myurl = urllib.urlopen(url) text = myurl.read() myurl.close() thenum = pid.search(text).group(1) Although BeautifulSoup is the preferred solution. From vincent at vincentdavis.net Tue Jan 27 12:39:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:39:47 -0700 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <77e831100901270939x1a1232cduf4abc7f3fbb0b7ee@mail.gmail.com> Being a newbie and not aware of other good places to ask dump questions. I have been very happy with the help I have gotten. Some of the other discussions are a little interesting to me but I wonder/am grateful if these keep the knowledgeable people around so us newbies can ask questions. Since I am a beginner programer and new to python it is really help to have a place to ask quick or long questions. Books are nly so good, Google helps but it doesn't debug code for you. Thanks Vincent Davis On Tue, Jan 27, 2009 at 10:13 AM, Grant Edwards wrote: > On 2009-01-27, Bruno Desthuilliers > wrote: > > > Please visit comp.databases or comp.lang.javascript for really > > unfriendly and unhelpful places where few happens except > > "bickering and name-calling". > > I've always found comp.lang.c to be a rather dangerous place as > well. > > Of the newsgroups I read, c.l.python is probably the most > friendly and has one of the highest S/N ratios. People who > would have been roasted alive in other newsgroups for their > laziness or presumptuousness get surprisingly gentle treatment > in c.l.python. I do know of a few low-volume mailing lists > that are probably as good, but for a Usenet news group with any > volume at all, c.l.pythong is exceptionally good. > > -- > Grant Edwards grante Yow! I wonder if I > should > at put myself in ESCROW!! > visi.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Tue Jan 27 12:45:29 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:45:29 -0700 Subject: regular expression, help In-Reply-To: <497F46D2.4000608@mrabarnett.plus.com> References: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> <497F46D2.4000608@mrabarnett.plus.com> Message-ID: <77e831100901270945q4804832an253fc4c60b350241@mail.gmail.com> is BeautifulSoup really better? Since I don't know either I would prefer to learn only one for now. Thanks Vincent Davis On Tue, Jan 27, 2009 at 10:39 AM, MRAB wrote: > Vincent Davis wrote: > >> I think there are two parts to this question and I am sure lots I am >> missing. I am hoping an example will help me >> I have a html doc that I am trying to use regular expressions to get a >> value out of. >> here is an example or the line >> >> I want to get the number "39-034-15-009" after "Parcel ID:" The number >> will be different each time but always the same format. >> I think I can match "Parcel ID:" but not sure how to get the number after. >> "Parcel ID:" only occurs once in the document. >> >> is this how i need to start? >> pid = re.compile('Parcel ID: ') >> >> Basically I am completely lost and am not finding examples I find helpful. >> >> I am getting the html using myurl=urllib.urlopen(). Can I use RE like this >> thenum=pid.match(myurl) >> >> I think the two key things I need to know are >> 1, how do I get the text after a match? >> 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl >> as the string in a RE, thenum=pid.match(myurl) >> >> Something like: > > pid = re.compile(r'Parcel ID: (\d+(?:-\d+)*)') > myurl = urllib.urlopen(url) > text = myurl.read() > myurl.close() > thenum = pid.search(text).group(1) > > Although BeautifulSoup is the preferred solution. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Jan 27 12:45:48 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 27 Jan 2009 09:45:48 -0800 Subject: Exec woes In-Reply-To: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> > IDLE 1.1.3 ==== No Subprocess ==== > >>> help(exec) > SyntaxError: invalid syntax > >>> > Its the same under Linux SuSe, Python 2.5.1. > > I think this is a BUG. > Exec is a statement, not a function nor an object: even though you can enclose parens around its arguments like you do later on, they don't have any syntax meaning. You can't help(print) or help(import) either. > Anyway, my real problem looks like this: > > >>> def Somefunc(): > def excrescence(): > exec('BUILD = "someString"') > return BUILD > > SyntaxError: unqualified exec is not allowed in function 'excrescence > it is a nested function (, line 3) > >>> > > Now this works if it is not nested, and it works if it is a method in a > class. > Why the complaint about the nestedness? > Once upon a time, Python had only two scopes or namespaces: local and globals. It'd look up variables in the local scope and if it didn't find them, it'd look them up in the global scope. (There's also the builtin namespace but to not digress...) Under this scenario, if you define some attributes in Somefunc() those will NOT be visible within excrescence(). So: def foo(): a = 5 def bar(): print a # error wouldn't work. Then PEP227 came around to add nested scopes -- or lexical scopes. Its what made "nested" functions like that actually useful: it's what brought closures into the scenario. As of Python 2.2, within bar() it would be able to see the definition of a because namespaces can now be nested. This addition was a problem for a couple features: doing "from blah import *" within a function, and a bare exec (an exec without an explicit globals() and locals()) that happened in certain places-- in this case a nested function. They introduced that SyntaxError to make sure it wouldn't accidentally hit you. Read up on PEP227 for the full details. To get around this, you need to specify exactly what scope you want exec to happen in when you're in a place where the 'current' scope is nested. You qualify exec-- > > So there is some namespace thing happening that is too subtle for me, and I > would like to know what "unqualified" means in the above message, and > what one must do to "qualify" the statement, if that is what is needed. > by doing: exec code in , In your situation: >>> def Somefunc(): def excrescence(): exec "BUILD = 'someString'" in globals(), locals() is probably sufficient. globals() returns the dictionary of the global namespace, locals() the dictionary of the current functions (non-nested) namespace. HTH, --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 27 12:46:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jan 2009 09:46:40 -0800 Subject: Exec woes In-Reply-To: References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: <50697b2c0901270946r70316622h5fb8c08e45e700a5@mail.gmail.com> On Tue, Jan 27, 2009 at 9:34 AM, Christian Heimes wrote: > Hendrik van Rooyen schrieb: >> It starts with the conspiracy of silence at the interactive prompt: >> >> Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 >> Type "copyright", "credits" or "license()" for more information. >> >> IDLE 1.1.3 ==== No Subprocess ==== >>>>> help(exec) >> SyntaxError: invalid syntax >> Its the same under Linux SuSe, Python 2.5.1. >> >> I think this is a BUG. > > No, it's the way exec is defined. exec is not a function, it's a > statement. "help(exec)" raises a syntax error like "help(if)" or > "help(while)" would raise a syntax error, too. Indeed. Although it would happen to work in Python 3.0, as exec() became a function once again. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From fetchinson at googlemail.com Tue Jan 27 12:50:14 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jan 2009 09:50:14 -0800 Subject: How do I say "two classes up in the inheritance chain" in python? In-Reply-To: <497ed07e$0$6718$426a34cc@news.free.fr> References: <497ed07e$0$6718$426a34cc@news.free.fr> Message-ID: >> I have two classes that both inherit from two other classes which both >> inherit from a single class. The two children have two almost >> identical methods: >> >> class grandparent( object ): >> def meth( self ): >> # do something >> >> class parent1( grandparent ): >> def meth( self ): >> # do something p1 >> super( parent1, self ).meth( ) >> >> class parent2( grandparent ): >> def meth( self ): >> # do something p2 >> super( parent2, self ).meth( ) >> >> class child1( parent1 ): >> def meth( self ): >> # do something c >> super( parent1, self ).meth( ) # I want to invoke meth on >> grandparent > > If so, it might be better to explicitly call grandparent.meth (passing > self as first argument). But this is an obvious design smell IMHO. What > you have is : > > def meth(self): > do_something_more_or_less_specific > call_granparent > > Looks like a candidate for a template method. Since you don't have hand > on Grandparent, the simplest would be to add an additional base class, ie: > > > class Abstract(Grandparent): > def do_something(self): > raise NotImplementedError > > def meth(self): > self.do_something() > super(Abstract, self).meth() > > > class Parent1(Abstract): > def do_something(self): > # do something p1 > > class Parent2(Abstract): > def do_something(self): > # do something p2 > > > Now you're problem is to factor out do_something() for Child1 and > Child2. The solution is quite simple : just define it outside the class > statements, and adds it afterward: > > def do_something_children(self): > # code here > > class Child1(Parent1): > # code here > > Child1.do_something = do_something_children > > class Child2(Parent2): > # code here > > Child2.do_something = do_something_children Thanks, this was very helpful. Also, thanks Duncan, your simple suggestion was helpful too to just call the grandparent directly (without super). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From vincent at vincentdavis.net Tue Jan 27 12:50:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:50:32 -0700 Subject: change syntax coloring in IDLE Message-ID: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it states I can change he text coloring by using "Configure IDLE" but I not sure what this is. It's not sn the menu, running Configure does nothing. How do I change the color (text and background) Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jan 27 12:53:40 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 09:53:40 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> Message-ID: <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> On Jan 27, 10:12?am, Bruno Desthuilliers wrote: > All you can say is that he didn't *post* here (at least under his real > identity...) for the 9 past years - this doesn't mean he never *reads* > (and this, you just have no way to know). Ah, this is a good point. You have to wonder, Guido could be one of the regulars here. very interesting. We should have a vote as to who would be the most likely candidate, now that would be a good thread :) From thorsten at thorstenkampe.de Tue Jan 27 13:00:09 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:00:09 +0100 Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: * Giampaolo Rodola' (Tue, 27 Jan 2009 04:52:16 -0800 (PST)) > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print unicode('\u20ac') > \u20ac > > This is pretty serious, IMHO, since breaks any Windows software > priting unicode to stdout. > I've filed an issue on the Python bug tracker: > http://bugs.python.org/issue5081 For printing to stdout you have to give an encoding that the terminal understands and that contains the character. In your case the terminal says "I speak cp 850" but of course there is no Euro sign in there. Why should that be a bug? Thorsten From http Tue Jan 27 13:00:24 2009 From: http (Paul Rubin) Date: 27 Jan 2009 10:00:24 -0800 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> Message-ID: <7xmydc6347.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > All you can say is that he didn't *post* here (at least under his real > identity...) for the 9 past years - this doesn't mean he never *reads* > (and this, you just have no way to know). Guido does post here once in a while, under his own name. I can't think of any very recent examples, but I can remember some from a few years back. From bbands at gmail.com Tue Jan 27 13:02:39 2009 From: bbands at gmail.com (BBands) Date: Tue, 27 Jan 2009 10:02:39 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: PyScripter does it for me. http://code.google.com/p/pyscripter/ jab From rantingrick at gmail.com Tue Jan 27 13:03:16 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 10:03:16 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: On Jan 27, 12:00?pm, Paul Rubin wrote: > Guido does post here once in a while, under his own name. ?I can't > think of any very recent examples, but I can remember some from a few > years back. I searched the archives for "Guido van Rossum" and there is nothing since May 2000. That's the most recent i could find anyway?? From thorsten at thorstenkampe.de Tue Jan 27 13:08:20 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:08:20 +0100 Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: * Denis Kasak (Tue, 27 Jan 2009 14:22:32 +0100) > On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' > wrote: > > I have this same issue on Windows. > > Note that on Python 2.6 it works: > > > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> print unicode('\u20ac') > > \u20ac > > Shouldn't this be > > print unicode(u'\u20ac') You are trying to create a Unicode object from a Unicode object. Doesn't make any sense. > on 2.6? Without the 'u' prefix, 2.6 will just encode it as a normal > (byte) string and escape the backslash. You are confusing encoding and decoding. unicode(str) = str.decode. To print it you have to encode it again to a character set that the terminal understands and that contains the desired character. Thorsten From steve at holdenweb.com Tue Jan 27 13:10:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 13:10:09 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: Bryan Olson wrote: > Paul Rubin wrote: >> Bryan Olson writes: >>> An object's __dict__ slot is *not* mutable; thus we could gain some >>> efficiency by protecting the object and its dict with the same lock. I >>> do not see a major win in Mr. Banks' point that we do not need to lock >>> the object, just its dict. >> >> If the dict contents don't change often, maybe we could use an >> STM-like approach to eliminate locks when reading. That would of >> course require rework to just about every C function that accesses >> Python objects. > > I'm a fan of lock-free data structure and software transactional memory, > but I'm also a realist. Heck, I'm one of this group's outspoken > advocates of threaded architectures. Theoretical breakthroughs will > happen, but in real world of today, threads are great but GIL-less > Python is a loser. > > Wherever Python is going, let's recognize that a scripting language that > rocks is better than any other kind of language that sucks. > > Guido, IIRC, has said that he's against any GIL-removal policy that lowers performance on single-processor systems. Personally I'd be happy if there were an *alternative* multi-processor implementation that was slower for single-processor architectures and faster for multi-processor, but I'm not about to start developing it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Tue Jan 27 13:12:42 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 10:12:42 -0800 (PST) Subject: pyAA for Python2.5 Message-ID: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> Hi, I would like to obtain pyAA for Python 2.5. I went through their web site, but they provide the windows exe only for Python2.4. I tried compiling from source, but that also was to no avail - it errs out as follows: C:\Documents and Settings\Guest\pyAA>python setup.py install running install running build running build_py file pyAAc.py (for module pyAAc) not found file pyAAc.py (for module pyAAc) not found running build_ext error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing "-c mingw32" to setup.py. C:\Documents and Settings\Guest\pyAA>python setup.py install -c mingw32 usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'mingw32' Has anyone tried the same? Can anyone give any suggestions? From thorsten at thorstenkampe.de Tue Jan 27 13:24:20 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:24:20 +0100 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) > On Jan 27, 12:00?pm, Paul Rubin wrote: > > Guido does post here once in a while, under his own name. ?I can't > > think of any very recent examples, but I can remember some from a few > > years back. > > I searched the archives for "Guido van Rossum" and there is nothing > since May 2000. That's the most recent i could find anyway?? Search again - the last was in December 2008: http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 &as_maxd=1&as_maxm=1&as_maxy=2009 &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa fe=off From denis.kasak at gmail.com Tue Jan 27 13:35:49 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Tue, 27 Jan 2009 19:35:49 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <39e19a010901271035k1363675fq6353c599724159c0@mail.gmail.com> On Tue, Jan 27, 2009 at 7:08 PM, Thorsten Kampe wrote: > * Denis Kasak (Tue, 27 Jan 2009 14:22:32 +0100) >> On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' >> wrote: >> >>>> print unicode('\u20ac') >> > \u20ac >> >> Shouldn't this be >> >> print unicode(u'\u20ac') > > You are trying to create a Unicode object from a Unicode object. Doesn't > make any sense. Of course it doesn't. :-) Giampaolo's example was wrong because he was creating a str object with a non-escaped backslash inside it (which automatically got escaped) and then converting it to a unicode object. In other words, he was doing: print unicode('\\u20ac') so the Unicode escape sequence didn't get interpreted the way he intended it to. I then modified that by adding the extra 'u' but forgot to delete the extraneous unicode(). > You are confusing encoding and decoding. unicode(str) = str.decode. To > print it you have to encode it again to a character set that the > terminal understands and that contains the desired character. I agree (except for the first sentence :-) ). As I said, I simply forgot to delete the call to the unicode builtin. -- Denis Kasak From http Tue Jan 27 13:45:57 2009 From: http (Paul Rubin) Date: 27 Jan 2009 10:45:57 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: <7x8wowegey.fsf@ruckus.brouhaha.com> Bryan Olson writes: > I'm a fan of lock-free data structure and software transactional > memory, but I'm also a realist. Heck, I'm one of this group's > outspoken advocates of threaded architectures. Theoretical > breakthroughs will happen, but in real world of today, threads are > great but GIL-less Python is a loser. GIL-less Python (i.e. Jython) already exists and beats CPython in performance a lot of the time, including on single processors. Whether the GIL can be eliminated from CPython without massive rework to every extension module ever written is a separate question, of course. Jython can be viewed a proof of concept. From martin at v.loewis.de Tue Jan 27 13:56:03 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 19:56:03 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> Message-ID: <497F58C3.6020209@v.loewis.de> > #include "stdio.h" > int main(int argc, char **argv) { > printf("<\xc2\x80>\n"); > } > > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) > and using "Lucida Console" font: > > After CHCP 1252, this prints < A-circumflex Euro >, as expected. > After CHCP 65001, it prints < hollow-square >. This is not surprising: this character is U+0080, which is a control character. Try \xe2\x82\xac instead. Regards, Martin From kyosohma at gmail.com Tue Jan 27 13:56:45 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 10:56:45 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> Message-ID: <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> On Jan 27, 12:12?pm, Kottiyath wrote: > Hi, > ? ?I would like to obtain pyAA for Python 2.5. I went through their > web site, but they provide the windows exe only for Python2.4. I tried > compiling from source, but that also was to no avail - it errs out as > follows: > > C:\Documents and Settings\Guest\pyAA>python setup.py install > running install > running build > running build_py > file pyAAc.py (for module pyAAc) not found > file pyAAc.py (for module pyAAc) not found > running build_ext > error: Python was built with Visual Studio 2003; > extensions must be built with a compiler than can generate compatible > binaries. > Visual Studio 2003 was not found on this system. If you have Cygwin > installed, > you can try compiling with MingW32, by passing "-c mingw32" to > setup.py. > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > mingw32 > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > ? ?or: setup.py --help [cmd1 cmd2 ...] > ? ?or: setup.py --help-commands > ? ?or: setup.py cmd --help > > error: invalid command 'mingw32' > > Has anyone tried the same? Can anyone give any suggestions? You probably have to put mingw32 on your path or provide an absolute path to it. By the way, where did you get the source? I couldn't find it... Mike From Pat at junk.net Tue Jan 27 14:04:28 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 14:04:28 -0500 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: >> >> I had no idea people were going to get so upset that I used a Windows >> example and go off on a tear. > > Nobody is upset, and nobody has "gone off on a tear". The point about > the "Windows example" is that the docs say in a close-to-screamingly- > obvious manner that /options are not supported, no matter what > religion uses them. It was not, and still is not, apparent what you > really wanted. We're all patiently waiting for you to rephrase the > question(s). Sigh. I used an incorrect example (I sincerely apologize to the world for that egregious error on my part). I''m totally cognizant that the documentation states '-'' or '--' need to be used for flags. The question was it possible to add a simple flag like 'd-' to optparse with no other parameters? I'm guessing from the vitriolic diatribes here that the answer is no. To those who wrote that no one uses command line windows and no one uses 'dir /s /b' command is totally irrelevant. I'm writing a proprietary program used solely by my company. Not everyone writes programs for the same target audience as you do. The program is written in Python on Ubuntu. If you don't want to answer the question or don't have any meaningful to add, please don't pollute the forum with further vacuous responses. I didn't ask, or expect, you to write the code for me. christ on a stick, so many of you behave like prima donnas. From Russ.Paielli at gmail.com Tue Jan 27 14:13:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 27 Jan 2009 11:13:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> On Jan 26, 6:09 am, Steve Holden wrote: > Quite. Python is a language "for consenting adults". It has perceived > deficiencies for certain software engineering environments. Can we drop > the subject now? This horse was flogged to death long ago, and it's > pointless and cruel to keep on beating the remains. Judging from this thread, not everyone got the memo yet. At least three or four people on this thread alone have argued that enforced data hiding is of no value whatsoever for any application or domain. And more than one of them has argued that Python is perfectly appropriate for even the largest and most safety-critical projects. We are moving into an era of increasing dependence on computers and software for safety-critical, mission-critical, and financial systems. If people who do not understand the principles necessary for ultra-reliable software get in charge of developing these systems, we will have serious problems that could have been avoided. I suggested that maybe -- maybe! -- the versatility of Python could be enhanced with enforced data hiding. I was careful to say several times that I don't know if that can even be done in Python (with all its introspection and so forth). And it would always be optional, of course (as far as I know, no language forces anyone to declare anything private). Several people here seem to take that suggestion as an assault on Python and, by projection, an assault on their worldview. We all know that Python is a fantastic language for many purposes, but it is only a language, and failing to recognize and address its limitations serves no useful purpose. From rene.heymans at gmail.com Tue Jan 27 14:18:32 2009 From: rene.heymans at gmail.com (Rene Heymans) Date: Tue, 27 Jan 2009 20:18:32 +0100 Subject: Python + IDLE under Linux Suse 11.0 Message-ID: <8f7f91620901271118l4962c254s3ffcda23bdc19f97@mail.gmail.com> Dear All, This is my first post to this list. When googling of "*python + idle + CallTip + "Exception in Tkinter* * callback"* one finds within a list of 7 results: at the top of the list (Nr. 1) a link to http://mail.python.org/pipermail/python-bugs-list/2004-August/024530.html dated August 2004 (I understand it is a bug fixed and closed.); as Nr. 3 in the list a link http://www.nabble.com/Output-to-file-gets-lost---don't-know-where-to-look-...-td21004997.html dated December 14, 2008. However, I have a situation where the symptoms are almost identical to the one described by the link Nr 3 (see output below) and that I can reproduce at will with something that looks like what is reported in the link Nr 1. The environment is: Linux OpenSuse 11.0 Python 2.5.2 Idle 1.2.2 When typing: *>>> l = len(* to query the length of an object, instead of getting a Call Tip, I get on my console the message below: *Alibaba:~ # idle Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 55, in try_open_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 79, in open_calltip self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1]) File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 66, in showtip self.position_window() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 35, in position_window self.parencol)) File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 2833, in bbox self.tk.call((self._w, 'bbox') + args)) or None File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1030, in _getints return tuple(map(getint, self.tk.splitlist(string))) ValueError: invalid literal for int() with base 10: '(117,' * and when closing the parenthesis the following messages: *Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 62, in refresh_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 65, in open_calltip self._remove_calltip_window() File "/usr/lib/python2.5/idlelib/CallTips.py", line 41, in _remove_calltip_window self.calltip.hidetip() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 126, in hidetip self.label.destroy() AttributeError: 'NoneType' object has no attribute 'destroy'* Furhtermore there is one little X window that opens up, totally empty and useless. IDLE works but each time you expect a Tip to appear you receive instead a bunch of messages to the console and you lose focus on your IDLE window, meaning you have to click on it to get the focus again and continue typing. I checked on Suse Repository 11.1 but then the available version is Python 2.6, which I don't want presently and which would require many updates to solve dependencies. I also tried to download the source of Python 2.5.4 from www.python.org . I can download the files, unpack them and run the trio of commands (./configure, make, make install) and all run smoothly. Python 2.5.4 starts and works nicely. But now IDLE begins but when you ask to run the shell, a window opens but you don't see anything: no menu, no begin, no >>> prompt, nothing ... I wonder (but I may be totally wrong here) if Suse packages Python + IDLE in a very special way ? Why would */usr/bin/python* be an executable of about 6KB within Suse and be an executable of about 3MB when generating from the source. This is my first encounter in porting a prototype under development to Linux ! Thank you for any help you may provide. All the best, Rene -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Jan 27 14:29:02 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jan 2009 20:29:02 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Pat wrote: > The question was it possible to add a simple flag like 'd-' to optparse > with no other parameters? Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's answer? Peter From babycode at gmail.com Tue Jan 27 14:39:25 2009 From: babycode at gmail.com (Baby Coder) Date: Tue, 27 Jan 2009 11:39:25 -0800 (PST) Subject: Is this pythonic? References: <66d058f9-cfe1-4b3c-ab8a-e6e88bb97770@m22g2000vbp.googlegroups.com> <7dc03d4b-4bce-4cc4-b020-681935cf0b0b@m4g2000vbp.googlegroups.com> Message-ID: <78e47d26-6c90-4697-aff3-4f6d172b207e@k19g2000yqg.googlegroups.com> On 18 d?c 2008, 13:51, Jason Scheirer wrote: > I'd say it's fine but breaking up the statement once or twice is a > good idea just because if one of the function calls in this nested > thing throws an exception, a smaller statement with fewer calls makes > for a far more readable traceback. And I hope that this whole > statement all lives inside of a method in the same x class, or is a > higher-level class that makes use of this behavior? If not, you may > want to consider doing so. > > class X(object): > ? @property > ? def todays_filepattern(self): > ? ? ? return self.match_filename( > ? ? ? ? ? ? ? self.determine_filename_pattern( > ? ? ? ? ? ? ? ? ? ?datetime.datetime.now())) > ? def validate_todays_files(self): > ? ? ?return self.validate_output(self.find_text > (self.todays_filepattern)) Thanks for this lesson in application design. Just what I was looking for. From kyrie at uh.cu Tue Jan 27 14:40:02 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 14:40:02 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: <200901271440.02579.kyrie@uh.cu> On Tuesday 27 January 2009 02:13:50 pm Russ P. wrote: > I suggested that maybe -- maybe! -- the versatility of Python could be > enhanced with enforced data hiding. I was careful to say several times > that I don't know if that can even be done in Python (with all its > introspection and so forth). And it would always be optional, of > course (as far as I know, no language forces anyone to declare > anything private). I think you still fail to see that what we are objecting is not that the original writer can "optionally" use the enforced data hiding (which, as someone pointed out before me, can be done with tools like pylint). The objection is about the _user_ of the library. If you don't force it into the _user_, how is it different from the current situation? And if you do force it, how can you say that it is optional? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From nad at acm.org Tue Jan 27 14:40:41 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 11:40:41 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: In article <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, Vincent Davis wrote: > I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it > states I can change he text coloring by using "Configure IDLE" but I not > sure what this is. It's not sn the menu, running Configure does nothing. How > do I change the color (text and background) There is supposed to be a Preferences menu option for IDLE on OS X but, depending on the Python version and how IDLE is launched, it may or may not appear due to various bugs. (I'm working on some patches for these.) If you have been launching IDLE via /Applications/MacPython 2.5/IDLE.app, try launching it via the shell command line: /usr/local/bin/idle2.5. There may now be a working Preferences menu item under the Python item in the menu bar; there may also be an Options -> Configure IDLE... . If that doesn't work, it should be possible to copy the default def files from idlelib in the python installation to your .idlerc directory and manually edit them there - ugh!. Something like: $ cd `python2.5 -c 'import sys; print sys.prefix'` $ cd lib/python2.5/idlelib $ ls *.def config-extensions.def config-highlight.def config-keys.def config-main.def $ cp -i *.def ~/.idlerc $ cd ~/.idlerc $ vi ... -- Ned Deily, nad at acm.org From steve at holdenweb.com Tue Jan 27 14:45:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 14:45:03 -0500 Subject: optparse question In-Reply-To: References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Peter Otten wrote: > Pat wrote: > >> The question was it possible to add a simple flag like 'd-' to optparse >> with no other parameters? > > Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's > answer? > I guess it got crowded out by the prima donnas anxious to help Pat phrase his/her question better ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Pat at junk.net Tue Jan 27 14:45:15 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 14:45:15 -0500 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Peter Otten wrote: > Pat wrote: > >> The question was it possible to add a simple flag like 'd-' to optparse >> with no other parameters? > > Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's > answer? > > Peter > I mean "-d" since that's what Unix commands expect for flags. My sole intention for the "-d" was to put my program into debug mode so that while I'm using the Wing IDE, I can debug my program using just one child process (instead of dozens) without having to change a constant within my program. I haven't figured out a way to debug multiple child processes in Wing. But, I confess, I haven't been very vigorous in learning how. My other intention was to learn the optparse module just for the sake of learning. From steve at holdenweb.com Tue Jan 27 14:47:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 14:47:40 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x8wowegey.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >> I'm a fan of lock-free data structure and software transactional >> memory, but I'm also a realist. Heck, I'm one of this group's >> outspoken advocates of threaded architectures. Theoretical >> breakthroughs will happen, but in real world of today, threads are >> great but GIL-less Python is a loser. > > GIL-less Python (i.e. Jython) already exists and beats CPython in > performance a lot of the time, including on single processors. > Whether the GIL can be eliminated from CPython without massive rework > to every extension module ever written is a separate question, of > course. Jython can be viewed a proof of concept. . I think probably the GIL will never be extracted successfully. Also IronPython and PyPy (though the latter only in concept for now, I believe). Even Guido admits that CPython doesn't necessarily represent the dominant future strain ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Russ.Paielli at gmail.com Tue Jan 27 14:56:51 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 27 Jan 2009 11:56:51 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> On Jan 27, 11:40 am, Luis Zarrabeitia wrote: > I think you still fail to see that what we are objecting is not that the > original writer can "optionally" use the enforced data hiding (which, as > someone pointed out before me, can be done with tools like pylint). The > objection is about the _user_ of the library. If you don't force it into the > _user_, how is it different from the current situation? And if you do force > it, how can you say that it is optional? As I have pointed out several times, the user cannot be forced to respect data hiding if he has access to the source code (and the right to modify it). If Python had a "private" keyword (or equivalent), for example, the user would only need to delete it wherever necessary to gain the desired access. From vincent at vincentdavis.net Tue Jan 27 15:07:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 13:07:32 -0700 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: <77e831100901271207o4117998cqc35c3b62fdbb15b5@mail.gmail.com> I am using "EPD with Py2.5 4.0.30002"when I try to launch IDLE.app which is in the above folder i get -bash: IDLE.app: command not found which is strange because when I do ls it is listed. the path to the folder is /Applications/EPD\ with\ Py2.5\ 4.0.30002 ls returns Build Applet.app Mayavi.terminal Docs Pylab.terminal Examples Python Launcher.app Extras Update Shell Profile.command IDLE.app Then I do/get vincent-daviss-macbook-pro:EPD with Py2.5 4.0.30002 vmd$ IDLE.app -bash: IDLE.app: command not found Not sure what I am doing wrong Is the a way do download a new version of IDLE.app? That last part is ugh! Thanks Vincent Davis On Tue, Jan 27, 2009 at 12:40 PM, Ned Deily wrote: > In article > <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, > Vincent Davis wrote: > > I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it > > states I can change he text coloring by using "Configure IDLE" but I not > > sure what this is. It's not sn the menu, running Configure does nothing. > How > > do I change the color (text and background) > > There is supposed to be a Preferences menu option for IDLE on OS X but, > depending on the Python version and how IDLE is launched, it may or may > not appear due to various bugs. (I'm working on some patches for these.) > > If you have been launching IDLE via /Applications/MacPython > 2.5/IDLE.app, try launching it via the shell command line: > /usr/local/bin/idle2.5. There may now be a working Preferences menu > item under the Python item in the menu bar; there may also be an Options > -> Configure IDLE... . If that doesn't work, it should be possible to > copy the default def files from idlelib in the python installation to > your .idlerc directory and manually edit them there - ugh!. Something > like: > > $ cd `python2.5 -c 'import sys; print sys.prefix'` > $ cd lib/python2.5/idlelib > $ ls *.def > config-extensions.def config-highlight.def config-keys.def > config-main.def > $ cp -i *.def ~/.idlerc > $ cd ~/.idlerc > $ vi ... > > -- > Ned Deily, > nad at acm.org > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bumens at dingens.org Tue Jan 27 15:10:32 2009 From: bumens at dingens.org (Volker Birk) Date: Tue, 27 Jan 2009 21:10:32 +0100 (CET) Subject: pyPEG parser-interpreter released Message-ID: Hi, pyPEG is a general parser for context free languages as a small Python module. It is PEG (Parsing Expression Grammar) based. It can be very easily used in your Python program. Everybody who understands regular expressions can quickly understand and use pyPEG. The output result is a standard Python data structure, pyAST, just consisting of lists of strings and tuples. You can find pyPEG here: Yours, VB. -- Bitte beachten Sie auch die R?ckseite dieses Schreibens! From mdw at distorted.org.uk Tue Jan 27 15:13:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:13:17 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <871vuose1u.fsf.mdw@metalzone.distorted.org.uk> [No, my email address doesn't begin `m...@'. Fixed.] Michele Simionato writes: > On Jan 21, 2:11 am, Mark Wooding wrote: > >> CLOS is much more complex and dynamic than Python's object system; >> but it can be compiled very aggressively. > > I agree that CLOS is complex and that it can be compiled very > aggressively, but I do not think that it is more dynamic than Python. > What feature are you alluding to? Multimethods? There are many Python > implementations of them, they are just not in the standard library. > Or are you referring to interactive facilities, such as the one > discussed in this recipe http://code.activestate.com/recipes/160164 ? I'm referring to a number of features: * Redefinition of classes, yes. Interactive development is very frustrating without this. Thanks for that link, by the way! * CHANGE-CLASS to change the class of instances. This is more than just assigning to mumble.__class__, since it correctly initializes the slots present in the new class which were absent in the old. * And all of the fancy MOP tricks you can play: inventing new slot classes; messing with class-precedence-list orderings (Python's MRO). It's a shorter list than I'd hoped! Still, these features kind of multiply up. You can redefine a class using a new metaclass and slot options, and all the instances are updated, for example. Anyway, I think I exaggerated when I said that CLOS was `much more dynamic', but it is /somewhat/ more dynamic, and still amenable to optimization; since my point was that dynamism in a language isn't necessarily antithetical to compilation, that's still sufficient. Thanks for keeping me honest! -- [mdw] From bumens at dingens.org Tue Jan 27 15:15:04 2009 From: bumens at dingens.org (Volker Birk) Date: Tue, 27 Jan 2009 21:15:04 +0100 (CET) Subject: pyPEG parser-interpreter released Message-ID: Hi, pyPEG is a general parser for context free languages as a small Python module. It is PEG (Parsing Expression Grammar) based. It can be very easily used in your Python program. Everybody who understands regular expressions can quickly understand and use pyPEG. The output result is a standard Python data structure, pyAST, just consisting of lists of strings and tuples. You can find pyPEG here: pyPEG is Free Software. It is under the GNU General Public License 2.0. Yours, VB. -- Bitte beachten Sie auch die R?ckseite dieses Schreibens! From mdw at distorted.org.uk Tue Jan 27 15:22:57 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:22:57 +0000 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <87wscgqz1a.fsf.mdw@metalzone.distorted.org.uk> Grant Edwards writes: > I've always found comp.lang.c to be a rather dangerous place as well. Hey, I grew up in comp.lang.c! I'd have to agree with you, though. (I try to play nice when I'm here.) In fact, comp.lang.* generally has a reputation as a place you don't want to find yourself after dark... > Of the newsgroups I read, c.l.python is probably the most friendly and > has one of the highest S/N ratios. People who would have been roasted > alive in other newsgroups for their laziness or presumptuousness get > surprisingly gentle treatment in c.l.python. I do know of a few > low-volume mailing lists that are probably as good, but for a Usenet > news group with any volume at all, c.l.pythong is exceptionally good. I certainly agree with this. And it's definitely a spirit that's worth preserving. -- [mdw] From cousinstanley at gmail.com Tue Jan 27 15:25:18 2009 From: cousinstanley at gmail.com (gmail_cs) Date: Tue, 27 Jan 2009 13:25:18 -0700 Subject: *.python.org broken? In-Reply-To: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> References: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> Message-ID: <200901271325.18667.cousinstanley@gmail.com> On Monday 26 January 2009 03:48:25 am you wrote: > I experienced the same problem here in Brazil. Tweeks ago I could not > access any *.python.org site. Today I tried and it worked. The > problem seemed to be limited to Python's domain because I could > access every other site that I tried the same day. > .... > Carlos Ribeiro Since yesterday ( Monday 2009-01-26 ) I can again access http://python.org with no problems .... -- Stanley C. Kitching Human Being Phoenix, Arizona From rhamph at gmail.com Tue Jan 27 15:31:46 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 27 Jan 2009 12:31:46 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: On Jan 27, 12:13?pm, "Russ P." wrote: > On Jan 26, 6:09 am, Steve Holden wrote: > > > Quite. Python is a language "for consenting adults". It has perceived > > deficiencies for certain software engineering environments. Can we drop > > the subject now? This horse was flogged to death long ago, and it's > > pointless and cruel to keep on beating the remains. > > Judging from this thread, not everyone got the memo yet. At least > three or four people on this thread alone have argued that enforced > data hiding is of no value whatsoever for any application or domain. > And more than one of them has argued that Python is perfectly > appropriate for even the largest and most safety-critical projects. > > We are moving into an era of increasing dependence on computers and > software for safety-critical, mission-critical, and ?financial > systems. If people who do not understand the principles ?necessary for > ultra-reliable software get in charge of developing these systems, we > will have serious problems that could have been avoided. > > I suggested that maybe -- maybe! -- the versatility of Python could be > enhanced with enforced data hiding. I was careful to say several times > that I don't know if that can even be done in Python (with all its > introspection and so forth). And it would always be optional, of > course (as far as I know, no language forces anyone to declare > anything private). > > Several people here seem to take that suggestion as an assault on > Python and, by projection, an assault on their worldview. We all know > that Python is a fantastic language for many purposes, but it is only > a language, and failing to recognize and address its limitations > serves no useful purpose. What you need is a middle ground. Something that can be *easily* circumvented for debugging, unit tests, and "friend" functions/modules/ class. Without suggesting a middle ground people are left assuming C++-style privates/protected, which would be a significant burden on everybody. The only way it wouldn't is if nobody actually uses it, except in specialized high-assurance software, but at that point you might as well fork python (or use metaclass trickery). From kyosohma at gmail.com Tue Jan 27 15:35:39 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 12:35:39 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> <87wscgqz1a.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <94b92fa9-6c6a-432d-bb6e-cdaad3740620@o4g2000pra.googlegroups.com> > > Of the newsgroups I read, c.l.python is probably the most friendly and > > has one of the highest S/N ratios. ?People who would have been roasted > > alive in other newsgroups for their laziness or presumptuousness get > > surprisingly gentle treatment in c.l.python. ?I do know of a few > > low-volume mailing lists that are probably as good, but for a Usenet > > news group with any volume at all, c.l.pythong is exceptionally good. > > I certainly agree with this. ?And it's definitely a spirit that's worth > preserving. > > -- [mdw] I don't know if we should encourage the use of pythons as thongs myself...I didn't even know there was a group on that topic. ;) Mike From mdw at distorted.org.uk Tue Jan 27 15:37:03 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:37:03 +0000 Subject: Pexpect and telnet not communicating properly References: <497f35ef$0$30312$da0feed9@news.zen.co.uk> Message-ID: <87skn4qyds.fsf.mdw@metalzone.distorted.org.uk> David Anderson writes: > I am trying to automate the following session - to talk to my router: > > telnet speedtouch [...] > I am using the following code: [...] > child.expect('sername : ') > child.sendline('Administrator') I've scripted communications with my Speedtouch 510 using pexpect: I use it to send the router's logs to my server. The obvious difference between my script and yours is that instead of sendline, I used send and an explicit carriage return. kid.expect('Username :') kid.send('admin\r\n') I think this is a result of a similar problem, but I don't remember any more. Anyway, I've put my (very simple) script up at http://www.distorted.org.uk/~mdw/example/guvnor-maintenance in case you're interested. (No, I wasn't daft enough to put the password in the script!) -- [mdw] From rhamph at gmail.com Tue Jan 27 15:40:50 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 27 Jan 2009 12:40:50 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: On Jan 27, 12:47?pm, Steve Holden wrote: > Paul Rubin wrote: > > GIL-less Python (i.e. Jython) already exists and beats CPython in > > performance a lot of the time, including on single processors. > > Whether the GIL can be eliminated from CPython without massive rework > > to every extension module ever written is a separate question, of > > course. ?Jython can be viewed a proof of concept. > > . I think probably the GIL will never be extracted successfully. > > Also IronPython and PyPy (though the latter only in concept for now, I > believe). Even Guido admits that CPython doesn't necessarily represent > the dominant future strain ... IMO it's possible to rewrite only the core while keeping the refcount API for external compatibility, but a tracing GC API in portable C is hideous. Enough to make me want to find or make a better implementation language. From http Tue Jan 27 15:45:22 2009 From: http (Paul Rubin) Date: 27 Jan 2009 12:45:22 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: <7x63k0iil9.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > IMO it's possible to rewrite only the core while keeping the refcount > API for external compatibility, but a tracing GC API in portable C is > hideous. It's done all the time for other languages, and is less hassle than the incref/decref stuff and having to remember the difference between owned and borrowed references, etc. > Enough to make me want to find or make a better implementation language. There is a lot to be said for this, including the self-respect that comes from a language being able to host its own implementation. From steve at holdenweb.com Tue Jan 27 15:47:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 15:47:02 -0500 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: rantingrick wrote: > On Jan 27, 12:00 pm, Paul Rubin wrote: >> Guido does post here once in a while, under his own name. I can't >> think of any very recent examples, but I can remember some from a few >> years back. > > I searched the archives for "Guido van Rossum" and there is nothing > since May 2000. That's the most recent i could find anyway?? I suspect his last major interaction was the "voting" for either the decorator or the ternary operator/if expression syntax. At that point I suspect he decided interaction with the community didn't actually improve the design of the language. But I'm not Guido. Honest. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From duncan.booth at invalid.invalid Tue Jan 27 15:52:02 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jan 2009 20:52:02 GMT Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: Thorsten Kampe wrote: > * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) >> On Jan 27, 12:00??pm, Paul Rubin wrote: >> > Guido does post here once in a while, under his own name. ??I can't >> > think of any very recent examples, but I can remember some from a few >> > years back. >> >> I searched the archives for "Guido van Rossum" and there is nothing >> since May 2000. That's the most recent i could find anyway?? > > Search again - the last was in December 2008: > http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= > 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 > &as_maxd=1&as_maxm=1&as_maxy=2009 > &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa > fe=off Or even: http://groups.google.com/groups/profile?show=more&enc_user=RVb59hAAAADAKHw2rKTOXQmYRzwTg33E&group=comp.lang.python which shows 456 posts to clp over the last 9 years, but only about once a year for the last 3 years. For comparison, according to Google I've managed 2251 posts to clp since 1997 which I find kind of scary. From mdw at distorted.org.uk Tue Jan 27 15:53:34 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:53:34 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> Message-ID: <87ocxsqxm9.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > If Python had a "private" keyword (or equivalent), for example, the > user would only need to delete it wherever necessary to gain the > desired access. And you obviously weren't listening when we said that having to make source code changes to upstream modules was a serious maintenance and distribution headache: <87ab9f8dp1.fsf.mdw at metalzone.distorted.org.uk> -- [mdw] From nad at acm.org Tue Jan 27 15:58:11 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 12:58:11 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> <77e831100901271207o4117998cqc35c3b62fdbb15b5@mail.gmail.com> Message-ID: In article <77e831100901271207o4117998cqc35c3b62fdbb15b5 at mail.gmail.com>, Vincent Davis wrote: > I am using "EPD with Py2.5 4.0.30002"when I try to launch IDLE.app which is > in the above folder i get -bash: IDLE.app: command not found > which is strange because when I do ls it is listed. > the path to the folder is > /Applications/EPD\ with\ Py2.5\ 4.0.30002 > ls returns > Build Applet.app Mayavi.terminal > Docs Pylab.terminal > Examples Python Launcher.app > Extras Update Shell Profile.command > IDLE.app > > Then I do/get > vincent-daviss-macbook-pro:EPD with Py2.5 4.0.30002 vmd$ IDLE.app > -bash: IDLE.app: command not found > > Not sure what I am doing wrong You can't launch an OSX application bundle from a shell that way. You could use /usr/bin/open but that should give the same results as double-clicking on the IDLE icon. I don't have personal experience with EPD distribution but there should be a command line binary of idle included. Try this from a Terminal shell: $ cd `python -c 'import sys; print sys.prefix'` $ bin/idle If you can change and save the preferences that way, they should then apply to IDLE no matter how you launch it. -- Ned Deily, nad at acm.org From Scott.Daniels at Acm.Org Tue Jan 27 15:58:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 27 Jan 2009 12:58:37 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz5xn55.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <7xeiz5xn55.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Scott David Daniels writes: >> But, the research on the language "Self" shows that even in the face >> of a language with more dynamism than Smalltalk (or Python), performance >> can be obtained using compiler technology.... > > I'd be interested in seeing any publications about that Self research, > which I remember someone else mentioning in another thread as well. Sorry this was sitting in drafts. Search for David Ungar and/or Randall Smith and Self. --Scott David Daniels Scott.Daniels at Acm.Org From reckoner at gmail.com Tue Jan 27 16:16:36 2009 From: reckoner at gmail.com (Reckoner) Date: Tue, 27 Jan 2009 13:16:36 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? Message-ID: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> I'm not sure this is possible, but I would like to have a list of objects A=[a,b,c,d,...,z] where, in the midst of a lot of processing I might do something like, A[0].do_something_which_changes_the_properties() which alter the properties of the object 'a'. The trick is that I would like A to be mysteriously aware that something about the object 'a' has changed so that when I revisit A, I will know that the other items in the list need to be refreshed to reflect the changes in A as a result of changing 'a'. Even better would be to automatically percolate the subsequent changes that resulted from altering 'a' for the rest of the items in the list. Naturally, all of these items are related in some parent-child fashion. that might be a lot to ask, however. Any advice appreciated. From excord80 at gmail.com Tue Jan 27 16:19:02 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 13:19:02 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? Message-ID: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> I need to make a small, relatively low-traffic site that users can create accounts on and log into. Scripts must run as cgi (no mod_python or FastCGI is available). Can anyone recommend a small and simple web framework for Python, maybe similar to Perl's CGI::Application? Or would it just be better to roll my own? From robert.kern at gmail.com Tue Jan 27 16:21:40 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 15:21:40 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Message-ID: On 2009-01-27 03:09, Johan Ekh wrote: > Thanks, > James I will try your suggestion! > Robert, what mean with "interactively" is that i would like to create an > array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or > by reading a file with values etc., and then execute my program with > "myprog -m m_i" and thus pass the array "m_i" to my program. > > This is just an example. I would like to pass several arrays. My program > will be wrapped inside a loop and the arrays are updated > in each loop. > > I have never heard of the "argparse" library. Do you think that it would > be better to use that in my case? No. Basically, no command line parser is going to work like you want. If you want to run something from IPython using the objects in your IPython session, you should make a module instead of a program. Import your module, and call its functions. Then you can pass whatever objects you like. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From clp2 at rebertia.com Tue Jan 27 16:27:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jan 2009 13:27:02 -0800 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901271327t2aec0155w3e0391d6a4fd06df@mail.gmail.com> On Tue, Jan 27, 2009 at 1:16 PM, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. Have you considered: A.change_properties_of_item_and_know_about_it(0) ? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From alecla at bluewin.ch Tue Jan 27 16:41:31 2009 From: alecla at bluewin.ch (alex) Date: Tue, 27 Jan 2009 13:41:31 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values Message-ID: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> Hello everybody I am mainly a Fortran programmer and beginning to learn Python(2.5) and OOP programming. I hope in the end to put a GUI on my existing Fortran code. Therefore I am also trying to learn Python's "ctypes" library. Unfortunately the ctypes tutorial does not show simple examples so I set up a simple fortran module and Python script to test. But even with passing Integer and Real values I get the right output but with subsequent error: ValueError: Procedure probably called with too many arguments (4 bytes in excess) The scripts exits then, so the second subroutine call does not happen. >From reading comp.lang.python and comp.lang.fortran I understood that passing character strings may not be simple but I could not find any solution to my problem. Maybe somebody can help me with solving it? The Fortran module (footst.f90): ! module footst ! implicit none ! ! !- End of module header ------------------------------------------------ ! !- Execution part of the module ---------------------------------------- ! ! contains !- Define procedures contained in this module. ! !----------------------------------------------------------------------- ! ! subroutine foo1(int_tst) !DEC$ ATTRIBUTES DLLEXPORT :: foo1 integer, intent(in):: int_tst write(unit=*, fmt="(a)") "Subroutine foo1(int_tst)" write(unit=*, fmt="(a, i4)") "a= ", int_tst end subroutine foo1 ! ! subroutine foo2(real_tst) !DEC$ ATTRIBUTES DLLEXPORT :: foo2 real, intent(in):: real_tst write(unit=*, fmt="(a)") "Subroutine foo2(real_tst)" write(unit=*, fmt="(a, f6.2)") "a= ", real_tst end subroutine foo2 ! ! end module footst ! The Python script (footst.py): #!/usr/bin/env python # # from ctypes import * # # if __name__ == '__main__': tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") # tst.restype=None # tst.argtypes=(c_int) x=c_int(999) y=c_float(10.5) tst.footst_mp_foo1_(byref(x)) # Passing Real values commented out, but leads to the same error # tst.footst_mp_foo2_(byref(y)) # main() # # The DOS prompt output: F:\Scratch\Test2>df /dll /iface=(cref,nomixed_str_len_arg)/ names:lowercase /assume:underscore footst.f90 Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update B) Copyright 2001 Compaq Computer Corp. All rights reserved. footst.f90 Microsoft (R) Incremental Linker Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. /entry:_DllMainCRTStartup at 12 /ignore:505 /debugtype:cv /debug:minimal /pdb:none F:\SysTemp\obj5B.tmp dfordll.lib msvcrt.lib dfconsol.lib dfport.lib kernel32.lib /out:footst.dll /dll Creating library footst.lib and object footst.exp F:\Scratch\Test2>dumpbin /exports footst.dll Microsoft (R) COFF Binary File Dumper Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. Dump of file footst.dll File Type: DLL Section contains the following exports for footst.dll 0 characteristics 497F5CC3 time date stamp Tue Jan 27 20:13:07 2009 0.00 version 1 ordinal base 2 number of functions 2 number of names ordinal hint RVA name 1 0 00001000 footst_mp_foo1_ 2 1 000010A6 footst_mp_foo2_ Summary 1000 .data 1000 .rdata 1000 .reloc 1000 .text F:\Scratch\Test2>footst.py Subroutine foo1(int_tst) a= 999 Traceback (most recent call last): File "F:\Scratch\Test2\footst.py", line 13, in tst.footst_mp_foo1_(byref(x)) ValueError: Procedure probably called with too many arguments (4 bytes in excess) F:\Scratch\Test2> From robert.kern at gmail.com Tue Jan 27 16:42:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 15:42:52 -0600 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: On 2009-01-27 13:40, Ned Deily wrote: > In article > <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, > Vincent Davis wrote: >> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it >> states I can change he text coloring by using "Configure IDLE" but I not >> sure what this is. It's not sn the menu, running Configure does nothing. How >> do I change the color (text and background) > > There is supposed to be a Preferences menu option for IDLE on OS X but, > depending on the Python version and how IDLE is launched, it may or may > not appear due to various bugs. (I'm working on some patches for these.) I'd love to get these patches so we can include them in EPD. Is there an issue on the Python bug tracker that I can follow? > If you have been launching IDLE via /Applications/MacPython > 2.5/IDLE.app, try launching it via the shell command line: > /usr/local/bin/idle2.5. In Vincent's case (EPD), this would be /Library/Frameworks/Python/Versions/Current/bin/idle2.5 . > There may now be a working Preferences menu > item under the Python item in the menu bar; there may also be an Options > -> Configure IDLE... . Yes, to both. -- 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 kyrie at uh.cu Tue Jan 27 16:44:24 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 16:44:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> Message-ID: <200901271644.24918.kyrie@uh.cu> On Tuesday 27 January 2009 02:56:51 pm Russ P. wrote: > On Jan 27, 11:40 am, Luis Zarrabeitia wrote: > > I think you still fail to see that what we are objecting is not that the > > original writer can "optionally" use the enforced data hiding (which, as > > someone pointed out before me, can be done with tools like pylint). The > > objection is about the _user_ of the library. If you don't force it into > > the _user_, how is it different from the current situation? And if you do > > force it, how can you say that it is optional? > > As I have pointed out several times, the user cannot be forced to > respect data hiding if he has access to the source code (and the right > to modify it). If Python had a "private" keyword (or equivalent), for > example, the user would only need to delete it wherever necessary to > gain the desired access. And, as others and I have pointed out several times, that would mean to maintain a fork. Would you say that current C++ has "optional" enforced data hiding for the user? After all, you can just fork the module (and if you don't have the source, you could mess with pointers until you find it). Also, I once pointed out that "access to the source code and right to modify it" is not a given. What you are proposing is not optional at all. You want the power to control what others do - and while it may be your legal right, it's also everyone else's right not go our of our ways to help you have it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From python.list at tim.thechases.com Tue Jan 27 16:52:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Jan 2009 15:52:12 -0600 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <497F820C.7000304@tim.thechases.com> > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? What are you looking for in your framework? Python comes with its own CGI module[1]. For the most basic of sites, this works nicely. However, if you want to be able to easily slide into a bigger environment, I've been pleased with WebStack[2] for my lightweight needs. It makes light work of transitioning from CGI to other stacks such as mod_python, Twisted, WSGI, etc. Backed with a simple sqlite DB, and some simple HTML/Python templating, just using dict-expansion: # template.html contains content like #

field1 = %(field1)s

template = file('template.html').read() : : params = { "field1": "value1", "field2": "value2", } : : return template % params Just set up the values in the params-dict, and use it to display your template. -tkc [1] http://docs.python.org/library/cgi.html [2] http://www.boddie.org.uk/python/WebStack.html From kyosohma at gmail.com Tue Jan 27 16:54:48 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 13:54:48 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: <86afa476-22d6-463e-b4f1-d193a8d3501e@w1g2000prm.googlegroups.com> On Jan 27, 2:52?pm, Duncan Booth wrote: > Thorsten Kampe wrote: > > * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) > >> On Jan 27, 12:00?pm, Paul Rubin wrote: > >> > Guido does post here once in a while, under his own name. ?I can't > >> > think of any very recent examples, but I can remember some from a few > >> > years back. > > >> I searched the archives for "Guido van Rossum" and there is nothing > >> since May 2000. That's the most recent i could find anyway?? > > > Search again - the last was in December 2008: > >http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= > > 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 > > &as_maxd=1&as_maxm=1&as_maxy=2009 > > &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa > > fe=off > > Or even: > > http://groups.google.com/groups/profile?show=more&enc_user=RVb59hAAAA... > > which shows 456 posts to clp over the last 9 years, but only about once a > year for the last 3 years. > > For comparison, according to Google I've managed 2251 posts to clp since 1997 > which I find kind of scary. That's not scary! I've managed over 1100 posts since 2007... Mike From vincent at vincentdavis.net Tue Jan 27 16:57:52 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 14:57:52 -0700 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: <77e831100901271357h2ac39589u2fbf2c7556f2e42c@mail.gmail.com> using terminal and opening"In Vincent's case (EPD), this would be /Library/Frameworks/Python/Versions/Current/bin/idle2.5" Worked!! Thanks for the help. Vincent Davis On Tue, Jan 27, 2009 at 2:42 PM, Robert Kern wrote: > On 2009-01-27 13:40, Ned Deily wrote: > >> In article >> <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, >> Vincent Davis wrote: >> >>> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it >>> states I can change he text coloring by using "Configure IDLE" but I not >>> sure what this is. It's not sn the menu, running Configure does nothing. >>> How >>> do I change the color (text and background) >>> >> >> There is supposed to be a Preferences menu option for IDLE on OS X but, >> depending on the Python version and how IDLE is launched, it may or may >> not appear due to various bugs. (I'm working on some patches for these.) >> > > I'd love to get these patches so we can include them in EPD. Is there an > issue on the Python bug tracker that I can follow? > > If you have been launching IDLE via /Applications/MacPython >> 2.5/IDLE.app, try launching it via the shell command line: >> /usr/local/bin/idle2.5. >> > > In Vincent's case (EPD), this would be > /Library/Frameworks/Python/Versions/Current/bin/idle2.5 . > > There may now be a working Preferences menu >> item under the Python item in the menu bar; there may also be an Options >> -> Configure IDLE... . >> > > Yes, to both. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Tue Jan 27 17:16:26 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 14:16:26 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: In article , Robert Kern wrote: > On 2009-01-27 13:40, Ned Deily wrote: > > There is supposed to be a Preferences menu option for IDLE on OS X but, > > depending on the Python version and how IDLE is launched, it may or may > > not appear due to various bugs. (I'm working on some patches for these.) > I'd love to get these patches so we can include them in EPD. Is there an > issue > on the Python bug tracker that I can follow? Not yet but soon. I ran across this recently with bug squashing of Python 3 on OSX and it's still not quite fixed. I'll ping back here when the issue/patch is filed. In article <77e831100901271357h2ac39589u2fbf2c7556f2e42c at mail.gmail.com>, Vincent Davis wrote: > Worked!! Yay! -- Ned Deily, nad at acm.org From toby at tobiah.org Tue Jan 27 17:30:29 2009 From: toby at tobiah.org (Tobiah) Date: Tue, 27 Jan 2009 14:30:29 -0800 Subject: len() Message-ID: Just out of curiosity, why was len() made to be it's own function? I often find myself typing things like my_list.len before I catch myself. Thanks, Toby From tino at wildenhain.de Tue Jan 27 17:43:00 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 27 Jan 2009 23:43:00 +0100 Subject: USB in python In-Reply-To: <49797836.5020807@al.com.au> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: <497F8DF4.4070303@wildenhain.de> Hi, Astan Chee wrote: > > Diez B. Roggisch wrote: >>> >> >> If all you need is on-off - why can't you just use a switch? >> >> >> > Because I want to control the on-off the device using a computer and > write software for it (which I am confident I can do if I had references > to how the wrappers to said interface). What I'm using is dallas 1wire stuff to do such things. The dongle (which is available as USB too) connects to the host and you have a lib with bindings even to python for it: http://www.owfs.org/ The other end is just a bus with a telephone wire... The most interesting part might be temperature sensors but there are a lot of GPIO chips, electronic resistors, A/D converters etc. available. Most of the stuff can be even ordered as sample from dallas/maxim. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mensanator at aol.com Tue Jan 27 17:44:45 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 27 Jan 2009 14:44:45 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> Message-ID: On Jan 27, 11:53?am, rantingrick wrote: > On Jan 27, 10:12?am, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > All you can say is that he didn't *post* here (at least under his real > > identity...) for the 9 past years - this doesn't mean he never *reads* > > (and this, you just have no way to know). > > Ah, this is a good point. You have to wonder, Guido could be one of > the regulars here. very interesting. We should have a vote as to who > would be the most likely candidate, now that would be a good thread :) It's not me!! :-) From david at boddie.org.uk Tue Jan 27 17:58:18 2009 From: david at boddie.org.uk (David Boddie) Date: Tue, 27 Jan 2009 23:58:18 +0100 Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: On Tuesday 27 January 2009 18:29, Gabriel Genellina wrote: > En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas > escribi?: > >> Hello all, This is my first post to this mailing list. Our requirement >> is to invoke a Tkinter python panel from a C++ GUI app where both GUI >> windows would run in 2 separate threads. We have written a sample PyQt >> application which calls this Tk panel using something like this:class >> TkPanel(threading.Thread):def run(self): # call showPaneldef >> showPanel():# create window = Tk.Tk() window.mainloop()def start():t = >> TkPanel()t.start()Now we call this from our main python code:def >> startPanel(self): import tkPanel tkPanel.start() # this calls >> tkwindow.mainloop() in a separate thread.This works absolutely fine when >> the invoking app is Python. > > From the above description I don't see where PyQt is involved. Do you > really want to mix Qt and Tk in the same application? I don't think they > could coexist... It's been made to work before: http://www.froglogic.com/pg?id=Products&category=tq&sub=overview Since Rajorshi has posted this to the PyQt list and qt-interest, in addition to this list, maybe it's time to take a look at the problem more closely: http://www.riverbankcomputing.com/pipermail/pyqt/2009-January/021649.html Without being able to see behind the scenes at what is happening with each framework, we can only say that it looks like some threading issue (possibly just an implementation detail of either framework) is causing control to be returned to the interpreter from within the wrong thread. Maybe it's just an issue of competing event loops and Python C API usage in the extension modules. I found that, using Ubuntu 7.10, the windows stopped receiving repaint events, making it look like the application had frozen. Basically, I think some kind of Qt-Tk event loop integration is required if widgets from both frameworks are going to coexist within the same process. David From joseph.a.marlin at gmail.com Tue Jan 27 18:06:46 2009 From: joseph.a.marlin at gmail.com (joseph.a.marlin at gmail.com) Date: Tue, 27 Jan 2009 15:06:46 -0800 (PST) Subject: New to python, open source Mac OS X IDE? Message-ID: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Greetings! I've heard enough raving about Python, I'm going to see for myself what all the praise is for! I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you even use an IDE for Python? Any recommendations on open source Python environments? Thanks! From joncle at googlemail.com Tue Jan 27 18:08:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 15:08:08 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> Message-ID: <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> On Jan 27, 9:41?pm, alex wrote: > Hello everybody > I am mainly a Fortran programmer and beginning to learn Python(2.5) > and OOP programming. > I hope in the end to put a GUI on my existing Fortran code. > Therefore I am also trying to learn Python's "ctypes" library. > > Unfortunately the ctypes tutorial does not show simple examples so I > set up a simple fortran module > and Python script to test. > But even with passing Integer and Real values I get the right output > but with subsequent error: > ValueError: Procedure probably called with too many arguments (4 bytes > in excess) > The scripts exits then, so the second subroutine call does not happen. > > From reading comp.lang.python and comp.lang.fortran I understood that > passing character strings > may not be simple but I could not find any solution to my problem. > Maybe somebody can help me with solving it? > > The Fortran module (footst.f90): > > ! > ? ? ? module footst > ! > ? ? ? implicit none > ! > ! > !- End of module header > ------------------------------------------------ > ! > !- Execution part of the module > ---------------------------------------- > ! > ! > ? ? ? contains > !- Define procedures contained in this module. > ! > !----------------------------------------------------------------------- > ! > ! > ? ? ? subroutine foo1(int_tst) > ? ? ? !DEC$ ATTRIBUTES DLLEXPORT :: foo1 > ? ? ? integer, intent(in):: int_tst > ? ? ? write(unit=*, fmt="(a)") "Subroutine foo1(int_tst)" > ? ? ? write(unit=*, fmt="(a, i4)") "a= ", int_tst > ? ? ? end subroutine foo1 > ! > ! > ? ? ? subroutine foo2(real_tst) > ? ? ? !DEC$ ATTRIBUTES DLLEXPORT :: foo2 > ? ? ? real, intent(in):: real_tst > ? ? ? write(unit=*, fmt="(a)") "Subroutine foo2(real_tst)" > ? ? ? write(unit=*, fmt="(a, f6.2)") "a= ", real_tst > ? ? ? end subroutine foo2 > ! > ! > ? ? ? end module footst > ! > > The Python script (footst.py): > > #!/usr/bin/env python > # > # > from ctypes import * > # > # > if __name__ == '__main__': > ? ? tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") > # ? ?tst.restype=None > # ? ?tst.argtypes=(c_int) > ? ? x=c_int(999) > ? ? y=c_float(10.5) > ? ? tst.footst_mp_foo1_(byref(x)) > # ? ?Passing Real values commented out, but leads to the same error > # ? ?tst.footst_mp_foo2_(byref(y)) > # > ? ? main() > # > # > > The DOS prompt output: > > F:\Scratch\Test2>df /dll /iface=(cref,nomixed_str_len_arg)/ > names:lowercase /assume:underscore footst.f90 > Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update B) > Copyright 2001 Compaq Computer Corp. All rights reserved. > > footst.f90 > Microsoft (R) Incremental Linker Version 6.00.8447 > Copyright (C) Microsoft Corp 1992-1998. All rights reserved. > > /entry:_DllMainCRTStartup at 12 > /ignore:505 > /debugtype:cv > /debug:minimal > /pdb:none > F:\SysTemp\obj5B.tmp > dfordll.lib > msvcrt.lib > dfconsol.lib > dfport.lib > kernel32.lib > /out:footst.dll > /dll > ? ?Creating library footst.lib and object footst.exp > > F:\Scratch\Test2>dumpbin /exports footst.dll > Microsoft (R) COFF Binary File Dumper Version 6.00.8447 > Copyright (C) Microsoft Corp 1992-1998. All rights reserved. > > Dump of file footst.dll > > File Type: DLL > > ? Section contains the following exports for footst.dll > > ? ? ? ? ? ?0 characteristics > ? ? 497F5CC3 time date stamp Tue Jan 27 20:13:07 2009 > ? ? ? ? 0.00 version > ? ? ? ? ? ?1 ordinal base > ? ? ? ? ? ?2 number of functions > ? ? ? ? ? ?2 number of names > > ? ? ordinal hint RVA ? ? ?name > > ? ? ? ? ? 1 ? ?0 00001000 footst_mp_foo1_ > ? ? ? ? ? 2 ? ?1 000010A6 footst_mp_foo2_ > > ? Summary > > ? ? ? ? 1000 .data > ? ? ? ? 1000 .rdata > ? ? ? ? 1000 .reloc > ? ? ? ? 1000 .text > > F:\Scratch\Test2>footst.py > Subroutine foo1(int_tst) > a= ?999 > Traceback (most recent call last): > ? File "F:\Scratch\Test2\footst.py", line 13, in > ? ? tst.footst_mp_foo1_(byref(x)) > ValueError: Procedure probably called with too many arguments (4 bytes > in excess) > > F:\Scratch\Test2> Have you tried: tst.footst_mp_foo1_.restype = None tst.footst_mp_foo1_(byref(x)) IIRC, the restype is applied to each function, not the library module. good luck, Jon From ori.livneh at gmail.com Tue Jan 27 18:15:51 2009 From: ori.livneh at gmail.com (Ori Livneh) Date: Tue, 27 Jan 2009 18:15:51 -0500 Subject: len() In-Reply-To: References: Message-ID: I'm newish to Python, so this might be way off-base, but I think it this might help: Allen Downey explains in "Think Python" that *"the syntax of a function call suggests that the function is the active agent."* So you're calling the function len() and telling it you have an object for it to measure. By contrast, method invocations suggest that the objects are the active agents. Python syntax does not always follow this implicit logic, but I think it makes sense here. On Tue, Jan 27, 2009 at 5:30 PM, Tobiah wrote: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. > > Thanks, > > Toby > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 27 18:16:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 21:16:02 -0200 Subject: len() References: Message-ID: En Tue, 27 Jan 2009 20:30:29 -0200, Tobiah escribi?: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list and http://groups.google.com/group/comp.lang.python/browse_thread/thread/782dcb8d62f28cdb/1480c3f3a1bf68bb#1480c3f3a1bf68bb -- Gabriel Genellina From philip at semanchuk.com Tue Jan 27 18:23:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 18:23:35 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <2FA0EA5B-35C2-49AE-84D6-6EF90E015C12@semanchuk.com> On Jan 27, 2009, at 6:06 PM, joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? Some people do; I don't. > Any recommendations on open source Python environments? I don't like single-use environments; I work frequently in Python, C, SQL, HTML, etc. and I prefer a general programmer's editor rather than switching applications based on which language I'm using. For that reason I can't give you any advice on Python-specific environments. My favorite open source editor on OS X that groks Python is jEdit. I, however, use the non-open source TextMate. It's very programmable and has a lot of user-contributed goodies. The community around it has somewhat of an open source ethic even if the main application is not. You could also use XCode which isn't open source, but it is free. HTH and welcome to Python From nad at acm.org Tue Jan 27 18:29:07 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 15:29:07 -0800 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: In article <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3 at i24g2000prf.googlegroups.com>, "joseph.a.marlin at gmail.com" wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? Well, there's IDLE that comes packaged with most Python distributions (today must be IDLE day). It may not be on your default path, though. If you are using the python Apple includes with OS X 10.5, you should be able to launch it from a terminal shell with: /usr/bin/python/../idle There is also a separate discussion group for Python on Macs: -- Ned Deily, nad at acm.org From fabiofz at gmail.com Tue Jan 27 18:31:58 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 21:31:58 -0200 Subject: Why doesn't eval of generator expression work with locals? Message-ID: Hi All, Anyone knows why the code below gives an error? global_vars = {} local_vars = {'ar':["foo", "bar"], 'y':"bar"} print eval('all((x == y for x in ar))', global_vars, local_vars) Error: Traceback (most recent call last): File "C:\temp\work\test\src\a.py", line 3, in print eval('all((x == y for x in ar))', global_vars, local_vars) File "", line 1, in File "", line 1, in NameError: global name 'y' is not defined Note that if a list is used instead of a generator it works... Thanks, Fabio From benjamin.kaplan at case.edu Tue Jan 27 18:38:57 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 18:38:57 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 6:06 PM, joseph.a.marlin at gmail.com < joseph.a.marlin at gmail.com> wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! Personally, I like Eclipse with the Pydev plugin. I believe that there is a plugin for Netbeans, but I don't know how well it works. There are also a couple of Python IDEs written in Python, like IDLE, which comes in the standard install, and SPE (http://pythonide.blogspot.com/). The Python wiki has a list of all the major Python IDEs if you want to look at others. http://wiki.python.org/moin/IntegratedDevelopmentEnvironments > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Tue Jan 27 18:41:55 2009 From: joe at strout.net (Joe Strout) Date: Tue, 27 Jan 2009 16:41:55 -0700 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <497F9BC3.4080107@strout.net> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? I don't -- I just use TextWrangler and a Terminal window. I tried several IDEs and didn't really find any of them stable and feature-rich enough to be worth the bother (though Editra came close). Lack of a really top-notch IDE is one of the primary drags harshing on my Python buzz (as the young people say). Best, - Joe From andre.roberge at gmail.com Tue Jan 27 18:47:59 2009 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Tue, 27 Jan 2009 15:47:59 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > If you already use netbeans, what about http://www.netbeans.org/features/python/ ? > Any recommendations on open source Python environments? I like Komodo Edit (which has many IDE like features). In fact, I like it so much that I decided to buy the Komodo IDE - the only non- free software I use. Andr? > > Thanks! From prologic at shortcircuit.net.au Tue Jan 27 18:51:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 09:51:37 +1000 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: > Anyone knows why the code below gives an error? > > global_vars = {} > local_vars = {'ar':["foo", "bar"], 'y':"bar"} > print eval('all((x == y for x in ar))', global_vars, local_vars) y is undefined in your generator expression. Why are you using eval ? cheers James From excord80 at gmail.com Tue Jan 27 18:53:21 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 15:53:21 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <11afaa71-cfb0-4112-abd3-5bc6dace13af@q30g2000prq.googlegroups.com> On Jan 27, 4:52?pm, Tim Chase wrote: > > I need to make a small, relatively low-traffic site that users can > > create accounts on and log into. Scripts must run as cgi (no > > mod_python or FastCGI is available). Can anyone recommend a small and > > simple web framework for Python, maybe similar to Perl's > > CGI::Application? > > > Or would it just be better to roll my own? > > What are you looking for in your framework? ?Python comes with > its own CGI module[1]. ?For the most basic of sites, this works > nicely. > > However, if you want to be able to easily slide into a bigger > environment, I've been pleased with WebStack[2] for my > lightweight needs. ?[snip] Thanks, Tim. I don't think WebStack is what I'm looking for, but will investigate doing things by hand with the cgi module and using Python's own built-in simple templating. From fabiofz at gmail.com Tue Jan 27 18:56:55 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 21:56:55 -0200 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On Tue, Jan 27, 2009 at 9:51 PM, James Mills wrote: > On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: >> Anyone knows why the code below gives an error? >> >> global_vars = {} >> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >> print eval('all((x == y for x in ar))', global_vars, local_vars) > > y is undefined in your generator expression. Yes... but why? It seems to me like it should be defined (if I put the locals in the globals it finds it... seems very weird to me) > Why are you using eval ? I'm using it to evaluate what the user entered on a watch expression in the Pydev debugger (bug: https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 )... That's just a sample to reproduce it without any dependencies. Cheers, Fabio From joncle at googlemail.com Tue Jan 27 18:59:26 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 15:59:26 -0800 (PST) Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: On Jan 27, 11:31?pm, Fabio Zadrozny wrote: > Hi All, > > Anyone knows why the code below gives an error? > > global_vars = {} > local_vars = {'ar':["foo", "bar"], 'y':"bar"} > print eval('all((x == y for x in ar))', global_vars, local_vars) > > Error: > > Traceback (most recent call last): > ? File "C:\temp\work\test\src\a.py", line 3, in > ? ? print eval('all((x == y for x in ar))', global_vars, local_vars) > ? File "", line 1, in > ? File "", line 1, in > NameError: global name 'y' is not defined > > Note that if a list is used instead of a generator it works... > > Thanks, > > Fabio I tend to think of it as a generator produces another scope, gets refactored into something similar to: def yourfunc(ar): for x in ar: yield x == y Which doesn't work either, however, if you introduce a global y the function can access it (similar if you add y to your global_vars). It's basically one of those scope/closure gotcha's along with lambdas (which was discussed quite heavily recently). hth, Jon From joseph.a.marlin at gmail.com Tue Jan 27 19:13:51 2009 From: joseph.a.marlin at gmail.com (joseph.a.marlin at gmail.com) Date: Tue, 27 Jan 2009 16:13:51 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> Message-ID: <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> On Jan 27, 6:47?pm, Andr? wrote: > On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" > > wrote: > > Greetings! I've heard enough raving about Python, I'm going to see for > > myself what all the praise is for! > > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > > even use an IDE for Python? > > If you already use netbeans, what abouthttp://www.netbeans.org/features/python/ > ? > Wow, you guys are fast... yes, I was having trouble deciding between that (Netbeans), Smultron, or TextWrangler. Thanks! From excord80 at gmail.com Tue Jan 27 19:15:14 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 16:15:14 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Jan 27, 4:52?pm, Tim Chase wrote: > > I need to make a small, relatively low-traffic site that users can > > create accounts on and log into. Scripts must run as cgi (no > > mod_python or FastCGI is available). Can anyone recommend a small and > > simple web framework for Python, maybe similar to Perl's > > CGI::Application? > > > Or would it just be better to roll my own? > > What are you looking for in your framework? Well, let's see. I don't need a templating library, since -- as you pointed out -- I can just use Python's own. I don't need a db interface (can just make my own dbapi calls if needed). Don't need url mapping (can just use mod_rewrite rules in my .htaccess to point at my cgi scripts). Don't think I need any i80n. And I don't need an admin interface. ... It would seem that I don't need a whole lot at the moment. From robert.kern at gmail.com Tue Jan 27 19:17:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 18:17:16 -0600 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On 2009-01-27 17:56, Fabio Zadrozny wrote: > On Tue, Jan 27, 2009 at 9:51 PM, James Mills > wrote: >> On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: >>> Anyone knows why the code below gives an error? >>> >>> global_vars = {} >>> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >>> print eval('all((x == y for x in ar))', global_vars, local_vars) >> y is undefined in your generator expression. > > Yes... but why? It seems to me like it should be defined (if I put the > locals in the globals it finds it... seems very weird to me) I think you can work around your problem by using the same dictionary for both locals and globals. The locals/globals distinction is not useful in your circumstances. For example, the Python interpreter has these the same: >>> globals() is locals() True And that makes the code work: >>> y = 'bar' >>> ar = ['foo', 'bar'] >>> all((x==y) for x in ar) False >>> eval('all((x==y) for x in ar)') False Making locals and globals different emulates a function, where the code will fail: >>> del y, ar >>> def f(): ... y = 'bar' ... ar = ['foo', 'bar'] ... print 'Raw genexp:', all((x==y) for x in ar) ... print 'Evaled:', eval('all((x==y) for x in ar)') ... >>> f() Raw genexp: False Evaled: Traceback (most recent call last): File "", line 1, in File "", line 5, in f File "", line 1, in File "", line 1, in NameError: global name 'y' is not defined Now, the reason that the raw generator expression works inside the function but not in the eval() is because the raw generator expression gets lexical scopes rather than just the two locals and globals dicts. Lexical scoping is not available to the eval() function. -- 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 prologic at shortcircuit.net.au Tue Jan 27 19:28:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 10:28:49 +1000 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Wed, Jan 28, 2009 at 10:15 AM, excord80 wrote: > Well, let's see. I don't need a templating library, since -- as you > pointed out -- I can just use Python's own. I don't need a db > interface (can just make my own dbapi calls if needed). Don't need url > mapping (can just use mod_rewrite rules in my .htaccess to point at my > cgi scripts). Don't think I need any i80n. And I don't need an admin > interface. ... It would seem that I don't need a whole lot at the > moment. One option is to configure Apache with mod_wsgi and just use WSGI. Fairly simple really and much like CGI. cheers James From fabiofz at gmail.com Tue Jan 27 19:36:05 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 22:36:05 -0200 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: > I think you can work around your problem by using the same dictionary for > both locals and globals. The locals/globals distinction is not useful in > your circumstances. For example, the Python interpreter has these the same: > > >>> globals() is locals() > True > Interesting... In my case, what I actually do (in the Pydev debugger) is that I find the frame where the code should be evaluated and then with the selected frame I do: frame = findframe(...) ... eval(expression, frame.f_globals, frame.f_locals) So, in that case, you think that instead of using frame.f_globals I should use: updated_globals = dict() updated_globals.update(frame.f_globals) updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals eval(expression, updated_globals, frame.f_locals) Is that it? -- I think that eval(expression, frame.f_locals, frame.f_locals) wouldn't work as expected in my actual case... (and I can't force the frame.f_globals and frame.f_locals to be the same) Thanks, Fabio From sjmachin at lexicon.net Tue Jan 27 19:41:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 16:41:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> Message-ID: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> On Jan 27, 6:17?pm, "Martin v. L?wis" wrote: > > Well, the first step would be to tell Python that there is a code page > > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > > doing "chcp 65001". I checked the list of aliases in Python 3 and there > > was no entry for cp65001. > > I see. What happens if you add it to encoding/aliases.py? A slight improvement. Get this: C:\junk\console>chcp 65001 Active code page: 65001 C:\junk\console>python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys; sys.stdout.encoding 'cp65001' >>> print u'\xff' Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: cp65001 >>> print u'\xff'.encode('utf8') Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied >>> Adding an entry to ...\lib\encodings\aliases.py as suggested did fix the Lookup error; it took it straight to the same IOError as above. Next step? From jstroud at mbi.ucla.edu Tue Jan 27 19:44:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 27 Jan 2009 16:44:52 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! Try open komodo. I haven't used it because vim is my IDE, but it looks pretty good. James From gslindstrom at gmail.com Tue Jan 27 19:49:26 2009 From: gslindstrom at gmail.com (gslindstrom) Date: Tue, 27 Jan 2009 18:49:26 -0600 Subject: Python and Nagios Message-ID: Hello all- We have started using Nagios at work to monitor our computer system and have been very happy with the results. We have decided to use it monitor our business processes as well, so I needed to write custom plug-ins and I opted to use Python because I am very comfortable with it. I found an excellent paper by Cameron Laird and Wojciech Kocjan showing the basics (thanks, guys!) and I have written plugins to verify the arrival and departure of files as well as the completion of business processes. We plan to use Nagios to report on file audits and reprocess jobs that have failed because a database or Internet connection burps. We have great plans for Nagios and I intend to submit a paper to next years PyCon showing what we have done. What I would like to know is if there is anything resembling a package to help with plugin deveopment with Python. I have a base class that provides most of the GNU plugin requirements (warning and critical threshold pattern processing, logging requirements, etc) and would like to work on creating something to release for general use, but I don't want to reinvent the wheel. Is there anything close to what I'm suggesting out there? I've looked in the standard places and have not located anything. I will continue to add to my local package and, if I don't hear about a similar effort, will look to create something for the Cheese Shop. If you are interested in helping out, please drop me a line via the list or at gslindstrom via gmail. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Tue Jan 27 19:53:40 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 16:53:40 -0800 (PST) Subject: Spam making a comeback?? Message-ID: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> Seems like the level of spam is increasing in the last week, and today has been bad. How are the spambytes coming along? From cosmo_general at yahoo.com Tue Jan 27 19:59:52 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Tue, 27 Jan 2009 16:59:52 -0800 (PST) Subject: How to execute a hyperlink? Message-ID: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Hi Folks, Module os provides a means of running shell commands, such as: import os os.system('dir .') will execute command dir I think a hyperlink should also be executed. I tried: os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') but I got kicked out by the Python interpreter. I wonder somebody knows the syntax of triggering a hyperlink? Thanks in advance! Muddy Coder From philip at semanchuk.com Tue Jan 27 20:04:49 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 20:04:49 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <87FD47BC-A7A1-4211-8C90-27E1FBEB6BC2@semanchuk.com> On Jan 27, 2009, at 7:44 PM, James Stroud wrote: > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see >> for >> myself what all the praise is for! >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> Any recommendations on open source Python environments? >> Thanks! > > Try open komodo. I haven't used it because vim is my IDE, but it > looks pretty good. I second that; I had used it for a while but had forgotten about it. From joncle at googlemail.com Tue Jan 27 20:06:04 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 17:06:04 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <34593f65-0c08-430f-951b-a0ca9967d675@r15g2000prd.googlegroups.com> On Jan 28, 12:59?am, Muddy Coder wrote: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! > > Muddy Coder The webbrowser module springs to mind. hth Jon. From burukena at gmail.com Tue Jan 27 20:07:48 2009 From: burukena at gmail.com (Burukena) Date: Tue, 27 Jan 2009 21:07:48 -0400 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <497FAFE4.4040602@gmail.com> On 1/27/09 8:44 PM, James Stroud wrote: > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see for >> myself what all the praise is for! >> >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> >> Any recommendations on open source Python environments? >> >> Thanks! > > Try open komodo. I haven't used it because vim is my IDE, but it looks > pretty good. > > James > -- > http://mail.python.org/mailman/listinfo/python-list > Vim and a terminal works for me, specifically with screen. Second choice would be TextMate but I have not used it in quite a while. From benjamin.kaplan at case.edu Tue Jan 27 20:11:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 20:11:35 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 7:41 PM, John Machin wrote: > On Jan 27, 6:17 pm, "Martin v. L?wis" wrote: > > > Well, the first step would be to tell Python that there is a code page > > > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > > > doing "chcp 65001". I checked the list of aliases in Python 3 and there > > > was no entry for cp65001. > > > > I see. What happens if you add it to encoding/aliases.py? > > A slight improvement. Get this: > > C:\junk\console>chcp 65001 > Active code page: 65001 > > C:\junk\console>python > Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys; sys.stdout.encoding > 'cp65001' > >>> print u'\xff' > Traceback (most recent call last): > File "", line 1, in > LookupError: unknown encoding: cp65001 > >>> print u'\xff'.encode('utf8') > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied > >>> > > Adding an entry to ...\lib\encodings\aliases.py as suggested did fix > the Lookup error; it took it straight to the same IOError as above. > > Next step? Wait for Microsoft to catch up to everyone else? I tried this on Windows 7 beta. I didn't get an IOError, but the command prompt apparently doesn't understand the concept of a multi-byte character. u'\xff' showed as 2 unprintable characters. At least it's an improvement. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.lyon at preisshare.net Tue Jan 27 20:12:58 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Tue, 27 Jan 2009 20:12:58 -0500 Subject: New to python, open source Mac OS X =?UTF-8?Q?IDE=3F?= In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <80fbd490849f69f97ea4ceb5a65f6b09@preisshare.net> > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see for >> myself what all the praise is for! >> >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> >> Any recommendations on open source Python environments? Quite a good one is Boa Constructor, it is a reasonable IDE From excord80 at gmail.com Tue Jan 27 20:48:47 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 17:48:47 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <4dadc5ea-21a1-4ebd-ba91-94189541559f@13g2000yql.googlegroups.com> On Jan 27, 7:28?pm, James Mills wrote: > > One option is to configure Apache with mod_wsgi and just > use WSGI. Fairly simple really and much like CGI. This is a shared hosting arrangement, so I don't have the option of adding an apache module. Also, if it's much like CGI, I don't see what benefit it would provide over CGI in this situation. From Graham.Dumpleton at gmail.com Tue Jan 27 20:52:35 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 27 Jan 2009 17:52:35 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Jan 28, 11:28?am, James Mills wrote: > On Wed, Jan 28, 2009 at 10:15 AM, excord80 wrote: > > Well, let's see. I don't need a templating library, since -- as you > > pointed out -- I can just use Python's own. I don't need a db > > interface (can just make my own dbapi calls if needed). Don't need url > > mapping (can just use mod_rewrite rules in my .htaccess to point at my > > cgi scripts). Don't think I need any i80n. And I don't need an admin > > interface. ... It would seem that I don't need a whole lot at the > > moment. > > One option is to configure Apache withmod_wsgiand just > use WSGI. Fairly simple really and much like CGI. Worth highlighting with mod_wsgi is that you also don't have to have everything inside of one WSGI application and can still use CGI like approach of lots of WSGI script files. That is, you are relying on Apache dispatching of URLs for file based resources and thus no Python specific dispatcher needed, nor mod_rewrite rules. Because each WSGI script files is given their own persistent sub interpreter by default, with this approach you probably though want to force them to all run in same sub interpreter to reduce memory usage. This can be done using WSGIApplicationGroup directive. For further information see: http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive Graham From sjmachin at lexicon.net Tue Jan 27 21:03:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 18:03:55 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> Message-ID: <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> On Jan 28, 5:56?am, "Martin v. L?wis" wrote: > > #include "stdio.h" > > int main(int argc, char **argv) { > > ? ? printf("<\xc2\x80>\n"); > > ? ? } > > > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) > > and using "Lucida Console" font: > > > After CHCP 1252, this prints < A-circumflex Euro >, as expected. > > After CHCP 65001, it prints < hollow-square >. > > This is not surprising: this character is U+0080, which is a control > character. Try \xe2\x82\xac instead. Doh! I'm a nutter. That works. Thanks. The only font choice offered apart from "Raster Fonts" in the Command Prompt window's Properties box is "Lucida Console", not "Lucida Sans Unicode". It will let me print Cyrillic characters from a C program, but not Chinese. I'm off looking for how to get a better font. Cheers, John From gagsl-py2 at yahoo.com.ar Tue Jan 27 21:06:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 00:06:17 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern escribi?: > On 2009-01-27 17:56, Fabio Zadrozny wrote: > Making locals and globals different emulates a function, where the code > will fail: > > >>> del y, ar > >>> def f(): > ... y = 'bar' > ... ar = ['foo', 'bar'] > ... print 'Raw genexp:', all((x==y) for x in ar) > ... print 'Evaled:', eval('all((x==y) for x in ar)') > ... > >>> f() > Raw genexp: False > Evaled: > Traceback (most recent call last): > File "", line 1, in > File "", line 5, in f > File "", line 1, in > File "", line 1, in > NameError: global name 'y' is not defined > > Now, the reason that the raw generator expression works inside the > function but not in the eval() is because the raw generator expression > gets lexical scopes rather than just the two locals and globals dicts. > Lexical scoping is not available to the eval() function. I *thought* I did understand this until I came to this example: 1) >>> id(globals()), id(locals()) (11239760, 11239760) # ok, globals and locals are the same at the module level 2) >>> s = "(id(n) for n in [globals(),locals()])" >>> list(eval(s)) [11239760, 11239760] # still the same results 3) >>> s = "(id(n()) for n in [globals,locals])" >>> list(eval(s)) [11239760, 12583248] # locals() is different Why do I get a different locals() here? Both expressions define the same scopes, ok? That is, I'd say that both 2) and 3) define the same, nested scopes -- why the different results? Seems that this is unrelated to eval, we can take it out of the question and still get the same values: >>> list(id(n) for n in [globals(),locals()]) [11239760, 11239760] >>> list(id(n()) for n in [globals,locals]) [11239760, 12583248] Worse, it isn't the new, inner scope of generator expressions. A list comprehension gives the same results: >>> [id(n) for n in [globals(),locals()]] [11239760, 11239760] >>> [id(n()) for n in [globals,locals]] [11239760, 12583248] Seems that it is important *when* those functions are evaluated, but I don't understand *why*... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Jan 27 21:16:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 00:16:29 -0200 Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 00:03:55 -0200, John Machin escribi?: > On Jan 28, 5:56?am, "Martin v. L?wis" wrote: >> > #include "stdio.h" >> > int main(int argc, char **argv) { >> > ? ? printf("<\xc2\x80>\n"); >> > ? ? } >> >> > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) >> > and using "Lucida Console" font: >> >> > After CHCP 1252, this prints < A-circumflex Euro >, as expected. >> > After CHCP 65001, it prints < hollow-square >. >> >> This is not surprising: this character is U+0080, which is a control >> character. Try \xe2\x82\xac instead. > > Doh! I'm a nutter. That works. Thanks. The only font choice offered > apart from "Raster Fonts" in the Command Prompt window's Properties > box is "Lucida Console", not "Lucida Sans Unicode". It will let me > print Cyrillic characters from a C program, but not Chinese. I'm off > looking for how to get a better font. In this post, Raymond Chen explains all the conditions a font must met to actually be usable in a console window: http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx In short, most TrueType font's (even the fixed-width ones) aren't eligible. -- Gabriel Genellina From n.kottiyath at gmail.com Tue Jan 27 21:57:25 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 18:57:25 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> Message-ID: <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> On Jan 27, 11:56?pm, Mike Driscoll wrote: > On Jan 27, 12:12?pm, Kottiyath wrote: > > > > > Hi, > > ? ?I would like to obtain pyAA for Python 2.5. I went through their > > web site, but they provide the windows exe only for Python2.4. I tried > > compiling from source, but that also was to no avail - it errs out as > > follows: > > > C:\Documents and Settings\Guest\pyAA>python setup.py install > > running install > > running build > > running build_py > > file pyAAc.py (for module pyAAc) not found > > file pyAAc.py (for module pyAAc) not found > > running build_ext > > error: Python was built with Visual Studio 2003; > > extensions must be built with a compiler than can generate compatible > > binaries. > > Visual Studio 2003 was not found on this system. If you have Cygwin > > installed, > > you can try compiling with MingW32, by passing "-c mingw32" to > > setup.py. > > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > > mingw32 > > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > > ? ?or: setup.py --help [cmd1 cmd2 ...] > > ? ?or: setup.py --help-commands > > ? ?or: setup.py cmd --help > > > error: invalid command 'mingw32' > > > Has anyone tried the same? Can anyone give any suggestions? > > You probably have to put mingw32 on your path or provide an absolute > path to it. By the way, where did you get the source? I couldn't find > it... > > Mike I have mingw32-gcc in my path. If I try that too -it fails. C:\Documents and Settings\Guest\pyAA>python setup.py install -c "mingw32-gcc" invalid command name 'mingw32-gcc' I got the source from http://sourceforge.net/cvs/?group_id=65529 Can somebody help me out? Our project needs pyAA, but I am unable to build on Python2.5. From benjamin.kaplan at case.edu Tue Jan 27 22:13:49 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 22:13:49 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 9:16 PM, Gabriel Genellina wrote: > En Wed, 28 Jan 2009 00:03:55 -0200, John Machin > escribi?: > > On Jan 28, 5:56 am, "Martin v. L?wis" wrote: >> >>> > #include "stdio.h" >>> > int main(int argc, char **argv) { >>> > printf("<\xc2\x80>\n"); >>> > } >>> >>> > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) >>> > and using "Lucida Console" font: >>> >>> > After CHCP 1252, this prints < A-circumflex Euro >, as expected. >>> > After CHCP 65001, it prints < hollow-square >. >>> >>> This is not surprising: this character is U+0080, which is a control >>> character. Try \xe2\x82\xac instead. >>> >> >> Doh! I'm a nutter. That works. Thanks. The only font choice offered >> apart from "Raster Fonts" in the Command Prompt window's Properties >> box is "Lucida Console", not "Lucida Sans Unicode". It will let me >> print Cyrillic characters from a C program, but not Chinese. I'm off >> looking for how to get a better font. >> > > In this post, Raymond Chen explains all the conditions a font must met to > actually be usable in a console window: > http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx > In short, most TrueType font's (even the fixed-width ones) aren't eligible. > Actually, you can trick the command prompt into allowing any TrueType font, if you don't mind messing with the registry. The font won't look so good, but it will still work. Even with a font that supports Unicode (GNU FreeMono), the console still displays 3 unprintable characters rather than the single multi-byte character. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Tue Jan 27 22:15:35 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Tue, 27 Jan 2009 19:15:35 -0800 Subject: Drawing and Displaying an Image with PIL Message-ID: Here's my program: # fun and games import Image, ImageDraw im = Image.open("wagon.tif") # it exists in the same Win XP # folder as the program draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line((0,0),(20,140), fill=128) # How show this final image on a display? root.mainloop() It has two problems. One is it crashes with: draw.line((0,0),(20,140), fill=128) TypeError: line() got multiple values for keyword argument 'fill' Secondly, it has no way to display the image drawn on. Is it possible, or do I have to pass the image off to another module's methods? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From barithegreat at gmail.com Tue Jan 27 22:23:34 2009 From: barithegreat at gmail.com (barithegreat at gmail.com) Date: Tue, 27 Jan 2009 19:23:34 -0800 (PST) Subject: Receiving data from USB Message-ID: Hi Can any body tell me how can i receive data from usb(usrp) in python. From rt8396 at gmail.com Tue Jan 27 22:30:44 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 19:30:44 -0800 (PST) Subject: Drawing and Displaying an Image with PIL References: Message-ID: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> On Jan 27, 9:15?pm, "W. eWatson" wrote: > Here's my program: > > # fun and games > import Image, ImageDraw > > im = Image.open("wagon.tif") # it exists in the same Win XP > # folder as the program > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line((0,0),(20,140), fill=128) > > # How show this final image on a display? > > root.mainloop() > > It has two problems. One is it crashes with: > ? ? ?draw.line((0,0),(20,140), fill=128) > TypeError: line() got multiple values for keyword argument 'fill' > > Secondly, it has no way to display the image drawn on. Is it possible, or do > I have to pass the image off to another module's methods? > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: I have not tried your code but i think you need to put your coodinates in one tuple. Here is an example from the docs Example Example: Draw a Grey Cross Over an Image import Image, ImageDraw im = Image.open("lena.pgm") draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line((0, im.size[1], im.size[0], 0), fill=128) del draw # write to stdout im.save(sys.stdout, "PNG") Hope that helps From steve at holdenweb.com Tue Jan 27 22:36:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 22:36:57 -0500 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern > escribi?: >> On 2009-01-27 17:56, Fabio Zadrozny wrote: > >> Making locals and globals different emulates a function, where the >> code will fail: >> >> >>> del y, ar >> >>> def f(): >> ... y = 'bar' >> ... ar = ['foo', 'bar'] >> ... print 'Raw genexp:', all((x==y) for x in ar) >> ... print 'Evaled:', eval('all((x==y) for x in ar)') >> ... >> >>> f() >> Raw genexp: False >> Evaled: >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 5, in f >> File "", line 1, in >> File "", line 1, in >> NameError: global name 'y' is not defined >> >> Now, the reason that the raw generator expression works inside the >> function but not in the eval() is because the raw generator expression >> gets lexical scopes rather than just the two locals and globals dicts. >> Lexical scoping is not available to the eval() function. > > I *thought* I did understand this until I came to this example: > > 1) >>>> id(globals()), id(locals()) > (11239760, 11239760) > > # ok, globals and locals are the same at the module level > > 2) >>>> s = "(id(n) for n in [globals(),locals()])" >>>> list(eval(s)) > [11239760, 11239760] # still the same results > > 3) >>>> s = "(id(n()) for n in [globals,locals])" >>>> list(eval(s)) > [11239760, 12583248] # locals() is different > No, locals is different, not locals(). You are looking at two different functions that return the same object when called in the given context, that's all. > Why do I get a different locals() here? Both expressions define the same > scopes, ok? That is, I'd say that both 2) and 3) define the same, nested > scopes -- why the different results? > > Seems that this is unrelated to eval, we can take it out of the question > and still get the same values: > >>>> list(id(n) for n in [globals(),locals()]) > [11239760, 11239760] >>>> list(id(n()) for n in [globals,locals]) > [11239760, 12583248] > Same thing: two different functions, same result. > Worse, it isn't the new, inner scope of generator expressions. A list > comprehension gives the same results: > >>>> [id(n) for n in [globals(),locals()]] > [11239760, 11239760] >>>> [id(n()) for n in [globals,locals]] > [11239760, 12583248] > > Seems that it is important *when* those functions are evaluated, but I > don't understand *why*... > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From ben at benfinney.id.au Tue Jan 27 22:49:42 2009 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 28 Jan 2009 14:49:42 +1100 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) References: <1afaf6160901271222i2e2d9525i883367789219f96d@mail.gmail.com> <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> Message-ID: <87mydcxf6x.fsf@benfinney.id.au> (Continuing a side topic of a different discussion) Steve Holden writes: > I think that [Python 2.6 was a rushed release]. 2.6 showed it in the > inclusion (later recognizable as somewhat ill-advised so late in the > day) of multiprocessing [?] What was ill-advised about the addition of the ?multiprocessing? module to Python 2.6? I ask because I haven't yet used it in anger, and am not sure what problems have been found in it. -- \ ?Holy bouncing boiler-plated fits, Batman!? ?Robin | `\ | _o__) | Ben Finney From adi at digitaltrowel.com Tue Jan 27 23:23:19 2009 From: adi at digitaltrowel.com (Adi Eyal) Date: Wed, 28 Jan 2009 06:23:19 +0200 Subject: Python Application Server Message-ID: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Hi All Could anyone recommend a python application server? My application consists mainly of long running background processes that need to communicate with each other. Features on my wishlist include, process pooling (each process will in general be stateless), monitoring, scheduling and a framework for inter-process communication. Ideally, I would also like to be able to cluster the app server if the need arises. I have never used Zope or Webware, but my impression is that these servers are focused on web applications with a short request-response cycle. My usage will be different since my processes will be triggered by certain events and then continue running until they complete, without sending any response at all but possibly spawning off additional processes in a workflow. I hope my description has been clear. Does such an application server exist for python? Thanks in advance Adi From prologic at shortcircuit.net.au Tue Jan 27 23:36:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:36:51 +1000 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <87mydcxf6x.fsf@benfinney.id.au> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: > Steve Holden writes: >> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >> inclusion (later recognizable as somewhat ill-advised so late in the >> day) of multiprocessing [?] Steve: It's just a new package - it used to be available as a 3rd-party package. I dare say it most definitely was -not- ill-advised. It happens to be a great addition to the standard library. > What was ill-advised about the addition of the 'multiprocessing' > module to Python 2.6? I ask because I haven't yet used it in anger, > and am not sure what problems have been found in it. I have found no problems with it - I've recently integrated it with my event/component framework (1). In my library I use Process, Pipe and Value. cheers James 1. http://pypi.python.org/pypi/circuits/ From prologic at shortcircuit.net.au Tue Jan 27 23:42:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:42:16 +1000 Subject: Python Application Server In-Reply-To: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: On Wed, Jan 28, 2009 at 2:23 PM, Adi Eyal wrote: > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? Might I recommend circuits (1) as a general purpose framework that you can build your application on top of. circuits will allow you to communicate with long-running background processes, communicate between processes (by way of a Bridge). All communication in circuits is asyncroneous. circuits has also recently seen the integration of the multiprocessing package from python 2.6/3.0 so you can create processes and have inter-process communication seamlessly. In fact, parts of your system can even run on other nodes (you mentioned clustering). Feel free to talk to me more about this in detail... cheers James 1. http://pypi.python.org/pypi/circuits/ From notvalid2 at sbcglobal.net Tue Jan 27 23:43:56 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Tue, 27 Jan 2009 20:43:56 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> Message-ID: r wrote: > On Jan 27, 9:15 pm, "W. eWatson" wrote: >> Here's my program: >> >> # fun and games >> import Image, ImageDraw >> >> im = Image.open("wagon.tif") # it exists in the same Win XP >> # folder as the program >> draw = ImageDraw.Draw(im) >> draw.line((0, 0) + im.size, fill=128) >> draw.line((0,0),(20,140), fill=128) >> >> # How show this final image on a display? >> >> root.mainloop() >> >> It has two problems. One is it crashes with: >> draw.line((0,0),(20,140), fill=128) >> TypeError: line() got multiple values for keyword argument 'fill' >> >> Secondly, it has no way to display the image drawn on. Is it possible, or do >> I have to pass the image off to another module's methods? >> >> -- >> W. eWatson >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >> >> Web Page: > > I have not tried your code but i think you need to put your coodinates > in one tuple. Here is an example from the docs > > Example > Example: Draw a Grey Cross Over an Image > import Image, ImageDraw > im = Image.open("lena.pgm") > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line((0, im.size[1], im.size[0], 0), fill=128) > del draw > # write to stdout > im.save(sys.stdout, "PNG") > > Hope that helps That's pretty much the code I used. In fact, I borrowed it from the pdf. I just tried it, and it output "%PNG". I'd like to see this displayed in a window. If the fine had written properly, I could see whether it really drew the lines. It did not fail on the same draw stmts in my program. I see my problem, , instead of + between the tuples. I thought I'd seen another example where the 2-d tuples could be separated. I see a ImageFile module, but it's not for writing image files simply. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From prologic at shortcircuit.net.au Tue Jan 27 23:45:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:45:14 +1000 Subject: Python Application Server In-Reply-To: References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: On Wed, Jan 28, 2009 at 2:42 PM, James Mills wrote: (...) > Might I recommend circuits (1) as a general purpose > framework that you can build your application on top of. > > circuits will allow you to communicate with long-running > background processes, communicate between processes > (by way of a Bridge). All communication in circuits is > asyncroneous. circuits has also recently seen the integration > of the multiprocessing package from python 2.6/3.0 so you > can create processes and have inter-process communication > seamlessly. In fact, parts of your system can even run on other > nodes (you mentioned clustering). I should probably mention some of the components available (features); * TCPServer, TCPClient * UDPServer, UDPClient * HTTP, IRC and SMTP protocols * Web Server (with limited WSGI support) (depends on parts of CherryPy) * Timers, Timer * Logger, Debugger * ... there are many more components ... :) Building new components is fairly easy as well. cheers James From pavlovevidence at gmail.com Tue Jan 27 23:59:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 27 Jan 2009 20:59:29 -0800 (PST) Subject: "The application has failed to start because the application configuration is incorrect" Message-ID: Perhaps someone who's familiar with Windows XP and Python can figure this one out, because it's baffling me. I installed the following packages on a more or less clean XP system: Python 2.6.1, straight from the MSI. WxPython 2.8.9.1, straight from the windows installer. Both installed with no errors. However, all attempts to run any wx code resulted in the following exception: "Import Error: DLL load failed: The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem." In fact, this seemed to be the case for any third-party extension module. I tried several other libraries for comparison (gtk, qt); they all had the same problem, and right out of the box. After a lot of reading I figured that I didn't have the right MSVSRT DLLs on my system, and that I should install the runtime redistributable packages from Microsoft. But I find it hard to believe the state of things in Windows is that you have to ask the user to install a package from Microsoft just to run an extension library. A package, I might add, that requires Adminstrative privileges. Which I don't have. Tkinter worked fine, BTW. My questions are 1. is that really what Windows extension users are expected to do, 2. if not, what else might be wrong, and 3. are there any workarounds? Carl Banks From wuwei23 at gmail.com Wed Jan 28 00:08:16 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 27 Jan 2009 21:08:16 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: On Jan 28, 10:59?am, Muddy Coder wrote: > Module os provides a means of running shell commands [...] > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') Well, clearly all you need to do is get your system to recognise URLs as shell commands and you're set... But if you'd like the *right* tool for the job, try webbrowser. From enleverlesX.XmcX at XmclaveauX.com Wed Jan 28 00:16:55 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Wed, 28 Jan 2009 06:16:55 +0100 Subject: "The application has failed to start because the application configuration is incorrect" In-Reply-To: References: Message-ID: <497feb36$0$4094$ba4acef3@news.orange.fr> Hi! I have a similar problem, with Python 2.6.1 and pywin32. Since python 2.6.1. Return to 2.6: OK ; re-install 2.6.1: the problem return. No solution to this day. The problem is known, but not resolved In the expectation, I stay in 2.6 @-salutations -- Michel Claveau From michele.simionato at gmail.com Wed Jan 28 00:33:08 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 27 Jan 2009 21:33:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <871vuose1u.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 27, 9:13?pm, Mark Wooding wrote: > I'm referring to a number of features: > > ? * Redefinition of classes, yes. ?Interactive development is very > ? ? frustrating without this. ?Thanks for that link, by the way! > > ? * CHANGE-CLASS to change the class of instances. ?This is more than > ? ? just assigning to mumble.__class__, since it correctly initializes > ? ? the slots present in the new class which were absent in the old. > > ? * And all of the fancy MOP tricks you can play: inventing new slot > ? ? classes; messing with class-precedence-list orderings (Python's > ? ? MRO). > > It's a shorter list than I'd hoped! ?Still, these features kind of > multiply up. ?You can redefine a class using a new metaclass and slot > options, and all the instances are updated, for example. > > Anyway, I think I exaggerated when I said that CLOS was `much more > dynamic', but it is /somewhat/ more dynamic, and still amenable to > optimization; since my point was that dynamism in a language isn't > necessarily antithetical to compilation, that's still sufficient. > > Thanks for keeping me honest! Fair enough. My view is that even if apparently CLOS has some additional feature over the standard Python object model, in practice you can implement the same features in Python with some metaclass trick, *without the need to change the language at the C level*. This is why I think the Python object model is at least as dynamic as CLOS. In particular, a metaclass can implement the functionality CHANGE- CLASS, can mess with the __bases__ and with the MRO, etc. If you want to see an example of how much the Python object model can be perverted, you may be interested in this module of mine: http://pypi.python.org/pypi/strait The module changes the standard object system from a multiple inheritance one to a single inheritance one plus traits. Michele Simionato From rajorshi at in.com Wed Jan 28 00:37:31 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Wed, 28 Jan 2009 11:07:31 +0530 Subject: =?UTF-8?B?UmU6IENhbGxpbmcgUHl0aG9uLXRrIGNvZGUgZnJvbSBDL0MrKw==?= Message-ID: <1233121051.300ecf93b7224cf439b6de6ee1d6c200@mail.in.com> Thanks David. I found some help in this thread :http://mail.python.org/pipermail/cplusplussig/2006September/010814.htmlI am trying to adapt the same over for our requirements looks like we need new Python interpreters to handle the Tk UI loop. We will post back if we are able to make it work.Thanks,RajRaj http://www.rajorshi.net/blog Original message From:David Boddie< david at boddie.org.uk >Date: 28 Jan 09 04:28:18Subject:Re: Calling Pythontk code from C/C++To: pythonlist at python.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Jan 28 00:45:00 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 21:45:00 -0800 (PST) Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> Message-ID: <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> Change this line: draw.line((0,0),(20,140), fill=128) To This: draw.line((0,0, 20,140), fill=128) And you should be good to go. Like you said, if you need to combine 2 tuples you can do: (1,2)+(3,4) From steven at REMOVE.THIS.cybersource.com.au Wed Jan 28 00:46:46 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 28 Jan 2009 05:46:46 GMT Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote: > I'm not sure this is possible, but I would like to have a list of > objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that something > about the object 'a' has changed so that when I revisit A, I will know > that the other items in the list need to be refreshed to reflect the > changes in A as a result of changing 'a'. Can't be done if A is a built-in list, probably can't be done entirely generically, but you can probably do it in a cooperative manner. class TaintList(list): tainted = False def taint(self): self.tainted = True def untaint(self): self.tainted = False A = TaintList() import functools def taint(parent): def decorator(func): @functools.wraps(func) def f(*args, **kwargs): parent.taint() return func(*args, **kwargs) return f return decorator class TaintAwareThing(object): def __init__(self): self.attr = 0 @taint(A) def change_attribute(self, x): self.attr = x >>> x = TaintAwareThing() >>> y = TaintAwareThing() >>> z = TaintAwareThing() >>> >>> A.extend([x, y, z]) >>> A.tainted False >>> x.change_attribute(5) >>> A.tainted True Here is a second approach: create a proxy class TaintThing that wraps whatever object you want, using delegation: class TaintThing(object): parent = A def __init__(self, obj): self.__dict__['_proxy'] = obj def __getattr__(self, attr): return getattr(self._proxy, attr) def __setattr__(self, attr, value): setattr(self._proxy, attr, value) self.parent.taint() Now change TaintList to automatically wrap anything stored in it: # untested class TaintList(list): def append(self, obj): list.append(self, TaintThing(obj)) # similar for __setitem__, extend, insert -- Steven From pavlovevidence at gmail.com Wed Jan 28 01:11:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 27 Jan 2009 22:11:32 -0800 (PST) Subject: "The application has failed to start because the application configuration is incorrect" References: <497feb36$0$4094$ba4acef3@news.orange.fr> Message-ID: <6a8296a1-be68-4c9e-bfab-532770251660@p23g2000prp.googlegroups.com> On Jan 27, 9:16?pm, "M?ta-MCI \(MVP\)" wrote: > Hi! > > I have a similar problem, with Python 2.6.1 and pywin32. Since python > 2.6.1. > Return to 2.6: OK ; re-install 2.6.1: the problem return. > No solution to this day. > The problem is known, but not resolved > In the expectation, I stay in 2.6 Whoa--it did NOT occur to me that the bug was in Python. Sure enough, bug tracker has big thread about it, and a neat fix. http://bugs.python.org/issue4566 Thanks. Reverting to 2.6.0 should suffice for now. Carl Banks From berankin99 at yahoo.com Wed Jan 28 01:16:16 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Tue, 27 Jan 2009 22:16:16 -0800 (PST) Subject: Python Package Managment References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> Message-ID: <596392.54834.qm@web112214.mail.gq1.yahoo.com> [extracted from pylons-discuss] > >> I hate to pass the buck, but this is Python's fault for not having > >> reliable package management built in. There's nothing Pylons can do > >> about it except switch to another programming language. > > [SNIP] > > Without Setuptools, > Pylons and TurboGears couldn't exist, and Zope and Twisted > would not have been able to split themselves into several packages. > People coming to Python from Perl and Ruby expect to be able to just > run a command to download and install a package. That problem was > solved ten years ago, so why does Python still not have it standard? > > If Setuptools and Virtualenv or the equivalent were built into Python, > you could trust that every computer that has successfully installed > Python can install packages and make virtual environments the same > way.. > > That would eliminate 2/3 of the problems users have when > installing Pylons, and the subsequent need to explain the problems and > workarounds in the installation docs. At > work people say, "Half the trouble of Pylons is installing it", and I > often have to help them install it in person because otherwise they > get stuck at some error message and have no idea what to do. > Agreed. I would even move ipython (or something like it) to core. Of course, even Setuptools has a long way to go in some areas. (Installation Rollback, for one.) Python is about "batteries included", and these are major "batteries" in most modern environments. A CPAN like "in-house hosted" archive would nice, too. This way, modules have a better chance of outliving the original author's interest/commitment in paying for, possibly non-trivial, web hosting. I'm sure these issues has been discussed to death, but I wonder what the larger Python community thinks. From berankin99 at yahoo.com Wed Jan 28 02:02:58 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Tue, 27 Jan 2009 23:02:58 -0800 (PST) Subject: Best/better way? (histogram) Message-ID: <492364.58189.qm@web112206.mail.gq1.yahoo.com> Hello, I've got several versions of code to here to generate a histogram-esque structure from rows in a CSV file. The basic approach is to use a Dict as a bucket collection to count instances of data items. Other than the try/except(KeyError) idiom for dealing with new bucket names, which I don't like as it desribes the initial state of a KeyValue _after_ you've just described what to do with the existing value, I've come up with a few other methods. What seems like to most resonable approuch? Do you have any other ideas? Is the try/except(KeyError) idiom reallyteh best? In the code below you will see several 4-line groups of code. Each of set of the n-th line represents one solution to the problem. (Cases 1 & 2 do differ from cases 3 & 4 in the final outcome.) Thank you :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from collections import defaultdict from csv import DictReader from pprint import pprint dataFile = open("sampledata.csv") dataRows = DictReader(dataFile) catagoryStats = defaultdict(lambda : {'leaf' : '', 'count' : 0}) #catagoryStats = {} #catagoryStats = defaultdict(int) #catagoryStats = {} for row in dataRows: catagoryRaw = row['CATEGORIES'] catagoryLeaf = catagoryRaw.split('|').pop() ## csb => Catagory Stats Bucket ## multi-statement lines are used for ease of method switching. csb = catagoryStats[catagoryRaw]; csb['count'] += 1; csb['leaf'] = catagoryLeaf #csb = catagoryStats.setdefault(catagoryRaw, {'leaf' : '', 'count' : 0}); csb['count'] += 1; csb['leaf'] = catagoryLeaf #catagoryStats[catagoryRaw] += 1 #catagoryStats[catagoryRaw] = catagoryStats.get(catagoryRaw, 0) + 1 catagoryStatsSorted = catagoryStats.items() catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1) pprint(catagoryStatsSorted, indent=4, width=60) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sampledata.csv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CATEGORIES,SKU "computers|laptops|accessories",12345 "computers|laptops|accessories",12345 "computers|laptops|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "toys|really|super_fun",12345 "toys|really|super_fun",12345 "toys|really|super_fun",12345 "toys|really|not_at_all_fun",12345 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ output: (in case #1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In [1]: %run catstat.py [ ( 'computers|servers|accessories', {'count': 5, 'leaf': 'accessories'}), ( 'toys|really|super_fun', {'count': 3, 'leaf': 'super_fun'}), ( 'computers|laptops|accessories', {'count': 3, 'leaf': 'accessories'}), ( 'toys|really|not_at_all_fun', {'count': 1, 'leaf': 'not_at_all_fun'})] From martin at v.loewis.de Wed Jan 28 02:32:53 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 08:32:53 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> Message-ID: <49800A25.2060702@v.loewis.de> > Next step? You need to use the Visual Studio debugger to find out where precisely the IOError comes from. Regards, Martin From AbelCodeMonk at gmail.com Wed Jan 28 02:37:25 2009 From: AbelCodeMonk at gmail.com (Arlo Belshee) Date: Tue, 27 Jan 2009 23:37:25 -0800 (PST) Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. This will let you start a program from within the browser. It will not let you run arbitrary Python inside the browser but it doesn't sound like that's your goal. If you goal is "user can go to site, click button, hit OK on confirmation box, and launch arbitrary Python code", then the mime type solution is probably the best bet. Just make your own custom extension which will launch the python interpreter on your file. Give it a mime type, and serve regular .py files with that extension and mime type. IE will start the interpreter in a new process and pass your file along. To verify the file's signature, you could simply create a custom interpreter by making a console app that takes a file, checks a sig, then runs the file against an embedded interpreter. Embedding the interpreter is simple enough. > I can code this myself, but prefer to use some open source project, if it exists. I don't know of any such. Heck, if you don't care about checking the signature on the file before running, your "project" could consist of a .reg file that sets up your extension/file type/mime type. Do an MSI if you want to get really fancy, but all you really need to do is add a couple entries to the registry. Of course, everything's a lot harder if you want to run within the browser. Having the browser ask the user for permission then launch a new process is easy. Building an integrated experience that hosts Python inside the browser sandbox is a lot harder - and probably not necessary. From mail at microcorp.co.za Wed Jan 28 02:47:00 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 28 Jan 2009 09:47:00 +0200 Subject: Exec woes References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> Message-ID: <015d01c9811c$c6042e80$0d00a8c0@hendrik> Stephen Hansen wrote: >Hendrik van Rooyen wrote: >>IDLE 1.1.3 ==== No Subprocess ==== >>>>> help(exec) >>SyntaxError: invalid syntax >>>>> >>Its the same under Linux SuSe, Python 2.5.1. >> >>I think this is a BUG. > >Exec is a statement, not a function nor an object: even though you can enclose parens around its arguments like you do later on, they >don't have any syntax meaning This is actually not correct - it is the root cause of my trouble. if you write, in a nested scope: exec ( "somestring to execute" in globals(),locals()) You get the syntax error, as the interpreter somehow sees it as one, unqualified thing. I did this, and it did not work in my real code, and that is why I started putting together the little example - all the trouble caused by too many parenthesis. But it is a GoodThing I made the error, because it has taught me more about how the scopes work. > >You can't help(print) or help(import) either. Right - was not aware of this - I suppose it has never occured to me to ask for help on print or import. >>Anyway, my real problem looks like this: >>>>> def Somefunc(): >> def excrescence(): >> exec('BUILD = "someString"') >> return BUILD >> >>SyntaxError: unqualified exec is not allowed in function 'excrescence >>it is a nested function (, line 3) >>>>> >> >>Now this works if it is not nested, and it works if it is a method in a class. >>Why the complaint about the nestedness? >> >> >Once upon a time, Python had only two scopes or namespaces: local and globals. It'd look up variables in the local scope and if it didn't >find them, it'd look them up in the global scope. (There's also the builtin namespace but to not digress...) 8<----------------------- historic position ---------------- > >Then PEP227 came around to add nested scopes -- or lexical scopes. Its what made "nested" functions like that actually useful: it's what >brought closures into the scenario. As of Python 2.2, within bar() it would be able to see the definition of a because namespaces can >now be nested. > >This addition was a problem for a couple features: doing "from blah import *" within a function, and a bare exec (an exec without an >explicit globals() and locals()) that happened in certain places-- in this case a nested function. They introduced that SyntaxError to make >sure it wouldn't accidentally hit you. Read up on PEP227 for the full details. > Thanks - will do, but I think I am already getting the picture. >To get around this, you need to specify exactly what scope you want exec to happen in when you're in a place where the 'current' scope >is nested. You qualify exec-- > Right - and it also works if you simply use the current locals() in the global position. I suppose one should use the scope "one up" in globals, and locals() as locals, but I can't figure out how to do that directly. (I mean using Somefunc'c locals() as the global for the exec, and excrescence's locals() as the locals - would require keeping a reference - see below) > >>So there is some namespace thing happening that is too subtle for me, and I >>would like to know what "unqualified" means in the above message, and >>what one must do to "qualify" the statement, if that is what is needed. >> > >by doing: > > exec code in , > >In your situation: > > >>> def Somefunc(): > def excrescence(): > exec "BUILD = 'someString'" in globals(), locals() > >is probably sufficient. globals() returns the dictionary of the global namespace, locals() the dictionary of the current functions (non->nested) namespace. > This works, thank you. However, locals() give you the nested function's namespace. The following illustrates what is going on: >>> def Somefunc(): print 'in Somefunc:',locals,id(locals),id(locals()) def excrescence(): print 'in excrescence:',locals,id(locals),id(locals()) exec "BUILD = 'someString'" in locals() print 'in excrescence:',locals,id(locals),id(locals()) return BUILD foo = excrescence() print 'in Somefunc:',locals,id(locals),id(locals()) return foo >>> Somefunc() in Somefunc: 7599848 18705696 in excrescence: 7599848 18799040 in excrescence: 7599848 18799040 in Somefunc: 7599848 18705696 'someString' >>> This leads me to speculate into other evil ways - if I use the outer locals, I need not even return the thing, it would get defined: >>> def Somefunc(): print 'in Somefunc:',locals,id(locals),id(locals()) outer_locals = locals() def excrescence(): print 'in excrescence:',locals,id(locals),id(locals()) exec "BUILD = 'someString'" in outer_locals print 'in excrescence:',locals,id(locals),id(locals()) return None foo = excrescence() print 'in Somefunc:',locals,id(locals),id(locals()) return BUILD >>> Somefunc() in Somefunc: 7599848 18822032 in excrescence: 7599848 18619824 in excrescence: 7599848 18619824 in Somefunc: 7599848 18822032 'someString' >>> And so it does. Using the locals like this in the globals position is not a good idea, except for purposes of illustration, like here - if one actually prints the contents of the dict after the exec, you see what is meant by namespace pollution.... Thank you to all who have responded - I think I have it now - Hendrik From v+python at g.nevcal.com Wed Jan 28 02:52:59 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Tue, 27 Jan 2009 23:52:59 -0800 Subject: errno 22 instead of errno 2 Message-ID: <49800EDB.3080800@g.nevcal.com> open("c:\abc","rb") This simple one-line script, produces errno 22 on Python 2.6, but errno 2 on Python 2.5.2 Is this an unintentional regression? Or is this an intentional bug fix? The file doesn't exist (errno 2) but I guess on Windows it is also somewhat an invalid file name (errno 22). Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file name produces errno 2 on both versions. -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From sjmachin at lexicon.net Wed Jan 28 03:35:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 19:35:03 +1100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <49800A25.2060702@v.loewis.de> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> <49800A25.2060702@v.loewis.de> Message-ID: <498018B7.1070803@lexicon.net> On 28/01/2009 6:32 PM, Martin v. L?wis wrote: >> Next step? > > You need to use the Visual Studio debugger to find out where > precisely the IOError comes from. Big step. I don't have Visual Studio and have never used it before. Which version of VS do I need to debug which released version of Python 2.X and where do I get that VS from? Or do I need to build Python from source to be able to debug it? From ferdinandsousa at gmail.com Wed Jan 28 03:40:13 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Wed, 28 Jan 2009 14:10:13 +0530 Subject: Python-list Digest, Vol 64, Issue 617 In-Reply-To: References: Message-ID: > > Secondly, it has no way to display the image drawn on. Is it possible, or >>> do >>> I have to pass the image off to another module's methods? >> >> im.show() this will display the image (and any modification(s) made to it) > >> Example: Draw a Grey Cross Over an Image >> import Image, ImageDraw >> im = Image.open("lena.pgm") >> draw = ImageDraw.Draw(im) >> draw.line((0, 0) + im.size, fill=128) >> draw.line((0, im.size[1], im.size[0], 0), fill=128) >> del draw >> # write to stdout >> im.save(sys.stdout, "PNG") >> >> Hope that helps >> > That's pretty much the code I used. In fact, I borrowed it from the pdf. I > just tried it, and it output "%PNG". > > im.save("picture1.png") OR im.save("picture1" "png") # not sure if it has to be "PNG" What was happening earlier was that the binary data was being directed to the standard output, which is where all your text is printed by a print statement (print func in Py 3000). If you open a png in notepad, you will notice that the 1st four characters are indeed %PNG, which is the magic number for a PNG file. For further info, see: http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files http://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header Regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jan 28 03:41:14 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 28 Jan 2009 09:41:14 +0100 Subject: Receiving data from USB In-Reply-To: References: Message-ID: <6uak1bFe83phU1@mid.uni-berlin.de> barithegreat at gmail.com schrieb: > Hi > Can any body tell me how can i receive data from usb(usrp) in python. http://letmegooglethatforyou.com/?q=python+usb Diez From __peter__ at web.de Wed Jan 28 03:52:49 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 09:52:49 +0100 Subject: Best/better way? (histogram) References: Message-ID: Bernard Rankin wrote: > I've got several versions of code to here to generate a histogram-esque > structure from rows in a CSV file. > > The basic approach is to use a Dict as a bucket collection to count > instances of data items. > > Other than the try/except(KeyError) idiom for dealing with new bucket > names, which I don't like as it desribes the initial state of a KeyValue > _after_ you've just described what to do with the existing value, I've > come up with a few other methods. > > What seems like to most resonable approuch? The simplest. That would be #3, cleaned up a bit: from collections import defaultdict from csv import DictReader from pprint import pprint from operator import itemgetter def rows(filename): infile = open(filename, "rb") for row in DictReader(infile): yield row["CATEGORIES"] def stats(values): histo = defaultdict(int) for v in values: histo[v] += 1 return sorted(histo.iteritems(), key=itemgetter(1), reverse=True) Should you need the inner dict (which doesn't seem to offer any additional information) you can always add another step: def format(items): result = [] for raw, count in items: leaf = raw.rpartition("|")[2] result.append((raw, dict(count=count, leaf=leaf))) return result pprint(format(stats(rows("sampledata.csv"))), indent=4, width=60) By the way, if you had broken the problem in steps like above you could have offered four different stats() functions which would would have been a bit easier to read... Peter From juvy.jumalon at gmail.com Wed Jan 28 03:58:02 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Wed, 28 Jan 2009 16:58:02 +0800 Subject: need help Message-ID: Hi guys, need help on how to read file from other server(linux). thanks a lot. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Jan 28 04:04:30 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 28 Jan 2009 09:04:30 +0000 Subject: errno 22 instead of errno 2 In-Reply-To: <49800EDB.3080800@g.nevcal.com> References: <49800EDB.3080800@g.nevcal.com> Message-ID: <49801F9E.1050700@timgolden.me.uk> Glenn Linderman wrote: > open("c:\abc","rb") > > This simple one-line script, produces errno 22 on Python 2.6, but errno > 2 on Python 2.5.2 > > Is this an unintentional regression? Or is this an intentional bug fix? > > The file doesn't exist (errno 2) but I guess on Windows it is also > somewhat an invalid file name (errno 22). > > Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file > name produces errno 2 on both versions. > Just glancing quickly at the svn logs, there certainly were some changes around that area in 2008: http://svn.python.org/view/python/trunk/Objects/fileobject.c?view=log Have a look at r61468, for example. Don't know if that's caused what you're seeing but it might well be. (Don't have time just at the mo to check out the revision and rebuild). http://svn.python.org/view/python/trunk/Objects/fileobject.c?rev=61468&r1=60984&r2=61468 I'd question whether it's strictly a "regression", unintentional or otherwise, since I doubt the code makes any particular commitment as to which error code is raised, but I'd certainly be looking askance if I had code which relied on a particular error number which then changed! Still, that's what unit tests are for, I suppose. TJG From castironpi at gmail.com Wed Jan 28 04:24:54 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 01:24:54 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 3:16?pm, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. What you could do is specialize '__getitem__' (or '__getslice__') so that whenever one of its items is accessed, the item is marked as dirty or the entire list is refreshed. (Unproduced.) def taintlist(list): def __getitem__( self, key ): x= super(taintlist, self).__getitem__( self, key ) self._dirty= True self.refresh() #too early, unfortunately return x ... However, what you are probably after is something like this (unproduced): def taintlist(list): def __getitem__( self, key ): x= super(taintlist, self).__getitem__( self, key ) y= delegate( self, key, x ) return y The 'delegate' class, also unproduced, automatically delegates function calls (including member lookups) to the target. After the delegated call returns, the list is notified-- hence the three arguments to its constructor. (Unproduced.) class delegate: def __getattr__( self, key ): attr= super( delegate, self ).__getattr__( self, key ) deleg= delegate( self.owner, self.ownerkey, attr ) return deleg def __call__( self, *ar, **kw ): res= self.attr( *ar, **kw ) self.owner.markdirty( ) return res I'm not convinced it's possible, but there's a possibility... or something like it. When you call a[0].meth(), three things happen: x= '0' looked up on 'a' y= 'meth' looked up on 'x' z= 'y' called You want control over the last of these parts, so you can call a custom function instead. It becomes increasingly risky as the depth increases, such as if the target class implements custom access, I guess. In the 'delegate' shown, for example, it assumes that the result is callable. You might need: class delegate: def __getattr__( self, key ): attr= super( delegate, self ).__getattr__( self, key ) if not iscallable( attr ): return attr ... #return delegate Further, if the result is callable, that doesn't mean it will necessarily be called. You should be able to tolerate this sequence: x= '0' looked up on 'a' y= 'meth' looked up on 'x' z= attribute looked up on 'y' (instead of 'y' called) Mind if we inquire after your progress? From phillip.oldham at gmail.com Wed Jan 28 04:35:55 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Wed, 28 Jan 2009 01:35:55 -0800 (PST) Subject: ORM recommendation when using "live"/predefined DB? Message-ID: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> We're trying to move to Python for a few parts of our application. We have a live database, which has been modeled for a specific use, and has other code connecting to and working with it. We'd like to reduce the amount of work we have to do in terms of keeping our python code up-to-date with schema changes, and we don't want python objects to dictate how the database should be structured. Can you recommend an ORM (or similar) package to look into? From mail at johnohagan.com Wed Jan 28 04:37:44 2009 From: mail at johnohagan.com (John O'Hagan) Date: Wed, 28 Jan 2009 09:37:44 +0000 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <200901280937.45277.mail@johnohagan.com> On Tue, 27 Jan 2009, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. [...] Interesting question. Maybe this is too simple for your purpose (or maybe just wrong!), but could you subclass list and give it an "update" method which keeps a dictionary of the state of its members and/or calls another method that makes the appropriate changes in the other members when a change occurs, something like: class SelfAwareList(list): state_dict = {} def update(self): for i in self: if i.state == 'some_condition': self.do_stuff_to_other_members() self.state_dict[i] = i.state def do_stuff_to_other_members(self): print 'doing stuff...' ? You could manually call update() on the SelfAwareList instance after calling a method on a SelfAwareList member, or even build it into the members' methods so that it was automatic. HTH, John From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:46:37 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:46:37 +0100 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <49802976$0$14303$426a74cc@news.free.fr> Grant Edwards a ?crit : > On 2009-01-27, Bruno Desthuilliers wrote: > >> Please visit comp.databases or comp.lang.javascript for really >> unfriendly and unhelpful places where few happens except >> "bickering and name-calling". > > I've always found comp.lang.c to be a rather dangerous place as > well. Really ? I remember having learned quite a lot there too - but it was several years ago, and things may have changed. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:50:39 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:50:39 +0100 Subject: How many followers of comp.lang.python In-Reply-To: <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> Message-ID: <49802a69$0$3270$426a34cc@news.free.fr> rantingrick a ?crit : > On Jan 27, 10:12 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> All you can say is that he didn't *post* here (at least under his real >> identity...) for the 9 past years - this doesn't mean he never *reads* >> (and this, you just have no way to know). > > Ah, this is a good point. You have to wonder, Guido could be one of > the regulars here. if you mean "one of the regular posters", I have serious doubts about it. It was mostly a theoretical refutation of your conclusions. The important point is that you just *can not* tell if he's *reading* this ng or not... > very interesting. We should have a vote as to who > would be the most likely candidate, now that would be a good thread :) Waste of time as far as I'm concerned. From rschroev_nospam_ml at fastmail.fm Wed Jan 28 04:51:00 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 28 Jan 2009 10:51:00 +0100 Subject: How to execute a hyperlink? In-Reply-To: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <8UVfl.45$n_6.33@newsfe22.ams2> Muddy Coder schreef: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! As others have said, you can use the webbrowser module for hyperlinks. Alternatively you can use os.startfile() which works hyperlinks and many types of files, but only works on Windows (it does the same as double-clicking in Windows Explorer). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From thorsten at thorstenkampe.de Wed Jan 28 04:53:08 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 28 Jan 2009 10:53:08 +0100 Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: * John Machin (Tue, 27 Jan 2009 18:03:55 -0800 (PST)) > On Jan 28, 5:56?am, "Martin v. L?wis" wrote: > The only font choice offered apart from "Raster Fonts" in the Command > Prompt window's Properties box is "Lucida Console", not "Lucida Sans > Unicode". It will let me print Cyrillic characters from a C program, > but not Chinese. I'm off looking for how to get a better font. I have [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont] "00"="DejaVu Sans Mono" Note that you have to /reboot/ (no, I'm not kidding) to make this work. Thorsten From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:57:32 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:57:32 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <49802c05$0$5139$426a34cc@news.free.fr> excord80 a ?crit : > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? What about: http://thraxil.org/code/cgi_app/ (yes, it is a port of CGI::Application, and FWIW it's mentionned on the CGI::Application's wiki). HTH From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 05:00:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 11:00:58 +0100 Subject: Python Application Server In-Reply-To: References: Message-ID: <49802cd3$0$5139$426a34cc@news.free.fr> Adi Eyal a ?crit : > Hi All > > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? > Not sure if it would fit your needs, but you may want to have a look at Twisted ? From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 05:02:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 11:02:28 +0100 Subject: ORM recommendation when using "live"/predefined DB? In-Reply-To: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> References: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> Message-ID: <49802d2d$0$5139$426a34cc@news.free.fr> Phillip B Oldham a ?crit : > We're trying to move to Python for a few parts of our application. We > have a live database, which has been modeled for a specific use, and > has other code connecting to and working with it. > > We'd like to reduce the amount of work we have to do in terms of > keeping our python code up-to-date with schema changes, and we don't > want python objects to dictate how the database should be structured. > > Can you recommend an ORM (or similar) package to look into? AFAICT, SQLAlchemy is the most "tolerant" (and advanced) Python SQL abstraction / ORM package. From koranthala at gmail.com Wed Jan 28 05:02:57 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 02:02:57 -0800 (PST) Subject: A Twisted Design Decision References: <6d674190-4692-42e0-91ba-0ca5ca4dd0d3@n33g2000pri.googlegroups.com> Message-ID: <488249aa-6139-4d0c-8151-1188a1a814ad@u18g2000pro.googlegroups.com> On Jan 27, 9:27?pm, koranthala wrote: > On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > > > > > On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: > > >Twisted, being twisted in its behavior is causing quite a lot of > > >confusion in design decisions. > > > I'm not sure I agree with your premise. ;) > > > >I will put forward a comparison of reactor and non-reactor patterns. > > >The code is not exact - whatever is shown is the gist of it. > > > >For example, a message handler - in a usual scenario: > > >class messageHandler: > > > ? def run(): > > > ? ? ? ? msg = self.get_next_msg() > > > ? ? ? ? if not msg.send(): > > > ? ? ? ? ? ? self.handle_failure() > > > >To handle parallel execution, we will have to use threads, but the > > >code flow is similar. > > > >How do we do the same in a reactor pattern (Twisted)? > > >msg.send will cause a deferred to be raised - the failure, if it > > >happens will happen much later. > > >i.e. other than sending messageHandler object in msg.send(), I cannot > > >see any mechanism of running handle_failure. > > > >In Twisted: > > >class messageHandler: > > > ? def run(): > > > ? ? ? ? msg = self.get_next_msg() > > > ? ? ? ? msg.send(self): > > > >class msgClass: > > > ? ?def send(o): > > > ? ? ? ?d = deferred.addCallBack(success_handler, o).addErrBack > > >(failure_handler, o) > > > > ? ?def failure_handler(o): > > > ? ? ? ?o.handle_failure() > > > This doesn't look like a correct or faithful translation of the original. > > Here are two possibilities. ?First: > > > ? ? class messageHandler: > > ? ? ? ? def run(): > > ? ? ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? ? ? d = msg.send() > > ? ? ? ? ? ? def cbSendFailed(result): > > ? ? ? ? ? ? ? ? if not result: > > ? ? ? ? ? ? ? ? ? ? self.handle_failure() > > ? ? ? ? ? ? d.addErrback(cbSendFailed) > > ? ? ? ? ? ? return d > > > Next: > > > ? ? class messageHandler: > > ? ? ? ? @inlineCallbacks > > ? ? ? ? def run(): > > ? ? ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? ? ? if not (yield msg.send()): > > ? ? ? ? ? ? ? ? self.handle_failure() > > > These are both just straight translations from your version so as to > > be able to handle a Deferred from `msg.send?. > > > >Basically, what I find is that a lot of functional encapsulation is > > >now lost by following reactor pattern. handle_failure is > > >messageHandlers code and makes for pretty viewing if called from > > >inside messageHandler itself. But, due to the twisted nature of > > >reactor pattern, the msg Class - who is functionally a lower class to > > >messageHandler invoking messageHandler's code. > > > You don't need to lose anything. ?I don't know what your motivation was > > for re-arranging the code when you wrote the Twisted version, but it doesn't > > appear to have been necessary. > > > >Is there a way to solve this in a more beautiful way? Am I missing > > >something here? > > > Hope this helps, > > > Jean-Paul > > Thank you Jean-Paul. > My code is more complex than what I have mentioned. When I mentioned > msg.send, the msg object actually gets the data from DB etc to send. > And there are many other items being done. > I will try to see whether I can change the code to incorporate what > you mentioned. > > I rewrote most of my code after learning just raw deferreds - I had > planned to study inlineCallbacks - but then it slipped my mind ?- now > it has come to bit me. :-( Hi, I tried to update the code as per the suggestion, but to no avail. My system uses Python2.4.3 (cannot move to 2.5) - so I tried to rewrite with deferredGenerators - since I thought inlineCallbacks are similar to deferredGenerators. But I cannot seem to rewrite it in a format where the functional encapsulation is not broken. i.e. as I mentioned in the first example - I have to pass SELF to child objects for them to modify it. The code was not exactly as I mentioned. I will try to explain more below: The code before Twisted was incorporated. class MessageHandler: def send_message(): if self.execute(): #Lots of checks going inside this for i in self.msgs: #Sends many messages at the same time if msg.send(): self.success += 1 else self.failure += 1 class Message: def send(): self.update_data() #The data to be sent is updated here return self.protocol.send() #Any protocol - for this example HTTP is used class Protocol: def send(): HTTP get page if page received: parse page and see parameters if parameters: return True return False The code I rewrote after Twisted was incorporated: class MessageHandler: def send_message(): if self.execute(): #Lots of checks going inside this for i in self.msgs: #Sends many messages at the same time msg.send(self): #Has to send myself to the childclass class Message: def send(h): self.h = h #The message handler object self.update_data() #The data to be sent is updated here return self.protocol.send(self) #Again, sending myself to child class def update(status): if status: self.h.success += 1 else: self.h.failure += 1 class Protocol: @deferredGenerator def send(msg): d = waitForDeferred(getPage(url, method, data)) yield d if page received: parse page and see parameters if parameters: msg.update(True) msg.update(False) As I mentioned, I am unable to rewrite it in reactor pattern without breaking functional encapsulation. I tried re-writing it as Jean-Paul mentioned - trying to push the deferred to msg.send etc, but then functional encapsulation of Protocol was broken. Am I being a blockhead here or is it possible to rewrite it in a proper mechanism? From asmodai at in-nomine.org Wed Jan 28 05:05:01 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Wed, 28 Jan 2009 11:05:01 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <20090128100501.GQ99614@nexus.in-nomine.org> -On [20090127 22:21], excord80 (excord80 at gmail.com) wrote: >I need to make a small, relatively low-traffic site that users can >create accounts on and log into. Scripts must run as cgi (no >mod_python or FastCGI is available). Can anyone recommend a small and >simple web framework for Python, maybe similar to Perl's >CGI::Application? Werkzeug[1] should be in your line, I think. [1] http://werkzeug.pocoo.org/ -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From thorsten at thorstenkampe.de Wed Jan 28 05:05:39 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 28 Jan 2009 11:05:39 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: * Pat (Tue, 27 Jan 2009 14:04:28 -0500) > >> I had no idea people were going to get so upset that I used a > >> Windows example and go off on a tear. > > > > Nobody is upset, and nobody has "gone off on a tear". The point > > about the "Windows example" is that the docs say in a > > close-to-screamingly- obvious manner that /options are not > > supported, no matter what religion uses them. It was not, and still > > is not, apparent what you really wanted. We're all patiently waiting > > for you to rephrase the question(s). > > Sigh. I used an incorrect example (I sincerely apologize to the world > for that egregious error on my part). > > I''m totally cognizant that the documentation states '-'' or '--' need > to be used for flags. > > The question was it possible to add a simple flag like 'd-' to optparse > with no other parameters? I'm guessing from the vitriolic diatribes > here that the answer is no. > [...] > If you don't want to answer the question or don't have any meaningful > to add, please don't pollute the forum with further vacuous responses. > I didn't ask, or expect, you to write the code for me. > > christ on a stick, so many of you behave like prima donnas. You have a problem. The problem is not a Python or a technical one. It's described here -> http://en.wikipedia.org/wiki/Attention_Deficit_Syndrome Thorsten From cournape at gmail.com Wed Jan 28 05:53:42 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 28 Jan 2009 19:53:42 +0900 Subject: Python Package Managment In-Reply-To: <596392.54834.qm@web112214.mail.gq1.yahoo.com> References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> Message-ID: <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin wrote: > [extracted from pylons-discuss] > > >> >> I hate to pass the buck, but this is Python's fault for not having >> >> reliable package management built in. There's nothing Pylons can do >> >> about it except switch to another programming language. >> > [SNIP] >> >> Without Setuptools, >> Pylons and TurboGears couldn't exist, and Zope and Twisted >> would not have been able to split themselves into several packages. >> People coming to Python from Perl and Ruby expect to be able to just >> run a command to download and install a package. That problem was >> solved ten years ago, so why does Python still not have it standard? >> >> If Setuptools and Virtualenv or the equivalent were built into Python, >> you could trust that every computer that has successfully installed >> Python can install packages and make virtual environments the same >> way.. >> >> That would eliminate 2/3 of the problems users have when >> installing Pylons, and the subsequent need to explain the problems and >> workarounds in the installation docs. At >> work people say, "Half the trouble of Pylons is installing it", and I >> often have to help them install it in person because otherwise they >> get stuck at some error message and have no idea what to do. >> > > Agreed. I would even move ipython (or something like it) to core. > > Of course, even Setuptools has a long way to go in some areas. (Installation Rollback, for one.) > > Python is about "batteries included", and these are major "batteries" in most modern environments. > > A CPAN like "in-house hosted" archive would nice, too. This way, modules have a better chance of outliving the original author's interest/commitment in paying for, possibly non-trivial, web hosting. > > I'm sure these issues has been discussed to death, but I wonder what the larger Python community thinks. You may be interested in the following: http://mail.python.org/pipermail/python-dev/2006-April/063952.html The thread is two years and a half old, but my impression is that the situation has not changeed much since. Few if any people are against improving the situation, but more people are against the currently available solutions (setuptools, virtualenv, etc...). cheers, David From bblais at bryant.edu Wed Jan 28 05:58:06 2009 From: bblais at bryant.edu (Brian Blais) Date: Wed, 28 Jan 2009 05:58:06 -0500 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <83C7BA1C-9AE3-4C1A-869F-C6B141044FA1@bryant.edu> On Jan 27, 2009, at 16:19 , excord80 wrote: > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? I'd strongly suggest webpy (http://webpy.org/). It is easy, works with CGI, FastCGI, etc... or you can run its own built-in server. It's very nice! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Jan 28 06:06:04 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 28 Jan 2009 22:06:04 +1100 Subject: errno 22 instead of errno 2 In-Reply-To: <49800EDB.3080800@g.nevcal.com> References: <49800EDB.3080800@g.nevcal.com> Message-ID: <49803C1C.20608@gmail.com> On 28/01/2009 6:52 PM, Glenn Linderman wrote: > open("c:\abc","rb") > > This simple one-line script, produces errno 22 on Python 2.6, but errno > 2 on Python 2.5.2 > > Is this an unintentional regression? Or is this an intentional bug fix? > > The file doesn't exist (errno 2) but I guess on Windows it is also > somewhat an invalid file name (errno 22). > > Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file > name produces errno 2 on both versions. > I think you will find that in Python 2.6, the exception object has both 'errno' and 'winerror' attributes, which more accurately reflect the source of the 2 different error numbers, where Python 2.5 would often store the windows error number in the errno field, leading to what you see. I tend to use something like "winerror = getattr(e, 'winerror', e.errno)" to handle both cases... Cheers, Mark From marco at sferacarta.com Wed Jan 28 06:31:47 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 28 Jan 2009 12:31:47 +0100 Subject: ORM recommendation when using "live"/predefined DB? In-Reply-To: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> References: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> Message-ID: Phillip B Oldham wrote: > Can you recommend an ORM (or similar) package to look into? SQLAlchemy with reflected tables. You can use straight SQL, generate it dynamically via python expressions, go with the ORM, or everything together (in a bucket :) It really pays due respect to the RDBMS, and does not try to avoid the OO-SQL gap. From notvalid2 at sbcglobal.net Wed Jan 28 06:45:50 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 03:45:50 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> Message-ID: <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> r wrote: > Change this line: > draw.line((0,0),(20,140), fill=128) > > To This: > draw.line((0,0, 20,140), fill=128) > > And you should be good to go. Like you said, if you need to combine 2 > tuples you can do: > (1,2)+(3,4) Yes, that's true, but the big question is how to "see" the final image? Either one employees another module or writes the file into a folder, then displays it with a paint program? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From claird at lairds.us Wed Jan 28 07:07:46 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 12:07:46 +0000 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> Message-ID: In article <33d59aa0-e73b-45f8-bdfe-4c78717c68f7 at v5g2000prm.googlegroups.com>, joseph.a.marlin at gmail.com wrote: >On Jan 27, 6:47?pm, Andr? wrote: >> On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" >> >> wrote: >> > Greetings! I've heard enough raving about Python, I'm going to see for >> > myself what all the praise is for! >> >> > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> > even use an IDE for Python? >> >> If you already use netbeans, what >abouthttp://www.netbeans.org/features/python/ >> ? >> > >Wow, you guys are fast... yes, I was having trouble deciding between >that (Netbeans), Smultron, or TextWrangler. Thanks! As already mentioned, both Netbeans and Komodo are good choices. A few more comments about these two appear in . From claird at lairds.us Wed Jan 28 07:10:53 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 12:10:53 +0000 Subject: Python Application Server References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: In article , James Mills wrote: >On Wed, Jan 28, 2009 at 2:42 PM, James Mills > wrote: >(...) > >> Might I recommend circuits (1) as a general purpose >> framework that you can build your application on top of. >> >> circuits will allow you to communicate with long-running >> background processes, communicate between processes >> (by way of a Bridge). All communication in circuits is >> asyncroneous. circuits has also recently seen the integration >> of the multiprocessing package from python 2.6/3.0 so you >> can create processes and have inter-process communication >> seamlessly. In fact, parts of your system can even run on other >> nodes (you mentioned clustering). > >I should probably mention some of the components available (features); > * TCPServer, TCPClient > * UDPServer, UDPClient > * HTTP, IRC and SMTP protocols > * Web Server (with limited WSGI support) (depends on parts of CherryPy) > * Timers, Timer > * Logger, Debugger > * ... there are many more components ... :) > >Building new components is fairly easy as well. . . . The big question will be whether circuits qualifies for the original poster as an "application server". I agree, though, that, by the definition as it appeared at the beginning of this thread, circuits seems to be the best candidate. From psteiger at dcc.ufba.br Wed Jan 28 07:25:03 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Wed, 28 Jan 2009 04:25:03 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <909ef3300901280425h6c2dc200pc7566a182be8067a@mail.gmail.com> I would recommend Netbeans with Python plugin, Eric4 and Komodo Edit, with descending order of preference 2009/1/27 joseph.a.marlin at gmail.com > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Wed Jan 28 07:42:08 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 04:42:08 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> On Jan 28, 2:16?am, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. I think Python Cookbook has a recipe which deals with this. - 6.12 Checking an Instance for Any State Change. From ssalam at gmail.com Wed Jan 28 07:51:48 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Wed, 28 Jan 2009 18:21:48 +0530 Subject: bigint to timestamp Message-ID: Hi Group, I have file with contents retrieved from mysql DB. which has a time field with type defined bigint(20) I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS GMT) using python code. The value I found for that field is 212099016004150509 Give me sample code that does the conversion. Regds Shah From wmcclain at watershade.net Wed Jan 28 07:53:51 2009 From: wmcclain at watershade.net (Bill McClain) Date: 28 Jan 2009 12:53:51 GMT Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: On 2009-01-28, W. eWatson wrote: > Yes, that's true, but the big question is how to "see" the final image? > Either one employees another module or writes the file into a folder, then > displays it with a paint program? Does im.show() not work? -Bill -- Sattre Press Tales of War http://sattre-press.com/ by Lord Dunsany info at sattre-press.com http://sattre-press.com/tow.html From __peter__ at web.de Wed Jan 28 07:58:09 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 13:58:09 +0100 Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: W. eWatson wrote: > r wrote: >> Change this line: >> draw.line((0,0),(20,140), fill=128) >> >> To This: >> draw.line((0,0, 20,140), fill=128) >> >> And you should be good to go. Like you said, if you need to combine 2 >> tuples you can do: >> (1,2)+(3,4) > Yes, that's true, but the big question is how to "see" the final image? > Either one employees another module or writes the file into a folder, then > displays it with a paint program? For debugging purposes you can just invoke the show() method im = Image.open(...) # modify image im.show() If you want to integrate the image into your own Tkinter program -- that is explained here: http://effbot.org/tkinterbook/photoimage.htm Following these instruction you code might become import Tkinter as tk import Image import ImageTk import ImageDraw import sys filename = sys.argv[1] im = Image.open(filename) draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line(((0,0),(20,140)), fill=128) root = tk.Tk() pi = ImageTk.PhotoImage(im) label = tk.Label(root, image=pi) label.pack() root.mainloop() Peter From bbxx789_05ss at yahoo.com Wed Jan 28 08:19:49 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 28 Jan 2009 05:19:49 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: On Jan 27, 6:07?pm, Burukena wrote: > On 1/27/09 8:44 PM, James Stroud wrote: > > > joseph.a.mar... at gmail.com wrote: > >> Greetings! I've heard enough raving about Python, I'm going to see for > >> myself what all the praise is for! > > >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > >> even use an IDE for Python? > > >> Any recommendations on open source Python environments? > > >> Thanks! > > > Try open komodo. I haven't used it because vim is my IDE, but it looks > > pretty good. > > > James > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Vim and a terminal works for me, specifically with screen. What does 'with screen' mean? From jnoller at gmail.com Wed Jan 28 08:28:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:28:34 -0500 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280528r469f3c3age3f085d0fe6593a2@mail.gmail.com> On Tue, Jan 27, 2009 at 11:36 PM, James Mills wrote: > On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: >> Steve Holden writes: >>> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >>> inclusion (later recognizable as somewhat ill-advised so late in the >>> day) of multiprocessing [?] > > Steve: It's just a new package - it used to be available > as a 3rd-party package. I dare say it most definitely was > -not- ill-advised. It happens to be a great addition to the > standard library. > >> What was ill-advised about the addition of the 'multiprocessing' >> module to Python 2.6? I ask because I haven't yet used it in anger, >> and am not sure what problems have been found in it. > > I have found no problems with it - I've recently integrated it with my > event/component framework (1). In my library I use Process, Pipe > and Value. > > cheers > James > Awesome James, I'll be adding this to both the multiprocessing talk, and the distributed talk. Let me know if you have any issues. -jesse From aspersieman at gmail.com Wed Jan 28 08:29:13 2009 From: aspersieman at gmail.com (aspersieman) Date: Wed, 28 Jan 2009 15:29:13 +0200 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <49805DA9.60406@googlemail.com> 7stud wrote: > On Jan 27, 6:07 pm, Burukena wrote: > >> On 1/27/09 8:44 PM, James Stroud wrote: >> >> >>> joseph.a.mar... at gmail.com wrote: >>> >>>> Greetings! I've heard enough raving about Python, I'm going to see for >>>> myself what all the praise is for! >>>> >>>> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >>>> even use an IDE for Python? >>>> >>>> Any recommendations on open source Python environments? >>>> >>>> Thanks! >>>> >>> Try open komodo. I haven't used it because vim is my IDE, but it looks >>> pretty good. >>> >>> James >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> Vim and a terminal works for me, specifically with screen. >> > > What does 'with screen' mean? > http://www.gnu.org/software/screen/ > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Vince Noir: Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard? Howard Moon: This better be good. Vince Noir: You know the black bits in bananas, are they tarantulas' eggs? Howard Moon: Please don't speak to me ever again in your life. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Wed Jan 28 08:31:00 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jan 2009 14:31:00 +0100 Subject: bigint to timestamp References: Message-ID: Shah Sultan Alam wrote: > I have file with contents retrieved from mysql DB. > which has a time field with type defined bigint(20) > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > GMT) using python code. Try time.strftime. > The value I found for that field is 212099016004150509 That looks like a bit big for digestion by strftime, so I'd suggest you first find out what the unit and offset of the value in your DB actually is. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve at holdenweb.com Wed Jan 28 08:32:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:32:05 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: James Mills wrote: > On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: >> Steve Holden writes: >>> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >>> inclusion (later recognizable as somewhat ill-advised so late in the >>> day) of multiprocessing [?] > > Steve: It's just a new package - it used to be available > as a 3rd-party package. I dare say it most definitely was > -not- ill-advised. It happens to be a great addition to the > standard library. > >> What was ill-advised about the addition of the 'multiprocessing' >> module to Python 2.6? I ask because I haven't yet used it in anger, >> and am not sure what problems have been found in it. > > I have found no problems with it - I've recently integrated it with my > event/component framework (1). In my library I use Process, Pipe > and Value. > It will be a great library in time, but the code was immature and insufficiently tested before the 2.6 release. The decision to include it late in the release cycle There are 32 outstanding issues on multiprocessing, two of them critical and four high. Many of them are platform-specific, so if they don't hit your platform you won't mind. Jesse did a great job in the time available. It would have been more sensible to wait until 2.7 to include it in the library, IMHO, or make the decision to include it in 2.6 in a more timely fashion. The one advantage of the inclusion is that the issues have been raised now, so as long as maintenance continues the next round will be better. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 28 08:40:07 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:40:07 -0500 Subject: need help In-Reply-To: References: Message-ID: juvy j wrote: > Hi guys, > > need help on how to read file from other server(linux). > Which service do you plan to use: FTP, HTTP and NFS are three possibilities that immediately come to mind, all well handled by {ython standard library modules. A little more background might help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jnoller at gmail.com Wed Jan 28 08:41:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:41:34 -0500 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <87mydcxf6x.fsf@benfinney.id.au> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> On Tue, Jan 27, 2009 at 10:49 PM, Ben Finney wrote: > (Continuing a side topic of a different discussion) > > Steve Holden writes: > >> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >> inclusion (later recognizable as somewhat ill-advised so late in the >> day) of multiprocessing [?] > > What was ill-advised about the addition of the 'multiprocessing' > module to Python 2.6? I ask because I haven't yet used it in anger, > and am not sure what problems have been found in it. > > -- > \ "Holy bouncing boiler-plated fits, Batman!" ?Robin | > `\ | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > I might write a longer blog post about this later, but I can see Steve's point of view. The fact is, pyprocessing/multiprocessing was a late addition to Python 2.6. Personally, I was game to put it into either 2.7 or 2.6, but I felt inclusion into 2.6 wasn't completely out of question - and others agreed with me. See these mail threads: http://mail.python.org/pipermail/python-dev/2008-May/079417.html http://mail.python.org/pipermail/python-dev/2008-June/080011.html And so on. All of that being said; the initial conversion and merging of the code into core exposed a lot of bugs I and others didn't realize were there in the first place. I take full responsibility for that - however some of those bugs were in python-core itself (deadlock after fork anyone?). So, the road to inclusion was a bit rougher than I initially thought - I relied heavily on the skills of people who had more experience in the core than I did, and it was disruptive to the release schedule of python 2.6 due to both the bugs and instability. I however; disagree that this was ultimately a bad decision, or that it was some how indicative of a poorly managed or rushed 2.6 release. All releases have bugs, and towards the end of the 2.6 cycle, multiprocessing *was not* the release blocker. After 2.6 went out, I had a small wave of bugs filed against multiprocessing that I've been working through bit by bit (I still need to work on BSD/Solaris issues) and some of the bugs have exposed issues I simply wish weren't there but I think this is true of any package, especially one as complex as multiprocessing is. I know of plenty of people using the package now, and I know of several groups switching to 2.6 as quickly as possible due to its new features, bug fixes/etc. Multiprocessing as a package is not bug free - I'm the first to admit that - however it is useful, and being used and frankly, I maintain that it is just one step in a larger project to bring additional concurrency and distributed "stuff" into python-core over time. So yes, I see Steve's point - multiprocessing *was* disruptive, and it inclusion late in the game siphoned off resources that could have been used elsewhere. Again, I'll take the responsibility for soiling the pool this way. I do however think, that python 2.6 is overall a *fantastic* release both feature wise, quality wise and is quite useful for people who want to "get things done" (tm). Now I'm going to go back to fixing bugs. -jesse From jnoller at gmail.com Wed Jan 28 08:49:28 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:49:28 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280549r4cc4bb55q299162dee2bce4c5@mail.gmail.com> On Wed, Jan 28, 2009 at 8:32 AM, Steve Holden wrote: ...snip... >> I have found no problems with it - I've recently integrated it with my >> event/component framework (1). In my library I use Process, Pipe >> and Value. >> > It will be a great library in time, but the code was immature and > insufficiently tested before the 2.6 release. The decision to include it > late in the release cycle > > There are 32 outstanding issues on multiprocessing, two of them critical > and four high. Many of them are platform-specific, so if they don't hit > your platform you won't mind. > See my reply to the thread I just sent out; I don't disagree with you. However, there are not 32 open bugs: http://bugs.python.org/issue?%40search_text=&title=&%40columns=title&id=&%40columns=id&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=&versions=&dependencies=&assignee=jnoller&keywords=&priority=&%40group=priority&status=1&%40columns=status&resolution=&%40pagesize=50&%40startwith=0&%40queryname=&%40old-queryname=&%40action=search Man, I hope that url comes through. As of this writing, there are 18 open bugs assigned to me for resolution. Of those, 2 are critical, but should not be - one is an enhancement I am on the fence about, and one is for platforms which have issues with semaphore support. However, I agree that there are bugs, and there will continue to be bugs. I think the quality has greatly increased since the port to core started, and we did find bugs in core as well. I also think it is more than ready for use now. > Jesse did a great job in the time available. It would have been more > sensible to wait until 2.7 to include it in the library, IMHO, or make > the decision to include it in 2.6 in a more timely fashion. The one > advantage of the inclusion is that the issues have been raised now, so > as long as maintenance continues the next round will be better. Again, I don't disagree. Alas, the PEP resolution and proposal was greatly delayed due to, well, someone paying me money to do something else ;) - that being said, yes, the decision was made late in the game, and was disruptive. Maintenance is going to continue as long as I continue to have an internet connection. Heck, there are enhancements to it I really want to add, but I swore off those until the bugs are closed/resolved and my pycon talks are in the can. -jesse From steve at holdenweb.com Wed Jan 28 08:50:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:50:58 -0500 Subject: bigint to timestamp In-Reply-To: References: Message-ID: Shah Sultan Alam wrote: > Hi Group, > I have file with contents retrieved from mysql DB. > which has a time field with type defined bigint(20) > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > GMT) using python code. > The value I found for that field is 212099016004150509 > Give me sample code that does the conversion. > Please? Perhaps you could tell us what date and time 212099016004150509 is supposed to represent? The classic format is "seconds since the Unix epoch" but that isn't what this is: >>> time.localtime(212099016004150509) Traceback (most recent call last): File "", line 1, in ValueError: timestamp out of range for platform time_t Neither does it appear to be a MySQL TIME field, since the maximum value for that would appear to be >>> ((838*60)+59)*60+59 3020399 So, just what is this field? What do the values mean? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Wed Jan 28 08:52:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 07:52:49 -0600 Subject: need help In-Reply-To: References: Message-ID: <49806331.20009@tim.thechases.com> >> need help on how to read file from other server(linux). >> > Which service do you plan to use: FTP, HTTP and NFS are three > possibilities that immediately come to mind, Or scp, or sftp, or rsync, or SMB, or AFS, or IMAP, or POP3, or instant-message, or VCS sync (svn/hg/git/bzr/cvs/darcs/whatever) or ... and via push or pull? > A little more background might help. indeed, for the OP: http://catb.org/~esr/faqs/smart-questions.html -tkc From adi at digitaltrowel.com Wed Jan 28 08:53:49 2009 From: adi at digitaltrowel.com (Adi Eyal) Date: Wed, 28 Jan 2009 15:53:49 +0200 Subject: Python Application Server Message-ID: <6cea0f1e0901280553x2b7bc8c6ke84c2d7c3fda5bb3@mail.gmail.com> Hi All Thanks for the responses - I'll look into Circuits and Twisted, the both seem to be relevant. Adi From steve at holdenweb.com Wed Jan 28 08:58:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:58:05 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> Message-ID: Jesse Noller wrote: [...] > So yes, I see Steve's point - multiprocessing *was* disruptive, and it > inclusion late in the game siphoned off resources that could have been > used elsewhere. Again, I'll take the responsibility for soiling the > pool this way. I do however think, that python 2.6 is overall a > *fantastic* release both feature wise, quality wise and is quite > useful for people who want to "get things done" (tm). > Overall I completely agree. And I don't think the decision to include it was down to you anyway, though you were certainly urging it. It was a release management issue. And 2.6 *is* a good release. > Now I'm going to go back to fixing bugs. > Don't forget those PyCon talks! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From joncle at googlemail.com Wed Jan 28 09:05:07 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 28 Jan 2009 06:05:07 -0800 (PST) Subject: bigint to timestamp References: Message-ID: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> On Jan 28, 1:50?pm, Steve Holden wrote: > Shah Sultan Alam wrote: > > Hi Group, > > I have file with contents retrieved from mysql DB. > > which has a time field with type defined bigint(20) > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > GMT) using python code. > > The value I found for that field is 212099016004150509 > > Give me sample code that does the conversion. > > Please? > > Perhaps you could tell us what date and time 212099016004150509 is > supposed to represent? The classic format is "seconds since the Unix > epoch" but that isn't what this is: > > >>> time.localtime(212099016004150509) > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: timestamp out of range for platform time_t > > Neither does it appear to be a MySQL TIME field, since the maximum value > for that would appear to be > > >>> ((838*60)+59)*60+59 > > 3020399 > > So, just what is this field? What do the values mean? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Bit hard to guess without the actual date to compare to... and I'm a bit busy, but thought I'd throw this in the pool: I'm guessing it's a MySQL database that's had data put into it via a .NET application using the .NET DateTime (so a 20 byte int sounds about right IIRC), which is based on the number of ticks since Jan 1, 1.... I think that should end up around 2[18ish digits here...]... Jon. From berankin99 at yahoo.com Wed Jan 28 09:08:46 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 06:08:46 -0800 (PST) Subject: Best/better way? (histogram) References: Message-ID: <622052.32909.qm@web112205.mail.gq1.yahoo.com> > > The simplest. That would be #3, cleaned up a bit: > > from collections import defaultdict > from csv import DictReader > from pprint import pprint > from operator import itemgetter > > def rows(filename): > infile = open(filename, "rb") > for row in DictReader(infile): > yield row["CATEGORIES"] > > def stats(values): > histo = defaultdict(int) > for v in values: > histo[v] += 1 > return sorted(histo.iteritems(), key=itemgetter(1), reverse=True) > > Should you need the inner dict (which doesn't seem to offer any additional > information) you can always add another step: > > def format(items): > result = [] > for raw, count in items: > leaf = raw.rpartition("|")[2] > result.append((raw, dict(count=count, leaf=leaf))) > return result > > pprint(format(stats(rows("sampledata.csv"))), indent=4, width=60) > > By the way, if you had broken the problem in steps like above you could have > offered four different stats() functions which would would have been a bit > easier to read... > Thank you. The code reorganization does make make it easer to read. I'll have to look up the docs on itemgetter() :) From exarkun at divmod.com Wed Jan 28 09:10:33 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 09:10:33 -0500 Subject: A Twisted Design Decision In-Reply-To: <488249aa-6139-4d0c-8151-1188a1a814ad@u18g2000pro.googlegroups.com> Message-ID: <20090128141033.24460.1020647946.divmod.quotient.3220@henry.divmod.com> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >On Jan 27, 9:27?pm, koranthala wrote: >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > [snip] >> >> Thank you Jean-Paul. >> My code is more complex than what I have mentioned. When I mentioned >> msg.send, the msg object actually gets the data from DB etc to send. >> And there are many other items being done. >> I will try to see whether I can change the code to incorporate what >> you mentioned. >> >> I rewrote most of my code after learning just raw deferreds - I had >> planned to study inlineCallbacks - but then it slipped my mind ?- now >> it has come to bit me. :-( > >Hi, > I tried to update the code as per the suggestion, but to no avail. > My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >rewrite with deferredGenerators - since I thought inlineCallbacks are >similar to deferredGenerators. > > But I cannot seem to rewrite it in a format where the functional >encapsulation is not broken. > i.e. as I mentioned in the first example - I have to pass SELF to >child objects for them to modify it. Why? You don't do this in the original version of your code. Why do it after switching to Twisted (particularly since you seem to want *not* to)? Jean-Paul From icanbob at gmail.com Wed Jan 28 09:17:38 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 28 Jan 2009 06:17:38 -0800 (PST) Subject: Python Application Server References: Message-ID: <17a4a6c1-0ca7-4e60-8863-29a9113a3191@f3g2000vbf.googlegroups.com> On Jan 27, 11:23 pm, Adi Eyal wrote: > Hi All > > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? > > Thanks in advance > Adi You might want to look into the SIMPL project stuff (http:// www.icanprogram.com/simpl). In particular there is a framework (SIMPL calls them softwareICs) called a proxy which sounds like exactly what you might want. bob From icanbob at gmail.com Wed Jan 28 09:21:13 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 28 Jan 2009 06:21:13 -0800 (PST) Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: <3efdce25-e6c1-48a4-b386-ee86c67374e6@t3g2000yqa.googlegroups.com> On Jan 27, 12:29 pm, "Gabriel Genellina" wrote: > En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas > escribi?: > > > Hello all, This is my first post to this mailing list. Our requirement > > is to invoke a Tkinter python panel from a C++ GUI app where both GUI > > windows would run in 2 separate threads. We have written a sample PyQt > > application which calls this Tk panel using something like this:class > > TkPanel(threading.Thread):def run(self): # call showPaneldef > > showPanel():# create window = Tk.Tk() window.mainloop()def start():t = > > TkPanel()t.start()Now we call this from our main python code:def > > startPanel(self): import tkPanel tkPanel.start() # this calls > > tkwindow.mainloop() in a separate thread.This works absolutely fine when > > the invoking app is Python. > > From the above description I don't see where PyQt is involved. Do you > really want to mix Qt and Tk in the same application? I don't think they > could coexist... > -- > Gabriel Genellina Check out the SIMPL project (http://www.icanprogram.com/simpl). Using that toolkit you should be able to have your C++ module exchange a message with a separate Python/Tk/SIMPL module. This might do what you are after. bob From perfreem at gmail.com Wed Jan 28 09:28:53 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 06:28:53 -0800 (PST) Subject: how to optimize object creation/reading from file? Message-ID: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> hi, i am doing a series of very simple string operations on lines i am reading from a large file (~15 million lines). i store the result of these operations in a simple instance of a class, and then put it inside of a hash table. i found that this is unusually slow... for example: class myclass(object): __slots__ = ("a", "b", "c", "d") def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d def __str__(self): return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) def __hash__(self): return hash((self.a, self.b, self.c, self.d)) def __eq__(self, other): return (self.a == other.a and \ self.b == other.b and \ self.c == other.c and \ self.d == other.d) __repr__ = __str__ n = 15000000 table = defaultdict(int) t1 = time.time() for k in range(1, n): myobj = myclass('a' + str(k), 'b', 'c', 'd') table[myobj] = 1 t2 = time.time() print "time: ", float((t2-t1)/60.0) this takes a very long time to run: 11 minutes!. for the sake of the example i am not reading anything from file here but in my real code i do. also, i do 'a' + str(k) but in my real code this is some simple string operation on the line i read from the file. however, i found that the above code shows the real bottle neck, since reading my file into memory (using readlines()) takes only about 4 seconds. i then have to iterate over these lines, but i still think that is more efficient than the 'for line in file' approach which is even slower. in the above code is there a way to optimize the creation of the class instances ? i am using defaultdicts instead of ordinary ones so i dont know how else to optimize that part of the code. is there a way to perhaps optimize the way the class is written? if takes only 3 seconds to read in 15 million lines into memory it doesnt make sense to me that making them into simple objects while at it would take that much more... From koranthala at gmail.com Wed Jan 28 09:30:32 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 06:30:32 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <000d8ddf-414c-4f8f-8be9-d1cf0b349dc5@e1g2000pra.googlegroups.com> On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: > >On Jan 27, 9:27?pm, koranthala wrote: > >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > > [snip] > > >> Thank you Jean-Paul. > >> My code is more complex than what I have mentioned. When I mentioned > >> msg.send, the msg object actually gets the data from DB etc to send. > >> And there are many other items being done. > >> I will try to see whether I can change the code to incorporate what > >> you mentioned. > > >> I rewrote most of my code after learning just raw deferreds - I had > >> planned to study inlineCallbacks - but then it slipped my mind ?- now > >> it has come to bit me. :-( > > >Hi, > > ?I tried to update the code as per the suggestion, but to no avail. > > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to > >rewrite with deferredGenerators - since I thought inlineCallbacks are > >similar to deferredGenerators. > > > ?But I cannot seem to rewrite it in a format where the functional > >encapsulation is not broken. > > ?i.e. as I mentioned in the first example - I have to pass SELF to > >child objects for them to modify it. > > Why? ?You don't do this in the original version of your code. ?Why do > it after switching to Twisted (particularly since you seem to want *not* > to)? > > Jean-Paul Without that, I am unable to increment success and failure counters which are part of the message handler object. In the original version, if send fails the return value of protocol.send is propogated back to msg.send and to msg handler.send. But in twisted, it is not so. So, I have to pass in SELF through to increment success and failure counter. Is it possible otherwise in twisted? From towitowi at gmail.com Wed Jan 28 09:36:06 2009 From: towitowi at gmail.com (towitowi at gmail.com) Date: Wed, 28 Jan 2009 06:36:06 -0800 (PST) Subject: Python 3.0, 'Hello' < 42 Message-ID: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Hello, In the 3.0 changes list there is mentioned that "<"-compares are not supported anymore if the compared types are different (except numbers). Like 42 < "Hello" did return True of False depending on the implementation but is now a TypeError. But the document also mentions that the result is not strictly "undefined" but "reproducable undetermined". Meaning, that on a given machine with a given python implementation result will always be the same. But on another machine, or with another python implementation, it might give a different result. My question now is, why this is? E.g, Is there an integer large enough so that the result changes? What circumstances influence the result? Thanks in advance. tschau, towi. From claird at lairds.us Wed Jan 28 09:42:57 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 14:42:57 +0000 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: In article , 7stud wrote: . . . >> Vim and a terminal works for me, specifically with screen. > >What does 'with screen' mean? > From Ron.Barak at lsi.com Wed Jan 28 09:54:24 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 28 Jan 2009 14:54:24 +0000 Subject: How to execute a hyperlink? In-Reply-To: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024EA1B7@enbmail01.lsi.com> Hi Muddy, http://docs.python.org/library/urllib2.html may help. Bye, Ron. -----Original Message----- From: Muddy Coder [mailto:cosmo_general at yahoo.com] Sent: Wednesday, January 28, 2009 03:00 To: python-list at python.org Subject: How to execute a hyperlink? Hi Folks, Module os provides a means of running shell commands, such as: import os os.system('dir .') will execute command dir I think a hyperlink should also be executed. I tried: os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') but I got kicked out by the Python interpreter. I wonder somebody knows the syntax of triggering a hyperlink? Thanks in advance! Muddy Coder From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 10:06:13 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 16:06:13 +0100 Subject: how to optimize object creation/reading from file? In-Reply-To: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> References: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> Message-ID: <4980745d$0$20447$426a34cc@news.free.fr> perfreem at gmail.com a ?crit : > hi, > > i am doing a series of very simple string operations on lines i am > reading from a large file (~15 million lines). i store the result of > these operations in a simple instance of a class, and then put it > inside of a hash table. i found that this is unusually slow... for > example: > > class myclass(object): > __slots__ = ("a", "b", "c", "d") > def __init__(self, a, b, c, d): > self.a = a > self.b = b > self.c = c > self.d = d > def __str__(self): > return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) > def __hash__(self): > return hash((self.a, self.b, self.c, self.d)) > def __eq__(self, other): > return (self.a == other.a and \ > self.b == other.b and \ > self.c == other.c and \ > self.d == other.d) > __repr__ = __str__ If your class really looks like that, a tuple would be enough. > n = 15000000 > table = defaultdict(int) > t1 = time.time() > for k in range(1, n): hint : use xrange instead. > myobj = myclass('a' + str(k), 'b', 'c', 'd') > table[myobj] = 1 hint : if all you want is to ensure unicity, use a set instead. > t2 = time.time() > print "time: ", float((t2-t1)/60.0) hint : use timeit instead. > this takes a very long time to run: 11 minutes!. for the sake of the > example i am not reading anything from file here but in my real code i > do. also, i do 'a' + str(k) but in my real code this is some simple > string operation on the line i read from the file. however, i found > that the above code shows the real bottle neck, since reading my file > into memory (using readlines()) takes only about 4 seconds. i then > have to iterate over these lines, but i still think that is more > efficient than the 'for line in file' approach which is even slower. iterating over the file, while indeed a bit slower on a per-line basis, avoid useless memory comsuption which can lead to disk swapping - so for "huge" files, it might still be better wrt/ overall performances. > in the above code is there a way to optimize the creation of the class > instances ? i am using defaultdicts instead of ordinary ones so i dont > know how else to optimize that part of the code. is there a way to > perhaps optimize the way the class is written? if takes only 3 seconds > to read in 15 million lines into memory it doesnt make sense to me > that making them into simple objects while at it would take that much > more... Did you bench the creation of a 15.000.000 ints list ?-) But anyway, creating 15.000.000 instances (which is not a small number) of your class takes many seconds - 23.466073989868164 seconds on my (already heavily loaded) machine. Building the same number of tuples only takes about 2.5 seconds - that is, almost 10 times less. FWIW, tuples have all the useful characteristics of your above class (wrt/ hashing and comparison). My 2 cents... From claird at lairds.us Wed Jan 28 10:17:26 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 15:17:26 +0000 Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> <8UVfl.45$n_6.33@newsfe22.ams2> Message-ID: <6h9656-i2n.ln1@lairds.us> In article <8UVfl.45$n_6.33 at newsfe22.ams2>, Roel Schroeven wrote: >Muddy Coder schreef: >> Hi Folks, >> >> Module os provides a means of running shell commands, such as: >> >> import os >> os.system('dir .') >> >> will execute command dir >> >> I think a hyperlink should also be executed. I tried: >> >> os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') >> >> but I got kicked out by the Python interpreter. I wonder somebody >> knows the syntax of triggering a hyperlink? Thanks in advance! > >As others have said, you can use the webbrowser module for hyperlinks. >Alternatively you can use os.startfile() which works hyperlinks and many >types of files, but only works on Windows (it does the same as >double-clicking in Windows Explorer). . . . I suspect that os.startfile() will indeed give Muddy Coder the most immediate satisfaction. It might interest him, though, also to experiment with os.system("start %s" % URL) Again, recognize this only gives happy results, in general, under Win*. From jeff at jmcneil.net Wed Jan 28 10:18:00 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 28 Jan 2009 07:18:00 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: On Jan 27, 7:59 pm, Muddy Coder wrote: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! > > Muddy Coder Like others have said, if you want a browser window, use the 'webbrowser' module. If you're looking to simply trigger a GET/POST without the UI aspect, then you'll probably want urllib or urllib2. Thanks, Jeff mcjeff.blogspot.com From mathieu.malaterre at gmail.com Wed Jan 28 10:21:05 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 28 Jan 2009 07:21:05 -0800 (PST) Subject: win32com.client / Trendlines Message-ID: <57ec1028-453a-4ce8-b76a-d6cc14689b54@z27g2000prd.googlegroups.com> Hi there, I am trying to use win32com.client, but I do not think I fully grasp the concept. So far I copied chunk of code from the net to write my script. It worked well until I could not find any example on Trendlines. According to doc it should be as simple as: wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear, name="Linear Trend") But I get an error: Traceback (most recent call last): File "addchart.py", line 65, in ? wc2.Chart.SeriesCollection(1).Trendlines.Add ( type=constants.xlLinear, name="Linear Trend") AttributeError: 'function' object has no attribute 'Add' It looks like Trendlines indeed does not have such member function. Am I missing something, do I need to generate something particular (eg. using makepy.py) Thanks ! From banaouas.medialog at wanadoo.fr Wed Jan 28 10:23:35 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Wed, 28 Jan 2009 16:23:35 +0100 Subject: file date/time on windows Message-ID: <49807795$0$18360$ba4acef3@news.orange.fr> hi, I noticed recently that the value of file date/time I get with python: time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) is forwarding by one hour the real file date/time. Example: file A.txt: 2009-01-18 16:13 returned valeur: 2009-01-28 15:13 Is there a simple way to get it work correctely (other than adding always 1 hour ...) ? thanks From exarkun at divmod.com Wed Jan 28 10:36:30 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 10:36:30 -0500 Subject: A Twisted Design Decision In-Reply-To: <000d8ddf-414c-4f8f-8be9-d1cf0b349dc5@e1g2000pra.googlegroups.com> Message-ID: <20090128153630.24460.1043773305.divmod.quotient.3248@henry.divmod.com> On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: >On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >> >On Jan 27, 9:27?pm, koranthala wrote: >> >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: >> > [snip] >> >> >> Thank you Jean-Paul. >> >> My code is more complex than what I have mentioned. When I mentioned >> >> msg.send, the msg object actually gets the data from DB etc to send. >> >> And there are many other items being done. >> >> I will try to see whether I can change the code to incorporate what >> >> you mentioned. >> >> >> I rewrote most of my code after learning just raw deferreds - I had >> >> planned to study inlineCallbacks - but then it slipped my mind ?- now >> >> it has come to bit me. :-( >> >> >Hi, >> > ?I tried to update the code as per the suggestion, but to no avail. >> > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >> >rewrite with deferredGenerators - since I thought inlineCallbacks are >> >similar to deferredGenerators. >> >> > ?But I cannot seem to rewrite it in a format where the functional >> >encapsulation is not broken. >> > ?i.e. as I mentioned in the first example - I have to pass SELF to >> >child objects for them to modify it. >> >> Why? ?You don't do this in the original version of your code. ?Why do >> it after switching to Twisted (particularly since you seem to want *not* >> to)? >> >> Jean-Paul > >Without that, I am unable to increment success and failure counters >which are part of the message handler object. >In the original version, if send fails the return value of >protocol.send is propogated back to msg.send and to msg handler.send. >But in twisted, it is not so. So, I have to pass in SELF through to >increment success and failure counter. >Is it possible otherwise in twisted? Why isn't the return value of protocol.send propagated back to msg.send? It sounds like it should be. Jean-Paul From gagsl-py2 at yahoo.com.ar Wed Jan 28 10:43:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 13:43:43 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden escribi?: > Gabriel Genellina wrote: >> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >> escribi?: >> I *thought* I did understand this until I came to this example: >> >> 1) >>>>> id(globals()), id(locals()) >> (11239760, 11239760) >> >> # ok, globals and locals are the same at the module level >> >> 2) >>>>> s = "(id(n) for n in [globals(),locals()])" >>>>> list(eval(s)) >> [11239760, 11239760] # still the same results >> >> 3) >>>>> s = "(id(n()) for n in [globals,locals])" >>>>> list(eval(s)) >> [11239760, 12583248] # locals() is different >> > No, locals is different, not locals(). You are looking at two different > functions that return the same object when called in the given context, > that's all. Perhaps you didn't notice that I shifted the () from right to left. I'm always printing the result of *calling* globals and locals -- the only change is *where* I do call them. >>>>> [id(n) for n in [globals(),locals()]] >> [11239760, 11239760] >>>>> [id(n()) for n in [globals,locals]] >> [11239760, 12583248] >> >> Seems that it is important *when* those functions are evaluated, but I >> don't understand *why*... -- Gabriel Genellina From mathieu.malaterre at gmail.com Wed Jan 28 10:43:51 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 28 Jan 2009 07:43:51 -0800 (PST) Subject: win32com.client / Trendlines References: <57ec1028-453a-4ce8-b76a-d6cc14689b54@z27g2000prd.googlegroups.com> Message-ID: On Jan 28, 4:21?pm, mathieu wrote: > Hi there, > > ? I am trying to use win32com.client, but I do not think I fully grasp > the concept. So far I copied chunk of code from the net to write my > script. It worked well until I could not find any example on > Trendlines. According to doc it should be as simple as: > > wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear, > name="Linear Trend") > > But I get an error: > > Traceback (most recent call last): > ? File "addchart.py", line 65, in ? > ? ? wc2.Chart.SeriesCollection(1).Trendlines.Add > ( type=constants.xlLinear, name="Linear Trend") > AttributeError: 'function' object has no attribute 'Add' > > It looks like Trendlines indeed does not have such member function. Am > I missing something, do I need to generate something particular (eg. > using makepy.py) > Ok found it. trend = wc2.Chart.SeriesCollection(1).Trendlines().Add (Type=constants.xlLinear, Name="Linear Trend") trend.DisplayRSquared = True trend.DisplayEquation = True Trendlines is a function... Sorry for the noise, win32com really rocks ! -Mathieu From kw at codebykevin.com Wed Jan 28 10:50:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 28 Jan 2009 10:50:58 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <49807EE2.3060007@codebykevin.com> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! I use IDLE + Terminal myself. IDLE has improved a lot on the Mac in recent years. Another good tool is Aquamacs, a Mac-optimized version of Emacs: http://aquamacs.org -- Kevin Walzer Code by Kevin http://www.codebykevin.com From google at mrabarnett.plus.com Wed Jan 28 10:56:36 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 15:56:36 +0000 Subject: file date/time on windows In-Reply-To: <49807795$0$18360$ba4acef3@news.orange.fr> References: <49807795$0$18360$ba4acef3@news.orange.fr> Message-ID: <49808034.9080806@mrabarnett.plus.com> m.banaouas wrote: > hi, > > I noticed recently that the value of file date/time I get with python: > time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) > is forwarding by one hour the real file date/time. > > Example: > file A.txt: 2009-01-18 16:13 > returned valeur: 2009-01-28 15:13 > > Is there a simple way to get it work correctely (other than adding always 1 > hour ...) ? > time.gmtime(), as the name suggests, returns GMT (UTC). From your email address I presume you're in France, which is GMT+1. Windows Explorer shows the file time in local time, which for you is currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. From perfreem at gmail.com Wed Jan 28 11:02:04 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:02:04 -0800 (PST) Subject: how to optimize object creation/reading from file? References: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> <4980745d$0$20447$426a34cc@news.free.fr> Message-ID: <35207f52-9c69-4b29-a9b0-bbd9b19115f3@p2g2000prf.googlegroups.com> On Jan 28, 10:06?am, Bruno Desthuilliers wrote: > perfr... at gmail.com a ?crit : > > > > > hi, > > > i am doing a series of very simple string operations on lines i am > > reading from a large file (~15 million lines). i store the result of > > these operations in a simple instance of a class, and then put it > > inside of a hash table. i found that this is unusually slow... for > > example: > > > class myclass(object): > > ? ? __slots__ = ("a", "b", "c", "d") > > ? ? def __init__(self, a, b, c, d): > > ? ? ? ? self.a = a > > ? ? ? ? self.b = b > > ? ? ? ? self.c = c > > ? ? ? ? self.d = d > > ? ? def __str__(self): > > ? ? ? ? return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) > > ? ? def __hash__(self): > > ? ? ? ? return hash((self.a, self.b, self.c, self.d)) > > ? ? def __eq__(self, other): > > ? ? ? ? return (self.a == other.a and \ > > ? ? ? ? ? ? ? ? self.b == other.b and \ > > ? ? ? ? ? ? ? ? self.c == other.c and \ > > ? ? ? ? ? ? ? ? self.d == other.d) > > ? ? __repr__ = __str__ > > If your class really looks like that, a tuple would be enough. > > > n = 15000000 > > table = defaultdict(int) > > t1 = time.time() > > for k in range(1, n): > > hint : use xrange instead. > > > ? ? myobj = myclass('a' + str(k), 'b', 'c', 'd') > > ? ? table[myobj] = 1 > > hint : if all you want is to ensure unicity, use a set instead. > > > t2 = time.time() > > print "time: ", float((t2-t1)/60.0) > > hint : use timeit instead. > > > this takes a very long time to run: 11 minutes!. for the sake of the > > example i am not reading anything from file here but in my real code i > > do. also, i do 'a' + str(k) but in my real code this is some simple > > string operation on the line i read from the file. however, i found > > that the above code shows the real bottle neck, since reading my file > > into memory (using readlines()) takes only about 4 seconds. i then > > have to iterate over these lines, but i still think that is more > > efficient than the 'for line in file' approach which is even slower. > > iterating over the file, while indeed a bit slower on a per-line basis, > avoid useless memory comsuption which can lead to disk swapping - so for > ? "huge" files, it might still be better wrt/ overall performances. > > > in the above code is there a way to optimize the creation of the class > > instances ? i am using defaultdicts instead of ordinary ones so i dont > > know how else to optimize that part of the code. is there a way to > > perhaps optimize the way the class is written? if takes only 3 seconds > > to read in 15 million lines into memory it doesnt make sense to me > > that making them into simple objects while at it would take that much > > more... > > Did you bench the creation of a 15.000.000 ints list ?-) > > But anyway, creating 15.000.000 instances (which is not a small number) > of your class takes many seconds - 23.466073989868164 seconds on my > (already heavily loaded) machine. Building the same number of tuples > only takes about 2.5 seconds - that is, almost 10 times less. FWIW, > tuples have all the useful characteristics of your above class (wrt/ > hashing and comparison). > > My 2 cents... thanks for your insight ful reply - changing to tuples made a big change! From koranthala at gmail.com Wed Jan 28 11:05:13 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 08:05:13 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> On Jan 28, 8:36?pm, Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: > >On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: > >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: > >> >On Jan 27, 9:27?pm, koranthala wrote: > >> >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > >> > [snip] > > >> >> Thank you Jean-Paul. > >> >> My code is more complex than what I have mentioned. When I mentioned > >> >> msg.send, the msg object actually gets the data from DB etc to send. > >> >> And there are many other items being done. > >> >> I will try to see whether I can change the code to incorporate what > >> >> you mentioned. > > >> >> I rewrote most of my code after learning just raw deferreds - I had > >> >> planned to study inlineCallbacks - but then it slipped my mind ?- now > >> >> it has come to bit me. :-( > > >> >Hi, > >> > ?I tried to update the code as per the suggestion, but to no avail. > >> > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to > >> >rewrite with deferredGenerators - since I thought inlineCallbacks are > >> >similar to deferredGenerators. > > >> > ?But I cannot seem to rewrite it in a format where the functional > >> >encapsulation is not broken. > >> > ?i.e. as I mentioned in the first example - I have to pass SELF to > >> >child objects for them to modify it. > > >> Why? ?You don't do this in the original version of your code. ?Why do > >> it after switching to Twisted (particularly since you seem to want *not* > >> to)? > > >> Jean-Paul > > >Without that, I am unable to increment success and failure counters > >which are part of the message handler object. > >In the original version, if send fails the return value of > >protocol.send is propogated back to msg.send and to msg handler.send. > >But in twisted, it is not so. So, I have to pass in SELF through to > >increment success and failure counter. > >Is it possible otherwise in twisted? > > Why isn't the return value of protocol.send propagated back to msg.send? > It sounds like it should be. > > Jean-Paul Thank you very much again Jean-Paul for helping me out. I am unable to understand how I will be able to propogate the return value of protocol.send to msg.send. Maybe I am being foolish - but my understanding is as follows. In a non-reactor pattern scenario: msg_handler.send_message calls msg.send which inturn calls protocol.send. So, the reply to protocol.send actually goes up the stack till msg_handler.send_message wherein I can increment/decrement success/ failure counter. In reactor pattern: msg_handler.send_message calls msg.send which call protocol.send which causes a deferred to be created. Now, when the deferred finishes its work, reactor calls the callback associated - but the original context (stack etc) is lost. Now, the only mechanism of interaction is via the parameters passed in the callback. This means that msg_handler has to pass in its object to msg.send which inturn has to send either msg_handler or self to protocol.send so that it is stored in the parameter to the callback. When callback is hit, I use this parameter to call methods in each object. This is what I was trying to say in my first mail that - Twisted, being twisted in its behavior is causing quite a lot of confusion in design decisions - because now I have to break functional encapsulation - by asking lower layer objects to handler upper layer objects behaviors. As I said earlier, maybe I am being completely stupid - there might be a very easy and obvious solution. But I cannot seem to get it at all. From perfreem at gmail.com Wed Jan 28 11:13:10 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:13:10 -0800 (PST) Subject: writing large dictionaries to file using cPickle Message-ID: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> hello all, i have a large dictionary which contains about 10 keys, each key has a value which is a list containing about 1 to 5 million (small) dictionaries. for example, mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': 'world'}, ...], key2: [...]} in total there are about 10 to 15 million lists if we concatenate together all the values of every key in 'mydict'. mydict is a structure that represents data in a very large file (about 800 megabytes). what is the fastest way to pickle 'mydict' into a file? right now i am experiencing a lot of difficulties with cPickle when using it like this: from cPickle import pickle pfile = open(my_file, 'w') pickle.dump(mydict, pfile) pfile.close() this creates extremely large files (~ 300 MB) though it does so *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and it gets slower and slower. it takes almost an hour if not more to write this pickle object to file. is there any way to speed this up? i dont mind the large file... after all the text file with the data used to make the dictionary was larger (~ 800 MB) than the file it eventually creates, which is 300 MB. but i do care about speed... i have tried optimizing this by using this: s = pickle.dumps(mydict, 2) pfile.write(s) but this takes just as long... any ideas ? is there a different module i could use that's more suitable for large dictionaries ? thank you very much. From arkanes at gmail.com Wed Jan 28 11:31:22 2009 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 28 Jan 2009 10:31:22 -0600 Subject: A Twisted Design Decision In-Reply-To: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> References: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> Message-ID: <4866bea60901280831x472ef75bw78bc7bf5e85aacdf@mail.gmail.com> On Wed, Jan 28, 2009 at 10:05 AM, koranthala wrote: > On Jan 28, 8:36 pm, Jean-Paul Calderone wrote: >> On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: >> >On Jan 28, 7:10 pm, Jean-Paul Calderone wrote: >> >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >> >> >On Jan 27, 9:27 pm, koranthala wrote: >> >> >> On Jan 27, 6:57 pm, Jean-Paul Calderone wrote: >> >> > [snip] >> >> >> >> Thank you Jean-Paul. >> >> >> My code is more complex than what I have mentioned. When I mentioned >> >> >> msg.send, the msg object actually gets the data from DB etc to send. >> >> >> And there are many other items being done. >> >> >> I will try to see whether I can change the code to incorporate what >> >> >> you mentioned. >> >> >> >> I rewrote most of my code after learning just raw deferreds - I had >> >> >> planned to study inlineCallbacks - but then it slipped my mind - now >> >> >> it has come to bit me. :-( >> >> >> >Hi, >> >> > I tried to update the code as per the suggestion, but to no avail. >> >> > My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >> >> >rewrite with deferredGenerators - since I thought inlineCallbacks are >> >> >similar to deferredGenerators. >> >> >> > But I cannot seem to rewrite it in a format where the functional >> >> >encapsulation is not broken. >> >> > i.e. as I mentioned in the first example - I have to pass SELF to >> >> >child objects for them to modify it. >> >> >> Why? You don't do this in the original version of your code. Why do >> >> it after switching to Twisted (particularly since you seem to want *not* >> >> to)? >> >> >> Jean-Paul >> >> >Without that, I am unable to increment success and failure counters >> >which are part of the message handler object. >> >In the original version, if send fails the return value of >> >protocol.send is propogated back to msg.send and to msg handler.send. >> >But in twisted, it is not so. So, I have to pass in SELF through to >> >increment success and failure counter. >> >Is it possible otherwise in twisted? >> >> Why isn't the return value of protocol.send propagated back to msg.send? >> It sounds like it should be. >> >> Jean-Paul > > Thank you very much again Jean-Paul for helping me out. > I am unable to understand how I will be able to propogate the return > value of protocol.send to msg.send. > Maybe I am being foolish - but my understanding is as follows. > > In a non-reactor pattern scenario: > msg_handler.send_message calls msg.send which inturn calls > protocol.send. > So, the reply to protocol.send actually goes up the stack till > msg_handler.send_message wherein I can increment/decrement success/ > failure counter. > > In reactor pattern: > msg_handler.send_message calls msg.send which call protocol.send which > causes a deferred to be created. > Now, when the deferred finishes its work, reactor calls the callback > associated - but the original context (stack etc) is lost. > Now, the only mechanism of interaction is via the parameters passed in > the callback. > This means that msg_handler has to pass in its object to msg.send > which inturn has to send either msg_handler or self to protocol.send > so that it is stored in the parameter to the callback. > When callback is hit, I use this parameter to call methods in each > object. > > This is what I was trying to say in my first mail that - Twisted, > being twisted in its behavior is causing quite a lot of > confusion in design decisions - because now I have to break functional > encapsulation - by asking lower layer objects to handler upper layer > objects behaviors. > > As I said earlier, maybe I am being completely stupid - there might > be a very easy and obvious solution. But I cannot seem to get it at > all. > I'm sure you're not completely stupid, but there is an easy and obvious solution - you should be returning the *deferred* up the callstack. That will allow the MessageHandler to attach callbacks/errbacks to it, without needing to pass self all the way down the call stack and have a proxy object manage it. From python at bdurham.com Wed Jan 28 11:32:27 2009 From: python at bdurham.com (python at bdurham.com) Date: Wed, 28 Jan 2009 11:32:27 -0500 Subject: writing large dictionaries to file using cPickle In-Reply-To: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: <1233160347.11640.1297229163@webmail.messagingengine.com> Hi, Change: pickle.dump(mydict, pfile) to: pickle.dump(mydict, pfile, -1 ) I think you will see a big difference in performance and also a much smaller file on disk. BTW: What type of application are you developing that creates so many dictionaries? Sounds interesting. Malcolm From jef.mangelschots at gmail.com Wed Jan 28 11:36:19 2009 From: jef.mangelschots at gmail.com (jefm) Date: Wed, 28 Jan 2009 08:36:19 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: this is alink explaining how to add new fonts to the command line (e.g. Lucida Sans Unicode) http://phatness.com/node/1643 From exarkun at divmod.com Wed Jan 28 11:40:59 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 11:40:59 -0500 Subject: A Twisted Design Decision In-Reply-To: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> Message-ID: <20090128164059.24460.408587049.divmod.quotient.3269@henry.divmod.com> On Wed, 28 Jan 2009 08:05:13 -0800 (PST), koranthala wrote: >On Jan 28, 8:36?pm, Jean-Paul Calderone wrote: >> [snip] >> Why isn't the return value of protocol.send propagated back to msg.send? >> It sounds like it should be. >> >> Jean-Paul > >Thank you very much again Jean-Paul for helping me out. >I am unable to understand how I will be able to propogate the return >value of protocol.send to msg.send. >Maybe I am being foolish - but my understanding is as follows. > >In a non-reactor pattern scenario: >msg_handler.send_message calls msg.send which inturn calls >protocol.send. >So, the reply to protocol.send actually goes up the stack till >msg_handler.send_message wherein I can increment/decrement success/ >failure counter. > >In reactor pattern: >msg_handler.send_message calls msg.send which call protocol.send which >causes a deferred to be created. >Now, when the deferred finishes its work, reactor calls the callback >associated - but the original context (stack etc) is lost. >Now, the only mechanism of interaction is via the parameters passed in >the callback. You can still interact via return values. You should be thinking about a Deferred in the same way as you think about a function which returns a result synchronously. The Deferred represents the result, even though it isn't the result itself (since the result doesn't exist yet). Anything you would have done by calling a function and then using its return value you can do by calling a function and then using the Deferred it returns. I'll try to update the Twisted version of the code you gave previously to demonstrate this: class MessageHandler: def send_message(self): def handleResult(result): if result: self.success += 1 else: self.failure += 1 if self.execute(): for i in self.msgs: msg.send().addCallback(handleResult) class Message: def send(self): self.h = h #The message handler object self.update_data() #The data to be sent is updated here return self.protocol.send() class Protocol: @deferredGenerator def send(self): d = waitForDeferred(getPage(url, method, data)) yield d if page received: parse page and see parameters if parameters: yield True return yield False See how neither the handler nor the message is passed into the protocol. The result of the Deferred returned by Protocol.send is instead used by the handler to do something that the handler knows about. The encapsulation is the same as it was in your original example. The only significant change is from synchronous return values to Deferred return values. Jean-Paul From perfreem at gmail.com Wed Jan 28 11:43:23 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:43:23 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 28, 11:32?am, pyt... at bdurham.com wrote: > Hi, > > Change: > > pickle.dump(mydict, pfile) > > to: > > pickle.dump(mydict, pfile, -1 ) > > I think you will see a big difference in performance and also a much > smaller file on disk. > > BTW: What type of application are you developing that creates so many > dictionaries? Sounds interesting. > > Malcolm hi! thank you for your reply. unfortunately i tried this but it doesn't change the speed. it's still writing the file extremely slowly. i'm not sure why? thank you. From invalid at invalid Wed Jan 28 11:43:44 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 28 Jan 2009 10:43:44 -0600 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> <49802a69$0$3270$426a34cc@news.free.fr> Message-ID: On 2009-01-28, Bruno Desthuilliers wrote: >> very interesting. We should have a vote as to who would be the >> most likely candidate, now that would be a good thread :) > > Waste of time as far as I'm concerned. Usenet? Wasting time? Never! -- Grant Edwards grante Yow! I feel ... JUGULAR ... at visi.com From lists at cheimes.de Wed Jan 28 11:48:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 28 Jan 2009 17:48:38 +0100 Subject: writing large dictionaries to file using cPickle In-Reply-To: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: perfreem at gmail.com schrieb: > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. Have a look at ZODB. From berankin99 at yahoo.com Wed Jan 28 12:02:55 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 09:02:55 -0800 (PST) Subject: small python-cgi wiki? Message-ID: <889572.28267.qm@web112204.mail.gq1.yahoo.com> Hello, I'm looking to set up a small private wiki, and am looking for recommendations. Some sort of CGI based package that I could just untar somewhere web accessable via Apache would be great. Any ideas? Thanks, :) From jeremiah.dodds at gmail.com Wed Jan 28 12:04:44 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Wed, 28 Jan 2009 12:04:44 -0500 Subject: How many followers of comp.lang.python In-Reply-To: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> Message-ID: <12cbbbfc0901280904y4b8c0ddfuf8ea9f5db9608a83@mail.gmail.com> On Tue, Jan 27, 2009 at 10:07 AM, rantingrick wrote: > I curious of how many are "really" out there. I have been watching the > list for some time but basically see the same 10 or so people > answering questions. > > Reply to this message so we can see how many exists here > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > I'm sure there are a lot more people lurking than actually posting. I personally do a lot more lurking than posting - plus I post through google groups at the moment, which means that at least some of the regular posters won't see what I post. I've learned an awful lot by lurking the mailing lists, hopefully I'll be able to contribute more in the future. -------------- next part -------------- An HTML attachment was scrubbed... URL: From berankin99 at yahoo.com Wed Jan 28 12:04:45 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 09:04:45 -0800 (PST) Subject: Python Package Managment References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> Message-ID: <759991.83977.qm@web112220.mail.gq1.yahoo.com> > > [extracted from pylons-discuss] > > > > > >> >> I hate to pass the buck, but this is Python's fault for not having > >> >> reliable package management built in. There's nothing Pylons can do > >> >> about it except switch to another programming language. > >> > [SNIP] > >> > >> Without Setuptools, > >> Pylons and TurboGears couldn't exist, and Zope and Twisted > >> would not have been able to split themselves into several packages. > >> People coming to Python from Perl and Ruby expect to be able to just > >> run a command to download and install a package. That problem was > >> solved ten years ago, so why does Python still not have it standard? > >> > >> If Setuptools and Virtualenv or the equivalent were built into Python, > >> you could trust that every computer that has successfully installed > >> Python can install packages and make virtual environments the same > >> way.. > >> > >> That would eliminate 2/3 of the problems users have when > >> installing Pylons, and the subsequent need to explain the problems and > >> workarounds in the installation docs. At > >> work people say, "Half the trouble of Pylons is installing it", and I > >> often have to help them install it in person because otherwise they > >> get stuck at some error message and have no idea what to do. > >> > > > > Agreed. I would even move ipython (or something like it) to core. > > > > Of course, even Setuptools has a long way to go in some areas. (Installation > Rollback, for one.) > > > > Python is about "batteries included", and these are major "batteries" in most > modern environments. > > > > A CPAN like "in-house hosted" archive would nice, too. This way, modules have > a better chance of outliving the original author's interest/commitment in paying > for, possibly non-trivial, web hosting. > > > > I'm sure these issues has been discussed to death, but I wonder what the > larger Python community thinks. > > You may be interested in the following: > > http://mail.python.org/pipermail/python-dev/2006-April/063952.html > > The thread is two years and a half old, but my impression is that the > situation has not changeed much since. Few if any people are against > improving the situation, but more people are against the currently > available solutions (setuptools, virtualenv, etc...). > Thank you, I'll have a look. From cjlesh at gmail.com Wed Jan 28 12:07:54 2009 From: cjlesh at gmail.com (cjl) Date: Wed, 28 Jan 2009 09:07:54 -0800 (PST) Subject: Windows PIL installer question Message-ID: <381de027-2be2-4de4-bb39-bf170a970a5a@s20g2000yqh.googlegroups.com> Is there any way to run the PIL installer from the command line on Windows in 'silent' mode, without displaying the install screens or requiring user interaction? From koranthala at gmail.com Wed Jan 28 12:12:18 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:12:18 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <298da38d-7678-4d54-9ab0-835eb5dbc854@w1g2000prk.googlegroups.com> > You can still interact via return values. ?You should be thinking about > a Deferred in the same way as you think about a function which returns > a result synchronously. ?The Deferred represents the result, even though > it isn't the result itself (since the result doesn't exist yet). ?Anything > you would have done by calling a function and then using its return value > you can do by calling a function and then using the Deferred it returns. > Oh! This makes it very clear. Thank you very much Jean-Paul and Chris Mellon. My view of deferred was very different from this. That was the reason behind these persistent questions. My view of deferred was that of it being a mechanism to provide asynchronous behavior and nothing more. The twisted documentation explicitly mentions this - 'Twisted?s Deferred abstraction, which symbolises a ?promised? result and which can pass an eventual result to handler functions.' But with my earlier view I understood it completely differently. Thank you once more, Jean-Paul & Chris for taking your valuable time out to help me out. From gil.shinar at gmail.com Wed Jan 28 12:12:57 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Wed, 28 Jan 2009 09:12:57 -0800 (PST) Subject: Process crash with no reason References: Message-ID: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> On Jan 27, 5:59?pm, Philip Semanchuk wrote: > On Jan 27, 2009, at 10:34 AM, gil.shi... at gmail.com wrote: > > > > > On Jan 27, 2:10 pm, Tim Golden wrote: > >> gil.shi... at gmail.com wrote: > >>> On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >>>> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>>>> Hi All, > >>>>> I'm running a program that is acting as a nice interface to ? > >>>>> sybase' > >>>>> replication server. The program is using the cherrypy web ? > >>>>> service for > >>>>> the GUI. The process is crashing every few days with no reason. ? > >>>>> In the > >>>>> log I can see INFO and DEBUG (No ERROR) log lines and I do not ? > >>>>> get any > >>>>> TraceBack python's message. This program is running on solaris 9 > >>>>> machine. > >>>>> Where can I see or what can I do in order to find out what ? > >>>>> causes the > >>>>> process to crash? > >>>>> I have tried simulating a "traceBack" message and I could see this > >>>>> traceback message in one of the log files I'm using. When the ? > >>>>> process > >>>>> crashes without my help, I don't have a clue. > >>>>> Let me know if you need any other info > >>>> Although Python isn't immune to fatal errors like you describe, I'd > >>>> immediately suspect a 3rd-party module instead, esp. one written ? > >>>> in C > >>>> or C++. Are you using anything like that? > > >>> No I do not. > > >> Then how are you interacting with Sybase? > > > I'm using python's functions to run sybase sql commands. > > Can you give a short code sample? I'm unaware of how one would use the ? > standard Python library to talk to Sybase, unless Sybase has a raw ? > socket interface or some such. First of all I have found the following python's import: import Sybase To connect the sybase server we are using the following function: def _getConnection (self): db = Sybase.connect(self.dbs, self.login[0], self.login [1], datetime='auto') return db To execute a DBS query, we are using the following function: def _executeQuery(self, cursor, query, expected_result=None): try: self.logger.debug('Executing query:' + query + ', expected:' + str(expected_result)) cursor.execute(query) except Sybase.DatabaseError, e: if ((expected_result != None) and ("Msg " + expected_result in str(e))): return (DBStatus.SUCCESS, self._getDBMsg(str(e))) raise Sybase.DatabaseError, self._getDBMsg(str (e)) return (DBStatus.SUCCESS, "") Do you need anything else? Thanks a lot From koranthala at gmail.com Wed Jan 28 12:16:18 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:16:18 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> Message-ID: <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> On Jan 28, 5:42?pm, koranthala wrote: > On Jan 28, 2:16?am, Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > a list of ?objects > > > A=[a,b,c,d,...,z] > > > where, ?in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that > > something about the ?object 'a' has changed so that when I revisit A, > > I will know that the other items in the list need to be refreshed to > > reflect the changes in A as a result of changing 'a'. > > > Even better would be to automatically percolate the subsequent changes > > that resulted from altering 'a' for the rest of the items in the list. > > Naturally, all of these items are related in some parent-child > > fashion. > > > that might be a lot to ask, however. > > > Any advice appreciated. > > I think Python Cookbook has a recipe which deals with this. > - 6.12 Checking an Instance for Any State Change. Were you able to get this? If not, let me know. I will try to type it in here - (it is a big recipe, so not doing it now) From alex at moreati.org.uk Wed Jan 28 12:17:29 2009 From: alex at moreati.org.uk (moreati) Date: Wed, 28 Jan 2009 09:17:29 -0800 (PST) Subject: Reuse of DB-API 2.0 cursors for multiple queries? Message-ID: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Today, I used the adodbapi module against an SQL Server Express database. I was surprised to get an exception, when I attempted to submit a second query with my cursor object. The full session is below. With cx_Oracle I've become used to reusing a cursor for subsequent queries. The PEP doesn't specify either way, that I can see. Is this behaviour left to the implementation, or should I be able to expect a cursor is reusable? With thanks, Alex Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import adodbapi >>> conn = adodbapi.connect('Provider=SQLOLEDB.1;Data Source=.\\SQLEXPRESS;Initial Catalog=MYDATABBASE;Integrated Security=SSPI;User Instance=False;') >>> curs = conn.cursor() >>> curs.execute('select * from localview_roles') >>> curs.execute('select * from localview_roles') Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 713, in execut e self._executeHelper(operation,False,parameters) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 664, in _execu teHelper self._raiseCursorError(DatabaseError,tracebackhistory) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 474, in _raise CursorError eh(self.conn,self,errorclass,errorvalue) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 60, in standar dErrorHandler raise errorclass(errorvalue) adodbapi.adodbapi.DatabaseError: --ADODBAPI Traceback (most recent call last): File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 650, in _exec uteHelper adoRetVal=self.cmd.Execute() File "", line 3, in Execute File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes ) + args) com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Cannot create new connection because in manual or distribute d transaction mode.', None, 0, -2147467259), None) -- on command: "select * from localview_roles" -- with parameters: None From ptmcg at austin.rr.com Wed Jan 28 12:33:35 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 28 Jan 2009 09:33:35 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 3:16?pm, Reckoner wrote: > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > Check out the Enthought Traits package. -- Paul From philip at semanchuk.com Wed Jan 28 12:37:56 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 28 Jan 2009 12:37:56 -0500 Subject: Process crash with no reason In-Reply-To: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> References: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> Message-ID: <41CFAEB0-8C19-45D0-9498-A9A7A7A36145@semanchuk.com> On Jan 28, 2009, at 12:12 PM, gil.shinar at gmail.com wrote: > On Jan 27, 5:59 pm, Philip Semanchuk wrote: >> On Jan 27, 2009, at 10:34 AM, gil.shi... at gmail.com wrote: >>> On Jan 27, 2:10 pm, Tim Golden wrote: >>>> Then how are you interacting with Sybase? >> >>> I'm using python's functions to run sybase sql commands. >> >> Can you give a short code sample? I'm unaware of how one would use >> the >> standard Python library to talk to Sybase, unless Sybase has a raw >> socket interface or some such. > > First of all I have found the following python's import: > > import Sybase This isn't part of the Python standard library. It's a 3rd party module -- exactly what we were looking for. Personally, I think this (or another C++ or C-based 3rd party module that you use heavily) is your prime suspect for the origin of the crashes you're having. That's not because I think the people who wrote or maintain it are bad or lazy coders. In fact, it's no reflection on their skill at all. It's just that a lot more people have used and exercised the Python standard library modules. A 3rd party module like this one will be less well-used and therefore less well-tested and therefore more likely to contain a bug that causes a crash. That said, I don't know how to advise you to proceed from here. You could perhaps turn on logging at the database level. I know Postgres, for instance, can write very detailed logs and so if you get a crash at 9:33:22 you can look in the log and see what was happening at that time. If you get several crashes and they all happen when a certain SQL statement is being executed, that's probably the culprit. You could also alter the Sybase module to add logging using Python's logging module. Who knows, it might already be there, waiting to be turned on with a switch. But I'm jumping the gun a little. As I said, it could be this module or another that's causing your problem. It's a lot easier to cause a hard crash using C or C++ than it is using pure Python, so pure Python modules would be lower on my list of suspects. Enumerate all of the modules you're using and find out where they come from. Any of them that are not in the standard library and are not written in pure Python should top your list of suspects. Good luck Philip From martin at v.loewis.de Wed Jan 28 12:38:46 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 18:38:46 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <498018B7.1070803@lexicon.net> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> <49800A25.2060702@v.loewis.de> <498018B7.1070803@lexicon.net> Message-ID: <49809826.2070701@v.loewis.de> > Big step. I don't have Visual Studio and have never used it before. > Which version of VS do I need to debug which released version of Python > 2.X and where do I get that VS from? Or do I need to build Python from > source to be able to debug it? You need Visual Studio 2008 (Professional, not sure about Standard), or Visual C++ 2008 (which is free). You need to build Python from source in debug mode; the released version is in release mode, and with no debug information. Regards, Martin From reckoner at gmail.com Wed Jan 28 12:39:44 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 28 Jan 2009 09:39:44 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> Message-ID: <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> On Jan 28, 9:16 am, koranthala wrote: > On Jan 28, 5:42 pm, koranthala wrote: > > > > > On Jan 28, 2:16 am, Reckoner wrote: > > > > I'm not sure this is possible, but I would like to have > > > a list of objects > > > > A=[a,b,c,d,...,z] > > > > where, in the midst of a lot of processing I might do something like, > > > > A[0].do_something_which_changes_the_properties() > > > > which alter the properties of the object 'a'. > > > > The trick is that I would like A to be mysteriously aware that > > > something about the object 'a' has changed so that when I revisit A, > > > I will know that the other items in the list need to be refreshed to > > > reflect the changes in A as a result of changing 'a'. > > > > Even better would be to automatically percolate the subsequent changes > > > that resulted from altering 'a' for the rest of the items in the list. > > > Naturally, all of these items are related in some parent-child > > > fashion. > > > > that might be a lot to ask, however. > > > > Any advice appreciated. > > > I think Python Cookbook has a recipe which deals with this. > > - 6.12 Checking an Instance for Any State Change. > > Were you able to get this? If not, let me know. I will try to type it > in here - (it is a big recipe, so not doing it now) Actually, I have the python cookbook, but cannot find the recipe you mention. maybe I have an older version? thanks. From pdorange at pas-de-pub-merci.mac.com Wed Jan 28 12:43:04 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 28 Jan 2009 18:43:04 +0100 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <1iu9nv4.ggxia541w0N%pdorange@pas-de-pub-merci.mac.com> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? I'm new to python, i began with IDLE, but then switch to TextWrangler+Terminal i prefer. Now i also try XCode (not opensource, but free from Apple) just as a text editor and still terminal, fine. Xcode editor is good for me. I try to use Python directly from Xcode but i do not understand the right way to do this. There is project for PyObjC but a can't make working directly simple script project, so i continue to use terminal... -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From koranthala at gmail.com Wed Jan 28 12:49:37 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:49:37 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> Message-ID: <52018aea-b706-444e-a820-bd262cacf29d@y23g2000pre.googlegroups.com> On Jan 28, 10:39?pm, Reckoner wrote: > On Jan 28, 9:16 am, koranthala wrote: > > > > > On Jan 28, 5:42 pm, koranthala wrote: > > > > On Jan 28, 2:16 am, Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > > > a list of ?objects > > > > > A=[a,b,c,d,...,z] > > > > > where, ?in the midst of a lot of processing I might do something like, > > > > > A[0].do_something_which_changes_the_properties() > > > > > which alter the properties of the object 'a'. > > > > > The trick is that I would like A to be mysteriously aware that > > > > something about the ?object 'a' has changed so that when I revisit A, > > > > I will know that the other items in the list need to be refreshed to > > > > reflect the changes in A as a result of changing 'a'. > > > > > Even better would be to automatically percolate the subsequent changes > > > > that resulted from altering 'a' for the rest of the items in the list. > > > > Naturally, all of these items are related in some parent-child > > > > fashion. > > > > > that might be a lot to ask, however. > > > > > Any advice appreciated. > > > > I think Python Cookbook has a recipe which deals with this. > > > - 6.12 Checking an Instance for Any State Change. > > > Were you able to get this? If not, let me know. I will try to type it > > in here - (it is a big recipe, so not doing it now) > > Actually, I have the python cookbook, but cannot find the recipe you > mention. maybe I have an older version? > > thanks. Mine is 2nd Edition. From excord80 at gmail.com Wed Jan 28 12:53:18 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:53:18 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <49802c05$0$5139$426a34cc@news.free.fr> Message-ID: <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> On Jan 28, 4:57?am, Bruno Desthuilliers wrote: > > What about:http://thraxil.org/code/cgi_app/ > > (yes, it is a port of CGI::Application, and FWIW it's mentionned on the > CGI::Application's wiki). > Nice find. Thank you. Interesting project. It seems to be only one fairly short file (perhaps that's all it takes), and its most recent release was in 2004. No mailing list. From steve at holdenweb.com Wed Jan 28 12:55:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 12:55:43 -0500 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden > escribi?: >> Gabriel Genellina wrote: >>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>> escribi?: > >>> I *thought* I did understand this until I came to this example: >>> >>> 1) >>>>>> id(globals()), id(locals()) >>> (11239760, 11239760) >>> >>> # ok, globals and locals are the same at the module level >>> >>> 2) >>>>>> s = "(id(n) for n in [globals(),locals()])" >>>>>> list(eval(s)) >>> [11239760, 11239760] # still the same results >>> >>> 3) >>>>>> s = "(id(n()) for n in [globals,locals])" >>>>>> list(eval(s)) >>> [11239760, 12583248] # locals() is different >>> >> No, locals is different, not locals(). You are looking at two different >> functions that return the same object when called in the given context, >> that's all. > > Perhaps you didn't notice that I shifted the () from right to left. I'm > always printing the result of *calling* globals and locals -- the only > change is *where* I do call them. > Ah, right. As you were ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From excord80 at gmail.com Wed Jan 28 12:56:12 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:56:12 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> On Jan 28, 5:05?am, Jeroen Ruigrok van der Werven wrote: > > Werkzeug[1] should be in your line, I think. > > [1]http://werkzeug.pocoo.org/ > Again, the solution must work for plain vanilla CGI. I don't have WSGI available. But thank you. From excord80 at gmail.com Wed Jan 28 12:58:34 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:58:34 -0800 (PST) Subject: small python-cgi wiki? References: Message-ID: <436cc75e-f86e-4ee1-98a4-d6681337c59b@g1g2000pra.googlegroups.com> On Jan 28, 12:02?pm, Bernard Rankin wrote: > > I'm looking to set up a small private wiki, and am looking for recommendations. > > Some sort of CGI based package that I could just untar somewhere web accessable via Apache would be great. There are a number of them listed at http://wiki.python.org/moin/PythonWikiEngines . You might have a look at PikiPiki. From Scott.Daniels at Acm.Org Wed Jan 28 13:00:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 28 Jan 2009 10:00:43 -0800 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden > escribi?: >> Gabriel Genellina wrote: >>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>> escribi?: > >>> I *thought* I did understand this until I came to this example: >>> >>> 1) >>>>>> id(globals()), id(locals()) >>> (11239760, 11239760) This is a bad test. We know distinct objects are distinct, but: >>> print id(object()), id(object()) 10598120 10598120 >>> a = object(); b = object() >>> print id(a), id(b) 10598120 10598128 The reason is that once your created object has its id taken, you must keep a handle on it, otherwise it may get recycled and reused. That is, id(var1) == id(var2) implies var1 is var2, but id(expr1) == id(expr2) does not even imply expr1 == expr2 --Scott David Daniels Scott.Daniels at Acm.Org From alecla at bluewin.ch Wed Jan 28 13:02:39 2009 From: alecla at bluewin.ch (alex) Date: Wed, 28 Jan 2009 10:02:39 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> Message-ID: <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Jon Thank you for your answer. I tried it with no success. However I tried with tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") and it runs now with no error message, I can't figure for now why, but it's great! This is motivating for going ahead. Regards Alex From coutinhotiago at gmail.com Wed Jan 28 13:05:39 2009 From: coutinhotiago at gmail.com (coutinhotiago at gmail.com) Date: Wed, 28 Jan 2009 10:05:39 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Hi! I had the same problem myself. Mark's detailed explanation really helped me understand. I ended up doing something like: class A: def __init__(self): names = 'n1', 'n2' for n in names: setattr(self, "get%s" % n, self._createGetter(n)) def _createGetter(self, n): def f(): return n return f Thanks a lot Cheers, Tiago From martin at v.loewis.de Wed Jan 28 13:13:00 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 19:13:00 +0100 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Message-ID: <4980a02c$0$25198$9b622d9e@news.freenet.de> > But the document also mentions that the result is not strictly > "undefined" but "reproducable undetermined". What specific document are you looking at, and where specifically does it say that? I can't believe that the quotation marks indicate an actual quote, in particular because "reproducible" is misspelled. In any case, I can't find anything like that in the 3.0 changes document, and, given that the comparison *does* give an exception, any statement that the result is undetermined would be false. Regards, Martin From schap at offenbachers.com Wed Jan 28 13:21:29 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 28 Jan 2009 13:21:29 -0500 Subject: Quickbooks Message-ID: <4980A229.1040606@offenbachers.com> Has anyone Implemented the Quickbooks COM object in Python. If so can you give me an Idea of where to begin. Thanks From rridge at csclub.uwaterloo.ca Wed Jan 28 13:29:08 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Jan 2009 13:29:08 -0500 Subject: unable to print Unicode characters in Python 3 References: <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: John Machin writes: > The only font choice offered apart from "Raster Fonts" in the Command > Prompt window's Properties box is "Lucida Console", not "Lucida Sans > Unicode". It will let me print Cyrillic characters from a C program, > but not Chinese. I'm off looking for how to get a better font. Thorsten Kampe wrote: >I have >[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont] >"00"="DejaVu Sans Mono" As near as I can tell the DejaVu Sans Mono font doesn't include Chinese characters. If you want to display Chinese characters in a console window on Windows you'll probably have change the (global) system locale to an appropriate Chinese locale and reboot. Note that a complete Unicode console font is essentially an impossibility, so don't bother looking for one. There are many characters in Unicode that can't be reasonably mappped to a single fixed-width "console" glyph. There are also characters in Unicode that should be represented as single-width gylphs in Western contexts, but as double-width glyphs in Far-Eastern contexts. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From Scott.Daniels at Acm.Org Wed Jan 28 13:33:04 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 28 Jan 2009 10:33:04 -0800 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Message-ID: towitowi at gmail.com wrote: > Hello, > > In the 3.0 changes list there is mentioned that "<"-compares are not > supported anymore if the compared types are different (except > numbers). Like > 42 < "Hello" > did return True of False depending on the implementation but is now a > TypeError. > > But the document also mentions that the result is not strictly > "undefined" but "reproducable undetermined". Meaning, that on a given > machine with a given python implementation result will always be the > same. But on another machine, or with another python implementation, > it might give a different result. > > My question now is, why this is? E.g, Is there an integer large enough > so that the result changes? What circumstances influence the result? The ordering of ints and strings may vary between python builds, but _any_ strings will have the same relationship to _any_ integers. That is, (str(x) < int(y)) == (str(y) < int(x)) for any x and y that don't cause exceptions. The types are compared before the values for sufficiently disparate types without accomodation in the comparison methods. This means the 2.X python series can sort more lists, but the sort order is not a particularly useful one (except for the fact that there is an order). --Scott David Daniels Scott.Daniels at Acm.Org From asmodai at in-nomine.org Wed Jan 28 13:33:55 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Wed, 28 Jan 2009 19:33:55 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> Message-ID: <20090128183355.GR99614@nexus.in-nomine.org> -On [20090128 19:01], excord80 (excord80 at gmail.com) wrote: >Again, the solution must work for plain vanilla CGI. I don't have WSGI >available. But thank you. It works for plain CGI. I myself use it for FCGI. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From reckoner at gmail.com Wed Jan 28 14:06:21 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 28 Jan 2009 11:06:21 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 9:46 pm, Steven D'Aprano wrote: > On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote: > > I'm not sure this is possible, but I would like to have a list of > > objects > > > A=[a,b,c,d,...,z] > > > where, in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that something > > about the object 'a' has changed so that when I revisit A, I will know > > that the other items in the list need to be refreshed to reflect the > > changes in A as a result of changing 'a'. > > Can't be done if A is a built-in list, probably can't be done entirely > generically, but you can probably do it in a cooperative manner. > > class TaintList(list): > tainted = False > def taint(self): > self.tainted = True > def untaint(self): > self.tainted = False > > A = TaintList() > > import functools > def taint(parent): > def decorator(func): > @functools.wraps(func) > def f(*args, **kwargs): > parent.taint() > return func(*args, **kwargs) > return f > return decorator > > class TaintAwareThing(object): > def __init__(self): > self.attr = 0 > @taint(A) > def change_attribute(self, x): > self.attr = x > > >>> x = TaintAwareThing() > >>> y = TaintAwareThing() > >>> z = TaintAwareThing() > > >>> A.extend([x, y, z]) > >>> A.tainted > False > >>> x.change_attribute(5) > >>> A.tainted > > True > > Here is a second approach: create a proxy class TaintThing that wraps > whatever object you want, using delegation: > > class TaintThing(object): > parent = A > def __init__(self, obj): > self.__dict__['_proxy'] = obj > def __getattr__(self, attr): > return getattr(self._proxy, attr) > def __setattr__(self, attr, value): > setattr(self._proxy, attr, value) > self.parent.taint() > > Now change TaintList to automatically wrap anything stored in it: > > # untested > class TaintList(list): > def append(self, obj): > list.append(self, TaintThing(obj)) > # similar for __setitem__, extend, insert > > -- > Steven thanks for your reply. For the second case where > class TaintThing(object): > parent = A > def __init__(self, obj): > self.__dict__['_proxy'] = obj > def __getattr__(self, attr): > return getattr(self._proxy, attr) > def __setattr__(self, attr, value): > setattr(self._proxy, attr, value) > self.parent.taint() you have told it that parent is 'A'. Shouldn't that be passed to it somehow in the following: > # untested > class TaintList(list): > def append(self, obj): > list.append(self, TaintThing(obj)) > # similar for __setitem__, extend, insert I apologize. I am probably missing something. This is getting pretty advanced for me. Thanks again. From blank at empty.blank Wed Jan 28 14:14:08 2009 From: blank at empty.blank (RGK) Date: Wed, 28 Jan 2009 14:14:08 -0500 Subject: Profiling Python Apps on Mac? Message-ID: I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & wxPython under OSX 10.4) As I make program architecture decisions, it would be nice to be able to profile the choices. Should I add that extra thread? Is this big-assed xml object I just created horribly bloated or kind of ordinary. Is there anything out there I should look into to if I want to see how those things are affecting my app? The closest I have is the widget iStat, but it's a very static low resolution view of what's really going on. Thx in advance. Ross. From philip at semanchuk.com Wed Jan 28 14:22:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 28 Jan 2009 14:22:18 -0500 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: <6149BE30-6C81-4368-AA71-74DA5430E604@semanchuk.com> On Jan 28, 2009, at 2:14 PM, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be > able to profile the choices. Should I add that extra thread? Is > this big-assed xml object I just created horribly bloated or kind of > ordinary. > > Is there anything out there I should look into to if I want to see > how those things are affecting my app? The closest I have is the > widget iStat, but it's a very static low resolution view of what's > really going on. Is there any reason that this wouldn't work? http://docs.python.org/library/hotshot.html From excord80 at gmail.com Wed Jan 28 14:32:25 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 11:32:25 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> Message-ID: <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> On Jan 28, 1:33?pm, Jeroen Ruigrok van der Werven wrote: > -On [20090128 19:01], excord80 (excor... at gmail.com) wrote: > > >Again, the solution must work for plain vanilla CGI. I don't have WSGI > >available. But thank you. > > It works for plain CGI. I myself use it for FCGI. Thanks, Jeroen. After looking at the Werkzeug "deploying" page, it seems as though one is able to write a WSGI webapp and have it work via CGI using something called wsgiref. Sounds good. If that's correct, it would be great if there were a Werkzeug tutorial on deploying it for use with CGI. Will look into wsgiref and Werkzeug. Thanks! From gagsl-py2 at yahoo.com.ar Wed Jan 28 14:48:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 17:48:14 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels escribi?: > Gabriel Genellina wrote: >> En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden >> escribi?: >>> Gabriel Genellina wrote: >>>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>>> >>>> escribi?: >> >>>> I *thought* I did understand this until I came to this example: >>>> >>>> 1) >>>>>>> id(globals()), id(locals()) >>>> (11239760, 11239760) > This is a bad test. We know distinct objects are distinct, but: > >>> print id(object()), id(object()) > 10598120 10598120 > > >>> a = object(); b = object() > >>> print id(a), id(b) > 10598120 10598128 > > The reason is that once your created object has its id taken, you > must keep a handle on it, otherwise it may get recycled and reused. It doesn't matter in this case, I think. globals() is always the same object and is alive during the whole test. So something having the same id() than globals() must be the very same object, and something having a different id() than globals() cannot be the same object. If you like, I can rewrite the example without using id(): >>> L = list(n for n in [globals(),locals()]) >>> L[0] is L[1] True >>> L = list(n() for n in [globals,locals]) >>> L[0] is L[1] False (I *think* this has to do with free variables in the "right side" (after the "in" keyword) of a generator expression; they appear to be evaluated when the expression is *defined*, not when is is *used*. By contrast, free variables in the "left side" appear to be evaluated when the expression is used.) -- Gabriel Genellina From blank at empty.blank Wed Jan 28 15:00:36 2009 From: blank at empty.blank (RGK) Date: Wed, 28 Jan 2009 15:00:36 -0500 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: Philip Semanchuk wrote: > > Is there any reason that this wouldn't work? > > http://docs.python.org/library/hotshot.html It suggests that it doesn't work well with threads, but as I didn't know about any options, it's a step forward. Thanks for the pointer. :) R. From __peter__ at web.de Wed Jan 28 15:06:01 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 21:06:01 +0100 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: Gabriel Genellina wrote: >>>> L = list(n for n in [globals(),locals()]) >>>> L[0] is L[1] > True >>>> L = list(n() for n in [globals,locals]) >>>> L[0] is L[1] > False > > (I think this has to do with free variables in the "right side" (after > the "in" keyword) of a generator expression; they appear to be evaluated > when the expression is *defined*, not when is is *used*. By contrast, free > variables in the "left side" appear to be evaluated when the expression is > used.) Indeed, the right side is evaluated in the enclosing namespace and then passed as an argument to the genexpr: >>> dis.dis(compile("(x for y in z)", "nofile", "exec")) 1 0 LOAD_CONST 0 ( at 0x2b22b2dcf828, file "nofile", line 1>) 3 MAKE_FUNCTION 0 6 LOAD_NAME 0 (z) 9 GET_ITER 10 CALL_FUNCTION 1 13 POP_TOP 14 LOAD_CONST 1 (None) 17 RETURN_VALUE Peter From xnews2 at fredp.lautre.net Wed Jan 28 15:10:29 2009 From: xnews2 at fredp.lautre.net (Fred Pacquier) Date: 28 Jan 2009 20:10:29 GMT Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: excord80 said : >> What are you looking for in your framework? > > Well, let's see. I don't need a templating library, since -- as you > pointed out -- I can just use Python's own. I don't need a db > interface (can just make my own dbapi calls if needed). Don't need url > mapping (can just use mod_rewrite rules in my .htaccess to point at my > cgi scripts). Don't think I need any i80n. And I don't need an admin > interface. ... It would seem that I don't need a whole lot at the > moment. That would be something close to Karrigell... From petite.abeille at gmail.com Wed Jan 28 15:12:12 2009 From: petite.abeille at gmail.com (Petite Abeille) Date: Wed, 28 Jan 2009 21:12:12 +0100 Subject: small python-cgi wiki? In-Reply-To: <889572.28267.qm@web112204.mail.gq1.yahoo.com> References: <889572.28267.qm@web112204.mail.gq1.yahoo.com> Message-ID: On Jan 28, 2009, at 6:02 PM, Bernard Rankin wrote: > I'm looking to set up a small private wiki, and am looking for > recommendations. > > Some sort of CGI based package that I could just untar somewhere web > accessable via Apache would be great. You might be interested by Nanoki, a small, simple wiki engine. Online demo: http://svr225.stepx.com:3388/search?q=python http://svr225.stepx.com:3388/nanoki One thing though... it's not Python :) Cheers, -- PA. http://alt.textdrive.com/nanoki/ From rt8396 at gmail.com Wed Jan 28 15:17:31 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 12:17:31 -0800 (PST) Subject: What is intvar? [Python Docs] References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> Message-ID: On Jan 26, 11:15?am, "W. eWatson" wrote: > I might be repeating myself here, but If anyone has pdf experience, and > could provide page numbers and maybe a TOC for some of Lundh's > contributions, that would be helpful. Did you try this one? http://effbot.org/tkinterbook/tkinter-index.htm here is the older less detailed version: http://www.pythonware.com/library/tkinter/introduction/ neither are PDF thought. But NMT has a PDF download here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/ From bjracine at glosten.com Wed Jan 28 15:20:30 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Wed, 28 Jan 2009 12:20:30 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8C077@clipper.glosten.local> I've tried Wing IDE professional, vim, textmate, and PyDev and am intrigued by each one for different reasons. Whichever module browser I get more comfortable between Wing and PyDev/Eclipse is probably the direction I will end up going. Further, if I get the Hg and SVN plugins for PyDev/Eclipse up and running, I think I will probably go in that direction, but will probably still need to use a wxPython GUI constructor like BOA or Glade. I have vim key-bindings in all four, so at least I don't fumble over that. I really haven't been able to decide yet... You could go to showmedo.com in order to see ipython, wing and pydev/eclipse all in action. HTH, Ben -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of joseph.a.marlin at gmail.com Sent: Tuesday, January 27, 2009 4:14 PM To: python-list at python.org Subject: Re: New to python, open source Mac OS X IDE? On Jan 27, 6:47?pm, Andr? wrote: > On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" > > wrote: > > Greetings! I've heard enough raving about Python, I'm going to see > > for myself what all the praise is for! > > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > > even use an IDE for Python? > > If you already use netbeans, what > abouthttp://www.netbeans.org/features/python/ > ? > Wow, you guys are fast... yes, I was having trouble deciding between that (Netbeans), Smultron, or TextWrangler. Thanks! -- http://mail.python.org/mailman/listinfo/python-list From ocschwar at gmail.com Wed Jan 28 15:38:17 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 12:38:17 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. Message-ID: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Hi, all. I have an application that that creates, manipulates, and finally archives on disk 10^6 instances of an object that in CS/DB terms is best described as a relation. It has 8 members, all of them common Python datatypes. 6 of these are set once and then not modified. 2 are modified around 4 times before the instance's archving. Large collections (of small lists) of these objects are created, iterated through, and sorted using any and all of the 8 members as sorting keys. It neither has nor needs custom methods. I used a simple dictionary to create the application prototype. Now I need to speed things up. I first tried changing to a new style class, with __slots__, __init__, __getstate__& __setstate__ (for pickling) and was shocked to see things SLOW down over dictionaries. So of these options, where should I go first to satisfy my need for speed? 0. Back to dict 1. old style class 2. new style class 3. new style class, with __slots__, with or without some nuance I'm missing. 4. tuple, with constants to mark the indices 5. namedTuple 6. other... From akineko at gmail.com Wed Jan 28 15:46:56 2009 From: akineko at gmail.com (akineko) Date: Wed, 28 Jan 2009 12:46:56 -0800 (PST) Subject: Terminating a Python program that uses multi-process, multi-threading Message-ID: Hello Python experts, I have a program that uses three processes (invoked by multiprocessing) and several threads. The program is terminated when ^C is typed (KeyboardInterrupt). The main process takes the KeyboardInterrupt Exception and it orderly shutdown the program. It works fine in normal situation. However, KeyboardInterrupt is not accepted when, for example, the program is stuck somewhere due to error in network. I understand that the KeyboardInterrupt won't be processed until the program moves out from an atomic step in a Python program. Probably this is partly my fault as I use some blocking statements (without timeout) as they should not block the program in normal situation. As the program freezes up, I cannot do anything except killing three processes using kill command. So, I cannot tell which statement is actually blocking when this occurs (and there are many suspects). Is there any good way to deal with this kind of problem? Killing three processes when it hangs is not a fun thing to do. Any suggestions will be greatly appreciated. Best regards, Aki Niimura From rtw at freenet.co.uk Wed Jan 28 15:51:20 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 28 Jan 2009 14:51:20 -0600 Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 @b38g2000prf.googlegroups.com in comp.lang.python: > > I have mingw32-gcc in my path. If I try that too -it fails. > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > "mingw32-gcc" > invalid command name 'mingw32-gcc' > All the examples I found via google have the tool name as "mingw32" so try: python setup.py install -c mingw32 or python setup.py build --compiler=mingw32 install The compiler that the MinGW package installs is gcc. You shoulf be able to verify it is on your path by typing: gcc --help or gcc --version and see some output. Rob. -- http://www.victim-prime.dsl.pipex.com/ From s.selvamsiva at gmail.com Wed Jan 28 15:55:21 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 29 Jan 2009 02:25:21 +0530 Subject: date handling problem Message-ID: Hi all, I need to parse rss-feeds based on time stamp,But rss-feeds follow different standards of date(IST,EST etc). I dont know,how to standardize this standards.It will be helpful if you can hint me. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From excord80 at gmail.com Wed Jan 28 16:02:47 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 13:02:47 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <36a98419-c111-440b-84a3-177c6b126936@w24g2000prd.googlegroups.com> On Jan 28, 3:10?pm, Fred Pacquier wrote: > > That would be something close to Karrigell... You know, I stumbled across Karrigell while looking around but was initially uninterested because of what initially seems like a lack of direction. That is, they tell you that you can use it any way you like: * python script * K service * html inside python * python inside html * cgi script So, I wasn't sure what to make of that. However, perhaps it's a strength... will have to look more into K. Thanks. From google at mrabarnett.plus.com Wed Jan 28 16:11:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 21:11:04 +0000 Subject: Terminating a Python program that uses multi-process, multi-threading In-Reply-To: References: Message-ID: <4980C9E8.7030001@mrabarnett.plus.com> akineko wrote: > Hello Python experts, > > I have a program that uses three processes (invoked by > multiprocessing) and several threads. > The program is terminated when ^C is typed (KeyboardInterrupt). > The main process takes the KeyboardInterrupt Exception and it orderly > shutdown the program. > > It works fine in normal situation. > > However, KeyboardInterrupt is not accepted when, for example, the > program is stuck somewhere due to error in network. I understand that > the KeyboardInterrupt won't be processed until the program moves out > from an atomic step in a Python program. > > Probably this is partly my fault as I use some blocking statements > (without timeout) as they should not block the program in normal > situation. > > As the program freezes up, I cannot do anything except killing three > processes using kill command. > So, I cannot tell which statement is actually blocking when this > occurs (and there are many suspects). > > Is there any good way to deal with this kind of problem? > Killing three processes when it hangs is not a fun thing to do. > > Any suggestions will be greatly appreciated. > The scripts could write to a log around where they could block (write to the log just before and just after), so that you can then see where they blocked. A hacky way of killing the processes would be for the processes to write their process IDs to the log and then you can write another script which will parse the log to get the process IDs and then kill the processes with those IDs. (Left as an exercise for the reader. :-)) From xahlee at gmail.com Wed Jan 28 16:32:29 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 28 Jan 2009 13:32:29 -0800 (PST) Subject: Function Application is not Currying Message-ID: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Function Application is not Currying Xah Lee, 2009-01-28 In Jon Harrop's book Ocaml for Scientist at http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html It says: Currying A curried function is a function which returns a function as its result. LOL. That is incorrect. Here are some examples of a function that returns a function as result, but is not currying. Mathematica example: f[n_]:=Function[n^#]; f[7][2] (* returns 49 *) Emacs lisp example: (defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) ) (funcall (f 7) 2) Perl example: sub f {$n=$_[0]; sub { $n ** $_[0]} }; print &{ f(7) } (2); Javascript example: function f(n) {return function (x) {return Math.pow(x,n);}; } alert (f(7) (2)); In the above, a function returns a function, and the result function is applied to a value. They demonstrate 2 things: * The ability of the lang to have a function that returns a function. * The ability to apply a value (of type function) to a value. These, are 2 of the features that is part of often sloppily termed as ?function as first class citizens?. However, the above are not languages that support currying, which is a feature that Haskell & Ocaml has. So what is Currying? Wikipedia article Currying said it best: In computer science, currying, invented by Moses Sch?nfinkel and Gottlob Frege, and independently by Haskell Curry,[1] is the technique of transforming a function that takes multiple arguments (or more accurately an n-tuple as argument) in such a way that it can be called as a chain of functions each with a single argument. Note how it says ?is the technique of ...?. To be more concrete, in the context of a given computer language, to say that it support curring, is to mean that the compiler understand the concept to certain degree. More to the point, the language is inherently able to take a function of more than one arg and deconstruct it to several functions of single arg. To say that function returning function is Currying, is a confusion of fundamental concepts. Mathematically, currying is the concept of deconstructing a function of multiple parameters to a composition of several functions all of arity 1. I like Jon, because i consider majority of his argument and perspective are more correct or sensible in his trollish spats in newsgroup fighting with tech geekers. But he is really a asshole, and take every chance to peddle his book. Every mother fucking opponitunity, he injects random opinion into discussions about how static typing or greatness of Microsoft, which paves a way for him to post a link to his book on Ocaml/F# or ?study? or ?speed comparison? of his site. He does this repeatedly and intentionally, about every week for the past 2 or so years, and write in a way to provoke irate responses. In the past 2 or 3 years, i have for 2 or so times without his or anyone's solicitation, publically supported him in ugly newsgroup fights (such as some serious sounding post that accuse him of spamming or or some real life threats about network abuse). However, in the past year as i have had some debates on language issues with jon, i find Jon to be a complete asshole as far as his newsgroup demeanor goes. PS see also: A Mathematica Optimization Problem ( story of a thread where Jon started a fight with me ) Perm url for this post: ? Function Application is not Currying http://xahlee.org/UnixResource_dir/writ/apply_func_examples.html Xah ? http://xahlee.org/ ? From rNOSPAMon at flownet.com Wed Jan 28 16:35:56 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 13:35:56 -0800 Subject: Sloooooowwwww WSGI restart Message-ID: I'm running a WSGI app under apache/mod_wsgi and I've noticed that whenever I restart the server after making a code change it takes a very long time (like a minute) before the script is active again. In other words, I do an apachectl restart, reload the page in my browser, and one minute later it finally comes up. During this time CPU usage is essentially zero. Loading all the code manually into a python interpreter is virtually instantaneous, and all subsequence interactions with the app are very fast. Does anyone have any ideas what might be going on or how to debug this? Thanks, rg From exarkun at divmod.com Wed Jan 28 16:44:05 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 16:44:05 -0500 Subject: Sloooooowwwww WSGI restart In-Reply-To: Message-ID: <20090128214405.24460.1545518426.divmod.quotient.3405@henry.divmod.com> On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret wrote: >I'm running a WSGI app under apache/mod_wsgi and I've noticed that >whenever I restart the server after making a code change it takes a very >long time (like a minute) before the script is active again. In other >words, I do an apachectl restart, reload the page in my browser, and one >minute later it finally comes up. During this time CPU usage is >essentially zero. Loading all the code manually into a python >interpreter is virtually instantaneous, and all subsequence interactions >with the app are very fast. > >Does anyone have any ideas what might be going on or how to debug this? strace is nice. It sounds like some blocking network operation. rdns can often cause things like this. If you're lucky, strace will point right at the problem. Jean-Paul From alex at a13x.net Wed Jan 28 16:44:44 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Wed, 28 Jan 2009 21:44:44 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <845b10c50901281344k4e76cc93w69fed1c33c47a7ad@mail.gmail.com> Hi there, On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > I'm running a WSGI app under apache/mod_wsgi and I've noticed that Off the bat, there's no reason to run an app under apache/mod_wsgi while developing it, ie. if u use Pylons or TurboGears, there's an easier way to serve the app (using paster or cherrypy). Secondly, why are you restarting apache after code changes? In normal circumstances, you shouldn't have to do that. -- a lex 13 x http://www.a13x.info From castironpi at gmail.com Wed Jan 28 16:45:19 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 13:45:19 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 28, 10:13?am, perfr... at gmail.com wrote: > hello all, > > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, snip > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. There is the 'shelve' module. You could create a shelf that tells you the filename of the 5 other ones. A million keys should be no problem, I guess. (It's standard library.) All your keys have to be strings, though, and all your values have to be pickleable. If that's a problem, yes you will need ZODB or Django (I understand), or another relational DB. From alex at a13x.net Wed Jan 28 16:49:40 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Wed, 28 Jan 2009 21:49:40 +0000 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <845b10c50901281349q5cf2c554n7044c53693a10b64@mail.gmail.com> On Tue, Jan 27, 2009 at 11:06 PM, joseph.a.marlin at gmail.com wrote: > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? I'm on a Mac, too. I don't use a full-fledged IDE for Python development, nor I think it's necessary. > Any recommendations on open source Python environments? Komodo Edit looks very professional and very usable. Other alternatives are PyDev w/ Eclipse, but I opted for TextMate - it has excellent features. I highly recommend spending ~$50 on it, it's money well spent. -- a lex 13 x http://www.a13x.info From castironpi at gmail.com Wed Jan 28 16:50:33 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 13:50:33 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Message-ID: <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: > Hi, all. > > I have an application that that creates, manipulates, and finally > archives on disk 10^6 instances of an object that in CS/DB terms is > best described as a relation. > > It has 8 members, all of them common Python datatypes. 6 of these are > set once and then not modified. 2 are modified around 4 times before > the instance's archving. Large collections (of small lists) of these > objects are created, iterated through, and sorted using any and all of > the 8 members as sorting keys. > > It neither has nor needs custom methods. > > I used a simple dictionary to create the application prototype. Now I > need to speed things up. > I first tried changing to a new style class, with __slots__, __init__, > __getstate__& __setstate__ (for pickling) and was shocked to see > things SLOW down over dictionaries. > > So of these options, where should I go first to satisfy my need for > speed? > > 0. Back to dict > 1. old style class > 2. new style class > 3. new style class, with __slots__, with or without some nuance I'm > missing. > 4. tuple, with constants to mark the indices > 5. namedTuple > 6. other... Hello, quoting myself from another thread today: There is the 'shelve' module. You could create a shelf that tells you the filename of the 5 other ones. A million keys should be no problem, I guess. (It's standard library.) All your keys have to be strings, though, and all your values have to be pickleable. If that's a problem, yes you will need ZODB or Django (I understand), or another relational DB. There is currently no way to store live objects. From sjmachin at lexicon.net Wed Jan 28 17:14:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 14:14:36 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 29, 3:13?am, perfr... at gmail.com wrote: > hello all, > > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > 'world'}, ...], > ? ? ? ? ? ? ? ? key2: [...]} > > in total there are about 10 to 15 million lists if we concatenate > together all the values of every key in 'mydict'. mydict is a > structure that represents data in a very large file (about 800 > megabytes). > > what is the fastest way to pickle 'mydict' into a file? right now i am > experiencing a lot of difficulties with cPickle when using it like > this: > > from cPickle import pickle > pfile = open(my_file, 'w') > pickle.dump(mydict, pfile) > pfile.close() > > this creates extremely large files (~ 300 MB) though it does so > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > it gets slower and slower. it takes almost an hour if not more to > write this pickle object to file. > > is there any way to speed this up? i dont mind the large file... after > all the text file with the data used to make the dictionary was larger > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > i do care about speed... > > i have tried optimizing this by using this: > > s = pickle.dumps(mydict, 2) > pfile.write(s) > > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. Pardon me if I'm asking the "bleedin' obvious", but have you checked how much virtual memory this is taking up compared to how much real memory you have? If the slowness is due to pagefile I/O, consider doing "about 10" separate pickles (one for each key in your top-level dictionary). From tjreedy at udel.edu Wed Jan 28 17:15:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Jan 2009 17:15:31 -0500 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <4980a02c$0$25198$9b622d9e@news.freenet.de> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> <4980a02c$0$25198$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> But the document also mentions that the result is not strictly >> "undefined" but "reproducable undetermined". > > What specific document are you looking at, and where specifically > does it say that? I can't believe that the quotation marks indicate > an actual quote, in particular because "reproducible" is misspelled. I believe there was something like that in the 2.x docs but nothing in the Expressions / Comparisons section of 3.0. > > In any case, I can't find anything like that in the 3.0 changes > document, and, given that the comparison *does* give an exception, > any statement that the result is undetermined would be false. From deets at nospam.web.de Wed Jan 28 17:21:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 28 Jan 2009 23:21:09 +0100 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Message-ID: <6uc42lFcmn4iU1@mid.uni-berlin.de> ocschwar at gmail.com schrieb: > Hi, all. > > I have an application that that creates, manipulates, and finally > archives on disk 10^6 instances of an object that in CS/DB terms is > best described as a relation. > > It has 8 members, all of them common Python datatypes. 6 of these are > set once and then not modified. 2 are modified around 4 times before > the instance's archving. Large collections (of small lists) of these > objects are created, iterated through, and sorted using any and all of > the 8 members as sorting keys. > > It neither has nor needs custom methods. > > I used a simple dictionary to create the application prototype. Now I > need to speed things up. > I first tried changing to a new style class, with __slots__, __init__, > __getstate__& __setstate__ (for pickling) and was shocked to see > things SLOW down over dictionaries. > > So of these options, where should I go first to satisfy my need for > speed? > > 0. Back to dict > 1. old style class > 2. new style class > 3. new style class, with __slots__, with or without some nuance I'm > missing. > 4. tuple, with constants to mark the indices > 5. namedTuple > 6. other... Use a database? Or *maybe* a C-extension wrapped by ctypes. Diez From gagsl-py2 at yahoo.com.ar Wed Jan 28 17:32:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 20:32:27 -0200 Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: En Wed, 28 Jan 2009 16:05:39 -0200, coutinhotiago at gmail.com escribi?: > I had the same problem myself. > Mark's detailed explanation really helped me understand. > > I ended up doing something like: The code doesn't work as-is, could you please post a working version? Just for the record, so people reading this thread later don't get confused. -- Gabriel Genellina From tutufan at gmail.com Wed Jan 28 17:33:33 2009 From: tutufan at gmail.com (Mike) Date: Wed, 28 Jan 2009 14:33:33 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: <62b51c07-614d-4963-be31-c5826abf1b21@40g2000prx.googlegroups.com> On Jan 17, 5:55?pm, "Brendan Miller" wrote: > The python devs seem to > consider the GIL a non-issue, though they may change their mind in 3 > years when we all have 32 core desktops, For what it's worth, I am currently using Python to perform a scientific computation on 1400+ cores, and it seems to work fairly well. (http://greylag.org/ if you're curious.) There are a number of things that annoy me about Python (even though it's my favorite everyday language), but the GIL isn't among them. The rare cases where the GIL is truly a problem can be balanced against the large majority where threading is simply inappropriate anyway. That the latter might help compulsive threaders kick their habit (or at least head for more convoluted horizons) might be considered a virtue. Mike From perfreem at gmail.com Wed Jan 28 17:43:16 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 14:43:16 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> On Jan 28, 5:14?pm, John Machin wrote: > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > hello all, > > > i have a large dictionary which contains about 10 keys, each key has a > > value which is a list containing about 1 to 5 million (small) > > dictionaries. for example, > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > 'world'}, ...], > > ? ? ? ? ? ? ? ? key2: [...]} > > > in total there are about 10 to 15 million lists if we concatenate > > together all the values of every key in 'mydict'. mydict is a > > structure that represents data in a very large file (about 800 > > megabytes). > > > what is the fastest way to pickle 'mydict' into a file? right now i am > > experiencing a lot of difficulties with cPickle when using it like > > this: > > > from cPickle import pickle > > pfile = open(my_file, 'w') > > pickle.dump(mydict, pfile) > > pfile.close() > > > this creates extremely large files (~ 300 MB) though it does so > > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > > it gets slower and slower. it takes almost an hour if not more to > > write this pickle object to file. > > > is there any way to speed this up? i dont mind the large file... after > > all the text file with the data used to make the dictionary was larger > > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > > i do care about speed... > > > i have tried optimizing this by using this: > > > s = pickle.dumps(mydict, 2) > > pfile.write(s) > > > but this takes just as long... any ideas ? is there a different module > > i could use that's more suitable for large dictionaries ? > > thank you very much. > > Pardon me if I'm asking the "bleedin' obvious", but have you checked > how much virtual memory this is taking up compared to how much real > memory you have? If the slowness is due to pagefile I/O, consider > doing "about 10" separate pickles (one for each key in your top-level > dictionary). the slowness is due to CPU when i profile my program using the unix program 'top'... i think all the work is in the file I/O. the machine i am using several GB of ram and ram memory is not heavily taxed at all. do you know how file I/O can be sped up? in reply to the other poster: i thought 'shelve' simply calls pickle. if thats the case, it wouldnt be any faster, right ? From cosmo_general at yahoo.com Wed Jan 28 17:49:14 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Wed, 28 Jan 2009 14:49:14 -0800 (PST) Subject: Results of executing hyperlink in script Message-ID: Hi Folks, My previous post got a many helps from the people, and I tested what they suggested. Since this topic maybe needed in future, so I drop these lines below to help the future programmers. The methods worked as below: 1. This method was suggested by Cameron Laird: os.system("start %s" % URL) It works. But, if the URL contains character &, it will fail. For example, if URL has only one field, such as: http://www.mydomain.com/ascript.cgi?user=muddy this method works well. But, if there more than one field need to be input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, the field password failed to reach server, and the CGI script complained. 2. The best way is to use urllib2, suggested by Ron Barak, my code is below: import urllib2 source = urllib2.urlopen(URL).read() print source It successfully triggered CGI script, and also got feedback from server. It works very well! My thanks go to all the helpers! Muddy Coder From prologic at shortcircuit.net.au Wed Jan 28 17:55:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 29 Jan 2009 08:55:09 +1000 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> Message-ID: Jesse: Can I mail you off-list regarding multiprocessing ? cheers James -- -- "Problems are solved by method" From sjmachin at lexicon.net Wed Jan 28 18:00:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:00:39 -0800 (PST) Subject: bigint to timestamp References: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> Message-ID: <4ee860a7-be3d-45a9-b393-260942fa08cb@x16g2000prn.googlegroups.com> On Jan 29, 1:05?am, Jon Clements wrote: > On Jan 28, 1:50?pm, Steve Holden wrote: > > > > > Shah Sultan Alam wrote: > > > Hi Group, > > > I have file with contents retrieved from mysql DB. > > > which has a time field with type defined bigint(20) > > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > > GMT) using python code. > > > The value I found for that field is 212099016004150509 > > > Give me sample code that does the conversion. > > > Please? > > > Perhaps you could tell us what date and time 212099016004150509 is > > supposed to represent? The classic format is "seconds since the Unix > > epoch" but that isn't what this is: > > > >>> time.localtime(212099016004150509) > > > Traceback (most recent call last): > > ? File "", line 1, in > > ValueError: timestamp out of range for platform time_t > > > Neither does it appear to be a MySQL TIME field, since the maximum value > > for that would appear to be > > > >>> ((838*60)+59)*60+59 > > > 3020399 > > > So, just what is this field? What do the values mean? > > > regards > > ?Steve > > -- > > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > Bit hard to guess without the actual date to compare to... and I'm a > bit busy, but thought I'd throw this in the pool: I'm guessing it's a > MySQL database that's had data put into it via a .NET application > using the .NET DateTime (so a 20 byte int sounds about right IIRC), > which is based on the number of ticks since Jan 1, 1.... I think that > should end up around 2[18ish digits here...]... Mmmm ... I thought it might be the MS format that's ticks since 1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen 10,000,000 times per second, but: >>> x = 212099016004150509 >>> seconds = x / 10000000.0 >>> seconds 21209901600.415051 >>> days = seconds / 60. / 60. / 24. >>> days 245484.97222702604 >>> years_approx = days / 365.25 >>> years_approx 672.10122444086528 which would make it in the year 2272. Perhaps the OP could tell us what are the maximum and minimum non-zero non-null values he can find, and what years those might belong to. Also (very important) he might assure us that he is copying/pasting those large numbers, not retyp[o]ing them. From banaouas.medialog at wanadoo.fr Wed Jan 28 18:02:50 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Thu, 29 Jan 2009 00:02:50 +0100 Subject: file date/time on windows In-Reply-To: References: <49807795$0$18360$ba4acef3@news.orange.fr> Message-ID: <4980e41a$0$9403$ba4acef3@news.orange.fr> thanks, someone gave me the solution: simply call time.localtime(...) instead of time.gmtime(...) The explorer file time is what I need because it's the only file date visible for most of users. So localtime is perfect for me. We are talking about the same file stored in a shared lan-computer-folder. I gess that if computers of those users are in different timezones, they could see different file date ? MRAB a ?crit : > m.banaouas wrote: >> hi, >> >> I noticed recently that the value of file date/time I get with python: >> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) >> is forwarding by one hour the real file date/time. >> >> Example: >> file A.txt: 2009-01-18 16:13 >> returned valeur: 2009-01-28 15:13 >> >> Is there a simple way to get it work correctely (other than adding >> always 1 >> hour ...) ? >> > time.gmtime(), as the name suggests, returns GMT (UTC). > > From your email address I presume you're in France, which is GMT+1. > > Windows Explorer shows the file time in local time, which for you is > currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. From castironpi at gmail.com Wed Jan 28 18:08:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 15:08:40 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> Message-ID: <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > hello all, > > > > i have a large dictionary which contains about 10 keys, each key has a > > > value which is a list containing about 1 to 5 million (small) > > > dictionaries. for example, > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > 'world'}, ...], > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > in total there are about 10 to 15 million lists if we concatenate > > > together all the values of every key in 'mydict'. mydict is a > > > structure that represents data in a very large file (about 800 > > > megabytes). snip > in reply to the other poster: i thought 'shelve' simply calls pickle. > if thats the case, it wouldnt be any faster, right ? Yes, but not all at once. It's a clear winner if you need to update any of them later, but if it's just write-once, read-many, it's about the same. You said you have a million dictionaries. Even if each took only one byte, you would still have a million bytes. Do you expect a faster I/ O time than the time it takes to write a million bytes? I want to agree with John's worry about RAM, unless you have several+ GB, as you say. You are not dealing with small numbers. From google at mrabarnett.plus.com Wed Jan 28 18:14:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:14:59 +0000 Subject: Results of executing hyperlink in script In-Reply-To: References: Message-ID: <4980E6F3.4010702@mrabarnett.plus.com> Muddy Coder wrote: > Hi Folks, > > My previous post got a many helps from the people, and I tested what > they suggested. Since this topic maybe needed in future, so I drop > these lines below to help the future programmers. The methods worked > as below: > > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For > example, if URL has only one field, such as: http://www.mydomain.com/ascript.cgi?user=muddy > this method works well. But, if there more than one field need to be > input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, > the field password failed to reach server, and the CGI script > complained. > You could put quotes around the URL: os.startfile('"%s"' % URL) or: os.system('start "%s"' % URL) if "&" has a special meaning to the command-line. From sln at netherlands.com Wed Jan 28 18:17:13 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Wed, 28 Jan 2009 23:17:13 GMT Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee wrote: >Function Application is not Currying > >Xah Lee, 2009-01-28 > >In Jon Harrop's book Ocaml for Scientist at >http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > >It says: > > Currying > > A curried function is a function which returns a function as its >result. > Curry, is that like chicken soup or some Indian mash? Why ? How about returning an index number into an array of function pointers as handlers from packet data? Oh, thats network communications. sln From ocschwar at gmail.com Wed Jan 28 18:20:41 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 15:20:41 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: On Jan 28, 4:50?pm, Aaron Brady wrote: > On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: > > Hello, quoting myself from another thread today: > > There is the 'shelve' module. ?You could create a shelf that tells you > the filename of the 5 other ones. ?A million keys should be no > problem, I guess. ?(It's standard library.) ?All your keys have to be > strings, though, and all your values have to be pickleable. ?If that's > a problem, yes you will need ZODB or Django (I understand), or another > relational DB. > > There is currently no way to store live objects. The problem is NOT archiving these objects. That works fine. It's the computations I'm using these thigns for that are slow, and that failed to speed up using __slots__. What I need is something that will speed up getattr() or its equivalent, and to a lesser degree setattr() or its equivalent. From ocschwar at gmail.com Wed Jan 28 18:23:47 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 15:23:47 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> Message-ID: <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> On Jan 28, 5:21?pm, "Diez B. Roggisch" wrote: > ocsch... at gmail.com schrieb: > > > > > Hi, all. > > > I have an application that that creates, manipulates, and finally > > archives on disk 10^6 instances of an object that in CS/DB terms is > > best described as a relation. > > > It has 8 members, all of them common Python datatypes. 6 of these are > > set once and then not modified. 2 are modified around 4 times before > > the instance's archving. Large collections (of small lists) of these > > objects are created, iterated through, and sorted using any and all of > > the 8 members as sorting keys. > > > It neither has nor needs custom methods. > > > I used a simple dictionary to create the application prototype. Now I > > need to speed things up. > > I first tried changing to a new style class, with __slots__, __init__, > > __getstate__& __setstate__ (for pickling) and was shocked to see > > things SLOW down over dictionaries. > > > So of these options, where should I go first to satisfy my need for > > speed? > > > 0. Back to dict > > 1. old style class > > 2. new style class > > 3. new style class, with __slots__, with or without some nuance I'm > > missing. > > 4. tuple, with constants to mark the indices > > 5. namedTuple > > 6. other... > > Use a database? Or *maybe* a C-extension wrapped by ctypes. > > Diez I can't port the entire app to be a stored database procedure. ctypes, maybe. I just find it odd that there's no quick answer on the fastest way in Python to implement a mapping in this context. From deets at nospam.web.de Wed Jan 28 18:24:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 29 Jan 2009 00:24:25 +0100 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: <6uc7paFepb16U1@mid.uni-berlin.de> ocschwar at gmail.com schrieb: > On Jan 28, 4:50 pm, Aaron Brady wrote: >> On Jan 28, 2:38 pm, ocsch... at gmail.com wrote: >> >> Hello, quoting myself from another thread today: >> >> There is the 'shelve' module. You could create a shelf that tells you >> the filename of the 5 other ones. A million keys should be no >> problem, I guess. (It's standard library.) All your keys have to be >> strings, though, and all your values have to be pickleable. If that's >> a problem, yes you will need ZODB or Django (I understand), or another >> relational DB. >> >> There is currently no way to store live objects. > > > The problem is NOT archiving these objects. That works fine. I know. But if they are sorted to various criteria, doing that inside a DB might also be faster. That was the point I wanted to make. Diez From sjmachin at lexicon.net Wed Jan 28 18:26:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:26:00 -0800 (PST) Subject: bigint to timestamp References: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> <4ee860a7-be3d-45a9-b393-260942fa08cb@x16g2000prn.googlegroups.com> Message-ID: On Jan 29, 10:00?am, John Machin wrote: > On Jan 29, 1:05?am, Jon Clements wrote: > > > > > On Jan 28, 1:50?pm, Steve Holden wrote: > > > > Shah Sultan Alam wrote: > > > > Hi Group, > > > > I have file with contents retrieved from mysql DB. > > > > which has a time field with type defined bigint(20) > > > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > > > GMT) using python code. > > > > The value I found for that field is 212099016004150509 > > > > Give me sample code that does the conversion. > > > > Please? > > > > Perhaps you could tell us what date and time 212099016004150509 is > > > supposed to represent? The classic format is "seconds since the Unix > > > epoch" but that isn't what this is: > > > > >>> time.localtime(212099016004150509) > > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ValueError: timestamp out of range for platform time_t > > > > Neither does it appear to be a MySQL TIME field, since the maximum value > > > for that would appear to be > > > > >>> ((838*60)+59)*60+59 > > > > 3020399 > > > > So, just what is this field? What do the values mean? > > > > regards > > > ?Steve > > > -- > > > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > > > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > > Bit hard to guess without the actual date to compare to... and I'm a > > bit busy, but thought I'd throw this in the pool: I'm guessing it's a > > MySQL database that's had data put into it via a .NET application > > using the .NET DateTime (so a 20 byte int sounds about right IIRC), > > which is based on the number of ticks since Jan 1, 1.... I think that > > should end up around 2[18ish digits here...]... > > Mmmm ... I thought it might be the MS format that's ticks since > 1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen > 10,000,000 times per second, but: > > >>> x = 212099016004150509 > >>> seconds = x / 10000000.0 > >>> seconds > 21209901600.415051 > >>> days = seconds / 60. / 60. / 24. > >>> days > 245484.97222702604 > >>> years_approx = days / 365.25 > >>> years_approx > > 672.10122444086528 > > which would make it in the year 2272. > > Perhaps the OP could tell us what are the maximum and minimum non-zero > non-null values he can find, and what years those might belong to. > Also (very important) he might assure us that he is copying/pasting > those large numbers, not retyp[o]ing them. About .Net DateTime: the word from Mordor is "Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 1 A.D. (C.E.) in the GregorianCalendar calendar." "12:00 midnight"??? Is this 0001-01-02T00:00:00 ??? In any case, this would make the OP's bigint about 50 years after the Hegira ... plausible only if his database is rather historical. From akineko at gmail.com Wed Jan 28 18:26:08 2009 From: akineko at gmail.com (akineko) Date: Wed, 28 Jan 2009 15:26:08 -0800 (PST) Subject: Terminating a Python program that uses multi-process, multi-threading References: Message-ID: <852a731b-2ada-413e-aea2-51877c0304a0@z27g2000prd.googlegroups.com> On Jan 28, 1:11?pm, MRAB wrote: > A hacky way of killing the processes would be for the processes to write > their process IDs to the log and then you can write another script which > will parse the log to get the process IDs and then kill the processes > with those IDs. (Left as an exercise for the reader. Thank you MRAB. Your suggestion is very reasonable. I think I will do both. Try to reduce the chance of freeze-up and create a script to clean-up. Aki- From exarkun at divmod.com Wed Jan 28 18:29:08 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 18:29:08 -0500 Subject: Results of executing hyperlink in script In-Reply-To: <4980E6F3.4010702@mrabarnett.plus.com> Message-ID: <20090128232908.24460.1432709719.divmod.quotient.3449@henry.divmod.com> On Wed, 28 Jan 2009 23:14:59 +0000, MRAB wrote: >Muddy Coder wrote: >>Hi Folks, >> >>My previous post got a many helps from the people, and I tested what >>they suggested. Since this topic maybe needed in future, so I drop >>these lines below to help the future programmers. The methods worked >>as below: >> >>1. This method was suggested by Cameron Laird: >> >> os.system("start %s" % URL) >> >>It works. But, if the URL contains character &, it will fail. For >>example, if URL has only one field, such as: >>http://www.mydomain.com/ascript.cgi?user=muddy >>this method works well. But, if there more than one field need to be >>input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, >>the field password failed to reach server, and the CGI script >>complained. >You could put quotes around the URL: > >os.startfile('"%s"' % URL) > >or: > >os.system('start "%s"' % URL) > >if "&" has a special meaning to the command-line. What if the URL has a " in it? Worse, what if the URL is: " & rm -rf ~ os.system is a pretty bad thing to use. Fortunately, the suggestion to use urllib was a much better one, and you can't use os.system here anyway since the poster is interested in getting the contents of the page at the URL. Jean-Paul From google at mrabarnett.plus.com Wed Jan 28 18:32:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:32:01 +0000 Subject: file date/time on windows In-Reply-To: <4980e41a$0$9403$ba4acef3@news.orange.fr> References: <49807795$0$18360$ba4acef3@news.orange.fr> <4980e41a$0$9403$ba4acef3@news.orange.fr> Message-ID: <4980EAF1.3060203@mrabarnett.plus.com> m.banaouas wrote: > thanks, > someone gave me the solution: > simply call time.localtime(...) instead of time.gmtime(...) > > The explorer file time is what I need because it's the only file date visible > for most of users. So localtime is perfect for me. > We are talking about the same file stored in a shared lan-computer-folder. > I gess that if computers of those users are in different timezones, they could > see different file date ? > > The filetime is stored as UTC and is converted to local time only for display. (Actually, that might apply only to NTFS.) There's also the idiosyncrasy that the filetime, when converted to local time, will have 1 added to the hour during DST, irrespective of whether the filetime itself was during DST, so a file that was modified at 09:00 on 1 January will appear to have been modified at 10:00 if viewed during June, and a file that was modified at 09:00 on 1 June will appear to have been modified at 08:00 if viewed during non-DST! > MRAB a ?crit : >> m.banaouas wrote: >>> hi, >>> >>> I noticed recently that the value of file date/time I get with python: >>> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) >>> is forwarding by one hour the real file date/time. >>> >>> Example: >>> file A.txt: 2009-01-18 16:13 >>> returned valeur: 2009-01-28 15:13 >>> >>> Is there a simple way to get it work correctely (other than adding >>> always 1 >>> hour ...) ? >>> >> time.gmtime(), as the name suggests, returns GMT (UTC). >> >> From your email address I presume you're in France, which is GMT+1. >> >> Windows Explorer shows the file time in local time, which for you is >> currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. > -- > http://mail.python.org/mailman/listinfo/python-list > From google at mrabarnett.plus.com Wed Jan 28 18:37:16 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:37:16 +0000 Subject: Function Application is not Currying In-Reply-To: <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> Message-ID: <4980EC2C.1020809@mrabarnett.plus.com> sln at netherlands.com wrote: > On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee wrote: > >> Function Application is not Currying >> >> Xah Lee, 2009-01-28 >> >> In Jon Harrop's book Ocaml for Scientist at >> http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html >> >> It says: >> >> Currying >> >> A curried function is a function which returns a function as its >> result. >> > Curry, is that like chicken soup or some Indian mash? > "Currying" is named after someone called Curry. The 'correct' term is "partial parameterisation", which explains why it's often called "Currying" instead! :-) > Why ? How about returning an index number into an array of function pointers > as handlers from packet data? > > Oh, thats network communications. > From sjmachin at lexicon.net Wed Jan 28 18:46:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:46:11 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> Message-ID: <531ffa9d-ddca-43de-9c3d-90b64c784755@o40g2000prn.googlegroups.com> On Jan 29, 9:43?am, perfr... at gmail.com wrote: > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > hello all, > > > > i have a large dictionary which contains about 10 keys, each key has a > > > value which is a list containing about 1 to 5 million (small) > > > dictionaries. for example, > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > 'world'}, ...], > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > in total there are about 10 to 15 million lists if we concatenate > > > together all the values of every key in 'mydict'. mydict is a > > > structure that represents data in a very large file (about 800 > > > megabytes). > > > > what is the fastest way to pickle 'mydict' into a file? right now i am > > > experiencing a lot of difficulties with cPickle when using it like > > > this: > > > > from cPickle import pickle > > > pfile = open(my_file, 'w') > > > pickle.dump(mydict, pfile) > > > pfile.close() > > > > this creates extremely large files (~ 300 MB) though it does so > > > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > > > it gets slower and slower. it takes almost an hour if not more to > > > write this pickle object to file. > > > > is there any way to speed this up? i dont mind the large file... after > > > all the text file with the data used to make the dictionary was larger > > > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > > > i do care about speed... > > > > i have tried optimizing this by using this: > > > > s = pickle.dumps(mydict, 2) > > > pfile.write(s) > > > > but this takes just as long... any ideas ? is there a different module > > > i could use that's more suitable for large dictionaries ? > > > thank you very much. > > > Pardon me if I'm asking the "bleedin' obvious", but have you checked > > how much virtual memory this is taking up compared to how much real > > memory you have? If the slowness is due to pagefile I/O, consider > > doing "about 10" separate pickles (one for each key in your top-level > > dictionary). > > the slowness is due to CPU when i profile my program using the unix > program 'top'... i think all the work is in the file I/O. the machine > i am using several GB of ram and ram memory is not heavily taxed at > all. do you know how file I/O can be sped up? More quick silly questions: (1) How long does it take to load that 300MB pickle back into memory using: (a) cpickle.load(f) (b) f.read() ? What else is happening on the machine while you are creating the pickle? (2) How does From gagsl-py2 at yahoo.com.ar Wed Jan 28 18:55:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 21:55:51 -0200 Subject: errno 22 instead of errno 2 References: <49800EDB.3080800@g.nevcal.com> <49801F9E.1050700@timgolden.me.uk> Message-ID: En Wed, 28 Jan 2009 07:04:30 -0200, Tim Golden escribi?: > Glenn Linderman wrote: >> open("c:\abc","rb") >> This simple one-line script, produces errno 22 on Python 2.6, but >> errno 2 on Python 2.5.2 > > Just glancing quickly at the svn logs, there certainly were some > changes around that area in 2008: > > I'd question whether it's strictly a "regression", unintentional or > otherwise, since I doubt the code makes any particular commitment as > to which error code is raised, but I'd certainly be looking askance > if I had code which relied on a particular error number which then > changed! Still, that's what unit tests are for, I suppose. Even if nothing had changed on Python, one should note that the Windows API doesn't promise anything about the specific set of error codes a function might set (not that it happens every day, but MS has reserved the right to alter them). PS: and thanks for my new word of the day: "askance" -- Gabriel Genellina From gdamjan at gmail.com Wed Jan 28 18:56:22 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 29 Jan 2009 00:56:22 +0100 Subject: Reuse of DB-API 2.0 cursors for multiple queries? References: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Message-ID: <6u7756-l0m.ln1@archaeopteryx.softver.org.mk> > Today, I used the adodbapi module against an SQL Server Express > database. I was surprised to get an exception, when I attempted to > submit a second query with my cursor object. The full session is > below. >>> curs.execute('select * from localview_roles') >>> curs.execute('select * from localview_roles') have you tried to curs.fetch() or fetchall() before the second execute? -- ?????? ( http://softver.org.mk/damjan/ ) Scarlett Johansson: You always see the glass half-empty. Woody Allen: No. I see the glass half-full, but of poison. From praxbaffle at hotmail.com Wed Jan 28 18:57:36 2009 From: praxbaffle at hotmail.com (John Seales) Date: Wed, 28 Jan 2009 15:57:36 -0800 Subject: how to update python on gnu emacs? Message-ID: I've updated to python 2.6. My terminal application finds the new python just fine, but my gnu-emacs still is on python 2.3. Does anyone know how I can change that? using x86 powerbook John Seales _________________________________________________________________ Windows Live? Hotmail??more than just e-mail. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Wed Jan 28 19:05:15 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 29 Jan 2009 01:05:15 +0100 Subject: small python-cgi wiki? References: Message-ID: > I'm looking to set up a small private wiki, and am looking for > recommendations. > > Some sort of CGI based package that I could just untar somewhere web > accessable via Apache would be great. http://hatta.sheep.art.pl/About ? single file ? stores stuff in mercurial. ? it's WSGI, so yes you can run it as CGI too (wsgiref.handlers.CGIHandler) http://hatta.sheep.art.pl/Features -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of converstion. Q: Why is top posting frowned upon? From david.lyon at preisshare.net Wed Jan 28 19:12:21 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Wed, 28 Jan 2009 19:12:21 -0500 Subject: Python Package Managment In-Reply-To: <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> Message-ID: Hi, >>> People coming to Python from Perl and Ruby expect to be able to just >>> run a command to download and install a package. TRUE TRUE.... Forgive me, but I am no python specialist. But I use all the other languages as well and python isn't up to standard in this area. Perphaps 50% of all my python time, is spent searching and testing packages for what I need off peoples web sites. It is crazy... In perl it is so much easier on cpan, but i hate the language (perl)... I really propose something be done about it, but it takes a team.... In perl, it is so easy to remember "ppm" (perl package manager).. My only suggestion is that allowance be made for platform specific components, ie, windows, mac... because under windows, a lot of the tools I use are platform specific linking to the o/s. It would be desirable to seperate those out from packages that are not platform specific. On Wed, 28 Jan 2009 19:53:42 +0900, David Cournapeau wrote: > On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin > wrote: >> [extracted from pylons-discuss] >> >> >>> >> I hate to pass the buck, but this is Python's fault for not having >>> >> reliable package management built in. There's nothing Pylons can do >>> >> about it except switch to another programming language. >>> > [SNIP] >>> >>> Without Setuptools, >>> Pylons and TurboGears couldn't exist, and Zope and Twisted >>> would not have been able to split themselves into several packages. >>> People coming to Python from Perl and Ruby expect to be able to just >>> run a command to download and install a package. That problem was >>> solved ten years ago, so why does Python still not have it standard? >>> >>> If Setuptools and Virtualenv or the equivalent were built into Python, >>> you could trust that every computer that has successfully installed >>> Python can install packages and make virtual environments the same >>> way.. >>> >>> That would eliminate 2/3 of the problems users have when >>> installing Pylons, and the subsequent need to explain the problems and >>> workarounds in the installation docs. At >>> work people say, "Half the trouble of Pylons is installing it", and I >>> often have to help them install it in person because otherwise they >>> get stuck at some error message and have no idea what to do. >>> >> >> Agreed. I would even move ipython (or something like it) to core. >> >> Of course, even Setuptools has a long way to go in some areas. > (Installation Rollback, for one.) >> >> Python is about "batteries included", and these are major "batteries" in > most modern environments. >> >> A CPAN like "in-house hosted" archive would nice, too. This way, > modules have a better chance of outliving the original author's > interest/commitment in paying for, possibly non-trivial, web hosting. >> >> I'm sure these issues has been discussed to death, but I wonder what the > larger Python community thinks. > > You may be interested in the following: > > http://mail.python.org/pipermail/python-dev/2006-April/063952.html > > The thread is two years and a half old, but my impression is that the > situation has not changeed much since. Few if any people are against > improving the situation, but more people are against the currently > available solutions (setuptools, virtualenv, etc...). > > cheers, > > David > -- > http://mail.python.org/mailman/listinfo/python-list From wuwei23 at gmail.com Wed Jan 28 19:28:22 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 28 Jan 2009 16:28:22 -0800 (PST) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> On Jan 29, 7:32?am, Xah Lee wrote: > But he is really a asshole, and > take every chance to peddle his book. As opposed to really being an asshole and peddling one's website at every opportunity? From prologic at shortcircuit.net.au Wed Jan 28 19:34:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 29 Jan 2009 10:34:51 +1000 Subject: Function Application is not Currying In-Reply-To: <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> Message-ID: On Thu, Jan 29, 2009 at 10:28 AM, alex23 wrote: > On Jan 29, 7:32 am, Xah Lee wrote: >> But he is really a asshole, and >> take every chance to peddle his book. > > As opposed to really being an asshole and peddling one's website at > every opportunity? It would seem that Xah Lee suffers from a syndrome we've come to know as "I'm Mr. Big Shot look at me I know everything" --JamesMills From gagsl-py2 at yahoo.com.ar Wed Jan 28 19:39:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 22:39:40 -0200 Subject: Windows PIL installer question References: <381de027-2be2-4de4-bb39-bf170a970a5a@s20g2000yqh.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 15:07:54 -0200, cjl escribi?: > Is there any way to run the PIL installer from the command line on > Windows in 'silent' mode, without displaying the install screens or > requiring user interaction? Is it a .msi? msiexec /i filename.msi /quiet /log path\to\logfile.log -- Gabriel Genellina From carsten.haese at gmail.com Wed Jan 28 19:47:02 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 28 Jan 2009 19:47:02 -0500 Subject: Reuse of DB-API 2.0 cursors for multiple queries? In-Reply-To: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> References: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Message-ID: <807gl.2381$PE4.137@nlpi061.nbdc.sbc.com> moreati wrote: > Today, I used the adodbapi module against an SQL Server Express > database. I was surprised to get an exception, when I attempted to > submit a second query with my cursor object. The full session is > below. > > With cx_Oracle I've become used to reusing a cursor for subsequent > queries. The PEP doesn't specify either way, that I can see. The PEP doesn't say explicitly that a cursor can execute multiple queries, but it's definitely implied by the second paragraph: """ .execute(operation[,parameters]) Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified in a database-specific notation (see the module's paramstyle attribute for details). [5] A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times). """ You might want to check on a list dedicated to adodbapi whether there are module-specific quirks or caveats to watch out for. Or wait for somebody with adodbapi-specific knowledge to chime in. HTH, -- Carsten Haese http://informixdb.sourceforge.net From vincent at vincentdavis.net Wed Jan 28 20:00:36 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 28 Jan 2009 18:00:36 -0700 Subject: program organization question Message-ID: <77e831100901281700w184b9e8bne323aef1647e5548@mail.gmail.com> Basically my program simulates the Medical Residency Match, generating simulated data, running the match and then summarizing results. Currently it does this all in one document (starting conditions--Gen data--run match--summarize results). I will be running multiple simulations on different starting condition and data generation. My question is how should I organize this. My plane was to have a separate document for staring conditions, data generation because these will change for each simulation. Then on for the match a summarizing data as this will always be the same except for saving the results as different names. I don't even know how to pass data from on program to another although I think I can figure this out. Any guidance? Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From Graham.Dumpleton at gmail.com Wed Jan 28 20:10:19 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 28 Jan 2009 17:10:19 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: Message-ID: <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c@s1g2000prg.googlegroups.com> On Jan 29, 8:35?am, Ron Garret wrote: > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > whenever I restart the server after making a code change it takes a very > long time (like a minute) before the script is active again. ?In other > words, I do an apachectl restart, reload the page in my browser, and one > minute later it finally comes up. ?During this time CPU usage is > essentially zero. ?Loading all the code manually into a python > interpreter is virtually instantaneous, and all subsequence interactions > with the app are very fast. > > Does anyone have any ideas what might be going on or how to debug this? The better place to discuss this is the mod_wsgi list. http://groups.google.com/group/modwsgi?hl=en As to the problem, you need to distinguish between whether it is Apache that is taking a long time to restart and ready to handle requests, or whether the delay is on the first subsequent request made against your WSGI application. When Apache restarts, it doesn't by default load your WSGI application, it only does that the first time a request comes in directed at it. Thus, if after you restart Apache you do a request of a static file, do you get a response straight away? If it doesn't respond straight away, then it is an issue with Apache restart and not mod_wsgi as your WSGI application wouldn't be involved. If the static file request is fine and only first request to WSGI application is slow, then likely that problem is to do with the startup cost of loading your WSGI application and initialising it upon first request. As you don't say what Python web framework/application you are using, hard to say what the issue may be there. If it is an Apache issue and not mod_wsgi, as pointed out already, could be that you have Apache setup to do reverse DNS lookups on client IP address and that isn't working properly. This often happens for Windows people. So, narrow down where problem is occurring. Graham From rNOSPAMon at flownet.com Wed Jan 28 20:11:52 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 17:11:52 -0800 Subject: Sloooooowwwww WSGI restart References: Message-ID: In article , Aleksandar Radulovic wrote: > Hi there, > > On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > > Off the bat, there's no reason to run an app under apache/mod_wsgi > while developing it, > ie. if u use Pylons or TurboGears, there's an easier way to serve the > app (using paster > or cherrypy). Yes, I know. I guess I'm just a masochist. But this would be an issue in production as well. I don't want to have to go down for a minute every time I push a new release. > Secondly, why are you restarting apache after code changes? In normal > circumstances, you shouldn't have to do that. I thought (and experiment confirms) that only the main WSGI app file gets reloaded automatically when it changes, not the libraries. rg From rNOSPAMon at flownet.com Wed Jan 28 20:12:19 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 17:12:19 -0800 Subject: Sloooooowwwww WSGI restart References: Message-ID: In article , Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret wrote: > >I'm running a WSGI app under apache/mod_wsgi and I've noticed that > >whenever I restart the server after making a code change it takes a very > >long time (like a minute) before the script is active again. In other > >words, I do an apachectl restart, reload the page in my browser, and one > >minute later it finally comes up. During this time CPU usage is > >essentially zero. Loading all the code manually into a python > >interpreter is virtually instantaneous, and all subsequence interactions > >with the app are very fast. > > > >Does anyone have any ideas what might be going on or how to debug this? > > strace is nice. It sounds like some blocking network operation. rdns can > often cause things like this. If you're lucky, strace will point right at > the problem. > > Jean-Paul That's a good idea. Thanks! rg From Graham.Dumpleton at gmail.com Wed Jan 28 20:16:19 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 28 Jan 2009 17:16:19 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: Message-ID: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> On Jan 29, 8:44?am, Aleksandar Radulovic wrote: > Hi there, > > On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > > Off the bat, there's no reason to run an app under apache/mod_wsgi > while developing it, > ie. if u use Pylons or TurboGears, there's an easier way to serve the > app (using paster > or cherrypy). > > Secondly, why are you restarting apache after code changes? In normal > circumstances, > you shouldn't have to do that. Sorry, you are wrong to assume that an Apache restart is not be required. If you are using mod_wsgi embedded mode, or mod_python, then a code change will always require a full restart of Apache. If you are using mod_wsgi daemon mode, you need to at least touch the WSGI script file for an automatic restart of that specific application to occur. Changes to arbitrary Python code files are not detected. If using mod_wsgi daemon mode, you can also set up a separate background thread to monitor for arbitrary code changes as described for Django in: http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html That page references original documentation on mod_wsgi wiki for bulk of information. Thus, the conjecture that Apache/mod_wsgi cannot be used and that CherryPy WSGI server or Paster server must be used when developing a Python web application is false. If using mod_wsgi then daemon mode would of course be preferred though, with touching the WSGI script file being safest option to ensure updates across multiple files picked up at same time, but if you really want completely automated restarts, use the recipe in mod_wsgi documentation. Graham From juvy.jumalon at gmail.com Wed Jan 28 20:44:12 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Thu, 29 Jan 2009 09:44:12 +0800 Subject: need help In-Reply-To: References: Message-ID: Hi Steve, Thanks for you reply. I am newbie in python. Im going to use HTTP. thanks a lot On Wed, Jan 28, 2009 at 9:40 PM, Steve Holden wrote: > juvy j wrote: > > Hi guys, > > > > need help on how to read file from other server(linux). > > > Which service do you plan to use: FTP, HTTP and NFS are three > possibilities that immediately come to mind, all well handled by {ython > standard library modules. A little more background might help. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kkylheku at gmail.com Wed Jan 28 20:49:25 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Thu, 29 Jan 2009 01:49:25 +0000 (UTC) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <20090203171740.143@gmail.com> On 2009-01-28, Xah Lee wrote: > Function Application is not Currying That's correct, Xah. Currying is a special case of function application. A currying function is applied to some other function, and returns function that has fewer arguments. In some languages, you don't see the currying function. It's invisibly performed whenever you forget an argument. Hit a three argument function with only two arguments, and you don't get a nice ``insufficient arguments in function call'' error, but the call is diverted to the currying function, which gives you back a function of one argument, which you can then call with the missing argument to compute the original function. > Xah Lee, 2009-01-28 > > In Jon Harrop's book Ocaml for Scientist at > http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html Figures you'd be reading this. Learning anything? > It says: > > Currying > > A curried function is a function which returns a function as its > result. > > LOL. That is incorrect. Yawn. Say it isn't so. From claird at lairds.us Wed Jan 28 21:02:22 2009 From: claird at lairds.us (Cameron Laird) Date: Thu, 29 Jan 2009 02:02:22 +0000 Subject: Results of executing hyperlink in script References: Message-ID: In article , MRAB wrote: >Muddy Coder wrote: . . . >You could put quotes around the URL: > >os.startfile('"%s"' % URL) > >or: > >os.system('start "%s"' % URL) > >if "&" has a special meaning to the command-line. In fact, no, happiness does NOT result in these contexts with another layer of quoting. os.startfile(URL) works fine even if URL embeds special characters, and does not work at all if URL is itself quoted. os.system("start ...") just gives a variety of unuseful results if URL embeds special characters. From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:11:33 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:11:33 -0200 Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 14:13:10 -0200, escribi?: > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > 'world'}, ...], > key2: [...]} > > [pickle] creates extremely large files (~ 300 MB) though it does so > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > it gets slower and slower. it takes almost an hour if not more to > write this pickle object to file. There is an undocumented Pickler attribute, "fast". Usually, when the same object is referenced more than once, only the first appearance is stored in the pickled stream; later references just point to the original. This requires the Pickler instance to remember every object pickled so far -- setting the "fast" attribute to a true value bypasses this check. Before using this, you must be positively sure that your objects don't contain circular references -- else pickling will never finish. py> from cPickle import Pickler py> from cStringIO import StringIO py> s = StringIO() py> p = Pickler(s, -1) py> p.fast = 1 py> x = [1,2,3] py> y = [x, x, x] py> y [[1, 2, 3], [1, 2, 3], [1, 2, 3]] py> y[0] is y[1] True py> p.dump(y) py> s.getvalue() '\x80\x02](](K\x01K\x02K\x03e](K\x01K\x02K\x03e](K\x01K\x02K\x03ee.' Note that, when unpickling, shared references are broken: py> s.seek(0,0) py> from cPickle import load py> y2 = load(s) py> y2 [[1, 2, 3], [1, 2, 3], [1, 2, 3]] py> y2[0] is y2[1] False -- Gabriel Genellina From notvalid2 at sbcglobal.net Wed Jan 28 21:13:53 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 18:13:53 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: Peter Otten wrote: > W. eWatson wrote: > >> r wrote: >>> Change this line: >>> draw.line((0,0),(20,140), fill=128) >>> >>> To This: >>> draw.line((0,0, 20,140), fill=128) >>> >>> And you should be good to go. Like you said, if you need to combine 2 >>> tuples you can do: >>> (1,2)+(3,4) >> Yes, that's true, but the big question is how to "see" the final image? >> Either one employees another module or writes the file into a folder, then >> displays it with a paint program? > > For debugging purposes you can just invoke the show() method > > im = Image.open(...) > # modify image > im.show() > > If you want to integrate the image into your own Tkinter program -- that is > explained here: > > http://effbot.org/tkinterbook/photoimage.htm > > Following these instruction you code might become > > import Tkinter as tk > import Image > import ImageTk > import ImageDraw > import sys > > filename = sys.argv[1] > im = Image.open(filename) > > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line(((0,0),(20,140)), fill=128) > > > root = tk.Tk() > pi = ImageTk.PhotoImage(im) > label = tk.Label(root, image=pi) > label.pack() > root.mainloop() > > Peter My initial quest was to do it in PIL. That seems impossible, and the way out is Tkinter. I'm not yet savvy enough with Pythons graphics. I was definitely leaning towards PhotoImage as the way out. What module is show in? Repairing my (0,0), ... to (0,0)+, and. replacing arg with ImageOPen, produces a correct solution. My NM Tech pdf misses the boat on PhotoImage. I've seen your reference before, but never looked at PhotoImage. I'll bookmark it. I sure wish it was in pdf format. Thanks. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:29:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:29:29 -0200 Subject: Quickbooks References: <4980A229.1040606@offenbachers.com> Message-ID: En Wed, 28 Jan 2009 16:21:29 -0200, Stephen Chapman escribi?: > Has anyone Implemented the Quickbooks COM object in Python. If so can > you give me > an Idea of where to begin. You'll want the pywin32 package by Mark Hammond -available from sourceforge-. It provides the infrastructure required to manipulate any COM object from Python. M. H. coauthored the book "Python Programming On Win32"; the sample chapter available at Amazon is precisely "Introduction to COM". -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:38:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:38:18 -0200 Subject: date handling problem References: Message-ID: En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva escribi?: > I need to parse rss-feeds based on time stamp,But rss-feeds follow > different > standards of date(IST,EST etc). > I dont know,how to standardize this standards.It will be helpful if you > can > hint me. You may find the Olson timezone database useful. http://pytz.sourceforge.net/ -- Gabriel Genellina From rNOSPAMon at flownet.com Wed Jan 28 21:52:34 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 18:52:34 -0800 Subject: Sloooooowwwww WSGI restart References: <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c@s1g2000prg.googlegroups.com> Message-ID: In article <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c at s1g2000prg.googlegroups.com>, Graham Dumpleton wrote: > On Jan 29, 8:35?am, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > > whenever I restart the server after making a code change it takes a very > > long time (like a minute) before the script is active again. ?In other > > words, I do an apachectl restart, reload the page in my browser, and one > > minute later it finally comes up. ?During this time CPU usage is > > essentially zero. ?Loading all the code manually into a python > > interpreter is virtually instantaneous, and all subsequence interactions > > with the app are very fast. > > > > Does anyone have any ideas what might be going on or how to debug this? > > The better place to discuss this is the mod_wsgi list. > > http://groups.google.com/group/modwsgi?hl=en The reason I don't go there is that I'm using an NNTP client. I find Google Groups' web interface to be very annoying because there's no way to keep track of read messages. > As to the problem, you need to distinguish between whether it is > Apache that is taking a long time to restart and ready to handle > requests, or whether the delay is on the first subsequent request made > against your WSGI application. > > When Apache restarts, it doesn't by default load your WSGI > application, it only does that the first time a request comes in > directed at it. Thus, if after you restart Apache you do a request of > a static file, do you get a response straight away? I thought I did, but having poked at it more I now realize that I was just getting a cached page. It does appear to be an apache issue, not a WSGI issue. Sorry for the false alarm. rg From rocky at panix.com Wed Jan 28 21:54:14 2009 From: rocky at panix.com (R. Bernstein) Date: Wed, 28 Jan 2009 21:54:14 -0500 Subject: How to get atexit hooks to run in the presence of execv? Message-ID: As a hobby I've been (re)writing a debugger. One of the commands, "restart", works by calling an execv(). You may need to do this when the program you are debugging is threaded or when one needs to ensure that all program state is reinitialized. Recently, I added remote debugging via TCP sockets. (Well, also FIFO's as well but closing sockets before restarting is what's of concern.) I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get called. Should it? Furthermore, I don't seen any atexit routine that would let me initiate such finalization. Should there be one? Or perhaps I'm missing something. Is there a way to arrange atexit hooks to get run before issuing an execv-like call? Thanks. From gagsl-py2 at yahoo.com.ar Wed Jan 28 22:00:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 01:00:25 -0200 Subject: Results of executing hyperlink in script References: Message-ID: En Wed, 28 Jan 2009 20:49:14 -0200, Muddy Coder escribi?: > My previous post got a many helps from the people, and I tested what > they suggested. Since this topic maybe needed in future, so I drop > these lines below to help the future programmers. The methods worked > as below: > > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For > 2. The best way is to use urllib2, suggested by Ron Barak, my code is > below: > > import urllib2 > source = urllib2.urlopen(URL).read() > print source Note that both methods are essencially different. The first one opens a browser window, and it's up to the user what to do after the initial request is done -- if this is what you want, the webbrowser module is better suited for that task. The second one is a pure programming interfase - the Python script is in control, and the user isn't involved at all. -- Gabriel Genellina From n.kottiyath at gmail.com Wed Jan 28 22:07:31 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Wed, 28 Jan 2009 19:07:31 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: On Jan 29, 1:51?am, Rob Williscroft wrote: > Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 > @b38g2000prf.googlegroups.com in comp.lang.python: > > > > > I have mingw32-gcc in my path. If I try that too -it fails. > > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > > "mingw32-gcc" > > invalid command name 'mingw32-gcc' > > All the examples I found via google have the tool name as "mingw32" > so try: > > ? ? ? ? python setup.py install -c mingw32 > > or > > ? ? ? ? python setup.py build --compiler=mingw32 install > > The compiler that the MinGW package installs is gcc. > > You shoulf be able to verify it is on your path by typing: > > ? ? ? ? gcc --help > or > ? ? ? ? gcc --version > > and see some output. > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Thank you Rob. The installation went ahead for some more time - but failed showing a lot of errors: >compile running build running build_py file pyAAc.py (for module pyAAc) not found file pyAAc.py (for module pyAAc) not found ... pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in this scope pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared in this scope pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not declared in this scope ... error: command 'gcc' failed with exit status 1 I cannot understand why it fails. I have not worked in C till now, so I am pretty confused. I googled also, but to no avail. From python.list at tim.thechases.com Wed Jan 28 22:08:13 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 21:08:13 -0600 Subject: need help In-Reply-To: References: Message-ID: <49811D9D.3000805@tim.thechases.com> > Thanks for you reply. I am newbie in python. > Im going to use HTTP. If all you want is to download a file, you might want to look into using "wget" or "curl" (which work for both HTTP and FTP). E.g. bash$ wget http://myothermachine/path/to/file.html However, if you need to roll it into a script, Python's urllib module will do the trick >>> import urllib >>> url = "http://myothermachine/path/to/file.html" >>> f = urlib.urlopen(url) >>> out = file('python.txt', 'w') >>> for line in f: out.write(line) ... >>> out.close() >>> f.close() If the content is small, you can just use >>> content = f.read() >>> out.write(content) instead of the "for line in f: out.write(line)". If you need to actually parse the HTML that's returned, the common suggestion is to use the BeautifulSoup add-on module which has worked for my needs. -tkc From python.list at tim.thechases.com Wed Jan 28 22:11:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 21:11:12 -0600 Subject: Results of executing hyperlink in script In-Reply-To: References: Message-ID: <49811E50.7010809@tim.thechases.com> > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For As an aside, the START command is a bit picky regarding quotes. You have to use this horrible contortion os.system('start "title" "%s"' % URL) The "title" is optional content-wise, but required positionally if there's a quoted resource, so you can just use start "" "%s" a pain, but that's CMD.EXE for you. :) -tkc From Russ.Paielli at gmail.com Wed Jan 28 22:14:02 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 28 Jan 2009 19:14:02 -0800 (PST) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <5d34610d-5a70-4851-8e24-6a86230edaaf@n33g2000pri.googlegroups.com> On Jan 28, 1:32?pm, Xah Lee wrote: > Function Application is not Currying > > Xah Lee, 2009-01-28 > > In Jon Harrop's book Ocaml for Scientist athttp://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > > It says: > > ? ? Currying > > ? ? A curried function is a function which returns a function as its > result. > > LOL. That is incorrect. What does that have to do with the price of bananas in Costa Rica? From tim at burlyhost.com Wed Jan 28 22:31:07 2009 From: tim at burlyhost.com (Tim Greer) Date: Wed, 28 Jan 2009 19:31:07 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <5d34610d-5a70-4851-8e24-6a86230edaaf@n33g2000pri.googlegroups.com> Message-ID: <0q9gl.109224$zJ2.519@newsfe23.iad> Russ P. wrote: > On Jan 28, 1:32?pm, Xah Lee wrote: >> Function Application is not Currying >> >> Xah Lee, 2009-01-28 >> >> In Jon Harrop's book Ocaml for Scientist >> athttp://www......./chapter1.html >> >> It says: >> >> Currying >> >> A curried function is a function which returns a function as its >> result. >> >> LOL. That is incorrect. > > What does that have to do with the price of bananas in Costa Rica? Xah Lee does this stuff in 4 or 5 groups he's decided to post random things to. They rarely have any relevance or substance, just his personal thoughts. He liked to provoke arguing and tell everyone he's a genius in his own mind. It's best to just filter his posts out like most of us have already done. I don't know what group you're seeing his post in, but he bugs us in the Perl group all the time, cross posting things that have nothing to do with Perl (same with his cross posts to Python, too). :-) -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From juvy.jumalon at gmail.com Wed Jan 28 22:52:01 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Thu, 29 Jan 2009 11:52:01 +0800 Subject: need help In-Reply-To: <49811D9D.3000805@tim.thechases.com> References: <49811D9D.3000805@tim.thechases.com> Message-ID: Hi tkc, Thanks so much.. it works! :-) I used the urllib. and thanks also to everybody who replied. jtj On Thu, Jan 29, 2009 at 11:08 AM, Tim Chase wrote: > Thanks for you reply. I am newbie in python. >> Im going to use HTTP. >> > > If all you want is to download a file, you might want to look into using > "wget" or "curl" (which work for both HTTP and FTP). E.g. > > bash$ wget http://myothermachine/path/to/file.html > > However, if you need to roll it into a script, Python's urllib module will > do the trick > > >>> import urllib > >>> url = "http://myothermachine/path/to/file.html" > >>> f = urlib.urlopen(url) > >>> out = file('python.txt', 'w') > >>> for line in f: out.write(line) > ... > >>> out.close() > >>> f.close() > > If the content is small, you can just use > > >>> content = f.read() > >>> out.write(content) > > instead of the "for line in f: out.write(line)". If you need to actually > parse the HTML that's returned, the common suggestion is to use the > BeautifulSoup add-on module which has worked for my needs. > > -tkc > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 28 23:12:07 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 29 Jan 2009 04:12:07 -0000 Subject: Exec woes In-Reply-To: <015d01c9811c$c6042e80$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> <015d01c9811c$c6042e80$0d00a8c0@hendrik> Message-ID: On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen wrote: > Stephen Hansen wrote: > >> Exec is a statement, not a function nor an object: even though you can >> enclose parens around its arguments like you do later on, they >> don't have any syntax meaning > > This is actually not correct - it is the root cause of my trouble. > if you write, in a nested scope: > > exec ( "somestring to execute" in globals(),locals()) > > You get the syntax error, as the interpreter somehow sees it as one, > unqualified thing. Well, no. Look at the error Python gives you, nested scope or not: Traceback (most recent call last): File "", line 1, in TypeError: exec: arg 1 must be a string, file, or code object If exec is a function, arg 1 is the boolean expression "somestring to execute" in globals() which is unlikely to be what you want. If exec is a statement, arg 1 is a tuple of two elements, "somestring to execute" in globals() and locals() which is also unlikely to be what you want. Neither of these are giving you a string, file or code object, exactly as the interpreter is telling you. -- Rhodri James *-* Wildebeeste Herder to the Masses From notvalid2 at sbcglobal.net Wed Jan 28 23:12:24 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:12:24 -0800 Subject: Tkinter w.pack()? Message-ID: Where in the world is a description of pack() for Tkinter widgets? Is it some sort of general method for all widgets? I'm looking in a few docs that use it without ever saying where it is described. For one, . In the NM Tech pdf on Tkinter, it's not found anywhere. I see Universal methods for widgets, but no mention of pack(). package, packed, but no pack. While I'm at it, what is w in the result of w = Label(parent, image=photo)? Just a widget pointer, address? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From rt8396 at gmail.com Wed Jan 28 23:28:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 20:28:25 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: On Jan 28, 10:12?pm, "W. eWatson" wrote: > Where in the world is a description of pack() for Tkinter widgets? Is it > some sort of general method for all widgets? I'm looking in a few docs that > use it without ever saying where it is described. For one, > . In the NM Tech pdf on Tkinter, > it's not found anywhere. I see Universal methods for widgets, but no mention > of pack(). package, packed, but no pack. did you try here :) http://effbot.org/tkinterbook/pack.htm From rt8396 at gmail.com Wed Jan 28 23:33:23 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 20:33:23 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: To expand on this there exists three geometry mangers [grid, pack, place]. I personally use pack() the most, grid() almost never, and place -- well never. But each one has it's strengths and weaknesses. w.grid() http://effbot.org/tkinterbook/grid.htm w.place() http://effbot.org/tkinterbook/place.htm Everything you need to know about Tkinter exists here: http://effbot.org/tkinterbook/ and at the NMT site i showed you before From steven at REMOVE.THIS.cybersource.com.au Wed Jan 28 23:44:32 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Jan 2009 04:44:32 GMT Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: On Wed, 28 Jan 2009 15:20:41 -0800, ocschwar wrote: > On Jan 28, 4:50?pm, Aaron Brady wrote: >> On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: >> >> Hello, quoting myself from another thread today: >> >> There is the 'shelve' module. ?You could create a shelf that tells you >> the filename of the 5 other ones. ?A million keys should be no problem, >> I guess. ?(It's standard library.) ?All your keys have to be strings, >> though, and all your values have to be pickleable. ?If that's a >> problem, yes you will need ZODB or Django (I understand), or another >> relational DB. >> >> There is currently no way to store live objects. > > > The problem is NOT archiving these objects. That works fine. > > It's the computations I'm using these thigns for that are slow, and that > failed to speed up using __slots__. You've profiled and discovered that the computations are slow, not the archiving? What parts of the computations are slow? > What I need is something that will speed up getattr() or its equivalent, > and to a lesser degree setattr() or its equivalent. As you've found, __slots__ is not that thing. >>> class Slotted(object): ... __slots__ = 'a' ... a = 1 ... >>> class Unslotted(object): ... a = 1 ... >>> t1 = Timer('x.a', 'from __main__ import Slotted; x = Slotted()') >>> t2 = Timer('x.a', 'from __main__ import Unslotted; x = Unslotted()') >>> >>> min(t1.repeat(10)) 0.1138761043548584 >>> min(t2.repeat(10)) 0.11414718627929688 One micro-optimization you can do is something like this: for i in xrange(1000000): obj.y = obj.x + 3*obj.x**2 obj.x = obj.y - obj.x # 12 name lookups per iteration Becomes: y = None x = obj.x try: for i in xrange(1000000): y = x + 3*x**2 x = y - x # 6 name lookups per iteration finally: obj.y = y obj.x = x Unless you've profiled and has evidence that the bottleneck is attribute access, my bet is that the problem is some other aspect of the computation. In general, your intuition about what's fast and what's slow in Python will be misleading if you're used to other languages. E.g. in C comparisons are fast and moving data is slow, but in Python comparisons are slow and moving data is fast. -- Steven From notvalid2 at sbcglobal.net Wed Jan 28 23:55:13 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:55:13 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > On Jan 28, 10:12 pm, "W. eWatson" wrote: >> Where in the world is a description of pack() for Tkinter widgets? Is it >> some sort of general method for all widgets? I'm looking in a few docs that >> use it without ever saying where it is described. For one, >> . In the NM Tech pdf on Tkinter, >> it's not found anywhere. I see Universal methods for widgets, but no mention >> of pack(). package, packed, but no pack. > > did you try here :) > http://effbot.org/tkinterbook/pack.htm Thanks. I have the site bookmarked, but it's hard to search. I posted a comment to them that they should have it in pdf form. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Jan 28 23:57:04 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:57:04 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > To expand on this there exists three geometry mangers [grid, pack, > place]. I personally use pack() the most, grid() almost never, and > place -- well never. But each one has it's strengths and weaknesses. > > w.grid() > http://effbot.org/tkinterbook/grid.htm > > w.place() > http://effbot.org/tkinterbook/place.htm > > There seems to be a pattern here. :-) > Everything you need to know about Tkinter exists here: > http://effbot.org/tkinterbook/ > > and at the NMT site i showed you before The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Thu Jan 29 00:23:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 03:23:56 -0200 Subject: Tkinter w.pack()? References: Message-ID: En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson escribi?: > The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? There is a PDF version of "An Introduction to Tkinter" here: http://www.pythonware.com/library/ -- Gabriel Genellina From rt8396 at gmail.com Thu Jan 29 00:31:01 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 21:31:01 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: On Jan 28, 10:57?pm, "W. eWatson" wrote: > The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? Only the grid manager is discussed at NMT. I just like how at NMT the widget attributes are in a table and then a list the widget methods follows below that -- much better navigation. I talked again to John at NMT and he assured me very soon he's going to make all the updates. It would probably help if you sent him a nice message of encouragement like -- 'Can you please update the documentation, i really like the sites layout?' -- but please don't forget to thank him for all his contributions to the Python community. I am currently crusading to have all the old Python tuts and documentation updated(among other crusades). This was my second win and i hope that more will follow. The python docs out there need a dusting off and spit shining. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 00:41:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Jan 2009 05:41:40 GMT Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Wed, 28 Jan 2009 11:06:21 -0800, Reckoner wrote: > thanks for your reply. > > For the second case where > >> class TaintThing(object): >> parent = A >> def __init__(self, obj): >> self.__dict__['_proxy'] = obj >> def __getattr__(self, attr): >> return getattr(self._proxy, attr) >> def __setattr__(self, attr, value): >> setattr(self._proxy, attr, value) >> self.parent.taint() > > you have told it that parent is 'A'. Shouldn't that be passed to it > somehow in the following: > >> # untested >> class TaintList(list): >> def append(self, obj): >> list.append(self, TaintThing(obj)) >> # similar for __setitem__, extend, insert Sure. Just change the initialisation of TaintThing to something like this: #untested def __init__(self, obj, parent): self.__dict__['_proxy'] = obj self.parent = parent and then TaintList to something like this: def append(self, obj): list.append(self, TaintThing(obj, self)) # similar for __setitem__, extend, insert -- Steven From jjposner at snet.net Thu Jan 29 00:42:36 2009 From: jjposner at snet.net (John Posner) Date: Thu, 29 Jan 2009 00:42:36 -0500 Subject: Tkinter w.pack()? Message-ID: <6C708034172C458696E52D9AF64BBB99@AMDUP> The difference between the fill=, expand=, and anchor= options to the pack() function takes a while to get used to. In brief: * fill= controls the size of a control itself * expand= controls the size of the space into which the pack() function places a control * anchor= comes into play if the size of the space exceeds the size of the control This Google Doc might be helpful: http://docs.google.com/Doc?id=dhmzfrmj_0c685rrdb It shows the effects of progressively adding various fill= and expand= clause within three statements that create and place Button controls. -John E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11640 http://www.pctools.com/en/spyware-doctor-antivirus/ From pdorange at pas-de-pub-merci.mac.com Thu Jan 29 00:52:48 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Thu, 29 Jan 2009 06:52:48 +0100 Subject: Profiling Python Apps on Mac? References: Message-ID: <1iualmh.11cquv31b8stniN%pdorange@pas-de-pub-merci.mac.com> RGK wrote: > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed > xml object I just created horribly bloated or kind of ordinary. python -m profile yourscript.py see -- Pierre-Alain Dorange MicroWar 2.0 : tuez des PC From mail at microcorp.co.za Thu Jan 29 01:06:31 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 08:06:31 +0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: <01d401c981f5$e5e301c0$0d00a8c0@hendrik> "Gabriel Genellina" wrote: >> Seems that it is important *when* those functions are evaluated, but I >> don't understand *why*... Because the scope changes - see also the recent thread on exec woes where towards the end I put in a similar example - funny, it must the flux or something - seems to be the season for calling id on locals() :-) - Hendrik From cournape at gmail.com Thu Jan 29 01:11:26 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 29 Jan 2009 15:11:26 +0900 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: <5b8d13220901282211v7b680d2en95f33119fb1eb39e@mail.gmail.com> On Thu, Jan 29, 2009 at 4:14 AM, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed xml > object I just created horribly bloated or kind of ordinary. > > Is there anything out there I should look into to if I want to see how those > things are affecting my app? The closest I have is the widget iStat, but > it's a very static low resolution view of what's really going on. On Mac OS X, dtrace can sometimes be quite useful. The Apple-provided python has the necessary 'probes'. http://blogs.sun.com/binujp/entry/dtrace_provider_for_python There are some useful scripts in the dtrace toolkit geared toward python: http://www.brendangregg.com/dtrace.html#DTraceToolkit If you want dtrace support for a bare python (built from sources), I made a quick patch, "documented" here: http://cournape.wordpress.com/?s=dtrace I don't know if it works for 2.6 (I doubt it would work out of the box - I don't claim any understanding of dtrace internals, I just applied the apple patches, removing all the apple specifics I did not care about). David From misterwang at gmail.com Thu Jan 29 01:17:01 2009 From: misterwang at gmail.com (Peter Wang) Date: Wed, 28 Jan 2009 22:17:01 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> On Jan 27, 3:16?pm, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. You should really look at Enthought's Traits package. It does exactly what you are asking for, and much, much more. See: http://code.enthought.com/projects/traits/documentation.php http://code.enthought.com/projects/traits/examples.php Using Traits, you could do the following: from enthought.traits.api import * class Child(HasTraits): state = Enum("happy", "sad", "bawling") class Parent(HasTraits): child = Instance(Child) @on_trait_change('child.state') def handler(self): print "new child state:", self.child.state bob_jr = Child() bob = Parent(child = bob_jr) bob_jr.state = "sad" # This would result in bob.handler() being called (Disclosure: I work at Enthought and have been using Traits heavily for the last 4+ years.) -Peter From michele.simionato at gmail.com Thu Jan 29 01:17:12 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> Message-ID: <917c70b6-e7d3-4b2e-855d-829cdd03ff01@s36g2000vbp.googlegroups.com> On Jan 29, 12:23?am, ocsch... at gmail.com wrote: > I just find it odd that there's no quick answer on the > fastest way in Python to implement a mapping in this context. A Python dict is as fast as you can get. If that is not enough, your only choice is to try something at the C level, which may give the desired speedup or not. Good luck! Michele Simionato From asmodai at in-nomine.org Thu Jan 29 01:31:54 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Thu, 29 Jan 2009 07:31:54 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> Message-ID: <20090129063154.GS99614@nexus.in-nomine.org> -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: >If that's correct, it would be great if there were a Werkzeug tutorial >on deploying it for use with CGI. There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look in the servers directory in the repository. I'll double check the documentation and expand where necessary. [1] http://zine.pocoo.org/ -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From robert.kern at gmail.com Thu Jan 29 01:47:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jan 2009 00:47:46 -0600 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: On 2009-01-28 13:14, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed > xml object I just created horribly bloated or kind of ordinary. > > Is there anything out there I should look into to if I want to see how > those things are affecting my app? The closest I have is the widget > iStat, but it's a very static low resolution view of what's really going > on. I have a script kernprof.py which provides a few conveniences over the builtin cProfile module. One of its modes of operation is to inject a decorator into the __builtins__. It will enable the profiler on entry to the method and disable it on exit. This lets you localize your profile results to just the part of your code that you are interested in. I found this especially useful in GUI apps which require user interaction to trigger the part of the code you are actually interesting in profiling. You don't want the interesting parts of your profile to be obscured by the GUI event loop waiting for your input. You can get it as part of my line_profiler package (which you may also be interested in; cProfile profiles function calls, line_profiler profiles individual lines). http://pypi.python.org/pypi/line_profiler You can view the profile results interactively with "python -m pstats my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install kcachegrind on your system: http://www.vrplumber.com/programming/runsnakerun/ http://pypi.python.org/pypi/pyprof2calltree/1.1.0 I don't recommend using hotshot because it is deprecated and slow to postprocess the data dumps. Also, I don't recommend using the plain profile module because it slows down your program rather more than cProfile. See the Python documentation for an overview of these modules: http://docs.python.org/library/profile -- 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 tino at wildenhain.de Thu Jan 29 01:59:58 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 29 Jan 2009 07:59:58 +0100 Subject: Results of executing hyperlink in script In-Reply-To: <49811E50.7010809@tim.thechases.com> References: <49811E50.7010809@tim.thechases.com> Message-ID: <498153EE.6040600@wildenhain.de> Tim Chase wrote: >> 1. This method was suggested by Cameron Laird: >> >> os.system("start %s" % URL) >> >> It works. But, if the URL contains character &, it will fail. For > > > As an aside, the START command is a bit picky regarding quotes. You have > to use this horrible contortion > > os.system('start "title" "%s"' % URL) > > The "title" is optional content-wise, but required positionally if > there's a quoted resource, so you can just use > > start "" "%s" > > a pain, but that's CMD.EXE for you. :) ah, and just for the records, at least os.popen2,os.popen3 support tuple as argument: i,o=os.popen2((cmd,arg1,arg2)) and quotes them correctly. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mail at microcorp.co.za Thu Jan 29 02:14:41 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 09:14:41 +0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> "Gabriel Genellina" wrote: En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels > escribi?: > >> The reason is that once your created object has its id taken, you >> must keep a handle on it, otherwise it may get recycled and reused. > >It doesn't matter in this case, I think. globals() is always the same >object and is alive during the whole test. So something having the same >id() than globals() must be the very same object, and something having a >different id() than globals() cannot be the same object. > >If you like, I can rewrite the example without using id(): > >>>> L = list(n for n in [globals(),locals()]) >>>> L[0] is L[1] >True >>>> L = list(n() for n in [globals,locals]) >>>> L[0] is L[1] >False > >(I *think* this has to do with free variables in the "right side" (after >the "in" keyword) of a generator expression; they appear to be evaluated >when the expression is *defined*, not when is is *used*. By contrast, free >variables in the "left side" appear to be evaluated when the expression is >used.) > Yikes! this is, IMO, far too complicated a way of looking at it. I think that if you rewrite the "comprehensions" as loops, you will see what is happening. - in the one case, the locals() returned is from the outer scope, while in the other the locals function is called from inside the loop - a different scope, because there must be *somewhere* where the state is kept to yield the next value. If you nest the thing inside something else, then globals() and locals() won't be the same, but the two locals() will still differ. I find it very confusing because locals is always the same function - but what it returns varies depending on where you call it from. So if you want to pass it around, it's no good passing the function - you have to pass the returned result, *called from the scope of interest*. Subtle stuff. - Hendrik From afriere at yahoo.co.uk Thu Jan 29 02:15:23 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) Subject: I'm a python addict ! References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <8d075393-ba38-4f9e-b1ca-98c642b414a6@r10g2000prf.googlegroups.com> On Jan 27, 4:52?am, Paul McGuire wrote: [snip] > > ? ? # how you have to do it in C++ and Java > ? ? # light = light.next_state() > > ? ? # using Python > ? ? light.__class__ = light.next_state I'm sure you can, but why poke yourself in the eye with a blunt stick? ;) IMO there are two obvious problems with the latter approach. Firstly the information about the next state is left lying about in some namespace separate from the object, whereas the object itself ought to know what it's 'next_state' is (or, more correctly, how to determine it). Secondly you miss the opportunity of sending a signal to the new state. Consider that in some jurisdictions the amber light shows before the green as well as before the red (yeah, I know is that an invitation for drag racing or what!?). If you called next_state as a verb you could pass the current state as an argument and the amber (or yellow, if you prefer) light could work which of the two possible next states to call in turn. The fact that this behaviour is, in this example, peculiar to the amber light, demonstrates the pertinence of my first objection above. Fortunately the "C++ and Java" approach, (though I would never want to be seen advocating the C++ or Java approach to anything), is in this case available in Python as well, at the cheaper price of fewer characters and arguably greater readibility to boot. I know, Iknow ... you wanted to show how that code could be used in a non "sulphurous" way. Which just goes to show that the devil makes work for idle hands ... or foils the best laid plans ... or is in the detail ... or something sulphurous. :) From mail at microcorp.co.za Thu Jan 29 03:15:57 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 10:15:57 +0200 Subject: Exec woes References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik><7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com><015d01c9811c$c6042e80$0d00a8c0@hendrik> Message-ID: <01d601c981f5$e721ea60$0d00a8c0@hendrik> "Rhodri James" wrote: To: Sent: Thursday, January 29, 2009 6:12 AM Subject: Re: Exec woes > On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen > wrote: > > This is actually not correct - it is the root cause of my trouble. > > if you write, in a nested scope: > > > > exec ( "somestring to execute" in globals(),locals()) > > > > You get the syntax error, as the interpreter somehow sees it as one, > > unqualified thing. > > Well, no. Look at the error Python gives you, nested scope or not: > > Traceback (most recent call last): > File "", line 1, in > TypeError: exec: arg 1 must be a string, file, or code object > > If exec is a function, arg 1 is the boolean expression > "somestring to execute" in globals() > which is unlikely to be what you want. If exec is a statement, > arg 1 is a tuple of two elements, > "somestring to execute" in globals() > and > locals() > which is also unlikely to be what you want. Neither of these are > giving you a string, file or code object, exactly as the interpreter > is telling you. Well, no - I stick by my assertion, about the nested scope: >>> def rubbish(): def deep_rubbish(): exec('BUILD = "somestring"' in globals(),locals()) SyntaxError: unqualified exec is not allowed in function 'deep_rubbish' it is a nested function (, line 3) >>> That is all I was saying - It was the brackets that buggered me, and adding the globals() and locals() inside the brackets, inside the nested scope, makes no difference - the interpreter sees it as an unqualified exec. Did you actually try it in a nested scope before asserting "nested scope or not" ? If you just do, in the outside scope, the thing I did originally: >>> exec('BUILD = "foobar"') >>> BUILD 'foobar' >>> Then the brackets are ignored, and the defaults kick in. But this is silly nit picking around the basic error, which was to treat the thing as a function and putting the brackets there. The other bits in the thread, about the scopes and locals() are far more interesting. - Hendrik From info at egenix.com Thu Jan 29 03:37:49 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 29 Jan 2009 09:37:49 +0100 Subject: ANN: eGenix mx Base Distribution 3.1.2 Message-ID: <49816ADD.2040705@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.1.2 for Python 2.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.1.2-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.1.2 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. We have fixed a number of small platform issues and added support for the strptime() function to mxDateTime on Windows. We have also enhanced the portability of our pre-built Mac OS X binaries. As always, we are providing pre-built binaries for all supported platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler to be installed. For a list of changes, please refer to the eGenix mx Base Distribution change log at http://www.egenix.com/products/python/mxBase/changelog.html and the change logs of the various included Python packages. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the packages can be found on the eGenix mx Base Distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ LICENSE The eGenix mx Base package is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use the packages in both commercial and non-commercial settings without fee or charge. The package comes with full source code ________________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mal at egenix.com Thu Jan 29 03:57:55 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 29 Jan 2009 09:57:55 +0100 Subject: date handling problem In-Reply-To: References: Message-ID: <49816F93.8080101@egenix.com> On 2009-01-29 03:38, Gabriel Genellina wrote: > En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva > escribi?: > >> I need to parse rss-feeds based on time stamp,But rss-feeds follow >> different >> standards of date(IST,EST etc). >> I dont know,how to standardize this standards.It will be helpful if >> you can >> hint me. > > You may find the Olson timezone database useful. > http://pytz.sourceforge.net/ Or have a look at the date/time parser in mxDateTime: http://www.egenix.com/products/python/mxBase/mxDateTime/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:03:29 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:03:29 +0100 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <498170d4$0$23718$426a74cc@news.free.fr> Ron Garret a ?crit : > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > whenever I restart the server after making a code change it takes a very > long time (like a minute) before the script is active again. In other > words, I do an apachectl restart, reload the page in my browser, and one > minute later it finally comes up. During this time CPU usage is > essentially zero. Loading all the code manually into a python > interpreter is virtually instantaneous, and all subsequence interactions > with the app are very fast. > > Does anyone have any ideas what might be going on or how to debug this? Restarting apache (with or without mod_wsgi) can by itself take some time. Now, if you're running mod_wsgi in daemon mode, you _don't_ have to restart apache to reload your code - just touch the wsgi script file and you'll be done, ie with: WSGIProcessGroup myproject.tld WSGIDaemonProcess myproject.tld user=you group=you WSGIReloadMechanism Process WSGIScriptAlias / /var/www/myproject/apache/myapp.py you just have to touch myapp.py to force reload the subinterpreter(s). From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:06:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:06:58 +0100 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <498171a5$0$3681$426a74cc@news.free.fr> Ron Garret a ?crit : > In article , > Aleksandar Radulovic wrote: (snip) >> Secondly, why are you restarting apache after code changes? In normal >> circumstances, you shouldn't have to do that. > > I thought (and experiment confirms) that only the main WSGI app file > gets reloaded automatically when it changes, not the libraries. Depends on how you configure mod_wsgi. Read the part about "Process Reloading Mechanism" here: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode From tomanishkb at gmail.com Thu Jan 29 04:08:20 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 14:38:20 +0530 Subject: Python-list Digest, Vol 64, Issue 644 In-Reply-To: References: Message-ID: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> is python a pure objected oriented language? On Thu, Jan 29, 2009 at 2:08 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: dicts,instances,containers, slotted instances, et cetera. > (Michele Simionato) > 2. Re: Recommendation for a small web framework like Perl's > CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven) > 3. Re: Profiling Python Apps on Mac? (Robert Kern) > 4. Re: Results of executing hyperlink in script (Tino Wildenhain) > 5. Re: I'm a python addict ! (afriere at yahoo.co.uk) > 6. ANN: eGenix mx Base Distribution 3.1.2 > (eGenix Team: M.-A. Lemburg) > > > ---------- Forwarded message ---------- > From: Michele Simionato > To: python-list at python.org > Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) > Subject: Re: dicts,instances,containers, slotted instances, et cetera. > On Jan 29, 12:23 am, ocsch... at gmail.com wrote: > > > I just find it odd that there's no quick answer on the > > fastest way in Python to implement a mapping in this context. > > A Python dict is as fast as you can get. If that is not enough, your > only choice is to try something at the C level, which may give the > desired speedup or not. Good luck! > > Michele Simionato > > > > ---------- Forwarded message ---------- > From: Jeroen Ruigrok van der Werven > To: excord80 > Date: Thu, 29 Jan 2009 07:31:54 +0100 > Subject: Re: Recommendation for a small web framework like Perl's > CGI::Application to run as CGI? > -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: > >If that's correct, it would be great if there were a Werkzeug tutorial > >on deploying it for use with CGI. > > There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look > in the servers directory in the repository. > > I'll double check the documentation and expand where necessary. > > [1] http://zine.pocoo.org/ > > -- > Jeroen Ruigrok van der Werven / asmodai > ????? ?????? ??? ?? ?????? > http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B > Earth to earth, ashes to ashes, dust to dust... > > > > ---------- Forwarded message ---------- > From: Robert Kern > To: python-list at python.org > Date: Thu, 29 Jan 2009 00:47:46 -0600 > Subject: Re: Profiling Python Apps on Mac? > On 2009-01-28 13:14, RGK wrote: > >> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & >> wxPython under OSX 10.4) >> >> As I make program architecture decisions, it would be nice to be able to >> profile the choices. Should I add that extra thread? Is this big-assed >> xml object I just created horribly bloated or kind of ordinary. >> >> Is there anything out there I should look into to if I want to see how >> those things are affecting my app? The closest I have is the widget >> iStat, but it's a very static low resolution view of what's really going >> on. >> > > I have a script kernprof.py which provides a few conveniences over the > builtin cProfile module. One of its modes of operation is to inject a > decorator into the __builtins__. It will enable the profiler on entry to the > method and disable it on exit. This lets you localize your profile results > to just the part of your code that you are interested in. I found this > especially useful in GUI apps which require user interaction to trigger the > part of the code you are actually interesting in profiling. You don't want > the interesting parts of your profile to be obscured by the GUI event loop > waiting for your input. > > You can get it as part of my line_profiler package (which you may also be > interested in; cProfile profiles function calls, line_profiler profiles > individual lines). > > http://pypi.python.org/pypi/line_profiler > > You can view the profile results interactively with "python -m pstats > my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install > kcachegrind on your system: > > http://www.vrplumber.com/programming/runsnakerun/ > http://pypi.python.org/pypi/pyprof2calltree/1.1.0 > > I don't recommend using hotshot because it is deprecated and slow to > postprocess the data dumps. Also, I don't recommend using the plain profile > module because it slows down your program rather more than cProfile. See the > Python documentation for an overview of these modules: > > http://docs.python.org/library/profile > > -- > 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 > > > > > ---------- Forwarded message ---------- > From: Tino Wildenhain > To: Tim Chase > Date: Thu, 29 Jan 2009 07:59:58 +0100 > Subject: Re: Results of executing hyperlink in script > Tim Chase wrote: > >> 1. This method was suggested by Cameron Laird: >>> >>> os.system("start %s" % URL) >>> >>> It works. But, if the URL contains character &, it will fail. For >>> >> >> >> As an aside, the START command is a bit picky regarding quotes. You have >> to use this horrible contortion >> >> os.system('start "title" "%s"' % URL) >> >> The "title" is optional content-wise, but required positionally if there's >> a quoted resource, so you can just use >> >> start "" "%s" >> >> a pain, but that's CMD.EXE for you. :) >> > > ah, and just for the records, at least > os.popen2,os.popen3 support tuple as argument: > > i,o=os.popen2((cmd,arg1,arg2)) and quotes them > correctly. > > Regards > Tino > > > ---------- Forwarded message ---------- > From: afriere at yahoo.co.uk > To: python-list at python.org > Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) > Subject: Re: I'm a python addict ! > On Jan 27, 4:52 am, Paul McGuire wrote: > [snip] > > > > # how you have to do it in C++ and Java > > # light = light.next_state() > > > > # using Python > > light.__class__ = light.next_state > > I'm sure you can, but why poke yourself in the eye with a blunt > stick? ;) > > IMO there are two obvious problems with the latter approach. Firstly > the information about the next state is left lying about in some > namespace separate from the object, whereas the object itself ought to > know what it's 'next_state' is (or, more correctly, how to determine > it). > > Secondly you miss the opportunity of sending a signal to the new > state. Consider that in some jurisdictions the amber light shows > before the green as well as before the red (yeah, I know is that an > invitation for drag racing or what!?). If you called next_state as a > verb you could pass the current state as an argument and the amber (or > yellow, if you prefer) light could work which of the two possible next > states to call in turn. The fact that this behaviour is, in this > example, peculiar to the amber light, demonstrates the pertinence of > my first objection above. > > Fortunately the "C++ and Java" approach, (though I would never want to > be seen advocating the C++ or Java approach to anything), is in this > case available in Python as well, at the cheaper price of fewer > characters and arguably greater readibility to boot. > > I know, Iknow ... you wanted to show how that code could be used in a > non "sulphurous" way. Which just goes to show that the devil makes > work for idle hands ... or foils the best laid plans ... or is in the > detail ... or something sulphurous. :) > > > > ---------- Forwarded message ---------- > From: "eGenix Team: M.-A. Lemburg" > To: "Python List @ Python.org" > Date: Thu, 29 Jan 2009 09:37:49 +0100 > Subject: ANN: eGenix mx Base Distribution 3.1.2 > ________________________________________________________________________ > > ANNOUNCING > > eGenix.com mx Base Distribution > > Version 3.1.2 for Python 2.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.1.2-GA.html > > ________________________________________________________________________ > > ABOUT > > The eGenix.com mx Base Distribution for Python is a collection of > professional quality software tools which enhance Python's usability > in many important areas such as fast text searching, date/time > processing and high speed data types. > > The tools have a proven record of being portable across many Unix and > Windows platforms. You can write applications which use the tools on > Windows and then run them on Unix platforms without change due to the > consistent platform independent interfaces. > > Contents of the distribution: > > * mxDateTime - Date/Time Library for Python > * mxTextTools - Fast Text Parsing and Processing Tools for Python > * mxProxy - Object Access Control for Python > * mxBeeBase - On-disk B+Tree Based Database Kit for Python > * mxURL - Flexible URL Data-Type for Python > * mxUID - Fast Universal Identifiers for Python > * mxStack - Fast and Memory-Efficient Stack Type for Python > * mxQueue - Fast and Memory-Efficient Queue Type for Python > * mxTools - Fast Everyday Helpers for Python > > All available packages have proven their stability and usefulness in > many mission critical applications and various commercial settings all > around the world. > > For more information, please see the distribution page: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > NEWS > > The 3.1.2 release of the eGenix mx Base Distribution is the latest > release of our open-source Python extensions. > > We have fixed a number of small platform issues and added support for > the strptime() function to mxDateTime on Windows. We have also enhanced > the portability of our pre-built Mac OS X binaries. > > As always, we are providing pre-built binaries for all supported > platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, > FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. > > Whether you are using a pre-built package or the source distribution, > installation is a simple "python setup.py install" command in all > cases. The only difference is that the pre-built packages do not > require a compiler to be installed. > > For a list of changes, please refer to the eGenix mx Base Distribution > change log at > > http://www.egenix.com/products/python/mxBase/changelog.html > > and the change logs of the various included Python packages. > > ________________________________________________________________________ > > DOWNLOADS > > The download archives and instructions for installing the packages can > be found on the eGenix mx Base Distribution page: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > LICENSE > > The eGenix mx Base package is distributed under the eGenix.com Public > License 1.1.0 which is an Open Source license similar to the Python > license. You can use the packages in both commercial and non-commercial > settings without fee or charge. > > The package comes with full source code > > ________________________________________________________________________ > > SUPPORT > > Commercial support for this product is available from eGenix.com. > Please see > > http://www.egenix.com/services/support/ > > for details about our support offerings. > > Enjoy, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Jan 29 2009) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:14:59 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:14:59 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <49802c05$0$5139$426a34cc@news.free.fr> <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> Message-ID: <49817386$0$24403$426a34cc@news.free.fr> excord80 a ?crit : > On Jan 28, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> What about:http://thraxil.org/code/cgi_app/ >> >> (yes, it is a port of CGI::Application, and FWIW it's mentionned on the >> CGI::Application's wiki). >> > > Nice find. Thank you. Interesting project. It seems to be only one > fairly short file (perhaps that's all it takes), It is. And given the intended context (CGI...), it's a GoodThing !-) > and its most recent > release was in 2004. No mailing list. Nope. But does it need new release or a mailing list ? As you say, it's just a pretty simple module. The point is that you are very likely to fork it for your own needs anyway - so see it as a good starting point for a simple lightweight CGI/mod_python (and why not WSGI) framework. From alex at a13x.net Thu Jan 29 04:15:27 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Thu, 29 Jan 2009 09:15:27 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> Message-ID: <845b10c50901290115s10b0b3c5qa5e30c87ea83998b@mail.gmail.com> Graham, On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton wrote: > Sorry, you are wrong to assume that an Apache restart is not be > required. > If you are using mod_wsgi embedded mode, or mod_python, then a code > change will always require a full restart of Apache. I am running several middleware apps I'm working on under mod_python (simple setup using mod_python.publisher handler) and so far, haven't had the reason to restart apache at all. > Thus, the conjecture that Apache/mod_wsgi cannot be used and that > CherryPy WSGI server or Paster server must be used when developing a > Python web application is false. If using mod_wsgi then daemon mode Not sure what (or whom) you're referring to. IMO, developing TG/Pylons/Django apps is much convinient with embedded web server (cherrypy or paster) as it is possible to do rapid development without resorting to restarts. Example with Pylons: $ paster serve development.ini --reload This will start a subprocess which monitors file changes. Regards, alex. -- a lex 13 x http://www.a13x.info From clp2 at rebertia.com Thu Jan 29 04:40:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 01:40:00 -0800 Subject: Python-list Digest, Vol 64, Issue 644 In-Reply-To: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> References: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> Message-ID: <50697b2c0901290140w12bcd121kf555c4f7999f41ec@mail.gmail.com> On Thu, Jan 29, 2009 at 1:08 AM, M Kumar wrote: > is python a pure objected oriented language? Firstly: (A) Replying to Digests rather than individual posts is very discouraged. (B) The proper way to start a new thread by emailing python-list at python.org (as it says in the very header of the digest!), not by replying to unrelated posts. And now to your question: Yes, Python is completely object-oriented in the Smalltalk sense; everything is an object, there are no "primitive types" or non-object values, in contrast to, say, Java. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > On Thu, Jan 29, 2009 at 2:08 PM, wrote: >> >> Send Python-list mailing list submissions to >> python-list at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.python.org/mailman/listinfo/python-list >> or, via email, send a message with subject or body 'help' to >> python-list-request at python.org >> >> You can reach the person managing the list at >> python-list-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Python-list digest..." >> >> Today's Topics: >> >> 1. Re: dicts,instances,containers, slotted instances, et cetera. >> (Michele Simionato) >> 2. Re: Recommendation for a small web framework like Perl's >> CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven) >> 3. Re: Profiling Python Apps on Mac? (Robert Kern) >> 4. Re: Results of executing hyperlink in script (Tino Wildenhain) >> 5. Re: I'm a python addict ! (afriere at yahoo.co.uk) >> 6. ANN: eGenix mx Base Distribution 3.1.2 >> (eGenix Team: M.-A. Lemburg) >> >> >> ---------- Forwarded message ---------- >> From: Michele Simionato >> To: python-list at python.org >> Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) >> Subject: Re: dicts,instances,containers, slotted instances, et cetera. >> On Jan 29, 12:23 am, ocsch... at gmail.com wrote: >> >> > I just find it odd that there's no quick answer on the >> > fastest way in Python to implement a mapping in this context. >> >> A Python dict is as fast as you can get. If that is not enough, your >> only choice is to try something at the C level, which may give the >> desired speedup or not. Good luck! >> >> Michele Simionato >> >> >> >> ---------- Forwarded message ---------- >> From: Jeroen Ruigrok van der Werven >> To: excord80 >> Date: Thu, 29 Jan 2009 07:31:54 +0100 >> Subject: Re: Recommendation for a small web framework like Perl's >> CGI::Application to run as CGI? >> -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: >> >If that's correct, it would be great if there were a Werkzeug tutorial >> >on deploying it for use with CGI. >> >> There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look >> in the servers directory in the repository. >> >> I'll double check the documentation and expand where necessary. >> >> [1] http://zine.pocoo.org/ >> >> -- >> Jeroen Ruigrok van der Werven / asmodai >> ????? ?????? ??? ?? ?????? >> http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B >> Earth to earth, ashes to ashes, dust to dust... >> >> >> >> ---------- Forwarded message ---------- >> From: Robert Kern >> To: python-list at python.org >> Date: Thu, 29 Jan 2009 00:47:46 -0600 >> Subject: Re: Profiling Python Apps on Mac? >> On 2009-01-28 13:14, RGK wrote: >>> >>> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & >>> wxPython under OSX 10.4) >>> >>> As I make program architecture decisions, it would be nice to be able to >>> profile the choices. Should I add that extra thread? Is this big-assed >>> xml object I just created horribly bloated or kind of ordinary. >>> >>> Is there anything out there I should look into to if I want to see how >>> those things are affecting my app? The closest I have is the widget >>> iStat, but it's a very static low resolution view of what's really going >>> on. >> >> I have a script kernprof.py which provides a few conveniences over the >> builtin cProfile module. One of its modes of operation is to inject a >> decorator into the __builtins__. It will enable the profiler on entry to the >> method and disable it on exit. This lets you localize your profile results >> to just the part of your code that you are interested in. I found this >> especially useful in GUI apps which require user interaction to trigger the >> part of the code you are actually interesting in profiling. You don't want >> the interesting parts of your profile to be obscured by the GUI event loop >> waiting for your input. >> >> You can get it as part of my line_profiler package (which you may also be >> interested in; cProfile profiles function calls, line_profiler profiles >> individual lines). >> >> http://pypi.python.org/pypi/line_profiler >> >> You can view the profile results interactively with "python -m pstats >> my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install >> kcachegrind on your system: >> >> http://www.vrplumber.com/programming/runsnakerun/ >> http://pypi.python.org/pypi/pyprof2calltree/1.1.0 >> >> I don't recommend using hotshot because it is deprecated and slow to >> postprocess the data dumps. Also, I don't recommend using the plain profile >> module because it slows down your program rather more than cProfile. See the >> Python documentation for an overview of these modules: >> >> http://docs.python.org/library/profile >> >> -- >> 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 >> >> >> >> >> ---------- Forwarded message ---------- >> From: Tino Wildenhain >> To: Tim Chase >> Date: Thu, 29 Jan 2009 07:59:58 +0100 >> Subject: Re: Results of executing hyperlink in script >> Tim Chase wrote: >>>> >>>> 1. This method was suggested by Cameron Laird: >>>> >>>> os.system("start %s" % URL) >>>> >>>> It works. But, if the URL contains character &, it will fail. For >>> >>> >>> As an aside, the START command is a bit picky regarding quotes. You have >>> to use this horrible contortion >>> >>> os.system('start "title" "%s"' % URL) >>> >>> The "title" is optional content-wise, but required positionally if >>> there's a quoted resource, so you can just use >>> >>> start "" "%s" >>> >>> a pain, but that's CMD.EXE for you. :) >> >> ah, and just for the records, at least >> os.popen2,os.popen3 support tuple as argument: >> >> i,o=os.popen2((cmd,arg1,arg2)) and quotes them >> correctly. >> >> Regards >> Tino >> >> >> ---------- Forwarded message ---------- >> From: afriere at yahoo.co.uk >> To: python-list at python.org >> Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) >> Subject: Re: I'm a python addict ! >> On Jan 27, 4:52 am, Paul McGuire wrote: >> [snip] >> > >> > # how you have to do it in C++ and Java >> > # light = light.next_state() >> > >> > # using Python >> > light.__class__ = light.next_state >> >> I'm sure you can, but why poke yourself in the eye with a blunt >> stick? ;) >> >> IMO there are two obvious problems with the latter approach. Firstly >> the information about the next state is left lying about in some >> namespace separate from the object, whereas the object itself ought to >> know what it's 'next_state' is (or, more correctly, how to determine >> it). >> >> Secondly you miss the opportunity of sending a signal to the new >> state. Consider that in some jurisdictions the amber light shows >> before the green as well as before the red (yeah, I know is that an >> invitation for drag racing or what!?). If you called next_state as a >> verb you could pass the current state as an argument and the amber (or >> yellow, if you prefer) light could work which of the two possible next >> states to call in turn. The fact that this behaviour is, in this >> example, peculiar to the amber light, demonstrates the pertinence of >> my first objection above. >> >> Fortunately the "C++ and Java" approach, (though I would never want to >> be seen advocating the C++ or Java approach to anything), is in this >> case available in Python as well, at the cheaper price of fewer >> characters and arguably greater readibility to boot. >> >> I know, Iknow ... you wanted to show how that code could be used in a >> non "sulphurous" way. Which just goes to show that the devil makes >> work for idle hands ... or foils the best laid plans ... or is in the >> detail ... or something sulphurous. :) >> >> >> >> ---------- Forwarded message ---------- >> From: "eGenix Team: M.-A. Lemburg" >> To: "Python List @ Python.org" >> Date: Thu, 29 Jan 2009 09:37:49 +0100 >> Subject: ANN: eGenix mx Base Distribution 3.1.2 >> ________________________________________________________________________ >> >> ANNOUNCING >> >> eGenix.com mx Base Distribution >> >> Version 3.1.2 for Python 2.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.1.2-GA.html >> >> ________________________________________________________________________ >> >> ABOUT >> >> The eGenix.com mx Base Distribution for Python is a collection of >> professional quality software tools which enhance Python's usability >> in many important areas such as fast text searching, date/time >> processing and high speed data types. >> >> The tools have a proven record of being portable across many Unix and >> Windows platforms. You can write applications which use the tools on >> Windows and then run them on Unix platforms without change due to the >> consistent platform independent interfaces. >> >> Contents of the distribution: >> >> * mxDateTime - Date/Time Library for Python >> * mxTextTools - Fast Text Parsing and Processing Tools for Python >> * mxProxy - Object Access Control for Python >> * mxBeeBase - On-disk B+Tree Based Database Kit for Python >> * mxURL - Flexible URL Data-Type for Python >> * mxUID - Fast Universal Identifiers for Python >> * mxStack - Fast and Memory-Efficient Stack Type for Python >> * mxQueue - Fast and Memory-Efficient Queue Type for Python >> * mxTools - Fast Everyday Helpers for Python >> >> All available packages have proven their stability and usefulness in >> many mission critical applications and various commercial settings all >> around the world. >> >> For more information, please see the distribution page: >> >> http://www.egenix.com/products/python/mxBase/ >> >> ________________________________________________________________________ >> >> NEWS >> >> The 3.1.2 release of the eGenix mx Base Distribution is the latest >> release of our open-source Python extensions. >> >> We have fixed a number of small platform issues and added support for >> the strptime() function to mxDateTime on Windows. We have also enhanced >> the portability of our pre-built Mac OS X binaries. >> >> As always, we are providing pre-built binaries for all supported >> platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, >> FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. >> >> Whether you are using a pre-built package or the source distribution, >> installation is a simple "python setup.py install" command in all >> cases. The only difference is that the pre-built packages do not >> require a compiler to be installed. >> >> For a list of changes, please refer to the eGenix mx Base Distribution >> change log at >> >> http://www.egenix.com/products/python/mxBase/changelog.html >> >> and the change logs of the various included Python packages. >> >> ________________________________________________________________________ >> >> DOWNLOADS >> >> The download archives and instructions for installing the packages can >> be found on the eGenix mx Base Distribution page: >> >> http://www.egenix.com/products/python/mxBase/ >> >> ________________________________________________________________________ >> >> LICENSE >> >> The eGenix mx Base package is distributed under the eGenix.com Public >> License 1.1.0 which is an Open Source license similar to the Python >> license. You can use the packages in both commercial and non-commercial >> settings without fee or charge. >> >> The package comes with full source code >> >> ________________________________________________________________________ >> >> SUPPORT >> >> Commercial support for this product is available from eGenix.com. >> Please see >> >> http://www.egenix.com/services/support/ >> >> for details about our support offerings. >> >> Enjoy, >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source (#1, Jan 29 2009) >> >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >> >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >> >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ >> ________________________________________________________________________ >> >> ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: >> >> >> eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 >> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg >> Registered at Amtsgericht Duesseldorf: HRB 46611 >> http://www.egenix.com/company/contact/ >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are interested > to be a part of it, please mail or call me. I will be happy to share and > inform - http://www.comat.com > > -- > http://mail.python.org/mailman/listinfo/python-list From jstroud at mbi.ucla.edu Thu Jan 29 04:52:57 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 29 Jan 2009 01:52:57 -0800 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> Message-ID: ocschwar at gmail.com wrote: > I can't port the entire app to be a stored database procedure. Perhaps I underestimate what you mean by this, but you may want to look at pyTables (http://www.pytables.org/moin/HowToUse). > ctypes, maybe. I just find it odd that there's no quick answer on the > fastest way in Python to implement a mapping in this context. Your explanation of where your prototype is slow is a little unclear. If your data is largely numerical, you may want to rethink your organization and use a numeric package. I did something similar and saw an order of magnitude speed increase by switching from python data types to numpy combined with careful tuning of how I managed the data. You may have to spend more time on this than you would like, but if you really put some thought into it and grind at your organization, you can probably get a significant performance increase. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From tomanishkb at gmail.com Thu Jan 29 05:01:40 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 15:31:40 +0530 Subject: is python Object oriented?? Message-ID: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Object oriented languages doesn't allow execution of the code without class objects, what is actually happening when we execute some piece of code, is it bound to any class? Those who have time and consideration can help me -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Thu Jan 29 05:17:52 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 29 Jan 2009 15:47:52 +0530 Subject: date handling problem In-Reply-To: <49816F93.8080101@egenix.com> References: <49816F93.8080101@egenix.com> Message-ID: On Thu, Jan 29, 2009 at 2:27 PM, M.-A. Lemburg wrote: > On 2009-01-29 03:38, Gabriel Genellina wrote: > > En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva > > escribi?: > > > >> I need to parse rss-feeds based on time stamp,But rss-feeds follow > >> different > >> standards of date(IST,EST etc). > >> I dont know,how to standardize this standards.It will be helpful if > >> you can > >> hint me. > > > > You may find the Olson timezone database useful. > > http://pytz.sourceforge.net/ > > Or have a look at the date/time parser in mxDateTime: > > http://www.egenix.com/products/python/mxBase/mxDateTime/ > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Jan 29 2009) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > -- > http://mail.python.org/mailman/listinfo/python-list > Thank you all, The link was really nice and i will try it out. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Thu Jan 29 05:21:37 2009 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 29 Jan 2009 02:21:37 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49818331.6010200@islandtraining.com> M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece > of code, is it bound to any class? > Those who have time and consideration can help me > Python *is* object-oriented, but it is not (as your definition suggests) object-fascist. We use objects to great effect in Python, when it is natural to do so, but the language does not force it on us. Gary Herron > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are > interested to be a part of it, please mail or call me. I will be happy > to share and inform - http://www.comat.com > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Thu Jan 29 05:25:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 02:25:57 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> On Thu, Jan 29, 2009 at 2:01 AM, M Kumar wrote: > Object oriented languages doesn't allow execution of the code without class > objects, what is actually happening when we execute some piece of code, is > it bound to any class? That's not really the standard definition of object-oriented (c.f. Wikipedia), but by your definition (which seems Java/Ruby-centric, IMHO), Python would not be object-oriented. In addition to methods, Python has functions, which are not associated with a class and let you write code in a procedural style, thus failing your criterion. Python also has the top-level module scope, in which the code isn't even part of a method or function at all and thus certainly is not associated with a class, again not satisfying your criterion. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 06:40:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 12:40:23 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49819599$0$20347$426a74cc@news.free.fr> (answering to the OP) > M Kumar wrote: >> Object oriented languages doesn't allow execution of the code without >> class objects, Chapter and verse, please ? Nothing in the (very few) "axioms" of OOP mentions "classes". You don't need classes to have an OOPL (ever heard about prototype-based languages ?). OOP is - as the name imply - about *objects*. >> what is actually happening when we execute some piece >> of code, Top-level code ? or the body of a def statement ? >> is it bound to any class? Why should it be ? From murielgodoi at gmail.com Thu Jan 29 06:47:51 2009 From: murielgodoi at gmail.com (Muriel de Souza Godoi) Date: Thu, 29 Jan 2009 09:47:51 -0200 Subject: is python Object oriented?? In-Reply-To: <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> Message-ID: Python offers support for object orientation, but it's not an object-oriented language. I mean, you can code a entire program in Python with no classes. So you use it if you want to. It's not like java, which you must use a class to code a Hello World, but Java isn't fully object-oriented, because it doesn't provide support for multiple inheritance and it has primitive types (multiple interfaces and wrappers to primitive types doesn't count :) ) AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe Simula?), where everything is a class, even the primitive types. An excellent reference book for that is: Sebesta, Robert W. (2002): *Concepts of Programming Languages (Fifth Edition).* Addison-Wesley Publishing Cheers, -- Muriel de Souza Godoi State University of Maring? Brazil -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Thu Jan 29 06:51:55 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 29 Jan 2009 12:51:55 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> Message-ID: <4981985B.4070108@wildenhain.de> Muriel de Souza Godoi wrote: > Python offers support for object orientation, but it's not an > object-oriented language. > I mean, you can code a entire program in Python with no classes. So you > use it if you want to. > > It's not like java, which you must use a class to code a Hello World, > but Java isn't fully object-oriented, because it doesn't provide support > for multiple inheritance and it has primitive types (multiple interfaces > and wrappers to primitive types doesn't count :) ) > > AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe > Simula?), where everything is a class, even the primitive types. well actually except keywords, everything is an object in python too, including of course primitive types (if you say so - practically python does not have them). Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From XX.XmcX at XX.XmclaveauX.com Thu Jan 29 07:10:08 2009 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Thu, 29 Jan 2009 13:10:08 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: Hi! Il se trouve que Chris Rebert a formul? : > Python has functions, which are not associated > with a class functions are methods of builtin... -- @-salutations Michel Claveau From steve at holdenweb.com Thu Jan 29 07:27:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 29 Jan 2009 07:27:36 -0500 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: W. eWatson wrote: > r wrote: >> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>> Where in the world is a description of pack() for Tkinter widgets? Is it >>> some sort of general method for all widgets? I'm looking in a few >>> docs that >>> use it without ever saying where it is described. For one, >>> . In the NM Tech pdf on >>> Tkinter, >>> it's not found anywhere. I see Universal methods for widgets, but no >>> mention >>> of pack(). package, packed, but no pack. >> >> did you try here :) >> http://effbot.org/tkinterbook/pack.htm > Thanks. I have the site bookmarked, but it's hard to search. I posted a > comment to them that they should have it in pdf form. > http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 29 07:33:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 29 Jan 2009 07:33:17 -0500 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece of > code, is it bound to any class? > Those who have time and consideration can help me a) This is a purely theoretical consideration. You asked whether "python is a pure object oriented language", but this will inevitably lead to obscure discussions about what you mean rather than what Python is. b) You seem to believe that a "pure" object oriented language must do everything using classes. Since many problems are just as easy (or easier) to solve with a procedural approach, Python takes the view that it should be easy to provide such solutions as well. c) import this The Zen of Python, by Tim Peters [...] practicality beats purity [...] We aren't big on purity in the Python world ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Graham.Dumpleton at gmail.com Thu Jan 29 08:00:06 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 05:00:06 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> Message-ID: <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> On Jan 29, 8:15?pm, Aleksandar Radulovic wrote: > Graham, > > On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton > > wrote: > > Sorry, you are wrong to assume that an Apache restart is not be > > required. > > If you are usingmod_wsgiembedded mode, or mod_python, then a code > > change will always require a full restart of Apache. > > I am running several middleware apps I'm working on under mod_python > (simple setup using mod_python.publisher handler) and so far, haven't > had the reason to restart apache at all. The automatic module reloading in mod_python when using mod_python.publisher only applies to the publisher code files or those imported via the mod_python module importer and which is also a candidate for reloading. Basically, any module or package installed on sys.path is not a candidate for reloading. Thus if you installed your code outside of your document tree in a directory in sys.path and those code files were changed, then no automatic reload would occur. For further information see documentation for import_module() in: http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html In other words, it is not universal that any code change will be automatically detected and a reload occur. There are also various caveats on what mod_python module importer does, as it is reloading modules into an existing process and not restarting the whole process. If you are not careful, weird things can happen. > > Thus, the conjecture that Apache/mod_wsgicannot be used and that > > CherryPy WSGI server or Paster server must be used when developing a > > Python web application is false. If usingmod_wsgithen daemon mode > > Not sure what (or whom) you're referring to. It was a general statement. There are various people on different forums and irc channels who keep saying that a full Apache restart is required with Apache/mod_wsgi when making code changes. Am just stating for the record that that isn't true. > IMO, developing TG/Pylons/Django > apps is much convinient with embedded web server (cherrypy or paster) as > it is possible to do rapid development without resorting to restarts. In the case of Django, it uses a single non threaded process, thus is not an adequate test of either a multithread or multiprocess environment. Something which Apache/mod_wsgi provides. CherryPy WSGI server although it provides multithreading doesn't have a multiprocess option and it itself doesn't have a reload feature but depends on some layer on top to manage that from what I remember. So, depends on how closely you want your development environment to mirror production so that issues are picked up sooner, rather than only at the point of deployment to a production system when you are under pressure. Graham From mdw at distorted.org.uk Thu Jan 29 08:04:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 29 Jan 2009 13:04:16 +0000 Subject: How to get atexit hooks to run in the presence of execv? References: Message-ID: <87ab9ap8kv.fsf.mdw@metalzone.distorted.org.uk> rocky at panix.com (R. Bernstein) writes: > Recently, I added remote debugging via TCP sockets. (Well, also FIFO's > as well but closing sockets before restarting is what's of concern.) > > I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get > called. Should it? I'd consider that to be highly unusual. Certainly, the C atexit(3) function is called only in response to a call to exit(3) (possibly implicitly by returning from main), and not by execve(2) or any of its little friends. Your specific problem is to do with file descriptors, so it's probably best dealt with using the close-on-exec flag: from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC sk = socket(...) ## ... fcntl(sk.fileno(), F_SETFD, fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC) Now the socket will be magically closed when you exec.. another program. Finally, can I urge against TCP sockets in an application like this? Certainly without adequate authentication, it will simply be insecure even within a single multiuser host (e.g., using localhost only) -- and assuming that even a home machine has only a single user is becoming less realistic. Unix-domain sockets live in the filesystem, and access to them is limited using the standard filesystem mechanisms. If you're expecting inter-host communications (e.g., remote debugging), it's a good idea to protect the session using TLS or something (much as I dislike the TLS certification/public-key- distribution model it's way better than nothing at all). -- [mdw] From wanglei.198112 at gmail.com Thu Jan 29 08:04:52 2009 From: wanglei.198112 at gmail.com (Wang Lei) Date: Thu, 29 Jan 2009 21:04:52 +0800 Subject: how to update python on gnu emacs? In-Reply-To: References: Message-ID: If you means python-mode, you can add this line to you .emacs: (setq py-python-command "python3.0") On 1/29/09, John Seales wrote: > > I've updated to python 2.6. My terminal application finds the new python > just fine, but my gnu-emacs still is on python 2.3. Does anyone know how I > can change that? > > using x86 powerbook > > John Seales > > _________________________________________________________________ > Windows Live? Hotmail(R)?more than just e-mail. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 -- Regards Lei From wanglei.198112 at gmail.com Thu Jan 29 08:06:50 2009 From: wanglei.198112 at gmail.com (Wang Lei) Date: Thu, 29 Jan 2009 21:06:50 +0800 Subject: how to update python on gnu emacs? In-Reply-To: References: Message-ID: Sorry. Mine is python3.0. Yours maybe is: (setq py-python-command "python2.6") -- Regards Lei From bettini at dsi.unifi.it Thu Jan 29 08:41:00 2009 From: bettini at dsi.unifi.it (Lorenzo Bettini) Date: Thu, 29 Jan 2009 14:41:00 +0100 Subject: syntax color lang source code in blogs or website In-Reply-To: References: Message-ID: <4981b1ea$1@news.x-privat.org> Xah Lee wrote: > For those of you using emacs, here's the elisp code that allows you to > syntax color computer language source code in your blog or website. > > http://xahlee.org/emacs/elisp_htmlize.html > may I suggest also this one: http://www.gnu.org/software/src-highlite/ -- Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino ICQ# lbetto, 16080134 (GNU/Linux User # 158233) HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com http://www.myspace.com/supertrouperabba BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com http://www.gnu.org/software/src-highlite http://www.gnu.org/software/gengetopt http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net From duncan.booth at invalid.invalid Thu Jan 29 08:44:45 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 Jan 2009 13:44:45 GMT Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Message-ID: alex wrote: > Jon > Thank you for your answer. I tried it with no success. > > However I tried with > tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of > tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") > > and it runs now with no error message, I can't figure for now why, but > it's great! This is motivating for going ahead. > cdll is for importing functions which use the cdecl calling convention where the caller must clean up the stack. windll is for functions that use the stdcall calling convention: the function that is called is responsible for cleaning up the stack. If you were using windll when you should have been using cdll then ctypes will have been expecting the library to clean up the stack, and the library will have been expecting the caller to do the cleanup, so nobody cleaned up the stack. The error message was telling you that ctypes pushed 4 bytes of argument onto the stack which weren't popped off by the caller. If you had been using the correct calling convention that would have indicated you had passed too many arguments, but as you were using the wrong calling convention the message was a bit unclear. -- Duncan Booth http://kupuguy.blogspot.com From tomanishkb at gmail.com Thu Jan 29 08:58:29 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 19:28:29 +0530 Subject: is python Object oriented?? In-Reply-To: <4981985B.4070108@wildenhain.de> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> Message-ID: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> but still I am not clear of the execution of the code, when we write or execute a piece of python code without defining class, predefined class attributes are available (not all but __name__ and __doc__ are available). does it mean anything to this topic. Is it necessory to have __module__, __dict__ and __bases__ for a class object in python? On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > Muriel de Souza Godoi wrote: > >> Python offers support for object orientation, but it's not an >> object-oriented language. >> I mean, you can code a entire program in Python with no classes. So you >> use it if you want to. >> >> It's not like java, which you must use a class to code a Hello World, but >> Java isn't fully object-oriented, because it doesn't provide support for >> multiple inheritance and it has primitive types (multiple interfaces and >> wrappers to primitive types doesn't count :) ) >> >> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >> Simula?), where everything is a class, even the primitive types. >> > > well actually except keywords, everything is an object in python too, > including of course primitive types (if you say so - practically python > does not have them). > > Regards > Tino > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythonsky at sky.com Thu Jan 29 09:11:30 2009 From: pythonsky at sky.com (garywood) Date: Thu, 29 Jan 2009 14:11:30 -0000 Subject: is there a shorter way to write this Message-ID: I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated import random list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'] word = ' ' a = random.choice(list) list.remove(a) b = random.choice(list) list.remove(b) c = random.choice(list) list.remove(c) d = random.choice(list) list.remove(d) e = random.choice(list) list.remove(e) word = a + b + c + d + e print (word) print(list) -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Thu Jan 29 09:22:56 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 29 Jan 2009 06:22:56 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <246d83f0-28e9-40e3-8584-0f0b364b4458@f40g2000pri.googlegroups.com> On Jan 29, 7:21?am, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. ? I'm a python-nazi. No python for you! From jnoller at gmail.com Thu Jan 29 09:26:23 2009 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 29 Jan 2009 09:26:23 -0500 Subject: Terminating a Python program that uses multi-process, multi-threading In-Reply-To: References: Message-ID: <4222a8490901290626n76dbe96bl8394bef2c9d413d6@mail.gmail.com> On Wed, Jan 28, 2009 at 3:46 PM, akineko wrote: > Hello Python experts, > > I have a program that uses three processes (invoked by > multiprocessing) and several threads. > The program is terminated when ^C is typed (KeyboardInterrupt). > The main process takes the KeyboardInterrupt Exception and it orderly > shutdown the program. > > It works fine in normal situation. > > However, KeyboardInterrupt is not accepted when, for example, the > program is stuck somewhere due to error in network. I understand that > the KeyboardInterrupt won't be processed until the program moves out > from an atomic step in a Python program. > > Probably this is partly my fault as I use some blocking statements > (without timeout) as they should not block the program in normal > situation. > > As the program freezes up, I cannot do anything except killing three > processes using kill command. > So, I cannot tell which statement is actually blocking when this > occurs (and there are many suspects). > > Is there any good way to deal with this kind of problem? > Killing three processes when it hangs is not a fun thing to do. > > Any suggestions will be greatly appreciated. > > Best regards, > Aki Niimura > > -- > http://mail.python.org/mailman/listinfo/python-list > See also: http://jessenoller.com/2009/01/08/multiprocessingpool-and-keyboardinterrupt/ jesse From apt.shansen at gmail.com Thu Jan 29 09:27:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:27:02 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <7a9c25c20901290627h1e415788h3516a189dc463e44@mail.gmail.com> On Thu, Jan 29, 2009 at 5:58 AM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think there's some confusion on what you're asking; Python enables you to write object oriented software if you choose to. It also enables you to write procedural software if you choose to. There's other paradigms it supports too, to varying degrees. Its a tool that allows you to use it as you wish, instead of saying that a paradigm is the Right Way to do it. When you are writing object oriented software, you generally define classes. Class can inherit from other classes: if they do then the __bases__ attribute is set on the class itself to indicate which classes it inherits from. All Python code is within a module -- as a module is simply a file. For classes, functions and methods, the __module__ attribute simply points to which module it was defined in. The __dict__ of a class represents the dictionary of attributes that are "in" or "on" that class (approximately). But those are all implementation details. You don't have to set any of them or worry about any of them generally. You just: class MyClass: def __init__(self, bar): self.value = bar def foo(self): return self.value You don't have to set any class attributes to work with classes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Thu Jan 29 09:29:15 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 29 Jan 2009 15:29:15 +0100 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> > I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated > > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) Hmm, sounds like homework, but I'll bite. How about... import random, string indices = range(26) random.shuffle(indices) word = "".join([string.ascii_lowercase[i] for i in indices[:5]]) print word Cheers, Drea -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Jan 29 09:35:05 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:35:05 -0800 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> On Thu, Jan 29, 2009 at 6:11 AM, garywood wrote: > I had a task in a book to pick 5 items from a list of 26 ensuring the > items are not repeated > > If the list is unique of 26 elements is guaranteed to be unique, simply: >>> import random >>> random.sample(list, 5) ['g', 'y', 'i', 'n', 'x'] If the list isn't unique: >>> import random >>> random.sample(set(list), 5) ['r', 'e', 'b', 'k', 'i'] If you want to combine them all into a single word as you do in your example: >>> import random >>> ''.join(random.sample(set(list), 5)) 'wmhsq' --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Thu Jan 29 09:35:46 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 29 Jan 2009 15:35:46 +0100 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <9fdb569a0901290635m22e37c81uc70f9b894ac32d56@mail.gmail.com> 2009/1/29 garywood : > I had a task in a book to pick 5 items from a list of 26 ensuring the items > are not repeated > > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > There are probably several ways to do that, e.g.: >>> lst = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] >>> randomized_list = lst[:] >>> random.shuffle(randomized_list) >>> randomized_list[:5] ['n', 'p', 'e', 'f', 'y'] >>> (better not name a variable like a builtin - list) hth, vbr From apt.shansen at gmail.com Thu Jan 29 09:36:05 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:36:05 -0800 Subject: is there a shorter way to write this In-Reply-To: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> References: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> Message-ID: <7a9c25c20901290636h75be5772if494da0a530b77cd@mail.gmail.com> If the list is unique of 26 elements is guaranteed to be unique, simply: > Wow, 6am copy editing of my own posts is terribly ineffective. "If the list of 26 elements is guaranteed to be unique" -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Jan 29 09:53:45 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 08:53:45 -0600 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <4981C2F9.4040901@tim.thechases.com> > I had a task in a book to pick 5 items from a list of 26 > ensuring the items are not repeated > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) If you just need the "word", you can use >>> word = "".join(random.sample(string.lowercase, 5)) If you need the "leftovers" too: >>> letters = list(string.lowercase) >>> random.shuffle(letters) >>> word = "".join(letters[:5]) >>> remainder = letters[5:] >>> print word hjwnq >>> print "".join(letters) ebultgydafpmrxszicvko This assumes that your input dataset is unique (which string.lowercase is, but your problem definition doesn't guarantee) for your definition of "unique" (are upper/lowercase considered "unique" or "the same"?). If you need unique, you'd have to pre-process -- likely with set(): >>> data = "abcdefghijABCDEFGHIJK" >>> input_data = list(set(c.lower() for c in data)) >>> word = "".join(random.sample(input_data, 5)) >>> random.shuffle(input_data) >>> word = "".join(input_data[:5]) >>> remainder = "".join(input_data[5:]) -tkc From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 09:55:32 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 15:55:32 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <4981c355$0$9784$426a74cc@news.free.fr> MC a ?crit : > Hi! > > Il se trouve que Chris Rebert a formul? : >> Python has functions, which are not associated >> with a class > > functions are methods of builtin... Please check your facts. Python functions are not "methods" of anything (and not even necessarily attributes of a module - think about nested functions...). From python.list at tim.thechases.com Thu Jan 29 10:03:50 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 09:03:50 -0600 Subject: is there a shorter way to write this In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> References: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> Message-ID: <4981C556.80602@tim.thechases.com> > Hmm, sounds like homework, but I'll bite. The underlying problem does sound like homework, but the OP posted a working solution, and was only looking for ways to improve it. So I'm a little more lenient on providing alternatives. It's true that the homework problem may have been exactly as posted ("Improve this code"), but that's less likely in my estimation. -tkc From a at nospam.org Thu Jan 29 10:05:11 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 16:05:11 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Hello all, I have frozen a running application which is using SQLite with py2exe. When I start the exe file I see in the log file of the exe: Traceback (most recent call last): File "dpconf.py", line 666, in ? File "dpconf.py", line 251, in __init__ File "sqlite\main.pyc", line 255, in execute _sqlite.DatabaseError: no such table: genslaveopt The table exist in the database file ... no problem with the plain python version. How can I solve that problem ?? Best Regards --Armin From a at nospam.org Thu Jan 29 10:06:26 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 16:06:26 +0100 Subject: py2exe + SQLite problem Message-ID: Hello all, I have frozen a running application which is using SQLite with py2exe. When I start the exe file I see in the log file of the exe: Traceback (most recent call last): File "dpconf.py", line 666, in ? File "dpconf.py", line 251, in __init__ File "sqlite\main.pyc", line 255, in execute _sqlite.DatabaseError: no such table: genslaveopt The table exist in the database file ... no problem with the plain python version. How can I solve that problem ?? Best Regards --Armin From alejandro.weinstein at gmail.com Thu Jan 29 11:04:49 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Thu, 29 Jan 2009 08:04:49 -0800 (PST) Subject: Get thread pid Message-ID: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Hi: I have Python program running under Linux, that create several threads, and I want to now the corresponding PID of the threads. In each of the threads I have def run(self): pid = os.getpid() logger.critical('process ID: %s', pid) However, the reported PID is the father number, not the PID of the new thread. Is there a way to get the PID of the thread? To illustrate this further, this is the output of pstree when the PID of the main Python thread is 9197: $pstree -p 9197 python(9197)???{python}(9555) ??{python}(9556) ??{python}(9557) ??{python}(9558) ??{python}(9559) ??{python}(9560) ??{python}(9561) ??{python}(9562) ??{python}(9563) ??{python}(9564 I want each thread to report its PID number, in this case 9555, 9556, etc., but with os.getpid() is get 9197. Regards, Alejandro. From coutinhotiago at gmail.com Thu Jan 29 11:21:39 2009 From: coutinhotiago at gmail.com (coutinhotiago at gmail.com) Date: Thu, 29 Jan 2009 08:21:39 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8a3105be-4eac-4da0-97f5-e0b8b02b7bb0@r15g2000prh.googlegroups.com> On Jan 28, 11:32?pm, "Gabriel Genellina" wrote: > En Wed, 28 Jan 2009 16:05:39 -0200, coutinhoti... at gmail.com ? > escribi?: > > > ? I had the same problem myself. > > ? Mark's detailed explanation really helped me understand. > > > ? I ended up doing something like: > > The code doesn't work as-is, could you please post a working version? Just ? > for the record, so people reading this thread later don't get confused. > > -- > Gabriel Genellina Sure! This works for me: class A: def __init__(self): names = 'n1', 'n2' for n in names: setattr(self, "get%s" % n, self._createGetter(n)) def _createGetter(self, n): def f(): return n return f if __name__ == "__main__": a=A() print a.getn1() print a.getn2() From mail at anjanesh.net Thu Jan 29 11:24:46 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 29 Jan 2009 21:54:46 +0530 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to Message-ID: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Im reading a file. But there seems to be some encoding error. >>> f = open(filename) >>> data = f.read() Traceback (most recent call last): File "", line 1, in data = f.read() File "C:\Python30\lib\io.py", line 1724, in read decoder.decode(self.buffer.read(), final=True)) File "C:\Python30\lib\io.py", line 1295, in decode output = self.decoder.decode(input, final=final) File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to The string at position 10442 is something like this : "query":"0 1???? \u2021 0\u201a0 \u2021????"," So what encoding value am I supposed to give ? I tried f = open(filename, encoding="cp1252") but still same error. I guess Python3 auto-detects it as cp1252 -- Anjanesh Lekshmnarayanan From bhood37 at hotmail.com Thu Jan 29 11:35:47 2009 From: bhood37 at hotmail.com (Uberman) Date: Thu, 29 Jan 2009 09:35:47 -0700 Subject: Weird invisible arguments issues with Windows Message-ID: I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. First off, it didn't register the extension for .PY (although it did register .PYC). After manually associating the .PY extension with the python.exe executable, I am now getting some weirdness on the command line. When I run the following script, saved as "build.py", by simply entering "build.py -r -d" on the command line, it produces the output "1": import sys if __name__ == "__main__": print len(sys.argv) It doesn't see the additional arguments for some reason. However, if I execute the script by prefixing it (i.e., "python build.py -r -d"), I get an output of "3", meaning it sees the additional arguments. Has anybody else run into this issue? And perhaps (hopefully) solved it? From rocky at panix.com Thu Jan 29 11:36:27 2009 From: rocky at panix.com (R. Bernstein) Date: Thu, 29 Jan 2009 11:36:27 -0500 Subject: How to get atexit hooks to run in the presence of execv? References: <87ab9ap8kv.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding writes: > rocky at panix.com (R. Bernstein) writes: > >> Recently, I added remote debugging via TCP sockets. (Well, also FIFO's >> as well but closing sockets before restarting is what's of concern.) >> >> I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get >> called. Should it? > > I'd consider that to be highly unusual. Certainly, the C atexit(3) > function is called only in response to a call to exit(3) (possibly > implicitly by returning from main), and not by execve(2) or any of its > little friends. > > Your specific problem is to do with file descriptors, so it's probably > best dealt with using the close-on-exec flag: > > from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC > > sk = socket(...) > ## ... > fcntl(sk.fileno(), F_SETFD, > fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC) > > Now the socket will be magically closed when you exec.. another program. Thanks for the wealth of information. Alas, somehow I think this begs the question. I *know* how to arrange in the debugger for it to clean up after itself. But it's the program being debugged which I have no control over. And I would like to give it an opportunity to clean up after itself. > > Finally, can I urge against TCP sockets in an application like this? By all means, I hope people will offer thoughts, concerns and ideas. > Certainly without adequate authentication, it will simply be insecure > even within a single multiuser host (e.g., using localhost only) -- and > assuming that even a home machine has only a single user is becoming > less realistic. Unix-domain sockets live in the filesystem, and access > to them is limited using the standard filesystem mechanisms. > > If you're expecting inter-host communications (e.g., remote debugging), > it's a good idea to protect the session using TLS or something (much as > I dislike the TLS certification/public-key- distribution model it's way > better than nothing at all). Well, I also started coding FIFO's as well as TCP sockets, partly because I could, and partly to try to try to keep the interface generic. And in the back of my mind, I'd like to add serial devices as well - I don't see a reason not to. Initially, I probably won't add authentication or encryption. I'm having enough of a time trying to get this much working. (cpickling over sockets seems to still require knowing how many messages were sent and unpickling each of those, and TCP_NODELAY isn't allowed and doesn't seem the right thing either.) However what I really would like to see is authentication and encription added as an independent plugin layer much as I view whether one is debugging locally or not. So I don't see this as an issue per se with TCP sockets. > > -- [mdw] From markobrien85 at gmail.com Thu Jan 29 11:38:43 2009 From: markobrien85 at gmail.com (markobrien85 at gmail.com) Date: Thu, 29 Jan 2009 08:38:43 -0800 (PST) Subject: persistent TCP connection in python using socketserver Message-ID: <1acc7d88-7903-4cf7-8f7f-5824c19dbf63@p2g2000prn.googlegroups.com> G'day I'm currently using socketserver to build a simple XMLSocket (an XML based protocol used for communication between flash and the outside world) server. I've got flash establishing a connection, sending a request and my python server responding. However at this point socketserver terminates the connection. Which is bad, since i need a persistent connection so i can push data from the server to the client without the overhead of polling. I need to create TCP connection that persists until I explicitly tell it to terminate, or the connection is terminated on the other end. A quick look through the socketserver code makes this seem impossible since it appears to call close after the handle() method. Is there an even lower level library to be using, or is there some option I haven't found yet in socketserver. Cheers From a at nospam.org Thu Jan 29 11:40:51 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 17:40:51 +0100 Subject: py2exe + data_files Message-ID: Hello, is there a way to place individual data files into to the standard 'dist' directory and not into a subdirectory of 'dist' --Armin From mcerini at gmail.com Thu Jan 29 11:48:03 2009 From: mcerini at gmail.com (mattc) Date: Thu, 29 Jan 2009 08:48:03 -0800 (PST) Subject: How does one view the source of function defined in the interpreter? Message-ID: 1) It appears that it is possible to view the source of a function defined in the interpreter; however, I seem to be unable to do it. Here is the code and resulting error. >>> def f(): print("hello world") >>> f >>> f() hello world >>> import inspect >>> inspect >>> inspect.getsourcelines(f) Traceback (most recent call last): File "", line 1, in inspect.getsourcelines(f) File "C:\Python30\lib\inspect.py", line 678, in getsourcelines lines, lnum = findsource(object) File "C:\Python30\lib\inspect.py", line 526, in findsource raise IOError('could not get source code') IOError: could not get source code 2) Also, is there a method to inspect f in the form "f.inspect" or "f.getsource" or "f.dump"? 3) One last thing, is there any documentation for augmenting, extending, or editing a function in the interpreter once it is defined? Yes, I'm new. Yes, I've spent the obligatory hours searching the web and use groups. Yes, I'd love to code in Python. Please help. Thank you. From bsk16 at case.edu Thu Jan 29 11:49:41 2009 From: bsk16 at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 11:49:41 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 11:24 AM, Anjanesh Lekshminarayanan < mail at anjanesh.net> wrote: > Im reading a file. But there seems to be some encoding error. > > >>> f = open(filename) > >>> data = f.read() > Traceback (most recent call last): > File "", line 1, in > data = f.read() > File "C:\Python30\lib\io.py", line 1724, in read > decoder.decode(self.buffer.read(), final=True)) > File "C:\Python30\lib\io.py", line 1295, in decode > output = self.decoder.decode(input, final=final) > File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position > 10442: character maps to > > The string at position 10442 is something like this : > "query":"0 1??? \u2021 0\u201a0 \u2021??? "," > > So what encoding value am I supposed to give ? I tried f = > open(filename, encoding="cp1252") but still same error. I guess > Python3 auto-detects it as cp1252 It does auto-detect it as cp1252- look at the files in the traceback and you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong encoding, try opening it as utf-8 or latin1 and see if that fixes it. > -- > Anjanesh Lekshmnarayanan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Thu Jan 29 11:55:13 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 29 Jan 2009 08:55:13 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson > escribi?: > >> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? > > There is a PDF version of "An Introduction to Tkinter" here: > http://www.pythonware.com/library/ > Thanks. I have it but it's an odd one to search on "pack(". There may be over 100 reference to pack(. It's probably explained there somewhere, but how many times do I want to press the search key? I have it printed out too. I guess I need to eyeball it. It's probably faster. Maybe find the section (geometry?) where it and others like it are found. There is an index, but it's a pitiful one page. Found in Chapter 34. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From a at nospam.org Thu Jan 29 11:57:36 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 17:57:36 +0100 Subject: distutil problem ?? Message-ID: Hello, I have the following setup script for py2exe: from distutils.core import setup import py2exe setup(windows=['dpconf.py'], data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] ) When I create the distribution I got the following err msg: *** copy data files *** warning: install_data: setup script did not provide a directory for '' -- installing right in 'C:\pyDPCONF.2.3-dev\dist' error: can't copy '': doesn't exist or not a regular file Looks a little bit inconsistent ? --Armin PS: "." makes also problems From notvalid2 at sbcglobal.net Thu Jan 29 11:59:26 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 29 Jan 2009 08:59:26 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > On Jan 28, 10:57 pm, "W. eWatson" wrote: >> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? > > Only the grid manager is discussed at NMT. I just like how at NMT the > widget attributes are in a table and then a list the widget methods > follows below that -- much better navigation. > > I talked again to John at NMT and he assured me very soon he's going > to make all the updates. It would probably help if you sent him a nice > message of encouragement like -- 'Can you please update the > documentation, i really like the sites layout?' -- but please don't > forget to thank him for all his contributions to the Python community. > > I am currently crusading to have all the old Python tuts and > documentation updated(among other crusades). This was my second win > and i hope that more will follow. The python docs out there need a > dusting off and spit shining. I fully agree with your assessment of their state. I might not want him to update the NMT. :-) Why would that be. I just had it printed. Another $8! I'm kidding, of course. Not only is it a good layout, I think it's the best layout out there, IMHO. I'll contact him. I think one of his other pdf files needs updating too. Possibly the one for PIL. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From mail at timgolden.me.uk Thu Jan 29 12:09:19 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 Jan 2009 17:09:19 +0000 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: <4981E2BF.90001@timgolden.me.uk> Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > import sys > if __name__ == "__main__": > print len(sys.argv) > > It doesn't see the additional arguments for some reason. However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? And perhaps (hopefully) solved it? What does your association look like? Try ftype; should be something like this: H:\>ftype python.file python.file="C:\Python26\python.exe" "%1" %* Notice the stuff at the end TJG From mail at anjanesh.net Thu Jan 29 12:09:29 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 29 Jan 2009 22:39:29 +0530 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Message-ID: <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> > It does auto-detect it as cp1252- look at the files in the traceback and > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > encoding, try opening it as utf-8 or latin1 and see if that fixes it. Thanks a lot ! utf-8 and latin1 were accepted ! From chris.hulan at gmail.com Thu Jan 29 12:11:04 2009 From: chris.hulan at gmail.com (Chris Hulan) Date: Thu, 29 Jan 2009 09:11:04 -0800 (PST) Subject: Weird invisible arguments issues with Windows References: Message-ID: On Jan 29, 11:35?am, Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. ?When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > ? ? import sys > ? ? if __name__ == "__main__": > ? ? ? ? print len(sys.argv) > > It doesn't see the additional arguments for some reason. ?However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? ?And perhaps (hopefully) solved it? Have seen this in some installs on XP. Indicates the registry entry that specfies how to invoke python on a *.py file is not correctly set to pass along the command line arguments on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications \python.exe\shell\open\command has: Name (Default) Type REG_SZ Data C:\Python23\python.exe "%1" %* If that '%*' is missing, thats the problem Cheers Chris From google at mrabarnett.plus.com Thu Jan 29 12:12:41 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jan 2009 17:12:41 +0000 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: <4981E389.6040307@mrabarnett.plus.com> Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > import sys > if __name__ == "__main__": > print len(sys.argv) > > It doesn't see the additional arguments for some reason. However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? And perhaps (hopefully) solved it? > You might want to check that: assoc .py displays: .py=Python.File and: ftype Python.File displays: Python.File="C:\Python26\python.exe" "%1" %* (or something similar). From torriem at gmail.com Thu Jan 29 12:19:25 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 29 Jan 2009 10:19:25 -0700 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <4981E51D.3090908@gmail.com> M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think you're confused as to what object-oriented means. OO defines the internals of a language more than a particular programming paradigm. Obviously python lets you program in a variety of paradigms, including procedural and event-driven, but it is all very much object-oriented. So ignore those that say python doesn't force you to use OOP, when in fact it's unavoidable. It's just that you're not forced to place all your code in class definitions. You don't need to because your code is already object-oriented in that you're manipulating objects and their attributes. As others have said, Python is an object-oriented language through and through, closer to Smalltalk in many ways, the grand-daddy of all OO languages. It appears that you are only really familiar with Java, and that leads to a number of interesting misconceptions about OO. Java's bizarre OO requires everything to be in a class, which leads many people to believe this is what OO should be. In fact Java is a bit odd when it comes to OO, as there are many things in Java that aren't in fact objects. For example, primitives are intrinsic types and are not objects. Furthermore class definitions are not objects either, at least from the programmer's pov. You can't manipulate them by standard means as you can in Smalltalk and Python. In Smalltalk and Python a "class" is an object just as much as an instance of a class is an object which has a constructor factory method that returns instance objects. Java also has very strange ways of doing singleton patterns. You have to wrap singletons in class and define them as "static." I think this was inherited from C++. The most basic object in a python script is the module object which represents the namespace of the current script. In effect a module object is a singleton. It has a few attributes, and you can use it to look up any of the objects it contains, such as functions, objects (so-called variables), classes, etc. Everything in python is an object. The statement: a = 4 defines an integer object "4" and binds a name to it, 'a.' You can even check to see what methods the object supports by doing: >>> dir(4) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] dir(a) would return the same thing. As you can see, all the operators that can be performed with a number object are defined. This little exercise alone should show you how much more object-oriented Python is than Java. Python's OO capabilities are really exposed when you start extending built-in types, or doing meta programming where you dynamically alter classes (and instance objects) on the fly. From bsk16 at case.edu Thu Jan 29 12:21:21 2009 From: bsk16 at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 12:21:21 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan < mail at anjanesh.net> wrote: > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Thanks a lot ! utf-8 and latin1 were accepted ! > -- > If you want to read the file as text, find out which encoding it actually is. In one of those encodings, you'll probably see some nonsense characters. If you are just looking at the file as a sequence of bytes, open the file in binary mode rather than text. That way, you'll avoid this issue all together (just make sure you use byte strings instead of unicode strings). -------------- next part -------------- An HTML attachment was scrubbed... URL: From dg.google.groups at thesamovar.net Thu Jan 29 12:34:52 2009 From: dg.google.groups at thesamovar.net (dg.google.groups at thesamovar.net) Date: Thu, 29 Jan 2009 09:34:52 -0800 (PST) Subject: CUDA Message-ID: <5c4d785e-d24a-47a2-866e-0443abadf6dd@f40g2000pri.googlegroups.com> Hi all, Has anyone managed to get any of the Python CUDA libraries working on Windows using cygwin? Which one, and was anything special required? Thanks in advance for any advice. Dan From skip at pobox.com Thu Jan 29 12:52:05 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 29 Jan 2009 11:52:05 -0600 Subject: Spam making a comeback?? In-Reply-To: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> References: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> Message-ID: <18817.60613.320344.871903@montanaro.dyndns.org> r> Seems like the level of spam is increasing in the last week, and r> today has been bad. How are the spambytes coming along? Spambayes is doing fine, but it only filters spam for the mailing list. It has no effect on the Usenet side of things (comp.lang.python). -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From alan.isaac at gmail.com Thu Jan 29 13:01:17 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 18:01:17 GMT Subject: slicings: 3 questions Message-ID: 1. I seem not to understand something obvious at http://docs.python.org/3.0/reference/expressions.html#slicings (I assume I'm just not reading this right.) What is an example of a slicing using a "slice_list"? 2. It seems that slice objects and range objects are awfully similar in many ways. Is this "appearance only", or was there any discussion of unifying them? Curious for insight... 3. Why are slicings not directly listed among the built-in types? (I know they are discussed here: http://docs.python.org/3.0/reference/datamodel.html#types). What makes them "internal"? http://docs.python.org/3.0/library/stdtypes.html#internal-objects Thanks, Alan Isaac From james at agentultra.com Thu Jan 29 13:02:46 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 29 Jan 2009 13:02:46 -0500 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <858wout2gp.fsf@agentultra.com> excord80 writes: > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? web.py pretty simple. lots of deployment options. ends up building into your own framework as your application grows. From gagsl-py2 at yahoo.com.ar Thu Jan 29 13:14:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 16:14:43 -0200 Subject: Tkinter w.pack()? References: Message-ID: En Thu, 29 Jan 2009 14:55:13 -0200, W. eWatson escribi?: > Gabriel Genellina wrote: >> En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson >> escribi?: >> >>> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? >> There is a PDF version of "An Introduction to Tkinter" here: >> http://www.pythonware.com/library/ >> > Thanks. I have it but it's an odd one to search on "pack(". There may be > over 100 reference to pack(. It's probably explained there somewhere, > but how many times do I want to press the search key? I have it printed > out too. I guess I need to eyeball it. It's probably faster. Maybe find > the section (geometry?) where it and others like it are found. There is > an index, but it's a pitiful one page. Uh? The very first occurence of "pack" is in the Table of Contents, "The pack geometry manager". (You may want to improve your search skills :) ) -- Gabriel Genellina From clp2 at rebertia.com Thu Jan 29 13:37:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 10:37:48 -0800 Subject: slicings: 3 questions In-Reply-To: References: Message-ID: <50697b2c0901291037p58902c62n53d87403e8c3aba2@mail.gmail.com> On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: > 1. I seem not to understand something obvious at > http://docs.python.org/3.0/reference/expressions.html#slicings > (I assume I'm just not reading this right.) > What is an example of a slicing using a "slice_list"? There's nothing in the stdlib that uses it IIRC, but for instance a matrix package could allow you to do: a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s print( a[4,2,6] ) #get an item from the matrix using slice_list syntax print( a[4][2][6] ) #another way to get the same item > 2. It seems that slice objects and range objects are > awfully similar in many ways. Is this "appearance only", > or was there any discussion of unifying them? > Curious for insight... Wouldn't really be possible, IMHO. True, they both have notions of start, stop, and step, but slices don't make sense as ranges without knowing the length of the container. For example, take the slice `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, since -2 < 1 (stop < start ) and 1 (the step) is positive, the range is nonsensical. You have to replace all the negative indices with calculated positive indices first in order to have a sensical range(), in this case, replacing the stop of -2 with len(container)-2. Also, more fundamentally, Python is liberal in what it allows for the parts of slices, so unifying slices with ranges would break code. For example, Python is perfectly happy if I go slice("a",[8],object), none of which are even numbers. > 3. Why are slicings not directly listed among the built-in types? > (I know they are discussed here: > http://docs.python.org/3.0/reference/datamodel.html#types). > What makes them "internal"? > http://docs.python.org/3.0/library/stdtypes.html#internal-objects Because they're generally only useful in the context of slicing lists and other containers, and not as a datatype in and of themselves. Also, the syntax sugar of a[b:c:d] means that you can practically disregard the existence of slice() objects and just think that there's special list-slicing syntax, with very little downside. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From exarkun at divmod.com Thu Jan 29 13:54:26 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 29 Jan 2009 13:54:26 -0500 Subject: persistent TCP connection in python using socketserver In-Reply-To: <1acc7d88-7903-4cf7-8f7f-5824c19dbf63@p2g2000prn.googlegroups.com> Message-ID: <20090129185426.12853.960619914.divmod.quotient.25@henry.divmod.com> On Thu, 29 Jan 2009 08:38:43 -0800 (PST), markobrien85 at gmail.com wrote: >G'day > >I'm currently using socketserver to build a simple XMLSocket (an XML >based protocol used for communication between flash and the outside >world) server. I've got flash establishing a connection, sending a >request and my python server responding. However at this point >socketserver terminates the connection. Which is bad, since i need a >persistent connection so i can push data from the server to the client >without the overhead of polling. If you don't want the connection to close, then don't let the request complete. SocketServer implements logic for single request/response per connection. You can change this by making your requests take a really long time (until you're done with the connection) or you can override the behavior which closes the connection after a response. Or you could use the socket module, on which the SocketServer module is based. Or you could use Twisted, another higher-level package built on the socket module (mostly). Actually, I recommend Twisted, since it will mostly isolate you from boring low-level details and let you implement whatever high-level behavior you're after (I know that a bunch of people have used it to communicate with Flash, for example). Jean-Paul From tjreedy at udel.edu Thu Jan 29 13:58:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 13:58:03 -0500 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece of > code, is it bound to any class? > Those who have time and consideration can help me My take.. Python is a language. Programs written in Python create and manipulate information objects. (But programs are not objects themselves.) So, Python is a language for describing object-based information processing. Every Python object is an instance of some class. Every class, being an object itself, is an instance of some metaclass. (The 'type' metaclass is an instance of itself.) Every class (in Py3) is also a subclasses of the base class 'object'. I think 'object-orient language' is a somewhat misleading abbreviation since 'object-orientedness' is a potential property of the an abstract computation system a language works, with rather than a property of a language itself. Terry Jan Reedy From kay.schluehr at gmx.net Thu Jan 29 14:01:45 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 29 Jan 2009 11:01:45 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <2f14db4c-2f1b-432e-87a2-e80441cf730d@r37g2000prr.googlegroups.com> On 29 Jan., 11:21, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. ? I'd put it more mildly. Python is object oriented. The orientation is there but the fanatism is gone. Kay From tjreedy at udel.edu Thu Jan 29 14:04:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 14:04:06 -0500 Subject: How does one view the source of function defined in the interpreter? In-Reply-To: References: Message-ID: mattc wrote: Once the interpreter reads lines of code, then, as far as the interpreter is concerned, they are gone. > 3) One last thing, is there any documentation for augmenting, > extending, or editing a function in the interpreter once it is > defined? Use IDLE, edit code in an edit window, then run. I generally use the interpreter or IDLE shell window only for single-line commands. From googler.1.webmaster at spamgourmet.com Thu Jan 29 14:04:39 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 11:04:39 -0800 (PST) Subject: ImportError in embedded Python Interpreter Message-ID: Hi, i have a problem. I compiled Python and the socket module so I got this structure. (all on windows) C:\test\dll_files\python25.dll C:\test\my_app C:\test\dll_files\DLLs\ C:\test\dll_files\python.exe If I run python I get the console and I can call "import socket" which succeeds. I wrote a small console app which is stored in C:\test\ and embeddeds the python interpreter. I set the environment variable PATH so the python DLL files can be load. But when I want to import in a script the socket module, it fails. (The interpreter works fine, just importing files in the DLLs folder fail). Why? When I print out the sys.path I get the same like in the real python.exe. What do you think, whats missing? Thanks a lot. bye :) From googler.1.webmaster at spamgourmet.com Thu Jan 29 14:07:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 11:07:01 -0800 (PST) Subject: ImportError in embedded Python Interpreter Message-ID: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Hi, i have a problem. I compiled Python and the socket module so I got this structure. (all on windows) C:\test\dll_files\python25.dll C:\test\my_app C:\test\dll_files\DLLs\ C:\test\dll_files\python.exe If I run python.exe I get the console and I can call "import socket" which succeeds. I wrote a small console app which is stored in C:\test\ and embeddeds the python interpreter. I set the environment variable PATH so the python25.dll can be load. But when I want to import the socket module in a script, it fails. (The interpreter works fine, just importing files in the DLLs folder fail). Why? When I print out the sys.path in my app I get the same like in the real python.exe. What do you think, whats missing? Thanks a lot. bye :) From tjreedy at udel.edu Thu Jan 29 14:07:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 14:07:56 -0500 Subject: Spam making a comeback?? In-Reply-To: <18817.60613.320344.871903@montanaro.dyndns.org> References: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> <18817.60613.320344.871903@montanaro.dyndns.org> Message-ID: skip at pobox.com wrote: > r> Seems like the level of spam is increasing in the last week, and > r> today has been bad. How are the spambytes coming along? > > Spambayes is doing fine, but it only filters spam for the mailing list. It > has no effect on the Usenet side of things (comp.lang.python). It does, however, affect the gmane.comp.lang.python newsgroup, which is very clean now. Thank you. (And items posted through gmane are apparently sent to the mailing list first, and filtered, before being added to the mirror.) tjr From elsjaako at gmail.com Thu Jan 29 14:33:15 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 11:33:15 -0800 (PST) Subject: receive and react to MIDI input Message-ID: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Hi all. I want to write an application that reads midi notes and then does something (specifically, play sound files, but that doesn't really matter for this question). I'm on windows. I went on MSDN and tried to get it to work, and I found myself getting pretty far (considering how little I know about all this), but I finally got stuck. I get en error referring to a Null pointer. What I tried to do is make it run MidiSigReceived every time a signal is received. I will add the processing as soon as I got this step working. I do not have my keyboard plugged in, so my computer should not receive signals. MidiSigReceived is run once though, and only after that does the error occur. What I think the problem is is that midiInID has to be of type HMIDIIN. Somewhere in the relevant .h file, I found: DECLARE_HANDLE(HMIDIIN); DECLARE_HANDLE I couldn't find in the headers, so I looked on the Internet and found: #ifdef STRICT typedef void *HANDLE; #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endif I think this means that the following could be said: typedef void *HANDLE; struct HMIDIIN##__ { int unused; }; typedef struct HMIDIIN##__ *HMIDIIN; but what exactly that means is I think beyond my C abilities. It seems that a HMIDIIN is a pointer to a structure with one element: unnamed. My attempts to figure it out didn't change the error at all. I find it even more confusing considering midiInOpen requires a pointer to such an object. The relevant MSDN page: http://msdn.microsoft.com/en-us/library/ms709430(VS.85).aspx This is what I have: #imports from ctypes import * from ctypes.wintypes import * winmm = windll.LoadLibrary("winmm") #structures and such MAXPNAMELEN = 32 MMVERSION = UINT CALLBACK_FUNCTION = 196608 # hex 30000 class MIDIOUTCAPS (Structure): _fields_ = [("wMid",WORD), ("wPid",WORD), ("vDriverVersion",MMVERSION), ("szPname",WCHAR * MAXPNAMELEN), ("dwSupport",DWORD)] # The next part defines the callback function CMPFUNC = CFUNCTYPE(None, c_long, UINT, DWORD, DWORD, DWORD) def MidiSigReceived(a,b,c,d,e): print a,b,c,d,e midi_get = CMPFUNC(MidiSigReceived) midiInID = c_long() #The ID of the Midi connection, so we can close it again winmm.midiInOpen(byref(midiInID), # reference to the connection ID 0, # Midi device to use midi_get, # callback function 0, # instance data CALLBACK_FUNCTION) # Callback flag, makes it use the callback, change it to 0 to remove error # Close the connection winmm.midiInClose(midiInID) Or, as far as I could understand, you could use the HMIDIIN thing: class MIDIHANDLESTRUCT (Structure): _fields_ = [("unused",c_long)] HMIDIIN = POINTER(MIDIHANDLESTRUCT) midiInID = HMIDIIN() If anyone could help, I would greatly appreciate it. Bart de Waal From alex at a13x.net Thu Jan 29 15:12:44 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Thu, 29 Jan 2009 20:12:44 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> Message-ID: <845b10c50901291212s6add86fahc18530265632cdda@mail.gmail.com> Graham, On Thu, Jan 29, 2009 at 1:00 PM, Graham Dumpleton wrote: > In other words, it is not universal that any code change will be > automatically detected and a reload occur. There are also various > caveats on what mod_python module importer does, as it is reloading > modules into an existing process and not restarting the whole. > If you are not careful, weird things can happen. Considering I'm not changing any of the modules (ie. working only on the source tree in the project itself which is published by mod_python.publisher) I haven't seen the need to restart Apache. There are caveats, of course - but in day-to-day work, I haven't noticed any difficulties and need to fully restart Apache. > It was a general statement. There are various people on different > forums and irc channels who keep saying that a full Apache restart is > required with Apache/mod_wsgi when making code changes. Am just > stating for the record that that isn't true. We agree here. Someone posted a link earlier explaining the settings of mod_wsgi (maybe it was you) where it's easy to configure it to detect code changes and reload the code. Hence my questions from the begining of the thread. There are custom built code-reloading modules (and techniques) which can also be used. > So, depends on how closely you want your development environment to > mirror production so that issues are picked up sooner, rather than > only at the point of deployment to a production system when you are > under pressure. Ideally, you would want the environments to be as closely related (in terms of setup) as possible. In my development, i try to keep the integration environment a mirror of production, but (as mentioned) keep the local (dev) environment as suitable to my needs as possible. Continuous integration system would help in deploying the code to integration for integration testing and final checks before hitting production (which is a manual process). Rushing things into production is never a good think(tm). All it needs is a bit of careful planning, but I'm going way too off-topic here. Regards, alex. -- a lex 13 x http://www.a13x.info From benjamin at python.org Thu Jan 29 15:25:41 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 29 Jan 2009 20:25:41 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan anjanesh.net> writes: > > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Thanks a lot ! utf-8 and latin1 were accepted ! Just so you know, latin-1 can decode any sequence of bytes, so it will always work even if that's not the "real" encoding. From rt8396 at gmail.com Thu Jan 29 15:36:44 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 12:36:44 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Message-ID: <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> On Jan 29, 1:33?pm, elsjaako wrote: There is a Python MIDI module, i think it is pyMIDI, have you checked it out? From alan.isaac at gmail.com Thu Jan 29 15:39:49 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 20:39:49 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: > On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: >> 1. I seem not to understand something obvious at >> http://docs.python.org/3.0/reference/expressions.html#slicings >> (I assume I'm just not reading this right.) >> What is an example of a slicing using a "slice_list"? On 1/29/2009 1:37 PM Chris Rebert apparently wrote: > There's nothing in the stdlib that uses it IIRC, but for instance a > matrix package could allow you to do: > > a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s > print( a[4,2,6] ) #get an item from the matrix using slice_list syntax > print( a[4][2][6] ) #another way to get the same item Ah sure, I was misreading it. It is just enabling NumPy style indexing. I was assuming that it was describing a legitimate way so slice sequences generally. Thanks, Alan From tjandacw at yahoo.com Thu Jan 29 15:58:16 2009 From: tjandacw at yahoo.com (timw.google) Date: Thu, 29 Jan 2009 12:58:16 -0800 (PST) Subject: python 2.6 wininst problem Message-ID: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> I just installed Python2.6 on my WinXP box in a non-standard location (not C:\Python26) since I'm not admin. I used cygwin to create a module of an extension I wrote, but when I went to execute the installer, I get a popup error "This application has failed to start because the application configuration is incorrect. Reinstalling the application my fix this problem." It turns out that the application installs my module on another machine where python is installed in C:\Python26, but why not in my installation? I went and reinstalled python2.5 in a similar nonstandard location (%USERPROFILE%\Python25) and rebuilt my extension module under that. The module installer worked just fine, so it seems to be a 2.6 issue. Do I now have to get the Helpdesk to install Python for me? TIA. From alecla at bluewin.ch Thu Jan 29 16:08:55 2009 From: alecla at bluewin.ch (alex) Date: Thu, 29 Jan 2009 13:08:55 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Message-ID: <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> Duncan Thank you for your explanation of the relationship between calling convention and stack management. I will try to understand better this topic in the CVF and ctypes documentation (not so easy). Regards Alex From sjmachin at lexicon.net Thu Jan 29 16:19:43 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 21:19:43 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Benjamin Kaplan case.edu> writes: > > > On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan anjanesh.net> wrote: > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. Benjamin, "auto-detect" has strong connotations of the open() call (with mode including text and encoding not specified) reading some/all of the file and trying to guess what the encoding might be -- a futile pursuit and not what the docs say: """encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings""" On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It would be interesting to know (1) what is produced on Anjanesh's machine (2) how the default encoding is derived (I would have thought I was a prime candidate for 'cp1252') (3) whether the 'default encoding' of open() is actually the same as the 'default encoding' of sys.getdefaultencoding() -- one would hope so but the docs don't say so. > Thanks a lot ! utf-8 and latin1 were accepted ! Benjamin and Anjanesh, Please understand that any_random_rubbish.decode('latin1') will be "accepted". This is *not* useful information to be greeted with thanks and exclamation marks. It is merely a by-product of the fact that *any* single-byte character set like latin1 that uses all 256 possible bytes can not fail, by definition; no character "maps to ". > If you want to read the file as text, find out which encoding it actually is. In one of those encodings, you'll probably see some nonsense characters. If you are just looking at the file as a sequence of bytes, open the file in binary mode rather than text. That way, you'll avoid this issue all together (just make sure you use byte strings instead of unicode strings). In fact, inspection of Anjanesh's report: """UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to The string at position 10442 is something like this : "query":"0 1?? \u2021 0\u201a0 \u2021??"," """ draws two observations: (1) there is nothing in the reported string that can be unambiguously identified as corresponding to "0x9d" (2) it looks like a small snippet from a Python source file! Anjanesh, Is it a .py file? If so, is there something like "# encoding: cp1252" or "# encoding: utf-8" near the start of the file? *Please* tell us what sys.getdefaultencoding() returns on your machine. Instead of "something like", please report exactly what is there: print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) Cheers, John From martin at v.loewis.de Thu Jan 29 16:25:05 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 29 Jan 2009 22:25:05 +0100 Subject: python 2.6 wininst problem In-Reply-To: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> References: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> Message-ID: <49821EB1.1000503@v.loewis.de> > Do I now have to get the Helpdesk to install Python for me? No, you should wait for Python 2.6.2; this should fix this problem. Regards, Martin From bhood37 at hotmail.com Thu Jan 29 16:31:08 2009 From: bhood37 at hotmail.com (Uberman) Date: Thu, 29 Jan 2009 14:31:08 -0700 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: Tim Golden wrote: > What does your association look like? Try ftype; should be something > like this: > > H:\>ftype python.file > python.file="C:\Python26\python.exe" "%1" %* Then, Chris Hulan wrote: > on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications > \python.exe\shell\open\command > has: > Name (Default) > Type REG_SZ > Data C:\Python23\python.exe "%1" %* > > If that '%*' is missing, thats the problem Finally, MRAB scribed: > You might want to check that: > > assoc .py > > displays: > > .py=Python.File > > and: > > ftype Python.File > > displays: > > Python.File="C:\Python26\python.exe" "%1" %* Thank you for all the replies, guys. :) You all seem to be pointing at the same thing, and on my system, I show: C:\Users\Administrator>ftype python.file python.file="D:\Python26\python.exe" "%1" %* and C:\Users\Administrator>assoc .py .py=Python.File Which all seems to be correct. I'm guessing this doesn't bode well... From alan.isaac at gmail.com Thu Jan 29 16:33:41 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 21:33:41 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: > On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: >> 2. It seems that slice objects and range objects are >> awfully similar in many ways. Is this "appearance only", >> or was there any discussion of unifying them? >> Curious for insight... On 1/29/2009 1:37 PM Chris Rebert apparently wrote: > Wouldn't really be possible, IMHO. True, they both have notions of > start, stop, and step, but slices don't make sense as ranges without > knowing the length of the container. Slices seem somewhat more general than ranges. > For example, take the slice > `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, > since -2 < 1 (stop < start ) and 1 (the step) is positive, the range > is nonsensical. Or rather, it makes sense, but is empty. But I take your point. However, I would turn it around slightly and ask: when is it not the case that range(*slice(start,stop,step).indices(stop)) != range(stop,start,step) If there are no interesting cases, then it seems that range might derive from slice. Just curious... > You have to replace all the negative indices with calculated positive > indices first in order to have a sensical range(), in this case, > replacing the stop of -2 with len(container)-2. > Also, more fundamentally, Python is liberal in what it allows for the > parts of slices, so unifying slices with ranges would break code. For > example, Python is perfectly happy if I go slice("a",[8],object), none > of which are even numbers. Ah, this is new in Python 3 I take it? I was not aware of this. Use case? Thanks! Alan From googler.1.webmaster at spamgourmet.com Thu Jan 29 16:38:21 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 13:38:21 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: <452bfd80-b705-47eb-af57-d6c5cfb6b77e@r36g2000prf.googlegroups.com> Hi! Okay, I checkede Py_Main(...) and called some python code there. There it works too. So I know whats missing. sys.environ.. returns nothing. How can I set the paths with the Python C API? Thanks. From robert.kern at gmail.com Thu Jan 29 16:41:28 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jan 2009 15:41:28 -0600 Subject: slicings: 3 questions In-Reply-To: References: Message-ID: On 2009-01-29 15:33, Alan G Isaac wrote: >> On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac >> wrote: >>> 2. It seems that slice objects and range objects are >>> awfully similar in many ways. Is this "appearance only", >>> or was there any discussion of unifying them? >>> Curious for insight... > > > On 1/29/2009 1:37 PM Chris Rebert apparently wrote: >> Wouldn't really be possible, IMHO. True, they both have notions of >> start, stop, and step, but slices don't make sense as ranges without >> knowing the length of the container. > > Slices seem somewhat more general than ranges. > > >> For example, take the slice >> `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, >> since -2 < 1 (stop < start ) and 1 (the step) is positive, the range >> is nonsensical. > > Or rather, it makes sense, but is empty. > But I take your point. > > However, I would turn it around slightly and ask: > when is it not the case that > range(*slice(start,stop,step).indices(stop)) != range(stop,start,step) > > If there are no interesting cases, then it seems > that range might derive from slice. > Just curious... It's possible that it *could*, but there's also no real benefit to doing so. >> You have to replace all the negative indices with calculated positive >> indices first in order to have a sensical range(), in this case, >> replacing the stop of -2 with len(container)-2. >> Also, more fundamentally, Python is liberal in what it allows for the >> parts of slices, so unifying slices with ranges would break code. For >> example, Python is perfectly happy if I go slice("a",[8],object), none >> of which are even numbers. > > Ah, this is new in Python 3 I take it? No. Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> slice("a",[8],object) slice('a', [8], ) > I was not aware of this. Use case? It allows (ab)uses like numpy.mgrid: >>> mgrid[0:10:11j] array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) -- 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 thudfoo at opensuse.us Thu Jan 29 16:43:36 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Thu, 29 Jan 2009 13:43:36 -0800 Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values In-Reply-To: <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> Message-ID: <3d881a310901291343s7f5ac4d4h546231ab3b8ac368@mail.gmail.com> On Thu, Jan 29, 2009 at 1:08 PM, alex wrote: > Duncan > Thank you for your explanation of the relationship between calling > convention and stack management. > I will try to understand better this topic in the CVF and ctypes > documentation (not so easy). > > Regards Alex > > -- > http://mail.python.org/mailman/listinfo/python-list > fwiw, ctypes has a mailing list: https://lists.sourceforge.net/lists/listinfo/ctypes-users From elsjaako at gmail.com Thu Jan 29 16:44:18 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 13:44:18 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> Message-ID: On Jan 29, 9:36?pm, r wrote: > On Jan 29, 1:33?pm, elsjaako wrote: > > There is a Python MIDI module, i think it is pyMIDI, have you checked > it out? Thank you for the responce. Unfortunately, that package is for OS X (it doesn't say that clearly on the website). But it might indeed be worthwhile to mention that I'd be more than happy to use a library, or a finished product (I asked for that elsewhere, nobody had any good ideas) From grim at asu.ntu-kpi.kiev.ua Thu Jan 29 16:50:07 2009 From: grim at asu.ntu-kpi.kiev.ua (Oleksiy Khilkevich) Date: Thu, 29 Jan 2009 23:50:07 +0200 Subject: Can't understand what python wants from me Message-ID: <4982248F.30505@asu.ntu-kpi.kiev.ua> Hello, everyone, This may be a totally noob question, but since I am one, so here is it. I have the following code (not something much of): http://paste.debian.net/27204 The current code runs well, but the problem is with input value: http://paste.debian.net/27205 ?s you can see, the numbers are ok, but strings and characters cause "not defined" error. I've obviously missing something important, but tutorial says nothing about this. Thank you for your help. From gagsl-py2 at yahoo.com.ar Thu Jan 29 16:51:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 19:51:52 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: En Thu, 29 Jan 2009 05:14:41 -0200, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels >> (I *think* this has to do with free variables in the "right side" (after >> the "in" keyword) of a generator expression; they appear to be evaluated >> when the expression is *defined*, not when is is *used*. By contrast, >> free >> variables in the "left side" appear to be evaluated when the expression >> is >> used.) >> > > Yikes! this is, IMO, far too complicated a way of looking at it. Sure? "Make everything as simple as possible, but not simpler." (att. A. Einstein). I cannot find a simpler way to explain it that is still true... > I think that if you rewrite the "comprehensions" as loops, > you will see what is happening. - in the one case, the locals() > returned is from the outer scope, while in the other the > locals function is called from inside the loop - a different scope, > because there must be *somewhere* where the state is kept to yield > the next value. But a loop doesn't define a new scope (only "def" and "class" used to define one; now generator expressions do too). The new scope is not the issue, but the fact that the right and left parts of a gen.expr. are evaluated at different times. This wasn't obvious to me -- and still isn't. If you rewrite the generator expression as a generator function you don't get the same behaviour: print "genexpr" A = [1,2,3] B = 1 g = (x+B for x in A) A = [4,5,6] B = 10 print list(g) # output: [11,12,13] # A is evaluated at the time g is *defined* # B is evaluated at the time g is *iterated* print "genfunc" A = [1,2,3] B = 1 def f(): for x in A: yield x+B A = [4,5,6] B = 10 g = f() A = [7,8,9] B = 100 print list(g) # output: [107,108,109] # A and B are evaluated at the time g is *iterated* Of course this is clearly stated in the Language Reference "Variables used in the generator expression are evaluated lazily in a separate scope when the next() method is called for the generator object (in the same fashion as for normal generators). However, the in expression of the leftmost for clause is immediately evaluated in the current scope..." -- but this behaviour is still surprising and not obvious to me. ("not obvious" means that things could have been different, choosing this was a design decision). As far as I can tell, this is the only case in Python where parts of the same expression are evaluated in different contexts at different times. > I find it very confusing because locals is always the same > function - but what it returns varies depending on where you > call it from. So if you want to pass it around, it's no good > passing the function - you have to pass the returned result, > *called from the scope of interest*. Subtle stuff. Yep, the fact that locals() returns a different thing depending on when/where you call it, was the initial clue to this issue. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jan 29 16:52:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 19:52:55 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 18:06:01 -0200, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: > >> (I think this has to do with free variables in the "right side" (after >> the "in" keyword) of a generator expression; they appear to be evaluated >> when the expression is *defined*, not when is is *used*. By contrast, >> free >> variables in the "left side" appear to be evaluated when the expression >> is >> used.) > > Indeed, the right side is evaluated in the enclosing namespace and then > passed as an argument to the genexpr: > > >>> dis.dis(compile("(x for y in z)", "nofile", "exec")) > 1 0 LOAD_CONST 0 ( at > 0x2b22b2dcf828, file "nofile", line 1>) > 3 MAKE_FUNCTION 0 > 6 LOAD_NAME 0 (z) > 9 GET_ITER > 10 CALL_FUNCTION 1 > 13 POP_TOP > 14 LOAD_CONST 1 (None) > 17 RETURN_VALUE Yes, this is explained (in not so much detail) in the Language Reference. Now I *know* how it works, but still isn't *obvious* to me. -- Gabriel Genellina From comptekki at gmail.com Thu Jan 29 16:54:34 2009 From: comptekki at gmail.com (Wes James) Date: Thu, 29 Jan 2009 14:54:34 -0700 Subject: parsing text from a file Message-ID: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> If I read a windows registry file with a line like this: "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted Multicast|Edge=FALSE|" with this code: f=open('fwrules.reg2.txt') for s in f: if s.find('LANDesk') <0: print s, LANDesk is not found. Also this does not work: for s in f: try: i=s.index('L') print s[i:i+7] except: pass all it prints is "LAND" how do I find LANDesk in a string like this. is the "\\" messing things up? thx, -wj From benjamin.kaplan at case.edu Thu Jan 29 16:58:38 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 16:58:38 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 4:19 PM, John Machin wrote: > Benjamin Kaplan case.edu> writes: > > > > > > > On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan > anjanesh.net> wrote: > > > It does auto-detect it as cp1252- look at the files in the traceback > and > > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Benjamin, "auto-detect" has strong connotations of the open() call (with > mode > including text and encoding not specified) reading some/all of the file and > trying to guess what the encoding might be -- a futile pursuit and not what > the > docs say: > > """encoding is the name of the encoding used to decode or encode the file. > This > should only be used in text mode. The default encoding is platform > dependent, > but any encoding supported by Python can be passed. See the codecs module > for > the list of supported encodings""" > > On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It > would be interesting to know > (1) what is produced on Anjanesh's machine > (2) how the default encoding is derived (I would have thought I was a prime > candidate for 'cp1252') > (3) whether the 'default encoding' of open() is actually the same as the > 'default encoding' of sys.getdefaultencoding() -- one would hope so but the > docs > don't say so. First of all, you're right that might be confusing. I was thinking of auto-detect as in "check the platform and locale and guess what they usually use". I wasn't thinking of it like the web browsers use it. I think it uses locale.getpreferredencoding(). On my machine, I get sys.getpreferredencoding() == 'utf-8' and locale.getdefaultencoding()== 'cp1252'. When I open a file without specifying the encoding, it's cp1252. > > > Thanks a lot ! utf-8 and latin1 were accepted ! > > Benjamin and Anjanesh, Please understand that > any_random_rubbish.decode('latin1') will be "accepted". This is *not* > useful > information to be greeted with thanks and exclamation marks. It is merely a > by-product of the fact that *any* single-byte character set like latin1 > that > uses all 256 possible bytes can not fail, by definition; no character "maps > to > ". If you check my response to Anjanesh's comment, I mentioned that he should either find out which encoding it is in particular or he should open the file in binary mode. I suggested utf-8 and latin1 because those are the most likely candidates for his file since cp1252 was already excluded. Looking at a character map, 0x9d is a control character in latin1, so the page is probably UTF-8 encoded. Thinking about it now, it could also be MacRoman but that isn't as common as UTF-8. > > > If you want to read the file as text, find out which encoding it actually > is. > In one of those encodings, you'll probably see some nonsense characters. If > you > are just looking at the file as a sequence of bytes, open the file in > binary > mode rather than text. That way, you'll avoid this issue all together (just > make > sure you use byte strings instead of unicode strings). > > In fact, inspection of Anjanesh's report: > """UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position > 10442: character maps to > The string at position 10442 is something like this : > "query":"0 1?? \u2021 0\u201a0 \u2021??"," """ > > draws two observations: > (1) there is nothing in the reported string that can be unambiguously > identified > as corresponding to "0x9d" > (2) it looks like a small snippet from a Python source file! > > Anjanesh, Is it a .py file? If so, is there something like "# encoding: > cp1252" > or "# encoding: utf-8" near the start of the file? *Please* tell us what > sys.getdefaultencoding() returns on your machine. > > Instead of "something like", please report exactly what is there: > > print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) > > Cheers, > John > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Thu Jan 29 17:02:53 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 14:02:53 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype Message-ID: I'm trying to make a script environment with datatypes (or classes) for accessing hardware registers. At the top level, I would like the ability to bitwise ops if bit slice brackets are used, but if no brackets are used, I would like it to write/read the whole value. For example, if I have something like: >>> shadow_register = MyRegClass(0xAA) >>> shadow_register 170 >>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>> shadow_register 58 >>> shadow_register = 0x89 >>> shadow_register 137 >>> shadow_register[4:1] 4 I have the bitslice part working. But of course as expected, if I type >>> shadow_register <__main__.boo object at 0x00A130D0> I wanted to avoid having something like shadow_register.value just because it's clumsier. I read about the __new__() class for overriding the classtype, like: print 'foo' class foo(object): def __new__(*args): return 0 but if I stick in a __init__(self, val): method, then it chokes saying val is a global name that's not defined. Now I know that I have to live with the fact that I can't have >>> shadow_register = 0x89 Because it will get reassigned from my class value to a newly intialized memory location (int object). But can I have it read the value without the .value extension? Is this even possible? Maybe there's a way to override the = operator? (Go easy on me - I'm a hardware guy). Thx, Mark From bignose+hates-spam at benfinney.id.au Thu Jan 29 17:03:20 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 30 Jan 2009 09:03:20 +1100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <873af1vkgn.fsf@benfinney.id.au> MC writes: > Hi! > > Il se trouve que Chris Rebert a formul? : > > Python has functions, which are not associated with a class > > functions are methods of builtin... No, because ?builtin? is not a class. -- \ ?The shortest distance between two points is under | `\ construction.? ?Noelie Alito | _o__) | Ben Finney From vlastimil.brom at gmail.com Thu Jan 29 17:08:11 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 29 Jan 2009 23:08:11 +0100 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> 2009/1/29 Wes James : > If I read a windows registry file with a line like this: > ... > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > if s.find('LANDesk') <0: > print s, > > > LANDesk is not found. > > how do I find LANDesk in a string like this. is the "\\" messing things up? ... > > thx, > > -wj > Hi, if s.find('LANDesk') <0: is True for a line which doesn't contain "LANDesk"; if you want the opposite, try if s.find('LANDesk') >-1: hth vbr From rtw at freenet.co.uk Thu Jan 29 17:10:03 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 29 Jan 2009 16:10:03 -0600 Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: Kottiyath wrote in news:d86a0c1d-e158-4aa1-a47f-e2149948bdc3 @p2g2000prf.googlegroups.com in comp.lang.python: > On Jan 29, 1:51?am, Rob Williscroft wrote: >> Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 >> @b38g2000prf.googlegroups.com in comp.lang.python: >> >> > I have mingw32-gcc in my path. If I try that too -it fails. >> >> > C:\Documents and Settings\Guest\pyAA>python setup.py install -c >> > "mingw32-gcc" >> > invalid command name 'mingw32-gcc' >> >> All the examples I found via google have the tool name as "mingw32" >> so try: >> >> ? ? ? ? python setup.py install -c mingw32 > Thank you Rob. > The installation went ahead for some more time - but failed showing a > lot of errors: >>compile > running build > running build_py > file pyAAc.py (for module pyAAc) not found > file pyAAc.py (for module pyAAc) not found > ... > pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in > this scope > pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared > in this scope > pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not > declared in this scope > ... > error: command 'gcc' failed with exit status 1 > > I cannot understand why it fails. I have not worked in C till now, so > I am pretty confused. > I googled also, but to no avail. > Looks like the package needs some headers that haven't yet been ported to to MinGW. Alas that meands you'll need to build with the Microsoft SDK and compiler. You can get the SDK including a non-optimising compiler from: http://www.microsoft.com/downloads/details.aspx?FamilyId=9B3A2CA6-3647- 4070-9F41-A333C6B9181D&displaylang=en or maybe here: http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656- 4969-ACE8-E4C0C0716ADB&displaylang=en Rob. -- http://www.victim-prime.dsl.pipex.com/ From roman.yakovenko at gmail.com Thu Jan 29 17:12:11 2009 From: roman.yakovenko at gmail.com (Roman) Date: Thu, 29 Jan 2009 14:12:11 -0800 (PST) Subject: pygccxml xml output file References: Message-ID: <3d5ad16f-babb-446c-999c-ee21113fc51f@t39g2000prh.googlegroups.com> On Jan 24, 3:25?pm, whatazor wrote: > Hi all, > I start to use this module in order to produce xml( and the make other > things), but differently from gccxml I don't find the variable that > set the name of the xml output file after the parsing (in gccxml is - > fxml), so it creates temporary files. > how can I do an Is there a tutorial that explain with dectails how it > works? I suggest you to ask your questions on the following mailing list: https://lists.sourceforge.net/lists/listinfo/pygccxml-development As for your question: see http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader-module.html#create_cached_source_fc documentation. and http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader.project_reader_t-class.html#read_files HTH From clp2 at rebertia.com Thu Jan 29 17:25:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 14:25:54 -0800 Subject: Can't understand what python wants from me In-Reply-To: <4982248F.30505@asu.ntu-kpi.kiev.ua> References: <4982248F.30505@asu.ntu-kpi.kiev.ua> Message-ID: <50697b2c0901291425v1f2df55fsba8ca691e9b970f@mail.gmail.com> On Thu, Jan 29, 2009 at 1:50 PM, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. > > I have the following code (not something much of): > http://paste.debian.net/27204 > The current code runs well, but the problem is with input value: > http://paste.debian.net/27205 > ?s you can see, the numbers are ok, but strings and characters cause "not > defined" error. > > I've obviously missing something important, but tutorial says nothing about > this. You're using input(). You should be using raw_input(), at least until everyone switches to Python 3.0 (which confusingly renames raw_input() to input() because of the exact newbie confusion you're encountering). raw_input() reads a string from stdin. input() call raw_input() and then eval()-s the string, hence 'asd' gets interpreted as a variable, which doesn't exist in your program, hence the error. For further information, use help() on input and raw_input from the interactive interpreter REPL. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From chris.hulan at gmail.com Thu Jan 29 17:32:16 2009 From: chris.hulan at gmail.com (Chris Hulan) Date: Thu, 29 Jan 2009 14:32:16 -0800 (PST) Subject: Can't understand what python wants from me References: Message-ID: <805c9fd1-2e09-4f92-9c74-6e6f26f8d72b@t3g2000yqa.googlegroups.com> On Jan 29, 4:50?pm, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. > > I have the following code (not something much of):http://paste.debian.net/27204 > The current code runs well, but the problem is with input value:http://paste.debian.net/27205 > ?s you can see, the numbers are ok, but strings and characters cause > "not defined" error. > > I've obviously missing something important, but tutorial says nothing > about this. > > Thank you for your help. You want raw_input() input() expects the string enterd to be Python code, which it evals() numbers eval to thenmselves cheers From mark.seagoe at gmail.com Thu Jan 29 17:33:20 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 14:33:20 -0800 (PST) Subject: Can't understand what python wants from me References: Message-ID: On Jan 29, 1:50?pm, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. For the input function, python is expecting you to input a number or a string. If you enter 'asd' without the '' then it thinks you are entering some variable that you've assigned to asd. Instead of asd, try to enter 'asd'. From sjmachin at lexicon.net Thu Jan 29 17:34:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 14:34:36 -0800 (PST) Subject: parsing text from a file References: Message-ID: On Jan 30, 8:54?am, Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > ? if s.find('LANDesk') <0: > ? ? print s, > > LANDesk is not found. You mean it's not printed. That code prints all lines that don't contain "LANDesk" > > Also this does not work: > > for s in f: > ? try: > ? ? i=s.index('L') > ? ? print s[i:i+7] > ?except: Using "except ValueError:" would be safer. > ? ?pass > > all it prints is "LAND" AFAICT your reported outcome is impossible given that such a line exists in the file. > > how do I find LANDesk in a string like this. What you were trying (second time, or first time (with >=) should work. I suggest that to diagnose your problem you change the second snippet as follows: 1. use except ValueError: 2. print s, len(s), i, and s.find('L') for all lines > ?is the "\\" messing things up? Each "\\" is presumably just the repr() of a single backslash. In any case whether there are 0,1,2 or many backslashes in a line or the repr () thereof has nothing to do with your problem. HTH, John From python.list at tim.thechases.com Thu Jan 29 17:36:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 16:36:34 -0600 Subject: parsing text from a file In-Reply-To: <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> Message-ID: <49822F72.80209@tim.thechases.com> > if s.find('LANDesk') <0: > is True for a line which doesn't contain "LANDesk"; if you want the > opposite, try > if s.find('LANDesk') >-1: Or more pythonically, just use if 'LANDesk' in s: -tkc From sjmachin at lexicon.net Thu Jan 29 17:51:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 14:51:40 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: Message-ID: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> On Jan 30, 9:02?am, mark.sea... at gmail.com wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. ?At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>> shadow_register = MyRegClass(0xAA) > >>> shadow_register > 170 > >>> shadow_register[7:4] = 3 ?# <== changes value to 0x3A > >>> shadow_register > 58 > >>> shadow_register = 0x89 > >>> shadow_register > 137 > >>> shadow_register[4:1] > > 4 > > I have the bitslice part working. ?But of course as expected, if I > type>>> shadow_register > > <__main__.boo object at 0x00A130D0> def __str__(self): return "d" % self.value From elsjaako at gmail.com Thu Jan 29 17:53:10 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 14:53:10 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Message-ID: <325e699e-993a-4dcf-a86a-24c754d8c78d@k1g2000prb.googlegroups.com> On Jan 29, 8:33?pm, elsjaako wrote: > I think this means that the following could be said: > > typedef void *HANDLE; > struct HMIDIIN##__ { int unused; }; typedef struct HMIDIIN##__ > *HMIDIIN; > I figured this problem out (I'm sure there will be more...): A handle should just be a c_void_p ... From rNOSPAMon at flownet.com Thu Jan 29 17:53:24 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 14:53:24 -0800 Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> Message-ID: In article <498171a5$0$3681$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > Ron Garret a ?crit : > > In article , > > Aleksandar Radulovic wrote: > (snip) > >> Secondly, why are you restarting apache after code changes? In normal > >> circumstances, you shouldn't have to do that. > > > > I thought (and experiment confirms) that only the main WSGI app file > > gets reloaded automatically when it changes, not the libraries. > > Depends on how you configure mod_wsgi. Read the part about "Process > Reloading Mechanism" here: > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode I'm running Debian Etch, which means I have an older version of mod_wsgi, which means I don't have the process reloading mechanism. rg From rNOSPAMon at flownet.com Thu Jan 29 17:54:33 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 14:54:33 -0800 Subject: Sloooooowwwww WSGI restart References: <498170d4$0$23718$426a74cc@news.free.fr> Message-ID: In article <498170d4$0$23718$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > Ron Garret a ?crit : > > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > > whenever I restart the server after making a code change it takes a very > > long time (like a minute) before the script is active again. In other > > words, I do an apachectl restart, reload the page in my browser, and one > > minute later it finally comes up. During this time CPU usage is > > essentially zero. Loading all the code manually into a python > > interpreter is virtually instantaneous, and all subsequence interactions > > with the app are very fast. > > > > Does anyone have any ideas what might be going on or how to debug this? > > Restarting apache (with or without mod_wsgi) can by itself take some time. > > Now, if you're running mod_wsgi in daemon mode, you _don't_ have to > restart apache to reload your code - just touch the wsgi script file and > you'll be done, ie with: > > > WSGIProcessGroup myproject.tld > WSGIDaemonProcess myproject.tld user=you group=you > WSGIReloadMechanism Process > WSGIScriptAlias / /var/www/myproject/apache/myapp.py > > > you just have to touch myapp.py to force reload the subinterpreter(s). Unfortunately, I'm running Debian Etch, which has an older mod_wsgi, which does not have the process reloading mechanism. But I guess if this gets too painful I'll upgrade. rg From stef.mientki at gmail.com Thu Jan 29 17:55:05 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 29 Jan 2009 23:55:05 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: Message-ID: <498233C9.1080906@gmail.com> mark.seagoe at gmail.com wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>>> shadow_register = MyRegClass(0xAA) >>>> shadow_register >>>> > 170 > >>>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>>> shadow_register >>>> > 58 > >>>> shadow_register = 0x89 >>>> shadow_register >>>> > 137 > >>>> shadow_register[4:1] >>>> > 4 > > I have the bitslice part working. But of course as expected, if I > type > >>>> shadow_register >>>> > <__main__.boo object at 0x00A130D0> > > I wanted to avoid having something like shadow_register.value just > because it's clumsier. I read about the __new__() class for > overriding the classtype, like: > > print 'foo' > class foo(object): > def __new__(*args): return 0 > > but if I stick in a __init__(self, val): method, then it chokes saying > val is a global name that's not defined. > > Now I know that I have to live with the fact that I can't have > >>>> shadow_register = 0x89 >>>> > Because it will get reassigned from my class value to a newly > intialized memory location (int object). But can I have it read the > value without the .value extension? Is this even possible? Maybe > there's a way to override the = operator? (Go easy on me - I'm a > hardware guy). > > Interesting what you're doing. I've struggled with the same issues, simulating a pic, never really solved them. Maybe this is what you're looking for: class MyRegClass ( object ) : def __init__ ( self, value ) : self.Value = value def __repr__ ( self ) : line = hex ( self.Value ) line = line [:2] + line [2:].upper() return line btw, I'm a hardware guy too, and therefor I've never understood why the hex function returns lowercase ;-) cheers, Stef From rNOSPAMon at flownet.com Thu Jan 29 18:01:07 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 15:01:07 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect Message-ID: I'm running mod_wsgi under apache (on Debian etch so it's a somewhat out of date version, though I doubt that has anything to do with this issue). I have a little test page that displays the process ID under which my app is running, and some global state, so I can tell when the wsgi app gets reloaded. This mostly only happens when I restart apache, but it also seems to happen when my WSGI app does an HTTP 302 redirect. (I'm actually using Yaro and calling req.redirect, but that only does a straightforward HTTP 302 redirect as far as I can tell.) It not only resets the global state, but changes process ID, so it seems to be doing a complete restart of mod_wsgi, which seems a little excessive. My question is: is this supposed to be happening? Or is this an indication that something is wrong, and if so, what? Thanks, rg From sjmachin at lexicon.net Thu Jan 29 18:01:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 15:01:21 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: Message-ID: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> On Jan 30, 9:55?am, Stef Mientki wrote: > ? def __repr__ ( self ) : > ? ? line = hex ( self.Value ) > ? ? line = line [:2] + line [2:].upper() > ? ? return line > > btw, I'm a hardware guy too, and therefor I've never understood why the > hex function returns lowercase ;-) 0xFF?? *Real* hardware guys prefer FFh or 377 :-) From mark.seagoe at gmail.com Thu Jan 29 18:09:31 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 15:09:31 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: Thanks. So far these solutions will return strings. So I can't really treat it like a variable, yet still perform bitslice on it, since I need a special class to do bitslice and bit selection, but as soon as I try to pass it into some other function to check a bit, I gotta then do another operation to convert back to a variable. So I can get it to a point where I can do shadow_register[3] and get the value of any bit, or I can do shadow_register[4:2] and get a bitslice, and I can write them just as easily at this point. If I add the __new__ method into the class, the instance obj becomes int, but is no longer slicable. I think it looks like I can't have it both ways. From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:12:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:12:35 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: > I have frozen a running application which is using SQLite with py2exe. > When I start the exe file I see in the log file of the exe: > Traceback (most recent call last): > File "dpconf.py", line 666, in ? > File "dpconf.py", line 251, in __init__ > File "sqlite\main.pyc", line 255, in execute > _sqlite.DatabaseError: no such table: genslaveopt > > The table exist in the database file ... no problem with the plain > python version. Did you solve this problem? As you posted 4 related messages and the last one might imply a solution to this first one... -- Gabriel Genellina From stef.mientki at gmail.com Thu Jan 29 18:13:16 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 00:13:16 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <4982380C.8050300@gmail.com> mark.seagoe at gmail.com wrote: > Thanks. So far these solutions will return strings. So I can't > really treat it like a variable, yet still perform bitslice on it, > since I need a special class to do bitslice and bit selection, but as > soon as I try to pass it into some other function to check a bit, I > gotta then do another operation to convert back to a variable. > > So I can get it to a point where I can do shadow_register[3] and get > the value of any bit, or I can do shadow_register[4:2] and get a > bitslice, and I can write them just as easily at this point. If I add > the __new__ method into the class, the instance obj becomes int, but > is no longer slicable. I think it looks like I can't have it both > ways. > -- > http://mail.python.org/mailman/listinfo/python-list > there are a few vhdl projects, can't find my links right now - myhdl - something like pysystemC maybe you can find the answer there cheers, Stef From stef.mientki at gmail.com Thu Jan 29 18:25:03 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 00:25:03 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <49823ACF.30703@gmail.com> mark.seagoe at gmail.com wrote: > Thanks. So far these solutions will return strings. So I can't > really treat it like a variable, yet still perform bitslice on it, > since I need a special class to do bitslice and bit selection, but as > soon as I try to pass it into some other function to check a bit, I > gotta then do another operation to convert back to a variable. > > So I can get it to a point where I can do shadow_register[3] and get > the value of any bit, or I can do shadow_register[4:2] and get a > bitslice, and I can write them just as easily at this point. If I add > the __new__ method into the class, the instance obj becomes int, but > is no longer slicable. I think it looks like I can't have it both > ways. > -- > http://mail.python.org/mailman/listinfo/python-list > try this: class MyRegClass ( int ) : def __init__ ( self, value ) : self.Value = value def __repr__ ( self ) : line = hex ( self.Value ) line = line [:2] + line [2:].upper() return line __str__ = __repr__ cheers, Stef From elsjaako at gmail.com Thu Jan 29 18:26:30 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 15:26:30 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> Message-ID: <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> On Jan 29, 10:44?pm, elsjaako wrote: > On Jan 29, 9:36?pm, r wrote: > > > On Jan 29, 1:33?pm, elsjaako wrote: > > > There is a Python MIDI module, i think it is pyMIDI, have you checked > > it out? > > Thank you for the responce. Unfortunately, that package is for OS X > (it doesn't say that clearly on the website). But it might indeed be > worthwhile to mention that I'd be more than happy to use a library, or > a finished product (I asked for that elsewhere, nobody had any good > ideas) Never mind. I was wrong. It still doesnt work. Just managed to get a normal error instead of WindowsError: exception: access violation reading 0x00000000 From BrianVanderburg2 at aim.com Thu Jan 29 18:36:19 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 18:36:19 -0500 Subject: Understanding descriptors Message-ID: <49823D73.70304@aim.com> I'm trying to better understand descriptors and I've got a few questions still after reading some sites. Here is what I 'think', but please let me know if any of this is wrong as I'm sure it probably is. First when accessing an attribute on a class or instance it must be found. For an instance, it's __dict__ is first search. If not found the class and base class __dict__ are searched. For a class, the __dict__ and base classes __dict__ are search. If assigning, and the attribute is found and is not a descriptor or if the attribute is not found, then the assignment will occur in the __dict__ of the class or instance. If it is found and is a descriptor, then __set__ will be call. For reading, if the attribute is found and is a descriptor, __get__ will be called, passing the object (if it is an instance) and class. If it is not a descriptor, the attribute will be returned directly. Class methods are just functions: class C(object): def F(self): pass C.__dict__['F'] # function object ... But functions are descriptors: C.__dict__['F'].__get__ # method wrapper ... def f1(): pass f1.__get__ # method wrapper ... When a lookup is done it uses this descriptor to make a bound or unbound method: c=C() C.F # unbound method object, expects explicit instance when calling the function c.F # bound method object provides instance implicitly when calling the function This is also done when adding to the classes: C.f1 = f1 f1 # function C.f1 # unbound method c.f1 # bound method To prevent this it has to be decorated so the descriptor doesn't cause the binding: C.f2 = staticmethod(f1) C.f2 # functon c.f2 # function Here is a question, why don't instance attributes do the same thing? c.f3 = f1 c.f3 # function, not bound method So it is not calling the __get__ method for c.f3 After it finds c.f3 in c.__dict__, and since it has a getter, shouldn't it call the __get__ to return the bound method. It is good that it doesn't I know, but I just want to know why it doesn't from an implementation view. Brian Vanderburg II From rhodri at wildebst.demon.co.uk Thu Jan 29 18:36:51 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 29 Jan 2009 23:36:51 -0000 Subject: Exec woes In-Reply-To: <01d601c981f5$e721ea60$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> <015d01c9811c$c6042e80$0d00a8c0@hendrik> <01d601c981f5$e721ea60$0d00a8c0@hendrik> Message-ID: On Thu, 29 Jan 2009 08:15:57 -0000, Hendrik van Rooyen wrote: > "Rhodri James" wrote: > To: > Sent: Thursday, January 29, 2009 6:12 AM > Subject: Re: Exec woes > > >> On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen >> wrote: > >> > This is actually not correct - it is the root cause of my trouble. >> > if you write, in a nested scope: >> > >> > exec ( "somestring to execute" in globals(),locals()) >> > >> > You get the syntax error, as the interpreter somehow sees it as one, >> > unqualified thing. >> >> Well, no. Look at the error Python gives you, nested scope or not: >> >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: exec: arg 1 must be a string, file, or code object >> >> If exec is a function, arg 1 is the boolean expression >> "somestring to execute" in globals() >> which is unlikely to be what you want. If exec is a statement, >> arg 1 is a tuple of two elements, >> "somestring to execute" in globals() >> and >> locals() >> which is also unlikely to be what you want. Neither of these are >> giving you a string, file or code object, exactly as the interpreter >> is telling you. > > Well, no - I stick by my assertion, about the nested scope: > >>>> def rubbish(): > def deep_rubbish(): > exec('BUILD = "somestring"' in globals(),locals()) > > SyntaxError: unqualified exec is not allowed in function 'deep_rubbish' > it is a > nested function (, line 3) >>>> > > That is all I was saying - It was the brackets that buggered me, > and adding the globals() and locals() inside the brackets, inside > the nested scope, makes no difference - the interpreter sees it > as an unqualified exec. Correct. In the language of the previous error message, the tuple ('BUILD = "something"' in globals(), locals()) is still the first argument. > Did you actually try it in a nested scope before asserting > "nested scope or not" ? Sorry, I assumed that you'd noticed that they were complaining about the same thing. > If you just do, in the outside scope, the thing I did originally: > >>>> exec('BUILD = "foobar"') >>>> BUILD > 'foobar' >>>> > > Then the brackets are ignored, and the defaults kick in. There are no commas, so the brackets are just fulfilling their usual roll of overriding operator precedence. Nothing strange there. There really is nothing unusual at all going on here. Please don't get the idea that brackets do anything unusual with an exec, or any other Python statement for that matter. -- Rhodri James *-* Wildebeeste Herder to the Masses From joshua at joshuakugler.com Thu Jan 29 18:43:18 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Thu, 29 Jan 2009 14:43:18 -0900 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: Ron Garret wrote: > My question is: is this supposed to be happening? Or is this an > indication that something is wrong, and if so, what? You are probably just hitting a different instance of Apache, thus the different process ID. j From rNOSPAMon at flownet.com Thu Jan 29 18:43:49 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 15:43:49 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: In article , Ron Garret wrote: > I'm running mod_wsgi under apache (on Debian etch so it's a somewhat out > of date version, though I doubt that has anything to do with this issue). > > I have a little test page that displays the process ID under which my > app is running, and some global state, so I can tell when the wsgi app > gets reloaded. This mostly only happens when I restart apache, but it > also seems to happen when my WSGI app does an HTTP 302 redirect. (I'm > actually using Yaro and calling req.redirect, but that only does a > straightforward HTTP 302 redirect as far as I can tell.) It not only > resets the global state, but changes process ID, so it seems to be doing > a complete restart of mod_wsgi, which seems a little excessive. > > My question is: is this supposed to be happening? Or is this an > indication that something is wrong, and if so, what? > > Thanks, > rg Here's a standalone WSGI app demonstrating the phenomenon: def redirect_test(env, start): if env['PATH_INFO']: start('302 Found', [('Location', '/')]) return ['Redirecting'] else: start('200 OK', [('Content-type', 'text/plain')]) return ['PID', str(os.getpid())] pass application = redirect_test Fire this up under mod_wsgi and observe that the process ID stays the same when you reload the app. Now add a path component to trigger the redirect and observe that process ID changes. rg From elsjaako at gmail.com Thu Jan 29 18:46:27 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 15:46:27 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> Message-ID: <9f5a0a78-2f5d-4b6c-8f17-8cf5825f500e@w39g2000prb.googlegroups.com> On Jan 30, 12:26?am, elsjaako wrote: > On Jan 29, 10:44?pm, elsjaako wrote: > > > On Jan 29, 9:36?pm, r wrote: > > > > On Jan 29, 1:33?pm, elsjaako wrote: > > > > There is a Python MIDI module, i think it is pyMIDI, have you checked > > > it out? > > > Thank you for the responce. Unfortunately, that package is for OS X > > (it doesn't say that clearly on the website). But it might indeed be > > worthwhile to mention that I'd be more than happy to use a library, or > > a finished product (I asked for that elsewhere, nobody had any good > > ideas) > > Never mind. I was wrong. It still doesnt work. Just managed to get a > normal error instead of WindowsError: exception: access violation > reading 0x00000000 Finally got it to work! I will soon packige it and publish it somewhere, so that the next person doesn't have to get frustrated (hint: use WINCFUNCTYPE) From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:47:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:47:20 -0200 Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 14:04:49 -0200, Alejandro escribi?: > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. > > In each of the threads I have > > def run(self): > pid = os.getpid() > logger.critical('process ID: %s', pid) > > However, the reported PID is the father number, not the PID of the new > thread. Is there a way to get the PID of the thread? Using "pid" for a thread identifier is confusing; I'd call it tid instead. (getpid() used to return a thread id in old Linux kernels, but that was a mess). Try using Thread.ident (requires Python 2.6). I'd expect it to return gettid() but I've not checked it; from the docs, it might be a synthesized number as well. In case it doesn't work, you can use ctypes to perform a gettid syscall. -- Gabriel Genellina From mark.seagoe at gmail.com Thu Jan 29 18:49:26 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 15:49:26 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <7cbee529-10d9-4c46-b683-8c46c4e3a09b@t39g2000prh.googlegroups.com> On Jan 29, 3:13?pm, Stef Mientki wrote: > mark.sea... at gmail.com wrote: > > Thanks. ?So far these solutions will return strings. ?So I can't > > really treat it like a variable, yet still perform bitslice on it, > > since I need a special class to do bitslice and bit selection, but as > > soon as I try to pass it into some other function to check a bit, I > > gotta then do another operation to convert back to a variable. > > > So I can get it to a point where I can do shadow_register[3] and get > > the value of any bit, or I can do shadow_register[4:2] and get a > > bitslice, and I can write them just as easily at this point. ?If I add > > the __new__ method into the class, the instance obj becomes int, but > > is no longer slicable. ?I think it looks like I can't have it both > > ways. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > there are a few vhdl projects, > can't find my links right now > - myhdl > - something like pysystemC > > maybe you can find the answer there > > cheers, > Stef- Hide quoted text - > > - Show quoted text - Thanks, Stef - I'll check them out. I have a feeling they are going through a preprocessing stage (ie. won't take command in a pure python window) but it's worth checking out. From google at mrabarnett.plus.com Thu Jan 29 18:50:08 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jan 2009 23:50:08 +0000 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <498240B0.3070608@mrabarnett.plus.com> Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > if s.find('LANDesk') <0: > print s, > > > LANDesk is not found. > > Also this does not work: > > for s in f: > try: > i=s.index('L') > print s[i:i+7] > except: > pass > > all it prints is "LAND" > > how do I find LANDesk in a string like this. is the "\\" messing things up? > How do you know what's in the file? Did you use an editor? It might be that the file contents are encoded in, say, UTF-16 and the editor is detecting that and decoding it for you, but Python's open() function is just returning the contents as a bytestring (Python 2.x). Try: import codecs f = codecs.open('fwrules.reg2.txt', encoding='UTF-16') for s in f: if u'LANDesk' in s: print s, f.close() From anders.u.persson at gmail.com Thu Jan 29 18:51:19 2009 From: anders.u.persson at gmail.com (anders) Date: Thu, 29 Jan 2009 15:51:19 -0800 (PST) Subject: search speed Message-ID: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Hi! I have written a Python program that serach for specifik customer in files (around 1000 files) the trigger is LF01 + CUSTOMERNO So a read all fils with dirchached Then a loop thru all files each files is read with readLines() and after that scaned Today this works fine, it saves me a lot of manuall work, but a seach takes around 5 min, so my questin is is there another way of search in a file (Today i step line for line and check) What i like to find is just filenames for files with the customerdata in, there can and often is more than one, English is not my first language and i hope someone understand my beginner question what i am looking for is somting like if file.findInFile("LF01"): ....... Is there any library like this ?? Best Regards Anders From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:57:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:57:14 -0200 Subject: Weird invisible arguments issues with Windows References: Message-ID: En Thu, 29 Jan 2009 19:31:08 -0200, Uberman escribi?: > You all seem to be pointing at the same thing, and on my system, I show: > > C:\Users\Administrator>ftype python.file > python.file="D:\Python26\python.exe" "%1" %* > > and > > C:\Users\Administrator>assoc .py > .py=Python.File > > Which all seems to be correct. I'm guessing this doesn't bode well... Note that file association is a per-user setting; does it fail using the same user as above (Administrator)? -- Gabriel Genellina From rNOSPAMon at flownet.com Thu Jan 29 19:01:40 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 16:01:40 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: In article , Joshua Kugler wrote: > Ron Garret wrote: > > My question is: is this supposed to be happening? Or is this an > > indication that something is wrong, and if so, what? > > You are probably just hitting a different instance of Apache, thus the > different process ID. Yep, that's what it turned out to be. I thought I had a WSGIDaemonProcess processes=1 directive in my config, but I had it in the wrong place (a different vhost) so it wasn't actually active. But that leaves me wondering why the redirect would reliably trigger switching processes. The reason I thought that I had the correct configuration and only had one process is that when I reloaded the non-redirected page I *always* got the same process ID. How does mod_wsgi decide which process (and which thread for that matter) to use? rg From google at mrabarnett.plus.com Thu Jan 29 19:04:52 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 00:04:52 +0000 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> References: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> Message-ID: <49824424.1080106@mrabarnett.plus.com> John Machin wrote: > On Jan 30, 9:02 am, mark.sea... at gmail.com wrote: >> I'm trying to make a script environment with datatypes (or classes) >> for accessing hardware registers. At the top level, I would like the >> ability to bitwise ops if bit slice brackets are used, but if no >> brackets are used, I would like it to write/read the whole value. >> >> For example, if I have something like: >> >>>>> shadow_register = MyRegClass(0xAA) >>>>> shadow_register >> 170 >>>>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>>>> shadow_register >> 58 >>>>> shadow_register = 0x89 >>>>> shadow_register >> 137 >>>>> shadow_register[4:1] >> 4 >> >> I have the bitslice part working. But of course as expected, if I >> type>>> shadow_register >> >> <__main__.boo object at 0x00A130D0> > > def __str__(self): > return "d" % self.value > That should be: return "%d" % self.value From todpose at hotmail.com Thu Jan 29 19:06:09 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Thu, 29 Jan 2009 16:06:09 -0800 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: How can you make python round numbers to the nearest 5: Example: 3 => 0 8 => 10 23.2 => 20 36 => 35 51.5 => 50 Thanks! _________________________________________________________________ Twice the fun?Share photos while you chat with Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Jan 29 19:09:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 22:09:56 -0200 Subject: slicings: 3 questions References: Message-ID: En Thu, 29 Jan 2009 19:41:28 -0200, Robert Kern escribi?: > On 2009-01-29 15:33, Alan G Isaac wrote: >> On 1/29/2009 1:37 PM Chris Rebert apparently wrote: >>> Also, more fundamentally, Python is liberal in what it allows for the >>> parts of slices, so unifying slices with ranges would break code. For >>> example, Python is perfectly happy if I go slice("a",[8],object), none >>> of which are even numbers. >> >> Ah, this is new in Python 3 I take it? > > No. [test using 2.5.1] Just out of curiosity, I tried with the oldest Python I have: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> slice("a",[8],3j) slice('a', [8], 3j) So, no, it's far for being a new feature... -- Gabriel Genellina From berankin99 at yahoo.com Thu Jan 29 19:19:18 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Thu, 29 Jan 2009 16:19:18 -0800 (PST) Subject: error on building 2.6.1. (_ctypes) Message-ID: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Hello, I am trying to build python 2.6 on a machine (web server) that I do not have root access to. (has 2.4 installed) Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1. Here is the command line I am using: ../configure -prefix=/home/username/local-python/ --enable-unicode=ucs4 (I don't know exactly what the ucs4 thing is for, but all the HOWTOs I saw say to use it. Is it good practice? Anyway, i get the same error either way.) Here is what the existing python reports itself as: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Python 2.4.3 (#1, Jul 29 2007, 14:09:31) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the error after I run "make": ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [SNIP] /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: error: syntax error before '*' token /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: warning: function declaration isn't a prototype /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In function `CFuncPtr_nonzero': /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: error: `self' undeclared (first use in this function) Failed to find the necessary bits to build these modules: _tkinter bsddb185 sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _ctypes running build_script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I am guessing that I don't need tkinter or sunaudiodev, but what about the others? What's the fix for this sort of thing? I do see via google some other folks are having the same issue, but I could find a solution. Thanks :) From rt8396 at gmail.com Thu Jan 29 19:21:08 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 16:21:08 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" Message-ID: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> I been around the list for a while and rubbed sholders with some pythonistas(some you would not beleieve if i told you) and i just don't see a community spirit here. Where are the community projects supporting Python? -- besides the core devlopment. Seem s that nobody is interested unless their pay-pal account is involved. I find this all quite disappointing. Also if anyone dares to mention that Python is a great language or better in this reguard or that, they get jumped and beat to death by their "so-called" brothers. AKAIK there is a group for every languge out there. C, Perl, Java, Ruby, etc, etc. This is comp.lang.python, if you don't like it, hang out in "comp.lang.whatever". Don't tell me or anybody "Comparing Python -> Perl is not allowed here!". From gherron at islandtraining.com Thu Jan 29 19:22:01 2009 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 29 Jan 2009 16:22:01 -0800 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <49824829.9000001@islandtraining.com> todpose at hotmail.com wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 round(n,-1) rounds to the nearest 10, so round(n*2,-1)/2 will round to the nearest five. Gary Herron > > > Thanks! > > ------------------------------------------------------------------------ > Twice the fun? Share photos while you chat with Windows Live > Messenger. > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From reckoner at gmail.com Thu Jan 29 19:22:42 2009 From: reckoner at gmail.com (Reckoner) Date: Thu, 29 Jan 2009 16:22:42 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> Message-ID: <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> On Jan 28, 10:17?pm, Peter Wang wrote: > On Jan 27, 3:16?pm,Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > a list of ?objects > > > A=[a,b,c,d,...,z] > > > where, ?in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that > > something about the ?object 'a' has changed so that when I revisit A, > > I will know that the other items in the list need to be refreshed to > > reflect the changes in A as a result of changing 'a'. > > > Even better would be to automatically percolate the subsequent changes > > that resulted from altering 'a' for the rest of the items in the list. > > Naturally, all of these items are related in some parent-child > > fashion. > > > that might be a lot to ask, however. > > > Any advice appreciated. > > You should really look at Enthought's Traits package. ?It does exactly > what you are asking for, and much, much more. ?See: > > http://code.enthought.com/projects/traits/documentation.phphttp://code.enthought.com/projects/traits/examples.php > > Using Traits, you could do the following: > > from enthought.traits.api import * > class Child(HasTraits): > ? ? state = Enum("happy", "sad", "bawling") > > class Parent(HasTraits): > ? ? child = Instance(Child) > > ? ? @on_trait_change('child.state') > ? ? def handler(self): > ? ? ? ? print "new child state:", self.child.state > > bob_jr = Child() > bob = Parent(child = bob_jr) > > bob_jr.state = "sad" > # This would result in bob.handler() being called > > (Disclosure: I work at Enthought and have been using Traits heavily > for the last 4+ years.) > > -Peter I haven't looked at Enthought in awhile. I want to avoid having to installing the entire Enthought toolsuite, however. Would I have to do that for Traits? Thanks again. From gagsl-py2 at yahoo.com.ar Thu Jan 29 19:23:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 22:23:35 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 17:07:01 -0200, escribi?: > i have a problem. I compiled Python and the socket module so I got > this structure. (all on windows) > > C:\test\dll_files\python25.dll > C:\test\my_app > C:\test\dll_files\DLLs\ > C:\test\dll_files\python.exe > > If I run python.exe I get the console and I can call "import socket" > which > succeeds. I wrote a small console app which is stored in C:\test\ and > embeddeds the python interpreter. I set the environment variable PATH > so the python25.dll can be load. The easiest way is to mirror the directory structure of a standard Python install. Python looks for Lib/os.py and, once found, derives all the other paths from here. See PC/getpathp.c in the source distribution. You have these alternatives: - put a lib\* containing at least os.py below the directory containing your main executable. - set a PYTHONHOME variable - call Py_SetProgramName - completely replace getpathp.c with your own functions -- Gabriel Genellina From python.list at tim.thechases.com Thu Jan 29 19:26:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 18:26:34 -0600 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982493A.90404@tim.thechases.com> > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 I'm not sure *any* rounding system will give those results. 3 should round up to 5 (not down to 0) and 23.2 should round up to 25 (not down to 20) in the same way that 8 rounds up to 10. tests = ( (3, 5), # not 0 (8, 10), (23.2, 25), # not 20 (36, 35), (51.5, 50), ) for x, expected in tests: result = int(round(x / 5.0) * 5) if result != expected: print "Failed:", x, result, expected break else: print "All tests passed" -tkc From google at mrabarnett.plus.com Thu Jan 29 19:27:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 00:27:09 +0000 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982495D.6090907@mrabarnett.plus.com> todpose at hotmail.com wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 > Divide by 5, round the result, then multiply by 5. From ysk1 at sfu.ca Thu Jan 29 19:29:11 2009 From: ysk1 at sfu.ca (Eric Kang) Date: Thu, 29 Jan 2009 16:29:11 -0800 (PST) Subject: Swapping values of two variables Message-ID: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> In python, I set: x=1 y=3 z = x x = y y = z This gave me 3 1, which are the values of x and y swapped. The following would have given me the same result: x, y = y, x But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory required to exchange two 32-bit quantities? What would be the pseudocode that achieves this minimum? From AlexandriaSupport at gmail.com Thu Jan 29 19:35:38 2009 From: AlexandriaSupport at gmail.com (viglen) Date: Thu, 29 Jan 2009 16:35:38 -0800 (PST) Subject: Quickbooks References: Message-ID: <04181750-2bd5-42ba-85f3-7736dbe8af30@d32g2000yqe.googlegroups.com> On Jan 28, 1:21?pm, Stephen Chapman wrote: > Has anyone Implemented the Quickbooks ?COM object in Python. ?If so can > you give me > an Idea of where to begin. > Thanks Have you tried to contact the customer support team? I have used them many times and they are very helpful. They have different levels of support members to help even the most complicated questions and problems regarding their POS Software. 1-888-320-7276 QuickBooks: Basic, Pro and Premier and Customer Manager 1-800-348-0254 QuickBooks: Point of Sale 1-866-340-QBES QuickBooks: Enterprise Solutions 1-800-881-2079 QuickBooks: Simple Start Desktop Edition Hours of Operation:1 (Pacific time) Point of Sale: Mon-Fri 6 A.M. to 8 P.M. Sat & Sun 7 A.M. to 4 P.M. All others: Mon-Fri 6 A.M. to 6 P.M. Support, www.AlexandriaComputers.com From alan.isaac at gmail.com Thu Jan 29 19:36:57 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 30 Jan 2009 00:36:57 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: On 1/29/2009 4:41 PM Robert Kern apparently wrote: > It allows (ab)uses like numpy.mgrid: > > >>> mgrid[0:10:11j] > array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) Ah of course. Obvious now, but I had presumed some deeper magic in that syntax, not recognizing that a legitimate slice object was being created. Thanks! Alan From jervisau at gmail.com Thu Jan 29 19:42:40 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 30 Jan 2009 11:42:40 +1100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: Message-ID: <8e63a5ce0901291642o65e3039esab02885cdd76f635@mail.gmail.com> On Fri, Jan 30, 2009 at 9:02 AM, wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>> shadow_register = MyRegClass(0xAA) > >>> shadow_register > is it so bad to type: >>> shadow_register[:] 170 ?? I like this because it is quite clear as to what you are doing, and is consistent with the bit slicing you have (already) implemented. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Thu Jan 29 19:44:45 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 16:44:45 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: On Jan 29, 3:13?pm, Stef Mientki wrote: > mark.sea... at gmail.com wrote: > > Thanks. ?So far these solutions will return strings. ?So I can't > > really treat it like a variable, yet still perform bitslice on it, > > since I need a special class to do bitslice and bit selection, but as > > soon as I try to pass it into some other function to check a bit, I > > gotta then do another operation to convert back to a variable. > > > So I can get it to a point where I can do shadow_register[3] and get > > the value of any bit, or I can do shadow_register[4:2] and get a > > bitslice, and I can write them just as easily at this point. ?If I add > > the __new__ method into the class, the instance obj becomes int, but > > is no longer slicable. ?I think it looks like I can't have it both > > ways. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > there are a few vhdl projects, > can't find my links right now > - myhdl > - something like pysystemC > > maybe you can find the answer there > > cheers, > Stef- Hide quoted text - > > - Show quoted text - Thanks for the tip. I checked out myhdl and it has a class called intbv which does exactly this, and much more than I need. It's GNU lesser license though, so not sure how to handle that, if I just want some concepts of the code as examples, but don't want copy it per se. Thanks, Mark From bj_666 at gmx.net Thu Jan 29 19:54:11 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 30 Jan 2009 00:54:11 GMT Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <6uf1djFengojU2@mid.uni-berlin.de> On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > try this: > > class MyRegClass ( int ) : > def __init__ ( self, value ) : > self.Value = value > def __repr__ ( self ) : > line = hex ( self.Value ) > line = line [:2] + line [2:].upper() > return line def __repr__(self): return '0x%X' % self.value > __str__ = __repr__ This is unnecessary, the fallback of `__str__` is `__repr__` already. Ciao, Marc 'BlackJack' Rintsch From alan.isaac at gmail.com Thu Jan 29 19:56:54 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 30 Jan 2009 00:56:54 GMT Subject: naming and binding (subtle Python 3 change) Message-ID: The example give at http://docs.python.org/reference/executionmodel.html#naming-and-binding remains unchanged at http://docs.python.org/3.0/reference/executionmodel.html#naming-and-binding but the change to Python 3 list comprehensions now means the example will fail even with list comprehension syntax. Should the example be changed to make that clear? Alan Isaac From google at mrabarnett.plus.com Thu Jan 29 20:11:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 01:11:05 +0000 Subject: Swapping values of two variables In-Reply-To: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: <498253A9.8050407@mrabarnett.plus.com> Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > > This gave me 3 1, which are the values of x and y swapped. > The following would have given me the same result: > x, y = y, x > > But could the swapping be done using less extra memory than this? > What is the minimum amount of extra memory required to exchange two > 32-bit quantities? What would be the pseudocode that achieves this > minimum? > x ^= y y ^= x x ^= y This is really only of use when working in assembly language. From gnewsg at gmail.com Thu Jan 29 20:11:21 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 29 Jan 2009 17:11:21 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: > Where are the community projects supporting Python? -- besides the > core devlopment. http://pypi.python.org/pypi ...which accidentally says "There are currently 5597 packages here." Not bad uh? --- Giampaolo http://code.google.com/p/pyftpdlib From sjmachin at lexicon.net Thu Jan 29 20:22:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 01:22:50 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Benjamin Kaplan case.edu> writes: > First of all, you're right that might be confusing. I was thinking of auto-detect as in "check the platform and locale and guess what they usually use". I wasn't thinking of it like the web browsers use it.I think it uses locale.getpreferredencoding(). You're probably right. I'd forgotten about locale.getpreferredencoding(). I'll raise a request on the bug tracker to get some more precise wording in the open() docs. > On my machine, I get sys.getpreferredencoding() == 'utf-8' and locale.getdefaultencoding()== 'cp1252'. sys <-> locale ... +1 long-range transposition typo of the year :-) > If you check my response to Anjanesh's comment, I mentioned that he should either find out which encoding it is in particular or he should open the file in binary mode. I suggested utf-8 and latin1 because those are the most likely candidates for his file since cp1252 was already excluded. The OP is on a Windows machine. His file looks like a source code file. He is unlikely to be creating latin1 files himself on a Windows box. Under the hypothesis that he is accidentally or otherwise reading somebody else's source files as data, it could be any encoding. In one package with which I'm familiar, the encoding is declared as cp1251 in every .py file; AFAICT the only file with non-ASCII characters is an example script containing his wife's name! The OP's 0x9d is a defined character in code pages 1250, 1251, 1256, and 1257 -- admittedly all as implausible as the latin1 control character. > Looking at a character map, 0x9d is a control character in latin1, so the page is probably UTF-8 encoded. Thinking about it now, it could also be MacRoman but that isn't as common as UTF-8. Late breaking news: I presume you can see two instances of U+00DD (LATIN CAPITAL LETTER Y WITH ACUTE) in the OP's report "query":"0 1?? \u2021 0\u201a0 \u2021??"," Well, u'\xdd'.encode('utf8') is '\xc3\x9d' ... the Bayesian score for utf8 just went up a notch. The preceding character U+00BB (looks like >>) doesn't cause an exception because 0xBB unlike 0x9D is defined in cp1252. Curiously looking at the \uxxxx escape sequences: \u2021 is "double dagger", \u201a is "single low-9 quotation mark" ... what appears to be the value part of an item in a hard-coded dictionary is about as comprehensible as the Voynich manuscript. Trouble with cases like this is as soon as they become interesting, the OP often snatches somebody's one-liner that "works" (i.e. doesn't raise an exception), makes a quick break for the county line, and they're not seen again :-) Cheers, John From Graham.Dumpleton at gmail.com Thu Jan 29 20:38:02 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 17:38:02 -0800 (PST) Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: <63cf7deb-f15c-4259-aa24-1b8da846876d@r41g2000prr.googlegroups.com> On Jan 30, 11:01?am, Ron Garret wrote: > In article , > ?Joshua Kugler wrote: > > > Ron Garret wrote: > > > My question is: is this supposed to be happening? ?Or is this an > > > indication that something is wrong, and if so, what? > > > You are probably just hitting a different instance of Apache, thus the > > different process ID. > > Yep, that's what it turned out to be. ?I thought I had a > WSGIDaemonProcess processes=1 directive in my config, but I had it in > the wrong place (a different vhost) so it wasn't actually active. > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > But that leaves me wondering why the redirect would reliably trigger > switching processes. ?The reason I thought that I had the correct > configuration and only had one process is that when I reloaded the > non-redirected page I *always* got the same process ID. ?How doesmod_wsgidecide which process ?(and which thread for that matter) to use? Details on process/threading in mod_wsgi available at: http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading When using WSGIDaemonProcess directive, if you want a single process it is better to allow it to default to a single process and not have 'processes=1'. As soon as you say 'processes=1' it will trigger wsgi.multiprocess to be True rather than default of False. This may sound counter intuitive, but is a little back door to allow wsgi.multiprocess to be set to True somehow when distributing an application across a cluster of machines where it does need to be True even if each machine only has a single process for that application. Tthat wsgi.multiprocess is True will not usually matter unless you are trying to use debugging middleware that require that there only be a single process. As to why you were getting a different process, because you were actually running in embedded mode due to WSGIDaemonProcess/ WSGIProcessGroup being in wrong context, then what process was used was really up to Apache and how it works. Specifically it can have multiple processes that can listen on the HTTP port (80). Because only one should be listening at a time it uses a cross process mutex lock to mediate access. When a process handles a request, it gives up the lock. If using worker MPM then another thread in same process may get lock, or for either worker MPM or prefork MPM, then another process could get it. Which actually gets it is a bit indeterminate as simply depends on which process the operating system lets have the lock next. So, there is no strict rule one can say as to who would get it next. Graham Graham From Graham.Dumpleton at gmail.com Thu Jan 29 20:43:18 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 17:43:18 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> Message-ID: <146f6796-37b5-4220-bdb1-5119cb3ac7e1@z6g2000pre.googlegroups.com> On Jan 30, 9:53?am, Ron Garret wrote: > In article <498171a5$0$3681$426a7... at news.free.fr>, > ?Bruno Desthuilliers > > ?wrote: > > Ron Garret a ?crit : > > > In article , > > > ?Aleksandar Radulovic wrote: > > (snip) > > >> Secondly, why are you restarting apache after code changes? In normal > > >> circumstances, you shouldn't have to do that. > > > > I thought (and experiment confirms) that only the main WSGI app file > > > gets reloaded automatically when it changes, not the libraries. > > > Depends on how you configure mod_wsgi. Read the part about "Process > > Reloading Mechanism" here: > >http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode > > I'm running Debian Etch, which means I have an older version of > mod_wsgi, which means I don't have the process reloading mechanism. Back port available at: http://packages.debian.org/etch-backports/libapache2-mod-wsgi Graham From tony.clarke5 at googlemail.com Thu Jan 29 20:50:04 2009 From: tony.clarke5 at googlemail.com (tony.clarke5 at googlemail.com) Date: Thu, 29 Jan 2009 17:50:04 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: On Jan 30, 12:29?am, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > This gave me 3 1, which are the values of x and y swapped. > The following would have given me the same result: > x, y = y, x > > But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory required to exchange two 32-bit quantities? What would be the pseudocode that achieves this minimum? How about: def transpose(x, y): print x, y, 'becomes: ', x = x + y y = x - y x = x - y print x, ' ', y transpose(1,3) transpose (9,8) From schickb at gmail.com Thu Jan 29 21:48:39 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 18:48:39 -0800 (PST) Subject: new.instancemethod questions Message-ID: I'd like to add bound functions to instances, and found the instancemethod function in the new module. A few questions: 1. Why is instancemethod even needed? Its counter-intuitive (to me at least) that assigning a function to a class results in bound functions its instances, while assigning directly to instances does not create a bound function. So why doesn't assigning a function to an instance attribute result in a function bound to that instance? 2. The 2.6 docs say the new module is depreciated and refers to the types module instead. But I haven't found a way to create bound functions using the types module. Am I just missing something? Thanks, -Brad From mark.seagoe at gmail.com Thu Jan 29 21:57:22 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 18:57:22 -0800 (PST) Subject: Using equals operator without changing reference pointer Message-ID: I know this may be asking too much of Python, but you never know unless you ask... So now having a class that can be treated like an int as far as math upon the instance name, and can be treated as in HDL simulators, allowing bitslice and bitselect ops, I was stoked. Also reading back the instance name returns the int, rather than text about the class name and location in memory. But... it would be wonderful if there was a way to assign a value without using any .member notation... if there were a way for me to specify that the reference would never change. For example: >>> myInst = MyClass(0xAA) >>> myInst 170 >>> myInst[0] # <== MyClass can do bit selection 0 >>> myInst = 0x55 # <== gets reassigned >>> myInst[0] # <== this is where it would choke 1 # <== this is the answer I would want Is there a way to lock down myInst so that it still refers to the original object, and is there some special member that will allow me to override the equals operator in this case? Or is that simply blasphemous against everything Python holds sacred? Certainly there is some keyword that I don't know about. Thanks! Mark From wuwei23 at gmail.com Thu Jan 29 22:01:52 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 19:01:52 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> On Jan 30, 10:21?am, r wrote: > I been around the list for a while and rubbed sholders with some > pythonistas(some you would not beleieve if i told you) and i just > don't see a community spirit here. Seriously, how -old- are you? Twelve? Thirteen? From max at alcyone.com Thu Jan 29 22:04:49 2009 From: max at alcyone.com (Erik Max Francis) Date: Thu, 29 Jan 2009 19:04:49 -0800 Subject: Using equals operator without changing reference pointer In-Reply-To: References: Message-ID: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> mark.seagoe at gmail.com wrote: > Is there a way to lock down myInst so that it still refers to the > original object, and is there some special member that will allow me > to override the equals operator in this case? Or is that simply > blasphemous against everything Python holds sacred? Certainly there > is some keyword that I don't know about. No. The assignment operator with a bare name on the left hand side is not overridable. You can override attribute access, however, with .__getattr__/.__getattribute__. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis The perfection of innocence, indeed, is madness. -- Arthur Miller From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:07:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:07:55 GMT Subject: Swapping values of two variables References: Message-ID: On Thu, 29 Jan 2009 16:29:11 -0800, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > > This gave me 3 1, which are the values of x and y swapped. The following > would have given me the same result: x, y = y, x Yes. > But could the swapping be done using less extra memory than this? What > is the minimum amount of extra memory required to exchange two 32-bit > quantities? What would be the pseudocode that achieves this minimum? Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes (96 bits) in size; a long will use as much memory as needed. If your application needs to optimize a swap of two ints, then Python is probably going to be much too memory-intensive for you. (But my money is on you doing premature optimization.) -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:31:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:31:03 GMT Subject: Swapping values of two variables References: Message-ID: On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > On Jan 30, 12:29?am, Eric Kang wrote: >> In python, I set: >> >> x=1 >> y=3 >> >> z = x >> x = y >> y = z >> >> This gave me 3 1, which are the values of x and y swapped. The >> following would have given me the same result: x, y = y, x >> >> But could the swapping be done using less extra memory than this? What >> is the minimum amount of extra memory required to exchange two 32-bit >> quantities? What would be the pseudocode that achieves this minimum? > > How about: > def transpose(x, y): > print x, y, 'becomes: ', > x = x + y > y = x - y > x = x - y > print x, ' ', y > > transpose(1,3) > transpose (9,8) I'm not sure what the point of that function is. It doesn't actually swap its arguments: >>> x = 23 >>> y = 42 >>> transpose(x, y) 23 42 becomes: 42 23 >>> x 23 >>> y 42 And it certainly doesn't save memory, as the original poster asked: >>> import dis >>> swap = compile('x, y = y, x', '', 'single') >>> dis.dis(swap) 1 0 LOAD_NAME 0 (y) 3 LOAD_NAME 1 (x) 6 ROT_TWO 7 STORE_NAME 1 (x) 10 STORE_NAME 0 (y) 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> dis.dis(transpose) 2 0 LOAD_FAST 0 (x) 3 PRINT_ITEM 4 LOAD_FAST 1 (y) 7 PRINT_ITEM 8 LOAD_CONST 1 ('becomes: ') 11 PRINT_ITEM 3 12 LOAD_FAST 0 (x) 15 LOAD_FAST 1 (y) 18 BINARY_ADD 19 STORE_FAST 0 (x) 4 22 LOAD_FAST 0 (x) 25 LOAD_FAST 1 (y) 28 BINARY_SUBTRACT 29 STORE_FAST 1 (y) 5 32 LOAD_FAST 0 (x) 35 LOAD_FAST 1 (y) 38 BINARY_SUBTRACT 39 STORE_FAST 0 (x) 6 42 LOAD_FAST 0 (x) 45 PRINT_ITEM 46 LOAD_CONST 2 (' ') 49 PRINT_ITEM 50 LOAD_FAST 1 (y) 53 PRINT_ITEM 54 PRINT_NEWLINE 55 LOAD_CONST 0 (None) 58 RETURN_VALUE The compiled code of the transpose function *alone* (not including all the other associated parts) takes 59 bytes, or 472 bits. >>> len(transpose.func_code.co_code) 59 Even if it worked, that's hardly using less memory than a direct swap. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:31:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:31:28 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > In addition to methods, Python has functions, which are not associated > with a class Yes they are. >>> (lambda: None).__class__ The function type itself has a class: >>> (lambda: None).__class__.__class__ -- Steven From mwilson at the-wire.com Thu Jan 29 22:38:37 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 29 Jan 2009 22:38:37 -0500 Subject: new.instancemethod questions References: Message-ID: schickb wrote: > I'd like to add bound functions to instances, and found the > instancemethod function in the new module. A few questions: > > 1. Why is instancemethod even needed? Its counter-intuitive (to me at > least) that assigning a function to a class results in bound functions > its instances, while assigning directly to instances does not create a > bound function. So why doesn't assigning a function to an instance > attribute result in a function bound to that instance? If I understand you correctly, rebinding to the instance would break code like: myfakefile.write = sys.stdout.write where the intent would be to redirect any output through myfakefile straight to sys.stdout. The code for the sys.stdout.write function would never find the attributes it needed in the instance of myfakefile. To do this, methods have to stay bound to their proper instances. Mel. From tjreedy at udel.edu Thu Jan 29 22:50:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 22:50:50 -0500 Subject: naming and binding (subtle Python 3 change) In-Reply-To: References: Message-ID: Alan G Isaac wrote: > The example give at > http://docs.python.org/reference/executionmodel.html#naming-and-binding > remains unchanged at > http://docs.python.org/3.0/reference/executionmodel.html#naming-and-binding > but the change to Python 3 list comprehensions now means the example > will fail even with list comprehension syntax. Should the example be > changed to make that clear? http://bugs.python.org/issue5106 From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:51:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:51:16 GMT Subject: Rounding to the nearest 5 References: Message-ID: On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote: >> How can you make python round numbers to the nearest 5: >> >> Example: >> >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > I'm not sure *any* rounding system will give those results. Round towards zero. > 3 should round up to 5 (not down to 0) That would be round to nearest. > result = int(round(x / 5.0) * 5) I think that should work. It even works for negative values: >>> int(round(-2.2 / 5.0) * 5) 0 >>> int(round(-2.7 / 5.0) * 5) -5 -- Steven From schickb at gmail.com Thu Jan 29 22:52:09 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 19:52:09 -0800 (PST) Subject: new.instancemethod questions References: Message-ID: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> On Jan 29, 7:38?pm, Mel wrote: > schickb wrote: > > I'd like to add bound functions to instances, and found the > > instancemethod function in the new module. A few questions: > > > 1. Why is instancemethod even needed? Its counter-intuitive (to me at > > least) that assigning a function to a class results in bound functions > > its instances, while assigning directly to instances does not create a > > bound function. So why doesn't assigning a function to an instance > > attribute result in a function bound to that instance? > > If I understand you correctly, rebinding to the instance would break code > like: > > myfakefile.write = sys.stdout.write > > where the intent would be to redirect any output through myfakefile straight > to sys.stdout. ?The code for the sys.stdout.write function would never find > the attributes it needed in the instance of myfakefile. ?To do this, > methods have to stay bound to their proper instances. > 1. I'm thinking about assigning free non-bound functions. Like: class A(object): pass def func(self): print repr(self) a = A() a.func = func # Why doesn't this automatically create a bound function (aka method)? 2. And what is the preferred way to do this if the "new" module and its instancemethod function are depreciated? -Brad From clp2 at rebertia.com Thu Jan 29 22:53:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 19:53:04 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <50697b2c0901291953j4af923d9nb7748f9bef1d7c64@mail.gmail.com> On Thu, Jan 29, 2009 at 7:31 PM, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > >> In addition to methods, Python has functions, which are not associated >> with a class > > Yes they are. > >>>> (lambda: None).__class__ > > > The function type itself has a class: > >>>> (lambda: None).__class__.__class__ > I think we're now quibbling over the interpretation of "associated". My intention was to contrast how methods and classmethods are stored and accessed through the class they are defined in (or grafted onto), whereas plain functions are not (instance/class variables that happen to hold functions notwithstanding). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 29 23:03:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 23:03:45 -0500 Subject: Using equals operator without changing reference pointer In-Reply-To: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> References: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> Message-ID: Erik Max Francis wrote: > mark.seagoe at gmail.com wrote: > >> Is there a way to lock down myInst so that it still refers to the >> original object, and is there some special member that will allow me >> to override the equals operator in this case? Or is that simply >> blasphemous against everything Python holds sacred? Certainly there >> is some keyword that I don't know about. > > No. The assignment operator with a bare name on the left hand side is > not overridable. So that 'name = ob' *always* binds name to ob. That is one thing one can depend on when reading Python code. > You can override attribute access, however, with > .__getattr__/.__getattribute__. I presume that you have over-riden __setitem__ in addition to __getitem__ so that myOb[0] = 1 sets the bit. You could add a branch to __setitem__ (or define __setslice__ in 2.x) so that myOb[:] = 0x55 does just what you want it to -- set all bits. Being able to get/set contiguous bits might be something you want anyway. tjr PS. When asking about internal details, specify version of interest, as there have been minor changes. From blackcapsoftware at gmail.com Thu Jan 29 23:06:42 2009 From: blackcapsoftware at gmail.com (blackcapsoftware at gmail.com) Date: Thu, 29 Jan 2009 20:06:42 -0800 (PST) Subject: Module/Library That is Able To Use Cookies + Proxies? Message-ID: <315e5bad-2c3f-4e69-b810-b9535266dfc9@f3g2000vbf.googlegroups.com> Hey guys, I have been search the net for a bit now and can't find anything. What I would like to do is be able to log into a site that uses cookies to store information about the user when logging in. This works fine and dandy with ClientCookie. Now, I want to be able to do so with a proxy, does anyone have any suggestions, or libraries? Any help is greatly appreciated. Regards From bignose+hates-spam at benfinney.id.au Thu Jan 29 23:11:38 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 30 Jan 2009 15:11:38 +1100 Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> Message-ID: <87vdrxsa9x.fsf@benfinney.id.au> alex23 writes: > On Jan 30, 10:21?am, r wrote: > > I been around the list for a while and rubbed sholders with some > > pythonistas(some you would not beleieve if i told you) and i just > > don't see a community spirit here. > > Seriously, how -old- are you? Twelve? Thirteen? Please stop baiting people. If you find someone to be annoying, don't incite them. Either find a way to direct the discussion to something more constructive, or filter it out. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but how will we get a pair of Abe Vigoda's pants?? | _o__) ?_Pinky and The Brain_ | Ben Finney From ysk1 at sfu.ca Thu Jan 29 23:13:52 2009 From: ysk1 at sfu.ca (Eric Kang) Date: Thu, 29 Jan 2009 20:13:52 -0800 (PST) Subject: Adding a positive number and a negative number Message-ID: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> In two?s complement representation, can adding one positive and one negative give you overflow? From rt8396 at gmail.com Thu Jan 29 23:21:03 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 20:21:03 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> Message-ID: On Jan 29, 9:01?pm, alex23 wrote: > Seriously, how -old- are you? Twelve? Thirteen? Ah, my good friend alex23. Somehow -- when i was writing this post -- i knew you would drop in and i swear i do not have any ESP abilities -- somehow i just knew. While your here why don't we take a walk down memory lane. Let's go back to our first encounter -- Yes, that crazy thread(i won't utter the title here). Seems i was promoting the inclusion of the Python language in a revolutionary and promising application and you were very upset about it. Why, i really don't know because you never told me. The only thing i can remember is you wishing me dead -- if i recall your wish was to cut off oxygen supply to my brain. I can't help but wonder of the devious thoughts that toil away in your demented little mind right now. Of what demise shall i suffer this time alex23. But please alex, at least -try- to be a little more creative, if i am to meet my end, i would hate for it to be some worn- out old cliche' From gagsl-py2 at yahoo.com.ar Thu Jan 29 23:35:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 02:35:38 -0200 Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Message-ID: En Thu, 29 Jan 2009 22:19:18 -0200, Bernard Rankin escribi?: > I am trying to build python 2.6 on a machine (web server) that I do not > have root access to. (has 2.4 installed) > > Python 2.5 builds fine, but I am getting an error when I run "make" for > 2.6.1. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: > error: syntax error before '*' token > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: > warning: function declaration isn't a prototype > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In > function `CFuncPtr_nonzero': > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: > error: `self' undeclared (first use in this function) Mmm... my 2.6.1 source show different line numbers, maybe you should check it's the right file? > Failed to find the necessary bits to build these modules: > _tkinter bsddb185 sunaudiodev > Failed to build these modules: > _ctypes > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > I am guessing that I don't need tkinter or sunaudiodev, but what about > the others? bsddb185 is just for compatibility with the old Berkeley DB. I'd be worried just by ctypes - and only if you actually require it. -- Gabriel Genellina From linuxguy123 at gmail.com Thu Jan 29 23:42:45 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Thu, 29 Jan 2009 21:42:45 -0700 Subject: libsudo ? Message-ID: <1233290565.3742.1.camel@localhost.localdomain> Does anyone know where I would find libsudo ? If you had the choice of using pexpect or libsudo, which would you use ? Thanks From BrianVanderburg2 at aim.com Thu Jan 29 23:51:29 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 23:51:29 -0500 Subject: new.instancemethod questions In-Reply-To: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> References: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> Message-ID: <49828751.8040503@aim.com> schickb at gmail.com wrote: > On Jan 29, 7:38 pm, Mel wrote: > >> schickb wrote: >> >>> I'd like to add bound functions to instances, and found the >>> instancemethod function in the new module. A few questions: >>> >>> 1. Why is instancemethod even needed? Its counter-intuitive (to me at >>> least) that assigning a function to a class results in bound functions >>> its instances, while assigning directly to instances does not create a >>> bound function. So why doesn't assigning a function to an instance >>> attribute result in a function bound to that instance? >>> >> If I understand you correctly, rebinding to the instance would break code >> like: >> >> myfakefile.write = sys.stdout.write >> >> where the intent would be to redirect any output through myfakefile straight >> to sys.stdout. The code for the sys.stdout.write function would never find >> the attributes it needed in the instance of myfakefile. To do this, >> methods have to stay bound to their proper instances. >> >> > > 1. I'm thinking about assigning free non-bound functions. Like: > > class A(object): > pass > > def func(self): > print repr(self) > > a = A() > a.func = func # Why doesn't this automatically create a bound > function (aka method)? > Actually I found out the implementation of why it doesn't after messing around some more. If an attribute is found in the instance dictionary, even if it is a descriptor it's __get__ doesn't get called, only if it is found in the class dictionary of the class or base classes. This makes it where you can store a function in the instance to be called later as a function for some useful purpose, for example two different instances of an object could use different sorting functions: # sort functions are responsible for sorting which mutation is the least and most fit def fitness1(v1, v2): # use one technique to determine which is more fit def fitness2(v1, v2): # use another technique to determine which is more fit ... # more fitness functions class Environment: def __init__(self, fitness, ...): self.fitness_func = fitness ... ... # create environments, each one has different fitness function a = Environment(fitness1) b = Environment(fitness2) Now when it is time to kill off the least fit of the genetic mutations, each environment can sort which is the least and most fit in different ways. > > 2. And what is the preferred way to do this if the "new" module and > its instancemethod function are depreciated? > > Most of the code I see does this with a closure something like this: def AddMethod(obj, func, name=None): if name is None: name = func.__name__ def method(*args, **kwargs): return func(obj, *args, **kwargs) setattr(obj, name, method) class MyClass(object): pass def f1(self): print self a = MyClass() AddMethod(a, f1) a.f1() # prints object a You can also create a bound method and manually bind it to the instance. This is easier import types a.f2 = types.MethodType(f1, a) a.f2() # prints object a These may work for most uses, but both have a problem that happens if you need to make a copy of the instance. When you copy it, the copies 'f1' will still call the function but using the old object a.f1() # prints object a b = copy.copy(a) b.f1() # still prints a Brian Vanderburg II From rt8396 at gmail.com Thu Jan 29 23:56:03 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 20:56:03 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <7e237bf2-b21f-439e-a8c8-0a1366c6c819@o36g2000yqh.googlegroups.com> On Jan 29, 5:51?pm, anders wrote: > if file.findInFile("LF01"): > Is there any library like this ?? > Best Regards > Anders Yea, it's called a for loop! for line in file: if "string" in line: do_this() From BrianVanderburg2 at aim.com Thu Jan 29 23:58:41 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 23:58:41 -0500 Subject: libsudo ? In-Reply-To: <1233290565.3742.1.camel@localhost.localdomain> References: <1233290565.3742.1.camel@localhost.localdomain> Message-ID: <49828901.1060706@aim.com> linuxguy123 at gmail.com wrote: > Does anyone know where I would find libsudo ? > http://sourceforge.net/projects/libsudo > If you had the choice of using pexpect or libsudo, which would you use ? > libsudo does all the work for you of executing sudo, checking for the expected responses and all. If all you need it for is to use sudo from Python I suspect it would be easier than pexpect. It is a C library however, so after being compiled and installed, you will need to use ctypes to use it. It is very simple, as the only function to deal with is: int runAs( char* command, char* password, char* user, int invalidate ); > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > Brian Vanderburg II From n.kottiyath at gmail.com Fri Jan 30 00:23:48 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 29 Jan 2009 21:23:48 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: <400ebbae-a923-438a-85af-8ff451b77f10@t39g2000prh.googlegroups.com> On Jan 30, 8:31?am, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > > On Jan 30, 12:29?am, Eric Kang wrote: > >> In python, I set: > > >> x=1 > >> y=3 > > >> z = x > >> x = y > >> y = z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory required to exchange two 32-bit > >> quantities? What would be the pseudocode that achieves this minimum? > > > How about: > > def transpose(x, y): > > ? ? print x, y, 'becomes: ', > > ? ? x = x + y > > ? ? y = x - y > > ? ? x = x - y > > ? ? print x, ' ', y > > > transpose(1,3) > > transpose (9,8) > > I'm not sure what the point of that function is. It doesn't actually swap > its arguments: > > >>> x = 23 > >>> y = 42 > >>> transpose(x, y) > > 23 42 becomes: ?42 ? 23>>> x > 23 > >>> y > > 42 > > And it certainly doesn't save memory, as the original poster asked: > > >>> import dis > >>> swap = compile('x, y = y, x', '', 'single') > >>> dis.dis(swap) > > ? 1 ? ? ? ? ? 0 LOAD_NAME ? ? ? ? ? ? ? ?0 (y) > ? ? ? ? ? ? ? 3 LOAD_NAME ? ? ? ? ? ? ? ?1 (x) > ? ? ? ? ? ? ? 6 ROT_TWO > ? ? ? ? ? ? ? 7 STORE_NAME ? ? ? ? ? ? ? 1 (x) > ? ? ? ? ? ? ?10 STORE_NAME ? ? ? ? ? ? ? 0 (y) > ? ? ? ? ? ? ?13 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?16 RETURN_VALUE > > >>> dis.dis(transpose) > > ? 2 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ? 3 PRINT_ITEM > ? ? ? ? ? ? ? 4 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ? 7 PRINT_ITEM > ? ? ? ? ? ? ? 8 LOAD_CONST ? ? ? ? ? ? ? 1 ('becomes: ') > ? ? ? ? ? ? ?11 PRINT_ITEM > > ? 3 ? ? ? ? ?12 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?15 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?18 BINARY_ADD > ? ? ? ? ? ? ?19 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 4 ? ? ? ? ?22 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?25 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?28 BINARY_SUBTRACT > ? ? ? ? ? ? ?29 STORE_FAST ? ? ? ? ? ? ? 1 (y) > > ? 5 ? ? ? ? ?32 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?35 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?38 BINARY_SUBTRACT > ? ? ? ? ? ? ?39 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 6 ? ? ? ? ?42 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?45 PRINT_ITEM > ? ? ? ? ? ? ?46 LOAD_CONST ? ? ? ? ? ? ? 2 (' ') > ? ? ? ? ? ? ?49 PRINT_ITEM > ? ? ? ? ? ? ?50 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?53 PRINT_ITEM > ? ? ? ? ? ? ?54 PRINT_NEWLINE > ? ? ? ? ? ? ?55 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?58 RETURN_VALUE > > The compiled code of the transpose function *alone* (not including all > the other associated parts) takes 59 bytes, or 472 bits. > > >>> len(transpose.func_code.co_code) > > 59 > > Even if it worked, that's hardly using less memory than a direct swap. > > -- > Steven Is it possible to swap two floats without a variable? From darcy at druid.net Fri Jan 30 00:24:47 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 00:24:47 -0500 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <20090130002447.e6c59998.darcy@druid.net> On Thu, 29 Jan 2009 16:06:09 -0800 "todpose at hotmail.com" wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 That appears to be rounding to nearest 10, not 5. Clarify your requirements first. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From grante at visi.com Fri Jan 30 00:29:44 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 29 Jan 2009 23:29:44 -0600 Subject: Swapping values of two variables References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: On 2009-01-30, MRAB wrote: >> What is the minimum amount of extra memory required to exchange two >> 32-bit quantities? What would be the pseudocode that achieves this >> minimum? > > x ^= y > y ^= x > x ^= y > > This is really only of use when working in assembly language. And rarely then. ;) [Readability counts everywhere.] -- Grant From rt8396 at gmail.com Fri Jan 30 00:38:12 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 21:38:12 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> On Jan 29, 6:21?pm, r wrote: > Also if anyone dares to mention that Python is a great language or > better in this reguard or that, they get jumped and beat to death by > their "so-called" brothers. This observation leads me to two scientific and common sense synopsis. Either nobody here gives a rats pa'toote about Python, and/or they are all just a bunch of gutless worms too afraid to stand up to the 10 or so Perl/Ruby leeches who's infestation slowly drains the life-blood out of the Python Community, keeping it too weak to fight back. From wuwei23 at gmail.com Fri Jan 30 00:38:43 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 21:38:43 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <7e237bf2-b21f-439e-a8c8-0a1366c6c819@o36g2000yqh.googlegroups.com> Message-ID: On Jan 30, 2:56?pm, r wrote: > On Jan 29, 5:51?pm, anders wrote: > > > if file.findInFile("LF01"): > > Is there any library like this ?? > > Best Regards > > Anders > > Yea, it's called a for loop! > > for line in file: > ? ? if "string" in line: > ? ? ? ? do_this() Which is what the OP is already doing: > (Today i step line for line and check) anders, you might have more luck with one of the text search libraries out there: PyLucene (although this makes Java a dependency): http://lucene.apache.org/pylucene/ Nucular: http://nucular.sourceforge.net/ mxTextTools: http://www.egenix.com/products/python/mxBase/mxTextTools/ From semanticist at gmail.com Fri Jan 30 00:43:27 2009 From: semanticist at gmail.com (Miles) Date: Fri, 30 Jan 2009 00:43:27 -0500 Subject: Rounding to the nearest 5 In-Reply-To: <4982493A.90404@tim.thechases.com> References: <4982493A.90404@tim.thechases.com> Message-ID: On Thu, Jan 29, 2009 at 7:26 PM, Tim Chase wrote: >> How can you make python round numbers to the nearest 5: >> Example: >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > I'm not sure *any* rounding system will give those results. def bogoround(n): n1 = n / 5.0 return int(round(n1) if n1 % 2 > 1 else n1) * 5 best-I-could-do-ly y'rs, -Miles From justin.mailinglists at gmail.com Fri Jan 30 00:51:17 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 29 Jan 2009 21:51:17 -0800 (PST) Subject: Module/Library That is Able To Use Cookies + Proxies? References: <315e5bad-2c3f-4e69-b810-b9535266dfc9@f3g2000vbf.googlegroups.com> Message-ID: <1c7e7278-a7e0-402a-8b75-a7266314c227@r10g2000prf.googlegroups.com> On Jan 30, 12:06?pm, blackcapsoftw... at gmail.com wrote: > I would like to do is be able to log into a site that uses cookies to > store information about the user when logging in. This works fine and > dandy with ClientCookie. Now, I want to be able to do so with a proxy, urllib2 http://docs.python.org/library/urllib2.html#module-urllib2 class urllib2.HTTPCookieProcessor([cookiejar]) A class to handle HTTP Cookies. class urllib2.ProxyHandler([proxies])? Cause requests to go through a proxy. If proxies is given, it must be a dictionary mapping protocol names to URLs of proxies. The default is to read the list of proxies from the environment variables . To disable autodetected proxy pass an empty dictionary. From prologic at shortcircuit.net.au Fri Jan 30 00:53:12 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 30 Jan 2009 15:53:12 +1000 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Fri, Jan 30, 2009 at 3:38 PM, r wrote: > This observation leads me to two scientific and common sense synopsis. > Either nobody here gives a rats pa'toote about Python, and/or they are > all just a bunch of gutless worms too afraid to stand up to the 10 or > so Perl/Ruby leeches who's infestation slowly drains the life-blood > out of the Python Community, keeping it too weak to fight back. > I for one am not e member of either the Perl or Ruby fan club - and I don't think I will ever be :) However I"m not going to go and start bagging those languages :) I prefer Python! I think you'll find a 3rd scenario: Python developers (those that develop Python) and Python programmers (those that use Python) just don't really care about politics, protest and all the rubbish that goes on in this list :) cheers James From hungvn94 at gmail.com Fri Jan 30 00:56:13 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 21:56:13 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From hungvn94 at gmail.com Fri Jan 30 00:56:39 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 21:56:39 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <34545a61-1b00-4c15-87fd-5dc7103dea24@p2g2000prn.googlegroups.com> On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From hungvn94 at gmail.com Fri Jan 30 01:00:14 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 22:00:14 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <3322b9e0-af59-4967-aac4-72b5750f87d4@z6g2000pre.googlegroups.com> On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From wuwei23 at gmail.com Fri Jan 30 01:09:10 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 22:09:10 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <3322b9e0-af59-4967-aac4-72b5750f87d4@z6g2000pre.googlegroups.com> Message-ID: On Jan 30, 4:00?pm, Hung Vo wrote: > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Well, it has the same _concepts_, but definitely not the same practices/implementations. As they say, Python is not Java :) From apt.shansen at gmail.com Fri Jan 30 01:14:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 22:14:55 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <7a9c25c20901292214n369c915ev1b4cdbc62fea19b3@mail.gmail.com> > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Python does not enforce Encapsulation; but convention is extremely successful here although there's some really loud people in this newsgroup who state otherwise. Python programmers tend to be very well-behaved in this regard and they do not poke into private API's -- unless /they have to/. That's important: /have/ to. If they were not allowed, they'd be unable to use that code. Internally in corporate software this is a complete non-issue: and in any major project it should be a non-issue too. If you follow basic convention (private is preceded by _) then it is extremely clear if you're obeying encapsulation and if someone in your project breaks it without a good reason-- refuse the addition. Python is *extremely* polymorphic. Python does not have any built-in "interface" capability, per se, but there are add-on libraries that can be used to provide interface functionality if you are doing a framework or large program that needs it. Then again "Interface" is a bit questionable as an "OOP Concept"; its used in some implementations of an OOP language, and not used in anothers-- and what it means in one can differ from what it means in another. There's all kinds of other "concepts" of OOP that various people describe, and generally you can do them all in Python. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 30 01:15:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 22:15:59 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? If you're looking for a benchmark for object-orientedness, Smalltalk, not Java, is the canonical language to compare against. Anyway, to your three-pronged question: - Yes, Python supports polymorphism. I find it hard to think of an example of an OO language that doesn't. - Python does not support interfaces in the Java sense (although there are a few third-party libraries that add such support); neither does Smalltalk. Instead, both Smalltalk and Python use duck-typing to similar effect. See http://en.wikipedia.org/wiki/Duck_typing - Python supports encapsulation. Prefixing an attribute/method with an underscore indicates that other programmers should treat it as 'private'. However, unlike B&D languages, Python itself does nothing to enforce this privacy, leaving it instead to the good judgement of the programmer, under the philosophy that "We're all consenting adults here". This allows people to meddle with internals, at their own risk, if it ends up being absolutely necessary. The enforcement point is largely academic anyway, as most languages' reflection APIs let you poke at ostensibly "private" things. Cheers, Chris P.S. You appear to have posted the same message 3 times(!), which is a bit annoying for readers. -- Follow the path of the Iguana... http://rebertia.com From schickb at gmail.com Fri Jan 30 01:20:14 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 22:20:14 -0800 (PST) Subject: new.instancemethod questions References: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> Message-ID: <99775666-1264-4908-bc6a-37150543a5b3@y23g2000pre.googlegroups.com> On Jan 29, 8:51?pm, Brian Allen Vanderburg II wrote: > You can also create a bound method and manually bind it to the > instance. ?This is easier > > import types > a.f2 = types.MethodType(f1, a) > > a.f2() # prints object a Ah thanks, that is what I was looking for. I missed that because following types.MethodType in the docs is: types.UnboundMethodType An alternate name for MethodType Which made me think it was a type for UnboundMethods (aka functions). This: >>> help(types.UnboundMethodType) clears it up for me, but the docs are rather confusing. > These may work for most uses, but both have a problem that happens if > you need to make a copy of the instance. ?When you copy it, the copies > 'f1' will still call the function but using the old object > > a.f1() # prints object a > b = copy.copy(a) > b.f1() # still prints a > Ugh, that is a problem. I guess that means pickling won't work either.... Nope, "TypeError: can't pickle instancemethod objects". So does these mean there is no way to create a method on an instance at runtime that behaves just like a method that originated from the instance's class? -Brad From steven at REMOVE.THIS.cybersource.com.au Fri Jan 30 01:23:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 06:23:17 GMT Subject: Rounding to the nearest 5 References: Message-ID: On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > On Thu, 29 Jan 2009 16:06:09 -0800 > "todpose at hotmail.com" wrote: >> How can you make python round numbers to the nearest 5: >> >> Example: >> >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > That appears to be rounding to nearest 10, not 5. Clarify your > requirements first. Look again. 36 => 35. -- Steven From rt8396 at gmail.com Fri Jan 30 01:24:09 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 22:24:09 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 29, 11:53?pm, James Mills wrote: > On Fri, Jan 30, 2009 at 3:38 PM, r wrote: > > This observation leads me to two scientific and common sense synopsis. > > Either nobody here gives a rats pa'toote about Python, and/or they are > > all just a bunch of gutless worms too afraid to stand up to the 10 or > > so Perl/Ruby leeches who's infestation slowly drains the life-blood > > out of the Python Community, keeping it too weak to fight back. > > > > I for one am not e member of either the Perl or Ruby > fan club - and I don't think I will ever be :) However I"m not > going to go and start bagging those languages :) I prefer Python! > > I think you'll find a 3rd scenario: > > Python developers (those that develop Python) > and Python programmers (those that use Python) > just don't really care about politics, protest and > all the rubbish that goes on in this list :) > > cheers > James I totally agree James. I not saying anybody should just go around bashing this or that language, but i have seen many a ruffled feather at the mere mention of Python's greatness. I could understand if someone went over to the Perl group and started parroting off "Python rules!, Perl sucks!". This should be condemned. But i have also seen at this group very viscous attacks on people who just simply think Python is a good language and want to tell their Python friends how happy they are -- myself included. People would call a happy user of Python a fanboy or a Python zealot. This blows me away in the context of this group. check out this thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d15ed72979ba20f7/6195c98209dcc852?hl=en&lnk=gst&q=python+is+great#6195c98209dcc852 Here a happy python user shared his thoughts on the Python language. He compared Python as "more readable" than Perl and by god he is right about that, no sane person can honestly deny this fact. But like always some angry responses and warnings followed that this person should not criticize Perl, and veil threats were cast. This is the madness i refer too. From wuwei23 at gmail.com Fri Jan 30 01:25:39 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 22:25:39 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> On Jan 30, 4:15?pm, Chris Rebert wrote: > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing I haven't yet had reason to use them, but do Abstract Base Classes (introduced in 2.6/3.0) go some way to provide more defined interface support for Python? My assumption was that was what they'd generally be used for... From tony.clarke5 at googlemail.com Fri Jan 30 01:28:42 2009 From: tony.clarke5 at googlemail.com (tony.clarke5 at googlemail.com) Date: Thu, 29 Jan 2009 22:28:42 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: <83ecd69d-d120-4a78-aed4-3fb9d87b9b60@p36g2000prp.googlegroups.com> On Jan 30, 3:31?am, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > > On Jan 30, 12:29?am, Eric Kang wrote: > >> In python, I set: > > >> x=1 > >> y=3 > > >> z = x > >> x = y > >> y = z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory required to exchange two 32-bit > >> quantities? What would be the pseudocode that achieves this minimum? > > > How about: > > def transpose(x, y): > > ? ? print x, y, 'becomes: ', > > ? ? x = x + y > > ? ? y = x - y > > ? ? x = x - y > > ? ? print x, ' ', y > > > transpose(1,3) > > transpose (9,8) > > I'm not sure what the point of that function is. It doesn't actually swap > its arguments: > > >>> x = 23 > >>> y = 42 > >>> transpose(x, y) > > 23 42 becomes: ?42 ? 23>>> x > 23 > >>> y > > 42 > > And it certainly doesn't save memory, as the original poster asked: > > >>> import dis > >>> swap = compile('x, y = y, x', '', 'single') > >>> dis.dis(swap) > > ? 1 ? ? ? ? ? 0 LOAD_NAME ? ? ? ? ? ? ? ?0 (y) > ? ? ? ? ? ? ? 3 LOAD_NAME ? ? ? ? ? ? ? ?1 (x) > ? ? ? ? ? ? ? 6 ROT_TWO > ? ? ? ? ? ? ? 7 STORE_NAME ? ? ? ? ? ? ? 1 (x) > ? ? ? ? ? ? ?10 STORE_NAME ? ? ? ? ? ? ? 0 (y) > ? ? ? ? ? ? ?13 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?16 RETURN_VALUE > > >>> dis.dis(transpose) > > ? 2 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ? 3 PRINT_ITEM > ? ? ? ? ? ? ? 4 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ? 7 PRINT_ITEM > ? ? ? ? ? ? ? 8 LOAD_CONST ? ? ? ? ? ? ? 1 ('becomes: ') > ? ? ? ? ? ? ?11 PRINT_ITEM > > ? 3 ? ? ? ? ?12 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?15 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?18 BINARY_ADD > ? ? ? ? ? ? ?19 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 4 ? ? ? ? ?22 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?25 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?28 BINARY_SUBTRACT > ? ? ? ? ? ? ?29 STORE_FAST ? ? ? ? ? ? ? 1 (y) > > ? 5 ? ? ? ? ?32 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?35 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?38 BINARY_SUBTRACT > ? ? ? ? ? ? ?39 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 6 ? ? ? ? ?42 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?45 PRINT_ITEM > ? ? ? ? ? ? ?46 LOAD_CONST ? ? ? ? ? ? ? 2 (' ') > ? ? ? ? ? ? ?49 PRINT_ITEM > ? ? ? ? ? ? ?50 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?53 PRINT_ITEM > ? ? ? ? ? ? ?54 PRINT_NEWLINE > ? ? ? ? ? ? ?55 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?58 RETURN_VALUE > > The compiled code of the transpose function *alone* (not including all > the other associated parts) takes 59 bytes, or 472 bits. > > >>> len(transpose.func_code.co_code) > > 59 > > Even if it worked, that's hardly using less memory than a direct swap. > > -- > Steven Should have been more explicit about that: the values are swapped within the namespace of the function, the function is just for demonstration of the process. WIthout the function, this is the result: Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = -10 >>> y = 4 >>> x = x + y >>> y = x - y >>> x = x - y >>> x 4 >>> >>> y -10 >>> Need to think about swapping floats though. Tony From steven at REMOVE.THIS.cybersource.com.au Fri Jan 30 01:32:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 06:32:37 GMT Subject: Swapping values of two variables References: <400ebbae-a923-438a-85af-8ff451b77f10@t39g2000prh.googlegroups.com> Message-ID: On Thu, 29 Jan 2009 21:23:48 -0800, Kottiyath wrote: > Is it possible to swap two floats without a variable? In Python? Sure. f = 1.23 g = 2.87 f, g = g, f This idiom is independent of the types of the objects: x = "hello world" y = [1, 2.0, None, "xyz", {}] x, y = y, x In other languages? Hard to say. You *might* be able to use the XOR trick on floats, if you can access a float as a set of raw bytes. Same for strings, if they are the same length. Assuming that the floats are of similar size, not NaNs or INFs, not subject to overflow or underflow, and not subject to rounding error, you can do this trick: >>> f = 1.23 >>> g = 2.87 >>> f, g (1.23, 2.8700000000000001) >>> >>> f = f + g >>> g = f - g >>> f = f - g >>> f, g (2.8700000000000001, 1.2299999999999995) But notice the round-off error in g. It gets worse if your values are of radically different sizes: >>> f = 123.4 >>> g = 1.2e35 >>> f, g (123.40000000000001, 1.2000000000000001e+35) >>> f = f + g >>> g = f - g >>> f = f - g >>> f, g (1.2000000000000001e+35, 0.0) This really is a trick, not something you should be doing in production code. -- Steven From clp2 at rebertia.com Fri Jan 30 01:34:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 22:34:52 -0800 Subject: is python Object oriented?? In-Reply-To: <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> Message-ID: <50697b2c0901292234v71579f6cm4007471e1ca79799@mail.gmail.com> On Thu, Jan 29, 2009 at 10:25 PM, alex23 wrote: > On Jan 30, 4:15 pm, Chris Rebert wrote: >> - Python does not support interfaces in the Java sense (although there >> are a few third-party libraries that add such support); neither does >> Smalltalk. Instead, both Smalltalk and Python use duck-typing to >> similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing > > I haven't yet had reason to use them, but do Abstract Base Classes > (introduced in 2.6/3.0) go some way to provide more defined interface > support for Python? My assumption was that was what they'd generally > be used for... Ah, excellent point. I neglected to take ABCs into account. Smalltalk did have those as well. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ochichinyezaboombwa at yahoo.com Fri Jan 30 02:43:33 2009 From: ochichinyezaboombwa at yahoo.com (Mabooka-Mabooka Mbe-Mbe) Date: Thu, 29 Jan 2009 23:43:33 -0800 (PST) Subject: 'Address already in use' ... with TCPServer Message-ID: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Hi all, I bet everybody knows exactly what I am about to ask about: ''' A server serves for a while, then drops on its knees, tries to restart, but... the port is busy, the TCP says "Address already in use". ''' And, I think I know the answer: setsockopt(REUSEADDR)... The problem is: I am trying to use a very-high level far-away-from-socket class ("TCPServer"); or to be 100% honest, - an even higher-level async version of it (like in http://www.python.org/doc/2.6/library/socketserver.html?highlight=tcpserver#asynchronous-mixins). What I came up with so far is this: >>> from SocketServer import * >>> s = TCPServer( ('', 32123), None) >>> dir(s) ['RequestHandlerClass', '__doc__', '__init__', '__module__', 'address_family', 'allow_reuse_address', 'close_request', 'fileno', 'finish_request', 'get_request', 'handle_error', 'handle_request', 'process_request', 'request_queue_size', 'serve_forever', 'server_activate', 'server_address', 'server_bind', 'server_close', 'socket', 'socket_type', 'verify_request'] Aha! My bet is (was): >>> s.allow_reuse_address=1 should do the trick. But it doesn't. (:___. The question is: how to set up TCPServer correctly to reuse the port right away. Please give a hand. I acknowledge that I am trying to hack it rather then looking at all the web 1st: sorry if I am spamming this list while good documentation exists. But does it? :-#). -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 30 03:26:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 00:26:20 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 30, 5:24?pm, r wrote: [snip] > This blows me away in the context of this group. check out this > thread:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Here a happy python user shared his thoughts on the Python language. > He compared Python as "more readable" than Perl and by god he is right > about that, no sane person can honestly deny this fact. But like > always some angry responses and warnings followed that this person > should not criticize Perl, and veil threats were cast. > > This is the madness i refer too. Clicking on that link leads me to a 14-message thread in which the meat relates to Joe Stroud's problems with py2app, and there is only one reference to perl: Joe says: """No, I'm *using* py2app. I've been trying to use it for a couple of weeks now, with the generous help of such people as Robin Dunn, and I still don't have it quite working pro*perl*y. """ This doesn't appear to match the description. Perhaps the PSU has subverted my comp)(*&^%$#@! NO CARRIER From rt8396 at gmail.com Fri Jan 30 03:38:34 2009 From: rt8396 at gmail.com (r) Date: Fri, 30 Jan 2009 00:38:34 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 30, 2:26?am, John Machin wrote: [snip] > This doesn't appear to match the description. Perhaps the PSU has > subverted my comp)(*&^%$#@! > NO CARRIER Oops -- Good catch John, Even perfect people like myself make mistakes :). Here is the aforementioned thread where a Python user was chastised for daring to say Python has a clearer syntax than Perl thereby easing maintainability: OH NO! *big hand wave* http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a These Perl mongers have no business doing their mongling here, go to c.l.Perl! From mail at timgolden.me.uk Fri Jan 30 03:39:43 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 30 Jan 2009 08:39:43 +0000 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <4982BCCF.9090408@timgolden.me.uk> Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" Watch out. .reg files exported from the registry are typically in UTF16. Notepad and other editors will recognise this and display what you see above, but if you were to, say, do this: print repr (open ("blah.reg").read ()) You might see a different picture. If that's the case, you'll have to use the codecs module or decode the string you read. TJG From __peter__ at web.de Fri Jan 30 03:42:22 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jan 2009 09:42:22 +0100 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: Gabriel Genellina wrote: > But a loop doesn't define a new scope (only "def" and "class" used to > define one; now generator expressions do too). The new scope is not the > issue, but the fact that the right and left parts of a gen.expr. are > evaluated at different times. This wasn't obvious to me -- and still > isn't. If you rewrite the generator expression as a generator function you > don't get the same behaviour: > > print "genexpr" > A = [1,2,3] > B = 1 > g = (x+B for x in A) > A = [4,5,6] > B = 10 > print list(g) > # output: [11,12,13] > # A is evaluated at the time g is *defined* > # B is evaluated at the time g is *iterated* > print "genfunc" I think it helps understanding if you translate the above to >>> A = [1,2,3] >>> B = 1 >>> def f(a): ... for x in a: ... yield x+B ... >>> g = f(A) >>> A = [4,5,6] >>> B = 10 >>> print list(g) [11, 12, 13] This is not altogether unintuitive, but I think I would prefer if it worked like >>> A = [1,2,3] >>> B = 1 >>> def f(a, b): ... for x in a: ... yield x+b ... >>> g = f(A, B) >>> A = [4,5,6] >>> B = 10 >>> list(g) [2, 3, 4] i. e. every name were bound early. Of course this wouldn't help with locals() which would still be called in different scopes. Peter From deets at nospam.web.de Fri Jan 30 03:49:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 30 Jan 2009 09:49:46 +0100 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <6uft9aFf9kgbU1@mid.uni-berlin.de> anders schrieb: > Hi! > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO > > So a read all fils with dirchached > > Then a loop thru all files each files is read with readLines() and > after that scaned > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) > > What i like to find is just filenames for files with the customerdata > in, there can and often > is more than one, > > English is not my first language and i hope someone understand my > beginner question > what i am looking for is somting like > > if file.findInFile("LF01"): > ....... > > Is there any library like this ?? No. Because nobody can automagically infer whatever structure your files have. alex23 gave you a set of tools that you can use for full-text-search. However, that's not necessarily the best thing to do if things have a record-like structure. The canonical answer to this is then to use a database to hold the data, instead of flat files. So if you have any chance to do that, you should try & stuff things in there. Diez From googler.1.webmaster at spamgourmet.com Fri Jan 30 03:54:56 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 30 Jan 2009 00:54:56 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: Hi! Thanks. Well, os.py is found and all the others which don't need a library. I tested this: I execute Py_Main(...) in my app which executes the console interpreter and i tried to execute "import socket" which works. So Py_Main has something what my created PyRun_SimpleString doesn't have. Maybe the environment variables? Something has to be called in Py_Main which I should call, too. bye.. From mail at microcorp.co.za Fri Jan 30 04:08:29 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 30 Jan 2009 11:08:29 +0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: <01ca01c982bf$d609ca20$0d00a8c0@hendrik> "Gabriel Genellina" wrote: Of course this is clearly stated in the Language Reference "Variables used in the generator expression are evaluated lazily in a separate scope when the next() method is called for the generator object (in the same fashion as for normal generators). However, the in expression of the leftmost for clause is immediately evaluated in the current scope..." -- but this behaviour is still surprising and not obvious to me. ("not obvious" means that things could have been different, choosing this was a design decision). I am not so sure that it could have been done differently - I see it something like this: (going back to almost your original example, and reversing the position of globals and locals to make it shorter) >>> def foo(things): for thing in things: yield thing() #it is obvious this is in the local scope of foo >>> boo = foo([locals,globals]) >>> boo.next() {'thing': , 'things': [, ]} >>> and so it is, when you feed it the locals function Your other example would have been something like this: >>> def bar(things): for thing in things: yield thing # this just returns it unchanged >>> baz = bar([locals(),globals()]) # here we are still in the outer scope >>> baz.next() {'bar': , '__builtins__': , 'baz': , '__file__': 'E:\\Python24\\Lib\\idlelib\\idle.pyw', 'idlelib': , 'boo': , '__name__': '__main__', 'foo': , '__doc__': None} >>> and we get the top level locals back, as expected. Now I don't think that you could really do it differently - the right hand side of the generator expression is exactly like my passed argument "things", in all cases as far as I can see, and this means that the right hand side is evaluated when it is "passed", and the left hand side is whatever is done in the "for thing in things:" loop. All the generator expression does is that it saves you the trouble of defining the function - it kind of does it for you, and calls it, and returns the generator object, and throws the function away, all in one hit. (this is not necessarily the real mechanism, but the effect is exactly as if it were) I can't think of a way to do it differently - you have to make the "things" you want to iterate over, before you can do the iteration, and this is the cause of the timing difference and the outer level evaluation of the "passed" argument, and the different scope comes from the scope of the "ghost" function. Or is this view too simple? - Hendrik From gagsl-py2 at yahoo.com.ar Fri Jan 30 04:16:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 07:16:01 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe escribi?: > setsockopt(REUSEADDR)... > > What I came up with so far is this: >>>> from SocketServer import * >>>> s = TCPServer( ('', 32123), None) >>>> dir(s) > ['RequestHandlerClass', '__doc__', '__init__', '__module__', > 'address_family', 'allow_reuse_address', ... ] > > Aha! My bet is (was): >>>> s.allow_reuse_address=1 > should do the trick. It's too late then; bind() has already been called. The easiest way is to define your own derived class: import SocketServer class TCPServer(SocketServer.TCPServer): allow_reuse_address = True s = TCPServer(...) > I acknowledge that I am trying to hack it rather then looking at all the > web 1st: > sorry if I am spamming this list while good documentation exists. But > does it? Sure: http://docs.python.org/library/socketserver.html#SocketServer.allow_reuse_address The server classes support the following class variables: SocketServer.allow_reuse_address Whether the server will allow the reuse of an address. This defaults to False, and can be set in subclasses to change the policy. Reading the source may help too :) -- Gabriel Genellina From sjmachin at lexicon.net Fri Jan 30 04:21:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 01:21:25 -0800 (PST) Subject: parsing text from a file References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: On Jan 30, 7:39?pm, Tim Golden wrote: > Wes James wrote: > > If I read a windows registry file with a line like this: > > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > > Multicast|Edge=FALSE|" > > Watch out. .reg files exported from the registry are typically > in UTF16. Notepad and other editors will recognise this and > display what you see above, but if you were to, say, do this: > > print repr (open ("blah.reg").read ()) > > You might see a different picture. If that's the case, you'll > have to use the codecs module or decode the string you read. > Ha! That's why it appeared to print "LAND" instead of "LANDesk" -- it found and was printing "L\0A\0N\0D". From gagsl-py2 at yahoo.com.ar Fri Jan 30 05:09:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 08:09:21 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 06:54:56 -0200, escribi?: > Thanks. Well, os.py is found and all the others which don't need a > library. > I tested this: > > I execute Py_Main(...) in my app which executes the console > interpreter and > i tried to execute "import socket" which works. > > So Py_Main has something what my created PyRun_SimpleString doesn't > have. > Maybe the environment variables? Something has to be called in Py_Main > which I should call, too. (I assume you moved the executable to another directory - in your first post, your app was in some place, and python.exe/python25.dll in another) Py_Main, apart from processing arguments and some stuff related to the interactive mode, doesn't do much; a stripped down version would be: Py_SetProgramName(argv[0]); Py_Initialize(); PySys_SetArgv(...); PyRun_AnyFileExFlags(fd, filename, ...) WaitForThreadShutdown(); Py_Finalize(); -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Fri Jan 30 05:50:45 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 30 Jan 2009 02:50:45 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: <321ac876-bc29-418a-81c7-7ef5e0f23478@u18g2000pro.googlegroups.com> Hi! Okay, thats just the question. I did that what you wrote but it doesn't really works. What is, if Py_SetProgramName() gets a NULL Pointer, if argv[0] is empty? Well, the problem is, in my opinion that os.environ returns some paths in python.exe and in my embedded interpreter if I call os.environ in Py_Main(...) When I call it in my PyRun_SimpleString(...) it returns nothing. Hm.. thats really strange. From ove.svensson at jeppesen.com Fri Jan 30 06:00:31 2009 From: ove.svensson at jeppesen.com (Ove Svensson) Date: Fri, 30 Jan 2009 12:00:31 +0100 Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: <9gwscdm52o.fsf@overberg.jeppesensystems.com> Alejandro writes: > Hi: > > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. > > In each of the threads I have > > def run(self): > pid = os.getpid() > logger.critical('process ID: %s', pid) > > However, the reported PID is the father number, not the PID of the new > thread. Is there a way to get the PID of the thread? Pid is a process identifier. Threads are not processes. All your threads execute within the context if a single process, hence they should have the same pid. Threads may have a thread id but it is not the same as the pid. From python.list at tim.thechases.com Fri Jan 30 06:38:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 05:38:49 -0600 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982E6C9.8090405@tim.thechases.com> Steven D'Aprano wrote: > On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote: > >>> How can you make python round numbers to the nearest 5: >>> >>> Example: >>> >>> 3 => 0 >>> 8 => 10 >>> 23.2 => 20 >>> 36 => 35 >>> 51.5 => 50 >> I'm not sure *any* rounding system will give those results. > > Round towards zero. 8 => 10 ? One can round down with def round_down_to_n(x, ROUNDER = 5): return (x // ROUNDER) * ROUNDER but 8=>10 still fails to pass because 3 rounded down and 3+5 rounds up. So I call bogus data, or fall back to Miles' bogoround() function :) -tkc From a at nospam.org Fri Jan 30 06:50:08 2009 From: a at nospam.org (Armin) Date: Fri, 30 Jan 2009 12:50:08 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: > >> I have frozen a running application which is using SQLite with py2exe. >> When I start the exe file I see in the log file of the exe: >> Traceback (most recent call last): >> File "dpconf.py", line 666, in ? >> File "dpconf.py", line 251, in __init__ >> File "sqlite\main.pyc", line 255, in execute >> _sqlite.DatabaseError: no such table: genslaveopt >> >> The table exist in the database file ... no problem with the plain >> python version. > > Did you solve this problem? As you posted 4 related messages and the > last one might imply a solution to this first one... Yes, the distutil option 'data_files' failed to copy the database files to the dist directory. All dbopen calls have created empty db files ... --Armin PS: any comments on the data_files issue ?? > From nanoeyes at gmail.com Fri Jan 30 06:53:00 2009 From: nanoeyes at gmail.com (nanoeyes at gmail.com) Date: Fri, 30 Jan 2009 03:53:00 -0800 (PST) Subject: Noob question Message-ID: Hello? I'm currently installed Ubuntu 8.10. I'm not a Linux person, so I don't know a lot about it. The reason I installed Ubuntu is just for EMAN (http://blake.bcm.tmc.edu/eman/). EMAN 1.8 software requires Python 2.4 not 2.5 which comes with Ubuntu 8.10. I installed Python 2.4 by typing sudo apt-get install python2.4 Still EMAN doesn't work for me. Do I have to downgrade 2.5 to 2.4 or install lower version of Ubuntu? From gnewsg at gmail.com Fri Jan 30 07:16:42 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 30 Jan 2009 04:16:42 -0800 (PST) Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: On 30 Gen, 10:16, "Gabriel Genellina" wrote: > En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? > escribi?: > > > ? setsockopt(REUSEADDR)... > > > What I came up with so far is this: > >>>> from SocketServer import * > >>>> s = TCPServer( ('', 32123), None) > >>>> dir(s) > > ['RequestHandlerClass', '__doc__', '__init__', '__module__', ? > > 'address_family', 'allow_reuse_address', ... ] > > > Aha! My bet is (was): > >>>> s.allow_reuse_address=1 > > should do the trick. > > It's too late then; bind() has already been called. The easiest way is to ? > define your own derived class: > > import SocketServer > > class TCPServer(SocketServer.TCPServer): > ? ? ?allow_reuse_address = True > > s = TCPServer(...) What's even faster is setting the class attribute right after the module import: >>> import SocketServer >>> SocketServer.TCPServer.allow_reuse_address = True --- Giampaolo http://code.google.com/p/pyftpdlib From hongyi.zhao at gmail.com Fri Jan 30 07:27:37 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 20:27:37 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. Message-ID: Hi all, Suppose I've the entries like the following in my file: ------------------ 116.52.155.237:80 ip-72-55-191-6.static.privatedns.com:3128 222.124.135.40:80 217.151.231.34:3128 202.106.121.134:80 211.161.197.182:80 hpc.be.itu.edu.tr:80 static3-117-183.worldinternetworkcorporation.com:80 ------------------ Now, I want to convert the domain name to IP by using a python script, e.g., ip-72-55-191-6.static.privatedns.com:3128 should be converted into the following form: 72.55.191.6:3128 any hints on this? From info at egenix.com Fri Jan 30 07:30:01 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 30 Jan 2009 13:30:01 +0100 Subject: ANN: eGenix pyOpenSSL Distribution 0.8.0-0.9.8j-1 Message-ID: <4982F2C9.3050600@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.8.0-0.9.8j-1 An easy to install and use repackaged distribution of the pyOpenSSL Python interface for OpenSSL - available on Windows and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.8.0-0.9.8j-1-GA.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy to use installer that includes the most recent OpenSSL library versions in pre-compiled form. pyOpenSSL is an open-source Python add-on (http://pyopenssl.sf.net/) that allows writing SSL aware networking applications as well as certificate management tools. OpenSSL is an open-source implementation of the SSL protocol (http://www.openssl.org/). For more information, please see the product page: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ NEWS This fourth release of the eGenix.com pyOpenSSL Distribution upgrades the included OpenSSL libs to version 0.9.8j, which fixes a vulnerability found in earlier OpenSSL releases of the 0.9.8 branch: CVE-2008-5077 (http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5077). We have also enabled zlib compression support in OpenSSL for both the Linux and Windows builds, so OpenSSL client/servers can now negotiate on-the-fly zlib compression for SSL connections. Binaries are available for Linux x86 and x64 as well as Windows x86 and include pyOpenSSL 0.8.0 as well as pre-compiled and tested OpenSSL 0.9.8j libraries. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 30 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From clp2 at rebertia.com Fri Jan 30 07:33:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jan 2009 04:33:55 -0800 Subject: Want to write a script to do the batch conversion from domain name to IP. In-Reply-To: References: Message-ID: <50697b2c0901300433t7c21f844o6db2e30d85a5184b@mail.gmail.com> On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao wrote: > Hi all, > > Suppose I've the entries like the following in my file: > > ------------------ > 116.52.155.237:80 > ip-72-55-191-6.static.privatedns.com:3128 > 222.124.135.40:80 > 217.151.231.34:3128 > 202.106.121.134:80 > 211.161.197.182:80 > hpc.be.itu.edu.tr:80 > static3-117-183.worldinternetworkcorporation.com:80 > ------------------ > > Now, I want to convert the domain name to IP by using a python script, > e.g., > > ip-72-55-191-6.static.privatedns.com:3128 > > should be converted into the following form: > > 72.55.191.6:3128 > > any hints on this? PyDNS might be a helpful library for writing such a script -- http://pydns.sourceforge.net/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Fri Jan 30 07:44:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 10:44:22 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:16:42 -0200, Giampaolo Rodola' escribi?: > On 30 Gen, 10:16, "Gabriel Genellina" wrote: >> En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? >> escribi?: >> >> > ? setsockopt(REUSEADDR)... >> >> >>>> s.allow_reuse_address=1 >> > should do the trick. >> >> It's too late then; bind() has already been called. The easiest way is >> to define your own derived class: >> >> import SocketServer >> >> class TCPServer(SocketServer.TCPServer): >> ? ? ?allow_reuse_address = True >> >> s = TCPServer(...) > > What's even faster is setting the class attribute right after the > module import: > >>>> import SocketServer >>>> SocketServer.TCPServer.allow_reuse_address = True ...but potentially unsafe if the application uses other servers in other places. C'mon, defining the new class can be a one-liner also, why take the risk? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Jan 30 07:44:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 10:44:22 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:16:42 -0200, Giampaolo Rodola' escribi?: > On 30 Gen, 10:16, "Gabriel Genellina" wrote: >> En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? >> escribi?: >> >> > ? setsockopt(REUSEADDR)... >> >> >>>> s.allow_reuse_address=1 >> > should do the trick. >> >> It's too late then; bind() has already been called. The easiest way is >> to define your own derived class: >> >> import SocketServer >> >> class TCPServer(SocketServer.TCPServer): >> ? ? ?allow_reuse_address = True >> >> s = TCPServer(...) > > What's even faster is setting the class attribute right after the > module import: > >>>> import SocketServer >>>> SocketServer.TCPServer.allow_reuse_address = True ...but potentially unsafe if the application uses other servers in other places. C'mon, defining the new class can be a one-liner also, why take the risk? -- Gabriel Genellina From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 30 07:49:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 30 Jan 2009 13:49:38 +0100 Subject: Noob question In-Reply-To: References: Message-ID: <4982f762$0$5266$426a74cc@news.free.fr> nanoeyes at gmail.com a ?crit : > Hello? Hi. Ok, first, this is mostly OT here - your question should have gone to either the project's maintainer or any Ubuntu forum / mailing-list/whatever. > I'm currently installed Ubuntu 8.10. I'm not a Linux person, so I > don't know a lot about it. The reason I installed Ubuntu is just for > EMAN (http://blake.bcm.tmc.edu/eman/). EMAN 1.8 software requires > Python From the doc, it doesn't *require* Python at all: """ Some others are optional, like boost.python, Python if you need run Pyhton program in EMAN or want to program in Python with EMAN, you can turn this option off by switching ENABLE_PYTHON to off """ http://blake.bcm.tmc.edu/emanwiki/EMAN_COMPILE_UNIX > 2.4 not 2.5 which comes with Ubuntu 8.10. > > I installed Python 2.4 by typing sudo apt-get install python2.4 You'll probably need python2.4-dev too. > Still EMAN doesn't work for me. Did you try to recompile it (eventually providing the path to your python2.4 install) ? > Do I have to downgrade 2.5 to 2.4 Not sure this is an option - IIRC, Ubuntu 8.10 depends on Python 2.5. > or install lower version of Ubuntu? This would at best be a short/medium-term workaround. From reckoner at gmail.com Fri Jan 30 07:51:42 2009 From: reckoner at gmail.com (Reckoner) Date: Fri, 30 Jan 2009 04:51:42 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> <52018aea-b706-444e-a820-bd262cacf29d@y23g2000pre.googlegroups.com> Message-ID: <32b664b3-2243-4ad2-ac46-ae777cec9665@y23g2000pre.googlegroups.com> On Jan 28, 9:49?am, koranthala wrote: > On Jan 28, 10:39?pm,Reckoner wrote: > > > > > On Jan 28, 9:16 am, koranthala wrote: > > > > On Jan 28, 5:42 pm, koranthala wrote: > > > > > On Jan 28, 2:16 am,Reckoner wrote: > > > > > > I'm not sure this is possible, but I would like to have > > > > > a list of ?objects > > > > > > A=[a,b,c,d,...,z] > > > > > > where, ?in the midst of a lot of processing I might do something like, > > > > > > A[0].do_something_which_changes_the_properties() > > > > > > which alter the properties of the object 'a'. > > > > > > The trick is that I would like A to be mysteriously aware that > > > > > something about the ?object 'a' has changed so that when I revisit A, > > > > > I will know that the other items in the list need to be refreshed to > > > > > reflect the changes in A as a result of changing 'a'. > > > > > > Even better would be to automatically percolate the subsequent changes > > > > > that resulted from altering 'a' for the rest of the items in the list. > > > > > Naturally, all of these items are related in some parent-child > > > > > fashion. > > > > > > that might be a lot to ask, however. > > > > > > Any advice appreciated. > > > > > I think Python Cookbook has a recipe which deals with this. > > > > - 6.12 Checking an Instance for Any State Change. > > > > Were you able to get this? If not, let me know. I will try to type it > > > in here - (it is a big recipe, so not doing it now) > > > Actually, I have the python cookbook, but cannot find the recipe you > > mention. maybe I have an older version? > > > thanks. > > Mine is 2nd Edition. for posterity's sake, here's the recipe in question: import copy class ChangeCheckerMixin(object): containerItems = {dict: dict.iteritems, list: enumerate} immutable = False def snapshot(self): ''' create a "snapshot" of self's state -- like a shallow copy, but recursing over container types (not over general instances: instances must keep track of their own changes if needed). ''' if self.immutable: return self._snapshot = self._copy_container(self.__dict__) def makeImmutable(self): ''' the instance state can't change any more, set .immutable ''' self.immutable = True try: del self._snapshot except AttributeError: pass def _copy_container(self, container): ''' semi-shallow copy, recursing on container types only ''' new_container = copy.copy(container) for k, v in self.containerItems[type(new_container)] (new_container): if type(v) in self.containerItems: new_container[k] = self._copy_container(v) elif hasattr(v, 'snapshot'): v.snapshot( ) return new_container def isChanged(self): ''' True if self's state is changed since the last snapshot ''' if self.immutable: return False # remove snapshot from self.__dict__, put it back at the end snap = self.__dict__.pop('_snapshot', None) if snap is None: return True try: return self._checkContainer(self.__dict__, snap) finally: self._snapshot = snap def _checkContainer(self, container, snapshot): ''' return True if the container and its snapshot differ ''' if len(container) != len(snapshot): return True for k, v in self.containerItems[type(container)](container): try: ov = snapshot[k] except LookupError: return True if self._checkItem(v, ov): return True return False def _checkItem(self, newitem, olditem): ''' compare newitem and olditem. If they are containers, call self._checkContainer recursively. If they're an instance with an 'isChanged' method, delegate to that method. Otherwise, return True if the items differ. ''' if type(newitem) != type(olditem): return True if type(newitem) in self.containerItems: return self._checkContainer(newitem, olditem) if newitem is olditem: method_isChanged = getattr(newitem, 'isChanged', None) if method_isChanged is None: return False return method_isChanged( ) return newitem != olditem if __name__ == '__main__': class eg(ChangeCheckerMixin): def __init__(self, *a, **k): self.L = list(*a, **k) def __str__(self): return 'eg(%s)' % str(self.L) def __getattr__(self, a): return getattr(self.L, a) x = eg('ciao') print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o']) is changed = True # now, assume x gets saved, then...: x.snapshot( ) print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o']) is changed = False # now we change x...: x.append('x') print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o', 'x']) is changed = True From digitig at gmail.com Fri Jan 30 08:00:02 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 30 Jan 2009 13:00:02 +0000 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: 2009/1/30 Hung Vo : > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? It's not the role of the language to follow those concepts, it's the role of the programmer to follow those concepts if the programmer believes OO to be an appropriate paradigm for the task in hand. If the programmer decides that following those concepts is appropriate, Python will offer more than enough support. If the programmer decides that OO is not an appropriate paradigm but wants to follow procedural or functional concepts instead, Python will support that, too. Object orientation is not really a language property at all; it's a design approach. I've written object oriented programs in C, hand-coding the despatch tables, before anybody gave the name "object oriented" to that approach. When people talk about an object oriented language they either mean a language that allows a close mapping between an object oriented design and the actual code (Python does), or they mean a language that *requires* the code to conform to an object oriented design (Python doesn't). So the answer to "Is Python Object-Oriented" is either "yes" or "no", depending on what you're /really/ asking. -- Tim Rowe From gagsl-py2 at yahoo.com.ar Fri Jan 30 08:09:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 11:09:13 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: > Gabriel Genellina wrote: >> En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: >> >> Did you solve this problem? As you posted 4 related messages and the >> last one might imply a solution to this first one... > > Yes, the distutil option 'data_files' failed to copy the database files > to the dist directory. All dbopen calls have created empty db files ... > > PS: any comments on the data_files issue ?? Yes: read the section "Installing Additional Files" in the "Distributing Python Modules" document http://docs.python.org/distutils/setupscript.html#installing-additional-files Right at the end: "To install data files directly in the target directory, an empty string should be given as the directory." setup(..., data_files=[ ('', ['list/of/file/names', 'perhaps/including/source/directory']), ] ) -- Gabriel Genellina From feliphil at gmx.net Fri Jan 30 08:10:47 2009 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 30 Jan 2009 14:10:47 +0100 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <20090130141047.5bfee166.feliphil@gmx.net> > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? WingIDE Not open source, but by far the best that I've tried. Sincerely, Wolfgang From gagsl-py2 at yahoo.com.ar Fri Jan 30 08:20:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 11:20:36 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:44:22 -0200, Gabriel Genellina escribi?: Sorry the duplicate post! I've seen that some of my messages come twice. I'll try to diagnose and fix the problem (if possible...). -- Gabriel Genellina From jeff at jmcneil.net Fri Jan 30 08:41:29 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Fri, 30 Jan 2009 05:41:29 -0800 (PST) Subject: Want to write a script to do the batch conversion from domain name to IP. References: Message-ID: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> On Jan 30, 7:33?am, Chris Rebert wrote: > On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao wrote: > > Hi all, > > > Suppose I've the entries like the following in my file: > > > ------------------ > > 116.52.155.237:80 > > ip-72-55-191-6.static.privatedns.com:3128 > > 222.124.135.40:80 > > 217.151.231.34:3128 > > 202.106.121.134:80 > > 211.161.197.182:80 > > hpc.be.itu.edu.tr:80 > > static3-117-183.worldinternetworkcorporation.com:80 > > ------------------ > > > Now, I want to convert the domain name to IP by using a python script, > > e.g., > > > ip-72-55-191-6.static.privatedns.com:3128 > > > should be converted into the following form: > > > 72.55.191.6:3128 > > > any hints on this? > > PyDNS might be a helpful library for writing such a script --http://pydns.sourceforge.net/ > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Why not just use socket.gethostbyname? Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') '72.55.191.6' >>> From justinwyer at gmail.com Fri Jan 30 08:46:33 2009 From: justinwyer at gmail.com (Justin Wyer) Date: Fri, 30 Jan 2009 15:46:33 +0200 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: On Fri, Jan 30, 2009 at 1:51 AM, anders wrote: > Hi! > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO > > So a read all fils with dirchached > > Then a loop thru all files each files is read with readLines() and > after that scaned > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) Do you require this information in a python application, seems like you did this manually before? If not then python is the wrong tool for this job, you can simply use this command on a unix-like environment (install cygwin, if you are on windows) $ find -name "*" -exec grep -nH "LF01" {} \; | cut -d ":" -f 1 | sort | uniq Now if you do require this information inside a python app, I would just do the above in python filenames = [] searchCmd = "find -name \"*\" -exec grep -nH \"LF01\" {} \; | cut -d \":\" -f 1 | sort | uniq" searchp = Popen(searchCmd, shell=True, bufsize=4096, stdout=PIPE) for line in searchp.stdout: filenames.append(line.strip()) Thats my advise anyway, guess you can try some search libraries don't know of any mysql tho, the above will probably be faster than anything else. Cheers and good luck. -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Fri Jan 30 08:58:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 13:58:06 +0000 Subject: Adding a positive number and a negative number In-Reply-To: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> Message-ID: <4983076E.5090209@mrabarnett.plus.com> Eric Kang wrote: > In two?s complement representation, can adding one positive and one negative give you overflow? > No. From darcy at druid.net Fri Jan 30 09:05:58 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 09:05:58 -0500 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <20090130090558.cd36d40d.darcy@druid.net> On Fri, 30 Jan 2009 15:46:33 +0200 Justin Wyer wrote: > $ find -name "*" -exec grep -nH "LF01" {} \; > | cut -d ":" -f 1 | sort | uniq I know this isn't a Unix group but please allow me to suggest instead; $ grep -lR LF01 -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Fri Jan 30 09:07:27 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 09:07:27 -0500 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <20090130090727.e0fe500b.darcy@druid.net> On 30 Jan 2009 06:23:17 GMT Steven D'Aprano wrote: > On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > > That appears to be rounding to nearest 10, not 5. Clarify your > > requirements first. > > Look again. 36 => 35. You are correct. I should have ommitted my first sentence and emphasized the second. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From digitig at gmail.com Fri Jan 30 09:14:07 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 30 Jan 2009 14:14:07 +0000 Subject: search speed In-Reply-To: <6uft9aFf9kgbU1@mid.uni-berlin.de> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: 2009/1/30 Diez B. Roggisch : > No. Because nobody can automagically infer whatever structure your files > have. Just so. But even without going to a full database solution it might be possible to make use of the flat file structure. For example, does the "LF01" have to appear at a specific position in the input line? If so, there's no need to search for it in the complete line. *If* there is any such structure then a compiled regexp search is likely to be faster than just 'if "LF01" in line', and (provided it's properly designed) provides a bit of extra insurance against false positives. -- Tim Rowe From veerendra.cse at gmail.com Fri Jan 30 09:43:10 2009 From: veerendra.cse at gmail.com (Veerendra Ganiger) Date: Fri, 30 Jan 2009 20:13:10 +0530 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: Python is not purely object oriented programming, because we can write functions without any class. You are right, predefined class attributes are available when we write or execute a piece of python code without defining class, that means it's just using objects for it's purpose. It does not mean its purely object oriented. It all depends on implementation, I think even we can make "C" object oriented with proper implementation. On Thu, Jan 29, 2009 at 7:28 PM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? > > > On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > >> Muriel de Souza Godoi wrote: >> >>> Python offers support for object orientation, but it's not an >>> object-oriented language. >>> I mean, you can code a entire program in Python with no classes. So you >>> use it if you want to. >>> >>> It's not like java, which you must use a class to code a Hello World, but >>> Java isn't fully object-oriented, because it doesn't provide support for >>> multiple inheritance and it has primitive types (multiple interfaces and >>> wrappers to primitive types doesn't count :) ) >>> >>> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >>> Simula?), where everything is a class, even the primitive types. >>> >> >> well actually except keywords, everything is an object in python too, >> including of course primitive types (if you say so - practically python >> does not have them). >> >> Regards >> Tino >> > > > > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are interested > to be a part of it, please mail or call me. I will be happy to share and > inform - http://www.comat.com > -- regards, Veerendra -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Fri Jan 30 09:45:46 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 08:45:46 -0600 Subject: Adding a positive number and a negative number References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> Message-ID: <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> On 2009-01-30, MRAB wrote: > Eric Kang wrote: > >> In two's complement representation, can adding one positive >> and one negative give you overflow? >> > No. AFAIK, in Python adding integers never gives you overlow regardless of sign. -- Grant Edwards grante Yow! Is it clean in other at dimensions? visi.com From google at mrabarnett.plus.com Fri Jan 30 09:47:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 14:47:37 +0000 Subject: Swapping values of two variables In-Reply-To: References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: <49831309.7050509@mrabarnett.plus.com> Grant Edwards wrote: > On 2009-01-30, MRAB wrote: > >>> What is the minimum amount of extra memory required to exchange two >>> 32-bit quantities? What would be the pseudocode that achieves this >>> minimum? >> x ^= y >> y ^= x >> x ^= y >> >> This is really only of use when working in assembly language. > > And rarely then. ;) > > [Readability counts everywhere.] > It can be useful if you want to swap the contents of 2 registers in ARM assembly language: EOR r0,r0,r1 EOR r1,r0,r1 EOR r0,r0,r1 The quickest alternative is to use MOV: MOV r2,r0 MOV r0,r1 MOV r1,r2 The same number of instructions, program bytes, and clock cycles, but requiring an additional register! From hongyi.zhao at gmail.com Fri Jan 30 09:48:00 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 22:48:00 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil wrote: [snipped] >Why not just use socket.gethostbyname? > >Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >[GCC 4.3.2] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> import socket >>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >'72.55.191.6' >>>> See the following errors I in my case: $ python 'import site' failed; use -v for traceback Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import socket Traceback (most recent call last): File "", line 1, in ImportError: No module named socket >>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') Traceback (most recent call last): File "", line 1, in NameError: name 'socket' is not defined -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From hongyi.zhao at gmail.com Fri Jan 30 09:53:33 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 22:53:33 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Fri, 30 Jan 2009 22:48:00 +0800, Hongyi Zhao wrote: >On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil > wrote: >[snipped] >>Why not just use socket.gethostbyname? >> >>Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >>[GCC 4.3.2] on linux2 >>Type "help", "copyright", "credits" or "license" for more information. >>>>> import socket >>>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >>'72.55.191.6' >>>>> > >See the following errors I in my case: > >$ python >'import site' failed; use -v for traceback >Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) >[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin >Type "help", "copyright", "credits" or "license" for more information. >>>> import socket >Traceback (most recent call last): > File "", line 1, in >ImportError: No module named socket >>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >Traceback (most recent call last): > File "", line 1, in >NameError: name 'socket' is not defined Sorry for my carelessness. It's obviously due to the lack of the socket module in my case. Another issue is: how can I perform all of these steps in a python script? -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From alejandro.weinstein at gmail.com Fri Jan 30 09:56:10 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 06:56:10 -0800 (PST) Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <9gwscdm52o.fsf@overberg.jeppesensystems.com> Message-ID: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> On Jan 30, 4:00?am, Ove Svensson wrote: > Pidis a process identifier. Threads are not processes. All your threads > execute within the context if a single process, hence they should have > the samepid. Threads may have athreadid but it is not the same as thepid. According to this document (http://heather.cs.ucdavis.edu/~matloff/ Python/PyThreads.pdf), at least in Linux, threads are process: "Here each thread really is a process, and for example will show up on Unix systems when one runs the appropriate ps process-list command, say ps axH. The threads manager is then the OS." If you look at my original post, pstree does show different PIDs for the threads. Regards, Alejandro. From invalid at invalid Fri Jan 30 10:02:36 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 09:02:36 -0600 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: On 2009-01-30, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > >> I'm new to Python and also wondering about OOP in Python. >> >> I want to justify the above question (is Python Object-Oriented?). >> Does Python follow the concepts/practices of Encapsulation, >> Polymorphism and Interface, which are quite familiar to Java >> programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. As long as one doesn't then conflate message-passingness with object-orientedness. [Not that I'm implying Chris does, but given the OP's comments one worries that he might.] -- Grant Edwards grante Yow! I know things about at TROY DONAHUE that can't visi.com even be PRINTED!! From Peter.Rupp at acxiom.com Fri Jan 30 10:08:28 2009 From: Peter.Rupp at acxiom.com (Rupp Peter - prupp) Date: Fri, 30 Jan 2009 09:08:28 -0600 Subject: Hello..General question about TKinter. Message-ID: <5A80174CDBD2004CB0A1A069083813C90408D2A9@CWYMSX05.Corp.Acxiom.net> Hello, I am a fluent Python programmer, but have limited (zero) GUI experience. I need to write simple GUI's fairly quickly and would prefer to use TKinter for it's simplicity and longevity. (I tried to compile QT on both HPUX and Solaris with recent compilers...and compiles/builds failed....frustrating. In contrast, compiling tcl/TK libraries was a breeze!) The only thing I'm curious about now are the following: Is the TKinter python module actively maintained? And does it keep up with the latest TK widget sets, features and methods? I'm seeing that TK 8.0 and later have significant enhancements that are very attractive and I would like to use them from the Tkinter interface. At some point I will need them, and was thinking that I might have to build my own interface module to encapsulate their methods, and/or start writing code in tcl/tk. Not sure which would be easier. Thank you for your time. Kind regards, Peter ************************************************************************* The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not 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 resend this communication to the sender and delete the original message or any copy of it from your computer system. Thank you. ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Fri Jan 30 10:31:45 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Fri, 30 Jan 2009 07:31:45 -0800 (PST) Subject: Using equals operator without changing reference pointer References: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> Message-ID: <0fd92d9d-b1cd-4dc8-8c66-1f1a949922a8@w24g2000prd.googlegroups.com> On Jan 29, 8:03?pm, Terry Reedy wrote: > Erik Max Francis wrote: > > mark.sea... at gmail.com wrote: > > >> Is there a way to lock down myInst so that it still refers to the > >> original object, and is there some special member that will allow me > >> to override the equals operator in this case? ?Or is that simply > >> blasphemous against everything Python holds sacred? ?Certainly there > >> is some keyword that I don't know about. > > > No. ?The assignment operator with a bare name on the left hand side is > > not overridable. > > So that 'name = ob' *always* binds name to ob. ?That is one thing one > can depend on when reading Python code. > > > You can override attribute access, however, with > > .__getattr__/.__getattribute__. > > I presume that you have over-riden __setitem__ in addition to > __getitem__ so that myOb[0] = 1 sets the bit. You could add a branch to > __setitem__ (or define __setslice__ in 2.x) so that myOb[:] = 0x55 does > just what you want it to -- set all bits. ?Being able to get/set > contiguous bits might be something you want anyway. > > tjr > > PS. When asking about internal details, specify version of interest, as > there have been minor changes. OK. Thanks for your advice. From lists at cheimes.de Fri Jan 30 10:49:15 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 16:49:15 +0100 Subject: Swapping values of two variables In-Reply-To: References: Message-ID: Steven D'Aprano schrieb: > Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes > (96 bits) in size; a long will use as much memory as needed. If your > application needs to optimize a swap of two ints, then Python is probably > going to be much too memory-intensive for you. An int object consumes more than 12 bytes of memory. It depends on the system architecture, too. It's usually 16 bytes on a 32bit system and 24 bytes on a 64bit system. The actual size can be computed by sizeof(ptr) + sizeof(long) + sizeof(ssize_t). The size is rounded up to the next multiple of 8 bytes due to address alignment. Christian From linuxguy123 at gmail.com Fri Jan 30 11:03:04 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 30 Jan 2009 09:03:04 -0700 Subject: Why doesn't this work in Eclipse ? (Simple pexpect code that works in bash) Message-ID: <1233331384.3886.12.camel@localhost.localdomain> I'm trying to build a small Python app in Eclipse under Fedora 10. I have the following code: import os import sys import pexpect child = pexpect.spawn('/bin/bash') child.interact() When I run it in Eclipse, I get: Traceback (most recent call last): File "/home/xxx/workspace/FixPermissions/src/default/main.py", line 56, in child.interact() File "/usr/lib/python2.5/site-packages/pexpect.py", line 1489, in interact mode = tty.tcgetattr(self.STDIN_FILENO) termios.error: (22, 'Invalid argument') Yet if I run it in a bash shell, it works: $ python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> import sys >>> import pexpect >>> child = pexpect.spawn('/bin/bash') >>> child.interact() [xxx at localhost ~]$ ls [xxx at localhost ~]$ exit >>> >>> Why doesn't it run under Eclipse and how do I fix it so it does ? Thanks From exarkun at divmod.com Fri Jan 30 11:11:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 11:11:27 -0500 Subject: Get thread pid In-Reply-To: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> Message-ID: <20090130161127.12853.1507278417.divmod.quotient.511@henry.divmod.com> On Fri, 30 Jan 2009 06:56:10 -0800 (PST), Alejandro wrote: >On Jan 30, 4:00?am, Ove Svensson wrote: >> Pidis a process identifier. Threads are not processes. All your threads >> execute within the context if a single process, hence they should have >> the samepid. Threads may have athreadid but it is not the same as thepid. > >According to this document (http://heather.cs.ucdavis.edu/~matloff/ >Python/PyThreads.pdf), at least in Linux, threads are process: > >"Here each thread really is a process, and for example will show up on >Unix systems when one runs the appropriate ps process-list command, >say ps axH. The threads manager is then the OS." > >If you look at my original post, pstree does show different PIDs for >the threads. That document is quite misleading. Threads are not processes. They are *similar* to processes. They share many qualities of processes. But they are not processes. The "H" option for ps is *explicitly* documented (in recent versions of ps) as a way to make ps lie to you: H Show threads as if they were processes In times long since past, threads on Linux were even more like processes than they are now. Then, it might have even been defensible to say that they were processes, but that was an implementation detail. These days, threads on Linux are provided by something called NPTL (whereas they used to be provided by something called LinuxThreads). When using NPTL, threads do not have distinct PIDs. So, if you want to learn more about threads on Linux, you should check out the NPTL documentation. It is a much more reliable authority than any Python documentation regarding the nature of threads on Linux. Hope this helps, Jean-Paul From mabdelkader at gmail.com Fri Jan 30 11:17:55 2009 From: mabdelkader at gmail.com (ma) Date: Fri, 30 Jan 2009 11:17:55 -0500 Subject: Get thread pid In-Reply-To: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <9gwscdm52o.fsf@overberg.jeppesensystems.com> <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> Message-ID: <148918f0901300817w3ba6b74cqd611b081cd21d5e3@mail.gmail.com> Actually, the command given "ps axH" uses H which shows threads as if they were processes. If you check the pid of these "processes," you would find that they are all equivalent. On Fri, Jan 30, 2009 at 9:56 AM, Alejandro wrote: > On Jan 30, 4:00 am, Ove Svensson wrote: > > Pidis a process identifier. Threads are not processes. All your threads > > execute within the context if a single process, hence they should have > > the samepid. Threads may have athreadid but it is not the same as thepid. > > According to this document (http://heather.cs.ucdavis.edu/~matloff/ > Python/PyThreads.pdf), > at least in Linux, threads are process: > > "Here each thread really is a process, and for example will show up on > Unix systems when one runs the appropriate ps process-list command, > say ps axH. The threads manager is then the OS." > > If you look at my original post, pstree does show different PIDs for > the threads. > > Regards, > Alejandro. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eliben at gmail.com Fri Jan 30 11:30:53 2009 From: eliben at gmail.com (eliben) Date: Fri, 30 Jan 2009 08:30:53 -0800 (PST) Subject: relpath problem on windows Message-ID: I'm having a problem with 2.6's new os.path.relpath function. This is correct: relpath(r'd:\abc\jho', r'd:\abc') => 'jho' But this isn't: relpath(r'd:\jho', r'd:\\') => '..\jho' Neither is this: relpath(r'd:\jho', r'd:') => '..\..\..\jho' What am I missing? From alejandro.weinstein at gmail.com Fri Jan 30 11:33:53 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 08:33:53 -0800 (PST) Subject: Get thread pid References: Message-ID: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> On Jan 30, 9:11?am, Jean-Paul Calderone wrote: > [clarification about threads] Thank you for the clarification. I will reformulate my question: pstree and also ntop (but not top) show a number for each thread, like for instance: $pstree -p 9197 python(9197)???{python}(9555) ??{python}(9556) ??{python}(9557) ??{python}(9558) ??{python}(9559) ??{python}(9560) ??{python}(9561) ??{python}(9562) ??{python}(9563) ??{python}(9564) Is is possible to get the number corresponding to each thread? The reason I am interested is because one of my thread is hogging the CPU, and want to find which one is the culprit. Regards, Alejandro. From rNOSPAMon at flownet.com Fri Jan 30 11:34:25 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 30 Jan 2009 08:34:25 -0800 Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> <146f6796-37b5-4220-bdb1-5119cb3ac7e1@z6g2000pre.googlegroups.com> Message-ID: In article <146f6796-37b5-4220-bdb1-5119cb3ac7e1 at z6g2000pre.googlegroups.com>, Graham Dumpleton wrote: > On Jan 30, 9:53?am, Ron Garret wrote: > > In article <498171a5$0$3681$426a7... at news.free.fr>, > > ?Bruno Desthuilliers > > > > ?wrote: > > > Ron Garret a ?crit : > > > > In article , > > > > ?Aleksandar Radulovic wrote: > > > (snip) > > > >> Secondly, why are you restarting apache after code changes? In normal > > > >> circumstances, you shouldn't have to do that. > > > > > > I thought (and experiment confirms) that only the main WSGI app file > > > > gets reloaded automatically when it changes, not the libraries. > > > > > Depends on how you configure mod_wsgi. Read the part about "Process > > > Reloading Mechanism" here: > > >http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode > > > > I'm running Debian Etch, which means I have an older version of > > mod_wsgi, which means I don't have the process reloading mechanism. > > Back port available at: > > http://packages.debian.org/etch-backports/libapache2-mod-wsgi > > Graham Cool! Thanks! rg From rNOSPAMon at flownet.com Fri Jan 30 11:35:12 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 30 Jan 2009 08:35:12 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: <63cf7deb-f15c-4259-aa24-1b8da846876d@r41g2000prr.googlegroups.com> Message-ID: In article <63cf7deb-f15c-4259-aa24-1b8da846876d at r41g2000prr.googlegroups.com>, Graham Dumpleton wrote: > On Jan 30, 11:01?am, Ron Garret wrote: > > In article , > > ?Joshua Kugler wrote: > > > > > Ron Garret wrote: > > > > My question is: is this supposed to be happening? ?Or is this an > > > > indication that something is wrong, and if so, what? > > > > > You are probably just hitting a different instance of Apache, thus the > > > different process ID. > > > > Yep, that's what it turned out to be. ?I thought I had a > > WSGIDaemonProcess processes=1 directive in my config, but I had it in > > the wrong place (a different vhost) so it wasn't actually active. > > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > > But that leaves me wondering why the redirect would reliably trigger > > switching processes. ?The reason I thought that I had the correct > > configuration and only had one process is that when I reloaded the > > non-redirected page I *always* got the same process ID. ?How > > doesmod_wsgidecide which process ?(and which thread for that matter) to > > use? > > Details on process/threading in mod_wsgi available at: > > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > > When using WSGIDaemonProcess directive, if you want a single process > it is better to allow it to default to a single process and not have > 'processes=1'. As soon as you say 'processes=1' it will trigger > wsgi.multiprocess to be True rather than default of False. This may > sound counter intuitive, but is a little back door to allow > wsgi.multiprocess to be set to True somehow when distributing an > application across a cluster of machines where it does need to be True > even if each machine only has a single process for that application. > Tthat wsgi.multiprocess is True will not usually matter unless you are > trying to use debugging middleware that require that there only be a > single process. > > As to why you were getting a different process, because you were > actually running in embedded mode due to WSGIDaemonProcess/ > WSGIProcessGroup being in wrong context, then what process was used > was really up to Apache and how it works. Specifically it can have > multiple processes that can listen on the HTTP port (80). Because only > one should be listening at a time it uses a cross process mutex lock > to mediate access. When a process handles a request, it gives up the > lock. If using worker MPM then another thread in same process may get > lock, or for either worker MPM or prefork MPM, then another process > could get it. Which actually gets it is a bit indeterminate as simply > depends on which process the operating system lets have the lock next. > So, there is no strict rule one can say as to who would get it next. > > Graham > Graham Thanks! rg From x at x.xx Fri Jan 30 11:36:54 2009 From: x at x.xx (x) Date: Fri, 30 Jan 2009 09:36:54 -0700 (MST) Subject: python is a python Message-ID: <0f33f6af54280c637676176a8e0a89fd@pseudo.borked.net> python is a python From mabdelkader at gmail.com Fri Jan 30 11:53:46 2009 From: mabdelkader at gmail.com (ma) Date: Fri, 30 Jan 2009 11:53:46 -0500 Subject: Get thread pid In-Reply-To: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> References: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> Message-ID: <148918f0901300853w1d0ee23dv7b5993e0f3bc778c@mail.gmail.com> I think issue here is that you're invoking a system call (using either the subprocess module or os.popen*) from your threads. Those *are* external processes and will show up under pstree since they have a parent process. If you're using subprocess.Popen() the object that is returned has an attribute 'pid' that can be accessed (which would serve your purpose). Please note that *this is NOT a thread id* On Fri, Jan 30, 2009 at 11:33 AM, Alejandro wrote: > On Jan 30, 9:11 am, Jean-Paul Calderone wrote: > > [clarification about threads] > > Thank you for the clarification. I will reformulate my question: > > pstree and also ntop (but not top) show a number for each thread, like > for instance: > > $pstree -p 9197 > python(9197)???{python}(9555) > ??{python}(9556) > ??{python}(9557) > ??{python}(9558) > ??{python}(9559) > ??{python}(9560) > ??{python}(9561) > ??{python}(9562) > ??{python}(9563) > ??{python}(9564) > > Is is possible to get the number corresponding to each thread? > > The reason I am interested is because one of my thread is hogging the > CPU, and want to find which one is the culprit. > > Regards, > Alejandro. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at divmod.com Fri Jan 30 11:55:50 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 11:55:50 -0500 Subject: Announcing Pyflakes 0.3.0 In-Reply-To: 0 Message-ID: <20090130165550.12853.274533186.divmod.quotient.527@henry.divmod.com> I am proud to announce the release of Pyflakes 0.3.0. This release fixes several bugs, improves compatibility with recent versions of Python, and new flake checks. Pyflakes is a static analysis tool for Python source. It is focused on identifying common errors quickly without executing Python code. It is a handy supplement to your project's test suite. Read more about Pyflakes and the 0.3.0 release on the website: http://divmod.org/trac/wiki/DivmodPyflakes Jean-Paul Calderone Divmod, Inc. From apt.shansen at gmail.com Fri Jan 30 11:58:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 30 Jan 2009 08:58:02 -0800 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> On Fri, Jan 30, 2009 at 12:38 AM, r wrote: > On Jan 30, 2:26 am, John Machin wrote: > [snip] > > This doesn't appear to match the description. Perhaps the PSU has > > subverted my comp)(*&^%$#@! > > NO CARRIER > > Oops -- Good catch John, > Even perfect people like myself make mistakes :). Here is the > aforementioned thread where a Python user was chastised for daring to > say Python has a clearer syntax than Perl thereby easing > maintainability: OH NO! *big hand wave* > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a > > These Perl mongers have no business doing their mongling here, go to > c.l.Perl! He was not chastised, nor threatened as you previously said; he was welcomed to Python in all of its awesomeness, and given a pointer about community etiquette. "excessive Perl bashing" ... "considered tasteless" ... Come on. That's so mild of a warning that you can barely call it that. Considering the comment after "the occasional snide comment should be fine :-)" complete with a smiley even should make it very clear that a simple and *friendly* pointer on getting along in a new community was given. It was great advice, too. No one has a problem with talking about Python's strengths, or how good Python has worked for them; or even comparing it to other languages in a reasoned way (though those conversations have all been had ten thousand years ago)... its the vitriolic bashing of other languages that isn't wanted because there's no point to it at all. It does nothing at all but make us look like mongers, zealots, and childish to boot. Advocating the language is a great thing to do. Evangelizing it makes us look like idiots. You catch grief because your evangelization of the language is *so* completely over the top that it comes off almost as trollish-- the reverse-troll technique is not all that uncommon. Like with http://groups.google.com/group/comp.lang.python/msg/b8a079b8b780be19 -- and the talk of throwing off shackles and embracing the Freedom That Python Gives You. Its so completely excessive that it can't even be taken seriously. You ask if community matters to Python? It does, absolutely. I just don't think you understand that community. Its there. Its full of tons of people in many walks of life who use Python to get things done, and who absolutely love doing so -- its full of people who use the language and the tools it provides to accomplish real things easier, faster (to accomplish a goal, not to execute a chunk of code) and without sacrificing long-term maintainability. My impression of the community is simply that its a more quiet one: advocacy instead of evangelism. I'd rather talk about how to accomplish something in a Pythonic way, or how to help use Python to solve your problems in a way that is natural to do in Python -- and convert you that way, then to worry about a "war with Ruby" and such nonsense. Personally, I love Python. I wouldn't take a job writing in either Perl or Ruby: but those who like that language are welcome to it. Personally, I work for a division in our company that has converted over the last few years our entire software line from an old, Windows-only mix of C and VCL-stuff, to a serious mid-sized product which recently clocked in at about 165k lines of Python code (about 600k more in third party libs!) that's fast, effective, flexible, multi-platform and highly responsive to our customer's evolving needs. We actually did a complete rewrite from the ground up -- a dangerous thing to do, but the legacy product was so out of date that it had to be done... and I don't think any other set of tools would have been able to let us do so as well, in as short of a period of time, or as iteratively and in cooperation with our customer base. I have tons of positive things to say about Python: lots of people in The Community do. And we've all worked with other languages and have reasons why we don't like those tools, and people are fine to share those reasons. But that's a different thing then flinging bile and ranting about how horrible Language-X is or how Perfect-For-All-Things Python is. --Stephen P.S. Sorry for waxing verbosely. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Fri Jan 30 11:58:16 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 08:58:16 -0800 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: Tim Rowe wrote: > .... But even without going to a full database solution it might > be possible to make use of the flat file structure. For example, does > the "LF01" have to appear at a specific position in the input line? If > so, there's no need to search for it in the complete line. *If* there > is any such structure then a compiled regexp search is likely to be > faster than just 'if "LF01" in line', and (provided it's properly > designed) provides a bit of extra insurance against false positives. Clearly this is someone who regularly uses grep or perl. If you know the structure, like the position in a line, something like the following should be fast: with open(somename) as source: for n, line in enumerate(source): if n % 5 == 3 and line[5 : 9] == 'LF01': print ('Found on line %s: %s' % (1 + n, line.rstrip()) Be careful with your assertion that a regex is faster, it is certainly not always true. Measure speed, don't take mantras as gospel. --Scott David Daniels Scott.Daniels at Acm.Org From invalid at invalid Fri Jan 30 12:05:11 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 11:05:11 -0600 Subject: Swapping values of two variables References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: > Grant Edwards wrote: > > On 2009-01-30, MRAB wrote: > > > >>> What is the minimum amount of extra memory required to exchange two > >>> 32-bit quantities? What would be the pseudocode that achieves this > >>> minimum? > >> x ^= y > >> y ^= x > >> x ^= y > >> > >> This is really only of use when working in assembly language. > > > > And rarely then. ;) > > > > [Readability counts everywhere.] > > It can be useful if you want to swap the contents of 2 registers in ARM > assembly language: > > EOR r0,r0,r1 > EOR r1,r0,r1 > EOR r0,r0,r1 > > The quickest alternative is to use MOV: > > MOV r2,r0 > MOV r0,r1 > MOV r1,r2 > > The same number of instructions, program bytes, and clock > cycles, but requiring an additional register! Yea, I guess the ARM's SWP instruction only works on register<->memory. That said, I don't remember ever needing to swap the contents of two register when working in ARM assembly language (yes I have done some). I always just use the value in the register where it is. Swap with top of stack (for which the SWP instruction works) can be useful for implementing some sorts of stack-based VMs, but register-register swap just doesn't seem to be something one needs to do (which probably explains why there's no instruction to do it). Given the choice between the cryptic version that doesn't require a third register, and the obvious version that uses a third register, I'll usually choose the latter. There aren't that many people left who'll recognize what the triple-xor sequence is doing -- so if I ever would use it, I'd probably make it a macro. -- Grant Edwards grante Yow! This ASEXUAL PIG at really BOILS my BLOOD visi.com ... He's so ... so ... URGENT!! From Scott.Daniels at Acm.Org Fri Jan 30 12:10:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 09:10:44 -0800 Subject: Adding a positive number and a negative number In-Reply-To: <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: Grant Edwards wrote: > On 2009-01-30, MRAB wrote: >> Eric Kang wrote: >>> In two's complement representation, can adding one positive >>> and one negative give you overflow? >> No. > AFAIK, in Python adding integers never gives you overlow > regardless of sign. Right, but he wants his homework answer. From exarkun at divmod.com Fri Jan 30 12:10:55 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 12:10:55 -0500 Subject: Get thread pid In-Reply-To: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> Message-ID: <20090130171055.12853.141462103.divmod.quotient.532@henry.divmod.com> On Fri, 30 Jan 2009 08:33:53 -0800 (PST), Alejandro wrote: >On Jan 30, 9:11?am, Jean-Paul Calderone wrote: >> [clarification about threads] > >Thank you for the clarification. I will reformulate my question: > >pstree and also ntop (but not top) show a number for each thread, like >for instance: > >$pstree -p 9197 >python(9197)???{python}(9555) > ??{python}(9556) > ??{python}(9557) > ??{python}(9558) > ??{python}(9559) > ??{python}(9560) > ??{python}(9561) > ??{python}(9562) > ??{python}(9563) > ??{python}(9564) > >Is is possible to get the number corresponding to each thread? > >The reason I am interested is because one of my thread is hogging the >CPU, and want to find which one is the culprit. I think someone mentioned calling gettid using ctypes earlier in this thread. Unfortunately, this is somewhat convoluted: exarkun at charm:~$ python Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes, os, threading, time >>> os.system("pstree -p " + str(os.getpid())) python(11427)???sh(11429)???pstree(11430) 0 >>> threading.Thread(target=time.sleep, args=(1000,)).start() >>> os.system("pstree -p " + str(os.getpid())) python(11427)???sh(11436)???pstree(11437) ??{python}(11431) 0 >>> ctypes.CDLL('libc.so.6').syscall(224) 11427 >>> 224 comes from grepping /usr/include for SYS_gettid. This is Linux specific, and probably even architecture specific. For a quick debug hack, perhaps this is good enough, though. Jean-Paul From google at mrabarnett.plus.com Fri Jan 30 12:13:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 17:13:53 +0000 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> Message-ID: <49833551.9000701@mrabarnett.plus.com> Stephen Hansen wrote: > On Fri, Jan 30, 2009 at 12:38 AM, r > wrote: > > On Jan 30, 2:26 am, John Machin > wrote: > [snip] > > This doesn't appear to match the description. Perhaps the PSU has > > subverted my comp)(*&^%$#@! > > NO CARRIER > > Oops -- Good catch John, > Even perfect people like myself make mistakes :). Here is the > aforementioned thread where a Python user was chastised for daring to > say Python has a clearer syntax than Perl thereby easing > maintainability: OH NO! *big hand wave* > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a > > > These Perl mongers have no business doing their mongling here, go to > c.l.Perl! > > > He was not chastised, nor threatened as you previously said; he was > welcomed to Python in all of its awesomeness, and given a pointer about > community etiquette. > [snip] > I have tons of positive things to say about Python: lots of people in > The Community do. And we've all worked with other languages and have > reasons why we don't like those tools, and people are fine to share > those reasons. But that's a different thing then flinging bile and > ranting about how horrible Language-X is or how Perfect-For-All-Things > Python is. > [snip] It's probably unpythonic to bash other languages. Python is so good that there's no need. :-) From ofzhengyi at gmail.com Fri Jan 30 12:19:21 2009 From: ofzhengyi at gmail.com (=?GB2312?B?1qPS5Q==?=) Date: Sat, 31 Jan 2009 01:19:21 +0800 Subject: What's new in 3.0 about threading? Message-ID: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> Hello I have questions about threading: import threading class myThread(threading.Thread): def run(self): print('hello,threads') if __name__=='__main__': threads=myThread() threads.start() Above program does't work at 'Run Module' in IDLE,but it works well under executing scripts.Is it anything wrong? WindowXP,Python 3.0 Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gduzan at gmail.com Fri Jan 30 12:21:49 2009 From: gduzan at gmail.com (Gary Duzan) Date: Fri, 30 Jan 2009 09:21:49 -0800 (PST) Subject: Why doesn't this work in Eclipse ? (Simple pexpect code that works in bash) References: Message-ID: On Jan 30, 11:03?am, Linuxguy123 wrote: > I'm trying to build a small Python app in Eclipse under Fedora 10. > > I have the following code: > > import os > import sys > import pexpect > > child = pexpect.spawn('/bin/bash') > child.interact() > > When I run it in Eclipse, I get: > > Traceback (most recent call last): > ? File "/home/xxx/workspace/FixPermissions/src/default/main.py", line > 56, in > ? ? child.interact() > ? File "/usr/lib/python2.5/site-packages/pexpect.py", line 1489, in > interact > ? ? mode = tty.tcgetattr(self.STDIN_FILENO) > termios.error: (22, 'Invalid argument') > > Yet if I run it in a bash shell, it works: > > [ ... ] > > Why doesn't it run under Eclipse and how do I fix it so it does ? That code assumes the stdin of the parent is a real (or possibly pseudo-) terminal, which appears not to be the case for programs run through Eclipse. Gary Duzan From ronaldjweiss at gmail.com Fri Jan 30 12:25:26 2009 From: ronaldjweiss at gmail.com (ronaldjweiss at gmail.com) Date: Fri, 30 Jan 2009 09:25:26 -0800 (PST) Subject: Python Developer needed for Greenwich, CT assignment Message-ID: Senior Python Programmer needed to develop, enhance and expand a Trade Capture application at a hedge fund client. The technical platform includes MySQL running both on Windows and UNIX. Requirements: 3-6+ years solid Python development skills and experience in the brokerage industry a must. SQL and UNIX required. This is a 6 - 12 month contract that could extend indefinitely. Ron Weiss THE BMW GROUP, INC. Technology placement in the securities industry 40 Exchange Place, Suite 700, New York, NY 10005 212-943-8800 ronw at careerobject.com From haag at lsu.edu Fri Jan 30 12:36:45 2009 From: haag at lsu.edu (Alaric Haag) Date: Fri, 30 Jan 2009 11:36:45 -0600 Subject: Odd syntactic NON-error? Message-ID: Hello, I just noticed that I've been successfully importing a module I wrote which contains a class definition that begins with (docstring removed): class TDF(): def __init__(self, name='', mode=tscan. GP_NOCLOBBER): Note the "space" which shouldn't be here---^ I'm running Python 2.5.2. What does the interpreter "think" I'm doing? It's not flagged by pylint either, so I suspect there's a reasonable explanation. Alaric From exarkun at divmod.com Fri Jan 30 12:39:48 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 12:39:48 -0500 Subject: Odd syntactic NON-error? In-Reply-To: Message-ID: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> On Fri, 30 Jan 2009 11:36:45 -0600, Alaric Haag wrote: >Hello, > >I just noticed that I've been successfully importing a module I wrote >which contains a class definition that begins with (docstring removed): > >class TDF(): > def __init__(self, name='', mode=tscan. GP_NOCLOBBER): > >Note the "space" which shouldn't be here---^ The space is irrelevant. >>> object. __init__ >>> object.__init__ is object. __init__ True >>> Jean-Paul From bjracine at glosten.com Fri Jan 30 13:19:32 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Fri, 30 Jan 2009 10:19:32 -0800 Subject: Rounding to the nearest 5 In-Reply-To: <20090130090727.e0fe500b.darcy@druid.net> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> Doesn't this work? round_by_5.py >>>>>>>>>>>>>>>>>>>>>>> import sys def round_by_5(x= sys.argv[0]): x = x/5. x = round(x) x = x*5 print(x) return x Ben R. -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of D'Arcy J.M. Cain Sent: Friday, January 30, 2009 6:07 AM To: Steven D'Aprano Cc: python-list at python.org Subject: Re: Rounding to the nearest 5 On 30 Jan 2009 06:23:17 GMT Steven D'Aprano wrote: > On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > > That appears to be rounding to nearest 10, not 5. Clarify your > > requirements first. > > Look again. 36 => 35. You are correct. I should have ommitted my first sentence and emphasized the second. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list From noama at answers.com Fri Jan 30 13:36:32 2009 From: noama at answers.com (Noam Aigerman) Date: Fri, 30 Jan 2009 20:36:32 +0200 Subject: A replacement to closures in python? Message-ID: <749CACF29BDFB64E9F80189ECD778688048FEB3C@jermail1.atomant.net> Hi, I want to create an array of functions, each doing the same thing with a change to the parameters it uses... something like: arr=['john','terry','graham'] funcs=[] for name in arr: def func(): print 'hello, my name is '+name funcs.append(func) for f in funcs: f() And I would like that to print hello, my name is john hello, my name is terry hello, my name is graham of course... Now I understand why the above code doesn't work as I want it to, but is there some simple workaround for it? Thanks, Noam -------------- next part -------------- An HTML attachment was scrubbed... URL: From berankin99 at yahoo.com Fri Jan 30 13:52:07 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Fri, 30 Jan 2009 10:52:07 -0800 (PST) Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Message-ID: <296542.92832.qm@web112216.mail.gq1.yahoo.com> > > > I am trying to build python 2.6 on a machine (web server) that I do not have > root access to. (has 2.4 installed) > > > > Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1. > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: error: > syntax error before '*' token > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: warning: > function declaration isn't a prototype > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In function > `CFuncPtr_nonzero': > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: error: > `self' undeclared (first use in this function) > > Mmm... my 2.6.1 source show different line numbers, maybe you should check it's > the right file? > Wow, good catch. I just re-downloaded the archive and it works fine. I know for certain that I did no editing to the files, and even tried expanding the original tar.gz a couple of times. There must be a corrupted package somewhere among the official Python mirrors. (Sadly, I overwrote the old tar.gz file when I got the new one.) From aahz at pythoncraft.com Fri Jan 30 13:56:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 10:56:20 -0800 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> Message-ID: In article <631e2879-6171-417e-8254-7f78c8cfc685 at i24g2000prf.googlegroups.com>, alex23 wrote: > >If you're having to set up your imports in a specific order, odds are >you have either a circular dependency or are overusing 'from >import *'. You should -never- (IMO) do something like 'from library> import x, y, z' in module 'a' and then 'from a import *' in >module 'b'. If 'b' uses x, y & z, it should import them itself. If you >-must- use 'import *', specify exactly what should be exported via >'__all__'...in most cases, it should be restricted to only objects >defined within that module. There's one other way to run into this problem: I forget the exact mechanics, but if you mix up absolute and relative imports for modules inside packages, you can get namespace problems. (It's also possible newer versions of Python don't have this issue.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From alejandro.weinstein at gmail.com Fri Jan 30 13:56:30 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 10:56:30 -0800 (PST) Subject: Get thread pid References: Message-ID: <76a44a3a-9eb5-4de1-9fd1-545b6b37aca7@r15g2000prd.googlegroups.com> On Jan 30, 10:10?am, Jean-Paul Calderone wrote: > ? ? >>> ctypes.CDLL('libc.so.6').syscall(224) Great! ctypes.CDLL('libc.so.6').syscall(224) does the trick. Thank you. Regards, Alejandro. From apt.shansen at gmail.com Fri Jan 30 14:02:44 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 30 Jan 2009 11:02:44 -0800 (PST) Subject: A replacement to closures in python? In-Reply-To: <749CACF29BDFB64E9F80189ECD778688048FEB3C@jermail1.atomant.net> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From jon at ffconsultancy.com Fri Jan 30 14:12:49 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Fri, 30 Jan 2009 19:12:49 +0000 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> I had hoped someone else would correct you but they haven't. So... Xah Lee wrote: > Here are some examples of a function that returns a function as > result, but is not currying. > > Mathematica example: > > f[n_]:=Function[n^#]; > f[7][2] > (* returns 49 *) > > Emacs lisp example: > > (defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) ) > (funcall (f 7) 2) > > Perl example: > > sub f {$n=$_[0]; sub { $n ** $_[0]} }; > print &{ f(7) } (2); > > Javascript example: > > function f(n) {return function (x) {return Math.pow(x,n);}; } > alert (f(7) (2)); > > However, the above are not languages that support currying, That is incorrect. Mathematica, Lisp, Perl and Javascript all support currying. > which is a feature that Haskell & Ocaml has. That is correct. Here is an OCaml equivalent: let f = fun n -> fun m -> n ** m > To be more concrete, in the context of a given computer language, to > say that it support curring, is to mean that the compiler understand > the concept to certain degree. More to the point, the language is > inherently able to take a function of more than one arg and > deconstruct it to several functions of single arg. That is incorrect. You only need a language with first-class functions. I believe you are confusing the syntactic support in OCaml and Haskell for something more. It simply allows you to rewrite the above as: let f n m = n ** m or: let f = fun n m -> n ** n -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From tim at burlyhost.com Fri Jan 30 14:22:01 2009 From: tim at burlyhost.com (Tim Greer) Date: Fri, 30 Jan 2009 11:22:01 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> Message-ID: Jon Harrop wrote: > I had hoped someone else would correct you but they haven't. So... The lack of replies aren't about anyone correcting him or not, it's that the guy just posts anything he can to spamvertize his site and tell everyone how brilliant he thinks he is. It's just a method he uses to try and feel important and also get people to his site (and for the search engines to rank it higher). He's a known troll and spammer in a lot of groups due to this. The guy rarely has anything relevant to the groups he posts to. Most people I know of have come to just filter out his posts. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From ivan.illarionov at gmail.com Fri Jan 30 14:58:10 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Fri, 30 Jan 2009 11:58:10 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> r wrote: > Where are the community projects supporting Python? -- besides the > core devlopment. Seem s that nobody is interested unless their pay-pal > account is involved. I find this all quite disappointing. Hi r, Can you just type import antigravity and join us up there? Hatred for Ruby and Perl seems to oppose natural Python forces, that's why you can't see community spirit. Let your hatred go and start flying already. -- Ivan From torriem at gmail.com Fri Jan 30 15:14:40 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 30 Jan 2009 13:14:40 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <49835FB0.5060903@gmail.com> Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? I'd say that actually Python uses encapsulation extensively throughout the language. Every object in Python has attributes. Thus every object encapsulates (contains) attributes (which are themselves objects). I think the term "encapsulation" is often misinterpreted by some (Java programmers in particular) to mean some kind of enforced black-box methodology. In effect they feel that getters and setters is the definition of encapsulation. This is really not true, especially if you go back to the original OO languages, such as Smalltalk. So if you are asking, does python enforce some kind of bizarre black box access semantics (requiring getters and setters), the answer is an emphatic "no!" Interfaces have nothing to do with OO programming as a matter of a fundamental principle. Interfaces exist in Java to compensate for flaws/features in the language. Particularly the lack of multiple inheritance which is a blessing/curse in Java. Python just doesn't need interfaces. Protocols for communication with an object do not need to be formally enforced. For example the popular database API that most python database libraries use just makes sure it implements certain methods. Thus it doesn't matter if I'm using mysql, postgresql, or oracle. I still call the object's "connect" method. Such a breath of fresh air compared to Java, in my opinion. Such informality can be a bit of a hindrance to some I guess. After this entire thread, it's funny that people are still chiming in saying, "so is it really OOP" after having it explained in so many ways. From sjmachin at lexicon.net Fri Jan 30 15:22:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 20:22:16 +0000 (UTC) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <20090130090558.cd36d40d.darcy@druid.net> Message-ID: D'Arcy J.M. Cain druid.net> writes: > > On Fri, 30 Jan 2009 15:46:33 +0200 > Justin Wyer gmail.com> wrote: > > $ find -name "*" -exec grep -nH "LF01" {} \; > > | cut -d ":" -f 1 | sort | uniq > > I know this isn't a Unix group but please allow me to suggest instead; > > $ grep -lR LF01 and if the OP is on Windows: an alternative to cygwin is the GnuWin32 collection of Gnu utilities ported to Windows. See http://gnuwin32.sourceforge.net/ ... you'll want the Grep package but I'd suggest the CoreUtils package as worth a detailed look, and do scan through the whole list of packages while you're there. HTH, John From torriem at gmail.com Fri Jan 30 15:32:00 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 30 Jan 2009 13:32:00 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <498363C0.5070909@gmail.com> Veerendra Ganiger wrote: > Python is not purely object oriented programming, because we can write > functions without any class. > You are right, predefined class attributes are available when we write or > execute a piece of python code without defining class, that means it's just > using objects for it's purpose. It does not mean its purely object oriented. To be clear, python does not force you to lay out your code according to some strict object-oriented paradigm. But Python itself is still purely object-oriented, as is your script when parsed. This function without a class that you mentioned, is in fact an object with attributes. You can pass a function around just like any other object. Even calling a function is invoked like so: myfunc.__call__(params) So necessitating that code be inside a class has nothing to do with object-oriented programming. Let's not forget that classes are themselves objects (metaobjects in smalltalk parlance if I recall correctly). Now python does not have any way besides lambda expressions of creating unbound function objects, but in practice this doesn't matter as I can rebind names freely. I can still do: a=myfunc myfunc=some other expression or object > It all depends on implementation, I think even we can make "C" object > oriented with proper implementation. Indeed, any code based on gobject libraries can be object-oriented in design and function. From stefan_ml at behnel.de Fri Jan 30 15:40:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 30 Jan 2009 21:40:00 +0100 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <498365a0$0$31868$9b4e6d93@newsspool3.arcor-online.net> D'Arcy J.M. Cain wrote: > On Fri, 30 Jan 2009 15:46:33 +0200 > Justin Wyer wrote: >> $ find -name "*" -exec grep -nH "LF01" {} \; >> | cut -d ":" -f 1 | sort | uniq > > I know this isn't a Unix group but please allow me to suggest instead; > > $ grep -lR LF01 That's a very good advice. I had to pull some statistics from a couple of log files recently some of which were gzip compressed. The obvious Python program just eats your first CPU's cycles parsing data into strings while the disk runs idle, but using the subprocess module to spawn a couple of gzgrep's in parallel that find the relevant lines, and then using Python to extract and aggregate the relevant information from them does the job in no-time. Stefan From lists at cheimes.de Fri Jan 30 15:40:49 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 21:40:49 +0100 Subject: Get thread pid In-Reply-To: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: Alejandro schrieb: > Hi: > > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. May I ask why you want to get the TID? You can't do anything useful with it. You can't kill a thread safely, neither from within Python nor from the outside world. thread.get_ident() gives you an id. On pthread based systems the function uses pthread_self(). For TLS, Python has builtin classes that are hooked into Python's internal threading system. From haag at lsu.edu Fri Jan 30 15:42:28 2009 From: haag at lsu.edu (Alaric Haag) Date: Fri, 30 Jan 2009 14:42:28 -0600 Subject: Odd syntactic NON-error? References: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> Message-ID: In article <20090130173948.12853.732928641.divmod.quotient.543 at henry.divmod.com>, Jean-Paul Calderone wrote: > On Fri, 30 Jan 2009 11:36:45 -0600, Alaric Haag wrote: > >Hello, > > > >I just noticed that I've been successfully importing a module I wrote > >which contains a class definition that begins with (docstring removed): > > > >class TDF(): > > def __init__(self, name='', mode=tscan. GP_NOCLOBBER): > > > >Note the "space" which shouldn't be here---^ > > The space is irrelevant. > > >>> object. __init__ > > >>> object.__init__ is object. __init__ > True > >>> > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list It strikes me as strange that Python (which I love btw) would be so loose in its syntax when "spaces matter" at the beginning of a line. I now see that a space could precede the period too, as in: x = foo . method() So, is the "secret" that the period is syntactically an "operator" like + or * ? From perfreem at gmail.com Fri Jan 30 15:44:07 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Fri, 30 Jan 2009 12:44:07 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> Message-ID: <0e855f75-9159-4b28-a153-ec6cb0d84fb2@g1g2000pra.googlegroups.com> On Jan 28, 6:08?pm, Aaron Brady wrote: > On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > > > On Jan 28, 5:14?pm, John Machin wrote: > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > hello all, > > > > > i have a large dictionary which contains about 10 keys, each key has a > > > > value which is a list containing about 1 to 5 million (small) > > > > dictionaries. for example, > > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > > 'world'}, ...], > > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > > in total there are about 10 to 15 million lists if we concatenate > > > > together all the values of every key in 'mydict'. mydict is a > > > > structure that represents data in a very large file (about 800 > > > > megabytes). > > snip > > > in reply to the other poster: i thought 'shelve' simply calls pickle. > > if thats the case, it wouldnt be any faster, right ? > > Yes, but not all at once. ?It's a clear winner if you need to update > any of them later, but if it's just write-once, read-many, it's about > the same. > > You said you have a million dictionaries. ?Even if each took only one > byte, you would still have a million bytes. ?Do you expect a faster I/ > O time than the time it takes to write a million bytes? > > I want to agree with John's worry about RAM, unless you have several+ > GB, as you say. ?You are not dealing with small numbers. in my case, i just write the pickle file once and then read it in later. in that case, cPickle and shelve would be identical, if i understand correctly? the file i'm reading in is ~800 MB file, and the pickle file is around 300 MB. even if it were 800 MB, it doesn't make sense to me that python's i/o would be that slow... it takes roughly 5 seconds to write one megabyte of a binary file (the pickled object in this case), which just seems wrong. does anyone know anything about this? about how i/o can be sped up for example? the dictionary might have a million keys, but each key's value is very small. i tried the same example where the keys are short strings (and there are about 10-15 million of them) and each value is an integer, and it is still very slow. does anyone know how to test whether i/o is the bottle neck, or whether it's something specific about pickle? thanks. From david at abbottdavid.com Fri Jan 30 15:50:55 2009 From: david at abbottdavid.com (David) Date: Fri, 30 Jan 2009 15:50:55 -0500 Subject: Rounding to the nearest 5 In-Reply-To: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> References: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> Message-ID: <4983682F.70108@abbottdavid.com> Benjamin J. Racine wrote: > Doesn't this work? > > round_by_5.py > > > import sys > > def round_by_5(x= sys.argv[0]): > x = x/5. > x = round(x) > x = x*5 > print(x) > return x > > Ben R. I am learning, I got this to work fine; #!/usr/bin/python import sys def round_by_5(x = sys.argv[1]): x = int(x)/5 x = round(x) x = x*5 print int(x) round_by_5(sys.argv[1]) -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From stefan_ml at behnel.de Fri Jan 30 15:51:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 30 Jan 2009 21:51:28 +0100 Subject: search speed In-Reply-To: <6uft9aFf9kgbU1@mid.uni-berlin.de> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: <49836850$0$31877$9b4e6d93@newsspool3.arcor-online.net> Diez B. Roggisch wrote: > that's not necessarily the best thing to do if things have a > record-like structure. The canonical answer to this is then to use a > database to hold the data, instead of flat files. So if you have any > chance to do that, you should try & stuff things in there. It's worth mentioning to the OP that Python has a couple of database libraries in the stdlib, notably simple things like the various dbm flavoured modules (see the anydbm module) that provide fast string-to-string hash mappings (which might well be enough in this case), but also a pretty powerful SQL database called sqlite3 which allows much more complex (and complicated) ways to find the needle in the haystack. http://docs.python.org/library/persistence.html Stefan From lists at cheimes.de Fri Jan 30 15:54:31 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 21:54:31 +0100 Subject: is python Object oriented?? In-Reply-To: <498363C0.5070909@gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <498363C0.5070909@gmail.com> Message-ID: Michael Torrie schrieb: >> It all depends on implementation, I think even we can make "C" object >> oriented with proper implementation. > > Indeed, any code based on gobject libraries can be object-oriented in > design and function. The Python C API is a good example for well designed and object oriented C code. Christian From stef.mientki at gmail.com Fri Jan 30 15:59:34 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 21:59:34 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: <6uf1djFengojU2@mid.uni-berlin.de> References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> Message-ID: <49836A36.5000809@gmail.com> Marc 'BlackJack' Rintsch wrote: > On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > > >> try this: >> >> class MyRegClass ( int ) : >> def __init__ ( self, value ) : >> self.Value = value >> def __repr__ ( self ) : >> line = hex ( self.Value ) >> line = line [:2] + line [2:].upper() >> return line >> > > def __repr__(self): > return '0x%X' % self.value > > >> __str__ = __repr__ >> > > This is unnecessary, the fallback of `__str__` is `__repr__` already. > > well this is what my Python is doing: without _str__ = __repr__ >>print shadow_register 170 with _str__ = __repr__ >>print shadow_register 0xAA cheers, Stef From simon at brunningonline.net Fri Jan 30 16:12:04 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 30 Jan 2009 21:12:04 +0000 Subject: Odd syntactic NON-error? In-Reply-To: References: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> Message-ID: <8c7f10c60901301312h4f967f48ycd0d32309a427e7a@mail.gmail.com> 2009/1/30 Alaric Haag : > So, is the "secret" that the period is syntactically an "operator" like > + or * ? Exactly that: . Shhhhh! -- Cheers, Simon B. From Scott.Daniels at Acm.Org Fri Jan 30 16:36:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 13:36:28 -0800 Subject: relpath problem on windows In-Reply-To: References: Message-ID: <3b-dnR645qzp7x7UnZ2dnUVZ_jWWnZ2d@pdx.net> eliben wrote: > I'm having a problem with 2.6's new os.path.relpath function. > ... But this isn't [correct]: > relpath(r'd:\jho', r'd:\\') > => '..\jho' > Neither is this: > relpath(r'd:\jho', r'd:') > => '..\..\..\jho' > > What am I missing? There is no way to write a raw string for text ending in a single backslash. r'd:\\' == 'd:\\\\' What you want is relpath(r'd:\jho', 'd:\\') But it turns out this doesn't work, either. File a bug. --Scott David Daniels Scott.Daniels at Acm.Org From tjreedy at udel.edu Fri Jan 30 16:39:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Jan 2009 16:39:45 -0500 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Fri, Jan 30, 2009 at 12:38 AM, r Personally, I work for a division in our company that has converted over > the last few years our entire software line from an old, Windows-only > mix of C and VCL-stuff, to a serious mid-sized product which recently > clocked in at about 165k lines of Python code (about 600k more in third > party libs!) that's fast, effective, flexible, multi-platform and highly > responsive to our customer's evolving needs. We actually did a complete > rewrite from the ground up -- a dangerous thing to do, but the legacy > product was so out of date that it had to be done... and I don't think > any other set of tools would have been able to let us do so as well, in > as short of a period of time, or as iteratively and in cooperation with > our customer base. Thank you for sharing this. If it has not been already, could this be shared as a Python success story on the site? (With proprietary detail omitted as needed for approval, of course.) tjr From tjreedy at udel.edu Fri Jan 30 16:47:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Jan 2009 16:47:01 -0500 Subject: What's new in 3.0 about threading? In-Reply-To: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> References: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> Message-ID: ?? wrote: > Hello > I have questions about threading: > > import threading > class myThread(threading.Thread): > def run(self): > print('hello,threads') > if __name__=='__main__': > threads=myThread() > threads.start() > > Above program does't work at 'Run Module' in IDLE, What does 'doesn't work' mean? If you get an error traceback, post it. Possible problem: IDLE runs on top of pythonw.exe (not python.exe) which does not open a window (IDLE runs its own window). So I would not be surprised if output from separate thread in pythonw process gets lost. If that is the problem, try having the run() method send something back to the main thread, say through a Queue, and print from there after starting the subthread. > but it works well > under executing scripts.Is it anything wrong? > WindowXP,Python 3.0 > Thanks. > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From ntwrkd at gmail.com Fri Jan 30 17:20:40 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:20:40 -0800 Subject: accessing elements of a tuple Message-ID: i am trying to access elements of a tuple without using the [1:5] notation. the contents of the tuple are as follows: ('--datasourcename', 'DB') I want to access everything in the second argument, but i am not sure how to go about this without converting to a string. thanks in advance From ntwrkd at gmail.com Fri Jan 30 17:23:31 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:23:31 -0800 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: let me re-phrase that question: i would like to access the element of individual tuples inside of a list, by using an index. so i have the list contents print list [('--datasourcename', 'DB'), ('--password', '123')] How can I access "DB" from the list directly using an index? right now I would have to grab the tuple and the use the index of the tuple On Fri, Jan 30, 2009 at 2:20 PM, Matthew Sacks wrote: > i am trying to access elements of a tuple without using the [1:5] notation. > the contents of the tuple are as follows: > ('--datasourcename', 'DB') > > I want to access everything in the second argument, but i am not sure > how to go about this without converting to a string. > > thanks in advance > From robert.kern at gmail.com Fri Jan 30 17:25:13 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 30 Jan 2009 16:25:13 -0600 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> Message-ID: On 2009-01-29 18:22, Reckoner wrote: > I haven't looked at Enthought in awhile. I want to avoid having to > installing the entire Enthought toolsuite, however. Would I have to > do that for Traits? No, Traits can be installed by itself unless if you want its GUI capabilities. http://pypi.python.org/pypi/Traits -- 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 arequipeno at gmail.com Fri Jan 30 17:32:44 2009 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 30 Jan 2009 16:32:44 -0600 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: Matthew Sacks wrote: > How can I access "DB" from the list directly using an index? list[0][1] ... or did I misunderstand your question? -- ======================================================================== Ian Pilcher arequipeno at gmail.com ======================================================================== From darcy at druid.net Fri Jan 30 17:34:23 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 17:34:23 -0500 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: <20090130173423.37837d7e.darcy@druid.net> On Fri, 30 Jan 2009 14:23:31 -0800 Matthew Sacks wrote: > let me re-phrase that question: > i would like to access the element of individual tuples inside of a > list, by using an index. > so i have the list contents > > print list > [('--datasourcename', 'DB'), ('--password', '123')] > > How can I access "DB" from the list directly using an index? First of all, list is a reserved word. Don't use it as a variable name. mylist[0][1] if I understand the question. I don't know what you are trying to accomplish but is this snippet useful? opts = dict([(x[0][2:], x[1]) for x in mylist if x[0][:2] == '--']) print opts['datasourcename'] -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Fri Jan 30 17:36:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 30 Jan 2009 17:36:49 -0500 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> Message-ID: Ivan Illarionov wrote: > r wrote: >> Where are the community projects supporting Python? -- besides the >> core devlopment. Seem s that nobody is interested unless their pay-pal >> account is involved. I find this all quite disappointing. > > Hi r, > > Can you just type > > import antigravity > > and join us up there? > > Hatred for Ruby and Perl seems to oppose natural Python forces, > that's why you can't see community spirit. Let your hatred go and > start > flying already. > Indeed. What r has not yet grasped is that to be in favor of one thing you don't necessarily have to be against everything else. For example, if it hadn't been for generous help from the Perl community (as represented by http://www.yapc.org/) the first PyCon would never have got off the ground. The competition between languages for the attention of programmers isn't a zero-sum game. I think there has perhaps been some slight decrease in the tolerance level as expressed on this list over the last couple of years, but I don't think it's (yet) anything to be concerned about. It's mostly a matter of teaching by example. I'd like to think I usually set a good example, but I've certainly been known to get crabby from time to time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Fri Jan 30 17:39:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 16:39:39 -0600 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: <498381AB.3030907@tim.thechases.com> > let me re-phrase that question: > i would like to access the element of individual tuples inside of a > list, by using an index. > so i have the list contents > > print list > [('--datasourcename', 'DB'), ('--password', '123')] > > How can I access "DB" from the list directly using an index? > > right now I would have to grab the tuple and the use the index of the tuple Well, you can use lst[0][1] to get it. Or, if you're parsing through the list, you can use tuple unpacking: for name, value in lst: print "%s = %s" % (name, value) As an aside, it looks like you're doing parameter parsing. The standard library has the optparse module which takes a lot of pain out of parsing parameters. -tkc From ntwrkd at gmail.com Fri Jan 30 17:42:48 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:42:48 -0800 Subject: accessing elements of a tuple In-Reply-To: <498381AB.3030907@tim.thechases.com> References: <498381AB.3030907@tim.thechases.com> Message-ID: >First of all, list is a reserved word. Don't use it as a variable name. I was using it as an example in this case. >mylist[0][1] if I understand the question. This works. Thank you. On Fri, Jan 30, 2009 at 2:39 PM, Tim Chase wrote: >> let me re-phrase that question: >> i would like to access the element of individual tuples inside of a >> list, by using an index. >> so i have the list contents >> >> print list >> [('--datasourcename', 'DB'), ('--password', '123')] >> >> How can I access "DB" from the list directly using an index? >> >> right now I would have to grab the tuple and the use the index of the >> tuple > > Well, you can use > > lst[0][1] > > to get it. Or, if you're parsing through the list, you can use tuple > unpacking: > > for name, value in lst: > print "%s = %s" % (name, value) > > As an aside, it looks like you're doing parameter parsing. The standard > library has the optparse module which takes a lot of pain out of parsing > parameters. > > -tkc > > > > From jervisau at gmail.com Fri Jan 30 18:42:57 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 10:42:57 +1100 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <8e63a5ce0901301542i5f220ey574431da390437bc@mail.gmail.com> > > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) > If the files you are searching are located at some other location on a network, you may find that much of the 5 minutes is actually the network delay in fetching each file. (Although you said something about your dir being cached?) Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntwrkd at gmail.com Fri Jan 30 18:43:19 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 15:43:19 -0800 Subject: problem with program - debugging leading nowhere Message-ID: i am trying to figure out what has gone wrong in my python program. it is complaining that there is an indendation error. should be simple enough but im stuck on this one. if anyone can help unjolt me it would be appreciated. thank you error message: Traceback (most recent call last): File "", line 1, in IndentationError: expected an indented block (, line 39) code: http://pastebin.com/f2f971f91 From jervisau at gmail.com Fri Jan 30 18:59:24 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 10:59:24 +1100 Subject: problem with program - debugging leading nowhere In-Reply-To: References: Message-ID: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> > > > > error message: > Traceback (most recent call last): > File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code: > http://pastebin.com/f2f971f91 > Hi, It looks like you have commented out a line on line 30, you need to place something in here, as python is expecting an indented level after your 'if'. (how about a pass statement or a print saying some placeholder help details.) On a side note, I've only had a quick skim, you shouldn't compare o to an empty string "" using the 'is', is tests identity not equality. So what you are saying is is o the exact same empty string that I am creating "" (obviously it never will be, because you just created it then with "") . Use the equality operator == instead. or in your case !=. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From jervisau at gmail.com Fri Jan 30 19:00:05 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 11:00:05 +1100 Subject: problem with program - debugging leading nowhere In-Reply-To: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> References: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> Message-ID: <8e63a5ce0901301600o5de06121k9635a65b1a28fe0f@mail.gmail.com> ---------- Forwarded message ---------- From: Jervis Whitley Date: Sat, Jan 31, 2009 at 10:59 AM Subject: Re: problem with program - debugging leading nowhere To: Matthew Sacks Cc: python-list at python.org > > > > error message: > Traceback (most recent call last): > File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code: > http://pastebin.com/f2f971f91 > Hi, It looks like you have commented out a line on line 30, you need to place something in here, as python is expecting an indented level after your 'if'. (how about a pass statement or a print saying some placeholder help details.) On a side note, I've only had a quick skim, you shouldn't compare o to an empty string "" using the 'is', is tests identity not equality. So what you are saying is is o the exact same empty string that I am creating "" (obviously it never will be, because you just created it then with "") . Use the equality operator == instead. or in your case !=. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurgenex at hotmail.com Fri Jan 30 19:01:50 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 30 Jan 2009 16:01:50 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> Message-ID: Jon Harrop wrote: >I had hoped someone else would correct you but they haven't. So... That is because ... >Xah Lee wrote: ... everyone with more than 5 cents of brain has killfiled him a long time ago. jue From aahz at pythoncraft.com Fri Jan 30 19:11:42 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 16:11:42 -0800 Subject: Swapping values of two variables References: Message-ID: In article , Eric Kang wrote: > >In python, I set: > >x=1 >y=3 > >z = x >x = y >y = z > > >This gave me 3 1, which are the values of x and y swapped. >The following would have given me the same result: >x, y = y, x > > > >But could the swapping be done using less extra memory than this? What >is the minimum amount of extra memory required to exchange two 32-bit >quantities? What would be the pseudocode that achieves this minimum? This looks like a homework problem to me.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From sjmachin at lexicon.net Fri Jan 30 19:14:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 16:14:58 -0800 (PST) Subject: problem with program - debugging leading nowhere References: Message-ID: <5006c00c-af2c-45a7-96d9-4f45a27736ef@t26g2000prh.googlegroups.com> On Jan 31, 10:43?am, Matthew Sacks wrote: > i am trying to figure out what has gone wrong in my python program. it > is complaining that there is an indendation error. should be simple > enough but im stuck on this one. if anyone can help unjolt me it would > be appreciated. > > thank you > > error message: > Traceback (most recent call last): > ? File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code:http://pastebin.com/f2f971f91 How are you running that? All that stuff is not very informative. I put your source into a pastebin.py: >>> import pastebin Traceback (most recent call last): File "", line 1, in File "pastebin.py", line 31 elif o is not "": ^ IndentationError: expected an indented block Dunno how you managed line 39. What you have there is: for o, a in optlist: if o == "-h": #usage() elif o is not "": which is equivalent to: for o, a in optlist: if o == "-h": elif o is not "": which is not such a good idea. BTW, why aren't you using optparse? HTH, John From sjmachin at lexicon.net Fri Jan 30 19:19:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 16:19:19 -0800 (PST) Subject: accessing elements of a tuple References: <498381AB.3030907@tim.thechases.com> Message-ID: <44365ba1-cbac-4965-ac4a-788872a5cc0d@r10g2000prf.googlegroups.com> On Jan 31, 9:42?am, Matthew Sacks wrote: > >First of all, list is a reserved word. ?Don't use it as a variable name. > > I was using it as an example in this case. > > >mylist[0][1] if I understand the question. > > This works. Thank you. > > On Fri, Jan 30, 2009 at 2:39 PM, Tim Chase > > wrote: > >> let me re-phrase that question: > >> i would like to access the element of individual tuples inside of a > >> list, by using an index. > >> so i have the list contents > > >> print list > >> [('--datasourcename', 'DB'), ('--password', '123')] > > >> How can I access "DB" from the list directly using an index? > > >> right now I would have to grab the tuple and the use the index of the > >> tuple > > > Well, you can use > > > ?lst[0][1] But that sort of code rapidly becomes unreadable. Unpacking the list and unpacking the tuple into named components will be more understandable when you revisit the code. From bignose+hates-spam at benfinney.id.au Fri Jan 30 19:22:26 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 11:22:26 +1100 Subject: problem with program - debugging leading nowhere References: Message-ID: <87k58cz5ml.fsf@benfinney.id.au> Matthew Sacks writes: > i am trying to figure out what has gone wrong in my python program. it > is complaining that there is an indendation error. should be simple > enough but im stuck on this one. if anyone can help unjolt me it would > be appreciated. Step one: Ensure the problem doesn't get worse. Set your text editor to use spaces for indentation and to *never* put an ASCII TAB character (U+0009) into your source code. They are, by default, invisibly indistinguishable from a sequence of spaces, and completely unnecessary. Step two: Run your program with ?python -t? instead of ?python?, to determine if your problem in this instance is caused by using TAB characters for indentation. Step three: When asking people to help with understanding an error message, it helps to post the actual (complete) error message :-) -- \ ?Sittin' on the fence, that's a dangerous course / You can even | `\ catch a bullet from the peace-keeping force? ?Dire Straits, | _o__) _Once Upon A Time In The West_ | Ben Finney From ntwrkd at gmail.com Fri Jan 30 19:31:40 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 16:31:40 -0800 Subject: problem with program - debugging leading nowhere In-Reply-To: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> References: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> Message-ID: this works. thanks! On Fri, Jan 30, 2009 at 3:59 PM, Jervis Whitley wrote: > > >> >> >> >> >> error message: >> Traceback (most recent call last): >> File "", line 1, in >> IndentationError: expected an indented block (, line 39) >> >> code: >> http://pastebin.com/f2f971f91 > > Hi, > > It looks like you have commented out a line on line 30, you need to place > something > in here, as python is expecting an indented level after your 'if'. (how > about a pass statement or a print saying some placeholder help details.) > > On a side note, I've only had a quick skim, you shouldn't compare o to an > empty string "" using the 'is', is tests identity not equality. So what you > are saying is > is o the exact same empty string that I am creating "" (obviously it never > will be, because you just created it then with "") . Use the equality > operator == instead. > or in your case !=. > > Cheers, > > From steve at holdenweb.com Fri Jan 30 19:35:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 30 Jan 2009 19:35:40 -0500 Subject: Adding a positive number and a negative number In-Reply-To: References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: Scott David Daniels wrote: > Grant Edwards wrote: >> On 2009-01-30, MRAB wrote: >>> Eric Kang wrote: >>>> In two's complement representation, can adding one positive >>>> and one negative give you overflow? >>> No. >> AFAIK, in Python adding integers never gives you overlow >> regardless of sign. > > Right, but he wants his homework answer. And Python doesn't use pure two's complement notation when it promotes regular integers to longs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bignose+hates-spam at benfinney.id.au Fri Jan 30 19:37:09 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 11:37:09 +1100 Subject: problem with program - debugging leading nowhere References: <87k58cz5ml.fsf@benfinney.id.au> Message-ID: <87fxj0z4y2.fsf@benfinney.id.au> Ben Finney writes: > Step three: When asking people to help with understanding an error > message, it helps to post the actual (complete) error message :-) My apologies, you did provide this and I missed it. -- \ ?One time I went to a drive-in in a cab. The movie cost me | `\ ninety-five dollars.? ?Steven Wright | _o__) | Ben Finney From castironpi at gmail.com Fri Jan 30 19:47:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 30 Jan 2009 16:47:50 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> <0e855f75-9159-4b28-a153-ec6cb0d84fb2@g1g2000pra.googlegroups.com> Message-ID: On Jan 30, 2:44?pm, perfr... at gmail.com wrote: > On Jan 28, 6:08?pm, Aaron Brady wrote: > > > > > On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > > > > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > > hello all, > > > > > > i have a large dictionary which contains about 10 keys, each key has a > > > > > value which is a list containing about 1 to 5 million (small) > > > > > dictionaries. for example, > > > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > > > 'world'}, ...], > > > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > > > in total there are about 10 to 15 million lists if we concatenate > > > > > together all the values of every key in 'mydict'. mydict is a > > > > > structure that represents data in a very large file (about 800 > > > > > megabytes). > > > snip > > > > in reply to the other poster: i thought 'shelve' simply calls pickle. > > > if thats the case, it wouldnt be any faster, right ? > > > Yes, but not all at once. ?It's a clear winner if you need to update > > any of them later, but if it's just write-once, read-many, it's about > > the same. > > > You said you have a million dictionaries. ?Even if each took only one > > byte, you would still have a million bytes. ?Do you expect a faster I/ > > O time than the time it takes to write a million bytes? > > > I want to agree with John's worry about RAM, unless you have several+ > > GB, as you say. ?You are not dealing with small numbers. > > in my case, i just write the pickle file once and then read it in > later. in that case, cPickle and shelve would be identical, if i > understand correctly? No not identical. 'shelve' is not a dictionary, it's a database object that implements the mapping protocol. 'isinstance( shelve, dict )' is False, for example. > the file i'm reading in is ~800 MB file, and the pickle file is around > 300 MB. even if it were 800 MB, it doesn't make sense to me that > python's i/o would be that slow... it takes roughly 5 seconds to write > one megabyte of a binary file (the pickled object in this case), which > just seems wrong. does anyone know anything about this? about how i/o > can be sped up for example? You can try copying a 1-MB file. Or something like: f= open( 'temp.temp', 'w' ) for x in range( 100000 ): f.write( '0'* 10 ) You know how long it takes OSes to boot, right? > the dictionary might have a million keys, but each key's value is very > small. i tried the same example where the keys are short strings (and > there are about 10-15 million of them) and each value is an integer, > and it is still very slow. does anyone know how to test whether i/o is > the bottle neck, or whether it's something specific about pickle? > > thanks. You could fall back to storing a parallel list by hand, if you're just using string and numeric primitives. From alan.isaac at gmail.com Fri Jan 30 20:15:11 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 31 Jan 2009 01:15:11 GMT Subject: naming and binding (subtle Python 3 change) In-Reply-To: References: Message-ID: On 1/29/2009 10:50 PM Terry Reedy apparently wrote: > http://bugs.python.org/issue5106 Thanks! Alan From vincent at vincentdavis.net Fri Jan 30 20:33:29 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 30 Jan 2009 18:33:29 -0700 Subject: question about Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)] Message-ID: <77e831100901301733s4ebe3ca7i251a79955894f00e@mail.gmail.com> Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)] I am not sure how to ask this but which "for" is looped first? I could test but was wondering if there was a nice explanation I could apply to future situations. Thanks Vincent Davis 720-301-3003 From grante at visi.com Fri Jan 30 20:35:03 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 30 Jan 2009 19:35:03 -0600 Subject: Swapping values of two variables References: Message-ID: <5Yidnf3R_pdaNx7UnZ2dnUVZ_qrinZ2d@posted.usinternet> On 2009-01-31, Aahz wrote: >>But could the swapping be done using less extra memory than this? What >>is the minimum amount of extra memory required to exchange two 32-bit >>quantities? What would be the pseudocode that achieves this minimum? > > This looks like a homework problem to me.... It looks 100% like a homework problem. -- Grant From hungvn94 at gmail.com Fri Jan 30 20:35:09 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Sat, 31 Jan 2009 12:35:09 +1100 Subject: is python Object oriented?? In-Reply-To: <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> Message-ID: <139bf30a0901301735v7cd6f794x20fc6d96592d9b43@mail.gmail.com> On Fri, Jan 30, 2009 at 5:15 PM, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > > > I'm new to Python and also wondering about OOP in Python. > > > > I want to justify the above question (is Python Object-Oriented?). > > Does Python follow the concepts/practices of Encapsulation, > > Polymorphism and Interface, which are quite familiar to Java > > programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. I was introduced to OOP via C++/Java, so its quite nature to compare and contrast with the languages you know even they seem not to be original. I definitely will learn about Smalltalk. > > Anyway, to your three-pronged question: > - Yes, Python supports polymorphism. I find it hard to think of an > example of an OO language that doesn't. > > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. See http://en.wikipedia.org/wiki/Duck_typing Its seem to me that duck typing is a special case of static vs dynamic type debate and clearly Python is a dynamic type philoshopy's follower. > > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here". This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. I like the flexibility of not being enforced to the encapsulation rules, however, you're right, we do at our own risk and have to tradeoff the flexibility with the secure a static type system like Java provides. P.S. You appear to have posted the same message 3 times(!), which is a > bit annoying for readers. sorry for this annoyance. I dont know why a new post was made whenever i cliked on the topic link. Probably, there's something wrong with google group. on investigating... > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 30 21:41:45 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 18:41:45 -0800 (PST) Subject: Adding a positive number and a negative number References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: <29357024-3a33-4f66-b639-8264e6cea69a@r41g2000prr.googlegroups.com> On Jan 31, 4:10?am, Scott David Daniels wrote: > Grant Edwards wrote: > > On 2009-01-30, MRAB wrote: > >> Eric Kang wrote: > >>> In two's complement representation, can adding one positive > >>> and one negative give you overflow? > >> No. > > AFAIK, in Python adding integers never gives you overlow > > regardless of sign. > > Right, but he wants his homework answer. For extra brownie points, here's a simple proof of the more general proposition that adding a non-negative integer p and a non-positive integer n can't overflow whatever the representation. Let a be the most negative integer and b the most positive. So we're given a <= n <= 0 <= p <= b and need to show that a <= (p + n) <= b. max(p) is b, max(n) is 0, so max(p + n) is b. Similarly min(p + n) is a. Q.E.D. IEEE 754 floating point? I don't know. Go read the standard :-) From timro21 at gmail.com Fri Jan 30 21:45:27 2009 From: timro21 at gmail.com (Tim) Date: Sat, 31 Jan 2009 12:45:27 +1000 Subject: nth root Message-ID: In PythonWin I'm running a program to find the 13th root (say) of millions of hundred-digit numbers. I'm using n = 13 root = base**(1.0/n) which correctly computes the root to a large number of decimal places, but therefore takes a long time. All I need is the integer component. Is there a quicker way? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ianand0204 at gmail.com Fri Jan 30 21:59:17 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 30 Jan 2009 18:59:17 -0800 (PST) Subject: SimpleXMLRPCServer question Message-ID: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> I am working on a very basic xmlrpc server, which will expose certain functions for administering BIND zone files. The big problem I am having is parsing the incoming xmlrpc request. Basically part of the xmlrpc request will help deterime which zone file is edited. I have been looking at the do_POST() method from SimpleXMLRPCDispatcher and it seems like I could code something which overides that method, however I am new to programming am at a loss, i might even be making this tougher than it needs to be. Is there a way to parse the incoming xmlrpc request before the function it is calling is executed? From rdmurray at bitdance.com Fri Jan 30 22:14:41 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 03:14:41 +0000 (UTC) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> <49836A36.5000809@gmail.com> Message-ID: Quoth Stef Mientki : > Marc 'BlackJack' Rintsch wrote: > > On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > > > > > >> try this: > >> > >> class MyRegClass ( int ) : > >> def __init__ ( self, value ) : > >> self.Value = value > >> def __repr__ ( self ) : > >> line = hex ( self.Value ) > >> line = line [:2] + line [2:].upper() > >> return line > >> > > > > def __repr__(self): > > return '0x%X' % self.value > > > > > >> __str__ = __repr__ > >> > > > > This is unnecessary, the fallback of `__str__` is `__repr__` already. > > > > > well this is what my Python is doing: > > without _str__ = __repr__ > >>print shadow_register > 170 > > with _str__ = __repr__ > >>print shadow_register > 0xAA >>> '__str__' in dir(170) True That is, the superclass (int) has an __str__, so you have to override it. --RDM From google at mrabarnett.plus.com Fri Jan 30 22:31:34 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 31 Jan 2009 03:31:34 +0000 Subject: nth root In-Reply-To: References: Message-ID: <4983C616.3000207@mrabarnett.plus.com> Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > Have you tried an iterative approach? def root_13(x): step = 1 while step ** 13 < x: step *= 2 root = 0 while step: if (root + step) ** 13 <= x: root += step step //= 2 return root Probably not that fast in Python, though. numpy or psyco might help. From t.roberts at cqu.edu.au Fri Jan 30 23:00:09 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sat, 31 Jan 2009 14:00:09 +1000 Subject: nth root References: <4983C616.3000207@mrabarnett.plus.com> Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? Tim Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > Have you tried an iterative approach? def root_13(x): step = 1 while step ** 13 < x: step *= 2 root = 0 while step: if (root + step) ** 13 <= x: root += step step //= 2 return root Probably not that fast in Python, though. numpy or psyco might help. -- http://mail.python.org/mailman/listinfo/python-list From rdmurray at bitdance.com Fri Jan 30 23:01:05 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:01:05 +0000 (UTC) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <86a336c4-66d1-4420-8f0e-d53b8d28085d@o40g2000prn.googlegroups.com> Message-ID: Quoth Mudcat : > [attribution omitted by Mudcat] > > I think you've probably had issues with circular imports (i.e. mutual > > dependencies), unless you can precisely remember what you were doing and > > what went wrong. > > That's possible, but circular imports become more of a hazard if you > have to import in several locations. Unify that to one file, and those > problems are much easier to avoid. Personally I've never run into circular import problems when importing library functions. Then, again, I always use 'from x import y' (or 'y as z' for those modules that use non-unique names for things, like os.path.split). Where I've run into circular import problems when when _my_ modules were circularly importing things. Which just meant that my code needed some refactoring. > > I can make up three or four different logical groupings in my > > applications... so what is 'logical' could not be the same for everyone, > > or from every point of view. > > That's not the point. The point is that multiple imports can be a > limiting factor if the module imports don't happen to align with the > model they'd like to use for their file layout. I'm inclined to agree with you that organizing code around which other modules it imports is (usually) not the optimal organization. But it is worth _considering_, because sometimes it does reveal a useful pattern to refactor by. > However playing around with the files, I guess it is possible to > create a file that just does imports and then reference them all just > like you would any other extension of the namespace. I created a file > called imports and was able to access the sys module within it by > importing all from imports and calling sys. That way at least all you > have to do is import the one file each time. If you are talking about making a file and then doing from X import *, I'd shudder a little bit looking at such code. It just doesn't feel like the python way :). Which doesn't mean you shouldn't do it, if it works for you, it is more of a personal preference thing. What I'd respond to better (and I almost started doing this in my code...but it's more typing so in the end I didn't) is to have a module, say 'lib', and just do 'import lib'. Then everything is called through 'lib': lib.os.path.split('/some/path'), etc, etc. The difference is that that is explicit. If I'm reading your code and I see that, I look at the top and I see the import for 'lib', and I know to look for a lib module. If you use the from X import * pattern, I lose that ability. Sure, I can look at the top, and see the 'from X import *', and if that's the only 'from *' import I can guess that the functions not defined in the file come from that one...but all of that takes more brain cycles. It just doesn't feel as clean :) But, in the end, it is mostly personal preference. I'm sure there are Pythonistas out there whose lips will curl when seeing 'from os.path import split as pathsplit, join as pathjoin' in my code :) --RDM From tim at thechases.com Fri Jan 30 23:12:03 2009 From: tim at thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 22:12:03 -0600 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <4983CF93.3040002@thechases.com> > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO While most of the solutions folks have offered involve scanning all the files each time you search, if the content of those files doesn't change much, you can build an index once and then query the resulting index multiple times. Because I was bored, I threw together the code below (after the "-------" divider) which does what you detail as best I understand, allowing you to do python tkc.py 31415 to find the files containing CUSTOMERNO=31415 The first time, it's slow because it needs to create the index file. However, subsequent runs should be pretty speedy. You can also specify multiple customers on the command-line: python tkc.py 31415 1414 77777 and it will search for each of them. I presume they're found by the regexp "LF01(\d+)" based on your description, that the file can be sensibly broken into lines, and the code allows for multiple results on the same line. Adjust accordingly if that's not the pattern you want or the conditions you expect. If your source files change, you can reinitialize the database with python tkc.py -i You can also change the glob pattern used for indexing -- by default, I assumed they were "*.txt". But you can either override the default with python tkc.py -i -p "*.dat" or you can change the source to default differently (or even skip the glob-check completely...look for the fnmatch() call). There are a few more options. Just use python tkc.py --help as usual. It's also a simple demo of the optparse module if you've never used it. Enjoy! -tkc PS: as an aside, how do I import just the fnmatch function? I tried both of the following and neither worked: from glob.fnmatch import fnmatch from glob import fnmatch.fnmatch I finally resorted to the contortion coded below in favor of import glob fnmatch = glob.fnmatch.fnmatch ----------------------------------------------------------------- #!/usr/bin/env python import dbm import os import re from glob import fnmatch fnmatch = fnmatch.fnmatch from optparse import OptionParser customer_re = re.compile(r"LF01(\d+)") def build_parser(): parser = OptionParser( usage="%prog [options] [cust#1 [cust#2 ... ]]" ) parser.add_option("-i", "--index", "--reindex", action="store_true", dest="reindex", default=False, help="Reindex files found in the current directory " "in the event any files have changed", ) parser.add_option("-p", "--pattern", action="store", dest="pattern", default="*.txt", metavar="GLOB_PATTERN", help="Index files matching GLOB_PATTERN", ) parser.add_option("-d", "--db", "--database", action="store", dest="indexfile", default=".index", metavar="FILE", help="Use the index stored at FILE", ) parser.add_option("-v", "--verbose", action="count", dest="verbose", default=0, help="Increase verbosity" ) return parser def reindex(options, db): if options.verbose: print "Indexing..." for path, dirs, files in os.walk('.'): for fname in files: if fname == options.indexfile: # ignore our database file continue if not fnmatch(fname, options.pattern): # ensure that it matches our pattern continue fullname = os.path.join(path, fname) if options.verbose: print fullname f = file(fullname) found_so_far = set() for line in f: for customer_number in customer_re.findall(line): if customer_number in found_so_far: continue found_so_far.add(customer_number) try: val = '\n'.join([ db[customer_number], fullname, ]) if options.verbose > 1: print "Appending %s" % customer_number except KeyError: if options.verbose > 1: print "Creating %s" % customer_number val = fullname db[customer_number] = val f.close() if __name__ == "__main__": parser = build_parser() opt, args = parser.parse_args() reindexed = False if opt.reindex or not os.path.exists("%s.db" % opt.indexfile): db = dbm.open(opt.indexfile, 'n') reindex(opt, db) reindexed = True else: db = dbm.open(opt.indexfile, 'r') if not (args or reindexed): parser.print_help() for arg in args: print "%s:" % arg, try: val = db[arg] print for item in val.splitlines(): print " %s" % item except KeyError: print "Not found" db.close() From rdmurray at bitdance.com Fri Jan 30 23:12:41 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:12:41 +0000 (UTC) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: Quoth flagg : > I am working on a very basic xmlrpc server, which will expose certain > functions for administering BIND zone files. The big problem I am > having is parsing the incoming xmlrpc request. Basically part of the > xmlrpc request will help deterime which zone file is edited. I have > been looking at the do_POST() method from SimpleXMLRPCDispatcher and > it seems like I could code something which overides that method, > however I am new to programming am at a loss, i might even be making > this tougher than it needs to be. Is there a way to parse the > incoming xmlrpc request before the function it is calling is executed? Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead? It's been a while since I looked at XMLRPC, but why wouldn't you have a operation names, with the zone file to operate on as an argument? Then you'd just be defining your operations as methods on your SimpleXMLRPCServer, and they'd use the argument to determine which file to operate on. If that doesn't make sense, either I've forgotten how XMLRPC works, or you should explain your requirements a bit more. --RDM From rdmurray at bitdance.com Fri Jan 30 23:20:44 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:20:44 +0000 (UTC) Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: Quoth Ron Garret : > In article , > Joshua Kugler wrote: > > > Ron Garret wrote: > > > My question is: is this supposed to be happening? Or is this an > > > indication that something is wrong, and if so, what? > > > > You are probably just hitting a different instance of Apache, thus the > > different process ID. > > Yep, that's what it turned out to be. I thought I had a > WSGIDaemonProcess processes=1 directive in my config, but I had it in > the wrong place (a different vhost) so it wasn't actually active. > > But that leaves me wondering why the redirect would reliably trigger > switching processes. The reason I thought that I had the correct > configuration and only had one process is that when I reloaded the > non-redirected page I *always* got the same process ID. How does > mod_wsgi decide which process (and which thread for that matter) to use? My WAG would be that when doing a refresh your client used a persistent http connection, and thus talked again to the same Apache child, but when it got a redirect it dropped the old connection and opened up a new one, thus having a high probability of hitting a new child. But that is, as I say, a WAG. --RDM From rdmurray at bitdance.com Fri Jan 30 23:37:50 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:37:50 +0000 (UTC) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: Quoth Tim Chase : > PS: as an aside, how do I import just the fnmatch function? I > tried both of the following and neither worked: > > from glob.fnmatch import fnmatch > from glob import fnmatch.fnmatch > > I finally resorted to the contortion coded below in favor of > import glob > fnmatch = glob.fnmatch.fnmatch What you want is: from fnmatch import fnmatch fnmatch is its own module, it just happens to be in the (non __all__) namespace of the glob module because glob uses it. --RDM From aahz at pythoncraft.com Fri Jan 30 23:51:12 2009 From: aahz at pythoncraft.com (Aahz) Date: Fri, 30 Jan 2009 20:51:12 -0800 Subject: FINAL REMINDER: OSCON 2009: Call For Participation Message-ID: <20090131045112.GA14260@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From dg.gmane at thesamovar.net Sat Jan 31 00:11:10 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 06:11:10 +0100 Subject: nth root In-Reply-To: References: Message-ID: Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of (10**100)**(1./13) (floats have about 7 and doubles about 16). Dan Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From aahz at pythoncraft.com Sat Jan 31 00:16:15 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 21:16:15 -0800 Subject: Securing a database References: Message-ID: In article , wrote: > >My company provides some services online, which now they are planning >to make it offline and sell to customers who can use it in their >networks. How critical is it that this application work completely offline? I suggest that you seriously consider making your application crippleware unless it can "call home" -- that is, certain key bits work only with online access even if the majority of the app is local. This may or may not include the secure database, but if the data is local, it can still get hacked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From duprez at hinet.net.au Sat Jan 31 00:25:08 2009 From: duprez at hinet.net.au (duprez at hinet.net.au) Date: Fri, 30 Jan 2009 21:25:08 -0800 (PST) Subject: error C3861: 'Py_InitModule' Message-ID: <43a745e8-9637-40bc-882f-e5735118d479@p36g2000prp.googlegroups.com> Hi All, Using python 3.0, VS2005, WinXP SP3 I know this looks like a simple one but i just installed Python 3.0 (no other Python installations etc) and I'm trying to convert my perfectly working 2.5 C code for an embedded interpreter to 3.0. I've changed all of my string functions etc to remove those errors and I've studied the doc's and searched but I'm still getting the error regarding Py_InitModule, it's as if it no longer exists but I can't find anything different in the doc's. My intellisense and all works fine and all the other python functions are fine, just this one, does anyone have any ideas? Have I missed a change that has not made it to the doc's?? thanks, Mick. From w_a_x_man at yahoo.com Sat Jan 31 00:32:31 2009 From: w_a_x_man at yahoo.com (William James) Date: 31 Jan 2009 05:32:31 GMT Subject: Mathematica 7 compares to other languages References: <7454a7ef-ec19-4d7c-986b-d56c3ed8111b@i24g2000prf.googlegroups.com> <6a8f2eef-43e1-4a99-ae41-e4c90e6130e7@x38g2000yqj.googlegroups.com> <49404775$0$4893$607ed4bc@cv.net> <452ba58b-9377-4463-85e2-5ecdaa25a129@t39g2000prh.googlegroups.com> <6375k4pf1mleb6im67nkpec5olqbsom88e@4ax.com> Message-ID: w_a_x_man at yahoo.com wrote: > On Dec 25, 5:24?am, Xah Lee wrote: > > > The JavaScript example: > > > > // Javascript. By William James > > function normalize( vec ) { > > var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) > > a+b)) ? return vec.map(function(x) x/div) > > > > } > > > > is also not qualified. (it is syntax error in SpiderMonkey engine > > ?JavaScript-C 1.7.0 2007-10-03?) > > Since you are using the latest version of Mathematica, you should > also use the latest version of SpiderMonkey. > > The function works outside of a web browser with jslibs, and it > works in Firefox 3.0.1. > > > > > > > > Reduce: procedure normalize vec; begin scalar div; div := for each u in vec sum u^2; return map(~x/div, vec) end; From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:38:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:38:38 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> <01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: En Fri, 30 Jan 2009 07:08:29 -0200, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > > Of course this is clearly stated in the Language Reference "Variables > used > in the generator expression are evaluated lazily in a separate scope when > the next() method is called for the generator object (in the same fashion > as for normal generators). However, the in expression of the leftmost for > clause is immediately evaluated in the current scope..." -- but this > behaviour is still surprising and not obvious to me. ("not obvious" means > that things could have been different, choosing this was a design > decision). > > I am not so sure that it could have been done differently - > I see it something like this: (going back to almost your > original example, and reversing the position of globals > and locals to make it shorter) > >>>> def foo(things): > for thing in things: > yield thing() #it is obvious this is in the local scope of foo > >>>> boo = foo([locals,globals]) >>>> boo.next() > {'thing': , 'things': [ locals>, > ]} >>>> > and so it is, when you feed it the locals function > [...] > Now I don't think that you could really do it differently - > the right hand side of the generator expression is exactly > like my passed argument "things", in all cases as far as > I can see, and this means that the right hand side is > evaluated when it is "passed", and the left hand side > is whatever is done in the "for thing in things:" loop. > All the generator expression does is that it saves you > the trouble of defining the function - it kind of does it > for you, and calls it, and returns the generator object, > and throws the function away, all in one hit. (this is not > necessarily the real mechanism, but the effect is exactly > as if it were) Yes, but this is not the only alternative. You *decided* that foo and bar will take one argument - this means that it uses early binding and it is evaluated when the generator expression is created. This is a design decision, and it could have been different. The left-part of the generator expression (in the function analogy, the "yield" expression) is late bound - it is completely evaluated at every iteration, using whatever values are currently bound to external (free) variables. The same *could* happen with the right part too -- although this is not what was decided. Consider this expression: g = (x+A for x in L for y in M). This is currently expanded more or less like this: def foo(L): for x in L: for y in M: yield x+A g = foo(iter(L)) (as your example above) Note that L has a special status -- it's the only expression evaluated at the time g is defined. It *could* have been like this: def foo() for x in L: for y in M: yield x+A g = foo() or even like this: def foo(L, M, A): for x in L: for y in M: yield x+A g = foo(iter(L), iter(M), A) In particular, I like the 2nd (all late binding). Seems this topic was discussed many times [1] when PEP289 [2] was proposed, and "practicality beats purity". [1] http://mail.python.org/pipermail/python-dev/2004-April/date.html [2] http://www.python.org/dev/peps/pep-0289/ -- Gabriel Genellina From t.roberts at cqu.edu.au Sat Jan 31 00:43:37 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sat, 31 Jan 2009 15:43:37 +1000 Subject: nth root References: Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Dan, Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 is 3221.2904208350265.... there must be a quicker way of finding out its between 3221 and 3222.... ....but perhaps not. Tim ________________________________ From: Dan Goodman [mailto:dg.gmane at thesamovar.net] Sent: Sat 31-Jan-09 3:11 PM To: python-list at python.org Subject: Re: nth root Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of (10**100)**(1./13) (floats have about 7 and doubles about 16). Dan Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:48:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:48:55 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: En Fri, 30 Jan 2009 06:42:22 -0200, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: >> g = (x+B for x in A) > > I think it helps understanding if you translate the above to > >>>> A = [1,2,3] >>>> B = 1 >>>> def f(a): > ... for x in a: > ... yield x+B > ... >>>> g = f(A) >>>> A = [4,5,6] >>>> B = 10 >>>> print list(g) > [11, 12, 13] > > This is not altogether unintuitive, but I think I would prefer if it > worked > like > >>>> A = [1,2,3] >>>> B = 1 >>>> def f(a, b): > ... for x in a: > ... yield x+b > ... >>>> g = f(A, B) >>>> A = [4,5,6] >>>> B = 10 >>>> list(g) > [2, 3, 4] > > i. e. every name were bound early. Of course this wouldn't help with > locals() which would still be called in different scopes. Yep -- although I would like all names were late bound instead. But as I posted in another message, in this case "practicality beat purity" and a special case was made for the leftmost iterable. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:56:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:56:21 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> <321ac876-bc29-418a-81c7-7ef5e0f23478@u18g2000pro.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 08:50:45 -0200, escribi?: > Okay, thats just the question. I did that what you wrote but it > doesn't really works. > What is, if Py_SetProgramName() gets a NULL Pointer, if argv[0] is > empty? Why so? Are you in an embedded environment or something that doesn't have a filesystem? Calling Py_SetProgramName with an absolute path would be the easiest way to make it work. -- Gabriel Genellina From duprez at hinet.net.au Sat Jan 31 01:10:06 2009 From: duprez at hinet.net.au (duprez at hinet.net.au) Date: Fri, 30 Jan 2009 22:10:06 -0800 (PST) Subject: error C3861: 'Py_InitModule' References: <43a745e8-9637-40bc-882f-e5735118d479@p36g2000prp.googlegroups.com> Message-ID: <21385b40-9e64-473f-9d05-9729dacdf0d0@w39g2000prb.googlegroups.com> Ok, I found the reason, you now need to do a bit more work and use PyModule_Create(). Also, for anyone else that may stumble on this, you need to refer to the online Dev doc's that get updated regularly (which I regrettably forgot about) which are here -> http://docs.python.org/dev/3.0/ thanks, Mick. From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:10:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:10:39 -0200 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao escribi?: >> See the following errors I in my case: >> >> $ python >> 'import site' failed; use -v for traceback >>>>> import socket >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named socket Those errors indicate that Python is not working correctly in your system. You should fix it before going on. > Another issue is: how can I perform all of these steps in a python > script? Start reading the tutorial and working the examples: http://docs.python.org/tutorial/ In a short time (maybe shorter than you expect) you'll manage enough of Python to do this. Come back when you have specific questions, or try the tutor list: http://mail.python.org/mailman/listinfo/tutor -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:30:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:30:42 -0200 Subject: relpath problem on windows References: Message-ID: En Fri, 30 Jan 2009 14:30:53 -0200, eliben escribi?: > I'm having a problem with 2.6's new os.path.relpath function. > > This is correct: > > relpath(r'd:\abc\jho', r'd:\abc') > => 'jho' > > But this isn't: > relpath(r'd:\jho', r'd:\\') > => '..\jho' Looks like a real bug to me -- please submit it to http://bugs.python.org/ > Neither is this: > relpath(r'd:\jho', r'd:') > => '..\..\..\jho' d: means "the current directory on drive d:", and it could be something like d:\a\b\c -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:49:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:49:16 -0200 Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> <296542.92832.qm@web112216.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 16:52:07 -0200, Bernard Rankin escribi?: >> > I am trying to build python 2.6 on a machine (web server) that I do >> not have >> root access to. (has 2.4 installed) >> > >> > Python 2.5 builds fine, but I am getting an error when I run "make" >> for 2.6.1. >> Mmm... my 2.6.1 source show different line numbers, maybe you should >> check it's >> the right file? > > Wow, good catch. > > I just re-downloaded the archive and it works fine. > > I know for certain that I did no editing to the files, and even tried > expanding the original tar.gz a couple of times. > > There must be a corrupted package somewhere among the official Python > mirrors. (Sadly, I overwrote the old tar.gz file when I got the new > one.) Oops... so bad. The python.org releases have PGP signatures and MD5 published so you can verify their authenticity. -- Gabriel Genellina From joncle at googlemail.com Sat Jan 31 02:03:27 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 30 Jan 2009 23:03:27 -0800 (PST) Subject: Number of bits/sizeof int Message-ID: Hi Group, This has a certain amount of irony (as this is what I'm pretty much after):- >From http://docs.python.org/dev/3.0/whatsnew/3.1.html: "The int() type gained a bit_length method that returns the number of bits necessary to represent its argument in binary:" Any tips on how to get this in 2.5.2 as that's the production version I'm stuck with. Cheers, Jon. From mail at microcorp.co.za Sat Jan 31 02:08:20 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 31 Jan 2009 09:08:20 +0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik><01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: <012301c98372$dde73f80$0d00a8c0@hendrik> "Gabriel Genellina" wrote: >Consider this expression: g = (x+A for x in L for y in M). This is >currently expanded more or less like this: > >def foo(L): > for x in L: > for y in M: > yield x+A >g = foo(iter(L)) > >(as your example above) Note that L has a special status -- it's the only >expression evaluated at the time g is defined. It *could* have been like >this: > >def foo() > for x in L: > for y in M: > yield x+A >g = foo() > >or even like this: > >def foo(L, M, A): > for x in L: > for y in M: > yield x+A >g = foo(iter(L), iter(M), A) > >In particular, I like the 2nd (all late binding). Seems this topic was >discussed many times [1] when PEP289 [2] was proposed, and "practicality >beats purity". Ok thanks - I see where you are coming from now. It never ceases to amaze me how different we all are - Given a choice, I would have chosen the last alternative, as it feels more natural to me - the one you like feels to me as if it were too tightly coupled, somehow. - almost as if you were using named globals in a function instead of passing arguments in. But hey - I have long since learned that it is of no use to rant against the way something works, if you cannot easily change it - one can just figure out what it does, and then figure out how to use it to get it to do what one wants. Thanks for an interesting discussion. - Hendrik From sjmachin at lexicon.net Sat Jan 31 02:29:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 23:29:10 -0800 (PST) Subject: Number of bits/sizeof int References: Message-ID: <6cf38435-9cb3-49b5-a8a0-8071bfb3329f@r15g2000prh.googlegroups.com> On Jan 31, 6:03?pm, Jon Clements wrote: > Hi Group, > > This has a certain amount of irony (as this is what I'm pretty much > after):- > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. For a positive integer, the simplest method (not necessarily the fastest) is to count how many times you need to shift it right to make it become zero. For non-positive integers, what answers do you want? From catphive at catphive.net Sat Jan 31 02:31:47 2009 From: catphive at catphive.net (Brendan Miller) Date: Fri, 30 Jan 2009 23:31:47 -0800 Subject: import reassignment different at module and function scope Message-ID: <4983FE63.8010308@catphive.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 If I: import sys sys = sys.version This executes find but: import sys def f(): sys = sys.version This gives an error indicating that the sys on the right hand side of = is undefined. What gives? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmD/mMACgkQ4eGWG/zYzOmrWgCbBLuD2HNDJJly3Z1KCPoNOB1G sDgAoJ+gMCt9hWKuDUN30VUP40zqtbmJ =+pND -----END PGP SIGNATURE----- From Scott.Daniels at Acm.Org Sat Jan 31 02:34:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 23:34:14 -0800 Subject: Number of bits/sizeof int In-Reply-To: References: Message-ID: Jon Clements wrote: > ... From http://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. Well, what are your arg constraints? Integers in 0 .. 2**53? math.frexp(n)[1] --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Sat Jan 31 02:37:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 05:37:16 -0200 Subject: Number of bits/sizeof int References: Message-ID: En Sat, 31 Jan 2009 05:03:27 -0200, Jon Clements escribi?: > This has a certain amount of irony (as this is what I'm pretty much > after):- >> From http://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. I'm sure *everyone* will now post his favourite algorithm... If you search the archives, you'll find *tons* of versions. Ok, my take: def number_of_bits(num): assert num>=0 nbits = 1 max = 2 while max<=num: nbits += 1 max += max return nbits -- Gabriel Genellina From joncle at googlemail.com Sat Jan 31 02:44:04 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 30 Jan 2009 23:44:04 -0800 (PST) Subject: Number of bits/sizeof int References: <6cf38435-9cb3-49b5-a8a0-8071bfb3329f@r15g2000prh.googlegroups.com> Message-ID: <009074e6-2eea-4b8d-8cc8-2a796a0570a7@q18g2000vbn.googlegroups.com> On Jan 31, 7:29?am, John Machin wrote: > On Jan 31, 6:03?pm, Jon Clements wrote: > > > Hi Group, > > > This has a certain amount of irony (as this is what I'm pretty much > > after):- > > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > > "The int() type gained a bit_length method that returns the number of > > bits necessary to represent its argument in binary:" > > > Any tips on how to get this in 2.5.2 as that's the production version > > I'm stuck with. > > For a positive integer, the simplest method (not necessarily the > fastest) is to count how many times you need to shift it right to make > it become zero. > For non-positive integers, what answers do you want? Thankfully, all integers are positive! Must have been having a blonde moment, 'cos as soon as I read your answer it was "of course that works". Not concerned about 'fast' as I hardly think with DB and disk I/O I'm going to worry about bit- shifting... Much appreciated John, Jon. From clp2 at rebertia.com Sat Jan 31 02:47:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jan 2009 23:47:23 -0800 Subject: import reassignment different at module and function scope In-Reply-To: <4983FE63.8010308@catphive.net> References: <4983FE63.8010308@catphive.net> Message-ID: <50697b2c0901302347g3e19c93agcfded84fb1ba5b09@mail.gmail.com> On Fri, Jan 30, 2009 at 11:31 PM, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > If I: > > import sys > > sys = sys.version > > This executes find but: > > import sys > > def f(): > sys = sys.version > > This gives an error indicating that the sys on the right hand side of = > is undefined. What gives? More specifically, you get: UnboundLocalError: local variable 'sys' referenced before assignment Here's what's happening (IIRC): Python sees (during "compilation") an assignment to 'sys' within the function and (since there's no 'global' declaration within the function) infers that the name 'sys', within the scope of the function, *always* refers a local variable. IIRC, it does this for significant optimization purposes. However, when the function gets run and it goes to evaluate the right-side of the assignment, it tries to lookup 'sys' as a local variable, which obviously fails since it was never previously assigned a value in the scope of the function, hence the error. You can fix this by either renaming 'sys' within the function to something else: def f(): version = sys.version #now sys is no longer treated as local or you can indicate that you want to refer to the global sys variable: def f(): global sys #tell python we mean the global sys sys = sys.version #this will rebind 'sys' in the outer, global scope Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Sat Jan 31 03:01:05 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 06:01:05 -0200 Subject: import reassignment different at module and function scope References: <4983FE63.8010308@catphive.net> Message-ID: En Sat, 31 Jan 2009 05:31:47 -0200, Brendan Miller escribi?: > If I: > > import sys > > sys = sys.version > > This executes find but: > > import sys > > def f(): > sys = sys.version > > This gives an error indicating that the sys on the right hand side of = > is undefined. What gives? Python doesn't have local variable declarations. Inside a function, *any* name that is assigned to (e.g. any name appearing on the left side of an assignment operation, like "a" in a=8) becomes a local variable. In your example, "sys" is a local variable, and it "shadows" (or "hides") the global one of the same name. When the interpreter tries to execute sys = sys.version it complains that it can't evaluate sys.version because the local name "sys" has not been assigned yet. The same thing at the global level is OK, because sys.version refers to the global "sys" name. (This should appear in the FAQ...) -- Gabriel Genellina From gandalf at shopzeus.com Sat Jan 31 03:11:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 31 Jan 2009 09:11:03 +0100 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49840797.2030504@shopzeus.com> M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece > of code, is it bound to any class? > Those who have time and consideration can help me There are many kinds of definitions for "object oriented" languages. I have learned some things in the University, and one of them was making distinction between "pure object oriented" languages, and "mixed" languages. Pure object oriented languages does not have programming tools that are non-objects. A good example was SmallTalk, if I remember correctly. Python is not a pure object oriented language, because it has other programming tools, for example functions. However, your question seems to be pedantry. As others would say, "you can do programming in FORTRAN in any language". In other words, it is possible to use Python in a non object-oriented way, but the "good" way of using it is defining classes and making objects... So Python *is* object oriented, if you use it the right way. There might be a definition of "object oriented language" that does not apply to Python, and theoretically, you could say that according to that definition, Python is not object oriented. But practically, it is! Best, Laszlo From lists at svrinformatica.it Sat Jan 31 03:45:38 2009 From: lists at svrinformatica.it (Mailing List SVR) Date: Sat, 31 Jan 2009 09:45:38 +0100 Subject: HTTPSConnection: client certificate auth Message-ID: <1233391538.6934.14.camel@localhost.localdomain> Hi all, I have a soap client using ZSI, the other end is oracle soa 10.1.3.1.0 all works fine since some months. The last week oracle soa was configured to accept client certificate authentication over https. If I try to use the standard python httplib.HTTPSConnection library it fails with the infamous "bad record mac" error and so also ZSI that use httplib. If I configure client certificate authentication on my own apache all is fine >>> from httplib import HTTPSConnection >>> conn=HTTPSConnection('192.168.2.66',443,'/etc/cert/clients1.key','/etc/cert/clients1.crt') >>> conn.request('GET','/ws?wsdl') >>> r=conn.getresponse() >>> r.read() the connection to oracle soa works fine with other java tools such as soapui, there is some known workaround for using HTTPSConnection with oracle soa? I'm using python 2.4 on red hat 5, thanks Nicola From hongyi.zhao at gmail.com Sat Jan 31 04:44:57 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sat, 31 Jan 2009 17:44:57 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Sat, 31 Jan 2009 04:10:39 -0200, "Gabriel Genellina" wrote: >En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao >escribi$)A(.: > >>> See the following errors I in my case: >>> >>> $ python >>> 'import site' failed; use -v for traceback > >>>>>> import socket >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named socket > >Those errors indicate that Python is not working correctly in your system. >You should fix it before going on. I use cygwin, I don't know whether the further discussion on fix this issue is suitable for this group or not? If not, could you please give me some hints on the newsgroups or maillists I should resort to? > >> Another issue is: how can I perform all of these steps in a python >> script? > >Start reading the tutorial and working the examples: >http://docs.python.org/tutorial/ >In a short time (maybe shorter than you expect) you'll manage enough of >Python to do this. >Come back when you have specific questions, or try the tutor list: >http://mail.python.org/mailman/listinfo/tutor Thanks, I've subscribe to this list. -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From johnwoo.eh at gmail.com Sat Jan 31 05:20:49 2009 From: johnwoo.eh at gmail.com (woo) Date: Sat, 31 Jan 2009 02:20:49 -0800 (PST) Subject: The $5 Dollar PayPal Money Making Method Message-ID: As Seen On OPRAH & 20/20 - TURN $5 into $24600. Earn money using PAYPAL. As seen on Oprah & 20/20. THE PAYPAL 5 DOLLAR MONEY-MAKING METHOD. AS SEEN ON OPRAH. EARN HUGE $$$$$$$$ all you need is: 1) An email address 2) A PayPal account 3) $5.00 THIS IS A 2008 "CURRENT EMAIL LIST" What do you have to lose being you are only sending 1 dollar to five people. I WAS SKEPTICAL AT FIRST, but over a few days hundreds starting appearing in my paypal account! It was like Christmas morning!!!! INSTRUCTIONS: STEP 1: The first thing to do is highlight and SAVE this entire post in word or notepad on your computer so you can come back to it later. After that, if you are not already a PayPal user you need to go to the PayPal website which is http://www.paypal.com If you want to be able to receive credit card payments from other people then you will need to sign up for a PREMIER or BUSINESS account (not just a PERSONAL account). This is highly recommended to allow others easy payment options. In order to place the initial $5 into your account, you will have to verify your bank account with PAYPAL (which may take a few days). PAYPAL is 100% secure and is used by millions of people worldwide. STEP 2: Here is where the action occurs. The first thing to do is to send a $1.00 payment to each of the 5 email addresses on the current list from your PayPal account. To do this quickly and successfully, follow these simple steps: 1. Login to PayPal and click on the "Send Money" tab near the top of the screen 2. In the "Recipient's Email" field enter the email address 3. In the "Amount" field enter "1" (This is your $1.00 payment) 4. In the "Category" field select "Service" (Keeping it legal) 5. In the "Subject" field type "EMAIL LIST", and in the "NOTE" field enter "PLEASE PUT ME ON YOUR EMAIL LIST". By doing this, you are creating a service and maintaining the legality of the system by "paying" for the service. 6. Finally, click on the "Continue" button to complete the payment. Repeat these steps for each of the 5 email addresses. That's it! By sending the $1.00 payment to each address, you are implementing the compounding POWER of the system. You will reap what you sow! Here is the current e-mail list: ****************************** ******************* The email list: 1) cwatson_37... at yahoo.com 2) jacque... at yahoo.com 3) phili... at cox.net 4) boa... at hotmail.com 5) johnwoo.eh at gmail.com ************************************* STEP 3: Now take the #1 email off of the list that you see above (from your saved file), move the other addresses up (5 becomes 4, 4 becomes 3, etc.) and add YOUR email address (the one used for your PayPal account) as number 5 on the list. This is the only part of the document that should be changed. ** Make sure your email address is the one you have registered with PayPal ** STEP 4: Post your amended article to at least 200 newsgroups or message boards. Keep in mind that there are tens of thousands of groups online! All you need is 200, but remember the more you post the more money you make - as well as everyone else on the list! I've began to see money roll in before I even hit 100 posts, but try to hit around 200 to allow maximum exposure. Use Netscape, Internet Explorer, Firefox, Safari, or whatever your internet browser is to search for various news groups, log on to any search engine like yahoo.com or google.com and type in a subject like 'MILLIONAIRE MESSAGE BOARD', 'MONEY MAKING DISCUSSIONS', 'MONEY MAKING FORUMS', or 'BUSINESS MESSAGE BOARD', PAYPAL 5 DOLLAR, OPRAH 5 DOLLAR PAYPAL METHOD. You will find thousands and thousands of message boards. Click them one by one and you will find the option to post a new message. Fill in the subject which will be the header that everyone sees as they scroll through the list of postings in a particular group, and post the article with the NEW list of email addresses included. THAT'S IT!! From anders.u.persson at gmail.com Sat Jan 31 05:28:16 2009 From: anders.u.persson at gmail.com (anders) Date: Sat, 31 Jan 2009 02:28:16 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: <5b2edcf4-4eb5-425c-9535-77f3d48f0cdf@q18g2000vbn.googlegroups.com> Tanks everyone that spent time helping my, the help was great. Best regards Anders From ck.thrissur at gmail.com Sat Jan 31 05:35:44 2009 From: ck.thrissur at gmail.com (CK Raju) Date: Sat, 31 Jan 2009 16:05:44 +0530 Subject: How to manipulate a contents of file as record structures Message-ID: I have a text file containing the following alphanumerals. aaaaaa22bbbbbbbb55 hhhhhh11dpdpdpdp22 kkkkkkk21lokolkolko33 ..... I need to read the contents as single line, one after the other and append the sum of digits at the end. aaaaaa22bbbbbbbb5577 hhhhhh11dpdpdpdp2233 kkkkkkk21lokolkolko3354 .... What would be a simple way to achieve this ? CK Raju From gagsl-py2 at yahoo.com.ar Sat Jan 31 05:49:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 08:49:25 -0200 Subject: How to manipulate a contents of file as record structures References: Message-ID: En Sat, 31 Jan 2009 08:35:44 -0200, CK Raju escribi?: > I have a text file containing the following alphanumerals. > aaaaaa22bbbbbbbb55 > hhhhhh11dpdpdpdp22 > kkkkkkk21lokolkolko33 > ..... > > I need to read the contents as single line, one after the other > and append the sum of digits at the end. > aaaaaa22bbbbbbbb5577 > hhhhhh11dpdpdpdp2233 > kkkkkkk21lokolkolko3354 > .... > > What would be a simple way to achieve this ? Suppose f is the open file. To read it a line at a time: for line in f: do_something_with(line) To search for a number, try the re module: http://docs.python.org/library/re.html To do some calculation with those numbers, remember to convert them to integers first: x="12" y="34" x+y gives "1234" int(x)+int(y) gives 46 Good luck! -- Gabriel Genellina From ck.thrissur at gmail.com Sat Jan 31 06:07:57 2009 From: ck.thrissur at gmail.com (CK Raju) Date: Sat, 31 Jan 2009 16:37:57 +0530 Subject: How to manipulate a contents of file as record structures In-Reply-To: References: Message-ID: On Sat, Jan 31, 2009 at 4:19 PM, Gabriel Genellina wrote: > for line in f: > do_something_with(line) Thanks a lot. CK Raju From XX.XmcX at XX.XmclaveauX.com Sat Jan 31 06:10:20 2009 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Sat, 31 Jan 2009 12:10:20 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: Re > ?builtin? is not a class. I think "object" ; not only "class" And "builtin" is an object. -- @-salutations Michel Claveau From castironpi at gmail.com Sat Jan 31 06:12:24 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 31 Jan 2009 03:12:24 -0800 (PST) Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik><01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: On Jan 31, 1:08?am, "Hendrik van Rooyen" wrote: > "Gabriel Genellina" wrote: snip > >or even like this: > > >def foo(L, M, A): > > ? for x in L: > > ? ? for y in M: > > ? ? ? yield x+A > >g = foo(iter(L), iter(M), A) > > >In particular, I like the 2nd (all late binding). Seems this topic was ? > >discussed many times [1] when PEP289 [2] was proposed, and "practicality ? > >beats purity". > > Ok thanks - I see where you are coming from now. > It never ceases to amaze me how different we all are - > Given a choice, I would have chosen the last alternative, > as it feels more natural to me - the one you like feels to > me as if it were too tightly coupled, somehow. - almost > as if you were using named globals in a function instead > of passing arguments in. snip Did anyone observe this yet? >>> global_vars = {} >>> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >>> print eval('all((x == y for x in ar))', local_vars, global_vars ) False >>> print eval('all((x == y for x in ar))', global_vars, local_vars) #error as original From aj at cubbyhole.net Sat Jan 31 06:35:05 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 11:35:05 +0000 Subject: Empty string is False right? Message-ID: <246E932C-93F6-486D-9991-15E55A662ED3@cubbyhole.net> Hello, First post so bear with me if I'm being a numpty ... Is it me or is there something slightly counter intuitive and thus not so pythonesque about this: >>> s = '' >>> if s: True ... else: False ... False >>> s and eval(s) '' >>> Regards, AJ From andrew at acooke.org Sat Jan 31 06:39:20 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 03:39:20 -0800 (PST) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: <4d802030-df80-4e02-ae70-fa736a4f4f74@r40g2000yqj.googlegroups.com> On Jan 30, 11:59?pm, flagg wrote: > I am working on a very basic xmlrpc server, which will expose certain > functions for administering BIND zone files. ?The big problem I am > having is parsing the incoming xmlrpc request. ?Basically part of the [...] at the risk of repeating what the other guy said, it sounds like you're going about this in the wrong way. the xmlrpc server will parse the incoming request for you if you supply it with a suitable function to invoke. so, for normal use, you do not override anything. andrew From bj_666 at gmx.net Sat Jan 31 06:42:14 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 31 Jan 2009 11:42:14 GMT Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> Message-ID: <6uiromFfkfaeU1@mid.uni-berlin.de> On Fri, 30 Jan 2009 21:59:34 +0100, Stef Mientki wrote: > Marc 'BlackJack' Rintsch wrote: >> On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: >> >> >>> try this: >>> >>> class MyRegClass ( int ) : >>> def __init__ ( self, value ) : >>> self.Value = value >>> def __repr__ ( self ) : >>> line = hex ( self.Value ) >>> line = line [:2] + line [2:].upper() >>> return line >>> >>> >> def __repr__(self): >> return '0x%X' % self.value >> >> >>> __str__ = __repr__ >>> >>> >> This is unnecessary, the fallback of `__str__` is `__repr__` already. >> >> > well this is what my Python is doing: > > without _str__ = __repr__ > >>print shadow_register > 170 > > with _str__ = __repr__ > >>print shadow_register > 0xAA Then don't inherit from `int`. Why are you doing this anyway? If you inherit from `int` you shouldn't store the value in an extra attribute but use the `int`\s value. This way you have one value used by the `int` methods and one used by your own methods. Ciao, Marc 'BlackJack' Rintsch From andrew at acooke.org Sat Jan 31 06:46:32 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 03:46:32 -0800 (PST) Subject: Where to host a (Python) project? Message-ID: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Hi, I have a new project, that I just released in beta (http:// www.acooke.org/lepl - a recursive decent parser with full backtracking). At the moment I am using pypi and setuptools for distribution (it's a pure python package) and I am happy with hosting static web pages (the manual and api doc linked to above) on my own site (I did try the packages.python.org web pages, but it seemed pointless duplicating my own). However, i am thinking I could really do with: - a mailing list - simple bug tracking - subversion and am wondering which is the best (free) provider for these (the code is LGPL open source). I'd prefer a mailing list to something like google groups (although I guess it may be possible to configure a gateway) and I could open up my personal subversion server, but that seems like a lot of work (not really that interested in moving to something other than svn). Any recommendations? Thanks, Andrew From csaba.hoch at gmail.com Sat Jan 31 06:51:35 2009 From: csaba.hoch at gmail.com (Csaba Hoch) Date: Sat, 31 Jan 2009 12:51:35 +0100 Subject: Why do operators and methods of built-in types differ Message-ID: <49843B47.4010906@gmail.com> Hi, if I write the following: >>> 1+1 2 it seems to be exactly equivalent to this: >>> (1).__add__(1) 2 However, if I write invalid code and try to add a list to an int, the errors will be different: >>> 1+[] Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'list' >>> (1).__add__([]) NotImplemented I found that operator.__add__(1, []) gives the same result as 1+[]. What is the reason behind this difference between the __add__ operator and int.__add__? Thank you, Csaba From ralf at schoenian-online.de Sat Jan 31 07:12:41 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sat, 31 Jan 2009 13:12:41 +0100 Subject: Empty string is False right? In-Reply-To: References: Message-ID: <49844039.7040900@schoenian-online.de> AJ Ostergaard wrote: > Hello, > > First post so bear with me if I'm being a numpty ... > > Is it me or is there something slightly counter intuitive and thus not > so pythonesque about this: > > >>> s = '' > >>> if s: True > .... else: False > .... > False > >>> s and eval(s) > '' > >>> > > Regards, > AJ > Hi, yes, the following evaluates to False: empty String: '' empty list: [] empty tuple: () empty dict: {} 0, None and False of course Regards, Ralf From ralf at schoenian-online.de Sat Jan 31 07:12:41 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sat, 31 Jan 2009 13:12:41 +0100 Subject: Empty string is False right? In-Reply-To: References: Message-ID: <49844039.7040900@schoenian-online.de> AJ Ostergaard wrote: > Hello, > > First post so bear with me if I'm being a numpty ... > > Is it me or is there something slightly counter intuitive and thus not > so pythonesque about this: > > >>> s = '' > >>> if s: True > .... else: False > .... > False > >>> s and eval(s) > '' > >>> > > Regards, > AJ > Hi, yes, the following evaluates to False: empty String: '' empty list: [] empty tuple: () empty dict: {} 0, None and False of course Regards, Ralf From aj at cubbyhole.net Sat Jan 31 07:16:19 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 12:16:19 +0000 Subject: Empty string is False right? In-Reply-To: <49844039.7040900@schoenian-online.de> References: <49844039.7040900@schoenian-online.de> Message-ID: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Hi Ralf, Thanks for that but why: >>> '' and True '' Surely that should be False?!? Regards, AJ On 31 Jan 2009, at 12:12, Ralf Schoenian wrote: > AJ Ostergaard wrote: >> Hello, >> First post so bear with me if I'm being a numpty ... >> Is it me or is there something slightly counter intuitive and thus >> not so pythonesque about this: >> >>> s = '' >> >>> if s: True >> .... else: False >> .... >> False >> >>> s and eval(s) >> '' >> >>> >> Regards, >> AJ > > Hi, > > yes, the following evaluates to False: > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} > 0, None > and False of course > > Regards, > Ralf From dickinsm at gmail.com Sat Jan 31 07:24:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 04:24:56 -0800 (PST) Subject: nth root References: Message-ID: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> On Jan 31, 5:43?am, "Tim Roberts" wrote: > Dan, > > Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 > is 3221.2904208350265.... > there must be a quicker way of finding out its between 3221 and 3222.... > > ....but perhaps not. I don't think you'll find anything much quicker than n**(1./13) (though I hope that if you're doing this millions of time then you're precomputing the 1./13 rather than redoing the division every single time. What happens behind the scenes here is that your integer is immediately converted to a float, then the system math library is used for the power operation. The integer -> float conversion is probably quite significant, timewise. I'd also be a bit worried about accuracy. Is it important to you that the integer part of the result is *exactly* right, or is it okay if (n**13)**(1./13) sometimes comes out as slightly less than n, or if (n**13-1)**(1./13) sometimes comes out as n? Mark From gagsl-py2 at yahoo.com.ar Sat Jan 31 07:26:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 10:26:50 -0200 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: En Sat, 31 Jan 2009 10:16:19 -0200, AJ Ostergaard escribi?: > Hi Ralf, > > Thanks for that but why: > > >>> '' and True > '' > > Surely that should be False?!? Python does "short-circuit evaluation" [1] "and" and "or" return one of its operands as soon as the outcome is determined, not just True or False. '' is a false value, as false as False itself :) After seeing that, there is no point in evaluating the second operand (True) because the final result cannot be true; so Python just returns the first operand. [1] http://en.wikipedia.org/wiki/Short_circuit_evaluation -- Gabriel Genellina From Bernd.Nawothnig at t-online.de Sat Jan 31 07:27:10 2009 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sat, 31 Jan 2009 13:27:10 +0100 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: On 2009-01-31, AJ Ostergaard wrote: > Thanks for that but why: >>>> '' and True > '' > Surely that should be False?!? It is: #v+ >>> bool('' and True) False #v- Bernd -- No time toulouse From vlastimil.brom at gmail.com Sat Jan 31 07:27:14 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 31 Jan 2009 13:27:14 +0100 Subject: Empty string is False right? In-Reply-To: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> 2009/1/31 AJ Ostergaard : > Hi Ralf, > > Thanks for that but why: > >>>> '' and True > '' > > Surely that should be False?!? > > Regards, > AJ > > see the docs: http://docs.python.org/reference/expressions.html#boolean-operations "The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned." hth, vbr From sjmachin at lexicon.net Sat Jan 31 07:32:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 04:32:16 -0800 (PST) Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <50869881-9f4b-4162-bdec-2c31b97372ef@g3g2000pre.googlegroups.com> On Jan 31, 11:12?pm, Ralf Schoenian wrote: > yes, the following evaluates to False: A much better way of describing the effect would be to say that the following are treated as false (no capital letter!) in a conditional context. > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} *any* empty container ... > 0, None > and False of course and objects which adhere to the protocol From andrew at acooke.org Sat Jan 31 07:33:12 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 04:33:12 -0800 (PST) Subject: Why do operators and methods of built-in types differ References: Message-ID: <14ee28f9-a504-4bf4-9213-6412243cd757@l39g2000yqn.googlegroups.com> On Jan 31, 8:51?am, Csaba Hoch wrote: > What is the reason behind this difference between the __add__ operator > and int.__add__? this is quite common in python. the special methods like __add__ are used to implement some functionality (like '+' in this case), but they are not all of it. for example, when a + b is evaluated, a.__add__(b) is attempted, but if that fails (raises a NotImplemented error) then b.__radd__(a) is tried instead. so there's not a 1-to-1 correspondence between '+' and __add__() and that is reflected in the exceptions, too. when a method does not exist a NotImplemented error is raised, but '+' contains extra logic and raises a more useful error message. does that make sense? i should probably add that this is just how i understand things - i assume it's correct, but i've not looked anything up in the documentation. andrew From aj at cubbyhole.net Sat Jan 31 07:36:03 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 12:36:03 +0000 Subject: Empty string is False right? In-Reply-To: <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: I'm not suggesting it's not operating as advertised - I'm suggesting the 'advertising' is slightly sguiffy if you catch my drift. I guess it's just me that finds it slightly counter intuitive. Surely intuitively the expression is "and" and therefore should always return a boolean? I'll shut up now. ;) AJ On 31 Jan 2009, at 12:27, Vlastimil Brom wrote: > 2009/1/31 AJ Ostergaard : >> Hi Ralf, >> >> Thanks for that but why: >> >>>>> '' and True >> '' >> >> Surely that should be False?!? >> >> Regards, >> AJ >> >> > see the docs: > http://docs.python.org/reference/expressions.html#boolean-operations > > "The expression x and y first evaluates x; if x is false, its value is > returned; otherwise, y is evaluated and the resulting value is > returned." > > hth, > vbr From gagsl-py2 at yahoo.com.ar Sat Jan 31 07:40:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 10:40:06 -0200 Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> Message-ID: En Sat, 31 Jan 2009 09:51:35 -0200, Csaba Hoch escribi?: > if I write the following: > > >>> 1+1 > 2 > > it seems to be exactly equivalent to this: > > >>> (1).__add__(1) > 2 > > However, if I write invalid code and try to add a list to an int, the > errors will be different: > > >>> 1+[] > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'int' and 'list' > > >>> (1).__add__([]) > NotImplemented > > I found that operator.__add__(1, []) gives the same result as 1+[]. > > What is the reason behind this difference between the __add__ operator > and int.__add__? The operator "+" does more than blindy calling left.__add__(right). In this case, as int + list returns NotImplemented, it reverses the operands and tries right.__radd__(left), and only then it gives up and raises TypeError. The actual rules are a bit more complex, involving type conversion too; see http://docs.python.org/reference/datamodel.html#emulating-numeric-types -- Gabriel Genellina From sjmachin at lexicon.net Sat Jan 31 07:43:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 04:43:25 -0800 (PST) Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <0f67afbd-8052-4ee7-9017-e844be85cca1@z28g2000prd.googlegroups.com> On Jan 31, 11:16?pm, AJ Ostergaard wrote: > Hi Ralf, > > Thanks for that but why: > > ?>>> '' and True > '' > > Surely that should be False?!? No, deliberately not. Read this for Python 3.0 http://docs.python.org/3.0/reference/expressions.html#boolean-operations and/or this for Python 2.X http://docs.python.org/reference/expressions.html#boolean-operations [essentially the only difference in 3.0 is a change to the protocol that allows a non-builtin object to say whether it is true or false] From csaba.hoch at gmail.com Sat Jan 31 07:49:03 2009 From: csaba.hoch at gmail.com (Csaba Hoch) Date: Sat, 31 Jan 2009 13:49:03 +0100 Subject: Why do operators and methods of built-in types differ In-Reply-To: References: <49843B47.4010906@gmail.com> Message-ID: <498448BF.2020307@gmail.com> Gabriel Genellina wrote: > The operator "+" does more than blindy calling left.__add__(right). In > this case, as int + list returns NotImplemented, it reverses the > operands and tries right.__radd__(left), and only then it gives up and > raises TypeError. > > The actual rules are a bit more complex, involving type conversion too; > see http://docs.python.org/reference/datamodel.html#emulating-numeric-types Thanks for both of you, it's much clearer now. Just a correction: according to the doc, NotImplemented is not an error, but a returned value. Csaba From bignose+hates-spam at benfinney.id.au Sat Jan 31 07:56:43 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 23:56:43 +1100 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <87ab9763ck.fsf@benfinney.id.au> Ralf Schoenian writes: > yes, the following evaluates to False: > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} > 0, None > and False of course More precisely: All the above evaluate as Boolean false. But only one of them evaluates to False: the object bound to the name ?False?. >>> bool(None) == bool(False) True >>> None == False False >>> None is False False >>> bool('') == bool(False) True >>> '' == False False >>> '' is False False >>> bool(0) == bool(False) True >>> 0 == False False >>> 0 is False False -- \ ?What is it that makes a complete stranger dive into an icy | `\ river to save a solid gold baby? Maybe we'll never know.? ?Jack | _o__) Handey | Ben Finney From martin at marcher.name Sat Jan 31 07:59:50 2009 From: martin at marcher.name (Martin) Date: Sat, 31 Jan 2009 13:59:50 +0100 Subject: Where to host a (Python) project? In-Reply-To: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <5fa6c12e0901310459t23757ed2x5b476abce9f9cd3b@mail.gmail.com> Hi, 2009/1/31 andrew cooke : > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion > and am wondering which is the best (free) provider for these (the code > is LGPL open source). I'd prefer a mailing list to something like > google groups (although I guess it may be possible to configure a > gateway) and I could open up my personal subversion server, but that > seems like a lot of work (not really that interested in moving to > something other than svn). Google Groups can be perfectly used as Mailings Lists - while I'm not a huge fan of them that isn't an argument from your feature list :) There's tigris.org, savannah (savannah.gnu.org, nongnu.org), launchpad. All of them are fine to some extent, you might want to read up on PyMotW about how Doug Hellmann decided where to host his stuff. hth Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From andrew at acooke.org Sat Jan 31 08:03:13 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 05:03:13 -0800 (PST) Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> Message-ID: <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> > Just a correction: according to the doc, NotImplemented is not an > error, but a returned value. curious, so it is. i wonder why there is both a special return value (NotIMplemented) and a related exception (NotImplementedError). seems very odd to have a value... andrew From steve at holdenweb.com Sat Jan 31 08:06:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:06:02 -0500 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: MC wrote: > Re > >> ?builtin? is not a class. > > I think "object" ; not only "class" > And "builtin" is an object. > You can think what you like, but there is a fundamental difference between methods of a class and functions of a module. Until you appreciate that you will likely make mistakes. Don't worry, though, we all learn from our mistakes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Sat Jan 31 08:10:54 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 05:10:54 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 9:59?am, Martin wrote: > There's tigris.org, savannah (savannah.gnu.org, nongnu.org), > launchpad. All of them are fine to some extent, you might want to read > up on PyMotW about how Doug Hellmann decided where to host his stuff. all i can find is that he is writing his own! http://blog.doughellmann.com/search/label/codehosting (his reqs are quite different to mine - I am looking for an external provider because I do not want to host dynamic pages myself). anyway, if that was what you mean, fine - i just wonder if i am missing something? thanks, andrew From steve at holdenweb.com Sat Jan 31 08:23:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:23:02 -0500 Subject: nth root In-Reply-To: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: Mark Dickinson wrote: > On Jan 31, 5:43 am, "Tim Roberts" wrote: >> Dan, >> >> Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 >> is 3221.2904208350265.... >> there must be a quicker way of finding out its between 3221 and 3222.... >> >> ....but perhaps not. > > I don't think you'll find anything much quicker than n**(1./13) > (though I hope > that if you're doing this millions of time then you're precomputing > the 1./13 > rather than redoing the division every single time. > Compared with the computation involved in the power computation I think you'll find this makes a negligible difference in timing. But that's just mu gut instinct, and we both know that a benchmark is the only way to be certain, right? It just seems like a possibly premature optimization to me. [sigh. I had to start this, didn't i?] >>> t1 = timeit.Timer("x = 4021503534212915433093809093996098953996019232**(1.0/13)") >>> t2 = timeit.Timer("x = 4021503534212915433093809093996098953996019232**power", "power=1.0/13") >>> t1.timeit() 1.4860000610351562 >>> t2.timeit() 1.3789999485015869 >>> Hmm, well, I suppose an 9% speed gain might be worth it. > What happens behind the scenes here is that your integer is > immediately > converted to a float, then the system math library is used for the > power operation. The integer -> float conversion is probably quite > significant, timewise. > I bow to your superior intuition! > I'd also be a bit worried about accuracy. Is it important to you > that the > integer part of the result is *exactly* right, or is it okay if > (n**13)**(1./13) sometimes comes out as slightly less than n, or if > (n**13-1)**(1./13) sometimes comes out as n? > Much more significant points, given the limited precision of the doubles Python will be using. Could gmpy do this better, I wonder? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From darcy at druid.net Sat Jan 31 08:24:06 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 31 Jan 2009 08:24:06 -0500 Subject: Empty string is False right? In-Reply-To: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: <20090131082406.1ebcac1e.darcy@druid.net> On Sat, 31 Jan 2009 12:16:19 +0000 AJ Ostergaard wrote: > >>> '' and True > '' > > Surely that should be False?!? Why? The first value evaluates to False in a boolean context and thus is returned in the above statement due to short circuit evaluation but is not itself False. You wouldn't expect the following statement to be True. >>> '' is False False -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Sat Jan 31 08:27:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:27:20 -0500 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: AJ Ostergaard wrote: > I'm not suggesting it's not operating as advertised - I'm suggesting the > 'advertising' is slightly sguiffy if you catch my drift. I guess it's > just me that finds it slightly counter intuitive. Surely intuitively the > expression is "and" and therefore should always return a boolean? > > I'll shut up now. ;) > You might think so, and it wouldn't be an entirely unreasonable thought, but in practice it makes a lot of sense to retain the original value where possible. The fact is that any left-hand operand that evaluates to false in a Boolean context can be used as it stands rather than being converted to Boolean first. So the conversion is essentially useless processing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Sat Jan 31 08:45:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 07:45:46 -0600 Subject: glob.fnmatch (was "search speed") In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: <4984560A.1000406@tim.thechases.com> rdmurray at bitdance.com wrote: > Quoth Tim Chase : >> PS: as an aside, how do I import just the fnmatch function? I >> tried both of the following and neither worked: >> >> from glob.fnmatch import fnmatch >> from glob import fnmatch.fnmatch >> >> I finally resorted to the contortion coded below in favor of >> import glob >> fnmatch = glob.fnmatch.fnmatch > > What you want is: > > from fnmatch import fnmatch Oh, that's head-smackingly obvious now...thanks! My thought process usually goes something like """ I want to do some file-name globbing there's a glob module that looks like a good place to start hmm, dir(glob) tells me there's a fnmatch thing that looks like what I want according to help(glob.fnmatch) oh, the fnmatch() function is inside this glob.fnmatch thing so, I want glob.fnmatch.fnmatch() """ It never occurred to me that fnmatch was its own importable module. -tkc From martin at marcher.name Sat Jan 31 08:51:13 2009 From: martin at marcher.name (Martin) Date: Sat, 31 Jan 2009 14:51:13 +0100 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <5fa6c12e0901310551i6bffacc5icdd460606c82f29f@mail.gmail.com> 2009/1/31 andrew cooke : > On Jan 31, 9:59 am, Martin wrote: >> There's tigris.org, savannah (savannah.gnu.org, nongnu.org), >> launchpad. All of them are fine to some extent, you might want to read >> up on PyMotW about how Doug Hellmann decided where to host his stuff. > > all i can find is that he is writing his own! > http://blog.doughellmann.com/search/label/codehosting > (his reqs are quite different to mine - I am looking for an external > provider because I do not want to host dynamic pages myself). Darn, my bad. I just remembered that something happened in terms of hosting on his site, I thought he had decided on this: http://blog.doughellmann.com/2008/12/moving-pymotw-to-public-repository.html (seems he didn't have any time...) anyway, tigris, nongnu and savannah are hopefully at least useable information :) /Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From a at nospam.org Sat Jan 31 08:51:16 2009 From: a at nospam.org (Armin) Date: Sat, 31 Jan 2009 14:51:16 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: >> > > Right at the end: "To install data files directly in the target > directory, an empty string should be given as the directory." > > setup(..., > data_files=[ > ('', ['list/of/file/names', > 'perhaps/including/source/directory']), > ] > ) > Yes ... so far the theory :) As posted before ... set's my script (python 2.3): from distutils.core import setup import py2exe setup(windows=['dpconf.py'], data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] ) When I create the distribution I got the following err msg: *** copy data files *** warning: install_data: setup script did not provide a directory for '' -- installing right in 'C:\pyDPCONF.2.3-dev\dist' error: can't copy '': doesn't exist or not a regular file Looks a little bit inconsistent ? --Armin From dickinsm at gmail.com Sat Jan 31 09:03:07 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 06:03:07 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> On Jan 31, 1:23?pm, Steve Holden wrote: > [Mark] > > power operation. ?The integer -> float conversion is probably quite > > significant, timewise. > > I bow to your superior intuition! Here's another timing that shows the significance of the int -> float conversion: (non-debug build of the trunk) >>> t1 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232; power = 1./13") >>> t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") >>> t1.timeit() 0.34778499603271484 >>> t2.timeit() 0.26025009155273438 I've got a patch posted to the tracker somewhere that improves the accuracy of long->float conversions, while also speeding them up a tiny bit (but not a lot...). Mark From dickinsm at gmail.com Sat Jan 31 09:05:57 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 06:05:57 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> On Jan 31, 1:23?pm, Steve Holden wrote: > Much more significant points, given the limited precision of the doubles > Python will be using. Could gmpy do this better, I wonder? Almost certainly, if exact results are wanted! At least, GMP has an mpz_root function; I don't know offhand whether gmpy makes it accessible from Python. Mark From michele.simionato at gmail.com Sat Jan 31 09:07:19 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 31 Jan 2009 06:07:19 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <62117934-9a3e-45a0-bbc5-4206ba9a6429@l33g2000pri.googlegroups.com> On Jan 31, 12:46?pm, andrew cooke wrote: > Any recommendations? Google Code seems fine. From grante at visi.com Sat Jan 31 09:15:58 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 31 Jan 2009 08:15:58 -0600 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: On 2009-01-31, Vlastimil Brom wrote: > 2009/1/31 AJ Ostergaard : >> Hi Ralf, >> >> Thanks for that but why: >> >>>>> '' and True >> '' >> >> Surely that should be False?!? >> >> Regards, >> AJ >> >> > see the docs: > http://docs.python.org/reference/expressions.html#boolean-operations > > "The expression x and y first evaluates x; if x is false, But that doesn't mean "x is False" in the strict Python expression sense of the phrase. It means if bool(x) is False (or something reasonably close to that). > its value is returned; otherwise, y is evaluated and the > resulting value is returned." -- Grant From eliben at gmail.com Sat Jan 31 09:22:34 2009 From: eliben at gmail.com (eliben) Date: Sat, 31 Jan 2009 06:22:34 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: andrew cooke wrote: > Hi, > > I have a new project, that I just released in beta (http:// > www.acooke.org/lepl - a recursive decent parser with full > backtracking). At the moment I am using pypi and setuptools for > distribution (it's a pure python package) and I am happy with hosting > static web pages (the manual and api doc linked to above) on my own > site (I did try the packages.python.org web pages, but it seemed > pointless duplicating my own). > > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion code.google.com provides all of these in a free and convenient manner. Recommended. From andrew at acooke.org Sat Jan 31 10:03:40 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 07:03:40 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 11:22?am, eliben wrote: > code.google.com provides all of these in a free and convenient manner. > Recommended. unfortunately google don't seem that reliable ;o) (have you tried a google search today?) From lists at cheimes.de Sat Jan 31 10:08:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jan 2009 16:08:34 +0100 Subject: Why do operators and methods of built-in types differ In-Reply-To: <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> References: <49843B47.4010906@gmail.com> <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> Message-ID: andrew cooke schrieb: >> Just a correction: according to the doc, NotImplemented is not an >> error, but a returned value. > > curious, so it is. i wonder why there is both a special return value > (NotIMplemented) and a related exception (NotImplementedError). seems > very odd to have a value... They are different and unrelated things. The NotImplentedError is an exception class while NotImplemented is a singleton like None. When a method like __add__ can't handle the other object it returns NotImplemented. It doesn't raise a NotImplementedError. The NotImplemented singleton is an optimization. The interpreter just has to compare the memory address of the returned value with the address of NotImplemented. That's a super fast op in C. Christian From theller at python.net Sat Jan 31 10:12:17 2009 From: theller at python.net (Thomas Heller) Date: Sat, 31 Jan 2009 16:12:17 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: <6uj823Ffh7l1U1@mid.individual.net> Armin schrieb: > As posted before ... set's my script (python 2.3): > > from distutils.core import setup > import py2exe > > setup(windows=['dpconf.py'], > data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] > ) > > When I create the distribution I got the following err msg: > > *** copy data files *** > warning: install_data: setup script did not provide a directory for '' > -- installing right in 'C:\pyDPCONF.2.3-dev\dist' > error: can't copy '': doesn't exist or not a regular file >From the Python docs (chapter 'writing the setup script): """ data_files specifies a sequence of (directory, files) pairs in the following way: setup(..., data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), ('config', ['cfg/data.cfg']), ('/etc/init.d', ['init-script'])] ) """ So, it looks like you should use > setup(windows=['dpconf.py'], > data_files=[("", ["proj_db","gsd_db","dachs2.xbm"])] ^ ^ > ) Thomas From gagsl-py2 at yahoo.com.ar Sat Jan 31 10:15:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 13:15:35 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Sat, 31 Jan 2009 11:51:16 -0200, Armin escribi?: > Gabriel Genellina wrote: >> En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: >> Right at the end: "To install data files directly in the target >> directory, an empty string should be given as the directory." >> setup(..., >> data_files=[ >> ('', ['list/of/file/names', >> 'perhaps/including/source/directory']), >> ] >> ) >> > Yes ... so far the theory :) > > As posted before ... set's my script (python 2.3): You didn't tell us that you were using version 2.3 -- it's important, as the current stable releases are 2.6 and 3.0. Anyway, this should work in 2.3 too. > from distutils.core import setup > import py2exe > > setup(windows=['dpconf.py'], > data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] > ) > Comparing my example and yours, you lack a parenthesis level: setup(windows=['dpconf.py'], data_files=[("", ["proj_db","gsd_db","dachs2.xbm"])] ) > When I create the distribution I got the following err msg: > > *** copy data files *** > warning: install_data: setup script did not provide a directory for '' > -- installing right in 'C:\pyDPCONF.2.3-dev\dist' > error: can't copy '': doesn't exist or not a regular file > > Looks a little bit inconsistent ? O thou of little faith, try again... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 10:16:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 13:16:03 -0200 Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> Message-ID: En Sat, 31 Jan 2009 11:03:13 -0200, andrew cooke escribi?: > >> Just a correction: according to the doc, NotImplemented is not an >> error, but a returned value. > > curious, so it is. i wonder why there is both a special return value > (NotIMplemented) and a related exception (NotImplementedError). seems > very odd to have a value... I consider it an optimization. Raising an exception is more costly than returning a value, and this failure is likely to happen often (not all types define all possible operators). AFAIK this is only recognized by the binary operators (__add__, __iadd__, etc) and rich comparisons (__eq__, __lt__, etc.) -- Gabriel Genellina From aahz at pythoncraft.com Sat Jan 31 10:32:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 31 Jan 2009 07:32:30 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xr62ufv1c.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr62ufv1c.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> CPython's "primitive" storage management has a lot to do with the >> simplicity of interfacing CPython with external libraries. Any solution >> that proposes to get rid of the GIL needs to address that. > >This, I don't understand. Other languages like Lisp and Java and >Haskell have foreign function interfaces that easier to program than >Python's, -and- they don't use reference counts. There's usually some >primitive to protect objects from garbage collection while the foreign >function is using them, etc. The Java Native Interface (JNI) and the >Haskell FFI are pretty well documented. The Emacs Lisp system is not >too hard to figure out from examining the source code, etc. This is the first time I've heard about Java being easier to interface than Python. I don't work at that level myself, so I rely on the informed opinions of other people; can you provide a summary of what makes those FFIs easier than Python? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From notvalid2 at sbcglobal.net Sat Jan 31 10:41:35 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 07:41:35 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Steve Holden wrote: > W. eWatson wrote: >> r wrote: >>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>> Where in the world is a description of pack() for Tkinter widgets? Is it >>>> some sort of general method for all widgets? I'm looking in a few >>>> docs that >>>> use it without ever saying where it is described. For one, >>>> . In the NM Tech pdf on >>>> Tkinter, >>>> it's not found anywhere. I see Universal methods for widgets, but no >>>> mention >>>> of pack(). package, packed, but no pack. >>> did you try here :) >>> http://effbot.org/tkinterbook/pack.htm >> Thanks. I have the site bookmarked, but it's hard to search. I posted a >> comment to them that they should have it in pdf form. >> > http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack > > regards > Steve Well, that's an interesting "link". Another side of Google facilities? Maybe you're using Snagit or its brethern? However, I'm interested in searching a pdf, which, of course, doesn't yet exist. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Sat Jan 31 10:50:47 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 07:50:47 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 14:55:13 -0200, W. eWatson > escribi?: >> Gabriel Genellina wrote: >>> En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson >>> escribi?: >>> >>>> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? >>> There is a PDF version of "An Introduction to Tkinter" here: >>> http://www.pythonware.com/library/ >>> >> Thanks. I have it but it's an odd one to search on "pack(". There may >> be over 100 reference to pack(. It's probably explained there >> somewhere, but how many times do I want to press the search key? I >> have it printed out too. I guess I need to eyeball it. It's probably >> faster. Maybe find the section (geometry?) where it and others like it >> are found. There is an index, but it's a pitiful one page. > > Uh? The very first occurence of "pack" is in the Table of Contents, "The > pack geometry manager". (You may want to improve your search skills :) ) > Yes, that's correct, but I was looking for "pack(". It all depends on one's perspective on how to search. I'll not labor the point. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From rdmurray at bitdance.com Sat Jan 31 11:07:08 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 16:07:08 +0000 (UTC) Subject: glob.fnmatch (was "search speed") References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> <4984560A.1000406@tim.thechases.com> Message-ID: Quoth Tim Chase : > rdmurray at bitdance.com wrote: > > What you want is: > > > > from fnmatch import fnmatch > > Oh, that's head-smackingly obvious now...thanks! > > My thought process usually goes something like > > """ > I want to do some file-name globbing > > there's a glob module that looks like a good place to start > > hmm, dir(glob) tells me there's a fnmatch thing that looks like > what I want according to help(glob.fnmatch) > > oh, the fnmatch() function is inside this glob.fnmatch thing > > so, I want glob.fnmatch.fnmatch() > """ > > It never occurred to me that fnmatch was its own importable > module. I did a help(glob), saw that fnmatch wasn't in there, did a dir(glob), saw fnmatch and was puzzled, so I looked up the glob doc page on docs.python.org for glob. There was a cross reference at the bottom of the page to fnmatch, and it was only at that point that I went: "oh, duh" :) --RDM From deets at nospam.web.de Sat Jan 31 11:09:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 31 Jan 2009 17:09:37 +0100 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> Message-ID: <6ujbe0Ffhh6lU1@mid.uni-berlin.de> AJ Ostergaard schrieb: > Hi Ralf, > > Thanks for that but why: > > >>> '' and True > '' > > Surely that should be False?!? No. Please read the section in the language reference about the and/or operators. "and" will return the first false value, or the right side. Thus '' and True -> '' True and '' -> '' 'a' and True -> True True and 'a' -> 'a' "or" does the same, obviously with the or-semantics: '' or False -> False False or '' -> '' '' or True -> True True or '' -> True 'a' or False -> 'a' False or 'a' -> 'a' Diez From robin at NOSPAMreportlab.com Sat Jan 31 11:39:23 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 31 Jan 2009 16:39:23 +0000 Subject: fastest way to detect a user type Message-ID: <49847EBB.4050307@jessikat.plus.net> Whilst considering a port of old code to python 3 I see that in several places we are using type comparisons to control processing of user instances (as opposed to instances of built in types eg float, int, str) I find that the obvious alternatives are not as fast as the current code; func0 below. On my machine isinstance seems slower than type for some reason. My 2.6 timings are C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func0(v) 1000000 loops, best of 3: 0.348 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func1(v) 1000000 loops, best of 3: 0.747 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func2(v) 1000000 loops, best of 3: 0.378 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func3(v) 1000000 loops, best of 3: 0.33 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func0(1) 1000000 loops, best of 3: 0.477 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func1(1) 1000000 loops, best of 3: 1.14 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func2(1) 1000000 loops, best of 3: 1.16 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func3(1) 1000000 loops, best of 3: 1.14 usec per loop so func 3 seems to be the fastest option for the case when the first test matches, but is poor when it doesn't. Can anyone suggest a better way to determine if an object is a user instance? ############################## from types import InstanceType class X: __X__=True class V(X): pass def func0(ob): t=type(ob) if t is InstanceType: pass elif t in (float, int): pass else: pass def func1(ob): if isinstance(ob,X): pass elif type(ob) in (float, int): pass else: pass def func2(ob): if getattr(ob,'__X__',False): pass elif type(ob) in (float, int): pass else: pass def func3(ob): if hasattr(ob,'__X__'): pass elif type(ob) in (float, int): pass else: pass ############################## -- Robin Becker From dg.gmane at thesamovar.net Sat Jan 31 11:48:31 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 17:48:31 +0100 Subject: nth root In-Reply-To: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: Mark Dickinson wrote: > I'd also be a bit worried about accuracy. Is it important to you > that the > integer part of the result is *exactly* right, or is it okay if > (n**13)**(1./13) sometimes comes out as slightly less than n, or if > (n**13-1)**(1./13) sometimes comes out as n? I don't think accuracy is too big a problem here actually (at least for 13th roots). I just tested it with several hundred thousand random 100 digit numbers and it never made a mistake. The precision of double ought to easily guarantee a correct result. If you let x=int(1e100**(1./13)) then ((x+1)**13-x**13)/x**13=2.6e-7 so you only need around the first 8 or 9 digits of the 100 digit number to compute the 13th root exactly (well within the accuracy of a double). OTOH, suppose you were doing cube roots instead then you would need the first 35 digits of the 100 digit number and this is more accurate than a double. So for example int(1e100**(1./3)) is a long way from being the integer part of the true cube root (it's between 10**18 and 10**19 away). Dan From mensanator at aol.com Sat Jan 31 11:53:38 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 31 Jan 2009 08:53:38 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> Message-ID: On Jan 31, 8:05?am, Mark Dickinson wrote: > On Jan 31, 1:23?pm, Steve Holden wrote: > > > Much more significant points, given the limited precision of the doubles > > Python will be using. Could gmpy do this better, I wonder? > > Almost certainly, if exact results are wanted! ?At least, GMP has > an mpz_root function; I don't know offhand whether gmpy makes it > accessible from Python. > > Mark What am I doing wrong here? IDLE 2.6b1 >>> import timeit >>> from gmpy import root >>> root(4021503534212915433093809093996098953996019232,13) (mpz(3221), 0) >>> t1 = timeit.Timer("x = root(a,r)", "a = 4021503534212915433093809093996098953996019232; r = 13") >>> t1.timeit() Traceback (most recent call last): File "", line 1, in t1.timeit() File "C:\Python26\lib\timeit.py", line 193, in timeit timing = self.inner(it, self.timer) File "", line 6, in inner NameError: global name 'root' is not defined From cjw at ncf.ca Sat Jan 31 11:53:39 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 31 Jan 2009 11:53:39 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: andrew cooke wrote: > On Jan 31, 11:22 am, eliben wrote: >> code.google.com provides all of these in a free and convenient manner. >> Recommended. > > unfortunately google don't seem that reliable ;o) (have you tried a > google search today?) I had a search problem today (10:00), the first I can remember, in which the response from a Google pointer was: Warning - visiting this web site may harm your computer! Yes, this is not Python related but I think that it is likely of general interest. Now, at 12:00, I get the page I was seeking. Colin W. From apt.shansen at gmail.com Sat Jan 31 12:01:37 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:01:37 -0800 (PST) Subject: Empty string is False right? Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From ajaksu at gmail.com Sat Jan 31 12:02:22 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 31 Jan 2009 09:02:22 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 1:03?pm, andrew cooke wrote: > On Jan 31, 11:22?am, eliben wrote: > > > code.google.com provides all of these in a free and convenient manner. > > Recommended. > > unfortunately google don't seem that reliable ;o) ?(have you tried a > google search today?) You can mirror at LP, bitbucket, github, etc. From thmpsn.m.k at gmail.com Sat Jan 31 12:08:25 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 09:08:25 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> On Jan 30, 12:15?am, Chris Rebert wrote: > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here". How do you know? (I know I'm not.) Seriously, though, the lack of private members does allow for ugly hacks in user code, and you know there are always ugly hackers. > This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. If it ends up being necessary, the class's design is flawed. (Though in this case, the flaw is easily solved by simply providing a getter.) > The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. If you're talking about getters, then note that this doesn't let you modify the member (unless there's a corresponding setter). In the absence of private/protected, Python should at least provide something similar to C++'s 'const' or Java's 'final'. (Similar, not equivalent, because then the object itself wouldn't be able to manipulate its own members!) From notvalid2 at sbcglobal.net Sat Jan 31 12:14:33 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 09:14:33 -0800 Subject: Python Doc 2.6 vs 2.5--A Matter of Format? Message-ID: I see for 2.5 and for 2.6. I'm guessing these two pages differ somewhat in formats simply because someone decided to do so, and not that I'm in the wrong place for each of the two versions, correct? For example, somewhere down in the 2.5, I should find the 2.6 equivalent of ? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From mensanator at aol.com Sat Jan 31 12:18:53 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 31 Jan 2009 09:18:53 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> Message-ID: <4868276d-dd3f-4e8d-96f6-81e7aabd4d15@r15g2000prd.googlegroups.com> On Jan 31, 10:53?am, Mensanator wrote: > On Jan 31, 8:05?am, Mark Dickinson wrote: > > > On Jan 31, 1:23?pm, Steve Holden wrote: > > > > Much more significant points, given the limited precision of the doubles > > > Python will be using. Could gmpy do this better, I wonder? > > > Almost certainly, if exact results are wanted! ?At least, GMP has > > an mpz_root function; I don't know offhand whether gmpy makes it > > accessible from Python. > > > Mark > > What am I doing wrong here? > > IDLE 2.6b1 > > >>> import timeit > >>> from gmpy import root > >>> root(4021503534212915433093809093996098953996019232,13) > (mpz(3221), 0) > >>> t1 = timeit.Timer("x = root(a,r)", "a = 4021503534212915433093809093996098953996019232; r = 13") > >>> t1.timeit() > > Traceback (most recent call last): > ? File "", line 1, in > ? ? t1.timeit() > ? File "C:\Python26\lib\timeit.py", line 193, in timeit > ? ? timing = self.inner(it, self.timer) > ? File "", line 6, in inner > NameError: global name 'root' is not defined Never mind, I figured it out. >>> import gmpy >>> a=gmpy.mpz(4021503534212915433093809093996098953996019232) >>> r=13 >>> t1 = timeit.Timer("x = root(a,r)", "from gmpy import root; from __main__ import a,r") >>> t1.timeit() 4.7018698921850728 For comparison: >>> t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") >>> t2.timeit() 0.43993394115364026 From dickinsm at gmail.com Sat Jan 31 12:25:34 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 09:25:34 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> On Jan 31, 4:48?pm, Dan Goodman wrote: > I don't think accuracy is too big a problem here actually (at least for > 13th roots). I just tested it with several hundred thousand random 100 > digit numbers and it never made a mistake. Well, random numbers is one thing. But how about the following: >>> n = 12345**13 >>> n 154662214940914131102165197707101295849230845947265625L >>> int(n ** (1./13)) # should be 12345; okay 12345 >>> int((n-1) ** (1./13)) # should be 12344; oops! 12345 Mark From apt.shansen at gmail.com Sat Jan 31 12:29:49 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:29:49 -0800 (PST) Subject: is python Object oriented?? In-Reply-To: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From markobrien85 at gmail.com Sat Jan 31 12:31:52 2009 From: markobrien85 at gmail.com (markobrien85 at gmail.com) Date: Sat, 31 Jan 2009 09:31:52 -0800 (PST) Subject: persistent TCP connection in python using socketserver References: Message-ID: <80bc0bfa-f505-49f9-8d5a-f6574e6f8608@z28g2000prd.googlegroups.com> On Jan 30, 5:54?am, Jean-Paul Calderone wrote: > On Thu, 29 Jan 2009 08:38:43 -0800 (PST), markobrie... at gmail.com wrote: > >G'day > > >I'm currentlyusingsocketserverto build a simple XMLSocket (an XML > >based protocol used for communication between flash and the outside > >world) server. I've got flash establishing aconnection, sending a > >request and mypythonserver responding. However at this point > >socketserverterminates theconnection. Which is bad, since i need a > >persistentconnectionso i can push data from the server to the client > >without the overhead of polling. > > If you don't want theconnectionto close, then don't let the request > complete. ?SocketServerimplements logic for single request/response > perconnection. ?You can change this by making your requests take a > really long time (until you're done with theconnection) or you can > override the behavior which closes theconnectionafter a response. > > Or you could use the socket module, on which theSocketServermodule is > based. ?Or you could use Twisted, another higher-level package built on > the socket module (mostly). ?Actually, I recommend Twisted, since it will > mostly isolate you from boring low-level details and let you implement > whatever high-level behavior you're after (I know that a bunch of people > have used it to communicate with Flash, for example). > > Jean-Paul Cheers mate I had a look into twisted but was put off by the FAQ stating 1.0+ modules may or may not be stable, and only the 'core' is. I don't wanna be messing around with a potentially buggy server, so im gonna roll my own using the sockets module. Thanks for your help ! From apt.shansen at gmail.com Sat Jan 31 12:36:26 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:36:26 -0800 (PST) Subject: Python Doc 2.6 vs 2.5--A Matter of Format? In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From thmpsn.m.k at gmail.com Sat Jan 31 12:40:59 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 09:40:59 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> On Jan 30, 2:32?pm, Michael Torrie wrote: > Veerendra Ganiger wrote: > > Python is not purely object oriented programming, because we can write > > functions without any class. > > You are right, predefined class attributes are available when we write or > > execute a piece of python code without defining class, that means it's just > > using objects for it's purpose. It does not mean its purely object oriented. > > To be clear, python does not force you to lay out your code according to > some strict object-oriented paradigm. ?But Python itself is still purely > object-oriented, as is your script when parsed. > > This function without a class that you mentioned, is in fact an object > with attributes. ?You can pass a function around just like any other > object. ?Even calling a function is invoked like so: > > myfunc.__call__(params) > > So necessitating that code be inside a class has nothing to do with > object-oriented programming. ?Let's not forget that classes are > themselves objects (metaobjects in smalltalk parlance if I recall > correctly). > > Now python does not have any way besides lambda expressions of creating > unbound function objects, but in practice this doesn't matter as I can > rebind names freely. ?I can still do: > > a=myfunc > myfunc=some other expression or object > > > It all depends on implementation, I think even we can make "C" object > > oriented with proper implementation. > > Indeed, any code based on gobject libraries can be object-oriented in > design and function. But it's only a faking, and things such as inheritance and polymorphism are implemented clumsily (actually I'm not even sure about polymorphism). And of course, there are still no private members. From dg.gmane at thesamovar.net Sat Jan 31 12:43:08 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 18:43:08 +0100 Subject: nth root In-Reply-To: <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> Message-ID: Mark Dickinson wrote: > Well, random numbers is one thing. But how about the following: > >>>> n = 12345**13 >>>> n > 154662214940914131102165197707101295849230845947265625L >>>> int(n ** (1./13)) # should be 12345; okay > 12345 >>>> int((n-1) ** (1./13)) # should be 12344; oops! > 12345 Good point! Oops indeed. :-) Dan From Scott.Daniels at Acm.Org Sat Jan 31 12:44:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 31 Jan 2009 09:44:13 -0800 Subject: Why do operators and methods of built-in types differ In-Reply-To: References: Message-ID: Csaba Hoch wrote: > if I write the following: > >>> 1+1 > 2 > it seems to be exactly equivalent to this: > >>> (1).__add__(1) > 2 > However, if I write invalid code and try to add a list to an int, the > errors will be different: .... As has been explained, binary operators are trickier than the above seems to show. Here is how to get the full behavior: >>> import operator >>> operator.add(1,[]) Traceback (most recent call last): File "", line 1, in operator.add(1,[]) TypeError: unsupported operand type(s) for +: 'int' and 'list' --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jan 31 12:48:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 31 Jan 2009 09:48:24 -0800 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: Steve Holden wrote: > AJ Ostergaard wrote: >> I'm not suggesting it's not operating as advertised - I'm suggesting the >> 'advertising' is slightly sguiffy if you catch my drift. I guess it's >> just me that finds it slightly counter intuitive. Surely intuitively the >> expression is "and" and therefore should always return a boolean? ... > You might think so, and it wouldn't be an entirely unreasonable thought, > but in practice it makes a lot of sense to retain the original value > where possible. For example: print name_from_form or default_name or: main(sys.arg[1:] or ['default', 'args']) --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Sat Jan 31 12:49:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 31 Jan 2009 18:49:55 +0100 Subject: Python Doc 2.6 vs 2.5--A Matter of Format? In-Reply-To: References: Message-ID: <49848f43$0$27848$9b622d9e@news.freenet.de> > I see for 2.5 and > for 2.6. I'm guessing these two pages differ > somewhat in formats simply because someone decided to do so, and not > that I'm in the wrong place for each of the two versions, correct? Correct. The documentation format has significantly changed. > For > example, somewhere down in the 2.5, I should find the 2.6 equivalent of > ? Not necessarily. The change in format also means a change in indices; the formats differ in what indices precisely are created, and what precisely they contain. Try http://www.python.org/doc/2.5/lib/genindex.html Regards, Martin From Pat at junk.net Sat Jan 31 13:27:02 2009 From: Pat at junk.net (Pat) Date: Sat, 31 Jan 2009 13:27:02 -0500 Subject: len() References: Message-ID: Tobiah wrote: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. > > Thanks, > > Toby I'm surprised that no one responded to that question. I keep making that mistake all the time myself. From alejandro.weinstein at gmail.com Sat Jan 31 14:04:25 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Sat, 31 Jan 2009 11:04:25 -0800 (PST) Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: <31508b6d-bebb-45e6-b57c-525d370e22c0@r37g2000prr.googlegroups.com> On Jan 30, 1:40?pm, Christian Heimes wrote: > May I ask why you want to get the TID? htop shows the TID of each thread. Knowing the TID allows me to know which thread is hogging the CPU. If there is a better way to do this, or there is something fundamentally wrong with this approach, please let me know. Alejandro. From ajaksu at gmail.com Sat Jan 31 14:04:54 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 31 Jan 2009 11:04:54 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> Message-ID: <0d710b35-691f-4951-a020-2dc3b1971555@n10g2000yqm.googlegroups.com> On Jan 31, 12:03 pm, Mark Dickinson wrote: [...] > t1 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232; power = 1./13") > t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") And by using a float literal instead of "float (402150353421291543309...)", (BTW, here -^), it not only is faster but also a great way make some innocent bystander waste his eyesight trying to figure out the magic trick :D From digitig at gmail.com Sat Jan 31 14:07:34 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 31 Jan 2009 19:07:34 +0000 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: 2009/1/30 Scott David Daniels : > Be careful with your assertion that a regex is faster, it is certainly > not always true. I was careful *not* to assert that a regex would be faster, merely that it was *likely* to be in this case. -- Tim Rowe From aj at cubbyhole.net Sat Jan 31 14:11:46 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 19:11:46 +0000 Subject: Python-list Digest, Vol 64, Issue 697 In-Reply-To: References: Message-ID: > AJ Ostergaard wrote: >> I'm not suggesting it's not operating as advertised - I'm >> suggesting the >> 'advertising' is slightly sguiffy if you catch my drift. I guess it's >> just me that finds it slightly counter intuitive. Surely >> intuitively the >> expression is "and" and therefore should always return a boolean? >> > You might think so, and it wouldn't be an entirely unreasonable > thought, > but in practice it makes a lot of sense to retain the original value > where possible. > > The fact is that any left-hand operand that evaluates to false in a > Boolean context can be used as it stands rather than being converted > to > Boolean first. So the conversion is essentially useless processing. That's what I've figured out during the course of the day. Thanks for listening one and all! :) Regards, AJ From gotbyrd at gmail.com Sat Jan 31 14:12:16 2009 From: gotbyrd at gmail.com (gotbyrd) Date: Sat, 31 Jan 2009 11:12:16 -0800 (PST) Subject: Searching a file for multiple strings Message-ID: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> Hello, I'm fairly new with python and am trying to build a fairly simple search script. Ultimately, I'm wanting to search a directory of files for multiple user inputted keywords. I've already written a script that can search for a single string through multiple files, now I just need to adapt it to multiple strings. I found a bit of code that's a good start: import re test = open('something.txt', 'r').read() list = ['a', 'b', 'c'] foundit = re.compile('|'.join(re.escape(target) for target in list)) if foundit.findall(test): print 'yes!' The only trouble with this is it returns yes! if it finds any of the search items, and I only want a return when it finds all of them. Is there a bit of code that's similar that I can use? Thanks From geekmail at usenot.de Sat Jan 31 14:16:48 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 31 Jan 2009 20:16:48 +0100 Subject: len() References: Message-ID: <20090131201648.201b6ed5@usenot.de> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: > Tobiah wrote: > > Just out of curiosity, why was len() made to > > be it's own function? I often find myself > > typing things like my_list.len before I > > catch myself. > > > > Thanks, > > > > Toby > > I'm surprised that no one responded to that question. > Huh? Gabriel Genellina replied about 46 minutes after it was posted. Might it be that your newsserver is a bit laggy? regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From eric.pruitt at gmail.com Sat Jan 31 14:23:37 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Sat, 31 Jan 2009 13:23:37 -0600 Subject: Import Replacement Message-ID: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> Imagine there are two files horse.py and buffalo.py. horse.py is imported by another file rider.py. Is it possible to make it so that under certain circumstances possibly based on an environment variable or something similar that when rider.py imports horse.py, it actually imports buffalo.py sort of like a behind the scenes replacement so that rider.py needs little, preferably absolutely no modification? Right now, I am investigating the use of sys.modules and doing something using sys.modules['horse.py'] = 'buffalo.py'. -------------- next part -------------- An HTML attachment was scrubbed... URL: From geekmail at usenot.de Sat Jan 31 14:26:08 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 31 Jan 2009 20:26:08 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <20090131202608.04fac735@usenot.de> On Sat, 31 Jan 2009 09:11:03 +0100 Laszlo Nagy wrote: > Python is not a pure object oriented language, because it has other > programming tools, for example functions. I'm not sure about the first part of the sentence, but Python's functions are objects. Check it in the interpreter: attributes, methods, the whole caboodle. regards, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From eric.pruitt at gmail.com Sat Jan 31 14:27:53 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Sat, 31 Jan 2009 13:27:53 -0600 Subject: Import Replacement In-Reply-To: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> Message-ID: <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> Imagine there are two files horse.py and buffalo.py. horse.py is imported by another file rider.py. Is it possible to make it so that under certain circumstances possibly based on an environment variable or something similar that when rider.py imports horse.py, it actually imports buffalo.py sort of like a behind the scenes replacement so that rider.py needs little, preferably absolutely no modification? Right now, I am investigating the use of sys.modules and doing something using sys.modules['horse.py'] = 'buffalo.py'. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sat Jan 31 14:45:27 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 13:45:27 -0600 Subject: Searching a file for multiple strings In-Reply-To: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> Message-ID: <4984AA57.3050106@tim.thechases.com> > I'm fairly new with python and am trying to build a fairly simple > search script. Ultimately, I'm wanting to search a directory of files > for multiple user inputted keywords. I've already written a script > that can search for a single string through multiple files, now I just > need to adapt it to multiple strings. > > I found a bit of code that's a good start: > > import re > test = open('something.txt', 'r').read() > > list = ['a', 'b', 'c'] > > foundit = re.compile('|'.join(re.escape(target) for target in list)) > if foundit.findall(test): > print 'yes!' > > The only trouble with this is it returns yes! if it finds any of the > search items, and I only want a return when it finds all of them. Is > there a bit of code that's similar that I can use? [insert standard admonition about using "list" as a variable name, masking the built-in "list"] Unless there's a reason to use regular expressions, you could simply use test = open("something.txt").read() items = ['a', 'b', 'c'] if all(s in test for s in items): print "Yes!" else: print "Sorry, bub" This presumes python2.5 in which the "all()" function was added. Otherwise in pre-2.5, you could do for s in items: if s not in test: print "Sorry, bub" break else: print "Yeparoo" (note that the "else" goes with the "for", not the "if") -tkc From gnewsg at gmail.com Sat Jan 31 14:50:36 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 31 Jan 2009 11:50:36 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> On 31 Gen, 12:46, andrew cooke wrote: > Hi, > > I have a new project, that I just released in beta (http://www.acooke.org/lepl- a recursive decent parser with full > backtracking). ?At the moment I am using pypi and setuptools for > distribution (it's a pure python package) and I am happy with hosting > static web pages (the manual and api doc linked to above) on my own > site (I did try the packages.python.org web pages, but it seemed > pointless duplicating my own). > > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion > and am wondering which is the best (free) provider for these (the code > is LGPL open source). ?I'd prefer a mailing list to something like > google groups (although I guess it may be possible to configure a > gateway) and I could open up my personal subversion server, but that > seems like a lot of work (not really that interested in moving to > something other than svn). > > Any recommendations? > > Thanks, > Andrew Google Code. --- Giampaolo http://code.google.com/p/pyftpdlib From python.list at tim.thechases.com Sat Jan 31 15:00:27 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 14:00:27 -0600 Subject: Searching a file for multiple strings (PS) In-Reply-To: <4984AA57.3050106@tim.thechases.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> Message-ID: <4984ADDB.2070509@tim.thechases.com> >> I'm fairly new with python and am trying to build a fairly simple >> search script. Ultimately, I'm wanting to search a directory of files >> for multiple user inputted keywords. I've already written a script >> that can search for a single string through multiple files, now I just >> need to adapt it to multiple strings. One more item: if your files are large, it may be more efficient to scan through them incrementally rather than reading the whole file into memory, assuming your patterns aren't multi-line (and by your escaping example, I suspect they're just single-words): items = set(['a', 'b', 'c']) for fname in ['file1.txt', 'file2.txt']: still_to_find = items.copy() for line in file(fname): found = set() for item in still_to_find: if item in line: found.add(item) still_to_find.difference_update(found) if not still_to_find: break if still_to_find: print "%s: Nope" % fname else: print "%s: Yep" % fname just one more way to do it :) -tkc From dickinsm at gmail.com Sat Jan 31 15:03:08 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 12:03:08 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> <0d710b35-691f-4951-a020-2dc3b1971555@n10g2000yqm.googlegroups.com> Message-ID: On Jan 31, 7:04?pm, ajaksu wrote: > also a great way make some innocent bystander waste his eyesight > trying to figure out the magic trick :D Oh, come on! At least I put the two lines next to each other! :-) Mark From ianand0204 at gmail.com Sat Jan 31 15:11:16 2009 From: ianand0204 at gmail.com (flagg) Date: Sat, 31 Jan 2009 12:11:16 -0800 (PST) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> On Jan 30, 8:12?pm, rdmur... at bitdance.com wrote: > Quoth flagg : > > > I am working on a very basic xmlrpc server, which will expose certain > > functions for administering BIND zone files. ?The big problem I am > > having is parsing the incoming xmlrpc request. ?Basically part of the > > xmlrpc request will help deterime which zone file is edited. ? ?I have > > been looking at the do_POST() method from SimpleXMLRPCDispatcher and > > it seems like I could code something which overides that method, > > however I am new to programming am at a loss, i might even be making > > this tougher than it needs to be. ? Is there a way to parse the > > incoming xmlrpc request before the function it is calling is executed? > > Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead? > > It's been a while since I looked at XMLRPC, but why wouldn't you have > a operation names, with the zone file to operate on as an argument? > Then you'd just be defining your operations as methods on your > SimpleXMLRPCServer, and they'd use the argument to determine which file > to operate on. > > If that doesn't make sense, either I've forgotten how XMLRPC works, > or you should explain your requirements a bit more. > > --RDM Let me see if i can elaborate on the requirements. I have 20+ different zone files. I want the xmlrpc server to be able to determine what zone file to open by looking at the incoming xml request. For example one of the functions I have now is to show a DNS record (I am using dnspython for most of this work) If i send an xmlrpc request that uses the 'showRecord' function with params of 'oracle1.foo.bar.com' I want to parse the "params" piece and then instruct the xml-rpc server to open foo.bar.com.zone for reading. The reason why i was looking at do_Post() and _dispatch was to attempt to read the incoming params and do exactly that. Do you think there is an easier way of accomplishing this, than the way I am going about it? From andrey.demidov at gmail.com Sat Jan 31 15:22:30 2009 From: andrey.demidov at gmail.com (Andrey Demidov) Date: Sat, 31 Jan 2009 23:22:30 +0300 Subject: Where to host a (Python) project? In-Reply-To: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> (andrew cooke's message of "Sat, 31 Jan 2009 03:46:32 -0800 (PST)") References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <877i4bcjjt.fsf@demashost.home.com> I use Google Code. From gherron at islandtraining.com Sat Jan 31 15:22:54 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 31 Jan 2009 12:22:54 -0800 Subject: Import Replacement In-Reply-To: <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> Message-ID: <4984B31E.7000809@islandtraining.com> James Pruitt wrote: > Imagine there are two files horse.py and buffalo.py. horse.py is > imported by another file rider.py. Is it possible to make it so that > under certain circumstances possibly based on an environment variable > or something similar that when rider.py imports horse.py, it actually > imports buffalo.py sort of like a behind the scenes replacement so > that rider.py needs little, preferably absolutely no modification? > Right now, I am investigating the use of sys.modules and doing > something using sys.modules['horse.py'] = 'buffalo.py'. > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > If horse and buffalo have the same interface then try something like this: if ...: import horse as ridable else: import buffalo as ridable # Now use ridable as any module... If each defines a class of its own name, but the classes have identical interfaces, then try if ...: from horse import Horse as Ridable else: from buffalo import Buffalo as Ridable # Then instantiate animal = Ridable(...) Gary Herron From lists at cheimes.de Sat Jan 31 15:27:10 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jan 2009 21:27:10 +0100 Subject: is python Object oriented?? In-Reply-To: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: thmpsn.m.k at gmail.com schrieb: > But it's only a faking, and things such as inheritance and > polymorphism are implemented clumsily (actually I'm not even sure > about polymorphism). And of course, there are still no private > members. Do you honestly believe that C++'s private members are really private? Privateness is only enforced during parsing time. Nobody can stop you from messing around with header files or memory. You can still access and modify private members but it's all messy and ugly. Even C# and .NET don't stop you from doing nasty things from unmananged assemblies. Seriously, 'private' and 'protected' are merely tools to stop bad programmers from doing bad stuff. And the serve as documentation, too. Oh, by the way, the first C++ compilers just converted C++ code to C code. Such much about "You can't do OOP in C."! Christian From aolsuppo at gmail.com Sat Jan 31 15:36:28 2009 From: aolsuppo at gmail.com (aolsuppo at gmail.com) Date: Sat, 31 Jan 2009 12:36:28 -0800 (PST) Subject: help me python Message-ID: C:\Python26>vnc.py Traceback (most recent call last): File "C:\Python26\vnc.py", line 4, in import PyD3DES ImportError: DLL load failed: The specified module could not be found. From andrew at acooke.org Sat Jan 31 16:30:22 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 13:30:22 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: On Jan 31, 4:50?pm, "Giampaolo Rodola'" wrote: > Google Code. > > --- Giampaolohttp://code.google.com/p/pyftpdlib thanks - that's a nice example. i'm a bit concerned about the whole google corporation thing, but reading through the ideological check- sheet at savannah convinced me i wasn't worthy and your project looks good (i admit i haven't seen that many google projects, but they all seemed abandoned/bare/hostile). so i'll follow the majority here and give google code a go. cheers, andrew From torriem at gmail.com Sat Jan 31 17:01:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:01:57 -0700 Subject: is python Object oriented?? In-Reply-To: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: <4984CA55.4060509@gmail.com> thmpsn.m.k at gmail.com wrote >> This allows people to meddle with internals, at their own risk, >> if it ends up being absolutely necessary. > > If it ends up being necessary, the class's design is flawed. (Though > in this case, the flaw is easily solved by simply providing a getter.) No the class design is not necessarily flawed. Sometimes it is desirable to modify a class's behavior at a lower level. In Java this isn't possible directly and so it has led to an entire class of libraries that provide means of doing this. For more information, look up "Aspect-oriented Programming" on wikipedia. Since most aspect-oriented programming examples I've seen are in Java I never understood much about it ("cross-cutting concerns" is a pretty meaningless explanation) until I realized that metaprogramming in python, monkey-patching classes, and dynamically adding attributes to an existing class are all forms of aspect-oriented programming. And it turns out to be quite useful for some things. One area where aspect-oriented programming is useful is in libraries that add security layers to objects and methods. Rather than having to make code directly aware of the security layer (which could take different forms), we can instead reach into the classes and, for example, wrap certain methods in a function that enforces security. If we do it in the class directly, then even code that descends from this class will transparently "inherit" all of the newly added security layer code that was never there when the code was first written. By security layer I'm talking more about code that enforces certain user authentication before use (as in web programming) rather than "secure" code. From torriem at gmail.com Sat Jan 31 17:09:12 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:09:12 -0700 Subject: is python Object oriented?? In-Reply-To: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <4984CC08.50902@gmail.com> thmpsn.m.k at gmail.com wrote: >> To be clear, python does not force you to lay out your code according to >> some strict object-oriented paradigm. But Python itself is still purely >> object-oriented, as is your script when parsed. > > But it's only a faking, and things such as inheritance and > polymorphism are implemented clumsily (actually I'm not even sure > about polymorphism). And of course, there are still no private > members. How is it faking? The class of a function object is "function," which is of the metaclass "type." What more do you want? If Guido himself declared that functions are objects would you believe that? Or modules? Since a function object is an instance of the class "function" I don't see how you could inherit from it, and polymorphism has nothing to do with this either. Maybe what you are talking about is deriving a class from the class "function." Not sure if that's allowed, mainly because the language has defined a standard way of declaring a function (methods are functions too, of course), so creating a useful, derived function object would be difficult given how the syntax of the language works. Private members? I could stick add any attribute I wanted to a function object and ask that people treat it as private if I wanted to: def myfunc(): pass myfunc.__dict__['_private'] = 4 If you are insinuating that not forcing private attributes to be unaccessible by others (black box theory) is in somehow a violation of object-oriented semantics, think again. It's not. (There are no formal definitions of OO anyay, but wikipedia lists quite a few characteristics considered common to OO, and enforced private members is not one of them.) From torriem at gmail.com Sat Jan 31 17:16:52 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:16:52 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: <4984CDD4.60601@gmail.com> Steve Holden wrote: > You can think what you like, but there is a fundamental difference > between methods of a class and functions of a module. Until you > appreciate that you will likely make mistakes. Don't worry, though, we > all learn from our mistakes. And this fundamental difference is? >From what I can tell an instance method is an object that encapsulates the function object in a closure that makes sure it has a reference to "self." I know that you dynamically add functions to objects creating methods dynamically, by using new.instancemethod or something. This seems to indicate to me that there are functions and there are functions. Methods are in fact functions, just with a callable wrapper around them. Is this not so? From rdmurray at bitdance.com Sat Jan 31 17:25:31 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 22:25:31 +0000 (UTC) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> Message-ID: Quoth flagg : > Let me see if i can elaborate on the requirements. I have 20+ > different zone files. I want the xmlrpc server to be able to > determine what zone file to open by looking at the incoming xml > request. For example one of the functions I have now is to show a DNS > record (I am using dnspython for most of this work) > > If i send an xmlrpc request that uses the 'showRecord' function with > params of 'oracle1.foo.bar.com' I want to parse the "params" piece > and then instruct the xml-rpc server to open foo.bar.com.zone for > reading. The reason why i was looking at do_Post() and _dispatch was > to attempt to read the incoming params and do exactly that. > > Do you think there is an easier way of accomplishing this, than the > way I am going about it? Yeah. Take a look at the SimpleXLMRPC documentation: http://docs.python.org/library/simplexmlrpcserver.html In addition to setting up the server as instructed (let's assume you assign it to the variable 'server'), you just need to do something like: class MyFunctions: def showRecord(self, dnsname): domain = '.'.join(dnsname.split('.')[1:]) with open(domain+'.zone')) as myfile: # do stuff with data from myfile server.register_instance(MyFunctions()) You would modify the body of that function to meet your processing requirements, of course. That is, SimpleXMLRPCServer does the request parsing for you, calls the correspondingly named method, and passes it the params as method arguments. (This example is taken from the SimpleXMLRPC documentation, I just selected one particular way of exposing the methods: via a class instance). --RDM From steve at holdenweb.com Sat Jan 31 17:29:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 17:29:03 -0500 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: W. eWatson wrote: > Steve Holden wrote: >> W. eWatson wrote: >>> r wrote: >>>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>>> Where in the world is a description of pack() for Tkinter widgets? >>>>> Is it >>>>> some sort of general method for all widgets? I'm looking in a few >>>>> docs that >>>>> use it without ever saying where it is described. For one, >>>>> . In the NM Tech pdf on >>>>> Tkinter, >>>>> it's not found anywhere. I see Universal methods for widgets, but no >>>>> mention >>>>> of pack(). package, packed, but no pack. >>>> did you try here :) >>>> http://effbot.org/tkinterbook/pack.htm >>> Thanks. I have the site bookmarked, but it's hard to search. I posted a >>> comment to them that they should have it in pdf form. >>> >> http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack >> >> regards >> Steve > Well, that's an interesting "link". Another side of Google facilities? > Maybe you're using Snagit or its brethern? However, I'm interested in > searching a pdf, which, of course, doesn't yet exist. > OK, someone asked if you'd seen the HTML pages. You replied that you had them bookmarked but they were difficult to search. So I simply demonstrated that a search of the site for "pack" gave the right page as its first result. Maybe you *do* want a PDF, but it will be less searchable than the existing HTML, so I am somewhat confused about why. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jsmith5616 at yahoo.com Sat Jan 31 18:10:45 2009 From: jsmith5616 at yahoo.com (John Smith) Date: Sat, 31 Jan 2009 15:10:45 -0800 (PST) Subject: Auto Logon to site and get page Message-ID: <456128.62923.qm@web112207.mail.gq1.yahoo.com> I'm trying to automatically log into a site and store the resulting html using python. The site uses a form and encrypts the password with some kind of md5 hash. This is the important parts of the form: This is the function called in md5.js: function doStudentLogin(form) { var pw = form.pw.value; var pw2 = pw; // Save a copy of the password preserving case pw = pw.toLowerCase(); form.pw.value = hex_hmac_md5(pskey, pw); if (form.ldappassword!=null) { // LDAP is enabled, so send the clear-text password // Customers should have SSL enabled if they are using LDAP form.ldappassword.value = pw2; // Send the unmangled password } return true; } ? I am not sure what the ldappassword is or does. Can some one explain that? ? Here's my code : ? from urllib import urlopen, urlencode import re import hmac ? account = 'account' psw = 'my password'' url = "http://ps.pvcsd.org/guardian/home.html" ? homepagetxt = urlopen("http://ps.pvcsd.org").read() ? # get key and pstoken from login page m = re.search(' From thmpsn.m.k at gmail.com Sat Jan 31 18:28:14 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 15:28:14 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: On Jan 31, 2:27?pm, Christian Heimes wrote: > thmpsn.... at gmail.com schrieb: > > > But it's only a faking, and things such as inheritance and > > polymorphism are implemented clumsily (actually I'm not even sure > > about polymorphism). And of course, there are still no private > > members. > > Do you honestly believe that C++'s private members are really private? > Privateness is only enforced during parsing time. Nobody can stop you > from messing around with header files or memory. You can still access > and modify private members but it's all messy and ugly. Even C# and .NET > don't stop you from doing nasty things from unmananged assemblies. I don't know how you would do it in C# (or Java for that matter). In C++ you can play with pointers to "get at" some memory location somewhere in the object. The only portable way to know the exact location between the beginning of the object and the desired member is the offsetof() macro, but as I understand it this only works for POD types, which means that it won't work for classes such as: class NonPOD { private: int a; int b; public: NonPOD(); ~NonPOD(); int C(); }; (I haven't ever actually tried it, so I'm not sure.) Nevertheless, you can play and hope for the best. For example, if the member you want to get at is 'b', then you can do: NonPOD obj; std::cout << "obj.b = " << *(int*) ((unsigned char*) &obj + sizeof (int)) << std::endl; and hope that the compiler didn't leave a hole between the 'a' member and the 'b' member. Getting at the 'a' member would be easier because the first member of a struct/class always has the same memory location as the object itself (although again I'm not sure if this is true for non-POD types as well). So: Sometimes it may work, usually it will be unsafe and/or non- portable, and in most cases the procedure will look complicated. It certainly isn't something I'd try in a real application. However, it WOULD be tempting to access the member if the language allows me to just write: print "obj.b =", obj.b and be done with it. Personally, in Python, I use double underscores for "private" members, so the above would look like: print "obj.b =", obj._NonPOD__b but it's still easier than the C++ example. > Seriously, 'private' and 'protected' are merely tools to stop bad > programmers from doing bad stuff. And the serve as documentation, too. It's not just documentation. For example, suppose you're reading a class definition and see the declaration of a veryInterestingMember and forget that you're not supposed to access it. If you try to access it, the compiler will give you a diagnostic message at compile time. So you can think of it as an error-checking tool as well. > Oh, by the way, the first C++ compilers just converted C++ code to C > code. Such much about "You can't do OOP in C."! More interestingly, though, most compilers translate C and C++ code to assembler first. Does that mean that you can do object-oriented programming, generic programming, and procedural programming in assembler? (Answer: No, but you can probably -- very clumsily -- fake them.) From apt.shansen at gmail.com Sat Jan 31 18:30:48 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 15:30:48 -0800 (PST) Subject: persistent TCP connection in python using socketserver In-Reply-To: <80bc0bfa-f505-49f9-8d5a-f6574e6f8608@z28g2000prd.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From robert.kern at gmail.com Sat Jan 31 18:33:34 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 17:33:34 -0600 Subject: nth root In-Reply-To: <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> References: <4983C616.3000207@mrabarnett.plus.com> <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: On 2009-01-30 22:00, Tim Roberts wrote: > Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) > > What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? No, but Google would help. -- 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 timr at probo.com Sat Jan 31 19:09:12 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 01 Feb 2009 00:09:12 GMT Subject: nth root References: Message-ID: "Tim Roberts" wrote: > >Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 >is 3221.2904208350265.... >there must be a quicker way of finding out its between 3221 and 3222.... > >....but perhaps not. Also, remember that the number you computed there is not really the 13th root of 4021503534212915433093809093996098953996019232. When you convert it to float to do the exponentiation, you're losing everything after the 15th significant digit. Of course, if all you're looking for is the nearest integer, that's not very relevant. Do you really need the absolute number? You could take log(x)/13 and work with the log of the results. I suspect (without trying it) that's faster than the exponentiation. >From one Tim Roberts to another. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From andrew at acooke.org Sat Jan 31 19:09:28 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 16:09:28 -0800 (PST) Subject: help me python References: Message-ID: On Jan 31, 5:36?pm, aolsu... at gmail.com wrote: > C:\Python26>vnc.py > Traceback (most recent call last): > ? File "C:\Python26\vnc.py", line 4, in > ? ? import PyD3DES > ImportError: DLL load failed: The specified module could not be found. i'm surprised no-one has replied here. what is happening is that the vnc module is trying to load a library it needs, called PyD3DES (this is a compiled library, a ".dll", not python source). a little googling shows that this is part of the vnc package. so either the vnc package is not installed correctly, or you have a problem with paths. since you are using windows i can't help you in any more detail than that - hope it helps. andrew From rt8396 at gmail.com Sat Jan 31 19:19:13 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 16:19:13 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> Message-ID: <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> On Jan 30, 4:36?pm, Steve Holden wrote: [snip] > It's mostly a matter of teaching by example. I'd like to think I usually > set a good example, but I've certainly been known to get crabby from time > to time Steve you are defiantly the better of two evils around here :D From pxrepreza at gmail.com Sat Jan 31 19:19:49 2009 From: pxrepreza at gmail.com (Paulo Repreza) Date: Sat, 31 Jan 2009 16:19:49 -0800 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' Message-ID: Hi, I'm just learning the very basics of python and I ran into this problem in version 3.0/3000: >>>x = input("x: ") x: 36 >>> y = input("y: ") y: 42 >>> print (x*y) Traceback (most recent call last): File "", line 1, in print (x*y) TypeError: can't multiply sequence by non-int of type 'str' But when I run the same code with Python 2.6.1 it does prints the result. Is there any special function that I should add in order to work properly under Python 3.0? Thanks, Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sat Jan 31 19:25:27 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 18:25:27 -0600 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' In-Reply-To: References: Message-ID: On 2009-01-31 18:19, Paulo Repreza wrote: > Hi, > I'm just learning the very basics of python and I ran into this problem > in version 3.0/3000: > >>>x = input("x: ") > x: 36 > >>> y = input("y: ") > y: 42 > >>> print (x*y) > Traceback (most recent call last): > File "", line 1, in > print (x*y) > TypeError: can't multiply sequence by non-int of type 'str' > But when I run the same code with Python 2.6.1 it does prints the result. In Python 3.0, the 2.x input() function, which evaluates the string, was removed, and the 2.x raw_input() function, which just returns the string that was entered, was renamed to input(). > Is there any special function that I should add in order to work > properly under Python 3.0? x = int(input('x: ')) y = int(input('y: ')) -- 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 pxrepreza at gmail.com Sat Jan 31 19:42:42 2009 From: pxrepreza at gmail.com (Paulo Repreza) Date: Sat, 31 Jan 2009 16:42:42 -0800 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' In-Reply-To: References: Message-ID: Hi, Thanks for your reply. It worked. Paulo Repreza On Sat, Jan 31, 2009 at 4:25 PM, Robert Kern wrote: > On 2009-01-31 18:19, Paulo Repreza wrote: > >> Hi, >> I'm just learning the very basics of python and I ran into this problem >> in version 3.0/3000: >> >>>x = input("x: ") >> x: 36 >> >>> y = input("y: ") >> y: 42 >> >>> print (x*y) >> Traceback (most recent call last): >> File "", line 1, in >> print (x*y) >> TypeError: can't multiply sequence by non-int of type 'str' >> But when I run the same code with Python 2.6.1 it does prints the result. >> > > In Python 3.0, the 2.x input() function, which evaluates the string, was > removed, and the 2.x raw_input() function, which just returns the string > that was entered, was renamed to input(). > > Is there any special function that I should add in order to work >> properly under Python 3.0? >> > > x = int(input('x: ')) > y = int(input('y: ')) > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sat Jan 31 19:44:44 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 16:44:44 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> <9f5a0a78-2f5d-4b6c-8f17-8cf5825f500e@w39g2000prb.googlegroups.com> Message-ID: <3ea2fd5b-c3fa-4173-859f-8f95e3564c1b@d32g2000yqe.googlegroups.com> Sorry i gave you the wrong module, try PMIDI for python 2.5 (win32.exe): http://sourceforge.net/project/showfiles.php?group_id=65529&package_id=106729 Also try this page near the bottom under "MIDI Mania" for more http://wiki.python.org/moin/PythonInMusic From greg.ewing at canterbury.ac.nz Sat Jan 31 19:50:57 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 01 Feb 2009 13:50:57 +1300 Subject: Pyggy Awards Judging Underway Message-ID: <6uk9rcFfrh6cU1@mid.individual.net> Judging for the Feb'09 Pyggy Awards has started. All registered users of the PyWeek web site are eligible to rate entries, so even if you haven't submitted an entry, you can still be a judge if you want. And if you're not a PyWeek user, it's not too late to sign up. The entries are here: http://pyggy.pyweek.org/1007/entries/ -- Greg From catphive at catphive.net Sat Jan 31 20:00:05 2009 From: catphive at catphive.net (Brendan Miller) Date: Sat, 31 Jan 2009 17:00:05 -0800 Subject: install modules for specific python version Message-ID: <4984F415.6090902@catphive.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have several version of python running side by side on my ubuntu install (2.5,2.6,3.0). I'm installing a module with a setup.py script, in this case logilab-common, so that I can get pylint going. However, I need to install into python 2.6, but by default it picks out 2.5 and throws things in the site packages for that version. Is there a standard way to specify what version of python you want to install into? I originally installed my other python versions with the altinstall method. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmE9BIACgkQ4eGWG/zYzOmmdgCfbjr3p3wQ8A0TpjeFaPJtmHkx ktQAoI7wONrj5gT4BDclePpwY5kiCy8p =Pg9L -----END PGP SIGNATURE----- From sjmachin at lexicon.net Sat Jan 31 20:24:56 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:24:56 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> Message-ID: <653b8930-6b6c-49ec-bfca-334a30ea48ea@i24g2000prf.googlegroups.com> On Feb 1, 11:19?am, r wrote: > Steve you are defiantly the better of two evils around here :D A most munificent malapropism! Sherman's goat must be serene with entropy!! From sjmachin at lexicon.net Sat Jan 31 20:37:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:37:24 -0800 (PST) Subject: install modules for specific python version References: Message-ID: <3008aa01-5a8e-4edf-98e5-0d062c364a93@l33g2000pri.googlegroups.com> On Feb 1, 12:00?pm, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > I have several version of python running side by side on my ubuntu > install (2.5,2.6,3.0). > > I'm installing a module with a setup.py script, in this case > logilab-common, so that I can get pylint going. However, I need to > install into python 2.6, but by default it picks out 2.5 and throws > things in the site packages for that version. > > Is there a standard way to specify what version of python you want to > install into? Quite generally, if you want to install a module into Python X.Y, use Python X.Y to run the setup.py script. E.g. on Windows I'd do directory-containing-setup.py> c:\python26\python setup.py install Just do the equivalent on ubuntu. Cheers, John From robert.kern at gmail.com Sat Jan 31 20:37:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 19:37:51 -0600 Subject: install modules for specific python version In-Reply-To: <4984F415.6090902@catphive.net> References: <4984F415.6090902@catphive.net> Message-ID: On 2009-01-31 19:00, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I have several version of python running side by side on my ubuntu > install (2.5,2.6,3.0). > > I'm installing a module with a setup.py script, in this case > logilab-common, so that I can get pylint going. However, I need to > install into python 2.6, but by default it picks out 2.5 and throws > things in the site packages for that version. > > Is there a standard way to specify what version of python you want to > install into? I originally installed my other python versions with the > altinstall method. Whichever python executable that you used to run the setup.py is the version that the package gets installed to. Most likely, you will want to do something like this: $ python2.6 setup.py install -- 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 sjmachin at lexicon.net Sat Jan 31 20:52:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:52:17 -0800 (PST) Subject: help me python References: Message-ID: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> On Feb 1, 11:09?am, andrew cooke wrote: > On Jan 31, 5:36?pm, aolsu... at gmail.com wrote: > > > C:\Python26>vnc.py > > Traceback (most recent call last): > > ? File "C:\Python26\vnc.py", line 4, in > > ? ? import PyD3DES > > ImportError: DLL load failed: The specified module could not be found. > > i'm surprised no-one has replied here. ?what is happening is that the > vnc module is trying to load a library it needs, called PyD3DES (this > is a compiled library, a ".dll", not python source). ?a little > googling shows that this is part of the vnc package. > > so either the vnc package is not installed correctly, or you have a > problem with paths. File "C:\Python26\vnc.py" doesn't look like correct installation to me. My Googling found vnc.py here: http://www.darkc0de.com/others/vnc.py This appears to be a hack/crack site ... should we be helping the OP with this? From gagsl-py2 at yahoo.com.ar Sat Jan 31 20:53:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 23:53:37 -0200 Subject: Import Replacement References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> <4984B31E.7000809@islandtraining.com> Message-ID: En Sat, 31 Jan 2009 18:22:54 -0200, Gary Herron escribi?: > James Pruitt wrote: >> Imagine there are two files horse.py and buffalo.py. horse.py is >> imported by another file rider.py. Is it possible to make it so that >> under certain circumstances possibly based on an environment variable >> or something similar that when rider.py imports horse.py, it actually >> imports buffalo.py sort of like a behind the scenes replacement so >> that rider.py needs little, preferably absolutely no modification? > > If horse and buffalo have the same interface then try something like > this: > > if ...: > import horse as ridable > else: > import buffalo as ridable > # Now use ridable as any module... > > If each defines a class of its own name, but the classes have identical > interfaces, then try > > if ...: > from horse import Horse as Ridable > else: > from buffalo import Buffalo as Ridable > # Then instantiate > animal = Ridable(...) Another alternative, that does not involve changing rider.py, would be to rename horse.py -> _horse.py, buffalo.py -> _buffalo.py and write a *new* horse.py: if ...: from _horse import * else: from _buffalo import * Then, rider.py (and all other modules) still says "import horse", but it will get one or another depending on the condition. -- Gabriel Genellina From jnoller at gmail.com Sat Jan 31 20:54:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Sat, 31 Jan 2009 20:54:39 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: <4222a8490901311754q301900aer4fdf1fb6ab800432@mail.gmail.com> On Sat, Jan 31, 2009 at 4:30 PM, andrew cooke wrote: > On Jan 31, 4:50 pm, "Giampaolo Rodola'" wrote: >> Google Code. >> >> --- Giampaolohttp://code.google.com/p/pyftpdlib > > thanks - that's a nice example. i'm a bit concerned about the whole > google corporation thing, but reading through the ideological check- > sheet at savannah convinced me i wasn't worthy and your project looks > good (i admit i haven't seen that many google projects, but they all > seemed abandoned/bare/hostile). so i'll follow the majority here and > give google code a go. > > cheers, > andrew > -- > http://mail.python.org/mailman/listinfo/python-list > Bitbucket: http://bitbucket.org/ (I use this, move from google code) Github: http://github.com/ Launchapd: https://launchpad.net/ FreeHG: http://freehg.org/ Google is nice due to the groups/mailing list options, but I find I don't miss mailing lists all that much after being subscribed to so many. -jesse From starsareblueandfaraway at gmail.com Sat Jan 31 20:57:36 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Sat, 31 Jan 2009 20:57:36 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: <6a5569ec0901311757ge3783b9i4b2738b606fa624b@mail.gmail.com> I really like WebFaction for web-based Python projects. It's a paid web-hosting service, though. What I like is how they always have the most up-to-date Python packages and frameworks using one-click installers. On Sat, Jan 31, 2009 at 4:30 PM, andrew cooke wrote: > On Jan 31, 4:50 pm, "Giampaolo Rodola'" wrote: >> Google Code. >> >> --- Giampaolohttp://code.google.com/p/pyftpdlib > > thanks - that's a nice example. i'm a bit concerned about the whole > google corporation thing, but reading through the ideological check- > sheet at savannah convinced me i wasn't worthy and your project looks > good (i admit i haven't seen that many google projects, but they all > seemed abandoned/bare/hostile). so i'll follow the majority here and > give google code a go. > > cheers, > andrew > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Sat Jan 31 21:00:50 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 18:00:50 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> <653b8930-6b6c-49ec-bfca-334a30ea48ea@i24g2000prf.googlegroups.com> Message-ID: <050f006c-4408-4b84-9141-10fec02f9f3b@e10g2000vbe.googlegroups.com> On Jan 31, 7:24?pm, John Machin wrote: > A most munificent malapropism! Sherman's goat must be serene with > entropy!! Who say's George Bush did't have anything to offer :). He was the decider after all. From robert.kern at gmail.com Sat Jan 31 21:01:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 20:01:29 -0600 Subject: help me python In-Reply-To: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> References: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> Message-ID: On 2009-01-31 19:52, John Machin wrote: > On Feb 1, 11:09 am, andrew cooke wrote: >> On Jan 31, 5:36 pm, aolsu... at gmail.com wrote: >> >>> C:\Python26>vnc.py >>> Traceback (most recent call last): >>> File "C:\Python26\vnc.py", line 4, in >>> import PyD3DES >>> ImportError: DLL load failed: The specified module could not be found. >> i'm surprised no-one has replied here. what is happening is that the >> vnc module is trying to load a library it needs, called PyD3DES (this >> is a compiled library, a ".dll", not python source). a little >> googling shows that this is part of the vnc package. >> >> so either the vnc package is not installed correctly, or you have a >> problem with paths. > > File "C:\Python26\vnc.py" doesn't look like correct installation to > me. > > My Googling found vnc.py here: > http://www.darkc0de.com/others/vnc.py > > This appears to be a hack/crack site ... should we be helping the OP > with this? It's actually just part of PyVNC, a perfectly legitimate VNC client: http://bdash.net.nz/svn/projects/PyVNC/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From torriem at gmail.com Sat Jan 31 21:10:40 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 19:10:40 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <498504A0.1080107@gmail.com> thmpsn.m.k at gmail.com wrote: > More interestingly, though, most compilers translate C and C++ code to > assembler first. Does that mean that you can do object-oriented > programming, generic programming, and procedural programming in > assembler? > > Answer: No, but you can probably -- very clumsily -- fake them.) This is getting quite far off the topic, but of course you can, and it's not faking anything. This should be obvious. You can certainly do OO programming in C, which is a glorified assembler. For example, the gobject system defines a complete object-oriented system with classes, inheritance, polymorphism, encapuslation. It uses structures for encapsulating the data and call tables for virtual methods (to use a c++ parlance). It's such a well defined object model that you can, with gtkmm, even extend a c-based gobject class with C++! Of course you can also extend gobject-based C classes with python as well using PyBank to import them. Back when assembly was still somewhat in vogue I read a book on programming assembly in an object-oriented manner. So of course you can. Yes it can be clumsy without syntactic sugar. If you set up call tables, you can handle polymorphism. How would this be faking it? By your definition C++ is faking it since C++ compiles to assembly. In the early days, C++ was first implemented as a preprocessor that emitted straight C code. And I guess python fakes it since the python interpreter is implemented in C compiled to ASM. Maybe the terminology would be less confusing if we considered the terms, object-oriented programming, object-oriented languages, object-oriented systems. Any language can be used for the first. Python, Java, C++ can be defined by the second, and things like Python (the runtime environment), .NET, JVM, Parrot, can be defined by the last term. Fair enough? Python is certainly an object-oriented language, and implements a complete object-oriented system. Python can support coding in an object-oriented methodology, or you can code traditionally while still taking advantage of the complete OO system. From v+python at g.nevcal.com Sat Jan 31 21:18:08 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Sat, 31 Jan 2009 18:18:08 -0800 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009 In-Reply-To: <497FB2A8.5050105@simplistix.co.uk> References: <497FB2A8.5050105@simplistix.co.uk> Message-ID: <49850660.3070708@g.nevcal.com> On approximately 1/27/2009 5:19 PM, came the following characters from the keyboard of Chris Withers: > Hi All, > > Too many people in the Python community think the only way to work with > Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's PyCon in > Chicago on Wednesday, 25th March that will cover working with Excel > files in Python using the pure-python libraries xlrd, xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > Including formatting, unicode dates and formulae. > > - Writing Excel Files > > Including formatting with easyxf and things like freeze pains, print > areas, etc > > - Filtering Excel Files > > A run through on the structure of xlutils.filter and some examples to > show you how it works. > > - Workshop for your problems > > I'm hoping anyone who attends will get a lot out of this! If you're > planning on attending and have a particular problem you'd like to work > on in this part of the tutorial, please drop me an email and I'll try > and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at PyCon this year: > > http://us.pycon.org > > I look forward to seeing you all there! Good luck with the tutorial. I can't use xlrd because it doesn't support comments. So I use Open Office basic macros to transform the data into a usable form. At least it is way faster than COM, and (although I'm using Windows) I think it could be done on Linux. -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From excord80 at gmail.com Sat Jan 31 22:47:50 2009 From: excord80 at gmail.com (excord80) Date: Sat, 31 Jan 2009 19:47:50 -0800 (PST) Subject: importlib: what is it, and why is it important? Message-ID: <049bd243-053b-43c6-a368-7be7cae37d0b@p29g2000vbn.googlegroups.com> Regarding this blog post: http://sayspy.blogspot.com/2009/01/importlib-is-now-in-python-31.html When I use the ``import foo`` statement at the top of my program, I get a module imported. python has a search path it follows, finds the module, and makes it available to my program. Works nice. :) So, could someone explain what importlib exactly is, and why this new version that will be in Python 3.1 is significant? Will the import statement work differently in 3.1, and if so, in what way? From benjamin at python.org Sat Jan 31 23:08:24 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 1 Feb 2009 04:08:24 +0000 (UTC) Subject: importlib: what is it, and why is it important? References: <049bd243-053b-43c6-a368-7be7cae37d0b@p29g2000vbn.googlegroups.com> Message-ID: excord80 gmail.com> writes: > > Regarding this blog post: http://sayspy.blogspot.com/2009/01/importlib-is-now-in-python-31.html Brett has made many other blog posts about his work on importlib. You might try examining those. > > So, could someone explain what importlib exactly is, and why this new > version that will be in Python 3.1 is significant? Will the import > statement work differently in 3.1, and if so, in what way? Basically importlib is all of the complicated logic in the import statment written in Python. The point is to make importing more extensible and easier to change. The behavior of the import statement shouldn't be any different or that is a bug. From db3l.net at gmail.com Sat Jan 31 23:33:49 2009 From: db3l.net at gmail.com (David Bolen) Date: Sat, 31 Jan 2009 23:33:49 -0500 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: thmpsn.m.k at gmail.com writes: > I don't know how you would do it in C# (or Java for that matter). > > In C++ you can play with pointers to "get at" some memory location > somewhere in the object. The only portable way to know the exact > location between the beginning of the object and the desired member is > the offsetof() macro, but as I understand it this only works for POD > types, which means that it won't work for classes such as: > > class NonPOD > { > private: > int a; > int b; > public: > NonPOD(); > ~NonPOD(); > int C(); > }; > > (I haven't ever actually tried it, so I'm not sure.) > > Nevertheless, you can play and hope for the best. For example, if the > member you want to get at is 'b', then you can do: > > NonPOD obj; > std::cout << "obj.b = " << *(int*) ((unsigned char*) &obj + sizeof > (int)) << std::endl; > > and hope that the compiler didn't leave a hole between the 'a' member > and the 'b' member. Probably moving off topic, but I don't think you have to get anywhere near that extreme in terms of pointers, unless you're trying to deal with instances for which you have no source but only opaque pointers. I haven't gotten stuck having to do this myself yet, but I believe one commmon "hack" for the sort of class you show above is to just "#define private public" before including the header file containing the class definition. No fiddling with pointers, offsets, or whatever, just normal object access syntax past that point. Of course, I believe such a redefinition violates the letter of the C++ standard, but most preprocessors do it anyway. Also, it won't handle the case where the "private:" is not used, but the members are just declared prior to any other definition, since a class is private by default. But even then, if you had to, just make a copy of the class definition (or heck, just define a structure if it's just data elements), ensure the private portions are public, and then cast a pointer to the old class instance to one of your new class instance. Assuming you're building everything in a single compiler, the layouts should match just fine. Again, normal object member access, no casting or pointers needed (beyond the initial overall object pointer cast). -- David From Shawn at Milochik.com Sat Jan 31 23:39:15 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Sat, 31 Jan 2009 23:39:15 -0500 Subject: Searching a file for multiple strings (PS) In-Reply-To: <4984ADDB.2070509@tim.thechases.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> Message-ID: <2dc0c81b0901312039s46d8541did0f2b846b14a7313@mail.gmail.com> On Sat, Jan 31, 2009 at 3:00 PM, Tim Chase wrote: >>> I'm fairly new with python and am trying to build a fairly simple >>> search script. Ultimately, I'm wanting to search a directory of files >>> for multiple user inputted keywords. I've already written a script >>> that can search for a single string through multiple files, now I just >>> need to adapt it to multiple strings. > Not to discourage the use of Python, but it seems that fgrep with the -f flag already does exactly what you want. If you're on Windows, you can get the Windows version of fgrep here: http://unxutils.sourceforge.net/ Shawn From sln at netherlands.com Thu Jan 1 00:23:52 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Thu, 01 Jan 2009 05:23:52 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: >Xah Lee wrote: >> Just spent 3 hours looking into Ruby today. Here's my short impression >> for those interested. >> >> * Why Not Ruby? >> http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html >> >> plain text version follows: >> -------------------------------------- >> >> Why Not Ruby? >> >> Xah Lee, 2008-12-31 >> >> Spent about 3 hours looking into Ruby language today. >> >> The articles i read in detail are: >> >> * Wikipedia: Ruby (programming language)?J. Gives general overview. >> >> * Brief tutorial: "Ruby in Twenty Minutes" >> http://www.ruby-lang.org/en/documentation/quickstart/ >> >> * Personal blog by Stevey Yegge, published in 2004-10. >> http://steve.yegge.googlepages.com/ruby-tour >> >> The Wikipedia gives the best intro and overview in proper context. The >> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete >> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't >> teach much and rambles, but provide a little personal view. I read it >> because his opinions i respect. >> >> Q: Will you learn Ruby? >> >> No. For practical application, the lang is some 100 times less useful >> than each of Perl, Python, PHP, Javascript. For academic study, >> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far >> more interesting and powerful in almost all aspects. Further, there's >> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or >> power, these modern lang of the past 5 years matches or exceed Ruby. >> >> Q: Do you think Ruby lang is elegant? >> >> Yes. In my opinion, better than Perl, Python, PHP. As a high level >> lang, it's far better than Java, C, C++ type of shit. However, i don't >> think it is any better than emacs lisp, Scheme lisp, javascript, >> Mathematica. Note that Ruby doesn't have a spec, and nor a formal >> spec. Javascript has. Ruby's syntax isn't that regular, nor is it >> based on a system. Mathemtica's is. Ruby's power is probably less than >> Scheme, and probably same as Javascript. >> >> I also didn't like the fact that ruby uses keyword "end" to indicate >> code block much as Pascal and Visual Basic, Logo, do. I don't like >> that. >> >> Q: Won't Ruby be a interesting learning experience? >> >> No. As far as semantics goes, Ruby is basically identical to Perl, >> Python, PHP. I am a expert in Perl and PHP, and have working knowledge >> of Python. I already regretted having spent significant amount of time >> (roughly over a year) on Python. In retrospect, i didn't consider the >> time invested in Python worthwhile. (as it turns out, i don't like >> Python and Guido cult, as the lang is going the ways of OOP mumbo- >> jumbo with its Python 3 "brand new" future.) There is absolutely >> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp, >> Scheme lisp. >> >> Q: Do you recommend new programers to learn Ruby then? >> >> Not particularly. As i mentioned, if you are interested in practical >> utility, there's already Perl, PHP, Python, Javascript, which are all >> heavily used in the computing industry. If you are interested as a >> academic exercise, there's Scheme lisp, and much of functional langs >> such as OCaml, Haskell, Mathematica, which will teach you a whole lot >> more about computer science, features of language semantics, etc. >> >> Q: Do you condemn Ruby? >> >> No. I think it's reasonably elegant, but today there are too many >> languages, so Ruby don't particularly standout for me. Many of them, >> are arguably quite more elegant and powerful than Ruby. See: >> Proliferation of Computing Languages. >> > >Kenny Tilton, 2008-12-31 > >Q: Why not Xah's review of Ruby? > >>> Spent about 3 hours looking into Ruby language today. > >A. Three hours? I've had belches that lasted longer than that. Of >course, a true master can tell a lot in just a few hours of coding with >a new language... > >>> The articles i read in detail are: > >Q: Read?! > >A: That's what he said. > > >hth,kzo Be carefull what you say. If they pay me I would rip your and Xah's guts out in a second. sln From mail at microcorp.co.za Thu Jan 1 01:45:38 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 1 Jan 2009 08:45:38 +0200 Subject: select.select and socket.setblocking References: <495a661d$0$11384$5fc30a8@news.tiscali.it><495b34d8$0$11387$5fc30a8@news.tiscali.it> <495b4be5$0$11379$5fc30a8@news.tiscali.it> Message-ID: <010601c96be0$538bffa0$0d00a8c0@hendrik> "Francesco Bochicchio" wrote: > but then, IIRC TCP guarantees that the packet is fully received by > hand-shaking at transport level between sender and receiver. Ad once the > packet is fully in the receiver buffer, why should recv choose to give > back to the application only a piece of it? This depends a lot on the definition of "package" - At the TCP/IP level, the protocol is quite complex - there are all sorts of info flowing back and forth, telling the transmitter how much space the receiver has available. So your "record" or "package" could be split up... But it gets worse, or better, depending on your point of view: At the ethernet level, a packet is less than 1.5k - so if your record is longer, it can also be split up - OTOH, if it all fits into one ethernet packet, there is every chance that it won't be split up, unless you send a lot of them in a row, without waiting for a response - if you are running something that sends a small request and listens for a small answer, then you will probably never see a record split - but if you run a kind of sliding window protocol that streams a lot of data (even in small packets) then sooner or later one of them will be partly delivered... - Hendrik From rt8396 at gmail.com Thu Jan 1 02:12:48 2009 From: rt8396 at gmail.com (r) Date: Wed, 31 Dec 2008 23:12:48 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Hey Lee, I really like your overview of the official Python tut, it's spot on, and your study of OOP was quite fascinating! I like people who are honest and not afraid to go up against the status quo, although i will admit you go a little further than i might at times :). But the world needs an enema from time to time. "Revolution is my name!" Face it, the world needs people like Xah. Go check out his site, his insights of languages and tech is fascinating. The man lives in a world driven by common sense, and you know what they say --"Common sense is the least most common thing"-- just look around at the responses here. I come from a different world than IT, and I thought initially the IT world would be filled with intelligent, free thinking, and open minded people... BOY was i wrong! I would not turn my back on these people for a second, lest you catch a knife in it! I find it laughable how people hate you so much, but would still take the time to reply to your post, just so they can call you a troll. You are not a troll Xah, but your posts do expose the true trolls and their minions. Instead of engaging in any sort of intellectual conversation, they spit 3 grade insults and try to discredit you. There is nothing wrong with a person expressing their opinion on any subject. Apparently some of you need to get laid and calm down a little. Xah has just as much right as anyone here to post his thoughts, even if they are off topic. Look, if you don't like what he is saying, DON'T F'IN READ IT! Xah, I been watching your posts for sometime and it looks like you have been around for a while. Your profile shows one star & 410 ratings. I have only been in usenet for 2 month and i have one star and 253 ratings(that will grow to much more after this post), most are from my supposed "brothers" here at c.l.py. Just letting you know there are open minded people out here. I would hate to live in a world that did not contain an Xah lee. Keep up the good work my brother, you have much more to give! Thanks From jasonrumney at gmail.com Thu Jan 1 03:05:41 2009 From: jasonrumney at gmail.com (Jason Rumney) Date: Thu, 1 Jan 2009 00:05:41 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: On Jan 1, 3:12?pm, r wrote: > The man lives in a world driven by common sense "Common" sense suggests that his views are shared among the general populace. I don't see much evidence of that in the sometimes never- ending threads that frequently follow his postings. But it is good to start debates about making changes to the status quo, often the debates will result in worthwhile changes, even if those changes are not what he proposed. I just wish he would choose his venue a little more carefully sometimes. From geon at post.cz Thu Jan 1 03:11:50 2009 From: geon at post.cz (Pavel Kosina) Date: Thu, 01 Jan 2009 09:11:50 +0100 Subject: idle 3.0 unicode Message-ID: <495C7AC6.1000506@post.cz> As for unicode in Python 2.5 everything works fine in program running either in IDLE or under Command line: # -*- coding: utf-8 -*- print u"?????????" In 3.0 there is an error. The same program, moved to 3.0 syntax, in IDLE editor : # -*- coding: utf-8 -*- print ("?????????") prints: ?????????????????? The same program running in Command line from PSPad editor works fine. Is it mistake of my misunderstanding or of IDLE? ------------- The same program without coding declaration (but saved in utf8) : print ("?????????") even immediately destroyed my IDLE window without any error message. -- geon Pavel Kosina From bockman at virgilio.it Thu Jan 1 03:31:13 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Thu, 01 Jan 2009 09:31:13 +0100 Subject: select.select and socket.setblocking In-Reply-To: References: <495a661d$0$11384$5fc30a8@news.tiscali.it> <495b34d8$0$11387$5fc30a8@news.tiscali.it> Message-ID: <495c7f52$0$733$5fc30a8@news.tiscali.it> > Can you post an example program that exhibits the behavior you > describe? > > I was forgetting about the MSG_WAITALL flag ... When I started programming with sockets, it was on a platform (IIRC Solaris) that by default behaved like MSG_WAITALL was set by default (actually, I don't remember it being mentioned at all in the man pages). This sort of biased my understanding of the matter. I actually used that flag recently - on Linux - to get the same behavior I was used to, but forgot about that. My bad :-) Ciao ------ FB From s.selvamsiva at gmail.com Thu Jan 1 03:38:53 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 1 Jan 2009 14:08:53 +0530 Subject: pygtkspell-help Message-ID: Hello, i am in a process of writing spell checker for my local language(Tamil). I wrote a plugin for gedit with pygtk for gui.Recently i came to know about pygtkspell ,that can be used for spell checking and suggestion offering. I am bit congused about it and could not able to get useful info by googling.It will be nice if someone can direct me in right way(may be by giving appropriate links or example program) -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Thu Jan 1 03:58:20 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 08:58:20 +0000 Subject: Videocapture in python In-Reply-To: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: Can you post your code or a code segment? I would be interested in seeing how this works. On Thu, Jan 1, 2009 at 3:29 AM, wrote: > I face issues in videocapture in python. Cant find anyplace where we > can raise bug reports, so mentioning here. Also help required if > somebody has solved it earlier. > > On using videocapture (python 2.4), I am facing the following issues > while creating a video sort of application. > -> Pull out the usb cable : Videocapture gets the data stored > initially in the buffer and returns always. The images are not updated > - but also there is no error returned. > i.e. there is no information to the viewer that it is not working > anymore. Especially because since the timestamp is updated everytime > (it is done inside videocapture.py - wherein current time is > overwritten on the received image), it gives a feeling that video is > running. > > Currently I have done a workaround in that every 2 captures, i setup > the camera again - but it takes too much time. Anyone has any > suggestions on solving this? > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Thu Jan 1 04:04:15 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 09:04:15 +0000 Subject: Creating an application for Linux In-Reply-To: <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> Message-ID: I found a great video on how to do this last night. I wasn't even looking for it. Check it out. It's really good. Makes me want to start making videos as well. Thanks. Ubuntu: Making a .deb package out of a python program (English) tutorial video - Ubuntu: Making a .deb package out of a python program (English) - Learn: python, deb, deb_package, publishing, package, english, ubuntu, linux On Wed, Dec 31, 2008 at 9:54 PM, Mike Driscoll wrote: > On Dec 31, 3:36 pm, lkcl wrote: > > hiya mike: where do i know you from? i've heard your name somewhere > > and for the life of me can't remember where! anyway... onwards. > > > > I don't know...while your username looks vaguely familiar, I don't > think I've communicated with you recently. I spend most of my time on > the wxPython list now... > > > > your simplest bet is to take advantage of the .deb install system, > > which, if you follow that, will allow you to pull in all of the > > dependencies _without_ screwing around with the ubuntu distribution, > > or requiring that you build "special" versions of the dependencies. > > > > so - your first port of call is to locate a similar app to your own > > one: > > > > apt-cache search wxwidgets > > [rose-tinted filter on the results...] > > cryptonit - A client side PKI (X.509) cryptographic tool > > fontypython - A GUI tool to manage ttf fonts > > jmdlx - jugglemaster deluxe using wxWidgets > > wxmaxima - a wxWidgets GUI for the computer algebra system maxima > > multiget - graphical download manager > > > > then, do apt-cache show , paying particular attention to > > the dependencies. apt-cache show fontypython looks like a good > > candidate. > > > > so, do apt-get source fontypython (or other candidate) > > > > also do apt-get build-essential dh-make dpkg-dev debutils python-dev > > devscripts python-setuptools juuust for fun, but the essential ones > > are probably dh-make and dpkg-dev. > > > > then you have something to work from (an example - the source of the > > deb-wrapped fontypython) and you will have most of the debian > > developer utils etc. etc. > > > > _then_ you go to e.g. oooo this: > http://www.pythonmark.com/python-library/debian/howto-build-a-debian-... > > the preamble for which says "don't bother with that annoying ubuntu > > python deb howto video, particularly on the basis that who gives a > > stuff about _verbal_ instructions when you actually want stuff you can > > READ!" > > > > :) > > > > the most important thing that _you_ need to remember is that you > > _must_ identify the correct libraries (and their debian packagenames - > > can't bring myself to say ubuntu packagenames) and make damn sure that > > you add them into the dependencies in the debian/control file. > > > > do _not_ be tempted to "bundle" customised versions of python- > > pysqlite, python-sqlalchemy etc. etc. > > > > testing: you should really use a debootstrap absolute "basic" > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > whatever). > > > I thought the general practice was to test on the closest software/ > hardware combo that your application was most likely to run on. I have > heard of doing testing on the lowest common denominator before though. > Unfortunately, I don't have time to set up a bare-bones VM since we're > closing soon, but I may give this a go on Friday and report back. > > > > > ... and _then_ install your .deb (with dpkg -i) followed by apt-get -f > > install (to pull in all of the dependencies). > > > > then, use export DISPLAY=192.168.1.5:0.0 (adapt as necessary), run > > xhost + on 192.168.1.5 (adapt as necessary), and _then_ fire up your > > test app. > > > > if you get a python library not found runtime error, you know that you > > got your dependencies wrong, in the debian/control file. > > > > if you install a "vanilla" ubuntu desktop, various other packages will > > pull in the dependencies for you - and you will never find out if you > > got all of the dependencies correct. > > > > that having been said, if you don't _care_ about correctness, skip the > > above six sentences :) > > > > l. > > > > Thanks for the instructions. > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.grimm at science-computing.de Thu Jan 1 04:23:32 2009 From: r.grimm at science-computing.de (r.grimm at science-computing.de) Date: Thu, 1 Jan 2009 01:23:32 -0800 (PST) Subject: folder extraction References: Message-ID: On Dec 30 2008, 4:30 pm, ibpe... at gmail.com wrote: > how do i get along with this task of extracting multiples folder and > generating their names individually in a their respective files as > they were generated. Hallo, I hope, that I interpret your question in the right way. You can use the following function as a starting point to get all files ending with py or pyc from your working dir. Invoke getAllFilesOfPatterns(".","*.py *.pyc") import os import fnmatch def getAllFilesOfPatterns( dir ,patterns="*", recursive=True ): """ patterns must be space separeted string of patterns e.g: *.pdf *.ps *.html """ patterns= patterns.split() retValue=[] for path,dirs,files in os.walk(dir): for file in files: for pattern in patterns: if fnmatch.fnmatch( file , pattern ): retValue.append(os.path.join(path,file)) if not recursive: break return retValue Greetings From aleksandr.goretoy at gmail.com Thu Jan 1 04:25:16 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 1 Jan 2009 09:25:16 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: I recently conquered this pass by ref thing. This is how I did it. Python 2.4.3 (#1, Apr 3 2006, 14:02:53) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(v): ... v="asdf" ... >>> def f2(v): ... v=["asdf"] ... >>> def f3(v): ... v.append("asdf") ... >>> a="fdsa" >>> b=["fdsa"] >>> f1(a) >>> a 'fdsa' >>> f1(b) >>> b ['fdsa'] >>> f2(a) >>> a 'fdsa' >>> f2(b) >>> b ['fdsa'] >>> f3(a) Traceback (most recent call last): File "", line 1, in ? File "", line 2, in f3 AttributeError: 'str' object has no attribute 'append' >>> f3(b) >>> b ['fdsa', 'asdf'] >>> if you only want one value in there, you can pop off the first value and then append. def f4(v): _old=v.pop() v.append("asdf") you can then also turn it back into a string by doing this: b[0] I was very glad to have learned this way to do by ref. Thanks. On Wed, Dec 31, 2008 at 11:32 PM, Aaron Brady wrote: > On Dec 31, 5:30 am, iu2 wrote: > > Hi, > > > > Is it possible somehow to change a varible by passing it to a > > function? > > > > I tried this: > > > > def change_var(dict0, varname, val): > > dict0[varname] = val > > > > def test(): > > a = 100 > > change_var(locals(), 'a', 3) > > print a > > > > But test() didn't work, the value a remains 100. > > > > I have several variables initialized to None. > > I need to convert each one of them an object only if it is None. > > something like: > > > > if not var1: var1 = MyObject() > > > > I want this to be a function, that is: > > > > def create_obj(var): > > if not var: var = MyObj() > > # set properties of var > > > > Now, I know I can achieve this by functional programming, > > > > def create_obj(var): > > if not var: > > x = MyObj() > > # set properties of x > > return x > > return var > > > > and then > > > > var = creaet_obj(var) > > > > Is there another way? > > > > Thanks > > A practical way is to use a container. Some people use lists; I like > an object. > > thingref= Ref( thing ) > f( thingref ) > print thingref() #or thingref.get() or w'ver. > > Then 'f' can assign like this: > > def f( aref ): > # blah blah > aref( newthing ) #or aref.set( newthing ) > > But the short answer is no. A function receives the contents of a > variable, not a variable. > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From qdlqdl at 163.com Thu Jan 1 04:32:12 2009 From: qdlqdl at 163.com (=?ISO-2022-JP?B?GyRCPi5PMBsoQg==?=) Date: Thu, 1 Jan 2009 01:32:12 -0800 (PST) Subject: idle 3.0 unicode References: Message-ID: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> On 1?1?, ??4?11?, Pavel Kosina wrote: > As for unicode in Python 2.5 everything works fine in program running > either in IDLE or under Command line: > # -*- coding: utf-8 -*- > print u"?????????" > > In 3.0 there is an error. ?The same program, moved to 3.0 syntax, in > IDLE editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program running in Command line from PSPad editor works fine. ? > Is it mistake of my misunderstanding or of IDLE? > > ------------- > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. > > -- > geon > Pavel Kosina #coding="utf-8" #?? print('a') saved in utf8 alt+x,destroyed IDLE... me too,why? From joshua86 at gmail.com Thu Jan 1 04:43:59 2009 From: joshua86 at gmail.com (Joshua Moore) Date: Thu, 1 Jan 2009 01:43:59 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <95479382-5996-40da-b20d-8e6e83b725ea@s1g2000prg.googlegroups.com> On Dec 30 2008, 8:07?am, "andyh... at gmail.com" wrote: > Hi, > > Can anybody recommend an approach for loading and parsing Excel > spreadsheets in Python. Any well known/recommended libraries for this? > > The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, > but I'd rather get some more input before going with something I don't > know. > > Thanks, > Andy. Is saving the spreadsheet as a comma separated file an option for you? If so, it's not hard to throw something together for cvs files, but there are even modules for that. Josh From sjmachin at lexicon.net Thu Jan 1 04:56:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 1 Jan 2009 01:56:10 -0800 (PST) Subject: folder extraction References: Message-ID: <9e75caba-1f52-4a01-b7d4-6c2bd52f3946@i20g2000prf.googlegroups.com> On Jan 1, 8:23?pm, r.gr... at science-computing.de wrote: > On Dec 30 2008, 4:30 pm, ibpe... at gmail.com wrote: > > > how do i get along with this task of extracting multiples folder and > > generating their names individually in a their respective files as > > they were generated. > > Hallo, > I hope, that I interpret your question in the right way. > You can use the following function as a starting point to get all > files ending with py or pyc from your working dir. > Invoke getAllFilesOfPatterns(".","*.py *.pyc") > > import os > import fnmatch > def getAllFilesOfPatterns( dir ,patterns="*", ?recursive=True ?): > ? ? """ patterns must be space separeted string of patterns > ? ? ? ? e.g: *.pdf *.ps *.html > ? ? ? ? """ > ? ? patterns= patterns.split() > ? ? retValue=[] > ? ? for path,dirs,files in os.walk(dir): > ? ? ? ? for file in files: > ? ? ? ? ? ? for pattern in patterns: > ? ? ? ? ? ? ? ? if fnmatch.fnmatch( file , pattern ): > ? ? ? ? ? ? ? ? ? ? retValue.append(os.path.join(path,file)) # put a "break" after the append so that you avoid (a) duplicates [if the patterns are not mutually exclusive] (b) waste of CPU time [always] > ? ? ? ? if not recursive: break > ? ? return retValue > > Greetings From geon at post.cz Thu Jan 1 05:06:48 2009 From: geon at post.cz (Pavel Kosina) Date: Thu, 01 Jan 2009 11:06:48 +0100 Subject: idle 3.0 unicode In-Reply-To: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> References: <9b7cb1c6-d705-4feb-94cd-3be1e94d6063@y1g2000pra.googlegroups.com> Message-ID: <495C95B8.7080300@post.cz> ?? napsal(a), dne 1.1.2009 10:32: > #coding="utf-8" > #?? > print('a') > > saved in utf8 > alt+x,destroyed IDLE... > me too,why? > Are you sure? Run (F5) with print('a') is OK here. Maybe you have redefined key bindings in IDLE ... -- geon Pavel Kosina From merlyn at stonehenge.com Thu Jan 1 05:07:26 2009 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Thu, 01 Jan 2009 02:07:26 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <861vvnqqzl.fsf@blue.stonehenge.com> >>>>> "r" == r writes: r> Xah, I been watching your posts for sometime and it looks like you r> have been around for a while. Your profile shows one star & 410 r> ratings. I have only been in usenet for 2 month and i have one star r> and 253 ratings(that will grow to much more after this post), most are r> from my supposed "brothers" here at c.l.py. Just letting you know r> there are open minded people out here. I would hate to live in a world r> that did not contain an Xah lee. Since Usenet has neither "stars" nor "ratings", you are hallucinating. Care to elaborate? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion From mirnazim at gmail.com Thu Jan 1 05:28:40 2009 From: mirnazim at gmail.com (Mir Nazim) Date: Thu, 1 Jan 2009 02:28:40 -0800 (PST) Subject: Chart libs for python Message-ID: <4a8c13a2-a2ae-4815-9560-8e1ef1e21f97@i24g2000prf.googlegroups.com> Hi guys, Please suggest me chart generation library for python comparable to google chart in features and ease of development. Google Chart has a limitation on amount on data you can send in a URL. Thanks From stef.mientki at gmail.com Thu Jan 1 06:10:34 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 01 Jan 2009 12:10:34 +0100 Subject: Easy-to-use Python GUI In-Reply-To: <6s2n0sF408fuU1@mid.uni-berlin.de> References: <6s2n0sF408fuU1@mid.uni-berlin.de> Message-ID: <495CA4AA.1080003@gmail.com> Gerhard H?ring wrote: > Dotan Cohen wrote: >> I have been following this thread with interest. Is there a way to >> build Qt apps with relative easy? I use KDE and would prefer the Qt >> toolkit for my GUI apps. Thanks. > > A few years ago, I've had bad experiences with wxPython (random things > not actually working on Linux, only on Windows; getting segfaults when > using not exactly the right values for API calls). > > So, when I had to decide for a toolkit for a new application I'm > developing on my job which required: > > - ability to run on Windows > - ability to run on MacOS > - time to develop is short > > I recommended to go with PyQt. > > I remembered it was warmly recommended by Alex Martelli and others a > few years ago. > > So far, it's been nothing but joy. We bought the book "Rapid GUI > Programming with Python and Qt" (http://www.qtrac.eu/pyqtbook.html) > which is *really* well written. It's probably the best tech book I > ever had. The author formerly did Qt documentation for Trolltech, so > he has deep understanding of what he's writing about. > > There may be not so many third-party add-ons for PyQt like for > wxPython, but in my opinion, the quality of Qt, PyQt and > documentation like the book make up for it. > > And, it's really extensive. So far I've found everything in Qt/PyQt I > wanted/needed: > > - MDI workspaces > - Dock windows > - I needed something like wxPythons wxOGL for a process modeler and > after looking around for two days, I found out that it's already all > there in Qt 4.4: QGraphicsScene/QGraphicsView > - etc. > I think wxPython now has it all too. I replaced wxOGL with a modified version of OGLlike, see some screenshots here: http://mientki.ruhosting.nl/data_www/pylab_works/pw_animations_screenshots.html cheers, Stef > -- Gerhard > -- > http://mail.python.org/mailman/listinfo/python-list From placebo at dontbesilly.com Thu Jan 1 06:34:42 2009 From: placebo at dontbesilly.com (Peter Wyzl) Date: Thu, 01 Jan 2009 11:34:42 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <861vvnqqzl.fsf@blue.stonehenge.com> Message-ID: "Randal L. Schwartz" wrote in message news:861vvnqqzl.fsf at blue.stonehenge.com... >>>>>> "r" == r writes: > > r> Xah, I been watching your posts for sometime and it looks like you > r> have been around for a while. Your profile shows one star & 410 > r> ratings. I have only been in usenet for 2 month and i have one star > r> and 253 ratings(that will grow to much more after this post), most are > r> from my supposed "brothers" here at c.l.py. Just letting you know > r> there are open minded people out here. I would hate to live in a world > r> that did not contain an Xah lee. > > Since Usenet has neither "stars" nor "ratings", you are hallucinating. > > Care to elaborate? Google groups' corrupting influence... P From huffman at tokyo.email.ne.jp Thu Jan 1 06:37:19 2009 From: huffman at tokyo.email.ne.jp (Tokyo Dan) Date: Thu, 1 Jan 2009 03:37:19 -0800 (PST) Subject: If your were going to program a game... Message-ID: If your were going to program a game in python what technologies would you use? The game is a board game with some piece animations, but no movement animation...think of a chess king exploding. The game runs in a browser in a window of a social site built around the game. The social site has login, chat, player stats, list of active games, etc. AND there is also be a desktop client that accesses the game server via the same communication mechanism (like an AIR-based desktop client/ app) as the browser-based version - I guess using JSON/RPC. From koranthala at gmail.com Thu Jan 1 07:28:21 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 04:28:21 -0800 (PST) Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: On Jan 1, 1:58?pm, "alex goretoy" wrote: > Can you post your code or a code segment? I would be interested in seeing > how this works. > > > > On Thu, Jan 1, 2009 at 3:29 AM, wrote: > > I face issues in videocapture in python. Cant find anyplace where we > > can raise bug reports, so mentioning here. Also help required if > > somebody has solved it earlier. > > > On using videocapture (python 2.4), I am facing the following issues > > while creating a video sort of application. > > -> Pull out the usb cable : Videocapture gets the data stored > > initially in the buffer and returns always. The images are not updated > > - but also there is no error returned. > > i.e. there is no information to the viewer that it is not working > > anymore. Especially because since the timestamp is updated everytime > > (it is done inside videocapture.py - wherein current time is > > overwritten on the received image), it gives a feeling that video is > > running. > > > Currently I have done a workaround in that every 2 captures, i setup > > the camera again - but it takes too much time. Anyone has any > > suggestions on solving this? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? Since the code uses a lot of other variables - due to being a part of a larger project, I will try to provide pseudocode. At initialization: def setup_cam(): global cam, i cam = Device (devnum = 0) i = 0 def take_photo(obj): i += 1 if i >2: setup_cam() obj.img = cam.getImage(timestamp=3) I actually would like to have the code as try: obj.img = cam.getImage(timestamp=3) except CamException: setup_cam() But, since no exception is provided, I have to resort to the kludge shown. Please let me know if you need any more information. From koranthala at gmail.com Thu Jan 1 07:44:33 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 04:44:33 -0800 (PST) Subject: initialization in python Message-ID: How does an average product handle initialization in python? I am facing lot of issues in handling initialization, especially if I import specific variables, due to the variables not getting updated. For example - taking a sqlalchemy based product: Module database: ^^^^^^^^^^^^^^^^^^^ Session = None def init(dbname): engine = create_engine('sqlite:///%s' %dbname) ... global Session Session = sessionmaker(bind=engine) In entry module to the application (APPENTRY): ^^^^^^^^^^^^^^^^^^^ import A, B, C, D <---- Please note, very important .... .... database.init('testdb.db') Now in user module A: ^^^^^^^^^^^^^^^^^^^^^^^^^^ from database import Session print Session --->This will print None, because at APPENTRY, during importing A itself, Session is stored. I have to call database.Session to get the values. Why is the variable not getting updated? Can anyone help me out? From bdesth.quelquechose at free.quelquepart.fr Thu Jan 1 08:43:30 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 01 Jan 2009 14:43:30 +0100 Subject: SQL, lite lite lite In-Reply-To: References: <39322fe4-e606-42dc-9123-71751258c3ae@a12g2000pro.googlegroups.com> <8da5c6b1-951f-4abd-8ee7-07b63802b9f6@13g2000yql.googlegroups.com> <186e44f7-f949-45e2-b1e2-a913560acf94@s9g2000prg.googlegroups.com> <495a97ce$0$25469$426a74cc@news.free.fr> Message-ID: <495cd630$0$17993$426a74cc@news.free.fr> Aaron Brady a ?crit : > On Dec 30, 2:52 pm, Bruno Desthuilliers > wrote: >> Aaron Brady a ?crit : >> >>> On Dec 30, 11:16 am, prueba... at latinmail.com wrote: >> (snip) >>>> You really do like to reinvent the wheels do you? :-) Nothing wrong >>>> with that. Just be aware that most people that really need what you >>>> are proposing are probably already using mature feature rich libraries >>>> for that. >>>> http://wiki.python.org/moin/HigherLevelDatabaseProgramming >>> Look at these options! Who invents the wheel? Naturally, I've had >>> time to master every one. >> Oh, so that's why you propose to add yet another item to the list ? > > Aha, so it is. Your criticism might seem harsh, This was mostly a tentative to make you notice that it might be better to check out the existing solutions and possibly contribute to one of them instead of inventing yet another one... > but it has an > advantage. It made me get the lead out, that is, think. > (snip) ... but it obviously failed. From luke.leighton at googlemail.com Thu Jan 1 08:47:22 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 1 Jan 2009 05:47:22 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> Message-ID: <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > On Dec 31, 3:36 pm,lkcl wrote: > > > hiya mike: where do i know you from? i've heard your name somewhere > > and for the life of me can't remember where! anyway... onwards. > > I don't know...while your username looks vaguely familiar, I don't > think I've communicated with you recently. I spend most of my time on > the wxPython list now... i think it might be from my old school - i could be confusing you with someone, though - "gary driscoll", perhaps? anyway, never mind :) > > testing: you should really use a debootstrap absolute "basic" > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > whatever). > > I thought the general practice was to test on the closest software/ > hardware combo that your application was most likely to run on. that you should do as well :) you should be able to either upgrade the bare-bones version using "tasksel install desktop" or just... what-the-heck, install on a vanilla combo. http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/current/images/netboot/ archive.ubuntu.com appears offline at the moment - maybe it'll be back later. i recommend you go for the mini.iso > I have > heard of doing testing on the lowest common denominator before though. > Unfortunately, I don't have time to set up a bare-bones VM since we're > closing soon, but I may give this a go on Friday and report back. ok - the issue that you will face if you _don't_ do a LCD test is that should ubuntu get upgraded, and one of the packages that _used_ to pull in a dependency [that you missed] no longer does so... From sjmachin at lexicon.net Thu Jan 1 08:54:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 1 Jan 2009 05:54:42 -0800 (PST) Subject: initialization in python References: Message-ID: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> On Jan 1, 11:44?pm, koranth... at gmail.com wrote: > How does an average product handle initialization in python? > I am facing lot of issues in handling initialization, especially if I > import specific variables, due to the variables not getting updated. > > For example - taking a sqlalchemy based product: > Module database: > ^^^^^^^^^^^^^^^^^^^ > Session = None > > def init(dbname): > ? ?engine = create_engine('sqlite:///%s' %dbname) > ? ?... > ? ?global Session > ? ?Session = sessionmaker(bind=engine) > > In entry module to the application (APPENTRY): > ^^^^^^^^^^^^^^^^^^^ > import A, B, C, D ?<---- Please note, very important > .... > .... > database.init('testdb.db') > > Now in user module A: > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > from database import Session > print Session > --->This will print None, because at APPENTRY, during importing A > itself, Session is stored. This is happening when you import A, which happens *before* you call database.init(). database.init binds the name database.Session to a new value. The name A.Session has been bound earlier to the value None. > I have to call database.Session to get the values. I don't understand that sentence. Is database.Session callable (i.e. is a function or class)? What valueS (plural)? > Why is the variable not getting updated? Firstly, it's not a "variable" in the sense of a named slice of memory to which various values can be assigned. Secondly, it could be updated only if the "from database import Session" operated like it was creating an alias e.g. A.Session isanaliasof database.Session like a C macro #define A_Session database_Session but it isn't; its effect is that of a fancy "assignment", more or less like: import database Session = database.Session del database In any case, mucking about with module globals like you are trying to do is not a good idea. As you have seen, it introduces dependencies like you need to import A after the database is initiated. As soon as you need more than one session at a time, or the single session needs to be closed and restarted, it really falls apart. Try passing your session around as a function arg, or as an attribute of an object that contains current state information. HTH, John From bj_666 at gmx.net Thu Jan 1 09:26:03 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 1 Jan 2009 14:26:03 GMT Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: <6s423rF44m1hU1@mid.uni-berlin.de> On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > Please let me know if you need any more information. Where does `videocapture.py` coming from? It's not part of the standard library. And which operating system are we talking about? Ciao, Marc 'BlackJack' Rintsch From david at abbottdavid.com Thu Jan 1 10:23:04 2009 From: david at abbottdavid.com (David) Date: Thu, 01 Jan 2009 10:23:04 -0500 Subject: Videocapture in python In-Reply-To: <6s423rF44m1hU1@mid.uni-berlin.de> References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: <495CDFD8.1010309@abbottdavid.com> Marc 'BlackJack' Rintsch wrote: > On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > >> Please let me know if you need any more information. > > Where does `videocapture.py` coming from? It's not part of the standard > library. And which operating system are we talking about? > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list > > Hope this is not off topic, I am new to python. I use linux and use the subprocess module, feel free to point out my noviceness; #!/usr/bin/python import subprocess def take_shot_func(): streamer = "/usr/bin/streamer" s_arg1 = "-c" s_device = "/dev/video0" s_arg2 = "-b" s_rate = "16" s_arg3 = "-o" save_to = "/tmp/camshot.jpeg" print "Taking picture with webcam and saved to /tmp/camshot.jpeg" subprocess.call([streamer, s_arg1, s_device, s_arg2, s_rate, s_arg3, save_to]) def main(): take_shot_func() if __name__ == "__main__": main() -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From koranthala at gmail.com Thu Jan 1 10:35:11 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 07:35:11 -0800 (PST) Subject: initialization in python References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: On Jan 1, 6:54?pm, John Machin wrote: > On Jan 1, 11:44?pm, koranth... at gmail.com wrote: > > > > > How does an average product handle initialization in python? > > I am facing lot of issues in handling initialization, especially if I > > import specific variables, due to the variables not getting updated. > > > For example - taking a sqlalchemy based product: > > Module database: > > ^^^^^^^^^^^^^^^^^^^ > > Session = None > > > def init(dbname): > > ? ?engine = create_engine('sqlite:///%s' %dbname) > > ? ?... > > ? ?global Session > > ? ?Session = sessionmaker(bind=engine) > > > In entry module to the application (APPENTRY): > > ^^^^^^^^^^^^^^^^^^^ > > import A, B, C, D ?<---- Please note, very important > > .... > > .... > > database.init('testdb.db') > > > Now in user module A: > > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > > from database import Session > > print Session > > --->This will print None, because at APPENTRY, during importing A > > itself, Session is stored. > > This is happening when you import A, which happens *before* you call > database.init(). database.init binds the name database.Session to a > new value. The name A.Session has been bound earlier to the value > None. > > > I have to call database.Session to get the values. > > I don't understand that sentence. Is database.Session callable (i.e. > is a function or class)? What valueS (plural)? > > > Why is the variable not getting updated? > > Firstly, it's not a "variable" in the sense of a named slice of memory > to which various values can be assigned. > > Secondly, it could be updated only if the "from database import > Session" operated like it was creating an alias e.g. > ? ? A.Session isanaliasof database.Session > like a C macro > ? ? #define A_Session database_Session > but it isn't; its effect is that of a fancy "assignment", more or less > like: > ? ? import database > ? ? Session = database.Session > ? ? del database > > In any case, mucking about with module globals like you are trying to > do is not a good idea. As you have seen, it introduces dependencies > like you need to import A after the database is initiated. As soon as > you need more than one session at a time, or the single session needs > to be closed and restarted, it really falls apart. Try passing your > session around as a function arg, or as an attribute of an object that > contains current state information. > > HTH, > John > This is happening when you import A, which happens *before* you call > database.init(). database.init binds the name database.Session to a > new value. The name A.Session has been bound earlier to the value > None. I guessed as much. But, I was under the impression that if the original value is modified, the variables value also will change. > I don't understand that sentence. Is database.Session callable (i.e. > is a function or class)? What valueS (plural)? Session() here is a session manager in SQLAlchemy. database.Session() creates a new session. > import database > Session = database.Session > del database Thank you. This answers my query. > In any case, mucking about with module globals like you are trying to > do is not a good idea. As you have seen, it introduces dependencies I avoid global variables as much as possible. But SQLAlchemy tutorial recommends this method of assignment. So, I was using this. Anyways, I now use database.Session always, and these dependencies are no longer there. From koranthala at gmail.com Thu Jan 1 10:40:41 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 07:40:41 -0800 (PST) Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: On Jan 1, 7:26?pm, Marc 'BlackJack' Rintsch wrote: > On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > > Please let me know if you need any more information. > > Where does `videocapture.py` coming from? ?It's not part of the standard > library. ?And which operating system are we talking about? > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch Hi Marc, It is not part of standard library. Sorry for me being very brief earlier. It is taken from http://videocapture.sourceforge.net/, - a very good tool for webcam capture in Win32. Hi David, I am in Windows. And there is a possibility that I might be using device 0 or 1. So, I am using the excellent VideoCapture tool created by Markus Gritsch. From Ron.Barak at lsi.com Thu Jan 1 11:19:03 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 1 Jan 2009 16:19:03 +0000 Subject: How to find the beginning of last line of a big text file ? Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Hi, I have a very big text file: I need to find the place where the last line begins (namely, the offset of the one-before-the-last '\n' + 1). Could you suggest a way to do that without getting all the file into memory (as I said, it's a big file), or heaving to readline() all lines (ditto) ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyosohma at gmail.com Thu Jan 1 11:36:14 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:36:14 -0800 (PST) Subject: Iowa Python Users Group Meeting (Jan. 5, 2008) Message-ID: Hi, The next Iowa Python Users Group meeting is Monday, January 5th, 2008, barring bad weather. We will be meeting from 7-9 p.m. at the following location: Marshall County Sheriff's Office 2369 Jessup Ave Marshalltown, IA 50158 Currently we have one tentative speaker scheduled and a workshop planned. If you don't have a laptop, let me know. We can provide a few for the workshop but we need to know ahead of time. Also let us know if you do plan to come so we know how many to expect. Email me off- list so we don't annoy the other people on this list. Our group is for both experience and new programmers. All experience levels are welcome. We hope to see you there! If you have any questions, just let me know. Mike Driscoll www.pyowa.org From kyosohma at gmail.com Thu Jan 1 11:38:39 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:38:39 -0800 (PST) Subject: Iowa Python Users Group Meeting (Jan. 5, 2008) References: Message-ID: <8c34ea80-2914-43dc-bf9d-a445439bfc6e@w39g2000prb.googlegroups.com> On Jan 1, 10:36?am, Mike Driscoll wrote: > Hi, > > The next Iowa Python Users Group meeting is Monday, January 5th, 2008, > barring bad weather. We will be meeting from 7-9 p.m. at the following > location: > > Marshall County Sheriff's Office > 2369 Jessup Ave > Marshalltown, IA 50158 > > Currently we have one tentative speaker scheduled and a workshop > planned. If you don't have a laptop, let me know. We can provide a few > for the workshop but we need to know ahead of time. Also let us know > if you do plan to come so we know how many to expect. Email me off- > list so we don't annoy the other people on this list. > > Our group is for both experience and new programmers. All experience > levels are welcome. We hope to see you there! If you have any > questions, just let me know. > > Mike Driscollwww.pyowa.org Looks like I am still getting over the lack of sleep from New Years. The date should be 2009, not 2008. Sorry about that. Mike From kyosohma at gmail.com Thu Jan 1 11:44:26 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 1 Jan 2009 08:44:26 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> Message-ID: <05e462b7-cfab-4f37-b545-bdff51f0e684@a12g2000pro.googlegroups.com> On Jan 1, 7:47?am, lkcl wrote: > On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > > > On Dec 31, 3:36 pm,lkcl wrote: > > > > hiya mike: where do i know you from? ?i've heard your name somewhere > > > and for the life of me can't remember where! ?anyway... onwards. > > > I don't know...while your username looks vaguely familiar, I don't > > think I've communicated with you recently. I spend most of my time on > > the wxPython list now... > > ?i think it might be from my old school - i could be confusing you > with > ?someone, though - "gary driscoll", perhaps? anyway, never mind :) > > > > testing: you should really use a debootstrap absolute "basic" > > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > > whatever). > > > I thought the general practice was to test on the closest software/ > > hardware combo that your application was most likely to run on. > > ?that you should do as well :) ?you should be able to either upgrade > ?the bare-bones version using "tasksel install desktop" or just... > ?what-the-heck, install on a vanilla combo. > > ?http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/c... > > ?archive.ubuntu.com appears offline at the moment - maybe it'll be > back later. ?i recommend you go for the mini.iso > Ok...thanks for the info! > > I have > > heard of doing testing on the lowest common denominator before though. > > Unfortunately, I don't have time to set up a bare-bones VM since we're > > closing soon, but I may give this a go on Friday and report back. > > ?ok - the issue that you will face if you _don't_ do a LCD test is > that > ?should ubuntu get upgraded, and one of the packages that _used_ to > pull > ?in a dependency [that you missed] no longer does so... I see. I had hoped that there was a way to create a frozen application like I do with py2exe on Windows so I wouldn't have to worry about a Linux upgrade breaking my application. I've been told that PyInstaller might do the trick too. Either way, I'll post the solution that works for me. Happy New Year! Mike From thorsten at thorstenkampe.de Thu Jan 1 11:50:39 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 1 Jan 2009 17:50:39 +0100 Subject: Desktop/File management support on MS Windows References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> Message-ID: * riklaunim at gmail.com (Wed, 31 Dec 2008 09:08:46 -0800 (PST))> > Are there any Python libraries that can trash files (move to Trash, > not delete) or for example return a list of applications that can open > given file? I can't find anything related to this for Windows. http://timgolden.me.uk/python/winshell.html Thorsten From sbassi at clubdelarazon.org Thu Jan 1 11:54:44 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Thu, 1 Jan 2009 14:54:44 -0200 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Message-ID: <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: > I have a very big text file: I need to find the place where the last line > begins (namely, the offset of the one-before-the-last '\n' + 1). > Could you suggest a way to do that without getting all the file into memory > (as I said, it's a big file), or heaving to readline() all lines (ditto) ? for line in open(filename): lastline = line print "the lastline is: %s",%lastline This will read all the lines, but line by line, so you will never have the whole file in memory. There may be more eficient ways to do this, like using the itertools. Best, SB. From kentilton at gmail.com Thu Jan 1 12:24:16 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Thu, 01 Jan 2009 12:24:16 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: <495cfcd2$0$4889$607ed4bc@cv.net> sln at netherlands.com wrote: > On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: > >> Xah Lee wrote: >>> Just spent 3 hours looking into Ruby today. Here's my short impression >>> for those interested. >>> >>> * Why Not Ruby? >>> http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html >>> >>> plain text version follows: >>> -------------------------------------- >>> >>> Why Not Ruby? >>> >>> Xah Lee, 2008-12-31 >>> >>> Spent about 3 hours looking into Ruby language today. >>> >>> The articles i read in detail are: >>> >>> * Wikipedia: Ruby (programming language)?J. Gives general overview. >>> >>> * Brief tutorial: "Ruby in Twenty Minutes" >>> http://www.ruby-lang.org/en/documentation/quickstart/ >>> >>> * Personal blog by Stevey Yegge, published in 2004-10. >>> http://steve.yegge.googlepages.com/ruby-tour >>> >>> The Wikipedia gives the best intro and overview in proper context. The >>> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete >>> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't >>> teach much and rambles, but provide a little personal view. I read it >>> because his opinions i respect. >>> >>> Q: Will you learn Ruby? >>> >>> No. For practical application, the lang is some 100 times less useful >>> than each of Perl, Python, PHP, Javascript. For academic study, >>> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far >>> more interesting and powerful in almost all aspects. Further, there's >>> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or >>> power, these modern lang of the past 5 years matches or exceed Ruby. >>> >>> Q: Do you think Ruby lang is elegant? >>> >>> Yes. In my opinion, better than Perl, Python, PHP. As a high level >>> lang, it's far better than Java, C, C++ type of shit. However, i don't >>> think it is any better than emacs lisp, Scheme lisp, javascript, >>> Mathematica. Note that Ruby doesn't have a spec, and nor a formal >>> spec. Javascript has. Ruby's syntax isn't that regular, nor is it >>> based on a system. Mathemtica's is. Ruby's power is probably less than >>> Scheme, and probably same as Javascript. >>> >>> I also didn't like the fact that ruby uses keyword "end" to indicate >>> code block much as Pascal and Visual Basic, Logo, do. I don't like >>> that. >>> >>> Q: Won't Ruby be a interesting learning experience? >>> >>> No. As far as semantics goes, Ruby is basically identical to Perl, >>> Python, PHP. I am a expert in Perl and PHP, and have working knowledge >>> of Python. I already regretted having spent significant amount of time >>> (roughly over a year) on Python. In retrospect, i didn't consider the >>> time invested in Python worthwhile. (as it turns out, i don't like >>> Python and Guido cult, as the lang is going the ways of OOP mumbo- >>> jumbo with its Python 3 "brand new" future.) There is absolutely >>> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp, >>> Scheme lisp. >>> >>> Q: Do you recommend new programers to learn Ruby then? >>> >>> Not particularly. As i mentioned, if you are interested in practical >>> utility, there's already Perl, PHP, Python, Javascript, which are all >>> heavily used in the computing industry. If you are interested as a >>> academic exercise, there's Scheme lisp, and much of functional langs >>> such as OCaml, Haskell, Mathematica, which will teach you a whole lot >>> more about computer science, features of language semantics, etc. >>> >>> Q: Do you condemn Ruby? >>> >>> No. I think it's reasonably elegant, but today there are too many >>> languages, so Ruby don't particularly standout for me. Many of them, >>> are arguably quite more elegant and powerful than Ruby. See: >>> Proliferation of Computing Languages. >>> >> Kenny Tilton, 2008-12-31 >> >> Q: Why not Xah's review of Ruby? >> >>>> Spent about 3 hours looking into Ruby language today. >> A. Three hours? I've had belches that lasted longer than that. Of >> course, a true master can tell a lot in just a few hours of coding with >> a new language... >> >>>> The articles i read in detail are: >> Q: Read?! >> >> A: That's what he said. >> >> >> hth,kzo > > Be carefull what you say. If they pay me I would rip your and Xah's > guts out in a second. Sorry, my new President has banned drama so I will only be responding pleasantly to civil comments. (This has been a non-responding response.) Peace,k From google at mrabarnett.plus.com Thu Jan 1 12:31:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jan 2009 17:31:06 +0000 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> Message-ID: <495CFDDA.7000507@mrabarnett.plus.com> Barak, Ron wrote: > Hi, > > I have a _very_ big text file: I need to find the place where the last > line begins (namely, the offset of the one-before-the-last '\n' + 1). > > Could you suggest a way to do that without getting all the file into > memory (as I said, it's a big file), or heaving to readline() all lines > (ditto) ? > You could seek() to near the end of the file before reading lines with readline(). Remember that the seek will almost certainly put the file pointer somewhere in the middle of a line, but that doesn't matter provided that it's not the last line (ie if the second readline() returns "" then the first readline() started somewhere in middle of the last line of the file). If you find that the seek put the file pointer somewhere in the middle of the last line, then try again, but this time seeking further back from the end of file before reading. Repeat as necessary. From sthalik at test123.ltd.pl Thu Jan 1 12:34:51 2009 From: sthalik at test123.ltd.pl (=?UTF-8?Q?Stanis=C5=82aw?= Halik) Date: Thu, 1 Jan 2009 17:34:51 +0000 (UTC) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: In comp.lang.lisp r wrote: > Face it, the world needs people like Xah. Go check out his site, his > insights of languages and tech is fascinating. The man lives in a > world driven by common sense, and you know what they say --"Common > sense is the least most common thing"-- just look around at the > responses here. Might hold true for some rants, but most of it's tl;dr drivel. For instance, his critique of Lisp's homoiconicity is completely off-target. > I come from a different world than IT, and I thought initially the IT > world would be filled with intelligent, free thinking, and open minded > people... BOY was i wrong! I would not turn my back on these people > for a second, lest you catch a knife in it! So-called "IT" is driven by capitalistic impulses. Dijkstra and his followers get dismissed as ivory tower intellectuals. FUT warning. -- You only have power over people so long as you don?t take everything away from them. But when you?ve robbed a man of everything he?s no longer in your power ? he?s free again. -- Aleksandr Isayevich Solzhenitsyn From rt8396 at gmail.com Thu Jan 1 12:50:57 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 09:50:57 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <39d1883d-fb26-41cd-8de3-9185760445f7@f13g2000yqj.googlegroups.com> On Jan 1, 2:05?am, Jason Rumney wrote: > On Jan 1, 3:12?pm, r wrote: > > > The man lives in a world driven by common sense > > "Common" sense suggests that his views are shared among the general > populace. I don't see much evidence of that in the sometimes never- > ending threads that frequently follow his postings. But it is good to > start debates about making changes to the status quo, often the > debates will result in worthwhile changes, even if those changes are > not what he proposed. I just wish he would choose his venue a little > more carefully sometimes. I think if you will consider society as a whole, you will see that most people don't display much sense at all. "Joe Blow" only cares about paris hilton, britney spears, or janet jackson wardrobe malfunctions. The only thing they contribute to society is human excrement. So --"Common sense is the least most common thing"-- really means there exists no sense as a commonality. This can apply to higher educated people too, even Guido. Go and read Xahs take on the Python official tutorial, you will find your self agreeing with everything that he says. Guido filled it with so much fluff and off topic BS, causing the learning process to shut down. The only kind of person that might find it enjoying would be a fellow Computer Science Graduate. I did not know it at the time but this contributed to my late understanding of classes and regexes. And being such a fanboy of Python and carrying such a high respect for Guido that is hard for me to say, BUT it is the TRUTH nonetheless. Guido has no business writing tutorials anymore, WHY you ask. Because he is too smart, and too much on the inside. He cannot relate to the n00b pythoneer, he has crossed the Rubicon. Less fluff more simple examples are the key to quick learning. My love for python has blinded me to some of the atrocities that exist here. I have many more examples from the Official-TUT than Xah covered. Don't take my word, judge for yourself... http://xahlee.org/perl-python/xlali_skami_cukta.html here is Xah's take on OOP, very good reading for beginners and Gurus... http://xahlee.org/Periodic_dosage_dir/t2/oop.html If all Xah did was come here and say "Hey, python sucks donkey dicks!", i would pay him no mind. But he brings much intelligence, and vigor to an otherwise boring, and sometimes mindless newsgroup. What i like about him is his out-side-the-box thinking style. He does not give in to this BS "Proper Society" wants to push onto us. He is a real rebel, but WITH a cause! And the cause is to bring common sense back to a world of fluff an BS jargonisms. I don't always agree with his thoughts, but most the time he's spot on. Open your min c.l.py. Lest it close forever. eliminate the life decline... its time to change... can't stay the same... Revolution is my name! -Phil Anselmo- From wicijowski at gmail.com Thu Jan 1 12:52:45 2009 From: wicijowski at gmail.com (janislaw) Date: Thu, 1 Jan 2009 09:52:45 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <9b40ed7a-cfde-4c00-8685-913c1a3889f9@r15g2000prd.googlegroups.com> On 1 Sty, 12:37, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. If I were to write a python game that ran in a _browser_ I'd go for jython applet. JW From tjreedy at udel.edu Thu Jan 1 13:01:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jan 2009 13:01:03 -0500 Subject: Videocapture in python In-Reply-To: References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> <6s423rF44m1hU1@mid.uni-berlin.de> Message-ID: koranthala at gmail.com wrote: > It is taken from http://videocapture.sourceforge.net/, - a very > good tool for webcam capture in Win32. > Hi David, > I am in Windows. And there is a possibility that I might be using > device 0 or 1. So, I am using the excellent VideoCapture tool created > by Markus Gritsch. Does the capture software require 2.4? Given " I actually would like to have the code as try: obj.img = cam.getImage(timestamp=3) except CamException: setup_cam() But, since no exception is provided, " I do not think the tool is so excellent. It should either return a picture or raise and exception. Request that of the author. From gliderman at none Thu Jan 1 13:01:48 2009 From: gliderman at none (gliderman) Date: Thu, 01 Jan 2009 19:01:48 +0100 Subject: python and gloox Message-ID: <495d04f4$0$19294$426a34cc@news.free.fr> Hi I am trying to use a python version of gloox (XMPP client library written in C++). The python binding is done using SWIG (provided by the author of gloox). I am trying to adapt first a c++ example to python. The code below fails with Traceback (most recent call last): File "tutu.py", line 54, in ? t.run() File "tutu.py", line 28, in run self.f = gloox.SIProfileFT( self.c, self ) File "/home/karim/boulot/gliders/archi/project//lib/python2.4/site-packages/gloox/gloox.py", line 1965, in __init__ this = _gloox.new_SIProfileFT(*args) NotImplementedError: Wrong number of arguments for overloaded function 'new_SIProfileFT'. Possible C/C++ prototypes are: gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *,gloox::SIManager *,gloox::SOCKS5BytestreamManager *) gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *,gloox::SIManager *) gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *) If I comment gloox.LogHandler.__init__( self ) (and self.c.logInstance().registerLogHandler( gloox....), it "works". The order to initialize the objects seems to be important. The error can differ with the order of __init__ . Moreover when I replace C++ : m_s5b->registerSOCKS5BytestreamDataHandler( this ); by its python version: self.m_s5b.registerSOCKS5BytestreamDataHandler(self) a pointer object in m_s5b is always null (it shouldnt). There is no constructor in c++ classes SIProfileFTHandler,LogHandler,ConnectionListener, SOCKS5BytestreamDataHandler (almost pure virtual). import gloox import sys import os class MyClient( gloox.SIProfileFTHandler,gloox.LogHandler,gloox.ConnectionListener,gloox.SOCKS5BytestreamDataHandler): def __init__( self ): gloox.ConnectionListener.__init__( self ) gloox.SOCKS5BytestreamDataHandler.__init__( self ) gloox.SIProfileFTHandler.__init__( self ) gloox.LogHandler.__init__( self ) self.j = gloox.JID( "test at localhost/yop" ) self.c = gloox.Client( self.j, 'test' ) self.f=None def run(self): self.c.registerConnectionListener(self ) self.c.logInstance().registerLogHandler( gloox.LogLevelDebug, gloox.LogAreaAll,self) m_server=gloox.SOCKS5BytestreamServer( self.c.logInstance(), 6666 ) le = m_server.listen() if le != gloox.ConnNoError: print( "listen returned: %d\n"% le) print( "listening\n" ) self.f = gloox.SIProfileFT( self.c, self ) self.f.registerSOCKS5BytestreamServer( m_server ) self.f.addStreamHost( gloox.JID("jabberd"), "127.0.0.1", 7777 ); b = self.c.connect( False ) if b: print 'successfully connected' ce = gloox.ConnNoError while ce == gloox.ConnNoError: ce = self.c.recv( 1 ) return def handleLog(self,level,area,message): print("log: level: %d, area: %d, %s\n", level, area, message ) def onConnect(self): print( "connected!!!\n" ) def onDisconnect(self, e ): print( "ft_send: disconnected: %d\n"% e ) if e == gloox.ConnAuthenticationFailed : print( "auth failed. reason: %d\n"% c.authError() ) ########################################################### t = MyClient() t.run() Thanks for any hint (and happy new year !) Karim From python.list at tim.thechases.com Thu Jan 1 13:03:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 01 Jan 2009 12:03:46 -0600 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> Message-ID: <495D0582.4010002@tim.thechases.com> Sebastian Bassi wrote: > On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: >> I have a very big text file: I need to find the place where the last line >> begins (namely, the offset of the one-before-the-last '\n' + 1). >> Could you suggest a way to do that without getting all the file into memory >> (as I said, it's a big file), or heaving to readline() all lines (ditto) ? > > for line in open(filename): > lastline = line > print "the lastline is: %s",%lastline > > This will read all the lines, but line by line, so you will never have > the whole file in memory. > There may be more eficient ways to do this, like using the itertools. I think the OP wanted to do it without having to touch each line in the file. The following should do the trick, returning both the offset in the file, and that last line's content. from os import stat def last_line(fname, estimated_line_size=1024): assert estimated_line_size > 0 file_size = stat(fname).st_size if not file_size: return 0, "" f = file(fname, 'rb') f.seek(-1, 2) # grab the last character if f.read(1) == '\n': # a "proper" text file file_size -= 1 offset = file_size content = "" while offset >= 0 and '\n' not in content: offset -= estimated_line_size if offset < 0: estimated_line_size += offset # back it off offset = 0 f.seek(offset) block = f.read(estimated_line_size) content = block + content f.close() loc = content.rfind('\n') + 1 # after the newline return offset + loc, content[loc:] offset, line = last_line('some_file.txt') print "[%r] was found at offset %i" % (line, offset) In theory, it should even handle "malformed" text-files that don't end in a newline. There might be some odd edge-cases that I missed, but I think I caught most of them. -tkc From geert.discussions at gmail.com Thu Jan 1 13:05:29 2009 From: geert.discussions at gmail.com (Geert Vancompernolle) Date: Thu, 01 Jan 2009 19:05:29 +0100 Subject: How to run Python in Windows w/o popping a DOS box? Message-ID: <495D05E9.4000004@gmail.com> I know it's been a long while since this thread has been handled, but maybe this is a "final" solution to your problem (if not yet resolved): http://www.py2exe.org/index.cgi/SingleFileExecutable Especially the last setup.py file results in only one exe which contains *all* the necessary stuff (only tested it on small examples, though) Maybe you can give this a try... Best rgds, --Geert * * From mmanns at gmx.net Thu Jan 1 13:12:26 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Thu, 1 Jan 2009 19:12:26 +0100 Subject: Testing if an index is in a slice Message-ID: <20090101191226.5137adb6@Schlamber.localdomain> Hi I would like to check if an index is in a slice or not without iterating over the slice. Something like: >>> isinslice(36, slice(None, 34, -1)) True I would like to use the batteries if possible. However, I looked in the docs, pypi and in Usenet without luck. Does anyone have a solution? Martin From davidalvi at gmail.com Thu Jan 1 13:13:07 2009 From: davidalvi at gmail.com (davidalvi at gmail.com) Date: Thu, 1 Jan 2009 10:13:07 -0800 (PST) Subject: Is this a bug in Python or something I do not understand. Message-ID: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Consider these two lists comprehensions: L1=[[1 for j in range(3)] for i in range(3)] L2=[[1]*3]*3 print L1 print L2 print L1==L2 The result is: [[1, 1, 1], [1, 1, 1], [1, 1, 1]] [[1, 1, 1], [1, 1, 1], [1, 1, 1]] True So far, everything is OK, but let us now modify the lists' contents in the following way: for i in range(3): for j in range(3): if j References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: koranthala at gmail.com wrote: >>> Module database: >>> ^^^^^^^^^^^^^^^^^^^ >>> Session = None 'Initializing' names is not necessary. Delete this. Without it, your error would be more obvious. >>> def init(dbname): >>> engine = create_engine('sqlite:///%s' %dbname) >>> ... >>> global Session >>> Session = sessionmaker(bind=engine) This **rebinds* the module name 'Session' to a new object, making the initial bindin irrelevant and misleading. [snip] > > I guessed as much. But, I was under the impression that if the > original value is modified, the variables value also will change. Python has names and slots bound to objects. Some objects are mutable and some not. None is not mutable. You replaced it. If you had done something like Session = sessionmaker() def init(dbname): Session.engine = create_engine('sqlite:///%s' %dbname) ... then you would have *modified* the original object (value) bound to 'Session' and would have seen the behavior you expected. Terry Jan Reedy From mmanns at gmx.net Thu Jan 1 13:15:00 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Thu, 1 Jan 2009 19:15:00 +0100 Subject: Testing if an index is in a slice Message-ID: <20090101191500.27ca3cce@Schlamber.localdomain> Hi I would like to check if an index is in a slice or not without iterating over the slice. Something like: >>> isinslice(36, slice(None, 34, -1)) True I would like to use the batteries if possible. However, I looked in the docs, pypi and in Usenet without luck. Does anyone have a solution? Martin From jurgenex at hotmail.com Thu Jan 1 13:17:54 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 10:17:54 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: r wrote: [Why not Ruby?] Becasue it is off topic in CL.perl.M just as in any other NG he posted to. >Face it, the world needs people like Xah. Go check out his site, his Oh my good, the idiot discovered alter egos. >There is nothing wrong with a person expressing their opinion on any >subject. Apparently some of you need to get laid and calm down a >little. Xah has just as much right as anyone here to post his >thoughts, even if they are off topic. Exactly everyone's point. He has exactly the same right as anybody else which is exactly that NOBODY has the "right" to post off topic posts. Sometimes they may be tolerated, on rare, special occasions even be welcome. But by and large they are as disturbing as playing 'Love me tender' during a perfomance of the Walkuere. I don't want to hear Elvis, I paid my money for Wagner! If I wanted to listen to Elvis, then I would go to an Elvis concert. >Look, if you don't like what he >is saying, DON'T F'IN READ IT! He has been plonked a loooooooong time ago. It's just he newcomers, who still respond to him. And no his alter ego with the unpronouncable name of rt8396. >Xah, I been watching your posts for sometime and it looks like you >have been around for a while. Your profile shows one star & 410 >ratings. I have only been in usenet for 2 month and i have one star >and 253 ratings(that will grow to much more after this post), most are There are neither profiles nor stars or ratings on Usenet. Keep you made-up nonsense to yourself. jue From semanticist at gmail.com Thu Jan 1 13:20:51 2009 From: semanticist at gmail.com (Miles) Date: Thu, 1 Jan 2009 13:20:51 -0500 Subject: Is this a bug in Python or something I do not understand. In-Reply-To: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 1:13 PM, wrote: > Consider these two lists comprehensions: > > L1=[[1 for j in range(3)] for i in range(3)] > L2=[[1]*3]*3 > [snip] > > It seems a misbehaviour in Python, or there is something I do not > understand in the syntax ???? It's not a Python bug. Does this help illuminate the difference? >>> L1 = [object() for j in range(3)] >>> L2 = [object()] * 3 >>> [id(o) for o in L1] [164968, 164976, 164984] >>> L1[0] is L1[1] False >>> [id(o) for o in L2] [164992, 164992, 164992] >>> L2[0] is L2[1] True -Miles From tjreedy at udel.edu Thu Jan 1 13:22:34 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jan 2009 13:22:34 -0500 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: alex goretoy wrote: > I recently conquered this pass by ref thing. This is how I did it. What you did was to pass a mutable object and mutate it. Absolutely standard practice in Python. I am glad you learned it, but also learning and using the standard terminology will also help. Hope you enjoy Python too. tjr From rt8396 at gmail.com Thu Jan 1 13:35:54 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 10:35:54 -0800 (PST) Subject: Why not Ruby? References: Message-ID: Xah Lee, > I also didn't like the fact that ruby uses keyword "end" to indicate > code block much as Pascal and Visual Basic, Logo, do. I don't like > that. You could not be more right Xah, the use of "end" in a language as high level as Ruby is redundant, and idiotic. There are a few things about Ruby i really like, but this "end" business is blasphemy. If ruby did not use indentation, i would see the need for "end", or braces, or whatever, but why use both indentation AND the "end" word? Such stupidity. I guess Mats thought Ruby would look too much like Python, ARE YOU KIDDING MATS?, you already took so much from Python anyway, dropping the end statement won't change that. And heck, you will gain many new users with out it's archaic redundancy!!!! I must say at first i did not like the each method but it has grow on me because of its space saving attributes. There are also some nice shortcuts in Ruby that do not exist in Python. I am beginning to think the perfect high level language would take the best for Ruby and Python. The ultimate language with speed in mind, pythons clear syntax, but with shortcuts for gurus. I would probably lean more towards python scoping and classes than ruby, but python classes need a little less redundancy also. Of course pythons list, dict, strings in my opinion just can't be beat, and regex forget-a-about-it! Python rules here. Even though Ruby has built in support, python's is much more elegant. I really like pythons handling of modules and module.class.method syntax. Both languages have much to offer, i believe though Python has a better base, it just needs some cleaning up, and shortcut syntax so moderate/Gurus don't develop carpal tunnel too early :) From geert.discussions at gmail.com Thu Jan 1 13:45:55 2009 From: geert.discussions at gmail.com (GeertVc) Date: Thu, 1 Jan 2009 10:45:55 -0800 (PST) Subject: How to run Python in Windows w/o popping a DOS box? References: Message-ID: <34e493fd-3a2a-49df-8b82-74f87c46cf9b@r36g2000prf.googlegroups.com> On Jan 1, 7:05?pm, Geert Vancompernolle wrote: > I know it's been a long while since this thread has been handled, but > maybe this is a "final" solution to your problem (if not yet resolved): > > http://www.py2exe.org/index.cgi/SingleFileExecutable > > Especially the last setup.py file results in only one exe which contains > *all* the necessary stuff (only tested it on small examples, though) > > Maybe you can give this a try... > > Best rgds, > --Geert > * > * Might seem an "odd" posting at first, but I wanted to reply on a (quite) old thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/456bc00fa11f689/b4357c9aa47f04d3?lnk=gst&q=dos+box+remove I couldn't reply any more on that one, so... Best rgds, --Geert From rtomek at ceti.com.pl Thu Jan 1 14:08:34 2009 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Thu, 1 Jan 2009 20:08:34 +0100 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> Message-ID: On Thu, 1 Jan 2009, sln at netherlands.com wrote: > On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton wrote: > > >Xah Lee wrote: > >> Just spent 3 hours looking into Ruby today. Here's my short impression > >> for those interested. > >> > > Be carefull what you say. If they pay me I would rip your and Xah's > guts out in a second. > > sln Too much champagne? A guy (XL) is sometimes off topic and I don't always agree with his postings - if I find the subject somewhat worthy, I usually skim through it, this is how I have found myself knee deep in this strange exchange between XL's supporters and opponents. And his website is big like a magazine and full of strange, sometimes not interesting or hard to assess stuff (it needs time to read and time is hard to find nowadays). But sometimes, what he writes is informative, too. A bit redundant but still, I would give him a small "plus", rather than "zero" or "minus". But I do not remember him being blunt or agressive. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From metolone+gmane at gmail.com Thu Jan 1 14:12:44 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 1 Jan 2009 11:12:44 -0800 Subject: idle 3.0 unicode References: <495C7AC6.1000506@post.cz> Message-ID: "Pavel Kosina" wrote in message news:495C7AC6.1000506 at post.cz... > As for unicode in Python 2.5 everything works fine in program running > either in IDLE or under Command line: > # -*- coding: utf-8 -*- > print u"?????????" > > In 3.0 there is an error. The same program, moved to 3.0 syntax, in IDLE > editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program running in Command line from PSPad editor works fine. Is > it mistake of my misunderstanding or of IDLE? > > ------------- > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. Both versions, with and without 'coding' line, destroy IDLE for me. Looks like a bug in IDLE 3.0. The print works fine from the shell, but not from a program run with F5. -Mark From ajaksu at gmail.com Thu Jan 1 14:34:53 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 1 Jan 2009 11:34:53 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 1, 4:12?pm, mma... at gmx.net wrote: > I would like to check if an index is in a slice or not without > iterating over the slice. > > Something like: > > >>> isinslice(36, slice(None, 34, -1)) > > True I think it'd be feasible for slices that can be mapped to ranges[1], but slices are more flexible than that. What would the answer be for: >>> isinslice(36, slice(0, -1, 1)) ? This shows the issue: >>> sli = slice(0, -1, 1) >>> range(4)[sli] [0, 1, 2] >>> range(10)[sli] [0, 1, 2, 3, 4, 5, 6, 7, 8] HTH, Daniel [1] http://article.gmane.org/gmane.comp.python.python-3000.devel/8732 From kay.schluehr at gmx.net Thu Jan 1 14:37:44 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 1 Jan 2009 11:37:44 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: On 1 Jan., 12:37, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. There is no solution to this problem from a Python perspective. Do what everyone does right now: use Flash for the game and manage your site with Python if you like the language. From excord80 at gmail.com Thu Jan 1 15:24:38 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 12:24:38 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> On Jan 1, 2:37?pm, Kay Schluehr wrote: > There is no solution to this problem from a Python perspective. Do > what everyone does right now: [snip] It still surprises me that no one has implemented the solution for this yet. Maybe it's harder than it seems, but it *seeems* like it's just a matter of telling Firefox, "hey, when you see this special html element that tells you to run this python code from the web, do it". Then have FF load up a python interpreter, sandbox it somehow (that is, limit it to only a safe subset of its std lib), it runs the code within its region of the browser window, and Bob's your uncle. People would go bonkers for that. From excord80 at gmail.com Thu Jan 1 15:29:33 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 12:29:33 -0800 (PST) Subject: Chart libs for python References: <4a8c13a2-a2ae-4815-9560-8e1ef1e21f97@i24g2000prf.googlegroups.com> Message-ID: <5d0f7788-2a28-4eb0-bb2a-22371ac7b236@m2g2000vbp.googlegroups.com> You might start by having a look at the wiki: http://wiki.python.org/moin/NumericAndScientific/Plotting From darcy at PyGreSQL.org Thu Jan 1 15:29:37 2009 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Thu, 1 Jan 2009 15:29:37 -0500 Subject: Release of PyGreSQL 4.0 Message-ID: <20090101152937.bf8ca6c3.darcy@PyGreSQL.org> We are please to announce the release of PyGreSQL 4.0. his is a major release and you should check it carefully before using in existing applications. There may be some incompatibilities. PyGreSQL is a Python module that interfaces to a PostgreSQL database. It embeds the PostgreSQL query library to allow easy use of the powerful PostgreSQL features from a Python script. For more information, please visit http://www.PyGreSQL.org/. >From the changelog: - Dropped support for Python below 2.3 and PostgreSQL below 7.4. - Improved performance of fetchall() for large result sets by speeding up the type casts (as suggested by Peter Schuller). - Exposed exceptions as attributes of the connection object. - Exposed connection as attribute of the cursor object. - Cursors now support the iteration protocol. - Added new method to get parameter settings. - Added customizable row_factory as suggested by Simon Pamies. - Separated between mandatory and additional type objects. - Added keyword args to insert, update and delete methods. - Added exception handling for direct copy. - Release the GIL while making a connection (as suggested by Peter Schuller). - If available, use decimal.Decimal for numeric types. - Allow DB wrapper to be used with DB-API 2 connections (as suggested by Chris Hilton). - Made private attributes of DB wrapper accessible. - Dropped dependence on mx.DateTime module. - Support for PQescapeStringConn() and PQescapeByteaConn(); these are now also used by the internal _quote() functions. - Added 'int8' to INTEGER types. New SMALLINT type. - Added a way to find the number of rows affected by a query() with the classic pg module by returning it as a string. For single inserts, query() still returns the oid as an integer. The pgdb module already provides the "rowcount" cursor attribute for the same purpose. - Improved getnotify() by calling PQconsumeInput() instead of submitting an empty command. - Removed compatibility code for old OID munging style. - The insert() and update() methods now use the "returning" clause if possible to get all changed values, and they also check in advance whether a subsequent select is possible, so that ongoing transactions won't break if there is no select privilege. - Added "protocol_version" and "server_version" attributes. - Revived the "user" attribute. - The pg module now works correctly with composite primary keys; these are represented as frozensets. - Removed the undocumented and actually unnecessary "view" parameter from the get() method. - get() raises a nicer ProgrammingError instead of a KeyError if no primary key was found. - delete() now also works based on the primary key if no oid available and returns whether the row existed or not. -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org From http Thu Jan 1 15:32:53 2009 From: http (Paul Rubin) Date: 01 Jan 2009 12:32:53 -0800 Subject: Why not Ruby? References: Message-ID: <7xr63m3gy2.fsf@ruckus.brouhaha.com> r writes: > I am beginning to think > the perfect high level language would take the best for Ruby and > Python. The ultimate language with speed in mind, pythons clear > syntax, but with shortcuts for gurus. You might like Tim Sweeney's POPL talk: http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf > Of course pythons list, dict, strings in my opinion just can't be beat, On many occasions I've wished for a functional dictionary implementation in Python, like Haskell's Data.Map. One of these years I'll get around to writing one. From clp at rebertia.com Thu Jan 1 15:55:06 2009 From: clp at rebertia.com (Chris Rebert) Date: Thu, 1 Jan 2009 12:55:06 -0800 Subject: If your were going to program a game... In-Reply-To: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <47c890dc0901011255s1b9ed128kcaada3de6f16be1@mail.gmail.com> On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > On Jan 1, 2:37 pm, Kay Schluehr wrote: > >> There is no solution to this problem from a Python perspective. Do >> what everyone does right now: [snip] > > It still surprises me that no one has implemented the solution for > this yet. > > Maybe it's harder than it seems, but it *seeems* like it's just a > matter of telling Firefox, "hey, when you see this special html > element that tells you to run this python code from the web, do it". > Then have FF load up a python interpreter, sandbox it somehow (that > is, limit it to only a safe subset of its std lib), it runs the code The "sandbox it somehow" part is significantly harder than you seem to believe it would be. Python tried previously with the rexec and Bastion modules, but they were found to be irreparably flawed and thus were removed. However, Google App Engine seems to have found at least a partial solution, but they're keeping it to themselves as far as I know, and it's server-side rather than client-side anyway. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From clp at rebertia.com Thu Jan 1 16:00:25 2009 From: clp at rebertia.com (Chris Rebert) Date: Thu, 1 Jan 2009 13:00:25 -0800 Subject: Is this a bug in Python or something I do not understand. In-Reply-To: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: <47c890dc0901011300i309055abn6607dc1c626da0a@mail.gmail.com> On Thu, Jan 1, 2009 at 10:13 AM, wrote: > Consider these two lists comprehensions: > > L1=[[1 for j in range(3)] for i in range(3)] > L2=[[1]*3]*3 > So far, everything is OK, but let us now modify the lists' contents in > the following way: > It seems a misbehaviour in Python, or there is something I do not > understand in the syntax ???? The latter, and it's a FAQ. Please read http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list (it's question 4.6). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Caseyweb at gmail.com Thu Jan 1 16:03:59 2009 From: Caseyweb at gmail.com (Casey) Date: Thu, 1 Jan 2009 13:03:59 -0800 (PST) Subject: Is this a bug in Python or something I do not understand. References: <802fc799-445d-460d-90a4-af080e158d4c@w1g2000prm.googlegroups.com> Message-ID: <723622f6-d03d-4ccf-9342-bd96909b5f9b@v42g2000yqv.googlegroups.com> L1 is a list of three different lists, although each list holds the same values. L2 is a list of three references to the same list (the '*' operator doesn't do a deep copy). So when you modify any of the referenced lists, you modify all of them. Try this: >>> q = [1, 1, 1] >>> r = [q, q, q] >>> r [[1, 1, 1], [1, 1, 1], [1, 1, 1]] >>> r[0][0] = 999 >>> r [[999, 1, 1], [999, 1, 1], [999, 1, 1]] Regards, Casey From fuzzyman at gmail.com Thu Jan 1 16:13:19 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 13:13:19 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> Message-ID: <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> On Jan 1, 8:32?pm, Paul Rubin wrote: [snip...] > > Of course pythons list, dict, strings in my opinion just can't be beat, > > On many occasions I've wished for a functional dictionary > implementation in Python, like Haskell's Data.Map. ?One of these years > I'll get around to writing one. Care to save me the effort of looking it up and tell me what Data.Map does that Python's dict doesn't? I guess if it is functional then every mutation must copy and return a new data structure? (Which will be much more efficient in Haskell than in Python - Haskell can share most of the underlying data whereas Python would have to create a new dict every time. At least it only stores references.) Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Thu Jan 1 16:18:40 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 13:18:40 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <60d98b76-344e-4d94-a39c-28d06f1b46d1@35g2000pry.googlegroups.com> On Jan 1, 8:55?pm, "Chris Rebert" wrote: > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > >> There is no solution to this problem from a Python perspective. Do > >> what everyone does right now: [snip] > > > It still surprises me that no one has implemented the solution for > > this yet. > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > matter of telling Firefox, "hey, when you see this special html > > element that tells you to run this python code from the web, do it". > > Then have FF load up a python interpreter, sandbox it somehow (that > > is, limit it to only a safe subset of its std lib), it runs the code > > The "sandbox it somehow" part is significantly harder than you seem to > believe it would be. Python tried previously with the rexec and > Bastion modules, but they were found to be irreparably flawed and thus > were removed. > However, Google App Engine seems to have found at least a partial > solution, but they're keeping it to themselves as far as I know, and > it's server-side rather than client-side anyway. > PyPy allows *true* sandboxing, as does IronPython through AppDomains. I wouldn't recommend either for 'in the browser' use though. You can do client side programming in the browser with Silverlight. It's great fun to program, and very flexible, but limited to Safari, IE & Firefox on Mac and Windows. Moonlight is making good progress which will bring Silverlight to Firefox on Linux - and eventually more browsers and platforms. Michael Foord -- http://www.ironpythoninaction.com/ From castironpi at gmail.com Thu Jan 1 17:13:42 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:13:42 -0800 (PST) Subject: game engine (as in rules not graphics) References: <402f625f-b835-4cb8-bcea-523756c489ca@g39g2000pri.googlegroups.com> Message-ID: <8fc5f865-43cf-4c5c-9c8e-1d6d6b06602c@t39g2000prh.googlegroups.com> On Dec 29 2008, 8:52?am, Aaron Brady wrote: > On Dec 29, 4:14?am, Martin wrote: > > > Hi, > > > 2008/12/29 Phil Runciman : > > > > See: Chris Moss, Prolog++: The Power of Object-Oriented and Logic Programming (ISBN 0201565072) > > > > This book is a pretty handy intro to an OO version Prolog produced by Logic Programming Associates. > > > From: Aaron Brady [mailto:castiro... at gmail.com] > > > Sent: Sunday, 28 December 2008 1:22 p.m. > > > Not my expertise but here are my $0.02. ?You are looking for ways to represent rules: buying a house is legal in such and such situation, and the formula for calculating its price is something. ?You want "predicates" such as InJail, OwnedBy, Costs. > > > > Costs( New York Ave, 200 ) > > > InJail( player2 ) > > > OwnedBy( St. Charles Ave, player4 ) > > > LegalMove( rolldie ) > > > LegalMove( sellhouse ) > > > I'm not sure I'm looking for prolog, i had an introductory course back > > at the university but it didn't exactly like it. I'm after some info > > how such rules would defined in python (specifically python althou > > logic programming is probably the more appropriate way). > > > I guess I'm missing quite some basics in the design of such concepts, > > I'll head back to google to find some introductory stuff now :). > > snip > > It depends on what you want to do with it. ?Do you want to answer a > question about whether something is legal? ?Do you want a catalog of > legal moves? ?Do you want to forward-chain moves to a state? ?Do you > want just a representation for its own sake? > > For instance, the game just started. ?Player 1 landed on Oriental, > bought it, and Player 2 landed in the same place. ?Here are the legal > possibilities. > > Player 1 offers to sell Oriental to Player X. > Player X offers to buy Oriental from Player 1. > Player 1 mortgages Oriental. > Player 1 collects rent from Player 2. > Player 3 rolls dice. > > Thinking aloud, I think the closest thing to predicates you'll have in > Python is to build a Relation class or use a relational database. > Some tables you might use are: Property( id, name, price, rent0houses, > rent1house, ..., numhouses, mortgaged, owner ). ?Player( id, location, > money ). ?LastMove( player.id ). > > P.S. ?There is 'pyprolog' on sourceforge; I did not check it out. You know what I am thinking for this-- not that the OP is still around-- is a regular expression / BNF grammar that transitions on moves from one legal set of moves to the next. It will need some sort of concatenation structure, since late in the game, selling each property a player has is a legal move. Sorry for the replies to myself. From castironpi at gmail.com Thu Jan 1 17:17:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:17:40 -0800 (PST) Subject: SQL, lite lite lite References: <39322fe4-e606-42dc-9123-71751258c3ae@a12g2000pro.googlegroups.com> <8da5c6b1-951f-4abd-8ee7-07b63802b9f6@13g2000yql.googlegroups.com> <186e44f7-f949-45e2-b1e2-a913560acf94@s9g2000prg.googlegroups.com> <495a97ce$0$25469$426a74cc@news.free.fr> <495cd630$0$17993$426a74cc@news.free.fr> Message-ID: On Jan 1, 7:43?am, Bruno Desthuilliers wrote: > Aaron Brady a ?crit : > > > > > On Dec 30, 2:52 pm, Bruno Desthuilliers > > wrote: > >> Aaron Brady a ?crit : > > >>> On Dec 30, 11:16 am, prueba... at latinmail.com wrote: > >> (snip) > >>>> You really do like to reinvent the wheels do you? :-) Nothing wrong > >>>> with that. Just be aware that most people that really need what you > >>>> are proposing are probably already using mature feature rich libraries > >>>> for that. > >>>>http://wiki.python.org/moin/HigherLevelDatabaseProgramming > >>> Look at these options! ?Who invents the wheel? ?Naturally, I've had > >>> time to master every one. > >> Oh, so that's why you propose to add yet another item to the list ? > > > Aha, so it is. ?Your criticism might seem harsh, > > This was mostly a tentative to make you notice that it might be better > to check out the existing solutions and possibly contribute to one of > them instead of inventing yet another one... > > > but it has an > > advantage. ?It made me get the lead out, that is, think. > > (snip) > > ... but it obviously failed. You have to admit that mine is simpler than a Django statement. If they want to use it, that's fine with me, but I have to invent it first. That's the reason I'm sharing on a newsgroup. Recap: An ADAPTER from a Django class into something simpler and less functional. From castironpi at gmail.com Thu Jan 1 17:24:02 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:24:02 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> On Jan 1, 2:55?pm, "Chris Rebert" wrote: > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > >> There is no solution to this problem from a Python perspective. Do > >> what everyone does right now: [snip] > > > It still surprises me that no one has implemented the solution for > > this yet. > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > matter of telling Firefox, "hey, when you see this special html > > element that tells you to run this python code from the web, do it". > > Then have FF load up a python interpreter, sandbox it somehow (that > > is, limit it to only a safe subset of its std lib), it runs the code > > The "sandbox it somehow" part is significantly harder than you seem to > believe it would be. Python tried previously with the rexec and > Bastion modules, but they were found to be irreparably flawed and thus > were removed. Suppose you compiled a version with no file type and a reduced os module? From larrydag at sbcglobal.net Thu Jan 1 17:24:05 2009 From: larrydag at sbcglobal.net (larrydag) Date: Thu, 1 Jan 2009 14:24:05 -0800 (PST) Subject: OpenOpt 0.21 (free optimization framework) References: Message-ID: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> On Dec 15 2008, 4:32?pm, dmitrey wrote: > Hi all, > OpenOpt 0.21, free optimization framework (license: BSD) with some own > solvers and connections to tens of 3rd party ones, has been released. > > All details here: > > http://openopt.blogspot.com/2008/12/openopt-release-021.html > > Regards, OpenOpt developers. Demitry, I love hearing about new implementations of free and open source operations research software. In fact I've made an update to my blog to notify about your new release. I suggest you may want to make an announcement at the comp.lang.python Usenet group. You could probably get some interest in python development from that group. Larry http://industrialengineertools.blogspot.com/ From castironpi at gmail.com Thu Jan 1 17:27:45 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 1 Jan 2009 14:27:45 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 1, 12:12?pm, mma... at gmx.net wrote: > Hi > > I would like to check if an index is in a slice or not without > iterating over the slice. > > Something like: > > >>> isinslice(36, slice(None, 34, -1)) > > True > > I would like to use the batteries if possible. > However, I looked in the docs, pypi and in Usenet without luck. > > Does anyone have a solution? > > Martin Untested: if slice.end< 0: slice.end= len( obj )- slice.end+ 1 if slice.step< 0 and slice.start<= target< slice.end: return True if slice.step> 0 and slice.start>= target> slice.end: return True return False From rileyrgdev at gmail.com Thu Jan 1 17:28:08 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:28:08 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: Jason Rumney writes: > On Jan 1, 3:12?pm, r wrote: > >> The man lives in a world driven by common sense > > "Common" sense suggests that his views are shared among the general > populace. I don't see much evidence of that in the sometimes never- > ending threads that frequently follow his postings. But it is good to > start debates about making changes to the status quo, often the > debates will result in worthwhile changes, even if those changes are > not what he proposed. I just wish he would choose his venue a little > more carefully sometimes. I find that with Xah's posts people argue the man and not his points. And they argue the man because he refuses to be brow beaten by those who do not like to be criticised or are too think skinned. I rarely find his posts controversial but always interesting. His ELisp tutorial is far and away better than anything else out there for the programmer moving to Elisp IMO. He backs up his points with reasons and supportive evidence and rarely with "because I'm experienced and thats the way it is" - something not every one takes the time to do. He is clearly intelligent, thoughtful and experienced if a little lacking in finesse at times. The world needs more Xah lees. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From fuzzyman at gmail.com Thu Jan 1 17:28:35 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 14:28:35 -0800 (PST) Subject: If your were going to program a game... References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> Message-ID: <370a021b-aaba-4aae-8f89-605f6229cf8a@n33g2000pri.googlegroups.com> On Jan 1, 10:24?pm, Aaron Brady wrote: > On Jan 1, 2:55?pm, "Chris Rebert" wrote: > > > > > On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: > > > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > > >> There is no solution to this problem from a Python perspective. Do > > >> what everyone does right now: [snip] > > > > It still surprises me that no one has implemented the solution for > > > this yet. > > > > Maybe it's harder than it seems, but it *seeems* like it's just a > > > matter of telling Firefox, "hey, when you see this special html > > > element that tells you to run this python code from the web, do it". > > > Then have FF load up a python interpreter, sandbox it somehow (that > > > is, limit it to only a safe subset of its std lib), it runs the code > > > The "sandbox it somehow" part is significantly harder than you seem to > > believe it would be. Python tried previously with the rexec and > > Bastion modules, but they were found to be irreparably flawed and thus > > were removed. > > Suppose you compiled a version with no file type and a reduced os > module? How would it be able to import? (I realise there is an answer to that question, but it would require more changes than you might think.) Python uses Python - so pulling bits out tends to break things... Michael Foord -- http://www.ironpythoninaction.com/ From rileyrgdev at gmail.com Thu Jan 1 17:29:31 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:29:31 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <39d1883d-fb26-41cd-8de3-9185760445f7@f13g2000yqj.googlegroups.com> Message-ID: r writes: > On Jan 1, 2:05?am, Jason Rumney wrote: >> On Jan 1, 3:12?pm, r wrote: >> >> > The man lives in a world driven by common sense >> >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I think if you will consider society as a whole, you will see that > most people don't display much sense at all. "Joe Blow" only cares > about paris hilton, britney spears, or janet jackson wardrobe > malfunctions. The only thing they contribute to society is human > excrement. So --"Common sense is the least most common thing"-- really > means there exists no sense as a commonality. > > This can apply to higher educated people too, even Guido. Go and read > Xahs take on the Python official tutorial, you will find your self > agreeing with everything that he says. Guido filled it with so much > fluff and off topic BS, causing the learning process to shut down. The > only kind of person that might find it enjoying would be a fellow > Computer Science Graduate. I did not know it at the time but this > contributed to my late understanding of classes and regexes. And being > such a fanboy of Python and carrying such a high respect for Guido > that is hard for me to say, BUT it is the TRUTH nonetheless. Guido has > no business writing tutorials anymore, WHY you ask. Because he is too > smart, and too much on the inside. He cannot relate to the n00b > pythoneer, he has crossed the Rubicon. Less fluff more simple examples > are the key to quick learning. My love for python has blinded me to > some of the atrocities that exist here. I have many more examples from > the Official-TUT than Xah covered. > > Don't take my word, judge for yourself... > http://xahlee.org/perl-python/xlali_skami_cukta.html > > here is Xah's take on OOP, very good reading for beginners and > Gurus... > http://xahlee.org/Periodic_dosage_dir/t2/oop.html > > If all Xah did was come here and say "Hey, python sucks donkey > dicks!", i would pay him no mind. But he brings much intelligence, and > vigor to an otherwise boring, and sometimes mindless newsgroup. What i > like about him is his out-side-the-box thinking style. He does not > give in to this BS "Proper Society" wants to push onto us. He is a > real rebel, but WITH a cause! And the cause is to bring common sense > back to a world of fluff an BS jargonisms. I don't always agree with > his thoughts, but most the time he's spot on. Open your min c.l.py. > Lest it close forever. Great post and I agree with you 100%. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From rileyrgdev at gmail.com Thu Jan 1 17:34:43 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:34:43 +0100 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Tim Greer writes: > Giampaolo Rodola' wrote: > >> This is not a Ruby group. >> I recommend you to go waste your time there. > > That poster has a frequent habit of cross posting to multiple, > irrelevant news groups. There's no rhyme or reason to it. It's best > to just filter the guy's posts. No rhyme nor reason? It's quite clear, to me, why. How is a comparison article not relevant when he is trying to stimulate discussion about alternative languages for modern development? Most news readers feature a kill thread command if you are not interested in the content. Certainly less extreme or ignorant than killing all posts from someone who clearly has interesting things to say about development practises and tools. From tkpapp at gmail.com Thu Jan 1 17:36:28 2009 From: tkpapp at gmail.com (Tamas K Papp) Date: 1 Jan 2009 22:36:28 GMT Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <6s4urcF47nr3U2@mid.individual.net> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: > posts controversial but always interesting. His ELisp tutorial is far > and away better than anything else out there for the programmer moving > to Elisp IMO. He backs up his points with reasons and supportive Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity when you want to program Emacs. No one in his/her right mind would use it in any other context, as far better alternatives exist (eg CL for those who like Lisp). Tamas From rileyrgdev at gmail.com Thu Jan 1 17:38:43 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Thu, 01 Jan 2009 23:38:43 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Tamas K Papp writes: > On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: > >> posts controversial but always interesting. His ELisp tutorial is far >> and away better than anything else out there for the programmer moving >> to Elisp IMO. He backs up his points with reasons and supportive > > Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity > when you want to program Emacs. No one in his/her right mind would use > it in any other context, as far better alternatives exist (eg CL for > those who like Lisp). > > Tamas "move to Elisp" was clearly meant as "moving towards it in order to use it". In this case to modify emacs. And to suggest that jobs of work are not done in Emacs is ridiculous. I am at a loss to really understand what you mean here in the context. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From robert.kern at gmail.com Thu Jan 1 17:40:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 01 Jan 2009 17:40:32 -0500 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: Hamish McKenzie wrote: > sometimes I want to be able to initialize an instance with a variety of different data types. > > as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > > is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? I recommend keeping the __init__() as dumb as possible. Ideally, it should just assign to attributes. I would add a from() classmethod for each that I wanted to support. If I really wanted an all-singing, all-dancing initialization method, I would add another classmethod that would just dispatch to the appropriate type-specific classmethod. I prefer classmethods to plain functions because I can subclass. -- 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 hamish at valvesoftware.com Thu Jan 1 17:46:54 2009 From: hamish at valvesoftware.com (Hamish McKenzie) Date: Thu, 1 Jan 2009 14:46:54 -0800 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016be89e$0$6988$c3e8da3@news.astraweb.com> Message-ID: >> You could also use a dict with type:method key/value pairings. This is closer to a switch/case than an if...elif chain is. of course, that's a great idea... thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Thu Jan 1 17:47:49 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 1 Jan 2009 16:47:49 -0600 Subject: OpenOpt 0.21 (free optimization framework) In-Reply-To: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> References: <162d658f-6b92-4338-9357-9d22fedfcdd3@w1g2000prk.googlegroups.com> Message-ID: <18781.18453.704082.526949@montanaro-dyndns-org.local> Larry> I suggest you may want to make an announcement at the Larry> comp.lang.python Usenet group. You could probably get some Larry> interest in python development from that group. Larry, Apparently you read the python-list at python.org mailing list. That list is bidirectionally gatewayed with the comp.lang.python Usenet newsgroup. If OpenOpt was announced on the mailing list then it was also announced on the newsgroup. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From raw at RawMBP.local Thu Jan 1 17:51:30 2009 From: raw at RawMBP.local (Raymond Wiker) Date: Thu, 01 Jan 2009 23:51:30 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Richard Riley writes: > Tamas K Papp writes: > >> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: >> >>> posts controversial but always interesting. His ELisp tutorial is far >>> and away better than anything else out there for the programmer moving >>> to Elisp IMO. He backs up his points with reasons and supportive >> >> Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity >> when you want to program Emacs. No one in his/her right mind would use >> it in any other context, as far better alternatives exist (eg CL for >> those who like Lisp). >> >> Tamas > > "move to Elisp" was clearly meant as "moving towards it in order to use > it". In this case to modify emacs. And to suggest that jobs of work are > not done in Emacs is ridiculous. I am at a loss to really understand > what you mean here in the context. OK, how about this: Xah's elisp code stinks to high heaven. His code should not be studied by anybody who actually wants to actually learn elisp (or anything else). From benjamin.kaplan at case.edu Thu Jan 1 18:01:25 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 1 Jan 2009 18:01:25 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 5:28 PM, Richard Riley wrote: > Jason Rumney writes: > > > On Jan 1, 3:12 pm, r wrote: > > > >> The man lives in a world driven by common sense > > > > "Common" sense suggests that his views are shared among the general > > populace. I don't see much evidence of that in the sometimes never- > > ending threads that frequently follow his postings. But it is good to > > start debates about making changes to the status quo, often the > > debates will result in worthwhile changes, even if those changes are > > not what he proposed. I just wish he would choose his venue a little > > more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. And they argue the man because he refuses to be brow beaten by > those who do not like to be criticised or are too think skinned. I > rarely find his posts controversial but always interesting. His ELisp > tutorial is far and away better than anything else out there for the > programmer moving to Elisp IMO. He backs up his points with reasons and > supportive evidence and rarely with "because I'm experienced and thats > the way it is" - something not every one takes the time to do. He is > clearly intelligent, thoughtful and experienced if a little lacking in > finesse at times. The world needs more Xah lees. If this were an Elisp/Mathematica/Ruby group, those posts would be fine. It isn't just the content of the posts, it's their subject that gets on everyone's nerves. We don't want to hear about Elisp tutorials or why Mathematica is superior to Python. We want to hear about Python. This isn't people being closed-minded, it's about people trying to keep comp.lang.* python* focused on python. If we want to hear about Elisp, we'd ask about it on an emacs or a lisp group. If we want to hear about Mathematica, we'd ask Wolfram for help. If Xah Lee came to the group with posts that constituted "general discussions and questions about Python" people on the list wouldn't get so annoyed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Jan 1 18:05:27 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 1 Jan 2009 18:05:27 -0500 Subject: If your were going to program a game... In-Reply-To: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> Message-ID: On Thu, Jan 1, 2009 at 3:24 PM, excord80 wrote: > On Jan 1, 2:37 pm, Kay Schluehr wrote: > > > There is no solution to this problem from a Python perspective. Do > > what everyone does right now: [snip] > > It still surprises me that no one has implemented the solution for > this yet. > > Maybe it's harder than it seems, but it *seeems* like it's just a > matter of telling Firefox, "hey, when you see this special html > element that tells you to run this python code from the web, do it". > Then have FF load up a python interpreter, sandbox it somehow (that > is, limit it to only a safe subset of its std lib), it runs the code > within its region of the browser window, and Bob's your uncle. > > People would go bonkers for that. This is just as bad as people who post broken HTML just because IE can display it. You should never post content online that only works in one browser. It will just irritate people. If you don't mind using Microsoft stuff, I believe that Silverlight 2 supports IronPython. Novell is almost finished with their open source implementation (Moonlight), but I don't know if they have ipy support yet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at burlyhost.com Thu Jan 1 18:19:58 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 15:19:58 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Richard Riley wrote: > > Tim Greer writes: > >> Giampaolo Rodola' wrote: >> >>> This is not a Ruby group. >>> I recommend you to go waste your time there. >> >> That poster has a frequent habit of cross posting to multiple, >> irrelevant news groups. There's no rhyme or reason to it. It's best >> to just filter the guy's posts. > > No rhyme nor reason? It's quite clear, to me, why. > > How is a comparison article not relevant when he is trying to > stimulate discussion about alternative languages for modern > development? Most news readers feature a kill thread command if you > are not interested in the content. Certainly less extreme or ignorant > than killing all posts from someone who clearly has interesting things > to say about development practises and tools. Don't get so wound up because people in groups he cross posts this junk to actually don't want to see it. This poster is hardly interesting or offering anything intelligent. This poster has a history of posting things that he is personally interested in arguing about, and posting it in groups that are not about the languages he chooses to complain about. There is no rhyme or reason to post in the Perl news group, for example, if you're complaining about Ruby. This is not even close to the first time this has happened, much like his relentless posts about Mathematica (again, cross posted to several groups, including Perl). This user has a specific bias and is trolling to get a rise out of people by picking random languages and trying to cut them down, claiming *his* opinions (based on lack of insights, ironically) are superior. He does this often, and always cross posts to several groups that are completely irrelevant to his argument. The fact you actually buy into this nonsense, actually doesn't make anyone else wrong or ignorant for not agreeing with him, or falling for it. In fact, it means exactly the opposite. If he had something actually interesting and/or relevant, then his rants would be more tolerated by users of these groups. However, since he offers none of those aspects, this is why you see people voice their grievances. Look at this in its basic element, if you don't believe what people say -- this user didn't post the topic in the most revelant group (being the ruby group), and each time he goes off on another misguided tangent, several people prove him wrong, and it doesn't phase him or change anything -- he just continues to cross post. Like I said, if you think he's interesting, fine. However, many people don't. Perhaps as you learn more about programming, development and specific tools and practices, you'll come to realize this fact as well. In the meantime, the irony is probably lost when you actually believe he is offering something of substance, interest or that people whom know better are somehow ignorant. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From slafs.e at gmail.com Thu Jan 1 18:21:18 2009 From: slafs.e at gmail.com (Slafs) Date: Thu, 1 Jan 2009 15:21:18 -0800 (PST) Subject: yacc statement recognition Message-ID: Hi ALL! I have to write in yacc an acceptor of files with lines matching this regexp: '[0-9],[0-9]' and I don't know what I am doing wrong beacuse this: -------- tokens = ( 'NUMBER', ) literals = [','] t_NUMBER = r'\d' ... def p_statement_exp(p): '''statement : NUMBER ',' NUMBER ''' print "OK!" sys.exit() ------- also accepts lines like 2,abcdef3 which of could someone please tell me what's wrong in my code? full source on http://paste-it.net/public/vba22d5/ From tim at burlyhost.com Thu Jan 1 18:24:44 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 15:24:44 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <1hc7l.23929$mE3.719@newsfe14.iad> Richard Riley wrote: > Jason Rumney writes: > >> On Jan 1, 3:12?pm, r wrote: >> >>> The man lives in a world driven by common sense >> >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. And they argue the man because he refuses to be brow beaten by > those who do not like to be criticised or are too think skinned. I > rarely find his posts controversial but always interesting. His ELisp > tutorial is far and away better than anything else out there for the > programmer moving to Elisp IMO. He backs up his points with reasons > and supportive evidence and rarely with "because I'm experienced and > thats the way it is" - something not every one takes the time to do. > He is clearly intelligent, thoughtful and experienced if a little > lacking in finesse at times. The world needs more Xah lees. > You say he's intelligent and interesting, others see it as the opposite. If you want to read his rants, by all means. However, there have been many, many posts there this poster was proven wrong. That is when the poster become more belligerent, off topic, and vulgar. That is not the actions of an intelligent person that's staying on topic or providing anything interesting. The only thing I find interesting, is two anonymous posters from gmail.com rushing to his defense, especially in light of the fact that few people share your version of this person's talents. I'm not trying to be mean, but the guy is what people call a usenet troll. By all means, be his fan, but don't encourage his cross posting trolling as a means to provoke interesting, intelligent debating (because he's not and it's absolutely not his intention). Believe what you want, though, and I'll believe what I know. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From kentilton at gmail.com Thu Jan 1 18:34:19 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Thu, 01 Jan 2009 18:34:19 -0500 Subject: Why not Ruby? In-Reply-To: References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> Message-ID: <495D52FB.6070601@gmail.com> Richard Riley wrote: > Jason Rumney writes: > >> On Jan 1, 3:12 pm, r wrote: >> >>> The man lives in a world driven by common sense >> "Common" sense suggests that his views are shared among the general >> populace. I don't see much evidence of that in the sometimes never- >> ending threads that frequently follow his postings. But it is good to >> start debates about making changes to the status quo, often the >> debates will result in worthwhile changes, even if those changes are >> not what he proposed. I just wish he would choose his venue a little >> more carefully sometimes. > > I find that with Xah's posts people argue the man and not his > points. Precisely, and thus they are the trolls: few of them trim followups, and all of them try to sound funny or clever in their attacks. Xah has something to say about technology, like what he says or not. His attackers just see an open mike and want to hear the sound of their own voice, which I certainly understand. And before anyone goes for that old argument from self-reference, the madding crowd succeeded once in their harrassment of The Xah so remaining silent is no option. p,k From timr at probo.com Thu Jan 1 18:43:00 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 01 Jan 2009 23:43:00 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <0fkql4huhn5tc87utlg6pbdtgt7gqiseca@4ax.com> Aaron Brady wrote: > >I agree that the form of the 4th fragment is 'X and Y are' in >general. However, native speakers don't often use the form 'X and X >are'. This is the source of my protest, because X = the Morning Star >= the Evening Star. We don't say, 'G.H.W. Bush and the President >are...', say, at Camp David. Only now do I begin to see the point you were trying to make. You chose that specific example because the Morning Star and the Evening Star happen to be the same celestial body -- the same object. However, in grammatical terms, that is absolutely irrelevant. For example, "The car and the patent are white rabbits" is, grammatically speaking, 100% correct. Grammatically correct sentences do not have to be logically consistent. Here's a counter example: The Pope and the Head of the Catholic Church are the same person. I don't think any moderately proficient English speaker would have trouble parsing that. By the way, G.H.W. Bush was president from 1988 to 1992. The President today is G.W. Bush. The current president doesn't have an "H". There has to be a pun about "getting the H out of there", but I'll leave that to the reader. >It is not that the meaning is unclear, it's just that form is never used. Well, *I* use it. ;) >How all this relates to Python semantics is, if I say, 'a and b are >the same object', the listener can get confused. I'm inclined to disagree, but in contexts where it is important, I always try to say "a and b are bound to the same object". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rileyrgdev at gmail.com Thu Jan 1 18:52:35 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 00:52:35 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <6s4urcF47nr3U2@mid.individual.net> Message-ID: Raymond Wiker writes: > Richard Riley writes: > >> Tamas K Papp writes: >> >>> On Thu, 01 Jan 2009 23:28:08 +0100, Richard Riley wrote: >>> >>>> posts controversial but always interesting. His ELisp tutorial is far >>>> and away better than anything else out there for the programmer moving >>>> to Elisp IMO. He backs up his points with reasons and supportive >>> >>> Programmers don't "move" to Elisp. Emacs Lisp is used out of necessity >>> when you want to program Emacs. No one in his/her right mind would use >>> it in any other context, as far better alternatives exist (eg CL for >>> those who like Lisp). >>> >>> Tamas >> >> "move to Elisp" was clearly meant as "moving towards it in order to use >> it". In this case to modify emacs. And to suggest that jobs of work are >> not done in Emacs is ridiculous. I am at a loss to really understand >> what you mean here in the context. > > OK, how about this: Xah's elisp code stinks to high > heaven. His code should not be studied by anybody who actually wants > to actually learn elisp (or anything else). I found his tutorial easy to use and very convenient for finding out how to do things quickly and easily. I grant you that possibly thats not the way to be a true Elisp god, but for getting things done in a timely and efficient manner I thought it was good. Clearly Xah Lee stirs up some strong emotions here. I can only go on what I have read from him and I find him interesting and always willing to back up his own research and views. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From rileyrgdev at gmail.com Thu Jan 1 18:57:06 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 00:57:06 +0100 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Tim Greer writes: > Richard Riley wrote: > >> >> Tim Greer writes: >> >>> Giampaolo Rodola' wrote: >>> >>>> This is not a Ruby group. >>>> I recommend you to go waste your time there. >>> >>> That poster has a frequent habit of cross posting to multiple, >>> irrelevant news groups. There's no rhyme or reason to it. It's best >>> to just filter the guy's posts. >> >> No rhyme nor reason? It's quite clear, to me, why. >> >> How is a comparison article not relevant when he is trying to >> stimulate discussion about alternative languages for modern >> development? Most news readers feature a kill thread command if you >> are not interested in the content. Certainly less extreme or ignorant >> than killing all posts from someone who clearly has interesting things >> to say about development practises and tools. > > Don't get so wound up because people in groups he cross posts this > junk Wound up? I am not wound up in any shape or form. I am suggesting the opposite. It seems you are the one a little wound up. So wound up in fact you are taking it on yourself to tell people who they should or should not read. > to actually don't want to see it. This poster is hardly interesting or > offering anything intelligent. This poster has a history of posting > things that he is personally interested in arguing about, and posting > it in groups that are not about the languages he chooses to complain > about. There is no rhyme or reason to post in the Perl news group, > for You dont seem to think that a comparison article is relevant in the groups dedicated to the languages he compares too? OK. I do. You are, of course, welcome to your opinion and I certainly would not tell you who to read or not read. I would suggest that not everyone woul agree with you and that telling people who to killfile is not at all constructive. > example, if you're complaining about Ruby. This is not even close to > the first time this has happened, much like his relentless posts about > Mathematica (again, cross posted to several groups, including Perl). > This user has a specific bias and is trolling to get a rise out of > people by picking random languages and trying to cut them down, > claiming *his* opinions (based on lack of insights, ironically) are > superior. He does this often, and always cross posts to several groups > that are completely irrelevant to his argument. You clearly have a personal issue with Xah Lee. Possibly it is better you killfile him or your spring will over wind :-; regards, r. From rileyrgdev at gmail.com Thu Jan 1 19:00:19 2009 From: rileyrgdev at gmail.com (Richard Riley) Date: Fri, 02 Jan 2009 01:00:19 +0100 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: Kenneth Tilton writes: > Richard Riley wrote: >> Jason Rumney writes: >> >>> On Jan 1, 3:12 pm, r wrote: >>> >>>> The man lives in a world driven by common sense >>> "Common" sense suggests that his views are shared among the general >>> populace. I don't see much evidence of that in the sometimes never- >>> ending threads that frequently follow his postings. But it is good to >>> start debates about making changes to the status quo, often the >>> debates will result in worthwhile changes, even if those changes are >>> not what he proposed. I just wish he would choose his venue a little >>> more carefully sometimes. >> >> I find that with Xah's posts people argue the man and not his >> points. > > Precisely, and thus they are the trolls: few of them trim followups, > and all of them try to sound funny or clever in their attacks. Xah has > something to say about technology, like what he says or not. His > attackers just see an open mike and want to hear the sound of their > own voice, which I certainly understand. > > And before anyone goes for that old argument from self-reference, the > madding crowd succeeded once in their harrassment of The Xah so > remaining silent is no option. > > p,k It's good to see I am not alone in my views on some of the more aggressive posters who seem to take delight in attacking Xah Lee. I was wondering if I had backed myself into a corner with no chance of escape for a moment. I found the comments on his elisp tutorial and reference particularly offensive and destructive considering I know it to be of at least some use as I referred to it quite a bit when trying some basic customisations. -- important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970 From jurgenex at hotmail.com Thu Jan 1 19:02:44 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 16:02:44 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <6cmql4hmfbsrtr1mgsub2l2p6o0lv7n03l@4ax.com> Richard Riley wrote: >discussion about alternative languages for modern development? Most news >readers feature a kill thread command if you are not interested in the >content. Certainly less extreme or ignorant than killing all posts from >someone Thank you for reminding me *PLONK* jue From jurgenex at hotmail.com Thu Jan 1 19:05:11 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Thu, 01 Jan 2009 16:05:11 -0800 Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: Kenneth Tilton wrote: >Xah has >something to say about technology, like what he says or not. Unfortunately it's unrelated to the topics the NGs he is spamming. *PLONK* jue From steve at REMOVE-THIS-cybersource.com.au Thu Jan 1 19:16:14 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 00:16:14 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> Message-ID: <016d53c1$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > On many occasions I've wished for a functional dictionary implementation > in Python, like Haskell's Data.Map. One of these years I'll get around > to writing one. You don't think Python's dict implementation is functional? That's pretty strange, Python dicts are the basis of much of the language. They certainly work, and work well, what makes you think they aren't functional? What does Data.Map do that dicts don't? Oh, and Paul, you've been around long enough that you should know better than to be cross-posting like you did. -- Steven From tim at burlyhost.com Thu Jan 1 19:18:54 2009 From: tim at burlyhost.com (Tim Greer) Date: Thu, 01 Jan 2009 16:18:54 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: Richard Riley wrote: > Tim Greer writes: > >> Richard Riley wrote: >> >>> >>> Tim Greer writes: >>> >>>> Giampaolo Rodola' wrote: >>>> >>>>> This is not a Ruby group. >>>>> I recommend you to go waste your time there. >>>> >>>> That poster has a frequent habit of cross posting to multiple, >>>> irrelevant news groups. There's no rhyme or reason to it. It's >>>> best to just filter the guy's posts. >>> >>> No rhyme nor reason? It's quite clear, to me, why. >>> >>> How is a comparison article not relevant when he is trying to >>> stimulate discussion about alternative languages for modern >>> development? Most news readers feature a kill thread command if you >>> are not interested in the content. Certainly less extreme or >>> ignorant than killing all posts from someone who clearly has >>> interesting things to say about development practises and tools. >> >> Don't get so wound up because people in groups he cross posts this >> junk > > > Wound up? Yes, I'd say that accusing people of bring ignorant and attacking them for not sharing your view on the irrelevant cross posting and trolling of the Xah poster, is indeed an indication that you appear to be wound up. Perhaps you've not seen the posts and threads he's made that I've seen? Perhaps I've not seen the one's you have? Either way, the one's I have, have all been either self serving garbage about his own personal feelings that he attempts to covey as fact with his overbearing arrogance, or it's simply to attack others for not sharing his view. I find that ironic. He attacks others, acting belligerent, and you attack those that simply say he's better ignored. > I am not wound up in any shape or form. Then convey that in your attitude when replying to others you don't know anything about, and try and be civil and not accuse people you don't know. > I am suggesting the > opposite. Suggesting it by doing exactly what you're saying people should not do? > It seems you are the one a little wound up. Nope, I responded to your attempts to provoke an issue, when you accused myself and others of being "ignorant" for not sharing your view regarding the Xah poster. > So wound up in > fact you are taking it on yourself to tell people who they should or > should not read. A suggestion is not an instruction or demand. You listed reasons why you believed those that didn't agree with you were wrong and ignorant, and I listed reasons in response to your claim to dispute it. >> to actually don't want to see it. This poster is hardly interesting >> or >> offering anything intelligent. This poster has a history of posting >> things that he is personally interested in arguing about, and posting >> it in groups that are not about the languages he chooses to complain >> about. There is no rhyme or reason to post in the Perl news group, >> for > > You dont seem to think that a comparison article is relevant in the > groups dedicated to the languages he compares too? No. Not when it's just his own feelings about the languages. A lot of people have their personal feelings about various languages, imagine all of the pollution we'd see if everyone was as arrogant as this guy, all posting their views as if they are the authority on the matter? Again, going by that deduction, what do you suppose explains his failure to consider posting this in the ruby group itself, since that is the primary (and actually, only) relevant group (dismissing his personal views)? > OK. I do. If you do, that's fine. However, many people in the Perl group, which I'm seeing this thread, have voiced their issues with this poster's relentless postings of this nature. I did as well, in this new thread. > You are, > of course, welcome to your opinion and I certainly would not tell you > who to read or not read. I can appreciate that, and I didn't tell you to do anything though, now did I? > I would suggest that not everyone woul agree > with you and that telling people who to killfile is not at all > constructive. Of course I don't expect everyone to agree with me. The poster that replied displayed annoyance at seeing the off topic, self serving and trollish post that this Xah poster is known for (at least in this group), and in response to *that*, I had suggested they don't take him seriously, and this is "what he does" (in my experience). There's no reason to read more into it and start claiming people are ignorant for not agreeing with you. And, I think it's perfectly constructive to advise someone that this isn't abnormal, and for future reference, to consider such an option if they are too annoyed by it. >> example, if you're complaining about Ruby. This is not even close to >> the first time this has happened, much like his relentless posts >> about Mathematica (again, cross posted to several groups, including >> Perl). This user has a specific bias and is trolling to get a rise >> out of people by picking random languages and trying to cut them >> down, claiming *his* opinions (based on lack of insights, ironically) >> are >> superior. He does this often, and always cross posts to several >> groups that are completely irrelevant to his argument. > > You clearly have a personal issue with Xah Lee. Not at all. It's not personal. It's a simple observation and opinion based on my experience seeing his cross posting trolling over the last few weeks. I didn't accuse you of having a personal issue with me for not agreeing with my opinion and methods, so perhaps you can consider the gesture of not making such accusations. They aren't true or relevant. Yeah, I verbalized (textualized) my displeasure with his tactics, but that's the end of the matter, really. > Possibly it is better > you killfile him or your spring will over wind :-; Uh huh. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From fuzzyman at gmail.com Thu Jan 1 19:19:38 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 16:19:38 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 2, 12:16?am, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > > On many occasions I've wished for a functional dictionary implementation > > in Python, like Haskell's Data.Map. ?One of these years I'll get around > > to writing one. > > You don't think Python's dict implementation is functional? That's pretty > strange, Python dicts are the basis of much of the language. They > certainly work, and work well, what makes you think they aren't > functional? What does Data.Map do that dicts don't? > He almost certainly (I assume) means functional in the way that Haskell is a functional language. Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Thu Jan 1 19:22:15 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 1 Jan 2009 16:22:15 -0800 (PST) Subject: why cannot assign to function call References: <97a11245-a034-4558-82d4-0c87e02bdb7e@u18g2000pro.googlegroups.com> Message-ID: <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> On Dec 29 2008, 9:34?am, John Machin wrote: > On Dec 29, 5:01?pm, scsoce wrote: > > > I have a function return a reference, > > Stop right there. You don't have (and can't have, in Python) a > function which returns a reference that acts like a pointer in C or C+ > +. Please tell us what manual, tutorial, book, blog or Usenet posting > gave you that idea, and we'll get the SWAT team sent out straight > away. > > > and want to assign to the > > reference, simply like this: > > ?>>def f(a) > > ? ? ? ? ? return a > > That's not a very useful function, even after you fix the syntax error > in the def statement. Would you care to give us a more realistic > example of what you are trying to achieve? > > > ? ? ?b = 0 > > ? ? * f( b ) = 1* > > Is the * at the start of the line meant to indicate pointer > dereferencing like in C? If not, what is it? Why is there a * at the > end of the line? > > > but the last line will be refused as "can't assign to function call". > > In my thought , the assignment is very nature, > > Natural?? Please tell us why you would want to do that instead of: > > ? ? b = 1 > > >?but ?why the interpreter > > refused to do that ? > > Because (the BDFL be praised!) it (was not, is not, will not be) in > the language grammar. Although not being able to do the following has on occasion annoyed me: f(x) += 1 If the object returned by f(x) supports in place operations then it is an entirely logical meaning, but not the interpreter can't know ahead of time whether that is the case or not. Michael Foord -- http://www.ironpythoninaction.com/ From rt8396 at gmail.com Thu Jan 1 19:24:43 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 16:24:43 -0800 (PST) Subject: Why not Ruby? References: <495c43c3$0$20279$607ed4bc@cv.net> <139581ae-97dd-4c62-9dfb-2eafa476261d@j35g2000yqh.googlegroups.com> <495D52FB.6070601@gmail.com> Message-ID: <00354316-4d95-4eca-8ff3-45d804ddf97a@s37g2000vbp.googlegroups.com> On Jan 1, 5:34?pm, Kenneth Tilton wrote: > Richard Riley wrote: > > Jason Rumney writes: > > >> On Jan 1, 3:12 pm, r wrote: > > >>> The man lives in a world driven by common sense > >> "Common" sense suggests that his views are shared among the general > >> populace. I don't see much evidence of that in the sometimes never- > >> ending threads that frequently follow his postings. But it is good to > >> start debates about making changes to the status quo, often the > >> debates will result in worthwhile changes, even if those changes are > >> not what he proposed. I just wish he would choose his venue a little > >> more carefully sometimes. > > > I find that with Xah's posts people argue the man and not his > > points. > > Precisely, and thus they are the trolls: few of them trim followups, and > all of them try to sound funny or clever in their attacks. Xah has > something to say about technology, like what he says or not. His > attackers just see an open mike and want to hear the sound of their own > voice, which I certainly understand. > > And before anyone goes for that old argument from self-reference, the > madding crowd succeeded once in their harrassment of The Xah so > remaining silent is no option. > > p,k Good Point, Starting a new thread is not off topic no matter what subject. I have never witnessed a time where Xah jumped in the middle of a thread and started a ruckus(i could be wrong), But i do see many interrupting Xah's threads or any thread for that matter that they feel is irrelevant to them. The topic of a thread is it's title. Here, the title is "Why Not Ruby". I am the only person yet to offer argument for or against Ruby here. From mmanns at gmx.net Thu Jan 1 19:28:23 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Fri, 2 Jan 2009 01:28:23 +0100 Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: <20090102012823.7bae496b@Schlamber.localdomain> On Thu, 1 Jan 2009 11:34:53 -0800 (PST) ajaksu wrote: > http://article.gmane.org/gmane.comp.python.python-3000.devel/8732 I will build upon this code. Thanks for your help Martin From google at mrabarnett.plus.com Thu Jan 1 20:04:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 02 Jan 2009 01:04:55 +0000 Subject: why cannot assign to function call In-Reply-To: <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> References: <97a11245-a034-4558-82d4-0c87e02bdb7e@u18g2000pro.googlegroups.com> <1961ef8a-27ba-428e-ba50-62fcef0f673d@w39g2000prb.googlegroups.com> Message-ID: <495D6837.6090307@mrabarnett.plus.com> Fuzzyman wrote: > On Dec 29 2008, 9:34 am, John Machin wrote: >> On Dec 29, 5:01 pm, scsoce wrote: >> >>> I have a function return a reference, >> Stop right there. You don't have (and can't have, in Python) a >> function which returns a reference that acts like a pointer in C or C+ >> +. Please tell us what manual, tutorial, book, blog or Usenet posting >> gave you that idea, and we'll get the SWAT team sent out straight >> away. >> >>> and want to assign to the >>> reference, simply like this: >>> >>def f(a) >>> return a >> That's not a very useful function, even after you fix the syntax error >> in the def statement. Would you care to give us a more realistic >> example of what you are trying to achieve? >> >>> b = 0 >>> * f( b ) = 1* >> Is the * at the start of the line meant to indicate pointer >> dereferencing like in C? If not, what is it? Why is there a * at the >> end of the line? >> >>> but the last line will be refused as "can't assign to function call". >>> In my thought , the assignment is very nature, >> Natural?? Please tell us why you would want to do that instead of: >> >> b = 1 >> >>> but why the interpreter >>> refused to do that ? >> Because (the BDFL be praised!) it (was not, is not, will not be) in >> the language grammar. > > Although not being able to do the following has on occasion annoyed > me: > > f(x) += 1 > > If the object returned by f(x) supports in place operations then it is > an entirely logical meaning, but not the interpreter can't know ahead > of time whether that is the case or not. > += always rebinds, even for in-place operations, so, in a sense, it's not surprising! I suppose it's like forbidding assignment within an expression (such as an if- or while-condition): annoying sometimes, but a reasonable restriction. From timr at probo.com Thu Jan 1 20:30:30 2009 From: timr at probo.com (Tim Roberts) Date: Fri, 02 Jan 2009 01:30:30 GMT Subject: Videocapture in python References: <0372e356-8f37-457d-9201-18ae94fc68d9@a29g2000pra.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > >On using videocapture (python 2.4), I am facing the following issues >while creating a video sort of application. >-> Pull out the usb cable : Videocapture gets the data stored >initially in the buffer and returns always. The images are not updated >- but also there is no error returned. >i.e. there is no information to the viewer that it is not working >anymore. Especially because since the timestamp is updated everytime >(it is done inside videocapture.py - wherein current time is >overwritten on the received image), it gives a feeling that video is >running. > >Currently I have done a workaround in that every 2 captures, i setup >the camera again - but it takes too much time. Anyone has any >suggestions on solving this? The "right" way to fix this is to modify the C++ code that sets up the DirectShow filter graph. The graph builder has the ability to deliver events asynchronously, like when the device goes away, but it would not be trivial to incorporate that into the module as written. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rt8396 at gmail.com Thu Jan 1 20:38:02 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 17:38:02 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> On Jan 1, 6:16?pm, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: > > On many occasions I've wished for a functional dictionary implementation > > in Python, like Haskell's Data.Map. ?One of these years I'll get around > > to writing one. > > You don't think Python's dict implementation is functional? That's pretty > strange, Python dicts are the basis of much of the language. They > certainly work, and work well, what makes you think they aren't > functional? What does Data.Map do that dicts don't? > > Oh, and Paul, you've been around long enough that you should know better > than to be cross-posting like you did. > > -- > Steven Steven, He was not cross posting. His reference to python dicts is a result of the nested scope of my references to Xah. Making them perfectly and completely valid in this thread, and the scope therein! I do not believe a linear conversation would do anybody any good here and even valid. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 1 20:38:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 01:38:06 GMT Subject: Why not Ruby? References: Message-ID: <016d66f1$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > the use of "end" in a language as > high level as Ruby is redundant, and idiotic. There are a few things > about Ruby i really like, but this "end" business is blasphemy. "Blasphemy"? You really are an idiot. Programming languages are not religions. Step away from the computer, and don't come back until you've grown up. And stop cross-posting, you rude little delinquent. -- Steven From excord80 at gmail.com Thu Jan 1 20:49:22 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 17:49:22 -0800 (PST) Subject: mod_pylite? Message-ID: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Just read this interesting post by chromatic on what features Perl 5 needs right now http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html and he mentions a neat-looking project called ``mod_perlite``. It sounds like it will be very handy. Anyone working on a ``mod_pylite``? Has it been done before, maybe under a different name? From jgardner at jonathangardner.net Thu Jan 1 21:10:30 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 1 Jan 2009 18:10:30 -0800 (PST) Subject: Understanding search queries, semantics, and "Meaning" ...aren't we all looking for meaning? References: <82372457-2503-4682-96b3-37540328bf26@w39g2000prb.googlegroups.com> <94ab1653-c88d-4bad-a094-47d67e435618@w1g2000prm.googlegroups.com> <3d4991d9-d0ab-4483-aee7-2763e3712b96@w1g2000prm.googlegroups.com> Message-ID: <23f35a8e-d560-41ac-8a86-c682a8596c81@k36g2000pri.googlegroups.com> On Dec 30 2008, 3:25?pm, 5lvqbw... at sneakemail.com wrote: > > In a typical SQL database, when you type in "SELECT foo FROM bar WHERE > > baz='bo'", you are not writing a program, at least not in the sense of > > Python or C or Java or Perl where you give instructions on HOW to run > > the program. You are writing a program in the sense of Lisp or Scheme > > or Haskell in that you are giving instructions on WHAT the program is. > > I've gotten a strong inkling that parsing a query yields new code, > (lambdas) that are created on the fly to do the search. > More on this at the very end. Just smile to know that you're very close. > > course. Instead, it transforms the query (the WHAT) into a set of > > procedures that describe HOW to get the result. > > For now I'm not parsing actual text queries... my real "search query" > is coded directly in python like this: > p1 = lambda: db.search_leaf('x location', 'lte', 5) > p2 = lambda: db.search_leaf('footprint', 'eq', '0603') > p3 = lambda: db.search(db.AND, p1, p2) > > p4 = lambda: db.search_leaf('x location', 'gte', 19) > p5 = lambda: db.search_leaf('footprint', 'eq', '0402') > p6 = lambda: db.search(db.AND, p1, p2) > > fc = db.search(db.OR, p3, p4) > > this particular example doesn't necessarily make any sense, but in > effect I'm trying to string together lambda functions which are > created explicitly for the individual query, then strung together with > combiner functions. > If only compilers were so simple... Again, you're writing the "HOW" when you're doing what you're doing above, when you really want to write the "WHAT". Oh, and BTW, lambdas are just an expression to generate a function quickly. You're confusing the python lambda expression with lambdas the theoretical concepts. Lambdas the theoretical concept are really Python's callable objects. Python just expresses them in a very weird way that is seemingly unrelated to lambda the theoretical concept (but really is). > > Oh, by the way, this step is nondeterministic. Why? Well, no one can > > really say what the BEST way to run any sufficiently complicated > > program is. We can point out good ways and bad ways, but not the best > > way. It's like the travelling salesman problem in a way. > > The nondeterministic stuff... wow, I've come across (call/cc...), > (require...), and different variants of this, both in sicp, teach > yourself scheme, the plt docs, other places, etc., but it still eludes > me. ?I'm afraid that unless I understand it, I'll wind up creating > some type of cargo-cult mimcry of a database without doing it right > (http://en.wikipedia.org/wiki/Cargo_cult) > Sorry, I got confused on the meaning of non-deterministic programming. I forgot that this was a specific thing in the Scheme world. Yes, you've got to understand this. It makes writing a compiler much, much easier, almost trivial. > > programmer, will be infinitely better for it. When you understand it, > > you will really unlock the full potential of Python and Scheme and > > whatever other language is out there because you will see how to go > > from HOW languages to WHAT languages. > > I'm under the impression python doesn't have the internal guts for > nondeterministic programming, specifcially that its lambdas are > limited to single-line expressions, but I may be wrong here. > (Recall what I mentioned about lambdas above. It applies here as well.) > Still, at the begining of the nondeterministic section of SICP > (section 4.3), it says "nondeterministic computing... is useful for > 'generate and test' applications", which almost categorically sounds > like an element-by-element search for what you're looking for. ?This > was my initial intention behind (prematurely?) optimizing the database > by using parameter keys instead of something like [x for x in stuff if > pred(x, val)] filtering. > Yes, you certainly can't use list comprehensions to solve your problems. They're too primitive and part of the interface is that they actually iterate through the sequence. > > Programmers who can write compilers are GOOD programmers. Programmers > > who can understand someone else's compilers are even better. > > Does incorporating a search capability in an application necessarily > mean I'm writing a search compiler? ?That seems overkill for the > specific case, but may be true generally. ?For instance, if a word > processing app allows you to search for characters with a certain > font, is that incorporating a search compiler and query language? ?Or > is it just brute-force filtering? > Ok, here's some big picture hand-waving. I'm going to make an assertion, and it turns out to be fundamental. I won't explain it here but I hope you'll learn what it means as time goes on. The assertion is this: All programs simply transform one program's code into another program's code. By program, I mean, a set of instructions to a computer of some sort that are meant to be actually evaluated somehow. By program's code, I mean a description in any form of such a program. For instance, all human language is really some kind of program code. So is all Scheme, Lisp, Python, whatever code. So is HTML. So are bytes and words in memory representing a compiled program. So are IP packets on the internet. When you type in search terms to the search feature of Word, you are writing program code. Sure, the program code is going to be interpreted in some way, but it represents a program that says, "Find, by whatever method available, the next instance of text matching the text I type in here". That's a fairly easy thing to do, and you don't need to know about relational algebra and non-deterministic code to write a correct and fast solution. If you're going to implement a general function that takes arbitrary search criteria against arbitrary structured data and uses several methods together to find the answers, that's going to require a fairly advanced compiler and optimizer. You can use Scheme's non- deterministic methods to build that program, which is really neat and a big time-saver in terms of development time. That level of program is pretty advanced and only those who really understand how to write a compiler can put it together. For the mouse-hovering bit, since you're always running the same query, you can "pre-compile" it and just write a specific index and some specific code to look it up. This isn't too difficult. From skip at pobox.com Thu Jan 1 21:12:32 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 1 Jan 2009 20:12:32 -0600 Subject: mod_pylite? In-Reply-To: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Message-ID: <18781.30736.601023.757172@montanaro-dyndns-org.local> >> http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html >> and he mentions a neat-looking project called ``mod_perlite``. It >> sounds like it will be very handy. Anyone working on a >> ``mod_pylite``? Has it been done before, maybe under a different >> name? It's kind of hard to tell. There's very little description of how mod_perlite would be different than mod_perl other than it would be more lightweight, presumably as mod_php somehow is. That hardly seems like a well-defined requirement document. Does mod_wsgi fit the bill? http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From marek at xivilization.net Thu Jan 1 21:13:34 2009 From: marek at xivilization.net (Marek Kubica) Date: Fri, 2 Jan 2009 02:13:34 +0000 (UTC) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> Message-ID: On Thu, 01 Jan 2009 13:13:19 -0800, Fuzzyman wrote: > Care to save me the effort of looking it up and tell me what Data.Map > does that Python's dict doesn't? > > I guess if it is functional then every mutation must copy and return a > new data structure? (Which will be much more efficient in Haskell than > in Python - Haskell can share most of the underlying data whereas Python > would have to create a new dict every time. At least it only stores > references.) Who says that it must create a whole new one? I could imagine that with a bit weakref code and some thought an immutable dictionary that shares data would be possible in Python too. regards, Marek From excord80 at gmail.com Thu Jan 1 22:28:17 2009 From: excord80 at gmail.com (excord80) Date: Thu, 1 Jan 2009 19:28:17 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> Message-ID: <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> On Jan 1, 9:12?pm, s... at pobox.com wrote: > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > ? ? >> sounds like it will be very handy. Anyone working on a > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > ? ? >> name? > > It's kind of hard to tell. ?There's very little description of how > mod_perlite would be different than mod_perl other than it would be more > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > well-defined requirement document. > > Does mod_wsgi fit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > I'm not sure if it fits the bill or not. The bill is two-fold: 1. The Apache module should present little risk to the admin who installs it. That is, it should not expose Apache's innards. 2. The Apache module should keep a Python instance running; run, for example, ``foo.py`` when a user accesses (for example) ``http:// www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the usual way; and return whatever html that script spits out. I'm not familiar with php or ``mod_php``, but I suspect that setup does something very similar to what's described above. This might explain why it's so blasted easy to deploy php scripts and create small and simple sites (and even not-so-small/simple sites) with it. Does mod_wsgi fit that bill? I don't know. The docs seem to be at http://code.google.com/p/modwsgi/w/list . Many of those are named "ChangesInVersionXXXX". I don't see any that named anything like "Introduction" or "BasicUsage" or "SimpleUsageLikeCGI" or even "Tutorial". So, my guess is that ``mod_wsgi`` doesn't fit the bill. From http Thu Jan 1 22:48:17 2009 From: http (Paul Rubin) Date: 01 Jan 2009 19:48:17 -0800 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xeizmtlku.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > You don't think Python's dict implementation is functional? I'm using the term "functional" in the sense of Chris Okasaki's book "Purely Functional Data Structures". Basically a functional dictionary is an immutable dictionary that supports fast "update" operations by letting you quickly make a new dictionary that shares structure with the old one. For example, if d is a functional dictionary, then e = d.update(("name", "joe")) would be something like Python's e = d.copy() e["name"] = "joe" except that it would not incur the overhead of copying d completely and instead would usually take O(log n) operations where n is the number of entries in d. Among other things this makes it trivial to implement rollback for dictionaries, multiple views of the same data, etc. Functional dictionaries are normally implemented using balanced tree structures such as red-black trees as their association mechanism, rather than hash tables. From http Thu Jan 1 22:51:53 2009 From: http (Paul Rubin) Date: 01 Jan 2009 19:51:53 -0800 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <9c813a5c-919c-4407-b78c-fec33d1bd0fa@w24g2000prd.googlegroups.com> Message-ID: <7xabaatleu.fsf@ruckus.brouhaha.com> Marek Kubica writes: > > I guess if it is functional then every mutation must copy and return a > > new data structure? Yes. > > (Which will be much more efficient in Haskell than > > in Python - Haskell can share most of the underlying data whereas Python > > would have to create a new dict every time. At least it only stores > > references.) The structure sharing is essential, but you can do it in Python, just not using Python dicts as far as I can tell. > Who says that it must create a whole new one? I could imagine that with a > bit weakref code and some thought an immutable dictionary that shares > data would be possible in Python too. I don't see a way to do that. Suppose d and e are dicts that are supposed to share structure except d['name']='bob' and e['name']='joe'. How do weakrefs help? Functional dictionaries are usually implemented using red-black trees or AVL trees or similar data structures, rather than hash tables. From Graham.Dumpleton at gmail.com Thu Jan 1 23:40:52 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 1 Jan 2009 20:40:52 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> Message-ID: <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> On Jan 2, 2:28?pm, excord80 wrote: > On Jan 1, 9:12?pm, s... at pobox.com wrote: > > > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > > ? ? >> sounds like it will be very handy. Anyone working on a > > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > > ? ? >> name? > > > It's kind of hard to tell. ?There's very little description of how > > mod_perlite would be different than mod_perl other than it would be more > > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > > well-defined requirement document. > > > Doesmod_wsgifit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > > I'm not sure if it fits the bill or not. The bill is two-fold: > > 1. The Apache module should present little risk to the admin who > installs it. That is, it should not expose Apache's innards. > > 2. The Apache module should keep a Python instance running; run, for > example, ``foo.py`` when a user accesses (for example) ``http://www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the > usual way; and return whatever html that script spits out. > > I'm not familiar with php or ``mod_php``, but I suspect that setup > does something very similar to what's described above. This might > explain why it's so blasted easy to deploy php scripts and create > small and simple sites (and even not-so-small/simple sites) with it. > > Doesmod_wsgifit that bill? I don't know. The docs seem to be athttp://code.google.com/p/modwsgi/w/list. Many of those are named > "ChangesInVersionXXXX". I don't see any that named anything like > "Introduction" or "BasicUsage" or "SimpleUsageLikeCGI" or even > "Tutorial". So, my guess is that ``mod_wsgi`` doesn't fit the bill. Have you looked up what the WSGI specification for Python even is? http://www.python.org/dev/peps/pep-0333/ http://www.wsgi.org/wsgi/Learn_WSGI Did you also read the front page of the wiki for mod_wsgi and follow the main links it gives on the front page? http://code.google.com/p/modwsgi/ http://code.google.com/p/modwsgi/wiki/InstallationInstructions http://code.google.com/p/modwsgi/wiki/DeveloperGuidelines If you understand what WSGI is, then you will realise that mod_wsgi is a very slim adapter for Apache that allows one to host any WSGI application. In the way one normally uses it, the internals of Apache are not exposed and do not need to be as the whole point of WSGI is that it is a portable interface for hosting Python web applications on various web hosting solutions and not Apache specifically. Back to whether it is equivalent to mod_perlite, that really depends on what mod_perlite does. If mod_perlite tries to enforce some sort of page template system like how PHP does then no mod_wsgi is not equivalent, as that isn't what WSGI itself is about. All WSGI is about is providing a most minimal interface for communicating with the web server, everything else has to be done by the application running on top of it. Thus WSGI and mod_wsgi is a light as it can get, perhaps even lighter than mod_perlite could be as it may have to embody the templating system, form handling, session management etc etc etc. This doesn't mean you couldn't use mod_wsgi to effectively achieve the same thing though, it just means your most minimal templating system, ie., like PHP or even closer to traditional Python CGI, needs to be implemented as an application on top of WSGI. Rather than do the dispatch in your WSGI application though, you can still use Apache to do the dispatching to individual file based resource files with the right configuration. How this could be done has been answered a number of times on mod_wsgi list as others have already wanted to know about how to do a PHP like solution in Python and so it has been discussed. If you want to talk more about this, come over to the mod_wsgi list on Google Groups. Graham From koranthala at gmail.com Fri Jan 2 00:48:34 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Thu, 1 Jan 2009 21:48:34 -0800 (PST) Subject: initialization in python References: <34960162-15bf-4b37-9d8d-4925c46712ac@d42g2000prb.googlegroups.com> Message-ID: <7bfb4f18-f133-4e2a-a11c-e339d2686acc@w1g2000prm.googlegroups.com> On Jan 1, 11:14?pm, Terry Reedy wrote: > koranth... at gmail.com wrote: > >>> Module database: > >>> ^^^^^^^^^^^^^^^^^^^ > >>> Session = None > > 'Initializing' names is not necessary. ?Delete this. ?Without it, your > error would be more obvious. > > >>> def init(dbname): > >>> ? ?engine = create_engine('sqlite:///%s' %dbname) > >>> ? ?... > >>> ? ?global Session > >>> ? ?Session = sessionmaker(bind=engine) > > This **rebinds* the module name 'Session' to a new object, making the > initial bindin irrelevant and misleading. > > [snip] > > > > > I guessed as much. But, I was under the impression that if the > > original value is modified, the variables value also will change. > > Python has names and slots bound to objects. ?Some objects are mutable > and some not. ?None is not mutable. ?You replaced it. > > If you had done something like > > Session = sessionmaker() > > def init(dbname): > ? ? ?Session.engine = create_engine('sqlite:///%s' %dbname) > ? ? ?... > > then you would have *modified* the original object (value) bound to > 'Session' and would have seen the behavior you expected. > > Terry Jan Reedy I did not think about it. I was using database.Session till now. I have now modified the code. Thank you very much, Terry Jan Reedy From ssalam at gmail.com Fri Jan 2 01:58:16 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Fri, 2 Jan 2009 12:28:16 +0530 Subject: Switching user in a SSH connection Message-ID: Hi Group, I am trying to connect to a Linux maching using paramiko. and able to run a command like "ls -l" Now I want to switch user being in the connection ( eg running something like "su -" ) Will you please let me know how to do that. Regds Shah From rt8396 at gmail.com Fri Jan 2 02:11:38 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 23:11:38 -0800 (PST) Subject: Why not Ruby? References: <016d66f1$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 1, 7:38?pm, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > > the use of "end" in a language as > > high level as Ruby is redundant, and idiotic. There are a few things > > about Ruby i really like, but this "end" business is blasphemy. > > "Blasphemy"? > > You really are an idiot. Programming languages are not religions. Step > away from the computer, and don't come back until you've grown up. > > And stop cross-posting, you rude little delinquent. > > -- > Steven Steven, Spare us your flamery, get on board, and be a part of the solution, and not just a constant problem to those you don't agree with. Or at least do like my friend Bruno, and send me up,up,and away to your bozo filter! Your one of the few trolls left that i have to deal with around here. And it's sad because sometimes you do offer good information. From rt8396 at gmail.com Fri Jan 2 02:54:36 2009 From: rt8396 at gmail.com (r) Date: Thu, 1 Jan 2009 23:54:36 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: On Jan 1, 4:40?pm, Robert Kern wrote: > Hamish McKenzie wrote: > > sometimes I want to be able to initialize an instance with a variety of different data types. > > > as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > > > is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > > I recommend keeping the __init__() as dumb as possible. Ideally, it should just > assign to attributes. I would add a from() classmethod for each that > I wanted to support. If I really wanted an all-singing, all-dancing > initialization method, I would add another classmethod that would just dispatch > to the appropriate type-specific classmethod. I prefer classmethods to plain > functions because I can subclass. > > -- > 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 Why are you busting into this thread? why have you not created your own thread. Someone asked a question about recycle bin access and you come in here, bust down the door and ask a completely off topic question, which is OK if you start a new thread of your own. And the most insane part to all of this, is that Steven just plays right along?!?!? Come on Stevie, you know better than this! PS (To OP) mark hammonds win32 package will not do what you ask, sorry From dotancohen at gmail.com Fri Jan 2 03:42:27 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 2 Jan 2009 10:42:27 +0200 Subject: Easy-to-use Python GUI In-Reply-To: <6s2n0sF408fuU1@mid.uni-berlin.de> References: <6s2n0sF408fuU1@mid.uni-berlin.de> Message-ID: <880dece00901020042m69878826y896c67b2fceacb3c@mail.gmail.com> 2009/1/1 Gerhard H?ring : > Dotan Cohen wrote: >> >> I have been following this thread with interest. Is there a way to >> build Qt apps with relative easy? I use KDE and would prefer the Qt >> toolkit for my GUI apps. Thanks. > > A few years ago, I've had bad experiences with wxPython (random things not > actually working on Linux, only on Windows; getting segfaults when using not > exactly the right values for API calls). > > So, when I had to decide for a toolkit for a new application I'm developing > on my job which required: > > - ability to run on Windows > - ability to run on MacOS > - time to develop is short > > I recommended to go with PyQt. > > I remembered it was warmly recommended by Alex Martelli and others a few > years ago. > > So far, it's been nothing but joy. We bought the book "Rapid GUI Programming > with Python and Qt" (http://www.qtrac.eu/pyqtbook.html) which is *really* > well written. It's probably the best tech book I ever had. The author > formerly did Qt documentation for Trolltech, so he has deep understanding of > what he's writing about. > > There may be not so many third-party add-ons for PyQt like for wxPython, > but in my opinion, the quality of Qt, PyQt and documentation like the book > make up for it. > > And, it's really extensive. So far I've found everything in Qt/PyQt I > wanted/needed: > > - MDI workspaces > - Dock windows > - I needed something like wxPythons wxOGL for a process modeler and after > looking around for two days, I found out that it's already all there in Qt > 4.4: QGraphicsScene/QGraphicsView > - etc. > Thank you. I just googled the book and it seems to be Python 2 only, which is not surprising considering that Python 3 just came out. I will purchase a copy as soon as it is updated for Python 3. Thanks! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From no-spam at no-spam.invalid Fri Jan 2 04:07:54 2009 From: no-spam at no-spam.invalid (robert) Date: Fri, 02 Jan 2009 10:07:54 +0100 Subject: similar words index? Message-ID: how can one index (text documents) for efficient similar word search? existing modules? what principles are used by search engines therefore? From bockman at virgilio.it Fri Jan 2 04:12:50 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 10:12:50 +0100 Subject: yacc statement recognition [PLY] In-Reply-To: References: Message-ID: <495dda95$0$749$5fc30a8@news.tiscali.it> Slafs ha scritto: > Hi ALL! > > I have to write in yacc an acceptor of files with lines matching this > regexp: > '[0-9],[0-9]' > and I don't know what I am doing wrong beacuse this: > > -------- > tokens = ( > 'NUMBER', > ) > literals = [','] > > t_NUMBER = r'\d' > > ... > > def p_statement_exp(p): > '''statement : NUMBER ',' NUMBER > ''' > print "OK!" > sys.exit() > ------- > > also accepts lines like 2,abcdef3 which of > could someone please tell me what's wrong in my code? > > full source on http://paste-it.net/public/vba22d5/ Your code works for me (Python 2.5 and ply 2.3 on ubuntu 8.10), except that, from the rest of your code, I see that you parse separately each line of file. Since you put a sys.exit() in the parsing rule, it means that at the first line successfully parsed your program will quit. Try putting a simple print in it and instead putting the sys.exit in your p_error function (if you want to exit at the first 'wrong' line line). BTW, are you aware that exists a specific google group for ply users? Specific ply questions could be answered here : http://groups.google.com/group/ply-hack?pli=1 Ciao ---- FB From tino at wildenhain.de Fri Jan 2 04:22:18 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 02 Jan 2009 10:22:18 +0100 Subject: Switching user in a SSH connection In-Reply-To: References: Message-ID: <495DDCCA.60009@wildenhain.de> Shah Sultan Alam wrote: > Hi Group, > I am trying to connect to a Linux maching using paramiko. > and able to run a command like "ls -l" > > Now I want to switch user being in the connection ( eg running > something like "su -" ) > > Will you please let me know how to do that. You would for example run su - in that connection? Or sudo if installed and configured. What else would you need? Tino. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From sjmachin at lexicon.net Fri Jan 2 04:32:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 01:32:51 -0800 (PST) Subject: similar words index? References: Message-ID: <6736f1d6-c1ab-42cb-8c91-bf832bfd4f76@b41g2000pra.googlegroups.com> On Jan 2, 8:07?pm, robert wrote: > how can one index (text documents) for efficient similar word search? > existing modules? > what principles are used by search engines therefore? Only your second question is on-topic for this newsgroup. Try this: http://pylucene.osafoundation.org/ Looking at the site for Lucene itself, where you should find references to the various technologies they use, and some (definitely recommended) googling should give you some clues about your other questions. Some computer science topics are: Burkhard-Keller tree, Voronoi diagram/tree, permuted lexicon ... do bear in mind that what is actually used in the real-world search engines like Google may be rather difficult to find out; Google sure ain't open source, not any more. HTH, John From usenet-nospam at well-adjusted.de Fri Jan 2 04:54:59 2009 From: usenet-nospam at well-adjusted.de (Jochen Schulz) Date: Fri, 2 Jan 2009 10:54:59 +0100 Subject: similar words index? References: Message-ID: * robert: > how can one index (text documents) for efficient similar word search? > existing modules? I implemented one approach in mspace.py: http://well-adjusted.de/mspace.py/ But beware that it is pure Python and not optimized for speed. You gain quite a lot by having Psyco installed, though. J. -- I count my partner's eyelashes. [Agree] [Disagree] From code at pizzashack.org Fri Jan 2 05:39:15 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 04:39:15 -0600 Subject: why cannot assign to function call In-Reply-To: <200812301421.29888.mail@johnohagan.com> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: <20090102103915.GJ28417@dragontoe.org> On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > Fortunately, unlike the murky world of philosophy, Python (AIUI) > simplifies this question by simply declaring that yes, in the case > of mutable objects, we may say that we are still referring to the > same object although we've changed it, and no, in the case of > immutable objects, we may not, and must exchange it if we want a > different "value" (a word too fraught with ambiguity in this context > to use unquoted!). That's sort of true; it would seem to be more accurate to say that whenever a name is assigned to an object and subsequently reassigned, the name no longer is associated with the original object. In the case of mutable objects, the object can be changed by performing an assignment of *part* of the object through its original name, i.e. strings may be mutable, but the following code still produces two different objects: a = 'hello' a = 'goodbye' The first object so created is orphaned; it's been given the Russian non-person treatment. It still exists, but the authorities (i.e. the python interpreter) don't acknowledge it and provide the rest of the world no way to communicate with it, and eventually it is reaped by the garbage collector. :) What the Python community often overlooks, when this discussion again rears its ugly head (as it seems to every other hour or so), is that its assignment model is BIZARRE, as in it's conceptually different from virtually all other languages substantially taught in undergraduate computer science programs. And for that matter, it's pretty unintuitive generally. That is, in what I'll call "normal" computer languages, a variable name is thought of as the address of a bin where some data is stored, and the name is inexorably tied to that bin. You can change what's in the bin, but the name you gave the bin always points to the same bin. This tends to be conceptually true even if it might technically not be true in a given implementation of a language. Python is very different from this. Names are not addresses of bins; they are instead simply ephemeral labels which are given to bins, where the bin is a Python object which contains specific data at the time of assignment. A second assignment of that name doesn't change what's in the original bin; it actually (probably) first creates a new bin, then removes the name from the original bin and assigns it to the new one. Intuitively, it's a bit like saying your kitchen table is no longer a kitchen table, and now the thing where you wash your dishes is a kitchen table. It doesn't really make a lot of sense (whether or not it's so for good reason), and it makes describing the assignment model necessarily convoluted, whereas the "named bins" model from the majority of other languages people are likely to have been exposed to is simple and sensible. It's small wonder that neophytes try to cram Python behaviors into terms and computing concepts they already understand from learning other languages, and that they fail to do so. What's mystifying is that when Pythonistas reply to their messages, they universally seem confused at how this could possibly happen, and often enough actually seem offended (or at least offensive) when it inevitably does happen... -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From bearophileHUGS at lycos.com Fri Jan 2 05:43:41 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 02:43:41 -0800 (PST) Subject: similar words index? References: Message-ID: <4a1e6211-03b0-4c54-bdcb-54f04344dcc5@q26g2000prq.googlegroups.com> Jochen Schulz: > I implemented one approach in mspace.py: > http://well-adjusted.de/mspace.py/ > But beware that it is pure Python and not optimized for speed. You gain > quite a lot by having Psyco installed, though. Something similar, I haven't compared performance, Psyco helps a lot here too: http://code.activestate.com/recipes/572156/ (I have also implemented the same code in D language through a bridge created by Pyd, more than 100 times faster). Bye, bearophile From code at pizzashack.org Fri Jan 2 05:52:21 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 04:52:21 -0600 Subject: why cannot assign to function call In-Reply-To: <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: <20090102105221.GK28417@dragontoe.org> On a mostly not related note: On Tue, Dec 30, 2008 at 07:52:26AM -0800, Aaron Brady wrote: > According to some rules, these are ungrammatical sentences, due to > plurality disagreement. Ex: > > The Morning Star is ... > The Evening Star is ... > *The Morning Star and The Evening Star is... > *The Morning Star and The Evening Star are... > > Neither of the latter two is correct. (* marks ungrammatical.) As > such, the listener isn't sure what meaning to take. This statement is false. The latter of the two is grammatically correct. The subject is a compound subject joined by the conjunction "and" which indicates that there are two subjects, and thus the plural form of the verb is necessary and correct. > Identity isn't defined on math objects, only on Python objects; there > is no notion of 'is' in math. This is also false, it even has its own operator (which requires Unicode to display): ? Still, the point you're trying to make is right: this stuff is hard to talk about, and the model actually encourages the use of ambiguous or even contradictory explanations. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 06:15:25 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 12:15:25 +0100 Subject: Why not Ruby? In-Reply-To: <016d66f1$0$8693$c3e8da3@news.astraweb.com> References: <016d66f1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <495e04fb$0$24380$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 01 Jan 2009 10:35:54 -0800, r wrote: > (snip stupid troll) > > You really are an idiot. Steven, this bozo is just another Xah Lee, so don't waste your time with him. We all know how to deal with trolls, don't we ? From koranthala at gmail.com Fri Jan 2 06:31:17 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 2 Jan 2009 03:31:17 -0800 (PST) Subject: Python logging question Message-ID: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Hi, I was reading through Python Logging tutorial, and I found one scenario which I couldnt properly understand. The tutorial (http://docs.python.org/library/logging.html) mentions at first that -- "Multiple calls to getLogger() with the same name will return a reference to the same logger object". In an example for Python Logging Adapter, the tutorial then mentions that - "While it might be tempting to create Logger instances on a per- connection basis, this is not a good idea because these instances are not garbage collected". I am confused reading both together. I will try to explain my confusion with an example: basicLogger = logging.getLogger("basic") Class A(): def __init__(self): self.logger = logging.getLogger("basic.class_a") Now, I make say 10 instances of A and then delete one by one. My understanding was that since the same name is used, a single basic.class_a logger object is created inside the logging system, and any calls to getLogger("basic.class_a") would return the same object everytime. So, my confusion is based on the second tutorial item I mentioned - why is it not a good idea to create logger instances on a per-instance basis? We are not creating new instances, right? And, if I create an instance of A, it will be garbage collected later, right? Could somebody help me out? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 06:38:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 11:38:23 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> Message-ID: <016df39f$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 16:19:38 -0800, Fuzzyman wrote: > On Jan 2, 12:16?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 01 Jan 2009 12:32:53 -0800, Paul Rubin wrote: >> > On many occasions I've wished for a functional dictionary >> > implementation in Python, like Haskell's Data.Map. ?One of these >> > years I'll get around to writing one. >> >> You don't think Python's dict implementation is functional? That's >> pretty strange, Python dicts are the basis of much of the language. >> They certainly work, and work well, what makes you think they aren't >> functional? What does Data.Map do that dicts don't? >> >> > He almost certainly (I assume) means functional in the way that Haskell > is a functional language. *slaps head* D'oh! Er, I mean... Of course, I knew that, I was checking to see if anyone else did. *cough* -- Steven From hendrik.kaju at gmail.com Fri Jan 2 07:14:08 2009 From: hendrik.kaju at gmail.com (Hendrik Kaju) Date: Fri, 02 Jan 2009 14:14:08 +0200 Subject: Open Source survey Message-ID: <1230898448.7751.0.camel@gecko3> Dear developers My name is Hendrik Kaju and I am a high school student and an open source enthusiast (and a Python programmer) from Estonia. As a part of my school project, I am conducting a survey on open source software development (how developing OSS is related to a developer's day job, etc). It is located at http://www.surveygizmo.com/s/90385/open-source I would really appreciate it if you could take a few minutes to fill out this short survey. Best regards, Hendrik Kaju -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: See on s?numi digitaalselt allkirjastatud osa URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 07:45:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 12:45:36 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> Message-ID: <016e0360$0$8693$c3e8da3@news.astraweb.com> On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: > He was not cross posting. You don't actually know what cross-posting is, do you? You've just earned a plonking for the next month. Do try to have at least half a clue by February. -- Steven From vinay_sajip at yahoo.co.uk Fri Jan 2 08:21:35 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 2 Jan 2009 05:21:35 -0800 (PST) Subject: Python logging question References: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Message-ID: On Jan 2, 11:31 am, koranth... at gmail.com wrote: > I am confused reading both together. I will try to explain my > confusion with an example: > > basicLogger =logging.getLogger("basic") > > Class A(): > def __init__(self): > self.logger =logging.getLogger("basic.class_a") > > Now, I make say 10 instances of A and then delete one by one. > > My understanding was that since the same name is used, a single > basic.class_a logger object is created inside theloggingsystem, and > any calls to getLogger("basic.class_a") would return the same object > everytime. That is correct. The logger instances stay around for the life of the process, and are not garbage collected. > So, my confusion is based on the second tutorial item I mentioned - > why is it not a good idea to create logger instances on a per-instance > basis? We are not creating new instances, right? And, if I create an > instance of A, it will be garbage collected later, right? > It's not a problem to create loggers per *class*, as in your example. It can be a bad idea to create different logger per class *instances*. The second example in the docs talks about creating loggers on a per- connection basis in a networked app. This is not per connection class, mind you, but per connection instance. You would typically have only a few dozen classes, but you might have hundreds of thousands of connection instances created in a long-lived server app. If you created a unique logger for each connection, for example based on the time the connection was instantiated - e.g. with name "connection. 20090102123456543", this would create hundreds of thousands of unique logger instances and have a potentially adverse impact on process memory. That's when you use LoggerAdapters. I hope that's clearer. Regards, Vinay Sajip From koranthala at gmail.com Fri Jan 2 08:38:41 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 2 Jan 2009 05:38:41 -0800 (PST) Subject: Python logging question References: <11408251-edd9-451d-ac99-30ad081829d6@p2g2000prn.googlegroups.com> Message-ID: <4e629256-e620-4c80-900e-1e8d276bf0ac@d36g2000prf.googlegroups.com> On Jan 2, 6:21?pm, Vinay Sajip wrote: > On Jan 2, 11:31 am, koranth... at gmail.com wrote: > > > ? ? I am confused reading both together. I will try to explain my > > confusion with an example: > > > basicLogger =logging.getLogger("basic") > > > Class A(): > > ? def __init__(self): > > ? ? ?self.logger =logging.getLogger("basic.class_a") > > > ? ?Now, I make say 10 instances of A and then delete one by one. > > > My understanding was that since the same name is used, a single > > basic.class_a logger object is created inside theloggingsystem, and > > any calls to getLogger("basic.class_a") would return the same object > > everytime. > > That is correct. The logger instances stay around for the life of the > process, and are not garbage collected. > > > So, my confusion is based on the second tutorial item I mentioned - > > why is it not a good idea to create logger instances on a per-instance > > basis? We are not creating new instances, right? And, if I create an > > instance of A, it will be garbage collected later, right? > > It's not a problem to create loggers per *class*, as in your example. > It can be a bad idea to create different logger per class *instances*. > The second example in the docs talks about creating loggers on a per- > connection basis in a networked app. This is not per connection class, > mind you, but per connection instance. You would typically have only a > few dozen classes, but you might have hundreds of thousands of > connection instances created in a long-lived server app. If you > created a unique logger for each connection, for example based on the > time the connection was instantiated - e.g. with name "connection. > 20090102123456543", this would create hundreds of thousands of unique > logger instances and have a potentially adverse impact on process > memory. That's when you use LoggerAdapters. > > I hope that's clearer. > > Regards, > > Vinay Sajip Thank you very much Vinay. I was confused by the way it was mentioned in the tutorial. Again, Thank you Regards Koranthala From stef.mientki at gmail.com Fri Jan 2 08:39:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 02 Jan 2009 14:39:25 +0100 Subject: Triple quoted string in exec function ? In-Reply-To: <495A253B.6010003@gmail.com> References: <495A253B.6010003@gmail.com> Message-ID: <495E190D.2090904@gmail.com> Stef Mientki wrote: > hello, > > I'm running scripts, with the execute function (Python 2.5), > and it seems that triple quoted strings are not allowed. > > Is there a workaround, > or is this a fundamental problem of the exec-function ? > > thanks, > Stef Mientki thanks for all the answers, but I still don't understand it yet :-( So maybe someone could explain why the next few lines of code don't work: Code = '' Code += """multiline comment and more lines""" exec ( Code ) thanks, Stef Mientki From Brian.Kelly at uwsp.edu Fri Jan 2 09:09:26 2009 From: Brian.Kelly at uwsp.edu (Kelly, Brian) Date: Fri, 2 Jan 2009 08:09:26 -0600 Subject: FW: python import sys.path Message-ID: After following your suggestions I was able to confirm that the 2.5 interpreter was being invoked. So then I grepped for all instances of python in the scripts that were imported as modules: from bacula_conf import * The calling script cleanup.py is invoking purge_client.py like an external script: def purgeAll(options, computer_name): cmd = "python purge_client.py %s" % computer_name if options.pretend <> True: error = os.system(cmd) else: _log.info("Done. No changes made due to --pretend flag.") if not error: return True else: return False When I saw the imports I assumed the functions in purge_client.py were being referenced from the calling scripts symbol table. However, that is not the case. Thanks, Brian -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Tuesday, December 30, 2008 4:42 PM To: python-list at python.org Subject: Re: python import sys.path On Dec 31, 5:05?am, "Kelly, Brian" wrote: > I have both 2.4 and 2.5 interpreters installed on a linux box. The > PythonPath is set to : > > PYTHONPATH=/usr/lib64/portage/pym:/prod/bacula/local/lib64/python2.4/site-pa > ckages:/prod/bacula/local/lib/python2.4/site-packages > > My main script is getting called like so: > > python2.4 cleanup.py wrkstnbs > > The imports statements in cleanup.py are as follows: > > import os,sys > print sys.path > from datetime import datetime > from optparse import OptionParser ? ? ? ?# used for parsing parameters > from bacula_conf import * ? ? ? ? ? ? ? ?# used for connecting to our > databases, etc. > from registration_cleanup \ > ? ? import RegistrationCleanup ? ? ? ? ? # used for interacting w/ > registration db (sql1) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# and configuration database > (genunix) > import directory_cleanup as fclean ? ? ? # file cleanup. > > One of the scripts being imported from bacula_conf is called > purge_client.py. > > It has the following imports: > > import sys > import MySQLdb > > Everytime I run "python2.4 cleanup.py wrkstnbs" I get the following error: > > Traceback (most recent call last): Have you snipped any traceback entries here? You say you are running cleanup.py but the first traceback entry is from purge_client.py!! You should first fix that, so that you've got the full story. My guess is that something along that trail is invoking another instance of the Python interpreter and somehow that instance is 2.5, not 2.4. I can't imagine how those 2.5-related entries would otherwise get into sys.path Suggestions: (1) where you are debug-printing sys.path, also print sys.version and sys.argv[0] ... and do debug-printing at more places between start and error. (2) run "python2.4 -vv cleanup.py wrkstnbs" and look for the first mention of 2.5 (indicating something has manipulated sys.path), or sudden cessation of -vv output (indicating a new instance of python is running without -vv), or some other phenomenon ... > ? File "purge_client.py", line 22, in > ? ? import MySQLdb > ? File > "/prod/bacula/local/lib64/python2.4/site-packages/MySQLdb/__init__.py", line > 27, in > ? ? import _mysql > ImportError: /prod/bacula/local/lib64/python2.4/site-packages/_mysql.so: > undefined symbol: Py_InitModule4 What happens when you run python2.4 and at the interactive prompt do >>> import _mysql ? Is there a possibility that you installed 2.5 MySQLdb into the 2.4 hierarchy? [could be a stupid question from a windows guy; this may be a non-problem on linux] Is this the first thing that you've tried after installing 2.5, or the only problem found in an exhaustive regression test of all your apps using 2.4, or somewhere in the middle? [big snip] HTH, John -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 5082 bytes Desc: not available URL: From sjmachin at lexicon.net Fri Jan 2 09:18:06 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 06:18:06 -0800 (PST) Subject: Triple quoted string in exec function ? References: <495A253B.6010003@gmail.com> Message-ID: On Jan 3, 12:39?am, Stef Mientki wrote: > Stef Mientki wrote: > > hello, > > > I'm running scripts, with the execute function (Python 2.5), > > and it seems that triple quoted strings are not allowed. > > > Is there a workaround, > > or is this a fundamental problem of the exec-function ? > > > thanks, > > Stef Mientki > > thanks for all the answers, > but I still don't understand it yet :-( > So maybe someone could explain why the next few lines of code don't work: Stef, "it doesn't work" is user-speak. Say what what you expected, and what happened instead. > Code = '' > Code += """multiline comment > and more lines""" > exec ( Code ) That is equivalent to: code = "multiline comment\nand morelines" exec(code) which of course produces a Syntax Error. What did you expect? Oh, yeah, the so-called "multiline comment". I can't imagine why you want to put comments in code that you're going to exec, but you need an extra layer of quotes: Code += '''"""multiline comment and more lines"""''' From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 09:24:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jan 2009 14:24:39 GMT Subject: Triple quoted string in exec function ? References: <495A253B.6010003@gmail.com> Message-ID: <016e1a94$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 14:39:25 +0100, Stef Mientki wrote: > thanks for all the answers, > but I still don't understand it yet :-( So maybe someone could explain > why the next few lines of code don't work: > > Code = '' > Code += """multiline comment > and more lines""" > exec ( Code ) You don't actually tell us what you expect to happen, so I'm going to take a wild guess. You are expecting that the contents of Code above should be a triple-quoted string, which Python treats as a comment when it is on its own (unless it is a doc string). A clue as to what is going on: >>> s = "x = 1" >>> print s x = 1 >>> exec s >>> x 1 Notice that even though the string s is created with delimiters ", the quote marks are not part of the string. Whether you use delimiters " ' ''' or """ doesn't matter, the delimiters are not part of the string. If you want quote marks *inside* the string, you need to include them as characters, not as delimiters: >>> s = "y = " # using " as delimiters >>> s += 'abc' # using ' as delimiters >>> print s # no quotes inside s y = abc >>> exec s Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'abc' is not defined >>> s = "y = " >>> s += '"abc"' # quotes inside the string >>> print s # includes quotes inside s y = "abc" >>> exec s >>> y 'abc' The fact that your earlier example used """ as delimiters instead of " is irrelevant. The delimiters are not part of the string, and so aren't seen by exec. There's no problem with exec and triple-quoted strings. You're just not giving it a triple-quoted string to work with. Another thing, you wrote: Code = '' Code += """multiline comment and more lines""" That's a little like saying: x = 0 x += 1 instead of just x = 1. Except that in general, string concatenation is potentially MUCH MUCH MUCH slower than addition. (If you haven't noticed the slow down, you're lucky you haven't hit the right circumstances.) s = """multiline comment and more lines""" makes a string s that starts with the letter m: >>> print s multiline comment and more lines That's no different from any other string delimiters. The delimiters are never part of the string. You want the string to start with three quotation marks, not m, so you have to include the quote marks inside the string. To do that, you need to use two different quote delimiters: >>> s = """'''multiline comment ... and more lines'''""" >>> print s '''multiline comment and more lines''' >>> exec s >>> Works perfectly. -- Steven From steve at holdenweb.com Fri Jan 2 09:25:32 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 09:25:32 -0500 Subject: If your were going to program a game... In-Reply-To: <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> References: <75b8e3d7-ee9f-46ea-a7ba-4c218608c18f@v13g2000yqm.googlegroups.com> <4c2e9395-2261-4114-b64a-6018852f1145@p2g2000prn.googlegroups.com> Message-ID: Aaron Brady wrote: > On Jan 1, 2:55 pm, "Chris Rebert" wrote: >> On Thu, Jan 1, 2009 at 12:24 PM, excord80 wrote: >>> On Jan 1, 2:37 pm, Kay Schluehr wrote: >>>> There is no solution to this problem from a Python perspective. Do >>>> what everyone does right now: [snip] >>> It still surprises me that no one has implemented the solution for >>> this yet. >>> Maybe it's harder than it seems, but it *seeems* like it's just a >>> matter of telling Firefox, "hey, when you see this special html >>> element that tells you to run this python code from the web, do it". >>> Then have FF load up a python interpreter, sandbox it somehow (that >>> is, limit it to only a safe subset of its std lib), it runs the code >> The "sandbox it somehow" part is significantly harder than you seem to >> believe it would be. Python tried previously with the rexec and >> Bastion modules, but they were found to be irreparably flawed and thus >> were removed. > > Suppose you compiled a version with no file type and a reduced os > module? "Cars are dangerous". "Yes, but suppose you made them completely elastic". Sheesh. The developers are way less dumb than you seem to believe. Suppose you did compile a version with no file type and a reduce os module? Perhaps you would like to do some research into *why* rexec and bastion were dropped from the implementation. Or read Brett Cannon's work on "safe" execution of arbitrary Python. That way you would stop making fatuous suggestions that don't help anybody. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Fri Jan 2 09:28:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 06:28:15 -0800 (PST) Subject: FW: python import sys.path References: Message-ID: <68177ab8-f073-4767-86b6-9abf8c331e36@r10g2000prf.googlegroups.com> On Jan 3, 1:09?am, "Kelly, Brian" wrote: > After following your suggestions I was able to confirm that the 2.5 > interpreter was being invoked. So then I grepped for all instances of python > in the scripts that were imported as modules: from bacula_conf import * > > The calling script cleanup.py is invoking purge_client.py like an external > script: > > def purgeAll(options, computer_name): > ? ? cmd = "python purge_client.py %s" % computer_name > ? ? if options.pretend <> True: Who wrote that? > ? ? ? ? error = os.system(cmd) > ? ? else: > ? ? ? ? _log.info("Done. No changes made due to --pretend flag.") #### error is not defined in this branch > ? ? if not error: #### Splat! > ? ? ? ? return True > ? ? else: > ? ? ? ? return False AArrgh! Try: return not error > When I saw the imports I assumed the functions in purge_client.py were being > referenced from the calling scripts symbol table. What does that mean?? From excord80 at gmail.com Fri Jan 2 09:49:03 2009 From: excord80 at gmail.com (excord80) Date: Fri, 2 Jan 2009 06:49:03 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> Message-ID: On Jan 1, 11:40?pm, Graham Dumpleton wrote: > On Jan 2, 2:28?pm, excord80 wrote: > > > > > On Jan 1, 9:12?pm, s... at pobox.com wrote: > > > > ? ? >>http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html > > > > ? ? >> and he mentions a neat-looking project called ``mod_perlite``. It > > > ? ? >> sounds like it will be very handy. Anyone working on a > > > ? ? >> ``mod_pylite``? ?Has it been done before, maybe under a different > > > ? ? >> name? > > > > It's kind of hard to tell. ?There's very little description of how > > > mod_perlite would be different than mod_perl other than it would be more > > > lightweight, presumably as mod_php somehow is. ?That hardly seems like a > > > well-defined requirement document. > > > > Doesmod_wsgifit the bill?http://www.rkblog.rk.edu.pl/w/p/mod_wsgi/ > > > I'm not sure if it fits the bill or not. The bill is two-fold: > > > 1. The Apache module should present little risk to the admin who > > installs it. That is, it should not expose Apache's innards. > > > 2. The Apache module should keep a Python instance running; run, for > > example, ``foo.py`` when a user accesses (for example) ``http://www.example.com/path/to/foo.py?baz=88``; pass baz=88 to foo.py in the > > usual way; and return whatever html that script spits out. > > > I'm not familiar with php or ``mod_php``, but I suspect that setup > > does something very similar to what's described above. This might > > explain why it's so blasted easy to deploy php scripts and create > > small and simple sites (and even not-so-small/simple sites) with it. > > > Doesmod_wsgifit that bill? I don't know. [snip] > > Have you looked up what the WSGI specification for Python even is? > > ?http://www.python.org/dev/peps/pep-0333/ > ?http://www.wsgi.org/wsgi/Learn_WSGI > Hi Graham, thanks for the links. I took a quick look at some of the articles on the Learn_WSGI page, but regrettably, my free time for this stuff has evaporated for now. > If you understand what WSGI is, then you will realise that mod_wsgi is > a very slim adapter for Apache that allows one to host any WSGI > application. [snip] > > All WSGI is about > is providing a most minimal interface for communicating with the web > server, It sounds interesting, however, after reading a bit about it, I see that a large part of wsgi is providing a nice interface between web server and webapp. I don't think I need any such interface, or at least, a replacement for CGI. I just need something like CGI but with a persistent Python so the web server doesn't have to restart python for every request. And I don't need need it to work with anything else other than Apache. I think that actually probably sums up what a lot of users want. For better or worse, most people use Apache. Apache works and is free software. And it's either already installed, or easy to install. And shared hosting providers already have it available. > This doesn't mean you couldn't use mod_wsgi to effectively achieve the > same thing though, [snip] I can't say I understand the details of wsgi, but if it does what I'm asking, and if shared hosting providers can be coaxed into installing mod_wsgi, then I think a fast-track to wide adoption for wsgi would be to provide an out-of-the-box drop-in little-to-no-configuration- required solution for getting php-style small webapps going as described above. If your answer to that is, "Oh no! WSGI is more general than that! You can do it, but can also do X, Y, Z ...", then I'm sorry, but I don't have the time right now to learn about all the details, and about things like Paste and middleware. Again, I'm only using Apache, and I only want the script to run when I access it in a url and to get its output back to the browser. Yes, I realize this is bush-league, but the php folks have been doing it for a long while now, and it works ok for small webapps and shared hosting setups, so I'm reluctant to thumb my nose at it. > If you want to talk more about this, come over to the mod_wsgi list on > Google Groups. Thank you, but, as I mentioned, my free time right now is in the negative numbers. Bleh. I wish it weren't so. From geekmail at usenot.de Fri Jan 2 10:00:14 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 16:00:14 +0100 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> Message-ID: <20090102160014.47a330c5@usenot.de> On 02 Jan 2009 12:45:36 GMT Steven D'Aprano wrote: > You've just earned a plonking for the next month. Do try to have at > least half a clue by February. I will state again that there seems to have been a slight change of tone in clp lately. How about we Python guys work a bit harder on not calling each other names and such? Not that I have a particular problem with *what* Steven said here, but it could have been phrased a tad more calmly, just for the sake of not stirring up unnecessary feelings of defiance. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From BrooklineTom at gmail.com Fri Jan 2 10:01:33 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Fri, 2 Jan 2009 07:01:33 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: On Dec 31 2008, 9:56 am, John Machin wrote: > On Dec 31 2008, 4:02 pm, brooklineTom wrote: > > > andyh... at gmail.com wrote: > > > Hi, > > > > Can anybody recommend an approach for loading and parsing Excel > > > spreadsheets in Python. Any well known/recommended libraries for this? > > > > The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, > > > but I'd rather get some more input before going with something I don't > > > know. > > > > Thanks, > > > Andy. > > > I save the spreadsheets (in Excel) in xml format. > > Which means that you need to be on a Windows box with a licensed copy > of Excel. I presume you talking about using Excel 2003 and saving as > "XML Spreadsheet (*.xml)". Do you save the files manually, or using a > COM script? What is the largest xls file that you've saved as xml, how > big was the xml file, and how long did it take to parse the xml file? > Do you extract formatting information or just cell contents? 1. The OP requested Excel files, by construction those must be generated with a licensed copy of Excel. I did the actual processing on both linux and windoze platforms. 2. Yes, I used Excel 2003. I haven't looked at later versions. 3. The largest file I used was about 228M, containing 36,393 hotel properties from Commission Junction. Each entry had 113 cells. The parsing overhead was minimal (on a per-entry basis) -- that's why I choose to use a pull-parser. 4. I extracted primarily cell contents, though I did some very limited format handling (looking for non-text fields and such). > > I started with the > > standard xml tools (xml.dom and xml.dom.minidom). I built a > > pullparser, and then just crack them. The MS format is tedious and > > overly complex (like all MS stuff), but straightforward. > > What do you think of the xml spat out by Excel 2007's (default) xlsx > format? I haven't looked at this. > > Once I've > > cracked them into their component parts (headers, rows, cells, etc), > > then I walk through them doing whatever I want. > > > I found this material to be no worse than doing similar crud with > > xhtml. I know there are various python packages around that do it, but > > I found the learning curve of those packages to be steeper than just > > grokking the spreadsheet structure itself. > > I'm curious to know which are the "various python packages" with the > so steep learning curves, and what the steep bits were. I looked, briefly, at xlrd. I found and scanned a few alternatives, though I don't remember what the others were. I needed something I could incorporate into my own application framework, and I knew I didn't need most of the formatting information. I'm not in any way criticizing xlrd, it's simply that, based on its API summary, it seems focused on problems I didn't have to solve. I knew that I needed only a small subset of the xlrd behavior, and I concluded (perhaps incorrectly) that it would be easier to roll my own parser than find, extract, and then port (to my own framework) the corresponding parts of xlrd. I needed to extract the content of each row, cell by cell, and build data objects (in my framework) with the content of various cells. I also needed to build an "exception file" containing malformed entries that I could re-open with Excel after my code finished, so that the bogus entries could be manually corrected. What I mean by "malformed" entry is, for example, an address field that fails to correctly geocode or comment fields with confused utf8/unicode contents. My focus was on data content, as opposed to presentation. I needed to crack the cells into things like "string", "boolean", "float", and so on. Most importantly, I needed to do this one entry at a time -- I did *not* want to load the entire spreadsheet at once. I'm not saying that this couldn't be done with xlrd; only that I chose to roll my own and had minimal difficulty doing so. I hope this helps! From james at agentultra.com Fri Jan 2 10:02:10 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 10:02:10 -0500 Subject: If your were going to program a game... References: Message-ID: <85eizlhhu5.fsf@dozer.localdomain> Tokyo Dan writes: > If your were going to program a game in python what technologies would > you use? > > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. Ever see chess.com? I don't know what they're using in the backend, but the client is entirely javascript. You could probably roll your own python javascript compiler to suit your needs. It could probably even build up your own DSL for writing these games. It's a worthwhile project and I think there might be support for it from other developers. From vinay_sajip at yahoo.co.uk Fri Jan 2 10:20:39 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 2 Jan 2009 07:20:39 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'DatagramHandler' (ubuntu-8.10, python 2.5.2) References: <4c6f0831-c05f-401f-b956-376600b38e06@r15g2000prd.googlegroups.com> Message-ID: <5958c48b-721e-45ae-9951-825317a7d0d5@g3g2000pre.googlegroups.com> On Dec 29 2008, 12:18 pm, "Chris Rebert" wrote: > > "The StreamHandler and FileHandler classes are defined in the coreloggingpackage. The other handlers are defined in a sub- module,logging.handlers." > > There's your answer. I do agree though that the "classlogging.DatagramHandler" line in the docs is misleading to say the > least. Perhaps a docs bug should be filed... > This should now be fixed in the current docs - thanks to Georg Brandl (creator of the Python documentation system). Regards, Vinay Sajip From victorsubervi at gmail.com Fri Jan 2 10:24:59 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 2 Jan 2009 16:24:59 +0100 Subject: =?ISO-8859-1?Q?Re:_Can=B4t_Surf_Python_Pages_in_Windoze?= In-Reply-To: References: <4dc0cfea0812260701q6baf0ccbj154c5b3fa2281cdb@mail.gmail.com> <4954FB9F.5050702@wildenhain.de> <4dc0cfea0812260911k4dbc0f2ame9cc874e067b7816@mail.gmail.com> Message-ID: <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> On Fri, Dec 26, 2008 at 8:00 PM, Gabriel Genellina wrote: > En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi < > victorsubervi at gmail.com> escribi?: > >> On 12/26/08, Tino Wildenhain wrote: >> > > print "Content-Type: text/html" >>>> print >>>> print """ >>>> >>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>> >>> > I think there should be only one blank line between header and content, you > have two (so the document contains an empty line before the doctype > declaration, and I think this is invalid). > Will try. Thanks. Let you know next week if problem. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From mamingcao at gmail.com Fri Jan 2 10:45:10 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:45:10 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop Message-ID: Hi all, I'm new to here and python. When I tried the code below to test python's speed... I found that python use more than 1.5G memory to run this and cost several minutes.... And this happened only under my linux os. Both jython and python... Is there something wrong with python under linux or my code? Thanks! a = 0 for i in range(100000000): a = a + 1 print a From michele.simionato at gmail.com Fri Jan 2 10:49:02 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 2 Jan 2009 07:49:02 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: On Jan 2, 4:45?pm, ming_cuhk wrote: > Hi all, I'm new to here and python. > When I tried the code below to test python's speed... > I found that python use more than 1.5G memory to run this and cost > several minutes.... And this happened only under my linux os. Both > jython and python... ?Is there something wrong with python under linux > or my code? > Thanks! > > a = 0 > for i in range(100000000): > ? ? a = a + 1 > print a This is fixed in Python 3.0. In older Python versions, use xrange instead of range. From mamingcao at gmail.com Fri Jan 2 10:50:32 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:50:32 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: On Jan 2, 11:49?pm, Michele Simionato wrote: > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > Hi all, I'm new to here and python. > > When I tried the code below to test python's speed... > > I found that python use more than 1.5G memory to run this and cost > > several minutes.... And this happened only under my linux os. Both > > jython and python... ?Is there something wrong with python under linux > > or my code? > > Thanks! > > > a = 0 > > for i in range(100000000): > > ? ? a = a + 1 > > print a > > This is fixed in Python 3.0. In older Python versions, use > xrange instead of range. Thanks! But this isn't appear in MAC and Windows~? From michele.simionato at gmail.com Fri Jan 2 10:52:18 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 2 Jan 2009 07:52:18 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: Message-ID: <7eb33c9d-4105-4671-828d-20ff9b5ff485@t39g2000prh.googlegroups.com> On Jan 2, 4:50?pm, ming_cuhk wrote: > On Jan 2, 11:49?pm, Michele Simionato > wrote: > > > > > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > > Hi all, I'm new to here and python. > > > When I tried the code below to test python's speed... > > > I found that python use more than 1.5G memory to run this and cost > > > several minutes.... And this happened only under my linux os. Both > > > jython and python... ?Is there something wrong with python under linux > > > or my code? > > > Thanks! > > > > a = 0 > > > for i in range(100000000): > > > ? ? a = a + 1 > > > print a > > > This is fixed in Python 3.0. In older Python versions, use > > xrange instead of range. > > Thanks! But this isn't appear in MAC and Windows~? It should happen on all platforms, since you are building a list with 100 millions of integers, which is quite large, especially if you are running on a 64 bit OS. From mamingcao at gmail.com Fri Jan 2 10:57:24 2009 From: mamingcao at gmail.com (ming_cuhk) Date: Fri, 2 Jan 2009 07:57:24 -0800 (PST) Subject: Unreasonable memory usage under linux with a simple loop References: <7eb33c9d-4105-4671-828d-20ff9b5ff485@t39g2000prh.googlegroups.com> Message-ID: <6021cfa9-3f45-4503-9a26-ffc8c95847ca@y1g2000pra.googlegroups.com> On Jan 2, 11:52?pm, Michele Simionato wrote: > On Jan 2, 4:50?pm, ming_cuhk wrote: > > > > > On Jan 2, 11:49?pm, Michele Simionato > > wrote: > > > > On Jan 2, 4:45?pm, ming_cuhk wrote: > > > > > Hi all, I'm new to here and python. > > > > When I tried the code below to test python's speed... > > > > I found that python use more than 1.5G memory to run this and cost > > > > several minutes.... And this happened only under my linux os. Both > > > > jython and python... ?Is there something wrong with python under linux > > > > or my code? > > > > Thanks! > > > > > a = 0 > > > > for i in range(100000000): > > > > ? ? a = a + 1 > > > > print a > > > > This is fixed in Python 3.0. In older Python versions, use > > > xrange instead of range. > > > Thanks! But this isn't appear in MAC and Windows~? > > It should happen on all platforms, since you are building > a list with 100 millions of integers, which is quite large, > especially if you are running on a 64 bit OS. You are right...Thanks.... Since my MAC have too much RAM..I didn't notice it.... From luke.leighton at googlemail.com Fri Jan 2 11:05:03 2009 From: luke.leighton at googlemail.com (lkcl) Date: Fri, 2 Jan 2009 08:05:03 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> <67d1e9f1-5515-47ea-a0c1-1e8faf9c056c@a12g2000pro.googlegroups.com> <116206d0-c276-4df0-9d8a-3d08a168c207@w39g2000prb.googlegroups.com> <05e462b7-cfab-4f37-b545-bdff51f0e684@a12g2000pro.googlegroups.com> Message-ID: <8f510c9a-3c35-4f93-8e69-43adb5d1fa50@u18g2000pro.googlegroups.com> On Jan 1, 4:44 pm, Mike Driscoll wrote: > On Jan 1, 7:47 am,lkcl wrote: > > > > > On Dec 31 2008, 9:54 pm, Mike Driscoll wrote: > > > > On Dec 31, 3:36 pm,lkcl wrote: > > > > > hiya mike: where do i know you from? i've heard your name somewhere > > > > and for the life of me can't remember where! anyway... onwards. > > > > I don't know...while your username looks vaguely familiar, I don't > > > think I've communicated with you recently. I spend most of my time on > > > the wxPython list now... > > > i think it might be from my old school - i could be confusing you > > with > > someone, though - "gary driscoll", perhaps? anyway, never mind :) > > > > > testing: you should really use a debootstrap absolute "basic" > > > > environment (set up a chroot, or a virtual KVM or other virtual PC, > > > > qemu, whatever, or even a real machine) do NOT do a "full" install of > > > > ubuntu, do an absolute minimalist install (netbook, businesscard, > > > > whatever). > > > > I thought the general practice was to test on the closest software/ > > > hardware combo that your application was most likely to run on. > > > that you should do as well :) you should be able to either upgrade > > the bare-bones version using "tasksel install desktop" or just... > > what-the-heck, install on a vanilla combo. > > > http://archive.ubuntu.com/ubuntu/dists/intrepid/main/installer-i386/c... > > > archive.ubuntu.com appears offline at the moment - maybe it'll be > > back later. i recommend you go for the mini.iso > > Ok...thanks for the info! > > > > I have > > > heard of doing testing on the lowest common denominator before though. > > > Unfortunately, I don't have time to set up a bare-bones VM since we're > > > closing soon, but I may give this a go on Friday and report back. > > > ok - the issue that you will face if you _don't_ do a LCD test is > > that > > should ubuntu get upgraded, and one of the packages that _used_ to > > pull > > in a dependency [that you missed] no longer does so... > > I see. I had hoped that there was a way to create a frozen application > like I do with py2exe on Windows so I wouldn't have to worry about a > Linux upgrade breaking my application. I've been told that ok - to do _that_, you will have to download copies of every single library that your app uses, compile them specially into a customised location (/opt/local or /usr/local); you will have to then make sure that PYTHONPATH environment variable is set to point to the locations. from a random manual somewhere: The PYTHONPATH variable can be set to a list of paths that will be added to the beginning of sys.path. For example, if PYTHONPATH is set to "/www/python:/opt/py", the search path will begin with ['/www/ python', '/opt/py']. (Note that directories must exist in order to be added to sys.path; the site module removes paths that don't exist.) having multiple copies of python libraries on your system was exactly the thing that i recommended that you _not_ do :) because you _still_ have to install them, and the process to do _that_ easily, on ubuntu, is "apt-get install" - so why bother duplicating that effort? path of least resistance says "go with the debian flow". well... it does in my book, anyway :) l. From darcy at druid.net Fri Jan 2 11:14:33 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 2 Jan 2009 11:14:33 -0500 Subject: Please show some restraint (Was: Why not Ruby?) In-Reply-To: References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <20090102111433.2e64afa3.darcy@druid.net> On Fri, 02 Jan 2009 00:57:06 +0100 Richard Riley wrote: > You clearly have a personal issue with Xah Lee. Possibly it is better > you killfile him or your spring will over wind :-; What good does a killfile do if people insist on repeating his posts in their entirety? Please people, try to resist the urge to reply to every post that raises your blood pressure a point or two but if you must reply, please trim. Anyone can always go back and review a previous message if they need more context. Heck, we can even review messages posted by people in our killfile. Personally, if I can't see your reply without scrolling down I just tend to hit the delete key. That means that thanks to you non-trimmers I get to read Xah posts over and over but never get to see your witty, entertaining and educational replies. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rcmn73 at gmail.com Fri Jan 2 11:19:01 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 08:19:01 -0800 (PST) Subject: Py2exe issue Message-ID: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> I'm using 2.6 (the issue was the same with 2.5) script.py: [code]import re from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", action="store", type="string", dest="filename") parser.add_option("-o", "--output", action="store", type="string", dest="fileout") (options, args) = parser.parse_args() from subprocess import Popen, PIPE if options.fileout: fileoutput = options.fileout output = open(fileoutput, "w") else: output = open("output.txt", "w") if options.filename: rawfile = options.filename file = open(rawfile) else: print "type -h for help" exit() from threading import Thread class Pinger(object): def __init__(self, hosts): for host in hosts: pa = PingAgent(host) pa.start() class PingAgent(Thread): def __init__(self, host): Thread.__init__(self) self.host = host def run(self): p = Popen('ping -n 1 ' + self.host, stdout=PIPE, stderr=True) m = re.search('Average = (.*)ms', p.stdout.read()) if m: output.write (self.host+",pingable\n") else: output.write (self.host+",not pingable\n") if __name__ == '__main__': pinglist = [] for line in file: pinglist.append(line.strip("\n")) Pinger(pinglist)[/code] py2exe setup.py : [code]from distutils.core import setup import py2exe, sys, os sys.argv.append('py2exe') setup( options = {'py2exe': {'bundle_files': 1}}, console = [{'script': "script.py"}], zipfile = None, ) [/code] error when the "script.exe" run [code]Exception in thread Thread-500 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "threading.pyc", line 522, in __bootstrap_inner File "script.py", line 35, in run File "subprocess.pyc", line 588, in __init__ [/code] So the script.py run perfectly well under the py environment but if i use py2exe to make an exe then i get the error above. I read the note in the py2exe Fac regarding Popen, but i don't know if it's relevant in my case. From kyosohma at gmail.com Fri Jan 2 11:26:13 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Fri, 2 Jan 2009 08:26:13 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> Message-ID: <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> On Jan 2, 10:19?am, rcmn wrote: > I'm using 2.6 (the issue was the same with 2.5) > > script.py: > > [code]import re > > from optparse import OptionParser > parser = OptionParser() > parser.add_option("-f", "--file", action="store", type="string", > dest="filename") > parser.add_option("-o", "--output", action="store", type="string", > dest="fileout") > (options, args) = parser.parse_args() > > from subprocess import Popen, PIPE > if options.fileout: > ? ? ? ? fileoutput = options.fileout > ? ? ? ? output = open(fileoutput, "w") > else: > ? ? ? ? output = open("output.txt", "w") > if options.filename: > ? ? ? ? rawfile = options.filename > ? ? ? ? file = open(rawfile) > else: > ? ? ? ? print "type -h for help" > ? ? ? ? exit() > > from threading import Thread > class Pinger(object): > ? ? def __init__(self, hosts): > ? ? ? ? for host in hosts: > ? ? ? ? ? ? pa = PingAgent(host) > ? ? ? ? ? ? pa.start() > > class PingAgent(Thread): > ? ? def __init__(self, host): > ? ? ? ? Thread.__init__(self) > ? ? ? ? self.host = host > > ? ? def run(self): > ? ? ? ? p = Popen('ping -n 1 ' + self.host, stdout=PIPE, stderr=True) > ? ? ? ? m = re.search('Average = (.*)ms', p.stdout.read()) > ? ? ? ? if m: > ? ? ? ? ? ? ? ? ? ? ? ? output.write (self.host+",pingable\n") > ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? output.write (self.host+",not pingable\n") > > if __name__ == '__main__': > ? ? ? ? pinglist = [] > ? ? ? ? for line in file: > ? ? ? ? ? ? ? ? pinglist.append(line.strip("\n")) > ? ? ? ? Pinger(pinglist)[/code] > > py2exe setup.py : > > [code]from distutils.core import setup > import py2exe, sys, os > > sys.argv.append('py2exe') > > setup( > ? ? ?options = {'py2exe': {'bundle_files': 1}}, > ? ? ?console = [{'script': "script.py"}], > ? ? ?zipfile = None, > ?) > [/code] > > error when the "script.exe" run > [code]Exception in thread Thread-500 (most likely raised during > interpreter shutdown): > Traceback (most recent call last): > ? File "threading.pyc", line 522, in __bootstrap_inner > ? File "script.py", line 35, in run > ? File "subprocess.pyc", line 588, in __init__ > [/code] > > So the script.py run perfectly well under the py environment but if i > use py2exe to make an exe then i get the error above. > I read the note in the py2exe Fac regarding Popen, but i don't know if > it's relevant in my case. Try it with bundle_files option 3 instead of 1. Also what version of py2exe are you using? Mike From steve at holdenweb.com Fri Jan 2 11:32:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:32:39 -0500 Subject: Parsing Excel spreadsheets In-Reply-To: References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <495E41A7.1050503@holdenweb.com> brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: >> On Dec 31 2008, 4:02 pm, brooklineTom wrote: >> >>> andyh... at gmail.com wrote: >>>> Hi, >>>> Can anybody recommend an approach for loading and parsing Excel >>>> spreadsheets in Python. Any well known/recommended libraries for this? >>>> The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, >>>> but I'd rather get some more input before going with something I don't >>>> know. >>>> Thanks, >>>> Andy. >>> I save the spreadsheets (in Excel) in xml format. >> Which means that you need to be on a Windows box with a licensed copy >> of Excel. I presume you talking about using Excel 2003 and saving as >> "XML Spreadsheet (*.xml)". Do you save the files manually, or using a >> COM script? What is the largest xls file that you've saved as xml, how >> big was the xml file, and how long did it take to parse the xml file? >> Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. Well, even if Andy meant "Excel files" rather than "Excel-formatted files" there are many ways to come by these without having a licensed copy of Excel. FTP and email attachment come to mind most readily. How then to convert those to XML without Excel? [...]> I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. > My own case was similar, in that I only needed the value data. The approach I took was to install xlrd and use it. Job done. > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > My data files weren't that large (IIRC the largest spreadsheet was about 6MB), so I was quite happy to load the whole thing in memory, iterate over it and then write the results to the database as they were extracted. > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > Given the constraints of your problem it seems like an intelligent approach. > I hope this helps! I'm sure it will. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 11:32:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:32:39 -0500 Subject: Parsing Excel spreadsheets In-Reply-To: References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <495E41A7.1050503@holdenweb.com> brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: >> On Dec 31 2008, 4:02 pm, brooklineTom wrote: >> >>> andyh... at gmail.com wrote: >>>> Hi, >>>> Can anybody recommend an approach for loading and parsing Excel >>>> spreadsheets in Python. Any well known/recommended libraries for this? >>>> The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, >>>> but I'd rather get some more input before going with something I don't >>>> know. >>>> Thanks, >>>> Andy. >>> I save the spreadsheets (in Excel) in xml format. >> Which means that you need to be on a Windows box with a licensed copy >> of Excel. I presume you talking about using Excel 2003 and saving as >> "XML Spreadsheet (*.xml)". Do you save the files manually, or using a >> COM script? What is the largest xls file that you've saved as xml, how >> big was the xml file, and how long did it take to parse the xml file? >> Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. Well, even if Andy meant "Excel files" rather than "Excel-formatted files" there are many ways to come by these without having a licensed copy of Excel. FTP and email attachment come to mind most readily. How then to convert those to XML without Excel? [...]> I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. > My own case was similar, in that I only needed the value data. The approach I took was to install xlrd and use it. Job done. > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > My data files weren't that large (IIRC the largest spreadsheet was about 6MB), so I was quite happy to load the whole thing in memory, iterate over it and then write the results to the database as they were extracted. > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > Given the constraints of your problem it seems like an intelligent approach. > I hope this helps! I'm sure it will. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 11:43:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 11:43:30 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102103915.GJ28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: [...] > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. > I'd definitely argue against bizarre. It's actually very easy to understand, and Python is by no means the only language to have used it. > That is, in what I'll call "normal" computer languages, a variable > name is thought of as the address of a bin where some data is stored, > and the name is inexorably tied to that bin. You can change what's in > the bin, but the name you gave the bin always points to the same bin. > This tends to be conceptually true even if it might technically not be > true in a given implementation of a language. > I'd argue that this approach is out of date and overly-restrictive, requiring data copying not required by the Python data model and running the risk, in the absence of such copying, of returning invalid references (the C++ "dangling pointer" issue being the best-known manifestation of such problems). > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, > where the bin is a Python object which contains specific data at the > time of assignment. A second assignment of that name doesn't change > what's in the original bin; it actually (probably) first creates a new > bin, then removes the name from the original bin and assigns it to > the new one. Intuitively, it's a bit like saying your kitchen table > is no longer a kitchen table, and now the thing where you wash your > dishes is a kitchen table. It doesn't really make a lot of sense > (whether or not it's so for good reason), and it makes describing the > assignment model necessarily convoluted, whereas the "named bins" > model from the majority of other languages people are likely to have > been exposed to is simple and sensible. > I'd instead say that Python uses ephemeral names for long-lived objects, where other languages use the addresses of ephemeral objects. Your ideas of "simple" and "sensible" are being conditioned by your experience. > It's small wonder that neophytes try to cram Python behaviors into > terms and computing concepts they already understand from learning > other languages, and that they fail to do so. What's mystifying is > that when Pythonistas reply to their messages, they universally seem > confused at how this could possibly happen, and often enough actually > seem offended (or at least offensive) when it inevitably does happen... > Generally speaking we try not to be offensive first on this list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rt8396 at gmail.com Fri Jan 2 12:00:01 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 09:00:01 -0800 (PST) Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> Message-ID: <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> On Jan 2, 6:45?am, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: > > He was not cross posting. > > You don't actually know what cross-posting is, do you? > > You've just earned a plonking for the next month. Do try to have at least > half a clue by February. > > -- > Steven Steven i got you NOW! Everybody go and look at this thread, there Mr. Makinzie butts in and posts an off-topic question, and Steven answers it, contributing to the off-topicalitly of the thread. And has yet to apologize for it, or admit his screwup, but will he preach to everyone else about making off topic post... Pot meet Kettle; Kettle Pot! http://groups.google.com/group/comp.lang.python/browse_thread/thread/fc57c18c3cff5937?hl=en&q=recycle+bin#97254d877903bbd From excord80 at gmail.com Fri Jan 2 12:10:08 2009 From: excord80 at gmail.com (excord80) Date: Fri, 2 Jan 2009 09:10:08 -0800 (PST) Subject: Creating an application for Linux References: <7d2fe328-064c-46da-9150-7305b6f9e94e@b41g2000pra.googlegroups.com> Message-ID: You might find this recent blog post interesting: http://www.mechanicalcat.net/richard/log/Python/Sane_Python_application_packaging__initial_solution From igouy2 at yahoo.com Fri Jan 2 12:28:26 2009 From: igouy2 at yahoo.com (Isaac Gouy) Date: Fri, 2 Jan 2009 09:28:26 -0800 (PST) Subject: 2to3 used in the Shootout References: <4f1a8f03-fd7f-49ea-8031-61f73fb0c0e8@x16g2000prn.googlegroups.com> <65a43a69-1ef2-4a41-b860-a370891aecbd@g39g2000pri.googlegroups.com> <67424d25-69c3-4c9d-ba38-0df208a28428@k19g2000yqg.googlegroups.com> Message-ID: On Dec 29 2008, 8:36?am, prueba... at latinmail.com wrote: > On Dec 23, 5:21?pm, Isaac Gouy wrote: > > > On Dec 23, 11:51?am, bearophileH... at lycos.com wrote: > > > > They have translated the Python benchmarks of theShootoutsite from > > > Py2 to Py3 using 2to3: > > > >http://shootout.alioth.debian.org/u32/benchmark.php?test=all?=pyt... > > > So please re-write those programs to remove problems created by > > automatic translation and better take advantage of Python 3 > > functionality... > > >http://shootout.alioth.debian.org/u32/faq.php#play > > > > It shows some "performance bugs" of Python3 itself (especially > > > regarding the binary-trees benchmark, that was unexpected by me), and > > > two points where 2to3 may be improved, for example after the > > > translation this gives error: > > > ? ? ? ? ?table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy', > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'TGVHCDM > > > \nKNSYAAWBRTGVHCDMKNSYAAWBR')): > > > > Gives: > > > TypeError: maketrans arguments must be bytes objects > > > > Bye, > > > bearophile > > BTW I am not sure how to submit this or if this is actually valid to > do, but I have a faster version for the pidigits program that uses > basically the same algorithm but removes function calls and unused > terms of the formula. > >
> import time
>
> def pi_digits(n, width):
> ? ? out = []
> ? ? wrt = out.append
> ? ? aq = 1
> ? ? ar = 0
> ? ? at = 1
> ? ? k = 0
> ? ? f = 1
> ? ? g = 2
> ? ? i = 0
> ? ? while i < n:
> ? ? ? ? y = (aq*3+ar)//at
> ? ? ? ? while y != ((aq*4+ar)//at):
> ? ? ? ? ? ? k += 1
> ? ? ? ? ? ? f += 2
> ? ? ? ? ? ? g += 4
> ? ? ? ? ? ? ar = aq*g+ar*f
> ? ? ? ? ? ? aq = aq*k
> ? ? ? ? ? ? at = at*f
> ? ? ? ? ? ? y = (aq*3+ar)//at
> ? ? ? ? aq = 10*aq
> ? ? ? ? ar = 10*ar-10*y*at
> ? ? ? ? i += 1
> ? ? ? ? wrt(str(y))
> ? ? ? ? if not i%width:
> ? ? ? ? ? ? wrt('\t:%d\n'%i)
> ? ? wrt(' '*(width-i%width))
> ? ? wrt('\t:%d\n'%i)
> ? ? return ''.join(out)
>
> def main():
> ? ? begin = time.time()
> ? ? n = 1000
> ? ? width = 70
> ? ? print pi_digits(n,width)
> ? ? print 'Total Time:', time.time()-begin
>
> main()
>
> 
http://shootout.alioth.debian.org/u32q/faq.php#play From fuzzyman at gmail.com Fri Jan 2 12:40:34 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:40:34 -0800 (PST) Subject: mod_pylite? References: <8af2c28b-d8f9-4f27-b51d-e3d45ea1a5b0@b1g2000yqg.googlegroups.com> <52d1daec-cd7f-4fa8-a0f0-4c02674f4610@k36g2000yqe.googlegroups.com> <485bc6cc-6bca-4e18-89ce-7dd49fdc0b57@w24g2000prd.googlegroups.com> Message-ID: On Jan 2, 2:49?pm, excord80 wrote: [snip...] > > It sounds interesting, however, after reading a bit about it, I see > that a large part of wsgi is providing a nice interface between web > server and webapp. I don't think I need any such interface, or at > least, a replacement for CGI. I just need something like CGI but with > a persistent Python so the web server doesn't have to restart python > for every request. And I don't need need it to work with anything else > other than Apache. > And indeed that is exactly what mod_wsgi is / does. It does a bit more - because CGI really isn't enough for most web apps these days, but WSGI can be used very simply. Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Fri Jan 2 12:44:55 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:44:55 -0800 (PST) Subject: If your were going to program a game... References: <85eizlhhu5.fsf@dozer.localdomain> Message-ID: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> On Jan 2, 3:02?pm, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > > browser in a window of a social site built around the game. The social > > site has login, chat, player stats, list of active games, etc. AND > > there is also be a desktop client that accesses the game server via > > the same communication mechanism (like an AIR-based desktop client/ > > app) as the browser-based version - I guess using JSON/RPC. > > Ever see chess.com? > > I don't know what they're using in the backend, but the client is > entirely javascript. > > You could probably roll your own python javascript compiler to suit your > needs. It could probably even build up your own DSL for writing these > games. > > It's a worthwhile project and I think there might be support for it from > other developers. There's a project called Pyjamas, and PyPy also has a Python to Javascript compiler. Imagine debugging it though - ouch. Just write some Javascript already. ;-) Michael Foord -- http://www.ironpythoninaction.com/ From fuzzyman at gmail.com Fri Jan 2 12:49:03 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 09:49:03 -0800 (PST) Subject: FW: python import sys.path References: <68177ab8-f073-4767-86b6-9abf8c331e36@r10g2000prf.googlegroups.com> Message-ID: <1b8445ae-2b9a-4656-b035-4a0af1ce55a5@i20g2000prf.googlegroups.com> On Jan 2, 2:28?pm, John Machin wrote: > On Jan 3, 1:09?am, "Kelly, Brian" wrote:> After following your suggestions I was able to confirm that the 2.5 > > interpreter was being invoked. So then I grepped for all instances of python > > in the scripts that were imported as modules: from bacula_conf import * > > > The calling script cleanup.py is invoking purge_client.py like an external > > script: > > > def purgeAll(options, computer_name): > > ? ? cmd = "python purge_client.py %s" % computer_name > > ? ? if options.pretend <> True: > > Who wrote that? > > > ? ? ? ? error = os.system(cmd) > > ? ? else: > > ? ? ? ? _log.info("Done. No changes made due to --pretend flag.") > > ? ? ? ? ? ?#### error is not defined in this branch> ? ? if not error: #### Splat! > > ? ? ? ? return True > > ? ? else: > > ? ? ? ? return False > > ?AArrgh! Try: > > ? ?return not error > That will still blow up with a NameError when the path doing the logging is invoked. How about: def purgeAll(options, computer_name): cmd = "python purge_client.py %s" % computer_name if options.pretend != True: # if not options.pretend (assuming it is a bool) error = os.system(cmd) return not error _log.info("Done. No changes made due to --pretend flag.") return True Michael -- http://www.ironpythoninaction.com/ From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 13:09:47 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 19:09:47 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <495e6619$0$3500$426a34cc@news.free.fr> Kottiyath a ?crit : > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? complement = lambda t: (t[0], None, t[1]) if len(t) == 2 else t for k, u, v in map(complement, L): print k, u, v From n.kottiyath at gmail.com Fri Jan 2 13:11:09 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Fri, 2 Jan 2009 10:11:09 -0800 (PST) Subject: Is there a better algorithm? Message-ID: I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: >>> for i in l: ... u = None ... try: ... (k, v) = i ... except ValueError: ... (k, u, v) = i ... print k, u, v --------- 1 None 2 3 4 5 6 None 7 ------------- But, this algorithm doesnt look very beautiful - like say -> for k, u, v in L: Can anyone suggest a better algorithm to get the values? From exarkun at divmod.com Fri Jan 2 13:16:13 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 2 Jan 2009 13:16:13 -0500 Subject: If your were going to program a game... In-Reply-To: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> Message-ID: <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: >On Jan 2, 3:02?pm, J Kenneth King wrote: >> Tokyo Dan writes: >> > If your were going to program a game in python what technologies would >> > you use? >> >> > The game is a board game with some piece animations, but no movement >> > animation...think of a chess king exploding. The game runs in a >> > browser in a window of a social site built around the game. The social >> > site has login, chat, player stats, list of active games, etc. AND >> > there is also be a desktop client that accesses the game server via >> > the same communication mechanism (like an AIR-based desktop client/ >> > app) as the browser-based version - I guess using JSON/RPC. >> >> Ever see chess.com? >> >> I don't know what they're using in the backend, but the client is >> entirely javascript. >> >> You could probably roll your own python javascript compiler to suit your >> needs. It could probably even build up your own DSL for writing these >> games. >> >> It's a worthwhile project and I think there might be support for it from >> other developers. > >There's a project called Pyjamas, and PyPy also has a Python to >Javascript compiler. No, PyPy includes an RPython to JavaScript compiler. RPython and Python are different languages. Jean-Paul From fuzzyman at gmail.com Fri Jan 2 13:16:58 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 10:16:58 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> On Jan 2, 6:11?pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ... ?u = None > ... ?try: > ... ? (k, v) = i > ... ?except ValueError: > ... ? (k, u, v) = i > ... ?print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? for i in l: u = None if len(i) == 2: k, v = i else: k, u, v = i Best I could come up with. Alternatively: def mangle(i): if len(i) == 3: return i k, v = i return k, None, v for i in l: k, u, v = mangle(i) I'm sure there is a clever one liner using the Python 2.5 ternary expression syntax. On the other hand I'm not sure it would be very readable, so a straightforward (if less clever) solution is probably better. Michael -- http://www.ironpythoninaction.com/ From tavares at fe.up.pt Fri Jan 2 13:17:59 2009 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Fri, 2 Jan 2009 10:17:59 -0800 (PST) Subject: =?windows-1252?Q?Workshop_=22Medical_Imaging_Systems=22_within_EUROMEDIA_?= =?windows-1252?Q?2009_=96_Announce_=26_Call_for_Papers?= Message-ID: -------------------------------------------------------------------------------------------------------------------------------------------- Workshop ?Medical Imaging Systems? within EUROSIS EUROMEDIA 2009 April 15-17, 2009, Novotel, Bruges, Belgium http://www.eurosis.org/cms/?q=taxonomy/term/172 (Apologies for cross-posting. We would appreciate if you could distribute this information by your colleagues and co-workers.) -------------------------------------------------------------------------------------------------------------------------------------------- Dear Colleague, In recent years, extensive research has been performed to develop more and more efficient and powerful medical imaging systems. Such systems are crucial for medical specialists, allowing a deeper analysis and to understand what is going inside the human body, and therefore they play an essential role for adequate medical diagnosis and treatments. To accomplish efficient and powerful medical imaging systems, many research works have being done in many domains, like the ones related with medical image devices, signal processing, image processing and analysis, biomechanical simulation and data visualization. The main goal of the Workshop ?Medical Imaging Systems? is to bring together researchers involved in the related domains, in order to set the major lines of development for the near future. Therefore, the proposed Workshop will consist of researchers representing various fields related to Medical Devices, Signal Processing, Computational Vision, Computer Graphics, Computational Mechanics, Scientific Visualization, Mathematics and Medical Imaging. The Workshop endeavors to contribute to obtain better solutions for more efficient and powerful medical imaging systems, and attempts to establish a bridge between clinicians and researchers from these diverse fields. Due to your research activities in the field, we would like to invite you to submit a contributed paper for the Workshop ?Medical Imaging Systems?. Important Dates - Submission Deadline: January 20, 2009; - Notification of Acceptance or Rejection: March 20, 2009; - Authors provide camera-ready manuscript: April 15-17, 2009; - Conference Events: April 15-17, 2009. For further details please see the conference website at: http://www.eurosis.org/cms/?q=taxonomy/term/172 We are looking forward to see you in Bruges next April. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, tavares at fe.up.pt, www.fe.up.pt/~tavares) From fuzzyman at gmail.com Fri Jan 2 13:19:50 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 2 Jan 2009 10:19:50 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <890cb4a3-7b45-4c50-ba60-b4ce4094fa14@n33g2000pri.googlegroups.com> On Jan 2, 6:16?pm, Jean-Paul Calderone wrote: > On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: > >On Jan 2, 3:02?pm, J Kenneth King wrote: > >> Tokyo Dan writes: > >> > If your were going to program a game in python what technologies would > >> > you use? > > >> > The game is a board game with some piece animations, but no movement > >> > animation...think of a chess king exploding. The game runs in a > >> > browser in a window of a social site built around the game. The social > >> > site has login, chat, player stats, list of active games, etc. AND > >> > there is also be a desktop client that accesses the game server via > >> > the same communication mechanism (like an AIR-based desktop client/ > >> > app) as the browser-based version - I guess using JSON/RPC. > > >> Ever see chess.com? > > >> I don't know what they're using in the backend, but the client is > >> entirely javascript. > > >> You could probably roll your own python javascript compiler to suit your > >> needs. It could probably even build up your own DSL for writing these > >> games. > > >> It's a worthwhile project and I think there might be support for it from > >> other developers. > > >There's a project called Pyjamas, and PyPy also has a Python to > >Javascript compiler. > > No, PyPy includes an RPython to JavaScript compiler. ?RPython and Python are > different languages. > Well valid RPython is valid Python - so different for some value of different... The advantage of PyPy is that it even does things like turn runtime exceptions into Python exceptions, so it should be much easier to debug. It is much more 'heavyweight' though. Michael Foord -- http://www.ironpythoninaction.com/ From imageguy1206 at gmail.com Fri Jan 2 13:34:12 2009 From: imageguy1206 at gmail.com (imageguy) Date: Fri, 2 Jan 2009 10:34:12 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string Message-ID: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' FWIW, the string is created using ctypes.create_string_buffer function The following code works but feels a bit clunk and is rather slow too. blist = list(buffer) for start in xrange(0,len(blist), 3): try: blue = blist[start] red = blist[start+2] blist[start] = red blist[start+2] = blue except IndexError: pass new_buffer = ''.join(blist) new_buffer is then passed to a wx program to create and image. Any thoughts comments would be appreciated. geoff. PS: I started this post earlier, but I think I hit the send button too soon. My apologies to the group for sloppy typing. From steve at holdenweb.com Fri Jan 2 13:41:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 13:41:58 -0500 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? L = [(1, 2), (3, 4, 5), (6, 7)] for i in L: if len(i) == 2: k, v, u = i + (None, ) else: k, u, v = i print k, u, v regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 13:50:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 13:50:50 -0500 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > May not be any quicker, but it works: blues = buffer[0::3] greens = buffer[1::3] reds = buffer[2::3] result = "".join("".join(x) for x in zip(reds, blues, greens)) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From news at slash-me.net Fri Jan 2 13:55:43 2009 From: news at slash-me.net (Markus Brueckner) Date: Fri, 02 Jan 2009 19:55:43 +0100 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> Message-ID: <6s769gF4gge3U1@mid.individual.net> Hi, Fuzzyman wrote: > I'm sure there is a clever one liner using the Python 2.5 ternary > expression syntax. On the other hand I'm not sure it would be very > readable, so a straightforward (if less clever) solution is probably > better. that would be something like this (using a generator) L = [(1, 2), (3, 4, 5), (6, 7)] g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in L) for elem in g: print elem So long, Markus P.S: No, I don't consider that more readable than your example ;-) -- "Hacking is like having sex: you get in, you get out and you hope that you did not leave anything which can be traced back to you" - Unbekannt From tekion at gmail.com Fri Jan 2 14:03:44 2009 From: tekion at gmail.com (tekion) Date: Fri, 2 Jan 2009 11:03:44 -0800 (PST) Subject: is there a way to determine a relative path to the script? Message-ID: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Hello, I have a script in /usr/local/app/mypython.py and a configuration file relative to /usr/local/app/conf. When I call the script with an absolute path of /usr/local/app/mypthon.py I recieved an error similar to the below error: Traceback (most recent call last): File "script/art/auditlog.py", line 28, in ? database = Config.get("DB", "user") File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/ConfigParser.py", line 505, in get raise NoSectionError(section) ConfigParser.NoSectionError: No section: 'DB' I know why, the configuration which I reference in the script is relative to "/usr/local/app", when I call the script via an absolute path, then the relative the configuration file is base on where ever I call the script from. One way to fix this is to add a path manually into the variable. But I would like to avoid this hard-coding parameter into my script. Is there a way to determined the relative location of the script programatically? FYI, in the end this scrip would run from CRON. From bockman at virgilio.it Fri Jan 2 14:15:58 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 20:15:58 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <495e67ef$0$743$5fc30a8@news.tiscali.it> Kottiyath ha scritto: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? One way to avoid explicit checks on tuple size (but making the code a bit less clear and probably slower): for i in l: k, v, u = (i[:3]+(None,))[:3] ... Ciao ----- FB From geekmail at usenot.de Fri Jan 2 14:27:41 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 20:27:41 +0100 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> <6s769gF4gge3U1@mid.individual.net> Message-ID: <20090102202741.14263c92@usenot.de> On Fri, 02 Jan 2009 19:55:43 +0100 Markus Brueckner wrote: > g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in > L) If this isn't proof of Python's versatility, I don't know what is. In one line it can mimic both Lisp and Perl. Sweet. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From bockman at virgilio.it Fri Jan 2 14:29:11 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 02 Jan 2009 20:29:11 +0100 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <495e6b08$0$11376$5fc30a8@news.tiscali.it> imageguy ha scritto: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > You could try the same algorithm on an array.array object : it might be faster. Ciao ---- FB From ryan.mccoskrie at gmail.com Fri Jan 2 14:39:30 2009 From: ryan.mccoskrie at gmail.com (Ryan McCoskrie) Date: Sat, 03 Jan 2009 08:39:30 +1300 Subject: Why not Ruby? References: Message-ID: Xah Lee wrote: > Q: Do you condemn Ruby? > > No. I think it's reasonably elegant, but today there are too many > languages, so Ruby don't particularly standout for me. Many of them, > are arguably quite more elegant and powerful than Ruby. There is one thing that Ruby is exceptionally good for and that is replacing COBOL and Visual Basic as the programming languages for non-programmers. It's dead boring as a language but somebody who is an accountant or something could make some okayish tools for personal use in it. Next point. If your going to post this sort of thing _only_ post to comp.programming and _never_ post what is on your website. Just put it into your sig block. ------------------------------------------------------------------------ Quote of the login: Computers don't actually think. You just think they think. (We think.) From robert.kern at gmail.com Fri Jan 2 14:46:31 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 02 Jan 2009 14:46:31 -0500 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: r wrote: > On Jan 1, 4:40 pm, Robert Kern wrote: >> Hamish McKenzie wrote: >>> sometimes I want to be able to initialize an instance with a variety of different data types. >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just >> assign to attributes. I would add a from() classmethod for each that >> I wanted to support. If I really wanted an all-singing, all-dancing >> initialization method, I would add another classmethod that would just dispatch >> to the appropriate type-specific classmethod. I prefer classmethods to plain >> functions because I can subclass. >> >> -- >> 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 > > Why are you busting into this thread? Are you talking to me, or Hamish, who (presumably unintentionally) responded to a message instead of making a new thread? If you want to suggest that one should have more care about starting new threads, that's fine, but please do not jump to the conclusion that there is malintent. And don't chastise people for not being as rude as you. -- 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 rcmn73 at gmail.com Fri Jan 2 15:04:41 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 12:04:41 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> Message-ID: <788a7ce3-1ba2-4996-af47-5af6c0a69b37@a26g2000prf.googlegroups.com> I'm using py2exe-0.6.9.win32-py2.6.exe i used option 3. On a list of 500 i get the same error than previous. On a list of 250 once it just quit leaving the open file at 0k and on the second attempt it failed with the same error and a note about "TypeError: 'NoneType' object is not callable". Basically totally random errors. Obviously there is something that py2exe cannot bundle. because I have been using this script(as *.py) more than 30 times now .And as long as i respect the 500 window$ limitation. I had no issues. From bdesth.quelquechose at free.quelquepart.fr Fri Jan 2 15:05:51 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 02 Jan 2009 21:05:51 +0100 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <495e814d$0$3502$426a34cc@news.free.fr> Derek Martin a ?crit : > On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: >> Derek Martin wrote: >>> What the Python community often overlooks, when this discussion again >>> rears its ugly head (as it seems to every other hour or so), is that >>> its assignment model is BIZARRE, as in it's conceptually different >>> from virtually all other languages substantially taught in >>> undergraduate computer science programs. And for that matter, it's >>> pretty unintuitive generally. >>> >> I'd definitely argue against bizarre. It's actually very easy to >> understand, and Python is by no means the only language to have used it. > > Clearly the first and third are true. :) But CS programs still > generally teach primarily C/C++, Java, and (some form of) assembly > AFAICT. A few odd ones pop up here and there along the way (I studied > with scheme, for example), but they vary and are highly > program-dependent. What the average CS grad sees is, AFAICT, still > very much what I described. Those languages also behave similarly to > what students see in mathematics (e.g. algebra etc.). With only that > to go on, Python seems rather weird, and I think from the frequency > with which these discussions occur on this list, clearly it *IS* > difficult for a neophyte Python programmer to understand the > assignment model. Took me about half an hour to grasp, not even being "CS grad" (nor whathever "grad" FWIW). By that time, I had a couple monthes working experience with VB, and had learned (but never seriously used) bits of C, C++, Java and Pascal. From rt8396 at gmail.com Fri Jan 2 15:11:34 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 12:11:34 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: On Jan 2, 1:46?pm, Robert Kern wrote: > r wrote: > > On Jan 1, 4:40 pm, Robert Kern wrote: > >> Hamish McKenzie wrote: > >>> sometimes I want to be able to initialize an instance with a variety of different data types. > >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just > >> assign to attributes. I would add a from() classmethod for each that > >> I wanted to support. If I really wanted an all-singing, all-dancing > >> initialization method, I would add another classmethod that would just dispatch > >> to the appropriate type-specific classmethod. I prefer classmethods to plain > >> functions because I can subclass. > > >> -- > >> 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 > > > Why are you busting into this thread? > > Are you talking to me, or Hamish, who (presumably unintentionally) responded to > a message instead of making a new thread? > > If you want to suggest that one should have more care about starting new > threads, that's fine, but please do not jump to the conclusion that there is > malintent. And don't chastise people for not being as rude as you. > > -- > 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 I am not so much chastising Hamish as i am Steven, Steven knows better than this BS, and has preached to so many people about off topic post that my ears are bleeding from his incessant rambling about it. Now, he goes and does what he complains about soooo much. I'm just calling him on it thats all. I can't speak for the other responders because i know of none of them. From code at pizzashack.org Fri Jan 2 15:44:44 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 14:44:44 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <20090102204444.GL28417@dragontoe.org> On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: > Derek Martin wrote: > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that > > its assignment model is BIZARRE, as in it's conceptually different > > from virtually all other languages substantially taught in > > undergraduate computer science programs. And for that matter, it's > > pretty unintuitive generally. > > > I'd definitely argue against bizarre. It's actually very easy to > understand, and Python is by no means the only language to have used it. Clearly the first and third are true. :) But CS programs still generally teach primarily C/C++, Java, and (some form of) assembly AFAICT. A few odd ones pop up here and there along the way (I studied with scheme, for example), but they vary and are highly program-dependent. What the average CS grad sees is, AFAICT, still very much what I described. Those languages also behave similarly to what students see in mathematics (e.g. algebra etc.). With only that to go on, Python seems rather weird, and I think from the frequency with which these discussions occur on this list, clearly it *IS* difficult for a neophyte Python programmer to understand the assignment model. And this is, in part, because it's kind of difficult to explain precisely, as has oft been demonstrated in this forum. > I'd argue that this approach is out of date and overly-restrictive, Sure, I already hinted that it's useful... but it's still uncommon, in the experience of most CS students -- not even taking into account the number of people who program who have never studied in a formal CS program. > I'd instead say that Python uses ephemeral names for long-lived objects, > where other languages use the addresses of ephemeral objects. Your ideas > of "simple" and "sensible" are being conditioned by your experience. Of course... I'd argue that our experience is a large part of what makes things simple or sensible. Things that behave like other things we are very familiar will be simple to understand. Python's assignment model is probably new to most people when they first start using it. To look at Python's code, at first glance assignment seems to be the same as everywhere else you've encountered it... Only once someone starts to write "real" programs does the difference really matter. > > It's small wonder that neophytes try to cram Python behaviors into > > terms and computing concepts they already understand from learning > > other languages, and that they fail to do so. What's mystifying is > > that when Pythonistas reply to their messages, they universally seem > > confused at how this could possibly happen, and often enough actually > > seem offended (or at least offensive) when it inevitably does happen... > > > Generally speaking we try not to be offensive first on this list. Perhaps I've misused the term Pythonista... I meant roughly, "people who frequent this list/news group who seem to consider themselves experts at programming Python (and for the most part, are)." I consider myself pretty well informed about Python (though not an expert by any means), and I still read this list often (I use the mailing list interface), because I still find that I learn useful things from the posts to it from time to time. But I often see python "experts" lambasting people who clearly from their posts are new at python, because their code is bad, their understanding is bad, or in this case even accusing the learning materials of being sub-par. I realize that some of this is meant in jest, but a lot of it isn't, and it can be quite difficult for someone who doesn't speak your language natively (or even one who does, given the medium) to tell the difference. There are better ways to foster understanding... ;-) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From GDoermann at gmail.com Fri Jan 2 15:46:00 2009 From: GDoermann at gmail.com (TechieInsite) Date: Fri, 2 Jan 2009 12:46:00 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Message-ID: <31f698b9-a6e7-41c5-91d3-b2264b9dec74@e1g2000pra.googlegroups.com> import os base = __file__.split(os.sep) os.path.relpath('path/to/your/file/, base) I hope this helps. Greg tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/local/app/mypthon.py I recieved an error > similar to the below error: > > Traceback (most recent call last): > File "script/art/auditlog.py", line 28, in ? > database = Config.get("DB", "user") > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > python2.3/ConfigParser.py", line 505, in get > raise NoSectionError(section) > ConfigParser.NoSectionError: No section: 'DB' > > I know why, the configuration which I reference in the script is > relative to "/usr/local/app", when I call the script via an absolute > path, then the relative the configuration file is base on where ever I > call the script from. One way to fix this is to add a path manually > into the variable. But I would like to avoid this hard-coding > parameter into my script. Is there a way to determined the relative > location of the script programatically? FYI, in the end this scrip > would run from CRON. From max at alcyone.com Fri Jan 2 15:50:44 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Jan 2009 12:50:44 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: Derek Martin wrote: > On a mostly not related note: > > On Tue, Dec 30, 2008 at 07:52:26AM -0800, Aaron Brady wrote: >> According to some rules, these are ungrammatical sentences, due to >> plurality disagreement. Ex: >> >> The Morning Star is ... >> The Evening Star is ... >> *The Morning Star and The Evening Star is... >> *The Morning Star and The Evening Star are... >> >> Neither of the latter two is correct. (* marks ungrammatical.) As >> such, the listener isn't sure what meaning to take. > > This statement is false. The latter of the two is grammatically > correct. The subject is a compound subject joined by the conjunction > "and" which indicates that there are two subjects, and thus the plural > form of the verb is necessary and correct. > >> Identity isn't defined on math objects, only on Python objects; there >> is no notion of 'is' in math. > > This is also false, it even has its own operator (which requires > Unicode to display): ? That can mean a number of things, one of which means "is identically equal to," but identity means something different in mathematics than it means here. In mathematics, identity means a relationship that is true regardless of the value of the variables involved (as opposed to equality which is only true under more specific circumstances). In computer science, identity means that two expressions are represented by the same object, something which not only has no meaning in mathematics, but which should also be clear since mathematical identities need not have any individual variables on either side of the triple bar; take, for instance, the trigonometric identity cos^2 theta + sin^2 theta = 1. Even if you write this equation with the triple bar to represent a mathematical identity (which it is), it obviously doesn't say anything about which "objects" are the same as each other. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Scars are like memories. We do not have them removed. -- Chmeee From james at agentultra.com Fri Jan 2 15:57:22 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 15:57:22 -0500 Subject: Is there a better algorithm? References: Message-ID: <85aba9h1e5.fsf@dozer.localdomain> Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: >>>> for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v) = i > ... print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? Just a note: this isn't really an algorithm problem. ;) It's more of a grammar obstruction. To make your code more simple, it would be nice if the assignment operator would return, "None," in the case where there are too few values to unpack from the right-operand of the assignment operator. Aside from the typical workarounds that first came to mind, I started wondering whether it was possible to expose the problem and solve it directly. Sadly, it appears to be non-trivial (or at least, well hidden from the unwashed masses). I'd be really curious if the unpacking machinery were exposed to the developer. I started poking around the operator and types modules, but the implementation isn't obvious. What methods are being called on the operands by the assignment operator in the following statement: a, b, c = some_tuple I'm sorry if this line of inquiry is not very pythonic; but one is curious if this is some python magic happening here. After using the idiom for years I hadn't really thought about it much until recently. From http Fri Jan 2 15:58:24 2009 From: http (Paul Rubin) Date: 02 Jan 2009 12:58:24 -0800 Subject: Is there a better algorithm? References: Message-ID: <7x8wptifwv.fsf@ruckus.brouhaha.com> Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > I want to loop through the list and extract the values. Others have suggested messy ways to code what you're asking. At another level, that list format seems like a code smell. You may be better off organizing the program so that L = [(1, None, 2), (3, 4, 5), (6, None, 7)] after which unpacking becomes trivial. From bearophileHUGS at lycos.com Fri Jan 2 15:58:41 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 12:58:41 -0800 (PST) Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> Message-ID: <95c3672c-105e-46b9-a241-7cb199ed45ba@r15g2000prh.googlegroups.com> Fuzzyman: > for i in l: > ? ?u = None > ? ?if len(i) == 2: > ? ? ? k, v = i > ? ?else: > ? ? ? ?k, u, v = i That's the best solution I have seen in this thread so far (but I suggest to improve indents and use better variable names). In programming it's generally better to follow the KISS principle. Bye, bearophile From steve at holdenweb.com Fri Jan 2 15:58:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 15:58:55 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102204444.GL28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <20090102204444.GL28417@dragontoe.org> Message-ID: <495E800F.8080808@holdenweb.com> Derek Martin wrote: > On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: >> Derek Martin wrote: [...] >>> It's small wonder that neophytes try to cram Python behaviors into >>> terms and computing concepts they already understand from learning >>> other languages, and that they fail to do so. What's mystifying is >>> that when Pythonistas reply to their messages, they universally seem >>> confused at how this could possibly happen, and often enough actually >>> seem offended (or at least offensive) when it inevitably does happen... >>> >> Generally speaking we try not to be offensive first on this list. > > Perhaps I've misused the term Pythonista... I meant roughly, "people > who frequent this list/news group who seem to consider themselves > experts at programming Python (and for the most part, are)." > I consider myself pretty well informed about Python (though not an > expert by any means), and I still read this list often (I use the > mailing list interface), because I still find that I learn useful > things from the posts to it from time to time. But I often see python > "experts" lambasting people who clearly from their posts are new at > python, because their code is bad, their understanding is bad, or in > this case even accusing the learning materials of being sub-par. I > realize that some of this is meant in jest, but a lot of it isn't, and > it can be quite difficult for someone who doesn't speak your language > natively (or even one who does, given the medium) to tell the > difference. There are better ways to foster understanding... ;-) > I don't think you can abuse a term that doesn't have any set meaning - generally it's used to refer simply to users of Python, or at least that's the way I use it. Lambasting is definitely not the way to proceed with learners, and generally the denizens of this group mostly behave properly. Even when meant in jest it's not appropriate, not helpful, and not Pythonic. I have been known to be unnecessarily crabby myself on the odd off-day, though usually when I catch myself behaving that way I try to apologize when it's appropriate. There are a few individuals who pop up from time to time and whose behavior is incendiary, but we should even ignore those. Not answering a post is the best way to ensure they don't come back seeking to offend again. Or, better still, change their ways and become model citizens. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From james at agentultra.com Fri Jan 2 16:06:48 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 02 Jan 2009 16:06:48 -0500 Subject: Is there a better algorithm? References: <7x8wptifwv.fsf@ruckus.brouhaha.com> Message-ID: <8563kxh0yf.fsf@dozer.localdomain> Paul Rubin writes: > Kottiyath writes: >> I have the following list of tuples: >> L = [(1, 2), (3, 4, 5), (6, 7)] >> I want to loop through the list and extract the values. > > Others have suggested messy ways to code what you're asking. At another > level, that list format seems like a code smell. You may be better off > organizing the program so that > > L = [(1, None, 2), (3, 4, 5), (6, None, 7)] > > after which unpacking becomes trivial. Very true. +1 From GDoermann at gmail.com Fri Jan 2 16:07:56 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:07:56 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> Message-ID: <2847b673-f936-4699-a5c0-46e66f884b8d@r36g2000prf.googlegroups.com> import os os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/local/app/mypthon.py I recieved an error > similar to the below error: > > Traceback (most recent call last): > File "script/art/auditlog.py", line 28, in ? > database = Config.get("DB", "user") > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > python2.3/ConfigParser.py", line 505, in get > raise NoSectionError(section) > ConfigParser.NoSectionError: No section: 'DB' > > I know why, the configuration which I reference in the script is > relative to "/usr/local/app", when I call the script via an absolute > path, then the relative the configuration file is base on where ever I > call the script from. One way to fix this is to add a path manually > into the variable. But I would like to avoid this hard-coding > parameter into my script. Is there a way to determined the relative > location of the script programatically? FYI, in the end this scrip > would run from CRON. From rcmn73 at gmail.com Fri Jan 2 16:08:34 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 13:08:34 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> Message-ID: <18c8ef26-116a-4ba8-85b8-a7013ad184b2@n33g2000pri.googlegroups.com> I just tried to compile with gui2exe. And i ran the exe. it faile the same way but at least generate a log. Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyc", line 522, in __bootstrap_inner File "pingable.py", line 35, in run File "subprocess.pyc", line 588, in __init__ File "subprocess.pyc", line 707, in _get_handles File "subprocess.pyc", line 752, in _make_inheritable WindowsError: [Error 6] The handle is invalid for every entry it generate this error and the line 35 is ...Popen ! From tjreedy at udel.edu Fri Jan 2 16:08:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jan 2009 16:08:57 -0500 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' For speed, I would look at PIL or pygame for existing function, or use numpy -- read into 2-d array, swap first and third members, flatten. From jsprad at gmail.com Fri Jan 2 16:15:04 2009 From: jsprad at gmail.com (sprad) Date: Fri, 2 Jan 2009 13:15:04 -0800 (PST) Subject: Noob question: Is all this typecasting normal? Message-ID: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> I've done a good bit of Perl, but I'm new to Python. I find myself doing a lot of typecasting (or whatever this thing I'm about to show you is called), and I'm wondering if it's normal, or if I'm missing an important idiom. For example: bet = raw_input("Enter your bet") if int(bet) == 0: # respond to a zero bet Or later, I'll have an integer, and I end up doing something like this: print "You still have $" + str(money) + " remaining" All the time, I'm going int(this) and str(that). Am I supposed to? From rcmn73 at gmail.com Fri Jan 2 16:15:45 2009 From: rcmn73 at gmail.com (rcmn) Date: Fri, 2 Jan 2009 13:15:45 -0800 (PST) Subject: Py2exe issue References: <35fc882d-13a4-4177-b5de-26b497bb2a0f@a12g2000pro.googlegroups.com> <656ae5e0-311f-4f25-a58a-6d2d182e01ce@v5g2000prm.googlegroups.com> <18c8ef26-116a-4ba8-85b8-a7013ad184b2@n33g2000pri.googlegroups.com> Message-ID: <7aa2f627-ea69-4f73-ba2b-400388637f33@w24g2000prd.googlegroups.com> On Jan 2, 3:08?pm, rcmn wrote: > I just tried to compile with gui2exe. And i ran the exe. it faile the > same way but at least generate a log. > Exception in thread Thread-1: > Traceback (most recent call last): > ? File "threading.pyc", line 522, in __bootstrap_inner > ? File "pingable.py", line 35, in run > ? File "subprocess.pyc", line 588, in __init__ > ? File "subprocess.pyc", line 707, in _get_handles > ? File "subprocess.pyc", line 752, in _make_inheritable > WindowsError: [Error 6] The handle is invalid > > for every entry it generate this error and the line 35 is ...Popen ! alright here is the issue : http://www.py2exe.org/index.cgi/Py2ExeSubprocessInteractions From gh at ghaering.de Fri Jan 2 16:16:26 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 02 Jan 2009 22:16:26 +0100 Subject: Is there a better algorithm? In-Reply-To: References: Message-ID: <6s7ehbF4kp3aU1@mid.uni-berlin.de> Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: [...] If this is part of a real program, instead of an exercise, you should fix the code that creates this list of tuples so that they have a uniform length of 3. And if the third element is missing, it should be None. This saves lots of trouble later on. -- Gerhard From GDoermann at gmail.com Fri Jan 2 16:16:37 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:16:37 -0800 (PST) Subject: is there a way to determine a relative path to the script? References: <5fc89ad3-419d-40d5-9b06-02f74e63b5eb@n33g2000pri.googlegroups.com> <2847b673-f936-4699-a5c0-46e66f884b8d@r36g2000prf.googlegroups.com> Message-ID: Note: The os.path.relpath is new in 2.6. If you are using an older version you will have to write your own algorithm TechieInsights wrote: > import os > os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) > > tekion wrote: > > Hello, > > I have a script in /usr/local/app/mypython.py and a configuration file > > relative to /usr/local/app/conf. When I call the script with an > > absolute path of /usr/local/app/mypthon.py I recieved an error > > similar to the below error: > > > > Traceback (most recent call last): > > File "script/art/auditlog.py", line 28, in ? > > database = Config.get("DB", "user") > > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > > python2.3/ConfigParser.py", line 505, in get > > raise NoSectionError(section) > > ConfigParser.NoSectionError: No section: 'DB' > > > > I know why, the configuration which I reference in the script is > > relative to "/usr/local/app", when I call the script via an absolute > > path, then the relative the configuration file is base on where ever I > > call the script from. One way to fix this is to add a path manually > > into the variable. But I would like to avoid this hard-coding > > parameter into my script. Is there a way to determined the relative > > location of the script programatically? FYI, in the end this scrip > > would run from CRON. From nad at acm.org Fri Jan 2 16:19:31 2009 From: nad at acm.org (Ned Deily) Date: Fri, 02 Jan 2009 13:19:31 -0800 Subject: Is there a better algorithm? References: <85aba9h1e5.fsf@dozer.localdomain> Message-ID: In article <85aba9h1e5.fsf at dozer.localdomain>, J Kenneth King wrote: > Kottiyath writes: > > I have the following list of tuples: > > L = [(1, 2), (3, 4, 5), (6, 7)] > > > > I want to loop through the list and extract the values. > > The only algorithm I could think of is: > >>>> for i in l: > > ... u = None > > ... try: > > ... (k, v) = i > > ... except ValueError: > > ... (k, u, v) = i > > ... print k, u, v > > --------- > > 1 None 2 > > 3 4 5 > > 6 None 7 > > ------------- > > But, this algorithm doesnt look very beautiful - like say -> for k, u, > > v in L: > > Can anyone suggest a better algorithm to get the values? > > Just a note: this isn't really an algorithm problem. ;) > > It's more of a grammar obstruction. > > To make your code more simple, it would be nice if the assignment > operator would return, "None," in the case where there are too few > values to unpack from the right-operand of the assignment operator. Looks like the extended iterable unpacking feature of Python 3.0, described in PEP 3132, comes to the rescue here: >>> L = [(1, 2), (3, 4, 5), (6, 7)] >>> for i in L: ... k, *u, v = i ... print(k, u, v) ... 1 [] 2 3 [4] 5 6 [] 7 -- Ned Deily, nad at acm.org From tjreedy at udel.edu Fri Jan 2 16:20:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jan 2009 16:20:07 -0500 Subject: If your were going to program a game... In-Reply-To: <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> References: <197631d6-ba14-435f-b8cd-c61185b0b9bd@g1g2000pra.googlegroups.com> <20090102181613.20272.1578896182.divmod.quotient.30753@ohm> Message-ID: Jean-Paul Calderone wrote: > No, PyPy includes an RPython to JavaScript compiler. RPython and Python > are > different languages. My impression from a few years ago is that RPython stands for Restricted Python and that it was/is? a proper subset of Python. Has this changed? From code at pizzashack.org Fri Jan 2 16:28:29 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 15:28:29 -0600 Subject: why cannot assign to function call In-Reply-To: <495e814d$0$3502$426a34cc@news.free.fr> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: <20090102212829.GM28417@dragontoe.org> On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: >> Python seems rather weird, and I think from the frequency >> with which these discussions occur on this list, clearly it *IS* >> difficult for a neophyte Python programmer to understand the >> assignment model. > > Took me about half an hour to grasp, not even being "CS grad" (nor > whathever "grad" FWIW). By that time, I had a couple monthes working > experience with VB, and had learned (but never seriously used) bits of > C, C++, Java and Pascal. It took me about a half a second to grasp the "named bins" concept -- i.e. as soon as I was finished reading the words that explained it I understood it, so I'd say that based on your half-hour number, Python's model is substantially more complicated. My own experience was kind of similar... When I read about Python's model I didn't understand it the first time around, had to re-read the section I read that described it, and then had to play with it to see for myself how it worked. I'd estimate it took 10 minutes. I'm not a CS grad either (my degree is in information technology) but I did take the first two years of CS classes at my local college (as a bridge to a masters degree in CS, which I never completed), and I've been programming as a hobbyist, in school, and in my profession for 25 years. I would argue that ideally, it should not take an experienced programmer 10 minutes to understand variable assignment. :) [Note that I'm including the semantics for passing arguments to functions as part of "assignment" for purposes of this discussion.] -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From benjamin.kaplan at case.edu Fri Jan 2 16:35:52 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 2 Jan 2009 16:35:52 -0500 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: On Fri, Jan 2, 2009 at 4:15 PM, sprad wrote: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet > > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" > > All the time, I'm going int(this) and str(that). Am I supposed to? The cast to the int is needed. The cast to a string isn't. Use string formatting instead. As an added bonus, you can ensure that you always show 2 digits past the decimal. >>> money = 2.1 >>>print "You still have $%0.2f remaining" % money You still have $2.10 remaining > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Jan 2 16:36:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 02 Jan 2009 22:36:00 +0100 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <6s7fm0F4k5tsU1@mid.uni-berlin.de> sprad schrieb: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. It is normal, although below you make things needlessly complicated. Python is strongly typed, which is a good thing. It refuses to guess you mean when you multiply a string with a number. Or how a number is to be formatted when printed. > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet You might better do bet = int(raw_input("Enter your bet")) because then you don't need to later on convert bet again and again. But *one* conversion you need. > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" This is more concisely & with much better control over the output-format (think e.g. digits of a fraction) using string-interpolation. See http://docs.python.org/library/stdtypes.html#string-formatting-operations for an overview. In your case, a simple print "You still have $%i remaining" % bet does the trick. Diez From castironpi at gmail.com Fri Jan 2 16:36:16 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 2 Jan 2009 13:36:16 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: On Jan 2, 12:11?pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ... ?u = None > ... ?try: > ... ? (k, v) = i > ... ?except ValueError: > ... ? (k, u, v) = i > ... ?print k, u, v > --------- > 1 None 2 > 3 4 5 > 6 None 7 > ------------- > But, this algorithm doesnt look very beautiful - like say -> for k, u, > v in L: > Can anyone suggest a better algorithm to get the values? for i in L: k, u, v= i[ 0 ], i[ 1 ], i[ -1 ] if len( i )== 2: u= None From mario.ruggier at gmail.com Fri Jan 2 16:38:15 2009 From: mario.ruggier at gmail.com (mr) Date: Fri, 2 Jan 2009 13:38:15 -0800 (PST) Subject: Is there a better algorithm? References: Message-ID: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> As has been noted, the best is to fix the input to be regular-3- tuples. For the fun of it, here's another variation of a solution: tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u, v for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: print k, u, v From GDoermann at gmail.com Fri Jan 2 16:47:25 2009 From: GDoermann at gmail.com (TechieInsights) Date: Fri, 2 Jan 2009 13:47:25 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <222d2d49-e96d-412e-aace-3fae272b59e6@u18g2000pro.googlegroups.com> You can use the built-in string formatting options and operations. 2.5: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html 2.6: http://docs.python.org/library/string.html In essence, you can do: print "You still have $%i remaining" %(money) On Jan 2, 2:15?pm, sprad wrote: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > ? ? # respond to a zero bet > > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" > > All the time, I'm going int(this) and str(that). Am I supposed to? From bthate at gmail.com Fri Jan 2 17:04:46 2009 From: bthate at gmail.com (Bart Thate) Date: Fri, 2 Jan 2009 14:04:46 -0800 (PST) Subject: Request For (gozerbot) Testers Message-ID: So 0.9 is getting in shape and there is one issue that keeps me from releasing 0.9 and that is the upgrade path. 0.9 is vastely different from 0.8 so a special upgrade script has been written to aid with this. Now i have tested this on some gozerbot users but i need a more broader audience that wants to test this for me. So if you run a 0.8 gozerbot you could help me out with testing the 0.9 upgrade script, testing can be done along side your own bot so you dont loose your old configuration. To test do the following: 1) hg clone http://core.gozerbot.org/hg/dev/0.9 0.9bot 2) cd 0.9bot 3) hg clone http://core.gozerbot.org/hg/plugs/gozerplugs 4) ./bin/gozerbot-upgrade . 5) ./bin/gozerbot Check if the bot has converted your data properly with the !size command. As a last step you can test the plugins with the !test-plugs command. If you have any problems with testing gozerbot 0.9 let me know on #dunkbots IRCnet or at bthate at gmail.com .. THNX ;] Bart see http://gozerbot.org/newsite/0.9/ for more information about the upcoming 0.9 release From code at pizzashack.org Fri Jan 2 17:16:41 2009 From: code at pizzashack.org (Derek Martin) Date: Fri, 2 Jan 2009 16:16:41 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: <20090102221641.GN28417@dragontoe.org> On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: >>> Identity isn't defined on math objects, only on Python objects; there >>> is no notion of 'is' in math. >> >> This is also false, it even has its own operator (which requires >> Unicode to display): ? > > That can mean a number of things, one of which means "is identically > equal to," Quite so. > but identity means something different in mathematics than it means > here. But for non-mutable objects, aren't they essentially the same? Mathematics has no concept of "objects" in the sense that computer science does, so of course the best you can really do is draw parallels. > In mathematics, identity means a relationship that is true > regardless of the value of the variables involved (as opposed to > equality which is only true under more specific circumstances). Does 2 = 2 not qualify? Isn't it true that 2 ? 2 and 2 is 2? :) Yet there are no variables at all... The "objects" of mathematics are numbers, which are constants, which as such I would argue always have the same "identity" as themselves. Other components of mathematics are "expressions", which may or may not evaluate to constants, depending on the set conditions. Python has those too, and they are not the same as objects. > In computer science, identity means that two expressions are > represented by the same object, something which not only has no > meaning in mathematics, We're getting way off track here, but I would argue this is also false. Take sets, for example: A = { 1, 2, 3 } B = { 1, 2, 3 } Is it not true that A ? B and in fact these two sets are the same, i.e. they are not actually two different sets at all; the have the same identity, even considering a definition of "identity" which reflects that in Python? A and B are in fact simply two different names we've given to the same mathematical entity. The major difference between mathematics and Python is that mathematical objects are essentially unique, i.e. the constant 1 is arguably always the same 1 wherever it appears, because there is no mathematical need to have multiple instances of the constant 1: Wherever you see the symbol '1' OR an expression which evaluates to the constant 1, it refers to a *concept* of the numerical value representing mathematical singularity and wholeness. In python, you can have multiple instances of objects which are identical to each other (though for this simple case, even python only creates one instance of the object). > but which should also be clear since > mathematical identities need not have any individual variables on > either side of the triple bar; take, for instance, the > trigonometric identity > > cos^2 theta + sin^2 theta = 1. Is theta not a variable? :) Not that it matters... > Even if you write this equation with the triple bar to represent a > mathematical identity (which it is), it obviously doesn't say anything > about which "objects" are the same as each other. I don't imagine I would agree, based on what I just said. To elaborate, each side of the expression contain symbols which always evaluate to the same constant. The identity of a constant is constant. :) Thus the objects on both sides are indeed the same identical mathematical entity... they are just expressed differently. It's just like if you refered to your kitchen table (assuming you have only one kitchen table) as "the table" or as "the large table I eat on in the kitchen..." No matter what you call it, it's still the same table. In the case where the identity can not be reduced to constants, the two expressions still evaluate to the same mathematical entity... except that you need to set the conditions (i.e. give values to the variables) to find out what that actually is. It seems exactly analogous to Python to me, except that again, unlike Python, there is no possibility that there can ever be two instances of the same object and thus applying the term "identity" to mathematical objects is not useful. It's not that it is meaningless, it just isn't very interesting. Clearly though, 2 is not 3, and these two mathematical objects do not have the same identity. Perhaps there is no concept of identity in mathematics precisely because it is unnecessary: 1 is always 1, by definition. But that is the definition of "is"... :) But the discussion is bordering on philosophy, and I will resign from it at this point, having previously made the points I intended to. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From vminch at gmail.com Fri Jan 2 17:36:04 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 14:36:04 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> Message-ID: <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> > You might better do > > bet = int(raw_input("Enter your bet")) > > because then you don't need to later on convert bet again and again. This is all fine until you give it to an end-user. This is what I picture: $ ./script.py Enter your bet: $10 .. or perhaps "ten", "all", or a jillion other tainted inputs. Python will try to cast these strings, but will slap you with a ValueError instead (an error of some sort, at least). There needs to be a "user_io" or "sanitize" module in the standard library to take care of this stuff. Like: import userio logic = userio.userio() number = logic.getNumeric("blah: ") # will offer the user a "re-do" in case of bad input number = logic.forceGetNumeric("Enter your bet!: ") # even if input is tainted, will return some number text = logic.getText("blargh: ") # return all text text = logic.setValidText("[A-Za-z]") text = logic.forceGetText("blargh: ") # return some text, strips invalid chars ... but there isn't, as far as I know. From geekmail at usenot.de Fri Jan 2 17:41:28 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Fri, 2 Jan 2009 23:41:28 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <20090102234128.0078d982@usenot.de> On Fri, 2 Jan 2009 14:36:04 -0800 (PST) vk wrote: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > [snip example] > Great idea! +1 > ... but there isn't, as far as I know. Well, get to it, then. ;) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From don at geddis.org Fri Jan 2 17:47:35 2009 From: don at geddis.org (Don Geddis) Date: Fri, 02 Jan 2009 14:47:35 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> Message-ID: <878wpt8gvs.fsf@geddis.org> Richard Riley wrote on Thu, 01 Jan 2009: > Tim Greer writes: >> That poster has a frequent habit of cross posting to multiple, irrelevant >> news groups. There's no rhyme or reason to it. > > No rhyme nor reason? It's quite clear, to me, why. How is a comparison > article not relevant when he is trying to stimulate discussion about > alternative languages for modern development? Sometimes crossposting can be useful. But you ought to at least be aware of some of the possible drawbacks, e.g. expressed here: http://www.nhplace.com/kent/PFAQ/cross-posting.html In particular, the usual hope by the poster is that the content is relevant to the union of people in the different groups, but the actual experience is that it is often relevant only to the intersection of such people. And, moreover, that a long cross-posted thread on controversial topics often winds up with people talking at cross-purposes past each other, because they don't share enough common values to have a useful conversation. In particular, the poster that started this thread is well known for adding far more noise than signal to any discussion, and for showing no interest in the greater good of any of the communities, but only in his own glorification. You labor under the delusion that there is at least good intent here, and the poster ought to receive the benefit of the doubt. Long prior experience shows that this hope is misplaced. -- Don _______________________________________________________________________________ Don Geddis http://don.geddis.org/ don at geddis.org The only purpose for which power can be rightfully exercised over any member of a civilized community, against his will, is to prevent harm to others. His own good, either physical or moral, is not a sufficient warrant. -- John Stuart Mill, _On Liberty_ From huffman at tokyo.email.ne.jp Fri Jan 2 17:48:00 2009 From: huffman at tokyo.email.ne.jp (Tokyo Dan) Date: Fri, 2 Jan 2009 14:48:00 -0800 (PST) Subject: If your were going to program a game... References: <85eizlhhu5.fsf@dozer.localdomain> Message-ID: On Jan 3, 12:02?am, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > > browser in a window of a social site built around the game. The social > > site has login, chat, player stats, list of active games, etc. AND > > there is also be a desktop client that accesses the game server via > > the same communication mechanism (like an AIR-based desktop client/ > > app) as the browser-based version - I guess using JSON/RPC. > > Ever see chess.com? > > I don't know what they're using in the backend, but the client is > entirely javascript. > > You could probably roll your own python javascript compiler to suit your > needs. It could probably even build up your own DSL for writing these > games. > > It's a worthwhile project and I think there might be support for it from > other developers. "You could probably roll your own python javascript compiler..." There's already one. I'm surprised that you don't know about it: "Pyjamas" st http://pyjs.org . Also see Pyjamas-desktop" at http://pyjd.org From max at alcyone.com Fri Jan 2 17:53:46 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Jan 2009 14:53:46 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <5fb29c80-a6a4-4cb4-aa62-0d2aeb437662@o4g2000pra.googlegroups.com> Message-ID: Derek Martin wrote: > On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: >>>> Identity isn't defined on math objects, only on Python objects; there >>>> is no notion of 'is' in math. >>> This is also false, it even has its own operator (which requires >>> Unicode to display): ? >> That can mean a number of things, one of which means "is identically >> equal to," > > Quite so. > >> but identity means something different in mathematics than it means >> here. > > But for non-mutable objects, aren't they essentially the same? > Mathematics has no concept of "objects" in the sense that computer > science does, so of course the best you can really do is draw > parallels. That's exactly the point. There is no concept of object identity in mathematics, so the above statement that you called false is, in fact, true. The concept does not translate. >> In computer science, identity means that two expressions are >> represented by the same object, something which not only has no >> meaning in mathematics, > > We're getting way off track here, but I would argue this is also > false. Take sets, for example: > > A = { 1, 2, 3 } > B = { 1, 2, 3 } > > Is it not true that A ? B and in fact these two sets are the same, > i.e. they are not actually two different sets at all; the have the > same identity, even considering a definition of "identity" which > reflects that in Python? Only if you try to make up a concept of identity that mathematics doesn't already have. The existing concept, which you invoked, has nothing to do with _object_ identity, it just has to do with a broader equality. > I don't imagine I would agree, based on what I just said. To elaborate, > each side of the expression contain symbols which always evaluate to > the same constant. The identity of a constant is constant. :) Except identities don't have to contain constants at all. They can contain arbitrary expressions on either side of the "is identically equal to" symbol. Which clearly indicates that the symbol can't mean the same thing as the identity operator in computer science, as you were claiming it did. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis There's something immoral about abandoning your own judgement. -- John F. Kennedy From rt8396 at gmail.com Fri Jan 2 17:57:07 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 14:57:07 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <14ec52c0-69e9-4366-90c3-c91e9a7a48a2@m2g2000vbp.googlegroups.com> > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. [snip] +1 You are sooo right. You know, it is easy to forget about such things after you learn a language, i have written my own input logic, but i remember my __init__ days with python now and the learning curve. Every new user will makes much use of raw_input()[or input 3.0] and has to climb this same little hill every time, you and i do it as second nature. A small module like you describe would be a great addition to the standard library, and heck, i would even use it :) From google at mrabarnett.plus.com Fri Jan 2 18:00:54 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 02 Jan 2009 23:00:54 +0000 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <495e6b08$0$11376$5fc30a8@news.tiscali.it> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <495e6b08$0$11376$5fc30a8@news.tiscali.it> Message-ID: <495E9CA6.20008@mrabarnett.plus.com> Francesco Bochicchio wrote: > imageguy ha scritto: >> I am looking for the most efficient method of replacing a repeating >> sequence in a byte string returned from a imaging .dll, connected via >> >> I receive the byte string with the following sequence 'bgrbgrbgrbgr' >> and I would like to convert this to 'rbgrbgrbgrbg' >> FWIW, the string is created using ctypes.create_string_buffer function >> >> The following code works but feels a bit clunk and is rather slow too. >> >> blist = list(buffer) >> for start in xrange(0,len(blist), 3): >> try: >> blue = blist[start] >> red = blist[start+2] >> blist[start] = red >> blist[start+2] = blue >> except IndexError: >> pass >> >> new_buffer = ''.join(blist) >> >> new_buffer is then passed to a wx program to create and image. >> >> Any thoughts comments would be appreciated. >> >> geoff. >> >> PS: I started this post earlier, but I think I hit the send button >> too soon. My apologies to the group for sloppy typing. >> > You could try the same algorithm on an array.array object : it might be > faster. > >>> s = "012345678" >>> from array import array >>> a = array("b", s) >>> a array('b', [48, 49, 50, 51, 52, 53, 54, 55, 56]) >>> a[0::3], a[2::3] = a[2::3], a[0::3] >>> a array('b', [50, 49, 48, 53, 52, 51, 56, 55, 54]) >>> a.tostring() '210543876' From bignose+hates-spam at benfinney.id.au Fri Jan 2 18:18:55 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 10:18:55 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> Message-ID: <87sko1l2jk.fsf@benfinney.id.au> vk writes: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > Like: > > import userio > > logic = userio.userio() > > number = logic.getNumeric("blah: ") # will offer the user a "re-do" in > case of bad input > number = logic.forceGetNumeric("Enter your bet!: ") # even if input is > tainted, will return some number > > text = logic.getText("blargh: ") # return all text > > text = logic.setValidText("[A-Za-z]") > text = logic.forceGetText("blargh: ") # return some text, strips > invalid chars > > > ... but there isn't, as far as I know. If there were, I would expect it to conform with PEP 8 (get those ugly camelCase names outta there :-) -- \ ?The face of a child can say it all, especially the mouth part | `\ of the face.? ?Jack Handey | _o__) | Ben Finney From bearophileHUGS at lycos.com Fri Jan 2 18:28:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 2 Jan 2009 15:28:57 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <495e6b08$0$11376$5fc30a8@news.tiscali.it> Message-ID: <10101f11-9380-436f-a36a-b16a5bf47611@e1g2000pra.googlegroups.com> imageguy: > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function MRAB: > ?>>> a.tostring() > '210543876' That's not the required 'rbgrbgrbgrbg', but you are close to a correct solution: >>> from array import array >>> s = 'bgrbgrbgrbgr' >>> a = array("B", s) # uppercase B >>> a[0::3], a[1::3], a[2::3] = a[2::3], a[0::3], a[1::3] >>> a.tostring() 'rbgrbgrbgrbg' Bye, bearophile From hamish at valvesoftware.com Fri Jan 2 18:49:25 2009 From: hamish at valvesoftware.com (Hamish McKenzie) Date: Fri, 2 Jan 2009 15:49:25 -0800 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: I actually have no idea what ur talking about... aren't conversations threaded by subject? -----Original Message----- From: python-list-bounces+hamish=valvesoftware.com at python.org [mailto:python-list-bounces+hamish=valvesoftware.com at python.org] On Behalf Of r Sent: Friday, January 02, 2009 12:12 PM To: python-list at python.org Subject: Re: type conversion On Jan 2, 1:46 pm, Robert Kern wrote: > r wrote: > > On Jan 1, 4:40 pm, Robert Kern wrote: > >> Hamish McKenzie wrote: > >>> sometimes I want to be able to initialize an instance with a variety of different data types. > >>> as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix or a quaternion. > >>> is there any other way to do it other than putting case statements in the __init__ method of the class, or having a Matrix.FromQuaternion( quat )? > >> I recommend keeping the __init__() as dumb as possible. Ideally, it should just > >> assign to attributes. I would add a from() classmethod for each that > >> I wanted to support. If I really wanted an all-singing, all-dancing > >> initialization method, I would add another classmethod that would just dispatch > >> to the appropriate type-specific classmethod. I prefer classmethods to plain > >> functions because I can subclass. > > >> -- > >> 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 > > > Why are you busting into this thread? > > Are you talking to me, or Hamish, who (presumably unintentionally) responded to > a message instead of making a new thread? > > If you want to suggest that one should have more care about starting new > threads, that's fine, but please do not jump to the conclusion that there is > malintent. And don't chastise people for not being as rude as you. > > -- > 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 I am not so much chastising Hamish as i am Steven, Steven knows better than this BS, and has preached to so many people about off topic post that my ears are bleeding from his incessant rambling about it. Now, he goes and does what he complains about soooo much. I'm just calling him on it thats all. I can't speak for the other responders because i know of none of them. -- http://mail.python.org/mailman/listinfo/python-list From sjmachin at lexicon.net Fri Jan 2 19:04:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 16:04:32 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> Message-ID: <782c68cf-ce9d-4f32-8ea3-6d57257b1b54@x16g2000prn.googlegroups.com> On Jan 3, 2:01?am, brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: > > On Dec 31 2008, 4:02 pm, brooklineTom wrote: > > > > andyh... at gmail.com wrote: > > > > Hi, > > > > > Can anybody recommend an approach for loading and parsing Excel > > > > spreadsheets in Python. Any well known/recommended libraries for this? > > > > > The only thing I found in a brief search was http://www.lexicon.net/sjmachin/xlrd.htm, > > > > but I'd rather get some more input before going with something I don't > > > > know. > > > > > Thanks, > > > > Andy. > > > > I save the spreadsheets (in Excel) in xml format. > > > Which means that you need to be on a Windows box with a licensed copy > > of Excel. I presume you talking about using Excel 2003 and saving as > > "XML Spreadsheet (*.xml)". Do you save the files manually, or using a > > COM script? What is the largest xls file that you've saved as xml, how > > big was the xml file, and how long did it take to parse the xml file? > > Do you extract formatting information or just cell contents? > > 1. The OP requested Excel files, by construction those must be > generated with a licensed copy of Excel. I did the actual processing > on both linux and windoze platforms. My point was that however the original XLS files were created or acquired, the first step in your solution involves converting the XLS file to "XML Spreadsheet" format, which requires a copy of Excel on a Windows box. Many people start with an XLS file, no Excel and no Windows box, no COM, and users who can't be relied on to open a file and save it in the right format with the right name and extension. BTW, did you consider opening the XLS files with OpenOffice.org's Calc and saving it in their default ods format (chunks of XML in a zip file)? > 3. The largest file I used was about 228M, Is that the XLS file or the XML file? > containing 36,393 hotel > properties from Commission Junction. Each entry had 113 cells. The > parsing overhead was minimal (on a per-entry basis) -- that's why I > choose to use a pull-parser. > 4. I extracted primarily cell contents, though I did some very limited > format handling (looking for non-text fields and such). I don't understand "looking for non-text fields" as "format handling". To my way of thinking, knowing the data-type that Excel has assigned to a cell is close to essential for effective use of the contents. And you don't have to look very far: the ss:Type attribute tells you whether a cell's content is String, Number, DateTime, Boolean, or Error. > > > xhtml. I know there are various python packages around that do it, but > > > I found the learning curve of those packages to be steeper than just > > > grokking the spreadsheet structure itself. > > > I'm curious to know which are the "various python packages" with the > > so steep learning curves, and what the steep bits were. > > I looked, briefly, at xlrd. I found and scanned a few alternatives, > though I don't remember what the others were. I needed something I > could incorporate into my own application framework, and I knew I > didn't need most of the formatting information. I'm not in any way > criticizing xlrd, it's simply that, based on its API summary, it seems > focused on problems I didn't have to solve. Not so focused at all. The default behaviour of xlrd is to ignore formatting info as much as possible. AFAICT this is the mode used by most users. > I knew that I needed only > a small subset of the xlrd behavior, and I concluded (perhaps > incorrectly) that it would be easier to roll my own parser than find, > extract, and then port (to my own framework) the corresponding parts > of xlrd. Possibly incorrectly. If approached at the time, I would have said: (a) if desperate to DIY: (a1) ignore any code for old Excel versions (self.biff_version < 80) (a2) ignore any code for extracting formatting info (self.formatting_info) (a3) find the Sheet.put_cell* methods in sheet.py e.g. def put_cell(self, rowx, colx, ctype, value, xf_index): ignore the xf_index arg and subvert them to your own needs instead of filling up a big rectangular arena with data (b) if not really so desperate, talk to me about implementing an option in xlrd where callers can specify a callback to be used instead of the Sheet.put_cell* methods (c) What is all this "port to my own framework" caper anyway? If you need to extract data from a database, do you rummage in their code libraries and port the relevant bits to your own framework? > > I needed to extract the content of each row, cell by cell, and build > data objects (in my framework) with the content of various cells. I > also needed to build an "exception file" containing malformed entries > that I could re-open with Excel after my code finished, so that the > bogus entries could be manually corrected. What I mean by "malformed" > entry is, for example, an address field that fails to correctly > geocode or comment fields with confused utf8/unicode contents. Building objects in your own framework and checking data integrity is something that happens *after* you've got the basics for a cell (row id, column id, data type, data value). You have dodgy postal addresses? You're not alone, and it's not relevant to how you parse the spreadsheet or even whether the data source was a spreadsheet or a database query or a box of punched cards. > My > focus was on data content, as opposed to presentation. I needed to > crack the cells into things like "string", "boolean", "float", and so > on. "Crack"? It's not the Enigma code. It's not even rot13. Spreadsheet XML tells you the type (String, Boolean, ...). xlrd tells you the type (XL_CELL_TEXT, XL_CELL_BOOLEAN, ...). > > Most importantly, I needed to do this one entry at a time -- I did > *not* want to load the entire spreadsheet at once. > > I'm not saying that this couldn't be done with xlrd; only that I chose > to roll my own and had minimal difficulty doing so. > > I hope this helps! I think so. Thanks. You didn't directly address the "steep learning curve" question, but you explained enough of where you came from. It's a matter of "horses for courses". I guess some people might regard (xml.dom, xml.dom.minidom, DIY "pullparser") as having a slightly non-horizontal learning curve :-) Cheers, John From vminch at gmail.com Fri Jan 2 19:16:10 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 16:16:10 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> Message-ID: <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> > If there were, I would expect it to conform with PEP 8 (get those ugly > camelCase names outta there :-) haha, please forgive me. I'll try and think of some more creative names. atm, I've got a chem final to study for. I'll probably post something resembling useful code tomorrow morning. until then, int(input()) away! From lists at cheimes.de Fri Jan 2 19:16:17 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 03 Jan 2009 01:16:17 +0100 Subject: type conversion In-Reply-To: References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: Hamish McKenzie schrieb: > I actually have no idea what ur talking about... aren't conversations threaded by subject? Nope, they are threaded by message id. The subject is used as fallback only. Christian From tim at burlyhost.com Fri Jan 2 19:20:49 2009 From: tim at burlyhost.com (Tim Greer) Date: Fri, 02 Jan 2009 16:20:49 -0800 Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: Don Geddis wrote: > Richard Riley wrote on Thu, 01 Jan 2009: >> Tim Greer writes: >>> That poster has a frequent habit of cross posting to multiple, >>> irrelevant >>> news groups. There's no rhyme or reason to it. >> >> No rhyme nor reason? It's quite clear, to me, why. How is a >> comparison article not relevant when he is trying to stimulate >> discussion about alternative languages for modern development? > > Sometimes crossposting can be useful. But you ought to at least be > aware of some of the possible drawbacks, e.g. expressed here: > http://www.nhplace.com/kent/PFAQ/cross-posting.html > > In particular, the usual hope by the poster is that the content is > relevant to the union of people in the different groups, but the > actual experience is that it is often relevant only to the > intersection of such people. > > And, moreover, that a long cross-posted thread on controversial topics > often winds up with people talking at cross-purposes past each other, > because they don't share enough common values to have a useful > conversation. > > In particular, the poster that started this thread is well known for > adding far more noise than signal to any discussion, and for showing > no interest in the greater good of any of the communities, but only in > his own glorification. > > You labor under the delusion that there is at least good intent here, > and the > poster ought to receive the benefit of the doubt. Long prior > experience shows that this hope is misplaced. > > -- Don Thank you, Don, for outlining the issue far more eloquently than I was able to. Also, to be clear, I don't think anyone's upset that people find his posts interesting, but it doesn't make it so for everyone else (or assign them any ailment if they don't see it that way) -- especially in regard to the other groups he cross posts to (of which one should have specifically been the ruby group, but I digress.) -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From geekmail at usenot.de Fri Jan 2 19:26:25 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 3 Jan 2009 01:26:25 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <20090103012625.2d0fbf21@usenot.de> On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. FYI: The names themselves aren't he problem at all. They just should be all_lowercase_with_underscores if they're functions or variables. CamelCase (with initial capital!) is "reserved" for classnames only. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From sjmachin at lexicon.net Fri Jan 2 19:33:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 16:33:28 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> On Jan 3, 5:34?am, imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. For some very strange definition of "works". You say you have 'bgr' and want to convert it to 'rbg'. The following code converts 'bgr' to 'rgb', which is somewhat more plausible, but not what you said you wanted. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > ? ?try: > ? ? ? ? blue = blist[start] > ? ? ? ? red = blist[start+2] > ? ? ? ? blist[start] = red > ? ? ? ? blist[start+2] = blue > ? ?except IndexError: > ? ? ? ?pass > > new_buffer = ''.join(blist) > From rt8396 at gmail.com Fri Jan 2 19:44:11 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 16:44:11 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> Message-ID: On Jan 2, 6:26?pm, Andreas Waldenburger wrote: > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-) ? > > > haha, please forgive me. > > I'll try and think of some more creative names. > > FYI: The names themselves aren't he problem at all. They just should > be all_lowercase_with_underscores if they're functions or variables. > CamelCase (with initial capital!) is "reserved" for classnames only. > > /W > > -- > My real email address is constructed by swapping the domain with the > recipient (local part). FYI camelCase with __init__ capital is called "title case" try this: >>> 'hello world".title() From greno at verizon.net Fri Jan 2 19:54:38 2009 From: greno at verizon.net (Gerry Reno) Date: Fri, 02 Jan 2009 19:54:38 -0500 Subject: Why not Ruby? In-Reply-To: References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: <495EB74E.10301@verizon.net> There's been almost 50 responses to this rubbish post. Could you please all stop! From geekmail at usenot.de Fri Jan 2 19:57:25 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 3 Jan 2009 01:57:25 +0100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> Message-ID: <20090103015725.086f7658@usenot.de> On Fri, 2 Jan 2009 16:44:11 -0800 (PST) r wrote: > On Jan 2, 6:26?pm, Andreas Waldenburger wrote: > > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > > > If there were, I would expect it to conform with PEP 8 (get > > > > those ugly camelCase names outta there :-) ? > > > > > haha, please forgive me. > > > I'll try and think of some more creative names. > > > > FYI: The names themselves aren't he problem at all. They just should > > be all_lowercase_with_underscores if they're functions or variables. > > CamelCase (with initial capital!) is "reserved" for classnames only. > > > > /W > > > > -- > > My real email address is constructed by swapping the domain with the > > recipient (local part). > > FYI camelCase with __init__ capital is called "title case" try this: > OK, since we're smartassing anyway: CamelCase refers specifically to compound words or phrases that are conjoined, that is, written without spaces between the words, where words are separated by writing their respective first letters in capitals. Title case however refers to normal phrases where (space separated) words are capitalized, and no inner capitals occur (unless of course actual CamelCase words are used in the phrase). You even assumed that distinction in your example: > >>> 'hello world".title() /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gherron at islandtraining.com Fri Jan 2 20:05:35 2009 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 02 Jan 2009 17:05:35 -0800 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> Message-ID: <495EB9DF.6050001@islandtraining.com> imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function > > The following code works but feels a bit clunk and is rather slow too. > > blist = list(buffer) > for start in xrange(0,len(blist), 3): > try: > blue = blist[start] > red = blist[start+2] > blist[start] = red > blist[start+2] = blue > except IndexError: > pass > > new_buffer = ''.join(blist) > > new_buffer is then passed to a wx program to create and image. > > Any thoughts comments would be appreciated. > > geoff. > > PS: I started this post earlier, but I think I hit the send button > too soon. My apologies to the group for sloppy typing. > > -- > http://mail.python.org/mailman/listinfo/python-list > I've not seen anyone mention numpy yet, but numpy has a nice (efficient) way to do this: >>> import numpy >>> s = 'bgrBGRcbaCBA' >>> a=numpy.array(s, 'c') # Initialize an array >>> a.shape = (4,3) # Reinterpret as a ?? by 3 array >>> b=a[...,::-1] # reverse the second dimension >>> print b.tostring() # Convert back to a string. rgbRGBabcABC Gary Herron From sjmachin at lexicon.net Fri Jan 2 20:06:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jan 2009 17:06:02 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <27cc82fd-277e-4420-8df5-ac64c5c37e6e@b38g2000prf.googlegroups.com> On Jan 3, 11:16?am, vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those ugly > > camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. > > atm, I've got a chem final to study for. > I'll probably post something resembling useful code tomorrow morning. > > until then, int(input()) away! Building on the earlier example (entering the amount of money for a bet), consider the following possibilities: 10 $10 USD 10.00 USD 10,00 # many European locales 10000 # moving to the high rollers table 10,000 10.000 # European 10T # T -> thousand dates: 1/12/35 # 1 December or 12 January? What year? 2035? Perhaps not, if the prompt was 'Enter pensioner's date of birth -> '. etc etc ... IOW consider not biting off more than you can chew. Also consider that raw_input is not sufficiently frequently used in real-world applications to warrant a data validation library to be built on top of it. From rt8396 at gmail.com Fri Jan 2 20:12:00 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 17:12:00 -0800 (PST) Subject: Why not Ruby? References: <6IQ6l.57340$ly1.11422@newsfe19.iad> <878wpt8gvs.fsf@geddis.org> Message-ID: On Jan 2, 6:54?pm, Gerry Reno wrote: > There's been almost 50 responses to this rubbish post. Could you please > all stop! Donde es Xah Lee? From bignose+hates-spam at benfinney.id.au Fri Jan 2 20:20:32 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 12:20:32 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> Message-ID: <87k59dkwwv.fsf@benfinney.id.au> vk writes: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. They don't need to be creative; they merely need to conform with the naming scheme as laid out in the PEP. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From 4329402926 at txt.att.net Fri Jan 2 20:28:39 2009 From: 4329402926 at txt.att.net (4329402926 at txt.att.net) Date: Fri, 2 Jan 2009 20:28:39 -0500 Subject: No subject Message-ID: <20090103012839.KNSY5498.atlmtaow03.cingularme.com@txt.att.net> -- ================================================================== This mobile text message is brought to you by AT&T From mario.ruggier at gmail.com Fri Jan 2 20:29:29 2009 From: mario.ruggier at gmail.com (mario) Date: Fri, 2 Jan 2009 17:29:29 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? Message-ID: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Hi, below is the essence of a an expression evaluator, by means of a getitem lookup. The expression codes are compiled and cached -- the lookup is actually recursive, and the first time around it will always fail. import sys class GetItemEval(object): def __init__(self): self.globals = globals() # some dict (always the same) self.locals = {} # some other dict (may be different between evaluations) self.codes = {} # compiled code expressions cache def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # KeyError, NameError, AttributeError, SyntaxError, ValueError, # TypeError, IOError # # Special case if a KeyError is coming from the self.codes [name] # lookup (traceback should consist of a single frame only): if sys.exc_info()[2].tb_next is None: if sys.exc_info()[0] is KeyError: self.codes[expr] = compile(expr, '', 'eval') return self[expr] # otherwise handle eval error in some way... This class could be used in a way as follows: # define some expressions def f(s): return "["+s+"]" exprs = ["1+2+3", "2*3*5", "f(__name__)"] # instantiate one gie = GetItemEval() # use it to lookup/eval each expression for x in exprs: print x, "=", gie[x] And, fwiw, some sample timeit code: import timeit print timeit.Timer("for x in exprs: gie[x]", "from __main__ import gie, exprs").timeit(500000) I had done various poking to discover if it could be made to go faster, and in the end I settled on the version above. mario Incidentally this constitutes the lion's share of the evaluation runtime of evoque templating... http://evoque.gizmojo.org/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 20:46:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 01:46:37 GMT Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> Message-ID: <016eba68$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 15:49:25 -0800, Hamish McKenzie wrote: > I actually have no idea what ur talking about... aren't conversations > threaded by subject? Not usually. When you hit Reply to a post, your post gets a hidden header line that says "I'm a reply to post #12345" (whatever post number it is). Just because you change the subject line doesn't change that. Most newsreader programs thread by that header, not the subject. Consequently most people who view posts in thread order will see: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Hello I'm changing the subject line +-- Re: Hello I'm changing the subject line +-- Re: Subject X Y Z +-- Re: Subject X Y Z This has the serious disadvantages that: (1) It annoys people who do threading; and (2) If people are ignoring a thread, they won't even see your post even though you have changed the subject line. It is considered rude to hijack a thread for a completely new subject, although it is acceptable to change the subject line if the thread gradually evolves to a new discussion: Subject X Y Z +-- Re: Subject X Y Z +-- Re: Subject X Y Z +-- Subject A B C [was Re: Subject X Y Z] +-- Re: Subject A B C [was Re: Subject X Y Z] Don't mistake the above for off-topic posting, which is something completely different, nor for cross-posting, which is different again. Off-topic posts are ones that don't have anything to do with the news group they are sent to, e.g. a message about Ruby sent to a Python list. It is barely acceptable to occasionally post brief off-topic messages that are particularly amusing or important if you label them such with [OT] or [off-topic] in the subject line. Cross-posting is sending a single message to more than one newsgroup. If you absolutely must cross-post, you should always set the Followup-To header to *one* newsgroup. If you don't know how to set followups, then don't cross-post. -- Steven From aleksandr.goretoy at gmail.com Fri Jan 2 20:52:04 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 01:52:04 +0000 Subject: list iteration if statement Message-ID: Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not int("0") then append to v list? Thank you in advance. -A -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 2 21:02:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 21:02:19 -0500 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <87k59dkwwv.fsf@benfinney.id.au> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > vk writes: > >>> If there were, I would expect it to conform with PEP 8 (get those >>> ugly camelCase names outta there :-) >> haha, please forgive me. >> I'll try and think of some more creative names. > > They don't need to be creative; they merely need to conform with the > naming scheme as laid out in the PEP. > They don't *need* to do that. It's just a good habit to get into if you plan to write code that gets read and possibly modified by other people. If you write a function called doSomething the PSU won't "%@#&%":,,.. carrier lost From aleksandr.goretoy at gmail.com Fri Jan 2 21:05:49 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:05:49 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login", "user":l["user"], "pass":l["pass"] } and it wouldn't work. So I had to do some research on how to make it work. passing a mutable object resolved my problem. Thank you for correcting me. -A On Thu, Jan 1, 2009 at 6:22 PM, Terry Reedy wrote: > alex goretoy wrote: > >> I recently conquered this pass by ref thing. This is how I did it. >> > > What you did was to pass a mutable object and mutate it. Absolutely > standard practice in Python. I am glad you learned it, but also learning > and using the standard terminology will also help. Hope you enjoy Python > too. > > tjr > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:07:35 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:07:35 +0000 Subject: Pass by reference In-Reply-To: References: <529e1d98-8932-49f0-b569-85285bd50f23@p2g2000prn.googlegroups.com> Message-ID: You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login", "user":l["user"], "pass":l["pass"] } and it wouldn't work. So I had to do some research on how to make it work. passing a mutable object resolved my problem. Thank you for correcting me. -A ps.I have this habit of pressing reply instead of reply to all. Working on fixing that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Fri Jan 2 21:07:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 02:07:57 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: <495EC87D.4040003@mrabarnett.plus.com> alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A > By: if j is not int("0") I assume you mean: if j != int("0") or just: if j != 0 The list comprehension is: [[v.append(j) for j in i if j != 0] for i in self.value] BWT, do you know that v.append(j) modifies v in-place and returns None, so the result of the list comprehension is a list of lists of None? From steve at holdenweb.com Fri Jan 2 21:09:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 21:09:48 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A Who, tiger. It "works" for a value of "works" that involves creating two lists. One is the one you want, referenced by v, and the other is the value if the list comprehension, which will be a list full of lists of all the None values returned by those append() calls. But I presume you are throwing that second list away ... See, a list comprehension is intended to create a list. So what you should have used (assuming v was the empty list before you started) was v = [[j for j in i] for i in self.value] Further, when you say 'j is not int("0")', do you actually mean that a is not in integer with the value 0? Assuming you do then what you need is v = [[j for j in i if not j] for i in self.value] or, more pedantically v = [[j for j in i if j==0] for i in self.value] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From s0suk3 at gmail.com Fri Jan 2 21:15:57 2009 From: s0suk3 at gmail.com (s0suk3 at gmail.com) Date: Fri, 2 Jan 2009 18:15:57 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: On Jan 2, 7:20?pm, Ben Finney wrote: > vk writes: > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-) > > > haha, please forgive me. > > I'll try and think of some more creative names. > > They don't need to be creative; they merely need to conform with the > naming scheme as laid out in the PEP. If it's something to be included in the standard library, I agree (just for consistency, not because using_underscores is better). But for user code, I prefer mixedCase. +1 for mixedCase! Sebastian From rt8396 at gmail.com Fri Jan 2 21:20:52 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 18:20:52 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <20090103012625.2d0fbf21@usenot.de> <20090103015725.086f7658@usenot.de> Message-ID: On Jan 2, 6:57?pm, Andreas Waldenburger wrote: [snip] > You even assumed that distinction in your example: > > > >>> 'hello world".title() [snip] sorry, here is TitleCase.py_b2 py> 'hello world'.title().replace(' ', '') From aleksandr.goretoy at gmail.com Fri Jan 2 21:38:54 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:38:54 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing this I get an unwanted list of None how do I make it disappear or not return this list. Would I have to be modifying it in place for this to happen? Wouldn't modifying it in place potentially overwrite some other values? I just don't want it to return [[None], [None, None], [None, None], [None]] You guys rock, thanks for helping me learn python. On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: > alex goretoy wrote: > > Hello All, > > > > I'm doing this in my code > > > > [[v.append(j) for j in i] for i in self.value] > > > > if works and all, but I need to add a if statement in the mix. Can't > > seem to remember the syntax to do so and everything I've tried seems to > > fail. How do I add a check to see if j is not int("0") then append to v > > list? Thank you in advance. -A > > Who, tiger. It "works" for a value of "works" that involves creating two > lists. One is the one you want, referenced by v, and the other is the > value if the list comprehension, which will be a list full of lists of > all the None values returned by those append() calls. But I presume you > are throwing that second list away ... > > See, a list comprehension is intended to create a list. So what you > should have used (assuming v was the empty list before you started) was > > v = [[j for j in i] for i in self.value] > > Further, when you say 'j is not int("0")', do you actually mean that a > is not in integer with the value 0? Assuming you do then what you need is > > v = [[j for j in i if not j] for i in self.value] > > or, more pedantically > > v = [[j for j in i if j==0] for i in self.value] > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:43:46 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:43:46 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: rather, how do I suppress the output of the list with all None in it? >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] >>> v=[] >>> [[v.append(j)for j in i if j != "0"] for i in l] [[None], [None], [None], []] >>> v ['39', '32', '1'] >>> On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > > the value is actually stored as a string so I would need to check if it is > "0". I do have one more question about list comprehension though. After > doing this I get an unwanted list of None how do I make it disappear or not > return this list. Would I have to be modifying it in place for this to > happen? Wouldn't modifying it in place potentially overwrite some other > values? I just don't want it to return [[None], [None, None], [None, None], > [None]] > > You guys rock, thanks for helping me learn python. > > > On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: > >> alex goretoy wrote: >> > Hello All, >> > >> > I'm doing this in my code >> > >> > [[v.append(j) for j in i] for i in self.value] >> > >> > if works and all, but I need to add a if statement in the mix. Can't >> > seem to remember the syntax to do so and everything I've tried seems to >> > fail. How do I add a check to see if j is not int("0") then append to v >> > list? Thank you in advance. -A >> >> Who, tiger. It "works" for a value of "works" that involves creating two >> lists. One is the one you want, referenced by v, and the other is the >> value if the list comprehension, which will be a list full of lists of >> all the None values returned by those append() calls. But I presume you >> are throwing that second list away ... >> >> See, a list comprehension is intended to create a list. So what you >> should have used (assuming v was the empty list before you started) was >> >> v = [[j for j in i] for i in self.value] >> >> Further, when you say 'j is not int("0")', do you actually mean that a >> is not in integer with the value 0? Assuming you do then what you need is >> >> v = [[j for j in i if not j] for i in self.value] >> >> or, more pedantically >> >> v = [[j for j in i if j==0] for i in self.value] >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Jan 2 21:47:42 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 02:47:42 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: v should have ['3','4','1'] sorry if I made it confusing. On Sat, Jan 3, 2009 at 2:43 AM, alex goretoy wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > [[None], [None], [None], []] > >>> v > ['39', '32', '1'] > > >>> > > On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > >> Thank you Steve and MRAB, >> >> This is what I was looking for: >> >> [[v.append(j) for j in i if j != 0] for i in self.value] >> >> the value is actually stored as a string so I would need to check if it is >> "0". I do have one more question about list comprehension though. After >> doing this I get an unwanted list of None how do I make it disappear or not >> return this list. Would I have to be modifying it in place for this to >> happen? Wouldn't modifying it in place potentially overwrite some other >> values? I just don't want it to return [[None], [None, None], [None, None], >> [None]] >> >> You guys rock, thanks for helping me learn python. >> >> >> On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden wrote: >> >>> alex goretoy wrote: >>> > Hello All, >>> > >>> > I'm doing this in my code >>> > >>> > [[v.append(j) for j in i] for i in self.value] >>> > >>> > if works and all, but I need to add a if statement in the mix. Can't >>> > seem to remember the syntax to do so and everything I've tried seems to >>> > fail. How do I add a check to see if j is not int("0") then append to v >>> > list? Thank you in advance. -A >>> >>> Who, tiger. It "works" for a value of "works" that involves creating two >>> lists. One is the one you want, referenced by v, and the other is the >>> value if the list comprehension, which will be a list full of lists of >>> all the None values returned by those append() calls. But I presume you >>> are throwing that second list away ... >>> >>> See, a list comprehension is intended to create a list. So what you >>> should have used (assuming v was the empty list before you started) was >>> >>> v = [[j for j in i] for i in self.value] >>> >>> Further, when you say 'j is not int("0")', do you actually mean that a >>> is not in integer with the value 0? Assuming you do then what you need is >>> >>> v = [[j for j in i if not j] for i in self.value] >>> >>> or, more pedantically >>> >>> v = [[j for j in i if j==0] for i in self.value] >>> >>> regards >>> Steve >>> -- >>> Steve Holden +1 571 484 6266 +1 800 494 3119 >>> Holden Web LLC http://www.holdenweb.com/ >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? >> ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? >> > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 21:47:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 02:47:44 GMT Subject: list iteration if statement References: Message-ID: <016ec8b9$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 01:52:04 +0000, alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, Replacing "self.value" with a list of lists of ints: >>> list_of_lists = [[1, 2, 3], [2, 4, 6]] >>> v = [] >>> output = [[v.append(j) for j in sublist] for sublist in list_of_lists] >>> v [1, 2, 3, 2, 4, 6] >>> output [[None, None, None], [None, None, None]] So you create two lists, one is a copy of self.value which has been flattened, and the other is a nested list of nothing but None. What a waste of effort if your input is large. Why not just do the obvious for loop? v = [] for L in list_of_lists: for item in L: v.append(item) > but I need to add a if statement in the mix. Using a for loop, it should be obvious: v = [] for L in list_of_lists: for item in L: if item != 0: v.append(item) > Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. If you *insist* on doing it the wrong way, [[v.append(j) for j in i if j != 0] for i in self.value] > How do I add a check to see if j is not int("0") then append to v > list? Thank you in advance. -A Is there some significance of you saying int("0") instead of 0? -- Steven. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 2 21:47:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 02:47:57 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <016ec8c6$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 21:02:19 -0500, Steve Holden wrote: > Ben Finney wrote: >> vk writes: >> >>>> If there were, I would expect it to conform with PEP 8 (get those >>>> ugly camelCase names outta there :-) >>> haha, please forgive me. >>> I'll try and think of some more creative names. >> >> They don't need to be creative; they merely need to conform with the >> naming scheme as laid out in the PEP. >> > They don't *need* to do that. They do if you want it accepted into the standard library, which was the hope. Not *my* hope, you understand, but that of the person who suggested it :) -- Steven From google at mrabarnett.plus.com Fri Jan 2 22:12:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 03:12:38 +0000 Subject: list iteration if statement In-Reply-To: References: Message-ID: <495ED7A6.4090205@mrabarnett.plus.com> alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > > the value is actually stored as a string so I would need to check if it > is "0". I do have one more question about list comprehension though. > After doing this I get an unwanted list of None how do I make it > disappear or not return this list. Would I have to be modifying it in > place for this to happen? Wouldn't modifying it in place potentially > overwrite some other values? I just don't want it to return [[None], > [None, None], [None, None], [None]] > > You guys rock, thanks for helping me learn python. > No, it's Python that rocks. ;-) [snip] From rt8396 at gmail.com Fri Jan 2 22:23:00 2009 From: rt8396 at gmail.com (r) Date: Fri, 2 Jan 2009 19:23:00 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016eba68$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 2, 7:46?pm, Steven D'Aprano wrote: ...incessant rambling about a news reader , 101 excuses for butting into a thread [snip] Throw your newsreader in the garbage and use Google groups, less headache, more filling! No need to worry about "hidden headers" And you may even get a star or 2 :) > If people are ignoring a thread, they won't even see your post even though you have changed the subject line. Yea NO $#Y, that makes a lot of sense, if i am ignoring something i course i will not see it! OK, Steven so you did not go off topic you simply high-jacked this thread. I get it now :) From mensanator at aol.com Fri Jan 2 22:23:17 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 2 Jan 2009 19:23:17 -0800 (PST) Subject: list iteration if statement References: Message-ID: <65f824f9-4f9d-4888-993c-79685d2dea5d@o40g2000prn.googlegroups.com> On Jan 2, 8:43?pm, "alex goretoy" wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > > [[None], [None], [None], []] > > >>> v > ['39', '32', '1'] > Assign it to something. >>> ignore_me = [[v.append(j)for j in i if j != "0"] for i in l] >>> v ['3', '4', '1'] From Russ.Paielli at gmail.com Fri Jan 2 22:28:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 2 Jan 2009 19:28:15 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <9730b858-421f-4214-acb9-3c359c257339@s9g2000prg.googlegroups.com> On Jan 2, 6:15?pm, s0s... at gmail.com wrote: > On Jan 2, 7:20?pm, Ben Finney > wrote: > > > vk writes: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > > ugly camelCase names outta there :-) > > > > haha, please forgive me. > > > I'll try and think of some more creative names. > > > They don't need to be creative; they merely need to conform with the > > naming scheme as laid out in the PEP. > > If it's something to be included in the standard library, I agree > (just for consistency, not because using_underscores is better). > > But for user code, I prefer mixedCase. > > +1 for mixedCase! > > Sebastian I agree. I find underscores in variable names to be both ugly and harder to read. At first glance, the underscores are easy to miss. From steve at holdenweb.com Fri Jan 2 23:04:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 23:04:27 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > No, it wasn't. You should *not* be modifying v in the list comprehension! > the value is actually stored as a string so I would need to check if it > is "0". I do have one more question about list comprehension though. If the value is stored as a string them you should be testing for "0", not 0. > After doing this I get an unwanted list of None how do I make it > disappear or not return this list. Would I have to be modifying it in > place for this to happen? Wouldn't modifying it in place potentially > overwrite some other values? I just don't want it to return [[None], > [None, None], [None, None], [None]] > If you just want to append all those lists to v then you should just say v += [[j for j in i if j != "0"] for i in self.value] You are getting the None values because the append method returns None. regards Steve > You guys rock, thanks for helping me learn python. > > On Sat, Jan 3, 2009 at 2:09 AM, Steve Holden > wrote: > > alex goretoy wrote: > > Hello All, > > > > I'm doing this in my code > > > > [[v.append(j) for j in i] for i in self.value] > > > > if works and all, but I need to add a if statement in the mix. Can't > > seem to remember the syntax to do so and everything I've tried > seems to > > fail. How do I add a check to see if j is not int("0") then append > to v > > list? Thank you in advance. -A > > Who, tiger. It "works" for a value of "works" that involves creating two > lists. One is the one you want, referenced by v, and the other is the > value if the list comprehension, which will be a list full of lists of > all the None values returned by those append() calls. But I presume you > are throwing that second list away ... > > See, a list comprehension is intended to create a list. So what you > should have used (assuming v was the empty list before you started) was > > v = [[j for j in i] for i in self.value] > > Further, when you say 'j is not int("0")', do you actually mean that a > is not in integer with the value 0? Assuming you do then what you > need is > > v = [[j for j in i if not j] for i in self.value] > > or, more pedantically > > v = [[j for j in i if j==0] for i in self.value] > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 2 23:07:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 02 Jan 2009 23:07:36 -0500 Subject: list iteration if statement In-Reply-To: References: Message-ID: alex goretoy wrote: > v should have ['3','4','1'] sorry if I made it confusing. > [...] Aah, I see I was giving you incorrect advice. I now realise that you want to flatten the lists as well. Don't try to do this with a list comprehension. It won't work without creating an unnecessary list of lists of None. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Fri Jan 2 23:55:12 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Fri, 2 Jan 2009 20:55:12 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: On Jan 3, 2:38?am, mr wrote: > As has been noted, the best is to fix the input to be regular-3- > tuples. For the fun of it, here's another variation of a solution: > > tuples = [(1, 2), (3, 4, 5), (6, 7)] > > def triple_or_pair(seq): > ? ? u = None > ? ? try: > ? ? ? ? k, u, v = seq > ? ? except ValueError: > ? ? ? ? k, v = seq > ? ? return k, u, v > > for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: > ? ? print k, u, v It is a code to post some data to HTML server. Even though usually the POST values are of type(name, value), if file transfer is involved, then POST values change to (name, filename, value). My view was that since filename is a rare occurance and doesnt make sense in a usual POST, I had not kept it as a full 3 tuple. Since so many programmers (that too much more capable than me) are suggesting that it is code smell, I am reviewing my decision. From vminch at gmail.com Sat Jan 3 00:05:28 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 21:05:28 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <9730b858-421f-4214-acb9-3c359c257339@s9g2000prg.googlegroups.com> Message-ID: <2cf9d91e-99ee-45de-87b3-9c185ffd6c7b@f40g2000pri.googlegroups.com> > etc etc ... IOW consider not biting off more than you can chew. It's possible that I am, but where's the fun without the risk? Good thinking in your post though! I will add "get_date" at some point, and I've modified "get_numeric" already. All-right, the moment you've all been waiting for: --------------------------------------------------------------------- http://docs.google.com/View?docid=dgsp7w2t_2gwf447g8 --------------------------------------------------------------------- Provides: 1) user_io.user_io -- get_text(msg) -- filter_get(msg, valid_chars) -- get_numeric(msg) -- bully_numeric(msg) 2) user_io.progress_bar -- ping() -- stop() Read the doc-strings for details. I know it isn't perfect, so just yell at me on this thread if you don't like something and I'll try to fix it. Actually, I'd rather you fix it yourself and THEN yell at me to update the module. have fun! From vminch at gmail.com Sat Jan 3 00:17:37 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 21:17:37 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Message-ID: What do you mean by 'fail'? you have; :: self.codes = {} so :: try: :: return eval(self.codes[expr], self.globals, self.locals) will always return an exception the first time (if this is what you're referring to). From aleksandr.goretoy at gmail.com Sat Jan 3 00:18:28 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 05:18:28 +0000 Subject: Is there a better algorithm? In-Reply-To: References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: I personally like this solution the best. Thanks mr. tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u, v for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: print k, u, v On Sat, Jan 3, 2009 at 4:55 AM, Kottiyath wrote: > On Jan 3, 2:38 am, mr wrote: > > As has been noted, the best is to fix the input to be regular-3- > > tuples. For the fun of it, here's another variation of a solution: > > > > tuples = [(1, 2), (3, 4, 5), (6, 7)] > > > > def triple_or_pair(seq): > > u = None > > try: > > k, u, v = seq > > except ValueError: > > k, v = seq > > return k, u, v > > > > for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: > > print k, u, v > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 01:16:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jan 2009 06:16:39 GMT Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> Message-ID: <016ef9b0$0$8693$c3e8da3@news.astraweb.com> On Fri, 02 Jan 2009 17:29:29 -0800, mario wrote: > Hi, > > below is the essence of a an expression evaluator, by means of a getitem > lookup. The expression codes are compiled and cached -- the lookup is > actually recursive, and the first time around it will always fail. > > import sys > class GetItemEval(object): > > def __init__(self): > self.globals = globals() # some dict (always the same) > self.locals = {} # some other dict (may be different between > evaluations) > self.codes = {} # compiled code expressions cache > > def __getitem__(self, expr): > try: > return eval(self.codes[expr], self.globals, self.locals) I was about to make a comment about this being a security hole, but I see from here http://evoque.gizmojo.org/usage/restricted/ that you are aware of at least some of the issues. I must say though, your choice of builtins to prohibit seems rather arbitrary. What is dangerous about (e.g.) id() and isinstance()? > except: > # KeyError, NameError, AttributeError, SyntaxError, > # ValueError, TypeError, IOError If you want to capture seven exceptions, then capture seven exceptions, not any exception. You should write: except (KeyError, NameError, ..., IOError): instead of a bare except clause. That will capture exceptions that represent bugs in your code as well as exceptions that should propbably be allowed to propagate, such as KeyboardInterupt and SystemExit. > # Special case if a KeyError is coming from the self.codes[name] > # lookup (traceback should consist of a single frame only): > if sys.exc_info()[2].tb_next is None: > if sys.exc_info()[0] is KeyError: > self.codes[expr] = compile(expr, '', 'eval') > return self[expr] > # otherwise handle eval error in some way... That seems awfully complicated for no good reason. If you want to handle KeyError differently, then capture KeyError: try: ... except KeyError: handle_keyerror() except: (NameError, ..., IOError): handle_everythingelse() It also seems significant slower: >>> import sys >>> def catch1(): ... D = {} ... try: ... D['x'] ... except KeyError: ... pass ... >>> def catch2(): ... D = {} ... try: ... D['x'] ... except: ... if sys.exc_info()[2].tb_next is None: ... if sys.exc_info()[0] is KeyError: ... pass ... >>> from timeit import Timer >>> t1 = Timer('catch1()', 'from __main__ import catch1') >>> t2 = Timer('catch2()', 'from __main__ import catch2, sys') >>> min(t1.repeat()) 4.8421750068664551 >>> min(t2.repeat()) 6.2694659233093262 -- Steven From bignose+hates-spam at benfinney.id.au Sat Jan 3 01:50:33 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 03 Jan 2009 17:50:33 +1100 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> Message-ID: <87d4f4lw7a.fsf@benfinney.id.au> s0suk3 at gmail.com writes: > On Jan 2, 7:20?pm, Ben Finney > wrote: > > They don't need to be creative; they merely need to conform with > > the naming scheme as laid out in the PEP. > > If it's something to be included in the standard library, I agree > (just for consistency, not because using_underscores is better). > > But for user code, I prefer mixedCase. That seems superficially like an easy distinction. Indeed, PEP 8 explicitly is meant to apply only to code intended for inclusion in the Python standard library. But consider: Python libraries generally don't get into the standard library until they've had a history of widespread public use as an external library. This helps ensure many of the harder-to-find wrinkles get discovered through wide exposure and ironed out before becoming standard. Code bases, especially library interfaces, that get a lot of use across wide communities are naturally going to have a whole lot of other people's code directly using those interfaces. Interfaces that are so widely used garner a high resistance to change, especially for something as non-functional as a naming convention. Choosing the naming convention for one's code is much easier to do when its usage base is smaller than when that base is larger. Therefore the easiest time to choose when to code in conformance to PEP 8 is right at the start. The best conclusion I can come to from this? Unless you explicitly *never* intend sharing your code with *anyone*, it's best to code all your Python code in accordance with PEP 8 anyway. You then don't have to make the decision about whether this is the time to follow PEP 8 or not; just do it by default, and you avoid the needless pain on those occasions, often unforeseeable at the start, where your code later ends up widely used. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From vminch at gmail.com Sat Jan 3 02:18:08 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 23:18:08 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> Message-ID: <91201b2b-7a66-49ae-b25f-b377dbb6bad4@z6g2000pre.googlegroups.com> > Unless you explicitly *never* intend sharing your code with *anyone*, > it's best to code all your Python code in accordance with PEP 8 anyway. Well said. Let's bury the puppy already. Anyone have something to say about the userio stuff? From vminch at gmail.com Sat Jan 3 02:22:51 2009 From: vminch at gmail.com (vk) Date: Fri, 2 Jan 2009 23:22:51 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <91201b2b-7a66-49ae-b25f-b377dbb6bad4@z6g2000pre.googlegroups.com> Message-ID: > Anyone have something to say about the userio stuff? (If you're going to post something about my coding style, I invite you to do something infinitely more useful: write crapToPep8.py {or is it crap_to_pep8?} to satisfy your sick fetish for consistency.) From mail at microcorp.co.za Sat Jan 3 03:40:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 3 Jan 2009 10:40:39 +0200 Subject: Is there a better algorithm? References: <77ff3cab-87cc-4117-8944-881ad347719c@k1g2000prb.googlegroups.com> <95c3672c-105e-46b9-a241-7cb199ed45ba@r15g2000prh.googlegroups.com> Message-ID: <021201c96d83$603b1d40$0d00a8c0@hendrik> bearophile wrote: >Fuzzyman: > >> for i in l: >> u = None >> if len(i) == 2: >> k, v = i >> else: >> k, u, v = i > >That's the best solution I have seen in this thread so far (but I >suggest to improve indents and use better variable names). In >programming it's generally better to follow the KISS principle. Strange that nobody has suggested: for Tup in Lst: for item in Tup: print item, print Because if I recall correctly, all the OP was doing was printing the stuff. Gets a bit hairier if you want to return the values though. - if you replace the first print statement above with a yield and delete the second, bare print, you lose knowledge of which tuple the item belongs to. It is not trivial to do if you don't have a priori knowledge of the maximum and minimum tuple length. Seems to me it is one of those gems that is a PITA to do completely generally - basically because you don't know when you call it how many items to unpack - so you have to return a count or something, or just fall back on a two step approach - get the tuple from the list, then do something with the items in the tuple. - Hendrik From geon at post.cz Sat Jan 3 04:39:41 2009 From: geon at post.cz (Pavel Kosina) Date: Sat, 03 Jan 2009 10:39:41 +0100 Subject: patch Message-ID: <495F325D.8090204@post.cz> T?k? se to Pythonu okrajov?, p?esto to d?v?m sem. Mysl?m, ?e by se mohlo hodit i ostatn?m, kdo cht?j? zkou?et pod Windows nov? v?ci z development verze: Jak opatchovat (python?rsk?) soubor pod Windows? Co jsem ud?lal: 1/ st?hl jsem http://gnuwin32.sourceforge.net/packages/patch.htm 2/ nainstaloval pod amin, p?idal cestu do ..bin .. do PATH 3/ st?hl http://bugs.python.org/file12561/conv.diff a ulo?il do Lib/idlelib 4/ cmd: patch < conf.diff h?z? chybu: C:\prg\Python30\Lib\idlelib>patch < conv.diff patching file IOBinding.py Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Patchuje n?kdo tady pod Windows? D?ky -- geon Pavel Kosina From pavel.kosina at gmail.com Sat Jan 3 04:43:53 2009 From: pavel.kosina at gmail.com (geon) Date: Sat, 3 Jan 2009 01:43:53 -0800 (PST) Subject: patch References: Message-ID: sorry, pls forget :-( From geon at post.cz Sat Jan 3 04:48:51 2009 From: geon at post.cz (Pavel Kosina) Date: Sat, 03 Jan 2009 10:48:51 +0100 Subject: patch Message-ID: <495F3483.3040806@post.cz> sorry, pls forget ... -- geon Pavel Kosina From jobolosh at gmail.com Sat Jan 3 04:55:24 2009 From: jobolosh at gmail.com (John Boloshevich) Date: Sat, 3 Jan 2009 09:55:24 +0000 Subject: ACL in python Message-ID: Hello, does anybody know about an ACL implementation for python, which is not tied to the filesystem? I would like to use ACL on different objects not on files, so the POSIX file access solution is not the one I am looking for. I would like to be able to define ACOs, AROs, but it would be even nicer, if there would be AXO possibility as well. I have tried to find already, but I wasn't really successful. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From bj_666 at gmx.net Sat Jan 3 04:56:12 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 09:56:12 GMT Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> Message-ID: <6s8r1sF4op56U1@mid.uni-berlin.de> On Fri, 02 Jan 2009 09:00:01 -0800, r wrote: > On Jan 2, 6:45?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: >> > He was not cross posting. >> >> You don't actually know what cross-posting is, do you? >> >> You've just earned a plonking for the next month. Do try to have at >> least half a clue by February. > > Steven i got you NOW! > Everybody go and look at this thread, there Mr. Makinzie butts in and > posts an off-topic question, and Steven answers it, contributing to the > off-topicalitly of the thread. And has yet to apologize for it, or admit > his screwup, but will he preach to everyone else about making off topic > post... Pot meet Kettle; Kettle Pot! > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/ fc57c18c3cff5937?hl=en&q=recycle+bin#97254d877903bbd No you didn't "got" Steven, as unnecessary cross posting is something different than answering a question that should have been a new thread start. Oh, and: *plonk* for your childish annoying behaviour? Ciao, Marc 'BlackJack' Rintsch From bj_666 at gmx.net Sat Jan 3 05:15:51 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 10:15:51 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: <6s8s6nF4op56U2@mid.uni-berlin.de> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that its > assignment model is BIZARRE, as in it's conceptually different from > virtually all other languages substantially taught in undergraduate > computer science programs. What's the difference between Python and Java or C# here!? Or are they also "BIZARRE"!? > And for that matter, it's pretty unintuitive generally. Names and objects are quite "natural" IMHO. There are many real world objects which we attach one or more names to, or refer to in sequences like "please give me the third book on that shelve" (``shelve[2]``). > That is, in what I'll call "normal" computer languages, a variable name > is thought of as the address of a bin where some data is stored, and the > name is inexorably tied to that bin. You just call that "normal" or "intuitive" because that's what you learned first. > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, where > the bin is a Python object which contains specific data at the time of > assignment. A second assignment of that name doesn't change what's in > the original bin; it actually (probably) first creates a new bin, then > removes the name from the original bin and assigns it to the new one. > Intuitively, it's a bit like saying your kitchen table is no longer a > kitchen table, and now the thing where you wash your dishes is a kitchen > table. It doesn't really make a lot of sense (whether or not it's so > for good reason), and it makes describing the assignment model > necessarily convoluted, whereas the "named bins" model from the majority > of other languages people are likely to have been exposed to is simple > and sensible. I think the "bin model" is more complex because you don't just have a name and an object but always that indirection of the "bin". Ciao, Marc 'BlackJack' Rintsch From mario.ruggier at gmail.com Sat Jan 3 07:14:14 2009 From: mario.ruggier at gmail.com (mario) Date: Sat, 3 Jan 2009 04:14:14 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> Message-ID: <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> On Jan 3, 7:16?am, Steven D'Aprano wrote: > I was about to make a comment about this being a security hole, Strange that you say this, as you are also implying that *all* the widely-used templating systems for python are security holes... Well, you would be right to say that of course ;-) Infact, evoque is really one of the few (or even the only one?) that was conceived from the start to support restricted evaluation. > but I see from here > > http://evoque.gizmojo.org/usage/restricted/ > > that you are aware of at least some of the issues. > > I must say though, your choice of builtins to prohibit seems rather > arbitrary. What is dangerous about (e.g.) id() and isinstance()? Preventive, probably. I also feel that temlates should have any business with info such as the memory addressed returnred by id(). For isinstance, becuase it is somewhat related to __subclasses__ that is known to be insecure. Incidentally, I updated the page you point to clarify what is going on. I also added a link to Brett Cannon's inspiration paper on the topic of securing the python interpreter... > > ? ? except: > > ? ? ? ? # KeyError, NameError, AttributeError, SyntaxError, > > ? ? ? ? # ValueError, TypeError, IOError > > If you want to capture seven exceptions, then capture seven exceptions, > not any exception. Absolutely not. I want to catch ALL evaluation exceptions... it would actually *be* a secuity hole to allow any exception to bubble. hey will however be handled appropriately as per the application policy/ config/deployment. > You should write: > > ? ? except (KeyError, NameError, ..., IOError): > > instead of a bare except clause. That will capture exceptions that > represent bugs in your code as well as exceptions that should propbably > be allowed to propagate, such as KeyboardInterupt and SystemExit. Again, no. Template presentational logic has no business issuing SystemExits or so. And, of course, there are no bugs in my code ;-) > > ? ? ? ? # Special case if a KeyError is coming from the self.codes[name] > > ? ? ? ? # lookup (traceback should consist of a single frame only): > > ? ? ? ? if sys.exc_info()[2].tb_next is None: > > ? ? ? ? ? ? if sys.exc_info()[0] is KeyError: > > ? ? ? ? ? ? ? ? self.codes[expr] = compile(expr, '', 'eval') > > ? ? ? ? ? ? ? ? ? ? return self[expr] > That seems awfully complicated for no good reason. Yes, you are probably right. I wanted to be precise in that if the KeyError originates strictly from the codes lookup and not from the actual eval of the expr itself -- in which case the expr should be compiled and added to codes (yes, this is the "first-time failure" I referred to in the first message). I tested the performance of your 2 variations in context, and there seems to be no noticeable performance gain (something like less than 1% gain). But note the two variations as you code them do not quite do exactly the same test. I have adjusted to use this code now: def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # We want to catch **all** evaluation errors! # KeyError, NameError, AttributeError, SyntaxError, V # alueError, TypeError, IOError, ... # # Special case: # if KeyError is coming from self.codes[expr] lookup, # then we add the compiledentry and try again: if not name in self.codes: self.codes[expr] = compile(name, '', 'eval') return self[expr] # handle any other error... This retains the correctness of the check, and has the same marginal perf improvement (that is basically negligible, but at least it is not slower) and has teh advantage that the code is clearer. Thanks for the remarks! mario > -- > Steven From tino at wildenhain.de Sat Jan 3 07:18:29 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 03 Jan 2009 13:18:29 +0100 Subject: ACL in python In-Reply-To: References: Message-ID: <495F5795.2090303@wildenhain.de> John Boloshevich wrote: > Hello, > > does anybody know about an ACL implementation for python, which is not > tied to the filesystem? I would like to use ACL on different objects not > on files, so the POSIX file access solution is not the one I am looking for. You mean something like the restricted environment you find within zope for all the TTW-stuff? Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mario.ruggier at gmail.com Sat Jan 3 07:19:42 2009 From: mario.ruggier at gmail.com (mario) Date: Sat, 3 Jan 2009 04:19:42 -0800 (PST) Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: correction: the code posted in previous message should have been: def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # We want to catch **all** evaluation errors! # KeyError, NameError, AttributeError, SyntaxError, V # alueError, TypeError, IOError, ... # # Special case: # if KeyError is coming from self.codes[expr] lookup, # then we add the compiledentry and try again: if not expr in self.codes: self.codes[expr] = compile(expr, '', 'eval') return self[expr] # handle any other error... From nobody at dizum.com Sat Jan 3 08:30:02 2009 From: nobody at dizum.com (Nomen Nescio) Date: Sat, 3 Jan 2009 14:30:02 +0100 (CET) Subject: python is great Message-ID: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> python is great. From nick at craig-wood.com Sat Jan 3 08:31:12 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 03 Jan 2009 07:31:12 -0600 Subject: multiprocessing vs thread performance References: Message-ID: mk wrote: > After reading http://www.python.org/dev/peps/pep-0371/ I was under > impression that performance of multiprocessing package is similar to > that of thread / threading. However, to familiarize myself with both > packages I wrote my own test of spawning and returning 100,000 empty > threads or processes (while maintaining at most 100 processes / threads > active at any one time), respectively. > > The results I got are very different from the benchmark quoted in PEP > 371. On twin Xeon machine the threaded version executed in 5.54 secs, > while multiprocessing version took over 222 secs to complete! > > Am I doing smth wrong in code below? Yes! The problem with your code is that you never start more than one process at once in the multiprocessing example. Just check ps when it is running and you will see. My conjecture is that this is due to the way fork() works under unix. I think that when the parent forks it yields the CPU to the child. Because you are giving the child effectively no work to do it returns immediately, re-awakening the parent, thus serialising your jobs. If you give the children some work to do you'll see a quite different result. I gave each child time.sleep(1) to do and cut down the total number to 10,000. $ ./test_multiprocessing.py == Process 1000 working == == Process 2000 working == == Process 3000 working == == Process 4000 working == == Process 5000 working == == Process 6000 working == == Process 7000 working == == Process 8000 working == == Process 9000 working == == Process 10000 working == === Main thread waiting for all processes to finish === Total time: 101.382129192 $ ./test_threading.py == Thread 1000 working == == Thread 2000 working == == Thread 3000 working == == Thread 4000 working == == Thread 5000 working == == Thread 6000 working == == Thread 7000 working == == Thread 8000 working == == Thread 9000 working == == Thread 10000 working == Total time: 100.659118176 So almost identical results and as expected - we ran 10,000 sleep(1)s in 100 seconds so we must have been running 100 simultaneously. If you replace the "time.sleep(1)" with "for _ in xrange(1000000): pass" you get this much more interesting answer on my dual core linux laptop, showing nicely the effect of the contention on the python global interpreter lock and how multiprocessing avoids it. $ ./test_multiprocessing.py == Process 1000 working == == Process 2000 working == == Process 3000 working == == Process 4000 working == == Process 5000 working == == Process 6000 working == == Process 7000 working == == Process 8000 working == == Process 9000 working == == Process 10000 working == === Main thread waiting for all processes to finish === Total time: 266.808327913 $ ./test_threading.py == Thread 1000 working == == Thread 2000 working == == Thread 3000 working == == Thread 4000 working == == Thread 5000 working == == Thread 6000 working == == Thread 7000 working == == Thread 8000 working == == Thread 9000 working == == Thread 10000 working == Total time: 834.81882 -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mdw at distorted.org.uk Sat Jan 3 10:00:22 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 3 Jan 2009 15:00:22 +0000 (UTC) Subject: greenlets and how they can be used References: Message-ID: James Mills wrote: > The "greenlet" from http://codespeak.net/py/dist/greenlet.html > is a rather interesting way of handling flow of control. Ahh, yes. It's actually a rather old idea, but too rarely used. > What can "greenlet"'s be used for ? What use-cases have you guys used > them for (if any) ? I've one project in which I use coroutines (either greenlets or some coroutines I concocted out of Python's built-in threading) extensively. The system consists of a server which speaks a text-based protocol (written in C), a graphical monitor program, and a number of ancillary services which are both clients of the server, and augment it by providing additional commands. The monitor and the services are all in Python, and make extensive use of coroutines. One reason for this is that some of the server's commands can take a long time, so it's useful for the programs to be able to do other things while they wait for replies. Full-on threading would be possible, but (a) in fact I make a /lot/ of coroutines, and (b) with coroutines I don't have to think anywhere near as hard about synchronization. You can browse about here, if you like: http://git.distorted.org.uk/gitweb/~mdw/tripe?a=tree;h=python The main Python module is in py/; the services are in svc/, and the graphical monitor is in mon/. > Can they be used in place of threads with much the same effect - but > more lightweight ? More lightweight, and much easier to reason about. They also confuse other libraries less. -- [mdw] From bdesth.quelquechose at free.quelquepart.fr Sat Jan 3 10:08:54 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jan 2009 16:08:54 +0100 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: <495f8d33$0$741$426a34cc@news.free.fr> Derek Martin a ?crit : > On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: >>> Python seems rather weird, and I think from the frequency >>> with which these discussions occur on this list, clearly it *IS* >>> difficult for a neophyte Python programmer to understand the >>> assignment model. >> Took me about half an hour to grasp, not even being "CS grad" (nor >> whathever "grad" FWIW). By that time, I had a couple monthes working >> experience with VB, and had learned (but never seriously used) bits of >> C, C++, Java and Pascal. > > It took me about a half a second to grasp the "named bins" concept -- Oh yes ? With all it's implications ? Fine, you're way smarter than I'm - or, as it seems, you were much more experimented and CS-litterate that I was by that time. But that was not the point. What I meant is that a concept that takes less than an hour to grasp for a newbie self-taught programmer with no previous exposure to the concept should by no mean be a problem for a CS graduate. From bdesth.quelquechose at free.quelquepart.fr Sat Jan 3 10:19:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jan 2009 16:19:58 +0100 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> Message-ID: <495f8fcc$0$20340$426a34cc@news.free.fr> sprad a ?crit : > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), Actually, it's just plain object instanciation. > and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: > > bet = raw_input("Enter your bet") > if int(bet) == 0: > # respond to a zero bet raw_input() returns a string. If you want an int and the string is supposed to contain a legitimate string representation of an integer, then yes, passing the string to the int object constructor is the right thing to do. I'd just write it a bit diffently: bet = int(raw_input("Enter your bet")) if bet == 0: # code here or even better: def read_int(prompt, err="Sorry, '%s' is not a valid integer"): while True: answer = raw_input(prompt) try: return int(answer) except ValueError: print err % answer bet = read_int("Enter your bet") if bet == 0: # code here > Or later, I'll have an integer, and I end up doing something like > this: > > print "You still have $" + str(money) + " remaining" May suggest learning about string formatting ? print "You still have $%s remaining" % money But indeed, you obviously cannot add strings with numerics nor concatenate numerics with strings. This would make no sense. > All the time, I'm going int(this) and str(that). Am I supposed to? Depends on the context. From koranthala at gmail.com Sat Jan 3 11:39:52 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 3 Jan 2009 08:39:52 -0800 (PST) Subject: Doubt on creating threads Message-ID: I was going through Python posts and this post caught my attention http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a You have missed an important point. A well designed application does neither create so many threads nor processes. The creation of a thread or forking of a process is an expensive operation. You should use a pool of threads or processes. I am creating an application and it creates ~1-2 threads every second and kill it within 10 seconds. After reading this I am worried. Is creating a thread a very costly operation? I cannot use a pool of threads because I am using an external application (twisted) to create the threads (deferToThread). From research at johnohagan.com Sat Jan 3 12:25:17 2009 From: research at johnohagan.com (John O'Hagan) Date: Sat, 3 Jan 2009 17:25:17 +0000 Subject: why cannot assign to function call In-Reply-To: <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <200901031725.18083.research@johnohagan.com> On Tue, 30th Dec 2008, Aaron Brady wrote: >Accepting that, I'll adopt the terms John proposed, 'change' vs. >'exchange', the former when the material configuration changes, the >latter when the communication axioms change. > >b= [2, 3] >b= [3, 4] > >'b' has exchanged. (Somewhat ungrammatical.) > >b= [2, 3] >b.append( 4 ) > >'b' has changed. > >According to this, when you replace every floorboard on a porch, one >at a time, it's still the same porch-- it's changed, it's different, >and it's the same. However, if you haul off the porch and put a new >one in its place, it's not. ('porch[:]=' vs. 'porch='.) You can't >just look at the initial and final configurations of matter to >determine so. Therefore, 'id' is an informal function. This analogy describes the "ontological minefield" I was referring to in a previous post in this thread (which has expired in my mail reader, so my apologies if the threading goes awry): In what sense is a porch (or list, or string) the same if all (or even some of) its parts have been exchanged? I think the answer is something to do with the abstraction, the "container", the instance of the class. Would it be fair to say that perhaps there are no truly mutable objects, only immutable containers whose contents (also immutable objects themselves) may be exchanged? Or to pose the question another way, are objects only mutable insofar as they are composite? As you argue above, the planks are not the porch; I would add that it's your _decision_ to build (or tear down) a porch which makes it _that_ particular porch (or not). As you imply above (I think), you have to keep looking (or someone does, presumably the interpreter) to know whether an object is the same as or just equal to another (which starts to sound spookily like the role of "the observer" in phenomenology or quantum physics). Whether this means that id() is "informal" or not, I'll leave to others better informed than I. Regards, John From fakeaddress at nowhere.org Sat Jan 3 12:26:06 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 09:26:06 -0800 Subject: select.select and socket.setblocking In-Reply-To: References: Message-ID: Laszlo Nagy wrote: [...] > I have read the socket programming howto ( > http://docs.python.org/howto/sockets.html#sockets ) but it does not > explain how a blocking socket + select is different from a non blocking > socket + select. Is there any difference? There is, but it may not effect you. There are cases where a socket can select() as readable, but not be readable by the time of a following recv() or accept() call. All such cases with which I'm familiar call for a non-blocking socket. Where does this come up? Suppose that to take advantage of multi-core processors, our server runs as four processes, each with a single thread that responds to events via select(). Clients all connect to the same server port, so the socket listening on that port is shared by all four processes. A perfectly reasonable architecture (though with many more processes the simple implementation suffers the "thundering herd problem"). Two of our processors may be waiting on select() when a new connections comes in. The select() call returns in both processes, showing the socket ready for read, so both call accept() to complete the connection. The O.S. ensures that accept() [and recv()] are atomic, so one process gets the new connection; what happens in the other depends on whether we use a blocking or non-blocking socket, and clearly we want non-blocking. -- --Bryan From ashen_light at messir.net Sat Jan 3 12:31:42 2009 From: ashen_light at messir.net (Exe) Date: Sat, 03 Jan 2009 20:31:42 +0300 Subject: strange thing after call PyObject_CallMethod Message-ID: Hello everybody! I'm in trouble. This code shows that ob_refcnt increased by python if "on_recv" method throws exception. This occurs only if base C-class subclassed in python code. ====== my_old_refcnt = Py_REFCNT(self); py_result = PyObject_CallMethod(self, "on_recv", "(y#)", recvbuf, result); my_new_refcnt = Py_REFCNT(self); log_debug("refcnt before call %d", my_old_refcnt); log_debug("after call: %d\n", my_new_refcnt); ====== Output: ====== tcpconn.c: refcnt before call 1 tcpconn.c: after call: 2 ====== If PyObject_CallMethod returns success(any non-NULL value) anything okay. Tested on Python 3.1a0 (py3k:68145M, Jan 2 2009, 20:51:28). Why this happenning and who makes Py_INCREF(self)? PS garbage collector knows about this so on exit PyGC_Collect deletes instance. -- //wbr Kandalintsev Alexandre From grante at visi.com Sat Jan 3 12:38:46 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 03 Jan 2009 11:38:46 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> On 2009-01-03, Marc 'BlackJack' Rintsch wrote: > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > >> What the Python community often overlooks, when this discussion again >> rears its ugly head (as it seems to every other hour or so), is that its >> assignment model is BIZARRE, as in it's conceptually different from >> virtually all other languages substantially taught in undergraduate >> computer science programs. > > What's the difference between Python and Java or C# here!? Or scheme, or lisp, or smalltalk, or .... > Or are they also "BIZARRE"!? One presumes that Mr. Martin finds anything different from his first computer language to be BIZARRE. He should try out Prolog or something genuinely different. -- Grant From exarkun at divmod.com Sat Jan 3 12:41:35 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sat, 3 Jan 2009 12:41:35 -0500 Subject: Doubt on creating threads In-Reply-To: Message-ID: <20090103174135.20272.301262509.divmod.quotient.31149@ohm> On Sat, 3 Jan 2009 08:39:52 -0800 (PST), koranthala at gmail.com wrote: >I was going through Python posts and this post caught my attention >http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a > > > You have missed an important point. A well designed application does > neither create so many threads nor processes. The creation of a >thread > or forking of a process is an expensive operation. You should use a >pool > of threads or processes. > > >I am creating an application and it creates ~1-2 threads every second >and kill it within 10 seconds. After reading this I am worried. Is >creating a thread a very costly operation? I cannot use a pool of >threads because I am using an external application (twisted) to create >the threads (deferToThread). Actually, deferToThread is implemented in terms of a thread pool. So you're only creating a small number of threads, and then they're being re-used. I somewhat disagree with the assertion that not using a threadpool means that your application is "well designed". However, it's absolutely true that using a threadpool lowers the runtime cost of using threads compared to creating and destroying threads all the time. Jean-Paul From martin at v.loewis.de Sat Jan 3 13:00:18 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 03 Jan 2009 19:00:18 +0100 Subject: strange thing after call PyObject_CallMethod In-Reply-To: References: Message-ID: <495fa7b2$0$22840$9b622d9e@news.freenet.de> > Why this happenning and who makes Py_INCREF(self)? There are multiple possible explanations, but I think you have ruled out most of them: 1. on_recv might be returning self. So py_result would be the same as self, and hence be an additional reference. However, you said that on_recv raised an exception, so py_result should be NULL (can you confirm?) 2. there might be a reference leak in the implementation of on_recv. However, you say that it is all fine at the end, so this is unlikely 3. The implementation of on_recv stores the object inside another objects. There are too many possibilities for that to enumerate; here are some examples: def on_recv(self, buf): global foo, bar foo = self # creates global reference bar = self.on_send # creates bound method self.foo = self # creates cyclic reference foobar.append(self) # adds self into container If you are using gdb, I recommend to set a watchpoint on changes to ob_refcnt: (gdb) p &((PyObject*)self)->ob_refcnt $1 = (Py_ssize_t *) 0xa0cb5a0 (gdb) watch *(Py_ssize_t *) 0xa0cb5a0 Hardware watchpoint 2: *(ssize_t *) 168605088 (gdb) c Continuing. Hardware watchpoint 2: *(ssize_t *) 168605088 Old value = 2 New value = 1 0xb7d5f406 in list_clear (a=0xa041c74) at Objects/listobject.c:550 550 Py_XDECREF(item[i]); As you can see: this specific object was stored in a list, and the list is now being cleared. HTH, Martin From Russ.Paielli at gmail.com Sat Jan 3 13:14:14 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 3 Jan 2009 10:14:14 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> Message-ID: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> On Jan 2, 10:50?pm, Ben Finney wrote: > s0s... at gmail.com writes: > > On Jan 2, 7:20?pm, Ben Finney > > wrote: > > > They don't need to be creative; they merely need to conform with > > > the naming scheme as laid out in the PEP. > > > If it's something to be included in the standard library, I agree > > (just for consistency, not because using_underscores is better). > > > But for user code, I prefer mixedCase. > > That seems superficially like an easy distinction. Indeed, PEP 8 > explicitly is meant to apply only to code intended for inclusion in > the Python standard library. > > But consider: > > Python libraries generally don't get into the standard library until > they've had a history of widespread public use as an external library. > This helps ensure many of the harder-to-find wrinkles get discovered > through wide exposure and ironed out before becoming standard. > > Code bases, especially library interfaces, that get a lot of use > across wide communities are naturally going to have a whole lot of > other people's code directly using those interfaces. > > Interfaces that are so widely used garner a high resistance to change, > especially for something as non-functional as a naming convention. > > Choosing the naming convention for one's code is much easier to do > when its usage base is smaller than when that base is larger. > Therefore the easiest time to choose when to code in conformance to > PEP 8 is right at the start. > > The best conclusion I can come to from this? Unless you explicitly > *never* intend sharing your code with *anyone*, it's best to code all > your Python code in accordance with PEP 8 anyway. You then don't have > to make the decision about whether this is the time to follow PEP 8 or > not; just do it by default, and you avoid the needless pain on those > occasions, often unforeseeable at the start, where your code later > ends up widely used. > > -- > ?\ ? ? ? ?One of the most important things you learn from the internet | > ? `\ ? is that there is no ?them? out there. It's just an awful lot of | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??us?.? ?Douglas Adams | > Ben Finney Fair enough, but for code that is not intended for general public usage (i.e., most code) so-called camelCase is every bit as good if not better than using underscores to divide variable names. It saves a few characters, and in my opinion it's significantly easier to read. Identifiers divided by underscores always appear to me at first glance to be multiple words, and I find that very annoying. So unless you think the standard library will someday include code for air traffic management, I'll stick with camelCase, and I'll thank you for not making an issue of it. As far as I am concerned, this is one of the most important bits of advice in PEP 8: A Foolish Consistency is the Hobgoblin of Little Minds From jonas.esp at googlemail.com Sat Jan 3 13:43:01 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 10:43:01 -0800 (PST) Subject: Returning a string Message-ID: How is possible that I can print a variable, but when I use *return var* it returns an empty string http://paste.pocoo.org/show/97588/ From sajmikins at gmail.com Sat Jan 3 13:56:17 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 3 Jan 2009 10:56:17 -0800 (PST) Subject: Doubt on creating threads References: Message-ID: On Jan 3, 8:39?am, koranth... at gmail.com wrote: > I was going through Python posts and this post caught my attentionhttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > ?You have missed an important point. A well designed application does > ?neither create so many threads nor processes. The creation of a > thread > ?or forking of a process is an expensive operation. You should use a > pool > ?of threads or processes. > > > I am creating an application and it creates ~1-2 threads every second > and kill it within 10 seconds. After reading this I am worried. Is > creating a thread a very costly operation? I cannot use a pool of > threads because I am using an external application (twisted) to create > the threads (deferToThread). Generally you should only worry about this sort of thing if A) you actually notice a performance problem and B) testing indicates that it's thread creation which is causing it. Otherwise you could spend a lot of time working on something that doesn't actually affect your app's performance. ~S From deets at nospam.web.de Sat Jan 3 14:12:02 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:12:02 +0100 Subject: Returning a string In-Reply-To: References: Message-ID: <6s9rk3F4vutmU1@mid.uni-berlin.de> Kless schrieb: > How is possible that I can print a variable, but when I use *return > var* it returns an empty string > > http://paste.pocoo.org/show/97588/ I don't see anything that indicates that the returned object is the empty string. Simply because there is no code testing for that. And of course you don't show any debugging output, which doesn't help either. Diez From jonas.esp at googlemail.com Sat Jan 3 14:20:19 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:20:19 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> Message-ID: <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> On 3 ene, 19:12, "Diez B. Roggisch" wrote: > Kless schrieb: > > > How is possible that I can print a variable, but when I use *return > > var* it returns an empty string > > >http://paste.pocoo.org/show/97588/ > > I don't see anything that indicates that the returned object is the > empty string. Simply because there is no code testing for that. And of > course you don't show any debugging output, which doesn't help either. > > Diez Afghanistan AF Out[19]: u'AF' AFG Out[19]: u'AFG' 004 Out[19]: u'004' From sajmikins at gmail.com Sat Jan 3 14:40:19 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 3 Jan 2009 11:40:19 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: On Jan 3, 11:20?am, Kless wrote: > On 3 ene, 19:12, "Diez B. Roggisch" wrote: > > > Kless schrieb: > > > > How is possible that I can print a variable, but when I use *return > > > var* it returns an empty string > > > >http://paste.pocoo.org/show/97588/ > > > I don't see anything that indicates that the returned object is the > > empty string. Simply because there is no code testing for that. And of > > course you don't show any debugging output, which doesn't help either. > > > Diez > > Afghanistan > AF > Out[19]: u'AF' > AFG > Out[19]: u'AFG' > 004 > Out[19]: u'004' What? From jonas.esp at googlemail.com Sat Jan 3 14:46:10 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:46:10 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> On 3 ene, 19:40, Simon Forman wrote: > On Jan 3, 11:20?am, Kless wrote: > > > Afghanistan > > AF > > Out[19]: u'AF' > > AFG > > Out[19]: u'AFG' > > 004 > > Out[19]: u'004' > > What? That's the output got from ipython. As you can see, it prints 'Afghanistan' but it can not returns it. In change, the another strings are returned. Could it be because it isn't returning the value from the recursivecall? From deets at nospam.web.de Sat Jan 3 14:49:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:49:36 +0100 Subject: Returning a string In-Reply-To: <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> Message-ID: <6s9tqhF4vtr6U1@mid.uni-berlin.de> Kless schrieb: > On 3 ene, 19:12, "Diez B. Roggisch" wrote: >> Kless schrieb: >> >>> How is possible that I can print a variable, but when I use *return >>> var* it returns an empty string >>> http://paste.pocoo.org/show/97588/ >> I don't see anything that indicates that the returned object is the >> empty string. Simply because there is no code testing for that. And of >> course you don't show any debugging output, which doesn't help either. >> >> Diez > > Afghanistan > AF > Out[19]: u'AF' > AFG > Out[19]: u'AFG' > 004 > Out[19]: u'004' What is that? IPython? And I don't see no empty string here. *What* I see is the way python's interactive prompt puts out strings, like this: >>> unicode("foo") u'foo' Do you mean by any chance that you don't understand why print prints foo, but the prompt shows u"foo"? That is because the prompt invokes repr(o) to print out an object: >>> print repr(unicode("foo")) u'foo' Which means that the output includes quotes and the "u"-prefix in case of an unicode object to help the user to see what the current object looks like. Diez From deets at nospam.web.de Sat Jan 3 14:51:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 20:51:16 +0100 Subject: Returning a string In-Reply-To: <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> Message-ID: <6s9ttkF4vtr6U2@mid.uni-berlin.de> Kless schrieb: > On 3 ene, 19:40, Simon Forman wrote: >> On Jan 3, 11:20 am, Kless wrote: >> >>> Afghanistan >>> AF >>> Out[19]: u'AF' >>> AFG >>> Out[19]: u'AFG' >>> 004 >>> Out[19]: u'004' >> What? > > That's the output got from ipython. As you can see, it prints > 'Afghanistan' but it can not returns it. In change, the another > strings are returned. > > Could it be because it isn't returning the value from the > recursivecall? Yep, I guess that's the problem. You need to do if cell_tag: return clean_tags(cell_tag) Diez From bj_666 at gmx.net Sat Jan 3 14:51:22 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 3 Jan 2009 19:51:22 GMT Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> Message-ID: <6s9ttqF4op56U3@mid.uni-berlin.de> On Sat, 03 Jan 2009 11:46:10 -0800, Kless wrote: > On 3 ene, 19:40, Simon Forman wrote: >> On Jan 3, 11:20?am, Kless wrote: >> >> > Afghanistan >> > AF >> > Out[19]: u'AF' >> > AFG >> > Out[19]: u'AFG' >> > 004 >> > Out[19]: u'004' >> >> What? > > That's the output got from ipython. As you can see, it prints > 'Afghanistan' but it can not returns it. In change, the another strings > are returned. Maybe you should show the *input* too? Ciao, Marc 'BlackJack' Rintsch From jonas.esp at googlemail.com Sat Jan 3 14:57:30 2009 From: jonas.esp at googlemail.com (Kless) Date: Sat, 3 Jan 2009 11:57:30 -0800 (PST) Subject: Returning a string References: <6s9rk3F4vutmU1@mid.uni-berlin.de> <0bc1adc2-be33-412f-8eb0-2c82beb3ed50@f40g2000pri.googlegroups.com> <65caf634-1466-47e9-8df7-0b2271bf528b@s1g2000prg.googlegroups.com> <6s9ttkF4vtr6U2@mid.uni-berlin.de> Message-ID: <97e5048e-29ba-41f9-80c0-479a6c8f2b39@r15g2000prh.googlegroups.com> On 3 ene, 19:51, "Diez B. Roggisch" wrote: > Kless schrieb: > > > > > On 3 ene, 19:40, Simon Forman wrote: > >> On Jan 3, 11:20 am, Kless wrote: > > >>> Afghanistan > >>> AF > >>> Out[19]: u'AF' > >>> AFG > >>> Out[19]: u'AFG' > >>> 004 > >>> Out[19]: u'004' > >> What? > > > That's the output got from ipython. As you can see, it prints > > 'Afghanistan' but it can not returns it. In change, the another > > strings are returned. > > > Could it be because it isn't returning the value from the > > recursivecall? > > Yep, I guess that's the problem. You need to do > > if cell_tag: > ? ? return clean_tags(cell_tag) > > Diez Thank you very much. It works now. From imageguy1206 at gmail.com Sat Jan 3 15:10:15 2009 From: imageguy1206 at gmail.com (imageguy) Date: Sat, 3 Jan 2009 12:10:15 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> Message-ID: <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> On Jan 2, 7:33?pm, John Machin wrote: > For some very strange definition of "works". You say you have 'bgr' > and want to convert it to 'rbg'. The following code converts 'bgr' to > 'rgb', which is somewhat more plausible, but not what you said you > wanted. Well that's embarrassing ... you are correct. I need to convert from 'bgr' to 'rgb' Thanks to all others for suggestions FWIW, I realized the the C.types string buffer is/was mutable so settled on this; for start in xrange(0, ctypes.sizeof(buffer), 3): if buffer[start] != buffer[start+2]: #only need to swap the bits if they are different. ie if both are white or black, no change is required. blue, red = buffer[start], buffer[start+2] buffer[start], buffer[start+2] = red, blue This was about 30-40% faster that converting to list, processing and then converting back again. Will try the array module too ... but I think I need to find a new graphic package rather that makes working with the bits easier. g. From aleksandr.goretoy at gmail.com Sat Jan 3 15:35:25 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 3 Jan 2009 20:35:25 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: for each his own. Any more word on userio? On Sat, Jan 3, 2009 at 6:14 PM, Russ P. wrote: > On Jan 2, 10:50 pm, Ben Finney > > > wrote: > > s0s... at gmail.com writes: > > > On Jan 2, 7:20 pm, Ben Finney > > > > > wrote: > > > > They don't need to be creative; they merely need to conform with > > > > the naming scheme as laid out in the PEP. > > > > > If it's something to be included in the standard library, I agree > > > (just for consistency, not because using_underscores is better). > > > > > But for user code, I prefer mixedCase. > > > > That seems superficially like an easy distinction. Indeed, PEP 8 > > explicitly is meant to apply only to code intended for inclusion in > > the Python standard library. > > > > But consider: > > > > Python libraries generally don't get into the standard library until > > they've had a history of widespread public use as an external library. > > This helps ensure many of the harder-to-find wrinkles get discovered > > through wide exposure and ironed out before becoming standard. > > > > Code bases, especially library interfaces, that get a lot of use > > across wide communities are naturally going to have a whole lot of > > other people's code directly using those interfaces. > > > > Interfaces that are so widely used garner a high resistance to change, > > especially for something as non-functional as a naming convention. > > > > Choosing the naming convention for one's code is much easier to do > > when its usage base is smaller than when that base is larger. > > Therefore the easiest time to choose when to code in conformance to > > PEP 8 is right at the start. > > > > The best conclusion I can come to from this? Unless you explicitly > > *never* intend sharing your code with *anyone*, it's best to code all > > your Python code in accordance with PEP 8 anyway. You then don't have > > to make the decision about whether this is the time to follow PEP 8 or > > not; just do it by default, and you avoid the needless pain on those > > occasions, often unforeseeable at the start, where your code later > > ends up widely used. > > > > -- > > \ "One of the most important things you learn from the internet | > > `\ is that there is no 'them' out there. It's just an awful lot of | > > _o__) 'us'." ?Douglas Adams | > > Ben Finney > > Fair enough, but for code that is not intended for general public > usage (i.e., most code) so-called camelCase is every bit as good if > not better than using underscores to divide variable names. It saves a > few characters, and in my opinion it's significantly easier to read. > Identifiers divided by underscores always appear to me at first glance > to be multiple words, and I find that very annoying. > > So unless you think the standard library will someday include code for > air traffic management, I'll stick with camelCase, and I'll thank you > for not making an issue of it. > > As far as I am concerned, this is one of the most important bits of > advice in PEP 8: > > A Foolish Consistency is the Hobgoblin of Little Minds > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lipun4u at gmail.com Sat Jan 3 15:38:38 2009 From: lipun4u at gmail.com (asit) Date: Sat, 3 Jan 2009 12:38:38 -0800 (PST) Subject: ResponseNotReady exception Message-ID: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> import httplib class Server: #server class def __init__(self, host): self.host = host def fetch(self, path): http = httplib.HTTPConnection(self.host) http.putrequest("GET", path) r = http.getresponse() print str(r.status) + " : " + r.reason server = Server("www.python.org") fp=open("phpvuln.txt") x=fp.readlines(); for y in x: server.fetch("/" + y); In the above code the phpvuln.txt file contains a list of directories. Why the above code throws ResponseNotReady exception ??? From bug_hunter at messir.net Sat Jan 3 15:43:38 2009 From: bug_hunter at messir.net (Bug Hunter) Date: Sat, 03 Jan 2009 23:43:38 +0300 Subject: strange thing after call PyObject_CallMethod In-Reply-To: <495fa7b2$0$22840$9b622d9e@news.freenet.de> References: <495fa7b2$0$22840$9b622d9e@news.freenet.de> Message-ID: Thank you for so amazing debugging tutorial :). I owe you a beer. I found source of problem: then unhandled in python code exception occurs frame_dealloc() (Objects/frameobject.c:422) not called. Even if I call PyErr_Print(). But! If I call PyErr_Clear() then all okay! Docs says that both this functions clears error indicator... I hit a bug or my brains overheated? Some gdb output if you are intrested: Without exception: http://dpaste.com/104973/ With exception: http://dpaste.com/104975/ From saju.pillai at gmail.com Sat Jan 3 15:44:09 2009 From: saju.pillai at gmail.com (Saju Pillai) Date: Sat, 3 Jan 2009 20:44:09 +0000 (UTC) Subject: select.select and socket.setblocking References: Message-ID: Bryan Olson wrote: > >Where does this come up? Suppose that to take advantage of multi-core >processors, our server runs as four processes, each with a single thread >that responds to events via select(). Clients all connect to the same >server port, so the socket listening on that port is shared by all four >processes. A perfectly reasonable architecture (though with many more >processes the simple implementation suffers the "thundering herd problem"). Which is why it is common for real world servers to serialize the select()/accept() code - usually via a file lock or a semaphore. -srp -- http://saju.net.in > >Two of our processors may be waiting on select() when a new connections >comes in. The select() call returns in both processes, showing the >socket ready for read, so both call accept() to complete the connection. > The O.S. ensures that accept() [and recv()] are atomic, so one process >gets the new connection; what happens in the other depends on whether we >use a blocking or non-blocking socket, and clearly we want non-blocking. > > >-- >--Bryan From vminch at gmail.com Sat Jan 3 15:48:38 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 12:48:38 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <5827781d-a583-499b-840e-a5face83328e@q26g2000prq.googlegroups.com> > Any more word on userio? None yet, I'm afraid. Should've started a different thread for it - but it's stuck here (in obscurity) forever xd. From enleverlesX.XmcX at XmclaveauX.com Sat Jan 3 15:50:30 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sat, 3 Jan 2009 21:50:30 +0100 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <495fd1f5$0$18383$ba4acef3@news.orange.fr> > python is great. No. Python is VERY GREAT !!!!!!! From vminch at gmail.com Sat Jan 3 15:54:41 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 12:54:41 -0800 (PST) Subject: ResponseNotReady exception References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <0f833b10-643f-4ae2-95de-9fd76aa8f270@d36g2000prf.googlegroups.com> http://www.python.org/phpvuln.txt Error 404: File Not Found The URL you requested was not found on this server. From clp at rebertia.com Sat Jan 3 15:59:37 2009 From: clp at rebertia.com (Chris Rebert) Date: Sat, 3 Jan 2009 12:59:37 -0800 Subject: ResponseNotReady exception In-Reply-To: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <47c890dc0901031259u8a6c029ie848f23795a18216@mail.gmail.com> On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > import httplib > > class Server: > #server class > def __init__(self, host): > self.host = host > def fetch(self, path): > http = httplib.HTTPConnection(self.host) > http.putrequest("GET", path) According to the docs, if you use .putrequest(), you have to also then call .putheader() [as many times as necessary], .endheaders(), and .send(), in that order. I'd advise just changing .putrequest() to .request() instead. And you should also read the fine docs yourself: http://docs.python.org/library/httplib.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From vminch at gmail.com Sat Jan 3 16:03:33 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 13:03:33 -0800 (PST) Subject: Port of python stdlib to other languages. Message-ID: Have there been ports of the Python standard library to other languages? I would imagine using pickle, urllib, and sys in C (with pythonic naming conventions) would be easier than using other libraries to do the same thing. From deets at nospam.web.de Sat Jan 3 16:08:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 03 Jan 2009 22:08:15 +0100 Subject: Port of python stdlib to other languages. In-Reply-To: References: Message-ID: <6sa2dvF4uc5uU1@mid.uni-berlin.de> vk schrieb: > Have there been ports of the Python standard library to other > languages? > > I would imagine using pickle, urllib, and sys in C (with pythonic > naming conventions) would be easier than using other libraries to do > the same thing. AFAIK not. You could try elmer (found on SF) to expose these as C-DLL. However, I doubt this will be widely adopted - to much hassle, especially for OO-style interfaces. Those aren't properly exposable. What do you need C for anyway? Or, to put it the other way round - why not expose whatever you need in C as python extension, and write your app in Python? Diez From goldnery at gmail.com Sat Jan 3 16:10:47 2009 From: goldnery at gmail.com (Gandalf) Date: Sat, 3 Jan 2009 13:10:47 -0800 (PST) Subject: win32gui Message-ID: <8bf17a89-11bc-4c89-8ebc-db46fccefaa2@o4g2000pra.googlegroups.com> Hi, I'm trying to capture the text word under the user cursor, so I was searching the win32 lib for functions I can use. i used this to fined the controller under the cursor win32gui.WindowFromPoint(win32gui.GetCursorPos()) to get the controller, but then when I try to read the text with this GetWindowText function it most of the time doesn't work, all the "getline" methon like the following didn't worked in most of the time too win32gui.SendMessage(hwnd, win32con.EM_GETLINE, line, linetext) I found this GetCharFromPosition in a VB forum which sound promising but unfortunately it's not part of the win32gui for python so now i'm looking for a reliable way to rich text from a controller or position if you know a function who may do it or a better way please tell me/ thank you and have a nice day From lipun4u at gmail.com Sat Jan 3 16:14:45 2009 From: lipun4u at gmail.com (asit) Date: Sat, 3 Jan 2009 13:14:45 -0800 (PST) Subject: ResponseNotReady exception References: <354b5298-b41d-4f47-89e0-ef58391ca2d3@i18g2000prf.googlegroups.com> Message-ID: <764fc7a9-fa2f-44e0-ab97-73c13d94f7a7@40g2000prx.googlegroups.com> On Jan 4, 1:59?am, "Chris Rebert" wrote: > On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > > import httplib > > > class Server: > > ? ?#server class > > ? ?def __init__(self, host): > > ? ? ? ?self.host = host > > ? ?def fetch(self, path): > > ? ? ? ?http = httplib.HTTPConnection(self.host) > > ? ? ? ?http.putrequest("GET", path) > > According to the docs, if you use .putrequest(), you have to also then > call .putheader() [as many times as necessary], .endheaders(), and > .send(), in that order. I'd advise just changing .putrequest() to > .request() instead. > > And you should also read the fine docs yourself:http://docs.python.org/library/httplib.html > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanx From lkcl at lkcl.net Sat Jan 3 16:22:33 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sat, 3 Jan 2009 21:22:33 +0000 Subject: compiling python2.5 on linux under wine Message-ID: hey, has anyone investigated compiling python2.5 using winegcc, under wine? i'm presently working my way through it, just for kicks, and was wondering if anyone would like to pitch in or stare at the mess under a microscope. it's not as crazed as it sounds. cross-compiling python2.5 for win32 with mingw32 is an absolute miserable bitch of a job that goes horribly wrong when you actually try to use the minimalist compiler to do any real work. so i figured that it would be easier to get python compiled using wine. i _have_ got some success - a python script and a python.exe.so (which is winegcc's friendly way of telling you you have something that stands a chance of working) as well as a libpython25.dll.so. what i _don't_ yet have is an _md5.dll (or should it be _md5.lib?) i.e. the standard modules are a bit... iffy. the _winreg.o is compiled; the _md5.o is compiled; the winreg.lib is not. whoops. plus, it's necessary to enable nt_dl.c which is in PC/ _not_ in Modules/. one of the key issues that's a bit of a bitch is that python is compiled up for win32 with a hard-coded pyconfig.h which someone went to a _lot_ of trouble to create by hand instead of using autoconf. oh - and it uses visualstudio so there's not even a Makefile. ignoring that for the time-being was what allowed me to get as far as actually having a python interpreter (with no c-based modules). so there's a whole _stack_ of stuff that needs dragging kicking and screaming into the 21st century. there _is_ a reason why i want to do this. actually, there's two. firstly, i sure as shit do _not_ want to buy, download, install _or_ run visual studio. i flat-out refuse to run an MS os and visual studio runs like a dog under wine. secondly, i want a python25.lib which i can use to cross-compile modules for poor windows users _despite_ sticking to my principles and keeping my integrity as a free software developer. thirdly i'd like to cross-compile pywebkitgtk for win32 fourthly i'd like to compile and link applications to the extremely successful and well wicked MSHTML.DLL... in the _wine_ project :) not the one in windows (!) i want to experiment with DOM model manipulation - from python - similar to the OLPC HulaHop project - _but_ i want to compile or cross-compile everything from linux, not windows (see 1 above) fifthly i'd like to see COM (DCOM) working and pywin32 compiled and useable under wine, even if it means having to get a license to use dcom98 and oleauth.lib and oleauth.h etc. and all the developer files needed to link DCOM applications under windows. actually what i'd _really_ like to see is FreeDCE's DCOM work actually damn well finished, it's only been eight years since wez committed the first versions of the IDL and header files, and it's only been over fifteen years since microsoft began its world domination using COM and DCOM. ... but that's another story :) so that's ... five reasons not two. if anyone would like to collaborate on a crazed project with someone who can't count, i'm happy to make available what i've got up to so far, on github.org. l. From roy at panix.com Sat Jan 3 16:25:59 2009 From: roy at panix.com (Roy Smith) Date: Sat, 03 Jan 2009 16:25:59 -0500 Subject: select.select and socket.setblocking References: Message-ID: Bryan Olson wrote: > There are cases where a socket can select() as readable, but not be > readable by the time of a following recv() or accept() call. All such > cases with which I'm familiar call for a non-blocking socket. I used to believe that if select() said data was ready for reading, a subsequent read/recv/recvfrom() call could not block. It could return an error, but it could not block. I was confident of this until just a few months ago when reality blew up in my face. The specific incident involved a bug in the linux kernel. If you received an UDP packet with a checksum error, the select() would return when the packet arrived, *before* the checksum was checked. By the time you did the recv(), the packet had been discarded and the recv() would block. This led me on a big research quest (including some close readings of Stevens, which appeared to say that this couldn't happen). The more I read, the more I (re) discovered just how vague and poorly written the Berkeley Socket API docs are :-) The bottom line is that Bryan is correct -- regardless of what the various man pages and textbooks say, in the real world, it is possible for a read() to block after select() says the descriptor is ready. The right way to think about select() is to treat it as a heuristic which can make a polling loop more efficient, but should never be relied upon to predict the future. Neither the negative nor positive behavior is guaranteed. There's no guaranteed response time; just because select() hasn't returned yet doesn't mean a descriptor couldn't be read without blocking in another thread right now. And, just because it has returned, that doesn't mean by the time you get around to reading, there will still be anything there. From dickinsm at gmail.com Sat Jan 3 16:27:06 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 3 Jan 2009 13:27:06 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> Message-ID: <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> On Dec 31 2008, 11:02?pm, Steven D'Aprano wrote: > On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: > > On Dec 28, 7:28?am, Steven D'Aprano > cybersource.com.au> wrote: > >> Ah crap, I forgot that from_float() has been left out of the decimal > >> API. That's very annoying. > > > Agreed. ?It's maybe even annoying enough that a feature request at > > bugs.python.org might be honoured. ?(Hint, hint!) > > I can take a hint :) > > http://bugs.python.org/issue4796# Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 and Python 3.1, within 72 hours of Steven submitting the feature request. If only all issues could be resolved this quickly. :-) Mark From dickinsm at gmail.com Sat Jan 3 16:34:11 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 3 Jan 2009 13:34:11 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> Message-ID: <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> On Jan 3, 9:27?pm, Mark Dickinson wrote: > Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > and Python 3.1, within 72 hours of Steven submitting the feature > request. ?If only all issues could be resolved this quickly. :-) Rats. I left out the crucial line of that post, namely: Thank you, Steven! From sjmachin at lexicon.net Sat Jan 3 17:08:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 3 Jan 2009 14:08:21 -0800 (PST) Subject: Reverse order of bit in repeating seqence of byte string References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> Message-ID: On Jan 4, 7:10?am, imageguy wrote: > On Jan 2, 7:33?pm, John Machin wrote: > > > For some very strange definition of "works". You say you have 'bgr' > > and want to convert it to 'rbg'. The following code converts 'bgr' to > > 'rgb', which is somewhat more plausible, but not what you said you > > wanted. > > Well that's embarrassing ... you are correct. ?I need to convert from > 'bgr' to 'rgb' > > Thanks to all others for suggestions > > FWIW, I realized the the C.types string buffer is/was mutable so > settled on this; > > for start in xrange(0, ctypes.sizeof(buffer), 3): > ? ? if buffer[start] != buffer[start+2]: > ? ? ? ? ?#only need to swap the bits if they are different. ?ie if > both are white or black, no change is required. > ? ? ? ? ?blue, red = buffer[start], buffer[start+2] > ? ? ? ? ?buffer[start], buffer[start+2] = red, blue You are likely find that using buffer[start], buffer[start+2] = buffer[start+2], buffer[start] is faster. Cheers, John From gruszczy at gmail.com Sat Jan 3 17:21:03 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sat, 3 Jan 2009 23:21:03 +0100 Subject: deleting a method Message-ID: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> I am trying to delete a method from a class. It's easy to delete other attributes, but when I try: >>> class A: ... def foo(): ... pass ... >>> a = A() >>> del a.foo I get Traceback (most recent call last): File "", line 1, in AttributeError: A instance has no attribute 'foo' Why is it so and how may still delete it? -- Filip Gruszczy?ski From google at mrabarnett.plus.com Sat Jan 3 17:36:47 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jan 2009 22:36:47 +0000 Subject: deleting a method In-Reply-To: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <495FE87F.6050905@mrabarnett.plus.com> Filip Gruszczy?ski wrote: > I am trying to delete a method from a class. It's easy to delete other > attributes, but when I try: > >>>> class A: > ... def foo(): > ... pass > ... >>>> a = A() >>>> del a.foo > > I get > > Traceback (most recent call last): > File "", line 1, in > AttributeError: A instance has no attribute 'foo' > > Why is it so and how may still delete it? > 'a' is an instance of class A. You're trying to delete 'foo' from the instance. From bignose+hates-spam at benfinney.id.au Sat Jan 3 17:41:45 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 04 Jan 2009 09:41:45 +1100 Subject: deleting a method References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <87zli8j9li.fsf@benfinney.id.au> MRAB writes: > Filip Gruszczy?ski wrote: > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: A instance has no attribute 'foo' > > > > Why is it so and how may still delete it? > > > 'a' is an instance of class A. You're trying to delete 'foo' from > the instance. To answer the second question: since ?foo? is an attribute of the class ?A?, you can delete the attribute from the class. >>> class A(object): ... def foo(self): ... pass ... >>> a = A() >>> 'foo' in dir(a) True >>> del A.foo >>> 'foo' in dir(a) False -- \ ?If you don't know what your program is supposed to do, you'd | `\ better not start writing it.? ?Edsger W. Dijkstra | _o__) | Ben Finney From fakeaddress at nowhere.org Sat Jan 3 17:53:12 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 14:53:12 -0800 Subject: Testing if an index is in a slice In-Reply-To: References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: ajaksu wrote: > On Jan 1, 4:12 pm, mma... at gmx.net wrote: >> I would like to check if an index is in a slice or not without >> iterating over the slice. >> >> Something like: >> >>>>> isinslice(36, slice(None, 34, -1)) >> True > > I think it'd be feasible for slices that can be mapped to ranges[1], > but slices are more flexible than that. If we add a parameter for the length of the list to which the slice is applied, then inslice() is well-defined. I thought it would easy to write, but that was hours ago when I knew less about Python slice indexing than I do now. And I thought I new a bunch from writing a virtual slice class. I'm leaning towards mmanns' idea that this should be built in. Handling all the cases is remarkably tricky. Here's a verbose version, with a little test: def inslice(i, slc, length): """ Would index i be part of slice slc of a list of len length? """ step = slc.step or 1 if step > 0: if slc.start is None: start = 0 elif slc.start >= 0: start = slc.start else: start = max(0, length + slc.start) if slc.stop is None: stop = length elif slc.stop >= 0: stop = min(length, slc.stop) else: stop = length + slc.stop return start <= i < stop and (i - start) % step == 0 else: if slc.start is None: start = length - 1 elif slc.start >= 0: start = min(length - 1, slc.start) else: start = length + slc.start if slc.stop is None: stop = -1 elif slc.stop >= 0: stop = slc.stop else: stop = max(-1, length + slc.stop) return start >= i > stop and (start - i) % (-step) == 0 # test for start in [None, 0, 1, -1, -3, 4]: for stop in [None, 0, 1, -1, 3, -5]: for step in [None, 1, -1, 2, -3]: for n in [0, 1, 2, 3, 5, 11, 16]: slc = slice(start, stop, step) s1 = [i for i in range(-3, n + 5) if inslice(i, slc, n)] s2 = sorted(range(n)[slc]) assert s1 == s2 -- --Bryan From castironpi at gmail.com Sat Jan 3 18:42:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 3 Jan 2009 15:42:47 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> Message-ID: <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> On Jan 3, 11:25?am, John O'Hagan wrote: > On Tue, 30th Dec 2008, Aaron Brady wrote: > >Accepting that, I'll adopt the terms John proposed, 'change' vs. > >'exchange', the former when the material configuration changes, the > >latter when the communication axioms change. > > >b= [2, 3] > >b= [3, 4] > > >'b' has exchanged. ?(Somewhat ungrammatical.) > > >b= [2, 3] > >b.append( 4 ) > > >'b' has changed. > > >According to this, when you replace every floorboard on a porch, one > >at a time, it's still the same porch-- it's changed, it's different, > >and it's the same. ?However, if you haul off the porch and put a new > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > >just look at the initial and final configurations of matter to > >determine so. ?Therefore, 'id' is an informal function. > > This analogy describes the "ontological minefield" I was referring to in a > previous post in this thread (which has expired in my mail reader, so my > apologies if the threading goes awry): In what sense is a porch (or list, or > string) the same if all (or even some of) its parts have been exchanged? > > I think the answer is something to do with the abstraction, the "container", > the instance of the class. Would it be fair to say that perhaps there are no > truly mutable objects, only immutable containers whose contents (also > immutable objects themselves) may be exchanged? Or to pose the question > another way, are objects only mutable insofar as they are composite? > > As you argue above, the planks are not the porch; I would add that it's your > _decision_ to build (or tear down) a porch which makes it _that_ ?particular > porch (or not). > > As you imply above (I think), you have to keep looking (or someone does, > presumably the interpreter) to know whether an object is the same as or just > equal to another (which starts to sound spookily like the role of "the > observer" in phenomenology or quantum physics). Whether this means that id() > is "informal" or not, I'll leave to others better informed than I. > > Regards, > > John I think the key ingredient is that there's no such thing as side effect in math. In example, a= [0, 1, 2] a[:]= [3, 4, 5] There aren't many natural language senses in which 'a' is the same object as before. If I have a leg transplant, I'm the same person, but if you replace the entire contents of me, I'm not. But 'a' is. The porch is defined by its location, but not exclusively. Natural language identity is a cluster concept, without strict necessary and sufficient conditions. Nothing really presses our boundaries of it that much; there aren't many practical questions that lay out the facts, then ask, 'But is it the same?' You can replace the porch board-at-a-time, and it is; and you can haul it somewhere and it is. But rearrange the same boards, and it's not. Continuity of form is probably the prevalent feature, which as you state, does break down in the case of composite (piece-wise) transformations. You might get farther comparing container objects to spots on a bulletin board. The only thing that goes 'in' a container is a denoting phrase to another object (and by the way, not a description); the other also has its own spot independently on the board. It's not clear IMO that the question is so much a minefield-- a question that it's really easy to get throw (fall) off course pursuing, as it is that there's no such course. In short, there is no such thing as composite identity, only matter; or in Python, only spots on the bulletin board. > Or to pose the question > another way, are objects only mutable insofar as they are composite? No; tuples are composite. If I flip one bit in a byte somewhere, is it the same byte? From fakeaddress at nowhere.org Sat Jan 3 18:44:34 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 15:44:34 -0800 Subject: socket send help In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > greywine at gmail.com escribi?: [...] >> A simple server: >> >> from socket import * >> myHost = '' > > Try with myHost = '127.0.0.1' instead - a firewall might be blocking > your server. Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty string is that a firewall might *not* be blocking your server. The Python sockets module interprets the empty string as INADDR_ANY, which means to bind to all available adapters including the loopback, A.K.A localhost, A.K.A '127.0.0.1'. -- --Bryan From fakeaddress at nowhere.org Sat Jan 3 18:59:02 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Jan 2009 15:59:02 -0800 Subject: Doubt on creating threads In-Reply-To: References: Message-ID: koranthala at gmail.com wrote: > I am creating an application and it creates ~1-2 threads every second > and kill it within 10 seconds. After reading this I am worried. Is > creating a thread a very costly operation? Compared to a procedure call it's expensive, but a couple threads per second is insignificant. My out-dated Pentium 4 desktop can create and destroy a few thousand threads per second under WinXP; more under recent Linux. -- --Bryan From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:27:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:27:30 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <01700766$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 20:35:25 +0000, alex goretoy wrote: > for each his own. Please don't top-post. Please don't quote the ENTIRE body of text (PLUS doubling it by including a completely useless HTML version) just to add a trivial comment. Trim the text you are replying to. > Any more word on userio? I doubt many people care about it. Why don't you write it, put it up on the Cheeseshop, and see if anyone uses it? Just because you think it is useful doesn't mean others do, but if they do, then great. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:30:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:30:18 GMT Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> Message-ID: <0170080e$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: > On Jan 3, 9:27?pm, Mark Dickinson wrote: >> Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 >> and Python 3.1, within 72 hours of Steven submitting the feature >> request. ?If only all issues could be resolved this quickly. :-) > > Rats. I left out the crucial line of that post, namely: > > Thank you, Steven! And many thanks to both you and Raymond, firstly for doing the actual work, and secondly for your patience with my questions on the bug tracker. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 20:41:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 01:41:37 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> Message-ID: <01700ab5$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 16:19:58 +0100, Bruno Desthuilliers wrote: > But indeed, you obviously cannot add strings with numerics nor > concatenate numerics with strings. This would make no sense. The OP comes from a Perl background, which AFAIK allows you to concat numbers to strings and add strings to numbers. That's probably the (mis) feature he was hoping Python had. -- Steven From workingpad at gmail.com Sat Jan 3 21:09:26 2009 From: workingpad at gmail.com (Jack.Chu) Date: Sat, 3 Jan 2009 18:09:26 -0800 (PST) Subject: Why not Ruby? References: <0640abb6-ab69-4709-a46c-b0ee8c9f0c09@n21g2000vba.googlegroups.com> Message-ID: <6af2263b-b31b-4e64-a283-b9c6e1fcf24f@p2g2000prf.googlegroups.com> On Jan 1, 3:55?am, Roger wrote: > On Dec 31, 12:55?pm, Xah Lee wrote: > > > Just spent 3 hours looking into Ruby today. Here's my short impression > > for those interested. > > Who are you? > > In case no one tells you, you are a cocky, egotistical windbag with > opinions that border constructive but never gets there. ?Why would > anyone care what you think? ?Again, who are you? ?Xah Lee? ?And? ?I > didn't subscribe to read reviews on Ruby. ?And I'm pretty sure anyone > that bothers to subscribe to a group about programming has the > wherewithal to research a language themselves and come to their own > determiniation. > > Also, this is a Python group and not Ruby. ?I knew I should have > avoided this post and read the one about Nike Shoes from China. ?At > least those bits of trolling spam don't try to mask themselves as > something worthwhile. agree with you. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 3 21:11:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 02:11:56 GMT Subject: Ideas to optimize this getitem/eval call? References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: <017011ce$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 04:14:14 -0800, mario wrote: > On Jan 3, 7:16?am, Steven D'Aprano cybersource.com.au> wrote: [...] >> I must say though, your choice of builtins to prohibit seems rather >> arbitrary. What is dangerous about (e.g.) id() and isinstance()? > > Preventive, probably. I also feel that temlates should have any business > with info such as the memory addressed returnred by id(). For > isinstance, becuase it is somewhat related to __subclasses__ that is > known to be insecure. It's that "probably" that worries me. In my earlier post, I was going to say "your choice of builtins to prohibit seems rather Cargo Cult-ish", but I decided that might be a bit rude, and I decided to give you the benefit of the doubt. But your answer here doesn't really give me any more confidence. What security issues do you think you are preventing by prohibiting id()? It is true that the id returned is a memory address in CPython, but that's a mere implementation detail, and may not be true in other implementations. Even if it is a memory address, so what? You can't do anything with it except treat it as an integer. I don't see how id() decreases security one iota. In the absence of even a theoretical threat, banning a function that returns an int because the int is derived from a memory address (but can't be used as one!) makes you appear to be engaging in Cargo Cult programming: following the ritual, without any understanding of what you are doing. http://catb.org/~esr/jargon/html/C/cargo-cult-programming.html Sorry to be so harsh, especially over such a tiny little thing as the id() function, but that's the impression it gives me, and I'm probably not the only one. It is true that a false positive (needlessly banning a harmless function) has less serious consequences than a false negative (failing to ban a harmful function), but it does reduce confidence that you know what you're doing. Likewise for isinstance() and issubclass(). They may be related to __subclasses__, but they don't give the caller access to __subclassess__. So what is the actual threat you are defending against? I'm not saying that there must be an actual in-the-wild demonstrated vulnerability before you prohibit a built-in, but there should be at least a plausible attack vector. > Incidentally, I updated the page you point to clarify what is going on. Speaking of that page, you have an obvious typo ("teh" instead of "the") that should be fixed: "In addition to teh above, all subclasses of BaseException..." http://evoque.gizmojo.org/usage/restricted/ > I also added a link to Brett Cannon's inspiration paper on the topic of > securing the python interpreter... > >> > ? ? except: >> > ? ? ? ? # KeyError, NameError, AttributeError, SyntaxError, # >> > ? ? ? ? ValueError, TypeError, IOError >> >> If you want to capture seven exceptions, then capture seven exceptions, >> not any exception. > > Absolutely not. I want to catch ALL evaluation exceptions... I see. It wasn't clear that this was deliberate, I read it as if there was a fixed, finite list you wanted to catch, and nothing else. You should make sure this is clearly documented in your code. -- Steven. From eric.kemp at cox.net Sat Jan 3 21:29:28 2009 From: eric.kemp at cox.net (Eric Kemp) Date: Sat, 03 Jan 2009 21:29:28 -0500 Subject: strange behavior of math.sqrt() in new 3.0 version In-Reply-To: References: Message-ID: Tim Roberts wrote: > Scott David Daniels wrote: >> I avoid using single-letter variables except where I know the types >>from the name (so I use i, j, k, l, m, n as integers, s as string, >> and w, x, y, and z I am a little looser with (but usually float or >> complex). > > It's amazing to me that Fortran continues to live on in the hearts and > minds of today's programmers. Fortran is alive and well. If you can find a Fortran 2003 compiler, you can even use classes. From guotie.9 at gmail.com Sat Jan 3 21:47:39 2009 From: guotie.9 at gmail.com (=?GB2312?B?tqO2o7WxtbE=?=) Date: Sat, 3 Jan 2009 18:47:39 -0800 (PST) Subject: =?ISO-2022-JP?B?V2hlbiBkb2VzIHB5dGhvbiAzLjEbJEIhJBsoQiAzLjIgdmVyc2lvbiBvdXQbJEIhKRsoQg==?= Message-ID: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Now? the 3.0 version is out for a time. I wonder when the python 3.1 is out, and what change is in python 3.1. Thanks. From musiccomposition at gmail.com Sat Jan 3 22:54:13 2009 From: musiccomposition at gmail.com (Benjamin) Date: Sat, 3 Jan 2009 19:54:13 -0800 (PST) Subject: =?ISO-2022-JP?B?UmU6IFdoZW4gZG9lcyBweXRob24gMy4xGyRCISQbKEIgMy4yIHZlcnNpb24gb3V0GyRCISkbKEI=?= References: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Message-ID: <786cce5a-6d55-41bf-8481-055153693004@w1g2000prk.googlegroups.com> On Jan 3, 8:47 pm, ???? wrote: > Now? the 3.0 version is out for a time. > > I wonder when the python 3.1 is out, and what change is in python 3.1. There's no schedule yet. Hopefully, one will come into being around PyCon. From greywine at gmail.com Sat Jan 3 22:58:19 2009 From: greywine at gmail.com (greywine at gmail.com) Date: Sat, 3 Jan 2009 19:58:19 -0800 (PST) Subject: simple turn-based multiplayer game via TCP server/client Message-ID: Hi everyone, I'm learning python to get a multiplayer roleplaying game up and running. I didn't see any simple examples of multiplayer games on the web so I thought I'd post mine here. I choose Rock, Paper, Scissors as a first game to experiment with as the game logic/options are easy to implement and understand. Initially, I tried to get the socketserver.TCPServer example in the Python Docs to work, but couldn't get my game variables into the handle method of the class MyTCPHandler. And I didn't know how else to do it. I ended up creating my own server & client out of simple sockets based on the simple echo server & client examples in the Python Docs. I also wanted to send chat messages OR game variables back & forth, but I couldn't figure out how to do the OR, so the basic idea in this implementation is to send the dictionary 'game' back and forth. game dict contains all the gaming variables as well as any chat messages. The program processes results depending on whether the game is starting, there's a chat message, or there's a game move. Finally, in testing, I ran the server in IDLE, but I had to load a command prompt and switch to c:\python30; then type 'python rpsmulti.py' for the client every time. Anyone know how to test server/client code strictly in IDLE? Anyway, try it out and let me know how you would improve it. John R. # NAME: rpsmulti.py # DESCRIPTION: rock, paper, scissors game multiplayer game # AUTHOR: John Robinson # DATE: 1/3/09 # VERSION: Python 3.0 # TO DO: # .server_address instead of HOST, PORT? import socket from random import choice from pickle import dumps, loads from pprint import pprint HOST, PORT = "localhost", 9999 # defined for now BUFFSIZE = 1024 # for socket.send & recv commands BACKLOG = 2 # number of clients supported by server SECONDS = 3 # seconds until socket.timeout (not implemented) # moves dict to translate 'rps' choice MOVES = {'r':'Rock', 'p':'Paper', 's':'Scissors'} # outcome dict stores result for all possible scenarios OUTCOME = {('p','r'): 'win', ('r','s'): 'win', ('s','p'): 'win', ('p','p'): 'draw', ('r','r'): 'draw', ('s','s'): 'draw', ('r','p'): 'lose', ('s','r'): 'lose', ('p','s'): 'lose'} def main_menu(game): """ initialize game dict variables & opening screen of the game """ game['total'] = 0 # total number of games played game['won'] = 0 # total games won by player game['lost'] = 0 # total games lost by player game['drew'] = 0 # total games drew by player game['move'] = '' # player's move (rps) game['message'] = '' # player's chat message game['sentmessage'] = '' # player's previous message game['start'] = True # setting up the game boolean print("\tROCK PAPER SCISSORS\n") if game['name']=='': # if returning to menu don't display the following game['name'] = get_name() print("Welcome "+game['name']+". Remember...") print("Rock smashes scissors! Paper covers Rock! Scissors cuts paper!\n") print("1. Play single player game") print("2. Start two player game") print("3. Join two player game") print("4. Quit") print() c = safe_input("Your choice? ", "1234") c = int(c) if c==1: one_player(game) elif c==2: start_two_player(game) elif c==3: two_player_join(game) else: print('Play again soon.') def safe_input(prompt, values='abcdefghijklmnopqrstuvwxyz'): """ gives prompt, checks first char of input, assures it meets given values default is anything goes """ while True: i = input(prompt) try: c = i[0].lower() except IndexError: # the only possible error?! if c=='': print("Try again.") else: if c not in values: # some other character print("Try again.") else: # looks good. continue. break return i def get_name(): """ returns input as name """ while True: name = input("What is your name? ") check = input(name + ". Correct (y/n)? ") if check[0] in 'yY': break return name def get_result(player, opponent): """ reports opponent's choice; checks player and opponent dicts ['move'] against OUTCOME dict; reports result returns player dict with updated values """ print(opponent['name'], 'chose %s.' % (MOVES[opponent['move']])) # check lookout dict (OUTCOME dictionary) result = OUTCOME[(player['move'], opponent['move'])] # update game variables player['total'] += 1 if result=='win': print('%s beats %s. You win.' % (MOVES[player['move']], MOVES [opponent['move']])) player['won'] += 1 elif result=='draw': print('%s - %s: no one wins. You draw.' % (MOVES[player ['move']], MOVES[opponent['move']])) player['drew'] += 1 else: print('%s loses to %s. You lose.' % (MOVES[player['move']], MOVES[opponent['move']])) player['lost'] += 1 return player def one_player(game): """ implements one player game with minimal opponent dict """ print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to return to \ main menu.") opponent = {} opponent['name'] = 'Computer' # gaming loop while True: # gets player's choice game['move'] = safe_input('1, 2, 3, GO! ','rpsq') if game['move']=='q': break # computer chooses via random.choice opponent['move'] = choice('rps') # check game outcome dict game = get_result(game, opponent) # exit loop print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) def start_two_player(game): """ starts tcp server and implements two player game game dict = player 1""" # Create a socket (SOCK_STREAM means a TCP socket) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((HOST, PORT)) sock.listen(BACKLOG) serverip, serverport = sock.getsockname() print("Running at %s, %s" % (serverip, serverport)) print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ return to main menu.") print("Waiting for player...") client, address = sock.accept() clientip, clientport = address # server/game loop while True: try: P2game = loads(client.recv(BUFFSIZE)) # receive other game variables except EOFError: # if available print(P2game['name'], "left the game.") break client.send(dumps(game)) # send our variables # it's either the start... if P2game['start']: print(P2game['name'],"logged on at", clientip, clientport) game['start'] = False # or there's a message if P2game['message']!='' and P2game['message']!=game ['sentmessage']: print(P2game['name']+': '+P2game['message']) game['sentmessage'] = P2game['message'] # to avoid many print calls game['move'] = '' # message always takes priority # or there's a move if game['move']=='': game['move'] = safe_input('1, 2, 3, GO! ') if game['move']=='q': break elif game['move'] not in 'rps': game['message'] = game['move'] game['move'] = '' # only check result if P2game also made a move if P2game['move']!='': # check game outcome dict game=get_result(game, P2game) game['move']='' # exit loop client.close() print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) def two_player_join(game): """ joins a tcp server two player game game dict = player 2""" # Create a socket (SOCK_STREAM means a TCP socket) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ return to main menu.") # client/game loop while True: sock.send(dumps(game)) try: P1game = loads(sock.recv(BUFFSIZE)) except EOFError: print(P1game['name'], "left the game.") break if P1game['start']: print("You're connected to "+P1game['name']+"'s game.") game['start'] = False if P1game['message']!='' and P1game['message']!=game ['sentmessage']: print(P1game['name']+': '+P1game['message']) game['sentmessage'] = P1game['message'] game['move'] = '' if game['move']=='': game['move'] = safe_input('1, 2, 3, GO! ') if game['move']=='q': break elif game['move'] not in 'rps': game['message'] = game['move'] game['move'] = '' if P1game['move']!='': # check game outcome dict game=get_result(game, P1game) game['move']='' # exit loop sock.close() print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ (game['won'],game['lost'],game['drew'],game['total'])) main_menu(game) if __name__=='__main__': game = {} # initialize game dict to store all game variables game['name'] = '' # player's name initially main_menu(game) From timr at probo.com Sat Jan 3 23:11:34 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 04 Jan 2009 04:11:34 GMT Subject: win32gui References: <8bf17a89-11bc-4c89-8ebc-db46fccefaa2@o4g2000pra.googlegroups.com> Message-ID: Gandalf wrote: > >I'm trying to capture the text word under the user cursor, >so I was searching the win32 lib for functions I can use. You should know that, in the general case, this is impossible. Remember that the screen image you are looking at is just a big array of dots. If the window underneath happens to be an image, there won't be any text to fetch. Now, in many cases it IS possible, but it's not easy. >i used this to fined the controller under the cursor >win32gui.WindowFromPoint(win32gui.GetCursorPos()) > to get the controller, That's the first step. Then, you need to figure out what kind of window it is. If it is a standard edit box, you can use the EM_GETLINE functions. If it's a rich text edit box, you can use the rich text messages. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From vminch at gmail.com Sat Jan 3 23:15:17 2009 From: vminch at gmail.com (vk) Date: Sat, 3 Jan 2009 20:15:17 -0800 (PST) Subject: Port of python stdlib to other languages. References: <6sa2dvF4uc5uU1@mid.uni-berlin.de> Message-ID: <7b8157b6-0781-4509-b1ba-b799a41a406b@a29g2000pra.googlegroups.com> > AFAIK not. You could try elmer Elmer looks very interesting, but not really what I was getting at. > What do you need C for anyway? Or, to put it the other way round - why > not expose whatever you need in C as python extension, and write your > app in Python? I'm not looking to write a Python app atm. Just curious if someone had started a project like this, to, say, make Python users more comfortable using other languages (for whatever reason), or allow other people to try "python-like" code in their language to see if it suits them. From koranthala at gmail.com Sat Jan 3 23:25:59 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 3 Jan 2009 20:25:59 -0800 (PST) Subject: Doubt on creating threads References: Message-ID: <8f2a3eb8-ee54-404f-b565-a44ad2a62f10@n33g2000pri.googlegroups.com> On Jan 4, 4:59?am, Bryan Olson wrote: > koranth... at gmail.com wrote: > > I am creating an application and it creates ~1-2 threads every second > > and kill it within 10 seconds. After reading this I am worried. Is > > creating a thread a very costly operation? > > Compared to a procedure call it's expensive, but a couple threads per > second is insignificant. My out-dated Pentium 4 desktop can create and > destroy a few thousand threads per second under WinXP; more under recent > Linux. > > -- > --Bryan Thank you very much. I was worried about this a lot. From mensanator at aol.com Sat Jan 3 23:27:44 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 3 Jan 2009 20:27:44 -0800 (PST) Subject: Port of python stdlib to other languages. References: <6sa2dvF4uc5uU1@mid.uni-berlin.de> <7b8157b6-0781-4509-b1ba-b799a41a406b@a29g2000pra.googlegroups.com> Message-ID: <491ccedf-ea2d-4294-864c-ed8977c9185f@p2g2000prn.googlegroups.com> On Jan 3, 10:15?pm, vk wrote: > > AFAIK not. You could try elmer > > Elmer looks very interesting, but not really what I was getting at. > > > What do you need C for anyway? Or, to put it the other way round - why > > not expose whatever you need in C as python extension, and write your > > app in Python? > > I'm not looking to write a Python app atm. > > Just curious if someone had started a project like this, to, say, make > Python users more comfortable using other languages (for whatever > reason), > or allow other people to try "python-like" code in their language to > see > if it suits them. But wouldn't your language of choice first have to support things like lists, generators, etc.? I can use GMP library in C instead of gmpy in Python, but not if I need to use Python things that I don't know how to implement in C. From ptmcg at austin.rr.com Sat Jan 3 23:55:57 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 3 Jan 2009 20:55:57 -0800 (PST) Subject: Memoizing and WeakValueDictionary Message-ID: <482f1e7f-52a7-4c7f-819b-59faeb4e203e@e10g2000vbe.googlegroups.com> Just wanted to share some experience I had in doing some memory and performance tuning of a graphics script. I've been running some long- running scripts on high-resolution images, and added memoizing to optimize/minimize object creation (my objects are immutable, so better to reuse objects from a cache than constantly create and discard instances). This helped my script early on, but as the data files got larger and larger, and runs got longer and longer, the object memoize cache started to suck up some serious memory, and performance started to degrade for a different reason - low memory -> page thrashing -> program crawling. It occurred to me that in my program, a given object may get used for a while, but once its use declines, it doesn't come back for a while. At first blush, I thought about using some sort of LRU cache, but first I tried the WeakValueDictionary from the wkref module. This worked great! Now I get fairly optimal reuse of my immutable instances, but my object cache doesn't grow without bounds. Does this sound like a correct interpretation of this behavior? If so, it would seem that WeakValueDictionary would be a good recommendation to go along with any memoizing implementations. From aleksandr.goretoy at gmail.com Sun Jan 4 02:18:45 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 07:18:45 +0000 Subject: simple turn-based multiplayer game via TCP server/client In-Reply-To: References: Message-ID: Since we are on the subject of Rock, Paper, Scissors. I've recntly watched this one video on how to make a .deb out of .py files and the tutor was using a rock, paper scissors game. Not sure how this may come of use to you but, I'll post it anyway for you to look at. May help somehow. http://www.google.com/search?hl=en&q=filetype%3Apy+%22rock+paper+scissors%22&btnG=Search http://www.showmedo.com/videos/video?name=linuxJensMakingDeb&fromSeriesID=37 Hope this help you in your journey for multiplayer game somehow On Sun, Jan 4, 2009 at 3:58 AM, greywine at gmail.com wrote: > Hi everyone, > > I'm learning python to get a multiplayer roleplaying game up and > running. > > I didn't see any simple examples of multiplayer games on the web so I > thought I'd post mine here. I choose Rock, Paper, Scissors as a first > game to experiment with as the game logic/options are easy to > implement and understand. > > Initially, I tried to get the socketserver.TCPServer example in the > Python Docs to work, but couldn't get my game variables into the > handle method of the class MyTCPHandler. And I didn't know how else > to do it. I ended up creating my own server & client out of simple > sockets based on the simple echo server & client examples in the > Python Docs. > > I also wanted to send chat messages OR game variables back & forth, > but I couldn't figure out how to do the OR, so the basic idea in this > implementation is to send the dictionary 'game' back and forth. game > dict contains all the gaming variables as well as any chat messages. > The program processes results depending on whether the game is > starting, there's a chat message, or there's a game move. > > Finally, in testing, I ran the server in IDLE, but I had to load a > command prompt and switch to c:\python30; then type 'python > rpsmulti.py' for the client every time. Anyone know how to test > server/client code strictly in IDLE? > > Anyway, try it out and let me know how you would improve it. > > John R. > > # NAME: rpsmulti.py > # DESCRIPTION: rock, paper, scissors game multiplayer game > # AUTHOR: John Robinson > # DATE: 1/3/09 > # VERSION: Python 3.0 > # TO DO: > # .server_address instead of HOST, PORT? > > import socket > from random import choice > from pickle import dumps, loads > from pprint import pprint > > HOST, PORT = "localhost", 9999 # defined for now > BUFFSIZE = 1024 # for socket.send & recv commands > BACKLOG = 2 # number of clients supported by > server > SECONDS = 3 # seconds until socket.timeout (not > implemented) > # moves dict to translate 'rps' choice > MOVES = {'r':'Rock', > 'p':'Paper', > 's':'Scissors'} > # outcome dict stores result for all possible scenarios > OUTCOME = {('p','r'): 'win', > ('r','s'): 'win', > ('s','p'): 'win', > ('p','p'): 'draw', > ('r','r'): 'draw', > ('s','s'): 'draw', > ('r','p'): 'lose', > ('s','r'): 'lose', > ('p','s'): 'lose'} > > def main_menu(game): > """ initialize game dict variables & opening screen of the game > """ > game['total'] = 0 # total number of games played > game['won'] = 0 # total games won by player > game['lost'] = 0 # total games lost by player > game['drew'] = 0 # total games drew by player > game['move'] = '' # player's move (rps) > game['message'] = '' # player's chat message > game['sentmessage'] = '' # player's previous message > game['start'] = True # setting up the game boolean > > print("\tROCK PAPER SCISSORS\n") > if game['name']=='': # if returning to menu don't display > the following > game['name'] = get_name() > print("Welcome "+game['name']+". Remember...") > print("Rock smashes scissors! Paper covers Rock! Scissors cuts > paper!\n") > print("1. Play single player game") > print("2. Start two player game") > print("3. Join two player game") > print("4. Quit") > print() > c = safe_input("Your choice? ", "1234") > c = int(c) > if c==1: > one_player(game) > elif c==2: > start_two_player(game) > elif c==3: > two_player_join(game) > else: > print('Play again soon.') > > def safe_input(prompt, values='abcdefghijklmnopqrstuvwxyz'): > """ gives prompt, checks first char of input, assures it meets > given values > default is anything goes """ > while True: > i = input(prompt) > try: > c = i[0].lower() > except IndexError: # the only possible error?! > if c=='': > print("Try again.") > else: > if c not in values: # some other character > print("Try again.") > else: # looks good. continue. > break > return i > > def get_name(): > """ returns input as name """ > while True: > name = input("What is your name? ") > check = input(name + ". Correct (y/n)? ") > if check[0] in 'yY': > break > return name > > def get_result(player, opponent): > """ reports opponent's choice; > checks player and opponent dicts ['move'] against OUTCOME > dict; > reports result > returns player dict with updated values """ > print(opponent['name'], 'chose %s.' % (MOVES[opponent['move']])) > # check lookout dict (OUTCOME dictionary) > result = OUTCOME[(player['move'], opponent['move'])] > # update game variables > player['total'] += 1 > if result=='win': > print('%s beats %s. You win.' % (MOVES[player['move']], MOVES > [opponent['move']])) > player['won'] += 1 > elif result=='draw': > print('%s - %s: no one wins. You draw.' % (MOVES[player > ['move']], MOVES[opponent['move']])) > player['drew'] += 1 > else: > print('%s loses to %s. You lose.' % (MOVES[player['move']], > MOVES[opponent['move']])) > player['lost'] += 1 > return player > > def one_player(game): > """ implements one player game with minimal opponent dict """ > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to > return to \ > main menu.") > opponent = {} > opponent['name'] = 'Computer' > > # gaming loop > while True: > # gets player's choice > game['move'] = safe_input('1, 2, 3, GO! ','rpsq') > if game['move']=='q': > break > # computer chooses via random.choice > opponent['move'] = choice('rps') > # check game outcome dict > game = get_result(game, opponent) > > # exit loop > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > def start_two_player(game): > """ starts tcp server and implements two player game > game dict = player 1""" > # Create a socket (SOCK_STREAM means a TCP socket) > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.bind((HOST, PORT)) > sock.listen(BACKLOG) > serverip, serverport = sock.getsockname() > print("Running at %s, %s" % (serverip, serverport)) > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ > return to main menu.") > print("Waiting for player...") > > client, address = sock.accept() > clientip, clientport = address > # server/game loop > while True: > try: > P2game = loads(client.recv(BUFFSIZE)) # receive other > game variables > except EOFError: # if available > print(P2game['name'], "left the game.") > break > client.send(dumps(game)) # send our > variables > # it's either the start... > if P2game['start']: > print(P2game['name'],"logged on at", clientip, clientport) > game['start'] = False > # or there's a message > if P2game['message']!='' and P2game['message']!=game > ['sentmessage']: > print(P2game['name']+': '+P2game['message']) > game['sentmessage'] = P2game['message'] # to avoid many > print calls > game['move'] = '' # message always takes > priority > # or there's a move > if game['move']=='': > game['move'] = safe_input('1, 2, 3, GO! ') > if game['move']=='q': > break > elif game['move'] not in 'rps': > game['message'] = game['move'] > game['move'] = '' > # only check result if P2game also made a move > if P2game['move']!='': > # check game outcome dict > game=get_result(game, P2game) > game['move']='' > # exit loop > client.close() > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > def two_player_join(game): > """ joins a tcp server two player game > game dict = player 2""" > # Create a socket (SOCK_STREAM means a TCP socket) > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.connect((HOST, PORT)) > > print("\nType (R)ock, (P)aper or (S)cissors to play. (q)uit to \ > return to main menu.") > > # client/game loop > while True: > sock.send(dumps(game)) > try: > P1game = loads(sock.recv(BUFFSIZE)) > except EOFError: > print(P1game['name'], "left the game.") > break > if P1game['start']: > print("You're connected to "+P1game['name']+"'s game.") > game['start'] = False > if P1game['message']!='' and P1game['message']!=game > ['sentmessage']: > print(P1game['name']+': '+P1game['message']) > game['sentmessage'] = P1game['message'] > game['move'] = '' > if game['move']=='': > game['move'] = safe_input('1, 2, 3, GO! ') > if game['move']=='q': > break > elif game['move'] not in 'rps': > game['message'] = game['move'] > game['move'] = '' > if P1game['move']!='': > # check game outcome dict > game=get_result(game, P1game) > game['move']='' > # exit loop > sock.close() > print('\nYou won %s, lost %s, drew %s (%s total)\n' % \ > (game['won'],game['lost'],game['drew'],game['total'])) > main_menu(game) > > if __name__=='__main__': > game = {} # initialize game dict to store all game > variables > game['name'] = '' # player's name initially > main_menu(game) > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 02:28:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 07:28:38 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> Message-ID: <01705c07$0$8693$c3e8da3@news.astraweb.com> I'm answering both John and Aaron's comments in the following. Mostly John at the start, Aaron toward the end. On Sat, 03 Jan 2009 15:42:47 -0800, Aaron Brady wrote: > On Jan 3, 11:25?am, John O'Hagan wrote: [...] > > >According to this, when you replace every floorboard on a porch, one > > >at a time, it's still the same porch-- it's changed, it's different, > > >and it's the same. ?However, if you haul off the porch and put a new > > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > > >just look at the initial and final configurations of matter to > > >determine so. ?Therefore, 'id' is an informal function. > > > > This analogy describes the "ontological minefield" I was referring to > > in a previous post in this thread (which has expired in my mail > > reader, so my apologies if the threading goes awry): In what sense is > > a porch (or list, or string) the same if all (or even some of) its > > parts have been exchanged? > > > > I think the answer is something to do with the abstraction, the > > "container", the instance of the class. That seems reasonable. When you say alist[:] = [1, 2, 3] the container remains "the same", while the contents change. > > Would it be fair to say that perhaps there are no > > truly mutable objects, only immutable containers whose contents (also > > immutable objects themselves) may be exchanged? Or to pose the > > question another way, are objects only mutable insofar as they are > > composite? That depends on what you mean by composite. Everything is composite in some sense, even a single bit in memory has a physical reality made of atoms with magnetic fields. But taken as an abstract entity, it is reasonable to treat a single bit as an atomic non-composite thing, and a single bit is mutable. In practice, actual Python objects tend to be mutable only if they are composite (although being composite doesn't make them mutable -- consider frozen sets and tuples). In principle, this is not necessary. There's no reason why Python couldn't expose a single bit as a data type, so you could write this: >>> n = bit(1) >>> bool(n) True >>> n.flip() >>> bool(n) False > > As you argue above, the planks are not the porch; I would add that > > it's your _decision_ to build (or tear down) a porch which makes it > > _that_ ?particular porch (or not). No, there's no such decision needed. Perhaps a hurricane comes through and rips the porch up. Maybe a rogue television crew comes by while you're at work and renovates your house without your knowledge. The lack of decision-making needed is more obvious when you consider something like a fast-flowing river. The specific water molecules making up the river at any particular instant in time flow away in a matter of days or weeks, but rivers have a continuity of existence measured in thousands of years. I trust that nobody is going to argue that the river makes any decisions at all? > > As you imply above (I think), you have to keep looking (or someone > > does, presumably the interpreter) to know whether an object is the > > same as or just equal to another (which starts to sound spookily like > > the role of "the observer" in phenomenology or quantum physics). No, I think you're introducing mysticism here that isn't needed. A bit like quantum mechanics, really :) In Python, every object has an identity and a value. If objects X and Y have the same identity, they are the same object. If X is the object with id 1234, and Y is the object with id 1234, then both are the same object. If their ids are different, then they are not. In CPython, the id is given by the memory location of the object, which leads to a very intuitive understanding of "same": the object with id 1234 is at memory location 1234, and since there can only be one object at a particular memory location at a time, obviously all objects with id 1234 must be the same object (provided they exist simultaneously). (To be pedantic, there can't actually be objects [note plural] existing simultaneously with the same id. There can only be multiple references to the one object.) In Python implementations where the id is not a memory address (IronPython and Jython I think?) the above remains true, even though there isn't the simple intuitive picture of "only one object can be at a specific memory address". Python guarantees that the id is *something* which is guaranteed to be unique over the lifetime of every object. Actually, our intuition about one thing per place at the one time is not strictly correct. Consider the memory address 1234, which currently has the value in hex of 0x58. That byte may be the numeric value 88, the ASCII char "X", the set of flags 1011000, or any other thing, depending on what interpretation we give to it. "What a thing is" is actually a more difficult question than it appears at first glance. [...] > I think the key ingredient is that there's no such thing as side > effect in math. I don't see that this is relevant. We're not talking about mathematical equality, but about the more general concepts of identity and sameness. > In example, > > a= [0, 1, 2] > a[:]= [3, 4, 5] > > There aren't many natural language senses in which 'a' is the same > object as before. Of course there are. If I have a box containing three things (a piece of paper with the number "0" written on it, a plastic block in the shape of "1" and a tally stick with two notches cut in it), and then I remove those three things and replace them with something else, it's the same box. The English and Australian cricket teams have been playing international Test cricket since 1877. None of the team members playing in 1877 are still alive today. The entire lineup of both cricket teams has been replaced repeatedly, and yet they are the same teams. The same holds for many, many different organisations: churches, armies, regiments, political parties, social clubs, companies, guilds, nations, sporting teams, secret societies, criminal gangs, ecosystems, tribes, communities of many sorts, and so forth. Far from being rare, this is very common. > If I have a leg transplant, I'm the same person, > but if you replace the entire contents of me, I'm not. Every (?) molecule in your body is replaced over a period of approximately seven years. Some molecules are replaced much quicker, some a little slower, but speaking roughly, the entire contents of you is replaced every seven years. Aaron, are you the same person you were a decade ago? In some sense, not at all -- you're a different person to the annoying person who called himself "castironpi" and was repeatedly accused of being a bot only a few months ago. But in another sense, yes, you are the same person -- there is a continuity of existence. See also the Ship of Theseus paradox, otherwise known as My Grandfather's Axe paradox. http://en.wikipedia.org/wiki/Ship_of_Theseus [...] > The porch is defined by its location, but not exclusively. If we remove the porch from the house and transport it whole to another house, it remains the same porch attached to a different house. > Natural > language identity is a cluster concept, without strict necessary and > sufficient conditions. Nothing really presses our boundaries of it > that much; there aren't many practical questions that lay out the > facts, then ask, 'But is it the same?' You can replace the porch > board-at-a-time, and it is; and you can haul it somewhere and it is. > But rearrange the same boards, and it's not. I think you overstate your case. If you move the boards around on the porch, it remains the same porch. Likewise if I have a chest of drawers, and I take the top drawer and put it at the bottom, the bottom drawer in the middle and the middle drawer at the top, surely it is the same chest of drawers? I haven't even replaced anything, just moved them around. > Continuity of form is > probably the prevalent feature, which as you state, does break down in > the case of composite (piece-wise) transformations. I think continuity of form is an important factor in deciding what is the same and what is not, but I don't think it is the only one. See for example the anecdote about the Japanese temple in the Wikipedia article above. And I think you're wrong to say that piece-wise transformations break down continuity of form. You are, in some sense, the same person who some years ago was a crawling baby unable to speak. There are significant changes and replacements and add-ons that nevertheless don't break continuity. > You might get farther comparing container objects to spots on a > bulletin board. The only thing that goes 'in' a container is a > denoting phrase to another object (and by the way, not a description); > the other also has its own spot independently on the board. That's a reasonable analogy for the implementation of CPython, but it need not be the only implementation. It wouldn't be fast, or efficient, or reasonable, but one could create a Python implementation where (for example) a list didn't just hold pointers to objects, but it held the actual entire object (no matter how large). Identity could be divorced from memory location: the one object could exist in many different places in memory, in the same way that an object can exist in many different times. The underlying VM would ensure that all such instantiations of the one object remained in sync at all time. Such an implementation would be inefficient and foolish, but it would still be Python. Having said that, it is perfectly valid to ignore the implementation when describing how Python operates. It really doesn't matter whether CPython is implemented like a bulletin board or not, it behaves as if it were, and that makes it a reasonable analogy. -- Steven From ajaksu at gmail.com Sun Jan 4 02:46:42 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 3 Jan 2009 23:46:42 -0800 (PST) Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: On Jan 3, 8:53?pm, Bryan Olson wrote: > If we add a parameter for the length of the list to which the slice is > applied, then inslice() is well-defined. Cool! > I thought it would easy to write, Heh, I gave up on the example I mentioned above :) > but that was hours ago when I knew > less about Python slice indexing than I do now. And I thought I new a > bunch from writing a virtual slice class. Maybe you could write about what you learned in the docs? > I'm leaning towards mmanns' idea that this should be built in. Handling > all the cases is remarkably tricky. Even without testing your code, I agree. I suggest that you add this as a feature request to the tracker at http://bugs.python.org/. I hope Raymond Hettinger likes it and adds an islice version :) From gruszczy at gmail.com Sun Jan 4 04:43:37 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 4 Jan 2009 10:43:37 +0100 Subject: deleting a method In-Reply-To: <87zli8j9li.fsf@benfinney.id.au> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> Message-ID: <1be78d220901040143v5918b5aft24df79b35b9cef25@mail.gmail.com> > To answer the second question: since 'foo' is an attribute of the > class 'A', you can delete the attribute from the class. > > >>> class A(object): > ... def foo(self): > ... pass > ... > >>> a = A() > >>> 'foo' in dir(a) > True > >>> del A.foo > >>> 'foo' in dir(a) > False Thanks, now I see, what happens, but don't exactly know why. Could you point me to some good explanation how object creation is performed in Python? I browsed language reference and google, but couldn't find good explanation. -- Filip Gruszczy?ski From aleksandr.goretoy at gmail.com Sun Jan 4 04:52:41 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 09:52:41 +0000 Subject: math module for Decimals In-Reply-To: <0170080e$0$8693$c3e8da3@news.astraweb.com> References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: I've been watching this thread for couple days now. I followed the bug report and all that stuff. It's very interesting to me how you guys talk about this stuff. I like it alot. I a new guy to python, just fyi. I'm one of my current projects I'm using Decimal as well and I think it be a huge pain in the you know what that it doesn't take floats as input. I'm currently doing this in my code: a=str(decimal.Decimal(str(round(self.value,2)-round(float(subtract),2)))) I know it's messy and I need sleep, yawn. But you see what I'm getting at here. I have to jump through somuch hoops to get what I wanted out of this. To be up front, I'm not sure that's what I wanted. Too tired. Anyway, I'm glad you guys got it pushed into 2.7 and 3.1. Thank you so much for this. Also, another reason why I'm posting to this thread. I noticed some error/typo in line 683 of decimal.py located on public svn repo. This is what is looks like. sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 I'm not trying to mention it to show someones flaws, rather I want to help you guys. Genuinely. I want in on the action. To do what I can, or what I'm capable of. So please do _NOT_ take it that way. This is awesome stuff, Thank you. -A On Sun, Jan 4, 2009 at 1:30 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: > > > On Jan 3, 9:27 pm, Mark Dickinson wrote: > >> Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > >> and Python 3.1, within 72 hours of Steven submitting the feature > >> request. If only all issues could be resolved this quickly. :-) > > > > Rats. I left out the crucial line of that post, namely: > > > > Thank you, Steven! > > And many thanks to both you and Raymond, firstly for doing the actual > work, and secondly for your patience with my questions on the bug tracker. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 04:52:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 09:52:49 GMT Subject: Testing if an index is in a slice References: <20090101191226.5137adb6@Schlamber.localdomain> Message-ID: <01707dd1$0$8693$c3e8da3@news.astraweb.com> On Sat, 03 Jan 2009 14:53:12 -0800, Bryan Olson wrote about testing whether or not an index is in a slice: > I'm leaning towards mmanns' idea that this should be built in. What's the use-case for it? > Handling > all the cases is remarkably tricky. Here's a verbose version, with a > little test: [snip code] Here's a less verbose version which passes your test cases: def inslice(index, slc, len): """Return True if index would be part of slice slc of a sequence of length len, otherwise return False. """ start, stop, stride = slc.indices(len) if stride < 0: return (start >= index > stop) and ((start-index) % -stride == 0) else: return (start <= index < stop) and ((index-start) % stride == 0) (Hint: help(slice) is your friend.) -- Steven From manishsinha.tech at gmail.com Sun Jan 4 05:09:27 2009 From: manishsinha.tech at gmail.com (Manish Sinha) Date: Sun, 04 Jan 2009 15:39:27 +0530 Subject: deleting a method In-Reply-To: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> Message-ID: <49608AD7.7050704@gmail.com> Filip Gruszczy?ski wrote: > I am trying to delete a method from a class. It's easy to delete other > attributes, but when I try: > > >>>> class A: >>>> > ... def foo(): > ... pass > ... > >>>> a = A() >>>> del a.foo >>>> > > I get > > Traceback (most recent call last): > File "", line 1, in > AttributeError: A instance has no attribute 'foo' > > Why is it so and how may still delete it? > > Sounds crazy.... If you want to delete a function, create lambda functions though am not sure whether it can be deleted or not. -- Manish Sinha Personal Blog: http://www.manishsinha.info Tech Blog: http://manishtech.wordpress.com OpenPGP Key: 99E6658F -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Sun Jan 4 05:12:41 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 04 Jan 2009 21:12:41 +1100 Subject: deleting a method References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> Message-ID: <87r63jjs6e.fsf@benfinney.id.au> "Filip Gruszczy?ski" writes: > Thanks, now I see, what happens, but don't exactly know why. Could > you point me to some good explanation how object creation is > performed in Python? Rather than ?how object creation is performed?, I would recommend you get a better handle on how the object *model* works in Python. If you haven't yet, please work through all of the Python Tutorial . Read each part, experiment with code until you understand what is presented, and only *then* move on to the next section. For theoretical explanations, the effbot's ?Python Objects? article is also recommended. Before theory though, use the Tutorial for concrete demonstrations coming from your very fingers. -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From dickinsm at gmail.com Sun Jan 4 05:21:34 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jan 2009 02:21:34 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 9:52?am, "alex goretoy" wrote: > Also, another reason why I'm posting to this thread. I noticed some > error/typo in line 683 of decimal.py located on public svn repo. This is > what is looks like. > > ? ? ? ? sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 This line looks okay to me; can you say why you think there's a typo here? If it's the 'sign = 0' part that's bothering you, that's just a peculiarity of Decimal: the stored sign value is 0 for positive numbers, 1 for negative numbers, which I agree is a little counterintuitive. (Think of the sign as analogous to the sign *bit* in an IEEE 754 floating-point number.) Mark From aleksandr.goretoy at gmail.com Sun Jan 4 05:38:11 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 10:38:11 +0000 Subject: math module for Decimals In-Reply-To: References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: No, I know there's a typo because python told me there is. If you have svn repo locally. then cd into Lib/ and run python decimal.py It will tell you line 683 has syntax error, please see below. haha python-svn # python Lib/decimal.py File "Lib/decimal.py", line 683 sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 ^ SyntaxError: invalid syntax Although, It may be only because I ran it through python 2.4.3 Thanks for quick response, I wasn't expecting so quick. :) On Sun, Jan 4, 2009 at 10:21 AM, Mark Dickinson wrote: > On Jan 4, 9:52 am, "alex goretoy" wrote: > > Also, another reason why I'm posting to this thread. I noticed some > > error/typo in line 683 of decimal.py located on public svn repo. This is > > what is looks like. > > > > sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 > > This line looks okay to me; can you say why you think there's a typo > here? > > If it's the 'sign = 0' part that's bothering you, that's just > a peculiarity of Decimal: the stored sign value is 0 for > positive numbers, 1 for negative numbers, which I agree > is a little counterintuitive. (Think of the sign > as analogous to the sign *bit* in an IEEE 754 floating-point > number.) > > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -- ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Sun Jan 4 05:43:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 4 Jan 2009 12:43:18 +0200 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> Message-ID: <010a01c96e64$78890380$0d00a8c0@hendrik> "Aaron Brady" wrote: >No; tuples are composite. If I flip one bit in a byte somewhere, is >it the same byte? Yes and No and No and Others: Yes it is the byte at the same somewhere in memory. No it is not the same as it was a moment ago, because the bit has flipped. No it is one of the bytes recently corrupted by a passing cosmic ray. [Insert other points of view here] And of course, depending on what we are doing, we take the viewpoint that is useful to the task in hand. Taking all at the same time leads to a room with soft walls and a jacket with funny sleeves. Simplifying the porch example: Here is a family heirloom - it is my grandfather's axe. My father fixed it up by replacing the handle, and I replaced the head because it was so worn. I still think of it as my grandfather's axe, though. Natural language seems to have very little to do with logic, or even common sense, as constructs like "my grandfather's axe" can be encountered in the wild, without causing excessive cognitive dissonance. I think the root trouble for computers when we want them to make decisions about stuff like this is that they are too rigid - their binary or boolean nature forces them into taking the first branch that looks true at the time. We probably need something softer based on majority logic like neural nets, or something entirely new if we want to use them to explore this kind of stuff. (yes I know we can write a simulation, but a simulation is not an interpreter, is not a compiler, is not an assembler is not an executable - and its at the executable level that the rigidity is most apparent) - Hendrik From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 05:55:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 10:55:17 GMT Subject: Take the first n items of an iterator Message-ID: <01708c76$0$8693$c3e8da3@news.astraweb.com> I thought there was an iterator in itertools for taking the first n items of an iterator, then halting, but I can't find it. Did I imagine such a tool, or am I missing something? -- Steven From dickinsm at gmail.com Sun Jan 4 05:56:01 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jan 2009 02:56:01 -0800 (PST) Subject: math module for Decimals References: <01671a9e$0$6988$c3e8da3@news.astraweb.com> <016721cc$0$6988$c3e8da3@news.astraweb.com> <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 10:38?am, "alex goretoy" wrote: > haha python-svn # python Lib/decimal.py > ? File "Lib/decimal.py", line 683 > ? ? sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 > ? ? ? ? ? ? ? ^ > SyntaxError: invalid syntax > > Although, It may be only because I ran it through python 2.4.3 Ah yes, that's it: the 'x if b else y' syntax wasn't introduced until Python 2.5; see http://docs.python.org/dev/whatsnew/2.5.html#pep-308-conditional-expressions for more. Hmm. Maybe we shouldn't be using this syntax in from_float, if it's the only thing that prevents the trunk version of decimal.py from being used with Python 2.4. On the other hand, from_float isn't going to work until 2.7 anyway, since it uses a whole bunch of new stuff: as_integer_ratio and copysign (both introduced in 2.6), and bit_length (introduced in 2.7). Mark From bj_666 at gmx.net Sun Jan 4 06:10:05 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 4 Jan 2009 11:10:05 GMT Subject: Take the first n items of an iterator References: <01708c76$0$8693$c3e8da3@news.astraweb.com> Message-ID: <6sbjodF51cmkU2@mid.uni-berlin.de> On Sun, 04 Jan 2009 10:55:17 +0000, Steven D'Aprano wrote: > I thought there was an iterator in itertools for taking the first n > items of an iterator, then halting, but I can't find it. Did I imagine > such a tool, or am I missing something? `itertools.islice()` Ciao, Marc 'BlackJack' Rintsch From Ron.Barak at lsi.com Sun Jan 4 06:25:18 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 4 Jan 2009 11:25:18 +0000 Subject: How to find the beginning of last line of a big text file ? In-Reply-To: <495D0582.4010002@tim.thechases.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494844@enbmail01.lsi.com> <9e2f512b0901010854y788d2312o1745207979b47537@mail.gmail.com> <495D0582.4010002@tim.thechases.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494880@enbmail01.lsi.com> Hi Tim, Thanks for the solution (and effort), and for teaching me some interesting new tricks. Happy 2009! Ron. -----Original Message----- From: Tim Chase [mailto:python.list at tim.thechases.com] Sent: Thursday, January 01, 2009 20:04 To: Sebastian Bassi Cc: python-list at python.org Subject: Re: How to find the beginning of last line of a big text file ? Sebastian Bassi wrote: > On Thu, Jan 1, 2009 at 2:19 PM, Barak, Ron wrote: >> I have a very big text file: I need to find the place where the last >> line begins (namely, the offset of the one-before-the-last '\n' + 1). >> Could you suggest a way to do that without getting all the file into >> memory (as I said, it's a big file), or heaving to readline() all lines (ditto) ? > > for line in open(filename): > lastline = line > print "the lastline is: %s",%lastline > > This will read all the lines, but line by line, so you will never have > the whole file in memory. > There may be more eficient ways to do this, like using the itertools. I think the OP wanted to do it without having to touch each line in the file. The following should do the trick, returning both the offset in the file, and that last line's content. from os import stat def last_line(fname, estimated_line_size=1024): assert estimated_line_size > 0 file_size = stat(fname).st_size if not file_size: return 0, "" f = file(fname, 'rb') f.seek(-1, 2) # grab the last character if f.read(1) == '\n': # a "proper" text file file_size -= 1 offset = file_size content = "" while offset >= 0 and '\n' not in content: offset -= estimated_line_size if offset < 0: estimated_line_size += offset # back it off offset = 0 f.seek(offset) block = f.read(estimated_line_size) content = block + content f.close() loc = content.rfind('\n') + 1 # after the newline return offset + loc, content[loc:] offset, line = last_line('some_file.txt') print "[%r] was found at offset %i" % (line, offset) In theory, it should even handle "malformed" text-files that don't end in a newline. There might be some odd edge-cases that I missed, but I think I caught most of them. -tkc From hubaghdadi at gmail.com Sun Jan 4 06:35:37 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Sun, 4 Jan 2009 03:35:37 -0800 (PST) Subject: Code coverage to Python code Message-ID: Hey, What is the best code coverage tool available for Python? Thanks. From hsoft at hardcoded.net Sun Jan 4 06:59:21 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Sun, 4 Jan 2009 03:59:21 -0800 (PST) Subject: Memoizing and WeakValueDictionary References: <482f1e7f-52a7-4c7f-819b-59faeb4e203e@e10g2000vbe.googlegroups.com> Message-ID: <94857225-f2b3-44f6-8f7d-a1391eb05540@v4g2000vbb.googlegroups.com> On Jan 4, 5:55?am, Paul McGuire wrote: > Just wanted to share some experience I had in doing some memory and > performance tuning of a graphics script. ?I've been running some long- > running scripts on high-resolution images, and added memoizing to > optimize/minimize object creation (my objects are immutable, so better > to reuse objects from a cache than constantly create and discard > instances). ?This helped my script early on, but as the data files got > larger and larger, and runs got longer and longer, the object memoize > cache started to suck up some serious memory, and performance started > to degrade for a different reason - low memory -> page thrashing -> > program crawling. > > It occurred to me that in my program, a given object may get used for > a while, but once its use declines, it doesn't come back for a while. > At first blush, I thought about using some sort of LRU cache, but > first I tried the WeakValueDictionary from the wkref module. ?This > worked great! > > Now I get fairly optimal reuse of my immutable instances, but my > object cache doesn't grow without bounds. > > Does this sound like a correct interpretation of this behavior? ?If > so, it would seem that WeakValueDictionary would be a good > recommendation to go along with any memoizing implementations. It depends on what you use memoizing for. If your memoized function return data from a dataset, then yeah, you want to use a weakref scheme because when such data is removed from the dataset, you want the memory associated to it to be freed. However, if you use memoizing on a function that creates the return value, you don't want to use a weakref scheme, because it makes the memoizing useless: If the caller of the memoized function doesn't keep a reference to the returned value, there will be no memoizing taking place for the next call of the function with the same arguments. To make it short: it depends. From skip at pobox.com Sun Jan 4 07:06:59 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 06:06:59 -0600 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: <18784.42595.41923.729353@montanaro.dyndns.org> Hussein> What is the best code coverage tool available for Python? Probably Ned Batchelders coverage.py. There is a trace.py module which comes with Python as well. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From aleksandr.goretoy at gmail.com Sun Jan 4 07:20:27 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 12:20:27 +0000 Subject: deleting a method In-Reply-To: <87r63jjs6e.fsf@benfinney.id.au> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <87zli8j9li.fsf@benfinney.id.au> <87r63jjs6e.fsf@benfinney.id.au> Message-ID: HAHAHAHA, I like your sig Ben. So much that I blogged about it. starnixalpha.blogspot.com Oh yeah, and the info on this thread was helpful. Thanks, -A ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? On Sun, Jan 4, 2009 at 10:12 AM, Ben Finney < bignose+hates-spam at benfinney.id.au >wrote: > "Filip Gruszczy?ski" writes: > > > Thanks, now I see, what happens, but don't exactly know why. Could > > you point me to some good explanation how object creation is > > performed in Python? > > Rather than "how object creation is performed", I would recommend > you get a better handle on how the object *model* works in Python. > > If you haven't yet, please work through all of the Python Tutorial > . Read each part, experiment > with code until you understand what is presented, and only *then* move > on to the next section. > > For theoretical explanations, the effbot's "Python Objects" article > is also recommended. > > Before theory though, use the Tutorial for concrete demonstrations > coming from your very fingers. > > -- > \ "? a Microsoft Certified System Engineer is to information | > `\ technology as a McDonalds Certified Food Specialist is to the | > _o__) culinary arts." ?Michael Bacarella | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Sun Jan 4 07:25:58 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 12:25:58 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <01700ab5$0$8693$c3e8da3@news.astraweb.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: My gmail did that. FYI, it wasn't intentional. ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? Paula Poundstone - "I don't have a bank account because I don't know my mother's maiden name." On Sun, Jan 4, 2009 at 1:41 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 03 Jan 2009 16:19:58 +0100, Bruno Desthuilliers wrote: > > > But indeed, you obviously cannot add strings with numerics nor > > concatenate numerics with strings. This would make no sense. > > The OP comes from a Perl background, which AFAIK allows you to concat > numbers to strings and add strings to numbers. That's probably the (mis) > feature he was hoping Python had. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wim76 at care2.com Sun Jan 4 07:56:51 2009 From: wim76 at care2.com (Morgul Banner Bearer) Date: Sun, 4 Jan 2009 04:56:51 -0800 (PST) Subject: Using PythonPath under Windows Vista. Message-ID: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Hi Everybody, I was using the O'Reilly book from 1999 to look into Python and ran into a problem with the use of Pythonpath. I have Python installed under c:\python26. I have the module "Brian.py" that i want to run installed under c \python26\work In Windows Vista, I have set an environment variable "Pythonpath" equal to c:\python26\work (by using the "My computer", "Properties", "Advanced", "Environment Variables". The behaviour of the program is as follows : In a Dos Box, the program executes nicely when i type : "c\python26>python c:\python26\work\brian.py". Now i understand that- because I set the Pythonpath- the program should also run if i type: "c\python26>python brian.py" (under these conditions Python should look for the file brian.py in the folders specified in the Pythonpath). However, this does not work, but gives : "Can't open file... No such file or directory". I have not found further info availlable on bulletin boards on the internet, so if anybody can post the solution here, that would help me out. Thanks, wim76. From steve at holdenweb.com Sun Jan 4 08:29:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:29:50 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <495e814d$0$3502$426a34cc@news.free.fr> Message-ID: Wolfgang Strobl wrote: > Derek Martin : > >> It took me about a half a second to grasp the "named bins" concept -- >> i.e. as soon as I was finished reading the words that explained it I >> understood it, so I'd say that based on your half-hour number, >> Python's model is substantially more complicated. > > I don't think so. Personally, I started programming by punching Fortran > IV statements into an IBM 26, submitting them as a batch job to an IBM > 7090, so the "named bins" concept is quite heavily engraved into my > brain. :-) But it didn't take me long to grasp (and enjoy!) the much > more advanced concept of variable bindings in SNOBOL4, which is similar > to Pythons, but predates Python quite some time. > > Quoting > > http://burks.bton.ac.uk/burks/language/snobol/catspaw/manual/ch6.htm > > Chapter 6 : DATA TYPES AND CONVERSION > > Most other programming languages require the user to explicitly declare > the type of data to be stored in a variable. In SNOBOL4, any variable > may contain any data type. Furthermore, the variable's type may be > freely altered during program execution. SNOBOL4 remembers what kind of > data is in each variable. > [...] > > C:\e\spitbol>spitbol test.spt > SPITBOL-386 Release 3.7(ver 1.30.16) Serial 20158 > (c) Copyright 1987-1997 Robert B. K. Dewar and Catspaw, Inc. > Snobol/Spitbol Beispiel [...] > Thanks for the memories. I developed the DECSystem-10 Spitbol implementation. I had no idea support of the language continued up to 1997, as I switched to Icon when Griswold produced that and found it a far superior language. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bockman at virgilio.it Sun Jan 4 08:34:38 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 04 Jan 2009 14:34:38 +0100 Subject: Using PythonPath under Windows Vista. References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: On Sun, 04 Jan 2009 04:56:51 -0800, Morgul Banner Bearer wrote: > Hi Everybody, > ... > > > The behaviour of the program is as follows : > In a Dos Box, the program executes nicely when i type : > "c\python26>python c:\python26\work\brian.py". > > Now i understand that- because I set the Pythonpath- the program > should also run if i type: > "c\python26>python brian.py" > (under these conditions Python should look for the file brian.py in > the folders specified in the > Pythonpath). However, this does not work, but gives : "Can't open > file... No such file or directory". > > I have not found further info availlable on bulletin boards on the > internet, so if anybody can post > the solution here, that would help me out. > AFAIK, PYTHONPATH only works for the imported modules. For the main module, you have to do give the full path. OR you could try out the new flag -m, which allows to run directly a module from the standard library and - I guess - also user modules if PYTHONPATH is set correcltly. So try from a "DOS Box" the command: "c\python26>python -m brian.py" Ciao --- FB From andrew at monkeysailor.co.uk Sun Jan 4 08:36:38 2009 From: andrew at monkeysailor.co.uk (Andrew Lewis) Date: Sun, 4 Jan 2009 13:36:38 +0000 Subject: Using PythonPath under Windows Vista. In-Reply-To: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: > In Windows Vista, I have set an environment variable "Pythonpath" > equal to c:\python26\work > (by using the "My computer", "Properties", "Advanced", "Environment > Variables". I always thought pythonpath was only for imports, try adding the location to the regular path variable. Andrew From steve at holdenweb.com Sun Jan 4 08:46:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:46:06 -0500 Subject: deleting a method In-Reply-To: <49608AD7.7050704@gmail.com> References: <1be78d220901031421i60607d9ckab4eebdcccbad83a@mail.gmail.com> <49608AD7.7050704@gmail.com> Message-ID: Manish Sinha wrote: > Filip Gruszczy?ski wrote: >> I am trying to delete a method from a class. It's easy to delete other >> attributes, but when I try: >> >> >>>>> class A: >>>>> >> ... def foo(): >> ... pass >> ... >> >>>>> a = A() >>>>> del a.foo >>>>> >> >> I get >> >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: A instance has no attribute 'foo' >> >> Why is it so and how may still delete it? >> >> > Sounds crazy.... > > If you want to delete a function, create lambda functions though am not > sure whether it can be deleted or not. > In what sense are lambda functions any more or less "deletable" than functions or methods created using the "def" statement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 4 08:55:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 08:55:52 -0500 Subject: Using PythonPath under Windows Vista. In-Reply-To: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: Morgul Banner Bearer wrote: > Hi Everybody, > > I was using the O'Reilly book from 1999 to look into Python and ran > into a problem with > the use of Pythonpath. > > I have Python installed under c:\python26. > I have the module "Brian.py" that i want to run installed under c > \python26\work > > In Windows Vista, I have set an environment variable "Pythonpath" > equal to c:\python26\work > (by using the "My computer", "Properties", "Advanced", "Environment > Variables". > > The behaviour of the program is as follows : > In a Dos Box, the program executes nicely when i type : > "c\python26>python c:\python26\work\brian.py". > > Now i understand that- because I set the Pythonpath- the program > should also run if i type: > "c\python26>python brian.py" > (under these conditions Python should look for the file brian.py in > the folders specified in the > Pythonpath). However, this does not work, but gives : "Can't open > file... No such file or directory". > The PYTHONPATH variable is used by the interpreter to augment the set of locations to search for *imported* modules. It isn't used in locating the script from the command line. However, you might find that your installation has set .py up to be executed by the Python interpreter using the pathext mechanism, in which case you can just give the script's name and it will be found if it's somewwhere on your PATH (not your PYTHONPATH). > I have not found further info availlable on bulletin boards on the > internet, so if anybody can post > the solution here, that would help me out. > Well, you could have tried the FAQ, but I don't know off the top of my head whether that explains things. [Pauses to re-read http://www.python.org/doc/faq/windows/]. Well, some useful things are covered there, but it doesn't answer your question. Since the -m option runs the code of a module you will probably find that python -m brian will do what you expect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 4 09:09:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 09:09:57 -0500 Subject: Using PythonPath under Windows Vista. In-Reply-To: References: <0ffe7494-61a1-4957-bb11-ce17e6cb0384@q26g2000prq.googlegroups.com> Message-ID: Francesco Bochicchio wrote: [...] > AFAIK, PYTHONPATH only works for the imported modules. For the main > module, you have to do give the full path. > OR you could try out the new flag -m, which allows to run directly a > module from the standard library and - I guess - also user modules if > PYTHONPATH is set correcltly. So try from a "DOS Box" the command: > > "c\python26>python -m brian.py" > Note that you need to give the *name* of the module to the -m option, so that should be brian, not brian.py. E.g.: $ python -m StringIO File length = 1001 First line = 'SYSTEM:*:18:544:,S-1-5-18::\n' Position = 28 Second line = 'LocalService:*:19:544:U-NT AUTHORITY\\LocalService,S-1-5-19::\n' Read 8 more lines File length = 1001 Truncated length = 500 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Sun Jan 4 09:49:42 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jan 2009 14:49:42 GMT Subject: Take the first n items of an iterator References: <01708c76$0$8693$c3e8da3@news.astraweb.com> <6sbjodF51cmkU2@mid.uni-berlin.de> Message-ID: <0170c364$0$8693$c3e8da3@news.astraweb.com> On Sun, 04 Jan 2009 11:10:05 +0000, Marc 'BlackJack' Rintsch wrote: > On Sun, 04 Jan 2009 10:55:17 +0000, Steven D'Aprano wrote: > >> I thought there was an iterator in itertools for taking the first n >> items of an iterator, then halting, but I can't find it. Did I imagine >> such a tool, or am I missing something? > > `itertools.islice()` Thanks Marc, time to check my glasses I think, I must have looked at that a dozen times and didn't draw the connection. -- Steven From roy at panix.com Sun Jan 4 10:08:01 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 07:08:01 -0800 (PST) Subject: Which SOAP module? Message-ID: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> I'm starting to play with SOAP. The zeroth question that needs answering is, "Which SOAP module should I use?" There seem to be a number of different ones to pick from. Any suggestions? From ralf at schoenian-online.de Sun Jan 4 10:41:40 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sun, 04 Jan 2009 16:41:40 +0100 Subject: Which SOAP module? In-Reply-To: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> Message-ID: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Roy Smith wrote: > I'm starting to play with SOAP. The zeroth question that needs > answering is, "Which SOAP module should I use?" There seem to be a > number of different ones to pick from. Any suggestions? > > It depends on whether you want to write a client or a server application. If you only want to write a client I found suds ( https://fedorahosted.org/suds/ ) very helpful. It is actively developed and the documentation is comprehensive. Well, for the server I think you have to rely on the ZSI (http://pywebsvcs.sourceforge.net/) project. In retrospect my first steps in this library were rather painful but som year ago it was the most sophisticated library. Regards, Ralf From roy at panix.com Sun Jan 4 11:09:06 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 08:09:06 -0800 (PST) Subject: Which SOAP module? References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <78be1000-73b7-47b1-be39-7a9da19f59e0@13g2000yql.googlegroups.com> On Jan 4, 10:41?am, Ralf Schoenian wrote: > It depends on whether you want to write a client or a server > application. At least for now, I'm only interesting in clients. From stefan_ml at behnel.de Sun Jan 4 11:10:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jan 2009 17:10:40 +0100 Subject: Which SOAP module? In-Reply-To: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4960df80$0$31334$9b4e6d93@newsspool4.arcor-online.net> Ralf Schoenian wrote: > Roy Smith wrote: >> I'm starting to play with SOAP. The zeroth question that needs >> answering is, "Which SOAP module should I use?" There seem to be a >> number of different ones to pick from. Any suggestions? > > for the server I think you > have to rely on the ZSI (http://pywebsvcs.sourceforge.net/) > project. In retrospect my first steps in this library were rather > painful but som year ago it was the most sophisticated library. Use soaplib (for client and/or server), it's a lot less painful. Stefan From hanser at club-internet.fr Sun Jan 4 11:49:18 2009 From: hanser at club-internet.fr (Pierre Hanser) Date: Sun, 04 Jan 2009 17:49:18 +0100 Subject: Which SOAP module? In-Reply-To: <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4960e88d$0$28676$7a628cd7@news.club-internet.fr> Ralf Schoenian a ?crit : > Roy Smith wrote: >> I'm starting to play with SOAP. The zeroth question that needs >> answering is, "Which SOAP module should I use?" There seem to be a >> number of different ones to pick from. Any suggestions? >> >> > It depends on whether you want to write a client or a server > application. If you only want to write a client I found suds ( > https://fedorahosted.org/suds/ ) very helpful. It is actively developed > and the documentation is comprehensive. +1 for suds From michael.p.yang at gmail.com Sun Jan 4 12:14:52 2009 From: michael.p.yang at gmail.com (Michael Yang) Date: Mon, 5 Jan 2009 01:14:52 +0800 Subject: some question about python2.6 and python3k Message-ID: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Hi,guys i am a new guy for python world,i have some question want to ask 1.should i learn about python2.6 or python3k?i heard of it has some difference from them 2.Do python3k has some good web framework(like web.py)? Thanks ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From clockworksaint at gmail.com Sun Jan 4 12:26:51 2009 From: clockworksaint at gmail.com (Weeble) Date: Sun, 4 Jan 2009 09:26:51 -0800 (PST) Subject: TKinter and multiprocessing in GNU/Linux/X Message-ID: I'm using the multiprocessing module in Python 2.6 to run a pygame application. When errors occur, I create a new Process with the multiprocessing module and have it display a TKinter dialog. The pygame application can carry on happily without waiting for the dialog. This works fine on Windows. However, I've just tried the same code on Linux, and the TKinter dialog never appears. The process is spawned - if I print from it then it still appears on the console, but it does not display any TKinter window. If I create a TKinter window in my main process it works okay. I have a feeling that on Linux the multiprocessing module is doing a fork and all of the subprocesses end up fighting over the same connection to the X-server, is this possible? If so, is there some way to get multiprocessing to create a more "independent" process like on Windows? Or is there some way to tell TKinter to create a new connection to the X-server? I posted this as a question on Stack Overflow already, and there I've included source code to demonstrate what I'm doing: http://stackoverflow.com/questions/410469/why-dont-tkinter-windows-appear-when-using-multiprocessing-on-linux From benjamin.kaplan at case.edu Sun Jan 4 12:36:50 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 4 Jan 2009 12:36:50 -0500 Subject: some question about python2.6 and python3k In-Reply-To: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: On Sun, Jan 4, 2009 at 12:14 PM, Michael Yang wrote: > Hi,guys > > i am a new guy for python world,i have some question want to ask > > 1.should i learn about python2.6 or python3k?i heard of it has some > difference from them > If you don't have to worry about external libraries, you should probably start using Py3k. If you need external libraries and they aren't ported yet, you should probably use Python 2.6. There aren't that many major differences and, when everything is ported to Python 3, you should be able to pick it up pretty quickly. > > 2.Do python3k has some good web framework(like web.py)? AFAIK, none of the major web frameworks have been ported to Python 3 *yet*. Python 3 just came out a month ago, and the differences are enough to cause some problems for these large projects. If you're trying to do web programming, you should probably stick with 2.6 for now. > > > > Thanks ! > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Sun Jan 4 12:46:40 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sun, 04 Jan 2009 18:46:40 +0100 Subject: Ideas to optimize this getitem/eval call? In-Reply-To: <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> Message-ID: <4960F600.8030909@wildenhain.de> mario wrote: > On Jan 3, 7:16 am, Steven D'Aprano cybersource.com.au> wrote: > >> I was about to make a comment about this being a security hole, > > Strange that you say this, as you are also implying that *all* the > widely-used templating systems for python are security holes... Well, > you would be right to say that of course ;-) Infact, evoque is really > one of the few (or even the only one?) that was conceived from the > start to support restricted evaluation. Thats is definitively not the case. There are at least 2 quite old template systems on top of a quite good restricted environment. Cheers Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From ken at seehart.com Sun Jan 4 13:04:48 2009 From: ken at seehart.com (Ken Seehart) Date: Sun, 04 Jan 2009 19:04:48 +0100 Subject: some question about python2.6 and python3k In-Reply-To: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: <4960FA40.2000702@seehart.com> Michael Yang wrote: > Hi,guys > > i am a new guy for python world,i have some question want to ask > > 1.should i learn about python2.6 or python3k?i heard of it has some > difference from them > . I think you should go directly to 3K to save your self the extra work of learning the differences. The main advantage of using 2.6 is compatibility with the past. People who have already developed major projects will use 2.6 for a while until they get around to converting (if ever). But if you are new to python, this advantage is not very relevant to you, so you should start with 3K. > 2.Do python3k has some good web framework(like web.py)? > I don't know whether web.py specifically works under python 3K, but it seems to be a fairly active project, so my uneducated guess is that it will soon if it doesn't already. In any case 3K has plenty of direct support for all web related things. > > Thanks ! > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From bdesth.quelquechose at free.quelquepart.fr Sun Jan 4 13:05:36 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 04 Jan 2009 19:05:36 +0100 Subject: some question about python2.6 and python3k In-Reply-To: References: <19c041970901040914l6bfe64fdn853e5825a96313c9@mail.gmail.com> Message-ID: <4961081e$0$3293$426a74cc@news.free.fr> Ken Seehart a ?crit : > Michael Yang wrote: >> Hi,guys >> >> i am a new guy for python world,i have some question want to ask >> >> 1.should i learn about python2.6 or python3k?i heard of it has some >> difference from them >> . > I think you should go directly to 3K to save your self the extra work of > learning the differences. That is, if you don't have any use for most major third-part lib. > The main advantage of using 2.6 is compatibility with the past. It's also compatibility with most third-part libs and with most existing tutorials and books. > People > who have already developed major projects will use 2.6 for a while until > they get around to converting (if ever). But if you are new to python, > this advantage is not very relevant to you, Unless you plan to work on any project relying on third-part libs... > so you should start with 3K. >> 2.Do python3k has some good web framework(like web.py)? >> > I don't know whether web.py specifically works under python 3K, but it > seems to be a fairly active project, so my uneducated guess is that it > will soon if it doesn't already. Django is also a "fairly active project", and it's by no mean py3k ready yet. Most major, active web frameworks will be ported to Py3k, but this will take some time. > In any case 3K has plenty of direct > support for all web related things. Sure, but this doesn't replace a full-blown framework. From kleefaj at gmail.com Sun Jan 4 13:14:29 2009 From: kleefaj at gmail.com (kleefaj) Date: Sun, 4 Jan 2009 10:14:29 -0800 (PST) Subject: IDLE spinning beach ball on OS X 10.3.9 Panther Message-ID: Greetings. I want to run IDLE on my iBook running Mac OS X 10.3.9 (Panther). Per the instructions on "Python on the Macintosh" [1], I downloaded and installed TclTkAqua [2], then downloaded and installed Universal- MacPython-2.4.3 [3]. Python launches in Terminal. The version shown is 2.4.3. When I launch IDLE (Applications/MacPython 2.4), a Console window and a *Python Shell* window open, and then I get the spinning beach ball. I have to Force Quit. Did I miss anything? How do I get this to work? Thanks, Jeff [1] http://www.python.org/download/mac/ [2] http://prdownloads.sourceforge.net/tcltkaqua/TclTkAqua-8.4.10.dmg?download [3] http://www.python.org/ftp/python/2.4.3/Universal-MacPython-2.4.3-2006-04-07.dmg From h at realh.co.uk Sun Jan 4 13:20:31 2009 From: h at realh.co.uk (Tony Houghton) Date: Sun, 4 Jan 2009 18:20:31 +0000 Subject: How to declare python ints in C extensions? Message-ID: <20090104182031.22dc6954@realh.co.uk> I want to write python wrappers for the Linux DVB API. The underlying structures and constants may change from time to time, and some of the constants are generated from macros, so I think it would be better to write the module in C rather than just copying the constants into pure python code and using python's ioctl and struct modules. The trouble is I can't find out how to define a simple python int variable/constant in a C extension. The docs only seem to tell you how to define functions/methods and new types. For example, where the kernel header dvb/frontend.h defines: typedef enum fe_type { FE_QPSK, FE_QAM, FE_OFDM, FE_ATSC } fe_type_t; I want to make them available as if there was a python module dvb/frontend.py containing: FE_QPSK = 0 FE_QAM = 1 FE_OFDM = 2 FE_ATSC = 3 but in real life the module would be dvb/frontendmodule.c. -- TH * http://www.realh.co.uk From saju.pillai at gmail.com Sun Jan 4 13:38:05 2009 From: saju.pillai at gmail.com (Saju Pillai) Date: Mon, 05 Jan 2009 00:08:05 +0530 Subject: How to declare python ints in C extensions? In-Reply-To: <20090104182031.22dc6954@realh.co.uk> References: <20090104182031.22dc6954@realh.co.uk> Message-ID: Tony Houghton wrote: > I want to write python wrappers for the Linux DVB API. The underlying > structures and constants may change from time to time, and some of the > constants are generated from macros, so I think it would be better to > write the module in C rather than just copying the constants into pure > python code and using python's ioctl and struct modules. > > The trouble is I can't find out how to define a simple python int > variable/constant in a C extension. The docs only seem to tell you how > to define functions/methods and new types. > > For example, where the kernel header dvb/frontend.h defines: > > typedef enum fe_type { > FE_QPSK, > FE_QAM, > FE_OFDM, > FE_ATSC > } fe_type_t; > > I want to make them available as if there was a python module > dvb/frontend.py containing: > > FE_QPSK = 0 > FE_QAM = 1 > FE_OFDM = 2 > FE_ATSC = 3 > > but in real life the module would be dvb/frontendmodule.c. > Create Python Int objects for each of these constants and set them into your module object's dictionary foo = PyInt_FromLong(1L); PyDict_SetItemString(PyModule_GetDict(your_module), "foo", foo); Py_DECREF(foo) srp -- http://saju.net.in From philip at semanchuk.com Sun Jan 4 13:46:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 4 Jan 2009 13:46:35 -0500 Subject: How to declare python ints in C extensions? In-Reply-To: <20090104182031.22dc6954@realh.co.uk> References: <20090104182031.22dc6954@realh.co.uk> Message-ID: On Jan 4, 2009, at 1:20 PM, Tony Houghton wrote: > I want to write python wrappers for the Linux DVB API. The underlying > structures and constants may change from time to time, and some of the > constants are generated from macros, so I think it would be better to > write the module in C rather than just copying the constants into pure > python code and using python's ioctl and struct modules. > > The trouble is I can't find out how to define a simple python int > variable/constant in a C extension. This works for me: PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); I've had to learn a lot about writing extensions from looking at the Python source code. Lots of valuable tricks to be learned there. HTH Philip From tommy.nordgren at comhem.se Sun Jan 4 14:16:57 2009 From: tommy.nordgren at comhem.se (Tommy Nordgren) Date: Sun, 4 Jan 2009 20:16:57 +0100 Subject: IDLE spinning beach ball on OS X 10.3.9 Panther In-Reply-To: References: Message-ID: <4C4C31F7-1ECC-407A-9100-6B541A2C8090@comhem.se> On Jan 4, 2009, at 7:14 PM, kleefaj wrote: > Greetings. > > I want to run IDLE on my iBook running Mac OS X 10.3.9 (Panther). > > Per the instructions on "Python on the Macintosh" [1], I downloaded > and installed TclTkAqua [2], then downloaded and installed Universal- > MacPython-2.4.3 [3]. > > Python launches in Terminal. The version shown is 2.4.3. > > When I launch IDLE (Applications/MacPython 2.4), a Console window and > a *Python Shell* window open, and then I get the spinning beach ball. > I have to Force Quit. > > Did I miss anything? How do I get this to work? > > Thanks, > Jeff > > [1] http://www.python.org/download/mac/ > [2] http://prdownloads.sourceforge.net/tcltkaqua/TclTkAqua-8.4.10.dmg?download > [3] http://www.python.org/ftp/python/2.4.3/Universal-MacPython-2.4.3-2006-04-07.dmg > -- > http://mail.python.org/mailman/listinfo/python-list That an app beach balls don't mean it's hung or crashed, but only that it does something time consuming on the main thread (the one that handles UI) ------------------------------------------------------ "Home is not where you are born, but where your heart finds peace" - Tommy Nordgren, "The dying old crone" tommy.nordgren at comhem.se From lutz at rmi.net Sun Jan 4 14:29:12 2009 From: lutz at rmi.net (Mark Lutz) Date: Sun, 4 Jan 2009 11:29:12 -0800 (PST) Subject: Python training in Colorado, January 27-30 Message-ID: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> Python author and trainer Mark Lutz will be teaching a 4-day Python class on January 27-30, in Longmont, Colorado. This is a public training session open to individual enrollments, and covers the same topics and hands-on lab work as the onsite sessions that Mark teaches. The class provides an in-depth introduction to both Python and its common applications, and parallels the instructor's popular Python books. For more information on this session, please visit its web page: http://home.earthlink.net/~python-training/2009-public-classes.htm For additional background on the class itself, see our home page: http://home.earthlink.net/~python-training Thanks for your interest, --Python Training Services From roy at panix.com Sun Jan 4 14:47:30 2009 From: roy at panix.com (Roy Smith) Date: Sun, 4 Jan 2009 11:47:30 -0800 (PST) Subject: pep-8 vs. external interfaces? Message-ID: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> I'm building a Python language wrapper to an network protocol which traditionally uses camelCase function names. I'm trying to make the new code pep-8 compliant, which means function names should be written this_way() instead of thisWay(). I've got a couple of choices open to me. I could convert all the protocol names to pep-8 style mechanically. This is not as much work as it seems; the lowest-level Python code is already machine generated from a tabular description of the protocol. It's about one more line of code to convert getLibraries() to get_libraries(). This will leave the result the cleanest from the Python point of view. It'll also make the Python binding look a little different from the C++, Java, Perl, etc, bindings. Or, I could draw a line in the sand and say, "If it's a protocol primitive, it stays as written. Otherwise, it's pep-8". That's a little uglier because it's not always obvious to the user exactly which names are protocol primitives and which are higher-level operations. I figure either way, somebody's going to complain that I did it wrong :-) I realize there's no single correct answer here. I'm seeking input from people who have faced this question before. Which way did you go? In retrospect, was it the right decision? From lists at cheimes.de Sun Jan 4 15:05:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 04 Jan 2009 21:05:14 +0100 Subject: How to declare python ints in C extensions? In-Reply-To: References: <20090104182031.22dc6954@realh.co.uk> Message-ID: Philip Semanchuk schrieb: > This works for me: > PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); > > I've had to learn a lot about writing extensions from looking at the > Python source code. Lots of valuable tricks to be learned there. This trick makes it even easier: #ifndef PyModule_AddIntMacro #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) #endif if (!PyModule_AddIntMacro(mod, O_CREAT)) return; Christian From boblatest at yahoo.com Sun Jan 4 15:18:09 2009 From: boblatest at yahoo.com (Robert Latest) Date: 4 Jan 2009 20:18:09 GMT Subject: Memory debugging tool for Python/C API? Message-ID: <6scjs1F4s2rjU1@mid.uni-berlin.de> Hello, extending Python in C ist just the coolest thing since sliced bread (and I'm particularly happy because I really had started to miss C when I did more and more things in Python). I've got one question though. Tha C/API documentation is not quite clear (to me, anyway) on what happens exactly to ressources between the C/Python side. One example is this: I wrote a function that assembles a string into a dynamically-allocated buffer, then creates a PyString from it which it returns to the Python side: PyObject *dyn_string(void) { char *buffer = malloc(20); PyObject *pystr; strcpy(buffer, "Hello, World"); pystr = PyString_FromString(buffer); free(buffer); return pystr; } This works, but I'm not sure if PyString...() really makes a new copy of the data (ellowing me to use free()), or if this will segfault one day. OTOH I wouldn't know how to safely dispose of the string data otherwise. Another example (all on the C side of things) is a function where I build a dictionary from a set of keys, putting PyNone into each value (Py_INCREF()ing PyNone each time). At another point some of the values are replaced by other PyObjects. At first I used PyDECREF() on each value before setting the new value, but that botched up the dictionary beyond repair. Without the PyDECREF() calls everything worked fine. Now to my actual question: Is there some sort of debugging tool that I could use to analyze my code to see if everything gets properly allocated and deallocated and if the reference counting works right? Thanks, robert From aleksandr.goretoy at gmail.com Sun Jan 4 15:19:15 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 20:19:15 +0000 Subject: Python training in Colorado, January 27-30 In-Reply-To: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> References: <399396b6-0cf5-416a-8c0b-cacc35bcd0a3@i18g2000prf.googlegroups.com> Message-ID: I'd be interested in attending if you make it to Tulsa,OK. Are your courses only in Colorado? -Alex Goretoy http://www.alexgoretoy.com On Sun, Jan 4, 2009 at 7:29 PM, Mark Lutz wrote: > Python author and trainer Mark Lutz will be teaching a 4-day > Python class on January 27-30, in Longmont, Colorado. > > This is a public training session open to individual enrollments, > and covers the same topics and hands-on lab work as the onsite > sessions that Mark teaches. The class provides an in-depth > introduction to both Python and its common applications, and > parallels the instructor's popular Python books. > > For more information on this session, please visit its web page: > > http://home.earthlink.net/~python-training/2009-public-classes.htm > > For additional background on the class itself, see our home page: > > http://home.earthlink.net/~python-training > > Thanks for your interest, > --Python Training Services > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexus at gmail.com Sun Jan 4 15:54:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 12:54:44 -0800 (PST) Subject: Python3 Message-ID: I wanted to try out new Python 3 on my system, so I did "make fullinstall" and now as promised it broke every single program there is that runs on my system that depends on Python. is there a way to undo that? I've tried re-installing Python 2, yet that didn't help me at all. From tmohr at s.netic.de Sun Jan 4 16:10:42 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 04 Jan 2009 22:10:42 +0100 Subject: Package / Module Hierarchy question Message-ID: Hi, in a package i use these files: module (dir) __init__.py submodule __init__.py qwe.py qwe.py defines a class that derives from a class defined in submodule (and by that in submodule/__init__.py. Is it possible somehow to write in qwe.py to import submodule (though __init__.py is in the same directory as qwe.py ? I'd like to keep the tests for qwe.py within qwe.py, the code that i want to execute when i directly execute qwe.py and then: if __name__ == '__main__': some_test_code() Or do i need to write an external test code? Thanks for any hints, Torsten. From skip at pobox.com Sun Jan 4 16:23:07 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 15:23:07 -0600 Subject: Python3 In-Reply-To: References: Message-ID: <18785.10427.762775.464617@montanaro.dyndns.org> alexus> I wanted to try out new Python 3 on my system, so I did "make alexus> fullinstall" and now as promised it broke every single program alexus> there is that runs on my system that depends on Python. alexus> is there a way to undo that? I've tried re-installing Python 2, alexus> yet that didn't help me at all. The install targets for Python 3 explicitly don't create a symlink named "python", so it's not obvious how you might have obliterated your Python 2 installation. You didn't provide any information about your environment (Windows? Linux? Mac? Was Python 2 provided by your OS vendor or installed by you?) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From naplanetu at gmail.com Sun Jan 4 16:30:15 2009 From: naplanetu at gmail.com (Taras Ivashchenko) Date: Mon, 5 Jan 2009 00:30:15 +0300 Subject: SSL certificate parsing? Message-ID: Hello, list! I use pyopenssl [0] for checking SSL certificates. And one of such checks is if given certificate is self-signed. I can do it using values of X509v3 extensions: the subject key identifier and the authority key id: X509v3 Subject Key Identifier: 0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 X509v3 Authority Key Identifier: keyid:0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 I read documentation of pyOpenSSL but I didn't find way how to grub this information from certificate using, for example, methods of X509 object. May be there is another way to parse SSL certificates? I will be glad to get ever text version of given SSL certificate :) [0] http://pyopenssl.sourceforge.net/ P.S. I already wrote to pyopenssl mailing list, but there is now answer there :( ????? ???????? (Taras Ivashchenko) -- "Software is like sex: it's better when it's free.", - Linus Torvalds. From alexus at gmail.com Sun Jan 4 16:39:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 13:39:44 -0800 (PST) Subject: Python3 References: Message-ID: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> On Jan 4, 4:23?pm, s... at pobox.com wrote: > ? ? alexus> I wanted to try out new Python 3 on my system, so I did "make > ? ? alexus> fullinstall" and now as promised it broke every single program > ? ? alexus> there is that runs on my system that depends on Python. > > ? ? alexus> is there a way to undo that? I've tried re-installing Python 2, > ? ? alexus> yet that didn't help me at all. > > The install targets for Python 3 explicitly don't create a symlink named > "python", so it's not obvious how you might have obliterated your Python 2 > installation. ?You didn't provide any information about your environment > (Windows? ?Linux? ?Mac? ?Was Python 2 provided by your OS vendor or > installed by you?) > > -- > Skip Montanaro - s... at pobox.com -http://smontanaro.dyndns.org/ sorry, for not providing all information at the first place, here it is: enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- p7 #6: Wed Dec 24 15:58:06 EST 2008 alexus at j.jothost.com:/usr/obj/ usr/src/sys/GENERIC i386 I installed both of Python 2 and Python 3 via source code (compile them myself) From skip at pobox.com Sun Jan 4 16:46:38 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Jan 2009 15:46:38 -0600 Subject: Python3 In-Reply-To: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> References: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> Message-ID: <18785.11838.976517.677454@montanaro.dyndns.org> alexus> enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- alexus> p7 #6: Wed Dec 24 15:58:06 EST 2008 alexus at j.jothost.com:/usr/obj/ alexus> usr/src/sys/GENERIC i386 alexus> I installed both of Python 2 and Python 3 via source code alexus> (compile them myself) Where was Python 2 installed? /usr/bin or /usr/local/bin or somewhere else? What was the --prefix arg to configure when building Python 3? S From aleksandr.goretoy at gmail.com Sun Jan 4 16:57:31 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 4 Jan 2009 21:57:31 +0000 Subject: Package / Module Hierarchy question In-Reply-To: References: Message-ID: You might try this in qwe.py import os,sys sys.path.append(os.getcwd()+"../") This will allow you to then import modules from module(dir). Hope this helps. OTOH, there maybe a better solution. -Alex Goretoy http://www.alexgoretoy.com On Sun, Jan 4, 2009 at 9:10 PM, Torsten Mohr wrote: > Hi, > > in a package i use these files: > > module (dir) > __init__.py > submodule > __init__.py > qwe.py > > > qwe.py defines a class that derives from a class defined in submodule (and > by that in submodule/__init__.py. > > Is it possible somehow to write in qwe.py to import submodule (though > __init__.py is in the same directory as qwe.py ? > > I'd like to keep the tests for qwe.py within qwe.py, the code that i want > to > execute when i directly execute qwe.py and then: > > if __name__ == '__main__': > some_test_code() > > > Or do i need to write an external test code? > > > Thanks for any hints, > Torsten. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexus at gmail.com Sun Jan 4 17:03:44 2009 From: alexus at gmail.com (alexus) Date: Sun, 4 Jan 2009 14:03:44 -0800 (PST) Subject: Python3 References: <558b476a-96f2-4b96-a4e6-dae256b92948@v39g2000pro.googlegroups.com> Message-ID: <9a4c7014-0b5a-41bf-b23b-ab202d75f158@g39g2000pri.googlegroups.com> On Jan 4, 4:46?pm, s... at pobox.com wrote: > ? ? alexus> enviroment: FreeBSD j.jothost.com 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE- > ? ? alexus> p7 #6: Wed Dec 24 15:58:06 EST 2008 ? ? ale... at j.jothost.com:/usr/obj/ > ? ? alexus> usr/src/sys/GENERIC ?i386 > > ? ? alexus> I installed both of Python 2 and Python 3 via source code > ? ? alexus> (compile them myself) > > Where was Python 2 installed? ?/usr/bin or /usr/local/bin or somewhere else? > What was the --prefix arg to configure when building Python 3? > > S both of them were default --prefix, so I assume --prefix=/usr/local/ su-3.2# whereis python python: /usr/local/bin/python /usr/ports/lang/python su-3.2# /usr/local/bin/python --version Python 2.6.1 su-3.2# it's shows like 2.6.1 is there, yet when I ran "trac-admin", I get su-3.2# trac-admin Traceback (most recent call last): File "/usr/local/bin/trac-admin", line 5, in from pkg_resources import load_entry_point ImportError: No module named pkg_resources su-3.2# From robert.kern at gmail.com Sun Jan 4 17:41:03 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 04 Jan 2009 17:41:03 -0500 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: Hussein B wrote: > Hey, > What is the best code coverage tool available for Python? I like Titus Brown's figleaf. http://darcs.idyll.org/~t/projects/figleaf/doc/ -- 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 prologic at shortcircuit.net.au Sun Jan 4 18:03:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 09:03:49 +1000 Subject: greenlets and how they can be used In-Reply-To: <495FB40A.9060606@gmx.net> References: <495FB40A.9060606@gmx.net> Message-ID: On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst wrote: > Back when I was still using Perl, there was - and still is, I guess - a really nice framework called POE, that allowed you to write event-driven state machines in a really easy and pleasant way. Under POE, EVERYTHING was an event. When writing a network server, each incoming client connection was an event, within a connection, each incoming piece of data was an event; when reading a file, each line fired an event (i.e. I/O was completely asynchronous); when querying a database, each result row would fire an event. What was even better, you could very easily plug GTK's or Tk's event loop into the whole mix and have GUI interactions fire events, too. > POE was one of the nicest software frameworks I have ever used, and I've been continuously frustrated by the lack of something like it in other languages such as Python or Ruby. It does exist :) It's called circuits. Or at least circuits is a framework that I develop and build which sounds very similar to POE in some ways :) cheers James From martin at v.loewis.de Sun Jan 4 18:05:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 05 Jan 2009 00:05:01 +0100 Subject: Memory debugging tool for Python/C API? In-Reply-To: <6scjs1F4s2rjU1@mid.uni-berlin.de> References: <6scjs1F4s2rjU1@mid.uni-berlin.de> Message-ID: <4961409d$0$22820$9b622d9e@news.freenet.de> > This works, but I'm not sure if PyString...() really makes a new copy of > the data (ellowing me to use free()) See the documentation: http://docs.python.org/c-api/string.html#PyString_FromString # Return a new string object with a *copy* of the string v as value > Another example (all on the C side of things) is a function where I > build a dictionary from a set of keys, putting PyNone into each value > (Py_INCREF()ing PyNone each time). Assuming you use PyDict_SetItem(String): you shouldn't INCREF Py_None; the SetItem will itself incref the value (and decref any old value that might be already stored under that key). The only exception where you, as a caller, have to INCREF is when the reference is documented as "stolen"; very few API functions steal references. > At another point some of the values > are replaced by other PyObjects. At first I used PyDECREF() on each > value before setting the new value, but that botched up the dictionary > beyond repair. Without the PyDECREF() calls everything worked fine. See above. > Now to my actual question: Is there some sort of debugging tool that I > could use to analyze my code to see if everything gets properly > allocated and deallocated and if the reference counting works right? You should compile Python in pydebug mode; this will perform some additional checks each time. In addition, you can look at sys.getrefcount repeatedly. If you create a test that allocates stuff and then releases it, then sys.getrefcount should be unchanged. If it does change, you might have a reference leak. Regards, Martin From h at realh.co.uk Sun Jan 4 18:47:29 2009 From: h at realh.co.uk (Tony Houghton) Date: Sun, 4 Jan 2009 23:47:29 +0000 Subject: How to declare python ints in C extensions? References: <20090104182031.22dc6954@realh.co.uk> Message-ID: <20090104234729.10c9ea77@realh.co.uk> On Sun, 04 Jan 2009 21:05:14 +0100 Christian Heimes wrote: > Philip Semanchuk schrieb: > > This works for me: > > PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); > > > > I've had to learn a lot about writing extensions from looking at the > > Python source code. Lots of valuable tricks to be learned there. Thanks, that's perfect. I see it is documented, but I didn't know where to look. > This trick makes it even easier: > > #ifndef PyModule_AddIntMacro > #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) > #endif Good idea, but I'm a lot more experienced with C in general than in interfacing it with python, so I already thought of it :-). -- TH * http://www.realh.co.uk From missive at hotmail.com Sun Jan 4 18:52:33 2009 From: missive at hotmail.com (Lee Harr) Date: Mon, 5 Jan 2009 04:22:33 +0430 Subject: [ANN] TZMud 0.8 Message-ID: TZMud is a Python MUD server. http://tzmud.googlecode.com/ A MUD is a text-based virtual environment accessed via telnet, or with a specialised MUD client. TZMud development is still in early stages, focusing on API and server stability. TZMud uses several high-quality Python libraries to facilitate rapid development: Twisted, ZODB, and Pyparsing. TZMud is released under GPLv3. Changes in TZMud-0.8: - web access to database - better cross-platform operation - added configuration file verifcation tool - more readable and natural messages and commands - improved handling of object attributes - Exit can now be subclassed and cloned - objects can now be invisible - objects can now have a weight - rudimentary plugin framework - more teleportation commands - more secure password storage - xyzzy - new items/ mobs/ exits: - ring of invisibility - traps - spawner - players only exit _________________________________________________________________ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/events.aspx From fakeaddress at nowhere.org Sun Jan 4 19:03:01 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 04 Jan 2009 16:03:01 -0800 Subject: Testing if an index is in a slice In-Reply-To: <01707dd1$0$8693$c3e8da3@news.astraweb.com> References: <20090101191226.5137adb6@Schlamber.localdomain> <01707dd1$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Here's a less verbose version which passes your test cases: > > def inslice(index, slc, len): > """Return True if index would be part of slice slc of a > sequence of length len, otherwise return False. > """ > start, stop, stride = slc.indices(len) > if stride < 0: > return (start >= index > stop) and ((start-index) % -stride == 0) > else: > return (start <= index < stop) and ((index-start) % stride == 0) > > > (Hint: help(slice) is your friend.) I should really think about abandoning my strategy of doing everything the hard way. -- --Bryan From tmohr at s.netic.de Sun Jan 4 19:17:57 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 05 Jan 2009 01:17:57 +0100 Subject: structuring a package? Message-ID: Hi, i have a question on how to structure a package best, would be great if anybody could give me some hint on this: Assuming i have a base class GraphicObject and derived from that some classes like Square, Circle, ... It looks natural to me to write in a code that uses the package: import graphic import graphic.square import graphic.circle That way i'd have to structure the code like this: graphic/ __init__,py (GraphicObject) square.py (Square) circle.py (Circle) Does that make sense like this? Are there better ways to structure things in Python? One thing that bothers me is that when i write in circly.py something like "import graphic", then i can't have the test code for the Circle within circle.py, at least it looks to me like this. The closest thing that handles this issue that i could find was PEP 328, but it doesn't cover this problem. Thanks for any hints, Torsten. From prologic at shortcircuit.net.au Sun Jan 4 19:27:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 10:27:37 +1000 Subject: structuring a package? In-Reply-To: References: Message-ID: On Mon, Jan 5, 2009 at 10:17 AM, Torsten Mohr wrote: > It looks natural to me to write in a code that uses the package: > > import graphic > import graphic.square > import graphic.circle > > That way i'd have to structure the code like this: > > graphic/ > __init__,py (GraphicObject) > square.py (Square) > circle.py (Circle) > > Does that make sense like this? This seems perfectly acceptable. cheers James From Scott.Daniels at Acm.Org Sun Jan 4 19:28:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 04 Jan 2009 16:28:06 -0800 Subject: Reverse order of bit in repeating seqence of byte string In-Reply-To: <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> References: <58bb12df-259a-48a9-b807-48a6c4841901@q30g2000prq.googlegroups.com> <318b5f5d-43f9-4b6e-8058-b216f7375b09@a12g2000pro.googlegroups.com> <572dcc55-3385-4540-8db5-b06ad158d2df@o4g2000pra.googlegroups.com> Message-ID: imageguy wrote: > On Jan 2, 7:33 pm, John Machin wrote: >> For some very strange definition of "works".... > > Well that's embarrassing ... you are correct. I need to convert from > 'bgr' to 'rgb' If that is the only issue: >>> import Image >>> p = Image.open('~/VPython.png') >>> r, g, b = p.split() >>> q = Image.merge('RGB', [b, r, g]) >>> q.save('~/VPython1.png') Should be plenty fast. Read the PIL docs before rolling your own solutions. --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Sun Jan 4 20:22:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 4 Jan 2009 17:22:00 -0800 (PST) Subject: pep-8 vs. external interfaces? References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> Message-ID: <27c6b149-3a5f-478d-a6fc-da87a66b9d4c@r36g2000prf.googlegroups.com> On Jan 4, 1:47?pm, Roy Smith wrote: > Or, I could draw a line in the sand and say, "If it's a protocol > primitive, it stays as written. ?Otherwise, it's pep-8". ?That's a > little uglier because it's not always obvious to the user exactly > which names are protocol primitives and which are higher-level > operations. So the question becomes, "Why are you mixing protocol primitives and high-level operations in the same namespace?" Because that's not normally a well-advised thing to do. 1. If you answered, "I shouldn't be", you should separate them and use camel case for the protocol primitives. 2. If you answered, "I'm including protocol primitive functions alongside high-level operations because conceptually they are the same, it's just that some functions happen to map directly to the underlying protocol", you should follow PEP-8, because by doing that you've implicity raised the protocol primitive functions to high-level status. 3. If you answered, "Protocol primitives are in the same namespace for convenience, but high-level users shouldn't use them", then you should use camel case for the protocol primitives but prepend an underscore. 4. If you answered, "I include those functions in the same namespace because I am following the example of other language bindings in Perl, Java, Ruby, etc.,", then figure out whether it's important to be consistent with Perl, Java, Ruby, etc., and if so, do whatever they did. If not, see #1. Carl Banks From code at pizzashack.org Sun Jan 4 21:03:11 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 20:03:11 -0600 Subject: why cannot assign to function call In-Reply-To: <6s8s6nF4op56U2@mid.uni-berlin.de> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <20090105020311.GP28417@dragontoe.org> On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that its > > assignment model is BIZARRE, as in it's conceptually different from > > virtually all other languages substantially taught in undergraduate > > computer science programs. > > What's the difference between Python and Java or C# here!? Or are they > also "BIZARRE"!? I am happily ignorant of C#. As for Java, take the following code: a = 6; a = 5; In Python, when you execute the equivalent code, it causes two different objects to spring into existence, the first of which may be cleaned up by the GC (except that since we're using small integers, that's not likely to happen). Unless I'm misinformed (which is very possible, my experience with Java has been extremely limited) in Java that's not the case... the storage is allocated to the name a when you execute its declaration, and the *same storage* is reused upon subsequent assignment. That behaves exactly like named bins. > > And for that matter, it's pretty unintuitive generally. > > Names and objects are quite "natural" IMHO. There are many real world > objects which we attach one or more names to, or refer to in sequences > like "please give me the third book on that shelve" (``shelve[2]``). Indeed, but the way we assign names to them does not behave as it does in Python. Nor does Python's assignment work like it does in algebra, or anywhere else the Python student is particularly likely to have seen variable assignment before encountering it in Python. Let's define intuitive, shall we? From dictionary.com (choosing the definition which most easily makes my point): intuitive: adj. capable of being perceived or known by intuition. I'm going to go out on a limb and assert that there's NO POSSIBLE WAY a student could intuit Python's variable assignment behavior, having never been exposed to that same behavior prior. It needs to be taught. > > That is, in what I'll call "normal" computer languages, a variable name > > is thought of as the address of a bin where some data is stored, and the > > name is inexorably tied to that bin. > > You just call that "normal" or "intuitive" because that's what you > learned first. In a sense, yes... but isn't that what intuition really is? You can figure something out whithout being told how it works... That's either because it's immediately obvious from observing it, or it behaves like something you've seen before. That is what intitive is. > I think the "bin model" is more complex because you don't just have a > name and an object but always that indirection of the "bin". I cheerfully disagree. :) "Named bins" is essentially how algebra works, and how several generations of computer languages, not to mention the actual machine language those generated, behaved, before the current crop. Those interpretations came first, because, much as in the evolution of any other science, that was the model which was most intuitive or easily explained. But you need not take my word for it. Simply read the archives and see for yourself how much confusion this has caused on this list. [Please include the closely related behavior of parameter passing in your search.] -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From cjlesh at gmail.com Sun Jan 4 21:06:44 2009 From: cjlesh at gmail.com (cjl) Date: Sun, 4 Jan 2009 18:06:44 -0800 (PST) Subject: Windows Python install vs. MSI extract question Message-ID: OK -- this might be a strange question. If I do a 'full' install of Python on Windows XP, the result is a directory 'C:\Python25'. Depending on whether I install for all users or just me, the 'python25.dll' might end up in 'C:\Python25', or in the Windows system directory. If I copy python25.dll to the 'C: \Python25' directory, I now should have everything that Python installs all in on spot, correct? Now, if I download the Python installer, create an empty directory 'C: \python' and type the following at the command prompt: msiexec /a python-2.5.4.msi /qb TARGETDIR=C:\python Is there any difference between the folder that resulted from running the installer and the folder that resulted from extracting the MSI? I put together a portable version of Django (www.instantdjango.com), and want to experiment with multiple versions of Python on Windows without running the installer. Besides the changes to the registry and environment variable, am I missing anything when I extract the MSI? Thanks in advance, cjlesh From code at pizzashack.org Sun Jan 4 21:07:51 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 20:07:51 -0600 Subject: why cannot assign to function call In-Reply-To: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <20090105020751.GQ28417@dragontoe.org> On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: > > Or are they also "BIZARRE"!? > > One presumes that Mr. Martin finds anything different from his > first computer language to be BIZARRE. He should try out > Prolog or something genuinely different. One's presumption would be mistaken. However thank you for illustrating my point so precisely, which was after all the condescending and insulting way people "communicate" with people whom (they think) know less than they do in this forum, and not actually how difficult or easy the assignment model of Python is to understand. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From roy at panix.com Sun Jan 4 21:26:05 2009 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jan 2009 21:26:05 -0500 Subject: Code coverage to Python code References: Message-ID: In article , Robert Kern wrote: > Hussein B wrote: > > Hey, > > What is the best code coverage tool available for Python? > > I like Titus Brown's figleaf. > > http://darcs.idyll.org/~t/projects/figleaf/doc/ I was playing with Ned Batchelder's coverage.py module today. Once I stopped screwing around trying to get the "easy install" stuff to work and just copied the danged .py file to my site-packages directory, I was up and running in a few minutes. I suppose there's a lot of bells and whistles you could add, but it ran my code and told me which lines had executed and which hadn't. That pretty much seems like what you want a code coverage tool to do. http://nedbatchelder.com/code/modules/coverage.html From steve at holdenweb.com Sun Jan 4 21:30:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 04 Jan 2009 21:30:20 -0500 Subject: why cannot assign to function call In-Reply-To: <20090105020311.GP28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: >> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: >> >>> On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: >>> What the Python community often overlooks, when this discussion again >>> rears its ugly head (as it seems to every other hour or so), is that its >>> assignment model is BIZARRE, as in it's conceptually different from >>> virtually all other languages substantially taught in undergraduate >>> computer science programs. >> What's the difference between Python and Java or C# here!? Or are they >> also "BIZARRE"!? > > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two > different objects to spring into existence, the first of which may be > cleaned up by the GC (except that since we're using small integers, > that's not likely to happen). Unless I'm misinformed (which is very > possible, my experience with Java has been extremely limited) in Java > that's not the case... the storage is allocated to the name a when > you execute its declaration, and the *same storage* is reused upon > subsequent assignment. > > That behaves exactly like named bins. > Ah, but if the right-hand-side expressions had been Integers rather than integers, things would have been different, no? The point is that once values become complex types it's convenient not to copy them each time they are required. but I needn't flog this particular dead horse as you clearly do understand Python's assignment semantics. >>> And for that matter, it's pretty unintuitive generally. >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. Nor does Python's assignment work like it does in algebra, > or anywhere else the Python student is particularly likely to have > seen variable assignment before encountering it in Python. Let's > define intuitive, shall we? From dictionary.com (choosing the > definition which most easily makes my point): > Algebra contains no assignments. > intuitive: adj. capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > a student could intuit Python's variable assignment behavior, having > never been exposed to that same behavior prior. It needs to be > taught. > As does assignment of any kind. You can't argue that one semantic or another is more intuitive without offering evidence. >>> That is, in what I'll call "normal" computer languages, a variable name >>> is thought of as the address of a bin where some data is stored, and the >>> name is inexorably tied to that bin. >> You just call that "normal" or "intuitive" because that's what you >> learned first. > > In a sense, yes... but isn't that what intuition really is? You can > figure something out whithout being told how it works... That's > either because it's immediately obvious from observing it, or it > behaves like something you've seen before. That is what intitive is. > >> I think the "bin model" is more complex because you don't just have a >> name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, and how several generations of computer languages, not to > mention the actual machine language those generated, behaved, before > the current crop. Those interpretations came first, because, much as > in the evolution of any other science, that was the model which was > most intuitive or easily explained. > You're perhaps familiar with some algebra that I didn't study. In algebra and number theory identity and equality are equivalent. This is far from the case in programming languages, so any analogy based on it is specious to some degree. Programming isn't mathematics (except perhaps for functional programming). > But you need not take my word for it. Simply read the archives and > see for yourself how much confusion this has caused on this list. > [Please include the closely related behavior of parameter passing in > your search.] > It's difficult to think of a single aspect of Python that doesn't cause confusion in a typical year. The confusion is sometimes caused by ill-informed comment. While well-informed, you appear to feel that everyone else should share your idea of what's intuitive and what's BIZARRE. Before extending this thread too long please ruminate on the recent parameter-passing thread, of which you are clearly aware. Let's try and create light rather than heat. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dstanek at dstanek.com Sun Jan 4 22:20:44 2009 From: dstanek at dstanek.com (David Stanek) Date: Sun, 4 Jan 2009 22:20:44 -0500 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: On Sun, Jan 4, 2009 at 9:26 PM, Roy Smith wrote: > In article , > Robert Kern wrote: > >> Hussein B wrote: >> > Hey, >> > What is the best code coverage tool available for Python? >> >> I like Titus Brown's figleaf. >> >> http://darcs.idyll.org/~t/projects/figleaf/doc/ > > I was playing with Ned Batchelder's coverage.py module today. Once I > stopped screwing around trying to get the "easy install" stuff to work and > just copied the danged .py file to my site-packages directory, I was up and > running in a few minutes. > > I suppose there's a lot of bells and whistles you could add, but it ran my > code and told me which lines had executed and which hadn't. That pretty > much seems like what you want a code coverage tool to do. > > http://nedbatchelder.com/code/modules/coverage.html It will show lines as covered when they are executed by the interpreter. Class statements, function definitions, etc. can show up as executed. Are you seeing other code show up as covered? Recently I pushed a branch of an experimental project I am calling Barbarian[0]. It uses nose, figleaf and pylint to generate HTML for a project. A blog post with a more detailed description will be posted within a few days. [0] http://code.launchpad.net/~dstanek/+junk/Barbarian -- David http://www.traceback.org From prologic at shortcircuit.net.au Sun Jan 4 22:29:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 13:29:06 +1000 Subject: Code coverage to Python code In-Reply-To: References: Message-ID: On Sun, Jan 4, 2009 at 9:35 PM, Hussein B wrote: > What is the best code coverage tool available for Python? I like ot use nose with it's coverage plugin. easy_install nose easy_install co And I use the following in my top-level Makefile tests: @nosetests \ --with-coverage \ --cover-package=circuits \ --cover-erase \ --cover-inclusive \ --with-doctest cheers James From jsprad at gmail.com Sun Jan 4 22:47:33 2009 From: jsprad at gmail.com (sprad) Date: Sun, 4 Jan 2009 19:47:33 -0800 (PST) Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 3, 6:41?pm, Steven D'Aprano wrote: > The OP comes from a Perl background, which AFAIK allows you to concat > numbers to strings and add strings to numbers. That's probably the (mis) > feature he was hoping Python had. That's correct -- and that's been one of the more difficult parts of my transition. Learned C++ in college, spent a few years doing Perl, and now all of a sudden type matters again. It's a very different philosophy, but I'm determined to stick with it until I have an Aha! moment and find something I can do more easily than I can with Perl. From grante at visi.com Sun Jan 4 22:56:33 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 04 Jan 2009 21:56:33 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: On 2009-01-05, Derek Martin wrote: > On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: >> > Or are they also "BIZARRE"!? >> >> One presumes that Mr. Martin finds anything different from his >> first computer language to be BIZARRE. He should try out >> Prolog or something genuinely different. > > One's presumption would be mistaken. However thank you for > illustrating my point so precisely, which was after all the > condescending and insulting way people "communicate" with > people whom (they think) know less than they do in this forum, > and not actually how difficult or easy the assignment model of > Python is to understand. I'm sorry, but I really don't see how Python's assignment model could be considered bizarre by anybody who's familiar with more than one or two languages. It's actually somewhat common outside the world of FORTRAN/assembly/C/Pascal. The only thing about Python that ever struck me as odd was the semantic significance of whitespace (and that's not without precedents either). The significance of white-space changed very quickly from odd to brilliant. Among the languages I've known, Python is probably in the bottom 10% as far as bizarrness goes. Lisp/Scheme, Prolog, SNOBOL, COBOL, APL, Forth, Smalltalk and several now-forgotton almost-purely-functional languages all seemed to me orders of magnitude more bizarre than Python. I must admit that a some of those languages (e.g. Forth and Smalltalk) probably felt more "bizarre" due to their developement environment than due to the language itself. And then there is C++ which is bizarre only in the extent to which it's a complete dog's-breakfast. Back to work... -- Grant From roy at panix.com Sun Jan 4 23:03:26 2009 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jan 2009 23:03:26 -0500 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: In article , sprad wrote: > On Jan 3, 6:41?pm, Steven D'Aprano cybersource.com.au> wrote: > > The OP comes from a Perl background, which AFAIK allows you to concat > > numbers to strings and add strings to numbers. That's probably the (mis) > > feature he was hoping Python had. > > That's correct -- and that's been one of the more difficult parts of > my transition. Learned C++ in college, spent a few years doing Perl, > and now all of a sudden type matters again. It's a very different > philosophy, but I'm determined to stick with it until I have an Aha! > moment and find something I can do more easily than I can with Perl. The Aha! moment comes 6 months from now, when you discover that you can understand the Python code you wrote 6 months ago, but the Perl code you wrote at the same time has become gibberish, even to you. The other day, I came upon this gem. It's a bit of perl embedded in a Makefile; this makes it even more gnarly because all the $'s get doubled to hide them from make: define absmondir $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print \\\$$1}"`; chomp($$prefix); \ ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! ); } \ ?? return unslash(undot(undotdot($$a))); }; \ sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; return($$_[0]); }; \ sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ sub undotdot ($$) { my $$in = $$_[0]; \ ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ print absmon("$(1)","$(2)"); \ ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? endef Barf-o-rama. I know what it's supposed to do, and I still can't figure it out. From prologic at shortcircuit.net.au Sun Jan 4 23:17:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 5 Jan 2009 14:17:06 +1000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jan 5, 2009 at 1:47 PM, sprad wrote: > On Jan 3, 6:41 pm, Steven D'Aprano cybersource.com.au> wrote: >> The OP comes from a Perl background, which AFAIK allows you to concat >> numbers to strings and add strings to numbers. That's probably the (mis) >> feature he was hoping Python had. I guess perl must have coercing for it's built-in types ? :) *shrugs* To be honest, doing such operations doesn't make much sense to me ... It's difficult to correctly understand what the following expression should evaluate to: >>> a = 2 >>> b = 3 >>> c = "foo" >>> a + b + c Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> "%d %d %s" % (a, b, c) '2 3 foo' >>> > That's correct -- and that's been one of the more difficult parts of > my transition. Learned C++ in college, spent a few years doing Perl, > and now all of a sudden type matters again. It's a very different > philosophy, but I'm determined to stick with it until I have an Aha! > moment and find something I can do more easily than I can with Perl. As mentioned string formatting is your friend :) cheers James From code at pizzashack.org Sun Jan 4 23:55:09 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 22:55:09 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <20090105045509.GR28417@dragontoe.org> On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > > a student could intuit Python's variable assignment behavior, having > > never been exposed to that same behavior prior. It needs to be > > taught. > > > As does assignment of any kind. I'm not sure that's true. Having taken algebra prior to learning Basic, I intuitively understood what this program would do when I executed it, the first time I saw the code, and before I read the explanation: 10 let x = 10 20 print x [Well, to be honest it's been a very long time since I've programmed in Pet BASIC, and the syntax may be wrong. The point is, just as I did then, I am positive that you intuitively understand what the above is intended to do, even if it is not valid BASIC syntax -- because if you did not, we would not be having this discussion.] > You can't argue that one semantic or another is more intuitive > without offering evidence. I think I have though, not that it matters, since that was never really my point. Python's assignment model requires more explanation than the traditional one, simply to state what it does. That alone is evidence (but not proof). I haven't proven it scientifically, and I'm not willing to jump through the necessary hoops (which would require a psychological study) to do so simply to win an argument on Usenet. It's not about winning... it's about illumination. ;-) > You're perhaps familiar with some algebra that I didn't study. Not unless you never studied it at all... ;-) > In algebra and number theory identity and equality are equivalent. Indeed. The point of bringing up algebra is that it provides a background against which someone might be very likely to intuit what variable assignment does in traditional programming languages -- at least accurately enough to use it effectively without needing to understand the underlying implementation and worry about any corner cases. It really doesn't need to be explained, unless the student has no prior background in either math or computers. In the case of passing parameters things unavoidably get hairy, but at least at the moment we're not discussing that, and also that has no analogous in (at least high school) mathematics (at least, that I can think of) or much of anywhere else from whence a student might draw any insights. As for there being no assignment in algebra, is that not really what variable substitution is? They have different names, but in my estimation they perform exactly the same function. You're assigning specific values to the variables in an expression so that you can solve for a constant... just like in a computer program. There is even an allocation of memory: it's in your brain. :D > This is far from the case in programming languages, so any analogy > based on it is specious to some degree. Programming isn't > mathematics (except perhaps for functional programming). I agree; but I wasn't making an analogy. I was pointing out (an extremely likely) basis for intuition. > It's difficult to think of a single aspect of Python that doesn't cause > confusion in a typical year. Surely some cause more than others... and surely some are more surprising than others. ;-) > The confusion is sometimes caused by ill-informed comment. While > well-informed, you appear to feel that everyone else should share > your idea of what's intuitive and what's BIZARRE. Alright, perhaps I exaggerated when I said bizarre, but I did explain exactly what I meant, and I believe that what I said in my explanation is at least arguably true. I stand by the idea that it's much less intuitive than the traditional assignment model, and despite your protestations of lack of proof, I'm pretty sure you agree. ;-) Ultimately, none of this really matters, as perhaps my point is that Python *is different* from what A LOT of folks learning it have already seen (if anything), and it's often easy for them to misunderstand the Python way. As you said, let's provide light, not heat, when we come across people who get confused between Python and something else. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From code at pizzashack.org Mon Jan 5 00:09:27 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 23:09:27 -0600 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <20090105050927.GS28417@dragontoe.org> On Sun, Jan 04, 2009 at 09:56:33PM -0600, Grant Edwards wrote: > On 2009-01-05, Derek Martin wrote: > > On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: > >> One presumes that Mr. Martin finds anything different from his > >> first computer language to be BIZARRE. He should try out > >> Prolog or something genuinely different. > > > > One's presumption would be mistaken. However thank you for > > illustrating my point so precisely, which was after all the > > condescending and insulting way people "communicate" with > > people whom (they think) know less than they do in this forum, > > and not actually how difficult or easy the assignment model of > > Python is to understand. > > I'm sorry, but I really don't see how Python's assignment model > could be considered bizarre by anybody who's familiar with more > than one or two languages. And... what if one wasn't? The OP of this thread clearly didn't understand... Whereas if you've read the thread, clearly I do. Of course, had you read my post, you probably would have understood that my comment about the model being bizarre was intended to be viewed from the perspective of someone who *had not* seen anything like it before, which is LOTS of relatively new programmers, whether or not it might be old hat to anyone here. The ultimate point of my post was not so much about whether the assignment model of Python was or wasn't easy to understand; it was about the idea that when someone doesn't understand, we should try to help them instead of making snide remarks about how stupid or small-minded they are. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From code at pizzashack.org Mon Jan 5 00:27:31 2009 From: code at pizzashack.org (Derek Martin) Date: Sun, 4 Jan 2009 23:27:31 -0600 Subject: why cannot assign to function call In-Reply-To: <20090105045509.GR28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> <20090105045509.GR28417@dragontoe.org> Message-ID: <20090105052731.GT28417@dragontoe.org> Forgive my indulgence, I find this rather academic discussion kind of interesting, as it turns out. On Sun, Jan 04, 2009 at 10:55:09PM -0600, Derek Martin wrote: > > You can't argue that one semantic or another is more intuitive > > without offering evidence. > > I think I have though, not that it matters, since that was never > really my point. Python's assignment model requires more explanation > than the traditional one, simply to state what it does. That alone is > evidence (but not proof). Here's (I think) a better argument, FWIW: The traditional model ties a name to some (usually predefined and static) storage (a memory address, or at least the start of a string of them). This is a very concrete thing to represent, and the conceptualization of variables as named bins in such languages captures this very succinctly, and requires no understanding of the underlying implementation for the programmer to use (at least with primitive data types, which are all that are used generally when variables are first introduced). The Python model binds a name to a particular Python object, which is itself an abstraction; understanding requires understanding first what an "object" is, and I think at least in some measure some knowledge about how Python is implemented (primitive data types are actually objects; and also recall the recent discussion about what constitutes a "value" in Python). The abstraction, and the requirement to partially understand the underlying implemenation, make the Python model inherently more complicated, and therefore also inherently less intuitive. That also is not proof, but as I said, real proof is rather hard to come by... And FWIW, remember that I never suggested that all this was without good reason, and I'm not attempting to advocate for simplifying the model. :) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aleksandr.goretoy at gmail.com Mon Jan 5 01:00:50 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 06:00:50 +0000 Subject: threading a 10 lines out of a file Message-ID: Hello All, I have a question. I'm not sure exactly as how to explain it in any other way then the way I will explain it. So I'm sorry if it's hard to understand exactly what it is I'm trying to do. Maybe not. Anyway. Here goes. Lets say I have a file that looks like this. id,name,desc,test 123,abc,testing is fun,yeah baby 456,qwe,python makes if funner, yeah baby 789,zxc,this is another line in this file, yeah baby ... ... This file can have an unknown amount of lines in it. It can be 700,400 or even 7,000. I do this to read the file: try: reader = csv.reader(file(filename, "rb")) try: header = reader.next() self.buffer = list(reader) # total = len(self.buffer) self.bufferp= [dict(zip(header,line)) for line in self.buffer] self.header = header #for row in reader: #self.buffer.append(row) #s,a=[],{} #for j in range(len(self.buffer[0])): #a[self.buffer[0][j]]=row[j] #self.bufferp.append(a) #i+=1 #self.total = i-1 except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) except IOError, e: sys.exit('file %s, IOError: %s' % (filename, e)) What I am currently doing is looping over this file, performing a function for every line. This function isbeing called from this class __init__(), def loop_lines(self): for k in range(len(self.buffer)): #for every line in csv file self.line=self.buffer[k] self.some_function(self.line) Now, for my question. Is it possible for me to thread this scenario somehow? So that I can set a variable that says how many lines to work on at the same time? lets say 10 lines at a time, once it finishes some it moves on to the next ones that are not in the thread pool or something to that nature. Always making sure that it works on 10 at the same time. How would I achieve something like this in my program? Can someone please recommend something for me. I would greatly appreciate. My program would appreciate it too, seeing as it will be multi-threaded :) Thank you for your help. -Alex Goretoy http://www.alexgoretoy.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From grante at visi.com Mon Jan 5 02:13:48 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 01:13:48 -0600 Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> Message-ID: <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> On 2009-01-05, Derek Martin wrote: >> I'm sorry, but I really don't see how Python's assignment >> model could be considered bizarre by anybody who's familiar >> with more than one or two languages. > > And... what if one wasn't? The OP of this thread clearly > didn't understand... Whereas if you've read the thread, > clearly I do. Of course, had you read my post, you probably > would have understood that my comment about the model being > bizarre was intended to be viewed from the perspective of > someone who *had not* seen anything like it before, X is bizarre because it is unfamiliar to anybody who has never seen X before? -- Grant From nospam at nospam.com Mon Jan 5 02:15:38 2009 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 05 Jan 2009 08:15:38 +0100 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' Message-ID: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Hello I successfully use the email package to send e-mail from Python scripts, but this script fails when I fetch addresses from an SQLite database where data is Unicode-encoded: ====== from email.MIMEText import MIMEText import smtplib,sys import apsw connection=apsw.Connection("test.sqlite") cursor=connection.cursor() subject = "My subject" f = open("message.txt", "r") message = f.read() f.close() msg = MIMEText(message) msg['Subject'] = subject >From = "me at acme.com" msg['From'] = From server = smtplib.SMTP("smtp.acme.com") sql="SELECT email FROM people WHERE email IS NOT NULL" rows=list(cursor.execute(sql)) for email in rows: To = email msg['To'] = email #print To #(u'dummy at acme.com',) #AttributeError: 'tuple' object has no attribute 'lstrip' #server.sendmail(From,[To],msg.as_string()) server.quit connection.close(True) ====== Does someone know what is wrong with the above? Does email choke on Unicode? Thank you. From aleksandr.goretoy at gmail.com Mon Jan 5 02:22:33 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 07:22:33 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: I've found a great example on how to do threads. It compares a ping program in regular for loop and with threaded for loop. The link is below if anyone is interested. http://www.wellho.net/solutions/python-python-threads-a-first-example.html I hope my eagerness to post doesn't annoy anyone. I like to get as much info from as many places as possible and compare. This way I think I may have a better solution for a problem. Plus people that Google will find this post or any words in it. Any more information on threading a for loop would be greatly appreciated. TIA -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:00 AM, alex goretoy wrote: > Hello All, > > I have a question. I'm not sure exactly as how to explain it in any other > way then the way I will explain it. So I'm sorry if it's hard to understand > exactly what it is I'm trying to do. Maybe not. Anyway. Here goes. > > Lets say I have a file that looks like this. > > id,name,desc,test > 123,abc,testing is fun,yeah baby > 456,qwe,python makes if funner, yeah baby > 789,zxc,this is another line in this file, yeah baby > ... > ... > > This file can have an unknown amount of lines in it. It can be 700,400 or > even 7,000. > I do this to read the file: > > try: > reader = csv.reader(file(filename, "rb")) > try: > header = reader.next() > self.buffer = list(reader) # total = len(self.buffer) > self.bufferp= [dict(zip(header,line)) for line in > self.buffer] > self.header = header > #for row in reader: > #self.buffer.append(row) > #s,a=[],{} > > #for j in range(len(self.buffer[0])): > #a[self.buffer[0][j]]=row[j] > #self.bufferp.append(a) > #i+=1 > #self.total = i-1 > except csv.Error, e: > sys.exit('file %s, line %d: %s' % (filename, > reader.line_num, e)) > except IOError, e: > sys.exit('file %s, IOError: %s' % (filename, e)) > > What I am currently doing is looping over this file, performing a function > for every line. This function isbeing called from this class __init__(), > > def loop_lines(self): > > for k in range(len(self.buffer)): #for every line in csv file > self.line=self.buffer[k] > self.some_function(self.line) > > > Now, for my question. Is it possible for me to thread this scenario > somehow? > > So that I can set a variable that says how many lines to work on at the > same time? > > lets say 10 lines at a time, once it finishes some it moves on to the next > ones that are not in the thread pool or something to that nature. Always > making sure that it works on 10 at the same time. > > How would I achieve something like this in my program? Can someone please > recommend something for me. I would greatly appreciate. My program would > appreciate it too, seeing as it will be multi-threaded :) Thank you for your > help. > > -Alex Goretoy > http://www.alexgoretoy.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp at rebertia.com Mon Jan 5 02:24:16 2009 From: clp at rebertia.com (Chris Rebert) Date: Sun, 4 Jan 2009 23:24:16 -0800 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' In-Reply-To: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: <47c890dc0901042324uee73cc7yf1a9d9492eca2086@mail.gmail.com> On Sun, Jan 4, 2009 at 11:15 PM, Gilles Ganault wrote: > Hello > > I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject > >From = "me at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > To = email > msg['To'] = email > > #print To > #(u'dummy at acme.com',) > > #AttributeError: 'tuple' object has no attribute 'lstrip' > #server.sendmail(From,[To],msg.as_string()) > > server.quit > > connection.close(True) > ====== > > Does someone know what is wrong with the above? Does email choke on > Unicode? Please include the full Traceback so that you can be helped more easily. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 02:47:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 07:47:11 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> Message-ID: On Mon, 05 Jan 2009 01:13:48 -0600, Grant Edwards wrote: > On 2009-01-05, Derek Martin wrote: > >>> I'm sorry, but I really don't see how Python's assignment model could >>> be considered bizarre by anybody who's familiar with more than one or >>> two languages. >> >> And... what if one wasn't? The OP of this thread clearly didn't >> understand... Whereas if you've read the thread, clearly I do. Of >> course, had you read my post, you probably would have understood that >> my comment about the model being bizarre was intended to be viewed from >> the perspective of someone who *had not* seen anything like it before, > > X is bizarre because it is unfamiliar to anybody who has never seen X > before? Bizarre: "conspicuously or grossly unconventional or unusual". The bizarre is contingent on what people consider familiar, and naturally if you've never seen X or anything like X before, you will find it unfamiliar and likely bizarre. There's no shame in finding spaghetti alla vongole bizarre if you've never seen noodles or clams before. What is shameful is the refusal to consider that just because it is bizarre to *you* doesn't mean that it is bizarre to anyone else, and that your sense of bizarreness probably reflects more your ignorance of the wide range of edible dishes than anything strange about the food itself. (On the other hand, maggot cheese really is bizarre. http://en.wikipedia.org/wiki/Casu_marzu ) By all means, if Derek doesn't like the assignment model used by Python (and Java, Ruby, C#, Perl, RealBasic, VisualBasic, Lua, and many other languages going back to at least CLU in the mid 1970s) he's free to say so. There are plenty of other languages out there, and perhaps he will find one that he likes. Or he will continue to use Python, hating every minute of it. Or perhaps he'll even come to like the assignment model, and wonder how he ever could have found it bizarre. But it's rather rich for him to claim that his subjective feelings about Python's assignment model should be treated as objective fact. -- Steven From kay.schluehr at gmx.net Mon Jan 5 02:56:26 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sun, 4 Jan 2009 23:56:26 -0800 (PST) Subject: Code coverage to Python code References: Message-ID: <21c3085b-927d-4577-a04f-0b362ead66b1@f3g2000vbf.googlegroups.com> On 4 Jan., 12:35, Hussein B wrote: > Hey, > What is the best code coverage tool available for Python? > Thanks. It depends. What are your requirements? From sjmachin at lexicon.net Mon Jan 5 03:12:54 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 5 Jan 2009 00:12:54 -0800 (PST) Subject: AttributeError: 'tuple' object has no attribute 'lstrip' References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: On Jan 5, 6:15?pm, Gilles Ganault wrote: > Hello > > ? ? ? ? I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject > From = "m... at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > ? ? ? ? To = email > ? ? ? ? msg['To'] = email > > ? ? ? ? #print To > ? ? ? ? #(u'du... at acme.com',) That looks like a tuple to me. What does it look like to you? > > ? ? ? ? #AttributeError: 'tuple' object has no attribute 'lstrip' > ? ? ? ? #server.sendmail(From,[To],msg.as_string()) When are asking for help, could you *PLEASE* supply the actual code that you ran, with the actual output, and (just in case the problem is not otherwise screamingly obvious) the *FULL* traceback? The to_addrs arg of SMTP.sendmail() should be a single string, or a list of strings. You have supplied [(u'du... at acme.com',)] which is a list containing one tuple. That tuple is a result of your SQL query, which has returned a 1-column row as a tuple (as expected/documented). SMTP.sendmail() treats your tuple as though it were a string, and consequently an exception is raised. > server.quit Should that perhaps be server.quit() ? > Does email choke on Unicode? I've got no idea; I've never used email or smtplib. Why don't you feed them some Unicode and find out? Also consider having a look at the manual. HTH, John From max at alcyone.com Mon Jan 5 03:28:43 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 05 Jan 2009 00:28:43 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: >>> I'm going to go out on a limb and assert that there's NO POSSIBLE WAY >>> a student could intuit Python's variable assignment behavior, having >>> never been exposed to that same behavior prior. It needs to be >>> taught. >>> >> As does assignment of any kind. > > I'm not sure that's true. Having taken algebra prior to learning Basic, > I intuitively understood what this program would do when I executed > it, the first time I saw the code, and before I read the explanation: > > 10 let x = 10 > 20 print x Did you understand that the first time you saw the statement in BASIC: X = X + 1 the = symbol couldn't possibly have the same meaning as it does in algebra? In BASIC, this is a statement which replaces the value of a variable X with the previous value, incremented by one. In algebra, this is an equation which has no solutions, since it reduces to 0 = 1, an equation which is inconsistent. The two things aren't even related. That is the whole point here. Computer science and programming languages have objects. Mathematics has no such concept whatsoever, unless you wish to define one. You're welcome to do so with a rigorous definition that you can publish papers about and decide whether other mathematicians are interested in your line of reasoning, but pretending that there is a natural overlap between the mathematical concepts of equality and identity and the computer scientific ones (especially since the term _identity_ isn't even used in remotely the same way) is simply ignoring the fact that other people either won't know what you mean or will presume you're misunderstanding something. Because, based on your previous comments, you are. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Do we ask what profit the little bird hopes for in singing? -- Johannes Kepler, 1571-1630 From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 03:41:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 08:41:08 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two different > objects to spring into existence, the first of which may be cleaned up > by the GC (except that since we're using small integers, that's not > likely to happen). Unless I'm misinformed (which is very possible, my > experience with Java has been extremely limited) in Java that's not the > case... the storage is allocated to the name a when you execute its > declaration, and the *same storage* is reused upon subsequent > assignment. > > That behaves exactly like named bins. In the case of Java, that's because Java uses two assignment models: named bins for "primitives" like ints and floats, and the Python model for class instances, which is *nearly* everything in Java except a few primitive types. >> > And for that matter, it's pretty unintuitive generally. >> >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. It doesn't? Oh my, you're going to be confused in a few weeks when The President of the USA ceases to be George W Bush and becomes Barack Obama. Same name (or rather, title), different object (person). > Nor does Python's assignment work like it does in algebra, Nor does any programming language, with the possible exception of computer algebra systems. > or anywhere else the Python student is particularly likely to have seen > variable assignment before encountering it in Python. Let's define > intuitive, shall we? From dictionary.com (choosing the definition which > most easily makes my point): > > intuitive: adj. capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY a > student could intuit Python's variable assignment behavior, having never > been exposed to that same behavior prior. Unless they've used Java, Perl, Ruby, or any number of other languages. > It needs to be taught. Exactly the same as the named bins assignment model needs to be taught. But, really, you're exaggerating the differences. There are differences of course, but for somebody writing a simple programming with (say) mathematical expressions, there's little or no difference between the models. x = 4 if y > 2: x = x-1 else: x = x+1 print x+y will have the same effect whether you are using the named bins model or not. [...] > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, I don't think so. Variables in algebra are quite different from variables in programming languages. Contrast the statement: x = x+1 as a programming expression and an algebraic equation. As a programming expression, it means "increment x by one". But as an algebraic expression, it means "x is some value such that it is equal to one more than itself", and there is no solution to such an equation. In algebra, a variable name (like x, or c) generally represents one of three things: (1) an an unknown quantity to be solved for; (2) a constant (either a known constant, or an arbitrary parameter); or (3) an alias, such as when you do a change-of-variable. One thing which algebraic variables are not is a bucket or bin that you can set to some value, then modify over and over again. > and how several generations of computer languages, not to mention > the actual machine language those generated, behaved, before the current > crop. Sure. And? > Those interpretations came first, because, much as in the > evolution of any other science, that was the model which was most > intuitive or easily explained. No no no no. That was the model that was most easily implemented! Before the named bins model of assignment was pure machine code, where you didn't have bins at all, just bits, and there was no distinction between code and data. And before that was *wires* -- early programmers literally had to plug and unplug wires to change the state of the computer. And before that were purely mechanical devices, such as the Enigma Machine, old calculators, and the grand-daddy of them all, Charles Babbage's difference engine and it's precursors. > But you need not take my word for it. Simply read the archives and see > for yourself how much confusion this has caused on this list. [Please > include the closely related behavior of parameter passing in your > search.] In my opinion, the cause of that confusion is nothing to do with Python's assignment model, and everything to do with the instance of some people to use named bins terminology when describing the Python model. If you keep the named bins terminology for describing the named bins model, you're fine; and if you keep the name/object terminology for describing languages with names/objects, you're fine. You only run into trouble when you mix them. That's when you get people confused because "Python is Call By Something, but it doesn't behave like Call By Something in language Foo I've used before". -- Steven From workingpad at gmail.com Mon Jan 5 04:47:09 2009 From: workingpad at gmail.com (Jack.Chu) Date: Mon, 5 Jan 2009 01:47:09 -0800 (PST) Subject: My last working day of 2007 Message-ID: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Hello guys: I created a simple tool to count how I wasted my time day by day ;-) http://www.flickr.com/photos/34017270 at N07/3169438647/sizes/o/ It's simple, a small program running on background, logging the title of foreground window. A python script parses the log file and then generates chart by matplotlib. I just want to get suggestions to improve it, or know the news that somebody had implemented a better one so I can abandon my toy. thanks. From vedrandekovic at gmail.com Mon Jan 5 04:53:11 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Mon, 5 Jan 2009 01:53:11 -0800 (PST) Subject: Python stack and heap Message-ID: <33b05bc0-d4f3-4fde-94bc-8b996f5a1266@f24g2000vbf.googlegroups.com> Hello, Does anybody know how can I get usage of stack or/heap memory in Python on Windows XP? Regards, Vedran From matrixhasu at gmail.com Mon Jan 5 04:57:48 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Mon, 5 Jan 2009 01:57:48 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? Message-ID: Hello and Happy 2009! I received the interesting proposal to author a book on Matplotlib, the powerful 2D plotting library for Python. While preparing the arguments list, I'd like to hear even your opinion, because different points-of-view will lead to a better product. Some basic question I'd like to ask are: - what are you using matplotlib for? - what are the things you like the most of matplotlib, that you want to give emphasis to? And why? - what are the (basic) things that, when you were beginning to use matplotlib, you wanted to see grouped up but couldn't find? - what would you like to see in a book about matplotlib? - what are some those advanced feature that made you yell "WOW!!" ? - what are the things you'd like to explore of matplotlib and never had time to do? Your suggestions are really appreciated :) And wish me good luck! From ssalam at gmail.com Mon Jan 5 05:00:08 2009 From: ssalam at gmail.com (Shah Alam) Date: Mon, 5 Jan 2009 02:00:08 -0800 (PST) Subject: Switching user in a SSH connection References: Message-ID: On Jan 2, 2:22?pm, Tino Wildenhain wrote: > Shah Sultan Alam wrote: > > Hi Group, > > ?I am trying to connect to a Linux maching using paramiko. > > ?and able to run a command like "ls -l" > > > ?Now I want to switch user being in the connection ( eg running > > something like "su -" ) > > > Will you please let me know how to do that. > > You would for example run su - in that connection? Or sudo if > installed and configured. > > What else would you need? > > Tino. > > ?smime.p7s > 4KViewDownload I am trying to run su - on that connection.. sudo is not configured From huwdjones at gmail.com Mon Jan 5 05:01:37 2009 From: huwdjones at gmail.com (huw_at1) Date: Mon, 5 Jan 2009 02:01:37 -0800 (PST) Subject: cx_Oracle issues References: <5b2dad81-2750-4347-8079-6ab31321d579@s1g2000prg.googlegroups.com> <9142a8f1-7f76-4fc0-9ca1-c9dec310f2ce@r37g2000prr.googlegroups.com> <9f436c9e-2319-499c-a306-d255996372fc@e22g2000vbe.googlegroups.com> <09b53231-5a92-437c-859b-6e5d0ce106c8@k36g2000pri.googlegroups.com> <75a97df3-7ee9-41ce-9f10-e525c42a7653@e18g2000vbe.googlegroups.com> Message-ID: On Dec 18 2008, 10:34?am, huw_at1 wrote: > On Dec 16, 12:17?pm, huw_at1 wrote: > > > > > On Dec 15, 12:59?pm, "ron.re... at gmail.com" > > wrote: > > > > On Dec 15, 2:44?am, huw_at1 wrote: > > > > > On Dec 11, 5:34?pm, "ron.re... at gmail.com" wrote: > > > > > > On Dec 10, 9:48?am, huw_at1 wrote: > > > > > > > Hey all. When usingcx_Oracleto run a procedure like: > > > > > > > cursor.execute("select (obj.function(value)) from table where > > > > > > id=blah") > > > > > > > I am getting the following error: > > > > > > > ORA-06502: PL/SQL: numeric or value error: character string buffer too > > > > > > small ORA-06512: at line 1 > > > > > > > Looking at cursor.description I get: > > > > > > > [('(obj.function(value))', , 4000, 4000, 0, > > > > > > 0, 1)] > > > > > > > Any tips - i have never seen this error before but am guessing that > > > > > > the value being returned is too big for the buffer size set for the > > > > > > cursor. the procedure fetches data from a LOB. > > > > > > > Any suggestions/confirmations? > > > > > > > Many thanks > > > > > > This error is a problem with the PL/SQL, notcx_Oracle. ?You need to > > > > > debug obj.function to see what kind of data is being accessed and then > > > > > a data analysis of that data to understand why this error occurs. ?I > > > > > can tell you the function is most likely expecting characters from a > > > > > column that are numeric [0 .. 9] and is getting alpha characters. > > > > > > -- > > > > > Ron Reidy > > > > > Sr. Oracle DBA > > > > > Hi thanks for the responses. Unfortunately the procedure in question > > > > is from a third party vendor so I can't really debug it so I'd say I > > > > was fairly stumped. Just out of interest how do you increase the > > > > output buffer size withcx_Oracle? > > > > > Many thanks- Hide quoted text - > > > > > - Show quoted text - > > > > Hi, > > > > Sure you can. ?You can see the PL/SQL source from the ditionary view > > > ALL_SOURCE: > > > select text from all_source where name = 'NAME_OF_FUNCTION'; > > > > From there, reverse engineeer which table(s) and column(s) are being > > > accesses and do the data analysis. > > > > -- > > > Ron Reidy > > > Hi all, > > > So I tried Rons query but unfortunately I got 0 records returned. > > However I can confirm that running the select query from a client does > > indeed generate the same error. Is there anything else I could try? > > Otherwise I'll just get in touch with the vendor I guess. > > Hi again. A further update to theseissuesis that I found some java > executable which seemed to execute the SQL query without hitch. My > Java isn't great but from what I could make out it seems that the > query is broken down from: > > select (obj.function(value)) from table where id=blah > > to: > > select value from table where id=blah > > obj.function(value) > > So make two queries. In the first retrieve the BLOB (value) and store > it in a java.sql.blob object. Then pass this back in to the stored > procedure. I'm a bit puzzled as to why this way would work over just > performing the straight select statement. Culd it be the jdbc > connector handles BLOBs better? Anyway I was wondering if I could > implement something similar usingcx_Oracle. however I am a bit stuck > on how to pass a BLOB in to the second query - specifically: > > cursor.execute(obj.function(value)) > > where value is the BLOB. I get an error: > > cx_Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data > typecx_Oracle.LOB > > So I wonder if I need to set something for the input type but I do not > know how to do this. > > Any suggestions? > > Many thanks again. Hi there. Any suggestions? I'm still a bit stuck on this one? Cheers From bj_666 at gmx.net Mon Jan 5 05:37:53 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 5 Jan 2009 10:37:53 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <6se680F5fbrrU1@mid.uni-berlin.de> On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch > wrote: >> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: >> >> What's the difference between Python and Java or C# here!? Or are they >> also "BIZARRE"!? > > I am happily ignorant of C#. As for Java, take the following code: > > a = 6; > a = 5; > > In Python, when you execute the equivalent code, it causes two different > objects to spring into existence, the first of which may be cleaned up > by the GC (except that since we're using small integers, that's not > likely to happen). Unless I'm misinformed (which is very possible, my > experience with Java has been extremely limited) in Java that's not the > case... the storage is allocated to the name a when you execute its > declaration, and the *same storage* is reused upon subsequent > assignment. > > That behaves exactly like named bins. So does the equivalent in Python. Or to see it the other way: In both languages it *behaves* like (re)binding the name `a` to two different objects. So it is an implementation detail. Even a Python implementation could reuse the same memory location to store the two numbers. >> > And for that matter, it's pretty unintuitive generally. >> >> Names and objects are quite "natural" IMHO. There are many real world >> objects which we attach one or more names to, or refer to in sequences >> like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. In what way? >> I think the "bin model" is more complex because you don't just have a >> name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) "Named bins" is essentially how algebra > works, No it isn't. Mathematics is about binding names and not about putting values into bins. And a mathematical variable can't be rebound once you assigned a value to it. The "intuitive" model for people with a math background would be that of functional languages like Haskell, which is even more strange for people used to "named bins" than the Python, Java, Ruby, ? approach. > and how several generations of computer languages, not to mention > the actual machine language those generated, behaved, before the current > crop. Those interpretations came first, because, much as in the > evolution of any other science, that was the model which was most > intuitive or easily explained. In terms of the underlying machine, but that is exactly what I meant by the additional indirection of the bins. You just have to drag the low level named bins into the explanation because it is an implementation detail of the languages. And there where always languages that use a model like Python parallel to the "named bins languages", it is nothing new. Ciao, Marc 'BlackJack' Rintsch From phil at freehackers.org Mon Jan 5 06:05:32 2009 From: phil at freehackers.org (BlueBird) Date: Mon, 5 Jan 2009 03:05:32 -0800 (PST) Subject: How to "kill" orphaned threads at program exit References: Message-ID: <69d64bbe-792d-4ec9-b422-bab1886f161f@q30g2000prq.googlegroups.com> On Dec 28 2008, 6:33?pm, "Giampaolo Rodola'" wrote: > Hi, > I know that it's not possible to "kill" threads but I'm wondering if > does exist some workaround for my problem. > I have a test suite which does a massive usage of threads. > Sometimes happens that one test fails, the test suite keeps running > until the end, and when it's finished the program hangs on and the > only way to stop is to kill it manually. > I noticed that, at the end of the program, I can call > threading.enumerate() and see the pending thread objects: > Hi, The way I handle it is to make sure that after each test, the thread count has returned to what I expect. It is possible to kill a thread if it's not blocked on a system call. It's highly unrecommended for standard usage but your use case exactly the one where the ability to kill a thread is very useful. I use the following code, which I borrowed to the Python Cook book somewhere: def _async_raise(tid, exctype): '''Raises an exception in the threads with id tid''' if not inspect.isclass(exctype): raise TypeError("Only types can be raised (not instances)") res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("invalid thread id") elif res != 1: # """if it returns a number greater than one, you're in trouble, # and you should call it again with exc=NULL to revert the effect""" ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0) raise SystemError("PyThreadState_SetAsyncExc failed") class ThreadWithExc(threading.Thread): '''A thread class that supports raising exception in the thread from another thread. ''' def _get_my_tid(self): """determines this (self's) thread id CAREFUL : this function is executed in the context of the caller thread, to get the identity of the thread represented by this instance. """ if not self.isAlive(): raise threading.ThreadError("the thread is not active") # do we have it cached? if hasattr(self, "_thread_id"): return self._thread_id # no, look for it in the _active dict for tid, tobj in threading._active.items(): if tobj is self: self._thread_id = tid return tid # TODO : in python 2.6, there's a simpler way to do : self.ident ... raise AssertionError("could not determine the thread's id") def raiseExc(self, exctype): """Raises the given exception type in the context of this thread. If the thread is busy in a system call (time.sleep(), socket.accept(), ...) the exception is simply ignored. If you are sure that your exception should terminate the thread, one way to ensure that it works is: t = ThreadWithExc( ... ) ... t.raiseExc( SomeException ) while t.isAlive(): time.sleep( 0.1 ) t.raiseExc( SomeException ) If the exception is to be caught by the thread, you need a way to check that your thread has caught it. CAREFUL : this function is executed in the context of the caller thread, to raise an excpetion in the context of the thread represented by this instance. """ _async_raise( self._get_my_tid(), exctype ) cheers, Philippe From bj_666 at gmx.net Mon Jan 5 06:15:12 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 5 Jan 2009 11:15:12 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <6se8e0F5fbrrU2@mid.uni-berlin.de> On Sun, 04 Jan 2009 22:55:09 -0600, Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote: >> > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY >> > a student could intuit Python's variable assignment behavior, having >> > never been exposed to that same behavior prior. It needs to be >> > taught. >> > >> As does assignment of any kind. > > I'm not sure that's true. Having taken algebra prior to learning Basic, > I intuitively understood what this program would do when I executed it, > the first time I saw the code, and before I read the explanation: > > 10 let x = 10 > 20 print x Do you really thought of `x` as a named memory location where the bit pattern for the floating point value 10 is stored, with just the algebra knowledge!? Isn't "Ah there the name `x` is bound to the value 10." more likely? As it is the technically easier and IMHO more intuitive explanation when you go from math to programming. > [Well, to be honest it's been a very long time since I've programmed in > Pet BASIC, and the syntax may be wrong. The point is, just as I did > then, I am positive that you intuitively understand what the above is > intended to do, even if it is not valid BASIC syntax -- because if you > did not, we would not be having this discussion.] Syntax is correct. :-) The ``let`` is optional in Commodore BASIC. But where is the difference to x = 10 print x ? Wouldn't you have guessed what this Python program will do just the same? Ciao, Marc 'BlackJack' Rintsch From lipun4u at gmail.com Mon Jan 5 06:37:31 2009 From: lipun4u at gmail.com (asit) Date: Mon, 5 Jan 2009 03:37:31 -0800 (PST) Subject: fetch image Message-ID: <43df25e3-8b98-4468-8e9c-e02e0e3d978e@p2g2000prf.googlegroups.com> import httplib class Server: #server class def __init__(self, host): self.host = host def fetch(self, path): http = httplib.HTTPConnection(self.host) http.request("GET", path) r = http.getresponse() print str(r.status) + " : " + r.reason server = Server("www.python.org") fp=open("phpvuln.txt") x=fp.readlines(); for y in x: server.fetch("/" + y); The above code fetches only the html source of the webpage. How to get the image, flash animation and other stuffs ???? From deets at nospam.web.de Mon Jan 5 06:41:26 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 05 Jan 2009 12:41:26 +0100 Subject: fetch image References: <43df25e3-8b98-4468-8e9c-e02e0e3d978e@p2g2000prf.googlegroups.com> Message-ID: <6se9v6F56eioU1@mid.uni-berlin.de> asit wrote: > import httplib > > class Server: > #server class > def __init__(self, host): > self.host = host > def fetch(self, path): > http = httplib.HTTPConnection(self.host) > http.request("GET", path) > r = http.getresponse() > print str(r.status) + " : " + r.reason > > server = Server("www.python.org") > fp=open("phpvuln.txt") > x=fp.readlines(); > for y in x: > server.fetch("/" + y); > > The above code fetches only the html source of the webpage. How to get > the image, flash animation and other stuffs ???? By parsing the result, extracting img-tags and others that contain references, and fetching these explicitly. The keywords on this for successful search are "python" and "crawling" or "crawler". There are some out there, e.g. here: http://weblab.infosci.cornell.edu/documentation/webbackscript Diez From tmohr at s.netic.de Mon Jan 5 07:12:57 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 05 Jan 2009 13:12:57 +0100 Subject: structuring a package? References: Message-ID: Hello James, >> That way i'd have to structure the code like this: >> >> graphic/ >> __init__,py (GraphicObject) >> square.py (Square) >> circle.py (Circle) >> >> Does that make sense like this? > > This seems perfectly acceptable. Thanks for that hint. Do you see a way that i could write in circle.py: circle.py: import graphic class Circle(graphic.GraphicObject): ..... if __name__ == '__main__': abc = Circle() abc.some_test_code() Thanks for any hints, Torsten. From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 5 08:18:06 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jan 2009 14:18:06 +0100 Subject: structuring a package? In-Reply-To: References: Message-ID: <4962088d$0$24202$426a74cc@news.free.fr> Torsten Mohr a ?crit : > Hi, > > i have a question on how to structure a package best, would be great if > anybody could give me some hint on this: > > Assuming i have a base class GraphicObject and derived from that some > classes like Square, Circle, ... > > It looks natural to me to write in a code that uses the package: > > import graphic > import graphic.square > import graphic.circle > > That way i'd have to structure the code like this: > > graphic/ > __init__,py (GraphicObject) > square.py (Square) > circle.py (Circle) > > Does that make sense like this? > > Are there better ways to structure things in Python? Well... Unless your Square and Circle classes are monster classes, or you have many many GraphicObject subclasses - that is, unless you need to do so for source-file size management -, there's not much reason to use a Java-like "one class per file" scheme[1], and it's not the common way to organize Python code. Now if you do have (or just really want - well, it's your code, isn't it ?-)) to use one-class-per-file, you may be better moving the base GraphicObject class in a base.py module. This would be easier to understand IMHO, and should make internal imports easier to manage. [1] A package can act as a facade for submodules/subpackages (using the __init__.py to expose submodules/subpackages at the top level), so it's not a problem to refactor a single module into a package... > One thing that bothers me is that when i write in circly.py something like > "import graphic", then i can't have the test code for the Circle within > circle.py, at least it looks to me like this. Depends on how you write your test code, but as far as I'm concerned, I prefer to separate source from tests (and use a unittesting framework). From truelixin at gmail.com Mon Jan 5 08:24:07 2009 From: truelixin at gmail.com (truelixin at gmail.com) Date: Mon, 5 Jan 2009 05:24:07 -0800 (PST) Subject: About PyOpenGL Message-ID: I follow the , write a small test: #!/usr/bin/env python # encoding=utf-8 import sys from OpenGL.GL import * from OpenGL.GLUT import * def display(): glClear(GL_COLOR_BUFFER_BIT) glColor(1.0, 1.0, 1.0) glBegin(GL_POLYGON) glVertex(0.25, 0.25, 0.0) glVertex(0.75, 0.25, 0.0) glVertex(0.75, 0.75, 0.0) glVertex(0.25, 0.75, 0.0) glEnd() glFlush() def init(): glClearColor(0.0, 0.0, 0.0, 0.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) glutCreateWindow('hello') init() glutDisplayFunc(display) glutMainLoop() if __name__ == '__main__': main() But I got an error: Traceback (most recent call last): File "test.py", line 36, in main() File "test.py", line 26, in main glutInit(sys.argv) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\GLUT\special.py", line 316, in glutInit _base_glutInit( ctypes.byref(count), holder ) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\GLUT\special.py", line 57, in _base_glutInit return __glutInitWithExit(pargc, argv, _exitfunc) File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg \OpenGL\platform\baseplatform.py", line 280, in __call__ self.__name__, self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined function __glutInitWithExit, check for bool(__glutInitWithExit) before calling Can anyone please tell me why? From digitig at gmail.com Mon Jan 5 08:31:35 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 5 Jan 2009 13:31:35 +0000 Subject: Why not Ruby? In-Reply-To: References: Message-ID: 2009/1/1 r : > I am beginning to think > the perfect high level language would take the best for Ruby and > Python. The ultimate language with speed in mind, pythons clear > syntax, but with shortcuts for gurus. I spent quite a few evenings looking at Ruby, and didn't find a single thing I liked (and I certainly didn't find it "elegant", as the original poster described it). What do you see in it that you think would be good in Python? Remember, put in too many shortcuts and you'll end up with code that's as unmaintainable as Perl! -- Tim Rowe From antroy at gmail.com Mon Jan 5 08:46:52 2009 From: antroy at gmail.com (Ant) Date: Mon, 5 Jan 2009 05:46:52 -0800 (PST) Subject: My last working day of 2007 References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: On Jan 5, 9:47?am, "Jack.Chu" wrote: > Hello guys: > I created a simple tool to count how I wasted my time day by day ;-)http://www.flickr.com/photos/34017270 at N07/3169438647/sizes/o/ Looks interesting - did you have some sort of time machine to be spending that much time in Chrome at the end of 2007? ;-) > I just want to get suggestions to improve it, ... It's a bit hard to tell just from the screenshot... Do you have some code we could look at? Would be perhaps good to sub-log each window's title so that you could subdivide, for example, Firefox's time by the pages you were looking at (this would work quite well for numerous apps.) From thomasvangurp at gmail.com Mon Jan 5 08:52:56 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Mon, 5 Jan 2009 05:52:56 -0800 (PST) Subject: f.seek() unwanted output Message-ID: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> I'm having trouble with a script that is printing the output of f.seek () whereas in the documentation it is quoted not to have any output: ---- file.seek(offset[, whence])? Set the file?s current position, like stdio?s fseek. The whence argument is optional and defaults to os.SEEK_SET or 0 (absolute file positioning); other values are os.SEEK_CUR or 1 (seek relative to the current position) and os.SEEK_END or 2 (seek relative to the file?s end). There is no return value. -------------- I have a file in memory. when i try f.seek(0) #or any other value in f.tell() it gives me 0 as output: the following script illustrates my 'problem' >>> for a in range(10): f.seek(a) 0 1 2 3 4 5 6 7 8 9 >>> I don't want python to produce output when setting the file pointer. Any help woul be appreciated. Kind regards, Thomas From python.list at tim.thechases.com Mon Jan 5 09:13:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Jan 2009 08:13:30 -0600 Subject: f.seek() unwanted output In-Reply-To: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: <4962158A.9030605@tim.thechases.com> > I'm having trouble with a script that is printing the output of f.seek > () [snip] > I have a file in memory. > when i try f.seek(0) #or any other value in f.tell() > it gives me 0 as output: > > the following script illustrates my 'problem' >>>> for a in range(10): > f.seek(a) > > > 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 You're seeing an artifact of the command-line (evidenced by your ">>>" before your command). Just like int("42") returns output...the Python console prints the output while a script (saved to the disk) doesn't. Try putting your test in foo.py and running that -- you'll notice that it doesn't echo back the numbers as you describe. The behavior seems to vary. In my Python2.4, seek() for file/cStringIO/StringIO objects returns None with each. Whichever version (or object-type) you're using seems to return its input offset as its output. -tkc From thomasvangurp at gmail.com Mon Jan 5 09:22:44 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Mon, 5 Jan 2009 06:22:44 -0800 (PST) Subject: f.seek() unwanted output References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: Hi Tim, works! thanx a lot Thomas From djames.suhanko at gmail.com Mon Jan 5 09:25:53 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 5 Jan 2009 12:25:53 -0200 Subject: Tkinter - problem closing window Message-ID: Hello! I'm sorry my terrible english (my native language is portuguese). I has a litle program that open another window. When I close de root window in quit button, I need clicking 2 times to close. is where the problem? The source: 1 #!/usr/bin/env python 2 from Tkinter import * 3 import sys 4 import random 5 class App: 6 def __init__(self, master): 7 frame = Frame(master) 8 frame.pack() 9 rotulo = Label(frame, text="Clique em 'Gerar' e boa sorte!",borderwidth=2,bg="gray",justify=C ENTER,relief=SUNKEN) 10 rotulo.pack() 11 12 self.button = Button(frame, text="Sair", fg="red", command=frame.quit,borderwidth=1) 13 self.button.pack(side=LEFT) 14 self.hi_there = Button(frame, text="Gerar Numero", command=self.say_hi,borderwidth=1) 15 self.hi_there.pack(side=RIGHT,padx=2,pady=2) 16 17 def gera_seis(self): 18 a = {} 19 for i in range(6): 20 a[i] = "%02d" % int (random.randint(0,60)) 21 resultadoA = "%s-%s-%s-%s-%s-%s" % (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) 22 return resultadoA 23 24 def say_hi(self): 25 resultado = self.gera_seis() 26 raiz = Tk() 27 F = Frame(raiz) 28 F.pack() 29 hello = Label(F, text=resultado) 30 hello.pack() 31 F.mainloop() 32 33 root = Tk() 34 root.title("$$$ Loteria $$$") 35 app = App(root) 36 root.mainloop() -- Djames Suhanko LinuxUser 158.760 From pruebauno at latinmail.com Mon Jan 5 09:54:51 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 5 Jan 2009 06:54:51 -0800 (PST) Subject: f.seek() unwanted output References: <08bcebdf-cab2-4433-92c9-1af20a07dcfe@c36g2000prc.googlegroups.com> Message-ID: On Jan 5, 8:52?am, "thomasvang... at gmail.com" wrote: > I'm having trouble with a script that is printing the output of f.seek > () whereas in the documentation it is quoted not to have any output: > > ---- > file.seek(offset[, whence])? > > ? ? Set the file?s current position, like stdio?s fseek. The whence > argument is optional and defaults to os.SEEK_SET or 0 (absolute file > positioning); other values are os.SEEK_CUR or 1 (seek relative to the > current position) and os.SEEK_END or 2 (seek relative to the file?s > end). There is no return value. > -------------- > > I have a file in memory. > when i try f.seek(0) #or any other value in f.tell() > it gives me 0 as output: > > the following script illustrates my 'problem'>>> for a in range(10): > > ? ? ? ? f.seek(a) > > 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > > > > I don't want python to produce output when setting the file pointer. > Any help woul be appreciated. > Kind regards, > Thomas You can also avoid the output by assigning the output to something: >>> for a in range(10): dummy=f.seek(a) From __peter__ at web.de Mon Jan 5 10:07:27 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Jan 2009 16:07:27 +0100 Subject: Tkinter - problem closing window References: Message-ID: Djames Suhanko wrote: > Hello! > I'm sorry my terrible english (my native language is portuguese). > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > The source: > 1 #!/usr/bin/env python > 2 from Tkinter import * > 3 import sys > 4 import random > 5 class App: > 6 def __init__(self, master): > 7 frame = Frame(master) > 8 frame.pack() > 9 rotulo = Label(frame, text="Clique em 'Gerar' e boa > sorte!",borderwidth=2,bg="gray",justify=C ENTER,relief=SUNKEN) > 10 rotulo.pack() > 11 > 12 self.button = Button(frame, text="Sair", fg="red", > command=frame.quit,borderwidth=1) > 13 self.button.pack(side=LEFT) > 14 self.hi_there = Button(frame, text="Gerar Numero", > command=self.say_hi,borderwidth=1) > 15 self.hi_there.pack(side=RIGHT,padx=2,pady=2) > 16 > 17 def gera_seis(self): > 18 a = {} > 19 for i in range(6): > 20 a[i] = "%02d" % int (random.randint(0,60)) > 21 resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > 22 return resultadoA > 23 > 24 def say_hi(self): > 25 resultado = self.gera_seis() > 26 raiz = Tk() > 27 F = Frame(raiz) > 28 F.pack() > 29 hello = Label(F, text=resultado) > 30 hello.pack() > 31 F.mainloop() You need only one mainloop(). Remove line 31 and you should be OK. > 32 > 33 root = Tk() > 34 root.title("$$$ Loteria $$$") > 35 app = App(root) > 36 root.mainloop() Peter From skip at pobox.com Mon Jan 5 10:18:53 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 5 Jan 2009 09:18:53 -0600 Subject: My last working day of 2007 In-Reply-To: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: <18786.9437.669282.928437@montanaro.dyndns.org> Jack> It's simple, a small program running on background, logging the Jack> title of foreground window. A python script parses the log file Jack> and then generates chart by matplotlib. Jack> I just want to get suggestions to improve it, or know the news Jack> that somebody had implemented a better one so I can abandon my Jack> toy. For starters, you might figure out how to make it work on a real operating system which allows multiple active processes. Nudge, nudge. Wink, wink. Say no more. Say no more. ;-) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From psaffrey at googlemail.com Mon Jan 5 10:39:44 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 5 Jan 2009 07:39:44 -0800 (PST) Subject: mod_python: delay in files changing after alteration Message-ID: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Maybe this is an apache question, in which case apologies. I am running mod_python 3.3.1-3 on apache 2.2.9-7. It works fine, but I find that when I alter a source file during development, it sometimes takes 5 seconds or so for the changes to be seen. This might sound trivial, but when debugging tens of silly errors, it's annoying that I have to keep hitting refresh on my browser waiting for the change to "take". I'm guessing this is just a caching issue of some kind, but can't figure out how to switch it off. Any suggestions? The entry in my apache2.conf looks like this: SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On Thanks, Peter From cousinstanley at gmail.com Mon Jan 5 10:59:51 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 5 Jan 2009 15:59:51 +0000 (UTC) Subject: About PyOpenGL References: Message-ID: > .... > OpenGL.error.NullFunctionError: Attempt to call an undefined function > __glutInitWithExit, check for bool(__glutInitWithExit) before calling > > Can anyone please tell me why? Your opengl program runs exactly as coded without error under Debian 5.0 Linux Lenny .... Perhaps a required library is missing from your opengl installation .... Sorry I couldn't provide more help .... -- Stanley C. Kitching Human Being Phoenix, Arizona From guillaume.aubert at gmail.com Mon Jan 5 11:29:47 2009 From: guillaume.aubert at gmail.com (guss) Date: Mon, 5 Jan 2009 08:29:47 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname Message-ID: I cannot find a satisfying answer to this question on the web so let's try here. My problem is the following, I would like to instantiate some object from a configuration file that would contain class names like for example classname=org.common.resource.MyResource. Here my resource is the class to instanciate and it is in the module resource that is in a package hierachy. In fact I would like to do something very similar to the Java: klass = Class.forname("org.common.resource.MyResource") instance = klass.newInstance() The second line is easy once I have a classobj but I have some problems to find the right recipe for getting it. I know how to create a class from scratch with new.classobj but how do you get a class object and then create an object ? I would like a recipe working for all cases (whatever the module is not the local one ...) Maybe I should follow another idiom I don't know ? Thanks your help Guillaume From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 5 11:34:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jan 2009 17:34:24 +0100 Subject: reflection as in Java: how to create an instance from a classname In-Reply-To: References: Message-ID: <4962368e$0$25548$426a74cc@news.free.fr> guss a ?crit : > I cannot find a satisfying answer to this question on the web so let's > try here. > > My problem is the following, I would like to instantiate some object > from a configuration file that would contain class names like for > example classname=org.common.resource.MyResource. > Here my resource is the class to instanciate and it is in the module > resource that is in a package hierachy. > > In fact I would like to do something very similar to the Java: > > klass = Class.forname("org.common.resource.MyResource") > > instance = klass.newInstance() > > The second line is easy once I have a classobj but I have some > problems to find the right recipe for getting it. > > I know how to create a class from scratch with new.classobj but how do > you get a class object and then create an object ? > > I would like a recipe working for all cases (whatever the module is > not the local one ...) use __import__ to get the module object, then getattr(module, classname) to get the class object (sorry, no much time right now to give you a full recipe, but that should be enough to get you started). HTH From qgallet at gmail.com Mon Jan 5 11:37:21 2009 From: qgallet at gmail.com (Quentin Gallet-Gilles) Date: Mon, 5 Jan 2009 17:37:21 +0100 Subject: reflection as in Java: how to create an instance from a classname In-Reply-To: <4962368e$0$25548$426a74cc@news.free.fr> References: <4962368e$0$25548$426a74cc@news.free.fr> Message-ID: <8b943f2b0901050837m6d399f91p825c63cf1ce01d85@mail.gmail.com> On Mon, Jan 5, 2009 at 5:34 PM, Bruno Desthuilliers wrote: > guss a ?crit : > >> I cannot find a satisfying answer to this question on the web so let's >> try here. >> >> My problem is the following, I would like to instantiate some object >> from a configuration file that would contain class names like for >> example classname=org.common.resource.MyResource. >> Here my resource is the class to instanciate and it is in the module >> resource that is in a package hierachy. >> >> In fact I would like to do something very similar to the Java: >> >> klass = Class.forname("org.common.resource.MyResource") >> >> instance = klass.newInstance() >> >> The second line is easy once I have a classobj but I have some >> problems to find the right recipe for getting it. >> >> I know how to create a class from scratch with new.classobj but how do >> you get a class object and then create an object ? >> >> I would like a recipe working for all cases (whatever the module is >> not the local one ...) >> > > use __import__ to get the module object, then getattr(module, classname) to > get the class object (sorry, no much time right now to give you a full > recipe, but that should be enough to get you started). > > HTH > A longer version of Bruno's idea can be found here : http://mail.python.org/pipermail/python-list/2003-March/192221.html Cheers, Quentin -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Mon Jan 5 11:50:17 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 16:50:17 +0000 Subject: math module for Decimals In-Reply-To: References: <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: > > Hmm. Maybe we shouldn't be using this syntax in from_float, if it's > the only thing that prevents the trunk version of decimal.py from > being used with Python 2.4. On the other hand, from_float isn't > going to work until 2.7 anyway, since it uses a whole bunch of > new stuff: as_integer_ratio and copysign (both introduced in 2.6), > and bit_length (introduced in 2.7). > I so new to python that I'm not sure that anything I can say may help as much as someone with more experience. I would leave is compatability to be decided by what other functions it relies on.(as_integer_ratio and copysign) Throw the rest out the window. Since that would make this function more bulky and I don't think there will be that many people wanting to use it with 2.4, OTOH I'm using BackTrack2 and it comes with python2.4.3 I started building my little program using ubuntu with python2.5.x, then I started to use my other option for dual-boot. Backtrack2 is an old time favorite and is alot faster for me to use when running X,firefox(with anywhere from 15-100 tabs open),konqueror,etc Ialready installed other versions of python for bt, no problem there. I'm just wondering about this import error in decimal.py inside python2.7a0(svn repo), don't let curiosity kill this cat. I just wanted to let All know what decimal.py is doing on my pc. Maybe I'm the only one getting this? This version of python2.7 is from python's svn repo. Is the python repo considered to be unstable(wrong word?) and this is expected? I get this when importing decimal: Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/decimal.py", line 138, in import math as _math ImportError: No module named math >>> Are other people seeing this as well? Just curious. -------------- next part -------------- An HTML attachment was scrubbed... URL: From collin.day.0 at gmail.com Mon Jan 5 11:52:48 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 5 Jan 2009 08:52:48 -0800 (PST) Subject: Tkinter - problem closing window References: Message-ID: On Jan 5, 6:25?am, "Djames Suhanko" wrote: > Hello! > I'm sorry my terrible english (my native language is portuguese). > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > The source: > ? 1 #!/usr/bin/env python > ? 2 from Tkinter import * > ? 3 import sys > ? 4 import random > ? 5 class App: > ? 6 ?def __init__(self, master): > ? 7 ? ?frame = Frame(master) > ? 8 ? ?frame.pack() > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > ?10 ? ?rotulo.pack() > ?11 > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > command=frame.quit,borderwidth=1) > ?13 ? ?self.button.pack(side=LEFT) > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > command=self.say_hi,borderwidth=1) > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > ?16 > ?17 ?def gera_seis(self): > ?18 ? ?a = {} > ?19 ? ?for i in range(6): > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > ?22 ? ?return resultadoA > ?23 > ?24 ?def say_hi(self): > ?25 ? ?resultado = self.gera_seis() > ?26 ? ?raiz = Tk() > ?27 ? ?F = Frame(raiz) > ?28 ? ?F.pack() > ?29 ? ?hello = Label(F, text=resultado) > ?30 ? ?hello.pack() > ?31 ? ?F.mainloop() > ?32 > ?33 root = Tk() > ?34 root.title("$$$ Loteria $$$") > ?35 app = App(root) > ?36 root.mainloop() > > -- > Djames Suhanko > LinuxUser 158.760 Also for style, you might want to group the import lines so they look like this: from Tkinter import * import sys, random A bit more pythonic. :P From rtw at freenet.co.uk Mon Jan 5 11:58:10 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Mon, 05 Jan 2009 10:58:10 -0600 Subject: About PyOpenGL References: Message-ID: truelixin at gmail.com wrote in news:f8099226-a953-4598-bfe2-61ee5772ce26 @l33g2000pri.googlegroups.com in comp.lang.python: > > Traceback (most recent call last): > File "test.py", line 36, in > main() > File "test.py", line 26, in main > glutInit(sys.argv) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\GLUT\special.py", line 316, in glutInit > _base_glutInit( ctypes.byref(count), holder ) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\GLUT\special.py", line 57, in _base_glutInit > return __glutInitWithExit(pargc, argv, _exitfunc) > File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > \OpenGL\platform\baseplatform.py", line 280, in __call__ > self.__name__, self.__name__, > OpenGL.error.NullFunctionError: Attempt to call an undefined function > __glutInitWithExit, check for bool(__glutInitWithExit) before calling To get you code running I needed (in addition to the PyOpenGL download) to download. glut-3.7.6-bin.zip (117 KB) from http://www.xmission.com/~nate/glut.html and put the glut32.dll where python can find it, the readme says \system which worked, but sticking it in the same directory as python.exe (c:\python25 in your case) worked too. http://pyopengl.sourceforge.net/ http://pyopengl.sourceforge.net/documentation/installation.html Rob. -- http://www.victim-prime.dsl.pipex.com/ From koranthala at gmail.com Mon Jan 5 11:59:35 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Mon, 5 Jan 2009 08:59:35 -0800 (PST) Subject: Python return values Message-ID: <8ddbd429-64d5-4e64-ba7d-556e6b508164@w1g2000prk.googlegroups.com> I have a newbie doubt about Python return values. In (say) C/C++, if we try to return a value which is stored inside the procedure stack, we will get an error when trying to access it outside of that procedure. For example: function foo(): dcl y int dcl x pointer to int pointing to y return x function bar(): x = foo() ... use x This will error out since the memory has be taken back. Now, in Python, we do it everytime, because all variables are references, and even returns just copies the references. function pyfoo(): return 786 function pyfoo1(): x = xclass() return x function pybar(): x = pyfoo() y = pyfoo1() ... use x, y Why doesnt it error out? From djm300 at gmail.com Mon Jan 5 12:00:37 2009 From: djm300 at gmail.com (Joris) Date: Mon, 5 Jan 2009 18:00:37 +0100 Subject: Python callback functions and static methods Message-ID: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Hello, I'm trying to implement callback functionality in a static class. I have a feeling that I'm doing something against the Python philosophy and not some programming error but any help would be appreciated. First, a piece of proof-of-concept-code: * class Data: callfunc = None @staticmethod def setCallBack(callfunc): Data.callfunc = callfunc @staticmethod def OnData(data): Data.callfunc(data) def DataCallback(a): print 'I received some data: '+ a Data.setCallBack(DataCallback) Data.OnData('I have new data') * I have defined a class called Data, which I want to use as a "static" class (i.e. I will never create an instance of it). (I come from a Java background so forgive me calling this static) It contains a class variable and 2 static methods. I also defined a separate function called DataCallback, which would just print the data it receives. The goal of this is to use the Data class as a dispatcher of some chunk of data to whatever function I would like, settable at run-time. When executing this script, following error occurs: *Traceback (most recent call last): File "callback.py", line 17, in Data.OnData('I have new data') File "callback.py", line 11, in OnData Data.callfunc(data) TypeError: unbound method DataCallback() must be called with Data instance as first argument (got str instance instead) * What I don't understand is why Python is expecting me to call the DataCallback() function with a Data instance. To my understanding, the DataCallback() function can be called from a static method and thus does not require any instance. Can anyone point me in the right direction ? Thanks, Joris -------------- next part -------------- An HTML attachment was scrubbed... URL: From schapman1974 at gmail.com Mon Jan 5 12:08:08 2009 From: schapman1974 at gmail.com (Stephen Chapman) Date: Mon, 5 Jan 2009 12:08:08 -0500 Subject: mod_python: delay in files changing after alteration In-Reply-To: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Message-ID: I have never noticed any such delay. After making a change I just hit F5 on my browser and its fine. Maybe its a browser issue On 1/5/09, psaffrey at googlemail.com wrote: > Maybe this is an apache question, in which case apologies. > > I am running mod_python 3.3.1-3 on apache 2.2.9-7. It works fine, but > I find that when I alter a source file during development, it > sometimes takes 5 seconds or so for the changes to be seen. This might > sound trivial, but when debugging tens of silly errors, it's annoying > that I have to keep hitting refresh on my browser waiting for the > change to "take". I'm guessing this is just a caching issue of some > kind, but can't figure out how to switch it off. Any suggestions? > > The entry in my apache2.conf looks like this: > > > SetHandler mod_python > PythonHandler mod_python.publisher > PythonDebug On > > > > Thanks, > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from Gmail for mobile | mobile.google.com From mwilson at the-wire.com Mon Jan 5 12:09:01 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 05 Jan 2009 12:09:01 -0500 Subject: Python return values References: <8ddbd429-64d5-4e64-ba7d-556e6b508164@w1g2000prk.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > I have a newbie doubt about Python return values. > > In (say) C/C++, if we try to return a value which is stored inside the > procedure stack, we will get an error when trying to access it outside > of that procedure. > For example: > function foo(): > dcl y int > dcl x pointer to int pointing to y > return x > > > function bar(): > x = foo() > ... > use x > > This will error out since the memory has be taken back. > > Now, in Python, we do it everytime, because all variables are > references, and even returns just copies the references. > function pyfoo(): > return 786 > > function pyfoo1(): > x = xclass() > return x > > function pybar(): > x = pyfoo() > y = pyfoo1() > ... > use x, y > > Why doesnt it error out? Because Python doesn't use the procedure stack that way. Using C/C++ terms, all objects are in the heap, and objects are deallocated automatically after all references to them disappear. Mel. From rdcollum at gmail.com Mon Jan 5 12:21:38 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 5 Jan 2009 09:21:38 -0800 (PST) Subject: Tkinter - problem closing window References: Message-ID: <3bd8f10c-abba-4e82-9795-0de7612ac7f0@s36g2000vbp.googlegroups.com> On Jan 5, 11:52?am, Collin D wrote: > On Jan 5, 6:25?am, "Djames Suhanko" wrote: > > > > > Hello! > > I'm sorry my terrible english (my native language is portuguese). > > I has a litle program that open another window. When I close de root > > window in quit button, I need clicking 2 times to close. is where the > > problem? > > > The source: > > ? 1 #!/usr/bin/env python > > ? 2 from Tkinter import * > > ? 3 import sys > > ? 4 import random > > ? 5 class App: > > ? 6 ?def __init__(self, master): > > ? 7 ? ?frame = Frame(master) > > ? 8 ? ?frame.pack() > > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > > ?10 ? ?rotulo.pack() > > ?11 > > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > > command=frame.quit,borderwidth=1) > > ?13 ? ?self.button.pack(side=LEFT) > > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > > command=self.say_hi,borderwidth=1) > > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > > ?16 > > ?17 ?def gera_seis(self): > > ?18 ? ?a = {} > > ?19 ? ?for i in range(6): > > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > > ?22 ? ?return resultadoA > > ?23 > > ?24 ?def say_hi(self): > > ?25 ? ?resultado = self.gera_seis() > > ?26 ? ?raiz = Tk() > > ?27 ? ?F = Frame(raiz) > > ?28 ? ?F.pack() > > ?29 ? ?hello = Label(F, text=resultado) > > ?30 ? ?hello.pack() > > ?31 ? ?F.mainloop() > > ?32 > > ?33 root = Tk() > > ?34 root.title("$$$ Loteria $$$") > > ?35 app = App(root) > > ?36 root.mainloop() > > > -- > > Djames Suhanko > > LinuxUser 158.760 > > Also for style, you might want to group the import lines so they look > like this: > > from Tkinter import * > import sys, random > > A bit more pythonic. :P In that case you probably want to take out the 'from' import and: import Tkinter, sys, random in order to avoid any namespace issues especially if you have a large project with lots of gui manipulations. But that's just me being pedantic. ;) From google at mrabarnett.plus.com Mon Jan 5 12:31:24 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 05 Jan 2009 17:31:24 +0000 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <496243EC.7010107@mrabarnett.plus.com> Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy > and not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > * > class Data: > > callfunc = None > > @staticmethod > def setCallBack(callfunc): > Data.callfunc = callfunc > > @staticmethod > def OnData(data): > Data.callfunc(data) > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > * > > I have defined a class called Data, which I want to use as a "static" > class (i.e. I will never create an instance of it). (I come from a Java > background so forgive me calling this static) > It contains a class variable and 2 static methods. > > I also defined a separate function called DataCallback, which would just > print the data it receives. > > The goal of this is to use the Data class as a dispatcher of some chunk > of data to whatever function I would like, settable at run-time. > > When executing this script, following error occurs: > > *Traceback (most recent call last): > File "callback.py", line 17, in > Data.OnData('I have new data') > File "callback.py", line 11, in OnData > Data.callfunc(data) > TypeError: unbound method DataCallback() must be called with Data > instance as first argument (got str instance instead) > * > What I don't understand is why Python is expecting me to call the > DataCallback() function with a Data instance. To my understanding, the > DataCallback() function can be called from a static method and thus does > not require any instance. > > Can anyone point me in the right direction ? > DataCallback isn't a static method, it's a plain function. Try this instead: class Data: ... @staticmethod def setCallBack(callfunc): Data.callfunc = staticmethod(callfunc) ... From clp at rebertia.com Mon Jan 5 12:33:23 2009 From: clp at rebertia.com (Chris Rebert) Date: Mon, 5 Jan 2009 09:33:23 -0800 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <47c890dc0901050933w3a04fde8ncb0bbc26bddc8544@mail.gmail.com> On Mon, Jan 5, 2009 at 9:00 AM, Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy and > not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > > class Data: > The call to setCallBack effectively makes it as though you'd done this (note that we're within the class body): def callfunc(a): print 'I received some data: '+ a Obviously this method is not "static" in the Java sense, hence the error about not being called with an instance. Here are my suggested changes: > @classmethod #class methods are closer to Java "static" methods; Python static methods are just functions in a class def setCallBack(cls, callfunc): cls.callfunc = staticmethod(callfunc) > @classmethod def OnData(cls, data): cls.callfunc(data) > > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > > Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Mon Jan 5 12:42:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 05 Jan 2009 15:42:39 -0200 Subject: socket send help References: Message-ID: En Sat, 03 Jan 2009 21:44:34 -0200, Bryan Olson escribi?: > Gabriel Genellina wrote: >> greywine at gmail.com escribi?: > [...] >>> A simple server: >>> >>> from socket import * >>> myHost = '' >> Try with myHost = '127.0.0.1' instead - a firewall might be blocking >> your server. > > Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty > string is that a firewall might *not* be blocking your server. > > The Python sockets module interprets the empty string as INADDR_ANY, > which means to bind to all available adapters including the loopback, > A.K.A localhost, A.K.A '127.0.0.1'. I thought a firewall would block an attempt to bind to any routeable address, but not to localhost. So using INADDR_ANY would be rejected. -- Gabriel Genellina From exarkun at divmod.com Mon Jan 5 13:07:07 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 5 Jan 2009 13:07:07 -0500 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: <20090105180707.20272.1723525760.divmod.quotient.32109@ohm> On Mon, 5 Jan 2009 18:00:37 +0100, Joris wrote: >Hello, > >I'm trying to implement callback functionality in a static class. > >I have a feeling that I'm doing something against the Python philosophy and >not some programming error but any help would be appreciated. > Others have explained what was wrong with your `Data` class, so I won't bother going into that. I will recommend that you take a look at Deferred and perhaps use it, rather than implementing something yourself: http://twistedmatrix.com/projects/core/documentation/howto/defer.html Jean-Paul From steve at holdenweb.com Mon Jan 5 13:07:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:07:27 -0500 Subject: Python callback functions and static methods In-Reply-To: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> References: <16c5025d0901050900l4f32358cka0995cdf02139e2@mail.gmail.com> Message-ID: Joris wrote: > Hello, > > I'm trying to implement callback functionality in a static class. > > I have a feeling that I'm doing something against the Python philosophy > and not some programming error but any help would be appreciated. > > First, a piece of proof-of-concept-code: > * > class Data: > > callfunc = None > > @staticmethod > def setCallBack(callfunc): > Data.callfunc = callfunc > > @staticmethod > def OnData(data): > Data.callfunc(data) > > def DataCallback(a): > print 'I received some data: '+ a > > Data.setCallBack(DataCallback) > Data.OnData('I have new data') > * > > I have defined a class called Data, which I want to use as a "static" > class (i.e. I will never create an instance of it). (I come from a Java > background so forgive me calling this static) > It contains a class variable and 2 static methods. > > I also defined a separate function called DataCallback, which would just > print the data it receives. > > The goal of this is to use the Data class as a dispatcher of some chunk > of data to whatever function I would like, settable at run-time. > > When executing this script, following error occurs: > > *Traceback (most recent call last): > File "callback.py", line 17, in > Data.OnData('I have new data') > File "callback.py", line 11, in OnData > Data.callfunc(data) > TypeError: unbound method DataCallback() must be called with Data > instance as first argument (got str instance instead) > * > What I don't understand is why Python is expecting me to call the > DataCallback() function with a Data instance. To my understanding, the > DataCallback() function can be called from a static method and thus does > not require any instance. > > Can anyone point me in the right direction ? > Although other posters have pointed out your mistake in strict terms, I would like to suggest that as long as you never intend to instantiate the class you would be better off without it, defining this functionality as a module and using the nodule global namespace instead of the class namespace. Something like this: callfunc = None def setCallBack(f): global callfunc callfunc = f def OnData(data): callfunc(data) if __name__ == "__main__": def DataCallback(a): print "I received this data:", a setCallBack(DataCallback) OnData("I have new data") OnData("And here's some more!") In other words, I'm not sure what you feel the class organization is buying you. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:13:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:13:29 -0500 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: alex goretoy wrote: > I've found a great example on how to do threads. It compares a ping > program in regular for loop and with threaded for loop. The link is > below if anyone is interested. > > http://www.wellho.net/solutions/python-python-threads-a-first-example.html > > I hope my eagerness to post doesn't annoy anyone. I like to get as much > info from as many places as possible and compare. This way I think I may > have a better solution for a problem. Plus people that Google will find > this post or any words in it. Any more information on threading a for > loop would be greatly appreciated. TIA > Your understanding that such eagerness can become annoying if taken too far is appreciated. So far I haven't heard anyone suggest you should move to comp.lang.somewhere-noobs-get-flamed ... Be aware, however, that the CPython implementation won't net you any benefit if all threads are CPU-bound, since due to something called the GIL (global interpreter lock) no two threads will run concurrently. If you search my past posts on threading you will doubtless find a couple where I've posted my standard example. I don't want to bore long-time readers (any more than I normally do) by repeating it yet again. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:23:04 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:23:04 -0500 Subject: why cannot assign to function call In-Reply-To: <20090105050927.GS28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: Derek Martin wrote: > On Sun, Jan 04, 2009 at 09:56:33PM -0600, Grant Edwards wrote: >> On 2009-01-05, Derek Martin wrote: >>> On Sat, Jan 03, 2009 at 11:38:46AM -0600, Grant Edwards wrote: >>>> One presumes that Mr. Martin finds anything different from his >>>> first computer language to be BIZARRE. He should try out >>>> Prolog or something genuinely different. >>> One's presumption would be mistaken. However thank you for >>> illustrating my point so precisely, which was after all the >>> condescending and insulting way people "communicate" with >>> people whom (they think) know less than they do in this forum, >>> and not actually how difficult or easy the assignment model of >>> Python is to understand. >> I'm sorry, but I really don't see how Python's assignment model >> could be considered bizarre by anybody who's familiar with more >> than one or two languages. > > And... what if one wasn't? The OP of this thread clearly didn't > understand... Whereas if you've read the thread, clearly I do. > Of course, had you read my post, you probably would have understood > that my comment about the model being bizarre was intended to be > viewed from the perspective of someone who *had not* seen anything > like it before, which is LOTS of relatively new programmers, whether > or not it might be old hat to anyone here. The ultimate point of my > post was not so much about whether the assignment model of Python was > or wasn't easy to understand; it was about the idea that when someone > doesn't understand, we should try to help them instead of making snide > remarks about how stupid or small-minded they are. Even if they really are small-minded or stupid I agree this wouldn't be helpful behavior. But neither would your characterization of Python's assignment model as "bizarre" (even ignoring that you SHOUTED IT AT US), and I have yet to see you admit that such a characterization was, shall we say, inappropriate. It takes little to admit one is in the wrong even when one isn't. I've had to learn to do it because I often *am* wrong about things. Could you be persuaded to consider the possibility that you met with a somewhat hostile reaction (whether or not such a reaction was useful or necessary) because you were, in a small way, poking people in the side with a sharp stick? If you couldn't I might find that a *little* bizarre. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 5 13:31:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 13:31:48 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: Steven D'Aprano wrote: > On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: [...]>>>> And for that matter, it's pretty unintuitive generally. >>> Names and objects are quite "natural" IMHO. There are many real world >>> objects which we attach one or more names to, or refer to in sequences >>> like "please give me the third book on that shelve" (``shelve[2]``). >> Indeed, but the way we assign names to them does not behave as it does >> in Python. > > It doesn't? > > Oh my, you're going to be confused in a few weeks when The President of > the USA ceases to be George W Bush and becomes Barack Obama. Same name > (or rather, title), different object (person). > No, he will doubtless describe the White House as a President variable whose value has been overwritten. There are many fine jokes to be made about the need to garbage-collect President Bush ... > > >> Nor does Python's assignment work like it does in algebra, > > Nor does any programming language, with the possible exception of > computer algebra systems. > I'm still waiting for an explanation of where assignment comes into algebra in the first place. > [...] > >> Those interpretations came first, because, much as in the >> evolution of any other science, that was the model which was most >> intuitive or easily explained. > > No no no no. That was the model that was most easily implemented! > Agreed. In those days the von Neumann architecture was a shiny new thing, and it was even a while before people thought of using computers for symbolic rather than numeric operations (which is IMHO what makes them so interesting). > Before the named bins model of assignment was pure machine code, where > you didn't have bins at all, just bits, and there was no distinction > between code and data. And before that was *wires* -- early programmers > literally had to plug and unplug wires to change the state of the > computer. And before that were purely mechanical devices, such as the > Enigma Machine, old calculators, and the grand-daddy of them all, Charles > Babbage's difference engine and it's precursors. > Aah, the old Univac 1004. Sorry, I'm rambling. > > >> But you need not take my word for it. Simply read the archives and see >> for yourself how much confusion this has caused on this list. [Please >> include the closely related behavior of parameter passing in your >> search.] > > In my opinion, the cause of that confusion is nothing to do with Python's > assignment model, and everything to do with the instance of some people > to use named bins terminology when describing the Python model. If you > keep the named bins terminology for describing the named bins model, > you're fine; and if you keep the name/object terminology for describing > languages with names/objects, you're fine. You only run into trouble when > you mix them. That's when you get people confused because "Python is Call > By Something, but it doesn't behave like Call By Something in language > Foo I've used before". > > This really does go to show that (some) people will argue about anything, with the major intention of proving themselves right rather than reaching a common understanding. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lutz at rmi.net Mon Jan 5 13:34:52 2009 From: lutz at rmi.net (lutz at rmi.net) Date: Mon, 5 Jan 2009 11:34:52 -0700 (GMT-07:00) Subject: Python training in Colorado, January 27-30 Message-ID: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> Yes, my public classes are held only in Colorado today. Most students travel from out-of-town to attend. Per my web page, my classes may be available in a different location later this year (Florida is a strong possibility), but not in Tulsa, unfortunately. Thanks, --Mark Lutz -----Original Message----- >From: alex goretoy >Sent: Jan 4, 2009 1:19 PM >To: Mark Lutz >Cc: python-list at python.org >Subject: Re: Python training in Colorado, January 27-30 > >I'd be interested in attending if you make it to Tulsa,OK. Are your courses >only in Colorado? > >-Alex Goretoy >http://www.alexgoretoy.com > > >On Sun, Jan 4, 2009 at 7:29 PM, Mark Lutz wrote: > >> Python author and trainer Mark Lutz will be teaching a 4-day >> Python class on January 27-30, in Longmont, Colorado. >> >> This is a public training session open to individual enrollments, >> and covers the same topics and hands-on lab work as the onsite >> sessions that Mark teaches. The class provides an in-depth >> introduction to both Python and its common applications, and >> parallels the instructor's popular Python books. >> >> For more information on this session, please visit its web page: >> >> http://home.earthlink.net/~python-training/2009-public-classes.htm >> >> For additional background on the class itself, see our home page: >> >> http://home.earthlink.net/~python-training >> >> Thanks for your interest, >> --Python Training Services >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From skip at pobox.com Mon Jan 5 13:47:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 5 Jan 2009 12:47:12 -0600 Subject: Python training in Colorado, January 27-30 In-Reply-To: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> References: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> Message-ID: <18786.21936.349848.917388@montanaro.dyndns.org> lutz> Per my web page, my classes may be available in a different lutz> location later this year (Florida is a strong possibility), but lutz> not in Tulsa, unfortunately. Maybe if Tulsa had more appealing geography or weather??? ;-) Skip From rt8396 at gmail.com Mon Jan 5 14:17:38 2009 From: rt8396 at gmail.com (r) Date: Mon, 5 Jan 2009 11:17:38 -0800 (PST) Subject: Why not Ruby? References: Message-ID: On Jan 5, 7:31 am, "Tim Rowe" wrote: > 2009/1/1 r : > > > I am beginning to think > > the perfect high level language would take the best for Ruby and > > Python. The ultimate language with speed in mind, pythons clear > > syntax, but with shortcuts for gurus. > > I spent quite a few evenings looking at Ruby, and didn't find a single > thing I liked (and I certainly didn't find it "elegant", as the > original poster described it). What do you see in it that you think > would be good in Python? Remember, put in too many shortcuts and > you'll end up with code that's as unmaintainable as Perl! > > -- > Tim Rowe Hello Tim, I think mainly i was just talking out of my bum. I am forced to learn Ruby because it is the only API available for one of my favorite applications. I lament every day that Python was not chosen for the API, not only for myself, but for the poor users who must deal with Ruby's backward way of doing things. I really think Python is the best high level language available today and teaches it's users more than meets-the-eye. I quite enjoy writing Python code, and learned the language very quickly despite the fact that i had no prior programming experience, and very little computer experience in general -- indecently Ruby was the first high level language i tried :) There were a few things initially that i -thought- i liked better about Ruby, but after much consideration, have decided they are not better, and are actually complete rubbish. If i had a choice i would much rather invest my time learning Perl than Ruby. I -will- never get over the use of "end", especially since indentation is allowed. In a language that is as "supposedly" high level as Ruby, this is moronic- monkey-drivel. This complete ludicrisness, coupled with archaic thought processes, is completely redundant, bombastically asinine, and morbidly irreprehensible. Which in turn evaluates to this plague of human excrement we must plow through each and every day! I could could go on and on for hours bashing Ruby, but i should probably stop here before somebody gets upset although i am sure that i will be viciously lambasted for what i have already said.(Pssft-- some people around here are quite touchy!) So let the tongue lashings begin! From code at pizzashack.org Mon Jan 5 14:21:09 2009 From: code at pizzashack.org (Derek Martin) Date: Mon, 5 Jan 2009 13:21:09 -0600 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: <20090105192109.GU28417@dragontoe.org> On Mon, Jan 05, 2009 at 01:23:04PM -0500, Steve Holden wrote: > Even if they really are small-minded or stupid I agree this wouldn't be > helpful behavior. But neither would your characterization of Python's > assignment model as "bizarre" (even ignoring that you SHOUTED IT AT US), > and I have yet to see you admit that such a characterization was, shall > we say, inappropriate. Actually I did, in one of my two most recent posts. But as Steve D'Arpano just pointed out (even though he clearly disagreed with me), such a characterization is subjective, and as such you can't rightly say it's inappropriate. That's the largest part of my point in posting in this thread. Many folks do exactly that, very often. Someone disagrees with you, tries to shed some light on a different perspective, or simply fails to understand something, and some members of this community treat them like heretics, fools, or criminals. I understand why the assignment model works the way it does, and it's quite sensible, *when you understand it*. However, I do also think that to someone who has not encountered such a model before, and who has not had it explained to them, and/or who has not the background to understand why it is implemented that way, it very likely might seem "markedly unusual in appearance, style, or general character and often involving incongruous or unexpected elements;" as dictionary.com defines the term bizarre. So no, I don't think that's a mischaracterization at all. As for using the term in all caps, I did so precisely because it was clear to me that many people here think that it could not be unusual, and I wanted to emphasize the fact that other perspectives exist... That they are not the same as yours does not invalidate them! > It takes little to admit one is in the wrong even when one isn't. I've > had to learn to do it because I often *am* wrong about things. Could you > be persuaded to consider the possibility that you met with a somewhat > hostile reaction (whether or not such a reaction was useful or > necessary) because you were, in a small way, poking people in the side > with a sharp stick? I fully expected to receive a hostile reaction, because I am criticising the behavior of the collective, and supplying a dissenting perspective -- something I knew from the start would trigger such hostility *because it always does*. I have witnessed hostile reactions time and time again in this forum, from some of the same people who are dumping on me for suggesting that the assignment model might be something other than obvious, and from others, for much less: I expect it because I see it in response to nothing more than asking a simple question, when the question displays a clear indication that the poster has missed something critical preventing them from understanding how to achieve their goals. My intent was exactly to point out this behavior, in an attempt to call to people's attention that it is what they are doing, and thereby discourage it. I fully expected a negative response. You in particular have responded quite well, but the rest of the community by and large has sadly not failed to live up to my expectations, even in the face of me saying that that is exactly what they are doing. Quite impressive. Some of the comments from people include the idea that the assignment model is nothing special, if you've encountered any one of a dozen other languages. I didn't realize programming in any of those languages was a prerequisite for posting questions here, or for programming with Python. And that speaks to my ultimate point: Some members of the community seem to make assumptions about what people know or should know, or have experienced, and talk down to people who haven't met their expectations. They meet different perspectives with hostility. Posts which phrase questions in terms commonly used in other programming paradigms are generally even more likely to be met with that same hostility, when they could simply instead explain politely that Python behaves according to a different model than what they are used to. Often this happens, but too often not without someone also letting the OP know what a mindless jerk he is... *This* is the "common understanding" which I'd hoped could be reached... But you were right... it's very difficult for people to admit that they might be wrong. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From GDoermann at gmail.com Mon Jan 5 14:49:09 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 11:49:09 -0800 (PST) Subject: __init__.py and package help Message-ID: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Ok I have read all of the tutorials and documents I could find. I am running Python 2.6 on windows. The problem I am having with packages is that they don't show up! Simple example of what isn't working... Structure- pytest/ Root directory of package __init__.py- code: __all__ = ['folder'] folder/ Another folder in the package __init__.py- code: __all__ = ['hello'] hello.py- code: print('Hello World') Then I append the path to sys.path, and try and import... >>> sys.path.append(r'E:\dev\test\pytest') >>> from pytest.folder import hello Traceback (most recent call last): File "", line 1, in ImportError: No module named pytest.folder What am I doing wrong! It's driving me crazy. Thanks in advance, Greg From GDoermann at gmail.com Mon Jan 5 14:58:09 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 11:58:09 -0800 (PST) Subject: __init__.py and package help References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: <1be7bd39-2642-4fb0-a540-b48ce9f0d7cf@r15g2000prd.googlegroups.com> Ok... I figured it out... you can only import packages via the __all__ = ['subpackage/folder']... if you include a module such as hello.py, it will fail. Go figures I'd find this right after posting here... Greg TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = ['folder'] > folder/ Another folder in the package > __init__.py- code: __all__ = ['hello'] > hello.py- code: print('Hello World') > > Then I append the path to sys.path, and try and import... > > >>> sys.path.append(r'E:\dev\test\pytest') > >>> from pytest.folder import hello > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named pytest.folder > > What am I doing wrong! It's driving me crazy. > Thanks in advance, > Greg From jcd at sdf.lonestar.org Mon Jan 5 15:01:26 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 05 Jan 2009 15:01:26 -0500 Subject: __init__.py and package help In-Reply-To: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: <1231185686.5932.50.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = ['folder'] > folder/ Another folder in the package > __init__.py- code: __all__ = ['hello'] > hello.py- code: print('Hello World') > > Then I append the path to sys.path, and try and import... > > >>> sys.path.append(r'E:\dev\test\pytest') > >>> from pytest.folder import hello > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named pytest.folder > > What am I doing wrong! It's driving me crazy. > Thanks in advance, > Greg You want >>> sys.path.append(r'E:\dev\test') unless your code is in E:\dev\test\pytest\pytest\folder\hello.py > -- > http://mail.python.org/mailman/listinfo/python-list > From GDoermann at gmail.com Mon Jan 5 15:03:24 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 12:03:24 -0800 (PST) Subject: replacement for __file__ in compiled exe Message-ID: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> __file__ command does not work when compiled to exe. It makes since because the file is now in a compressed library. Is there a replacement or something else you can do? The real problem is that when you create an exe of your program with python embedded, you can't always guarantee that your current directory is the directory of your program. I guess when you could just set a registry entry on windows... but it would be nice to have a quick fix for this (like os.path.dirname(__file__)). Thanks, Greg From GDoermann at gmail.com Mon Jan 5 15:05:45 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 12:05:45 -0800 (PST) Subject: __init__.py and package help References: <074164c4-da62-4639-8299-411f16f30d38@b41g2000pra.googlegroups.com> Message-ID: Thanks J. Cliff Dyer wrote: > On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > > Ok I have read all of the tutorials and documents I could find. I am > > running Python 2.6 on windows. The problem I am having with packages > > is that they don't show up! > > > > Simple example of what isn't working... > > Structure- > > > > pytest/ Root directory of package > > __init__.py- code: __all__ = ['folder'] > > folder/ Another folder in the package > > __init__.py- code: __all__ = ['hello'] > > hello.py- code: print('Hello World') > > > > Then I append the path to sys.path, and try and import... > > > > >>> sys.path.append(r'E:\dev\test\pytest') > > >>> from pytest.folder import hello > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named pytest.folder > > > > What am I doing wrong! It's driving me crazy. > > Thanks in advance, > > Greg > > You want > > >>> sys.path.append(r'E:\dev\test') > > unless your code is in E:\dev\test\pytest\pytest\folder\hello.py > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > From heniser at yahoo.com Mon Jan 5 15:06:13 2009 From: heniser at yahoo.com (Ryan) Date: Mon, 5 Jan 2009 12:06:13 -0800 (PST) Subject: Extending Python with C or C++ Message-ID: I've been using Python for many years now. It's a wonderful language that I enjoy using everyday. I'm now interested in getting to know more about the guts (C/C++) and extending it. But, extending python still seems like a black art to me. Is there anymore docs or info on extending it besides the standard sparse ones (http://www.python.org/ doc/2.5.2/ext/intro.html) that may give me more insight? Is there a class available? How can I learn more about the guts of python? How would one go about following an interest in contributing to the development of python. Thanks, Ryan From ralf at schoenian-online.de Mon Jan 5 15:28:28 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Mon, 05 Jan 2009 21:28:28 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: Message-ID: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts (C/C++) and extending it. But, extending python > still seems like a black art to me. Is there anymore docs or info on > extending it besides the standard sparse ones (http://www.python.org/ > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > class available? How can I learn more about the guts of python? How > would one go about following an interest in contributing to the > development of python. > > Thanks, > > Ryan It is not exactly what you are looking for but nevertheless I am thinking the article "Automatic C Library Wrapping -- Ctypes from the Trenches" may be interesting for you. You can find it in the latest Python Papers issue or simply following the link: http://ojs.pythonpapers.org/index.php/tpp/article/view/71 Regards, Ralf From aleksandr.goretoy at gmail.com Mon Jan 5 15:46:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 20:46:23 +0000 Subject: Python training in Colorado, January 27-30 In-Reply-To: <18786.21936.349848.917388@montanaro.dyndns.org> References: <13489149.1231180492741.JavaMail.root@mswamui-blood.atl.sa.earthlink.net> <18786.21936.349848.917388@montanaro.dyndns.org> Message-ID: > > lutz> Per my web page, my classes may be available in a different > lutz> location later this year (Florida is a strong possibility), but > lutz> not in Tulsa, unfortunately. > > Maybe if Tulsa had more appealing geography or weather??? ;-) > > Skip Yes, that makes sense to me. Thank you. There's just not much going on here in Tulsa. I moved here about 3 years ago. It's difficult with linux, PHP,python,administration,networking jobs around here. That's one of the reason why I want to boost the blood flow here in Tulsa. I mainly like it here because it's quiet and the people are nice. Depends on what you compare that too though. It's a good place for family. But if your a linux system administrator, programmer then it's a little more difficult for that stuff here. It's not in the market here. Everyone wants .Net this, Microsoft that. I don't like Microsoft, but don't get me wrong I still have to virtualize it sometimes to get certain things done. I just wish that it were the other way around. Not that it won't be sometime in the near future. Simply due to how things are looking for Micr0$pft. I think I heard something about them getting in to linux/unix as base or is capable of running linux side-by-side. Not virtualbox. Something else. But, I think that's a rumor. Can someone verify that for me? Sorry, of topic. That's why I want to do something to change things around. Maybe open a small school(dream?) Monthly meetings or something. so people can hang out, talk geek. I also want to somehow make it so more people dive into linux, python development. The only way that I think this to be conceivable is if people don't have to pay for it to go there. Or maybe just a small cover charge. They learn cool s*** for fun and profit. I think one way to do this is to bring some trainers to the area. Note I haven't done this before. But I want t organize someway for linux, python development to boom around here and spread all around like a virus. Kinda like organized crime only legal. It's fun. :) Then we find a place to do this and boom. We have a 3 day event in python development here in Tulsa. If more people are able to go then there's a better chance for them to get into linux and python. *Some possible room would be:* Picking a flavor of linux, focusing on gentoo,slackware,ubuntu,centos,bsd as > main choice for starters. Installing that flavor and using it for daily > tasks that a person would perform in windows. > > Ubuntu Linux Installation and customization. Merging from windows, command > line, tools, development starting points,best application to use,techniques, > etc... > > Customizing and using c,python(pyrex),bash,php,etc... > > Then we could go around to some companies.Get them to goto to these meetings. It doesn't even have to be companies. But it is preferred. Somehow making it so that every company/person starts to invest at least 33% of there resource/time on linux and python, for starters. The only thing is that, I don't know where to start. to achieve this. I've been thinking about this from a long time ago. I even bought a domain. HackersHappenHere.com in contrast with the Microsoft launch of HeroesHappenHere.com (Are they saying they want to find more Heroes for there crisis they have going on?) We need more hackers. Oh, one question. How would I get someone, say like Ubuntu to sponsor this whole shenanigans? Or Google for that matter. This would actually, inderictly prepare everyone for Chrome for Linux and undeniably move people from IE. What if there were billboards for linux in the USA? How would that effect Microsoft? OUCH. I think someones turf gonna get jacked. People driving by will see Ubuntu, and be like whats that? A new windows? I gotta try it. Need a upgrade. Then they call there local computer guy,etc... Google will definitely have more playing ground on this turf, not that there sandbox isn't big enough as it is. I just really like google. They have a good culture, etc... I would like this culture to spread out side of google though. This I think would be nice. This way there can be events to go across the USA for Hacker Happen Here. People will truly then start seeing some of the power that linux has over windows and how cost effective it use to use it. Not only for servers, but as a desktop too. Most people, all they need is Firefox. Ubuntu has that. For development it's a different story. For me linux is better for development. I know I can do more with it. Windows I think is somewhat restrictive to what a person can do with there computer. Is there something like this for linux already? Am I missing out on something? trying to duplicate some else's efforts? Certainly, I'm not trying to do that. This will hopefully get some of those really good .Net developers to try python,spe,ubuntu,etc...If they haven't yet. All I know is this. I want linux and python to own USA turf. This will also make it so that development and new applications/tools will come out faster. More users, programmers, hackers, etc... Don't get me wrong, It's nothing personal against Microsoft. I just don't like how so many people are wasting there time with it. Especially when there are significantly way better things out there to feed you mind and your computer. In an unrestrictive so much environment as windows. Especially for development. Sorry this is long and off topic. (I need to learn how to write better.) It's just some things I think about sometimes. Please help me some how to achieve this goal. I want people to really harness the true power of there computer and stop eating BS for applications and development environments. If there is more sand, then there's more sand castles, holes and fun. Why would someone want to pass up the ability to use the same thing in so many more ways than one. It doesn't compute. By all means I'm not trying to steal your thread. Please don't feel that way. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:47 PM, wrote: > > lutz> Per my web page, my classes may be available in a different > lutz> location later this year (Florida is a strong possibility), but > lutz> not in Tulsa, unfortunately. > > Maybe if Tulsa had more appealing geography or weather??? ;-) > > Skip > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Mon Jan 5 15:51:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 5 Jan 2009 12:51:31 -0800 (PST) Subject: replacement for __file__ in compiled exe References: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> Message-ID: <00d1a607-7f1a-4b56-8675-1a44d6926541@z28g2000prd.googlegroups.com> On Jan 6, 7:03?am, TechieInsights wrote: > __file__ command does not work when compiled to exe. ?It makes since > because the file is now in a compressed library. ?Is there a > replacement or something else you can do? ?The real problem is that > when you create an exe of your program with python embedded, you can't > always guarantee that your current directory is the directory of your > program. How can you *ever* guarantee that the current directory is the same as the directory in which the program resides? This lack of guarantee is quite independent of whether the "program" is .py, .exe, .bat, .com, etc. Isn't the real problem how to find out which directory the program is in? > ?I guess when you could just set a registry entry on > windows... but it would be nice to have a quick fix for this (like > os.path.dirname(__file__)). if hasattr(sys, 'frozen'): answer = os.path.split(sys.executable)[0] else: answer = os.path.split(sys.argv[0])[0] (maybe) ... your question is a little unclear. HTH, John From aleksandr.goretoy at gmail.com Mon Jan 5 16:05:36 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:05:36 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: Steve, Are you referring to the endless GIL debate? I googled about what you said. I'll look into it here shortly. I just know one thing, is that I need a comparison for regular code and something about how GIL and threading fit in the picture. It makes it easier for me to understand what is going on. Can you post an example? something I can use to truely thread a for loop? The example previously posted show that it works 10 times faster than original for loop. My current program runs for 4.5 hours. I think it will be good to minimize that by 10 times. But if It can do more/faster, than that would be great. TIA for all your help. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 6:13 PM, Steve Holden wrote: > re, however, that the CPython implementation won't net you any > benefit if all threads are CPU-bound, since due to something called the > GIL (global interpreter lock) no two threads will run concurrently. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Jan 5 16:17:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 05 Jan 2009 16:17:30 -0500 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: alex goretoy wrote: > Steve, > > Are you referring to the endless GIL debate? I googled about what you > said. I'll look into it here shortly. I just know one thing, is that I > need a comparison for regular code and something about how GIL and > threading fit in the picture. It makes it easier for me to understand > what is going on. Can you post an example? something I can use to truely > thread a for loop? The example previously posted show that it works 10 > times faster than original for loop. My current program runs for 4.5 > hours. I think it will be good to minimize that by 10 times. But if It > can do more/faster, than that would be great. TIA for all your help. > Sadly my example doesn't show that. I did, once upon a time, write code that used several hundred threads to send emails, and gave a dramatic speed-up (because of the network-bound nature of the task). Can I presume that your original inquiry was a toy, and that your real problem is also IO-bound? Otherwise I am unsure how you will benefit by threading - if your line-processing tasks don't contain any IO then using a threaded approach will not yield any speed-up at all. The example you quoted achieved its speed-up because a thread releases the GIL while waiting for a network response, allowing other threads to process. Thus it effectively ran all the pings in parallel. Se we need to know a bit more about your 4.5-hour program before we can determine whether threads can help. There is light at the end of the tunnel, however, since even if threads don't work it's possible that the multiprocessing module will (assuming you have multi-processor hardware at your disposal). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From news123 at free.fr Mon Jan 5 16:40:24 2009 From: news123 at free.fr (News123) Date: Mon, 05 Jan 2009 22:40:24 +0100 Subject: My last working day of 2007 In-Reply-To: References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> Message-ID: <49627e48$0$21839$426a34cc@news.free.fr> skip at pobox.com wrote: > Jack> It's simple, a small program running on background, logging the > Jack> title of foreground window. A python script parses the log file > Jack> and then generates chart by matplotlib. > > Jack> I just want to get suggestions to improve it, or know the news > Jack> that somebody had implemented a better one so I can abandon my > Jack> toy. > > For starters, you might figure out how to make it work on a real operating > system which allows multiple active processes. Well the computer can do things in paralell. Most human beings, and according to stereotypes especially male human beings are only single tasking, (like the mouse focus). So if you want to find out what a user is busy with I guess, that the title of the window in focus is probaly a very reasonable indicator. Of course if you want to find out what the computer is busy with, then you should make statistics of the processes and heir cpu loads. bye N > > Nudge, nudge. Wink, wink. Say no more. Say no more. ;-) > From aleksandr.goretoy at gmail.com Mon Jan 5 16:43:00 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:43:00 +0000 Subject: threading a 10 lines out of a file In-Reply-To: References: Message-ID: > > Se we need to know a bit more about your 4.5-hour program before we can > determine whether threads can help. There is light at the end of the > tunnel, however, since even if threads don't work it's possible that the > multiprocessing module will (assuming you have multi-processor hardware > at your disposal). What my program is doing is sending each line to a function that processes it via pycurl(with urllib fallback),mysqlDB(with _mysql fallback). It check the mysql database to see if this line exists. If it doesn't then it sends it either via mysql query or pycurl. Depending on the option set in the functions. Some sections of the function have time.sleep(6) in them. Otherwise things won't work. This considerably slows down performance. If I thread all lines then it will process more at the same time. So that means there will be like 10 or set amount threads running doing all steps in the functions. posting forms, performing queries and waiting for form postings to process on the server, etc... I hope this adds more light at the end of that tunnel. It currently works under my ubuntu install of python(2.5.x) and bt's python(2.4.3). Then reason why I added a fallback to MySQLdb and pycurl is then a person can install this on a server that is hosted elsewhere. Where you can't install python modules, due to permissions and such. I want it to work everywhere. There's alot more to this application, I'm not sure I can disclose at the moment. Seeing as it can be used for good or bad. I don't want it to get in the wrong hands if it's public. OTOH, I think I'll make it public. That's all up in the air at the moment. One thing it that it does make life easier for me. A lot easier. Although, I haven't made money with it. Yet. Plus, I want to make pyGTK frontend for it. Looking into that too. I wouldn't be against a private team assembling to create this though. As long as I can get money out of it somehow. Cuz I'm broke. and I live with my mom. Not sure how anyone can help me there. But I'll throw it up in the air for all to see. Maybe somethings comes out of it. This program is an idea I've been building inside my garage(my room) for about a year and a half. Built in PHP and python, now. Would something that uses pycurl,mysql be good for threading? It doesn't run on SMP but maybe one day. I also need to look into how to make a python package out of it. I researched some stuff awhile ago, but I didn't quite need it then. I just wanted to see what I'm getting into. Any other stuff about this would be appreciated to. Although of topic. Sorry. By the way, I wanted to really thank everyone for all your help. It means a lot to me. -Alex Goretoy http://www.alexgoretoy.com On Mon, Jan 5, 2009 at 9:17 PM, Steve Holden wrote: > I did, once upon a time, write code > that used several hundred threads to send emails, and gave a dramatic > speed-up (because of the network-bound nature of the task). Can I > presume that your original inquiry was a toy, and that your real problem > is also IO-bound? Otherwise I am unsure how you will benefit by > threading - if your line-processing tasks don't contain any IO then > using a threaded approach will not yield any speed-up at all. > > The example you quoted achieved its speed-up because a thread releases > the GIL while waiting for a network response, allowing other threads to > process. Thus it effectively ran all the pings in parallel. > > Se we need to know a bit more about your 4.5-hour program before we can > determine whether threads can help. There is light at the end of the > tunnel, however, since even if threads don't work it's possible that the > multiprocessing module will (assuming you have multi-processor hardware > at your disposal). > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aixer77 at gmail.com Mon Jan 5 17:26:06 2009 From: aixer77 at gmail.com (Kangkook Jee) Date: Mon, 05 Jan 2009 17:26:06 -0500 Subject: Measuring bytes of packet sent from python application Message-ID: <49628901$0$90271$14726298@news.sunsite.dk> Hi, all I'd like to measure number of bytes sent(or recv'd) from my python application. Does anyone have any idea how can I achieve this? I tried to do this by tracing some socket calls (send, sendto, sendAll) using 'metaclass' but I could find exactly place that I can put this in. My application runs some number of protocols (bittorrent, xmlrpc ..) in it and will be measured for a couple of hours. Thanks a lot for your help, in advance /Kangkook From steve at REMOVE-THIS-cybersource.com.au Mon Jan 5 17:28:59 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jan 2009 22:28:59 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: <01728080$0$8693$c3e8da3@news.astraweb.com> On Mon, 05 Jan 2009 13:21:09 -0600, Derek Martin wrote: > Some of the comments from people include the idea that the assignment > model is nothing special, if you've encountered any one of a dozen other > languages. I didn't realize programming in any of those languages was a > prerequisite for posting questions here, or for programming with Python. It's not. But the tone of your argument suggests you think that matching the named bins assignment model of the 1970s should be a prerequisite for all new programming languages. There are, in general, four types of programmers new to Python. In no particular order: (1) People with no programming experience at all. They won't have any problems with Python's assignment model because they have no preconceived ideas about how assignment should work. (2) People who are used to name binding in Ruby, Java, etc. and so will find Python's assignment model more or less identical. (3) Those who come from an entirely different programming model, say, Forth or Haskell. For them, Python's assignment model is going to be the least of their worries. (4) People who are used to the named bins model from C, Pascal or Fortran, who will find some unusual corner cases where Python behaves differently to their mental model of assignment (but not for simple arithmetic using numbers). Python is accessible to *all* of the above groups, although naturally some will need to put in more effort in different directions than others. The tone of reproach in your posts suggests that you believe that the people in group 4 are more authentic programmers whose opinions are more correct than those in groups 1-3. I do not think there is any good reason to believe that group 4 is more special than the other groups. Nor do I believe that newly created languages (as Python was, a decade and a half ago) should be limited to following the named bin assignment model for fear that C etc programmers will be put off by the (supposed) bizarreness of name binding. Speaking as a former Pascal programmer, I think most C, Fortran and Pascal programmers are far too smart for that. > And that speaks to my ultimate point: Some members of the community > seem to make assumptions about what people know or should know, or have > experienced, and talk down to people who haven't met their expectations. > They meet different perspectives with hostility. In my experience, two perspectives are likely to be met with hostility: * those which arrogantly assume that they are the One True and Correct perspective and all others are inferior and wrong; and * those which ignorantly assume that they are the only perspective possible. Your first post in this topic made the extraordinarily arrogant and incorrect claim that: [quote] What the Python community often overlooks, when this discussion again rears its ugly head (as it seems to every other hour or so), is that its assignment model is BIZARRE, as in it's conceptually different from virtually all other languages substantially taught in undergraduate computer science programs. [end quote] We can see some pretty poor assumptions right there: * That the Python community is capable of uniformly overlooking Python's differences from other languages. * That only languages "substantially taught" in undergraduate CS courses matter. It seems that you don't include in the Python community all those who use the term "name binding" instead of variable assignment specifically because it gives new users a clue that Python is not the same as C. You've also missed out on probably twenty years of CS where Java (using the same assignment model as Python!) has been *the* language of choice for undergrad CS, not to mention those introductory courses which use Python. And then you're shocked, SHOCKED!!! that people respond sharply. How different do you think the response would have been if you had said: "What we in the Python community should try to remember is that for those new to the language, there can sometimes be preconceived ideas about how assignment works that clashes with Python's assignment model. From my own perspective, I found the differences between Python's name binding model and the named-bins model of C/Pascal/Fortran confusing at first, and to be honest, I still get caught by those differences. Naturally this is a general problem for every language, Python is hardly unique, but please remember not to bite the newbies just because they are still thinking in some other language." -- Steven From prologic at shortcircuit.net.au Mon Jan 5 17:30:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 08:30:46 +1000 Subject: greenlets and how they can be used In-Reply-To: <496253F8.4070905@gmx.net> References: <495FB40A.9060606@gmx.net> <496253F8.4070905@gmx.net> Message-ID: On Tue, Jan 6, 2009 at 4:39 AM, Benjamin Walkenhorst wrote: > James Mills wrote: >> On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst wrote: >>> POE was one of the nicest software frameworks I have ever used, and I've been continuously frustrated by the lack of something like it in other languages such as Python or Ruby. >> >> It does exist :) It's called circuits. >> Or at least circuits is a framework that I develop >> and build which sounds very similar to POE in >> some ways :) (snip) > Then, one very sad day, a Gentoo upgrade broke POE. I got it working again a few months later, but by then I had somehow lost interest in Perl and discovered the beauty of Python, where my search for an appropriate replacement was frustrated (Twisted seemed to be the closest equivalent, but it seemed overly complex to me, at least I never got the hang of it...). It would seem to me that circuits is quite similar to POE - I've never really used or played with Perl though and probably will never :) > Or, to put it briefly, I would really like to take a look at that sometime. If you intend to release it in any form, I would like to hear about it. Currently released: circuits-1.0b1 See: http://trac.softcircuit.com.au/circuits/ > Oh. I see, it already IS available. How nice!!! That is going to be an interesting evening! > Oh, and thank you very much for bringing this to my attention!!! Your very welcome ... circuits is by no means a replacement or competitor to Twisted - it has very different design goals and architecture (nicer/simpler ihmo). That said though anything that Twisted can do, circuits can do - I've deliberately tried to keep the Component Library as simple and straight forward as possible. Happy hacking! cheers James From collin.day.0 at gmail.com Mon Jan 5 17:36:12 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 5 Jan 2009 14:36:12 -0800 (PST) Subject: Tkinter - problem closing window References: <3bd8f10c-abba-4e82-9795-0de7612ac7f0@s36g2000vbp.googlegroups.com> Message-ID: <18f37013-f140-465e-9393-8ea17c3e5574@35g2000pry.googlegroups.com> On Jan 5, 9:21?am, Roger wrote: > On Jan 5, 11:52?am, Collin D wrote: > > > > > On Jan 5, 6:25?am, "Djames Suhanko" wrote: > > > > Hello! > > > I'm sorry my terrible english (my native language is portuguese). > > > I has a litle program that open another window. When I close de root > > > window in quit button, I need clicking 2 times to close. is where the > > > problem? > > > > The source: > > > ? 1 #!/usr/bin/env python > > > ? 2 from Tkinter import * > > > ? 3 import sys > > > ? 4 import random > > > ? 5 class App: > > > ? 6 ?def __init__(self, master): > > > ? 7 ? ?frame = Frame(master) > > > ? 8 ? ?frame.pack() > > > ? 9 ? ?rotulo = Label(frame, text="Clique em 'Gerar' e boa > > > sorte!",borderwidth=2,bg="gray",justify=C ? ?ENTER,relief=SUNKEN) > > > ?10 ? ?rotulo.pack() > > > ?11 > > > ?12 ? ?self.button = Button(frame, text="Sair", fg="red", > > > command=frame.quit,borderwidth=1) > > > ?13 ? ?self.button.pack(side=LEFT) > > > ?14 ? ?self.hi_there = Button(frame, text="Gerar Numero", > > > command=self.say_hi,borderwidth=1) > > > ?15 ? ?self.hi_there.pack(side=RIGHT,padx=2,pady=2) > > > ?16 > > > ?17 ?def gera_seis(self): > > > ?18 ? ?a = {} > > > ?19 ? ?for i in range(6): > > > ?20 ? ? ? a[i] = "%02d" % ?int (random.randint(0,60)) > > > ?21 ? ?resultadoA = "%s-%s-%s-%s-%s-%s" % > > > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > > > ?22 ? ?return resultadoA > > > ?23 > > > ?24 ?def say_hi(self): > > > ?25 ? ?resultado = self.gera_seis() > > > ?26 ? ?raiz = Tk() > > > ?27 ? ?F = Frame(raiz) > > > ?28 ? ?F.pack() > > > ?29 ? ?hello = Label(F, text=resultado) > > > ?30 ? ?hello.pack() > > > ?31 ? ?F.mainloop() > > > ?32 > > > ?33 root = Tk() > > > ?34 root.title("$$$ Loteria $$$") > > > ?35 app = App(root) > > > ?36 root.mainloop() > > > > -- > > > Djames Suhanko > > > LinuxUser 158.760 > > > Also for style, you might want to group the import lines so they look > > like this: > > > from Tkinter import * > > import sys, random > > > A bit more pythonic. :P > > In that case you probably want to take out the 'from' import and: > > import Tkinter, sys, random > > in order to avoid any namespace issues especially if you have a large > project with lots of gui manipulations. ?But that's just me being > pedantic. ;) I agree... you could have conflicting functions.. not fun. XD From tjreedy at udel.edu Mon Jan 5 17:37:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 17:37:43 -0500 Subject: Extending Python with C or C++ In-Reply-To: References: Message-ID: Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts The 'guts' of Python the language include the object model, namespaces (including modules), and the statement and infix-expression syntax. > (C/C++) and extending it. Now you are asking about CPython, the leading computer implementation. > But, extending python still seems like a black art to me. > Is there anymore docs or info on > extending it besides the standard sparse ones (http://www.python.org/ > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > class available? If you want to connect CPython to Python-oblivious code written in C, Swig (with C code) and Ctypes (with Python code) are the main choices. If you want to write new Python-aware (and specific) code, you can use the CPython C-API functions. Extensions in C are written as importable modules. The interface for such is not difficult; existing examples should be a good guide. > How can I learn more about the guts of python? The 'guts' of an implementation follow from the 'guts' of the language. There must be a syntax parser and compiler to internal form, evaluation loop, and implemenations of built-in constants, functions, classes, and modules. CPython's source tree begins as http://svn.python.org/view/ You might actually want to start at http://svn.python.org/view/python/trunk/ Note: if you click a filename, such as 'setup.py', you get the entire revision history with checkin messages. If you click the displayed revision number, such as '67978', you get the latest checkin message and the current version of the file. > How would one go about following an interest in contributing to the > development of python. Read http://python.org/dev/ and start following the pydev list, mirrored to gmane.comp.python.devel at news.gmane.org. Terry Jan Reedy From tjreedy at udel.edu Mon Jan 5 17:54:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 17:54:19 -0500 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' In-Reply-To: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: Gilles Ganault wrote: > Hello > > I successfully use the email package to send e-mail from Python > scripts, but this script fails when I fetch addresses from an SQLite > database where data is Unicode-encoded: > > ====== > from email.MIMEText import MIMEText > import smtplib,sys > import apsw > > connection=apsw.Connection("test.sqlite") > cursor=connection.cursor() > > subject = "My subject" > f = open("message.txt", "r") > message = f.read() > f.close() > > msg = MIMEText(message) > > msg['Subject'] = subject >>From = "me at acme.com" > msg['From'] = From > > server = smtplib.SMTP("smtp.acme.com") > > sql="SELECT email FROM people WHERE email IS NOT NULL" > rows=list(cursor.execute(sql)) > for email in rows: > To = email Why is 'email' renamed 'To'? > msg['To'] = email > > #print To > #(u'dummy at acme.com',) Why are these line comments? Why is the string enclosed in a tuple? > #AttributeError: 'tuple' object has no attribute 'lstrip' True. Only strings have lstrip method. > #server.sendmail(From,[To],msg.as_string()) Ditto. This looks looks a line from a doc. If you want help interpreting an error message, copy and paste the *entire traceback* without editing. > > server.quit > > connection.close(True) > ====== > > Does someone know what is wrong with the above? Why do you think anything is wrong? Post the actual error message separate from the code that generates the error message. > Does email choke on Unicode? tjr From jgardner at jonathangardner.net Mon Jan 5 17:59:44 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 5 Jan 2009 14:59:44 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> On Jan 5, 2:26?pm, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my python > application. Does anyone have any idea how can I achieve this? > > I tried to do this by tracing some socket calls (send, sendto, sendAll) > ? using 'metaclass' but I could find exactly place that I can put this in. > > My application runs some number of protocols (bittorrent, xmlrpc ..) in > it and will be measured for a couple of hours. > A good universal tool on the Linux platform is tcpdump. It takes some learning, but is very useful for this kind of task. You can use a tool like ethereal to visualize the data that tcpdump gathers. From GDoermann at gmail.com Mon Jan 5 18:00:34 2009 From: GDoermann at gmail.com (TechieInsights) Date: Mon, 5 Jan 2009 15:00:34 -0800 (PST) Subject: replacement for __file__ in compiled exe References: <8881495d-e50a-4f2f-9eaa-d40c97b2cdd7@w1g2000prk.googlegroups.com> <00d1a607-7f1a-4b56-8675-1a44d6926541@z28g2000prd.googlegroups.com> Message-ID: <290f4077-c794-4f60-bf0e-49f2c8733584@z27g2000prd.googlegroups.com> Yes, that is my exact question. How do you get the file path of your script/program. Normally in python you can use __file__ and it will return the file path of the script you are in, however, when you compile the script to exe py2exe (or whatever util you are using) compresses them into a zip folder... not usually a problem, except when you want the access the file path of the exe. Thanks for the answer... I should have thought of that all along... just look on the system path. Sometimes the answer was right in front of your face the whole time... Greg On Jan 5, 1:51?pm, John Machin wrote: > On Jan 6, 7:03?am, TechieInsights wrote: > > > __file__ command does not work when compiled to exe. ?It makes since > > because the file is now in a compressed library. ?Is there a > > replacement or something else you can do? ?The real problem is that > > when you create an exe of your program with python embedded, you can't > > always guarantee that your current directory is the directory of your > > program. > > How can you *ever* guarantee that the current directory is the same as > the directory in which the program resides? This lack of guarantee is > quite independent of whether the "program" is .py, .exe, .bat, .com, > etc. Isn't the real problem how to find out which directory the > program is in? > > > ?I guess when you could just set a registry entry on > > windows... but it would be nice to have a quick fix for this (like > > os.path.dirname(__file__)). > > ? ? if hasattr(sys, 'frozen'): > ? ? ? ? answer = os.path.split(sys.executable)[0] > ? ? else: > ? ? ? ? answer = os.path.split(sys.argv[0])[0] > > (maybe) ... your question is a little unclear. > > HTH, > John From rhodri at wildebst.demon.co.uk Mon Jan 5 18:05:43 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 05 Jan 2009 23:05:43 -0000 Subject: why cannot assign to function call In-Reply-To: <01728080$0$8693$c3e8da3@news.astraweb.com> References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, 05 Jan 2009 22:28:59 -0000, Steven D'Aprano wrote: > * That only languages "substantially taught" in undergraduate CS courses > matter. As an aside, I use only one of the languages I was taught in my Computer Science course, and that only for poking my EMACS configuration. Every other language I use (yes, including C) I learned afterwards. Moral: times change. -- Rhodri James *-* Wildebeeste Herder to the Masses From aixer77 at gmail.com Mon Jan 5 18:23:10 2009 From: aixer77 at gmail.com (Kangkook Jee) Date: Mon, 05 Jan 2009 18:23:10 -0500 Subject: Measuring bytes of packet sent from python application In-Reply-To: <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> Message-ID: <4962965f$0$90276$14726298@news.sunsite.dk> Jonathan Gardner wrote: > On Jan 5, 2:26 pm, Kangkook Jee wrote: >> I'd like to measure number of bytes sent(or recv'd) from my python >> application. Does anyone have any idea how can I achieve this? >> >> I tried to do this by tracing some socket calls (send, sendto, sendAll) >> using 'metaclass' but I could find exactly place that I can put this in. >> >> My application runs some number of protocols (bittorrent, xmlrpc ..) in >> it and will be measured for a couple of hours. >> > > A good universal tool on the Linux platform is tcpdump. It takes some > learning, but is very useful for this kind of task. You can use a tool > like ethereal to visualize the data that tcpdump gathers. Thanks a lot Jonathan That seems like a good solution for my issue but how can I distinguish traffics from my application to others? I'm still struggling to solve it within python process since it looks cleaner but it doesn't seems to be easy at all. From jgardner at jonathangardner.net Mon Jan 5 18:36:42 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 5 Jan 2009 15:36:42 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On Jan 5, 3:23?pm, Kangkook Jee wrote: > Jonathan Gardner wrote: > > A good universal tool on the Linux platform is tcpdump. It takes some > > learning, but is very useful for this kind of task. You can use a tool > > like ethereal to visualize the data that tcpdump gathers. > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > There are a variety of ways to distinguish traffic with tcpdump and ethereal. Usually you should have some idea of what ports or hosts your traffic is going to. If not, then you will have some indicator within the packets themselves. Note that tcpdump is remarkable since it can identify TCP sessions, and not just individual packets. > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. Replacing a lower-level component of a 3rd party library is difficult at best. If you can get it to work without rewriting the library, congratulations. At the very least, you'll probably have to do some low-level things within the libraries themselves. From aleksandr.goretoy at gmail.com Mon Jan 5 18:38:41 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 23:38:41 +0000 Subject: multiprocessing vs thread performance In-Reply-To: References: Message-ID: There doesn't seem to be any good examples on POSH or it's not clear to me. For when using with a for loop like mk is doing who started this thread. How would somethings like this be possible to do with POSH? The example show how to share variables between processes/threads but nothing about How the thread starts or a for loop. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sat, Jan 3, 2009 at 1:31 PM, Nick Craig-Wood wrote: > mk wrote: > > After reading http://www.python.org/dev/peps/pep-0371/ I was under > > impression that performance of multiprocessing package is similar to > > that of thread / threading. However, to familiarize myself with both > > packages I wrote my own test of spawning and returning 100,000 empty > > threads or processes (while maintaining at most 100 processes / threads > > active at any one time), respectively. > > > > The results I got are very different from the benchmark quoted in PEP > > 371. On twin Xeon machine the threaded version executed in 5.54 secs, > > while multiprocessing version took over 222 secs to complete! > > > > Am I doing smth wrong in code below? > > Yes! > > The problem with your code is that you never start more than one > process at once in the multiprocessing example. Just check ps when it > is running and you will see. > > My conjecture is that this is due to the way fork() works under unix. > I think that when the parent forks it yields the CPU to the child. > Because you are giving the child effectively no work to do it returns > immediately, re-awakening the parent, thus serialising your jobs. > > If you give the children some work to do you'll see a quite different > result. I gave each child time.sleep(1) to do and cut down the total > number to 10,000. > > $ ./test_multiprocessing.py > == Process 1000 working == > == Process 2000 working == > == Process 3000 working == > == Process 4000 working == > == Process 5000 working == > == Process 6000 working == > == Process 7000 working == > == Process 8000 working == > == Process 9000 working == > == Process 10000 working == > === Main thread waiting for all processes to finish === > Total time: 101.382129192 > > $ ./test_threading.py > == Thread 1000 working == > == Thread 2000 working == > == Thread 3000 working == > == Thread 4000 working == > == Thread 5000 working == > == Thread 6000 working == > == Thread 7000 working == > == Thread 8000 working == > == Thread 9000 working == > == Thread 10000 working == > Total time: 100.659118176 > > So almost identical results and as expected - we ran 10,000 sleep(1)s > in 100 seconds so we must have been running 100 simultaneously. > > If you replace the "time.sleep(1)" with "for _ in xrange(1000000): > pass" you get this much more interesting answer on my dual core linux > laptop, showing nicely the effect of the contention on the python > global interpreter lock and how multiprocessing avoids it. > > $ ./test_multiprocessing.py > == Process 1000 working == > == Process 2000 working == > == Process 3000 working == > == Process 4000 working == > == Process 5000 working == > == Process 6000 working == > == Process 7000 working == > == Process 8000 working == > == Process 9000 working == > == Process 10000 working == > === Main thread waiting for all processes to finish === > Total time: 266.808327913 > > $ ./test_threading.py > == Thread 1000 working == > == Thread 2000 working == > == Thread 3000 working == > == Thread 4000 working == > == Thread 5000 working == > == Thread 6000 working == > == Thread 7000 working == > == Thread 8000 working == > == Thread 9000 working == > == Thread 10000 working == > Total time: 834.81882 > > -- > Nick Craig-Wood -- http://www.craig-wood.com/nick > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at opensuse.us Mon Jan 5 18:42:00 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 5 Jan 2009 15:42:00 -0800 Subject: Is there a best linux distro for a python hobbyist? Message-ID: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... And so on. From prologic at shortcircuit.net.au Mon Jan 5 18:44:45 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 09:44:45 +1000 Subject: Measuring bytes of packet sent from python application In-Reply-To: <49628901$0$90271$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: On Tue, Jan 6, 2009 at 8:26 AM, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my python > application. Does anyone have any idea how can I achieve this? > > I tried to do this by tracing some socket calls (send, sendto, sendAll) > using 'metaclass' but I could find exactly place that I can put this in. > > > My application runs some number of protocols (bittorrent, xmlrpc ..) in > it and will be measured for a couple of hours. > > Thanks a lot for your help, in advance Something like this perhaps ? Example code follows ... NB: This uses circuits (1) $ ./test.py smtp-int.vision6.com.au 25 Trying smtp-int.vision6.com.au... Connected to smtp-int.vision6.com.au 220 marvin.vision6.com.au ESMTP EHLO localhost 250-marvin.vision6.com.au 250-AUTH LOGIN CRAM-MD5 PLAIN 250-AUTH=LOGIN CRAM-MD5 PLAIN 250-PIPELINING 250 8BITMIME QUIT 221 marvin.vision6.com.au Connection closed Traffic In: 179 bytes Out: 20 bytes --------------------------------------------------------- http://codepad.org/V32fsqKt Note the Stats component on line 60. --------------------------------------------------------- cheers James From aleksandr.goretoy at gmail.com Mon Jan 5 18:45:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 23:45:23 +0000 Subject: Measuring bytes of packet sent from python application In-Reply-To: <4962965f$0$90276$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: Have you looked into scapy? www.secdev.org/projects/*scapy*/ There's another one, it comes with python I think. Can't seem to remember the name. I may be mistaken though. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 11:23 PM, Kangkook Jee wrote: > Jonathan Gardner wrote: > >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >> >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, sendAll) >>> using 'metaclass' but I could find exactly place that I can put this in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) in >>> it and will be measured for a couple of hours. >>> >>> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. >> > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.pruitt at gmail.com Mon Jan 5 19:18:29 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Mon, 5 Jan 2009 18:18:29 -0600 Subject: Regex Generator From Multiple Files Message-ID: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> I am looking for a way given a number of files, say 3, that represent technical support tickets in the same format to generate regular expressions for the different fields automatically. An example from of one line from each file: Date: 12/30/2008 Room: 457 Building: Main Date: 12/31/2008 Room: A21 Building: Annex Date: 1/4/2009 Room: L69 Building: Library The program would then, possibly using the python diff library, generate the regular expression needed to parse out different fields. In this case it might return a tuple like ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.*)[\w]+$") that would match each of the fields based on the common data and sort of assume that what doesn't change between them is data we are looking for. -------------- next part -------------- An HTML attachment was scrubbed... URL: From heniser at yahoo.com Mon Jan 5 19:27:34 2009 From: heniser at yahoo.com (Ryan) Date: Mon, 5 Jan 2009 16:27:34 -0800 (PST) Subject: Extending Python with C or C++ References: Message-ID: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> On Jan 5, 2:37 pm, Terry Reedy wrote: > Ryan wrote: > > I've been using Python for many years now. It's a wonderful language > > that I enjoy using everyday. I'm now interested in getting to know > > more about the guts > > The 'guts' of Python the language include the object model, namespaces > (including modules), and the statement and infix-expression syntax. > > > (C/C++) and extending it. > > Now you are asking about CPython, the leading computer implementation. > > > But, extending python still seems like a black art to me. > > > Is there anymore docs or info on > > > extending it besides the standard sparse ones (http://www.python.org/ > > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > > class available? > > If you want to connect CPython to Python-oblivious code written in C, > Swig (with C code) and Ctypes (with Python code) are the main choices. > If you want to write new Python-aware (and specific) code, you can use > the CPython C-API functions. Extensions in C are written as importable > modules. The interface for such is not difficult; existing examples > should be a good guide. > > > How can I learn more about the guts of python? > > The 'guts' of an implementation follow from the 'guts' of the language. > There must be a syntax parser and compiler to internal form, > evaluation loop, and implemenations of built-in constants, functions, > classes, and modules. CPython's source tree begins ashttp://svn.python.org/view/ > You might actually want to start athttp://svn.python.org/view/python/trunk/ > Note: if you click a filename, such as 'setup.py', you get the entire > revision history with checkin messages. > If you click the displayed revision number, such as '67978', you get the > latest checkin message and the current version of the file. > > > How would one go about following an interest in contributing to the > > development of python. > > Readhttp://python.org/dev/ > and start following the pydev list, mirrored to gmane.comp.python.devel > at news.gmane.org. > > Terry Jan Reedy Thanks Terry! This clarifies many of the concepts that I want to get started to dive deeper into CPython. 1. The abstract Python Language (not specific to any implementation) 2. The CPython implementation (http://svn.python.org/view/python/ trunk/) 3. Extending CPython by connecting it to Python-oblivious code written in C with Ctypes (Ralf's suggestion is good for this) 4. Extending CPython by connecting it to Python-aware (and specific) code using the CPython C-API functions (http://docs.python.org/c-api/) From david.lyon at preisshare.net Mon Jan 5 19:39:25 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Mon, 05 Jan 2009 19:39:25 -0500 Subject: Is there a best linux distro for a python =?UTF-8?Q?hobbyist=3F?= In-Reply-To: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: Hi, I would have to put in a vote for Ubuntu. There seems to be a working ubuntu package for most of the things that I have tried. Instead of having to use a pythonic package - just get one from the os. As for the things you mention.. give it a go On Mon, 5 Jan 2009 15:42:00 -0800, "member thudfoo" wrote: > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > And so on. From google at mrabarnett.plus.com Mon Jan 5 19:48:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jan 2009 00:48:20 +0000 Subject: Regex Generator From Multiple Files In-Reply-To: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> References: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> Message-ID: <4962AA54.7030500@mrabarnett.plus.com> James Pruitt wrote: > I am looking for a way given a number of files, say 3, that represent > technical support tickets in the same format to generate regular > expressions for the different fields automatically. > > An example from of one line from each file: > Date: 12/30/2008 Room: 457 Building: Main > Date: 12/31/2008 Room: A21 Building: Annex > Date: 1/4/2009 Room: L69 Building: Library > > The program would then, possibly using the python diff library, generate > the regular expression needed to parse out different fields. In this > case it might return a tuple like > ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.*)[\w]+$") > that would match each of the fields based on the common data and sort of > assume that what doesn't change between them is data we are looking for. > Why not just assume that each field consists of a word terminated by a colon, then some text, then the next field or the end of the line? From fakeaddress at nowhere.org Mon Jan 5 19:49:59 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 05 Jan 2009 16:49:59 -0800 Subject: socket send help In-Reply-To: References: Message-ID: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Gabriel Genellina wrote: > Bryan Olson escribi?: > >> Gabriel Genellina wrote: >>> greywine at gmail.com escribi?: >> [...] >>>> A simple server: >>>> >>>> from socket import * >>>> myHost = '' >>> Try with myHost = '127.0.0.1' instead - a firewall might be blocking >>> your server. >> >> Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty >> string is that a firewall might *not* be blocking your server. >> >> The Python sockets module interprets the empty string as INADDR_ANY, >> which means to bind to all available adapters including the loopback, >> A.K.A localhost, A.K.A '127.0.0.1'. > > I thought a firewall would block an attempt to bind to any routeable > address, but not to localhost. So using INADDR_ANY would be rejected. So you thought this would fail at bind()? My understanding is that firewalls block network traffic, not system calls. -- --Bryan From mdw at distorted.org.uk Mon Jan 5 19:55:06 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 00:55:06 +0000 (UTC) Subject: Rich Comparisons Gotcha References: <014c51d9$0$20670$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There is nothing to blame them for. This is the correct behaviour. NaNs > should *not* compare equal to themselves, that's mathematically > incoherent. Indeed. The problem is a paucity of equality predicates. This is hardly surprising: Common Lisp has four general-purpose equality predicates (EQ, EQL, EQUAL and EQUALP), and many more type-specific ones (=, STRING=, STRING-EQUAL (yes, I know...), CHAR=, ...), and still doesn't really have enough. For example, EQUAL compares strings case-sensitively, but other arrays are compared by address; EQUALP will recurse into arbitrary arrays, but compares strings case-insensitively... For the purposes of this discussion, however, it has enough to be able to distinguish between * numerical comparisons, which (as you explain later) should /not/ claim that two NaNs are equal, and * object comparisons, which clearly must declare an object equal to itself. For example, I had the following edifying conversation with SBCL. CL-USER> ;; Return NaNs rather than signalling errors. (sb-int:set-floating-point-modes :traps nil) ; No value CL-USER> (defconstant nan (/ 0.0 0.0)) NAN CL-USER> (loop for func in '(eql equal equalp =) collect (list func (funcall func nan nan))) ((EQL T) (EQUAL T) (EQUALP T) (= NIL)) CL-USER> That is, a NaN is EQL, EQUAL and EQUALP to itself, but not = to itself. (Due to the vagaries of EQ, a NaN might or might not be EQ to itself or other NaNs.) Python has a much more limited selection of equality predicates -- in fact, just == and is. The is operator is Python's equivalent of Lisp's EQ predicate: it compares objects by address. I can have a similar chat with Python. In [12]: nan = float('nan') In [13]: nan is nan Out[13]: True In [14]: nan == nan Out[14]: False In [16]: nan is float('nan') Out[16]: False Python numbers are the same as themselves reliably, unlike in Lisp. But there's no sensible way of asking whether something is `basically the same as' nan, like Lisp's EQL or EQUAL. I agree that the primary equality predicate for numbers must be the numerical comparison, and NaNs can't (sensibly) be numerically equal to themselves. Address comparisons are great when you're dealing with singletons, or when you carefully intern your objects. In other cases, you're left with ==. This puts a great deal of responsibility on the programmer of an == method to weigh carefully the potentially conflicting demands of compatibility (many other libraries just expect == to be an equality operator returning a straightforward truth value, and given that there isn't a separate dedicated equality operator, this isn't unreasonable), and doing something more domain-specifically useful. It's worth pointing out that numpy isn't unique in having == not return a straightforward truth value. The SAGE computer algebra system (and sympy, I believe) implement the == operator on algebraic formulae so as to construct equations. For example, the following is syntactically and semantically Python, with fancy libraries. sage: var('x') # x is now a variable x sage: solve(x**2 + 2*x - 4 == 1) [x == -sqrt(6) - 1, x == sqrt(6) - 1] (SAGE has some syntactic tweaks, such as ^ meaning the same as **, but I didn't use them.) I think this is an excellent use of the == operator -- but it does have some potential to interfere with other libraries which make assumptions about how == behaves. The SAGE developers have been clever here, though: sage: 2*x + 1 == (2 + 4*x)/2 2*x + 1 == (4*x + 2)/2 sage: bool(2*x + 1 == (2 + 4*x)/2) True sage: bool(2*x + 1 == (2 + 4*x)/3) False I think Python manages surprisingly well with its limited equality predicates. But the keyword there is `surprisingly' -- and it may not continue this trick forever. -- [mdw] From prologic at shortcircuit.net.au Mon Jan 5 19:59:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 10:59:46 +1000 Subject: socket send help In-Reply-To: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: On Tue, Jan 6, 2009 at 10:49 AM, Bryan Olson wrote: >> I thought a firewall would block an attempt to bind to any routeable >> address, but not to localhost. So using INADDR_ANY would be rejected. No. > My understanding is that firewalls block network traffic, not system calls. This is correct. Firewalls (real firewalls) can only act on incoming and outgoing traffic on the IP level. cheers James From prologic at shortcircuit.net.au Mon Jan 5 20:02:43 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 11:02:43 +1000 Subject: socket send help In-Reply-To: References: Message-ID: On Wed, Dec 24, 2008 at 3:59 PM, greywine at gmail.com wrote: (snip) > If I run testserver.py via the cmd prompt in Windows XP and then the > testclient.py program, I get the following error: > > Traceback (most recent call last): > File "C:\Python30\testclient.py", line 12, in > s.send('Hello world') # send the data > TypeError: send() argument 1 must be string or buffer, not str > > This happens in 2.6 or 3.0 and with different example client & server > programs from the web. What am I missing? I'm sorry I should have answered sooner :) Python 3.x (and probably 2.6+) required that you use bytes to send your data through sockets rather than strings. This was part of the revamp for better unicode support irrc. cheers James From zac256 at gmail.com Mon Jan 5 20:04:30 2009 From: zac256 at gmail.com (Zac Burns) Date: Mon, 5 Jan 2009 17:04:30 -0800 Subject: cPickle vs pickle discrepancy Message-ID: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Greetings, I have a module that attempts to pickle classes defined in that module. I get an error of the form: PicklingError: Can't pickle : import of module Module.SubModule failed when using cPickle (protocol -1, python version 2.5.1). The module has already been imported and is in sys.modules when the exception is raised. Using pickle instead of cPickle works, but the section of the code is performance critical. How can this be worked around? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From aleksandr.goretoy at gmail.com Mon Jan 5 20:11:44 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 01:11:44 +0000 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: +1 for ubuntu -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 12:39 AM, wrote: > Hi, > > I would have to put in a vote for Ubuntu. > > There seems to be a working ubuntu package for most of the things that I > have tried. Instead of having to use a pythonic package - just get one from > the os. > > As for the things you mention.. give it a go > > On Mon, 5 Jan 2009 15:42:00 -0800, "member thudfoo" > wrote: > > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > > And so on. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 5 20:14:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 6 Jan 2009 11:14:10 +1000 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: On Tue, Jan 6, 2009 at 11:11 AM, alex goretoy wrote: > +1 for ubuntu +1 for Ubuntu also (for the novice and ex-windows user(s)) +2 for CRUX (1) cheers James 1. http://crux.nu/ From floss at lex.hider.name Mon Jan 5 20:16:08 2009 From: floss at lex.hider.name (Lex Hider) Date: Tue, 6 Jan 2009 12:16:08 +1100 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> Message-ID: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Probably not a big difference in most cases between debian, ubuntu, fedora. The latter two may be more likely to have more recent versions. I'm pretty sure ubuntu is the only one which currently has python 3.0 in it's archives [no, it's not the default version]. On 06/01/2009, member thudfoo wrote: > One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... > And so on. > -- > http://mail.python.org/mailman/listinfo/python-list > From mdw at distorted.org.uk Mon Jan 5 20:24:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 01:24:58 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > I've already mentioned NaNs. Sentinel values also sometimes need to > compare not equal with themselves. Forcing them to compare equal will > cause breakage. There's a conflict between such domain-specific considerations (NaNs, strange sentinels, SAGE's equations), and relatively natural assumptions about an == operator, such as it being an equivalence relation. I don't know how to resolve this conflict without introducing a new function which is (or at least strongly encourages developers to arrange for it to be) an equivalence relation. -- [mdw] From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 20:53:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 01:53:17 GMT Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On Mon, 05 Jan 2009 18:23:10 -0500, Kangkook Jee wrote: > Jonathan Gardner wrote: >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, >>> sendAll) >>> using 'metaclass' but I could find exactly place that I can put this >>> in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) >>> in it and will be measured for a couple of hours. >>> >>> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? > > I'm still struggling to solve it within python process since it looks > cleaner but it doesn't seems to be easy at all. A relatively straightforward, if not totally accurate, way of doing that is to create a layer between your application code and the network libraries, and have the layer measure the amount of data you send before it reaches the specific protocols being used. Naturally this won't give you a totally accurate count of network traffic sent from your application, since every protocol includes some overhead, but that might not matter for your use-case. -- Steven From castironpi at gmail.com Mon Jan 5 21:01:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 5 Jan 2009 18:01:55 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> <01705c07$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 4, 1:28?am, Steven D'Aprano wrote: > I'm answering both John and Aaron's comments in the following. Mostly > John at the start, Aaron toward the end. > > On Sat, 03 Jan 2009 15:42:47 -0800, Aaron Brady wrote: > > On Jan 3, 11:25?am, John O'Hagan wrote: > > [...] > > > > >According to this, when you replace every floorboard on a porch, one > > > >at a time, it's still the same porch-- it's changed, it's different, > > > >and it's the same. ?However, if you haul off the porch and put a new > > > >one in its place, it's not. ?('porch[:]=' vs. 'porch='.) ?You can't > > > >just look at the initial and final configurations of matter to > > > >determine so. ?Therefore, 'id' is an informal function. > > > > This analogy describes the "ontological minefield" I was referring to > > > in a previous post in this thread (which has expired in my mail > > > reader, so my apologies if the threading goes awry): In what sense is > > > a porch (or list, or string) the same if all (or even some of) its > > > parts have been exchanged? > > > > I think the answer is something to do with the abstraction, the > > > "container", the instance of the class. > > That seems reasonable. When you say alist[:] = [1, 2, 3] the container > remains "the same", while the contents change. > > > > Would it be fair to say that perhaps there are no > > > truly mutable objects, only immutable containers whose contents (also > > > immutable objects themselves) may be exchanged? Or to pose the > > > question another way, are objects only mutable insofar as they are > > > composite? > > That depends on what you mean by composite. Everything is composite in > some sense, even a single bit in memory has a physical reality made of > atoms with magnetic fields. But taken as an abstract entity, it is > reasonable to treat a single bit as an atomic non-composite thing, and a > single bit is mutable. > > In practice, actual Python objects tend to be mutable only if they are > composite (although being composite doesn't make them mutable -- consider > frozen sets and tuples). In principle, this is not necessary. There's no > reason why Python couldn't expose a single bit as a data type, so you > could write this: > > >>> n = bit(1) > >>> bool(n) > True > >>> n.flip() > >>> bool(n) > > False > > > > As you argue above, the planks are not the porch; I would add that > > > it's your _decision_ to build (or tear down) a porch which makes it > > > _that_ ?particular porch (or not). > > No, there's no such decision needed. Perhaps a hurricane comes through > and rips the porch up. Maybe a rogue television crew comes by while > you're at work and renovates your house without your knowledge. > > The lack of decision-making needed is more obvious when you consider > something like a fast-flowing river. The specific water molecules making > up the river at any particular instant in time flow away in a matter of > days or weeks, but rivers have a continuity of existence measured in > thousands of years. I trust that nobody is going to argue that the river > makes any decisions at all? > > > > As you imply above (I think), you have to keep looking (or someone > > > does, presumably the interpreter) to know whether an object is the > > > same as or just equal to another (which starts to sound spookily like > > > the role of "the observer" in phenomenology or quantum physics). > > No, I think you're introducing mysticism here that isn't needed. A bit > like quantum mechanics, really :) > > In Python, every object has an identity and a value. If objects X and Y > have the same identity, they are the same object. If X is the object with > id 1234, and Y is the object with id 1234, then both are the same object. > If their ids are different, then they are not. > > In CPython, the id is given by the memory location of the object, which > leads to a very intuitive understanding of "same": the object with id > 1234 is at memory location 1234, and since there can only be one object > at a particular memory location at a time, obviously all objects with id > 1234 must be the same object (provided they exist simultaneously). > > (To be pedantic, there can't actually be objects [note plural] existing > simultaneously with the same id. There can only be multiple references to > the one object.) > > In Python implementations where the id is not a memory address > (IronPython and Jython I think?) the above remains true, even though > there isn't the simple intuitive picture of "only one object can be at a > specific memory address". Python guarantees that the id is *something* > which is guaranteed to be unique over the lifetime of every object. > > Actually, our intuition about one thing per place at the one time is not > strictly correct. Consider the memory address 1234, which currently has > the value in hex of 0x58. That byte may be the numeric value 88, the > ASCII char "X", the set of flags 1011000, or any other thing, depending > on what interpretation we give to it. "What a thing is" is actually a > more difficult question than it appears at first glance. > > [...] > > > I think the key ingredient is that there's no such thing as side > > effect in math. > > I don't see that this is relevant. We're not talking about mathematical > equality, but about the more general concepts of identity and sameness. > > > In example, > > > a= [0, 1, 2] > > a[:]= [3, 4, 5] > > > There aren't many natural language senses in which 'a' is the same > > object as before. > > Of course there are. > > If I have a box containing three things (a piece of paper with the number > "0" written on it, a plastic block in the shape of "1" and a tally stick > with two notches cut in it), and then I remove those three things and > replace them with something else, it's the same box. > > The English and Australian cricket teams have been playing international > Test cricket since 1877. None of the team members playing in 1877 are > still alive today. The entire lineup of both cricket teams has been > replaced repeatedly, and yet they are the same teams. > > The same holds for many, many different organisations: churches, armies, > regiments, political parties, social clubs, companies, guilds, nations, > sporting teams, secret societies, criminal gangs, ecosystems, tribes, > communities of many sorts, and so forth. > > Far from being rare, this is very common. > > > If I have a leg transplant, I'm the same person, > > but if you replace the entire contents of me, I'm not. > > Every (?) molecule in your body is replaced over a period of > approximately seven years. Some molecules are replaced much quicker, some > a little slower, but speaking roughly, the entire contents of you is > replaced every seven years. Aaron, are you the same person you were a > decade ago? In some sense, not at all -- you're a different person to the > annoying person who called himself "castironpi" and was repeatedly > accused of being a bot only a few months ago. But in another sense, yes, > you are the same person -- there is a continuity of existence. > > See also the Ship of Theseus paradox, otherwise known as My Grandfather's > Axe paradox. > > http://en.wikipedia.org/wiki/Ship_of_Theseus > > [...] > > > The porch is defined by its location, but not exclusively. > > If we remove the porch from the house and transport it whole to another > house, it remains the same porch attached to a different house. > > > Natural > > language identity is a cluster concept, without strict necessary and > > sufficient conditions. ?Nothing really presses our boundaries of it > > that much; there aren't many practical questions that lay out the > > facts, then ask, 'But is it the same?' ?You can replace the porch > > board-at-a-time, and it is; and you can haul it somewhere and it is. > > But rearrange the same boards, and it's not. > > I think you overstate your case. If you move the boards around on the > porch, it remains the same porch. Likewise if I have a chest of drawers, > and I take the top drawer and put it at the bottom, the bottom drawer in > the middle and the middle drawer at the top, surely it is the same chest > of drawers? I haven't even replaced anything, just moved them around. > > > Continuity of form is > > probably the prevalent feature, which as you state, does break down in > > the case of composite (piece-wise) transformations. > > I think continuity of form is an important factor in deciding what is the > same and what is not, but I don't think it is the only one. See for > example the anecdote about the Japanese temple in the Wikipedia article > above. And I think you're wrong to say that piece-wise transformations > break down continuity of form. You are, in some sense, the same person > who some years ago was a crawling baby unable to speak. There are > significant changes and replacements and add-ons that nevertheless don't > break continuity. > > > You might get farther comparing container objects to spots on a > > bulletin board. ?The only thing that goes 'in' a container is a > > denoting phrase to another object (and by the way, not a description); > > the other also has its own spot independently on the board. > > That's a reasonable analogy for the implementation of CPython, but it > need not be the only implementation. It wouldn't be fast, or efficient, > or reasonable, but one could create a Python implementation where (for > example) a list didn't just hold pointers to objects, but it held the > actual entire object (no matter how large). Identity could be divorced > from memory location: the one object could exist in many different places > in memory, in the same way that an object can exist in many different > times. The underlying VM would ensure that all such instantiations of the > one object remained in sync at all time. > > Such an implementation would be inefficient and foolish, but it would > still be Python. > > Having said that, it is perfectly valid to ignore the implementation when > describing how Python operates. It really doesn't matter whether CPython > is implemented like a bulletin board or not, it behaves as if it were, > and that makes it a reasonable analogy. > > -- > Steven Hi, a bit behind in the discussion. (What'd I miss?) I think it would be funny in math if someone said, "No, the answer is *that* five, not this one," or "Don't use that five, use this other one." You can use either one. Containers are funny in Python in that 'a in a' can be true. It can't in real containers. Also true in 'a in b and a in c and b is not c' (and 'b not in c' technically). About the porch, you could rearrange some of the boards into a swing or porch door or something, and it's not the same; even though you have the same boards. In the Grandfather's Axe story, you could divide the blade into two, and reattach both halves. It's the same material, but in a different configuration. And here's a funny example of the usage of 'same'. -- X and Y have the same teacher. -- X and Y have the same shower curtain. -- X and Y have the same car. -- X and Y have the same shirt. -- X and Y have the same shirt on. Do you think that context determines the meaning of all of these; that is, that they never lead to confusion? Do you think they're common to say, or do people find other ways, to avoid confusion? The meaning of 'same' varies from one to another, without syntactical markings. I want to conclude that 'equality' and 'identicality' (sharing an identity) are two of the meanings of same, and closely related enough that they can be confusing for neophyte programmers. 'J and K are not the same, just the same.' I think earlier, when John said, you have to keep an eye on the porch to know if it's the same between two points in time, he was observing that 'id([])==id([])' can be true. The porch was secretly wrecked and rebuilt overnight. 'Same' isn't too far down in frequency (U.K. corpus). http://ucrel.lancs.ac.uk/bncfreq/lists/2_2_spokenvwritten.txt > actual entire object (no matter how large). Identity could be divorced > from memory location: the one object could exist in many different places > in memory, in the same way that an object can exist in many different Yes, and it's even possible that multiple objects could exist in the same place, such as in a copy-on-write. > above. And I think you're wrong to say that piece-wise transformations > break down continuity of form. You are, in some sense, the same person > who some years ago was a crawling baby unable to speak. There are It's common enough to say, 'He's not the same person around his parents.' > porch, it remains the same porch. Likewise if I have a chest of drawers, > and I take the top drawer and put it at the bottom, the bottom drawer in > the middle and the middle drawer at the top, surely it is the same chest > of drawers? I haven't even replaced anything, just moved them around. Surely. But what if you remove them, and exchange them with new drawers? > The English and Australian cricket teams have been playing international > Test cricket since 1877. None of the team members playing in 1877 are > still alive today. The entire lineup of both cricket teams has been > replaced repeatedly, and yet they are the same teams. Yet, you could comfortably say, 'The team's not the same without Michael Jordan (star player)'. I don't think identity is indestructible. Over the years, the ballpark, name, uniform, fan base, manager, owner, and players have *all* changed. Not the same. There's a famous psychology example about a brain injury, after which the subject's friends said, 'He's not the same man anymore', and 'It just isn't him.' I don't remember if they (his friends) were native speakers or not. From grante at visi.com Mon Jan 5 21:06:41 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:06:41 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> Message-ID: On 2009-01-05, Jonathan Gardner wrote: > On Jan 5, 2:26?pm, Kangkook Jee wrote: >> >> I'd like to measure number of bytes sent(or recv'd) from my >> python application. Does anyone have any idea how can I >> achieve this? >> >> I tried to do this by tracing some socket calls (send, sendto, >> sendAll) using 'metaclass' but I could find exactly place that >> I can put this in. >> >> My application runs some number of protocols (bittorrent, >> xmlrpc ..) in it and will be measured for a couple of hours. > > A good universal tool on the Linux platform is tcpdump. It takes some > learning, but is very useful for this kind of task. You can use a tool > like ethereal to visualize the data that tcpdump gathers. Ethereal has been called wireshark for quite a while now. It can be used to capture the traffic as well as to visualize it. Wireshark is available for both Linux and Windows. -- Grant From grante at visi.com Mon Jan 5 21:08:25 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:08:25 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: On 2009-01-05, Kangkook Jee wrote: > Jonathan Gardner wrote: >> On Jan 5, 2:26 pm, Kangkook Jee wrote: >>> I'd like to measure number of bytes sent(or recv'd) from my python >>> application. Does anyone have any idea how can I achieve this? >>> >>> I tried to do this by tracing some socket calls (send, sendto, sendAll) >>> using 'metaclass' but I could find exactly place that I can put this in. >>> >>> My application runs some number of protocols (bittorrent, xmlrpc ..) in >>> it and will be measured for a couple of hours. >>> >> >> A good universal tool on the Linux platform is tcpdump. It takes some >> learning, but is very useful for this kind of task. You can use a tool >> like ethereal to visualize the data that tcpdump gathers. > > Thanks a lot Jonathan > > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? You can't predict ahead of time what hosts/ports that your application is going to be using? > I'm still struggling to solve it within python process since > it looks cleaner but it doesn't seems to be easy at all. I don't why adding bunches of code to your app would be "cleaner" than gathering data using external programs. -- Grant From grante at visi.com Mon Jan 5 21:14:26 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 05 Jan 2009 20:14:26 -0600 Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: On 2009-01-05, Kangkook Jee wrote: > I'd like to measure number of bytes sent(or recv'd) from my > python application. Does anyone have any idea how can I > achieve this? Aside from tcpdump/wireshark, you can set up iptables rules to enable accounting for traffic based on IP addresses and ports. http://wiki.openvz.org/Traffic_accounting_with_iptables http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html http://www.catonmat.net/blog/traffic-accounting-with-iptables/ -- Grant From steven at REMOVE.THIS.cybersource.com.au Mon Jan 5 21:16:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 02:16:50 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Tue, 06 Jan 2009 01:24:58 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I've already mentioned NaNs. Sentinel values also sometimes need to >> compare not equal with themselves. Forcing them to compare equal will >> cause breakage. > > There's a conflict between such domain-specific considerations (NaNs, > strange sentinels, SAGE's equations), and relatively natural assumptions > about an == operator, such as it being an equivalence relation. Such assumptions only hold under particular domains though. You can't assume equality is an equivalence relation once you start thinking about arbitrary domains. > I don't know how to resolve this conflict without introducing a new > function which is (or at least strongly encourages developers to arrange > for it to be) an equivalence relation. But there cannot be any such function which is a domain-independent equivalence relation, not if we're talking about arbitrarily wacky domains. Even something as straight-forward as "is" can't be an equivalence relation under a domain where identity isn't well-defined. -- Steven From gagsl-py2 at yahoo.com.ar Mon Jan 5 21:42:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 00:42:38 -0200 Subject: idle 3.0 unicode References: <495C7AC6.1000506@post.cz> Message-ID: En Thu, 01 Jan 2009 06:11:50 -0200, Pavel Kosina escribi?: > In 3.0 there is an error. The same program, moved to 3.0 syntax, in > IDLE editor : > # -*- coding: utf-8 -*- > print ("?????????") > > prints: > ?????????????????? > > The same program without coding declaration (but saved in utf8) : > print ("?????????") > > even immediately destroyed my IDLE window without any error message. There are some unicode-related errors reported for IDLE and 3.0, but I could not find this one. Better to file a bug report at http://bugs.python.org -- Gabriel Genellina From workingpad at gmail.com Mon Jan 5 21:42:58 2009 From: workingpad at gmail.com (Jack.Chu) Date: Mon, 5 Jan 2009 18:42:58 -0800 (PST) Subject: My last working day of 2007 References: <2d14a579-9011-40ce-ad81-085b6b619f94@b38g2000prf.googlegroups.com> <49627e48$0$21839$426a34cc@news.free.fr> Message-ID: <0bac21a4-85bb-4533-9418-690e881e29c7@v5g2000prm.googlegroups.com> Actually I want to put the funny statistic on web. It means create a simple website and show informations such as that picture. But the hard job is I don't know how to collect the log info from client. If I have to install something I don't think people would dare to install it - it is too dangerous to use, and without big benefit. From eric.pruitt at gmail.com Mon Jan 5 21:55:37 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Mon, 5 Jan 2009 20:55:37 -0600 Subject: Diff Across Multiple Files Message-ID: <171e8a410901051855k7b5bed5l6ca58d0a1eda32e1@mail.gmail.com> I am looking for a way to diff across multiple files; on average around 30 to 60 using python and probably the diff library so that we could see what is common between all files and sort of ignore the differences. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Jan 5 21:58:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 00:58:58 -0200 Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: En Sat, 03 Jan 2009 02:55:12 -0200, Kottiyath escribi?: >> tuples = [(1, 2), (3, 4, 5), (6, 7)] > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. What about using another data structure instead - like this: class entry: filename = None def __init__(self, name, value, filename=None): self.name = name self.value = value if filename is not None: self.filename = filename [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, 'path/to/file')] -- Gabriel Genellina From aleksandr.goretoy at gmail.com Mon Jan 5 22:00:01 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:00:01 -0600 Subject: Measuring bytes of packet sent from python application In-Reply-To: References: <49628901$0$90271$14726298@news.sunsite.dk> Message-ID: You can alot run "lsof -i -T -n" from popen2 to see what applications use what port and addr they are connected to. In order to see all jobs though it needs to be ran as root. This way you can find out what ports and such Then perform tcp dump thru popen2 and filter for port and addr. This is just a first shot, then I would figure out what to do after having gotten to this point. import popen2 #find out what ports and addrs what program is connected to r,w,e=popen2.popen3("lsof -i -T -n") # this may need sudo prepended to lsof r=r.readlines() e=e.readlines() #get tcpdump, doesn't quiet work here....needs something more, maybe a different way altogether. #tcpdump to pcap file and read file periodically? r1,w1,e1=popen2.popen3("sudo tcpdump -i eth1") r1=r1.readlines() e1=e1.readlines() Something to this nature, then do regular expression on tcpdump output, either logged to pcap output file or by other means. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 8:14 PM, Grant Edwards wrote: > On 2009-01-05, Kangkook Jee wrote: > > > I'd like to measure number of bytes sent(or recv'd) from my > > python application. Does anyone have any idea how can I > > achieve this? > > Aside from tcpdump/wireshark, you can set up iptables rules to > enable accounting for traffic based on IP addresses and ports. > > http://wiki.openvz.org/Traffic_accounting_with_iptables > http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html > http://www.catonmat.net/blog/traffic-accounting-with-iptables/ > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Mon Jan 5 22:04:21 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 5 Jan 2009 21:04:21 -0600 Subject: Is there a better algorithm? In-Reply-To: References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: > > class entry: > filename = None > > def __init__(self, name, value, filename=None): > self.name = name > self.value = value > if filename is not None: > self.filename = filename > > [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, > 'path/to/file')] Gabriel thank you for this. I just now realized I've being doing things the hard way. :) -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 5, 2009 at 8:58 PM, Gabriel Genellina wrote: > En Sat, 03 Jan 2009 02:55:12 -0200, Kottiyath > escribi?: > > tuples = [(1, 2), (3, 4, 5), (6, 7)] >>> >> >> It is a code to post some data to HTML server. >> Even though usually the POST values are of type(name, value), if file >> transfer is involved, then POST values change to (name, filename, >> value). >> My view was that since filename is a rare occurance and doesnt make >> sense in a usual POST, I had not kept it as a full 3 tuple. >> Since so many programmers (that too much more capable than me) are >> suggesting that it is code smell, I am reviewing my decision. >> > > What about using another data structure instead - like this: > > class entry: > filename = None > > def __init__(self, name, value, filename=None): > self.name = name > self.value = value > if filename is not None: > self.filename = filename > > [entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data, > 'path/to/file')] > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerb at rogerbinns.com Mon Jan 5 22:16:26 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 05 Jan 2009 19:16:26 -0800 Subject: Measuring bytes of packet sent from python application In-Reply-To: <4962965f$0$90276$14726298@news.sunsite.dk> References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Kangkook Jee wrote: > That seems like a good solution for my issue but how can I distinguish > traffics from my application to others? I use nethogs on Ubuntu. If you use Intrepid, you can press 'm' to make it change amongst different displays (eg cumulative traffic, send/receive rates etc). Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAklizQYACgkQmOOfHg372QQc2gCgiMCeY1X9Qd/Fyh77SuDUNPqx 7lkAn1ozstsf2542+OuFuBC54vtOaaUR =qSxN -----END PGP SIGNATURE----- From gagsl-py2 at yahoo.com.ar Mon Jan 5 22:24:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 01:24:14 -0200 Subject: multiprocessing vs thread performance References: Message-ID: En Sat, 03 Jan 2009 11:31:12 -0200, Nick Craig-Wood escribi?: > mk wrote: >> The results I got are very different from the benchmark quoted in PEP >> 371. On twin Xeon machine the threaded version executed in 5.54 secs, >> while multiprocessing version took over 222 secs to complete! >> >> Am I doing smth wrong in code below? > > Yes! > > The problem with your code is that you never start more than one > process at once in the multiprocessing example. Just check ps when it > is running and you will see. Oh, very good analysis! Those results were worriying me a little. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 5 22:44:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 01:44:18 -0200 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: En Mon, 05 Jan 2009 02:03:26 -0200, Roy Smith escribi?: > The other day, I came upon this gem. It's a bit of perl embedded in a > Makefile; this makes it even more gnarly because all the $'s get doubled > to > hide them from make: > > define absmondir > $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print \\\$$1}"`; > chomp($$prefix); \ > ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ > ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ > ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! ); > } \ > ?? return unslash(undot(undotdot($$a))); }; \ > sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; > return($$_[0]); > }; \ > sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ > sub undotdot ($$) { my $$in = $$_[0]; \ > ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ > print absmon("$(1)","$(2)"); \ > ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > endef > > Barf-o-rama. I know what it's supposed to do, and I still can't figure > it out. Ouch! Me too, when I come to some piece of Perl code I've written some years ago, I invariably think "what's all this noise?". Never happens with other languages I've used in the past. -- Gabriel Genellina From truelixin at gmail.com Mon Jan 5 23:30:42 2009 From: truelixin at gmail.com (truelixin at gmail.com) Date: Mon, 5 Jan 2009 20:30:42 -0800 (PST) Subject: About PyOpenGL References: Message-ID: <1311f0d4-f0b1-4e82-b66b-014988609e59@n33g2000pri.googlegroups.com> On Jan 6, 12:58?am, Rob Williscroft wrote: > trueli... at gmail.com wrote in news:f8099226-a953-4598-bfe2-61ee5772ce26 > @l33g2000pri.googlegroups.com in comp.lang.python: > > > > > > > Traceback (most recent call last): > > ? File "test.py", line 36, in > > ? ? main() > > ? File "test.py", line 26, in main > > ? ? glutInit(sys.argv) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\GLUT\special.py", line 316, in glutInit > > ? ? _base_glutInit( ctypes.byref(count), holder ) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\GLUT\special.py", line 57, in _base_glutInit > > ? ? return __glutInitWithExit(pargc, argv, _exitfunc) > > ? File "c:\python25\lib\site-packages\PyOpenGL-3.0.0b8-py2.5-win32.egg > > \OpenGL\platform\baseplatform.py", line 280, in __call__ > > ? ? self.__name__, self.__name__, > > OpenGL.error.NullFunctionError: Attempt to call an undefined function > > __glutInitWithExit, check for bool(__glutInitWithExit) before calling > > To get you code running I needed (in addition to the PyOpenGL download) > to download. > > glut-3.7.6-bin.zip (117 KB) fromhttp://www.xmission.com/~nate/glut.html > > and put the glut32.dll where python can find it, the readme says > \system which worked, but sticking it in the same directory > as python.exe (c:\python25 in your case) worked too. > > http://pyopengl.sourceforge.net/http://pyopengl.sourceforge.net/documentation/installation.html > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Yeah! It works now! Thank you very much! From tjreedy at udel.edu Mon Jan 5 23:45:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jan 2009 23:45:10 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <0164a0d4-97c9-4be1-a948-4e5b0deb9585@b38g2000prf.googlegroups.com> <8bbf7133-92b2-43ef-9149-3cb8d63c7f79@40g2000prx.googlegroups.com> <01705c07$0$8693$c3e8da3@news.astraweb.com> Message-ID: Aaron Brady wrote: > > Containers are funny in Python in that 'a in a' can be true. > It can't in real containers. Guido uses 'container' in the Ref Manual because such 'contain' references (of an undefined nature). Thinking more abstractly, I use 'collection', rather that 'container' and think of the object as a 'roster' -- like for the members of a club. A bibliography of bibliographies could list itself but would only metaphorically 'contain' itself. An association of associations could conceivably be a member of itself. tjr From pythonnutter at gmail.com Tue Jan 6 02:11:40 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Tue, 6 Jan 2009 18:11:40 +1100 Subject: SSL certificate parsing? In-Reply-To: References: Message-ID: If no one answers, the way I do my work with certificates is I just wrap OpenSSL myself by doing a popen call (probably now should be using subprocess for any future scripts I write). I then redirect the output that normally goes to the shell window into a buffer then I search/slice out the fields using standard Python string searching. You could go to regex's but its overkill in my opinion if you can simply do standard string searches. The buffer always follows a set pattern so you are not going to have to search wildly varying output from OpenSSL call to OpenSSL call. I looked at PyOpenSSL but I have country specific OIDs that are standard by not in the default ISO standard. Most libraries fall short on supporting what I need and it was brain dead easy to just call OpenSSL in my script directly and capture the output for parsing. Its up to you what you want to do with the extracted information, you could just populate a dict with it and perhaps shelve or store it for later use if you have such a need or as in my case since I only process the certificates once I just use the parsed information immediately in my scripts logic decision tree(s) to create various output. Cheers, PN 2009/1/5 Taras Ivashchenko : > Hello, list! > > I use pyopenssl [0] for checking SSL certificates. > And one of such checks is if given certificate is self-signed. > I can do it using values of X509v3 extensions: the subject key identifier and > the authority key id: > X509v3 Subject Key Identifier: > 0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 > X509v3 Authority Key Identifier: > keyid:0E:D4:AA:B1:09:91:7C:36:60:EA:56:4E:9C:57:00:AF:9C:4D:02:00 > > I read documentation of pyOpenSSL but I didn't find way how to grub > this information > from certificate using, for example, methods of X509 object. > > May be there is another way to parse SSL certificates? > I will be glad to get ever text version of given SSL certificate :) > > [0] http://pyopenssl.sourceforge.net/ > > P.S. I already wrote to pyopenssl mailing list, but there is now > answer there :( > > ????? ???????? (Taras Ivashchenko) > -- > "Software is like sex: it's better when it's free.", - Linus Torvalds. > -- > http://mail.python.org/mailman/listinfo/python-list > From david at crouse.us Tue Jan 6 02:41:58 2009 From: david at crouse.us (David Crouse) Date: Tue, 6 Jan 2009 01:41:58 -0600 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Message-ID: <596da3790901052341yd74400ard4b621a3b67618c6@mail.gmail.com> I use Arch Linux, it has Python 3.0 and 2.6 and 2.4. Below are some common packages and their version numbers. I wouldn't however recommend Arch to a new Linux user, it's not Ubuntu. However once installed and configured, it's very easy to maintain. python3 3.0-3 python 2.6.1-1 python24 2.4.6-1 wxpython 2.8.9.1-1 pykde 3.16.2-1 pygtk 2.13.0-2 pyqt 4.4.4-1 eric 4.2.4a-1 scite 1.77-1 ipython 0.9.1-1 python-cheetah 2.0.1-2 django 1.0.2-1 cherrypy 3.1.1-1 pil 1.1.6-5 pylint 0.15.2-1 beautiful-soup 3.1.0-1 On Mon, Jan 5, 2009 at 7:16 PM, Lex Hider wrote: > Probably not a big difference in most cases between debian, ubuntu, > fedora. The latter two may be more likely to have more recent > versions. > > I'm pretty sure ubuntu is the only one which currently has python 3.0 > in it's archives [no, it's not the default version]. > > On 06/01/2009, member thudfoo wrote: >> One with all the major python GUIs: pyQT, pyGtk, pyKde, wxPython, .... >> And so on. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > From electronixtar at gmail.com Tue Jan 6 03:09:24 2009 From: electronixtar at gmail.com (est) Date: Tue, 6 Jan 2009 00:09:24 -0800 (PST) Subject: ctypes to customize MSN now playing status Message-ID: <2ab68e63-ad77-46d5-9323-cfc88ad4f712@i18g2000prf.googlegroups.com> Hi guys, I am trying to switch MSN/WLM now playing status using ctypes with python, here's my code import ctypes, win32con, win32api, win32gui FindWindow = ctypes.windll.User32.FindWindowA SendMessage = ctypes.windll.User32.SendMessageA hWnd = FindWindow('MsnMsgrUIManager', None) s = u"\\0Music\\01\\0{test}\\0\\0\\0\\0\\0" class MsnData(ctypes.Structure): _fields_ = [("dwData", ctypes.c_int), ("cbData", ctypes.c_int), ("lpData", ctypes.c_wchar_p), ] msndata = MsnData(0x547, 256, ctypes.c_wchar_p(s)) SendMessage(hWnd, win32con.WM_COPYDATA, 0, ctypes.byref(msndata)) The code is not working, could anybody help? From guillaume.aubert at gmail.com Tue Jan 6 03:24:49 2009 From: guillaume.aubert at gmail.com (guss) Date: Tue, 6 Jan 2009 00:24:49 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> Message-ID: <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> hi Thanks for the tip but I had to play with the __import__ func a bit. Indeed to load not only the top module with __import__ one needs to try to load an object from the module: Here is my forname: def forname(modname, classname): module = __import__(modname,globals(),locals(),['NoName'],-1) classobj = getattr(module, classname) return classobj Like that I can load MyError from the module org.myapp.exceptions >>> c = forname('org.myapp.exceptions','MyError') >>> instance = c('My Message') If I do not put 'NoName' that is a fake object only module will be org and not org.myapp.exceptions. This is strange ? I think Python has all the elements for doing java like reflection and introspection and even more but the API is not as mature and it is quite difficult to find the information. There is the need for a high level API. Maybe it already exists, if anyone knows please tell me. Thanks. Guillaume On Jan 5, 5:34?pm, Bruno Desthuilliers wrote: > guss a ?crit : > > > > > I cannot find a satisfying answer to this question on the web so let's > > try here. > > > My problem is the following, I would like to instantiate some object > > from a configuration file that would contain class names like for > > example classname=org.common.resource.MyResource. > > Here my resource is the class to instanciate and it is in the module > > resource that is in a package hierachy. > > > In fact I would like to do something very similar to the Java: > > > klass = Class.forname("org.common.resource.MyResource") > > > instance = klass.newInstance() > > > The second line is easy once I have a classobj but I have some > > problems to find the right recipe for getting it. > > > I know how to create a class from scratch with new.classobj but how do > > you get a class object and then create an object ? > > > I would like a recipe working for all cases (whatever the module is > > not the local one ...) > > use __import__ to get the module object, then getattr(module, classname) > to get the class object (sorry, no much time right now to give you a > full recipe, but that should be enough to get you started). > > HTH From nawijn at gmail.com Tue Jan 6 03:26:13 2009 From: nawijn at gmail.com (Marco Nawijn) Date: Tue, 6 Jan 2009 00:26:13 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <32ed6add-2266-498d-b9a9-96b6b426dc15@g1g2000pra.googlegroups.com> On Jan 5, 10:57?am, Sandro Tosi wrote: > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? > - what would you like to see in a book about matplotlib? > - what are some those advanced feature that made you yell "WOW!!" ? > - what are the things you'd like to explore of matplotlib and never > had time to do? > > Your suggestions are really appreciated :) And wish me good luck! Hello Sandro, I am happy to hear that there might be a book on Matplotlib. I am using Matplotlib for a while now and find it a very usefull and powerfull library for generating graphs. I will try to answer some of your questions. I am by no means an expert in the field, so I only express my personal experience. >> What are you using matplotlib for? I currently use Matplotlib to generate a series of graphs that visualise data channels (strain measurements) during a structural test. These graphs need to be refreshed about every 4 seconds. Each of the graphs contains 1 to 6 curves. >> What are the things you like the most of matplotlib, that you want to give emphasis to? And why? In general I like the most the fact that I can generate high quality publication ready graphs with a consistent look with minimal effort. Further, although the matlab-style commands are very usefull I think the class interface is more powerfull. The class interface also has a steeper learning curve. So, for me it would be very interesting if much emphasis will be on the class interface. >> What are the (basic) things that, when you were beginning to use matplotlib, you wanted to see grouped up but couldn't find? I seriously hope the book is not for "dummies", but provides at least a significant amount of information on more advanced features of Matplotlib. I think the currently available tutorials are sufficient to getting started. From my point of view I am very interested in: - Dynamically updating a series of graphs - Configuring layout of graphs (colors, labels, legends, etc.) - Managing dimensions of the figure when you export the figure to e.g PNG. For me this is interesting in the sense that if I insert a figure in a report/paper, I would like that the fonts used in the graph remain proportional to the surrounding text. If you need more information please let me know. I wish you good luck! Kind regards, Marco From jstroud at mbi.ucla.edu Tue Jan 6 03:33:31 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:33:31 -0800 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: Sandro Tosi wrote: > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? Matplot lib shines for interactive environments wherein graphs and charts must be produced. I have incorporated it into a simple program for analysis of fluorometric data: http://fluorit.bravais.net/ (The forthcoming version 1.0 is a quantum improvement in speed and function over the SLOW *prototype* version 0.9 currently available--see the wish list, feature requests, and known issues for details. Version 1.0 is very fast.) > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? The ability to embed a figure (composed of subplots) into a custom window is my favorite aspect. Also: massive configurability of plots, event driven plot canvas, antigrain geometry antialiasing are also all very important. Additionally the toolbar of standard interactive functions and the ability to export plots in a variety of formats are also invaluable features. > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? The documentation for basic plot configuration, especially for embedded plots, and also tapping into the event model is very weak currently. These need the most improvement. > - what would you like to see in a book about matplotlib? A big, huge, gigantic, chapter---no make that 3 chapters--on programming interactivity with the plot canvas. > - what are some those advanced feature that made you yell "WOW!!" ? I listed them above, but my most "WOW" moment was when I saw the Tkinter backend doing beautiful antialiasing. I was also very happy to seamlessly add new functionality to the toolbar. > - what are the things you'd like to explore of matplotlib and never > had time to do? I want to program a lot of interactivity with the plots in my current application. > Your suggestions are really appreciated :) And wish me good luck! Good luck! I can't wait to read your book! James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From narkewoody at gmail.com Tue Jan 6 03:38:16 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 6 Jan 2009 16:38:16 +0800 Subject: __builtin__ quote Message-ID: Hi, I am a new leaner and I get a question: abs() is a member of __builtin__ module, but why should I use abs() rather than __builtin__.abs() ? Thanks. From jstroud at mbi.ucla.edu Tue Jan 6 03:42:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:42:53 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: Steven Woody wrote: > Hi, > > I am a new leaner and I get a question: abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. It saves typing. This might help your understanding: py> import __builtin__ py> __builtin__.abs is abs True James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bj_666 at gmx.net Tue Jan 6 03:47:00 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 6 Jan 2009 08:47:00 GMT Subject: Tkinter - problem closing window References: Message-ID: <6sgk44F5qmm8U2@mid.uni-berlin.de> On Mon, 05 Jan 2009 12:25:53 -0200, Djames Suhanko wrote: > I has a litle program that open another window. When I close de root > window in quit button, I need clicking 2 times to close. is where the > problem? > > [?] > > 17 def gera_seis(self): > 18 a = {} > 19 for i in range(6): > 20 a[i] = "%02d" % int (random.randint(0,60)) > 21 resultadoA = "%s-%s-%s-%s-%s-%s" % > (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) > 22 return resultadoA Not the problem but unnecessary complex. `random.randint()` already returns an int, no need to call `int()` on it. The string formatting with ``%`` returns strings, so there is no need to call `str()` on the values. Even if the values where not strings: The '%s' place holder implies a call to `str()` while formatting. If you put something into a dictionary with consecutive `int` keys, you might use a list instead. All this can be written as a simple one liner:: '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) > 24 def say_hi(self): > 25 resultado = self.gera_seis() > 26 raiz = Tk() The problem is here? > 27 F = Frame(raiz) > 28 F.pack() > 29 hello = Label(F, text=resultado) 30 hello.pack() > 31 F.mainloop() ?and here. There is only one `Tk` instance and mainloop allowed per `Tkinter` application. Otherwise really strange things can happen. Additional windows have to be created as `Toplevel` instances. Ciao, Marc 'BlackJack' Rintsch From narkewoody at gmail.com Tue Jan 6 03:47:57 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 6 Jan 2009 16:47:57 +0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: > Steven Woody wrote: >> >> Hi, >> >> I am a new leaner and I get a question: abs() is a member of >> __builtin__ module, but why should I use abs() rather than >> __builtin__.abs() ? Thanks. > > It saves typing. > > This might help your understanding: > > py> import __builtin__ > py> __builtin__.abs is abs > True > Does that mean someone did 'import * from __builtin__' when python startup? From clp at rebertia.com Tue Jan 6 03:50:16 2009 From: clp at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 00:50:16 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <47c890dc0901060050o69360e40ida6e097bff9da605@mail.gmail.com> On Tue, Jan 6, 2009 at 12:47 AM, Steven Woody wrote: > On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: >> Steven Woody wrote: >>> >>> Hi, >>> >>> I am a new leaner and I get a question: abs() is a member of >>> __builtin__ module, but why should I use abs() rather than >>> __builtin__.abs() ? Thanks. >> >> It saves typing. >> >> This might help your understanding: >> >> py> import __builtin__ >> py> __builtin__.abs is abs >> True >> > > Does that mean someone did 'import * from __builtin__' when python startup? In a sense, yes. The interpreter effectively automatically does such an import. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From cournape at gmail.com Tue Jan 6 03:51:53 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 6 Jan 2009 17:51:53 +0900 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> Message-ID: <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> On Tue, Jan 6, 2009 at 10:16 AM, Lex Hider wrote: > Probably not a big difference in most cases between debian, ubuntu, > fedora. The latter two may be more likely to have more recent > versions. > > I'm pretty sure ubuntu is the only one which currently has python 3.0 > in it's archives [no, it's not the default version]. OTOH, it does not have python 2.6 yet, which is a bit annoying. cheers, David From clp at rebertia.com Tue Jan 6 03:52:06 2009 From: clp at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 00:52:06 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <47c890dc0901060052m13053526ube60edaaf90a43bf@mail.gmail.com> On Tue, Jan 6, 2009 at 12:38 AM, Steven Woody wrote: > Hi, > > I am a new leaner and I get a question: abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. To clarify, having __builtin__ is just the language's way of reifying the notion of "built-in functions" in the form of a special module. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apardon at forel.vub.ac.be Tue Jan 6 03:53:12 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Jan 2009 08:53:12 GMT Subject: ftp seems to get a delayed reaction. Message-ID: I'm not sure if this is a python problem or something else. I'm trying with the use of ftplib to get a dump on a remote machine. The dump mirrors the directory structure but instead of the files a bziped tar file is made and transferred. While mirroring the directory structure I don't care to check which directories are already present. I just try to make the directory and catch the exception when it occurs. This worked fine until now. I recently movade the script to a new computer and use a different ftp server. Now it seems the error code for the ftp.mkd is received by the storbinary later on. This is the traceback: Traceback (most recent call last): File "ftpdump", line 141, in main() File "ftpdump", line 133, in main process(path) File "ftpdump", line 90, in process ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl) File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary self.voidcmd('TYPE I') File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.5/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists This is part of the code: # Somethings define somewhere above # # pj = os.path.join # FTPProblem = ftplib.error_temp while problem: try: ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl) fl.close() problem = False except FTPProblem: warn ("reconnecting for %s\n" % cprt) try: ftp.quit() except Exception: pass time.sleep(5) ftpconnect() So what seems to happen is that I call the ftp.storbinary and that I get the mesg: ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists That I should have gotten while doing the ftp.mkd earlier. Can someone shed some light on how to deal with this? -- Antoon Pardon From jstroud at mbi.ucla.edu Tue Jan 6 03:56:36 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 00:56:36 -0800 Subject: __builtin__ quote In-Reply-To: References: Message-ID: <81F8l.4494$jZ1.3657@flpi144.ffdc.sbc.com> Steven Woody wrote: > On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: >> py> import __builtin__ >> py> __builtin__.abs is abs >> True > > Does that mean someone did 'import * from __builtin__' when python startup? In terms of the exact implementation of the cPython interpreter, I don't know. But the interpreter behaves as if someone did just that. So there is nothing wrong with thinking of it this way if it helps you understand the interpreter. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From you680 at gmail.com Tue Jan 6 04:10:28 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 01:10:28 -0800 (PST) Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data Message-ID: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> hi all: when I handled mass data table in mysql with python's MySQLdb lib, something frustrated me. I could't find any function like datareader, which yield one row by recording rows' anchor ,after each time I invoked 'read()' in a loop.fetchall or fetchmany just fetched all data in once, which take so much memory when meeting one mass data table. Is anybody know that function or other lib similar to MySQLdb ? thanks! From alexi.zuo at gmail.com Tue Jan 6 04:12:21 2009 From: alexi.zuo at gmail.com (Alexi Zuo) Date: Tue, 6 Jan 2009 17:12:21 +0800 Subject: Python subprocess question Message-ID: <5259b2e20901060112x4943e946xc4a5871425cbb4ee@mail.gmail.com> Hi everyone, Here I have a simple program which starts a thread and the thread use Popen to execute a shell cmd which needs a long time. I want to stop the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this program enters a dead loop. Can anyone tell me what is wrong? Alex from subprocess import * import threading import time class TestThread(threading.Thread): def run(self): try: while True: p=Popen("for (( i = 0 ; i <= 100000; i++ )); do echo hello; done", shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE,close_fds=True) print p.stdout.readlines() print p.stderr.readlines() except KeyboardInterrupt: print "got ex" print "leave..." a=TestThread() a.start() try: a.join() except: print "gone" From dcml1 at crouse.us Tue Jan 6 04:21:34 2009 From: dcml1 at crouse.us (Dave Crouse) Date: Tue, 6 Jan 2009 03:21:34 -0600 Subject: Is there a best linux distro for a python hobbyist? In-Reply-To: <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> References: <3d881a310901051542m6e3a9cdbv3c45b765780a9735@mail.gmail.com> <9b34f920901051716h2e75cc4jf60bd6388bce4dd7@mail.gmail.com> <5b8d13220901060051q7bfbfb91o65574d54b60df0ed@mail.gmail.com> Message-ID: <596da3790901060121p7015f3ebo540404475196a1a2@mail.gmail.com> My apologies to the list if this is a double post. My email client tried to send with the wrong email address. I use Arch Linux, it has Python 3.0 and 2.6 and 2.4. Below are some common packages and their version numbers. I wouldn't however recommend Arch to a new Linux user, it's not Ubuntu. However once installed and configured, it's very easy to maintain. python3 3.0-3 python 2.6.1-1 python24 2.4.6-1 wxpython 2.8.9.1-1 pykde 3.16.2-1 pygtk 2.13.0-2 pyqt 4.4.4-1 eric 4.2.4a-1 scite 1.77-1 ipython 0.9.1-1 python-cheetah 2.0.1-2 django 1.0.2-1 cherrypy 3.1.1-1 pil 1.1.6-5 pylint 0.15.2-1 beautiful-soup 3.1.0-1 On Tue, Jan 6, 2009 at 2:51 AM, David Cournapeau wrote: > On Tue, Jan 6, 2009 at 10:16 AM, Lex Hider wrote: >> Probably not a big difference in most cases between debian, ubuntu, >> fedora. The latter two may be more likely to have more recent >> versions. >> >> I'm pretty sure ubuntu is the only one which currently has python 3.0 >> in it's archives [no, it's not the default version]. > > OTOH, it does not have python 2.6 yet, which is a bit annoying. > > cheers, > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From pavlovevidence at gmail.com Tue Jan 6 04:29:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 6 Jan 2009 01:29:00 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> Message-ID: <32f65b9f-7cb6-4ba3-8c26-92acf0811a14@s9g2000prm.googlegroups.com> On Jan 6, 2:24?am, guss wrote: > hi Thanks for the tip but I had to play with the __import__ func a > bit. > Indeed to load not only the top module with __import__ one needs to > try to load an object from the module: > > Here is my forname: > > def forname(modname, classname): > ? ? module = __import__(modname,globals(),locals(),['NoName'],-1) > ? ? classobj = getattr(module, classname) > ? ? return classobj > > Like that I can load MyError from the module org.myapp.exceptions > > >>> c = forname('org.myapp.exceptions','MyError') > >>> instance = c('My Message') > > If I do not put 'NoName' that is a fake object only module will be org > and not org.myapp.exceptions. This is strange ? Yes, it's strange. It's that way for historical and logistical reasons. Here's how I'd write the function; no need to specify modname and classname separately. def forname(name): parts = name.split(".") obj = __import__(".".join(parts[:-1])) for part in parts[1:]: obj = getattr(obj,part) return obj > I think Python has all the elements for doing java like reflection and > introspection and even more but the API is not as mature and it is > quite difficult to find the information. > There is the need for a high level API. > > Maybe it already exists, if anyone knows please tell me. > Thanks. I'm going to suggest that the reason high-level reflection APIs are used so often in Java is to compensate for Java's lack of run-time flexibility. If you don't know what class to use or method to call at compile-time, the easiest thing to do is to store the name in a string and use the Reflection API to get at it at run-time. Python, OTOH, is very dynamic, so there is not much demand for spiffy introspection APIs. Functions and classes are ordinary objects, so if you don't know what function to call or class to use at compile-time, you can just pass the objects around. No strings required. So what I'm saying is: the Python developers didn't bother to make an high-level, easy-to-use __import__ because there really isn't much demand for it. Carl Banks From sjmachin at lexicon.net Tue Jan 6 04:38:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 6 Jan 2009 01:38:20 -0800 (PST) Subject: __builtin__ quote References: Message-ID: <7327e5f7-c0d1-4f54-b202-fdc9831a9edd@r10g2000prf.googlegroups.com> On Jan 6, 7:38?pm, "Steven Woody" wrote: > Hi, > > I am a new leaner and I get a question: ?abs() is a member of > __builtin__ module, but why should I use abs() rather than > __builtin__.abs() ? Thanks. Fewer keystrokes. From stefan_ml at behnel.de Tue Jan 6 05:25:59 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Jan 2009 11:25:59 +0100 Subject: Extending Python with C or C++ In-Reply-To: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> References: <669bd36f-ba06-4f66-929f-41ca502656a0@b38g2000prf.googlegroups.com> Message-ID: <496331b8$0$32665$9b4e6d93@newsspool2.arcor-online.net> Ryan wrote: > 3. Extending CPython by connecting it to Python-oblivious code written > in C with Ctypes (Ralf's suggestion is good for this) > 4. Extending CPython by connecting it to Python-aware (and specific) > code using the CPython C-API functions (http://docs.python.org/c-api/) For extending CPython (and possibly connecting it to external C code/libraries) without learning too many new things (Python + a little C should be enough), you can use ctypes if you can accept the runtime overhead and the dependency on the ctypes module (which does not exist in all CPython releases). However, I'd recommend Cython instead, as it gives you very fast and portable code that works with all CPython versions. And Cython code is not any harder to write at all. http://cython.org/ Stefan From dickinsm at gmail.com Tue Jan 6 05:44:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 6 Jan 2009 10:44:56 +0000 Subject: math module for Decimals In-Reply-To: References: <016bf0f4$0$6988$c3e8da3@news.astraweb.com> <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> On Mon, Jan 5, 2009 at 4:50 PM, alex goretoy wrote: > I get this when importing decimal: > > Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) > [GCC 3.4.6] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import decimal > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python2.7/decimal.py", line 138, in > import math as _math > ImportError: No module named math >>>> It's working fine for me. I assume that a simple "import math" also fails? A couple of possibilities: (1) the math module built, but Python is looking in the wrong place for it, for some reason. (2) the math module failed to build. If you look at the end of the make output, you'll probably see some lines that look like the following (but with different modules listed). Python build finished, but the necessary bits to build these modules were not found: bsddb185 gdbm linuxaudiodev ossaudiodev spwd sunaudiodev If math is included in the modules listed, then I'd very much like to know about it. Mark From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 6 06:29:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 06 Jan 2009 12:29:49 +0100 Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data In-Reply-To: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> References: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> Message-ID: <496340a6$0$3533$426a74cc@news.free.fr> Jeremy.Chen a ?crit : > hi all: > when I handled mass data table in mysql with python's MySQLdb lib, > something frustrated me. I could't find any function like datareader, > which yield one row by recording rows' anchor ,after each time I > invoked 'read()' in a loop. I think you want cursor.fetchone(). But read below... > fetchall or fetchmany just fetched all data > in once, which take so much memory when meeting one mass data > table. The cursor object is it's own iterator. So you just have to do: cursor.execute(your_query) for row in cursor: process(row) HTH From nick at craig-wood.com Tue Jan 6 06:31:14 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 06 Jan 2009 05:31:14 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Ralf Schoenian wrote: > Ryan wrote: > > I've been using Python for many years now. It's a wonderful language > > that I enjoy using everyday. I'm now interested in getting to know > > more about the guts (C/C++) and extending it. But, extending python > > still seems like a black art to me. Is there anymore docs or info on > > extending it besides the standard sparse ones (http://www.python.org/ > > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a > > class available? How can I learn more about the guts of python? How > > would one go about following an interest in contributing to the > > development of python. > > It is not exactly what you are looking for but nevertheless I am > thinking the article "Automatic C Library Wrapping -- Ctypes from the > Trenches" may be interesting for you. You can find it in the latest > Python Papers issue or simply following the link: > http://ojs.pythonpapers.org/index.php/tpp/article/view/71 Interesting - I didn't know about h2xml and xml2py before and I've done lots of ctypes wrapping! Something to help with the initial drudge work of converting the structures would be very helpful. ( http://pypi.python.org/pypi/ctypeslib/ ) I gave it a quick go and it worked fine. I had to edit the XML in one place to make it acceptable (removing a u from a hex number). The output of xml2py was an excellent place to start for the conversion, though I don't think I'd want to use an automated process like in the paper above as its output needed tweaking. ... Here are my thoughts on the conversion :- It converted an interface which looked like this (the inotify interface) struct inotify_event { int wd; /* Watch descriptor */ uint32_t mask; /* Mask of events */ uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */ uint32_t len; /* Size of name field */ char name[]; /* Optional null-terminated name */ }; Into this class inotify_event(Structure): pass inotify_event._fields_ = [ ('wd', c_int), ('mask', uint32_t), ('cookie', uint32_t), ('len', uint32_t), ('name', c_char * 0), ] Which is a very good start. However it defined these which clearly aren't portable int32_t = c_int uint32_t = c_uint Whereas it should have been using the ctypes inbuilt types c_int32 c_uint32 Also I don't think c_char * 0 does anything sensible in ctypes, c_byte * 0 is what is required plus a bit of casting. This is a non-standard GNU extension to C though. All that said though, it looks like a great time saver. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From apardon at forel.vub.ac.be Tue Jan 6 06:56:52 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Jan 2009 11:56:52 GMT Subject: ftp seems to get a delayed reaction. References: Message-ID: I have managed to prune the script, so I can post it here: ========================================================== from ftplib import FTP bckrt = "/tmpstor/rcpc42" def process(): print "making directory" try: ftp.mkd('ftp-tst') print "mkdir succeeded" except Exception, ErrMsg: print "mkdir failed: %s" % ErrMsg fl = open("tstfile") print "storing file" ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) fl.close() ftp = FTP('ftphost', 'user', 'passwd') ftp.set_pasv(False) ftp.cwd(bckrt) print "Doing once" process() print "Doing twice" process() ---------------------------------------------------------- And this is the output: ========================================================== Doing once making directory mkdir succeeded storing file Doing twice making directory mkdir failed: 500 '': command not understood. storing file Traceback (most recent call last): File "ftptst", line 24, in process() File "ftptst", line 14, in process ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary self.voidcmd('TYPE I') File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.5/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists From guillaume.aubert at gmail.com Tue Jan 6 07:28:29 2009 From: guillaume.aubert at gmail.com (guss) Date: Tue, 6 Jan 2009 04:28:29 -0800 (PST) Subject: reflection as in Java: how to create an instance from a classname References: <4962368e$0$25548$426a74cc@news.free.fr> <3feba2cc-fa87-457e-a2d0-b7294e127142@m15g2000vbl.googlegroups.com> <32f65b9f-7cb6-4ba3-8c26-92acf0811a14@s9g2000prm.googlegroups.com> Message-ID: <93ada359-2d4f-4064-a7fa-20301b11c6fc@w24g2000prd.googlegroups.com> Hi Carl thanks for your improved forname method. Regarding the high level reflection API, it is true that we don't need an API as complex as in Java considering the dynamic aspect of Python but you have a forname function I needed one so it could be nice to have it (and other services related to reflection and introspection) standardized in an api supported by default by Python. Who doesn't need to load or create a class (a plugin object ...) from a configuration file these days. Cheers Guillaume > On Jan 6, 2:24?am, guss wrote: > > > > > hi Thanks for the tip but I had to play with the __import__ func a > > bit. > > Indeed to load not only the top module with __import__ one needs to > > try to load an object from the module: > > > Here is my forname: > > > def forname(modname, classname): > > ? ? module = __import__(modname,globals(),locals(),['NoName'],-1) > > ? ? classobj = getattr(module, classname) > > ? ? return classobj > > > Like that I can load MyError from the module org.myapp.exceptions > > > >>> c = forname('org.myapp.exceptions','MyError') > > >>> instance = c('My Message') > > > If I do not put 'NoName' that is a fake object only module will be org > > and not org.myapp.exceptions. This is strange ? > > Yes, it's strange. ?It's that way for historical and logistical > reasons. ?Here's how I'd write the function; no need to specify > modname and classname separately. > > def forname(name): > ? ? parts = name.split(".") > ? ? obj = __import__(".".join(parts[:-1])) > ? ? for part in parts[1:]: > ? ? ? ? obj = getattr(obj,part) > ? ? return obj > > > I think Python has all the elements for doing java like reflection and > > introspection and even more but the API is not as mature and it is > > quite difficult to find the information. > > There is the need for a high level API. > > > Maybe it already exists, if anyone knows please tell me. > > Thanks. > > I'm going to suggest that the reason high-level reflection APIs are > used so often in Java is to compensate for Java's lack of run-time > flexibility. ?If you don't know what class to use or method to call at > compile-time, the easiest thing to do is to store the name in a string > and use the Reflection API to get at it at run-time. > > Python, OTOH, is very dynamic, so there is not much demand for spiffy > introspection APIs. ?Functions and classes are ordinary objects, so if > you don't know what function to call or class to use at compile-time, > you can just pass the objects around. ?No strings required. > > So what I'm saying is: the Python developers didn't bother to make an > high-level, easy-to-use __import__ because there really isn't much > demand for it. > > Carl Banks From aleksandr.goretoy at gmail.com Tue Jan 6 07:33:42 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 12:33:42 +0000 Subject: math module for Decimals In-Reply-To: <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> References: <724eaff0-f105-4abb-9f19-636fa0a9e08b@g3g2000pre.googlegroups.com> <406bd2ed-612b-4102-9ca5-64f552d2bdd7@b41g2000pra.googlegroups.com> <0170080e$0$8693$c3e8da3@news.astraweb.com> <5c6f2a5d0901060244j5fdebdbh4d5f6de398c723b7@mail.gmail.com> Message-ID: Yes I ran strace python and imported math time(NULL) = 1231244692 futex(0x80575d8, FUTEX_WAKE, 1) = 0 stat64("math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python24.zip/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python24.zip/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/plat-linux2/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/plat-linux2/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/lib-tk/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/mathmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-tk/math.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.4/lib-dynload/math", 0xbfabef50) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.4/lib-dynload/math.so", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0 open("/usr/lib/python2.4/lib-dynload/math.so", O_RDONLY) = 4 read(4, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\16"..., 512) = 512 fstat64(4, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0 mmap2(NULL, 15588, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0xb7f2b000 mmap2(0xb7f2e000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x2) = 0xb7f2e000 close(4) = 0 close(3) = 0 It's probably because I only downloaded python from svn repo and ran ./configure&&make&&make install I didn't do anything else. Like set PYTHONPATH. I solved it though. You can tell by the output it's looking for it in my other python install lib path. Thank you. -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 10:44 AM, Mark Dickinson wrote: > dule built, but Python is looking in the wrong > place for it, for some reason. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Jan 6 07:42:13 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 12:42:13 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > Such assumptions only hold under particular domains though. You can't > assume equality is an equivalence relation once you start thinking > about arbitrary domains. >From a formal mathematical point of view, equality /is/ an equivalence relation. If you have a relation on some domain, and it's not an equivalence relation, then it ain't the equality relation, and that's flat. > But there cannot be any such function which is a domain-independent > equivalence relation, not if we're talking about arbitrarily wacky > domains. That looks like a claim which requires a proof to me. But it could also do with a definition of `domain', so I'll settle for one of those first. If we're dealing with sets (i.e., `domain's form a subclass of `sets') then the claim is clearly false, and equality (determined by comparison of elements) is indeed a domain-independent equivalence relation. > Even something as straight-forward as "is" can't be an equivalence > relation under a domain where identity isn't well-defined. You've completely lost me here. The Python `is' operator is (the characteristic function of) an equivalence relation on Python values: that's its definition. You could describe an extension of the `is' relation to a larger set of items, such that it fails to be an equivalence relation on that set, but you'd be (rightly) criticized for failing to preserve one of its two defining properties. (The other is that `is' makes distinctions between values which are at least as fine as any other method, and this property should also be extended .) Let me have another go. All Python objects are instances of `object' or of some more specific class. The `==' operator on `object' is (the characteristic function of) an equivalence relation. In, fact, it's the same as `is' -- but `==' can be overridden by subclasses, and subclasses are permitted -- according to the interface definition -- to coarsen the relation. In fact, they're permitted to make it not be an equivalence class at all. I claim that this is a problem. I /agree/ that domain-specific predicates are useful, and can be sufficiently useful that they deserve the `==' name -- as well as floats and numpy, I've provided SAGE and sympy as examples myself. But I also believe that there are good reasons to want an `equivalence' operator (I'll write it as `=~', though I don't propose this as Python syntax -- see below) with the following properties: * `=~' is the characteristic function[1] of an equivalence relation, i.e., for all values x, y, z: x =~ y in (True, False); (x =~ x) == True; if x =~ y then y =~ x; and if x =~ y and y =~ z then x =~ z * Moreover, `=~' is a coarsening of `is', i.e. for all values x, y: if x is y then x =~ y. A valuable property might be that x =~ y if x and y are indistinguishable without using `is'. That would mean immediately that 'xyz' =~ 'xy' + 'z' (regardless of interning, because strings are immutable). But for tuples this would imply elementwise comparison, which may be expensive -- and, in the case of tuples manufactured by C extensions, nontrivial because manufactured tuples need not be acyclic. On the other hand, `==' is already recursive on tuples. We can envisage a collection of different relations, according to which distinguishing methods we're willing to disallow. For example, for numerical types, there are actually a number of interesting relations, according to whether you think the answers to the following questions are true or false. * Is 1 =~ 1/1? (Here, 1 is an integer, and 1/1 is a rational number; both are the multiplicative identities of their respective rings. I'd suggest that it doesn't seem very useful to say `no' here, but there might be reasons why one would want type(x) is type(y) if x =~ y.) * Is 1 =~ 1.0? (This is trickier. Numerically the values are equal; but the former is exact and the latter inexact, and this is a good reason to want a separation.) Essentially, these are asking whether `type' is a legitimate distinguisher, and I think that the answer, unhelpful as it may be, is `sometimes'. A third useful distinguishing technique is mutation. Given two singleton lists whose respective elements compare equivalent, I can mutate one of them to decide whether the other is in fact the same. Is this something which `=~' should distinguish? Again, the answer is probably `sometimes'. To summarize: we're left with at least three different characteristics which an equivalence predicate might have: * efficient (e.g., bounded recursion depth, works on circular values); * neglects irrelevant (to whom?) differences of type; and * neglects differences due to mutability. A predicate used to compare set elements or hash-table keys should probably /respect/ mutability. (Associating hashing with this predicate, rather than `==', would coherently allow mutable objects such as lists to be used as dictionary keys, though they'd be compared by address. I don't actually know how useful this would be, but suspect that it wouldn't.) Oh, before I go, let me make this very clear: I am /not/ proposing a language change. I think the right way to addres these problems is using existing mechanisms such as generic functions with multimethods. Syntax can come later if it seems sufficiently important. [1] I'll settle for it being a partial function, i.e., attempting to evaluate x =~ y might raise exceptions, e.g., if x is in some invalid state, or perhaps if one or both of x or y is circular, though it would be good to minimize such cases. -- [mdw] From nytrokiss at gmail.com Tue Jan 6 07:45:05 2009 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 6 Jan 2009 14:45:05 +0200 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> I agree but please enlighten us what caused you to say that python is great? On Sat, Jan 3, 2009 at 3:30 PM, Nomen Nescio wrote: > python is great. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Tue Jan 6 07:46:13 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Jan 2009 12:46:13 GMT Subject: Python subprocess question References: Message-ID: "Alexi Zuo" wrote: > Hi everyone, > > Here I have a simple program which starts a thread and the thread use > Popen to execute a shell cmd which needs a long time. I want to stop > the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this > program enters a dead loop. Can anyone tell me what is wrong? The KeyboardInterrupt exception is being raised in your main thread which doesn't handle it so it just terminates. Your child thread isn't marked as a daemon thread so the program won't exit until the child thread has also terminated. From skip at pobox.com Tue Jan 6 07:50:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 06:50:06 -0600 Subject: How to get involved In-Reply-To: <33e09baf-00b5-40f0-9b5f-152c370941e6@r36g2000prf.googlegroups.com> References: <33e09baf-00b5-40f0-9b5f-152c370941e6@r36g2000prf.googlegroups.com> Message-ID: <18787.21374.941591.845418@montanaro.dyndns.org> Kaj> I'm new to the open source comunnity and I was wondering if there Kaj> are any bugs that I can trouble shoot or just some beginner tasks I Kaj> can be sent? Python bugs and patches are tracked at http://bugs.python.org/ You can always write patches for bugs or review other peoples' patches. There is talk of a Python Bug Day in the near future. I suspect it will be announced here. A bug day is a virtual exercise where lots of people work on closing out items on the bug tracker. People communicate via IRC. You might check out the links in the core development page: http://www.python.org/dev/ You can also get involved with open source projects written in Python. There are plenty: Twisted SpamBayes Matplotlib SciPy etc etc etc -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From googler.1.webmaster at spamgourmet.com Tue Jan 6 07:53:52 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Tue, 6 Jan 2009 04:53:52 -0800 (PST) Subject: Compile as static library Message-ID: <32445465-1109-4df0-aea0-e86b3a8d7b8b@x16g2000prn.googlegroups.com> Hi! I have a big problem with compiling Python on MacOSX. I compile it - everything works ./configure make so I get a libpython2.5.a file which I include into a Xcode Project. I want to static link it with my project (works in Debug mode but not in Release) 1. Is there a static library flag which I have to set, or something like that? 2. Why does it work in Debug mode, not in Release? The import settings for a library doesn't differe between debug and release, does it? Thanks a lot. From you680 at gmail.com Tue Jan 6 08:00:36 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:00:36 -0800 (PST) Subject: Is there some methods like 'datareader' in MySQLdb for handling mass data References: <28cb948a-852e-4fdd-a21e-8eb6d254698d@p2g2000prf.googlegroups.com> <496340a6$0$3533$426a74cc@news.free.fr> Message-ID: <6d409588-8f63-485b-932f-45b9dc23634e@w1g2000prk.googlegroups.com> On Jan 6, 7:29?pm, Bruno Desthuilliers wrote: > Jeremy.Chen a ?crit : > > > hi all: > > ? when I handled mass data table in mysql with python's MySQLdb lib, > > something frustrated me. I could't find any function like datareader, > > which yield one row by recording rows' anchor ,after each time I > > invoked 'read()' in a loop. > > I think you want cursor.fetchone(). But read below... > > > fetchall or fetchmany just fetched all data > > in once, which take so much memory when meeting one mass data > > table. > > The cursor object is it's own iterator. So you just have to do: > > cursor.execute(your_query) > for row in cursor: > ? ? process(row) > > HTH That's what I want. I see,cursor also can be a iterator. From mdw at distorted.org.uk Tue Jan 6 08:05:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 13:05:50 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <2s2dnSf7f-CxLvzUnZ2dnUVZ_vGdnZ2d@posted.usinternet> Message-ID: Steven D'Aprano wrote: > By all means, if Derek doesn't like the assignment model used by Python > (and Java, Ruby, C#, Perl, RealBasic, VisualBasic, Lua, and many other > languages going back to at least CLU in the mid 1970s) It goes back to Lisp in the late 1950s. [snip stuff I agree with.] -- [mdw] From you680 at gmail.com Tue Jan 6 08:08:53 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:08:53 -0800 (PST) Subject: ftp seems to get a delayed reaction. References: Message-ID: <125c8dc6-d467-443f-8755-4ab725266b22@z28g2000prd.googlegroups.com> On Jan 6, 7:56?pm, Antoon Pardon wrote: > I have managed to prune the script, so I can post it here: > > ========================================================== > > from ftplib import FTP > > bckrt = "/tmpstor/rcpc42" > > def process(): > ? print "making directory" > ? try: > ? ? ftp.mkd('ftp-tst') > ? ? print "mkdir succeeded" > ? except Exception, ErrMsg: > ? ? print "mkdir failed: %s" % ErrMsg > ? fl = open("tstfile") > ? print "storing file" > ? ftp.storbinary("STOR ftp-tst/ftp-file\n", ?fl) > ? fl.close() > > ftp = FTP('ftphost', 'user', 'passwd') > ftp.set_pasv(False) > ftp.cwd(bckrt) > > print "Doing once" > process() > print "Doing twice" > process() > > ---------------------------------------------------------- > And this is the output: > ========================================================== > Doing once > making directory > mkdir succeeded > storing file > Doing twice > making directory > mkdir failed: 500 '': command not understood. > storing file > Traceback (most recent call last): > ? File "ftptst", line 24, in > ? ? process() > ? File "ftptst", line 14, in process > ? ? ftp.storbinary("STOR ftp-tst/ftp-file\n", ?fl) > ? File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary > ? ? self.voidcmd('TYPE I') > ? File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd > ? ? return self.voidresp() > ? File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp > ? ? resp = self.getresp() > ? File "/usr/lib/python2.5/ftplib.py", line 216, in getresp > ? ? raise error_perm, resp > ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) ---------- I think the params after STOR should't be a path,should be splited. ftp.cwd("ftp-tst") ftp.storbinary("STOR ftp-file\n", fl) From you680 at gmail.com Tue Jan 6 08:17:01 2009 From: you680 at gmail.com (Jeremy.Chen) Date: Tue, 6 Jan 2009 05:17:01 -0800 (PST) Subject: Regex Generator From Multiple Files References: <171e8a410901051618w11a4710cudba860c32faa53df@mail.gmail.com> Message-ID: <76ab1a89-1e94-4a1c-be2f-55d87d3c2139@p2g2000prf.googlegroups.com> On Jan 6, 8:48?am, MRAB wrote: > James Pruitt wrote: > > I am looking for a way given a number of files, say 3, that represent > > technical support tickets in the same format to generate regular > > expressions for the different fields automatically. > > > An example from of one line from each file: > > Date: 12/30/2008 Room: 457 Building: Main > > Date: 12/31/2008 Room: A21 Building: Annex > > Date: 1/4/2009 Room: L69 Building: Library > > > The program would then, possibly using the python diff library, generate > > the regular expression needed to parse out different fields. In this > > case it might return a tuple like > > ("^Date:[\w]+(.*)[\w]+Room","Room:[\w]+(.*)[\w]+Building","Building:[\w]+(.?*)[\w]+$") > > that would match each of the fields based on the common data and sort of > > assume that what doesn't change between them is data we are looking for. > > Why not just assume that each field consists of a word terminated by a > colon, then some text, then the next field or the end of the line?- Hide quoted text - > > - Show quoted text - do you mean the sub method? ------------- re.sub( r'(?i)(example)',self.captureRegxp,content ) From victorsubervi at gmail.com Tue Jan 6 08:18:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 6 Jan 2009 14:18:52 +0100 Subject: =?ISO-8859-1?Q?Re:_Can=B4t_Surf_Python_Pages_in_Windoze?= In-Reply-To: <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> References: <4dc0cfea0812260701q6baf0ccbj154c5b3fa2281cdb@mail.gmail.com> <4954FB9F.5050702@wildenhain.de> <4dc0cfea0812260911k4dbc0f2ame9cc874e067b7816@mail.gmail.com> <4dc0cfea0901020724l7ae1d4aer73aa97f0311a42e0@mail.gmail.com> Message-ID: <4dc0cfea0901060518k6d3d3b70w668fadfad58f1e63@mail.gmail.com> On Fri, Jan 2, 2009 at 4:24 PM, Victor Subervi wrote: > On Fri, Dec 26, 2008 at 8:00 PM, Gabriel Genellina > wrote: > >> En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi < >> victorsubervi at gmail.com> escribi?: >> >>> On 12/26/08, Tino Wildenhain wrote: >>> >> >> print "Content-Type: text/html" >>>>> print >>>>> print """ >>>>> >>>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>>> >>>> >> I think there should be only one blank line between header and content, >> you have two (so the document contains an empty line before the doctype >> declaration, and I think this is invalid). >> > I tried eliminating the second line (print) but it didn?t help. Seems there is a problem with Python on my Windoze box. I reinstalled with no luck. I tried opening a page which should have opened (works fine on my server) with same "black box" problem. Thanks, Victor > > Will try. Thanks. Let you know next week if problem. > Victor > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mal at egenix.com Tue Jan 6 08:31:52 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 14:31:52 +0100 Subject: creating a datetime.datetime from an XML xs:dateTime In-Reply-To: References: <5fa6c12e0812271208x4baccaedk262e51becb6e2076@mail.gmail.com> <18774.36465.346262.883182@montanaro-dyndns-org.local> <5fa6c12e0812271255l4f4893e8w9f96e9ace73ea50c@mail.gmail.com> Message-ID: <49635D48.9020803@egenix.com> On 2008-12-29 05:26, Jack.Chu wrote: > I think a simple regular expression is a relatively easy solution. Or use mxDateTime and let the parser do all the heavy lifting for you: >>> from mx.DateTime import Parser >>> t = Parser.DateTimeFromString('2000-01-12T12:13:14Z') >>> t >>> t = Parser.DateTimeFromString('2000-01') >>> t >>> t = Parser.DateTimeFromString('2000-01-12') >>> t http://www.egenix.com/products/python/mxBase/mxDateTime/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From Caseyweb at gmail.com Tue Jan 6 08:31:52 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 05:31:52 -0800 (PST) Subject: Python 3.0 nonlocal statement Message-ID: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> In PEP 3104 the nonlocal statement was proposed and accepted for implementation in Python 3.0 for access to names in outer scopes. The proposed syntax included an optional assignment or augmented assignment to the outer name, such as: nonlocal x += 1 This syntax doesn't appear to be supported in the 3.0 implementation. My question is: was this intentional or was it missed in the initial release? If it was intentional, is there any plan to support it in a later 3.x release? I realize it is a very small convenience feature but I have already come across a couple of cases where I use nested functions where it does make the code seem a little cleaner. Regards, Casey From n.kottiyath at gmail.com Tue Jan 6 08:33:29 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 6 Jan 2009 05:33:29 -0800 (PST) Subject: Traceback in Logging Message-ID: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> Hi all, Is it possible to print traceback for all logging? I have created something like this: def trace(): import traceback return ''.join(traceback.format_stack(limit=4)[1:]) And during every logging, append it - self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data, kwargs, trace())) -->Result<-- 2009-01-06 18:52:21,483 - test- INFO ---> Data:, kwargs: {} Traceback: File "C:\test.py", line 48, in success super(testObj, self).success(reply, **kwargs) File "C:\test.py", line 87, in success self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data, kwargs, trace())) File "C:\test.py", line 151, in trace return ''.join(traceback.format_stack(limit=4)[1:]) This seems somewhat kludgy. Is it possible in logging mechanism itself to provide traceback as default? I use Python2.4, so LoggingAdapter is not there too. From mdw at distorted.org.uk Tue Jan 6 09:03:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:03:16 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > (3) Those who come from an entirely different programming model, say, > Forth or Haskell. For them, Python's assignment model is going to be the > least of their worries. Actually, Haskell's assignment model (you have to grubbing about for IORefs or STRefs to find it but it's there) is exactly the same as Lisp, Scheme, Python, Dylan, Perl, Lua, Icon, Ruby, Erlang, ML, ... The variables-and-containers-hold-references-to-objects idea is common to a very large number (probably the majority? depends how you count) of high-level languages. Java is in the same category. C# is definitely not, since `struct's are composite, mutable value types clearly distinguishable from anything Python can do. The main dissent is probably from Tcl, which pretends to copy values -- even complex objects such as lists -- wholesale (though actually does fancy copy-on-write things under the covers). > Your first post in this topic made the extraordinarily arrogant and > incorrect claim that: > > [quote] > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. > [end quote] > > We can see some pretty poor assumptions right there: > > * That the Python community is capable of uniformly overlooking Python's > differences from other languages. > > * That only languages "substantially taught" in undergraduate CS courses > matter. And a massive assumption about the languages taught to CS undergrads too. In particular, Scheme is a fairly popular language to teach to undergrads, often as a first language. See, for example, `The Structure and Interpretation of Computer Programs' by Abelson and Sussman, and the (much more recent) `How to Design Programs' by Felleisen, Findler, Flatt and Krishnamurthi. > It seems that you don't include in the Python community all those who > use the term "name binding" instead of variable assignment > specifically because it gives new users a clue that Python is not the > same as C. Unfortunately, this practice causes other confusion, since `binding' is often used (in other language communities, notably Lisp and the functional languages) to describe the association between names and slots that hold references. Let me explain. I'll try to be clear, though I know that Stephen already understands this stuff well. At run-time, each named variable denotes a storage area (I'll call it a slot[2]) which holds a reference to some object[1]. +-----+ name ----> | ref -----> object +-----+ If we `assign' a different object to the variable, what really happens is that the slot is modified to refer to the other object; but the name continues to denote the same slot. Usually `binding', or `rebinding', a name describes a different process, whereby the name (for a while) denotes a different slot. This name-to- slot mapping is important because it's the mapping which is inherited by nested functions. This is most clearly shown by example. Consider this Python interaction. In [1]: l = [] In [2]: for i in [1, 2, 3]: ...: l.append(lambda: i) ...: In [3]: [f() for f in l] Out[3]: [3, 3, 3] This prints [3, 3, 3]. What's happened is that the lambdas have closed over the prevailing /binding/ of i -- i.e., which reference slot it denotes. Since the for loop operates by assignment, and /not/ by rebinding i, the three lambdas all closed over the same environment, and return the same value. Scheme's DO loop, by contrast, really does operate by binding. Consider this example of a GNU Guile interaction. guile> (define l '()) guile> (do ((i (list 1 2 3) (cdr i))) ... ((null? i)) ... (set! l (append l (list (lambda () (car i)))))) guile> (map (lambda (f) (f)) l) $1 = (1 2 3) That is, each time through the loop, the variable I denotes a /different/ reference slot; the LAMBDAs close over different environments, and the functions return different values. (This example illustrates both binding and assignment, since the SET! changes the value referred to in the slot denoted by L, without rebinding L.) A very approximate translation of the above into Python looks like this. In [1]: l = [] In [2]: items = [1, 2, 3] In [3]: def _loop(ix): ...: if ix >= len(items): return ...: l.append(lambda: items[ix]) ...: _loop(ix + 1) ...: In [4]: _loop(0) In [5]: [f() for f in l] Out[5]: [1, 2, 3] (I've cheated and used indices because Python lists don't have the head/tail structure of Lisp lists.) None of this is a criticism of Python's behaviour. (Sometimes it'd be nice if `for' worked by rebinding, but sometimes it's better that it doesn't.) But it is a criticism of the Python community's confusing use of the word `binding' to mean something different from what fairly closely-related communities use it to mean. [1] Lisp has a notion of `unbound variables', which is another confusing use of the terminology. What this usually means is that the variable really refers to a special value, and the run-time signals an error if it retrieves this value from a variable. [2] `Slot' gets used a lot too. Sorry. This usage has nothing to do with Lisp's structure or instance slots, and nothing to do with Python's __slots__. > You've also missed out on probably twenty years of CS where Java (using > the same assignment model as Python!) has been *the* language of choice > for undergrad CS, not to mention those introductory courses which use > Python. There's no way that Java has been taught anywhere for 20 years. It just isn't old enough. Wikipedia claims that Java appeared in 1995, which looks right to me. Python, released in 1991, is therefore older. > > And then you're shocked, SHOCKED!!! that people respond sharply. > > How different do you think the response would have been if you had said: > > "What we in the Python community should try to remember is that for those > new to the language, there can sometimes be preconceived ideas about how > assignment works that clashes with Python's assignment model. From my own > perspective, I found the differences between Python's name binding model > and the named-bins model of C/Pascal/Fortran confusing at first, and to > be honest, I still get caught by those differences. Naturally this is a > general problem for every language, Python is hardly unique, but please > remember not to bite the newbies just because they are still thinking in > some other language." > > -- [mdw] From mdw at distorted.org.uk Tue Jan 6 09:12:19 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:12:19 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: Steven D'Aprano wrote: > I don't think so. Variables in algebra are quite different from variables > in programming languages. Contrast the statement: > > x = x+1 > > as a programming expression and an algebraic equation. As a programming > expression, it means "increment x by one". But as an algebraic > expression, it means "x is some value such that it is equal to one more > than itself", and there is no solution to such an equation. Surely there is. The solution is: 1 = 0 (and hence x is an -- no, /the/ -- element of the trivial ring). > > and how several generations of computer languages, not to mention > > the actual machine language those generated, behaved, before the current > > crop. > > Sure. And? Actally, this is true only for /very/ small values of `several'. There was FORTRAN in 1957, with what you're calling the `named bins' model, and I call assignment-is-copying, and Lisp in 1958, with the assignment- is-pointer-diddling model. -- [mdw] From simon at brunningonline.net Tue Jan 6 09:15:11 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 6 Jan 2009 14:15:11 +0000 Subject: Returning a string In-Reply-To: References: Message-ID: <8c7f10c60901060615o3de4a9f7ybb2480e3eee91784@mail.gmail.com> 2009/1/3 Kless : > How is possible that I can print a variable, but when I use *return > var* it returns an empty string What makes you think it's returning an empty string? You aren't doing anything with the return value in line 26 of your example. -- Cheers, Simon B. From lihang9999 at gmail.com Tue Jan 6 09:28:37 2009 From: lihang9999 at gmail.com (Li Han) Date: Tue, 6 Jan 2009 06:28:37 -0800 (PST) Subject: image recogniton? Message-ID: Hi! I know little about the computer image processing, and now I have a fancy problem which is how to read the time from the picture of a clock by programming ? Is there anyone who can give me some suggestions? Thank! Li Han From mdw at distorted.org.uk Tue Jan 6 09:32:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 6 Jan 2009 14:32:04 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Derek Martin wrote: > I think I have though, not that it matters, since that was never > really my point. Python's assignment model requires more explanation > than the traditional one, simply to state what it does. That alone is > evidence (but not proof). Hmm. Actually, it's not the assignment model which is strange at all. It's the data model. What does an expression like [1, 2, 3] denote? Is it the list itself, or a /reference/ to the list? If you answer the first, you'll want Tcl/C/Fortran semantics. If you answer the second, you'll want Lisp/Python/Javascript semantics. If you answer `it depends', you'll want to be confused. Python decided that all values are passed around as and manipulated through references. (There are no locatives: references are not values, and you can't have a reference to a reference.) Lists store references; tuples store references; and so on. If one is to be able to implement complex data structures which involve sharing of data (e.g., cyclic graphs) or which allow efficient reorganization (e.g., various kinds of trees) we need to be able to manage references to values somehow. There are a number of ways of doing this. * Everything is a reference. This is the most uniform. Once you've got the hang of it, there are no surprises. * Nothing is a reference. If you want complex data structures, you're either screwed (e.g., if your data model is too weak) or you have to invent them yourself using array indices or something wretched like that. Tcl is in this category: you have to mess with (associative) arrays or variable names to make complex data structures. * Some values are references to others. This is like C, and causes exciting problems when you get confused. C++ makes things more confusing because dereferencing can happen implicitly. Perl manages to be in this camp /and/ the first one. It's very strange. * Some things are references, and some aren't. This is what Java and C# do. Java says that only simple, atomic things are non-references, so assignment looks the same either way, but you can't store primitive things in containers expecting to store references (until Sun added automatic boxing and unboxing -- eventually). C# makes matters more complicated by letting users define structured mutable data which aren't handled by reference, but does the boxing and unboxing thing transparently. > As for there being no assignment in algebra, is that not really what > variable substitution is? No. > They have different names, but in my estimation they perform exactly > the same function. You're assigning specific values to the variables > in an expression so that you can solve for a constant... just like in > a computer program. When you do this, you construct a different expression. They might have equal values, but they're still different. (You can consider equivalence classes under some appropriate equivalence relation if you like, but that just makes things more complex.) > There is even an allocation of memory: it's in your brain. :D Ahh! You're modifying a memory location in your brain so that it refers to a different expression. Isn't this the Lisp/Python/Javascript model? ;-) -- [mdw] From dotancohen at gmail.com Tue Jan 6 09:35:11 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 16:35:11 +0200 Subject: python is great In-Reply-To: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <880dece00901060635g5c6a73eew6352f13d449ca695@mail.gmail.com> 2009/1/3 Nomen Nescio : > python is great. > No, those are anacondas. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From furkankuru at gmail.com Tue Jan 6 09:50:04 2009 From: furkankuru at gmail.com (Furkan Kuru) Date: Tue, 6 Jan 2009 16:50:04 +0200 Subject: image recogniton? In-Reply-To: References: Message-ID: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> start with Python Image Library: http://www.pythonware.com/products/pil/ On Tue, Jan 6, 2009 at 4:28 PM, Li Han wrote: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han > -- > http://mail.python.org/mailman/listinfo/python-list > -- Furkan Kuru -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-url at phaseit.net Tue Jan 6 10:05:37 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 6 Jan 2009 15:05:37 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 6) Message-ID: QOTW: "If you have good, experienced people who are able to withstand the pressure to deliver no matter what and are familiar with the problem domain, then any project is on the way to succeess no matter what technology was chosen in my experience. The choice of type system is way down on the list." - Stefan Axelsson Performance comparison: multiprocessing vs threading: http://groups.google.com/group/comp.lang.python/t/f99326a4e5d394e/ A speed boost of more than 15% in many common situations is exciting: http://bugs.python.org/issue4753 How to seek to the last line in a text file: http://groups.google.com/group/comp.lang.python/t/e24ac82e6d236c1e/ Counting elements - where a "bag" class would be useful: http://groups.google.com/group/comp.lang.python/t/68acebd75fb7c61c/ How (and when) to forcibly kill a thread: http://groups.google.com/group/comp.lang.python/t/c080c23fed0f8a5a/ Getting all function defined in a file: http://groups.google.com/group/comp.lang.python/t/7be03c127bd8eabe/ Debugging embedded applications: http://groups.google.com/group/comp.lang.python/t/1edb44574e4da6b6/ Guilherme Polo nicely illustrates embedding in a tktable Tkinter cell: http://mail.python.org/pipermail/tkinter-discuss/2009-January/001787.html Running Python scripts inside a web browser: http://groups.google.com/group/comp.lang.python/t/d977140a3a163025/ Unpacking tuples of different sizes: http://groups.google.com/group/comp.lang.python/t/b8eb96ba3097a27e/ http://groups.google.com/group/comp.lang.python/t/ecf29cdc64010a4d/ Why isn't `some*(arbitrary-expression) = value` allowed? http://groups.google.com/group/comp.lang.python/t/75a63598d7f0b60c/ It's not a good idea to create many logger instances: http://groups.google.com/group/comp.lang.python/t/31c394f0bd0bc8b3/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From andrea.francia at REMOVE-FROM-HERE.ohoihihoihoih.TO-HERE.gmx.it Tue Jan 6 10:20:15 2009 From: andrea.francia at REMOVE-FROM-HERE.ohoihihoihoih.TO-HERE.gmx.it (Andrea Francia) Date: Tue, 06 Jan 2009 15:20:15 GMT Subject: Code Review request for the trash-cli project Message-ID: The trash-cli project is a opensource implementation of the FreeDesktop.org Trash Specification that provides a command line interface to manage the trashcan. It's provide the following commands: * trash-put trashes files and directories. * trash-empty empty the trashcan(s). * trash-list list trashed file. * trash-restore restore a trashed file. It is written in python and its sources are available at http://code.google.com/p/trash-cli/source/browse/#svn/trunk I'm the main developer and I'm not so good in Python as I would be. Would you review my software and point out the problems you see? The review comments can be written using the code-review facilities of google code. You need only to double click the line of code where you want add a comment. Patches are also welcome. Thank you. From fredrik.johansson at gmail.com Tue Jan 6 10:23:10 2009 From: fredrik.johansson at gmail.com (Fredrik Johansson) Date: Tue, 6 Jan 2009 07:23:10 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> Message-ID: <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> On Dec 28 2008, 4:55?pm, jerry.carl... at gmail.com wrote: > > - are you usingDecimalfor the base-10-ness or the > > ? extra precisionDecimalprovides? ?Or significant zeros? > > ? Or compatibility with existingDecimalcode, or what? > > Oh boy, now I will finally prove myself illiterate... well, so be it. > But i am after the extra precision: > > >>> from math import * > >>> (1+1e-16)-1 > > 0.0 > > Agree: sin, cos and atan would do it. FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- precision standard transcendental functions in pure Python. It is much faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, and handles huge arguments just fine. Fredrik From tino at wildenhain.de Tue Jan 6 10:25:45 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 06 Jan 2009 16:25:45 +0100 Subject: image recogniton? In-Reply-To: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> Message-ID: <496377F9.6080903@wildenhain.de> Hi, Furkan Kuru wrote: > start with Python Image Library: > http://www.pythonware.com/products/pil/ I think this is more a job for OpenCV and its python bindings. http://opencv.willowgarage.com/wiki/PythonInterface > On Tue, Jan 6, 2009 at 4:28 PM, Li Han > wrote: > > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mail at microcorp.co.za Tue Jan 6 10:26:45 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 6 Jan 2009 17:26:45 +0200 Subject: image recogniton? References: Message-ID: <008d01c97014$1df62fe0$0d00a8c0@hendrik> "Li Han" wrote: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? When the big hand is on the twelve, and the little hand is on the eight, it is eight O'clock... :-) - Hendrik From dotancohen at gmail.com Tue Jan 6 10:30:19 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 17:30:19 +0200 Subject: Code Review request for the trash-cli project In-Reply-To: References: Message-ID: <880dece00901060730s56747954he2d251267d503173@mail.gmail.com> 2009/1/6 Andrea Francia : > The trash-cli project is a opensource implementation of the FreeDesktop.org > Trash Specification that provides a command line interface to manage the > trashcan. > > It's provide the following commands: > * trash-put trashes files and directories. > * trash-empty empty the trashcan(s). > * trash-list list trashed file. > * trash-restore restore a trashed file. > > It is written in python and its sources are available at > > http://code.google.com/p/trash-cli/source/browse/#svn/trunk > > I'm the main developer and I'm not so good in Python as I would be. > > Would you review my software and point out the problems you see? > > The review comments can be written using the code-review facilities of > google code. You need only to double click the line of code where you want > add a comment. > > Patches are also welcome. > > Thank you. > I don't know about the code, but would there be a reason _not_ to alias rm, rmdir to this program? I see that it is GPL, so this would be a great addition to any Linux distro. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From mark.fink1 at googlemail.com Tue Jan 6 10:32:20 2009 From: mark.fink1 at googlemail.com (mark) Date: Tue, 6 Jan 2009 07:32:20 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python Message-ID: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. This means no disturbing '.;()\' characters. I like to have the power of the hosting language as well. Thats why I want to build it as an internal DSL and NOT as a external DSL. I want the DSL as human readable as possible: >>> open_browser navigate_to 'www.openstreetmap.org' website search 'Von-Gumppenberg-Strasse, Schmiechen' verify search_result zoom in <<< Martin Fowler recommends "Method Chaining" to build internal DSLs: >>> Browser("http://www.openstreetmap.org/") \ .search("Von-Gumppenberg-Strasse, Schmiechen") \ .zoom_in() <<< I guess that it is possible to argue that this means the same. Nevertheless I do not like all the parentheses and punctuation necessary to satisfy the Python interpreter. The reason why I need this is that I want to have non technical people review the files written in the DSL. I already know that there are parser frameworks available but I want to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and whatnot). How would one approach this in Python? Do I need to build a custom loader which compiles *.dsl files to *.pyc files? Is it possible to switch between the custom DSL and the standard Python interpreter? From dotancohen at gmail.com Tue Jan 6 10:45:36 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 17:45:36 +0200 Subject: image recogniton? In-Reply-To: <008d01c97014$1df62fe0$0d00a8c0@hendrik> References: <008d01c97014$1df62fe0$0d00a8c0@hendrik> Message-ID: <880dece00901060745y7ba1ed15kf45d50d2d43a5689@mail.gmail.com> 2009/1/6 Hendrik van Rooyen : > "Li Han" wrote: > >> Hi! I know little about the computer image processing, and now I have >> a fancy problem which is how to read the time from the picture of a >> clock by programming ? Is there anyone who can give me some >> suggestions? > > When the big hand is on the twelve, and the little hand is on the eight, > it is eight O'clock... > My clock is digital, you insensitive clod! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From skip at pobox.com Tue Jan 6 10:53:55 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 09:53:55 -0600 Subject: image recogniton? In-Reply-To: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> Message-ID: <18787.32403.82637.308936@montanaro.dyndns.org> Furkan> start with Python Image Library: Furkan> http://www.pythonware.com/products/pil/ Well, there's the little problem of optical character recognition. You might want to check out open source OCR tools like gocr: http://jocr.sourceforge.net/ Just use PIL to convert input images into PNM format, run gocr in a subprocess read the stdout to get text. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From tekion at gmail.com Tue Jan 6 10:56:18 2009 From: tekion at gmail.com (tekion) Date: Tue, 6 Jan 2009 07:56:18 -0800 (PST) Subject: figuring week of the day.... Message-ID: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Is there a module where you could figure week of the day, like where it starts and end. I need to do this for a whole year. Thanks. From rt8396 at gmail.com Tue Jan 6 11:00:14 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 08:00:14 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <0546c834-957f-41e3-94e1-db359a5fd36f@w39g2000prb.googlegroups.com> On Jan 6, 9:56?am, tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. import datetime help(datetime) import time help(time) From vinay_sajip at yahoo.co.uk Tue Jan 6 11:01:01 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jan 2009 08:01:01 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> Message-ID: <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> On Jan 6, 1:33 pm, Kottiyath wrote: > This seems somewhat kludgy. Is it possible in logging mechanism itself > to provide traceback as default? > No, because it's not a common use case to print tracebacks for every logging call. There's support for adding traceback information in exception handling, via use of the Logger.exception method in the exception handling code. > I use Python2.4, so LoggingAdapter is not there too. If you need LoggingAdapter, you can always copy and paste the relevant code from Python's SVN repository into your own application. Regards, Vinay Sajip From joe at strout.net Tue Jan 6 11:01:31 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 09:01:31 -0700 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <4963805B.3090000@strout.net> Mark Wooding wrote: > Derek Martin wrote: > >> I think I have though, not that it matters, since that was never >> really my point. Python's assignment model requires more explanation >> than the traditional one, simply to state what it does. That alone is >> evidence (but not proof). > > Hmm. Actually, it's not the assignment model which is strange at all. > It's the data model. What does an expression like > > [1, 2, 3] > > denote? Is it the list itself, or a /reference/ to the list? If you > answer the first, you'll want Tcl/C/Fortran semantics. If you answer > the second, you'll want Lisp/Python/Javascript semantics. If you answer > `it depends', you'll want to be confused. Well said! You can easily see that assignment in Python is perfectly ordinary, by comparing it to languages that have both values and references (such as C++, Java, or REALbasic). Those languages have only one assignment model, that operates on both values and references just fine. Python has only references, and I think it's for this reason that some people here try to pretend that it doesn't have them at all, thus leading them to weird explanations of strange assignment and argument-passing behavior. > Python decided that all values are passed around as and manipulated > through references. (There are no locatives: references are not values, > and you can't have a reference to a reference.) Also very clearly put. If you don't mind, I may crib some of your verbage for , as it may be clearer than my own. Best, - Joe From sturlamolden at yahoo.no Tue Jan 6 11:03:41 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:03:41 -0800 (PST) Subject: Extending Python with C or C++ References: Message-ID: <87a6fd18-d9bc-4a65-b635-f1519e67b5cf@t39g2000prh.googlegroups.com> On Jan 5, 9:06 pm, Ryan wrote: > I've been using Python for many years now. It's a wonderful language > that I enjoy using everyday. I'm now interested in getting to know > more about the guts (C/C++) and extending it. But, extending python > still seems like a black art to me. There are several alternatives to using the Python C API by hand, depending on your particular need. It will save you a lot of greif: Pyrex: Python-like language for creating extension modules. *Cython: clone of Pyrex *ctypes: call DLLs from python comtypes: call COM DLLs from Python *f2py: generate wrappers for Fortran or C libraries. Knowledge of Fortran required. pywin32: use or implement ActiveX objects with Python *scipy.weave: inline C++ code in Python Swig: generate wrappers for C libraries (some C++ support) CXX: C++ wrapper for the Python C API Boost.Python: C++ wrapper for the Python C API SIP: generate wrappers for C++ libraries (* Works easily with NumPy arrays.) From mccredie at gmail.com Tue Jan 6 11:10:13 2009 From: mccredie at gmail.com (Matimus) Date: Tue, 6 Jan 2009 08:10:13 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> Message-ID: <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> On Jan 6, 5:31?am, Casey wrote: > In PEP 3104 the nonlocal statement was proposed and accepted for > implementation in Python 3.0 for access to names in outer scopes. ?The > proposed syntax included an optional assignment or augmented > assignment to the outer name, such as: > > nonlocal x += 1 > > This syntax doesn't appear to be supported in the 3.0 implementation. > My question is: was this intentional or was it missed in the initial > release? ?If it was intentional, is there any plan to support it in a > later 3.x release? ?I realize it is a very small convenience feature > but I have already come across a couple of cases where I use nested > functions where it does make the code seem a little cleaner. > > Regards, Casey `nonlocal` should behave just like `global` does. It doesn't support that syntax either. So, yes it was intentional. No, there probably is no plan to support it in a later release. Matt From sturlamolden at yahoo.no Tue Jan 6 11:13:46 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:13:46 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <614dfad7-8367-479f-bf99-45e11ee1122d@w24g2000prd.googlegroups.com> On Jan 6, 4:32 pm, mark wrote: > Is it possible to > switch between the custom DSL and the standard Python interpreter? As far as I can tell, there are three different options: - Embed a Python and DSL interpreter in the same executable. - Write the DSL interpreter in Python. - Expose the DSL interpreter as a Python extension module. I don't know which you prefer, but I would try to avoid the first. From n.kottiyath at gmail.com Tue Jan 6 11:17:02 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 6 Jan 2009 08:17:02 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: I dont want the whole traceback. I just wanted to know where the log was generated from i.e. which procedure and which line. I have 3/4 points in many procedures where I encounter a small error (not an exception) and want to log it. So having individual names for each looks to be somewhat verbose - esp since the application is >10K LOC. This might be a good item to have in the logging system - along with time and level, just proc name and the line number. Thank you for the help. Regards K Vinay Sajip wrote: > On Jan 6, 1:33 pm, Kottiyath wrote: > > This seems somewhat kludgy. Is it possible in logging mechanism itself > > to provide traceback as default? > > > > No, because it's not a common use case to print tracebacks for every > logging call. There's support for adding traceback information in > exception handling, via use of the Logger.exception method in the > exception handling code. > > > > I use Python2.4, so LoggingAdapter is not there too. > > If you need LoggingAdapter, you can always copy and paste the relevant > code from Python's SVN repository into your own application. > > Regards, > > Vinay Sajip From sturlamolden at yahoo.no Tue Jan 6 11:18:08 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 08:18:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> On Jan 6, 4:32 pm, mark wrote: > I want to implement a internal DSL in Python. I would like the syntax > as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). From skip at pobox.com Tue Jan 6 11:30:43 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 10:30:43 -0600 Subject: Traceback in Logging In-Reply-To: References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: <18787.34611.420657.794371@montanaro.dyndns.org> Kottiyath> I dont want the whole traceback. I just wanted to know where Kottiyath> the log was generated from i.e. which procedure and which Kottiyath> line. The asyncore standard module has an undocumented compact_traceback() function: #!/usr/bin/env python import asyncore def f(): 1/0 def g(): f() def h(): g() try: h() except ZeroDivisionError: print asyncore.compact_traceback()[3] Output looks like this: % python f.py [f.py||15] [f.py|h|12] [f.py|g|9] [f.py|f|6] Might be of interest. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From metalzong at 163.com Tue Jan 6 11:45:45 2009 From: metalzong at 163.com (Metal Zong) Date: Wed, 7 Jan 2009 00:45:45 +0800 Subject: Problem on pylab - matplotlib_examples_0.98.3 Message-ID: <029201c9701e$392a67e0$6501a8c0@nsnintra.net> Hello, I meet some problems on pylab (matplotlib_examples_0.98.3). I could not get valuable information from api document. Any help is appreciated. Or is there any other convenient library for making charts. Thanks a lot. 1, It's ok to draw table chart with enclosed file. 2. The problem is - the position is wrong if I try to add plot on this chart - (un-comment the part in the end) -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 1898740 bytes Desc: not available URL: From rtw at freenet.co.uk Tue Jan 6 11:46:02 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 06 Jan 2009 10:46:02 -0600 Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: Matimus wrote in news:2a3d6700-85f0-4861-84c9-9f269791f044 @f40g2000pri.googlegroups.com in comp.lang.python: > On Jan 6, 5:31?am, Casey wrote: >> In PEP 3104 the nonlocal statement was proposed and accepted for >> implementation in Python 3.0 for access to names in outer scopes. ?The >> proposed syntax included an optional assignment or augmented >> assignment to the outer name, such as: >> >> nonlocal x += 1 >> >> This syntax doesn't appear to be supported in the 3.0 implementation. >> My question is: was this intentional or was it missed in the initial >> release? ?If it was intentional, is there any plan to support it in a >> later 3.x release? ?I realize it is a very small convenience feature >> but I have already come across a couple of cases where I use nested >> functions where it does make the code seem a little cleaner. >> >> Regards, Casey > > `nonlocal` should behave just like `global` does. It doesn't support > that syntax either. So, yes it was intentional. No, there probably is > no plan to support it in a later release. > > Matt > http://www.python.org/dev/peps/pep-3104/ A shorthand form is also permitted, in which nonlocal is prepended to an assignment or augmented assignment: nonlocal x = 3 The above has exactly the same meaning as nonlocal x; x = 3. (Guido supports a similar form of the global statement [24].) Searching (AKA googling) for: nonlocal site:bugs.python.org leads to: http://bugs.python.org/issue4199 Rob. -- http://www.victim-prime.dsl.pipex.com/ From Caseyweb at gmail.com Tue Jan 6 11:48:15 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 08:48:15 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: <886f160b-4cdb-4249-adfe-566996e28915@m2g2000vbp.googlegroups.com> On Jan 6, 11:10?am, Matimus wrote: > `nonlocal` should behave just like `global` does. It doesn't support > that syntax either. So, yes it was intentional. No, there probably is > no plan to support it in a later release. > > Matt >From my perspective, that's an unfortunate decision and I question the rationale. First, nonlocal doesn't behave exactly like global (you cannot declare a previously undefined variable nonlocal as you can with global). Second, the PEP 3104 description explicitly mentions that Guido favored adding this behavior to global; I would have preferred that approach to not providing the extended assignment support for nonlocal. Third, I believe that it adds some clarity to the code. Seeing 'nonlocal x += 1' immediately tells me that I'm incrementing a variable defined in an outer scope. Having 'nonlocal x' on one line and 'x += 1' on another makes it a little less clear. But I do appreciate the reply! Casey From Caseyweb at gmail.com Tue Jan 6 11:52:40 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 6 Jan 2009 08:52:40 -0800 (PST) Subject: Python 3.0 nonlocal statement References: <8c65b7c5-ebd3-418d-940f-e51b7837fb0e@j38g2000yqa.googlegroups.com> <2a3d6700-85f0-4861-84c9-9f269791f044@f40g2000pri.googlegroups.com> Message-ID: <26dce886-497d-4edc-8bbe-a32333356621@q18g2000vbn.googlegroups.com> On Jan 6, 11:46?am, Rob Williscroft wrote: > Matimus wrote in news:2a3d6700-85f0-4861-84c9-9f269791f044 > Searching (AKA googling) for: nonlocal site:bugs.python.org > leads to:http://bugs.python.org/issue4199 > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Doh. I looked at the PEP and the 3.0 BNF syntax and never thought to search the online bugs. Thanks, Rob! From sturlamolden at yahoo.no Tue Jan 6 12:18:10 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 09:18:10 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <62471ee7-fcb6-455f-8442-56595c1f78ce@f40g2000pri.googlegroups.com> On Jan 2, 5:43 pm, Steve Holden wrote: > Derek Martin wrote: > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > [...] > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that > > its assignment model is BIZARRE, as in it's conceptually different > > from virtually all other languages substantially taught in > > undergraduate computer science programs. And for that matter, it's > > pretty unintuitive generally. > > I'd definitely argue against bizarre. It's actually very easy to > understand, and Python is by no means the only language to have used it. A statement like f(x) = 1 has no meaning in most languages - including Python, C and Java. C++ references allows operator= to be overloaded. It is one of few languages where a statement like 'f(x) = 1;' maybe meaningful. But C++ references are addresses (pointers in disguise), not names. The = is Python's name binding operator. Python is similar to Java in this respect. If anything is bizarre here, it is C++ references. P.S. The C statement '*f(x) = 1;' does have meaning, but 'f(x) = 1;' do not. But in the former case, one is not assigning to the return value. Python and Java do not have raw pointers like C. From joe at strout.net Tue Jan 6 12:36:47 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 10:36:47 -0700 Subject: python is great In-Reply-To: <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> Message-ID: <496396AF.5020809@strout.net> I've actually been rather frustrated by Python lately. It's great at some things, but rather poor at others. In the latter category is building a neatly packaged executable that can be shipped to users and run reliably on their machine. On the Mac in particular, if you want your app to run on any PowerPC or Intel machine runing 10.4 or later, and you're using anything not in the standard framework (such as MySQLdb), it's a bit of a nightmare. Compare this to, say, REALbasic, where you just check "Mac OS X Universal" in the Build Settings, click Build, and you're done. (RB has its own issues, of course.) So I would say that Python as a language is great, and its standard framework is great. But its (many) IDEs are pretty poor, and the process of building a polished, packaged app is abysmal. And there are some things (such as Flash-style web applets) that you still can't do at all in Python, even after all these years. But of course, the nice thing about an open-source environment is that, with enough motivation, time, and expertise, one can fix the most annoying limitations oneself. And if I stick with Python over the upcoming years, I'll certainly do my part. Best, - Joe From rt8396 at gmail.com Tue Jan 6 12:37:45 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 09:37:45 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <0546c834-957f-41e3-94e1-db359a5fd36f@w39g2000prb.googlegroups.com> Message-ID: <31bd361e-438b-4d1f-9736-3cd21f128693@e1g2000pra.googlegroups.com> here are a few tuts that go into more detail http://effbot.org/librarybook/datetime.htm http://seehuhn.de/pages/pdate From joe at strout.net Tue Jan 6 12:44:39 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 10:44:39 -0700 Subject: If your were going to program a game... In-Reply-To: References: Message-ID: <49639887.5000806@strout.net> Kay Schluehr wrote: > There is no solution to this problem from a Python perspective. Do > what everyone does right now: use Flash for the game and manage your > site with Python if you like the language. I know this has been discussed before, and the difficulties are many, yadda yadda etc... But suppose we reduce the scope: just the core Python language, maybe a VERY few of the standard modules (e.g. math and string), plus some pygame-like classes to move sprites around, play sounds, and check keyboard and mouse state. Or to look at it another way: Python is used as the scripting language in many commercial games. Why couldn't we make a browser plugin (in C++, for example) that implements a "generic" game, i.e. moving of sprites and playing of sounds and so on -- and that uses Python as its scripting language? Not that I have anything against Flash; I've started learning it just last week, and apart from the nasty C-derived syntax, it's quite nice. It has a good IDE, good performance, great portability, and it's easy to use. It just surprises me that after all these years, the Python community hasn't done something similar. Best, - Joe From sturlamolden at yahoo.no Tue Jan 6 12:45:02 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 09:45:02 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> Message-ID: On Jan 2, 11:39 am, Derek Martin wrote: > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. For one thing, Python's 'assignment model' (an annoying buzzword) is similar to that of Java. It cannot be that different from what is thought in undergraduate CS classes. But take a look at C++: int& foobar(int& x) { // blahblah } Now a statement like 'foobar(x) = y;' can actually have a meaning. Whereas, int* foobar(int& x) { // blahblah } would make the same statement illegal. I have yet to see undergraduate students knowing the difference between C++ pointers and references after attending an introductory CS course. Try to do the same in, say, Java. You will see that is behaves like Python. And as for bizarreness, I feel that Python and Java is greatly surpassed by C++. Note that C do not share the bizarreness of C++. From lists at js3d.co.uk Tue Jan 6 12:51:03 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 17:51:03 -0000 Subject: reading stdout from a running win32 process Message-ID: <017601c97027$58d83690$0a88a3b0$@co.uk> Hi list, I'm launching a process from windows using the demo 'winprocess' from the win32 extensions. I want to be able to record the output of the process as it runs and display it elsewhere. If I use the following [very bad] code: import winprocess import tempfile import time some_condition=True out=tempfile.TemporaryFile() #launch process winprocess.run('xsibatch.exe', show=1, stdout=out, stderr=out) while some_condition<20: print out.read() time.sleep(0.2) some_condition+=1 out.close() I don't seem to be able to read the 'out' at all? If I omit redirecting stdout etc then the output displays fine in the console. Any info / pointers on where I'm going very wrong much appreciated. Jules From rdcollum at gmail.com Tue Jan 6 13:07:04 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 6 Jan 2009 10:07:04 -0800 (PST) Subject: Python subprocess question References: Message-ID: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> On Jan 6, 7:46?am, Duncan Booth wrote: > "Alexi Zuo" wrote: > > Hi everyone, > > > Here I have a simple program which starts a thread and the thread use > > Popen to execute a shell cmd which needs a long time. ?I want to stop > > the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this > > program enters a dead loop. Can anyone tell me what is wrong? > > The KeyboardInterrupt exception is being raised in your main thread which > doesn't handle it so it just terminates. Your child thread isn't marked as > a daemon thread so the program won't exit until the child thread has also > terminated. I've been recently working with threads for the first time and I've been unclear on the setDaemon flag though I've sifted through the documentation for a clear answer (most likely my reading comprehension has failed me and not the documentation). I think I had the notion of that flag backwards. .setDaemon(True) means the thread gets destroyed when the program exits and default .setDaemon(False) means that the thread continues to process even when the main program is gone? From sturlamolden at yahoo.no Tue Jan 6 13:18:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 10:18:29 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: On Jan 6, 3:35 pm, "Dotan Cohen" wrote: > 2009/1/3 Nomen Nescio : > > > python is great. > > No, those are anacondas. Unless Nomen Nescio is thinking of the giant serpent Python from greek mythology. - Python lived in a cave near Delphi. CPython can be embedded in Delphi. - Python was made of slime. CPython runs equally slow. - Python had pythian games. CPython has PyGame. - Pythian can be made pythonian. - Pythians are benevolent. Pythonistas are not (except for Guido). I think that sums it up. From skip at pobox.com Tue Jan 6 13:18:42 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 12:18:42 -0600 Subject: Python subprocess question In-Reply-To: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> References: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> Message-ID: <18787.41090.846416.883877@montanaro.dyndns.org> Roger> .setDaemon(True) means the thread gets destroyed when the program Roger> exits and default .setDaemon(False) means that the thread Roger> continues to process even when the main program is gone? Approximately. The main thread (and thus the program) will exit only when all non-daemon threads have finished. A thread can't continue to run if the main program has exited. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From sturlamolden at yahoo.no Tue Jan 6 13:29:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jan 2009 10:29:49 -0800 (PST) Subject: reading stdout from a running win32 process References: Message-ID: <21f99889-9440-436e-8d0d-de89aa19c1d4@z6g2000pre.googlegroups.com> On Jan 6, 6:51 pm, "Jules Stevenson" wrote: > I don't seem to be able to read the 'out' at all? If I omit redirecting > stdout etc then the output displays fine in the console. You are redirecting to a file, not a pipe. Read the file from beginning to end after your process had finished. Or redirect to a pipe. From jcd at sdf.lonestar.org Tue Jan 6 13:55:36 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 06 Jan 2009 13:55:36 -0500 Subject: python is great In-Reply-To: <496396AF.5020809@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: <1231268136.14487.1.camel@aalcdl07.lib.unc.edu> On Tue, 2009-01-06 at 10:36 -0700, Joe Strout wrote: > I've actually been rather frustrated by Python lately. OFF TOPIC!!! Please try to stay within the subject presented by the subject header. The subject in question is "python is great," not "python is frustrating." Speaking of which, python is truly great. From dotancohen at gmail.com Tue Jan 6 13:59:50 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 20:59:50 +0200 Subject: python is great In-Reply-To: References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> Message-ID: <880dece00901061059m76eb0c00kcc662ebd70bb1055@mail.gmail.com> 2009/1/6 sturlamolden : > On Jan 6, 3:35 pm, "Dotan Cohen" wrote: >> 2009/1/3 Nomen Nescio : >> >> > python is great. >> >> No, those are anacondas. > > Unless Nomen Nescio is thinking of the giant serpent Python from greek > mythology. > The word "great" means large, as well as "doubleplusgood". So I mentioned something related, but larger. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From jgardner at jonathangardner.net Tue Jan 6 14:03:08 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 11:03:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <614dfad7-8367-479f-bf99-45e11ee1122d@w24g2000prd.googlegroups.com> Message-ID: <19350a8e-4e88-4e1a-a75d-45697698088a@k1g2000prb.googlegroups.com> On Jan 6, 8:13?am, sturlamolden wrote: > On Jan 6, 4:32 pm, mark wrote: > > > > Is it possible to > > switch between the custom DSL and the standard Python interpreter? > > > > - Write the DSL interpreter in Python. > There are Python modules out there that make writing a language interpreter almost trivial, provided you are familiar with tools like Bison and the theories about parsing in general. I suggest PLY, but there are other really good solution out there. If you are familiar enough with parsing and the syntax is simple enough, you can write your own parser. The syntax you describe above is really simple, so using str.split and then calling a function based on the first item is probably enough. From jgardner at jonathangardner.net Tue Jan 6 14:04:27 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 11:04:27 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> Message-ID: <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> On Jan 6, 8:18?am, sturlamolden wrote: > On Jan 6, 4:32 pm, mark wrote: > > > I want to implement a internal DSL in Python. I would like the syntax > > as human readable as possible. > > Also beware that Python is not Lisp. You cannot define new syntax (yes > I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. From rcmn73 at gmail.com Tue Jan 6 14:23:22 2009 From: rcmn73 at gmail.com (rcmn) Date: Tue, 6 Jan 2009 11:23:22 -0800 (PST) Subject: parse/slice/... Message-ID: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> I'm not sure how to call it sorry for the subject description. Here what i'm trying to accomplish. the script i'm working on, take a submitted list (for line in file) and generate thread for it. unfortunately winxp has a limit of 500 thread . So I have to parse/slice the file by chunk of 500 and loop until the list is done. I though i would of done it in no time but i can't get started for some reason. And i can't find a good way to do it efficiently . Does anyone have something similar to this. thank you From vinay_sajip at yahoo.co.uk Tue Jan 6 14:24:54 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jan 2009 11:24:54 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> Message-ID: <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> On Jan 6, 4:17 pm, Kottiyath wrote: > I dont want the whole traceback. I just wanted to know where the log > was generated from i.e. which procedure and which line. I have 3/4 > points in many procedures where I encounter a small error (not an > exception) and want to log it. So having individual names for each > looks to be somewhat verbose - esp since the application is >10K LOC. > Don't the funcName and lineno arguments in the format string work for you? (See http://docs.python.org/library/logging.html#id1) Regards, Vinay Sajip From dickinsm at gmail.com Tue Jan 6 14:29:55 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 6 Jan 2009 11:29:55 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> Message-ID: On Jan 6, 3:23?pm, Fredrik Johansson wrote: > FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- > precision standard transcendental functions in pure Python. It is much > faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, > and handles huge arguments just fine. Yes, I think mpmath was mentioned already somewhere above; it sounds like a perfect tool for the OP's requirements. Note that it's still subject to the same limitations as anything else for trig_function(really huge argument), of course: >>> import mpmath >>> mpmath.cos(mpmath.mpf('1e999999999')) [... still waiting for a result 30 minutes later ...] (not a criticism of mpmath: just a demonstration that this really is pretty much unavoidable). Out of curiosity, what sort of guarantees does mpmath give on error bounds? It looks like it aims for 'almost correctly rounded'; i.e., error < 0.500...001 ulps. Here's one place in mpmath where it looks as though more internal precision is needed (with default settings: 53-bit precision, etc.) >>> mpmath.log(mpmath.mpc(0.6, 0.8)) mpc(real='0.0', imag='0.9272952180016123') Shouldn't the real part here be something like: 2.2204460492503132e-17 instead of 0.0? Mark From skip at pobox.com Tue Jan 6 14:30:25 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Jan 2009 13:30:25 -0600 Subject: parse/slice/... In-Reply-To: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: <18787.45393.134938.550581@montanaro.dyndns.org> rcmn> So I have to parse/slice the file by chunk of 500 and loop until rcmn> the list is done. I though i would of done it in no time but i rcmn> can't get started for some reason. Check the itertools module. Probably itertools.islice. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From rdcollum at gmail.com Tue Jan 6 14:34:46 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 6 Jan 2009 11:34:46 -0800 (PST) Subject: Python subprocess question References: <409d6cbc-a82c-45d5-a49a-a5030278136d@d42g2000prb.googlegroups.com> Message-ID: <21301d5c-9db8-4126-a728-d7b6adf07e74@s1g2000prg.googlegroups.com> On Jan 6, 1:18?pm, s... at pobox.com wrote: > ? ? Roger> .setDaemon(True) means the thread gets destroyed when the program > ? ? Roger> exits and default .setDaemon(False) means that the thread > ? ? Roger> continues to process even when the main program is gone? > > Approximately. ?The main thread (and thus the program) will exit only when > all non-daemon threads have finished. ?A thread can't continue to run if the > main program has exited. > > -- > Skip Montanaro - s... at pobox.com -http://smontanaro.dyndns.org/ Gotcha. Thank you, that makes it clearer. =) From kay.schluehr at gmx.net Tue Jan 6 14:42:55 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Tue, 6 Jan 2009 11:42:55 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> > How would one approach this in Python? Do I need to build a custom > loader which compiles *.dsl files to *.pyc files? Is it possible to > switch between the custom DSL and the standard Python interpreter? Sure, but there is no way to avoid extending the Python parser and then your DSL becomes external. I remember having had a similar discussion a while ago with Kevin Dangoor the original TurboGears developer who has also written Paver [1]. In the end DSL syntax wasn't worth the hassle and Kevin developed Paver entirely in Python. Kay [1] http://www.blueskyonmars.com/projects/paver/ From andrea.francia at no.spam.invalid Tue Jan 6 14:45:35 2009 From: andrea.francia at no.spam.invalid (Andrea Francia) Date: Tue, 06 Jan 2009 20:45:35 +0100 Subject: Code Review request for the trash-cli project In-Reply-To: References: Message-ID: <4963b4e4$0$17068$6e1ede2f@read.cnntp.org> Dotan Cohen wrote: > 2009/1/6 Andrea Francia > : >> The trash-cli project is a opensource implementation of the FreeDesktop.org > > I don't know about the code, but would there be a reason _not_ to > alias rm, rmdir to this program? Actually the trash-put command accept all the options of GNU rm in order allows user doing alias rm='trash-put', but it does not accept yet some GNU rmdir options (--ignore-fail-on-non-empty, -p, --parents). A enhancement issue about accepting rmdir options was added to the tracker. > I see that it is GPL, so this would > be a great addition to any Linux distro. It's available in some distro but many distro uses a very old version, to gain all the advantages of the latest development version you can use: easy_install trash-cli The easy_install command is provided by the python-setuptools package. From mrmakent at cox.net Tue Jan 6 14:53:03 2009 From: mrmakent at cox.net (Mike Kent) Date: Tue, 6 Jan 2009 11:53:03 -0800 (PST) Subject: Problem building Python 2.5.2 curses module on HP/UX 11.11 Message-ID: I'm having a problem building the Python 2.5.2 curses module on HP/UX 11.11 using gcc 3.3.6, and was hoping someone had a solution. Compiling Modules/_cursesmodule.c is giving several warnings, but no errors. The relevant compile/link output is below. The key output line is: *** WARNING: renaming "_curses" since importing it failed: dynamic module does n ot define init function (init_curses) So, given that there are no actual errors during the compile, and the warnings are probably benign, does anyone know what would cause the resulting compiled module to NOT have the init function? Full build output: building '_curses' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict- prototype s -I. -I/usr/local/src/xyzpython/Python-2.5.2/./Include -I/usr/local/ xyz/python/ include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/ src/xyzpytho n/Python-2.5.2/Include -I/usr/local/src/xyzpython/Python-2.5.2 -c /usr/ local/src /xyzpython/Python-2.5.2/Modules/_cursesmodule.c -o build/temp.hp-ux-B. 11.11-9000 -800-2.5/usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.o In file included from /usr/local/src/xyzpython/Python-2.5.2/Include/ Python.h:8, from /usr/local/src/xyzpython/Python-2.5.2/Modules/ _cursesmodul e.c:102: pyconfig.h:942:1: warning: "_POSIX_C_SOURCE" redefined :6:1: warning: this is the location of the previous definition /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rsesWindow_AddStr': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:449: warning: impl icit declaration of function `getattrs' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_getsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1712: warning: imp licit declaration of function `getsyx' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_setsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2369: warning: imp licit declaration of function `setsyx' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_UnCtrl': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2499: warning: imp licit declaration of function `unctrl' /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2499: warning: pas sing arg 1 of `PyString_FromString' makes pointer from integer without a cast /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: In function `PyCu rses_getsyx': /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1708: warning: `x' might be used uninitialized in this function /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:1708: warning: `y' might be used uninitialized in this function /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c: At top level: /usr/local/src/xyzpython/Python-2.5.2/Modules/_cursesmodule.c:2266: warning: `up date_lines_cols' defined but not used ld -b build/temp.hp-ux-B.11.11-9000-800-2.5/usr/local/src/xyzpython/ Python-2.5.2 /Modules/_cursesmodule.o -L/usr/local/xyz/python/lib -L/usr/local/lib - lncurses -o build/lib.hp-ux-B.11.11-9000-800-2.5/_curses.sl *** WARNING: renaming "_curses" since importing it failed: dynamic module does n ot define init function (init_curses) From mal at egenix.com Tue Jan 6 15:02:36 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 21:02:36 +0100 Subject: python is great In-Reply-To: <496396AF.5020809@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: <4963B8DC.1020508@egenix.com> On 2009-01-06 18:36, Joe Strout wrote: > I've actually been rather frustrated by Python lately. It's great at > some things, but rather poor at others. In the latter category is > building a neatly packaged executable that can be shipped to users and > run reliably on their machine. On the Mac in particular, if you want > your app to run on any PowerPC or Intel machine runing 10.4 or later, > and you're using anything not in the standard framework (such as > MySQLdb), it's a bit of a nightmare. > > Compare this to, say, REALbasic, where you just check "Mac OS X > Universal" in the Build Settings, click Build, and you're done. (RB has > its own issues, of course.) You're looking for py2app: http://undefined.org/python/py2app.html (creating a button that invokes it is left as exercise to the interested reader :-) > So I would say that Python as a language is great, and its standard > framework is great. But its (many) IDEs are pretty poor, and the > process of building a polished, packaged app is abysmal. It's certainly work, but that's always the case for nicely polished apps :-) For packaging, you can choose from a multitude of installer builders - none of which are really Python specific. We tend to use InnoSetup on Windows, the Mac OS installer for Mac OS X and an installer shell script for Unix. More recently we've found InstallJammer which looks very promising, esp. when building applications for multiple platforms. > And there are > some things (such as Flash-style web applets) that you still can't do at > all in Python, even after all these years. You're looking for Silverlight: http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > But of course, the nice thing about an open-source environment is that, > with enough motivation, time, and expertise, one can fix the most > annoying limitations oneself. And if I stick with Python over the > upcoming years, I'll certainly do my part. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From james at agentultra.com Tue Jan 6 15:04:04 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:04:04 -0500 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <495f8fcc$0$20340$426a34cc@news.free.fr> <01700ab5$0$8693$c3e8da3@news.astraweb.com> Message-ID: <858wporykr.fsf@dozer.localdomain> "Gabriel Genellina" writes: > En Mon, 05 Jan 2009 02:03:26 -0200, Roy Smith escribi?: > > >> The other day, I came upon this gem. It's a bit of perl embedded in a >> Makefile; this makes it even more gnarly because all the $'s get >> doubled to >> hide them from make: >> >> define absmondir >> $(shell perl -e ' \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? sub absmon { my $$a = $$_[0]; \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? ? ? ?? if ( $$^O =~ m/cygwin|MSWin32/i ) { ? ? ? ? ? ? ? ? ? ? >> ? ? ? ? ? ? ? ?? ? ?$$prefix = `/bin/mount -p|awk "NR==2{print >> \\\$$1}"`; >> chomp($$prefix); \ >> ?? ? ?$$a = ($$_[1]||"$(PWD)") . "/$$a" \ >> ?? ? ? ? unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \ >> ?? } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! >> ); } \ >> ?? return unslash(undot(undotdot($$a))); }; \ >> sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::; >> return($$_[0]); >> }; \ >> sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \ >> sub undotdot ($$) { my $$in = $$_[0]; \ >> ?? ? ?return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \ >> print absmon("$(1)","$(2)"); \ >> ' ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> ? ? endef >> >> Barf-o-rama. I know what it's supposed to do, and I still can't >> figure it out. > > Ouch! Me too, when I come to some piece of Perl code I've written some > years ago, I invariably think "what's all this noise?". Never happens > with other languages I've used in the past. I still occassion upon the chance to write some Perl, and even as a full-time developer who works with Python for a living, I relish every opportunity. The funny thing is that I've never had the problem of writing code like this in Perl. The example is a very poor use-case and doesn't reflect on the useful/useless-ness of the language itself but more on the choices of the implementor. Perl is a very useful language overall and when used properly, very powerful. From marduk at letterboxes.org Tue Jan 6 15:05:46 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 06 Jan 2009 15:05:46 -0500 Subject: parse/slice/... In-Reply-To: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: <1231272346.3312.7.camel@localhost.localdomain> On Tue, 2009-01-06 at 11:23 -0800, rcmn wrote: > I'm not sure how to call it sorry for the subject description. > Here what i'm trying to accomplish. > the script i'm working on, take a submitted list (for line in file) > and generate thread for it. unfortunately winxp has a limit of 500 > thread . So I have to parse/slice the file by chunk of 500 and loop > until the list is done. > I though i would of done it in no time but i can't get started for > some reason. > And i can't find a good way to do it efficiently . Does anyone have > something similar to this. If your thread is smart enough to handle the file you can do something like: class Worker(threading.Thread): def __init__(self, file_object): self.file_object = file_object threading.Thread.__init__(self) def run(self): while True: line = self.file_object.readline() if line == '': return # process line NUM_WORKERS = 500 bigfile = open('somefile', 'r') workers = [Worker(bigfile) for i in range(NUM_WORKERS)] for worker in workers: worker.start() From dotancohen at gmail.com Tue Jan 6 15:05:59 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 22:05:59 +0200 Subject: image recogniton? In-Reply-To: <18787.32403.82637.308936@montanaro.dyndns.org> References: <3a4a8f930901060650q25170071hdd4b4b8eaf93c0c9@mail.gmail.com> <18787.32403.82637.308936@montanaro.dyndns.org> Message-ID: <880dece00901061205x1a84c1d6yda49e7244ee38306@mail.gmail.com> This was just mentioned on the KDE bugtracker: http://opencv.willowgarage.com/wiki/FaceDetection -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From radix at twistedmatrix.com Tue Jan 6 15:07:34 2009 From: radix at twistedmatrix.com (Christopher Armstrong) Date: Tue, 6 Jan 2009 15:07:34 -0500 Subject: ANN: Twisted 8.2 released Message-ID: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> Version 8.2 of Twisted is now out (actually, it's been out for over a week now!). You can download it (in Windows, Mac, and source forms) at: http://twistedmatrix.com/ Twisted 8.2 is a major feature release, also including many important bug fixes: * twistd now has a --umask option for specifying the umask * Log observers can now be configured in .tac files * ProcessProtocols can now implement processExited to get reliable notification of a process exiting * FTPClient has many more convenience methods * Twisted.words now has a standalone XMPP router * Twisted.names now supports NAPTR records * Twisted.web can now deal with multi-value headers and supports the Range header in requests for static files There have been many additional improvements which you can read all about in the release notes: http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/NEWS?format=raw What is Twisted? From the web site: Twisted is an event-driven networking engine written in Python and licensed under the MIT license. Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH, IRC, FTP, and others), and much more. See more at: http://twistedmatrix.com/ -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/ http://canonical.com/ From mal at egenix.com Tue Jan 6 15:11:40 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 21:11:40 +0100 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> References: <000ef06c-46ab-4253-ae91-2c1f7e6e52a7@o4g2000pra.googlegroups.com> Message-ID: <4963BAFC.1040209@egenix.com> On 2009-01-06 20:42, Kay Schluehr wrote: >> How would one approach this in Python? Do I need to build a custom >> loader which compiles *.dsl files to *.pyc files? Is it possible to >> switch between the custom DSL and the standard Python interpreter? > Sure, but there is no way to avoid extending the Python parser and > then your DSL becomes external. Try python4ply: http://dalkescientific.com/Python/python4ply.html ...much easier to work with than extending the Python parser by hand. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From rt8396 at gmail.com Tue Jan 6 15:13:56 2009 From: rt8396 at gmail.com (r) Date: Tue, 6 Jan 2009 12:13:56 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> Message-ID: On Jan 6, 11:36?am, Joe Strout wrote: > I've actually been rather frustrated by Python lately. ?It's great at > some things, but rather poor at others. ?In the latter category is > building a neatly packaged executable that can be shipped to users and > run reliably on their machine. ?On the Mac in particular, if you want > your app to run on any PowerPC or Intel machine runing 10.4 or later, > and you're using anything not in the standard framework (such as > MySQLdb), it's a bit of a nightmare. > > Compare this to, say, REALbasic, where you just check "Mac OS X > Universal" in the Build Settings, click Build, and you're done. ?(RB has > its own issues, of course.) > > So I would say that Python as a language is great, and its standard > framework is great. ?But its (many) IDEs are pretty poor, and the > process of building a polished, packaged app is abysmal. ?And there are > some things (such as Flash-style web applets) that you still can't do at > all in Python, even after all these years. > > But of course, the nice thing about an open-source environment is that, > with enough motivation, time, and expertise, one can fix the most > annoying limitations oneself. ?And if I stick with Python over the > upcoming years, I'll certainly do my part. > > Best, > - Joe Joe, At post.readlines()[:1] i was quite angry, but from [2:] i started agreeing very much with you. I very much love the python programming language(and everyone here knows that) but app packaging is dismal in python. And many improvements need to be made to IDLE. You make some very good points and hopefully i will be able to give my time shortly to help fix some of these deficiencies. PS: Whoever rated the OP with one star needs to hang out somewhere else! From james at agentultra.com Tue Jan 6 15:14:05 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:14:05 -0500 Subject: image recogniton? References: Message-ID: <854p0cry42.fsf@dozer.localdomain> Li Han writes: > Hi! I know little about the computer image processing, and now I have > a fancy problem which is how to read the time from the picture of a > clock by programming ? Is there anyone who can give me some > suggestions? > Thank! > Li Han I do work in object recognition, and I would classify this as a rather difficult problem. Not impossible of course, but you'll need some OCR to read the clock face and some sort of magnitude vector feature to tell which hand is which and the "general direction" is is pointing in. Also, depends if we're talking digital clocks or analog. :) The other problem is one of accuracy: depending on your input image, even slight variances can change your results. I'm curious as to what application the solution to this problem is practical for all of its difficulty? From joe at strout.net Tue Jan 6 15:24:40 2009 From: joe at strout.net (Joe Strout) Date: Tue, 06 Jan 2009 13:24:40 -0700 Subject: python is great In-Reply-To: <4963B8DC.1020508@egenix.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> Message-ID: <4963BE08.5070006@strout.net> M.-A. Lemburg wrote: >> On the Mac in particular, if you want >> your app to run on any PowerPC or Intel machine runing 10.4 or later, >> and you're using anything not in the standard framework (such as >> MySQLdb), it's a bit of a nightmare. >> > > You're looking for py2app: > > http://undefined.org/python/py2app.html No, I'm *using* py2app. I've been trying to use it for a couple of weeks now, with the generous help of such people as Robin Dunn, and I still don't have it quite working properly. (I'd be happy to send you my notes on what was required to get as far as I've gotten, but it's several pages, a bit long to post here.) (py2exe works a little more easily, thank goodness.) >> So I would say that Python as a language is great, and its standard >> framework is great. But its (many) IDEs are pretty poor, and the >> process of building a polished, packaged app is abysmal. > > It's certainly work, but that's always the case for nicely polished > apps :-) In Python, yes. :) Not in all environments. > For packaging, you can choose from a multitude of installer builders - > none of which are really Python specific. I'm not even talking about that level of packaging -- I'm just talking about making something that appears to the user like a normal executable, which they can double-click on their system and have it actually run, rather than aborting with something unhelpful like "No module named MySQLdb". >> And there are >> some things (such as Flash-style web applets) that you still can't do at >> all in Python, even after all these years. > > You're looking for Silverlight: > http://www.voidspace.org.uk/ironpython/silverlight/index.shtml Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit that this does mostly fit the bill I described above (or has the potential to, anyway). Thanks, - Joe From james at agentultra.com Tue Jan 6 15:24:43 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 06 Jan 2009 15:24:43 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> Message-ID: <85zli4qj1w.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 6, 8:18?am, sturlamolden wrote: >> On Jan 6, 4:32 pm, mark wrote: >> >> > I want to implement a internal DSL in Python. I would like the syntax >> > as human readable as possible. >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >> I've seen the goto joke). > > This isn't really true. You can, for instance, write a program (in > Python) that takes your pseudo-Python and converts it into Python. > This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. From akineko at gmail.com Tue Jan 6 15:34:48 2009 From: akineko at gmail.com (akineko) Date: Tue, 6 Jan 2009 12:34:48 -0800 (PST) Subject: subclassing 'list' Message-ID: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Hello everyone, I'm creating a class which is subclassed from list (Bulit-in type). It works great. However, I'm having a hard time finding a way to set a new value to the object (within the class). There are methods that alter a part of the object (ex. __setitem__()). But I couldn't find any method that can replace the value of the object. I wanted to do something like the following: class Mylist(list): def arrange(self): new_value = .... list.self.__assign__.(self, new_value) I serached the newsgroup and found that assignment operator ('=') cannot be overridden because it is not an operator. But it shouldn't stop Python to provide a way to re-assign the value internally. Any suggestions will be highly appreciated. Best regards, Aki- From benjamin.kaplan at case.edu Tue Jan 6 15:36:44 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 6 Jan 2009 15:36:44 -0500 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: On Tue, Jan 6, 2009 at 3:24 PM, Joe Strout wrote: > M.-A. Lemburg wrote: > > On the Mac in particular, if you want >>> your app to run on any PowerPC or Intel machine runing 10.4 or later, >>> and you're using anything not in the standard framework (such as >>> MySQLdb), it's a bit of a nightmare. >>> >>> >> You're looking for py2app: >> >> http://undefined.org/python/py2app.html >> > > No, I'm *using* py2app. I've been trying to use it for a couple of weeks > now, with the generous help of such people as Robin Dunn, and I still don't > have it quite working properly. (I'd be happy to send you my notes on what > was required to get as far as I've gotten, but it's several pages, a bit > long to post here.) > > (py2exe works a little more easily, thank goodness.) > > So I would say that Python as a language is great, and its standard >>> framework is great. But its (many) IDEs are pretty poor, and the >>> process of building a polished, packaged app is abysmal. >>> >> >> It's certainly work, but that's always the case for nicely polished >> apps :-) >> > > In Python, yes. :) Not in all environments. > > For packaging, you can choose from a multitude of installer builders - >> none of which are really Python specific. >> > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal executable, > which they can double-click on their system and have it actually run, rather > than aborting with something unhelpful like "No module named MySQLdb". > > And there are >>> some things (such as Flash-style web applets) that you still can't do at >>> all in Python, even after all these years. >>> >> >> You're looking for Silverlight: >> http://www.voidspace.org.uk/ironpython/silverlight/index.shtml >> > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit that > this does mostly fit the bill I described above (or has the potential to, > anyway). If your only problem with Silverlight is Microsoft, there is an open source .NET implementation called Mono (www.mono-project.com) and an open source Silverlight plugin, Moonlight (http://www.go-mono.com/moonlight/). > > > Thanks, > - Joe > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 6 15:43:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 12:43:57 -0800 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <50697b2c0901061243o1b88e249w2eb3da51140db548@mail.gmail.com> On Tue, Jan 6, 2009 at 12:34 PM, akineko wrote: > > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) If you mean you want to replace the contents of the list with that of another list, just do: def arrange(self): self.clear() #empty the list self.extend(new_list) #append the contents of other list If you instead mean that you want the object to somehow completely "become" or be replaced by another object, that's not possible (short of proxying). Smalltalk has a `become` method, but not Python (it's pretty deep black magic anyway). If you gave more info about _why_ you want to do that, someone could probably suggest an alternative. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jstroud at mbi.ucla.edu Tue Jan 6 15:45:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 06 Jan 2009 12:45:53 -0800 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) > > I serached the newsgroup and found that assignment operator ('=') > cannot be overridden because it is not an operator. But it shouldn't > stop Python to provide a way to re-assign the value internally. > > Any suggestions will be highly appreciated. > > Best regards, > Aki- Slice assignment will behave as you like: py> class Mylist(list): ... def arrange(self): ... new_value = [1, 2, 3] ... self[:] = new_value ... py> m = Mylist() py> m.arrange() py> m [1, 2, 3] Your other option is to arrange the list in-place, depending on what it means to arrange the list. You may want to provide a more explicit example. From dotancohen at gmail.com Tue Jan 6 16:05:58 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 6 Jan 2009 23:05:58 +0200 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: <880dece00901061305l69806a14l6e79673c05bc4518@mail.gmail.com> 2009/1/6 Joe Strout : > No, I'm *using* py2app. I've been trying to use it for a couple of weeks > now, with the generous help of such people as Robin Dunn, and I still don't > have it quite working properly. (I'd be happy to send you my notes on what > was required to get as far as I've gotten, but it's several pages, a bit > long to post here.) > If you want to save me the trouble, then I'd like to see those notes. If you want, I can host the notes at dotancohen.com to that they will be publicaly accessible. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From jcd at sdf.lonestar.org Tue Jan 6 16:09:13 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 06 Jan 2009 16:09:13 -0500 Subject: subclassing 'list' In-Reply-To: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <1231276153.16001.12.camel@aalcdl07.lib.unc.edu> On Tue, 2009-01-06 at 12:34 -0800, akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a part of the object (ex. __setitem__()). > But I couldn't find any method that can replace the value of the > object. > I wanted to do something like the following: > > class Mylist(list): > > def arrange(self): > new_value = .... > list.self.__assign__.(self, new_value) > > I serached the newsgroup and found that assignment operator ('=') > cannot be overridden because it is not an operator. But it shouldn't > stop Python to provide a way to re-assign the value internally. Aki, I'm not sure I understand your problem. What I see above is an attribute error: AttributeError: type object 'list' has no attribute 'self' coming from your use of list.self, but it doesn't sound like that's what you are asking about. Do you mean that you want to be able to specify some sort of processing to be done when you assign to an attribute of your object? To do that, you need to use properties: import math class Circle(object): def __init__(self, radius=1.0): self._radius = radius self.circum = 2.0 * self._radius * math.pi def __get_radius(self): return self._radius def __set_radius(self,radius): self._radius = radius self.circum = 2.0 * self._radius * math.pi radius = property(__get_radius, __set_radius) Then you can do: >>> circ = Circle(2.0) >>> print circ.radius 2.0 >>> print circ.circum 12.5663706144 >>> circ.radius = 4.5 >>> print circ.radius 4.5 >>> print circ.circum 28.2743338823 There are lots of good tutorials on this online. From mal at egenix.com Tue Jan 6 16:09:52 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2009 22:09:52 +0100 Subject: python is great In-Reply-To: <4963BE08.5070006@strout.net> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <4963BE08.5070006@strout.net> Message-ID: <4963C8A0.8090606@egenix.com> On 2009-01-06 21:24, Joe Strout wrote: > M.-A. Lemburg wrote: > >>> On the Mac in particular, if you want >>> your app to run on any PowerPC or Intel machine runing 10.4 or later, >>> and you're using anything not in the standard framework (such as >>> MySQLdb), it's a bit of a nightmare. >>> >> >> You're looking for py2app: >> >> http://undefined.org/python/py2app.html > > No, I'm *using* py2app. I've been trying to use it for a couple of > weeks now, with the generous help of such people as Robin Dunn, and I > still don't have it quite working properly. (I'd be happy to send you > my notes on what was required to get as far as I've gotten, but it's > several pages, a bit long to post here.) Perhaps not post it here, but put it up on the web somewhere and link to it from the Python.org wiki. > (py2exe works a little more easily, thank goodness.) We're using py2exe to wrap up apps on Windows and then pass them on to InnoSetup for creating the installer. On Unix, we tried using cx_Freeze, but that had too many issues. We've then modified and updated an old project of mine, called mxCGIPython, to create a one file Python interpreter and use that with the applications: http://www.egenix.com/www2002/python/mxCGIPython.html One of these days, we're going to release the new version as OSS. >>> So I would say that Python as a language is great, and its standard >>> framework is great. But its (many) IDEs are pretty poor, and the >>> process of building a polished, packaged app is abysmal. >> >> It's certainly work, but that's always the case for nicely polished >> apps :-) > > In Python, yes. :) Not in all environments. Hmm, I'm not only referring to nice looking GUIs. Those are only part of the game. More important is well working application, without any annoying bugs. >> For packaging, you can choose from a multitude of installer builders - >> none of which are really Python specific. > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal > executable, which they can double-click on their system and have it > actually run, rather than aborting with something unhelpful like "No > module named MySQLdb". That's part of polishing the application, IMHO. For point-and-click apps, you need to include all the required dependencies together with the application. >>> And there are >>> some things (such as Flash-style web applets) that you still can't do at >>> all in Python, even after all these years. >> >> You're looking for Silverlight: >> http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit > that this does mostly fit the bill I described above (or has the > potential to, anyway). Ok, how about a Firefox Extension, then... http://pyxpcomext.mozdev.org/ together with a shell: http://pyxpcomext.mozdev.org/samples.html#pyshell With this plugin you write the GUI using XUL and JavaScript... and after some polishing, which includes dropping the Firefox GUI and turning to XULRunner, you can create apps such as Miro: http://www.getmiro.com/ and watch TED videos driven by Python (and a gazillion other tools working for you behind the scenes). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From akineko at gmail.com Tue Jan 6 16:11:00 2009 From: akineko at gmail.com (akineko) Date: Tue, 6 Jan 2009 13:11:00 -0800 (PST) Subject: subclassing 'list' References: <3fcc7752-5209-4781-b7bc-5e5baa7af1da@f40g2000pri.googlegroups.com> Message-ID: <8ece7e06-70fc-4e12-b78d-ec20dc3fb06c@n33g2000pri.googlegroups.com> Hello Chris and James, Thank you for you guys' prompt response. Yes, that is what I wanted to do. I, somehow, didn't think of using those list methods. Instead, I was looking for a single method to override. Big Thanks! Aki- On Jan 6, 12:43 pm, "Chris Rebert" wrote: > If you mean you want to replace the contents of the list with that of > another list, just do: > > def arrange(self): > self.clear() #empty the list > self.extend(new_list) #append the contents of other list On Jan 6, 12:45 pm, James Stroud wrote: > Slice assignment will behave as you like: > > py> class Mylist(list): > ... def arrange(self): > ... new_value = [1, 2, 3] > ... self[:] = new_value > ... From nospam at nospam.com Tue Jan 6 16:13:38 2009 From: nospam at nospam.com (Gilles Ganault) Date: Tue, 06 Jan 2009 22:13:38 +0100 Subject: [http] Example with proxy + post + cookie? Message-ID: Hello I need to write a script that goes out through a proxy, connects with a POST query, and receives a cookie for a Session ID. I didn't find an example on the Net that did it all three, but only some of the features. Does someone have one handy by any chance? Thank you. From nospam at nospam.com Tue Jan 6 16:16:35 2009 From: nospam at nospam.com (Gilles Ganault) Date: Tue, 06 Jan 2009 22:16:35 +0100 Subject: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip' References: <3jc3m45r2m7ie65s2rq0p9463kpo930cv6@4ax.com> Message-ID: On Mon, 05 Jan 2009 17:54:19 -0500, Terry Reedy wrote: >> for email in rows: >> To = email Thanks guys. Turns out email is a tuple, so here's how to extract the columns: for email in rows: email=email[0] From steve at holdenweb.com Tue Jan 6 16:19:00 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 06 Jan 2009 16:19:00 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <85zli4qj1w.fsf@dozer.localdomain> References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> Message-ID: J Kenneth King wrote: [...] > I could go on a really long rant about how the two are worlds apart, but > I'll let Google tell you if you're really interested. a) How is Google going to know if he's really interested? b) Put a space after the "--" in your sig, please; that way my mailer won't yto to quote your signature as part of the message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From philip at semanchuk.com Tue Jan 6 16:21:07 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 6 Jan 2009 16:21:07 -0500 Subject: pep-8 vs. external interfaces? In-Reply-To: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> Message-ID: <01F63503-9BCE-49BF-88D1-5FFC0DC113A9@semanchuk.com> On Jan 4, 2009, at 2:47 PM, Roy Smith wrote: > I'm building a Python language wrapper to an network protocol which > traditionally uses camelCase function names. I'm trying to make the > new code pep-8 compliant, which means function names should be written > this_way() instead of thisWay(). I've got a couple of choices open to > me. > > I could convert all the protocol names to pep-8 style mechanically. > This is not as much work as it seems; the lowest-level Python code is > already machine generated from a tabular description of the protocol. > It's about one more line of code to convert getLibraries() to > get_libraries(). This will leave the result the cleanest from the > Python point of view. It'll also make the Python binding look a > little different from the C++, Java, Perl, etc, bindings. +1 for PEP 8 compliance. Programmers unfamiliar with the existing protocol will appreciate its Pythonic feel instead of wondering why the names are all "wrong". Those familiar with the existing protocol will have to make a mental adjustment, but at least they'll be adjusting to a target (standard Python style) that they presumably know. > I figure either way, somebody's going to complain that I did it > wrong :-) I promise to be the first to complain no matter what you choose. ;) Good luck Philip From kyosohma at gmail.com Tue Jan 6 16:24:10 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 6 Jan 2009 13:24:10 -0800 (PST) Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> Message-ID: <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> On Jan 6, 2:24?pm, Joe Strout wrote: > M.-A. Lemburg wrote: > >> On the Mac in particular, if you want > >> your app to run on any PowerPC or Intel machine runing 10.4 or later, > >> and you're using anything not in the standard framework (such as > >> MySQLdb), it's a bit of a nightmare. > > > You're looking for py2app: > > >http://undefined.org/python/py2app.html > > No, I'm *using* py2app. ?I've been trying to use it for a couple of > weeks now, with the generous help of such people as Robin Dunn, and I > still don't have it quite working properly. ?(I'd be happy to send you > my notes on what was required to get as far as I've gotten, but it's > several pages, a bit long to post here.) > > (py2exe works a little more easily, thank goodness.) > > >> So I would say that Python as a language is great, and its standard > >> framework is great. ?But its (many) IDEs are pretty poor, and the > >> process of building a polished, packaged app is abysmal. > > > It's certainly work, but that's always the case for nicely polished > > apps :-) > > In Python, yes. ?:) ?Not in all environments. > > > For packaging, you can choose from a multitude of installer builders - > > none of which are really Python specific. > > I'm not even talking about that level of packaging -- I'm just talking > about making something that appears to the user like a normal > executable, which they can double-click on their system and have it > actually run, rather than aborting with something unhelpful like "No > module named MySQLdb". > > >> And there are > >> some things (such as Flash-style web applets) that you still can't do at > >> all in Python, even after all these years. > > > You're looking for Silverlight: > >http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > Maybe. ?I'm not a big fan of anything so Microsoftian, but I'll admit > that this does mostly fit the bill I described above (or has the > potential to, anyway). > > Thanks, > - Joe I use Andrea Gavana's GUI2Exe to create my binaries. He recently added a py2app wrapper to it. I don't have a Mac, so I haven't tested that part of his app. However, the py2exe portion rocks! I put in the path to my main Python executable, add any special 3rd party modules and it just works! I've written a tutorial for the py2exe part of it if you're interested... Mike From lasizoillo at gmail.com Tue Jan 6 16:26:23 2009 From: lasizoillo at gmail.com (lasizoillo) Date: Tue, 6 Jan 2009 22:26:23 +0100 Subject: [Twisted-web] ANN: Twisted 8.2 released In-Reply-To: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> References: <60ed19d40901061207p4260331en8a4021a0dda0df4c@mail.gmail.com> Message-ID: <49414f570901061326v1d500b35ob95c603ca7d4449f@mail.gmail.com> 2009/1/6 Christopher Armstrong : > Version 8.2 of Twisted is now out (actually, it's been out for over a > week now!). You can download it (in Windows, Mac, and source forms) > at: > > http://twistedmatrix.com/ This year is for 9.x version, isn't? A query to cheese shop returns 8.1 Version: http://pypi.python.org/pypi?%3Aaction=search&term=twisted&submit=search :-( Thanks a lot for all twisted contributors > > Twisted 8.2 is a major feature release, also including many important bug fixes: > > * twistd now has a --umask option for specifying the umask > * Log observers can now be configured in .tac files > * ProcessProtocols can now implement processExited to get reliable > notification of a process exiting > * FTPClient has many more convenience methods > * Twisted.words now has a standalone XMPP router > * Twisted.names now supports NAPTR records > * Twisted.web can now deal with multi-value headers and supports the > Range header in requests for static files > > There have been many additional improvements which you can read all > about in the release notes: > > http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/NEWS?format=raw > > > What is Twisted? From the web site: > > Twisted is an event-driven networking engine written in Python and > licensed under the MIT license. > > Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix > sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH, > IRC, FTP, and others), and much more. See more at: > > http://twistedmatrix.com/ > > > -- > Christopher Armstrong > http://radix.twistedmatrix.com/ > http://planet-if.com/ > http://canonical.com/ > > _______________________________________________ > Twisted-web mailing list > Twisted-web at twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web > From aleksandr.goretoy at gmail.com Tue Jan 6 16:28:11 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 6 Jan 2009 21:28:11 +0000 Subject: python is great In-Reply-To: <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> <4963B8DC.1020508@egenix.com> <2bdd2c19-9eb3-44a7-8da1-26058d474e9d@p2g2000prn.googlegroups.com> Message-ID: > > I use Andrea Gavana's GUI2Exe to create my binaries. He recently added > a py2app wrapper to it. I don't have a Mac, so I haven't tested that > part of his app. However, the py2exe portion rocks! I put in the path > to my main Python executable, add any special 3rd party modules and it > just works! I've written a tutorial for the py2exe part of it if > you're interested... > Can you post the link to this tutorial? If you want to save me the trouble, then I'd like to see those notes. > If you want, I can host the notes at dotancohen.com to that they will > be publicaly accessible. > Any more news on this research? -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Tue, Jan 6, 2009 at 9:24 PM, Mike Driscoll wrote: > On Jan 6, 2:24 pm, Joe Strout wrote: > > M.-A. Lemburg wrote: > > >> On the Mac in particular, if you want > > >> your app to run on any PowerPC or Intel machine runing 10.4 or later, > > >> and you're using anything not in the standard framework (such as > > >> MySQLdb), it's a bit of a nightmare. > > > > > You're looking for py2app: > > > > >http://undefined.org/python/py2app.html > > > > No, I'm *using* py2app. I've been trying to use it for a couple of > > weeks now, with the generous help of such people as Robin Dunn, and I > > still don't have it quite working properly. (I'd be happy to send you > > my notes on what was required to get as far as I've gotten, but it's > > several pages, a bit long to post here.) > > > > (py2exe works a little more easily, thank goodness.) > > > > >> So I would say that Python as a language is great, and its standard > > >> framework is great. But its (many) IDEs are pretty poor, and the > > >> process of building a polished, packaged app is abysmal. > > > > > It's certainly work, but that's always the case for nicely polished > > > apps :-) > > > > In Python, yes. :) Not in all environments. > > > > > For packaging, you can choose from a multitude of installer builders - > > > none of which are really Python specific. > > > > I'm not even talking about that level of packaging -- I'm just talking > > about making something that appears to the user like a normal > > executable, which they can double-click on their system and have it > > actually run, rather than aborting with something unhelpful like "No > > module named MySQLdb". > > > > >> And there are > > >> some things (such as Flash-style web applets) that you still can't do > at > > >> all in Python, even after all these years. > > > > > You're looking for Silverlight: > > >http://www.voidspace.org.uk/ironpython/silverlight/index.shtml > > > > Maybe. I'm not a big fan of anything so Microsoftian, but I'll admit > > that this does mostly fit the bill I described above (or has the > > potential to, anyway). > > > > Thanks, > > - Joe > > I use Andrea Gavana's GUI2Exe to create my binaries. He recently added > a py2app wrapper to it. I don't have a Mac, so I haven't tested that > part of his app. However, the py2exe portion rocks! I put in the path > to my main Python executable, add any special 3rd party modules and it > just works! I've written a tutorial for the py2exe part of it if > you're interested... > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From David Tue Jan 6 16:34:03 2009 From: David (David) Date: Tue, 06 Jan 2009 15:34:03 -0600 Subject: How to get millisec/fractional seconds out of a time object ? Message-ID: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Thanks for help to a beginner. script23 import time import datetime start_time = datetime.datetime.now() time.sleep(0.14) end_time = datetime.datetime.now() datetime.timedelta = end_time - start_time print(datetime.timedelta) # works, prints 0:00:0.141000 print(datetime.timedelta.seconds) # prints 0 print(datetime.timedelta.milliseconds) # fails < object has no attribute milliseconds > How do I get the 0.141000 out of that or any time object ? On line docs are arcane to a novice. From castironpi at gmail.com Tue Jan 6 16:43:01 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 6 Jan 2009 13:43:01 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> On Jan 6, 8:03?am, Mark Wooding wrote: > Steven D'Aprano wrote: snip > > It seems that you don't include in the Python community all those who > > use the term "name binding" instead of variable assignment > > specifically because it gives new users a clue that Python is not the > > same as C. > > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. > > Let me explain. ?I'll try to be clear, though I know that Stephen > already understands this stuff well. > > At run-time, each named variable denotes a storage area (I'll call it a > slot[2]) which holds a reference to some object[1]. > > ? ? ? ? ? ? ? +-----+ > ? ?name ----> | ref -----> object ? > ? ? ? ? ? ? ? +-----+ > > If we `assign' a different object to the variable, what really happens > is that the slot is modified to refer to the other object; but the name > continues to denote the same slot. > > Usually `binding', or `rebinding', a name describes a different process, > whereby the name (for a while) denotes a different slot. ?This name-to- > slot mapping is important because it's the mapping which is inherited by > nested functions. Say you start with: +------+ a ----> | ref1 -----> (1, 2, 3) +------+ Then you can do: +------+ a ----> | ref2 -----> (4, 5, 6) +------+ But not: +------+ a ----> | ref1 -----> (4, 5, 6) +------+ That is, you can 'repoint a' to another 'ref', but not repoint a 'ref'. I think one of the ideas we have trouble communicating is that [1, 2, 3] and [4, 5, 6] can be the same object (using '[:]='), but [1, 2, 3] and [1, 2, 3] don't have to be. From Scott.Daniels at Acm.Org Tue Jan 6 16:44:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 06 Jan 2009 13:44:31 -0800 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <9rOdnbo7LoQaTf7UnZ2dnUVZ_sTinZ2d@pdx.net> David Lemper wrote: > Thanks for help to a beginner. > > script23 > ... > datetime.timedelta = end_time - start_time This is a bad idea. You are changing the globals of another module. You are lucky you didn't break anything. Better would be: elapsed = end_time - start_time then use things like: print elapsed print elapsed.seconds >... How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. Try this: print dir(elapsed) The answer should become obvious. --Scott David Daniels Scott.Daniels at Acm.Org From clp2 at rebertia.com Tue Jan 6 16:46:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 13:46:46 -0800 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <50697b2c0901061346q2a6b43d5i246fe2380280c04b@mail.gmail.com> On Tue, Jan 6, 2009 at 1:34 PM, wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. Not all that arcane. >From http://docs.python.org/library/datetime.html : """ timedelta Objects A timedelta object represents a duration, the difference between two dates or times. [...] Attribute Value days Between -999999999 and 999999999 inclusive seconds Between 0 and 86399 inclusive microseconds Between 0 and 999999 inclusive """ The attribute you're looking for is 'microseconds', not 'milliseconds'. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From fredrik.johansson at gmail.com Tue Jan 6 16:48:54 2009 From: fredrik.johansson at gmail.com (Fredrik Johansson) Date: Tue, 6 Jan 2009 13:48:54 -0800 (PST) Subject: math module for Decimals References: <41937dc9-4b67-43b5-9eab-6f8c851474cf@p2g2000prn.googlegroups.com> <40dee7cf-d14f-43dd-a179-fcfd36476b8b@f40g2000pri.googlegroups.com> Message-ID: <88f22492-0d01-48a1-9db7-d2de7cbe450f@k36g2000pri.googlegroups.com> On Jan 6, 8:29 pm, Mark Dickinson wrote: > Note that it's still subject to the same limitations as anything > else for trig_function(really huge argument), of course: > > >>> import mpmath > >>> mpmath.cos(mpmath.mpf('1e999999999')) > > [... still waiting for a result 30 minutes later ...] > > (not a criticism of mpmath: just a demonstration that this > really is pretty much unavoidable). Indeed. That's asking for 1 billion digits of pi. (I feel that I need to point out that mpmath really does go out of its way to make ridiculous things like that work, though. It uses a very fast algorithm to compute pi, faster than MPFR even. Assuming gmpy is installed on the system and enough RAM, cos('1e999999999') should finish in about 10^5 seconds = 1 day (based on extrapolation on my computer). You just weren't patient enough :-) > Out of curiosity, what sort of guarantees does mpmath give on > error bounds? It looks like it aims for 'almost correctly > rounded'; i.e., error < 0.500...001 ulps. Sort of; there are different standards of rigor. The basic arithmetic operations are correctly rounded. The elementary functions are 'almost correctly rounded' in the sense you described (subject to the usual bug disclaimer); they are also correctly rounded around some zeros and poles (e.g. sin(x) for sufficiently small x properly rounds to x or x* (1-eps) if upward/downward rounding is used). Some other functions like erf and gamma are 'almost correctly rounded' for real arguments, but currently no attempt is made to correct for cancellations in real/imaginary parts (this problem is mostly avoided for elementary functions by decomposition into real-valued functions like cos(a+b*i) = cos(a)*cosh(b)-sin(a)*sinh(b)*i). Finally, some "higher" functions are computed more naively and can easily be forced to lose accuracy by finding large arguments that correspond to small function values. It would indeed be nice to support correct rounding for at least the elementary transcendental functions in the future. One advantage of arbitrary precision is that the user can compensate for rounding errors very easily by just increasing the working precision, but ideally that shouldn't be necessary for atomic operations. > Here's one place in mpmath where it looks as though more > internal precision is needed (with default settings: 53-bit > precision, etc.) > > >>> mpmath.log(mpmath.mpc(0.6, 0.8)) > > mpc(real='0.0', imag='0.9272952180016123') > > Shouldn't the real part here be something like: > > 2.2204460492503132e-17 > > instead of 0.0? That's certainly a bug; it should be fixed soon. Fredrik From lists at js3d.co.uk Tue Jan 6 16:48:59 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 21:48:59 -0000 Subject: read pipe information on a running (popen) process Message-ID: <004c01c97048$956ffb30$c04ff190$@co.uk> Hi, I'm really struggling with how to read the stdout on a running process. All the examples I've seen tend to rely on waiting for the process to finish. The process I'm running takes a while and I need to get stdout [and stderr] and be able to pipe them into a string for displaying in a web app. My shoddy code is currently this: p = subprocess.Popen('xsibatch.exe -s', bufsize=200, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while p.returncode==None: p.poll() print p.stdout.readline(), p.stderr.readline(), time.sleep(1) print 'finished' Which results in it printing (i think) the last line written to the pipe file. I'm thinking there must be a simpler way to access this information. Ideally I'd like to dump the whole lot to a string at periodic intervals but am completely stumped as to how to do this as readlines() and many other methods require an EOF. On a side note [and much lesser problem currently], I was under the impression that p.poll() writes the returncode attribute, but from what I can see when the process terminates p.poll() still returns none? Many thanks, Jules From google at mrabarnett.plus.com Tue Jan 6 16:49:58 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jan 2009 21:49:58 +0000 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <4963D206.2040403@mrabarnett.plus.com> David at bag.python.org wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time You've just overwritten the timedelta class in the datetime module! Do something like this instead: elapsed_time = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > print (elapsed_time.microseconds / 1.0E6) > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. > From lists at js3d.co.uk Tue Jan 6 17:00:50 2009 From: lists at js3d.co.uk (Jules Stevenson) Date: Tue, 6 Jan 2009 22:00:50 -0000 Subject: read pipe information on a running (popen) process In-Reply-To: <004c01c97048$956ffb30$c04ff190$@co.uk> References: <004c01c97048$956ffb30$c04ff190$@co.uk> Message-ID: <005401c9704a$3dc85600$b9590200$@co.uk> > Which results in it printing (i think) the last line written to the > pipe > file. I'm thinking there must be a simpler way to access this > information. > Ideally I'd like to dump the whole lot to a string at periodic > intervals but > am completely stumped as to how to do this as readlines() and many > other > methods require an EOF. FWIW google found this, which looks very promising: http://code.activestate.com/recipes/440554/ From thorsten at thorstenkampe.de Tue Jan 6 17:19:51 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 6 Jan 2009 23:19:51 +0100 Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: * Vinay Sajip (Tue, 6 Jan 2009 11:24:54 -0800 (PST)) > On Jan 6, 4:17 pm, Kottiyath wrote: > > I dont want the whole traceback. I just wanted to know where the log > > was generated from i.e. which procedure and which line. I have 3/4 > > points in many procedures where I encounter a small error (not an > > exception) and want to log it. So having individual names for each > > looks to be somewhat verbose - esp since the application is >10K LOC. > > > > Don't the funcName and lineno arguments in the format string work for > you? > > (See http://docs.python.org/library/logging.html#id1) I don't think he's interested in the "line number where the logging call was issued" but where the exception occurred. Thorsten From jgardner at jonathangardner.net Tue Jan 6 17:20:01 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 6 Jan 2009 14:20:01 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> Message-ID: <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> On Jan 6, 12:24?pm, J Kenneth King wrote: > Jonathan Gardner writes: > > On Jan 6, 8:18?am, sturlamolden wrote: > >> On Jan 6, 4:32 pm, mark wrote: > > >> > I want to implement a internal DSL in Python. I would like the syntax > >> > as human readable as possible. > > >> Also beware that Python is not Lisp. You cannot define new syntax (yes > >> I've seen the goto joke). > > > This isn't really true. You can, for instance, write a program (in > > Python) that takes your pseudo-Python and converts it into Python. > > This is what a number of templating libraries such as Mako do. > > Which is not even close to being the same. > > Lisp - the program source is also the data format > > Python - the program source is a string > > I could go on a really long rant about how the two are worlds apart, but > I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. From gagsl-py2 at yahoo.com.ar Tue Jan 6 17:49:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 20:49:19 -0200 Subject: socket send help References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: En Mon, 05 Jan 2009 22:59:46 -0200, James Mills escribi?: > On Tue, Jan 6, 2009 at 10:49 AM, Bryan Olson > wrote: >>> I thought a firewall would block an attempt to bind to any routeable >>> address, but not to localhost. So using INADDR_ANY would be rejected. > > No. > >> My understanding is that firewalls block network traffic, not system >> calls. > > This is correct. Firewalls (real firewalls) can only act on incoming > and outgoing traffic on the IP level. That's true for hardware firewalls (those found in a router, by example). They can at most analyze traffic at the application layer but have no idea of the applications (processes) behind. A "software firewall" may react not just to traffic but to *who* is doing that; it may block *processes* when they try to bind/listen to any port, even before any packet is sent or received. See http://www.securityfocus.com/infocus/1839 (One may argue whether those are *real* firewalls or not, but that's their common name...) (Also note that I'm far for being an expert on these topics) -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:10:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:10:08 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Tue, 06 Jan 2009 12:42:13 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Such assumptions only hold under particular domains though. You can't >> assume equality is an equivalence relation once you start thinking >> about arbitrary domains. > > From a formal mathematical point of view, equality /is/ an equivalence > relation. If you have a relation on some domain, and it's not an > equivalence relation, then it ain't the equality relation, and that's > flat. Okay, fair enough. In the formal mathematical sense, equality is always an equivalence relation. So there are certain domains which don't have equality, e.g. floating point, since nan != nan. Also Python objects, since x.__eq__(y) is not necessarily the same as y.__eq__(x). >> But there cannot be any such function which is a domain-independent >> equivalence relation, not if we're talking about arbitrarily wacky >> domains. > > That looks like a claim which requires a proof to me. But it could also > do with a definition of `domain', so I'll settle for one of those first. I'm talking about domain in the sense of "a particular problem domain". That is, the model, data and operations used to solve a problem. I don't know that I can be more formal than that. To prove my claim, all you need is two domains with a mutually incompatible definition of equality. That's not so difficult, surely? How about equality of integers, versus equality of integers modulo some N? > If we're dealing with sets (i.e., `domain's form a subclass of `sets') > then the claim is clearly false, and equality (determined by comparison > of elements) is indeed a domain-independent equivalence relation. It isn't domain-independent in my sense, because you have specified one specific domain, namely set equality. >> Even something as straight-forward as "is" can't be an equivalence >> relation under a domain where identity isn't well-defined. > > You've completely lost me here. The Python `is' operator is (the > characteristic function of) an equivalence relation on Python values: > that's its definition. Yes, that's because identity is well-defined in Python. I'm saying that if identity isn't well-defined, then neither is the 'is' operator, and therefore it isn't an equivalence relation. That shouldn't be controversial. > All Python objects are instances of `object' or of some more specific > class. The `==' operator on `object' is (the characteristic function > of) an equivalence relation. In, fact, it's the same as `is' -- but > `==' can be overridden by subclasses, and subclasses are permitted -- > according to the interface definition -- to coarsen the relation. In > fact, they're permitted to make it not be an equivalence class at all. > > I claim that this is a problem. It *can* be a problem, if you insist on using == on arbitrary types while still expecting it to be an equivalence relation. If you drop the requirement that it remain an e-r, then you can apply == to arbitrary types. And if you limit yourself to non-arbitrary types, then you can safely use (say) any strings you like, and == will remain an e-r. I /agree/ that domain-specific > predicates are useful, and can be sufficiently useful that they deserve > the `==' name -- as well as floats and numpy, I've provided SAGE and > sympy as examples myself. But I also believe that there are good > reasons to want an `equivalence' operator (I'll write it as `=~', though > I don't propose this as Python syntax -- see below) with the following > properties: > > * `=~' is the characteristic function[1] of an equivalence relation, > i.e., for all values x, y, z: x =~ y in (True, False); (x =~ x) == > True; if x =~ y then y =~ x; and if x =~ y and y =~ z then x =~ z > > * Moreover, `=~' is a coarsening of `is', i.e. for all values x, y: if > x is y then x =~ y. Ah, but you can't have such a generic e-r that applies across all problem domains. Consider: Let's denote regular, case-sensitive strings using "abc", and special, case-insensitive strings using i"abc". So for regular strings, equality is an e-r; for case-insensitive strings, equality is also an e-r (I trust that the truth of this is obvious). But if you try to use equality on *both* regular and case-insensitive strings, it fails to be an e-r: i"abc" =~ "ABC" returns True if you use the case-insensitive definition of equality, but returns False if you use the case-sensitive definition. There is no single definition of equality that is *simultaneously* case- sensitive and case-insensitive. > A valuable property might be that x =~ y if x and y are > indistinguishable without using `is'. That's a little strong, because it implies that equality must look at *everything* about a particular object, not just whatever bits of data are relevant for the problem domain. For example, consider storing data in a dict. >>> D1 = {-1: 0, -2: 0} >>> D2 = {-2: 0} >>> D2[-1] = 0 >>> D1 == D2 True We certainly want D1 and D2 to be equal. But their history is different, and that makes their internal details different, which has detectable consequences: >>> D1 {-2: 0, -1: 0} >>> D2 {-1: 0, -2: 0} The same happens with trees. Given a tree structure defined as: (payload, left-subtree, right-subtree) do you want the following two trees to be equal? ('b', ('a', None, None), ('c', None, None)) ('a', None, ('b', None, ('c', None, None))) Unless I've made a silly mistake, not only are the payloads of the two trees equal, but so are the in-order representation of both. Only the specific order the nodes are stored in differ, and that may not be important for the specific problem you are trying to solve. There may be problem domains where the order of elements in a list (or tree structure) *is* important, and other problem domains where order is irrelevant. One single relation can't cover all such conflicting requirements. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:15:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:15:35 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Tue, 06 Jan 2009 14:03:16 +0000, Mark Wooding wrote: >> You've also missed out on probably twenty years of CS where Java (using >> the same assignment model as Python!) has been *the* language of choice >> for undergrad CS, not to mention those introductory courses which use >> Python. > > There's no way that Java has been taught anywhere for 20 years. It just > isn't old enough. Wikipedia claims that Java appeared in 1995, which > looks right to me. Python, released in 1991, is therefore older. I stand corrected. Can we agree that Java has been the language of choice for most of a decade? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:18:39 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:18:39 GMT Subject: Code Review request for the trash-cli project References: Message-ID: On Tue, 06 Jan 2009 17:30:19 +0200, Dotan Cohen wrote: > I don't know about the code, but would there be a reason _not_ to alias > rm, rmdir to this program? I see that it is GPL, so this would be a > great addition to any Linux distro. I sure as hell don't want rm to move files to the trash. If I rm something, I want it *gone*. I do want a *different* command for moving files to the trash. But absolutely not rm. Of course, if anyone wants to alias rm in their own shell, they're welcome to. That's what the alias command is for. -- Steven From Graham.Dumpleton at gmail.com Tue Jan 6 18:31:29 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 6 Jan 2009 15:31:29 -0800 (PST) Subject: mod_python: delay in files changing after alteration References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> Message-ID: <80e89ae6-af47-420b-8d25-63966f92891a@o40g2000prn.googlegroups.com> On Jan 6, 2:39?am, "psaff... at googlemail.com" wrote: > Maybe this is an apache question, in which case apologies. > > I am runningmod_python3.3.1-3 on apache 2.2.9-7. It works fine, but > I find that when I alter a source file during development, it > sometimes takes 5 seconds or so for the changes to be seen. This might > sound trivial, but when debugging tens of silly errors, it's annoying > that I have to keep hitting refresh on my browser waiting for the > change to "take". I'm guessing this is just a caching issue of some > kind, but can't figure out how to switch it off. Any suggestions? > > The entry in my apache2.conf looks like this: > > > ? ?SetHandlermod_python > ? ?PythonHandlermod_python.publisher > ? ?PythonDebug On > If the change is to a Python module installed on sys.path the change would never be reloaded by a process. If you are seeing a delay, it is probably only because the request is being handled by a different Apache child process that has never loaded the code before. This is all because Apache is a multiprocess web server on UNIX. Thus, any changes to modules/packages installed on sys.path require a full restart of Apache to ensure they are loaded by all Apache child worker processes. So, which code files are you actually modifying, ie., where do they exist and how are they imported? Graham From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 18:35:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 06 Jan 2009 23:35:12 GMT Subject: If your were going to program a game... References: Message-ID: On Tue, 06 Jan 2009 10:44:39 -0700, Joe Strout wrote: > Not that I have anything against Flash; I've started learning it just > last week, and apart from the nasty C-derived syntax, it's quite nice. > It has a good IDE, good performance, great portability, and it's easy to > use. It just surprises me that after all these years, the Python > community hasn't done something similar. It's bad enough that every time I go to a website using Flash, my browser is running untrusted code in my browser, but at least Adobe has spent a bucket-load of time and money making it (almost) secure. I sure as hell don't want arbitrary Python code running in my browser. Oh, and even Adobe hasn't got it completely right: IBM research Mark Dowd has demonstrated an incredible vulnerability that allows a single Trojan to exploit Flash in either IE or Firefox while leaving the Flash runtime operating normally. And it can bypass Vista security. Although Dowd doesn't explicitly mention other OSes, I see no reason to believe the same technique wouldn't work on Linux. http://www.matasano.com/log/1032/this-new-vulnerability-dowds-inhuman- flash-exploit/ This is not your regular buffer overflow vulnerability. Read it and weep. -- Steven From gagsl-py2 at yahoo.com.ar Tue Jan 6 18:41:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 21:41:32 -0200 Subject: Why not Ruby? References: <7xr63m3gy2.fsf@ruckus.brouhaha.com> <016d53c1$0$8693$c3e8da3@news.astraweb.com> <35e7276d-eb2b-4376-9996-2c68356a4d6c@o4g2000pra.googlegroups.com> <016e0360$0$8693$c3e8da3@news.astraweb.com> <18befd32-305a-400f-836b-d6409c3f1508@r36g2000prf.googlegroups.com> Message-ID: En Fri, 02 Jan 2009 15:00:01 -0200, r escribi?: > Steven i got you NOW! > Everybody go and look at this thread, there Mr. Makinzie butts in and > posts an off-topic question, and Steven answers it, contributing to > the off-topicalitly of the thread. And has yet to apologize for it, or Does the word "annoyness" exist? You're getting high scores on my ranking. -- Gabriel Genellina From bowman.joseph at gmail.com Tue Jan 6 19:18:10 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Tue, 6 Jan 2009 16:18:10 -0800 (PST) Subject: having problems with a multi-conditional while statement Message-ID: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Hi, I'm trying to write a multi-conditional while statement, and am having problems. I've broken it down to this simple demo. #!/usr/bin/python2.5 condition1 = False condition2 = False while not condition1 and not condition2: print 'conditions met' if condition1: condition2 = True condition1 = True As I understand it, this should print 'conditions met' twice, however, it only prints it once. It seems that once condition1 is made true, the whole thing evaluates as true and stops the while loop. I've also tried to set the while condition the following ways also, and had the same problem while (not condition1 and not condition2): while (not condition1) and (not condition2): while condition1 != True and condition2 != True: while (condition1 != True and condition2 != True): while (condition1 != True) and (condition2 != True): Can someone lend me a hand in understanding this? From philip at semanchuk.com Tue Jan 6 19:34:32 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 6 Jan 2009 19:34:32 -0500 Subject: having problems with a multi-conditional while statement In-Reply-To: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: <95F236CF-6FAE-4690-AB81-9D2FF54341CD@semanchuk.com> On Jan 6, 2009, at 7:18 PM, bowman.joseph at gmail.com wrote: > Hi, > > I'm trying to write a multi-conditional while statement, and am having > problems. I've broken it down to this simple demo. > > #!/usr/bin/python2.5 > > condition1 = False > condition2 = False > > while not condition1 and not condition2: > print 'conditions met' > if condition1: > condition2 = True > condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > it only prints it once. It seems that once condition1 is made true, > the whole thing evaluates as true and stops the while loop. Think it through. At the outset: while (not condition1) and (not condition2) ==> while (not False) and (not False) ==> while True and True ==> while True After it's been through the loop once: while (not condition1) and (not condition2) ==> while (not True) and (not False) ==> while False and True ==> while False Change the "and" to an "or" and you'll get the result you expected. From nad at acm.org Tue Jan 6 19:42:26 2009 From: nad at acm.org (Ned Deily) Date: Tue, 06 Jan 2009 16:42:26 -0800 Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: In article <40a44d6b-c638-464d-b166-ef66496a0676 at l16g2000yqo.googlegroups.com>, "bowman.joseph at gmail.com" wrote: > Hi, > > I'm trying to write a multi-conditional while statement, and am having > problems. I've broken it down to this simple demo. > > #!/usr/bin/python2.5 > > condition1 = False > condition2 = False > > while not condition1 and not condition2: > print 'conditions met' > if condition1: > condition2 = True > condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > it only prints it once. It seems that once condition1 is made true, > the whole thing evaluates as true and stops the while loop. Are you perhaps expecting that the "while" condition is tested at the end of the loop? It's not; it is tested at the top of the loop, so, once the condition evaluates as false, the loop exits. This can even result in zero trips: >>> while False: ... print "never" ... >>> Unwinding the snippet above: >>> condition1 = False >>> condition2 = False >>> not condition1 and not condition2 True >>> if condition1: ... condition2 = True ... >>> condition1 = True >>> not condition1 and not condition2 False # -> while loop exits after 1 trip -- Ned Deily, nad at acm.org From gagsl-py2 at yahoo.com.ar Tue Jan 6 19:57:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 22:57:43 -0200 Subject: cPickle vs pickle discrepancy References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: En Mon, 05 Jan 2009 23:04:30 -0200, Zac Burns escribi?: > I have a module that attempts to pickle classes defined in that module. > > I get an error of the form: > PicklingError: Can't pickle : import > of module Module.SubModule failed > when using cPickle (protocol -1, python version 2.5.1). > > The module has already been imported and is in sys.modules when the > exception is raised. There is no thing as a "submodule"; very likely you have a package, and a module inside that package. - always import the "submodules" from the package, not directly (relative imports are safer) - in general, don't play with PYTHONPATH, sys.path, and such things. - don't directly execute a module inside a package (it's name is always __main__ and it doesn't even "know" it's part of a package). > Using pickle instead of cPickle works, but the section of the code is > performance critical. Could you provide a short example? I'd say that if you stick to the above rules you won't have the issue again, but anyway I'd like to know in which cases Pickle and cPickle differ. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 20:02:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 01:02:54 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Tue, 06 Jan 2009 14:32:04 +0000, Mark Wooding wrote: > Derek Martin wrote: > >> I think I have though, not that it matters, since that was never really >> my point. Python's assignment model requires more explanation than the >> traditional one, simply to state what it does. That alone is evidence >> (but not proof). > > Hmm. Actually, it's not the assignment model which is strange at all. > It's the data model. What does an expression like > > [1, 2, 3] > > denote? Is it the list itself, Yes. > or a /reference/ to the list? No. > If you answer the first, you'll want Tcl/C/Fortran semantics. Absolutely not! I want *Python* semantics, and amazingly enough, that's *just what Python gives*. > If you answer the second, you'll want Lisp/Python/Javascript > semantics. If I wanted a reference to a list, I'd expect to *dereference* the reference to get to the list. That's not what Python forces you do to: you just use the list as the list object itself. This isn't hard people. Stop confusing the implementation details of how CPython works under the hood with Python level code. In Python, [1, 2, 3] is a list, not a reference to a list. When you pass [1, 2, 3] to a function, the function sees the list you passed it. The function doesn't see "a reference to a list", it sees a list: >>> def func(x): ... print type(x) ... >>> func([1, 2, 3]) It's so easy, some people refuse to believe it could be that easy, and insist on complicating matters by bring the implementation details into the discussion. Just stop, please. References belong in the *implementation*, nothing to do with Python level code. In Python code, there are no references and no dereferencing. > Python decided that all values are passed around as and manipulated > through references. Oh really? Then why can't I write a Python function that does this? x = 1 y = 2 swap(x, y) assert x == 2 assert y == 1 You can't, because Python doesn't have references. In a language with references, that's easy. Here's an untested Pascal version for swap: procedure swap(var x: integer, var y: integer); var tmp: integer; begin tmp := x; x := y; y := x; end; It's harder (impossible?) to write a version that will operate on arbitrary types, but that's statically typed languages for you. > (There are no locatives: references are not values, But references *are* locatives. > and you can't have a reference to a reference.) Lists store references; > tuples store references; and so on. No no no, lists and tuples store *objects*. Such storage happens to be implemented as pointers in CPython, but that's an irrelevant detail at the level of Python. -- Steven From bowman.joseph at gmail.com Tue Jan 6 20:17:36 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Tue, 6 Jan 2009 17:17:36 -0800 (PST) Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> Message-ID: <509aed9c-a761-4d05-bda0-02971fc2e495@r37g2000prr.googlegroups.com> Thanks for the assistance. I actually realized I was making things more complicated than they needed to be and I really only needed one condition to be met. On Jan 6, 7:42?pm, Ned Deily wrote: > In article > <40a44d6b-c638-464d-b166-ef66496a0... at l16g2000yqo.googlegroups.com>, > > > > ?"bowman.jos... at gmail.com" wrote: > > Hi, > > > I'm trying to write a multi-conditional while statement, and am having > > problems. I've broken it down to this simple demo. > > > #!/usr/bin/python2.5 > > > condition1 = False > > condition2 = False > > > while not condition1 and not condition2: > > ? ? print 'conditions met' > > ? ? if condition1: > > ? ? ? ? condition2 = True > > ? ? condition1 = True > > > As I understand it, this should print 'conditions met' twice, however, > > it only prints it once. It seems that once condition1 is made true, > > the whole thing evaluates as true and stops the while loop. > > Are you perhaps expecting that the "while" condition is tested at the > end of the loop? ? It's not; it is tested at the top of the loop, so, > once the condition evaluates as false, the loop exits. ?This can even > result in zero trips: > > >>> while False: > > ... ? ? print "never" > ... > > > > Unwinding the snippet above: > > >>> condition1 = False > >>> condition2 = False > >>> not condition1 and not condition2 > True > >>> if condition1: > > ... ? ? condition2 = True > ...>>> condition1 = True > >>> not condition1 and not condition2 > > False > > # -> while loop exits after 1 trip > > -- > ?Ned Deily, > ?n... at acm.org From mdw at distorted.org.uk Tue Jan 6 20:23:19 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 01:23:19 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > To prove my claim, all you need is two domains with a mutually > incompatible definition of equality. That's not so difficult, surely? How > about equality of integers, versus equality of integers modulo some N? No, that's not an example. The integers modulo N form a ring Z/NZ of residue classes. Such residue classes are distinct from the integers -- e.g., an integer 3 (say) is not the same as the set 3 + NZ { ..., 3 - 2N, 3 - N, 3, 3 + N, 3 + 2N, ... } -- but there is a homomorphism from Z to Z/NZ under which 3 + NZ is the image of 3. If we decide to define the == operator such that 3 == 3 + NZ and 3 + N == 3 + NZ then == is not an equivalence relation (in particular, transitivity fails). But that's just an artifact of the definition. If we distinguish 3 from 3 + NZ then everything is fine. 3 + NZ == (3 + N) + NZ correctly, but 3 != 3 + N, and all is well. Here, at least, the problem is not that == as an equivalence relation fails in some particular domain -- because in both Z and Z/NZ it can be a perfectly fine equivalence relation -- but that it can potentially fail on the boundaries between domains. Easy answer: don't mess it up at the boundaries. Proposition. Let U, U' be disjoint sets, and let E, E' be equivalence relations on U, U' respectively. Define E^ on U union U' as E^ = E union E', i.e., E^(x, y) iff x in U and y in U and E(x, y) or x in U' and y in U' and E'(x, y) Then E^ is an equivalence relation. Proof. Reflexivity and symmetry are trivial; transitivity follows from disjointness of U and U'. > It *can* be a problem, if you insist on using == on arbitrary types > while still expecting it to be an equivalence relation. Unfortunately, from the surrounding discussion, it seems that container types particularly want to be able to contain arbitrary objects, and the failure of == to be a equivalence relation makes this fail. The problem is that objects with wacky == operators are still more or less quacking like the more usual kinds of ducks; but they turn out to taste very different. > Let's denote regular, case-sensitive strings using "abc", and special, > case-insensitive strings using i"abc". So for regular strings, equality > is an e-r; for case-insensitive strings, equality is also an e-r (I > trust that the truth of this is obvious). But if you try to use equality > on *both* regular and case-insensitive strings, it fails to be an e-r: > > i"abc" =~ "ABC" returns True if you use the case-insensitive definition > of equality, but returns False if you use the case-sensitive definition. > There is no single definition of equality that is *simultaneously* case- > sensitive and case-insensitive. A case-sensitive string is /not the same/ as a case-insensitive string. One's a duck, the other's a goose. I'd claim here that i"abc" =~ "ABC" must be False, because i"abc" =~ "abc" must be false also! To define it otherwise leads to the incoherence you describe. But the above proposition provides an easy answer. > > A valuable property might be that x =~ y if x and y are > > indistinguishable without using `is'. > > That's a little strong, because it implies that equality must look at > *everything* about a particular object, not just whatever bits of data > are relevant for the problem domain. Yes. That's one of the reasons that =~ isn't the same as ==. I've been thinking on my feet in this thread, so I haven't thought everything through. And as I mention below, there are /many/ useful equality predicates on values. As I didn't mention (but hope is obvious) having a massively-parametrized equality predicate is daft, and providing enough to suit every possible application equally so. But we might be able to do well enough with just one or two -- or maybe by just leaving things as they are. > For example, consider storing data in a dict. > > >>> D1 = {-1: 0, -2: 0} > >>> D2 = {-2: 0} > >>> D2[-1] = 0 > >>> D1 == D2 > True > > > We certainly want D1 and D2 to be equal. Do we? If we're using my `indistinguishable without using ``is''' criterion from above, then D1 and D2 are certainly different! To detect the difference, mutate one and see if the other changes: def distinct_dictionaries_p(D1, D2): """ Decide whether D1 and D2 are the same dictionary or not. Not threadsafe. """ magic = [] more_magic = [magic] old = D1.get('mumble', more_magic) D1['mumble'] = magic result = D2.get('mumble', more_magic) is magic if old is more_magic: del D1['mumble'] else: D1['mumble'] = old return result But that criterion was a suggestion -- a way of defining a coherent equivalence relation on the whole of the Python value space which is coarser than `is' and maybe more useful. My primary purpose in proposing it was to stimulate discussion: what /do/ we want from equality predicates? We already have `is', which is too fine-grained to be widely useful: it distinguishes between different instances of the number 500000, for example, and I can't for the life of me see why that's a useful behaviour. (The `is' operator is a fine thing, and I wouldn't want it any other way: it trades away some useful semantics for the sake of speed, and that was the /right/ decision.) My criterion succeeds in distinguishing 1 from 1.0 (they have different types), which may be considered good. It doesn't distinguish a quiet NaN from another quiet NaN: that's definitely good. (It'd be bogus for a numeric equality operator, but we've already got one of those, so we don't need to define another.) But you're probably right: it's still too fine-grained for some purposes. > But their history is different, and that makes their internal details > different, which has detectable consequences: > > >>> D1 > {-2: 0, -1: 0} > >>> D2 > {-1: 0, -2: 0} So in this case, `str' also works as a distinguisher. Fine. > There may be problem domains where the order of elements in a list (or > tree structure) *is* important, and other problem domains where order is > irrelevant. One single relation can't cover all such conflicting > requirements. Absolutely. This is why Common Lisp provides four(!) out of the box and it still isn't enough. Python provides one (`is') and a half (`==' when it's behaving) is actually coping remarkably well considering. But this /is/ causing problems, and so thinking about solutions seems reasonable. I'm not trying to change the language. I don't have a pet feature I want added. I do think the discussion is interesting and worthwhile, though. -- [mdw] From gdamjan at gmail.com Tue Jan 6 20:24:31 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 07 Jan 2009 02:24:31 +0100 Subject: python is great References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <8a6b8e350901060445i3a722bf5r197030a03a71ea56@mail.gmail.com> <496396AF.5020809@strout.net> Message-ID: >> And there are >> some things (such as Flash-style web applets) that you still can't do >> at all in Python, even after all these years. > > You're looking for Silverlight: > > http://www.voidspace.org.uk/ironpython/silverlight/index.shtml or clutter which has Python bindings http://www.clutter-project.org/ -- ?????? ( http://softver.org.mk/damjan/ ) Hi! I'm a .signature virus! copy me into your .signature file to help me spread! From gagsl-py2 at yahoo.com.ar Tue Jan 6 20:24:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 06 Jan 2009 23:24:32 -0200 Subject: __builtin__ quote References: <81F8l.4494$jZ1.3657@flpi144.ffdc.sbc.com> Message-ID: En Tue, 06 Jan 2009 06:56:36 -0200, James Stroud escribi?: > Steven Woody wrote: >> On Tue, Jan 6, 2009 at 4:42 PM, James Stroud >> wrote: >>> py> import __builtin__ >>> py> __builtin__.abs is abs >>> True >> Does that mean someone did 'import * from __builtin__' when python >> startup? > > In terms of the exact implementation of the cPython interpreter, I don't > know. But the interpreter behaves as if someone did just that. So there > is nothing wrong with thinking of it this way if it helps you understand > the interpreter. Not exactly. Built-in names are "one step further" global names; it's not that builtin names populate by default the global namespace. As local names "hide" (or "shadow") global names, those global names "hide" builtin names. Those three namespaces are distinct, like onion layers (global and local namespaces are the same at the module level). If the interpreter did the equivalent of "from __builtin__ import *", redefining builtin names would destroy them, but that's not the case: # the builtin "abs" function >>> abs(-3) 3 >>> abs # this one "hides" the builtin abs >>> def abs(x): ... return "Hi, I'm the abs() global function!" ... >>> abs(-3) "Hi, I'm the abs() global function!" >>> abs # remove the global "abs" >>> del abs # we can access again the builtin "abs" >>> abs(-3) 3 >>> abs -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Jan 6 21:25:21 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 02:25:21 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Tue, 06 Jan 2009 13:43:01 -0800, Aaron Brady wrote: > I think one of the ideas we have trouble communicating is that [1, 2, 3] > and [4, 5, 6] can be the same object Not at the same time they can't. > (using '[:]='), but [1, 2, 3] and [1, 2, 3] don't have to be. I don't think this is hard to get across, if you think about objects. You have a list. It's like a box. That box can hold items 1, 2 and 3. You can replace those items with 4, 5 and 6, and it's still the same box. Likewise, you can have a box with items 1, 2 and 3 inside it, and a different box also with items 1, 2 and 3, and they're still different boxes. The only tricky thing is that items 1, 2 and 3 can be inside two different boxes at the same time. There's no obvious real world analogy to that without the boxes being nested. This ability for objects to be in two places at once (or even to be inside themselves!) is one of the few reasons why Python's use of references in the implementation needs to be mentioned. -- Steven From narkewoody at gmail.com Tue Jan 6 21:56:26 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 10:56:26 +0800 Subject: message of Exception Message-ID: Hi, I am trying define an Exception as below: class MyError(Exception): def __init__(self, message): self.message = message And, I expect that when I raise a MyError as raise MyError, "my message" the python should print a line such as MyError: my message But I did not get that, I just got: ... MyError I guess I had made something wrong with the __init__() definition, but I can not find an answer in doc. Please help, thanks! - narke From gnewsg at gmail.com Tue Jan 6 22:01:48 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Tue, 6 Jan 2009 19:01:48 -0800 (PST) Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? Message-ID: <76277bc4-2810-48f4-8953-4393eb97c810@t26g2000prh.googlegroups.com> Hi, I'm trying to add TLS/SSL support to pyftpdlib. Since various defects have been found in the SSLv2 protocol many FTPS servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 only and sistematically reject any client attempting to use SSLv2. Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 connections only? If that's not possible can I determine the encryption protocol being used *after* that the SSL/TLS handshake took place? I tried to use wrap_socket as follows: self.socket = ssl.wrap_socket(self.socket, , certfile=CERTFILE, server_side=True, ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) ...it works if on the client side I use TLSv1 but not if I use SSLv3 ("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is raised) Thanks in advance for any help. --- Giampaolo http://code.google.com/p/pyftpdlib/ From clp2 at rebertia.com Tue Jan 6 22:09:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 19:09:17 -0800 Subject: message of Exception In-Reply-To: References: Message-ID: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> On Tue, Jan 6, 2009 at 6:56 PM, Steven Woody wrote: > Hi, > > I am trying define an Exception as below: > > class MyError(Exception): > def __init__(self, message): > self.message = message > > And, I expect that when I raise a MyError as > raise MyError, "my message" > the python should print a line such as > MyError: my message > > But I did not get that, I just got: > ... > MyError > > I guess I had made something wrong with the __init__() definition, but > I can not find an answer in doc. Please help, thanks! You need to call the superclass constructor: #note: this code will be different in Py 3.0 class MyError(Exception): def __init__(self, message): super(MyError, self).__init__(message) Or if you're not going to add anything else to MyError, you might as well just leave the class body empty and it'll use Exception's __init__, which takes care of the message. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rurpy at yahoo.com Tue Jan 6 22:21:13 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 6 Jan 2009 19:21:13 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> Message-ID: <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> On Jan 6, 7:03?am, Mark Wooding wrote: ... > > It seems that you don't include in the Python community all those who > > use the term "name binding" instead of variable assignment > > specifically because it gives new users a clue that Python is not the > > same as C. > > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. Is not the proper term "aliasing"? Perhaps Python "variables" should be called "alises". >From http://en.wikipedia.org/wiki/Aliasing_(computing) "aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program." From mdw at distorted.org.uk Tue Jan 6 22:36:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 03:36:50 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: Steven D'Aprano wrote: > If I wanted a reference to a list, I'd expect to *dereference* the > reference to get to the list. That's not what Python forces you do to: > you just use the list as the list object itself. That's odd. No, you give a reference to the list to a function, and the function messes with the list for you. > This isn't hard people. Stop confusing the implementation details of > how CPython works under the hood with Python level code. I'm not confusing anything. This is conceptual-model stuff, not implementation details. (Further discussion below.) > In Python, [1, 2, 3] is a list, not a reference to a list. In [1]: l = [1, 2, 3] In [2]: l[1] = l In [3]: l Out[3]: [1, , 3] Now, if you're right, then l directly contains itself and some other stuff, which is obviously absurd: it's a list, not a Tardis. If I'm right, then l is bound to a reference to a list which contains three references, two of them to integers and a third to the list itself. This doesn't seem absurd at all any more. Variables are not the only places where sharing can occur! Explaining this is much harder if you don't start from the idea that all you're doing is carting uniformly shaped references about. Another example: In [1]: a = [1, 2, 3] In [2]: b = (a, a) In [3]: b Out[3]: ([1, 2, 3], [1, 2, 3]) In [4]: a[1] = 0 In [5]: b Out[5]: ([1, 0, 3], [1, 0, 3]) If b is a tuple containing two copies of a, then this shouldn't have happened. The only satisfactory explanation is that the tuple that b refers to actually contains two references to the same list, so when I mutate that list, the change shows up twice. > When you pass [1, 2, 3] to a function, the function sees the list you > passed it. The function doesn't see "a reference to a list", it sees a > list: > > >>> def func(x): > ... print type(x) > ... > >>> func([1, 2, 3]) > It sees the reference. `type' sees the reference. `type' digs the type of the object out of the reference, and returns you a reference to the type. > It's so easy, some people refuse to believe it could be that easy, and > insist on complicating matters by bring the implementation details into > the discussion. Just stop, please. References belong in the > *implementation*, nothing to do with Python level code. I'm not getting into implementation details. I'm presenting a mental model. The `they're objects: they contain other objects' model is invalidated when you create circular or shared structures, as I've shown above. There are other epicyclic explanations you could invent to explain sharing, maybe -- like keeping lists of clones, and magically updating all the clones whenever one us mutated. That may even be a valid implementation for a distributed Python (with cached copies of objects and a cache-coherency protocol and all that), but it makes a rotten mental model. And it still doesn't explain circularity. Internally, Tcl uses pointers to values in its implementation. The common currency inside the Tcl interpreter is a Tcl_Obj *. (It used to be a char *, before Tcl 8.) So Tcl could easily offer the same semantics as Python and friends. But there's a twist. Tcl does copy-on-write. It's just impossible to make a circular value in Tcl, and sharing doesn't happen. For example, here's a snippet of a tclsh session. % set l {a b c} a b c % lreplace $l 1 1 $l a {a b c} c Tcl really /can/ be explained without talking about references. The existence of Tcl_Obj, and its strange dual-ported nature (it contains a string and an internal representation, and lazily updates one from the other, and uses the string in order to allow changes of internal representation as necessary) really is an implementation detail, and it's possible to have a full understanding of the behaviour of Tcl programs without knowing about it. This is just impossible with Python. Reference semantics pervade the language. > In Python code, there are no references and no dereferencing. You're right! But the concept is essential in understanding the semantics of the language. Even though no references are explicitly made, and no dereferencing explicitly performed, these things are done repeatedly under the covers -- and failure to understand that will lead to confusion. > > Python decided that all values are passed around as and manipulated > > through references. > > Oh really? Then why can't I write a Python function that does this? > > x = 1 > y = 2 > swap(x, y) > assert x == 2 > assert y == 1 Because the function is given references to the objects. It's not given references to /your/ references to those objects. Therefore it can't modify /your/ references, only its ones. Pedantic answer: def swap(hunoz, hukairz): global x, y x, y = y, x (Maybe nonlocal for Python 3.) > You can't, because Python doesn't have references. In a language with > references, that's easy. Here's an untested Pascal version for swap: [snip] That's call-by-reference, which is a different thing. Python, like Lisp, Scheme, Javascript, ML, Haskell, Lua, Smalltalk, Erlang, Prolog, Java, and indeed C, does call-by-value exclusively. This deserves to be called out as a display: Python passes references by value. By contrast, Pascal (sometimes) passes values by reference! The terminology is admittedly confusing, because it comes from different places. If you don't like me talking about Python having references, then pretend I've been saying `pointer' instead, all the way through. I think `pointer' and `reference' are synonymous in this context, attempts by Stroustrup to confuse everybody notwithstanding. But `pointer' has unhelpful connotations: * pointers are more usually values rather than strange behind-the- scenes things, e.g., in C; * pointers, probably because of C, are associated with scariness and non-safe-ness; and * talking of pointers does seem like it's getting towards implementation details, and I wanted to avoid that. Anyway, call-by-value means that the function gets given copies of the caller's arguments; call-by-reference means that the function gets told where the caller's arguments are. In other words call-by-reference introduces /another/ level of indirection between variables and values. > > (There are no locatives: references are not values, > > But references *are* locatives. No! A locative is a /reified/ reference -- a /value/ that /is/ a reference. That is a locative is a reference, but a reference need not be a locative. (A sheep is a mammal, but not all mammals are sheep.) The Lisp Machine had real locatives. You dereferenced them using CAR and RPLACA -- most unpleasant. In modern Lisp systems they seem to have died a death, probably because making them work with fancy things like resizing arrays when you don't have invisible pointers is too painful. > No no no, lists and tuples store *objects*. Such storage happens to be > implemented as pointers in CPython, but that's an irrelevant detail at > the level of Python. Uh-uh. There's no way that an object can store itself and still have room left over. The idea is just crazy. It can't possibly fit. (Axiom of foundation, if you're into that funky stuff.) If you say `no, but it can store a reference to itself', then everything makes sense. It's completely uniform, and not very scary. Lisp people draw these box-and-pointer diagrams all over the place +-----+-----+ | * | *------> NIL +--|--+-----+ | v 3 to show how the data model works. Of course, the Lisp data model is /exactly the same as Python's/. After a while, the diagrams get less pedantic, and tend to show values stashed /in/ the cons cells. In fact, this is actually closer to most implementations for small things like fixnums, characters and flonums, because they're represented by stashing the actual value with some special not-really-a-pointer tag bits -- but the program can't tell, so this doesn't need to be part of your mental model until you start worrying about performance hacking and why your program is consing so much. -- [mdw] From mdw at distorted.org.uk Tue Jan 6 22:49:02 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 03:49:02 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: Steven D'Aprano wrote: > The only tricky thing is that items 1, 2 and 3 can be inside two > different boxes at the same time. There's no obvious real world analogy > to that without the boxes being nested. This ability for objects to be in > two places at once (or even to be inside themselves!) is one of the few > reasons why Python's use of references in the implementation needs to be > mentioned. Ahh. So it /does/ need to be mentioned after all. But you're wrong: it's not an implementation detail: it's an essential part of the language semantics. A better analogy. The objects are scattered across the floor. No object is contained in another. However, we have a plentiful supply of bits of string, each of which is tied to a Teflon-covered paperweight at one end and has a blob of Blu-Tack on the other. Instead of putting something in a box directly, what we do is grab a piece of string, stick the Blu-Tack to the thing, and put the paperweight in the box. This way, we can stick several bits of string to the same object and put the paperweights in different boxes. Indeed, nothing stops us sticking two bits of string to a box, and putting both paperweights inside that same box. But fitting a box into itself twice requires origami skills that frighten me. The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos you're not allowed to do that. There's a daemon who comes around periodically and cleans up the mess of paperweights which aren't in boxes, and tidies away things which don't have any string stuck to them any more, but really he's just an implementation detail and you wouldn't need him if your floor was big enough and you had enough bits of sufficiently long string. -- [mdw] From narkewoody at gmail.com Tue Jan 6 22:55:56 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 11:55:56 +0800 Subject: message of Exception In-Reply-To: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> References: <50697b2c0901061909h4a3bac35w99977e84544a997d@mail.gmail.com> Message-ID: On Wed, Jan 7, 2009 at 11:09 AM, Chris Rebert wrote: > On Tue, Jan 6, 2009 at 6:56 PM, Steven Woody wrote: >> Hi, >> >> I am trying define an Exception as below: >> >> class MyError(Exception): >> def __init__(self, message): >> self.message = message >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" >> the python should print a line such as >> MyError: my message >> >> But I did not get that, I just got: >> ... >> MyError >> >> I guess I had made something wrong with the __init__() definition, but >> I can not find an answer in doc. Please help, thanks! > > You need to call the superclass constructor: > > #note: this code will be different in Py 3.0 > class MyError(Exception): > def __init__(self, message): > super(MyError, self).__init__(message) Thank you, I forgot to call base class's __init__() > > Or if you're not going to add anything else to MyError, you might as > well just leave the class body empty and it'll use Exception's > __init__, which takes care of the message. Yes, I know that, I just want to try and learn something. From tjreedy at udel.edu Tue Jan 6 23:02:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jan 2009 23:02:20 -0500 Subject: message of Exception In-Reply-To: References: Message-ID: Steven Woody wrote: > Hi, > > I am trying define an Exception as below: > > class MyError(Exception): > def __init__(self, message): > self.message = message > > And, I expect that when I raise a MyError as > raise MyError, "my message" In 2.x you may and in 3.0 you must write that as raise MyError("my message") Best to start looking forward ;-). From mdw at distorted.org.uk Tue Jan 6 23:20:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 04:20:26 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Is not the proper term "aliasing"? Perhaps Python "variables" should > be called "alises". No. The proper term is most definitely `binding': see SICP, for example. (Wikipedia has a link to the full text.) The topic of `aliasing' deals with a problem in compiler implementation, where certain optimizations are valid only if two objects are known not to share storage, so that mutating one won't alter the other. This is a particular problem for C, since C programs makes heavy use of pointers; also, Fortran semantics allow the compiler to assume that aliasing does not occur in a number of places, and C compiler writers are keen to keep up with Fortran performance levels. In a wider context, `aliases' tend to be /additional/ names for things, with the connotation of being secondary to some primary or canonical name. For example, Linux 2.2 network interfaces had `aliases', which were additional logical interfaces associated with the physical interface, but with different (but related) names and distinct addresses. Nowadays, Linux network interfaces can have multiple addresses anyway, and the idea of aliases is left as a compatibility hack. -- [mdw] From narkewoody at gmail.com Wed Jan 7 00:03:51 2009 From: narkewoody at gmail.com (Steven Woody) Date: Wed, 7 Jan 2009 13:03:51 +0800 Subject: message of Exception In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 12:02 PM, Terry Reedy wrote: > Steven Woody wrote: >> >> Hi, >> >> I am trying define an Exception as below: >> >> class MyError(Exception): >> def __init__(self, message): >> self.message = message >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" > > In 2.x you may and in 3.0 you must write that as > raise MyError("my message") > Best to start looking forward ;-). Ok, I will adapt the advice. From wuwei23 at gmail.com Wed Jan 7 00:04:45 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 6 Jan 2009 21:04:45 -0800 (PST) Subject: If your were going to program a game... References: Message-ID: <795ea4a1-ed8e-44e8-9a06-9199318b9e01@f40g2000pri.googlegroups.com> On Jan 1, 9:37?pm, Tokyo Dan wrote: > If your were going to program a game in python what technologies would > you use? pyglet[1], pygame[2], or pycap[3]. > The game is a board game with some piece animations, but no movement > animation...think of a chess king exploding. The game runs in a > browser in a window of a social site built around the game. The social > site has login, chat, player stats, list of active games, etc. AND > there is also be a desktop client that accesses the game server via > the same communication mechanism (like an AIR-based desktop client/ > app) as the browser-based version - I guess using JSON/RPC. You could always make Firefox + the PyXPCOM[4] extensions a requirement for use, then just code up the UI in Python where you'd usually use JavaScript. The desktop client could be based on XULRunner [5], then both the web & desktop versions should be pretty much identical. 1: http://www.pyglet.org/ 2: http://www.pygame.org/ 3: http://www.farbs.org/pycap.html 4: http://pyxpcomext.mozdev.org/ 5: https://developer.mozilla.org/en/XULRunner From steve at holdenweb.com Wed Jan 7 00:19:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 00:19:11 -0500 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <49643B4F.7020709@holdenweb.com> Mark Wooding wrote: > Steven D'Aprano wrote: > >> The only tricky thing is that items 1, 2 and 3 can be inside two >> different boxes at the same time. There's no obvious real world analogy >> to that without the boxes being nested. This ability for objects to be in >> two places at once (or even to be inside themselves!) is one of the few >> reasons why Python's use of references in the implementation needs to be >> mentioned. > > Ahh. So it /does/ need to be mentioned after all. But you're wrong: > it's not an implementation detail: it's an essential part of the > language semantics. > > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. > > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, but really he's just an > implementation detail and you wouldn't need him if your floor was big > enough and you had enough bits of sufficiently long string. > Thanks for nailing that one. I have long felt the semantics of Python could be but poorly served without the use of the term "reference" (and indeed I have pointed out int he past that the language reference manual feels free to use the term liberally), but I wasn't able to persist long enough to bring the conversation to this conclusion (except that I am pretty sure this *won't* be a conclusion ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mensanator at aol.com Wed Jan 7 01:25:07 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 6 Jan 2009 22:25:07 -0800 (PST) Subject: Oh! The people of all over the world! References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> Message-ID: <6f17738f-3355-4b3c-b137-6c32b8e5a0ed@r41g2000prr.googlegroups.com> On Jan 6, 7:51?pm, "Obaid R." wrote: > On Jan 7, 2:53?am, Mensanator wrote: > > > But the OP isn't trying to get sympathy for the Isrealis, he's > > trying to get sympathy for his own cause. > > > Which is hard to do given the provocation that's resulting > > in Isreal's retalliation. > > > If the civilians are suffering, why isn't this appeal being > > made to the Hamas leadership? > > > > -- > > > Steven > > So an illegal occupation is NOT a provocation Jesus taught that you don't react to provocation, so you won't make any headway with that argument. > but fighting the > occupation IS? By which scales do you judge? I don't judge, I ignore. Your real task is to break the apathy. > > I would argue that a person following such backwards logic and who > sees these pictures[1] The problem is that no one sees the pictures. Which came first, the rockets or the cluster bombs? Because the rockets were first, no one cares to peruse the pictures because they have already decided that the victims are just getting what they deserve. You may have a keen sense of logic but obviously are clueless about human nature. > and STILL claims that showing sympathy is Doesn't this campaign of yours make you a heretic to the true believers who advocate martyrdom? > difficult has a serious problem. After all the logic is simple: for > every action (read occupation) there is a reaction (read resistance) > equal to it in force and opposite to it in direction. > > You can of course argue that the reaction is the cause of the action, > but that is clearly illogical and proves your iniquity in this matter > and your bias against the victim. It might take a humanitarian > catastrophe of sizable proportions and a biased person would still not > feel any sympathy. Not that there is no catastrophe, but rather > because bias is by nature practiced in spite of good reason and > available evidence, not because of it. > > [1] Pictures > -------------http://www.aljazeera.net/mritems/images/2009/1/6/1_883542_1_34.jpghttp://www.aljazeera.net/mritems/images/2009/1/5/1_883331_1_34.jpghttp://www.aljazeera.net/mritems/images/2009/1/2/1_882580_1_23.jpghttp://newsimg.bbc.co.uk/media/images/45348000/jpg/_45348570_2.jpghttp://newsimg.bbc.co.uk/media/images/45348000/jpg/_45348571_3.jpghttp://newsimg.bbc.co.uk/media/images/45350000/jpg/_45350743_boygrab2...http://newsimg.bbc.co.uk/media/images/45346000/jpg/_45346309_ambulanc...http://www.alquds.co.uk/latest/data/2009-01-06-14-21-12.jpghttp://www.alquds.co.uk/today/06z49.jpghttp://www.alrai.com/img/208500/208725.jpg From harish.shastry at gmail.com Wed Jan 7 01:28:09 2009 From: harish.shastry at gmail.com (Harish Vishwanath) Date: Wed, 7 Jan 2009 11:58:09 +0530 Subject: What is ''r'' in python? Message-ID: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Hello, I accidentally did this in the shell. >>> ''r'' '' >>> ''r'' == '' True >>> ''r'' == "" True That is . However if I try -> >>> ''c'' File "", line 1 ''c'' ^ SyntaxError: invalid syntax >>> ''z'' File "", line 1 ''z'' ^ SyntaxError: invalid syntax Any other character that way is Invalid Syntax. What is so special about character r enclose within a pair of single quotes? Regards, Harish -------------- next part -------------- An HTML attachment was scrubbed... URL: From c2thunes at brewtab.com Wed Jan 7 01:38:33 2009 From: c2thunes at brewtab.com (Christopher Thunes) Date: Wed, 07 Jan 2009 01:38:33 -0500 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <49644DE9.4070002@brewtab.com> Hey Harish, Python automatically concatenates strings constants so this is actually '' then r'' which is the empty string followed by a 'raw' empty string. See here, http://docs.python.org/tutorial/introduction.html#strings. ''u'' and ''b'' will work for the same reason. - Chris Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > >> >> ''r'' > '' >> >> ''r'' == '' > True >> >> ''r'' == "" > True > > That is . However if > I try -> > >> >> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax >> >> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special about > character r enclose within a pair of single quotes? > > Regards, > Harish > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Wed Jan 7 01:45:51 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jan 2009 22:45:51 -0800 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <50697b2c0901062245t53c75ea0w72d8c865b15545ab@mail.gmail.com> On Tue, Jan 6, 2009 at 10:28 PM, Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > >>>> ''r'' > '' >>>> ''r'' == '' > True >>>> ''r'' == "" > True > > That is . However if I > try -> > >>>> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax >>>> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special about > character r enclose within a pair of single quotes? That's probably an artifact of r being used as the prefix in the syntax for raw strings. See http://docs.python.org/reference/lexical_analysis.html#string-literals for more on raw strings. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gherron at islandtraining.com Wed Jan 7 01:47:44 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 06 Jan 2009 22:47:44 -0800 Subject: What is ''r'' in python? In-Reply-To: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> References: <78f8019c0901062228k18102256v1ce658151feaf694@mail.gmail.com> Message-ID: <49645010.1020703@islandtraining.com> Harish Vishwanath wrote: > Hello, > > I accidentally did this in the shell. > > >>> ''r'' > '' > >>> ''r'' == '' > True > >>> ''r'' == "" > True > > That is . However > if I try -> > > >>> ''c'' > File "", line 1 > ''c'' > ^ > SyntaxError: invalid syntax > >>> ''z'' > File "", line 1 > ''z'' > ^ > SyntaxError: invalid syntax > > Any other character that way is Invalid Syntax. What is so special > about character r enclose within a pair of single quotes? Well... For starters, that's not what you have. Python does not have "pairs of single quotes", so you'll have to look elsewhere for an answer. Here it is, but bear with me for a minute: Strings can be created in many different ways: 'a' # single quotes "b" # double quotes '''c''' # Triple single quotes """c""" # Triple double quotes Then there are the so-called raw strings which interpret backslashes differently r'a' r"b" ... Then there are also Unicode strings -- but we don't need those here. So what you have when you type ''r'' # (That's four single quotes although your font may make it look like two double quotes.) is an empty string '' followed by another empty string (using raw syntax) r'' The last piece of the puzzle is a (seemingly) little know feature of Python's syntax: If you specify two strings (in any syntax) without an operator between them, they are automatically concatenated. Like this: >>> 'a' 'b' 'ab' >>> "a" 'b' 'ab' >>> 'a' r'b' 'ab' >>> 'a' u'b' u'ab' So there you have it. Your mystery is the (automatic) concatenation of two empty strings. Gary Herron > > Regards, > Harish > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From quian.xu at stud.tu-ilmenau.de Wed Jan 7 02:16:23 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 08:16:23 +0100 Subject: pg_result_status() alternative? Message-ID: Hi All, I am using the pg module (http://www.pygresql.org/pg.html) for database testing. I have got a problem now: I want to check the result status of postgresql database, which can be done in php by using pg_result_status() (http://www.phpbuilder.com/manual/en/function.pg-result-status.php) How can I do the same thing in python (2.5)? Thanks in advance -- Qian Xu From apardon at forel.vub.ac.be Wed Jan 7 02:31:06 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 7 Jan 2009 07:31:06 GMT Subject: ftp seems to get a delayed reaction. References: <125c8dc6-d467-443f-8755-4ab725266b22@z28g2000prd.googlegroups.com> Message-ID: On 2009-01-06, Jeremy.Chen wrote: > ftp.storbinary("STOR ftp-tst/ftp-file\n", fl) > ---------- > I think the params after STOR should't be a path,should be splited. > ftp.cwd("ftp-tst") > ftp.storbinary("STOR ftp-file\n", fl) No that isn't the problem. The problem is the '\n' at the end of the string. Having removed it, all worked fine. -- Antoon Pardon From mail at microcorp.co.za Wed Jan 7 02:44:36 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 7 Jan 2009 09:44:36 +0200 Subject: having problems with a multi-conditional while statement References: <40a44d6b-c638-464d-b166-ef66496a0676@l16g2000yqo.googlegroups.com> <95F236CF-6FAE-4690-AB81-9D2FF54341CD@semanchuk.com> Message-ID: <019501c970a1$699e5700$0d00a8c0@hendrik> "Philip Semanchuk" wrote: 8<------------ nice explanation -------------------- > Change the "and" to an "or" and you'll get the result you expected. Also google for "De Morgan", or "De Morgan's laws" Almost everybody stumbles over this or one of it's corollaries at least once in their careers. - Hendrik -- With the disappearance of the gas mantle and the advent of the short circuit, man's tranquillity began to be threatened by everything he put his hand on. (James Thurber. First sentence of Sex ex Machina) From alessio.pace at gmail.com Wed Jan 7 02:54:40 2009 From: alessio.pace at gmail.com (Alessio Pace) Date: Tue, 6 Jan 2009 23:54:40 -0800 (PST) Subject: Portable (Linux/Mac/Win) way to get network interfaces names and their addresses? Message-ID: <80b18a66-2817-4080-8a64-2e0392b8042d@c36g2000prc.googlegroups.com> Hi, I'm wondering how could I get, possibly in a pure Python solution, the list of network addresses on a machine and the IP address of each of them. In fact I came across recently on two solutions, one that is pure Python but that works only on Linux: ############################# def all_interfaces(): max_possible = 128 # arbitrary. raise if needed. bytes = max_possible * 32 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) names = array.array('B', '\0' * bytes) outbytes = struct.unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, # SIOCGIFCONF struct.pack('iL', bytes, names.buffer_info()[0]) ))[0] namestr = names.tostring() return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) ########################### and one other instead that is in the "netifaces" package (=> http://alastairs-place.net/netifaces/) which is written in C. Thanks in advance for any suggestion. -- Alessio Pace. From mail at microcorp.co.za Wed Jan 7 03:20:43 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 7 Jan 2009 10:20:43 +0200 Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com><200812301421.29888.mail@johnohagan.com><6s8s6nF4op56U2@mid.uni-berlin.de><3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet><20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com><531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <019601c970a1$6a3566e0$0d00a8c0@hendrik> "Mark Wooding" wrote: > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. > > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, but really he's just an > implementation detail and you wouldn't need him if your floor was big > enough and you had enough bits of sufficiently long string. > Lovely! This is the nicest analogy I have seen, and it seems to completely account for all the observed effects. The only other one that comes close is Dennis L Bieber's "Wandering Names". I propose that we name the garbage collection demon "Steven" because he has IMO lost this argument, and therefore deserves to spend eternity tied up in string. ;-) - Hendrik -- With the disappearance of the gas mantle and the advent of the short circuit, man's tranquillity began to be threatened by everything he put his hand on. (James Thurber. First sentence of Sex ex Machina) From mobiledreamers at gmail.com Wed Jan 7 03:37:13 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Wed, 7 Jan 2009 00:37:13 -0800 Subject: Using couchdb to build a EMAIL messaging solution with threaded inline replies Message-ID: Using couchdb to build a EMAIL messaging solution with threaded inline replies http://pylab.blogspot.com/search/label/couchdb -------------- next part -------------- An HTML attachment was scrubbed... URL: From ihatespam at hotmail.com Wed Jan 7 03:48:09 2009 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Wed, 7 Jan 2009 03:48:09 -0500 Subject: Any news on when some libraries will be ported to Python 3.0? Message-ID: I'm excited to use Python 3.0 (foolishly, it's the only Python interpreter I have on my system) but there are no libraries for it beyond the kitchen sink. Personally, a good start would be Beautiful Soup and Mechanize. I could also use DB. Has there been any word on Beautiful Soup? Has there been any word on Mechanize? What about DB? PIL would be nice, too, now that I think about it. Anyway, I'd love to hear some news about any of these things in particular or even anything in general. Am I the only one who's psyched for this version of Python? Thank you... From steven at REMOVE.THIS.cybersource.com.au Wed Jan 7 03:53:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 08:53:29 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 03:49:02 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> The only tricky thing is that items 1, 2 and 3 can be inside two >> different boxes at the same time. There's no obvious real world analogy >> to that without the boxes being nested. This ability for objects to be >> in two places at once (or even to be inside themselves!) is one of the >> few reasons why Python's use of references in the implementation needs >> to be mentioned. > > Ahh. So it /does/ need to be mentioned after all. Only in the sense that the behaviour of *real world* objects don't entirely match the behaviour of Python objects. If you just accept that Python objects can be in two places at once, an unintuitive concept I accept but hardly difficult to grasp, then you don't need to mention references. (Of course, as a purely practical matter, the English language makes it difficult to avoid the word "reference" entirely. That's not my intention.) > But you're wrong: > it's not an implementation detail: it's an essential part of the > language semantics. Er, pardon me, but you yourself suggested that one could implement Python without using references to objects, "like keeping lists of clones, and magically updating all the clones whenever one us mutated. That may even be a valid implementation for a distributed Python". Like you suggested, it would be a seriously rotten model for standard Python, but it is possible. The language semantics specifies the *behaviour*, not the *mechanism* required to implement that behaviour. > A better analogy. The objects are scattered across the floor. No > object is contained in another. However, we have a plentiful supply of > bits of string, each of which is tied to a Teflon-covered paperweight at > one end and has a blob of Blu-Tack on the other. Instead of putting > something in a box directly, what we do is grab a piece of string, stick > the Blu-Tack to the thing, and put the paperweight in the box. Not a bad analogy. I like it. But it still fails. Why can't I stick the paperweight in the box *before* attaching the Blu- Tack to something else, and then forget about attaching the Blu-Tack? There's nothing in your model to prevent dangling pointers, except hand- waving "it doesn't work like that". I assume the string is made of Teflon, otherwise I could stick the Blu- Tack to another piece of string. By the same token, the floor needs to be Teflon too. Why can't I grab the string by the end with the Blu-Tack and follow it backwards to find out where the paperweight is? I obviously know how to handle the end, because according to your model I'm sticking it to other objects. I suppose maybe there's a robot that does that Blu-Tack sticking for me, I just point to the object and say "That one!" and it happens. The string itself is invisible except to radar, which the robot has, and I don't. That way I can't follow the string backwards to find out where the paperweight is. Hmmm. This model is getting awfully complicated: Teflon string, Teflon paperweights, Blu-Tack, *and* a robot (presumably Teflon as well), none of which are visible to Python code, as well as objects which are. > This > way, we can stick several bits of string to the same object and put the > paperweights in different boxes. Indeed, nothing stops us sticking two > bits of string to a box, and putting both paperweights inside that same > box. But fitting a box into itself twice requires origami skills that > frighten me. Ah, you've obviously never studied origami under Sensei Ping of the Clan of the Pointed Stick! > The Teflon stops the Blu-Tack from sticking to the paperweights, 'cos > you're not allowed to do that. > > There's a daemon who comes around periodically and cleans up the mess of > paperweights which aren't in boxes, and tidies away things which don't > have any string stuck to them any more, So there's a brief moment between creating the object and sticking the Blu-Tack on it when the daemon might take the object and the string away? No, I guess not, that's another thing I just have to take on faith... the daemon knows not to touch anything until the robot has finished with it. Can I tie two pieces of string together, stop the daemon from disposing of them? Apparently not. Objects in two places at one time isn't sounding that weird any more. I actually do like your model, despite poking holes in it. As a model for what CPython is doing under the hood, it pretty good. But it's not a model for what a Python programmer does when writing Python code. There's no action equivalent to "attach blob of Blu-Tack to object", no action equivalent to "put the paperweight in the box". The robot does that when you point to an object and say "put that inside the box". The programmer doesn't do these things, he says "put that object in the box" and the robot attaches the Blu-Tack and moves the paperweight. The strings and paperweights and Blu-Tack are invisible and intangible to the programmer, *and* they are an implementation detail: as you put it, we could implement Python using clones of objects magically kept in sync, no string required. -- Steven From rogerb at rogerbinns.com Wed Jan 7 04:13:11 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 07 Jan 2009 01:13:11 -0800 Subject: Any news on when some libraries will be ported to Python 3.0? In-Reply-To: References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just Another Victim of the Ambient Morality wrote: > Anyway, I'd love to hear some news about any of these things in > particular or even anything in general. Am I the only one who's psyched for > this version of Python? I ported my APSW SQLite access module many months before Python 3.0 was released (around the time of the first beta release). The same codebase supports both Python 2 and 3 with very few conditionals and a few macros to make some Python 2 C api look like the Python 3 C api (eg pretending that the bytes type exists). Python 2.3 and up are supported on all platforms. It took longest to port my test suite over as I have 99.6% code coverage which is achieved by the test suite abusing every corner of the language and implementation. Fortunately a whole host of issues go away because of no 8 bit strings in Python 3. Other tools like Sphinx made my documentation so much better. That actually psyches me the most since Python is all about ease of reading and writing. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAklkchwACgkQmOOfHg372QTgewCfXBrz0UGuUNDqxjVGEJOwfF4p N6QAoJvZCZ1Vm9f6sN0P4bXb8o3I2pVj =Lba+ -----END PGP SIGNATURE----- From akineko at gmail.com Wed Jan 7 04:24:56 2009 From: akineko at gmail.com (akineko) Date: Wed, 7 Jan 2009 01:24:56 -0800 (PST) Subject: multiprocessing and SIGINT Message-ID: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> Hello everyone, I'm trying to use multiprocessing module, which is now available with Python 2.6. It is a nice enhancement and it worked great. However, I have a situation and I couldn't figure out how to deal with. My Python program spawns another process to take care of GUI house- keeping. When I type Ctrl-C to my terminal, instead of my main process, the spawned process always gets the SIGINT. I don't want the spawned process to handle SIGINT event. An exception handler (KeyboardInterrupt) is placed in the main program (but it didn't catch the event). I never encountered this problem before as spawned threads won't take SIGINT event. Is there any way I can force SIGINT event routing so that my main process will get it? Because of another requirement, I cannot swap main and spawned process. Any suggestions will be greatly appreciated. Best regards, Aki Niimura From steven at REMOVE.THIS.cybersource.com.au Wed Jan 7 04:26:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 07 Jan 2009 09:26:47 GMT Subject: Rich Comparisons Gotcha References: Message-ID: On Wed, 07 Jan 2009 01:23:19 +0000, Mark Wooding wrote: > A case-sensitive string is /not the same/ as a case-insensitive string. > One's a duck, the other's a goose. I'd claim here that i"abc" =~ "ABC" > must be False, because i"abc" =~ "abc" must be false also! To define it > otherwise leads to the incoherence you describe. It's only incoherent if you need equality to be an equivalence relation. If you don't, it is perfectly reasonable to declare that i"abc" equals "abc". -- Steven From sibteym at infotechsw.com Wed Jan 7 04:53:13 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Wed, 7 Jan 2009 15:23:13 +0530 Subject: Multiprocessing takes higher execution time Message-ID: <005701c970ad$c1b27140$5fc513ac@pwit.com> Hi, I use multiprocessing to compare more then one set of files. For comparison each set of files (i.e. Old file1 Vs New file1) I create a process, Process(target=compare, args=(oldFile, newFile)).start() It takes 61 seconds execution time. When I do the same comparison without implementing multiprocessing, it takes 52 seconds execution time. The parallel processing time should be lesser. I am not able to get advantage of multiprocessing here. Any suggestions can be very helpful. Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at python.net Wed Jan 7 04:58:05 2009 From: theller at python.net (Thomas Heller) Date: Wed, 07 Jan 2009 10:58:05 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <6sjcksF6574qU1@mid.individual.net> Nick Craig-Wood schrieb: > Ralf Schoenian wrote: >> Ryan wrote: >> > I've been using Python for many years now. It's a wonderful language >> > that I enjoy using everyday. I'm now interested in getting to know >> > more about the guts (C/C++) and extending it. But, extending python >> > still seems like a black art to me. Is there anymore docs or info on >> > extending it besides the standard sparse ones (http://www.python.org/ >> > doc/2.5.2/ext/intro.html) that may give me more insight? Is there a >> > class available? How can I learn more about the guts of python? How >> > would one go about following an interest in contributing to the >> > development of python. >> >> It is not exactly what you are looking for but nevertheless I am >> thinking the article "Automatic C Library Wrapping -- Ctypes from the >> Trenches" may be interesting for you. You can find it in the latest >> Python Papers issue or simply following the link: >> http://ojs.pythonpapers.org/index.php/tpp/article/view/71 > > Interesting - I didn't know about h2xml and xml2py before and I've > done lots of ctypes wrapping! Something to help with the initial > drudge work of converting the structures would be very helpful. > > ( http://pypi.python.org/pypi/ctypeslib/ ) > > I gave it a quick go and it worked fine. I had to edit the XML in one > place to make it acceptable (removing a u from a hex number). The > output of xml2py was an excellent place to start for the conversion, > though I don't think I'd want to use an automated process like in the > paper above as its output needed tweaking. > > ... If you are using a recent version of gccxml, then you should use the ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should really merge the gccxml-0.9 branch into the trunk;-) If you are already using the branch and the XML file is not accepted, then could you please provide a short C code snippet that reproduces the problem so that I can fix it? > Here are my thoughts on the conversion :- > > It converted an interface which looked like this (the inotify interface) > > struct inotify_event { > int wd; /* Watch descriptor */ > uint32_t mask; /* Mask of events */ > uint32_t cookie; /* Unique cookie associating related > events (for rename(2)) */ > uint32_t len; /* Size of name field */ > char name[]; /* Optional null-terminated name */ > }; > > Into this > > class inotify_event(Structure): > pass > inotify_event._fields_ = [ > ('wd', c_int), > ('mask', uint32_t), > ('cookie', uint32_t), > ('len', uint32_t), > ('name', c_char * 0), > ] > > Which is a very good start. However it defined these which clearly > aren't portable > > int32_t = c_int > uint32_t = c_uint > > Whereas it should have been using the ctypes inbuilt types > > c_int32 > c_uint32 IMO this would be difficult to achive automatically. There are cases wher c_int is the correct type, in other cases c_int32 is correct. > Also I don't think c_char * 0 does anything sensible in ctypes, > c_byte * 0 is what is required plus a bit of casting. This is a > non-standard GNU extension to C though. > > All that said though, it looks like a great time saver. > Thanks, Thomas From mdw at distorted.org.uk Wed Jan 7 05:17:55 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 10:17:55 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: Steven D'Aprano wrote: > Only in the sense that the behaviour of *real world* objects don't > entirely match the behaviour of Python objects. If you just accept > that Python objects can be in two places at once, an unintuitive > concept I accept but hardly difficult to grasp, then you don't need to > mention references. To my mind, explaining that objects can actually be in two (or three, or any unbounded number) of places at once, stashed inside each other to an arbitrary degree -- that looks like the excuses of someone who's been caught in a lie. Maybe it was a useful lie-to-children, meant to avoid explaining the full details in advance, but the time comes to put away childish things, and learn the truth. (I can't believe I just quoted Paul. I feel all dirty.) > Er, pardon me, but you yourself suggested that one could implement > Python without using references to objects, "like keeping lists of > clones, and magically updating all the clones whenever one us mutated. > That may even be a valid implementation for a distributed Python". > > Like you suggested, it would be a seriously rotten model for standard > Python, but it is possible. The language semantics specifies the > *behaviour*, not the *mechanism* required to implement that behaviour. Yes, there's an isomorphism between the two, so technically either could be used as a model to explain the behaviour of Python. But, to my mind at least, the idea of references (or sticky bits of string) is the simpler -- it doesn't involve doing anything`magically' -- so Occam suggests that it's superior. I'm sure, if I tried, I could come with an even more absurd model, or express it in more complicated ways, but the power of a model lies in its combination of simplicity and explanatory power. The `they're just objects' model is very simple, but gets tied up in knots explaining things. The `it's all references' model is only a little more complicated, but explains everything. It might be -- and I don't know, because I'm not an educator -- that the `they're just objects' model hits a local maximum in the tradeoff between simplicity and explanation that's sufficiently high that it's useful for teaching beginners. It's hard to expose this simple model's weaknesses without assignment (or messing with `is' or `id'); unfortunately, it's very easy to explose them once you do have assignment (or any kind of mutable state). And Python's purely functional subset is rarely used exclusively in nontrivial programs. So I'm sceptical that this particular lie-to-children doesn't cause more harm than good. > Why can't I stick the paperweight in the box *before* attaching the Blu- > Tack to something else, and then forget about attaching the Blu-Tack? > There's nothing in your model to prevent dangling pointers, except hand- > waving "it doesn't work like that". Perils of posting at half past three in the morning, I'm afraid. I seemed to have hit a creative streak, but my clarity of thinking was definitely impaired. You are only allowed to handle paperweights. A robot does the rest. Some of the objects might give you splinters or paper cuts. The robot is concerned about your safety and won't let you go near them. There's a wall between you and the playpen, with a catflap in it. The robot will fit through the catflap but you're too big. (For advanced users only: there might be a secret hatch which lets you into the main arena where the robot works, via a storeroom containing a surprising quantity of handy power tools, heavy weaponry, and explosives, but oddly lacking in safety goggles. You can build some truly marvellous things by sneaking through here, and persuade the robot to do things it wouldn't usually by threatening it at gunpoint, but you can also blow yourself up.) You tell the robot what you want him to do by handing him paperweights. He doesn't take the paperweights away with him, but instead hooks onto the string so that he can follow it to the other end. He's quite good at following even tangled strings, and at finding paperweights in boxes and hooking onto their strings too. The robot will stick new strings onto objects at your request and hand you the paperweights. > I assume the string is made of Teflon, otherwise I could stick the Blu- > Tack to another piece of string. By the same token, the floor needs to be > Teflon too. You could do, if you were actually given a loose piece of string. But you aren't, so that's OK. I was wrong that the paperweights needed to be Teflon. > Why can't I grab the string by the end with the Blu-Tack and follow it > backwards to find out where the paperweight is? Because you're never at that end. And the robot just won't do that. (The daemon in the MIT Scheme environment /can/ do this for you. It uses a feature called `wabbit hunting'. You set up a `Fudd thunk' describing which objects you want it to find the paperweights of, and set the thing to `wabbit season'. The daemon will track down the `wabbits' -- boxes holding those paperweights -- that you asked for and returns them. When you want it to stop doing this, you return to `duck season'. Yes, it's very silly.) > This model is getting awfully complicated: Teflon string, Teflon > paperweights, Blu-Tack, *and* a robot (presumably Teflon as well), > none of which are visible to Python code, as well as objects which > are. Wow. I didn't actually read this far before hitting `follow-up', but you anticipated the robot. Well done. But, no, actually nothing needs to be made of Teflon, and I was just tired. > Ah, you've obviously never studied origami under Sensei Ping of the > Clan of the Pointed Stick! Apparently not. My origami skills are, alas, weak. > So there's a brief moment between creating the object and sticking the > Blu-Tack on it when the daemon might take the object and the string away? > No, I guess not, that's another thing I just have to take on faith... the > daemon knows not to touch anything until the robot has finished with > it. The daemon knows not to interfere with the robot, and the robot knows to do everything in the right order. But the daemon is an optional part of the model, so we can just ignore him until we're ready to deal with him. The daemon's name is Maxwell, by the way. Say hello, Maxwell. > Can I tie two pieces of string together, stop the daemon from disposing > of them? Apparently not. No, but you can confuse him for a little while by building box- paperweight-string-box-... cycles. Eventually he cottons on to what you've done, though. > But it's not a model for what a Python programmer does when writing > Python code. There's no action equivalent to "attach blob of Blu-Tack > to object", no action equivalent to "put the paperweight in the box". No, indeed. Python is a language for talking about paperweights. And it's because of the paperweights that the duck-typing works: all the paperweights are the same shape and size, so they're physically interchangeable. > The robot does that when you point to an object and say "put that > inside the box". The programmer doesn't do these things, he says "put > that object in the box" and the robot attaches the Blu-Tack and moves > the paperweight. Yup! > The strings and paperweights and Blu-Tack are invisible and intangible > to the programmer, *and* they are an implementation detail: as you put > it, we could implement Python using clones of objects magically kept > in sync, no string required. You could try to explain Python in terms of paperweights only, but since they all look identical, it's hard to see why interesting behaviour emerges without explaining about the world on the side of the strings. Of course, the paperweights-and-string-(and-robot-and-catflap-(and- storeroom-cum-arms-cache)) model explains it all, and doesn't leave you having to learn Sensei Ping's arcane origami skills. If you're actually /in/ the arena with the objects, armed with the ability to fold a box so strangely that you can store it in three other boxes and itself, how come you never make a catastrophic mistake? My answer is that the robot doesn't make mistakes often, and the worst you can do to yourself is get in a bit of a tangle with those bits of string. If you're really cunning, you might manage to persuade the robot to fetch a hand-grenade from the storeroom and blow itself up, but there'll be a new version of the robot available later which won't fall for that trick. -- [mdw] From mdw at distorted.org.uk Wed Jan 7 05:21:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 7 Jan 2009 10:21:50 +0000 (UTC) Subject: Rich Comparisons Gotcha References: Message-ID: Steven D'Aprano wrote: > It's only incoherent if you need equality to be an equivalence relation. > If you don't, it is perfectly reasonable to declare that i"abc" equals > "abc". Right! And if you didn't want an equivalence relation, then `==' will suit you fine. The problem is that some applications seem to /want/ an equivalence relation, and one that's more useful (i.e., less discriminating) than `is'. -- [mdw] From jstroud at mbi.ucla.edu Wed Jan 7 05:25:31 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 02:25:31 -0800 Subject: Oh! The people of all over the world! In-Reply-To: <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6abdb6a8-40af-4fc3-8b87-eee6a93ce72b@w24g2000prd.googlegroups.com> Message-ID: Obaid R. wrote: > So an illegal occupation is NOT a provocation but fighting the > occupation IS? By which scales do you judge? > > I would argue that a person following such backwards logic and who > sees these pictures[1] and STILL claims that showing sympathy is > difficult has a serious problem. After all the logic is simple: for > every action (read occupation) there is a reaction (read resistance) > equal to it in force and opposite to it in direction. > > You can of course argue that the reaction is the cause of the action, > but that is clearly illogical and proves your iniquity in this matter > and your bias against the victim. It might take a humanitarian > catastrophe of sizable proportions and a biased person would still not > feel any sympathy. Not that there is no catastrophe, but rather > because bias is by nature practiced in spite of good reason and > available evidence, not because of it. I'm much more apt to listen now that you aren't invoking references to religion at every sentence. If Israel is guilty of inhumanity, then it is more appropriate to appeal to one's humanity. By the way, its obvious to most rational people that the Israeli reaction is overwrought and likely morally unjust--but I can't stand antisemitism just like I can't stand hatred of Islam just like I can't stand hatred of Christians. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From quian.xu at stud.tu-ilmenau.de Wed Jan 7 05:40:35 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 11:40:35 +0100 Subject: string length problem? Message-ID: Hi All, why the code print len(u"?test?") returns 8 instead of 6? Best regards Qian From vinay_sajip at yahoo.co.uk Wed Jan 7 05:47:32 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 7 Jan 2009 02:47:32 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: <5710ebc5-cf13-4978-a411-08d1df6eb422@40g2000prx.googlegroups.com> On Jan 6, 10:19 pm, Thorsten Kampe wrote: > I don't think he's interested in the "line number where the logging call > was issued" but where the exception occurred. Well, he does say "all logging" and "every logging". And, as I mentioned earlier, there is already support for tracebacks by using the Logger.exception method in an exception handler. Regards, Vinay Sajip From david at hlacik.eu Wed Jan 7 05:57:57 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Wed, 7 Jan 2009 11:57:57 +0100 Subject: linked list with cycle structure Message-ID: dictionary with cycle structure Hello guys, I have a linked list where *number of elements is unlimited* and **last element points on random (can be first, last, in middle , anywhere) element within linked list** - this is important . My goals is to create an architecture /scheme for **algoritmus which will count total number of elements** of such linked list. Yes , maybe it sounds strange, but we need to implement this and i would be very gladfull for your toughts. Thanks in advance and wishing you a sucessfull year! David From martin at v.loewis.de Wed Jan 7 06:17:58 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 12:17:58 +0100 Subject: Problem building Python 2.5.2 curses module on HP/UX 11.11 In-Reply-To: References: Message-ID: <49648f66$0$32239$9b622d9e@news.freenet.de> > So, given that there are no actual errors during the compile, and the > warnings are probably benign, does anyone know what would cause the > resulting compiled module to NOT have the init function? Can you do nm(1) on the module? It's now called _curses_failed.sl Regards, Martin From __peter__ at web.de Wed Jan 7 06:26:12 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Jan 2009 12:26:12 +0100 Subject: string length problem? References: Message-ID: Qian Xu wrote: > why the code > print len(u"?test?") > returns 8 instead of 6? You may have declared an encoding that differs from the one your editor actually uses, e. g. # -*- coding: iso-8859-1 -*- print len(u"?test?") whereas your editor writes UTF-8. Peter From nospam at nospam.com Wed Jan 7 06:27:00 2009 From: nospam at nospam.com (Gilles Ganault) Date: Wed, 07 Jan 2009 12:27:00 +0100 Subject: [urllib2] 302 -> can't get cookie Message-ID: Hello I'm using urllib2 to connect to a web server with POST, and then the server sends a cookie to hold the session ID, but also redirects the user to another page: === HTTP/1.1 302 Found Date: Wed, 07 Jan 2009 11:20:51 GMT Server: Apache Set-Cookie: PHPSESSID=4015f14eb04dc81159253a9533a7c590; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Location: second_page.php Content-Length: 0 Connection: close Content-Type: text/html; charset=ISO-8859-1 === As a result, urllib2 follows this new page, and the HTTP header that I get is the one from the second page. Is there a way to ignore this second page, and stick to the first page through which I connect? Thank you. From quian.xu at stud.tu-ilmenau.de Wed Jan 7 06:28:17 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 12:28:17 +0100 Subject: string length problem? References: Message-ID: Qian Xu wrote: > Hi All, > > why the code > print len(u"?test?") > returns 8 instead of 6? > > Best regards > Qian I have solved the problem myself. # -*- coding: utf-8 -*- print len(u"?test?") --- or --- s = "?test?" print len(s.decode("utf-8")) --Qian From sturlamolden at yahoo.no Wed Jan 7 06:45:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jan 2009 03:45:00 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Jan 7, 2:02 am, Steven D'Aprano wrote: > In Python code, there are no references and no dereferencing. The why does CPython keep track of reference counts? > You can't, because Python doesn't have references. In a language with > references, that's easy. Python does not 'pass-by-reference' as Fortran or Pascal do. > It's harder (impossible?) to write a version that will operate on > arbitrary types, but that's statically typed languages for you. In Python an assignment (re)binds the name to another value. You can certainly write a swap method for mutable types. But you cannot use the assignment operator to swap the values. > No no no, lists and tuples store *objects*. >>> a = 123456789 >>> b = [a] >>> c = [a] >>> d = [a, a] >>> b[0] is a True >>> c[0] is a True >>> d[0] is a True >>> d[1] is a True Where is the object 'a' stored? From steve at holdenweb.com Wed Jan 7 06:47:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 06:47:27 -0500 Subject: pg_result_status() alternative? In-Reply-To: References: Message-ID: Qian Xu wrote: > Hi All, > > I am using the pg module (http://www.pygresql.org/pg.html) for database > testing. > > I have got a problem now: > I want to check the result status of postgresql database, which can be done > in php by using pg_result_status() > (http://www.phpbuilder.com/manual/en/function.pg-result-status.php) > > How can I do the same thing in python (2.5)? > Without knowing the full details of that particular module I would hazard a guess that any database errors will raise exceptions in Python. No exceptions means your database operation worked fine. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 7 06:49:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 06:49:46 -0500 Subject: Multiprocessing takes higher execution time In-Reply-To: <005701c970ad$c1b27140$5fc513ac@pwit.com> References: <005701c970ad$c1b27140$5fc513ac@pwit.com> Message-ID: Sibtey Mehdi wrote: > Hi, > > > > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) I create > a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > > > When I do the same comparison without implementing multiprocessing, it > takes 52 seconds execution time. > > > > The parallel processing time should be lesser. > > > > I am not able to get advantage of multiprocessing here. > > > > Any suggestions can be very helpful. > My first suggestion would be: show us some code. We aren't psychic, you know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From quian.xu at stud.tu-ilmenau.de Wed Jan 7 07:21:23 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Wed, 07 Jan 2009 13:21:23 +0100 Subject: pg_result_status() alternative? References: Message-ID: Steve Holden wrote: > Without knowing the full details of that particular module I would > hazard a guess that any database errors will raise exceptions in Python. > No exceptions means your database operation worked fine. result status is not an exception. It means the information of frontend/backend protocal, after a SQL-statement is execute. The following is a list of backend IPC commands (v3) ---------------------------------------------------- Z - Zero / Ready for Query E - Error Code A - Notification P - Cursor Response B - Binary Row D - Data, Ascii C - Complete G - Copy IN H - Copy OUT I - Idle T - Row Description V - Function result For instance: ---------------------------------------------------- SELECT * FROM my_table; The backend protocal should return T (Row Description) and the frontend protocal should return Q (Query) ---------------------------------------------------- DROP TABLE my_table; The backend protocal should return C (Complete) and the frontend protocal should return Q (Query) --Qian From marcisimo at googlemail.com Wed Jan 7 07:27:17 2009 From: marcisimo at googlemail.com (marco kuhn) Date: Wed, 7 Jan 2009 13:27:17 +0100 Subject: mac osx how to use a specific python environment Message-ID: hi, I would like to use a specific python environment in a script . The script is load as a plugin by a program which offer a python api . The python environment is build in. How can I use the standard python environment. Can i explicit load the env in my python script. Best MArco -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Wed Jan 7 07:31:15 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 07 Jan 2009 06:31:15 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> Message-ID: Thomas Heller wrote: > Nick Craig-Wood schrieb: > > Interesting - I didn't know about h2xml and xml2py before and I've > > done lots of ctypes wrapping! Something to help with the initial > > drudge work of converting the structures would be very helpful. > > > > ( http://pypi.python.org/pypi/ctypeslib/ ) > > > > I gave it a quick go and it worked fine. I had to edit the XML in one > > place to make it acceptable (removing a u from a hex number). > > If you are using a recent version of gccxml, then you should use the > ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should > really merge the gccxml-0.9 branch into the trunk;-) > > If you are already using the branch and the XML file is not accepted, > then could you please provide a short C code snippet that reproduces > the problem so that I can fix it? I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess doesn't have the code from the branch in. > > Here are my thoughts on the conversion :- > > > > It converted an interface which looked like this (the inotify interface) > > > > struct inotify_event { > > int wd; /* Watch descriptor */ > > uint32_t mask; /* Mask of events */ > > uint32_t cookie; /* Unique cookie associating related > > events (for rename(2)) */ > > uint32_t len; /* Size of name field */ > > char name[]; /* Optional null-terminated name */ > > }; > > > > Into this > > > > class inotify_event(Structure): > > pass > > inotify_event._fields_ = [ > > ('wd', c_int), > > ('mask', uint32_t), > > ('cookie', uint32_t), > > ('len', uint32_t), > > ('name', c_char * 0), > > ] > > > > Which is a very good start. However it defined these which clearly > > aren't portable > > > > int32_t = c_int > > uint32_t = c_uint > > > > Whereas it should have been using the ctypes inbuilt types > > > > c_int32 > > c_uint32 > > IMO this would be difficult to achive automatically. There are cases > wher c_int is the correct type, in other cases c_int32 is correct. Yes it is almost impossible difficult to achieve automatically - exactly how far do you want to unravel the twisty turny mess of typedefs that make up uint32_t? It is easy to change the generated output since it defines the type in one place. uint32_t and friends (stdint.h) are standardised in C99 so might it be reasonable to put some special cases in for them, expecially since the corresponding types already exist in ctypes? -- Nick Craig-Wood -- http://www.craig-wood.com/nick From wladimirufc at gmail.com Wed Jan 7 07:44:43 2009 From: wladimirufc at gmail.com (wladimir) Date: Wed, 7 Jan 2009 04:44:43 -0800 (PST) Subject: Defer problem Message-ID: <21330603.post@talk.nabble.com> Hi, I have an problem. I want to fire one callback after n callbacks fired, but when i fire one callback all the chain will be executed. Example: def handle(x): print 'callback ' + str(x) def handle2(x): print 'after callbacks' d1 = defer.Deffered() d2 = defer.Deffered() d3 = defer.Deffered() d = defer.DeferredList([d1, d2, d3], fireOnOneCallback =1 , fireOnOneErrback=1) d1.addCallback(handle) d2.addCallback(handle) d3.addCallback(handle) #d.addCallback(handle2) d1.callback(1) d2.callback(2) d3.callback(3) I want fire handle2 after all handle -- View this message in context: http://www.nabble.com/Defer-problem-tp21330603p21330603.html Sent from the Python - python-list mailing list archive at Nabble.com. From exarkun at divmod.com Wed Jan 7 08:05:53 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 7 Jan 2009 08:05:53 -0500 Subject: Defer problem In-Reply-To: <21330603.post@talk.nabble.com> Message-ID: <20090107130553.20272.1063061710.divmod.quotient.32919@ohm> On Wed, 7 Jan 2009 04:44:43 -0800 (PST), wladimir wrote: > >Hi, > >I have an problem. I want to fire one callback after n callbacks fired, but >when i fire one callback all the chain will be executed. Example: > >def handle(x): > print 'callback ' + str(x) > > >def handle2(x): > print 'after callbacks' > > >d1 = defer.Deffered() >d2 = defer.Deffered() >d3 = defer.Deffered() > >d = defer.DeferredList([d1, d2, d3], fireOnOneCallback =1 , >fireOnOneErrback=1) `fireOnOneCallback? is the flag which makes the `DeferredList? fire when the first wrapped `Deferred? has fired. If you want the `DeferredList? to only fire after all of the wrapped deferreds have fired, don't pass this flag. Jean-Paul From sjmachin at lexicon.net Wed Jan 7 08:12:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 7 Jan 2009 05:12:03 -0800 (PST) Subject: string length problem? References: Message-ID: On Jan 7, 9:40?pm, Qian Xu wrote: > Hi All, > > why the code > ? print len(u"?test?") > returns 8 instead of 6? I suggest that you do print repr(u"?test?") and inspect the result. HTH, John From exarkun at divmod.com Wed Jan 7 08:21:21 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 7 Jan 2009 08:21:21 -0500 Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? In-Reply-To: <76277bc4-2810-48f4-8953-4393eb97c810@t26g2000prh.googlegroups.com> Message-ID: <20090107132121.20272.551977417.divmod.quotient.32922@ohm> On Tue, 6 Jan 2009 19:01:48 -0800 (PST), Giampaolo Rodola' wrote: >Hi, >I'm trying to add TLS/SSL support to pyftpdlib. >Since various defects have been found in the SSLv2 protocol many FTPS >servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 >only and sistematically reject any client attempting to use SSLv2. >Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 >connections only? >If that's not possible can I determine the encryption protocol being >used *after* that the SSL/TLS handshake took place? > > >I tried to use wrap_socket as follows: > >self.socket = ssl.wrap_socket(self.socket, , > certfile=CERTFILE, > server_side=True, > >ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) > >...it works if on the client side I use TLSv1 but not if I use SSLv3 >("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL >routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is >raised) > At the OpenSSL level, you do this by specifying SSLv23_METHOD and then setting the SSL_OP_NO_SSLv2 flag. With pyOpenSSL, you do this by creating a context with SSLv23_METHOD and then setting SSL_OP_NO_SSLv2 on it, like so: from OpenSSL.SSL import Context, SSLv23_METHOD, OP_NO_SSLv2 context = Context(SSLv23_METHOD) context.set_options(OP_NO_SSLv2) It seems the ssl module does expose SSLv23_METHOD as PROTOCOL_SSLv23, but I don't see SSL_OP_NO_SSLv2 anywhere, nor any way to specify any extra flags. Oring PROTOCOL_SSLv3 together with PROTOCOL_TLSv1 is almost certainly not the right approach, anyway (as you saw with your tests). Jean-Paul From deets at nospam.web.de Wed Jan 7 08:22:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 14:22:16 +0100 Subject: linked list with cycle structure References: Message-ID: <6sjok8F6dqciU1@mid.uni-berlin.de> David Hl??ik wrote: > dictionary with cycle structure > > Hello guys, > > I have a linked list where *number of elements is unlimited* and > **last element points on random (can be first, last, in middle , > anywhere) element within linked list** - this is important . My goals > is to create an architecture /scheme for **algoritmus which will count > total number of elements** of such linked list. > Yes , maybe it sounds strange, but we need to implement this and i > would be very gladfull for your toughts. Time for homework again? Last time sorting in O(n), now this. How about you try something yourself and show us the results - then we might comment on enhancements or problems. Diez From lihang9999 at gmail.com Wed Jan 7 08:31:14 2009 From: lihang9999 at gmail.com (Li Han) Date: Wed, 7 Jan 2009 05:31:14 -0800 (PST) Subject: image recogniton? References: <854p0cry42.fsf@dozer.localdomain> Message-ID: On 1?7?, ??4?14?, J Kenneth King wrote: > I'm curious as to what application the solution to this problem is > practical for all of its difficulty? Sorry, I oversimplified the question because of my poor english. It is an analog compass whose value we need to read into the computer every second. We use a video camera keep shooting it, and the compass and camera are fixed. -- Li Han From alessiogiovanni.baroni at gmail.com Wed Jan 7 08:42:31 2009 From: alessiogiovanni.baroni at gmail.com (alessiogiovanni.baroni at gmail.com) Date: Wed, 7 Jan 2009 05:42:31 -0800 (PST) Subject: Interpreter & Thread state & Frame structures. Message-ID: Hi to all, there are some fields in the PyInterpreterState and PyThreadState obscures. PyInterpreterState: 1) Why there are the fields *next and *tstate_head? PyThreadState: 1) Why there is the field *next? An object PyFrameObject is a portion of code, with a state. But exactly? Contents of a method/function, or more simply any block indented of code? For example, this code: def foo(s): if s > 0: return True else: return False how much frames are? Thank you! From David Wed Jan 7 09:04:18 2009 From: David (David) Date: Wed, 07 Jan 2009 08:04:18 -0600 Subject: How to get millisec/fractional seconds out of a time object ? References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: On Tue, 6 Jan 2009 13:46:46 -0800, "Chris Rebert" wrote: >The attribute you're looking for is 'microseconds', not 'milliseconds'. > >Cheers, >Chris Thanks Most of the docs are useful but those on timedelta seemed too concise. Dave From bj_666 at gmx.net Wed Jan 7 09:37:09 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 14:37:09 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: <6sjt0lF6bhk2U3@mid.uni-berlin.de> On Wed, 07 Jan 2009 03:45:00 -0800, sturlamolden wrote: > On Jan 7, 2:02 am, Steven D'Aprano > wrote: > >> In Python code, there are no references and no dereferencing. > > The why does CPython keep track of reference counts? Show me the *Python* code that does that. Using reference counting for memory management is an implementation detail. It's possible to use other garbage collectors without the need of reference counting. Ciao, Marc 'BlackJack' Rintsch From fake at usenet.no Wed Jan 7 09:45:18 2009 From: fake at usenet.no (Terje) Date: Wed, 07 Jan 2009 15:45:18 +0100 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> Message-ID: <6sjtg5F6gnvfU1@mid.individual.net> Is there a web service/API out there identifying Israel owned software/software companies/web sites/web services? If I am about to buy a piece of software, but don't want to support the Israeli economy, it would have been handy if I could just poll a web service to get the answer. This information should be kept in a database, and be public to the world through a very simple xml API, something along these lines: Request: Some Company Name Response: true Here's one source for this kind of information (I am sure there are plenty others): http://www.science.co.il/SoftwareCo.asp Of course, a web service like this would be equally useful to those who want to support Israeli companies. From almar.klein at gmail.com Wed Jan 7 10:06:08 2009 From: almar.klein at gmail.com (Almar Klein) Date: Wed, 7 Jan 2009 16:06:08 +0100 Subject: image recogniton? In-Reply-To: References: <854p0cry42.fsf@dozer.localdomain> Message-ID: 2009/1/7 Li Han > On 1?7?, ??4?14?, J Kenneth King wrote: > > I'm curious as to what application the solution to this problem is > > practical for all of its difficulty? > Sorry, I oversimplified the question because of my poor english. It is > an analog compass whose value we need to read into the computer every > second. We use a video camera keep shooting it, and the compass and > camera are fixed. > -- > Li Han > > -- > http://mail.python.org/mailman/listinfo/python-list > The compass of the needle looks like a line. Lines can be best detected using second order (Gaussian) derivatives. scipy.ndimage.gaussian_filter provides a filter you can use for that. Then maybe PCA to find the direction of the needle, and you're done! There's probably more to it (there always is), but this might get you started. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Jan 7 10:07:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jan 2009 10:07:18 -0500 Subject: mac osx how to use a specific python environment In-Reply-To: References: Message-ID: <476B6270-EDDE-45E1-96A6-12C4180C2D14@semanchuk.com> On Jan 7, 2009, at 7:27 AM, marco kuhn wrote: > hi, > > I would like to use a specific python environment in a script . > The script is load as a plugin by a program which offer a python api . > The python environment is build in. > > How can I use the standard python environment. > Can i explicit load the env in my python script. Hi Marco, I'm not exactly sure what you want to do. But if you execute `python` at the command line, OS X will launch whatever version of Python it finds first in your PATH. Hope this helps Philip From joe at strout.net Wed Jan 7 10:09:55 2009 From: joe at strout.net (Joe Strout) Date: Wed, 07 Jan 2009 08:09:55 -0700 Subject: image recogniton? In-Reply-To: References: <854p0cry42.fsf@dozer.localdomain> Message-ID: <4964C5C3.602@strout.net> Li Han wrote: > Sorry, I oversimplified the question because of my poor english. It is > an analog compass whose value we need to read into the computer every > second. We use a video camera keep shooting it, and the compass and > camera are fixed. If you have any choice about it, it would be greatly simpler, cheaper, and more effective to throw out the camera and analog compass, and use an electronic compass instead. These are affordable and work quite well provided you keep them level (the same constraint you have with an old-fashioned compass too). You can make some simple interface hardware, or spend a bit more for something with a USB or serial interface built in, like this: Best, - Joe From pruebauno at latinmail.com Wed Jan 7 10:19:49 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Wed, 7 Jan 2009 07:19:49 -0800 (PST) Subject: Any news on when some libraries will be ported to Python 3.0? References: Message-ID: On Jan 7, 3:48?am, "Just Another Victim of the Ambient Morality" wrote: > ? ? Anyway, I'd love to hear some news about any of these things in > particular or even anything in general. ?Am I the only one who's psyched for > this version of Python? > ? ? Thank you... There are many people psyched about 3.0, but also many older farts that have been using Python since 1.0 and have tons of code that already works fine and feel a little bit like the mechanic that has to switch his tools from imperial to metric; it is overall probably for the better but still a pain to adapt everything to the new system. This is open source so you either have to find a way to motivate the authors of the libraries without pissing them off, or you will have to be patient. From djames.suhanko at gmail.com Wed Jan 7 10:21:25 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Wed, 7 Jan 2009 13:21:25 -0200 Subject: Tkinter - problem closing window In-Reply-To: <6sgk44F5qmm8U2@mid.uni-berlin.de> References: <6sgk44F5qmm8U2@mid.uni-berlin.de> Message-ID: Wow, nice! But, with join i can't padding with 0. '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) Then, i has been used: a[i] = "%02d" % int(random.randint(0,60)) I will change int(random.randint(0,60)) for random.randint(0,60), only. Thank you, guys !! ;-) The problem was solved when removed the second "mainloop". I will use the Toplevel instead Tk() again. Thank you for the nice lesson !! On Tue, Jan 6, 2009 at 6:47 AM, Marc 'BlackJack' Rintsch wrote: > On Mon, 05 Jan 2009 12:25:53 -0200, Djames Suhanko wrote: > >> I has a litle program that open another window. When I close de root >> window in quit button, I need clicking 2 times to close. is where the >> problem? >> >> [?] >> >> 17 def gera_seis(self): >> 18 a = {} >> 19 for i in range(6): >> 20 a[i] = "%02d" % int (random.randint(0,60)) >> 21 resultadoA = "%s-%s-%s-%s-%s-%s" % >> (str(a[0]),str(a[1]),str(a[2]),str(a[3]),str(a[4]),str(a[5])) >> 22 return resultadoA > > Not the problem but unnecessary complex. `random.randint()` already > returns an int, no need to call `int()` on it. The string formatting > with ``%`` returns strings, so there is no need to call `str()` on the > values. Even if the values where not strings: The '%s' place holder > implies a call to `str()` while formatting. If you put something into a > dictionary with consecutive `int` keys, you might use a list instead. > > All this can be written as a simple one liner:: > > '-'.join(str(random.randint(0, 60)) for dummy in xrange(6)) > >> 24 def say_hi(self): >> 25 resultado = self.gera_seis() >> 26 raiz = Tk() > > The problem is here? > >> 27 F = Frame(raiz) >> 28 F.pack() >> 29 hello = Label(F, text=resultado) 30 hello.pack() >> 31 F.mainloop() > > ?and here. > > There is only one `Tk` instance and mainloop allowed per `Tkinter` > application. Otherwise really strange things can happen. Additional > windows have to be created as `Toplevel` instances. > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list > -- Djames Suhanko LinuxUser 158.760 From invalid at invalid Wed Jan 7 10:28:27 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 07 Jan 2009 09:28:27 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> Message-ID: <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> On 2009-01-07, Steve Holden wrote: >> I use multiprocessing to compare more then one set of files. >> >> For comparison each set of files (i.e. Old file1 Vs New file1) >> I create a process, >> >> Process(target=compare, args=(oldFile, newFile)).start() >> >> It takes 61 seconds execution time. >> >> When I do the same comparison without implementing >> multiprocessing, it takes 52 seconds execution time. > My first suggestion would be: show us some code. We aren't > psychic, you know. I am! He's only got one processor, and he's just been bit by Amdahl's law when P<1 and S<1. There you have a perfectly "psychic" answer: an educated guess camoflaged in plausible-sounding but mostly-bullshit buzzwords. A better psychic would have avoided making that one falsifiable statement (he's only got one processor). -- Grant Edwards grante Yow! Hello. Just walk at along and try NOT to think visi.com about your INTESTINES being almost FORTY YARDS LONG!! From tryg.olson at gmail.com Wed Jan 7 10:35:58 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Wed, 7 Jan 2009 07:35:58 -0800 (PST) Subject: How to set a cookie using Cookie Module Message-ID: Hello - This is my first attempt at python cookies. I'm using the Cookie module and trying to set a cookie. Below is my code. The cookie does not get set. What am I doing wrong? print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" print print """ My Page """ c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print If I put javascript code to create a cookie in place of my python cookie code, the javascript cookie gets set. Any tips appreciated! Tryg From james at agentultra.com Wed Jan 7 10:50:56 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 07 Jan 2009 10:50:56 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> Message-ID: <85vdsrqfmn.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 6, 12:24?pm, J Kenneth King wrote: >> Jonathan Gardner writes: >> > On Jan 6, 8:18?am, sturlamolden wrote: >> >> On Jan 6, 4:32 pm, mark wrote: >> >> >> > I want to implement a internal DSL in Python. I would like the syntax >> >> > as human readable as possible. >> >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >> >> I've seen the goto joke). >> >> > This isn't really true. You can, for instance, write a program (in >> > Python) that takes your pseudo-Python and converts it into Python. >> > This is what a number of templating libraries such as Mako do. >> >> Which is not even close to being the same. >> >> Lisp - the program source is also the data format >> >> Python - the program source is a string >> >> I could go on a really long rant about how the two are worlds apart, but >> I'll let Google tell you if you're really interested. > > I get that Lisp is special because you can hack on the reader as it is > reading the file in. This is strongly discouraged behavior, as far as > I know, despite the number of cute hacks you can accomplish with it. It is generally discouraged unless there's a reason for it. > But consider that this really isn't different than having a program > read in the lisp-with-modification source and spitting out pure lisp, > to be read by an honest-to-gosh lisp program later. > > If that's the case, then Lisp and Python really aren't that different > in this regard, except that you don't have the option of modifying the > reader as it reads in the file. I think you are missing the distinction. Lisp expressions are also data structures. A Lisp expression can be passed to functions and macros to be operated on before being executed. When you're writing Lisp source, you're basically looking at the AST on one level and when you start writing macros for your program, you're creating a "DSL" or interface to that AST. Lisp source is eventually expanded to a giant list that is consed by the evaluator (as far as I understand it. I'm just getting into the compiler stuff myself). Consider: (my-func 1 2 3) This is just a list, the "primitive" data-type in Lisp! This piece of "data" can be operated on by other bits of Lisp code because it is just a list as far as Lisp is concerned. In contrast, Python source is a string that needs to be parsed into bytecode which is then run through the interpreter. The AST is completely hidden from the source author. Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. I can only write a python program that parses some other string and generates code that can be run by another interpreter. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. From hv at tbz-pariv.de Wed Jan 7 11:11:14 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 07 Jan 2009 17:11:14 +0100 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: <6sk2h5F6h203U1@mid.individual.net> Sandro Tosi schrieb: > Some basic question I'd like to ask are: > > - what are you using matplotlib for? I use the API to create PNGs from data stored in postgres. Webframework: Django. > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? The API is not good documented. It was very hard for me to understand what was going on the source. > - what would you like to see in a book about matplotlib? How to use the API. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From per.olav.kroka at ericsson.com Wed Jan 7 11:17:52 2009 From: per.olav.kroka at ericsson.com (PerOK) Date: Wed, 7 Jan 2009 17:17:52 +0100 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid Message-ID: os.listdir() keep giving this error: [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid: 'V:\\ETOPOK_Example_MyTestView\\LD_FuncBlocks_013\\cnh1603087_ui_toolkit_mid p\\test/*.*' The V:\\ETOPOK_Example_MyTestView refer to a ClearCase (CC) dynamic view. I have found that MS Visual Studio.Net 2002 and 2003 seems to have this problem with CC. But I am not using any of MS's Visual Studios. (see http://www-01.ibm.com/support/docview.wss?ratlid=cctocbody&rs=984&uid=swg21229572) The seen problem only to appear when some/all caches have forgot about the directory. If I query the directory again (multiple times) listdir() will finally return the content of the directory. The "DOS" command DIR has no problem listing the same directory. Configuration: >>> sys.version '2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]' >>> sys.getwindowsversion() (5, 0, 2195, 2, 'Service Pack 4') >>> sys.platform 'win32' Per OK PS: Why does the listdir() function add '*.*' to the path? PS2: Why does the listdir() function add '/*.*' to the path on windows and not '\\*.*' ? From nick at craig-wood.com Wed Jan 7 11:31:15 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 07 Jan 2009 10:31:15 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: Grant Edwards wrote: > On 2009-01-07, Steve Holden wrote: > > >> I use multiprocessing to compare more then one set of files. > >> > >> For comparison each set of files (i.e. Old file1 Vs New file1) > >> I create a process, > >> > >> Process(target=compare, args=(oldFile, newFile)).start() > >> > >> It takes 61 seconds execution time. > >> > >> When I do the same comparison without implementing > >> multiprocessing, it takes 52 seconds execution time. > > > My first suggestion would be: show us some code. We aren't > > psychic, you know. > > I am! > > He's only got one processor, and he's just been bit by Amdahl's > law when P<1 and S<1. > > There you have a perfectly "psychic" answer: an educated guess > camoflaged in plausible-sounding but mostly-bullshit buzzwords. > A better psychic would have avoided making that one falsifiable > statement (he's only got one processor). ;-) My guess would be that the job is IO bound rather than CPU bound, but that is covered by Amdahl's Law too where P is approx 0, N irrelevant... Being IO bound explains why it takes longer with multiprocessing - it causes more disk seeks to run an IO bound algorithm in parallel than running it sequentially. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jcd at unc.edu Wed Jan 7 11:38:29 2009 From: jcd at unc.edu (J. Cliff Dyer) Date: Wed, 07 Jan 2009 11:38:29 -0500 Subject: Creating new instances of subclasses. Message-ID: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> I want to be able to create an object of a certain subclass, depending on the argument given to the class constructor. I have three fields, and one might need to be a StringField, one an IntegerField, and the last a ListField. But I'd like my class to delegate to the proper subclass automatically, so I can just do: >>> f1 = Field('abc') >>> f2 = Field('123') >>> f3 = Field('D,E,F') >>> f1.data 'abc' >>> f2.data 123 >>> f3.data ['D','E','F'] >>> type(f1) >>> type(f2) >>> type(f3) I've come up with a solution, but I suspect there's something cleaner I can do with the inheritance structure of __new__. I don't like explicitly leapfrogging over Field.__new__ to object.__new__. My attempt is below: def is_list(arg): if ',' in arg: return True else: return False def is_integer(arg): try: int(arg) except ValueError: return False else: return True class Field(object): def __new__(cls, a): if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) def __init__(self, input): super(Field, self).__init__(input) self.data = input class IntegerField(Field): def __new__(cls, a): return object.__new__(cls, a) def __init__(self, s): super(IntegerField, self).__init__(s) self.s = int(self.s) class ListField(Field): def __new__(cls, a): return object.__new__(cls, a) def __init__(self, s): super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): def __new__(cls, a): return object.__new__(cls, a) Is there a cleaner way to do this? The main problem is that Field.__new__ gets in the way of properly constructing the subclasses once I've used it to select the proper subclass in the first place. Cheers, Cliff -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill From davidgshi at googlemail.com Wed Jan 7 11:44:55 2009 From: davidgshi at googlemail.com (davidgshi at googlemail.com) Date: Wed, 7 Jan 2009 08:44:55 -0800 (PST) Subject: Looking for a generic Python script to turn xml into a dataset/array Message-ID: I am looking for a generic Python script to turn xml into a dataset/ array, to be ready to be saved in a .dbf file. The xml contains CDATA section. Regards. David From steve at holdenweb.com Wed Jan 7 11:47:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 11:47:19 -0500 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <6sjtg5F6gnvfU1@mid.individual.net> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: Terje wrote: > Is there a web service/API out there identifying Israel owned > software/software companies/web sites/web services? If I am about to buy > a piece of software, but don't want to support the Israeli economy, it > would have been handy if I could just poll a web service to get the > answer. This information should be kept in a database, and be public to > the world through a very simple xml API, something along these lines: > > Request: > Some Company Name > > Response: > true > > Here's one source for this kind of information (I am sure there are > plenty others): > http://www.science.co.il/SoftwareCo.asp > > Of course, a web service like this would be equally useful to those who > want to support Israeli companies. Words fail me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kay.schluehr at gmx.net Wed Jan 7 12:11:29 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Wed, 7 Jan 2009 09:11:29 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: On 7 Jan., 16:50, J Kenneth King wrote: > Python expressions are not > data types either and hence no macros -- I can't write a python function > that generates python code at compile time. Have you ever considered there are languages providing macros other than Lisp? Macros have nothing to do with homoiconcity. > I can only write a python > program that parses some other string and generates code that can be run > by another interpreter. No, it is the same interpreter and it is also possible to modify python parsers on the fly. This is just not possible with Pythons builtin parser. > > Consider: > > for i in range(0, 100): > ? ? do_something_interesting(i) > > That's a pretty straight forward Python expression, but I can't do > anything with it -- it's not a unit of data, it's a string. > > The distinction is not subtle by any means. From arkanes at gmail.com Wed Jan 7 12:16:48 2009 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 7 Jan 2009 11:16:48 -0600 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python In-Reply-To: <85vdsrqfmn.fsf@dozer.localdomain> References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <4866bea60901070916q33a8f0e6x4fbf625ba68ddea3@mail.gmail.com> On Wed, Jan 7, 2009 at 9:50 AM, J Kenneth King wrote: > Jonathan Gardner writes: > >> On Jan 6, 12:24 pm, J Kenneth King wrote: >>> Jonathan Gardner writes: >>> > On Jan 6, 8:18 am, sturlamolden wrote: >>> >> On Jan 6, 4:32 pm, mark wrote: >>> >>> >> > I want to implement a internal DSL in Python. I would like the syntax >>> >> > as human readable as possible. >>> >>> >> Also beware that Python is not Lisp. You cannot define new syntax (yes >>> >> I've seen the goto joke). >>> >>> > This isn't really true. You can, for instance, write a program (in >>> > Python) that takes your pseudo-Python and converts it into Python. >>> > This is what a number of templating libraries such as Mako do. >>> >>> Which is not even close to being the same. >>> >>> Lisp - the program source is also the data format >>> >>> Python - the program source is a string >>> >>> I could go on a really long rant about how the two are worlds apart, but >>> I'll let Google tell you if you're really interested. >> >> I get that Lisp is special because you can hack on the reader as it is >> reading the file in. This is strongly discouraged behavior, as far as >> I know, despite the number of cute hacks you can accomplish with it. > > It is generally discouraged unless there's a reason for it. > >> But consider that this really isn't different than having a program >> read in the lisp-with-modification source and spitting out pure lisp, >> to be read by an honest-to-gosh lisp program later. >> >> If that's the case, then Lisp and Python really aren't that different >> in this regard, except that you don't have the option of modifying the >> reader as it reads in the file. > > I think you are missing the distinction. > > Lisp expressions are also data structures. A Lisp expression can be > passed to functions and macros to be operated on before being > executed. When you're writing Lisp source, you're basically looking at > the AST on one level and when you start writing macros for your program, > you're creating a "DSL" or interface to that AST. Lisp source is > eventually expanded to a giant list that is consed by the evaluator (as > far as I understand it. I'm just getting into the compiler stuff > myself). > > Consider: > > (my-func 1 2 3) > > This is just a list, the "primitive" data-type in Lisp! This piece of > "data" can be operated on by other bits of Lisp code because it is just > a list as far as Lisp is concerned. > > In contrast, Python source is a string that needs to be parsed into > bytecode which is then run through the interpreter. The AST is > completely hidden from the source author. Python expressions are not > data types either and hence no macros -- I can't write a python function > that generates python code at compile time. I can only write a python > program that parses some other string and generates code that can be run > by another interpreter. > > Consider: > > for i in range(0, 100): > do_something_interesting(i) > > That's a pretty straight forward Python expression, but I can't do > anything with it -- it's not a unit of data, it's a string. > > The distinction is not subtle by any means. Ignoring reader macros for a moment, there is no way in either lisp, ruby, or python to change the syntax that the compiler understands, and the ability to work with your code directly as a data structure (which is what makes lisp macros powerful) isn't directly relevant to the idea of an "internal' DSL. The OP wants a Ruby-style DSL by which he means "something that lets me write words instead of expressions". The ruby syntax is amenable to this, python (and lisp, for that matter) syntax is not and you can't implement that style of internal DSL in those languages. The answer to the OP is "you can't - use Ruby or modify your requirements". From adal.chiriliuc at gmail.com Wed Jan 7 12:24:00 2009 From: adal.chiriliuc at gmail.com (Adal Chiriliuc) Date: Wed, 7 Jan 2009 09:24:00 -0800 (PST) Subject: Is it ok to type check a boolean argument? Message-ID: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Hello, Me and my colleagues are having an discussion about the best way to code a function (more Pythonic). Here is the offending function: def find(field, order): ....if not isinstance(order, bool): ........raise ValueError("order must be a bool") ....order_by = "asc" if order else "desc" ....return _find(field + "+" + order_by) We are not sure what's the best practice here. Should we or should we not check the type of the "order" variable, which should be a bool? In one of our unit-tests we passed the "invalid_order" string as the order argument value. No exception was raised, since the string was evaluated as being True. We know about "Don't look before we jump", but we are not sure how it applies in this case, since we don't get any exception when passing an invalid type argument. This function is not visible to our clients, only internally in our project. It's part of the public interface of a sub-system, so we are not sure either if the fact that it returns an invalid result for a badly type argument it's an API specification break or not. The pro argument was that if a new programmer comes and passes a wrongly typed argument, he will get a silent failure. The cons argument was that there are many functions which could silently fail in this mode, especially those having bool arguments. Should we in general check when doing unit-testing that the methods behave correctly when passed arguments of the wrong type? What do you do in your projects? From gnewsg at gmail.com Wed Jan 7 12:27:37 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 7 Jan 2009 09:27:37 -0800 (PST) Subject: ssl module - how can I accept SSLv3 and TLSv1 protocols only? References: Message-ID: On 7 Gen, 14:21, Jean-Paul Calderone wrote: > On Tue, 6 Jan 2009 19:01:48 -0800 (PST), Giampaolo Rodola' wrote: > >Hi, > >I'm trying to add TLS/SSL support to pyftpdlib. > >Since various defects have been found in the SSLv2 protocol many FTPS > >servers (i.e. proftpd and vsftpd) decided to support SSLv3 and TLSv1 > >only and sistematically reject any client attempting to use SSLv2. > >Is there a way to tell ssl.wrap_socket() to accept SSLv3 and TLSv1 > >connections only? > >If that's not possible can I determine the encryption protocol being > >used *after* that the SSL/TLS handshake took place? > > >I tried to use wrap_socket as follows: > > >self.socket = ssl.wrap_socket(self.socket, , > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?certfile=CERTFILE, > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?server_side=True, > > >ssl_version=ssl.PROTOCOL_SSLv3 | ssl.PROTOCOL_TLSv1) > > >...it works if on the client side I use TLSv1 but not if I use SSLv3 > >("SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL > >routines:SSL3_READ_BYTES:sslv 3 alert handshake failure" exception is > >raised) > > At the OpenSSL level, you do this by specifying SSLv23_METHOD and then > setting the SSL_OP_NO_SSLv2 flag. ?With pyOpenSSL, you do this by > creating a context with SSLv23_METHOD and then setting SSL_OP_NO_SSLv2 on > it, like so: > > ? ? from OpenSSL.SSL import Context, SSLv23_METHOD, OP_NO_SSLv2 > ? ? context = Context(SSLv23_METHOD) > ? ? context.set_options(OP_NO_SSLv2) > > It seems the ssl module does expose SSLv23_METHOD as PROTOCOL_SSLv23, > but I don't see SSL_OP_NO_SSLv2 anywhere, nor any way to specify any > extra flags. > > Oring PROTOCOL_SSLv3 together with PROTOCOL_TLSv1 is almost certainly > not the right approach, anyway (as you saw with your tests). > > Jean-Paul- Nascondi testo citato > > - Mostra testo citato - These are pretty bad news. I'm going to open a request on the bug tracker hoping that this situation could be solved soon. Thanks for your reply anyway. Sincerely --- Giampaolo http://code.google.com/p/pyftpdlib From e4me4m at gmail.com Wed Jan 7 12:29:06 2009 From: e4me4m at gmail.com (e4me4m at gmail.com) Date: Wed, 7 Jan 2009 09:29:06 -0800 (PST) Subject: Importing modules Message-ID: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Coming from a scripting background where we used to write everything into one script, I'm now going modular with Python. I place related functions in one module, and other functions in other modules. This all works OK, but I'm a bit confused about importing modules from the standard library. For example, say 3 of my 12 modules use os and os.path. Right now, I have import statements in all 3 modules that import both os and os.path. This seems wrong to me. I read the docs and understand that before loading a module that Python is smart enough to look and see if it's already loaded, so there is no performance issue (it would seem), but I was thinking there is probably a way to load all the modules I need in some orderly fashion without having these multiple import statements in my separate modules. Could someone point me to some docs that explain the Python way of loading modules when breaking old, big (everything in one script) into more manageable modular scripts? Thanks, e4m From jakecjacobson at gmail.com Wed Jan 7 12:32:23 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 09:32:23 -0800 (PST) Subject: FTP example going through a FTP Proxy Message-ID: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> Hi, I need to write a simple Python script that I can connect to a FTP server and download files from the server to my local box. I am required to go through a FTP Proxy and I don't see any examples on how to do this. The FTP proxy doesn't require username or password to connect but the FTP server that I am connecting to does. Any examples on how to do this would be greatly appreciated. I am limited to using Python version 2.4.3 on a Linux box. From nospam at forMe.thks Wed Jan 7 12:35:31 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:35:31 -0500 Subject: formatted 'time' data in calculations Message-ID: There seems to be no shortage of information around on how to use the time module, for example to use time.ctime() and push it into strftime and get something nice out the other side, but I haven't found anything helpful in going the other way. That is, given some formatted text describing times - is there something that makes it easy to calculate time differences, or do I have to index my way through the string pulling out characters, converting to integers etc... Data is formatted: t1 = 09:12:10 t2 = 11:22:14 I want to calculate tdiff = t2-t1 Any suggestions? (Thanks for anything you can offer) -Ross From deets at nospam.web.de Wed Jan 7 12:39:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 18:39:16 +0100 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: <6sk7m4F6oe4jU1@mid.uni-berlin.de> e4me4m at gmail.com wrote: > Coming from a scripting background where we used to write everything > into one script, I'm now going modular with Python. I place related > functions in one module, and other functions in other modules. > > This all works OK, but I'm a bit confused about importing modules from > the standard library. For example, say 3 of my 12 modules use os and > os.path. Right now, I have import statements in all 3 modules that > import both os and os.path. This seems wrong to me. > > I read the docs and understand that before loading a module that > Python is smart enough to look and see if it's already loaded, so > there is no performance issue (it would seem), but I was thinking > there is probably a way to load all the modules I need in some orderly > fashion without having these multiple import statements in my separate > modules. > > Could someone point me to some docs that explain the Python way of > loading modules when breaking old, big (everything in one script) into > more manageable modular scripts? There is no way around the multiple imports. Or, at least not a clean way - you *could* stuff things into __builtin__ in one module, effectively making it available globally. But this is a hack at best, and certainly not the way to go. The thing about modularization is that you want single pieces of code that can be read and understood and extended by themselves (even if embedded and useful in - or only in - a larger context). So the seemingly unnecessary imports serve documentation purposes - what is actually needed by the current module. Diez From clp2 at rebertia.com Wed Jan 7 12:40:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 09:40:12 -0800 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid In-Reply-To: References: Message-ID: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> > PS: Why does the listdir() function add '*.*' to the path? Don't know what you're talking about. It doesn't do any globbing or add "*.*" to the path. Its exclusive purpose is to list the contents of a directory, so /in a sense/ it does add "*.*", but then not adding "*.*" would make the function completely useless given its purpose. > PS2: Why does the listdir() function add '/*.*' to the path on windows and > not '\\*.*' ? You can use either directory separator (\ or /) with the Python APIs on Windows. r"c:\WINDOWS\" works just as well as "c:/WINDOWS/". Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tim.arnold at sas.com Wed Jan 7 12:42:45 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Wed, 7 Jan 2009 12:42:45 -0500 Subject: parse/slice/... References: <51451b8a-6377-45d7-a8c8-54d4cadb2594@n33g2000pri.googlegroups.com> Message-ID: "rcmn" wrote in message news:51451b8a-6377-45d7-a8c8-54d4cadb2594 at n33g2000pri.googlegroups.com... > I'm not sure how to call it sorry for the subject description. > Here what i'm trying to accomplish. > the script i'm working on, take a submitted list (for line in file) > and generate thread for it. unfortunately winxp has a limit of 500 > thread . So I have to parse/slice the file by chunk of 500 and loop > until the list is done. > I though i would of done it in no time but i can't get started for > some reason. > And i can't find a good way to do it efficiently . Does anyone have > something similar to this. > > thank you Here's how I work on a list a bunch of items (100 by default) ata time: def drain_list(tlist,step=None): if not step: step = 100 j=0 for i in range(step,len(tlist), step): yield tlist[j:i] j = i if j < len(tlist): yield tlist[j:] --Tim From schap at offenbachers.com Wed Jan 7 12:45:12 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 07 Jan 2009 12:45:12 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <4964EA28.4050203@offenbachers.com> Here is how I have done adjustments to time in the past. This is mostly Date related but it may help today = datetime.date.today() wkdiff = datetime.timedelta(weeks=1) daydiff = datetime.timedelta(days=1) startdate=(today-wkdiff)-daydiff this will subtract 1 week and 1 day from today. Stephen Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found > anything helpful in going the other way. > > That is, given some formatted text describing times - is there > something that makes it easy to calculate time differences, or do I > have to index my way through the string pulling out characters, > converting to integers etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) > > -Ross > -- > http://mail.python.org/mailman/listinfo/python-list > > From steve at holdenweb.com Wed Jan 7 12:46:10 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 12:46:10 -0500 Subject: Importing modules In-Reply-To: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: e4me4m at gmail.com wrote: > Coming from a scripting background where we used to write everything > into one script, I'm now going modular with Python. I place related > functions in one module, and other functions in other modules. > > This all works OK, but I'm a bit confused about importing modules from > the standard library. For example, say 3 of my 12 modules use os and > os.path. Right now, I have import statements in all 3 modules that > import both os and os.path. This seems wrong to me. > It isn't. > I read the docs and understand that before loading a module that > Python is smart enough to look and see if it's already loaded, so > there is no performance issue (it would seem), but I was thinking > there is probably a way to load all the modules I need in some orderly > fashion without having these multiple import statements in my separate > modules. > Think of the import statement as giving access to a particular namespace, with the side-effect of loading the code if it's the first import. > Could someone point me to some docs that explain the Python way of > loading modules when breaking old, big (everything in one script) into > more manageable modular scripts? > Import each module into every other module that requires its functionality. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From simonharrison.uk at googlemail.com Wed Jan 7 12:46:22 2009 From: simonharrison.uk at googlemail.com (simonh) Date: Wed, 7 Jan 2009 09:46:22 -0800 (PST) Subject: #python IRC help - my internet provider is banned! Message-ID: Hi. Not sure if anyone can help here, but I'm trying to access #python and have found out that my ISP has a blanket ban (for some reason). Does anyone know how I can contact an operator to join? Thanks. From ptmcg at austin.rr.com Wed Jan 7 12:48:19 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 09:48:19 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: On Jan 7, 11:24?am, Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > First of all, please get used to saying "My colleagues and I..." instead of "Me and my colleagues". My kids still haven't learned this (both are in college!), and it annoys me daily. Sorry for the rant, you were just the final straw, so I'm taking it out on you. The offending part of this function is the argument name "order". If this is a boolean argument, I would assume that True should be ordered data, and False would be unordered or randomly ordered data. The name "order" really does not clue me in that the two choices are "ascending" and "descending", nor is it clear what the mapping is to True and False. You are right, Python's inference of boolean-ness makes it easy for coders to guess wrong as to the argument type and still get a program that emits no exceptions, although possibly doing the opposite of the intended function. I would suggest that in your project, you establish a naming convention for these boolean arguments. The name should be descriptive and assertive, so that the value of True is reasonably intuitive. Instead of "order", perhaps "return_ascending_results" with a default value of True. To further cue your developers that a boolean argument is desired, you could try adding "_flag" to all of your boolean arguments, sort of a Reverse Hungarian Notation. Or another option altogether would be to define some module level constants, like this: ASCENDING_RESULTS = object() DESCENDING_RESULTS = object() def find(field, results_order=ASCENDING_RESULTS): order_by = { ASCENDING_RESULTS : "asc", DESCENDING_RESULTS: "desc"} [results_order] return _find(field + "+" + order_by) If anything other than those two constants is passed for the results_order argument, then a KeyError exception will be raised. (I used a similar technique to this in pyparsing's operatorPrecedence method, in which an argument indicates whether an operator is right- or left-associative.) -- Paul From deets at nospam.web.de Wed Jan 7 12:49:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 07 Jan 2009 18:49:10 +0100 Subject: formatted 'time' data in calculations References: Message-ID: <6sk88mF6qpbhU1@mid.uni-berlin.de> Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found anything > helpful in going the other way. > > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index > my way through the string pulling out characters, converting to integers > etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) The datetime module contains everything you need. Look at the strptime-function that will allow you to parse the above string to an actual datetime.time-object, and the you can subtract these to yield a datetime.timedelta-object. Diez From clp2 at rebertia.com Wed Jan 7 12:50:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 09:50:32 -0800 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <50697b2c0901070950y66a61f84h6b999a7e9056444d@mail.gmail.com> On Wed, Jan 7, 2009 at 9:35 AM, Ross wrote: > There seems to be no shortage of information around on how to use the time > module, for example to use time.ctime() and push it into strftime and get > something nice out the other side, but I haven't found anything helpful in > going the other way. > > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index my > way through the string pulling out characters, converting to integers etc... > > Data is formatted: > > t1 = 09:12:10 > t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Any suggestions? (Thanks for anything you can offer) Use the `datetime` class in the `datetime` module (http://docs.python.org/library/datetime.html). It has a class method .strptime() to parse a string into a `datetime` object. You can then subtract one `datetime` from another to produce a `timedelta` object representing the difference between them. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ptmcg at austin.rr.com Wed Jan 7 12:53:17 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 09:53:17 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> ...and don't worry about a possible performance issue of importing os (or any other module) multiple times - the Python import manager is smart enough to recognize previously imported modules, and wont import them again. If a module uses the os module, then it should import it - that's just it. Another consideration might be that you are breaking up your own program modules too much. For instance, if I had a program in which I were importing urllib in lots of modules, it might indicate that I still have some regrouping to do, and that I could probably gather all of my urllib dependent code into a single place. -- Paul From nospam at forMe.thks Wed Jan 7 12:54:13 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:54:13 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <4964EC45.3040902@forMe.thks> Thanks Chris and Diez for the quick pointers... Very helpful Ross. From nospam at forMe.thks Wed Jan 7 12:54:54 2009 From: nospam at forMe.thks (Ross) Date: Wed, 07 Jan 2009 12:54:54 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Thanks Chris and Diez for the quick pointers... Very helpful Ross. From philip at semanchuk.com Wed Jan 7 12:59:34 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jan 2009 12:59:34 -0500 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <82FCAE42-F733-47FC-B411-AB31383DD590@semanchuk.com> On Jan 7, 2009, at 12:24 PM, Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? IMHO you should not. > The pro argument was that if a new programmer comes and passes a > wrongly typed argument, he will get a silent failure. "Wrongly typed" is a matter of opinion. The following values also evaluate to False when converted to bool: None [] () "" {} To me, they're just as false as False is, if you catch my meaning. I would not like to have to convert them to bool to be able to use them when calling your function. Imagine this scenario -- order = read_order_from_preferences_xml_file(default_value = None) # order is now "ascending" or None find(the_field_name, order) It seems logical to pass a string or None in this case without converting them to bool. You might feel more comfortable if the parameter was called "is_ordered", which would at least imply that it is a boolean so that someone unfamiliar with the interface would be less tempted to pass something like the last part of an ORDER BY statement, like "last_name, first_name, age DESC". I can understand your temptation to enforce bool-ness, but you have a very good point about this one function then being different from all of the others that aren't as picky. HTH Philip From ptmcg at austin.rr.com Wed Jan 7 13:00:06 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jan 2009 10:00:06 -0800 (PST) Subject: Creating new instances of subclasses. References: Message-ID: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> On Jan 7, 10:38?am, "J. Cliff Dyer" wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. ?But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > > >>> f1 = Field('abc') > >>> f2 = Field('123') > >>> f3 = Field('D,E,F') O-O is not always the solution to every problem. Since inheritance is getting in your way, try using a class-level factory method. Instead of using the Field constructor, use a staticmethod of Field, something like: @staticmethod def make_Field(a) if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) and then get rid of all those __new__ methods, too. -- Paul From mwilson at the-wire.com Wed Jan 7 13:06:53 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 07 Jan 2009 13:06:53 -0500 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> Message-ID: Steve Holden wrote: > e4me4m at gmail.com wrote: [ ... ] >> Could someone point me to some docs that explain the Python way of >> loading modules when breaking old, big (everything in one script) into >> more manageable modular scripts? >> > Import each module into every other module that requires its > functionality. True. The O.P. can note one of the miracles of Python: (for an example, I'll pick a library module at random .. image) One can write a module -- myimage.py, say, that imports image, and has some functions that return objects based on calls to image functions. A program that imports myimage can use these objects in all possible ways and not have to import image. It doesn't need to know anything about just where myimage gets its stuff. Importing only strictly needs to be one level deep. (Of course, the programmer needs to know what all those possible ways are. The programmer may have to have read the docs for the image module ... ) Mel. From tjreedy at udel.edu Wed Jan 7 13:11:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 13:11:09 -0500 Subject: Creating new instances of subclasses. In-Reply-To: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> References: <1231346309.20559.18.camel@aalcdl07.lib.unc.edu> Message-ID: J. Cliff Dyer wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > >>>> f1 = Field('abc') >>>> f2 = Field('123') >>>> f3 = Field('D,E,F') >>>> f1.data > 'abc' >>>> f2.data > 123 >>>> f3.data > ['D','E','F'] >>>> type(f1) > >>>> type(f2) > >>>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner Make your master class _Field and make Field a factory function that returns the proper subclass instance. The body of Field could be the body of __new__ below. Then dump the __new__ methods. tjr I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. > > Cheers, > Cliff > From mensanator at aol.com Wed Jan 7 13:17:55 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 7 Jan 2009 10:17:55 -0800 (PST) Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: On Jan 7, 8:45?am, Terje wrote: > Is there a web service/API out there identifying Israel owned > software/software companies/web sites/web services? If I am about to buy > a piece of software, but don't want to support the Israeli economy, it > would have been handy if I could just poll a web service to get the > answer. This information should be kept in a database, and be public to > the world through a very simple xml API, something along these lines: > > Request: > Some Company Name > > Response: > true > > Here's one source for this kind of information (I am sure there are > plenty others):http://www.science.co.il/SoftwareCo.asp > > Of course, a web service like this would be equally useful to those who > want to support Israeli companies. Something like that web-service that publishes the names and addresses of doctors who perform abortions so that they can be assassinated? From mildew_spores at hotmail.com Wed Jan 7 13:30:32 2009 From: mildew_spores at hotmail.com (Mildew Spores) Date: Wed, 7 Jan 2009 18:30:32 -0000 Subject: #python IRC help - my internet provider is banned! References: Message-ID: What? Sounds a bit unlikely unless its Virgin.. I'd imagine it might be that your isp needs to get itself off a black list. Brian -- My Hotmail Account mildew_spores at hotmail.com "simonh" wrote in message news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com... > Hi. Not sure if anyone can help here, but I'm trying to access #python > and have found out that my ISP has a blanket ban (for some reason). > Does anyone know how I can contact an operator to join? Thanks. From thedavidfactor at gmail.com Wed Jan 7 13:32:34 2009 From: thedavidfactor at gmail.com (TheDavidFactor) Date: Wed, 7 Jan 2009 10:32:34 -0800 (PST) Subject: socket.error 24: too many open files Message-ID: I'm new to python, but have been writing programs in other languages for about 15 years now. As part of my job I develop applications that interface with Asterisk in various ways. As a way of getting my feet wet I decided to try to rewrite an outbound call script that I have in another language into python. It's a deamon that runs on a linux box and every 15 seconds it checks a MySQL table for new records, if there are any it creates a .call file on the Asterisk server using ssh, it also checks the Asterisk server, again via ssh, for any finished calls and if there are any it reads the .call file and writes the result in to the MySQL table. I did a google search for ssh and a python script that someone had written that wraps up some paramiko calls to make the ssh interaction easier. I'm also using MySQLdb for the MySQL access. It sleeps for 15 seconds then creates an ssh connection the asterisk server, checks the MySQL table, checks the asterisk server, closes the connection and goes back to sleep. After it has run for an hour or so I get the error in the subject when the ssh class tries to create a new socket. I have double checked that it is closing the socket. I don't know what else to check, any suggestions would be much appreciated. From enleverlesX.XmcX at XmclaveauX.com Wed Jan 7 13:44:33 2009 From: enleverlesX.XmcX at XmclaveauX.com (=?utf-8?Q?M=C3=A9ta-MCI_=28MVP=29?=) Date: Wed, 7 Jan 2009 19:44:33 +0100 Subject: =?utf-8?Q?Re:_When_does_python_3.1=EF=BC=8C_3.2_ve?= =?utf-8?Q?rsion_out=EF=BC=9F?= In-Reply-To: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> References: <8b0ca9f7-3e67-4571-a55f-660b53d35f58@b41g2000pra.googlegroups.com> Message-ID: <4964f93c$0$4079$ba4acef3@news.orange.fr> Hi! The mountain Python-3000 gave birth to a mouse Python-3. You must waiting for Python-4000... @+ MCI From tjreedy at udel.edu Wed Jan 7 13:45:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 13:45:52 -0500 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: Adal Chiriliuc wrote: > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) My opinions: 1. 'order' should be 'a' (the default) or 'd'. True and False by themselves are meaningless. Then the check, if needed, is "if order not in 'ad':". 'up' and 'down' are possible too. 2. Consider renaming _find as find, with two params and do the parameter check there. Except when one is calling a function recursively (repeatedly) with known-good params, wrapping a function with a simple arg check seems like noise to me. > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? I say it should not be a bool. The below illustrates another reason why this is the wrong type. > In one of our unit-tests we passed the "invalid_order" string as the > order argument value. No exception was raised, since the string was > evaluated as being True. If you make 'order' a string, then a bad string input should raise an exception somewhere. I suspect _find could be written to do this if it does not already. > We know about "Don't look before we jump", but we are not sure how it > applies in this case, since we don't get any exception when passing an > invalid type argument. > This function is not visible to our clients, only internally in our > project. It's part of the public interface of a sub-system, so we are > not sure either if the fact that it returns an invalid result for a > badly type argument it's an API specification break or not. > > The pro argument was that if a new programmer comes and passes a > wrongly typed argument, he will get a silent failure. That is bad, but in this case, I see the problem as a slight mis-design. > The cons argument was that there are many functions which could > silently fail in this mode, especially those having bool arguments. Which are rather rare, I think. In the 3.0 builtin functions, sorted's 'reverse' param is the only one. For back compatibility, it actually accepts ints. > Should we in general check when doing unit-testing that the methods > behave correctly when passed arguments of the wrong type? As in 'raise an exception', I think at least one test is good. Terry Jan Reedy From tiktak.hodiki at gmail.com Wed Jan 7 13:49:26 2009 From: tiktak.hodiki at gmail.com (tiktak.hodiki at gmail.com) Date: Wed, 7 Jan 2009 10:49:26 -0800 (PST) Subject: [Mechanize.ClientForm] double reading from urllib2.urlopen Message-ID: Hello, folks! I use mechanize.clientform to parse HTML-forms. I preliminary check response and call response.read().find("..."). But when it's taken to ClientForm.ParseResponse, it can't parse because of response.read() is zero-length text. The problem is that ClientForm.ParseResponse is not taken text of response, only object. Example: import urllib from ClientForm import ParseResponse response = urllib.urlopen("http://yandex.ru") if -1 != response.read().find("foobar"): pass form = ParseResponse(response)[1] <-- there is exception IndexError From simonharrison.uk at googlemail.com Wed Jan 7 13:52:51 2009 From: simonharrison.uk at googlemail.com (simonh) Date: Wed, 7 Jan 2009 10:52:51 -0800 (PST) Subject: #python IRC help - my internet provider is banned! References: Message-ID: On Jan 7, 6:30?pm, "Mildew Spores" wrote: > What? Sounds a bit unlikely unless its Virgin.. > I'd imagine it might be that your isp needs to get itself off a black list. > Brian > > -- > My Hotmail Account > mildew_spo... at hotmail.com > > "simonh" wrote in message > > news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com... > > > Hi. Not sure if anyone can help here, but I'm trying to access #python > > and have found out that my ISP has a blanket ban (for some reason). > > Does anyone know how I can contact an operator to join? Thanks. > > ISP is bethere and client is Chatzilla. From mal at egenix.com Wed Jan 7 14:10:58 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 07 Jan 2009 20:10:58 +0100 Subject: How to get millisec/fractional seconds out of a time object ? In-Reply-To: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> References: <7ai7m49t20lf322b4gfliabggt86j6bfp3@4ax.com> Message-ID: <4964FE42.4090706@egenix.com> On 2009-01-06 22:34, David at bag.python.org wrote: > Thanks for help to a beginner. > > script23 > import time > import datetime > start_time = datetime.datetime.now() > time.sleep(0.14) > end_time = datetime.datetime.now() > datetime.timedelta = end_time - start_time > print(datetime.timedelta) # works, prints 0:00:0.141000 > print(datetime.timedelta.seconds) # prints 0 > print(datetime.timedelta.milliseconds) # fails > < object has no attribute milliseconds > > > How do I get the 0.141000 out of that or any time object ? > On line docs are arcane to a novice. If you're only interested in the fractional seconds part, you're much better off with doing: import time start_time = time.time() ... end_time = time.time() delta_seconds = end_time - start_time delta_milliseconds = delta_seconds * 1000 -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 07 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From jakecjacobson at gmail.com Wed Jan 7 14:11:27 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 11:11:27 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> Message-ID: <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> On Jan 7, 12:32?pm, jakecjacobson wrote: > Hi, > > I need to write a simple Python script that I can connect to a FTP > server and download files from the server to my local box. ?I am > required to go through a FTP Proxy and I don't see any examples on how > to do this. ?The FTP proxy doesn't require username or password to > connect but the FTP server that I am connecting to does. > > Any examples on how to do this would be greatly appreciated. ?I am > limited to using Python version 2.4.3 on a Linux box. This is what I have tried so far, import urllib proxies = {'ftp':'ftp://proxy_server:21'} ftp_server = 'ftp.somecompany.com' ftp_port='21' username = 'aaaa' password = 'secretPW' ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + ftp_port data = urllib.urlopen(ftp_string, proxies=proxies) data=urllib.urlopen(req).read() print data I get the following error: Traceback (most recent call last): File "./ftptest.py", line 22, in ? data = urllib.urlopen(ftp_server, proxies=proxies) File "/usr/lib/python2.4/urllib.py", line 82, in urlopen return opener.open(url) File "/usr/lib/python2.4/urllib.py", line 190, in open return getattr(self, name)(url) File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp host, path = splithost(url) File "/usr/lib/python2.4/urllib.py", line 949, in splithost match = _hostprog.match(url) TypeError: expected string or buffer From google at mrabarnett.plus.com Wed Jan 7 14:12:15 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 19:12:15 +0000 Subject: [Mechanize.ClientForm] double reading from urllib2.urlopen In-Reply-To: References: Message-ID: <4964FE8F.3000004@mrabarnett.plus.com> tiktak.hodiki at gmail.com wrote: > Hello, folks! > I use mechanize.clientform to parse HTML-forms. I preliminary check > response and call response.read().find("..."). But when it's taken to > ClientForm.ParseResponse, it can't parse because of response.read() is > zero-length text. The problem is that ClientForm.ParseResponse is not > taken text of response, only object. > > Example: > > import urllib > from ClientForm import ParseResponse > response = urllib.urlopen("http://yandex.ru") > if -1 != response.read().find("foobar"): > pass > form = ParseResponse(response)[1] <-- there is exception IndexError > It might be that read() is consuming the data, so there's none remaining for the second read(). Try: response = urllib.urlopen("http://yandex.ru") text = response.read() if "foobar" in text: # preferred to find() pass form = ParseResponse(text)[1] From stefan_ml at behnel.de Wed Jan 7 14:22:36 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Jan 2009 20:22:36 +0100 Subject: Any news on when some libraries will be ported to Python 3.0? In-Reply-To: References: Message-ID: <496500fd$0$32663$9b4e6d93@newsspool2.arcor-online.net> Just Another Victim of the Ambient Morality wrote: > I'm excited to use Python 3.0 (foolishly, it's the only Python > interpreter I have on my system) but there are no libraries for it beyond > the kitchen sink. Personally, a good start would be Beautiful Soup and > Mechanize. I could also use DB. > Has there been any word on Beautiful Soup? At least for new code, you can use lxml instead. Being written (mostly) in Cython, it compiles and works in Py3. Stefan From Scott.Daniels at Acm.Org Wed Jan 7 14:23:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 11:23:32 -0800 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Ross wrote: > There seems to be no shortage of information around on how to use the > time module, for example to use time.ctime() and push it into strftime > and get something nice out the other side, but I haven't found anything > helpful in going the other way. As to a paucity of conversion formatting, there is no magic way to take everyone's way of putting date and time information in text and convert it to unambiguous format, in part because there are too many different and contradictory formats. When I write dates, I know what I intended; when I read dates, I guess what the author intended. Have you read the entire time module document? If so, which functions in that module take strings as arguments? > That is, given some formatted text describing times - is there something > that makes it easy to calculate time differences, or do I have to index > my way through the string pulling out characters, converting to integers > etc... > > Data is formatted: > t1 = 09:12:10 > t2 = 11:22:14 > I want to calculate tdiff = t2-t1 Do you do any work yourself? Show us your attempts. This looks like a trivial exercise. It seems that for less than four times the effort of asking your question you might have found the answer. Perhaps I am being too cranky this morning. --Scott David Daniels Scott.Daniels at Acm.Org From excord80 at gmail.com Wed Jan 7 14:31:23 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 11:31:23 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? Message-ID: Does Python work with Tk 8.5? I'm manually installing my own Python 2.6.1 (separate from my system's Python 2.5.2), and am about to install my own Tcl/Tk 8.5 but am unsure how to make them talk to eachother. Should I install Tk first? If I put Tk into my home directory (under "~/opt" most likely), is there some configure option I need to pass Python to tell it where to find my Tk? Also, I see that Python comes with Tix. Was Tix supposed to be something to make up for what was lacking in Tk prior to its 8.5 release? Is Tix here to stay, or has it been eclipsed by what comes with Tk 8.5 OOTB? From esnow at verio.net Wed Jan 7 14:39:13 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:39:13 -0800 (PST) Subject: del behavior Message-ID: I was reading in the documentation about __del__ and have a couple of questions. Here is what I was looking at: http://docs.python.org/reference/datamodel.html#object.__del__ What is globals referring to in the following text from that reference page? "Starting with version 1.5, Python guarantees that globals whose name begins with a single underscore are deleted from their module before other globals are deleted; if no other references to such globals exist, this may help in assuring that imported modules are still available at the time when the __del__() method is called." Thus those with an _ get deleted before everything else. This is not referring to members of my objects is it, such that those members starting with _ get deleted first? I suppose that would delete __del__ before it would get called so I assume that is not the case. But I want to be sure about that behavior and exactly what globals is. Is globals meaning the contents of "globals" or something else. I ask because sometimes some words get used for varied meanings. From ahill21programming at gmail.com Wed Jan 7 14:41:58 2009 From: ahill21programming at gmail.com (Aaron Hill) Date: Wed, 7 Jan 2009 12:41:58 -0700 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: <1e38ae490901071141y72840b9u6ba0054f699034a0@mail.gmail.com> I personally use epoch time since its absolute. I have a simple time clock app that uses this method, from that it is easy to convert into human date: [code] def OnButtonIn(self,evt): 'create time stamp with ID/action' 'print to the rightFrame text' if self.punchedIn: print "Already punched in cannot punch again" else: seconds = time.time() current = time.localtime(seconds) day = time.localtime() # time string can have characters 0..9, -, period, or space timeday = time.strftime('%H:%M-%m.%d.%y', day) formatday = time.strftime('%c', day) self.ClockIntext = seconds #self.text = "Clock in: " + self.text self.punchIn.SetValue(formatday) self.punchedIn = True self.punchedOut = False def OnButtonOut(self,evt): if self.punchedOut: print "Already punched out!" else: 'create time stamp with ID/action' 'print to the rightFrame text' 'write to time sheet' seconds = time.time() current = time.localtime(seconds) day = time.localtime() # time string can have characters 0..9, -, period, or space timeday = time.strftime('%H:%M-%m.%d.%y', day) formatday = time.strftime('%c', day) self.ClockOuttext = seconds self.punchOut.SetValue(formatday) self.punchedIn = False self.punchedOut = True 'create a file and write the table to it' file = open('timesheet.txt', 'a') file.write(str(self.ClockIntext)) file.write('\t') file.write(str(self.ClockOuttext)) file.write('\n') file.close() return None def OnButtonCalc(self,event): 'open the time sheet and calculate the total time' file = open('timesheet.txt','r') lines = file.readlines() time1 = '' time2 = '' self.hours = 0.000 for punch in lines: for x in punch: if(len(x) <= 0): self.hours = self.hours else: if x != '\t' and x!= '\n': time1 = time1 + x elif x == '\t': time2 = time1 time1 = '' elif x == '\n': self.hours = self.hours + abs(((float(time2)-float(time1))/60)/60) time2 = '' time1 = '' self.total.SetValue('%2f' % self.hours) [/code] Oops wrong person, sorry about that. This time it should go to the mailing list Aaron Hill -------------- next part -------------- An HTML attachment was scrubbed... URL: From esnow at verio.net Wed Jan 7 14:42:43 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:42:43 -0800 (PST) Subject: del behavior 2 Message-ID: I was reading in the documentation about __del__ and have a couple of questions. Here is what I was looking at: http://docs.python.org/reference/datamodel.html#object.__del__ My second question is about the following: "It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits." I understand that and have seen it too. That's fine. But how do any of you deal with things that are left open because you did not get a chance to close them? How do you clean up after the fact? Do you simply keep track externally the things that need to be cleaned up if __del__ doesn't get a chance? Any ideas? Thanks -eric From clp2 at rebertia.com Wed Jan 7 14:48:06 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 11:48:06 -0800 Subject: del behavior In-Reply-To: References: Message-ID: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > What is globals referring to in the following text from that reference > page? Globals are variables that have toplevel module scope. Basically, any assignments, function definitions, or class definitions with no indentation from the left margin will create a global variable. If you can get at the variable by appending something of the form "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in function, then it's a global. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From esnow at verio.net Wed Jan 7 14:55:28 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:55:28 -0800 (PST) Subject: del behavior References: Message-ID: On Jan 7, 12:48?pm, "Chris Rebert" wrote: > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > > I was reading in the documentation about __del__ and have a couple of > > questions. ?Here is what I was looking at: > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > What is globals referring to in the following text from that reference > > page? > > Globals are variables that have toplevel module scope. Basically, any > assignments, function definitions, or class definitions with no > indentation from the left margin will create a global variable. If you > can get at the variable by appending something of the form > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > function, then it's a global. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Perfect! that is kind of what I thought. Thanks. So any such in any module every variable in memory that starts with an underscore will be deleted before the rest. Then this does not affect the order in which variables are deleted in instances of my classes, and thus all my class and instance variables (including methods) are available when the __del__ of the class instance is called? -eric From google at mrabarnett.plus.com Wed Jan 7 14:55:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 19:55:40 +0000 Subject: del behavior 2 In-Reply-To: References: Message-ID: <496508BC.7080607@mrabarnett.plus.com> Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks > There's the 'with' statement and try...finally. From clp2 at rebertia.com Wed Jan 7 14:57:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 11:57:00 -0800 Subject: del behavior 2 In-Reply-To: References: Message-ID: <50697b2c0901071157n12aa1b1fi92baef5792d268ec@mail.gmail.com> On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks As you point out, __del__ is not a reliable way to free limited resources. Instead, one generally includes logic to explicitly free the resources. This is generally done using try-finally or the `with` statement. Example: def mess_with_file(f): try: #fiddle with the file finally: f.close() #guarantee that the file gets closed def mess_with_other_file(filename): with open(filename) as f: #do stuff with file x = None #the file has now been closed, and it'll be closed even if an exception gets raised #the "context handler" (see PEP 343) for the `file` type guarantees this for us Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From esnow at verio.net Wed Jan 7 14:57:41 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 11:57:41 -0800 (PST) Subject: del behavior References: Message-ID: On Jan 7, 12:55?pm, Eric Snow wrote: > On Jan 7, 12:48?pm, "Chris Rebert" wrote: > > > > > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: > > > I was reading in the documentation about __del__ and have a couple of > > > questions. ?Here is what I was looking at: > > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > > What is globals referring to in the following text from that reference > > > page? > > > Globals are variables that have toplevel module scope. Basically, any > > assignments, function definitions, or class definitions with no > > indentation from the left margin will create a global variable. If you > > can get at the variable by appending something of the form > > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > > function, then it's a global. > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Perfect! ?that is kind of what I thought. ?Thanks. > > So any such in any module every variable in memory that starts with an > underscore will be deleted before the rest. ?Then this does not affect > the order in which variables are deleted in instances of my classes, > and thus all my class and instance variables (including methods) are > available when the __del__ of the class instance is called? > > -eric Typo. Perfect! that is kind of what I thought. Thanks. So in any module every such variable in memory that starts with an underscore will be deleted before the rest. Then this does not affect the order in which variables are deleted in instances of my classes, and thus all my class and instance variables (including methods) are available when the __del__ of the class instance is called? -eric From martin at v.loewis.de Wed Jan 7 14:59:20 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 20:59:20 +0100 Subject: del behavior 2 In-Reply-To: References: Message-ID: <49650999$0$22775$9b622d9e@news.freenet.de> > I understand that and have seen it too. That's fine. But how do any > of you deal with things that are left open because you did not get a > chance to close them? How do you clean up after the fact? Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? Any ideas? Thanks You should try to write you program so that any kind of process exit will not need any cleanup. For many kinds of things, this will work automatically on most file systems. For example, file handles and network connections get automatically closed - so you don't absolutely have to close them if your program exits abnormally. Likewise, database connections will shut down properly, and windows will close just fine. What kind of thing do you have that remains open even after the process terminates? Regards, Martin From esnow at verio.net Wed Jan 7 15:03:36 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 12:03:36 -0800 (PST) Subject: del behavior 2 References: Message-ID: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> On Jan 7, 12:57?pm, "Chris Rebert" wrote: > On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > > I was reading in the documentation about __del__ and have a couple of > > questions. ?Here is what I was looking at: > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > My second question is about the following: > > > "It is not guaranteed that __del__() methods are called for objects > > that still exist when the interpreter exits." > > > I understand that and have seen it too. ?That's fine. ?But how do any > > of you deal with things that are left open because you did not get a > > chance to close them? ?How do you clean up after the fact? ?Do you > > simply keep track externally the things that need to be cleaned up if > > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > As you point out, __del__ is not a reliable way to free limited > resources. Instead, one generally includes logic to explicitly free > the resources. This is generally done using try-finally or the `with` > statement. > > Example: > > def mess_with_file(f): > ? ? try: > ? ? ? ? #fiddle with the file > ? ? finally: > ? ? ? ? f.close() #guarantee that the file gets closed > > def mess_with_other_file(filename): > ? ? with open(filename) as f: > ? ? ? ? #do stuff with file > ? ? x = None #the file has now been closed, and it'll be closed even > if an exception gets raised > ? ? #the "context handler" (see PEP 343) for the `file` type > guarantees this for us > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanks for the responses. What I mean is when a python process is interrupted and does not get a chance to clean everything up then what is a good way to do so? For instance, I have a script that uses child ptys to facilitate ssh connections (I'm using pxssh). When I ^C the python process I am left with the child processes running and the ssh connections open. Naturally I run out of ttys if this happens too much, which I have had happen. So if python does not get a chance to take care of those, what is a good way to do so? Does a try/finally or a with statement address that? Thanks! -eric From esnow at verio.net Wed Jan 7 15:04:35 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 12:04:35 -0800 (PST) Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <52a6e7f5-5a0e-4760-8afc-a73da250aee0@40g2000prx.googlegroups.com> On Jan 7, 1:03?pm, Eric Snow wrote: > On Jan 7, 12:57?pm, "Chris Rebert" wrote: > > > > > On Wed, Jan 7, 2009 at 11:42 AM, Eric Snow wrote: > > > I was reading in the documentation about __del__ and have a couple of > > > questions. ?Here is what I was looking at: > > > >http://docs.python.org/reference/datamodel.html#object.__del__ > > > > My second question is about the following: > > > > "It is not guaranteed that __del__() methods are called for objects > > > that still exist when the interpreter exits." > > > > I understand that and have seen it too. ?That's fine. ?But how do any > > > of you deal with things that are left open because you did not get a > > > chance to close them? ?How do you clean up after the fact? ?Do you > > > simply keep track externally the things that need to be cleaned up if > > > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > > As you point out, __del__ is not a reliable way to free limited > > resources. Instead, one generally includes logic to explicitly free > > the resources. This is generally done using try-finally or the `with` > > statement. > > > Example: > > > def mess_with_file(f): > > ? ? try: > > ? ? ? ? #fiddle with the file > > ? ? finally: > > ? ? ? ? f.close() #guarantee that the file gets closed > > > def mess_with_other_file(filename): > > ? ? with open(filename) as f: > > ? ? ? ? #do stuff with file > > ? ? x = None #the file has now been closed, and it'll be closed even > > if an exception gets raised > > ? ? #the "context handler" (see PEP 343) for the `file` type > > guarantees this for us > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Thanks for the responses. ?What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? ?For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). ?When I ^C the > python process I am left with the child processes running and the ssh > connections open. ?Naturally I run out of ttys if this happens too > much, which I have had happen. ?So if python does not get a chance to > take care of those, what is a good way to do so? ?Does a try/finally > or a with statement address that? ?Thanks! > > -eric pxssh uses pexpect which uses pty.fork From clp2 at rebertia.com Wed Jan 7 15:05:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 12:05:30 -0800 Subject: del behavior In-Reply-To: References: Message-ID: <50697b2c0901071205t67ed8b9bna7d39859ea907141@mail.gmail.com> On Wed, Jan 7, 2009 at 11:55 AM, Eric Snow wrote: > On Jan 7, 12:48 pm, "Chris Rebert" wrote: >> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >> > I was reading in the documentation about __del__ and have a couple of >> > questions. Here is what I was looking at: >> >> >http://docs.python.org/reference/datamodel.html#object.__del__ >> >> > What is globals referring to in the following text from that reference >> > page? >> >> Globals are variables that have toplevel module scope. Basically, any >> assignments, function definitions, or class definitions with no >> indentation from the left margin will create a global variable. If you >> can get at the variable by appending something of the form >> "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in >> function, then it's a global. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana...http://rebertia.com > > Perfect! that is kind of what I thought. Thanks. > > So any such in any module every variable in memory that starts with an > underscore will be deleted before the rest. Then this does not affect > the order in which variables are deleted in instances of my classes, > and thus all my class and instance variables (including methods) are > available when the __del__ of the class instance is called? Indeed. The underscore special-casing only applies to modules. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From google at mrabarnett.plus.com Wed Jan 7 15:05:33 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 20:05:33 +0000 Subject: del behavior In-Reply-To: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> References: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> Message-ID: <49650B0D.1080707@mrabarnett.plus.com> Chris Rebert wrote: > On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >> I was reading in the documentation about __del__ and have a couple of >> questions. Here is what I was looking at: >> >> http://docs.python.org/reference/datamodel.html#object.__del__ >> >> What is globals referring to in the following text from that reference >> page? > > Globals are variables that have toplevel module scope. Basically, any > assignments, function definitions, or class definitions with no > indentation from the left margin will create a global variable. If you > can get at the variable by appending something of the form > "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in > function, then it's a global. > Actually, the amount of indentation doesn't matter. What matters is whether it's within a 'def' or 'class' statement or not. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 7 15:15:20 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 07 Jan 2009 21:15:20 +0100 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <49651b04$0$24804$426a74cc@news.free.fr> Adal Chiriliuc a ?crit : > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? This kind of typechecking is usually considered bad practice in Python, but well, practicallity beats purity - and as a matter of fact, if you refer to list.sort, passing a non-integer value as the 'reverse' argument raises a TypeError... This being said, I can only concur with other posters here about the very poor naming. As far as I'm concerned, I'd either keep the argument as a boolean but rename it "ascending" (and use a default True value), or keep the 'order' name but then accept 'asc' and 'desc' as values ('asc' being the default). My 2 cents... From clp2 at rebertia.com Wed Jan 7 15:15:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jan 2009 12:15:21 -0800 Subject: del behavior In-Reply-To: <49650B0D.1080707@mrabarnett.plus.com> References: <50697b2c0901071148s4ada07e6uee42b9d77fe070fc@mail.gmail.com> <49650B0D.1080707@mrabarnett.plus.com> Message-ID: <50697b2c0901071215n78803232of12e274ea96f3e7a@mail.gmail.com> On Wed, Jan 7, 2009 at 12:05 PM, MRAB wrote: > Chris Rebert wrote: >> >> On Wed, Jan 7, 2009 at 11:39 AM, Eric Snow wrote: >>> >>> I was reading in the documentation about __del__ and have a couple of >>> questions. Here is what I was looking at: >>> >>> http://docs.python.org/reference/datamodel.html#object.__del__ >>> >>> What is globals referring to in the following text from that reference >>> page? >> >> Globals are variables that have toplevel module scope. Basically, any >> assignments, function definitions, or class definitions with no >> indentation from the left margin will create a global variable. If you >> can get at the variable by appending something of the form >> "\nSomeIdentifierHere\n" to the module's file, and it's not a built-in >> function, then it's a global. >> > Actually, the amount of indentation doesn't matter. What matters is whether > it's within a 'def' or 'class' statement or not. Yes, but those do require you *to indent* (though so do while & if for that matter); I just couldn't seem to come up with a better description of the rule at the time. But you are correct and yours is a much better description of the rule. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rdcollum at gmail.com Wed Jan 7 15:31:09 2009 From: rdcollum at gmail.com (Roger) Date: Wed, 7 Jan 2009 12:31:09 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: <330a26a3-860a-4c0e-82a3-831417472310@j39g2000yqn.googlegroups.com> On Jan 7, 2:31?pm, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? > > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? I'm curious about this too. If no one responds please let us know how it goes. From lkcl at lkcl.net Wed Jan 7 15:40:23 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 7 Jan 2009 20:40:23 +0000 Subject: compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Sat, Jan 3, 2009 at 9:22 PM, Luke Kenneth Casson Leighton wrote: > hey, has anyone investigated compiling python2.5 using winegcc, under wine? some people might find this kind of thing amusing. it's considered in very obtuse circles to be "progress"... :) lkcl at gonzalez:/mnt/src/python2.5-2.5.2/Lib$ ../build/python -v Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] # installing zipimport hook import zipimport # builtin # installed zipimport hook 'import site' failed; traceback: ImportError: No module named site Python 2.5.2 (r252:60911, Jan 7 2009, 20:33:53) [gcc] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import site fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored [....] [....] [....] import sre_compile # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.py fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.pyc import _sre # builtin import sre_constants # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_constants.py # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_constants.pyc import sre_parse # from Z:\mnt\src\python2.5-2.5.2\Lib\sre_parse.py # wrote Z:\mnt\src\python2.5-2.5.2\Lib\sre_parse.pyc Traceback (most recent call last): File "", line 1, in File "site.py", line 415, in main() File "site.py", line 406, in main aliasmbcs() File "site.py", line 356, in aliasmbcs import locale, codecs File "Z:\mnt\src\python2.5-2.5.2\Lib\locale.py", line 167, in import re, operator File "Z:\mnt\src\python2.5-2.5.2\Lib\re.py", line 223, in _pattern_type = type(sre_compile.compile("", 0)) File "Z:\mnt\src\python2.5-2.5.2\Lib\sre_compile.py", line 530, in compile groupindex, indexgroup OverflowError: signed integer is less than minimum >>> From bdesth.quelquechose at free.quelquepart.fr Wed Jan 7 15:41:55 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 07 Jan 2009 21:41:55 +0100 Subject: Creating new instances of subclasses. In-Reply-To: References: Message-ID: <49652140$0$29486$426a34cc@news.free.fr> J. Cliff Dyer a ?crit : > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > >>>> f1 = Field('abc') >>>> f2 = Field('123') >>>> f3 = Field('D,E,F') >>>> f1.data > 'abc' >>>> f2.data > 123 >>>> f3.data > ['D','E','F'] >>>> type(f1) > >>>> type(f2) > >>>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. Not only that, but the base class should know nothing of its subclasses. As Paul suggested, a better solution would be to make Field a factory function (and rename the Field class to BaseField). Also and FWIW, since your Field subclasses are responsible for doing the conversion, you could as well use this to find out the concrete class to use for a given value, ie (not tested): class Field(object): __classes = [] __default = None @classmethod def register(cls, subclass, is_default=False): if is_default: if cls.__default is not None: raise WhateverError("only one default subclass, thanks") cls.__default = subclass cls.__classes.append(subclass) def __new__(cls, value): for subclass in cls.__classes: try: return subclass(value) except (TypeError, ValueError): continue if cls.__default is not None: return cls.__default(value) raise ValueError("no appropriate subclass for '%s'" % value) class BaseField(object): # common code here class FloatField(BaseField): def __init__(self, value): self.value = float(value) Field.register(FloatField) class ListField(BaseField): def __init__(self, value): if "," in value: self.value = value.split(",") raise ValueError("could not convert '%s' to a list" % value) Field.register(ListField) class IntegerField(BaseField): def __init__(self, value): self.value = int(value) Field.register(IntegerField) class StringField(self, value): def __init__(self, value): self.value = str(value) Field.register(StringField, is_default=True) Now this may just be overkill for your needs - I don't have enough context to know !-) From rolf.oltmans at gmail.com Wed Jan 7 15:42:21 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Wed, 7 Jan 2009 12:42:21 -0800 (PST) Subject: How to store passwords? Message-ID: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> I'm writing a program in which I will ask users to enter user name and password once only. It's a console based program that will run on Windows XP. Actually, I'm trying to provide the similar functionality as "Remember me" thing in browsers. For that, I will need to store user name and passwords on the disk. I don't have a background in Crypto so how do you suggest I do that? What algorithms shall I be using? Moreover, I cannot use a whole library to do that due to certain issues. However, I can use like 1--2 files that will be shipped along with the main script. Any ideas? Any help will be really appreciated. Thanks. From james at agentultra.com Wed Jan 7 15:50:10 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 07 Jan 2009 15:50:10 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <85ocyivo1p.fsf@dozer.localdomain> Kay Schluehr writes: > On 7 Jan., 16:50, J Kenneth King wrote: > >> Python expressions are not >> data types either and hence no macros -- I can't write a python function >> that generates python code at compile time. > > Have you ever considered there are languages providing macros other > than Lisp? Of course. > Macros have nothing to do with homoiconcity. Not directly, no. >> I can only write a python >> program that parses some other string and generates code that can be run >> by another interpreter. > > No, it is the same interpreter and it is also possible to modify > python parsers on the fly. This is just not possible with Pythons > builtin parser. PyPy is probably the best bet when/if it gets finished. > > >> >> Consider: >> >> for i in range(0, 100): >> ? ? do_something_interesting(i) >> >> That's a pretty straight forward Python expression, but I can't do >> anything with it -- it's not a unit of data, it's a string. >> >> The distinction is not subtle by any means. From daniel.a.esch at gmail.com Wed Jan 7 15:53:13 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Wed, 7 Jan 2009 15:53:13 -0500 Subject: why cannot assign to function call In-Reply-To: <20090102103915.GJ28417@dragontoe.org> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Wait a sec... I think I get this... In essence, the implication of immutability for Python is that there is only one "parrot", one "spam,"in fact one anything. (This seems like it must hold for data primitives - does it hold for complex objects as well? It seems it must...) In addition there is only one 1, and one 2 etc. We may or may not have realized that string in a memory address to which variable names can be bound, but should we do so, there is only one "parrot" Python, is in fact, a Platonic programming language. Weird. If I've got this right, worth chewing on.... On 1/2/09, Derek Martin wrote: > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > Fortunately, unlike the murky world of philosophy, Python (AIUI) > > simplifies this question by simply declaring that yes, in the case > > of mutable objects, we may say that we are still referring to the > > same object although we've changed it, and no, in the case of > > immutable objects, we may not, and must exchange it if we want a > > different "value" (a word too fraught with ambiguity in this context > > to use unquoted!). > > That's sort of true; it would seem to be more accurate to say that > whenever a name is assigned to an object and subsequently reassigned, > the name no longer is associated with the original object. In the > case of mutable objects, the object can be changed by performing an > assignment of *part* of the object through its original name, i.e. > strings may be mutable, but the following code still produces two > different objects: > > a = 'hello' > a = 'goodbye' > > The first object so created is orphaned; it's been given the Russian > non-person treatment. It still exists, but the authorities (i.e. the > python interpreter) don't acknowledge it and provide the rest of the > world no way to communicate with it, and eventually it is reaped by > the garbage collector. :) > > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that > its assignment model is BIZARRE, as in it's conceptually different > from virtually all other languages substantially taught in > undergraduate computer science programs. And for that matter, it's > pretty unintuitive generally. > > That is, in what I'll call "normal" computer languages, a variable > name is thought of as the address of a bin where some data is stored, > and the name is inexorably tied to that bin. You can change what's in > the bin, but the name you gave the bin always points to the same bin. > This tends to be conceptually true even if it might technically not be > true in a given implementation of a language. > > Python is very different from this. Names are not addresses of bins; > they are instead simply ephemeral labels which are given to bins, > where the bin is a Python object which contains specific data at the > time of assignment. A second assignment of that name doesn't change > what's in the original bin; it actually (probably) first creates a new > bin, then removes the name from the original bin and assigns it to > the new one. Intuitively, it's a bit like saying your kitchen table > is no longer a kitchen table, and now the thing where you wash your > dishes is a kitchen table. It doesn't really make a lot of sense > (whether or not it's so for good reason), and it makes describing the > assignment model necessarily convoluted, whereas the "named bins" > model from the majority of other languages people are likely to have > been exposed to is simple and sensible. > > It's small wonder that neophytes try to cram Python behaviors into > terms and computing concepts they already understand from learning > other languages, and that they fail to do so. What's mystifying is > that when Pythonistas reply to their messages, they universally seem > confused at how this could possibly happen, and often enough actually > seem offended (or at least offensive) when it inevitably does happen... > > -- > Derek D. Martin > http://www.pizzashack.org/ > GPG Key ID: 0x81CFE75D > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From casey.mcginty at gmail.com Wed Jan 7 15:53:56 2009 From: casey.mcginty at gmail.com (Casey McGinty) Date: Wed, 7 Jan 2009 10:53:56 -1000 Subject: Free place to host python files? In-Reply-To: <4948E346.7090009@mattnordhoff.com> References: <7f3baaf3-6116-4a7a-8181-6f88b0e44950@w24g2000prd.googlegroups.com> <47c890dc0812161625o76f5c7e6lb8809b99f6962d32@mail.gmail.com> <4948E346.7090009@mattnordhoff.com> Message-ID: Check out nearlyfreespeech.net for a free account. You could store hundreds of scripts on there for about 12 cents a year. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sbassi at clubdelarazon.org Wed Jan 7 15:55:29 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 7 Jan 2009 18:55:29 -0200 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <9e2f512b0901071255q523ada4p84a1b4e72e68003a@mail.gmail.com> On Wed, Jan 7, 2009 at 6:42 PM, Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on In general you don't store the password, but a "hash" of it. Then when the user logs-in, you hash it and compare the result with the stored hash. About hash, use sha, look here: http://docs.python.org/library/hashlib.html#module-hashlib > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in I don't understand how this is supposed to work. "Remember me" in browser doesn't store passwords. > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. The library I pointed out before is built-in. Best, SB. -- Sebasti?n Bassi. Diplomado en Ciencia y Tecnolog?a. Book: Python for bioinformatics. http://tinyurl.com/biopython Vendo isla: http://www.genesdigitales.com/isla What's new in Python 3: http://tinyurl.com/5cd89r Curso Biologia molecular para programadores: http://tinyurl.com/2vv8w6 From jakecjacobson at gmail.com Wed Jan 7 15:56:58 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Wed, 7 Jan 2009 12:56:58 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> Message-ID: <341b04d3-10be-4a29-b170-fd6ec3a2be51@k8g2000yqn.googlegroups.com> On Jan 7, 2:11?pm, jakecjacobson wrote: > On Jan 7, 12:32?pm, jakecjacobson wrote: > > > Hi, > > > I need to write a simple Python script that I can connect to a FTP > > server and download files from the server to my local box. ?I am > > required to go through a FTP Proxy and I don't see any examples on how > > to do this. ?The FTP proxy doesn't require username or password to > > connect but the FTP server that I am connecting to does. > > > Any examples on how to do this would be greatly appreciated. ?I am > > limited to using Python version 2.4.3 on a Linux box. > > This is what I have tried so far, > > import urllib > > proxies = {'ftp':'ftp://proxy_server:21'} > ftp_server = 'ftp.somecompany.com' > ftp_port='21' > username = 'aaaa' > password = 'secretPW' > > ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + > ftp_port > > data = urllib.urlopen(ftp_string, proxies=proxies) > > data=urllib.urlopen(req).read() > > print data > > I get the following error: > > Traceback (most recent call last): > ? File "./ftptest.py", line 22, in ? > ? ? data = urllib.urlopen(ftp_server, proxies=proxies) > ? File "/usr/lib/python2.4/urllib.py", line 82, in urlopen > ? ? return opener.open(url) > ? File "/usr/lib/python2.4/urllib.py", line 190, in open > ? ? return getattr(self, name)(url) > ? File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp > ? ? host, path = splithost(url) > ? File "/usr/lib/python2.4/urllib.py", line 949, in splithost > ? ? match = _hostprog.match(url) > TypeError: expected string or buffer I might be getting closer. Now I am getting "I/O error(ftp error): (111, 'Connection refused')" error with the following code: import urllib2 proxies = {'ftp':'ftp://proxy_server:21'} ftp_server = 'ftp.somecompany.com' ftp_port='21' username = 'aaaa' password = 'secretPW' password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() top_level_url = ftp_server password_mgr.add_password(None, top_level_url, username, password) proxy_support = urllib2.ProxyHandler(proxies) handler = urllib2.HTTPBasicAuthHandler(password_mgr) opener = urllib2.build_opener(proxy_support) opener = urllib2.build_opener(handler) a_url = 'ftp://' + ftp_server + ':' + ftp_port + '/' print a_url try: data = opener.open(a_url) print data except IOError, (errno, strerror): print "I/O error(%s): %s" % (errno, strerror) From floob.spam at gmail.com Wed Jan 7 16:00:48 2009 From: floob.spam at gmail.com (floob) Date: Wed, 7 Jan 2009 13:00:48 -0800 (PST) Subject: Printed Documentation Message-ID: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> I have been searching for a way to print the official Python documentation into some kind of book (for my own uses). I don't really care if it's printed on newspaper and bound with elmer's glue ... any way I can get relatively recent _official documentation_ in print form will do. I'm on the go a lot, and can't read for long periods of time on LCD screens anyhow (so having a laptop is not my solution). Until eBook readers grow up a bit, I'm stuck trying to print the documentation that I REALLY need to read and absorb. Lulu.com is an option, but it would cost something around $100 US before shipping to get everything printed. Also, I would have to split up some larger documents into Volumes, which I'd rather not have to do. Has anyone tried this before? Is the documentation already available in print? Thanks, drfloob From rolf.oltmans at gmail.com Wed Jan 7 16:06:07 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Wed, 7 Jan 2009 13:06:07 -0800 (PST) Subject: How to store passwords? References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> On Jan 8, 1:55 am, "Sebastian Bassi" wrote: > In general you don't store the password, but a "hash" of it. Then when > the user logs-in, you hash it and compare the result with the stored > hash. > About hash, use sha, look here:http://docs.python.org/library/hashlib.html#module-hashlib But the thing is that I will ask the user for user name and password only once i.e. when they start the application for the first time. After that, I'm not supposed to ask the user name and password again. So in this scenario, if I store a hash on the disk I cannot retrieve plain-text string back from my hash as I've to send user name and password to the server in plain-text. From jstroud at mbi.ucla.edu Wed Jan 7 16:10:54 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 13:10:54 -0800 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? What algorithms shall I be > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. There is a pure python implementation of blowfish out there. Google will help you. I can't remember which, if any, types of block chaining it supports. In some cases, it is important to use a block chaining protocol, but for passwords with high entropy (ie good passwords), block chaining is not really necessary. 256 bit Blowfish or AES are adequate for storage of sensitive passwords. You would be well advised to read a manual like Schneier before you use cryptography for sensitive applications. Pitfalls exist even when you use a strong algorithm and think you know what you are doing. Stay away from stream ciphers. They are easy to screw up. Don't attempt to use DES, etc., for this either, they are not secure enough. Don't pretend that you can invent your own cipher either just in case the thought might cross your mind. Google "adacrypt" for some hilarity in this area. If you check out sf.passerby.net and download the source, you will see a pure python module in there called jenncrypt which can help with buffering and has minimal fileIO type emulation for block ciphers, which you will appreciate when you try to use your block cipher for plaintexts of irregular sizes. James From jstroud at mbi.ucla.edu Wed Jan 7 16:12:43 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 13:12:43 -0800 Subject: How to store passwords? In-Reply-To: References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: James Stroud wrote: > Oltmans wrote: >> I'm writing a program in which I will ask users to enter user name and >> password once only. It's a console based program that will run on >> Windows XP. Actually, I'm trying to provide the similar functionality >> as "Remember me" thing in browsers. For that, I will need to store >> user name and passwords on the disk. I don't have a background in >> Crypto so how do you suggest I do that? What algorithms shall I be >> using? Moreover, I cannot use a whole library to do that due to >> certain issues. However, I can use like 1--2 files that will be >> shipped along with the main script. Any ideas? Any help will be really >> appreciated. Thanks. > > There is a pure python implementation of blowfish out there. Google will > help you. I can't remember which, if any, types of block chaining it > supports. In some cases, it is important to use a block chaining > protocol, but for passwords with high entropy (ie good passwords), block > chaining is not really necessary. > > 256 bit Blowfish or AES are adequate for storage of sensitive passwords. > You would be well advised to read a manual like Schneier before you use > cryptography for sensitive applications. Pitfalls exist even when you > use a strong algorithm and think you know what you are doing. Stay away > from stream ciphers. They are easy to screw up. > > Don't attempt to use DES, etc., for this either, they are not secure > enough. Don't pretend that you can invent your own cipher either just in > case the thought might cross your mind. Google "adacrypt" for some > hilarity in this area. > > If you check out sf.passerby.net and download the source, you will see a > pure python module in there called jenncrypt which can help with > buffering and has minimal fileIO type emulation for block ciphers, which > you will appreciate when you try to use your block cipher for plaintexts > of irregular sizes. > > James Before anyone jumps me, I just realized the point is authentication. Use a hash as others have suggested. James From sjmachin at lexicon.net Wed Jan 7 16:14:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 7 Jan 2009 13:14:17 -0800 (PST) Subject: formatted 'time' data in calculations References: Message-ID: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> On Jan 8, 6:23?am, Scott David Daniels wrote: > Ross wrote: > > There seems to be no shortage of information around on how to use the > > time module, for example to use time.ctime() and push it into strftime > > and get something nice out the other side, but I haven't found anything > > helpful in going the other way. > > As to a paucity of conversion formatting, there is no magic way to take > everyone's way of putting date and time information in text and convert > it to unambiguous format, in part because there are too many different > and contradictory formats. ?When I write dates, I know what I intended; > when I read dates, I guess what the author intended. > > Have you read the entire time module document? ?If so, which functions > in that module take strings as arguments? > > > That is, given some formatted text describing times - is there something > > that makes it easy to calculate time differences, or do I have to index > > my way through the string pulling out characters, converting to integers > > etc... > > > Data is formatted: > > ? ?t1 = 09:12:10 > > ? ?t2 = 11:22:14 > > I want to calculate tdiff = t2-t1 > > Do you do any work yourself? ?Show us your attempts. ?This looks like > a trivial exercise. ?It seems that for less than four times the effort > of asking your question you might have found the answer. > > Perhaps I am being too cranky this morning. Indeed. Be not cranky at clueless bludgers and cargo-cultists lest they rise high in the serried ranks of IT management and remember your name inclusive-or the net-nannies sally forth and wallop thee with a balloon on a stick. To the OP: Your Lordship did not specify whether output should be expressed in hours and a fraction, or in hours, minutes, and seconds. So that the eminent one may avoid having to make a decision in public, I humbly submit answers to both possibilities: >>> t1 = "09:12:10" >>> t2 = "11:22:14" >>> sum((a - b) / c for (a, b, c) in zip(map(int, t2.split(":")), map(int,t1.split(":")), (1., 60., 3600.))) 2.1677777777777778 >>> def tdiff(t1, t2): ... h, m, s = [a - b for (a, b) in zip(map(int, t2.split(":")), map (int,t1.split(":")))] ... if s < 0: ... s += 60 ... m -= 1 ... if m < 0: ... m += 60 ... h -= 1 ... return h, m, s ... >>> tdiff(t1, t2) (2, 10, 4) >>> tdiff('09:12:10', '10:11:09') (0, 58, 59) HTH, John From pavlovevidence at gmail.com Wed Jan 7 16:29:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jan 2009 13:29:08 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: Message-ID: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> On Jan 6, 9:32?am, mark wrote: > I want to implement a internal DSL in Python. I would like the syntax > as human readable as possible. This means no disturbing '.;()\' > characters. I like to have the power of the hosting language as well. > Thats why I want to build it as an internal DSL and NOT as a external > DSL. > > I want the DSL as human readable as possible: > > open_browser > > navigate_to 'www.openstreetmap.org'website > > search 'Von-Gumppenberg-Strasse, Schmiechen' > > verify search_result > > zoom in In the Python grammar, there are no non-trivial situations where two expressions can be separated by whitespace and not punctuation. (The trivial exception is string concatentation.) String constants like 'www.openstreetmap.org' and identifiers like open_browser are expressions, and if you try to separate them with whitespace you get a syntax error. So you can't make an internal DSL like this that uses Python's built- in grammar. You'd have to hack the parser or settle for an external preprocessor. > Martin Fowler recommends "Method Chaining" to build internal DSLs: > > ?Browser("http://www.openstreetmap.org/") \ > ? ? ? ? .search("Von-Gumppenberg-Strasse, Schmiechen") \ > ? ? ? ? .zoom_in() > ?<<< > > I guess that it is possible to argue that this means the same. > Nevertheless I do not like all the parentheses and punctuation > necessary to satisfy the Python interpreter. > > The reason why I need this is that I want to have non technical people > review the files written in the DSL. > > I already know that there are parser frameworks available but I want > to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and > whatnot). > > How would one approach this in Python? Do I need to build a custom > loader which compiles *.dsl files to *.pyc files? Is it possible to > switch between the custom DSL and the standard Python interpreter? I don't know specifically what you mean my "custom loader", or "switching between the custom DSL and the standard Python interpreter". However, the gist of it seems to be that you want to be able to write files in your DSL that can be imported just like a regular Python module. Yes, that can be done. See PEP 302, Import Hooks: http://www.python.org/dev/peps/pep-0302/ Python's standard importer looks for files with *.py, *.pyc, *.pyd, or *.so extensions. You could write an importer that looks for *.dsl files, and, instead of loading it as a Python file, invokes your DSL parser. Carl Banks From bj_666 at gmx.net Wed Jan 7 16:30:52 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 21:30:52 GMT Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <6skl8cF6bhk2U4@mid.uni-berlin.de> On Wed, 07 Jan 2009 12:03:36 -0800, Eric Snow wrote: > Thanks for the responses. What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? Well, if it doesn't get a chance then it doesn't get a chance. ;-) > For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). When I ^C the > python process I am left with the child processes running and the ssh > connections open. Naturally I run out of ttys if this happens too much, > which I have had happen. So if python does not get a chance to take > care of those, what is a good way to do so? Does a try/finally or a > with statement address that? Thanks! If you clean up the mess in the ``finally`` branch: yes. + raises a `KeyboardInterrupt`. Ciao, Marc 'BlackJack' Rintsch From BrooklineTom at gmail.com Wed Jan 7 16:34:23 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Wed, 7 Jan 2009 13:34:23 -0800 (PST) Subject: Parsing Excel spreadsheets References: <6a54de23-bea4-40c7-ad7c-22c6eba4bd8a@z6g2000pre.googlegroups.com> <782c68cf-ce9d-4f32-8ea3-6d57257b1b54@x16g2000prn.googlegroups.com> Message-ID: <63505b1a-6cbf-48b6-953e-38c25c34dea0@n41g2000yqh.googlegroups.com> On Jan 2, 7:04 pm, John Machin wrote: > On Jan 3, 2:01 am, brooklineTom wrote: > > > > My point was that however the original XLS files were created or > acquired, the first step in your solution involves converting the XLS > file to "XML Spreadsheet" format, which requires a copy of Excel on a > Windows box. Many people start with an XLS file, no Excel and no > Windows box, no COM, and users who can't be relied on to open a file > and save it in the right format with the right name and extension. True enough. I develop on a WinXP box and have Excel. I just used it. > BTW, did you consider opening the XLS files with OpenOffice.org's Calc > and saving it in their default ods format (chunks of XML in a zip > file)? No. As I said, I have Excel. > > 3. The largest file I used was about 228M, > > Is that the XLS file or the XML file? That's the xml file size. I just *love* file-bloat, don't you? :-) > > > > > I knew that I needed only > > a small subset of the xlrd behavior, and I concluded (perhaps > > incorrectly) that it would be easier to roll my own parser than find, > > extract, and then port (to my own framework) the corresponding parts > > of xlrd. > > Possibly incorrectly. If approached at the time, I would have said: > (a) if desperate to DIY: > (a1) ignore any code for old Excel versions (self.biff_version < 80) > (a2) ignore any code for extracting formatting info > (self.formatting_info) > (a3) find the Sheet.put_cell* methods in sheet.py e.g. > > def put_cell(self, rowx, colx, ctype, value, xf_index): > > ignore the xf_index arg and subvert them to your own needs instead of > filling up a big rectangular arena with data > > (b) if not really so desperate, talk to me about implementing an > option in xlrd where callers can specify a callback to be used instead > of the Sheet.put_cell* methods > > (c) What is all this "port to my own framework" caper anyway? If you > need to extract data from a database, do you rummage in their code > libraries and port the relevant bits to your own framework? I'm sure xlrd is fine, I wasn't any way suggesting that any "improvements" are needed. I was just explaining what I did. > > > > "Crack"? It's not the Enigma code. It's not even rot13. Spreadsheet > XML tells you the type (String, Boolean, ...). xlrd tells you the type > (XL_CELL_TEXT, XL_CELL_BOOLEAN, ...). Sure, once you've sorted through the excess MS-specific stuff, dealt with the runs of empty cells, and so on. I needed to write an exception file, containing the original spreadsheet entries that failed, so that our curators could find and fix (or delete) them. Thus, I already had to do row-by-row handling of the input, I had to catch and handle exceptions, I had to know and remember enough about the original SS format/layout to replicate it in the exception file, and so on. > I think so. Thanks. You didn't directly address the "steep learning > curve" question, but you explained enough of where you came from. > > It's a matter of "horses for courses". I guess some people might > regard (xml.dom, xml.dom.minidom, DIY "pullparser") as having a > slightly non-horizontal learning curve :-) *LOL* Yes. Sadly, I had already climbed the dom/minidom/pullparser curve for all the other stuff I have to do. In the space I work in, xml handling is pervasive enough that I already have all that stuff "in my hands" anyway. I wonder if the OP ever read any of this.... :-) Thx, Tom From steve at holdenweb.com Wed Jan 7 16:35:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 16:35:53 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Dan Esch wrote: > Wait a sec... > > I think I get this... > > In essence, the implication of immutability for Python is that there is > only one "parrot", one "spam,"in fact one anything. (This seems like it > must hold for data primitives - does it hold for complex objects as > well? It seems it must...) In addition there is only one 1, and one 2 > etc. We may or may not have realized that string in a memory address to > which variable names can be bound, but should we do so, there is only > one "parrot" > > Python, is in fact, a Platonic programming language. Weird. If I've > got this right, worth chewing on.... > 'Fraid not. Certain immutables are cached by the interpreter, but most are not. >>> s1 = "a" + "b" + "c" >>> n = 12345 >>> s2 = "ab" + chr(99) >>> m = 2469 * 5 >>> s1 == s2 True >>> s1 is s2 False >>> n == m True >>> n is m False >>> id(s1), id(s2), id(n), id(m) (2146661888, 2146661792, 14453620, 14453584) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From excord80 at gmail.com Wed Jan 7 16:39:00 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 13:39:00 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> On Jan 7, 4:00?pm, floob wrote: > I have been searching for a way to print the official Python > documentation into some kind of book (for my own uses). ?I don't > really care if it's printed on newspaper and bound with elmer's > glue ... any way I can get relatively recent _official documentation_ > in print form will do. > > I'm on the go a lot, and can't read for long periods of time on LCD > screens anyhow (so having a laptop is not my solution). ?Until eBook > readers grow up a bit, I'm stuck trying to print the documentation > that I REALLY need to read and absorb. > > Lulu.com is an option, but it would cost something around $100 US > before shipping to get everything printed. ?Also, I would have to > split up some larger documents into Volumes, which I'd rather not have > to do. > > Has anyone tried this before? ?Is the documentation already available > in print? > > Thanks, > > drfloob http://docs.python.org/download.html I'd try taking the pdf to my local print shop and ask how much they'd charge. Local print shops have options for various bindings too. From bj_666 at gmx.net Wed Jan 7 16:52:10 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 7 Jan 2009 21:52:10 GMT Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> Message-ID: <6skmgaF6bhk2U5@mid.uni-berlin.de> On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: > On Jan 7, 8:45?am, Terje wrote: >> Is there a web service/API out there identifying Israel owned >> software/software companies/web sites/web services? If I am about to >> buy a piece of software, but don't want to support the Israeli economy, >> it would have been handy if I could just poll a web service to get the >> answer. This information should be kept in a database, and be public to >> the world through a very simple xml API, something along these lines: >> >> Request: >> Some Company Name >> >> Response: >> true >> >> Here's one source for this kind of information (I am sure there are >> plenty others):http://www.science.co.il/SoftwareCo.asp >> >> Of course, a web service like this would be equally useful to those who >> want to support Israeli companies. > > Something like that web-service that publishes the names and addresses > of doctors who perform abortions so that they can be assassinated? Hey, it's about boycott, not killing them. Applied to the doctors example: You go to someone without a doctors degree, a clothes hanger and some experience? ;-) Ciao, Marc 'BlackJack' Rintsch From google at mrabarnett.plus.com Wed Jan 7 17:00:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 22:00:12 +0000 Subject: How to store passwords? In-Reply-To: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> Message-ID: <496525EC.7080409@mrabarnett.plus.com> Oltmans wrote: > On Jan 8, 1:55 am, "Sebastian Bassi" > wrote: > >> In general you don't store the password, but a "hash" of it. Then >> when the user logs-in, you hash it and compare the result with the >> stored hash. About hash, use sha, look >> here:http://docs.python.org/library/hashlib.html#module-hashlib > > But the thing is that I will ask the user for user name and password > only once i.e. when they start the application for the first time. > After that, I'm not supposed to ask the user name and password again. > So in this scenario, if I store a hash on the disk I cannot retrieve > plain-text string back from my hash as I've to send user name and > password to the server in plain-text. > Is the application itself password-protected? If not, then there's no point in encrypting the username and password for the server in a file because anyone could just run the application after the first time and use it to access the server. From daniel.a.esch at gmail.com Wed Jan 7 17:06:07 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Wed, 7 Jan 2009 17:06:07 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: Okay, thanks... Still trying to wrap my fragile little VBA-corrupted brain around names, namespaces, and objects. Progress is being made. For me, the naive idea of variable ==> label for bin has been hard to get past simply because someone in the the back of my head is screaming, "Wait, if the VARIABLE doesn't point to a memory address, (somewhere down the implementation stack) whatinthehell does??" Further reading clarifies: For object X, id(X) is an immutable attribute reference that can ultimately be bound to a memory address (he said, blithely skipping over several layers of architecture...) So, okay, now I can relax. To oversimplify (told you VBA warped my mind) everything in python is an object (at some level). At minimum, all objects have an identity-- id(X), a type which subclasses and extends it from object, and some content, the nature of which depends on the object type. Once I got my head around the idea that there was something that was a fixed point of reference for the object, nevermind what, then I could relax and get on with get on with getting my head around names and namespaces. Thanks for listening to me ramble. On 1/7/09, Steve Holden wrote: > > Dan Esch wrote: > > Wait a sec... > > > > I think I get this... > > > > In essence, the implication of immutability for Python is that there is > > only one "parrot", one "spam,"in fact one anything. (This seems like it > > must hold for data primitives - does it hold for complex objects as > > well? It seems it must...) In addition there is only one 1, and one 2 > > etc. We may or may not have realized that string in a memory address to > > which variable names can be bound, but should we do so, there is only > > one "parrot" > > > > Python, is in fact, a Platonic programming language. Weird. If I've > > got this right, worth chewing on.... > > > 'Fraid not. Certain immutables are cached by the interpreter, but most > are not. > > >>> s1 = "a" + "b" + "c" > >>> n = 12345 > >>> s2 = "ab" + chr(99) > >>> m = 2469 * 5 > >>> s1 == s2 > True > >>> s1 is s2 > False > >>> n == m > True > >>> n is m > False > >>> id(s1), id(s2), id(n), id(m) > (2146661888, 2146661792, 14453620, 14453584) > >>> > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at hlacik.eu Wed Jan 7 17:13:57 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Wed, 7 Jan 2009 23:13:57 +0100 Subject: linked list with cycle structure In-Reply-To: <6sjok8F6dqciU1@mid.uni-berlin.de> References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: Hi, so okay, i will create a helping set, where i will be adding elements ID, when element ID will be allready in my helping set i will stop and count number of elements in helping set. This is how long my cycled linked list is. But what if i have another condition , and that is *i can use only helping memory with constant size* ? This means i am not able to create any set and adding elements there. I need to have a constant size variables . This is complication a complication for me. Thanks in advance! David On Wed, Jan 7, 2009 at 2:22 PM, Diez B. Roggisch wrote: > > David Hl??ik wrote: > > > dictionary with cycle structure > > > > Hello guys, > > > > I have a linked list where *number of elements is unlimited* and > > **last element points on random (can be first, last, in middle , > > anywhere) element within linked list** - this is important . My goals > > is to create an architecture /scheme for **algoritmus which will count > > total number of elements** of such linked list. > > Yes , maybe it sounds strange, but we need to implement this and i > > would be very gladfull for your toughts. > > Time for homework again? Last time sorting in O(n), now this. How about you > try something yourself and show us the results - then we might comment on > enhancements or problems. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list From floob.spam at gmail.com Wed Jan 7 17:14:31 2009 From: floob.spam at gmail.com (floob) Date: Wed, 7 Jan 2009 14:14:31 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> Message-ID: <2727789e-b644-4403-83a5-59b96a7317e0@s9g2000prg.googlegroups.com> On Jan 7, 1:39?pm, excord80 wrote: > On Jan 7, 4:00?pm, floob wrote: > > > > > I have been searching for a way to print the official Python > > documentation into some kind of book (for my own uses). ?I don't > > really care if it's printed on newspaper and bound with elmer's > > glue ... any way I can get relatively recent _official documentation_ > > in print form will do. > > > I'm on the go a lot, and can't read for long periods of time on LCD > > screens anyhow (so having a laptop is not my solution). ?Until eBook > > readers grow up a bit, I'm stuck trying to print the documentation > > that I REALLY need to read and absorb. > > > Lulu.com is an option, but it would cost something around $100 US > > before shipping to get everything printed. ?Also, I would have to > > split up some larger documents into Volumes, which I'd rather not have > > to do. > > > Has anyone tried this before? ?Is the documentation already available > > in print? > > > Thanks, > > > drfloob > > http://docs.python.org/download.html > > I'd try taking the pdf to my local print shop and ask how much they'd > charge. > > Local print shops have options for various bindings too. I tried 7 print shops in my area. Five refused to print single-run books (minimum quantity of 100). Of the 2 that WOULD print a single set of books, the cheapest was $250.00 (spiral bound, no covers, 8.5" x 11", cheapest paper available). That quote included roughly: the tutorial, library, reference, distutils, extending, and c-api pdfs. For that price, I could buy an eBook reader with plans to throw it away when I was done! Off on a bit of a tangent: if the Python Software Foundation could strike a deal with a charitable printing company, users could probably get a slight discount on buying printed documentation, and I'd bet Python's organization could get a small percentage of each sale. I believe ubuntu is doing something like this with Lulu.com. It'd be nice to support Python while doing something I was going to do on my own, anyhow. From martin at v.loewis.de Wed Jan 7 17:23:14 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 07 Jan 2009 23:23:14 +0100 Subject: del behavior 2 In-Reply-To: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> Message-ID: <49652b53$0$25195$9b622d9e@news.freenet.de> > Thanks for the responses. What I mean is when a python process is > interrupted and does not get a chance to clean everything up then what > is a good way to do so? For instance, I have a script that uses child > ptys to facilitate ssh connections (I'm using pxssh). When I ^C the > python process I am left with the child processes running and the ssh > connections open. Naturally I run out of ttys if this happens too > much, which I have had happen. So if python does not get a chance to > take care of those, what is a good way to do so? Does a try/finally > or a with statement address that? Thanks! That's strange. When the parent process terminates, the tty master should get closed, causing the slave to be closed as well, in addition to sending a SIGHUP signal to the child, which ssh should interpret as terminating. Perhaps the problem is that the master socket *doesn't* get closed? I see that pexpect closes all file descriptors in the child before invoking exec. Could it be that you are starting addition child processes which inherit the master socket? Regards, Martin From benjamin.kaplan at case.edu Wed Jan 7 17:25:25 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 17:25:25 -0500 Subject: del behavior In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 2:39 PM, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > What is globals referring to in the following text from that reference > page? > > "Starting with version 1.5, Python guarantees that globals whose name > begins with a single underscore are deleted from their module before > other globals are deleted; if no other references to such globals > exist, this may help in assuring that imported modules are still > available at the time when the __del__() method is called." > > Thus those with an _ get deleted before everything else. This is not > referring to members of my objects is it, such that those members > starting with _ get deleted first? I suppose that would delete > __del__ before it would get called so I assume that is not the case. > But I want to be sure about that behavior and exactly what globals > is. Is globals meaning the contents of "globals" or something else. > I ask because sometimes some words get used for varied meanings. Names with a *single* leading underscore are, by convention, "private". Names with double leading and trailing underscores are for special methods. The sort-of private methods are the ones that get deleted first, not the special methods. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From David Wed Jan 7 17:46:06 2009 From: David (David) Date: Wed, 07 Jan 2009 16:46:06 -0600 Subject: How do you write to the printer ? Message-ID: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Can find nothing in the on-line docs or a book. Groping in the dark I attempted : script24 import io io.open('stdprn','w') # accepted stdprn.write('hello printer') # fails < stdprn is not defined > Thanks to all responders I'm inching up on the snake. Dave WB3DWE From Scott.Daniels at Acm.Org Wed Jan 7 17:51:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 14:51:22 -0800 Subject: formatted 'time' data in calculations In-Reply-To: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> References: <6a956850-070e-4530-8c69-98baa3d3c8f7@40g2000prx.googlegroups.com> Message-ID: John Machin wrote: > On Jan 8, 6:23 am, Scott David Daniels wrote: >> ...some stuff perhaps too cranky... >> Have you read the entire time module document? If so, which functions >> in that module take strings as arguments?.... then even more cranky stuff... > > Indeed. Be not cranky at clueless bludgers and cargo-cultists .... And since others are pointing you at datetime and othert places, I'll just point out that I _did_, in fact, answer your question: (1) The answer to the oblique clue is strptime. (2) Only mktime takes a time_struct and returns a non-string. import time struct_time1 = time.strptime('14:11-01.07.09', '%H:%M-%m.%d.%y') struct_time2 = time.strptime('14:18-01.07.09', '%H:%M-%m.%d.%y') since_epoch1 = time.mktime(struct_time1) since_epoch2 = time.mktime(struct_time2) print int((since_epoch2 - since_epoch1) / 10) Hmmmm.... where have I seen that number before? A slightly less cranky kid because of the mollifying influence of the ever-diplomatic John Machin. --Scott David Daniels Scott.Daniels at Acm.Org From excord80 at gmail.com Wed Jan 7 17:53:40 2009 From: excord80 at gmail.com (excord80) Date: Wed, 7 Jan 2009 14:53:40 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> <5b4aabbd-6337-4dd3-a091-c3ed98b3d5f0@k8g2000yqn.googlegroups.com> <2727789e-b644-4403-83a5-59b96a7317e0@s9g2000prg.googlegroups.com> Message-ID: On Jan 7, 5:14?pm, floob wrote: > On Jan 7, 1:39?pm, excord80 wrote: > > > > > On Jan 7, 4:00?pm, floob wrote: > > > > I have been searching for a way to print the official Python > > > documentation into some kind of book (for my own uses). > > > > http://docs.python.org/download.html > > > I'd try taking the pdf to my local print shop and ask how much they'd > > charge. > > > Local print shops have options for various bindings too. > > I tried 7 print shops in my area. ?Five refused to print single-run > books (minimum quantity of 100). ?Of the 2 that WOULD print a single > set of books, the cheapest was $250.00 (spiral bound, no covers, 8.5" > x 11", cheapest paper available). Oh, heck. In that case, I'd just take the pdf on a flash drive to my local Fedex Kinkos and use their self-server printing machines and print it myself. If you can get it to print double-sided, it should cost half as much. Then just 3-hole-punch what you print out and put it into a 3-ring binder. I've done this myself in the past for docs that I wanted to have on my shelf and it works great. From ken.dambrosio at segway.com Wed Jan 7 17:54:03 2009 From: ken.dambrosio at segway.com (Ken D'Ambrosio) Date: Wed, 7 Jan 2009 17:54:03 -0500 (EST) Subject: Regular Expressions... Message-ID: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" the re module. For example, I'd like to do a few things (I'm going to use phone numbers, 'cause that's what I'm currently dealing with): 12345678900 -- How would I: - Get just the area code? - Get just the seven-digit number? In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have that stuff in $1 and $2, respectively. But the Python stuff simply isn't clicking for me. If anyone could supply concrete examples of how to do the problem, above, that would be terrific. Thanks! -Ken From fakeaddress at nowhere.org Wed Jan 7 17:54:04 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 07 Jan 2009 14:54:04 -0800 Subject: socket send help In-Reply-To: References: <_Ux8l.16881$ZP4.8821@nlpi067.nbdc.sbc.com> Message-ID: Gabriel Genellina wrote: > James Mills escribi?: >> Bryan Olson wrote: >>>> I thought a firewall would block an attempt to bind to any routeable >>>> address, but not to localhost. So using INADDR_ANY would be rejected. >> >> No. >> >>> My understanding is that firewalls block network traffic, not system >>> calls. >> >> This is correct. Firewalls (real firewalls) can only act on incoming >> and outgoing traffic on the IP level. > > That's true for hardware firewalls (those found in a router, by > example). They can at most analyze traffic at the application layer but > have no idea of the applications (processes) behind. > A "software firewall" may react not just to traffic but to *who* is > doing that; it may block *processes* when they try to bind/listen to any > port, even before any packet is sent or received. See > http://www.securityfocus.com/infocus/1839 > (One may argue whether those are *real* firewalls or not, but that's > their common name...) Even if one's 'firewall' product is one of "the rather useless ones that merely hook socket calls" (in the words of the linked article), I still don't see failing a bind() to INADDR_ANY while allowing a bind() to 127.0.0.1. INADDR_ANY means all available adapters. If some physical network adapter should be unavailable while the loopback is allowed, fine; passing INADDR_ANY should work and bind to the loopback adapter. > (Also note that I'm far for being an expert on these topics) Sure. I was mostly just making a couple points because at one time they confused me. Python's socket.bind() treats the empty string as INADDR_ANY, which means all available adapters. It's a fine address parameter for bind(), and ought to work at least as well as any. The time to bind() to localhost is when we specifically do not want to be available on an external network adapter. Now don't get me started on the vagaries of passing INADDR_ANY to connect(). -- --Bryan From prologic at shortcircuit.net.au Wed Jan 7 18:02:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 09:02:14 +1000 Subject: Regular Expressions... In-Reply-To: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> References: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Message-ID: On Thu, Jan 8, 2009 at 8:54 AM, Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" > the re module. For example, I'd like to do a few things (I'm going to use > phone numbers, 'cause that's what I'm currently dealing with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like > m/^1(...)(.......)/; > and then I'd have that stuff in $1 and $2, respectively. But the Python > stuff > simply isn't clicking for me. If anyone could supply concrete examples of > how to do the problem, above, that would be terrific. There is nothing so special or different about Python's re module than say over any other language's regular expression library or capabilities. You should be able to use pretty much the same things, however: 1. Why can't you just use ordinary string manipulation her e? One of Python's strengths is in string manipulation. Consider: >>> s = "1234567890" >>> area, number = s[:2], s[2:] >>> area '12' >>> number '34567890' cheers James From mensanator at aol.com Wed Jan 7 18:02:58 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 7 Jan 2009 15:02:58 -0800 (PST) Subject: An idea of how to identify Israeli owned software companies References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> Message-ID: <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> On Jan 7, 3:52?pm, Marc 'BlackJack' Rintsch wrote: > On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: > > On Jan 7, 8:45?am, Terje wrote: > >> Is there a web service/API out there identifying Israel owned > >> software/software companies/web sites/web services? If I am about to > >> buy a piece of software, but don't want to support the Israeli economy, > >> it would have been handy if I could just poll a web service to get the > >> answer. This information should be kept in a database, and be public to > >> the world through a very simple xml API, something along these lines: > > >> Request: > >> Some Company Name > > >> Response: > >> true > > >> Here's one source for this kind of information (I am sure there are > >> plenty others):http://www.science.co.il/SoftwareCo.asp > > >> Of course, a web service like this would be equally useful to those who > >> want to support Israeli companies. > > > Something like that web-service that publishes the names and addresses > > of doctors who perform abortions so that they can be assassinated? > > Hey, it's about boycott, not killing them. ? One person's boycott is another person's murder. It's like they say, guns don't kill people, people kill people. If guns are banned, then databases of such information should be banned also. > Applied to the doctors > example: ?You go to someone without a doctors degree, a clothes hanger > and some experience? ?;-) > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch- Hide quoted text - > > - Show quoted text - From rurpy at yahoo.com Wed Jan 7 18:06:47 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 7 Jan 2009 15:06:47 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> Message-ID: <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> On Jan 6, 9:20 pm, Mark Wooding wrote: > ru... at yahoo.com wrote: > > Is not the proper term "aliasing"? Perhaps Python "variables" should > > be called "alises". > > No. The proper term is most definitely `binding': see SICP, for > example. (Wikipedia has a link to the full text.) I thought you were objecting to Python's use of the term "binding" when you wrote: > Unfortunately, this practice causes other confusion, since `binding' is > often used (in other language communities, notably Lisp and the > functional languages) to describe the association between names and > slots that hold references. in response to someone talking about "...all those who use the term \"name binding\" instead of variable assignment...". From Scott.Daniels at Acm.Org Wed Jan 7 18:17:19 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 15:17:19 -0800 Subject: How do you write to the printer ? In-Reply-To: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: David Lemper wrote: > Can find nothing in the on-line docs or a book. > Groping in the dark I attempted : > > script24 > import io > io.open('stdprn','w') # accepted Here's your first mistake: you need to get the result of that call. Try: stdprn = io.open('stdprn', 'w') > stdprn.write('hello printer') # fails < stdprn is not defined > Note that (1) You may have just created a file named stdprn. (2) You need to close that file bwhen you are done. (3) A final end-of-line is traditional. (4) You could give us a clue about your operating environment. (To wit: os, version, python version) A printer is nothing Python has or controls, it is a standard thing for a computer system, so details about your computing environment are necessary in order to give you good advice. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Wed Jan 7 18:24:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 07 Jan 2009 18:24:06 -0500 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> Message-ID: Mensanator wrote: > On Jan 7, 3:52 pm, Marc 'BlackJack' Rintsch wrote: >> On Wed, 07 Jan 2009 10:17:55 -0800, Mensanator wrote: >>> On Jan 7, 8:45 am, Terje wrote: >>>> Is there a web service/API out there identifying Israel owned >>>> software/software companies/web sites/web services? If I am about to >>>> buy a piece of software, but don't want to support the Israeli economy, >>>> it would have been handy if I could just poll a web service to get the >>>> answer. This information should be kept in a database, and be public to >>>> the world through a very simple xml API, something along these lines: >>>> Request: >>>> Some Company Name >>>> Response: >>>> true >>>> Here's one source for this kind of information (I am sure there are >>>> plenty others):http://www.science.co.il/SoftwareCo.asp >>>> Of course, a web service like this would be equally useful to those who >>>> want to support Israeli companies. >>> Something like that web-service that publishes the names and addresses >>> of doctors who perform abortions so that they can be assassinated? >> Hey, it's about boycott, not killing them. > > One person's boycott is another person's murder. > > It's like they say, guns don't kill people, people kill > people. > > If guns are banned, then databases of such information > should be banned also. > >> Applied to the doctors >> example: You go to someone without a doctors degree, a clothes hanger >> and some experience? ;-) >> OK, that's enough non-Python ramblings for this thread. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From martin at v.loewis.de Wed Jan 7 18:25:45 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 00:25:45 +0100 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <496539fa$0$11157$9b622d9e@news.freenet.de> > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? Here is how the "Remember me" thing in browsers works: 1. The user *has* to pick a "master password". It can't work without (ignoring smartcards etc.). 2. the browser uses the master password to encrypt the many individual passwords that the user needs. 3. when the user navigates to a password protected site, the browser checks whether it has a cached password, and uses the master password to restore the encrypted site password. In interaction, several cases can occur A1. site never seen, no master password entered - ask user for site password, and whether to store password - ask user for master password - encrypt site password, and store on disk - remember master password in memory A2. site seen before, no master password entered - ask for master password, then continue with B2 B1. site never seen, master password entered - ask user for site password, and whether to store it - (if store) encrypt site password, store on disk B2. site seen before, master password entered - load encrypted password from disk, decrypt with master password, send to site The "encrypt" and "decrypt" operations are "symmetric", so what you need is a symmetric encryption algorithm. If you absolutely cannot accept additional algorithms, you can implement XOR password encryption yourself: Compute, letter-for-letter, the exclusive or of the site password and the master password; if you run out of master password letters, start over with the first one. Notice that this algorithm is very poor, and can be cracked by a crypto expert easily, given a few encrypted passwords. If you want a good algorithm, you might chose AES, with pure-Python implementations available here: http://bitconjurer.org/rijndael.py A simpler, yet supposedly secure algorithm is TEA: http://mail.python.org/pipermail/python-list/2002-August/159138.html Regards, Martin From news123 at free.fr Wed Jan 7 18:26:17 2009 From: news123 at free.fr (News123) Date: Thu, 08 Jan 2009 00:26:17 +0100 Subject: How to store passwords? In-Reply-To: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: <49653a19$0$5267$426a74cc@news.free.fr> Oltmans wrote: > I'm writing a program in which I will ask users to enter user name and > password once only. It's a console based program that will run on > Windows XP. Actually, I'm trying to provide the similar functionality > as "Remember me" thing in browsers. For that, I will need to store > user name and passwords on the disk. I don't have a background in > Crypto so how do you suggest I do that? What algorithms shall I be > using? Moreover, I cannot use a whole library to do that due to > certain issues. However, I can use like 1--2 files that will be > shipped along with the main script. Any ideas? Any help will be really > appreciated. Thanks. If you have to store user name and password in order to send them at a later time to another application, then there is really no point for encryption. If your script can read it, then anybody who can read your script (and thus the encryption password) will be able to decrypt the username and password. One exception on linux: suid executables writing the password file with restricted permissions, but then you rely on file system permissions and not on passwords ANother exception would be if - you start your python script - you enter a password interactively - the user switches then over enters his username and password, which you encrypt with your interactive pwd Lateron you could - start your script - enter your interactive password - read the encrypted user name / passwords from a file and send them over the network. Perhaps it would be best if you explain EXACTLY, what you would like to achieve and who trusts whom, whom you want to hide the passwords from, etc . bye N From prologic at shortcircuit.net.au Wed Jan 7 18:33:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 09:33:36 +1000 Subject: An idea of how to identify Israeli owned software companies In-Reply-To: References: <731e549a-0ec7-4915-89ab-c585606c20cf@o40g2000prn.googlegroups.com> <6sjtg5F6gnvfU1@mid.individual.net> <6skmgaF6bhk2U5@mid.uni-berlin.de> <4589d8b8-e186-47ea-ac98-cc59022d0ed6@p36g2000prp.googlegroups.com> Message-ID: On Thu, Jan 8, 2009 at 9:24 AM, Steve Holden wrote: (...) > OK, that's enough non-Python ramblings for this thread. God I wish we could delete threads :) cheers James From joe at strout.net Wed Jan 7 18:34:14 2009 From: joe at strout.net (Joe Strout) Date: Wed, 07 Jan 2009 16:34:14 -0700 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> Message-ID: <49653BF6.5020004@strout.net> Dan Esch wrote: > In essence, the implication of immutability for Python is that there is > only one "parrot", one "spam,"in fact one anything. (This seems like it > must hold for data primitives - does it hold for complex objects as > well? It seems it must...) In addition there is only one 1, and one 2 > etc. That's not necessarily true. If you have a = "par" + "rot" b = "parrot" then, most likely (though it depends on how clever the compiler optimizations are), there are two different string objects containing the data "parrot". In this case, "a == b" is true because string equality testing compares the data, but "a is b" is false because a and b refer to different objects. And by the way, don't let the people claiming that Python's assignment model is bizarre confuse you. Assignment and parameter-passing in Python is exactly the same as in any other modern OOP language; it just so happens that in Python, all variables are references, while in most other languages, some variables are references and others are primitive types. But it should be obvious (though apparently isn't, to some) that this restricted, uniform data model does not fundamentally change anything; it just makes Python a little more restricted and uniform. For details, see: Best, - Joe From adal.chiriliuc at gmail.com Wed Jan 7 18:38:05 2009 From: adal.chiriliuc at gmail.com (Adal Chiriliuc) Date: Wed, 7 Jan 2009 15:38:05 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> Message-ID: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> On Jan 7, 10:15?pm, Bruno Desthuilliers wrote: > This being said, I can only concur with other posters here about the > very poor naming. As far as I'm concerned, I'd either keep the argument > as a boolean but rename it "ascending" (and use a default True value), > or keep the 'order' name but then accept 'asc' and 'desc' as values > ('asc' being the default). Well, I lied a bit :-p The actual function is 20 lines long, and does other stuff to. The "order" argument is not passed as an argument, but as a field on an input object. Since I generally don't like it when people post questions and include gazillions of lines of code, I boiled down the real function to the one posted above, which is the minimum required to show our dilemma. "_find" also does not exist in the real code. You are all right, "order" is a bad name choice. "sort_ascending" would be a much better name for a boolean variable. I found Paul's idea very interesting, but I prefer to not introduce new objects which behave like C enums (maybe that would be more Pythonic?), so I found this variant: def find(field, sort_ascending): ....order_by = {True: "asc", False: "desc"} ....return _find(field + "+" + order_by[sort_ascending]) But what if we can't solve it as ellegantly, and we need to execute different code depending on the condition: def find(field, fast_mode=True): ....if fast_mode: ........do_something(field, 1, DEFAULT_PAGE_SIZE) ....else: ........do_another_thing(field, False, "xml", ignore_error=False) ........and_another_one() Should we typecheck in this case to ensure that if we pass a string for "fast_mode" we will raise an exception? From jgardner at jonathangardner.net Wed Jan 7 18:38:13 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 7 Jan 2009 15:38:13 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: On Jan 7, 7:50?am, J Kenneth King wrote: > Jonathan Gardner writes: > > On Jan 6, 12:24?pm, J Kenneth King wrote: > >> Jonathan Gardner writes: > >> > On Jan 6, 8:18?am, sturlamolden wrote: > >> >> On Jan 6, 4:32 pm, mark wrote: > > >> >> > I want to implement a internal DSL in Python. I would like the syntax > >> >> > as human readable as possible. > > >> >> Also beware that Python is not Lisp. You cannot define new syntax (yes > >> >> I've seen the goto joke). > > >> > This isn't really true. You can, for instance, write a program (in > >> > Python) that takes your pseudo-Python and converts it into Python. > >> > This is what a number of templating libraries such as Mako do. > > >> Which is not even close to being the same. > > >> Lisp - the program source is also the data format > > >> Python - the program source is a string > > >> I could go on a really long rant about how the two are worlds apart, but > >> I'll let Google tell you if you're really interested. > > > I get that Lisp is special because you can hack on the reader as it is > > reading the file in. This is strongly discouraged behavior, as far as > > I know, despite the number of cute hacks you can accomplish with it. > > It is generally discouraged unless there's a reason for it. > > > But consider that this really isn't different than having a program > > read in the lisp-with-modification source and spitting out pure lisp, > > to be read by an honest-to-gosh lisp program later. > > > If that's the case, then Lisp and Python really aren't that different > > in this regard, except that you don't have the option of modifying the > > reader as it reads in the file. > > I think you are missing the distinction. > > Lisp expressions are also data structures. A Lisp expression can be > passed to functions and macros to be operated on before being > executed. When you're writing Lisp source, you're basically looking at > the AST on one level and when you start writing macros for your program, > you're creating a "DSL" or interface to that AST. Lisp source is > eventually expanded to a giant list that is consed by the evaluator (as > far as I understand it. I'm just getting into the compiler stuff > myself). > I think you misunderstood what I was trying to explain. Yes, you can do those wonderful things with Lisp. You can also do wonderful things with Python. Consider programs that take some text written in some other language besides Python. Those programs interpret and translate the text to Python. Then the programs feed the translations to the Python interpreter. Tada! You have a DSL in Python. No, it's not built in, nor is there any standard, but it is entirely possible and people are doing it today. That's how the variety of templating solutions work in the Python world. It's why I can write ${x +y} in Mako and get a Python program that will do the right thing. Alternatively, you can skip the Python interpreter altogether, and write your own interpreter for the language. If it's a simple language (like the original poster hinted at), this is very easy to do. From jgardner at jonathangardner.net Wed Jan 7 18:40:37 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 7 Jan 2009 15:40:37 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> Message-ID: <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> On Jan 7, 9:16?am, "Chris Mellon" wrote: > > The OP wants a Ruby-style DSL by which he means "something that lets > me write words instead of expressions". The ruby syntax is amenable to > this, python (and lisp, for that matter) syntax is not and you can't > implement that style of internal DSL in those languages. > > The answer to the OP is "you can't - use Ruby or modify your requirements". > As far as putting the code into Python, yeah, you can't put it in Python. The best you can do is store it in a string and then interpret the string with some function later on. From David Wed Jan 7 18:45:04 2009 From: David (David) Date: Wed, 07 Jan 2009 17:45:04 -0600 Subject: How do you write to the printer ? References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: On Wed, 07 Jan 2009 15:17:19 -0800, Scott David Daniels wrote: >David Lemper wrote: >> Can find nothing in the on-line docs or a book. >> Groping in the dark I attempted : >Note that (1) You may have just created a file named stdprn. > (2) You need to close that file bwhen you are done. > (3) A final end-of-line is traditional. > (4) You could give us a clue about your operating environment. > (To wit: os, version, python version) > >A printer is nothing Python has or controls, it is a standard thing for >a computer system, so details about your computing environment are >necessary in order to give you good advice. > >--Scott David Daniels >Scott.Daniels at Acm.Org Thanks Scott. System is Windows XP on an Intel, Python version 3.0 Dave From google at mrabarnett.plus.com Wed Jan 7 18:51:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2009 23:51:09 +0000 Subject: Regular Expressions... In-Reply-To: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> References: <38900.75.67.222.25.1231368843.squirrel@webmail.jots.org> Message-ID: <49653FED.800@mrabarnett.plus.com> Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, I have to admit I don't quite > "get" the re module. For example, I'd like to do a few things (I'm > going to use phone numbers, 'cause that's what I'm currently dealing > with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have > that stuff in $1 and $2, respectively. But the Python stuff simply > isn't clicking for me. If anyone could supply concrete examples of > how to do the problem, above, that would be terrific. > Perl puts the captured text into variables as a side-effect, which, from the Python point of view, is undesirable 'magic'. The Python way is for the result to be returned like any normal function or method call: match = re.search(r"^1(...)(.......)", phone_number) # match is now a match object if successful or None if unsuccessful if match: area_code = match.group(1) local_code = match.group(2) # or: # area_code, local_code = match.groups() No magic involved! (In this case simple string slicing would be simpler and faster.) From gh at ghaering.de Wed Jan 7 18:54:53 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 08 Jan 2009 00:54:53 +0100 Subject: pg_result_status() alternative? In-Reply-To: References: Message-ID: <6sktmdF6t1jiU1@mid.uni-berlin.de> Qian Xu wrote: > Steve Holden wrote: >> Without knowing the full details of that particular module I would >> hazard a guess that any database errors will raise exceptions in Python. >> No exceptions means your database operation worked fine. > > result status is not an exception. > It means the information of frontend/backend protocal, after a SQL-statement > is execute. > > The following is a list of backend IPC commands (v3) > ---------------------------------------------------- > Z - Zero / Ready for Query > [...] > For instance: > ---------------------------------------------------- > SELECT * FROM my_table; > The backend protocal should return T (Row Description) and the frontend > protocal should return Q (Query) > ---------------------------------------------------- > DROP TABLE my_table; > The backend protocal should return C (Complete) and the frontend protocal > should return Q (Query) What are you testing, really? "Normal" Python code should use a PostgreSQL DB-API module or a wrapper on top of it, like SQLAlchemy. Generally, you shouldn't have to drop down to protocol-level functions, unless you're developing a PostgreSQL adapter yourself. Care to explain why you're messing around with this low-level functions? -- Gerhard From jstroud at mbi.ucla.edu Wed Jan 7 18:55:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 15:55:52 -0800 Subject: How to store passwords? In-Reply-To: References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> Message-ID: James Stroud wrote: > If you check out sf.passerby.net and download the source, you will see a passerby.sf.net Shuffle things I did. From roy at panix.com Wed Jan 7 18:56:31 2009 From: roy at panix.com (Roy Smith) Date: Wed, 07 Jan 2009 18:56:31 -0500 Subject: socket.error 24: too many open files References: Message-ID: In article , TheDavidFactor wrote: > I have double checked that it is closing the socket. I don't know what > else to check, any suggestions would be much appreciated. All of the symptoms you report point to sockets not getting closed. What does "double checked" mean? Don't rely on __del__() closing sockets, because __del__() may never get called. Here's a few ways to look for sockets that aren't getting closed: 1) Run netstat. 2) Look in /proc. 3) This is the cute one; iterate over all possible descriptors from 0 to `ulimit -n`. For each one, dup() it, then close the dupe. If dup() didn't raise an exception, the descriptor was valid. Count the ones that don't fail, and you know how many descriptors are open at any time. This is useful for tracking descriptor leaks (which sounds like what you've got). From google at mrabarnett.plus.com Wed Jan 7 19:00:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 00:00:00 +0000 Subject: [SPAM] Re: How do you write to the printer ? In-Reply-To: References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: <49654200.4080505@mrabarnett.plus.com> David at bag.python.org wrote: > On Wed, 07 Jan 2009 15:17:19 -0800, Scott David Daniels > wrote: > >> David Lemper wrote: >>> Can find nothing in the on-line docs or a book. >>> Groping in the dark I attempted : > >> Note that (1) You may have just created a file named stdprn. >> (2) You need to close that file bwhen you are done. >> (3) A final end-of-line is traditional. >> (4) You could give us a clue about your operating environment. >> (To wit: os, version, python version) >> >> A printer is nothing Python has or controls, it is a standard thing for >> a computer system, so details about your computing environment are >> necessary in order to give you good advice. >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Thanks Scott. System is Windows XP on an Intel, Python version 3.0 > The simplest way on Windows is opening "PRN:" or "LPT1": printer = open("PRN:", "wb") printer.write(binary_data) printer.close() where 'binary_data' is a bytestring (class 'bytes' in Python 3.x). From jstroud at mbi.ucla.edu Wed Jan 7 19:03:56 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 16:03:56 -0800 Subject: Regular Expressions... In-Reply-To: References: Message-ID: Ken D'Ambrosio wrote: > Hi, all. As a recovering Perl guy, [snip] > In Perl, I'd so something like > m/^1(...)(.......)/; Indeed it seems you are recovering from an especially bad case. I recommend two doses of the python cookbook per day for one to two months. Report back here after your first cycle and we'll tell you how you are doing. I'm very optimistic about the prognosis. James From fakeaddress at nowhere.org Wed Jan 7 19:06:02 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 07 Jan 2009 16:06:02 -0800 Subject: socket.error 24: too many open files In-Reply-To: References: Message-ID: TheDavidFactor wrote: > [...] It's a deamon that runs on a linux box > and every 15 seconds it checks a MySQL table for new records, if there > are any it creates a .call file on the Asterisk server using ssh, it > also checks the Asterisk server, again via ssh, for any finished calls > and if there are any it reads the .call file and writes the result in > to the MySQL table. > > [...] After it has run for an hour or so I get the error > in the subject when the ssh class tries to create a new socket. I have > double checked that it is closing the socket. I don't know what else > to check, any suggestions would be much appreciated. Is it possible you keep accumulating MySQLdb connection or cursor objects and don't close() them? (I don't know the innards of MySQLdb, but it's something to check.) One thing you might try is to regularly log the filno() of your sockets. -- --Bryan From tjreedy at udel.edu Wed Jan 7 19:08:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 19:08:03 -0500 Subject: linked list with cycle structure In-Reply-To: References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: David Hl??ik wrote: > so okay, i will create a helping set, where i will be adding elements > ID, when element ID will be allready in my helping set i will stop and > count number of elements in helping set. This is how long my cycled > linked list is. CPython now does this in printing and marshalling/pickling so that the following terminates instead of going into an infinite spin. >>> a=[1] >>> b=[2,a] >>> c=[3,b] >>> d=[4,c] >>> a.append(d) >>> a [1, [4, [3, [2, [...]]]]] >>> Sets cannot be recursive because members must be hashable. Dict values do not have to be. So >>> d={1:None} >>> d[1]=d >>> d {1: {...}} >>> > But what if i have another condition , and that is *i can use only > helping memory with constant size* ? This means i am not able to > create any set and adding elements there. I need to have a constant > size variables . This is complication a complication for me. Interesting problem. If it is homework, there must be an answer. Think time-space tradeoff. However, this of really off-topic here. It not only has nothing in particular to with Python, but an indefinitely long looping linked list is something very unlikely in a Python program since Python is based on array-type lists. If you do write a solution in Python, you could, however, post it. tjr From prologic at shortcircuit.net.au Wed Jan 7 19:10:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 10:10:10 +1000 Subject: Regular Expressions... In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 10:03 AM, James Stroud wrote: (...) > Indeed it seems you are recovering from an especially bad case. I recommend > two doses of the python cookbook per day for one to two months. Report back > here after your first cycle and we'll tell you how you are doing. I'm very > optimistic about the prognosis. 2nd opinion :) I highly recommend a strong dose of the Python Tutorial (1) followed by a recovery program of the Python Docs (2) cheers James 1. http://docs.python.org/tutorial/ 2. http://docs.python.org/ From leith.bade at silentone.com Wed Jan 7 19:11:32 2009 From: leith.bade at silentone.com (Leith Bade) Date: Thu, 8 Jan 2009 13:11:32 +1300 Subject: Detecting a GUI session Message-ID: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> I would like to know whether my GUI program is being run under python or pythonw. I would like to know this so I can redirect stderr when their is no console window (pythonw) otherwise leave it spitting to the console window (python). This is because I debug using python while the customer release build uses pythonw. I can see their is sys.executable but a google search turned up various discussions on what this actually means (e.g when run under an integrated exe file - which we do for our release builds). Leith Bade -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jan 7 19:21:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 16:21:06 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> Message-ID: <1ZednYe8UMYq2_jUnZ2dnUVZ_rrinZ2d@pdx.net> Adal Chiriliuc wrote: > On Jan 7, 10:15 pm, Bruno Desthuilliers > wrote: >> ... I'd either keep the argument as a boolean but rename it "ascending" ... > > Well, I lied a bit :-p .... > But what if we can't solve it as elegantly, and we need to ... > > Should we typecheck in this case to ensure that if we pass a string > for "fast_mode" we will raise an exception? Why are you concerned only with type errors on inputs? Even if you could do exhaustive checking of input parameters to make sure they are the only acceptable values, what prevents your user from providing the wrong valid value? What made you pick on type errors in the first place? If it turns out that an argument of 422 is a typo for 42, why is that less of a problem? Just because you are used to systems where one kind of error is always caught does not really make you invulnerable. You'll have no problem telling your users that the 422 is their fault. Why do you have such certainty that passing in "nonsense" as a boolean is a failure you need to deal with? Anyhow, you can guess where my votes would go. If the failure in results will come sufficiently far removed from the bad entry, I sometimes resort to input validation. Often those cases are for setting attributes used much later in an interactive environment. Maybe you can layer your checking in: have a subclass that wraps calls with lots of checking, and see if the subclass or the base is used more. One place I have needed validation is in setting callbacks, since the callback typically gets called asynchronously, and I have trouble discovering why those things blew up. If I can, I manage to try the callback once first, hoping for an early explosion. --Scott David Daniels Scott.Daniels at Acm.Org From jstroud at mbi.ucla.edu Wed Jan 7 19:21:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 16:21:52 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: Adal Chiriliuc wrote: > Hello, > > Me and my colleagues are having an discussion about the best way to > code a function (more Pythonic). > > Here is the offending function: > > def find(field, order): > ....if not isinstance(order, bool): > ........raise ValueError("order must be a bool") > ....order_by = "asc" if order else "desc" > ....return _find(field + "+" + order_by) > > We are not sure what's the best practice here. Should we or should we > not check the type of the "order" variable, which should be a bool? None of the above. You have put unnecessary constraints on find by requiring a certain data type. def find(field, order_by='desc'): return _find(field + "+" + order_by) Here we are deferring error checking to the _find function. Otherwise: def find(field, order_by='desc'): if order_by not in ['asc', 'desc']: raise ValueError, 'Bad order_by parameter.' else: return _find(field + "+" + order_by) Now you have achieved the exact same affect without any sort of explicit type checking. Moreover, you have eliminated an "if" statement. Also, you leave room for exotic orderings should you ever want them. James From tjreedy at udel.edu Wed Jan 7 19:22:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jan 2009 19:22:00 -0500 Subject: why cannot assign to function call In-Reply-To: <49653BF6.5020004@strout.net> References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: Joe Strout wrote: > That's not necessarily true. If you have > > a = "par" + "rot" > b = "parrot" > > then, most likely (though it depends on how clever the compiler > optimizations are), there are two different string objects containing > the data "parrot". >>> a='par'+'rot' >>> b='parrot' >>> a is b True From robert.kern at gmail.com Wed Jan 7 19:23:24 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 07 Jan 2009 19:23:24 -0500 Subject: linked list with cycle structure In-Reply-To: References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: Terry Reedy wrote: > David Hl??ik wrote: >> But what if i have another condition , and that is *i can use only >> helping memory with constant size* ? This means i am not able to >> create any set and adding elements there. I need to have a constant >> size variables . This is complication a complication for me. > > Interesting problem. If it is homework, there must be an answer. It's also an interview question I've seen reasonably often, particularly with that last complication. -- 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 bearophileHUGS at lycos.com Wed Jan 7 19:24:40 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 7 Jan 2009 16:24:40 -0800 (PST) Subject: Regular Expressions... References: Message-ID: Ken D'Ambrosio: >?But the Python stuff simply isn't clicking for me. For people coming from Perl that want to perform some string processing with Python I suggest to learn first array/string slices and string methods. And to try to use the regular expressions as little as possible. Bye, bearophile From Scott.Daniels at Acm.Org Wed Jan 7 19:29:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 07 Jan 2009 16:29:53 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: James Stroud wrote: > ... > def find(field, order_by='desc'): > if order_by not in ['asc', 'desc']: > raise ValueError, 'Bad order_by parameter.' > ... I'd try a little harder with that error message. At least: raise ValueError('Bad order_by parameter %r.' % (order_by,)) if not: raise ValueError('Bad order_by = %r (should be in %r).' % ( order_by, ['asc', 'desc'])) --Scott David Daniels Scott.Daniels at Acm.Org From rurpy at yahoo.com Wed Jan 7 19:45:06 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 7 Jan 2009 16:45:06 -0800 (PST) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: On Jan 5, 12:21 pm, Derek Martin wrote: ... > I understand why the assignment model works the way it does, and it's > quite sensible, *when you understand it*. However, I do also think > that to someone who has not encountered such a model before, and who > has not had it explained to them, and/or who has not the background to > understand why it is implemented that way, it very likely might seem > "markedly unusual in appearance, style, or general character and often > involving incongruous or unexpected elements;" as dictionary.com > defines the term bizarre. So no, I don't think that's a > mischaracterization at all. ... Ignoring the nit-picking over choice of words, or what languages are taught in CS courses, I agree with Derek's general point that Python's assignment semantics is *not* the same as many other common languages, and that this confuses people coming to Python from those languages, as evidenced by frequent postings to this list by those people. I concluded exactly the same a long time ago. When I started using Python I had no problem with Python's assignment semantics because I had been using references in Perl for years. I did not have a very hard time with Perl's references, after I recognized their similarities to C's pointers. But as I recall, it took a *long* time to wrap my mind around C pointers. Here is the output of set of equivalent programs in five common (at least at one time) languages (code below) that I have worked in and that formed my "intuition" about how assignment works. Sure looks to me as though Python is the odd man out. Perl: 1, 4, 3 1, 2, 3 Basic (MS VBA): 1 4 3 1 2 3 C: 1, 4, 3 1, 2, 3 Fortran: 1 4 3 1 2 3 Python: [1, 4, 3] [1, 4, 3] Of course, one can dismiss these as non-mainstream or non-modern languages, and maintain that all "important" languages have the same assignment semantics as Python, but then one is left having to explain the frequent confusion about assignment that is visible on this list. I find Derek's explantion more plausible than any others I have read in this thread. ======================================================== Python: #/usr/bin/python a = [1,2,3] b = a a[1] = 4 print a print b ======================================================== Perl: #!/usr/bin/perl @a = (1,2,3); @b = @a; $a[1] = 4; print join (',', @a), "\n"; print join (',', @b), "\n"; ======================================================== Basic: Sub test() Dim a, b a = Array(1, 2, 3) b = a a(1) = 4 Debug.Print a(0), a(1), a(2) Debug.Print b(0), b(1), b(2) End Sub ======================================================== C: #include main () { int i; struct {int a[3];} a, b; for (i=0; i<3; i++) { a.a[i] = i+1; } b = a; a.a[1] = 4; printf ("%i,%i,%i\n", a.a[0], a.a[1], a.a[2]); printf ("%i,%i,%i\n", b.a[0], b.a[1], b.a[2]); } ========================================================== Fortran: program test integer a(3), b(3) do 100, i=1,3 a(i) = i 100 continue b = a a(2) = 4 write(unit=*,fmt=*) a write(unit=*,fmt=*) b end From ken at jots.org Wed Jan 7 19:51:21 2009 From: ken at jots.org (Ken D'Ambrosio) Date: Wed, 7 Jan 2009 19:51:21 -0500 (EST) Subject: Regular Expressions... Message-ID: <41178.75.67.222.25.1231375881.squirrel@webmail.jots.org> Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" the re module. For example, I'd like to do a few things (I'm going to use phone numbers, 'cause that's what I'm currently dealing with): 12345678900 -- How would I: - Get just the area code? - Get just the seven-digit number? In Perl, I'd so something like m/^1(...)(.......)/; and then I'd have the numbers in $1 and $2, respectively. But the Python stuff simply isn't clicking for me. If anyone could supply concrete examples of how to do the problem, above, that would be terrific. Thanks! -Ken From erexsha at gmail.com Wed Jan 7 19:55:51 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 7 Jan 2009 16:55:51 -0800 Subject: multiprocessing vs thread performance In-Reply-To: References: Message-ID: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Hi All , Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch of good example for it? I am trying to break a loop to run it over multiple core in a system. And I need to return an integer value as the result of the process an accumulate all of them. the examples that I found there is no return for the process. Thanks, -Arash On Mon, Jan 5, 2009 at 7:24 PM, Gabriel Genellina wrote: > En Sat, 03 Jan 2009 11:31:12 -0200, Nick Craig-Wood > escribi?: > >> mk wrote: >> > > The results I got are very different from the benchmark quoted in PEP >>> 371. On twin Xeon machine the threaded version executed in 5.54 secs, >>> while multiprocessing version took over 222 secs to complete! >>> >>> Am I doing smth wrong in code below? >>> >> >> Yes! >> >> The problem with your code is that you never start more than one >> process at once in the multiprocessing example. Just check ps when it >> is running and you will see. >> > > Oh, very good analysis! Those results were worriying me a little. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Wed Jan 7 19:58:12 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 11:58:12 +1100 Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> Message-ID: <87y6xmhavv.fsf@benfinney.id.au> Scott David Daniels writes: > James Stroud wrote: > > ... > > def find(field, order_by='desc'): > > if order_by not in ['asc', 'desc']: > > raise ValueError, 'Bad order_by parameter.' > > ... > I'd try a little harder with that error message. > At least: > raise ValueError('Bad order_by parameter %r.' % (order_by,)) > if not: > raise ValueError('Bad order_by = %r (should be in %r).' % ( > > order_by, ['asc', 'desc'])) Why are people so reluctant to make error message templates clearer with named placeholders? valid_order_by_values = ['asc', 'desc'] if order_by not in valid_order_by_values: raise ValueError( 'Bad order_by parameter %(order_by)r, should be in %(valid_order_by_values)r' % vars()) -- \ ?I love and treasure individuals as I meet them, I loathe and | `\ despise the groups they identify with and belong to.? ?George | _o__) Carlin, 2007 | Ben Finney From p at ulmcnett.com Wed Jan 7 20:00:07 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 17:00:07 -0800 Subject: Unexpected scientific notation Message-ID: <49655017.6010100@ulmcnett.com> One of my users has reported that my app is giving them scientific notation instead of decimal notation for one specific value among many that display properly. I am unable to reproduce on my end, and this is the first I've heard of anything like this since the app's launch 2 years ago. The app bundles python 2.5.2 using py2exe. It displays '3E+1' instead of '30.0'. As I can't reproduce I'm looking for an idea brainstorm of what could be causing this. What would be choosing to display such a normal number in scientific notation? Ideas? Paul From benjamin.kaplan at case.edu Wed Jan 7 20:01:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 20:01:35 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 2:31 PM, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? > > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? Python will work with Tk 8.5. Regardless of the version, Tk has to be installed first. I also think you'll have to modify the detect_modules method in setup.py to include the directory where Tk is installed. I'm on a Mac, so the method for detecting Tk is a little bit different. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Wed Jan 7 20:05:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 11:05:53 +1000 Subject: multiprocessing vs thread performance In-Reply-To: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> References: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Message-ID: On Thu, Jan 8, 2009 at 10:55 AM, Arash Arfaee wrote: > Hi All , HI :) > Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch of > good example for it? I am trying to break a loop to run it over multiple > core in a system. And I need to return an integer value as the result of the > process an accumulate all of them. the examples that I found there is no > return for the process. You communicate with the process in one of several ways: * Semaphores * Locks * PIpes I prefer to use Pipes which act much like sockets. (in fact they are). Read the docs and let us know how you go :) I'm actually implementing multiprocessing support into circuits (1) right now... cheers James 1. http://trac.softcircuit.com.au/circuits/ From max at alcyone.com Wed Jan 7 20:07:29 2009 From: max at alcyone.com (Erik Max Francis) Date: Wed, 07 Jan 2009 17:07:29 -0800 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: <6LqdnQurg-dMzPjUnZ2dnUVZ_uGdnZ2d@speakeasy.net> Terry Reedy wrote: > Joe Strout wrote: > >> That's not necessarily true. If you have >> >> a = "par" + "rot" >> b = "parrot" >> >> then, most likely (though it depends on how clever the compiler >> optimizations are), there are two different string objects containing >> the data "parrot". > > >>> a='par'+'rot' > >>> b='parrot' > >>> a is b > True One exactly doesn't really say much. It's implementation dependent, and depends on the length of the string: >>> a = 'this is a much longer ' + 'parrot' >>> b = 'this is a much longer parrot' >>> a is b False In practice, tests like these are pretty much never useful. It's completely implementation dependent when and under what circumstances fundamental immutable objects are reused, and it's not useful anyway; what you care about is whether two objects are equal or not, not whether they're the same object through some optimization behind the scenes. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis All delays are dangerous in war. -- John Dryden, 1631-1700 From robert.kern at gmail.com Wed Jan 7 20:18:15 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 07 Jan 2009 20:18:15 -0500 Subject: Unexpected scientific notation In-Reply-To: <49655017.6010100@ulmcnett.com> References: <49655017.6010100@ulmcnett.com> Message-ID: Paul McNett wrote: > One of my users has reported that my app is giving them scientific > notation instead of decimal notation for one specific value among many > that display properly. I am unable to reproduce on my end, and this is > the first I've heard of anything like this since the app's launch 2 > years ago. > > The app bundles python 2.5.2 using py2exe. > > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be > causing this. What would be choosing to display such a normal number in > scientific notation? > > Ideas? Locales? Do you at last know the code that's responsible for formatting the number? -- 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 benjamin.kaplan at case.edu Wed Jan 7 20:19:51 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Jan 2009 20:19:51 -0500 Subject: why cannot assign to function call In-Reply-To: References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> Message-ID: On Wed, Jan 7, 2009 at 7:22 PM, Terry Reedy wrote: > Joe Strout wrote: > > That's not necessarily true. If you have >> >> a = "par" + "rot" >> b = "parrot" >> >> then, most likely (though it depends on how clever the compiler >> optimizations are), there are two different string objects containing the >> data "parrot". >> > > >>> a='par'+'rot' > >>> b='parrot' > >>> a is b > True (this is on Mono. I don't know if the real .NET and/or newer versions of IronPython do this differently) IronPython 1.1 (1.1) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. >>> a = "par" + "rot" >>> b="parrot" >>> a is b False > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at mbi.ucla.edu Wed Jan 7 20:27:49 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 17:27:49 -0800 Subject: Is it ok to type check a boolean argument? In-Reply-To: <87y6xmhavv.fsf@benfinney.id.au> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <87y6xmhavv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Why are people so reluctant to make error message templates clearer > with named placeholders? Because they can never remember they even exist. Thanks for the reminder. From lists at cheimes.de Wed Jan 7 20:31:24 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jan 2009 02:31:24 +0100 Subject: Detecting a GUI session In-Reply-To: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> References: <0C7699C0AFCDAD4B9EC31C61398D00C92BB15B@eris.silentone.com> Message-ID: Leith Bade schrieb: > I would like to know whether my GUI program is being run under python or > pythonw. > > I would like to know this so I can redirect stderr when their is no > console window (pythonw) otherwise leave it spitting to the console > window (python). > > This is because I debug using python while the customer release build > uses pythonw. > > I can see their is sys.executable but a google search turned up various > discussions on what this actually means (e.g when run under an > integrated exe file - which we do for our release builds). You can check the file descriptor number of sys.stderr. If sys.stderr.fileno() returns -1 or any other value smaller than zero than stderr is not connected to a stream. Christian From bignose+hates-spam at benfinney.id.au Wed Jan 7 20:41:14 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 12:41:14 +1100 Subject: Regular Expressions... References: Message-ID: <87tz8ah8w5.fsf@benfinney.id.au> "Ken D'Ambrosio" writes: > Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" > the re module. For example, I'd like to do a few things (I'm going to use > phone numbers, 'cause that's what I'm currently dealing with): > 12345678900 -- How would I: > - Get just the area code? > - Get just the seven-digit number? > > In Perl, I'd so something like > m/^1(...)(.......)/; Wouldn't that be better as: m/^1(\d{3})(\d{7})$/; I'll assume that more-precise expression in what follows. > and then I'd have the numbers in $1 and $2, respectively. But the Python > stuff simply isn't clicking for me. In general, where a set of data is likely to be iterated, the Pythonic way to present it is via a single iterable (instead of, in your Perl example, separate variables). Then, for those (generally less frequent) cases where you do want the separate items, you can bind them in a single statement: (foo, bar, baz) = some_sequence or (foo, bar, baz) = (item for item in some_sequence) e.g.: >>> (foo, bar, baz) = [1, 2, 3] >>> foo 1 >>> bar 2 >>> baz 3 So, the match returned by the various ?re? module match functions is an object which allows access to the grouped matches as a sequence. > If anyone could supply concrete examples of how to do the problem, > above, that would be terrific. Assuming the following: >>> import re >>> phone_number_regex = '^1(\d{3})(\d{7})$' Trivial one-shot example: >>> phone_number = '12345678900' >>> (area_code, local_number) = re.match(phone_number_regex, phone_number).groups() >>> area_code '234' >>> local_number '5678900' More explicit example, showing the various steps and assuming you want to re-use the various values in multiple statements: >>> phone_number_pattern = re.compile(phone_number_regex) >>> phone_number_pattern <_sre.SRE_Pattern object at 0xf7f8c598> >>> phone_number = '12345678900' >>> phone_number_match = phone_number_pattern.match(phone_number) >>> phone_number_match <_sre.SRE_Match object at 0xf7f52338> >>> (area_code, local_number) = phone_number_match.groups() >>> area_code '234' >>> local_number '5678900' Python regular expressions also allow naming each group, for later access to the matches via a dict: >>> phone_number_regex = '^1(?P\d{3})(?P\d{7})' >>> phone_number_pattern = re.compile(phone_number_regex) >>> phone_number_match = phone_number_pattern.match(phone_number) >>> phone_number_groups = phone_number_match.groupdict() >>> phone_number_groups['area_code'] '234' >>> phone_number_groups['local_number'] '5678900' -- \ ?? one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.? ?Robert Firth | Ben Finney From cs at zip.com.au Wed Jan 7 20:55:30 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 8 Jan 2009 12:55:30 +1100 Subject: Regular Expressions... In-Reply-To: <41178.75.67.222.25.1231375881.squirrel@webmail.jots.org> Message-ID: <20090108015530.GA13974@cskk.homeip.net> On 07Jan2009 19:51, Ken D'Ambrosio wrote: | Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" | the re module. For example, I'd like to do a few things (I'm going to use | phone numbers, 'cause that's what I'm currently dealing with): | 12345678900 -- How would I: | - Get just the area code? | - Get just the seven-digit number? | | In Perl, I'd so something like | m/^1(...)(.......)/; | and then I'd have the numbers in $1 and $2, respectively. But the Python | stuff simply isn't clicking for me. If anyone could supply concrete | examples of how to do the problem, above, that would be terrific. I presume you're consulting this: http://docs.python.org/library/re.html#module-re Something like this (untested): import re phone = '12345678900' num_re = re.compile('^1(...)(.......)') num_re is now a regular expression object: http://docs.python.org/library/re.html#regular-expression-objects much as you get from a "precompiled" perl regular expression. m = num_re.match(phone) m is now the result of a match against the phone number: http://docs.python.org/library/re.html#id1 m.group(0) is what was matched by the whole expression. m.group(1) is perl's $1, m.group(2) is $2 etc. For example: area_code = m.group(1) There is also an expand() method that accepts \1, \2 etc in its template. For direct substitutions (as in perl's s/this/that/) there is the regular expression object sub() method. It's a bit more broken out than you normally get in perl, but the pieces are all there. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Teamwork is essential. It lets you blame someone else. From bignose+hates-spam at benfinney.id.au Wed Jan 7 20:56:58 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 12:56:58 +1100 Subject: Unexpected scientific notation References: Message-ID: <87priyh85x.fsf@benfinney.id.au> Paul McNett

writes: > The app bundles python 2.5.2 using py2exe. > > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what > could be causing this. What would be choosing to display such a > normal number in scientific notation? As I understand it, the Python string formatting operations use the operating system's C library to perform (some of?) the formatting. The different behaviours you see might therefore be caused by different C libraries in the operating system. To avoid these and related problems, I would avoid floating point wherever possible and use the ?Decimal? type for representing decimal numbers. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From ndbecker2 at gmail.com Wed Jan 7 20:58:41 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 20:58:41 -0500 Subject: buffer creates only read-only buffer? Message-ID: m = mmap.mmap (fd, 64, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) b2 = buffer (m) print b2 Why read-only? Why doesn't 'buffer' allow creation of read-write? Should buffer constructor take an additional optional arg for specifying this? Doc doesn't say anything about the fact that it's read only. From p at ulmcnett.com Wed Jan 7 21:04:16 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 18:04:16 -0800 Subject: Unexpected scientific notation In-Reply-To: References: <49655017.6010100@ulmcnett.com> Message-ID: <49655F20.1020901@ulmcnett.com> Robert Kern wrote: > Paul McNett wrote: >> One of my users has reported that my app is giving them scientific >> notation instead of decimal notation for one specific value among many >> that display properly. I am unable to reproduce on my end, and this is >> the first I've heard of anything like this since the app's launch 2 >> years ago. >> >> The app bundles python 2.5.2 using py2exe. >> >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what could >> be causing this. What would be choosing to display such a normal >> number in scientific notation? >> >> Ideas? > > Locales? Do you at last know the code that's responsible for formatting > the number? I do use locale.format, but I use it for all numbers, and only one such number displays in scientific notation - the rest are fine. Here's the code: 1355 def uom_string(self, val): 1356 """Given a decimal value, format it for string display.""" 1357 if self.unit_of_measure == "inches": 1358 fd = dabo.dAppRef.getSSPref("fraction_display") 1359 if fd == "decimal": 1360 return '%s"' % locale.format("%.5f", val.normalize(), True) 1361 else: 1362 return '%s"' % fractions.getImperial(val) 1363 elif self.unit_of_measure == "millimeters": 1364 #return u"%s\u339C" % self.uom_round(val) 1365 return "%smm" % locale.format("%.1f", self.uom_round(val), True) 1366 else: 1367 raise ValueError, "Unit of Measure '%s' not recognized." % self.unit_of_measure In this case, self.unit_of_measure == "inches" and fd == "decimal". Thanks Paul From greno at verizon.net Wed Jan 7 21:09:01 2009 From: greno at verizon.net (Gerry Reno) Date: Wed, 07 Jan 2009 21:09:01 -0500 Subject: Distutils, bdist_XXX, rpmbuild issues Message-ID: <4965603D.7030207@verizon.net> I've been trying to use the "built distribution" distutils commands such as bdist_rpm to create distro-specific packages for python applications but I'm running into some thorny issues specifically with pre-release versioning of source distributions and built distributions and how to get a "final" release to update these pre-release distributions. For example: We have an application, foo-5.0.0, and we want to put out some pre-release candidates for testing, so we set the version to "5.0.0_rc1" in setup.py. We create the source distribution with: $ python setup.py sdist which creates a source archive, foo-5.0.0_rc1.tar.gz. We extract this archive and 'cd' into the foo-5.0.0_rc1 directory and create a built distribution with: $ python setup.py bdist_rpm which creates source and binary RPMS in the form: foo-5.0.0_rc1-1.noarch.rpm. So we think everything is fine. Everyone installs and tests using the pre-release candidate and subsequent candidates but when you eventually get to the final release, foo-5.0.0, and build your final release RPMS, foo-5.0.0-1.noarch.rpm, you find that it will not update your last pre-release candidate RPM, foo-5.0.0_rcX-1.noarch.rpm because it is not "rpm newer". So I've been working on this for a while but have not found a good way to do this by setting options in a setup.cfg file. It seems like for RPM purposes we have to keep the version to "5.0.0" and set "release" to "0_rcX" for the pre-release candidates and this will work for RPM purposes but then "sdist" does not generate the correct tarball names for each pre-release candidate. It always generates foo-5.0.0.tar.gz. Has anyone managed to solve this issue or is distutils in need of some enhancement. We need the "sdist" command to generate distinct pre-release candidate tarball names. And we need the "bdist_XXX" commands to generate distro-specific package naming such that the pre-release candidate packages can be updated by the final release package. Regards, Gerry From ndbecker2 at gmail.com Wed Jan 7 21:14:50 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 21:14:50 -0500 Subject: mmap only supports string Message-ID: Problem is, AFAIK a string can only be created as a copy of some other data. Say I'd like to take some large object and read/write to/from mmap object. A good way to do this would be the buffer protocol. Unfortunately, mmap only supports string. A string could only be created after copying the original object AFAIK. I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. Specifically, mmap slice should support buffer protocol. From ndbecker2 at gmail.com Wed Jan 7 21:29:45 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Jan 2009 21:29:45 -0500 Subject: mmap doesn't support weakref Message-ID: r = weakref.ref (m) TypeError: cannot create weak reference to 'mmap.mmap' object I believe it would be very useful for mmap object to support weakref. Can it be added? From bignose+hates-spam at benfinney.id.au Wed Jan 7 21:36:54 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 13:36:54 +1100 Subject: Distutils, bdist_XXX, rpmbuild issues References: Message-ID: <87ljtmh6bd.fsf@benfinney.id.au> Gerry Reno writes: > We have an application, foo-5.0.0, and we want to put out some > pre-release candidates for testing, so we set the version to > "5.0.0_rc1" in setup.py. That's where your problems start (as you no doubt surmised). If you want version numbers to compare in a certain order, you should name them so that the version string will trivially compare in that order. > Has anyone managed to solve this issue or is distutils in need of > some enhancement. Surely the solution is to choose version strings that will compare correctly without complicated algorithms? -- \ ?A fine is a tax for doing wrong. A tax is a fine for doing | `\ well.? ?anonymous | _o__) | Ben Finney From prologic at shortcircuit.net.au Wed Jan 7 21:40:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 12:40:26 +1000 Subject: subclassing multiprocessing.Process Message-ID: Hey all, Just a quick clarification on multiprocessing' Process object. If I were to subclass this, say: class Foo(Process): def foo(self): ... def run(self): ... Would the parent and child objects be identical ? That is, would the same methods of Foo exist in the child ? Basically I'm trying to create a Process object, and within that a Pipe to communicate between the parent and child processes. cheers James -- -- "Problems are solved by method" From rhodri at wildebst.demon.co.uk Wed Jan 7 21:46:21 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 08 Jan 2009 02:46:21 -0000 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: On Thu, 08 Jan 2009 00:45:06 -0000, wrote: > When I started using Python I had no problem with Python's > assignment semantics because I had been using references in > Perl for years. I did not have a very hard time with Perl's > references, after I recognized their similarities to C's > pointers. But as I recall, it took a *long* time to wrap > my mind around C pointers. I'd suggest that part of the reason for that is C's blurring of the line between arrays and pointers. You can treat them interchangeably enough of the time that when you can't it catches you by surprise. My experience of teaching twelve-year olds Python is that they understand assignment when it's explained in terms of giving names to these objects (numbers, strings, wombats...) that we've already shown them. It's a lot harder to get them to understand the "putting an object into a labelled box" model when working with other languages. I don't know why this should be, but it is. -- Rhodri James *-* Wildebeeste Herder to the Masses From acooke.org at gmail.com Wed Jan 7 21:46:55 2009 From: acooke.org at gmail.com (acooke.org at gmail.com) Date: Wed, 7 Jan 2009 18:46:55 -0800 (PST) Subject: Generator metadata/attributes Message-ID: Hi, (I searched back and found some previous discussion on generator attributes that seemed to be related to callable generators - this is NOT that, as far as I can tell) I want to associate some data with a generator. This is in a decorator function, as it happens; the generator is being returned and I want to add some info that is useful for debugging later. I have tried modifying both .__doc__ and an arbitrary attribute, but the first is read-only, and the second does not exist (ie you cant just add one by writing to it; same error with setattr). I realise I could create my own wrapper that implements __next__ (I am using Python 3 and haven't checked the exact interface required, but I guess it's something like that), and add the information that way, but I am worried I am doing something too complicated. Is there really no way to stick some arbitrary data onto a generator (from a function that "yield"s)? In case it's any help, the decorator is basically: def mydecorator(f): def decorate(self, *args): generator = f(self, *args) # none of these work generator.__doc__ = 'From ' + str(self) generator.description = 'From ' + str(self) setattr(generator, 'description', 'From ' + str(self)) return generator return decorate and it's used like: class ... @mydeocrator def foo(self, ...): yield... Thanks, Andrew From greno at verizon.net Wed Jan 7 21:52:50 2009 From: greno at verizon.net (Gerry Reno) Date: Wed, 07 Jan 2009 21:52:50 -0500 Subject: Distutils, bdist_XXX, rpmbuild issues In-Reply-To: <87ljtmh6bd.fsf@benfinney.id.au> References: <87ljtmh6bd.fsf@benfinney.id.au> Message-ID: <49656A82.6040604@verizon.net> Ben Finney wrote: > Gerry Reno writes: > > >> We have an application, foo-5.0.0, and we want to put out some >> pre-release candidates for testing, so we set the version to >> "5.0.0_rc1" in setup.py. >> > > That's where your problems start (as you no doubt surmised). If you > want version numbers to compare in a certain order, you should name > them so that the version string will trivially compare in that order. > In many instances we don't get to make that decision when we join projects already in motion. Otherwise, I would not have bothered to post the problem to the list. The fact is that many applications use version string constructs such as I illustrated, "5.0.0_rc1" when they create their release candidates. And yes, the final release, "5.0.0", is not lexically superior. But, as much as I might like that everyone would not do this, I cannot change the whole world which has developed a habit of such things. So I am looking for a solution that works with the world as it is. Regards, Gerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 7 21:56:00 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 08 Jan 2009 02:56:00 -0000 Subject: How to store passwords? In-Reply-To: <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> References: <24f4451f-efde-48d2-8d78-f405540cd5cf@35g2000pry.googlegroups.com> <58968e34-eed2-4ddc-8ed7-e86d3c248d84@p36g2000prp.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 21:06:07 -0000, Oltmans wrote: > But the thing is that I will ask the user for user name and password > only once i.e. when they start the application for the first time. > After that, I'm not supposed to ask the user name and password again. > So in this scenario, if I store a hash on the disk I cannot retrieve > plain-text string back from my hash as I've to send user name and > password to the server in plain-text. The words "massive security hole" spring to mind. Does your server really require you to reauthenticate so often? Can't you invoke some kind of secured protocol instead? -- Rhodri James *-* Wildebeeste Herder to the Masses From jstroud at mbi.ucla.edu Wed Jan 7 22:14:55 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 07 Jan 2009 19:14:55 -0800 Subject: Generator metadata/attributes In-Reply-To: References: Message-ID: acooke.org at gmail.com wrote: > Hi, > > (I searched back and found some previous discussion on generator > attributes that seemed to be related to callable generators - this is > NOT that, as far as I can tell) > > I want to associate some data with a generator. This is in a > decorator function, as it happens; the generator is being returned and > I want to add some info that is useful for debugging later. I have > tried modifying both .__doc__ and an arbitrary attribute, but the > first is read-only, and the second does not exist (ie you cant just > add one by writing to it; same error with setattr). > > I realise I could create my own wrapper that implements __next__ That is what you are going to have to do. Immutable python builtins work that way: py> i = 4 py> i.bob = 2 ------------------------------------------------------------ Traceback (most recent call last): File "", line 1, in : 'int' object has no attribute 'bob' py> i.__doc__ = 'I am an int' ------------------------------------------------------------ Traceback (most recent call last): File "", line 1, in : 'int' object attribute '__doc__' is read-only James From musiccomposition at gmail.com Wed Jan 7 22:27:44 2009 From: musiccomposition at gmail.com (Benjamin) Date: Wed, 7 Jan 2009 19:27:44 -0800 (PST) Subject: Interpreter & Thread state & Frame structures. References: Message-ID: <0a7a0b16-5e8d-46af-a8ef-f8ee696acaaa@i24g2000prf.googlegroups.com> On Jan 7, 7:42?am, alessiogiovanni.bar... at gmail.com wrote: > Hi to all, > there are some fields in the PyInterpreterState and PyThreadState > obscures. > PyInterpreterState: > ? 1) Why there are the fields *next and *tstate_head? When there are multiple interpreters active, they are kept in a linked list. *next refers to the next interpreter state in the list. > > PyThreadState: > ? 1) Why there is the field *next? ditto for thread states > > An object PyFrameObject is a portion of code, with a state. But > exactly? Contents of a method/function, or more simply any block > indented of code? For example, this code: > ? ? def foo(s): > ? ? ? ? if s > 0: > ? ? ? ? ? ? return True > ? ? ? ? else: > ? ? ? ? ? ? return False > > how much frames are? 1 in this case. Each, module, class, function (and method) have a code object which corresponds to one frame when it is executed. From jeff at jmcneil.net Wed Jan 7 22:57:17 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 7 Jan 2009 19:57:17 -0800 (PST) Subject: Generator metadata/attributes References: Message-ID: You'll see the same behavior if you attempt to add an attribute to an instance of object as well. >>> object().t = 5 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 't' >>> You'll have to build your own iterator or wrap the generator object and delegate calls to it. If you elect the latter, you should also ensure that send and throw and gang work properly. Perhaps something nice and thin using getattr within your wrapper class. Jeff On Jan 7, 9:46?pm, acooke.... at gmail.com wrote: > Hi, > > (I searched back and found some previous discussion on generator > attributes that seemed to be related to callable generators - this is > NOT that, as far as I can tell) > > I want to associate some data with a generator. ?This is in a > decorator function, as it happens; the generator is being returned and > I want to add some info that is useful for debugging later. ?I have > tried modifying both .__doc__ and an arbitrary attribute, but the > first is read-only, and the second does not exist (ie you cant just > add one by writing to it; same error with setattr). > > I realise I could create my own wrapper that implements __next__ (I am > using Python 3 and haven't checked the exact interface required, but I > guess it's something like that), and add the information that way, but > I am worried I am doing something too complicated. ?Is there really no > way to stick some arbitrary data onto a generator (from a function > that "yield"s)? > > In case it's any help, the decorator is basically: > > def mydecorator(f): > ? def decorate(self, *args): > ? ? generator = f(self, *args) > ? ? # none of these work > ? ? generator.__doc__ = 'From ' + str(self) > ? ? generator.description = 'From ' + str(self) > ? ? setattr(generator, 'description', 'From ' + str(self)) > ? ? return generator > ? return decorate > > and it's used like: > > class ... > ? @mydeocrator > ? def foo(self, ...): > ? ? yield... > > Thanks, > Andrew From rtw at freenet.co.uk Wed Jan 7 23:18:19 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 07 Jan 2009 22:18:19 -0600 Subject: Generator metadata/attributes References: Message-ID: wrote in news:d301c93a-8a73-4cbb-9601-fe0c18a94f97 @v5g2000prm.googlegroups.com in comp.lang.python: > I realise I could create my own wrapper that implements __next__ (I am > using Python 3 and haven't checked the exact interface required, but I > guess it's something like that), and add the information that way, but > I am worried I am doing something too complicated. Is there really no > way to stick some arbitrary data onto a generator (from a function > that "yield"s)? > > In case it's any help, the decorator is basically: > > def mydecorator(f): > def decorate(self, *args): > generator = f(self, *args) You can use something like this: def mydecorator( f ): def decorated(self, *args): for i in f(self, *args): yield i decorated.__doc__ = 'madeup doc string' return decorated class Example( object ): @mydecorator def foo(self, a, b, ): yield 1 print( help( Example ) ) But realise that when the decorator ("mydecorator" above) is run neither the class ("Example") or the instance (self) is available. Which limits somewhat the debugging information you can attach automatically. Rob. -- http://www.victim-prime.dsl.pipex.com/ From p at ulmcnett.com Wed Jan 7 23:23:52 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 20:23:52 -0800 Subject: Unexpected scientific notation In-Reply-To: <87priyh85x.fsf@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> Message-ID: <49657FD8.8020001@ulmcnett.com> [Some day hopefully I'll remember to change the to: address to python-list at python.org instead of the original sender. I always end up sending the first reply to the sender, then going "oops, forgot to hit 'reply-all'", and sending another copy to the list.] Ben Finney wrote: > Paul McNett

writes: > >> The app bundles python 2.5.2 using py2exe. >> >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what >> could be causing this. What would be choosing to display such a >> normal number in scientific notation? > > As I understand it, the Python string formatting operations > > use the operating system's C library to perform (some of?) the > formatting. > > The different behaviours you see might therefore be caused by > different C libraries in the operating system. > > To avoid these and related problems, I would avoid floating point > wherever possible and use the ?Decimal? type for representing decimal > numbers. Thanks. I forgot to mention that all numbers are already instances of decimal.Decimal, not float. As I mentioned in a prior message, they do go through a locale.format() call to display the value. Paul From gshanemiller at verizon.net Thu Jan 8 00:08:42 2009 From: gshanemiller at verizon.net (Shane) Date: Wed, 7 Jan 2009 21:08:42 -0800 (PST) Subject: parallel and/or synchronous start/run/stop on multiple boxes Message-ID: Consider a network of 3 fully-connected boxes i.e. every box as a TCP- IP connection to every other box. Suppose you start a python program P on box A. Is there a Python mechanism for P to send a copy of itself to box B or C then start that program P on B or C by running a method p in P? Is there a way that P on A could wait for that result? Bottom line: we have a number of needs in which it'd very convienent to write a phython program, install and run it, so that it could automatically propogate itself to wherever the code needs to go and run itself so that there could be multiple copies of the code running on different boxes with synchrounous (maybe asychronous) communication. Shane From bignose+hates-spam at benfinney.id.au Thu Jan 8 00:14:04 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 16:14:04 +1100 Subject: Replying to list messages (was: Unexpected scientific notation) References: <87priyh85x.fsf@benfinney.id.au> Message-ID: <87hc4agz1f.fsf_-_@benfinney.id.au> Paul McNett

writes: > [Some day hopefully I'll remember to change the to: address to > python-list at python.org instead of the original sender. Even better: Take full advantage of the standards-compliant messages from the list, by using the ?Reply to list? function of your RFC 2369 compliant mail program. That way the message is sent to the declared list posting address, without you having to change anything. If your mail program still doesn't have such a function, over a decade since RFC 2369 was written, lobby the vendor to add it. Or, in the case of free software, act some way yourself (write code, pay someone else to do so, or some other action) to have that function added for everyone. For Thunderbird (which I see you're using, Paul), the open bug report is . Meanwhile, you can install an add-on to provide the function . > I always end up sending the first reply to the sender, then going > "oops, forgot to hit reply-all'", and sending another copy to the > list.] At least that's merely a minor inconvenience; easily rectified by just sending the message again using the correct function. That's much better, of course, than the opposite situation which exists on some misconfigured mailing lists: that a message sent using the ?Reply to sender? function, with content written in the knowledge that only the original message's sender should be reading it, instead ends up going to the mailing list. That damage can't be undone. Thanks to the Python mailing list administrators for conforming to the standards and not breaking the configuration like that! -- \ ?[T]he question of whether machines can think ? is about as | `\ relevant as the question of whether submarines can swim.? | _o__) ?Edsger W. Dijkstra | Ben Finney From prologic at shortcircuit.net.au Thu Jan 8 00:17:35 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:17:35 +1000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:08 PM, Shane wrote: > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > IP connection to every other box. > > Suppose you start a python program P on box A. Is there a Python > mechanism for P to send a copy of itself to box B or C then start that > program P on B or C by running a method p in P? Is there a way that P > on A could wait for that result? No, python provides no such mechanism. However, I would highly recommend you take a look at circuits (1) for this task - as it's been especially developed for distributed processing in the manner you describe above. In order for your program to propagate itself, you would have to rely on ssh (recommended). There are several good ssh libraries/clients for python, and pexpect might come in handy as well. cheers James 1. http://trac.softcircuit.com.au/circuits/ From sibteym at infotechsw.com Thu Jan 8 00:18:10 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Thu, 8 Jan 2009 10:48:10 +0530 Subject: Multiprocessing takes higher execution time In-Reply-To: <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: <00f701c97150$7fcc2f20$5fc513ac@pwit.com> Hello, Please see the code I have send in attachment. Any suggestions will highly appreciate. Thanks and Regards, Gopal -----Original Message----- From: Grant Edwards [mailto:invalid at invalid] Sent: Wednesday, January 07, 2009 8:58 PM To: python-list at python.org Subject: Re: Multiprocessing takes higher execution time On 2009-01-07, Steve Holden wrote: >> I use multiprocessing to compare more then one set of files. >> >> For comparison each set of files (i.e. Old file1 Vs New file1) >> I create a process, >> >> Process(target=compare, args=(oldFile, newFile)).start() >> >> It takes 61 seconds execution time. >> >> When I do the same comparison without implementing >> multiprocessing, it takes 52 seconds execution time. > My first suggestion would be: show us some code. We aren't > psychic, you know. I am! He's only got one processor, and he's just been bit by Amdahl's law when P<1 and S<1. There you have a perfectly "psychic" answer: an educated guess camoflaged in plausible-sounding but mostly-bullshit buzzwords. A better psychic would have avoided making that one falsifiable statement (he's only got one processor). -- Grant Edwards grante Yow! Hello. Just walk at along and try NOT to think visi.com about your INTESTINES being almost FORTY YARDS LONG!! -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: zipFilesComparision.txt URL: From tjreedy at udel.edu Thu Jan 8 00:22:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 00:22:44 -0500 Subject: why cannot assign to function call In-Reply-To: References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> Message-ID: Rhodri James wrote: > On Thu, 08 Jan 2009 00:45:06 -0000, wrote: > >> When I started using Python I had no problem with Python's >> assignment semantics because I had been using references in >> Perl for years. I did not have a very hard time with Perl's >> references, after I recognized their similarities to C's >> pointers. But as I recall, it took a *long* time to wrap >> my mind around C pointers. > > I'd suggest that part of the reason for that is C's blurring > of the line between arrays and pointers. You can treat them > interchangeably enough of the time that when you can't it > catches you by surprise. > > My experience of teaching twelve-year olds Python is that > they understand assignment when it's explained in terms of > giving names to these objects (numbers, strings, wombats...) > that we've already shown them. It's a lot harder to get > them to understand the "putting an object into a labelled > box" model when working with other languages. I don't know > why this should be, but it is. Kids have little experience with being 'the guest in Room 203' or 'the inmate in cell a-23'. From v+python at g.nevcal.com Thu Jan 8 00:28:14 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Wed, 07 Jan 2009 21:28:14 -0800 Subject: length of a tuple or a list containing only one element In-Reply-To: <490F572D.7070708@tim.thechases.com> References: <874p2pngab.fsf@benfinney.id.au> <490F572D.7070708@tim.thechases.com> Message-ID: <49658EEE.80308@g.nevcal.com> On approximately 11/3/2008 11:55 AM, came the following characters from the keyboard of Tim Chase: >>>> For making a literal tuple, parentheses are irrelevant; only the >>>> commas matter: >>> I don't think I'd go so far as to say that the parentheses around >>> tuples are *irrelevant*...maybe just relevant in select contexts >>> >>> >>> def foo(*args): >>> ... for i, arg in enumerate(args): >>> ... print i, arg >>> ... >>> >>> foo(1,2) >>> 0 1 >>> 1 2 >>> >>> foo((1,2)) # these parens are pretty important :) >>> 0 (1, 2) >>> >>> pedantically-grinning-ducktyping-and-running-ly yers, >> >> I'll see your pedantry and raise you one: >> >>> foo() >> >>> foo(()) >> 0 () > > And just because another "tuples without parens" case exists: > > >>> foo(,) > File "", line 1 > foo(,) > ^ > SyntaxError: invalid syntax > > To maintain the poker theme, I'd say "You raised, and I call" but my > call fails :-P > > -tkc > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm glad you guys had this thread, which I read with interest and some amusement back when it happened. I am an experienced programmer, but a relative newcomer to Python. And so it was, the last couple nights, that I spent much time looking for why my CherryPy configuration didn't work, and after much searching of the CherryPy documentation for a tracing technique (which I still wish I could find), I finally hacked the code to add an extra pprint. Even after that, I focused on the wrong data in the pprint output. At long last, I discovered that somehow my hash-of-hashes was mostly a hash-of-hashes, but there was a tuple in there that contained a hash too! Now how did that get in there? conf['/path'] = { 'item1': 'value1', 'item2': 'value2', }, So I was focusing on the items and values of the pprint, and they were all correct. But this tuple clearly didn't belong, but my brain was expecting that tuples would be surrounded by () in source... -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From p at ulmcnett.com Thu Jan 8 00:44:15 2009 From: p at ulmcnett.com (Paul McNett) Date: Wed, 07 Jan 2009 21:44:15 -0800 Subject: Replying to list messages In-Reply-To: <87hc4agz1f.fsf_-_@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: <496592AF.2020603@ulmcnett.com> Ben Finney wrote: > Paul McNett

writes: > >> [Some day hopefully I'll remember to change the to: address to >> python-list at python.org instead of the original sender. > > Even better: Take full advantage of the standards-compliant messages > from the list, by using the ?Reply to list? function of your RFC > 2369 compliant mail program. That way the message is sent to the > declared list posting address, without you having to change anything. > > If your mail program still doesn't have such a function, over a decade > since RFC 2369 was written, lobby the vendor to add it. Or, in the > case of free software, act some way yourself (write code, pay someone > else to do so, or some other action) to have that function added for > everyone. I remember taking advantage of that in KMail, before that program became unusably bloated. > For Thunderbird (which I see you're using, Paul), the open bug report > is . > Meanwhile, you can install an add-on to provide the function > . Thanks; I'll follow up with those. In general I don't tend to use add-ons because I have at least 3 computers I regularly use and it is a pain to keep them all configured consistently. >> I always end up sending the first reply to the sender, then going >> "oops, forgot to hit reply-all'", and sending another copy to the >> list.] > > At least that's merely a minor inconvenience; easily rectified by > just sending the message again using the correct function. Yep. > That's much better, of course, than the opposite situation which > exists on some misconfigured mailing lists: that a message sent using > the ?Reply to sender? function, with content written in the > knowledge that only the original message's sender should be reading > it, instead ends up going to the mailing list. That damage can't be > undone. Well, when you are a member of a public mailing list, replying to a thread, the expectation is that you are replying to the list, so I happen to think the correct behavior is the one you think is broken, because practicality beats purity. If I want to send a private message to someone, I'll start a new mail to that person, or simply copy/paste their email addy over the list address, but the most common case is that someone intends to reply to the list. But arguing about this here isn't going to change anything: opinions differ just like tabs/spaces and bottom-post/top-post. > Thanks to the Python mailing list administrators for conforming to the > standards and not breaking the configuration like that! Thanks to the Python mailing list volunteers for running such a well-oiled and popular list! Paul From nad at acm.org Thu Jan 8 00:44:58 2009 From: nad at acm.org (Ned Deily) Date: Wed, 07 Jan 2009 21:44:58 -0800 Subject: parallel and/or synchronous start/run/stop on multiple boxes References: Message-ID: In article , "James Mills" wrote: > On Thu, Jan 8, 2009 at 3:08 PM, Shane wrote: > > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > > IP connection to every other box. > > > > Suppose you start a python program P on box A. Is there a Python > > mechanism for P to send a copy of itself to box B or C then start that > > program P on B or C by running a method p in P? Is there a way that P > > on A could wait for that result? > > No, python provides no such mechanism. The multiprocessing module, new in the 2.6 standard library and available in PyPi as a backport to 2.4 and 2.5, supports managing of processes on both local and remote machines. The 2.6 module documentation has an "example/demo of how to use the managers.SyncManager, Process and others to build a system which can distribute processes and work via a distributed queue to a 'cluster' of machines on a network, accessible via SSH". -- Ned Deily, nad at acm.org From prologic at shortcircuit.net.au Thu Jan 8 00:45:18 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:45:18 +1000 Subject: asynchronous events with multithreading and multiprocessing with circuits Message-ID: Hi folks, For those interested, I have just completed implementing multiprocessing support for circuits (1). It has historically always had multithreading support. These components can be found in circuits.workers and are called: Thread and Process The reason these exist is to perform "work", ie: long-running and potentially blocking tasks that should not be handled with regular event handlers of components in a single process or thread. Here is the code that I used to test this with that utilizes 1 main process/thread, 1 additional thread and 1 additional process. ------------------------------------------------------------ #!/usr/bin/env python from time import sleep from circuits import listener, Event, Component, Debugger, Manager from workers import Thread, Process class Foo(Component): @listener("foo") def onFOO(self): print "foo" @listener("msg") def onMSG(self, s): print s class A(Thread): def run(self): while self.running: try: sleep(2) self.push(Event("Hello from A"), "msg") except KeyboardInterrupt: self.running = False break class B(Process): def run(self): while self.running: try: sleep(3) self.push(Event("Hello from B"), "msg") except KeyboardInterrupt: self.running = False break manager = Manager() #manager += Debugger() foo = Foo() a = A() b = B() manager += foo manager += a manager += b a.start() b.start() while True: try: manager.flush() b.poll() sleep(1) manager.push(Event(), "foo") except KeyboardInterrupt: break a.stop() b.stop() a.unregister() b.unregister() ------------------------------------------------------------ I'll be later adapating primes.py found in the examples/ directory of the circuits distribution to utilize multiprocessing as well as distributed processing. I may also provide other examples of typical use-cases (distributed and parallel csv processing for example). The result of running the above test results in the following (expected) output: ------------------------------------------------------------ $ python test.py foo foo Hello from A Hello from B foo foo Hello from A foo Hello from B foo Hello from A foo foo Hello from A Hello from B foo ^C ------------------------------------------------------------ Note: Each output line is approximately 1s in time. Have a nice day and happy hacking :) cheers James -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Thu Jan 8 00:47:19 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:47:19 +1000 Subject: asynchronous events with multithreading and multiprocessing with circuits In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:45 PM, James Mills wrote: > For those interested, I have just completed implementing > multiprocessing support for circuits (1). (...) PS: circuits can be found on PyPi or here: http://trac.softcircuits.com.au/circuits/ The code/support I mentioned is in the development branch. cheers James From prologic at shortcircuit.net.au Thu Jan 8 00:49:13 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 15:49:13 +1000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:44 PM, Ned Deily wrote: > The multiprocessing module, new in the 2.6 standard library and > available in PyPi as a backport to 2.4 and 2.5, supports managing of > processes on both local and remote machines. The 2.6 module > documentation has an "example/demo of how to use the > managers.SyncManager, Process and others to build a system which can > distribute processes and work via a distributed queue to a 'cluster' of > machines on a network, accessible via SSH". Wow! :) I didn't know that! It seems the multiprocessing library packs quite a punch! :) cheers James From narkewoody at gmail.com Thu Jan 8 00:56:59 2009 From: narkewoody at gmail.com (Steven Woody) Date: Thu, 8 Jan 2009 13:56:59 +0800 Subject: frontend + backend style application design Message-ID: Hi, I am considering write an application, its core functionalities should be implemented in a command-line application with which a user can interact via its command line interface. This kind of command line interface can help batch usage of the application. On the other hand, I still want a GUI front-end which does not implement any core functionality but only provides a rich GUI interface and communicates with the command-line back-end. I am asking you experts, in the terms of python, what idea/tools/module support this kind of architecture? Thanks in advance. - narke From prologic at shortcircuit.net.au Thu Jan 8 01:05:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 16:05:10 +1000 Subject: frontend + backend style application design In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 3:56 PM, Steven Woody wrote: > I am considering write an application, its core functionalities should > be implemented in a command-line application with which a user can > interact via its command line interface. This kind of command line > interface can help batch usage of the application. On the other hand, > I still want a GUI front-end which does not implement any core > functionality but only provides a rich GUI interface and communicates > with the command-line back-end. > > I am asking you experts, in the terms of python, what > idea/tools/module support this kind of architecture? Quite simple really. 1. Implement all your core functionality as part of a library. 2. Implement your command-line tools that utilize this library. 3. Implement your gui that also utilizes the same library. myproject/ | |-setup.py | |-myproject/ | |-__init__.py | |-foo.py |-bar.py |-gui.py | |-tools/ | |-foo.py |-bar.py |-myproject.py (gu) You can also take advantage of setuptools along with distutils and define "entry points" for your application. cheers James From esnow at verio.net Thu Jan 8 01:32:24 2009 From: esnow at verio.net (Eric Snow) Date: Wed, 7 Jan 2009 22:32:24 -0800 (PST) Subject: os.fork and pty.fork Message-ID: <1336d687-b147-4466-8c25-8edb1c23744b@w39g2000prb.googlegroups.com> I am trying to wrap my head around an issue here that has to do with running python without a tty. I use pexpect to connect to ssh and run some commands. However, if my script runs from a process which I forked using os.fork my pexpect spawn object can't open a good file descriptor in which to run my ssh command, as far as I can tell. pexpect uses pty.fork to fork the process, attach a tty, and run my command in the child with os.exec. When I go to expect something on the spawn object the read on the fd of the child returns EOF, which indicates that the child's fd is already closed before I did anything. This is the point at which I am trying to make sense of things. pty.fork gave pexpect the child's fd but does that fd actually go to a tty? Does the fact that my use of pexpect happens in a process which is not running in a tty, as it was generated from os.fork? It looks like pty.fork tries to use os.forkpty but I am not sure how an existing tty plays in to getting a new tty for the child process... Any insight into os.fork and pty.fork would be great. Thanks. -eric From bignose+hates-spam at benfinney.id.au Thu Jan 8 01:48:06 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 08 Jan 2009 17:48:06 +1100 Subject: Replying to list messages References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: <878wpmguop.fsf@benfinney.id.au> Paul McNett

writes: > Ben Finney wrote: > > For Thunderbird (which I see you're using, Paul), the open bug > > report is > > . > > Meanwhile, you can install an add-on to provide the function > > . > > Thanks; I'll follow up with those. In general I don't tend to use > add-ons because I have at least 3 computers I regularly use and it > is a pain to keep them all configured consistently. You're welcome. It sounds like you're definitely in the position of wanting to get the above bug fixed; hopefully you can use the frustration you expressed as motivation for getting progress on that. > > [some mailing lists are misconfigured such] that a message sent > > using the ?Reply to sender? function, with content written in > > the knowledge that only the original message's sender should be > > reading it, instead ends up going to the mailing list. That damage > > can't be undone. > > Well, when you are a member of a public mailing list, replying to a > thread, the expectation is that you are replying to the list, so I > happen to think the correct behavior is the one you think is broken, Those lists are misconfigured because they violate the email standards (in this case, RFC 2822) by munging the ?Reply-To? field, reserved for use only by the author of the message. That's broken, and enabling that broken behaviour by failing to provide a ?Reply to list? function in a mail client is also broken. More at . > If I want to send a private message to someone, I'll start a new > mail to that person, or simply copy/paste their email addy over the > list address All of that bother is avoided by simply using the ?Reply to author? function of any mail program, so long as the mailing list isn't misconfigured. > but the most common case is that someone intends to reply to the > list. Indeed it is, which is why RFC 2369 is a standard: it recommends (and just about every mailing list active today conforms by) providing fields in the header of mailing list messages to allow a mail program to implement the ?Reply to list? function for that common case. That's been a standard for over ten years. The mailing list programs are pretty much all conformant with it, and have been for many years. Any mail client that *still* isn't making use of those fields, not even for the very common use case of a ?Reply to list? function, is rather backward. > But arguing about this here isn't going to change anything: opinions > differ just like tabs/spaces and bottom-post/top-post. In cases like this, one side can simply be wrong :-) Best of luck getting your programs behaving as you want them to! -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From quian.xu at stud.tu-ilmenau.de Thu Jan 8 02:41:27 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Thu, 08 Jan 2009 08:41:27 +0100 Subject: pg_result_status() alternative? References: <6sktmdF6t1jiU1@mid.uni-berlin.de> Message-ID: Gerhard H?ring wrote: > What are you testing, really? "Normal" Python code should use a > PostgreSQL DB-API module or a wrapper on top of it, like SQLAlchemy. > > Generally, you shouldn't have to drop down to protocol-level functions, > unless you're developing a PostgreSQL adapter yourself. > > Care to explain why you're messing around with this low-level functions? > I am using pgpool (a middleware that works between PostgreSQL servers and a PostgreSQL database client. http://pgpool.projects.postgresql.org/) for data republication. And it works not stable. Sometimes it crashes after couple of weeks. So I want to test. whether the pgpool behaviors correctly. I performed same queries to a real postgresql database and to a pgpool by using the pg module (http://www.pygresql.org/pg.html). Same query results and same frontend/backend protocol responses are expected. 1. There is no problem to compare the query results. 2. There is no problem to retrieve the protocol responses of pgpool (by calling an API of pgpool) as well. 3. But I have problem to retrieve the protocol responses of a real postgresql database. This is my motivation of using the low-level function. --Qian From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 02:45:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 07:45:35 GMT Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Only in the sense that the behaviour of *real world* objects don't >> entirely match the behaviour of Python objects. If you just accept that >> Python objects can be in two places at once, an unintuitive concept I >> accept but hardly difficult to grasp, then you don't need to mention >> references. > > To my mind, explaining that objects can actually be in two (or three, or > any unbounded number) of places at once, stashed inside each other to an > arbitrary degree -- that looks like the excuses of someone who's been > caught in a lie. Maybe it was a useful lie-to-children, meant to avoid > explaining the full details in advance, but the time comes to put away > childish things, and learn the truth. (I can't believe I just quoted > Paul. I feel all dirty.) All analogies are lies-to-children. I don't think this is any worse than the lie-to-children about magic pieces of string that you can only handle by the paperweight at one end. Both analogies contain leaky abstractions. > The `they're just objects' model is very simple, but gets tied up in > knots explaining things. The `it's all references' model is only a > little more complicated, but explains everything. But it *over* explains, because it implies things that "everybody knows" about references in other languages that aren't true for Python. Of course it's not literally true that "everybody knows" that you can use references to implement a swap(x, y) procedure. But people coming from a C or Pascal background tend to assume that everything is like C/Pascal, and there are a lot of them. If C was a rare, unfamiliar language, my opposition to using the term "reference" would be a lot milder. Maybe in another five years? > No, indeed. Python is a language for talking about paperweights. And > it's because of the paperweights that the duck-typing works: all the > paperweights are the same shape and size, so they're physically > interchangeable. Okay, the abstraction has leaked again... are the paperweights references to the objects, or the names we've bound objects to? I'm confused... How do we deal with anonymous objects in your model? -- Steven From per.olav.kroka at ericsson.com Thu Jan 8 02:58:34 2009 From: per.olav.kroka at ericsson.com (Per Olav Kroka) Date: Thu, 8 Jan 2009 08:58:34 +0100 Subject: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid In-Reply-To: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> References: <50697b2c0901070940h33de4a11xc2fb1f978a29bc23@mail.gmail.com> Message-ID: <61D8D34BB13CFE408D154529C120E0790243F7E8@eseldmw101.eemea.ericsson.se> FYI: the '/*.*' is part of the error message returned. -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Wednesday, January 07, 2009 6:40 PM To: Per Olav Kroka Cc: python-list at python.org Subject: Re: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid > PS: Why does the listdir() function add '*.*' to the path? Don't know what you're talking about. It doesn't do any globbing or add "*.*" to the path. Its exclusive purpose is to list the contents of a directory, so /in a sense/ it does add "*.*", but then not adding "*.*" would make the function completely useless given its purpose. > PS2: Why does the listdir() function add '/*.*' to the path on windows > and not '\\*.*' ? You can use either directory separator (\ or /) with the Python APIs on Windows. r"c:\WINDOWS\" works just as well as "c:/WINDOWS/". Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sri_annauni at yahoo.co.in Thu Jan 8 02:59:37 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Thu, 8 Jan 2009 13:29:37 +0530 (IST) Subject: How to deepcopy a list of user defined lists? Message-ID: <35331.99250.qm@web7908.mail.in.yahoo.com> Hi, I have a class which is a subclass of builtin-type list. #------------------------------------------------------------------------------ class clist(list): ??? def __new__(cls, values, ctor): ??????? val = [] ??????? for item in values: ??????????? item = ctor(item) ??????????? val.append(item) ??????? ??????? self = list.__new__(cls, val) ??????? self.__values = val ??????? self.__ctor = ctor ??????? return self #----------------------------------------------------------------------------------- I have a list of clists, say c1 = [clist1, clist2, clist3] How do i deepcopy this list? I tried using copy.deepcopy() method. But i got?some errors. Please suggest me. Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From clp2 at rebertia.com Thu Jan 8 03:26:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 00:26:27 -0800 Subject: How to deepcopy a list of user defined lists? In-Reply-To: <35331.99250.qm@web7908.mail.in.yahoo.com> References: <35331.99250.qm@web7908.mail.in.yahoo.com> Message-ID: <50697b2c0901080026vcd1637bk1208d33e976ee9e9@mail.gmail.com> On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > def __new__(cls, values, ctor): > val = [] > for item in values: > item = ctor(item) > val.append(item) > > self = list.__new__(cls, val) > self.__values = val > self.__ctor = ctor > return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] > How do i deepcopy this list? I tried using copy.deepcopy() method. But i got some errors. Please suggest me. And those errors are? Please include a full Traceback. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 03:37:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 08:37:12 GMT Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <20090105020311.GP28417@dragontoe.org> Message-ID: On Wed, 07 Jan 2009 03:45:00 -0800, sturlamolden wrote: > On Jan 7, 2:02 am, Steven D'Aprano > wrote: > >> In Python code, there are no references and no dereferencing. > > The why does CPython keep track of reference counts? Two different levels of explanation. At the level of Python code, you don't see reference counts. You never manipulate reference counts directly. The gc module does expose them, if you want to see them, but the gc module deliberately peaks behind the curtains. It's special. At the implementation level, CPython uses references so it needs reference counts. Jython doesn't keep reference counts at all, because it uses Java's garbage collection (or so I understand). And the hypothetical Distributed Python uses clones of objects and a daemon which keeps them in sync, and hence there are no reference counts because each clone is attached once and once only. >> You can't, because Python doesn't have references. In a language with >> references, that's easy. > > Python does not 'pass-by-reference' as Fortran or Pascal do. That's right. But sadly, if you tell people that Python uses references, many people will say "How do I pass a reference to this object to a function?". >>>> a = 123456789 >>>> b = [a] >>>> c = [a] >>>> d = [a, a] > >>>> b[0] is a > True >>>> c[0] is a > True >>>> d[0] is a > True >>>> d[1] is a > True > > Where is the object 'a' stored? Somewhere in memory, floating free, where it is referred to under the name 'a'. In CPython, it will be in the heap, unless it has been paged out to disk. In the lists 'b', 'c' and (twice) 'd'. I don't have a problem with objects being in two places at the same time. It's just a mental model. I understand that, underneath, the memory for the object is in *one place*, somewhere, because distributed storage is a hard problem and no existing Python does it. But I also understand that underneath, *everything* is just mutable bytes. There are no ints or strings or lists or dicts, they're just an abstraction. If you keep looking behind the curtains, looking at the implementation of each level of abstraction, eventually you'll get to bytes, and then electrons. If you go there, then you'll conclude that the object 'a' isn't anywhere. I'm happy with a high-level abstraction where Python objects can be in more than one place at once. Now, how do you implement such an abstraction? The easiest way is to have the object in one (hidden?) place, and have everywhere else use a pointer or reference to it. But that's a lower level of description than you can reach from Python code, because you can't access those pointers. You can only infer that they are there because otherwise you have to accept that objects can be in two places at once. Or because you've read the source code, but that's implementation. -- Steven From castironpi at gmail.com Thu Jan 8 03:40:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 8 Jan 2009 00:40:46 -0800 (PST) Subject: mmap only supports string References: Message-ID: <97e28947-8560-4029-beb5-d25ac1ef94da@y1g2000pra.googlegroups.com> On Jan 7, 8:14?pm, Neal Becker wrote: > Problem is, AFAIK a string can only be created as a copy of some other data. ?Say I'd like to take some large object and read/write to/from mmap object. ?A good way to do this would be the buffer protocol. ?Unfortunately, mmap only supports string. ?A string could only be created after copying the original object AFAIK. > > I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. ?Specifically, mmap slice should support buffer protocol. Hi. It is a weakness. Strings are supposed to be read-only in Python: so. You can use and get the PyObject_AsWriteBuffer C function from 'ctypes' if you are interested. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 8 03:51:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Jan 2009 08:51:40 GMT Subject: How to deepcopy a list of user defined lists? References: Message-ID: On Thu, 08 Jan 2009 13:29:37 +0530, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > ??? def __new__(cls, values, ctor): > ??????? val = [] > ??????? for item in values: > ??????????? item = ctor(item) > ??????????? val.append(item) > ??????? > ??????? self = list.__new__(cls, val) > ??????? self.__values = val > ??????? self.__ctor = ctor > ??????? return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] How do i > deepcopy this list? I tried using copy.deepcopy() method. But i got?some > errors. Please suggest me. Don't tell us what the errors are, I love guessing games!!! Let's see... is it TypeError because your class doesn't override the list.__init__ method? >>> clist1 = clist([1,2,3], str) Traceback (most recent call last): File "", line 1, in TypeError: list() takes at most 1 argument (2 given) Before you get to deepcopy, you actually need to have clist work correctly. Once you've done that, show us what error you get. -- Steven From sri_annauni at yahoo.co.in Thu Jan 8 03:53:42 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Thu, 8 Jan 2009 14:23:42 +0530 (IST) Subject: How to deepcopy a list of user defined lists? References: <35331.99250.qm@web7908.mail.in.yahoo.com> <50697b2c0901080026vcd1637bk1208d33e976ee9e9@mail.gmail.com> Message-ID: <537836.85410.qm@web7904.mail.in.yahoo.com> --> 964???????? self.__tmp_data = copy.deepcopy(self.__data) ??? 965 /usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil) ??? 160???? copier = _deepcopy_dispatch.get(cls) ??? 161???? if copier: --> 162???????? y = copier(x, memo) ??? 163???? else: ??? 164???????? try: /usr/local/python-2.5.1/lib/python2.5/copy.py in _deepcopy_list(x, memo) ??? 225???? memo[id(x)] = y ??? 226???? for a in x: --> 227???????? y.append(deepcopy(a, memo)) ??? 228???? return y ??? 229 d[list] = _deepcopy_list /usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil) ??? 187???????????????????????????? raise Error( ??? 188???????????????????????????????? "un(deep)copyable object of type %s" % cls) --> 189???????????????? y = _reconstruct(x, rv, 1, memo) ??? 190 ??? 191???? memo[d] = y /usr/local/python-2.5.1/lib/python2.5/copy.py in _reconstruct(x, info, deep, memo) ??? 320???? if deep: ??? 321???????? args = deepcopy(args, memo) --> 322???? y = callable(*args) ??? 323???? memo[id(x)] = y ??? 324???? if listiter is not None: /usr/local/python-2.5.1/lib/python2.5/copy_reg.py in __newobj__(cls, *args) ???? 90 ???? 91 def __newobj__(cls, *args): ---> 92???? return cls.__new__(cls, *args) ???? 93 ???? 94 def _slotnames(cls): : __new__() takes exactly 3 arguments (1 given) ----- Original Message ---- From: Chris Rebert To: srinivasan srinivas Cc: python-list at python.org Sent: Thursday, 8 January, 2009 1:56:27 PM Subject: Re: How to deepcopy a list of user defined lists? On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): >? ? def __new__(cls, values, ctor): >? ? ? ? val = [] >? ? ? ? for item in values: >? ? ? ? ? ? item = ctor(item) >? ? ? ? ? ? val.append(item) > >? ? ? ? self = list.__new__(cls, val) >? ? ? ? self.__values = val >? ? ? ? self.__ctor = ctor >? ? ? ? return self > #----------------------------------------------------------------------------------- > > I have a list of clists, say c1 = [clist1, clist2, clist3] > How do i deepcopy this list? I tried using copy.deepcopy() method. But i got some errors. Please suggest me. And those errors are? Please include a full Traceback. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/ From see.signature at no.spam Thu Jan 8 04:24:39 2009 From: see.signature at no.spam (Eric Brunel) Date: Thu, 08 Jan 2009 10:24:39 +0100 Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: On Wed, 07 Jan 2009 20:31:23 +0100, excord80 wrote: > Does Python work with Tk 8.5? I'm manually installing my own Python > 2.6.1 (separate from my system's Python 2.5.2), and am about to > install my own Tcl/Tk 8.5 but am unsure how to make them talk to > eachother. Should I install Tk first? If I put Tk into my home > directory (under "~/opt" most likely), is there some configure option > I need to pass Python to tell it where to find my Tk? There's some important information missing here: the platform you're on... Anyway, you should indeed install tcl/tk first. Then, assuming you're on Linux, you should edit the file named Setup in the Modules sub-directory of your Python installation, find the lines for the _tkinter module and edit them to match your installation. Then, you can build and install Python and it should work without problem. As for Python 2.6 / tk 8.5 compatibility, it depends on what you want to do. Since tk 8.5 still offers the 'regular' tk widgets, these will work in Python 2.6. If you want the new widgets (aka ttk), I'm not sure there are official wrappers for them in the distro (there weren't any last time I checked). If there aren't, you can find the 'pre-official' ones here: http://pypi.python.org/pypi/pyttk > Also, I see that Python comes with Tix. Was Tix supposed to be > something to make up for what was lacking in Tk prior to its 8.5 > release? Is Tix here to stay, or has it been eclipsed by what comes > with Tk 8.5 OOTB? I've never worked with Tix myself, but I'd say the widget set offered by tk/ttk is now quite complete. HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From nick at craig-wood.com Thu Jan 8 04:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 08 Jan 2009 03:31:16 -0600 Subject: Multiprocessing takes higher execution time References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: Sibtey Mehdi wrote: > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) > I create a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > When I do the same comparison without implementing > multiprocessing, it takes 52 seconds execution time. > The oldProjects and newProjects will contains zip files > i.e(oldxyz1.zip,oldxyz2.zip, newxyz2.zip,newxyz2.zip) > it will unzip both the zip files and compare all the files between old > and new (mdb files or txt files) and gives the result. > I do this comparision for n number set of zip files and i assigne each > set of zip files comparision to a process. I had a brief look at the code and your use of multiprocessing looks fine. How many projects are you processing at once? And how many MB of zip files is it? As reading zip files does lots of disk IO I would guess it is disk limited rather than anything else, which explains why doing many at once is actually slower (the disk has to do more seeks). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Thu Jan 8 04:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 08 Jan 2009 03:31:16 -0600 Subject: Creating new instances of subclasses. References: Message-ID: J. Cliff Dyer wrote: > I want to be able to create an object of a certain subclass, depending > on the argument given to the class constructor. > > I have three fields, and one might need to be a StringField, one an > IntegerField, and the last a ListField. But I'd like my class to > delegate to the proper subclass automatically, so I can just do: > > >>> f1 = Field('abc') > >>> f2 = Field('123') > >>> f3 = Field('D,E,F') > >>> f1.data > 'abc' > >>> f2.data > 123 > >>> f3.data > ['D','E','F'] > >>> type(f1) > > >>> type(f2) > > >>> type(f3) > > > I've come up with a solution, but I suspect there's something cleaner I > can do with the inheritance structure of __new__. I don't like > explicitly leapfrogging over Field.__new__ to object.__new__. > > My attempt is below: > > def is_list(arg): > if ',' in arg: return True > else: return False > > def is_integer(arg): > try: int(arg) > except ValueError: return False > else: return True > > class Field(object): > def __new__(cls, a): > if is_list(a): > return ListField(a) > elif is_integer(a): > return IntegerField(a) > else: > return StringField(a) > > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > class IntegerField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(IntegerField, self).__init__(s) > self.s = int(self.s) > > class ListField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > def __init__(self, s): > super(ListField, self).__init__(s) > self.s = s.split(',') > > class StringField(Field): > def __new__(cls, a): > return object.__new__(cls, a) > > Is there a cleaner way to do this? The main problem is that > Field.__new__ gets in the way of properly constructing the subclasses > once I've used it to select the proper subclass in the first place. How about this minor modification? # rest as above class Field(object): def __new__(cls, a): if cls != Field: return object.__new__(cls, a) if is_list(a): return ListField(a) elif is_integer(a): return IntegerField(a) else: return StringField(a) def __init__(self, input): super(Field, self).__init__(input) self.data = input class IntegerField(Field): def __init__(self, s): super(IntegerField, self).__init__(s) self.s = int(s) class ListField(Field): def __init__(self, s): super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass Or you could go for the full metaclass self registration scheme like this, which is actually less code since I delegated the "is this ok" test to the subclass - failing it returns a ValueError. class Field(object): registry = [] class __metaclass__(type): def __init__(cls, name, bases, dict): cls.registry.append(cls) def __new__(cls, a): if cls != Field: return object.__new__(cls, a) for subcls in cls.registry: if subcls == Field: continue try: return subcls(a) except ValueError: pass raise ValueError("Couldn't find subclass") def __init__(self, input): super(Field, self).__init__(input) self.data = input # Raise a ValueError in init if not suitable args for this subtype class IntegerField(Field): def __init__(self, s): s = int(s) super(IntegerField, self).__init__(s) self.s = s class ListField(Field): def __init__(self, s): if ',' not in s: raise ValueError("Not a list") super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass -- Nick Craig-Wood -- http://www.craig-wood.com/nick From amvds at xs4all.nl Thu Jan 8 04:31:45 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 09:31:45 GMT Subject: eval('07') works, eval('08') fails, why? Message-ID: <4965c801$0$193$e4fe514c@news.xs4all.nl> I am baffled by this: IDLE 1.2.2 ==== No Subprocess ==== >>> input() 07 7 >>> input() 08 Traceback (most recent call last): File "", line 1, in input() File "", line 1 08 ^ SyntaxError: invalid token of course, I can work around this using raw_input() but I want to understand why this happens. It boils down to: >>> eval('07') 7 >>> eval('08') Traceback (most recent call last): File "", line 1, in eval('08') File "", line 1 08 ^ SyntaxError: invalid token I can't think of anything that could cause this. Similarly, eval('09') fails, but for string 0x with x<8 it works. I am teaching myself Python in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-- >VisualBasic(2000)-->Python. I am a physicist, have programmed computers all my life but I won't understand the real tech jargon of present day computer science. Please keep it simple Thanks in advance, Alex van der Spek From hv at tbz-pariv.de Thu Jan 8 04:34:21 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 08 Jan 2009 10:34:21 +0100 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: <4965c801$0$193$e4fe514c@news.xs4all.nl> References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <6slvktF6q6dfU1@mid.individual.net> Hi, 07 is octal. That's way 08 is invalid. Try this: ===> python >>> print 011 9 >>> print int('011') 11 -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From hv at tbz-pariv.de Thu Jan 8 04:38:01 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 08 Jan 2009 10:38:01 +0100 Subject: Force exception on attribute write access only one object Message-ID: <6slvrrF71ds4U1@mid.individual.net> Hi, for debugging I want to raise an exception if an attribute is changed on an object. Since it is only for debugging I don't want to change the integer attribute to a property. This should raise an exception: myobj.foo=1 Background: Somewhere this value gets changed. But I don't now where. -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From prologic at shortcircuit.net.au Thu Jan 8 04:38:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 8 Jan 2009 19:38:02 +1000 Subject: Multiprocessing takes higher execution time In-Reply-To: References: <005701c970ad$c1b27140$5fc513ac@pwit.com> <0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: On Thu, Jan 8, 2009 at 7:31 PM, Nick Craig-Wood wrote: (...) > How many projects are you processing at once? And how many MB of zip > files is it? As reading zip files does lots of disk IO I would guess > it is disk limited rather than anything else, which explains why doing > many at once is actually slower (the disk has to do more seeks). If this is the case, this problem is not well suited to multi processing but rather distributed processing :) --JamesMills From dickinsm at gmail.com Thu Jan 8 04:38:35 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jan 2009 01:38:35 -0800 (PST) Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <9709ed24-8990-4f11-82e2-e6d32dddaa19@q18g2000vbn.googlegroups.com> On Jan 8, 9:31?am, Alex van der Spek wrote: > >>> eval('07') > 7 > >>> eval('08') > > Traceback (most recent call last): > ? File "", line 1, in > ? ? eval('08') > ? File "", line 1 > ? ? 08 > ? ? ?^ > SyntaxError: invalid token An integer literal with a leading zero is interpreted as an octal (base 8) number, so only digits in the range 0-7 (inclusive) are permitted in such a literal. Mark > > I can't think of anything that could cause this. Similarly, eval('09') > fails, but for string 0x with x<8 it works. I am teaching myself Python > in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-->VisualBasic(2000)-->Python. I am a physicist, have programmed computers > > all my life but I won't understand the real tech jargon of present day > computer science. Please keep it simple > > Thanks in advance, > Alex van der Spek From clp2 at rebertia.com Thu Jan 8 04:59:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 01:59:55 -0800 Subject: Force exception on attribute write access only one object In-Reply-To: <6slvrrF71ds4U1@mid.individual.net> References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: <50697b2c0901080159i15c15fb0n72c422ee68b5a707@mail.gmail.com> On Thu, Jan 8, 2009 at 1:38 AM, Thomas Guettler wrote: > Hi, > > for debugging I want to raise an exception if an attribute is > changed on an object. Since it is only for debugging I don't want > to change the integer attribute to a property. > > This should raise an exception: > > myobj.foo=1 > > Background: > Somewhere this value gets changed. But I don't now where. Completely untested: class Protector(object): def __init__(self, delegate, *forbidden): self.__delegate = delegate self.__forbidden = set(forbidden) def __getattr__(self, name): return getattr(self.__delegate, name) def __setattr__(self, name, value): if name in self.__forbidden: raise TypeError("attempt to assign to forbidden attribute '%s'" % name) setattr(self.__delegate, name, value) x = Foo() x = Protector(x, "bar") x.bar = 6 #should raise TypeError Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From n.kottiyath at gmail.com Thu Jan 8 05:06:51 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 8 Jan 2009 02:06:51 -0800 (PST) Subject: Traceback in Logging References: <25ace631-0ce7-41bf-ac53-b0e9bfb3b2dd@x16g2000prn.googlegroups.com> <61a22afc-1073-48f4-8d81-ead0fca500a3@r15g2000prd.googlegroups.com> <1c1794a1-b25f-4e8e-95df-1cbb6bd33d93@a26g2000prf.googlegroups.com> Message-ID: <3f5390c2-1ab0-4ce3-b902-29145e6c2ab0@w1g2000prm.googlegroups.com> The issue is that I am on Python 2.4 which doesnt support func name. I am using filename and lineno now. That does serve the purpose. Thank you, I had not checked all the parameters. Regards K Vinay Sajip wrote: > On Jan 6, 4:17 pm, Kottiyath wrote: > > I dont want the whole traceback. I just wanted to know where the log > > was generated from i.e. which procedure and which line. I have 3/4 > > points in many procedures where I encounter a small error (not an > > exception) and want to log it. So having individual names for each > > looks to be somewhat verbose - esp since the application is >10K LOC. > > > > Don't the funcName and lineno arguments in the format string work for > you? > > (See http://docs.python.org/library/logging.html#id1) > > Regards, > > Vinay Sajip From amvds at xs4all.nl Thu Jan 8 05:07:53 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 10:07:53 GMT Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: <4965d079$0$199$e4fe514c@news.xs4all.nl> Thanks much, that makes sense! Alex van der Spek From amvds at xs4all.nl Thu Jan 8 05:25:55 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 08 Jan 2009 10:25:55 GMT Subject: Reading C# serialized objects into Python? Message-ID: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Is there a way to read C# serialized objects into Python? I know the definition and structure of the C# objects. The Python docs say that pickle is specific to Python, which does not give me much hope. There may be a library however that I haven't come across yet. Thanks much, Alex van der Spek From anurag.bagaria at gmail.com Thu Jan 8 05:38:01 2009 From: anurag.bagaria at gmail.com (ANURAG BAGARIA) Date: Thu, 8 Jan 2009 11:38:01 +0100 Subject: using subprocess module in Python CGI In-Reply-To: <49518848.1080602@mattnordhoff.com> References: <49518848.1080602@mattnordhoff.com> Message-ID: Dear Matt, Thank you for your answer. This script is just a kind of test script so as to actually get it started on doing any simple job. The actual process would be much more complicated where in I would like to extract the tar file and search for a file with certain extension and this file would be given as input to another program installed on the server. Later on I would also like to use process.wait() so that I can get a status of the job execution and completion from the server and this information can be displayed to the users on the web-page where they submit their jobs. As to what I understand subprocess.call() would be the best in that case. Please correct, if I am wrong. The whole process is like a user submitting a tar file via the web-browser with some data and getting back the processed results in the form of a new tar file after performing a few operations on the files submitted as input tar file. Thanking you once again for your valuable time. Regards. On Wed, Dec 24, 2008 at 1:54 AM, Matt Nordhoff wrote: > ANURAG BAGARIA wrote: > > Hello, > > > > I am a Python Newbie and would like to call a short python script via > > browser using a CGI script, but initially I am trying to call the same > > python script directly through python command line. The script intends > > to perform a few command line in a pipe and I have written the script (a > > short one) as follows. > > > > #!/usr/bin/python > > > > import cgi, string, os, sys, cgitb, commands, subprocess > > import posixpath, macpath > > #file = "x.tar.gz" > > #comd = "tar -xf %s" % (file) > > #os.system(comd) > > #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../') > > comd = [\ > > "tar -xf x.tar.gz", \ > > "cd demo", \ > > "cp README ../", \ > > ] > > That's not how subprocess.call() works. You're trying to run an > executable called "tar -xf x.tar.gz", passing it the arguments "cd demo" > and "cp README ../". > > > outFile = os.path.join(os.curdir, "output.log") > > outptr = file(outFile, "w") > > errFile = os.path.join(os.curdir, "error.log") > > errptr = file(errFile, "w") > > retval = subprocess.call(comd, 0, None, None, outptr, errptr) > > errptr.close() > > outptr.close() > > if not retval == 0: > > errptr = file(errFile, "r") > > errData = errptr.read() > > errptr.close() > > raise Exception("Error executing command: " + repr(errData)) > > > > > > but after trying to execute this independently, I get the following > > error which I am unable to interpret : > > > > Traceback (most recent call last): > > File "process.py", line 18, in > > retval = subprocess.call(comd, 0, None, None, outptr, errptr) > > File "/usr/lib/python2.5/subprocess.py", line 443, in call > > return Popen(*popenargs, **kwargs).wait() > > File "/usr/lib/python2.5/subprocess.py", line 593, in __init__ > > errread, errwrite) > > File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child > > raise child_exception > > > > > > Could someone suggest where am I going wrong and if corrected, what is > > the probability of this script being compatible with being called > > through the browser. Thanking you people in advance. > > Well, you'd need to output something, but otherwise, sure, why not? > > print "Content-Type: text/html" > print > print "..." > > > Regards. > > Why do you even need to use subprocess to do this? All it's doing is > extracting the README file from a tarball, right? You can use the > tarfile module for that. > > > -- > -- I just want to LIVE while I'm alive. AB -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Jan 8 05:55:57 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 11:55:57 +0100 Subject: Reading C# serialized objects into Python? References: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Message-ID: <6sm4dtF72ul9U1@mid.uni-berlin.de> Alex van der Spek wrote: > Is there a way to read C# serialized objects into Python? > > I know the definition and structure of the C# objects. The Python docs > say that pickle is specific to Python, which does not give me much hope. > There may be a library however that I haven't come across yet. IronPython might be of help here. You might try to de-serialize in IronPython, and then serialize again using pickle. Diez From castironpi at gmail.com Thu Jan 8 06:11:05 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 8 Jan 2009 03:11:05 -0800 (PST) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> Message-ID: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> On Jan 8, 1:45?am, Steven D'Aprano wrote: > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: snip > > The `they're just objects' model is very simple, but gets tied up in > > knots explaining things. ?The `it's all references' model is only a > > little more complicated, but explains everything. > > But it *over* explains, because it implies things that "everybody knows" > about references in other languages that aren't true for Python. > > Of course it's not literally true that "everybody knows" that you can use > references to implement a swap(x, y) procedure. But people coming from a > C or Pascal background tend to assume that everything is like C/Pascal, > and there are a lot of them. If C was a rare, unfamiliar language, my > opposition to using the term "reference" would be a lot milder. Maybe in > another five years? > > > No, indeed. ?Python is a language for talking about paperweights. ?And > > it's because of the paperweights that the duck-typing works: all the > > paperweights are the same shape and size, so they're physically > > interchangeable. > > Okay, the abstraction has leaked again... are the paperweights references > to the objects, or the names we've bound objects to? I'm confused... > > How do we deal with anonymous objects in your model? > > -- > Steven Mark, hi, Steven, pleasure as always. Neither side is perfect or wild; (Do admit it); How do we decide what is best for newcomers to Python, depending on background? From mdw at distorted.org.uk Thu Jan 8 06:13:40 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 11:13:40 +0000 (UTC) Subject: why cannot assign to function call References: <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > I thought you were objecting to Python's use of the term "binding" > when you wrote: [snip] > in response to someone talking about "...all those who use the term > \"name binding\" instead of variable assignment...". Oh, that. Well, the terms are `binding' and `assignment'. Python doesn't need another name for assignment, because actually its idea of assignment is the same as anyone else's. The difference is in the way it deals with objects. See argument elsewhere. -- [mdw] From acooke.org at gmail.com Thu Jan 8 06:14:28 2009 From: acooke.org at gmail.com (acooke.org at gmail.com) Date: Thu, 8 Jan 2009 03:14:28 -0800 (PST) Subject: Generator metadata/attributes References: Message-ID: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Thanks folks. Will write my own class.... Andrew PS So for the record, this works and isn't as ugly/verbose as I was expecting: class TaggedWrapper(): def __init__(self, generator, logMixin, stream): self.__generator = generator self.__tag = '%s@%s' % (logMixin.describe(), stream) logMixin._debug('Created %s' % self) def __next__(self): return next(self.__generator) def __str__(self): return self.__tag def tag_generator(f): ''' Log the generator. ''' def call(self, stream): return TaggedWrapper(f(self, stream), self, stream) return call From __peter__ at web.de Thu Jan 8 06:29:19 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Jan 2009 12:29:19 +0100 Subject: Force exception on attribute write access only one object References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > for debugging I want to raise an exception if an attribute is > changed on an object. Since it is only for debugging I don't want > to change the integer attribute to a property. Why? > This should raise an exception: > > myobj.foo=1 > > Background: > Somewhere this value gets changed. But I don't now where. If you change your mind: class A(object): def __init__(self): self.foo = 42 a = A() b = A() class B(A): @property def foo(self): return self.__dict__["foo"] b.__class__ = B a.foo = "whatever" print b.foo b.foo = "whatever" Peter From steve at holdenweb.com Thu Jan 8 07:11:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:11:22 -0500 Subject: Python Community Service Awards Message-ID: <4965ED6A.8080207@holdenweb.com> Ben Finney recently wrote: > Paul McNett

writes: [...] >> I always end up sending the first reply to the sender, then going >> "oops, forgot to hit reply-all'", and sending another copy to the >> list.] [...] > Thanks to the Python mailing list administrators for conforming to the > standards and not breaking the configuration like that! > And for the way they keep the mail flowing day after day, and for the news/email gateway function, and ... Brad Knowles is a frequently unsung hero, who thoroughly deserves the PSF Community Award he got for his sterling service in the email area. He is ably assisted in this task by Ralf Hildebrandt and Patrick Koetter, authors of "The Book of Postfix". If you know of anyone whom you think deserves to be similarly honored please feel free to let me, or the PSF Board, know about it. When we can't reward people in a material way I believe it's very important to acknowledge these voluntary contributions. http://www.python.org/community/awards/psf-awards/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 07:14:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:14:50 -0500 Subject: Reading C# serialized objects into Python? In-Reply-To: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> References: <4965d4b3$0$182$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek wrote: > Is there a way to read C# serialized objects into Python? > > I know the definition and structure of the C# objects. The Python docs > say that pickle is specific to Python, which does not give me much hope. > There may be a library however that I haven't come across yet. > struct? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 07:18:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 07:18:06 -0500 Subject: why cannot assign to function call In-Reply-To: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: Aaron Brady wrote: > On Jan 8, 1:45 am, Steven D'Aprano > wrote: >> On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > snip >>> The `they're just objects' model is very simple, but gets tied up in >>> knots explaining things. The `it's all references' model is only a >>> little more complicated, but explains everything. >> But it *over* explains, because it implies things that "everybody knows" >> about references in other languages that aren't true for Python. >> >> Of course it's not literally true that "everybody knows" that you can use >> references to implement a swap(x, y) procedure. But people coming from a >> C or Pascal background tend to assume that everything is like C/Pascal, >> and there are a lot of them. If C was a rare, unfamiliar language, my >> opposition to using the term "reference" would be a lot milder. Maybe in >> another five years? >> >>> No, indeed. Python is a language for talking about paperweights. And >>> it's because of the paperweights that the duck-typing works: all the >>> paperweights are the same shape and size, so they're physically >>> interchangeable. >> Okay, the abstraction has leaked again... are the paperweights references >> to the objects, or the names we've bound objects to? I'm confused... >> >> How do we deal with anonymous objects in your model? >> >> -- >> Steven > > Mark, hi, Steven, pleasure as always. > > Neither side is perfect or wild; (Do admit it); How do we decide what > is best for newcomers to Python, depending on background? The crux of this mistake is assuming that all beginners are alike, and that there is therefore a single "best" way to explain things to them. Teaching should be a dialog, in which the teacher makes use of knowledge revealed by the student about their existing knowledge and ways of thinking to present ideas in an easily assimilable form. In other words, don't treat all students the same. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sibteym at infotechsw.com Thu Jan 8 07:33:23 2009 From: sibteym at infotechsw.com (Sibtey Mehdi) Date: Thu, 8 Jan 2009 18:03:23 +0530 Subject: Multiprocessing takes higher execution time In-Reply-To: References: <005701c970ad$c1b27140$5fc513ac@pwit.com><0Lqdnf9Ba46GV_nUnZ2dnUVZ_q7inZ2d@posted.visi> Message-ID: <002f01c9718d$4c4d94d0$5fc513ac@pwit.com> Thanks Nick. It processes 10-15 projects(i.e. 10-15 processes are started) at once. One Zip file size is 2-3 MB. When I used dual core system it reduced the execution time from 61 seconds to 55 seconds. My dual core system Configuration is, Pentium(R) D CPU 3.00GHz, 2.99GHz 1 GB RAM Regards, Gopal -----Original Message----- From: Nick Craig-Wood [mailto:nick at craig-wood.com] Sent: Thursday, January 08, 2009 3:01 PM To: python-list at python.org Subject: Re: Multiprocessing takes higher execution time Sibtey Mehdi wrote: > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) > I create a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution time. > > When I do the same comparison without implementing > multiprocessing, it takes 52 seconds execution time. > The oldProjects and newProjects will contains zip files > i.e(oldxyz1.zip,oldxyz2.zip, newxyz2.zip,newxyz2.zip) > it will unzip both the zip files and compare all the files between old > and new (mdb files or txt files) and gives the result. > I do this comparision for n number set of zip files and i assigne each > set of zip files comparision to a process. I had a brief look at the code and your use of multiprocessing looks fine. How many projects are you processing at once? And how many MB of zip files is it? As reading zip files does lots of disk IO I would guess it is disk limited rather than anything else, which explains why doing many at once is actually slower (the disk has to do more seeks). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 8 07:38:19 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 13:38:19 +0100 Subject: Is it ok to type check a boolean argument? In-Reply-To: <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> Message-ID: <4965f3a7$0$16997$426a74cc@news.free.fr> Adal Chiriliuc a ?crit : > On Jan 7, 10:15 pm, Bruno Desthuilliers > wrote: >> This being said, I can only concur with other posters here about the >> very poor naming. As far as I'm concerned, I'd either keep the argument >> as a boolean but rename it "ascending" (and use a default True value), >> or keep the 'order' name but then accept 'asc' and 'desc' as values >> ('asc' being the default). > > Well, I lied a bit :-p > > The actual function is 20 lines long, and does other stuff to. The > "order" argument is not passed as an argument, but as a field on an > input object. Then the input object should probably be responsible for validating this (IMHO). (snip) > You are all right, "order" is a bad name choice. "sort_ascending" > would be a much better name for a boolean variable. > > I found Paul's idea very interesting, but I prefer to not introduce > new objects which behave like C enums (maybe that would be more > Pythonic?), so I found this variant: > > def find(field, sort_ascending): > ....order_by = {True: "asc", False: "desc"} > ....return _find(field + "+" + order_by[sort_ascending]) for a simple True/False dispatch, my usual idiom (predating the ternary operator) is: order_by = ("desc", "asc")[sort_ascending] > But what if we can't solve it as ellegantly, and we need to execute > different code depending on the condition: > > def find(field, fast_mode=True): > ....if fast_mode: > ........do_something(field, 1, DEFAULT_PAGE_SIZE) > ....else: > ........do_another_thing(field, False, "xml", ignore_error=False) > ........and_another_one() > > Should we typecheck in this case to ensure that if we pass a string > for "fast_mode" we will raise an exception? I don't think so. Going that way, you will end up typechecking each and any function argument. While there are a couple typechecks here and there even in the stdlib and builtins, this doesn't mean it's how Python is supposed to be used - Python is a dynamic language, leave with it or choose another one !-) But anyway, ensuring a program's correctness requires much more than static typing. What you want IMHO is: 1/ a solid *user input* validation/conversion framework (FormEncode comes to mind) 2/ a sensible set of unittests and integration tests. Trying to forcefit static typing into Python will only buy you pain and frustration (not even talking about the waste of time). From hodgestar+pythondev at gmail.com Thu Jan 8 07:42:09 2009 From: hodgestar+pythondev at gmail.com (Simon Cross) Date: Thu, 8 Jan 2009 14:42:09 +0200 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton wrote: > secondly, i want a python25.lib which i can use to cross-compile > modules for poor windows users _despite_ sticking to my principles and > keeping my integrity as a free software developer. If this eventually leads to being able to compile Python software for Windows under Wine (using for example, py2exe) it would make my life a lot easier. Schiavo Simon From cournape at gmail.com Thu Jan 8 08:11:28 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jan 2009 22:11:28 +0900 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross wrote: > On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton > wrote: >> secondly, i want a python25.lib which i can use to cross-compile >> modules for poor windows users _despite_ sticking to my principles and >> keeping my integrity as a free software developer. > > If this eventually leads to being able to compile Python software for > Windows under Wine (using for example, py2exe) it would make my life a > lot easier. You can already do that: just install windows python under wine. It works quite well, actually. You need mingw, though, of course - Visual Studio is far from being usable on wine. cheers, David From voidwrk at gmail.com Thu Jan 8 08:53:23 2009 From: voidwrk at gmail.com (Sergey Kishchenko) Date: Thu, 8 Jan 2009 05:53:23 -0800 (PST) Subject: Default __nonzero__ impl doesn't throw a TypeError exception Message-ID: In Python empty container equals False in 'if' statements: # prints "It's ok" if not []: print "It's ok" Let's create a simple Foo class: class Foo: pass Now I can use Foo objects in 'if' statements: #prints "Ouch!" f=Foo() if f: print "Ouch!" So, default __nonzero__ impl is to return True. I think, this behaviour conflicts with 'Explicit is better than implicit' and 'Practicality beats purity' statements. I think, throwing a TypeError exception would be better. It will result in more explicit code with fewer errors. From lkcl at lkcl.net Thu Jan 8 08:53:57 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 13:53:57 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 12:42 PM, Simon Cross wrote: > On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton > wrote: >> secondly, i want a python25.lib which i can use to cross-compile >> modules for poor windows users _despite_ sticking to my principles and >> keeping my integrity as a free software developer. > > If this eventually leads to being able to compile Python software for > Windows under Wine (using for example, py2exe) it would make my life a > lot easier. that looks like being an accidental side-effect, yes. where i'm up to so far: * i'm using -I $(src_dir)/PC at the beginning of the includes, so that PC/pyconfig.h gets pulled in as a priority over-and-above the auto-generated pyconfig.h (yukkk - i know); this makes the job of building almost-exactly-like-the-visual-studio-build much easier. * i'm manually compiling-linking the Modules/*.c and PC/*modules.c as i also pulled in PC/config.c and left out Modules/config.c - that got me even further * as a result i've actually got a python.exe.so that.... damnit, it works! the winreg test actually passes for example! the fly in the ointment i'm presently trying to track down: len([1,2]) returns 1L which of course screws up sre_parse.py at line 515 with "TypeError: __nonzero__ should return an int" because duh "if subpattern" is returning a Long not an Int. tracking this down further, it would appear that there's some lovely logic in PyInt_FromSsize_t() which i believe is what's getting called from PyInt_AsSsize_t() which is what's getting called from slot_sq_length() (i think) - and, although in this case this build is _definitely_ returning a Long type when it shouldn't, if the value is ever over LONG_MAX then the result will be "if subpattern" will definitely fail. but... i mean... if ever anyone passes in over 2^^31 items into sre_parse then they _deserve_ to have their code fail, but that's not the point. anyway, i'm floundering around a bit and making a bit of a mess of the code, looking for where LONG_MAX is messing up. l. which of course means that there's a bug in From lkcl at lkcl.net Thu Jan 8 09:02:01 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 14:02:01 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: On Thu, Jan 8, 2009 at 1:11 PM, David Cournapeau wrote: > On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross > wrote: >> On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton >> wrote: >>> secondly, i want a python25.lib which i can use to cross-compile >>> modules for poor windows users _despite_ sticking to my principles and >>> keeping my integrity as a free software developer. >> >> If this eventually leads to being able to compile Python software for >> Windows under Wine (using for example, py2exe) it would make my life a >> lot easier. > > You can already do that: just install windows python under wine. i tried that a few months ago - the builder requires the MS installer, which segfaulted on my installation of wine (i installed it using winetricks) which left me flummoxed because other people report successful use of MSI. i also don't want "just" the python.exe, i want the libpython25.a, i want the libpython25.lib, so as to be able to build libraries such as pywekbit-gtk for win32 (cross-compiled using winegcc of course) unpacking the python installer .exe (which was, again, created with a proprietary program) i found that all of the contents were name-mangled and so were useless: i wasn't about to work my way through nearly a hundred files, manually, when i can just as well get python compiling under wine once and then stand a good chance of being able to repeat the exercise in the future, also for python 2.6. so, basically, i really don't want to use visual studio, i really don't want to install a proprietary MSI installer, i really don't want a proprietarily-built python25.exe, and i really don't want a proprietarily-packed installation. i'd just ... much rather be completely independent of proprietary software when it comes to building free software. .... onwards.... :) From cournape at gmail.com Thu Jan 8 09:05:54 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jan 2009 23:05:54 +0900 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: <5b8d13220901080605l6ecc7224ve7d579612f09abd1@mail.gmail.com> On Thu, Jan 8, 2009 at 11:02 PM, Luke Kenneth Casson Leighton wrote: > On Thu, Jan 8, 2009 at 1:11 PM, David Cournapeau wrote: >> On Thu, Jan 8, 2009 at 9:42 PM, Simon Cross >> wrote: >>> On Sat, Jan 3, 2009 at 11:22 PM, Luke Kenneth Casson Leighton >>> wrote: >>>> secondly, i want a python25.lib which i can use to cross-compile >>>> modules for poor windows users _despite_ sticking to my principles and >>>> keeping my integrity as a free software developer. >>> >>> If this eventually leads to being able to compile Python software for >>> Windows under Wine (using for example, py2exe) it would make my life a >>> lot easier. >> >> You can already do that: just install windows python under wine. > > i tried that a few months ago - the builder requires the MS > installer, which segfaulted on my installation of wine (i installed it > using winetricks) which left me flummoxed because other people report > successful use of MSI. > Hm, I could definitely install python - I have python in wine ATM. wine python -c 'import sys; print sys.version' -> 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] IIRC, I could build numpy on it, which is far from a trivial package from a build POV :) I think it crashes on wine, though - which I why I did not pursued it so far. But I believe python itself at least is usable in wine, depending on what you are trying to do. David From Ron.Barak at lsi.com Thu Jan 8 09:11:20 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 8 Jan 2009 14:11:20 +0000 Subject: Nubie question: how to not pass "self" in call to seek() function ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Hi, I am getting the error TypeError: seek() takes exactly 2 arguments (3 given), namely: $ ./_LogStream.py Traceback (most recent call last): File "./_LogStream.py", line 47, in log_stream.last_line_loc_and_contents() File "./_LogStream.py", line 20, in last_line_loc_and_contents self.input_file.seek(-1, 2) # grab the last character TypeError: seek() takes exactly 2 arguments (3 given) When I run the below code. I understand that the extra argument is the "self", but I don't know how to change my class to make the seek(-1,2) work. Could you help ? Thanks, Ron. $ cat _LogStream.py #!/usr/bin/env python import gzip import sys from Debug import _line as line class LogStream(): def __init__(self, filename): self.filename = filename self.input_file = self.open_file(filename) self.index_increment = 10 self.last_line_offset = -1 def last_line_loc_and_contents(self, estimated_line_size=1024): assert estimated_line_size > 0 file_size = len(self.input_file.read()) self.input_file.seek(-1, 2) # grab the last character if self.input_file.read(1) == '\n': # a "proper" text file file_size -= 1 def open_file(self, in_file): """ The gzip module checks if the input file is a gzipped file, only at the read stage. This is why the f.readline() is needed. """ try: f = gzip.GzipFile(in_file, "r") f.readline() except IOError: f = open(in_file, "r") f.readline() f.seek(0) return(f) if __name__ == "__main__": filename = "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" log_stream = LogStream(filename) log_stream.limit_ = 1000 log_stream.index_increment = 12 log_stream.last_line_loc_and_contents() -------------- next part -------------- An HTML attachment was scrubbed... URL: From antroy at gmail.com Thu Jan 8 09:14:32 2009 From: antroy at gmail.com (Ant) Date: Thu, 8 Jan 2009 06:14:32 -0800 (PST) Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: You could look at something like the following to turn the class iteslf into a decorator (changed lines *-ed): > class TaggedWrapper(): > * ? ? def __init__(self, logMixin, stream): > ? ? ? ? self.__tag = '%s@%s' % (logMixin.describe(), stream) > ? ? ? ? logMixin._debug('Created %s' % self) > > ? ? def __next__(self): > ? ? ? ? return next(self.__generator) > > ? ? def __str__(self): > ? ? ? ? return self.__tag def __call__(self, generator): self.__generator = generator return self and then decorate your generator: @TaggedWrapper(mixin, stream) def myGen; for a in range(1,100): yield a (Disclaimer: Completely untested...) From tryg.olson at gmail.com Thu Jan 8 09:39:12 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 06:39:12 -0800 (PST) Subject: How to set a cookie using Cookie Module References: Message-ID: <851933b7-d24f-48a6-8391-93275c205c9f@a29g2000pra.googlegroups.com> On Jan 7, 9:35 am, tryg.ol... at gmail.com wrote: > Hello - > > This is my first attempt at python cookies. I'm using the Cookie > module and trying to set a cookie. Below is my code. The cookie does > not get set. What am I doing wrong? > > print "Cache-Control: max-age=0, must-revalidate, no-store" > print "Content-type: text/html" > print > print """ > My Page > """ > > c = Cookie.Cookie() > c['MyCookie'] = "Tryg" > print c > print > > If I put javascript code to create a cookie in place of my python > cookie code, the javascript cookie gets set. > > Any tips appreciated! > Tryg I eventually figured it out myself. The cookie code needs to be part of the HTTP header. See example below. print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print print """ My Page """ From tryg.olson at gmail.com Thu Jan 8 09:39:25 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 06:39:25 -0800 (PST) Subject: How to set a cookie using Cookie Module References: Message-ID: On Jan 7, 9:35 am, tryg.ol... at gmail.com wrote: > Hello - > > This is my first attempt at python cookies. I'm using the Cookie > module and trying to set a cookie. Below is my code. The cookie does > not get set. What am I doing wrong? > > print "Cache-Control: max-age=0, must-revalidate, no-store" > print "Content-type: text/html" > print > print """ > My Page > """ > > c = Cookie.Cookie() > c['MyCookie'] = "Tryg" > print c > print > > If I put javascript code to create a cookie in place of my python > cookie code, the javascript cookie gets set. > > Any tips appreciated! > Tryg I eventually figured it out myself. The cookie code needs to be part of the HTTP header. See example below. print "Cache-Control: max-age=0, must-revalidate, no-store" print "Content-type: text/html" c = Cookie.Cookie() c['MyCookie'] = "Tryg" print c print print """ My Page """ From rtw at freenet.co.uk Thu Jan 8 09:42:55 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 08 Jan 2009 08:42:55 -0600 Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: wrote in news:053df793-9e8e-4855-aba1-f92482cd8922 @v31g2000vbb.googlegroups.com in comp.lang.python: > class TaggedWrapper(): > > def __init__(self, generator, logMixin, stream): > self.__generator = generator > self.__tag = '%s@%s' % (logMixin.describe(), stream) > logMixin._debug('Created %s' % self) Note that "self" in the above is the instance of the wrapper class TaggedWrapper, not the class that is having its (generator) method decorated. import logging logging.basicConfig( level = logging.DEBUG ) def mydecorator( f ): def decorated(self, *args): logging.debug( "Created %s", self.__class__.__name__ ) for i in f(self, *args): yield i return decorated class Example( object ): @mydecorator def foo(self, a, b, ): yield 1 + a + b e = Example() for i in e.foo( 2, 3 ): print( i ) Output of the above is: DEBUG:root:Created Example 6 Rob. -- http://www.victim-prime.dsl.pipex.com/ From ptmcg at austin.rr.com Thu Jan 8 09:52:15 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 8 Jan 2009 06:52:15 -0800 (PST) Subject: Creating new instances of subclasses. References: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> Message-ID: On Jan 7, 12:00?pm, Paul McGuire wrote: > On Jan 7, 10:38?am, "J. Cliff Dyer" wrote: > > > I want to be able to create an object of a certain subclass, depending > > on the argument given to the class constructor. > > > I have three fields, and one might need to be a StringField, one an > > IntegerField, and the last a ListField. ?But I'd like my class to > > delegate to the proper subclass automatically, so I can just do: > > > >>> f1 = Field('abc') > > >>> f2 = Field('123') > > >>> f3 = Field('D,E,F') > > O-O is not always the solution to every problem. ?Since inheritance is > getting in your way, try using a class-level factory method. ?Instead > of using the Field constructor, use a staticmethod of Field, something > like: > > @staticmethod > def make_Field(a) > ? ? if is_list(a): > ? ? ? ? return ListField(a) > ? ? elif is_integer(a): > ? ? ? ? return IntegerField(a) > ? ? else: > ? ? ? ? return StringField(a) > > and then get rid of all those __new__ methods, too. > > -- Paul After looking this over a bit more, I decided I didn't like make_Field having to know the criteria for creating the different subclasses, but wanted to put the smarts into the subclasses themselves. Here is an excerpt that shows this working: class Field(object): def __init__(self, input): super(Field, self).__init__(input) self.data = input @staticmethod def make_Field(a): subs = (ListField, IntegerField, StringField) ret = None for cls in subs: try: ret = cls(a) except TypeError: continue else: break return ret class IntegerField(Field): def __new__(cls, a): if not is_integer(a): raise TypeError() return Field.__new__(cls, a) ... ListField has a similar __new__ method, and StringField just creates the object, with no validation. make_Field still has to know what order to list the subclasses in (StringField is the most permissive, and so must come last in the list of subclasses), but the specific type tests are moved into the subclasses, which is a more appropriate place I think. -- Paul From gruszczy at gmail.com Thu Jan 8 09:53:00 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 15:53:00 +0100 Subject: Tree views - Best design practices Message-ID: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Hi! I have certain design problem, which I cannot solve elegantly. Maybe you know some good design patterns for this kind of tasks. Task: We have a model which has two kinds of objects: groups and elements. Groups can hold other groups (subgroups) and elements. It's a simple directory tree, for example. We would like to display it in a tree view (which sound good for this kind of model). What is more required, for groups and elements there are different sets of operations, which should be available under right click. For example for group, there should be operations: 'add element' and 'add group', and for element there should be 'change properties'. Do you know any smart way to achieve this? The simplest way is to ask for the class and display operations accordingly. But from the first day with OO programming I have heard, that asking for class is wrong. But I can hardly see any easy and more maintainable solution for this problem. Could you help me with this? -- Filip Gruszczy?ski From lkcl at lkcl.net Thu Jan 8 09:57:03 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 14:57:03 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: > anyway, i'm floundering around a bit and making a bit of a mess of the > code, looking for where LONG_MAX is messing up. fixed with this: PyObject * PyInt_FromSsize_t(Py_ssize_t ival) { if ((long)ival >= (long)LONG_MIN && (long)ival <= (long)LONG_MAX) { return PyInt_FromLong((long)ival); } return _PyLong_FromSsize_t(ival); } raised as http://bugs.python.org/issue4880 next bug: distutils.sysconfig.get_config_var('srcdir') is returning None (!!) From daniel.a.esch at gmail.com Thu Jan 8 09:57:16 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 09:57:16 -0500 Subject: why cannot assign to function call In-Reply-To: References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: Absolutely. Trivially and at a high level, teaching python to kids who are learning programming as introductory material teaching python to motivated college graduate students teaching python to adult non-professional programmers with a need to learn python (like for instance, frustrated accountants who have HAD IT with VBA...) The difference between the last 2 is important. I am not now nor will I ever be a professional programmer; there's a depth of knowledge to the subject that I will not ever systematically study (mostly due to time constraints). On the other hand, the problems I want and need to solve, I want to get right and will put in the effort to learn what I need to get it right. Contrast the college student. He's getting a broad and hopefully deep grounding in more CS theory than I have. How much does he care? Well, the beer bash Friday at 4 probably has a higher priority in his life right now, not unreasonably. So you can explain things to me fairly technically (I've done lots of VBA programming, hated it, and am motivated in self-study in python), but not too abstractly, because I don't have a deep ground in the theory behind CS and programming. (What I know of grammar parsing comes via some linguistics work I did in college, not Backus-Naur Form, although Noam chomsky was important in both fields) In contrast, the CS student should get a generalized explanation because he needs to grow the skills to work it out on his own, and because the generalized and theoretically grounded explanation is more useful for him in extrapolating to other areas. If he can't do more with it than i can, he needs to change majors. On 1/8/09, Steve Holden wrote: > > Aaron Brady wrote: > > On Jan 8, 1:45 am, Steven D'Aprano > > wrote: > >> On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > snip > >>> The `they're just objects' model is very simple, but gets tied up in > >>> knots explaining things. The `it's all references' model is only a > >>> little more complicated, but explains everything. > >> But it *over* explains, because it implies things that "everybody knows" > >> about references in other languages that aren't true for Python. > >> > >> Of course it's not literally true that "everybody knows" that you can > use > >> references to implement a swap(x, y) procedure. But people coming from a > >> C or Pascal background tend to assume that everything is like C/Pascal, > >> and there are a lot of them. If C was a rare, unfamiliar language, my > >> opposition to using the term "reference" would be a lot milder. Maybe in > >> another five years? > >> > >>> No, indeed. Python is a language for talking about paperweights. And > >>> it's because of the paperweights that the duck-typing works: all the > >>> paperweights are the same shape and size, so they're physically > >>> interchangeable. > >> Okay, the abstraction has leaked again... are the paperweights > references > >> to the objects, or the names we've bound objects to? I'm confused... > >> > >> How do we deal with anonymous objects in your model? > >> > >> -- > >> Steven > > > > Mark, hi, Steven, pleasure as always. > > > > Neither side is perfect or wild; (Do admit it); How do we decide what > > is best for newcomers to Python, depending on background? > > The crux of this mistake is assuming that all beginners are alike, and > that there is therefore a single "best" way to explain things to them. > Teaching should be a dialog, in which the teacher makes use of knowledge > revealed by the student about their existing knowledge and ways of > thinking to present ideas in an easily assimilable form. > > In other words, don't treat all students the same. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.a.esch at gmail.com Thu Jan 8 10:07:13 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 10:07:13 -0500 Subject: Work with Open Office Message-ID: Okay, I'm currently stuck with VBA / Excel in work and the following paradigm: VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access Where I'd like to be is this Python ==> X ==> Open Office / (MySQL or other) for some sufficiently useful value of X. Does it exist? Is it just a set of modules I need to be looking for? or something else? -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Thu Jan 8 10:16:15 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 8 Jan 2009 07:16:15 -0800 Subject: Nubie question: how to not pass "self" in call to seek() function ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know how > to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, only > at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list From tryg.olson at gmail.com Thu Jan 8 10:16:42 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 07:16:42 -0800 (PST) Subject: How to Delete a Cookie? Message-ID: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Hello - I managed to get a cookie set. Now I want to delete it but it is not working. Do I need to do another 'set-cookie' in the HTTP header? I tried (code below setting expires to 0) and it didn't work. c = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) c["mycook"]["expires"] = 0 print c In case its useful, here is how I set my cookie: c = Cookie.SimpleCookie() c["mycook"] = "Tryg" c["mycook"]["expires"] = 60*60*24 c["mycook"]["comment"] = "" c["mycook"]["path"] = "/" c["mycook"]["domain"] = "" c["mycook"]["secure"] = "" print c Thanks Tryg From lkcl at lkcl.net Thu Jan 8 10:18:03 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 8 Jan 2009 15:18:03 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: Message-ID: > next bug: distutils.sysconfig.get_config_var('srcdir') is returning None (!!) ok ... actually, that's correct. oops. sysconfig.get_config_vars() only returns these, on win32: {'EXE': '.exe', 'exec_prefix': 'Z:\\mnt\\src\\python2.5-2.5.2', 'LIBDEST': 'Z:\\mnt\\src\\python2.5-2.5.2\\Lib', 'prefix': 'Z:\\mnt\\src\\python2.5-2.5.2', 'SO': '.pyd', 'BINLIBDEST': 'Z:\\mnt\\src\\python2.5-2.5.2\\Lib', 'INCLUDEPY': 'Z:\\mnt\\src\\python2.5-2.5.2\\include'} ... aaaand, that means disabling setup.py or hacking it significantly to support a win32 build, e.g. to build pyexpat, detect which modules are left, etc. by examining the remaining vcproj files in PCbuild. .... ok - i'm done for now. the project's not complete, but can be regarded as successful so far. i think the best thing is being able to do "import _winreg" on a linux system. that absolutely tickles me silly :) been running a few tests - test_mmap.py is a hoot, esp. the Try opening a bad file descriptor... that causes a wine segfault. if anyone wants to play with this further, source is here: http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine at some point - if i feel like taking this further, and if people offer some advice and hints on where to go (with e.g. setup.py) i'll continue. then once that's done i'll do python 2.6 as well. l. From grflanagan at gmail.com Thu Jan 8 10:18:24 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 08 Jan 2009 15:18:24 GMT Subject: Generator metadata/attributes References: <053df793-9e8e-4855-aba1-f92482cd8922@v31g2000vbb.googlegroups.com> Message-ID: <4Po9l.1$H27.0@newsfe10.ams2> On Thu, 08 Jan 2009 08:42:55 -0600, Rob Williscroft wrote: > > def mydecorator( f ): > def decorated(self, *args): > logging.debug( "Created %s", self.__class__.__name__ ) > for i in f(self, *args): > yield i > return decorated > can optionally be written as: def mydecorator( f ): def decorated(self, *args): logging.debug( "Created %s", self.__class__.__name__ ) return f(self, *args) return decorated From benjamin.kaplan at case.edu Thu Jan 8 10:21:42 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 8 Jan 2009 10:21:42 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch wrote: > Okay, I'm currently stuck with VBA / Excel in work and the following > paradigm: > > VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access > > Where I'd like to be is this > > Python ==> X ==> Open Office / (MySQL or other) for some sufficiently > useful value of X. > > Does it exist? Is it just a set of modules I need to be looking for? or > something else? > > Did you google search first? This is the second result for "Python OpenOffice". http://wiki.services.openoffice.org/wiki/Python -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Thu Jan 8 10:25:56 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 08 Jan 2009 10:25:56 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> Message-ID: <85hc49vmyj.fsf@dozer.localdomain> Jonathan Gardner writes: > On Jan 7, 9:16?am, "Chris Mellon" wrote: >> >> The OP wants a Ruby-style DSL by which he means "something that lets >> me write words instead of expressions". The ruby syntax is amenable to >> this, python (and lisp, for that matter) syntax is not and you can't >> implement that style of internal DSL in those languages. >> >> The answer to the OP is "you can't - use Ruby or modify your requirements". >> > > As far as putting the code into Python, yeah, you can't put it in > Python. The best you can do is store it in a string and then interpret > the string with some function later on. That's what I'm saying. It seems we're defining "DSL" in two different ways. You can't write a DSL in Python because you can't change the syntax and you don't have macros. You can write a compiler in Python that will compile your "DSL." As another poster mentioned, eventually PyPy will be done and then you'll get more of an "in-Python" DSL. From tavares at fe.up.pt Thu Jan 8 10:26:07 2009 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Thu, 8 Jan 2009 07:26:07 -0800 (PST) Subject: =?windows-1252?Q?Symposium_=93Image_Processing_and_Visualization_in_S?= =?windows-1252?Q?olid_Mechanics_Processes=94_within_the_ESMC2009_Conference_?= =?windows-1252?Q?=96_Announce_=26_Call_for_Papers?= Message-ID: <6ff6c038-e25e-4fa2-ada1-2f1387735ca2@g39g2000pri.googlegroups.com> --------------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) Symposium on ?Visualization and Human-Computer? 7th EUROMECH Solid Mechanics Conference (ESMC2009) Instituto Superior T?cnico, Lisbon, PORTUGAL, September 7-11, 2009 http://www.dem.ist.utl.pt/esmc2009/ (We would appreciate if you could distribute this information by your colleagues and co-workers.) ------------------------------------------------------------------------------------------------------------------------------- Dear Colleague, Within the 7th EUROMECH Solid Mechanics Conference (ESMC2009), to be held in Instituto Superior T?cnico, Lisbon, Portugal, September 7-11, 2009, we are organizing the Symposium ?Image Processing and Visualization in Solid Mechanics Processes?. Examples of some topics that will be considered are: Image Analysis; Image Restoration, Compression, Segmentation and Description; Object Tracking, Matching, Recognition, and Reconstruction; Visual Inspection; 3D Vision; Medical Imaging; Data Processing, Modeling and Analysis; Scientific Visualization; Enhanced Visualization; Human Computer Interaction; Virtual Reality; Simulation and Animation; Software Development for Image Processing and Visualization; Grid Computing in Image Processing and Visualization; Applications of Image Processing and Visualization. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Image Processing and Visualization in Solid Mechanics Processes?. For instructions and submission, please access to the conference website at: http://www.dem.ist.utl.pt/esmc2009/ Please note that, when submitting your work, you should select the Symposium MS-08 ? ?Image Processing and Visualization in Solid Mechanics Processes?. Important dates: - Abstract submission: January 31, 2009; - Notification of acceptance: March 15, 2009; - Conference Events: September 7-11, 2009. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Michel A. Audette (Kitware, USA, michel.audette at kitware.com) (Symposium organizers) From thorsten at thorstenkampe.de Thu Jan 8 10:38:53 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 16:38:53 +0100 Subject: "python -3" not working as expected Message-ID: [Python 2.6.1] Hi, to test existing Python code, I ran "python -3" ("warn about Python 3.x incompatibilities") against a test file that only contains "print 'test'". Unfortunately I saw no warnings about print becoming a function in Python 3 ("print()"). Where is the problem? Thorsten From jldunn2000 at googlemail.com Thu Jan 8 10:39:03 2009 From: jldunn2000 at googlemail.com (loial) Date: Thu, 8 Jan 2009 07:39:03 -0800 (PST) Subject: sftp with no password from python Message-ID: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> Is it possible to use sftp without a password from python? From Ron.Barak at lsi.com Thu Jan 8 10:44:16 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 8 Jan 2009 15:44:16 +0000 Subject: Nubie question: how to not pass "self" in call to seek() function ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494BCB@enbmail01.lsi.com> Hi Mark, I think my open_file() - that is called in __init__ - assures that self.input_file is a regular text file, regardless if filename is a gz or a regular text file. My Python is Python 2.5.2. Bye, Ron. -----Original Message----- From: Mark Tolonen [mailto:metolone+gmane at gmail.com] Sent: Thursday, January 08, 2009 17:16 To: python-list at python.org Subject: Re: Nubie question: how to not pass "self" in call to seek() function ? "Barak, Ron" <> wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know > how to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, > only at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list From nospam at forMe.thks Thu Jan 8 10:45:23 2009 From: nospam at forMe.thks (Ross) Date: Thu, 08 Jan 2009 10:45:23 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Ross wrote: >> There seems to be no shortage of information around on how to use the >> time module, for example to use time.ctime() and push it into strftime >> and get something nice out the other side, but I haven't found >> anything helpful in going the other way. > > As to a paucity of conversion formatting, there is no magic way to take > everyone's way of putting date and time information in text and convert > it to unambiguous format, in part because there are too many different > and contradictory formats. When I write dates, I know what I intended; > when I read dates, I guess what the author intended. > > Have you read the entire time module document? If so, which functions > in that module take strings as arguments? > >> That is, given some formatted text describing times - is there >> something that makes it easy to calculate time differences, or do I >> have to index my way through the string pulling out characters, >> converting to integers etc... >> >> Data is formatted: >> t1 = 09:12:10 >> t2 = 11:22:14 >> I want to calculate tdiff = t2-t1 > > Do you do any work yourself? Show us your attempts. This looks like > a trivial exercise. It seems that for less than four times the effort > of asking your question you might have found the answer. > > Perhaps I am being too cranky this morning. > --Scott David Daniels > Scott.Daniels at Acm.Org Jeeze, you're quite an ass aren't you? From invalid at invalid Thu Jan 8 10:46:26 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 08 Jan 2009 09:46:26 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: On 2009-01-08, Alex van der Spek wrote: > Thanks much, that makes sense! Well, that's the correct explanation. Whether that feature makes sense or not is debatable. Even I'm not old-school enough that I ever use octal literals -- and I used Unix on a PDP-11 for years (actually had my own PDP-11 for while, but it never worked). Now that I think of it, my Heathkit Z80 stuff used octal notation too. -- Grant Edwards grante Yow! I represent a at sardine!! visi.com From google at mrabarnett.plus.com Thu Jan 8 10:47:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 15:47:07 +0000 Subject: parallel and/or synchronous start/run/stop on multiple boxes In-Reply-To: References: Message-ID: <49661FFB.1090604@mrabarnett.plus.com> Shane wrote: > Consider a network of 3 fully-connected boxes i.e. every box as a TCP- > IP connection to every other box. > > Suppose you start a python program P on box A. Is there a Python > mechanism for P to send a copy of itself to box B or C then start that > program P on B or C by running a method p in P? Is there a way that P > on A could wait for that result? > > Bottom line: we have a number of needs in which it'd very convienent > to write a phython program, install and run it, so that it could > automatically propogate itself to wherever the code needs to go and > run itself so that there could be multiple copies of the code running > on different boxes with synchrounous (maybe asychronous) > communication. > A sort of Pythonic virus? :-) From xulx1981 at gmail.com Thu Jan 8 10:48:50 2009 From: xulx1981 at gmail.com (=?GB2312?B?0OzBttDC?=) Date: Thu, 8 Jan 2009 23:48:50 +0800 Subject: ask a question about richtextctrl Message-ID: <88e0f95b0901080748y19b70c66vad1f2b9426542bc8@mail.gmail.com> I have countered a problem while using wx.RichTextCtrl. I want to do some check when user presss Ctrl+C to paste. But i found that i can not get the wx.EVT_CHAR event while Ctrl+C is pressed. And I have tried many methods but all failed. So anybody can tell me some tips?Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From kay.schluehr at gmx.net Thu Jan 8 11:03:03 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 8 Jan 2009 08:03:03 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> Message-ID: <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> On 8 Jan., 16:25, J Kenneth King wrote: > As another poster mentioned, eventually PyPy will be done and then > you'll get more of an "in-Python" DSL. May I ask why you consider it as important that the interpreter is written in Python? I see no connection between PyPy and syntactical Python extensions and the latter isn't an objective of PyPy. You can write Python extensions with virtually any Python aware parser. M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then there is ANTLR which provides a Python grammar. I also know about two other Python aware parsers. One of them was written by myself. From daniel.a.esch at gmail.com Thu Jan 8 11:10:32 2009 From: daniel.a.esch at gmail.com (Dan Esch) Date: Thu, 8 Jan 2009 11:10:32 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: Have been browsing through this list and reading documentation and tutorials for python self-study. I have, apparently, teh stupid. Google is my friend. Off I go. Thanks. On 1/8/09, Benjamin Kaplan wrote: > > > > On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch wrote: > >> Okay, I'm currently stuck with VBA / Excel in work and the following >> paradigm: >> >> VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access >> >> Where I'd like to be is this >> >> Python ==> X ==> Open Office / (MySQL or other) for some sufficiently >> useful value of X. >> >> Does it exist? Is it just a set of modules I need to be looking for? or >> something else? >> >> > > Did you google search first? This is the second result for "Python > OpenOffice". > > http://wiki.services.openoffice.org/wiki/Python > > -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Thu Jan 8 11:16:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 16:16:38 +0000 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Message-ID: <496626E6.2030501@mrabarnett.plus.com> Filip Gruszczy?ski wrote: > Hi! > > I have certain design problem, which I cannot solve elegantly. Maybe > you know some good design patterns for this kind of tasks. > > Task: > > We have a model which has two kinds of objects: groups and elements. > Groups can hold other groups (subgroups) and elements. It's a simple > directory tree, for example. We would like to display it in a tree > view (which sound good for this kind of model). What is more required, > for groups and elements there are different sets of operations, which > should be available under right click. For example for group, there > should be operations: 'add element' and 'add group', and for element > there should be 'change properties'. > > Do you know any smart way to achieve this? The simplest way is to ask > for the class and display operations accordingly. But from the first > day with OO programming I have heard, that asking for class is wrong. > But I can hardly see any easy and more maintainable solution for this > problem. Could you help me with this? > You could ask the object what the operations are. Here's an example using strings: >>> class Element(object): operations = "Element operations" >>> class Group(object): operations = "Group operations" >>> e = Element() >>> g = Group() >>> >>> e.operations 'Element operations' >>> g.operations 'Group operations' From gruszczy at gmail.com Thu Jan 8 11:21:52 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 17:21:52 +0100 Subject: Tree views - Best design practices In-Reply-To: <496626E6.2030501@mrabarnett.plus.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> Message-ID: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> >>>> class Element(object): > operations = "Element operations" > > >>>> class Group(object): > operations = "Group operations" > > >>>> e = Element() >>>> g = Group() >>>> >>>> e.operations > 'Element operations' >>>> g.operations > 'Group operations' But this is the same as asking for a class, except for having to write a method giving some form of a class name and then basing on this classname display operations. I know this solution, but this is what I would like to evade. -- Filip Gruszczy?ski From luke.leighton at googlemail.com Thu Jan 8 11:26:48 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 8 Jan 2009 08:26:48 -0800 (PST) Subject: compiling python2.5 on linux under wine References: Message-ID: <852657ad-8fa8-4e71-a2d8-8028c97f06c8@t39g2000prh.googlegroups.com> > ... aaaand, that means disabling setup.py or hacking it significantly > to support a win32 build, e.g. to build pyexpat, detect which modules > are left, etc. by examining the remaining vcproj files in PCbuild. > > .... ok - i'm done for now. > if anyone wants to play with this further, source is here: > > http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine patch is also here: http://bugs.python.org/issue4880 From bj_666 at gmx.net Thu Jan 8 11:26:55 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 8 Jan 2009 16:26:55 GMT Subject: "python -3" not working as expected References: Message-ID: <6smnqfF71c2fU1@mid.uni-berlin.de> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > [Python 2.6.1] > > Hi, > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > incompatibilities") against a test file that only contains "print > 'test'". > > Unfortunately I saw no warnings about print becoming a function in > Python 3 ("print()"). Where is the problem? There is no problem. ``print``\s are handled fine by the 2to3.py script. The option warns about stuff that is not easily automatically converted. Ciao, Marc 'BlackJack' Rintsch From google at mrabarnett.plus.com Thu Jan 8 11:40:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 16:40:07 +0000 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: <49662C67.5030800@mrabarnett.plus.com> Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, except for having to write > a method giving some form of a class name and then basing on this > classname display operations. I know this solution, but this is what I > would like to evade. > My point was that the 'operations' attribute could specify the operations for that kind of object. More explicitly: class Element(object): operations = [change_properties] class Group(object): operations = [add_element, add_group] and so on. From deets at nospam.web.de Thu Jan 8 11:41:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:41:20 +0100 Subject: Tree views - Best design practices References: Message-ID: <6smolgF763pbU1@mid.uni-berlin.de> Filip Gruszczy?ski wrote: > Hi! > > I have certain design problem, which I cannot solve elegantly. Maybe > you know some good design patterns for this kind of tasks. > > Task: > > We have a model which has two kinds of objects: groups and elements. > Groups can hold other groups (subgroups) and elements. It's a simple > directory tree, for example. We would like to display it in a tree > view (which sound good for this kind of model). What is more required, > for groups and elements there are different sets of operations, which > should be available under right click. For example for group, there > should be operations: 'add element' and 'add group', and for element > there should be 'change properties'. > > Do you know any smart way to achieve this? The simplest way is to ask > for the class and display operations accordingly. But from the first > day with OO programming I have heard, that asking for class is wrong. > But I can hardly see any easy and more maintainable solution for this > problem. Could you help me with this? You don't ask *for* the class. You ask the class itself (or better, the object you currently deal with) what operations it supports. Your treeview-code then gets a list of strings for example (or better, a list of tuples (action, menuentry) ) that it uses to build the context-menu. When a given entry is selected, you then ask the object again to perform the action on itself, by passing the action-name. Or invoking a method called that way, or some such. Thus your treeview-code is completely generic and easily extendable with new functionality. There are variations of this scheme, if you don't want to "pollute" your model-classes with view/controller-logic. Then you need some sort of ActionFactory or something like that, which eventually somewhere might resort to a hard-coded list of class-to-action-mappings. Diez From jakecjacobson at gmail.com Thu Jan 8 11:44:26 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Thu, 8 Jan 2009 08:44:26 -0800 (PST) Subject: FTP example going through a FTP Proxy References: <0ea8bb68-31a3-4fd7-98dd-8ff5916d6123@35g2000pry.googlegroups.com> <7ec61386-3e10-408e-98e1-de7a7aee4ad0@a29g2000pra.googlegroups.com> <341b04d3-10be-4a29-b170-fd6ec3a2be51@k8g2000yqn.googlegroups.com> Message-ID: <612e02a4-543c-46fd-8aa6-312f8c51a6fd@r15g2000prd.googlegroups.com> On Jan 7, 3:56?pm, jakecjacobson wrote: > On Jan 7, 2:11?pm, jakecjacobson wrote: > > > > > On Jan 7, 12:32?pm, jakecjacobson wrote: > > > > Hi, > > > > I need to write a simple Python script that I can connect to a FTP > > > server and download files from the server to my local box. ?I am > > > required to go through a FTP Proxy and I don't see any examples on how > > > to do this. ?The FTP proxy doesn't require username or password to > > > connect but the FTP server that I am connecting to does. > > > > Any examples on how to do this would be greatly appreciated. ?I am > > > limited to using Python version 2.4.3 on a Linux box. > > > This is what I have tried so far, > > > import urllib > > > proxies = {'ftp':'ftp://proxy_server:21'} > > ftp_server = 'ftp.somecompany.com' > > ftp_port='21' > > username = 'aaaa' > > password = 'secretPW' > > > ftp_string='ftp://' + username + '@' + password + ftp_server + ':' + > > ftp_port > > > data = urllib.urlopen(ftp_string, proxies=proxies) > > > data=urllib.urlopen(req).read() > > > print data > > > I get the following error: > > > Traceback (most recent call last): > > ? File "./ftptest.py", line 22, in ? > > ? ? data = urllib.urlopen(ftp_server, proxies=proxies) > > ? File "/usr/lib/python2.4/urllib.py", line 82, in urlopen > > ? ? return opener.open(url) > > ? File "/usr/lib/python2.4/urllib.py", line 190, in open > > ? ? return getattr(self, name)(url) > > ? File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp > > ? ? host, path = splithost(url) > > ? File "/usr/lib/python2.4/urllib.py", line 949, in splithost > > ? ? match = _hostprog.match(url) > > TypeError: expected string or buffer > > I might be getting closer. ?Now I am getting "I/O error(ftp error): > (111, 'Connection refused')" error with the following code: > > import urllib2 > > proxies = {'ftp':'ftp://proxy_server:21'} > ftp_server = 'ftp.somecompany.com' > ftp_port='21' > username = 'aaaa' > password = 'secretPW' > > password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() > top_level_url = ftp_server > password_mgr.add_password(None, top_level_url, username, password) > > proxy_support = urllib2.ProxyHandler(proxies) > handler = urllib2.HTTPBasicAuthHandler(password_mgr) > opener = urllib2.build_opener(proxy_support) > opener = urllib2.build_opener(handler) > a_url = 'ftp://' + ftp_server + ':' + ftp_port + '/' > print a_url > > try: > ? ? ? ? data = opener.open(a_url) > ? ? ? ? print data > except IOError, (errno, strerror): > ? ? ? ? print "I/O error(%s): %s" % (errno, strerror) I tried the same code from a different box and got a different error message: I/O error(ftp error): 501 USER format: proxy-user:auth- method at destination. Closing connection. My guess is that my original box couldn't connect with the firewall proxy so I was getting a connection refused error. Now it appears that the password mgr has an issue if I understand the error correctly. I really hope that someone out in the Python Community can give me a pointer. From deets at nospam.web.de Thu Jan 8 11:48:39 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:48:39 +0100 Subject: linked list with cycle structure References: <6sjok8F6dqciU1@mid.uni-berlin.de> Message-ID: <6smp37F763pbU2@mid.uni-berlin.de> David Hl??ik wrote: > Hi, > > so okay, i will create a helping set, where i will be adding elements > ID, when element ID will be allready in my helping set i will stop and > count number of elements in helping set. This is how long my cycled > linked list is. > But what if i have another condition , and that is *i can use only > helping memory with constant size* ? This means i am not able to > create any set and adding elements there. I need to have a constant > size variables . This is complication a complication for me. This isn't to hard - think about what you are really interested in - knowing if *all* other elements are already counted, or a specific one? You can get away with only one, to detect the cycle and abort. Diez From ZeeGeek at gmail.com Thu Jan 8 11:52:18 2009 From: ZeeGeek at gmail.com (ZeeGeek) Date: Thu, 8 Jan 2009 08:52:18 -0800 (PST) Subject: socket and thread Message-ID: <9a013936-c5b2-4671-ae7d-138a57695a8c@s1g2000prg.googlegroups.com> I'm writing a small program which uses different threads to monitor an IMAP mailbox and an RSS feed. If network is not available when the program starts, both threads will sleep for a while and try again. It seems that the first thread succeeds when the network becomes available will cause the other thread to always give a gaierror "No address associated with hostname". The weird thing is that this only happens when the program starts with network unavailable. If network is available when the program starts, both threads work well, even if the network drops in the middle, the threads can recover properly when the network comes back alive. Is Python socket thread-unsafe or is it because of some other problems? Thanks. From deets at nospam.web.de Thu Jan 8 11:52:21 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 08 Jan 2009 17:52:21 +0100 Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> Message-ID: <6smpa5F763pbU3@mid.uni-berlin.de> Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, except for having to write > a method giving some form of a class name and then basing on this > classname display operations. I know this solution, but this is what I > would like to evade. > It is *not* the same - the code that knows about the operations is not in the treeview-logic anymore, but local to the class that can actually deal with the operations. Diez From kyosohma at gmail.com Thu Jan 8 12:11:44 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 8 Jan 2009 09:11:44 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: <1a939f2e-90c5-4b25-812f-dfa2b3da53f8@r15g2000prh.googlegroups.com> On Jan 8, 9:16?am, tryg.ol... at gmail.com wrote: > Hello - > > I managed to get a cookie set. ?Now I want to delete it but it is not > working. > > Do I need to do another 'set-cookie' in the HTTP header? ?I tried > (code below setting expires to 0) and it didn't work. > c = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) > c["mycook"]["expires"] = 0 > print c > > In case its useful, here is how I set my cookie: > c = Cookie.SimpleCookie() > c["mycook"] = "Tryg" > c["mycook"]["expires"] = 60*60*24 > c["mycook"]["comment"] = "" > c["mycook"]["path"] ? ?= "/" > c["mycook"]["domain"] ?= "" > c["mycook"]["secure"] ?= "" > print c > > Thanks > Tryg Well, if you know where the cookie file is stored, you should be able to do this: os.remove(path) Mike From steve at holdenweb.com Thu Jan 8 12:15:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 12:15:03 -0500 Subject: "python -3" not working as expected In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > [Python 2.6.1] > > Hi, > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > incompatibilities") against a test file that only contains "print > 'test'". > > Unfortunately I saw no warnings about print becoming a function in > Python 3 ("print()"). Where is the problem? > I *believe* that's not flagged because 2to3 will fix it automatically. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 8 12:17:13 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jan 2009 12:17:13 -0500 Subject: formatted 'time' data in calculations In-Reply-To: References: Message-ID: Ross wrote: > Scott David Daniels wrote: >> Ross wrote: >>> There seems to be no shortage of information around on how to use the >>> time module, for example to use time.ctime() and push it into >>> strftime and get something nice out the other side, but I haven't >>> found anything helpful in going the other way. >> >> As to a paucity of conversion formatting, there is no magic way to take >> everyone's way of putting date and time information in text and convert >> it to unambiguous format, in part because there are too many different >> and contradictory formats. When I write dates, I know what I intended; >> when I read dates, I guess what the author intended. >> >> Have you read the entire time module document? If so, which functions >> in that module take strings as arguments? >> >>> That is, given some formatted text describing times - is there >>> something that makes it easy to calculate time differences, or do I >>> have to index my way through the string pulling out characters, >>> converting to integers etc... >>> >>> Data is formatted: >>> t1 = 09:12:10 >>> t2 = 11:22:14 >>> I want to calculate tdiff = t2-t1 >> >> Do you do any work yourself? Show us your attempts. This looks like >> a trivial exercise. It seems that for less than four times the effort >> of asking your question you might have found the answer. >> >> Perhaps I am being too cranky this morning. > > Jeeze, you're quite an ass aren't you? And how did sending this message improve things? Let's keep it civil, guys. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From theller at python.net Thu Jan 8 12:29:16 2009 From: theller at python.net (Thomas Heller) Date: Thu, 08 Jan 2009 18:29:16 +0100 Subject: Extending Python with C or C++ In-Reply-To: References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> Message-ID: <6smrejF74ss9U1@mid.individual.net> Nick Craig-Wood schrieb: > Thomas Heller wrote: >> Nick Craig-Wood schrieb: >> > Interesting - I didn't know about h2xml and xml2py before and I've >> > done lots of ctypes wrapping! Something to help with the initial >> > drudge work of converting the structures would be very helpful. >> > >> > ( http://pypi.python.org/pypi/ctypeslib/ ) >> > >> > I gave it a quick go and it worked fine. I had to edit the XML in one >> > place to make it acceptable (removing a u from a hex number). >> >> If you are using a recent version of gccxml, then you should use the >> ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should >> really merge the gccxml-0.9 branch into the trunk;-) >> >> If you are already using the branch and the XML file is not accepted, >> then could you please provide a short C code snippet that reproduces >> the problem so that I can fix it? > > I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess > doesn't have the code from the branch in. I meant the branch in the repository where ctypeslib lives in. Anyway, it doesn't matter anymore since I merged that branch into the ctypeslib trunk. Now the problem with the 'u' suffix that you mentioned should be fixed, and I also made a quick change so that the sized integer types from stdint.h are generated correctly. So, please update your ctypeslib installation and trey again;-) Thomas From jason.ribeiro at gmail.com Thu Jan 8 12:30:58 2009 From: jason.ribeiro at gmail.com (Jason Ribeiro) Date: Thu, 8 Jan 2009 12:30:58 -0500 Subject: #python IRC help - my internet provider is banned! In-Reply-To: References: Message-ID: I am not a #python operator, but do note that #python is +r so you must be registered and identified to join the channel, see http://freenode.net/faq.shtml#userregistration . Otherwise, giving the exact ban that is affecting you or your hostmask would probably be helpful to the operators. On Wed, Jan 7, 2009 at 1:52 PM, simonh wrote: > On Jan 7, 6:30 pm, "Mildew Spores" wrote: > > What? Sounds a bit unlikely unless its Virgin.. > > I'd imagine it might be that your isp needs to get itself off a black > list. > > Brian > > > > -- > > My Hotmail Account > > mildew_spo... at hotmail.com > > > > "simonh" wrote in message > > > > news:fd0bd7d3-ad1d-43c2-b8e5-642a95c21f78 at t26g2000prh.googlegroups.com. > .. > > > > > Hi. Not sure if anyone can help here, but I'm trying to access #python > > > and have found out that my ISP has a blanket ban (for some reason). > > > Does anyone know how I can contact an operator to join? Thanks. > > > > > > > ISP is bethere and client is Chatzilla. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Jan 8 12:45:56 2009 From: mrkafk at gmail.com (mk) Date: Thu, 08 Jan 2009 18:45:56 +0100 Subject: How to Delete a Cookie? In-Reply-To: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: tryg.olson at gmail.com wrote: > Hello - > > I managed to get a cookie set. Now I want to delete it but it is not > working. Why struggle with this manually? Isn't it better to learn a bit of framework like Pylons and have it all done for you (e.g. in Pylons you have response.delete_cookie method)? Regards, mk From tim.arnold at sas.com Thu Jan 8 12:48:26 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 8 Jan 2009 12:48:26 -0500 Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: "floob" wrote in message news:0af87074-6d9c-41a8-98ec-501f6f37bf9a at s1g2000prg.googlegroups.com... >I have been searching for a way to print the official Python > documentation into some kind of book (for my own uses). I don't > really care if it's printed on newspaper and bound with elmer's > glue ... any way I can get relatively recent _official documentation_ > in print form will do. > > I'm on the go a lot, and can't read for long periods of time on LCD > screens anyhow (so having a laptop is not my solution). Until eBook > readers grow up a bit, I'm stuck trying to print the documentation > that I REALLY need to read and absorb. > > Lulu.com is an option, but it would cost something around $100 US > before shipping to get everything printed. Also, I would have to > split up some larger documents into Volumes, which I'd rather not have > to do. > > Has anyone tried this before? Is the documentation already available > in print? > > Thanks, > > drfloob just a datapoint, but I used lulu.com to print the latex sources (525 pages) hardbound for a cost of $25 US. --Tim Arnold From nad at acm.org Thu Jan 8 12:56:11 2009 From: nad at acm.org (Ned Deily) Date: Thu, 08 Jan 2009 09:56:11 -0800 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: In article , Unknown wrote: > On 2009-01-08, Alex van der Spek wrote: > > Thanks much, that makes sense! > Well, that's the correct explanation. > Whether that feature makes sense or not is debatable. The debate is over! In Py 3.0, octal literals changed from 07 to 0o7; the old format gets an 'invalid token' parsing error. -- Ned Deily, nad at acm.org From brendandetracey at yahoo.com Thu Jan 8 12:58:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 8 Jan 2009 09:58:46 -0800 (PST) Subject: ftplib - 226 message not received Message-ID: I am trying to download a file within a very large zipfile. I need two partial downloads of the zipfile. The first to get the file byte offset, the second to get the file itself which I then inflate. I am implementing the partial downloads as follows: con = ftp.transfercmd('RETR ' + filename, rest_offset) # the data socket while True: block = con.recv(blocksize) # stop transfer while it isn't finished yet if bytes_recv >= buf_length: break elif not block: break buf = ''.join([buf, block]) bytes_recv += len(block) con.close() My problem is that even though the socket is closed, I have no way to receive the 226 response from server so I can proceed with the next download. Of course I could close the ftp connection entirely and open a new one, but I am hoping to avoid doing so. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 13:02:45 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 19:02:45 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: Message-ID: <49664d71$0$15794$426a74cc@news.free.fr> Zac Burns a ?crit : > I have a decorator in a class Why ? (snip) > The exception that I get when using it as a staticmethod and try to > use it in the baseclass is "TypeError: 'staticmethod' object is not > callable". > When it is not staticmethod the exception I get in the extension class > is is "TypeError: unbound method decorateTest() must be called with C > instance as first argument (got function instance instead)" Just make it a plain function and you'll be fine. From houdinihound69 at gmail.com Thu Jan 8 13:16:28 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 10:16:28 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> Message-ID: <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> > c["mycook"]["expires"] = 0 Set ["expires"] using the following format to any time less than current (which causes the browser to delete the cookie). Here's a function I use to return a cookie expiry timestamp, negative values passed in result in cookie being deleted. def cookie_expiry_date(numdays): """ Returns a cookie expiry date in the required format. -ve value in = kill cookie. `expires` should be a string in the format "Wdy, DD-Mon-YY HH:MM:SS GMT" NOTE! Must use [expires] because earlier IE versions don't support [max-age]. """ from datetime import date, timedelta new = date.today() + timedelta(days = numdays) return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") Usage: c["mycook"]["expires"] = cookie_expiry_date(-10) # any negative value will remove cookie HTH, JC From esnow at verio.net Thu Jan 8 13:17:44 2009 From: esnow at verio.net (Eric Snow) Date: Thu, 8 Jan 2009 10:17:44 -0800 (PST) Subject: del behavior 2 References: <79c87196-69a5-4caa-8cc0-af3ba952d8a6@w24g2000prd.googlegroups.com> <49652b53$0$25195$9b622d9e@news.freenet.de> Message-ID: On Jan 7, 3:23?pm, "Martin v. L?wis" wrote: > > Thanks for the responses. ?What I mean is when a python process is > > interrupted and does not get a chance to clean everything up then what > > is a good way to do so? ?For instance, I have a script that uses child > > ptys to facilitate ssh connections (I'm using pxssh). ?When I ^C the > > python process I am left with the child processes running and the ssh > > connections open. ?Naturally I run out of ttys if this happens too > > much, which I have had happen. ?So if python does not get a chance to > > take care of those, what is a good way to do so? ?Does a try/finally > > or a with statement address that? ?Thanks! > > That's strange. When the parent process terminates, the tty master > should get closed, causing the slave to be closed as well, in addition > to sending a SIGHUP signal to the child, which ssh should interpret > as terminating. > > Perhaps the problem is that the master socket *doesn't* get closed? > I see that pexpect closes all file descriptors in the child before > invoking exec. Could it be that you are starting addition child > processes which inherit the master socket? > > Regards, > Martin Thanks. I'll look into that. -eric From esnow at verio.net Thu Jan 8 13:21:58 2009 From: esnow at verio.net (Eric Snow) Date: Thu, 8 Jan 2009 10:21:58 -0800 (PST) Subject: del behavior 2 References: Message-ID: <882912bf-d016-4645-80fa-4f754b1a6a09@w1g2000prk.googlegroups.com> On Jan 7, 12:42?pm, Eric Snow wrote: > I was reading in the documentation about __del__ and have a couple of > questions. ?Here is what I was looking at: > > http://docs.python.org/reference/datamodel.html#object.__del__ > > My second question is about the following: > > "It is not guaranteed that __del__() methods are called for objects > that still exist when the interpreter exits." > > I understand that and have seen it too. ?That's fine. ?But how do any > of you deal with things that are left open because you did not get a > chance to close them? ?How do you clean up after the fact? ?Do you > simply keep track externally the things that need to be cleaned up if > __del__ doesn't get a chance? ?Any ideas? ?Thanks > > -eric So I see a couple of options here. Thanks for all the suggestions everyone. Here is what I have: - use try/finally to clean things up - set a handler using signal.signal to clean everything up There is also having try/except for more specific behvaior, like for KeyboardInterrupt, but I am not sure I need that much specificity. Again, thanks for all the great help. Really cleared things up for me. -eric From zac256 at gmail.com Thu Jan 8 13:27:45 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 10:27:45 -0800 Subject: cPickle vs pickle discrepancy In-Reply-To: References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: <333edbe80901081027g49ef3319xd24d931914d4dd42@mail.gmail.com> Thanks for your patience waiting for me to isolate the problem. | Package --__init__.py ->empty --Package.py ->empty --Module.py import cPickle class C(object): pass def fail(): return cPickle.dumps(C(), -1) import Package.Module Package.Module.fail() The failure seems to happen because pickle correctly does an absolute import and cPickle incorrectly relatively imports Package.py and fails to find Module underneath. The package and the module named package was because in there was a main class defined with the same name as the package in that file and Module.py contained support code for the package. -Zac -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Jan 6, 2009 at 4:57 PM, Gabriel Genellina wrote: > En Mon, 05 Jan 2009 23:04:30 -0200, Zac Burns escribi?: > >> I have a module that attempts to pickle classes defined in that module. >> >> I get an error of the form: >> PicklingError: Can't pickle : import >> of module Module.SubModule failed >> when using cPickle (protocol -1, python version 2.5.1). >> >> The module has already been imported and is in sys.modules when the >> exception is raised. > > There is no thing as a "submodule"; very likely you have a package, and a > module inside that package. > - always import the "submodules" from the package, not directly (relative > imports are safer) > - in general, don't play with PYTHONPATH, sys.path, and such things. > - don't directly execute a module inside a package (it's name is always > __main__ and it doesn't even "know" it's part of a package). > >> Using pickle instead of cPickle works, but the section of the code is >> performance critical. > > Could you provide a short example? I'd say that if you stick to the above > rules you won't have the issue again, but anyway I'd like to know in which > cases Pickle and cPickle differ. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From brendandetracey at yahoo.com Thu Jan 8 13:32:40 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 8 Jan 2009 10:32:40 -0800 (PST) Subject: ftplib - 226 message not received References: Message-ID: <3caa2010-80c9-45cf-8886-6ef8844d55ff@o40g2000prn.googlegroups.com> Okay, found it on my own. ftp.voidresp() is what is needed, and it does _not_ seem to be in the Python documentation for ftplib. On Jan 8, 1:58?pm, Brendan wrote: > I am trying to download a file within a very large zipfile. I need two > partial downloads of the zipfile. The first to get the file byte > offset, the second to get the file itself which I then inflate. > > I am implementing the partial downloads as follows: > > con = ftp.transfercmd('RETR ' + filename, rest_offset) ?# the data > socket > while True: > ? ? block = con.recv(blocksize) > # stop transfer while it isn't finished yet > ? ? if bytes_recv >= buf_length: > ? ? ? ? break > ? ? elif not block: > ? ? ? ? break > ? ? buf = ''.join([buf, block]) > ? ? bytes_recv += len(block) > con.close() > > My problem is that even though the socket is closed, I have no way to > receive the 226 response from server so I can proceed with the next > download. ?Of course I could close the ftp connection entirely and > open a new one, but I am hoping to avoid doing so. From tryg.olson at gmail.com Thu Jan 8 13:33:02 2009 From: tryg.olson at gmail.com (tryg.olson at gmail.com) Date: Thu, 8 Jan 2009 10:33:02 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> Message-ID: On Jan 8, 1:16 pm, Jose C wrote: > > c["mycook"]["expires"] = 0 > > Set ["expires"] using the following format to any time less than > current (which causes the browser to delete the cookie). > Here's a function I use to return a cookie expiry timestamp, negative > values passed in result in cookie being deleted. > > def cookie_expiry_date(numdays): > """ Returns a cookie expiry date in the required format. -ve > value in = kill cookie. > `expires` should be a string in the format "Wdy, DD-Mon-YY > HH:MM:SS GMT" > NOTE! Must use [expires] because earlier IE versions don't > support [max-age]. > """ > from datetime import date, timedelta > new = date.today() + timedelta(days = numdays) > return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") > > Usage: > c["mycook"]["expires"] = cookie_expiry_date(-10) # any negative value > will remove cookie > > HTH, > JC Jose C's piece of code works to delete the cookie as does setting ["expires"]=0 but ONLY as long as I also set the path. Why is this? So what would be the best way to do this. I tried reading in the existing cookie (b), creating a new cookie (c) with all the same values except for the "expires" but this did not get my cookie deleted. b = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) c = Cookie.SimpleCookie() c[cookieName] = b[cookieName].value c[cookieName]["expires"] = 0 c[cookieName]["path"] = b[cookieName]["path"] print c From mdw at distorted.org.uk Thu Jan 8 13:33:50 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 18:33:50 +0000 (UTC) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: [Steven's message hasn't reached my server, so I'll reply to it here. Sorry if this is confusing.] Aaron Brady wrote: > On Jan 8, 1:45 am, Steven D'Aprano > wrote: > > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > > > > The `they're just objects' model is very simple, but gets tied up in > > > knots explaining things. The `it's all references' model is only a > > > little more complicated, but explains everything. > > > > But it *over* explains, because it implies things that "everybody knows" > > about references in other languages that aren't true for Python. I addressed this elsewhere. Summary: `pass-by-reference' is a different thing to `all you manipulate are references': Python does pass-by-value, but the things it passes -- by value -- are references. (The `pass-by-*' notions are confusingly named anyway. Pass-by-name doesn't actually involve names at all.) > > Of course it's not literally true that "everybody knows" that you > > can use references to implement a swap(x, y) procedure. But people > > coming from a C or Pascal background tend to assume that everything > > is like C/Pascal, and there are a lot of them. If C was a rare, > > unfamiliar language, my opposition to using the term "reference" > > would be a lot milder. Maybe in another five years? I agree with the comment about Pascal, but C is actually pretty similar to Python here. C only does pass-by-value. If you want a function to modify your variable, you have to pass a pointer value which points to it. Python has no pointer values, so you need a different hack. The hack usually involves lists. (Though it's easier in the main to return compound data objects like tuples. I don't suppose that a proposal for true multiple return values would go down well here. No, didn't think so...) > > Okay, the abstraction has leaked again... are the paperweights references > > to the objects, or the names we've bound objects to? I'm confused... They're the references to the objects. You don't bind names to objects. You bind names slots in which you store references. This discussion -- I'd call it an argument, but that might give the wrong impression, because I think we're being remarkably civil and constructive by the standards of Usenet arguments! -- hasn't started on the topic of variable bindings or environments yet. > > How do we deal with anonymous objects in your model? > > > > -- > > Steven > > Mark, hi, Steven, pleasure as always. Hello. ;-) > Neither side is perfect or wild; (Do admit it); It's true. > How do we decide what is best for newcomers to Python, depending on > background? That I really don't know. I'm not good at teaching total beginners (does it show?) because I'm too enmired in the theory. (It doesn't help that I go off on tangents about how language X does something similar but subtly different all the time, though my rich background comes in very useful all over the place and that's something I think is worth sharing.) It probably doesn't help that I came to Python with a thorough understanding of Scheme (among many others) under my belt, because many Scheme concepts carry over directly, including the data model (it's all references) and the variable model (nested, mutable, lexical environments with closures). What I am pretty sure of is that references are going to have to enter the picture at some point, because other models get too complicated. Oh, while I remember: the `distributed Python' model, with auto-updating copies, only works for sharing. Circular structures still require actual references or a Tardis. -- [mdw] From benjamin at python.org Thu Jan 8 13:37:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 8 Jan 2009 18:37:21 +0000 (UTC) Subject: "python -3" not working as expected References: Message-ID: Steve Holden holdenweb.com> writes: > Thorsten Kampe wrote: > > Unfortunately I saw no warnings about print becoming a function in > > Python 3 ("print()"). Where is the problem? > > > I *believe* that's not flagged because 2to3 will fix it automatically. This is correct; there's not much point to adding py3k warning for things that 2to3 can fix easily. From p at ulmcnett.com Thu Jan 8 13:42:13 2009 From: p at ulmcnett.com (Paul McNett) Date: Thu, 08 Jan 2009 10:42:13 -0800 Subject: Replying to list messages In-Reply-To: <878wpmguop.fsf@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> <878wpmguop.fsf@benfinney.id.au> Message-ID: <49664905.2010806@ulmcnett.com> Ben Finney wrote: > Paul McNett

writes: >> But arguing about this here isn't going to change anything: opinions >> differ just like tabs/spaces and bottom-post/top-post. > > In cases like this, one side can simply be wrong :-) > > Best of luck getting your programs behaving as you want them to! BTW, I agree with you that in an ideal, pure world mailing lists wouldn't munge the reply-to field, but when 80% of the people use email clients that don't support reply-list, the practical thing to do as a list admin that wants to avoid having to explain over and over again that "your client software is broken" is to simply swallow some pride and munge the reply-to. Now, 99% of the users are happy, and the remaining 1% are elite enough to understand how to get around any problems this caused. Happy is good. Paul From pavlovevidence at gmail.com Thu Jan 8 13:49:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 10:49:03 -0800 (PST) Subject: Is it ok to type check a boolean argument? References: <7b6cce76-2c33-4b62-a20d-83040ac49069@d36g2000prf.googlegroups.com> <49651b04$0$24804$426a74cc@news.free.fr> <67ffba41-21a9-4fd8-9b81-b25c7b0e9ce0@y1g2000pra.googlegroups.com> <1ZednYe8UMYq2_jUnZ2dnUVZ_rrinZ2d@pdx.net> Message-ID: On Jan 7, 6:21?pm, Scott David Daniels wrote: > Adal Chiriliuc wrote: > > On Jan 7, 10:15 pm, Bruno Desthuilliers > > wrote: > >> ... I'd either keep the argument as a boolean but rename it "ascending" ... > > > Well, I lied a bit :-p ?.... > > But what if we can't solve it as elegantly, and we need to ... > > > Should we typecheck in this case to ensure that if we pass a string > > for "fast_mode" we will raise an exception? > > Why are you concerned only with type errors on inputs? > Even if you could do exhaustive checking of input parameters to > make sure they are the only acceptable values, what prevents your > user from providing the wrong valid value? ?What made you pick on > type errors in the first place? ?If it turns out that an argument > of 422 is a typo for 42, why is that less of a problem? ?Just because > you are used to systems where one kind of error is always caught does > not really make you invulnerable. ?You'll have no problem telling > your users that the 422 is their fault. ?Why do you have such > certainty that passing in "nonsense" as a boolean is a failure > you need to deal with? I'm going to play Devil's Advocate here. The motivation here is not "we want type safety" but "our unit tests can't register this deliberate error because it passes silently". Presumably if they had a function that accepted integers, and 442 was an invalid value, and the function failed silently in a unit test, they would also consider whether it should instead fail loudly. It's always a judgment call how much to screen for bad input, but type errors aren't different from any other error in this regard. Sometimes it's appropriate (note: not, IMHO, in this case), just like it's sometimes appropriate to check for 442. Carl Banks From mhjorleifsson at gmail.com Thu Jan 8 13:49:54 2009 From: mhjorleifsson at gmail.com (Mike Hjorleifsson) Date: Thu, 8 Jan 2009 10:49:54 -0800 (PST) Subject: sftp with no password from python References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> Message-ID: <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> On Jan 8, 10:39?am, loial wrote: > Is it possible to use sftp without a password from python? Yes you can use keys you preestablish between the server and client so you dont need passwords, i do this on all my servers then lock off the ability to accept passwords at all, this way no one can dictionary attack my ssh servers. From luke.leighton at googlemail.com Thu Jan 8 13:50:23 2009 From: luke.leighton at googlemail.com (lkcl) Date: Thu, 8 Jan 2009 10:50:23 -0800 (PST) Subject: compiling python2.5 on linux under wine References: Message-ID: > ... aaaand, that means disabling setup.py or hacking it significantly > to support a win32 build, e.g. to build pyexpat, detect which modules > are left, etc. by examining the remaining vcproj files in PCbuild. ok - i started the hacking. the first bit of hacking is this, in distutils/sysconfig.py, added to _init_nt() try: filename = get_makefile_filename() parse_makefile(filename, g) except IOError, msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror raise DistutilsPlatformError(my_msg) # load the installed pyconfig.h: try: prefix = EXEC_PREFIX prefix = os.path.join(prefix, "PC") filename = os.path.join(prefix, "pyconfig.h") parse_config_h(file(filename), g) except IOError, msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror raise DistutilsPlatformError(my_msg) global _config_vars _config_vars = g that gets me part-way - at least i get... oh dear : self.build_extensions() File "../setup.py", line 183, in build_extensions self.compiler.set_executables(**args) File "Z:\mnt\src\python2.5-2.5.2\lib\distutils\ccompiler.py", line 165, in set_executables (key, self.__class__.__name__) ValueError: unknown executable 'compiler_so' for class MSVCCompiler whoops :) so, next, we hack in a compiler, in to ... ooo, let's saaay... distutils/cygwinccompiler.py, just for fun. now we get this! winegcc -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IZ:\mnt\src\python2.5-2.5.2\./Include -I. - IInclude -I../Include -I/usr/local/include -IZ:\mnt\src \python2.5-2.5.2\include -IZ:\mnt\src\python2.5-2.5.2\PC -c Z:\mnt\src \python2.5-2.5.2\Modules\_ctypes/_ctypes_test.c -o z:\mnt\src \python2.5-2.5.2\modules\_ctypes\_ctypes_test.o wha-hey! but... oh dear. oh dear number 1) firstly, err.... this is cross-compiling - those path names are bullshit because actually we're compiling on.... LINUX damnit, not windows. hmm.... there's something to work around that one, perhaps, by installing the mingw32 compiler under wine (o god i've done that before, it's dreadfully slow) oh dear number 2) File "Z:\mnt\src\python2.5-2.5.2\lib\os.py", line 562, in spawnv return _spawnvef(mode, file, args, None, execv) File "Z:\mnt\src\python2.5-2.5.2\lib\os.py", line 545, in _spawnvef wpid, sts = waitpid(pid, 0) NameError: global name 'waitpid' is not defined err.... oh - ok, found another missing function: spawnv. so, added that, in PC/pcbuild.h: #ifdef __WINE__ #define HAVE_SPAWNV #endif and after some futzing around with yet more #ifdefs in posixmodule.c we have another build - this time using wine's spawnv so it doesn't try to find a non-existent waitpid aaannnd SPLAT yesss, we get the crash-output from winegcc: Failed to configure _ctypes module building '_ctypes_test' extension winegcc -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IZ:\mnt\src\python2.5-2.5.2\./Include -I. - IInclude -I../Include -I/usr/local/include -IZ:\mnt\src \python2.5-2.5.2\include -IZ:\mnt\src\python2.5-2.5.2\PC -c Z:\mnt\src \python2.5-2.5.2\Modules\_ctypes/_ctypes_test.c -o z:\mnt\src \python2.5-2.5.2\modules\_ctypes\_ctypes_test.o wine: Unhandled page fault on read access to 0x7265704f at address 0x601ec25b (thread 001c), starting debugger... Unhandled exception: page fault on read access to 0x7265704f in 32-bit code (0x601ec25b). Register dump: CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b EIP:601ec25b ESP:0032c70c EBP:0032c718 EFLAGS:00010206( - 00 - RIP1) EAX:7265704f EBX:7bc8a7a4 ECX:00000003 EDX:604ab3d7 ESI:0032c848 EDI:7265704f Stack dump: 0x0032c70c: 7bc6859d 7265704f 6056a0b8 0032c788 0x0032c71c: 603fd0eb 7265704f 006e9544 001bc84c 0x0032c72c: 006c574c 6056b82c 605721a0 00000002 0x0032c73c: 0032c7d8 718e21fe 0016329c 7265704f 0x0032c74c: 00730065 002e0074 0000006f 00159320 0x0032c75c: 603aa590 001b3f0c 005086e0 00000004 Backtrace: =>1 0x601ec25b strlen+0xb() in libc.so.6 (0x0032c718) fixme:dbghelp_dwarf:dwarf2_parse_variable Unsupported form for const value degToRad (a) 2 0x603fd0eb do_mkvalue+0x3db(p_format=, p_va=, flags=0x0) [/mnt/src/python2.5-2.5.2/ build/../Python/modsupport.c:419] in python (0x0032c788) 3 0x603fcc6d do_mktuple+0x7d(p_format=0x32c848, p_va=0x32c844, endchar=0x29, n=0x2, flags=0x0) [/mnt/src/python2.5-2.5.2/build/../ Python/modsupport.c:268] in python (0x0032c7b8) ..... ..... hey, this is fun! let's try a crazed compile of python and see what falls over, wheeeee :) ... much as this seems to be consuming much of my time, for some bizarre reason i just can't seem to stop. anyway - yes, this is effectively cross-compiling, and so the python25.exe and environment created is unfortunately expecting to see a windows-like environment. bugger. i'll ask on the wine lists if there's a "back-translator". winegcc and wineg++ are wrapper-scripts that wrap gcc and g++ to "make it look like" you're compiling for win32 when in fact you're compiling under linux. if there was a back-translation of that concept, that recognised z: \blahblah and back-translated it into /unix/blah then it would be possible to get away with specifying _that_ script as the compiler, which would then pass winegcc as _its_ script.... yuukkk! From zac256 at gmail.com Thu Jan 8 13:54:31 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 10:54:31 -0800 Subject: Making a decorator a staticmethod Message-ID: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> I have a decorator in a class to be used by that class and by inheriting classes ###### class C(object): @staticmethod # With this line enabled or disabled usage in either C or D will be broken. To see that D works remember to remove usage in C def decorateTest(func): def newFunc(*args, **kwargs): print args, kwargs return func(*args, **kwargs) return newFunc @decorateTest def testDecorated(self): return None class D(C): @C.decorateTest def test2(self): return None ###### The exception that I get when using it as a staticmethod and try to use it in the baseclass is "TypeError: 'staticmethod' object is not callable". When it is not staticmethod the exception I get in the extension class is is "TypeError: unbound method decorateTest() must be called with C instance as first argument (got function instance instead)" Python version is 2.5.1 -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From houdinihound69 at gmail.com Thu Jan 8 13:58:05 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 10:58:05 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> Message-ID: <51303f95-3e67-4baf-9b90-93300fcb9605@k36g2000pri.googlegroups.com> On Jan 8, 10:33?am, tryg.ol... at gmail.com wrote: > On Jan 8, 1:16 pm, Jose C wrote: > > > > > > c["mycook"]["expires"] = 0 > > > Set ["expires"] using the following format to any time less than > > current (which causes the browser to delete the cookie). > > Here's a function I use to return a cookie expiry timestamp, negative > > values passed in result in cookie being deleted. > > > def cookie_expiry_date(numdays): > > ? ? """ Returns a cookie expiry date in the required format. ?-ve > > value in = kill cookie. > > ? ? `expires` should be a string in the format "Wdy, DD-Mon-YY > > HH:MM:SS GMT" > > ? ? NOTE! ?Must use [expires] because earlier IE versions don't > > support [max-age]. > > ? ? """ > > ? ? from datetime import date, timedelta > > ? ? new = date.today() + timedelta(days = numdays) > > ? ? return new.strftime("%a, %d-%b-%Y 23:59:59 GMT") > > > Usage: > > c["mycook"]["expires"] = cookie_expiry_date(-10) ?# any negative value > > will remove cookie > > > HTH, > > JC > > Jose C's piece of code works to delete the cookie as does setting > ["expires"]=0 but ONLY as long as I also set the path. ?Why is this? The path specifies which directory the cookie is active. Usually the path is set to /, which means the cookie is valid throughout the entire domain, but you could set it to /mydir meaning it would only be active for pages within /mydir. > So what would be the best way to do this. ?I tried reading in the > existing cookie (b), creating a new cookie (c) with all the same > values except for the "expires" but this did not get my cookie > deleted. To kill the cookie, simply set a cookie with the same name (and path) and a past date (or 0, although IIRC there was some issue with 0 being used on a particular browser some time ago, can't remember which on at the moment) as an 'expires' parameter, is enough to tell the browser to kill an existing cookie with that same name, regardles of it's value or previous expiry, etc. Basically, when you set a cookie, the browser overwrites the previous one of the same name if it exists. If not, it creates a new cookie with your specified parameters. So in your case, when you want to kill the cookie you set previously, you should be able to just set a cookie of the exact same name, path and 'expire' it appropriately, and the browser takes care of the rest. Don't worry about assigning it's previous value, the browser is just going to delete it anyway. JC From marduk at letterboxes.org Thu Jan 8 14:07:34 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 08 Jan 2009 14:07:34 -0500 Subject: How do you write to the printer ? In-Reply-To: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> References: <1dbam45a53p92p6puv76bqgquqvb6rcjcv@4ax.com> Message-ID: <1231441654.3358.3.camel@localhost.localdomain> On Wed, 2009-01-07 at 16:46 -0600, David at bag.python.org wrote: > Can find nothing in the on-line docs or a book. > Groping in the dark I attempted : > > script24 > import io > io.open('stdprn','w') # accepted > stdprn.write('hello printer') # fails < stdprn is not defined > You didn't specify what platform you are running on, but the first problem I see with the above is... well stdprn is not defined. Did you perhaps mean: sdtprn = io.open('stdprn', 'w') stdprn.write(...) However on a Linux system that will simply open and write to a file called 'stdprn' in your current directory. -a From houdinihound69 at gmail.com Thu Jan 8 14:07:44 2009 From: houdinihound69 at gmail.com (Jose C) Date: Thu, 8 Jan 2009 11:07:44 -0800 (PST) Subject: How to Delete a Cookie? References: <17f8d3eb-89ee-4562-af85-560b68a8904c@q9g2000yqc.googlegroups.com> <7793f173-1d34-458c-8a10-fa6d3711b98d@o4g2000pra.googlegroups.com> <51303f95-3e67-4baf-9b90-93300fcb9605@k36g2000pri.googlegroups.com> Message-ID: <6e3d1e0c-0d96-40a6-adb2-b3bc10de8995@z28g2000prd.googlegroups.com> > To kill the cookie, simply set a cookie with the same name (and path) Actually you may not even need to specify the path. Just the name and expires param should do the trick. Haven't played with cookies in a while so try with and without the path. From mdw at distorted.org.uk Thu Jan 8 14:13:38 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 8 Jan 2009 19:13:38 +0000 (UTC) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <20090102103915.GJ28417@dragontoe.org> <49653BF6.5020004@strout.net> <6LqdnQurg-dMzPjUnZ2dnUVZ_uGdnZ2d@speakeasy.net> Message-ID: Erik Max Francis wrote: > Terry Reedy wrote: > > > >>> a='par'+'rot' > > >>> b='parrot' > > >>> a is b > > True > > One exactly doesn't really say much. It's implementation dependent, and > depends on the length of the string: > > >>> a = 'this is a much longer ' + 'parrot' > >>> b = 'this is a much longer parrot' > >>> a is b > False That Terry's example works is due to constant folding in the bytecode compiler. Consider: In [1]: a = 'parrot' In [2]: a is 'par' + 'rot' Out[2]: True Fair enough. But build the string in a more complicated way: In [3]: b = 'par' In [4]: a is b + 'rot' Out[4]: False What's going on? In the first case, the compiler notices that both operands to `+' are constants, and evaluates the concatenation at compile-time. The resulting constant string is then interned if it's short enough. Putting part of the string in a variable is enough to stymie this optimization -- the same compiler gets used in functions which can't assume that the variable will still have the same value as it does now. The concatenation method on strings doesn't try to intern the result, as that might be a runtime performance loss. > In practice, tests like these are pretty much never useful. It's > completely implementation dependent when and under what circumstances > fundamental immutable objects are reused, and it's not useful anyway; > what you care about is whether two objects are equal or not, not whether > they're the same object through some optimization behind the scenes. Absolutely. The examples above provide insight into how the specific implementation actually behaves; but that's of strictly academic interest. (Well, I find that sort of thing interesting, anyway.) -- [mdw] From zac256 at gmail.com Thu Jan 8 14:18:37 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 11:18:37 -0800 Subject: Making a decorator a staticmethod In-Reply-To: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <333edbe80901081118p2f6cfb8mda01a908bebf8f7d@mail.gmail.com> I've read the "Making staticmethod objects callable?" thread now, and would have to disagree that all the use cases are strange as stated at http://www.python.org/dev/summary/2006-03-01_2006-03-15/#making-staticmethod-objects-callable In my use case (not the example below) the decorator returns a function of the form def f(self, *args, **kwargs) which makes use of attributes on the instance self. So, it only makes sense to use the staticmethod in the class and in the baseclass. Making this decorator a module level function doesn't make sense here. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 10:54 AM, Zac Burns wrote: > I have a decorator in a class to be used by that class and by inheriting classes > > ###### > class C(object): > @staticmethod # With this line enabled or disabled usage in either C > or D will be broken. To see that D works remember to remove usage in C > def decorateTest(func): > def newFunc(*args, **kwargs): > print args, kwargs > return func(*args, **kwargs) > return newFunc > > @decorateTest > def testDecorated(self): > return None > class D(C): > @C.decorateTest > def test2(self): > return None > ###### > > The exception that I get when using it as a staticmethod and try to > use it in the baseclass is "TypeError: 'staticmethod' object is not > callable". > When it is not staticmethod the exception I get in the extension class > is is "TypeError: unbound method decorateTest() must be called with C > instance as first argument (got function instance instead)" > > Python version is 2.5.1 > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From tjreedy at udel.edu Thu Jan 8 14:32:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:32:57 -0500 Subject: Work with Open Office In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > > > On Thu, Jan 8, 2009 at 10:07 AM, Dan Esch > wrote: > > Okay, I'm currently stuck with VBA / Excel in work and the following > paradigm: > > VB (6? .NET? not sure) ==> VBA ==> Excel 2003 and Access > > Where I'd like to be is this > > Python ==> X ==> Open Office / (MySQL or other) for some > sufficiently useful value of X. > > Does it exist? Is it just a set of modules I need to be looking > for? or something else? > > > > Did you google search first? This is the second result for "Python > OpenOffice". > > http://wiki.services.openoffice.org/wiki/Python PyUNO is basically for working 'live' with OOo. There is also odfpy at http://opendocumentfellowship.com/development/projects/odfpy for working with open doc format documents as produced by OOo and other programs. From pavlovevidence at gmail.com Thu Jan 8 14:34:59 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 11:34:59 -0800 (PST) Subject: cPickle vs pickle discrepancy References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: On Jan 8, 12:27?pm, "Zac Burns" wrote: > Thanks for your patience waiting for me to isolate the problem. > > | Package > --__init__.py ->empty > --Package.py ->empty > --Module.py > ? ? ?import cPickle > ? ? ?class C(object): > ? ? ? ? pass > ? ? ?def fail(): > ? ? ? ? return cPickle.dumps(C(), -1) > > import Package.Module > Package.Module.fail() > > The failure seems to happen because pickle correctly does an absolute > import and cPickle incorrectly relatively imports Package.py and fails > to find Module underneath. > > The package and the module named package was because in there was a > main class defined with the same name as the package in that file and > Module.py contained support code for the package. I'd call it a bug. Nice detecitve work pinpointing it. I suspect the issue disappears (accidentally) in 2.6, though. From the What's New in Python 2.6 doc: C API: the PyImport_Import and PyImport_ImportModule functions now default to absolute imports, not relative imports. This will affect C extensions that import other modules. Presumably __import__ also defaults to absolute (since PyImport_Import calls it) so the two modules should both use absolute imports in 2.6. Carl Banks From tjreedy at udel.edu Thu Jan 8 14:40:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:40:24 -0500 Subject: Tree views - Best design practices In-Reply-To: <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: Filip Gruszczy?ski wrote: >>>>> class Element(object): >> operations = "Element operations" >> >> >>>>> class Group(object): >> operations = "Group operations" >> >> >>>>> e = Element() >>>>> g = Group() >>>>> >>>>> e.operations >> 'Element operations' >>>>> g.operations >> 'Group operations' > > But this is the same as asking for a class, The point is to put (and use) the information about what operations apply to instances in each class rather than in an external function. From mark.fink1 at googlemail.com Thu Jan 8 14:43:43 2009 From: mark.fink1 at googlemail.com (mark) Date: Thu, 8 Jan 2009 11:43:43 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> Message-ID: <1642fe0d-c7e5-41ca-9b7b-753d96646ebc@i18g2000prf.googlegroups.com> > So you can't make an internal DSL like this that uses Python's built- > in grammar. ?You'd have to hack the parser or settle for an external > preprocessor. This time it is really hard for me but I begin accepting the fact that I will have to build an external DSL. I experimented some weeks ago with ANTLR and the tools work fine but I do not like the extra effort to learn and maintain the extra tooling. I think that in the beginning the DSL language will have to change a very often as new features are added. To implement a standardized rock solid language like SQL ANTLR might be the perfect tool but to develop something from scratch that will be expanded interactively a internal DSL has huge benefits. Please not that I really like ANTLR. It is just the first tool I used for this task and I want to double check if other tools fit better to my needs. I will look into Ply and Pyparsing over the next weeks unless someone points out that there is some special tool that makes growing a new "fast evolving" language as easy as building an internal DSL. Maybe this is all overkill and there is a hacking ruby-style DSLs with regular expressions recipe out there? So far I could not find one. > However, the gist of it seems to be that you want to be able to write > files in your DSL that can be imported just like a regular Python > module. ?Yes, that can be done. > > See PEP 302, Import Hooks: > > http://www.python.org/dev/peps/pep-0302/ > > Python's standard importer looks for files with *.py, *.pyc, *.pyd, or > *.so extensions. ?You could write an importer that looks for *.dsl > files, and, instead of loading it as a Python file, invokes your DSL > parser. This is really helpful. Thanks for giving me directions. Mark From zac256 at gmail.com Thu Jan 8 14:49:22 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 11:49:22 -0800 Subject: cPickle vs pickle discrepancy In-Reply-To: References: <333edbe80901051704m726eb873ieaa8ba07ca3b5944@mail.gmail.com> Message-ID: <333edbe80901081149v768cb2f1jdb02270b30b9e5da@mail.gmail.com> Correct, 2.6.1 does not complain. If only I could upgrade! The workaround is obvious and I'll do that. Thanks for your help. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 11:34 AM, Carl Banks wrote: > On Jan 8, 12:27 pm, "Zac Burns" wrote: >> Thanks for your patience waiting for me to isolate the problem. >> >> | Package >> --__init__.py ->empty >> --Package.py ->empty >> --Module.py >> import cPickle >> class C(object): >> pass >> def fail(): >> return cPickle.dumps(C(), -1) >> >> import Package.Module >> Package.Module.fail() >> >> The failure seems to happen because pickle correctly does an absolute >> import and cPickle incorrectly relatively imports Package.py and fails >> to find Module underneath. >> >> The package and the module named package was because in there was a >> main class defined with the same name as the package in that file and >> Module.py contained support code for the package. > > I'd call it a bug. Nice detecitve work pinpointing it. > > I suspect the issue disappears (accidentally) in 2.6, though. From > the What's New in Python 2.6 doc: > > C API: the PyImport_Import and PyImport_ImportModule functions now > default to absolute imports, not relative imports. This will affect C > extensions that import other modules. > > Presumably __import__ also defaults to absolute (since PyImport_Import > calls it) so the two modules should both use absolute imports in 2.6. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Jan 8 14:51:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 14:51:23 -0500 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: Sergey Kishchenko wrote: > In Python empty container equals False in 'if' statements: > > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: > > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. I think, this > behaviour conflicts with 'Explicit is better than implicit' and > 'Practicality beats purity' statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. Sensible (and documented) defaults pervade Python. From tim at thechases.com Thu Jan 8 14:52:38 2009 From: tim at thechases.com (Tim Chase) Date: Thu, 08 Jan 2009 13:52:38 -0600 Subject: figuring week of the day.... In-Reply-To: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <49665986.7080301@thechases.com> tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. sounds like you want the standard library's "calendar" module, particularly the monthcalendar() which gets you pretty close. For a lazy version just using the stdlib with minimal fuss: >>> import calendar as c >>> week = lambda y,m,d: [w for w in c.monthcalendar(y, m) if d in w][0] >>> week(2009, 1, 8) [5, 6, 7, 8, 9, 10, 11] the monthcalendar() call returns the whole month's calendar which may be more what you want for the big-picture. -tkc From joe at strout.net Thu Jan 8 14:57:05 2009 From: joe at strout.net (Joe Strout) Date: Thu, 08 Jan 2009 12:57:05 -0700 Subject: why cannot assign to function call In-Reply-To: References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <49665A91.8070801@strout.net> Mark Wooding wrote: >>>> The `they're just objects' model is very simple, but gets tied up in >>>> knots explaining things. The `it's all references' model is only a >>>> little more complicated, but explains everything. >>> But it *over* explains, because it implies things that "everybody knows" >>> about references in other languages that aren't true for Python. > > I addressed this elsewhere. Summary: `pass-by-reference' is a different > thing to `all you manipulate are references': Python does pass-by-value, > but the things it passes -- by value -- are references. Quite right. It's easy to see this in languages where some types are references and others are simple values; and even easier in such a language that supports both pass-by-value and pass-by-reference (such as REALbasic or VB.NET). Then you can easily see, in one language, all combinations of [value type, reference type] * [pass by ref, pass by val]. In Python, we only have reference types, and we only have pass by value, so out of the four combinations above, there is only one: references passed by value. You'd think this would make it easier, but from the raging debates and repeated obfuscation on this point, it apparently makes Python MORE difficult to understand and explain (at least for some). > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. If you want a function to > modify your variable, you have to pass a pointer value which points to > it. Right -- a C/C++ pointer is (or at least, can be in normal usage) pretty similar to a reference (though of course you can do more low-level and hackish things with them too). In C, such a reference is always passed by value, as in Python or Java, and just like the default mode in RB or .NET. In C++, you can also choose to pass such a parameter by reference, like the ByRef mode in RB and .NET. This parameter passing mode is unavailable in Python or Java. >>> Okay, the abstraction has leaked again... are the paperweights references >>> to the objects, or the names we've bound objects to? I'm confused... > > They're the references to the objects. You don't bind names to > objects. You bind names slots in which you store references. Well put (again). This is technically the correct description, though in casual usage, I think it's fine to occasionally gloss over some of these layers as long as everyone involved understands what is meant. (This is especially true when the references are to immutable objects, which are functionally very similar to simple values.) >> How do we decide what is best for newcomers to Python, depending on >> background? > > That I really don't know. I'm not good at teaching total beginners > (does it show?) because I'm too enmired in the theory. ... FWIW, I've spent a fair amount of time teaching beginners, though not so much in Python yet. But plenty of time in other languages where the same questions come up. In my experience, pointing out that a variable of any object type contains a *reference* to that object, rather than the object data itself, and then illustrating with a couple of examples, quickly clears up any confusion. I've never had a newbie require more than a couple of exchanges on this topic before they get it. (And before I joined the Python community, I never even felt the need to actually draw a picture [1] to make it clearer.) > What I am pretty sure of is that references are going to have to enter > the picture at some point, because other models get too complicated. I agree completely. I can barely understand the other models myself. Best, - Joe [1] http://www.strout.net/info/coding/valref/ From jgardner at jonathangardner.net Thu Jan 8 14:57:54 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 11:57:54 -0800 (PST) Subject: Making a decorator a staticmethod References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> On Jan 8, 11:18?am, "Zac Burns" wrote: > > In my use case (not the example below) the decorator returns a > function of the form def f(self, *args, **kwargs) which makes use of > attributes on the instance self. So, it only makes sense to use the > staticmethod in the class and in the baseclass. Making this decorator > a module level function doesn't make sense here. > I don't think you should be using staticmethod in this case since you are relying on information in the class itself. This really looks like it should be a classmethod. Granted, the example you gave can be a staticmethod, but it sounds like you want to incorporate some of the information in the class. (Aside: I really can't think of any reason to use staticmethods in Python other than to organize functions into namespaces, and even then, that's what modules are for, right?) I think you need to show a better example of what it is you are trying to do. From clp2 at rebertia.com Thu Jan 8 15:03:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 12:03:35 -0800 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: <50697b2c0901081203n459bd979idabb843f322d40f1@mail.gmail.com> On Thu, Jan 8, 2009 at 5:53 AM, Sergey Kishchenko wrote: > In Python empty container equals False in 'if' statements: > > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: > > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. I think, this > behaviour conflicts with 'Explicit is better than implicit' and > 'Practicality beats purity' statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. Python has a rich notion of boolean truth compared to other languages. In this case, by default, non-None objects are considered True. It's a reasonable default behavior since wanting to differentiate between None and non-None objects is such a common task. Also, I've been programming in Python for a long while and have yet to encounter any bug due to this behavior. Regarding the Zen, on the contrary, this is a perfect example of "Practicality beats purity" in action. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 8 15:04:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:04:07 -0500 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: <4965c801$0$193$e4fe514c@news.xs4all.nl> References: <4965c801$0$193$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek wrote: > I can't think of anything that could cause this. Similarly, eval('09') > fails, but for string 0x with x<8 it works. I am teaching myself Python > in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-- >> VisualBasic(2000)-->Python. I am a physicist, have programmed computers > all my life but I won't understand the real tech jargon of present day > computer science. Please keep it simple I taught myself Python as a statistician with a Fortran/C backgound by interleaving interactive experiments (such as you did) with reading of the manuals. The Language Manual chapter on Lexical Analysis has an Integer Literals subsection that answers this question. I strongly recommend you peruse the Language Manual and the initial Library Manual chapters on built-ins. tjr From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:06:29 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:06:29 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> Message-ID: <49666a71$0$25544$426a74cc@news.free.fr> Zac Burns a ?crit : > I've read the "Making staticmethod objects callable?" thread now, and > would have to disagree that all the use cases are strange as stated at > http://www.python.org/dev/summary/2006-03-01_2006-03-15/#making-staticmethod-objects-callable > > In my use case (not the example below) Then please provide the concrete use case (or at least anything close enough) > the decorator returns a > function of the form def f(self, *args, **kwargs) There's nothing magic wrt/ 'self'. Heck, it's not even a keyword. > which makes use of > attributes on the instance self. s/instance self/object passed as first argument/ > So, it only makes sense to use the > staticmethod in the class and in the baseclass. Nope. It makes senses for any object implementing the (implied) interface, whatever the class or base class. > Making this decorator > a module level function doesn't make sense here. It does, as long as you clearly document the expected interface. Please understand that what you decorate are plain functions - not "methods". Whether the function is being used as the implementation for a method or not is totally irrelevant - what's relevant is what the decorated function expects as arguments. wrt/ functions vs methods, technically, there's *no* difference between: def func(some_interface): do_something_depending_on(some_interface) and class SomeClassImplementingSomeInterface(object): def method(self): do_something_depending_on(some_interface) As a matter of fact, the second snippet is strictly equivalent to: def func(some_interface): do_something_depending_on(some_interface) class SomeClassImplementingSomeInterface(object): pass SomeClassImplementingSomeInterface.method = func IOW, a method is implemented by a function (that takes the object as first argument). To be true, a Python "method" object is only a thin wrapper around a function and an object, that is instanciated (by the function object itself) each time an attribute lookup resolves to a function object accessed thru the descriptor protocol. wrt/ decorators: well, a "decorator" is just any callable(that is, any object implementing the __call__ method) taking a callable as first argument and returning a callable[1]. Now some decorator are generic - they just don't care about the decorated function's signature -, and some are not - they expect a (more or less) defined argument list. For example, the Django framework provides a set of decorators that expects to be applied to callables taking an HttpRequest object as first argument. That doesn't mean these decorators have to be methods of the HttpRequest class - they are just callable that takes as argument a callable which itself takes an HttpRequest object as first argument. [1] and even this definition, while technically mostly correct, doesn't cover all acceptations of the term "decorator" - some so-called decorators are in fact callables taking some specific argument list and returning a proper decorator. That's what you get each time you see something like: @decorate(some_arg) def some_func(other_arg): code_here HTH From clp2 at rebertia.com Thu Jan 8 15:11:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 12:11:36 -0800 Subject: figuring week of the day.... In-Reply-To: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> Message-ID: <50697b2c0901081211k7c18df01je8990b0269e9c363@mail.gmail.com> On Tue, Jan 6, 2009 at 7:56 AM, tekion wrote: > Is there a module where you could figure week of the day, like where > it starts and end. I need to do this for a whole year. Thanks. The "%U" time format specifier (Week number of the year) to strftime() [http://docs.python.org/library/datetime.html#strftime-behavior] might be helpful. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gruszczy at gmail.com Thu Jan 8 15:13:37 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 21:13:37 +0100 Subject: Tree views - Best design practices In-Reply-To: References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <496626E6.2030501@mrabarnett.plus.com> <1be78d220901080821j54ecfb2bm629849dab6e931b8@mail.gmail.com> Message-ID: <1be78d220901081213r201f6549jc0ecfed82a8cacee@mail.gmail.com> I'd love to have operations methods, which would return names of operations and references to proper methods. The problem is that certain operations require more, than just running some operation on the Group or Element. Let's say, you want to add new group to an existing one - you can't do that to an element. But adding a group cannot be just done by calling group.addGroup. You must first construct the group or at least get information require to construct a group, so you must for example call a dialog which will ask for information about the group. And that's in conflict with model/view pattern. And that's not all. I am using qt and when I want to add this group to another one, I have to first call beginInsertRows on the model used by the tree view (it's a layer between the gui and the real model). I tried building a wrapper around my model which would provide additional info, but then I had to keep relations between objects in two places (relations between real groups and elements and wrapper groups and wrapper elements), which wasn't the right way to do. I just can figure a simple, elegant way to do this. -- Filip Gruszczy?ski From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:21:07 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:21:07 +0100 Subject: Making a decorator a staticmethod In-Reply-To: <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> Message-ID: <49666ddf$0$10251$426a74cc@news.free.fr> Jonathan Gardner a ?crit : > On Jan 8, 11:18 am, "Zac Burns" wrote: >> In my use case (not the example below) the decorator returns a >> function of the form def f(self, *args, **kwargs) which makes use of >> attributes on the instance self. So, it only makes sense to use the >> staticmethod in the class and in the baseclass. Making this decorator >> a module level function doesn't make sense here. >> > > I don't think you should be using staticmethod in this case since you > are relying on information in the class itself. Nope. He's relying on (part of) the interface(s) implemented by the first argument. The class object itself has nothing to do with is (well... it does, but only as far as it contribute to the implementation of the interface expected by the decorator). > (Aside: I really can't think of any reason to use staticmethods in > Python other than to organize functions into namespaces, and even > then, that's what modules are for, right?) I sometimes found staticmethods to be useful, in that they provided polymorphic dispatch without having to care about the containing module (or whether the object thru which the staticmethod_or_function is accessed is a module, class or instance). > I think you need to show a better example of what it is you are trying > to do. +1 on this. So far, the only concrete use case for staticmethod as a decorator I can think of is the one exposed above for staticmethods in general. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:24:40 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:24:40 +0100 Subject: eval('07') works, eval('08') fails, why? In-Reply-To: References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: <49666eb4$0$10251$426a74cc@news.free.fr> Grant Edwards a ?crit : > On 2009-01-08, Alex van der Spek wrote: > >> Thanks much, that makes sense! > > Well, that's the correct explanation. > > Whether that feature makes sense or not is debatable. Even I'm > not old-school enough that I ever use octal literals -- and I > used Unix on a PDP-11 for years (actually had my own PDP-11 for > while, but it never worked). Now that I think of it, my > Heathkit Z80 stuff used octal notation too. What about your DeathStation 9000 ?-) From tjreedy at udel.edu Thu Jan 8 15:33:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:33:59 -0500 Subject: How to deepcopy a list of user defined lists? In-Reply-To: <35331.99250.qm@web7908.mail.in.yahoo.com> References: <35331.99250.qm@web7908.mail.in.yahoo.com> Message-ID: srinivasan srinivas wrote: > Hi, > I have a class which is a subclass of builtin-type list. > > #------------------------------------------------------------------------------ > class clist(list): > def __new__(cls, values, ctor): > val = [] > for item in values: > item = ctor(item) > val.append(item) > > self = list.__new__(cls, val) > self.__values = val > self.__ctor = ctor > return self A subclass of list should populate the list in __init__, not __new__, usually by calling list.__init__, as lists are mutable and subclasses thereof should be too. class clist(list): def __init__(self, values, ctor): list.__init__(self, map(ctor, values)) self.__ctor = ctor clist1 = clist((1,2,3),str) clist2 = clist((1,2,3), float) alist1 = [clist1,clist2] print(alist1) #[['1', '2', '3'], [1.0, 2.0, 3.0]] from copy import deepcopy alist2 = deepcopy(alist1) print(alist2) #[['1', '2', '3'], [1.0, 2.0, 3.0]] print(alist1[0] is alist2[0]) #False - ie, inner clist was copied I omitted your __values attribute as redundant with the value of the clist itself. Since clist is not a mixin class, double underscores for name-mangling are not needed. Unless you make use of _ctor in other methods, initializing regular lists with 'list(map(ctor,values)) would work as well. Terry Jan Reedy From jgardner at jonathangardner.net Thu Jan 8 15:35:36 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 12:35:36 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> Message-ID: <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> On Jan 8, 8:16?am, MRAB wrote: > Filip Gruszczy?ski wrote: > > Hi! > > > I have certain design problem, which I cannot solve elegantly. Maybe > > you know some good design patterns for this kind of tasks. > > > Task: > > > We have a model which has two kinds of objects: groups and elements. > > Groups can hold other groups (subgroups) and elements. It's a simple > > directory tree, for example. We would like to display it in a tree > > view (which sound good for this kind of model). What is more required, > > for groups and elements there are different sets of operations, which > > should be available under right click. For example for group, there > > should be operations: 'add element' and 'add group', and for element > > there should be 'change properties'. > > > Do you know any smart way to achieve this? The simplest way is to ask > > for the class and display operations accordingly. But from the first > > day with OO programming I have heard, that asking for class is wrong. > > But I can hardly see any easy and more maintainable solution for this > > problem. Could you help me with this? > > You could ask the object what the operations are. Here's an example > using strings: > > ?>>> class Element(object): > ? ? ? ? operations = "Element operations" > > ?>>> class Group(object): > ? ? ? ? operations = "Group operations" > > ?>>> e = Element() > ?>>> g = Group() > ?>>> > ?>>> e.operations > 'Element operations' > ?>>> g.operations > 'Group operations' When faced with this kind of scenario, I usually write boolean methods like "is_leaf" or "is_branch". class Element(object): @staticmethod def is_leaf(): return True @staticmethod def is_branch(): return False class Group(object): @staticmethod def is_leaf(): return False @staticmethod def is_branch(): return True Of course, you have to give priority to one or the other, in case an object thinks it is both. if thing.is_branch(): # Treat it like a branch elif thing.is_leaf(): # Treat it like a leaf I believe this is a simpler method than checking a single attribute for a name. From tjreedy at udel.edu Thu Jan 8 15:43:34 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 15:43:34 -0500 Subject: Replying to list messages In-Reply-To: <87hc4agz1f.fsf_-_@benfinney.id.au> References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > For Thunderbird (which I see you're using, Paul), the open bug report > is . > Meanwhile, you can install an add-on to provide the function > . When I read the list as a newsgroup (gmane.comp.python.general), the Reply button of Thunderbird replies to the newsgroup. There is also a Replay All button and Message/Reply to Sender only menu selection. From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 15:51:44 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 21:51:44 +0100 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: References: Message-ID: <4966750c$0$5150$426a74cc@news.free.fr> Sergey Kishchenko a ?crit : > In Python empty container equals False in 'if' statements: Yes. > # prints "It's ok" > if not []: > print "It's ok" > > Let's create a simple Foo class: > > class Foo: > pass > > Now I can use Foo objects in 'if' statements: Yes. > #prints "Ouch!" > f=Foo() > if f: > print "Ouch!" > > So, default __nonzero__ impl is to return True. Yes. It's clearly documented FWIW. > I think, this > behaviour conflicts with 'Explicit is better than implicit' Why so ? It *is* explicit that the default for an object is to have a true value in a boolean context. > and > 'Practicality beats purity' Quite on the contrary. From a practical POV, the default truth values of Python objects are most of the time what you practically want in a boolean context - that is, any non-None object, non-empty sequence and non-zero numeric objects are true. __nonzero__ is here for the *very few* corner cases where this is not the sensible default. > statements. I think, throwing a TypeError > exception would be better. It will result in more explicit code with > fewer errors. I can understand that you've been bitten by the rules regarding truth values of Python objects. But if so, please remember that it's only because *you* assumed something different from what's documented. From robert.kern at gmail.com Thu Jan 8 15:51:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Jan 2009 15:51:45 -0500 Subject: mmap only supports string In-Reply-To: References: Message-ID: Neal Becker wrote: > Problem is, AFAIK a string can only be created as a copy of some other data. Say I'd like to take some large object and read/write to/from mmap object. A good way to do this would be the buffer protocol. Unfortunately, mmap only supports string. A string could only be created after copying the original object AFAIK. > > I think mmap should work directly with buffer protocol, so it could directly read/write with objects supporting buffer protocol. Specifically, mmap slice should support buffer protocol. You could use numpy as an intermediate. Slices will be numpy arrays which are views onto the mmap (no memory copying), and you can get a buffer from the numpy arrays. -- 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 lindahl at pbm.com Thu Jan 8 15:52:36 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 12:52:36 -0800 (PST) Subject: ulimit stack size and python threads Message-ID: I figure this is a FAQ, but I can't find it in any FAQs. I want to limit the stacksize on my server. If I set it to 8 megs, or unlimited, python is happy. If I set it to 4 gigabytes, things like yum (which is a python program) crash creating a thread. This is on an x86_64 linux kernel, RHEL5, etc etc. Why is Python overloading the meaning of the ulimit -s like this? There are plenty of real non-python programs with huge stack usage, and I'd like my system default stack limit to be less than unlimited but much larger than Python will allow. -- greg From gruszczy at gmail.com Thu Jan 8 16:00:04 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 22:00:04 +0100 Subject: Tree views - Best design practices In-Reply-To: <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: <1be78d220901081300x67023278gb5ae5645298947af@mail.gmail.com> > class Element(object): > @staticmethod > def is_leaf(): return True > @staticmethod > def is_branch(): return False > > class Group(object): > @staticmethod > def is_leaf(): return False > @staticmethod > def is_branch(): return True > > Of course, you have to give priority to one or the other, in case an > object thinks it is both. > > if thing.is_branch(): > # Treat it like a branch > elif thing.is_leaf(): > # Treat it like a leaf > > I believe this is a simpler method than checking a single attribute > for a name. Is it really any better than asking for class? I mean, if I need to add another class to a hierarchy which behaves differently, will it be more flexible (actually you have to add another method to every class and check for in the gui). I believe it's just the same as asking for the class, but we hide it under static methods. It's no different though. -- Filip Gruszczy?ski From google at mrabarnett.plus.com Thu Jan 8 16:03:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 21:03:53 +0000 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49666A39.5000205@mrabarnett.plus.com> Greg Lindahl wrote: > I figure this is a FAQ, but I can't find it in any FAQs. > > I want to limit the stacksize on my server. > > If I set it to 8 megs, or unlimited, python is happy. > > If I set it to 4 gigabytes, things like yum (which is a python > program) crash creating a thread. This is on an x86_64 linux kernel, > RHEL5, etc etc. > > Why is Python overloading the meaning of the ulimit -s like this? > There are plenty of real non-python programs with huge stack usage, > and I'd like my system default stack limit to be less than unlimited > but much larger than Python will allow. > I'm only guessing, but could it be a 32-bit limit somewhere? Have you tried, say, 1GB, which would be within a 32-bit limit? From tim.arnold at sas.com Thu Jan 8 16:06:21 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 8 Jan 2009 16:06:21 -0500 Subject: drive a desktop app from python? Message-ID: Hi, I don't even know what to google for on this one. I need to drive a commercial desktop app (on windows xp) since the app doesn't have a batch interface. It's intended to analyze one file at a time and display a report. I can get the thing to write out the report an html browser, but I have thousands of files I need it to analyze every night. Is there any lib or recipe(s) for doing something like this via python? thanks, --Tim Arnold From martin at v.loewis.de Thu Jan 8 16:07:03 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 22:07:03 +0100 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> Message-ID: <49666AF7.9010804@v.loewis.de> > i'd just ... much rather be completely independent of proprietary > software when it comes to building free software. I guess my question is then: why do you want to use Windows in the first place? Regards, Martin From lindahl at pbm.com Thu Jan 8 16:07:49 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 13:07:49 -0800 (PST) Subject: ulimit stack size and python threads References: Message-ID: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> > I'm only guessing, but could it be a 32-bit limit somewhere? Have you > tried, say, 1GB, which would be within a 32-bit limit? Indeed, ulimit -s 1000000 (a bit smaller than 1 GB) does work, but it doesn't solve my problem, since I want to set the limit higher than 1 GB. -- greg From jgardner at jonathangardner.net Thu Jan 8 16:25:36 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 13:25:36 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> On Jan 8, 1:00?pm, "Filip Gruszczy?ski" wrote: > > Is it really any better than asking for class? I mean, if I need to > add another class to a hierarchy which behaves differently, will it be > more flexible (actually you have to add another method to every class > and check for in the gui). I believe it's just the same as asking for > the class, but we hide it under static methods. It's no different > though. > Yes. There is a difference between the interface of an object (namely, what methods and attributes it has and what their semantic meaning is) and the class of an object (what methods and attributes it has and how they are implemented.) In general, you shouldn't be asking about an object's class. Down the road, you may want to use an object that isn't of the same class but does support the interface. Consider how the file object is used in Python. Pretty much every place you can use a file object you can use a StringIO, right? That's because StringIO supports the file interface while it isn't a file. You may want to read up on 'duck typing' to get a better sense of why this is important. From jgardner at jonathangardner.net Thu Jan 8 16:33:17 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 13:33:17 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> Message-ID: On Jan 8, 1:00?pm, "Filip Gruszczy?ski" wrote: > > Is it really any better than asking for class? I mean, if I need to > add another class to a hierarchy which behaves differently, will it be > more flexible (actually you have to add another method to every class > and check for in the gui). I believe it's just the same as asking for > the class, but we hide it under static methods. It's no different > though. > One additional note: Given that the interface and class of an object are two, orthogonal and independent things, how do you tell what interfaces an object supports? There are a variety of methods. I can break them down into 3. (1) The user of the object keeps track of which classes support which interfaces. This is bad because you can't anticipate new classes properly. Sometimes it is necessary when the other two options aren't feasible. (2) The implementor of the object provides information on what interfaces it supports through a method or attribute of some sort. This is bad because there may be new interfaces that come into existence that the object does support but the implementor doesn't know about it and so the object says it doesn't support the interface. (3) Some 3rd Party registration of interfaces and classes keeps track of which classes support which interfaces, and vice-versa. When you add a new interface, you have to list all the existing classes that also support that interface. When you add a new class, you list all the existing interfaces that it supports. This is just plain hard to do, of course. None of these solutions are perfect, of course. Duck typing tries to solve this problem with option (4): Nobody really keeps track of interfaces at all, and you just kind of wing it hoping for the best. This solution is also far from perfect, but it suggests that you never look at the class of an object, or really, even its interface. You just start using it. So my solution is the "just use it" bit. All the user really needs to know is "Are you a leaf or a branch?" And the objects simply have to answer that question. From thorsten at thorstenkampe.de Thu Jan 8 16:39:18 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 22:39:18 +0100 Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) > On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > > [Python 2.6.1] > > > > to test existing Python code, I ran "python -3" ("warn about Python 3.x > > incompatibilities") against a test file that only contains "print > > 'test'". > > > > Unfortunately I saw no warnings about print becoming a function in > > Python 3 ("print()"). Where is the problem? > > There is no problem. ``print``\s are handled fine by the 2to3.py > script. The option warns about stuff that is not easily automatically > converted. There /is/ obviously a problem: the Python command line help[1] and the "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido van Rossum are misleading (if not to say wrong): """ For porting existing [...] code to Python 3.0, the best strategy is the following: [...] 2. [...] Turn on the -3 command line switch. This enables warnings about features that will be removed (or change) in 3.0.[...] 3. Run the 2to3 source-to-source translator [...] """ Thorsten [1] "-3 : warn about Python 3.x incompatibilities" From gruszczy at gmail.com Thu Jan 8 16:50:50 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 8 Jan 2009 22:50:50 +0100 Subject: Tree views - Best design practices In-Reply-To: <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> Message-ID: <1be78d220901081350h6200dfcfy10196642b7190f6b@mail.gmail.com> > Yes. There is a difference between the interface of an object (namely, > what methods and attributes it has and what their semantic meaning is) > and the class of an object (what methods and attributes it has and how > they are implemented.) > > In general, you shouldn't be asking about an object's class. Down the > road, you may want to use an object that isn't of the same class but > does support the interface. > > Consider how the file object is used in Python. Pretty much every > place you can use a file object you can use a StringIO, right? That's > because StringIO supports the file interface while it isn't a file. > > You may want to read up on 'duck typing' to get a better sense of why > this is important. I have read also your next message and these are good arguments for dynamically typed languages and really convinces me - I mean that they provide some flexibility at the cost of writing a little more. They provide flexibility though in a different field. Duck typing is great, because it allows completely use of a completely different hierarchy, which only has to have the same interface. But I am looking for a different type of flexibility. I would like to be able to add more classes to my hierarchy and not have to change my code in many places when I add new class to the hierarchy. If I have to change every class in the hierarchy because I add new class, then it's not something I would like to do. And idea how I can avoid this? -- Filip Gruszczy?ski From torriem at gmail.com Thu Jan 8 16:54:34 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 08 Jan 2009 14:54:34 -0700 Subject: Work with Open Office In-Reply-To: References: Message-ID: <4966761A.6090507@gmail.com> Dan Esch wrote: > Have been browsing through this list and reading documentation and tutorials > for python self-study. I have, apparently, teh stupid. Google is my > friend. Off I go. Thanks. Let us know how it goes. Last time I tried to script OO, I found it to be much more difficult than VBA. OO's scripting is a mess, honestly. From google at mrabarnett.plus.com Thu Jan 8 16:54:56 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jan 2009 21:54:56 +0000 Subject: ulimit stack size and python threads In-Reply-To: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> Message-ID: <49667630.80006@mrabarnett.plus.com> Greg Lindahl wrote: >> I'm only guessing, but could it be a 32-bit limit somewhere? Have you >> tried, say, 1GB, which would be within a 32-bit limit? > > Indeed, ulimit -s 1000000 (a bit smaller than 1 GB) does work, but it > doesn't solve my problem, since I want to set the limit higher than 1 > GB. > How much higher? You could try just under 4GB (unsigned 32-bit) and just under 2GB (signed 32-bit). From tjreedy at udel.edu Thu Jan 8 17:04:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jan 2009 17:04:04 -0500 Subject: "python -3" not working as expected In-Reply-To: References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: Thorsten Kampe wrote: > * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) >> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: >>> [Python 2.6.1] >>> >>> to test existing Python code, I ran "python -3" ("warn about Python 3.x >>> incompatibilities") against a test file that only contains "print >>> 'test'". >>> >>> Unfortunately I saw no warnings about print becoming a function in >>> Python 3 ("print()"). Where is the problem? >> There is no problem. ``print``\s are handled fine by the 2to3.py >> script. The option warns about stuff that is not easily automatically >> converted. > > There /is/ obviously a problem: the Python command line help[1] and the > "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido > van Rossum are misleading (if not to say wrong): > > """ > For porting existing [...] code to Python 3.0, the best strategy is the > following: > [...] > 2. [...] Turn on the -3 command line switch. This enables warnings about > features that will be removed (or change) in 3.0.[...] > 3. Run the 2to3 source-to-source translator [...] > """ > > Thorsten > [1] "-3 : warn about Python 3.x incompatibilities" > -- Since you are, I believe, at least the second person to report being bit by this confusion, please open an issue at bugs.python.org and suggest a couple of revised sentences that you think are more informative. From zac256 at gmail.com Thu Jan 8 17:07:16 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 8 Jan 2009 14:07:16 -0800 Subject: Making a decorator a staticmethod In-Reply-To: <49666ddf$0$10251$426a74cc@news.free.fr> References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> <49666ddf$0$10251$426a74cc@news.free.fr> Message-ID: <333edbe80901081407u7b41f7a8oe27d98c870561c9a@mail.gmail.com> To Bruno's first e-mail: Everything you said was correct but largely off topic. I did already understand these things as well. To Bruno's second email quote: """ Nope. He's relying on (part of) the interface(s) implemented by the first argument. The class object itself has nothing to do with is (well... it does, but only as far as it contribute to the implementation of the interface expected by the decorator). """ Yes - this is exactly what I was trying to communicate. In addition - perhaps what I should have made clear all along is that the interface I'm relying on isn't as much of an interface as it is an implementation. The attributes that I will be accessing are 'local' (starting with underscores, let's not get into a discussion about this - I know they aren't really local) and are subject to change as the implementation of the class changes. The class provides a 'service' for the inherited classes with differing behaviors for different method via the decorators it provides. The details of which I can't get into because it's proprietary. If this use case is objectionable to you then fine, I've implemented my own staticdecorator. (which simply inherits from staticmethod and implements call). But to those who the use case makes sense for it may be worth thinking about implementing the call method in the main distribution. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 12:21 PM, Bruno Desthuilliers wrote: > Jonathan Gardner a ?crit : >> >> On Jan 8, 11:18 am, "Zac Burns" wrote: >>> >>> In my use case (not the example below) the decorator returns a >>> function of the form def f(self, *args, **kwargs) which makes use of >>> attributes on the instance self. So, it only makes sense to use the >>> staticmethod in the class and in the baseclass. Making this decorator >>> a module level function doesn't make sense here. >>> >> >> I don't think you should be using staticmethod in this case since you >> are relying on information in the class itself. > > Nope. He's relying on (part of) the interface(s) implemented by the first > argument. The class object itself has nothing to do with is (well... it > does, but only as far as it contribute to the implementation of the > interface expected by the decorator). > > >> (Aside: I really can't think of any reason to use staticmethods in >> Python other than to organize functions into namespaces, and even >> then, that's what modules are for, right?) > > I sometimes found staticmethods to be useful, in that they provided > polymorphic dispatch without having to care about the containing module (or > whether the object thru which the staticmethod_or_function is accessed is a > module, class or instance). > > >> I think you need to show a better example of what it is you are trying >> to do. > > +1 on this. So far, the only concrete use case for staticmethod as a > decorator I can think of is the one exposed above for staticmethods in > general. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Thu Jan 8 17:11:29 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 08 Jan 2009 23:11:29 +0100 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49667a11$0$22812$9b622d9e@news.freenet.de> > Why is Python overloading the meaning of the ulimit -s like this? Why do you think Python is overloading the meaning of that? I ensure you it isn't - it doesn't actively care what the limits are. Regards, Martin From invalid at invalid Thu Jan 8 17:12:00 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 08 Jan 2009 16:12:00 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> <49666eb4$0$10251$426a74cc@news.free.fr> Message-ID: On 2009-01-08, Bruno Desthuilliers wrote: > Grant Edwards a ?crit : >> On 2009-01-08, Alex van der Spek wrote: >> >>> Thanks much, that makes sense! >> >> Well, that's the correct explanation. >> >> Whether that feature makes sense or not is debatable. Even I'm >> not old-school enough that I ever use octal literals -- and I >> used Unix on a PDP-11 for years (actually had my own PDP-11 for >> while, but it never worked). Now that I think of it, my >> Heathkit Z80 stuff used octal notation too. > > What about your DeathStation 9000 ?-) The closest thing I've seen to a DS9K would probably be a CDC Cyber 6600 mainframe. I guess for somebody with a mainframe background it might not have been too weird, but for somebody who came from a PDP-11, Z80, 65XX background, it seemed awfully obtuse. -- Grant Edwards grante Yow! I'm having a RELIGIOUS at EXPERIENCE ... and I don't visi.com take any DRUGS From thorsten at thorstenkampe.de Thu Jan 8 17:21:04 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 8 Jan 2009 23:21:04 +0100 Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > Thorsten Kampe wrote: > > * Marc 'BlackJack' Rintsch (8 Jan 2009 16:26:55 GMT) > >> On Thu, 08 Jan 2009 16:38:53 +0100, Thorsten Kampe wrote: > >>> [Python 2.6.1] > >>> > >>> to test existing Python code, I ran "python -3" ("warn about Python 3.x > >>> incompatibilities") against a test file that only contains "print > >>> 'test'". > >>> > >>> Unfortunately I saw no warnings about print becoming a function in > >>> Python 3 ("print()"). Where is the problem? > >> There is no problem. ``print``\s are handled fine by the 2to3.py > >> script. The option warns about stuff that is not easily automatically > >> converted. > > > > There /is/ obviously a problem: the Python command line help[1] and the > > "Porting To Python 3.0" section of "What?s New In Python 3.0" from Guido > > van Rossum are misleading (if not to say wrong): > > > > """ > > For porting existing [...] code to Python 3.0, the best strategy is the > > following: > > [...] > > 2. [...] Turn on the -3 command line switch. This enables warnings about > > features that will be removed (or change) in 3.0.[...] > > 3. Run the 2to3 source-to-source translator [...] > > """ > > > > Thorsten > > [1] "-3 : warn about Python 3.x incompatibilities" > > -- > > Since you are, I believe, at least the second person to report being bit > by this confusion, please open an issue at bugs.python.org and suggest a > couple of revised sentences that you think are more informative. Will do tomorrow. The revised sentence could be in the line of "warn about Python 3.x incompatibilities that cannot trivially be fixed by 2to3.py". Thorsten From david at hlacik.eu Thu Jan 8 17:24:21 2009 From: david at hlacik.eu (=?ISO-8859-2?Q?David_Hl=E1=E8ik?=) Date: Thu, 8 Jan 2009 23:24:21 +0100 Subject: linked list with cycle structure In-Reply-To: <6smp37F763pbU2@mid.uni-berlin.de> References: <6sjok8F6dqciU1@mid.uni-berlin.de> <6smp37F763pbU2@mid.uni-berlin.de> Message-ID: Hi, well i am able to find a loop in a list using two iterators.One iterator runs "two times faster than the other", and if he encounters the first, it means that there is a loop. Example : 1,2,3,4,5,6,7,8,9,5 the algorithm would generate: start - 1,2 iteration 1- 2, 4 iteration 2- 3, 6 iteration 3- 4, 8 iteration 4- 5, 5 ( match) But how can this help me with counting list elements? :( Thanks, D. On Thu, Jan 8, 2009 at 5:48 PM, Diez B. Roggisch wrote: > > David Hl??ik wrote: > > > Hi, > > > > so okay, i will create a helping set, where i will be adding elements > > ID, when element ID will be allready in my helping set i will stop and > > count number of elements in helping set. This is how long my cycled > > linked list is. > > > But what if i have another condition , and that is *i can use only > > helping memory with constant size* ? This means i am not able to > > create any set and adding elements there. I need to have a constant > > size variables . This is complication a complication for me. > > This isn't to hard - think about what you are really interested in - knowing > if *all* other elements are already counted, or a specific one? You can get > away with only one, to detect the cycle and abort. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list From bdesth.quelquechose at free.quelquepart.fr Thu Jan 8 17:26:19 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 08 Jan 2009 23:26:19 +0100 Subject: Making a decorator a staticmethod In-Reply-To: References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> <49666ddf$0$10251$426a74cc@news.free.fr> Message-ID: <49668b37$0$27584$426a74cc@news.free.fr> Zac Burns a ?crit : > To Bruno's first e-mail: Everything you said was correct but largely > off topic. for a definition of "off topic" equals to "didn't fit your expectations". > I did already understand these things as well. Sorry - but it was not necessarily obvious from your post, and it's near to impossible to guess someone's background on a single post basis. So please don't hold it against me. Anyway, you're not the only people reading this group, and some readers might not have the same knowledge. > To Bruno's second email > quote: > """ > Nope. He's relying on (part of) the interface(s) implemented by the > first argument. The class object itself has nothing to do with is > (well... it does, but only as far as it contribute to the > implementation of the interface expected by the decorator). > """ > > Yes - this is exactly what I was trying to communicate. In addition - > perhaps what I should have made clear all along is that the interface > I'm relying on isn't as much of an interface as it is an > implementation. The attributes that I will be accessing are 'local' > (starting with underscores, let's not get into a discussion about this > - I know they aren't really local) and are subject to change as the > implementation of the class changes. Ok. > The class provides a 'service' for the inherited classes with > differing behaviors for different method via the decorators it > provides. Not sure it's quite clear to me, but I think I get the whole picture. > The details of which I can't get into because it's > proprietary. No problem - the above precisions are enough IMHO. > If this use case is objectionable to you then fine, I've implemented > my own staticdecorator. What I still find questionable is the "necessity" to make your decorators part of the base class. OO is about objects - not classes - and Python's functions _are_ objects (just like modules, classes and everything else FWIW), so even if your decorators are bound to a specific implementation, well, what's the problem ? (BTW, please read until the end of the post before replying). Just document the fact that they only accept instances of your base class, and that's enough - well, IMHO at least !-). Anyway, given Python's highly dynamic nature, being an instance of a given class _at a given moment in time_ doesn't garantee you have this or this _implementation attribute - at best, it makes it highly plausible, but that's all you can expect, really. > (which simply inherits from staticmethod and > implements call). If it makes you feel better - no judgement call on this, I personnaly care a lot about feeling good with my own code, and perfectly understand we don't all have the same feeling about what looks right or wrong -, then go for it. FWIW, I might even agree with your choice if I saw the real code and knew the whole context. My point was just that it was not *technically* necessary to make the decorators part of the base class !-) > But to those who the use case makes sense for it may > be worth thinking about implementing the call method in the main > distribution. Python is a free, opensource software, so feel free to send the patch - who knows, it might even be accepted if don't break anything. But prepare to make your point, the BDFL tends to be very conservative (which is a very GoodThing(tm) IMHO). From lindahl at pbm.com Thu Jan 8 17:32:20 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 14:32:20 -0800 (PST) Subject: ulimit stack size and python threads References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> Message-ID: <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> > How much higher? You could try just under 4GB (unsigned 32-bit) and just > under 2GB (signed 32-bit). I'd like to set it to be about 1/2 the memory size of my server, which happens to end up being 4 gbytes. And no, slightly less than 4 gb doesn't work. But even if that worked, I'd be worried that python is doing something bad with the ulimit -s value under the covers. -- greg From jgardner at jonathangardner.net Thu Jan 8 17:41:56 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 8 Jan 2009 14:41:56 -0800 (PST) Subject: Tree views - Best design practices References: <1be78d220901080653u1dde6e63naecc3831a1d2ce28@mail.gmail.com> <8883d270-e9d5-4ad2-b56d-239cc3724ec6@r10g2000prf.googlegroups.com> <4f1bcb5b-40c8-4910-b073-f3bf24d1e1aa@k1g2000prb.googlegroups.com> Message-ID: <6d9db505-7564-4c96-9f97-2d8d3cd0b677@i20g2000prf.googlegroups.com> On Jan 8, 1:50?pm, "Filip Gruszczy?ski" wrote: > > But I am looking for a different type of flexibility. I would like to > be able to add more classes to my hierarchy and not have to change my > code in many places when I add new class to the hierarchy. If I have > to change every class in the hierarchy because I add new class, then > it's not something I would like to do. And idea how I can avoid this? > I don't understand why you have to change other classes when you add a new class under duck typing. The whole point of duck typing is you don't look at the class or the interface of an object so you don't have to keep track of it. From martin at v.loewis.de Thu Jan 8 18:00:52 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 00:00:52 +0100 Subject: ulimit stack size and python threads In-Reply-To: <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> References: <3aa69a73-7da8-4df3-9dc2-b7c7a70f5f61@s9g2000prg.googlegroups.com> <9a6f60d8-2dbb-4a38-999a-6e8f13f2cb97@i20g2000prf.googlegroups.com> Message-ID: <496685A4.8050105@v.loewis.de> > But even if that worked, I'd be worried that python is doing something > bad with the ulimit -s value under the covers. Again: it definitely isn't. Regards, Martin From andymac at bullseye.apana.org.au Thu Jan 8 18:06:47 2009 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 09 Jan 2009 10:06:47 +1100 Subject: ulimit stack size and python threads In-Reply-To: References: Message-ID: <49668707.6090204@bullseye.andymac.org> Greg Lindahl wrote: > I figure this is a FAQ, but I can't find it in any FAQs. > > I want to limit the stacksize on my server. > > If I set it to 8 megs, or unlimited, python is happy. > > If I set it to 4 gigabytes, things like yum (which is a python > program) crash creating a thread. This is on an x86_64 linux kernel, > RHEL5, etc etc. > > Why is Python overloading the meaning of the ulimit -s like this? > There are plenty of real non-python programs with huge stack usage, > and I'd like my system default stack limit to be less than unlimited > but much larger than Python will allow. The Python interpreter itself (absent a call to resource.setrlimit()) does nothing with resource limits - it just uses the environment it is loaded into. In the absence of effective alternative solutions, it may be possible to achieve the effect you desire by calling resource.setrlimit() in your Python installation's site.py, effectively over-riding the system default. -- ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From lindahl at pbm.com Thu Jan 8 18:27:27 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 15:27:27 -0800 (PST) Subject: ulimit stack size and python threads References: <49667a11$0$22812$9b622d9e@news.freenet.de> Message-ID: <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> > Why do you think Python is overloading the meaning of that? I ensure > you it isn't - it doesn't actively care what the limits are. Always crashing because I asked the OS to please not allow a process to grow too big is what I call overloading the meaning of ulimit -s. It's quite surprising. Not to mention the poor error message. -- greg From james at agentultra.com Thu Jan 8 18:35:41 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 08 Jan 2009 18:35:41 -0500 Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> Message-ID: <85bpuhv0aa.fsf@dozer.localdomain> Kay Schluehr writes: > On 8 Jan., 16:25, J Kenneth King wrote: > >> As another poster mentioned, eventually PyPy will be done and then >> you'll get more of an "in-Python" DSL. > > May I ask why you consider it as important that the interpreter is > written in Python? I don't think it's important for Python to have a meta-circular interpreter (though it can't hurt). > I see no connection between PyPy and syntactical > Python extensions and the latter isn't an objective of PyPy. You can > write Python extensions with virtually any Python aware parser. > M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then > there is ANTLR which provides a Python grammar. I also know about two > other Python aware parsers. One of them was written by myself. Because... there is no connection to see? I never mentioned any such relation. DSL's tend to be a natural side-effect of languages which can manipulate their own expressions without extensive parsing. Creating a new parser that can generate Python AST's is certainly a valid approach (and probably the easiest one). It's not the only one. It depends on your definition of a DSL. My definition isn't satisfied with creating a parser, and so my answers reflect that. From voidwrk at gmail.com Thu Jan 8 19:26:28 2009 From: voidwrk at gmail.com (Sergey Kishchenko) Date: Thu, 8 Jan 2009 16:26:28 -0800 (PST) Subject: Default __nonzero__ impl doesn't throw a TypeError exception References: Message-ID: On 8 ???, 22:03, "Chris Rebert" wrote: > On Thu, Jan 8, 2009 at 5:53 AM, Sergey Kishchenko wrote: > > In Python empty container equals False in 'if' statements: > > > # prints "It's ok" > > if not []: > > ? ?print "It's ok" > > > Let's create a simple Foo class: > > > class Foo: > > ? ?pass > > > Now I can use Foo objects in 'if' statements: > > > #prints "Ouch!" > > f=Foo() > > if f: > > ? ?print "Ouch!" > > > So, default __nonzero__ impl is to return True. I think, this > > behaviour conflicts with 'Explicit is better than implicit' and > > 'Practicality beats purity' statements. I think, throwing a TypeError > > exception would be better. ?It will result in more explicit code with > > fewer errors. > > Python has a rich notion of boolean truth compared to other languages. > In this case, by default, non-None objects are considered True. It's a > reasonable default behavior since wanting to differentiate between > None and non-None objects is such a common task. > Also, I've been programming in Python for a long while and have yet to > encounter any bug due to this behavior. > Regarding the Zen, on the contrary, this is a perfect example of > "Practicality beats purity" in action. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com I agree with you. I completely forget about differentiating between None and non-None objects. I think, thread can be closed. From lindahl at pbm.com Thu Jan 8 19:44:08 2009 From: lindahl at pbm.com (Greg Lindahl) Date: Thu, 8 Jan 2009 16:44:08 -0800 (PST) Subject: ulimit stack size and python threads References: Message-ID: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> I see. I should be blaming the default behavior of pthreads. I did work on a OpenMP library once, and we worked around this problem, plus we gave good error messages. Given the number of HPC sites which use Python, I'd think that Python would have grown similar features. (HPC sites are more likely to have intermediate-sized stack limits due to use of Fortran.) -- greg From ryandw at gmail.com Thu Jan 8 19:47:39 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 16:47:39 -0800 (PST) Subject: BadZipfile "file is not a zip file" Message-ID: The error... >>> file = zipfile.ZipFile('data.zip', "r") Traceback (most recent call last): File "", line 1, in file = zipfile.ZipFile('data.zip', "r") File "C:\Python25\lib\zipfile.py", line 346, in __init__ self._GetContents() File "C:\Python25\lib\zipfile.py", line 366, in _GetContents self._RealGetContents() File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents raise BadZipfile, "File is not a zip file" BadZipfile: File is not a zip file When I look at data.zip in Windows, it appears to be a valid zip file. I am able to uncompress it in Windows XP, and can also uncompress it with 7-Zip. It looks like zipfile is not able to read a "table of contents" in the zip file. That's not a concept I'm familiar with. data.zip is created in this script... decoded = base64.b64decode(datum) f = open('data.zip', 'wb') f.write(decoded) f.close() file = zipfile.ZipFile('data.zip', "r") datum is a base64 encoded zip file. Again, I am able to open data.zip as if it's a valid zip file. Maybe there is something wrong with the approach I've taken to writing the data to data.zip? I'm not sure if it matters, but the zipped data is Unicode. What would cause a zip file to not have a table of contents? Is there some way I can add a table of contents to a zip file using python? Maybe there is some more fundamental problem with the data that is making it seem like there is no table of contents? Thanks in advance for your help. Ryan From google at mrabarnett.plus.com Thu Jan 8 20:02:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 01:02:44 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <4966A234.3070808@mrabarnett.plus.com> webcomm wrote: > The error... > >>>> file = zipfile.ZipFile('data.zip', "r") > Traceback (most recent call last): > File "", line 1, in > file = zipfile.ZipFile('data.zip', "r") > File "C:\Python25\lib\zipfile.py", line 346, in __init__ > self._GetContents() > File "C:\Python25\lib\zipfile.py", line 366, in _GetContents > self._RealGetContents() > File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents > raise BadZipfile, "File is not a zip file" > BadZipfile: File is not a zip file > > When I look at data.zip in Windows, it appears to be a valid zip > file. I am able to uncompress it in Windows XP, and can also > uncompress it with 7-Zip. It looks like zipfile is not able to read a > "table of contents" in the zip file. That's not a concept I'm > familiar with. > > data.zip is created in this script... > > decoded = base64.b64decode(datum) > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > file = zipfile.ZipFile('data.zip', "r") > > datum is a base64 encoded zip file. Again, I am able to open data.zip > as if it's a valid zip file. Maybe there is something wrong with the > approach I've taken to writing the data to data.zip? I'm not sure if > it matters, but the zipped data is Unicode. > > What would cause a zip file to not have a table of contents? Is there > some way I can add a table of contents to a zip file using python? > Maybe there is some more fundamental problem with the data that is > making it seem like there is no table of contents? > You're just creating a file called "data.zip". That doesn't make it a zip file. A zip file has a specific format. If the file doesn't have that format then the zipfile module will complain. From rurpy at yahoo.com Thu Jan 8 20:24:25 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 17:24:25 -0800 (PST) Subject: why cannot assign to function call References: <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> Message-ID: <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Mark Wooding wrote: ... > Python doesn't need another name for assignment, OK. > because actually its > idea of assignment is the same as anyone else's. The difference is in > the way it deals with objects. See argument elsewhere. "the same as anyone else's" only if [Python's] "idea of assignment" does not include producing the same results. a = array (1,2,3) b = a a[1] = 4 print b C, C++, VBA, Fortran, Perl: 1, 2, 3 Python: 1, 4, 3 Telling someone coming to Python from one of those languages that Python's assignment works the same way as those languages is confusing at best. "dealing objects" is part of assignment semantics ISTM. From rurpy at yahoo.com Thu Jan 8 20:27:33 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 17:27:33 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Mark Wooding wrote: ... > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. As a side comment (because it always bugs me when I read this, even though I read it in very authoritative sources), ISTM that C passes everything by value except arrays; they are passed by reference (by passing a pointer to the array by value.) Admittedly, the close relationship between arrays and pointers makes it easy conflate them. From ryandw at gmail.com Thu Jan 8 20:28:17 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 17:28:17 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:02?pm, MRAB wrote: > You're just creating a file called "data.zip". That doesn't make it a > zip file. A zip file has a specific format. If the file doesn't have > that format then the zipfile module will complain. Hmm. When I open it in Windows or with 7-Zip, it contains a text file that has the data I would expect it to have. I guess that alone doesn't necessarily prove it's a zip file? datum is something I'm downloading via a web service. The providers of the service say it's a zip file, and have provided a code sample in C# (which I know nothing about) that shows how to deal with it. In the code sample, the file is base64 decoded and then unzipped. I'm trying to write something in Python to decode and unzip the file. I checked the file for comments and it has none. At least, when I view the properties in Windows, there are no comments. From aahz at pythoncraft.com Thu Jan 8 20:29:50 2009 From: aahz at pythoncraft.com (Aahz) Date: Thu, 8 Jan 2009 17:29:50 -0800 Subject: OSCON 2009: Call For Participation Message-ID: <20090109012950.GA5426@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From googler.1.webmaster at spamgourmet.com Thu Jan 8 20:30:00 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 8 Jan 2009 17:30:00 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report Message-ID: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> Hi! I compiled Python 2.6.1 on a Mac OSX 10.5.5 Intel machine with this configure command and got this message FAILS: ./configure --with-framework-name=Python --with- universal-archs=all --enable-framework --enable- universalsdk=@executable_path/my/path/to/app WORKS: ./configure --with-framework-name=Python --with- universal-archs=all --enable-framework --enable-universalsdk=/ [...] configure: WARNING: dlfcn.h: present but cannot be compiled configure: WARNING: dlfcn.h: check for missing prerequisite headers? configure: WARNING: dlfcn.h: see the Autoconf documentation configure: WARNING: dlfcn.h: section "Present But Cannot Be Compiled" configure: WARNING: dlfcn.h: proceeding with the preprocessor's result configure: WARNING: dlfcn.h: in the future, the compiler will take precedence configure: WARNING: ## ------------------------------------------------ ## configure: WARNING: ## Report this to http://www.python.org/python-bugs ## configure: WARNING: ## ------------------------------------------------ ## checking for dlfcn.h... yes [...] many of this error warnings occure. /* its already noted in the bug reporter but there is no solution. Does anyone know how to use my custom path? Thanks. From prologic at shortcircuit.net.au Thu Jan 8 20:39:50 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 11:39:50 +1000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 11:28 AM, webcomm wrote: > Hmm. When I open it in Windows or with 7-Zip, it contains a text file > that has the data I would expect it to have. I guess that alone > doesn't necessarily prove it's a zip file? > > datum is something I'm downloading via a web service. The providers > of the service say it's a zip file, and have provided a code sample in > C# (which I know nothing about) that shows how to deal with it. In > the code sample, the file is base64 decoded and then unzipped. I'm > trying to write something in Python to decode and unzip the file. Send us a sample of this file in question... cheers James From googler.1.webmaster at spamgourmet.com Thu Jan 8 20:41:56 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 8 Jan 2009 17:41:56 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> Message-ID: <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> Hi searched for "Library/Frameworks/" in the config file and edited it to "@executable_path". Well my configure and make command worked very fine. Just 'make install' aborted after this error message. test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python 2.6" test -d "/Applications/Python 2.6/IDLE.app" && rm -r "/Applications/ Python 2.6/IDLE.app" cp -PR IDLE.app "/Applications/Python 2.6" touch "/Applications/Python 2.6/IDLE.app" cp ./config-main.def "@executable_path/Python.framework/Versions/2.6/ lib/python2.6/idlelib/config-main.def" cp: @executable_path/Python.framework/Versions/2.6/lib/python2.6/ idlelib/config-main.def: No such file or directory make[2]: *** [install] Error 1 make[1]: *** [install_IDLE] Error 2 make: *** [frameworkinstallapps4way] Error 2 That is not cool.. really.. thats not cool. Thanks for your tipps. From ryandw at gmail.com Thu Jan 8 20:44:45 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 17:44:45 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:39?pm, "James Mills" wrote: > Send us a sample of this file in question... It contains data that I can't share publicly. I could ask the providers of the service if they have a dummy file I could use that doesn't contain any real data, but I don't know how responsive they'll be. It's an event registration service called RegOnline. From google at mrabarnett.plus.com Thu Jan 8 20:54:54 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 01:54:54 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <4966AE6E.4070204@mrabarnett.plus.com> webcomm wrote: > On Jan 8, 8:02 pm, MRAB wrote: >> You're just creating a file called "data.zip". That doesn't make it >> a zip file. A zip file has a specific format. If the file doesn't >> have that format then the zipfile module will complain. > > Hmm. When I open it in Windows or with 7-Zip, it contains a text > file that has the data I would expect it to have. I guess that alone > doesn't necessarily prove it's a zip file? > > datum is something I'm downloading via a web service. The providers > of the service say it's a zip file, and have provided a code sample > in C# (which I know nothing about) that shows how to deal with it. > In the code sample, the file is base64 decoded and then unzipped. > I'm trying to write something in Python to decode and unzip the file. > > I checked the file for comments and it has none. At least, when I > view the properties in Windows, there are no comments. > Ah, OK. You didn't explicitly say in your original posting that the decoded data was definitely zipfile data. There was a thread a month ago about gzip Unix commands which could also handle non-gzipped files and I was wondering whether this problem was something like that. Have you tried gzip instead? From ryandw at gmail.com Thu Jan 8 21:56:14 2009 From: ryandw at gmail.com (webcomm) Date: Thu, 8 Jan 2009 18:56:14 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: On Jan 8, 8:54?pm, MRAB wrote: > Have you tried gzip instead? There's no option to download the data in a gzipped format. The files are .zip archives. From musiccomposition at gmail.com Thu Jan 8 21:56:56 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 8 Jan 2009 18:56:56 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> Message-ID: <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> On Jan 8, 4:21?pm, Thorsten Kampe wrote: > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > Since you are, I believe, at least the second person to report being bit > > by this confusion, please open an issue at bugs.python.org and suggest a > > couple of revised sentences that you think are more informative. > > Will do tomorrow. The revised sentence could be in the line of "warn > about Python 3.x incompatibilities that cannot trivially be fixed by > 2to3.py". Actually, don't bother now; I've fixed it up in the trunk. From dfnsonfsduifb at gmx.de Thu Jan 8 22:04:41 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 04:04:41 +0100 Subject: Implementing file reading in C/Python Message-ID: <9fri36xno7.ln2@joeserver.homelan.net> Hello group, I've come from C/C++ and am now trying to code some Python because I absolutely love the language. However I still have trouble getting Python code to run efficiently. Right now I have a easy task: Get a file, split it up into a million chunks, count the most prominent character in each chunk and output that value into a file - in other words: Say we have a 2 GB file, we evaluate what character is most prominent in filepos [0, 2048[ - say it's a "A", then put a 65 in there (ord("A")). I've first tried Python. Please don't beat me, it's slow as hell and probably a horrible solution: #!/usr/bin/python import sys import os f = open(sys.argv[1], "r") filesize = os.stat(sys.argv[1])[6] width = 1024 height = 1024 pixels = width * height blocksize = filesize / width / height print("Filesize : %d" % (filesize)) print("Image size : %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) picture = { } havepixels = 0 while True: data = f.read(blocksize) if len(data) <= 0: break datamap = { } for i in range(len(data)): datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 maxchr = None maxcnt = None for (char, count) in datamap.items(): if (maxcnt is None) or (count > maxcnt): maxcnt = count maxchr = char most = maxchr posx = havepixels % width posy = havepixels / width havepixels += 1 if (havepixels % 1024) == 0: print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / pixels)) picture[(posx, posy)] = most pic = open(sys.argv[1] + ".pgm", "w") pic.write("P2\n") pic.write("# CREATOR: Crappyass Python Script\n") pic.write("%d %d\n" % (width, height)) pic.write("255\n") for y in range(height): for x in range(width): pos = (x, y) most = picture.get(pos, -1) pic.write("%d\n" % (most)) As this was horribly slow (20 Minutes for a 2GB file) I coded the whole thing in C also: #include #include #include #include #define BLOCKSIZE 2048 int main(int argc, char **argv) { unsigned int count[256]; int width, height; FILE *f; FILE *in; width = 1024; height = 1024; char temp[2048]; if (argc != 2) { fprintf(stderr, "Argument?\n"); exit(2); } in = fopen(argv[1], "r"); if (!in) { perror("fopen"); exit(1); } snprintf(temp, 255, "%s.pgm", argv[1]); f = fopen(temp, "w"); if (!f) { perror("fopen"); exit(1); } fprintf(f, "P2\n"); fprintf(f, "# CREATOR: C\n"); fprintf(f, "%d %d\n", width, height); fprintf(f, "255\n"); width = 1024; height = 1024; while (fread(temp, 1, sizeof(temp), in) == sizeof(temp)) { int i; memset(count, 0, sizeof(count)); for (i = 0; i < sizeof(temp); i++) { count[(int)temp[i]]++; } int greatest; int maxcount; greatest = 0; maxcount = count[0]; for (i = 1; i < 256; i++) { if (count[i] > maxcount) { maxcount = count[i]; greatest = i; } } fprintf(f, "%d\n", greatest); } fclose(f); fclose(in); return 0; } Which takes about 40 seconds. I want the niceness of Python but a little more speed than I'm getting (I'd settle for factor 2 or 3 slower, but factor 30 is just too much). Can anyone point out how to solve this efficiently in Python? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From google at mrabarnett.plus.com Thu Jan 8 22:05:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 03:05:19 +0000 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <4966BEEF.5040007@mrabarnett.plus.com> Johannes Bauer wrote: > Hello group, > > I've come from C/C++ and am now trying to code some Python because I > absolutely love the language. However I still have trouble getting > Python code to run efficiently. Right now I have a easy task: Get a > file, split it up into a million chunks, count the most prominent > character in each chunk and output that value into a file - in other > words: Say we have a 2 GB file, we evaluate what character is most > prominent in filepos [0, 2048[ - say it's a "A", then put a 65 in there > (ord("A")). > > I've first tried Python. Please don't beat me, it's slow as hell and > probably a horrible solution: > > #!/usr/bin/python > import sys > import os > > f = open(sys.argv[1], "r") > filesize = os.stat(sys.argv[1])[6] > > width = 1024 > height = 1024 > pixels = width * height > blocksize = filesize / width / height > > print("Filesize : %d" % (filesize)) > print("Image size : %dx%d" % (width, height)) > print("Bytes per Pixel: %d" % (blocksize)) > > picture = { } > havepixels = 0 > while True: > data = f.read(blocksize) > if len(data) <= 0: break > > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 > > maxchr = None > maxcnt = None > for (char, count) in datamap.items(): > if (maxcnt is None) or (count > maxcnt): > maxcnt = count > maxchr = char > > most = maxchr > > posx = havepixels % width > posy = havepixels / width > > havepixels += 1 > if (havepixels % 1024) == 0: > print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / pixels)) > > picture[(posx, posy)] = most > > pic = open(sys.argv[1] + ".pgm", "w") > pic.write("P2\n") > pic.write("# CREATOR: Crappyass Python Script\n") > pic.write("%d %d\n" % (width, height)) > pic.write("255\n") > for y in range(height): > for x in range(width): > pos = (x, y) > most = picture.get(pos, -1) > pic.write("%d\n" % (most)) > > As this was horribly slow (20 Minutes for a 2GB file) I coded the whole > thing in C also: > > #include > #include > #include > #include > > #define BLOCKSIZE 2048 > > int main(int argc, char **argv) { > unsigned int count[256]; > int width, height; > FILE *f; > FILE *in; > width = 1024; > height = 1024; > char temp[2048]; > > if (argc != 2) { fprintf(stderr, "Argument?\n"); exit(2); } > > in = fopen(argv[1], "r"); > if (!in) { perror("fopen"); exit(1); } > > snprintf(temp, 255, "%s.pgm", argv[1]); > f = fopen(temp, "w"); > if (!f) { perror("fopen"); exit(1); } > > fprintf(f, "P2\n"); > fprintf(f, "# CREATOR: C\n"); > fprintf(f, "%d %d\n", width, height); > fprintf(f, "255\n"); > > width = 1024; > height = 1024; > while (fread(temp, 1, sizeof(temp), in) == sizeof(temp)) { > int i; > memset(count, 0, sizeof(count)); > for (i = 0; i < sizeof(temp); i++) { > count[(int)temp[i]]++; > } > > int greatest; > int maxcount; > > greatest = 0; > maxcount = count[0]; > for (i = 1; i < 256; i++) { > if (count[i] > maxcount) { > maxcount = count[i]; > greatest = i; > } > } > > fprintf(f, "%d\n", greatest); > } > > fclose(f); > fclose(in); > return 0; > } > > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). > > Can anyone point out how to solve this efficiently in Python? > Have a look at psyco: http://psyco.sourceforge.net/ From prologic at shortcircuit.net.au Thu Jan 8 23:16:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 14:16:05 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 1:04 PM, Johannes Bauer wrote: > Hello group, Hello. (...) > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). > > Can anyone point out how to solve this efficiently in Python? Johannes, your 2 programs, 1 in Python and the other in C do _not_ produce the same result. I have tested this against a randomly generated file from /dev/urandom (10M). Yes the Python one is much slower, but I believe it's bebcause the Python implementation is _correct_ where teh C one is _wrong_ :) The resulting test.bin.pgm from python is exactly 3.5M (from 10M). The resulting test.bin.pgm from the C version is 16K. Something is not quite right here :) cheers James From joe at strout.net Thu Jan 8 23:22:17 2009 From: joe at strout.net (Joe Strout) Date: Thu, 08 Jan 2009 21:22:17 -0700 Subject: why cannot assign to function call In-Reply-To: <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> References: <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Message-ID: <4966D0F9.8070100@strout.net> rurpy at yahoo.com wrote: > "the same as anyone else's" only if [Python's] "idea > of assignment" does not include producing the same > results. > > a = array (1,2,3) > b = a > a[1] = 4 > print b > > C, C++, VBA, Fortran, Perl: 1, 2, 3 > Python: 1, 4, 3 You are mistaken (except perhaps in the Fortran case, which is an oddball by modern standards, and I don't know Perl well enough to judge). C/C++ code: int* a = malloc(3); a[0] = 1; a[1] = 2; a[2] = 3; int* b = a; a[1] = 4; print_array(b) ---> Result: 1, 4, 3 REALbasic code: Dim a() As Integer = Array(1,2,3) Dim b() As Integer = a a(1) = 4 PrintArray b --> Result: 1, 4, 3 VB.NET code would be very similar in syntax, and identical in behavior, to the REALbasic code. Java would also have the same semantics, though my Java is too rusty to get the syntax right without actually trying it. If you can find a language where an array variable is NOT a reference (and thus does not behave exactly as in Python, Java, REALbasic, C++, etc.), then that language is either a dinosaur or some weird academic oddity. Best, - Joe From prologic at shortcircuit.net.au Thu Jan 8 23:29:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 14:29:46 +1000 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 3:13 PM, Johannes Bauer wrote: > Uhh, yes, you're right there... I must admit that I was too lazy to > include all the stat headers and to a proper st_size check in the C > version (just a quick hack), so it's practically hardcoded. > > With files of exactly 2GB in size the results should be the same (more > or less, +- 1 line doesn't matter really), because 2 GB / 2048 (the > buffer) = 1 Million. > > Sorry I didn't mention that, it was really kind of sloppy, > quick-and-dirty C writing on my part. But you're right, the Python > implementation does what is actually supposed to happen. I shall attempt to optimize this :) I have a funny feeling you might be caught up with some features of Python - one notable one being that some things in Python are immutable. psyco might help here though ... cheers James From pavlovevidence at gmail.com Thu Jan 8 23:40:37 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jan 2009 20:40:37 -0800 (PST) Subject: Making a decorator a staticmethod References: <333edbe80901081054j1df61633k17c4a64f98e3ecdc@mail.gmail.com> <01194462-0470-4c68-b822-1bbb041dc41b@a26g2000prf.googlegroups.com> Message-ID: <77aa3b25-581b-4207-a758-12b4387e471f@z28g2000prd.googlegroups.com> On Jan 8, 1:57?pm, Jonathan Gardner wrote: > (Aside: I really can't think of any reason to use staticmethods in > Python other than to organize functions into namespaces, and even > then, that's what modules are for, right?) In a certain widget toolkit (which I won't mention by name but it begins with G, ends with K, and the middle rhymes with "be") sometimes when subclassing a widget and setting up methods of the class to be event handlers, you want to use staticmethods, because the toolkit passes the widget as the first argument. Since this is a subclass of the widget, the first argument ends up being the object itself, so we end up with odd-looking definitions like this: @staticmethod def on_mouse_button_down(self,event): If it wasn't for staticmethods, you'd have to define it like this: def on_mouse_button_down(self,widget,event): widget and self would always be the same object, and that's just a waste. Carl Banks From narkewoody at gmail.com Thu Jan 8 23:57:44 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 12:57:44 +0800 Subject: Best practice in organize classes into modules Message-ID: Hi, In C++/Java, people usually put one class into one file. What's the suggestion on this topic in Python? I so much interesting this especially when exception classes also involved. Thanks. - narke From prologic at shortcircuit.net.au Fri Jan 9 00:02:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 15:02:51 +1000 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: > In C++/Java, people usually put one class into one file. What's the > suggestion on this topic in Python? I so much interesting this > especially when exception classes also involved. Normally i group related functionality into the one module. I do try to keep my std dev. as low as I can though if that makes any sense. cheers James From akineko at gmail.com Fri Jan 9 00:04:58 2009 From: akineko at gmail.com (akineko) Date: Thu, 8 Jan 2009 21:04:58 -0800 (PST) Subject: multiprocessing and SIGINT References: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> Message-ID: <493e1114-84c4-47df-be80-e93ed4fcbfce@a12g2000pro.googlegroups.com> It is a bit awkward to respond to my posting but I have some updates. I created two simple test programs, one uses threading and another uses multiprocessing. What I found was: (1) test program with threading Only main thread receives SIGINT (generated thread won't receive SIGINT) (2) test program with multiprocessing Both processes receives SIGINT. OS apparently distributes the SIGINT event to processes associated with the terminal. (3) signal handler I realized that I could assign a signal handler specific to a process by placing it to a worker method. def worker(): # this process ignores SIGINT signal.signal(signal.SIGINT, signal.SIG_IGN) ... the rest ... def main(): process = multiprocessing.Process(target=worker) process.start() (4) terminating the spawned process I needed to send a shutdown message to the process via a communication between two processes. You can use Process.terminate() to brutally kill the process but that is a last resort. Now my program can shutdown elegantly when I type Ctrl-C. I see a big potential in multiprocessing as more PCs now have multi- Core CPU. Aki- From narkewoody at gmail.com Fri Jan 9 00:09:06 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 13:09:06 +0800 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 1:02 PM, James Mills wrote: > On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >> In C++/Java, people usually put one class into one file. What's the >> suggestion on this topic in Python? I so much interesting this >> especially when exception classes also involved. > > Normally i group related functionality into the one module. Will that lead to too large source file size? Is there a recommendation on max lines of a python source? Thanks. > I do try to keep my std dev. as low as I can though > if that makes any sense. > > cheers > James > From dfnsonfsduifb at gmx.de Fri Jan 9 00:13:26 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 06:13:26 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: James Mills schrieb: > I have tested this against a randomly generated > file from /dev/urandom (10M). Yes the Python > one is much slower, but I believe it's bebcause > the Python implementation is _correct_ where > teh C one is _wrong_ :) > > The resulting test.bin.pgm from python is exactly > 3.5M (from 10M). The resulting test.bin.pgm from > the C version is 16K. > > Something is not quite right here :) Uhh, yes, you're right there... I must admit that I was too lazy to include all the stat headers and to a proper st_size check in the C version (just a quick hack), so it's practically hardcoded. With files of exactly 2GB in size the results should be the same (more or less, +- 1 line doesn't matter really), because 2 GB / 2048 (the buffer) = 1 Million. Sorry I didn't mention that, it was really kind of sloppy, quick-and-dirty C writing on my part. But you're right, the Python implementation does what is actually supposed to happen. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From clp2 at rebertia.com Fri Jan 9 00:22:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jan 2009 21:22:03 -0800 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: > On Fri, Jan 9, 2009 at 1:02 PM, James Mills > wrote: >> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>> In C++/Java, people usually put one class into one file. What's the >>> suggestion on this topic in Python? I so much interesting this >>> especially when exception classes also involved. >> >> Normally i group related functionality into the one module. > > Will that lead to too large source file size? Is there a > recommendation on max lines of a python source? Thanks. I don't think there's really a hard-and-fast rule (just like in Java & C++!). When the program starts to feel unwieldly, then start splitting it into multiple modules. Python files can generally contain several classes and functions and still be quite manageable. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Fri Jan 9 00:35:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 8 Jan 2009 21:35:19 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> Message-ID: <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> On Jan 9, 1:56?pm, Benjamin wrote: > On Jan 8, 4:21?pm, Thorsten Kampe wrote: > > > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > > Since you are, I believe, at least the second person to report being bit > > > by this confusion, please open an issue at bugs.python.org and suggest a > > > couple of revised sentences that you think are more informative. > > > Will do tomorrow. The revised sentence could be in the line of "warn > > about Python 3.x incompatibilities that cannot trivially be fixed by > > 2to3.py". > > Actually, don't bother now; I've fixed it up in the trunk. Would you mind giving a pointer to where or what your fix is? The reason for asking is that Thorsten's suggestion is ambiguous: warn about some? all? 3.x problems that can't be trivially fixed by 2to3? Can't be "all"; there are in fact a number of problems that can't be trivially fixed by 2to3 and can't be detected by running 2.6 with the -3 option. These include (a) problems that cause a reasonably informative exception in 3.x right at the point where the problem exists (b) problems where the behaviour has changed but no exception is raised, and your code lurches off down the wrong path, and you need to work backwards from subsequent exception(s) and/or failing test case (s) to pin-point the problem. I'll use string constants to provide an example of each type. When faced with "abcd", 2to3 has no way of telling whether that should be str ("abcd") or bytes (b"abcd"). In the vast majority of cases, to guess it should be str is correct, so there is no change to the source file, and a warning would almostly always be noise. Example of problem (a): chunks is a list of slices of bytes read from a binary file. In 2.x you write glued = ''.join(chunks) In 3.0 you get this: >>> chunks = [b'x', b'y'] >>> ''.join(chunks) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 0: expected str instance, bytes found Example of problem (b): some_bytes has been read from a file that was opened in 'rb' mode and contains the 4 ASCII bytes 'abcd' # 2.x simulation >> some_bytes == "abcd" True # 3.0 simulation >>> type(some_bytes) >>> type("abcd") >>> some_bytes == "abcd" False # because the types are not comparable for equality. Another type (b) example is the (majority-guessed) 2to3 change from [c] StringIO.StringIO to io.StringIO ... if you really should feed some library an io.BytesIO instance instead, it can travel quite a distance before blowing up. Perhaps some of this info could be put into http://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 ... or maybe a separate HOWTO or wiki chapter could be set up for porting to 3.x, including topics like: (1) maintaining one set of source files (when you are maintaining a package that must run on e.g. 2.1 through 3.x) (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x support-range issue but would like to have the one set of source looking like 3.x code instead of the ugliness of version-conditional stuff like BYTES_NULL = bytes(0) # 3.x or BYTES_NULL = '' # 2.x and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? Cheers, John From rurpy at yahoo.com Fri Jan 9 00:56:05 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 8 Jan 2009 21:56:05 -0800 (PST) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> Message-ID: <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >> "the same as anyone else's" only if [Python's] "idea >> of assignment" does not include producing the same >> results. >> >> a = array (1,2,3) >> b = a >> a[1] = 4 >> print b >> >> C, C++, VBA, Fortran, Perl: 1, 2, 3 >> Python: 1, 4, 3 > > You are mistaken I don't think so. See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 The code I quoted there was tested. In the C/C++ case, array-to-pointer coercion confuses the issue so I embedded the array in a struct which is more like an "object". The assignment semantics are copy-like producing the results I quoted. (Keep in mind my point was not to show the behavior of arrays, but to show that several common languages *do not* use Python's "*all* names are references" model -- though of course this does not preclude their having some Python-like assignments since they all have some way of doing references.) It seems plausible to me that experience with copy-like assignments semantics in other languages accounts for the frequent misunderstanding of Python assignments that is seen on this list. > (except perhaps in the Fortran case, which is an > oddball by modern standards, and I don't know Perl well enough to judge). Whether or not Perl is oddball or modern is irrelevant; it is still widely used and it is reasonable to assume that there are a significant number of people coming to Python with a lot of previous experience with Perl. Even Fortran is still used in scientific computing circles (or so I'm told) although I can't say I have seen any c.l.p. postings from people claiming Python doesn't work like fortran. :-) > C/C++ code: > > int* a = malloc(3); > a[0] = 1; > a[1] = 2; > a[2] = 3; > int* b = a; > a[1] = 4; > print_array(b) > ---> Result: 1, 4, 3 > > REALbasic code: > > Dim a() As Integer = Array(1,2,3) > Dim b() As Integer = a > a(1) = 4 > PrintArray b > --> Result: 1, 4, 3 > > VB.NET code would be very similar in syntax, and identical in behavior, > to the REALbasic code. Don't know about RealBasic or VB.Net, my experience and quoted results were from MS Visual Basic for Apps which is (I think) based on VB6. From nl.srinivas at gmail.com Fri Jan 9 00:58:27 2009 From: nl.srinivas at gmail.com (Srinivasa NL) Date: Fri, 9 Jan 2009 11:28:27 +0530 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: <8b85ec440901082158g6f1a277ao4f85284323a74914@mail.gmail.com> You can use subprocess module to start an application and also read it's output. You can kill it yourself (when you know when to do it) Srinivas. On Fri, Jan 9, 2009 at 2:36 AM, Tim Arnold wrote: > Hi, I don't even know what to google for on this one. I need to drive a > commercial desktop app (on windows xp) since the app doesn't have a batch > interface. It's intended to analyze one file at a time and display a > report. > > I can get the thing to write out the report an html browser, but I have > thousands of files I need it to analyze every night. > > Is there any lib or recipe(s) for doing something like this via python? > > thanks, > --Tim Arnold > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Fri Jan 9 01:31:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 16:31:49 +1000 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Fri, Jan 9, 2009 at 2:29 PM, James Mills wrote: > I shall attempt to optimize this :) > I have a funny feeling you might be caught up with > some features of Python - one notable one being that > some things in Python are immutable. > > psyco might help here though ... What does this little tool do anyway ? It's very interesting the images it creates out of files. What is this called ? I'm curious :) I haven't had much tiem to optimize it yet - I'll try to when I get home from work. cheers James From steve at holdenweb.com Fri Jan 9 01:49:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 01:49:30 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <4966BEEF.5040007@mrabarnett.plus.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <4966BEEF.5040007@mrabarnett.plus.com> Message-ID: MRAB wrote: > Johannes Bauer wrote: >> Hello group, [and about 200 other lines there was no need to quote] [...] > Have a look at psyco: http://psyco.sourceforge.net/ Have a little consideration for others when making a short reply to a long post, please. Trim what isn't necessary. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 9 01:52:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 01:52:44 -0500 Subject: Best practice in organize classes into modules In-Reply-To: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> References: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: >> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >> wrote: >>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>>> In C++/Java, people usually put one class into one file. What's the >>>> suggestion on this topic in Python? I so much interesting this >>>> especially when exception classes also involved. >>> Normally i group related functionality into the one module. >> Will that lead to too large source file size? Is there a >> recommendation on max lines of a python source? Thanks. > > I don't think there's really a hard-and-fast rule (just like in Java & > C++!). When the program starts to feel unwieldly, then start splitting > it into multiple modules. Python files can generally contain several > classes and functions and still be quite manageable. > The OP can take a look at the standard library to get some impression of what's been considered acceptable over the years. Just remember that some of the code is a little antiquated, as working code is not rewritten just for the fun of fixing the bugs this would inject. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From narkewoody at gmail.com Fri Jan 9 02:10:17 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:10:17 +0800 Subject: Best practice in organize classes into modules In-Reply-To: References: <50697b2c0901082122g25e84740m30e99ef9c3bb51d4@mail.gmail.com> Message-ID: On Fri, Jan 9, 2009 at 2:52 PM, Steve Holden wrote: > Chris Rebert wrote: >> On Thu, Jan 8, 2009 at 9:09 PM, Steven Woody wrote: >>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >>> wrote: >>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>>>> In C++/Java, people usually put one class into one file. What's the >>>>> suggestion on this topic in Python? I so much interesting this >>>>> especially when exception classes also involved. >>>> Normally i group related functionality into the one module. >>> Will that lead to too large source file size? Is there a >>> recommendation on max lines of a python source? Thanks. >> >> I don't think there's really a hard-and-fast rule (just like in Java & >> C++!). When the program starts to feel unwieldly, then start splitting >> it into multiple modules. Python files can generally contain several >> classes and functions and still be quite manageable. >> > The OP can take a look at the standard library to get some impression of > what's been considered acceptable over the years. Just remember that > some of the code is a little antiquated, as working code is not > rewritten just for the fun of fixing the bugs this would inject. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for all your inputs! From narkewoody at gmail.com Fri Jan 9 02:15:28 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:15:28 +0800 Subject: threading in PyQt vs threading in standard library Message-ID: Hi, I am considering using PyQt for GUI programs, and I notices that both of them include threading supports, so which one should I pick up? Similar also applies 'socket'. Thanks. From phil at riverbankcomputing.com Fri Jan 9 02:32:34 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Fri, 09 Jan 2009 07:32:34 +0000 Subject: threading in PyQt vs threading in standard library In-Reply-To: References: Message-ID: On Fri, 9 Jan 2009 15:15:28 +0800, "Steven Woody" wrote: > Hi, > > I am considering using PyQt for GUI programs, and I notices that both > of them include threading supports, so which one should I pick up? > Similar also applies 'socket'. I'd recommend using the PyQt versions of both. A significant advantage of PyQt's sockets is that they are integrated with the event loop. This means you don't need threads to handle networking. Phil From narkewoody at gmail.com Fri Jan 9 02:48:17 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 15:48:17 +0800 Subject: threading in PyQt vs threading in standard library In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 3:32 PM, Phil Thompson wrote: > On Fri, 9 Jan 2009 15:15:28 +0800, "Steven Woody" > wrote: >> Hi, >> >> I am considering using PyQt for GUI programs, and I notices that both >> of them include threading supports, so which one should I pick up? >> Similar also applies 'socket'. > > I'd recommend using the PyQt versions of both. > > A significant advantage of PyQt's sockets is that they are integrated with > the event loop. This means you don't need threads to handle networking. > Thank you. From a.bilgin.a at gmail.com Fri Jan 9 02:49:39 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Fri, 9 Jan 2009 09:49:39 +0200 Subject: Python Imaging Library and textmate Message-ID: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> Hello, I am a beginner in python and I am trying to create image files that contain lines from a text file. I am trying to do this with PIL, which seems like a suitable tool. I have a copy of TextMate(1.5.8) and I run Macosx 10.5.6 The problem is, even though I installed PIL correctly (I get no errors from "import Image" in IDLE or in terminal), I can't get TextMate to import the module. I keep getting "ImportError: No module named Image" error. I tried reloading TextMate's bundles but that did not work either. I used this set of instructions to install PIL http://www.p16blog.com/p16/2008/05/appengine-installing-pil-on-os-x-1053.html I think there is something wrong with symbolic links, although I am also a novice to UNIX based systems so I do not know for sure what to do about it. There was a similar thread in this list with textmate but I can't understand how that issue was solved in the end. Thanks Ali -------------- next part -------------- An HTML attachment was scrubbed... URL: From kay.schluehr at gmx.net Fri Jan 9 02:54:56 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 8 Jan 2009 23:54:56 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <651f07ee-ca8f-4bed-b76c-84c2722dbde1@b38g2000prf.googlegroups.com> <1642fe0d-c7e5-41ca-9b7b-753d96646ebc@i18g2000prf.googlegroups.com> Message-ID: O.K. Mark. Since you seem to accept the basic requirement to build an *external* DSL I can provide some help. I'm the author of EasyExtend ( EE ) which is a system to build external DSLs for Python. http://www.fiber-space.de/EasyExtend/doc/EE.html EE is very much work in progress and in the last year I was more engaged with increasing power than enhance accessibility for beginners. So be warned. A DSL in EE is called a *langlet*. Download the EE package and import it in a Python shell. A langlet can then be built this way: >>> import EasyExtend >>> EasyExtend.new_langlet("my_langlet", prompt = "myl> ", source_ext = ".dsl") This creates a bunch of files in a directory /EasyExtend/langlets/my_langlet Among them is run_my_langet.py and langlet.py. You can cd to the directory and apply $python run_my_langlet.py which opens a console with prompt 'myl>'. Each langlet is immediatly interactive. A user can also run a langlet specific module like $python run_my_langlet.py mod.dsl with the suffix .dsl defined in the langlet builder function. Each module xxx.dsl can be imported from other modules of the my_langlet langlet. EE provides a generic import hook for user defined suffixes. In order to do anything meaningful one has to implement langlet transformations in the langlet.py module. The main transformations are defined in a class called LangletTransformer. It defines a set of visitor methods that are marked by a decorator called @trans. Each @trans method is named like a terminal/non-terminal in a grammar file and responds to a terminal or non-terminal node of the parse tree which is traversed. The structure of the parse tree is the same as those you'd get from Pythons builtin parser. It is entirely determined by 4 files: - Grammar which is precisely the Python grammar found in the Python source distribution. - Grammar.ext which defines new non-terminals and overwrites old ones. - Token which defines Pythons token. - Token.ext which is the analog of Grammar.ext for token definitions. The Grammar.ext file is in the directory my_langlet/parsedef. There is also an analog lexdef directory for Token.ext. A possible Grammar.ext extension of the Python grammar that overwrites two non-terminals of looks like this: Grammar.ext ----------- trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | NAME | NUMBER | STRING atom: ('(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING) ----------- Once this has been defined you can start a new my_langlet session and type myl> navigate_to 'www.openstreetmap.org' website Traceback (most recent call last): File "C:\lang\Python25\lib\site-packages\EasyExtend\eeconsole.py", line 270, in compile_cst _code = compile(src,"","single", COMPILER_FLAGS) File "", line 1 navigate_to 'www.openstreetmap.org' website ^ SyntaxError: invalid syntax myl> It will raise a SyntaxError but notice that this error stems from the *compiler*, not the parser. The parser perfectly accepts the modified non-terminals and produces a parse tree. This parse tree has to be transformed into a valid Python parse tree that can be accepted by Pythons bytecode compiler. I'm not going into detail here but recommend to read the tutorial http://www.fiber-space.de/EasyExtend/doc/tutorial/EETutorial.html that walks through a complete example that defines a few terminals, non-terminals and the transformations accordingly. It also shows how to use command line options to display parse tree properties, unparse parse trees back into source code ( you can eliminate DSL code from the code base entirely and replace it by equivalent Python code ), do some validation on transformed parse trees etc. From martin at v.loewis.de Fri Jan 9 03:16:16 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:16:16 +0100 Subject: ulimit stack size and python threads In-Reply-To: <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> References: <49667a11$0$22812$9b622d9e@news.freenet.de> <81579974-792a-4628-bfea-efefc956751c@r10g2000prf.googlegroups.com> Message-ID: <496707D0.9050502@v.loewis.de> > Always crashing because I asked the OS to please not allow a process > to grow too big is what I call overloading the meaning of ulimit -s. Please trust that there is no explicit code in the Python interpreter that tests whether the stack size is 4GB, and then produces an explicit crash. > It's quite surprising. Not to mention the poor error message. AFAICT, you didn't even *report* yet what the error message is, so I don't know whether it is poor. Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 03:16:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 08:16:17 GMT Subject: BadZipfile "file is not a zip file" References: Message-ID: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > The error... ... > BadZipfile: File is not a zip file > > When I look at data.zip in Windows, it appears to be a valid zip file. > I am able to uncompress it in Windows XP, and can also uncompress it > with 7-Zip. It looks like zipfile is not able to read a "table of > contents" in the zip file. That's not a concept I'm familiar with. No, ZipFile can read table of contents: Help on method printdir in module zipfile: printdir(self) unbound zipfile.ZipFile method Print a table of contents for the zip file. In my experience, zip files originating from Windows sometimes have garbage at the end of the file. WinZip just ignores the garbage, but other tools sometimes don't -- if I recall correctly, Linux unzip successfully unzips the file but then complains that the file was corrupt. It's possible that you're running into a similar problem. > data.zip is created in this script... > > decoded = base64.b64decode(datum) > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > file = zipfile.ZipFile('data.zip', "r") > > datum is a base64 encoded zip file. Again, I am able to open data.zip > as if it's a valid zip file. Maybe there is something wrong with the > approach I've taken to writing the data to data.zip? I'm not sure if it > matters, but the zipped data is Unicode. The full signature of ZipFile is: ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and see if that makes any difference. The zip format does support alternative compression methods, it's possible that this particular file uses a different sort of compression which Python doesn't deal with. > What would cause a zip file to not have a table of contents? What makes you think it doesn't have one? -- Steven From martin at v.loewis.de Fri Jan 9 03:18:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:18:01 +0100 Subject: ulimit stack size and python threads In-Reply-To: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> References: <82e89196-4b29-403a-8c49-d0119cb6c2ee@w1g2000prk.googlegroups.com> Message-ID: <49670839$0$25219$9b622d9e@news.freenet.de> > I see. I should be blaming the default behavior of pthreads. You shouldn't blame anybody. Instead, you should sit down and study the problem in detail, until you fully understand it. Then you should start contributing fixes. Never ever should you spread blame. Regards, Martin From koranthala at gmail.com Fri Jan 9 03:21:09 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 9 Jan 2009 00:21:09 -0800 (PST) Subject: Encrypted Logging in python Message-ID: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> I was wondering if there is a mechanism to encrypt logging automatically in python. The issue is as follows: (a) An application (after py2exe) will go as executable and there is no need for the user to know that it is written in python. If an exception occurs and it is logged, then the user can understand it is written in python. (b) A security threat. If an exception occurs, the code is seen by the user - and possibly be misused. Base64 encoding somewhat helps - which is supported by logging module - but even that is not very secure. If there can be an option - wherein we send in the password and the logging is encrypted - it might be better. I would have loved to provide the code, but I am completely tied up at the moment and wont be able to help for another month. From martin at v.loewis.de Fri Jan 9 03:30:17 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 09 Jan 2009 09:30:17 +0100 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: Message-ID: <49670B19.4090504@v.loewis.de> > What would cause a zip file to not have a table of contents? AFAICT, _EndRecData is failing to find the "end of zipfile" structure in the file. You might want debug through it to see where it looks, and how it decides that this structure is not present in the file. Towards 22 bytes before the end of the file, the bytes PK\005\006 should appear. If they don't appear, you don't have a zipfile. If they appear, but elsewhere towards the end of the file, there might be a bug in the zip file module (or, more likely, the zip file uses an optional zip feature which the module doesn't implement). Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 03:32:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 08:32:23 GMT Subject: Replying to list messages References: <87priyh85x.fsf@benfinney.id.au> <87hc4agz1f.fsf_-_@benfinney.id.au> <878wpmguop.fsf@benfinney.id.au> Message-ID: <01770252$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 10:42:13 -0800, Paul McNett wrote: > Ben Finney wrote: >> Paul McNett

writes: >>> But arguing about this here isn't going to change anything: opinions >>> differ just like tabs/spaces and bottom-post/top-post. >> >> In cases like this, one side can simply be wrong :-) >> >> Best of luck getting your programs behaving as you want them to! > > BTW, I agree with you that in an ideal, pure world mailing lists > wouldn't munge the reply-to field, but when 80% of the people use email > clients that don't support reply-list, the practical thing to do as a > list admin that wants to avoid having to explain over and over again > that "your client software is broken" is to simply swallow some pride > and munge the reply-to. Now, 99% of the users are happy, and the > remaining 1% are elite enough to understand how to get around any > problems this caused. The only problem this leads to is people who hit send without checking where they are sending to are likely to be embarrassed when they send personal posts to the entire mailing list. As far as I'm concerned, hitting send without looking to see who you are sending to is akin to turning into a busy road without looking to see if there are any cars coming: any accident that happens is YOUR fault, not the fault of the road, car, mail client or mailing list. It boggles my brain that [insert sweeping generalisation here] the people who are most vehement about blaming the mailing list software are usually also the least understanding when (l)users click "OK" to dialogs without reading what the dialog says first. -- Steven From pavlovevidence at gmail.com Fri Jan 9 03:46:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 00:46:27 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 2:16?am, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > The error... > ... > > BadZipfile: File is not a zip file > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > I am able to uncompress it in Windows XP, and can also uncompress it > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > contents" in the zip file. ?That's not a concept I'm familiar with. > > No, ZipFile can read table of contents: > > ? ? Help on method printdir in module zipfile: > > ? ? printdir(self) unbound zipfile.ZipFile method > ? ? ? ? Print a table of contents for the zip file. > > In my experience, zip files originating from Windows sometimes have > garbage at the end of the file. WinZip just ignores the garbage, but > other tools sometimes don't -- if I recall correctly, Linux unzip > successfully unzips the file but then complains that the file was > corrupt. It's possible that you're running into a similar problem. The zipfile format is kind of brain dead, you can't tell where the end of the file is supposed to be by looking at the header. If the end of file hasn't yet been reached there could be more data. To make matters worse, somehow zip files came to have text comments simply appended to the end of them. (Probably this was for the benefit of people who would cat them to the terminal.) Anyway, if you see something that doesn't adhere to the zipfile format, you don't have any foolproof way to know if it's because the file is corrupted or if it's just an appended comment. Most zipfile readers use a heuristic to distinguish. Python's zipfile module just assumes it's corrupted. The following post from a while back gives a solution that tries to snip the comment off so that zipfile module can handle it. It might help you out. http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 Carl Banks From jstroud at mbi.ucla.edu Fri Jan 9 03:50:24 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 09 Jan 2009 00:50:24 -0800 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: Tim Arnold wrote: > Hi, I don't even know what to google for on this one. I need to drive a > commercial desktop app (on windows xp) since the app doesn't have a batch > interface. It's intended to analyze one file at a time and display a > report. > > I can get the thing to write out the report an html browser, but I have > thousands of files I need it to analyze every night. > > Is there any lib or recipe(s) for doing something like this via python? You are a little thin on details here. My only advice at this point is to check out os.system, which is the simplest option. From there you can move to the popen2 module for greater control, but if you are talking about a gui app, you may run into hang-ups. A quick recipe would be the following pretend application that recursively descends from the current directory calling the utility named "dosapp" on every file it finds that ends with "jpg" (what "dosapp" does is left to your imagination): import os def doit(suffix, adir, filenames): for afile in filenames: if afile.endswith(suffix): pathname = os.path.join(adir, afile) os.system('dosapp %s' % pathname) top = '.' suffix = '.jpg' os.path.walk(top, doit, suffix) Read the docs on os.path.walk, of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 03:54:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 09:54:44 +0100 Subject: Best practice in organize classes into modules In-Reply-To: References: Message-ID: <496710ba$0$27487$426a74cc@news.free.fr> Steven Woody a ?crit : > On Fri, Jan 9, 2009 at 1:02 PM, James Mills > wrote: >> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody wrote: >>> In C++/Java, people usually put one class into one file. What's the >>> suggestion on this topic in Python? I so much interesting this >>> especially when exception classes also involved. >> Normally i group related functionality into the one module. > > Will that lead to too large source file size? When the case happens, then you can safely refactor the module into a package with submodules, and use the package's __init__.py to make it a facade for the submodules so the refactoring is transparent for client code. But given Python's expressivity and metaprogramming features, it's usually easy to avoid cruft and boilerplate and keep the code short. > Is there a > recommendation on max lines of a python source? Not really - use your own judgement, mostly. As far as I'm concerned, I start worrying about this when a module grows bigger than 1Kloc, but I seldom have this problem. From narkewoody at gmail.com Fri Jan 9 03:59:26 2009 From: narkewoody at gmail.com (Steven Woody) Date: Fri, 9 Jan 2009 16:59:26 +0800 Subject: Best practice in organize classes into modules In-Reply-To: <496710ba$0$27487$426a74cc@news.free.fr> References: <496710ba$0$27487$426a74cc@news.free.fr> Message-ID: On Fri, Jan 9, 2009 at 4:54 PM, Bruno Desthuilliers wrote: > Steven Woody a ?crit : >> >> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >> wrote: >>> >>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody >>> wrote: >>>> >>>> In C++/Java, people usually put one class into one file. What's the >>>> suggestion on this topic in Python? I so much interesting this >>>> especially when exception classes also involved. >>> >>> Normally i group related functionality into the one module. >> >> Will that lead to too large source file size? > > When the case happens, then you can safely refactor the module into a > package with submodules, and use the package's __init__.py to make it a > facade for the submodules so the refactoring is transparent for client code. really a smart idea. Did you mean putting some 'import statement in __init__.py and use the old module name as the new package name? Thanks. From bj_666 at gmx.net Fri Jan 9 04:15:20 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:15:20 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6soit7F7bavsU1@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > I've first tried Python. Please don't beat me, it's slow as hell and > probably a horrible solution: > > #!/usr/bin/python > import sys > import os > > f = open(sys.argv[1], "r") Mode should be 'rb'. > filesize = os.stat(sys.argv[1])[6] `os.path.getsize()` is a little bit more readable. > width = 1024 > height = 1024 > pixels = width * height > blocksize = filesize / width / height > > print("Filesize : %d" % (filesize)) print("Image size : %dx%d" > % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is a statement and not a function. > picture = { } > havepixels = 0 > while True: > data = f.read(blocksize) > if len(data) <= 0: break if data: break is enough. > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 Here you are creating a list full of integers to use them as index into `data` (twice) instead of iterating directly over the elements in `data`. And you are calling `ord()` for *every* byte in the file although you just need it for one value in each block. If it's possible to write the raw PGM format this conversion wouldn't be necessary at all. For the `datamap` a `collections.defaultdict()` might be faster. > maxchr = None > maxcnt = None > for (char, count) in datamap.items(): > if (maxcnt is None) or (count > maxcnt): > maxcnt = count > maxchr = char Untested: maxchr = max((i, c) for c, i in datamap.iteritems())[1] > most = maxchr Why? > posx = havepixels % width > posy = havepixels / width posx, posy = divmod(havepixels, width) Don't know if this is faster though. > havepixels += 1 > if (havepixels % 1024) == 0: > print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / > pixels)) > > picture[(posx, posy)] = most Why are you using a dictionary as "2d array"? In the C code you simply write the values sequentially, why can't you just use a flat list and append here? Ciao, Marc 'BlackJack' Rintsch From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 04:15:50 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 10:15:50 +0100 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: <4966750c$0$5150$426a74cc@news.free.fr> References: <4966750c$0$5150$426a74cc@news.free.fr> Message-ID: <496715ac$0$15321$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Sergey Kishchenko a ?crit : (snip) >> #prints "Ouch!" >> f=Foo() >> if f: >> print "Ouch!" >> >> So, default __nonzero__ impl is to return True. > > Yes. It's clearly documented FWIW. To be more exact: there's no "default __nonzero__". The boolean value of an object is eval'd this way: If the object is None (special cased by the interpreter AFAICT), it is false. Else if the object implements __nonzero__, it has the boolean value returned by __nonzero__. Else if the object implements __len__, it has the boolean value of its length. Else if is true. >> I think, this >> behaviour conflicts with 'Explicit is better than implicit' > > Why so ? It *is* explicit that the default for an object is to have a > true value in a boolean context. I meant "explicit because documented", of course. >> and >> 'Practicality beats purity' > > Quite on the contrary. From a practical POV, the default truth values of > Python objects are most of the time what you practically want in a > boolean context - that is, any non-None object, non-empty sequence and > non-zero numeric objects are true. __nonzero__ is here for the *very > few* corner cases where this is not the sensible default. >> statements. I think, throwing a TypeError >> exception would be better. It will result in more explicit code with >> fewer errors. As a last note wrt/ explicitness and practicality: Implementing your proposition, one would have to either put each and every boolean expression in a try/except block or "explicitly" define __nonzero__ for each and any class - most of the time (about 99.9999% I'd say) implementing it as to return True - and expect that *everybody* does so. So yes, from a "purity" POV, it might look "more explicit". But this would certainly not be practical at all. OTHO, since boolean algebra only knows two values, it's clear that what is not false is by definition true. So having a default value (true) and a way to override it (__len__ and __nonzero__) is perhaps less "pure", but really as explicit and much more practical. My 2 cents... From googler.1.webmaster at spamgourmet.com Fri Jan 9 04:18:40 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 01:18:40 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> Message-ID: <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> hm... any ideas? From cournape at gmail.com Fri Jan 9 04:24:01 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 9 Jan 2009 18:24:01 +0900 Subject: Python 2.6 fails on compiling > Bug report In-Reply-To: <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: <5b8d13220901090124k64b7b867v6419cef7f08fc52f@mail.gmail.com> On Fri, Jan 9, 2009 at 6:18 PM, wrote: > hm... any ideas? Posting the config.log file would be a first step to give more information, David From prologic at shortcircuit.net.au Fri Jan 9 04:33:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 19:33:53 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch wrote: >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. Not true as of 2.6+ and 3.0+ print is now a function. cheers James From sjmachin at lexicon.net Fri Jan 9 04:37:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 01:37:50 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <2b959051-0871-44da-acb7-e43b0eaf2f66@x16g2000prn.googlegroups.com> On Jan 9, 7:16?pm, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > The error... > ... > > BadZipfile: File is not a zip file > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > I am able to uncompress it in Windows XP, and can also uncompress it > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > contents" in the zip file. ?That's not a concept I'm familiar with. > > No, ZipFile can read table of contents: > > ? ? Help on method printdir in module zipfile: > > ? ? printdir(self) unbound zipfile.ZipFile method > ? ? ? ? Print a table of contents for the zip file. > > In my experience, zip files originating from Windows sometimes have > garbage at the end of the file. WinZip just ignores the garbage, but > other tools sometimes don't -- if I recall correctly, Linux unzip > successfully unzips the file but then complains that the file was > corrupt. It's possible that you're running into a similar problem. > > > data.zip is created in this script... > > > ? ? decoded = base64.b64decode(datum) > > ? ? f = open('data.zip', 'wb') > > ? ? f.write(decoded) > > ? ? f.close() > > ? ? file = zipfile.ZipFile('data.zip', "r") > > > datum is a base64 encoded zip file. ?Again, I am able to open data.zip > > as if it's a valid zip file. ?Maybe there is something wrong with the > > approach I've taken to writing the data to data.zip? ?I'm not sure if it > > matters, but the zipped data is Unicode. > > The full signature of ZipFile is: > > ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) > > Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and > see if that makes any difference. "compression" is irrelevant when reading. The compression method used is stored on a per-file basis, not on a per-archive basis, and it hasn't got anywhere near per-file details when that exception is raised. "allowZip64" has not been used either. > > The zip format does support alternative compression methods, it's > possible that this particular file uses a different sort of compression > which Python doesn't deal with. > > > What would cause a zip file to not have a table of contents? > > What makes you think it doesn't have one? > > -- > Steven From antroy at gmail.com Fri Jan 9 04:38:21 2009 From: antroy at gmail.com (Ant) Date: Fri, 9 Jan 2009 01:38:21 -0800 (PST) Subject: drive a desktop app from python? References: Message-ID: On Jan 8, 9:06?pm, "Tim Arnold" wrote: > Is there any lib or recipe(s) for doing something like this via python? Look into the PyWin32 extension module. It gives access to Windows internals including the COM interface. You'll need to do some research into how to automate the GUI you're using from other sources (there are often VBA examples on the web that can be modified). http://pywin32.sourceforge.net/ I've successfully used this in the past for automating MS Excel. From bj_666 at gmx.net Fri Jan 9 04:41:49 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:41:49 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <6soketF7bavsU2@mid.uni-berlin.de> On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch > wrote: >> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >> is a statement and not a function. > > Not true as of 2.6+ and 3.0+ > > print is now a function. Please read again what I wrote. Ciao, Marc 'BlackJack' Rintsch From bj_666 at gmx.net Fri Jan 9 04:45:50 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 09:45:50 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6sokmeF7bavsU3@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > datamap = { } > for i in range(len(data)): > datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 Here is an error by the way: You call `ord()` just on the left side of the ``=``, so all keys in the dictionary are mapped to ones after the loop which gives a pretty boring PGM. :-) Ciao, Marc 'BlackJack' Rintsch From prologic at shortcircuit.net.au Fri Jan 9 04:46:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jan 2009 19:46:58 +1000 Subject: Implementing file reading in C/Python In-Reply-To: <6soketF7bavsU2@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> <6soketF7bavsU2@mid.uni-berlin.de> Message-ID: On Fri, Jan 9, 2009 at 7:41 PM, Marc 'BlackJack' Rintsch wrote: > Please read again what I wrote. Lol I thought "<3" was a smiley! :) Sorry! cheers James From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:01:00 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:01:00 GMT Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> Message-ID: <01771716$0$8693$c3e8da3@news.astraweb.com> On Thu, 08 Jan 2009 18:33:50 +0000, Mark Wooding wrote: > [Steven's message hasn't reached my server, so I'll reply to it here. > Sorry if this is confusing.] > > Aaron Brady wrote: >> On Jan 8, 1:45 am, Steven D'Aprano >> wrote: >> > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: >> > >> > > The `they're just objects' model is very simple, but gets tied up >> > > in knots explaining things. The `it's all references' model is >> > > only a little more complicated, but explains everything. >> > >> > But it *over* explains, because it implies things that "everybody >> > knows" about references in other languages that aren't true for >> > Python. > > I addressed this elsewhere. Summary: `pass-by-reference' is a different > thing to `all you manipulate are references': You know, I've written a fair bit of Python code over the years, and I've never manipulated a reference *once*. Ints, strings, floats, lists, tuples... but references? Never. I'm pretty sure that no other pure-Python coder has manipulated references either. They've manipulated objects. Whatever the VM does under the hood is another story. If you insist on talking about implementations, then at least get it right: in Python, like every other programming language, all you do is flip bits. It's *all* bit flipping. That's why we should try to keep the different layers of explanation separate, without conflating them. Python programmers don't actually flip bits, and neither do they manipulate references. Python programmers don't have access to bits, or references. What they have access to is objects. (Of course, there are ways to get under the hood if you really want to.) > Python does pass-by-value, > but the things it passes -- by value -- are references. If you're going to misuse pass-by-value to describe what Python does, *everything* is pass-by-value "where the value is foo", for some foo. You can't have anything but pass-by-value with current computer technology, because computers don't actually move arguments, they only copy bytes. So pass-by-value becomes a meaningless term, because it describes every computer language imaginable, including hypothetical ones using calling conventions not yet invented, and therefore explains nothing. > (The `pass-by-*' notions are confusingly named anyway. Pass-by-name > doesn't actually involve names at all.) You might find them confusing, but I don't. What I find confusing is that people insist on misusing terminology invented for describing one type of behaviour in order to use it for a completely different type of behaviour just because of certain similarities under the hood. >> > Of course it's not literally true that "everybody knows" that you can >> > use references to implement a swap(x, y) procedure. But people coming >> > from a C or Pascal background tend to assume that everything is like >> > C/Pascal, and there are a lot of them. If C was a rare, unfamiliar >> > language, my opposition to using the term "reference" would be a lot >> > milder. Maybe in another five years? > > I agree with the comment about Pascal, but C is actually pretty similar > to Python here. C only does pass-by-value. Except for arrays. > If you want a function to > modify your variable, you have to pass a pointer value which points to > it. Yes, because the variable is copied before the function sees it. So if you pass a struct, and modify one of the struct's fields, the caller doesn't see the change. Now try that with Python, and you'll see completely different behaviour. (You'll have to use something *like* a struct, because Python doesn't have them. Try an object with attributes.) In other words... C is call-by-value, and (according to you) Python is call-by-value, but they behaviour differently. > Python has no pointer values, so you need a different hack. The > hack usually involves lists. (Though it's easier in the main to return > compound data objects like tuples. I don't suppose that a proposal for > true multiple return values would go down well here. No, didn't think > so...) Out of curiosity, what makes Python returning tuples less "true" than "true multiple return values", and what can you do with TMRVs that you can't do with tuples? >> > Okay, the abstraction has leaked again... are the paperweights >> > references to the objects, or the names we've bound objects to? I'm >> > confused... > > They're the references to the objects. You don't bind names to objects. Amazing. It sure feels like it to me. x = 23 There's a name, and an object, and I've bound the name to the object so I can refer to the object 23 by the name x. > You bind names slots in which you store references. I'm pretty sure I don't. I'd have noticed. You may have missed my last question: >> > How do we deal with anonymous objects in your model? > What I am pretty sure of is that references are going to have to enter > the picture at some point, because other models get too complicated. Well, I dare say that at *some* point all models are insufficient. The map is not the territory, and there's always something that gets left out. But I think your model with strings is more complicated: robots, sticky Blu-Tack, string that you can't touch or see, and so forth. Compared to that, TARDIS technology enabling objects to be in two places at once is remarkably straightforward. Despite it being physically unrealistic, it's logically simple. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:09:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:09:58 GMT Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <01771931$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 00:46:27 -0800, Carl Banks wrote: > On Jan 9, 2:16?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: >> > The error... >> ... >> > BadZipfile: File is not a zip file >> >> > When I look at data.zip in Windows, it appears to be a valid zip >> > file. I am able to uncompress it in Windows XP, and can also >> > uncompress it with 7-Zip. ?It looks like zipfile is not able to read >> > a "table of contents" in the zip file. ?That's not a concept I'm >> > familiar with. >> >> No, ZipFile can read table of contents: >> >> ? ? Help on method printdir in module zipfile: >> >> ? ? printdir(self) unbound zipfile.ZipFile method >> ? ? ? ? Print a table of contents for the zip file. >> >> In my experience, zip files originating from Windows sometimes have >> garbage at the end of the file. WinZip just ignores the garbage, but >> other tools sometimes don't -- if I recall correctly, Linux unzip >> successfully unzips the file but then complains that the file was >> corrupt. It's possible that you're running into a similar problem. > > > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. If the end of > file hasn't yet been reached there could be more data. To make matters > worse, somehow zip files came to have text comments simply appended to > the end of them. (Probably this was for the benefit of people who would > cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile format, > you don't have any foolproof way to know if it's because the file is > corrupted or if it's just an appended comment. Yes, this has lead to a nice little attack vector, using hostile Java classes inside JAR files (a variant of ZIP). http://www.infoworld.com/article/08/08/01/ A_photo_that_can_steal_your_online_credentials_1.html or http://snipurl.com/9oh0e -- Steven From gandalf at shopzeus.com Fri Jan 9 05:11:43 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 11:11:43 +0100 Subject: Fatal Python error: ceval: tstate mix-up Message-ID: <496722DF.6080206@shopzeus.com> After upgrading my system, a program started to throw this error, and make a core dump: Fatal Python error: ceval: tstate mix-up Kernel log says: Jan 9 05:06:49 shopzeus kernel: pid 89184 (python), uid 1024: exited on signal 6 (core dumped) I found out that this can happen only when executing Python code without holding the GIL. My program is written entriely in Python, but uses some third part libraries: py25-json py25-psycopg2 Here is Python version: Python 2.5.2 (r252:60911, Nov 17 2008, 22:19:20) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 (OS is FreeBSD 7.0 amd64 stable on dual quad core xeon 5420, it that matters...) I have the code dump, but I do not know how to debug that. What should I do? Thanks, Laszlo From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:15:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:15:35 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <01771a82$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch > wrote: >>> print("Filesize : %d" % (filesize)) print("Image size : >>> %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) >> >> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >> is a statement and not a function. > > Not true as of 2.6+ and 3.0+ > > print is now a function. Not so. print is still a statement in 2.6. $ python2.6 Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13) [GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> print 23 23 -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:16:05 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:16:05 GMT Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> Message-ID: <01771aa0$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 00:21:09 -0800, koranthala wrote: > I was wondering if there is a mechanism to encrypt logging automatically > in python. > The issue is as follows: > (a) An application (after py2exe) will go as executable and there > is no need for the user to know that it is written in python. If an > exception occurs and it is logged, then the user can understand it is > written in python. > (b) A security threat. If an exception occurs, the code is seen by > the user - and possibly be misused. Security by obscurity is not security. If your application isn't secure against people who know what language is written in, then it isn't secure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 05:17:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 10:17:36 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: <01771afb$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 09:15:20 +0000, Marc 'BlackJack' Rintsch wrote: >> picture = { } >> havepixels = 0 >> while True: >> data = f.read(blocksize) >> if len(data) <= 0: break > > if data: > break > > is enough. You've reversed the sense of the test. The OP exits the loop when data is empty, you exit the loop when it *isn't* empty. -- Steven From bj_666 at gmx.net Fri Jan 9 05:32:34 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 10:32:34 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <6sone1F7bavsU5@mid.uni-berlin.de> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > As this was horribly slow (20 Minutes for a 2GB file) I coded the whole > thing in C also: Yours took ~37?minutes for 2?GiB here. This "just" ~15?minutes: #!/usr/bin/env python from __future__ import division, with_statement import os import sys from collections import defaultdict from functools import partial from itertools import imap def iter_max_values(blocks, block_count): for i, block in enumerate(blocks): histogram = defaultdict(int) for byte in block: histogram[byte] += 1 yield max((count, byte) for value, count in histogram.iteritems())[1] if i % 1024 == 0: print 'Progresss: %.1f%%' % (100 * i / block_count) def write_pgm(filename, width, height, pixel_values): with open(filename, 'w') as pgm_file: pgm_file.write('P2\n' '# CREATOR: Crappyass Python Script\n' '%d %d\n' '255\n' % (width, height)) pgm_file.writelines('%d\n' % value for value in pixel_values) def main(): filename = sys.argv[1] filesize = os.path.getsize(filename) width = 1024 height = 1024 pixels = width * height blocksize = filesize // width // height print 'Filesize : %d' % filesize print 'Image size : %dx%d' % (width, height) print 'Bytes per Pixel: %d' % blocksize with open(filename, 'rb') as data_file: blocks = iter(partial(data_file.read, blocksize), '') pixel_values = imap(ord, iter_max_values(blocks, pixels)) write_pgm(filename + '.pgm', width, height, pixel_values) if __name__ == '__main__': main() Ciao, Marc 'BlackJack' Rintsch From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 9 05:34:55 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 09 Jan 2009 11:34:55 +0100 Subject: Best practice in organize classes into modules In-Reply-To: References: <496710ba$0$27487$426a74cc@news.free.fr> Message-ID: <49672835$0$31446$426a74cc@news.free.fr> Steven Woody a ?crit : > On Fri, Jan 9, 2009 at 4:54 PM, Bruno Desthuilliers > wrote: >> Steven Woody a ?crit : >>> On Fri, Jan 9, 2009 at 1:02 PM, James Mills >>> wrote: >>>> On Fri, Jan 9, 2009 at 2:57 PM, Steven Woody >>>> wrote: >>>>> In C++/Java, people usually put one class into one file. What's the >>>>> suggestion on this topic in Python? I so much interesting this >>>>> especially when exception classes also involved. >>>> Normally i group related functionality into the one module. >>> Will that lead to too large source file size? >> When the case happens, then you can safely refactor the module into a >> package with submodules, and use the package's __init__.py to make it a >> facade for the submodules so the refactoring is transparent for client code. > > really a smart idea. Mostly a common Python idiom. > Did you mean putting some 'import statement in > __init__.py and use the old module name as the new package name? Yes, you guessed. From steve at holdenweb.com Fri Jan 9 05:41:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 05:41:39 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: [...] >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. > Portability? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Fri Jan 9 05:42:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 02:42:32 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 7:46?pm, Carl Banks wrote: > On Jan 9, 2:16?am, Steven D'Aprano > > > > > cybersource.com.au> wrote: > > On Thu, 08 Jan 2009 16:47:39 -0800, webcomm wrote: > > > The error... > > ... > > > BadZipfile: File is not a zip file > > > > When I look at data.zip in Windows, it appears to be a valid zip file. > > > I am able to uncompress it in Windows XP, and can also uncompress it > > > with 7-Zip. ?It looks like zipfile is not able to read a "table of > > > contents" in the zip file. ?That's not a concept I'm familiar with. > > > No, ZipFile can read table of contents: > > > ? ? Help on method printdir in module zipfile: > > > ? ? printdir(self) unbound zipfile.ZipFile method > > ? ? ? ? Print a table of contents for the zip file. > > > In my experience, zip files originating from Windows sometimes have > > garbage at the end of the file. WinZip just ignores the garbage, but > > other tools sometimes don't -- if I recall correctly, Linux unzip > > successfully unzips the file but then complains that the file was > > corrupt. It's possible that you're running into a similar problem. > > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. ?If the end of > file hasn't yet been reached there could be more data. ?To make > matters worse, somehow zip files came to have text comments simply > appended to the end of them. ?(Probably this was for the benefit of > people who would cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile > format, you don't have any foolproof way to know if it's because the > file is corrupted or if it's just an appended comment. > > Most zipfile readers use a heuristic to distinguish. ?Python's zipfile > module just assumes it's corrupted. > > The following post from a while back gives a solution that tries to > snip the comment off so that zipfile module can handle it. ?It might > help you out. > > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 And here's a little gadget that might help the diagnostic effort; it shows the archive size and the position of all the "magic" PKnn markers. In a "normal" uncommented archive, EndArchive_pos + 22 == archive_size. 8<--- # usage: python zip_susser.py name_of_archive.zip import sys grimoire = [ ("FileHeader", "PK\003\004"), # magic number for file header ("CentralDir", "PK\001\002"), # magic number for central directory ("EndArchive", "PK\005\006"), # magic number for end of archive record ("EndArchive64", "PK\x06\x06"), # magic token for Zip64 header ("EndArchive64Locator", "PK\x06\x07"), # magic token for locator header ] f = open(sys.argv[1], 'rb') buff = f.read() f.close() blen = len(buff) print "archive size is", blen for magic_name, magic in grimoire: pos = 0 while pos < blen: pos = buff.find(magic, pos) if pos < 0: break print "%s at %d" % (magic_name, pos) pos += 4 8<--- HTH, John From steve at holdenweb.com Fri Jan 9 05:45:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 05:45:29 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <01771a82$0$8693$c3e8da3@news.astraweb.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> <01771a82$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > >> On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch >> wrote: >>>> print("Filesize : %d" % (filesize)) print("Image size : >>>> %dx%d" % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) >>> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >>> is a statement and not a function. >> Not true as of 2.6+ and 3.0+ >> >> print is now a function. > > > Not so. print is still a statement in 2.6. > > $ python2.6 > Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13) > [GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> print 23 > 23 > C:\Users\sholden>\python26\python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print >>> OK, I confess I missed out >>> from __future__ import print_function regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pistacchio at gmail.com Fri Jan 9 05:47:42 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 11:47:42 +0100 Subject: Line completion with custom commands Message-ID: Hi, my Python program can be launched with a range of different options (or subcommands) like: $ myProgram doSomething $ myProgram doSomethingElse $ myProgram nowDoSomethingDifferent I want it to use auto-completion with so that if i type "myProgram d" it returns "myProgram doSomething" and if i type "myProgram n" it renders "myProgram nowDoSomethingDifferent". This is similar to the average use of the module rlcompleter, but it does not pick possible completion options from the filesystem (or from history) but from a custom set of strings (that correspond to the available options for my program) Any idea on how to implement this? I'm aware of the variable PYTHONSTARTUP (that should point to a file I don't know how to write). As a working example, django-admin (from the django package) has the same exact feature i'm looking for From lkcl at lkcl.net Fri Jan 9 05:51:13 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Fri, 9 Jan 2009 10:51:13 +0000 Subject: [Python-Dev] compiling python2.5 on linux under wine In-Reply-To: <49666AF7.9010804@v.loewis.de> References: <5b8d13220901080511x2fe96845l8ad86e70908f0a3e@mail.gmail.com> <49666AF7.9010804@v.loewis.de> Message-ID: On Thu, Jan 8, 2009 at 9:07 PM, "Martin v. L?wis" wrote: >> i'd just ... much rather be completely independent of proprietary >> software when it comes to building free software. > > I guess my question is then: why do you want to use Windows in the > first place? ha ha :) the same question was asked when i started the nt domains reverse-engineering for samba, in 1996. the answer is: i don't. but there are a lot of users and developers who feel that they don't have a choice. or haven't been given one. so if it's possible for me, as one of the "under 1% of computer users i.e. linux" to compile stuff that will work on the "over 95% of computers used by everyone else i.e. windows" _and_ i get to stick to free software principles, that's gotta be good. take pywebkit-gtk as an example. the first-level (and some of the second-level) dependencies for pywebkit-gtk are roughly as follows: * libstdc++ * cairo, pango, gdk, fontconfig, gtk * libxml2 (which is dodgy) * libxslt1 (which is so dodgy and dependent on incompatible versions of libxml2 it can't be compiled on win32) * libicu38 * libcurl * libssl * webkit * python2.5 * python-gobect * python-gtk that's a *big* xxxxing list that comes in at a whopping 40mb of _binaries_. webkit itself comes in at 10mb alone. libicu38 fails _miserably_ to cross-compile with mingw32. i was damn lucky to have beaten it into submission: it took two days and i couldn't run any of the tests, but actually managed to get at least some .libs, .dlls and .a's out of the mess. libxslt1 and libxml2 have compile errors in mutually incompatible versions on win32, plus, unfortunately, the versions that _do_ compile correctly (really old versions like libxslt-1.12 + libxml2-18 or something) are not the ones that can be used on webkit! i had to get the source code for gcc (4.4) because when linking webkit against the MSVC-compiled libicu38 gcc actually segfaulted (!). and that was tracked down to exception handling across process / thread boundaries in libstdc++-6 which had only literally been fixed/patched a few days before i started the monster-compile-process. i tried hunting down python-gobject and python-gtk for win32, but there is a dependency needed before you get to that: python25.lib. as i mentioned previously i tried hunting down a .lib for python25 but of course that would be useless unless i also have a libtool-compiled .a so there wasn't any point. so, all the hard work that i did cross-compiling up webkit for win32 was completely wasted because python itself could not be compiled on linux for a win32 platform. hence my interest in making sure that it can be. _then_ i can go back and revisit the monster compile process and finally come up with the goods, on win32, on the gobject-based DOM-model manipulation stuff i've added to pywebkit-gtk. i've got linux covered, i've got macosx covered. win32 is the last one. l. From mrkafk at gmail.com Fri Jan 9 05:56:35 2009 From: mrkafk at gmail.com (mk) Date: Fri, 09 Jan 2009 11:56:35 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <9fri36xno7.ln2@joeserver.homelan.net> References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Johannes Bauer wrote: > Which takes about 40 seconds. I want the niceness of Python but a little > more speed than I'm getting (I'd settle for factor 2 or 3 slower, but > factor 30 is just too much). This probably doesn't contribute much, but have you tried using Python profiler? You might have *something* wrong that eats up a lot of time in the code. The factor of 30 indeed does not seem right -- I have done somewhat similar stuff (calculating Levenshtein distance [edit distance] on words read from very large files), coded the same algorithm in pure Python and C++ (using linked lists in C++) and Python version was 2.5 times slower. Regards, mk From steve at holdenweb.com Fri Jan 9 06:03:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 06:03:47 -0500 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: gu wrote: > > Hi, my Python program can be launched with a range of different options > (or subcommands) like: > > $ myProgram doSomething > $ myProgram doSomethingElse > $ myProgram nowDoSomethingDifferent > > I want it to use auto-completion with so that if i type "myProgram d" it > returns "myProgram doSomething" and if i type "myProgram n" it renders > "myProgram nowDoSomethingDifferent". This is similar to the average use > of the module rlcompleter, but it does not pick possible completion > options from the filesystem (or from history) but from a custom set of > strings (that correspond to the available options for my program) > > Any idea on how to implement this? > > I'm aware of the variable PYTHONSTARTUP (that should point to a file I > don't know how to write). > > As a working example, django-admin (from the django package) has the > same exact feature i'm looking for The issue here is that Python doesn't get control until afer you've hit RETURN on the command line. so nothing you can do in your program or interpreter setup will have any effect on how the command shell behaves. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Fri Jan 9 06:05:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 09 Jan 2009 05:05:46 -0600 Subject: figuring week of the day.... In-Reply-To: <49665986.7080301@thechases.com> References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <49665986.7080301@thechases.com> Message-ID: <49672F8A.6040001@tim.thechases.com> Tim Chase wrote: > tekion wrote: >> Is there a module where you could figure week of the day, like where >> it starts and end. I need to do this for a whole year. Thanks. > > the monthcalendar() call returns the whole month's calendar which > may be more what you want for the big-picture. And if you want a whole year's worth, you can get pretty close with: import itertools as i import calendar as c for month in range(1,13): for week in c.monthcalendar(2009, month): print repr(w) You don't detail how you want the month-boundaries to behave, so this gives "calendar"'s default behavior of filling in zeros on month-boundaries, so November through the 1st week in Dec 2009 comes back as ... [0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], ... rather than ... [26, 27, 28, 29, 30, 31, 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, 1, 2, 3, 4, 5, 6], ... -tkc From pistacchio at gmail.com Fri Jan 9 06:12:15 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:12:15 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <4967310F.8070704@gmail.com> Steve Holden wrote: > gu wrote: >> Hi, my Python program can be launched with a range of different options >> (or subcommands) like: >> >> $ myProgram doSomething >> $ myProgram doSomethingElse >> $ myProgram nowDoSomethingDifferent >> >> I want it to use auto-completion with so that if i type "myProgram d" it >> returns "myProgram doSomething" and if i type "myProgram n" it renders >> "myProgram nowDoSomethingDifferent". This is similar to the average use >> of the module rlcompleter, but it does not pick possible completion >> options from the filesystem (or from history) but from a custom set of >> strings (that correspond to the available options for my program) >> >> Any idea on how to implement this? >> >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >> don't know how to write). >> >> As a working example, django-admin (from the django package) has the >> same exact feature i'm looking for > > The issue here is that Python doesn't get control until afer you've hit > RETURN on the command line. so nothing you can do in your program or > interpreter setup will have any effect on how the command shell behaves. > > regards > Steve I see, but how does django-admin work, then? From pistacchio at gmail.com Fri Jan 9 06:12:15 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:12:15 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <4967310F.8070704@gmail.com> Steve Holden wrote: > gu wrote: >> Hi, my Python program can be launched with a range of different options >> (or subcommands) like: >> >> $ myProgram doSomething >> $ myProgram doSomethingElse >> $ myProgram nowDoSomethingDifferent >> >> I want it to use auto-completion with so that if i type "myProgram d" it >> returns "myProgram doSomething" and if i type "myProgram n" it renders >> "myProgram nowDoSomethingDifferent". This is similar to the average use >> of the module rlcompleter, but it does not pick possible completion >> options from the filesystem (or from history) but from a custom set of >> strings (that correspond to the available options for my program) >> >> Any idea on how to implement this? >> >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >> don't know how to write). >> >> As a working example, django-admin (from the django package) has the >> same exact feature i'm looking for > > The issue here is that Python doesn't get control until afer you've hit > RETURN on the command line. so nothing you can do in your program or > interpreter setup will have any effect on how the command shell behaves. > > regards > Steve I see, but how does django-admin work, then? From castironpi at gmail.com Fri Jan 9 06:15:57 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 9 Jan 2009 03:15:57 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> On Jan 9, 4:01?am, Steven D'Aprano wrote: > On Thu, 08 Jan 2009 18:33:50 +0000, Mark Wooding wrote: > > [Steven's message hasn't reached my server, so I'll reply to it here. > > Sorry if this is confusing.] > > > Aaron Brady wrote: > >> On Jan 8, 1:45 am, Steven D'Aprano > >> wrote: > >> > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote: > > >> > > The `they're just objects' model is very simple, but gets tied up > >> > > in knots explaining things. ?The `it's all references' model is > >> > > only a little more complicated, but explains everything. > > >> > But it *over* explains, because it implies things that "everybody > >> > knows" about references in other languages that aren't true for > >> > Python. > > > I addressed this elsewhere. ?Summary: `pass-by-reference' is a different > > thing to `all you manipulate are references': > > You know, I've written a fair bit of Python code over the years, and I've > never manipulated a reference *once*. Ints, strings, floats, lists, > tuples... but references? Never. snip > That's why we should try to keep the different layers of explanation > separate, without conflating them. Python programmers don't actually flip > bits, and neither do they manipulate references. Python programmers don't > have access to bits, or references. What they have access to is objects. snip > >> > How do we deal with anonymous objects in your model? > > What I am pretty sure of is that references are going to have to enter > > the picture at some point, because other models get too complicated. > > Well, I dare say that at *some* point all models are insufficient. The > map is not the territory, and there's always something that gets left > out. But I think your model with strings is more complicated: robots, > sticky Blu-Tack, string that you can't touch or see, and so forth. > Compared to that, TARDIS technology enabling objects to be in two places > at once is remarkably straightforward. Despite it being physically > unrealistic, it's logically simple. > > -- > Steven Possible compromise. You can think of functions as mutation-only. You pass the object, and it gets a new (additional) name. The old name doesn't go in. Regardless, IMO, references don't add any explanatory power; they just make you feel cocky that you know what they are. M: If 'fun()' returned a reference, you would be able to assign to it. m: You can't assign to it. C: It doesn't return a reference. -- Why can't I assign to a function call? -- Python variables are references only. -- Ok, why can't I assign to a function call? -- [Explanation Steven is trying to give.] In other words, Mark and Joe, cut to the chase. You're shirking. From marco at sferacarta.com Fri Jan 9 06:18:14 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 09 Jan 2009 12:18:14 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: gu wrote: > I see, but how does django-admin work, then? from bash: complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram From steve at holdenweb.com Fri Jan 9 06:24:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 06:24:29 -0500 Subject: Line completion with custom commands In-Reply-To: <4967310F.8070704@gmail.com> References: <4967310F.8070704@gmail.com> Message-ID: gu wrote: > Steve Holden wrote: >> gu wrote: >>> Hi, my Python program can be launched with a range of different options >>> (or subcommands) like: >>> >>> $ myProgram doSomething >>> $ myProgram doSomethingElse >>> $ myProgram nowDoSomethingDifferent >>> >>> I want it to use auto-completion with so that if i type "myProgram d" it >>> returns "myProgram doSomething" and if i type "myProgram n" it renders >>> "myProgram nowDoSomethingDifferent". This is similar to the average use >>> of the module rlcompleter, but it does not pick possible completion >>> options from the filesystem (or from history) but from a custom set of >>> strings (that correspond to the available options for my program) >>> >>> Any idea on how to implement this? >>> >>> I'm aware of the variable PYTHONSTARTUP (that should point to a file I >>> don't know how to write). >>> >>> As a working example, django-admin (from the django package) has the >>> same exact feature i'm looking for >> >> The issue here is that Python doesn't get control until afer you've hit >> RETURN on the command line. so nothing you can do in your program or >> interpreter setup will have any effect on how the command shell behaves. >> >> regards >> Steve > > I see, but how does django-admin work, then? > Probably the issue you has was not knowing the name of the feature. When I asked Google to tell me about django-admin command completion it said: http://code.djangoproject.com/ticket/1240 as the first hit. As you will see, this is done by configuring the shell to know about the specific commands it has to deal with. Enjoy! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pistacchio at gmail.com Fri Jan 9 06:28:04 2009 From: pistacchio at gmail.com (gu) Date: Fri, 09 Jan 2009 12:28:04 +0100 Subject: Line completion with custom commands In-Reply-To: References: Message-ID: <496734C4.201@gmail.com> Marco Mariani wrote: > gu wrote: > >> I see, but how does django-admin work, then? > > from bash: > > complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram This worked like a charm, thank you so much. Is this available for bash only or any shell? From zugnush at gmail.com Fri Jan 9 06:38:34 2009 From: zugnush at gmail.com (zugnush at gmail.com) Date: Fri, 9 Jan 2009 03:38:34 -0800 (PST) Subject: drive a desktop app from python? References: Message-ID: <4dd5903b-78f2-4ed4-9885-a43ed07da80c@w1g2000prk.googlegroups.com> > Is there any lib or recipe(s) for doing something like this via python? > I've used pywinauto to do something similar, and found it good. http://pywinauto.openqa.org/ From boyee118 at gmail.com Fri Jan 9 06:39:10 2009 From: boyee118 at gmail.com (Korobase) Date: Fri, 9 Jan 2009 19:39:10 +0800 Subject: [Help] The pywinauto Can't select the MDI's menu using the MenuItems() which return []. In-Reply-To: <8c7f10c60812220156k4a290fa1re469bc8c4a4019ae@mail.gmail.com> References: <85676.52949.qm@web32801.mail.mud.yahoo.com> <8c7f10c60812220156k4a290fa1re469bc8c4a4019ae@mail.gmail.com> Message-ID: 2008/12/22 Simon Brunning > 2008/12/21 : > > The code below opens the Choose Font dialog on my Spanish Windows > version: > > > > py> from pywinauto.application import Application > > py> app = Application.start("Notepad.exe") > > Notepad's menus are build with MFC. Word's menus are not. Trust me, > give it up. For automating Word, COM (with Mark Hammond's excellent > Python/COM bridge) is the only way to go. Yeah. But the GuiLib program also don't work. You can dowload sample from http://www.beyondata.com/ and use the pywinauto to test it. I want to know how to do the GuiLib's automation. > > > -- > Cheers, > Simon B. > simon at brunningonline.net > -- > http://mail.python.org/mailman/listinfo/python-list > -- "OpenBookProject"-?????????? ??: http://groups.google.com/group/OpenBookProject ??: http://wiki.woodpecker.org.cn/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Fri Jan 9 06:55:27 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 03:55:27 -0800 (PST) Subject: Unexpected scientific notation References: Message-ID: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> On Jan 8, 1:00?am, Paul McNett wrote: > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be causing > this. What would be choosing to display such a normal number in scientific notation? > > Ideas? [I thought I replied to this earlier, but the post isn't showing up. So here it is again.] I suspect it's your use of the Decimal normalize() method that's causing this. Trailing zeros on Decimal instances are significant, so Decimal('30.0'), Decimal('30') and Decimal('3E+1') are considered distinct (though they all have the same value). The normalize method strips all trailing zeros, turning Decimal('30.0') into Decimal('3E +1'). One way to get around this is to add 0 after normalizing: this will make sure that scientific notation is used only for very large or small numbers, as usual. Python 2.7a0 (trunk:68298:68318, Jan 6 2009, 10:39:14) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal >>> 0 + Decimal('3E1') Decimal('30') >>> Decimal('0.0') + Decimal('3E1') Decimal('30.0') Adding 0 also has the side-effect of turning a negative zero into a positive zero, but I suspect that this isn't going to worry you much. :) You might also want to look at the Decimal.quantize method. Mark From gandalf at shopzeus.com Fri Jan 9 07:40:36 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 13:40:36 +0100 Subject: Fatal Python error: ceval: tstate mix-up In-Reply-To: <496722DF.6080206@shopzeus.com> References: <496722DF.6080206@shopzeus.com> Message-ID: <496745C4.60105@shopzeus.com> I could start "gdb python python.core" but don't know what it means. Unfortunately, there are no debugging symbols. %gdb /usr/local/bin/python python.core GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)... Core was generated by `python'. Program terminated with signal 6, Aborted. Reading symbols from /lib/libutil.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libutil.so.7 Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libm.so.5 Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done. Loaded symbols for /lib/libthr.so.3 Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libc.so.7 Reading symbols from /usr/local/lib/python2.5/lib-dynload/time.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/time.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/collections.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/collections.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/datetime.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/datetime.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/cStringIO.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/cStringIO.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/strop.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/strop.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/operator.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/operator.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_struct.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_struct.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/binascii.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/binascii.so Reading symbols from /usr/local/lib/python2.5/site-packages/sgmlop.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/sgmlop.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/pyexpat.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/pyexpat.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_socket.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_socket.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_ssl.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_ssl.so Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done. Loaded symbols for /usr/lib/libssl.so.5 Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libcrypto.so.5 Reading symbols from /usr/local/lib/python2.5/lib-dynload/math.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/math.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_random.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_random.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/fcntl.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/fcntl.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/select.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/select.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/rand.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/rand.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/crypto.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/crypto.so Reading symbols from /usr/local/lib/python2.5/site-packages/OpenSSL/SSL.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/OpenSSL/SSL.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/cPickle.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/cPickle.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_weakref.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_weakref.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_hashlib.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_hashlib.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_bisect.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_bisect.so Reading symbols from /usr/local/lib/python2.5/lib-dynload/_locale.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/lib-dynload/_locale.so Reading symbols from /usr/local/lib/python2.5/site-packages/psycopg2/_psycopg.so...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/python2.5/site-packages/psycopg2/_psycopg.so Reading symbols from /usr/local/lib/libpq.so.5...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libpq.so.5 Reading symbols from /usr/local/lib/libintl.so.8...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libintl.so.8 Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done. Loaded symbols for /lib/libcrypt.so.4 Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libiconv.so.3 Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done. Loaded symbols for /libexec/ld-elf.so.1 #0 0x0000000800a9cfec in thr_kill () from /lib/libc.so.7 [New Thread 0x800d05060 (LWP 100709)] [New Thread 0x800d04ef0 (LWP 100269)] [New Thread 0x800d04d80 (LWP 100253)] [New Thread 0x800d04c10 (LWP 100231)] [New Thread 0x800d04aa0 (LWP 100226)] [New Thread 0x800d04930 (LWP 100206)] [New Thread 0x800d047c0 (LWP 100189)] [New Thread 0x800d01120 (LWP 100096)] (gdb) From daved170 at gmail.com Fri Jan 9 07:45:33 2009 From: daved170 at gmail.com (Dave Dave) Date: Fri, 9 Jan 2009 14:45:33 +0200 Subject: pySerial - accessing GSM module failed Message-ID: Hello all, I'm newbie in the serial buissness and I beed some Help. I'm a student at my last year and I got final assaignment. My goal is to comunicate with SIM free, GSM Module through computer. I want to simulate SIM card by receiving and transferring data from my code. In order to understand how to comunicate with the GSM module I took an existing module which gut RS232 connector and connected it to the computer. I ran my python code: class MySerial(): def __init__ (self,port,baundrate,....) self.s = serial.Serial(port,baundreate,....) def read(self,size=1): txt = self.s.read(size) def write(self,text=''): txt = self.s.write(text) def main(): obj = MySerial('COM1') obj.write('ATI') sleep(1) obj.read(10) the code run and I send the comman 'ATI' which ask the GSM Module if everything is OK. the read line returs 'ATI'. echo to my write function. Whenever I run this comman ('ATI') through hyperterminal I gut the result : 232 OK Does any one got an Idea why my code isn't getting the same answer from the GSM Module? thanks dave -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Fri Jan 9 08:01:10 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 09 Jan 2009 14:01:10 +0100 Subject: Force exception on attribute write access only one object In-Reply-To: References: <6slvrrF71ds4U1@mid.individual.net> Message-ID: <6sp04mF7hgjdU1@mid.individual.net> Hi Peter and others, your idea was good, but it does not work with Django ORM Models: Traceback (most recent call last): File "/localhome/modw/django/core/handlers/base.py", line 87, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/localhome/modw/foo/views/filter.py", line 473, in add return edit(request, 'add') File "/localhome/modw/foo/views/filter.py", line 493, in edit filter=form.save() File "/localhome/modw/foo/views/filter.py", line 457, in save action=form.save() File "/localhome/modw/django/forms/models.py", line 315, in save if self.instance.pk is None: File "/localhome/modw/django/db/models/base.py", line 292, in _get_pk_val return getattr(self, meta.pk.attname) AttributeError: 'MyAction' object has no attribute 'filter_action_ptr_id' Peter Otten schrieb: > Thomas Guettler wrote: > >> for debugging I want to raise an exception if an attribute is >> changed on an object. Since it is only for debugging I don't want >> to change the integer attribute to a property. > > Why? > >> This should raise an exception: >> >> myobj.foo=1 >> >> Background: >> Somewhere this value gets changed. But I don't now where. > > If you change your mind: > > class A(object): > def __init__(self): > self.foo = 42 > > a = A() > b = A() > > class B(A): > @property > def foo(self): > return self.__dict__["foo"] > > b.__class__ = B > > a.foo = "whatever" > print b.foo > b.foo = "whatever" > > Peter -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From koranthala at gmail.com Fri Jan 9 08:02:16 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Fri, 9 Jan 2009 05:02:16 -0800 (PST) Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> <01771aa0$0$8693$c3e8da3@news.astraweb.com> Message-ID: <3d7f8241-50ae-48e1-a541-f562f056aa8d@r37g2000prr.googlegroups.com> On Jan 9, 3:16?pm, Steven D'Aprano wrote: > On Fri, 09 Jan 2009 00:21:09 -0800, koranthala wrote: > > I was wondering if there is a mechanism to encrypt logging automatically > > in python. > > ? ?The issue is as follows: > > ? ? (a) An application (after py2exe) will go as executable and there > > is no need for the user to know that it is written in python. If an > > exception occurs and it is logged, then the user can understand it is > > written in python. > > ? ? (b) A security threat. If an exception occurs, the code is seen by > > the user - and possibly be misused. > > Security by obscurity is not security. If your application isn't secure > against people who know what language is written in, then it isn't secure. > > -- > Steven I understand that completely. My point is that even though I can try to make the application completely secure - I can never be sure of that. Especially if your company is a very small one - and might not be able to have the best programmers around. So, another layer of security - even security through obscurity - can give that bit extra time in which the bugs in the system can be ironed out. Also, what I am asking is a generic option in logging - which can help the adoption of the logging framework in even closed source systems. It is not just about security - just that a closed source company might be much more comfortable in using the system if crypt is there. From gandalf at shopzeus.com Fri Jan 9 08:08:39 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 09 Jan 2009 14:08:39 +0100 Subject: Fatal Python error: ceval: tstate mix-up In-Reply-To: <496722DF.6080206@shopzeus.com> References: <496722DF.6080206@shopzeus.com> Message-ID: <49674C57.3040908@shopzeus.com> Meanwhile I'm trying to turn off threads in that program one by one. I just got this new type of error: Fatal Python error: PyThreadState_Delete: invalid tstate From goldnery at gmail.com Fri Jan 9 08:34:06 2009 From: goldnery at gmail.com (Gandalf) Date: Fri, 9 Jan 2009 05:34:06 -0800 (PST) Subject: win32gui Message-ID: Hi, everyone I'm searching the win32gui lib to find a way to get the text under the user cursor. so far I managed to find only the controller ID which under the cursor this way cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) their is function called GetWindowText I tried to use but it doesn't work in most of the time someone know a way to do this? thank you! From dfnsonfsduifb at gmx.de Fri Jan 9 08:38:20 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:38:20 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <6soit7F7bavsU1@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch schrieb: >> f = open(sys.argv[1], "r") > > Mode should be 'rb'. Check. >> filesize = os.stat(sys.argv[1])[6] > > `os.path.getsize()` is a little bit more readable. Check. >> print("Filesize : %d" % (filesize)) print("Image size : %dx%d" >> % (width, height)) print("Bytes per Pixel: %d" % (blocksize)) > > Why parentheses around ``print``\s "argument"? In Python <3 ``print`` is > a statement and not a function. I write all new code to work under Python3.0. Actually I develop on Python 3.0 but the code is currently deployed onto 2.6. >> picture = { } >> havepixels = 0 >> while True: >> data = f.read(blocksize) >> if len(data) <= 0: break > > if data: > break > > is enough. > >> datamap = { } >> for i in range(len(data)): >> datamap[ord(data[i])] = datamap.get(data[i], 0) + 1 > > Here you are creating a list full of integers to use them as index into > `data` (twice) instead of iterating directly over the elements in > `data`. And you are calling `ord()` for *every* byte in the file > although you just need it for one value in each block. If it's possible > to write the raw PGM format this conversion wouldn't be necessary at all. OK, those two are just stupid, you're right. I changed it to: datamap = { } for i in data: datamap[i] = datamap.get(i, 0) + 1 array = sorted([(b, a) for (a, b) in datamap.items()], reverse=True) most = ord(array[0][1]) pic.write("%d\n" % (most)) > For the `datamap` a `collections.defaultdict()` might be faster. Tried that, not much of a change. >> maxchr = None >> maxcnt = None >> for (char, count) in datamap.items(): >> if (maxcnt is None) or (count > maxcnt): >> maxcnt = count >> maxchr = char > > Untested: > > maxchr = max((i, c) for c, i in datamap.iteritems())[1] This is nice, I use it - the sort thing was a workaround anyways. >> most = maxchr > > Why? I don't really know anymore :-\ >> posx = havepixels % width >> posy = havepixels / width > > posx, posy = divmod(havepixels, width) That's a nice one. > Why are you using a dictionary as "2d array"? In the C code you simply > write the values sequentially, why can't you just use a flat list and > append here? Yup, I changed the Python code to behave the same way the C code did - however overall it's not much of an improvement: Takes about 15 minutes to execute (still factor 23). Thanks for all your pointers! Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From dfnsonfsduifb at gmx.de Fri Jan 9 08:42:37 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:42:37 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: James Mills schrieb: > What does this little tool do anyway ? > It's very interesting the images it creates > out of files. What is this called ? It has no particular name. I was toying around with the Princeton Cold Boot Attack (http://citp.princeton.edu/memory/). In particular I was interested in how much memory is erased when I would (on my system) enable the slow POST (which counts through all RAM three times). I downloaded the provided utitilities, dumped my system memory via PXE boot onto another system after resetting it hard in the middle of a running Linux session. I did sync, though. Praise all journaling filesystems. As a 2GB file is not really of much use for telling where something is and where isn't, I thought of that picture coloring. In a 1024x1024 picture a pixel is 2048 bytes with 2GB of RAM, so exactly half a page. This is sufficiently high resolution to detect what's in there. > I'm curious :) I haven't had much tiem to > optimize it yet - I'll try to when I get home from work. Thanks for your effort, I appreciate it... hope my work leads to some meaningful results. Currently it looks (*cough* if there aren't bugs in my picture code) as if my PC would reset the whole RAM anyways, although I do not have any ECC. Strange. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From dfnsonfsduifb at gmx.de Fri Jan 9 08:46:19 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:46:19 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <6sone1F7bavsU5@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch schrieb: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > >> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >> thing in C also: > > Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: Ah, ok... when implementing your suggestions int he other post, I did not get such a drastic performance increase. I really will have a look at it and try to locate where I'm wasting the time. Thanks a lot, Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From mdw at distorted.org.uk Fri Jan 9 08:47:43 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 13:47:43 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > As a side comment (because it always bugs me when I read this, even > though I read it in very authoritative sources), ISTM that C passes > everything by value except arrays; they are passed by reference (by > passing a pointer to the array by value.) Admittedly, the close > relationship between arrays and pointers makes it easy conflate them. Arrays are distinctly second-class citizens in C. Basically, in C, arrays aren't passed at all but there's some syntactic sugar so you can squint and con yourself that they're passed by reference. If you try to pass an array, the array name immediately decays to a pointer, and the pointer gets passed instead -- by value. The corresponding function parameter must be a pointer to an approrpriate kind of thing, though you're allowed to write []s to confuse yourself if you like -- T D[] in a function parameter declaration means precisely the same as T *D -- to the extent that &D has type T **D and so on. -- [mdw] From dfnsonfsduifb at gmx.de Fri Jan 9 08:48:30 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 09 Jan 2009 14:48:30 +0100 Subject: Implementing file reading in C/Python In-Reply-To: References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: mk schrieb: > Johannes Bauer wrote: > >> Which takes about 40 seconds. I want the niceness of Python but a little >> more speed than I'm getting (I'd settle for factor 2 or 3 slower, but >> factor 30 is just too much). > > This probably doesn't contribute much, but have you tried using Python > profiler? You might have *something* wrong that eats up a lot of time in > the code. No - and I've not known there was a profiler yet have found anything meaningful (there seems to be an profiling C interface, but that won't get me anywhere). Is that a seperate tool or something? Could you provide a link? > The factor of 30 indeed does not seem right -- I have done somewhat > similar stuff (calculating Levenshtein distance [edit distance] on words > read from very large files), coded the same algorithm in pure Python and > C++ (using linked lists in C++) and Python version was 2.5 times slower. Yup, that was about what I had expected (and what I could well live with, it's a tradeoff). Thanks, Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From duane.kaufman at gmail.com Fri Jan 9 09:08:22 2009 From: duane.kaufman at gmail.com (TheSeeker) Date: Fri, 9 Jan 2009 06:08:22 -0800 (PST) Subject: win32gui References: Message-ID: On Jan 9, 7:34?am, Gandalf wrote: > Hi, everyone > I'm searching the win32gui lib to find a way to get the text under the > user cursor. > so far I managed to find only the controller ID which under the cursor > this way > > cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) > > their is function called GetWindowText I tried to use but it doesn't > work in most of the time > > someone know a way to do this? > > thank you! One app that might be of help with your endeavors is called AutoIt (http://www.autoitscript.com/autoit3/) This suite of apps has a nice window browser, which shows most (if mot all) information available from a Windows window. Sometimes not all text in a window is available, depending on the window. It even comes with a COM component, so it can be scripted from Python... No affiliation, other than a contented user. Duane From pruebauno at latinmail.com Fri Jan 9 09:27:54 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 9 Jan 2009 06:27:54 -0800 (PST) Subject: Encrypted Logging in python References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> <01771aa0$0$8693$c3e8da3@news.astraweb.com> <3d7f8241-50ae-48e1-a541-f562f056aa8d@r37g2000prr.googlegroups.com> Message-ID: <1dd44189-f6dd-48b9-bcf5-b77236bc6a8f@a26g2000prf.googlegroups.com> On Jan 9, 8:02?am, koranth... at gmail.com wrote: > Also, what I am asking is a generic option in logging - which can help > the adoption of the logging framework in even closed source systems. > It is not just about security - just that a closed source company > might be much more comfortable in using the system if crypt is there. Python is an open source project. Many people that read this list don't like closed source code too much and are not willing to invest time to work in features like this. You might get lucky and somebody that is interested in the topic might give you some tips. From slbentley at gmail.com Fri Jan 9 09:36:46 2009 From: slbentley at gmail.com (Scooter) Date: Fri, 9 Jan 2009 06:36:46 -0800 (PST) Subject: Python Apache Handler Message-ID: Does anyone have any good examples, or links thereto for using python as an Apache handler? And I should qualify all of this by saying I'm a python newbie, and while having experience with Apache, I've never done anything outside whats "in the box" . What I'm looking for is how one might use Python not from the CGI/ presentation side but more on the backend...i.e. for each page Apache serves up examine the request and update some headers, or add a cookie to the response. Or possibly use Python for writing a custom Apache logger. I've searched the web but typically end up with pages for mod_python and writing CGI scripts. And if you feel this is better posted in an Apache group vs. here, let me apologize up front. Thanks From goldnery at gmail.com Fri Jan 9 09:39:15 2009 From: goldnery at gmail.com (Gandalf) Date: Fri, 9 Jan 2009 06:39:15 -0800 (PST) Subject: win32gui References: Message-ID: <54ca66c2-fceb-4402-9086-5ae622c420e6@x16g2000prn.googlegroups.com> thank you I'm checking autoit documentation... From ricaraoz at gmail.com Fri Jan 9 09:45:14 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 09 Jan 2009 12:45:14 -0200 Subject: drive a desktop app from python? In-Reply-To: References: Message-ID: <496762FA.6040203@gmail.com> James Stroud wrote: > Tim Arnold wrote: >> Hi, I don't even know what to google for on this one. I need to drive >> a commercial desktop app (on windows xp) since the app doesn't have a >> batch interface. It's intended to analyze one file at a time and >> display a report. >> >> I can get the thing to write out the report an html browser, but I >> have thousands of files I need it to analyze every night. >> >> Is there any lib or recipe(s) for doing something like this via python? > > You are a little thin on details here. My only advice at this point is > to check out os.system, which is the simplest option. From there you > can move to the popen2 module for greater control, but if you are > talking about a gui app, you may run into hang-ups. > > A quick recipe would be the following pretend application that > recursively descends from the current directory calling the utility > named "dosapp" on every file it finds that ends with "jpg" (what > "dosapp" does is left to your imagination): > > > > import os > > def doit(suffix, adir, filenames): > for afile in filenames: > if afile.endswith(suffix): > pathname = os.path.join(adir, afile) > os.system('dosapp %s' % pathname) > > > top = '.' > suffix = '.jpg' > > os.path.walk(top, doit, suffix) > > > Read the docs on os.path.walk, of course. > > James > > >From a search in my mail's lists : http://www.openqa.org/pywinauto/ or http://pywinauto.openqa.org/ http://wwwsearch.sourceforge.net/mechanize/ http://www.autoitscript.com/autoit3/ (see the COM server) http://people.redhat.com/zcerza/dogtail/ HTH From philip at semanchuk.com Fri Jan 9 09:46:51 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 9 Jan 2009 09:46:51 -0500 Subject: Python Imaging Library and textmate In-Reply-To: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> References: <55460f80901082349g5f56c393q801f21221d716400@mail.gmail.com> Message-ID: On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: > Hello, > I am a beginner in python and I am trying to create image files that > contain > lines from a text file. > I am trying to do this with PIL, which seems like a suitable tool. I > have a > copy of TextMate(1.5.8) and I run Macosx 10.5.6 > > The problem is, even though I installed PIL correctly (I get no > errors from > "import Image" in IDLE or in terminal), I can't get TextMate to > import the > module. > I keep getting "ImportError: No module named Image" error. > I tried reloading TextMate's bundles but that did not work either. I use TextMate but I don't know what you mean when you say you can't get TM to import a module. Can you give a little more context? > There was a similar thread in this list with textmate but I can't > understand > how that issue was solved in the end. link? bye Philip From ryandw at gmail.com Fri Jan 9 09:59:36 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 06:59:36 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 3:16?am, Steven D'Aprano wrote: > The full signature of ZipFile is: > > ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) > > Try passing compression=zipfile.ZIP_DEFLATED and/or allowZip64=False and > see if that makes any difference. Those arguments didn't make a difference in my case. > The zip format does support alternative compression methods, it's > possible that this particular file uses a different sort of compression > which Python doesn't deal with. > > > What would cause a zip file to not have a table of contents? > > What makes you think it doesn't have one? Because when I search for the "file is not a zip file" error in zipfile.py, there is a function that checks for a table of contents. Tho it looks like there are other ideas in this thread about what might cause that error... I'll keep reading... From ryandw at gmail.com Fri Jan 9 10:05:25 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:05:25 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 3:46?am, Carl Banks wrote: > The zipfile format is kind of brain dead, you can't tell where the end > of the file is supposed to be by looking at the header. ?If the end of > file hasn't yet been reached there could be more data. ?To make > matters worse, somehow zip files came to have text comments simply > appended to the end of them. ?(Probably this was for the benefit of > people who would cat them to the terminal.) > > Anyway, if you see something that doesn't adhere to the zipfile > format, you don't have any foolproof way to know if it's because the > file is corrupted or if it's just an appended comment. > > Most zipfile readers use a heuristic to distinguish. ?Python's zipfile > module just assumes it's corrupted. > > The following post from a while back gives a solution that tries to > snip the comment off so that zipfile module can handle it. ?It might > help you out. > > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > > Carl Banks Thanks Carl. I tried Scott's getzip() function yesterday... I stumbled upon it in my searches. It didn't seem to help in my case, though it did produce a different error: ValueError, substring not found. Not sure what that means. From againstmethod at gmail.com Fri Jan 9 10:11:59 2009 From: againstmethod at gmail.com (Rich Henry) Date: Fri, 9 Jan 2009 10:11:59 -0500 Subject: struct unpack to pre-allocated array? Message-ID: <329fe1530901090711w7bafbc1cyb2a014bbe5d9524e@mail.gmail.com> Is there any way to struct.unpack or struct.unpack_from into an existing array.array or similar structure? I am unpacking file data in a loop and i was hoping to find something that performs better than simply unpacking into a new tuple each iteration. Thanks in advance, Rich -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Fri Jan 9 10:12:32 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 08:12:32 -0700 Subject: why cannot assign to function call In-Reply-To: <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Message-ID: <49676960.3050802@strout.net> rurpy at yahoo.com wrote: >>> a = array (1,2,3) >>> b = a >>> a[1] = 4 >>> print b >>> >>> C, C++, VBA, Fortran, Perl: 1, 2, 3 >>> Python: 1, 4, 3 >> You are mistaken > > I don't think so. > See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 > The code I quoted there was tested. > In the C/C++ case, array-to-pointer coercion confuses > the issue so I embedded the array in a struct which > is more like an "object". No, that's cheating (IMHO). Structs used directly (rather than via pointers) are the odd beast, and while they're certainly possible in C, they are far from the normal idiom. And certainly embedding an array in a struct just to force it to be copied, avoiding the standard reference semantics, is an arbitrary trick. I never claimed that you *couldn't* have copy semantics in C; you can do almost anything you want in C (or C++). But the *normal* usage of an array is via a pointer, in which case the semantics are exactly the same as in Python, Java, REALbasic, .NET, etc. >(Keep in mind > my point was not to show the behavior of arrays, but to > show that several common languages *do not* use Python's > "*all* names are references" model -- though of course > this does not preclude their having some Python-like > assignments since they all have some way of doing > references.) Ah. OK then, I guess I missed you're point. You're absolutely right; many languages have both reference types and value types. Python is a bit unusual in that it has only reference types. I would have picked a different example to illustrate that, but it's true nonetheless. Best, - Joe From arkanes at gmail.com Fri Jan 9 10:14:35 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 09:14:35 -0600 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4866bea60901090714x296e38dwefa540beb28419a3@mail.gmail.com> On Fri, Jan 9, 2009 at 9:05 AM, webcomm wrote: > On Jan 9, 3:46 am, Carl Banks wrote: >> The zipfile format is kind of brain dead, you can't tell where the end >> of the file is supposed to be by looking at the header. If the end of >> file hasn't yet been reached there could be more data. To make >> matters worse, somehow zip files came to have text comments simply >> appended to the end of them. (Probably this was for the benefit of >> people who would cat them to the terminal.) >> >> Anyway, if you see something that doesn't adhere to the zipfile >> format, you don't have any foolproof way to know if it's because the >> file is corrupted or if it's just an appended comment. >> >> Most zipfile readers use a heuristic to distinguish. Python's zipfile >> module just assumes it's corrupted. >> >> The following post from a while back gives a solution that tries to >> snip the comment off so that zipfile module can handle it. It might >> help you out. >> >> http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 >> >> Carl Banks > > Thanks Carl. I tried Scott's getzip() function yesterday... I > stumbled upon it in my searches. It didn't seem to help in my case, > though it did produce a different error: ValueError, substring not > found. Not sure what that means. > -- > http://mail.python.org/mailman/listinfo/python-list > This is a ticket about another issue or 2 with invalid zipfiles that the zipfile module won't load, but that other tools will compensate for: http://bugs.python.org/issue1757072 From pruebauno at latinmail.com Fri Jan 9 10:14:48 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 9 Jan 2009 07:14:48 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On Jan 9, 8:48?am, Johannes Bauer wrote: > No - and I've not known there was a profiler yet have found anything > meaningful (there seems to be an profiling C interface, but that won't > get me anywhere). Is that a seperate tool or something? Could you > provide a link? > Thanks, > Kind regards, > Johannes It is part of the python standard library: http://docs.python.org/library/profile.html From jldunn2000 at googlemail.com Fri Jan 9 10:20:50 2009 From: jldunn2000 at googlemail.com (loial) Date: Fri, 9 Jan 2009 07:20:50 -0800 (PST) Subject: sftp with no password from python References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> Message-ID: <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> On 8 Jan, 18:49, Mike Hjorleifsson wrote: > On Jan 8, 10:39?am, loial wrote: > > > Is it possible to usesftpwithout a password from python? > > Yes you can use keys you preestablish between the server and client so > you dont need passwords, i do this on all my servers then lock off the > ability to accept passwords at all, this way no one can dictionary > attack my ssh servers. Thanks...do you have any python examples of using sftp? From ryandw at gmail.com Fri Jan 9 10:22:16 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:22:16 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> On Jan 9, 5:42?am, John Machin wrote: > And here's a little gadget that might help the diagnostic effort; it > shows the archive size and the position of all the "magic" PKnn > markers. In a "normal" uncommented archive, EndArchive_pos + 22 == > archive_size. I ran the diagnostic gadget... archive size is 69888 FileHeader at 0 CentralDir at 43796 EndArchive at 43846 From ryandw at gmail.com Fri Jan 9 10:29:05 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 07:29:05 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 10:14?am, "Chris Mellon" wrote: > This is a ticket about another issue or 2 with invalid zipfiles that > the zipfile module won't load, but that other tools will compensate > for: > > http://bugs.python.org/issue1757072 Hmm. That's interesting. Are there other tools I can use in a python script that are more forgiving? I am using the zipfile module only because it seems to be the most widely used. Are other options in python likely to be just as unforgiving? Guess I'll look and see... From joe at strout.net Fri Jan 9 10:30:46 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 08:30:46 -0700 Subject: why cannot assign to function call In-Reply-To: <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <49676DA6.3030600@strout.net> Aaron Brady wrote: > Possible compromise. You can think of functions as mutation-only. > You pass the object, and it gets a new (additional) name. The old > name doesn't go in. That's correct. The reference itself is passed in, not the variable (or expression) that held or generated the reference in the calling code. This is no different from, in C, passing an integer: void foo(int bar) { bar = 42; } int baz = 0; foo(baz); This doesn't change baz because, speaking precisely, baz wasn't passed to foo -- only the *value* of baz (i.e. 0) was passed to foo. Within foo, that value was stored in bar. Assigning a new value to bar does not affect foo. It's the exact same thing when the value happens to be a reference to an object: typedef SomeClass* SomeClassPtr; void foo(SomeClassPtr bar) { bar = new SomeClass(); } SomeClassPtr baz = NULL; foo(baz); Again, we're not passing baz into foo; we're passing the *value* of baz (i.e. NULL) into foo. That value is stored in bar within foo, and when we assign a new value (a reference to a freshly minted SomeClass object) into bar, of course it doesn't affect baz. > Regardless, IMO, references don't add any explanatory power; they just > make you feel cocky that you know what they are. Nonsense. They are the simple and clear explanation of what's going on. > M: If 'fun()' returned a reference, you would be able to assign to it. > m: You can't assign to it. > C: It doesn't return a reference. C is false because M is false (at least, in the way I believe you mean it). Or, more precisely, both M and m are nonsensical; what does it mean to "assign to a reference"? It makes no sense. What would it mean to assign to 42? You don't assign to references any more than you assign to integers or assign to strings or assign to None. Those are all values, and you don't assign to values -- you assign to variables. "Assign" means to give a new value to a variable, i.e. to let (or cause) a variable to have a new value. (Ye olde BASIC even used the LET keyword to indicate this, e.g. LET X = 42.) Speaking casually, we don't always make this distinction, but I think precision is needed here. So, I see two ways to make sense of your argument: M1: If 'fun()' returned a variable, you would be able to assign to it. m1: You can't assign to it. C1: It doesn't return a variable. This is true. (Technically, instead of variable, we should say "LValue" here -- there are things slightly more complex than simple variables that can serve as the left-hand side of an assignment. So replace "variable" with "lvalue" above if you prefer.) Or, the other way some may see it is: M2: If 'fun()' returned a reference, you might be able to mutate the object that refers to. m2: You can sometimes mutate the object it refers to. C2: 'fun()' returns a reference. This is true (though the logic is flawed, but fixable). > -- Why can't I assign to a function call? > -- Python variables are references only. > -- Ok, why can't I assign to a function call? You're right, "Python variables are references only" has nothing to do with it. In a language where the only data type were "integer", you wouldn't be able to assign to a function call either. You can't assign to a function call because a function call is not itself an lvalue, and it doesn't return an lvalue. That's just not something you can get for free from the type model; it's an extra feature that would have to be built into the language somehow, and Python doesn't have it. If assignment were an operator rather than a statement, and could be overridden in a class via some specially-named method -- or, for that matter, if the assignment statement looked for such a method when it finds an object reference on the left-hand side -- then any object could be an lvalue, and you COULD (in some cases) assign to the result of a function. But it's not and it doesn't. Best, - Joe From nick at craig-wood.com Fri Jan 9 10:31:16 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 09 Jan 2009 09:31:16 -0600 Subject: Extending Python with C or C++ References: <49626d4d$0$31340$9b4e6d93@newsspool4.arcor-online.net> <6sjcksF6574qU1@mid.individual.net> <6smrejF74ss9U1@mid.individual.net> Message-ID: Thomas Heller wrote: > Nick Craig-Wood schrieb: > > Thomas Heller wrote: > >> Nick Craig-Wood schrieb: > >> > Interesting - I didn't know about h2xml and xml2py before and I've > >> > done lots of ctypes wrapping! Something to help with the initial > >> > drudge work of converting the structures would be very helpful. > >> > > >> > ( http://pypi.python.org/pypi/ctypeslib/ ) > >> > > >> > I gave it a quick go and it worked fine. I had to edit the XML in one > >> > place to make it acceptable (removing a u from a hex number). > >> > >> If you are using a recent version of gccxml, then you should use the > >> ctypeslib-gccxml-0.9 branch of ctypeslib instead of the trunk. (I should > >> really merge the gccxml-0.9 branch into the trunk;-) > >> > >> If you are already using the branch and the XML file is not accepted, > >> then could you please provide a short C code snippet that reproduces > >> the problem so that I can fix it? > > > > I'm using gccxml from debian testing 0.9.0+cvs20080525-1 which I guess > > doesn't have the code from the branch in. > > I meant the branch in the repository where ctypeslib lives in. > Anyway, it doesn't matter anymore since I merged that branch > into the ctypeslib trunk. > > Now the problem with the 'u' suffix that you mentioned should be fixed, and > I also made a quick change so that the sized integer types from stdint.h are generated > correctly. So, please update your ctypeslib installation and trey again;-) I gave it a go and I can report success on both counts! Well done and thank you. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From rurpy at yahoo.com Fri Jan 9 10:33:27 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 07:33:27 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <5f85a3a8-e718-475d-9bb1-238bb61b5018@x16g2000prn.googlegroups.com> On Jan 9, 6:48 am, Johannes Bauer wrote: > mk schrieb: > > The factor of 30 indeed does not seem right -- I have done somewhat > > similar stuff (calculating Levenshtein distance [edit distance] on words > > read from very large files), coded the same algorithm in pure Python and > > C++ (using linked lists in C++) and Python version was 2.5 times slower. > > Yup, that was about what I had expected (and what I could well live > with, it's a tradeoff). The rule-of-thumb I use is that Python is generally 5 to 50 times slower than C. It is considered blasphemy to say it in this group, but Python is slow. It does of course have many compensating advantages that make using it advantageous when runtime speed is not of primary importance. From google at mrabarnett.plus.com Fri Jan 9 10:34:17 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 15:34:17 +0000 Subject: Implementing file reading in C/Python In-Reply-To: <6sone1F7bavsU5@mid.uni-berlin.de> References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: <49676E79.1000709@mrabarnett.plus.com> Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: > >> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >> thing in C also: > > Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: > > #!/usr/bin/env python > from __future__ import division, with_statement > import os > import sys > from collections import defaultdict > from functools import partial > from itertools import imap > > > def iter_max_values(blocks, block_count): > for i, block in enumerate(blocks): > histogram = defaultdict(int) > for byte in block: > histogram[byte] += 1 > > yield max((count, byte) > for value, count in histogram.iteritems())[1] > [snip] Would it be faster if histogram was a list initialised to [0] * 256? From googler.1.webmaster at spamgourmet.com Fri Jan 9 10:49:21 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 07:49:21 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: Hi! I didn't wanted to post 11.000 Lines here, so I uploaded it here: http://rapidshare.com/files/181425216/config.log.html From jcd at sdf.lonestar.org Fri Jan 9 10:50:15 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 09 Jan 2009 10:50:15 -0500 Subject: Creating new instances of subclasses. In-Reply-To: References: <0ce2fa20-a37d-4f7c-b3ce-8c62b5037581@s20g2000yqh.googlegroups.com> Message-ID: <1231516215.31282.29.camel@aalcdl07.lib.unc.edu> Thanks for the solutions everyone! I'm not sure which I'll end up using, but I think I've got a better grasp of the problem now. Cool stuff. Cheers, Cliff On Thu, 2009-01-08 at 06:52 -0800, Paul McGuire wrote: > On Jan 7, 12:00 pm, Paul McGuire wrote: > > On Jan 7, 10:38 am, "J. Cliff Dyer" wrote: > > > > > I want to be able to create an object of a certain subclass, depending > > > on the argument given to the class constructor. > > > > > I have three fields, and one might need to be a StringField, one an > > > IntegerField, and the last a ListField. But I'd like my class to > > > delegate to the proper subclass automatically, so I can just do: > > > > > >>> f1 = Field('abc') > > > >>> f2 = Field('123') > > > >>> f3 = Field('D,E,F') > > > > O-O is not always the solution to every problem. Since inheritance is > > getting in your way, try using a class-level factory method. Instead > > of using the Field constructor, use a staticmethod of Field, something > > like: > > > > @staticmethod > > def make_Field(a) > > if is_list(a): > > return ListField(a) > > elif is_integer(a): > > return IntegerField(a) > > else: > > return StringField(a) > > > > and then get rid of all those __new__ methods, too. > > > > -- Paul > > After looking this over a bit more, I decided I didn't like make_Field > having to know the criteria for creating the different subclasses, but > wanted to put the smarts into the subclasses themselves. Here is an > excerpt that shows this working: > > class Field(object): > def __init__(self, input): > super(Field, self).__init__(input) > self.data = input > > @staticmethod > def make_Field(a): > subs = (ListField, IntegerField, StringField) > ret = None > for cls in subs: > try: > ret = cls(a) > except TypeError: > continue > else: > break > return ret > > class IntegerField(Field): > def __new__(cls, a): > if not is_integer(a): > raise TypeError() > return Field.__new__(cls, a) > > ... > ListField has a similar __new__ method, and StringField just creates > the object, with no validation. > > make_Field still has to know what order to list the subclasses in > (StringField is the most permissive, and so must come last in the list > of subclasses), but the specific type tests are moved into the > subclasses, which is a more appropriate place I think. > > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From chardish at gmail.com Fri Jan 9 11:14:16 2009 From: chardish at gmail.com (Evan Jones) Date: Fri, 9 Jan 2009 11:14:16 -0500 Subject: Guaranteeing an n-byte data type? Message-ID: Hello all, I'm trying to use sockets to implement a pre-defined network protocol that requires that I send messages of exactly a certain number of bytes. In Python, integer values are represented as 4 bytes each (AFAIK.) However I don't want to always send 4 bytes: sometimes I want to send one byte, or 11 bytes, or 33 bytes, or any other permutation that's not a multiple of 4. It seems to make the most sense to use one-byte data members and concatenate them before sending. This is reasonably easy in C (thanks to the uint8_t data type), but with Python I'm not sure how I'd implement it. The send() method in the socket module will take any kind of data, but you can't specify the number of bytes you want to send, so there's no guarantee as to how many you're actually sending (particularly if you're sending a value that's regarded in Python as a long integer - who knows how that data is actually represented in memory behind the scenes!) Perhaps since I'm trying to perform low-level operations, Python is simply the wrong tool for this job. However, I'd very much like to write this implementation in Python for sake of quick implementation and testing. Cheers, Evan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 9 11:42:16 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 11:42:16 -0500 Subject: why cannot assign to function call In-Reply-To: <49676DA6.3030600@strout.net> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <49676DA6.3030600@strout.net> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> Possible compromise. You can think of functions as mutation-only. >> You pass the object, and it gets a new (additional) name. The old >> name doesn't go in. > > That's correct. The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. > > This is no different from, in C, passing an integer: > > void foo(int bar) { > bar = 42; > } > int baz = 0; > foo(baz); > > This doesn't change baz because, speaking precisely, baz wasn't passed > to foo -- only the *value* of baz (i.e. 0) was passed to foo. Within > foo, that value was stored in bar. Assigning a new value to bar does > not affect foo. > > It's the exact same thing when the value happens to be a reference to an > object: > > typedef SomeClass* SomeClassPtr; > void foo(SomeClassPtr bar) { > bar = new SomeClass(); > } > SomeClassPtr baz = NULL; > foo(baz); > > Again, we're not passing baz into foo; we're passing the *value* of baz > (i.e. NULL) into foo. That value is stored in bar within foo, and when > we assign a new value (a reference to a freshly minted SomeClass object) > into bar, of course it doesn't affect baz. > >> Regardless, IMO, references don't add any explanatory power; they just >> make you feel cocky that you know what they are. > > Nonsense. They are the simple and clear explanation of what's going on. > >> M: If 'fun()' returned a reference, you would be able to assign to it. >> m: You can't assign to it. >> C: It doesn't return a reference. > > C is false because M is false (at least, in the way I believe you mean > it). Or, more precisely, both M and m are nonsensical; what does it > mean to "assign to a reference"? It makes no sense. What would it mean > to assign to 42? > > You don't assign to references any more than you assign to integers or > assign to strings or assign to None. Those are all values, and you > don't assign to values -- you assign to variables. "Assign" means to > give a new value to a variable, i.e. to let (or cause) a variable to > have a new value. (Ye olde BASIC even used the LET keyword to indicate > this, e.g. LET X = 42.) Speaking casually, we don't always make this > distinction, but I think precision is needed here. > > So, I see two ways to make sense of your argument: > > M1: If 'fun()' returned a variable, you would be able to assign to it. > m1: You can't assign to it. > C1: It doesn't return a variable. > > This is true. (Technically, instead of variable, we should say "LValue" > here -- there are things slightly more complex than simple variables > that can serve as the left-hand side of an assignment. So replace > "variable" with "lvalue" above if you prefer.) > > Or, the other way some may see it is: > > M2: If 'fun()' returned a reference, you might be able to mutate the > object that refers to. > m2: You can sometimes mutate the object it refers to. > C2: 'fun()' returns a reference. > > This is true (though the logic is flawed, but fixable). > >> -- Why can't I assign to a function call? >> -- Python variables are references only. >> -- Ok, why can't I assign to a function call? > > You're right, "Python variables are references only" has nothing to do > with it. In a language where the only data type were "integer", you > wouldn't be able to assign to a function call either. > > You can't assign to a function call because a function call is not > itself an lvalue, and it doesn't return an lvalue. That's just not > something you can get for free from the type model; it's an extra > feature that would have to be built into the language somehow, and > Python doesn't have it. > > If assignment were an operator rather than a statement, and could be > overridden in a class via some specially-named method -- or, for that > matter, if the assignment statement looked for such a method when it > finds an object reference on the left-hand side -- then any object could > be an lvalue, and you COULD (in some cases) assign to the result of a > function. But it's not and it doesn't. > Pretty soon you guys will have me believing Python doesn't work ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 11:43:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jan 2009 16:43:39 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <01777574$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 08:30:46 -0700, Joe Strout wrote: > That's correct. The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. > > This is no different from, in C, passing an integer: > > void foo(int bar) { > bar = 42; > } > int baz = 0; > foo(baz); > > This doesn't change baz because, speaking precisely, baz wasn't passed > to foo -- only the *value* of baz (i.e. 0) was passed to foo. We can check whether bar and baz are the same thing, by printing their addresses: #include void foo(int bar) { printf("\n The address of bar is %p ", &bar); bar = 42; } int main() { int baz = 0; printf("\n The address of baz is %p ", &baz); foo(baz); return 0; } When I do this, I get: The address of baz is 0xbfa72870 The address of bar is 0xbfa72850 So we can agree that baz and bar are different entities. Now, would anyone like to take a small wager on what the equivalent code in CPython would print? def foo(bar): print " The address of bar is %s " % id(bar) bar = 42 baz = 0 print " The address of baz is %s " % id(baz) foo(baz) When I execute this, I get The address of baz is 143599468 The address of bar is 143599468 Python doesn't do the same thing as C. It actually passes the same value to the function, without copying it. Why oh why do you keep insisting that Python is no different from C? Let's try one more. In C: #include #include struct record { int x; }; void mutate(struct record bar) { printf("\n The address of bar is %p ", &bar); bar.x = 0; printf("\n Inside: %d ", bar.x); } struct record baz; int main(void) { baz.x = 1; printf("\n The address of baz is %p ", &baz); printf("\n Before: %d ", baz.x); mutate(baz); printf("\n After: %d ", baz.x); return 0; } gives output: The address of baz is 0x80496fc Before: 1 The address of bar is 0xbfb8f980 Inside: 0 After: 1 We can clearly see that baz and bar are different entities, and changes made to bar inside the function don't affect baz. A Python equivalent: class struct: pass def mutate(bar): print " The address of bar is %d " % id(bar) bar.x = 0; print " Inside: %d " % bar.x baz = struct() baz.x = 1 print " The address of baz is %d " % id(baz) print " Before: %d " % baz.x mutate(baz) print " After: %d " % baz.x which gives output: The address of baz is 3085537420 Before: 1 The address of bar is 3085537420 Inside: 0 After: 0 Why oh why do you keep insisting that Python is no different from C? -- Steven From google at mrabarnett.plus.com Fri Jan 9 11:45:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 16:45:04 +0000 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: <49677F10.3070907@mrabarnett.plus.com> Evan Jones wrote: > Hello all, > > I'm trying to use sockets to implement a pre-defined network protocol > that requires that I send messages of exactly a certain number of bytes. > In Python, integer values are represented as 4 bytes each (AFAIK.) > However I don't want to always send 4 bytes: sometimes I want to send > one byte, or 11 bytes, or 33 bytes, or any other permutation that's not > a multiple of 4. It seems to make the most sense to use one-byte data > members and concatenate them before sending. > > This is reasonably easy in C (thanks to the uint8_t data type), but with > Python I'm not sure how I'd implement it. The send() method in the > socket module will take any kind of data, but you can't specify the > number of bytes you want to send, so there's no guarantee as to how many > you're actually sending (particularly if you're sending a value that's > regarded in Python as a long integer - who knows how that data is > actually represented in memory behind the scenes!) > > Perhaps since I'm trying to perform low-level operations, Python is > simply the wrong tool for this job. However, I'd very much like to write > this implementation in Python for sake of quick implementation and testing. > The send() method takes a bytestring argument (class "str" in Python 2.x, class "bytes" in Python 3.x), which is a string of 8-bit characters (1 byte per character). Just build your bytestring and then send it (actually it's better to use sendall() because send() isn't guaranteed to send all the bytes in one call). From steve at holdenweb.com Fri Jan 9 11:46:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 11:46:52 -0500 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: Evan Jones wrote: > Hello all, > > I'm trying to use sockets to implement a pre-defined network protocol > that requires that I send messages of exactly a certain number of bytes. > In Python, integer values are represented as 4 bytes each (AFAIK.) > However I don't want to always send 4 bytes: sometimes I want to send > one byte, or 11 bytes, or 33 bytes, or any other permutation that's not > a multiple of 4. It seems to make the most sense to use one-byte data > members and concatenate them before sending. > > This is reasonably easy in C (thanks to the uint8_t data type), but with > Python I'm not sure how I'd implement it. The send() method in the > socket module will take any kind of data, but you can't specify the > number of bytes you want to send, so there's no guarantee as to how many > you're actually sending (particularly if you're sending a value that's > regarded in Python as a long integer - who knows how that data is > actually represented in memory behind the scenes!) > > Perhaps since I'm trying to perform low-level operations, Python is > simply the wrong tool for this job. However, I'd very much like to write > this implementation in Python for sake of quick implementation and testing. > In Python 2 you'd use an 8-bit string - though as you surmise you need access to the conversions to and from the primitive data types. This is provided by the struct module. In Python 3 you'll use a bytes object; in 2.6 and onwards the bytes syntax can be used to refer to regular strings, to make portability easier (in Python 3, strings are Unicode by default). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From invalid at invalid Fri Jan 9 11:56:44 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 10:56:44 -0600 Subject: Guaranteeing an n-byte data type? References: Message-ID: Evan Jones wrote: > I'm trying to use sockets to implement a pre-defined network > protocol that requires that I send messages of exactly a > certain number of bytes. In Python, integer values are > represented as 4 bytes each (AFAIK.) However I don't want to > always send 4 bytes: sometimes I want to send one byte, or 11 > bytes, or 33 bytes, or any other permutation that's not a > multiple of 4. It seems to make the most sense to use one-byte > data members and concatenate them before sending. In addition to previous suggestions, you should look at the "struct" and "ctypes" modules in the standard Python library. Both allow you to pack/unpack data to/from data structures with arbitrary layout and endianness. -- Grant Edwards grante Yow! I'm meditating on at the FORMALDEHYDE and the visi.com ASBESTOS leaking into my PERSONAL SPACE!! From ryandw at gmail.com Fri Jan 9 11:58:14 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 08:58:14 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 10:14?am, "Chris Mellon" wrote: > This is a ticket about another issue or 2 with invalid zipfiles that > the zipfile module won't load, but that other tools will compensate > for: > > http://bugs.python.org/issue1757072 Looks like I just need to do this to unzip with unix... from os import popen popen("unzip data.zip") That works for me. No idea why I didn't think of that earlier. I'm new to python but should have realized I could run unix commands with python. I had blinders on. Now I just need to get rid of some bad characters in the unzipped file. I'll start a new thread if I need help with that... From invalid at invalid Fri Jan 9 11:59:41 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 10:59:41 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On 2009-01-09, Johannes Bauer wrote: > I've come from C/C++ and am now trying to code some Python because I > absolutely love the language. However I still have trouble getting > Python code to run efficiently. Right now I have a easy task: Get a > file, If I were you, I'd try mmap()ing the file instead of reading it into string objects one chunk at a time. -- Grant Edwards grante Yow! I'm DESPONDENT ... I at hope there's something visi.com DEEP-FRIED under this miniature DOMED STADIUM ... From wesbrooks at gmail.com Fri Jan 9 12:06:28 2009 From: wesbrooks at gmail.com (Wesley Brooks) Date: Fri, 9 Jan 2009 17:06:28 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: I missed the begining of this thread and so appologise if I'm repeating what someone else has said! I had a very similar problem with this error and it turned out it was due to me moving a file across a socket connection and either not reading it or writing it in the binary mode, ie open(filename, 'rb') or write(filename, 'wb'). This didn't make any difference on the linux machines (where the error didn't occur) but did on the windows machines and fixed the problem. Cheers, Wes On 09/01/2009, webcomm wrote: > > On Jan 9, 10:14 am, "Chris Mellon" wrote: > > This is a ticket about another issue or 2 with invalid zipfiles that > > the zipfile module won't load, but that other tools will compensate > > for: > > > > http://bugs.python.org/issue1757072 > > Looks like I just need to do this to unzip with unix... > > from os import popen > popen("unzip data.zip") > > That works for me. No idea why I didn't think of that earlier. I'm > new to python but should have realized I could run unix commands with > python. I had blinders on. Now I just need to get rid of some bad > characters in the unzipped file. I'll start a new thread if I need > help with that... > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Fri Jan 9 12:13:03 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 9 Jan 2009 09:13:03 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Johannes Bauer, I was about to start writing a faster version. I think with some care and Psyco you can go about as 5 times slower than C or something like that. To do that you need to use almost the same code for the C version, with a list of 256 ints for the frequencies, not using max() but a manual loop, not using itertools or generators, maybe splitting code in two functions to allow Psyco to optimize better, maybe using another array("...") for the frequences too. The data can be read into an array.array("B"), and so on. But I think all this work is a waste of time. I like Python, but that C code, after some cleaning and polishing looks fine for this job. Of course there are other languages that may give you a little nicer code for this program, like D, and there may be ways to use numpy too to speed up the computation of the mode, but they don't look so much important this time. Bye, bearophile From p at ulmcnett.com Fri Jan 9 12:16:35 2009 From: p at ulmcnett.com (Paul McNett) Date: Fri, 09 Jan 2009 09:16:35 -0800 Subject: Unexpected scientific notation In-Reply-To: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> Message-ID: <49678673.5000003@ulmcnett.com> Mark Dickinson wrote: > On Jan 8, 1:00 am, Paul McNett wrote: >> It displays '3E+1' instead of '30.0'. >> >> As I can't reproduce I'm looking for an idea brainstorm of what could be causing >> this. What would be choosing to display such a normal number in scientific notation? >> >> Ideas? > > [I thought I replied to this earlier, but the post isn't showing up. > So here it is again.] LOL! > I suspect it's your use of the Decimal normalize() method that's > causing > this. Trailing zeros on Decimal instances are significant, so > Decimal('30.0'), Decimal('30') and Decimal('3E+1') are considered > distinct (though they all have the same value). The normalize method > strips all trailing zeros, turning Decimal('30.0') into Decimal('3E > +1'). > > One way to get around this is to add 0 after normalizing: this will > make sure that scientific notation is used only for very large > or small numbers, as usual. Thank you for the insight. I believe the problem is with my use of normalize(), but I still can't figure out why I can't reproduce the issue in my running app. But I can see in the interpreter that printing Decimal("30.0").normalize() results in "3E+1". Paul From concat_names at hotmail.com Fri Jan 9 12:17:08 2009 From: concat_names at hotmail.com (Aivar Annamaa) Date: Fri, 09 Jan 2009 19:17:08 +0200 Subject: Problem with -3 switch Message-ID: Hi I'm getting started with Python and in order to get good habits for Python 3, i'd like to run my Python 2.6.1 with Python 3 warning mode. When i run python -3 and execute statement >>> print 4 then i expect to see a warning because i've understood that this statement is not valid in Python 3 however no warning appears. Have is misunderstood something? I'm running Python on Windows Vista. thanks in advance! Aivar From a.bilgin.a at gmail.com Fri Jan 9 12:19:43 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Fri, 9 Jan 2009 19:19:43 +0200 Subject: Python Imaging Library and textmate Message-ID: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> Hi Philip, I tried to install PIL with the directions given and it seemed to be ok. When I tried it with IDLE, import Image did not give an error and as far as I checked it seemed to be working. However, importing Image module in TextMate gives an error, saying that the module cannot be found for some strange reason. The code simply contains the line *"import Image"* in both cases On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: >* Hello, *>* I am a beginner in python and I am trying to create image files that *>* contain *>* lines from a text file. *>* I am trying to do this with PIL, which seems like a suitable tool. I *>* have a *>* copy of TextMate(1.5.8) and I run Macosx 10.5.6 *>* *>* The problem is, even though I installed PIL correctly (I get no *>* errors from *>* "import Image" in IDLE or in terminal), I can't get TextMate to *>* import the *>* module. *>* I keep getting "ImportError: No module named Image" error. *>* I tried reloading TextMate's bundles but that did not work either. * I use TextMate but I don't know what you mean when you say you can't get TM to import a module. Can you give a little more context? >* There was a similar thread in this list with textmate but I can't *>* understand *>* how that issue was solved in the end. * link? bye Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 9 12:26:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 09:26:27 -0800 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: <50697b2c0901090926r10e1008ct35c80ea6ab0ef0c6@mail.gmail.com> On Fri, Jan 9, 2009 at 9:17 AM, Aivar Annamaa wrote: > Hi > > I'm getting started with Python and in order to get good habits for Python > 3, i'd like to run my Python 2.6.1 with Python 3 warning mode. > > When i run > python -3 > > and execute statement >>>> print 4 > > then i expect to see a warning because i've understood that this statement > is not valid in Python 3 > > however no warning appears. > > Have is misunderstood something? As was recently pointed out in a nearly identical thread, the -3 switch only points out problems that the 2to3 converter tool can't automatically fix. Changing print to print() on the other hand is easily fixed by 2to3. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From dickinsm at gmail.com Fri Jan 9 12:31:42 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 09:31:42 -0800 (PST) Subject: Unexpected scientific notation References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> Message-ID: On Jan 9, 5:16?pm, Paul McNett wrote: > Thank you for the insight. I believe the problem is with my use of normalize(), but I > still can't figure out why I can't reproduce the issue in my running app. Me neither. In particular, I can't see how it could this output could come out of a locale.format call. Is it possible that your user is somehow seeing a direct str() or "%s" of a Decimal instance, rather than something that's been through a format method? Mark From gh at ghaering.de Fri Jan 9 12:32:11 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 09 Jan 2009 18:32:11 +0100 Subject: Python Apache Handler In-Reply-To: References: Message-ID: Scooter wrote: > Does anyone have any good examples, or links thereto for using python > as an Apache handler? And I should qualify all of this by saying I'm a > python newbie, and while having experience with Apache, I've never > done anything outside whats "in the box" . > > What I'm looking for is how one might use Python not from the CGI/ > presentation side but more on the backend...i.e. for each page Apache > serves up examine the request and update some headers, or add a cookie > to the response. I vaguely remembered that mod_python can do such things. Looking again it seems to be the case: http://www.modpython.org/live/current/doc-html/pyapi-filter.html > Or possibly use Python for writing a custom Apache > logger. [...] Maybe http://www.modpython.org/live/current/doc-html/dir-handlers-plh.html The documentation about this is a joke, though. Remember that you can write custom Apache loggers quite easily with "piped logs": http://httpd.apache.org/docs/2.2/logs.html This looks roughly like this: CustomLog "|/path/to/my_script.py" common ## begin my_script.py ## import sys for line in sys.stdin: # do stuff ## end ## -- Gerhard From p at ulmcnett.com Fri Jan 9 12:38:36 2009 From: p at ulmcnett.com (Paul McNett) Date: Fri, 09 Jan 2009 09:38:36 -0800 Subject: Unexpected scientific notation In-Reply-To: <49678673.5000003@ulmcnett.com> References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> <49678673.5000003@ulmcnett.com> Message-ID: <49678B9C.9030009@ulmcnett.com> Paul McNett wrote: > Mark Dickinson wrote: >> On Jan 8, 1:00 am, Paul McNett wrote: >>> It displays '3E+1' instead of '30.0'. >>> >>> As I can't reproduce I'm looking for an idea brainstorm of what could >>> be causing >>> this. What would be choosing to display such a normal number in >>> scientific notation? >>> >>> Ideas? >> >> [I thought I replied to this earlier, but the post isn't showing up. >> So here it is again.] > > LOL! I'll clarify my LOL: Mark initially replied to me directly, to which I responded directly. Because he replied directly, I kept my response offline, too, not knowing if he had a special reason to discuss this offline instead of in public. Then he replied to the list, so I made a different response to the list. Anyway, thanks again Mark for your guidance. Paul From concat_names at hotmail.com Fri Jan 9 12:39:03 2009 From: concat_names at hotmail.com (Aivar Annamaa) Date: Fri, 09 Jan 2009 19:39:03 +0200 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: > As was recently pointed out in a nearly identical thread, the -3 > switch only points out problems that the 2to3 converter tool can't > automatically fix. Changing print to print() on the other hand is > easily fixed by 2to3. > > Cheers, > Chris > I see. So i gotta keep my own discipline with print() then :) thanks! A From siona at chiark.greenend.org.uk Fri Jan 9 12:41:29 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 09 Jan 2009 17:41:29 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: Grant Edwards wrote: >On 2009-01-09, Johannes Bauer wrote: >> I've come from C/C++ and am now trying to code some Python because I >> absolutely love the language. However I still have trouble getting >> Python code to run efficiently. Right now I have a easy task: Get a >> file, >If I were you, I'd try mmap()ing the file instead of reading it >into string objects one chunk at a time. You've snipped the bit further on in that sentence where the OP says that the file of interest is 2GB. Do you still want to try mmap'ing it? -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From ryandw at gmail.com Fri Jan 9 12:46:44 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 09:46:44 -0800 (PST) Subject: how to remove 'FFFD' character Message-ID: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> Does anyone know a way to remove the 'FFFD' character with python? You can see the browser output I'm dealing with here: http://webcomm.webfactional.com/htdocs/fffd.JPG I deleted a big chunk out of the middle of that JPG to protect sensitive data. I don't know what the character encoding of this data is and don't know what the 'FFFD' represents. I guess it is something that can't be represented in whatever this particular encoding is, or maybe it is something corrupt that can't be represented in any encoding. I just want to scrub it out. I tried this... clean = txt.encode('ascii','ignore') ...but the 'FFFD' still comes through. Other ideas? Thanks, Ryan From gh at ghaering.de Fri Jan 9 12:48:44 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 09 Jan 2009 18:48:44 +0100 Subject: Encrypted Logging in python In-Reply-To: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> References: <44091334-9cb8-41a1-a489-df31bc5cafc2@r15g2000prd.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > I was wondering if there is a mechanism to encrypt logging > automatically in python. Python's standard library doesn't include any "strong" symmetric ciphers. But if you include for example a cryptographic module for AES, for example, it should be easy (I guess 10 lines of code, yes, the issue always is *which* 10 lines) to write a custom logger that encrypts using a hardcoded key. As others have said, this is not really secure, so you could just as well use something stupid like rot13 or base64 instead. > The issue is as follows: > (a) An application (after py2exe) will go as executable and there > is no need for the user to know that it is written in python. If an > exception occurs and it is logged, then the user can understand it is > written in python. In 99.326 % of all cases, the answer is: so what? > (b) A security threat. If an exception occurs, the code is seen by > the user - and possibly be misused. Simply make the user not see the exception, but use a fallback exception handler that does whatever you want to. Write to a log file. Or write to an encrypted log file if you still think that helps. > Base64 encoding somewhat helps - which is supported by logging > module - but even that is not very secure. If there can be an option - > wherein we send in the password and the logging is encrypted - it > might be better. [...] As I said before, that should be trivial to program if you look up the documentation about the logging module. Just subclass FileHandler. And make sure your class is then used. That's probably the hardest part ;-) That all being said, I have one final advise: Your time is probably much better spent on *real* issues. -- Gerhard From philip at semanchuk.com Fri Jan 9 12:53:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 9 Jan 2009 12:53:35 -0500 Subject: Python Imaging Library and textmate In-Reply-To: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> References: <55460f80901090919hcbfb5f2tb5a710a8ab2c4650@mail.gmail.com> Message-ID: <0432ACB4-1255-4046-B816-46F5D124C3C1@semanchuk.com> On Jan 9, 2009, at 12:19 PM, bilgin arslan wrote: > Hi Philip, > I tried to install PIL with the directions given and it seemed to be > ok. > > When I tried it with IDLE, import Image did not give an error and as > far as I checked it seemed to be working. > However, importing Image module in TextMate gives an error, saying > that the module cannot be found for some strange reason. I am still unclear on how you're importing Python modules via TextMate. It's a text editor, so even though I've used it for a couple of years, it's not at all obvious to me how you'd use it to import a Python module. I think I can help you, but to do so I need you to tell me *exactly* what menu items you're clicking on, e.g. "Bundle/Python/ Run Script..." > The code simply contains the line *"import Image"* in both cases From what I can see in the PIL documentation, this wouldn't work. You'd need either this: from PIL import Image or this: import PIL.Image What am I missing? > On Jan 9, 2009, at 2:49 AM, bilgin arslan wrote: > >> * Hello, > *>* I am a beginner in python and I am trying to create image files > that > *>* contain > *>* lines from a text file. > *>* I am trying to do this with PIL, which seems like a suitable > tool. I > *>* have a > *>* copy of TextMate(1.5.8) and I run Macosx 10.5.6 > *>* > *>* The problem is, even though I installed PIL correctly (I get no > *>* errors from > *>* "import Image" in IDLE or in terminal), I can't get TextMate to > *>* import the > *>* module. > *>* I keep getting "ImportError: No module named Image" error. > *>* I tried reloading TextMate's bundles but that did not work either. > * > I use TextMate but I don't know what you mean when you say you can't > get TM to import a module. Can you give a little more context? > > >> * There was a similar thread in this list with textmate but I can't > *>* understand > *>* how that issue was solved in the end. > * > link? > > > > bye > Philip > -- > http://mail.python.org/mailman/listinfo/python-list From chardish at gmail.com Fri Jan 9 13:12:18 2009 From: chardish at gmail.com (Evan Jones) Date: Fri, 9 Jan 2009 13:12:18 -0500 Subject: Guaranteeing an n-byte data type? In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 11:56 AM, Grant Edwards wrote: > In addition to previous suggestions, you should look at the > "struct" and "ctypes" modules in the standard Python library. > Both allow you to pack/unpack data to/from data structures with > arbitrary layout and endianness. > > Thank you, everyone. struct appears to be exactly what I want; combined with MRAB's insight into how socket.send() works, I feel I should be able to code this in at around 25% the length of equivalent C code. Cheers, Evan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Jan 9 13:13:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 13:13:37 -0500 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: Aivar Annamaa wrote: >> As was recently pointed out in a nearly identical thread, the -3 >> switch only points out problems that the 2to3 converter tool can't >> automatically fix. Changing print to print() on the other hand is >> easily fixed by 2to3. >> >> Cheers, >> Chris >> > > I see. > So i gotta keep my own discipline with print() then :) > Only if you don't want to run your 2.x code through 2to3 before you use it as Python 3.x code. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Fri Jan 9 13:32:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 09 Jan 2009 10:32:54 -0800 Subject: BadZipfile "file is not a zip file" In-Reply-To: References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: webcomm wrote: > .... I tried Scott's getzip() function yesterday... I > stumbled upon it in my searches. It didn't seem to help in my case, > though it did produce a different error: ValueError, substring not > found. Not sure what that means. and in another message webcomm wrote: > I ran the diagnostic gadget... > > archive size is 69888 > FileHeader at 0 > CentralDir at 43796 > EndArchive at 43846 This is telling you that the archive ends at 43846, but the file is 69888 bytes long (69888 - 43846 = 26042 post-archive bytes). Have you tried calling getzip(filename, ignoreable=30000)? The whole point of the function is to ignore the nasty stuff at the end, but if _I_ had a file with more than 25K of post-archive bytes, I'd certainly try to figure out if the archive was mis-handled somewhere along the way. Byt the way, one reason you cannot find the archive by looking at the start of the file is that the zip file format is meant to allow you to append a zip file to another file (such as an executable) and treat the combination as an archive. --Scott David Daniels Scott.Daniels at Acm.Org From jcd at sdf.lonestar.org Fri Jan 9 13:36:59 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 09 Jan 2009 13:36:59 -0500 Subject: Problem with -3 switch In-Reply-To: References: Message-ID: <1231526219.1464.7.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > Aivar Annamaa wrote: > >> As was recently pointed out in a nearly identical thread, the -3 > >> switch only points out problems that the 2to3 converter tool can't > >> automatically fix. Changing print to print() on the other hand is > >> easily fixed by 2to3. > >> > >> Cheers, > >> Chris > >> > > > > I see. > > So i gotta keep my own discipline with print() then :) > > > Only if you don't want to run your 2.x code through 2to3 before you use > it as Python 3.x code. > > regards > Steve And mind you, if you follow that route, you are programming in a mightily crippled language. It's about as bad as trying to write cross-browser CSS. Don't put yourself through that pain if you don't have to. From vginer at gmail.com Fri Jan 9 13:41:37 2009 From: vginer at gmail.com (Vicent) Date: Fri, 9 Jan 2009 19:41:37 +0100 Subject: Where's Psyco now? Message-ID: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Hello. This is my first message to the list. In this article written in 2002 http://www.ibm.com/developerworks/library/l-psyco.html they talk about Psyco as a module that makes it possible to accelerate Python. Is it still a state-of-the-art module? I found it here also: http://pypi.python.org/pypi/psyco/1.6 Do you think it's useful, or it depends...? -- Vicent Giner-Bosch, Valencia, Spain -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Jan 9 13:43:28 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:43:28 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> Message-ID: On Jan 8, 7:25?am, J Kenneth King wrote: > Jonathan Gardner writes: > > It seems we're defining "DSL" in two different ways. > > You can't write a DSL in Python because you can't change the syntax and > you don't have macros. > > You can write a compiler in Python that will compile your "DSL." > Yes, that's what I'm saying. You can get the same results even thought you can't manipulate the Python language itself as it's compiling Python because you can feed it Python code that you've generated. > As another poster mentioned, eventually PyPy will be done and then > you'll get more of an "in-Python" DSL. Of course, such a language wouldn't be Python anymore because Python doesn't have such features. From jgardner at jonathangardner.net Fri Jan 9 13:45:55 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:45:55 -0800 (PST) Subject: looking for tips on how to implement "ruby-style" Domain Specific Language in Python References: <6973aa60-5da4-41a6-85f1-ed93ee851580@q26g2000prq.googlegroups.com> <68d3e5a5-9245-49bf-8854-705640a21f00@35g2000pry.googlegroups.com> <85zli4qj1w.fsf@dozer.localdomain> <9eeaf133-5467-453a-b482-015da71a037a@l33g2000pri.googlegroups.com> <85vdsrqfmn.fsf@dozer.localdomain> <68bb349e-0c3f-4e4e-a719-9f0be7a180f9@f40g2000pri.googlegroups.com> <85hc49vmyj.fsf@dozer.localdomain> <1c8ee30a-05c6-48b8-91e9-4ebd10e1b2a0@k1g2000prb.googlegroups.com> Message-ID: On Jan 8, 8:03?am, Kay Schluehr wrote: > On 8 Jan., 16:25, J Kenneth King wrote: > > > As another poster mentioned, eventually PyPy will be done and then > > you'll get more of an "in-Python" DSL. > > May I ask why you consider it as important that the interpreter is > written in Python? I see no connection between PyPy and syntactical > Python extensions and the latter isn't an objective of PyPy. You can > write Python extensions with virtually any Python aware parser. > M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then > there is ANTLR which provides a Python grammar. I also know about two > other Python aware parsers. One of them was written by myself. If you're going to manipulate the Python compiler/interpreter from the Python program itself, it's only reasonable that the Python compiler/ interpreter be written in Python so that it can be manipulated. If you haven't already made it through SICP, you really should. It will help you understand why being able to write a language in itself is a big deal and why having the language around to be manipulated from within the language is very useful. From jgardner at jonathangardner.net Fri Jan 9 13:50:01 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 9 Jan 2009 10:50:01 -0800 (PST) Subject: Measuring bytes of packet sent from python application References: <49628901$0$90271$14726298@news.sunsite.dk> <78f224ae-34b1-472b-a298-29048688e227@g39g2000pri.googlegroups.com> <4962965f$0$90276$14726298@news.sunsite.dk> Message-ID: <02c701b5-68a1-476d-9885-ba2dab406b58@k1g2000prb.googlegroups.com> On Jan 5, 6:08?pm, Grant Edwards wrote: > On 2009-01-05, Kangkook Jee wrote: > > I'm still struggling to solve it within python process since > > it looks cleaner but it doesn't seems to be easy at all. > > I don't why adding bunches of code to your app would be > "cleaner" than gathering data using external programs. > Those external programs may not be available on all the platforms he might want to run in. Or he may have some specific requirements that those tools can't satisfy. Software reuse is wonderful when it works. But it doesn't work all the time, even though it probably should. From carsten.haese at gmail.com Fri Jan 9 14:12:44 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 09 Jan 2009 14:12:44 -0500 Subject: how to remove 'FFFD' character In-Reply-To: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> References: <284e37fb-41f9-43f7-adfa-ed7ecb0f6f85@s9g2000prm.googlegroups.com> Message-ID: webcomm wrote: > I don't know what the character encoding of this data is and don't > know what the 'FFFD' represents. The codepoint 0xFFFD is the so-called 'REPLACEMENT CHARACTER'. It is used replace an incoming character whose value is unknown or unrepresentable in Unicode. The browser might display these if for example a page is encoded in latin-1 but it claims to be utf-8, so the byte stream will contain byte sequences that can't be decoded into unicode code points. > I just > want to scrub it out. I tried this... > > clean = txt.encode('ascii','ignore') > > ...but the 'FFFD' still comes through. You must be doing something wrong, then: py> u'Hello,\ufffd World'.encode('ascii', 'ignore') 'Hello, World' HTH, -- Carsten Haese http://informixdb.sourceforge.net From dickinsm at gmail.com Fri Jan 9 14:14:31 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 9 Jan 2009 11:14:31 -0800 (PST) Subject: Unexpected scientific notation References: <25c87218-8c88-4e6e-aa91-ff324e6f100e@t39g2000prh.googlegroups.com> <49678673.5000003@ulmcnett.com> Message-ID: <309bbdb9-ea6d-4da3-a5df-78ebe1267f58@t39g2000prh.googlegroups.com> On Jan 9, 5:38?pm, Paul McNett wrote: > I'll clarify my LOL: Mark initially replied to me directly, to which I responded > directly. Because he replied directly, I kept my response offline, too, not knowing > if he had a special reason to discuss this offline instead of in public. Yup, definitely a special reason. Nothing to do with being unable to distinguish between 'Reply' and 'Reply to author'. Honest. Mark From jmazzonelli at gmail.com Fri Jan 9 14:17:50 2009 From: jmazzonelli at gmail.com (Jorge Mazzonelli) Date: Fri, 9 Jan 2009 17:17:50 -0200 Subject: sftp with no password from python In-Reply-To: <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> References: <3758a059-c44c-4369-8a13-483a8be0cf42@f40g2000pri.googlegroups.com> <1d82b651-c063-4b28-b226-2518046f9f93@z28g2000prd.googlegroups.com> <575effdf-663a-4100-b2e9-f60705e0e651@g39g2000pri.googlegroups.com> Message-ID: <138a70320901091117h76c8944epfbe017bbf3b77d19@mail.gmail.com> You should try the paramiko package for that (http://www.lag.net/paramiko/) A google search on that package & SFTP got me this example: http://commandline.org.uk/python/sftp-python/ Cheers Jorge On Fri, Jan 9, 2009 at 1:20 PM, loial wrote: > On 8 Jan, 18:49, Mike Hjorleifsson wrote: > > On Jan 8, 10:39 am, loial wrote: > > > > > Is it possible to usesftpwithout a password from python? > > > > Yes you can use keys you preestablish between the server and client so > > you dont need passwords, i do this on all my servers then lock off the > > ability to accept passwords at all, this way no one can dictionary > > attack my ssh servers. > > Thanks...do you have any python examples of using sftp? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- (\__/) (='.'=)This is Bunny. Copy and paste bunny into your (")_(")signature to help him gain world domination. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 9 14:21:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 11:21:28 -0800 Subject: Where's Psyco now? In-Reply-To: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: <50697b2c0901091121u523a506ei40c62d4bce5be107@mail.gmail.com> On Fri, Jan 9, 2009 at 10:41 AM, Vicent wrote: > Hello. This is my first message to the list. > > In this article written in 2002 > > http://www.ibm.com/developerworks/library/l-psyco.html > > they talk about Psyco as a module that makes it possible to accelerate > Python. > > Is it still a state-of-the-art module? > > I found it here also: http://pypi.python.org/pypi/psyco/1.6 > > Do you think it's useful, or it depends...? Its present homepage is http://psyco.sourceforge.net/ , and yes, it is still useful and fairly current. However, it should be used judiciously; only bother with it if you're having a performance problem and would otherwise be tempted to rewrite the algorithm in C. Don't casually use it as an all-purpose accelerator, as that's not what it was built for. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From invalid at invalid Fri Jan 9 14:39:17 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 13:39:17 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: On 2009-01-09, Sion Arrowsmith wrote: > Grant Edwards wrote: >>On 2009-01-09, Johannes Bauer wrote: >>> I've come from C/C++ and am now trying to code some Python because I >>> absolutely love the language. However I still have trouble getting >>> Python code to run efficiently. Right now I have a easy task: Get a >>> file, >>If I were you, I'd try mmap()ing the file instead of reading it >>into string objects one chunk at a time. > > You've snipped the bit further on in that sentence where the > OP says that the file of interest is 2GB. Do you still want to > try mmap'ing it? Sure. The larger the file, the more you gain from mmap'ing it. 2GB should easily fit within the process's virtual memory space. When you mmap a file, it doesn't take up any physical memory. As you access different parts of it, pages are swapped in/out by the OS's VM system. If you're using a decent OS, the demand-paged VM system will handle things far more efficiently than creating millions of strings and letting the Python garbage collector clean them up. Or does "mmap" in Python mean something completely different than "mmap" in the C library? -- Grant Edwards grante Yow! Everybody gets free at BORSCHT! visi.com From invalid at invalid Fri Jan 9 14:47:27 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 13:47:27 -0600 Subject: eval('07') works, eval('08') fails, why? References: <4965c801$0$193$e4fe514c@news.xs4all.nl> <4965d079$0$199$e4fe514c@news.xs4all.nl> Message-ID: On 2009-01-09, Dennis Lee Bieber wrote: > On Thu, 08 Jan 2009 09:46:26 -0600, Grant Edwards > declaimed the following in comp.lang.python: > > >> Heathkit Z80 stuff used octal notation too. > > Octal worked well for the old 8080 and derivative processors as > there were only 7 registers and "memory/indirect" to encode in an > instruction... So (pseudo example) a MOV command might have been > > 01sssddd (binary) > > or > > 1SD (octal) > > > and S or D representing > > A 1 > B 2 > C 3 > D 4 > E 5 > H 6 > L 7 > Mem 0 (indirect via contents of HL pair) I presume that's why DEC chose octal for the PDP-11 also. There were 8 registers and 8 addressing modes, so they ended up with several fields within the opcodes that were three-bits wide and aligned with octal digits: http://en.wikipedia.org/wiki/PDP-11#Instruction_set When I was in University, we spent an entire quarter studying the PDP-11 instruction set at the binary/octal level and discussing instruction decoding and sequencing. We wrote a few PDP-11 assembly language programs as well, but the course was more about machine level instruction sets than about assembly language. Octal made a lot of sense if you had to deal with raw memory, but once you had access to an assembler and disassembler it didn't really matter. -- Grant Edwards grante Yow! NANCY!! Why is at everything RED?! visi.com From ryandw at gmail.com Fri Jan 9 14:49:23 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 11:49:23 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file Message-ID: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Hi, In python, is there a distinction between unzipping bytes and unzipping a binary file to which those bytes have been written? The following code is, I think, an example of writing bytes to a file and then unzipping... decoded = base64.b64decode(datum) #datum is a base64 encoded string of data downloaded from a web service f = open('data.zip', 'wb') f.write(decoded) f.close() x = zipfile.ZipFile('data.zip', 'r') After looking at the preceding code, the provider of the web service gave me this advice... "Instead of trying to create a file, take the unzipped bytes and get a Unicode string of text from it." If so, I'm not sure how to do what he's suggesting, or if it's really different from what I've done. I find that I am able to unzip the resulting data.zip using the unix unzip command, but the file inside contains some FFFD characters, as described in this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# I don't know if the unwanted characters might be the result of my trying to write and unzip a file, rather than unzipping the bytes. The file does contain a semblance of what I ultimately want -- it's not all garbage. Apologies if it's not appropriate to start a new thread for this. It just seems like a different topic than how to deal with the resulting FFFD characters. Thanks for your help, Ryan From ryandw at gmail.com Fri Jan 9 14:54:14 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 11:54:14 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: On Jan 9, 2:49?pm, webcomm wrote: > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') Sorry, that code is not what I mean to paste. This is what I intended... decoded = base64.b64decode(datum) #datum is a base64 encoded string of data downloaded from a web service f = open('data.zip', 'wb') f.write(decoded) f.close() x = popen("unzip data.zip") From pavlovevidence at gmail.com Fri Jan 9 14:58:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 11:58:21 -0800 (PST) Subject: Problem with -3 switch References: Message-ID: On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > Aivar Annamaa wrote: > > >> As was recently pointed out in a nearly identical thread, the -3 > > >> switch only points out problems that the 2to3 converter tool can't > > >> automatically fix. Changing print to print() on the other hand is > > >> easily fixed by 2to3. > > > >> Cheers, > > >> Chris > > > > I see. > > > So i gotta keep my own discipline with print() then :) > > > Only if you don't want to run your 2.x code through 2to3 before you use > > it as Python 3.x code. > > > regards > > ?Steve > > And mind you, if you follow that route, you are programming in a > mightily crippled language. How do you figure? I expect that it'd be a PITA in some cases to use the transitional dialect (like getting all your Us in place), but that doesn't mean the language is crippled. >?It's about as bad as trying to write > cross-browser CSS. ?Don't put yourself through that pain if you don't > have to. Have you tried doing that, or are you imagining how it will be? I'm curious about people's actual experiences. Problem is, a lot of people use the "bang at it with a hammer till it works" approach to programming, and really have no shame when it comes to engaging in questionable practices like relying on accidental side effects, rather than taking the time to try to program robustly. I expect people with that style of programming will have many more issues with the transition. Carl Banks From rurpy at yahoo.com Fri Jan 9 15:06:22 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 12:06:22 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> Message-ID: <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >>>> a = array (1,2,3) >>>> b = a >>>> a[1] = 4 >>>> print b >>>> >>>> C, C++, VBA, Fortran, Perl: 1, 2, 3 >>>> Python: 1, 4, 3 >>> You are mistaken >> >> I don't think so. >> See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 >> The code I quoted there was tested. >> In the C/C++ case, array-to-pointer coercion confuses >> the issue so I embedded the array in a struct which >> is more like an "object". > > No, that's cheating (IMHO). Structs used directly (rather than via > pointers) are the odd beast, and while they're certainly possible in C, > they are far from the normal idiom. And certainly embedding an array in > a struct just to force it to be copied, avoiding the standard reference > semantics, is an arbitrary trick. It was intended as a purely rhetorical device to avoid requiring a lot of verbiage to say why a struct example is used for C and arrays for the others and why that makes no difference to my point. Actually, the whole code/results thing was purely for effect since I presume most people reading already understand how assignments work in these languages, or that least that there are significant languages using copy-like assignments. > I never claimed that you *couldn't* have copy semantics in C; you can do > almost anything you want in C (or C++). But the *normal* usage of an > array is via a pointer, in which case the semantics are exactly the same > as in Python, Java, REALbasic, .NET, etc. Arrays are the only datatype in C that don't use copy-like assignment. Everything else does. >>(Keep in mind >> my point was not to show the behavior of arrays, but to >> show that several common languages *do not* use Python's >> "*all* names are references" model -- though of course >> this does not preclude their having some Python-like >> assignments since they all have some way of doing >> references.) > > Ah. OK then, I guess I missed you're point. You're absolutely right; > many languages have both reference types and value types. Python is a > bit unusual in that it has only reference types. I would have picked a > different example to illustrate that, but it's true nonetheless. If one accepts that there are a "lot" of people who post in here that clearly are surprised by Python's assignment semantics, and further appear to expect assignment to have copy-like semantics, then where is that expectation coming from? How would anyone develop that expectation if (from a different post in this thread), "[Python's] idea of assignment is the same as anyone else's." If you maintain that reference-like assignment is very common and something every programmer is accustomed to, then where are they getting the copy-like assignment expectations from? I agree that most of the time, when one is using large (memory) composite "objects", and one needs to pass, or access them by different names, one will often use references to do so in order to avoid expensive copies or to get desired "shared" behavior. But (with the exception of C arrays [*1]), doing so requires some special syntax in all the languages I mentioned (AFAIK). So it still seems to me that this is a likely explanation to why there is frequent misunderstanding of Python's assignments, and why responding to such misunderstandings with, "Python's assignments are the same as other languages'", is at best not helpful. [*1] I have often wished that C handled arrays the same way it does structs. I am sure that the pointer-array pseudo-equivalence seemed like a very clever idea at the time but I wonder if Dennis Richie ever had second thoughts about it. From steve at holdenweb.com Fri Jan 9 15:15:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 09 Jan 2009 15:15:29 -0500 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: webcomm wrote: > Hi, > In python, is there a distinction between unzipping bytes and > unzipping a binary file to which those bytes have been written? > > The following code is, I think, an example of writing bytes to a file > and then unzipping... > > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') > > After looking at the preceding code, the provider of the web service > gave me this advice... > "Instead of trying to create a file, take the unzipped bytes and get a > Unicode string of text from it." > Not terribly useful advice, but one presumes he she or it was trying to be helpful. > If so, I'm not sure how to do what he's suggesting, or if it's really > different from what I've done. > Well, what you have done appears pretty wrong to me, but let's take a look. What's datum? You appear to be treating it as base64-encoded data; is that correct? Have you examined it? f = open('data.zip', 'wb') opens the file data.zip for writing in binary. Not as a zip file, you understand, just as a regular file. I suspect here you really needed f = zipfile.ZipFile('data.zip', 'w') Now, of course, you need to remember what zipfiles contain. Which is other files. So the data you *write* tot he zipfile has to be associated with a filename in the archive. Of course you don't have the data in a file, you have it in a string, so you would use f.writestr("somefile.dat", decoded) f.close() You have now written a zip file containing a single "somefile.dat" file with the decoded base64 data in it. Open it with Winzip or one of its buddies and see if anyone barfs. > I find that I am able to unzip the resulting data.zip using the unix > unzip command, but the file inside contains some FFFD characters, as > described in this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# > I don't know if the unwanted characters might be the result of my > trying to write and unzip a file, rather than unzipping the bytes. > The file does contain a semblance of what I ultimately want -- it's > not all garbage. > But it's certainly not a zip file. > Apologies if it's not appropriate to start a new thread for this. It > just seems like a different topic than how to deal with the resulting > FFFD characters. > Don't worry about it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Fri Jan 9 15:16:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 20:16:01 +0000 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: <4967B081.2030901@mrabarnett.plus.com> webcomm wrote: > Hi, > In python, is there a distinction between unzipping bytes and > unzipping a binary file to which those bytes have been written? > Python's zipfile module can only read and write zip files; it can't compress or decompress data as a bytestring. > The following code is, I think, an example of writing bytes to a file > and then unzipping... > > decoded = base64.b64decode(datum) > #datum is a base64 encoded string of data downloaded from a web > service > f = open('data.zip', 'wb') > f.write(decoded) > f.close() > x = zipfile.ZipFile('data.zip', 'r') > > After looking at the preceding code, the provider of the web service > gave me this advice... > "Instead of trying to create a file, take the unzipped bytes and get a > Unicode string of text from it." > > If so, I'm not sure how to do what he's suggesting, or if it's really > different from what I've done. > If what you've been given is data which has been zipped and then base-64 encoded, then I can't see that you might be doing wrong. > I find that I am able to unzip the resulting data.zip using the unix > unzip command, but the file inside contains some FFFD characters, as > described in this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# > I don't know if the unwanted characters might be the result of my > trying to write and unzip a file, rather than unzipping the bytes. > The file does contain a semblance of what I ultimately want -- it's > not all garbage. > > Apologies if it's not appropriate to start a new thread for this. It > just seems like a different topic than how to deal with the resulting > FFFD characters. > From ryandw at gmail.com Fri Jan 9 15:18:35 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 12:18:35 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 9, 1:32?pm, Scott David Daniels wrote: > I'd certainly try to figure out if the archive was mis-handled > somewhere along the way. ? Quite possible that I'm mishandling something, or the service provider is mishandling something. Probably the former. Please see this more recent thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864?hl=en# From mdw at distorted.org.uk Fri Jan 9 15:23:11 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 20:23:11 +0000 (UTC) Subject: why cannot assign to function call References: <6s8s6nF4op56U2@mid.uni-berlin.de> <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: [Sigh. I must apologize for the length of this article. I can't, alas, see a satisfactory way of trimming it. The doubly-quoted stuff later on was by me.] Steven D'Aprano wrote: > I'm pretty sure that no other pure-Python coder has manipulated > references either. They've manipulated objects. No: not directly. The Python program deals solely with references; anything involving actual objects is mediated by the runtime. > Whatever the VM does under the hood is another story. (And, to stave off a return to the discussion about synchronized clones and other implementation techniques, whether a reference is a memory pointer, a tagged immutable immediate value, or an element of an equivalence-class of clones is an irrelevant implementation detail; but the reference needs to exist to explain observed, specified behaviour. For the purposes of this discussion, I shall continue to use the commonly accepted term `reference' to denote an arbitrary and implementation-specific choice of the isomorphism class of such possible implementation techniques.) > That's why we should try to keep the different layers of explanation > separate, without conflating them. Python programmers don't actually > flip bits, and neither do they manipulate references. Python > programmers don't have access to bits, or references. What they have > access to is objects. No, that's my point: Python programmers /don't/ have direct access to objects. The objects themselves are kept at arm's length by the indirection layer of references. > (Of course, there are ways to get under the hood if you really want > to.) Yes, but -- as I've done throughout this discussion -- I shall continue to use only Python examples whose behaviour is fully specified and implementation independent in order to support my thesis. > > Python does pass-by-value, but the things it passes -- by value -- > > are references. > > If you're going to misuse pass-by-value to describe what Python does, > *everything* is pass-by-value "where the value is foo", for some foo. No. I've tried explaining this before, with apparently little success. This is probably my fault: I don't seem to be good at explaining concepts to people whose mindset is significantly different to mine. (My refusal to ignore complicated corner cases doesn't help.) The words `value' and `reference' have significantly different meanings depending on whether we're talking on the one hand about data models and on the other hand about argument-passing models. In particular, the latter focuses on details at a lower abstraction level. This is extremely unfortunate, and is causing a lot of confusion. I can only speculate that the origins of this mess are historical and have their origins in the fact that lower-level languages have tended to have more exotic argument-passing models. This is going to be (as far as I can make it) a language-independent survey. That in itself is going to make matters complicated, because I know a lot of programming languages, and they differ in sometimes subtle ways. Enough of the disclaimers, and on to some terminology. For the avoidance of confusion, I shall use the following terms in perhaps technical senses, defined below. Even so, I believe that I'm using these terms in the senses (or at least, in ways similar to the senses) commonly understood in the field of programming language design. * A /value/ is an item of data. The range and nature of values is language specific. Typically, values encompass at least some kinds of numbers, textual data, and compound data structures; they may also include behavioural items such as functions. * A /location/[1] is an area of memory suitable for storing the /immediate representation/ (which I shall abbreviate to /IR/) of a value. (A location may be capable of storing things other than IRs, e.g., representations of unevaluated expressions in lazily evaluated languages. Locations may vary in size, e.g., in order to be capable of storing different types of IRs.) * A /variable/ is a location to which has been /bound/ a name. Given an occurrence of a name in a program's source, there is a language specific rule for determining the variable to which it is bound. * /Evaluation/ is the process of determining a value from an expression. The /value of/ an expression is the result of evaluating the expression. This value is, in general, dependent on the contents of the locations to which names appearing in the expression are bound. * A /function/ (synonymously, /procedure/) is a subprogram which may be /called/ by another (not necessarily distinct) part of the program, supplying zero or more /arguments/, performing a computation depending on these arguments, and returning zero or more /results/. Whether functions are values is language specific. The nature of the arguments and results is language specific. [1] Previously, I used the term `slot' for what I'm now calling a `location'. The argument passing model `pass-by-value' has a number of distinctive properties. * The argument expression is fully evaluated before the function is called, yielding an argument value. * The corresponding parameter name is bound to a fresh location. * The argument value IR is stored in the parameter's location. By contrast, the `pass-by-reference' model has other distinguishing properties. * Whether arbitrary argument expressions are permitted is language dependent; often, only a subset of available expressions -- those that designate locations -- are permitted. If the argument expression does designate a location, then this location is the /argument location/. If arbitrary expressions are permitted, and the expression does not designate a location, then a fresh location is allocated to be the argument location, the expression evaluated, and the resulting IR stored in the argument location. * The corresponding parameter name is bound to the argument location. There are other models, including value/return and call-by-name. It should be clear that it is possible to write the traditional `swap' function trivially using pass-by-reference, but one requires explicit indirection in order to achieve the same effect using pass-by-value. > You can't have anything but pass-by-value with current computer > technology, because computers don't actually move arguments, they only > copy bytes. So pass-by-value becomes a meaningless term, because it > describes every computer language imaginable, including hypothetical > ones using calling conventions not yet invented, and therefore > explains nothing. I hope that I have convincingly demonstrated that it's possible to define `pass-by-value' in a coherent manner, consistent with conventional usage, and distinguishing it clearly from `pass-by- reference'. > > (The `pass-by-*' notions are confusingly named anyway. Pass-by-name > > doesn't actually involve names at all.) > > You might find them confusing, but I don't. What I find confusing is > that people insist on misusing terminology invented for describing one > type of behaviour in order to use it for a completely different type > of behaviour just because of certain similarities under the hood. I hope that I've also demonstrated that the similarities `under the hood' are not actually there. Indeed, I've defined `pass-by-reference' without describing references at all. This is actually as it should be. The simple assembler procedure xchg eax, ebx ret implements a `swap' function pretty well. We can map the abstract concepts listed above onto the low-level details easily: locations can be in memory on in registers; argument locations are in registers; argument value IRs are words; and the binding of names to locations is fixed. > > I agree with the comment about Pascal, but C is actually pretty similar > > to Python here. C only does pass-by-value. > > Except for arrays. Even for those. C doesn't pass arrays at all; instead it passes (programmer-visible) pointers. See other article. > > If you want a function to modify your variable, you have to pass a > > pointer value which points to it. > > Yes, because the variable is copied before the function sees it. So if > you pass a struct, and modify one of the struct's fields, the caller > doesn't see the change. > > Now try that with Python, and you'll see completely different behaviour. > (You'll have to use something *like* a struct, because Python doesn't > have them. Try an object with attributes.) That's because C's IRs are raw value representations; its `locations' correspond to what the C standard calls `objects' (3.15). Pass-by-value works by storing IRs in freshly allocated locations -- in C, these are objects with automatic storage duration (6.2.4, 6.5.2.2). > In other words... C is call-by-value, and (according to you) Python is > call-by-value, but they behaviour differently. And this is entirely due to the difference in their immediate representations of values. > > Python has no pointer values, so you need a different hack. The > > hack usually involves lists. (Though it's easier in the main to return > > compound data objects like tuples. I don't suppose that a proposal for > > true multiple return values would go down well here. No, didn't think > > so...) > > Out of curiosity, what makes Python returning tuples less "true" than > "true multiple return values", and what can you do with TMRVs that you > can't do with tuples? `What can you do with ... that you can't do with ...' questions are meaningless when asked about Turing-complete languages, since they're obviously equipotent. In Python, if I want to convey multiple results to a function's caller, I usually use a tuple. This is a proper first-class value and needs to be properly allocated and populated, and a reference returned. Python's unpacking assignment syntax provides a relatively reasonable way of destructuring the tuple and recovering the individual results. So all of that's fine. * Construction, population and destructuring of the intermediate tuple has a performance impact. An intelligent compiler with knowledge of the function and the call site might be able to optimize the tuple away, but this is difficult due to Python's intrinsically dynamic nature: dynamic typing means a compiler must be better at drawing inferences from complicated code, and it not actually be possible to determine at compile time which actual function is being called anyway. (Not that I'd have Python any other way.) This would matter more if there were a significant statically-compiled implementation of Python that was intended for high-performance computing. * I quite frequently find myself only interested in one of several results from a function. For example, a function which parses some data from the head of a string might plausibly return both the parsed object and the remainder of the string. If I'm interested only in the object, I'll write something like obj = parse(string) and then obj will be a tuple. If the thing I'm expecting might be a tuple (or at least a sequence of some kind) it might be a while before an error occurs, if ever. Multiple return values would either (Common Lisp model) let me ignore return values I wasn't interested in, or (Scheme model) signal errors that I'd done something wrong. The Common Lisp model is riskier (I can ignore things which perhaps I shouldn't) but more flexible (in particular, I can enhance functions by adding return values without breaking existing callers, and I can write functions which return potentially interesting things which they computed anyway but weren't part of the main objective). It's not a big deal. Forget I mentioned it. In particular, there's no convenient syntax left to use for multiple return values anyway. When (not if) I want Lisp, I /do/ know where to find it. > x = 23 > > There's a name, and an object, and I've bound the name to the object so I > can refer to the object 23 by the name x. (Assume that x was previously unbound, and this is evaluated at top level) The above expression: binds x to a new location, and stores the immediate representation of the constant 23 in this location. (Languages -- other than C++ -- seem pretty uniform in their interpretation of assignment as overwriting a location with a new IR.) Because 23 is immutable, its IR doesn't actually matter that much. These things become apparent only with mutable data. > > You bind names slots in which you store references. Oops. Missing `to' between `names' and `slots'. Sorry. > I'm pretty sure I don't. I'd have noticed. You bind names to locations which store immediate representations. Python IRs are (in the sense defined above) exclusively references. > You may have missed my last question: > > >> > How do we deal with anonymous objects in your model? No. I decided that it was irrelevant given the previous answers I'd already given. That is, if an object's only attached paperweights are stored in other objects -- maybe in boxes -- then it has no obvious name; if there is no path from you to the object, then no action you take can be affected if the daemon clears it away -- so it might as well do that. (This is my fault, I know, but: `model' is the wrong word for the objects/boxes/string/paperweights description. `Metaphor' is probably better. Sorry for my lack of precision on this subject.) > > What I am pretty sure of is that references are going to have to > > enter the picture at some point, because other models get too > > complicated. > Well, I dare say that at *some* point all models are insufficient. No. The Python Language Reference presents a model of Python. CPython, and other implementations are expected to implement this model: failure to do so is (presumably) a bug in the implementation, or a defect in the document. The PLM (assumed defect-free) is therefore a sufficient model of Python, capable of describing all aspects of the language which are not implementation specific. > The map is not the territory, and there's always something that gets > left out. The trick is to explain Python, rather than implementations of Python. But the behaviour of l = [1, 2, 3] l[1] = l can be understood without recourse to implementation specifics. I argue -- and this has really been my point all along -- that this understanding is best achieved by a diagram of the form ,----------, v | +---+ +---+ | l: | *----> | *-----> 1 | +---+ +---+ | | *----------' +---+ | *-----> 3 +---+ than by one of the form +-----+ l: | 1 | +-----+ | <------------- in here is an identical copy of l +-----+ | 3 | +-----+ This immediately gets me thinking about `G?del Escher Bach', strange loops, and all manner of weirdness. Such things still give me the willies occasionally. (I'm willing to accept that I suck at drawing diagrams, and that I might anyway have accidentally misrepresented your position. If you think you can draw a more convincing diagram of this data structure, according to your model, please do.) > But I think your model with strings is more complicated: robots, > sticky Blu-Tack, string that you can't touch or see, and so forth. The metaphor is complicated, yes, but the concepts are somewhat complicated too. Fortunately there are direct mappings from the metaphor to identifiable > Compared to that, TARDIS technology enabling objects to be in two > places at once is remarkably straightforward. Despite it being > physically unrealistic, it's logically simple. You certainly get to talk about Tardises, which is cool. ;-) There is some interesting and relevant material in the classic Who stories `Logopolis' and `Castrovalva'. And, if the resulting recursion is explained thoroughly, it'll lead you on some fascinating diversions around some valuable areas of theory... -- [mdw] From lelandpeng at gmail.com Fri Jan 9 15:26:19 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:26:19 -0800 (PST) Subject: string split Message-ID: Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES It seems work this way, is there more elegant way to do this? Thanks, Leland From joe at strout.net Fri Jan 9 15:29:35 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 13:29:35 -0700 Subject: why cannot assign to function call In-Reply-To: <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <4967B3AF.8050507@strout.net> rurpy at yahoo.com wrote: >> I never claimed that you *couldn't* have copy semantics in C; you can do >> almost anything you want in C (or C++). But the *normal* usage of an >> array is via a pointer, in which case the semantics are exactly the same >> as in Python, Java, REALbasic, .NET, etc. > > Arrays are the only datatype in C that don't use > copy-like assignment. Everything else does. No, arrays are just one reference type; pointers are another (and in most ways, these are the same thing). When dealing with objects in C++, one routinely handles them with pointers, so that's the use case which is analogous to Python -- all the value types can be ignored for the sake of comparison. (C is not an OOP language, of course, but even there, all but the most trivial of structs are usually allocated on the heap and passed around via pointers, just like in C++, Java, .NET, RB, and Python.) >> Ah. OK then, I guess I missed you're point. You're absolutely right; >> many languages have both reference types and value types. Python is a >> bit unusual in that it has only reference types. I would have picked a >> different example to illustrate that, but it's true nonetheless. > > If one accepts that there are a "lot" of people > who post in here that clearly are surprised by > Python's assignment semantics, and further appear > to expect assignment to have copy-like semantics, > then where is that expectation coming from? I think it comes from people stumbling across posts in this forum claiming that Python has unusual assignment semantics. I wish people would stop saying that, as it causes a lot of confusion. > How would anyone develop that expectation if (from > a different post in this thread), "[Python's] idea > of assignment is the same as anyone else's." I can think of two ways: 1. They're new to programming in general, and would have had the same expectation for any other language. OR, 2. They already understand some other language, and then they come here and read wild claims that Python's assignment and parameter-passing semantics are different from other languages. Duped by this claim, they conclude that, if it's unlike other languages, then Python must have copy semantics. > If you maintain that reference-like assignment > is very common and something every programmer is > accustomed to, then where are they getting the > copy-like assignment expectations from? Reference-like assignment IS very common (see ). So, see above. > I agree that most of the time, when one is using > large (memory) composite "objects", and one needs > to pass, or access them by different names, one will > often use references to do so in order to avoid > expensive copies or to get desired "shared" behavior. Right. > But (with the exception of C arrays [*1]), doing so > requires some special syntax in all the languages I > mentioned (AFAIK). Whether you consider it "special" or not, pointers are extremely common in C. Even more so in C++, which is the closest thing to an OOP language in the list of moldy languages you mentioned. You also mentioned VBA -- if that's anything like VB, it does NOT require any special syntax; a variable is a reference type if its declared type is a class or string, and a simple type if it's anything else (just like in .NET, Java, and REALbasic). > So it still seems to me that this is a likely > explanation to why there is frequent misunderstanding > of Python's assignments, and why responding to such > misunderstandings with, "Python's assignments are > the same as other languages'", is at best not helpful. I don't think so. More likely, people are being confused by the claim that Python's assignments are NOT like other languages, when in fact they are. Best, - Joe From fred.sells at adventistcare.org Fri Jan 9 15:31:06 2009 From: fred.sells at adventistcare.org (Sells, Fred) Date: Fri, 9 Jan 2009 15:31:06 -0500 Subject: Python Apache Handler In-Reply-To: References: Message-ID: Mod_python works, but if you are doing anything significant look into one of the many frameworks like turbogears or django. More structure to learn but less code when all is said and done. > -----Original Message----- > From: python-list-bounces+frsells=adventistcare.org at python.org > [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On > Behalf Of Scooter > Sent: Friday, January 09, 2009 9:37 AM > To: python-list at python.org > Subject: Python Apache Handler > > Does anyone have any good examples, or links thereto for using python > as an Apache handler? And I should qualify all of this by saying I'm a > python newbie, and while having experience with Apache, I've never > done anything outside whats "in the box" . > > What I'm looking for is how one might use Python not from the CGI/ > presentation side but more on the backend...i.e. for each page Apache > serves up examine the request and update some headers, or add a cookie > to the response. Or possibly use Python for writing a custom Apache > logger. I've searched the web but typically end up with pages for > mod_python and writing CGI scripts. > > And if you feel this is better posted in an Apache group vs. here, let > me apologize up front. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list From ryandw at gmail.com Fri Jan 9 15:32:28 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 12:32:28 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: On Jan 9, 3:15?pm, Steve Holden wrote: > webcomm wrote: > > Hi, > > In python, is there a distinction between unzipping bytes and > > unzipping a binary file to which those bytes have been written? > > > The following code is, I think, an example of writing bytes to a file > > and then unzipping... > > > decoded = base64.b64decode(datum) > > #datum is a base64 encoded string of data downloaded from a web > > service > > f = open('data.zip', 'wb') > > f.write(decoded) > > f.close() > > x = zipfile.ZipFile('data.zip', 'r') > > > After looking at the preceding code, the provider of the web service > > gave me this advice... > > "Instead of trying to create a file, take the unzipped bytes and get a > > Unicode string of text from it." > > Not terribly useful advice, but one presumes he she or it was trying to > be helpful. > > > If so, I'm not sure how to do what he's suggesting, or if it's really > > different from what I've done. > > Well, what you have done appears pretty wrong to me, but let's take a > look. What's datum? You appear to be treating it as base64-encoded data; > is that correct? Have you examined it? It's data that has been compressed then base64 encoded by the web service. I'm supposed to download it, then decode, then unzip. They provide a C# example of how to do this on page 13 of http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf If you have a minute, see also this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 From markus.falb at fasel.at Fri Jan 9 15:33:55 2009 From: markus.falb at fasel.at (Markus Falb) Date: Fri, 9 Jan 2009 21:33:55 +0100 (CET) Subject: mac osx how to use a specific python environment References: Message-ID: On Wed, 07 Jan 2009 10:07:18 -0500, Philip Semanchuk wrote: > On Jan 7, 2009, at 7:27 AM, marco kuhn wrote: > >> hi, >> >> I would like to use a specific python environment in a script . The >> script is load as a plugin by a program which offer a python api . The >> python environment is build in. >> >> How can I use the standard python environment. Can i explicit load the >> env in my python script. > > Hi Marco, > I'm not exactly sure what you want to do. But if you execute `python` at > the command line, OS X will launch whatever version of Python it finds > first in your PATH. also, with unix you can set a "per script" interpreter in the first line of the script #!/usr/bin/env python2.5 or #!/usr/bin/python2.3 or #!/usr/bin/python or something like that should do the trick. however, i'm also not exactly sure what you want to do. i dont think its possible to switch the interpreter in case you import your plugin as a module best regards, markus From lelandpeng at gmail.com Fri Jan 9 15:36:34 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:36:34 -0800 (PST) Subject: string split Message-ID: <1ac9a2f6-7561-4f5e-8655-1dee27632a5d@d42g2000prb.googlegroups.com> Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES if str7[0] == "\"" : str8=str7.split("\"", 2) str9=str8[1] else : str8=str7.split(",", 1) str9=str8[0] print(key, ":", str9) It seems work this way, but is there more elegant way to do this? Thanks, Leland From rdcollum at gmail.com Fri Jan 9 15:37:38 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 9 Jan 2009 12:37:38 -0800 (PST) Subject: Where's Psyco now? References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: On Jan 9, 2:21?pm, "Chris Rebert" wrote: > On Fri, Jan 9, 2009 at 10:41 AM, Vicent wrote: > > Hello. This is my first message to the list. > > > In this article written in 2002 > > >http://www.ibm.com/developerworks/library/l-psyco.html > > > they talk about Psyco as a module that makes it possible to accelerate > > Python. > > > Is it still a state-of-the-art module? > > > I found it here also:http://pypi.python.org/pypi/psyco/1.6 > > > Do you think it's useful, or it depends...? > > Its present homepage ishttp://psyco.sourceforge.net/, and yes, it is > still useful and fairly current. > However, it should be used judiciously; only bother with it if you're > having a performance problem and would otherwise be tempted to rewrite > the algorithm in C. Don't casually use it as an all-purpose > accelerator, as that's not what it was built for. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com If that's the case where's the point of diminishing returns on using psyco? Why would it not be useful in a general setting? From lelandpeng at gmail.com Fri Jan 9 15:39:22 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 12:39:22 -0800 (PST) Subject: string split Message-ID: <26c34fad-a0cf-4f0a-9db6-410e19f38ba3@z28g2000prd.googlegroups.com> Hi, I have some formatted strings that I'd like to split and get the meaningful data, here is the example of the string format. The big difference of these two line are the second double quote set at the second line 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", 3,"D24,D72,D104", I want to split the string into the following format: '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' '100-01004-001', 'Diode,High Voltage General Purpose,600mA, 200V,SOT-23', '3', 'D24,D72,D104' By doing so, the list then has the meaning of part #, description, quantity and reference. Here is the way I way to split: str2=line1.split(',\"', 1) # Split part# and the rest key = str2[0] str3 = str2[1] str4 = str3.split("\",", 1) Value1 = str4[0] str5 = str4[1] str6 = str5.split(",", 1) # QTY, PARTS & BOM_NOTES Quanty = str6[0] str7 = str6[1] # PARTS & BOM_NOTES if str7[0] == "\"" : str8=str7.split("\"", 2) str9=str8[1] else : str8=str7.split(",", 1) str9=str8[0] print(key, ":", str9) It seems work this way, but is there more elegant way to do this? Thanks, Leland From benjamin.kaplan at case.edu Fri Jan 9 15:39:54 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 9 Jan 2009 15:39:54 -0500 Subject: string split In-Reply-To: References: Message-ID: On Fri, Jan 9, 2009 at 3:26 PM, Leland wrote: > Hi, > > I have some formatted strings that I'd like to split and get the > meaningful data, here is the example of the string format. The big > difference of these two line are the second double quote set at the > second line > 100-01001-001,"Diode,Small Signal,SOT-23",1,D46, > 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23", > 3,"D24,D72,D104", > > I want to split the string into the following format: > '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46' > '100-01004-001', 'Diode,High Voltage General Purpose,600mA, > 200V,SOT-23', '3', 'D24,D72,D104' > [snip code] This looks like a CSV file to me. If that is the case, it is easier to use the built-in csv module than to try to write your own parser. http://docs.python.org/library/csv.html#module-csv -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Fri Jan 9 15:46:06 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 20:46:06 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: Aaron Brady wrote: > Possible compromise. You can think of functions as mutation-only. > You pass the object, and it gets a new (additional) name. The old > name doesn't go in. Huh? That doesn't explain circular data structures at all, unless your idea of `name' is unrelated to the identifiers the programmer has typed and in fact is the same as what I'm calling a reference. > Regardless, IMO, references don't add any explanatory power; they just > make you feel cocky that you know what they are. No, they're essential to understanding sharing and circular data. > M: If 'fun()' returned a reference, you would be able to assign to it. [mdw]: Why would you think that you can assign to a reference? You assign to variables, not references. > -- Why can't I assign to a function call? > -- Python variables are references only. You may have missed this, but I explained at least twice: variables are bound to `slots' or `locations'; locations, in Python, store references to values; references are not values. But I answered this lot ages ago. I'm still dealing with the fallout because of my approach, though. > In other words, Mark and Joe, cut to the chase. You're shirking. I'm trying to explain somewhat complex concepts in defence of my thesis. This is not intended to be an answer to the original poster: the discussion has become considerably more technical since then. -- [mdw] From sjmachin at lexicon.net Fri Jan 9 15:48:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 12:48:57 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 10, 5:32?am, Scott David Daniels wrote: > webcomm wrote: > > .... ?I tried Scott's getzip() function yesterday... I > > stumbled upon it in my searches. ?It didn't seem to help in my case, > > though it did produce a different error: ?ValueError, substring not > > found. ?Not sure what that means. > > and in another message webcomm wrote: > ?> I ran the diagnostic gadget... > ?> > ?> archive size is 69888 > ?> FileHeader at 0 > ?> CentralDir at 43796 > ?> EndArchive at 43846 > > This is telling you that the archive ends at 43846, Not quite. """In a "normal" uncommented archive, EndArchive_pos + 22 == archive_size.""" > but the file > is 69888 bytes long (69888 - 43846 = 26042 post-archive bytes). > Have you tried calling getzip(filename, ignoreable=30000)? > The whole point of the function is to ignore the nasty stuff at the > end, but if _I_ had a file with more than 25K of post-archive bytes, > I'd certainly try to figure out if the archive was mis-handled > somewhere along the way. Me too. Further, if I wasn't "ever diplomatic" :-), I wouldn't be calling software (or people!) that blithely ignored 25kb of unexplained data "forgiving" ... some other f-words, perhaps. > ?Byt the way, one reason you cannot find > the archive by looking at the start of the file is that the zip file > format is meant to allow you to append a zip file to another file (such > as an executable) and treat the combination as an archive. > > --Scott David Daniels > Scott.Dani... at Acm.Org From bj_666 at gmx.net Fri Jan 9 15:52:59 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 20:52:59 GMT Subject: string split References: <26c34fad-a0cf-4f0a-9db6-410e19f38ba3@z28g2000prd.googlegroups.com> Message-ID: <6sprpbF7n8nmU1@mid.uni-berlin.de> On Fri, 09 Jan 2009 12:39:22 -0800, Leland wrote: > It seems work this way, but is there more elegant way to do this? Yes, the `csv` module in the standard library. Ciao, Marc 'BlackJack' Rintsch From malaclypse2 at gmail.com Fri Jan 9 15:57:42 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 9 Jan 2009 15:57:42 -0500 Subject: string split In-Reply-To: References: Message-ID: <16651e80901091257x42e633bcnee738d262188c525@mail.gmail.com> On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan > This looks like a CSV file to me. If that is the case, it is easier to use > the built-in csv module than to try to write your own parser. It should be as easy as this: import csv testfile = open('testfile.csv', 'w') testdata = """100-01001-001,"Diode,Small Signal,SOT-23",1,D46, 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23",3,"D24,D72,D104", """ testfile.write(testdata) testfile.close() infile = open('testfile.csv', 'r') reader = csv.reader(infile) for line in reader: print line The output of that code is: ['100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46', ''] ['100-01004-001', 'Diode,High Voltage General Purpose,600mA,200V,SOT-23', '3', 'D24,D72,D104', ''] so line[0] is your part number, etc. -- Jerry From tjreedy at udel.edu Fri Jan 9 15:58:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jan 2009 15:58:56 -0500 Subject: Default __nonzero__ impl doesn't throw a TypeError exception In-Reply-To: <496715ac$0$15321$426a74cc@news.free.fr> References: <4966750c$0$5150$426a74cc@news.free.fr> <496715ac$0$15321$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > > To be more exact: there's no "default __nonzero__". In Py3, '__nonzero__' has been renamed to __bool__. All objects are instances of class object, which indeed has no __bool__ method to be a default (it does have default __hash__ and __eq__, etc). > The boolean value of > an object is eval'd this way: > > If the object is None (special cased by the interpreter AFAICT), it is > false. Must be, since None.__bool__ does not exist. > Else if the object implements __nonzero__, it has the boolean value > returned by __nonzero__. Leaving None aside, __bool__ is only needed for non-collection classes (which do not have __len__) if at least 1 instance of the class is intended to be False. For built-in classes, this means numbers. > Else if the object implements __len__, it has the boolean value of its > length. This method, interpreted more generally as 'object count', essentially defines collection classes. > Else if is true. Thank you for the clarification. Then the __new__ method of class bool would be implemented in Python as def __new__(cls, ob): if ob is None: return False elif hasattr(ob, '__bool__'): b = ob.__bool__() if b.__class__ is bool: return b else: raise TypeError("__bool__ should return bool, returned %s" % b.__class__) elif hasattr(ob, '__len__'): return len(ob) != 0 # ob.__len__() != 0 does not do len's typecheck on return else: return True Experiments show that 3.0 bool.__new__ does typecheck the return of ob.__bool__ and raises the error indicated and that __len__ must return a value that passes len's typecheck. Terry Jan Reedy From bj_666 at gmx.net Fri Jan 9 16:02:57 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 21:02:57 GMT Subject: Where's Psyco now? References: <50ed08f40901091041v2602817ar6557fab2087212f1@mail.gmail.com> Message-ID: <6spsc1F7n8nmU2@mid.uni-berlin.de> On Fri, 09 Jan 2009 12:37:38 -0800, Roger wrote: > If that's the case where's the point of diminishing returns on using > psyco? Why would it not be useful in a general setting? There is some overhead involved with the runtime analysis and compiling. Functions that are only called once usually don't benefit from psyco, even worse they can be slower because of the unnecessary overhead. And not all code can be accelerated. Best candidates are functions that are somewhat C-like, i.e. doing lots of operations on simple number types. Things that can be translated directly to machine code. And for some very generic functions that are called with lots of different types, the memory consumption is high because of all the specialized code that will be compiled. Ciao, Marc 'BlackJack' Rintsch From mdw at distorted.org.uk Fri Jan 9 16:03:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 21:03:39 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Python doesn't do the same thing as C. It actually passes the same value > to the function, without copying it. > > Why oh why do you keep insisting that Python is no different from C? I'm beginning to think that you're not bothing to read what I'm writing, but I'll assume instead that I'm just not writing clearly enough. In one respect, C and Python are alike. That respect is that they both pass arguments to functions `by value'. In another respect, C and Python are different. That respect is that they represent these arguments differently: C stores a binary representation of the value directly in the object allocated to store it (6.2.6.1); whereas Python stores a reference to the actual value (3.1, 4.1). This is what I mean when I say that Python passes arguments by value -- but the `values' that are passed are references. References to the C standard are to ISO 9899:1999, though I'm fairly sure that N843 and N1256 will do as well; references to the Python Language Reference are to the 2.5.2 version dated 2008-02-21. I'll note here that the PLM uses the term `binding' in the usual sense understood by the larger programming-language community, and not as a confusing synonym for assignment. > Why oh why do you keep insisting that Python is no different from C? Why oh why do you keep insisting that, because I claim that the two languages are alike in one respect, that I believe that they must be alike in a different respect, despite my repeated assertions to the contrary? -- [mdw] From lelandpeng at gmail.com Fri Jan 9 16:05:24 2009 From: lelandpeng at gmail.com (Leland) Date: Fri, 9 Jan 2009 13:05:24 -0800 (PST) Subject: string split References: Message-ID: <0f73cff0-b5db-4e43-851b-9ff12b1ab159@t39g2000prh.googlegroups.com> On Jan 9, 12:57?pm, "Jerry Hill" wrote: > On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan > > > This looks like a CSV file to me. If that is the case, it is easier to use > > the built-in csv module than to try to write your own parser. > > It should be as easy as this: > > import csv > > testfile = open('testfile.csv', 'w') > testdata = """100-01001-001,"Diode,Small Signal,SOT-23",1,D46, > 100-01004-001,"Diode,High Voltage General > Purpose,600mA,200V,SOT-23",3,"D24,D72,D104", > """ > testfile.write(testdata) > testfile.close() > > infile = open('testfile.csv', 'r') > reader = csv.reader(infile) > for line in reader: > ? ? print line > > The output of that code is: > > ['100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46', ''] > ['100-01004-001', 'Diode,High Voltage General > Purpose,600mA,200V,SOT-23', '3', 'D24,D72,D104', ''] > > so line[0] is your part number, etc. > > -- > Jerry It works like a charm. Really appreciate all the helps. From arkanes at gmail.com Fri Jan 9 16:08:35 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 15:08:35 -0600 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> Message-ID: <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> On Fri, Jan 9, 2009 at 2:32 PM, webcomm wrote: > On Jan 9, 3:15 pm, Steve Holden wrote: >> webcomm wrote: >> > Hi, >> > In python, is there a distinction between unzipping bytes and >> > unzipping a binary file to which those bytes have been written? >> >> > The following code is, I think, an example of writing bytes to a file >> > and then unzipping... >> >> > decoded = base64.b64decode(datum) >> > #datum is a base64 encoded string of data downloaded from a web >> > service >> > f = open('data.zip', 'wb') >> > f.write(decoded) >> > f.close() >> > x = zipfile.ZipFile('data.zip', 'r') >> >> > After looking at the preceding code, the provider of the web service >> > gave me this advice... >> > "Instead of trying to create a file, take the unzipped bytes and get a >> > Unicode string of text from it." >> >> Not terribly useful advice, but one presumes he she or it was trying to >> be helpful. >> >> > If so, I'm not sure how to do what he's suggesting, or if it's really >> > different from what I've done. >> >> Well, what you have done appears pretty wrong to me, but let's take a >> look. What's datum? You appear to be treating it as base64-encoded data; >> is that correct? Have you examined it? > > It's data that has been compressed then base64 encoded by the web > service. I'm supposed to download it, then decode, then unzip. They > provide a C# example of how to do this on page 13 of > http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf > > If you have a minute, see also this thread... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 > When they say "zip", they're talking about a zlib compressed stream of bytes, not a zip archive. You want to base64 decode the data, then zlib decompress it, then finally interpret it as (I think) UTF-16, as that's what Windows usually means when it says "Unicode". decoded = base64.b64decode(datum) decompressed = zlib.decompress(decoded) result = decompressed.decode('utf-16') From arkanes at gmail.com Fri Jan 9 16:12:42 2009 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 9 Jan 2009 15:12:42 -0600 Subject: distinction between unzipping bytes and unzipping a file In-Reply-To: <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> Message-ID: <4866bea60901091312s760c9649hab50693e204ef604@mail.gmail.com> On Fri, Jan 9, 2009 at 3:08 PM, Chris Mellon wrote: > On Fri, Jan 9, 2009 at 2:32 PM, webcomm wrote: >> On Jan 9, 3:15 pm, Steve Holden wrote: >>> webcomm wrote: >>> > Hi, >>> > In python, is there a distinction between unzipping bytes and >>> > unzipping a binary file to which those bytes have been written? >>> >>> > The following code is, I think, an example of writing bytes to a file >>> > and then unzipping... >>> >>> > decoded = base64.b64decode(datum) >>> > #datum is a base64 encoded string of data downloaded from a web >>> > service >>> > f = open('data.zip', 'wb') >>> > f.write(decoded) >>> > f.close() >>> > x = zipfile.ZipFile('data.zip', 'r') >>> >>> > After looking at the preceding code, the provider of the web service >>> > gave me this advice... >>> > "Instead of trying to create a file, take the unzipped bytes and get a >>> > Unicode string of text from it." >>> >>> Not terribly useful advice, but one presumes he she or it was trying to >>> be helpful. >>> >>> > If so, I'm not sure how to do what he's suggesting, or if it's really >>> > different from what I've done. >>> >>> Well, what you have done appears pretty wrong to me, but let's take a >>> look. What's datum? You appear to be treating it as base64-encoded data; >>> is that correct? Have you examined it? >> >> It's data that has been compressed then base64 encoded by the web >> service. I'm supposed to download it, then decode, then unzip. They >> provide a C# example of how to do this on page 13 of >> http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf >> >> If you have a minute, see also this thread... >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/5b9eceeee3e77dd4?hl=en&lnk=gst&q=webcomm#5b9eceeee3e77dd4 >> > > When they say "zip", they're talking about a zlib compressed stream of > bytes, not a zip archive. > > You want to base64 decode the data, then zlib decompress it, then > finally interpret it as (I think) UTF-16, as that's what Windows > usually means when it says "Unicode". > > decoded = base64.b64decode(datum) > decompressed = zlib.decompress(decoded) > result = decompressed.decode('utf-16') > And of course as *soon* as I write that, I read the appendix on the documentation in full and turn out to be wrong. Ignore me *sigh*. It would really help if you could post a sample file somewhere. From bj_666 at gmx.net Fri Jan 9 16:14:52 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 9 Jan 2009 21:14:52 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: <6spt2cF7n8nmU3@mid.uni-berlin.de> On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > Marc 'BlackJack' Rintsch wrote: > >> def iter_max_values(blocks, block_count): >> for i, block in enumerate(blocks): >> histogram = defaultdict(int) >> for byte in block: >> histogram[byte] += 1 >> >> yield max((count, byte) >> for value, count in histogram.iteritems())[1] >> > [snip] > Would it be faster if histogram was a list initialised to [0] * 256? Don't know. Then for every byte in the 2?GiB we have to call `ord()`. Maybe the speedup from the list compensates this, maybe not. I think that we have to to something with *every* byte of that really large file *at Python level* is the main problem here. In C that's just some primitive numbers. Python has all the object overhead. Ciao, Marc 'BlackJack' Rintsch From robert.kern at gmail.com Fri Jan 9 16:33:10 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 09 Jan 2009 15:33:10 -0600 Subject: Printed Documentation In-Reply-To: References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: Tim Arnold wrote: > just a datapoint, but I used lulu.com to print the latex sources (525 pages) > hardbound for a cost of $25 US. Did they handle the LaTeX fonts well? The last time I looked at Lulu, they claimed that there were some font issues with PDFs made by LaTeX. -- 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 ryandw at gmail.com Fri Jan 9 16:56:56 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 13:56:56 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> Message-ID: <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> On Jan 9, 4:12?pm, "Chris Mellon" wrote: > It would really help if you could post a sample file somewhere. Here's a sample with some dummy data from the web service: http://webcomm.webfactional.com/htdocs/data.zip That's the zip created in this line of my code... f = open('data.zip', 'wb') If I open the file it contains as unicode in my text editor (EditPlus) on Windows XP, there is ostensibly nothing wrong with it. It looks like valid XML. But if I return it to my browser with python+django, there are bad characters every other character If I unzip it like this... popen("unzip data.zip") ...then the bad characters are 'FFFD' characters as described and pictured here... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# If I unzip it like this... getzip('data.zip', ignoreable=30000) ...using the function at... http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 ...then the bad characters are \x00 characters. From ryandw at gmail.com Fri Jan 9 17:00:36 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:00:36 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: Message-ID: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> On Jan 8, 8:39?pm, "James Mills" wrote: > Send us a sample of this file in question... Here's a sample with some dummy data from the web service: http://webcomm.webfactional.com/htdocs/data.zip That's the zip created in this line of my code... f = open('data.zip', 'wb') If I open the file it contains as unicode in my text editor (EditPlus) on Windows XP, there is ostensibly nothing wrong with it. It looks like valid XML. But if I return it to my browser with python+django, there are bad characters every other character If I unzip it like this... popen("unzip data.zip") ...then the bad characters are 'FFFD' characters as described and pictured here... http://groups.google.com/group/comp.lang.python/browse_thread/thread/... If I unzip it like this... getzip('data.zip', ignoreable=30000) ...using Scott's function at... http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 ...then the bad characters are \x00 characters. From ryandw at gmail.com Fri Jan 9 17:04:15 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:04:15 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> Message-ID: <59234154-ab06-442b-8433-52275e774eae@p36g2000prp.googlegroups.com> On Jan 9, 5:00?pm, webcomm wrote: > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > trying again to post the link re: FFFD characters... http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f57abea978cc0bf?hl=en# From sjmachin at lexicon.net Fri Jan 9 17:21:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 14:21:55 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> Message-ID: <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> On Jan 10, 2:22?am, webcomm wrote: > On Jan 9, 5:42?am, John Machin wrote: > > > And here's a little gadget that might help the diagnostic effort; it > > shows the archive size and the position of all the "magic" PKnn > > markers. In a "normal" uncommented archive, EndArchive_pos + 22 == > > archive_size. > > I ran the diagnostic gadget... > > archive size is 69888 > FileHeader at 0 > CentralDir at 43796 > EndArchive at 43846 Thanks. Would you mind spending a few minutes more on this so that we can see if it's a problem that can be fixed easily, like the one that Chris Mellon reported? The above output says that there are 43868 (43846 + 22) bytes of useable data. That leaves 69888 - 43868 = 26020 bytes of "comment" ... rather large for a comment. Have you run a virus scanner over this file? At the end is an updated version of the diagnostic gadget. It explores the "EndArchive" structure and the comment at the end, with a special check for all '\0' (as per Chris's bug report) and another for all blank. Please run it over your file and show us the results. Note: you may want to suppress the display of the first 100 bytes of comment if it turns out to be private data. Cheers, John 8<--- # zip_susser_v2.py import sys grimoire = [ ("FileHeader", "PK\003\004"), # magic number for file header ("DataDescriptor", "PK\x07\x08"), # see PKZIP APPNOTE (V) (C) ("CentralDir", "PK\001\002"), # magic number for central directory ("EndArchive", "PK\005\006"), # magic number for end of archive record ("EndArchive64", "PK\x06\x06"), # magic token for Zip64 header ("EndArchive64Locator", "PK\x06\x07"), # magic token for locator header ("ArchiveExtraData", "PK\x06\x08"), # APPNOTE (V) (E) ("DigitalSignature", "PK\x05\x05"), # APPNOTE (V) (F) ] f = open(sys.argv[1], 'rb') buff = f.read() f.close() blen = len(buff) print "archive size is", blen for magic_name, magic in grimoire: pos = 0 while pos < blen: pos = buff.find(magic, pos) if pos < 0: break print "%s at %d" % (magic_name, pos) pos += 4 # # find what is in the EndArchive struct # structEndArchive = "<4s4H2LH" # 9 [sic] items, end of archive, 22 bytes import struct posEndArchive = buff.find("PK\005\006") print "using posEndArchive =", posEndArchive assert 0 < posEndArchive < blen endArchive = struct.unpack(structEndArchive, buff [posEndArchive:posEndArchive+22]) print "endArchive:", repr(endArchive) endArchiveFieldNames = """ signature this_disk_num central_dir_disk_num central_dir_this_disk_num_entries central_dir_overall_num_entries central_dir_size central_dir_offset comment_size """.split() for name, value in zip(endArchiveFieldNames, endArchive): print "%33s : %r" % (name, value) # # inspect the comment # actual_comment_size = blen - 22 - posEndArchive expected_comment_size = endArchive[7] comment = buff[posEndArchive + 22:] print print "expected_comment_size:", expected_comment_size print "actual_comment_size:", actual_comment_size print "comment is all spaces:", comment == ' ' * actual_comment_size print "comment is all '\\0':", comment == '\0' * actual_comment_size print "comment (first 100 bytes):", repr(comment[:100]) 8<--- From invalid at invalid Fri Jan 9 17:23:28 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 09 Jan 2009 16:23:28 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> <6spt2cF7n8nmU3@mid.uni-berlin.de> Message-ID: On 2009-01-09, Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > >> Marc 'BlackJack' Rintsch wrote: >> >>> def iter_max_values(blocks, block_count): >>> for i, block in enumerate(blocks): >>> histogram = defaultdict(int) >>> for byte in block: >>> histogram[byte] += 1 >>> >>> yield max((count, byte) >>> for value, count in histogram.iteritems())[1] >>> >> [snip] >> Would it be faster if histogram was a list initialised to [0] * 256? > > Don't know. Then for every byte in the 2??GiB we have to call `ord()`. > Maybe the speedup from the list compensates this, maybe not. > > I think that we have to to something with *every* byte of that really > large file *at Python level* is the main problem here. In C that's just > some primitive numbers. Python has all the object overhead. Using buffers or arrays of bytes instead of strings/lists would probably reduce the overhead quite a bit. -- Grant Edwards grante Yow! I've got an IDEA!! at Why don't I STARE at you visi.com so HARD, you forget your SOCIAL SECURITY NUMBER!! From steven.klass at gmail.com Fri Jan 9 17:30:30 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 14:30:30 -0800 (PST) Subject: redirecting stderr back.. Message-ID: Hi All, Can someone tell me how to redirect stderr back to the console once you've moved it? import os,sys se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) sys.stderr.write("Foobar\n") Foobar os.dup2(se, 2) cmds = os.popen("ls alaksjdf") sys.stderr.write("Foobar\n") Foobar Any ideas? Thanks From steven.klass at gmail.com Fri Jan 9 17:33:53 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 14:33:53 -0800 (PST) Subject: redirecting stderr back.. Message-ID: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Hi All, Can someone tell me how to redirect stderr back to the console once you've moved it? import os,sys se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) sys.stderr.write("Foobar\n") Foobar os.dup2(se, 2) cmds = os.popen("ls alaksjdf") sys.stderr.write("Foobar\n") Foobar Any ideas? Thanks From lists at cheimes.de Fri Jan 9 17:38:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jan 2009 23:38:41 +0100 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: rh0dium schrieb: > Hi All, > > Can someone tell me how to redirect stderr back to the console once > you've moved it? sys.stderr = sys.__stderr__ or better: orig_stderr = sys.stderr try: sys.stderr = open(...) ... finally: sys.stderr = orig_stderr Christian From robert.kern at gmail.com Fri Jan 9 17:42:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 09 Jan 2009 16:42:46 -0600 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: Christian Heimes wrote: > rh0dium schrieb: >> Hi All, >> >> Can someone tell me how to redirect stderr back to the console once >> you've moved it? > > sys.stderr = sys.__stderr__ > > or better: > > orig_stderr = sys.stderr > try: > sys.stderr = open(...) > ... > finally: > sys.stderr = orig_stderr He's not reassigning the sys.stderr object; he's fiddling with the underlying file descriptor. Steven, look at my code here for a mostly complete solution: http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/redir/ -- 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 bedouglas at earthlink.net Fri Jan 9 17:47:17 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 14:47:17 -0800 Subject: spawning pyhon apps... Message-ID: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> hi... toying with an idea.. trying to figure out a good/best way to spawn multiple python scripts from a parent python app. i'm trying to figure out how to determine when all child apps have completed, or to possibly determine if any of the child processes have died/halted.. parent app spawn child1 spawn child2 spawn child3 . . . spawn childn do i iterate through a os.waitpid(pid) for each pid of the child processes i create? is there another approach? code samples/tutorial...?? i've seen various approaches via google, but not just what i'm looking for.. thanks From lists at cheimes.de Fri Jan 9 17:52:17 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jan 2009 23:52:17 +0100 Subject: redirecting stderr back.. In-Reply-To: References: Message-ID: Robert Kern schrieb: > Christian Heimes wrote: >> rh0dium schrieb: >>> Hi All, >>> >>> Can someone tell me how to redirect stderr back to the console once >>> you've moved it? >> >> sys.stderr = sys.__stderr__ >> >> or better: >> >> orig_stderr = sys.stderr >> try: >> sys.stderr = open(...) >> ... >> finally: >> sys.stderr = orig_stderr > > He's not reassigning the sys.stderr object; he's fiddling with the > underlying file descriptor. I know that. I wanted to show him a better way than messing around with file descriptors. In Python one doesn't have to (and should not) alter the file descriptor of a standard stream. Python always uses sys.stderr to write to the standard error stream. Christian From ryandw at gmail.com Fri Jan 9 17:52:24 2009 From: ryandw at gmail.com (webcomm) Date: Fri, 9 Jan 2009 14:52:24 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> Message-ID: On Jan 9, 5:21?pm, John Machin wrote: > Thanks. Would you mind spending a few minutes more on this so that we > can see if it's a problem that can be fixed easily, like the one that > Chris Mellon reported? > Don't mind at all. I'm now working with a zip file with some dummy data I downloaded from the web service. You'll notice it's a smaller archive than the one I was working with when I ran zip_susser.py, but it has the same problem (whatever the problem is). It's the one I uploaded to http://webcomm.webfactional.com/htdocs/data.zip Here's what I get when I run zip_susser_v2.py... archive size is 1092 FileHeader at 0 CentralDir at 844 EndArchive at 894 using posEndArchive = 894 endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) signature : 'PK\x05\x06' this_disk_num : 0 central_dir_disk_num : 0 central_dir_this_disk_num_entries : 1 central_dir_overall_num_entries : 1 central_dir_size : 50 central_dir_offset : 844 comment_size : 0 expected_comment_size: 0 actual_comment_size: 176 comment is all spaces: False comment is all '\0': True comment (first 100 bytes): '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00' Not sure if you've seen this thread... http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864?hl=en# Thanks, Ryan From sjmachin at lexicon.net Fri Jan 9 18:07:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 15:07:10 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> Message-ID: <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> On Jan 10, 8:56?am, webcomm wrote: > On Jan 9, 4:12?pm, "Chris Mellon" wrote: > > > It would really help if you could post a sample file somewhere. > > Here's a sample with some dummy data from the web service:http://webcomm.webfactional.com/htdocs/data.zip > > That's the zip created in this line of my code... > f = open('data.zip', 'wb') Your original problem is identical to that already reported by Chris Mellon (gratuitous \0 bytes appended to the real archive contents). Here's the output of the diagnostic gadget that I posted a few minutes ago: .......................................................... C:\downloads>python zip_susser_v2.py data.zip archive size is 1092 FileHeader at 0 CentralDir at 844 EndArchive at 894 using posEndArchive = 894 endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) signature : 'PK\x05\x06' this_disk_num : 0 central_dir_disk_num : 0 central_dir_this_disk_num_entries : 1 central_dir_overall_num_entries : 1 central_dir_size : 50 central_dir_offset : 844 comment_size : 0 expected_comment_size: 0 actual_comment_size: 176 comment is all spaces: False comment is all '\0': True comment (first 100 bytes): '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00' ................................... > > If I open the file it contains as unicode in my text editor (EditPlus) > on Windows XP, there is ostensibly nothing wrong with it. ?It looks > like valid XML. Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as God^H^H^HGates intended: >>> buff = open('data', 'rb').read() >>> buff[:100] '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> \x00<\x00B\x0 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> \x000\x00.\x000\x000\x000\x000\x0 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< \x00S\x00t\x0 0a\x00t\x00' >>> buff[:100].decode('utf_16_le') u'0.0000>> > ?But if I return it to my browser with python+django, > there are bad characters every other character Please consider that we might have difficulty guessing what "return it to my browser with python+django" means. Show actual code. > > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... Yup, you've somehow pushed your utf_16_le-encoded data through some decoder that doesn't like '\x00' and is replacing it with U+FFFD whose name is (funnily enough) REPLACEMENT CHARACTER and whose meaning is "big fat Unicode version of the question mark". > > If I unzip it like this... > getzip('data.zip', ignoreable=30000) > ...using the function at...http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > ...then the bad characters are \x00 characters. Hmmm ... shouldn't make a difference how you extracted 'data' from 'data.zip'. Please consider reading the Unicode HOWTO at http://docs.python.org/howto/unicode.html Cheers, John From clp2 at rebertia.com Fri Jan 9 18:10:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 15:10:20 -0800 Subject: spawning pyhon apps... In-Reply-To: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> References: <078401c972ac$39bd04c0$0301a8c0@tmesa.com> Message-ID: <50697b2c0901091510s3772b742wdd11b47a0f87a7a7@mail.gmail.com> On Fri, Jan 9, 2009 at 2:47 PM, bruce wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > spawn child1 > spawn child2 > spawn child3 > . > . > . > spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? Use the `subprocess` module's (http://docs.python.org/library/subprocess.html) Popen class to spawn the processes. Then use .wait() or .poll(), and .returncode on the Popen instances to check their exit status. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven.klass at gmail.com Fri Jan 9 18:10:48 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 15:10:48 -0800 (PST) Subject: redirecting stderr back.. References: Message-ID: <3fe1a82a-ff6b-40ce-9a60-c90096abe7d8@s1g2000prg.googlegroups.com> On Jan 9, 3:52?pm, Christian Heimes wrote: > Robert Kern schrieb: > > > > > Christian Heimes wrote: > >> rh0dium schrieb: > >>> Hi All, > > >>> Can someone tell me how to redirect stderr back to the console once > >>> you've moved it? > > >> sys.stderr = sys.__stderr__ > > >> or better: > > >> orig_stderr = sys.stderr > >> try: > >> ? ? sys.stderr = open(...) > >> ? ? ... > >> finally: > >> ? ? sys.stderr = orig_stderr > > > He's not reassigning the sys.stderr object; he's fiddling with the > > underlying file descriptor. > > I know that. I wanted to show him a better way than messing around with > file descriptors. In Python one doesn't have to (and should not) alter > the file descriptor of a standard stream. Python always uses sys.stderr > to write to the standard error stream. > > Christian Christian - it's not python that's the problem. Unfortunately the stuff I'm calling (outside of python) won't play nicely unless I mess with the FD's.. From google at mrabarnett.plus.com Fri Jan 9 18:13:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 23:13:20 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> Message-ID: <4967DA10.6080502@mrabarnett.plus.com> webcomm wrote: > On Jan 8, 8:39 pm, "James Mills" wrote: >> Send us a sample of this file in question... > > Here's a sample with some dummy data from the web service: > http://webcomm.webfactional.com/htdocs/data.zip > > That's the zip created in this line of my code... > f = open('data.zip', 'wb') > > If I open the file it contains as unicode in my text editor (EditPlus) > on Windows XP, there is ostensibly nothing wrong with it. It looks > like valid XML. But if I return it to my browser with python+django, > there are bad characters every other character > > If I unzip it like this... > popen("unzip data.zip") > ...then the bad characters are 'FFFD' characters as described and > pictured here... > http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > If I unzip it like this... > getzip('data.zip', ignoreable=30000) > ...using Scott's function at... > http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 > ...then the bad characters are \x00 characters. > I can unzip it in Windows XP. The file within it (called "data") is XML encoded as UTF-16LE (2 bytes per character, low byte first), but without the initial byte order mark. Python's zipfile module says "BadZipfile: File is not a zip file". From steven.klass at gmail.com Fri Jan 9 18:17:48 2009 From: steven.klass at gmail.com (rh0dium) Date: Fri, 9 Jan 2009 15:17:48 -0800 (PST) Subject: redirecting stderr back.. References: Message-ID: On Jan 9, 3:42?pm, Robert Kern wrote: > Christian Heimes wrote: > > rh0dium schrieb: > >> Hi All, > > >> Can someone tell me how to redirect stderr back to the console once > >> you've moved it? > > > sys.stderr = sys.__stderr__ > > > or better: > > > orig_stderr = sys.stderr > > try: > > ? ? sys.stderr = open(...) > > ? ? ... > > finally: > > ? ? sys.stderr = orig_stderr > > He's not reassigning the sys.stderr object; he's fiddling with the underlying > file descriptor. > > Steven, look at my code here for a mostly complete solution: > > ? ?http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/redir/ > > -- > 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 Interesting stuff - but the documentation is a bit lacking - but I think I can figure it out. From jason.scheirer at gmail.com Fri Jan 9 18:19:26 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 15:19:26 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> On Jan 9, 2:47?pm, "bruce" wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > ?spawn child1 > ?spawn child2 > ?spawn child3 > ?. > ?. > ?. > ?spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? > > i've seen various approaches via google, but not just what i'm looking for.. > > thanks Investigate the subprocess module, you probably want Popen objects. You can do a poll loop like my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] while any(popenobject.statuscode is None for popenobject in my_popenobjects): time.sleep(0.25) If your tasks are more like function calls and less like shell scripts, then investigate writing your python as an importable module and use the multiprocessing module, which will do threading/ subprocessing for you. From gagsl-py2 at yahoo.com.ar Fri Jan 9 18:19:33 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 09 Jan 2009 21:19:33 -0200 Subject: multiprocessing vs thread performance References: <266557d0901071655y25520910v23455441d6076329@mail.gmail.com> Message-ID: En Wed, 07 Jan 2009 23:05:53 -0200, James Mills escribi?: >> Does anybody know any tutorial for python 2.6 multiprocessing? Or bunch >> of >> good example for it? I am trying to break a loop to run it over multiple >> core in a system. And I need to return an integer value as the result >> of the >> process an accumulate all of them. the examples that I found there is no >> return for the process. > > You communicate with the process in one of several > ways: > * Semaphores > * Locks > * PIpes The Pool class provides a more abstract view that may be better suited in this case. Just create a pool, and use map_async to collect and summarize the results. import string import multiprocessing def count(args): (lineno, line) = args print "This is %s, processing line %d\n" % ( multiprocessing.current_process().name, lineno), result = dict(letters=0, digits=0, other=0) for c in line: if c in string.letters: result['letters'] += 1 elif c in string.digits: result['digits'] += 1 else: result['other'] += 1 # just to make some "random" delay import time; time.sleep(len(line)/100.0) return result if __name__ == '__main__': summary = dict(letters=0, digits=0, other=0) def summary_add(results): # this is called with a list of results for result in results: summary['letters'] += result['letters'] summary['digits'] += result['digits'] summary['other'] += result['other'] # count letters on this same script f = open(__file__, 'r') pool = multiprocessing.Pool(processes=6) # invoke count((lineno, line)) for each line in the file pool.map_async(count, enumerate(f), 10, summary_add) pool.close() # no more jobs pool.join() # wait until done print summary -- Gabriel Genellina From mdw at distorted.org.uk Fri Jan 9 18:40:07 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 9 Jan 2009 23:40:07 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > If one accepts that there are a "lot" of people who post in here that > clearly are surprised by Python's assignment semantics, But one should not accept that. One might accept that there are many who post who claim that they are surprised by Python's assignment semantics. Such people are wrong, however, since what they are surprised by is Python's data model, and one reason that they are surprised by Python's data model is because it's not actually explained very well. > and further appear to expect assignment to have copy-like semantics, This expectation is justified and, indeed, satisfied. Python does, most definitely, copy on assignment. What it copies is references, however. This might be clearer if the data model were explained better. As an aside, I don't notice anywhere near as much confusion in Lisp and Scheme groups, which might be surprising since Lisp and Scheme have precisely the same data model, argument passing convention, and assignment semantics, as Python has. There are many possible explanations: * The Lisp and Scheme communities are smaller. This is certainly true. But it wouldn't explain what appears to be a disproportionate level of confusion on the topic among Python beginners. * Individuals in the Lisp and Scheme communities are cleverer and/or more widely experienced. One might make an argument that this is true and a result of the relative community sizes -- basically a result of self-selection. But instead I'll reject this as an explanation. It's arrogant and unproven. * The Lisp and Scheme communities make a concerted effort to explain their data model clearly and precisely. They accept that it's actually quite complicated and, rather than pretend that it isn't, explain the complexity and the benefits it brings that make the complexity worthwhile. I think this is the likely one. > then where is that expectation coming from? > How would anyone develop that expectation if (from a different post in > this thread), "[Python's] idea of assignment is the same as anyone > else's." Because they've fundamentally misunderstood the data model. The very fact that their confusion is ascribed to the wrong thing is strongly indicative of this. > If you maintain that reference-like assignment is very common and > something every programmer is accustomed to, then where are they > getting the copy-like assignment expectations from? But it's not just assignment that deals with references. It's argument passing and storage of compound data as well. (See PLR 3.1.) They expect that assignment copies stuff, because that's what assignment does. Everywhere that I can think of -- except C++, which leaves assignment semantics in hands of the programmer. What they're confused about is what, precisely, it is that gets copied. And that, really, is a result of an inadequate understanding of the data model. > I agree that most of the time, when one is using large (memory) > composite "objects", and one needs to pass, or access them by > different names, one will often use references to do so in order to > avoid expensive copies or to get desired "shared" behavior. But (with > the exception of C arrays [*1]), doing so requires some special syntax > in all the languages I mentioned (AFAIK). Ummm... you mentioned C, C++, `Python, Java, REALbasic, .NET'. Well, C we've dealt with. C++ is weird. Python we all know, and is the main subject of the argument. REALbasic I don't know at all, but BASICs traditionally represent data fairly directly (rather than via references) so will largely be like C. .NET isn't a language at all: rather, it's a virtual machine, runtime system, class library and family of languages each of which may have idiosyncratic semantics. Which leaves Java. Java divides the world into `primitive' and `reference' types (4.1). The former are represented directly; the latter have a pointer to the true data as immediate representation. But observe that Java's primitive types are integer types (including its misnamed `char'), floating-point types, and booleans. Equivalent objects of all of these are immutable in Python -- and there is no observable difference (unless exposed by an operator like `is' or the `id' built-in) between a directly represented object and an /immutable/ object represented by reference. (I've no doubt that the original language designers were aware of this equivalence, so it's a mystery to me precisely why they specified the language as they did rather than leaving the messy business of boxing and unboxing primitive values to the compiler, which, given Java's mandatory type annotations, should have found the job trivial.) > So it still seems to me that this is a likely explanation to why there > is frequent misunderstanding of Python's assignments, and why > responding to such misunderstandings with, "Python's assignments are > the same as other languages'", is at best not helpful. That's why I'm not just saying that assignment is the same. I'm also saying that the data model is most definitely not the same as C. > I have often wished that C handled arrays the same way it does > structs. I am sure that the pointer-array pseudo-equivalence seemed > like a very clever idea at the time but I wonder if Dennis Richie ever > had second thoughts about it. Probably. But I think the idea was actually inherited from BCPL, via B. In BCPL, memory is divided into words. Depending on which operator you use, you can treat a particular word as an integer, a floating-point number, or a pointer. An array in BCPL is represented as a pointer to its first element -- always -- and you index it by an expression of the form p!i (a notation inherited by BBC BASIC and Haskell of all things). The array->pointer decay is a compromise position between the BCPL notion of array-as-pointer and the desire to allocate such things with automatic storage duration and have sizeof and so on work properly. -- [mdw] From bedouglas at earthlink.net Fri Jan 9 18:43:25 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 15:43:25 -0800 Subject: spawning pyhon apps... In-Reply-To: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> Message-ID: <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> hi jason.... forgive me... but in your sample: my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] are you spawning 'foo.py' 10 times? that can't be right! so just what is "foo.py" used for? what am i missing... it looks like the my_popenobjects array is iterated through to check the statuscode. is the statuscode the value that would be returned from a child python script via something like "return(2)".... i've seen mention of os.waitpid(..) does this play into waiting for child processes to complete, or determine if they've terminated?? thanks -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Jason Scheirer Sent: Friday, January 09, 2009 3:19 PM To: python-list at python.org Subject: Re: spawning pyhon apps... On Jan 9, 2:47?pm, "bruce" wrote: > hi... > > toying with an idea.. trying to figure out a good/best way to spawn multiple > python scripts from a parent python app. i'm trying to figure out how to > determine when all child apps have completed, or to possibly determine if > any of the child processes have died/halted.. > > parent app > ?spawn child1 > ?spawn child2 > ?spawn child3 > ?. > ?. > ?. > ?spawn childn > > do i iterate through a os.waitpid(pid) for each pid of the child processes i > create? > > is there another approach? code samples/tutorial...?? > > i've seen various approaches via google, but not just what i'm looking for.. > > thanks Investigate the subprocess module, you probably want Popen objects. You can do a poll loop like my_popenobjects = [subprocess.Popen("foo.py", "--filename=file %i.txt"%x) for x in xrange(10)] while any(popenobject.statuscode is None for popenobject in my_popenobjects): time.sleep(0.25) If your tasks are more like function calls and less like shell scripts, then investigate writing your python as an importable module and use the multiprocessing module, which will do threading/ subprocessing for you. -- http://mail.python.org/mailman/listinfo/python-list From nad at acm.org Fri Jan 9 18:46:28 2009 From: nad at acm.org (Ned Deily) Date: Fri, 09 Jan 2009 15:46:28 -0800 Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: In article <07832575-9b98-4a03-a181-4470a5a00fd6 at 35g2000pry.googlegroups.com>, googler.1.webmaster at spamgourmet.com wrote: > hm... any ideas? Have you tried specifying one of the universal SDKs, i.e. /Developer/SDKs/MacOSX10.n.sdk? That's what the "official" python.org builds do. The build script for the batteries-included installer is in the source tar ball at Mac/BuildScript/build-installer.py. FWIW, I made a universal (4-way) batteries-included framework build for 2.6 on 10.5 with the following patch to that script: --- build-installer.py.bak 2008-12-17 20:02:59.000000000 -0800 +++ build-installer.py 2008-12-17 23:18:57.000000000 -0800 @@ -1,12 +1,9 @@ -#!/usr/bin/python2.3 +#!/usr/bin/python2.5 """ This script is used to build the "official unofficial" universal build on -Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its +Mac OS X. It requires Mac OS X 10.5, Xcode 3.0 and the 10.5u SDK to do its work. -Please ensure that this script keeps working with Python 2.3, to avoid -bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) - Usage: see USAGE variable in the script. """ import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd @@ -65,10 +62,10 @@ DEPSRC = os.path.expanduser('~/Universal/other-sources') # Location of the preferred SDK -SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" +SDKPATH = "/Developer/SDKs/MacOSX10.5.sdk" #SDKPATH = "/" -ARCHLIST = ('i386', 'ppc',) +ARCHLIST = ('i386', 'ppc', 'x86_64', 'ppc64', ) # Source directory (asume we're in Mac/BuildScript) SRCDIR = os.path.dirname( @@ -630,7 +627,7 @@ version = getVersion() print "Running configure..." - runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( + runCommand("%s -C --enable-framework --enable-universalsdk=%s --with-universal-archs=all LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1])) @@ -1017,7 +1014,7 @@ parseOptions() checkEnvironment() - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' + os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.5' if os.path.exists(WORKDIR): shutil.rmtree(WORKDIR) -- Ned Deily, nad at acm.org From bhood37 at hotmail.com Fri Jan 9 18:50:26 2009 From: bhood37 at hotmail.com (Uberman) Date: Fri, 09 Jan 2009 16:50:26 -0700 Subject: Why can't I store a DLL in a module library Zip file? Message-ID: I'm using Python 2.5.1, and I'm trying to use the module library as a Zip file (for example, with python25_d.dll, the module library file would be called python25_d.zip). This works for the basic modules that come with Python (os, sys, site, etc.), and it even seems to work when I place my own Python-based modules within the Zip file (e.g., my_module.py). My Python modules are found within the library Zip file. However, my Python module is dependent upon a SWIG-generated shared library, which also has it's own Python module. When placed into the Zip file, the SWIG Python module is found, but the shared library file (the compiled C shared library) is not. I've stepped through the Python code to try and see what's happening, but when it comes to looking in the Zip file (python25_d.zip) for this shared library (*.pyd), it won't find it. When I place all the files in the same folder as the executable (outside the python25_d.zip) file, they are found by the run-time system, and everything is happy. I've also tried a properly constructed 'site-package' within the Zip file, with the SWIG-generated files contained within, but that doesn't work either. It's almost like shared libraries are disallowed from the module library Zip format. Is there a trick, or some special location where it needs to be placed? Any help with this would be appreciated. Thanks. From google at mrabarnett.plus.com Fri Jan 9 18:52:02 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jan 2009 23:52:02 +0000 Subject: BadZipfile "file is not a zip file" In-Reply-To: <4967DA10.6080502@mrabarnett.plus.com> References: <7c960ca8-484d-4a37-958f-ecb0466a997b@v18g2000pro.googlegroups.com> <4967DA10.6080502@mrabarnett.plus.com> Message-ID: <4967E322.1000909@mrabarnett.plus.com> MRAB wrote: > webcomm wrote: >> On Jan 8, 8:39 pm, "James Mills" wrote: >>> Send us a sample of this file in question... >> >> Here's a sample with some dummy data from the web service: >> http://webcomm.webfactional.com/htdocs/data.zip >> >> That's the zip created in this line of my code... >> f = open('data.zip', 'wb') >> >> If I open the file it contains as unicode in my text editor (EditPlus) >> on Windows XP, there is ostensibly nothing wrong with it. It looks >> like valid XML. But if I return it to my browser with python+django, >> there are bad characters every other character >> >> If I unzip it like this... >> popen("unzip data.zip") >> ...then the bad characters are 'FFFD' characters as described and >> pictured here... >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> >> If I unzip it like this... >> getzip('data.zip', ignoreable=30000) >> ...using Scott's function at... >> http://groups.google.com/group/comp.lang.python/msg/c2008e48368c6543 >> ...then the bad characters are \x00 characters. >> > I can unzip it in Windows XP. The file within it (called "data") is XML > encoded as UTF-16LE (2 bytes per character, low byte first), but without > the initial byte order mark. Python's zipfile module says "BadZipfile: > File is not a zip file". > If I strip off all but the last 4 zero-bytes then the zipfile module can open it: decoded = base64.b64decode(datum) five_zeros = chr(0) * 5 while decoded.endswith(five_zeros): decoded = decoded[ : -1] f = open('data.zip', 'wb') f.write(decoded) f.close() x = zipfile.ZipFile('data.zip', 'r') From clp2 at rebertia.com Fri Jan 9 18:53:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jan 2009 15:53:21 -0800 Subject: spawning pyhon apps... In-Reply-To: <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> References: <8d722eb7-4bc8-4c62-8656-87bc9e650756@v13g2000vbb.googlegroups.com> <07b101c972b4$11abc7c0$0301a8c0@tmesa.com> Message-ID: <50697b2c0901091553s73cb1f82id4c196fb93e4527c@mail.gmail.com> On Fri, Jan 9, 2009 at 3:43 PM, bruce wrote: > hi jason.... > > forgive me... but in your sample: > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! Indeed, it probably ought to be (note the 2nd pair of brackets): my_popenobjects = [subprocess.Popen(["foo.py", "--filename=file%i.txt"%x]) for x in xrange(10)] > so just what is "foo.py" used for? what am i missing... It's the name of the program you want to run. In this case, it happens to be a Python script. > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... It's the POSIX exit code of the program (i.e. what int you return from main() in a C program, or what you pass to sys.exit() in Python) > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? Don't know specifically, but that's another, lower-level API. The `subprocess` module is superior. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jason.scheirer at gmail.com Fri Jan 9 18:59:24 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 15:59:24 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <4337c89e-f623-4dd5-b9a7-be66ca107f43@l39g2000yqn.googlegroups.com> On Jan 9, 3:43?pm, "bruce" wrote: > hi jason.... > > forgive me... but in your sample: > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > ? ? ? ? %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! > so just what is "foo.py" used for? what am i missing... > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... > > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:19 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 2:47?pm, "bruce" wrote: > > hi... > > > toying with an idea.. trying to figure out a good/best way to spawn > multiple > > python scripts from a parent python app. i'm trying to figure out how to > > determine when all child apps have completed, or to possibly determine if > > any of the child processes have died/halted.. > > > parent app > > ?spawn child1 > > ?spawn child2 > > ?spawn child3 > > ?. > > ?. > > ?. > > ?spawn childn > > > do i iterate through a os.waitpid(pid) for each pid of the child processes > i > > create? > > > is there another approach? code samples/tutorial...?? > > > i've seen various approaches via google, but not just what i'm looking > for.. > > > thanks > > Investigate the subprocess module, you probably want Popen objects. > You can do a poll loop like > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > > while any(popenobject.returncode is None for popenobject in > my_popenobjects): > ? time.sleep(0.25) > > If your tasks are more like function calls and less like shell > scripts, then investigate writing your python as an importable module > and use the multiprocessing module, which will do threading/ > subprocessing for you. > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. Foo.py is the hypothetical Python script you want to run in a subprocess. In this example, I have an external shell script named foo.py, and I am indeed spawning 10 copies of it, each with a second argument that varies (foo.py --filename=file0.txt, foo.py -- filename=file1.txt, ... foo.py --filename=file9.txt). You don't need os.waitpid() with a Popen object, there is a Popen.wait() method you can call which will accomplish the exact same thing. I'm polling the Popen.returncode for each process' return code (which is the numeric code a process returns when it finishes, like sys.exit(x) or return, or gives None if it's not done yet. What this sample is doing is opening 10 copies of the script and running them in parallel, if you want to run it is serial then you can do a simple for loop and .wait() on each: for cmd in ('a', 'b', 'c'): sp = subprocess.Popen(cmd) sp.wait() print "Command %r completed with status %i" % (cmd, sp.returncode) I'm still not 100% sure what you're trying to accomplish. What is the exact problem you are wishing to solve? From martin at v.loewis.de Fri Jan 9 19:03:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 10 Jan 2009 01:03:11 +0100 Subject: Why can't I store a DLL in a module library Zip file? In-Reply-To: References: Message-ID: <4967E5BF.3070707@v.loewis.de> > It's almost like shared libraries are disallowed from the module > library Zip format. Correct. That's a limitation of the Windows operating system, which can load DLLs only from plain, regular files. Python can load .py files from zip files because it implements the loading itself. For DLL loading, it must use the OS routines, which just don't look into zipfiles. Regards, Martin From bedouglas at earthlink.net Fri Jan 9 19:07:36 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 9 Jan 2009 16:07:36 -0800 Subject: spawning pyhon apps... In-Reply-To: <4337c89e-f623-4dd5-b9a7-be66ca107f43@l39g2000yqn.googlegroups.com> Message-ID: <07b801c972b7$73cbfda0$0301a8c0@tmesa.com> thanks jason.... or i could also, simply iterate through a loop of the names of the "child processes" i want to spawn, using the names in the subprocess.popen, and then proceeding with the rest of your example.. question though... if i have a child app that's hanging.. how do i kill it. or is this getting into the aspect of using interprocess pipes, where if the parent isn't getting a 'live ping' via the pipe back from the child after a certain amount of time... it could kill the child... thoughts/comments... thanks -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Jason Scheirer Sent: Friday, January 09, 2009 3:59 PM To: python-list at python.org Subject: Re: spawning pyhon apps... On Jan 9, 3:43?pm, "bruce" wrote: > hi jason.... > > forgive me... but in your sample: > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > ? ? ? ? %i.txt"%x) for x in xrange(10)] > are you spawning 'foo.py' 10 times? that can't be right! > so just what is "foo.py" used for? what am i missing... > > it looks like the my_popenobjects array is iterated through to check the > statuscode. is the statuscode the value that would be returned from a child > python script via something like "return(2)".... > > i've seen mention of os.waitpid(..) does this play into waiting for child > processes to complete, or determine if they've terminated?? > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:19 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 2:47?pm, "bruce" wrote: > > hi... > > > toying with an idea.. trying to figure out a good/best way to spawn > multiple > > python scripts from a parent python app. i'm trying to figure out how to > > determine when all child apps have completed, or to possibly determine if > > any of the child processes have died/halted.. > > > parent app > > ?spawn child1 > > ?spawn child2 > > ?spawn child3 > > ?. > > ?. > > ?. > > ?spawn childn > > > do i iterate through a os.waitpid(pid) for each pid of the child processes > i > > create? > > > is there another approach? code samples/tutorial...?? > > > i've seen various approaches via google, but not just what i'm looking > for.. > > > thanks > > Investigate the subprocess module, you probably want Popen objects. > You can do a poll loop like > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > %i.txt"%x) for x in xrange(10)] > > while any(popenobject.returncode is None for popenobject in > my_popenobjects): > ? time.sleep(0.25) > > If your tasks are more like function calls and less like shell > scripts, then investigate writing your python as an importable module > and use the multiprocessing module, which will do threading/ > subprocessing for you. > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. Foo.py is the hypothetical Python script you want to run in a subprocess. In this example, I have an external shell script named foo.py, and I am indeed spawning 10 copies of it, each with a second argument that varies (foo.py --filename=file0.txt, foo.py -- filename=file1.txt, ... foo.py --filename=file9.txt). You don't need os.waitpid() with a Popen object, there is a Popen.wait() method you can call which will accomplish the exact same thing. I'm polling the Popen.returncode for each process' return code (which is the numeric code a process returns when it finishes, like sys.exit(x) or return, or gives None if it's not done yet. What this sample is doing is opening 10 copies of the script and running them in parallel, if you want to run it is serial then you can do a simple for loop and .wait() on each: for cmd in ('a', 'b', 'c'): sp = subprocess.Popen(cmd) sp.wait() print "Command %r completed with status %i" % (cmd, sp.returncode) I'm still not 100% sure what you're trying to accomplish. What is the exact problem you are wishing to solve? -- http://mail.python.org/mailman/listinfo/python-list From sjmachin at lexicon.net Fri Jan 9 19:11:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 16:11:10 -0800 (PST) Subject: Problem with -3 switch References: Message-ID: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> On Jan 10, 6:58?am, Carl Banks wrote: > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > Aivar Annamaa wrote: > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > >> switch only points out problems that the 2to3 converter tool can't > > > >> automatically fix. Changing print to print() on the other hand is > > > >> easily fixed by 2to3. > > > > >> Cheers, > > > >> Chris > > > > > I see. > > > > So i gotta keep my own discipline with print() then :) > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > it as Python 3.x code. > > > > regards > > > ?Steve > > > And mind you, if you follow that route, you are programming in a > > mightily crippled language. > > How do you figure? > > I expect that it'd be a PITA in some cases to use the transitional > dialect (like getting all your Us in place), but that doesn't mean the > language is crippled. What is this "transitional dialect"? What does "getting all your Us in place" mean? Steve & Cliff are talking about the rather small subset of Python that is not only valid syntax in both 2.x and 3.x but also has the same meaning in 2.x and 3.x. > > >?It's about as bad as trying to write > > cross-browser CSS. ?Don't put yourself through that pain if you don't > > have to. > > Have you tried doing that, or are you imagining how it will be? ?I'm > curious about people's actual experiences. I maintain two packages, xlrd which supports 2.1 to 2.6, and xlwt which supports 2.3 to 2.6. I've done suck-it-and-see trials on being able to support 3.x as well from the same codebase, and it's turned out reasonably well. xlrd already had a module called timemachine which caters for version- dependent stuff. Extending this to 3.x was more a voyage of discovery than a PITA. timemachine.py is "crippled" in Cliff's sense, in that because I'm the principal user I need to make it robust and idiot-proof, so it has been written under the following constraints: (1) not one copy of timemachine.py for 2.1, one for 2.2, one for 2.3, ... etc; just one copy, period. (2) means that it must use syntax that's valid in all supported versions (3) must be able to be processed by 2to3 without causing a commotion (4) the original version and the 2to3 output must have the same effect when imported by 3.x. So one ends up with code like: glued = BYTES_NULL.join(list_of_pieces_of_a_binary_file) which is supported by timemachine definitions like BYTES_NULL = bytes(0) # 3.x ... note b'' is not valid in 2.x BYTES_NULL = '' # 2.x BYTES_NULL.join() may be ugly, but it's not crippled, it's fully functional, and it would be very easy to find and change in the future in two possible scenarios (1) drop 2.x support (2) change codebase to be mostly 3.x, support 2.x by a (mythical, hoped-for) 3to2 mechanism. > Problem is, a lot of people use the "bang at it with a hammer till it > works" approach to programming, and really have no shame when it comes > to engaging in questionable practices like relying on accidental side > effects, rather than taking the time to try to program robustly. ?I > expect people with that style of programming will have many more > issues with the transition. Those with many more issues are likely to be those who don't have adequate tests and/or can't debug their way out of a wet paper bag -- could well be we're talking about the same bunch :-) Cheers, John From joe at strout.net Fri Jan 9 19:11:12 2009 From: joe at strout.net (Joe Strout) Date: Fri, 09 Jan 2009 17:11:12 -0700 Subject: why cannot assign to function call In-Reply-To: References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <4967E7A0.8050502@strout.net> Mark Wooding wrote: > As an aside, I don't notice anywhere near as much confusion in Lisp and > Scheme groups, which might be surprising since Lisp and Scheme have > precisely the same data model, argument passing convention, and > assignment semantics, as Python has. Nor is there anywhere near as much confusion in the REALbasic community (with which I'm most familiar), which also has the same semantics for reference types (which in RB is everything except numbers, colors, and Boolean). Apparently there is occasionally a little confusion in the Java community, but it rarely reaches the sillyness proportions seen here: > * The Lisp and Scheme communities are smaller. This is certainly > true. But it wouldn't explain what appears to be a disproportionate > level of confusion on the topic among Python beginners. > > * Individuals in the Lisp and Scheme communities are cleverer and/or > more widely experienced. One might make an argument that this is > true and a result of the relative community sizes -- basically a > result of self-selection. But instead I'll reject this as an > explanation. It's arrogant and unproven. > > * The Lisp and Scheme communities make a concerted effort to explain > their data model clearly and precisely. They accept that it's > actually quite complicated and, rather than pretend that it isn't, > explain the complexity and the benefits it brings that make the > complexity worthwhile. I think this is the likely one. That's a nice way of putting it. I might go a step further and say that there is a small but vocal portion of the Python community that insists on confounding the issue by claiming that Python's assignment and parameter-passing conventions are different from other languages. (Which, of course, requires one's head to be firmly in the sand with regard to the basic fact that Python variables contain references, not objects.) > But it's not just assignment that deals with references. It's argument > passing and storage of compound data as well. (See PLR 3.1.) > > They expect that assignment copies stuff, because that's what assignment > does. Everywhere that I can think of -- except C++, which leaves > assignment semantics in hands of the programmer. What they're confused > about is what, precisely, it is that gets copied. And that, really, is > a result of an inadequate understanding of the data model. I have nothing to add to this. It just seem well worth quoting. :) >> I agree that most of the time, when one is using large (memory) >> composite "objects", and one needs to pass, or access them by >> different names, one will often use references to do so in order to >> avoid expensive copies or to get desired "shared" behavior. But (with >> the exception of C arrays [*1]), doing so requires some special syntax >> in all the languages I mentioned (AFAIK). > > Ummm... you mentioned C, C++, `Python, Java, REALbasic, .NET'. No, actually, that was me. rurpy's list was something like C, FORTRAN, Perl, and VBA. > Well, C we've dealt with. C++ is weird. Python we all know, and is the > main subject of the argument. REALbasic I don't know at all, but BASICs > traditionally represent data fairly directly (rather than via > references) so will largely be like C. Not REALbasic. It's a very modern language with semantics pretty much identical to Java. Simple types (numbers, colors, Booleans) are stored directly; all other types (including strings, objects, and arrays) are stored on the heap and accessed via references. > .NET isn't a language at all: > rather, it's a virtual machine, runtime system, class library and family > of languages each of which may have idiosyncratic semantics. But they don't, AFAIK -- they all have the same semantics; only the surface syntax differs. And those semantics are the same as REALbasic and Java. See for some side-by-side comparisons. > Which leaves Java. Java divides the world into `primitive' and > `reference' types (4.1). The former are represented directly; the > latter have a pointer to the true data as immediate representation. Right -- a very common pattern among modern languages. >> So it still seems to me that this is a likely explanation to why there >> is frequent misunderstanding of Python's assignments, and why >> responding to such misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > That's why I'm not just saying that assignment is the same. I'm also > saying that the data model is most definitely not the same as C. Technically true, in that pointers in C require some special syntax, but the common idiom is to hide this away by defining a new type: typedef Foo* FooPtr; Now, for any code using the "FooPtr" type, the data model is the same as Python (or as Java, RB, .NET, etc., again for code that's using only reference types). Best, - Joe From jason.scheirer at gmail.com Fri Jan 9 19:11:46 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 9 Jan 2009 16:11:46 -0800 (PST) Subject: spawning pyhon apps... References: Message-ID: <045737d6-e44c-4f1f-b79e-d87f2cbc7d72@f11g2000vbf.googlegroups.com> On Jan 9, 4:07?pm, "bruce" wrote: > thanks jason.... > > or i could also, simply iterate through a loop of the names of the "child > processes" i want to spawn, using the names in the subprocess.popen, and > then proceeding with the rest of your example.. > > question though... if i have a child app that's hanging.. how do i kill it. > > or is this getting into the aspect of using interprocess pipes, where if the > parent isn't getting a 'live ping' via the pipe back from the child after a > certain amount of time... it could kill the child... > > thoughts/comments... > > thanks > > -----Original Message----- > From: python-list-bounces+bedouglas=earthlink.... at python.org > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > Of Jason Scheirer > Sent: Friday, January 09, 2009 3:59 PM > To: python-l... at python.org > Subject: Re: spawning pyhon apps... > > On Jan 9, 3:43?pm, "bruce" wrote: > > hi jason.... > > > forgive me... but in your sample: > > ? ? ? ? my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > > ? ? ? ? %i.txt"%x) for x in xrange(10)] > > are you spawning 'foo.py' 10 times? that can't be right! > > so just what is "foo.py" used for? what am i missing... > > > it looks like the my_popenobjects array is iterated through to check the > > statuscode. is the statuscode the value that would be returned from a > child > > python script via something like "return(2)".... > > > i've seen mention of os.waitpid(..) does this play into waiting for child > > processes to complete, or determine if they've terminated?? > > > thanks > > > -----Original Message----- > > From: python-list-bounces+bedouglas=earthlink.... at python.org > > > [mailto:python-list-bounces+bedouglas=earthlink.... at python.org]On Behalf > > Of Jason Scheirer > > Sent: Friday, January 09, 2009 3:19 PM > > To: python-l... at python.org > > Subject: Re: spawning pyhon apps... > > > On Jan 9, 2:47?pm, "bruce" wrote: > > > hi... > > > > toying with an idea.. trying to figure out a good/best way to spawn > > multiple > > > python scripts from a parent python app. i'm trying to figure out how to > > > determine when all child apps have completed, or to possibly determine > if > > > any of the child processes have died/halted.. > > > > parent app > > > ?spawn child1 > > > ?spawn child2 > > > ?spawn child3 > > > ?. > > > ?. > > > ?. > > > ?spawn childn > > > > do i iterate through a os.waitpid(pid) for each pid of the child > processes > > i > > > create? > > > > is there another approach? code samples/tutorial...?? > > > > i've seen various approaches via google, but not just what i'm looking > > for.. > > > > thanks > > > Investigate the subprocess module, you probably want Popen objects. > > You can do a poll loop like > > > my_popenobjects = [subprocess.Popen("foo.py", "--filename=file > > %i.txt"%x) for x in xrange(10)] > > > while any(popenobject.returncode is None for popenobject in > > my_popenobjects): > > ? time.sleep(0.25) > > > If your tasks are more like function calls and less like shell > > scripts, then investigate writing your python as an importable module > > and use the multiprocessing module, which will do threading/ > > subprocessing for you. > > --http://mail.python.org/mailman/listinfo/python-list > > Correction: statuscode is wrong. It's returncode. > > Foo.py is the hypothetical Python script you want to run in a > subprocess. In this example, I have an external shell script named > foo.py, and I am indeed spawning 10 copies of it, each with a second > argument that varies (foo.py --filename=file0.txt, foo.py -- > filename=file1.txt, ... foo.py --filename=file9.txt). You don't need > os.waitpid() with a Popen object, there is a Popen.wait() method you > can call which will accomplish the exact same thing. I'm polling the > Popen.returncode for each process' return code (which is the numeric > code a process returns when it finishes, like sys.exit(x) or return, > or gives None if it's not done yet. What this sample is doing is > opening 10 copies of the script and running them in parallel, if you > want to run it is serial then you can do a simple for loop and .wait() > on each: > > for cmd in ('a', 'b', 'c'): > ? sp = subprocess.Popen(cmd) > ? sp.wait() > ? print "Command %r completed with status %i" % (cmd, sp.returncode) > > I'm still not 100% sure what you're trying to accomplish. What is the > exact problem you are wishing to solve? > --http://mail.python.org/mailman/listinfo/python-list > > Yes, so to open your processes you can loop over a list of commands and create new subprocess.Popen(cmd) objects for each. Everything is explained: http://docs.python.org/library/subprocess.html#popen-objects You can do .terminate() to kill a process that may be hanging, you can get the .stdout and poll on its .read() to see if it's still putting anything out to the console. From rurpy at yahoo.com Fri Jan 9 19:21:27 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 16:21:27 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Joe Strout wrote: > rurpy at yahoo.com wrote: > >>> I never claimed that you *couldn't* have copy semantics in C; you can do >>> almost anything you want in C (or C++). But the *normal* usage of an >>> array is via a pointer, in which case the semantics are exactly the same >>> as in Python, Java, REALbasic, .NET, etc. >> >> Arrays are the only datatype in C that don't use >> copy-like assignment. Everything else does. > > No, arrays are just one reference type; pointers are another (and in > most ways, these are the same thing). Pointers are passed and assigned by value, just as other types (disputedly except arrays) are. One can then use that pointer to manually effect pass-(the-value-pointed-to)-by-reference, or sharing, etc. > When dealing with objects in C++, > one routinely handles them with pointers, so that's the use case which > is analogous to Python -- all the value types can be ignored for the > sake of comparison. (C is not an OOP language, of course, but even > there, all but the most trivial of structs are usually allocated on the > heap and passed around via pointers, just like in C++, Java, .NET, RB, > and Python.) In C (you have to explicitly ask for a reference (pointer) to something (other than arrays) if you want to use/pass a reference to something. If you simply use the name, you get by-value semantics. >>> Ah. OK then, I guess I missed you're point. You're absolutely right; >>> many languages have both reference types and value types. Python is a >>> bit unusual in that it has only reference types. I would have picked a >>> different example to illustrate that, but it's true nonetheless. >> >> If one accepts that there are a "lot" of people >> who post in here that clearly are surprised by >> Python's assignment semantics, and further appear >> to expect assignment to have copy-like semantics, >> then where is that expectation coming from? > > I think it comes from people stumbling across posts in this forum > claiming that Python has unusual assignment semantics. I wish people > would stop saying that, as it causes a lot of confusion. > >> How would anyone develop that expectation if (from >> a different post in this thread), "[Python's] idea >> of assignment is the same as anyone else's." > > I can think of two ways: > > 1. They're new to programming in general, and would have had the same > expectation for any other language. OR, IIRC, Someone posted here that his experience was that 12-year old kids (presumably without programming experience) had no problem with Python and references when described as "names given to an object". (From memory, can't locate the post right now.) > 2. They already understand some other language, and then they come here > and read wild claims that Python's assignment and parameter-passing > semantics are different from other languages. Duped by this claim, they > conclude that, if it's unlike other languages, then Python must have > copy semantics. I have seen no evidence of that. If it were true I would expect at least some posts to refer to reading those "wild claims". >> If you maintain that reference-like assignment >> is very common and something every programmer is >> accustomed to, then where are they getting the >> copy-like assignment expectations from? > > Reference-like assignment IS very common (see > ). So, see above. > >> I agree that most of the time, when one is using >> large (memory) composite "objects", and one needs >> to pass, or access them by different names, one will >> often use references to do so in order to avoid >> expensive copies or to get desired "shared" behavior. > > Right. > >> But (with the exception of C arrays [*1]), doing so >> requires some special syntax in all the languages I >> mentioned (AFAIK). > > Whether you consider it "special" or not, pointers are extremely common > in C. Even more so in C++, which is the closest thing to an OOP > language in the list of moldy languages you mentioned. Non-special is "b = a". > You also mentioned VBA -- if that's anything like VB, it does NOT > require any special syntax; a variable is a reference type if its > declared type is a class or string, and a simple type if it's anything > else (just like in .NET, Java, and REALbasic). It (mercifully) been a long time since I've used VB but the VB code I posted does run, and does exhibit by-value assignment behavior. My faint recollection is that if you want to assign a reference you cannot write, "b = a" but must instead write "set b = a". "b = a" assigns by value. In Perl it is definitely true that you different syntax: @a = (1,2,3) @b = @a # Copy $b = \@a # Reference C is the same way for everything (including pointers) except arrays: struct {...} foo; foo a, b *bp; b = a; # Copy bp = &a; # Reference >> So it still seems to me that this is a likely >> explanation to why there is frequent misunderstanding >> of Python's assignments, and why responding to such >> misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > I don't think so. More likely, people are being confused by the claim > that Python's assignments are NOT like other languages, when in fact > they are. It may be one can make a technical case that assignment is the same, but the reason I posted the code and results, was because the behavior of "=" in them produces clearly different results that "=" in Python. If you want to then say to someone, "ignore those different results, '=' works exactly the same", all I can say is good luck. I will look forward to continuing to see weekly questions on this list. :-) From mdw at distorted.org.uk Fri Jan 9 19:24:53 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 00:24:53 +0000 (UTC) Subject: spawning pyhon apps... References: Message-ID: bruce wrote: > toying with an idea.. trying to figure out a good/best way to spawn > multiple python scripts from a parent python app. i'm trying to figure > out how to determine when all child apps have completed, or to > possibly determine if any of the child processes have died/halted.. You don't say what platform you're using, but you mention os.waitpid so I'll randomly assume it's Unix-like. > do i iterate through a os.waitpid(pid) for each pid of the child > processes i create? That will technically work, and give you the information you wanted, though not necessarily in the most timely fashion. It'll block on each process in turn, waiting for its exit status -- so it'll finish as soon as all the children are dead, but if (say) the fifth process dies first, you won't find out until the first four have also passed on. If you don't have anything better for your program to do, and you're really on Unix, you can call kid, status = os.waitpid(0, 0) to wait for something to happen to any of your process's children; the kid is the process-id of the child being reported and the status is what happened to it. If you do have other things for your process to be doing, then your best bet is to establish a signal handler for SIGCHLD and installing a handler of the form import signal as S import os as OS import errno as E ## Children sometimes die. It's sad. def sigchld(sig, frame): try: while True: kid, status = OS.waitpid(0, OS.WNOHANG) if kid == 0: break ## Handle death of KID here. except OSError, err: if err.errno != E.ECHILD: raise ### ... ## Establish handler. S.signal(S.SIGCHLD, sigchld) should work. If you're running on Windows then these tricks won't work. As a grim hack, you could start a thread per child process and have each thread wait for its own child (sending the exit status through a queue or something). I'm afraid I don't know Windows well enough to offer slicker solutions; maybe someone else can help. -- [mdw] From benjamin.kaplan at case.edu Fri Jan 9 19:25:42 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 9 Jan 2009 19:25:42 -0500 Subject: why cannot assign to function call In-Reply-To: <4967E7A0.8050502@strout.net> References: <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <4967E7A0.8050502@strout.net> Message-ID: On Fri, Jan 9, 2009 at 7:11 PM, Joe Strout wrote: > Mark Wooding wrote: > > > .NET isn't a language at all: >> rather, it's a virtual machine, runtime system, class library and family >> of languages each of which may have idiosyncratic semantics. >> > > But they don't, AFAIK -- they all have the same semantics; only the surface > syntax differs. And those semantics are the same as REALbasic and Java. > They do in fact differ. You can have Visual C++ compile to CLI, in which case you have the C++ assignment in .NET, you can use VisualBasic, in which you can specify pass-by-value or -reference when you pass arguments to methods, and you have Visual C#, which copies Java's model and is therefore the same as Python. > > See for some side-by-side > comparisons. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 9 19:33:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 16:33:11 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> Message-ID: <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> On Jan 10, 9:52?am, webcomm wrote: > On Jan 9, 5:21?pm, John Machin wrote: > > > Thanks. Would you mind spending a few minutes more on this so that we > > can see if it's a problem that can be fixed easily, like the one that > > Chris Mellon reported? > > Don't mind at all. ?I'm now working with a zip file with some dummy > data I downloaded from the web service. ?You'll notice it's a smaller > archive than the one I was working with when I ran zip_susser.py, but > it has the same problem (whatever the problem is). You mean it produces the same symptom. The zipfile.py has several paths to the symptom i.e. the uninformative "bad zipfile" exception; we don't know which path, yet. That's why Martin was suggesting that you debug the sucker; that's why I'm trying to do it for you by remote control. It is not impossible for a file with dummy data to have been handcrafted or otherwise produced by a process different to that used for a real-data file. Please run v2 of the gadget on the real-data zip and report the results. >?It's the one I > uploaded tohttp://webcomm.webfactional.com/htdocs/data.zip > > Here's what I get when I run zip_susser_v2.py... > > archive size is 1092 > FileHeader at 0 > CentralDir at 844 > EndArchive at 894 > using posEndArchive = 894 > endArchive: ('PK\x05\x06', 0, 0, 1, 1, 50, 844, 0) > ? ? ? ? ? ? ? ? ? ? ? ? signature : 'PK\x05\x06' > ? ? ? ? ? ? ? ? ? ? this_disk_num : 0 > ? ? ? ? ? ? ?central_dir_disk_num : 0 > central_dir_this_disk_num_entries : 1 > ? central_dir_overall_num_entries : 1 > ? ? ? ? ? ? ? ? ?central_dir_size : 50 > ? ? ? ? ? ? ? ?central_dir_offset : 844 > ? ? ? ? ? ? ? ? ? ? ?comment_size : 0 > > expected_comment_size: 0 > actual_comment_size: 176 > comment is all spaces: False > comment is all '\0': True > comment (first 100 bytes): > '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0?0\x00 > \x00\x00\x00\x00\x00\x00\x00' > > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick with one thread ... From stutsman at cs.stanford.edu Fri Jan 9 19:39:24 2009 From: stutsman at cs.stanford.edu (Ryan Stutsman) Date: Fri, 09 Jan 2009 16:39:24 -0800 Subject: Common path all PyObjects take on destruction? Message-ID: <874p08t2o3.fsf@stutsman-jos64.scs.stanford.edu> I've added a field to all PyObjects in the interpreter which is of type PyObject*. Most of the time this pointer is NULL but occassionally I want to track some information in there. The problem I'm running into is that I can add a reference to a PyObject inside any of my PyObjects, but it seems that there isn't any one path that all objects follow on destruction so that I can later Py_DECREF that reference. Eventually most of the types seem to call PyObject_Free, but this gets called with void* and it seems it isn't always the case that PyObject*s are passed in. Where is the best place to implement something like this? It really won't work to implement this in the destructor of each of the individual types because other types added later won't know to DECREF this field on destruction. Any hints would be appreciated. Hopefully I'm just missing something simple. From googler.1.webmaster at spamgourmet.com Fri Jan 9 19:47:31 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 16:47:31 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: hi, thanks for your help. May the diff file is wrong? on my system it doesn't work. Well, set the -enable-universalsdk= path occurs that error. Hmm. that is really a disaster, isn't it :( hm. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 9 20:14:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 01:14:48 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0177ed3f$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 21:03:39 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> Python doesn't do the same thing as C. It actually passes the same >> value to the function, without copying it. >> >> Why oh why do you keep insisting that Python is no different from C? > > I'm beginning to think that you're not bothing to read what I'm writing, Er, perhaps you missed that I was replying to Joe Strout. Joe wrote: "The reference itself is passed in, not the variable (or expression) that held or generated the reference in the calling code. This is no different from, in C, passing an integer:" I'm pretty sure I clearly quoted Joe in my post. Perhaps you missed it. In any case, I'm happy for you to contribute (it's a public forum), but how do you conclude I'm not reading *your* posts because I disagree with Joe's claim that Python is just like C? -- Steven From grante at visi.com Fri Jan 9 20:25:14 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 09 Jan 2009 19:25:14 -0600 Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: On 2009-01-10, Joe Strout wrote: > Mark Wooding wrote: > >> As an aside, I don't notice anywhere near as much confusion in Lisp and >> Scheme groups, which might be surprising since Lisp and Scheme have >> precisely the same data model, argument passing convention, and >> assignment semantics, as Python has. > > Nor is there anywhere near as much confusion in the REALbasic > community (with which I'm most familiar), which also has the > same semantics for reference types (which in RB is everything > except numbers, colors, and Boolean). It's not that there's a lot of confusion, it's just that we spend a lot of time talking about it. Programming in Python is so much more productive that we've got a lot more spare time that people who use other languages. -- Grant From sjmachin at lexicon.net Fri Jan 9 20:49:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 17:49:05 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> On Jan 9, 9:56?pm, mk wrote: > The factor of 30 indeed does not seem right -- I have done somewhat > similar stuff (calculating Levenshtein distance [edit distance] on words > read from very large files), coded the same algorithm in pure Python and > C++ (using linked lists in C++) and Python version was 2.5 times slower. Levenshtein distance using linked lists? That's novel. Care to divulge? And if C++ is using linked lists and Python isn't, it's not really the same algorithm, is it? Cheers, John From nad at acm.org Fri Jan 9 20:49:55 2009 From: nad at acm.org (Ned Deily) Date: Fri, 09 Jan 2009 17:49:55 -0800 Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: In article , googler.1.webmaster at spamgourmet.com wrote: > May the diff file is wrong? on my system it doesn't work. > Well, set the -enable-universalsdk= path occurs that error. Sorry, there were a few line wrap-arounds in the diff file due to long lines but the changes for the four significant lines should be easy to do manually. Note that the build I made this way has not been tested on ppc64 and has had minimal testing so far on x64_64. -- Ned Deily, nad at acm.org From googler.1.webmaster at spamgourmet.com Fri Jan 9 20:54:00 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 9 Jan 2009 17:54:00 -0800 (PST) Subject: Python 2.6 fails on compiling > Bug report References: <323e9e9c-c881-48b8-97ef-6e9fdf4e04b6@a26g2000prf.googlegroups.com> <91289c1e-d0ef-450b-9189-25cdd66b8fed@g1g2000pra.googlegroups.com> <07832575-9b98-4a03-a181-4470a5a00fd6@35g2000pry.googlegroups.com> Message-ID: <65362bd0-7227-49fa-996c-ee0ffdb58b63@d42g2000prb.googlegroups.com> Hi! :) >Sorry, there were a few line wrap-arounds in the diff file due to long >lines but the changes for the four significant lines should be easy to >do manually. Hadn't done that before but I found a ressource how to read that syntax. x86_64 would be enough. i test that again. Thank you. :) From ppetrick at gmail.com Fri Jan 9 21:07:15 2009 From: ppetrick at gmail.com (p.) Date: Fri, 9 Jan 2009 18:07:15 -0800 (PST) Subject: download timeout vs. socket timeout Message-ID: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> i'm using urllib2 in python 2.4 wondering how people typically deal with the case in which a download is too slow. setting the socket timeout only covers those cases where there is no response in the socket for whatever the timeout period is. what if, however, i'm getting bits back but want simply to bail out if the total time to download takes too long? i'm trying to avoid creating a whole other thread if possible? From gagsl-py2 at yahoo.com.ar Fri Jan 9 21:20:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 10 Jan 2009 00:20:26 -0200 Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: En Sat, 10 Jan 2009 00:07:15 -0200, p. escribi?: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? You may use signal.alarm if it is available on your platform. On Windows, using a separate thread for reading is the easiest option - unless you plan to download hundreds of files simultaneously. -- Gabriel Genellina From google at mrabarnett.plus.com Fri Jan 9 21:26:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 02:26:48 +0000 Subject: download timeout vs. socket timeout In-Reply-To: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: <49680768.6090907@mrabarnett.plus.com> p. wrote: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? > Don't try to download all the data in one go, but do it a chunk at a time. If you calculate that it would take too long to complete, then stop. From arobert at townisp.com Fri Jan 9 21:27:05 2009 From: arobert at townisp.com (Andrew Robert) Date: Fri, 09 Jan 2009 21:27:05 -0500 Subject: Detecting open files and forcing closure Message-ID: Hi Everyone, We have a process that does a copy of a share from one location to another. This usually works fine but can occasionally bomb if a file is opened by a user somewhere. Is there a way to code detection of open files and force a close? The files in question are typically PDF files if that matters. Any pointers you can provide on this would be greatly appreciated. From rhodri at wildebst.demon.co.uk Fri Jan 9 21:32:54 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 10 Jan 2009 02:32:54 -0000 Subject: why cannot assign to function call In-Reply-To: <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Message-ID: On Sat, 10 Jan 2009 00:21:27 -0000, wrote: > Joe Strout wrote: >> rurpy at yahoo.com wrote: [snip] > Pointers are passed and assigned by value, just as > other types (disputedly except arrays) are. > One can then use that pointer to manually effect > pass-(the-value-pointed-to)-by-reference, or sharing, > etc. [snip] > In C (you have to explicitly ask for a reference > (pointer) to something (other than arrays) if you > want to use/pass a reference to something. > If you simply use the name, you get by-value semantics. >>> How would anyone develop that expectation if (from >>> a different post in this thread), "[Python's] idea >>> of assignment is the same as anyone else's." >> >> I can think of two ways: >> >> 1. They're new to programming in general, and would have had the same >> expectation for any other language. OR, > > IIRC, Someone posted here that his experience was > that 12-year old kids (presumably without programming > experience) had no problem with Python and references > when described as "names given to an object". (From > memory, can't locate the post right now.) 'Twas I. It was a rebuttal to your point that Python's assignment, parameter passing and data model is somehow inherently more difficult to wrap your brain around than that of other languages. It isn't; if anything it seems to be easier. >> 2. They already understand some other language, and then they come here >> and read wild claims that Python's assignment and parameter-passing >> semantics are different from other languages. Duped by this claim, they >> conclude that, if it's unlike other languages, then Python must have >> copy semantics. > > I have seen no evidence of that. If it were true I > would expect at least some posts to refer to reading > those "wild claims". 3. They conflate assignment, parameter passing and the data model, bring in preconceptions of their own from other languages, and get caught out by them. It's quite easy to do, even within a language. Look at the number of times you had to say "except arrays" about C above. > In Perl it is definitely true that you different syntax: > @a = (1,2,3) > @b = @a # Copy > $b = \@a # Reference Perl has different syntax for everything. It also has its own peculiarities of assignment and data model that make it a less than glowing example of comprehensibility. List flattening, for instance, is amazingly useful in many common Perl idioms, but really not what you expect during assignment. > C is the same way for everything (including pointers) > except arrays: Oh look, there's that exception again. > It may be one can make a technical case that assignment > is the same, but the reason I posted the code and results, > was because the behavior of "=" in them produces clearly > different results that "=" in Python. If you want to > then say to someone, "ignore those different results, > '=' works exactly the same", all I can say is good luck. > I will look forward to continuing to see weekly questions > on this list. :-) It would help if you were using "=" on things that were conceptually the same across the languages, instead of things that only looked similar. Which is where the data model comes in, as has already been explained at length, several times now. -- Rhodri James *-* Wildebeeste Herder to the Masses From mdw at distorted.org.uk Fri Jan 9 21:40:46 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 02:40:46 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: Joe Strout wrote: > No, actually, that was me. rurpy's list was something like C, FORTRAN, > Perl, and VBA. My mistake -- I failed to read the quoting properly. Apologies to all. We still dealt with C. Fortran (to give it its modern spelling) has a similar data model to C, but passes arguments by reference, as described in my Epic Argument Passing Article; I believe that arbitrary expressions may be used as arguments, though I'm unsure as to the semantics of modifying parameters bound to the resulting temporary argument locations. I must confess to being ignorant of VBA. My excuse is that I avoid Windows systems as much as practical, and VBA doesn't have a significant uptake on other systems. Perl has a very strange data model indeed, and it's hard to get a proper handle on it without getting into implementation details: unlike Python, Perl is largely defined /by/ its implementation. Perl has `references', which are proper (scalar) values through which one may read and modify other values; i.e., they're what I called `locatives' elsewhere. Perl provides syntactic sugar, through its `prototypes' which will convert an actual argument which designates (e.g.) a list or hash into a reference to that list or hash; prototypes provide other syntactic shortcuts too, though they have no fundamental semantic effect. In order to add to the confusion, Perl also provides `typeglobs', which are a reification of toplevel variable bindings. Perl's argument passing is fundamentally by /reference/. Given the function sub swap { ($_[0], $_[1]) = ($_[1], $_[0]) } after setting $a = 1, $b = 2, and calling swap $a, $b, we find that $a has the value 2 and $b is 1. What's going on here is that a `location' in Perl is an explicit SV, AV or HV object (for `scalar-', `array-' and `hash-value' respectively. Calling a subroutine involves marking a position on a stack, pushing a number of SVs, and then executing the subroutine's code, which receives the items between the stack pointer and mark in the @_ array. In the case of argument expressions which designate SVs, those SVs are pushed directly, and are therefore made available via @_. Arguments which are arrays or hashes are flattened: their components are pushed onto the stack. (This use of the stack corresponds to what the Perl manual refers to as `list context'.) > Not REALbasic. It's a very modern language with semantics pretty much > identical to Java. Very well; thanks for the correction. I might have a look at this at some point. > > .NET isn't a language at all: rather, it's a virtual machine, > > runtime system, class library and family of languages each of which > > may have idiosyncratic semantics. > > But they don't, AFAIK -- they all have the same semantics; only the > surface syntax differs. And those semantics are the same as REALbasic > and Java. There's a .NET implementation of C++, which obviously brings all of C++'s low-level data model (and it's user-definable assignment and copying). C#'s data model is more complex than Java's because it provides mutable compound `value types', i.e., types whose immediate representations consist of the raw contents of the object rather than a reference. The mutability allows one to distinguish this IR from a reference IR. C# is additionally complicated by its automatic boxing and unboxing rules: an object of value type may under some circumstances be `boxed', appearing as an object of reference type, and obeying the reference-type semantics. > Technically true, in that pointers in C require some special syntax, but > the common idiom is to hide this away by defining a new type: > > typedef Foo* FooPtr; > > Now, for any code using the "FooPtr" type, the data model is the same > as Python (or as Java, RB, .NET, etc., again for code that's using > only reference types). This is a syntactic transformation rather than a change to the data model, though. -- [mdw] From mdw at distorted.org.uk Fri Jan 9 21:42:21 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 02:42:21 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <01777574$0$8693$c3e8da3@news.astraweb.com> <0177ed3f$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Er, perhaps you missed that I was replying to Joe Strout. Yes, evidently. My apologies for the mix up! -- [mdw], who obviously should put the keyboard down now. From rurpy at yahoo.com Fri Jan 9 21:53:59 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 18:53:59 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: Mark Wooding wrote: > rurpy at yahoo.com wrote: > >> If one accepts that there are a "lot" of people who post in here that >> clearly are surprised by Python's assignment semantics, > > But one should not accept that. One might accept that there are many > who post who claim that they are surprised by Python's assignment > semantics. Such people are wrong, however, since what they are > surprised by is Python's data model, and one reason that they are > surprised by Python's data model is because it's not actually explained > very well. Agreed. I think the docs, especially those that develop the conceptual model of how Python work at runtime, could use some major attention. >> and further appear to expect assignment to have copy-like semantics, > > This expectation is justified and, indeed, satisfied. Python does, most > definitely, copy on assignment. What it copies is references, however. > This might be clearer if the data model were explained better. > ... >> then where is that expectation coming from? > >> How would anyone develop that expectation if (from a different post in >> this thread), "[Python's] idea of assignment is the same as anyone >> else's." > > Because they've fundamentally misunderstood the data model. The very > fact that their confusion is ascribed to the wrong thing is strongly > indicative of this. > >> If you maintain that reference-like assignment is very common and >> something every programmer is accustomed to, then where are they >> getting the copy-like assignment expectations from? > > But it's not just assignment that deals with references. It's argument > passing and storage of compound data as well. (See PLR 3.1.) > > They expect that assignment copies stuff, because that's what assignment > does. Everywhere that I can think of -- except C++, which leaves > assignment semantics in hands of the programmer. What they're confused > about is what, precisely, it is that gets copied. And that, really, is > a result of an inadequate understanding of the data model. ... >> So it still seems to me that this is a likely explanation to why there >> is frequent misunderstanding of Python's assignments, and why >> responding to such misunderstandings with, "Python's assignments are >> the same as other languages'", is at best not helpful. > > That's why I'm not just saying that assignment is the same. I'm also > saying that the data model is most definitely not the same as C. I would be willing to bet that most of the confused posters do not distinguish between assignment operation (AO) and data model (DM). Their conceptual box is labeled "assignment behavior" and includes both AO and DM. They expect that AO+DM in Python will produce the same results in Python as they are used to in the other languages they've used. That the discrepancy comes from the DM part rather than the AO part is pretty irrelevant to them given that world view. So responding to the cry, "Python assignment is bizarre!" with an indignant, "No, it is the same as other common languages", is talking with different vocabularies, unless it's also accompanied with all the other information presented in this thread about how Python treats all names as references (which *is* different that some other languages). I notice there is not even an FAQ on the subject of assignment despite the frequency which which people ask about it. >> I have often wished that C handled arrays the same way it does >> structs. I am sure that the pointer-array pseudo-equivalence seemed >> like a very clever idea at the time but I wonder if Dennis Richie ever >> had second thoughts about it. > > Probably. But I think the idea was actually inherited from BCPL, via B. > In BCPL, memory is divided into words. Depending on which operator you > use, you can treat a particular word as an integer, a floating-point > number, or a pointer. An array in BCPL is represented as a pointer to > its first element -- always -- and you index it by an expression of the > form p!i (a notation inherited by BBC BASIC and Haskell of all things). > The array->pointer decay is a compromise position between the BCPL > notion of array-as-pointer and the desire to allocate such things with > automatic storage duration and have sizeof and so on work properly. Interesting tidbit, thanks. From google at mrabarnett.plus.com Fri Jan 9 21:57:56 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 02:57:56 +0000 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: <49680EB4.7020008@mrabarnett.plus.com> Andrew Robert wrote: > Hi Everyone, > > We have a process that does a copy of a share from one location to > another. > > This usually works fine but can occasionally bomb if a file is opened > by a user somewhere. > > Is there a way to code detection of open files and force a close? > > The files in question are typically PDF files if that matters. > > Any pointers you can provide on this would be greatly appreciated. > If the file is open then an exception will be raised. You could catch it, sleep a while, and then retry, or continue with the other files and then come back to it and retry. It might take more than one retry. Anyway, it's a bad idea to force a close, even if that's possible. From arobert at townisp.com Fri Jan 9 22:06:03 2009 From: arobert at townisp.com (Andrew Robert) Date: Fri, 09 Jan 2009 22:06:03 -0500 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: MRAB wrote: > Andrew Robert wrote: >> Hi Everyone, >> >> We have a process that does a copy of a share from one location to >> another. >> >> This usually works fine but can occasionally bomb if a file is opened >> by a user somewhere. >> >> Is there a way to code detection of open files and force a close? >> >> The files in question are typically PDF files if that matters. >> >> Any pointers you can provide on this would be greatly appreciated. >> > If the file is open then an exception will be raised. You could catch > it, sleep a while, and then retry, or continue with the other files and > then come back to it and retry. It might take more than one retry. > Anyway, it's a bad idea to force a close, even if that's possible. The usual scenario is that a user will leave a PDF open and then go home for the evening. They are simply viewing and not modifying the file. When the XCOPY executes, it signals a failure and subsequent scheduler job abend. What I need to do is detect if files are open for viewing and force a close before the copy operation is attempted. Sleeping and retrying the copy is not an option because the user will likely leave it open all night. Is there a way to detect the open files and close them out? From matthew.nuzum at canonical.com Fri Jan 9 22:18:25 2009 From: matthew.nuzum at canonical.com (Matthew Nuzum) Date: Fri, 9 Jan 2009 21:18:25 -0600 Subject: Jython 2.5 Beta1 Released! In-Reply-To: <4dab5f760901091337q79178ac3m1387594a4c738145@mail.gmail.com> References: <4dab5f760901091337q79178ac3m1387594a4c738145@mail.gmail.com> Message-ID: On Fri, Jan 9, 2009 at 3:37 PM, Frank Wierzbicki wrote: > On behalf of the Jython development team, I'm pleased to announce that > Jython 2.5b1 is available for download: > http://downloads.sourceforge.net/jython/jython_installer-2.5b1.jar. > See the installation instructions here: > http://www.jython.org/Project/installation.html. > > Jython 2.5 Beta1 continues a code cooling period where the number of > new features should significantly slow as we concentrate on > solidifying Jython 2.5 for an eventual release. I would guess that we > will put out about two more betas before we start pushing out release > candidates, hopefully in February. > > This is a beta release so be careful. Congrats, I'm watching with eager anticipation! I'm stunned at how well this is working and the progress you're making. Keep up the great work. -- Matthew Nuzum newz2000 on freenode, skype, linkedin, identi.ca and twitter From rurpy at yahoo.com Fri Jan 9 22:19:56 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 9 Jan 2009 19:19:56 -0800 (PST) Subject: why cannot assign to function call References: <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> <5b0680de-9728-4208-bca6-e2e0a359d9a1@r37g2000prr.googlegroups.com> Message-ID: Rhodri James wrote: > On Sat, 10 Jan 2009 00:21:27 -0000, wrote: >> IIRC, Someone posted here that his experience was >> that 12-year old kids (presumably without programming >> experience) had no problem with Python and references >> when described as "names given to an object". (From >> memory, can't locate the post right now.) > > 'Twas I. It was a rebuttal to your point that Python's assignment, > parameter passing and data model is somehow inherently more difficult > to wrap your brain around than that of other languages. It isn't; if > anything it seems to be easier. That was and is not my point. My point was that there seems to be an observably significant number of people who are surprised by the way Python assignment works. I hypothesized that this was due to their experience with other languages, *not* that Python is somehow "inherently more difficult to wrap your brain around", and that the response, "Python assignments are the same as in those other languages" is insufficient. From silfheed at gmail.com Fri Jan 9 22:21:56 2009 From: silfheed at gmail.com (Silfheed) Date: Fri, 9 Jan 2009 19:21:56 -0800 (PST) Subject: Mocking `from foo import *` functions Message-ID: So I'm in the current testing situation: sender.py: ------------- def sendEmails(): return "I send emails" alerter.py: ------------- from sender import * def DoStuffAndSendEmails(): doStuff() sendEmails() I'm trying to write a test fn that will test DoStuffAndSendEmails() (as well as it's kin) without actually sending any emails out. I could go through alter alerter so that it does `import sender` and then find and replace fn() with sender.fn() so I can just create a mock fn fakeSendEmails() and and do something like sender.sendEmails = fakeSendEmails, but I'd rather not. Anyone know how to test alerter.py with out altering the file? Thanks! From google at mrabarnett.plus.com Fri Jan 9 22:41:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jan 2009 03:41:21 +0000 Subject: Mocking `from foo import *` functions In-Reply-To: References: Message-ID: <496818E1.6020506@mrabarnett.plus.com> Silfheed wrote: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > doStuff() > sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? > > You could alter sender.py. :-) Actually, you could have: alerter.py: ------------- TEST = False if TEST: from mock_sender import * else: from sender import * so you're changing alerter.py in only one place, or read the value of TEST from a config file. From pavlovevidence at gmail.com Fri Jan 9 22:42:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 9 Jan 2009 19:42:42 -0800 (PST) Subject: Common path all PyObjects take on destruction? References: <874p08t2o3.fsf@stutsman-jos64.scs.stanford.edu> Message-ID: <86bd1eca-2cd2-42f2-884c-9619abe4c919@w1g2000prk.googlegroups.com> On Jan 9, 6:39?pm, Ryan Stutsman wrote: > I've added a field to all PyObjects in the interpreter which is of type > PyObject*. ?Most of the time this pointer is NULL but occassionally I > want to track some information in there. ?The problem I'm running into > is that I can add a reference to a PyObject inside any of my PyObjects, > but it seems that there isn't any one path that all objects follow on > destruction so that I can later Py_DECREF that reference. > > Eventually most of the types seem to call PyObject_Free, but this gets > called with void* and it seems it isn't always the case that PyObject*s > are passed in. > > Where is the best place to implement something like this? ?It really > won't work to implement this in the destructor of each of the individual > types because other types added later won't know to DECREF this field on > destruction. > > Any hints would be appreciated. ?Hopefully I'm just missing something > simple. I believe no object in CPython ever gets deleted except by the Py_DECREF macro (Py_XDECREF and Py_CLEAR both expand Py_DECREF). So there is your common reference point. Let's look at the macro, shall we? #define Py_DECREF(op) \ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ --((PyObject*)(op))->ob_refcnt != 0) \ _Py_CHECK_REFCNT(op) \ else \ _Py_Dealloc((PyObject *)(op)) So, if the reference count goes down to zero, Py_DECREF calls _Py_Dealloc to delete the object. _Py_Dealloc is the common point you want. Carl Banks From rtw at freenet.co.uk Fri Jan 9 22:54:20 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Fri, 09 Jan 2009 21:54:20 -0600 Subject: Mocking `from foo import *` functions References: Message-ID: Silfheed wrote in news:c73b304b-f601-4bb5-89c1-3ee667eeb7d9 @l37g2000vba.googlegroups.com in comp.lang.python: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > doStuff() > sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? Yes you alter the module *after* you have imported it. In your test script do: def mock_sendEmails(): pass # or some test code maybe # setup ... import alerter # now patch the module alerter.sendEmails = mock_sendEmails # run the test ... DoStuffAndSendEmails() Because python is dynamic alerter.DoStuffAndSendEmails will call the sendEmails in the alerter module that has been replaced with mock_sendEmails from the test script. Rob. -- http://www.victim-prime.dsl.pipex.com/ From musiccomposition at gmail.com Fri Jan 9 22:55:23 2009 From: musiccomposition at gmail.com (Benjamin) Date: Fri, 9 Jan 2009 19:55:23 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> Message-ID: <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> On Jan 8, 11:35?pm, John Machin wrote: > On Jan 9, 1:56?pm, Benjamin wrote: > > > On Jan 8, 4:21?pm, Thorsten Kampe wrote: > > > > * Terry Reedy (Thu, 08 Jan 2009 17:04:04 -0500) > > > > Since you are, I believe, at least the second person to report being bit > > > > by this confusion, please open an issue at bugs.python.org and suggest a > > > > couple of revised sentences that you think are more informative. > > > > Will do tomorrow. The revised sentence could be in the line of "warn > > > about Python 3.x incompatibilities that cannot trivially be fixed by > > > 2to3.py". > > > Actually, don't bother now; I've fixed it up in the trunk. > > Would you mind giving a pointer to where or what your fix is? The > reason for asking is that Thorsten's suggestion is ambiguous: warn > about some? all? 3.x problems that can't be trivially fixed by 2to3? > Can't be "all"; there are in fact a number of problems that can't be > trivially fixed by 2to3 and can't be detected by running 2.6 with the > -3 option. I added "and cannot by trivially fixed by 2to3". > > These include > (a) problems that cause a reasonably informative exception in 3.x > right at the point where the problem exists > (b) problems where the behaviour has changed but no exception is > raised, and your code lurches off down the wrong path, and you need to > work backwards from subsequent exception(s) and/or failing test case > (s) to pin-point the problem. > > I'll use string constants to provide an example of each type. When > faced with "abcd", 2to3 has no way of telling whether that should be > str ("abcd") or bytes (b"abcd"). In the vast majority of cases, to > guess it should be str is correct, so there is no change to the source > file, and a warning would ?almostly always be noise. > > Example of problem (a): chunks is a list of slices of bytes read from > a binary file. > In 2.x you write > glued = ''.join(chunks) > In 3.0 you get this:>>> chunks = [b'x', b'y'] > >>> ''.join(chunks) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: sequence item 0: expected str instance, bytes found > > Example of problem (b): some_bytes has been read from a file that was > opened in 'rb' mode and contains the 4 ASCII bytes 'abcd' > # 2.x simulation>> some_bytes == "abcd" > > True > # 3.0 simulation>>> type(some_bytes) > > >>> type("abcd") > > >>> some_bytes == "abcd" > > False # because the types are not comparable for equality. > > Another type (b) example is the (majority-guessed) 2to3 change from [c] > StringIO.StringIO to io.StringIO ... if you really should feed some > library an io.BytesIO instance instead, it can travel quite a distance > before blowing up. Yes, bytes/str is an excellent example of where the third part of the porting helpers. We'll need good documentation. Unfortunately, as you note below, this isn't exactly the case yet. > > Perhaps some of this info could be put intohttp://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 > ... or maybe a separate HOWTO or wiki chapter could be set up for > porting to 3.x, including topics like: > (1) maintaining one set of source files (when you are maintaining a > package that must run on e.g. 2.1 through 3.x) > (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x > support-range issue but would like to have the one set of source > looking like 3.x code instead of the ugliness of version-conditional > stuff like > BYTES_NULL = bytes(0) # 3.x > or > BYTES_NULL = '' # 2.x > and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? > > Cheers, > John From sjmachin at lexicon.net Fri Jan 9 23:19:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 9 Jan 2009 20:19:11 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> Message-ID: On Jan 10, 2:55?pm, Benjamin wrote: > On Jan 8, 11:35?pm, John Machin wrote: > > > Actually, don't bother now; I've fixed it up in the trunk. > > > Would you mind giving a pointer to where or what your fix is? The > > reason for asking is that Thorsten's suggestion is ambiguous: warn > > about some? all? 3.x problems that can't be trivially fixed by 2to3? > > Can't be "all"; there are in fact a number of problems that can't be > > trivially fixed by 2to3 and can't be detected by running 2.6 with the > > -3 option. > > I added "and cannot by trivially fixed by 2to3". That's what I was afraid of. Please consider changing it so that it does not give the impression that together -3 and 2to3 cover all the bases. > Yes, bytes/str is an excellent example of where the third part of the > porting helpers. I don't understand that. What is/are "the third part of the porting helpers"? Are there words missing from the end? > We'll need good documentation. Unfortunately, as you > note below, this isn't exactly the case yet. So is there a plot to remedy this? Where do we sign up? > > Perhaps some of this info could be put intohttp://docs.python.org/dev/py3k/whatsnew/3.0.html#porting-to-python-3-0 > > ... or maybe a separate HOWTO or wiki chapter could be set up for > > porting to 3.x, including topics like: > > (1) maintaining one set of source files (when you are maintaining a > > package that must run on e.g. 2.1 through 3.x) > > (2) the possibility of a 3to2 kit for those who have the 2.1 to 3.x > > support-range issue but would like to have the one set of source > > looking like 3.x code instead of the ugliness of version-conditional > > stuff like > > BYTES_NULL = bytes(0) # 3.x > > or > > BYTES_NULL = '' # 2.x > > and (3) [getting in early] what about a %to{} kit (or a {}to% kit!)? From rhodri at wildebst.demon.co.uk Fri Jan 9 23:38:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 10 Jan 2009 04:38:18 -0000 Subject: Detecting open files and forcing closure In-Reply-To: References: Message-ID: On Sat, 10 Jan 2009 03:06:03 -0000, Andrew Robert wrote: > The usual scenario is that a user will leave a PDF open and then go home > for the evening. They are simply viewing and not modifying the file. > When the XCOPY executes, it signals a failure and subsequent scheduler > job abend. > > What I need to do is detect if files are open for viewing and force a > close before the copy operation is attempted. > > Sleeping and retrying the copy is not an option because the user will > likely leave it open all night. > > Is there a way to detect the open files and close them out? I can't think of one off the top of my head, but this approach will cause more anguish than you would believe possible in any case. Imagine if the file was open for write; you've either just corrupted it or lost the most recent work if you force it closed. It sounds like you're trying to implement a backup strategy. If you are, I'd suggest your problem is XCOPY -- you really need something more combat capable instead. -- Rhodri James *-* Wildebeeste Herder to the Masses From hsoft at hardcoded.net Sat Jan 10 01:12:57 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Fri, 9 Jan 2009 22:12:57 -0800 (PST) Subject: Mocking `from foo import *` functions References: Message-ID: On Jan 10, 4:21?am, Silfheed wrote: > So I'm in the current testing situation: > > sender.py: > ------------- > def sendEmails(): > ? ?return "I send emails" > > alerter.py: > ------------- > from sender import * > def DoStuffAndSendEmails(): > ? doStuff() > ? sendEmails() > > I'm trying to write a test fn that will test DoStuffAndSendEmails() > (as well as it's kin) without actually sending any emails out. ?I > could go through alter alerter so that it does `import sender` and > then find and replace fn() with sender.fn() so I can just create a > mock fn fakeSendEmails() and and do something like sender.sendEmails = > fakeSendEmails, but I'd rather not. > > Anyone know how to test alerter.py with out altering the file? > > Thanks! Don't ever put testing flag in your non-code, that's very ugly and creates a weird circular dependency between your real code and your test code. It will give you headaches later. To answer to Rob: yeah, sure that would work, but I always thought mocking the imported function didn't feel right. The test then depends on the import method of the tested module. If you later change your mind and decide to use "import sender" and then "sender.sendEmails()", you have to change your test code. In my code, I have a custom TestCase class which has a method for dealing with this stuff, here's the code relevant to your problem: class TestCase(unittest.TestCase): cls_tested_module = None def run(self, result=None): self._mocked = [] unittest.TestCase.run(self, result) # We use reversed() so the original value is put back, even if we mock twice. for target, attrname, old_value in reversed(self._mocked): setattr(target, attrname, old_value) def mock(self, target, attrname, replace_with): ''' Replaces 'target' attribute 'attrname' with 'replace_with' and put it back to normal at tearDown. The very nice thing about mock() is that it will scan self.cls_tested_module for the mock target and mock it as well. This is to fix the "from" imports problem (Where even if you mock(os, 'path'), if the tested module imported it with "from os import path", the mock will not work). ''' oldvalue = getattr(target, attrname) self._mocked.append((target, attrname, oldvalue)) setattr(target, attrname, replace_with) if (self.cls_tested_module is not None) and (self.cls_tested_module is not target): for key, value in self.cls_tested_module.__dict__.iteritems (): if value is oldvalue: self.mock(self.cls_tested_module, key, replace_with) When you use it, set cls_tested_module (at the class level) to "sender" (not the string, the module instance) From enleverlesX.XmcX at XmclaveauX.com Sat Jan 10 01:36:52 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sat, 10 Jan 2009 07:36:52 +0100 Subject: Free Download - Microsoft Windows 7 Beta In-Reply-To: References: Message-ID: <496843c4$0$18388$ba4acef3@news.orange.fr> Hi! I downloaded W7 two days ago, directly on MSDN (Microsoft), and not on a bizarre, unknown site, and doubtful. Python 2.6 run OK. But the problem (well known) with Python 2.6.1 is always present. @-salutations -- Michel Claveau From gagsl-py2 at yahoo.com.ar Sat Jan 10 02:15:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 10 Jan 2009 05:15:22 -0200 Subject: multiprocessing and SIGINT References: <32bc4191-b914-4429-a13a-b51aba173f64@40g2000prx.googlegroups.com> <493e1114-84c4-47df-be80-e93ed4fcbfce@a12g2000pro.googlegroups.com> Message-ID: En Fri, 09 Jan 2009 03:04:58 -0200, akineko escribi?: > (2) test program with multiprocessing > Both processes receives SIGINT. > OS apparently distributes the SIGINT event to processes associated > with the terminal. Yes, to avoid that, the child process has to detach itself from the terminal. I'd expect the multiprocessing module to do that for us - but it doesn't. See http://www.onlamp.com/python/pythoncook2/solution.csp?day=1 > (3) signal handler > I realized that I could assign a signal handler specific to a process > by placing it to a worker method. > > def worker(): > # this process ignores SIGINT > signal.signal(signal.SIGINT, signal.SIG_IGN) > ... the rest ... Looks fine... > (4) terminating the spawned process > I needed to send a shutdown message to the process via a communication > between two processes. > You can use Process.terminate() to brutally kill the process but that > is a last resort. What about sending a signal, like SIGTERM? -- Gabriel Genellina From rhamph at gmail.com Sat Jan 10 02:44:31 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Fri, 9 Jan 2009 23:44:31 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> <6spt2cF7n8nmU3@mid.uni-berlin.de> Message-ID: On Jan 9, 2:14?pm, Marc 'BlackJack' Rintsch wrote: > On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > > Marc 'BlackJack' Rintsch wrote: > > >> def iter_max_values(blocks, block_count): > >> ? ? for i, block in enumerate(blocks): > >> ? ? ? ? histogram = defaultdict(int) > >> ? ? ? ? for byte in block: > >> ? ? ? ? ? ? histogram[byte] += 1 > > >> ? ? ? ? yield max((count, byte) > >> ? ? ? ? ? ? ? ? ? for value, count in histogram.iteritems())[1] > > > [snip] > > Would it be faster if histogram was a list initialised to [0] * 256? > > Don't know. ?Then for every byte in the 2?GiB we have to call `ord()`. ? > Maybe the speedup from the list compensates this, maybe not. > > I think that we have to to something with *every* byte of that really > large file *at Python level* is the main problem here. ?In C that's just > some primitive numbers. ?Python has all the object overhead. struct's B format might help here. Also, struct.unpack_from could probably be combined with mmap to avoid copying the input. Not to mention that the 0..256 ints are all saved and won't be allocated/ deallocated. From __peter__ at web.de Sat Jan 10 02:53:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 Jan 2009 08:53:47 +0100 Subject: Force exception on attribute write access only one object References: <6slvrrF71ds4U1@mid.individual.net> <6sp04mF7hgjdU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Peter Otten schrieb: >> Thomas Guettler wrote: >> >>> for debugging I want to raise an exception if an attribute is >>> changed on an object. Since it is only for debugging I don't want >>> to change the integer attribute to a property. >> class A(object): >> def __init__(self): >> self.foo = 42 >> >> a = A() >> b = A() >> >> class B(A): >> @property >> def foo(self): >> return self.__dict__["foo"] >> >> b.__class__ = B >> >> a.foo = "whatever" >> print b.foo >> b.foo = "whatever" > your idea was good, but it does not work with Django ORM Models: > > Traceback (most recent call last): > File "/localhome/modw/django/core/handlers/base.py", line 87, in > get_response > response = callback(request, *callback_args, **callback_kwargs) > File "/localhome/modw/foo/views/filter.py", line 473, in add > return edit(request, 'add') > File "/localhome/modw/foo/views/filter.py", line 493, in edit > filter=form.save() > File "/localhome/modw/foo/views/filter.py", line 457, in save > action=form.save() > File "/localhome/modw/django/forms/models.py", line 315, in save > if self.instance.pk is None: > File "/localhome/modw/django/db/models/base.py", line 292, in > _get_pk_val > return getattr(self, meta.pk.attname) > AttributeError: 'MyAction' object has no attribute 'filter_action_ptr_id' I can't tell what's happening from the traceback alone. Is "filter_action_ptr_id"" your actual "foo" and "MyAction" your "B"? Maybe the relevant setup code would help... Peter From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 04:24:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 09:24:51 GMT Subject: Detecting open files and forcing closure References: Message-ID: <01786016$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 22:06:03 -0500, Andrew Robert wrote: > Is there a way to detect the open files and close them out? You can detect open files by trying to move them and catching the exception when you can't. You may wish to distinguish permission errors. As far as forcing the file to close, that depends on what OS you are using and what permissions your application is running as. I intuit that you are running under Windows, because POSIX systems allow you to copy open files. My knowledge of Windows isn't that great, but I imagine that the only way to force a close is something drastic like rebooting the machine. Sounds like your real problem is a social problem, not a technical one. Maybe you need a "failed to log out" jar (like a swear jar), and every person who failed to close their open files has to put a dollar in the jar. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 04:46:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 09:46:18 GMT Subject: why cannot assign to function call References: <3eadnQJtvuI7P8LUnZ2dnUVZ_sninZ2d@posted.usinternet> <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0178651d$0$8693$c3e8da3@news.astraweb.com> On Fri, 09 Jan 2009 20:23:11 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I'm pretty sure that no other pure-Python coder has manipulated >> references either. They've manipulated objects. > > No: not directly. The Python program deals solely with references; > anything involving actual objects is mediated by the runtime. Your claim is ambiguous: when you say "the Python program", are you talking about the program I write using the Python language, or the Python VM, or something else? If the first, then you are wrong: the Python program I write doesn't deal with references. It deals with objects. This discussion flounders because we conflate multiple levels of explanation. People say "You do foo" when they mean "the Python VM does foo". Earlier, I responded to your claim that I was storing references by saying I was pretty sure I didn't store references, and gave an example of the line of Python code x=23. Your response was to mix explanatory levels: > You bind names to locations which store immediate representations. > Python IRs are (in the sense defined above) exclusively references. I most certainly don't bind names to locations. When I write x=23, I don't know what the location of the object 23 is, so how could I bind that location to the name? You are conflating what the Python VM does with what I do. What *I* do is bind the object 23 to the name x. I don't know the location of 23, I don't even know if 23 has a well-defined location or if it is some sort of distributed virtual data structure. As a Python programmer, that's the level I see: names and objects. At a lower level, what the Python VM does is store the name 'x' in a dictionary, bound to the object 23. No locations come into it, because at this level of explanation, dictionaries are an abstract mapping. There's no requirement that the abstract dictionary structure works by storing addresses. All we know is that it maps the name 'x' to the object 23 somehow. Maybe there's no persistent storage, and the dict stores instructions telling the VM how to recreate the object 23 when it is needed. Who knows? But at this explanatory level, there are no locatives involved. Names and objects float as disembodied entities in the aether, and dicts map one to the other. At an even lower explanatory level, the CPython implementation of dictionaries works by storing a pointer (or if you prefer, a reference) to the object in a hash table. Pointers, of course, are locatives, and so finally we come to the explanation you prefer. We've gone from abstract names-and-classes to concrete pointers-to-bytes. But this is at least two levels deeper than what's visible in Python code. Just about the only time Python coders work with locatives is when they manually calculate some index into a string or list, or similar. At an even lower explanatory level, all the VM does is copy bytes. And at a lower level still, it doesn't even copy bytes, it just flips bits. And below that, we're into physics, and I won't go there. I daresay you probably get annoyed at me when I bring up explanations at the level of copying bytes. You probably feel that for the average Python programmer, *most of the time* such explanations are more obfuscatory than useful. Of course, there are exceptions, such as explaining why repeated string concatenation is likely to be slow. There is a time and a place for such low level explanations, but not at the high-level overview needed by the average Python programmer. And you would be right. But I argue that your explanation at the level of references is exactly the same: it is too low level. It relies on specific details which may not even be true for all implementations of Python. It certainly relies on details which won't be true for hypothetical versions of Python running on exotic hardware. One can do massively parallel calculations using DNA, and such "DNA computers" are apparently Turing complete. I have no idea how one would write a Python virtual machine in such a biological computer, but I'm pretty sure that data values won't have well-defined locations in a machine that consists of billions of DNA molecules floating in a liquid. If that's too bizarre for you, think about simulating a Python VM in your own head. If we know one thing about the human brain, it is that thoughts and concepts are not stored in single, well-defined locations, so when you think of "x=23", there is no pointer to a location in your head. >> That's why we should try to keep the different layers of explanation >> separate, without conflating them. Python programmers don't actually >> flip bits, and neither do they manipulate references. Python >> programmers don't have access to bits, or references. What they have >> access to is objects. > > No, that's my point: Python programmers /don't/ have direct access to > objects. The objects themselves are kept at arm's length by the > indirection layer of references. I think you are wrong. If I want a name 'x' to refers to (is bound to) the object 23, I write x=23, not some variation of: create object 23 give me a reference to that object bind the reference to name 'x' Those three steps may take places at some level of the Python VM, but that's not what *I* do as a Python programmer. Note that what we're really doing is manipulating the symbol '23' in source code. Normally that makes no difference, but if you've ever tried to get the float 1.1 you'll discover the model (metaphor) of "source code symbols are programming entities" fails. All models fail sometimes. >> > Python does pass-by-value, but the things it passes -- by value -- >> > are references. >> >> If you're going to misuse pass-by-value to describe what Python does, >> *everything* is pass-by-value "where the value is foo", for some foo. > > No. I've tried explaining this before, with apparently little success. [...] > * A /value/ is an item of data. The range and nature of values is > language specific. Typically, values encompass at least some kinds > of numbers, textual data, and compound data structures; they may > also include behavioural items such as functions. Yes. This is an intuitive meaning of the world value. In Python, all values are objects. Some typical examples of values are: 5, None, "Fred", True, 3.5, [2, 3, 4], {}, lambda x: x+1 These (and more complicated structures built on top of them) are the things of interest to the programmer. They are the values: the things which are denoted by the symbols '5', 'None', '"Fred"' etc. > * A /location/[1] is an area of memory suitable for storing the > /immediate representation/ (which I shall abbreviate to /IR/) of a > value. (A location may be capable of storing things other than IRs, > e.g., representations of unevaluated expressions in lazily evaluated > languages. Locations may vary in size, e.g., in order to be capable > of storing different types of IRs.) At the level of Python code, we have no access to such locations. The closest we have is the id() function, which uses location in memory as a unique ID for objects, but this is an accident of the CPython implementation. Whatever the /immediate representation/ of a value is, we can't manipulate it directly in Python code. > * A /variable/ is a location to which has been /bound/ a name. Given > an occurrence of a name in a program's source, there is a language > specific rule for determining the variable to which it is bound. According to this definition, there are no variables in Python, because Python's data model is that names are an abstract mapping between symbols and values, not between symbols and locations. > * /Evaluation/ is the process of determining a value from an > expression. The /value of/ an expression is the result of > evaluating the expression. This value is, in general, dependent on > the contents of the locations to which names appearing in the > expression are bound. [...] > The argument passing model `pass-by-value' has a number of distinctive > properties. > > * The argument expression is fully evaluated before the function is > called, yielding an argument value. > > * The corresponding parameter name is bound to a fresh location. > > * The argument value IR is stored in the parameter's location. This is an underspecified definition. Without a definition of /immediate representation/, we can't determine what this means. I can guess that, based on Pascal, Fortran and C, the /immediate representation/ of a value is whatever data structure represents that value. However, I fear that you are going to try to slip in an open-ended definition, that /immediate representation/ could be *anything* -- for ints in C, it will be the bytes that represent the int; for C arrays, it will be a pointer to the bytes that represent the array; for Python, it will be references to objects; for Algol 60, it will be thunks. To avoid weakening pass-by-value to mean everything and anything at all, I'm going to say that the /immediate representation/ is the bytes which represent the value. (That is, the value itself.) Given this, we can see that Python is not pass-by-value. As I have shown in another post, replying to Joe, the location (as exposed by the id() function in CPython) of the formal parameter is the same as that of the argument value, not a fresh location with a copy of the value. To save you looking up my post, here's a simple example: >>> def function(parrot): ... return id(parrot) ... >>> spam = 23 >>> print id(spam), function(spam) 143599192 143599192 > By contrast, the `pass-by-reference' model has other distinguishing > properties. > > * Whether arbitrary argument expressions are permitted is language > dependent; often, only a subset of available expressions -- those > that designate locations -- are permitted. As you said above: "The /value of/ an expression is the result of evaluating the expression". Given the expression 2+3, the result of that expression is 5, not the location where 5 is stored. There is no reason to believe that 5 designates a location, as opposed to designating the number of peas in a pod or the average length of a piece of string. For want of a better description, let me re-word the above to say: * Whether arbitrary argument expressions are permitted is language dependent; often, only a subset of available expressions -- e.g. those that evaluate at a named location -- are permitted. Note that I say they evaluate *at*, not *to*, a fixed location. A practical example, to ensure we're talking about the same thing. In Pascal, I can declare a procedure swap(a, b) taking two VAR parameters, which use call-by-reference semantics. I might do something like this: a := 8; { number of peas in a pod } b := 13; { a baker's dozen } swap(a, b); Even though the values of a and b do not designate locations, the compiler can pass them to the procedure because the named variables a and b exist *at* particular locations. Contrast this with: swap(a, 10+3); which will fail in Pascal, because the value of the expression 10+3 doesn't correspond to a named location. (Presumably this is a design choice, because the value of the expression will certainly exist at a known location, although possibly not known until runtime.) > If the argument > expression does designate a location, then this location is the > /argument location/. Replace this with "If the argument expression does evaluate at an allowed location (named location for Pascal), then..." and I will accept it. > If arbitrary expressions are permitted, and > the expression does not designate a location, then a fresh location > is allocated to be the argument location, the expression evaluated, > and the resulting IR stored in the argument location. Modulo similar changes, accepted. > * The corresponding parameter name is bound to the argument location. According to this definition, Python is call-by-reference. Refer my code snippet above. But clearly Python doesn't behave like call-by-reference in other languages: you can't write a swap() procedure. This is where I quote Barbara Liskov, talking about the language CLU which has precisely the same calling semantics as Python: "In particular it is not call by value because mutations of arguments performed by the called routine will be visible to the caller. And it is not call by reference because access is not given to the variables of the caller, but merely to certain objects." http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-11/ msg01499.html or http://snipurl.com/9qd0b > There are other models, including value/return and call-by-name. And Python's call-by-object (also CLU, Ruby, Java -- although Java people don't use the term -- and others). [...] > I hope that I have convincingly demonstrated that it's possible to > define `pass-by-value' in a coherent manner, consistent with > conventional usage, and distinguishing it clearly from `pass-by- > reference'. Of course you can define pass-by-value coherently, but not if the definition of value can be anything you like. Once you start declaring that a language is "pass-by-value, where the value is a Foo rather than the actual value", pass-by-value can be used to describe *anything*. Pass- by-reference becomes pass-by-value where the value is the location of the value. Pass-by-object is pass-by-value where the value is a reference to the object (your claim). And so forth. [...] >> > I agree with the comment about Pascal, but C is actually pretty >> > similar to Python here. C only does pass-by-value. >> >> Except for arrays. > > Even for those. C doesn't pass arrays at all; instead it passes > (programmer-visible) pointers. See other article. But you are conflating concepts again. The value of an array is the array: it's what the programmer asked for when he declared an array. See your own definition of value above: "A /value/ is an item of data." Given a symbol x which represents an array, C doesn't pass the value of x (the array). It passes a pointer (reference) to the value of x. This is not pass-by-value unless you define value so broadly that it could mean anything. Given the Pascal declaration procedure foo(x: array[1..1000] of char) You get pass-by-value semantics: when you pass an array to foo, the entire array is duplicated. Changes to x are not visible in the caller's array. C arrays do not behave like this with an equivalent declaration. Change the declaration to be VAR x, and using pass-by-reference semantics, and the array is *not* duplicated, and changes to x *are* visible to the caller. C's default handling of arrays is just like Pascal's call-by-reference semantics, not like pass-by-value. This is AFAIK unique in C to arrays. [...] >> In other words... C is call-by-value, and (according to you) Python is >> call-by-value, but they behaviour differently. > > And this is entirely due to the difference in their immediate > representations of values. Values are values. Regardless of whether you are using C or Pascal or Python, the value of 1+1 is 2, not some arbitrary memory location. I'm going to quote from Fredrik Lundh: "I'm not aware of any language where a reference to an object, rather than the *contents* of the object, is seen as the object's actual value. It's definitely not true for Python, at least." http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-11/ msg01341.html or http://snipurl.com/9qdze The viewpoint that values are references is bizarre and counter- intuitive, and it leaves us with no simple way of talking about the value of expressions in the sense that 2 is the value of the expression 1+1. -- Steven From castironpi at gmail.com Sat Jan 10 06:30:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 10 Jan 2009 03:30:55 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: On Jan 9, 9:30?am, Joe Strout wrote: > Aaron Brady wrote: > > Possible compromise. ?You can think of functions as mutation-only. > > You pass the object, and it gets a new (additional) name. ?The old > > name doesn't go in. ? > > That's correct. ?The reference itself is passed in, not the variable (or > expression) that held or generated the reference in the calling code. This is very odd, and I see it quite a bit. Me: "You pass the object." Joe: "That's correct. You pass the reference." What was wrong with my original? > This is true. ?(Technically, instead of variable, we should say "LValue" > here -- there are things slightly more complex than simple variables > that can serve as the left-hand side of an assignment. ?So replace > "variable" with "lvalue" above if you prefer.) This is a point worth making. I want to penny-pinch every term in an introductory text, though, so, it's a tough call. > M2: If 'fun()' returned a reference, you might be able to mutate the > object that refers to. > m2: You can sometimes mutate the object it refers to. > C2: 'fun()' returns a reference. This is horrendous. http://en.wikipedia.org/wiki/Formal_fallacy http://en.wikipedia.org/wiki/Affirming_the_consequent A question: Are you Joe and you Mark certain that the simplest possible introductory explanation makes use of the term 'reference'? Perhaps we can have a contest for shortest/simplest/best description of Python's data/variable/argument model. Lastly, I don't see any reason why we couldn't make both explanations available. 'For those coming from Java/etc....; for those coming from C++/etc.....' They would both get read. From goldnery at gmail.com Sat Jan 10 09:15:22 2009 From: goldnery at gmail.com (Gandalf) Date: Sat, 10 Jan 2009 06:15:22 -0800 (PST) Subject: if-else statement Message-ID: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> other languages like PHP or javascript as this if-else operator like this myVar = checking == 1? 'string': 'other string' is this stuff exist in python? thanks! From duncan.booth at invalid.invalid Sat Jan 10 09:26:15 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Jan 2009 14:26:15 GMT Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: Gandalf wrote: > other languages like PHP or javascript as this if-else operator like > this > > myVar = checking == 1? 'string': 'other string' > > is this stuff exist in python? > See http://docs.python.org/reference/expressions.html#boolean-operations conditional_expression ::= or_test ["if" or_test "else" expression] ... The expression x if C else y first evaluates C (not x); if C is true, x is evaluated and its value is returned; otherwise, y is evaluated and its value is returned. From jamesthiele.usenet at gmail.com Sat Jan 10 10:12:40 2009 From: jamesthiele.usenet at gmail.com (James Thiele) Date: Sat, 10 Jan 2009 07:12:40 -0800 (PST) Subject: NorthwestPythonDay, 31 Jan 2009 Message-ID: Posted for Brian Dorsey Hello everyone, On behalf of the Seattle Python Interest Group, I'd like to invite you to join us for an informal day of Python talks & socializing. When: January, 31st 9am - 5pm Where: University of Washington campus, Seattle, Washington Price: Free! Details and updated information: http://www.seapig.org/NorthwestPythonDay The day will be mostly 30 minute talks and two sets of 5 minute lightning talks. We'll also have plenty of time to chat over lunch and dinner/drinks. We still have room for a few more talks, please propose a talk! (http://www.seapig.org/NorthwestPythonDay for details) Please join us and forward this on to other Python people! From rtw at freenet.co.uk Sat Jan 10 10:19:21 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sat, 10 Jan 2009 09:19:21 -0600 Subject: Mocking `from foo import *` functions References: Message-ID: wrote in news:a9ed10ff-d907-46f0-8c6a- c3d95579a5ab at k1g2000prb.googlegroups.com in comp.lang.python: > To answer to Rob: yeah, sure that would work, but I always thought Just to note: you're answering a question about testing, but I answered how to alter the alerter module *for* testing. given it was the import * that was causing the OP the problem, I tried to address that. > mocking the imported function didn't feel right. The test then depends > on the import method of the tested module. If you later change your > mind and decide to use "import sender" and then "sender.sendEmails()", > you have to change your test code. You have to add: import sender sender.sendEmails = mock_sendEmails to your test script. Note that doing the above *before* any other module imports from sender, will be sufficient in *any* case, though it won't help if the tested code calls reload( sender ). No need to scan every imported module for the mocked function. It also handles the case where other code imports the sender module and calls sendEmails(). For additional robustness the above can be changed to: ## assert sender module hasn't been imported elsewhere yet import sys assert 'sender' not in sys.modules import sender sender.sendEmails = mock_sendEmails Rob. -- http://www.victim-prime.dsl.pipex.com/ From Maksim.Kasimov at gmail.com Sat Jan 10 10:45:53 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Sat, 10 Jan 2009 07:45:53 -0800 (PST) Subject: are there some special about '\x1a' symbol Message-ID: Hi all! I had touch with some different python behavior: I was tried to write into a file a string with the '\x1a' symbol, and for FreeBSD system, it gives expected result: >>> open("test", "w").write('before\x1aafter') >>> open('test').read() 'before\x1aafter' but for my WinXP box, it gives some strange: >>> open("test", "w").write('before\x1aafter') >>> open('test').read() 'before' Here I can write all symbols, but not read. I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. Why is it so and is it possible to fix it? -- Maksim From mdw at distorted.org.uk Sat Jan 10 10:46:35 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 15:46:35 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: [Another tome. I hope this contains sufficient new material to continue to be of interest to other readers.] Steven D'Aprano wrote: > On Fri, 09 Jan 2009 20:23:11 +0000, Mark Wooding wrote: > > > No: not directly. The Python program deals solely with references; > > anything involving actual objects is mediated by the runtime. > > Your claim is ambiguous: when you say "the Python program", are you > talking about the program I write using the Python language, or the > Python VM, or something else? The former. > If the first, then you are wrong: the Python program I write doesn't > deal with references. It deals with objects. Do you have evidence for this claim other than your vigorous assertion? I have evidence: in particular, after the example l = [1, 2, 3] l[1] = l the list l (abuse of terminology: I mean `the list referred to from the location bound to l') has the structure I drew, but you snipped: ,----------, v | +---+ +---+ | l: | *----> | *-----> 1 | +---+ +---+ | | *----------' +---+ | *-----> 3 +---+ Can you explain, without using the concept of references (or anything else equivalent) why this happens, and why the result is not (for example) [1, [1, 2, 3], 3]? > This discussion flounders because we conflate multiple levels of > explanation. No. I'm sticking to a single level of explanation. It may appear to be a lower level than the one you're trying to promote, and therefore contains more detail and is more complicated, but it has the benefit that it explains observed phenomena. > People say "You do foo" when they mean "the Python VM does foo". Since what the programmer does is type at a keyboard, the keystrokes being interpreted eventually as editing commands in a text editor (having been processed by various intermediate pieces of software probably including keyboard drivers, and maybe window systems or terminal line disciplines), anything else is an abuse of terminology; but a useful one. So, the programmer types, with the objective (presumably) of constructing a text file containing a Python program which, when executed by an appropriate Python implementation, will behave in a satisfactory way. The notion of `Python VM' is a good one (though potentially open to confusion -- alas, `virtual machine' has multiple meanings too). So: a Python program can be interpreted as instructions to such a virtual machine, to behave in particular ways. Agreed? The question is: how do we best describe the behaviour of such a Python VM when executing a Python program, given its text? It's far too easy, as we've both shown, to slip into imprecise terminology here. When I write > > You bind names to locations which store immediate representations. > > Python IRs are (in the sense defined above) exclusively references. I mean, of course, that a Python implementation behaves is if it binds `names to locations which store immediate representations'. > I most certainly don't bind names to locations. When I write x=23, I > don't know what the location of the object 23 is, so how could I bind > that location to the name? Quite. A lapse on my part, due to sloppy writing caused by a desire not to make this article any longer than it already was. > You are conflating what the Python VM does with what I do. No... > What *I* do is bind the object 23 to the name x. What you do is described above. It doesn't involve any binding at all, or objects. Unless, that is, you are actually implementing Python personally (i.e., not merely instructing a computer to do so, but actually within your own mind); in which case I claim that you must do so as I have described, or do so wrongly. > I don't know the location of 23, I don't even know if 23 has a > well-defined location I warned that I was using certain terms in a technical sense, and attempted to define them clearly at the top of my article. The word `location' was one such: : * A /location/[1] is an area of memory suitable for storing the : /immediate representation/ (which I shall abbreviate to /IR/) of a : value. (A location may be capable of storing things other than : IRs, e.g., representations of unevaluated expressions in lazily : evaluated languages. Locations may vary in size, e.g., in order : to be capable of storing different types of IRs.) Whether 23 has a location is unimportant. In the context of your example `x = 23', what's important is that the name `x' is bound to a location, and then an immediate representation of the value `23' is stored in that location. (This description holds for all languages I can think of, modulo details of which occurrences of names are binding occurrences, and C++'s user- controlled assignment and so on.) > or if it is some sort of distributed virtual data structure. As a > Python programmer, that's the level I see: names and objects. Only if you want to be confused. Without references one is confused by circular data structures; without locations, one is confused by closures and assignment. There are /two/ layers of indirection between variable names and values in Python. One layer is the mapping between names and locations: the usual term for this mapping is an `environment', and the modification of this mapping is termed `binding'. The other layer is the mapping from locations to values; modification of this mapping is called `assignment'. As an example, I had this conversation with Python 3.0rc1. (Python 2 can't illustrate the situation as clearly since it doesn't have `nonlocal'.) >>> ff = [lambda: x for x in [1, 2, 3]] >>> ff[0]() 3 >>> ff[1]() 3 >>> def getset(x): ... def get(): return x ... def set(y): nonlocal x; x = y ... return get, set ... >>> g, s = getset(42) >>> g() 42 >>> s(69) >>> g() 69 >>> ff = [getset(x) for x in [1, 2, 3]] >>> ff[0][0]() 1 >>> ff[1][0]() 2 >>> ff[1][1](5) >>> ff[1][0]() 5 >>> ff[0][0]() 1 >>> ff[2][0]() 3 Again, your challenge is to explain these phenomena -- all of which, I believe are required behaviour of Python 3 -- without talking about both levels of indirection. > At a lower level, what the Python VM does is store the name 'x' in a > dictionary, bound to the object 23. No locations come into it, because > at this level of explanation, dictionaries are an abstract mapping. You've misunderstood my definition of `location'. Here, the dictionary entry for the key `x' would indeed be the location. As a matter of implementation detail, a `dictionary', as understood by Python users as a kind of Python value which implements an associative array, is not actually used to deal with local variables at run-time. Rather, each bound variable is given an index into a vector allocated at function-entry time; variables which are bound in an outer function are also given indices, and looked up in a different vector, allocated when the closure was constructed. > There's no requirement that the abstract dictionary structure works by > storing addresses. I'd hoped I'd been very careful to avoid talking about addresses! Indeed, I'd gone as far as saying that a location was an area of memory, rather than the address of an area of memory, specifically to avoid that trap. Maybe it'll help at this point if I explain that all of the machinery I described above, together with the definitions of pass-by-value and pass-by-reference, can be converted fairly easily (I hope -- the examples below make some headway here) into a formal semantics, with the (intentionally) undefined notion of `immediate representation' of values left as one of its parameters. The use of terms such as `location' is therefore intended to be /indicative/ of common machine architectures, but not exclusively tied to them, since much more abstract systems -- such as, for example, denotational semantics -- can serve just as well. > All we know is that it maps the name 'x' to the object 23 > somehow. Maybe there's no persistent storage, and the dict stores > instructions telling the VM how to recreate the object 23 when it is > needed. Who knows? But at this explanatory level, there are no > locatives involved. Names and objects float as disembodied entities in > the aether, and dicts map one to the other. Explain the list `l' above using this model. > At an even lower explanatory level, the CPython implementation of > dictionaries works by storing a pointer (or if you prefer, a > reference) to the object in a hash table. Pointers, of course, are > locatives, and so finally we come to the explanation you prefer. No! No, no, no! I want to keep locatives /out/ of the picture, because Python doesn't provide them. > I daresay you probably get annoyed at me when I bring up explanations > at the level of copying bytes. You probably feel that for the average > Python programmer, *most of the time* such explanations are more > obfuscatory than useful. My objective is to explain defined semantics: behaviour common to all Python implementations (real, or imagined). > Of course, there are exceptions, such as explaining why repeated > string concatenation is likely to be slow. There is a time and a place > for such low level explanations, but not at the high-level overview > needed by the average Python programmer. Right: performance is inherently related to implementation details and understanding performance requires an understanding of the implementation behaviour. But that's very different from understanding language semantics, which is (I hope) the topic under discussion. > And you would be right. But I argue that your explanation at the level > of references is exactly the same: it is too low level. It relies on > specific details which may not even be true for all implementations of > Python. No. It introduces concepts which are analogous to the way some implementations behave. But as a model for Python, it works for all implementations. > It certainly relies on details which won't be true for hypothetical > versions of Python running on exotic hardware. If they produce other results for my examples above, then they don't implement Python. > If that's too bizarre for you, think about simulating a Python VM in > your own head. If we know one thing about the human brain, it is that > thoughts and concepts are not stored in single, well-defined > locations, so when you think of "x=23", there is no pointer to a > location in your head. But if I'm implementing Python in my mind, I need to invent a concept of location -- or something isomorphic -- or I'll get the semantics wrong. Indeed, this seems to be exactly what's happening to confused beginners -- they're getting the semantics wrong in their minds, so the real implementation doesn't match their expectations. > > No, that's my point: Python programmers /don't/ have direct access to > > objects. The objects themselves are kept at arm's length by the > > indirection layer of references. > > I think you are wrong. If I want a name 'x' to refers to (is bound to) > the object 23, I write x=23, not some variation of: > > create object 23 > give me a reference to that object > bind the reference to name 'x' > > Those three steps may take places at some level of the Python VM, but > that's not what *I* do as a Python programmer. No. You type; the VM obeys. If you want to understand its behaviour, you must > > * A /value/ is an item of data. The range and nature of values is > > language specific. Typically, values encompass at least some kinds > > of numbers, textual data, and compound data structures; they may > > also include behavioural items such as functions. > > Yes. This is an intuitive meaning of the world value. In Python, all > values are objects. Some typical examples of values are: > > 5, None, "Fred", True, 3.5, [2, 3, 4], {}, lambda x: x+1 > > These (and more complicated structures built on top of them) are the > things of interest to the programmer. They are the values: the things > which are denoted by the symbols '5', 'None', '"Fred"' etc. Good: agreement. We're making progress. > > * A /location/[1] is an area of memory suitable for storing the > > /immediate representation/ (which I shall abbreviate to /IR/) of a > > value. (A location may be capable of storing things other than IRs, > > e.g., representations of unevaluated expressions in lazily evaluated > > languages. Locations may vary in size, e.g., in order to be capable > > of storing different types of IRs.) > > At the level of Python code, we have no access to such locations. The > closest we have is the id() function, which uses location in memory as > a unique ID for objects, but this is an accident of the CPython > implementation. Whatever the /immediate representation/ of a value is, > we can't manipulate it directly in Python code. Indeed we have not. But an understanding of their existence is nonetheless essential in order to comprehend Python semantics. Indeed, it's /because/ the locations are not directly visible to a Python programmer that we can describe them in such abstract terms; but omitting them from the explanation altogether leaves important aspects of behaviour unexplained. > > * A /variable/ is a location to which has been /bound/ a name. Given > > an occurrence of a name in a program's source, there is a language > > specific rule for determining the variable to which it is bound. > > According to this definition, there are no variables in Python, because > Python's data model is that names are an abstract mapping between symbols > and values, not between symbols and locations. Chapter and verse? Besides, `names are an abstract mapping'? Names are names, dammit! Names, symbols, identifiers: all mean the same thing. And again, I challenge you to explain the Python 3 interaction above without the concept of location. > > * /Evaluation/ is the process of determining a value from an > > expression. The /value of/ an expression is the result of > > evaluating the expression. This value is, in general, dependent on > > the contents of the locations to which names appearing in the > > expression are bound. > [...] > > The argument passing model `pass-by-value' has a number of distinctive > > properties. > > > > * The argument expression is fully evaluated before the function is > > called, yielding an argument value. > > > > * The corresponding parameter name is bound to a fresh location. > > > > * The argument value IR is stored in the parameter's location. > > This is an underspecified definition. Without a definition of > /immediate representation/, we can't determine what this means. It is intentionally underspecified, since the immediate representation of values varies between languages, and the whole point was to define the argument passing models in a language-independent manner. > I can guess that, based on Pascal, Fortran and C, the /immediate > representation/ of a value is whatever data structure represents that > value. However, I fear that you are going to try to slip in an > open-ended definition, that /immediate representation/ could be > *anything* -- for ints in C, it will be the bytes that represent the > int; for C arrays, it will be a pointer to the bytes that represent > the array; for Python, it will be references to objects; for Algol 60, > it will be thunks. No slipping involved. The definition is quite intentionally open-ended, and if I didn't make it explicit then I should have done. C arrays are strange: it is simply impossible for an array to be the value of a C expression (except in the very strange case of the operand of `sizeof'); therefore I don't need to define an IR for arrays to get pass-by-value to work: the fact that argument expressions are evaluated eliminates all arrays at the first step. Regarding Algol, no, you can't catch me out that easily. A thunk in Algol represents an /unevaluated expression/. But I've only made use of immediate representation of /values/ -- i.e., the result of fully evaluating an expression. I should have made this explicit: immediate representations are the `common currency' for doing expression evaluation. Expressions are (typically) constructed from subexpressions: to evaluate, one gathers the values of the subexpressions -- recursively if necessary -- and combines them in the appropriate manner to discover the final value. We do this in fact by manipulating immediate representations. One kind of subexpression is typically an identifier: this is an interesting case, so I'll talk about it in detail. To evaluate an identifier, we find the location bound to that identifier, and extract the IR from the location. We've got a lot of types, processes and mappings. Let's make it clear what's going on. Types: N: names V: values R: immediate representations L: locations X: expressions E = N -> L: environments S = L -> R: stores Operations: rep: V -> R value to immediate-representation unrep: R -> V immediate-representation to value eval: (X, E, S) -> (R, S) evaluation alloc: () -> L yields a fresh location (A `store' maintains the mapping between locations and their contents. It's an input to evaluation because one needs to retrieve the contents of variables; it's an output because evaluating some expressions may have side effects on storage.) Names are a kind of expression. The operation of retrieving a variable looks like this: eval(n, e, s) = (s(e(n)), s) That is, we look the name up in the environment to find a location, and we find the contents of the location in the store; the store is unchanged by this operation. Assignment to a variable is straightforward in this model: assgn(n, e, s, r) = (?, s[r/e(n)]) For the unfamiliar: x[y/z] is a function which behaves like x, except that it returns y on input z: i.e., y if a = z x[y/z](a) = { x(a) if a /= z That is, the /value/ of assignment is language-specific (and it may not syntactically be an expression, but statements can be modelled as expressions which yield unspecified values which are unavailable to the program due to syntactic constraints, and this saves us having to introduce another kind of thing). Note that we don't actually need the rep/unrep operations in order to define the semantics, at least until we actually start constructing values. > To avoid weakening pass-by-value to mean everything and anything at > all, I'm going to say that the /immediate representation/ is the bytes > which represent the value. And this decision takes you back round another loop of the argument and leads you to all manner of difficulty. No, the right answer is necessarily language-specific. Besides, I never mentioned bytes when discussing values, and certainly the idea that there might be a unique representation in terms of bytes is completely wrong. I hope I've already shown that my definition of pass-by-value is /not/ so weak as to allow anything at all -- in particular, it doesn't have the same semantics as pass-by-reference or pass-by-name. To this end, let's formalize it some more. Suppose we have an argument expression x, which is part of a call to a function f; x is to be evaluated in environment e, with store s. We first evaluate the argument: (r, s') = eval(x, e, s) We now allocate a fresh location for the corresponding parameter l = alloc() and bind the parameter name -- call it n -- in the function's environment e': e'' = e'[l/n] Finally, we store the argument value representation in the location: s'' = s'[r/l] We do this for all the pass-by-value arguments (it doesn't matter whether we do the parameter stores all at once later or interleaved, because the locations are distinct from all previous locations), augmenting the environment e''. We evaluate the function body with respect to the final store and this augmented environment. This model is now sufficiently detailed that we can /prove/ that implementing `swap' using pass-by-value (as defined here) is impossible. The soundbite version of all of this: pass-by-value means that the parameters are distinct variables, which are initialized by assignment. > (That is, the value itself.) No! Be very careful here. Do not confuse the value with its representation: to do so is to fall into a very nasty trap. A sequence of bytes is not a number, for example, though one may define mappings between the two. > > By contrast, the `pass-by-reference' model has other distinguishing > > properties. > > > > * Whether arbitrary argument expressions are permitted is language > > dependent; often, only a subset of available expressions -- those > > that designate locations -- are permitted. > > As you said above: "The /value of/ an expression is the result of > evaluating the expression". Given the expression 2+3, the result of that > expression is 5, not the location where 5 is stored. Right... > There is no reason to believe that 5 designates a location, as opposed > to designating the number of peas in a pod or the average length of a > piece of string. And indeed I don't think that 5 does designate a location. But fortunately my definition wasn't talking about /values/ designating locations: it was talking about /expressions/ designating locations, and that's entirely different. Considered as expressions, `2 + 3' does not equal `5' -- one contains an addition operator and two subexpressions, each an integer constant, whereas the other is a single constant. The two should produce the same result on evaluation, but that's a different matter. > For want of a better description, let me re-word the above to say: > > * Whether arbitrary argument expressions are permitted is language > dependent; often, only a subset of available expressions -- e.g. those > that evaluate at a named location -- are permitted. > > Note that I say they evaluate *at*, not *to*, a fixed location. Yes, I noticed that, but I don't know what it means. > A practical example, to ensure we're talking about the same thing. In > Pascal, I can declare a procedure swap(a, b) taking two VAR parameters, > which use call-by-reference semantics. I might do something like this: > > a := 8; { number of peas in a pod } > b := 13; { a baker's dozen } > swap(a, b); > > Even though the values of a and b do not designate locations, the > compiler can pass them to the procedure because the named variables a > and b exist *at* particular locations. The values of `a' and `b' aren't important here. What is important is that the /expression/ `a' designates a location, namely the location bound to the name `a'; similarly for `b'. > Contrast this with: > > swap(a, 10+3); And `10 + 3' does not designate a location. (The circumlocution involved with `designating locations' is to cope with expressions like `v[5]' as well as simple names. In some languages, an expression which designates a location is said to produce an `lvalue' rather than an `rvalue'; we can think of an `lvalue' as being a location and an `rvalue' as being an immediate representation: we can convert the former to the latter by consulting the store; but we cannot convert in the other direction without allocating.) > which will fail in Pascal, because the value of the expression 10+3 > doesn't correspond to a named location. (Presumably this is a design > choice, because the value of the expression will certainly exist at a > known location, although possibly not known until runtime.) I think the design choice is that it's not considered meaningful to modify the value of `10 + 3', whereas it is considered meaningful to modify the value of `a'. (In both cases, by `the value of FOO', I mean `the result of evaluating the expression FOO'.) > > If the argument expression does designate a location, then this > > location is the /argument location/. > > Replace this with "If the argument expression does evaluate at an > allowed location (named location for Pascal), then..." and I will > accept it. I still don't know what `evaluate at' means. > > * The corresponding parameter name is bound to the argument location. > > According to this definition, Python is call-by-reference. Refer my > code snippet above. No. Work through it again, now I've explained what's going on more clearly. Here's the more formal version. We need some new notions. Types: D: expressions which designate locations Operations: loc: (D, E, S) -> (L, S) location designated by expression Important: D is a subset of X; if (l, s') = loc(d, e, s) then (axiomatically) (s'(l), s') = eval(d, e, s) If n is a name, then loc(n, e, s) = (e(n), s) (and we can see that this definition is consistent with the one above). So, pass by reference. Let x be the argument expression, e the caller's environment, and s the prevailing store. Firstly, if x in D then (l, s'') = loc(x, e, s) Otherwise (if supported), (r, s') = eval(x, e, s) l = alloc() s'' = s'[r/l] (Note that, after this, we always have (s''(l), s'') = eval(x, e, s).) If n is the corresponding parameter name, and e' is the function's enclosing environment, then all we need to complete the job is e'' = e'[l/n] The significant difference between the two is that, in pass-by-value, the parameter names are /always/ bound to fresh locations, whereas in pass-by-reference this need not be the case. The soundbite version of all of this: pass-by-reference means that new variables are not constructed; rather, new names are given to the caller's variables. > But clearly Python doesn't behave like call-by-reference in other > languages: you can't write a swap() procedure. The definition I've given for call-by-reference should make it possible to write a `swap'. Indeed, `can I write swap?' is a good rule-of-thumb test for call-by-reference -- though it may also detect call-by-name and more exotic things. > This is where I quote Barbara Liskov, talking about the language CLU > which has precisely the same calling semantics as Python: > > "In particular it is not call by value because mutations of arguments > performed by the called routine will be visible to the caller. And it > is not call by reference because access is not given to the variables > of the caller, but merely to certain objects." Quite why she decided that CLU isn't call-by-value, despite it having the same semantics as Lisp which certainly is call-by-value and has been so since 1958 (and may even have introduced the concept!) is a mystery to me. > Once you start declaring that a language is "pass-by-value, where the > value is a Foo rather than the actual value", pass-by-value can be > used to describe *anything*. Pass- by-reference becomes pass-by-value > where the value is the location of the value. No, it can't. Or prove your claim: provide a definition of `immediate representation' which allows one to implement `swap' using call-by-value semantics. > Pass-by-object is pass-by-value where the value is a reference to the > object (your claim). I don't believe in `pass-by-object' as being a different thing, no. > > Even for those. C doesn't pass arrays at all; instead it passes > > (programmer-visible) pointers. See other article. > > But you are conflating concepts again. The value of an array is the > array: it's what the programmer asked for when he declared an array. See > your own definition of value above: "A /value/ is an item of data." Again: in C, the value of an expression cannot be an array (6.3.2.1p3). The definition of pass-by-value requires that the argument expression be evaluated. Therefore, the resulting argument value cannot be an array; it is, instead, a pointer, and that pointer is passed by value. I'll quote 6.3.2.1p3 in full: : [#3] Except when it is the operand of the sizeof operator or the unary : & operator, or is a string literal used to initialize an array, an : expression that has type ``array of type'' is converted to an : expression with type ``pointer to type'' that points to the initial : element of the array object and is not an lvalue. If the array object : has register storage class, the behavior is undefined. This happens logically before function calling: there is a sequence point before the call (6.5.2.2p10). Note that 6.5.2.2 (which defines the behaviour of the function call operator) does not mention arrays at all. Rather, it describes conversion of arguments, as if by assignment, for function types with and without prototypes, and for variadic functions, and then states: : [#8] No other conversions are performed implicitly; in particular, the : number and types of arguments are not compared with those of the : parameters in a function definition that does not include a function : prototype declarator. (6.5.16, which describes assignment, doesn't mention arrays either.) > You get pass-by-value semantics: when you pass an array to foo, the > entire array is duplicated. Changes to x are not visible in the caller's > array. C arrays do not behave like this with an equivalent > declaration. But that's because of the (bizarre) way that arrays are treated during expression evaluation. > Change the declaration to be VAR x, and using pass-by-reference > semantics, and the array is *not* duplicated, and changes to x *are* > visible to the caller. C's default handling of arrays is just like > Pascal's call-by-reference semantics, not like pass-by-value. This is > AFAIK unique in C to arrays. The effect is similar from the point of view of the caller; the cause is very different, as is the whole situation from the point of view of the called function, which is left with an explicit pointer. > > And this is entirely due to the difference in their immediate > > representations of values. > > Values are values. Regardless of whether you are using C or Pascal or > Python, the value of 1+1 is 2, not some arbitrary memory location. I'm > going to quote from Fredrik Lundh: > > "I'm not aware of any language where a reference to an object, rather > than the *contents* of the object, is seen as the object's actual value. > It's definitely not true for Python, at least." And that's why I've been at such pains to distinguish the /immediate representation/ of the value from the value itself. > The viewpoint that values are references is bizarre and counter- > intuitive, and it leaves us with no simple way of talking about the value > of expressions in the sense that 2 is the value of the expression 1+1. Unless one introduces the necessary concept of representation. Fortunately I did that. -- [mdw] From mdw at distorted.org.uk Sat Jan 10 10:49:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 15:49:17 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <2acdbff5-ece7-4564-8bb4-2cfceb425d23@i24g2000prf.googlegroups.com> <836839a0-0942-42f9-a1c8-2c45f1af3fe3@x16g2000prn.googlegroups.com> <40e0514b-89bb-4d50-b1dc-46662f67d637@a29g2000pra.googlegroups.com> <018aaa94-f846-45af-9be2-60f359c49760@w24g2000prd.googlegroups.com> <572cfcef-2b21-4508-9585-e447ccca5af3@g1g2000pra.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Agreed. I think the docs, especially those that develop > the conceptual model of how Python work at runtime, could > use some major attention. If we can achieve consensus in this (still remarkably civil) discussion, we might be able to amend the docs. > I would be willing to bet that most of the confused posters do not > distinguish between assignment operation (AO) and data model (DM). > Their conceptual box is labeled "assignment behavior" and includes > both AO and DM. They expect that AO+DM in Python will produce the > same results in Python as they are used to in the other languages > they've used. That the discrepancy comes from the DM part rather than > the AO part is pretty irrelevant to them given that world view. I think that we're in agreement, up to this point at least. That's good. My claim is that, until they learn to distinguish these two aspects of Python's semantics, they will remain confused. -- [mdw] From hsoft at hardcoded.net Sat Jan 10 10:49:20 2009 From: hsoft at hardcoded.net (hsoft at hardcoded.net) Date: Sat, 10 Jan 2009 07:49:20 -0800 (PST) Subject: Mocking `from foo import *` functions References: Message-ID: <68239214-859a-4484-91b1-ec208393d28d@f40g2000pri.googlegroups.com> On Jan 10, 4:19?pm, Rob Williscroft wrote: > Note that doing the above *before* any other module imports > from sender, will be sufficient in *any* case, though it won't > help if the tested code calls reload( sender ). Yeah, of course, but most of the time, you want to mock at the *test* level, (you don't want your mock to affect all the tests in your module), so you can't just mock the function before you import your tested module. That is why I created this handy TestCase. From mwilson at the-wire.com Sat Jan 10 11:04:19 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 10 Jan 2009 11:04:19 -0500 Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: Aaron Brady wrote: > Lastly, I don't see any reason why we couldn't make both explanations > available. 'For those coming from Java/etc....; for those coming from > C++/etc.....' They would both get read. That's what I was just thinking .. there are lots of others, too: "for those coming from relational database theory..." would be a good one. Mel. From bj_666 at gmx.net Sat Jan 10 11:08:35 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 10 Jan 2009 16:08:35 GMT Subject: are there some special about '\x1a' symbol References: Message-ID: <6srvg2F7o3lrU2@mid.uni-berlin.de> On Sat, 10 Jan 2009 07:45:53 -0800, sim.sim wrote: > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, it > gives expected result: > >>>> open("test", "w").write('before\x1aafter') open('test').read() > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > >>>> open("test", "w").write('before\x1aafter') open('test').read() > 'before' > > Here I can write all symbols, but not read. I've tested it with python > 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? \x1a is treated as "end of text" character in text files by Windows. So if you want all, unaltered data, open the file in binary mode ('rb' and 'wb'). Ciao, Marc 'BlackJack' Rintsch From mwilson at the-wire.com Sat Jan 10 11:27:40 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 10 Jan 2009 11:27:40 -0500 Subject: are there some special about '\x1a' symbol References: Message-ID: sim.sim wrote: > Hi all! > > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, > it gives expected result: > >>>> open("test", "w").write('before\x1aafter') >>>> open('test').read() > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > >>>> open("test", "w").write('before\x1aafter') >>>> open('test').read() > 'before' > > Here I can write all symbols, but not read. > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? '\x1a' is the End-of-file mark that Windows inherited from MS-DOS and CP/M. The underlying Windows libraries honour it for files opened in text mode. open ('test', 'rb').read() will read the whole file. Mel. From rt8396 at gmail.com Sat Jan 10 11:45:31 2009 From: rt8396 at gmail.com (r) Date: Sat, 10 Jan 2009 08:45:31 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: Message-ID: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> We need TK 8.5's themes. This will bring Tkinter out of the dark ages and into the 21st Century! And improve the shine of the Python base distro. Python could use a good boost right now! From davidgshi at yahoo.co.uk Sat Jan 10 12:12:30 2009 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 10 Jan 2009 17:12:30 +0000 (GMT) Subject: Looking for an efficient Python script to download and save a .zip file programmatically Message-ID: <324592.49250.qm@web26307.mail.ukl.yahoo.com> I am looking for an efficient Python script to download and save a .zip file programmatically (from http or https call). ? Regards. ? David -------------- next part -------------- An HTML attachment was scrubbed... URL: From bockman at virgilio.it Sat Jan 10 12:39:55 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sat, 10 Jan 2009 18:39:55 +0100 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6sone1F7bavsU5@mid.uni-berlin.de> Message-ID: On Fri, 09 Jan 2009 15:34:17 +0000, MRAB wrote: > Marc 'BlackJack' Rintsch wrote: >> On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote: >> >>> As this was horribly slow (20 Minutes for a 2GB file) I coded the whole >>> thing in C also: >> >> Yours took ~37 minutes for 2 GiB here. This "just" ~15 minutes: >> >> #!/usr/bin/env python >> from __future__ import division, with_statement >> import os >> import sys >> from collections import defaultdict >> from functools import partial >> from itertools import imap >> >> >> def iter_max_values(blocks, block_count): >> for i, block in enumerate(blocks): >> histogram = defaultdict(int) >> for byte in block: >> histogram[byte] += 1 >> >> yield max((count, byte) >> for value, count in histogram.iteritems())[1] >> > [snip] > Would it be faster if histogram was a list initialised to [0] * 256? I tried it on my computer, also getting character codes with struct.unpack, like this: histogram = [0,]*256 for byte in struct.unpack( '%dB'%len(block), block ): histogram[byte] +=1 yield max(( count, byte ) for idx, count in enumerate(histogram))[1] and I also removed the map( ord ... ) statement in main program, since iter_max_values mow returns character codes directly. The result is 10 minutes against the 13 of the original 'BlackJack's code on my PC (iMac Intel python 2.6.1). Strangely, using histogram = array.array( 'i', [0,]*256 ) gives again 13 minutes, even if I create the array outside the loop and then use histogram[:] = zero_array to reset the values. Ciao ----- FB From lipun4u at gmail.com Sat Jan 10 12:56:19 2009 From: lipun4u at gmail.com (asit) Date: Sat, 10 Jan 2009 09:56:19 -0800 (PST) Subject: urlopen exception Message-ID: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> site="www.bput.org" payloads="" attack= urllib2.urlopen(site+payloads,80).readlines() according to my best knowledge, the above code is correct. but why it throws exceptio ???? From marduk at letterboxes.org Sat Jan 10 13:09:17 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 10 Jan 2009 13:09:17 -0500 Subject: Looking for an efficient Python script to download and save a .zip file programmatically In-Reply-To: <324592.49250.qm@web26307.mail.ukl.yahoo.com> References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: <1231610957.3226.1.camel@blackwidow.nbk> On Sat, 2009-01-10 at 17:12 +0000, David Shi wrote: > I am looking for an efficient Python script to download and save > a .zip file programmatically (from http or https call). > > Regards. > > David urllib? -a -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Jan 10 13:22:00 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 10 Jan 2009 13:22:00 -0500 Subject: if-else statement In-Reply-To: References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: <83D3AADE-455A-4170-A340-C2DA3EB75EF2@semanchuk.com> On Jan 10, 2009, at 9:26 AM, Duncan Booth wrote: > Gandalf wrote: > >> other languages like PHP or javascript as this if-else operator like >> this >> >> myVar = checking == 1? 'string': 'other string' >> >> is this stuff exist in python? >> > See http://docs.python.org/reference/expressions.html#boolean-operations > > conditional_expression ::= or_test ["if" or_test "else" expression] > > ... > > The expression x if C else y first evaluates C (not x); if C is > true, x is > evaluated and its value is returned; otherwise, y is evaluated and its > value is returned. Gandalf, I'd add to the above that this expression was only added to Python in v2.5, so if you want your code to be compatible with versions of Python <= 2.4, you should not use the ternary if. bye Philip From rurpy at yahoo.com Sat Jan 10 13:44:37 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 10 Jan 2009 10:44:37 -0800 (PST) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> Message-ID: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> On Jan 9, 6:47 am, Mark Wooding wrote: > ru... at yahoo.com wrote: > > As a side comment (because it always bugs me when I read this, even > > though I read it in very authoritative sources), ISTM that C passes > > everything by value except arrays; they are passed by reference (by > > passing a pointer to the array by value.) Admittedly, the close > > relationship between arrays and pointers makes it easy conflate them. > > Arrays are distinctly second-class citizens in C. > > Basically, in C, arrays aren't passed at all but there's some syntactic > sugar so you can squint and con yourself that they're passed by > reference. > > If you try to pass an array, the array name immediately decays to a > pointer, and the pointer gets passed instead -- by value. The > corresponding function parameter must be a pointer to an approrpriate > kind of thing, though you're allowed to write []s to confuse yourself if > you like -- T D[] in a function parameter declaration means precisely > the same as T *D -- to the extent that &D has type T **D and so on. What is the observable difference between converting an array to a reference (pointer) to that array and passing the reference by value, and passing the array by reference? That is, given a C-like compiler that is the same as C except that it passes arrays by reference, how would it differ from an ordinary C compiler? The choice of terminology (in this case) seems to me to be a matter of convention rather than any fundamental observable difference. I guess the case for pass-by-value would be a little stronger because one has to have "passing a pointer by value" anyway (since pointers are first-class datatypes) and that can be used to describe passing arrays (as you described). Adding a second mechanism, "passing-arrays-by-reference", is perhaps unnecessary, but not wrong, and may be more easily understandable to the target audience. From ryandw at gmail.com Sat Jan 10 14:15:45 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 10 Jan 2009 11:15:45 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> Message-ID: <64bd3670-b642-48d0-8edb-a5c24121a0a8@r37g2000prr.googlegroups.com> On Jan 9, 6:07?pm, John Machin wrote: > Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as > God^H^H^HGates intended: > > >>> buff = open('data', 'rb').read() > >>> buff[:100] > > '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> > \x00<\x00B\x0 > 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> > \x000\x00.\x000\x000\x000\x000\x0 > 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< > \x00S\x00t\x0 > 0a\x00t\x00'>>> buff[:100].decode('utf_16_le') There it is. Thanks. > u'0.0000 > > > > ?But if I return it to my browser with python+django, > > there are bad characters every other character > > Please consider that we might have difficulty guessing what "return it > to my browser with python+django" means. Show actual code. I did stop and consider what code to show. I tried to show only the code that seemed relevant, as there are sometimes complaints on this and other groups when someone shows more than the relevant code. You solved my problem with decode('utf_16_le'). I can't find any description of that encoding on the WWW... and I thought *everything* was on the WWW. :) I didn't know the data was utf_16_le-encoded because I'm getting it from a service. I don't even know if *they* know what encoding they used. I'm not sure how you knew what the encoding was. > Please consider reading the Unicode HOWTO athttp://docs.python.org/howto/unicode.html Probably wouldn't hurt, though reading that HOWTO wouldn't have given me the encoding, I don't think. -Ryan > Cheers, > John From mdw at distorted.org.uk Sat Jan 10 14:31:57 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 10 Jan 2009 19:31:57 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? For one: #include static size_t foo(char v[]) { return sizeof v; } int main(void) { char v[sizeof(char *) * 10]; puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); return (0); } For another: static void bar(char v[]) { char ch = 0; v = &ch; } /* type error if arrays truly passed by reference */ > I guess the case for pass-by-value would be a little stronger because > one has to have "passing a pointer by value" anyway (since pointers > are first-class datatypes) and that can be used to describe passing > arrays (as you described). The difference is that the /callee/ function is different between the two cases. Also, notice that arrays in expressions turn into pointers in the same way, so function argument passing works the same way as assignment -- a hallmark of pass-by-value. -- [mdw] From ryandw at gmail.com Sat Jan 10 14:32:01 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 10 Jan 2009 11:32:01 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> Message-ID: <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> On Jan 9, 7:33?pm, John Machin wrote: > It is not impossible for a file with dummy data to have been > handcrafted or otherwise produced by a process different to that used > for a real-data file. I knew it was produced by the same process, or I wouldn't have shared it. : ) But you couldn't have known that. > > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick > with one thread ... Thanks... I thought I was posting about separate issues and would annoy people who were only interested in one of the issues if I put them both in the same thread. I guess all posts re: the same script should go in one thread, even if the questions posed may be unrelated and may be separate issues. There are grey areas. Problem solved in John Machin's post at http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/03b8341539d87989?hl=en&lnk=raot#03b8341539d87989 I'll post the final code when it's prettier. -Ryan From gnewsg at gmail.com Sat Jan 10 14:37:42 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 10 Jan 2009 11:37:42 -0800 (PST) Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: On 10 Gen, 03:07, "p." wrote: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? You could retrieve your file in little parts and at the same time have a thread which checks how many bytes have been transmitted every second. --- Giampaolo http://code.google.com/p/pyftpdlib From gnewsg at gmail.com Sat Jan 10 14:39:04 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 10 Jan 2009 11:39:04 -0800 (PST) Subject: download timeout vs. socket timeout References: <3cc7e6dc-5da4-4ac5-957d-0389655cd58d@p2g2000prn.googlegroups.com> Message-ID: I'm sorry. I realized they had already replied when it was too late. --- Giampaolo http://code.google.com/p/pyftpdlib From joe at strout.net Sat Jan 10 14:49:48 2009 From: joe at strout.net (Joe Strout) Date: Sat, 10 Jan 2009 12:49:48 -0700 Subject: why cannot assign to function call In-Reply-To: References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <4968FBDC.4030202@strout.net> Aaron Brady wrote: >> Aaron Brady wrote: >>> Possible compromise. You can think of functions as mutation-only. >>> You pass the object, and it gets a new (additional) name. The old >>> name doesn't go in. >> That's correct. The reference itself is passed in, not the variable (or >> expression) that held or generated the reference in the calling code. > > This is very odd, and I see it quite a bit. > Me: "You pass the object." > Joe: "That's correct. You pass the reference." > > What was wrong with my original? I'm saying that I believe your idea was correct, but worded imprecisely (IMHO of course). So I restated what I believed you were saying, using terminology which I believe to be more precise. If nothing else, this gives you the opportunity to say "No, that's not what I meant at all." >> This is true. (Technically, instead of variable, we should say "LValue" >> here -- there are things slightly more complex than simple variables >> that can serve as the left-hand side of an assignment. So replace >> "variable" with "lvalue" above if you prefer.) > > This is a point worth making. I want to penny-pinch every term in an > introductory text, though, so, it's a tough call. Agreed. >> M2: If 'fun()' returned a reference, you might be able to mutate the >> object that refers to. >> m2: You can sometimes mutate the object it refers to. >> C2: 'fun()' returns a reference. > > This is horrendous. > http://en.wikipedia.org/wiki/Formal_fallacy > http://en.wikipedia.org/wiki/Affirming_the_consequent I did point out that the logic was incorrect (even though the conclusion, in this case, happens to be true). > A question: Are you Joe and you Mark certain that the simplest > possible introductory explanation makes use of the term 'reference'? I am. > Perhaps we can have a contest for shortest/simplest/best description > of Python's data/variable/argument model. Sure -- but it judging it might be difficult, requiring some newbies and a test to check their comprehension (as you and I pondered once before). > Lastly, I don't see any reason why we couldn't make both explanations > available. 'For those coming from Java/etc....; for those coming from > C++/etc.....' They would both get read. Yes, except that the reference explanation applies equally well to anyone coming from Java, C/C++, RB, VB.NET, and probably others... I'm not sure to whom the other explanation would appeal, unless perhaps it's LISP programmers (just a guess, since those on that side of the aisle seem to invoke LISP more frequently). Best, - Joe From joe at strout.net Sat Jan 10 14:52:47 2009 From: joe at strout.net (Joe Strout) Date: Sat, 10 Jan 2009 12:52:47 -0700 Subject: why cannot assign to function call In-Reply-To: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <4968FC8F.2070306@strout.net> rurpy at yahoo.com wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? The difference is whether an assignment to the formal parameter (within the function) affects the actual parameter (in the calling code). If it does, then that's pass by reference. If it does not, then that's pass by value. > That is, given a C-like compiler that is the same as > C except that it passes arrays by reference, how would > it differ from an ordinary C compiler? Such a compiler is available: it's called C++, and it gives the programmer the choice to pass by value or pass by reference (the latter indicated by adding "&" to the parameter in the function declaration, just like you would add "ByRef" in RB or VB.NET). If the parameter is called "foo", and you pass in "bar", then foo = SomeNewArray(); would change bar if it were passed by reference; it would not affect bar at all if it were passed by value. The two are quite distinct. Best, - Joe From Scott.Daniels at Acm.Org Sat Jan 10 15:12:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 10 Jan 2009 12:12:07 -0800 Subject: if-else statement In-Reply-To: References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: Duncan Booth wrote: > Gandalf wrote: >> other languages ... [have an] if-else operator like... >> myVar = checking == 1? 'string': 'other string' > See http://docs.python.org/reference/expressions.html#boolean-operations > ... > The expression x if C else y first evaluates C (not x); if C is true, x is > evaluated and its value is returned; otherwise, y is evaluated and its > value is returned. While we _do_ have the form if else , it is generally agreed that in most cases your code will be more clear with explicit tests and assignments. Your particular example is better if checking: my_var = 'string' else: my_var = 'other string' remember, vertical space only kills trees if printed. --Scott David Daniels (who still prints this too frequently). Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sat Jan 10 15:28:47 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 10 Jan 2009 12:28:47 -0800 (PST) Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> Message-ID: <96d8f9f5-2679-4855-8b8a-7caaf4e5a410@b38g2000prf.googlegroups.com> Scott David Daniels: > ? ? ? if checking: > ? ? ? ? ? my_var = 'string' > ? ? ? else: > ? ? ? ? ? my_var = 'other string' > > remember, vertical space only kills trees if printed. I value clarity a lot. But this is more DRY, sometimes it's almost equally clear, and you reduce vertical space, packing more code in the same space, this allows you to see more logic, allowing you to have a higher level view of the code, so allows you to understand the code better: my_var = 'string' if checking else 'other string' So I think that sometimes it's useful. Bye, bearophile From steve at holdenweb.com Sat Jan 10 15:32:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 15:32:52 -0500 Subject: urlopen exception In-Reply-To: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: asit wrote: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? what exception it throw? -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Sat Jan 10 15:42:28 2009 From: http (Paul Rubin) Date: 10 Jan 2009 12:42:28 -0800 Subject: urlopen exception References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: <7xbpuesxjf.fsf@ruckus.brouhaha.com> asit writes: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? The code is incorrect. Look at the string ou are sending into urlopen. What on earth are you trying to do? From excord80 at gmail.com Sat Jan 10 16:05:39 2009 From: excord80 at gmail.com (excord80) Date: Sat, 10 Jan 2009 13:05:39 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> Message-ID: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> On Jan 10, 11:45?am, r wrote: > We need TK 8.5's themes. This will bring Tkinter out of the dark ages > and into the 21st Century! And improve the shine of the Python base > distro. Python could use a good boost right now! Could someone please explain what Tix provides compared to what the new stuff in Tk 8.5 provides? Is there much overlap? From sjmachin at lexicon.net Sat Jan 10 16:18:14 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 10 Jan 2009 13:18:14 -0800 (PST) Subject: distinction between unzipping bytes and unzipping a file References: <65507e70-722d-4388-a842-5fa063816a6a@d32g2000yqe.googlegroups.com> <4866bea60901091308h3a60dd05kbba938408103e102@mail.gmail.com> <510bd446-0e18-4c65-9444-65141ead8e69@r10g2000prf.googlegroups.com> <64d4e482-cf61-48d7-bb79-bf21e48dc1e1@35g2000pry.googlegroups.com> <64bd3670-b642-48d0-8edb-a5c24121a0a8@r37g2000prr.googlegroups.com> Message-ID: <25480c03-26e6-4f77-8d83-87a3aa5fc6a0@v5g2000prm.googlegroups.com> On Jan 11, 6:15?am, webcomm wrote: > On Jan 9, 6:07?pm, John Machin wrote: > > > Yup, it looks like it's encoded in utf_16_le, i.e. no BOM as > > God^H^H^HGates intended: > > > >>> buff = open('data', 'rb').read() > > >>> buff[:100] > > > '<\x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00a\x00t\x00i\x00o\x00n\x00> > > \x00<\x00B\x0 > > 0a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00> > > \x000\x00.\x000\x000\x000\x000\x0 > > 0<\x00/\x00B\x00a\x00l\x00a\x00n\x00c\x00e\x00D\x00u\x00e\x00>\x00< > > \x00S\x00t\x0 > > 0a\x00t\x00' > > >>> buff[:100].decode('utf_16_le') > > There it is. ?Thanks. > > > u'0.0000 > > > ?But if I return it to my browser with python+django, > > > there are bad characters every other character > > > Please consider that we might have difficulty guessing what "return it > > to my browser with python+django" means. Show actual code. > > I did stop and consider what code to show. ?I tried to show only the > code that seemed relevant, as there are sometimes complaints on this > and other groups when someone shows more than the relevant code. ?You > solved my problem with decode('utf_16_le'). ?I can't find any > description of that encoding on the WWW... and I thought *everything* > was on the WWW. ?:) Try searching using the official name UTF-16LE ... looks like a blind spot in the approximate matching algorithm(s) used by the search engine (s) that you tried :-( > I didn't know the data was utf_16_le-encoded because I'm getting it > from a service. ?I don't even know if *they* know what encoding they > used. ?I'm not sure how you knew what the encoding was. Actually looked at the raw data. Pattern appeared to be an alternation of 1 "meaningful" byte and one zero ('\x00') byte: => UTF16*. No BOM ('\xFE\xFF' or '\xFF\xFE') at start of file: => UTF16-?E. First byte is meaningful: => UTF16-LE. > > Please consider reading the Unicode HOWTO at http://docs.python.org/howto/unicode.html > > Probably wouldn't hurt, Definitely won't hurt. Could even help. > though reading that HOWTO wouldn't have given > me the encoding, I don't think. It wasn't intended to give you the encoding. Just read it. Cheers, John From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:28:32 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:28:32 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path? I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:29:22 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:29:22 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <5ebf9dbd-1666-49f6-ad31-e6a4e0a91e52@g3g2000pre.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path on MacOSX? I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:30:36 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:30:36 -0800 (PST) Subject: Python 2.6.1 @executable_path Message-ID: <7e187df9-e6d8-4c49-94ad-74c2f8ec5297@i18g2000prf.googlegroups.com> Hi! I asked something similar a few days ago. Is it possible to compile Python 2.6.1 with a dynamic path on Mac OSX Leopard 10.5.x. I found out that I could use @executable_path but I don't know how the configure command would look like. This is my current configure command for the default /Library/ Frameworks/ path: ./configure --with-framework-name=Python --with-universal-archs=all -- enable-framework --enable-universalsdk=/ Can anyone help me? Thanks. From sjmachin at lexicon.net Sat Jan 10 16:40:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 10 Jan 2009 13:40:44 -0800 (PST) Subject: are there some special about '\x1a' symbol References: Message-ID: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> On Jan 11, 2:45?am, "sim.sim" wrote: > Hi all! > > I had touch with some different python behavior: I was tried to write > into a file a string with the '\x1a' symbol, and for FreeBSD system, > it gives expected result: > > >>> open("test", "w").write('before\x1aafter') > >>> open('test').read() > > 'before\x1aafter' > > but for my WinXP box, it gives some strange: > > >>> open("test", "w").write('before\x1aafter') > >>> open('test').read() > > 'before' > > Here I can write all symbols, but not read. > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > Why is it so and is it possible to fix it? You've already got two good answers, but this might add a little more explanation: You will aware that in Windows Command Prompt, to exit the interactive mode of Python (among others), you need to type Ctrl-Z ... | C:\junk>python | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> problem = '\x1a' | >>> ord(problem) | 26 | >>> # What is the 26th letter of the English/ASCII alphabet? | ... | >>> ^Z | | C:\junk> HTH, John From martin at v.loewis.de Sat Jan 10 16:47:49 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 10 Jan 2009 22:47:49 +0100 Subject: Python 2.6.1 @executable_path In-Reply-To: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> Message-ID: <49691785$0$25150$9b622d9e@news.freenet.de> > I asked something similar a few days ago. Is it possible to compile > Python 2.6.1 with a dynamic path? What is a "dynamic path"? Regards, Martin From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:55:43 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:55:43 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: <5ebb4054-89d3-4261-b218-f4fa3d841766@35g2000pry.googlegroups.com> I want to embedd it into another app so on the 'customers'-mac I want to put python into a subdirectory of my app. bye From googler.1.webmaster at spamgourmet.com Sat Jan 10 16:57:27 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 13:57:27 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: I want to embedd it into my app so on the 'customers'-mac I want to put python into a subdirectory of my app. and with the configure command above, that will not work because the library has to be on every system in /Library/Framework/ so I found out that @executable_path is replaced by the path of the app. bye From nad at acm.org Sat Jan 10 17:11:49 2009 From: nad at acm.org (Ned Deily) Date: Sat, 10 Jan 2009 14:11:49 -0800 Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: In article , googler.1.webmaster at spamgourmet.com wrote: > I want to embedd it into my app so on the 'customers'-mac I want > to put python into a subdirectory of my app. > > and with the configure command above, that will not work > because the library has to be on every system in /Library/Framework/ > so I found out that @executable_path is replaced by the path of the > app. Have you looked at py2app yet? It should take care of all that for you. http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html -- Ned Deily, nad at acm.org From clp2 at rebertia.com Sat Jan 10 17:23:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 14:23:08 -0800 Subject: Looking for an efficient Python script to download and save a .zip file programmatically In-Reply-To: <324592.49250.qm@web26307.mail.ukl.yahoo.com> References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: <50697b2c0901101423x4ac9608ekc31570459f459ea2@mail.gmail.com> On Sat, Jan 10, 2009 at 9:12 AM, David Shi wrote: > I am looking for an efficient Python script to download and save a .zip file > programmatically (from http or https call). You want urllib.urlretrieve(): http://docs.python.org/library/urllib.html#urllib.urlretrieve Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From googler.1.webmaster at spamgourmet.com Sat Jan 10 17:26:14 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 14:26:14 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> Message-ID: <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Thanks for the link but I don't want to do a make a python script as an applicatin, I want to embedd python into a C++ app so thats the reason why I have to compile Python. From rt8396 at gmail.com Sat Jan 10 17:27:33 2009 From: rt8396 at gmail.com (r) Date: Sat, 10 Jan 2009 14:27:33 -0800 (PST) Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <4f51f4e1-0a7b-4efd-bedb-dedb59776ad9@35g2000pry.googlegroups.com> On Jan 10, 3:05?pm, excord80 wrote: > On Jan 10, 11:45?am, r wrote: > > > We need TK 8.5's themes. This will bring Tkinter out of the dark ages > > and into the 21st Century! And improve the shine of the Python base > > distro. Python could use a good boost right now! > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? TIX is just a set of compound widgets that were not included in the base Python Tkinter distro(notebook, label entry, etc... Now, it looks like they are standard. The new 8.5 TK includes support for OS specific themes, so as to give a more native feel to TK apps, hence the 21st century analogy :) From clp2 at rebertia.com Sat Jan 10 17:32:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 14:32:24 -0800 Subject: urlopen exception In-Reply-To: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> Message-ID: <50697b2c0901101432n1ecd0fe7v4fd3d09f0feb2347@mail.gmail.com> On Sat, Jan 10, 2009 at 9:56 AM, asit wrote: > site="www.bput.org" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > according to my best knowledge, the above code is correct. > but why it throws exceptio ???? Because it's not correct. It's trying to load www.bput.org which is definitely not a valid URL. Also, you need to specify the protocol in the URL, i.e. http:// Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From kw at codebykevin.com Sat Jan 10 17:41:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 10 Jan 2009 17:41:58 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <49692436.1010306@codebykevin.com> excord80 wrote: > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? Tix is a compiled Tk extension that adds a good number of widgets to the base set, such as a notebook tab, treeview, combobox, and others; Python includes a Tix wrapper as part of the standard library. However, it has not undergone much development over the past several years, and its widgets look very outdated (they have a mid-90s feel to them). The themed Tk widgets (ttk) that come with Tk 8.5 add a lot of the same things that Tix does, but they do so in a more modern way, hooking into platform-specific themes and API's wherever possible (XP, Vista, Mac) and updating the generic X11 look as well. As such, they are more appropriate for modern development. Tix is more of a legacy toolkit. A Python wrapper for ttk can be found here: http://code.google.com/p/python-ttk/ It will be added to the standard library at some point, probably for Python 3.1. Here are some screenshots: http://code.google.com/p/python-ttk/wiki/Screenshots HTH, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sat Jan 10 17:43:42 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 10 Jan 2009 17:43:42 -0500 Subject: State of the art: Tkinter, Tk 8.5, Tix? In-Reply-To: <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> Message-ID: <4969249E.2040701@codebykevin.com> excord80 wrote: > On Jan 10, 11:45 am, r wrote: >> We need TK 8.5's themes. This will bring Tkinter out of the dark ages >> and into the 21st Century! And improve the shine of the Python base >> distro. Python could use a good boost right now! > > Could someone please explain what Tix provides compared to what the > new stuff in Tk 8.5 provides? Is there much overlap? And here are some Tix screenshots: http://tixlibrary.sourceforge.net/screenshots/index.shtml -- Kevin Walzer Code by Kevin http://www.codebykevin.com From Lie.1296 at gmail.com Sat Jan 10 18:07:55 2009 From: Lie.1296 at gmail.com (Lie) Date: Sat, 10 Jan 2009 15:07:55 -0800 (PST) Subject: type conversion References: <4b7188db-63b2-4ac5-80cb-d1326ca3694a@q26g2000prq.googlegroups.com> <613a20bf-6e5a-435e-9a83-36766e12f0ab@k8g2000yqn.googlegroups.com> <016eba68$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 3, 10:23?am, r wrote: > On Jan 2, 7:46?pm, Steven D'Aprano wrote: > > ...incessant rambling about a news reader , 101 excuses for butting > into a thread > [snip] ... public display of ignorance of newsgroup ethics, 101 excuses for not knowing proper terminologies. > Throw your newsreader in the garbage and use Google groups, less > headache, more filling! > Really? I found Google Groups lacking for many thing. Google Groups' only advantage is being browser-based. > No need to worry about > "hidden headers" And you may even get a star or 2 :) Don't you realize that even Google Groups handles those hidden headers too. And that the hidden headers aren't really hidden, even in Google Groups. > > If people are ignoring a thread, they won't even see your post even though you have changed the subject line. > > Yea NO $#Y, that makes a lot of sense, if i am ignoring something i > course i will not see it! > OK, Steven so you did not go off topic you simply high-jacked this > thread. I get it now :) "Yea NO $#Y", that doesn't make sense. Yea or NO? or $#Y? From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 18:28:09 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jan 2009 23:28:09 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <017925b8$0$8693$c3e8da3@news.astraweb.com> On Sat, 10 Jan 2009 12:52:47 -0700, Joe Strout wrote: >> What is the observable difference between converting an array to a >> reference (pointer) to that array and passing the reference by value, >> and passing the array by reference? > > The difference is whether an assignment to the formal parameter (within > the function) affects the actual parameter (in the calling code). If it > does, then that's pass by reference. If it does not, then that's pass > by value. Such a definition is incomplete. You are mischaracterising call-by- reference as defined by a single binary state: assignment either affects the caller, or it doesn't. If it does, it is p-b-r, if it doesn't, it's p- b-v. According to this definition, there are no other argument passing strategies possible. That's an enormously broad brush by which you sweep away decades of comp sci terminology. Not just Barbara Liskov and pass-by- object, but Algol's thunk-based pass-by-name and Haskell's pass-by-need. In other words, you have created a false dichotomy between pass-by- reference and pass-by-value. There are actually three fundamental characteristics of pass-by-reference: * passing a value by reference does not lead to the value being copied, in contrast with pass-by-value where it does; * modifications to the value passed by reference are visible to the caller; * assignments to the value passed by reference are visible to the caller. Pascal VAR parameters have all three characteristics. Pascal non-VAR parameters have none of them. Python parameters have two of the three. C parameters (call-by-value) have none of them, except for arrays, where they have all three, making arrays in C behave just like Pascal pass-by- reference VAR parameters. -- Steven From MrJean1 at gmail.com Sat Jan 10 18:49:20 2009 From: MrJean1 at gmail.com (MrJean1) Date: Sat, 10 Jan 2009 15:49:20 -0800 (PST) Subject: Looking for an efficient Python script to download and save a .zip file programmatically References: <324592.49250.qm@web26307.mail.ukl.yahoo.com> Message-ID: Here are some examples using urllib.urlretrieve(): /Jean Brouwers On Jan 10, 2:23?pm, Chris Rebert wrote: > On Sat, Jan 10, 2009 at 9:12 AM, David Shi wrote: > > I am looking for an efficient Python script to download and save a .zip file > > programmatically (from http or https call). > > You want urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com From Nicolas.Thiery at u-psud.fr Sat Jan 10 18:59:50 2009 From: Nicolas.Thiery at u-psud.fr (=?ISO-8859-1?Q?Nicolas_M=2E_Thi=E9ry?=) Date: Sat, 10 Jan 2009 15:59:50 -0800 (PST) Subject: Pickling classes (not class instances) Message-ID: <582b45b4-ed93-4a05-9c7b-7f72da34861d@r36g2000prf.googlegroups.com> Dear python developers, Purpose of this e-mail: ----------------------- How to customize how a class (not an instance of a class!!!) is pickled? Example: ============================================================================== class metaclass(type): def __new__(mcs, name, bases, dict): print " running metaclass.__new__" return type.__new__(mcs, name, bases, dict) # def __reduce_class__(self): print "reducing a class" # do the real work c = metaclass("foo", (object,), dict()) import copy_reg copy_reg.pickle(metaclass, metaclass.__reduce_class__) pickle.dumps(c) --------------------------------------------------------------------------- PicklingError Traceback (most recent call last) ... PicklingError: Can't pickle : it's not found as __main__.foo ============================================================================== Context: -------- I am working on the Sage project (www.sagemath.org), and more precisely on the category infrastructure. The code is building lots of classes on the fly by composing preexisting classes by inheritance (for the curious, see the doc of the class Category in http://sage.math.washington.edu:2144/file/1567cea09170/categories-nt.patch). Since those classes are built on the fly, they cannot be pickled with the default mechanism of name lookup. A proper pickling would be to rebuild the class anew. Nothing problematic, except for the question above. Discussion: ----------- It sounds like copy_reg would be the natural way to go (as in the example above). However, its documentation suggests that it explicitly is not intended for pickling classes, e.g. first paragraph of: http://docs.python.org/library/copy_reg.html#module-copy_reg is: The copy_reg module provides support for the pickle and cPickle modules. The copy module is likely to use this in the future as well. It provides configuration information about object constructors which are not classes. Such constructors may be factory functions or class instances. And indeed, looking up at the code of pickle (l. 289-299 of pickle.py) (and similarly in cpickle), the copy-reg dispatch is explicit bypassed for metaclasses: # Check for a class with a custom metaclass; treat as regular class try: issc = issubclass(t, TypeType) except TypeError: # t is not a class (old Boost; see SF #502085) issc = 0 if issc: self.save_global(obj) return # Check copy_reg.dispatch_table reduce = dispatch_table.get(t) Which causes the failure above. Is there a specific reason for this restriction? Would it be thinkable to move up the copy reg dispatch before the metaclass treatment in pickle and cPickle? I did it locally, and it fixed my problem. If not, what would be the right way to achieve this? Many thanks in advance! Best regards, Nicolas -- Nicolas M. Thi?ry "Isil" http://Nicolas.Thiery.name/ From rhodri at wildebst.demon.co.uk Sat Jan 10 20:22:48 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 11 Jan 2009 01:22:48 -0000 Subject: why cannot assign to function call In-Reply-To: <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: On Sat, 10 Jan 2009 18:44:37 -0000, wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? This is a red herring, though. From either viewpoint, C arrays are anomalous in comparison with other C data types. -- Rhodri James *-* Wildebeeste Herder to the Masses From schickb at gmail.com Sat Jan 10 20:56:14 2009 From: schickb at gmail.com (schickb) Date: Sat, 10 Jan 2009 17:56:14 -0800 (PST) Subject: Regex for unicode letter characters Message-ID: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> I need a regex that will match strings containing only unicode letter characters (not including numeric or the _ character). I was surprised to find the 're' module does not include a special character class for this already (python 2.6). Or did I miss something? It seems like this would be a very common need. Is the following the only option to generate the character class (based on an old post by Martin v. L?wis )? import unicodedata, sys def letters(): start = end = None result = [] for index in xrange(sys.maxunicode + 1): c = unichr(index) if unicodedata.category(c)[0] == 'L': if start is None: start = end = c else: end = c elif start: if start == end: result.append(start) else: result.append(start + "-" + end) start = None return u'[' + u''.join(result) + u']' Seems rather cumbersome. -Brad From rocky.bernstein at gmail.com Sat Jan 10 21:11:51 2009 From: rocky.bernstein at gmail.com (rocky) Date: Sat, 10 Jan 2009 18:11:51 -0800 (PST) Subject: import relative (with a directory) Message-ID: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Import relative? Recently for fun I've been working on a large Python program. It has many files/modules spread over several directories/submodules. Each module has some "demo" code at the end that I can use to run or experiment with that module. Of course, modules often refer to others; depending on which one, more of the code may get pulled in or not. In this situation it has been very convenient to have do "import relative" which is like import, but I get to specify where to start searching from. Of course I can set sys.path, but I find that hokey. (When I write systems administration scripts, I also generally prefer specifying a full path name to a program, e.g. /bin/mount rather than using PATH. Strikes me as the same issue here). The other thing about the Python import mechanism that sometimes gets in the way is that if there is a module imported (from the wrong place for this context), it tacitly gets used. Within such a project I want to specify when I want the code in this project, and if it can't find that, then that's a failure. I'm curious if other have the same problem and how other they deal with this? Reading "Expert Python Programming", I see that one solution is to install into a sandbox. But it strikes me as a little less agile. Just as I don't enjoy issuing compile and link commands (even if run via a Makefile), I don't want to have to issue install- into-sandbox commands. For concreteness here's the import code I've been using is: http://code.google.com/p/pyimport-relative/ It is far from perfect because I just wanted to get this done and I don't fully understand the Python modules and imp module, but for now it gets what I want done. I will probably add some ability to top- level package name to avoid collisions from other packages. However if I do this, I still will probably have the program figure out the intermediate compound names. So if I am in directory ...my-project/a/b/ c and I can say import_relative("x", "myproject") and have it import that as "myproject.a.b.c.x". That way, if files move around and get renamed I don't have to change any code. Also, I can probably store somewhere in a variable "myproject". Code that uses this can be found at http://code.google.com/p/pydbg/ Suggestions on how to improve the code are welcome; but again I don't represent that this is done that well or that I've mastered this. Oh, also meant to mention that in looking at say the knee code (which looks like a translation into Python of its C code) and the C code, a very deliberate decision was made *not* to allow filenames. So I probably am treading where others have been and have decided not to go. If folks are aware of threads, and discussions on this I'd be grateful for pointers on this discussion. Thanks. From clp2 at rebertia.com Sat Jan 10 21:27:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 10 Jan 2009 18:27:38 -0800 Subject: import relative (with a directory) In-Reply-To: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> References: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Message-ID: <50697b2c0901101827i1cfe68f5oa0e08e545ac0dbcd@mail.gmail.com> On Sat, Jan 10, 2009 at 6:11 PM, rocky wrote: > Import relative? > > Recently for fun I've been working on a large Python program. It has > many files/modules spread over several directories/submodules. > > Each module has some "demo" code at the end that I can use to run or > experiment with that module. Of course, modules often refer to others; > depending on which one, more of the code may get pulled in or not. > > In this situation it has been very convenient to have do "import > relative" which is like import, but I get to specify where to start > searching from. Of course I can set sys.path, but I find that hokey. > (When I write systems administration scripts, I also generally prefer > specifying a full path name to a program, e.g. /bin/mount rather than > using PATH. Strikes me as the same issue here). > > The other thing about the Python import mechanism that sometimes gets > in the way is that if there is a module imported (from the wrong place > for this context), it tacitly gets used. Within such a project I want > to specify when I want the code in this project, and if it can't find > that, then that's a failure. > > I'm curious if other have the same problem and how other they deal > with this? Reading "Expert Python Programming", I see that one > solution is to install into a sandbox. But it strikes me as a little > less agile. Just as I don't enjoy issuing compile and link commands > (even if run via a Makefile), I don't want to have to issue install- > into-sandbox commands. > > For concreteness here's the import code I've been using is: > http://code.google.com/p/pyimport-relative/ > > It is far from perfect because I just wanted to get this done and I > don't fully understand the Python modules and imp module, but for now > it gets what I want done. I will probably add some ability to top- > level package name to avoid collisions from other packages. However if > I do this, I still will probably have the program figure out the > intermediate compound names. So if I am in directory ...my-project/a/b/ > c and I can say import_relative("x", "myproject") and have it import > that as "myproject.a.b.c.x". That way, if files move around and get > renamed I don't have to change any code. Also, I can probably store > somewhere in a variable "myproject". You should probably check out the relative import syntax introduced in PEP 328: http://www.python.org/dev/peps/pep-0328/ It should be able to do exactly what you want. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From google at mrabarnett.plus.com Sat Jan 10 21:33:26 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 02:33:26 +0000 Subject: Regex for unicode letter characters In-Reply-To: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> Message-ID: <49695A76.9060306@mrabarnett.plus.com> schickb wrote: > I need a regex that will match strings containing only unicode letter > characters (not including numeric or the _ character). I was surprised > to find the 're' module does not include a special character class for > this already (python 2.6). Or did I miss something? > > It seems like this would be a very common need. Is the following the > only option to generate the character class (based on an old post by > Martin v. L?wis )? > [snip] Basically, yes. The re module was last worked on in 2003 (remember it's all voluntary!). Such omissions should be addressed in Python 2.7. From googler.1.webmaster at spamgourmet.com Sat Jan 10 21:41:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 10 Jan 2009 18:41:01 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <0bf35b53-d672-4557-adb8-7fa764288525@o4g2000pra.googlegroups.com> hmm.. very strange. Is it so complicated to compile python that I can move the framework to the app folder? hmm. thats really strange :-( /myapp.app /subfolder/Python.framework any suggestions? Thank you very muc. From mdw at distorted.org.uk Sat Jan 10 21:41:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 02:41:17 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <017925b8$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There are actually three fundamental characteristics of pass-by-reference: > > * passing a value by reference does not lead to the value being copied, > in contrast with pass-by-value where it does; > > * modifications to the value passed by reference are visible to the > caller; > > * assignments to the value passed by reference are visible to the > caller. I've given an extensive definition of pass-by-reference. Distilling and paraphrasing, the main characteristic is that (where possible) new variables are not created: rather, the parameter names are bound to the caller's variables. All three of your above characteristics are consequences of this one. But your definition is also flawed: it doesn't distinguish pass-by- reference from pass-by-value/return (where the caller's variable is updated from the function parameter's final value when the function returns). The difference is detectable if you use global variables, however: variable g = 1 function foo(x): x = 2 print g foo(g) print g prints 1 and 1 if you use pass-by-value, 2 and 2 if you use pass-by- reference, and 1 and 2 if you use pass-by-value/result. (Within the framework I presented elsewhere, pass-by-value/result is like pass-by-value, except that we update: s'''' = s'''[s'''(e''(n))/l] where s''' is the store just prior to the return, s'''' is the store just after the return, n is the parameter name, e'' is the function's environment, and l is the location designated by the argument expression, i.e., (l, s') = loc(x, e, s). If there is no such location, then the language may either fail to compile the call, or omit the update operation.) > Pascal VAR parameters have all three characteristics. That's because they work as I've suggested. > Pascal non-VAR parameters have none of them. Indeed. > Python parameters have two of the three. C parameters (call-by-value) > have none of them, except for arrays, where they have all three, > making arrays in C behave just like Pascal pass-by- reference VAR > parameters. Rubbish. In C: void foo(char v[42]) { v = 0; } Calling this function has no effect on the caller whatsoever. I've already explained C arrays, with reference to the ISO standard, exhaustively: there should be no excuse for continued misunderstanding of this point. -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Jan 10 21:48:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 02:48:12 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <0179549a$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 01:22:48 +0000, Rhodri James wrote: > On Sat, 10 Jan 2009 18:44:37 -0000, wrote: > >> What is the observable difference between converting an array to a >> reference (pointer) to that array and passing the reference by value, >> and passing the array by reference? > > This is a red herring, though. From either viewpoint, C arrays are > anomalous in comparison with other C data types. I don't believe it is a red-herring. As I understand it, Mark and Joe insist that C is pass-by-value *even in the case of arrays*, despite the semantics of array passing being identical to the semantics of pass-by- reference in (say) Pascal. While Mark is willing to admit that arrays are "bizarre" (his term) in C, I don't think he accepts that passing arrays in C is anything but pass-by-value. I think this gets very close to the bone of the debate. It demonstrates that "pass-by-value" as Mark and Joe understand it is such a broad concept that it can describe any argument passing behaviour at all and therefore is meaningless. -- Steven From steve at holdenweb.com Sat Jan 10 21:49:26 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 21:49:26 -0500 Subject: urlopen exception In-Reply-To: <7xbpuesxjf.fsf@ruckus.brouhaha.com> References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > asit writes: >> site="www.bput.org" >> payloads="" >> attack= urllib2.urlopen(site+payloads,80).readlines() >> >> according to my best knowledge, the above code is correct. >> but why it throws exceptio ???? > > The code is incorrect. Look at the string ou are sending into > urlopen. What on earth are you trying to do? He's investigating potential cross-site scripting vulnerabilities. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gdamjan at gmail.com Sat Jan 10 21:57:12 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 11 Jan 2009 03:57:12 +0100 Subject: State of the art: Tkinter, Tk 8.5, Tix? References: <92b2eac4-df64-451c-a8df-535405fb6883@r37g2000prr.googlegroups.com> <790c5b33-ac72-410e-8af0-a5e86b8f0305@k36g2000yqe.googlegroups.com> <49692436.1010306@codebykevin.com> Message-ID: <8p3o36-j8t.ln1@archaeopteryx.softver.org.mk> > The themed Tk widgets (ttk) that come with Tk 8.5 add a lot of the > same things that Tix does, but they do so in a more modern way, > hooking into platform-specific themes and API's wherever possible (XP, > Vista, Mac) and updating the generic X11 look as well. As such, they > are more appropriate for modern development. Tix is more of a legacy > toolkit. Interesting... so to summarize, what do I get from Python/TK on *Linux* with tkinter beeing dynamically linked to the system tk 8.5.6 ? Especially I'd like to know if it will support fontconfig/TTF/antialiased fonts? -- ?????? ( http://softver.org.mk/damjan/ ) When you do things right, people won't be sure if you did anything at all. From steve at holdenweb.com Sat Jan 10 22:03:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 10 Jan 2009 22:03:38 -0500 Subject: Regex for unicode letter characters In-Reply-To: <49695A76.9060306@mrabarnett.plus.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> Message-ID: MRAB wrote: > schickb wrote: >> I need a regex that will match strings containing only unicode letter >> characters (not including numeric or the _ character). I was surprised >> to find the 're' module does not include a special character class for >> this already (python 2.6). Or did I miss something? >> >> It seems like this would be a very common need. Is the following the >> only option to generate the character class (based on an old post by >> Martin v. L?wis )? >> > [snip] > Basically, yes. > > The re module was last worked on in 2003 (remember it's all voluntary!). > Such omissions should be addressed in Python 2.7. By "should be" do you mean "ought to be (but I have no intention of helping)", "are expected to be (but someone else will be doing the work", "it's on my list and I am expecting to get finished in time for 2.7 integration" or something else? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mdw at distorted.org.uk Sat Jan 10 22:25:24 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 03:25:24 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I don't believe it is a red-herring. As I understand it, Mark and Joe > insist that C is pass-by-value *even in the case of arrays*, despite the > semantics of array passing being identical to the semantics of pass-by- > reference in (say) Pascal. But they aren't. I've provided several examples to show this. Most tellingly, the parameter types are different in the two cases. > While Mark is willing to admit that arrays are "bizarre" (his term) in > C, I don't think he accepts that passing arrays in C is anything but > pass-by-value. For the purpose of clearing this up once and for all: arrays, in C, are `don't-pass-at-all'. There is no way -- none whatever -- of declaring a function parameter as having array type. Furthermore, if (say) an argument expression consists only of an identifier bound to an object of array type, the resulting argument expression has pointer type, and is fully evaluated prior to the sequence point before the function call. I provided chapter and verse elsewhere, and I'm getting rather fed up of repeating myself. Certainly a dissenting opinion should include references to at least a (specific) draft of the ISO C standard. > I think this gets very close to the bone of the debate. It demonstrates > that "pass-by-value" as Mark and Joe understand it is such a broad > concept that it can describe any argument passing behaviour at all and > therefore is meaningless. I've proven (not quite rigorously, but sketched a proof, and provided definitions which are now sufficiently formal that you can fill in the details) that my definition of pass-by-value excludes certain behaviours. But, most significantly, you cannot implement `swap' given only pass-by-value. -- [mdw], wondering whether Hanlon's razor is getting blunt. From google at mrabarnett.plus.com Sat Jan 10 22:38:13 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 03:38:13 +0000 Subject: Regex for unicode letter characters In-Reply-To: References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> Message-ID: <496969A5.4090601@mrabarnett.plus.com> Steve Holden wrote: > MRAB wrote: >> schickb wrote: >>> I need a regex that will match strings containing only unicode letter >>> characters (not including numeric or the _ character). I was surprised >>> to find the 're' module does not include a special character class for >>> this already (python 2.6). Or did I miss something? >>> >>> It seems like this would be a very common need. Is the following the >>> only option to generate the character class (based on an old post by >>> Martin v. L?wis )? >>> >> [snip] >> Basically, yes. >> >> The re module was last worked on in 2003 (remember it's all voluntary!). >> Such omissions should be addressed in Python 2.7. > > By "should be" do you mean "ought to be (but I have no intention of > helping)", "are expected to be (but someone else will be doing the > work", "it's on my list and I am expecting to get finished in time for > 2.7 integration" or something else? > The third one. From rurpy at yahoo.com Sat Jan 10 22:59:13 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 10 Jan 2009 19:59:13 -0800 (PST) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> Message-ID: <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Mark Wooding wrote: > rurpy at yahoo.com wrote: > >> What is the observable difference between converting an >> array to a reference (pointer) to that array and passing >> the reference by value, and passing the array by reference? > > For one: > > #include > static size_t foo(char v[]) { return sizeof v; } > int main(void) { > char v[sizeof(char *) * 10]; > puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); > return (0); > } You are saying that because the size of the argument (10) is not available in the function, it cannot be call-by-reference? I think fortran is accepted as the archetypal call-by- reference language and it does not automatically supply argument size information to functions. In fortran, if the size of the argument is known at compile time, the programmer explicitly declares the parameter with the same size in the function. integer k(3) call mysub (k) write (unit=*, fmt=*) k(1),k(2),k(3) end subroutine mysub (x) integer x(3) do 100, i=1,3 100 x(i) = i return end If not, he passes the size explicitly as an argument: integer k(3) call mysub (k, 3) write (unit=*, fmt=*) k(1),k(2),k(3) end subroutine mysub(x, n) integer x(0) do 100, i=1,3 100 x(i) = i return end Obviously both these idioms translate directly into C. Here is the second: #include void mysub (int k[], int n) { int i; for (i=0; i<3; i++) { k[i] = i; } return; } main() { int k[3]; mysub (k, 3); printf ("%i,%i,%i\n", k[0],k[1],k[2]); } So if fortran can be call-by-reference without the compiler passing size information, I don't see why the above C code can't be as well. > For another: > > static void bar(char v[]) { char ch = 0; v = &ch; } > /* type error if arrays truly passed by reference */ v can be used as an array reference, e.g. "v[1] = 23" exactly as in the pass-by-reference fortran example. And v can also be used as a local variable and reassigned. If the first option was the only one, would you not say C was definitely pass-by-reference (for arrays)? If one could only use v as a pointer (i.e. access the argument array as "*(v+1) = 23", then I would say that arrays are not passed at all, only pointers by-value. That both these options exist causes me to conclude that, for arrays, parameter passing can be viewed as either arrays by-reference or pointers by-value. I don't understand what relevance type checking has. Since you are choosing to use v as a pointer, one would not expect a type error, yes? >> I guess the case for pass-by-value would be a little stronger because >> one has to have "passing a pointer by value" anyway (since pointers >> are first-class datatypes) and that can be used to describe passing >> arrays (as you described). > > The difference is that the /callee/ function is different between the > two cases. > > Also, notice that arrays in expressions turn into pointers in the same > way, so function argument passing works the same way as assignment -- a > hallmark of pass-by-value. Not in all expressions as you yourself mentioned: int a[10], *ap; sizeof a; sizeof ap; From musiccomposition at gmail.com Sat Jan 10 23:09:31 2009 From: musiccomposition at gmail.com (Benjamin) Date: Sat, 10 Jan 2009 20:09:31 -0800 (PST) Subject: "python -3" not working as expected References: <6smnqfF71c2fU1@mid.uni-berlin.de> <7fb51141-4920-4cea-80b0-93c23a4f3fee@o40g2000prn.googlegroups.com> <470b7664-2752-4368-b08d-9b43f9bfad70@i18g2000prf.googlegroups.com> <40fdc5f4-42e5-4e4d-9545-54faf3b5fa9b@p36g2000prp.googlegroups.com> Message-ID: <4da72a7f-29f1-4121-a168-7e6fe54a9575@s1g2000prg.googlegroups.com> On Jan 9, 10:19?pm, John Machin wrote: > On Jan 10, 2:55?pm, Benjamin wrote: > > > We'll need good documentation. Unfortunately, as you > > note below, this isn't exactly the case yet. > > So is there a plot to remedy this? Where do we sign up? Feel free to contribute to the wiki page: http://wiki.python.org/moin/PortingToPy3k From koranthala at gmail.com Sat Jan 10 23:18:53 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 10 Jan 2009 20:18:53 -0800 (PST) Subject: Python strings and coding conventions Message-ID: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Hi, Python Coding Convention (PEP 8) suggests : Maximum Line Length Limit all lines to a maximum of 79 characters. I have a string which is ~110 char long. It is a string which I am going to print in a text file as a single string. i.e. in that text file, each line is taken as a different record - so it has to be in a single line. Now, how can I write this code - while following PEP 8? I tried blockstrings, but as shown in the example below: >>> s = r''' ... abcd ... efgh ... ''' >>> s '\nabcd\nefgh\n' it has "\n" inserted - which will disallow printing it to a single line. I thought about other options like concatenating strings etc, but it seems very kludgy - esp since the whole string has a single meaning and cannot be easily split to many logically. Then I thought of creating a blockstring and then removing "\n", but it seemed kludgier... I am sure this is a very usual issue and I am missing some very very simple solution. But I cannot think of it at all... From robert.kern at gmail.com Sat Jan 10 23:26:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 10 Jan 2009 22:26:46 -0600 Subject: Python strings and coding conventions In-Reply-To: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: koranthala at gmail.com wrote: > Hi, > Python Coding Convention (PEP 8) suggests : > Maximum Line Length > > Limit all lines to a maximum of 79 characters. > > I have a string which is ~110 char long. It is a string which I am > going to print in a text file as a single string. > i.e. in that text file, each line is taken as a different record - > so it has to be in a single line. > > Now, how can I write this code - while following PEP 8? > I tried blockstrings, but as shown in the example below: >>>> s = r''' > ... abcd > ... efgh > ... ''' >>>> s > '\nabcd\nefgh\n' > it has "\n" inserted - which will disallow printing it to a single > line. > > I thought about other options like concatenating strings etc, but > it seems very kludgy - esp since the whole string has a single meaning > and cannot be easily split to many logically. Then I thought of > creating a blockstring and then removing "\n", but it seemed > kludgier... I usually use implicit concatenation: s = ('some long text that ' 'needs to be split') -- 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 mensanator at aol.com Sat Jan 10 23:48:21 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 10 Jan 2009 20:48:21 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: On Jan 10, 10:26?pm, Robert Kern wrote: > koranth... at gmail.com wrote: > > Hi, > > ? ?Python Coding Convention (PEP 8) suggests : > > ? Maximum Line Length > > > ? ? Limit all lines to a maximum of 79 characters. > > > ? I have a string which is ~110 char long. It is a string which I am > > going to print in a text file as a single string. > > ? i.e. in that text file, each line is taken as a different record - > > so it has to be in a single line. > > > ? Now, how can I write this code - while following PEP 8? > > ? I tried blockstrings, but as shown in the example below: > >>>> s = r''' > > ... abcd > > ... efgh > > ... ''' > >>>> s > > '\nabcd\nefgh\n' > > ? ?it has "\n" inserted - which will disallow printing it to a single > > line. > > > ? ?I thought about other options like concatenating strings etc, but > > it seems very kludgy - esp since the whole string has a single meaning > > and cannot be easily split to many logically. Then I thought of > > creating a blockstring and then removing "\n", but it seemed > > kludgier... > > I usually use implicit concatenation: > > s = ('some long text that ' > ? ? ? 'needs to be split') Damn! I didn't know you could do that! And if I saw it in a program listing, such would never occur to me. I was going to suggest the stupid way: >>> ga = ['four score and seven years ago ', \ 'our fathers brought forth ', \ 'on this continent a new nation ', \ 'conceived in liberty and dedicated ', \ 'to the proposition that all men ', \ 'are created equal'] >>> ''.join(ga) 'four score and seven years ago our fathers brought forth on this continent a new nation conceived in liberty and dedicated to the proposition that all men are created equal' > > -- > 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- Hide quoted text - > > - Show quoted text - From kay.schluehr at gmx.net Sun Jan 11 00:32:34 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 10 Jan 2009 21:32:34 -0800 (PST) Subject: import relative (with a directory) References: <0fdae084-a450-4c1c-a744-24e7f8a31a4f@h5g2000yqh.googlegroups.com> Message-ID: On 11 Jan., 03:27, Chris Rebert wrote: > You should probably check out the relative import syntax introduced in > PEP 328:http://www.python.org/dev/peps/pep-0328/ > It should be able to do exactly what you want. This should exactly lead to exceptions in all of his demo code because the modules are not "scripts" anymore but "modules in a package" - a semantical difference I wasn't even aware of until relative imports were introduced in Python 2.5. I'd rather avoid the sour grapes and use absolute imports. Kay From torriem at gmail.com Sun Jan 11 00:49:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 10 Jan 2009 22:49:57 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <49698885.1090700@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > Thanks for the link but I don't want to do a make a python script as > an applicatin, I want to embedd python into a C++ app so thats the > reason why I have to compile Python. If you are embedding python, then all you have to do is stick the python modules you need in somewhere in the resources folder, along with the dynamic link library that you built. Then you fix up your executable to be able to find the dynamic link library (been a while since I made app bundles in general... followed the Qt docs if I recall). When your app goes to initialize python, just use python api calls to set the python path that it will use to find the import modules. You should be able to programmatically determine this (see apple docs I guess). In short, you can do it all with the python C api, programmatically in your exe, once you've taken care of the initial link against the python dynlib. From aleksandr.goretoy at gmail.com Sun Jan 11 00:58:55 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 11 Jan 2009 05:58:55 +0000 Subject: urlopen exception In-Reply-To: References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: I would try: site="http://www.bput.org/" payloads="" attack= urllib2.urlopen(site+payloads,80).readlines() -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden wrote: > Paul Rubin wrote: > > asit writes: > >> site="www.bput.org" > >> payloads="" > >> attack= urllib2.urlopen(site+payloads,80).readlines() > >> > >> according to my best knowledge, the above code is correct. > >> but why it throws exceptio ???? > > > > The code is incorrect. Look at the string ou are sending into > > urlopen. What on earth are you trying to do? > > He's investigating potential cross-site scripting vulnerabilities. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Sun Jan 11 01:04:03 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 11 Jan 2009 06:04:03 +0000 Subject: urlopen exception In-Reply-To: References: <76df0cac-bacb-4144-8def-f38b98bac1ef@a12g2000pro.googlegroups.com> <7xbpuesxjf.fsf@ruckus.brouhaha.com> Message-ID: oops, remove the ,80 since port is not needed. Well, in my case it wasn't working with port. notice it gives me 404, but this with my domain >>> att=urllib2.urlopen(site+payload,80).readlines() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/local/lib/python2.6/urllib2.py", line 381, in open req = meth(req) File "/usr/local/lib/python2.6/urllib2.py", line 1057, in do_request_ 'Content-length', '%d' % len(data)) TypeError: object of type 'int' has no len() >>> att=urllib2.urlopen(site+payload).readlines() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/local/lib/python2.6/urllib2.py", line 389, in open response = meth(req, response) File "/usr/local/lib/python2.6/urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs) File "/usr/local/lib/python2.6/urllib2.py", line 427, in error return self._call_chain(*args) File "/usr/local/lib/python2.6/urllib2.py", line 361, in _call_chain result = func(*args) File "/usr/local/lib/python2.6/urllib2.py", line 510, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Sun, Jan 11, 2009 at 5:58 AM, alex goretoy wrote: > I would try: > > site="http://www.bput.org/" > payloads="" > attack= urllib2.urlopen(site+payloads,80).readlines() > > > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > > > > On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden wrote: > >> Paul Rubin wrote: >> > asit writes: >> >> site="www.bput.org" >> >> payloads="" >> >> attack= urllib2.urlopen(site+payloads,80).readlines() >> >> >> >> according to my best knowledge, the above code is correct. >> >> but why it throws exceptio ???? >> > >> > The code is incorrect. Look at the string ou are sending into >> > urlopen. What on earth are you trying to do? >> >> He's investigating potential cross-site scripting vulnerabilities. >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bedouglas at earthlink.net Sun Jan 11 01:58:23 2009 From: bedouglas at earthlink.net (bruce) Date: Sat, 10 Jan 2009 22:58:23 -0800 Subject: parsing javascript generated files... Message-ID: <098401c973b9$ffbf9760$0301a8c0@tmesa.com> Hi. Looking to parse some web pages that have javascript (jquery) embedded/used in the pages. I'm trying to get a better understanding of exactly how the page is generated, and displayed in the browser. I've seen various references to python-spidermonkey, as well as watir/firewatir. Is there a way to accomplish fetching text from javascript generated pages? It appears that the ability to "call" firefox using "jssh" could allow me to return the complete page of the displayed app. I'm not sure if this is pythonic!! I suspect that I would have to somehow invoke the page, using firefox/jssh, (or spidermonkey) or some other javascript engine, and then somehow invoke the javascript function, that would fill in the 'div' within the page... Is this even doable??? It would be great if there was someway of calling an external browser/app that one could pass the targeted url, and get back the resulting html that's displayed by the browser!! A target site is http:://web-app.usc.edu/soc/term_20091.html where the 'dept' list is completely generated by javascript functions... When i researched this awhile ago, there didn't appear to be a really good solution to this situation. I'm curious if someone knows of a solution to this issue that's now available and that works! Thanks for any thoughts/comments in this issue... -bruce From koranthala at gmail.com Sun Jan 11 02:17:59 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Sat, 10 Jan 2009 23:17:59 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> On Jan 11, 9:26?am, Robert Kern wrote: > koranth... at gmail.com wrote: > > Hi, > > ? ?Python Coding Convention (PEP 8) suggests : > > ? Maximum Line Length > > > ? ? Limit all lines to a maximum of 79 characters. > > > ? I have a string which is ~110 char long. It is a string which I am > > going to print in a text file as a single string. > > ? i.e. in that text file, each line is taken as a different record - > > so it has to be in a single line. > > > ? Now, how can I write this code - while following PEP 8? > > ? I tried blockstrings, but as shown in the example below: > >>>> s = r''' > > ... abcd > > ... efgh > > ... ''' > >>>> s > > '\nabcd\nefgh\n' > > ? ?it has "\n" inserted - which will disallow printing it to a single > > line. > > > ? ?I thought about other options like concatenating strings etc, but > > it seems very kludgy - esp since the whole string has a single meaning > > and cannot be easily split to many logically. Then I thought of > > creating a blockstring and then removing "\n", but it seemed > > kludgier... > > I usually use implicit concatenation: > > s = ('some long text that ' > ? ? ? 'needs to be split') > > -- > 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 This is a very good method. I found another method too - on further investigation >>> s = "abc\ ... efg" >>> s 'abcefg' Only problem being that it doesnt support indentation. So, implicit concatenation it is... From matrixhasu at gmail.com Sun Jan 11 03:54:25 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 00:54:25 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: <32ed6add-2266-498d-b9a9-96b6b426dc15@g1g2000pra.googlegroups.com> Message-ID: Hello Marco, thanks for your reply (and sorry for my late one) On Jan 6, 9:26?am, Marco Nawijn wrote: > On Jan 5, 10:57?am, Sandro Tosi wrote: > I am happy to hear that there might be a book on Matplotlib. I am > using Matplotlib for a while now and find it a very usefull and > powerfull library for generating graphs. I will try to answer some of > your questions. I am by no means an expert in the field, so I only > express my personal experience. And that's fine, because the audience of the book is people that have never seen matplotlib and wanted to learn it. > >> What are you using matplotlib for? I currently use Matplotlib to generate a series of graphs that visualise data channels (strain measurements) during a structural test. These graphs need to be refreshed about every 4 seconds. Each of the graphs contains 1 to 6 curves. Just out of curiosity: how do you refresh those plots? in a loop closing/opening the figure or clear the figure and replot on it? are those graphs embedded in an application or are just "shown on screen"? > >> What are the things you like the most of matplotlib, that you want > > to give emphasis to? And why? In general I like the most the fact that > I can generate high quality publication ready graphs with a consistent > look with minimal effort. Indeed, that's one of the reason for its use in so many scientific environments. > Further, although the matlab-style commands > are very usefull I think the class interface is more powerfull. The > class interface also has a steeper learning curve. So, for me it would > be very interesting if much emphasis will be on the class interface. Yes, we will show the "class" interface during the examples, while showing the difference just for the sake of completeness. > >> What are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? I > seriously hope the book is not for "dummies", as already said, this bug is intended to people that knows nothing about mpl, so an introductory part will begin the book. > but provides at least a > significant amount of information on more advanced features of > Matplotlib. and we will try to show as much features as possible, even the advanced one. > I think the currently available tutorials are sufficient > to getting started. From my point of view I am very interested in: > ? ? - Dynamically updating a series of graphs > ? ? - Configuring layout of graphs (colors, labels, legends, etc.) > ? ? - Managing dimensions of the figure when you export the figure to > e.g PNG. For me this is interesting in the sense that if I insert a > figure in a report/paper, I would like that the fonts used in the > graph remain proportional to the surrounding text. Those will be surely in the book :) > If you need more information please let me know. Well, whatever comes to mind, please let me know :) > I wish you good luck! Cheers, Sandro From dotancohen at gmail.com Sun Jan 11 04:02:59 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 11 Jan 2009 11:02:59 +0200 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: References: Message-ID: <880dece00901110102i32f7ca85jaf9ded3d49e09701@mail.gmail.com> 2009/1/5 Sandro Tosi : > Hello and Happy 2009! > > I received the interesting proposal to author a book on Matplotlib, > the powerful 2D plotting library for Python. > > While preparing the arguments list, I'd like to hear even your > opinion, because different points-of-view will lead to a better > product. > > Some basic question I'd like to ask are: > > - what are you using matplotlib for? > - what are the things you like the most of matplotlib, that you want > to give emphasis to? And why? > - what are the (basic) things that, when you were beginning to use > matplotlib, you wanted to see grouped up but couldn't find? > - what would you like to see in a book about matplotlib? > - what are some those advanced feature that made you yell "WOW!!" ? > - what are the things you'd like to explore of matplotlib and never > had time to do? > > Your suggestions are really appreciated :) And wish me good luck! I wish you good luck! I would suggest at least a chapter on _acquiring_ the data that is to be plotted using Python to scrape different sources _not_designed_ to be scraped. Online webpages come to mind. An example on retrieving, for instance, the prices of varying currencies, parsing the HTML pages, extracting the data, and then plotting it would be a great example for a real worlds usage that show matplotlib as a tool in a toolchain, not a means to an end. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From matrixhasu at gmail.com Sun Jan 11 04:42:53 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 01:42:53 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <91eb0601-225d-4416-8b8d-af86f07c271b@n10g2000vbl.googlegroups.com> Hi James, thanks for getting back to me. On Jan 6, 9:33?am, James Stroud wrote: > Sandro Tosi wrote: > > - what are the things you like the most of matplotlib, that you want > > to give emphasis to? And why? > > The ability to embed a figure (composed of subplots) into a custom > window is my favorite aspect. Do you mean embed the figure in an application or simply a figure with several subplots in it? > Also: massive configurability of plots, > event driven plot canvas, antigrain geometry antialiasing are also all > very important. Additionally the toolbar of standard interactive > functions and the ability to export plots in a variety of formats are > also invaluable features. > > > - what are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? > > The documentation for basic plot configuration, especially for embedded > plots, and also tapping into the event model is very weak currently. > These need the most improvement. What do you mean by "event model"? > > - what would you like to see in a book about matplotlib? > > A big, huge, gigantic, chapter---no make that 3 chapters--on programming > ? interactivity with the plot canvas. Big chapters a harder to read. And what exactly do you mean by "interactivity"? > > Your suggestions are really appreciated :) And wish me good luck! > > Good luck! I can't wait to read your book! Thanks! Sandro From bj_666 at gmx.net Sun Jan 11 04:56:02 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 11 Jan 2009 09:56:02 GMT Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <6stu1iF813rdU1@mid.uni-berlin.de> On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote: > Damn! I didn't know you could do that! And if I saw it in a program > listing, such would never occur to me. I was going to suggest the stupid > way: > >>>> ga = ['four score and seven years ago ', \ > 'our fathers brought forth ', \ > 'on this continent a new nation ', \ > 'conceived in liberty and dedicated ', \ > 'to the proposition that all men ', \ > 'are created equal'] What are all those line continuation characters ('\') for? You are aware that they are unnecessary here? Ciao, Marc 'BlackJack' Rintsch From Ron.Barak at lsi.com Sun Jan 11 05:12:27 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 11 Jan 2009 10:12:27 +0000 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Hi Mark, I googled a bit, and found http://bugs.python.org/issue1355023. It seems that this patch implemented fuller seek() for GzipFile around November 2006 (including whence==2). Do I misunderstand and this patch was not actually implemented, namely, is seek(-n,2) not implemented in Python 2.5.2 ? The source of gzip.py on my system seems to suggest that negative seeks are supported: def seek(self, offset): if self.mode == WRITE: if offset < self.offset: raise IOError('Negative seek in write mode') count = offset - self.offset for i in range(count // 1024): self.write(1024 * '\0') self.write((count % 1024) * '\0') elif self.mode == READ: if offset < self.offset: # for negative seek, rewind and do positive seek self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) Could any who're familiar with the inner working of gzip settle this issue ? Is seek from EOF supported for gzip files ? Thanks, Ron. P.S.: as you guessed, my python 2.5.2 gives the not very helpful error: Traceback (most recent call last): File "./_LogStream.py", line 53, in log_stream.last_line_loc_and_contents() File "./_LogStream.py", line 20, in last_line_loc_and_contents self.input_file.seek(-1, 2) # grab the last character TypeError: seek() takes exactly 2 arguments (3 given) -----Original Message----- From: Mark Tolonen [mailto:metolone+gmane at gmail.com] Sent: Thursday, January 08, 2009 17:16 To: python-list at python.org Subject: Re: Nubie question: how to not pass "self" in call to seek() function ? "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494BA6 at enbmail01.lsi.com... > Hi, > > I am getting the error TypeError: seek() takes exactly 2 arguments (3 > given), namely: > > $ ./_LogStream.py > Traceback (most recent call last): > File "./_LogStream.py", line 47, in > log_stream.last_line_loc_and_contents() > File "./_LogStream.py", line 20, in last_line_loc_and_contents > self.input_file.seek(-1, 2) # grab the last character > TypeError: seek() takes exactly 2 arguments (3 given) > > When I run the below code. > > I understand that the extra argument is the "self", but I don't know > how to change my class to make the seek(-1,2) work. > > Could you help ? Perhaps the extra agrument is 2. You don't mention your Python version, but in Python 2.6.1 gzip files don't support seeking from the end. An older (your?) version of Python may not be providing as helpful an error message. >>> f=gzip.GzipFile('blah.gz','r') >>> f.seek(-1,2) Traceback (most recent call last): File "", line 1, in File "C:\dev\python\lib\gzip.py", line 368, in seek raise ValueError('Seek from end not supported') ValueError: Seek from end not supported -Mark > > Thanks, > Ron. > > $ cat _LogStream.py > #!/usr/bin/env python > > import gzip > import sys > > from Debug import _line as line > > class LogStream(): > > def __init__(self, filename): > self.filename = filename > self.input_file = self.open_file(filename) > self.index_increment = 10 > self.last_line_offset = -1 > > def last_line_loc_and_contents(self, estimated_line_size=1024): > > assert estimated_line_size > 0 > file_size = len(self.input_file.read()) > self.input_file.seek(-1, 2) # grab the last character > > if self.input_file.read(1) == '\n': # a "proper" text file > file_size -= 1 > > def open_file(self, in_file): > """ > The gzip module checks if the input file is a gzipped file, > only at the read stage. > This is why the f.readline() is needed. > """ > try: > f = gzip.GzipFile(in_file, "r") > f.readline() > except IOError: > f = open(in_file, "r") > f.readline() > > f.seek(0) > return(f) > > > if __name__ == "__main__": > filename = > "../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz" > log_stream = LogStream(filename) > log_stream.limit_ = 1000 > log_stream.index_increment = 12 > > log_stream.last_line_loc_and_contents() -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matrixhasu at gmail.com Sun Jan 11 05:14:30 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 02:14:30 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: <6sk2h5F6h203U1@mid.individual.net> Message-ID: <36df237b-6b86-47ae-8cfd-6f03356380da@x16g2000prn.googlegroups.com> Hello Thomas, thanks for your reply. On Jan 7, 5:11?pm, Thomas Guettler wrote: > Sandro Tosi schrieb: > > - what are you using matplotlib for? > > I use the API to create PNGs from data stored in postgres. Webframework: Django. Nice, I plan to make some examples of web embedding of mpl, and one of the frameworks is Django. > > - what are the (basic) things that, when you were beginning to use > > matplotlib, you wanted to see grouped up but couldn't find? > > The API is not good documented. It was very hard for me to understand > what was going on the source. > > > - what would you like to see in a book about matplotlib? > > How to use the API. Of course we will follow a gradual path, introducing simple apis and then going deeper in the advanced features. So, if you mean API as "pyplot.figure()" and so, they'll be covered :) Thanks, Sandro From matrixhasu at gmail.com Sun Jan 11 05:17:13 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 02:17:13 -0800 (PST) Subject: What would you like to see in a book about Matplotlib? References: Message-ID: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> Hi Dotan, On Jan 11, 10:02?am, "Dotan Cohen" wrote: > 2009/1/5 Sandro Tosi : > > Your suggestions are really appreciated :) And wish me good luck! > > I wish you good luck! Thanks you :) > I would suggest at least a chapter on _acquiring_ the data that is to > be plotted using Python to scrape different sources _not_designed_ to > be scraped. Online webpages come to mind. An example on retrieving, > for instance, the prices of varying currencies, parsing the HTML > pages, extracting the data, and then plotting it would be a great > example for a real worlds usage that show matplotlib as a tool in a > toolchain, not a means to an end. Well, a whole chapter to this is a little too much, but such examples will be presented in the book: we're not going to teach how to program in Python, but how to use matplotlib, so the data retriving is a little out-of-scope (or at least border-line), so the code will be in the examples provided along with the book, but not deeply explained in the book text. Thanks, Sandro From ihatespam at hotmail.com Sun Jan 11 05:18:22 2009 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Sun, 11 Jan 2009 05:18:22 -0500 Subject: Bad hack fix around a bizarre problem... Message-ID: I'm trying to write a Python program that manipulates a MySQL database and have chosen to use MySQLdb. So, I used by system's package manager, YUM, and it appeared to install correctly. So, I tried it out and got this error: Traceback (most recent call last): File "", line 1, in ? File "MySQLdb/__init__.py", line 22, in ? raise ImportError, "this is MySQLdb version %s, but _mysql is version %r" %\ ImportError: this is MySQLdb version (1, 2, 2, 'final', 0), but _mysql is version (1, 2, 1, 'final', 1) It looks like the MySQLdb version doesn't match the _mysql version. If these were two different libraries, I might understand how this error happened. However, they're part of the same library. _mysql is just a Python binding to the MySQL C API and MySQLdb is just a Python wrapper around _mysql to be compliant with the Python DB specification. They were both part of the same library so how did their versions fall out of sync? That's like getting a Windows application with incompatible DLLs! So, my bad hack of a fix is to copy the MySQLdb python code to a local directory (where my python program will eventually reside) and, on this local copy, comment out the version check. The idea is that MySQLdb is pure Python, so it's unlikely that there is any incompatibility between it and the very thin layer that is _mysql. The local copy is so I don't forget that I'm using a modified version of this library. Python seems to import this over the global one. I've done a bit of testing and, so far, it appears to work! What is my problem? A google search reveals that I'm not the only person with this problem but it also reveals that absolutely no one knows how to fix this. What are the chances that my fix will backfire? Thank you... From bignose+hates-spam at benfinney.id.au Sun Jan 11 05:22:54 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 11 Jan 2009 21:22:54 +1100 Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: <87ab9yf8g1.fsf@benfinney.id.au> Robert Kern writes: > I usually use implicit concatenation: > > s = ('some long text that ' > 'needs to be split') I do something very similar: fleebnorg.spam = ( 'some long text that' ' needs to be split') The differences are: I prefer to have indents as 4 spaces no matter how long the preceding line is; but I also want the opening quote for the start of the string to line up with subsequent open quotes for that string. So I have all the portions of the string line up at the same (new) indent level. To make that simpler without thinking about it every time I change the first line, I simply break after the opening parenthesis. I prefer the continued portions to have the connecting space (or whatever characters are contextually ?connecting? in the text); this is a greater visual cue that the string doesn't stand alone. -- \ ?I went camping and borrowed a circus tent by mistake. I didn't | `\ notice until I got it set up. People complained because they | _o__) couldn't see the lake.? ?Steven Wright | Ben Finney From mdw at distorted.org.uk Sun Jan 11 05:47:09 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 10:47:09 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Mark Wooding wrote: > > rurpy at yahoo.com wrote: > > > >> What is the observable difference between converting an > >> array to a reference (pointer) to that array and passing > >> the reference by value, and passing the array by reference? > > > > For one: > > > > #include > > static size_t foo(char v[]) { return sizeof v; } > > int main(void) { > > char v[sizeof(char *) * 10]; > > puts(foo(v) == sizeof(char *) ? "pointer" : "reference"); > > return (0); > > } > > You are saying that because the size of the argument > (10) is not available in the function, it cannot be > call-by-reference? No, I'm saying that because the parameter has pointer type, not array type, it's a pointer being passed by value, not an array being passed by reference. And the size of the argument is not 10: it's 10 times as much as the (nonzero) size of a pointer -- and therefore distinguishable on any C implementation. > I think fortran is accepted as the archetypal call-by- > reference language and it does not automatically > supply argument size information to functions. Well and dandy; but Fortran doesn't turn arrays into pointers. > > For another: > > > > static void bar(char v[]) { char ch = 0; v = &ch; } > > /* type error if arrays truly passed by reference */ > > v can be used as an array reference, e.g. "v[1] = 23" > exactly as in the pass-by-reference fortran example. And > v can also be used as a local variable and reassigned. > If the first option was the only one, would you not > say C was definitely pass-by-reference (for arrays)? > If one could only use v as a pointer (i.e. access > the argument array as "*(v+1) = 23", then I would > say that arrays are not passed at all, only pointers > by-value. Your knowledge of C is clearly limited, at best. The notations *(p + i) and p[i] are entirely equivalent in every way, since the square-brackets indexing operator is in fact defined in terms of pointer dereference (6.5.2.1): : [#2] 2 A postfix expression followed by an expression in square : brackets [] is a subscripted designation of an element of an array : object. The definition of the subscript operator [] is that E1[E2] is : identical to (*((E1)+(E2))). Because of the conversion rules that : apply to the binary + operator, if E1 is an array object : (equivalently, a pointer to the initial element of an array object) : and E2 is an integer, E1[E2] designates the E2-th element of E1 : (counting from zero). Of course, because the + operator is commutative > That both these options exist causes me to conclude > that, for arrays, parameter passing can be viewed > as either arrays by-reference or pointers by-value. > > I don't understand what relevance type checking > has. Since you are choosing to use v as a pointer, > one would not expect a type error, yes? Compare: void mumble(void) { char v[42]; char ch = 0; v = &ch; } /* error: incompatible types in assignment */ It's because in the previous case v is a pointer that the compiler doesn't mind me assigning to it. In this case, because it's an array, the compiler objects. > >> I guess the case for pass-by-value would be a little stronger because > >> one has to have "passing a pointer by value" anyway (since pointers > >> are first-class datatypes) and that can be used to describe passing > >> arrays (as you described). > > > > The difference is that the /callee/ function is different between the > > two cases. > > > > Also, notice that arrays in expressions turn into pointers in the same > > way, so function argument passing works the same way as assignment -- a > > hallmark of pass-by-value. > > Not in all expressions as you yourself mentioned: > int a[10], *ap; > sizeof a; > sizeof ap; Well done, you've pedantically picked up on the lapse in the first part of the sentence (about sizeof, which as you say I've already mentioned elsewhere) but failed to take any notice of the more important and relevant point in the second half -- that argument passing works the same way as assignment -- for `arrays' just as for other types. void fa(char p[]); void fp(char *p); void fi(int i); char a[10 * sizeof(char *)] = "bar", aa[10 * sizeof(char *)] = "splat"; char *p = "foo", *pp = "mumble"; int i = 42, ii = 69; i = ii; /* assignment of integers */ fi(ii); /* integer call-by-value */ p = pp; /* assignment of pointers */ fp(pp); /* pointer call-by-value */ fa(pp); /* pointer call-by-value again */ a = aa; /* type error: incompatible types in assignment */ a = pp; /* type error: incompatible types in assignment */ p = aa; /* assignment of pointers */ fa(aa); /* pointer call-by-value yet again */ fp(aa); /* pointer call-by-value yet again */ Again, I refer readers to ISO 9899:1999: in particular: * 6.3.2.1p3 (array-to-pointer decay) * 6.5.2.2 (function calls) * 6.5.16 (assignment operator) Since I'm getting thoroughly fed up of repeating myself on this point, I'm simply going to assume, from now on, that anyone who offers a disagreement without citing passages from (at least a specific draft of) ISO 9899 to support any claims made is simply being wilfully ignorant -- and therefore no longer worth my attention. (If you don't have a copy of any such version, may I suggest http://std.dkuug.dk/jtc1/sc22/open/n2794/ citing this (confusingly) as n843, as a place to start.) -- [mdw] From deets at nospam.web.de Sun Jan 11 08:08:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 11 Jan 2009 14:08:06 +0100 Subject: Bad hack fix around a bizarre problem... In-Reply-To: References: Message-ID: <6su99mF888akU1@mid.uni-berlin.de> Just Another Victim of the Ambient Morality schrieb: > I'm trying to write a Python program that manipulates a MySQL database > and have chosen to use MySQLdb. So, I used by system's package manager, > YUM, and it appeared to install correctly. So, I tried it out and got this > error: > > > Traceback (most recent call last): > File "", line 1, in ? > File "MySQLdb/__init__.py", line 22, in ? > raise ImportError, "this is MySQLdb version %s, but _mysql is version > %r" %\ > ImportError: this is MySQLdb version (1, 2, 2, 'final', 0), but _mysql is > version (1, 2, 1, 'final', 1) > > > It looks like the MySQLdb version doesn't match the _mysql version. If > these were two different libraries, I might understand how this error > happened. However, they're part of the same library. _mysql is just a > Python binding to the MySQL C API and MySQLdb is just a Python wrapper > around _mysql to be compliant with the Python DB specification. They were > both part of the same library so how did their versions fall out of sync? > That's like getting a Windows application with incompatible DLLs! > > So, my bad hack of a fix is to copy the MySQLdb python code to a local > directory (where my python program will eventually reside) and, on this > local copy, comment out the version check. The idea is that MySQLdb is pure > Python, so it's unlikely that there is any incompatibility between it and > the very thin layer that is _mysql. The local copy is so I don't forget > that I'm using a modified version of this library. Python seems to import > this over the global one. I've done a bit of testing and, so far, it > appears to work! > What is my problem? A google search reveals that I'm not the only > person with this problem but it also reveals that absolutely no one knows > how to fix this. What are the chances that my fix will backfire? Thank > you... I guess the package maintainer messed up. If you'd install MySQLdb from source, it won't happen I guess. So I'd contact the package maintainer. Diez From googler.1.webmaster at spamgourmet.com Sun Jan 11 08:13:13 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 05:13:13 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <69bfa2e8-ac0f-4a71-981a-0724e75334f6@o4g2000pra.googlegroups.com> Hi! :) Thank you. I found PySys_SetPythonHome() to set the path where the lib folder of Python is, but I guess they are not really implemented because they are fixed compiled for an absolute path, aren't they? Thats the whole problem. Do you have a suggestoin for the command line how I can build it? Thanks From googler.1.webmaster at spamgourmet.com Sun Jan 11 08:27:37 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 05:27:37 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: Thank you, I found PySys_SetPythonHome() to set the path where the lib folder of Python is, but I guess they are not really implemented because they are fixed compiled with an absolute path, aren't they? Thats the problem. I hadn't compiled Python and I don't know if I should compile it as a dylib file or a framework? hmm. I know how to create a framework but compiling as a dylib hadn't worked yet. :-( Thanks From castironpi at gmail.com Sun Jan 11 08:27:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 05:27:48 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> Message-ID: <4140f1d3-0dff-4d20-84a1-17b735a71241@s9g2000prm.googlegroups.com> On Jan 10, 1:49?pm, Joe Strout wrote: > Aaron Brady wrote: > >> Aaron Brady wrote: > >>> Possible compromise. ?You can think of functions as mutation-only. > >>> You pass the object, and it gets a new (additional) name. ?The old > >>> name doesn't go in. ? > >> That's correct. ?The reference itself is passed in, not the variable (or > >> expression) that held or generated the reference in the calling code. > > > This is very odd, and I see it quite a bit. > > Me: "You pass the object." > > Joe: "That's correct. ?You pass the reference." > > > What was wrong with my original? > > I'm saying that I believe your idea was correct, but worded imprecisely > (IMHO of course). ?So I restated what I believed you were saying, using > terminology which I believe to be more precise. ?If nothing else, this > gives you the opportunity to say "No, that's not what I meant at all." I believe that my summary is exceedingly beginner-oriented, you might say colloquial. Someone who has even a little programming experience might find it childish. > >> This is true. ?(Technically, instead of variable, we should say "LValue" > >> here -- there are things slightly more complex than simple variables > >> that can serve as the left-hand side of an assignment. ?So replace > >> "variable" with "lvalue" above if you prefer.) > > > This is a point worth making. ?I want to penny-pinch every term in an > > introductory text, though, so, it's a tough call. > > Agreed. Is a function call an lvalue in Python? If not, descriptors are not functions. > >> M2: If 'fun()' returned a reference, you might be able to mutate the > >> object that refers to. > >> m2: You can sometimes mutate the object it refers to. > >> C2: 'fun()' returns a reference. > > > This is horrendous. > >http://en.wikipedia.org/wiki/Formal_fallacy > >http://en.wikipedia.org/wiki/Affirming_the_consequent > > I did point out that the logic was incorrect (even though the > conclusion, in this case, happens to be true).- You've done nothing other than restate your claim; and worse, you disguised doing so in the form of a deduction. > > A question: Are you Joe and you Mark certain that the simplest > > possible introductory explanation makes use of the term 'reference'? > > I am. In any explanation, there is an amount of detail omitted. In an introduction, it's large. (I hold false statements should be avoided, of course, and even misleading ones. However the latter is widely subject-dependent.) Your strategy may have a net positive unifying power, though; and we should see it if so. I may be asking whether it is safe and prudent to avoid (introducing) the term at the level we're looking at (as well as what level exactly it is). > > Perhaps we can have a contest for shortest/simplest/best description > > of Python's data/variable/argument model. > > Sure -- but it judging it might be difficult, requiring some newbies and > a test to check their comprehension (as you and I pondered once before). I think the step of least load would be to ask those who are having difficulty what their background is. At worst, they lie; next worst, there's no pattern. > > Lastly, I don't see any reason why we couldn't make both explanations > > available. ?'For those coming from Java/etc....; for those coming from > > C++/etc.....' ?They would both get read. > > Yes, except that the reference explanation applies equally well to > anyone coming from Java, C/C++, RB, VB.NET, and probably others... I'm > not sure to whom the other explanation would appeal, unless perhaps it's > LISP programmers (just a guess, since those on that side of the aisle > seem to invoke LISP more frequently). True or not, it requires the reader to know what references are. And, since your definition conflicts with the C++ definition, it's not clear that the requirement is good. More terminology: is 'a' a variable, a reference, or an object, in 'a=2'? It's a variable; it refers to an object. It's a variable, which refers to an object. It's a variable, which is a reference to an object. It's a reference to an object. Similarly, is '2' an expression, a reference, or an object? It's an expression; it evaluates to an object. It's an expression; it evaluates to a reference to an object. It's an expression; it expresses an object. It's an expression; it refers to an object. It's a reference to an object. It's an object. I'd like to recommend we decide on unique answers, or avoid ambiguity another way. In the case of the Socratic, non-bludgeoning, dialogue with a student, if the student can be trusted to question intelligently, s/he can be expected, on our telling him/er, "'a' is an object", to ask, "What object?" Whether to expect audience interaction, and what interaction, is a big component in the choice of method of a demonstration. >>> 300+301+302 is 300+301+302 False There are 10 objects created in the evaluation of this, 11 if including 'False'. They (their integer contents), in order, are: 300, 301, 302, then 300, 301, 302, not the same ones, again, then 602, 903, 602, 903, and then possibly 'False' *. * Based on a run of a build of 'r26:66714' with extra output from 'PyInt_FromLong' and command line '-c "300+301+302 is 300+301+302"'. Actual output showed 624 int objects created (!) with this function alone, ending with: 300 301 302 300 301 302 11788072 8192 11788072 601 903 601 903! Any ideas about those extra three? From castironpi at gmail.com Sun Jan 11 08:55:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 05:55:22 -0800 (PST) Subject: if-else statement References: <6951db8e-3302-4a65-9ebd-384ffacd86c3@s9g2000prg.googlegroups.com> <96d8f9f5-2679-4855-8b8a-7caaf4e5a410@b38g2000prf.googlegroups.com> Message-ID: On Jan 10, 2:28?pm, bearophileH... at lycos.com wrote: > Scott David Daniels: > > > ? ? ? if checking: > > ? ? ? ? ? my_var = 'string' > > ? ? ? else: > > ? ? ? ? ? my_var = 'other string' > > > remember, vertical space only kills trees if printed. > > I value clarity a lot. But this is more DRY, sometimes it's almost > equally clear, and you reduce vertical space, packing more code in the > same space, this allows you to see more logic, allowing you to have a > higher level view of the code, so allows you to understand the code > better: > > my_var = 'string' if checking else 'other string' > > So I think that sometimes it's useful. > > Bye, > bearophile It would be a good tool that allows you to see logic-- extra points for dynamic! A quick Google for 'python flow chart' turns up 'Visustin' (commercial + demo), 'Flowchart Python', & others. http://www.google.com/search?q=python+flow+chart . The "bird's eye view" in Visustin is pretty cool. Control-flow-only could be a lot simpler, just filtering statements with 'if/while/for', and try-except, not even in diagram. It's on the way for the open source IDE, right? From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 09:27:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 14:27:12 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0179f86a$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 03:25:24 +0000, Mark Wooding wrote: > Steven D'Aprano wrote: > >> I don't believe it is a red-herring. As I understand it, Mark and Joe >> insist that C is pass-by-value *even in the case of arrays*, despite >> the semantics of array passing being identical to the semantics of >> pass-by- reference in (say) Pascal. > > But they aren't. I've provided several examples to show this. Here's some p-b-r code in Pascal: program main(input, output); type arraytype = array[1..2] of integer; var arr: arraytype; procedure foo(var bar: arraytype); begin bar[2] := 42; writeln(' bar = ', bar[1], ' ', bar[2]); end; begin arr[1] := 0; arr[2] := 0; writeln(' Before: arr = ', arr[1], ' ', arr[2]); foo(arr); writeln(' After: arr = ', arr[1], ' ', arr[2]); end. Here's the output from running that code: Before: arr = 0 0 bar = 0 42 After: arr = 0 42 Here's the equivalent C code, as close to an exact one-to-one correspondence as I can come up with: #include void foo(int bar[2]) { bar[1] = 42; printf("\n bar = %d %d ", bar[0], bar[1]); } int main() { int arr[2]={0,0}; printf("\n Before: arr = %d %d ", arr[0], arr[1]); foo(arr); printf("\n After: arr = %d %d ", arr[0], arr[1]); printf("\n"); return 0; } And the output of it: Before: arr = 0 0 bar = 0 42 After: arr = 0 42 If it walks like pass-by-reference, and smells like pass-by-reference, and swims like pass-by-reference, is it still your contention that it is pass-by-value? > For the purpose of clearing this up once and for all: arrays, in C, are > `don't-pass-at-all'. There is no way -- none whatever -- of declaring a > function parameter as having array type. It looks just like I did precisely that here: void foo(int bar[2]) I guess this is where you explain again that arrays in C are "bizarre", and that while "int arr[2]" inside a function body means "declare an array of two ints and call it 'arr'", the exact same declaration in a function parameter list means something else. Possibly: "Declare a pointer which points to an array of two ints, call the pointer 'arr', and dereference the pointer every time it is used inside the function as if you were referring to the array directly". Am I close? -- Steven From http Sun Jan 11 09:32:31 2009 From: http (Paul Rubin) Date: 11 Jan 2009 06:32:31 -0800 Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xd4etj4lc.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > If it walks like pass-by-reference, and smells like pass-by-reference, > and swims like pass-by-reference, is it still your contention that it is > pass-by-value? Of course the C example is pass by value. It's just that the value being passed is an address. From steve at holdenweb.com Sun Jan 11 09:59:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 11 Jan 2009 09:59:21 -0500 Subject: Regex for unicode letter characters In-Reply-To: <496969A5.4090601@mrabarnett.plus.com> References: <2213c0f9-ad58-4d9c-915a-bd42b96e7a7c@t39g2000prh.googlegroups.com> <49695A76.9060306@mrabarnett.plus.com> <496969A5.4090601@mrabarnett.plus.com> Message-ID: MRAB wrote: > Steve Holden wrote: >> MRAB wrote: >>> schickb wrote: >>>> I need a regex that will match strings containing only unicode letter >>>> characters (not including numeric or the _ character). I was surprised >>>> to find the 're' module does not include a special character class for >>>> this already (python 2.6). Or did I miss something? >>>> >>>> It seems like this would be a very common need. Is the following the >>>> only option to generate the character class (based on an old post by >>>> Martin v. L?wis )? >>>> >>> [snip] >>> Basically, yes. >>> >>> The re module was last worked on in 2003 (remember it's all voluntary!). >>> Such omissions should be addressed in Python 2.7. >> >> By "should be" do you mean "ought to be (but I have no intention of >> helping)", "are expected to be (but someone else will be doing the >> work", "it's on my list and I am expecting to get finished in time for >> 2.7 integration" or something else? >> > The third one. Well, that's good news. Let me know if you need help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Jan 11 10:06:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 11 Jan 2009 10:06:46 -0500 Subject: Python strings and coding conventions In-Reply-To: References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> Message-ID: Mensanator wrote: > On Jan 10, 10:26?pm, Robert Kern wrote: >> koranth... at gmail.com wrote: >>> Hi, >>> ? ?Python Coding Convention (PEP 8) suggests : >>> ? Maximum Line Length >>> ? ? Limit all lines to a maximum of 79 characters. >>> ? I have a string which is ~110 char long. It is a string which I am >>> going to print in a text file as a single string. >>> ? i.e. in that text file, each line is taken as a different record - >>> so it has to be in a single line. >>> ? Now, how can I write this code - while following PEP 8? >>> ? I tried blockstrings, but as shown in the example below: >>>>>> s = r''' >>> ... abcd >>> ... efgh >>> ... ''' >>>>>> s >>> '\nabcd\nefgh\n' >>> ? ?it has "\n" inserted - which will disallow printing it to a single >>> line. >>> ? ?I thought about other options like concatenating strings etc, but >>> it seems very kludgy - esp since the whole string has a single meaning >>> and cannot be easily split to many logically. Then I thought of >>> creating a blockstring and then removing "\n", but it seemed >>> kludgier... >> I usually use implicit concatenation: >> >> s = ('some long text that ' >> ? ? ? 'needs to be split') > > Damn! I didn't know you could do that! And if I > saw it in a program listing, such would never occur > to me. I was going to suggest the stupid way: > Another option is escaping the newlines in triple-quoted strings: >>> s = """Some long text that \ ... needs to be split""" >>> s 'Some long text that needs to be split' >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From castironpi at gmail.com Sun Jan 11 10:21:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 11 Jan 2009 07:21:49 -0800 (PST) Subject: why cannot assign to function call References: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> <7xd4etj4lc.fsf@ruckus.brouhaha.com> Message-ID: On Jan 11, 8:32?am, Paul Rubin wrote: > Steven D'Aprano writes: > > If it walks like pass-by-reference, and smells like pass-by-reference, > > and swims like pass-by-reference, is it still your contention that it is > > pass-by-value? > > Of course the C example is pass by value. ?It's just that the value > being passed is an address. I believe, that in order for the C example to be p-b-r, you would need the following: void foo(var int bar[2]) { bar = malloc( something ); } Such that the caller reflects the change. From google at mrabarnett.plus.com Sun Jan 11 11:10:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jan 2009 16:10:53 +0000 Subject: Python strings and coding conventions In-Reply-To: <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <72622041-b54e-4872-8f7e-55ec1ef4e602@d42g2000prb.googlegroups.com> Message-ID: <496A1A0D.1060708@mrabarnett.plus.com> koranthala at gmail.com wrote: > On Jan 11, 9:26 am, Robert Kern wrote: >> koranth... at gmail.com wrote: >>> Hi, >>> Python Coding Convention (PEP 8) suggests : >>> Maximum Line Length >>> Limit all lines to a maximum of 79 characters. >>> I have a string which is ~110 char long. It is a string which I am >>> going to print in a text file as a single string. >>> i.e. in that text file, each line is taken as a different record - >>> so it has to be in a single line. >>> Now, how can I write this code - while following PEP 8? >>> I tried blockstrings, but as shown in the example below: >>>>>> s = r''' >>> ... abcd >>> ... efgh >>> ... ''' >>>>>> s >>> '\nabcd\nefgh\n' >>> it has "\n" inserted - which will disallow printing it to a single >>> line. >>> I thought about other options like concatenating strings etc, but >>> it seems very kludgy - esp since the whole string has a single meaning >>> and cannot be easily split to many logically. Then I thought of >>> creating a blockstring and then removing "\n", but it seemed >>> kludgier... >> I usually use implicit concatenation: >> >> s = ('some long text that ' >> 'needs to be split') >> >> -- >> 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 > > This is a very good method. > I found another method too - on further investigation >>>> s = "abc\ > ... efg" >>>> s > 'abcefg' > Only problem being that it doesnt support indentation. > So, implicit concatenation it is... > Another possibility is continuation _plus_ implicit concatenation. def example(): message = "now is the time " \ "for all good people ..." print message From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 11:28:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 16:28:58 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> <7xd4etj4lc.fsf@ruckus.brouhaha.com> Message-ID: <017a14f4$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 06:32:31 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> If it walks like pass-by-reference, and smells like pass-by-reference, >> and swims like pass-by-reference, is it still your contention that it >> is pass-by-value? > > Of course the C example is pass by value. It's just that the value > being passed is an address. I believe that's exactly the way VAR (reference) parameters are implemented in Pascal. What's the difference? -- Steven From torriem at gmail.com Sun Jan 11 11:29:21 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jan 2009 09:29:21 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <496A1E61.8030009@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > Thank you, I found PySys_SetPythonHome() to set the path where the lib > folder of Python is, but I guess they are not really implemented > because they are fixed compiled with an absolute path, aren't they? I'm afraid I'm not following you here. What is fixed compiled with an absolute path? What path are you talking about here? Linker path? Python default path for importing modules? Please read the documentation on embedding python and you'll see that you can initialize python and tell it to look anywhere for import modules. This is really all you have to do. In fact, if you import the built-in "sys" module, you can, from C++, add your Resource folder path to the sys.path dictionary (using api calls) and dynamically affect where python will import from. I did this once when I had a case where the user could place his plugin in an arbitrary spot. Hence I had to dynamically add the location to the path. If you are embedding python in your app, I would expect you to be familiar with the python apis. > Thats the problem. I hadn't compiled Python and I don't know if I > should > compile it as a dylib file or a framework? hmm. I know how to create a > framework but compiling as a dylib hadn't worked yet. :-( I'm very confused as previously you were talking about compiling python and now you're talking about not compiling python. Although it doesn't matter, since a framework file is a dylib file. In any case if you don't know how to set the linker paths (to relative) in App bundles, you'll want to consult apple docs, and the various apple e-mail lists. From googler.1.webmaster at spamgourmet.com Sun Jan 11 11:44:33 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 11 Jan 2009 08:44:33 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> Message-ID: <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> yeap, okay, its just the beginning so I didn't know that the framework is still the dylib file. Well, I only want to compile python and put the framework in the subdirectory. Thats all. And the current state is, that the framework is not found because the path of the compiled Python library is hardcoded so when I move it from /Library/Frameworks/ to my app folder it isn't found when I start my app. I found a ressource that I have to compile it with a dynamic path flag like LDFLAGS="-install_name, at executable_path/../Frameworks" to put it in the Framework of my app. maybe you know where my problem is. hm. bye From spaceoutlet at gmail.com Sun Jan 11 12:32:04 2009 From: spaceoutlet at gmail.com (Alex K) Date: Sun, 11 Jan 2009 18:32:04 +0100 Subject: template inheritance Message-ID: While building a website using template inheritance one usually does the following: fetch from database fetch from some more data from database ... << more required computations then at the end render the template with the fetched data Without template inheritance one usually does the following: fetch from database render this part of the site with this fetched data fetch some more data from the database render this other part of the site with the fetched data ... etc The first approach is much more elegant and leads to easier to maintain code. However the user will have to wait till the end of the fetching (long computations) before any rendering can take place. In the second approach however the site loads as we are fetching the data which is more convenient to the user. Am I correct to assume this? Is there a way to get the best of both worlds? Thank you. From mensanator at aol.com Sun Jan 11 12:48:53 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 09:48:53 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> Message-ID: <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> On Jan 11, 3:56?am, Marc 'BlackJack' Rintsch wrote: > On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote: > > Damn! I didn't know you could do that! And if I saw it in a program > > listing, such would never occur to me. I was going to suggest the stupid > > way: > > >>>> ga = ['four score and seven years ago ', \ > > ? ? ? ? ? 'our fathers brought forth ', \ > > ? ? ? ? ? 'on this continent a new nation ', \ > > ? ? ? ? ? 'conceived in liberty and dedicated ', \ > > ? ? ? ? ? 'to the proposition that all men ', \ > > ? ? ? ? ? 'are created equal'] > > What are all those line continuation characters ('\') for? ?You are aware > that they are unnecessary here? Actually, I wasn't aware of that. A quick review shows why. In the old manuals, implicit line continuation was in a seperate chapter (2.1.6) from implicit (2.1.5) so if you didn't read past 2.1.5 you would have missed it. The 2.6 manual is much better in this regard as it is now difficult to miss. Thanks for pointing that out as lists are just about the only place I use line continuation. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch From dotancohen at gmail.com Sun Jan 11 12:50:28 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 11 Jan 2009 19:50:28 +0200 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> References: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> Message-ID: <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> 2009/1/11 Sandro Tosi : >> I would suggest at least a chapter on _acquiring_ the data that is to >> be plotted using Python to scrape different sources _not_designed_ to >> be scraped. Online webpages come to mind. An example on retrieving, >> for instance, the prices of varying currencies, parsing the HTML >> pages, extracting the data, and then plotting it would be a great >> example for a real worlds usage that show matplotlib as a tool in a >> toolchain, not a means to an end. > > Well, a whole chapter to this is a little too much, but such examples > will be presented in the book: we're not going to teach how to program > in Python, but how to use matplotlib, so the data retriving is a > little out-of-scope (or at least border-line), so the code will be in > the examples provided along with the book, but not deeply explained in > the book text. > The problem with that approach is that you limit your audience to people who: 1) Are interested in matplotlab -AND- 2) Are already familiar with Python For every AND clause you remove you broaden the book's audience. You do not need to rewrite the book on Python programming or programming in general, but getting a C or even PHP programmer up to speed on the basics of Python as related to matplotlib will make the book much more accessible. At a minimum, it will add another valuable chapter to the book that can be safely ignored by Python gurus. And you are making the book that much more accessible. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From roy at panix.com Sun Jan 11 13:12:16 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 13:12:16 -0500 Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> Message-ID: In article <5db6181f-d6f6-4bdc-88c8-e12ad228c105 at r41g2000prr.googlegroups.com>, Mensanator wrote: > > What are all those line continuation characters ('\') for? ?You are aware > > that they are unnecessary here? > > Actually, I wasn't aware of that. A quick review shows > why. In the old manuals, implicit line continuation > was in a seperate chapter (2.1.6) from implicit (2.1.5) > so if you didn't read past 2.1.5 you would have missed it. My philosophy about line continuation is to assume lines can be continued after just about any piece of punctuation. If I'm wrong, the computer will tell me, and then I make the computer happy by adding a \. It's easier than looking it up, and way easier than memorizing the details. From mdw at distorted.org.uk Sun Jan 11 13:28:59 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 18:28:59 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <504c774c-f24e-453c-9f05-4cd56b577680@n33g2000pri.googlegroups.com> <4140f1d3-0dff-4d20-84a1-17b735a71241@s9g2000prm.googlegroups.com> Message-ID: Aaron Brady wrote: > True or not, it requires the reader to know what references are. And, > since your definition conflicts with the C++ definition, it's not > clear that the requirement is good. I blame C++ for coopting a perfectly good word with a established well-understood meaning, and applying it to a half-baked and inconsistent concept. > More terminology: is 'a' a variable, a reference, or an object, in > 'a=2'? > > It's a variable; it refers to an object. > It's a variable, which refers to an object. > It's a variable, which is a reference to an object. > It's a reference to an object. It's an /identifier/ (2.3); or, if you want a shorter word, a /name/ (also 2.3). (I'll go with `name'.) In any given context, the name might or might not mean something. Names are assigned meanings by an /environment/; if the environment assigns a meaning to a name, we say that the name is /bound/ to that meaning; otherwise it is /unbound/. The rules for determining the environment at any given point in a program vary with language. Python is fairly simple: it is /lexically scoped/, which means that a great deal of information about the environment can be determined simply by analysing the program text statically. (Compare `dynamic scope', where the environment at any point in a program's executiondepends quite subtly on which functions are active at that point. The main difference is that, under lexical scoping, a function's environment is an extension of the environment in which it was defined, whereas under dynamic scoping a function's environment is an extension of the environment of the caller. Languages can offer both kinds of scoping simultaneously: both Common Lisp and Perl do this.) Python is /block-structured/: various syntactic forms (/blocks/) introduce new environments which are extensions of the environment of the enclosing block, i.e., within the inner block, a few names are bound to new meanings, while all the other names retain whatever meaning they had in the enclosing block. Names whose meanings are modified are said to be /bound by the block/. A name which occurs within the block is a /bound occurrence/ if the name is bound by the block, or a /free occurrence/ otherwise. Python has what one might call `implicit binding': a name appearing alone (or as part of a destructuring pattern) on the left-hand side of an assignment which would otherwise be a free occurrence, and in the absence of an explicit declaration such as `global' or `nonlocal', is implicitly bound to a fresh variable by the smallest enclosing block. Python also has explicit binding: e.g., the parameter names of a function are explicitly bound to new variables by the function. So, where were we? `a = 2'. The `a' is a name. It appears alone on the left-hand side of an assignment: this is therefore a candidate for implicit binding. Let's assume that `a' is bound to a variable, either as a result of this or some other implicit binding, or an explicit declaration. (I don't believe Python has meanings other than variables which might be bound to a name, so this is pretty safe. Scheme, for example, puts macros and special syntactic keywords in the same namespace as variables, so you can, for example, lexically rebind the IF keyword as a function, should you so wish. This is probably a bad idea.) So, `a' is bound to a variable. The variable, like all Python variables, stores a reference. We don't know what this reference might be before the assignment, but afterwards, we know that it must be a reference to an integer object representing the value 2. This is cumbersome to talk about; in informal conversations, one often talks about `the variable a' or even `the integer a'. It's important to realise that such phrases are abbreviations for convenience, and do not directly correspond to reality. > Similarly, is '2' an expression, a reference, or an object? > > It's an expression; it evaluates to an object. > It's an expression; it evaluates to a reference to an object. > It's an expression; it expresses an object. > It's an expression; it refers to an object. > It's a reference to an object. > It's an object. It's an /integer literal/ (2.4.3). It's also an expression, because all literals are expressions. We can confidently predict that the value of this expression (i.e., the result of evaluating it) is an integer object representing the value 2. > In the case of the Socratic, non-bludgeoning, dialogue with a student, > if the student can be trusted to question intelligently, s/he can be > expected, on our telling him/er, "'a' is an object", to ask, "What > object?" Whether to expect audience interaction, and what > interaction, is a big component in the choice of method of a > demonstration. Declaring `a' to be an object begs many questions, such as `what type does this object have?'. This is an unfortunate question, because the naive answer (e.g., from the above: `it's an integer') comes up against the problem that one can later say `a = "mumble"', causing one to declare `it's now a string'; but this contradicts 3.1: `An object's /type/ is also unchangeable' (with a footnote about how this might not be the complete truth). We could try to escape by saying that `a' is now a /different/ object, but that's strange because its appearance (i.e., the letter `a') hasn't changed at all. There are other problems with naively declaring that `a' is an object. In particular, if I just type `a' at a fresh Python, it says `name 'a' is not defined'. (Among other things, that tells me that `a' is a name.) Now the question `which object?' naively yields the answer `err... none -- no, not None, but none, there isn't one.'. At some level within the compiler, the `a' you type gets represented by an `object', though whether > >>> 300+301+302 is 300+301+302 > False > > There are 10 objects created in the evaluation of this, 11 if > including 'False'. They (their integer contents), in order, are: 300, > 301, 302, then 300, 301, 302, not the same ones, again, then 602, 903, > 602, 903, and then possibly 'False' *. Here we enter some philosophical (and implementation-specific) territory. Does the evaluation of a literal /create/ an object? The answer seems to be `maybe'. >>> 123456789 is 123456789 True Hmm. So at most one of the occurrences created a new object. I wonder... >>> def foo(x): ... if x is 123456789: print 'snap!' ... return 123456789 ... >>> foo(123456789) 123456789 >>> foo(_) snap! 123456789 It seems as if foo has a private copy of the magic number, rather than generating a new one (indeed, two new ones) each time. There is only one False object in the system (like there is only one None object). We can be sure that it didn't create that False specially for us. Given this, it doesn't seem right to talk about an expression necessarily creating objects, especially ones whose value appears literally. As another example, with strings this time: >>> def foo(): return '!mumble' ... >>> foo() is '!mumble' False >>> foo() is foo() True (The `!' suppresses the CPython compiler's interning process.) Tuples behave similarly. Lists, obviously, do not -- otherwise we could observably change the function's behaviour by mutating the list. (Lisp makes all of this much more explicit, since the input to the compiler consists of objects -- constructed by the reader -- rather than text, and one expects that, for example, self-evaluating and quoted objects evaluate identically to themselves, rather than creating new copies.) > * Based on a run of a build of 'r26:66714' with extra output from > 'PyInt_FromLong' and command line '-c "300+301+302 is 300+301+302"'. > Actual output showed 624 int objects created (!) with this function > alone, ending with: 300 301 302 300 301 302 11788072 8192 11788072 601 > 903 601 903! Any ideas about those extra three? My guess is that the first six at least are generated at compile-time, and then probably merged when the literal table is constructed. Some digging about with gdb shows that most of the early integer object constructions are from random modules imported on startup (even with `-S'). The `extra three' -- in your case 11788072 8192 11788072 -- are caused within PyAST_Compile. The first is by PySTEntry_New, constructing a new symbol table, and the argument is actually the address of a _mod structure explaining what we're meant to be compiling. The second is the value of FREE << SCOPE_OFF, from within update_symbols, and the last is in PySymtable_Lookup, and again it's converted the _mod address to an integer. This doesn't actually leave me much the wiser. But basically they're artifacts of internal compiler wrangling. -- [mdw] From mensanator at aol.com Sun Jan 11 13:34:35 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 10:34:35 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> Message-ID: <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> On Jan 11, 12:12?pm, Roy Smith wrote: > In article > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > ?Mensanator wrote: > > > What are all those line continuation characters ('\') for? ?You are aware > > > that they are unnecessary here? > > > Actually, I wasn't aware of that. A quick review shows > > why. In the old manuals, implicit line continuation > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > so if you didn't read past 2.1.5 you would have missed it. > > My philosophy about line continuation is to assume lines can be continued > after just about any piece of punctuation. ?If I'm wrong, the computer will > tell me, and then I make the computer happy by adding a \. ?It's easier > than looking it up, and way easier than memorizing the details. I proably got mine from Visual Basic where there are no exceptions to explicit line continuation marks. A least adding them when not necessary doesn't cause a problem. From mdw at distorted.org.uk Sun Jan 11 13:42:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 18:42:04 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <0179549a$0$8693$c3e8da3@news.astraweb.com> <0179f86a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I guess this is where you explain again that arrays in C are "bizarre", > and that while "int arr[2]" inside a function body means "declare an > array of two ints and call it 'arr'", the exact same declaration in a > function parameter list means something else. I quoted 6.7.5.3p7 before. Please pay attention. : A declaration of a parameter as ``array of type'' shall be adjusted to : ``qualified pointer to type'', where the type qualifiers (if any) are : those specified within the [ and ] of the array type derivation. If : the keyword static also appears within the [and ] of the array type : derivation, then for each call to the function, the value of the : corresponding actual argument shall provide access to the first : element of an array with at least as many elements as specified by the : size expression. > "Declare a pointer which points to an array of two ints, call the pointer > 'arr', and dereference the pointer every time it is used inside the > function as if you were referring to the array directly". No. Declare a pointer which points to an int, and call the pointer `arr'. > Am I close? Vaguely. A pointer to an array is not the same as a pointer to its first element. The former has type T (*)[N]; the latter has type T *. The compiler entirely ignores the number (unless you write `static' -- little-known C99 feature). There is no further magic: it's just a pointer. -- [mdw] From rdcollum at gmail.com Sun Jan 11 14:00:58 2009 From: rdcollum at gmail.com (Roger) Date: Sun, 11 Jan 2009 11:00:58 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox Message-ID: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> Hi Everyone, I have a behavior associated with a default binding with Tkinter Listbox that I want to get rid of but I can't no matter if I return "break" on the binding or unbind it directly. If you have a Listbox where the bounding box is not completely revealed in the window that holds it and you use the mouse to drag the list box, the contents of the listbox will move in the X direction to reveal the area that's hidden. After searching the internet for hours I found the behavior I want to remove is a default binding as described here: http://tcltk.free.fr/man/TkCmd/listbox.php3 "[3] If the mouse leaves the listbox window with button 1 down, the window scrolls away from the mouse, making information visible that used to be off-screen on the side of the mouse. The scrolling continues until the mouse re-enters the window, the button is released, or the end of the listbox is reached. " After further searching I found that the code for this in tcl is described here: http://www.openmash.org/lxr/source/library/listbox.tcl?c=tk8.3 50 bind Listbox { 51 set tkPriv(x) %x 52 set tkPriv(y) %y 53 tkListboxMotion %W [%W index @%x,%y] 54 } Now I've found no way to successfully unbind B1-Motion from the listbox, as I said above. Nor return "break" on receiving the event. I do want to eventually have my own B1-Motion binding applied to the listbox for a different reason (with add='+' if necessary). My next step was to see if I could just unbind B1-Motion then programmatically delete tkListboxMotion in my code but tkListboxMotion is not available in the Tkinter source (it's part of a compiled binary I can't reach?). Any help would be greatly appreciated. Thanks! Roger. From metolone+gmane at gmail.com Sun Jan 11 14:08:18 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 11 Jan 2009 11:08:18 -0800 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: "Barak, Ron" wrote in message news:7F0503CD69378F49BE0DC30661C6CCF602494CBE at enbmail01.lsi.com... > The source of gzip.py on my system seems to suggest that negative seeks > are supported: > > def seek(self, offset): > if self.mode == WRITE: > if offset < self.offset: > raise IOError('Negative seek in write mode') > count = offset - self.offset > for i in range(count // 1024): > self.write(1024 * '\0') > self.write((count % 1024) * '\0') > elif self.mode == READ: > if offset < self.offset: > # for negative seek, rewind and do positive seek > self.rewind() > count = offset - self.offset > for i in range(count // 1024): > self.read(1024) > self.read(count % 1024) > > Could any who're familiar with the inner working of gzip settle this issue > ? > Is seek from EOF supported for gzip files ? Source from 2.6.1. Seek from EOF not supported: def seek(self, offset, whence=0): if whence: if whence == 1: offset = self.offset + offset else: raise ValueError('Seek from end not supported') if self.mode == WRITE: if offset < self.offset: raise IOError('Negative seek in write mode') count = offset - self.offset for i in range(count // 1024): self.write(1024 * '\0') self.write((count % 1024) * '\0') elif self.mode == READ: if offset < self.offset: # for negative seek, rewind and do positive seek self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) -Mark From matrixhasu at gmail.com Sun Jan 11 14:16:25 2009 From: matrixhasu at gmail.com (Sandro Tosi) Date: Sun, 11 Jan 2009 20:16:25 +0100 Subject: What would you like to see in a book about Matplotlib? In-Reply-To: <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> References: <9bd5ad6d-cd3d-450a-9ccd-a49cdf14461d@a12g2000pro.googlegroups.com> <880dece00901110950j58229736md9cd60cbb4843360@mail.gmail.com> Message-ID: <8b2d7b4d0901111116u44282b2ey9300f20c9f530b05@mail.gmail.com> On Sun, Jan 11, 2009 at 18:50, Dotan Cohen wrote: > 2009/1/11 Sandro Tosi : >>> I would suggest at least a chapter on _acquiring_ the data that is to >>> be plotted using Python to scrape different sources _not_designed_ to >>> be scraped. Online webpages come to mind. An example on retrieving, >>> for instance, the prices of varying currencies, parsing the HTML >>> pages, extracting the data, and then plotting it would be a great >>> example for a real worlds usage that show matplotlib as a tool in a >>> toolchain, not a means to an end. >> >> Well, a whole chapter to this is a little too much, but such examples >> will be presented in the book: we're not going to teach how to program >> in Python, but how to use matplotlib, so the data retriving is a >> little out-of-scope (or at least border-line), so the code will be in >> the examples provided along with the book, but not deeply explained in >> the book text. > > The problem with that approach is that you limit your audience to people who: > 1) Are interested in matplotlab > -AND- > 2) Are already familiar with Python That is exactly the target the editor wants to reach... > For every AND clause you remove you broaden the book's audience. You > do not need to rewrite the book on Python programming or programming > in general, but getting a C or even PHP programmer up to speed on the > basics of Python as related to matplotlib will make the book much more > accessible. At a minimum, it will add another valuable chapter to the > book that can be safely ignored by Python gurus. And you are making > the book that much more accessible. I will try to ask this, but they were really clear that knowing python is a prerequisite of the book readers. -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi From rurpy at yahoo.com Sun Jan 11 14:18:38 2009 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 11 Jan 2009 11:18:38 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> Message-ID: <22449938-4dab-45ae-820f-15e2c84963a5@v18g2000pro.googlegroups.com> Mark Wooding wrote: > rurpy at yahoo.com wrote: >> Mark Wooding wrote: >> > rurpy at yahoo.com wrote: >... >> > For another: >> > >> > static void bar(char v[]) { char ch = 0; v = &ch; } >> > /* type error if arrays truly passed by reference */ >> >> v can be used as an array reference, e.g. "v[1] = 23" >> exactly as in the pass-by-reference fortran example. And >> v can also be used as a local variable and reassigned. > >> If the first option was the only one, would you not >> say C was definitely pass-by-reference (for arrays)? >> If one could only use v as a pointer (i.e. access >> the argument array as "*(v+1) = 23", then I would >> say that arrays are not passed at all, only pointers >> by-value. > > Your knowledge of C is clearly limited, at best. The notations *(p + i) > and p[i] are entirely equivalent in every way, since the square-brackets > indexing operator is in fact defined in terms of pointer dereference > (6.5.2.1): >... Yes, my C experience is limited. I very rarely write any C these days and even many years ago when I wrote more, it was very vanilla stuff not requiring any deep knowlage of dark corners of the language. Nevertheless, I am aware of everything you wrote above (the gist, not the standard's verbiage) and the common demonstration of it: 3["surprised?"] => 'p'. But if you'll note, I said "if ..." referring to a couple of hypothetical C-like languages, so your chapter-and-verse quote from the standard, while interesting and appreciated, was basically irrelevant. >... >> > Also, notice that arrays in expressions turn into pointers in the same >> > way, so function argument passing works the same way as assignment -- a >> > hallmark of pass-by-value. >> >> Not in all expressions as you yourself mentioned: >> int a[10], *ap; >> sizeof a; >> sizeof ap; > > Well done, you've pedantically picked up on the lapse in the first part It isn't pedantic. It is the only thing (IFAIK) that allows one to talk about variables of an array type (as opposed to only pointers). >... > Since I'm getting thoroughly fed up of repeating myself on this point, > I'm simply going to assume, from now on, that anyone who offers a > disagreement without citing passages from (at least a specific draft of) > ISO 9899 to support any claims made is simply being wilfully ignorant -- > and therefore no longer worth my attention. > > (If you don't have a copy of any such version, may I suggest > > http://std.dkuug.dk/jtc1/sc22/open/n2794/ > > citing this (confusingly) as n843, as a place to start.) Actually I've already downloaded a C89/90 standard draft in the hope that an earlier version would be simpler. Since C's behavior vis "call-by-x" is (I presume) unchanged back to K&R, whatever it said about it should be confirmable by any ealier versions descriptions of C. But more importantly, we seem to be talking at cross purposes. My idea of a language model is a description of the language that is precise enough to allow a model's user to predict how any piece of code will behave when run. The C-standard(s) do that for C. Since many people would claim that a language that does not behave as the C standard describes is not C, it is definitional, and one cannot reasonably say that the model presented in the C standard is incorrect. (Of course, like all standards, the C standard is not perfect, it contains errors and inconsistencies that require correction, and like all languages, C evolves requiring new versions of the standard.) Nevertheless, I see no reason to believe, based on anything said in this thread, or my experience in general, that there can be *only* one correct model of a language, or part of a language. So all the quoting of the C standard in the world does not address the issue: can C's array passing be described (modeled) as pass-by-reference? I acknowledge that the C standard provides one (correct) model in which arrays aren't passed, only pointers by-value. To address the issue you need to show that an alternate model (array passing by-reference for example) is incorrect, i.e. leads it user to conclude that a program will behave differently than it does. And of course, when such a discrepancy model and behavior is pointed out, the proposer of the alternate model will fix it if possible. If you can not show that an alternate model is incorrect, then the next best thing is to show that your model is better. Better would involve considerations such as simpler, consistent with other languages, easier to understand by various categories of users, etc. Obviously this is a very subjective task, and one could expect disagreement. Many of the responses by you, Joe, and others, have an "of course this model is the right one, how could anyone think otherwise" tone to them. I hope I have explained clearly why I think that attitude is unjustified. Finally, and please don't be insulted by this, but to me and many readers, you are a bunch on glowing dots on a screen. I have been using the internet long enough to have any number of times read very plausible, authoritative sounding tomes only to find out later they were BS, or a least, not as widely accepted as gospel as the author proclaimed. All that not withstanding, thank you for taking the time to respond in the depth you have. I appreciate it and have clarified a lot of my thinking on the subject as as result. From deets at nospam.web.de Sun Jan 11 15:04:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 11 Jan 2009 21:04:11 +0100 Subject: template inheritance In-Reply-To: References: Message-ID: <6sv1lsF8arprU1@mid.uni-berlin.de> Alex K schrieb: > While building a website using template inheritance one usually does > the following: > > fetch from database > fetch from some more data from database > ... << more required computations > then at the end render the template with the fetched data > > Without template inheritance one usually does the following: > > fetch from database > render this part of the site with this fetched data > fetch some more data from the database > render this other part of the site with the fetched data > ... > etc > > The first approach is much more elegant and leads to easier to > maintain code. However the user will have to wait till the end of the > fetching (long computations) before any rendering can take place. In > the second approach however the site loads as we are fetching the data > which is more convenient to the user. > > Am I correct to assume this? Is there a way to get the best of both > worlds? Thank you. I don't think that the question of inheritance or not is really relevant here. It's a matter of how the templating system is written - does it collect all the data beforehand, or not, is it potentially using e.g. generators and so forth. And of course how the programmer uses the templating system. does he fetch all the data beforehand, or does he use lazy generation approachs - again, e.g. generators, or callbacks. Besides, *usually* the 20-39Kb of a website itself aren't the problem I'd say - loading referenced resources is much more of an issue. And AFAIK the render-mode matters, too. If the site is XHTML-compliant, the browser can start the rendering once the HTML is complete - otherwise, it might wait until the referenced resources are all loaded to calculate the layout. Diez From sjmachin at lexicon.net Sun Jan 11 15:37:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 12:37:17 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> Message-ID: <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> On Jan 12, 5:34?am, Mensanator wrote: > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > > > > In article > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > Mensanator wrote: > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > that they are unnecessary here? > > > > Actually, I wasn't aware of that. A quick review shows > > > why. In the old manuals, implicit line continuation > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > so if you didn't read past 2.1.5 you would have missed it. > > > My philosophy about line continuation is to assume lines can be continued > > after just about any piece of punctuation. If I'm wrong, the computer will > > tell me, and then I make the computer happy by adding a \. It's easier > > than looking it up, and way easier than memorizing the details. > > I proably got mine from Visual Basic where there are no > exceptions to explicit line continuation marks. A least > adding them when not necessary doesn't cause a problem. Fugly code is not a problem? From mdw at distorted.org.uk Sun Jan 11 15:45:46 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 20:45:46 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <28f25af3-8fc3-4435-adb0-c7030cd5e96d@i20g2000prf.googlegroups.com> <1779ccc8-58ab-42e9-b73c-9ffb55d33cc7@40g2000prx.googlegroups.com> <2e540bef-dcc3-41df-8783-40dca1e95154@i24g2000prf.googlegroups.com> <22449938-4dab-45ae-820f-15e2c84963a5@v18g2000pro.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > But if you'll note, I said "if ..." referring to a couple of > hypothetical C-like languages, so your chapter-and-verse quote from > the standard, while interesting and appreciated, was basically > irrelevant. Ah, what you actually said was still quoted above (thanks): : v can be used as an array reference, e.g. "v[1] = 23" exactly as in : the pass-by-reference fortran example. And v can also be used as a : local variable and reassigned. : : If the first option was the only one, would you not say C was : definitely pass-by-reference (for arrays)? I must have been reading too quickly and I missed the conditional here. I'm terribly sorry. :-( Answering the question as posed, rather than mis-read: I think the sizeof business would still indicate that a pointer was being passed. If the language also forbade sizeof on array-type arguments and passing array as arguments to functions expecting pointers, then I'd say you'd have a point. But I'm not sure I'd agree that such a language was `C-like' -- the bizarre behaviour of arrays is one of the language's most distinctive features! > >> > Also, notice that arrays in expressions turn into pointers in the same > >> > way, so function argument passing works the same way as assignment -- a > >> > hallmark of pass-by-value. > >> > >> Not in all expressions as you yourself mentioned: > >> int a[10], *ap; > >> sizeof a; > >> sizeof ap; > > > > Well done, you've pedantically picked up on the lapse in the first part > > It isn't pedantic. It is the only thing (IFAIK) that allows one to > talk about variables of an array type (as opposed to only pointers). You can talk about /variables/ of array type, but not /expressions/ of array type (except in very limited circumstances, as operands of sizeof or &). > Actually I've already downloaded a C89/90 standard draft in the hope > that an earlier version would be simpler. Since C's behavior vis > "call-by-x" is (I presume) unchanged back to K&R, whatever it said > about it should be confirmable by any ealier versions descriptions of > C. It should be; but you may have to adjust the clause numbers I'm citing. Also, the earlier version of the standard didn't have numbered paragraphs, which makes citing specific bits more tedious. > But more importantly, we seem to be talking at cross purposes. We might be... [snip] > So all the quoting of the C standard in the world does not address the > issue: can C's array passing be described (modeled) as > pass-by-reference? I acknowledge that the C standard provides one > (correct) model in which arrays aren't passed, only pointers by-value. > > To address the issue you need to show that an alternate model (array > passing by-reference for example) is incorrect, i.e. leads it user to > conclude that a program will behave differently than it does. And of > course, when such a discrepancy model and behavior is pointed out, the > proposer of the alternate model will fix it if possible. I'd claim, in fact, that the proposer of an alternative model bears the responsibility to prove it correct, i.e., in the case of C, at least consistent with the official standard. But I believe that I have indeed shown that the arrays-passed-by- reference model is incorrect, by demonstrating that the called function sees the parameter as a freshly allocated pointer and not an array: it can be assigned (unlike an array); its size is that of a pointer; one can take its address and manipulate its bit-pattern as if it were a pointer. Indeed, the standard guarantees that no strictly-conforming C program can distinguish the parameter from a freshly allocated pointer. And therefore I can point to my earlier (almost-formal) definitions of pass-by-value and pass-by-reference to complete the proof: the allocation of a new variable is inconsistent with pass-by-reference, while it is consistent with pointer-decay followed by pass-by-value. Of course, this is contingent on your acceptance of my definitions. But I don't see anyone else providing sufficiently detailed definitions to make such proofs, and my definitions seem consistent with the way most other languages use the terms, so I'm pretty confident that they're good... > Many of the responses by you, Joe, and others, have an "of course this > model is the right one, how could anyone think otherwise" tone to > them. I hope I have explained clearly why I think that attitude is > unjustified. I hope that I've been doing more than that: drawing comparisons with and borrowing concepts from other languages, attempting to solidify definitions which otherwise seem to cause controversy, and then drawing conclusions from these definitions to strengthen my case and weaken others' cases. > Finally, and please don't be insulted by this, but to me and many > readers, you are a bunch on glowing dots on a screen. As are we all. (Brought to you by Sobering Thought for the Day.) > I have been using the internet long enough to have any number of times > read very plausible, authoritative sounding tomes only to find out > later they were BS, or a least, not as widely accepted as gospel as > the author proclaimed. I'm trying very hard not to ask anyone to take my word for things -- it always makes me uneasy when people are willing to do that, but they seem to be[1]. Rather, I'm attempting to present my reasoning in a way that you and others can read and judge for yourselves. If I've failed, then I'm sorry -- I'm fallible, and my communication skills are somewhere between imperfect and downright patchy depending on who you talk to. [1] I work in security. Being asked to take things on trust rubs me up the wrong way, and I hope that other people react the same way; if they don't, I get nervous... > All that not withstanding, thank you for taking the time to respond in > the depth you have. I appreciate it and have clarified a lot of my > thinking on the subject as as result. -- [mdw] From madhusudancs at gmail.com Sun Jan 11 16:22:47 2009 From: madhusudancs at gmail.com (Madhusudan.C.S) Date: Sun, 11 Jan 2009 13:22:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? Message-ID: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> I am sorry all I am not here to just blame Python. This is just an introspection of whether what I believe is right. Being a devotee of Python from past 2 years I have been writing only small apps and singing praises about Python where ever I go. I now got a chance to read Django's code for some reason. I have now strongly started feeling if Python really follows its "Readability Counts" philosophy. For example, class A: a = 10 b = "Madhu" def somemethod(self, arg1): self.c = 20.22 d = "some local variable" # do something .... ... def somemethod2 (self, arg2): self.c = "Changed the variable" # do something 2 ... In such situations, where the Instance variables come into existence only when they are used it is very difficult to track the flow of code. Its obviously not possible to remember what instance variable was defined where, when reading some substantial amount of code and where it was manipulated for that matter. It becomes so very frustrating even when reading a Class's code with just 6-8 methods and not more than 100-150 lines of code. I am interested in knowing if I am reading this kind of code in the wrong way mostly because of C++/Java hangover since most other languages follow the same approach as them? If there is a Pythonic way reading this code for better readability? What made Python developers to adopt this strange strategy keeping "Readibility Counts" in mind? -- Python Rocks! Madhusudan.C.S From mensanator at aol.com Sun Jan 11 16:23:36 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 11 Jan 2009 13:23:36 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> Message-ID: On Jan 11, 2:37?pm, John Machin wrote: > On Jan 12, 5:34?am, Mensanator wrote: > > > > > > > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > In article > > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > > Mensanator wrote: > > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > > that they are unnecessary here? > > > > > Actually, I wasn't aware of that. A quick review shows > > > > why. In the old manuals, implicit line continuation > > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > > so if you didn't read past 2.1.5 you would have missed it. > > > > My philosophy about line continuation is to assume lines can be continued > > > after just about any piece of punctuation. If I'm wrong, the computer will > > > tell me, and then I make the computer happy by adding a \. It's easier > > > than looking it up, and way easier than memorizing the details. > > > I proably got mine from Visual Basic where there are no > > exceptions to explicit line continuation marks. A least > > adding them when not necessary doesn't cause a problem. > > Fugly code is not a problem? Is that how you justify breaing "explicit is better than implicit"? From clp2 at rebertia.com Sun Jan 11 16:31:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 13:31:22 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <50697b2c0901111331t151a902q67b2f25a153100cb@mail.gmail.com> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > class A: > a = 10 > b = "Madhu" Those are class variables, not instance variables. There is a distinct difference. Instance variables, in contrast, are "declared" and created in the body of the __init__ method. > > def somemethod(self, arg1): > self.c = 20.22 > d = "some local variable" > # do something > .... > ... > def somemethod2 (self, arg2): > self.c = "Changed the variable" > # do something 2 > ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code and where > it was manipulated for that matter. It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. That's bad coding style on the part of the code writer. Conditionally-existing instance variables are *evil*. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sun Jan 11 16:42:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 13:42:41 -0800 (PST) Subject: Python strings and coding conventions References: <8aa56d34-f060-45a5-af57-0e564c1fa9e1@k1g2000prb.googlegroups.com> <6stu1iF813rdU1@mid.uni-berlin.de> <5db6181f-d6f6-4bdc-88c8-e12ad228c105@r41g2000prr.googlegroups.com> <1d2ddbc2-fb9f-4828-9bc2-3cb6f928484f@a12g2000pro.googlegroups.com> <3509d8f7-81fa-4d67-a362-2210c196a29d@r36g2000prf.googlegroups.com> Message-ID: <22a3c0ce-20c1-48a2-99ef-4ad4ae9db837@r36g2000prf.googlegroups.com> On Jan 12, 8:23?am, Mensanator wrote: > On Jan 11, 2:37 pm, John Machin wrote: > > > > > > > On Jan 12, 5:34 am, Mensanator wrote: > > > > On Jan 11, 12:12 pm, Roy Smith wrote: > > > > > In article > > > > <5db6181f-d6f6-4bdc-88c8-e12ad228c... at r41g2000prr.googlegroups.com>, > > > > > Mensanator wrote: > > > > > > What are all those line continuation characters ('\') for? ?You are aware > > > > > > that they are unnecessary here? > > > > > > Actually, I wasn't aware of that. A quick review shows > > > > > why. In the old manuals, implicit line continuation > > > > > was in a seperate chapter (2.1.6) from implicit (2.1.5) > > > > > so if you didn't read past 2.1.5 you would have missed it. > > > > > My philosophy about line continuation is to assume lines can be continued > > > > after just about any piece of punctuation. If I'm wrong, the computer will > > > > tell me, and then I make the computer happy by adding a \. It's easier > > > > than looking it up, and way easier than memorizing the details. > > > > I proably got mine from Visual Basic where there are no > > > exceptions to explicit line continuation marks. A least > > > adding them when not necessary doesn't cause a problem. > > > Fugly code is not a problem? > > Is that how you justify breaing "explicit is > better than implicit"? I don't '''justify breaing "explicit is better than implicit"''' and wasn't attempting to do so. The Zen is more than one saying. No one saying trumps all others. Some may appear to be in conflict with others. One must consider the combined effect. Other sayings relevant to your problem are: Beautiful is better than ugly. Simple is better than complex. Readability counts. HTH, John From bjourne at gmail.com Sun Jan 11 16:59:34 2009 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sun, 11 Jan 2009 22:59:34 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <740c3aec0901111359k1a7007cfrbe1cf9616df49889@mail.gmail.com> 2009/1/11 Madhusudan.C.S : > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > class A: > a = 10 > b = "Madhu" > > def somemethod(self, arg1): > self.c = 20.22 > d = "some local variable" > # do something > .... > ... > def somemethod2 (self, arg2): > self.c = "Changed the variable" > # do something 2 > ... In this case is the "c" attribute not "declared" in the __init__() method of A? > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? Not declaring instance variables is just poor form. IMHO Python code should mostly be written like C++/Java. When you use "tricks" like the above (dynamically adding attributes to a class) or getattr calls, catching AttributeErrors, manipulating __dict__, decorators or metaclasses you should really think twice whether you actually _need_ to use those tricks. -- mvh Bj?rn From kiliansto at gmail.com Sun Jan 11 17:06:22 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 14:06:22 -0800 (PST) Subject: Object help Message-ID: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> I have a class called ball. The members are things like position, size, active. So each ball is an object. How do I make the object without specifically saying ball1 = ball()? Because I don't know how many balls I want; each time it is different. The balls are to be thrown in from the outside of the screen. I think you get that is enough information. This doesn't directly pertain to balls, I have wanted to do something like this for many different things but didn't know how. I would think something like: def newball(): x = last_named_ball + 1 ball_x = ball(size, etc) # this initializes a new ball return ball_x But then that would just name a ball ball_x, not ball_1 or ball_2. Is it possible? From clp2 at rebertia.com Sun Jan 11 17:15:01 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 14:15:01 -0800 Subject: Object help In-Reply-To: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <50697b2c0901111415y2518b4d5j27c1bf7de7608b28@mail.gmail.com> On Sun, Jan 11, 2009 at 2:06 PM, killsto wrote: > I have a class called ball. The members are things like position, > size, active. So each ball is an object. Class names should use CamelCase, so it should be `Ball`, not `ball`. > How do I make the object without specifically saying ball1 = ball()? > Because I don't know how many balls I want; each time it is different. > > The balls are to be thrown in from the outside of the screen. I think > you get that is enough information. > > This doesn't directly pertain to balls, I have wanted to do something > like this for many different things but didn't know how. > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball > return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > Is it possible? Yes, but only using deep dark black magic. Just use a list of Ball objects instead. Example: the_balls = [Ball(size, etc) for i in range(number_of_balls)] -- Follow the path of the Iguana... http://rebertia.com From jervisau at gmail.com Sun Jan 11 17:17:46 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Mon, 12 Jan 2009 09:17:46 +1100 Subject: Object help In-Reply-To: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <8e63a5ce0901111417q56bffcc9wf1d0c99822dadf5@mail.gmail.com> On Mon, Jan 12, 2009 at 9:06 AM, killsto wrote: > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball > return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > Is it possible? > > How about placing the balls in a python list:balls = [Ball() for i in range(number_of_balls)] where number_of_balls is the number of balls you want to create. additional balls can be added to the list: balls.append(Ball()) now you can access the balls like so: >>> balls[0] < __main__.Ball instance at ...> -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Jan 11 17:20:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Jan 2009 22:20:17 GMT Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> Message-ID: <017a6749$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > I have a class called ball. The members are things like position, size, > active. So each ball is an object. > > How do I make the object without specifically saying ball1 = ball()? > Because I don't know how many balls I want; each time it is different. > > The balls are to be thrown in from the outside of the screen. I think > you get that is enough information. > > This doesn't directly pertain to balls, I have wanted to do something > like this for many different things but didn't know how. > > I would think something like: > > def newball(): > x = last_named_ball + 1 > ball_x = ball(size, etc) # this initializes a new ball return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. This is the TOTALLY wrong approach. Instead of having named balls, have a list of balls. balls = [] # no balls yet balls.append(Ball()) # one ball comes in from off-screen balls.append(Ball()) # and a second del balls[0] # the first ball got stuck in a tree balls = [] # all the balls were swept up in a hurricane and lost balls = [Ball(), Ball(), Ball(), Ball()] # four balls come in balls.append(Ball()) # and a fifth for b in balls: print b.colour # print the colour of each ball and so forth. -- Steven From pavlovevidence at gmail.com Sun Jan 11 17:42:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 14:42:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> On Jan 11, 3:22?pm, "Madhusudan.C.S" wrote: > ? I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. Ok, let's clear up a couple misconceptions right now. First: "Reabability counts" is a design principle of the language, not a mandate that every Python programmer write readable code. If Django project wants to write less readable code, they can. "Readability counts" means that Python is designed to make it easy for the Django project to write readable code if they choose. Second: "Readability counts" is not the only factor that matters. There are 19 Zen and sometimes they conflict with each other. Python tries to balance all these concerns; it doesn't greedily maximize any one of them. Some things might be a little less readable than they could be, but oftentimes that's because other design considerations were judged more important in that case. Having cleared that up, let's consider your specific points. > For example, > > ? ? class A: > ? ? a = 10 > ? ? b = "Madhu" > > ? ? def somemethod(self, arg1): > ? ? ? ? self.c = 20.22 > ? ? ? ? d = "some local variable" > ? ? ? ? # do something > ? ? ? ? .... > ? ? ... > ? ? def somemethod2 (self, arg2): > ? ? ? ? self.c = "Changed the variable" > ? ? ? ? # do something 2 > ? ? ? ? ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code Impossible? You are seriously overstating things. > and where > it was manipulated for that matter. This criticism is completely unfair. Instance variables have to be manipulated somewhere, and unless your object is immutable, that is going to happen outside of __init__. That's true in Java, C++, and pretty much any other language. > It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. > > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? (Well, it is a lot safer in Python. In C++, if you try to use an uninitialized variable, you'd get undefined behavior. Better to initialize it to null and at least get a guaranteed segfault. In Python if you try to use an uninitialized variable you'd get an AttributeError.) > If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? I'm not going to argue that this doesn't hurt readability, because it does (though not nearly as much as you claim). But there are other considerations, and in this case the flexibility of defining attributes outside __init__ is worth the potential decrease in readability. Here's a couple examples of where it's useful: 1. Sometimes classes are initialized without calling __init__, strange but true. Look at the pickle module, for instance. It creates the object without calling __init__ then sets all the instance variables itself. 2. Some classes have factory classmethods that create the object by a different means than calling __init__. (In fact, some classes have an internal method that initializes variables, which __init__ and the factories both call.) 3. Some objects, such as proxies, have uncertain sets of attributes. Requiring such objects to predict all the variables they need inside __init__ would limit their usability. Programmers would probably resort to hack-like workarounds like Decorator Design Pattern. 4. It allows a simplification of the object system. Right now, all attribute access is handled identically: at any point in time any attribute may be set. If you wanted to limit attribute creation to __init__, then it would mean objects have to have two phases (one, during __init__, where you can create attributes; the other, where you can only modify them). This would add significant complexity, and "Simple is better than complex. I'll also point out that even in C++/Java/etc. you have occasions where an instance variable doesn't do anything until a something triggers it. You can look to the constructor to see what it's initialized to, but it isn't really initialized to anything useful until some method call sets it to something useful. (Python makes it explicit that the variable isn't in use until it is initialized, and "Explicit is better than implicit".) In the end, the answer to you question is simply, "Readibilty counts, but other stuff matters too." Carl Banks From notvalid2 at sbcglobal.net Sun Jan 11 17:55:14 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 14:55:14 -0800 Subject: Where Find Activestate Python 2.5? Message-ID: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> I went to their site and the only choice seems 2.6. I looked around and found no other choices. Is it possible to get 2.5? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From sjmachin at lexicon.net Sun Jan 11 18:02:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 15:02:24 -0800 (PST) Subject: Where Find Activestate Python 2.5? References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> Message-ID: <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> On Jan 12, 9:55?am, "W. eWatson" wrote: > I went to their site and the only choice seems 2.6. I looked around and > found no other choices. Is it possible to get 2.5? What do you see when you go to http://www.activestate.com/activepython/downloads/ and scroll down? I see 3.0, 2.6.1, 2.6, 2.5.2. From http Sun Jan 11 18:02:54 2009 From: http (Paul Rubin) Date: 11 Jan 2009 15:02:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> Message-ID: <7x63klqwdd.fsf@ruckus.brouhaha.com> Carl Banks writes: > and where it was manipulated for that matter. > > This criticism is completely unfair. Instance variables have to be > manipulated somewhere, and unless your object is immutable, that is > going to happen outside of __init__. That's true in Java, C++, and > pretty much any other language. The criticism is very valid. Some languages do support immutable variables (e.g. "final" declarations in Java, "const" in C++, or universal immutability in pure functional languages) and they do so precisely for the purpose of taming the chaos of uncontrolled mutation. It would be great if Python also supported immutability. > I'm not going to argue that this doesn't hurt readability, because it > does (though not nearly as much as you claim). But there are other > considerations, and in this case the flexibility of defining > attributes outside __init__ is worth the potential decrease in > readability. There are cases where this is useful but they're not terribly common. I think it would be an improvement if creating new object attributes was by default not allowed outside the __init__ method. In the cases where you really do want to create new attributes elsewhere, you'd have to explicitly enable this at instance creation time, for example by inheriting from a special superclass: class Foo (DynamicAttributes, object): pass > 4. It allows a simplification of the object system. Right now, all > attribute access is handled identically: at any point in time any > attribute may be set. If you wanted to limit attribute creation to > __init__, then it would mean objects have to have two phases (one, > during __init__, where you can create attributes; the other, where you > can only modify them). This would add significant complexity, and > "Simple is better than complex. On the other hand, correct is better than buggy. From pavlovevidence at gmail.com Sun Jan 11 18:15:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 15:15:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> On Jan 11, 3:31?pm, Chris Rebert wrote: > On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > > ? ?def somemethod(self, arg1): > > ? ? ? ?self.c = 20.22 > > ? ? ? ?d = "some local variable" > > ? ? ? ?# do something > > ? ? ? ?.... > > ? ?... > > ? ?def somemethod2 (self, arg2): > > ? ? ? ?self.c = "Changed the variable" > > ? ? ? ?# do something 2 > > ? ? ? ?... > > > In such situations, where the Instance variables come into existence > > only when they are used > > it is very difficult to track the flow of code. Its obviously not > > possible to remember what > > instance variable was defined where, when reading some substantial > > amount of code and where > > it was manipulated for that matter. It becomes so very frustrating > > even when reading a Class's > > code with just 6-8 methods and not more than 100-150 lines of code. > > That's bad coding style on the part of the code writer. > Conditionally-existing instance variables are *evil*. Do you mean conditionally-useful instance variables evil, or that conditionally-useful variables are ok but it's evil for them to conditionally-exist? The former I don't agree with at all. If it's the latter, I believe there is something to be said for variables that exist when they are needed and don't when they're not. However, I acknowledge that listing all the variables you intend to use in __init__ is highly comforting, even if it does belie their current uselessness. Carl Banks From pavlovevidence at gmail.com Sun Jan 11 18:32:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 15:32:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> Message-ID: <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> On Jan 11, 5:02?pm, Paul Rubin wrote: > Carl Banks writes: > > and where it was manipulated for that matter. > > > This criticism is completely unfair. ?Instance variables have to be > > manipulated somewhere, and unless your object is immutable, that is > > going to happen outside of __init__. ?That's true in Java, C++, and > > pretty much any other language. > > The criticism is very valid. ?Some languages do support immutable > variables (e.g. "final" declarations in Java, "const" in C++, or > universal immutability in pure functional languages) and they do so > precisely for the purpose of taming the chaos of uncontrolled > mutation. ?It would be great if Python also supported immutability. I don't think what you said (which is fine) makes his criticism valid, unless you also suggest that all objects should be immutable. If any objects are mutable, you have to be prepared for objects to mutated outside the initializer. I guess it could be a valid criticism of Django's progamming style ("They mutate stuff haphazardly everywhere!!~") but that's not the Python langauge's problem. > > 4. It allows a simplification of the object system. ?Right now, all > > attribute access is handled identically: at any point in time any > > attribute may be set. ?If you wanted to limit attribute creation to > > __init__, then it would mean objects have to have two phases (one, > > during __init__, where you can create attributes; the other, where you > > can only modify them). ?This would add significant complexity, and > > "Simple is better than complex. > > On the other hand, correct is better than buggy. What bugginess do you speak of? Adding a variable outside __init__ is questionable style, not a bug. I don't think it's a significant source of bugs, either. And I definitely don't think the language should add a layer of complexity (and I think you're underestimating the complexity of making the whole object system two-phase) just to prevent a minor style issue. pychecker is the appropriate tool to diagnose this issue. Carl Banks From http Sun Jan 11 18:41:51 2009 From: http (Paul Rubin) Date: 11 Jan 2009 15:41:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> Message-ID: <7xhc45csw0.fsf@ruckus.brouhaha.com> Carl Banks writes: > > The criticism is very valid. ?Some languages do support immutable > > variables (e.g. "final" declarations in Java, "const" in C++, or > > universal immutability in pure functional languages) and they do so > > precisely for the purpose of taming the chaos of uncontrolled > > mutation. ?It would be great if Python also supported immutability. > > I don't think what you said (which is fine) makes his criticism valid, > unless you also suggest that all objects should be immutable. It would be enough to have a way to make specific objects and instance attributes immutable. > If any objects are mutable, you have to be prepared for objects to > mutated outside the initializer. Sure, but why have mutable objects all over the place? And, why always have attributes visible at all, outside the class definition? The approach in C++ and Java is to have public and private instance variables, where the private ones are visible only in the class methods. From kiliansto at gmail.com Sun Jan 11 18:49:27 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 15:49:27 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 11, 2:20?pm, Steven D'Aprano wrote: > On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > > I have a class called ball. The members are things like position, size, > > active. So each ball is an object. > > > How do I make the object without specifically saying ball1 = ball()? > > Because I don't know how many balls I want; each time it is different. > > > The balls are to be thrown in from the outside of the screen. I think > > you get that is enough information. > > > This doesn't directly pertain to balls, I have wanted to do something > > like this for many different things but didn't know how. > > > I would think something like: > > > def newball(): > > ? ? ?x = last_named_ball + 1 > > ? ? ball_x = ball(size, etc) # this initializes a new ball return ball_x > > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > This is the TOTALLY wrong approach. > > Instead of having named balls, have a list of balls. > > balls = [] ?# no balls yet > balls.append(Ball()) ?# one ball comes in from off-screen > balls.append(Ball()) ?# and a second > del balls[0] ?# the first ball got stuck in a tree > balls = [] ?# all the balls were swept up in a hurricane and lost > balls = [Ball(), Ball(), Ball(), Ball()] ?# four balls come in > balls.append(Ball()) ?# and a fifth > for b in balls: > ? ? print b.colour ?# print the colour of each ball > > and so forth. > > -- > Steven Thanks. That makes sense. It helps a lot. Although, you spelled color wrong :P. Just curious, is there another way? How would I do this in c++ which is listless IIRC. From clp2 at rebertia.com Sun Jan 11 18:49:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 15:49:31 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> Message-ID: <50697b2c0901111549r59e2e13bv7b19668d1ecc7210@mail.gmail.com> On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: > On Jan 11, 3:31 pm, Chris Rebert wrote: >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: >> > def somemethod(self, arg1): >> > self.c = 20.22 >> > d = "some local variable" >> > # do something >> > .... >> > ... >> > def somemethod2 (self, arg2): >> > self.c = "Changed the variable" >> > # do something 2 >> > ... >> >> > In such situations, where the Instance variables come into existence >> > only when they are used >> > it is very difficult to track the flow of code. Its obviously not >> > possible to remember what >> > instance variable was defined where, when reading some substantial >> > amount of code and where >> > it was manipulated for that matter. It becomes so very frustrating >> > even when reading a Class's >> > code with just 6-8 methods and not more than 100-150 lines of code. >> >> That's bad coding style on the part of the code writer. >> Conditionally-existing instance variables are *evil*. > > > Do you mean conditionally-useful instance variables evil, or that > conditionally-useful variables are ok but it's evil for them to > conditionally-exist? > > The former I don't agree with at all. > > If it's the latter, I believe there is something to be said for > variables that exist when they are needed and don't when they're not. > However, I acknowledge that listing all the variables you intend to > use in __init__ is highly comforting, even if it does belie their > current uselessness. The latter. I never even used the word "useful", so I have no idea where you got that from. To reiterate, variables which might only exist under certain conditions are evil, IMHO. This is not to say they are not useful in certain specific cases, just that in general there are better ways to design/structure programs to avoid them. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Sun Jan 11 18:53:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 11 Jan 2009 23:53:04 +0000 (UTC) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: [Dynamically adding and removing instance attributes...] > Here's a couple examples of where it's useful: > > 1. Sometimes classes are initialized without calling __init__, [...] > 2. Some classes have factory classmethods [...] > 3. Some objects, such as proxies, have uncertain sets of attributes. [...] > 4. It allows a simplification of the object system. [...] All good points. I'd like to add a fifth: it can provide a handy hook for one module to hang data off of another module's objects. This sort of thing isn't very nice, but it's sometimes the best way. (Other approaches include using wrappers, which might be very invasive if opaque, or don't actually solve the name-collision problem if transparent; or maintaining a dictionary, which involves messing about with weak pointers if you want to keep it from filling with cruft.) > In the end, the answer to you question is simply, "Readibilty counts, > but other stuff matters too." Amen. -- [mdw] From prologic at shortcircuit.net.au Sun Jan 11 18:53:52 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 09:53:52 +1000 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jan 12, 2009 at 9:49 AM, killsto wrote: > Thanks. That makes sense. It helps a lot. Although, you spelled color > wrong :P. color colour They are both correct depending on what country you come from :) > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. Why are you asking us ? We're Python devs/programmers not C++ cheers James PS: I wouldn't touch C++ with a 10-foot pole From clp2 at rebertia.com Sun Jan 11 18:58:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 15:58:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xhc45csw0.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c0901111558o4568bc0fy51152e8e8017351e@mail.gmail.com> On Sun, Jan 11, 2009 at 3:41 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Carl Banks writes: >> If any objects are mutable, you have to be prepared for objects to >> mutated outside the initializer. > > Sure, but why have mutable objects all over the place? And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. Regarding the second question, Python adheres to the principle that "We're all consenting adults here" and so does not provide complete encapsulation like more B&D languages. This is handy sometimes as it allows one to break through the encapsulation when necessary and fiddle with the internals. This is not to say that breaking encapsulation willy-nilly is advised, but it does allow for some neat hackery every now and again. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From roy at panix.com Sun Jan 11 19:00:46 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 19:00:46 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: In article <34c95e04-5b3f-44bc-a5bf-498518507131 at p36g2000prp.googlegroups.com>, "Madhusudan.C.S" wrote: > In such situations, where the Instance variables come into existence > only when they are used it is very difficult to track the flow of code. As the saying goes, "It's possible to write Fortran in any language". My personal habit is to "declare" all instance variables in the __init__() method of every class. If there's no better value, I set them to None. This isn't strictly required, but I think it makes it easier for somebody reading the code to understand the class. I'm not a big fan of dogmatic rules, other than the rule that says you should make your code as easy for somebody else to understand as possible. From clp2 at rebertia.com Sun Jan 11 19:00:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 16:00:57 -0800 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: <50697b2c0901111600w451bae73k92489959a0dd9fb8@mail.gmail.com> On Sun, Jan 11, 2009 at 3:49 PM, killsto wrote: > On Jan 11, 2:20 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: >> > I have a class called ball. The members are things like position, size, >> > active. So each ball is an object. >> >> > How do I make the object without specifically saying ball1 = ball()? >> > Because I don't know how many balls I want; each time it is different. >> This is the TOTALLY wrong approach. >> >> Instead of having named balls, have a list of balls. > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. If *I* recall correctly, the STL has a `vector` type which is the equivalent of Python's `list`. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From torriem at gmail.com Sun Jan 11 19:01:36 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jan 2009 17:01:36 -0700 Subject: Python 2.6.1 @executable_path In-Reply-To: <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> Message-ID: <496A8860.2020603@gmail.com> googler.1.webmaster at spamgourmet.com wrote: > yeap, okay, its just the beginning so I didn't know that the framework > is still the dylib file. > Well, I only want to compile python and put the framework in the > subdirectory. Thats all. > And the current state is, that the framework is not found because the > path of the compiled Python > library is hardcoded so when I move it from /Library/Frameworks/ to my > app folder it isn't found > when I start my app. Okay, that last sentence finally started to make some sense. Basically you can fixup your executable and any libraries you need to have the "@executable_path" part *after* the fact. This is not about python, but see this excellent document on bundling Qt apps which explains how this is done: http://doc.trolltech.com/4.3/deployment-mac.html It will tell you every thing you need to know about making it so app bundles can include and link against libraries and frameworks inside the app bundle itself. The keys are "otool" and "install_name_tool." > > I found a ressource that I have to compile it with a dynamic path flag > like LDFLAGS="-install_name, at executable_path/../Frameworks" to put it > in the Framework of my app. maybe you know where my problem is. hm. Yeah that sounds like one way to do it. From notvalid2 at sbcglobal.net Sun Jan 11 19:29:16 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 16:29:16 -0800 Subject: Where Find Activestate Python 2.5? In-Reply-To: <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> Message-ID: John Machin wrote: > On Jan 12, 9:55 am, "W. eWatson" wrote: >> I went to their site and the only choice seems 2.6. I looked around and >> found no other choices. Is it possible to get 2.5? > > What do you see when you go to http://www.activestate.com/activepython/downloads/ > and scroll down? I see 3.0, 2.6.1, 2.6, 2.5.2. That's correct. If I try to get there (downloads) via starting with the home page (click Python tab), select ActivePython in the Community, then I see one large icon button that takes me to 2.6. If instead of using the button, I select ActiveState Downloads, then I get to . I see ActivePython among the Developer Tools. Using that gets me to , the big download 2.6 button again. Nowhere did I get your url. An interesting maze. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From pavlovevidence at gmail.com Sun Jan 11 19:33:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:33:12 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> Message-ID: <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> On Jan 11, 5:49?pm, Chris Rebert wrote: > On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: > > On Jan 11, 3:31 pm, Chris Rebert wrote: > >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: > >> > ? ?def somemethod(self, arg1): > >> > ? ? ? ?self.c = 20.22 > >> > ? ? ? ?d = "some local variable" > >> > ? ? ? ?# do something > >> > ? ? ? ?.... > >> > ? ?... > >> > ? ?def somemethod2 (self, arg2): > >> > ? ? ? ?self.c = "Changed the variable" > >> > ? ? ? ?# do something 2 > >> > ? ? ? ?... > > >> > In such situations, where the Instance variables come into existence > >> > only when they are used > >> > it is very difficult to track the flow of code. Its obviously not > >> > possible to remember what > >> > instance variable was defined where, when reading some substantial > >> > amount of code and where > >> > it was manipulated for that matter. It becomes so very frustrating > >> > even when reading a Class's > >> > code with just 6-8 methods and not more than 100-150 lines of code. > > >> That's bad coding style on the part of the code writer. > >> Conditionally-existing instance variables are *evil*. > > > Do you mean conditionally-useful instance variables evil, or that > > conditionally-useful variables are ok but it's evil for them to > > conditionally-exist? > > > The former I don't agree with at all. > > > If it's the latter, I believe there is something to be said for > > variables that exist when they are needed and don't when they're not. > > However, I acknowledge that listing all the variables you intend to > > use in __init__ is highly comforting, even if it does belie their > > current uselessness. > > The latter. I never even used the word "useful", so I have no idea > where you got that from. I was just asking for clarification of your rationale, of which I imagined two possibilities ("conditional-usefulness is bad", or "declaring attributes outside of __init__" is bad). However... > To reiterate, variables which might only exist under certain > conditions are evil, IMHO. > This is not to say they are not useful in certain specific cases, just > that in general there are better ways to design/structure programs to > avoid them. ...the way you phrase this suggests to me that conditional-usefulness *is* what you are really concerned with. Let me give you an example: class A: def __init__(self): pass def something(self): self._conditionally_existent_variable = 1 ISTM that I don't need any restructuring at all to avoid conditional existence; all I'd have to do is add self._conditionally_existent_variable = None to __init__. If you think I need to restructure this code, than you evidently care about something more than just conditional existence. If so, what is it that's so evil about conditionally-existent variables? (I'll leave the question open-ended this time.) Carl Banks From rt8396 at gmail.com Sun Jan 11 19:37:09 2009 From: rt8396 at gmail.com (r) Date: Sun, 11 Jan 2009 16:37:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <05fbd39e-5906-4f84-886d-bc6c27d2c5ec@p29g2000vbn.googlegroups.com> On Jan 11, 6:00?pm, Roy Smith wrote: > In article > <34c95e04-5b3f-44bc-a5bf-498518507... at p36g2000prp.googlegroups.com>, > > ?"Madhusudan.C.S" wrote: > > In such situations, where the Instance variables come into existence > > only when they are used it is very difficult to track the flow of code. > > As the saying goes, "It's possible to write Fortran in any language". > > My personal habit is to "declare" all instance variables in the __init__() > method of every class. ?If there's no better value, I set them to None. ? > This isn't strictly required, but I think it makes it easier for somebody > reading the code to understand the class. > > I'm not a big fan of dogmatic rules, other than the rule that says you > should make your code as easy for somebody else to understand as possible. Roy i totally agree and as i read down this thread i was thinking i might get to spit that out first but you beat me -- Darn! PS: your explanation is also much more eloquent than mine would have been :) From http Sun Jan 11 19:42:52 2009 From: http (Paul Rubin) Date: 11 Jan 2009 16:42:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> Message-ID: <7xtz851hir.fsf@ruckus.brouhaha.com> Carl Banks writes: > If so, what is it that's so evil about conditionally-existent > variables? (I'll leave the question open-ended this time.) I have found they make the code more confusing and bug prone. It's better to define and document all the instance variables in one place, in most cases. From tjreedy at udel.edu Sun Jan 11 19:44:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Jan 2009 19:44:09 -0500 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: killsto wrote: > Just curious, is there another way? How would I do this in c++ which > is listless IIRC. If you do not have 0) built-in expandable arrays, as in Python, one can 1) program (or find) the equivalent of Python lists; 2) use linked-lists (as long as one does not need O(1) random access); 3) pick a maximum number of items, either for the app or for the run, and allocate space for that. Python enthusiasts include those who see the virtue of option 0). From pavlovevidence at gmail.com Sun Jan 11 19:44:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:44:27 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <44341058-6055-4cfd-ae00-55fff4112a2e@r41g2000prr.googlegroups.com> On Jan 11, 5:41?pm, Paul Rubin wrote: > Carl Banks writes: > > > The criticism is very valid. ?Some languages do support immutable > > > variables (e.g. "final" declarations in Java, "const" in C++, or > > > universal immutability in pure functional languages) and they do so > > > precisely for the purpose of taming the chaos of uncontrolled > > > mutation. ?It would be great if Python also supported immutability. > > > I don't think what you said (which is fine) makes his criticism valid, > > unless you also suggest that all objects should be immutable. > > It would be enough to have a way to make specific objects and instance > attributes immutable. Enough for what, to make the guy's criticism valid? No it wouldn't. Or are you just ignoring the OP altogether and complaining about what bothers you? For my part I am concerned with answering the OP's issues here, not yours. > > If any objects are mutable, you have to be prepared for objects to > > mutated outside the initializer. > > Sure, but why have mutable objects all over the place? ?And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. The OP wasn't complaining about the fact that objects aren't immutable, as far as I can tell, nor about having public and private variables, so I can't agree Python's lack of these has anything to do with the OP's concerns. Carl Banks From marek at xivilization.net Sun Jan 11 19:44:51 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 12 Jan 2009 01:44:51 +0100 Subject: Where Find Activestate Python 2.5? References: <9Nual.11133$as4.10218@nlpi069.nbdc.sbc.com> <5988a324-84a6-4e05-a42e-2b70c0f86c98@b38g2000prf.googlegroups.com> Message-ID: <20090112014451.35a588f0@halmanfloyd.lan.local> On Sun, 11 Jan 2009 16:29:16 -0800 "W. eWatson" wrote: > Using that gets me to > , the big download 2.6 > button again. Nowhere did I get your url. An interesting maze. Tried that "Other Systems and Versions" just below that "Download Now" button? regards, Marek From pavlovevidence at gmail.com Sun Jan 11 19:47:56 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 16:47:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> <7xtz851hir.fsf@ruckus.brouhaha.com> Message-ID: <0c65cf26-f0d0-4fba-87d9-7dda7869fa4e@s1g2000prg.googlegroups.com> On Jan 11, 6:42?pm, Paul Rubin wrote: > Carl Banks writes: > > If so, what is it that's so evil about conditionally-existent > > variables? ?(I'll leave the question open-ended this time.) > > I have found they make the code more confusing and bug prone. > It's better to define and document all the instance variables > in one place, in most cases. That means all I have to do is add a stopgap value in __init__. I'm asking Chris why that is evidently not enough, and that I'd have to structure/design my code to avoid it. Carl Banks From sjmachin at lexicon.net Sun Jan 11 20:07:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 17:07:30 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> On Jan 12, 10:49?am, killsto wrote: > On Jan 11, 2:20?pm, Steven D'Aprano wrote: > > On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote: > > > I have a class called ball. The members are things like position, size, > > > active. So each ball is an object. > > > > How do I make the object without specifically saying ball1 = ball()? > > > Because I don't know how many balls I want; each time it is different. > > > Instead of having named balls, have a list of balls. Or some other collection or container of objects (e.g. a dict or a queue), depending on what you are trying to simulate. > > for b in balls: > > ? ? print b.colour ?# print the colour of each ball > > Thanks. That makes sense. It helps a lot. Although, you spelled color > wrong :P. At this time of day you are likely to find yourself communicating with Australians. Get used to it :-) Cheers, John From roy at panix.com Sun Jan 11 20:16:24 2009 From: roy at panix.com (Roy Smith) Date: Sun, 11 Jan 2009 20:16:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: In article , Chris Rebert wrote: > This is not to say that breaking encapsulation willy-nilly is advised, > but it does allow for some neat hackery every now and again. I'm all for neat hackery, except when used in code that I need to read and understand. From pavlovevidence at gmail.com Sun Jan 11 20:23:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jan 2009 17:23:19 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: On Jan 9, 6:11?pm, John Machin wrote: > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > Aivar Annamaa wrote: > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > >> automatically fix. Changing print to print() on the other hand is > > > > >> easily fixed by 2to3. > > > > > >> Cheers, > > > > >> Chris > > > > > > I see. > > > > > So i gotta keep my own discipline with print() then :) > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > it as Python 3.x code. > > > > > regards > > > > ?Steve > > > > And mind you, if you follow that route, you are programming in a > > > mightily crippled language. > > > How do you figure? > > > I expect that it'd be a PITA in some cases to use the transitional > > dialect (like getting all your Us in place), but that doesn't mean the > > language is crippled. > > What is this "transitional dialect"? What does "getting all your Us in > place" mean? Transitional dialect is the subset of Python 2.6 that can be translated to Python3 with 2to3 tool. Getting all your Us in place refers to prepending a u to strings to make them unicode objects, which is something 2to3 users are highly advised to do to keep hassles to a minimum. (Getting Bs in place would be a good idea too.) > Steve & Cliff are talking about the rather small subset of Python that > is not only valid syntax in both 2.x and 3.x but also has the same > meaning in 2.x and 3.x. That would be a crippled language, yes. But I do not believe that's what Steve and Cliff are referring to. Steve wrote of "running your code through 2to3", and that was what Cliff followed up to, so I believe they are both referring to writing valid code in 2.6 which is able to be translated through 2to3, and then generating 3.0 code using 2to3. That is not a crippled language at all, just a PITA sometimes. > > >?It's about as bad as trying to write > > > cross-browser CSS. ?Don't put yourself through that pain if you don't > > > have to. > > > Have you tried doing that, or are you imagining how it will be? ?I'm > > curious about people's actual experiences. > > I maintain two packages, xlrd which supports 2.1 to 2.6, and xlwt > which supports 2.3 to 2.6. I've done suck-it-and-see trials on being > able to support 3.x as well from the same codebase, and it's turned > out reasonably well. xlrd already had a module called timemachine > which caters for version- dependent stuff. Extending this to 3.x was > more a voyage of discovery than a PITA. timemachine.py is "crippled" > in Cliff's sense, in that because I'm the principal user I need to > make it robust and idiot-proof, so it has been written under the > following constraints: > (1) not one copy of timemachine.py for 2.1, one for 2.2, one for > 2.3, ... etc; just one copy, period. > (2) means that it must use syntax that's valid in all supported > versions > (3) must be able to be processed by 2to3 without causing a commotion > (4) the original version and the 2to3 output must have the same effect > when imported by 3.x. > > So one ends up with code like: > ? ?glued = BYTES_NULL.join(list_of_pieces_of_a_binary_file) > which is supported by timemachine definitions like > BYTES_NULL = bytes(0) # 3.x ... note b'' is not valid in 2.x > BYTES_NULL = '' # 2.x > > BYTES_NULL.join() may be ugly, but it's not crippled, it's fully > functional, and it would be very easy to find and change in the future > in two possible scenarios (1) drop 2.x support (2) change codebase to > be mostly 3.x, support 2.x by a (mythical, hoped-for) 3to2 mechanism. Cool, thanks. Carl Banks From clp2 at rebertia.com Sun Jan 11 20:26:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jan 2009 17:26:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9039d1a1-03b1-4448-b111-7f75dcc7b634@o40g2000prn.googlegroups.com> <9acdd4af-6b1c-4781-9b51-328219b26bc6@p23g2000prp.googlegroups.com> Message-ID: <50697b2c0901111726h5f3bd21cud85cca3ef3615d29@mail.gmail.com> On Sun, Jan 11, 2009 at 4:33 PM, Carl Banks wrote: > On Jan 11, 5:49 pm, Chris Rebert wrote: >> On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks wrote: >> > On Jan 11, 3:31 pm, Chris Rebert wrote: >> >> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S wrote: >> >> > def somemethod(self, arg1): >> >> > self.c = 20.22 >> >> > d = "some local variable" >> >> > # do something >> >> > .... >> >> > ... >> >> > def somemethod2 (self, arg2): >> >> > self.c = "Changed the variable" >> >> > # do something 2 >> >> > ... >> >> >> > In such situations, where the Instance variables come into existence >> >> > only when they are used >> >> > it is very difficult to track the flow of code. Its obviously not >> >> > possible to remember what >> >> > instance variable was defined where, when reading some substantial >> >> > amount of code and where >> >> > it was manipulated for that matter. It becomes so very frustrating >> >> > even when reading a Class's >> >> > code with just 6-8 methods and not more than 100-150 lines of code. >> >> >> That's bad coding style on the part of the code writer. >> >> Conditionally-existing instance variables are *evil*. >> >> > Do you mean conditionally-useful instance variables evil, or that >> > conditionally-useful variables are ok but it's evil for them to >> > conditionally-exist? >> >> > The former I don't agree with at all. >> >> > If it's the latter, I believe there is something to be said for >> > variables that exist when they are needed and don't when they're not. >> > However, I acknowledge that listing all the variables you intend to >> > use in __init__ is highly comforting, even if it does belie their >> > current uselessness. >> >> The latter. I never even used the word "useful", so I have no idea >> where you got that from. > > I was just asking for clarification of your rationale, of which I > imagined two possibilities ("conditional-usefulness is bad", or > "declaring attributes outside of __init__" is bad). However... > > >> To reiterate, variables which might only exist under certain >> conditions are evil, IMHO. >> This is not to say they are not useful in certain specific cases, just >> that in general there are better ways to design/structure programs to >> avoid them. > > ...the way you phrase this suggests to me that conditional-usefulness > *is* what you are really concerned with. Let me give you an example: > > class A: > def __init__(self): > pass > def something(self): > self._conditionally_existent_variable = 1 > > > ISTM that I don't need any restructuring at all to avoid conditional > existence; all I'd have to do is add > > self._conditionally_existent_variable = None > > to __init__. If you think I need to restructure this code, than you > evidently care about something more than just conditional existence. No, this is exactly the sort of restructuring I was referring to; and nothing more. Making that one-line change would be sufficient for me. Perhaps "restructuring" was a poor choice of words... Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From prologic at shortcircuit.net.au Sun Jan 11 20:59:00 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 11:59:00 +1000 Subject: urllib2 - 403 that _should_ not occur. Message-ID: Hey all, The following fails for me: >>> from urllib2 import urlopen >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 389, in open response = meth(req, response) File "/usr/lib/python2.6/urllib2.py", line 502, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.6/urllib2.py", line 427, in error return self._call_chain(*args) File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden >>> However, that _same_ url works perfectly fine on the same machine (and same network) using any of: * curl * wget * elinks * firefox Any helpful ideas ? cheers James -- -- "Problems are solved by method" From narkewoody at gmail.com Sun Jan 11 21:00:40 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 12 Jan 2009 10:00:40 +0800 Subject: File layout in development stage Message-ID: Hi, Adapted your kindly suggestions in a previous post, I now decide to organize my source tree in a pattern like below: prj: src: lib: foomodule.py barmodule.py scripts: prj_main.py test: footest.py bartest.py ... That is, I want to put the top-level scripts in prj/src/scripts and share libraries in prj/src/lib. In the prj/test directory I want to put my unit-tests using unittest module. My question is that when in development stage there is no file is actually distributed, so how should a python source in one directory refer to (import) another module in another directory? Thanks in advance. - narke From aleksandr.goretoy at gmail.com Sun Jan 11 21:07:23 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 12 Jan 2009 02:07:23 +0000 Subject: File layout in development stage In-Reply-To: References: Message-ID: sys.path.append() -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com On Mon, Jan 12, 2009 at 2:00 AM, Steven Woody wrote: > Hi, > > Adapted your kindly suggestions in a previous post, I now decide to > organize my source tree in a pattern like below: > > > prj: > src: > lib: > foomodule.py > barmodule.py > scripts: > prj_main.py > test: > footest.py > bartest.py > ... > > > That is, I want to put the top-level scripts in prj/src/scripts and > share libraries in prj/src/lib. In the prj/test directory I want to > put my unit-tests using unittest module. My question is that when in > development stage there is no file is actually distributed, so how > should a python source in one directory refer to (import) another > module in another directory? > > Thanks in advance. > > - > narke > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sun Jan 11 21:58:52 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 11 Jan 2009 21:58:52 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> On Jan 11, 2009, at 8:59 PM, James Mills wrote: > Hey all, > > The following fails for me: > >>>> from urllib2 import urlopen >>>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>> ") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen > return _opener.open(url, data, timeout) > File "/usr/lib/python2.6/urllib2.py", line 389, in open > response = meth(req, response) > File "/usr/lib/python2.6/urllib2.py", line 502, in http_response > 'http', request, response, code, msg, hdrs) > File "/usr/lib/python2.6/urllib2.py", line 427, in error > return self._call_chain(*args) > File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain > result = func(*args) > File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > urllib2.HTTPError: HTTP Error 403: Forbidden >>>> > > However, that _same_ url works perfectly fine on the > same machine (and same network) using any of: > * curl > * wget > * elinks > * firefox > > Any helpful ideas ? The remote server doesn't like your user agent? It'd be easier to help if you post a working sample. Cheers Philip From notvalid2 at sbcglobal.net Sun Jan 11 22:00:53 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 11 Jan 2009 19:00:53 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) Message-ID: I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to try windowpy from ActiveState. Is having both of these installed going to cause me trouble? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From prologic at shortcircuit.net.au Sun Jan 11 22:05:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 13:05:30 +1000 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk wrote: > > On Jan 11, 2009, at 8:59 PM, James Mills wrote: > >> Hey all, >> >> The following fails for me: >> >>>>> from urllib2 import urlopen >>>>> f = >>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >> >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >> return _opener.open(url, data, timeout) >> File "/usr/lib/python2.6/urllib2.py", line 389, in open >> response = meth(req, response) >> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >> 'http', request, response, code, msg, hdrs) >> File "/usr/lib/python2.6/urllib2.py", line 427, in error >> return self._call_chain(*args) >> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >> result = func(*args) >> File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default >> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>> >> >> However, that _same_ url works perfectly fine on the >> same machine (and same network) using any of: >> * curl >> * wget >> * elinks >> * firefox >> >> Any helpful ideas ? > > The remote server doesn't like your user agent? > > It'd be easier to help if you post a working sample. That was a working sample! The "User-Agent" didn't occur to me :) Thanks - I think that might be it. Why Google would deny access to services by unknown User Agents is beyond me - especially since in most cases User Agents strings are not strict. cheers James From philip at semanchuk.com Sun Jan 11 22:25:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 11 Jan 2009 22:25:38 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Jan 11, 2009, at 10:05 PM, James Mills wrote: > On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk > wrote: >> >> On Jan 11, 2009, at 8:59 PM, James Mills wrote: >> >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>>> ") >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >>> return _opener.open(url, data, timeout) >>> File "/usr/lib/python2.6/urllib2.py", line 389, in open >>> response = meth(req, response) >>> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >>> 'http', request, response, code, msg, hdrs) >>> File "/usr/lib/python2.6/urllib2.py", line 427, in error >>> return self._call_chain(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >>> result = func(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 510, in >>> http_error_default >>> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >>> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>>> >>> >>> However, that _same_ url works perfectly fine on the >>> same machine (and same network) using any of: >>> * curl >>> * wget >>> * elinks >>> * firefox >>> >>> Any helpful ideas ? >> >> The remote server doesn't like your user agent? >> >> It'd be easier to help if you post a working sample. > > That was a working sample! Oooops, I guess it is my brain that's not working, then! Sorry about that. I tried your sample and got the 403. This works for me: >>> import urllib2 >>> user_agent="Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101" >>> url="http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml " >>> req = urllib2.Request(url, None, { 'User-Agent' : user_agent}) >>> f = urllib2.urlopen(req) >>> s=f.read() >>> f.close() >>> print s Chromium-Announce Google Group http://groups.google.com/group/chromium-announce This list is intended for important product announcements that affect the majority of etc. > Why Google would deny access to services by > unknown User Agents is beyond me - especially > since in most cases User Agents strings are not > strict. Some sites ban UAs that look like bots. I know there's a Java-based bot with a distinct UA that was really badly-behaved when visiting my server. Ignored robots.txt, fetched pages as quickly as it could etc. That was worthy of banning. FWIW, when I try the code above with a UA of "funny fish" it still works OK, so it looks like the groups.google.com server has it out for UAs with Python in them, not just unknown ones. I'm sure that if you changed wget's UA string to something Pythonic it would start to fail too. Cheers Philip From aahz at pythoncraft.com Sun Jan 11 22:38:48 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Jan 2009 19:38:48 -0800 Subject: sys.stdout.write()'s bug or doc bug? References: Message-ID: In article , Qiangning Hong wrote: > >So, my question is, as sys.stdout IS a file object, why it does not >use its encoding attribute to convert the given unicode? An >implementation bug? A documenation bug? Please file a bug on bugs.python.org -- that's the only way this can be tracked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From prologic at shortcircuit.net.au Sun Jan 11 22:50:28 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 13:50:28 +1000 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, Jan 12, 2009 at 1:25 PM, Philip Semanchuk wrote: > Oooops, I guess it is my brain that's not working, then! Sorry about that. Nps. > I tried your sample and got the 403. This works for me: (...) > Some sites ban UAs that look like bots. I know there's a Java-based bot with > a distinct UA that was really badly-behaved when visiting my server. Ignored > robots.txt, fetched pages as quickly as it could etc. That was worthy of > banning. FWIW, when I try the code above with a UA of "funny fish" it still > works OK, so it looks like the groups.google.com server has it out for UAs > with Python in them, not just unknown ones. > > I'm sure that if you changed wget's UA string to something Pythonic it would > start to fail too. My problem that I'm solving and my use-case is a tool to periodically check configured RSS feeds for updates. I was going to use urllib2 to get the data and pass this off to feedparser.parse(...) Because of the UA problem though (which can be overcome) - I decided to try a different approach and use feedparse entirely (which uses urllib internally). Problem is, feedparser doesn't store the http's response content anywhere - only the parsed results - *sigh*. My solution now is to parse and store the data I required in a simple object and pickle this to a set of cached files and compare this against hashed versions of the content. cheers James From gagsl-py2 at yahoo.com.ar Sun Jan 11 23:24:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 12 Jan 2009 02:24:03 -0200 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron escribi?: > I googled a bit, and found http://bugs.python.org/issue1355023. > It seems that this patch implemented fuller seek() for GzipFile around > November 2006 (including whence==2). > Do I misunderstand and this patch was not actually implemented, namely, > is seek(-n,2) not implemented in Python 2.5.2 ? > > The source of gzip.py on my system seems to suggest that negative seeks > are supported: The source comments are misleading: "negative seeks" means seeking backwards (towards the beginning of the file), not offset<0. The second argument to seek (whence) was added in 2.6, and only accepts 0 or 1; whence==2 isn't supported. -- Gabriel Genellina From kiliansto at gmail.com Sun Jan 11 23:26:57 2009 From: kiliansto at gmail.com (killsto) Date: Sun, 11 Jan 2009 20:26:57 -0800 (PST) Subject: Object help References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> Message-ID: > > > Thanks. That makes sense. It helps a lot. Although, you spelled color > > wrong :P. > > At this time of day you are likely to find yourself communicating with > Australians. Get used to it :-) > > Cheers, > John I was kidding. IMO, we Americans should spell color like everyone else. Heck, use the metric system too while we are at it. From prologic at shortcircuit.net.au Sun Jan 11 23:34:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jan 2009 14:34:02 +1000 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> <383bbfe1-d69f-4d2a-9c63-2021ee8221f7@v39g2000pro.googlegroups.com> Message-ID: On Mon, Jan 12, 2009 at 2:26 PM, killsto wrote: > I was kidding. IMO, we Americans should spell color like everyone > else. Heck, use the metric system too while we are at it. Yes well why don't you start up a rally and convince your brand new shiny government to catch up with the rest of the world! :) cheers James From sjmachin at lexicon.net Mon Jan 12 01:32:07 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 22:32:07 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: On Jan 12, 12:23?pm, Carl Banks wrote: > On Jan 9, 6:11?pm, John Machin wrote: > > > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > > Aivar Annamaa wrote: > > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > > >> automatically fix. Changing print to print() on the other hand is > > > > > >> easily fixed by 2to3. > > > > > > >> Cheers, > > > > > >> Chris > > > > > > > I see. > > > > > > So i gotta keep my own discipline with print() then :) > > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > > it as Python 3.x code. > > > > > > regards > > > > > ?Steve > > > > > And mind you, if you follow that route, you are programming in a > > > > mightily crippled language. > > > > How do you figure? > > > > I expect that it'd be a PITA in some cases to use the transitional > > > dialect (like getting all your Us in place), but that doesn't mean the > > > language is crippled. > > > What is this "transitional dialect"? What does "getting all your Us in > > place" mean? > > Transitional dialect is the subset of Python 2.6 that can be > translated to Python3 with 2to3 tool. I'd never seen it called "transitional dialect" before. > ?Getting all your Us in place > refers to prepending a u to strings to make them unicode objects, > which is something 2to3 users are highly advised to do to keep hassles > to a minimum. ?(Getting Bs in place would be a good idea too.) Ummm ... I'm not understanding something. 2to3 changes u"foo" to "foo", doesn't it? What's the point of going through the code and changing all non-binary "foo" to u"foo" only so that 2to3 can rip the u off again? What hassles? Who's doing the highly-advising where and with what supporting argument? "Getting Bs into place" is necessary eventually. Whether it is worthwhile trying to find these in advance, or waiting for them to be picked up at testing time is a bit of a toss-up. Let's look at this hypothetical but fairly realistic piece of 2.x code: OLE2_SIGNATURE = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE This is already syntactically valid 3.x code, and won't be changed by 2to3, but it won't work in 3.x because b"x" != "x" for all x. In this case, the cause of test failures should be readily apparent; in other cases the unexpected exception or test failure may happen at some distance. The 3.x version needs to have the effect of: OLE2_SIGNATURE = b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE So in my regional variation of the transitional dialect, this becomes: from timemachine import * OLE2_SIGNATURE = BYTES_LITERAL("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") def is_ole2_file(filepath): return open(filepath, "rb").read(8) == OLE2_SIGNATURE # NOTE: don't change "rb" ... and timemachine.py contains (amongst other things): import sys python_version = sys.version_info[:2] # e.g. version 2.4 -> (2, 4) if python_version >= (3, 0): BYTES_LITERAL = lambda x: x.encode('latin1') else: BYTES_LITERAL = lambda x: x It is probably worthwhile taking an up-front inventory of all file open () calls and [c]StringIO.StringIO() calls -- is the file being used as a text file or a binary file? If a text file, check that any default encoding is appropriate. If a binary file, ensure there's a "b" in the mode (real file) or you supply (in 3.X) an io.BytesIO() instance, not an io.StringIO() instance. > > > Steve & Cliff are talking about the rather small subset of Python that > > is not only valid syntax in both 2.x and 3.x but also has the same > > meaning in 2.x and 3.x. > > That would be a crippled language, yes. ?But I do not believe that's > what Steve and Cliff are referring to. ?Steve wrote of "running your > code through 2to3", and that was what Cliff followed up to, so I > believe they are both referring to writing valid code in 2.6 which is > able to be translated through 2to3, and then generating 3.0 code using > 2to3. ?That is not a crippled language at all, just a PITA sometimes. Uh huh; I assumed that "crippled" was being applied to the worse of the two options :-) Cheers, John From arkanes at gmail.com Mon Jan 12 01:38:20 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 00:38:20 -0600 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: <4866bea60901112238v249d6a6ajc660baca01c7607@mail.gmail.com> On Sun, Jan 11, 2009 at 9:05 PM, James Mills wrote: > On Mon, Jan 12, 2009 at 12:58 PM, Philip Semanchuk wrote: >> >> On Jan 11, 2009, at 8:59 PM, James Mills wrote: >> >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen >>> return _opener.open(url, data, timeout) >>> File "/usr/lib/python2.6/urllib2.py", line 389, in open >>> response = meth(req, response) >>> File "/usr/lib/python2.6/urllib2.py", line 502, in http_response >>> 'http', request, response, code, msg, hdrs) >>> File "/usr/lib/python2.6/urllib2.py", line 427, in error >>> return self._call_chain(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain >>> result = func(*args) >>> File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default >>> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >>> urllib2.HTTPError: HTTP Error 403: Forbidden >>>>>> >>> >>> However, that _same_ url works perfectly fine on the >>> same machine (and same network) using any of: >>> * curl >>> * wget >>> * elinks >>> * firefox >>> >>> Any helpful ideas ? >> >> The remote server doesn't like your user agent? >> >> It'd be easier to help if you post a working sample. > > That was a working sample! The "User-Agent" didn't > occur to me :) Thanks - I think that might be it. > > Why Google would deny access to services by > unknown User Agents is beyond me - especially > since in most cases User Agents strings are not > strict. If you look at the actual response text and not just the error code, you will get a clear explanation of why you were forbidden. From sjmachin at lexicon.net Mon Jan 12 01:45:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 11 Jan 2009 22:45:55 -0800 (PST) Subject: ActiveState Python Together with "Regular" Python) ((DLE) References: Message-ID: On Jan 12, 2:00?pm, "W. eWatson" wrote: > I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to > try windowpy from ActiveState. Is having both of these installed going to > cause me trouble? What is "windowpy from ActiveState"? If you mean you wanted to try the PythonWin IDE instead of IDLE, all you needed to do was go to http://sourceforge.net/projects/pywin32/ hit the big download button and make sure you get the 2.5 version (it's the default atm) and install it. From nytrokiss at gmail.com Mon Jan 12 02:34:57 2009 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 12 Jan 2009 09:34:57 +0200 Subject: template inheritance In-Reply-To: <6sv1lsF8arprU1@mid.uni-berlin.de> References: <6sv1lsF8arprU1@mid.uni-berlin.de> Message-ID: <8a6b8e350901112334l5ee8c215n6af1a1920aaaa55a@mail.gmail.com> Not always sometimes you want to show some template code (You have a blog about web dev) and sometimes you want to nest some code. On Sun, Jan 11, 2009 at 10:04 PM, Diez B. Roggisch wrote: > Alex K schrieb: > >> While building a website using template inheritance one usually does >> the following: >> >> fetch from database >> fetch from some more data from database >> ... << more required computations >> then at the end render the template with the fetched data >> >> Without template inheritance one usually does the following: >> >> fetch from database >> render this part of the site with this fetched data >> fetch some more data from the database >> render this other part of the site with the fetched data >> ... >> etc >> >> The first approach is much more elegant and leads to easier to >> maintain code. However the user will have to wait till the end of the >> fetching (long computations) before any rendering can take place. In >> the second approach however the site loads as we are fetching the data >> which is more convenient to the user. >> >> Am I correct to assume this? Is there a way to get the best of both >> worlds? Thank you. >> > > I don't think that the question of inheritance or not is really relevant > here. > > It's a matter of how the templating system is written - does it collect all > the data beforehand, or not, is it potentially using e.g. generators and so > forth. > > And of course how the programmer uses the templating system. does he fetch > all the data beforehand, or does he use lazy generation approachs - again, > e.g. generators, or callbacks. > > Besides, *usually* the 20-39Kb of a website itself aren't the problem I'd > say - loading referenced resources is much more of an issue. > > And AFAIK the render-mode matters, too. If the site is XHTML-compliant, the > browser can start the rendering once the HTML is complete - otherwise, it > might wait until the referenced resources are all loaded to calculate the > layout. > > Diez > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Zhangfang.hit at gmail.com Mon Jan 12 02:46:10 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Sun, 11 Jan 2009 23:46:10 -0800 (PST) Subject: hlep: a text search and rename question Message-ID: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> matter description: when a use an tools to do the ape to flac convert, i can use the cue file attached with ape, but the problem is the converted flac file don't name by the title in the cue file but like Track_1.flac, Track_2.flac ... , so i want to write a script to do this work, system is xp sp2, the python is 2.44, i have a plone site in this computer, that is why i want to use python to do this work. so simplify and example CDImage.cue, Track_1.flac, Track_2.flac, Track_3.flac, Track_4.flac all above files in the same folder. the cue file is just a text file like bellow: PERFORMER "Dido" TITLE "Life For Rent" FILE "Dido - Life for Rent.ape" WAVE TRACK 01 AUDIO TITLE "White Flag" PERFORMER "Dido" INDEX 01 00:00:00 TRACK 02 AUDIO TITLE "Stoned" PERFORMER "Dido" INDEX 00 04:00:03 INDEX 01 04:01:45 TRACK 03 AUDIO TITLE "Life For Rent" PERFORMER "Dido" INDEX 00 09:56:47 INDEX 01 09:56:53 TRACK 04 AUDIO TITLE "Mary's In India" PERFORMER "Dido" INDEX 01 13:37:57 the things i want to do 1. search the current folder cue file (only one cue file) contents. find the TITLE "White Flag" and get the White Flag and maybe we can save it to a var. 2. then rename the Track_1.flac to the White Flag.flac 3. search the next title TITLE "Stoned" and save ti to var. 4. then rename the Track_2.flac to the Stoned.flac. 5. do the same things to the end title. someone can give some outline, or code is more wonderful. thanks in advance. From steve at holdenweb.com Mon Jan 12 03:05:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:05:48 -0500 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 9, 6:11 pm, John Machin wrote: >> On Jan 10, 6:58 am, Carl Banks wrote: [...] >> Steve & Cliff are talking about the rather small subset of Python that >> is not only valid syntax in both 2.x and 3.x but also has the same >> meaning in 2.x and 3.x. > > That would be a crippled language, yes. But I do not believe that's > what Steve and Cliff are referring to. Steve wrote of "running your > code through 2to3", and that was what Cliff followed up to, so I > believe they are both referring to writing valid code in 2.6 which is > able to be translated through 2to3, and then generating 3.0 code using > 2to3. That is not a crippled language at all, just a PITA sometimes. > Correct. The recommended way of maintaining a dual-version code base is to paraphrase your 2.6 code in such a way that the 2to3 converter will produce correct 3.0 code that required no further attention. If you don't do this you are making a rod for your own back. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 03:09:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:09:41 -0500 Subject: Is negative seek() from EOF of a GzipFile supported on Python 2.5.2 ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494BA6@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF602494CBE@enbmail01.lsi.com> Message-ID: Gabriel Genellina wrote: > En Sun, 11 Jan 2009 08:12:27 -0200, Barak, Ron > escribi?: > >> I googled a bit, and found http://bugs.python.org/issue1355023. >> It seems that this patch implemented fuller seek() for GzipFile around >> November 2006 (including whence==2). >> Do I misunderstand and this patch was not actually implemented, >> namely, is seek(-n,2) not implemented in Python 2.5.2 ? >> >> The source of gzip.py on my system seems to suggest that negative >> seeks are supported: > > The source comments are misleading: "negative seeks" means seeking > backwards (towards the beginning of the file), not offset<0. > The second argument to seek (whence) was added in 2.6, and only accepts 0 > or 1; whence==2 isn't supported. > Specifically in the case of a zip file that means the whole entry would need to be expanded to allow such a seek to take place from the end of the file; hence there are good pragmatic reasons for the restriction. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 03:24:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 03:24:41 -0500 Subject: Object help In-Reply-To: References: <0efd62e7-d2b6-4a7b-ab8f-4722ec3a71bf@u18g2000pro.googlegroups.com> <017a6749$0$8693$c3e8da3@news.astraweb.com> Message-ID: James Mills wrote: > On Mon, Jan 12, 2009 at 9:49 AM, killsto wrote: >> Thanks. That makes sense. It helps a lot. Although, you spelled color >> wrong :P. > > color > colour > > They are both correct depending on what > country you come from :) > They are also both incorrect, depending which country you come from :P regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Mon Jan 12 03:29:17 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 00:29:17 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> Message-ID: <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> On Jan 12, 12:32?am, John Machin wrote: > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > On Jan 9, 12:36?pm, "J. Cliff Dyer" wrote: > > > > > > On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > > > > > > Aivar Annamaa wrote: > > > > > > >> As was recently pointed out in a nearly identical thread, the -3 > > > > > > >> switch only points out problems that the 2to3 converter tool can't > > > > > > >> automatically fix. Changing print to print() on the other hand is > > > > > > >> easily fixed by 2to3. > > > > > > > >> Cheers, > > > > > > >> Chris > > > > > > > > I see. > > > > > > > So i gotta keep my own discipline with print() then :) > > > > > > > Only if you don't want to run your 2.x code through 2to3 before you use > > > > > > it as Python 3.x code. > > > > > > > regards > > > > > > ?Steve > > > > > > And mind you, if you follow that route, you are programming in a > > > > > mightily crippled language. > > > > > How do you figure? > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > language is crippled. > > > > What is this "transitional dialect"? What does "getting all your Us in > > > place" mean? > > > Transitional dialect is the subset of Python 2.6 that can be > > translated to Python3 with 2to3 tool. > > I'd never seen it called "transitional dialect" before. I had hoped the context would make it clear what I was talking about. > > ?Getting all your Us in place > > refers to prepending a u to strings to make them unicode objects, > > which is something 2to3 users are highly advised to do to keep hassles > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > "foo", doesn't it? What's the point of going through the code and > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > u off again? It does a bit more than that. > What hassles? Who's doing the highly-advising where and > with what supporting argument? You add the u so the the constant will be the same data type in 2.6 as it becomes in 3.0 after applying 2to3. str and unicode objects aren't always with smooth with each other, and you have a much better chance of getting the same behavior in 2.6 and 3.0 if you use an actual unicode string in both. A example of this, though not with string constants, was posted here recently. Someone found that urllib.open() returns a bytes object in Python 3.0, which messed him up since in 2.x he was running regexp searches on the output. If he had been taking care to use only unicode objects in 2.x (in this case, by explicitly decoding the output) then it wouldn't have been an issue. > "Getting Bs into place" is necessary eventually. Whether it is > worthwhile trying to find these in advance, or waiting for them to be > picked up at testing time is a bit of a toss-up. > > Let's look at this hypothetical but fairly realistic piece of 2.x > code: > OLE2_SIGNATURE = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > > This is already syntactically valid 3.x code, and won't be changed by > 2to3, but it won't work in 3.x because b"x" != "x" for all x. In this > case, the cause of test failures should be readily apparent; in other > cases the unexpected exception or test failure may happen at some > distance. > > The 3.x version needs to have the effect of: > OLE2_SIGNATURE = b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > > So in my regional variation of the transitional dialect, this becomes: > from timemachine import * > OLE2_SIGNATURE = BYTES_LITERAL("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") > def is_ole2_file(filepath): > ? ? ?return open(filepath, "rb").read(8) == OLE2_SIGNATURE > # NOTE: don't change "rb" > ... > and timemachine.py contains (amongst other things): > import sys > python_version = sys.version_info[:2] # e.g. version 2.4 -> (2, 4) > if python_version >= (3, 0): > ? ? BYTES_LITERAL = lambda x: x.encode('latin1') > else: > ? ? BYTES_LITERAL = lambda x: x > > It is probably worthwhile taking an up-front inventory of all file open > () calls and [c]StringIO.StringIO() calls -- is the file being used as > a text file or a binary file? > If a text file, check that any default encoding is appropriate. > If a binary file, ensure there's a "b" in the mode (real file) or you > supply (in 3.X) an io.BytesIO() instance, not an io.StringIO() > instance. Right. "Taking care of the Us" refered specifically to the act of prepending Us to string constants, but figuratively it means making explicit your intentions with all string data. 2to3 can only do so much; it can't always guess whether your string usage is supposed to be character or binary. It's definitely going to be the hardest part of the transition since it's the most drastic change. Carl Banks From gandalf at shopzeus.com Mon Jan 12 03:51:55 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 09:51:55 +0100 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: <49674C57.3040908@shopzeus.com> References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> Message-ID: <496B04AB.9010409@shopzeus.com> Laszlo Nagy wrote: > Meanwhile I'm trying to turn off threads in that program one by one. I > just got this new type of error: > > Fatal Python error: PyThreadState_Delete: invalid tstate After some days, there are now answers to my question. I guess this is because nobody knows the answer. I think I need to consider this a bug in Python. Where can I post a bug report? Laszlo From notvalid2 at sbcglobal.net Mon Jan 12 05:16:16 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 12 Jan 2009 02:16:16 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: References: Message-ID: John Machin wrote: > On Jan 12, 2:00 pm, "W. eWatson" wrote: >> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to >> try windowpy from ActiveState. Is having both of these installed going to >> cause me trouble? > > What is "windowpy from ActiveState"? If you mean you wanted to try the > PythonWin IDE instead of IDLE, all you needed to do was go to > http://sourceforge.net/projects/pywin32/ hit the big download button > and make sure you get the 2.5 version (it's the default atm) and > install it. > Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. Is it possible to just disable the vanilla (IDLE) version? I may want to switch between the two. Most users of the program I'm about to modify use the vanilla version. At some point, I may want to go back to it to verify that in their world all is OK. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From michele.simionato at gmail.com Mon Jan 12 05:38:12 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 12 Jan 2009 02:38:12 -0800 (PST) Subject: debugging ignored exceptions at cleanup Message-ID: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> In some conditions (typically with threads, __del__ methods, etc) the cleanup mechanism of Python gets in trouble and some exceptions are not raised but just printed on stderr. I have an application using Paste and when I run the tests I get some annoying ignored exceptions during cleanup. Running the code with the -v option I get things like that: # cleanup[2] sqlalchemy.util # cleanup[2] sqlalchemy.sql.expression # cleanup[2] symbol # cleanup[2] urllib2 # cleanup[2] sqlalchemy.orm.query # cleanup[2] smweb.config # cleanup[2] formencode # cleanup[2] smweb.config.environment Exception exceptions.TypeError: "'NoneType' object is not callable" in at 0x26861b8> ignored Exception exceptions.TypeError: "'NoneType' object is not callable" in at 0x2598578> ignored # cleanup[2] dbhash # cleanup[2] xmlrpclib # cleanup[2] mako.pygen # cleanup[2] time # cleanup[2] paste.util.import_string # cleanup sys # cleanup __builtin__ # cleanup ints: 5096 unfreed ints in 145 out of 171 blocks # cleanup floats: 43 unfreed floats in 3 out of 4 blocks As you see, the exceptions happen during the cleanup of smweb.config.environment, which the part of code I wrote, but which has no obvious problems and imports *lots* of other stuff. Is there some way to hook in the cleanup mechanism, start a pdb and see really what is happening? I tried to trace the execution flow with the trace module but without success. There is so much code there that I am unable to track down the source of the problem. I suspect there is some __del__ method somewhere that tries to call a function which has been set to None by the cleanup mechanism, possibly from another thread, but I cannot find it. How am I supposed to debug such things? From sjmachin at lexicon.net Mon Jan 12 05:49:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 02:49:48 -0800 (PST) Subject: ActiveState Python Together with "Regular" Python) ((DLE) References: Message-ID: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> On Jan 12, 9:16?pm, "W. eWatson" wrote: > John Machin wrote: > > On Jan 12, 2:00 pm, "W. eWatson" wrote: > >> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to > >> try windowpy from ActiveState. Is having both of these installed going to > >> cause me trouble? > > > What is "windowpy from ActiveState"? If you mean you wanted to try the > > PythonWin IDE instead of IDLE, all you needed to do was go to > >http://sourceforge.net/projects/pywin32/hit the big download button > > and make sure you get the 2.5 version (it's the default atm) and > > install it. > > Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. > > Is it possible to just disable the vanilla (IDLE) version? I may want to > switch between the two. Most users of the program I'm about to modify use > the vanilla version. At some point, I may want to go back to it to verify > that in their world all is OK. I'll try again. All you need is (a) the official distribution of Python 2.5 for Windows from http://www.python.org (b) the pywin32 package from the URL I gave you. Install both. Click on Start / All Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ or your users can use IDLE or PythonWin, only one copy of Python, no conflicts. Why do you think you need to "disable" IDLE? Just don't use it. From jstroud at mbi.ucla.edu Mon Jan 12 06:13:25 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:13:25 -0800 Subject: hlep: a text search and rename question In-Reply-To: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> Message-ID: sensen wrote: > matter description: > > when a use an tools to do the ape to flac convert, i can use the cue > file attached with ape, but the problem is the converted flac file > don't name by the title in the cue file but like Track_1.flac, > Track_2.flac ... , so i want to write a script to do this work, system > is xp sp2, the python is 2.44, i have a plone site in this computer, > that is why i want to use python to do this work. > > so simplify and example > > CDImage.cue, Track_1.flac, Track_2.flac, Track_3.flac, Track_4.flac > all above files in the same folder. > > the cue file is just a text file like bellow: > > > PERFORMER "Dido" > TITLE "Life For Rent" > FILE "Dido - Life for Rent.ape" WAVE > TRACK 01 AUDIO > TITLE "White Flag" > PERFORMER "Dido" > INDEX 01 00:00:00 > TRACK 02 AUDIO > TITLE "Stoned" > PERFORMER "Dido" > INDEX 00 04:00:03 > INDEX 01 04:01:45 > TRACK 03 AUDIO > TITLE "Life For Rent" > PERFORMER "Dido" > INDEX 00 09:56:47 > INDEX 01 09:56:53 > TRACK 04 AUDIO > TITLE "Mary's In India" > PERFORMER "Dido" > INDEX 01 13:37:57 > > the things i want to do > > 1. search the current folder cue file (only one cue file) contents. > find the TITLE "White Flag" and get the White Flag and maybe we > can save it to a var. > 2. then rename the Track_1.flac to the White Flag.flac > 3. search the next title TITLE "Stoned" and save ti to var. > 4. then rename the Track_2.flac to the Stoned.flac. > 5. do the same things to the end title. > > someone can give some outline, or code is more wonderful. thanks in > advance. This isn't much work in python: import os, glob, re cue = iter(open('CDImage.cue').readlines()) titles = [] for line in cue: if line.strip().startswith('FILE'): break for line in cue: if line.strip().startswith('TITLE'): titles.append(line.split('"')[-2]) flacs = glob.glob('*.flac') flacs.sort(key=lambda f: int(re.search(r'\d+', f).group(0))) for old, new in zip(flacs, titles): os.rename(old, new) There is no error checking for properly formatted cue file, etc. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From jstroud at mbi.ucla.edu Mon Jan 12 06:17:14 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:17:14 -0800 Subject: hlep: a text search and rename question In-Reply-To: References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> Message-ID: <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> James Stroud wrote: > cue = iter(open('CDImage.cue').readlines()) It just occurred to me that this could simply be: cue = open('CDImage.cue') James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From apardon at forel.vub.ac.be Mon Jan 12 06:18:53 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Jan 2009 11:18:53 GMT Subject: change only the nth occurrence of a pattern in a string References: <0scs26-7a5.ln1@rama.fbx.proxad.net> Message-ID: On 2008-12-31, TP wrote: > Hi everybody, > > I would like to change only the nth occurence of a pattern in a string. The > problem with "replace" method of strings, and "re.sub" is that we can only > define the number of occurrences to change from the first one. > >>>> v="coucou" >>>> v.replace("o","i",2) > 'ciuciu' >>>> import re >>>> re.sub( "o", "i", v,2) > 'ciuciu' >>>> re.sub( "o", "i", v,1) > 'ciucou' > > What is the best way to change only the nth occurence (occurrence number n)? > > Why this default behavior? For the user, it would be easier to put re.sub or > replace in a loop to change the first n occurences. I would do it as follows: 1) Change the pattern n times to somethings that doesn't occur in your string 2) Change it back n-1 times 3) Change the remaining one to what you want. >>> v="coucou" >>> v.replace('o', 'O', 2).replace('O', 'o', 1).replace('O', 'i') 'couciu' -- Antoon Pardon From sjmachin at lexicon.net Mon Jan 12 06:26:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 03:26:58 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> Message-ID: <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> On Jan 12, 7:29?pm, Carl Banks wrote: > On Jan 12, 12:32?am, John Machin wrote: > > > > > > > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > > language is crippled. > > > > > What is this "transitional dialect"? What does "getting all your Us in > > > > place" mean? > > > > Transitional dialect is the subset of Python 2.6 that can be > > > translated to Python3 with 2to3 tool. > > > I'd never seen it called "transitional dialect" before. > > I had hoped the context would make it clear what I was talking about. In vain. > > > > ?Getting all your Us in place > > > refers to prepending a u to strings to make them unicode objects, > > > which is something 2to3 users are highly advised to do to keep hassles > > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > > "foo", doesn't it? What's the point of going through the code and > > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > > u off again? > > It does a bit more than that. Like what? > > > What hassles? Who's doing the highly-advising where and > > with what supporting argument? > > You add the u so the the constant will be the same data type in 2.6 as > it becomes in 3.0 after applying 2to3. ?str and unicode objects aren't > always with smooth with each other, and you have a much better chance > of getting the same behavior in 2.6 and 3.0 if you use an actual > unicode string in both. (1) Why specifically 2.6? Do you mean 2.X, or is this related to the "port to 2.6 first" theory? (2) We do assume we are starting off with working 2.X code, don't we? If we change "foo" to u"foo" and get a different answer from the 2.X code, is that still "working"? > > A example of this, though not with string constants, And therefore irrelevant. I would like to hear from someone who has actually started with working 2.x code and changed all their text-like "foo" to u"foo" [except maybe unlikely suspects like open()'s mode arg]: * how many places where the 2.x code broke and so did the 3.x code [i.e. the problem would have been detected without prepending u] * how many places where the 2.x code broke but the 3.x code didn't [i.e. prepending u did find the problem] * whether they thought it was worth the effort In the meantime I would be interested to hear from anybody with a made- up example of code where the problem would be detected (sooner | better | only) by prepending u to text-like string constants. > 2to3 can only do so > much; it can't always guess whether your string usage is supposed to > be character or binary. AFAICT it *always* guesses text rather than binary; do you have any examples where it guesses binary (rightly or wrongly)? From jstroud at mbi.ucla.edu Mon Jan 12 06:27:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:27:52 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> Message-ID: <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Roger wrote: > Hi Everyone, > > I have a behavior associated with a default binding with Tkinter > Listbox that I want to get rid of but I can't no matter if I return > "break" on the binding or unbind it directly. If you have a Listbox > where the bounding box is not completely revealed in the window that > holds it and you use the mouse to drag the list box, the contents of > the listbox will move in the X direction to reveal the area that's > hidden. After searching the internet for hours I found the behavior I > want to remove is a default binding as described here: > > http://tcltk.free.fr/man/TkCmd/listbox.php3 > > "[3] If the mouse leaves the listbox window with button 1 down, the > window scrolls away from the mouse, making information visible that > used to be off-screen on the side of the mouse. The scrolling > continues until the mouse re-enters the window, the button is > released, or the end of the listbox is reached. " > > After further searching I found that the code for this in tcl is > described here: > > http://www.openmash.org/lxr/source/library/listbox.tcl?c=tk8.3 > > 50 bind Listbox { > 51 set tkPriv(x) %x > 52 set tkPriv(y) %y > 53 tkListboxMotion %W [%W index @%x,%y] > 54 } > > Now I've found no way to successfully unbind B1-Motion from the > listbox, as I said above. Nor return "break" on receiving the event. > I do want to eventually have my own B1-Motion binding applied to the > listbox for a different reason (with add='+' if necessary). My next > step was to see if I could just unbind B1-Motion then programmatically > delete tkListboxMotion in my code but tkListboxMotion is not available > in the Tkinter source (it's part of a compiled binary I can't reach?). > > Any help would be greatly appreciated. Thanks! > Roger. You can directly send commands to the Tcl interpreter via the call method of the tk attribute of any Tkinter widget. For example: py> from Tkinter import * py> tk = Tk() py> b = Button(tk) py> b.pack() py> b.tk py> b.tk.call('bind', 'Listbox', '') '\n set tk::Priv(x) %x\n set tk::Priv(y) %y\n tk::ListboxMotion %W [%W index @%x,%y]\n' py> b.tk.call('bind', 'Listbox', '', _) '' James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From jstroud at mbi.ucla.edu Mon Jan 12 06:31:54 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 03:31:54 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: James Stroud wrote: > py> b.tk.call('bind', 'Listbox', '', _) You want b.tk.call('bind', 'Listbox', '', "") of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From n.kottiyath at gmail.com Mon Jan 12 06:52:46 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Mon, 12 Jan 2009 03:52:46 -0800 (PST) Subject: Python logging rollover Message-ID: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> Hi, I want to do a log rollover - preferably based on day; size is also Ok. I checked logging.TimedRotatingFileHandler, but I am not sure whether it will suit my purpose. Mine is a desktop application. So, everytime the machine starts, the whole logging system is reinitialized. So, in such a case, can I use TimedRotatingFileHandler? I tested it with 'midnight' option, but it did not work as I expected. Regards K From siona at chiark.greenend.org.uk Mon Jan 12 06:58:12 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Jan 2009 11:58:12 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <0kt*vWSws@news.chiark.greenend.org.uk> Grant Edwards wrote: >On 2009-01-09, Sion Arrowsmith wrote: >> Grant Edwards wrote: >>>If I were you, I'd try mmap()ing the file instead of reading it >>>into string objects one chunk at a time. >> You've snipped the bit further on in that sentence where the >> OP says that the file of interest is 2GB. Do you still want to >> try mmap'ing it? >Sure. The larger the file, the more you gain from mmap'ing it. >2GB should easily fit within the process's virtual memory >space. Assuming you're in a 64bit world. Me, I've only got 2GB of address space available to play in -- mmap'ing all of it out of the question. But I supposed that mmap'ing it chunk at a time instead of reading chunk at a time might be worth considering. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From Zhangfang.hit at gmail.com Mon Jan 12 07:03:43 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 04:03:43 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> Message-ID: <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> On Jan 12, 8:17?pm, James Stroud wrote: > James Stroud wrote: > > cue = iter(open('CDImage.cue').readlines()) > > It just occurred to me that this could simply be: > > cue = open('CDImage.cue') > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com Thanks you James, i will check it now. thanks again for your kindness help. From lists at cheimes.de Mon Jan 12 07:05:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 13:05:03 +0100 Subject: Problem with -3 switch In-Reply-To: <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: John Machin schrieb: > And therefore irrelevant. No, Carl is talking about the very same issue. > I would like to hear from someone who has actually started with > working 2.x code and changed all their text-like "foo" to > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > * how many places where the 2.x code broke and so did the 3.x code > [i.e. the problem would have been detected without prepending u] > * how many places where the 2.x code broke but the 3.x code didn't > [i.e. prepending u did find the problem] > * whether they thought it was worth the effort Perhaps you also like to hear from a developer who has worked on Python 3.0 itself and who has done lots of work with internationalized applications. If you want to get it right you must * decode incoming text data to unicode as early as possible * use unicode for all internal text data * encode outgoing unicode as late as possible. where incoming data is read from the file system, database, network etc. This rule applies not only to Python 3.0 but to *any* application written in *any* languate. The urlopen example is a very good example for the issue. The author didn't think of decoding the incoming bytes to unicode. In Python 2.x it works fine as long as the site contains ASCII only. In Python 3.0 however an error is raised because binary data is no longer implicitly converted to unicode. Christian From sjmachin at lexicon.net Mon Jan 12 07:20:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 04:20:12 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> On Jan 12, 11:05?pm, Christian Heimes wrote: > John Machin schrieb: > > > And therefore irrelevant. > > No, Carl is talking about the very same issue. > > > I would like to hear from someone who has actually started with > > working 2.x code and changed all their text-like "foo" to > > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > > * how many places where the 2.x code broke and so did the 3.x code > > [i.e. the problem would have been detected without prepending u] > > * how many places where the 2.x code broke but the 3.x code didn't > > [i.e. prepending u did find the problem] > > * whether they thought it was worth the effort > > Perhaps you also like to hear from a developer who has worked on Python > 3.0 itself and who has done lots of work with internationalized > applications. If you want to get it right you must > > * decode incoming text data to unicode as early as possible > * use unicode for all internal text data > * encode outgoing unicode as late as possible. > > where incoming data is read from the file system, database, network etc. > > This rule applies not only to Python 3.0 but to *any* application > written in *any* languate. The above is a story with which I'm quite familiar. However it is *not* the issue!! The issue is why would anyone propose changing a string constant "foo" in working 2.x code to u"foo"? > The urlopen example is a very good example > for the issue. The author didn't think of decoding the incoming bytes to > unicode. In Python 2.x it works fine as long as the site contains ASCII > only. In Python 3.0 however an error is raised because binary data is no > longer implicitly converted to unicode. All very true but nothing to do with the "foo" -> u"foo" issue. Somebody please come up with an example of how changing "foo" to u"foo" could help a port from 2.x working code to a single codebase that supports 2.x and 2to3ed 3.x. From googler.1.webmaster at spamgourmet.com Mon Jan 12 07:22:07 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 12 Jan 2009 04:22:07 -0800 (PST) Subject: Python 2.6.1 @executable_path References: <105a99a2-838d-4a77-92de-2239d90733ee@t39g2000prh.googlegroups.com> <49691785$0$25150$9b622d9e@news.freenet.de> <664f0f5c-0852-4130-a094-3bf66c191c29@a26g2000prf.googlegroups.com> <1443a10d-1def-4ee6-a880-20b38c9d9b43@s1g2000prg.googlegroups.com> Message-ID: Hi! Woow, thanks. The unix command install_name_tool solved my problem. Thanks a lot. From heston.james at coldbeans.co.uk Mon Jan 12 07:24:23 2009 From: heston.james at coldbeans.co.uk (Heston James - Cold Beans) Date: Mon, 12 Jan 2009 12:24:23 -0000 Subject: strange dict issue Message-ID: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> Ok, this feels like a horribly noobish question to ask guys but I can't figure this one out. I have code which looks like this: print this_config[1] this_adapter_config["name"] = this_config[1]["NAME"] Now, the print statement gives me the following: {'value': 'Route66', 'key': 'NAME'} Yet when the second line of my code throws an error saying the key 'NAME' doesn't exist. Any ideas on what's going on, seems quite senseless to me!? Thanks, Heston -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.reginato at gmail.com Mon Jan 12 07:32:35 2009 From: andrea.reginato at gmail.com (Andrea Reginato) Date: Mon, 12 Jan 2009 04:32:35 -0800 (PST) Subject: Encoding Title mail Message-ID: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some mails from a google account and save the attached files. All works fine, but when a tile has some letters with accents (like ?????) I read a string like this. =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? _=E9*=A7=B0=E7;:=5F_test_chars?= I tried to use the string.decode(ISO-8859-1) function, but nothing change. I'm newbie into python, so I wanted to ask if you know how I could solve this problem, as with a google search i didn't find the solution. Thanks a lot. From sturlamolden at yahoo.no Mon Jan 12 07:50:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jan 2009 04:50:49 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> Message-ID: <7c6d30a3-36fb-4a0c-934e-3f08b09a3159@s1g2000prg.googlegroups.com> On Jan 9, 6:41 pm, Sion Arrowsmith wrote: > You've snipped the bit further on in that sentence where the OP > says that the file of interest is 2GB. Do you still want to try > mmap'ing it? Python's mmap object does not take an offset parameter. If it did, one could mmap smaller portions of the file. From siona at chiark.greenend.org.uk Mon Jan 12 07:52:32 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Jan 2009 12:52:32 +0000 (GMT) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> Message-ID: <8Fl*e9Sws@news.chiark.greenend.org.uk> In case the cancel didn't get through: Sion Arrowsmith wrote: >Grant Edwards wrote: >>2GB should easily fit within the process's virtual memory >>space. >Assuming you're in a 64bit world. Me, I've only got 2GB of address >space available to play in -- mmap'ing all of it out of the question. And today's moral is: try it before posting. Yeah, I can map a 2GB file no problem, complete with associated 2GB+ allocated VM. The addressing is clearly not working how I was expecting it too. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From benjamin.kaplan at case.edu Mon Jan 12 08:04:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 12 Jan 2009 08:04:58 -0500 Subject: strange dict issue In-Reply-To: <-4440361288562330204@unknownmsgid> References: <-4440361288562330204@unknownmsgid> Message-ID: On Mon, Jan 12, 2009 at 7:24 AM, Heston James - Cold Beans < heston.james at coldbeans.co.uk> wrote: > Ok, this feels like a horribly noobish question to ask guys but I can't > figure this one out. > > > > I have code which looks like this: > > > > print this_config[1] > > > > this_adapter_config[*"name"*] = this_config[1][*"NAME"*] > > > > Now, the print statement gives me the following: > > > > {'value': 'Route66', 'key': 'NAME'} > > > Yet when the second line of my code throws an error saying the key 'NAME' > doesn't exist. > > > > Any ideas on what's going on, seems quite senseless to me!? > > > > Thanks, > > > > Heston > A dict stores key/value pairs. When you see the print of the dict, it shows you {key1:value1, key2:value2}. So your dict has two keys ('value' and 'key') that map to two values ('Route66' and 'Name' respectively). 'Name' is a value in the dict, not a key, so you can't use that syntax to get it.. In order for this code to work, the dictionary would have to be {'NAME' : 'Route66'} or you would have to use this_config[1]['value'] > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary at byoteki.com Mon Jan 12 08:05:47 2009 From: gary at byoteki.com (Gary M. Josack) Date: Mon, 12 Jan 2009 08:05:47 -0500 Subject: strange dict issue In-Reply-To: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> References: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> Message-ID: <496B402B.6010803@byoteki.com> Heston James - Cold Beans wrote: > > Ok, this feels like a horribly noobish question to ask guys but I > can?t figure this one out. > > I have code which looks like this: > > print this_config[1] > > this_adapter_config[/"name"/] = this_config[1][/"NAME"/] > > Now, the print statement gives me the following: > > {'value': 'Route66', 'key': 'NAME'} > > Yet when the second line of my code throws an error saying the key > ?NAME? doesn?t exist. > > Any ideas on what?s going on, seems quite senseless to me!? > > Thanks, > > Heston > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > 'NAME' is the value, and 'key' is the key. Your dictionary has two keys mapped to two values: 'value' -> 'Route66' 'key' -> 'NAME' You need to lookup the values by their key. Does that make sense? Thanks, Gary M. Josack From lists at cheimes.de Mon Jan 12 08:06:29 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 14:06:29 +0100 Subject: Problem with -3 switch In-Reply-To: <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: >> Perhaps you also like to hear from a developer who has worked on Python >> 3.0 itself and who has done lots of work with internationalized >> applications. If you want to get it right you must >> >> * decode incoming text data to unicode as early as possible >> * use unicode for all internal text data >> * encode outgoing unicode as late as possible. >> >> where incoming data is read from the file system, database, network etc. >> >> This rule applies not only to Python 3.0 but to *any* application >> written in *any* languate. > > The above is a story with which I'm quite familiar. However it is > *not* the issue!! The issue is why would anyone propose changing a > string constant "foo" in working 2.x code to u"foo"? Do I really have to repeat "use unicode for all internal text data"? "foo" and u"foo" are two totally different things. The former is a byte sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just happens that "foo" and u"foo" are equal in Python 2.x because "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is unequal to "foo". Christian From bj_666 at gmx.net Mon Jan 12 08:06:56 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 12 Jan 2009 13:06:56 GMT Subject: Encoding Title mail References: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> Message-ID: <6t0tjgF8gel1U1@mid.uni-berlin.de> On Mon, 12 Jan 2009 04:32:35 -0800, Andrea Reginato wrote: > Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some > mails from a google account and save the attached files. All works fine, > but when a tile has some letters with accents (like ?????) I read a > string like this. > > =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? > _=E9*=A7=B0=E7;:=5F_test_chars?= > > I tried to use the string.decode(ISO-8859-1) function, but nothing > change. > I'm newbie into python, so I wanted to ask if you know how I could solve > this problem, as with a google search i didn't find the solution. Look into the `email` package in the standard library. Ciao, Marc 'BlackJack' Rintsch From raj.indian.08 at gmail.com Mon Jan 12 08:10:45 2009 From: raj.indian.08 at gmail.com (RajNewbie) Date: Mon, 12 Jan 2009 05:10:45 -0800 (PST) Subject: Python tricks Message-ID: Hi, My code has a lot of while loops of the following format: while True: ... if : break The danger with such a code is that it might go to an infinite loop - if the never occurs. Is there a way - a python trick - to have a check such that if the loop goes for more than x number of steps, it will cause an exception? I do understand that we can use the code like - i = 0 while True: i++ if i > 200: raise infinite_Loop_Exception ... if : break But I am not very happy with this code for 3 reasons 1. Verbosity (i=0 and i++) which doesnt add to the logic 2. The loop now has dual focus. - incrementing i, etc. 3. A person looks into the code and thinks 'i' has special significance. His/her mind will be focused on not the actual reason for the loop. The solution that I had in mind is: while True: ... if : break if inifinte_loop(): raise infiinte_loop_exception Wherein infinite_loop is a generator, which returns true if i > 200 def infinite_loop(): i = 0 while i < 200: i++ yield False yield True Could somebody let me know whether this is a good option? One of my main worries is - what will happen if I call this same procedure from another loop? Will it start again from 0 or will it again start from my previous stored i? i.e. def big_proc: while True: ... if infinite_loop: raise while True: ... if infinite_loop: raise In such a case, will we run it 200 times both the times or not? Could someone chip in with other suggestions? From heston.james at coldbeans.co.uk Mon Jan 12 08:11:47 2009 From: heston.james at coldbeans.co.uk (Heston James - Cold Beans) Date: Mon, 12 Jan 2009 13:11:47 -0000 Subject: strange dict issue In-Reply-To: <496B402B.6010803@byoteki.com> References: <016701c974b0$b5f70260$21e50720$@james@coldbeans.co.uk> <496B402B.6010803@byoteki.com> Message-ID: <01b601c974b7$52cd6740$f86835c0$@james@coldbeans.co.uk> Gary, Ben, Thanks for your replies, that makes perfect sense. This is a dict generated by the ZSI web service library and looks different to what I expect. :-( I'll work on your suggestions, thanks again for your help. Heston From sturlamolden at yahoo.no Mon Jan 12 08:13:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jan 2009 05:13:26 -0800 (PST) Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> Message-ID: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> On Jan 12, 1:52 pm, Sion Arrowsmith wrote: > And today's moral is: try it before posting. Yeah, I can map a 2GB > file no problem, complete with associated 2GB+ allocated VM. The > addressing is clearly not working how I was expecting it too. The virtual memory space of a 32 bit process is 4 GB. From bieffe62 at gmail.com Mon Jan 12 08:14:35 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 12 Jan 2009 05:14:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> Message-ID: <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> On 12 Gen, 00:02, Paul Rubin wrote: > Carl Banks writes: > > and where it was manipulated for that matter. > > > This criticism is completely unfair. ?Instance variables have to be > > manipulated somewhere, and unless your object is immutable, that is > > going to happen outside of __init__. ?That's true in Java, C++, and > > pretty much any other language. > > The criticism is very valid. ?Some languages do support immutable > variables (e.g. "final" declarations in Java, "const" in C++, or > universal immutability in pure functional languages) and they do so > precisely for the purpose of taming the chaos of uncontrolled > mutation. ?It would be great if Python also supported immutability. > > > I'm not going to argue that this doesn't hurt readability, because it > > does (though not nearly as much as you claim). ?But there are other > > considerations, and in this case the flexibility of defining > > attributes outside __init__ is worth the potential decrease in > > readability. > > There are cases where this is useful but they're not terribly common. > I think it would be an improvement if creating new object attributes > was by default not allowed outside the __init__ method. ?In the cases > where you really do want to create new attributes elsewhere, you'd > have to explicitly enable this at instance creation time, for example > by inheriting from a special superclass: > > ? ?class Foo (DynamicAttributes, object): pass > You cannot do that, but you can establish a fixed set of attributes by defining the __slot__ class variable. Ciao ----- FB From ferdinandsousa at gmail.com Mon Jan 12 08:26:40 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Mon, 12 Jan 2009 18:56:40 +0530 Subject: strange dict issue Message-ID: James First off, the computer is always right :-) > {'value': 'Route66', 'key': 'NAME'} > > > > Yet when the second line of my code throws an error saying the key 'NAME' > doesn't exist. > If you look carefully the key NAME indeed does not exist. The dictionary contains 2 key-value pairs. This should clear things out: *key * *value *'value' 'Route66' 'key' 'NAME' Get it? NAME is a value, not a key. You have used the string 'key' itself as a dictionary key. My advice would be to not use such conflicting names. Regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Mon Jan 12 08:31:26 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 12 Jan 2009 14:31:26 +0100 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <7c6d30a3-36fb-4a0c-934e-3f08b09a3159@s1g2000prg.googlegroups.com> Message-ID: <871vv87is1.fsf@mulj.homelinux.net> sturlamolden writes: > On Jan 9, 6:41 pm, Sion Arrowsmith > wrote: > >> You've snipped the bit further on in that sentence where the OP >> says that the file of interest is 2GB. Do you still want to try >> mmap'ing it? > > Python's mmap object does not take an offset parameter. If it did, one > could mmap smaller portions of the file. As of 2.6 it does, but that might not be of much use if you're using 2.5.x or earlier. If you speak Python/C and really need offset, you could backport the mmap module from 2.6 and compile it under a different name for 2.5. From bignose+hates-spam at benfinney.id.au Mon Jan 12 08:37:51 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 13 Jan 2009 00:37:51 +1100 Subject: Python tricks References: Message-ID: <87ab9wejbk.fsf@benfinney.id.au> RajNewbie writes: > Could someone chip in with other suggestions? Set up an iterable that will end under the right conditions. Then, iterate over that with ?for foo in that_iterable?. This idiom is usually far more expressive than any tricks with ?while? loops and ?break? statements. For tools to work with that can give you such an iterable without needing to make one from scratch, try the following and use the one that is most suitable to the problem at hand: * list * dict * list comprehension * generator expression * generator function * functions from the ?itertools? module -- \ ?Too many Indians spoil the golden egg.? ?Sir Joh | `\ Bjelke-Petersen | _o__) | Ben Finney From sjmachin at lexicon.net Mon Jan 12 08:38:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 05:38:51 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: On Jan 13, 12:06?am, Christian Heimes wrote: > >> Perhaps you also like to hear from a developer who has worked on Python > >> 3.0 itself and who has done lots of work with internationalized > >> applications. If you want to get it right you must > > >> * decode incoming text data to unicode as early as possible > >> * use unicode for all internal text data > >> * encode outgoing unicode as late as possible. > > >> where incoming data is read from the file system, database, network etc. > > >> This rule applies not only to Python 3.0 but to *any* application > >> written in *any* languate. > > > The above is a story with which I'm quite familiar. However it is > > *not* the issue!! The issue is why would anyone propose changing a > > string constant "foo" in working 2.x code to u"foo"? > > Do I really have to repeat "use unicode for all internal text data"? > > "foo" and u"foo" are two totally different things. The former is a byte > sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just > happens that "foo" and u"foo" are equal in Python 2.x because > "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is > unequal to "foo". > Again, all very true, but irrelevant. b"foo" is *not* involved. You're ignoring the effect of 2to3: Original 2.x code: assert "foo" == u"foo" # works output from 2to3: assert "foo" == "foo" # works Original 2.x code with u prepended: assert u"foo" == u"foo" # works output from 2to3: assert "foo" == "foo" # works I say again, show me a case of working 2.5 code where prepending u to an ASCII string constant that is intended to be used in a text context is actually worth the keystrokes. From Zhangfang.hit at gmail.com Mon Jan 12 08:41:07 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 05:41:07 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> Message-ID: both above works well, but a problem is renamed file is without filename extension. only change to the title. for example, the origin file is track_1.flac, after run the script i want it to for example, White Flag.flac, but now it change to White Flag without extension. could you do a favor to fix it. thank you. From http Mon Jan 12 08:45:13 2009 From: http (Paul Rubin) Date: 12 Jan 2009 05:45:13 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> Message-ID: <7x1vv83afq.fsf@ruckus.brouhaha.com> bieffe62 at gmail.com writes: > > ? ?class Foo (DynamicAttributes, object): pass > > > You cannot do that, but you can establish a fixed set of attributes by > defining the __slot__ class variable. That is not what __slot__ is for. From Maksim.Kasimov at gmail.com Mon Jan 12 08:45:33 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Mon, 12 Jan 2009 05:45:33 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> Message-ID: <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> On 10 ???, 23:40, John Machin wrote: > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > > Hi all! > > > I had touch with some different python behavior: I was tried to write > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > it gives expected result: > > > >>> open("test", "w").write('before\x1aafter') > > >>> open('test').read() > > > 'before\x1aafter' > > > but for my WinXP box, it gives some strange: > > > >>> open("test", "w").write('before\x1aafter') > > >>> open('test').read() > > > 'before' > > > Here I can write all symbols, but not read. > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > Why is it so and is it possible to fix it? > > You've already got two good answers, but this might add a little more > explanation: > > You will aware that in Windows Command Prompt, to exit the interactive > mode of Python (among others), you need to type Ctrl-Z ... > > | C:\junk>python > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > (Intel)] on > win32 > | Type "help", "copyright", "credits" or "license" for more > information. > | >>> problem = '\x1a' > | >>> ord(problem) > | 26 > | >>> # What is the 26th letter of the English/ASCII alphabet? > | ... > | >>> ^Z > | > | C:\junk> > > HTH, > John Hi John, I agree - those two answers are really good. Thanks to Mel and Marc. I'm sorry if my stupid question was annoyed you. -- Maksim From python.list at tim.thechases.com Mon Jan 12 08:51:17 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jan 2009 07:51:17 -0600 Subject: Python tricks In-Reply-To: References: Message-ID: <496B4AD5.2010900@tim.thechases.com> > My code has a lot of while loops of the following format: > while True: > ... > if : break > > The danger with such a code is that it might go to an infinite loop > - if the never occurs. > Is there a way - a python trick - to have a check such that if the > loop goes for more than x number of steps, it will cause an exception? > > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons > 1. Verbosity (i=0 and i++) which doesnt add to the logic > 2. The loop now has dual focus. - incrementing i, etc. > 3. A person looks into the code and thinks 'i' > has special significance. His/her mind will be focused on not the > actual reason for the loop. My first thought would be to simply not use "while True": INFINITE_LOOP_COUNT = 200 for _ in xrange(INFINITE_LOOP_COUNT): do_something() if : break else: raise InfiniteLoopException > The solution that I had in mind is: > while True: > ... > if : break > if inifinte_loop(): raise infiinte_loop_exception > > Wherein infinite_loop is a generator, which returns true if i > 200 > def infinite_loop(): > i = 0 > while i < 200: > i++ > yield False > yield True > > Could somebody let me know whether this is a good option? To do this, you'd need to do the same sort of thing as you do with your i/i++ variable: i = infinite_loop() while True: ... if : break if i.next(): raise InfiniteLoopException which doesn't gain much, and makes it a whole lot more confusing. > Could someone chip in with other suggestions? As an aside: the phrase is "chime in"[1] (to volunteer suggestions) "Chip in"[2] usually involves contributing money to a common fund ("care to chip in $10 for Sally's wedding gift from the office?" where the pool of money would then be used to buy one large/expensive gift for Sally) -tkc [1] http://www.thefreedictionary.com/chime+in [2] http://www.english-test.net/forum/ftopic1768.html From sjmachin at lexicon.net Mon Jan 12 09:00:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 06:00:16 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> Message-ID: <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> On Jan 13, 12:45?am, "sim.sim" wrote: > On 10 ???, 23:40, John Machin wrote: > > > > > > > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > Hi all! > > > > I had touch with some different python behavior: I was tried to write > > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > > it gives expected result: > > > > >>> open("test", "w").write('before\x1aafter') > > > >>> open('test').read() > > > > 'before\x1aafter' > > > > but for my WinXP box, it gives some strange: > > > > >>> open("test", "w").write('before\x1aafter') > > > >>> open('test').read() > > > > 'before' > > > > Here I can write all symbols, but not read. > > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > > Why is it so and is it possible to fix it? > > > You've already got two good answers, but this might add a little more > > explanation: > > > You will aware that in Windows Command Prompt, to exit the interactive > > mode of Python (among others), you need to type Ctrl-Z ... > > > | C:\junk>python > > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > > (Intel)] on > > win32 > > | Type "help", "copyright", "credits" or "license" for more > > information. > > | >>> problem = '\x1a' > > | >>> ord(problem) > > | 26 > > | >>> # What is the 26th letter of the English/ASCII alphabet? > > | ... > > | >>> ^Z > > | > > | C:\junk> > > > HTH, > > John > > Hi John, > > I agree - those two answers are really good. Thanks to Mel and Marc. > I'm sorry if my stupid question was annoyed you. I didn't think your question was stupid. Stupid was (a) CP/M recording file size as number of 128-byte sectors, forcing the use of an in-band EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF decades after people stopped writing Ctrl-Z at the end of text files. And I wasn't annoyed either ... I was merely adding the information that Ctrl-Z and '\x1a' were the same thing; many people don't make the connection. Cheers, John From raj.indian.08 at gmail.com Mon Jan 12 09:01:46 2009 From: raj.indian.08 at gmail.com (RajNewbie) Date: Mon, 12 Jan 2009 06:01:46 -0800 (PST) Subject: Python tricks References: Message-ID: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> On Jan 12, 6:51?pm, Tim Chase wrote: > > ? ?My code has a lot of while loops of the following format: > > ? ?while True: > > ? ? ?... > > ? ? ?if : break > > > ? ?The danger with such a code is that it might go to an infinite loop > > - if the never occurs. > > ? ?Is there a way - a python trick - to have a check such that if the > > loop goes for more than x number of steps, it will cause an exception? > > > ? ?I do understand that we can use the code like - > > ? ?i = 0 > > ? ?while True: > > ? ? ?i++ > > ? ? ?if i > 200: raise infinite_Loop_Exception > > ? ? ?... > > ? ? ?if : break > > > ? ?But I am not very happy with this code for 3 reasons > > ? ?1. Verbosity (i=0 and i++) which doesnt add to the logic > > ? ?2. The loop now has dual focus. - incrementing i, etc. > > ? ?3. ? A person looks into the code and thinks 'i' > > has special significance. His/her mind will be focused on not the > > actual reason for the loop. > > My first thought would be to simply not use "while True": > > ? ?INFINITE_LOOP_COUNT = 200 > ? ?for _ in xrange(INFINITE_LOOP_COUNT): > ? ? ?do_something() > ? ? ?if : break > ? ?else: > ? ? ?raise InfiniteLoopException > > > ? ?The solution that I had in mind is: > > ? ?while True: > > ? ? ?... > > ? ? ?if : break > > ? ? ?if inifinte_loop(): raise infiinte_loop_exception > > > ? Wherein infinite_loop is a generator, which returns true if i > 200 > > ? def infinite_loop(): > > ? ? ?i = 0 > > ? ? ?while i < 200: > > ? ? ? ? ?i++ > > ? ? ? ? ?yield False > > ? ? ?yield True > > > Could somebody let me know whether this is a good option? > > To do this, you'd need to do the same sort of thing as you do > with your i/i++ variable: > > ? ?i = infinite_loop() > ? ?while True: > ? ? ?... > ? ? ?if : break > ? ? ?if i.next(): raise InfiniteLoopException > > which doesn't gain much, and makes it a whole lot more confusing. > > > Could someone chip in with other suggestions? > > As an aside: ?the phrase is "chime in"[1] (to volunteer > suggestions) "Chip in"[2] usually involves contributing money to > a common fund ("care to chip in $10 for Sally's wedding gift from > the office?" ?where the pool of money would then be used to buy > one large/expensive gift for Sally) > > -tkc > > [1]http://www.thefreedictionary.com/chime+in > > [2]http://www.english-test.net/forum/ftopic1768.html Thank you very much Tim. I agree on all counts - esp the fact that my suggestion is very confusing + (chime in part too :) ). But, I still feel it would be much more aesthetically pleasing if I can call a single procedure like if infinite_loop() -> to do the same. Is it somehow possible? - say by using static variables, iterators -- anything? From http Mon Jan 12 09:02:52 2009 From: http (Paul Rubin) Date: 12 Jan 2009 06:02:52 -0800 Subject: Python tricks References: Message-ID: <7x8wpgei5v.fsf@ruckus.brouhaha.com> RajNewbie writes: > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons I prefer: from itertools import count for i in count(): if i > 200: raise infinite_Loop_Exception ... You could also use: for i in xrange(200): ... else: raise infinite_Loop_Exception The "else" clause runs only if no break statement is executed. From psaffrey at googlemail.com Mon Jan 12 09:04:11 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 06:04:11 -0800 (PST) Subject: mod_python: delay in files changing after alteration References: <3a80cbe2-0506-4f8a-98bc-67c487af6ab1@l33g2000pri.googlegroups.com> <80e89ae6-af47-420b-8d25-63966f92891a@o40g2000prn.googlegroups.com> Message-ID: On 6 Jan, 23:31, Graham Dumpleton wrote: > Thus, any changes to modules/packages installed on sys.path require a > full restart of Apache to ensure they are loaded by all Apache child > worker processes. > That will be it. I'm pulling in some libraries of my own from elsewhere, which are still being modified to accommodate the web app. These are the changes that are causing the problems. An Apache restart isn't too onerous - I'll just start doing that. Thanks, Peter From sjmachin at lexicon.net Mon Jan 12 09:10:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 06:10:58 -0800 (PST) Subject: Python tricks References: Message-ID: <20045ef5-8183-44e8-a3f9-c98ca2cdf968@q30g2000prq.googlegroups.com> On Jan 13, 12:51?am, Tim Chase took a walk on the OT side: > > Could someone chip in with other suggestions? > > As an aside: ?the phrase is "chime in"[1] (to volunteer > suggestions) "Chip in"[2] usually involves contributing money to > a common fund ("care to chip in $10 for Sally's wedding gift from > the office?" ?where the pool of money would then be used to buy > one large/expensive gift for Sally) > > [1]http://www.thefreedictionary.com/chime+in > [2]http://www.english-test.net/forum/ftopic1768.html All rather locale-dependent; see e.g. http://www.answers.com/topic/chip-in From roy at panix.com Mon Jan 12 09:22:41 2009 From: roy at panix.com (Roy Smith) Date: Mon, 12 Jan 2009 09:22:41 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> Message-ID: In article <7x1vv83afq.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > bieffe62 at gmail.com writes: > > > ? ?class Foo (DynamicAttributes, object): pass > > > > > You cannot do that, but you can establish a fixed set of attributes by > > defining the __slot__ class variable. > > That is not what __slot__ is for. Right. And tuples are not immutable lists (ducking and covering). From mrkafk at gmail.com Mon Jan 12 09:36:29 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 15:36:29 +0100 Subject: Egg deinstallation Message-ID: Hello everyone, I googled and googled and can't seem to find the definitive answer: how to *properly* deinstall egg? Just delete the folder and/or .py and .pyc files from Lib/site-packages? Would that break anything in Python installation or not? Regards, mk From psaffrey at googlemail.com Mon Jan 12 09:37:35 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 06:37:35 -0800 (PST) Subject: subprocess.Popen stalls Message-ID: I'm building a bioinformatics application using the ipcress tool: http://www.ebi.ac.uk/~guy/exonerate/ipcress.man.html I'm using subprocess.Popen to execute ipcress, which takes a group of files full of DNA sequences and returns some analysis on them. Here's a code fragment: cmd = "/usr/bin/ipcress ipcresstmp.txt --sequence /home/pzs/genebuilds/ human/*.fasta" print "checking with ipcress using command", cmd p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) retcode = p.wait() if retcode != 0: print "ipcress failed with error code:", retcode raise Exception output = p.stdout.read() If I run the command at my shell, it finishes successfully. It takes 30 seconds - it uses 100% of one core and several hundred MB of memory during this time. The output is 220KB of text. However, running it through Python as per the above code, it stalls after 5 seconds not using any processor at all. I've tried leaving it for a few minutes with no change. If I interrupt it, it's at the "retcode = p.wait()" line. I've tried making the bufsize really large and that doesn't seem to help. I'm a bit stuck - any suggestions? This same command has worked fine on other ipcress runs. This one might generate more output than the others, but 220KB isn't that much, is it? Peter Peter From deets at nospam.web.de Mon Jan 12 09:44:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 12 Jan 2009 15:44:07 +0100 Subject: Egg deinstallation References: Message-ID: <6t139nF8ip4nU1@mid.uni-berlin.de> mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? It depends on how you installed it. If it is done via setuptools/easy_install, you should also clean up the site-packages/easy-install.pth file. Diez From exarkun at divmod.com Mon Jan 12 09:50:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 12 Jan 2009 09:50:27 -0500 Subject: subprocess.Popen stalls In-Reply-To: Message-ID: <20090112145027.9754.1144898156.divmod.quotient.1254@henry.divmod.com> On Mon, 12 Jan 2009 06:37:35 -0800 (PST), "psaffrey at googlemail.com" wrote: >I'm building a bioinformatics application using the ipcress tool: > >http://www.ebi.ac.uk/~guy/exonerate/ipcress.man.html > >I'm using subprocess.Popen to execute ipcress, which takes a group of >files full of DNA sequences and returns some analysis on them. Here's >a code fragment: > >cmd = "/usr/bin/ipcress ipcresstmp.txt --sequence /home/pzs/genebuilds/ >human/*.fasta" >print "checking with ipcress using command", cmd >p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) >retcode = p.wait() >if retcode != 0: > print "ipcress failed with error code:", retcode > raise Exception >output = p.stdout.read() > >If I run the command at my shell, it finishes successfully. It takes >30 seconds - it uses 100% of one core and several hundred MB of memory >during this time. The output is 220KB of text. > >However, running it through Python as per the above code, it stalls >after 5 seconds not using any processor at all. I've tried leaving it >for a few minutes with no change. If I interrupt it, it's at the >"retcode = p.wait()" line. > >I've tried making the bufsize really large and that doesn't seem to >help. I'm a bit stuck - any suggestions? This same command has worked >fine on other ipcress runs. This one might generate more output than >the others, but 220KB isn't that much, is it? You have to read the output. Otherwise, the process's stdout fills up and its write attempt eventually blocks, preventing it from continuing. If you use Twisted's process API instead, the reading will be done for you (without any of the race conditions that are likely when using the subprocess module), and things will probably "just work". Jean-Paul From Zhangfang.hit at gmail.com Mon Jan 12 09:52:20 2009 From: Zhangfang.hit at gmail.com (sensen) Date: Mon, 12 Jan 2009 06:52:20 -0800 (PST) Subject: hlep: a text search and rename question References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> Message-ID: <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> On Jan 12, 10:41?pm, sensen wrote: > both above works well, but a problem is renamed file is without > filename extension. > > only change to the title. > > for example, the origin file is track_1.flac, after run the script i > want it to for example, White Flag.flac, but now it change to White > Flag without extension. > > could you do a favor to fix it. thank you. fixed it, i check the reference of python. the last line from os.rename(old, new) changed to os.rename(old, new+'.flac') thanks, now i still try to read the reference of python. i want to the script can know what file it will open. in other words, the script maybe first do a search, and get the exactly file name of the cue type file in the folder, then open it. From mrkafk at gmail.com Mon Jan 12 10:19:32 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:19:32 +0100 Subject: Egg deinstallation In-Reply-To: <6t139nF8ip4nU1@mid.uni-berlin.de> References: <6t139nF8ip4nU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: Thanks, Diez. From mrkafk at gmail.com Mon Jan 12 10:21:11 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:21:11 +0100 Subject: Compressed vs uncompressed eggs Message-ID: Hello everyone, Are there *good* reasons to use uncompressed eggs? Is there a, say, performance penalty in using compressed eggs? Regards, mk From mrkafk at gmail.com Mon Jan 12 10:33:34 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 16:33:34 +0100 Subject: subprocess.Popen stalls In-Reply-To: References: Message-ID: psaffrey at googlemail.com wrote: > p = Popen(cmd, shell=True, bufsize=100, stdout=PIPE, stderr=PIPE) > output = p.stdout.read() Better use communicate() method: standardoutputstr, standarderrorstr = subprocess.communicate(...) Never had any problem with subprocesses when using subprocess module in this manner (well it's possible that standardoutputstr and/or standarderrorstr fill up the memory, you get the idea). Regards, mk From deets at nospam.web.de Mon Jan 12 10:35:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 12 Jan 2009 16:35:20 +0100 Subject: Compressed vs uncompressed eggs References: Message-ID: <6t169oF8j6vnU1@mid.uni-berlin.de> mk wrote: > Hello everyone, > > Are there *good* reasons to use uncompressed eggs? Plenty. Mostly that some things simply don't work in compressed eggs. See the zipsafe-flag in setuptools-docs. > Is there a, say, performance penalty in using compressed eggs? Not that it matters I'd say - only if you had an application that imports a lot & runs very short time. Diez From notvalid2 at sbcglobal.net Mon Jan 12 10:40:47 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 12 Jan 2009 07:40:47 -0800 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> References: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> Message-ID: <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> John Machin wrote: > On Jan 12, 9:16 pm, "W. eWatson" wrote: >> John Machin wrote: >>> On Jan 12, 2:00 pm, "W. eWatson" wrote: >>>> I installed "Python" 2.5 a few months ago with IDLE, and decided I'd like to >>>> try windowpy from ActiveState. Is having both of these installed going to >>>> cause me trouble? >>> What is "windowpy from ActiveState"? If you mean you wanted to try the >>> PythonWin IDE instead of IDLE, all you needed to do was go to >>> http://sourceforge.net/projects/pywin32/hit the big download button >>> and make sure you get the 2.5 version (it's the default atm) and >>> install it. >> Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. >> >> Is it possible to just disable the vanilla (IDLE) version? I may want to >> switch between the two. Most users of the program I'm about to modify use >> the vanilla version. At some point, I may want to go back to it to verify >> that in their world all is OK. > > I'll try again. All you need is (a) the official distribution of > Python 2.5 for Windows from http://www.python.org (b) the pywin32 > package from the URL I gave you. Install both. Click on Start / All > Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ > or your users can use IDLE or PythonWin, only one copy of Python, no > conflicts. Why do you think you need to "disable" IDLE? Just don't use > it. > Once upon a time, six months ago, I asked a similar question and the answer was more complex. I decided to put this off until I truly needed it. Even better than Start, for me, is that I can choose PythonWin or IDLE from the right-click menu which I want. I do see a choice there of Open With-> Python. I can see it executed properly, but which 2.5 did it use? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From bieffe62 at gmail.com Mon Jan 12 10:42:47 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 12 Jan 2009 07:42:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> Message-ID: <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> On 12 Gen, 14:45, Paul Rubin wrote: > bieff... at gmail.com writes: > > > ? ?class Foo (DynamicAttributes, object): pass > > > You cannot do that, but you can establish a fixed set of attributes by > > defining the __slot__ class variable. > > That is not what __slot__ is for. Really? It seems to work: >>> class A(object): ... __slots__ = ('a', 'b') ... def __init__(self): self.not_allowed = 1 ... >>> a = A() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ AttributeError: 'A' object has no attribute 'not_allowed' >>> Ciao ----- FB From invalid at invalid Mon Jan 12 10:43:06 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 12 Jan 2009 09:43:06 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> Message-ID: On 2009-01-12, Sion Arrowsmith wrote: > Grant Edwards wrote: >>On 2009-01-09, Sion Arrowsmith wrote: >>> Grant Edwards wrote: >>>>If I were you, I'd try mmap()ing the file instead of reading it >>>>into string objects one chunk at a time. >>> You've snipped the bit further on in that sentence where the >>> OP says that the file of interest is 2GB. Do you still want to >>> try mmap'ing it? >>Sure. The larger the file, the more you gain from mmap'ing it. >>2GB should easily fit within the process's virtual memory >>space. > > Assuming you're in a 64bit world. Me, I've only got 2GB of address > space available to play in -- mmap'ing all of it out of the question. Oh. I assumed that decent 32-bit OSes would provide at least 3-4GB of address space to user processes. What OS are you using? > But I supposed that mmap'ing it chunk at a time instead of > reading chunk at a time might be worth considering. I'd try mmap'ing it in large chunks (512MB maybe). -- Grant Edwards grante Yow! I feel like a wet at parking meter on Darvon! visi.com From psaffrey at googlemail.com Mon Jan 12 10:45:22 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 12 Jan 2009 07:45:22 -0800 (PST) Subject: subprocess.Popen stalls References: Message-ID: On 12 Jan, 15:33, mk wrote: > > Better use communicate() method: > Oh yes - it's right there in the documentation. That worked perfectly. Many thanks, Peter From invalid at invalid Mon Jan 12 10:46:14 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 12 Jan 2009 09:46:14 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> Message-ID: On 2009-01-12, Sion Arrowsmith wrote: > In case the cancel didn't get through: > > Sion Arrowsmith wrote: >>Grant Edwards wrote: >>>2GB should easily fit within the process's virtual memory >>>space. >>Assuming you're in a 64bit world. Me, I've only got 2GB of address >>space available to play in -- mmap'ing all of it out of the question. > > And today's moral is: try it before posting. Yeah, I can map a 2GB > file no problem, complete with associated 2GB+ allocated VM. The > addressing is clearly not working how I was expecting it too. Cool. I'd be very interested to to know how the performance compares to open/read. -- Grant Edwards grante Yow! I think I am an at overnight sensation right visi.com now!! From mrkafk at gmail.com Mon Jan 12 11:11:48 2009 From: mrkafk at gmail.com (mk) Date: Mon, 12 Jan 2009 17:11:48 +0100 Subject: subprocess.Popen stalls In-Reply-To: References: Message-ID: psaffrey at googlemail.com wrote: > On 12 Jan, 15:33, mk wrote: >> Better use communicate() method: >> > > Oh yes - it's right there in the documentation. That worked perfectly. What's also in the docs and I did not pay attention to before: Note The data read is buffered in memory, so do not use this method if the data size is large or unlimited. Regards, mk From lists at cheimes.de Mon Jan 12 11:26:26 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 17:26:26 +0100 Subject: Compressed vs uncompressed eggs In-Reply-To: References: Message-ID: > Is there a, say, performance penalty in using compressed eggs? To the contrary, it can be faster to import from a zip file than from the file system. Christian From ryandw at gmail.com Mon Jan 12 11:28:50 2009 From: ryandw at gmail.com (webcomm) Date: Mon, 12 Jan 2009 08:28:50 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <66c46e9e-74dc-4d86-8dba-1edc17085bb9@x14g2000yqk.googlegroups.com> If anyone's interested, here are my django views... from django.shortcuts import render_to_response from django.http import HttpResponse from xml.etree.ElementTree import ElementTree import urllib, base64, subprocess def get_data(request): service_url = 'http://www.something.com/webservices/someservice/ etc?user=etc&pass=etc' xml = urllib.urlopen(service_url) #the base64-encoded string is in a one-element xml doc... tree = ElementTree() xml_doc = tree.parse(xml) datum = "" for node in xml_doc.getiterator(): datum = "%s" % (node.text) decoded = base64.b64decode(datum) dir = '/path/to/data/' f = open(dir+'data.zip', 'wb') f.write(decoded) f.close() file = subprocess.call('unzip '+dir+'data.zip -d '+dir, shell=True) file = open(dir+'data', 'rb').read() txt = file.decode('utf_16_le') return render_to_response('output.html',{ 'output' : txt }) def read_xml(request): xml = urllib.urlopen('http://www.something.org/get_data/') #page using the get_data view xml = xml.read() xml = unicode(xml) xml = '\n'+xml+'' f = open('/path/to/temp.txt','w') f.write(xml) f.close() tree = ElementTree() xml_doc = tree.parse('/path/to/temp.txt') datum = "" for node in xml_doc.getiterator(): datum = "%s
%s - %s" % (datum, node.tag, node.text) return render_to_response('output.html',{ 'output' : datum }) From thomas.steffen75 at googlemail.com Mon Jan 12 11:35:45 2009 From: thomas.steffen75 at googlemail.com (thomas.steffen75 at googlemail.com) Date: Mon, 12 Jan 2009 08:35:45 -0800 (PST) Subject: read a password protected xls file Message-ID: <567034d3-32b7-4954-a3ce-fae716159ded@k1g2000prb.googlegroups.com> Hello, how can I read (and parse) a password protected xls file, perhaps with the package xlrd? Thanks for your hints, Thomas From andrea.reginato at gmail.com Mon Jan 12 11:47:24 2009 From: andrea.reginato at gmail.com (Andrea Reginato) Date: Mon, 12 Jan 2009 08:47:24 -0800 (PST) Subject: Encoding Title mail References: <5eff0137-063e-4653-901d-134afd208ba9@f40g2000pri.googlegroups.com> <6t0tjgF8gel1U1@mid.uni-berlin.de> Message-ID: <30e3f843-184f-4a52-81e9-86be560d6524@a29g2000pra.googlegroups.com> On Jan 12, 2:06?pm, Marc 'BlackJack' Rintsch wrote: > On Mon, 12 Jan 2009 04:32:35 -0800, Andrea Reginato wrote: > > Hi to everybody, I'm trying to use libgmail version 0.1.9, to read some > > mails from a google account and save the attached files. All works fine, > > but when a tile has some letters with accents (like ?????) I read a > > string like this. > > > =?ISO-8859-1?Q?=F2=E0=F9+=E8=EC'_0987654321_\?= =?ISO-8859-1?Q? > > _=E9*=A7=B0=E7;:=5F_test_chars?= > > > I tried to use the string.decode(ISO-8859-1) function, but nothing > > change. > Look into the `email` package in the standard library. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch I tried to look at it, but nothing to do, sorry. I used email.Utils.decode_rfc2231(msg['Subject']) that seems what I need (I could be wrong, but it looks the closer at what I need) but it do not work out. I'm searching into the library, I'm not able to get the solution. Thanks again for your time From bj_666 at gmx.net Mon Jan 12 11:53:07 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 12 Jan 2009 16:53:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> Message-ID: <6t1arjF8gel1U2@mid.uni-berlin.de> On Mon, 12 Jan 2009 07:42:47 -0800, bieffe62 wrote: > On 12 Gen, 14:45, Paul Rubin wrote: >> bieff... at gmail.com writes: >> > > ? ?class Foo (DynamicAttributes, object): pass >> >> > You cannot do that, but you can establish a fixed set of attributes >> > by defining the __slot__ class variable. >> >> That is not what __slot__ is for. > > > Really? It seems to work: It works but it is not what `__slot__` was invented for. Some call it a misuse of that feature if you use it to prevent adding attributes dynamically. And it has some drawbacks when you inherit from such classes. Ciao, Marc 'BlackJack' Rintsch From arkanes at gmail.com Mon Jan 12 11:53:26 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 10:53:26 -0600 Subject: BadZipfile "file is not a zip file" In-Reply-To: <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <4866bea60901120853t19f3897q91df65a9d8e71f52@mail.gmail.com> On Sat, Jan 10, 2009 at 1:32 PM, webcomm wrote: > On Jan 9, 7:33 pm, John Machin wrote: >> It is not impossible for a file with dummy data to have been >> handcrafted or otherwise produced by a process different to that used >> for a real-data file. > > I knew it was produced by the same process, or I wouldn't have shared > it. : ) > But you couldn't have known that. > > >> > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> >> Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick >> with one thread ... > > Thanks... I thought I was posting about separate issues and would > annoy people who were only interested in one of the issues if I put > them both in the same thread. I guess all posts re: the same script > should go in one thread, even if the questions posed may be unrelated > and may be separate issues. There are grey areas. > > Problem solved in John Machin's post at > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/03b8341539d87989?hl=en&lnk=raot#03b8341539d87989 > It's worth pointing out (although the provider probably doesn't care) that this isn't really an XML document and this was a bad way of them to distribute the data. If they'd used a correctly formatted XML document (with the prelude and everything) with the correct encoding information, existing XML parsers should have just Done The Right Thing with the data, instead of you needing to know the encoding a priori to extract an XML fragment. From Scott.Daniels at Acm.Org Mon Jan 12 12:05:38 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 09:05:38 -0800 Subject: Python logging rollover In-Reply-To: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> References: <143c2529-0020-460e-a72c-38fc2ff1be79@v39g2000pro.googlegroups.com> Message-ID: Kottiyath wrote: > Hi, > > I want to do a log rollover .... I tested it with 'midnight' option, > but it did not work as I expected. Please google "smart questions". All I can conclude from your message is that your expectations are wrong. It is not enough to tell us you are confused. You need to show us enough so that we can discover what might, or might not, be going wrong. At the least, what was your code, what happened, and what did you expect to happen. --Scott David Daniels Scott.Daniels at Acm.Org From almar.klein at gmail.com Mon Jan 12 12:07:49 2009 From: almar.klein at gmail.com (Almar Klein) Date: Mon, 12 Jan 2009 18:07:49 +0100 Subject: VTK in python Message-ID: Hi all, I want to use the Visualisation ToolKit from python. However, I cannot find an easy way to install it. Of course, I could download the source, use CMake to build and VS to compile it, but... yeah, that takes a lot of time and will probably not work the first time... I noticed that with VTK 4.0 there was a vtk40python.exe installer supplied. But that realease if almost 7 years old... Why is such an installer no longer distributed with the newer releases? I hope I overlooked something, or else I guess I should go compiling tomorrow... :( Thanks for any help, Almar PS: I know entought ships with VTK, but it's such a huge install I try to avoid that... -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jan 12 12:16:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jan 2009 12:16:16 -0500 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: <496B04AB.9010409@shopzeus.com> References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> <496B04AB.9010409@shopzeus.com> Message-ID: Laszlo Nagy wrote: > Laszlo Nagy wrote: >> Meanwhile I'm trying to turn off threads in that program one by one. I >> just got this new type of error: >> >> Fatal Python error: PyThreadState_Delete: invalid tstate > After some days, there are now answers to my question. I guess this is > because nobody knows the answer. I think I need to consider this a bug > in Python. Where can I post a bug report? bugs.python.org From tjreedy at udel.edu Mon Jan 12 12:30:48 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jan 2009 12:30:48 -0500 Subject: Bug in python [was: Fatal Python error: ceval: tstate mix-up] In-Reply-To: References: <496722DF.6080206@shopzeus.com> <49674C57.3040908@shopzeus.com> <496B04AB.9010409@shopzeus.com> Message-ID: Terry Reedy wrote: > Laszlo Nagy wrote: >> Laszlo Nagy wrote: >>> Meanwhile I'm trying to turn off threads in that program one by one. >>> I just got this new type of error: >>> >>> Fatal Python error: PyThreadState_Delete: invalid tstate >> After some days, there are now answers to my question. I guess this is >> because nobody knows the answer. I think I need to consider this a bug >> in Python. Where can I post a bug report? > > bugs.python.org Before submitting, search for existing report of same bug. If none, try to write a minimal program that reliably reproduces the bug. (If you can't, it will be hard to fix.). Make sure the bug occurs with 2.6.1 or 3.0. Earlier 2.x is not maintained except for security patches. From Scott.Daniels at Acm.Org Mon Jan 12 12:34:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 09:34:21 -0800 Subject: Python tricks In-Reply-To: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: RajNewbie wrote: > On Jan 12, 6:51 pm, Tim Chase wrote: [a perfectly fine reply which is how I'd solve it] >> RajNewbie wrote: >>> ... The solution that I had in mind is: >>> while True: >>> ... >>> if : break >>> if inifinte_loop(): raise infiinte_loop_exception >>> Wherein infinite_loop is a generator, which returns true if i > 200 >>> def infinite_loop(): >>> i = 0 >>> while i < 200: >>> i++ >>> yield False >>> yield True >>> Could somebody let me know whether this is a good option? > ... > But, I still feel it would be much more aesthetically pleasing if I > can call a single procedure like > if infinite_loop() -> to do the same. > Is it somehow possible? - say by using static variables, iterators -- > anything? 1) Please cut down quoted text to as little as needed to understand the reply. Yes, it is possible. After: def Fuse(count, exception): for i in range(count): yield None raise exception You can do your loop as: check_infinite = Fuse(200, ValueError('Infinite Loop')).next while True: ... check_infinite() but I agree with Tim that a for ... else loop for the limit is clearer. --Scott David Daniels Scott.Daniels at Acm.Org From dskippy at ccs.neu.edu Mon Jan 12 12:40:57 2009 From: dskippy at ccs.neu.edu (Mike MacHenry) Date: Mon, 12 Jan 2009 12:40:57 -0500 Subject: Simple CGI-XMLRPC failure Message-ID: <7d9c10d20901120940t544448cdl35f2c806a4bfc59a@mail.gmail.com> I am having a difficult time understanding why my very simple CGI-XMLRPC test isn't working. I created a server to export two functions, the built-in function "pow" and my own identity function "i". I run a script to call both of them and the "pow" work fine but the "i" gives me an error that says my XMLRPC server doesn't support than name. Here is the code for both files and the output: #!/usr/bin/env python #This file is /usr/lib/cgi-bin/roundwarerpc.py from SimpleXMLRPCServer import CGIXMLRPCRequestHandler def i(x): return x server = CGIXMLRPCRequestHandler() server.register_function(pow) server.register_function(i) server.handle_request() #!/usr/bin/env python #This file is ~/test.py import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") print server.pow(2,3) print server.i(10) #This is the STDOUT and STDERR when running ~/test.py dskippy at dskippy-laptop:$ python test.py 8 Traceback (most recent call last): File "test.py", line 4, in print server.test(10) File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ return self.__send(self.__name, args) File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response return u.close() File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :method "i" is not supported'> Does anyone know what might be wrong with this? Thanks for the help, -mike p.s. Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Server version Apache/2.2.8 (Ubuntu) Server built: Jun 25 2008 13:54:13 From nad at acm.org Mon Jan 12 13:03:22 2009 From: nad at acm.org (Ned Deily) Date: Mon, 12 Jan 2009 10:03:22 -0800 Subject: Egg deinstallation References: <6t139nF8ip4nU1@mid.uni-berlin.de> Message-ID: In article <6t139nF8ip4nU1 at mid.uni-berlin.de>, "Diez B. Roggisch" wrote: > mk wrote: > > I googled and googled and can't seem to find the definitive answer: how > > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > > files from Lib/site-packages? Would that break anything in Python > > installation or not? > > It depends on how you installed it. If it is done via > setuptools/easy_install, you should also clean up the > > site-packages/easy-install.pth > > file. ... and which you can do by editing that file directly or by using the easy_install -m option to mark the egg as multi-version before deleting. In either case, keep in mind that the egg may have installed one or more scripts; those have to be removed manually. -- Ned Deily, nad at acm.org From rdcollum at gmail.com Mon Jan 12 13:14:19 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 10:14:19 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: On Jan 12, 6:31?am, James Stroud wrote: > James Stroud wrote: > > py> b.tk.call('bind', 'Listbox', '', _) > > You want b.tk.call('bind', 'Listbox', '', "") of course. > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com Knowing this is actually extremely useful (looking at Tkinter.py i see this is equivalent to the unbind method). Unfortunately it's not working to unbind B1-Motion from Listbox even though I get the same output results as you've gotten above. =( Thanks a ton James. This is still very educational to me. Roger. From gert.cuykens at gmail.com Mon Jan 12 13:27:57 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 10:27:57 -0800 (PST) Subject: python3.0 MySQLdb Message-ID: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> I need something to connect to a database, preferably mysql, that works in python3.0 please. From Tribulations at Paralleles.invalid Mon Jan 12 13:51:23 2009 From: Tribulations at Paralleles.invalid (TP) Date: Mon, 12 Jan 2009 19:51:23 +0100 Subject: trying to modify locals() dictionary Message-ID: Hi everybody, I try to modify locals() as an exercise. According to the context (function or __main__), it works differently (see below). Why? Thanks Julien ######################################## def try_to_modify_locals( locals_ ): locals_[ "a" ] = 2 print "locals_[ 'a' ]=", locals_[ "a" ] return locals_ def test_modify_locals(): a = 3 l = try_to_modify_locals( locals() ) print l is locals() print a # Below, a remains equal to 3 print "test from test_modify_locals()" test_modify_locals() # But here, it works: a is modified print "test from __main__" a = 3 l = try_to_modify_locals( locals() ) print l is locals() print a ######################################## -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From lists at cheimes.de Mon Jan 12 14:08:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 20:08:38 +0100 Subject: trying to modify locals() dictionary In-Reply-To: References: Message-ID: TP schrieb: > Hi everybody, > > I try to modify locals() as an exercise. > According to the context (function or __main__), it works differently (see > below). Why? Thanks Because http://docs.python.org/library/functions.html#locals Warning The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. Christian From lists at cheimes.de Mon Jan 12 14:12:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 12 Jan 2009 20:12:52 +0100 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: > I say again, show me a case of working 2.5 code where prepending u to > an ASCII string constant that is intended to be used in a text context > is actually worth the keystrokes. Eventually you'll learn it the hard way. *sigh* Christian From gandalf at shopzeus.com Mon Jan 12 14:13:37 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 20:13:37 +0100 Subject: Slow network? Message-ID: <496B9661.30406@shopzeus.com> Hi All, To make the long story short, I have a toy version of an ORB being developed, and the biggest problem is slow network speed over TCP/IP. There is an object called 'endpoint' on both sides, with incoming and outgoing message queues. This endpoint object has a socket assigned, with nodelay: conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) The endpoint is running two separate threads - those are dedicated for reading/writing messages from/into the socket object, as shown below: def _process_incoming(self): try: while not self.stop_requested.isSet(): data = self.read_str() while not self.stop_requested.isSet(): try: self.incoming.put(data,1) break except orb.util.smartqueue.Full: pass if not self.stop_requested.isSet(): if self.router: self.router.on_message_arrived(self) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) def _process_outgoing(self): try: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): try: data = self.outgoing.get(1) data_ok = True break except orb.util.smartqueue.Empty: pass if data_ok: self.write_str(data) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) The main point is that the sender does not need to wait for the message to be actually written into the socket (unless the outgoing queue becomes full). When I try to send a message and receive an answer for it, I can only get as much as 130 request+response message pairs per second. Apparently, it is the same from messages size =77bytes to message size=16 Kbytes. However, if I send 100 outgoing messages first, then read back all answers then the speed goes up to 1300 message pairs/sec. I suspect that this has something to do with TCP/IP. Since this will be used for RPC/RMI, it would be very important to lower the time needed to exchange messages. Is there any way I can speed this up? Or do you think that this speed is the best I can get? My friend tried to do the same thing in Java, and he said that he could reach 1000 messages/sec. (Is there a special "socket.flush()" method in Java that we do not have in Python?) Thanks, Laszlo From jcd at sdf.lonestar.org Mon Jan 12 14:15:00 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Mon, 12 Jan 2009 14:15:00 -0500 Subject: Creating new instances of subclasses. In-Reply-To: References: Message-ID: <1231787700.5865.9.camel@mctell> On Fri, 2009-01-09 at 10:46 -0800, Dennis Lee Bieber wrote: > On Wed, 07 Jan 2009 11:38:29 -0500, "J. Cliff Dyer" > declaimed the following in comp.lang.python: > > > I want to be able to create an object of a certain subclass, depending > > on the argument given to the class constructor. > > > > I have three fields, and one might need to be a StringField, one an > > IntegerField, and the last a ListField. But I'd like my class to > > delegate to the proper subclass automatically, so I can just do: > > > > >>> f1 = Field('abc') > > >>> f2 = Field('123') > > >>> f3 = Field('D,E,F') > > And how do you differentiate a string that contains a comma from a > purported list? > > What is expected for: > > ambiguous = Field('He said "Blast, it won''t work"') My strings don't look like that. Nor is that relevant to my question. I created a simple, uncluttered example to illustrate my issue with instantiating the proper subclass for a given argument. I did not try to make sure my example handled all edge cases properly. Cheers, Cliff From marduk at letterboxes.org Mon Jan 12 14:18:59 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 12 Jan 2009 14:18:59 -0500 Subject: trying to modify locals() dictionary In-Reply-To: References: Message-ID: <1231787939.3639.1.camel@localhost.localdomain> On Mon, 2009-01-12 at 19:51 +0100, TP wrote: > Hi everybody, > > I try to modify locals() as an exercise. > According to the context (function or __main__), it works differently (see > below). Why? Thanks > > Julien Per the locals() documentation @ http://docs.python.org/library/functions.html Warning The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. From fetchinson at googlemail.com Mon Jan 12 14:25:16 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 12 Jan 2009 11:25:16 -0800 Subject: python3.0 MySQLdb In-Reply-To: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: > I need something to connect to a database, preferably mysql, that > works in python3.0 please. And your question is? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From arkanes at gmail.com Mon Jan 12 14:35:00 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 13:35:00 -0600 Subject: Slow network? In-Reply-To: <496B9661.30406@shopzeus.com> References: <496B9661.30406@shopzeus.com> Message-ID: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> On Mon, Jan 12, 2009 at 1:13 PM, Laszlo Nagy wrote: > > Hi All, > > To make the long story short, I have a toy version of an ORB being > developed, and the biggest problem is slow network speed over TCP/IP. > > There is an object called 'endpoint' on both sides, with incoming and > outgoing message queues. This endpoint object has a socket assigned, with > nodelay: > > conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) > > The endpoint is running two separate threads - those are dedicated for > reading/writing messages from/into the socket object, as shown below: > > > def _process_incoming(self): > try: > while not self.stop_requested.isSet(): > data = self.read_str() > while not self.stop_requested.isSet(): > try: > self.incoming.put(data,1) > break > except orb.util.smartqueue.Full: > pass > if not self.stop_requested.isSet(): > if self.router: > self.router.on_message_arrived(self) > except Exception, e: > if self.router: > if not isinstance(e,TransportClosedError): > self.router.logger.error(dumpexc(e)) > self.router.unregister_endpoint(self) > self.shutdown() > raise SystemExit(0) > > def _process_outgoing(self): > try: > while not self.stop_requested.isSet(): > data_ok = False > while not self.stop_requested.isSet(): > try: > data = self.outgoing.get(1) > data_ok = True > break > except orb.util.smartqueue.Empty: > pass > if data_ok: > self.write_str(data) > except Exception, e: > if self.router: > if not isinstance(e,TransportClosedError): > self.router.logger.error(dumpexc(e)) > self.router.unregister_endpoint(self) > self.shutdown() > raise SystemExit(0) > > > The main point is that the sender does not need to wait for the message to > be actually written into the socket (unless the outgoing queue becomes > full). > > When I try to send a message and receive an answer for it, I can only get as > much as 130 request+response message pairs per second. Apparently, it is the > same from messages size =77bytes to message size=16 Kbytes. > > However, if I send 100 outgoing messages first, then read back all answers > then the speed goes up to 1300 message pairs/sec. I suspect that this has > something to do with TCP/IP. Since this will be used for RPC/RMI, it would > be very important to lower the time needed to exchange messages. Is there > any way I can speed this up? > It is very likely that nodelay is actually hurting you here. Using the select module and doing non-blocking IO will be faster than using threads for this as well. From perfreem at yahoo.com Mon Jan 12 14:36:47 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 11:36:47 -0800 (PST) Subject: efficient interval containment lookup Message-ID: hello, suppose I have two lists of intervals, one significantly larger than the other. For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain thousands of elements while listB (of the same form) might contain hundreds of thousands or millions of elements. I want to count how many intervals in listB are contained within every listA. For example, if listA = [(10, 30), (600, 800)] and listB = [(20, 25), (12, 18)] is the input, then the output should be that (10, 30) has 2 intervals from listB contained within it, while (600, 800) has 0. (Elements of listB can be contained within many intervals in listA, not just one.) What is an efficient way to this? One simple way is: for a_range in listA: for b_range in listB: is_within(b_range, a_range): # accumulate a counter here where is_within simply checks if the first argument is within the second. I'm not sure if it's more efficient to have the iteration over listA be on the outside or listB. But perhaps there's a way to index this that makes things more efficient? I.e. a smart way of indexing listA such that I can instantly get all of its elements that are within some element of listB, maybe? Something like a hash, where this look up can be close to constant time rather than an iteration over all lists... if there's any built-in library functions that can help in this it would be great. any suggestions on this would be awesome. thank you. From google at mrabarnett.plus.com Mon Jan 12 14:49:15 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jan 2009 19:49:15 +0000 Subject: Slow network? In-Reply-To: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> Message-ID: <496B9EBB.7050908@mrabarnett.plus.com> Chris Mellon wrote: > On Mon, Jan 12, 2009 at 1:13 PM, Laszlo Nagy wrote: >> Hi All, >> >> To make the long story short, I have a toy version of an ORB being >> developed, and the biggest problem is slow network speed over TCP/IP. >> >> There is an object called 'endpoint' on both sides, with incoming and >> outgoing message queues. This endpoint object has a socket assigned, with >> nodelay: >> >> conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) >> >> The endpoint is running two separate threads - those are dedicated for >> reading/writing messages from/into the socket object, as shown below: >> >> >> def _process_incoming(self): >> try: >> while not self.stop_requested.isSet(): >> data = self.read_str() >> while not self.stop_requested.isSet(): >> try: >> self.incoming.put(data,1) >> break >> except orb.util.smartqueue.Full: >> pass >> if not self.stop_requested.isSet(): >> if self.router: >> self.router.on_message_arrived(self) >> except Exception, e: >> if self.router: >> if not isinstance(e,TransportClosedError): >> self.router.logger.error(dumpexc(e)) >> self.router.unregister_endpoint(self) >> self.shutdown() >> raise SystemExit(0) >> >> def _process_outgoing(self): >> try: >> while not self.stop_requested.isSet(): >> data_ok = False >> while not self.stop_requested.isSet(): >> try: >> data = self.outgoing.get(1) >> data_ok = True >> break >> except orb.util.smartqueue.Empty: >> pass >> if data_ok: >> self.write_str(data) >> except Exception, e: >> if self.router: >> if not isinstance(e,TransportClosedError): >> self.router.logger.error(dumpexc(e)) >> self.router.unregister_endpoint(self) >> self.shutdown() >> raise SystemExit(0) >> >> >> The main point is that the sender does not need to wait for the message to >> be actually written into the socket (unless the outgoing queue becomes >> full). >> >> When I try to send a message and receive an answer for it, I can only get as >> much as 130 request+response message pairs per second. Apparently, it is the >> same from messages size =77bytes to message size=16 Kbytes. >> >> However, if I send 100 outgoing messages first, then read back all answers >> then the speed goes up to 1300 message pairs/sec. I suspect that this has >> something to do with TCP/IP. Since this will be used for RPC/RMI, it would >> be very important to lower the time needed to exchange messages. Is there >> any way I can speed this up? >> > > It is very likely that nodelay is actually hurting you here. > > Using the select module and doing non-blocking IO will be faster than > using threads for this as well. > You might also want to replace those 'pass' statements when smartqueue is empty or full with time.sleep() to avoid busy waiting. From gandalf at shopzeus.com Mon Jan 12 14:56:02 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 20:56:02 +0100 Subject: Slow network? In-Reply-To: <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> Message-ID: <496BA052.2040101@shopzeus.com> > It is very likely that nodelay is actually hurting you here. > > Using the select module and doing non-blocking IO will be faster than > using threads for this as well. > These sockets are non blocking and I'm using select.select indeed. Here is how it is implemented: def read_data(self,size): res = "" fd = self.socket.fileno() while not self.stop_requested.isSet(): remaining = size - len(res) if remaining<=0: break # Give one second for an incoming connection so we can stop the # server in seconds when needed ready = select.select([fd], [], [], 0.2) if fd in ready[0]: data = self.socket.recv(min(remaining,8192)) # 8192 is recommended by socket.socket manual. if not data: # select returns the fd but there is no data to read -> connection closed! raise TransportClosedError("Connection closed.") else: res += data else: pass if self.stop_requested.isSet(): raise SystemExit(0) return res def write_data(self,data): fd = self.socket.fileno() while not self.stop_requested.isSet(): size = len(data) if size==0: break # Give one second for an incoming connection so we can stop the server in seconds when needed ready = select.select([], [fd], [], 0.2) if fd in ready[1]: sent = self.socket.send( # 8192 is recommended by socket.socket manual. data[:max(size,8192)] ) if not sent: # select returns the fd but there is no data written -> connection closed! raise TransportClosedError("Connection closed.") else: data = data[sent:] # Not too efficient... else: pass if self.stop_requested.isSet(): raise SystemExit(0) All other I/O methods are calling write_data() and read_data(). One thing I cannot do is to remove threads. This endpoint class is specifically designed so that other threads can put messages into the outgoing queue, and they do not need to wait for the message to be written out into the socket: endpoint.send_message(msg) # won't block unless the outgoing queue is full endpoint.recv_message(msg) # won't block unless the incoming queue is empty Given this situation, I see no alternative to using threads. Do you? Here is how the socket is set up on the client side: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) s.connect((params['address'],params['port'])) return orb.endpoint.SocketEndpoint(s) And on the server side: def handle_request(self): conn,client_address = self.serversocket.accept() self.logger.info( str(client_address) + ' connecting') conn.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1) t = orb.endpoint.SocketEndpoint(conn,self.router) The socket based endpoint starts with setting non-blocking mode: class SocketEndpoint(Endpoint): """Specialized Transport endpoint that communicates over a socket.""" def __init__(self,socket,router=None): self.socket = socket self.socket.setblocking(0) Endpoint.__init__(self,router) Here are some more test results: - original example with setblocking(0) and TCP_NODELAY: 130 messages / sec - same example without TCP_NODELAY: 130 messages/sec (I don't understand why?) - same example without setblocking(0): 130 messages/sec (I guess because I'm using select.select already?) - same example without setblocking(0) and without TCP_NODELAY: 130 messages / sec Now I really didn't understand where is the problem? I suspected that maybe the overhead for select.select? But nope, tried the same example without select.select and without setblocking(0) and it was also 130 messages/sec. What is hurting me then? Is it not TCP? :-( From gandalf at shopzeus.com Mon Jan 12 15:01:07 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:01:07 +0100 Subject: Slow network? In-Reply-To: <496B9EBB.7050908@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496B9EBB.7050908@mrabarnett.plus.com> Message-ID: <496BA183.8050900@shopzeus.com> > You might also want to replace those 'pass' statements when smartqueue > is empty or full with time.sleep() to avoid busy waiting. It won't do busy waiting, because read_str and write_str are using select.select and they will block without using CPU time, until data becomes available to read/write. From gandalf at shopzeus.com Mon Jan 12 15:04:54 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:04:54 +0100 Subject: Slow network? In-Reply-To: <496B9EBB.7050908@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496B9EBB.7050908@mrabarnett.plus.com> Message-ID: <496BA266.4070709@shopzeus.com> > You might also want to replace those 'pass' statements when smartqueue > is empty or full with time.sleep() to avoid busy waiting. I misunderstood your post, sorry. My smartqueue class has a timeout parameter, and it can block for an item, or raise the Full/Empty exception after timeout exceeded. That is 1 second in my example program: self.incoming.put(data,1) data = self.outgoing.get(1) From bdesth.quelquechose at free.quelquepart.fr Mon Jan 12 15:06:46 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 12 Jan 2009 21:06:46 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xhc45csw0.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> Message-ID: <496bb081$0$31451$426a74cc@news.free.fr> Paul Rubin a ?crit : > Carl Banks writes: >>> The criticism is very valid. Some languages do support immutable >>> variables (e.g. "final" declarations in Java, "const" in C++, or >>> universal immutability in pure functional languages) and they do so >>> precisely for the purpose of taming the chaos of uncontrolled >>> mutation. It would be great if Python also supported immutability. >> I don't think what you said (which is fine) makes his criticism valid, >> unless you also suggest that all objects should be immutable. > > It would be enough to have a way to make specific objects and instance > attributes immutable. > >> If any objects are mutable, you have to be prepared for objects to >> mutated outside the initializer. > > Sure, but why have mutable objects all over the place? And, why > always have attributes visible at all, outside the class definition? > The approach in C++ and Java is to have public and private instance > variables, where the private ones are visible only in the class methods. Why on earth are you using Python if you don't like the way it work ??? From silfheed at gmail.com Mon Jan 12 15:07:20 2009 From: silfheed at gmail.com (Silfheed) Date: Mon, 12 Jan 2009 12:07:20 -0800 (PST) Subject: Mocking `from foo import *` functions References: <68239214-859a-4484-91b1-ec208393d28d@f40g2000pri.googlegroups.com> Message-ID: <0057e679-ce50-4321-a23c-b3e21b57d6fd@e10g2000vbe.googlegroups.com> Brilliant, I love it. Thanks a million, guys. From google at mrabarnett.plus.com Mon Jan 12 15:15:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jan 2009 20:15:48 +0000 Subject: Slow network? In-Reply-To: <496BA052.2040101@shopzeus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496BA052.2040101@shopzeus.com> Message-ID: <496BA4F4.6090709@mrabarnett.plus.com> Laszlo Nagy wrote: > [snip] > Here are some more test results: > > - original example with setblocking(0) and TCP_NODELAY: 130 messages / sec > - same example without TCP_NODELAY: 130 messages/sec (I don't understand > why?) > - same example without setblocking(0): 130 messages/sec (I guess because > I'm using select.select already?) > - same example without setblocking(0) and without TCP_NODELAY: 130 > messages / sec > > Now I really didn't understand where is the problem? I suspected that > maybe the overhead for select.select? But nope, tried the same example > without select.select and without setblocking(0) and it was also 130 > messages/sec. > > What is hurting me then? Is it not TCP? :-( > Waiting for a response after each send will take longer than doing the sends and then the responses. Have you tried pinging the destination to see how long the round trip takes? Has your friend? From gert.cuykens at gmail.com Mon Jan 12 15:19:52 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 12:19:52 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> On Jan 12, 8:25?pm, "Daniel Fetchinson" wrote: > > I need something to connect to a database, preferably mysql, that > > works in python3.0 please. > > And your question is? MySQLdb or something else for python3.0 ? From skip at pobox.com Mon Jan 12 15:24:39 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 12 Jan 2009 14:24:39 -0600 Subject: python3.0 MySQLdb In-Reply-To: <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <2b6531e5-a68e-4123-a13c-f44d831ca367@v18g2000pro.googlegroups.com> Message-ID: <18795.42759.175057.640166@montanaro.dyndns.org> >> > I need something to connect to a database, preferably mysql, that >> > works in python3.0 please. >> >> And your question is? gert> MySQLdb or something else for python3.0 ? Given that Python 3.0 is so new and so few packages have been ported to it yet, it might be helpful if you explained why Python 2.6 + MySQLdb isn't sufficient for your needs. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From ryandw at gmail.com Mon Jan 12 15:27:42 2009 From: ryandw at gmail.com (webcomm) Date: Mon, 12 Jan 2009 12:27:42 -0800 (PST) Subject: BadZipfile "file is not a zip file" References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> Message-ID: <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> On Jan 12, 11:53?am, "Chris Mellon" wrote: > On Sat, Jan 10, 2009 at 1:32 PM,webcomm wrote: > > On Jan 9, 7:33 pm, John Machin wrote: > >> It is not impossible for a file with dummy data to have been > >> handcrafted or otherwise produced by a process different to that used > >> for a real-data file. > > > I knew it was produced by the same process, or I wouldn't have shared > > it. : ) > > But you couldn't have known that. > > >> > Not sure if you've seen this thread...http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > >> Yeah, I've seen it ... (sigh) ... pax Steve Holden, but *please* stick > >> with one thread ... > > > Thanks... I thought I was posting about separate issues and would > > annoy people who were only interested in one of the issues if I put > > them both in the same thread. ?I guess all posts re: the same script > > should go in one thread, even if the questions posed may be unrelated > > and may be separate issues. ?There are grey areas. > > > Problem solved in John Machin's post at > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > It's worth pointing out (although the provider probably doesn't care) > that this isn't really an XML document and this was a bad way of them > to distribute the data. If they'd used a correctly formatted XML > document (with the prelude and everything) with the correct encoding > information, existing XML parsers should have just Done The Right > Thing with the data, instead of you needing to know the encoding a > priori to extract an XML fragment. Agreed. I can't say I understand their rationale for doing it this way. From gandalf at shopzeus.com Mon Jan 12 15:33:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 12 Jan 2009 21:33:03 +0100 Subject: Slow network? In-Reply-To: <496BA4F4.6090709@mrabarnett.plus.com> References: <496B9661.30406@shopzeus.com> <4866bea60901121135s4ead2695l8325ba8b90da5446@mail.gmail.com> <496BA052.2040101@shopzeus.com> <496BA4F4.6090709@mrabarnett.plus.com> Message-ID: <496BA8FF.4060801@shopzeus.com> >> > Waiting for a response after each send will take longer than doing the > sends and then the responses. Have you tried pinging the destination > to see how long the round trip takes? Has your friend? My test application listens on 127.0.0.1. gandalf at gandalf-desktop:~/Python/Lib/orb/examples/01_lowlevel$ ping 127.0.0.1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.027 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.018 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.021 ms If we only see the response time, the worst case would be 1000.0/ ( 2*0.027 ) = 18518 message pairs / sec... (My friend used 127.0.0.1 too) From pavlovevidence at gmail.com Mon Jan 12 15:39:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 12:39:38 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: <2f09e5e2-3849-4f23-a65c-3edf21740fa6@q30g2000prq.googlegroups.com> On Jan 12, 5:26?am, John Machin wrote: > On Jan 12, 7:29?pm, Carl Banks wrote: > > > > > On Jan 12, 12:32?am, John Machin wrote: > > > > On Jan 12, 12:23?pm, Carl Banks wrote: > > > > > On Jan 9, 6:11?pm, John Machin wrote: > > > > > > On Jan 10, 6:58?am, Carl Banks wrote: > > > > > > I expect that it'd be a PITA in some cases to use the transitional > > > > > > dialect (like getting all your Us in place), but that doesn't mean the > > > > > > language is crippled. > > > > > > What is this "transitional dialect"? What does "getting all your Us in > > > > > place" mean? > > > > > Transitional dialect is the subset of Python 2.6 that can be > > > > translated to Python3 with 2to3 tool. > > > > I'd never seen it called "transitional dialect" before. > > > I had hoped the context would make it clear what I was talking about. > > In vain. You were one who was mistaken about what Steve and Cliff were talking about, chief. Maybe if you'd have paid better attention you would have gotten it? > > > > ?Getting all your Us in place > > > > refers to prepending a u to strings to make them unicode objects, > > > > which is something 2to3 users are highly advised to do to keep hassles > > > > to a minimum. ?(Getting Bs in place would be a good idea too.) > > > > Ummm ... I'm not understanding something. 2to3 changes u"foo" to > > > "foo", doesn't it? What's the point of going through the code and > > > changing all non-binary "foo" to u"foo" only so that 2to3 can rip the > > > u off again? > > > It does a bit more than that. > > Like what? Never mind; I was confusing it with a different tool. (Someone had a source code processing tool that replaced strings with their reprs a while back.) My bad. > > > What hassles? Who's doing the highly-advising where and > > > with what supporting argument? > > > You add the u so the the constant will be the same data type in 2.6 as > > it becomes in 3.0 after applying 2to3. ?str and unicode objects aren't > > always with smooth with each other, and you have a much better chance > > of getting the same behavior in 2.6 and 3.0 if you use an actual > > unicode string in both. > > (1) Why specifically 2.6? Do you mean 2.X, or is this related to the > "port to 2.6 first" theory? It's not a theory. 2to3 was designed to translate a subset of 2.6 code to 3.0. It's not designed to translate arbitrary 2.6 code, nor any 2.5 or lower code. It might work well enough from 2.5, but it wasn't designed for it. > (2) We do assume we are starting off with working 2.X code, don't we? > If we change "foo" to u"foo" and get a different answer from the 2.X > code, is that still "working"? Of course it's not "working" in 2.6, and that's the point: you want it to work in 2.6 with Unicode strings because it has to run in 3.0 with Unicode strings. > > A example of this, though not with string constants, > > And therefore irrelevant. Well, it wasn't from my viewpoint, which was "make sure you are using only unicode and bytes objects", never str objects. But if you want to talk about string constants specifically, ok. > I would like to hear from someone who has actually started with > working 2.x code and changed all their text-like "foo" to > u"foo" [except maybe unlikely suspects like open()'s mode arg]: > * how many places where the 2.x code broke and so did the 3.x code > [i.e. the problem would have been detected without prepending u] I think you're missing the point. This isn't merely about detecting errors; it's about making the code in 2.6 behave as similarly to 3.0 as possible, and that includes internal behavior. When you have mixed str and unicode objects, 2.6 has to do a lot of encoding and decoding under the covers; in 3.0 that won't be happening. That increases the risk of divergent behavior, and is something you want to avoid. If you think your test suite is invincible and can catch every possible edge case where some encoding or decoding mishap occurs, be my guest and don't do it. Also, I'm not sure why you think it's preferrable to run tests on 3.0 and have to go back to the 2.6 codebase, run 2to3 again, apply the patch again, and retest, to fix it. I don't know, maybe it makes sense for people with a timemachine.py module, but I don't think it'll make sense for most people. > * how many places where the 2.x code broke but the 3.x code didn't > [i.e. prepending u did find the problem] If you think this was the main benefit of doing that you are REALLY missing the point. The point isn't to find problems in 2.6, it's to modify 2.6 to behave as similarly to 3.0 as possible. > * whether they thought it was worth the effort > > In the meantime I would be interested to hear from anybody with a made- > up example of code where the problem would be detected (sooner | > better | only) by prepending u to text-like string constants. Here's one for starters. The mistake was using a multibyte character in a str object in 2.6. 2to3 would have converted this to a script that has different behavior. If the u"" had been present on the string it would have the same behavior in both 2.6 and 3.0. (Well, the repr is different but it's a repr of the same object in both.) # coding: utf-8 print repr("abcd?") Out of curiosity, do > > 2to3 can only do so > > much; it can't always guess whether your string usage is supposed to > > be character or binary. > > AFAICT it *always* guesses text rather than binary; do you have any > examples where it guesses binary (rightly or wrongly)? Again, not the point. It's not whether 2to3 guesses correctly, but whether the runtime does different things in the two versions. Carl Banks From python.list at tim.thechases.com Mon Jan 12 15:43:57 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jan 2009 14:43:57 -0600 Subject: efficient interval containment lookup In-Reply-To: References: Message-ID: <496BAB8D.4020807@tim.thechases.com> > suppose I have two lists of intervals, one significantly larger than > the other. > For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain > thousands > of elements while listB (of the same form) might contain hundreds of > thousands > or millions of elements. > I want to count how many intervals in listB are contained within every > listA. For example, if listA = [(10, 30), (600, 800)] and listB = > [(20, 25), (12, 18)] is the input, then the output should be that (10, > 30) has 2 intervals from listB contained within it, while (600, 800) > has 0. (Elements of listB can be contained within many intervals in > listA, not just one.) > > What is an efficient way to this? One simple way is: > > for a_range in listA: > for b_range in listB: > is_within(b_range, a_range): > # accumulate a counter here Could you detail the is_within() function? most importantly, is it inclusive, such that "a1 <= b1 <= b2 <= a2", or is it overlapping such that "a1 <= b2 or a2 <= b1". Additionally, do you want to count how many intervals of A overlap with intervals of B, or do you just want a count of how many intervals in B have *any* overlap within A? My leaning would be to make a custom "is this in A" function, iterate over B and test against an "appropriate subset" of A: listA = sorted([...]) min_a1 = min(a1 for (a1, a2) in listA) max_a2 = max(a2 for (a1, a2) in listA) def in_a(b1, b2): for a1, a2 in smartly_chosen_subset(listA, b1, b2): if is_within((b1, b2), (a1, a2)): return True return False i = 0 for b1, b2 in sorted(listB): if b2 < min_a1: continue if b1 > max_a2: break if in_a(b1, b2): i += 1 The in_a() function can be optimized to terminate early if a1>b2 or a2 < b1 (perhaps even choosing an smart starting point for iterating). Short-circuiting by returning True as soon as you know there's a match will trim some of the time. How distributed are the endpoints? If there's a lot of commonality in the data, you might be able to cache results to cut even further. Just a few ideas, and questions that might help develop better solutions. -tkc From Scott.Daniels at Acm.Org Mon Jan 12 15:52:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 12 Jan 2009 12:52:14 -0800 Subject: efficient interval containment lookup In-Reply-To: References: Message-ID: Are these ranges constrained in any way? Does preprocessing count in the efficiency cost? Is the long list or the short list fixed while the other varies? With no constraints the problem is harder. > But perhaps there's a way to index this that makes things more > efficient? I.e. a smart way of indexing listA such that I can > instantly get all of its elements that are within some element > of listB, maybe? Something like a hash, where this look up can be > close to constant time rather than an iteration over all lists... > [what] built-in library functions ... can help? > any suggestions on this would be awesome. thank you. If the intervals have a rough size on either side (or both), that could give you a useful grid for your hashing. If the total range of the integers in listA is smallish, you could label every value in that range with which elements of listA contain that point. You could also look for interesting orders of the intervals in listA, so that you can use the bisect module to get to one end of a range that will hold all your answers and only check the applicable elements of the range. You might also consider how you could set up numpy arrays to test the set of ranges in listA in a pair of operations. I hope I haven't helped you with your homework. --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Mon Jan 12 16:05:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 12 Jan 2009 15:05:32 -0600 Subject: efficient interval containment lookup In-Reply-To: <496BAB8D.4020807@tim.thechases.com> References: <496BAB8D.4020807@tim.thechases.com> Message-ID: [Apologies for piggybacking, but I think GMane had a hiccup today and missed the original post] [Somebody wrote]: >> suppose I have two lists of intervals, one significantly larger than >> the other. >> For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain >> thousands >> of elements while listB (of the same form) might contain hundreds of >> thousands >> or millions of elements. >> I want to count how many intervals in listB are contained within every >> listA. For example, if listA = [(10, 30), (600, 800)] and listB = >> [(20, 25), (12, 18)] is the input, then the output should be that (10, >> 30) has 2 intervals from listB contained within it, while (600, 800) >> has 0. (Elements of listB can be contained within many intervals in >> listA, not just one.) Interval trees. http://en.wikipedia.org/wiki/Interval_tree -- 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 rdcollum at gmail.com Mon Jan 12 16:29:52 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 13:29:52 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> Message-ID: <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> I'm sorry for harassing the list but any suggestions would be greatly appreciated. =) From http Mon Jan 12 16:36:07 2009 From: http (Paul Rubin) Date: 12 Jan 2009 13:36:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> Message-ID: <7xfxjofbqw.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Why on earth are you using Python if you don't like the way it work ??? Why on earth keep releasing new versions of Python if the old ones are already perfect? From boblatest at yahoo.com Mon Jan 12 16:40:47 2009 From: boblatest at yahoo.com (Robert Latest) Date: 12 Jan 2009 21:40:47 GMT Subject: Python tricks References: Message-ID: <6t1rmuF8jrfaU1@mid.uni-berlin.de> RajNewbie wrote: > Is there a way - a python trick - to have a check such that if the > loop goes for more than x number of steps, it will cause an exception? > > I do understand that we can use the code like - > i = 0 > while True: > i++ > if i > 200: raise infinite_Loop_Exception > ... > if : break > > But I am not very happy with this code for 3 reasons > 1. Verbosity (i=0 and i++) which doesnt add to the logic > 2. The loop now has dual focus. - incrementing i, etc. > 3. A person looks into the code and thinks 'i' > has special significance. His/her mind will be focused on not the > actual reason for the loop. Maybe you should call the counter variable something meaningful instead of -- of all things -- "i", which is idiomatic for soething entirely else. And add a comment, and be done with it. > The solution that I had in mind is: > while True: > ... > if : break > if inifinte_loop(): raise infiinte_loop_exception This is a lot less understandable because whoever is working with your code will now have to check an additional function rather than a pretty self-explanatory variable increment. robert From boblatest at yahoo.com Mon Jan 12 16:44:10 2009 From: boblatest at yahoo.com (Robert Latest) Date: 12 Jan 2009 21:44:10 GMT Subject: Python tricks References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: <6t1rtaF8jrfaU2@mid.uni-berlin.de> RajNewbie wrote: > But, I still feel it would be much more aesthetically pleasing if I > can call a single procedure like > if infinite_loop() -> to do the same. You may find it aesthetically pleasing, and it may very well be, but it will obfuscate your code and make it less maintainable. robert From rt8396 at gmail.com Mon Jan 12 16:48:29 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 13:48:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> Message-ID: <1ead9f8d-e32f-4dd8-8dc3-aa26d4f01928@e10g2000vbe.googlegroups.com> On Jan 12, 2:06?pm, Bruno Desthuilliers wrote: > Why on earth are you using Python if you don't like the way it work ??? Why on earth are you busting into someone's thread just because you don't like what they have to say ??? From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 16:49:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 21:49:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > Bruno Desthuilliers writes: >> Why on earth are you using Python if you don't like the way it work ??? > > Why on earth keep releasing new versions of Python if the old ones are > already perfect? That's a fallacious argument. Nobody is arguing that any specific version of Python is perfect, but clearly many people do like the general design choices of the language, that is, the way it works. *If* you don't like the way it works, and you have a choice in the matter, perhaps you should find another language that works more the way you would prefer. On the other hand... Bruno's question is unfair. It is perfectly reasonable to (hypothetically) consider Python to be the best *existing* language while still wanting it to be improved (for some definition of improvement). Just because somebody has criticisms of Python, or a wish- list of features, doesn't mean they hate the language. -- Steven From rt8396 at gmail.com Mon Jan 12 16:54:45 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 13:54:45 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> [stevie] On the other hand... Bruno's question is unfair. It is perfectly reasonable to (hypothetically) consider Python to be the best *existing* language while still wanting it to be improved (for some definition of improvement). Just because somebody has criticisms of Python, or a wish- list of features, doesn't mean they hate the language. [/stevie] WOW Steven, i am very impressed. That's the first thing you have said in a very long time that i totally agree with! Keep this up and i may put you back on my Python Brethren list :) From http Mon Jan 12 16:58:28 2009 From: http (Paul Rubin) Date: 12 Jan 2009 13:58:28 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <7xtz84fapn.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > *If* you don't like the way it works, and you have a choice in the > matter, perhaps you should find another language that works more the way > you would prefer. We are in an era for programming languages sort of like the Windows 95 era was for operating systems, where everything is broken but some of the fixes are beginning to come into view. So there is no language that currently really works the right way, but some of them including Python are (one hopes) moving in good directions. Maybe I can help that process along by posting, maybe not. From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 17:00:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 22:00:35 GMT Subject: efficient interval containment lookup References: Message-ID: On Mon, 12 Jan 2009 11:36:47 -0800, Per Freem wrote: > hello, > > suppose I have two lists of intervals, one significantly larger than the > other. [...] > What is an efficient way to this? One simple way is: http://en.wikipedia.org/wiki/Interval_tree > for a_range in listA: > for b_range in listB: > is_within(b_range, a_range): > # accumulate a counter here > > where is_within simply checks if the first argument is within the > second. This will be O(m*n) where m is the size of the smaller list and n is the size of the big one. It shouldn't matter which order you do the loops, you still have to iterate over every point in each list, for every point in the other list. Using an interval tree may let you decrease the time to O(m*log n), at the cost of extra overhead, but for millions of items the saving should be large. -- Steven From martin at v.loewis.de Mon Jan 12 17:25:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 12 Jan 2009 23:25:15 +0100 Subject: python3.0 MySQLdb In-Reply-To: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <496BC34B.2050406@v.loewis.de> > I need something to connect to a database, preferably mysql, that > works in python3.0 please. For postgres, psycopg2 works with Python 3 (if you use my patch). Regards, Martin From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 17:34:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Jan 2009 22:34:27 GMT Subject: urllib2 - 403 that _should_ not occur. References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: On Mon, 12 Jan 2009 00:38:20 -0600, Chris Mellon wrote: >> Why Google would deny access to services by unknown User Agents is >> beyond me - especially since in most cases User Agents strings are not >> strict. > > If you look at the actual response text and not just the error code, you > will get a clear explanation of why you were forbidden. You have a funny idea of what constitutes a "clear explanation".

Forbidden

Your client does not have permission to get URL /group/chromium- announce/feed/rss_v2_0_msgs.xml from this server. That hardly explains "Why Google would deny access to services by unknown User Agents", does it? -- Steven From arkanes at gmail.com Mon Jan 12 17:43:32 2009 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 12 Jan 2009 16:43:32 -0600 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: <24433E68-1A87-4BD4-A894-C701C071D801@semanchuk.com> Message-ID: <4866bea60901121443h73e299f0s2f47e272c4bc0037@mail.gmail.com> On Mon, Jan 12, 2009 at 4:34 PM, Steven D'Aprano wrote: > On Mon, 12 Jan 2009 00:38:20 -0600, Chris Mellon wrote: > >>> Why Google would deny access to services by unknown User Agents is >>> beyond me - especially since in most cases User Agents strings are not >>> strict. >> >> If you look at the actual response text and not just the error code, you >> will get a clear explanation of why you were forbidden. > > You have a funny idea of what constitutes a "clear explanation". > > >

Forbidden

> Your client does not have permission to get URL /group/chromium- > announce/feed/rss_v2_0_msgs.xml from this server. > > > That hardly explains "Why Google would deny access to services by unknown > User Agents", does it? > > I suppose I should have checked that specific URL. The search results pages (last I checked) gave a detailed error message. From jstroud at mbi.ucla.edu Mon Jan 12 17:45:20 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 14:45:20 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: Roger wrote: > I'm sorry for harassing the list but any suggestions would be greatly > appreciated. =) I just checked the behavior you are describing. It seems that you want to unbind the event to stop the autoscrolling when you leave the listbox. E.g.: from Tkinter import * tk = Tk() lb = Listbox(tk) lb.pack() tk.tk.call('bind', str(lb), '', "break") for i in range(12): lb.insert(END, str(i)) Sorry for not reading more carefully. James From perfreem at yahoo.com Mon Jan 12 17:49:43 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 14:49:43 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: thanks for your replies -- a few clarifications and questions. the is_within operation is containment, i.e. (a,b) is within (c,d) iff a >= c and b <= d. Note that I am not looking for intervals that overlap... this is why interval trees seem to me to not be relevant, as the overlapping interval problem is way harder than what I am trying to do. Please correct me if I'm wrong on this... Scott Daniels, I was hoping you could elaborate on your comment about bisect. I am trying to use it as follows: I try to grid my space (since my intervals have an upper and lower bound) into segments (e.g. of 100) and then I take these "bins" and put them into a bisect list, so that it is sorted. Then when a new interval comes in, I try to place it within one of those bins. But this is getting messy: I don't know if I should place it there by its beginning number or end number. Also, if I have an interval that overlaps my boundaries -- i.e. (900, 1010) when my first interval is (0, 1000), I may miss some items from listB when i make my count. Is there an elegant solution to this? Gridding like you said seemed straight forward but now it seems complicated.. I'd like to add that this is *not* a homework problem, by the way. On Jan 12, 4:05?pm, Robert Kern wrote: > [Apologies for piggybacking, but I think GMane had a hiccup today and missed the > original post] > > [Somebody wrote]: > > >> suppose I have two lists of intervals, one significantly larger than > >> the other. > >> For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain > >> thousands > >> of elements while listB (of the same form) might contain hundreds of > >> thousands > >> or millions of elements. > >> I want to count how many intervals in listB are contained within every > >> listA. For example, if listA = [(10, 30), (600, 800)] and listB = > >> [(20, 25), (12, 18)] is the input, then the output should be that (10, > >> 30) has 2 intervals from listB contained within it, while (600, 800) > >> has 0. (Elements of listB can be contained within many intervals in > >> listA, not just one.) > > Interval trees. > > http://en.wikipedia.org/wiki/Interval_tree > > -- > 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 rt8396 at gmail.com Mon Jan 12 17:52:02 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 14:52:02 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> Message-ID: <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> On Jan 12, 3:58?pm, Paul Rubin wrote: > We are in an era for programming languages sort of like the Windows 95 > era was for operating systems, where everything is broken but some of > the fixes are beginning to come into view. ?So there is no language > that currently really works the right way, but some of them including > Python are (one hopes) moving in good directions. ?Maybe I can help > that process along by posting, maybe not. Paul, Python is the best hope for readable, maintainable very high-level coding. Python forged the path and showed all other languages for what they truly are; archaic, redundant, pieces of complete rubbish! In my mind only 2 languages stand out in the very high level category; Python and Ruby. Ruby only exists in this world because of the things it took from Python. Nobody would touch Ruby without it's Pythonisms. Python wins hands down, WHY? you ask. Well i could list a thousand reasons why but i will only cover a few. 1.) read-ability 2.) learn-ability 3.) maintain-ability 4.) perfect choice of keywords 5.) no end statement, braces, or lisps! 6.) no forced capitalizations 7.) modules are the actual script name 8.) introspection 9.) class, and class inheritance is beautiful 8.) true procedural support(no instance vars needed) 10.) loads of quality documentation! 11.) IDLE 12.) Guido (the genius that made all this happen!) I could keep going for days and days. Python is hands down the best thing that ever happened to the world of programming. Sure it could use a few improvements, nothing and nobody is perfect. But can any language stand toe to toe with Python? HELL NO! From jstroud at mbi.ucla.edu Mon Jan 12 17:58:58 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 14:58:58 -0800 Subject: Unbinding Tkinter default bindings for Listbox In-Reply-To: References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: James Stroud wrote: > tk.tk.call('bind', str(lb), '', "break") Which is equivalent to lb.bind('', "break") But I checked and overriding the default behavior of Listbox does not work (tk.tk.call('bind', "Listbox", '', "break")). So I would subclass Listbox and do the bindings in the __init__: class MyListbox(Listbox): def __init__(self, *args, **kwargs): Listbox.__init__(self, *args, **kwargs) self.bind('', "break") James From sjmachin at lexicon.net Mon Jan 12 18:03:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 15:03:20 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: <0268015d-e31b-4931-97cd-a92fcd74c567@p36g2000prp.googlegroups.com> On Jan 13, 6:12?am, Christian Heimes wrote: > > I say again, show me a case of working 2.5 code where prepending u to > > an ASCII string constant that is intended to be used in a text context > > is actually worth the keystrokes. > > Eventually you'll learn it the hard way. *sigh* And the hard way involves fire and brimstone, together with weeping, wailing and gnashing of teeth, correct? Hmmm, let's see. Let's take Carl's example of the sinner who didn't decode the input: """ Someone found that urllib.open() returns a bytes object in Python 3.0, which messed him up since in 2.x he was running regexp searches on the output. If he had been taking care to use only unicode objects in 2.x (in this case, by explicitly decoding the output) then it wouldn't have been an issue. """ 3.0 says: | >>> re.search("foo", b"barfooble") | Traceback (most recent call last): | File "", line 1, in | File "C:\python30\lib\re.py", line 157, in search | return _compile(pattern, flags).search(string) | TypeError: can't use a string pattern on a bytes-like object The problem is diagnosed at the point of occurrence with a 99%-OK exception message. Why only 99%? Because it only vaguely hints at this possibility: | >>> re.search(b"foo", b"barfooble") | <_sre.SRE_Match object at 0x00FACD78> Obvious solution (repent and decode): | >>> re.search("foo", b"barfooble".decode('ascii')) | <_sre.SRE_Match object at 0x00FD86B0> This is "messed him up"? One can get equally "messed up" when AFAICT one is doing the right thing in 2.X e.g. one is digging XML documents out of a ZIP file (str in 2.X, bytes in 3.x). ElementTree.parse() requires a file, so in 2.X one uses cStringIO.StringIO. 2to3 changes that to io.StringIO [quite reasonable; no easy way of knowing if BytesIO would be better; StringIO more probable]. 3.X barfs on the io.StringIO(xml_bytes) with a reasonable message "TypeError: can't write bytes to text stream" [momentarily puzzling -- write? Oh yeah, it happens in self.write(initial_value)] so there's a need to setup a BYTESIO that's conditional on Python version -- not a big deal at all. I see no /Inferno/ here :-) From pecora at anvil.nrl.navy.mil Mon Jan 12 18:12:19 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Mon, 12 Jan 2009 15:12:19 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: In article , Roy Smith wrote: > In article > <34c95e04-5b3f-44bc-a5bf-498518507131 at p36g2000prp.googlegroups.com>, > "Madhusudan.C.S" wrote: > > > In such situations, where the Instance variables come into existence > > only when they are used it is very difficult to track the flow of code. > > As the saying goes, "It's possible to write Fortran in any language". > > My personal habit is to "declare" all instance variables in the __init__() > method of every class. If there's no better value, I set them to None. > This isn't strictly required, but I think it makes it easier for somebody > reading the code to understand the class. I agree with you. I do exactly this. It prevents a lot of problems by giving one place to look for class variables and comments on them. Setting to None is good, too, since many times if I use one before setting a value I'll get an exception or really bad results that I can easily trace to the unset variable. > I'm not a big fan of dogmatic rules, other than the rule that says you > should make your code as easy for somebody else to understand as possible. Right. -- -- Lou Pecora From http Mon Jan 12 18:34:23 2009 From: http (Paul Rubin) Date: 12 Jan 2009 15:34:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> Message-ID: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> r writes: > Python and Ruby. Ruby only exists in this world because of the things > it took from Python. Nobody would touch Ruby without it's Pythonisms. I confess to not knowing much about Ruby. It looks sort of Perl-ish to me, and I always hear it is slower than Python, which is already too slow. > Python wins hands down, WHY? you ask. Well i could list a thousand > reasons why but i will only cover a few. > > 1.) read-ability > 2.) ... > I could keep going for days and days. Python is hands down the best > thing that ever happened to the world of programming. Sure it could > use a few improvements, nothing and nobody is perfect. But can any > language stand toe to toe with Python? HELL NO! Those things on your list are all nice, but I think Python has considerable room for improvement in several areas: 1) Parallelism. Commodity desktop computers now have 8 effective cpu cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still has the evil GIL that forces all threads to run on one core. Java, Erlang, and Haskell (GHC) all beat Python in this area. By the time Python 4 comes out, we will probably all be using PC's with 32 or more cores, so the current limitations will be intolerable. Even today, since no one doing anything serious uses single core machines any more, the GIL is a huge pain in the neck which the multiprocessing module helps only slightly. (While we are at it, lightweight threads like Erlang's or GHC's would be very useful.) 2) Native-code compilation. Per the Alioth shootouts, Python is much slower (even on single cores) than Java, Haskell, ML, or even Scheme. PyPy is addressing this but it will be a while before it replaces CPython. 3) Data encapsulation, the subject of most of this thread. 4) Static analysis. It would be great if there were a much more powerful Pylint that could do ML-like type inference among other things. You could still program in a dynamic, heterogeneous style if you wanted to, but Pylint would complain about it unless you supplied some annotations to tell it where the dynamism was and how to separate it from the rest of the program. This is consistent with Python's "consenting adults" principle: if consenting adults want to participate in a BDSM scene, they should be allowed to. There would probably have to be some new language features to assist in writing typefully. Python 3.0 has some gestures in this direction but they are not yet fully formed. I believe that the PyPy project is developing the above areas in ways CPython really could not. While we are now committed to Python 3.0 being a CPython revision that makes some minor (and in my view somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 will be based on PyPy and have more substantial differences. From gert.cuykens at gmail.com Mon Jan 12 18:35:52 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 12 Jan 2009 15:35:52 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496BC34B.2050406@v.loewis.de> Message-ID: Its for testing mod_wsgi trunk on Python3.0 in combination with a database. Does anybody has a patch for MySQLdb ? From deets at nospam.web.de Mon Jan 12 18:45:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 00:45:41 +0100 Subject: Simple CGI-XMLRPC failure In-Reply-To: References: Message-ID: <6t2315F8lo1gU1@mid.uni-berlin.de> Mike MacHenry schrieb: > I am having a difficult time understanding why my very simple > CGI-XMLRPC test isn't working. I created a server to export two > functions, the built-in function "pow" and my own identity function > "i". I run a script to call both of them and the "pow" work fine but > the "i" gives me an error that says my XMLRPC server doesn't support > than name. Here is the code for both files and the output: > > #!/usr/bin/env python > #This file is /usr/lib/cgi-bin/roundwarerpc.py > from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > def i(x): > return x > server = CGIXMLRPCRequestHandler() > server.register_function(pow) > server.register_function(i) > server.handle_request() > > > #!/usr/bin/env python > #This file is ~/test.py > import xmlrpclib > server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > print server.pow(2,3) > print server.i(10) > > #This is the STDOUT and STDERR when running ~/test.py > dskippy at dskippy-laptop:$ python test.py 8 > Traceback (most recent call last): > File "test.py", line 4, in > print server.test(10) > File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > return self.__send(self.__name, args) > File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > verbose=self.__verbose > File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > return self._parse_response(h.getfile(), sock) > File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > return u.close() > File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > raise Fault(**self._stack[0]) > xmlrpclib.Fault: :method "i" > is not supported'> > > Does anyone know what might be wrong with this? This works. --- import threading from SimpleXMLRPCServer import SimpleXMLRPCServer def i(x): return x server = SimpleXMLRPCServer(('localhost', 10000)) server.register_function(pow) server.register_function(i) t = threading.Thread(target=server.serve_forever) t.setDaemon(True) t.start() import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost:10000") print server.pow(2,3) print server.i(10) --- So maybe i is somehow an instance-variable of CGIXMLRPCRequestHandler. What happens if you rename it? Diez From ajaksu at gmail.com Mon Jan 12 18:48:50 2009 From: ajaksu at gmail.com (ajaksu) Date: Mon, 12 Jan 2009 15:48:50 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 11, 11:59?pm, "James Mills" wrote: > Hey all, > > The following fails for me: > > >>> from urllib2 import urlopen > >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") > > Traceback (most recent call last): [...] > Any helpful ideas ? Maybe raise a real bug @ bugs.python.org instead of just mentioning it like I did: http://bugs.python.org/msg77889 I think at least some sites would be willing to add the new UA to their whitelists. HTH, Daniel From deets at nospam.web.de Mon Jan 12 18:49:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 00:49:04 +0100 Subject: debugging ignored exceptions at cleanup In-Reply-To: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> References: <1cc2674d-a96d-491c-a3da-560c12901541@r15g2000prh.googlegroups.com> Message-ID: <6t237gF8lo1gU2@mid.uni-berlin.de> Michele Simionato schrieb: > In some conditions (typically with threads, __del__ methods, etc) the > cleanup mechanism of Python gets in trouble and some exceptions are > not raised but just printed on stderr. > I have an application using Paste and when I run the tests I get some > annoying > ignored exceptions during cleanup. Running the code with the -v option > I get things > like that: > > > # cleanup[2] sqlalchemy.util > # cleanup[2] sqlalchemy.sql.expression > # cleanup[2] symbol > # cleanup[2] urllib2 > # cleanup[2] sqlalchemy.orm.query > # cleanup[2] smweb.config > # cleanup[2] formencode > # cleanup[2] smweb.config.environment > Exception exceptions.TypeError: "'NoneType' object is not callable" in > at 0x26861b8> ignored > Exception exceptions.TypeError: "'NoneType' object is not callable" in > at 0x2598578> ignored > # cleanup[2] dbhash > # cleanup[2] xmlrpclib > # cleanup[2] mako.pygen > # cleanup[2] time > # cleanup[2] paste.util.import_string > # cleanup sys > # cleanup __builtin__ > # cleanup ints: 5096 unfreed ints in 145 out of 171 blocks > # cleanup floats: 43 unfreed floats in 3 out of 4 blocks > > As you see, the exceptions happen during the cleanup of > smweb.config.environment, > which the part of code I wrote, but which has no obvious problems and > imports > *lots* of other stuff. Is there some way to hook in the cleanup > mechanism, start > a pdb and see really what is happening? I tried to trace the execution > flow with the > trace module but without success. There is so much code there that I > am unable > to track down the source of the problem. I suspect there is some > __del__ method > somewhere that tries to call a function which has been set to None by > the cleanup > mechanism, possibly from another thread, but I cannot find it. How am > I supposed to > debug such things? You aren't I guess. AFAIK, you can't do anything about this - if there is really some cleanup todo, it should be done before exiting the program. I for once know that the TurboMail lib has had similar problems - and the "fix" was to check the used names in __del__ before trying to invoke anything on them. Even *that* might not help in a multi-threaded environment though, nobody can guarantee that between the check and the usage of a name the underlying object isn't GCed. Diez From excord80 at gmail.com Mon Jan 12 18:55:07 2009 From: excord80 at gmail.com (excord80) Date: Mon, 12 Jan 2009 15:55:07 -0800 (PST) Subject: Egg deinstallation References: Message-ID: <41a0569f-0b7c-4900-9476-a28837a9ac30@k9g2000vbl.googlegroups.com> On Jan 12, 9:36?am, mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? As an aside, note that there's no automated way to uninstall (for exmaple, like doing "aptitude purge" or "make uninstall"). It's a known problem with setuptools/eggs/easy_install/whatever. Dunno if pip [1] yet solves this problem or not. http://pip.openplans.org/ From pavlovevidence at gmail.com Mon Jan 12 19:00:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 12 Jan 2009 16:00:19 -0800 (PST) Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> <0268015d-e31b-4931-97cd-a92fcd74c567@p36g2000prp.googlegroups.com> Message-ID: On Jan 12, 5:03?pm, John Machin wrote: > On Jan 13, 6:12?am, Christian Heimes wrote: > > > > I say again, show me a case of working 2.5 code where prepending u to > > > an ASCII string constant that is intended to be used in a text context > > > is actually worth the keystrokes. > > > Eventually you'll learn it the hard way. *sigh* > > And the hard way involves fire and brimstone, together with weeping, > wailing and gnashing of teeth, correct? Hmmm, let's see. Let's take > Carl's example of the sinner who didn't decode the input: """ Someone > found that urllib.open() returns a bytes object in Python 3.0, which > messed him up since in 2.x he was running regexp searches on the > output. ?If he had been taking care to use only unicode objects in 2.x > (in this case, by explicitly decoding the output) then it wouldn't > have been an issue. """ > > 3.0 says: > | >>> re.search("foo", b"barfooble") > | Traceback (most recent call last): > | ? File "", line 1, in > | ? File "C:\python30\lib\re.py", line 157, in search > | ? ? return _compile(pattern, flags).search(string) > | TypeError: can't use a string pattern on a bytes-like object > > The problem is diagnosed at the point of occurrence with a 99%-OK > exception message. Why only 99%? Because it only vaguely hints at this > possibility: > | >>> re.search(b"foo", b"barfooble") > | <_sre.SRE_Match object at 0x00FACD78> > > Obvious solution (repent and decode): > | >>> re.search("foo", b"barfooble".decode('ascii')) > | <_sre.SRE_Match object at 0x00FD86B0> > > This is "messed him up"? If you believe in waiting for bugs to occur and then fixing them, rather than programming to avoid bugs, there is no helping you. P.S. The "obvious" solution is wrong, although I'm not sure if you were making some kind of ironic point. Carl Banks From gdamjan at gmail.com Mon Jan 12 19:31:38 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jan 2009 01:31:38 +0100 Subject: Problem with -3 switch References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> Message-ID: > Perhaps you also like to hear from a developer who has worked on > Python 3.0 itself and who has done lots of work with internationalized > applications. If you want to get it right you must > > * decode incoming text data to unicode as early as possible > * use unicode for all internal text data > * encode outgoing unicode as late as possible. > > where incoming data is read from the file system, database, network > etc. amen to that... I hate all those apps/libs that only work with ASCII. -- ?????? ( http://softver.org.mk/damjan/ ) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From steve at holdenweb.com Mon Jan 12 19:33:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 19:33:09 -0500 Subject: hlep: a text search and rename question In-Reply-To: <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> References: <05566243-60dd-4b96-b2e5-a03bcbb422b6@s9g2000prg.googlegroups.com> <7FFal.17509$Ws1.14688@nlpi064.nbdc.sbc.com> <4008cd38-094a-40a1-84aa-13737c90753a@s1g2000prg.googlegroups.com> <7a394099-00e2-4c63-9d5a-de62edc770e4@n10g2000yqm.googlegroups.com> Message-ID: sensen wrote: > On Jan 12, 10:41 pm, sensen wrote: >> both above works well, but a problem is renamed file is without >> filename extension. >> >> only change to the title. >> >> for example, the origin file is track_1.flac, after run the script i >> want it to for example, White Flag.flac, but now it change to White >> Flag without extension. >> >> could you do a favor to fix it. thank you. > > fixed it, i check the reference of python. > the last line from > os.rename(old, new) > changed to > os.rename(old, new+'.flac') > > thanks, now i still try to read the reference of python. > i want to the script can know what file it will open. in other words, > the script maybe first do a search, and get the exactly file name of > the cue type file in the folder, then open it. Well done - the true Python spirit. Fix it yourself when you can. And now you know a bit more about the logic James so kindly wrote for you. Congratulations, and welcome to the Python community. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gdamjan at gmail.com Mon Jan 12 19:43:34 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jan 2009 01:43:34 +0100 Subject: redirecting stderr back.. References: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Message-ID: > Hi All, > > Can someone tell me how to redirect stderr back to the console once > you've moved it? > > import os,sys > se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) > sys.stderr.write("Foobar\n") > Foobar > os.dup2(se, 2) why not os.dup2(2, 10) and then later os.dup2(10, 2) -- ?????? ( http://softver.org.mk/damjan/ ) Begin...the rest is easy. From jeff at jmcneil.net Mon Jan 12 19:47:20 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 12 Jan 2009 16:47:20 -0800 (PST) Subject: Egg deinstallation References: Message-ID: <90b54e54-70a9-49cb-9b72-a9c2fb5fb68d@z1g2000yqn.googlegroups.com> On Jan 12, 9:36?am, mk wrote: > Hello everyone, > > I googled and googled and can't seem to find the definitive answer: how > to *properly* deinstall egg? Just delete the folder and/or .py and .pyc > files from Lib/site-packages? Would that break anything in Python > installation or not? > > Regards, > mk You might find a tool like VirtualEnv (http://pypi.python.org/pypi/ virtualenv/1.3.2) useful. It allows you to create a localized sandbox such that you don't stomp all over your system installation or require elevated privileges. It's good for development or toying with different eggs. When you're done, simply blow away the environment. I've used it for just about everything over the past few months, it's a wonderful tool. Jeff From mauriceling at gmail.com Mon Jan 12 19:47:34 2009 From: mauriceling at gmail.com (mauriceling@acm.org) Date: Mon, 12 Jan 2009 16:47:34 -0800 (PST) Subject: [ANN] The Python Papers Volume 3 Issue 3 Message-ID: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> Hi everyone First of all, let me apologize for the delay of this issue of TPP. I understand that all of you had been anxiously waiting and I do sincerely apologize that Christmas and New Year celebrations are taking a toll on my time. Finally, here it is... Volume 3 Issue 3... And we are THIRD year in business. As usual, the issue can be found at http://ojs.pythonpapers.org/index.php/tpp/issue/current The 1-PDF per issue will be released shortly. Let me also take this opportunity to show our deep felt appreciation to all our supporters/readers and contributors. Without you, we will not have our day to serve the community. At this moment, I will also like to announce our new publication schedule - there will not be any!!! Oppss, that did not come out right... What I am trying to say is that from Volume 4 Issue 1 onwards, we will adopt the "fast publishing" method that many journals are using. We will be releasing each article out to the public as they are being accepted but each issue will be delimited by our usual ?issue release? date. The ?issue release? date is then our cutoff deadline to prepare the 1-PDF per issue file. This means that we will be serving new articles to everyone much faster than now and there will not be anymore meaningful publication schedules. Hence, let's gear up to another year of exciting Python development and a recovering economy. Happy reading Maurice Ling Co-EIC, The Python Papers Anthology From sjmachin at lexicon.net Mon Jan 12 19:55:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 12 Jan 2009 16:55:21 -0800 (PST) Subject: read a password protected xls file References: <567034d3-32b7-4954-a3ce-fae716159ded@k1g2000prb.googlegroups.com> Message-ID: <30a129df-9800-4896-ba2b-80838d94fb01@i18g2000prf.googlegroups.com> On Jan 13, 3:35?am, thomas.steffe... at googlemail.com wrote: > Hello, > how can I read (and parse) a password protected xls file, perhaps with > the package xlrd? > Thanks for your hints, Thomas Perhaps not with xlrd. google("xlrd"); *first* hit displayed: """ Lingfo - xlrd extension 11 Jun 2007 ... Exclusions: xlrd will not attempt to decode password- protected (encrypted) files . Otherwise, it will safely and reliably ignore any of these ... www.lexicon.net/sjmachin/xlrd.htm - 15k - Cached - Similar pages - """ You'll need a Windows box with Excel installed. Get the package described here: http://wiki.python.org/moin/Win32All Install it, do the "makepy" thing [see the docs] to link with the Excel COM routines. Ask questions on the mailing list described on http://mail.python.org/mailman/listinfo/python-win32 Sample code: import sys import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") print "Excel library version:", xlApp.Version filename, password = sys.argv[1:3] # filename should be absolute path e.g. r'C:\myfiles\foo.xls' xlwb = xlApp.Workbooks.Open(filename, Password=password) # xlwb = xlApp.Workbooks.Open(filename) """ From the MS VBA Help for Excel 2003: Password Optional Variant. A string that contains the password required to open a protected workbook. If this argument is omitted and the workbook requires a password, the user is prompted for the password. """ print repr(xlwb) print xlwb.FullName xlws = xlwb.Sheets(1) # counts from 1, not from 0 print repr(xlws) print xlws.Name print xlws.Cells(1, 1) # that's A1 HTH, John From rdcollum at gmail.com Mon Jan 12 20:13:04 2009 From: rdcollum at gmail.com (Roger) Date: Mon, 12 Jan 2009 17:13:04 -0800 (PST) Subject: Unbinding Tkinter default bindings for Listbox References: <5dc5c01b-05de-4dc3-970c-9986bc1a7e34@r40g2000yqj.googlegroups.com> <5PFal.17510$Ws1.16807@nlpi064.nbdc.sbc.com> <90b6f9aa-cc0b-4992-bfa7-5e2f03b59d0b@h16g2000yqj.googlegroups.com> Message-ID: <32699b3e-9532-4d62-a459-1c6c2ffd59a4@w1g2000prk.googlegroups.com> On Jan 12, 5:58?pm, James Stroud wrote: > James Stroud wrote: > > tk.tk.call('bind', str(lb), '', "break") > > Which is equivalent to > > lb.bind('', "break") > > But I checked and overriding the default behavior of Listbox does not > work (tk.tk.call('bind', "Listbox", '', "break")). > > So I would subclass Listbox and do the bindings in the __init__: > > class MyListbox(Listbox): > ? ?def __init__(self, *args, **kwargs): > ? ? ?Listbox.__init__(self, *args, **kwargs) > ? ? ?self.bind('', "break") > > James You sir are awesome. Thank you so much. I've so far been really good at troubleshooting Tkinter, the library has really melded with my thinking naturally since I started using Python on a regular basis a year ago. I had mixed feelings about asking for help on this because I wanted so badly to figure it out myself but I became so exasperated especially after combing through the TCL source to no affect. Now that you've given me the correct solution it seems like the Leave event should have been a natural binding for me to break in all my fiddling. Ah well, it's a lesson I won't forget thanks to you. Thanks so much again, you're help is invaluable. =D Roger. From Russ.Paielli at gmail.com Mon Jan 12 20:48:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 12 Jan 2009 17:48:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: On Jan 12, 3:34 pm, Paul Rubin wrote: > r writes: > > Python and Ruby. Ruby only exists in this world because of the things > > it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. > > > Python wins hands down, WHY? you ask. Well i could list a thousand > > reasons why but i will only cover a few. > > > 1.) read-ability > > 2.) ... > > I could keep going for days and days. Python is hands down the best > > thing that ever happened to the world of programming. Sure it could > > use a few improvements, nothing and nobody is perfect. But can any > > language stand toe to toe with Python? HELL NO! > > Those things on your list are all nice, but I think Python has > considerable room for improvement in several areas: > > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) > > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. > > 3) Data encapsulation, the subject of most of this thread. > > 4) Static analysis. It would be great if there were a much more > powerful Pylint that could do ML-like type inference among other > things. You could still program in a dynamic, heterogeneous style if > you wanted to, but Pylint would complain about it unless you supplied > some annotations to tell it where the dynamism was and how to separate > it from the rest of the program. This is consistent with Python's > "consenting adults" principle: if consenting adults want to > participate in a BDSM scene, they should be allowed to. There would > probably have to be some new language features to assist in writing > typefully. Python 3.0 has some gestures in this direction but they > are not yet fully formed. > > I believe that the PyPy project is developing the above areas in ways > CPython really could not. While we are now committed to Python 3.0 > being a CPython revision that makes some minor (and in my view > somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 > will be based on PyPy and have more substantial differences. Thanks for that nice appraisal. I agree completely. I've suggested before here (as have others) that some sort of basic data encapsulation would be nice, but many Python users don't seem to want anything to do with it. Also, static analysis would be very desirable for my purposes. I would be more than happy to declare types if someone else would write an advanced static analyser that could make use of the type information and formally check the code for correctness. That has been done for other languages such as Java and Ada, and it can be very useful for safety-critical and mission-critical software. (I am currently developing a research prototype of safety-critical software.) I started looking at Scala a while back. It is has many nice features. It seamlessly combines object orientation with advanced functional programming. It is statically typed, but the types often do not need to be explicitly declared. It is fully "compatible" with Java, but (like Python) it is much less verbose and more elegant, typically requiring less (in some cases, much less) than half the lines of code for a given task. But I am reluctant to use Scala for several reasons. For example, it doesn't have "continue" and "break." The Scala folks claim they are unnecessary, but they are sure handy sometimes. Maybe my style is bad, but I use continue and break a lot, particularly continue. Getting by without them could be hard. The other thing is that Scala has no default arguments and no argument passing by keyword. Those are a couple of my favorite Python features. So I'm basically screwed. From jeff at jmcneil.net Mon Jan 12 21:02:04 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 12 Jan 2009 18:02:04 -0800 (PST) Subject: Simple CGI-XMLRPC failure References: Message-ID: On Jan 12, 12:40?pm, "Mike MacHenry" wrote: > I am having a difficult time understanding why my very simple > CGI-XMLRPC test isn't working. I created a server to export two > functions, the built-in function "pow" and my own identity function > "i". I run a script to call both of them and the "pow" work fine but > the "i" gives me an error that says my XMLRPC server doesn't support > than name. Here is the code for both files and the output: > > #!/usr/bin/env python > #This file is /usr/lib/cgi-bin/roundwarerpc.py > from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > def i(x): > ? ? ? ? return x > server = CGIXMLRPCRequestHandler() > server.register_function(pow) > server.register_function(i) > server.handle_request() > > #!/usr/bin/env python > #This file is ~/test.py > import xmlrpclib > server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > print server.pow(2,3) > print server.i(10) > > #This is the STDOUT and STDERR when running ~/test.py > dskippy at dskippy-laptop:$ python test.py 8 > Traceback (most recent call last): > ? File "test.py", line 4, in > ? ? print server.test(10) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > ? ? return self.__send(self.__name, args) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > ? ? verbose=self.__verbose > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > ? ? return self._parse_response(h.getfile(), sock) > ? File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > ? ? return u.close() > ? File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > ? ? raise Fault(**self._stack[0]) > xmlrpclib.Fault: :method "i" > is not supported'> > > Does anyone know what might be wrong with this? > > Thanks for the help, > -mike > > p.s. > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Server version Apache/2.2.8 (Ubuntu) > Server built: Jun 25 2008 13:54:13 I copied your code verbatim and I don't have any issues with it at all. Same version of Python, same version of Apache. In SimpleXMLRPCServer.py, register_function adds directly to a self.funcs dictionary, so an instance variable of the same name shouldn't hurt anything. That exception is only raised when a self.funcs lookup raises a KeyError unless you're registering an instance. From steve at holdenweb.com Mon Jan 12 21:14:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:14:28 -0500 Subject: redirecting stderr back.. In-Reply-To: References: <4d301841-9617-4511-ab04-b846f441e528@g3g2000pre.googlegroups.com> Message-ID: ?????? ??????????? wrote: > >> Hi All, >> >> Can someone tell me how to redirect stderr back to the console once >> you've moved it? >> >> import os,sys >> se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT) >> sys.stderr.write("Foobar\n") >> Foobar >> os.dup2(se, 2) > > why not os.dup2(2, 10) and then later os.dup2(10, 2) > I'd have thought it would be necessary to do something like that in the general case to ensure that the original standard error remained open. os.dup2 will close the original file unless it's still open on another descriptor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 21:16:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:16:24 -0500 Subject: ActiveState Python Together with "Regular" Python) ((DLE) In-Reply-To: <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> References: <8f39301c-1f4b-4bf9-a90b-28cd1a552e97@p36g2000prp.googlegroups.com> <3wJal.10247$W06.5199@flpi148.ffdc.sbc.com> Message-ID: W. eWatson wrote: > John Machin wrote: >> On Jan 12, 9:16 pm, "W. eWatson" wrote: >>> John Machin wrote: >>>> On Jan 12, 2:00 pm, "W. eWatson" wrote: >>>>> I installed "Python" 2.5 a few months ago with IDLE, and decided >>>>> I'd like to >>>>> try windowpy from ActiveState. Is having both of these installed >>>>> going to >>>>> cause me trouble? >>>> What is "windowpy from ActiveState"? If you mean you wanted to try the >>>> PythonWin IDE instead of IDLE, all you needed to do was go to >>>> http://sourceforge.net/projects/pywin32/hit the big download button >>>> and make sure you get the 2.5 version (it's the default atm) and >>>> install it. >>> Yes, I want to try the PythonWin IDE instead of IDLE. "(DLE" was a typo. >>> >>> Is it possible to just disable the vanilla (IDLE) version? I may want to >>> switch between the two. Most users of the program I'm about to modify >>> use >>> the vanilla version. At some point, I may want to go back to it to >>> verify >>> that in their world all is OK. >> >> I'll try again. All you need is (a) the official distribution of >> Python 2.5 for Windows from http://www.python.org (b) the pywin32 >> package from the URL I gave you. Install both. Click on Start / All >> Programs/ Python 2.5 and will find *BOTH* IDLE and PythonWin. You and/ >> or your users can use IDLE or PythonWin, only one copy of Python, no >> conflicts. Why do you think you need to "disable" IDLE? Just don't use >> it. >> > Once upon a time, six months ago, I asked a similar question and the > answer was more complex. I decided to put this off until I truly needed it. > > Even better than Start, for me, is that I can choose PythonWin or IDLE > from the right-click menu which I want. I do see a choice there of Open > With-> Python. I can see it executed properly, but which 2.5 did it use? > Both IDLE and PythonWin use the same interpreter - neither of them carry their own, and there's only one Python 2.5 available on your system. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kj7ny at nakore.com Mon Jan 12 21:19:29 2009 From: kj7ny at nakore.com (kj7ny) Date: Mon, 12 Jan 2009 18:19:29 -0800 (PST) Subject: Scheduled Tasks - SetFlags Message-ID: <88f5dbd9-ffa8-4498-9635-bfba8bdd1193@i18g2000prf.googlegroups.com> How do I enable/disable a scheduled task using Python? I can get to a task: self.ts=pythoncom.CoCreateInstance (taskscheduler.CLSID_CTaskScheduler,None,pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler) self.ts.SetTargetComputer(u'\\\\SomeServer') self.tasks=self.ts.Enum() for task in self.tasks: self.t=self.ts.Activate(task) if self.t.GetAccountInformation().lower().find('SomeUser') >=0: print self.t.GetFlags() I can find if a task is enabled or not and toggle it: disabled=self.t.GetFlags() & taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED print 'Originally Disabled: %s'%(disabled,) if disabled: self.t.SetFlags(self.t.GetFlags() & ~taskscheduler.TASK_FLAG_DISABLED) else: self.t.SetFlags(self.t.GetFlags() | taskscheduler.TASK_FLAG_DISABLED) disabled=self.t.GetFlags() & taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED print 'Recheck Disabled: %s'%(disabled,) ... "Recheck Disabled" shows that the value "says" it has been disabled. The problem is that if I run it again and again, "Originally Disabled" is always the same. In other words, "Recheck Disabled" does NOT stick. It's like I'm missing a .commit() For example: First run ... 8388 Originally Disabled: True Recheck Disabled: False Second run ... 8388 Originally Disabled: True Recheck Disabled: False How do I disable and enable a scheduled task in Windows using python? From steve at holdenweb.com Mon Jan 12 21:26:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:26:27 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: sturlamolden wrote: > On Jan 12, 1:52 pm, Sion Arrowsmith > wrote: > >> And today's moral is: try it before posting. Yeah, I can map a 2GB >> file no problem, complete with associated 2GB+ allocated VM. The >> addressing is clearly not working how I was expecting it too. > > The virtual memory space of a 32 bit process is 4 GB. > I believe, though, that in some environments 2GB of that is mapped onto the operating system, to allow system calls to access OS memory structures without any VM remapping being required - see http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx. Things have, however, improved if we are to believe what we read in http://www.tenouk.com/WinVirtualAddressSpace.html The very idea of mapping part of a process's virtual address space onto an area in which "low-level system code resides, so writing to this region may corrupt the system, with potentially catastrophic consequences" seems to be asking for trouble to me. It's surprising things used to don't go wrong with Windows all the time, really. Oh, wait a minute, they did, didn't they? Still do for that matter ... getting-sicker-of-vista-by-the-minute-ly yr's - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 12 21:29:15 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Jan 2009 21:29:15 -0500 Subject: Implementing file reading in C/Python In-Reply-To: <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: sturlamolden wrote: > On Jan 12, 1:52 pm, Sion Arrowsmith > wrote: > >> And today's moral is: try it before posting. Yeah, I can map a 2GB >> file no problem, complete with associated 2GB+ allocated VM. The >> addressing is clearly not working how I was expecting it too. > > The virtual memory space of a 32 bit process is 4 GB. > After my last post I should also point out a) That was specific to 32-bit processes, and b) http://regions.cmg.org/regions/mcmg/Virtual%20memory%20constraints%20in%2032bit%20Windows.pdf describes the situation better, and outliones some steps you can take to get relief. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rt8396 at gmail.com Mon Jan 12 22:33:11 2009 From: rt8396 at gmail.com (r) Date: Mon, 12 Jan 2009 19:33:11 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <38c9a46b-38b4-4529-a244-c7b6bbe5040d@e6g2000vbe.googlegroups.com> On Jan 12, 5:34?pm, Paul Rubin wrote: > r writes: > > Python and Ruby. Ruby only exists in this world because of the things > > it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. ?It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. There exists in the world of very-high-level languages only two big players -- Python and Ruby. The only reason Ruby even exist is because of what Mats stole from Python. Ruby is a corrupting and hideous language, that will ruin all future "scripters" with it's abominations of coding styles. Ruby is basically Perl's "Mini-Me". A small but deadly form of viral infection that will plague us all for many years to come with unreadable, unmaintainable code! I lament every day the creation of Ruby language. Ruby took the only good things it possess from Python. A little History Lesson: Python came into being around 1991 by a computer science genius named "Guido van Rossum". This man is truly a man before his time. Python revolutionized the world of programming and exposed the other languages for what they are. Archaic, and redundant pieces of petrified dino dookie. Python promotes good coding styles by indentation(ruby stole that) Python's syntax is clear, and choice of keywords is perfect(ruby stole some of that too). Python allows for true OOP and true procedural(ruby tried to steal that but failed miserably) I like to think of Python as simplistic programming elegance. No other high level language can compete with Python, so what did Ruby DEV do? They stole from Python, thats what! And they did not bother to mention this little tidbit of info to new recruits on their website!Tthey act as if Ruby were here first. And pay no respect to the path Python forged. Ruby owes it's very existence to Python! I will never get over the use of "end". Why on GODS green earth would you use indentation AND the "end" statement? That's completely redundant. That would be the same as using two periods at the end of a sentence.. Complete monkey logic! Python is better, but we must stay alert and not fall asleep at the wheel. I think Python DEV has good intention, but they do not realize the battle that lay ahead. We must fight to get Python in every API we can. We must stay on our toes and not let Ruby one-up us! I do not want to see Python go down the evolutionary toilet! Lets send Ruby to programming HELL! From philip at semanchuk.com Mon Jan 12 22:33:16 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 12 Jan 2009 22:33:16 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: On Jan 12, 2009, at 6:48 PM, ajaksu wrote: > On Jan 11, 11:59 pm, "James Mills" > wrote: >> Hey all, >> >> The following fails for me: >> >>>>> from urllib2 import urlopen >>>>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>> ") >> >> Traceback (most recent call last): > [...] >> Any helpful ideas ? > > Maybe raise a real bug @ bugs.python.org instead of just mentioning it > like I did: http://bugs.python.org/msg77889 > > I think at least some sites would be willing to add the new UA to > their whitelists. I don't think I understand you clearly. Whether or not Google et al whitelist the Python UA isn't a Python issue, is it? From rob.clewley at gmail.com Mon Jan 12 22:41:00 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Mon, 12 Jan 2009 22:41:00 -0500 Subject: Unexpected behavior with dictionary keys containment and a user-defined class Message-ID: Hi, the short version of my question is: when is a dictionary's __contains__ method behavior different to using the 'in' idiom? (because I have an example of a difference in my code). Longer version: I have a user-defined class with a few overrides of special methods, particularly __eq__ and __ne__. I also have a dictionary keyed by instances of these classes, and I'm confused about the unexpected behavior trying to test whether an instance is in the dictionary's keys. The instance is i and the dictionary is d. I have been using the idiom i in d which I understood to be the pythonic way to test the keys, but it doesn't work. However, when I debug my code I see the instance in the list of keys, and in fact i in d.keys() and d.keys()[10] == i both return True. But d.__contains__(i) d.has_key(i) d.keys()[10] is i return False. I put a print statement in my class's __eq__ method and it is being called. It tests equality of some of my class instance's attributes. I didn't realize there was any situation where you could expect different results from i in d versus i in d.keys() -- am I misunderstanding something? I'm not sure what other details to provide! Thanks a lot, Rob From jstroud at mbi.ucla.edu Mon Jan 12 22:56:19 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 12 Jan 2009 19:56:19 -0800 Subject: Unexpected behavior with dictionary keys containment and a user-defined class In-Reply-To: References: Message-ID: Rob Clewley wrote: > Hi, the short version of my question is: when is a dictionary's > __contains__ method behavior different to using the 'in' idiom? > (because I have an example of a difference in my code). Never. > Longer version: I have a user-defined class with a few overrides of > special methods, particularly __eq__ and __ne__. I also have a > dictionary keyed by instances of these classes, and I'm confused about > the unexpected behavior trying to test whether an instance is in the > dictionary's keys. The instance is i and the dictionary is d. I have > been using the idiom > > i in d > > which I understood to be the pythonic way to test the keys, but it > doesn't work. However, when I debug my code I see the instance in the > list of keys, and in fact > > i in d.keys() and d.keys()[10] == i > > both return True. But > > d.__contains__(i) > d.has_key(i) > d.keys()[10] is i > > return False. I put a print statement in my class's __eq__ method and > it is being called. It tests equality of some of my class instance's > attributes. I didn't realize there was any situation where you could > expect different results from i in d versus i in d.keys() -- > am I misunderstanding something? Well, the only conclusion is that dict uses the hash of an object to test containment while lists use id. James From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 22:58:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 03:58:40 GMT Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > thanks for your replies -- a few clarifications and questions. the > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >>= c and b <= d. Note that I am not looking for intervals that > overlap... this is why interval trees seem to me to not be relevant, as > the overlapping interval problem is way harder than what I am trying to > do. Please correct me if I'm wrong on this... To test for contained intervals: a >= c and b <= d To test for overlapping intervals: not (b < c or a > d) Not exactly what I would call "way harder". -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jan 12 23:05:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 04:05:57 GMT Subject: Unexpected behavior with dictionary keys containment and a user-defined class References: Message-ID: On Mon, 12 Jan 2009 22:41:00 -0500, Rob Clewley wrote: > Hi, the short version of my question is: when is a dictionary's > __contains__ method behavior different to using the 'in' idiom? (because > I have an example of a difference in my code). [...] > i in d.keys() and d.keys()[10] == i > > both return True. But > > d.__contains__(i) > d.has_key(i) > d.keys()[10] is i The instance you are testing for isn't the same instance as the one in the dictionary. It might be *equal*, but it isn't identical, and by default, hashing of classes goes by identity. You need to give your class a hash function so that whenever x==y hash(x)==hash(y) as well. That means you need to over-ride __hash__(self) in the class. > return False. I put a print statement in my class's __eq__ method and it > is being called. It tests equality of some of my class instance's > attributes. I didn't realize there was any situation where you could > expect different results from i in d versus i in d.keys() -- am > I misunderstanding something? i in d.keys() does an item-by-item equality test, returning the first time i is equal to an item. i in d hashes i, then looks up a table to see whether there is an item in that spot. If there is, it compares that item to i for equality. -- Steven From rob.clewley at gmail.com Mon Jan 12 23:13:49 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Mon, 12 Jan 2009 23:13:49 -0500 Subject: Unexpected behavior with dictionary keys containment and a user-defined class In-Reply-To: References: Message-ID: >> Hi, the short version of my question is: when is a dictionary's >> __contains__ method behavior different to using the 'in' idiom? >> (because I have an example of a difference in my code). > > Never. Yes, sorry, I managed to summarize the long version incorrectly :) > Well, the only conclusion is that dict uses the hash of an object to test > containment while lists use id. Great, thanks. I think a copy of my object has been made so that it doesn't hash to the same thing. I'll write a __hash__ as suggested in the other post. I forgot all about dictionary hashing for some reason... -Rob From http Mon Jan 12 23:44:16 2009 From: http (Paul Rubin) Date: 12 Jan 2009 20:44:16 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <38c9a46b-38b4-4529-a244-c7b6bbe5040d@e6g2000vbe.googlegroups.com> Message-ID: <7xocyblsrj.fsf@ruckus.brouhaha.com> r writes: > Python revolutionized the world of programming and exposed the other > languages for what they are. Archaic, and redundant pieces of > petrified dino dookie. ... We must fight to get Python in every API we > can. We must stay on our toes and not let Ruby one-up us! I do not > want to see Python go down the evolutionary toilet! Lets send Ruby to > programming HELL! Heh, I have to admire your enthusiasm. That testimonial is truly suitable for framing ;-) From perfreem at yahoo.com Mon Jan 12 23:55:36 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 20:55:36 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 10:58?pm, Steven D'Aprano wrote: > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > thanks for your replies -- a few clarifications and questions. the > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > >>= c and b <= d. Note that I am not looking for intervals that > > overlap... this is why interval trees seem to me to not be relevant, as > > the overlapping interval problem is way harder than what I am trying to > > do. Please correct me if I'm wrong on this... > > To test for contained intervals: > a >= c and b <= d > > To test for overlapping intervals: > > not (b < c or a > d) > > Not exactly what I would call "way harder". > > -- > Steven hi Steven, i found an implementation (which is exactly how i'd write it based on the description) here: http://hackmap.blogspot.com/2008/11/python-interval-tree.html when i use this however, it comes out either significantly slower or equal to a naive search. my naive search just iterates through a smallish list of intervals and for each one says whether they overlap with each of a large set of intervals. here is the exact code i used to make the comparison, plus the code at the link i have above: class Interval(): def __init__(self, start, stop): self.start = start self.stop = stop import random import time num_ints = 30000 init_intervals = [] for n in range(0, num_ints): start = int(round(random.random() *1000)) end = start + int(round(random.random()*500+1)) init_intervals.append(Interval(start, end)) num_ranges = 900 ranges = [] for n in range(0, num_ranges): start = int(round(random.random() *1000)) end = start + int(round(random.random()*500+1)) ranges.append((start, end)) #print init_intervals tree = IntervalTree(init_intervals) t1 = time.time() for r in ranges: tree.find(r[0], r[1]) t2 = time.time() print "interval tree: %.3f" %((t2-t1)*1000.0) t1 = time.time() for r in ranges: naive_find(init_intervals, r[0], r[1]) t2 = time.time() print "brute force: %.3f" %((t2-t1)*1000.0) on one run, i get: interval tree: 8584.682 brute force: 8201.644 is there anything wrong with this implementation? it seems very right to me but i am no expert. any help on this would be relly helpful. From grante at visi.com Mon Jan 12 23:55:41 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 12 Jan 2009 22:55:41 -0600 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: <0qOdnR88rIFQg_HUnZ2dnUVZ_o7inZ2d@posted.usinternet> On 2009-01-13, Steve Holden wrote: > sturlamolden wrote: >> On Jan 12, 1:52 pm, Sion Arrowsmith >> wrote: >> >>> And today's moral is: try it before posting. Yeah, I can map a 2GB >>> file no problem, complete with associated 2GB+ allocated VM. The >>> addressing is clearly not working how I was expecting it too. >> >> The virtual memory space of a 32 bit process is 4 GB. >> > I believe, though, that in some environments 2GB of that is mapped onto > the operating system, to allow system calls to access OS memory > structures without any VM remapping being required IIRC, in Linux the default for the past several years has been 3GB user, 1GB kernel. But, there are kernel configuration options to enable different configurations. > getting-sicker-of-vista-by-the-minute-ly yr's - steve Haven't had to touch Vista yet -- I'm annoyed enough by XP. -- Grant From perfreem at yahoo.com Mon Jan 12 23:58:03 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 20:58:03 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> i forgot to add, my naive_find is: def naive_find(intervals, start, stop): results = [] for interval in intervals: if interval.start >= start and interval.stop <= stop: results.append(interval) return results On Jan 12, 11:55?pm, Per Freem wrote: > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > thanks for your replies -- a few clarifications and questions. the > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > >>= c and b <= d. Note that I am not looking for intervals that > > > overlap... this is why interval trees seem to me to not be relevant, as > > > the overlapping interval problem is way harder than what I am trying to > > > do. Please correct me if I'm wrong on this... > > > To test for contained intervals: > > a >= c and b <= d > > > To test for overlapping intervals: > > > not (b < c or a > d) > > > Not exactly what I would call "way harder". > > > -- > > Steven > > hi Steven, > > i found an implementation (which is exactly how i'd write it based on > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. > > here is the exact code i used to make the comparison, plus the code at > the link i have above: > > class Interval(): > ? ? def __init__(self, start, stop): > ? ? ? ? self.start = start > ? ? ? ? self.stop = stop > > import random > import time > num_ints = 30000 > init_intervals = [] > for n in range(0, > num_ints): > ? ? start = int(round(random.random() > *1000)) > ? ? end = start + int(round(random.random()*500+1)) > ? ? init_intervals.append(Interval(start, end)) > num_ranges = 900 > ranges = [] > for n in range(0, num_ranges): > ? start = int(round(random.random() > *1000)) > ? end = start + int(round(random.random()*500+1)) > ? ranges.append((start, end)) > #print init_intervals > tree = IntervalTree(init_intervals) > t1 = time.time() > for r in ranges: > ? tree.find(r[0], r[1]) > t2 = time.time() > print "interval tree: %.3f" %((t2-t1)*1000.0) > t1 = time.time() > for r in ranges: > ? naive_find(init_intervals, r[0], r[1]) > t2 = time.time() > print "brute force: %.3f" %((t2-t1)*1000.0) > > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 > > is there anything wrong with this implementation? it seems very right > to me but i am no expert. any help on this would be relly helpful. From imageguy1206 at gmail.com Tue Jan 13 00:02:08 2009 From: imageguy1206 at gmail.com (imageguy) Date: Mon, 12 Jan 2009 21:02:08 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? Message-ID: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Using py2.5.4 and entering the following lines in IDLE, I don't really understand why I get the result shown in line 8. Note the difference between lines 7 and 10 is that 'else' clause result enclosed in brackets, however, in line 2, both the 'c,d' variables are assign correctly without the brackets being required. Any chance someone could enlighten me on the rules for tuple unpacking as this seems inconsistent. 1) >>> n = None 2) >>> c,d = n if n is not None else 0,0 3) >>> print c,d, type(c), type(d) 4) 0 0 5) >>> n = 22,11 6) >>> print n, type(n) (22, 11) 7) >>> c,d = n if n is not None else 0,0 8) >>> print c,d 9) (22, 11) 0 10) >>> c,d = n if n is not None else (0,0) 11) >>> print c,d 12) 22 11 From imageguy1206 at gmail.com Tue Jan 13 00:08:51 2009 From: imageguy1206 at gmail.com (imageguy) Date: Mon, 12 Jan 2009 21:08:51 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <9ee1d660-2fe4-4ada-ac67-d10580f75633@p36g2000prp.googlegroups.com> > understand why I get the result shown in line 8. >7) >>> c,d = n if n is not None else 0,0 >8) >>> print c,d >9) (22, 11) 0 OOPS sorry that should be line 9. g. From bpederse at gmail.com Tue Jan 13 00:24:45 2009 From: bpederse at gmail.com (brent) Date: Mon, 12 Jan 2009 21:24:45 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 8:55?pm, Per Freem wrote: > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > thanks for your replies -- a few clarifications and questions. the > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > >>= c and b <= d. Note that I am not looking for intervals that > > > overlap... this is why interval trees seem to me to not be relevant, as > > > the overlapping interval problem is way harder than what I am trying to > > > do. Please correct me if I'm wrong on this... > > > To test for contained intervals: > > a >= c and b <= d > > > To test for overlapping intervals: > > > not (b < c or a > d) > > > Not exactly what I would call "way harder". > > > -- > > Steven > > hi Steven, > > i found an implementation (which is exactly how i'd write it based on > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. > > here is the exact code i used to make the comparison, plus the code at > the link i have above: > > class Interval(): > ? ? def __init__(self, start, stop): > ? ? ? ? self.start = start > ? ? ? ? self.stop = stop > > import random > import time > num_ints = 30000 > init_intervals = [] > for n in range(0, > num_ints): > ? ? start = int(round(random.random() > *1000)) > ? ? end = start + int(round(random.random()*500+1)) > ? ? init_intervals.append(Interval(start, end)) > num_ranges = 900 > ranges = [] > for n in range(0, num_ranges): > ? start = int(round(random.random() > *1000)) > ? end = start + int(round(random.random()*500+1)) > ? ranges.append((start, end)) > #print init_intervals > tree = IntervalTree(init_intervals) > t1 = time.time() > for r in ranges: > ? tree.find(r[0], r[1]) > t2 = time.time() > print "interval tree: %.3f" %((t2-t1)*1000.0) > t1 = time.time() > for r in ranges: > ? naive_find(init_intervals, r[0], r[1]) > t2 = time.time() > print "brute force: %.3f" %((t2-t1)*1000.0) > > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 > > is there anything wrong with this implementation? it seems very right > to me but i am no expert. any help on this would be relly helpful. hi, the tree is inefficient when the interval is large. as the size of the interval shrinks to much less than the expanse of the tree, the tree will be faster. changing 500 to 50 in both cases in your script, i get: interval tree: 3233.404 brute force: 9807.787 so the tree will work for limited cases. but it's quite simple. check the tree in bx-python: http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/operations/quicksect.py for a more robust implementation. -brentp From perfreem at yahoo.com Tue Jan 13 00:34:42 2009 From: perfreem at yahoo.com (Per Freem) Date: Mon, 12 Jan 2009 21:34:42 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: hi brent, thanks very much for your informative reply -- didn't realize this about the size of the interval. thanks for the bx-python link. could you (or someone else) explain why the size of the interval makes such a big difference? i don't understand why it affects efficiency so much... thanks. On Jan 13, 12:24?am, brent wrote: > On Jan 12, 8:55?pm, Per Freem wrote: > > > > > On Jan 12, 10:58?pm, Steven D'Aprano > > > wrote: > > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > > thanks for your replies -- a few clarifications and questions. the > > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > > >>= c and b <= d. Note that I am not looking for intervals that > > > > overlap... this is why interval trees seem to me to not be relevant, as > > > > the overlapping interval problem is way harder than what I am trying to > > > > do. Please correct me if I'm wrong on this... > > > > To test for contained intervals: > > > a >= c and b <= d > > > > To test for overlapping intervals: > > > > not (b < c or a > d) > > > > Not exactly what I would call "way harder". > > > > -- > > > Steven > > > hi Steven, > > > i found an implementation (which is exactly how i'd write it based on > > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > > when i use this however, it comes out either significantly slower or > > equal to a naive search. my naive search just iterates through a > > smallish list of intervals and for each one says whether they overlap > > with each of a large set of intervals. > > > here is the exact code i used to make the comparison, plus the code at > > the link i have above: > > > class Interval(): > > ? ? def __init__(self, start, stop): > > ? ? ? ? self.start = start > > ? ? ? ? self.stop = stop > > > import random > > import time > > num_ints = 30000 > > init_intervals = [] > > for n in range(0, > > num_ints): > > ? ? start = int(round(random.random() > > *1000)) > > ? ? end = start + int(round(random.random()*500+1)) > > ? ? init_intervals.append(Interval(start, end)) > > num_ranges = 900 > > ranges = [] > > for n in range(0, num_ranges): > > ? start = int(round(random.random() > > *1000)) > > ? end = start + int(round(random.random()*500+1)) > > ? ranges.append((start, end)) > > #print init_intervals > > tree = IntervalTree(init_intervals) > > t1 = time.time() > > for r in ranges: > > ? tree.find(r[0], r[1]) > > t2 = time.time() > > print "interval tree: %.3f" %((t2-t1)*1000.0) > > t1 = time.time() > > for r in ranges: > > ? naive_find(init_intervals, r[0], r[1]) > > t2 = time.time() > > print "brute force: %.3f" %((t2-t1)*1000.0) > > > on one run, i get: > > interval tree: 8584.682 > > brute force: 8201.644 > > > is there anything wrong with this implementation? it seems very right > > to me but i am no expert. any help on this would be relly helpful. > > hi, the tree is inefficient when the interval is large. as the size of > the interval shrinks to much less than the expanse of the tree, the > tree will be faster. changing 500 to 50 in both cases in your script, > i get: > interval tree: 3233.404 > brute force: 9807.787 > > so the tree will work for limited cases. but it's quite simple. check > the tree in bx-python:http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/opera... > for a more robust implementation. > -brentp From steven at REMOVE.THIS.cybersource.com.au Tue Jan 13 00:47:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 05:47:29 GMT Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Mon, 12 Jan 2009 20:55:36 -0800, Per Freem wrote: > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 Here are three runs on my computer: interval tree: 10132.682 brute force: 12054.988 interval tree: 10355.058 brute force: 12119.227 interval tree: 9975.414 brute force: 12052.174 I find that interval tree is consistently faster than the brute force method, by a factor of at least 16%. I'd expect that benefit to increase dramatically as the number of intervals gets bigger. -- Steven From semanticist at gmail.com Tue Jan 13 01:01:24 2009 From: semanticist at gmail.com (Miles) Date: Tue, 13 Jan 2009 01:01:24 -0500 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > Using py2.5.4 and entering the following lines in IDLE, I don't really > understand why I get the result shown in line 8. > > Note the difference between lines 7 and 10 is that 'else' clause > result enclosed in brackets, however, in line 2, both the 'c,d' > variables are assign correctly without the brackets being required. > > 1) >>> n = None > 2) >>> c,d = n if n is not None else 0,0 > 3) >>> print c,d, type(c), type(d) > 4) 0 0 The ternary expression has higher precedence than the comma, so the actual effect of line 2 (and 8) is: >>> c, d = (n if n is not None else 0), 0 Or written more explicitly: >>> c = n if n is not None else 0 >>> d = 0 So the only correct way to write the expression, for the result you want, is to use your line 10: > 10) >>> c,d = n if n is not None else (0,0) But if you're struggling with the precedence issues, I'd recommend ditching ternary expressions altogether and using full conditional blocks. -Miles From javen72 at gmail.com Tue Jan 13 01:03:35 2009 From: javen72 at gmail.com (javen72 at gmail.com) Date: Mon, 12 Jan 2009 22:03:35 -0800 (PST) Subject: File buffer flush issue in multi-process in Windows Message-ID: <1bbaccea-26f2-4ed6-a61e-4e51eed1de60@h20g2000yqn.googlegroups.com> Hi, I encountered a very strange issue in file flush operation in Windows. Here's the scenario of my application: 1. The main thread of my application will create makefiles sequentially. 2. Once a makefile is generated, launch a new process calling nmake.exe to run it. The main thread then create another makefile until no more makefiles to create. 3. The number of new processes is limited by command line options. My application has been running for almost a year without any problem. But, after I made some changes recently to the content of makefile generated, "nmake.exe" in separate process sometimes complains that the makefile is not found. When I went into the directory, the makefile did exist there. Because I didn't change any thing related to file creation and the new makefiles are a little bit less than before, I guessed that the makefile just created hasn't been flushed to disk because of size change so the new process could not see it in a short time. So I decided add code to force flush file buffer after writing the file content (I didn't flush the file explicitly before). I did it like below: Fd = open(File, "w") Fd.write(Content) Fd.flush() os.fsync(Fd.fileno()) Fd.close() The strangest thing happened. The "makefile" missing happened more frequently than no flush operation. I searched the web but no answer there. Finally I tried to use Windows file API to create the file via pywin32 extension. The problem's gone. import win32file Fd = win32file.CreateFile( File, win32file.GENERIC_WRITE, 0, None, win32file.CREATE_ALWAYS, win32file.FILE_ATTRIBUTE_NORMAL, None ) win32file.WriteFile(Fd, str(Content), None) win32file.FlushFileBuffers(Fd) win32file.CloseHandle(Fd) I tried writing small python extension in C to make use Windows API to create file like above. It also works well, even I removed the FlushFileBuffers() calling. Did anyone encounter such problem before? Did I do something wrong in Python file operation? If not, I believe that there's a bug in Python file buffer mechanism. I'd appreciate any help or hints. Cheers, Javen From javen72 at gmail.com Tue Jan 13 01:06:20 2009 From: javen72 at gmail.com (javen72 at gmail.com) Date: Mon, 12 Jan 2009 22:06:20 -0800 (PST) Subject: File buffer flush issue in multi-process in Windows References: <1bbaccea-26f2-4ed6-a61e-4e51eed1de60@h20g2000yqn.googlegroups.com> Message-ID: <720c31c2-053b-4f70-902c-1202e318aeb2@u14g2000yqg.googlegroups.com> On 1?13?, ??2?03?, jave... at gmail.com wrote: > Hi, > > I encountered a very strange issue in file flush operation in Windows. > Here's the scenario of my application: > > 1. The main thread of my application will create makefiles > sequentially. > 2. Once a makefile is generated, launch a new process calling > nmake.exe to run it. The main thread then create another makefile > until no more makefiles to create. > 3. The number of new processes is limited by command line options. > > My application has been running for almost a year without any problem. > But, after I made some changes recently to the content of makefile > generated, "nmake.exe" in separate process sometimes complains that > the makefile is not found. When I went into the directory, the > makefile did exist there. > > Because I didn't change any thing related to file creation and the new > makefiles are a little bit less than before, I guessed that the > makefile just created hasn't been flushed to disk because of size > change so the new process could not see it in a short time. > > So I decided add code to force flush file buffer after writing the > file content (I didn't flush the file explicitly before). I did it > like below: > > Fd = open(File, "w") > Fd.write(Content) > Fd.flush() > os.fsync(Fd.fileno()) > Fd.close() > > The strangest thing happened. The "makefile" missing happened more > frequently than no flush operation. I searched the web but no answer > there. > > Finally I tried to use Windows file API to create the file via pywin32 > extension. The problem's gone. > > import win32file > Fd = win32file.CreateFile( > File, > win32file.GENERIC_WRITE, > 0, > None, > win32file.CREATE_ALWAYS, > win32file.FILE_ATTRIBUTE_NORMAL, > None > ) > win32file.WriteFile(Fd, str(Content), None) > win32file.FlushFileBuffers(Fd) > win32file.CloseHandle(Fd) > > I tried writing small python extension in C to make use Windows API to > create file like above. It also works well, even I removed the > FlushFileBuffers() calling. > > Did anyone encounter such problem before? Did I do something wrong in > Python file operation? If not, I believe that there's a bug in Python > file buffer mechanism. I'd appreciate any help or hints. > > Cheers, > Javen And the same application has no such problem in Linux. From steve at holdenweb.com Tue Jan 13 01:14:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:14:57 -0500 Subject: BadZipfile "file is not a zip file" In-Reply-To: <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> References: <0176fe8c$0$8693$c3e8da3@news.astraweb.com> <17473bee-24bc-462a-8ce9-a6cf830903f1@f13g2000yqj.googlegroups.com> <8f4da688-b602-4aa2-9177-36c8d807ce9b@z27g2000prd.googlegroups.com> <43e6ebdc-fe85-44a9-b406-9b3610dc961b@v39g2000pro.googlegroups.com> <5f5462db-8ca7-4553-a16b-ad6d485957c6@n21g2000vba.googlegroups.com> <362ac73e-6b08-40cc-a632-161aba27c375@x16g2000prn.googlegroups.com> Message-ID: webcomm wrote: > On Jan 12, 11:53 am, "Chris Mellon" wrote: [file distribution horror story ...] >> It's worth pointing out (although the provider probably doesn't care) >> that this isn't really an XML document and this was a bad way of them >> to distribute the data. If they'd used a correctly formatted XML >> document (with the prelude and everything) with the correct encoding >> information, existing XML parsers should have just Done The Right >> Thing with the data, instead of you needing to know the encoding a >> priori to extract an XML fragment. > > Agreed. I can't say I understand their rationale for doing it this way. Sadly their rationale is irrelevant to the business of making sense of the data, which we all hope you have eventually managed to do. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bpederse at gmail.com Tue Jan 13 01:15:41 2009 From: bpederse at gmail.com (brent) Date: Mon, 12 Jan 2009 22:15:41 -0800 (PST) Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: On Jan 12, 9:34?pm, Per Freem wrote: > hi brent, thanks very much for your informative reply -- didn't > realize this about the size of the interval. > > thanks for the bx-python link. ?could you (or someone else) explain > why the size of the interval makes such a big difference? i don't > understand why it affects efficiency so much... > > thanks. > > On Jan 13, 12:24?am, brent wrote: > > > On Jan 12, 8:55?pm, Per Freem wrote: > > > > On Jan 12, 10:58?pm, Steven D'Aprano > > > > wrote: > > > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > > > thanks for your replies -- a few clarifications and questions. the > > > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > > > > >>= c and b <= d. Note that I am not looking for intervals that > > > > > overlap... this is why interval trees seem to me to not be relevant, as > > > > > the overlapping interval problem is way harder than what I am trying to > > > > > do. Please correct me if I'm wrong on this... > > > > > To test for contained intervals: > > > > a >= c and b <= d > > > > > To test for overlapping intervals: > > > > > not (b < c or a > d) > > > > > Not exactly what I would call "way harder". > > > > > -- > > > > Steven > > > > hi Steven, > > > > i found an implementation (which is exactly how i'd write it based on > > > the description) here:http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > > > when i use this however, it comes out either significantly slower or > > > equal to a naive search. my naive search just iterates through a > > > smallish list of intervals and for each one says whether they overlap > > > with each of a large set of intervals. > > > > here is the exact code i used to make the comparison, plus the code at > > > the link i have above: > > > > class Interval(): > > > ? ? def __init__(self, start, stop): > > > ? ? ? ? self.start = start > > > ? ? ? ? self.stop = stop > > > > import random > > > import time > > > num_ints = 30000 > > > init_intervals = [] > > > for n in range(0, > > > num_ints): > > > ? ? start = int(round(random.random() > > > *1000)) > > > ? ? end = start + int(round(random.random()*500+1)) > > > ? ? init_intervals.append(Interval(start, end)) > > > num_ranges = 900 > > > ranges = [] > > > for n in range(0, num_ranges): > > > ? start = int(round(random.random() > > > *1000)) > > > ? end = start + int(round(random.random()*500+1)) > > > ? ranges.append((start, end)) > > > #print init_intervals > > > tree = IntervalTree(init_intervals) > > > t1 = time.time() > > > for r in ranges: > > > ? tree.find(r[0], r[1]) > > > t2 = time.time() > > > print "interval tree: %.3f" %((t2-t1)*1000.0) > > > t1 = time.time() > > > for r in ranges: > > > ? naive_find(init_intervals, r[0], r[1]) > > > t2 = time.time() > > > print "brute force: %.3f" %((t2-t1)*1000.0) > > > > on one run, i get: > > > interval tree: 8584.682 > > > brute force: 8201.644 > > > > is there anything wrong with this implementation? it seems very right > > > to me but i am no expert. any help on this would be relly helpful. > > > hi, the tree is inefficient when the interval is large. as the size of > > the interval shrinks to much less than the expanse of the tree, the > > tree will be faster. changing 500 to 50 in both cases in your script, > > i get: > > interval tree: 3233.404 > > brute force: 9807.787 > > > so the tree will work for limited cases. but it's quite simple. check > > the tree in bx-python:http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/opera... > > for a more robust implementation. > > -brentp > > well, i think if your search interval covers the entire span of the tree, you can't do better than just naive search as the tree just adds overhead. as the len of the search interval decreases relative to the span of the tree, the tree performs better. if all the intervals in the tree itself are long and overlapping, that tree just ... ugh ... doesnt work, because it has to do all the extra checks in the find() method anyway. the bx-python tree probably does a better job, but you set up a pretty rough test there. From steve at holdenweb.com Tue Jan 13 01:18:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:18:09 -0500 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: Daniel Fetchinson wrote: >> I need something to connect to a database, preferably mysql, that >> works in python3.0 please. > > And your question is? > > Surely it's fairly obvious that the question is "does such a thing exist, and if so where can I find it?". If that isn't obvious then please continue to lurk until it is. There's enough signal on this channel that we can do without such noise. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From timr at probo.com Tue Jan 13 01:21:08 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 13 Jan 2009 06:21:08 GMT Subject: win32gui References: Message-ID: Gandalf wrote: ? >Hi, everyone >I'm searching the win32gui lib to find a way to get the text under the >user cursor. >so far I managed to find only the controller ID which under the cursor >this way > >cursorID = win32gui.WindowFromPoint(win32gui.GetCursorPos()) > >their is function called GetWindowText I tried to use but it doesn't >work in most of the time > >someone know a way to do this? Did you not like the reply I gave you the first time you asked this question? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at holdenweb.com Tue Jan 13 01:22:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:22:12 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: Philip Semanchuk wrote: > > On Jan 12, 2009, at 6:48 PM, ajaksu wrote: > >> On Jan 11, 11:59 pm, "James Mills" >> wrote: >>> Hey all, >>> >>> The following fails for me: >>> >>>>>> from urllib2 import urlopen >>>>>> f = >>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>>>>> >>> >>> Traceback (most recent call last): >> [...] >>> Any helpful ideas ? >> >> Maybe raise a real bug @ bugs.python.org instead of just mentioning it >> like I did: http://bugs.python.org/msg77889 >> >> I think at least some sites would be willing to add the new UA to >> their whitelists. > > I don't think I understand you clearly. Whether or not Google et al > whitelist the Python UA isn't a Python issue, is it? > I'd say it's an issue relevant to Python users, which woudl seem to put it pretty much in the mainstream for c.l.py - especially as the code causing concern was written in Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:29:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:29:55 -0500 Subject: Problem with -3 switch In-Reply-To: References: <8f26f1f5-5315-4879-b696-8e3b62a0a157@z6g2000pre.googlegroups.com> <39641685-7988-428b-82ad-81eb4de5e45c@w1g2000prm.googlegroups.com> <495a0b5a-3927-4a72-bff5-bb00388593f3@r15g2000prh.googlegroups.com> <75b97a49-4d84-4757-96af-bc8f117208e0@p23g2000prp.googlegroups.com> Message-ID: Christian Heimes wrote: >>> Perhaps you also like to hear from a developer who has worked on Python >>> 3.0 itself and who has done lots of work with internationalized >>> applications. If you want to get it right you must >>> >>> * decode incoming text data to unicode as early as possible >>> * use unicode for all internal text data >>> * encode outgoing unicode as late as possible. >>> >>> where incoming data is read from the file system, database, network etc. >>> >>> This rule applies not only to Python 3.0 but to *any* application >>> written in *any* languate. >> The above is a story with which I'm quite familiar. However it is >> *not* the issue!! The issue is why would anyone propose changing a >> string constant "foo" in working 2.x code to u"foo"? > > Do I really have to repeat "use unicode for all internal text data"? > You don't have to, but apparently that wasn't sufficient to stop you. > "foo" and u"foo" are two totally different things. The former is a byte > sequence "\x66\x6f\x6f" while the latter is the text 'foo'. It just > happens that "foo" and u"foo" are equal in Python 2.x because > "foo".decode("ascii") == u"foo". In Python 3.x does it right, b"foo" is > unequal to "foo". > People, it's really helpful if rather than just disagreeing we make efforts to isolate the sources of the disagreement then work towards common understanding. Otherwise we each end up shouting at each other from our individual islands of knowledge. For a *really*N good example of this, though one which does (eventually, and glacially) seem to be moving towards convergence, see the "Why cannot assign to function call" thread. Don't try to prove yourself right, or the other person wrong: instead seek common understanding of the issues, and resolutions thereof. Christian: please don't regard this post as aimed specifically at your behavior, which it isn't. It's a general (and hopefully not entirely useless) attempt to improve the signal-to-noise ratio. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:31:54 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:31:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> Message-ID: r wrote: > [stevie] > On the other hand... Bruno's question is unfair. It is perfectly > reasonable to (hypothetically) consider Python to be the best > *existing* > language while still wanting it to be improved (for some definition > of > improvement). Just because somebody has criticisms of Python, or a > wish- > list of features, doesn't mean they hate the language. > [/stevie] > > WOW Steven, i am very impressed. That's the first thing you have said > in a very long time that i totally agree with! Keep this up and i may > put you back on my Python Brethren list :) What can one do to get *off* it? ;-) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:33:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:33:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <4fbb4bbc-738c-4945-99eb-fd597abfdefa@35g2000pry.googlegroups.com> <7x1vv83afq.fsf@ruckus.brouhaha.com> <2d47317b-be2f-45a5-b890-bb97d0acd065@d36g2000prf.googlegroups.com> Message-ID: bieffe62 at gmail.com wrote: > On 12 Gen, 14:45, Paul Rubin wrote: >> bieff... at gmail.com writes: >>>> class Foo (DynamicAttributes, object): pass >>> You cannot do that, but you can establish a fixed set of attributes by >>> defining the __slot__ class variable. >> That is not what __slot__ is for. > > > Really? It seems to work: > [...] So does using a butt-plug to seal a bottle of wine, but that's still not what it's for. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:36:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:36:27 -0500 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: Miles wrote: > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: >> Using py2.5.4 and entering the following lines in IDLE, I don't really >> understand why I get the result shown in line 8. >> >> Note the difference between lines 7 and 10 is that 'else' clause >> result enclosed in brackets, however, in line 2, both the 'c,d' >> variables are assign correctly without the brackets being required. >> >> 1) >>> n = None >> 2) >>> c,d = n if n is not None else 0,0 >> 3) >>> print c,d, type(c), type(d) >> 4) 0 0 > > The ternary expression has higher precedence than the comma, so the > actual effect of line 2 (and 8) is: > >>>> c, d = (n if n is not None else 0), 0 > > Or written more explicitly: > >>>> c = n if n is not None else 0 >>>> d = 0 > > So the only correct way to write the expression, for the result you > want, is to use your line 10: > >> 10) >>> c,d = n if n is not None else (0,0) > > But if you're struggling with the precedence issues, I'd recommend > ditching ternary expressions altogether and using full conditional > blocks. > Yet another great example of why Guido was right to resist putting conditional expressions into Python for so long (and wrong to succumb to the demand). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:37:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:37:59 -0500 Subject: [ANN] The Python Papers Volume 3 Issue 3 In-Reply-To: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> References: <17c27977-a4d2-40b0-8dc1-ff846f50ac12@r41g2000prr.googlegroups.com> Message-ID: <496C36C7.8020104@holdenweb.com> mauriceling at acm.org wrote: > Hi everyone > > First of all, let me apologize for the delay of this issue of TPP. I > understand that all of you had been anxiously waiting and I do > sincerely apologize that Christmas and New Year celebrations are > taking a toll on my time. > > Finally, here it is... Volume 3 Issue 3... And we are THIRD year in > business. > > As usual, the issue can be found at http://ojs.pythonpapers.org/index.php/tpp/issue/current > > The 1-PDF per issue will be released shortly. > > Let me also take this opportunity to show our deep felt appreciation > to all our supporters/readers and contributors. Without you, we will > not have our day to serve the community. > > At this moment, I will also like to announce our new publication > schedule - there will not be any!!! Oppss, that did not come out > right... > > What I am trying to say is that from Volume 4 Issue 1 onwards, we will > adopt the "fast publishing" method that many journals are using. We > will be releasing each article out to the public as they are being > accepted but each issue will be delimited by our usual ?issue release? > date. The ?issue release? date is then our cutoff deadline to prepare > the 1-PDF per issue file. This means that we will be serving new > articles to everyone much faster than now and there will not be > anymore meaningful publication schedules. > > Hence, let's gear up to another year of exciting Python development > and a recovering economy. > What we might term the "on-supply" publishing model? Good luck for a great third year! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Jan 13 01:51:04 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 01:51:04 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > r writes: >> Python and Ruby. Ruby only exists in this world because of the things >> it took from Python. Nobody would touch Ruby without it's Pythonisms. > > I confess to not knowing much about Ruby. It looks sort of Perl-ish > to me, and I always hear it is slower than Python, which is already > too slow. > >> Python wins hands down, WHY? you ask. Well i could list a thousand >> reasons why but i will only cover a few. >> >> 1.) read-ability >> 2.) ... >> I could keep going for days and days. Python is hands down the best >> thing that ever happened to the world of programming. Sure it could >> use a few improvements, nothing and nobody is perfect. But can any >> language stand toe to toe with Python? HELL NO! > > Those things on your list are all nice, but I think Python has > considerable room for improvement in several areas: > > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) > Of course the tradition answer to this question is "reframe your algorithm in multi-process form". My response to that tends to be "Isn't that what computers are for?" > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. > Speed, of course, isn't everything. But it would be nice to accommodate those problem classes where it *is* significant. > 3) Data encapsulation, the subject of most of this thread. > There's always more to do there, though I fell the thread started out based on a misapprehension. > 4) Static analysis. It would be great if there were a much more > powerful Pylint that could do ML-like type inference among other > things. You could still program in a dynamic, heterogeneous style if > you wanted to, but Pylint would complain about it unless you supplied > some annotations to tell it where the dynamism was and how to separate > it from the rest of the program. This is consistent with Python's > "consenting adults" principle: if consenting adults want to > participate in a BDSM scene, they should be allowed to. There would > probably have to be some new language features to assist in writing > typefully. Python 3.0 has some gestures in this direction but they > are not yet fully formed. > That part of Python 3'sw design is, of course, totally intentional. I believe Guido is on record as saying that he hopes the uses for the annotation feature can be concretized (is that a word) down the line when good use cases have emerged. And I believe they will (as you suggest to be desirable) always be optional - almost like a pragma in other languages. > I believe that the PyPy project is developing the above areas in ways > CPython really could not. While we are now committed to Python 3.0 > being a CPython revision that makes some minor (and in my view > somewhat gratuitous) changes to the 2.x series, I hope that Python 4.0 > will be based on PyPy and have more substantial differences. I have to confess that I occasionally find some of your posts a bit pedantic and obscurantist. Just the same I appreciate your continued presence on the list, because no matter how unreasonable I feel what you says to be, when I examine it I always find your opinions well expressed and well thought-out. Sometimes I just want to shout "be quiet, Python is just fine the way it is", but alas your objections are usually too sensible to be dismissed in that way. In the long term I feel it has to be good for Python that it has such conscientious critics. Ultimately it may well be that some other project than CPython represents the way forward for the language. I don't think that day has arrived yet, but that doesn't mean we should exclude the possibility out of hand. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From abhigyan_agrawal at in.ibm.com Tue Jan 13 02:03:32 2009 From: abhigyan_agrawal at in.ibm.com (abhi) Date: Mon, 12 Jan 2009 23:03:32 -0800 (PST) Subject: Problems in Using C-API for Unicode handling Message-ID: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Hi, I am trying to handle Unicode objects in C (Python 2.5.2). I am getting PyObjects from and want to coerce them to unicode objects. The documentation provides two APIs for that: PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) PyUnicode_FromObject(PyObject *obj) (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) Now I want to utf-16 so I am trying to use the first one, but it is giving back NULL in case of PyObject is already Unicode type which is expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) is passing irrespective of type of PyObject. The API says it is Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I use that, it returns NULL where as PyUnicode_FromObject works. Is there any way by which I can take in any PyObject and convert it to utf-16 object? Any help is appreciated. Thanks, Abhigyan From gagsl-py2 at yahoo.com.ar Tue Jan 13 02:04:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 05:04:56 -0200 Subject: [urllib2] 302 -> can't get cookie References: Message-ID: En Wed, 07 Jan 2009 09:27:00 -0200, Gilles Ganault escribi?: > I'm using urllib2 to connect to a web server with POST, and then the > server sends a cookie to hold the session ID, but also redirects the > user to another page: If you're still interested, the way to avoid a redirect would be to use a RedirectHandler that does nothing: from urllib2 import HTTPRedirectHandler, build_opener class AvoidRedirectHandler(HTTPRedirectHandler): def http_error_302(self, req, fp, code, msg, headers): pass http_error_301 = http_error_303 = http_error_307 = http_error_302 opener = build_opener(AvoidRedirectHandler) opener.open(url, data) -- Gabriel Genellina From tjreedy at udel.edu Tue Jan 13 02:17:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 02:17:43 -0500 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: abhi wrote: > Hi, > I am trying to handle Unicode objects in C (Python 2.5.2). I am > getting PyObjects from and want to coerce them to unicode objects. The > documentation provides two APIs for that: > > PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, > const char *errors) > PyUnicode_FromObject(PyObject *obj) > > (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) > Now I want to utf-16 so I am trying to use the first one, but it is > giving back NULL in case of PyObject is already Unicode type which is > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > is passing irrespective of type of PyObject. The API says it is > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > use that, it returns NULL where as PyUnicode_FromObject works. > > Is there any way by which I can take in any PyObject and convert it to > utf-16 object? Any help is appreciated. Whether Unicode objects are utf-16 or utf=32 depends on your Python build. You can always convert a byte string representation of an object to unicode. From mail at microcorp.co.za Tue Jan 13 02:25:30 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 13 Jan 2009 09:25:30 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com><7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr><7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> Message-ID: <028201c97550$55c3d260$0d00a8c0@hendrik> "Steve Holden" wrote: > r wrote: (about another Steven) > > WOW Steven, i am very impressed. That's the first thing you have said > > in a very long time that i totally agree with! Keep this up and i may > > put you back on my Python Brethren list :) > > What can one do to get *off* it? ;-) eeh by gum lad - there's nowt for it - tis direct result of heavy infestation of people on planet! - Hendrik From timr at probo.com Tue Jan 13 02:29:43 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 13 Jan 2009 07:29:43 GMT Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: imageguy wrote: >Using py2.5.4 and entering the following lines in IDLE, I don't really >understand why I get the result shown in line 8. > >Note the difference between lines 7 and 10 is that 'else' clause >result enclosed in brackets, however, in line 2, both the 'c,d' >variables are assign correctly without the brackets being required. > >Any chance someone could enlighten me on the rules for tuple unpacking >as this seems inconsistent. It's not the tuple unpacking that's burning you. It's simple operator precedence. >7) >>> c,d = n if n is not None else 0,0 >8) >>> print c,d >9) (22, 11) 0 >10) >>> c,d = n if n is not None else (0,0) >11) >>> print c,d >12) 22 11 As line 10 makes clear, line 7 is interpreted thus: c,d = (n if n is not None else 0) , 0 "c" gets bound to the result of the ternary (the tuple (22,11)), and "d" gets bound to 0. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From neokannon at gmail.com Tue Jan 13 02:35:14 2009 From: neokannon at gmail.com (Kannon) Date: Mon, 12 Jan 2009 23:35:14 -0800 (PST) Subject: Attaching a live interpreter to a script? Message-ID: I'm sure this has come up before, but my google-fu is just not strong enough to find it out of 10,000~ posts, and apologies if this is obvious. What I'd like to do is attach an interpreter to a program running from a script (I.E, not something I typed into the live interpreter). It'd be an awesome way to debug programs, as well as tweak parameters and such at runtime. Ideally, I'd like it to be something in pure python so I could throw it into Jython and IronPython as well. (Though, I can actually code Java and C#, so implementing it is something I could do myself, if needed.) I was thinking maybe something I could throw into a tkinter window or similar, but I wasn't able to find anything on how to pass stuff directly to the interpreter. Any ideas, or if this is even possible would be nice. Thanks in advance. From steve at holdenweb.com Tue Jan 13 02:40:16 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 02:40:16 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <028201c97550$55c3d260$0d00a8c0@hendrik> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com><7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr><7xfxjofbqw.fsf@ruckus.brouhaha.com> <8fa2c232-ec50-439f-b5d1-9fcc6294a376@n33g2000pri.googlegroups.com> <028201c97550$55c3d260$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen wrote: > "Steve Holden" wrote: > >> r wrote: (about another Steven) > >>> WOW Steven, i am very impressed. That's the first thing you have said >>> in a very long time that i totally agree with! Keep this up and i may >>> put you back on my Python Brethren list :) >> What can one do to get *off* it? ;-) > > eeh by gum lad - there's nowt for it - > tis direct result of heavy infestation > of people on planet! > 'appen so, but if folk 'ud keep it in ther trousers there'd be less on 'em and I wouldn't be so mithered. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From s.selvamsiva at gmail.com Tue Jan 13 02:46:31 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 13 Jan 2009 13:16:31 +0530 Subject: Extracting real-domain-name (without sub-domains) from a given URL Message-ID: Hi all, I need to extract the domain-name from a given url(without sub-domains). With urlparse, i am able to fetch only the domain-name(which includes the sub-domain also). eg: http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, .... all must lead to *huffingtonpost.com or huffingtonpost.de** * Please suggest me some ideas regarding this problem. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 13 02:57:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 05:57:32 -0200 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: En Mon, 12 Jan 2009 12:00:16 -0200, John Machin escribi?: > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. This is called "backwards compatibility" and it's a good thing :) Consider the Atucha II nuclear plant, started in 1980, based on a design from 1965, and still unfinished. People require access to the complete design, plans, specifications, CAD drawings... decades after they were initially written. I actually do use (and maintain! -- ugh!) some DOS programs. Some people would have a hard time if they could not read their old data with new programs. Even Python has a "print" statement decades after nobody uses a teletype terminal anymore... -- Gabriel Genellina From clp2 at rebertia.com Tue Jan 13 03:20:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 00:20:41 -0800 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: Message-ID: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: > Hi all, > > I need to extract the domain-name from a given url(without sub-domains). > With urlparse, i am able to fetch only the domain-name(which includes the > sub-domain also). > > eg: > http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, > .... all must lead to huffingtonpost.com or huffingtonpost.de > > Please suggest me some ideas regarding this problem. That would require (pardon the pun) domain-specific logic. For most TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, etc. But for ccTLDs, often only second-level registrations are allowed, e.g. for www.bbc.co.uk, so the main domain name would be bbc.co.uk I think a few TLDs have even more complicated rules. I doubt anyone's created a general ready-made solution for this, you'd have to code it yourself. To handle the common case, you can cheat and just .split() at the periods and then slice and rejoin the list of domain parts, ex: '.'.join(domain.split('.')[-2:]) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Ron.Barak at lsi.com Tue Jan 13 03:24:02 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 08:24:02 +0000 Subject: Relative performance of comparable regular expressions In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494DBB@enbmail01.lsi.com> Hi, I have a question about relative performance of comparable regular expressions. I have large log files that start with three letters month names (non-unicode). Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? Also, which is better (if different at all): "\d\d" or "\d{2}" ? Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Thanks, Ron. From s.selvamsiva at gmail.com Tue Jan 13 03:28:36 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 13 Jan 2009 13:58:36 +0530 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: On Tue, Jan 13, 2009 at 1:50 PM, Chris Rebert wrote: > > On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: > > Hi all, > > > > I need to extract the domain-name from a given url(without sub-domains). > > With urlparse, i am able to fetch only the domain-name(which includes the > > sub-domain also). > > > > eg: > > http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, > > .... all must lead to huffingtonpost.com or huffingtonpost.de > > > > Please suggest me some ideas regarding this problem. > > That would require (pardon the pun) domain-specific logic. For most > TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, > etc. But for ccTLDs, often only second-level registrations are > allowed, e.g. for www.bbc.co.uk, so the main domain name would be > bbc.co.uk I think a few TLDs have even more complicated rules. > > I doubt anyone's created a general ready-made solution for this, you'd > have to code it yourself. > To handle the common case, you can cheat and just .split() at the > periods and then slice and rejoin the list of domain parts, ex: > '.'.join(domain.split('.')[-2:]) > > Cheers, > Chris Thank you Chris Rebert, Actually i tried with domain specific logic.Having 200 TLD like .com,co.in,co.uk and tried to extract the domain name. But my boss want more reliable solution than this method,any way i will try to find some alternative solution. -- Yours, S.Selvam From jules at REMOVETHIS.op59.net Tue Jan 13 04:05:28 2009 From: jules at REMOVETHIS.op59.net (Julian Smith) Date: Tue, 13 Jan 2009 09:05:28 +0000 Subject: Attaching a live interpreter to a script? References: Message-ID: <20090113090528.3a6da52a.jules@REMOVETHIS.op59.net> On Mon, 12 Jan 2009 23:35:14 -0800 (PST) Kannon wrote: > What I'd like to do is attach an interpreter to a program running from > a script (I.E, not something I typed into the live interpreter). It'd > be an awesome way to debug programs, as well as tweak parameters and > such at runtime. Ideally, I'd like it to be something in pure python > so I could throw it into Jython and IronPython as well. (Though, I can > actually code Java and C#, so implementing it is something I could do > myself, if needed.) I was thinking maybe something I could throw into > a tkinter window or similar, but I wasn't able to find anything on how > to pass stuff directly to the interpreter. > > Any ideas, or if this is even possible would be nice. Thanks in > advance. I have a few lines of code that runs a debug-server in its own thread, listening on a socket, and exec-ing text that is sent to the socket. The exec happens in the debug-server thread. It's very useful - you can get a backtrace for all threads (on python-2.5 and later), look at globals, call functions, etc etc, all while the main programme is running. If anyone's interested, i'll put the code somewhere. It's all very simple; some would say crude, too. - Jules -- http://op59.net/ http://undo-software.com/ From gagsl-py2 at yahoo.com.ar Tue Jan 13 04:07:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 13 Jan 2009 07:07:16 -0200 Subject: efficient interval containment lookup References: <496BAB8D.4020807@tim.thechases.com> Message-ID: En Tue, 13 Jan 2009 02:55:36 -0200, Per Freem escribi?: > On Jan 12, 10:58?pm, Steven D'Aprano > wrote: >> On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: >> > thanks for your replies -- a few clarifications and questions. the >> > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >> >>= c and b <= d. Note that I am not looking for intervals that >> > overlap... this is why interval trees seem to me to not be relevant, > i found an implementation (which is exactly how i'd write it based on > the description) here: > http://hackmap.blogspot.com/2008/11/python-interval-tree.html > > when i use this however, it comes out either significantly slower or > equal to a naive search. my naive search just iterates through a > smallish list of intervals and for each one says whether they overlap > with each of a large set of intervals. I think there is an algorithm by Baeza-Yates that handles efficiently what you want; but I can't find it. Perhaps Google works better for you. It might be only available in Spanish, though. -- Gabriel Genellina From bj_666 at gmx.net Tue Jan 13 04:09:44 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 13 Jan 2009 09:09:44 GMT Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <0kt*vWSws@news.chiark.greenend.org.uk> <8Fl*e9Sws@news.chiark.greenend.org.uk> <92e4374f-6910-4705-a2a8-bb60cfd57859@p2g2000prn.googlegroups.com> Message-ID: <6t342oF8s8v0U1@mid.uni-berlin.de> On Mon, 12 Jan 2009 21:26:27 -0500, Steve Holden wrote: > The very idea of mapping part of a process's virtual address space onto > an area in which "low-level system code resides, so writing to this > region may corrupt the system, with potentially catastrophic > consequences" seems to be asking for trouble to me. That's why those regions are usually "write protected" and "no execution allowed" from the code in the user area of the virtual address space. Ciao, Marc 'BlackJack' Rintsch From sjmachin at lexicon.net Tue Jan 13 04:15:18 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 01:15:18 -0800 (PST) Subject: Relative performance of comparable regular expressions References: Message-ID: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> On Jan 13, 7:24?pm, "Barak, Ron" wrote: > Hi, > > I have a question about relative performance of comparable regular expressions. > > I have large log files that start with three letters month names (non-unicode). > > Which would give better performance, matching with ?"^[a-zA-Z]{3}", or with "^\S{3}" ? (1) If you want to match at the start of a line, use re.match() *without* the pointless "^". Don't use re.search with a pattern starting with "^" -- it won't be any faster than and it could be a lot worse; re.search doesn't know to stop if the first match fails: command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.match(text)" 1000000 loops, best of 3: 1.15 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.search(text)" 100000 loops, best of 3: 4.47 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*1000" "rx.search(text)" 10000 loops, best of 3: 34.1 usec per loop (2) I think you mean "^\s{3}" not "^\S{3}" (3) Now that you've seen how to do timings, over to you :-) > Also, which is better (if different at all): "\d\d" or "\d{2}" ? > Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? > And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Cheers, John From steven at REMOVE.THIS.cybersource.com.au Tue Jan 13 04:54:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 13 Jan 2009 09:54:20 GMT Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sat, 10 Jan 2009 15:46:35 +0000, Mark Wooding wrote: > [Another tome. I hope this contains sufficient new material to continue > to be of interest to other readers.] I found it interesting. I don't know about others. However, at 756 lines (including quoting) it was nearly double the size of my previous tome, so I think this discussion is clearly not going anyway. I think this conversation is reaching it's natural end. Frustration levels are rising. I could -- and in fact intended to -- write a point-by-point argument, but that would only send the size of this skyrocketing and probably nobody would read it. So I'm going to take a different tack in an attempt to reduce frustration levels: if I can't convince the other side they're wrong, can I at least get them to understand where I'm coming from a little better? As I see it, this conversation is floundering on two radically different ideas about what it means to say a language uses pass-by-foo. On the one hand, some people (me and possibly rurpy) consider "this is pass-by-foo" to be a statement about behaviour directly visible to the programmer. We have a set of behavioral traits in mind, and if a language exhibits those behaviours, then it is clearly and obviously pass-by-foo no matter how that behaviour is implemented. I'll call these the behaviorists. On the other hand, others (I'm going to put Joe and Mark into this group) consider "pass-by-foo" to be a statement about mechanism, or if you prefer, implementation. If a compiler does X, then the language is pass- by-foo, regardless of behaviour. I'll call these the mechanists. To a behaviorist, Python simply can't be pass-by-value, because it doesn't behave like pass-by-value in other languages (particularly C and Pascal). The Python community has a tradition of duck-typing: if it quacks like a duck and swims like a duck, then it is a duck in every way that is important. If it can't swim and doesn't quack, it isn't a duck, no matter how much duck DNA is in it. If it flies, that's irrelevant to the question, because some ducks fly and some don't. According to the behaviorist view, what makes an evaluation strategy call- by-reference is whether or not it exhibits the following three behaviours: (1) passing a value to a function does not copy the value; (2) modifications to the value inside the function are visible to the caller; (3) assignments to the value inside the function are visible to the caller. where "value" means the thing the programmer manipulates symbolically in source code. Values are ints, strings, lists and so forth. Pointers or references are *only* values if the language allows you to write the equivalent of: ptr = SomeReferenceTo(x) # like Pascal's ptr := ^x; x = Dereference(ptr) # like Pascal's x := ptr^; According to this viewpoint, Python clearly cannot be pass-by-reference because (3) is not true. Similarly, what makes pass-by-value is: (1) passing a value to a function makes a copy of the value, where value is an entity the programmer can symbolically manipulate in source code (lists, ints, floats etc.); (2) modifications to the value inside the function are not visible to the caller; (3) assignments to the value inside the function are not visible to the caller. According to this viewpoint, Python clearly cannot be pass-by-value either because neither (1) nor (2) are true. The underlying mechanism is irrelevant. Mechanists take a different view. A typical argument paraphrased from Joe in previous threads is: "Of course Python makes a copy of the value you pass to a function. The difference is that the value you pass is a reference." Mechanists reject the restriction that values only include entities manipulated by the programmer. Consequently they're prepared to say that values in Python aren't the things which Python programmers symbolically manipulate (strings, ints etc.) but are references. Needless to say this claim strikes behaviorists as nonsensical and rather incoherent. If the value of 2 isn't 2, then value has no meaning. If mechanists see the behaviorists as "willfully ignorant", the behaviorists see the mechanists as being blatantly obfuscatory, introducing irrelevant details and ignoring clear examples of the duck quacking. And these two viewpoints are why this debate never ends, merely goes quite for a few weeks or months. -- Steven From python.list at tim.thechases.com Tue Jan 13 05:13:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 13 Jan 2009 04:13:06 -0600 Subject: efficient interval containment lookup In-Reply-To: <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> References: <496BAB8D.4020807@tim.thechases.com> <95d2c129-981a-4edb-b08f-b65289a0abbe@a26g2000prf.googlegroups.com> Message-ID: <496C6932.4030706@tim.thechases.com> Per Freem wrote: > i forgot to add, my naive_find is: > > def naive_find(intervals, start, stop): > results = [] > for interval in intervals: > if interval.start >= start and interval.stop <= stop: > results.append(interval) > return results I don't know if using a list-comprehension here is a better choice, but your code looks very much like def naive_find(intervals, start, stop): return [interval for interval in intervals if interval.start >= start and interval.stop <= stop] which may even be simple enough to include in-line rather than as a sub-function (with any associated call overhead). I've found that usually Python's smart/efficient handling of list-comprehensions can make an appreciable difference within critical-loop constructs. -tkc From jesolem at gmail.com Tue Jan 13 05:16:35 2009 From: jesolem at gmail.com (Jan Erik Solem) Date: Tue, 13 Jan 2009 02:16:35 -0800 (PST) Subject: using PIL for PCA analysis In-Reply-To: References: <8d9c20ee-f277-4c53-9e67-028f34958192@s37g2000prg.googlegroups.com> <1c90eade-098d-49ea-bd72-b9b1f5e726c8@u10g2000prn.googlegroups.com> Message-ID: <21432675.post@talk.nabble.com> > if i want to do an array of PIL image data i can use > img=Image.open("myimg.jpg") .convert("L") > pixelarray=img.getdata() > convert("L") is a good way to make images grayscale. An option to using getdata() is to try numpy's array: pixelarray = numpy.array(img) this gives lots of possibilities for working with the images numerically, like for PCA. (see example code in the link below) > thus i guess i can build a matrix of a set of images > is there something wrong in the way i do this above?may be i can use > that to find covariance matrix for the set of images? > I wrote a short script for doing PCA on images using python, with some explanations and example code http://jesolem.blogspot.com/2009/01/pca-for-images-using-python.html here . Could be of help to you guys. -- View this message in context: http://www.nabble.com/using-PIL-for-PCA-analysis-tp15606311p21432675.html Sent from the Python - python-list mailing list archive at Nabble.com. From debasishroy02 at gmail.com Tue Jan 13 05:23:13 2009 From: debasishroy02 at gmail.com (debasish ray) Date: Tue, 13 Jan 2009 15:53:13 +0530 Subject: best site for hacking tricks , computer tweaks Message-ID: <000001c97568$f6d088c0$e4719a40$@com> -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Tue Jan 13 05:32:08 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 13 Jan 2009 04:32:08 -0600 Subject: Python tricks References: <283a5c3a-9672-4229-a4ae-26c17b1fe912@n33g2000pri.googlegroups.com> Message-ID: Scott David Daniels wrote: > RajNewbie wrote: > > On Jan 12, 6:51 pm, Tim Chase wrote: > [a perfectly fine reply which is how I'd solve it] > >> RajNewbie wrote: > >>> ... The solution that I had in mind is: > >>> while True: > >>> ... > >>> if : break > >>> if inifinte_loop(): raise infiinte_loop_exception > >>> Wherein infinite_loop is a generator, which returns true if i > 200 > >>> def infinite_loop(): > >>> i = 0 > >>> while i < 200: > >>> i++ > >>> yield False > >>> yield True > >>> Could somebody let me know whether this is a good option? > > ... > > But, I still feel it would be much more aesthetically pleasing if I > > can call a single procedure like > > if infinite_loop() -> to do the same. > > Is it somehow possible? - say by using static variables, iterators -- > > anything? > > Yes, it is possible. After: > > def Fuse(count, exception): > for i in range(count): > yield None > raise exception > > You can do your loop as: > check_infinite = Fuse(200, ValueError('Infinite Loop')).next > while True: > ... > check_infinite() Or related to the above and the original proposal class InfiniteLoopError(Exception): """An 'infinite' loop has been detected""" def infinite_loop(max=200): for i in xrange(max): yield i raise InfiniteLoopError() Use it like this for i in infinite_loop(): if i > 10: break print "iteration", i or for i in infinite_loop(10): print "iteration", i > but I agree with Tim that a for ... else loop for the limit is > clearer. Probably yes -- Nick Craig-Wood -- http://www.craig-wood.com/nick From Maksim.Kasimov at gmail.com Tue Jan 13 06:12:08 2009 From: Maksim.Kasimov at gmail.com (sim.sim) Date: Tue, 13 Jan 2009 03:12:08 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On 12 ???, 16:00, John Machin wrote: > On Jan 13, 12:45?am, "sim.sim" wrote: > > > > > On 10 ???, 23:40, John Machin wrote: > > > > On Jan 11, 2:45?am, "sim.sim" wrote: > > > > > Hi all! > > > > > I had touch with some different python behavior: I was tried to write > > > > into a file a string with the '\x1a' symbol, and for FreeBSD system, > > > > it gives expected result: > > > > > >>> open("test", "w").write('before\x1aafter') > > > > >>> open('test').read() > > > > > 'before\x1aafter' > > > > > but for my WinXP box, it gives some strange: > > > > > >>> open("test", "w").write('before\x1aafter') > > > > >>> open('test').read() > > > > > 'before' > > > > > Here I can write all symbols, but not read. > > > > I've tested it with python 2.6, 2.5 and 2.2 and WinXP SP2. > > > > > Why is it so and is it possible to fix it? > > > > You've already got two good answers, but this might add a little more > > > explanation: > > > > You will aware that in Windows Command Prompt, to exit the interactive > > > mode of Python (among others), you need to type Ctrl-Z ... > > > > | C:\junk>python > > > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > > > (Intel)] on > > > win32 > > > | Type "help", "copyright", "credits" or "license" for more > > > information. > > > | >>> problem = '\x1a' > > > | >>> ord(problem) > > > | 26 > > > | >>> # What is the 26th letter of the English/ASCII alphabet? > > > | ... > > > | >>> ^Z > > > | > > > | C:\junk> > > > > HTH, > > > John > > > Hi John, > > > I agree - those two answers are really good. Thanks to Mel and Marc. > > I'm sorry if my stupid question was annoyed you. > > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. > > And I wasn't annoyed either ... I was merely adding the information > that Ctrl-Z and '\x1a' were the same thing; many people don't make the > connection. > > Cheers, > John Ah John, thank you for your explanations! My first impression was that your comments does not relates to my question, but I've found new things where I used to think there was nothing. Now it is interesting to me how one have to give reasons to use open (.., 'r') instead of open(.., 'rb')? There is confusing situation when we use open(.., 'r'), are there some scenario when we might be confused when we'll use open(.., 'rb')? -- Maksim From sjmachin at lexicon.net Tue Jan 13 06:37:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 03:37:58 -0800 (PST) Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On Jan 13, 10:12?pm, "sim.sim" wrote: > > Ah John, thank you for your explanations! > My first impression was that your comments does not relates to my > question, > but I've found new things where I used to think there was nothing. > > Now it is interesting to me how one have to give reasons to use open > (.., 'r') instead of open(.., 'rb')? > There is confusing situation when we use open(.., 'r'), are there some > scenario when we might be confused when we'll use open(.., 'rb')? Some general rules: if you regard a file as text, open it with "rt" -- the "t" is redundant but gives you and anyone else who reads your code that assurance that you've actually thought about it. Otherwise you regard the file as binary, and open it with "rb". The distinction was always important on Windows because of the special handling of newlines and '\x1a') but largely unimportant on *x boxes. With Python 3.0, it is important for all users to specify the mode that they really need: 'b' files read and write bytes objects whereas 't' files read and write str objects, have the newline etc changes, and need an encoding to decode the raw bytes into str (Unicode) objects -- and you can't use bytes objects directly with a 't' file nor str objects directly a 'b' file. HTH, John From steve at holdenweb.com Tue Jan 13 06:43:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 06:43:37 -0500 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: S.Selvam Siva wrote: > On Tue, Jan 13, 2009 at 1:50 PM, Chris Rebert wrote: >> On Mon, Jan 12, 2009 at 11:46 PM, S.Selvam Siva wrote: >>> Hi all, >>> >>> I need to extract the domain-name from a given url(without sub-domains). >>> With urlparse, i am able to fetch only the domain-name(which includes the >>> sub-domain also). >>> >>> eg: >>> http://feeds.huffingtonpost.com/posts/ , http://www.huffingtonpost.de/, >>> .... all must lead to huffingtonpost.com or huffingtonpost.de >>> >>> Please suggest me some ideas regarding this problem. >> That would require (pardon the pun) domain-specific logic. For most >> TLDs (e.g. .com, .org) the domain name is just blah.com, blah.org, >> etc. But for ccTLDs, often only second-level registrations are >> allowed, e.g. for www.bbc.co.uk, so the main domain name would be >> bbc.co.uk I think a few TLDs have even more complicated rules. >> >> I doubt anyone's created a general ready-made solution for this, you'd >> have to code it yourself. >> To handle the common case, you can cheat and just .split() at the >> periods and then slice and rejoin the list of domain parts, ex: >> '.'.join(domain.split('.')[-2:]) >> >> Cheers, >> Chris > > > Thank you Chris Rebert, > Actually i tried with domain specific logic.Having 200 TLD like > .com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i > will try to find some alternative solution. > If you post a good first try, opening the source, I would be surprised if others do not join your effort to establish suitable rules. This is somethjing that many people could doubtless use. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From abhigyan_agrawal at in.ibm.com Tue Jan 13 06:44:05 2009 From: abhigyan_agrawal at in.ibm.com (abhi) Date: Tue, 13 Jan 2009 03:44:05 -0800 (PST) Subject: Problems in Using C-API for Unicode handling References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> On Jan 13, 12:17?pm, Terry Reedy wrote: > abhi wrote: > > Hi, > > ? ? I am trying to handle Unicode objects in C (Python 2.5.2). I am > > getting PyObjects from and want to coerce them to unicode objects. The > > documentation provides two APIs for that: > > > ?PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, > > const char *errors) > > ?PyUnicode_FromObject(PyObject *obj) > > > (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) > > Now I want to utf-16 so I am trying to use the first one, but it is > > giving back NULL in case of PyObject is already Unicode type which is > > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > > is passing irrespective of type of PyObject. The API says it is > > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > > use that, it returns NULL where as PyUnicode_FromObject works. > > > Is there any way by which I can take in any PyObject and convert it to > > utf-16 object? Any help is appreciated. > > Whether Unicode objects are utf-16 or utf=32 depends on your Python > build. ?You can always convert a byte string representation of an object > to unicode.- Hide quoted text - > > - Show quoted text - Hi, I agree with you. I have a Python unicode object in C (I don't know which utf) and I want to convert this explicitely to utf-16. Is there any way to do this? PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) says that obj can't be a unicode type so I guess I can't use this one, does anybody knows any other method by which I can achieve my goal? Thanks, Abhigyan From steve at holdenweb.com Tue Jan 13 06:47:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 06:47:05 -0500 Subject: Relative performance of comparable regular expressions In-Reply-To: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> Message-ID: John Machin wrote: > On Jan 13, 7:24 pm, "Barak, Ron" wrote: >> Hi, >> >> I have a question about relative performance of comparable regular expressions. >> >> I have large log files that start with three letters month names (non-unicode). >> >> Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? > > (1) If you want to match at the start of a line, use re.match() > *without* the pointless "^". Don't use re.search with a pattern > starting with "^" -- it won't be any faster than and it could be a lot > worse; re.search doesn't know to stop if the first match fails: > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.match(text)" > 1000000 loops, best of 3: 1.15 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.search(text)" > 100000 loops, best of 3: 4.47 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*1000" "rx.search(text)" > 10000 loops, best of 3: 34.1 usec per loop > > (2) I think you mean "^\s{3}" not "^\S{3}" > > (3) Now that you've seen how to do timings, over to you :-) > >> Also, which is better (if different at all): "\d\d" or "\d{2}" ? >> Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? >> And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" > Of course if the log strings all begin with a string like "Dec 12 2009 ...." then you don't need regular expressions at all - just pull the characters out using their positions and slicing. The month would be string[0:3] and so on. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent.gulinao at gmail.com Tue Jan 13 07:03:25 2009 From: vincent.gulinao at gmail.com (Vincent Gulinao) Date: Tue, 13 Jan 2009 20:03:25 +0800 Subject: WebDAV client module Message-ID: Kindly point me to a good WebDAV client module for Python. Looks like PyDav is popular, but it seems some of the modules used within were already deprecated. TIA. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gkcdri at gmail.com Tue Jan 13 07:36:37 2009 From: gkcdri at gmail.com (gkcdri at gmail.com) Date: Tue, 13 Jan 2009 04:36:37 -0800 (PST) Subject: i want to join developer group Message-ID: Hello, I want to contribute to the open source projects. From steve at holdenweb.com Tue Jan 13 08:00:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 08:00:43 -0500 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> Message-ID: abhi wrote: > On Jan 13, 12:17 pm, Terry Reedy wrote: >> abhi wrote: >>> Hi, >>> I am trying to handle Unicode objects in C (Python 2.5.2). I am >>> getting PyObjects from and want to coerce them to unicode objects. The >>> documentation provides two APIs for that: >>> PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, >>> const char *errors) >>> PyUnicode_FromObject(PyObject *obj) >>> (http://www.python.org/doc/2.5.2/api/unicodeObjects.html) >>> Now I want to utf-16 so I am trying to use the first one, but it is >>> giving back NULL in case of PyObject is already Unicode type which is >>> expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) >>> is passing irrespective of type of PyObject. The API says it is >>> Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I >>> use that, it returns NULL where as PyUnicode_FromObject works. >>> Is there any way by which I can take in any PyObject and convert it to >>> utf-16 object? Any help is appreciated. >> Whether Unicode objects are utf-16 or utf=32 depends on your Python >> build. You can always convert a byte string representation of an object >> to unicode.- Hide quoted text - >> >> - Show quoted text - > > Hi, > I agree with you. I have a Python unicode object in C (I don't know > which utf) and I want to convert this explicitely to utf-16. Is there > any way to do this? > PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const > char *errors) says that obj can't be a unicode type so I guess I can't > use this one, does anybody knows any other method by which I can > achieve my goal? > I suspect that a "Python Unicode object in C" will be using either UCS-2 or UCS-4 representation, depending on the options your interpreter was built with. So whatever else it is, it won't be UTF-anything. Don't know whether that helps or not. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python-url at phaseit.net Tue Jan 13 08:14:24 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 13 Jan 2009 13:14:24 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 13) Message-ID: QOTW: "If Jack Valenti had been around at the time of Gutenberg he would have organized the monks to come and burn down the printing press' :-)." - Information Technology Association of America president Harris Miller Dynamic creation of instance attributes may adversely affect code readability: http://groups.google.com/group/comp.lang.python/browse_thread/thread/68bc54bca830c46/ A detective story: getting meaningful data out of a mix of base64, UTF-16, and gzip: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d84f42493fe81864/ http://groups.google.com/group/comp.lang.python/browse_thread/thread/d72d883409764559/ Analyzing existing alternatives to extend Python with C or C++ code: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9afb5b4bdfaac6/ This long post on PyObjC from late in 2004 is worth re-reading for its remarks on Macintosh, architecture, and getting things to work: http://mail.python.org/pipermail/pythonmac-sig/2004-October/012023.html Handling multiple child processes: http://groups.google.com/group/comp.lang.python/browse_thread/thread/80a8edb06c3b7f1b/ How to create an instance of the right subclass: http://groups.google.com/group/comp.lang.python/browse_thread/thread/636d0f516e9850c9/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From benjamin.kaplan at case.edu Tue Jan 13 08:33:19 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 13 Jan 2009 08:33:19 -0500 Subject: Attaching a live interpreter to a script? In-Reply-To: References: Message-ID: On Tue, Jan 13, 2009 at 2:35 AM, Kannon wrote: > I'm sure this has come up before, but my google-fu is just not strong > enough to find it out of 10,000~ posts, and apologies if this is > obvious. > > What I'd like to do is attach an interpreter to a program running from > a script (I.E, not something I typed into the live interpreter). It'd > be an awesome way to debug programs, as well as tweak parameters and > such at runtime. Ideally, I'd like it to be something in pure python > so I could throw it into Jython and IronPython as well. (Though, I can > actually code Java and C#, so implementing it is something I could do > myself, if needed.) I was thinking maybe something I could throw into > a tkinter window or similar, but I wasn't able to find anything on how > to pass stuff directly to the interpreter. > > Any ideas, or if this is even possible would be nice. Thanks in > advance. I don't know exactly what they did, but wxPython has a "widget inspection tool" that includes such a thing. It lets you manipulate whatever widget is selected in the tree control above the shell. The widget inspection tool is in wx/lib/inspection.py and the code for the shell they use is in wx/py/shell.py. I think it's pure python except for the gui. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lie.1296 at gmail.com Tue Jan 13 08:58:53 2009 From: Lie.1296 at gmail.com (Lie) Date: Tue, 13 Jan 2009 05:58:53 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: <6de24fc3-64d2-4cf2-afaa-a3cfc2aede6a@y1g2000pra.googlegroups.com> On Jan 3, 4:38?am, mr wrote: > As has been noted, the best is to fix the input to be regular-3- > tuples. For the fun of it, here's another variation of a solution: > Yet another solution: for i in l: k, u, v = i[0], None if len(i) == 2 else i[1], i[-1] From Lie.1296 at gmail.com Tue Jan 13 09:07:43 2009 From: Lie.1296 at gmail.com (Lie) Date: Tue, 13 Jan 2009 06:07:43 -0800 (PST) Subject: Is there a better algorithm? References: <7f3708b3-c82a-457f-bb26-e07306e0f477@y1g2000pra.googlegroups.com> Message-ID: <67e0dfc1-0a33-4902-850b-e48fabb85642@g3g2000pre.googlegroups.com> On Jan 3, 11:55?am, Kottiyath wrote: > On Jan 3, 2:38?am, mr wrote: > > It is a code to post some data to HTML server. > Even though usually the POST values are of type(name, value), if file > transfer is involved, then POST values change to (name, filename, > value). > My view was that since filename is a rare occurance and doesnt make > sense in a usual POST, I had not kept it as a full 3 tuple. > Since so many programmers (that too much more capable than me) are > suggesting that it is code smell, I am reviewing my decision. Is it possible to change (name, filename, value) into (name, value, filename) instead? In most cases optional arguments should be last. There are some very exceptional case, where early optional argument might be better, like python's range, which type signature is: [[start,] stop[, step]] (i.e. with one argument, it is assigned to stop, instead of start) From Ron.Barak at lsi.com Tue Jan 13 09:16:56 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 14:16:56 +0000 Subject: Relative performance of comparable regular expressions In-Reply-To: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> Hi John, Thanks for the below - teaching me how to fish ( instead of just giving me a fish :-) Now I could definitely get the answers for myself, and also be a bit more enlightened. As for your (2) remark below (on my question: Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ?): (2) I think you mean "^\s{3}" not "^\S{3}", I actually did meant to use \S, namely - a character that is not a white-space. Bye, Ron. -----Original Message----- From: John Machin [] Sent: Tuesday, January 13, 2009 11:15 To: python-list at python.org Subject: Re: Relative performance of comparable regular expressions On Jan 13, 7:24 pm, "Barak, Ron" wrote: > Hi, > > I have a question about relative performance of comparable regular expressions. > > I have large log files that start with three letters month names (non-unicode). > > Which would give better performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ? (1) If you want to match at the start of a line, use re.match() *without* the pointless "^". Don't use re.search with a pattern starting with "^" -- it won't be any faster than and it could be a lot worse; re.search doesn't know to stop if the first match fails: command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.match(text)" 1000000 loops, best of 3: 1.15 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*100" "rx.search(text)" 100000 loops, best of 3: 4.47 usec per loop command-prompt>\python26\python -m timeit -s"import re;rx=re.compile ('^AB') ;text='Z'*1000" "rx.search(text)" 10000 loops, best of 3: 34.1 usec per loop (2) I think you mean "^\s{3}" not "^\S{3}" (3) Now that you've seen how to do timings, over to you :-) > Also, which is better (if different at all): "\d\d" or "\d{2}" ? > Also, would matching "." be different (performance-wise) than matching the actual character, e.g. matching ":" ? > And lastly, at the end of a line, is there any performance difference between "(.+)$" and "(.+)" Cheers, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From BrianVanderburg2 at aim.com Tue Jan 13 09:24:51 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Tue, 13 Jan 2009 09:24:51 -0500 Subject: Python threading Message-ID: <496CA433.2040507@aim.com> I'm doing some multi-threaded programming and before diving into the C/C++ code I though I'd do some in Python first. I decided to read through the threading module and I understand some of it, but I don't understand this, though I'm sure it is easy: The condition object has a method _is_owned, which is called if the lock doesn't have one. The RLock does have one but a regular lock not. It is supposed to return true if the lock is owned by the current thread: def _is_owned(self): # Return True if lock is owned by currentThread. # This method is called only if __lock doesn't have _is_owned(). if self.__lock.acquire(0): self.__lock.release() return False else: return True It seems that for a condition without an RLock but a Lock, self.__lock.acquire(0) will return False even if the lock is owned by another thread other than the current thread, so _is_owned would return True even if the lock is owned by another thread. B. Vanderburg II From philip at semanchuk.com Tue Jan 13 09:39:08 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 09:39:08 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> On Jan 13, 2009, at 1:22 AM, Steve Holden wrote: > Philip Semanchuk wrote: >> >> On Jan 12, 2009, at 6:48 PM, ajaksu wrote: >> >>> On Jan 11, 11:59 pm, "James Mills" >>> wrote: >>>> Hey all, >>>> >>>> The following fails for me: >>>> >>>>>>> from urllib2 import urlopen >>>>>>> f = >>>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml >>>>>>> ") >>>>>>> >>>> >>>> Traceback (most recent call last): >>> [...] >>>> Any helpful ideas ? >>> >>> Maybe raise a real bug @ bugs.python.org instead of just >>> mentioning it >>> like I did: http://bugs.python.org/msg77889 >>> >>> I think at least some sites would be willing to add the new UA to >>> their whitelists. >> >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? >> > I'd say it's an issue relevant to Python users, which woudl seem to > put > it pretty much in the mainstream for c.l.py - especially as the code > causing concern was written in Python. I didn't mean to imply that the conversation didn't belong here. I think that is perfectly appropriate. What I don't understand is the suggestion that Google's server config should be raised as a bug against Python. (i.e. "raise a real bug @ bugs.python.org...") From Tribulations at Paralleles.invalid Tue Jan 13 10:13:21 2009 From: Tribulations at Paralleles.invalid (TP) Date: Tue, 13 Jan 2009 16:13:21 +0100 Subject: exec in a nested function yields an error Message-ID: Hi everybody, Try the following program: #################### def f(): def f_nested(): exec "a=2" print a f() #################### It yields an error. $ python nested_exec.py File "nested_exec.py", line 3 exec "a=2" SyntaxError: unqualified exec is not allowed in function 'f_nested' it is a nested function What is the problem? Why? Thanks -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From steve at holdenweb.com Tue Jan 13 10:14:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 10:14:38 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> References: <04F65391-C240-46EF-B161-D69F5676EABE@semanchuk.com> Message-ID: Philip Semanchuk wrote: > > On Jan 13, 2009, at 1:22 AM, Steve Holden wrote: > >> Philip Semanchuk wrote: >>> >>> On Jan 12, 2009, at 6:48 PM, ajaksu wrote: >>> >>>> On Jan 11, 11:59 pm, "James Mills" >>>> wrote: >>>>> Hey all, >>>>> >>>>> The following fails for me: >>>>> >>>>>>>> from urllib2 import urlopen >>>>>>>> f = >>>>>>>> urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") >>>>>>>> >>>>>>>> >>>>> >>>>> Traceback (most recent call last): >>>> [...] >>>>> Any helpful ideas ? >>>> >>>> Maybe raise a real bug @ bugs.python.org instead of just mentioning it >>>> like I did: http://bugs.python.org/msg77889 >>>> >>>> I think at least some sites would be willing to add the new UA to >>>> their whitelists. >>> >>> I don't think I understand you clearly. Whether or not Google et al >>> whitelist the Python UA isn't a Python issue, is it? >>> >> I'd say it's an issue relevant to Python users, which woudl seem to put >> it pretty much in the mainstream for c.l.py - especially as the code >> causing concern was written in Python. > > I didn't mean to imply that the conversation didn't belong here. I think > that is perfectly appropriate. What I don't understand is the suggestion > that Google's server config should be raised as a bug against Python. > (i.e. "raise a real bug @ bugs.python.org...") > Oh, I see! Yes, it's hard to know what actions anyone could take on such a bug report. I suppose the documentation could be modified to describe how some services require specific agents, but that wouldn't help a huge amount. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Kiran.Karra at gmail.com Tue Jan 13 10:21:40 2009 From: Kiran.Karra at gmail.com (K-man) Date: Tue, 13 Jan 2009 07:21:40 -0800 (PST) Subject: Ethernet packet size python Message-ID: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Hi, I am sending data using the socket interface in python, but I want to know how big the ethernet packet size is (in bytes). I didn't really see a way using the socket library of how to do this. Any suggestions? From oltman at gmail.com Tue Jan 13 10:23:46 2009 From: oltman at gmail.com (Ryan Oltman) Date: Tue, 13 Jan 2009 07:23:46 -0800 (PST) Subject: Embedding Python with non-filesystem code source? Message-ID: <7c18a276-d11a-4e20-be32-343e656bad3d@v5g2000prm.googlegroups.com> Background: I'm trying to develop some certification software in C/C++ that would allow engineers/technicians to quickly develop scripts/functions in Python to verify a product (there could be hundreds of functions per product). I would like to use SQLite db to store the functions and the necessary certification reference data. Question: I have successfully embedded python code in C/C++ using the PyEval_CallObject when using a file as the module source,but is it possible using the PyImport_ImportModule & PyObject_GetAttrString to point to a non-filesystem source? Is there another way to setup the PyEval_CallObject that would allow this capability? Ryan Oltman From skip at pobox.com Tue Jan 13 10:28:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 13 Jan 2009 09:28:29 -0600 Subject: Converting from PyUnicodeObject to char * without calling C API Message-ID: <18796.45853.852587.379554@montanaro.dyndns.org> I'm trying to convert Python's gdbinit file to Python 3. One of the things it does is print filenames and function names when displaying stack frames. This worked fine in Python 2 because the type of such objects is PyStringObject which uses NUL-terminated strings under the covers. For example: set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval In Python 3 co->co_filename is a PyUnicodeObject pointer with the raw data encoded as either UCS2 or UCS4. This presents problems when displaying strings: (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) (gdb) p *$__f->str@$__f->length $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} (gdb) p *(char *)($__f->str)@$__f->length $15 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p" (gdb) p *(char *)($__f->str)@($__f->length*2) $16 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p\000y\0003\000k\000-\000t\000/\000L\000i\000b\000/\000_\000w\000e\000a\000k\000r\000e\000f\000s\000e\000t\000.\000p\000y" I'd like to get rid of those NULs when displaying names. Making it more difficult, I'd like to do it without calling any C API functions. If at all possible the user-defined commands should work even if there is no process available. (e.g., when working with core files). Any suggestions? -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From google at mrabarnett.plus.com Tue Jan 13 10:35:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jan 2009 15:35:48 +0000 Subject: Converting from PyUnicodeObject to char * without calling C API In-Reply-To: <18796.45853.852587.379554@montanaro.dyndns.org> References: <18796.45853.852587.379554@montanaro.dyndns.org> Message-ID: <496CB4D4.8070407@mrabarnett.plus.com> skip at pobox.com wrote: > I'm trying to convert Python's gdbinit file to Python 3. One of the things > it does is print filenames and function names when displaying stack frames. > This worked fine in Python 2 because the type of such objects is > PyStringObject which uses NUL-terminated strings under the covers. For > example: > > set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval > > In Python 3 co->co_filename is a PyUnicodeObject pointer with the raw data > encoded as either UCS2 or UCS4. This presents problems when displaying > strings: > > (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) > (gdb) p *$__f->str@$__f->length > $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} > > (gdb) p *(char *)($__f->str)@$__f->length > $15 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p" > > (gdb) p *(char *)($__f->str)@($__f->length*2) > $16 = "/\000U\000s\000e\000r\000s\000/\000s\000k\000i\000p\000/\000s\000r\000c\000/\000p\000y\000t\000h\000o\000n\000/\000p\000y\0003\000k\000-\000t\000/\000L\000i\000b\000/\000_\000w\000e\000a\000k\000r\000e\000f\000s\000e\000t\000.\000p\000y" > > > I'd like to get rid of those NULs when displaying names. Making it more > difficult, I'd like to do it without calling any C API functions. If at all > possible the user-defined commands should work even if there is no process > available. (e.g., when working with core files). > Should you be using "char *" when they aren't char? Is there a wide char type of some sort? From steve at holdenweb.com Tue Jan 13 10:35:56 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Jan 2009 10:35:56 -0500 Subject: Ethernet packet size python In-Reply-To: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: K-man wrote: > Hi, > I am sending data using the socket interface in python, but I want > to know how big the ethernet packet size is (in bytes). I didn't > really see a way using the socket library of how to do this. Any > suggestions? There is no way to know what size Ethernet packets will result from specific traffic. Or do you want to know the MTU size (largest possible Ethernet packet size)? This shouldn't really matter, since large TCP messages will be split into a sequence of IP datagrams, and large IP datagrams will be automatically fragmented and then reassembled at the other end. Is there a specific reason this is important to you? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From marduk at letterboxes.org Tue Jan 13 10:37:17 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 10:37:17 -0500 Subject: exec in a nested function yields an error In-Reply-To: References: Message-ID: <1231861037.18519.9.camel@localhost.localdomain> On Tue, 2009-01-13 at 16:13 +0100, TP wrote: > Hi everybody, > > Try the following program: > > #################### > def f(): > def f_nested(): > exec "a=2" > print a > f() > #################### > > It yields an error. > $ python nested_exec.py > File "nested_exec.py", line 3 > exec "a=2" > SyntaxError: unqualified exec is not allowed in function 'f_nested' it is a > nested function > > What is the problem? > Why? > I believe because in the above example what namespace is local for the exec is ambiguous so you need to specify it explicitly. Also, and I'm sure you know this, exec can be dangerous and should be used wisely/rarely. From Scott.Daniels at Acm.Org Tue Jan 13 10:47:56 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 07:47:56 -0800 Subject: Ternary operator and tuple unpacking -- What am I missing ? In-Reply-To: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: imageguy wrote: > 1) >>> n = None > 2) >>> c,d = n if n is not None else 0,0 ... This is more easily expressed as: c, d = n or (0, 0) From dskippy at ccs.neu.edu Tue Jan 13 10:51:09 2009 From: dskippy at ccs.neu.edu (Mike MacHenry) Date: Tue, 13 Jan 2009 10:51:09 -0500 Subject: Simple CGI-XMLRPC failure In-Reply-To: References: Message-ID: <7d9c10d20901130751w81f862fm3cdff04f123475bb@mail.gmail.com> I figured it was some kind of bug. Must be either a bug with my version of either the library (most likely) or perhaps some weird environment setting that I have set incorrectly (also likely). How can I figure out which version of SimpleXMLRPCServer I'm running? Do you run Ubuntu by any chance? If you which version? Does anyone know of any environment settings I could look into on Apache or Python? -mike On Mon, Jan 12, 2009 at 9:02 PM, Jeff McNeil wrote: > On Jan 12, 12:40 pm, "Mike MacHenry" wrote: >> I am having a difficult time understanding why my very simple >> CGI-XMLRPC test isn't working. I created a server to export two >> functions, the built-in function "pow" and my own identity function >> "i". I run a script to call both of them and the "pow" work fine but >> the "i" gives me an error that says my XMLRPC server doesn't support >> than name. Here is the code for both files and the output: >> >> #!/usr/bin/env python >> #This file is /usr/lib/cgi-bin/roundwarerpc.py >> from SimpleXMLRPCServer import CGIXMLRPCRequestHandler >> def i(x): >> return x >> server = CGIXMLRPCRequestHandler() >> server.register_function(pow) >> server.register_function(i) >> server.handle_request() >> >> #!/usr/bin/env python >> #This file is ~/test.py >> import xmlrpclib >> server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") >> print server.pow(2,3) >> print server.i(10) >> >> #This is the STDOUT and STDERR when running ~/test.py >> dskippy at dskippy-laptop:$ python test.py 8 >> Traceback (most recent call last): >> File "test.py", line 4, in >> print server.test(10) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ >> return self.__send(self.__name, args) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request >> verbose=self.__verbose >> File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request >> return self._parse_response(h.getfile(), sock) >> File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response >> return u.close() >> File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close >> raise Fault(**self._stack[0]) >> xmlrpclib.Fault: :method "i" >> is not supported'> >> >> Does anyone know what might be wrong with this? >> >> Thanks for the help, >> -mike >> >> p.s. >> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) >> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 >> Server version Apache/2.2.8 (Ubuntu) >> Server built: Jun 25 2008 13:54:13 > > I copied your code verbatim and I don't have any issues with it at > all. Same version of Python, same version of Apache. > > In SimpleXMLRPCServer.py, register_function adds directly to a > self.funcs dictionary, so an instance variable of the same name > shouldn't hurt anything. That exception is only raised when a > self.funcs lookup raises a KeyError unless you're registering an > instance. > > -- > http://mail.python.org/mailman/listinfo/python-list > From Ron.Barak at lsi.com Tue Jan 13 10:51:54 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 13 Jan 2009 15:51:54 +0000 Subject: Could you suggest optimisations ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Hi, In the attached script, the longest time is spent in the following functions (verified by psyco log): def match_generator(self,regex): """ Generate the next line of self.input_file that matches regex. """ generator_ = self.line_generator() while True: self.file_pointer = self.input_file.tell() if self.file_pointer != 0: self.file_pointer -= 1 if (self.file_pointer + 2) >= self.last_line_offset: break line_ = generator_.next() print "%.2f%% \r" % (((self.last_line_offset - self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), if not line_: break else: match_ = regex.match(line_) groups_ = re.findall(regex,line_) if match_: yield line_.strip("\n"), groups_ def get_matching_records_by_regex_extremes(self,regex_array): """ Function will: Find the record matching the first item of regex_array. Will save all records until the last item of regex_array. Will save the last line. Will remember the position of the beginning of the next line in self.input_file. """ start_regex = regex_array[0] end_regex = regex_array[len(regex_array) - 1] all_recs = [] generator_ = self.match_generator try: match_start,groups_ = generator_(start_regex).next() except StopIteration: return(None) if match_start != None: all_recs.append([match_start,groups_]) line_ = self.line_generator().next() while line_: match_ = end_regex.match(line_) groups_ = re.findall(end_regex,line_) if match_ != None: all_recs.append([line_,groups_]) return(all_recs) else: all_recs.append([line_,[]]) line_ = self.line_generator().next() def line_generator(self): """ Generate the next line of self.input_file, and update self.file_pointer to the beginning of that line. """ while self.input_file.tell() <= self.last_line_offset: self.file_pointer = self.input_file.tell() line_ = self.input_file.readline() if not line_: break yield line_.strip("\n") I was trying to think of optimisations, so I could cut down on processing time, but got no inspiration. (I need the "print "%.2f%% \r" ..." line for user's feedback). Could you suggest any optimisations ? Thanks, Ron. P.S.: Examples of processing times are: * 2m42.782s on two files with combined size of 792544 bytes (no matches found). * 28m39.497s on two files with combined size of 4139320 bytes (783 matches found). These times are quite unacceptable, as a normal input to the program would be ten files with combined size of ~17MB. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: _failover_multiple_files_client.py Type: application/octet-stream Size: 7771 bytes Desc: _failover_multiple_files_client.py URL: From Kiran.Karra at gmail.com Tue Jan 13 10:58:33 2009 From: Kiran.Karra at gmail.com (K-man) Date: Tue, 13 Jan 2009 07:58:33 -0800 (PST) Subject: Ethernet packet size python References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: <6261d4c1-96e3-40b4-ab62-30f6f4702597@v18g2000pro.googlegroups.com> On Jan 13, 10:35?am, Steve Holden wrote: > K-man wrote: > > Hi, > > ? I am sending data using the socket interface in python, but I want > > to know how big the ethernet packet size is (in bytes). ?I didn't > > really see a way using the socket library of how to do this. ?Any > > suggestions? > > There is no way to know what size Ethernet packets will result from > specific traffic. Or do you want to know the MTU size (largest possible > Ethernet packet size)? This shouldn't really matter, since large TCP > messages will be split into a sequence of IP datagrams, and large IP > datagrams will be automatically fragmented and then reassembled at the > other end. > > Is there a specific reason this is important to you? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ I am trying to determine the actual network link speed. From http Tue Jan 13 11:01:25 2009 From: http (Paul Rubin) Date: 13 Jan 2009 08:01:25 -0800 Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <7xljtfw5yi.fsf@ruckus.brouhaha.com> imageguy writes: > Using py2.5.4 and entering the following lines in IDLE, I don't really > understand why I get the result shown in line 8. > > Note the difference between lines 7 and 10 is that 'else' clause > result enclosed in brackets, however, in line 2, both the 'c,d' > variables are assign correctly without the brackets being required. c,d = n if n is not None else 0,0 parses as: c,d = (n if n is not None else 0), 0 In the case where n is None, c and d are both set to 0. In the case where n is a tuple, c is set to the tuple and d is set to 0. Does that help? From clp2 at rebertia.com Tue Jan 13 11:14:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 08:14:49 -0800 Subject: Relative performance of comparable regular expressions In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> References: <5f3d75d6-e5b7-499f-87b5-cdd4a1574ee0@t26g2000prh.googlegroups.com> <7F0503CD69378F49BE0DC30661C6CCF602494E2F@enbmail01.lsi.com> Message-ID: <50697b2c0901130814x5541273ay34b7727160174a4b@mail.gmail.com> On Tue, Jan 13, 2009 at 6:16 AM, Barak, Ron wrote: > Hi John, > > Thanks for the below - teaching me how to fish ( instead of just giving > me a fish :-) > Now I could definitely get the answers for myself, and also be a bit more > enlightened. > > As for your (2) remark below (on my question: Which would give better > performance, matching with "^[a-zA-Z]{3}", or with "^\S{3}" ?): > (2) I think you mean "^\s{3}" not "^\S{3}", > I actually did meant to use \S, namely - a character that is not a > white-space. (A) Please don't top-post, it makes replying to you more awkward and makes it harder for readers to follow the conversation. (B) But "^[a-zA-Z]{3}", and "^\S{3}" aren't even equivalent! \S allows *digits* and *punctuation* too, whereas the former *only* matches letters. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > -----Original Message----- > From: John Machin [ > ] > Sent: Tuesday, January 13, 2009 11:15 > To: python-list at python.org > Subject: Re: Relative performance of comparable regular expressions > > On Jan 13, 7:24 pm, "Barak, Ron" wrote: >> Hi, >> >> I have a question about relative performance of comparable regular >> expressions. >> >> I have large log files that start with three letters month names >> (non-unicode). >> >> Which would give better performance, matching with "^[a-zA-Z]{3}", or >> with "^\S{3}" ? > > (1) If you want to match at the start of a line, use re.match() > *without* the pointless "^". Don't use re.search with a pattern starting > with "^" -- it won't be any faster than and it could be a lot worse; > re.search doesn't know to stop if the first match fails: > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.match(text)" > 1000000 loops, best of 3: 1.15 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*100" "rx.search(text)" > 100000 loops, best of 3: 4.47 usec per loop > > command-prompt>\python26\python -m timeit -s"import re;rx=re.compile > ('^AB') > ;text='Z'*1000" "rx.search(text)" > 10000 loops, best of 3: 34.1 usec per loop > > (2) I think you mean "^\s{3}" not "^\S{3}" > > (3) Now that you've seen how to do timings, over to you :-) > >> Also, which is better (if different at all): "\d\d" or "\d{2}" ? >> Also, would matching "." be different (performance-wise) than matching the >> actual character, e.g. matching ":" ? >> And lastly, at the end of a line, is there any performance difference >> between "(.+)$" and "(.+)" > > Cheers, > John From grimson at gmx.de Tue Jan 13 11:22:24 2009 From: grimson at gmx.de (Grimson) Date: Tue, 13 Jan 2009 17:22:24 +0100 Subject: ctype problem Message-ID: <496CBFC0.3080809@gmx.de> hello out there, I have a problem with c-types. I made a c-library, which expects a pointer to a self defined structure. let the funtion call myfunction(struct interface* iface) and the struct: struct interface { int a; int b; char *c; } the Python ctype port of this structur would be: class INTERFACE(Structure): _fields_ = [("a" c_int), ("b", c_int), ("c", c_char)] in my python-struct a create a instance of INTERFACE myiface = INTERFACE() myiface.a = ctypes.c_int(80) myiface.b = ctypes.c_int(22) ... than I make a pointer onto it. p_iface = ctypes.pointer(myiface) and I tried it also with a reference r_iface = ctypes.byref(myiface) but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) works properly. The function is been called but it reads only zeros (0) for each parameter (member in the struct). Where is my fault? Thank you.. sincerely chris From gandalf at shopzeus.com Tue Jan 13 11:25:13 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 17:25:13 +0100 Subject: Standard IPC for Python? Message-ID: <496CC069.80909@shopzeus.com> I would like to develop some module for Python for IPC. Socket programming howto recommends that for local communication, and I personally experienced problems with TCP (see my previous post: "Slow network"). I was looking for semaphores and shared memory, but it is not in the standard lib. I was also thinking about unix domain sockets, but it is not available under windows. I was looking for non-standard modules as well, but only found a few references with insufficient information. For example: http://code.activestate.com/recipes/519626/ The question is: what is the standard way to implement fast and portable IPC with Python? Are there tools in the standard lib that can do this? Thanks, Laszlo From deets at nospam.web.de Tue Jan 13 11:35:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 13 Jan 2009 17:35:50 +0100 Subject: Standard IPC for Python? References: Message-ID: <6t3u76F94k2gU1@mid.uni-berlin.de> Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: "Slow > network"). > > I was looking for semaphores and shared memory, but it is not in the > standard lib. I was also thinking about unix domain sockets, but it is > not available under windows. > > I was looking for non-standard modules as well, but only found a few > references with insufficient information. For example: > > http://code.activestate.com/recipes/519626/ > > The question is: what is the standard way to implement fast and portable > IPC with Python? Are there tools in the standard lib that can do this? I use Pyro. Has always been fast enough for me. It spares you the troubles of bloated XML-documents other RPC-mechanisms use. Of course it is RPC, not "only" IPC - so it comes with a tradeoff. But so far, it has been always fast enough for me. Diez From philip at semanchuk.com Tue Jan 13 11:39:23 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 11:39:23 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CC069.80909@shopzeus.com> References: <496CC069.80909@shopzeus.com> Message-ID: <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> On Jan 13, 2009, at 11:25 AM, Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: > "Slow network"). > > I was looking for semaphores and shared memory, but it is not in the > standard lib. I was also thinking about unix domain sockets, but it > is not available under windows. > > I was looking for non-standard modules as well, but only found a few > references with insufficient information. For example: > > http://code.activestate.com/recipes/519626/ > > The question is: what is the standard way to implement fast and > portable IPC with Python? Are there tools in the standard lib that > can do this? They're not in the standard lib, but I have 3 modules for Python IPC. They're all Unix-only. posix_ipc gives you semaphores, shared memory and messages queues: http://semanchuk.com/philip/posix_ipc/ sysv_ipc gives you semaphores and shared memory: http://semanchuk.com/philip/sysv_ipc/ shm also gives access to SysV semaphores and shared memory: http://nikitathespider.com/python/shm/ The only reason to use shm over the sysv_ipc module is that shm supports versions of Python < 2.5. I'm not developing shm any further, so avoid using it if possible. Here's an overview that compares the three: http://semanchuk.com/philip/PythonIpc/ The overview of the overview is that posix_ipc is the one to use if you can because it is the simplest. sysv_ipc is more broadly supported but is more complicated for programmer (me) and user (you) alike. Bugs reports are of course welcome. Enjoy! Philip From garrickp at gmail.com Tue Jan 13 11:49:51 2009 From: garrickp at gmail.com (Falcolas) Date: Tue, 13 Jan 2009 08:49:51 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: <4d0a6584-44d8-45ba-8315-dc5235e974f8@v5g2000prm.googlegroups.com> On Jan 11, 6:59?pm, "James Mills" wrote: > Hey all, > > The following fails for me: > > >>> from urllib2 import urlopen > >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml") For what it's worth, I've had a similar problem with the urlopen as well. Using the library default urlopen results in an error, but if I build an opener with the basic handlers, it works just fine. >>> import urllib2 >>> f = urllib2.urlopen("http://localhost:8000") Traceback (most recent call last): File "", line 1, in f = urllib2.urlopen("http://localhost:8000") File "C:\Python25\lib\urllib2.py", line 121, in urlopen return _opener.open(url, data) File "C:\Python25\lib\urllib2.py", line 380, in open response = meth(req, response) File "C:\Python25\lib\urllib2.py", line 491, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python25\lib\urllib2.py", line 418, in error return self._call_chain(*args) File "C:\Python25\lib\urllib2.py", line 353, in _call_chain result = func(*args) File "C:\Python25\lib\urllib2.py", line 499, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden >>> opener = urllib2.OpenerDirector() >>> opener.add_handler(urllib2.HTTPHandler()) >>> opener.add_handler(urllib2.HTTPDefaultErrorHandler()) >>> f = opener.open("http://localhost:8000") >>> f.read() 'something relevant' From stefan_ml at behnel.de Tue Jan 13 11:52:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 13 Jan 2009 17:52:25 +0100 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> Message-ID: <496cc6c9$0$31870$9b4e6d93@newsspool3.arcor-online.net> abhi wrote: > Now I want to utf-16 so I am trying to use the first one, but it is > giving back NULL in case of PyObject is already Unicode type which is > expected. What puzzles me is that PyUnicode_FromObject(PyObject *obj) > is passing irrespective of type of PyObject. The API says it is > Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") but if I > use that, it returns NULL where as PyUnicode_FromObject works. > > Is there any way by which I can take in any PyObject and convert it to > utf-16 object? Any help is appreciated. Use PyUnicode_FromObject() to convert the (non-string) object to a unicode object, then encode the unicode object as UTF-16 using the respecive functions in the codecs API (see the bottom of the C-API docs page for the unicode object). Note, however, that you will not succeed to convert a byte string to the corresponding unicode string using PyUnicode_FromObject(), except in the simple case where the string is ASCII encoded. Doing this right requires explicit decoding using a byte encoding that you must specify (again, see the codecs API). Stefan From bedouglas at earthlink.net Tue Jan 13 11:59:22 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 13 Jan 2009 08:59:22 -0800 Subject: basic python list/dict/key question/issues.. Message-ID: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> Hi.. quite new to python, and have a couple of basic question: i have ("term":["1","2","3"]) as i understand it, this is a list, yes/no? how can i represent this as a dict/list? i've got a few of these that i'm trying to deal with.. thanks From Scott.Daniels at Acm.Org Tue Jan 13 12:22:39 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 09:22:39 -0800 Subject: Problems in Using C-API for Unicode handling In-Reply-To: <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> References: <31e47e0c-1c50-4047-b5d9-6ddc723e0323@r15g2000prd.googlegroups.com> <05e6c330-8d3c-44fa-ae6d-006938d7bd8a@b38g2000prf.googlegroups.com> Message-ID: abhi wrote: > On Jan 13, 12:17 pm, Terry Reedy wrote: >> abhi wrote: >>> Hi, >>> I am trying to handle Unicode objects in C (Python 2.5.2).... > ... I want to convert this explicitely to utf-16.... You are trying to get Unicode and UTF-16, whereas you should think of those two as distinct. UTF-16 is an encoded form (bytes) from the abstract "Unicode is characters". What you want in Python is: u'abc'.encode('UTF-16') So look for something returning a string by invoking the decode method. --Scott David Daniels Scott.Daniels at Acm.Org From rdcollum at gmail.com Tue Jan 13 12:33:42 2009 From: rdcollum at gmail.com (Roger) Date: Tue, 13 Jan 2009 09:33:42 -0800 (PST) Subject: basic python list/dict/key question/issues.. References: Message-ID: On Jan 13, 11:59?am, "bruce" wrote: > Hi.. > > quite new to python, and have a couple of basic question: > > i have > ?("term":["1","2","3"]) > > as i understand it, this is a list, yes/no? > > how can i represent this as a dict/list? > > i've got a few of these that i'm trying to deal with.. > > thanks x = {"term":["1","2","3"]} is a dictionary and the value of the key "term" is a list. From marduk at letterboxes.org Tue Jan 13 12:35:55 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 12:35:55 -0500 Subject: basic python list/dict/key question/issues.. In-Reply-To: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> References: <10aa01c975a0$49d73eb0$0301a8c0@tmesa.com> Message-ID: <1231868155.3422.18.camel@localhost.localdomain> On Tue, 2009-01-13 at 08:59 -0800, bruce wrote: > Hi.. > > quite new to python, and have a couple of basic question: > > i have > ("term":["1","2","3"]) > > as i understand it, this is a list, yes/no? > No, that's invalid syntax: >>> ("term":["1","2","3"]) File "", line 1 ("term":["1","2","3"]) ^ SyntaxError: invalid syntax > how can i represent this as a dict/list? ["this","is","a","list"] {"this":1, "is":2, "a": 3, "dict": 3} > > i've got a few of these that i'm trying to deal with.. If you are new to python you might to read up on a tutorial. http://docs.python.org/tutorial/ From gandalf at shopzeus.com Tue Jan 13 12:40:06 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 18:40:06 +0100 Subject: Standard IPC for Python? In-Reply-To: <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> Message-ID: <496CD1F6.3080604@shopzeus.com> > The only reason to use shm over the sysv_ipc module is that shm > supports versions of Python < 2.5. I'm not developing shm any further, > so avoid using it if possible. Hmm, we are using FreeBSD, Ubuntu and Windows. Unfortunately - posix_ipc is broken under FreeBSD - sysv_ipc does not support message queues at all - shm is not maintained - windows is not supported by any of these modules It is so interesting that there is no standard implementation for IPC in Python. I would think it is a very common task for programmers. I might find myself writting a new IPC module that works under Windows as well. Can anyone tell me if select.select works under OS X? Thanks, Laszlo From gandalf at shopzeus.com Tue Jan 13 12:42:01 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 18:42:01 +0100 Subject: Standard IPC for Python? In-Reply-To: <6t3u76F94k2gU1@mid.uni-berlin.de> References: <6t3u76F94k2gU1@mid.uni-berlin.de> Message-ID: <496CD269.20105@shopzeus.com> > I use Pyro. Has always been fast enough for me. It spares you the troubles > of bloated XML-documents other RPC-mechanisms use. > > Of course it is RPC, not "only" IPC - so it comes with a tradeoff. But so > far, it has been always fast enough for me. > Unfortunately, I'm developing an ORB, and using another type of ORB to transport data would be silly. :-) I need the lower level stuff. From bdesth.quelquechose at free.quelquepart.fr Tue Jan 13 12:47:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 13 Jan 2009 18:47:14 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> Message-ID: <496ce14b$0$18741$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > >> Bruno Desthuilliers writes: >>> Why on earth are you using Python if you don't like the way it work ??? >> Why on earth keep releasing new versions of Python if the old ones are >> already perfect? > > That's a fallacious argument. Nobody is arguing that any specific version > of Python is perfect, but clearly many people do like the general design > choices of the language, that is, the way it works. Thanks for making my point clear. > *If* you don't like the way it works, and you have a choice in the > matter, perhaps you should find another language that works more the way > you would prefer. > > On the other hand... Bruno's question is unfair. It is perfectly > reasonable to (hypothetically) consider Python to be the best *existing* > language while still wanting it to be improved (for some definition of > improvement). And that's the problem : what Paul suggests are not "improvements" but radical design changes. The resulting language - whatever it may be worth, I'm not making any judgement call here - would not be Python anymore. > Just because somebody has criticisms of Python, or a wish- > list of features, doesn't mean they hate the language. There's probably a whole range of nuances between "not liking" and "hating". And Paul is of course perfectly right to think that a language having this and that features from Python, but not this other one, would be a "better" language (at least according to it's own definition of "better"). Where I totally disagree is that it would make *Python* better. Also, my question was not that "unfair" (even if a bit provocative). I really wonder why peoples that seems to dislike one of the central features of Python - it's dynamism - still use it (assuming of course they are free to choose another language). And FWIW, I at least had a partial answer on this. From gert.cuykens at gmail.com Tue Jan 13 12:50:23 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 13 Jan 2009 09:50:23 -0800 (PST) Subject: i want to join developer group References: Message-ID: <47062d42-2e79-4d38-a869-db4d01ee0eba@a12g2000pro.googlegroups.com> On Jan 13, 1:36?pm, gkc... at gmail.com wrote: > Hello, > ? ? ? I want to contribute to the open source projects. Open source is about finding where you are good at. Contributing is a product of the skills you learn. From philip at semanchuk.com Tue Jan 13 13:09:09 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 13:09:09 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CD1F6.3080604@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> On Jan 13, 2009, at 12:40 PM, Laszlo Nagy wrote: > >> The only reason to use shm over the sysv_ipc module is that shm >> supports versions of Python < 2.5. I'm not developing shm any >> further, so avoid using it if possible. > Hmm, we are using FreeBSD, Ubuntu and Windows. Unfortunately > > - posix_ipc is broken under FreeBSD A clarification: the module posix_ipc is *not* broken. It exposes FreeBSD's implementation of POSIX IPC which has broken semaphores (based on my experiments, anyway). The practical result for you is the same but the difference is very important to me as the module author. Fixing the posix_ipc module is under my control, fixing FreeBSD's POSIX IPC is not. > - sysv_ipc does not support message queues at all That's true, but in your original email you said you were looking for "semaphores and shared memory". There was no mention of message queues. I'm working on message queue support, but the Sys V IPC API is a headache and takes longer to code against than the POSIX API. > - shm is not maintained SHM *is* maintained. As I said in my first email and as it says on the Web page, I'm not developing it any further. No further development != unmaintained. Also, it offers only a subset of the features in sysv_ipc, so its status is not of great concern unless you're using Python < 2.5. > - windows is not supported by any of these modules Windows uses a different API, but I think there are some packages that can make Windows look like some flavor of Unix. For instance, Cygwin seems to expose some relevant APIs like sem_open(), sem_post(), etc: http://cygwin.com/cygwin-api/compatibility.html#std-susv3 It might be that posix_ipc would work with this package with just a little tweaking. I have no idea. As I said on the posix_ipc page, if anyone wants to tackle this one and send me bug reports, please do! > It is so interesting that there is no standard implementation for > IPC in Python. I would think it is a very common task for > programmers. I might find myself writting a new IPC module that > works under Windows as well. Feel free to reinvent the wheel. Or, you could pitch in and help with what's already out there. bye Philip From Scott.Daniels at Acm.Org Tue Jan 13 13:13:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 13 Jan 2009 10:13:47 -0800 Subject: exec in a nested function yields an error In-Reply-To: References: Message-ID: TP wrote: > ... > def f(): > def f_nested(): > exec "a=2" > print a > f() > ... What is the problem? Why? What it wants is you to provide the "in context" portion of the exec statement. I expect the reason it fails is that there is no dictionary that is available as locals that encompasses the locals of both f and f_nested, so you'll have to be explicit about what you mean. So, the code wants you to say something like: def f(): def f_nested(): exec "a=2" in globals(), locals() print a return f_nested f() --Scott David Daniels Scott.Daniels at Acm.Org From gandalf at shopzeus.com Tue Jan 13 13:22:48 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 19:22:48 +0100 Subject: Standard IPC for Python? In-Reply-To: <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> Message-ID: <496CDBF8.5020402@shopzeus.com> >> >> - posix_ipc is broken under FreeBSD > > A clarification: the module posix_ipc is *not* broken. It exposes > FreeBSD's implementation of POSIX IPC which has broken semaphores > (based on my experiments, anyway). The practical result for you is the > same but the difference is very important to me as the module author. > Fixing the posix_ipc module is under my control, fixing FreeBSD's > POSIX IPC is not. Mea culpa. :-) I did not want to offend you. >> - sysv_ipc does not support message queues at all > > That's true, but in your original email you said you were looking for > "semaphores and shared memory". There was no mention of message queues. You are right again. :-) I would like to use IPC beacuse I want to send messages between processes. >> - shm is not maintained > > SHM *is* maintained. As I said in my first email and as it says on the > Web page, I'm not developing it any further. No further development != > unmaintained. My bad again. :-( This is not my day. >> It is so interesting that there is no standard implementation for IPC >> in Python. I would think it is a very common task for programmers. I >> might find myself writting a new IPC module that works under Windows >> as well. > > Feel free to reinvent the wheel. Or, you could pitch in and help with > what's already out there. From invalid at invalid Tue Jan 13 13:23:26 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 13 Jan 2009 12:23:26 -0600 Subject: Ethernet packet size python References: <61695ed2-c769-4fbf-a218-a45a115aacf8@v5g2000prm.googlegroups.com> Message-ID: On 2009-01-13, Steve Holden wrote: > K-man wrote: >> >> I am sending data using the socket interface in python, but I >> want to know how big the ethernet packet size is (in bytes). >> I didn't really see a way using the socket library of how to >> do this. Any suggestions? > > There is no way to know what size Ethernet packets will result > from specific traffic. Unless he's using a low level API such as AF_PACKET/SOCK_RAW. If that's the case then the packets will be exactly as big as he makes them. And he wouldn't be asking this question. :) > Or do you want to know the MTU size (largest possible Ethernet > packet size)? This shouldn't really matter, since large TCP > messages will be split into a sequence of IP datagrams, and > large IP datagrams will be automatically fragmented and then > reassembled at the other end. > > Is there a specific reason this is important to you? If it's just idle curiosity, then wireshark or tcpdump can show one exactly what's going on on the wire. A reading of http://en.wikipedia.org/wiki/Transmission_Control_Protocol should also allow one to predict pretty accurately what's going to happen when you call send(). -- Grant Edwards grante Yow! I want EARS! I want at two ROUND BLACK EARS visi.com to make me feel warm 'n secure!! From jeff at jmcneil.net Tue Jan 13 13:28:24 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 13 Jan 2009 10:28:24 -0800 (PST) Subject: Simple CGI-XMLRPC failure References: Message-ID: I don't have the version in front of me now as that was on my home machine, but Python was the same right down to the revision number. Unless you've mucked with it, it's the same file that I've got on my box. Jeff On Jan 13, 10:51 am, "Mike MacHenry" wrote: > I figured it was some kind of bug. Must be either a bug with my > version of either the library (most likely) or perhaps some weird > environment setting that I have set incorrectly (also likely). How can > I figure out which version of SimpleXMLRPCServer I'm running? Do you > run Ubuntu by any chance? If you which version? > > Does anyone know of any environment settings I could look into on > Apache or Python? > > -mike > > On Mon, Jan 12, 2009 at 9:02 PM, Jeff McNeil wrote: > > On Jan 12, 12:40 pm, "Mike MacHenry" wrote: > >> I am having a difficult time understanding why my very simple > >> CGI-XMLRPC test isn't working. I created a server to export two > >> functions, the built-in function "pow" and my own identity function > >> "i". I run a script to call both of them and the "pow" work fine but > >> the "i" gives me an error that says my XMLRPC server doesn't support > >> than name. Here is the code for both files and the output: > > >> #!/usr/bin/env python > >> #This file is /usr/lib/cgi-bin/roundwarerpc.py > >> from SimpleXMLRPCServer import CGIXMLRPCRequestHandler > >> def i(x): > >> return x > >> server = CGIXMLRPCRequestHandler() > >> server.register_function(pow) > >> server.register_function(i) > >> server.handle_request() > > >> #!/usr/bin/env python > >> #This file is ~/test.py > >> import xmlrpclib > >> server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py") > >> print server.pow(2,3) > >> print server.i(10) > > >> #This is the STDOUT and STDERR when running ~/test.py > >> dskippy at dskippy-laptop:$ python test.py 8 > >> Traceback (most recent call last): > >> File "test.py", line 4, in > >> print server.test(10) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ > >> return self.__send(self.__name, args) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request > >> verbose=self.__verbose > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request > >> return self._parse_response(h.getfile(), sock) > >> File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response > >> return u.close() > >> File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close > >> raise Fault(**self._stack[0]) > >> xmlrpclib.Fault: :method "i" > >> is not supported'> > > >> Does anyone know what might be wrong with this? > > >> Thanks for the help, > >> -mike > > >> p.s. > >> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > >> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > >> Server version Apache/2.2.8 (Ubuntu) > >> Server built: Jun 25 2008 13:54:13 > > > I copied your code verbatim and I don't have any issues with it at > > all. Same version of Python, same version of Apache. > > > In SimpleXMLRPCServer.py, register_function adds directly to a > > self.funcs dictionary, so an instance variable of the same name > > shouldn't hurt anything. That exception is only raised when a > > self.funcs lookup raises a KeyError unless you're registering an > > instance. > > > -- > >http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Tue Jan 13 13:39:47 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 13 Jan 2009 12:39:47 -0600 Subject: Converting from PyUnicodeObject to char * without calling C API In-Reply-To: <496CB4D4.8070407@mrabarnett.plus.com> References: <18796.45853.852587.379554@montanaro.dyndns.org> <496CB4D4.8070407@mrabarnett.plus.com> Message-ID: <18796.57331.670546.510420@montanaro.dyndns.org> MRAB> Should you be using "char *" when they aren't char? Is there a MRAB> wide char type of some sort? No, I shouldn't. The storage is wchar_t *, what you get with my first printed expression: (gdb) set $__f = (PyUnicodeObject *)(co->co_filename) (gdb) p *$__f->str@$__f->length $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121} That's not too readable. I'm not sure I can do much with that without having a process to use. Ideally: print "".join([ chr(x) for x in *$__f->str@$__f->length]) The question is, how do you do that in gdb-speak??? Skip From philip at semanchuk.com Tue Jan 13 13:55:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 13:55:17 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CDBF8.5020402@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> Message-ID: <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> On Jan 13, 2009, at 1:22 PM, Laszlo Nagy wrote: > >>> >>> - posix_ipc is broken under FreeBSD >> >> A clarification: the module posix_ipc is *not* broken. It exposes >> FreeBSD's implementation of POSIX IPC which has broken semaphores >> (based on my experiments, anyway). The practical result for you is >> the same but the difference is very important to me as the module >> author. Fixing the posix_ipc module is under my control, fixing >> FreeBSD's POSIX IPC is not. > Mea culpa. :-) I did not want to offend you. Thank you, Laszlo, I appreciate that. > >>> - sysv_ipc does not support message queues at all >> >> That's true, but in your original email you said you were looking >> for "semaphores and shared memory". There was no mention of message >> queues. > You are right again. :-) I would like to use IPC beacuse I want to > send messages between processes. If you can wait a bit and Windows is not crucial, sysv_ipc should have message queue support before too long. >>> - shm is not maintained >> >> SHM *is* maintained. As I said in my first email and as it says on >> the Web page, I'm not developing it any further. No further >> development != unmaintained. > My bad again. :-( This is not my day. >>> It is so interesting that there is no standard implementation for >>> IPC in Python. I would think it is a very common task for >>> programmers. I might find myself writting a new IPC module that >>> works under Windows as well. >> >> Feel free to reinvent the wheel. Or, you could pitch in and help >> with what's already out there. I realize that lack of Windows support is a big minus for both of these modules. As I said, any help getting either posix_ipc or sysv_ipc working under Windows would be much appreciated. It sounds like you have access to the platform and incentive to see it working, so dig in if you like. Once I get message queues working for SysV, I want to support unnamed semaphores in the POSIX module and then I'll consider these modules mainly feature-complete. After that I can think about adding more features like: - Windows support - Python 2.6/3.0 support - buffer-style access to shared memory (slicing, etc.) - Merging these two into a generic ipc module that's agnostic about POSIX versus Sys V. That might not be realistic. If I have time in the future, I'll tackle these items myself. But these projects are just educational for me and paying work will take priority. bye Philip From gandalf at shopzeus.com Tue Jan 13 14:01:32 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 20:01:32 +0100 Subject: Standard IPC for Python? In-Reply-To: <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> Message-ID: <496CE50C.6000308@shopzeus.com> > > I realize that lack of Windows support is a big minus for both of > these modules. As I said, any help getting either posix_ipc or > sysv_ipc working under Windows would be much appreciated. It sounds > like you have access to the platform and incentive to see it working, > so dig in if you like. Maybe I can help with windows. I just need to figure out what to use: pipes or windows sockets? http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx From philip at semanchuk.com Tue Jan 13 14:37:39 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 14:37:39 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CE50C.6000308@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2009, at 2:01 PM, Laszlo Nagy wrote: > >> >> I realize that lack of Windows support is a big minus for both of >> these modules. As I said, any help getting either posix_ipc or >> sysv_ipc working under Windows would be much appreciated. It sounds >> like you have access to the platform and incentive to see it >> working, so dig in if you like. > Maybe I can help with windows. I just need to figure out what to > use: pipes or windows sockets? > > http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx I was suggesting getting posix_ipc or sysv_ipc to compile against a compatibility library (Cygwin?) under Windows. It sounds like you're proposing something totally different, no? From andygrove73 at gmail.com Tue Jan 13 14:54:07 2009 From: andygrove73 at gmail.com (ag73) Date: Tue, 13 Jan 2009 11:54:07 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError Message-ID: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Hi, I am trying to parse data posted to a Python class that extends http.server.BaseHTTPRequestHandler. Here is the code I am using: def do_POST(self): ctype, pdict = cgi.parse_header(self.headers['Content-Type']) length = int(self.headers['Content-Length']) if ctype == 'application/x-www-form-urlencoded': qs = self.rfile.read(length) print("qs="+str(qs)) form = urllib.parse.parse_qs(qs, keep_blank_values=1) The print statement shows the following output, so it looks like the data is being posted correctly: qs=b'file_data=b %27IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCiMgZW5jb2Rpbmc6IHV0Zi04CiIiIgp1bnRpdGxlZC5weQoK %5CnQ3JlYXRlZCBieSBBbmR5IEdyb3ZlIG9uIDIwMDgtMTItMDIuCkNvcHlyaWdodCAoYykgMjAwOCBf %5CnX015Q29tcGFueU5hbWVfXy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4KIiIiCgppbXBvcnQgc3lzCmlt %5CncG9ydCBvcwoKCmRlZiBtYWluKCk6CglwcmludCAibmFtZTE9dmFsdWUxIgoJcHJpbnQgIm5hbWUy %5CnPXZhbHVlMiIKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgoJbWFpbigpCgo%3D %5Cn%27&filename=test.py' However, the last line of code that calls parse_qs causes the following exception to be thrown: Type str doesn't support the buffer API I haven't been able to find any information on the web about this. Any pointers would be appreciated. I am using ActivePython 3.0 and have tried this on Linux and Max OS X with the same outcome. Thanks, Andy. From sromero at gmail.com Tue Jan 13 15:02:54 2009 From: sromero at gmail.com (Santiago Romero) Date: Tue, 13 Jan 2009 12:02:54 -0800 (PST) Subject: Read binary file and dump data in Message-ID: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Hi. Until now, all my python programs worked with text files. But now I'm porting an small old C program I wrote lot of years ago to python and I'm having problems with datatypes (I think). some C code: fp = fopen( file, "rb"); while !feof(fp) { value = fgetc(fp); printf("%d", value ); } I started writing: fp = open(file, "rb") data = fp.read() for i in data: print "%d, " % (int(i)) But it complains about i not being an integer... . len(data) shows exactly the file size, so maybe is a "type cast" problem... :-? What's the right way to work with the binary data (read 1 byte values and work with them, dumping them as an integer in this case)? Thanks. From gandalf at shopzeus.com Tue Jan 13 15:04:04 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 13 Jan 2009 21:04:04 +0100 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <496CF3B4.4040709@shopzeus.com> > > I was suggesting getting posix_ipc or sysv_ipc to compile against a > compatibility library (Cygwin?) under Windows. It sounds like you're > proposing something totally different, no? OK I see. But probably I do not want to use Cygwin because that would create another dependency. I understand that posix_ipc/sysv is not natively supported under windows. What about this: - create a wrapper, using ctypes, /windll / cdll/ to access API functions - use CreateFileMapping on the page file to create shared memory (a la windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) - use CreateEvent/WaitForSingleObject for signaling (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) - these should be enough to implement shared memory functions and message queues under windows, and that might be a quick solution at least for me. - it might also be used to emulate the same posix_ipc interface, without any external dependency added (cygwin). All I care about is to create a working message queue. But if you think that this ctypes hack would be useful for other users, then I can try to implement it. I must tell you that I'm not very familiar with C programming (it was a long time ago...) and I do not own MSVC. (Hmm, can I compile this with mingw?) Laszlo From marduk at letterboxes.org Tue Jan 13 15:18:37 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 13 Jan 2009 15:18:37 -0500 Subject: Read binary file and dump data in In-Reply-To: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: <1231877917.3422.26.camel@localhost.localdomain> On Tue, 2009-01-13 at 12:02 -0800, Santiago Romero wrote: > Hi. > > Until now, all my python programs worked with text files. But now I'm > porting an small old C program I wrote lot of years ago to python and > I'm having problems with datatypes (I think). > > some C code: > > fp = fopen( file, "rb"); > while !feof(fp) > { > value = fgetc(fp); > printf("%d", value ); > } > > I started writing: > > fp = open(file, "rb") > data = fp.read() > for i in data: > print "%d, " % (int(i)) > > But it complains about i not being an integer... . len(data) shows > exactly the file size, so maybe is a "type cast" problem... :-? > int() expects something that "looks like" an integer. E.g. int(2) => 2 int(2.0) => 2 int('2') => 2 int('c') => ValueError If you are reading arbitrary bytes then it will likely not always "look" like integers. What you probably meant is: for i in data: print "%d, " % ord(i) But if you are really dealing with C-like data structures then you might be better off using the struct module. -a From imageguy1206 at gmail.com Tue Jan 13 15:43:27 2009 From: imageguy1206 at gmail.com (imageguy) Date: Tue, 13 Jan 2009 12:43:27 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <6e62a728-e441-4e24-8ace-c210f6508223@n33g2000pri.googlegroups.com> On Jan 13, 1:01?am, Miles wrote: > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > > Using py2.5.4 and entering the following lines in IDLE, I don't really > > understand why I get the result shown in line 8. > > > Note the difference between lines 7 and 10 is that 'else' clause > > result enclosed in brackets, however, in line 2, both the 'c,d' > > variables are assign correctly without the brackets being required. > > > 1) >>> n = None > > 2) >>> c,d = n if n is not None else 0,0 > > 3) >>> print c,d, type(c), type(d) > > 4) 0 0 > > The ternary expression has higher precedence than the comma, so the > actual effect of line 2 (and 8) is: > > >>> c, d = (n if n is not None else 0), 0 > > Or written more explicitly: > > >>> c = n if n is not None else 0 > >>> d = 0 > > So the only correct way to write the expression, for the result you > want, is to use your line 10: > > > 10) ?>>> c,d = n if n is not None else (0,0) > > But if you're struggling with the precedence issues, I'd recommend > ditching ternary expressions altogether and using full conditional > blocks. > > -Miles Thanks. Hadn't thought through the operator precedence and the affect of the comma. This was the first time I tried to use with tuples, so will be more careful next time or stick to control blocks. g. From orsenthil at gmail.com Tue Jan 13 15:48:29 2009 From: orsenthil at gmail.com (Phoe6) Date: Tue, 13 Jan 2009 12:48:29 -0800 (PST) Subject: Previous PyCon Videos, anyone? Message-ID: Hello All, Youtube channel of pycon09 has some videos ( http://www.youtube.com/user/pycon08), but most of them don't have a sufficiently good audio quality. Is there anyone who has better recording of an earlier PyCon talk? If yes, can you please point me to the location? Thanks, Senthil From clp2 at rebertia.com Tue Jan 13 15:50:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 12:50:10 -0800 Subject: Read binary file and dump data in In-Reply-To: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: <50697b2c0901131250g2f64ee91kb10322ccfca50ee9@mail.gmail.com> On Tue, Jan 13, 2009 at 12:02 PM, Santiago Romero wrote: > > Hi. > > Until now, all my python programs worked with text files. But now I'm > porting an small old C program I wrote lot of years ago to python and > I'm having problems with datatypes (I think). > > some C code: > > fp = fopen( file, "rb"); > while !feof(fp) > { > value = fgetc(fp); > printf("%d", value ); > } > > I started writing: > > fp = open(file, "rb") > data = fp.read() > for i in data: > print "%d, " % (int(i)) > > But it complains about i not being an integer... . len(data) shows > exactly the file size, so maybe is a "type cast" problem... :-? > > What's the right way to work with the binary data (read 1 byte values > and work with them, dumping them as an integer in this case)? Albert already pointed out the problem with using int(), so I'll just say that you might be interested in the `struct` module: http://docs.python.org/library/struct.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Russ.Paielli at gmail.com Tue Jan 13 15:58:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 12:58:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> On Jan 13, 9:47 am, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : > > > On Mon, 12 Jan 2009 13:36:07 -0800, Paul Rubin wrote: > > >> Bruno Desthuilliers writes: > >>> Why on earth are you using Python if you don't like the way it work ??? > >> Why on earth keep releasing new versions of Python if the old ones are > >> already perfect? > > > That's a fallacious argument. Nobody is arguing that any specific version > > of Python is perfect, but clearly many people do like the general design > > choices of the language, that is, the way it works. > > Thanks for making my point clear. > > > *If* you don't like the way it works, and you have a choice in the > > matter, perhaps you should find another language that works more the way > > you would prefer. > > > On the other hand... Bruno's question is unfair. It is perfectly > > reasonable to (hypothetically) consider Python to be the best *existing* > > language while still wanting it to be improved (for some definition of > > improvement). > > And that's the problem : what Paul suggests are not "improvements" but > radical design changes. The resulting language - whatever it may be > worth, I'm not making any judgement call here - would not be Python > anymore. > > > Just because somebody has criticisms of Python, or a wish- > > list of features, doesn't mean they hate the language. > > There's probably a whole range of nuances between "not liking" and > "hating". And Paul is of course perfectly right to think that a language > having this and that features from Python, but not this other one, would > be a "better" language (at least according to it's own definition of > "better"). Where I totally disagree is that it would make *Python* better. > > Also, my question was not that "unfair" (even if a bit provocative). I > really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of course > they are free to choose another language). And FWIW, I at least had a > partial answer on this. I think the issue here is the distinction between hacking and software engineering. I may be misusing the term "hacking," but I do not mean it in a pejoritive sense. I just mean getting things done fast without a lot of concern for safety, security, and long-term maintainability and scalability. I'm not a computer scientist, but it seems to me that Python is great for hacking and good for software engineering, but it is not ideal for software engineering. What Paul is suggesting, I think, is that Python should move in the direction of software engineering. Whether that can be done without compromising its hacking versatility is certainly a valid question, but if it can be done, then why not do it? Certainly one basic principle of software engineering is data encapsulation. Tacking new attributes onto class instances all over the place may be convenient and useful in many cases, but it is not consistent with good software engineering. If the programmer could somehow disallow it in certain classes, that could be useful, providing that those who wish to continue doing it would be free to do so. If class attributes could somehow be declared private, that would be useful too. Optional explicit type declarations could also be useful -- and I believe Python does have that now, so no need to argue about that. Why do I continue to use Python when I have so many "complaints" about it? As everyone here knows, it has many good qualities. My work falls somewhere in the middle between "hacking" and software engineering. I am developing a research prototype of a safety-critical system. A research prototype is not safety-critical itself, and it needs to be flexible enough to try new ideas quickly, but it also needs to serve as a model for a well-engineered system. Is Python the right choice? I think so, but I don't know for sure. From gregsaundersemail at gmail.com Tue Jan 13 16:11:35 2009 From: gregsaundersemail at gmail.com (Greg) Date: Tue, 13 Jan 2009 13:11:35 -0800 (PST) Subject: Reminder: Calgary Python User Group - 1st Meeting tomorrow - Wed Jan 14 Message-ID: <75ea4945-e8f0-4e11-9b0e-f501e5f05fc7@l33g2000pri.googlegroups.com> Our first meeting is tomorrow night at: Good Earth Cafe, 1502 11 Street SW, Calgary, AB Wed Jan 14, 7pm - 8pm Topic: Google App Engine http://www.google.com/calendar/event?eid=Z2Q0cDdpYmJobzVzbzZobXJxbTc2OHUxYW9fMjAwOTAxMTVUMDIwMDAwWiBhZG1pbkBweXRob25jYWxnYXJ5LmNvbQ&ctz=America/Edmonton Google Group / mailing list: http://groups.google.ca/group/pythoncalgary Website: http://www.pythoncalgary.com/ Thanks Greg From drobinow at gmail.com Tue Jan 13 16:31:34 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Tue, 13 Jan 2009 13:31:34 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2:37?pm, Philip Semanchuk wrote: > On Jan 13, 2009, at 2:01 PM, Laszlo Nagy wrote: > > > > >> I realize that lack of Windows support is a big minus for both of ? > >> these modules. As I said, any help getting either posix_ipc or ? > >> sysv_ipc working under Windows would be much appreciated. It sounds ? > >> like you have access to the platform and incentive to see it ? > >> working, so dig in if you like. > > Maybe I can help with windows. I just need to figure out what to ? > > use: pipes or windows sockets? > > >http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx > > I was suggesting getting posix_ipc or sysv_ipc to compile against a ? > compatibility library (Cygwin?) under Windows. It sounds like you're ? > proposing something totally different, no? It's not really correct to call Cygwin a compatibility library. It's more of a separate system. In any case, the current version (1.5.25) does not support sem_unlink or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under test, will support these. I haven't tried it yet. I expect it will work OOTB. From castironpi at gmail.com Tue Jan 13 16:54:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 13:54:58 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <0b91a5c9-01a0-4c6e-aa73-853c6a21611e@s20g2000yqh.googlegroups.com> On Jan 13, 2:04?pm, Laszlo Nagy wrote: > - create a wrapper, using ctypes, /windll / cdll/ to access API functions > - use CreateFileMapping on the page file to create shared memory (a la > windows:http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling > (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. > - it might also be used to emulate the same posix_ipc interface, without > any external dependency added (cygwin). > > All I care about is to create a working message queue. But if you think > that this ctypes hack would be useful for other users, then I can try to > implement it. > > I must tell you that I'm not very familiar with C programming (it was a > long time ago...) and I do not own MSVC. > > (Hmm, can I compile this with mingw?) > > Laszlo Yes. The flags in the Extending/Embedding C++ section work with mingw. You can create inheritable pipes with the CreatePipe API. 'mmap' provides shared memory, and it's a standard module. You may also like the 'multiprocessing' module, which comes with Python 2.6. From sjmachin at lexicon.net Tue Jan 13 16:58:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 13:58:36 -0800 (PST) Subject: Ternary operator and tuple unpacking -- What am I missing ? References: <375bac43-d1cc-4d70-91a8-7882619b5750@y1g2000pra.googlegroups.com> Message-ID: <54e40cc1-8133-43ba-813d-a2498784a93f@f20g2000yqg.googlegroups.com> On Jan 13, 5:36?pm, Steve Holden wrote: > Miles wrote: > > On Tue, Jan 13, 2009 at 12:02 AM, imageguy wrote: > >> Using py2.5.4 and entering the following lines in IDLE, I don't really > >> understand why I get the result shown in line 8. > > >> Note the difference between lines 7 and 10 is that 'else' clause > >> result enclosed in brackets, however, in line 2, both the 'c,d' > >> variables are assign correctly without the brackets being required. > > >> 1) >>> n = None > >> 2) >>> c,d = n if n is not None else 0,0 > >> 3) >>> print c,d, type(c), type(d) > >> 4) 0 0 > > > The ternary expression has higher precedence than the comma, so the > > actual effect of line 2 (and 8) is: > > >>>> c, d = (n if n is not None else 0), 0 > > > Or written more explicitly: > > >>>> c = n if n is not None else 0 > >>>> d = 0 > > > So the only correct way to write the expression, for the result you > > want, is to use your line 10: > > >> 10) ?>>> c,d = n if n is not None else (0,0) > > > But if you're struggling with the precedence issues, I'd recommend > > ditching ternary expressions altogether and using full conditional > > blocks. > > Yet another great example of why Guido was right to resist putting > conditional expressions into Python for so long (and wrong to succumb to > the demand). """I thought I said "Nobody mention the war!" """ IMO this is just an example of why (1) in general people who are unsure of operator precedence should use parentheses and (2) in particular it's not a good idea to try to write tuples without parentheses in any but the simpler cases like a, b = b, a From castironpi at gmail.com Tue Jan 13 16:59:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 13:59:50 -0800 (PST) Subject: ctype problem References: Message-ID: <6197f37d-0ea0-4430-a466-2f36b2011ea8@v42g2000yqj.googlegroups.com> On Jan 13, 10:22?am, Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > ? ? int a; > ? ? int b; > ? ? char *c; > > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > ? ? _fields_ = [("a" ? ? ? ? c_int), > ? ? ? ? ? ? ? ? ? ? ? ("b", ? ? ? ?c_int), > ? ? ? ? ? ? ? ? ? ? ? ("c", ? ? ? ? c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? > > Thank you.. > > sincerely chris Did you remember to define myclib.myfunction.argtypes= [ INTERFACE ] ? From http Tue Jan 13 17:03:07 2009 From: http (Paul Rubin) Date: 13 Jan 2009 14:03:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: <7xk58yn9t0.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > And that's the problem : what Paul suggests are not "improvements" but > radical design changes. Eh? I think of them as moderate and incremental improvements, in a direction that Python is already moving in. Radical would be something like a full-scale static type system. > I really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of > course they are free to choose another language). I certainly don't think dynamism is central to Python. In what I see as well-developed Python programming style, it's something that is only rarely used in any important way. I'd spend much less time debugging if I got compiler warnings whenever I used dynamism without a suitable annotation. The 1% of the time where I really want to use dynamism I don't see any problem with putting in an appropriate decorator, superclass, or whatever. From philip at semanchuk.com Tue Jan 13 17:05:21 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 17:05:21 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CF3B4.4040709@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <496CF3B4.4040709@shopzeus.com> Message-ID: <8383FE60-36B4-4810-BCB8-61A1FED3C85C@semanchuk.com> On Jan 13, 2009, at 3:04 PM, Laszlo Nagy wrote: > >> >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like >> you're proposing something totally different, no? > OK I see. But probably I do not want to use Cygwin because that > would create another dependency. I understand that posix_ipc/sysv is > not natively supported under windows. What about this: > > - create a wrapper, using ctypes, /windll / cdll/ to access API > functions > - use CreateFileMapping on the page file to create shared memory (a > la windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx > ) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. Python has the mmap module which might work a lot like shared memory. I'm not clear on the differences, honestly. Named pipes might be a cleaner way to implement message queues: http://msdn.microsoft.com/en-us/library/aa365590(VS.85).aspx > - it might also be used to emulate the same posix_ipc interface, > without any external dependency added (cygwin). It'd be nice to have message queues/named pipes working under Windows. If I were you, I'd steer clear of calling them something specific like "SysV" or "POSIX" messages queues. That will create an expectation of certain semantics, and you might find it difficult to fulfill that promise in certain cases (e.g. implementing the POSIX function mq_notify() ). If you call them Nagy message queues then no one will be disappointed or surprised as long as your code implements FIFO IPC. Bye Philip From philip at semanchuk.com Tue Jan 13 17:08:02 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 17:08:02 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> On Jan 13, 2009, at 4:31 PM, drobinow at gmail.com wrote: > On Jan 13, 2:37 pm, Philip Semanchuk wrote: >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like you're >> proposing something totally different, no? > > It's not really correct to call Cygwin a compatibility library. It's > more of a separate system. Thanks for the education; I'm obviously not very familiar with it. > In any case, the current version (1.5.25) does not support sem_unlink > or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under > test, will support these. I haven't tried it yet. I expect it will > work OOTB. Thanks for the report. Strange that it supports the functions to open but not close semaphores. IN any case, I'd be very happy if posix_ipc or sysv_ipc would work with few or no modifications under Cygwin. Cheers Philip From sjmachin at lexicon.net Tue Jan 13 17:08:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 14:08:36 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: On Jan 14, 6:54?am, ag73 wrote: > Hi, > > I am trying to parse data posted to a Python class that extends > http.server.BaseHTTPRequestHandler. Here is the code I am using: > > ? ? ? ? def do_POST(self): > ? ? ? ? ? ? ? ? ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > ? ? ? ? ? ? ? ? length = int(self.headers['Content-Length']) > ? ? ? ? ? ? ? ? if ctype == 'application/x-www-form-urlencoded': > ? ? ? ? ? ? ? ? ? ? ? ? qs = self.rfile.read(length) > ? ? ? ? ? ? ? ? ? ? ? ? print("qs="+str(qs)) > ? ? ? ? ? ? ? ? ? ? ? ? form = urllib.parse.parse_qs(qs, keep_blank_values=1) > > The print statement shows the following output, so it looks like the > data is being posted correctly: > > qs=b'file_data=b > %27IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCiMgZW5jb2Rpbmc6IHV0Zi04CiIiIgp1bnRpdGxlZC5w?eQoK > %5CnQ3JlYXRlZCBieSBBbmR5IEdyb3ZlIG9uIDIwMDgtMTItMDIuCkNvcHlyaWdodCAoYykgMjA?wOCBf > %5CnX015Q29tcGFueU5hbWVfXy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4KIiIiCgppbXBvcnQgc3l?zCmlt > %5CncG9ydCBvcwoKCmRlZiBtYWluKCk6CglwcmludCAibmFtZTE9dmFsdWUxIgoJcHJpbnQgIm5?hbWUy > %5CnPXZhbHVlMiIKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgoJbWFpbigpCgo%3D > %5Cn%27&filename=test.py' > > However, the last line of code that calls parse_qs causes the > following exception to be thrown: > > > Type str doesn't support the buffer API Please show the full traceback. From fabiofz at gmail.com Tue Jan 13 17:12:29 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 13 Jan 2009 20:12:29 -0200 Subject: Pydev 1.4.2 Released Message-ID: Hi All, Pydev and Pydev Extensions 1.4.2 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: ----------------------------------------------------------------- * Context insensitive code-completion working with multiple interpreters * Fixed code analysis problem on staticmethod * Giving proper warning on version mismatch * Remote debugger fix Release Highlights in Pydev: ---------------------------------------------- * Interpreter can be configured on a per-project basis * Jython 2.5b0 properly supported * Find definition working for Jython builtins * Run: can be python/jython even if it doesn't match the interpreter configured for the project * Fixed problem on find definition if one of the interpreters was not configured * Fixed halting condition that could occur on code-completion * __file__ available in code-completion * Reorganized preferences (removed editor preferences from the root) * Preferences for showing hover info * Fixed problem when formatting binary operator that was in a new line * When converting spaces to tabs (and vice-versa), the number of spaces for each tab is asked * Debugger o When finishing the user code debugging, it doesn't step into the debugger code anymore o Fixes for working with Jython o Fix for Python 3.0 integration (could not resolve variables) What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com From rupole at hotmail.com Tue Jan 13 17:22:10 2009 From: rupole at hotmail.com (Roger Upole) Date: Tue, 13 Jan 2009 17:22:10 -0500 Subject: Scheduled Tasks - SetFlags References: <88f5dbd9-ffa8-4498-9635-bfba8bdd1193@i18g2000prf.googlegroups.com> Message-ID: kj7ny wrote: > How do I enable/disable a scheduled task using Python? > > I can get to a task: > > self.ts=pythoncom.CoCreateInstance > (taskscheduler.CLSID_CTaskScheduler,None,pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler) > self.ts.SetTargetComputer(u'\\\\SomeServer') > self.tasks=self.ts.Enum() > for task in self.tasks: > self.t=self.ts.Activate(task) > if self.t.GetAccountInformation().lower().find('SomeUser') >>=0: > print self.t.GetFlags() > > I can find if a task is enabled or not and toggle it: > > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Originally Disabled: %s'%(disabled,) > if disabled: > self.t.SetFlags(self.t.GetFlags() & > ~taskscheduler.TASK_FLAG_DISABLED) > else: > self.t.SetFlags(self.t.GetFlags() | > taskscheduler.TASK_FLAG_DISABLED) > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Recheck Disabled: %s'%(disabled,) > > ... "Recheck Disabled" shows that the value "says" it has been > disabled. > > The problem is that if I run it again and again, "Originally Disabled" > is always the same. In other words, "Recheck Disabled" does NOT > stick. It's like I'm missing a .commit() > Your missing commit is spelled pf=t.QueryInterface(pythoncom.IID_IPersistFile) pf.Save(None,1) Roger From kevin.jingqiu at caseware.com Tue Jan 13 17:29:58 2009 From: kevin.jingqiu at caseware.com (Kevin Jing Qiu) Date: Tue, 13 Jan 2009 17:29:58 -0500 Subject: Weird behaviour re: Python on Windows In-Reply-To: <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> References: <496CC069.80909@shopzeus.com><1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com><496CD1F6.3080604@shopzeus.com><4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com><496CDBF8.5020402@shopzeus.com><1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com><496CE50C.6000308@shopzeus.com> <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> Message-ID: I've been experiencing weird behavior of Python's os module on Windows: Here's the environment: Box1: Running Windows 2003 Server with Apache+mod_python Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ on Box1 It appears any os calls that deals with file/dir on the mapped drive is problematic. More specifically, os.stat(path), os.path.exists(path) gives 'File not found' when path is on the mapped drive. Wait, this gets better: when I'm in the debug mode (or Python interactive shell), everything works fine! Os.stat, os.path.exists, os.fstat, etc, worked as expected. I tried PyWin32 extension's GetFileSize() method and the same thing happens: debug or interactive mode works fine, but when Plone is run in non-debug mode, the problems begin. I swear this isn't a Plone problem either. I switched the configuration. Now Box1 has a network drive mapped to Box2's D:\. The custom Apache filter we have (which is written in python executed by mod_python) complains that it can't find the file which is on the mapped drive. So there you go. I'm wondering if anyone else experienced such problem. Any suggestions or input is appreciated! Thanks, Kevin From andygrove73 at gmail.com Tue Jan 13 17:56:35 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 14:56:35 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> On Jan 13, 3:08?pm, John Machin wrote: > Please show the full traceback. John, Thanks. Here it is: File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 307, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/socketserver.py", line 614, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/http/server.py", line 363, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/http/server.py", line 357, in handle_one_request method() File "/Users/andy/Development/EclipseWorkspace/dbsManage/kernel.py", line 178, in do_POST form = urllib.parse.parse_qs(qs, keep_blank_values=1) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/urllib/parse.py", line 351, in parse_qs ---------------------------------------- for name, value in parse_qsl(qs, keep_blank_values, strict_parsing): File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ python3.0/urllib/parse.py", line 377, in parse_qsl pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] TypeError: Type str doesn't support the buffer API From martin at v.loewis.de Tue Jan 13 17:58:00 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 13 Jan 2009 23:58:00 +0100 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> Message-ID: <496D1C78.3060307@v.loewis.de> Steve Holden wrote: > Daniel Fetchinson wrote: >>> I need something to connect to a database, preferably mysql, that >>> works in python3.0 please. >> And your question is? >> >> > Surely it's fairly obvious that the question is "does such a thing > exist, and if so where can I find it?". Interestingly enough, the question was slightly (but importantly) different, though: the question really was "Does anybody has a patch for MySQLdb?"; as my reference to the existing interface to PostgreSQL was not sufficient for the OP. Regards, Martin From kylotan at gmail.com Tue Jan 13 18:06:19 2009 From: kylotan at gmail.com (Ben Sizer) Date: Tue, 13 Jan 2009 15:06:19 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible Message-ID: I have the following C++ code and am attempting to embed Python 2.5, but although the "import sys" statement works, attempting to reference "sys.path" from inside a function after that point fails. It's as if it's not treating it as a normal module but as any other global variable which I'd have to explicitly qualify. Py_InitializeEx(0); // the zero skips registration of signal handlers. PyObject* ourNamespace_ = PyDict_New(); PyDict_SetItemString(ourNamespace_, "__builtins__", PyEval_GetBuiltins()); PyObject* locals = PyDict_New(); const char* scriptStr = "print '1'\n" "import sys\n" "print sys.path\n" "def debug_path_info():\n" " print 'These are the directories Python looks into for modules and source files:'\n" " print '2'\n" " for folder in sys.path:\n" " print folder\n" " print '--------------'\n" " print 'This would be your present working folder/ directory:'\n" " print '3'\n" " print sys.path[0]\n" "debug_path_info()\n"; PyObject* scriptResult = PyRun_String( scriptStr, // Python code to execute Py_file_input, ourNamespace_, // globals dictionary locals); // locals dictionary if (!scriptResult) { std::cerr << "Python error: " << "Unhandled Python exception from script." << std::endl; PyErr_Print(); } else { Py_DECREF(scriptResult); // don't need result any more } Py_DECREF(locals); Py_DECREF(ourNamespace_); Py_Finalize(); And the output is like this: 1 ['E:\\code\\Python25\\lib\\site-packages\\turbokid-1.0.4-py2.5.egg', 'E:\\code\\ Python25\\lib\\site-packages\\turbocheetah-1.0-py2.5.egg', 'E:\\code\ \Python25\\ lib\\site-packages\\simplejson-1.8.1-py2.5-win32.egg', 'E:\\code\ \Python25\\lib\ \site-packages\\ruledispatch-0.5a0.dev_r2306-py2.5-win32.egg', 'E:\ \code\\Python 25\\lib\\site-packages\\pastescript-1.6.2-py2.5.egg', 'E:\\code\ \Python25\\lib\\ site-packages\\formencode-1.0.1-py2.5.egg', 'E:\\code\\Python25\\lib\ \site-packa ges\\decoratortools-1.7-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\\con figobj-4.5.2-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \cherrypy-2.3.0 -py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\\kid-0.9.6- py2.5.egg', 'E:\ \code\\Python25\\lib\\site-packages\\cheetah-2.0.1-py2.5-win32.egg', 'E:\\code\\ Python25\\lib\\site-packages\\pyprotocols-1.0a0-py2.5-win32.egg', 'E:\ \code\\Pyt hon25\\lib\\site-packages\\pastedeploy-1.3.1-py2.5.egg', 'E:\\code\ \Python25\\li b\\site-packages\\paste-1.6-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\ \sqlobject-0.10.0-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \tgfastdat a-0.9a7-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \webhelpers-0.6-py2. 5.egg', 'E:\\code\\Python25\\lib\\site-packages\\shove-0.1.3- py2.5.egg', 'E:\\co de\\Python25\\lib\\site-packages\\boto-1.3a-py2.5.egg', 'E:\\code\ \Python25\\lib \\site-packages\\sqlalchemy-0.5.0beta3-py2.5.egg', 'E:\\code\\Python25\ \lib\\sit e-packages\\turbojson-1.1.4-py2.5.egg', 'E:\\code\\Python25\\lib\\site- packages\ \setuptools-0.6c9-py2.5.egg', 'E:\\code\\Python25\\lib\\site-packages\ \turbogear s-1.0.8-py2.5.egg', 'C:\\WINDOWS\\system32\\python25_d.zip', 'E:\\code\ \Python25 \\Lib', 'E:\\code\\Python25\\DLLs', 'E:\\code\\Python25\\Lib\\lib-tk', 'e:\\Visu al Studio 2008\\Projects\\StacklessEmbed\\StacklessEmbed', 'e:\\Visual Studio 20 08\\Projects\\StacklessEmbed\\Debug', 'E:\\code\\Python25', 'E:\\code\ \Python25\ \lib\\site-packages', 'E:\\code\\Python25\\lib\\site-packages\\PIL', 'E:\\code\\ Python25\\lib\\site-packages\\wx-2.8-msw-unicode'] These are the directories Python looks into for modules and source files: 2 Python error: Unhandled Python exception from script. Traceback (most recent call last): File "", line 13, in File "", line 7, in debug_path_info NameError: global name 'sys' is not defined [12532 refs] (Incidentally, the Stackless references are because I was originally trying to embed Stackless, but I reverted to vanilla 2.5 to see if it was a Stackless specific issue, which it appears not.) Another interesting thing is that sys.path[0] doesn't appear to be the current working directory, despite several sources online suggesting it should be. What am I doing wrong? -- Ben Sizer From mdw at distorted.org.uk Tue Jan 13 18:06:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 13 Jan 2009 23:06:58 +0000 (UTC) Subject: why cannot assign to function call References: <20090105050927.GS28417@dragontoe.org> <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I found it interesting. Well, that's something, at any rate. > I think this conversation is reaching it's natural end. Frustration > levels are rising. I think you may be right. That said... > So I'm going to take a different tack in an attempt to reduce > frustration levels: if I can't convince the other side they're wrong, > can I at least get them to understand where I'm coming from a little > better? Maybe... > As I see it, this conversation is floundering on two radically different > ideas about what it means to say a language uses pass-by-foo. You might be right, but I'm unconvinced. > On the one hand, some people (me and possibly rurpy) consider "this is > pass-by-foo" to be a statement about behaviour directly visible to the > programmer. We have a set of behavioral traits in mind, and if a language > exhibits those behaviours, then it is clearly and obviously pass-by-foo > no matter how that behaviour is implemented. I'll call these the > behaviorists. Here's the problem. I think I'm in that camp too! I'm going to move away from the formal semantics stuff and try a different tack. Here's what I think is the defining property of pass-by-value (distilled from the formal approach I described earlier, but shorn of the symbolism): The callee's parameters are /new variables/, initialized /as if by assignment/ from the values of caller's argument expressions. I'd just like to examine that for a bit. Firstly, let's expand it from the soundbite: basically what it says is that you should be able to replace function mumble(a, b, c) { stuff in terms of a, b, and c } ... mumble(1 + 2, xyz, whatever) with ... fresh_a = 1 + 2 fresh_b = xyz fresh_c = whatever stuff in terms of fresh_a, fresh_b, and fresh_c with no observable difference (here, fresh_a and so on are a variable names not appearing in the rest of the program). So: * It captures C's behaviour (at least if you don't count arrays -- let's not open that one again), and Pascal's normal behaviour. Assigning to the parameters doesn't affect the caller's argument variables because the parameters are fresh variables. * It /doesn't/ capture Fortran's behaviour, or Pascal's `var' parameters, because obviously assignment to parameters in Fortran /can/ affect the caller's argument variables * It also doesn't capture exotic things like Algol's call by name, and lazy evaluation, because there's an evaluation step in there. My soundbite definition for pass-by-reference is this: The callee's parameters are merely /new names/ for the caller's argument variables -- as far as that makes sense. There's a caveat there for argument expressions which don't correspond directly to variables -- and I've glossed over the issue of lvalue expressions which designate locations and all of that. The idea is that you can replace function mumble(a, b) { stuff in terms of a and b } ... mumble(xyz, whatever) by ... stuff in terms of xyz and whatever This does indeed capture Fortran, and Pascal's `var', while excluding C and Pascal non-`var'. Good! So... obviously I'm going to claim that Python is pass-by-value. Why? Because its argument passing works the same way as its assignment. But! (you claim) ... > Python simply can't be pass-by-value, because it doesn't behave like > pass-by-value in other languages (particularly C and Pascal). Ah! (say I) but assignment in C and Pascal looks different from the way it looks in C -- and in exactly the same way that argument passing looks different. And there, I think, I'm going to rest my case. I'm sorry I took so long to distill these thoughts. Thank you for putting up with my theoretical meanderings on the way. -- [mdw] From pavlovevidence at gmail.com Tue Jan 13 18:07:57 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 15:07:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> Message-ID: <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> On Jan 13, 4:03?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > And that's the problem : what Paul suggests are not "improvements" but > > radical design changes. > > Eh? ?I think of them as moderate and incremental improvements, in a > direction that Python is already moving in. I've seen no evidence that any Python project is moving even remotely toward data encapsulation. That would be a drastic change. Even if it were only a minor change in the implementation (and it would not be), it would be a major stroke in the Python community. It would basically cause a wholescale power shift from the user to the implementor. As a user it'd be like the difference between living in a free democracy and a fascist dictatorship. > ?Radical would be > something like a full-scale static type system. > > > I really wonder why peoples that seems to dislike one of the central > > features of Python - it's dynamism - still use it (assuming of > > course they are free to choose another language). > > I certainly don't think dynamism is central to Python.?In what I see > as well-developed Python programming style, it's something that is > only rarely used in any important way. You're in the minority, then. >?I'd spend much less time > debugging if I got compiler warnings whenever I used dynamism without > a suitable annotation. ?The 1% of the time where I really want to use > dynamism I don't see any problem with putting in an appropriate > decorator, superclass, or whatever. Well, I guess you are the sacrifical lamb so that everyone else can take advantage of the dynamicism. Carl Banks From andygrove73 at gmail.com Tue Jan 13 18:10:52 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 15:10:52 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> Message-ID: I don't fully understand this but if I pass in "str(qs)" instead of "qs" then the call works. However, qs is returned from file.read() operation so shouldn't that be a string already? In case it's not already obvious, I am new to Python :-) .. so I'm probably missing something here. From andygrove73 at gmail.com Tue Jan 13 18:24:57 2009 From: andygrove73 at gmail.com (Andy Grove) Date: Tue, 13 Jan 2009 15:24:57 -0800 (PST) Subject: cgi.FieldStorage hanging with Python 3.0 (but works with 2.5.1) Message-ID: I'm trying to get a Python web server running that I can upload files to. I actually have the code running with the version of Python pre- installed on Mac OS X but it doesn't work with ActivePython 3.0 - I have not been able to compile Python from source myself to see if the issue is specific to the ActivePython distribution. Here is the relevant code: class MyHandler(http.server.BaseHTTPRequestHandler): def do_POST(self): try: print( "Calling cgi.FieldStorage()" ) form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content- Type'], }) print( "Calling cgi.FieldStorage()" ) The client is the following HTML form being submitted with Firefox 3.0.5 running on the same machine. The browser also hangs, waiting for a response from the server.
Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009
File:
 
As I said, this all works fine with Python 2.5.1 pre-installed. Any suggestions? Thanks, Andy. From mwilson at the-wire.com Tue Jan 13 18:41:51 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 13 Jan 2009 18:41:51 -0500 Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: Philip Semanchuk wrote: > I'm working on message queue support, but the Sys V IPC API is a > headache and takes longer to code against than the POSIX API. I hadn't found it that bad. I have a C extension I should perhaps clean up and make public. Mel. From tjreedy at udel.edu Tue Jan 13 18:47:35 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 18:47:35 -0500 Subject: Standard IPC for Python? In-Reply-To: <496CF3B4.4040709@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <496CF3B4.4040709@shopzeus.com> Message-ID: Laszlo Nagy wrote: > >> >> I was suggesting getting posix_ipc or sysv_ipc to compile against a >> compatibility library (Cygwin?) under Windows. It sounds like you're >> proposing something totally different, no? > OK I see. But probably I do not want to use Cygwin because that would > create another dependency. I understand that posix_ipc/sysv is not > natively supported under windows. What about this: > A few comments: First, the issue of cross-platform IPC, and its difficulties, has come up occasionally, but most with the knowledge of writing stuff for one system (esp. Windows) tend to stick with that system. > - create a wrapper, using ctypes, /windll / cdll/ to access API functions ctypes was only added in 2.5. It should make some things easier than they would have been before. > - use CreateFileMapping on the page file to create shared memory (a la > windows: http://msdn.microsoft.com/en-us/library/aa366537.aspx) > - use CreateEvent/WaitForSingleObject for signaling > (http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx) > - these should be enough to implement shared memory functions and > message queues under windows, and that might be a quick solution at > least for me. > - it might also be used to emulate the same posix_ipc interface, without > any external dependency added (cygwin). That would be good. > > All I care about is to create a working message queue. But if you think > that this ctypes hack would be useful for other users, then I can try to > implement it. > > I must tell you that I'm not very familiar with C programming (it was a > long time ago...) and I do not own MSVC. Python compiles, I believe, with the free VCExpress. But I would start with ctypes. From tjreedy at udel.edu Tue Jan 13 18:57:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 18:57:22 -0500 Subject: Could you suggest optimisations ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Hi, > > In the attached script, the longest time is spent in the following > functions (verified by psyco log): I cannot help but wonder why and if you really need all the rigamorole with file pointers, offsets, and tells instead of for line in open(...): do your processing. > > def match_generator(self,regex): > """ > Generate the next line of self.input_file that > matches regex. > """ > generator_ = self.line_generator() > while True: > self.file_pointer = self.input_file.tell() > if self.file_pointer != 0: > self.file_pointer -= 1 > if (self.file_pointer + 2) >= self.last_line_offset: > break > line_ = generator_.next() > print "%.2f%% \r" % (((self.last_line_offset - > self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), > if not line_: > break > else: > match_ = regex.match(line_) > groups_ = re.findall(regex,line_) > if match_: > yield line_.strip("\n"), groups_ > > def get_matching_records_by_regex_extremes(self,regex_array): > """ > Function will: > Find the record matching the first item of regex_array. > Will save all records until the last item of regex_array. > Will save the last line. > Will remember the position of the beginning of the next line in > self.input_file. > """ > start_regex = regex_array[0] > end_regex = regex_array[len(regex_array) - 1] > > all_recs = [] > generator_ = self.match_generator > > try: > match_start,groups_ = generator_(start_regex).next() > except StopIteration: > return(None) > > if match_start != None: > all_recs.append([match_start,groups_]) > > line_ = self.line_generator().next() > while line_: > match_ = end_regex.match(line_) > groups_ = re.findall(end_regex,line_) > if match_ != None: > all_recs.append([line_,groups_]) > return(all_recs) > else: > all_recs.append([line_,[]]) > line_ = self.line_generator().next() > > def line_generator(self): > """ > Generate the next line of self.input_file, and update > self.file_pointer to the beginning of that line. > """ > while self.input_file.tell() <= self.last_line_offset: > self.file_pointer = self.input_file.tell() > line_ = self.input_file.readline() > if not line_: > break > yield line_.strip("\n") > > I was trying to think of optimisations, so I could cut down on > processing time, but got no inspiration. > (I need the "print "%.2f%% \r" ..." line for user's feedback). > > Could you suggest any optimisations ? > Thanks, > Ron. > > > P.S.: Examples of processing times are: > > * 2m42.782s on two files with combined size of 792544 bytes > (no matches found). > * 28m39.497s on two files with combined size of 4139320 bytes > (783 matches found). > > These times are quite unacceptable, as a normal input to the program > would be ten files with combined size of ~17MB. > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Jan 13 19:04:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 19:04:33 -0500 Subject: [OT] Re: are there some special about '\x1a' symbol In-Reply-To: References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Mon, 12 Jan 2009 12:00:16 -0200, John Machin > escribi?: > >> I didn't think your question was stupid. Stupid was (a) CP/M recording >> file size as number of 128-byte sectors, forcing the use of an in-band >> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >> decades after people stopped writing Ctrl-Z at the end of text files. > > This is called "backwards compatibility" and it's a good thing :) But it does not have to be the default or only behavior to be available. > Consider the Atucha II nuclear plant, started in 1980, based on a design > from 1965, and still unfinished. People require access to the complete > design, plans, specifications, CAD drawings... decades after they were > initially written. > I actually do use (and maintain! -- ugh!) some DOS programs. Some people > would have a hard time if they could not read their old data with new > programs. > Even Python has a "print" statement decades after nobody uses a teletype > terminal anymore... > From sjmachin at lexicon.net Tue Jan 13 19:07:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 13 Jan 2009 16:07:00 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> <167ccc02-2101-4d3a-b3ee-8f9008e2afa8@33g2000yqm.googlegroups.com> Message-ID: On Jan 14, 9:56?am, Andy Grove wrote: > On Jan 13, 3:08?pm, John Machin wrote: > > > Please show the full traceback. > > John, > > Thanks. Here it is: > > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 281, in _handle_request_noblock > ? ? self.process_request(request, client_address) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 307, in process_request > ? ? self.finish_request(request, client_address) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 320, in finish_request > ? ? self.RequestHandlerClass(request, client_address, self) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/socketserver.py", line 614, in __init__ > ? ? self.handle() > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/http/server.py", line 363, in handle > ? ? self.handle_one_request() > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/http/server.py", line 357, in handle_one_request > ? ? method() > ? File "/Users/andy/Development/EclipseWorkspace/dbsManage/kernel.py", > line 178, in do_POST > ? ? form = urllib.parse.parse_qs(qs, keep_blank_values=1) > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/urllib/parse.py", line 351, in parse_qs > ---------------------------------------- > ? ? for name, value in parse_qsl(qs, keep_blank_values, > strict_parsing): > ? File "/Library/Frameworks/Python.framework/Versions/3.0/lib/ > python3.0/urllib/parse.py", line 377, in parse_qsl > ? ? pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] > TypeError: Type str doesn't support the buffer API | Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> qs_bytes = b'a;b&c;d' | >>> qs_str = 'a;b&c;d' | >>> pairs = [s2 for s1 in qs_bytes.split('&') for s2 in s1.split (';')] | Traceback (most recent call last): | File "", line 1, in | TypeError: Type str doesn't support the buffer API | >>> pairs = [s2 for s1 in qs_str.split('&') for s2 in s1.split(';')] | >>> pairs | ['a', 'b', 'c', 'd'] | >>> b'x&y'.split('&') | Traceback (most recent call last): | File "", line 1, in | TypeError: Type str doesn't support the buffer API | >>> b'x&y'.split(b'&') | [b'x', b'y'] | >>> 'x&y'.split('&') | ['x', 'y'] | >>> The immediate cause is that as expected mixing str and bytes raises an exception -- this one however qualifies as "not very informative" and possibly wrong [not having inspected the code for whatever.split() I'm left wondering what is the relevance of the buffer API]. The docs for urllib.parse.parse_qs() and .parse_qsl() are a bit vague: """query string given as a string argument (data of type application/x- www-form-urlencoded)""" ... does "string" mean "str only" or "str or bytes"? Until someone can give an authoritative answer [*], you might like to try decoding your data (presuming you know what it is or how to dig it out like you found the type and length) and feeding the result to the .parse_qs(). [*] I know next to zilch about cgi and urllib -- I'm just trying to give you some clues to see if you can get yourself back on the road. From tjreedy at udel.edu Tue Jan 13 19:11:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 19:11:44 -0500 Subject: Extracting real-domain-name (without sub-domains) from a given URL In-Reply-To: References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: S.Selvam Siva wrote: >> I doubt anyone's created a general ready-made solution for this, you'd >> have to code it yourself. >> To handle the common case, you can cheat and just .split() at the >> periods and then slice and rejoin the list of domain parts, ex: >> '.'.join(domain.split('.')[-2:]) >> >> Cheers, >> Chris > > > Thank you Chris Rebert, > Actually i tried with domain specific logic.Having 200 TLD like > .com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i > will try to find some alternative solution. I make a dict mapping TLDs to number of parts to strip off parts = { 'com':1, 'in':2, 'org':1, 'uk':2, } etc If certain TLDs need a special function, define the function first and map that TLD to the function and then switch on the type of value (int or function) when you look it up. From fetchinson at googlemail.com Tue Jan 13 19:30:52 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 13 Jan 2009 16:30:52 -0800 Subject: python3.0 MySQLdb In-Reply-To: <496D1C78.3060307@v.loewis.de> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> Message-ID: >>>> I need something to connect to a database, preferably mysql, that >>>> works in python3.0 please. >>> And your question is? >>> >>> >> Surely it's fairly obvious that the question is "does such a thing >> exist, and if so where can I find it?". > > Interestingly enough, the question was slightly (but importantly) > different, though: the question really was "Does anybody has a patch for > MySQLdb?"; as my reference to the existing interface to PostgreSQL > was not sufficient for the OP. Exactly. One could think about 3-4 different potentially useful answers to the OP but when one sees 3-4 immediately right after reading the post then probably there are a couple more still after some thinking. So if the OP specifies exactly what he/she wants, he/she will get more signal than noise. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From prologic at shortcircuit.net.au Tue Jan 13 19:33:29 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 10:33:29 +1000 Subject: Standard IPC for Python? In-Reply-To: <496CC069.80909@shopzeus.com> References: <496CC069.80909@shopzeus.com> Message-ID: On Wed, Jan 14, 2009 at 2:25 AM, Laszlo Nagy wrote: > The question is: what is the standard way to implement fast and portable IPC > with Python? Are there tools in the standard lib that can do this? Certainly not standard by any means, but I use circuits (1). Two or more processes can communicate via Bridge by propagating events. Example: http://trac.softcircuit.com.au/circuits/browser/examples/remotepy.py cheers James 1. http://trac.softcircuit.com.au/circuits/ From prologic at shortcircuit.net.au Tue Jan 13 19:34:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 10:34:37 +1000 Subject: Standard IPC for Python? In-Reply-To: <496CD1F6.3080604@shopzeus.com> References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: On Wed, Jan 14, 2009 at 3:40 AM, Laszlo Nagy wrote: > Can anyone tell me if select.select works under OS X? Yes it does. cheers James From Russ.Paielli at gmail.com Tue Jan 13 19:45:17 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 16:45:17 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 3:07 pm, Carl Banks wrote: > I've seen no evidence that any Python project is moving even remotely > toward data encapsulation. That would be a drastic change. Even if > it were only a minor change in the implementation (and it would not > be), it would be a major stroke in the Python community. It would > basically cause a wholescale power shift from the user to the > implementor. As a user it'd be like the difference between living in > a free democracy and a fascist dictatorship. I just googled "object oriented principles." The first site that came up lists four princicples: - Encapsulation - Abstraction - Inheritance - Polymorphism The Wikipedia entry for "object-oriented programming" also lists encapsulation as a "fundamental concept." The first line on the python.org site says: "Python is a dynamic object-oriented programming language that can be used for many kinds of software development." How can that possibly be true if you see "no evidence that any Python project is moving even remotely toward data encapsulation"? Semantics aside, I fail to understand your hostility toward a fundamental concept of object-oriented programming. The difference between a free democracy and a "fascist dictatorship"? Give me a break! From Catherine.M.Moroney at jpl.nasa.gov Tue Jan 13 20:02:28 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Tue, 13 Jan 2009 17:02:28 -0800 Subject: executing multiple functions in background simultaneously Message-ID: <496D39A4.2030406@jpl.nasa.gov> Hello everybody, I know how to spawn a sub-process and then wait until it completes. I'm wondering if I can do the same thing with a Python function. I would like to spawn off multiple instances of a function and run them simultaneously and then wait until they all complete. Currently I'm doing this by calling them as sub-processes executable from the command-line. Is there a way of accomplishing the same thing without having to make command-line executables of the function call? I'm primarily concerned about code readability and ease of programming. The code would look a lot prettier and be shorter to boot if I could spawn off function calls rather than subprocesses. Thanks for any advice, Catherine From prologic at shortcircuit.net.au Tue Jan 13 20:12:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:12:25 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D39A4.2030406@jpl.nasa.gov> References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney wrote: > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? Try using the python standard threading module. Create multiple instances of Thread with target=your_function Maintain a list of these new Thread instnaces Join (wait) on them. pydoc threading.Thread cheers James From pieterprovoost at gmail.com Tue Jan 13 20:28:53 2009 From: pieterprovoost at gmail.com (pieterprovoost at gmail.com) Date: Tue, 13 Jan 2009 20:28:53 -0500 Subject: problem calling method Message-ID: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> I'm trying to call a method within my wx frame, but that doesn't seem to work. What am I doing wrong? class MyFrame(wx.Frame): def __init__(self, *args, **kwds): self.Bind(wx.EVT_BUTTON, self.test, self.testbutton) ... def sendmail(self): ... def test(self, event): self.sendmail() event.Skip() Clicking the test button returns: Traceback (most recent call last): File "D:\python\bx\bxgui.py", line 120, in test self.sendmail() AttributeError: 'MyFrame' object has no attribute 'sendmail' Thanks! -- This message was sent on behalf of pieterprovoost at gmail.com at openSubscriber.com http://www.opensubscriber.com/messages/python-list at python.org/topic.html From kiliansto at gmail.com Tue Jan 13 20:29:29 2009 From: kiliansto at gmail.com (killsto) Date: Tue, 13 Jan 2009 17:29:29 -0800 (PST) Subject: Programming friction Message-ID: I'm trying to implement a basic user controlled sliding box with pygame. I have everything worked out, except for two things. The acceleration is changed once a second (for meters/second) this leads to very jumpy movement. I need to add a way to check how long it takes the program to loop and multiply the acceleration by that much. (I think) After I move, the box slows down appropriately, but then the speed passes 0 and the box shoots off the other way. The equation (in real life) is mS (Coefficient of static friction)*Normal Force >= friction force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1, the next number will be -1 and I shoot off in the other direction. How do I fix this an still have backwards movement? From wuwei23 at gmail.com Tue Jan 13 20:29:36 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 Jan 2009 17:29:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> On Jan 14, 10:45?am, "Russ P." wrote: > The Wikipedia entry for "object-oriented programming" also lists > encapsulation as a "fundamental concept." The Wikipedia entry for "encapsulation" defines it as "the grouping together of data and functionality". That sounds like Python classes & modules to me. From prologic at shortcircuit.net.au Tue Jan 13 20:34:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:34:07 +1000 Subject: Programming friction In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 11:29 AM, killsto wrote: > I'm trying to implement a basic user controlled sliding box with > pygame. I have everything worked out, except for two things. Try the pygame mailing list :) cheers James From google at mrabarnett.plus.com Tue Jan 13 20:35:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 01:35:01 +0000 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496D4145.4060905@mrabarnett.plus.com> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function and run >> them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables of >> the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces Join (wait) on them. > > pydoc threading.Thread > The disadvantage of threads in Python (CPython, actually) is that there's the GIL (Global Interpreter Lock), so you won't get any speed advantage if the threads are mostly processor-bound. From prologic at shortcircuit.net.au Tue Jan 13 20:40:24 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 11:40:24 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D4145.4060905@mrabarnett.plus.com> References: <496D39A4.2030406@jpl.nasa.gov> <496D4145.4060905@mrabarnett.plus.com> Message-ID: On Wed, Jan 14, 2009 at 11:35 AM, MRAB wrote: > The disadvantage of threads in Python (CPython, actually) is that > there's the GIL (Global Interpreter Lock), so you won't get any speed > advantage if the threads are mostly processor-bound. The OP didn't really say what this function does :) *sigh* @OP: You have (at least in 2.6+) threading and multiprocessing modules at your disposal. --JamesMills From AbelCodeMonk at gmail.com Tue Jan 13 20:44:36 2009 From: AbelCodeMonk at gmail.com (Arlo Belshee) Date: Tue, 13 Jan 2009 17:44:36 -0800 (PST) Subject: New Python 3.0 string formatting - really necessary? References: <3e1973d1-0fbc-4b35-a9c3-d7e4d7910a4f@z6g2000pre.googlegroups.com> <29dddf46-dd5f-4c61-bc9b-d24ce726dcb9@v39g2000pro.googlegroups.com> <494ea6ab$0$7769$426a74cc@news.free.fr> <9c8c524f-6985-4cc8-b19c-666f85c69946@a26g2000prf.googlegroups.com> <01696606$0$6988$c3e8da3@news.astraweb.com> <78bd573f-03b0-4628-909d-3f84f9718e7e@13g2000yql.googlegroups.com> <4f95bf3c-69cb-4b8f-b2c5-cce5f5f38b49@v42g2000yqv.googlegroups.com> Message-ID: For R, and others who haven't read the PEP or worked a lot with the web, here are some really strong advantages of the new string formatting over the old. Note: I'm not saying that you have to use one or the other. I'm just pointing out some of the things that the new format gives us - things which allow the next generation of application simplification (especially web apps). When working on resource-oriented, generalized display applications (eg, most any modern website), you commonly run into the problem of wanting to display a bunch of different things in a bunch of different ways - and on the web, display means "convert to a string for the browser". However, the mapping is not a complete graph. Rather, there are usually some rules. For example: * I want to show the same thing to different people in different ways, depending on permissions. * Sometimes I want to show a thing as a full display, and sometimes as a link to go get more. Usually, the template (context) knows how I want to show something, but the thing knows how to show itself. I can solve this using the new string formatting. In particular, by using the "{0.property}", "{variable[index]}", and similar substitutions (none of which can be done in the old syntax). As a result, I end up with an entire website, of an arbitrary number of pages, being supported with one, 5-line "generate the view" method. There is 0 code per page. Here are some of the simpler examples. First, there might be a link to a user's page: "{0.display_name}" Wait...isn't that the same? Yup. There's the first widget: a link. Any resource that knows its own name and URL (and that's all of them) can be shown as a link. Similar widget extraction hugely reduces the other combinations I have to support - eliminating a lot of redundancy, and many LoC. However, display_name doesn't show up the same for all users. Administrators often get additional data (such as the username), everywhere they see a user's name. Friends of a user see little rollovers that tell them more about that user - such as a photo. Fortunately, I defined my user class like: class User: @property def display_name(self): # viewer-dependent context stuff here. And the new string formatting calls my arbitrary code, without anyone having to think about it. But display_name doesn't need to know how to display a name - it just needs to choose which style to use. I can also extract that out to a template, and then have "{0.first}" for friends and "{0.first} {0.last} ({0.username})" for admins, and so on. My display_name code just needs to choose which representation to use - it doesn't define that format. It just returns one of several opaque string constants / widgets, making refactoring trivial. Similarly, I can use "{resource.full_display_for_viewer}" or "{resource.link_display}" to tell the resource how I want it to display itself. Hm. Doesn't that make widget sets (a la ToscaWidgets / TuboGears) and template languages (such as Cheetah / Kid / Mako) a little obsolete? Well, sorta. After all when displaying my user class, I can do this too: "{self.blog_entries.recent.as_ordered_list.using.link_display}". Is that pathological? Probably (unless you have a functional programming background or like domain-specific languages). Looping is, after all, one of the things a real templating system gives you. However, now you don't need to use it for common (and simple) things. Eventually, you do run into stuff for which you want a full templating language. And I use them. For example, they define the base page layouts. The point, however, is that a lot of the lower-level things can be done without using the templating language. And this reduces the number of Mako templates you have lying around, while still allowing great decomposability. Most of these things could be done by having the object override __format__(self). However, that jams my display code in with the rest of my resource class. This way, I can have templates pull out what they want from my resources. And I can compute the template to use and the resources to use it on independently, then just pass it to my displayer method. These are capabilities that %s has no chance to every approach. The ability to use new-style format strings reducees my LoC by a half-ton, and they make what they leave behind a lot easier to read. Being higher-level constructs, they allow me to eliminate redundancy, and that's the real purpose of a programmer. From invalid at invalid Tue Jan 13 20:44:59 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 13 Jan 2009 19:44:59 -0600 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: On 2009-01-12, John Machin wrote: > I didn't think your question was stupid. Stupid was (a) CP/M recording > file size as number of 128-byte sectors, forcing the use of an in-band > EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF > decades after people stopped writing Ctrl-Z at the end of text files. I believe that "feature" was inherited by CP/M from DEC OSes (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API (including the FCB) was lifted almost directly from DEC's PDP-11 stuff, which probably copied it from PDP-8 stuff. Perhaps in the early 60's somebody at DEC had a reason. The really interesting thing is that we're still suffering because of it 40+ years later. -- Grant Edwards grante Yow! I want to read my new at poem about pork brains and visi.com outer space ... From Russ.Paielli at gmail.com Tue Jan 13 20:50:05 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 17:50:05 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> Message-ID: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> On Jan 13, 5:29 pm, alex23 wrote: > On Jan 14, 10:45 am, "Russ P." wrote: > > > The Wikipedia entry for "object-oriented programming" also lists > > encapsulation as a "fundamental concept." > > The Wikipedia entry for "encapsulation" defines it as "the grouping > together of data and functionality". > > That sounds like Python classes & modules to me. Here's the definition on the Wikipedia page for object oriented programming (and it does *not* sound like Python classes): Encapsulation conceals the functional details of a class from objects that send messages to it. ... Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface ? those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member. From ivan.illarionov at gmail.com Tue Jan 13 20:55:11 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Tue, 13 Jan 2009 17:55:11 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: Ben Sizer wrote: > What am I doing wrong? What are you trying to achieve? If you want to modify sys.path I suggest using Python/C API directly: (boilerplate removed) PyImport_ImportModule("sys") PyObject_GetAttrString(sysmod_pointer, "path") PyList_Insert(pathobj_pointer, 0, path_python_str) -- Ivan From prologic at shortcircuit.net.au Tue Jan 13 21:04:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:04:04 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 11:50 AM, Russ P. wrote: > Here's the definition on the Wikipedia page for object oriented > programming (and it does *not* sound like Python classes): > > Encapsulation conceals the functional details of a class from objects > that send messages to it. ... Encapsulation is achieved by specifying > which classes may use the members of an object. The result is that > each object exposes to any class a certain interface ? those members > accessible to that class. The reason for encapsulation is to prevent > clients of an interface from depending on those parts of the > implementation that are likely to change in future, thereby allowing > those changes to be made more easily, that is, without changes to > clients. For example, an interface can ensure that puppies can only be > added to an object of the class Dog by code in that class. Members are > often specified as public, protected or private, determining whether > they are available to all classes, sub-classes or only the defining > class. Some languages go further: Java uses the default access > modifier to restrict access also to classes in the same package, C# > and VB.NET reserve some members to classes in the same assembly using > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > one to specify which classes may access any member. You do realize this is a model and not strictly a requirement. Quite a few things in Python are done merely by convention. Don't get caught up. --JamesMills From castironpi at gmail.com Tue Jan 13 21:15:09 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 13 Jan 2009 18:15:09 -0800 (PST) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 13, 5:06?pm, Mark Wooding wrote: snip > I'm going to move away from the formal semantics stuff and try a > different tack. ?Here's what I think is the defining property of > pass-by-value (distilled from the formal approach I described earlier, > but shorn of the symbolism): > > ? The callee's parameters are /new variables/, initialized /as if by > ? assignment/ from the values of caller's argument expressions. In other words, the same as assignment in that language. snip > Because its argument passing works the same way as its assignment. That would be called pass-by-assignment. But you've just postponed explaining yourself. Stop delegating and work. From metolone+gmane at gmail.com Tue Jan 13 21:17:39 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 13 Jan 2009 18:17:39 -0800 Subject: ctype problem References: <6197f37d-0ea0-4430-a466-2f36b2011ea8@v42g2000yqj.googlegroups.com> Message-ID: "Aaron Brady" wrote in message news:6197f37d-0ea0-4430-a466-2f36b2011ea8 at v42g2000yqj.googlegroups.com... On Jan 13, 10:22 am, Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > int a; > int b; > char *c; > > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > _fields_ = [("a" c_int), > ("b", c_int), > ("c", c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? I believe you want ("c",c_char_p), although I don't get the same error as you describe when I use c_char. Below is my working code (Python 2.6.1 and Visual Studio 2008): ---- x.py ---- from ctypes import * class INTERFACE(Structure): _fields_ = [ ('a',c_int), ('b',c_int), ('c',c_char) ] x = CDLL('x.dll') i = INTERFACE() i.a = 1 i.b = 2 i.c = 'hello' x.myfunction(byref(i)) ---- cl /LD /W4 x.c -> x.dll ---- #include struct interface { int a; int b; char* c; }; __declspec(dllexport) void myfunction(struct interface* iface) { printf("%d %d %s\n",iface->a,iface->b,iface->c); } -Mark From lists at cheimes.de Tue Jan 13 21:18:37 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jan 2009 03:18:37 +0100 Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible In-Reply-To: References: Message-ID: Ivan Illarionov schrieb: > Ben Sizer wrote: >> What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: > (boilerplate removed) > PyImport_ImportModule("sys") > PyObject_GetAttrString(sysmod_pointer, "path") > PyList_Insert(pathobj_pointer, 0, path_python_str) The sys module has its own set of special functions like PySys_GetObject. The following (untested) code should take care of error checking and ref counting. #include "Python.h" PyObject* addtosyspath(const char* addpath) { PyObject *syspath=NULL, *path=NULL; int result; if ((syspath = PySys_GetObject("path")) == NULL) return NULL; if ((path = PyString_FromString(addpath) == NULL) { Py_DECREF(syspath); return NULL; } result = PyList_Insert(syspath, 0, path); Py_DECREF(syspath); Py_DECREF(path); if (result != 0) return NULL; Py_RETURN_NONE; } Christian From jervisau at gmail.com Tue Jan 13 21:22:40 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 14 Jan 2009 13:22:40 +1100 Subject: Programming friction In-Reply-To: References: Message-ID: <8e63a5ce0901131822l458a3026of0ee08e53b8d4c93@mail.gmail.com> On Wed, Jan 14, 2009 at 12:29 PM, killsto wrote: > > force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1, > the next number will be -1 and I shoot off in the other direction. How > do I fix this an still have backwards movement? > -- > http://mail.python.org/mailman/listinfo/python-list > try something like: force = max(force, 0) where force is the force applied to the object that you have calculated. this should ensure that the force is bounded to 0 in the negative direction. I believe that in pygame you can use the clock module to help you with your timing issues (see the docs), and perhaps attempt to keep a regular frame rate. Cheers, Jervis -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Tue Jan 13 21:27:09 2009 From: http (Paul Rubin) Date: 13 Jan 2009 18:27:09 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <7xpriqmxky.fsf@ruckus.brouhaha.com> "James Mills" writes: > You do realize this is a model and not strictly a requirement. Quite > a few things in Python are done merely by convention. > Don't get caught up. But, if something is done by convention, then departing from the convention is by definition unconventional. If you do something unconventional in a program, it could be on purpose for a reason, or it could be by accident indicating a bug. I don't understand why some folks spew such violent rhetoric against the idea of augmenting Python with features to alert you automatically when you depart from the convention, so that you can check that the departure is actually what you wanted. A lot of the time, I find, the departures are accidental and automated checks would save me considerable debugging. From prologic at shortcircuit.net.au Tue Jan 13 21:33:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:33:07 +1000 Subject: problem calling method In-Reply-To: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> References: <12329707.01231896533913.JavaMail.root@wombat.diezmil.com> Message-ID: On Wed, Jan 14, 2009 at 11:28 AM, wrote: > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): It might be helpful here if you called the parent __init__. Like so: class MyFrame(wx.Frame): def __init__(self, *args, **kwds): super(MyFrame, self).__init__(*args, **kwargs) ... cheers James From prologic at shortcircuit.net.au Tue Jan 13 21:36:11 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 12:36:11 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 12:27 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. Amen to that! Finally someone with some sense and his/her head screwed on properly! :) Kudos to your thoughtful post :) cheers James From ajaksu at gmail.com Tue Jan 13 21:42:47 2009 From: ajaksu at gmail.com (ajaksu) Date: Tue, 13 Jan 2009 18:42:47 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 13, 1:33?am, Philip Semanchuk wrote: > I don't think I understand you clearly. Whether or not Google et al ? > whitelist the Python UA isn't a Python issue, is it? Hi, sorry for taking so long to reply :) I imagine it's something akin to Firefox's 'Report broken website': evangelism. IMHO, if the PSF *cough* Steve *cough* or individual Python hackers can contact key sites (as Wikipedia, groups.google, etc.) the issue can be solved sooner. Instead of waiting for each whitelist maintainer's to find out we have a new UA, go out and tell them. A template for such requests could help those inside e.g. Google to bring the issue to the attention of the whitelist admins. The community has lots of connections that could be useful to pass the message along, if only 'led by the nose' to achieve that :) Hence, the suggestion to raise a bug. Regards, Daniel From bedouglas at earthlink.net Tue Jan 13 21:53:38 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 13 Jan 2009 18:53:38 -0800 Subject: List/Set/Dict.. Message-ID: <11de01c975f3$4f22e740$0301a8c0@tmesa.com> Hi... i have the test dict/list a= {"a": 'a1',"b" : "b1"} b= [{"a": 'a1',"b" : "b1"}] i'm trying to figure out how to programtically tell them apart... ie, which is a dict, and which is a list... is there a way to accomplish this.. thanks From philip at semanchuk.com Tue Jan 13 21:53:57 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 21:53:57 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: On Jan 13, 2009, at 6:41 PM, Mel wrote: > Philip Semanchuk wrote: > >> I'm working on message queue support, but the Sys V IPC API is a >> headache and takes longer to code against than the POSIX API. > > I hadn't found it that bad. I have a C extension I should perhaps > clean up > and make public. Have you compared the SysV objects to the POSIX objects? I'll give you two examples of how SysV is more trouble with which to work. Example 1 --- The SysV objects expose a ton of information that show up as Python attributes. For instance, a sysv_ipc.Semaphore object has 16 attributes: key, id, value, undo, block, mode, uid, gid, cuid, cgid, last_pid, waiting_for_nonzero, waiting_for_zero and o_time. The first two and last eight are read-only, the middle six are read-write. Contrast this to a posix_ipc.Semaphore object which has two read-only attributes: name and value. All of those attributes on the SysV object add up to a lot of code. Furthermore, the SysV attributes have types of key_t, mode_t, uid_t, gid_t, pid_t, time_t, etc. I've spent the past few days researching these types and trying to find out whether they're signed or unsigned, guaranteed to fit in a long, etc. I also need to know what Python types are appropriate for representing these. For instance, anything that can exceed a C long can also exceed a Python int, and so I need to return a Python long object if the C value exceeds LONG_MAX. When I returned to the sysv_ipc code a few days ago, my intention was to add message queue support to it, but instead I've gotten distracted chasing type-related bugs that won't show up until e.g. someone compiles the module on a 64-bit platform and tries to use a key that exceeds 0xFFFFFFFF, or compiles it on some weird 16-bit embedded processor that exposes another of my flawed type assumptions. The POSIX API is so much simpler that I spend much less time working on type-related drudgery. Example 2 --- SysV shared memory has to be attached and detached and accessed with the un-Pythonic read & write methods. I'd like to support buffer-type access (like slicing), but that's more code to be written. And there's another 16 attributes to expose. POSIX shared memory OTOH is mmapped, and there's already a Python library for that. For posix_ipc.SharedMemory objects I had to write a constructor, an unlink() method, and code for three read-only attributes and I was done. Nice. I invite you to look at my extension and compare: http://semanchuk.com/philip/sysv_ipc/ Maybe your code can benefit from what I've done, or vice versa. Good luck Philip From tjreedy at udel.edu Tue Jan 13 21:57:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Jan 2009 21:57:04 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 13, 5:29 pm, alex23 wrote: >> On Jan 14, 10:45 am, "Russ P." wrote: >> >>> The Wikipedia entry for "object-oriented programming" also lists >>> encapsulation as a "fundamental concept." >> The Wikipedia entry for "encapsulation" defines it as "the grouping >> together of data and functionality". >> >> That sounds like Python classes & modules to me. > > Here's the definition on the Wikipedia page for object oriented > programming (and it does *not* sound like Python classes): > > Encapsulation conceals the functional details of a class from objects > that send messages to it. ... Encapsulation is achieved by specifying > which classes may use the members of an object. The result is that > each object exposes to any class a certain interface ? those members > accessible to that class. The reason for encapsulation is to prevent > clients of an interface from depending on those parts of the > implementation that are likely to change in future, thereby allowing > those changes to be made more easily, that is, without changes to > clients. For example, an interface can ensure that puppies can only be > added to an object of the class Dog by code in that class. Members are > often specified as public, protected or private, determining whether public = no leading underscore private = one leading underscore protected = two leading underscores Python uses encapsulation by convention rather than by enforcement. > they are available to all classes, sub-classes or only the defining > class. Some languages go further: Java uses the default access > modifier to restrict access also to classes in the same package, C# > and VB.NET reserve some members to classes in the same assembly using > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > one to specify which classes may access any member. > -- > http://mail.python.org/mailman/listinfo/python-list > From prologic at shortcircuit.net.au Tue Jan 13 22:14:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:14:46 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 12:57 PM, Terry Reedy wrote: > public = no leading underscore > private = one leading underscore > protected = two leading underscores > > Python uses encapsulation by convention rather than by enforcement. As mentioned previously this is not encapsulation, but access control. But yes correct, this is how we conventionally define access control over members of an object. It's up to the programmer correctly adhere to the interface(s). --JamesMills From Russ.Paielli at gmail.com Tue Jan 13 22:18:24 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 19:18:24 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Jan 13, 6:04 pm, "James Mills" wrote: > On Wed, Jan 14, 2009 at 11:50 AM, Russ P. wrote: > > Here's the definition on the Wikipedia page for object oriented > > programming (and it does *not* sound like Python classes): > > > Encapsulation conceals the functional details of a class from objects > > that send messages to it. ... Encapsulation is achieved by specifying > > which classes may use the members of an object. The result is that > > each object exposes to any class a certain interface ? those members > > accessible to that class. The reason for encapsulation is to prevent > > clients of an interface from depending on those parts of the > > implementation that are likely to change in future, thereby allowing > > those changes to be made more easily, that is, without changes to > > clients. For example, an interface can ensure that puppies can only be > > added to an object of the class Dog by code in that class. Members are > > often specified as public, protected or private, determining whether > > they are available to all classes, sub-classes or only the defining > > class. Some languages go further: Java uses the default access > > modifier to restrict access also to classes in the same package, C# > > and VB.NET reserve some members to classes in the same assembly using > > keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow > > one to specify which classes may access any member. > > You do realize this is a model and not > strictly a requirement. Quite a few things > in Python are done merely by convention. > > Don't get caught up. > > --JamesMills Yes, but the fact that you can approximate OO programming in a particular language does not make that language object oriented. You can approximate OO programming in C, but that does not mean that C is an OO language. So I can claim that Python is not strictly object oriented until it gets encapsulation (in the sense of data hiding). That is simply a fact, and no amount of pleading or obfuscation will change it. Should Python get true encapsulation? I don't know. Maybe encapsulation cannot be added without excessive overhead or without compromising other more important aspects and features of the language. But I do know that not having encapsulation is a limitation to the use of Python for good software engineering. I may be in the minority in the Python "community" on this one, but I am apparently in the majority in the OO programming "community." From rhodri at wildebst.demon.co.uk Tue Jan 13 22:25:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 14 Jan 2009 03:25:55 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 14 Jan 2009 02:27:09 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. I wouldn't violently object to having some means of policing class or module privacy, but it does have consequences. When it's a convention, you can break it; when it isn't, you can't, even if you do have good reason. Add that to the obviousness of the "leading underscore => private" convention, and I just don't see a burning need for it, that's all. -- Rhodri James *-* Wildebeeste Herder to the Masses From rt8396 at gmail.com Tue Jan 13 22:31:56 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 19:31:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: > public = no leading underscore > private = one leading underscore > protected = two leading underscores > > Python uses encapsulation by convention rather than by enforcement. Very well said Terry! I like that python does not force me to do "everything" but does force things like parenthesis in a function/method call whether or not an argument is required/expected. This makes for very readable code. Visual parsing a Python file is very easy on the eyes due to this fact -- Thanks Guido! We do not need to add three new keywords when there is an accepted Pythonic way to handle public/private/protected From prologic at shortcircuit.net.au Tue Jan 13 22:32:54 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:32:54 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: > Yes, but the fact that you can approximate OO programming in a > particular language does not make that language object oriented. You > can approximate OO programming in C, but that does not mean that C is > an OO language. Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) (Please stop confusing the two) is not a strict requirements of the OO model. Remember that it is a model and not a strict set of requirements that programming languages must implement. In fact, Python borrows features from the Functional Paradigm. Does this make it a Functional Language ? No. Why ? Because one of the clear requirements of the Functional Paradigm is that functions cannot have side affects. > So I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. In fact this is true, C can be seen as an programming language that has features of the OO model. I think one of the things you guys are missing out here is that there are really only two Paradigms or Machines. Functional and Imperative. And guess what ? As it turns out we can implement functional machines that run on top of imperative ones! > Should Python get true encapsulation? I don't know. Maybe > encapsulation cannot be added without excessive overhead or without > compromising other more important aspects and features of the > language. But I do know that not having encapsulation is a limitation > to the use of Python for good software engineering. I may be in the > minority in the Python "community" on this one, but I am apparently in > the majority in the OO programming "community." Again, stop confusing terminology. Should Python get strict and enforce access control of object members ? No. Why ? I can think of several reasons. Give me one use-case where you strictly require that members of an object be private and their access enforced as such ? cheers James From prologic at shortcircuit.net.au Tue Jan 13 22:35:54 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:35:54 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 1:25 PM, Rhodri James wrote: > I wouldn't violently object to having some means of policing class > or module privacy, but it does have consequences. When it's a > convention, you can break it; when it isn't, you can't, even if > you do have good reason. Add that to the obviousness of the > "leading underscore => private" convention, and I just don't see > a burning need for it, that's all. Bare in mind also, that enfocing access control / policing as you called it has a performance hit as the machine (the Python vm) has to perform checks each time members of an object are accessed. I can think of no reason to want to do this at runtime hwatosever and I've been developing in Python for quite some years now. cheers James From prologic at shortcircuit.net.au Tue Jan 13 22:39:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 13:39:30 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:31 PM, r wrote: >> public = no leading underscore >> private = one leading underscore >> protected = two leading underscores >> >> Python uses encapsulation by convention rather than by enforcement. > > Very well said Terry! > > I like that python does not force me to do "everything" but does force > things like parenthesis in a function/method call whether or not an > argument is required/expected. This makes for very readable code. > Visual parsing a Python file is very easy on the eyes due to this fact > -- Thanks Guido! We do not need to add three new keywords when there > is an accepted Pythonic way to handle public/private/protected Agreed. Furthermore there very few cases where you need to distinguish between whether an object's attribute is public or private or even protected. Consider the following two pieces of code and tell me which is more Pythonic: class A(object): def __init__(self): self.x = None def setX(self, v): self.x = v def getX(self): return self.x ---------------------------------------- class A(object): def __init__(self): self.x = None I'll give you a hint ... It's the simpler one :) cheers James From pavlovevidence at gmail.com Tue Jan 13 22:50:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 19:50:41 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 6:45?pm, "Russ P." wrote: > On Jan 13, 3:07 pm, Carl Banks wrote: > > > I've seen no evidence that any Python project is moving even remotely > > toward data encapsulation. ?That would be a drastic change. ?Even if > > it were only a minor change in the implementation (and it would not > > be), it would be a major stroke in the Python community. ?It would > > basically cause a wholescale power shift from the user to the > > implementor. ?As a user it'd be like the difference between living in > > a free democracy and a fascist dictatorship. > > I just googled "object oriented principles." The first site that came > up lists four princicples: > > - Encapsulation > - Abstraction > - Inheritance > - Polymorphism > > The Wikipedia entry for "object-oriented programming" also lists > encapsulation as a "fundamental concept." > > The first line on the python.org site says: > > "Python is a dynamic object-oriented programming language that can be > used for many kinds of software development." > > How can that possibly be true if you see "no evidence that any Python > project is moving even remotely toward data encapsulation"? Is this seriously your argument? Python must be moving towards data encapsulation because there is a line in Python.org that, if you blindly accept the Wikipedia definition as truth, indirectly implies that it is? Are you *seriously* arguing this? The argument is too ridiculous to deserve a refutation, so I'll just point out two things: 1. Wise people don't believe everything that is written on Wikipedia. 2. The person who wrote that line in Python.org is a wise person. > Semantics aside, I fail to understand your hostility toward a > fundamental concept of object-oriented programming. The difference > between a free democracy and a "fascist dictatorship"? Give me a > break! You know what? Computer science buzzwords mean jack squat to me. I don't give a horse's tail whether some people label it a fundamental concept of object-oriented programming or not. I think it's a bad thing. And it's a bad thing for exactly the reason I said: it gives the library implementor the power to dictate to the user how they can and can't use the library. The cultural impact that would have on the community is far worse, IMHO, than any short-sighted benefits like being able to catch an accidental usage of an internal variable. Trust would be replaced by mistrust, and programming in Python would go from a pleasant experience to constant antagonism. No thanks. "Software engineering" be damned. Python is better off the way it is. Carl Banks From pavlovevidence at gmail.com Tue Jan 13 23:17:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 20:17:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 9:50?pm, Carl Banks wrote: > The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. And I'll give you a perfect example: XML-DOM versus ElementTree XML-DOM is the sort of standard that is borne of a culture that values encapsulation, strict type safety, and so on. It's the way it is because designers were allowed to distrust the user, and the culture said that it was good to distrust the user. Consequently, the interface is a pain to use, with all kinds of boilerplate and iterator types and such. ElementTree was borne out of an environment where implementors are forced to trust the user. As a consequence it was free to create an interface that was natural and straightforward and pleasant to use, without having to be guarded. Carl Banks From philip at semanchuk.com Tue Jan 13 23:18:50 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jan 2009 23:18:50 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: <078F3865-79F1-4C48-8170-B4EE777FC8FF@semanchuk.com> On Jan 13, 2009, at 9:42 PM, ajaksu wrote: > On Jan 13, 1:33 am, Philip Semanchuk wrote: >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? > > Hi, sorry for taking so long to reply :) > > I imagine it's something akin to Firefox's 'Report broken website': > evangelism. > > IMHO, if the PSF *cough* Steve *cough* or individual Python hackers > can contact key sites (as Wikipedia, groups.google, etc.) the issue > can be solved sooner. > > Instead of waiting for each whitelist maintainer's to find out we have > a new UA, go out and tell them. A template for such requests could > help those inside e.g. Google to bring the issue to the attention of > the whitelist admins. The community has lots of connections that could > be useful to pass the message along, if only 'led by the nose' to > achieve that :) > > Hence, the suggestion to raise a bug. Gotcha. In this case I think there is no whitelist. I think Google has a default accept policy supplemented with a blacklist rather than a default ban policy mitigated by a whitelist. As evidence I submit the fact that my user agent of "funny fish" was accepted. In other words, Google has taken explicit steps to ban agents sending the default Python UA. Now, if the default UA changed in Python 3.0, maybe the best thing to do is keep quiet and maybe it will fly under the Google radar for a while. =) Cheers Philip From rt8396 at gmail.com Tue Jan 13 23:24:14 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 20:24:14 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <1cbcd14d-ced0-4d0a-a1ae-f017096478b4@a12g2000pro.googlegroups.com> On Jan 13, 9:50?pm, Carl Banks wrote: [snip] it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. [snip] > Carl Banks I agree, the second the Python interpretor say's NO! you cant do that or i will wrap your knuckles! is the day i leave Python forever. I hear C programmers complain all the time about Python saying; "Well, I like in "C" that variable types must be declared because this keeps me from making mistakes later" -- hog wash! Just learn to think in a dynamic way and you will never have any problems. If you need a hand holding language i guess Python is not for you. And don't forget, you can learn a lot from your mistakes. They are so brainwashed by this mumbo-jumbo, i see them do this all the time... int_count = 0 float_cost = 1.25 str_name = "Bob" They can't think in a dynamic way because momma "C" has done it for them for too long. "Eat your Peas and carrots now little C coder" :D From prologic at shortcircuit.net.au Tue Jan 13 23:24:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 14:24:37 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 1:50 PM, Carl Banks wrote: > 1. Wise people don't believe everything that is written on Wikipedia. > 2. The person who wrote that line in Python.org is a wise person. Agreed. > You know what? Computer science buzzwords mean jack squat to me. I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. I think it's a bad > thing. And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. +1 > No thanks. "Software engineering" be damned. Python is better off > the way it is. Python ihmo is one of the best engineered programming languages and platform I have ever had the pleasure of working with and continue to! :) --JamesMills From drobinow at gmail.com Tue Jan 13 23:26:14 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Tue, 13 Jan 2009 20:26:14 -0800 (PST) Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 5:08?pm, Philip Semanchuk wrote: > On Jan 13, 2009, at 4:31 PM, drobi... at gmail.com wrote: > > > On Jan 13, 2:37 pm, Philip Semanchuk wrote: > >> I was suggesting getting posix_ipc or sysv_ipc to compile against a > >> compatibility library (Cygwin?) under Windows. It sounds like you're > >> proposing something totally different, no? > > > It's not really correct to call Cygwin a compatibility library. It's > > more of a separate system. > > Thanks for the education; I'm obviously not very familiar with it. > > > In any case, the current version (1.5.25) does not support sem_unlink > > or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently under > > test, will support these. ?I haven't tried it yet. I expect it will > > work OOTB. > > Thanks for the report. Strange that it supports the functions to open ? > but not close semaphores. IN any case, I'd be very happy if posix_ipc ? > or sysv_ipc would work with few or no modifications under Cygwin. > > Cheers > Philip I just downloaded cygwin 1.7 and posix_ipc builds successfully. The demo appears to work. From malaclypse2 at gmail.com Tue Jan 13 23:42:51 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 13 Jan 2009 23:42:51 -0500 Subject: Weird behaviour re: Python on Windows In-Reply-To: References: <496CC069.80909@shopzeus.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> <550C2237-B017-436F-8E3E-B27991402EAE@semanchuk.com> Message-ID: <16651e80901132042u5862a716g9442ad497d76bb82@mail.gmail.com> On Tue, Jan 13, 2009 at 5:29 PM, Kevin Jing Qiu wrote: > I've been experiencing weird behavior of Python's os module on Windows: > > Here's the environment: > Box1: Running Windows 2003 Server with Apache+mod_python > Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ > on Box1 > > It appears any os calls that deals with file/dir on the mapped drive is > problematic. What user is this running as? By any chance is it running as the Local System user? If so, that user has no network privileges, including to mapped drives. -- Jerry From roy at panix.com Tue Jan 13 23:43:44 2009 From: roy at panix.com (Roy Smith) Date: Tue, 13 Jan 2009 23:43:44 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: In article , "Russ P." wrote: > I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. I have no idea if Python is strictly anything. What I do know is that it's a useful tool. I'll take useful over OOO (Object Oriented Orthodoxy) any day. People get all worked up over OO as if it were some kind of religion. If I want religion, I'll go to shul. What I want from a programming language is a tool that lets me get my work done. If I transgress against some sacred tenet of OO religion, it is, as Rev. Dupas would say, all right. Earlier in this thread, somebody (name elided to avoid me getting pegged for a indulging in a spelling flame): > Bare in mind also, that enfocing access control / policing as you > called it has a performance hit as the machine (the Python vm) > has to perform checks each time members of an object are accessed. All I can say to that is, "He who bares his mind, soon gets to the naked truth". From Russ.Paielli at gmail.com Tue Jan 13 23:54:41 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 20:54:41 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <73d6eefc-44e5-4841-ab9c-6a9746727568@40g2000prx.googlegroups.com> On Jan 13, 7:50?pm, Carl Banks wrote: > On Jan 13, 6:45?pm, "Russ P." wrote: > > > > > On Jan 13, 3:07 pm, Carl Banks wrote: > > > > I've seen no evidence that any Python project is moving even remotely > > > toward data encapsulation. ?That would be a drastic change. ?Even if > > > it were only a minor change in the implementation (and it would not > > > be), it would be a major stroke in the Python community. ?It would > > > basically cause a wholescale power shift from the user to the > > > implementor. ?As a user it'd be like the difference between living in > > > a free democracy and a fascist dictatorship. > > > I just googled "object oriented principles." The first site that came > > up lists four princicples: > > > - Encapsulation > > - Abstraction > > - Inheritance > > - Polymorphism > > > The Wikipedia entry for "object-oriented programming" also lists > > encapsulation as a "fundamental concept." > > > The first line on the python.org site says: > > > "Python is a dynamic object-oriented programming language that can be > > used for many kinds of software development." > > > How can that possibly be true if you see "no evidence that any Python > > project is moving even remotely toward data encapsulation"? > > Is this seriously your argument? ?Python must be moving towards data > encapsulation because there is a line in Python.org that, if you > blindly accept the Wikipedia definition as truth, indirectly implies > that it is? > > Are you *seriously* arguing this? Did you read what I wrote? If so, you apparently didn't understand it. > The argument is too ridiculous to deserve a refutation, so I'll just > point out two things: > > 1. Wise people don't believe everything that is written on Wikipedia. Nice try at diverting attention. The issue is not Wikipedia. As far as I know, the definition of OOP given on Wikipedia is not controversial -- at least not anywhere but here. > 2. The person who wrote that line in Python.org is a wise person. Oh, isn't that wonderful. Wow, I sure wish I was wise like that person! > > Semantics aside, I fail to understand your hostility toward a > > fundamental concept of object-oriented programming. The difference > > between a free democracy and a "fascist dictatorship"? Give me a > > break! > > You know what? ?Computer science buzzwords mean jack squat to me. ?I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. ?I think it's a bad > thing. ?And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. > > No thanks. ?"Software engineering" be damned. ?Python is better off > the way it is. Now that's just classic. "We have Python and we don't need no stinkin' software engineering." Well, you may not need it in your line of work, but I need it in mine. In my line of work, Python is a tool, not a religious faith. From rt8396 at gmail.com Wed Jan 14 00:00:29 2009 From: rt8396 at gmail.com (r) Date: Tue, 13 Jan 2009 21:00:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Here is a piece of C code this same guy showed me saying Pythonic indention would make this hard to read -- Well lets see then! I swear, before god, this is the exact code he showed me. If you don't believe me i will post a link to the thread. // Warning ugly C code ahead! if( is_opt_data() < sizeof( long double ) ) { // test for insufficient data return TRUE; // indicate buffer empty } // end test for insufficient data if( is_circ() ) { // test for circular buffer if( i < o ) { // test for data area divided if( ( l - o ) > sizeof( long double ) ) { // test for data contiguous *t = ( ( long double * ) f )[ o ]; // return data o += sizeof( long double ); // adjust out if( o >= l ) { // test for out wrap around o = 0; // wrap out around limit } // end test for out wrap around } else { // data not contiguous in buffer return load( ( char * ) t, sizeof( long double ) ); // return data } // end test for data contiguous } else { // data are not divided *t = ( ( float * ) f )[ o ]; // return data o += sizeof( long double ); // adjust out if( o >= l ) { // test for out reached limit o = 0; // wrap out around } // end test for out reached limit } // end test for data area divided } else { // block buffer *t = ( ( long double * ) f )[ o ]; // return data o += sizeof( long double ); // adjust data pointer } // end test for circular buffer if i where to write the same code in a 'Python style" it would look like below. And personally i would never use that many comments in my code. I normally in a situation as this one would only comment each major conditional code block, and only if it contains code that is not completely obvious. Commenting is important, but it *can* be over done. #-- Python Style --# if is_opt_data() < sizeof(long double): return TRUE if is_circ(): if i < o: #test for data area divided if (l-o) > sizeof(long double): #test for data contiguous *t = ( ( long double * ) f )[ o ] o += sizeof( long double ) if o >= l: o = 0 else: #data not contiguous in buffer return load((char*) t, sizeof(long double)) else: #data are not divided *t = ((float*) f)[ o ] o += sizeof(long double) if o >= l: #test for out reached limit o = 0 else: #block buffer *t = ((long double*) f)[ o ] o += sizeof(long double) WOW!, without all the braces, and over commenting, i can actually read this code now! Of course it would not run in C or Python but the point here is readability. Python forged the path for all 21st century languages. Get on board, or get on with your self.extinction() -- Your Choice! From Russ.Paielli at gmail.com Wed Jan 14 00:11:44 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 21:11:44 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> On Jan 13, 7:32?pm, "James Mills" wrote: > On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: > > Yes, but the fact that you can approximate OO programming in a > > particular language does not make that language object oriented. You > > can approximate OO programming in C, but that does not mean that C is > > an OO language. > > Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) > (Please stop confusing the two) is not a strict requirements of the OO model. I think you are the one who is confused. Part of the problem here is that the term "encapsulation" has at least two widely used meanings (in the context of programming). In one sense, it just means grouping data and methods together. In another sense, it means restricting the client's access to data or methods. Someone earlier on this thread tried to claim that the first meaning applies to OOP, but Wikipedia (and many other sources) say just the opposite. People here are trying to claim that the leading underscore conventions used with Python are essentially equivalent to encapsulation. That is nonsense, of course. Others are arguing against encapsulation altogether. That is a bit like being against locks or passwords because they create a lot of hassle. Now locks are not needed everywhere, of course, but certainly they have their place. But the point is that if you don't like encapsulation, then by definition you don't like OOP. You may like certain features of OOP, but you don't like it in general. That's about all their is to it. And by the way, please don't bring up the canard that I am some kind of OO zealot. I think OO is overrated, and I don't Java, in part because it forces everything to be OO. The issue here is not my personal opinion of OOP. This issue is one of widely accepted definitions within the OO community. > Remember that it is a model and not a strict set of requirements that > programming > languages must implement. Of course it's not a "requirement that programming languages must implement." It's only a requirement if they want to be OO languages. > In fact, Python borrows features from the Functional Paradigm. Does this > make it a Functional Language ? No. Why ? Because one of the clear > requirements of the Functional Paradigm is that functions cannot have > side affects. > > > So I can claim that Python is not strictly object oriented until it > > gets encapsulation (in the sense of data hiding). That is simply a > > fact, and no amount of pleading or obfuscation will change it. > > In fact this is true, C can be seen as an programming language > that has features of the OO model. > > I think one of the things you guys are missing out > here is that there are really only two Paradigms > or Machines. Functional and Imperative. And guess > what ? As it turns out we can implement functional > machines that run on top of imperative ones! > > > Should Python get true encapsulation? I don't know. Maybe > > encapsulation cannot be added without excessive overhead or without > > compromising other more important aspects and features of the > > language. But I do know that not having encapsulation is a limitation > > to the use of Python for good software engineering. I may be in the > > minority in the Python "community" on this one, but I am apparently in > > the majority in the OO programming "community." > > Again, stop confusing terminology. > > Should Python get strict and enforce access control > of object members ? No. Why ? I can think of several > reasons. > > Give me one use-case where you strictly require > that members of an object be private and their > access enforced as such ? You're kidding, right? Think about a ten-million line program being developed by 100 developers. From philip at semanchuk.com Wed Jan 14 00:14:12 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jan 2009 00:14:12 -0500 Subject: Standard IPC for Python? In-Reply-To: References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> <4A6EB4AB-0208-4AB0-B497-B7CAE4D9AF34@semanchuk.com> <496CDBF8.5020402@shopzeus.com> <1079CAE6-291A-4995-877F-86ADA0610959@semanchuk.com> <496CE50C.6000308@shopzeus.com> Message-ID: On Jan 13, 2009, at 11:26 PM, drobinow at gmail.com wrote: > On Jan 13, 5:08 pm, Philip Semanchuk wrote: >> On Jan 13, 2009, at 4:31 PM, drobi... at gmail.com wrote: >> >>> On Jan 13, 2:37 pm, Philip Semanchuk wrote: >>>> I was suggesting getting posix_ipc or sysv_ipc to compile against a >>>> compatibility library (Cygwin?) under Windows. It sounds like >>>> you're >>>> proposing something totally different, no? >> >>> It's not really correct to call Cygwin a compatibility library. It's >>> more of a separate system. >> >> Thanks for the education; I'm obviously not very familiar with it. >> >>> In any case, the current version (1.5.25) does not support >>> sem_unlink >>> or shm_unlink so posix_ipc does not build. Cygwin 1.7, currently >>> under >>> test, will support these. I haven't tried it yet. I expect it will >>> work OOTB. >> >> Thanks for the report. Strange that it supports the functions to open >> but not close semaphores. IN any case, I'd be very happy if posix_ipc >> or sysv_ipc would work with few or no modifications under Cygwin. >> >> Cheers >> Philip > > I just downloaded cygwin 1.7 and posix_ipc builds successfully. The > demo appears to work. Most excellent! Thank you for the good news. From prologic at shortcircuit.net.au Wed Jan 14 00:25:38 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 15:25:38 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: (...) >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. No I"m sorry this is not a valid use-case. cheers James From michele.simionato at gmail.com Wed Jan 14 00:29:29 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 13 Jan 2009 21:29:29 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Jan 14, 2:02?am, Catherine Moroney wrote: > Hello everybody, > > I know how to spawn a sub-process and then wait until it > completes. ?I'm wondering if I can do the same thing with > a Python function. > > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. ?Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? > > I'm primarily concerned about code readability and ease of > programming. ?The code would look a lot prettier and be shorter > to boot if I could spawn off function calls rather than > subprocesses. > > Thanks for any advice, > > Catherine There is an example explaining how to implement exactly this use case in the documentation of my decorator module: http://pypi.python.org/pypi/decorator/3.0.0#async The Async decorator works both with threads and with multiprocessing. Here is an example of printing from multiple processes (it assumes you downloaded the tarball of the decorator module, documentation.py is the file containing the documentation and the Async decorator; it also assumes you have the multiprocessing module): $ cat example.py import os, multiprocessing from documentation import Async async = Async(multiprocessing.Process) @async def print_msg(): print 'hello from process %d' % os.getpid() for i in range(3): print_msg() $ python example.py hello from process 5903 hello from process 5904 hello from process 5905 From Russ.Paielli at gmail.com Wed Jan 14 00:35:34 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 13 Jan 2009 21:35:34 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 7:50?pm, Carl Banks wrote: > You know what? ?Computer science buzzwords mean jack squat to me. ?I > don't give a horse's tail whether some people label it a fundamental > concept of object-oriented programming or not. ?I think it's a bad > thing. ?And it's a bad thing for exactly the reason I said: it gives > the library implementor the power to dictate to the user how they can > and can't use the library. ?The cultural impact that would have on the > community is far worse, IMHO, than any short-sighted benefits like > being able to catch an accidental usage of an internal variable. > Trust would be replaced by mistrust, and programming in Python would > go from a pleasant experience to constant antagonism. > > No thanks. ?"Software engineering" be damned. ?Python is better off > the way it is. You know what? The more I think about the kind of nonsense you and others are spouting here, the more annoyed I get. I will gladly agree that encapsulation may be more trouble than it's worth for small applications, maybe even some medium sized ones, but you and others here are making blanket proclamations that are just plain nonsense. I suggest you call Boeing and tell them that encapsulation is more trouble than it's worth for their 787 flight software. But please don't do it if you ever wish to work for them, because you will be proving conclusively that you don't have a clue about the kind of software systems they produce. I've wasted more than enough time with this nonsense. From krmane at gmail.com Wed Jan 14 00:46:58 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 11:16:58 +0530 Subject: initialising a class by name Message-ID: <1231912018.7570.22.camel@krishna-laptop> hello all, I have a strange situation where I have to load initiate an instance of a class at run-time with the name given by the user from a dropdown list. Is this possible in python and how? To make things clear, let me give the real example. there is an inventory management system and products belong to different categories. There are predefined categories in the database and for each category there is a module which contains a class made out of pygtk. This means what class gets instantiated and displayed in the gui depends on the choice a user makes in the dropdown. Now, I could have created a list of if conditions for all the categories as in if categorySelection == "books": Books = BookForm() However this is a problem because when there will be more than 100 categories there will be that many if conditions and this will make the code uggly. so my idea is to name the class exactly after the name of the category so that when the user selects a category that name is used to initialise the instance of that class. So is it possible to initialise an instance of a class given its name from a variable? thanks and Happy hacking. Krishnakant. From clp2 at rebertia.com Wed Jan 14 00:51:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 21:51:37 -0800 Subject: initialising a class by name In-Reply-To: <1231912018.7570.22.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> On Tue, Jan 13, 2009 at 9:46 PM, Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. > Is this possible in python and how? > To make things clear, let me give the real example. > there is an inventory management system and products belong to different > categories. > There are predefined categories in the database and for each category > there is a module which contains a class made out of pygtk. > This means what class gets instantiated and displayed in the gui depends > on the choice a user makes in the dropdown. > Now, I could have created a list of if conditions for all the categories > as in > if categorySelection == "books": > Books = BookForm() > > However this is a problem because when there will be more than 100 > categories there will be that many if conditions and this will make the > code uggly. > so my idea is to name the class exactly after the name of the category > so that when the user selects a category that name is used to initialise > the instance of that class. > So is it possible to initialise an instance of a class given its name > from a variable? > thanks and Assuming all the classes are in the same module as the main program: instance = vars()[class_name](args, to, init) Assuming the classes are all in the same module "mod", which is separate from the main program: instance = getattr(mod, class_name)(args, to, init) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From prologic at shortcircuit.net.au Wed Jan 14 00:57:42 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 15:57:42 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: > I think you are the one who is confused. Part of the problem here is > that the term "encapsulation" has at least two widely used meanings > (in the context of programming). In one sense, it just means grouping > data and methods together. In another sense, it means restricting the > client's access to data or methods. Someone earlier on this thread > tried to claim that the first meaning applies to OOP, but Wikipedia > (and many other sources) say just the opposite. > > People here are trying to claim that the leading underscore > conventions used with Python are essentially equivalent to > encapsulation. That is nonsense, of course. > > Others are arguing against encapsulation altogether. That is a bit > like being against locks or passwords because they create a lot of > hassle. Now locks are not needed everywhere, of course, but certainly > they have their place. But the point is that if you don't like > encapsulation, then by definition you don't like OOP. You may like > certain features of OOP, but you don't like it in general. That's > about all their is to it. > > And by the way, please don't bring up the canard that I am some kind > of OO zealot. I think OO is overrated, and I don't Java, in part > because it forces everything to be OO. The issue here is not my > personal opinion of OOP. This issue is one of widely accepted > definitions within the OO community. Russ: 1. Quit while you're ahead. 2. OOP is encapsulating data and functionality into a single grouping (object). 3. Other features more recently developed by OO languages such as Polymorphism, Access Control (a type of encapsulation), Inheritance and Multiple Inheritance are all irrelevant and OO languages either implement all or a subset of these features and each do so differently. Fundamentally it all boils down to4 things (which all of you - including you Russ - just completely miss the point): READ UPDATE ADVANCE These are the 3 operations of a Turing machine of which all computer algorithms can be defined. We usually define a 4th operation called HALT. Now go ponder on that a while and come back and tell me whether you think you really need such things as Abstract Base Classes, Interfaces, Access Control, Static Typing, and so on and so forth ... >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. And what is your point exactly ? Like I said, this is _not_ a valid use case. A language that implements all of the features descirbed in academic texts on OOP will not help you build such a system any faster. I should also point out that building such a system in Python would most likely result in 1/3 of the size in terms of LoC. I should also point out that your numbers you pulled out of your hat would require 22years of development time given the industry standard of 5 LOC/hg per developer. Good luck with that. cheers James From prologic at shortcircuit.net.au Wed Jan 14 01:02:28 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:02:28 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, Jan 14, 2009 at 3:35 PM, Russ P. wrote: > You know what? The more I think about the kind of nonsense you and > others are spouting here, the more annoyed I get. I will gladly agree > that encapsulation may be more trouble than it's worth for small > applications, maybe even some medium sized ones, but you and others > here are making blanket proclamations that are just plain nonsense. > > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. > > I've wasted more than enough time with this nonsense. I am 100% confident that those same systems could be well written in a language such as Python and would very likely end up being much smaller and more manageable. I have a question for you: All your arguments seem to lean towards size and the importance of encapsulation. What is the largest system you have worked on - that has been written entirely in Python ? cheers James From http Wed Jan 14 01:35:31 2009 From: http (Paul Rubin) Date: 13 Jan 2009 22:35:31 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <7x3afm2y4s.fsf@ruckus.brouhaha.com> "James Mills" writes: > Bare in mind also, that enfocing access control / policing as you > called it has a performance hit as the machine (the Python vm) > has to perform checks each time members of an object are accessed. It's the other way around. If the compiler knows that you aren't creating new attributes on the fly, it can put them into fixed slots like a C struct, and method calls become ordinary function calls through a dispatch vector. From catphive at catphive.net Wed Jan 14 01:49:34 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 13 Jan 2009 22:49:34 -0800 Subject: pep 8 constants Message-ID: PEP 8 doesn't mention anything about using all caps to indicate a constant. Is all caps meaning "don't reassign this var" a strong enough convention to not be considered violating good python style? I see a lot of people using it, but I also see a lot of people writing non-pythonic code... so I thought I'd see what the consensus is. Brendan From prologic at shortcircuit.net.au Wed Jan 14 01:55:34 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:55:34 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3afm2y4s.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 4:35 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "James Mills" writes: >> Bare in mind also, that enfocing access control / policing as you >> called it has a performance hit as the machine (the Python vm) >> has to perform checks each time members of an object are accessed. > > It's the other way around. If the compiler knows that you aren't > creating new attributes on the fly, it can put them into fixed slots > like a C struct, and method calls become ordinary function calls > through a dispatch vector. Paul I wasn't referring to static languages and languages that are compiled to machine code such as C, C++, etc. Python is a dynamic object oriented language ... (almost verbatim from the website). It is compiled to bytecode and run on a virtual machine. I don't really think it would be possible or desirable to have strict access control (encapsulation) in the core of python. a) it would piss us all off. b) it would greatly impact on the dynamic nature of python. cheers James From prologic at shortcircuit.net.au Wed Jan 14 01:58:40 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 14 Jan 2009 16:58:40 +1000 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 4:49 PM, Brendan Miller wrote: > PEP 8 doesn't mention anything about using all caps to indicate a constant. > > Is all caps meaning "don't reassign this var" a strong enough > convention to not be considered violating good python style? I see a > lot of people using it, but I also see a lot of people writing > non-pythonic code... so I thought I'd see what the consensus is. It may in fact be deliberate. As there really are no such thing as constants in Python - clearly :) However, on the rare occasion I need to define a global variable in a module that gets used in several places and is more or less used as a standard configured value - I tend to use ALL CAPS. Still I would avoid using this idiom altogether and jsut stick with default values. For Example: FOO = 1 def f(x=FOO): ... Use this instead: def f(x=1): ... cheers James From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:14:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:14:06 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > On Wed, Jan 14, 2009 at 3:11 PM, Russ P. wrote: > (...) > >>> Give me one use-case where you strictly require that members of an >>> object be private and their access enforced as such ? >> >> You're kidding, right? Think about a ten-million line program being >> developed by 100 developers. > > No I"m sorry this is not a valid use-case. Why not? Just saying it isn't doesn't make it not. -- Steven From steve at holdenweb.com Wed Jan 14 02:14:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 02:14:39 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: ajaksu wrote: > On Jan 13, 1:33 am, Philip Semanchuk wrote: >> I don't think I understand you clearly. Whether or not Google et al >> whitelist the Python UA isn't a Python issue, is it? > > Hi, sorry for taking so long to reply :) > > I imagine it's something akin to Firefox's 'Report broken website': > evangelism. > > IMHO, if the PSF *cough* Steve *cough* or individual Python hackers > can contact key sites (as Wikipedia, groups.google, etc.) the issue > can be solved sooner. > > Instead of waiting for each whitelist maintainer's to find out we have > a new UA, go out and tell them. A template for such requests could > help those inside e.g. Google to bring the issue to the attention of > the whitelist admins. The community has lots of connections that could > be useful to pass the message along, if only 'led by the nose' to > achieve that :) > > Hence, the suggestion to raise a bug. > OK, but be aware that the PSF doesn't monitor the bugs looking for actions to take on behalf of the Python user community. In fact we aren't overtly "political" in this way at all. This doesn't mean it wouldn't be useful for the PSF to get involved in this role; just that right now it isn't, and a bug report probably isn't the best way to get action. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From thaisiang at gmail.com Wed Jan 14 02:21:25 2009 From: thaisiang at gmail.com (ts) Date: Tue, 13 Jan 2009 23:21:25 -0800 (PST) Subject: read string in bits Message-ID: hi, is there a way to read a character/string into bits in python? i understand that character is read in bytes. Do i have to write a function to convert it myself into 1010101 or there is a library in python that enable me to do that? From http Wed Jan 14 02:22:45 2009 From: http (Paul Rubin) Date: 13 Jan 2009 23:22:45 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> Message-ID: <7xpriqtkqi.fsf@ruckus.brouhaha.com> "James Mills" writes: > Python is a dynamic object oriented language ... (almost verbatim > from the website). It is compiled to bytecode and run on a virtual > machine. 1. There is nothing inherent about dynamic languages that prevents them from being compiled. There are compiled implementations of Lisp and Scheme that beat the pants off of Python in performance. 2. There is also nothing inherent in a dynamic OO language that says that class descriptors have to be mutable, any more than strings have to be mutable (Python has immutable strings). I agree that being able to modify class descriptors at runtime is sometimes very useful. The feature shouldn't be eliminated from Python or else it wouldn't be Python any more. But those occasions are rare enough that having to enable the feature by saying (e.g.) "@dynamic" before the class definition doesn't seem like a problem, both for encapsulation and because it can also improve performance. From catphive at catphive.net Wed Jan 14 02:26:54 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 13 Jan 2009 23:26:54 -0800 Subject: pep 8 constants In-Reply-To: References: Message-ID: > FOO = 1 > > def f(x=FOO): > ... > > > Use this instead: > > def f(x=1): > ... I tend to use constants as a means of avoiding the proliferation of magic literals for maintenance reasons... Like say if your example of FOO would have been used in 10 places. Maybe it is more pythonic to simply denote such a thing as simply a normal variable? That doesn't seem to give a hint that it shouldn't be assigned a second time. From clp2 at rebertia.com Wed Jan 14 02:32:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 23:32:58 -0800 Subject: read string in bits In-Reply-To: References: Message-ID: <50697b2c0901132332i1b8ce526rd1d0bab37eca7797@mail.gmail.com> On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > hi, is there a way to read a character/string into bits in python? > > i understand that character is read in bytes. Do i have to write a > function to convert it myself into 1010101 or there is a library in > python that enable me to do that? It's not quite clear to me what you mean, but here are 2 guesses: - If you want to convert an ASCII character to its ASCII integer value, use ord() - If you want to convert an integer into a string of its base-2 representation, use bin() [requires Python 2.6, I think] Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From pavlovevidence at gmail.com Wed Jan 14 02:34:15 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 13 Jan 2009 23:34:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 11:35?pm, "Russ P." wrote: > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. That's funny. I worked for four years at a GE Aviation subcontractor on their jet engine control software, so I think do I have a clue about how flight control software systems work. At GE there was no encapsulation in sight on any system I worked on. In fact, our engine simulation was a special-purpose object-oriented language with--get this--no private variables. Some other systems I worked on didn't even use scoping, let alone encapsulation. Looks like my anecdote cancels out yours! Got any more? Carl Banks From steve at holdenweb.com Wed Jan 14 02:35:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 02:35:53 -0500 Subject: are there some special about '\x1a' symbol In-Reply-To: References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Unknown wrote: > On 2009-01-12, John Machin wrote: > >> I didn't think your question was stupid. Stupid was (a) CP/M recording >> file size as number of 128-byte sectors, forcing the use of an in-band >> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >> decades after people stopped writing Ctrl-Z at the end of text files. > > I believe that "feature" was inherited by CP/M from DEC OSes > (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API > (including the FCB) was lifted almost directly from DEC's > PDP-11 stuff, which probably copied it from PDP-8 stuff. > > Perhaps in the early 60's somebody at DEC had a reason. The > really interesting thing is that we're still suffering because > of it 40+ years later. > I suspect this is probably a leftover from some paper tape data formats, when it was easier to detect the end of a file with a sentinel byte than it was to detect run-off as end of file. It could easily date back to the PDP-8. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent.gulinao at gmail.com Wed Jan 14 02:37:30 2009 From: vincent.gulinao at gmail.com (Vincent Gulinao) Date: Wed, 14 Jan 2009 15:37:30 +0800 Subject: WebDAV client module In-Reply-To: References: Message-ID: Um.. and I can't seem to find any sample code of it around. Can anybody share a simple snippet of how to use it? I don't understand what's URI in PutFile method is suppose to be. TIA. On Tue, Jan 13, 2009 at 8:03 PM, Vincent Gulinao wrote: > Kindly point me to a good WebDAV client module for Python. Looks like PyDav > is popular, but it seems some of the modules used within were already > deprecated. > > TIA. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:40:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:40:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Tue, 13 Jan 2009 20:17:08 -0800, Carl Banks wrote: > On Jan 13, 9:50?pm, Carl Banks wrote: >> The cultural impact that would have on the community is far worse, >> IMHO, than any short-sighted benefits like being able to catch an >> accidental usage of an internal variable. Trust would be replaced by >> mistrust, and programming in Python would go from a pleasant experience >> to constant antagonism. > > And I'll give you a perfect example: > > XML-DOM versus ElementTree > > XML-DOM is the sort of standard that is borne of a culture that values > encapsulation, strict type safety, and so on. It's the way it is > because designers were allowed to distrust the user, and the culture > said that it was good to distrust the user. Consequently, the interface > is a pain to use, with all kinds of boilerplate and iterator types and > such. > > ElementTree was borne out of an environment where implementors are > forced to trust the user. As a consequence it was free to create an > interface that was natural and straightforward and pleasant to use, > without having to be guarded. Which is all well and good, but there are circumstances where you *don't* want to trust arbitrary parts of your code to change other parts of your code, for good reason. In other words, you don't always want to trust your users. Forget copy protection and DRM. Think about the software controlling a radiation machine for cancer treatment, with a limit on the number of rads it fires at any one time. It would be disastrous for any arbitrary function in the machine's software to be able to mess with that limit, accidentally or deliberately. People will die if you get it wrong. My attitude when programming in Python is to accept that if the caller passes an inappropriate argument to my function, my function may crash (raise an exception). That's the caller's responsibility. I can get away with this laissez faire attitude because I don't have to worry about my software crashing at the wrong time and causing a plane filled with 500 nuns and orphans suddenly flip upside down and nose-dive into a mountain. Or the nuclear reactor to suddenly drop all the fuel rods into the core simultaneously. Sometimes "oh, just raise an exception and exit" is simply not good enough. Security/safety and freedom/flexibility are sometimes in conflict. There are plenty of languages which enforce access. It is a good thing that Python allows more flexibility. That's why I use Python. The traditional answer to this "if you need Java, you know where to get it". But, gosh darn it, wouldn't it be nice to program the critical parts of your code in "strict Python", and leave the rest as "trusting Python", instead of having to use Java for the lot just to get strictness in the critical parts? If only there was a way to do this, and ensure people won't abuse it. -- Steven From thaisiang at gmail.com Wed Jan 14 02:44:07 2009 From: thaisiang at gmail.com (ts) Date: Tue, 13 Jan 2009 23:44:07 -0800 (PST) Subject: read string in bits References: Message-ID: On Jan 14, 3:32?pm, Chris Rebert wrote: > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > hi, is there a way to read a character/string into bits in python? > > > i understand that character is read in bytes. Do i have to write a > > function to convert it myself into 1010101 or there is a library in > > python that enable me to do that? > > It's not quite clear to me what you mean, but here are 2 guesses: > - If you want to convert an ASCII character to its ASCII integer > value, use ord() > - If you want to convert an integer into a string of its base-2 > representation, use bin() [requires Python 2.6, I think] > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com hi, bin() is what i'm looking for. But only python 2.4 is available to me. Is there a replacement of bin() in python 2.4? From krmane at gmail.com Wed Jan 14 02:49:23 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:19:23 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> Message-ID: <1231919363.7570.27.camel@krishna-laptop> On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: > Assuming all the classes are in the same module as the main program: > > instance = vars()[class_name](args, to, init) > The classes are not in the same module. Every glade window is coupled with one py file (module) containing one class that has the events for the glade file. Inshort, there is one class in one module and they are all seperate. > Assuming the classes are all in the same module "mod", which is > separate from the main program: > > instance = getattr(mod, class_name)(args, to, init) > Can you explain the difference between getattr and var()? > Cheers, > Chris > happy hacking. Krishnakant. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 02:50:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 07:50:47 GMT Subject: initialising a class by name References: Message-ID: On Wed, 14 Jan 2009 11:16:58 +0530, Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. Not strange at all. > Is this possible in python and how? Of course. Just use a dispatch table. Use a dict to map user strings to classes: >>> class Spam(object): pass ... >>> class Ham(object): pass ... >>> dispatch_table = {"Spam": Spam, "Ham": Ham} >>> dispatch_table["Ham"]() <__main__.Ham object at 0xb7ea2f8c> The keys don't even have to be the name of the class, they can be whatever input your users can give: >>> dispatch_table["Yummy meat-like product"] = Spam >>> dispatch_table["Yummy meat-like product"]() <__main__.Spam object at 0xb7ea2f6c> You can even automate it: >>> dispatch_table = {} >>> for name in dir(): ... obj = globals()[name] ... if type(obj) == type: ... dispatch_table[name] = obj ... >>> dispatch_table {'Ham': , 'Spam': } -- Steven From http Wed Jan 14 02:51:58 2009 From: http (Paul Rubin) Date: 13 Jan 2009 23:51:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: <7xsknmwcip.fsf@ruckus.brouhaha.com> Carl Banks writes: > At GE there was no encapsulation in sight on any system I worked on. > In fact, our engine simulation was a special-purpose object-oriented > language with--get this--no private variables. Some other systems I > worked on didn't even use scoping, let alone encapsulation. Where my officemate used to work, the simulation stuff was written in Matlab, but the actual flight stuff was written in Ada. I wonder if GE did something similar. From clp2 at rebertia.com Wed Jan 14 02:55:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jan 2009 23:55:21 -0800 Subject: initialising a class by name In-Reply-To: <1231919363.7570.27.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> Message-ID: <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> Assuming all the classes are in the same module as the main program: >> >> instance = vars()[class_name](args, to, init) >> > The classes are not in the same module. > Every glade window is coupled with one py file (module) containing one > class that has the events for the glade file. > Inshort, there is one class in one module and they are all seperate. >> Assuming the classes are all in the same module "mod", which is >> separate from the main program: >> >> instance = getattr(mod, class_name)(args, to, init) >> > Can you explain the difference between getattr and var()? getattr(x, 'y') <==> x.y vars() gives a dict representing the current accessible variable bindings (I should have instead recommended the related globals() function) globals() gives a dict representing the global variable bindings For example: #foo.py class Foo(object): #code here Foo() #same as globals()['Foo']() #end of file Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Wed Jan 14 03:06:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 14 Jan 2009 06:06:11 -0200 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: En Tue, 13 Jan 2009 22:04:33 -0200, Terry Reedy escribi?: > Gabriel Genellina wrote: >> En Mon, 12 Jan 2009 12:00:16 -0200, John Machin >> escribi?: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> This is called "backwards compatibility" and it's a good thing :) > > But it does not have to be the default or only behavior to be available. Sure. And it isn't - there are many flags to open and fopen to choose from... The C89 standard (the language used to compile CPython) guarantees *only* that printable characters, tab, and newline are preserved in a text file; everything else may or may not appear when it is read again. Even whitespace at the end of a line may be dropped. Binary files are more predictable... Delphi recognizes the EOF marker when reading a text file only inside the file's last 128-byte block -- this mimics the original CP/M behavior rather closely. I thought the MSC runtime did the same, but no, the EOF marker is recognized anywhere. And Python inherits that (at least in 2.6 -- I've not tested with 3.0) -- Gabriel Genellina From pavlovevidence at gmail.com Wed Jan 14 03:08:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 00:08:51 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 14, 1:40?am, Steven D'Aprano wrote: > On Tue, 13 Jan 2009 20:17:08 -0800, Carl Banks wrote: > > On Jan 13, 9:50?pm, Carl Banks wrote: > >> The cultural impact that would have on the community is far worse, > >> IMHO, than any short-sighted benefits like being able to catch an > >> accidental usage of an internal variable. Trust would be replaced by > >> mistrust, and programming in Python would go from a pleasant experience > >> to constant antagonism. > > > And I'll give you a perfect example: > > > XML-DOM versus ElementTree > > > XML-DOM is the sort of standard that is borne of a culture that values > > encapsulation, strict type safety, and so on. ?It's the way it is > > because designers were allowed to distrust the user, and the culture > > said that it was good to distrust the user. ?Consequently, the interface > > is a pain to use, with all kinds of boilerplate and iterator types and > > such. > > > ElementTree was borne out of an environment where implementors are > > forced to trust the user. ?As a consequence it was free to create an > > interface that was natural and straightforward and pleasant to use, > > without having to be guarded. > > Which is all well and good, but there are circumstances where you *don't* > want to trust arbitrary parts of your code to change other parts of your > code, for good reason. In other words, you don't always want to trust > your users. > > Forget copy protection and DRM. Think about the software controlling a > radiation machine for cancer treatment, with a limit on the number of > rads it fires at any one time. It would be disastrous for any arbitrary > function in the machine's software to be able to mess with that limit, > accidentally or deliberately. People will die if you get it wrong. I'm on record saying Python shouldn't be used for systems with the possibility of catastrophic failure: that's with or without encapsulation. Too much happening internally to account for it all. Frankly I'm not sure that C++ and Java's encapsulation is good enough, either. Software-enforced encapsulation can be subverted, and sometimes invalid access can happen from within the protection zone. If something's that important, it needs to be running with redundancy and lots and lots of fault tolerance, and it needs to have the hell tested out of it. If it's critically important, the code should be storing the critical information in a separate data area with a higher privledge level than the rest of the program. The simpleminded encapsulation schemes of C++ and Java are weak compared to these methods, and probably wouldn't add much. As I said, I've worked on flight control systems that didn't use any data hiding at all. Even if a drastic coding mistake like you mentioned was able to make it though dozens of peer reviews and hundreds of tests, it still might not result in catastrophic failure because of all the fault tolerance built-in. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:13:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:13:30 GMT Subject: pep 8 constants References: Message-ID: On Tue, 13 Jan 2009 23:26:54 -0800, Brendan Miller wrote: > I tend to use constants as a means of avoiding the proliferation of > magic literals for maintenance reasons... Like say if your example of > FOO would have been used in 10 places. Maybe it is more pythonic to > simply denote such a thing as simply a normal variable? But it isn't a "normal variable", it's a named constant, or at least it would be if Python enforced constanticity. Or constantness. Or whatever. > That doesn't > seem to give a hint that it shouldn't be assigned a second time. Absolutely. It's rather sad that I can do this: import math math.pi = 3.0 I like the ability to shoot myself in the foot, thank you very much, but I should at least get a warning when I'm about to do so: math.PI = 3.0 # use God-like powers to change a constant Changing the laws of physics, one fundamental constant at a time-ly y'rs, -- Steven From krmane at gmail.com Wed Jan 14 03:15:05 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:45:05 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> Message-ID: <1231920905.7570.40.camel@krishna-laptop> Hi, So should I not use getattr()? If I have one class in one module, then should I use global? I found getattr() very easy to use, my only dowbt is that if there is going to be one class per module then will it be a good idea? some thing like module, class_name happy hacking. Krishnakantt. On Tue, 2009-01-13 at 23:55 -0800, Chris Rebert wrote: > On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: > > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: > >> Assuming all the classes are in the same module as the main program: > >> > >> instance = vars()[class_name](args, to, init) > >> > > The classes are not in the same module. > > Every glade window is coupled with one py file (module) containing one > > class that has the events for the glade file. > > Inshort, there is one class in one module and they are all seperate. > >> Assuming the classes are all in the same module "mod", which is > >> separate from the main program: > >> > >> instance = getattr(mod, class_name)(args, to, init) > >> > > Can you explain the difference between getattr and var()? > > getattr(x, 'y') <==> x.y > > vars() gives a dict representing the current accessible variable > bindings (I should have instead recommended the related globals() > function) > globals() gives a dict representing the global variable bindings > For example: > #foo.py > class Foo(object): > #code here > > Foo() > #same as > globals()['Foo']() > #end of file > > Cheers, > Chris > From mail at microcorp.co.za Wed Jan 14 03:15:42 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 14 Jan 2009 10:15:42 +0200 Subject: read string in bits References: <50697b2c0901132332i1b8ce526rd1d0bab37eca7797@mail.gmail.com> Message-ID: <04f201c97622$21df0780$0d00a8c0@hendrik> "Chris Rebert" wrote: > It's not quite clear to me what you mean, but here are 2 guesses: > - If you want to convert an ASCII character to its ASCII integer > value, use ord() > - If you want to convert an integer into a string of its base-2 > representation, use bin() [requires Python 2.6, I think] Another case: >>> s = '1010101' >>> int (s,2) 85 >>> Works almost anywhere, AFAIK. - Hendrik From clp2 at rebertia.com Wed Jan 14 03:20:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 00:20:21 -0800 Subject: initialising a class by name In-Reply-To: <1231920905.7570.40.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> Message-ID: <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> On Wed, Jan 14, 2009 at 12:15 AM, Krishnakant wrote: > Hi, > So should I not use getattr()? > If I have one class in one module, then should I use global? > I found getattr() very easy to use, my only dowbt is that if there is > going to be one class per module then will it be a good idea? > some thing like module, class_name > happy hacking. > Krishnakantt. Aside from Steven's excellent idea, to use the getattr() technique with your module scheme you'd probably also need to use __import__() to dynamically import the right module. Also, don't top-post. It makes following the conversation harder for readers. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > On Tue, 2009-01-13 at 23:55 -0800, Chris Rebert wrote: > >> On Tue, Jan 13, 2009 at 11:49 PM, Krishnakant wrote: >> > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> >> Assuming all the classes are in the same module as the main program: >> >> >> >> instance = vars()[class_name](args, to, init) >> >> >> > The classes are not in the same module. >> > Every glade window is coupled with one py file (module) containing one >> > class that has the events for the glade file. >> > Inshort, there is one class in one module and they are all seperate. >> >> Assuming the classes are all in the same module "mod", which is >> >> separate from the main program: >> >> >> >> instance = getattr(mod, class_name)(args, to, init) >> >> >> > Can you explain the difference between getattr and var()? >> >> getattr(x, 'y') <==> x.y >> >> vars() gives a dict representing the current accessible variable >> bindings (I should have instead recommended the related globals() >> function) >> globals() gives a dict representing the global variable bindings >> For example: >> #foo.py >> class Foo(object): >> #code here >> >> Foo() >> #same as >> globals()['Foo']() >> #end of file >> >> Cheers, >> Chris >> From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:23:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:23:07 GMT Subject: initialising a class by name References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> Message-ID: On Wed, 14 Jan 2009 13:19:23 +0530, Krishnakant wrote: > On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote: >> Assuming all the classes are in the same module as the main program: >> >> instance = vars()[class_name](args, to, init) >> > The classes are not in the same module. Every glade window is coupled > with one py file (module) containing one class that has the events for > the glade file. Inshort, there is one class in one module and they are > all seperate. Just import the classes you need, and dispatch on them. import spammodule, hammodule dispatch_table = { "Spam": spammodule.Spamclass, "Ham": hammodule.Hamclass} # later obj = dispatch_table[ user_input ]() >> Assuming the classes are all in the same module "mod", which is >> separate from the main program: >> >> instance = getattr(mod, class_name)(args, to, init) >> > Can you explain the difference between getattr and var()? They are completely different things. At an interactive prompt, type: help(getattr) help(var) and read what they say. -- Steven From hackingkk at gmail.com Wed Jan 14 03:23:52 2009 From: hackingkk at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 13:53:52 +0530 Subject: initialising a class by name In-Reply-To: References: Message-ID: <1231921432.7570.46.camel@krishna-laptop> Hi steevan, I liked this idea of dispatchTable. is it possible to say some thing like inst = dispatchTable{"ham"} according to me, inst will become the instance of class ham. Another thing to note is that all the classes are in different modules. So where do I create the dict of classes mapped with the name? happy hacking. Krishnakant. On Wed, 2009-01-14 at 07:50 +0000, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 11:16:58 +0530, Krishnakant wrote: > > > hello all, > > I have a strange situation where I have to load initiate an instance of > > a class at run-time with the name given by the user from a dropdown > > list. > > Not strange at all. > > > Is this possible in python and how? > > Of course. Just use a dispatch table. Use a dict to map user strings to > classes: > > > >>> class Spam(object): pass > ... > >>> class Ham(object): pass > ... > >>> dispatch_table = {"Spam": Spam, "Ham": Ham} > >>> dispatch_table["Ham"]() > <__main__.Ham object at 0xb7ea2f8c> > > > The keys don't even have to be the name of the class, they can be > whatever input your users can give: > > >>> dispatch_table["Yummy meat-like product"] = Spam > >>> dispatch_table["Yummy meat-like product"]() > <__main__.Spam object at 0xb7ea2f6c> > > > You can even automate it: > > >>> dispatch_table = {} > >>> for name in dir(): > ... obj = globals()[name] > ... if type(obj) == type: > ... dispatch_table[name] = obj > ... > >>> dispatch_table > {'Ham': , 'Spam': } > > > From mail at microcorp.co.za Wed Jan 14 03:24:17 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 14 Jan 2009 10:24:17 +0200 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <04f301c97622$2286e040$0d00a8c0@hendrik> "Steve Holden" wrote: > Unknown wrote: > > On 2009-01-12, John Machin wrote: > > I believe that "feature" was inherited by CP/M from DEC OSes > > (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API > > (including the FCB) was lifted almost directly from DEC's > > PDP-11 stuff, which probably copied it from PDP-8 stuff. > > > > Perhaps in the early 60's somebody at DEC had a reason. The > > really interesting thing is that we're still suffering because > > of it 40+ years later. > > > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. We can be kind of fortunate that the ASCII chars for field separator, record separator, file separator, unit separator did not catch on in a big way in file formatting. (remembering the Pick OS running on Reality...) - Hendrik From joost.ruyter at gmail.com Wed Jan 14 03:31:11 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 00:31:11 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem Message-ID: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> I have this really strange problem. I hope someone can help: I am trying to update a database like so: UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like '%certainvalue%' My Python code looks like this: fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like '%%%s%%' " % certainvalue print fillsql cursor.execute(fillsql) #also tried: #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy like %s ", "%%%s%%" % certainvalue) But it doesn't work... But when i copy and past the SQL (printed by "print fillsql" line) and execute that in phpMyAdmin, it does work!!! Can anyone tell me what i am doing wrong?? Thanks in advance!! From sjmachin at lexicon.net Wed Jan 14 03:33:49 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 00:33:49 -0800 (PST) Subject: read string in bits References: Message-ID: <8fee210c-1775-4fc7-b0f8-6898529180cb@e1g2000pra.googlegroups.com> On Jan 14, 6:44?pm, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? No. You would have to write some code 8-( This should give you some clues: | Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> def char_as_number(char, base): | ... assert 2 <= base <= 16 | ... n = ord(char) | ... if not n: | ... return '0' | ... result = '' | ... while n: | ... n, r = divmod(n, base) | ... result = '0123456789ABCDEF'[r] + result | ... return result | ... | >>> [char_as_number(chr(x), 2) for x in (0, 1, 7, 8, 127, 128, 255)] | ['0', '1', '111', '1000', '1111111', '10000000', '11111111'] | >>> [char_as_number(chr(x), 2).zfill(8) for x in (0, 1, 7, 8, 127, 128, 255)] | ['00000000', '00000001', '00000111', '00001000', '01111111', '10000000', '11111111'] | >>> [char_as_number(chr(x), 16).zfill(2) for x in (0, 1, 7, 8, 127, 128, 255)] | ['00', '01', '07', '08', '7F', '80', 'FF'] | >>> [char_as_number(chr(x), 8).zfill(3) for x in (0, 1, 7, 8, 127, 128, 255)] | ['000', '001', '007', '010', '177', '200', '377'] | >>> HTH, John From pornbypost at gmail.com Wed Jan 14 03:35:01 2009 From: pornbypost at gmail.com (Mark Smith) Date: Wed, 14 Jan 2009 00:35:01 -0800 (PST) Subject: read string in bits References: Message-ID: <283174d4-df94-4d78-a218-2bb492019d9a@i20g2000prf.googlegroups.com> On Jan 14, 7:44?am, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? There's a recipe for this at ActiveState: http://code.activestate.com/recipes/219300/#c6 From pornbypost at gmail.com Wed Jan 14 03:36:45 2009 From: pornbypost at gmail.com (Mark Smith) Date: Wed, 14 Jan 2009 00:36:45 -0800 (PST) Subject: read string in bits References: Message-ID: <82f91b98-115d-4eeb-ba0f-c067e62d702e@q30g2000vbn.googlegroups.com> On Jan 14, 7:44?am, ts wrote: > On Jan 14, 3:32?pm, Chris Rebert wrote: > > > > > On Tue, Jan 13, 2009 at 11:21 PM, ts wrote: > > > hi, is there a way to read a character/string into bits in python? > > > > i understand that character is read in bytes. Do i have to write a > > > function to convert it myself into 1010101 or there is a library in > > > python that enable me to do that? > > > It's not quite clear to me what you mean, but here are 2 guesses: > > - If you want to convert an ASCII character to its ASCII integer > > value, use ord() > > - If you want to convert an integer into a string of its base-2 > > representation, use bin() [requires Python 2.6, I think] > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > hi, bin() is what i'm looking for. But only python 2.4 is available to > me. Is there a replacement of bin() in python 2.4? There's a recipe at ActiveState: http://code.activestate.com/recipes/219300/#c6 From krmane at gmail.com Wed Jan 14 03:36:49 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 14:06:49 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> Message-ID: <1231922209.7570.49.camel@krishna-laptop> On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > Aside from Steven's excellent idea, to use the getattr() technique > with your module scheme you'd probably also need to use __import__() > to dynamically import the right module. > I would generally import all the modules I would need at the top of the main module. then would use getattr(module,class_name) will that work? or do I need to import in some other way? happy hacking. Krishnakant. From clp2 at rebertia.com Wed Jan 14 03:39:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 00:39:50 -0800 Subject: initialising a class by name In-Reply-To: <1231922209.7570.49.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> <1231922209.7570.49.camel@krishna-laptop> Message-ID: <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: >> Aside from Steven's excellent idea, to use the getattr() technique >> with your module scheme you'd probably also need to use __import__() >> to dynamically import the right module. >> > I would generally import all the modules I would need at the top of the > main module. > then would use getattr(module,class_name) will that work? Yes, that is how you'd do it in that case. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 03:43:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 08:43:17 GMT Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Tue, 13 Jan 2009 23:06:58 +0000, Mark Wooding wrote: > I'm going to move away from the formal semantics stuff and try a > different tack. Here's what I think is the defining property of > pass-by-value (distilled from the formal approach I described earlier, > but shorn of the symbolism): > > The callee's parameters are /new variables/, initialized /as if by > assignment/ from the values of caller's argument expressions. Well, that's one way of looking at it, I guess. The problem is that when I do this: x = "something" # just an example, not necessarily a string y = x Does the line y=x create a new variable? Depends on what you mean by variable. If you mean a new name, symbol or whatever, then obviously yes. But if you mean a new value, namely the string "something", then not necessarily. In Pascal (and C?) those bytes are copied, giving two independent values which just happen to be equal. In Python, both x and y refer to the same string, and I choose the term deliberately. See, I'm not *entirely* against the use of referring to references, when appropriate. I think we just differ on when we think it's appropriate. Which I guess brings us back to your earlier assertion (I think it was you) that people aren't confused about argument passing, they're confused about assignment. [...] > But! (you claim) ... > >> Python simply can't be pass-by-value, because it doesn't behave like >> pass-by-value in other languages (particularly C and Pascal). > > Ah! (say I) but assignment in C and Pascal looks different from the way > it looks in C I'm sorry, that confuses me. Assignment in C looks different from the way it looks in C? I guess the second C should be Python. > -- and in exactly the same way that argument passing looks > different. And there, I think, I'm going to rest my case. > > I'm sorry I took so long to distill these thoughts. Thank you for > putting up with my theoretical meanderings on the way. And thank you for not kill-filing me when tempers were getting short. -- Steven From Russ.Paielli at gmail.com Wed Jan 14 03:44:05 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 00:44:05 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> Message-ID: <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> On Jan 13, 11:51?pm, Paul Rubin wrote: > Carl Banks writes: > > At GE there was no encapsulation in sight on any system I worked on. > > In fact, our engine simulation was a special-purpose object-oriented > > language with--get this--no private variables. ?Some other systems I > > worked on didn't even use scoping, let alone encapsulation. > > Where my officemate used to work, the simulation stuff was written in > Matlab, but the actual flight stuff was written in Ada. ?I wonder > if GE did something similar. I was going to suggest the same thing. An engine *simulation* is one thing; the actual engine control code is another. And the interface between the engine control code and the rest of the flight software is yet another. The FMS should be setting the throttle level, but I doubt it should be fooling around with the guts of the engine control software. From Ron.Barak at lsi.com Wed Jan 14 03:45:37 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 14 Jan 2009 08:45:37 +0000 Subject: Could you suggest optimisations ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF602494E68@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF602494EC6@enbmail01.lsi.com> Hi Terry, -----Original Message----- From: Terry Reedy [mailto:tjreedy at udel.edu] Sent: Wednesday, January 14, 2009 01:57 To: python-list at python.org Subject: Re: Could you suggest optimisations ? Barak, Ron wrote: > Hi, > > In the attached script, the longest time is spent in the following > functions (verified by psyco log): I cannot help but wonder why and if you really need all the rigamorole with file pointers, offsets, and tells instead of for line in open(...): do your processing. I'm building a database of the found events in the logs (those records between the first and last regexs in regex_array). The user should then be able to navigate among these events (among other functionality). This is why I need the tells and offsets, so I'd know the place in the logs where an event starts/ends. Bye, Ron. > > def match_generator(self,regex): > """ > Generate the next line of self.input_file that > matches regex. > """ > generator_ = self.line_generator() > while True: > self.file_pointer = self.input_file.tell() > if self.file_pointer != 0: > self.file_pointer -= 1 > if (self.file_pointer + 2) >= self.last_line_offset: > break > line_ = generator_.next() > print "%.2f%% \r" % (((self.last_line_offset - > self.input_file.tell()) / (self.last_line_offset * 1.0)) * 100.0), > if not line_: > break > else: > match_ = regex.match(line_) > groups_ = re.findall(regex,line_) > if match_: > yield line_.strip("\n"), groups_ > > def get_matching_records_by_regex_extremes(self,regex_array): > """ > Function will: > Find the record matching the first item of regex_array. > Will save all records until the last item of regex_array. > Will save the last line. > Will remember the position of the beginning of the next line in > self.input_file. > """ > start_regex = regex_array[0] > end_regex = regex_array[len(regex_array) - 1] > > all_recs = [] > generator_ = self.match_generator > > try: > match_start,groups_ = generator_(start_regex).next() > except StopIteration: > return(None) > > if match_start != None: > all_recs.append([match_start,groups_]) > > line_ = self.line_generator().next() > while line_: > match_ = end_regex.match(line_) > groups_ = re.findall(end_regex,line_) > if match_ != None: > all_recs.append([line_,groups_]) > return(all_recs) > else: > all_recs.append([line_,[]]) > line_ = self.line_generator().next() > > def line_generator(self): > """ > Generate the next line of self.input_file, and update > self.file_pointer to the beginning of that line. > """ > while self.input_file.tell() <= self.last_line_offset: > self.file_pointer = self.input_file.tell() > line_ = self.input_file.readline() > if not line_: > break > yield line_.strip("\n") > > I was trying to think of optimisations, so I could cut down on > processing time, but got no inspiration. > (I need the "print "%.2f%% \r" ..." line for user's feedback). > > Could you suggest any optimisations ? > Thanks, > Ron. > > > P.S.: Examples of processing times are: > > * 2m42.782s on two files with combined size of 792544 bytes > (no matches found). > * 28m39.497s on two files with combined size of 4139320 bytes > (783 matches found). > > These times are quite unacceptable, as a normal input to the program > would be ten files with combined size of ~17MB. > > > ---------------------------------------------------------------------- > -- > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From sromero at gmail.com Wed Jan 14 04:02:33 2009 From: sromero at gmail.com (Santiago Romero) Date: Wed, 14 Jan 2009 01:02:33 -0800 (PST) Subject: Read binary file and dump data in References: <005ebe51-69c0-477b-a5de-30e5e20183f0@g3g2000pre.googlegroups.com> Message-ID: > If you are reading arbitrary bytes then it will likely not always "look" > like integers. What you probably meant is: > > for i in data: > ? ?print "%d, " % ord(i) That's it! :-) Thanks a lot. From castironpi at gmail.com Wed Jan 14 04:03:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 01:03:43 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: On Jan 13, 7:02?pm, Catherine Moroney wrote: > Hello everybody, > > I know how to spawn a sub-process and then wait until it > completes. ?I'm wondering if I can do the same thing with > a Python function. > > I would like to spawn off multiple instances of a function > and run them simultaneously and then wait until they all complete. > Currently I'm doing this by calling them as sub-processes > executable from the command-line. ?Is there a way of accomplishing > the same thing without having to make command-line executables > of the function call? > > I'm primarily concerned about code readability and ease of > programming. ?The code would look a lot prettier and be shorter > to boot if I could spawn off function calls rather than > subprocesses. > > Thanks for any advice, > > Catherine 'multiprocessing' does what you mentioned, as others said. The abstraction layer is solid, which makes your code pretty. However, it just creates a command line like this: '"c:\\programs\\python26\\python.exe" "-c" "from multiprocessing.forking import main; main()" "--multiprocessing-fork" "1916"' The handle '1916' is a pipe used to read further instructions. The arrive in 'main()' in the form of a pickled (serialized) dictionary. In it, the 'main_path' key contains the path to your program. 'main ()' calls the 'prepare()' function, which calls 'imp.find_module', using that path. Pretty sophisticated. You can do it yourself by creating your own command line. Create a subprocess by this command line (untested & lots of caveats): '"c:\\programs\\python26\\python.exe" "-c" "from myprogram import myfunc; myfunc()"' But you have practically no communication with it. If you need parameters, you can include them on the command line, since you're building it yourself (untested & highly vulnerable): '"c:\\programs\\python26\\python.exe" "-c" "from myprogram import myfunc; myfunc( literal1, literal2 )"' For a return value, unless it can be a simple exit code, you'll need a communication channel. For it, a socket wouldn't be bad, or a pipe if you're not on Windows (include the port or descriptor on the command line). (Even with 'multiprocessing', you're limited to pickleable objects, however, I believe.) From lilanidhaval at gmail.com Wed Jan 14 04:03:53 2009 From: lilanidhaval at gmail.com (lilanidhaval at gmail.com) Date: Wed, 14 Jan 2009 01:03:53 -0800 (PST) Subject: PYTHON HTTP POST Message-ID: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> Hi, I need one complete example of how to do a http post to any site. I have tried making a POST to google but all I am returned with is a 405 error. I don't want to use Pygoogle as I want to try and do this with other sites. I am also having problems inputing with the param I have tried Mechanize. There are no problems with getting data only posting. >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', ... 'User-Agent':'Mozilla/4.0', ... 'Content-Length':'7'} >>> conn = httplib.HTTPConnection("www.google.com") >>> conn.request("POST","/search",params,headers) >>> r2 = conn.getresponse() >>> print r2.status, r2.reason 405 Method Not Allowed Regards, Dhaval From steve at holdenweb.com Wed Jan 14 04:09:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 04:09:24 -0500 Subject: initialising a class by name In-Reply-To: <1231912018.7570.22.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: Krishnakant wrote: > hello all, > I have a strange situation where I have to load initiate an instance of > a class at run-time with the name given by the user from a dropdown > list. > Is this possible in python and how? > To make things clear, let me give the real example. > there is an inventory management system and products belong to different > categories. > There are predefined categories in the database and for each category > there is a module which contains a class made out of pygtk. > This means what class gets instantiated and displayed in the gui depends > on the choice a user makes in the dropdown. > Now, I could have created a list of if conditions for all the categories > as in > if categorySelection == "books": > Books = BookForm() > > However this is a problem because when there will be more than 100 > categories there will be that many if conditions and this will make the > code uggly. > so my idea is to name the class exactly after the name of the category > so that when the user selects a category that name is used to initialise > the instance of that class. > So is it possible to initialise an instance of a class given its name > from a variable? > thanks and > Happy hacking. > Krishnakant. > You don't need to have the names of the classes related to anything in the interface. Just use a list of classes, and have the user interface return the correct index for each class. Then (supposing the selection by the user is seln) use Books = classes[seln]() If the classes are all in different modules, import them before creating the list of classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Russ.Paielli at gmail.com Wed Jan 14 04:09:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 01:09:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Jan 13, 11:40?pm, Steven D'Aprano wrote: > But, gosh darn it, wouldn't it be nice to program the critical parts of > your code in "strict Python", and leave the rest as "trusting Python", > instead of having to use Java for the lot just to get strictness in the > critical parts? If only there was a way to do this, and ensure people > won't abuse it. Yes, that would indeed be nice. I am certainly not the only one who could use a language that is excellent for both research prototyping *and* the final, safety-critical system. Then perhaps the prototype could just be cleaned up and "hardened" for the end product rather than rewritten in another language -- by programmers in another state who may fail to understand many of the details that the prototype developer agonized over. I don't know if such a versatile language could even exist, but it would sure be valuable. Maybe it's like asking for a football player who can excel as both a wide receiver and a guard. But players who weigh 280 pounds and run a 4.4 40 are hard to find. From sjmachin at lexicon.net Wed Jan 14 04:14:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 01:14:36 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> On Jan 14, 7:31?pm, gumbah wrote: > I have this really strange problem. I hope someone can help: > > I am trying to update a database like so: > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > like '%certainvalue%' > > My Python code looks like this: > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > and fieldy like '%%%s%%' " % certainvalue call this trial 1 > print fillsql > cursor.execute(fillsql) > > #also tried: > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > null and fieldy like %s ", "%%%s%%" % certainvalue) call this trial 2 > > But it doesn't work... But when i copy and past the SQL (printed by > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! You don't say what "doesn't work" means ... did you get exceptions, or just silently not updating? > > Can anyone tell me what i am doing wrong?? Well the "trial 1" method is guaranteed not to work if certainvalue contains an apostrophe e.g. "O'Reilly". In any case, you should never build your own SQL statement like that; use the "trial 2" method -- it will do whatever is necessary in the way of reformatting or escaping your input. I know near nothing about mySQLdb, but here are some comments based on general SQL experience: (1) `tablename` isn't SQL syntax that I've seen before; perhaps it works in phpMyAdmin but not in cursor.execute() (2) similarly = NULL ... I'd expect IS NULL (3) It is updating but your script and your phpMyAdmin session are pointing at different instances of the database (4) For trial 2 method, shouldn't the 2nd arg of cursor.execute() should be a sequence e.g. ("%%%s%%" % certainvalue, ) ? HTH John From koranthala at gmail.com Wed Jan 14 04:21:58 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Wed, 14 Jan 2009 01:21:58 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> Message-ID: <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Does google accept POST? Anyways, if you dont need to post files, you can use urlencode itself. def encode_formdata(fields): body = urllib.urlencode(dict()) content_type = "application/x-www-form-urlencoded" return content_type, body If you need to post files too, then you will have to use multipart data def encode_multipart_formdata(fields, files): """ fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance """ BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append('Content-Type: %s' % mimetypes.guess_type(filename) [0] or 'application/octet-stream' L.append('') L.append(value) L.append('--' + BOUNDARY + '--') L.append('') body = CRLF.join(L) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type, body Since POST files doesnt work with urllib, you might have to use httplib - or go for very high level tools like twisted. I here show an example with httplib. def post(host, selector, fields, files): if files: content_type, body = encode_multipart_formdata(fields, files) else: content_type, body = encode_formdata(fields) h = httplib.HTTPConnection(host) #Spoof Mozilla headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', 'Content-Type': content_type } h.request('POST', selector, body, headers) res = h.getresponse() return res.status, res.reason, res.read() Please note that you can use multipart whether or not files are there, but parsing multipart usually is slower. Hope this helps. lilanidha... at gmail.com wrote: > Hi, > > I need one complete example of how to do a http post to any site. > I have tried making a POST to google but all I am returned with is a > 405 error. > I don't want to use Pygoogle as I want to try and do this with other > sites. > I am also having problems inputing with the param > I have tried Mechanize. There are no problems with getting data only > posting. > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > ... 'User-Agent':'Mozilla/4.0', > ... 'Content-Length':'7'} > >>> conn = httplib.HTTPConnection("www.google.com") > >>> conn.request("POST","/search",params,headers) > >>> r2 = conn.getresponse() > >>> print r2.status, r2.reason > 405 Method Not Allowed > > Regards, > Dhaval From mdw at distorted.org.uk Wed Jan 14 04:37:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 14 Jan 2009 09:37:28 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > Ah! (say I) but assignment in C and Pascal looks different from the way > > it looks in C > > I'm sorry, that confuses me. Assignment in C looks different from the way > it looks in C? I guess the second C should be Python. Yes, you're right. Stupid mistake on my part. -- [mdw] From mdw at distorted.org.uk Wed Jan 14 04:51:10 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 14 Jan 2009 09:51:10 +0000 (UTC) Subject: why cannot assign to function call References: <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: Aaron Brady wrote: > On Jan 13, 5:06 pm, Mark Wooding wrote: > snip > > I'm going to move away from the formal semantics stuff and try a > > different tack. Here's what I think is the defining property of > > pass-by-value (distilled from the formal approach I described earlier, > > but shorn of the symbolism): > > > > The callee's parameters are /new variables/, initialized /as if by > > assignment/ from the values of caller's argument expressions. > > In other words, the same as assignment in that language. It's the same as assignment of /values/ to /fresh variables/. It's important to specify that argument expressions are fully evaluated, and that nothing gets overwritten in the process. So the difference between Python and C is that C copies values during assignment, but Python doesn't. Therefore the argument passing works the same way. > > Because its argument passing works the same way as its assignment. > > That would be called pass-by-assignment. But you've just postponed > explaining yourself. Stop delegating and work. Huh? I'm really at a loss to know what you want me to do. I can't help it if people are confused over the phrase `pass-by-value', beyond trying to explain what it means using clear definitions. The `value' part means that argument expressions are /evaluated/ (turned into values), which forces applicative-order semantics rather than (say) normal-order. -- [mdw] From hackingkk at gmail.com Wed Jan 14 04:51:38 2009 From: hackingkk at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 15:21:38 +0530 Subject: initialising a class by name In-Reply-To: References: <1231912018.7570.22.camel@krishna-laptop> Message-ID: <1231926698.7570.53.camel@krishna-laptop> On Wed, 2009-01-14 at 04:09 -0500, Steve Holden wrote: > > > You don't need to have the names of the classes related to anything in > the interface. Just use a list of classes, and have the user interface > return the correct index for each class. Then (supposing the selection > by the user is seln) use > > Books = classes[seln]() > > If the classes are all in different modules, import them before creating > the list of classes. > Is there a way to get the list of all the classes in the package? I mean is there a way to build a list of modules from some global variable which can be accessed and then looped through. happy hacking. Krishnakant. > regards > Steve From koranthala at gmail.com Wed Jan 14 04:53:10 2009 From: koranthala at gmail.com (koranthala at gmail.com) Date: Wed, 14 Jan 2009 01:53:10 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Message-ID: <33c76d13-1617-4bd0-8bcf-f19950169655@v5g2000pre.googlegroups.com> On Jan 14, 2:21?pm, koranth... at gmail.com wrote: > Does google accept POST? > > Anyways, if you dont need to post files, you can use urlencode itself. > def encode_formdata(fields): > ? ? ? ? body = urllib.urlencode(dict()) > ? ? ? ? content_type = "application/x-www-form-urlencoded" > ? ? ? ? return content_type, body > > If you need to post files too, then you will have to use multipart > data > def encode_multipart_formdata(fields, files): > ? ? """ > ? ? fields is a sequence of (name, value) elements for regular form > fields. > ? ? files is a sequence of (name, filename, value) elements for data > to be uploaded as files > ? ? Return (content_type, body) ready for httplib.HTTP instance > ? ? """ > ? ? BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' > ? ? CRLF = '\r\n' > ? ? L = [] > ? ? for (key, value) in fields: > ? ? ? ? L.append('--' + BOUNDARY) > ? ? ? ? L.append('Content-Disposition: form-data; name="%s"' % key) > ? ? ? ? L.append('') > ? ? ? ? L.append(value) > ? ? for (key, filename, value) in files: > ? ? ? ? L.append('--' + BOUNDARY) > ? ? ? ? L.append('Content-Disposition: form-data; name="%s"; > filename="%s"' % (key, filename)) > ? ? ? ? L.append('Content-Type: %s' % mimetypes.guess_type(filename) > [0] or 'application/octet-stream' > ? ? ? ? L.append('') > ? ? ? ? L.append(value) > ? ? L.append('--' + BOUNDARY + '--') > ? ? L.append('') > ? ? body = CRLF.join(L) > ? ? content_type = 'multipart/form-data; boundary=%s' % BOUNDARY > ? ? return content_type, body > > Since POST files doesnt work with urllib, you might have to use > httplib - or go for very high level tools like twisted. > I here show an example with httplib. > > def post(host, selector, fields, files): > ? ? if files: > ? ? ? ?content_type, body = encode_multipart_formdata(fields, files) > ? ? else: > ? ? ? ?content_type, body = encode_formdata(fields) > > ? ? h = httplib.HTTPConnection(host) > ? ? #Spoof Mozilla > ? ? headers = { > ? ? ? ? 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; > rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', > ? ? ? ? 'Content-Type': content_type > ? ? ? ? } > ? ? h.request('POST', selector, body, headers) > ? ? res = h.getresponse() > ? ? return res.status, res.reason, res.read() > > Please note that you can use multipart whether or not files are there, > but parsing multipart usually is slower. > > Hope this helps. > > lilanidha... at gmail.com wrote: > > Hi, > > > I need one complete example of how to do a http post to any site. > > I have tried making a POST to google but all I am returned with is a > > 405 error. > > I don't want to use Pygoogle as I want to try and do this with other > > sites. > > I am also having problems inputing with the param > > I have tried Mechanize. There are no problems with getting data only > > posting. > > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > > ... ? ? ? ? 'User-Agent':'Mozilla/4.0', > > ... ? ? ? ? 'Content-Length':'7'} > > >>> conn = httplib.HTTPConnection("www.google.com") > > >>> conn.request("POST","/search",params,headers) > > >>> r2 = ?conn.getresponse() > > >>> print r2.status, r2.reason > > 405 Method Not Allowed > > > Regards, > > Dhaval > > oops - Forgot to mention that POSTing files mechanism is taken from a recipe in active state - http://code.activestate.com/recipes/146306/ From lilanidhaval at gmail.com Wed Jan 14 04:53:27 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 01:53:27 -0800 (PST) Subject: PYTHON HTTP POST References: <33f3940e-9f8b-4850-842b-3df5937905bb@k18g2000yqj.googlegroups.com> <59a46f09-58c8-489a-9d11-0f616d383946@t39g2000prh.googlegroups.com> Message-ID: The action part of the field is not set to anything. I need any site with working example that accepts POST. On Jan 14, 2:21 pm, koranth... at gmail.com wrote: > Does google accept POST? > > Anyways, if you dont need to post files, you can use urlencode itself. > def encode_formdata(fields): > body = urllib.urlencode(dict()) > content_type = "application/x-www-form-urlencoded" > return content_type, body > > If you need to post files too, then you will have to use multipart > data > def encode_multipart_formdata(fields, files): > """ > fields is a sequence of (name, value) elements for regular form > fields. > files is a sequence of (name, filename, value) elements for data > to be uploaded as files > Return (content_type, body) ready for httplib.HTTP instance > """ > BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' > CRLF = '\r\n' > L = [] > for (key, value) in fields: > L.append('--' + BOUNDARY) > L.append('Content-Disposition: form-data; name="%s"' % key) > L.append('') > L.append(value) > for (key, filename, value) in files: > L.append('--' + BOUNDARY) > L.append('Content-Disposition: form-data; name="%s"; > filename="%s"' % (key, filename)) > L.append('Content-Type: %s' % mimetypes.guess_type(filename) > [0] or 'application/octet-stream' > L.append('') > L.append(value) > L.append('--' + BOUNDARY + '--') > L.append('') > body = CRLF.join(L) > content_type = 'multipart/form-data; boundary=%s' % BOUNDARY > return content_type, body > > Since POST files doesnt work with urllib, you might have to use > httplib - or go for very high level tools like twisted. > I here show an example with httplib. > > def post(host, selector, fields, files): > if files: > content_type, body = encode_multipart_formdata(fields, files) > else: > content_type, body = encode_formdata(fields) > > h = httplib.HTTPConnection(host) > #Spoof Mozilla > headers = { > 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; > rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4', > 'Content-Type': content_type > } > h.request('POST', selector, body, headers) > res = h.getresponse() > return res.status, res.reason, res.read() > > Please note that you can use multipart whether or not files are there, > but parsing multipart usually is slower. > > Hope this helps. > > lilanidha... at gmail.com wrote: > > Hi, > > > I need one complete example of how to do a http post to any site. > > I have tried making a POST to google but all I am returned with is a > > 405 error. > > I don't want to use Pygoogle as I want to try and do this with other > > sites. > > I am also having problems inputing with the param > > I have tried Mechanize. There are no problems with getting data only > > posting. > > > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1', > > ... 'User-Agent':'Mozilla/4.0', > > ... 'Content-Length':'7'} > > >>> conn = httplib.HTTPConnection("www.google.com") > > >>> conn.request("POST","/search",params,headers) > > >>> r2 = conn.getresponse() > > >>> print r2.status, r2.reason > > 405 Method Not Allowed > > > Regards, > > Dhaval From hubaghdadi at gmail.com Wed Jan 14 04:54:11 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 01:54:11 -0800 (PST) Subject: Why this code is working? Message-ID: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Hey, Why this code is working? >>> def f1( ): ... x = 88 ... f2(x) ... >>> def f2(x): ... print x ... >>> f1( ) 88 Thanks. From pavlovevidence at gmail.com Wed Jan 14 04:54:31 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 01:54:31 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: On Jan 14, 2:44?am, "Russ P." wrote: > On Jan 13, 11:51?pm, Paul Rubin wrote: > > > Carl Banks writes: > > > At GE there was no encapsulation in sight on any system I worked on. > > > In fact, our engine simulation was a special-purpose object-oriented > > > language with--get this--no private variables. ?Some other systems I > > > worked on didn't even use scoping, let alone encapsulation. > > > Where my officemate used to work, the simulation stuff was written in > > Matlab, but the actual flight stuff was written in Ada. ?I wonder > > if GE did something similar. > > I was going to suggest the same thing. I thought you were done wasting time with this nonsense. > An engine *simulation* is one > thing; the actual engine control code is another. Guess what systems I worked on that didn't even use scoping? I wrote code for the GP7000 (equipped on some Airbus 380s) and the F-136 (which will be equipped on some F-35 fighters) engine controllers. Neither one used any data hiding. The language was C (not C++), but it was generated from schematic diagrams. Would you like to adopt GE's practice of schematic-generated C with no namespaces or data hiding? No? Then don't be telling me I have to embrace Boeing's. Carl Banks From krmane at gmail.com Wed Jan 14 04:55:27 2009 From: krmane at gmail.com (Krishnakant) Date: Wed, 14 Jan 2009 15:25:27 +0530 Subject: initialising a class by name In-Reply-To: <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901132151o5438c258iab5b65794b8a63b8@mail.gmail.com> <1231919363.7570.27.camel@krishna-laptop> <50697b2c0901132355r3705bf5dse5f028ad1bf2c4b1@mail.gmail.com> <1231920905.7570.40.camel@krishna-laptop> <50697b2c0901140020k6aa5da68m54ba8cf235ecb0fa@mail.gmail.com> <1231922209.7570.49.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> Message-ID: <1231926927.7570.55.camel@krishna-laptop> On Wed, 2009-01-14 at 00:39 -0800, Chris Rebert wrote: > On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > >> Aside from Steven's excellent idea, to use the getattr() technique > >> with your module scheme you'd probably also need to use __import__() > >> to dynamically import the right module. > >> > > I would generally import all the modules I would need at the top of the > > main module. > > then would use getattr(module,class_name) will that work? > > Yes, that is how you'd do it in that case. > By the way, is there a kind of global list of modules/classes which are maintained in a package once the program is loaded into memory? happy hacking. Krishnakant. > Cheers, > Chris > -- > Follow the path of the Iguana... > http://rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 04:55:47 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 10:55:47 +0100 Subject: Why this code is working? In-Reply-To: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Message-ID: <496db69d$0$20355$426a34cc@news.free.fr> Hussein B a ?crit : > Hey, > Why this code is working? > >>>> def f1( ): > ... x = 88 > ... f2(x) > ... >>>> def f2(x): > ... print x > ... >>>> f1( ) > 88 > Well... Because it is correct ? What make you think it _shouldn't_ work ? From joost.ruyter at gmail.com Wed Jan 14 04:55:58 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 01:55:58 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> Message-ID: <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Hi John, thanks a lot for your quick reply! I tried all of your suggestions but none of them work... I have a clue on why it is failing: MySQLdb seems to quote the % characters or something... Even when i do: cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is null and fieldy like '%therealvalue%' " or: cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is null and fieldy like '%%therealvalue%%' " # escaping the % it is not updating the database... Maybe I am completely overlooking something, but I am pretty lost here... Googling this it seems as if no one is using "LIKE '%value%'" type queries with Python & mySQL... Anyone any other thoughts? regards, Joost On 14 jan, 10:14, John Machin wrote: > On Jan 14, 7:31 pm, gumbah wrote: > > > I have this really strange problem. I hope someone can help: > > > I am trying to update a database like so: > > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > > like '%certainvalue%' > > > My Python code looks like this: > > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > > and fieldy like '%%%s%%' " % certainvalue > > call this trial 1 > > > print fillsql > > cursor.execute(fillsql) > > > #also tried: > > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > > null and fieldy like %s ", "%%%s%%" % certainvalue) > > call this trial 2 > > > > > But it doesn't work... But when i copy and past the SQL (printed by > > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! > > You don't say what "doesn't work" means ... did you get exceptions, or > just silently not updating? > > > > > Can anyone tell me what i am doing wrong?? > > Well the "trial 1" method is guaranteed not to work if certainvalue > contains an apostrophe e.g. "O'Reilly". In any case, you should never > build your own SQL statement like that; use the "trial 2" method -- it > will do whatever is necessary in the way of reformatting or escaping > your input. > > I know near nothing about mySQLdb, but here are some comments based on > general SQL experience: > (1) `tablename` isn't SQL syntax that I've seen before; perhaps it > works in phpMyAdmin but not in cursor.execute() > (2) similarly = NULL ... I'd expect IS NULL > (3) It is updating but your script and your phpMyAdmin session are > pointing at different instances of the database > (4) For trial 2 method, shouldn't the 2nd arg of cursor.execute() > should be a sequence e.g. ("%%%s%%" % certainvalue, ) ? > > HTH > John From hubaghdadi at gmail.com Wed Jan 14 04:57:48 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 01:57:48 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> Message-ID: <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> On Jan 14, 11:55?am, Bruno Desthuilliers wrote: > Hussein B a ?crit : > > > Hey, > > Why this code is working? > > >>>> def f1( ): > > ... ? ? ?x = 88 > > ... ? ? ?f2(x) > > ... > >>>> def f2(x): > > ... ? ? ?print x > > ... > >>>> f1( ) > > 88 > > Well... Because it is correct ? > > What make you think it _shouldn't_ work ? Because def2 is defined after def1 in an interpreted language, not compiled. From __peter__ at web.de Wed Jan 14 04:59:31 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jan 2009 10:59:31 +0100 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> Message-ID: Hussein B wrote: > Why this code is working? > >>>> def f1( ): > ... x = 88 > ... f2(x) > ... >>>> def f2(x): > ... print x > ... >>>> f1( ) > 88 The name 'f2' is not resolved once when the f1 function is created. Instead Python looks for a global name 'f2' each time f1 is executed. Peter From __peter__ at web.de Wed Jan 14 05:06:26 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jan 2009 11:06:26 +0100 Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: gumbah wrote: > I tried all of your suggestions but none of them work... I have a clue > on why it is failing: MySQLdb seems to quote the % characters or > something... > > Even when i do: > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > null and fieldy like '%therealvalue%' " > it is not updating the database... > > Maybe I am completely overlooking something, but I am pretty lost > here... Googling this it seems as if no one is using "LIKE '%value%'" > type queries with Python & mySQL... > > Anyone any other thoughts? Did you call the connection object's commit() method? Peter From joost.ruyter at gmail.com Wed Jan 14 05:14:09 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 02:14:09 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> Yep, also tried that. Weird thing is that I get no errors, it's just silently not updating... On 14 jan, 11:06, Peter Otten <__pete... at web.de> wrote: > gumbah wrote: > > I tried all of your suggestions but none of them work... I have a clue > > on why it is failing: MySQLdb seems to quote the % characters or > > something... > > > Even when i do: > > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > > null and fieldy like '%therealvalue%' " > > it is not updating the database... > > > Maybe I am completely overlooking something, but I am pretty lost > > here... Googling this it seems as if no one is using "LIKE '%value%'" > > type queries with Python & mySQL... > > > Anyone any other thoughts? > > Did you call the connection object's commit() method? > > Peter From staaleu at gmail.com Wed Jan 14 05:20:50 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 02:20:50 -0800 (PST) Subject: Parent module not loaded error Message-ID: I have a pretty strange error that I can't figure out the cause off. This is in a Django app. I am using berkelydb, with secondary databases for indexing. The secondary databases are associated with a callback that uses cPickle to serialize index values. The problem is that cPickle.dumps(value) fails when I run it through mod_wsgi or mod_python on the deployment server (Ubuntu Linux 8.10), but works fine when when I use Djangos runserver on the same computer. Also, on my own computer (Ubuntu Linux 8.10), it works fine through mod_python. Each time I call on cPickle.dumps(value) I get: SystemError("Parent module 'd4' not loaded",) Using sys.exc_info() I get no type or traceback, just that exception. The callstack as far as I can figure is: django view bsddb.put indexer callback cPickle.dumps cPickle.loads works fine within the callback, I can also use cPickle.dumps() outside the indexer callback. But inside the callback, I need to use normal pickle instead. I just want to know why. I am assuming it has something to do with the fact that I go from python to C (bsddb) back to python (indexer callback) and back to C (cPickle). It is still strange then that cPickle.loads() work, but not cPickle.dumps(). I am also only storing integer values when I get this error, so no fancy list, dictionaries or objects. From joost.ruyter at gmail.com Wed Jan 14 05:22:42 2009 From: joost.ruyter at gmail.com (gumbah) Date: Wed, 14 Jan 2009 02:22:42 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> Message-ID: <1716d5bb-d0bc-40e6-95da-5041af8fc064@g1g2000pra.googlegroups.com> Aahh the conn.commit() DID the trick!! I tried that before, but then it failed at another point. I got it working now! Thanks a lot Peter and John!! cheers! On 14 jan, 11:14, gumbah wrote: > Yep, also tried that. Weird thing is that I get no errors, it's just > silently not updating... > > On 14 jan, 11:06, Peter Otten <__pete... at web.de> wrote: > > > gumbah wrote: > > > I tried all of your suggestions but none of them work... I have a clue > > > on why it is failing: MySQLdb seems to quote the % characters or > > > something... > > > > Even when i do: > > > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > > > null and fieldy like '%therealvalue%' " > > > it is not updating the database... > > > > Maybe I am completely overlooking something, but I am pretty lost > > > here... Googling this it seems as if no one is using "LIKE '%value%'" > > > type queries with Python & mySQL... > > > > Anyone any other thoughts? > > > Did you call the connection object's commit() method? > > > Peter From davide.picca at gmail.com Wed Jan 14 05:25:52 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 02:25:52 -0800 (PST) Subject: os system command not found Message-ID: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Hi all! I installed a external program called infomap using the classical procedure ./configure make sudo make install and it works perfectly in Terminal (Os x) using both bash and tcsh shell admins-macbook-pro-2:~ unil$ infomap-build Usage: infomap-build [-w working_dir] [-p param_file] [-D var_1=val_1 ... -D var_N=val_N] (-s single_corpus_file | -m multi_file_list) but when I call it from python using os.system or subprocess.call I get the message "sh: infomap-build: command not found". Do you know why? Many thanks Davide From w.richert at gmx.net Wed Jan 14 05:26:39 2009 From: w.richert at gmx.net (Willi Richert) Date: Wed, 14 Jan 2009 11:26:39 +0100 Subject: initialising a class by name In-Reply-To: <1231926927.7570.55.camel@krishna-laptop> References: <1231912018.7570.22.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> <1231926927.7570.55.camel@krishna-laptop> Message-ID: <200901141126.39366.w.richert@gmx.net> Hi, try the following exemplarily for the os module import os, types [(c, klass) for (c,klass) in os.__dict__.items() if type(klass)==types.ClassType] will print: [('_Environ', )] Regards, wr Am Mittwoch, 14. Januar 2009 10:55:27 schrieb Krishnakant: > On Wed, 2009-01-14 at 00:39 -0800, Chris Rebert wrote: > > On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant wrote: > > > On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote: > > >> Aside from Steven's excellent idea, to use the getattr() technique > > >> with your module scheme you'd probably also need to use __import__() > > >> to dynamically import the right module. > > > > > > I would generally import all the modules I would need at the top of the > > > main module. > > > then would use getattr(module,class_name) will that work? > > > > Yes, that is how you'd do it in that case. > > By the way, is there a kind of global list of modules/classes which are > maintained in a package once the program is loaded into memory? > happy hacking. > Krishnakant. > > > Cheers, > > Chris > > -- > > Follow the path of the Iguana... > > http://rebertia.com > > -- > http://mail.python.org/mailman/listinfo/python-list From Graham.Dumpleton at gmail.com Wed Jan 14 05:31:59 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 14 Jan 2009 02:31:59 -0800 (PST) Subject: Parent module not loaded error References: Message-ID: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> On Jan 14, 9:20?pm, St?le Undheim wrote: > I have a pretty strange error that I can't figure out the cause off. > This is in a Django app. > > I am using berkelydb, with secondary databases for indexing. The > secondary databases are associated with a callback that uses cPickle > to serialize index values. The problem is that cPickle.dumps(value) > fails when I run it throughmod_wsgior mod_python on the deployment > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > runserver on the same computer. Also, on my own computer (Ubuntu Linux > 8.10), it works fine through mod_python. > > Each time I call on cPickle.dumps(value) I get: > SystemError("Parent module 'd4' not loaded",) > > Using sys.exc_info() I get no type or traceback, just that exception. > The callstack as far as I can figure is: > > django > view > bsddb.put > indexer callback > cPickle.dumps > > cPickle.loads works fine within the callback, I can also use > cPickle.dumps() outside the indexer callback. But inside the callback, > I need to use normal pickle instead. I just want to know why. I am > assuming it has something to do with the fact that I go from python to > C (bsddb) back to python (indexer callback) and back to C (cPickle). > It is still strange then that cPickle.loads() work, but not > cPickle.dumps(). I am also only storing integer values when I get this > error, so no fancy list, dictionaries or objects. Where is module 'd4'? Is that one of yours defined inside of your Django project? One of the problems with Django runserver is that the parent of the site directory and the site directory are effectively starting points for searching for modules, even though neither is explicitly listed in sys.path. The parent is used because runserver does momentarily add parent to sys.path to import site package root, after which it removes directory from sys.path. The site directory itself is used because for runserver that is the current working directory and imports look there automatically. End result is that modules inside of site can be imported either via site package root, or direct. For example, if d4.py was at same level as settings.py file and site was called mysite, you could import it as mysite.d4 or just d4. This is bad because means you could end up with two copies of a module imported under the different name references. If they way the pickle was done in application was such that reference was via d4, and then when you deployed to mod_python or mod_wsgi you only added parent directory of site to Python path, then it will not be able to find d4, since at that point would only be found as mysite.d4. If this is the case, add the site directory to Python path by setting PythonPath for mod_python or sys.path in WSGI script file for mod_wsgi. Better still, fix up your code so module references in code, ie., urls.py, or anywhere else, are always done by site package root reference and not direct. Ie., such that it uses mysite.d4 and not just d4. Would that seem about right? Graham From db3l.net at gmail.com Wed Jan 14 05:34:48 2009 From: db3l.net at gmail.com (David Bolen) Date: Wed, 14 Jan 2009 05:34:48 -0500 Subject: Implementing file reading in C/Python References: <9fri36xno7.ln2@joeserver.homelan.net> <6soit7F7bavsU1@mid.uni-berlin.de> Message-ID: Johannes Bauer writes: > Yup, I changed the Python code to behave the same way the C code did - > however overall it's not much of an improvement: Takes about 15 minutes > to execute (still factor 23). Not sure this is completely fair if you're only looking for a pure Python solution, but to be honest, looping through a gazillion individual bytes of information sort of begs for trying to offload that into a library that can execute faster, while maintaining the convenience of Python outside of the pure number crunching. I'd assume numeric/numpy might have applicable functions, but I don't use those libraries much, whereas I've been using OpenCV recently for a lot of image processing work, and it has matrix/histogram support, which seems to be a good match for your needs. For example, assuming the OpenCV library and ctypes-opencv wrapper, add the following before the file I/O loop: from opencv import * # Histogram for each file chunk hist = cvCreateHist([256], CV_HIST_ARRAY, [(0,256)]) then, replace (using one of your posted methods as a sample): datamap = { } for i in data: datamap[i] = datamap.get(i, 0) + 1 array = sorted([(b, a) for (a, b) in datamap.items()], reverse=True) most = ord(array[0][1]) with: matrix = cvMat(1, len(data), CV_8UC1, data) cvCalcHist([matrix], hist) most = cvGetMinMaxHistValue(hist, min_val = False, max_val = False, min_idx = False, max_idx = True) should give you your results in a fraction of the time. I didn't run with a full size data file, but for a smaller one using smaller chunks the OpenCV varient ran in about 1/10 of the time, and that was while leaving all the other remaining Python code in place. Note that it may not be identical results to some of your other methods in the case of multiple values with the same counts, as the OpenCV histogram min/max call will always pick the lower value in such cases, whereas some of your code (such as above) will pick the upper value, or your original code depended on the order of information returned by dict.items. This sort of small dedicated high performance choke point is probably also perfect for something like Pyrex/Cython, although that would require a compiler to build the extension for the histogram code. -- David From staaleu at gmail.com Wed Jan 14 05:41:30 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 02:41:30 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> Message-ID: On Jan 14, 11:31?am, Graham Dumpleton wrote: > On Jan 14, 9:20?pm, St?le Undheim wrote: > > > > > I have a pretty strange error that I can't figure out the cause off. > > This is in a Django app. > > > I am using berkelydb, with secondary databases for indexing. The > > secondary databases are associated with a callback that uses cPickle > > to serialize index values. The problem is that cPickle.dumps(value) > > fails when I run it throughmod_wsgior mod_python on the deployment > > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > > runserver on the same computer. Also, on my own computer (Ubuntu Linux > > 8.10), it works fine through mod_python. > > > Each time I call on cPickle.dumps(value) I get: > > SystemError("Parent module 'd4' not loaded",) > > > Using sys.exc_info() I get no type or traceback, just that exception. > > The callstack as far as I can figure is: > > > django > > view > > bsddb.put > > indexer callback > > cPickle.dumps > > > cPickle.loads works fine within the callback, I can also use > > cPickle.dumps() outside the indexer callback. But inside the callback, > > I need to use normal pickle instead. I just want to know why. I am > > assuming it has something to do with the fact that I go from python to > > C (bsddb) back to python (indexer callback) and back to C (cPickle). > > It is still strange then that cPickle.loads() work, but not > > cPickle.dumps(). I am also only storing integer values when I get this > > error, so no fancy list, dictionaries or objects. > > Where is module 'd4'? Is that one of yours defined inside of your > Django project? > d4 is the root project name. This message occurs in d4/views.py. Here is how I set up my wsgi.py - which is in the d4/ folder: sys.path.append(path.join(path.dirname(__file__), '..')) os.environ['DJANGO_SETTINGS_MODULE'] = 'd4.settings' application = django.core.handlers.wsgi.WSGIHandler() > One of the problems with Django runserver is that the parent of the > site directory and the site directory are effectively starting points > for searching for modules, even though neither is explicitly listed in > sys.path. The parent is used because runserver does momentarily add > parent to sys.path to import site package root, after which it removes > directory from sys.path. The site directory itself is used because for > runserver that is the current working directory and imports look there > automatically. > > End result is that modules inside of site can be imported either via > site package root, or direct. For example, if d4.py was at same level > as settings.py file and site was called mysite, you could import it as > mysite.d4 or just d4. This is bad because means you could end up with > two copies of a module imported under the different name references. Everywhere in the code, the imports refer to d4.something.something. All urls.py files refer to the full package names. The test code where I am running this is actually quit minimal. > If they way the pickle was done in application was such that reference > was via d4, and then when you deployed to mod_python or mod_wsgi you > only added parent directory of site to Python path, then it will not > be able to find d4, since at that point would only be found as > mysite.d4. > I use "import cPickle as pickle" at the top off my views file. So I don't reference imports from other files. > If this is the case, add the site directory to Python path by setting > PythonPath for mod_python or sys.path in WSGI script file for > mod_wsgi. Better still, fix up your code so module references in code, > ie., urls.py, or anywhere else, are always done by site package root > reference and not direct. Ie., such that it uses mysite.d4 and not > just d4. > > Would that seem about right? Unfortunatly, at least to me, it seems that all code is allready correctly using packagenames. The views.py file where I am testing this is a simple file that doesn't depend on anything else in the project. It only imports a set of system modules for testing and info. The only "dependency" is really the urls.py file, which does refer to all the views as "d4.views.somemethod". From steve at holdenweb.com Wed Jan 14 05:42:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 05:42:09 -0500 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <496DC181.7090601@holdenweb.com> gumbah wrote: > I have this really strange problem. I hope someone can help: > > I am trying to update a database like so: > > UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy > like '%certainvalue%' > > My Python code looks like this: > > fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null > and fieldy like '%%%s%%' " % certainvalue > print fillsql > cursor.execute(fillsql) > > #also tried: > #cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx = > null and fieldy like %s ", "%%%s%%" % certainvalue) > > But it doesn't work... But when i copy and past the SQL (printed by > "print fillsql" line) and execute that in phpMyAdmin, it does work!!! > > Can anyone tell me what i am doing wrong?? > 1. You can't test for equality with NULL. 2. You don't have quote marks around the LIKE argument. cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx IS NULL and fieldy like '%s' ", "%%%s%%" % certainvalue) *might* work. 3. I can't be certain my experience with PostgreSQL extends to MySQl, but I have done experiments which prove to my satisfaction that it isn't possible to parameterize LIKE arguments. So the only way to do it appears to be to build the query yourself. This means that you will need to make sure the string is made "safe", typically by replacing each occurrence of the string "'" with "''" to retain the syntactic integrity of the SQL statement. So finally, try cursor.execute("""UPDATE tablename set fieldx='test' WHERE flfieldx IS NULL AND fieldy LIKE '%%%s%%'""" % certainvalue.replace("'", "''")) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From divinekid at gmail.com Wed Jan 14 05:43:12 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Wed, 14 Jan 2009 18:43:12 +0800 Subject: [ANN] SWIG 1.3.37 Message-ID: <1d7983e80901140243n4a2d9edcme8846092d7144a9d@mail.gmail.com> This is the SWIG with Python 3.0 support! :) *** ANNOUNCE: SWIG 1.3.37 (13 January 2009) *** http://www.swig.org We're pleased to announce SWIG-1.3.37, the latest installment in the SWIG development effort. SWIG-1.3.37 includes a number of bug fixes and enhancements. What is SWIG? ------------- SWIG is a software development tool that reads C/C++ header files and generates the wrapper code needed to make C and C++ code accessible from other languages including Perl, Python, Tcl, Ruby, PHP, Java, Scheme (Guile, MzScheme, CHICKEN), Ocaml, Lua, Pike, C#, Modula-3, Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI). SWIG can also export its parse tree in the form of XML and Lisp s-expressions. Major applications of SWIG include generation of scripting language extension modules, rapid prototyping, testing, and user interface development for large C/C++ systems. Availability: ------------- The release is available for download on Sourceforge at http://prdownloads.sourceforge.net/swig/swig-1.3.37.tar.gz A Windows version is also available at http://prdownloads.sourceforge.net/swig/swigwin-1.3.37.zip What's New? =========== SWIG-1.3.37 summary: - Python 3 support added - SWIG now ships with a version of ccache that can be used with SWIG. This enables the files generated by SWIG to be cached so that repeated use of SWIG on unchanged input files speeds up builds quite considerably. - PHP 4 support removed and PHP support improved in general - Improved C# array support - Numerous Allegro CL improvements - Bug fixes/enhancements for Python, PHP, Java, C#, Chicken, Allegro CL, CFFI, Ruby, Tcl, Perl, R, Lua. - Other minor generic bug fixes and enhancements Release numbers --------------- With SWIG-1.3, we are adopting an odd/even version numbering scheme for SWIG. Odd version numbers (1.3, 1.5, 1.7, etc...) are considered to be development releases. Even numbers (1.4,1.6,1.8) are stable releases. The current 1.3 effort is working to produce a stable 2.0 release. A stable 2.0 release will not be made until it can accompanied by fully updated documentation. In the meantime, we will continue to make periodic 1.3.x releases. Please report problems with this release to the swig-dev mailing list, details at http://www.swig.org/mail.html. --- The SWIG Developers From Graham.Dumpleton at gmail.com Wed Jan 14 05:48:37 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 14 Jan 2009 02:48:37 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> Message-ID: <9d4373c9-2cab-4eee-a2ad-dfd4398abe40@z28g2000prd.googlegroups.com> On Jan 14, 9:41?pm, St?le Undheim wrote: > On Jan 14, 11:31?am, Graham Dumpleton > wrote: > > > > > On Jan 14, 9:20?pm, St?le Undheim wrote: > > > > I have a pretty strange error that I can't figure out the cause off. > > > This is in a Django app. > > > > I am using berkelydb, with secondary databases for indexing. The > > > secondary databases are associated with a callback that uses cPickle > > > to serialize index values. The problem is that cPickle.dumps(value) > > > fails when I run it throughmod_wsgior mod_python on the deployment > > > server (Ubuntu Linux 8.10), but works fine when when I use Djangos > > > runserver on the same computer. Also, on my own computer (Ubuntu Linux > > > 8.10), it works fine through mod_python. > > > > Each time I call on cPickle.dumps(value) I get: > > > SystemError("Parent module 'd4' not loaded",) > > > > Using sys.exc_info() I get no type or traceback, just that exception. > > > The callstack as far as I can figure is: > > > > django > > > view > > > bsddb.put > > > indexer callback > > > cPickle.dumps > > > > cPickle.loads works fine within the callback, I can also use > > > cPickle.dumps() outside the indexer callback. But inside the callback, > > > I need to use normal pickle instead. I just want to know why. I am > > > assuming it has something to do with the fact that I go from python to > > > C (bsddb) back to python (indexer callback) and back to C (cPickle). > > > It is still strange then that cPickle.loads() work, but not > > > cPickle.dumps(). I am also only storing integer values when I get this > > > error, so no fancy list, dictionaries or objects. > > > Where is module 'd4'? Is that one of yours defined inside of your > > Django project? > > d4 is the root project name. This message occurs in d4/views.py. > > Here is how I set up my wsgi.py - which is in the d4/ folder: > ? sys.path.append(path.join(path.dirname(__file__), '..')) > > ? os.environ['DJANGO_SETTINGS_MODULE'] = 'd4.settings' > ? application = django.core.handlers.wsgi.WSGIHandler() > > > One of the problems with Django runserver is that the parent of the > > site directory and the site directory are effectively starting points > > for searching for modules, even though neither is explicitly listed in > > sys.path. The parent is used because runserver does momentarily add > > parent to sys.path to import site package root, after which it removes > > directory from sys.path. The site directory itself is used because for > > runserver that is the current working directory and imports look there > > automatically. > > > End result is that modules inside of site can be imported either via > > site package root, or direct. For example, if d4.py was at same level > > as settings.py file and site was called mysite, you could import it as > > mysite.d4 or just d4. This is bad because means you could end up with > > two copies of a module imported under the different name references. > > Everywhere in the code, the imports refer to d4.something.something. > All urls.py files refer to the full package names. The test code where > I am running this is actually quit minimal. > > > If they way the pickle was done in application was such that reference > > was via d4, and then when you deployed to mod_python or mod_wsgi you > > only added parent directory of site to Python path, then it will not > > be able to find d4, since at that point would only be found as > > mysite.d4. > > I use "import cPickle as pickle" at the top off my views file. So I > don't reference imports from other files. > > > If this is the case, add the site directory to Python path by setting > > PythonPath for mod_python or sys.path in WSGI script file for > > mod_wsgi. Better still, fix up your code so module references in code, > > ie., urls.py, or anywhere else, are always done by site package root > > reference and not direct. Ie., such that it uses mysite.d4 and not > > just d4. > > > Would that seem about right? > > Unfortunatly, at least to me, it seems that all code is allready > correctly using packagenames. The views.py file where I am testing > this is a simple file that doesn't depend on anything else in the > project. It only imports a set of system modules for testing and info. > The only "dependency" is really the urls.py file, which does refer to > all the views as "d4.views.somemethod". As a test, just prior to where unpickle is done, do: import sys import d4 print >> sys.stderr, "d4.__name__", dr.__name__ print >> sys.stderr, "d4.__file__", dr.__file__ This will just confirm that manual import works and what values of those attributes are. The messages will end up in Apache error log for that virtual host or main server error log as appropriate. Graham From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 05:49:51 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 11:49:51 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> Message-ID: <496dc349$0$21349$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > I think the issue here is the distinction between hacking and software > engineering. I may be misusing the term "hacking," but I do not mean > it in a pejoritive sense. I just mean getting things done fast without > a lot of concern for safety, security, and long-term maintainability > and scalability. I do feel concerned by these issues. > I'm not a computer scientist, but it seems to me that > Python is great for hacking and good for software engineering, but it > is not ideal for software engineering. > > What Paul is suggesting, I think, is that Python should move in the > direction of software engineering. Whether that can be done without > compromising its hacking versatility is certainly a valid question, > but if it can be done, then why not do it? > > Certainly one basic principle of software engineering is data > encapsulation. Tacking new attributes onto class instances all over > the place There's a clear distinction between "making wise use of dynamicity" and "tacking new attributes onto class instances all over the place". > may be convenient and useful in many cases, but it is not > consistent with good software engineering. simplicity is "good software engineering". Accidental complexity is not. Dynamism _can_ greatly reduce accidental complexity. > If the programmer could > somehow disallow it in certain classes, Already possible - you just have to provide your own implementation of __setattr__. > that could be useful, > providing that those who wish to continue doing it would be free to do > so. If class attributes could somehow be declared private, The important point is to make implementation distinct from interface - which we already know how to do -, and sometimes to prevent _accidental_ overriding of some critical implementation attributes - which is also already implemented. Enforcing access restriction is, from experience, just pointless. """ patient : doctor, when I do this, it hurts doctor : well, don't do it, then. """ From kylotan at gmail.com Wed Jan 14 05:49:57 2009 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 14 Jan 2009 02:49:57 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: On Jan 14, 1:55?am, Ivan Illarionov wrote: > Ben Sizer wrote: > > What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: No, I don't want to do anything with sys.path apart from see it. I just wanted my original question answered, not a guess at my intent and a solution for something I'm not doing. ;) Thanks though! Again - why can I not reference sys from within the function? -- Ben Sizer From bj_666 at gmx.net Wed Jan 14 05:53:33 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 14 Jan 2009 10:53:33 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <6t5uhcF9bu1hU1@mid.uni-berlin.de> On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > >> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. >> wrote: (...) >> >>>> Give me one use-case where you strictly require that members of an >>>> object be private and their access enforced as such ? >>> >>> You're kidding, right? Think about a ten-million line program being >>> developed by 100 developers. >> >> No I"m sorry this is not a valid use-case. > > Why not? Just saying it isn't doesn't make it not. Because "developer" means people who don't mess with implementation details. So they respect the leading underscore convention. No use case for enforced access restriction. Ciao, Marc 'BlackJack' Rintsch From pieterprovoost at gmail.com Wed Jan 14 05:54:21 2009 From: pieterprovoost at gmail.com (pieterprovoost at gmail.com) Date: Wed, 14 Jan 2009 05:54:21 -0500 Subject: problem calling method In-Reply-To: Message-ID: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> The parent is called like this (I didn't copy that line): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) The frame works fine and so does the button, but somehow I cannot call the sendmail method from the event handler... -- James Mills wrote : On Wed, Jan 14, 2009 at 11:28 AM, wrote: > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): It might be helpful here if you called the parent __init__. Like so: class MyFrame(wx.Frame): def __init__(self, *args, **kwds): super(MyFrame, self).__init__(*args, **kwargs) ... cheers James -- -- This message was sent on behalf of pieterprovoost at gmail.com at openSubscriber.com http://www.opensubscriber.com/message/python-list at python.org/11236393.html From sjmachin at lexicon.net Wed Jan 14 05:58:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 02:58:10 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> Message-ID: <6509268d-81c4-479d-869b-264734694a20@s1g2000prg.googlegroups.com> On Jan 14, 8:55?pm, gumbah wrote: > Hi John, > > thanks a lot for your quick reply! Please don't top-post. Please answer the question """You don't say what "doesn't work" means ... did you get exceptions, or just silently not updating?""" > > I tried all of your suggestions but none of them work... I have a clue > on why it is failing: MySQLdb seems to quote the % characters or > something... > > Even when i do: > cursor.execute("UPDATE tablename set fieldx='test' WHERE flfieldx is > null and fieldy like '%therealvalue%' " Please stop stuffing around with the 'trial 1' method. What SQL data type is fieldy? What Python datatype is therealvalue coming from? Do this: print type(realvalue), repr(realvalue) Are you sure that the datatypes are compatible? Is there perhaps a Unicode encoding problem? Try this: cursor.execute("select fieldy from tablename") # dig out a sample result print type(sample_result), repr(sample_result) print therealvalue in sample_result I suggest that you avoid UPDATE and the supersensitive fieldy none of whose values you can reveal, and try the code on a column with simple noncontroversial data e.g. if you have an address table with the U.S. state code in it, we can try a simple query to find all addresses that are in a state that contains some letter: state_letter = "A" sql = "select address_id, state from address where state like %s" cursor.execute(sql, ("%" + state_letter + "%", )) That would be my best shot at getting it to work. It is based on this: http://mail.python.org/pipermail/python-list/2003-August/218382.html If that works, try applying it to a query on fieldy and then to your original problem. Cheers, John From sturlamolden at yahoo.no Wed Jan 14 05:59:22 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 02:59:22 -0800 (PST) Subject: Standard IPC for Python? References: Message-ID: On Jan 13, 5:25 pm, Laszlo Nagy wrote: > I would like to develop some module for Python for IPC. Socket > programming howto recommends that for local communication, and I > personally experienced problems with TCP (see my previous post: "Slow > network"). There are plenty of different IPC mechanisms available in multiprocessing. > I was looking for semaphores and shared memory, but it is not in the > standard lib. Take a look at: - multiprocessing.Array and multiprocessing.Value - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, respectively) - pywin32 on Windows (not standard lib) > I was also thinking about unix domain sockets, but it is > not available under windows. Unix domain sockets are called 'named pipes' under Windows. Look for it in multiprocessing or pywin32. > The question is: what is the standard way to implement fast and portable > IPC with Python? form multiprocessing import Queue From sjmachin at lexicon.net Wed Jan 14 06:08:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 03:08:30 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <38eb5fd7-dd20-4176-9b72-cd73472512ba@i24g2000prf.googlegroups.com> <7b7e3661-6084-4674-9551-6a3451a7ab5b@w1g2000prk.googlegroups.com> <06cd5282-2e62-41fb-903e-8775d834b5f5@x16g2000prn.googlegroups.com> <1716d5bb-d0bc-40e6-95da-5041af8fc064@g1g2000pra.googlegroups.com> Message-ID: On Jan 14, 9:22?pm, gumbah wrote: > Aahh the conn.commit() DID the trick!! > > I tried that before, but then it failed at another point. I got it > working now! Thanks a lot Peter and John!! For the benefit of future searchers, can you please tell us which varieties of cursor.execute() it works on -- copy/paste the code that was run, please, rather than some possibly vague/ambiguous narrative :-) and do please try it using a parameterised method ("trial 2"), because that's much more prefereable to build-your-own SQL ("trial 1") if both work. Cheers, John From lilanidhaval at gmail.com Wed Jan 14 06:11:06 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 03:11:06 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED Message-ID: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Hi, Can someone please give me an example of a working python post? for example using the site http://www.cookiemag.com/ Thanks in advance, Dhaval From lilanidhaval at gmail.com Wed Jan 14 06:19:12 2009 From: lilanidhaval at gmail.com (dhaval) Date: Wed, 14 Jan 2009 03:19:12 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Message-ID: On Jan 14, 4:11 pm, dhaval wrote: > Hi, > > Can someone please give me an example of a working python post? > for example using the sitehttp://www.cookiemag.com/ > > Thanks in advance, > Dhaval I have tried to look at the code at http://code.activestate.com/recipes/146306/ I can't make any sense out of it. From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 06:20:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 11:20:56 GMT Subject: sys.stdout.write()'s bug or doc bug? References: Message-ID: <017dc12e$0$8693$c3e8da3@news.astraweb.com> On Sun, 11 Jan 2009 19:38:48 -0800, Aahz wrote: > In article > , > Qiangning Hong wrote: >> >>So, my question is, as sys.stdout IS a file object, why it does not use >>its encoding attribute to convert the given unicode? An implementation >>bug? A documenation bug? > > Please file a bug on bugs.python.org -- that's the only way this can be > tracked. Done: http://bugs.python.org/issue4947 -- Steven From tjreedy at udel.edu Wed Jan 14 06:29:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Jan 2009 06:29:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. The question is where such checks should be. Guido prefers separate checkers (PyChecker, PyLint) rather than in the interpreter. If you think they are incomplete, help improve one of them. From deets at nospam.web.de Wed Jan 14 06:33:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 12:33:10 +0100 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> Message-ID: <6t60rmF9auodU1@mid.uni-berlin.de> dhaval wrote: > On Jan 14, 4:11 pm, dhaval wrote: >> Hi, >> >> Can someone please give me an example of a working python post? >> for example using the sitehttp://www.cookiemag.com/ >> >> Thanks in advance, >> Dhaval > > I have tried to look at the code at > http://code.activestate.com/recipes/146306/ > I can't make any sense out of it. - don't SHOUT. - don't open up new threads 2 hours after you asked the first time with the *same* question. - show code of your actual efforts. This is not the "free code snippets producing system." - read this: http://www.catb.org/~esr/faqs/smart-questions.html Diez From staaleu at gmail.com Wed Jan 14 06:39:21 2009 From: staaleu at gmail.com (=?ISO-8859-1?Q?St=E5le_Undheim?=) Date: Wed, 14 Jan 2009 03:39:21 -0800 (PST) Subject: Parent module not loaded error References: <8f5d102e-4bfa-4416-9862-45565dc4b1ff@r15g2000prd.googlegroups.com> <9d4373c9-2cab-4eee-a2ad-dfd4398abe40@z28g2000prd.googlegroups.com> Message-ID: <2029f394-4a61-4ad1-b826-b75c878fdc2b@w39g2000prb.googlegroups.com> On Jan 14, 11:48?am, Graham Dumpleton wrote: > As a test, just prior to where unpickle is done, do: > > ? import sys > ? import d4 > > ? print >> sys.stderr, "d4.__name__", dr.__name__ > ? print >> sys.stderr, "d4.__file__", dr.__file__ > > This will just confirm that manual import works and what values of > those attributes are. The messages will end up in Apache error log for > that virtual host or main server error log as appropriate. d4.__name__ d4 d4.__file__ /home/petromarker/django-apps/d4/src/d4/../d4/__init__.pyc It's the same both before and after the exception. From gandalf at shopzeus.com Wed Jan 14 06:47:07 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 14 Jan 2009 12:47:07 +0100 Subject: Standard IPC for Python? In-Reply-To: References: Message-ID: <496DD0BB.6090203@shopzeus.com> > There are plenty of different IPC mechanisms available in > multiprocessing. > It is good for a special case: a tree of processes, forked from a main process. multiprocessing.Queue cannot be used as a general message queue between arbitrary processes. > - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, > respectively) > Which lacks synchronization between processes. (How do you notify the other process? How can the other process wait until notified?) From sjmachin at lexicon.net Wed Jan 14 07:01:14 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 04:01:14 -0800 (PST) Subject: MySQLdb LIKE '%%%s%%' problem References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> On Jan 14, 9:42?pm, Steve Holden wrote: > 3. I can't be certain my experience with PostgreSQL extends to MySQl, > but I have done experiments which prove to my satisfaction that it isn't > possible to parameterize LIKE arguments. So the only way to do it > appears to be to build the query yourself. This means that you will need > to make sure the string is made "safe", typically by replacing each > occurrence of the string "'" with "''" to retain the syntactic integrity > of the SQL statement. So finally, try > > cursor.execute("""UPDATE tablename set fieldx='test' > ? ? ? ? ? ? ? ? ? WHERE flfieldx IS NULL > ? ? ? ? ? ? ? ? ? AND fieldy LIKE '%%%s%%'""" % > ? ? ? ? ? ? ? ? ? certainvalue.replace("'", "''")) It appears possible to parameterise LIKE arguments in sqlite3: 8<--- code import sqlite3 tests = [ ["select * from foo", None], ["select * from foo where text like '%o%'", None], ["select * from foo where text like ?", "o"], ["select * from foo where text like ?", "a"], ] conn = sqlite3.connect("c:/junk/sql_like/foodb") curs = conn.cursor() for testno, test in enumerate(tests): sql, parm = test print "\n=== Test %d ===" % (testno + 1) print "sql =", sql print "parm =", parm if parm is None: curs.execute(sql) else: arg2 = "%" + parm + "%" curs.execute(sql, (arg2, )) results = curs.fetchall() print "results:", results 8<--- output === Test 1 === sql = select * from foo parm = None results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',), (u'echo',), (u'foxtrot',)] === Test 2 === sql = select * from foo where text like '%o%' parm = None results: [(u'bravo',), (u'echo',), (u'foxtrot',)] === Test 3 === sql = select * from foo where text like ? parm = o results: [(u'bravo',), (u'echo',), (u'foxtrot',)] === Test 4 === sql = select * from foo where text like ? parm = a results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',)] Cheers, John From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:07:43 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:07:43 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <6t5uhcF9bu1hU1@mid.uni-berlin.de> Message-ID: <017dcc25$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 10:53:33 +0000, Marc 'BlackJack' Rintsch wrote: > On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > >> On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: >> >>> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. >>> wrote: (...) >>> >>>>> Give me one use-case where you strictly require that members of an >>>>> object be private and their access enforced as such ? >>>> >>>> You're kidding, right? Think about a ten-million line program being >>>> developed by 100 developers. >>> >>> No I"m sorry this is not a valid use-case. >> >> Why not? Just saying it isn't doesn't make it not. > > Because "developer" means people who don't mess with implementation > details. So they respect the leading underscore convention. No use > case for enforced access restriction. O rly? *raise eyebrow* http://www.clausbrod.de/cgi-bin/view.pl/Blog/ WebHome#DefinePrivatePublic20080413_This or http://snipurl.com/a0ujm Sometimes developers have to work around encapsulation in their own code: http://www.gamedev.net/community/forums/topic.asp?topic_id=386856 Sometimes they do it just because they can: http://java-interview-faqs.blogspot.com/2008/08/hacking-by-reflection- accessing-private.html or http://snipurl.com/a0tox And try this: http://www.google.com/codesearch?q=%22%23define+private+public%22 -- Steven From sturlamolden at yahoo.no Wed Jan 14 07:15:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 04:15:26 -0800 (PST) Subject: Standard IPC for Python? References: Message-ID: <1f6c0e5c-2766-418b-9c91-e636bcb4cbaf@p36g2000prp.googlegroups.com> On Jan 14, 12:47 pm, Laszlo Nagy wrote: > multiprocessing.Queue cannot be used as a general message queue > between arbitrary processes. Then e.g. use Listener and Client in multiprocessing.connection to create a named pipe (AF_PIPE). Or use win32pipe.CreateNamedPipe from pywin32. > - mmap.mmap with 0 or -1 as the first argument (Windows and Linux, > > respectively) > > Which lacks synchronization between processes. It gives you access to shared memory. You must obviously use synchronization objects for synchronization. > (How do you notify the > other process? How can the other process wait until notified?) multiprocessing.Event multiprocessing.Lock win32event.CreateEvent win32event.SetEvent win32event.CreateMutex etc. From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:16:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:16:40 GMT Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Message-ID: <017dce3e$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: > Hi all! > I installed a external program called infomap using the classical > procedure > > ./configure > make > sudo make install > > and it works perfectly in Terminal (Os x) using both bash and tcsh > shell What happens when you call it using the sh shell (which is not necessarily aliased to bash)? [...] > but when I call it from python using os.system or subprocess.call I > get the message "sh: infomap-build: command not found". > > Do you know why? Possibly sh uses a different path to bash and can't find infomap-build. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 07:21:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 12:21:21 GMT Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: <017dcf56$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. Python is compiled. What do you think the c in .pyc stands for? And what do you think the compile() function does? It's just not compiled to machine code. It's compiled to byte code. -- Steven From rt8396 at gmail.com Wed Jan 14 07:49:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 04:49:25 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> Message-ID: <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> dhaval, Try www.pythonforum.org people there are much nicer to n00bs. Lots of nice people exist here, but they are too scared to speak up because of a few bullies. I am scared of nothing, as you can tell. There also exist grammarians and topicality police here that can make this forum less fun. Basically some people here think there bowel movements smell like bakery fresh cinnamon rolls :) Diez is right though, you should post something to show your efforts. Lots of people go around to forums just wanting to get their homework done for them. This does not sound like homework. From sturlamolden at yahoo.no Wed Jan 14 07:57:25 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 04:57:25 -0800 (PST) Subject: LGPL license for Qt 4.5 Message-ID: According to a Norwegian publication, Nokia will release Qt under LGPL as of version 4.5. If I had stocks in Riverbank Computing ltd., I would sell them now... For the rest of us, this is fantastic news. http://digi.no/php/art.php?id=800922 From hubaghdadi at gmail.com Wed Jan 14 07:59:08 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Wed, 14 Jan 2009 04:59:08 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 14, 2:21?pm, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: > >> Well... Because it is correct ? > > >> What make you think it _shouldn't_ work ? > > > Because def2 is defined after def1 in an interpreted language, not > > compiled. > > Python is compiled. > > What do you think the c in .pyc stands for? And what do you think the > compile() function does? > > It's just not compiled to machine code. It's compiled to byte code. > > -- > Steven Yes I know Python programs can be compiled but when I do: python Script1.py Did Python compile Script1 into the memory? From benjamin.kaplan at case.edu Wed Jan 14 08:04:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:04:04 -0500 Subject: Why this code is working? In-Reply-To: References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jan 14, 2009 at 7:59 AM, Hussein B wrote: > On Jan 14, 2:21 pm, Steven D'Aprano cybersource.com.au> wrote:a > > On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: > > >> Well... Because it is correct ? > > > > >> What make you think it _shouldn't_ work ? > > > > > Because def2 is defined after def1 in an interpreted language, not > > > compiled. > > > > Python is compiled. > > > > What do you think the c in .pyc stands for? And what do you think the > > compile() function does? > > > > It's just not compiled to machine code. It's compiled to byte code. > > > > -- > > Steven > > Yes I know Python programs can be compiled but when I do: > python Script1.py > Did Python compile Script1 into the memory? > -- > yes it does, but not in the way you are thinking. Python compiles to its byte code as needed, not at the start of the program. Because Python is dynamic, you can change things on the fly. For instance, this code is perfectly valid def f2(x) : print x def f1() : f2(88) f1() #prints 88 def f2(x) : print x/2 f1() #prints 44 Because the code can change on the fly, Python looks for f2 every time f1 is called, not when it first sees the function. This is the beauty of a dynamic language. > > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Jan 14 08:08:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 05:08:25 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Listen Hussien, In python you do not have to worry about what order this is, what type to declare that, my friend your bonds are cut. Be happy with your freedom and stop complaining about it. I guess where i come from freedom is second nature so i took to python pretty quick. From benjamin.kaplan at case.edu Wed Jan 14 08:16:52 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:16:52 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <017dcc25$0$8693$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <6t5uhcF9bu1hU1@mid.uni-berlin.de> <017dcc25$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jan 14, 2009 at 7:07 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Wed, 14 Jan 2009 10:53:33 +0000, Marc 'BlackJack' Rintsch wrote: > > > On Wed, 14 Jan 2009 07:14:06 +0000, Steven D'Aprano wrote: > > > >> On Wed, 14 Jan 2009 15:25:38 +1000, James Mills wrote: > >> > >>> On Wed, Jan 14, 2009 at 3:11 PM, Russ P. > >>> wrote: (...) > >>> > >>>>> Give me one use-case where you strictly require that members of an > >>>>> object be private and their access enforced as such ? > >>>> > >>>> You're kidding, right? Think about a ten-million line program being > >>>> developed by 100 developers. > >>> > >>> No I"m sorry this is not a valid use-case. > >> > >> Why not? Just saying it isn't doesn't make it not. > > > > Because "developer" means people who don't mess with implementation > > details. So they respect the leading underscore convention. No use > > case for enforced access restriction. > > > O rly? *raise eyebrow* > > http://www.clausbrod.de/cgi-bin/view.pl/Blog/ > WebHome#DefinePrivatePublic20080413_This > > or http://snipurl.com/a0ujm > > Sometimes developers have to work around encapsulation in their own code: > http://www.gamedev.net/community/forums/topic.asp?topic_id=386856 > > Sometimes they do it just because they can: > > http://java-interview-faqs.blogspot.com/2008/08/hacking-by-reflection- > accessing-private.html > or http://snipurl.com/a0tox > > And try this: > > http://www.google.com/codesearch?q=%22%23define+private+public%22 > I think you actually just proved his point- the access restrictions are pointless. If there are ways to access private variables, then aren't they just private by convention as well? The only difference with Python is that, rather than going through the introspection (which Python does better than Java anyway) to get the variables, all you have to do is type that leading underscore. Either way, you know you're doing something you shouldn't. -- Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jan 14 08:21:02 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 14:21:02 +0100 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: <6t675uF9akueU1@mid.uni-berlin.de> r wrote: > Listen Hussien, Granted, with a name of "r", spelling it wrong is hard, and thus you might not be trained in the art of spelling names proper. But I suggest you try your best. After all, you posts lack so much in content, you could at least excel in form... > In python you do not have to worry about what order this is, what type > to declare that, my friend your bonds are cut. Be happy with your > freedom and stop complaining about it. I guess where i come from > freedom is second nature so i took to python pretty quick. What's that condescending nonsense to mean? What do you know of the heritage and living circumstances of the OP? And since when is a choice of typing-system correlated with the political and social aspects of a society - you care to prove that? And where did the OP "complain"? He merely wondered. I'm well aware that you are a piece of trolling d.....t. But this goes a bit to far, Mr. Diez From nick at craig-wood.com Wed Jan 14 08:32:07 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 14 Jan 2009 07:32:07 -0600 Subject: ctype problem References: Message-ID: Grimson wrote: > hello out there, > I have a problem with c-types. > I made a c-library, which expects a pointer to a self defined structure. > > let the funtion call myfunction(struct interface* iface) > > and the struct: > struct interface > { > int a; > int b; > char *c; > } > > the Python ctype port of this structur would be: > > class INTERFACE(Structure): > _fields_ = [("a" c_int), > ("b", c_int), > ("c", c_char)] > > in my python-struct a create a instance of INTERFACE > > myiface = INTERFACE() > myiface.a = ctypes.c_int(80) > myiface.b = ctypes.c_int(22) > ... > than I make a pointer onto it. > p_iface = ctypes.pointer(myiface) > and I tried it also with a reference > r_iface = ctypes.byref(myiface) > > but neither myclib.myfunction(p_iface) nor myclib.myfunction(r_iface) > works properly. The function is been called but it reads only zeros (0) > for each parameter (member in the struct). > > Where is my fault? You didn't (or you didn't show) defining the argument types of the function. myclib = CDLL("myclib.so") # or whatever myclib.myfunction.argtypes = [ POINTER(INTERFACE) ] myclib.myfunction.restype = c_int # or whatever If you do that then you should be able to pass in myiface directly or byref(myiface). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From grante at visi.com Wed Jan 14 08:37:37 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 14 Jan 2009 07:37:37 -0600 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <172dnfILH8Y8d_DUnZ2dnUVZ_gCdnZ2d@posted.usinternet> On 2009-01-14, Steve Holden wrote: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. >> > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. You're probably right. That's why the "delete" character is all 1's (all holes). It's easy to punch more holes -- un-punching them is pretty arduous. -- Grant From castironpi at gmail.com Wed Jan 14 08:39:23 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 05:39:23 -0800 (PST) Subject: why cannot assign to function call References: <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <590b092e-ae35-47d2-8793-039ee877dc8c@k1g2000prb.googlegroups.com> On Jan 14, 3:51?am, Mark Wooding wrote: > Aaron Brady wrote: > > On Jan 13, 5:06 pm, Mark Wooding wrote: > > snip > > > I'm going to move away from the formal semantics stuff and try a > > > different tack. ?Here's what I think is the defining property of > > > pass-by-value (distilled from the formal approach I described earlier, > > > but shorn of the symbolism): > > > > ? The callee's parameters are /new variables/, initialized /as if by > > > ? assignment/ from the values of caller's argument expressions. > > > In other words, the same as assignment in that language. > > It's the same as assignment of /values/ to /fresh variables/. ?It's > important to specify that argument expressions are fully evaluated, and > that nothing gets overwritten in the process. > > So the difference between Python and C is that C copies values during > assignment, but Python doesn't. ?Therefore the argument passing works > the same way. That interferes with Joe's claim that the value of a variable is a memory address. I think you'd have better luck sticking with "pass-by- assignment". A Java reference and a C++ reference are different things, somewhat regrettably. > > > Because its argument passing works the same way as its assignment. > > > That would be called pass-by-assignment. ?But you've just postponed > > explaining yourself. ?Stop delegating and work. > > Huh? ?I'm really at a loss to know what you want me to do. You were remarkably civil about that. I regretted it as soon as I sent it. You keep wanting to say "but it's just a reference, it's just a reference". But all that does is put more burden on the fellow that explains what a reference is. It took me years to grasp pointers... possibly all the way up until comp. architecture class. (As such, I find you're shirking.) > I can't help it if people are confused over the phrase `pass-by-value', > beyond trying to explain what it means using clear definitions. ?The > `value' part means that argument expressions are /evaluated/ (turned > into values), which forces applicative-order semantics rather than (say) > normal-order. I can't believe it's taken this long, including October's discussion ( and especially with my dual (not duel, ha!) in Philosophy ), but I'd finally like to quote the manuals. "An object's identity never changes once it has been created." "The value of some objects can change." - http://docs.python.org/reference/datamodel.html Therefore, an object's value is not its identity. (Its identity is something other than its value.) You might get away with 'pass-by- identity'. After 'X= [1, 2, 3]', X refers to an object. You can change two things: (1) the fact that X refers to that object, (2) that object. In 'X= None' and 'del X', you change the fact that X refers to that object. In 'X[:]= [4, 5, 6]' and 'X.pop()', you change the object. Explanatory note: It really takes two sentences to say that. 'X refers to an object. You can change the object, or change the fact that X refers to it.' If you try to say it in one sentence, the distinction collapses: 'You can change (1) the object that X refers to, or (2) the object that X refers to.' Irony! 'X' is a key in a namespace. namespace[ 'X' ]= [1, 2, 3] namespace[ 'Y' ]= namespace[ 'X' ] del namespace[ 'X' ] No matter how hard you try, if you don't have both of two things, 'namespace' and '"X"', you can't change namespace[ 'X' ]. And back to the OP (long since gone, naturally): You can do: f()[:]= [1, 2, 3] As well as: f().replace( [1, 2, 3] ) As well as: f().contents= [1, 2, 3] The particular thing s/he wanted isn't one of these. Lastly, I think it would do you and Joe good to ignore some details, when thinking about beginners. From grante at visi.com Wed Jan 14 08:39:54 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 14 Jan 2009 07:39:54 -0600 Subject: [OT] Re: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <172dne0LH8a3dvDUnZ2dnUVZ_gAAAAAA@posted.usinternet> On 2009-01-14, Gabriel Genellina wrote: > En Tue, 13 Jan 2009 22:04:33 -0200, Terry Reedy > escribi?: > >> Gabriel Genellina wrote: >>> En Mon, 12 Jan 2009 12:00:16 -0200, John Machin >>> escribi?: >>> >>>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>>> file size as number of 128-byte sectors, forcing the use of an in-band >>>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>>> decades after people stopped writing Ctrl-Z at the end of text files. >>> This is called "backwards compatibility" and it's a good thing :) >> >> But it does not have to be the default or only behavior to be available. > > Sure. And it isn't It _is_ the default behavior on some systems. The default file mode when you open a file in C or in Python is "text" mode. In text mode, Windows interprets a ctrl-Z as EOF, doesn't it? -- Grant From castironpi at gmail.com Wed Jan 14 08:45:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 05:45:48 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <6t675uF9akueU1@mid.uni-berlin.de> Message-ID: <77e6e69e-bd55-41a2-b171-63d116145abf@r15g2000prd.googlegroups.com> On Jan 14, 7:21?am, "Diez B. Roggisch" wrote: > r wrote: > > Listen Hussien, > > Granted, with a name of "r", spelling it wrong is hard, and thus you might > not be trained in the art of spelling names proper. Or spelling proper names! Bah ha. From davide.picca at gmail.com Wed Jan 14 08:52:21 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 05:52:21 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <017dce3e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4e9c2c1b-bac2-4edf-8728-188876a64b00@n33g2000pri.googlegroups.com> On 14 Gen, 13:16, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: > > Hi all! > > I installed a external program called infomap using the classical > > procedure > > > ./configure > > make > > sudo make install > > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > > shell > > What happens when you call it using the sh shell (which is not > necessarily aliased to bash)? > > [...] > > > ?but when I call it from python using os.system or subprocess.call I > > get the message "sh: infomap-build: command not found". > > > Do you know why? > > Possibly sh uses a different path to bash and can't find infomap-build. > > -- > Steven in infocmp infotocap installer indent infokey install instmodsh indxbib infomap-build install-info instruments info infomap-install install_name_tool sh-3.2$ infomap-build Usage: infomap-build [-w working_dir] [-p param_file] [-D var_1=val_1 ... -D var_N=val_N] (-s single_corpus_file | -m multi_file_list) sh-3.2$ I am not able to figure out why.. any idea? Thanks From pythonsky at sky.com Wed Jan 14 08:52:44 2009 From: pythonsky at sky.com (garywood) Date: Wed, 14 Jan 2009 13:52:44 -0000 Subject: can someone tell me why this doesn't work please python 3 Message-ID: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): while True: password = input("enter something") if password in ('y', 'ye', 'yes'): return True if password in ('n', 'no', 'nope'): return False retries = retries - 1 if retries < 0: raise IOError('refusenik user') print(complaint) -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Jan 14 08:54:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 08:54:30 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Wed, Jan 14, 2009 at 3:13 AM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > On Tue, 13 Jan 2009 23:26:54 -0800, Brendan Miller wrote: > > > I tend to use constants as a means of avoiding the proliferation of > > magic literals for maintenance reasons... Like say if your example of > > FOO would have been used in 10 places. Maybe it is more pythonic to > > simply denote such a thing as simply a normal variable? > > But it isn't a "normal variable", it's a named constant, or at least it > would be if Python enforced constanticity. Or constantness. Or whatever. > > > That doesn't > > seem to give a hint that it shouldn't be assigned a second time. > > Absolutely. It's rather sad that I can do this: > > import math > math.pi = 3.0 > > I like the ability to shoot myself in the foot, thank you very much, but > I should at least get a warning when I'm about to do so: > > math.PI = 3.0 # use God-like powers to change a constant (OT) You don't need God-like powers to do that. God already did it (it's in the bible somewhere, I don't remember where) And the Indiana state legislature thinks that doing that changing the value of pi is a perfectly legitimate action. (I guess they arrest all circles whose circumfrence:diameter ratio doesn't conform to the new value ???) http://en.wikipedia.org/wiki/Indiana_Pi_Bill > > > > > > Changing the laws of physics, one fundamental constant at a time-ly y'rs, > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From siona at chiark.greenend.org.uk Wed Jan 14 08:55:38 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 14 Jan 2009 13:55:38 +0000 (GMT) Subject: initialising a class by name References: <1231912018.7570.22.camel@krishna-laptop> <1231922209.7570.49.camel@krishna-laptop> <50697b2c0901140039n70bb750ar43502ca1af06b8af@mail.gmail.com> Message-ID: Krishnakant wrote: >By the way, is there a kind of global list of modules/classes which are >maintained in a package once the program is loaded into memory? sys.modules is a dict of loaded module objects, keyed by module name. So: >>> getattr(sys.modules["sys"], "version_info") (2, 5, 0, 'final', 0) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From deets at nospam.web.de Wed Jan 14 09:01:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 14 Jan 2009 15:01:25 +0100 Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <017dce3e$0$8693$c3e8da3@news.astraweb.com> <4e9c2c1b-bac2-4edf-8728-188876a64b00@n33g2000pri.googlegroups.com> Message-ID: <6t69hlF98rhgU1@mid.uni-berlin.de> codicedave wrote: > On 14 Gen, 13:16, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 14 Jan 2009 02:25:52 -0800, codicedave wrote: >> > Hi all! >> > I installed a external program called infomap using the classical >> > procedure >> >> > ./configure >> > make >> > sudo make install >> >> > and it works perfectly in Terminal (Os x) using both bash and tcsh >> > shell >> >> What happens when you call it using the sh shell (which is not >> necessarily aliased to bash)? >> >> [...] >> >> > but when I call it from python using os.system or subprocess.call I >> > get the message "sh: infomap-build: command not found". >> >> > Do you know why? >> >> Possibly sh uses a different path to bash and can't find infomap-build. >> >> -- >> Steven > > in infocmp infotocap installer > indent infokey install instmodsh > indxbib infomap-build install-info instruments > info infomap-install install_name_tool > sh-3.2$ infomap-build > > Usage: infomap-build [-w working_dir] [-p param_file] > [-D var_1=val_1 ... -D var_N=val_N] > (-s single_corpus_file | -m multi_file_list) > > > sh-3.2$ > > I am not able to figure out why.. > > any idea? How about you give the full path to the executable? Might be that the PATH isn't set correctly. If you installed the software by yourself, it is very likely that it ended up in /usr/local/bin instead of /usr/bin, and the former might not be part of the PATH-variable. Diez From wladimirufc at gmail.com Wed Jan 14 09:10:32 2009 From: wladimirufc at gmail.com (wladimir) Date: Wed, 14 Jan 2009 06:10:32 -0800 (PST) Subject: Twisted Trial - Framework for Test Message-ID: <21456710.post@talk.nabble.com> Hi, Somebody have some tutorial or examples using Twisted Trial?? -- View this message in context: http://www.nabble.com/Twisted-Trial---Framework-for-Test-tp21456710p21456710.html Sent from the Python - python-list mailing list archive at Nabble.com. From drobinow at gmail.com Wed Jan 14 09:11:12 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Wed, 14 Jan 2009 06:11:12 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 7:57?am, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > For the rest of us, this is fantastic news. > > http://digi.no/php/art.php?id=800922 http://www.qtsoftware.com/about/licensing Not sure what this means for PyQt From sturlamolden at yahoo.no Wed Jan 14 09:20:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 14 Jan 2009 06:20:06 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> On Jan 14, 3:11?pm, "drobi... at gmail.com" wrote: > On Jan 14, 7:57?am, sturlamolden wrote: > > > According to a Norwegian publication, Nokia will release Qt under LGPL > > as of version 4.5. > > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > > For the rest of us, this is fantastic news. > > >http://digi.no/php/art.php?id=800922 > > http://www.qtsoftware.com/about/licensing > > Not sure what this means for PyQt It means that: - If Riverbank keep their dual GPL licensing scheme, somebody else will make an LGPL 'QtPython' instead. - If Riverbank change PyQt to LGPL, they will loose most of their revenue form PyQt. In either case, Qt will be available under the same licensing terms as wxWidgets. As of today, the main reason to prefer wxPython over PyQt is the license. With an LGPL'd Qt, I'd rather ask what this will mean for wxPython. From aahz at pythoncraft.com Wed Jan 14 09:28:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Jan 2009 06:28:33 -0800 Subject: Understanding search queries, semantics, and "Meaning" ...aren't we all looking for meaning? References: <82372457-2503-4682-96b3-37540328bf26@w39g2000prb.googlegroups.com> Message-ID: In article <82372457-2503-4682-96b3-37540328bf26 at w39g2000prb.googlegroups.com>, <5lvqbwl02 at sneakemail.com> wrote: > >I have Section 4.4.1 of SICP rattling around in my head (database >queries), and I'm trying to come up with a simple dictionary-based >database in Python to represent circuit diagrams. My main confusion >isn't one of implementation, but a matter of "big thinking", >fundamentally, about the problem. Please don't suggest using a SQL >library, as I'm looking to learn to fish, so to speak, and to learn a >bit about the biology of fish. Having read the rest of your conversation with Jonathan, I'm going to suggest a related book that I think may help you approach this from a different angle: _Mastering Regular Expressions_ by Jeffrey Friedl. (I haven't gone through SICP myself, so I can't be sure that it's relevant, but it covers the topic of transforming search criteria into executable statements -- and it will almost certainly be useful to you even if it's not relevant to your current problem.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From ddasilva at umd.edu Wed Jan 14 09:30:19 2009 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 14 Jan 2009 06:30:19 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> Message-ID: <3df592bc-b544-4e63-b54e-fbdd1bdafb0a@s1g2000prg.googlegroups.com> On Jan 14, 5:25?am, codicedave wrote: > Hi all! > I installed a external program called infomap using the classical > procedure > > ./configure > make > sudo make install > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > shell > > admins-macbook-pro-2:~ unil$ infomap-build > > Usage: infomap-build [-w working_dir] [-p param_file] > ? ? ? ?[-D var_1=val_1 ... -D var_N=val_N] > ? ? ? ?(-s single_corpus_file | -m multi_file_list) > ? ? ? ? > > ?but when I call it from python using os.system or subprocess.call I > get the message "sh: infomap-build: command not found". > > Do you know why? > > Many thanks > > Davide Type "which infomap-build" from the command line to find out where infomap-build is. From lkcl at lkcl.net Wed Jan 14 09:36:40 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 14 Jan 2009 14:36:40 +0000 Subject: pyjamas 0.4p1 release Message-ID: This is a minor patch release of pyjamas 0.4p1, the Python-to-Javascript compiler and Python Web UI Widgets Toolkit. What is Pyjamas for? Pyjamas allows a developer to create U.I applications in python as if the Web Browser was a Desktop Widget Set toolkit platform (like pygtk2, pywxWidgets and pyqt4, only much simpler, and more powerful). No knowledge of javascript programming is required: the python-to-javascript compiler takes care of the conversion between python and javascript, and the U.I widget set takes care of all the browser and AJAX incompatibilities. Why don't I find that exciting? The significance of pyjamas takes a while to sink in. Or you're not a UI developer. Or you've never been asked to write an identical app that works on both the desktop and all major web browsers. If you're a python developer who has followed the history of web application development of the past decade, with much frustration and disappointment, is overwhelmed by Javascript, AJAX and the demands of the "Web 2.00o0ooo0 Revverlushun", then Pyjamas is something that you should consider investigating. Pyjamas 0.4p1 Bug-fixes (and accidental Features) Significant bugs fixed include HorizontalPanel's remove() function, SimplePanel's clear() function, and sprintf with multiple arguments ("%s %d" % ("hello", 2) will now work) Dialog Box now has modal functionality (thanks to jurgen kartnaller). HorizontalSplitPanel has been added, although both the horizontal and vertical panels operate correctly on Mozilla-based browsers, but Safari and IE need volunteers to work on them. Several more examples have also been added, including a spreadsheet-like GridEdit example; a Transparent SVG canvas clock widget (that actually tells the time); an "Information Hierarchy" example that could be used as the basis for an online cooperative spreadsheet editor; Erik Westra's "Showcase" source code which provides and shows the source of the 30 widgets being demo'd; and a few other minor examples. Discussion: http://groups.google.com/group/pyjamas-dev/ Bugs: http://code.google.com/p/pyjamas/issues/list Downloads: https://sourceforge.net/project/showfiles.php?group_id=239074 http://code.google.com/p/pyjamas/downloads/list Web site: http://pyjs.org (pyjamas javascript compiler and UI widget set) http://pyjd.org (sister project, pyjamas-desktop) From gary at byoteki.com Wed Jan 14 09:44:29 2009 From: gary at byoteki.com (Gary M. Josack) Date: Wed, 14 Jan 2009 09:44:29 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <496DFA4D.6090801@byoteki.com> garywood wrote: > def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): > while True: > password = input("enter something") > if password in ('y', 'ye', 'yes'): return True > if password in ('n', 'no', 'nope'): return False > retries = retries - 1 > if retries < 0: > raise IOError('refusenik user') > print(complaint) > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > Well since you didn't give an error I'm going to assume your problems are as follows: * Use raw_input() instead of input() # input evals the input received. * pass prompt as the argument to raw_input so that your prompt gets set # might want to give prompt a default value * password.lower() so Y, YE, YES, N, NO, NOPE also work for input From bsk16 at case.edu Wed Jan 14 09:47:57 2009 From: bsk16 at case.edu (Ben Kaplan) Date: Wed, 14 Jan 2009 09:47:57 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <496DFA4D.6090801@byoteki.com> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> Message-ID: <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: > garywood wrote: >> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >> while True: >> password = input("enter something") >> if password in ('y', 'ye', 'yes'): return True >> if password in ('n', 'no', 'nope'): return False >> retries = retries - 1 >> if retries < 0: >> raise IOError('refusenik user') >> print(complaint) >> --- >> --------------------------------------------------------------------- >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > Well since you didn't give an error I'm going to assume your > problems are as follows: > * Use raw_input() instead of input() # input evals the input received. > * pass prompt as the argument to raw_input so that your prompt gets > set # might want to give prompt a default value > * password.lower() so Y, YE, YES, N, NO, NOPE also work for input > -- > http://mail.python.org/mailman/listinfo/python-list Did you miss the python 3 part? Raw_input was removed and input now behaves like raw_input did in 2.x From mikehartl at web.de Wed Jan 14 10:01:11 2009 From: mikehartl at web.de (Michael Hartl) Date: Wed, 14 Jan 2009 16:01:11 +0100 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <496DFE37.2040306@web.de> garywood schrieb: > def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): > while True: > password = input("enter something") > if password in ('y', 'ye', 'yes'): return True > if password in ('n', 'no', 'nope'): return False > retries = retries - 1 > if retries < 0: > raise IOError('refusenik user') > print(complaint) > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > What's your problem, anyway? It seems to work perfectly fine, except that you ignore the prompt variable. From gary at byoteki.com Wed Jan 14 10:02:06 2009 From: gary at byoteki.com (Gary M. Josack) Date: Wed, 14 Jan 2009 10:02:06 -0500 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> Message-ID: <496DFE6E.8020304@byoteki.com> Ben Kaplan wrote: > > > On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: > >> garywood wrote: >>> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >>> while True: >>> password = input("enter something") >>> if password in ('y', 'ye', 'yes'): return True >>> if password in ('n', 'no', 'nope'): return False >>> retries = retries - 1 >>> if retries < 0: >>> raise IOError('refusenik user') >>> print(complaint) >>> --- >>> --------------------------------------------------------------------- >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> Well since you didn't give an error I'm going to assume your problems >> are as follows: >> * Use raw_input() instead of input() # input evals the input received. >> * pass prompt as the argument to raw_input so that your prompt gets >> set # might want to give prompt a default value >> * password.lower() so Y, YE, YES, N, NO, NOPE also work for input >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Did you miss the python 3 part? Raw_input was removed and input now > behaves like raw_input did in 2.x Ah, yes. Subject got truncated on my little laptop screen. Either way, more information is needed to diagnose the problem. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 10:02:09 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 16:02:09 +0100 Subject: Why this code is working? In-Reply-To: <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: <496dfe71$0$4822$426a74cc@news.free.fr> Hussein B a ?crit : > On Jan 14, 11:55 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Hussein B a ?crit : >> >>> Hey, >>> Why this code is working? >>>>>> def f1( ): >>> ... x = 88 >>> ... f2(x) >>> ... >>>>>> def f2(x): >>> ... print x >>> ... >>>>>> f1( ) >>> 88 >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. CPython actually compiles to byte-code, which is then executed. But anyway: even if it was fully interpreted, the fact that f2 is defined after f1 should not matter - what matters is that name f2 exists (and is bound to a callable taking a single mandatory argument) when f1 is actually _called_. >>> def f1(): ... x = 42 ... f2(x) ... >>> f1() Traceback (most recent call last): File "", line 1, in File "", line 3, in f1 NameError: global name 'f2' is not defined >>> def f2(x): ... print x ... >>> f1() 42 >>> def f2(x): ... print "pikaboo" ... >>> f1() pikaboo >>> >>> del f2 >>> f1() Traceback (most recent call last): File "", line 1, in File "", line 3, in f1 NameError: global name 'f2' is not defined >>> HTH From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 10:06:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 16:06:49 +0100 Subject: Why this code is working? In-Reply-To: References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> Message-ID: <496dff88$0$4822$426a74cc@news.free.fr> Hussein B a ?crit : > On Jan 14, 2:21 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 14 Jan 2009 01:57:48 -0800, Hussein B wrote: >>>> Well... Because it is correct ? >>>> What make you think it _shouldn't_ work ? >>> Because def2 is defined after def1 in an interpreted language, not >>> compiled. >> Python is compiled. >> (snip) > > Yes I know Python programs can be compiled wrt/ CPython: s/can be/are/ > but when I do: > python Script1.py > Did Python compile Script1 into the memory? Yes. Only (imported) modules are automatically saved as .pyc. From mwilson at the-wire.com Wed Jan 14 10:15:33 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 10:15:33 -0500 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Steve Holden wrote: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. Perhaps, although in ASCII it's the SUB symbol: "A control character that is used in the place of a character that is recognized to be invalid or in error or that cannot be represented on a given device." [Wikipedia]. There were other codes defined for End-of-Text and File-Separator. Unless the protocol were one of DEC's own. The fact that it's Ctrl-last-letter-of-the-alphabet makes me suspect that it was picked in a pretty informal way. Mel. From nick at craig-wood.com Wed Jan 14 10:32:07 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 14 Jan 2009 09:32:07 -0600 Subject: initialising a class by name References: Message-ID: Krishnakant wrote: > I liked this idea of dispatchTable. > is it possible to say some thing like > inst = dispatchTable{"ham"} > according to me, inst will become the instance of class ham. > Another thing to note is that all the classes are in different modules. > So where do I create the dict of classes mapped with the name? You could use a metaclass which will get round the problem, provided all the classes have a common baseclass, eg class BaseThing(object): registry = {} class __metaclass__(type): def __init__(cls, name, bases, dict): cls.registry[cls.__name__] = cls class ThingOne(BaseThing): pass class ThingTwo(BaseThing): pass class ThingThree(BaseThing): pass print BaseThing.registry["ThingOne"] print BaseThing.registry["ThingTwo"] print BaseThing.registry["ThingThree"] Which prints -- Nick Craig-Wood -- http://www.craig-wood.com/nick From marco at sferacarta.com Wed Jan 14 10:32:30 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 14 Jan 2009 16:32:30 +0100 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> Message-ID: Steve Holden wrote: > 3. I can't be certain my experience with PostgreSQL extends to MySQl, > but I have done experiments which prove to my satisfaction that it isn't > possible to parameterize LIKE arguments. So the only way to do it > appears to be to build the query yourself. Or using Postgres through SQLAlchemy. Actually, the only thing SQLAlchemy cannot do (yet) is withstand a zombie army. From http Wed Jan 14 10:33:20 2009 From: http (Paul Rubin) Date: 14 Jan 2009 07:33:20 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> Message-ID: <7xljtdkim7.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > If the programmer could > > somehow disallow it in certain classes, > > Already possible - you just have to provide your own implementation of > __setattr__. Part of the idea of non-dynamic attribute sets is to make the program run faster, not slower. From mwilson at the-wire.com Wed Jan 14 10:46:28 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 10:46:28 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 13, 11:40?pm, Steven D'Aprano > wrote: > >> But, gosh darn it, wouldn't it be nice to program the critical parts of >> your code in "strict Python", and leave the rest as "trusting Python", >> instead of having to use Java for the lot just to get strictness in the >> critical parts? If only there was a way to do this, and ensure people >> won't abuse it. > > Yes, that would indeed be nice. I am certainly not the only one who > could use a language that is excellent for both research prototyping > *and* the final, safety-critical system. Then perhaps the prototype > could just be cleaned up and "hardened" for the end product rather > than rewritten in another language -- by programmers in another state > who may fail to understand many of the details that the prototype > developer agonized over. You might have a look at Business Shell which is based on Ada. Mel. From kyrie at uh.cu Wed Jan 14 10:48:30 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 10:48:30 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqtkqi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <200901141048.31049.kyrie@uh.cu> On Wednesday 14 January 2009 02:22:45 am Paul Rubin wrote: > 2. There is also nothing inherent in a dynamic OO language that says > that class descriptors have to be mutable, any more than strings have > to be mutable (Python has immutable strings). ?I agree that being able > to modify class descriptors at runtime is sometimes very useful. ?The > feature shouldn't be eliminated from Python or else it wouldn't be > Python any more. ?But those occasions are rare enough that having to > enable the feature by saying (e.g.) "@dynamic" before the class > definition doesn't seem like a problem, both for encapsulation Why don't you do it backwards? You *can* implement a metaclass that will remove the dynasmism from its instances. Do it - I can give you a starting point if you wish. But most of us are very happy with the dynamic nature of python... I chose python _because_ of it. > and because it can also improve performance. Btw, for performance, there is __slots__, with the side-effect that it forbids attribute creation 'on the fly'. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Wed Jan 14 10:51:13 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 10:51:13 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <200901141051.13235.kyrie@uh.cu> On Tuesday 13 January 2009 09:57:04 pm Terry Reedy wrote: > Russ P. wrote: > public = no leading underscore > private = one leading underscore > protected = two leading underscores Aren't the last two reversed? protected = one leading underscore [both you and your subclasses should access it] private = two leading underscores (name munging) [only you should access - implementation detail.] -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Wed Jan 14 11:00:50 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 11:00:50 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901141100.50504.kyrie@uh.cu> On Tuesday 13 January 2009 10:32:54 pm James Mills wrote: > Should Python get strict and enforce access control > of object members ? No. Why ? I can think of several > reasons. > > Give me one use-case where you strictly require > that members of an object be private and their > access enforced as such ? Devil's advocate here - I think I can give you one: when you need to share some objects with potentially untrusted code (like, a plugin system). You can't, and you shouldn't, expect that the user will know what plugins he should or shouldn't load, and you shouldn't blame him/her when your app stops working because you failed to protect it's internals from malicious plugins (think web browser). Of course... in that scenario, the public/private distinction is the least of the concerns... and whatever is done to solve them will likely make irrelevant if the members are private or public. But, for trusted code? Or at least code known at compile time? It's just not worth it... pylint should take care of that - and if it doesn't, the OP should go fix it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Wed Jan 14 11:14:56 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:14:56 -0800 (PST) Subject: point class help Message-ID: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> I am hacking up a point class but having problems with how to properly overload some methods. in the __add__, __sub__, __iadd__, __isub__, I want to have the option of passing an instance or a container(list, tuple) like >>> p1 = Point2d(10,10) >>> p1 += (10,10) >>> p1 Point2d(20,20) >>> >>> p2 = Point2d(10,10) >>> p2 += p1 >>> p2 Point2d(30,30) here is what i have, it would seem stupid to use a conditional in each method like this... def method(self, other): if isinstance(other, Point2d): x, y = origin.x, origin.y else: x, y = origin[0], origin[1] #modify self.x & self.y with x&y there must be a way to get the x, y with reusable code, i am not about to have this conditional under every method call, What am i missing here? class Point2d(): def __init__(self, x, y=None): if type(x) == tuple: self.x = x[0] self.y = x[1] else: self.x = x self.y = y def __str__(self): return 'Point2d(%f, %f)' %(self.x, self.y) def __add__(self, other): if isinstance(other, Point2d): x, y = origin.x, origin.y else: x, y = origin[0], origin[1] return (self.x+x, self.y+y) def __sub__(self, other): pass def __iadd__(self, other): #+= pass def __isub__(self, other): #-= pass any ideas? From marduk at letterboxes.org Wed Jan 14 11:17:14 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 14 Jan 2009 11:17:14 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: <1231949834.26918.2.camel@localhost.localdomain> On Wed, 2009-01-14 at 16:58 +1000, James Mills wrote: [...] > Still I would avoid using this idiom altogether > and jsut stick with default values. For Example: > > FOO = 1 > > def f(x=FOO): > ... > > > Use this instead: > > def f(x=1): > ... That only works well when "1" is only used once, and as an argument to a function. Once you find yourself outside of that special case then anytime you want to change "1" to "2" then you're going to regret having made that decision. From http Wed Jan 14 11:18:51 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:18:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <7xab9tj1xw.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > when you need to share some objects with potentially untrusted code (like, a > plugin system). You can't, and you shouldn't, expect that the user will know > what plugins he should or shouldn't load, and you shouldn't blame him/her > when your app stops working because you failed to protect it's internals from > malicious plugins (think web browser). Python is not set up for this even slightly. Java attempts it, with mixed success. From mwilson at the-wire.com Wed Jan 14 11:21:38 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 14 Jan 2009 11:21:38 -0500 Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> Message-ID: Hussein B wrote: > On Jan 14, 11:55?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Hussein B a ?crit : >> >> > Hey, >> > Why this code is working? >> >> >>>> def f1( ): >> > ... ? ? ?x = 88 >> > ... ? ? ?f2(x) >> > ... >> >>>> def f2(x): >> > ... ? ? ?print x >> > ... >> >>>> f1( ) >> > 88 >> >> Well... Because it is correct ? >> >> What make you think it _shouldn't_ work ? > > Because def2 is defined after def1 in an interpreted language, not > compiled. You don't have to know about f2 when f1 is compiled. You only have to know about f2 when f1 is called. I predict that def f1(): n = 88 f2 (n) f1() def f2 (x): print x will *not* work. Python won't consider the non-definition of f2 to be a problem until you try to actually use it. Mel. From kyrie at uh.cu Wed Jan 14 11:24:12 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 11:24:12 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <200901141124.12596.kyrie@uh.cu> On Wednesday 14 January 2009 12:57:42 am James Mills wrote: > Russ: > > 1. Quit while you're ahead. > 2. OOP is encapsulating data and functionality into a single grouping > (object). > 3. Other features more recently developed by OO languages such as > Polymorphism, Access Control (a type of encapsulation), Inheritance > and Multiple Inheritance are all irrelevant and OO languages either > implement all or a subset of these features and each do so > differently. To further your point, I'd say that python _doesn't_ have polymorphism. It doesn't need it - the natural, expected, "OOP" behavior is always there, you cannot break it. A dog will always bark and a cat will always meow, regardless of the context and the inheritance relation between a cat and a dog (there should be none, but I couldn't think of a better example than the broken 'a cat is a dog'... please bear with me). If the very concept of polymorphism is superfluous in python, would that make python 'less' OOP? Judging by this thread, I'd guess that Russ believes that languages like C# are closer to his OOP ideal... and guess what, C# not only needs a word for the concept of "objects should behave as you expect them to behave - we want no barking cats, ever", but it is even not polymorphic by default (the cursed "virtual" keyword). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Wed Jan 14 11:31:07 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:31:07 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: <8150efe3-23c9-4909-8740-2981a9930647@d32g2000yqe.googlegroups.com> before anybody say's anything, i screwed up when i pasted the code, here is what i really have... def method(self, other): if isinstance(other, Point2d): x, y = other.x, other.y else: x, y = other[0], other[1] return self.x+x, self.y+y #and the fixed class :) class Point2d(): def __init__(self, x, y=None): if type(x) == tuple: self.x = x[0] self.y = x[1] else: self.x = x self.y = y def __str__(self): return 'Point2d(%f, %f)' %(self.x, self.y) def __add__(self, other): if isinstance(other, Point2d): x, y = other.x, other.y else: x, y = other[0], other[1] return (self.x+x, self.y+y) def __sub__(self, other): pass def __iadd__(self, other): #+= pass def __isub__(self, other): #-= pass PS: i know i could have one method like def get_xy(self, other): #conditional and then call it like x, y = self.get_xy(other) but that seems pretty clumsy. There must be a more Pythonic way! From steve at holdenweb.com Wed Jan 14 11:32:00 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:32:00 -0500 Subject: Why this code is working? In-Reply-To: <6t675uF9akueU1@mid.uni-berlin.de> References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <6t675uF9akueU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > r wrote: > >> Listen Hussien, > > Granted, with a name of "r", spelling it wrong is hard, and thus you might > not be trained in the art of spelling names proper. But I suggest you try > your best. After all, you posts lack so much in content, you could at least > excel in form... > >> In python you do not have to worry about what order this is, what type >> to declare that, my friend your bonds are cut. Be happy with your >> freedom and stop complaining about it. I guess where i come from >> freedom is second nature so i took to python pretty quick. > > What's that condescending nonsense to mean? What do you know of the > heritage and living circumstances of the OP? And since when is a choice of > typing-system correlated with the political and social aspects of a > society - you care to prove that? > > And where did the OP "complain"? He merely wondered. > > I'm well aware that you are a piece of trolling d.....t. But this goes a bit > to far, Mr. > I am happy to say I did not receive the post of which you complain, Diez. Its tone was indeed abominable, and is most definitely unwelcome within fifteen thousand miles of this list. Just in case anyone else thought it was OK to make irrational deductions based only on someone's name ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 14 11:34:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:34:29 -0500 Subject: MySQLdb LIKE '%%%s%%' problem In-Reply-To: <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> References: <4017fe4c-2c0f-417b-aefc-cfb1a78dcfd0@m22g2000vbp.googlegroups.com> <859fbcac-9dfb-4a1c-98e4-eada4a58fb2b@g1g2000pra.googlegroups.com> Message-ID: John Machin wrote: > On Jan 14, 9:42 pm, Steve Holden wrote: > >> 3. I can't be certain my experience with PostgreSQL extends to MySQl, >> but I have done experiments which prove to my satisfaction that it isn't >> possible to parameterize LIKE arguments. So the only way to do it >> appears to be to build the query yourself. This means that you will need >> to make sure the string is made "safe", typically by replacing each >> occurrence of the string "'" with "''" to retain the syntactic integrity >> of the SQL statement. So finally, try >> >> cursor.execute("""UPDATE tablename set fieldx='test' >> WHERE flfieldx IS NULL >> AND fieldy LIKE '%%%s%%'""" % >> certainvalue.replace("'", "''")) > > It appears possible to parameterise LIKE arguments in sqlite3: > 8<--- code > import sqlite3 > tests = [ > ["select * from foo", None], > ["select * from foo where text like '%o%'", None], > ["select * from foo where text like ?", "o"], > ["select * from foo where text like ?", "a"], > ] > conn = sqlite3.connect("c:/junk/sql_like/foodb") > curs = conn.cursor() > for testno, test in enumerate(tests): > sql, parm = test > print "\n=== Test %d ===" % (testno + 1) > print "sql =", sql > print "parm =", parm > if parm is None: > curs.execute(sql) > else: > arg2 = "%" + parm + "%" > curs.execute(sql, (arg2, )) > results = curs.fetchall() > print "results:", results > 8<--- output > > === Test 1 === > sql = select * from foo > parm = None > results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',), > (u'echo',), (u'foxtrot',)] > > === Test 2 === > sql = select * from foo where text like '%o%' > parm = None > results: [(u'bravo',), (u'echo',), (u'foxtrot',)] > > === Test 3 === > sql = select * from foo where text like ? > parm = o > results: [(u'bravo',), (u'echo',), (u'foxtrot',)] > > === Test 4 === > sql = select * from foo where text like ? > parm = a > results: [(u'alpha',), (u'bravo',), (u'charlie',), (u'delta',)] > Thanks. So this is probably a driver, or a platform, restriction. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Wed Jan 14 11:34:36 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:34:36 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <7x4p01x2w3.fsf@ruckus.brouhaha.com> Terry Reedy writes: > The question is where such checks should be. Guido prefers separate > checkers (PyChecker, PyLint) rather than in the interpreter. Again, there have to be some language extensions to communicate the necessary info to the external tool. Python 3.0 begins to do that, but as others have mentioned, it's still in a formative state while we get more experience with it. The other angle is that the compiler can use static knowledge about the program to make the program run faster, so if the checks are in an external tool, there has to be communication in both directions to make use of that. From ivan.illarionov at gmail.com Wed Jan 14 11:37:28 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 08:37:28 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> On Jan 14, 1:49?pm, Ben Sizer wrote: > No, I don't want to do anything with sys.path apart from see it. I > just wanted my original question answered, not a guess at my intent > and a solution for something I'm not doing. ;) ?Thanks though! > > Again - why can I not reference sys from within the function? Ah, sorry for wrong guess. I would try to use ourNamespace_ dict for both globals and locals in PyRun_String call. -- Ivan From steve at holdenweb.com Wed Jan 14 11:44:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 11:44:35 -0500 Subject: point class help In-Reply-To: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: r wrote: > I am hacking up a point class but having problems with how to properly > overload some methods. in the __add__, __sub__, __iadd__, __isub__, I > want to have the option of passing an instance or a container(list, > tuple) like > >>>> p1 = Point2d(10,10) >>>> p1 += (10,10) >>>> p1 > Point2d(20,20) >>>> p2 = Point2d(10,10) >>>> p2 += p1 >>>> p2 > Point2d(30,30) > > > here is what i have, it would seem stupid to use a conditional in each > method like this... > > def method(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > #modify self.x & self.y with x&y > > there must be a way to get the x, y with reusable code, i am not about > to have this conditional under every method call, What am i missing > here? > Not much. If you want these points to be freely mixable with containers then you should define a function like makePoint: def makePoint(x): if type(x) is Point: # assumes new-style classes return x else: return Point(x) > > class Point2d(): > def __init__(self, x, y=None): > if type(x) == tuple: > self.x = x[0] > self.y = x[1] > else: > self.x = x > self.y = y > > def __str__(self): > return 'Point2d(%f, %f)' %(self.x, self.y) > > def __add__(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > return (self.x+x, self.y+y) > > def __sub__(self, other): > pass > > def __iadd__(self, other): #+= > pass > > def __isub__(self, other): #-= > pass > > any ideas? Then your __add__ method would become: def __add__(self, other): other = makePoint(other) return (self.x+other.x, self.y+other.y) Thous it does seem particularly perverse to have the add method not itself return a Point. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Wed Jan 14 11:45:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:45:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <7xab9t7s5h.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Why don't you do it backwards? > You *can* implement a metaclass that will remove the dynasmism from its > instances. Do it - I can give you a starting point if you wish. That's kind of interesting, how does it work? > But most of us are very happy with the dynamic nature of python... I chose > python _because_ of it. I like it too, since it is indispensable in some situations. But, those situations are uncommon enough that I don't mind typing a few extra keystrokes to turn the dynamism on. > Btw, for performance, there is __slots__, That is a good point, we somehow lost sight of that in this thread. > with the side-effect that it forbids attribute creation 'on the > fly'. I have had the impression that this is a somewhat accidental side effect and shouldn't be relied on. From p3dda.adam at googlemail.com Wed Jan 14 11:47:16 2009 From: p3dda.adam at googlemail.com (p3dda.adam at googlemail.com) Date: Wed, 14 Jan 2009 08:47:16 -0800 (PST) Subject: Mod_python, jsonrpc and sessions Message-ID: <5da6ec34-673a-468c-a67c-7ad2bdbe32f8@r10g2000prf.googlegroups.com> Hi, I've got a python web-application being served by apache via mod_python, in which the users sessions are tracked via the mod_python Session module. Some of websites generated contain a java-script function which starts a jsonrpc call to the same server and gets further data or stores something to a database (AJAX). The server-sided jsonrpc functions are written in python as ServiceMethods. As I need to identify the user issuing the rpc call, I'm wondering if there is any possibility to access the session created by the previosly called mod_python Handler-method. In mod_python it is accessed using the mod_python request object, but in the rpc servicemethod I don't have such an object. So how can I track the rpc caller? Any ideas and hints appreciated. Peter From p3dda.adam at googlemail.com Wed Jan 14 11:47:18 2009 From: p3dda.adam at googlemail.com (p3dda.adam at googlemail.com) Date: Wed, 14 Jan 2009 08:47:18 -0800 (PST) Subject: Mod_python, jsonrpc and sessions Message-ID: <1e1eaa10-5e93-4961-9224-ff16ea8e9a93@w24g2000prd.googlegroups.com> Hi, I've got a python web-application being served by apache via mod_python, in which the users sessions are tracked via the mod_python Session module. Some of websites generated contain a java-script function which starts a jsonrpc call to the same server and gets further data or stores something to a database (AJAX). The server-sided jsonrpc functions are written in python as ServiceMethods. As I need to identify the user issuing the rpc call, I'm wondering if there is any possibility to access the session created by the previosly called mod_python Handler-method. In mod_python it is accessed using the mod_python request object, but in the rpc servicemethod I don't have such an object. So how can I track the rpc caller? Any ideas and hints appreciated. Peter From davide.picca at gmail.com Wed Jan 14 11:48:26 2009 From: davide.picca at gmail.com (codicedave) Date: Wed, 14 Jan 2009 08:48:26 -0800 (PST) Subject: os system command not found References: <42cf26f3-c347-4489-92ea-d0297e5f0db9@v5g2000prm.googlegroups.com> <3df592bc-b544-4e63-b54e-fbdd1bdafb0a@s1g2000prg.googlegroups.com> Message-ID: On 14 Gen, 15:30, Daniel da Silva wrote: > On Jan 14, 5:25?am, codicedave wrote: > > > > > Hi all! > > I installed a external program called infomap using the classical > > procedure > > > ./configure > > make > > sudo make install > > > ?and it works perfectly in Terminal (Os x) using both bash and tcsh > > shell > > > admins-macbook-pro-2:~ unil$ infomap-build > > > Usage: infomap-build [-w working_dir] [-p param_file] > > ? ? ? ?[-D var_1=val_1 ... -D var_N=val_N] > > ? ? ? ?(-s single_corpus_file | -m multi_file_list) > > ? ? ? ? > > > ?but when I call it from python using os.system or subprocess.call I > > get the message "sh: infomap-build: command not found". > > > Do you know why? > > > Many thanks > > > Davide > > Type "which infomap-build" from the command line to find out where > infomap-build is. Thank you all guys I tried to use "which" command and found it in /usr/local/bin it seemed to work but at the end I think there is a dependency problem now it can not find another program called by infomap-build bin/sh: prepare_corpus: command not found make: *** [/tmp/unil/infomap_working_dir/prova/wordlist] Error 127 (take a look above) Process begun ../files/filename.txt.sst.clean Sourcing param file "/usr/local/share/infomap-nlp/default-params" Sourcing extra param file "/tmp/infomap-build.1eD7KR" Contents are: Removing extra param file WORKING_DATA_DIR = "/tmp/unil/infomap_working_dir/prova" CORPUS_DIR = "../files" CORPUS_FILE = "../files/filename.txt.sst.clean" FNAMES_FILE = "" ROWS = "20000" COLUMNS = "1000" SINGVALS = "100" SVD_ITER = "100" PRE_CONTEXT_SIZE = "30" POST_CONTEXT_SIZE = "30" WRITE_MATLAB_FORMAT = "0" VALID_CHARS_FILE = "/usr/local/share/infomap-nlp/valid_chars.en" STOPLIST_FILE = "/usr/local/share/infomap-nlp/stop.list" COL_LABELS_FROM_FILE = "0" COL_LABEL_FILE = "" echo "Making datadir" Making datadir mkdir -p /tmp/unil/infomap_working_dir/prova ================================================== Building target: /tmp/unil/infomap_working_dir/prova/wordlist Prerequisites: ../files/filename.txt.sst.clean Wed Jan 14 17:43:21 CET 2009 .................................................. prepare_corpus \ -cdir "../files" \ -mdir "/tmp/unil/infomap_working_dir/prova" \ -cfile "../files/filename.txt.sst.clean" \ -fnfile "" \ -chfile "/usr/local/share/infomap-nlp/valid_chars.en" \ -slfile "/usr/local/share/infomap-nlp/stop.list" \ -rptfile "" /bin/sh: prepare_corpus: command not found make: *** [/tmp/unil/infomap_working_dir/prova/wordlist] Error 127 any idea? thanks From rt8396 at gmail.com Wed Jan 14 11:50:52 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 08:50:52 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: <85f4d33e-c5d8-4438-badf-69f68fdba581@e6g2000vbe.googlegroups.com> On Jan 14, 10:44?am, Steve Holden wrote: > Thous it does seem particularly perverse to have the add method not > itself return a Point. Thanks Steve, i was going implement exactly this but thought there "might" be a better way i did not know about. So i feel better about myself already. And your right, i should be returning a Point2d() Many Thanks From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 11:51:17 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 17:51:17 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xljtdkim7.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> Message-ID: <496e1804$0$3515$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> If the programmer could >>> somehow disallow it in certain classes, >> Already possible - you just have to provide your own implementation of >> __setattr__. > > Part of the idea of non-dynamic attribute sets is to make the program > run faster, not slower. Russ argument was about "good engineering", not about raw perfs. FWIW, _you_ may be willing to trade dynamism for raw perfs, but there are probably some people here that won't agree. From kevin.jingqiu at caseware.com Wed Jan 14 11:55:20 2009 From: kevin.jingqiu at caseware.com (Kevin Jing Qiu) Date: Wed, 14 Jan 2009 11:55:20 -0500 Subject: Weird behaviour re: Python on Windows Message-ID: It's run as Administrator. The problem here is why it behaves differently when in debug mode or interactive shell than in the non-debug mode? -----Original Message----- From: python-list-bounces+kevin.jingqiu=caseware.com at python.org [mailto:python-list-bounces+kevin.jingqiu=caseware.com at python.org] On Behalf Of Jerry Hill Sent: Tuesday, January 13, 2009 11:43 PM To: python-list (General) Subject: Re: Weird behaviour re: Python on Windows On Tue, Jan 13, 2009 at 5:29 PM, Kevin Jing Qiu wrote: > I've been experiencing weird behavior of Python's os module on Windows: > > Here's the environment: > Box1: Running Windows 2003 Server with Apache+mod_python > Box2: Running Windows 2003 Server with Zope/Plone and Z:\ mapped to D:\ > on Box1 > > It appears any os calls that deals with file/dir on the mapped drive is > problematic. What user is this running as? By any chance is it running as the Local System user? If so, that user has no network privileges, including to mapped drives. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list -- Click the link below to report this message as spam to Caseware E-Mail Security Server ESVA. http://esva3.caseware.com/cgi-bin/learn-msg.cgi?id=404585D8606.052FD From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 11:56:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 17:56:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <496e1945$0$11785$426a74cc@news.free.fr> Paul Rubin a ?crit : > "James Mills" writes: >> You do realize this is a model and not strictly a requirement. Quite >> a few things in Python are done merely by convention. >> Don't get caught up. > > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. > > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. Given that the convention for "protected" attributes in Python is to prefix them with an underscore, I fail to see how one could "accidentally" mess with implementation details. Typing a leading underscore is rarely a typo. Oh, BTW, IIRC, there are a couple lint-like apps for Python, some of them being able to warn you about most of these (potential) problems. From rdcollum at gmail.com Wed Jan 14 11:56:43 2009 From: rdcollum at gmail.com (Roger) Date: Wed, 14 Jan 2009 08:56:43 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: On Jan 14, 8:08?am, r wrote: > I guess where i come from > freedom is second nature so i took to python pretty quick. Wow, that's presumptive, assuming, and harsh. Not at all helpful and unnecessary. Geez... From http Wed Jan 14 11:58:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 08:58:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> Message-ID: <7xpripzuwp.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Russ argument was about "good engineering", not about raw perfs. FWIW, > _you_ may be willing to trade dynamism for raw perfs, but there are > probably some people here that won't agree. Obviously there will never be total unanimity about every tiny thing. I haven't anywhere in this thread as far as I know suggested eliminating dynamism from Python, which would be in "that's not Python any more" territory. But, in the dozens of class definitions I write in any given day of coding, I might use the dynamism we're talking about in 1% of them at most. If having to type a few extra keystrokes on that 1% improves program reliabiity AND performance, it certainly seems worth it to me. From kylotan at gmail.com Wed Jan 14 12:00:01 2009 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 14 Jan 2009 09:00:01 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: On Jan 14, 4:37?pm, Ivan Illarionov wrote: > > I would try to use ourNamespace_ dict for > both globals and locals in PyRun_String call. I will try it when I get home. However I would like to be able to treat them as separate dictionaries, as I want to be able to import some symbols and modules at a global level, but be able to clear out objects introduced at the local level on a periodic basis, so that I can have some degree of isolation between distinct 'scripts'. The docs aren't terribly clear about what the globals and locals parameters to PyRun_String actually do, though. I also wonder if this is something specific to the sys module, since it's already been shown that there are some specific C API functions for it. I will try with other modules and see if they exhibit the same symptoms. And I'm still wondering about the sys.path[0] question. :) -- Ben Sizer From http Wed Jan 14 12:00:38 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:00:38 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <496e1945$0$11785$426a74cc@news.free.fr> Message-ID: <7xljtdzutl.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Given that the convention for "protected" attributes in Python is to > prefix them with an underscore, I fail to see how one could > "accidentally" mess with implementation details. Typing a leading > underscore is rarely a typo. We are talking about the accidental creation of new attributes in places outside the initializer. The underscore convention does nothing to prevent that. From kyrie at uh.cu Wed Jan 14 12:03:05 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 12:03:05 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9tj1xw.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9tj1xw.fsf@ruckus.brouhaha.com> Message-ID: <200901141203.05313.kyrie@uh.cu> On Wednesday 14 January 2009 11:18:51 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > when you need to share some objects with potentially untrusted code > > (like, a plugin system). You can't, and you shouldn't, expect that the > > user will know what plugins he should or shouldn't load, and you > > shouldn't blame him/her when your app stops working because you failed to > > protect it's internals from malicious plugins (think web browser). > > Python is not set up for this even slightly. Java attempts it, with > mixed success. I know. I find it sad, though. Also, I find it not a priority. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 12:08:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 18:08:44 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqtkqi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> Message-ID: <496e1c1b$0$24829$426a74cc@news.free.fr> Paul Rubin a ?crit : > "James Mills" writes: >> Python is a dynamic object oriented language ... (almost verbatim >> from the website). It is compiled to bytecode and run on a virtual >> machine. > > 1. There is nothing inherent about dynamic languages that prevents > them from being compiled. There are compiled implementations of > Lisp and Scheme that beat the pants off of Python in performance. Yes. If you're really that concerned about Python's performances, you may want to contribute to Pypy. > 2. There is also nothing inherent in a dynamic OO language that says > that class descriptors have to be mutable, Nope, but that's how Python is designed, and we are quite a few here that value this more than raw perfs. > any more than strings have > to be mutable (Python has immutable strings). I agree that being able > to modify class descriptors at runtime is sometimes very useful. The > feature shouldn't be eliminated from Python or else it wouldn't be > Python any more. But those occasions are rare enough that having to > enable the feature by saying (e.g.) "@dynamic" before the class > definition doesn't seem like a problem, This imply that you (as the library author) pretend to know by advance when your users (programmers) will have a need for dynamism and when they won't. Fact is : you never know. It's the same old horse as enforcing access restriction : the net result is that you prevent users (which, I repeat, are programmers) to use your library as they see fit. From ivan.illarionov at gmail.com Wed Jan 14 12:17:54 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 09:17:54 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: On Jan 14, 8:00?pm, Ben Sizer wrote: > I will try it when I get home. However I would like to be able to > treat them as separate dictionaries, as I want to be able to import > some symbols and modules at a global level, but be able to clear out > objects introduced at the local level on a periodic basis, so that I > can have some degree of isolation between distinct 'scripts'. The docs > aren't terribly clear about what the globals and locals parameters to > PyRun_String actually do, though. > > I also wonder if this is something specific to the sys module, since > it's already been shown that there are some specific C API functions > for it. I will try with other modules and see if they exhibit the same > symptoms. After quick testing it looks like '__builtins__' must be in locals dictionary for your embed Python code to work, it may be a separate dictionary from globals though. >From what I know 'sys' module is related to builtins. My knowledge of Python internals is not so deep to explain the details of this relationship and answer your question about sys.path[0] though. -- Ivan From kyrie at uh.cu Wed Jan 14 12:23:58 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 12:23:58 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9t7s5h.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <200901141223.58207.kyrie@uh.cu> On Wednesday 14 January 2009 11:45:46 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > Why don't you do it backwards? > > You *can* implement a metaclass that will remove the dynasmism from its > > instances. Do it - I can give you a starting point if you wish. > > That's kind of interesting, how does it work? Proof of concept, that breaks on inheritance (can't call 'super'), but it took me just a few minutes to cook. If you aren't that paranoid, you could get rid of the 'currentframe' and 'code' hacks. This creates a class "MyClass" which instances cannot be modified. I once gave my students the homework of creating a metaclass that would type-check all the assignments to its members - so that the types wouldn't change. ======== import inspect class ImmutableType(type): def __init__(self, *args, **kwds): super(ImmutableType, self).__init__(*args, **kwds) initmethod = self.__init__.im_func def setattr(instance, attr, value): callee = inspect.currentframe(1) #letting the initializer if callee.f_code is initmethod.func_code: #initialize the object super(self, instance).__setattr__(attr, value) else: raise Exception("Object is immutable") self.__setattr__ = setattr # Heh, I'm adding a dynamic attribute :D class MyClass(object): __metaclass__ = ImmutableType a = 5 def __init__(self, value): print "assigning b" self.b = value print self.b m = MyClass("can't change") print m.a, m.b # these work m.b = 6 # and these dont. m.c = 8 ========== > > But most of us are very happy with the dynamic nature of python... I > > chose python _because_ of it. > > I like it too, since it is indispensable in some situations. But, > those situations are uncommon enough that I don't mind typing a few > extra keystrokes to turn the dynamism on. I find the opposite to be true. I _usually_ want the dynamism. Even if I'm not using it - I rely on the dynamism to be there for when I need it. > > Btw, for performance, there is __slots__, > > That is a good point, we somehow lost sight of that in this thread. > > > with the side-effect that it forbids attribute creation 'on the > > fly'. > > I have had the impression that this is a somewhat accidental side > effect and shouldn't be relied on. Yes, accidental side effect. But I see no _necessary_ harm on tacking extra attributes to an existing object - specially if you are going to use them pretty close to the creation. I use them, a lot, specially when writing decorators... Many times I just want to 'mark' the decorated functions so I can inspect those marks later. I'd rather have a semi-private namespace for each pair ([group of]calling function[s], object), but it is way easier (and so far, maintanable) to just add an appropriately named dynamic attribute to the object. Of course there can be harm - but the fault lies on the user and not the tool. I specially dislike that I can't add dynamic attributes to an object(). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From http Wed Jan 14 12:29:02 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:29:02 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> Message-ID: <7x4p01pzj5.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > But those occasions are rare enough that having to > > enable the feature by saying (e.g.) "@dynamic" before the class > > definition doesn't seem like a problem, > > This imply that you (as the library author) pretend to know by advance > when your users (programmers) will have a need for dynamism and when > they won't. We're not talking about libraries here. But in fact, we do have extensible and non-extensible versions of certain libraries (pickle, StringIO) so that the user can pick the one that suits their requirements. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 12:46:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 18:46:23 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> Message-ID: <496e24ed$0$20343$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 13, 7:32 pm, "James Mills" > wrote: >> On Wed, Jan 14, 2009 at 1:18 PM, Russ P. wrote: >>> Yes, but the fact that you can approximate OO programming in a >>> particular language does not make that language object oriented. You >>> can approximate OO programming in C, but that does not mean that C is >>> an OO language. >> Wrong. Not having strict and enforced access control 9_NOT_ encapsulation) >> (Please stop confusing the two) is not a strict requirements of the OO model. > > I think you are the one who is confused. Part of the problem here is > that the term "encapsulation" has at least two widely used meanings > (in the context of programming). In one sense, it just means grouping > data and methods together. In another sense, it means restricting the > client's access to data or methods. The second is named "data hiding". And while it's a mean to _enforce_ encapsulation, it is not encapsulation by itself. Encapsulation is about making clear what's part of the public interface and what's implementation detail - IOW, it's about decoupling client code from implementation. Nothing in this _requires_ data hiding. > Someone earlier on this thread > tried to claim that the first meaning applies to OOP, but Wikipedia > (and many other sources) say just the opposite. You can choose to trust everything you read on wikipedia. You can... wrt/ what's OO, the only commonly accepted definitions are: 1/ objects are defined by an identity, a state and a behaviour 2/ objects communicate by sending messages to each other > People here are trying to claim that the leading underscore > conventions used with Python are essentially equivalent to > encapsulation. That is nonsense, of course. Your POV. > But the point is that if you don't like > encapsulation, I do like it. What I don't like is useless language-enforced restrictions. > then by definition you don't like OOP. You may like > certain features of OOP, but you don't like it in general. That's > about all their is to it. > > And by the way, please don't bring up the canard that I am some kind > of OO zealot. I think OO is overrated, and I don't Java, in part > because it forces everything to be OO. The issue here is not my > personal opinion of OOP. This issue is one of widely accepted > definitions within the OO community. Another widely accepted definition within the OO community is that C++ is an OO language because it has classes and data-hiding, and that Javascript is not because it has none of them. > >> Remember that it is a model and not a strict set of requirements that >> programming >> languages must implement. > > Of course it's not a "requirement that programming languages must > implement." It's only a requirement if they want to be OO languages. Neither. The only requirements for being an OOPL are stated above. >> In fact, Python borrows features from the Functional Paradigm. Does this >> make it a Functional Language ? No. Why ? Because one of the clear >> requirements of the Functional Paradigm is that functions cannot have >> side affects. >> >>> So I can claim that Python is not strictly object oriented You can claim it, yes. OTHO, I can claim that Java is not strictly object oriented since it has non-object types. In both cases, this is just plain meaningless. There's no closed, well-defined theory, no mathematical model behind "OO" (like there are for functional programming or for the relational model). So you just can't apply "strictly" to OO. It's just nonsense. >>> until it >>> gets encapsulation (in the sense of data hiding). That is simply a >>> fact, and no amount of pleading or obfuscation will change it. IOW : "this is the HolyTruth(tm), because I said so". Sorry, won't work. >> In fact this is true, C can be seen as an programming language >> that has features of the OO model. Yes. And FWIW, there are OO libraries and programs written in plain C. Ever heard of GTK+ ? >> I think one of the things you guys are missing out >> here is that there are really only two Paradigms >> or Machines. Functional and Imperative. And guess >> what ? As it turns out we can implement functional >> machines that run on top of imperative ones! >> >>> Should Python get true encapsulation? I don't know. Maybe >>> encapsulation cannot be added without excessive overhead or without >>> compromising other more important aspects and features of the >>> language. But I do know that not having encapsulation is a limitation >>> to the use of Python for good software engineering. For a somewhat partial definition of "good software engineering". Mine is that anything that leads to a correct, robuste and maintainable program is good engineering, anything else is not. From this POV, and given the proven fact that the bug/LOC ratio is nearly constant whatever the language, anything that adds accidental complexity makes the program less robust and less maintainable, and as such is _not_ "good software engineering". Sorry for being pragmatic !-) >>> I may be in the >>> minority in the Python "community" on this one, but I am apparently in >>> the majority in the OO programming "community." >> Again, stop confusing terminology. >> >> Should Python get strict and enforce access control >> of object members ? No. Why ? I can think of several >> reasons. >> >> Give me one use-case where you strictly require >> that members of an object be private and their >> access enforced as such ? > > You're kidding, right? Think about a ten-million line program being > developed by 100 developers. And ? Except that this code surely needs urgent surgery (sorry, I meant refactoring), I don't see what the size of the project or the team has to do with it. You'll find successful "monster" projects written in languages that are even more permissive than Python (C anyone ?), and failed "monster" projects written in highly unpermissive languages like Java or ADA. From http Wed Jan 14 12:54:13 2009 From: http (Paul Rubin) Date: 14 Jan 2009 09:54:13 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <2a478506-1979-4dff-acc3-9af646717171@w1g2000prm.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> Message-ID: <7xvdshhiyi.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > You'll find successful "monster" projects written in > languages that are even more permissive than Python (C anyone ?), Could you name one written in C? Anyway, C is far less safe than Python in some ways, but has lots more compile time checking. From Scott.Daniels at Acm.Org Wed Jan 14 12:57:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 14 Jan 2009 09:57:28 -0800 Subject: can someone tell me why this doesn't work please python 3 In-Reply-To: References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> <496DFA4D.6090801@byoteki.com> <8B85F1CD-624D-4EB6-9670-647EB774BF0C@case.edu> Message-ID: Gary M. Josack wrote: > Ben Kaplan wrote: >> On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" wrote: >>> garywood wrote: >>>> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"): >>>> while True: >>>> password = input("enter something") >>>> if password in ('y', 'ye', 'yes'): return True >>>> if password in ('n', 'no', 'nope'): return False >>>> retries = retries - 1 >>>> if retries < 0: >>>> raise IOError('refusenik user') >>>> print(complaint) >>> Well since you didn't give an error I'm going to assume your problems >>> are as follows: >>> * Use raw_input() instead of input() # input evals the input received. >>> * pass prompt as the argument to raw_input so that your prompt gets >>> set # might want to give prompt a default value >>> * password.lower() so Y, YE, YES, N, NO, NOPE also work for input >> Did you miss the python 3 part? Raw_input was removed and input now >> behaves like raw_input did in 2.x > Ah, yes. Subject got truncated on my little laptop screen. Either way, > more information is needed to diagnose the problem. It is a bad idea to have post content exclusively in the headers. Readers sometimes select by subject, but only read content. However the answer the OP is looking for with his ill-formed question could be revealed if his final print were: print('%s on reply %r' % (complaint, password)) He'd realize he wanted: password = input(prompt).rstrip() --Scott David Daniels Scott.Daniels at Acm.Org From ivan.illarionov at gmail.com Wed Jan 14 13:03:35 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Wed, 14 Jan 2009 10:03:35 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: <12810ebb-9047-4096-815f-0d8639b309f2@r38g2000vbi.googlegroups.com> On Jan 14, 8:17?pm, Ivan Illarionov wrote: > On Jan 14, 8:00?pm, Ben Sizer wrote: > > > I will try it when I get home. However I would like to be able to > > treat them as separate dictionaries, as I want to be able to import > > some symbols and modules at a global level, but be able to clear out > > objects introduced at the local level on a periodic basis, so that I > > can have some degree of isolation between distinct 'scripts'. The docs > > aren't terribly clear about what the globals and locals parameters to > > PyRun_String actually do, though. > > > I also wonder if this is something specific to the sys module, since > > it's already been shown that there are some specific C API functions > > for it. I will try with other modules and see if they exhibit the same > > symptoms. > > After quick testing it looks like '__builtins__' must be in locals > dictionary for your embed Python code to work, it may be a separate > dictionary from globals though. > > From what I know 'sys' module is related to builtins. My knowledge of > Python internals is not so deep to explain the details of this > relationship and answer your question about sys.path[0] though. Sorry, I probably was terribly wrong in my last post, it doesn't work this way with separate dictionaries. I never had to use separate dictionaries. Maybe someone with better knowledge of Python internals may help? -- Ivan From kyrie at uh.cu Wed Jan 14 13:07:39 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 13:07:39 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xvdshhiyi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> Message-ID: <200901141307.39415.kyrie@uh.cu> On Wednesday 14 January 2009 12:54:13 pm Paul Rubin wrote: > Bruno Desthuilliers writes: > > You'll find successful "monster" projects written in > > languages that are even more permissive than Python (C anyone ?), > > Could you name one written in C? hmm... http://kernel.org -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From http Wed Jan 14 13:13:46 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:13:46 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> Message-ID: <7x3aflwyat.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > > You'll find successful "monster" projects written in > > > languages that are even more permissive than Python (C anyone ?), > > > > Could you name one written in C? > > hmm... http://kernel.org That project may be successful in terms of having a lot of users, but much less so in terms of code reliability (see all the CERT bulletins about it). Also, it is much smaller than 10 MLOC, I think. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 14 13:17:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 19:17:36 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpripzuwp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: <496e2c3f$0$29454$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Russ argument was about "good engineering", not about raw perfs. FWIW, >> _you_ may be willing to trade dynamism for raw perfs, but there are >> probably some people here that won't agree. > > Obviously there will never be total unanimity about every tiny thing. Indeed !-) > I haven't anywhere in this thread as far as I know suggested > eliminating dynamism from Python, Nope, but your suggestion would have the same practical result as far as I'm concerned. > which would be in "that's not Python > any more" territory. But, in the dozens of class definitions I write > in any given day of coding, I might use the dynamism we're talking > about in 1% of them at most. Indeed : these are the classes _you_ (as a library author), write, so they work as _you_ (as a user of these library) expect them to work. > If having to type a few extra keystrokes > on that 1% improves program reliabiity AND performance, it certainly > seems worth it to me. If it makes simple thing overly complicated, it certainly seems _worse_ to me !-) From http Wed Jan 14 13:21:01 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:21:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: <7xab9t3g1e.fsf@ruckus.brouhaha.com> Carl Banks writes: > Guess what systems I worked on that didn't even use scoping? I wrote > code for the GP7000 (equipped on some Airbus 380s) and the F-136 > (which will be equipped on some F-35 fighters) engine controllers. > Neither one used any data hiding. The language was C (not C++), but > it was generated from schematic diagrams. Generated from a schematic by a program you mean? In that case, the C was used sort of like assembly code emitted by a compiler. Not really the same situation. > Would you like to adopt GE's practice of schematic-generated C with no > namespaces or data hiding? No? Then don't be telling me I have to > embrace Boeing's. All you're telling us is that GE makes foolish choices. From http Wed Jan 14 13:22:53 2009 From: http (Paul Rubin) Date: 14 Jan 2009 10:22:53 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> Message-ID: <7x63kh3fya.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > I haven't anywhere in this thread as far as I know suggested > > eliminating dynamism from Python, > > Nope, but your suggestion would have the same practical result as far > as I'm concerned. Sorry, I don't comprehend that. The rest of your post makes no sense as a consequence. Python already had such a change when it deprecated and later got rid of string exceptions. It's still Python. From Russ.Paielli at gmail.com Wed Jan 14 13:32:47 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 10:32:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: On Jan 14, 1:54?am, Carl Banks wrote: > I thought you were done wasting time with this nonsense. So did I. > > An engine *simulation* is one > > thing; the actual engine control code is another. > > Guess what systems I worked on that didn't even use scoping? ?I wrote > code for the GP7000 (equipped on some Airbus 380s) and the F-136 > (which will be equipped on some F-35 fighters) engine controllers. > Neither one used any data hiding. ?The language was C (not C++), but > it was generated from schematic diagrams. > > Would you like to adopt GE's practice of schematic-generated C with no > namespaces or data hiding? ?No? ?Then don't be telling me I have to > embrace Boeing's. Well, that's interesting. But you say the code was "generated from schematic diagrams." Does that mean it was automatically generated by machine? If so, then the concerns about encapsulation may no longer apply. In that case, the schematics were the implementation "language," and the code that was generated was essentially a higher level version of assembly or machine code (because humans don't work with it directly). I know some researchers in software engineering who believe that the ultimate solution to software reliability is automatic code generation. The don't really care much which language is used, because it would only be an intermediate form that humans don't interact with directly. In that scenario, humans would essentially use a "higher level" language such as UML or some such thing. I personally have a hard time seeing how that could work, but that may just be due to be my own lack of understanding or vision. From benjamin.kaplan at case.edu Wed Jan 14 13:34:06 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 14 Jan 2009 13:34:06 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3aflwyat.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496e24ed$0$20343$426a74cc@news.free.fr> <7xvdshhiyi.fsf@ruckus.brouhaha.com> <7x3aflwyat.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 14, 2009 at 1:13 PM, Paul Rubin <"http://phr.cx"@nospam.invalid>wrote: > Luis Zarrabeitia writes: > > > > You'll find successful "monster" projects written in > > > > languages that are even more permissive than Python (C anyone ?), > > > > > > Could you name one written in C? > > > > hmm... http://kernel.org > > That project may be successful in terms of having a lot of users, but > much less so in terms of code reliability (see all the CERT bulletins > about it). Also, it is much smaller than 10 MLOC, I think. It just recent passed the 10 million mark. http://www.heise-online.co.uk/open/Kernel-Log-Higher-and-Further-The-innovations-of-Linux-2-6-28--/features/112299/5 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.sakkis at gmail.com Wed Jan 14 13:44:20 2009 From: george.sakkis at gmail.com (George Sakkis) Date: Wed, 14 Jan 2009 10:44:20 -0800 (PST) Subject: Preserving file permissions with distutils Message-ID: I'm trying to use distutils to install some package data and additional files, some of which may be executable. It turns out that distutils does not preserve the permissions. Digging in the code, there is the following comment on distutils/command/build_py: # XXX copy_file by default preserves mode, which appears to be the # wrong thing to do: if a file is read-only in the working # directory, we want it to be installed read/write so that the next # installation of the same module distribution can overwrite it # without problems. (This might be a Unix-specific issue.) Thus If the only reason for not preserving the mode is ensuring it's read/ write, why not preserve the rest permissions and set the write flag for the owner ? The comment continues: # we turn off 'preserve_mode' when copying to the build directory, # since the build directory is supposed to be exactly what the # installation will look like (ie. we preserve mode when # installing). But installing copies from the build dir which has forgotten the original permissions, so there is no actual preservation! Am I reading this wrong or should I submit a bug report ? George From gert.cuykens at gmail.com Wed Jan 14 13:47:43 2009 From: gert.cuykens at gmail.com (gert) Date: Wed, 14 Jan 2009 10:47:43 -0800 (PST) Subject: python3.0 MySQLdb References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> Message-ID: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> On Jan 13, 11:58?pm, "Martin v. L?wis" wrote: > Steve Holden wrote: > > Daniel Fetchinson wrote: > >>> I need something to connect to a database, preferably mysql, that > >>> works in python3.0 please. > >> And your question is? > > > Surely it's fairly obvious that the question is "does such a thing > > exist, and if so where can I find it?". > > Interestingly enough, the question was slightly (but importantly) > different, though: the question really was "Does anybody has a patch for > MySQLdb?"; as my reference to the existing interface to PostgreSQL > was not sufficient for the OP. Yes it was enough, but I can not imagine it has not been done yet for MySql either :) It was a open statement where I expected like 10 different databases responses. For example if you go to a dinner place you have never been gone before and want to try something new and there is no menu available. What do you ask ? You just say something similar. "I would like to order a salet please with some red wine." I don't think any one of you would expect the waiter to answer,"And your question is?" I also think the waiter does not expect me to ask 10 similar questions like "red wine 1991? red wine 1992? red wine 1993? until i hit something that is on the menu" So the final questions was, is there anything els on the menu besides PostgreSQL, like MySql for example ? If not I will take PostgreSQL please. From ajaksu at gmail.com Wed Jan 14 13:56:47 2009 From: ajaksu at gmail.com (ajaksu) Date: Wed, 14 Jan 2009 10:56:47 -0800 (PST) Subject: urllib2 - 403 that _should_ not occur. References: Message-ID: On Jan 14, 5:14?am, Steve Holden wrote: > ajaksu wrote: >> [snip evangelism stuff] > OK, but be aware that the PSF doesn't monitor the bugs looking for > actions to take on behalf of the Python user community. In fact we > aren't overtly "political" in this way at all. This doesn't mean it > wouldn't be useful for the PSF to get involved in this role; just that > right now it isn't, and a bug report probably isn't the best way to get > action. Acknowledged. I have posted a (pretty poor) support request @ http://groups.google.com/group/Google-Groups-Basics/ and suggest others do the same for Wikipedia and other big sites that block 3.0 (I might build a list of those later today). Maybe a wiki page, some blog posts, etc. Best regards, Daniel Request: http://groups.google.com/group/Google-Groups-Basics/browse_thread/thread/498a39a89d81b650# """ Hi, As mentioned in a comp.lang.python thread[1], the new version of Python (3.0) cannot open pages @ groups.google.com. It seems the UA of Python 3.0 ("User-Agent: Python-urllib/3.1") is actively blocked, while that of Python 2.5 ("User-Agent: Python-urllib/ 1.17") isn't. This message is a call for help so that we can get Python 3.0 working with groups.google.com. Is this the right place to bring the issue to the attention of those that can fix it? Does anyone have a contact that could speed up getting Python 3.0 working? Thanks in advance, Daniel [1]http://groups.google.com/group/comp.lang.python/browse_thread/ thread/088491d5a0d86f1b """ From kyosohma at gmail.com Wed Jan 14 14:05:31 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 14 Jan 2009 11:05:31 -0800 (PST) Subject: LGPL license for Qt 4.5 References: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> Message-ID: On Jan 14, 8:20?am, sturlamolden wrote: > On Jan 14, 3:11?pm, "drobi... at gmail.com" wrote: > > > On Jan 14, 7:57?am, sturlamolden wrote: > > > > According to a Norwegian publication, Nokia will release Qt under LGPL > > > as of version 4.5. > > > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > > > For the rest of us, this is fantastic news. > > > >http://digi.no/php/art.php?id=800922 > > >http://www.qtsoftware.com/about/licensing > > > Not sure what this means for PyQt > > It means that: > - If Riverbank keep their dual GPL licensing scheme, somebody else > will make an LGPL 'QtPython' instead. > - If Riverbank change PyQt to LGPL, they will loose most of their > revenue form PyQt. > > In either case, Qt will be available under the same licensing terms as > wxWidgets. > > As of today, the main reason to prefer wxPython over PyQt is the > license. With an LGPL'd Qt, I'd rather ask what this will mean for > wxPython. I'm pretty sure that Qt is mostly (if not all) custom widgets whereas wxPython uses native widgets whenever possible. While this allows Qt to have skinning (a plus!), it also can make them look less than native (a minus!). If they do release a LGPL version, I may take a look at it just to see how different it is, although I'm pretty happy with what I'm using. Mike From martin at v.loewis.de Wed Jan 14 14:08:22 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 14 Jan 2009 20:08:22 +0100 Subject: python3.0 MySQLdb In-Reply-To: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: <496E3826.5080100@v.loewis.de> > So the final questions was, is there anything els on the menu besides > PostgreSQL, like MySql for example ? There is sqlite3 also; it is included in Python 3. Otherwise, I don't think any other DB-API compliant database connectors have been ported to Python 3 yet; it may take many months until somebody volunteers to port a MySQL driver. The difference to your restaurant example is that the market for red wine is many hundred years old. The market for Python 3 modules is just a month old. Hence, you have different offers for red wine, but nearly none for Python 3 modules. Regards, Martin From http Wed Jan 14 14:16:23 2009 From: http (Paul Rubin) Date: 14 Jan 2009 11:16:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> Message-ID: <7x4p01n1fc.fsf@ruckus.brouhaha.com> "Russ P." writes: > I know some researchers in software engineering who believe that the > ultimate solution to software reliability is automatic code > generation. The don't really care much which language is used, because > it would only be an intermediate form that humans don't interact with > directly. In that scenario, humans would essentially use a "higher > level" language such as UML or some such thing. > > I personally have a hard time seeing how that could work, but that may > just be due to be my own lack of understanding or vision. The usual idea is that you would write a specificiation, and a constructive mathematical proof that a certain value meets that specification. The compiler then verifies the proof and turns it into code. Coq (http://coq.inria.fr) is an example of a language that works like that. There is a family of jokes that go: Q. How many $LANGUAGE programmers does it take to change a lightbulb? A. [funny response that illustrates some point about $LANGUAGE]. The instantiation for Coq goes: Q. How many Coq programmers does it take to change a lightbulb? A. Are you kidding? It took two postdocs six months just to prove that the bulb and socket are threaded in the same direction. Despite this, a compiler for a fairly substantial C subset has been written mostly in Coq (http://compcert.inria.fr/doc/index.html). But, this stuff is far far away from Python. I have a situation which I face almost every day, where I have some gigabytes of data that I want to slice and dice somehow and get some numbers out of. I spend 15 minutes writing a one-off Python program and then several hours waiting for it to run. If I used C instead, I'd spend several hours writing the one-off program and then 15 minutes waiting for it to run, which is not exactly better. (Or, I could spend several hours writing a parallel version of the Python program and running it on multiple machines, also not an improvement). Often, the Python program crashes halfway through, even though I tested it on a few megabytes of data before starting the full multi-gigabyte run, because it hit some unexpected condition in the data that could have been prevented with more compile time checking that made sure the structures understood by the one-off script matched the ones in the program that generated the input data. I would be ecstatic with a version of Python where I might have to spend 20 minutes instead of 15 minutes writing the program, but then it runs in half an hour instead of several hours and doesn't crash. I think the Python community should be aiming towards this. From Scott.Daniels at Acm.Org Wed Jan 14 14:20:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 14 Jan 2009 11:20:27 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpripzuwp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > .... I haven't anywhere in this thread as far as I know suggested > eliminating dynamism from Python, which would be in "that's not Python > any more" territory. But, in the dozens of class definitions I write > in any given day of coding, I might use the dynamism we're talking > about in 1% of them at most. If having to type a few extra keystrokes > on that 1% improves program reliabiity AND performance, it certainly > seems worth it to me. But, the research on the language "Self" shows that even in the face of a language with more dynamism than Smalltalk (or Python), performance can be obtained using compiler technology. It turns out you don't have to type those type any extra keystrokes. Compilers capable of doing strong optimization already have to do enough analysis that they can discover the static typing that is available in the code you write naturally. The way to get to such performance on Python is through efforts like PyPy. --Scott David Daniels Scott.Daniels at Acm.Org From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:33:01 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:33:01 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x63kh3fya.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> <7x63kh3fya.fsf@ruckus.brouhaha.com> Message-ID: <496e4b97$0$24021$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> I haven't anywhere in this thread as far as I know suggested >>> eliminating dynamism from Python, >> Nope, but your suggestion would have the same practical result as far >> as I'm concerned. > > Sorry, I don't comprehend that. IIRC, your suggestion was that one should have to explicitely allow "dynamic binding" (ie: outside the initializer) of new attributes, and that the default vould be to disallow them. That's at least what I understood from : """ There are cases where this is useful but they're not terribly common. I think it would be an improvement if creating new object attributes was by default not allowed outside the __init__ method. In the cases where you really do want to create new attributes elsewhere, you'd have to explicitly enable this at instance creation time, for example by inheriting from a special superclass: class Foo (DynamicAttributes, object): pass """ (snip) > Python already had such a change when it deprecated and later got rid > of string exceptions. I really don't get how this would be comparable with the above suggestion. I can well understand your concerns wrt/ Python's performances (even if I don't agree on your proposed solutions), but this one "argument" really looks like a straw man. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:44:04 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:44:04 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01pzj5.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> Message-ID: <496e4e2e$0$10088$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> But those occasions are rare enough that having to >>> enable the feature by saying (e.g.) "@dynamic" before the class >>> definition doesn't seem like a problem, >> This imply that you (as the library author) pretend to know by advance >> when your users (programmers) will have a need for dynamism and when >> they won't. > > We're not talking about libraries here. Yes we are. If the default is "non-dynamic", then a class author is in charge of explicitely allowing it when *he* see fits. > But in fact, we do have > extensible and non-extensible versions of certain libraries (pickle, > StringIO) what we have are python-coded and highly optimized C-coded versions of the same libraries. FWIW, in both cases, the python version came first, and the C implementation followed when it was clear that for these specific libs, the less-dynamic C version's perf improvement justified giving up on dynamism, *given that:* > so that the user can pick the one that suits their requirements. As long as it's up to the *user* to choose, that's ok. Your "@dynamic" class decorator doesn't have the same implications. From bdesth.quelquechose at free.quelquepart.fr Wed Jan 14 14:56:08 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 14 Jan 2009 20:56:08 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xljtdzutl.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <496e1945$0$11785$426a74cc@news.free.fr> <7xljtdzutl.fsf@ruckus.brouhaha.com> Message-ID: <496e5102$0$18840$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Given that the convention for "protected" attributes in Python is to >> prefix them with an underscore, I fail to see how one could >> "accidentally" mess with implementation details. Typing a leading >> underscore is rarely a typo. > > We are talking about the accidental creation of new attributes in > places outside the initializer. Nope. This was about encapsulation and data-hiding, cf: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/068bc54bca830c46/049a721414f4d4da?rnum=41&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F068bc54bca830c46%3F#doc_83a09b54d386eb6c and the convention James refered to was obviously the naming convention. From rt8396 at gmail.com Wed Jan 14 14:56:41 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 11:56:41 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) Message-ID: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> I actually like the IDLE, but it could use a few improvements. If anybody else has suggestions by all means post them. 1.) The text widget and the prompt(>>>) should be separated. Trying to write a conditional in the interactive IDLE is a real PITA. Not to mention if you copy the working code snippet to the IDLE editor window the indention is 8 spaces instead 4 AND you've got that prompt(>>>) stuck in there. I have a solution for the problem though.( I hope you all are using fixed-width font) frm |<---------------------text widget -----------------> >>> | >>> |if this == 1: ... | if that == 2: ... | #do ... | elif that ==3: ... | #do ... | else: ... | pass >>> | >>> |x = 10 Basically you have a Listbox on the left for the prompt and a Text on the right. Disable the Listbox highlight and key press events and now we have a very friendly interactive IDLE! No more prompt hijacking your snippets, and no more 8 space indention! 2.) When you press MMB and there is a highlighted selection in the text it gets pasted over and over again @ the insertion cursor (gives me the red @ss!) Anybody want to comment or add suggestions? From mccredie at gmail.com Wed Jan 14 14:59:48 2009 From: mccredie at gmail.com (Matimus) Date: Wed, 14 Jan 2009 11:59:48 -0800 (PST) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> <85f4d33e-c5d8-4438-badf-69f68fdba581@e6g2000vbe.googlegroups.com> Message-ID: On Jan 14, 8:50?am, r wrote: > On Jan 14, 10:44?am, Steve Holden wrote: > > > Thous it does seem particularly perverse to have the add method not > > itself return a Point. > > Thanks Steve, > i was going implement exactly this but thought there "might" be a > better way i did not know about. So i feel better about myself > already. And your right, i should be returning a Point2d() > Many Thanks I just inherited from tuple and did it like this. Note that this served my needs, but it definitely needs some work to become general purpose. Also note that I used '__new__' instead of __init__, making this type immutable. class Point(tuple): "Simple immutable point class (vector) supports addition and subtraction" def __new__(cls, x, y=None): if y is None: x, y = x return super(Point, cls).__new__(cls,(x, y)) def __add__(self, p): return Point(self[0]+p[0], self[1]+p[1]) def __sub__(self, p): return Point(self[0]-p[0], self[1]-p[1]) def __neg__(self): return Point(-self[0], -self[1]) def __pos__(self): return self def __str__(self): return "Point(%d, %d)"%(self[0], self[1]) __repr__ = __str__ Matt From koranthala at gmail.com Wed Jan 14 15:57:03 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 14 Jan 2009 12:57:03 -0800 (PST) Subject: Python Crashes Message-ID: Hi, I have a twisted based application based on Python 2.4.3. I also have one thread in this application. I found that my program crashes repeatedly after a random interval (ranging from 10 min to 3 hr). When I say crash, it is not just that the program dies. Rather in WinXP - a window comes mentioning that 'Python.exe unexpectedly crashed'. I tried putting in catching the exception by using try: except - and logging everything. But the logging code is also not hit, i.e. even the 'except' code is not hit. I feel that the base python interpreter itself is crashing due to some bug in my program. Earlier, I had put code as try: except: log At this time, my whole machine also froze. It was so slow that one mouse movement happened after 7-8 minutes after I moved the mouse. Then I modified the code to try: except Exception: log Then, the machine no longer freezes. But, still there is no logging of errors happening too. Could anyone guide me on this? I have been facing this issue for a day, and cannot seem to solve it. P.S -> I am not allowed to post the code of application - so I hope I have explained it enough. From philip at semanchuk.com Wed Jan 14 16:02:42 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jan 2009 16:02:42 -0500 Subject: Python Crashes In-Reply-To: References: Message-ID: <2CFF5365-ECA9-49BA-B7AE-37B2BFA1FCD4@semanchuk.com> On Jan 14, 2009, at 3:57 PM, koranthala wrote: > Hi, > I have a twisted based application based on Python 2.4.3. I also > have one thread in this application. > > I found that my program crashes repeatedly after a random interval > (ranging from 10 min to 3 hr). When I say crash, it is not just that > the program dies. Rather in WinXP - a window comes mentioning that > 'Python.exe unexpectedly crashed'. Are you using any 3rd party modules? From kirby.urner at gmail.com Wed Jan 14 16:05:09 2009 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 14 Jan 2009 13:05:09 -0800 (PST) Subject: pythonic chew toyz (a column, by K. Urner) v.1 n.1 Message-ID: <4bc8d545-8148-4dad-86f5-b8c227c7c8b5@w1g2000prm.googlegroups.com> Selena spotted me right away as "the O'Reilly spy", me agreeing she had an exceptionally good memory, maybe we could recruit her? Our banter traces to the first meeting on OS Bridge and how I introduced myself [0], not yet realizing Allison Randal was in the audience (way more an insider, as to how many Ls).[1] Last night in the Roman room (CubeSpace) I proposed she could emcee the panel we're planning (maybe?), after the new Mayor (Sam Adams) kicks it off with a keynote -- all in the proposal stage, looking over her shoulder. I was also there for the __metaclasses__ discussion by John Melesky, and for work, most of that same day (this is PDX CubeSpace, a lot of us rent office space). Jason talked about the __missing__ rib (in dict). As we were getting settled, they talked about OSCON, perking my interest. Whereas some take the view we're somehow competing with San Jose (where a lot of my friends work), my model is more Cirque du Soleil, given where "geeks" come from (something about chickens). Five OSCONs running in parallel in any given summer would make more sense than just one, but then O'Reilly isn't quite as big as McGraw- Hill (BYTE), yet. Anyway, Portland is happy to share the glory. OS Bridge another bulb on the breadboard (aka grid), getting brighter by the day. Speaking of BYTE, I also learned last night that Eliza, our geek therapist, is alive and well in Python, as a part of the Natural Language Toolkit or NLTK. And she's got company. Some of you may recall Hugh Kenner's hilarious investigation of chat bots, then very new, in a way back issue (1980s).[3] Hugh, by the way, was a leading 20th century James Joyce scholar and fan of R. Buckminster Fuller (see 'The Pound Era'), Bucky a champion for me as well (hence my rbf.py -- named after the guy, for use with VPython, POV-Ray, x3d etc., more on edu-sig). I'll catch up again later, maybe from Chicago, maybe before.[4] [1] http://mail.python.org/pipermail/portland/2008-November/000512.html [2] http://mybizmo.blogspot.com/2009/01/ppug-2009113.html [3] http://mathforum.org/kb/message.jspa?messageID=5256703&tstart=0 [4] http://showmedo.com/videos/video?name=1010050&fromSeriesID=101 From kirby.urner at gmail.com Wed Jan 14 16:18:10 2009 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 14 Jan 2009 13:18:10 -0800 (PST) Subject: pythonic chew toyz (a column, by K. Urner) v.1 n.1 Message-ID: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> Selena spotted me right away as "the O'Reilly spy", me agreeing she had an exceptionally good memory, maybe we could recruit her? Our banter traces to the first meeting on OS Bridge and how I introduced myself [0], not yet realizing Allison Randal was in the audience (way more an insider, as to how many Ls in Randall).[1] Last night in the Roman room (CubeSpace) I proposed she could emcee the panel we're planning (maybe?), after the new Mayor (Sam Adams) kicks it off with a keynote -- all in the proposal stage, looking over her shoulder. I was also there for the __metaclasses__ discussion by John Melesky, and for work, most of that same day (this is PDX CubeSpace, a lot of us rent office space). Jason talked about the __missing__ rib (in dict).[2] As we were getting settled, they talked about OSCON, perking my interest. Whereas some take the view we're somehow competing with San Jose (where some of my friends work, or worked in the case of Maxtor and IBM), my model is more Cirque du Soleil, given where "geeks" come from (something about chickens).[3] Five OSCONs running in parallel in any given summer would make more sense than just one, but then O'Reilly isn't quite as big as McGraw- Hill (BYTE), yet. Anyway, Portland is happy to share the glory. OS Bridge is yet another bulb on the breadboard (aka grid), getting brighter by the day. Speaking of BYTE, I also learned last night that Eliza, our geek therapist, is alive and well in Python, as a part of the Natural Language Toolkit or NLTK. And she's got company. Some of you may recall Hugh Kenner's hilarious investigation of chat bots, then very new, in a way back issue (1980s).[4] Hugh, by the way, was a leading 20th century James Joyce scholar and fan of R. Buckminster Fuller (see 'The Pound Era'), Bucky a champion for me as well (hence my rbf.py -- named after the guy, for use with VPython, POV-Ray, x3d etc., more on edu-sig). I'll catch up again later, maybe from Chicago, maybe before.[5] [0] http://mail.python.org/pipermail/portland/2008-November/000512.html [1] http://radar.oreilly.com/allison/ [2] http://mybizmo.blogspot.com/2009/01/ppug-2009113.html [3] http://worldgame.blogspot.com/2007/06/pro-python-propaganda.html [4] http://mathforum.org/kb/message.jspa?messageID=5256703&tstart=0 [5] http://showmedo.com/videos/video?name=1010050&fromSeriesID=101 [ 2nd edition: reformatted, fixed endnotes ] << with thanks to verizon wireless >> From luke.leighton at googlemail.com Wed Jan 14 16:19:47 2009 From: luke.leighton at googlemail.com (lkcl) Date: Wed, 14 Jan 2009 13:19:47 -0800 (PST) Subject: Mod_python, jsonrpc and sessions References: <1e1eaa10-5e93-4961-9224-ff16ea8e9a93@w24g2000prd.googlegroups.com> Message-ID: <0b82a5b5-5bcb-4c31-a4ff-9a172e2d6590@w1g2000prm.googlegroups.com> On Jan 14, 4:47 pm, p3dda.a... at googlemail.com wrote: > Hi, > > I've got a python web-application being served by apache via > mod_python, in which the users sessions are tracked via the mod_python > Session module. > Some of websites generated contain a java-script function which starts > a jsonrpc call to the same server and gets further data or stores > something to a database (AJAX). The server-sided jsonrpc functions are > written in python as ServiceMethods. > > As I need to identify the user issuing the rpc call, I'm wondering if > there is any possibility to access the session created by the > previosly called mod_python Handler-method. In mod_python it is > accessed using the mod_python request object, but in the rpc > servicemethod I don't have such an object. So how can I track the rpc > caller? the only way to store "session" info reliably is: cookies. therefore, the code in one part of the application _will_ have to store a session cookie as an identifier, and you can track the name of that cookie through the source code that created it. or look in the source code for anything beginning with the word "session". "grep - ril" is your friend. also, if the app stores its session authentication information in a database, you can look through the app for the database table name. if you don't _know_ the database table name, and are having difficulty finding out because the design of the app is SHITE then you can do a dump of the database _before_ a session login, and a dump afterwards, and then diff is your friend. if the database is mysql, add --extended-insert=no (something like that) to the mysqldump command otherwise you will have a bitch-awful job identifying the right line. i've done this when working with fricking-joomla, integrating it with django. fireboard. i had to hunt through the php code looking for the database user-session. once you have the session info, that's your "user tracking" function in the rpc calls. none of the above is particularly rocket science - or actually anything to do with python: it's a simple matter of applying investigative techniques logically working from how the technology _should_ work and then bludgeoning it into submission to tell you what the hell's going on. l. From schap at offenbachers.com Wed Jan 14 16:22:20 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 14 Jan 2009 16:22:20 -0500 Subject: QT4 In-Reply-To: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> References: <34bc1fb6-ac49-4e35-9bd8-aa30aef5191b@r41g2000prr.googlegroups.com> Message-ID: <496E578C.70402@offenbachers.com> Hey, looks like Nokia bought Qt and solved the Open Source/Commercial license issue: http://rss.slashdot.org/~r/Slashdot/slashdot/~3/A4br-rQA460/article.pl I wonder if pyqt will follow suit... -------------- next part -------------- An HTML attachment was scrubbed... URL: From BrooklineTom at gmail.com Wed Jan 14 16:25:25 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Wed, 14 Jan 2009 13:25:25 -0800 (PST) Subject: executing multiple functions in background simultaneously References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <43a3e528-4c28-4618-b44c-0510847758a1@e25g2000vbe.googlegroups.com> > The disadvantage of threads in Python (CPython, actually) is that > there's the GIL (Global Interpreter Lock), so you won't get any speed > advantage if the threads are mostly processor-bound. On a single processor machine with compute-bound threads, I don't the GIL is the bottleneck. No matter how you slice it, there's still only one CPU. It might be interesting to see what it takes to make CPython do something useful with multicore machines, perhaps using approaches similar to that offered by Cilk Arts (http://www.cilk.com). From jstroud at mbi.ucla.edu Wed Jan 14 16:51:53 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 14 Jan 2009 13:51:53 -0800 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: r wrote: > I actually like the IDLE, but it could use a few improvements. If > anybody else has suggestions by all means post them. > > 1.) The text widget and the prompt(>>>) should be separated. Trying to > write a conditional in the interactive IDLE is a real PITA. Not to > mention if you copy the working code snippet to the IDLE editor window > the indention is 8 spaces instead 4 AND you've got that prompt(>>>) > stuck in there. I have a solution for the problem though.( I hope you > all are using fixed-width font) > > frm |<---------------------text widget -----------------> >>>> | >>>> |if this == 1: > ... | if that == 2: > ... | #do > ... | elif that ==3: > ... | #do > ... | else: > ... | pass >>>> | >>>> |x = 10 Brilliantly put. This is probably the main reason that IDLE is not worth using. Good luck on getting this changed. Best is to find yourself another IDE. Try vim. > Basically you have a Listbox on the left for the prompt and a Text on > the right. Disable the Listbox highlight and key press events and now > we have a very friendly interactive IDLE! No more prompt hijacking > your snippets, and no more 8 space indention! Excellent suggestions are a dime a dozen. Finding people to implement them is slightly harder. Getting said suggestions accepted into the python distribution is nearly impossible. Accept what you are given and try vim. If you really want a cool IDE, try Leo. It had some bugs about 4 years ago when I tried it, but I'm sure they have been worked out now. I'm addicted to vim, but if I wasn't, I'd probably be using Leo. James From fetchinson at googlemail.com Wed Jan 14 17:03:12 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jan 2009 14:03:12 -0800 Subject: python3.0 MySQLdb In-Reply-To: <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: >> >>> I need something to connect to a database, preferably mysql, that >> >>> works in python3.0 please. >> >> And your question is? >> >> > Surely it's fairly obvious that the question is "does such a thing >> > exist, and if so where can I find it?". >> >> Interestingly enough, the question was slightly (but importantly) >> different, though: the question really was "Does anybody has a patch for >> MySQLdb?"; as my reference to the existing interface to PostgreSQL >> was not sufficient for the OP. > > Yes it was enough, but I can not imagine it has not been done yet for > MySql either :) Well, this actually is the case: MySql has not been ported. As far as I can see the mysql python module in general (meaning for the 2.x branch) is not as well maintained as some others and questions about windows vs. linux issues periodically come up on the mailing list. So I would not be surprised if porting mysql to the 3.x branch will take longer and will be less well-maintained than other database bindings. > It was a open statement where I expected like 10 different databases > responses. For example if you go to a dinner place you have never been > gone before and want to try something new and there is no menu > available. What do you ask ? You just say something similar. "I would > like to order a salet please with some red wine." I don't think any > one of you would expect the waiter to answer,"And your question is?" I > also think the waiter does not expect me to ask 10 similar questions > like "red wine 1991? red wine 1992? red wine 1993? until i hit > something that is on the menu" > > So the final questions was, is there anything els on the menu besides > PostgreSQL, like MySql for example ? If not I will take PostgreSQL > please. The 3.x branch just as the 2.x branch contains bindings to sqlite. This you can use from day 1, the 3.0 release contains it. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Wed Jan 14 17:05:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 17:05:57 -0500 Subject: urllib2 - 403 that _should_ not occur. In-Reply-To: References: Message-ID: ajaksu wrote: > On Jan 14, 5:14 am, Steve Holden wrote: >> ajaksu wrote: >>> [snip evangelism stuff] >> OK, but be aware that the PSF doesn't monitor the bugs looking for >> actions to take on behalf of the Python user community. In fact we >> aren't overtly "political" in this way at all. This doesn't mean it >> wouldn't be useful for the PSF to get involved in this role; just that >> right now it isn't, and a bug report probably isn't the best way to get >> action. > > Acknowledged. I have posted a (pretty poor) support request @ > http://groups.google.com/group/Google-Groups-Basics/ and suggest > others do the same for Wikipedia and other big sites that block 3.0 (I > might build a list of those later today). Maybe a wiki page, some blog > posts, etc. > > Best regards, > Daniel > > Request: http://groups.google.com/group/Google-Groups-Basics/browse_thread/thread/498a39a89d81b650# > """ > Hi, > As mentioned in a comp.lang.python thread[1], the new version of > Python (3.0) cannot open pages @ groups.google.com. > > It seems the UA of Python 3.0 ("User-Agent: Python-urllib/3.1") is > actively blocked, while that of Python 2.5 ("User-Agent: Python-urllib/ > 1.17") isn't. > > This message is a call for help so that we can get Python 3.0 working > with groups.google.com. Is this the right place to bring the issue to > the attention of those that can fix it? Does anyone have a contact > that could speed up getting Python 3.0 working? > > Thanks in advance, > Daniel > > [1]http://groups.google.com/group/comp.lang.python/browse_thread/ > thread/088491d5a0d86f1b > """ Thanks very much. It's good to see Python users taking action that will lead to benefits for all. Congratulations on taking the initiative. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Wed Jan 14 17:08:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:08:39 +0000 Subject: change only the nth occurrence of a pattern in a string In-Reply-To: References: <0scs26-7a5.ln1@rama.fbx.proxad.net> Message-ID: <496E6267.3020006@mrabarnett.plus.com> Antoon Pardon wrote: > On 2008-12-31, TP wrote: >> Hi everybody, >> >> I would like to change only the nth occurence of a pattern in a string. The >> problem with "replace" method of strings, and "re.sub" is that we can only >> define the number of occurrences to change from the first one. >> >>>>> v="coucou" >>>>> v.replace("o","i",2) >> 'ciuciu' >>>>> import re >>>>> re.sub( "o", "i", v,2) >> 'ciuciu' >>>>> re.sub( "o", "i", v,1) >> 'ciucou' >> >> What is the best way to change only the nth occurence (occurrence number n)? >> >> Why this default behavior? For the user, it would be easier to put re.sub or >> replace in a loop to change the first n occurences. > > I would do it as follows: > > 1) Change the pattern n times to somethings that doesn't occur in your string > 2) Change it back n-1 times > 3) Change the remaining one to what you want. > >>>> v="coucou" >>>> v.replace('o', 'O', 2).replace('O', 'o', 1).replace('O', 'i') > 'couciu' > Sorry for the last posting, but it did occur to me that str.replace() could grow another parameter 'start', so it would become: s.replace(old, new[[, start], end]]) -> string (In Python 2.x the method doesn't accept keyword arguments, so that isn't a problem.) If the possible replacements are numbered from 0, then 'start' is the first one actually to perform and 'end' the one after the last to perform. The 2-argument form would be s.replace(old, new) with 'start' defaulting to 0 and 'end' to None => replacing all occurrences, same as now. The 3-argument form would be s.replace(old, new, end) with 'start' defaulting to 0 => equivalent to replacing the first 'end' occurrences, same as now. The 4-argument form would be s.replace(old, new, start, end) => replacing from the 'start'th to before the 'end'th occurrence, additional behaviour as requested. From steve at holdenweb.com Wed Jan 14 17:09:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Jan 2009 17:09:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01n1fc.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Russ P." writes: >> I know some researchers in software engineering who believe that the >> ultimate solution to software reliability is automatic code >> generation. The don't really care much which language is used, because >> it would only be an intermediate form that humans don't interact with >> directly. In that scenario, humans would essentially use a "higher >> level" language such as UML or some such thing. >> >> I personally have a hard time seeing how that could work, but that may >> just be due to be my own lack of understanding or vision. > > The usual idea is that you would write a specificiation, and a > constructive mathematical proof that a certain value meets that > specification. The compiler then verifies the proof and turns it into > code. Coq (http://coq.inria.fr) is an example of a language that > works like that. There is a family of jokes that go: > > Q. How many $LANGUAGE programmers does it take to change a lightbulb? > A. [funny response that illustrates some point about $LANGUAGE]. > > The instantiation for Coq goes: > > Q. How many Coq programmers does it take to change a lightbulb? > A. Are you kidding? It took two postdocs six months just to prove > that the bulb and socket are threaded in the same direction. > > Despite this, a compiler for a fairly substantial C subset has been > written mostly in Coq (http://compcert.inria.fr/doc/index.html). But, > this stuff is far far away from Python. > > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. If I used C instead, > I'd spend several hours writing the one-off program and then 15 > minutes waiting for it to run, which is not exactly better. (Or, I > could spend several hours writing a parallel version of the Python > program and running it on multiple machines, also not an improvement). > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. > > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. I > think the Python community should be aiming towards this. RPython might help, but of course it wouldn't allow you the full language. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From denis.papathanasiou at gmail.com Wed Jan 14 17:11:43 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:11:43 -0800 (PST) Subject: Getting around immutable default arguments for recursion Message-ID: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> I wrote this function to retrieve a list of items from a dictionary. The first time it was called, it worked properly. But every subsequent call returned the results of the prior call, plus the results of the current call. I was confused until I read in the docs that default arguments are immutable. Is there any way around this, to be able to write recursive functions with default arguments? Here's the code: def get_prior_versions (item_id, priors=[]): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: return priors else: priors.append(prior_id) return get_prior_versions(prior_id, priors) From prologic at shortcircuit.net.au Wed Jan 14 17:12:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:12:09 +1000 Subject: Python Crashes In-Reply-To: References: Message-ID: On Thu, Jan 15, 2009 at 6:57 AM, koranthala wrote: > Hi, > I have a twisted based application based on Python 2.4.3. I also > have one thread in this application. > > I found that my program crashes repeatedly after a random interval > (ranging from 10 min to 3 hr). When I say crash, it is not just that > the program dies. Rather in WinXP - a window comes mentioning that > 'Python.exe unexpectedly crashed'. > I tried putting in catching the exception by using try: except - > and logging everything. But the logging code is also not hit, i.e. > even the 'except' code is not hit. I feel that the base python > interpreter itself is crashing due to some bug in my program. > Earlier, I had put code as > try: > except: > log > At this time, my whole machine also froze. It was so slow that > one mouse movement happened after 7-8 minutes after I moved the > mouse. > > Then I modified the code to > try: > except Exception: > log > > Then, the machine no longer freezes. But, still there is no > logging of errors happening too. > > Could anyone guide me on this? I have been facing this issue for a > day, and cannot seem to solve it. > > P.S -> I am not allowed to post the code of application - so I hope > I have explained it enough. Do you use any 3rd party extensions (DLLs) ? cheers James From BrianVanderburg2 at aim.com Wed Jan 14 17:13:31 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Wed, 14 Jan 2009 17:13:31 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Message-ID: <496E638B.90209@aim.com> rt8396 at gmail.com wrote: > Here is a piece of C code this same guy showed me saying Pythonic > indention would make this hard to read -- Well lets see then! > > I swear, before god, this is the exact code he showed me. If you don't > believe me i will post a link to the thread. > > // Warning ugly C code ahead! > if( is_opt_data() < sizeof( long double ) ) { // test for insufficient > data > return TRUE; // indicate buffer empty > } // end test for insufficient data > if( is_circ() ) { // test for circular buffer > if( i < o ) { // test for data area divided > if( ( l - o ) > sizeof( long double ) ) { // test for data > contiguous > *t = ( ( long double * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust out > if( o >= l ) { // test for out wrap around > o = 0; // wrap out around limit > } // end test for out wrap around > } else { // data not contiguous in buffer > return load( ( char * ) t, sizeof( long double ) ); // return > data > } // end test for data contiguous > } else { // data are not divided > *t = ( ( float * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust out > if( o >= l ) { // test for out reached limit > o = 0; // wrap out around > } // end test for out reached limit > } // end test for data area divided > } else { // block buffer > *t = ( ( long double * ) f )[ o ]; // return data > o += sizeof( long double ); // adjust data pointer > } // end test for circular buffer > > I do a bit of C and C++ programming and even I think that is ugly and unreadable. First of all there are 'way' to many comments. Why does he comment every single line. Second of all I've always found that brace/indent style to lead toward harder-to-read code IMHO. I think the Allman style is the most readable followed by perhaps Whitesmiths style. Brian Vanderburg II From LambertDW at Corning.com Wed Jan 14 17:14:17 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Wed, 14 Jan 2009 17:14:17 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Please, why isn't a set permitted as the second argument to isinstance? From prologic at shortcircuit.net.au Wed Jan 14 17:16:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:16:25 +1000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Message-ID: On Thu, Jan 15, 2009 at 8:14 AM, Lambert, David W (S&T) wrote: > Please, why isn't a set permitted as the second argument to isinstance? Care to show us a code sample ? We're not psychic you know... cheers James From excord80 at gmail.com Wed Jan 14 17:21:15 2009 From: excord80 at gmail.com (excord80) Date: Wed, 14 Jan 2009 14:21:15 -0800 (PST) Subject: LGPL license for Qt 4.5 References: <88a86873-2693-41c5-a044-afb1b1e4e48f@s9g2000prg.googlegroups.com> Message-ID: On Jan 14, 9:20?am, sturlamolden wrote: > > In either case, Qt will be available under the same licensing terms as > wxWidgets. > > As of today, the main reason to prefer wxPython over PyQt is the > license. With an LGPL'd Qt, I'd rather ask what this will mean for > wxPython. wx has a nice community, and is actively developed, FWICT. I've also heard that its maintainer is very responsive. However, my impression is that the main appeal of wx is that it's API is similar to MS Windows MFC (an appeal only for (some) MS Windows developers though) and that it has favorable licensing conditions (like GTK+). Further, I suspect that Pythoneers have been using and recommending it because it's currently the least worst solution. Now that LGPL Qt is very nearly here, I'd say that wxWidgets is going to have a very challenging time ahead. Very challenging. From google at mrabarnett.plus.com Wed Jan 14 17:24:23 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:24:23 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D0F@CVCV0XI05.na.corning.com> Message-ID: <496E6617.5000205@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > Please, why isn't a set permitted as the second argument to > isinstance? > Do you mean set as a class ("isinstance(s, set)", which is valid) or a set of classes ("isinstance(s, set([str, bytes])", which isn't valid)? From google at mrabarnett.plus.com Wed Jan 14 17:26:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jan 2009 22:26:06 +0000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <496E667E.1090603@mrabarnett.plus.com> dpapathanasiou wrote: > I wrote this function to retrieve a list of items from a dictionary. > > The first time it was called, it worked properly. > > But every subsequent call returned the results of the prior call, plus > the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. > > Is there any way around this, to be able to write recursive functions > with default arguments? > > Here's the code: > > def get_prior_versions (item_id, priors=[]): The usual solution is: def get_prior_versions (item_id, priors=None): if priors is None: priors = [] > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > priors.append(prior_id) > return get_prior_versions(prior_id, priors) From skip at pobox.com Wed Jan 14 17:29:17 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 14 Jan 2009 16:29:17 -0600 Subject: python3.0 MySQLdb In-Reply-To: References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> Message-ID: <18798.26429.431192.82340@montanaro.dyndns.org> Daniel> Well, this actually is the case: MySql has not been ported. As Daniel> far as I can see the mysql python module in general (meaning for Daniel> the 2.x branch) is not as well maintained as some others and Daniel> questions about windows vs. linux issues periodically come up on Daniel> the mailing list. So I would not be surprised if porting mysql Daniel> to the 3.x branch will take longer and will be less Daniel> well-maintained than other database bindings. Unless you have direct evidence to the contrary people should take what you wrote with a grain of salt. In my experience Andy Dustman has been quite responsive to inputs about MySQLdb, when those inputs happen in the forum he inhabits. That forum is the MySQL forum tool on SourceForge: http://sourceforge.net/forum/?group_id=22307 If you're curious about MySQLdb on Python 3.0 that is the place to ask. Of course, like all open source software if you provide a patch in the project tracker things will happen faster. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From rt8396 at gmail.com Wed Jan 14 17:29:18 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 14:29:18 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: <292f8c54-9e22-4d20-958b-f32b75f85f4e@p2g2000prf.googlegroups.com> Hello James, I actually want to trash IDLE and start over. I would be willing to do a complete re-write. I have already made a template GUI that works (early stages). I am wondering if anyone else might be interested in taking this on with me? IMO IDLE is full of fluff where it should not be, and thin where it should be fat. Trim off the fat and lean this puppy up! I like that in ActiveState's version you can delete as much text as you want. IDLE won't allow it. I want a better setup for extensions, and complete control of mouse and key bindings for the user. We need to clean the dust off and polish IDLE up a bit. If not, i will just write up a simplified version it for myself. I just thought someone out there may be thinking like i am. From prologic at shortcircuit.net.au Wed Jan 14 17:29:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 08:29:36 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 8:11 AM, dpapathanasiou wrote: > I wrote this function to retrieve a list of items from a dictionary. > > The first time it was called, it worked properly. > > But every subsequent call returned the results of the prior call, plus > the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. > > Is there any way around this, to be able to write recursive functions > with default arguments? > > Here's the code: > > def get_prior_versions (item_id, priors=[]): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > priors.append(prior_id) > return get_prior_versions(prior_id, priors) How about: def get_prior_versions (item_id, priors=None): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: return priors else: if priors: priors.append(prior_id) else: priors = [prior_id] return get_prior_versions(prior_id, priors) From denis.papathanasiou at gmail.com Wed Jan 14 17:31:19 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:31:19 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: > The usual solution is: > > def get_prior_versions (item_id, priors=None): > if priors is None: > priors = [] Thanks! From denis.papathanasiou at gmail.com Wed Jan 14 17:32:30 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 14:32:30 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> > How about: > > def get_prior_versions (item_id, priors=None): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > return priors > else: > if priors: > priors.append(prior_id) > else: > priors = [prior_id] > return get_prior_versions(prior_id, priors) It's not exactly right for what I'm doing, b/c the caller always expects a list in return. From pavlovevidence at gmail.com Wed Jan 14 17:37:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 14:37:16 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> On Jan 14, 6:57?am, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > > For the rest of us, this is fantastic news. > > http://digi.no/php/art.php?id=800922 Is Nokia the making the full Qt toolkit LGPL, or just the parts that were previously GPL? (Can't read Norwegian if it's in the article.) If it's the former Rivebank Computing will be ok, they might even sell more support contracts this way since companies are more likely to use LGPL than GPL software. Carl Banks From bignose+hates-spam at benfinney.id.au Wed Jan 14 17:38:58 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 15 Jan 2009 09:38:58 +1100 Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> Message-ID: <87fxjlcy2l.fsf@benfinney.id.au> dpapathanasiou writes: > But every subsequent call returned the results of the prior call, > plus the results of the current call. > > I was confused until I read in the docs that default arguments are > immutable. You'll continue to be confused if you use that term. Python already has a specific use of the term ?immutable?, and it doesn't apply here. Better to say: default arguments are part of the function definition statement, and are evaluated when the definition is evaluated. -- \ ?To me, boxing is like a ballet, except there's no music, no | `\ choreography, and the dancers hit each other.? ?Jack Handey | _o__) | Ben Finney From tjreedy at udel.edu Wed Jan 14 17:43:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Jan 2009 17:43:19 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: James Stroud wrote: > r wrote: >> I actually like the IDLE, but it could use a few improvements. If >> anybody else has suggestions by all means post them. >> >> 1.) The text widget and the prompt(>>>) should be separated. Trying to >> write a conditional in the interactive IDLE is a real PITA. Not to >> mention if you copy the working code snippet to the IDLE editor window >> the indention is 8 spaces instead 4 AND you've got that prompt(>>>) >> stuck in there. I have a solution for the problem though.( I hope you >> all are using fixed-width font) >> >> frm |<---------------------text widget -----------------> >>>>> | >>>>> |if this == 1: >> ... | if that == 2: >> ... | #do >> ... | elif that ==3: >> ... | #do >> ... | else: >> ... | pass >>>>> | >>>>> |x = 10 > > Brilliantly put. This is probably the main reason that IDLE is not worth > using. Good luck on getting this changed. Best is to find yourself > another IDE. Try vim. > >> Basically you have a Listbox on the left for the prompt and a Text on >> the right. Disable the Listbox highlight and key press events and now >> we have a very friendly interactive IDLE! No more prompt hijacking >> your snippets, and no more 8 space indention! > > Excellent suggestions are a dime a dozen. Finding people to implement > them is slightly harder. Getting said suggestions accepted into the > python distribution is nearly impossible. Accept what you are given and > try vim. My doc suggestions get accepted regularly, sometimes within hours. I think the 'main' IDLE maintainer is no longer active. I think someone who would do more than fix critical bugs might be welcome. From pavlovevidence at gmail.com Wed Jan 14 17:43:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 14 Jan 2009 14:43:40 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: On Jan 14, 4:14?pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The Python development team might be open to adding it if you were to submit a patch. The use case is fairly obvious. I doubt any of them would respond to a wishlist request, though. As a workaround, you can just cast the set to a tuple like this: isinstance(x,tuple(s)) Carl Banks From prologic at shortcircuit.net.au Wed Jan 14 18:04:07 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 09:04:07 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 8:32 AM, dpapathanasiou wrote: (...) > It's not exactly right for what I'm doing, b/c the caller always > expects a list in return. How about this then: def get_prior_versions (item_id, priors=None): """Return a list of all prior item ids starting with this one""" global history_db # key = item id, value = prior item id prior_id = history_db[item_id] if not prior_id: if priors: return priors or [] else: if priors: priors.append(prior_id) else: priors = [prior_id] return get_prior_versions(prior_id, priors) By the way, this is a really badly written function for 2 reasons: a) a global should and need not be used. b) this function could be rewritten without recursion. cheers James From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:07:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:07:41 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <496e2c3f$0$29454$426a74cc@news.free.fr> <7x63kh3fya.fsf@ruckus.brouhaha.com> <496e4b97$0$24021$426a34cc@news.free.fr> Message-ID: <017e66cf$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 20:33:01 +0100, Bruno Desthuilliers wrote: > Paul Rubin a ?crit : >> Bruno Desthuilliers >> writes: >>>> I haven't anywhere in this thread as far as I know suggested >>>> eliminating dynamism from Python, >>> Nope, but your suggestion would have the same practical result as far >>> as I'm concerned. >> >> Sorry, I don't comprehend that. > > IIRC, your suggestion was that one should have to explicitely allow > "dynamic binding" (ie: outside the initializer) of new attributes, and > that the default vould be to disallow them. Lots of heat and noise in this discussion, but I wonder, just how often do Python programmers use this dynamism *in practice*? I hardly ever do. I like that it is there, I like that Python is so easy to use without the overhead of Java, but I rarely need *all* the dynamism available. [sweeping generalization] Most objects people use are built-ins, and you can't add attributes to them. I don't think I've ever done subclasses a built-in just to get dynamic attributes: class DynamicInt(int): pass x = DynamicInt(2) x.attribute = "something" As far as non built-in classes go: >>> from decimal import Decimal >>> d = Decimal('0.5') >>> d.something = "something" Traceback (most recent call last): File "", line 1, in AttributeError: 'Decimal' object has no attribute 'something' If I recall correctly, the first implementation of Decimal was written in Python. Did anyone object to Decimal being re-written in C because they missed the ability to add arbitrary attributes to Decimal instances? And if they did, I'm pretty sure the answer given would have been: deal with it. Subclass Decimal, or use delegation. Don't penalise 99% of uses of Decimal for that 1% of uses where you need dynamism. I think that's a wise decision. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:08:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:08:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <017e66e9$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 08:45:46 -0800, Paul Rubin wrote: >> Btw, for performance, there is __slots__, > > That is a good point, we somehow lost sight of that in this thread. > >> with the side-effect that it forbids attribute creation 'on the fly'. > > I have had the impression that this is a somewhat accidental side effect > and shouldn't be relied on. Not accidental, but people complain if you use slots for the purpose of prohibiting attribute creation. They say "That's not what __slots__ was designed for!". That's okay though, computers were designed for breaking Germany ciphers and calculating the trajectory of cannon-shells, but they're not the only things we use computers for these days. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Jan 14 18:08:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jan 2009 23:08:12 GMT Subject: can someone tell me why this doesn't work please python 3 References: <76B121EBB7D0476EA8AF287FEADAEBE7@Home> Message-ID: <017e66ee$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 09:45:58 -0800, Dennis Lee Bieber wrote: > Personally -- I'd accept anything that started with the character: > > while True: > password = input(prompt).lower() > if password.startswith("y"): > return True > elif password.startswith("n"): > return False [...] >>> response = input("Shall I delete all your files? ").lower() Shall I delete all your files? Ye gods, NOOO!!!!! >>> if response.startswith('y'): print "Deleting files now" ... Deleting files now There are times where being flexible in what you accept is *not* a virtue. -- Steven From rt8396 at gmail.com Wed Jan 14 18:12:09 2009 From: rt8396 at gmail.com (r) Date: Wed, 14 Jan 2009 15:12:09 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> Message-ID: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> On Jan 14, 4:43?pm, Terry Reedy wrote: [snip] > I think the 'main' IDLE maintainer is no longer active. ?I think someone > who would do more than fix critical bugs might be welcome. Hello Terry, That's what i was beginning to think. I am not quite ready (as far as my skills are concerned) to put out something that would be as useful to many people. I could hack together something real quick for myself. This is why i am looking for like-minded people who would be interested in this. I have the foresight and willpower at this point to contribute something meaningful to the Python community -- to give back. OFF-TOPIC:(but related) What is the state of Tkinter at this point. Is an active effort under way to port TK 8.5 into Python? Tkinter and IDLE are very important to Python, but i understand there are much more important areas where the GURU's are concentrating. Should there be a calling for "others" to get involved here? I would like to help out. Thanks From denis.papathanasiou at gmail.com Wed Jan 14 18:23:10 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 15:23:10 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <87fxjlcy2l.fsf@benfinney.id.au> Message-ID: > You'll continue to be confused if you use that term. Python already > has a specific use of the term ?immutable?, and it doesn't apply > here. I was just following the terminology used in "A Byte of Python" (which, that particular point aside, is a very good tutorial). > Better to say: default arguments are part of the function definition > statement, and are evaluated when the definition is evaluated. Yes, well said. From denis.papathanasiou at gmail.com Wed Jan 14 18:27:01 2009 From: denis.papathanasiou at gmail.com (dpapathanasiou) Date: Wed, 14 Jan 2009 15:27:01 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: > How about this then: > > def get_prior_versions (item_id, priors=None): > """Return a list of all prior item ids starting with this one""" > global history_db # key = item id, value = prior item id > prior_id = history_db[item_id] > if not prior_id: > if priors: > return priors or [] > else: > if priors: > priors.append(prior_id) > else: > priors = [prior_id] > return get_prior_versions(prior_id, priors) Without the "if priors:" line just above the first return statement (a typo perhaps?), then yes, it would do what I want. > a) a global should and need not be used. Passing the entire dictionary to every function that accesses it is better? > b) this function could be rewritten without recursion. Right, any recursive function can be written iteratively and vice- versa. I'm not sure that makes it "bad". From prologic at shortcircuit.net.au Wed Jan 14 18:37:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 09:37:14 +1000 Subject: Getting around immutable default arguments for recursion In-Reply-To: References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 9:27 AM, dpapathanasiou wrote: > Without the "if priors:" line just above the first return statement (a > typo perhaps?), then yes, it would do what I want. Yes sorry it was :) >> a) a global should and need not be used. > > Passing the entire dictionary to every function that accesses it is > better? Yes :) >> b) this function could be rewritten without recursion. > > Right, any recursive function can be written iteratively and vice- > versa. I'm not sure that makes it "bad". No it doesn't necessarily make it bad, but recursion is not necessary here :) What does history_db look like ? I think I can write a much simpler function for you. Also, show me what the results are used for. cheers James From robert.kern at gmail.com Wed Jan 14 18:44:34 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 14 Jan 2009 17:44:34 -0600 Subject: LGPL license for Qt 4.5 In-Reply-To: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> References: <0890a295-d4f8-4cb2-bab9-7cbc0ce3ef17@w24g2000prd.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 14, 6:57 am, sturlamolden wrote: >> According to a Norwegian publication, Nokia will release Qt under LGPL >> as of version 4.5. >> >> If I had stocks in Riverbank Computing ltd., I would sell them now... >> >> For the rest of us, this is fantastic news. >> >> http://digi.no/php/art.php?id=800922 > > Is Nokia the making the full Qt toolkit LGPL, or just the parts that > were previously GPL? (Can't read Norwegian if it's in the article.) The "full" Qt toolkit <4.5 is dual-licensed Commercial/GPL, and the "full" Qt toolkit >=4.5 will be Commercial/LGPL/GPL. Trolltech did have a few extra libraries that were just Commercial, IIRC, but these were relatively small. What people usually call "Qt" (i.e. all of the stuff that PyQt wraps) is going to be LGPLed. You can get more information in English at the new Qt site here: http://www.qtsoftware.com/about/licensing -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 18:50:54 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 15:50:54 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496E7A5E.3010308@jpl.nasa.gov> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function >> and run them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables >> of the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces > Join (wait) on them. > > pydoc threading.Thread > > cheers > James What is the proper syntax to use if I wish to return variables from a function run as a thread? For example, how do I implement the following code to return the variable "c" from MyFunc for later use in RunThreads? Trying to return anything from the threading.Thread call results in a "unpack non-sequence" error. import threading, sys def MyFunc(a, b): c = a + b print "c =",c return c def RunThreads(): args = (1,2) threading.Thread(target=MyFunc,args=(1,2)).start() if __name__ == "__main__": RunThreads() sys.exit() From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 18:50:54 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 15:50:54 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: <496E7A5E.3010308@jpl.nasa.gov> James Mills wrote: > On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > wrote: >> I would like to spawn off multiple instances of a function >> and run them simultaneously and then wait until they all complete. >> Currently I'm doing this by calling them as sub-processes >> executable from the command-line. Is there a way of accomplishing >> the same thing without having to make command-line executables >> of the function call? > > Try using the python standard threading module. > > Create multiple instances of Thread with target=your_function > Maintain a list of these new Thread instnaces > Join (wait) on them. > > pydoc threading.Thread > > cheers > James What is the proper syntax to use if I wish to return variables from a function run as a thread? For example, how do I implement the following code to return the variable "c" from MyFunc for later use in RunThreads? Trying to return anything from the threading.Thread call results in a "unpack non-sequence" error. import threading, sys def MyFunc(a, b): c = a + b print "c =",c return c def RunThreads(): args = (1,2) threading.Thread(target=MyFunc,args=(1,2)).start() if __name__ == "__main__": RunThreads() sys.exit() From fetchinson at googlemail.com Wed Jan 14 18:55:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jan 2009 15:55:57 -0800 Subject: python3.0 MySQLdb In-Reply-To: <18798.26429.431192.82340@montanaro.dyndns.org> References: <4d9dcf38-f9e0-4841-aa40-f2f59d74ad76@w1g2000prm.googlegroups.com> <496D1C78.3060307@v.loewis.de> <643b9408-eb22-46cf-8458-d264b7ee6c43@e18g2000vbe.googlegroups.com> <18798.26429.431192.82340@montanaro.dyndns.org> Message-ID: > Daniel> Well, this actually is the case: MySql has not been ported. As > Daniel> far as I can see the mysql python module in general (meaning for > Daniel> the 2.x branch) is not as well maintained as some others and > Daniel> questions about windows vs. linux issues periodically come up on > Daniel> the mailing list. So I would not be surprised if porting mysql > Daniel> to the 3.x branch will take longer and will be less > Daniel> well-maintained than other database bindings. > > Unless you have direct evidence to the contrary people should take what you > wrote with a grain of salt. What I wrote is of course solely my own experience. When I needed to use a database with python I looked around and tried to guess which db binding is the most mature, stable, well-maintained, etc. Meaning, I'd like to have the least amount of compilation/linking problems for both windows and linux and I'd like to have the least amount of runtime problems. I did what I guess anybody would have done: a google search on the main database bindings. From this rather ad hoc research I concluded that mysqldb has more problems than the other major databases. > In my experience Andy Dustman has been quite > responsive to inputs about MySQLdb, when those inputs happen in the forum he > inhabits. I agree with you and I didn't say anything which contradicts your statement. Being very responsive to problems is absolutely compatible with having some problems. > That forum is the MySQL forum tool on SourceForge: > > http://sourceforge.net/forum/?group_id=22307 > > If you're curious about MySQLdb on Python 3.0 that is the place to ask. Of > course, like all open source software if you provide a patch in the project > tracker things will happen faster. Sure, we agree again. But since my impression about the OP's question was that his/her main intention is not really code contribution but rather a solution to use, I'd say this is pretty much irrelevant for the OP. But yes, we agree on how development of open source projects go :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From cs at zip.com.au Wed Jan 14 19:00:23 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Jan 2009 11:00:23 +1100 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E7A5E.3010308@jpl.nasa.gov> Message-ID: <20090115000023.GA26379@cskk.homeip.net> On 14Jan2009 15:50, Catherine Moroney wrote: > James Mills wrote: >> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >> wrote: >>> I would like to spawn off multiple instances of a function >>> and run them simultaneously and then wait until they all complete. [...] >> Try using the python standard threading module. >> Create multiple instances of Thread with target=your_function >> Maintain a list of these new Thread instnaces >> Join (wait) on them. > > What is the proper syntax to use if I wish to return variables > from a function run as a thread? The easy thing is to use a Queue object. The background thread uses .put() to place a computed result on the QUeue and the caller uses .get() to read from the queue. There's an assortment of other ways too. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From http Wed Jan 14 19:02:44 2009 From: http (Paul Rubin) Date: 14 Jan 2009 16:02:44 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> <017e66e9$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xocy9l9ln.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Not accidental, but people complain if you use slots for the purpose of > prohibiting attribute creation. They say "That's not what __slots__ was > designed for!". That's okay though, computers were designed for breaking > Germany ciphers and calculating the trajectory of cannon-shells, but > they're not the only things we use computers for these days. It's hard to figure out from the docs exactly what slots is supposed to do: http://docs.python.org/reference/datamodel.html#id3 I don't think it's good style to rely on accidental, undocumented characteristics of some language feature. But, I may start using slots for some of the stuff I'm doing, just to reduce space consumption and keep more instances around, which is what it's really intended for. From kyrie at uh.cu Wed Jan 14 19:09:54 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 14 Jan 2009 19:09:54 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01n1fc.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <1231978194.496e7ed213a2b@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. Wait, do you _really_ believe that _static_ checks could prevent problems arising from _unexpected_ conditions in the _data_? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From castironpi at gmail.com Wed Jan 14 19:30:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 16:30:36 -0800 (PST) Subject: reverse dict lookup & Relation class Message-ID: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Hi, this is a continuation of something that comes up now and again about reverse lookups on dictionaries, as well as a follow-up to my pursuit of a Relation class from earlier. For a reverse lookup, you just need two lookups. name= {} phone= {} name[ '555-963' ]= 'Joan' phone[ 'Joan' ]= '555-963' Though maybe the keys in 'name' should be names, instead of the values in it. The variable name doesn't clarify that. (What is more natural to you in reading code? Is one obviously wrong?) phone[ '555-963' ]= 'Joan' name[ 'Joan' ]= '555-963' To provide for non-unique fields, the structure becomes kind of complicated. phone[ '555-963' ]= 'Joan' phone[ '555-964' ]= 'Joan' name[ 'Joan' ]= [ '555-963', '555-964' ] For uniform access, 'phone' can be a dict of strings to lists too. phone[ '555-963' ]= [ 'Joan' ] phone[ '555-964' ]= [ 'Joan' ] To add a third field, the structure becomes again more complicated. Either define a unique key: phone[ '555-963' ]= [ object1 ] phone[ '555-964' ]= [ object2 ] name[ 'Joan' ]= [ object1, object2 ] hourstocall= {} hourstocall[ '9a-5p' ]= [ object1 ] hourstocall[ '5p-11p' ]= [ object2 ] records= {} records[ object1 ]= ( 'Joan', '555-963', '9a-5p' ) records[ object2 ]= ( 'Joan', '555-964', '5p-11p' ) Or, and this is the interesting part, use the ('identificationally') same tuples in both mappings, since the object is only mentioned, not used. phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', '5p-11p' ) ] hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] What's the best way to construct this class? Or, do you have an argument that it could not be simpler than using a relational db? Brainstorming, not flamestorming. From castironpi at gmail.com Wed Jan 14 19:36:25 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 14 Jan 2009 16:36:25 -0800 (PST) Subject: executing multiple functions in background simultaneously References: Message-ID: <8c03b7e0-19c8-4f15-8ffb-aaa8c9c30663@r36g2000prf.googlegroups.com> On Jan 14, 6:00?pm, Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: > > > James Mills wrote: > >> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney > >> wrote: > >>> I would like to spawn off multiple instances of a function > >>> and run them simultaneously and then wait until they all complete. > [...] > >> Try using the python standard threading module. > >> Create multiple instances of Thread with target=your_function > >> Maintain a list of these new Thread instnaces > >> Join (wait) on them. > > > What is the proper syntax to use if I wish to return variables > > from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. You could just set the result as an attribute of the thread you're starting (untested): class MyThread(Thread): def run( self ): stuff() self.result= something (Strictly speaking, threads don't return values, since nothing follows them in flow of control.) From clp2 at rebertia.com Wed Jan 14 20:04:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jan 2009 17:04:38 -0800 Subject: reverse dict lookup & Relation class In-Reply-To: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <50697b2c0901141704k661f8b77sf626d05b41b2efd5@mail.gmail.com> On Wed, Jan 14, 2009 at 4:30 PM, Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. > > For a reverse lookup, you just need two lookups. > name= {} > phone= {} > name[ '555-963' ]= 'Joan' > phone[ 'Joan' ]= '555-963' > > Though maybe the keys in 'name' should be names, instead of the values > in it. The variable name doesn't clarify that. (What is more natural > to you in reading code? Is one obviously wrong?) > > phone[ '555-963' ]= 'Joan' > name[ 'Joan' ]= '555-963' > > To provide for non-unique fields, the structure becomes kind of > complicated. > > phone[ '555-963' ]= 'Joan' > phone[ '555-964' ]= 'Joan' > name[ 'Joan' ]= [ '555-963', '555-964' ] > > For uniform access, 'phone' can be a dict of strings to lists too. > > phone[ '555-963' ]= [ 'Joan' ] > phone[ '555-964' ]= [ 'Joan' ] > > To add a third field, the structure becomes again more complicated. > Either define a unique key: > > phone[ '555-963' ]= [ object1 ] > phone[ '555-964' ]= [ object2 ] > name[ 'Joan' ]= [ object1, object2 ] > hourstocall= {} > hourstocall[ '9a-5p' ]= [ object1 ] > hourstocall[ '5p-11p' ]= [ object2 ] > records= {} > records[ object1 ]= ( 'Joan', '555-963', '9a-5p' ) > records[ object2 ]= ( 'Joan', '555-964', '5p-11p' ) > > Or, and this is the interesting part, use the ('identificationally') > same tuples in both mappings, since the object is only mentioned, not > used. > > phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', > '5p-11p' ) ] > hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. Once you get beyond a main dict (e.g. name2phone) and one that's its inverse (e.g. phone2name), yeah, I'd probably say you should be using a relational DB for this. You could also use objects, but it sounds like you really want to use SQL-like querying, which isn't well-suited to plain objects (though it'd be fine with an ORM). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 20:11:44 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:11:44 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: Message-ID: <496E8D50.4050900@jpl.nasa.gov> Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: >> James Mills wrote: >>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>> wrote: >>>> I would like to spawn off multiple instances of a function >>>> and run them simultaneously and then wait until they all complete. > [...] >>> Try using the python standard threading module. >>> Create multiple instances of Thread with target=your_function >>> Maintain a list of these new Thread instnaces >>> Join (wait) on them. >> What is the proper syntax to use if I wish to return variables >> from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. > > Cheers, Thank you for this hint. This goes a long way to solving my problem. One question - is there any way to name the objects that get put on a queue? For my application, it's important to know which thread put a particular item on the queue. Catherine From Catherine.M.Moroney at jpl.nasa.gov Wed Jan 14 20:11:44 2009 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:11:44 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: References: Message-ID: <496E8D50.4050900@jpl.nasa.gov> Cameron Simpson wrote: > On 14Jan2009 15:50, Catherine Moroney wrote: >> James Mills wrote: >>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>> wrote: >>>> I would like to spawn off multiple instances of a function >>>> and run them simultaneously and then wait until they all complete. > [...] >>> Try using the python standard threading module. >>> Create multiple instances of Thread with target=your_function >>> Maintain a list of these new Thread instnaces >>> Join (wait) on them. >> What is the proper syntax to use if I wish to return variables >> from a function run as a thread? > > The easy thing is to use a Queue object. The background thread uses > .put() to place a computed result on the QUeue and the caller uses > .get() to read from the queue. There's an assortment of other ways too. > > Cheers, Thank you for this hint. This goes a long way to solving my problem. One question - is there any way to name the objects that get put on a queue? For my application, it's important to know which thread put a particular item on the queue. Catherine From exarkun at divmod.com Wed Jan 14 20:20:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 14 Jan 2009 20:20:27 -0500 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E8D50.4050900@jpl.nasa.gov> Message-ID: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney wrote: > [snip] >> >>The easy thing is to use a Queue object. The background thread uses >>.put() to place a computed result on the QUeue and the caller uses >>.get() to read from the queue. There's an assortment of other ways too. >> >>Cheers, > >Thank you for this hint. This goes a long way to solving >my problem. > >One question - is there any way to name the objects that get >put on a queue? For my application, it's important to know >which thread put a particular item on the queue. There's lots and lots of ways. The simplest might be to put two-tuples of the thread identifier and some other object. eg queue.put((threadID, obj)) Perhaps you can accomplish your goal that way, or perhaps a minor variation would be more suitable. Jean-Paul From joe at socallinuxexpo.org Wed Jan 14 20:31:35 2009 From: joe at socallinuxexpo.org (joe at socallinuxexpo.org) Date: Wed, 14 Jan 2009 17:31:35 -0800 (PST) Subject: Invitation for Python at the Southern California Linux Expo Message-ID: <45582.206.211.148.69.1231983095.squirrel@socallinuxexpo.org> Greetings, I would like to invite the Python project to attend the 7th Southern California Linux Expo. The show will be held February 20th-22nd, 2009 at the Westin LAX in Los Angeles, CA. SCALE 7x will be an excellent venue to increase awareness and showcase the work of the Python community. Each project will have some room in the zone on the show floor. This will include all the usual amenities: a 6' table, chairs, a 500W power drop, one Ethernet drop and 3-5 complementary passes to the show. I am including our application for dotORG exhibitors, if anyone is down in the Southern California area, and would like to set up a booth, I encourage you to apply. Any questions, please do not hesitate to ask. Thanks for your time! Joe Smith http://scale7x.socallinuxexpo.org/conference-info/call-for-dotorg-exhibitors From catherine.m.moroney at jpl.nasa.gov Wed Jan 14 20:31:48 2009 From: catherine.m.moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 14 Jan 2009 17:31:48 -0800 Subject: executing multiple functions in background simultaneously In-Reply-To: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> References: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> Message-ID: <93E91E25-9F4C-4A11-ACE4-3BEEFDE94813@jpl.nasa.gov> On Jan 14, 2009, at 5:20 PM, Jean-Paul Calderone wrote: > On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney > wrote: >> [snip] >>> >>> The easy thing is to use a Queue object. The background thread uses >>> .put() to place a computed result on the QUeue and the caller uses >>> .get() to read from the queue. There's an assortment of other >>> ways too. >>> >>> Cheers, >> >> Thank you for this hint. This goes a long way to solving >> my problem. >> >> One question - is there any way to name the objects that get >> put on a queue? For my application, it's important to know >> which thread put a particular item on the queue. > > There's lots and lots of ways. The simplest might be to put two- > tuples > of the thread identifier and some other object. eg > > queue.put((threadID, obj)) > > Perhaps you can accomplish your goal that way, or perhaps a minor > variation would be more suitable. I just came to that conclusion myself and a short test shows that things are working. Thanks to all who contributed to this discussion. Even though I'm by no means an expert, at least I can work with threads and queues now! I love this language ... > > Jean-Paul Catherine From prologic at shortcircuit.net.au Wed Jan 14 20:39:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 11:39:05 +1000 Subject: executing multiple functions in background simultaneously In-Reply-To: <496D39A4.2030406@jpl.nasa.gov> References: <496D39A4.2030406@jpl.nasa.gov> Message-ID: Speaking of Threading .. http://codepad.org/dvxwAphE Just a really interesting way of doing this :) cheers James -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Jan 14 20:53:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 11:53:37 +1000 Subject: process/thread instances and attributes Message-ID: Hey all, I have this concept I'm working on and here is the code... Problem is if you run this it doesn't terminate. I believe you can terminate it in the main process by calling a.stop() But I can't find a way for it to self terminate, ie: self.stop() As indicated by the code... ---------------------------------------- #!/usr/bin/env python import os from time import sleep from threading import Thread as _Thread from multiprocessing import Process as _Process class Process(object): def __init__(self, *args, **kwargs): super(Process, self).__init__(*args, **kwargs) self.running = False self.process = _Process(target=self._run) def _run(self): thread = _Thread(target=self.run) thread.start() try: while self.running and thread.isAlive(): try: sleep(1) print "!" except SystemExit: self.running = False break except KeyboardInterrupt: self.running = False break finally: thread.join() def start(self): self.running = True self.process.start() def run(self): pass def stop(self): print "%s: Stopping ..." % self self.running = False class A(Process): def run(self): while self.running: sleep(5) self.stop() a = A() a.start() while a.running: sleep(1) print "." print "DONE" ---------------------------------------- cheers James -- -- "Problems are solved by method" From google at mrabarnett.plus.com Wed Jan 14 20:54:49 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 01:54:49 +0000 Subject: reverse dict lookup & Relation class In-Reply-To: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <496E9769.90808@mrabarnett.plus.com> Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. > > For a reverse lookup, you just need two lookups. > name= {} > phone= {} > name[ '555-963' ]= 'Joan' > phone[ 'Joan' ]= '555-963' > > Though maybe the keys in 'name' should be names, instead of the > values in it. The variable name doesn't clarify that. (What is more > natural to you in reading code? Is one obviously wrong?) > > phone[ '555-963' ]= 'Joan' > name[ 'Joan' ]= '555-963' > Consider "str(x)". It isn't saying "x is a string", it's saying "x as a string". Similarly, "ord(x)" says "the ordinal value of x". So, "phone[x]" means "the phone number of x". [snip] > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. > You could imagine an object where you provide a field name and a value and it returns all those entries where that field contains that value. That, basically, is a database. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 21:02:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 02:02:57 GMT Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 15:27:01 -0800, dpapathanasiou wrote: >> a) a global should and need not be used. > > Passing the entire dictionary to every function that accesses it is > better? Yes. There is very little overhead when passing objects to functions in Python. There's no performance penalty to passing objects instead of relying on globals, and it may in fact be marginally faster: >>> D = {'parrot': None} >>> >>> def byargument(d): ... return d ... >>> def byglobal1(): ... return D ... >>> def byglobal2(): ... global D ... return D ... >>> >>> from timeit import Timer >>> setup = "from __main__ import byargument, byglobal1, byglobal2, D" >>> t1 = Timer('result = byargument(D)', setup) >>> t2 = Timer('result = byglobal1()', setup) >>> t3 = Timer('result = byglobal2()', setup) >>> >>> min(t1.repeat()) 0.23665285110473633 >>> min(t2.repeat()) 0.23789191246032715 >>> min(t3.repeat()) 0.23757314682006836 -- Steven From http Wed Jan 14 21:22:15 2009 From: http (Paul Rubin) Date: 14 Jan 2009 18:22:15 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Wait, do you _really_ believe that _static_ checks could prevent problems > arising from _unexpected_ conditions in the _data_? The data does not arrive from outer space on a magtape stapled to a meteor. It comes out of another program. Most of the problems in processing it come from mismatches between the processing programs and the generation programs. Static checks would help eliminate those mismatches. From wuwei23 at gmail.com Wed Jan 14 21:24:02 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 18:24:02 -0800 (PST) Subject: Getting around immutable default arguments for recursion References: <630e66f9-91af-4d4b-a015-f9a097162c1b@u14g2000yqg.googlegroups.com> <3d007d6c-aef1-4c6d-aed2-ff723a1b4eb0@e3g2000vbe.googlegroups.com> Message-ID: dpapathanasiou wrote: > Passing the entire dictionary to every function that accesses it is > better? If there are a large number of functions, you could combine them and the history_db dict into a single object. From steven at REMOVE.THIS.cybersource.com.au Wed Jan 14 21:24:09 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 02:24:09 GMT Subject: initialising a class by name References: Message-ID: On Wed, 14 Jan 2009 13:53:52 +0530, Krishnakant wrote: > Hi steevan, > I liked this idea of dispatchTable. > is it possible to say some thing like inst = dispatchTable{"ham"} > according to me, inst will become the instance of class ham. Yes, that works, provided you fix the syntax. (You used {} instead of square brackets.) There's nothing special about dispatching: you look up the dict with a key, and that returns a class. You then call that class to create a class instance as if you were calling it directly by name. > Another > thing to note is that all the classes are in different modules. So where > do I create the dict of classes mapped with the name? That's up to you. -- Steven From MLThornton at gmail.com Wed Jan 14 21:28:18 2009 From: MLThornton at gmail.com (MLT) Date: Wed, 14 Jan 2009 18:28:18 -0800 (PST) Subject: General direction Message-ID: Hello all: I'm a beginner to Python (and programming altogether), and am now looking to create a program of my own. What I've got in mind is a very basic pest control program that would keep track of 1) trap findings and 2) pesticides. My thought is to make each of these classes. Looking at the general outline written below, can anyone give general impression about whether I'm somewhat going in the right direction or if I need to approach it entirely differently? Thanks for any suggestions or help! Class Insect_Trapping attributes: - Unique Name - Location - Type - Frequency of Checks? - Next Check Date Within Insect_Trapping there are Trap_Count objects Trap_Count objects have the following attributes: - Date - Time - Insect A Finds - Insect B Finds - Insect C Finds - Insect A Number - Insect B Number - Insect C Number Class Pesticides attributes: - Unique Name - Usage Instructions Within Pesticide there are Pesticide_Usage objects Pesticide_Usage objects have the following attributes: - Date - Time - Location - Reason for Use - Amt Used From wuwei23 at gmail.com Wed Jan 14 21:56:40 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 18:56:40 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> On Jan 15, 5:16?am, Paul Rubin wrote: > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. Paul, have you looked into Cython at all? I've only used it trivially but it does seem to provide the potential for static typing & improve compile time checking (as well as increased performance) while retaining as Pythonic a representation as possible. From LambertDW at Corning.com Wed Jan 14 22:03:37 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Wed, 14 Jan 2009 22:03:37 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. From http Wed Jan 14 22:06:03 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:06:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> Message-ID: <7xwscx6zfo.fsf@ruckus.brouhaha.com> alex23 writes: > Paul, have you looked into Cython at all? I've only used it trivially > but it does seem to provide the potential for static typing & improve > compile time checking (as well as increased performance) while > retaining as Pythonic a representation as possible. I haven't. Maybe I should. I've looked at Pyrex and PyPy. I've spent quite a bit of time over the past year or so studying Haskell, which has been very educational and worthwhile, but not all that useful for my day-to-day tasks in the present state of things. I just looked up Cython and see that it's based on Pyrex. Worth knowing about, I guess; but basically I think C is evil. I may start looking into Pig Latin (http://wiki.apache.org/pig) for these large data crunching tasks. Unfortunately it is written in Java and my attitude towards Java is probably the one typical of Python programmers, if you know what I mean. From prologic at shortcircuit.net.au Wed Jan 14 22:11:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 13:11:51 +1000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: On Thu, Jan 15, 2009 at 1:03 PM, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. What's wrong with: >>> a = "" >>> b = bytes() >>> any([isinstance(a, x) for x in {str, bytes}]) True >>> any([isinstance(b, x) for x in {str, bytes}]) True >>> cheers James From http Wed Jan 14 22:12:16 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:12:16 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> <496e4e2e$0$10088$426a34cc@news.free.fr> Message-ID: <7xsknl6z5b.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > We're not talking about libraries here. > > Yes we are. If the default is "non-dynamic", then a class author is in > charge of explicitely allowing it when *he* see fits. Oh, I see what you mean, the standard libraries would be affected if the language default were to tone down the dynamism. True. > As long as it's up to the *user* to choose, that's ok. Your "@dynamic" > class decorator doesn't have the same implications. Well, you could use it on library classes too: from library import Libclass Libclass = dynamic(Libclass) ... would be like using the decorator on the class definition. From http Wed Jan 14 22:29:26 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:29:26 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> Message-ID: <7xeiz5xn55.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > But, the research on the language "Self" shows that even in the face > of a language with more dynamism than Smalltalk (or Python), performance > can be obtained using compiler technology. It turns out you don't have > to type those type any extra keystrokes. Compilers capable of doing > strong optimization already have to do enough analysis that they can > discover the static typing that is available in the code you write > naturally. The way to get to such performance on Python is through > efforts like PyPy. I'd be interested in seeing any publications about that Self research, which I remember someone else mentioning in another thread as well. However, part of the idea of the extra keystrokes is to allow the compiler (or an external tool like Pylint) to flag any type-inconsistency for closer programmer inspection, instead of just quietly treating it as dynamic and generating the extra code for it. The keystrokes let the tool know exactly when the dynamism is intentional. As has been mentioned a few times already, Python 3.0 has some rudimentary features for type annotation, so this concept isn't completely anathema to the Python developers. From http Wed Jan 14 22:37:37 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:37:37 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <7xiqohqlxa.fsf@ruckus.brouhaha.com> "James Mills" writes: > In fact, Python borrows features from the Functional Paradigm. Does > this make it a Functional Language ? No. Why ? Because one of the > clear requirements of the Functional Paradigm is that functions > cannot have side affects. I'd say functional programming emphasizes a style that avoids use of side effects, but saying "functions cannot have side effects" is a bit of an overstatement. Even Haskell lets you code effectfully when necessary, using the type system (IO Monad) to separate effectful code from pure code. From rhodri at wildebst.demon.co.uk Wed Jan 14 22:42:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:42:08 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> Message-ID: On Wed, 14 Jan 2009 09:09:37 -0000, Russ P. wrote: > Yes, that would indeed be nice. I am certainly not the only one who > could use a language that is excellent for both research prototyping > *and* the final, safety-critical system. Then perhaps the prototype > could just be cleaned up and "hardened" for the end product rather > than rewritten in another language -- by programmers in another state > who may fail to understand many of the details that the prototype > developer agonized over. You should always plan on throwing away your prototype anyway (though few people do), because *something* in the architecture will turn out to be not what you thought. And if the programmers in the other state fail to understand the details, maybe the developer should have documented a whole lot more (he says through gritted teeth, having had the original code as the sole documentation far too many times). We return you to your regularly scheduled original point... -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 14 22:45:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:45:41 -0000 Subject: problem calling method In-Reply-To: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> References: <21408858.01231930461043.JavaMail.root@wombat.diezmil.com> Message-ID: On Wed, 14 Jan 2009 10:54:21 -0000, wrote: > The parent is called like this (I didn't copy that line): > > def __init__(self, *args, **kwds): > # begin wxGlade: MyFrame.__init__ > kwds["style"] = wx.DEFAULT_FRAME_STYLE > wx.Frame.__init__(self, *args, **kwds) > > The frame works fine and so does the button, but somehow I cannot call > the sendmail method from the event handler... > > -- James Mills wrote : > On Wed, Jan 14, 2009 at 11:28 AM, wrote: >> class MyFrame(wx.Frame): >> def __init__(self, *args, **kwds): > > It might be helpful here if you called > the parent __init__. Like so: > > class MyFrame(wx.Frame): > def __init__(self, *args, **kwds): > super(MyFrame, self).__init__(*args, **kwargs) 1. Please don't top-post. It makes the thread of discussion really hard to follow. 2. You've over-snipped now; could you repost the MyFrame class without oversimplifying it? It would make it a lot easier to see what's going on. 3. There is no point 3. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 14 22:46:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 03:46:45 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x4p01x2w3.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 14 Jan 2009 16:34:36 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Terry Reedy writes: >> The question is where such checks should be. Guido prefers separate >> checkers (PyChecker, PyLint) rather than in the interpreter. > Again, there have to be some language extensions to communicate the > necessary info to the external tool. Or, dare one say it, conventions? -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 14 22:53:08 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:53:08 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xy6xd444b.fsf@ruckus.brouhaha.com> "Russ P." writes: > I started looking at Scala a while back. It is has many nice features. > It seamlessly combines object orientation with advanced functional > programming. It is statically typed, but the types often do not need > to be explicitly declared. It is fully "compatible" with Java, but > (like Python) it is much less verbose and more elegant, typically > requiring less (in some cases, much less) than half the lines of code > for a given task. I haven't examined Scala closely at all; my mile-high view was that it was very ugly and closely bound to Java and that the main reason for finding it interesting would be to interoperate with Java programs in a JVM. Since I didn't care about that, I didn't pursue Scala further. > But I am reluctant to use Scala for several reasons. For example, it > doesn't have "continue" and "break." The Scala folks claim they are > unnecessary, but they are sure handy sometimes. Maybe my style is bad, > but I use continue and break a lot, particularly continue. Getting by > without them could be hard. The other thing is that Scala has no > default arguments and no argument passing by keyword. Those are a > couple of my favorite Python features. So I'm basically screwed. I think in functional programming, "continue" and "break" lose some of their importance since you normally don't code any loops at all (you express iteration in terms of functions like "map"). Anyway, you might look at Haskell, although it has its own weirdness. This old paper might be of interest: http://www.haskell.org/papers/NSWC/jfp.ps From http Wed Jan 14 22:54:02 2009 From: http (Paul Rubin) Date: 14 Jan 2009 19:54:02 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> Message-ID: <7xtz81442t.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > > Again, there have to be some language extensions to communicate the > > necessary info to the external tool. > > Or, dare one say it, conventions? If the language-tool combo uses the info in a formal way, they are extensions, not conventions. From http Wed Jan 14 23:28:12 2009 From: http (Paul Rubin) Date: 14 Jan 2009 20:28:12 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xbpu9kxb7.fsf@ruckus.brouhaha.com> Steve Holden writes: > Sometimes I just want to shout "be quiet, Python is just fine the way it > is", but alas your objections are usually too sensible to be dismissed > in that way. In the long term I feel it has to be good for Python that > it has such conscientious critics. Thanks for the kind words. But I'm not aiming to be a conscientious critic; I'm just an everyday user who sometimes has to grapple with the limitations of the tool, and look for ways around them. From cs at zip.com.au Wed Jan 14 23:33:06 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Jan 2009 15:33:06 +1100 Subject: executing multiple functions in background simultaneously In-Reply-To: <496E8D50.4050900@jpl.nasa.gov> Message-ID: <20090115043306.GA4593@cskk.homeip.net> On 14Jan2009 17:11, Catherine Moroney wrote: > Cameron Simpson wrote: >> On 14Jan2009 15:50, Catherine Moroney wrote: >>> James Mills wrote: >>>> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney >>>> wrote: >>>>> I would like to spawn off multiple instances of a function >>>>> and run them simultaneously and then wait until they all complete. >> [...] >>>> Try using the python standard threading module. >>>> Create multiple instances of Thread with target=your_function >>>> Maintain a list of these new Thread instnaces >>>> Join (wait) on them. >>> What is the proper syntax to use if I wish to return variables >>> from a function run as a thread? >> >> The easy thing is to use a Queue object. The background thread uses >> .put() to place a computed result on the QUeue and the caller uses >> .get() to read from the queue. There's an assortment of other ways too. >> >> Cheers, > > Thank you for this hint. This goes a long way to solving > my problem. > > One question - is there any way to name the objects that get > put on a queue? For my application, it's important to know > which thread put a particular item on the queue. Give each thread an id (eg give it a name when you create it, and keep track). Instead of going: queue.put(value) go: queue.put((threadname,value)) and at the main program: threadname, value = queue.get() You're still put()ing a single value, it just happens to be a tuple of (threadname, value). You don't even need to use a name (and thus need to backtrack through some name->object dictionary). If every thread has some object for its state you can use the object instead of the threadname. Then you've got direct access to the thread object. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From rfritz at u.washington.edu Wed Jan 14 23:34:41 2009 From: rfritz at u.washington.edu (R Fritz) Date: Wed, 14 Jan 2009 20:34:41 -0800 Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: Raps cane on floor. It's probably an "end-of-file" sentinel because 'Z' is the last letter of the alphabet. I suspect it comes from MIT. Unix, developed at a telephone company, uses \x4, which was, in fact, the ASCII in-band end-of-transmission code and would disconnect a teletype. Does this qualify me for the dinosaur award? R Fritz On 2009-01-14 07:15:33 -0800, Mel said: > Steve Holden wrote: >> Unknown wrote: >>> On 2009-01-12, John Machin wrote: >>>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>>> file size as number of 128-byte sectors, forcing the use of an in-band >>>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>>> decades after people stopped writing Ctrl-Z at the end of text files. > >>> I believe that "feature" was inherited by CP/M from DEC OSes >>> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >>> (including the FCB) was lifted almost directly from DEC's >>> PDP-11 stuff, which probably copied it from PDP-8 stuff. >>> Perhaps in the early 60's somebody at DEC had a reason. The >>> really interesting thing is that we're still suffering because >>> of it 40+ years later. > >> I suspect this is probably a leftover from some paper tape data formats, >> when it was easier to detect the end of a file with a sentinel byte than >> it was to detect run-off as end of file. It could easily date back to >> the PDP-8. > > Perhaps, although in ASCII it's the SUB symbol: "A control character that is > used in the place of a character that is recognized to be invalid or in > error or that cannot be represented on a given device." [Wikipedia]. There > were other codes defined for End-of-Text and File-Separator. Unless the > protocol were one of DEC's own. The fact that it's > Ctrl-last-letter-of-the-alphabet makes me suspect that it was picked in a > pretty informal way. > > Mel. From Russ.Paielli at gmail.com Wed Jan 14 23:50:23 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 20:50:23 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 7:37?pm, Paul Rubin wrote: > "James Mills" writes: > > In fact, Python borrows features from the Functional Paradigm. Does > > this make it a Functional Language ? No. Why ? Because one of the > > clear requirements of the Functional Paradigm is that functions > > cannot have side affects. > > I'd say functional programming emphasizes a style that avoids use > of side effects, but saying "functions cannot have side effects" is > a bit of an overstatement. ?Even Haskell lets you code effectfully > when necessary, using the type system (IO Monad) to separate > effectful code from pure code. I think we need to distinguish here between purely functional languages and a languages that support functional programming. I would be even more averse to a purely functional language than I am to a purely OO language such as Java. One feature of Ada that I always thought was a good idea is the distinction between functions and procedures, where functions are guaranteed to not have side effects. But I don't think Ada allows advanced functional programming such as passing functions as arguments to other functions. Scala combines advanced functional and OO programming very nicely as far as I can tell (I've read some about it but haven't used it yet). I don't think it distinguishes between functions and procedures, but it does allow you to declare function arguments as "val" (value) or "var" (variable), where the former cannot be modified. If Scala only had default arguments and argument passing by keyword (and maybe "continue" and "break"), I think it would be *very* hard to beat for a very wide range of applications. From prologic at shortcircuit.net.au Thu Jan 15 00:04:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 15:04:16 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Thu, Jan 15, 2009 at 2:50 PM, Russ P. wrote: (..) > One feature of Ada that I always thought was a good idea is the > distinction between functions and procedures, where functions are > guaranteed to not have side effects. But I don't think Ada allows > advanced functional programming such as passing functions as arguments > to other functions. Russ please do your research before you post. The whole idea of the Functional Paradigm is _in fact_ computing expressions and functions. Functional Programming is an implementation of formal systems (calculus). Therefore it would be very useless for any functional language to not do what you describe aboave. Passing the result of a function as input to another function _is not_ Advanced Functional Programming, but a requirement of the functional paradigm. --JamesMills From sjmachin at lexicon.net Thu Jan 15 00:10:27 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 21:10:27 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <24eecd3a-0ca7-4255-8a1f-8f1950a5a0e0@i18g2000prf.googlegroups.com> On Jan 15, 2:03 pm, "Lambert, David W (S&T)" wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. In the anticipated/usual use case (the type/class names are hard- coded): * order is a very mild plus (you can list them in descending order of (imagined) probability) * immutability is not a problem * the number of items is not likely to be so large that duplicate entries would creep in > A set is most reasonable in a mathematical sense. This is true -- distinguishing carefully between "most reasonable" and "the most reasonable" :-) Do you actually have a use case for dynamically assembling a collection of classes/types for use with isinstance(), or are you propelled solely by mathematical reasonableness? Cheers, John From http Thu Jan 15 00:19:58 2009 From: http (Paul Rubin) Date: 14 Jan 2009 21:19:58 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: <7xy6xd6t8h.fsf@ruckus.brouhaha.com> "Russ P." writes: > I think we need to distinguish here between purely functional > languages and a languages that support functional programming. I would > be even more averse to a purely functional language than I am to a > purely OO language such as Java. I guess I'm not sure what you're considering "purely functional language" to mean, in this context. Haskell has a print function that prints on the terminal. It's "purely functional" in the sense that it conceptualizes an expression like 'print "hello"' as a "state transformer function" that takes as input a state of the world in which your screen is blank, and returns as output a state in which your screen has "hello" on it. Your program constructs this state transformer, and then the runtime system applies the transformer to the external world and presto, "hello" appears on your screen. But that is just the metaphysics of it. Normally in practical usage, you'd think of the print function as something you use more or less the way you'd use it in Python, except that you can only use it in functions with IO in their type. > One feature of Ada that I always thought was a good idea is the > distinction between functions and procedures, where functions are > guaranteed to not have side effects. But I don't think Ada allows > advanced functional programming such as passing functions as arguments > to other functions. Well, Haskell uses its type system to encapsulate functions with side effects. If you want to open a file or print something, you can only do it from a function with IO in its type. Similarly, if you want to do the equivalent of assigning a new value to a variable, you have to use a special type for that purpose, and the type isolates any code that can affect that variable, etc. I think that generalizes what you're describing about Ada. It's actually very beautiful but takes some getting used to. > If Scala only had default arguments and argument passing by keyword > (and maybe "continue" and "break"), I think it would be *very* hard to > beat for a very wide range of applications. I guess I don't understand the issue about continue and break, since if Scala is anything like Haskell, the issue doesn't really arise. Haskell doesn't have keyword args per se, but there are various ways of simulating them, at least for the usual sorts of applications. Anyway, Haskell is quite a bit more formal than Python, and it doesn't yet have as much library support for everyday tasks, and generally suffers from the not-always-practical priorities of being a "research" language, but some people have switched to it from Python. I personally find Haskell very interesting but too difficult in some aspects, and lacking in "creature comforts" compared with Python. I liked Tim Sweeney's talk about where he thinks PL design should go: http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf From leith at leithalweapon.geek.nz Thu Jan 15 00:21:42 2009 From: leith at leithalweapon.geek.nz (leith at leithalweapon.geek.nz) Date: Wed, 14 Jan 2009 21:21:42 -0800 (PST) Subject: SOAPpy under Python 2.6 Message-ID: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> I am having problems with SOAPpy after we upgraded to Python 2.6 Here is the exception I keep getting: File "C:\Dev\Phoenix\SAPI.py", line 2561, in getSystemInfo obj = self.soapProxy.getSystemInfo() File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 492, in __r_call self.__hd, self.__ma) File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 363, in __call config = self.config) TypeError: call() got multiple values for keyword argument 'encoding' Could some please help me with this? I don't have the faintest idea what the exception is on about and SOAPpy\Client.py is very hard to follow. Leith Bade From coolaj86 at gmail.com Thu Jan 15 00:25:05 2009 From: coolaj86 at gmail.com (Alvin ONeal) Date: Wed, 14 Jan 2009 22:25:05 -0700 Subject: Open Source Software in the Government Message-ID: I thought it might be useful to know that if an idea gets enough votes on Obama's site, he (supposedly) reviews it. Here are the ideas related to open source software. http://citizensbriefingbook.change.gov/search/SearchResults?str=open+source&search.x=0&search.y=0&search=Submit I hope that that is something that you all find helpful, regardless of your political orientation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 15 00:32:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 00:32:47 -0500 Subject: SOAPpy under Python 2.6 In-Reply-To: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> References: <43f460fe-9e8a-4f1c-a4c0-3b8f3755b35e@a12g2000pro.googlegroups.com> Message-ID: leith at leithalweapon.geek.nz wrote: > I am having problems with SOAPpy after we upgraded to Python 2.6 > > Here is the exception I keep getting: > > File "C:\Dev\Phoenix\SAPI.py", line 2561, in getSystemInfo > obj = self.soapProxy.getSystemInfo() > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 470, in > __call__ > return self.__r_call(*args, **kw) > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 492, in > __r_call > self.__hd, self.__ma) > File "c:\python26\Lib\site-packages\SOAPpy\Client.py", line 363, in > __call > config = self.config) > TypeError: call() got multiple values for keyword argument 'encoding' > > Could some please help me with this? > > I don't have the faintest idea what the exception is on about and > SOAPpy\Client.py is very hard to follow. As for the error: IDLE 3.0 >>> def f(a): pass >>> f(a=2,a=3) SyntaxError: keyword argument repeated (, line 1) >>> f(2,a=3) Traceback (most recent call last): File "", line 1, in f(2,a=3) TypeError: f() got multiple values for keyword argument 'a' I therefore suspect that this line return self.__r_call(*args, **kw) gave 'encoding' both positionally in args and nominally in kw. But then I would expect that to be the end of the traceback. From michele.simionato at gmail.com Thu Jan 15 00:34:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:34:11 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <5c8bf7bd-2e89-49d7-9622-2549059600f3@n33g2000pri.googlegroups.com> On Jan 14, 8:16?pm, Paul Rubin wrote: > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. ?I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. > Often, the Python program crashes halfway through, even though I > tested it on a few megabytes of data before starting the full > multi-gigabyte run, because it hit some unexpected condition in the > data that could have been prevented with more compile time checking > that made sure the structures understood by the one-off script matched > the ones in the program that generated the input data. I know the feeling. The worse thing is when you have a stupid typo (which would be immediately caught by a compiler) which affects a section of the code that runs after 8 hours of computations. Pylint helps - when you remember torun it on all your code base - but it is definitely not the same as a compiler. > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. ?I > think the Python community should be aiming towards this. Dunno. Python has been designed from the start to be fully dynamic and with no type checks, I don't think it is really possible to change that. On the other hand, one could envision a Python-like language with more type safety (there are already a few experiments in that direction). Personally, I would be glad to trade some flexibility for additional safety; if you we get more speed as an additional bonus, that's fine too. From koranthala at gmail.com Thu Jan 15 00:36:25 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 14 Jan 2009 21:36:25 -0800 (PST) Subject: Python Crashes References: Message-ID: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> On Jan 15, 3:12?am, "James Mills" wrote: > On Thu, Jan 15, 2009 at 6:57 AM, koranthala wrote: > > Hi, > > ? ?I have a twisted based application based on Python 2.4.3. I also > > have one thread in this application. > > > ? ?I found that my program crashes repeatedly after a random interval > > (ranging from 10 min to 3 hr). When I say crash, it is not just that > > the program dies. Rather in WinXP - a window comes mentioning that > > 'Python.exe unexpectedly crashed'. > > ? ?I tried putting in catching the exception by using try: except - > > and logging everything. But the logging code is also not hit, i.e. > > even the 'except' code is not hit. I feel that the base python > > interpreter itself is crashing due to some bug in my program. > > ? ?Earlier, I had put code as > > try: > > except: > > ?log > > ? ? At this time, my whole machine also froze. It was so slow that > > one mouse movement happened after 7-8 minutes after I moved the > > mouse. > > > Then I modified the code to > > try: > > except Exception: > > ?log > > > ? ?Then, the machine no longer freezes. But, still there is no > > logging of errors happening too. > > > ? ?Could anyone guide me on this? I have been facing this issue for a > > day, and cannot seem to solve it. > > > P.S -> ? ?I am not allowed to post the code of application - so I hope > > I have explained it enough. > > Do you use any 3rd party extensions (DLLs) ? > > cheers > James I am using 9 3rd party modules and there are some DLLs too - PIL etc. But the problem is that the issue comes only after 3 hrs usually. When I checked the memory using taskmanager, I found that it is not going too high. Is there any tool or anything which will help me debug this? From Russ.Paielli at gmail.com Thu Jan 15 00:36:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 21:36:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 9:04?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 2:50 PM, Russ P. wrote: > > (..) > > > One feature of Ada that I always thought was a good idea is the > > distinction between functions and procedures, where functions are > > guaranteed to not have side effects. But I don't think Ada allows > > advanced functional programming such as passing functions as arguments > > to other functions. > > Russ please do your research before you post. Please spare me the pedantry. > The whole idea of the Functional Paradigm is _in fact_ computing > expressions and functions. Functional Programming is an implementation > of formal systems (calculus). Therefore it would be very useless > for any functional language to not do what you describe aboave. So what? > Passing the result of a function as input to another function > _is not_ Advanced Functional Programming, but a requirement > of the functional paradigm. Oh, excuse me for misusing the word "advanced." I was merely using it to distinguish it from programming without side effects, which I would regard as more "basic" functional programming. But then I'm not as sophisticated as you. By the way, your statements earlier to the effect that Python is as good as any language for large-scale safety-critical systems were very interesting. I'm wondering how you "know" that. Also, have you checked with Boeing or ARINC on that? Last I heard, those neanderthals at ARINC are still suporting Ada as the standard language for flight systems. I urge you to get in touch with them and straighten them out right away. From tjreedy at udel.edu Thu Jan 15 00:40:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 00:40:12 -0500 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. I agree. However, isinstance predates set. Hence the status quo. From michele.simionato at gmail.com Thu Jan 15 00:41:14 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:41:14 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> Message-ID: <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> On Jan 12, 10:58?pm, Paul Rubin wrote: > We are in an era for programming languages sort of like the Windows 95 > era was for operating systems, where everything is broken but some of > the fixes are beginning to come into view. ?So there is no language > that currently really works the right way, but some of them including > Python are (one hopes) moving in good directions. To be fair, this has been true for the last 50 years. If a language that works the right way really existed, CS would be dead and there would be no progress to make. Happily I think we will never end in that situation ;) From Russ.Paielli at gmail.com Thu Jan 15 00:45:52 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 21:45:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xiqohqlxa.fsf@ruckus.brouhaha.com> Message-ID: On Jan 14, 9:04?pm, "James Mills" wrote: Oh, by the way, please quit emailing me every time you reply to one of my posts. You're the only one here who does that, and it isn't necessary. Thanks. From michele.simionato at gmail.com Thu Jan 15 00:51:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:51:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> On Jan 13, 2:48?am, "Russ P." wrote: > I started looking at Scala a while back. It is has many nice features. > It seamlessly combines object orientation with advanced functional > programming. I don't like that. Scala was designed with the idea of putting together the two worlds, by I think the result was to get the complications of both worlds. I don't think a SML-like functional language needs to be integrated with object orientation, it is fine just without it. The old quote applies: """ Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make additional features appear necessary. -- William Clinger """ From rhodri at wildebst.demon.co.uk Thu Jan 15 00:56:12 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 15 Jan 2009 05:56:12 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xtz81442t.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x4p01x2w3.fsf@ruckus.brouhaha.com> <7xtz81442t.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 03:54:02 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > Again, there have to be some language extensions to communicate the >> > necessary info to the external tool. >> >> Or, dare one say it, conventions? > > If the language-tool combo uses the info in a formal way, they are > extensions, not conventions. If the tool isn't part of the compile/run cycle, I'm not convinced that that's a useful view to take. It is useful to regard to C preprocessor statements as extensions to C, though it's had the result that nobody uses that quite general purpose preprocessor for anything other than C. It's less obvious that the conventional folding marks "{{{ ... }}}" some editors (can be made to) recognise are usefully considered as extensions to any language. But this is just quibbling over semantics. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at holdenweb.com Thu Jan 15 00:58:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 15 Jan 2009 00:58:11 -0500 Subject: executing multiple functions in background simultaneously In-Reply-To: <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> References: <496E8D50.4050900@jpl.nasa.gov> <20090115012027.9754.2078839787.divmod.quotient.2700@henry.divmod.com> Message-ID: Jean-Paul Calderone wrote: > On Wed, 14 Jan 2009 17:11:44 -0800, Catherine Moroney > wrote: >> [snip] >>> >>> The easy thing is to use a Queue object. The background thread uses >>> .put() to place a computed result on the QUeue and the caller uses >>> .get() to read from the queue. There's an assortment of other ways too. >>> >>> Cheers, >> >> Thank you for this hint. This goes a long way to solving >> my problem. >> >> One question - is there any way to name the objects that get >> put on a queue? For my application, it's important to know >> which thread put a particular item on the queue. > > There's lots and lots of ways. The simplest might be to put two-tuples > of the thread identifier and some other object. eg > > queue.put((threadID, obj)) > > Perhaps you can accomplish your goal that way, or perhaps a minor > variation would be more suitable. > Catherine: Did you attend one of my classes at JPL? Feel free to rope me in to discussions like this if so. (Or even if not: NASA are a good customer). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From michele.simionato at gmail.com Thu Jan 15 00:59:16 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 21:59:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Jan 13, 6:47?pm, Bruno Desthuilliers wrote: > I really wonder why peoples that seems to dislike one of the central > features of Python - it's dynamism - still use it (assuming of course > they are free to choose another language). And FWIW, I at least had a > partial answer on this. It could just be an issue of practicality. Python is an industrial strength language with libraries for everything and you can use it for your daily work. There are nice little languages out there that are however not usable for real work because of lack of libraries/lack of support/small community etc. From marco.m.petersen at gmail.com Thu Jan 15 01:01:21 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:01:21 -0800 (PST) Subject: 2to3 Help? Message-ID: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> I have Python 3.0. I tried to use the 2to3 program included with the interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. When I try to start it form the Python command line, it says it is a syntax error. This was the line of code: $ 2to3 testscript.py Any help would be appreciated. Thanks - Marco From prologic at shortcircuit.net.au Thu Jan 15 01:07:46 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:07:46 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Thu, Jan 15, 2009 at 3:59 PM, Michele Simionato wrote: (...) > It could just be an issue of practicality. Python is an industrial > strength language with libraries for everything and you can use it for > your daily work. There are nice little languages out there that are > however not usable for real work because of lack of libraries/lack of > support/small community etc. So _exactly_ how does this thread relate to the subject: Does Python really follow its philosophy of "Readability counts"? --JamesMills From prologic at shortcircuit.net.au Thu Jan 15 01:09:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:09:49 +1000 Subject: 2to3 Help? In-Reply-To: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:01 PM, wrote: > I have Python 3.0. I tried to use the 2to3 program included with the > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. > When I try to start it form the Python command line, it says it is a > syntax error. > > This was the line of code: > > $ 2to3 testscript.py > > Any help would be appreciated. $ 2to3 testscript.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Can't open testscript.py: [Errno 2] No such file or directory: 'testscript.py' RefactoringTool: No files need to be modified. RefactoringTool: There was 1 error: RefactoringTool: Can't open testscript.py: [Errno 2] No such file or directory: 'testscript.py' Seems to work perfectly fine here. It would greatly help if you showed us the error! cheers James From marco.m.petersen at gmail.com Thu Jan 15 01:17:25 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:17:25 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> On Jan 15, 2:09?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:01 PM, ? wrote: > > I have Python 3.0. I tried to use the 2to3 program included with the > > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. > > When I try to start it form the Python command line, it says it is a > > syntax error. > > > This was the line of code: > > > $ 2to3 testscript.py > > > Any help would be appreciated. > > $ 2to3 testscript.py > RefactoringTool: Skipping implicit fixer: buffer > RefactoringTool: Skipping implicit fixer: idioms > RefactoringTool: Skipping implicit fixer: set_literal > RefactoringTool: Skipping implicit fixer: ws_comma > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or > directory: 'testscript.py' > RefactoringTool: No files need to be modified. > RefactoringTool: There was 1 error: > RefactoringTool: Can't open testscript.py: [Errno 2] No such file or > directory: 'testscript.py' > > Seems to work perfectly fine here. > > It would greatly help if you showed us the error! > > cheers > James The error was: >>> $ 2to3.py testscript.py File "", line 1 $ 2to3.py testscript.py ^ Syntax Error: Invalid Syntax >>> From steven at REMOVE.THIS.cybersource.com.au Thu Jan 15 01:18:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 06:18:29 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> Message-ID: On Thu, 15 Jan 2009 16:07:46 +1000, James Mills wrote: > On Thu, Jan 15, 2009 at 3:59 PM, Michele Simionato > wrote: > (...) > >> It could just be an issue of practicality. Python is an industrial >> strength language with libraries for everything and you can use it for >> your daily work. There are nice little languages out there that are >> however not usable for real work because of lack of libraries/lack of >> support/small community etc. > > So _exactly_ how does this thread relate to the subject: Does Python > really follow its philosophy of "Readability counts"? If you had followed the thread since the beginning, you'd see that the topic has evolved (or perhaps strayed) from the original subject. -- Steven From michele.simionato at gmail.com Thu Jan 15 01:20:07 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:20:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> On Jan 14, 3:27?am, Paul Rubin wrote:> > I don't understand why some folks spew such violent rhetoric against > the idea of augmenting Python with features to alert you automatically > when you depart from the convention, so that you can check that the > departure is actually what you wanted. ?A lot of the time, I find, the > departures are accidental and automated checks would save me > considerable debugging. I would be fine having something like pylint built-in in the language and running at every change of the source code (unless disabled with a command line switch). I think this is the only reasonable solution to get some additional protection we can hope for. A true change of the language IMO is impossible, both technically, politically and for legacy issue. Also, I am not convinced it would be a good idea, even theoretically. It is easier to write a new Python-like language from scratch than to add type checking to Python (I think you were not proposing adding type checking in this post, right?). Michele Simionato From prologic at shortcircuit.net.au Thu Jan 15 01:24:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:24:06 +1000 Subject: 2to3 Help? In-Reply-To: <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:17 PM, wrote: >>>> $ 2to3.py testscript.py > File "", line 1 > $ 2to3.py testscript.py > ^ > Syntax Error: Invalid Syntax Oh i see... You need to do 2 things: 1) Run 2to3 on the shell not the python interpreter. 2) Learn some basic UNIX. cheers James From steven at REMOVE.THIS.cybersource.com.au Thu Jan 15 01:25:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 06:25:16 GMT Subject: Python 3 isinstance References: Message-ID: On Wed, 14 Jan 2009 22:03:37 -0500, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) *shrug* Just change the {} to () and it will work fine. Or do this: isinstance(s, tuple({str, bytes})) > tuples have order, immutability, and the possibility of repeat items. Yes. And why is this a problem? > A set is most reasonable in a mathematical sense. What is the benefit of using sets instead of tuples inside isinstance? -- Steven From tjreedy at udel.edu Thu Jan 15 01:30:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 01:30:59 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: r wrote: > On Jan 14, 4:43 pm, Terry Reedy wrote: > [snip] >> I think the 'main' IDLE maintainer is no longer active. I think someone >> who would do more than fix critical bugs might be welcome. > > Hello Terry, > That's what i was beginning to think. I am not quite ready (as far as > my skills are concerned) to put out something that would be as useful > to many people. I could hack together something real quick for myself. > This is why i am looking for like-minded people who would be > interested in this. I have the foresight and willpower at this point > to contribute something meaningful to the Python community -- to give > back. If you are willing and able to channel your obvious enthusiasm and energy into incremental improvements, you could make meaningful contributions within weeks and months. If you go to http://bugs.python.org/issue?@template=search&status=1 and select IDLE in the 'Components' field and hit 'Search', you will get a list of (at the moment) 66 open issues. Some are bug reports, some feature requests. Some have patches waiting for review and some not. There may be some (near?) duplicate and obsolete items that could be closed after review. Pick one issue and help resolve it. Reviewing exiting patches would be definitely helpful. For instance, I would particularly like to see http://bugs.python.org/issue2704 Patch to make PyShell behave more like a Terminal interface tested and applied. It was posted last April and revised in June. Should you decide to do this, and wish further input from me, let me know, on or off list. > OFF-TOPIC:(but related) > What is the state of Tkinter at this point. Is an active effort under > way to port TK 8.5 into Python? Tkinter and IDLE are very important to > Python, but i understand there are much more important areas where the > GURU's are concentrating. Should there be a calling for "others" to > get involved here? I would like to help out. Running a search from the same page for '8.5' in the 'All text' box gave no hits. I would tend to expect that 8.5 upgrades to tkinter would be welcome at some point, but anyone actively ready to work on it could open a tracker issue or inquire on py-dev first. Terry Jan Reedy From marco.m.petersen at gmail.com Thu Jan 15 01:32:45 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:32:45 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> Message-ID: <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> > You need to do 2 things: > > 1) Run 2to3 on the shell not the python interpreter. > 2) Learn some basic UNIX. > > cheers > James I tried to run it on the command prompt (I use Windows XP) but it doesn't work either. I opened the command prompt: C:\Documents and Settings\User> Then I typed '$ 2to3 testscript.py': C:\Documents and Settings\User>$ 2to3.py testscript.py But then this appears: C:\Documents and Settings\User>$ 2to3.py testscript.py '$' is not recognized as an internal or external command, operable program or batch file. Anyway I'll try some UNIX. Thanks. From michele.simionato at gmail.com Thu Jan 15 01:34:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:34:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Jan 14, 4:18?am, "Russ P." wrote: > > So I can claim that Python is not strictly object oriented until it > gets encapsulation (in the sense of data hiding). That is simply a > fact, and no amount of pleading or obfuscation will change it. > > Should Python get true encapsulation? I don't know. Maybe > encapsulation cannot be added without excessive overhead or without > compromising other more important aspects and features of the > language. But I do know that not having encapsulation is a limitation > to the use of Python for good software engineering. I may be in the > minority in the Python "community" on this one, but I am apparently in > the majority in the OO programming "community." There are lots of Python developers (and most of the core developers) that think the OO community is wrong about enforced encapsulation. Personally, I think in a few years everybody will realize the mistake of enforced encapsulation and that the OO definition in the Wikipedia page will be changed. Even if not, Wikipedia definitions does not matter much, everybody has his own idea of what OO means, and the Python definition is good as any other. Don't get pissed off on words. Michele Simionato From lipun4u at gmail.com Thu Jan 15 01:34:57 2009 From: lipun4u at gmail.com (asit) Date: Wed, 14 Jan 2009 22:34:57 -0800 (PST) Subject: why o/p is different ??? Message-ID: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> I recently faced a peculiar o/p. My objective is to remove the command name(my script name) from sys.argv[0]. I coded like this import urllib import sys print "\n\n\t\tlipun4u[at]gmail[dot]com" print "\t\t------------------------" apppath = sys.argv[0].split("/") appname = apppath[len(apppath)-1] print appname if len(sys.argv) not in [2,3]: print "Usage : " + appname + " [options]" print "e.g. : " + appname + "www.google.com --verbose" print "\n\t[option]" print "\t\t--verbose/-V for verbose output" print "\t\t-r for recursive scan" sys.exit(1) site = appname.replace("http://","").rsplit("/",1)[0] site = "http://" + site.lower() print site It showed the required o/p in the IDLE here is the o/p lipun4u[at]gmail[dot]com ------------------------ linkscan.py Usage : linkscan.py [options] e.g. : linkscan.pywww.google.com --verbose [option] --verbose/-V for verbose output -r for recursive scan Traceback (most recent call last): File "I:/Python26/linkscan.py", line 18, in sys.exit(1) SystemExit: 1 But in command prompt the o/p is still faulty lipun4u[at]gmail[dot]com ------------------------ I:\Python26\linkscan.py Usage : I:\Python26\linkscan.py [options] e.g. : I:\Python26\linkscan.pywww.google.com --verbose [option] --verbose/-V for verbose output -r for recursive scan I:\Python26> regards asit dhal From prologic at shortcircuit.net.au Thu Jan 15 01:38:40 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:38:40 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:20 PM, Michele Simionato wrote: (...) > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. Protection from what ? If one is a clumsy programmer, then perhaps one ought to be using a language that holds one's hand. --JamesMills From prologic at shortcircuit.net.au Thu Jan 15 01:40:15 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:40:15 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:34 PM, Michele Simionato wrote: (...) > There are lots of Python developers (and most of the core developers) > that think the OO community is wrong about enforced encapsulation. > Personally, I think in a few years everybody will realize the mistake > of enforced encapsulation and that the OO definition in the Wikipedia > page will be changed. Even if not, Wikipedia definitions does not > matter much, everybody has his own idea of what OO means, > and the Python definition is good as any other. Don't get pissed off > on words. Amen! The first thing said right in this entire thread! (one of) --JamesMills From michele.simionato at gmail.com Thu Jan 15 01:40:52 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jan 2009 22:40:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> On Jan 15, 7:38?am, "James Mills" wrote: > > If one is a clumsy programmer, then perhaps > one ought to be using a language that holds one's hand. Yes, and I use Python because it is a language that holds my hand, otherwise I would use C and enjoy segmentation faults all the time. From wuwei23 at gmail.com Thu Jan 15 01:42:14 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 22:42:14 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <76b04548-303d-4f39-aaab-42c9f2ee666f@x16g2000prn.googlegroups.com> On Jan 15, 4:34?pm, asit wrote: > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] I'd replace these two lines with the following: import os.path # at the top of the file, of course appname = os.path.basename(sys.argv[0]) Also note that you can use negative indices in lists, with -1 being the last element, -2 the last but one etc. From prologic at shortcircuit.net.au Thu Jan 15 01:43:29 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:43:29 +1000 Subject: 2to3 Help? In-Reply-To: <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:32 PM, wrote: > I tried to run it on the command prompt (I use Windows XP) but it > doesn't work either. I did not realize you were using WIndows :) Normally most shells in the UNIX/Linux world start with a '$'. > I opened the command prompt: > > C:\Documents and Settings\User> > > Then I typed '$ 2to3 testscript.py': > > C:\Documents and Settings\User>$ 2to3.py testscript.py > > But then this appears: > > C:\Documents and Settings\User>$ 2to3.py testscript.py > '$' is not recognized as an internal or external command, > operable program or batch file. Your problem is, you are treating the '$' (most likely copied/pasted from readings on the web) as part of what you need to enter into the command prompt. '$' is (like I said above) normally part of most commonly configured shells (eg: Bash). You need to just enter: 2to3 testscript.py > Anyway I'll try some UNIX. Thanks. That is a good idea :) Windows teaches you nothing! cheers James From delroth at gmail.com Thu Jan 15 01:45:47 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Thu, 15 Jan 2009 07:45:47 +0100 Subject: why o/p is different ??? In-Reply-To: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <1ba9eaed0901142245g22aa86f7y5fef5ef3a29a298f@mail.gmail.com> Use os.path.basename : >>> os.path.basename('/foo/bar/baz.py') 'baz.py' It will have the expected behavior on each system. You could also use os.sep instead of '/' in your split method call, but os.path.basename is more elegant. On Thu, Jan 15, 2009 at 7:34 AM, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this > > import urllib > import sys > > > print "\n\n\t\tlipun4u[at]gmail[dot]com" > print "\t\t------------------------" > > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] > print appname > > if len(sys.argv) not in [2,3]: > print "Usage : " + appname + " [options]" > print "e.g. : " + appname + "www.google.com --verbose" > print "\n\t[option]" > print "\t\t--verbose/-V for verbose output" > print "\t\t-r for recursive scan" > sys.exit(1) > > site = appname.replace("http://","").rsplit("/",1)[0] > site = "http://" + site.lower() > print site > > > It showed the required o/p in the IDLE > here is the o/p > > lipun4u[at]gmail[dot]com > ------------------------ > linkscan.py > Usage : linkscan.py [options] > e.g. : linkscan.pywww.google.com --verbose > > [option] > --verbose/-V for verbose output > -r for recursive scan > > Traceback (most recent call last): > File "I:/Python26/linkscan.py", line 18, in > sys.exit(1) > SystemExit: 1 > > But in command prompt the o/p is still faulty > > lipun4u[at]gmail[dot]com > ------------------------ > I:\Python26\linkscan.py > Usage : I:\Python26\linkscan.py [options] > e.g. : I:\Python26\linkscan.pywww.google.com --verbose > > [option] > --verbose/-V for verbose output > -r for recursive scan > > I:\Python26> > > regards > asit dhal > -- > http://mail.python.org/mailman/listinfo/python-list > From wuwei23 at gmail.com Thu Jan 15 01:46:37 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 22:46:37 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Jan 15, 4:32?pm, marco.m.peter... at gmail.com wrote: > I tried to run it on the command prompt (I use Windows XP) but it > doesn't work either. > '$' is not recognized as an internal or external command, > operable program or batch file. '$' is used in the instructions to denote a command prompt. You're not supposed to type it :) In your case '$' == 'C:\Documents and Settings\User>'; just type '2to3.py testscript.py' and it should work (assuming it's location is in your PATH and you have the right handlers set up to launch it) From prologic at shortcircuit.net.au Thu Jan 15 01:47:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 16:47:25 +1000 Subject: why o/p is different ??? In-Reply-To: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 4:34 PM, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this If you _really_ want to remove your script_name from sys.argv, then do this: del sys.argv[0] If you're just after what the name of your script is that's being run (for human readability) try the following function (taken from pymills): def getProgName(): """getProgName() -> str Return the name of the current program being run by working it out from the script's basename. """ return os.path.basename(sys.argv[0]) -------------------------------------------------- cheers James From marco.m.petersen at gmail.com Thu Jan 15 01:52:43 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 22:52:43 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: Oh okay. I don't think my Python installation is in PATH yet. I'll try to add it then. From wuwei23 at gmail.com Thu Jan 15 02:02:51 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 23:02:51 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: On Jan 15, 4:52?pm, marco.m.peter... at gmail.com wrote: > Oh okay. I don't think my Python installation is in PATH yet. I'll try > to add it then. I don't yet have 3.0 installed, but my guess is you'll also need to have 'C:\Python30\Scripts' in your path as well. I'm assuming that's where it resides, so check first. From http Thu Jan 15 02:02:52 2009 From: http (Paul Rubin) Date: 14 Jan 2009 23:02:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> Message-ID: <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Michele Simionato writes: > > there is no language that currently really works the right way, > > but some of them including Python are (one hopes) moving in good > > directions. > > To be fair, this has been true for the last 50 years. If a language > that works the right way really existed, CS would be dead and there > would be no progress to make. Happily I think we will never end in > that situation ;) I'd say there was a time Lisp worked the right way, and a time C worked the right way, and maybe a time Python worked the right way, and for a while, Algol 60 was perfection embodied. But times have changed more than those languages have, so they no longer work the right way. The right way basically can never mean more than "the best that can be done using current technology". Right now, the stuff happening in the programming-language research world is light years beyond what us poor peons are using in everyday hacking, while we face harder and harder challenges due to bigger and faster computers leading to more complex software, and a vastly enlarged attack surface exposed to internet security threats. Have you looked at Tim Sweeney's talk that I mentioned in another post? http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf From Russ.Paielli at gmail.com Thu Jan 15 02:05:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 23:05:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> Message-ID: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> On Jan 14, 10:40?pm, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:34 PM, Michele Simionato wrote: > > (...) > > > There are lots of Python developers (and most of the core developers) > > that think the OO community is wrong about enforced encapsulation. > > Personally, I think in a few years everybody will realize the mistake > > of enforced encapsulation and that the OO definition in the Wikipedia > > page will be changed. Even if not, Wikipedia definitions does not > > matter much, everybody has his own idea of what OO means, > > and the Python definition is good as any other. Don't get pissed off > > on words. > > Amen! The first thing said right in this entire thread! (one of) > > --JamesMills Wait a minute. Aren't the guy who just took me to task about the definition of functional programming? So the definition of functional programming is written in stone, but the definition of OO programming is written in smoke? Just for the record, I really don't care much about the definition of OO programming. I brought it up only because someone tried to claim that "enforced" encapsulation is a terrible idea. Well, as far as I can tell, the majority of OO "programmers" (and software engineers, software architects, etc.) seem to think otherwise. Maybe they are wrong -- but I seriously doubt it. As I said before, enforced encapsulation may not be appropriate for every application, but it is definitely appropriate for some. Not every door needs a lock, but certainly some do. From http Thu Jan 15 02:10:07 2009 From: http (Paul Rubin) Date: 14 Jan 2009 23:10:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: <7x3afl3v00.fsf@ruckus.brouhaha.com> Michele Simionato writes: > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. A true change of the > language IMO is impossible, both technically, politically and for > legacy issue. Also, I am not convinced it would be a good idea, even > theoretically. It is easier to write a new Python-like language > from scratch than to add type checking to Python (I think you > were not proposing adding type checking in this post, right?). I think this sub-thread has been mostly about dynamically creating new class instance attributes, but yes, at one point I did suggest adding type checking (ML-like inference) to pylint, presumably with feedback to the compiler for optimization purposes. I noted that Python 3.0 in fact has some features to support annotations for the purpose of static type checking, so it's not as far off the wall as it might sound. From marco.m.petersen at gmail.com Thu Jan 15 02:13:17 2009 From: marco.m.petersen at gmail.com (marco.m.petersen at gmail.com) Date: Wed, 14 Jan 2009 23:13:17 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: <9262bda5-e884-427b-a20d-8391db801230@t39g2000prh.googlegroups.com> > I don't yet have 3.0 installed, but my guess is you'll also need to > have 'C:\Python30\Scripts' in your path as well. I'm assuming that's > where it resides, so check first. Its in C:\Python30\Tools\Scripts. Anyway it now works. C:\Documents and Settings\User>python C:\Python30\Tools\Scripts \2to3.py C:\Python30\testscript.py Thanks a lot alex23. From wuwei23 at gmail.com Thu Jan 15 02:15:18 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Jan 2009 23:15:18 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: On Jan 15, 1:06?pm, Paul Rubin wrote: > I just looked up Cython and see that it's based on Pyrex. ?Worth > knowing about, I guess; but basically I think C is evil. I feel much the same way, but the recent modifications to Cython that provide a "pure Python"[1] approach mean that you can minimise the amount of C you need to write and still take advantage of features like static types: @cython.locals(s=cython.double, i=int, n=int) def harmonic_sum(n): s = 0 for i in range(1, n+1): s += 1.0 / i return s The same code will both run in Python and compile via Cython. (I'm surprised the new "pure" approach isn't more clearly promoted on the site.) 1: http://wiki.cython.org/pure From Russ.Paielli at gmail.com Thu Jan 15 02:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 14 Jan 2009 23:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> Message-ID: On Jan 14, 9:51?pm, Michele Simionato wrote: > On Jan 13, 2:48?am, "Russ P." wrote: > > > I started looking at Scala a while back. It is has many nice features. > > It seamlessly combines object orientation with advanced functional > > programming. > > I don't like that. Scala was designed with the idea of putting > together the two worlds, by I think the result was to get the > complications of both worlds. I don't think a SML-like functional > language needs to be integrated with object orientation, it is fine > just without it. The old quote > applies: > > """ > Programming languages should be designed not by piling feature on top > of feature, but by removing the weaknesses and restrictions that make > additional features appear necessary. -- William Clinger > """ I haven't used Scala yet, but I can't see any inherent problem with combining OO and functional programming. Doesn't Python itself do that to some extent, after all? The two paradigms are actually complementary: FP is stateless and the OOP is state-based. Some problems are best solved using OOP and some are best solved using FP. Are you suggesting that a programmer should use a different language for each problem? What if a software project involves many subproblems, some of which are best solved using OOP and others of which are best solved using FP? Should one language be used for one part of the project and another language for the other? I don't think so. From aleksandr.goretoy at gmail.com Thu Jan 15 02:20:16 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:20:16 -0600 Subject: error: cannot invoke setopt() - perform() is currently running Message-ID: hello all, I have a problem when using pycurl with threading Thread from threading import Thread the error i get is this: error: cannot invoke setopt() - perform() is currently running how do I catch a error like this in my code and perform a action like wait for perform to finish until it tries to setopt again? Has anyone come across this? Any help in this matter will be highly appreciated, I've spent a week on this and can't seem to figure it out. Googling hasn't brought me any thing except my own code....hahaha go figure TIA -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From sjmachin at lexicon.net Thu Jan 15 02:26:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 14 Jan 2009 23:26:48 -0800 (PST) Subject: 2to3 Help? References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> <4d17d2d1-1e7a-41e6-b9d2-269b8f8a5fa6@r15g2000prd.googlegroups.com> <2905b8cb-f116-4cdc-a60d-56688009059f@a26g2000prf.googlegroups.com> Message-ID: <5ac3d83e-3394-49de-a730-5578c8feb0ea@g39g2000pri.googlegroups.com> On Jan 15, 5:52?pm, marco.m.peter... at gmail.com wrote: > Oh okay. I don't think my Python installation is in PATH yet. I'll try > to add it then. Am I permitted to ask a really silly question? Thanks. Here it is: How much working 2.X code do you have that needs migrating from 2.x to 3.x? Cheers, John From aleksandr.goretoy at gmail.com Thu Jan 15 02:36:58 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:36:58 -0600 Subject: error: cannot invoke setopt() - perform() is currently running In-Reply-To: References: Message-ID: more info for all: the class I'm trying to use threading on top of called pcrunchly. I've posted it previously on here, but you can find it at this link. http://article.gmane.org/gmane.comp.python.general/604050 How can i make this work with threading Thread? On 1/15/09, alex goretoy wrote: > hello all, > > I have a problem when using pycurl with threading Thread > > from threading import Thread > > the error i get is this: > > error: cannot invoke setopt() - perform() is currently running > > > how do I catch a error like this in my code and perform a action like > wait for perform to finish until it tries to setopt again? > > Has anyone come across this? > > Any help in this matter will be highly appreciated, I've spent a week > on this and can't seem to figure it out. Googling hasn't brought me > any thing except my own code....hahaha go figure TIA > > -- > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From aleksandr.goretoy at gmail.com Thu Jan 15 02:38:25 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 15 Jan 2009 01:38:25 -0600 Subject: error: cannot invoke setopt() - perform() is currently running In-Reply-To: References: Message-ID: sorry for multi posting It's a habit I have. The closest thing I can come up with is this http://pycurl.cvs.sourceforge.net/viewvc/pycurl/pycurl/examples/retriever-multi.py?revision=1.29&view=markup but how to make this work with pcrunchly and threading Thread? On 1/15/09, alex goretoy wrote: > more info for all: > > the class I'm trying to use threading on top of called pcrunchly. I've > posted it previously on here, but you can find it at this link. > > http://article.gmane.org/gmane.comp.python.general/604050 > > How can i make this work with threading Thread? > > On 1/15/09, alex goretoy wrote: >> hello all, >> >> I have a problem when using pycurl with threading Thread >> >> from threading import Thread >> >> the error i get is this: >> >> error: cannot invoke setopt() - perform() is currently running >> >> >> how do I catch a error like this in my code and perform a action like >> wait for perform to finish until it tries to setopt again? >> >> Has anyone come across this? >> >> Any help in this matter will be highly appreciated, I've spent a week >> on this and can't seem to figure it out. Googling hasn't brought me >> any thing except my own code....hahaha go figure TIA >> >> -- >> -Alex Goretoy >> http://www.alexgoretoy.com >> somebodywhocarez at gmail.com >> > > > -- > -Alex Goretoy > http://www.alexgoretoy.com > somebodywhocarez at gmail.com > -- -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com From python at rcn.com Thu Jan 15 02:57:06 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 14 Jan 2009 23:57:06 -0800 (PST) Subject: Alphametric fun with Python Message-ID: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> Thought you guys might enjoy this: http://code.activestate.com/recipes/576615/ SEND + MORE == MONEY 9567 + 1085 == 10652 Raymond Hettinger From Lie.1296 at gmail.com Thu Jan 15 03:02:57 2009 From: Lie.1296 at gmail.com (Lie) Date: Thu, 15 Jan 2009 00:02:57 -0800 (PST) Subject: why cannot assign to function call References: <495867C2.7080807@gmail.com> <5e807c67-7d97-4b8a-8c5f-a3b97f5c5003@i20g2000prf.googlegroups.com> <200812301421.29888.mail@johnohagan.com> <6s8s6nF4op56U2@mid.uni-berlin.de> Message-ID: <8ae18e97-76e6-4e29-a9de-827fc06d8cab@g1g2000pra.googlegroups.com> On Jan 5, 9:03?am, Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch wrote: > > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > > > > On Tue, Dec 30, 2008 at 02:21:29PM +0000, John O'Hagan wrote: > > > What the Python community often overlooks, when this discussion again > > > rears its ugly head (as it seems to every other hour or so), is that its > > > assignment model is BIZARRE, as in it's conceptually different from > > > virtually all other languages substantially taught in undergraduate > > > computer science programs. > > > What's the difference between Python and Java or C# here!? ?Or are they > > also "BIZARRE"!? > > I am happily ignorant of C#. ?As for Java, take the following code: > > ? a = 6; > ? a = 5; > > In Python, when you execute the equivalent code, it causes two > different objects to spring into existence, the first of which may be > cleaned up by the GC (except that since we're using small integers, > that's not likely to happen). ?Unless I'm misinformed (which is very > possible, my experience with Java has been extremely limited) in Java > that's not the case... ?the storage is allocated to the name a when > you execute its declaration, and the *same storage* is reused upon > subsequent assignment. > > That behaves exactly like named bins. > > > > And for that matter, it's pretty unintuitive generally. > > > Names and objects are quite "natural" IMHO. ?There are many real world > > objects which we attach one or more names to, or refer to in sequences > > like "please give me the third book on that shelve" (``shelve[2]``). > > Indeed, but the way we assign names to them does not behave as it does > in Python. ?Nor does Python's assignment work like it does in algebra, > or anywhere else the Python student is particularly likely to have > seen variable assignment before encountering it in Python. ?Let's > define intuitive, shall we? ?From dictionary.com (choosing the > definition which most easily makes my point): > > ? intuitive: adj. ?capable of being perceived or known by intuition. > > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY > a student could intuit Python's variable assignment behavior, having > never been exposed to that same behavior prior. ?It needs to be > taught. Which limb would you like to go with? > > > That is, in what I'll call "normal" computer languages, a variable name > > > is thought of as the address of a bin where some data is stored, and the > > > name is inexorably tied to that bin. > > > You just call that "normal" or "intuitive" because that's what you > > learned first. > > In a sense, yes... but isn't that what intuition really is? ?You can > figure something out whithout being told how it works... ?That's > either because it's immediately obvious from observing it, or it > behaves like something you've seen before. ?That is what intitive is. No. You've just said it yourself, something is intuitive if "it behaves like something you've seen before". People have different experience, people deeply involved in mathematics would see "named bin" is the obvious thing to go, however commoners (including mathematician) will have different say: "Derek is the name of a human object" instead of "Derek is a specific collection of atoms that resembles human". This is also why python community tend to avoid the use of "variable", because python's name doesn't behave like variables in mathematics, it behaves like "name". (heck, one would argue that even "variable" in programming is not exactly the same as "variable" in mathematic either) > > I think the "bin model" is more complex because you don't just have a > > name and an object but always that indirection of the "bin". > > I cheerfully disagree. :) ?"Named bins" is essentially how algebra > works, and how several generations of computer languages, not to > mention the actual machine language those generated, behaved, before > the current crop. ?Those interpretations came first, because, much as > in the evolution of any other science, that was the model which was > most intuitive or easily explained. No, it is neither the most intuitive nor easily explained, but indeed it is the simplest to implement as humans at that time have limited capability to design chips. In the early days, ease of use is not a priority, simplicity is. > But you need not take my word for it. ?Simply read the archives and > see for yourself how much confusion this has caused on this list. > [Please include the closely related behavior of parameter passing in > your search.] The first time I used python, I didn't have any idea how the object model works, and I don't have experience in similar programming concept nor was python my first language, yet I have no difficulty in understanding why things goes like it is. For me, at least, python's object model is intuitive (do you remember about the limb?). From gandalf at shopzeus.com Thu Jan 15 03:33:43 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 09:33:43 +0100 Subject: Slow Queue.queue? (was: slow network) Message-ID: <496EF4E7.5040804@shopzeus.com> I had this test program originally that sent message over TCP/IP. Messages where buffered two a Queue.Queue instances, one for incoming and one for outgoing. #1. endpoint.send_message(msg) -> endpoint.outgoing.put(msg) #2. endpoint._process_outgoing() is a thread, that does: endpoint.write_into_socket( endpoint.outgoing.get() ) On the other side: #1 endpoint._process_incoming() is a thread, that does endpoint.incoming.put( endpoint.read_from_socket() ) #2 endpoing.recv_messages() -> return endpoint.incoming.get() This could do 130 message pairs/sec on Linux (on 127.0.0.1) and only 20 message pairs /sec on Windows XP. If do not start the _process_outgoing() thread, and do not use the outgoing queue: #1. endpoint.send_message(msg) -> endpoint.write_into_socket(msg) then the speed goes up to 64 messages/sec on windows and 500 messages/sec on Linux. This has nothing to do with TCP/IP. The only change is that I'm not using a queue, and not using +1 thread. How can this slow down my program? Is it a problem with Queue.Queue, or with the +1 thread? Thanks, Laszlo From prologic at shortcircuit.net.au Thu Jan 15 04:03:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 19:03:30 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: On Thu, Jan 15, 2009 at 5:05 PM, Russ P. wrote: (...) > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming > is written in smoke? Did anyone say that ? OO concepts are a much studied concept. However -you- still miss the basic point. OO programming -is- a model not a paradigm. Functional Programming -is- a paradigm. > Just for the record, I really don't care much about the definition of > OO programming. I brought it up only because someone tried to claim > that "enforced" encapsulation is a terrible idea. Well, as far as I > can tell, the majority of OO "programmers" (and software engineers, > software architects, etc.) seem to think otherwise. Maybe they are > wrong -- but I seriously doubt it. Ever thought that perhaps you might be the one that's wrong ? Not that it really matters, but I am a Software Engineer myself. > As I said before, enforced encapsulation may not be appropriate for > every application, but it is definitely appropriate for some. Not > every door needs a lock, but certainly some do. Your analogy is terrible. We are talking about machines that execute instructions in a sequence. At the most basic level do you really think a machine really cares about whether -you- the programmer has illegally accessed something you shouldn't have ? --JamesMills From deets at nospam.web.de Thu Jan 15 04:08:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 15 Jan 2009 10:08:37 +0100 Subject: General direction In-Reply-To: References: Message-ID: <6t8comF9ou5uU1@mid.uni-berlin.de> MLT schrieb: > Hello all: I'm a beginner to Python (and programming altogether), and > am now looking to create a program of my own. What I've got in mind > is a very basic pest control program that would keep track of 1) trap > findings and 2) pesticides. My thought is to make each of these > classes. Looking at the general outline written below, can anyone > give general impression about whether I'm somewhat going in the right > direction or if I need to approach it entirely differently? Thanks > for any suggestions or help! Familiarize yourself with PEP8 for naming and coding-conventions first. > Class Insect_Trapping attributes: > - Unique Name > - Location > - Type Depending on what the Type is, you might consider using subclassing here instead. > - Frequency of Checks? > - Next Check Date > > Within Insect_Trapping there are Trap_Count objects > > Trap_Count objects have the following attributes: > - Date > - Time > - Insect A Finds > - Insect B Finds > - Insect C Finds > - Insect A Number > - Insect B Number > - Insect C Number Instead of manually coding attributes for all kinds of insects, better use a mapping of insect-name to attributes. There are plenty of options for that - you could a mapping of name to tuple: { "cockroach" : (100, 200), "wasp" : (2000, 3000) } Or introduce a InsectInfo-class that has finds and numbers as fields: { "bee" : InsectInfo(finds=100, number=200) } > Class Pesticides attributes: > - Unique Name > - Usage Instructions > > Within Pesticide there are Pesticide_Usage objects > > Pesticide_Usage objects have the following attributes: > - Date > - Time > - Location > - Reason for Use > - Amt Used HTH, Diez From gandalf at shopzeus.com Thu Jan 15 04:22:06 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 10:22:06 +0100 Subject: Slow Queue.queue? (was: slow network) In-Reply-To: <496EF4E7.5040804@shopzeus.com> References: <496EF4E7.5040804@shopzeus.com> Message-ID: <496F003E.7010800@shopzeus.com> > > then the speed goes up to 64 messages/sec on windows and 500 > messages/sec on Linux. Finally I could reach 1500 messages/sec without using the queue. If I comment out one line (use the queue instead of direct write into socket) then speed decreases to 40-60 messages/sec. I don't understand why the slow version is slower by a factor of 40? Fast version: def send_message(self,sender,recipient,msgtype,body,timeout=3600): self.write_str(self.serializer.serialize([sender,recipient,msgtype,body])) Slow version: def send_message(self,sender,recipient,msgtype,body,timeout=3600): self.outgoing.put(self.serializer.serialize([ sender,recipient,msgtype,body ]),1,timeout) plus this method, executed in a different thread: def _process_outgoing(self): try: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): try: data = self.outgoing.get(1,1) data_ok = True break except Queue.Empty: pass if data_ok: self.write_str(data) except Exception, e: if self.router: if not isinstance(e,TransportClosedError): self.router.logger.error(dumpexc(e)) self.router.unregister_endpoint(self) self.shutdown() raise SystemExit(0) From duncan.booth at invalid.invalid Thu Jan 15 04:35:42 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Jan 2009 09:35:42 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Terry Reedy wrote: > Lambert, David W (S&T) wrote: >> Overly terse. I do mean that this is illegal: >> >> isinstance(s, {str, bytes}) >> >> tuples have order, immutability, and the possibility of repeat items. >> >> A set is most reasonable in a mathematical sense. > > I agree. However, isinstance predates set. Hence the status quo. > > There is another reason which nobody has mentioned, and which might make it tricky to do a good implementation that does accept sets. The second argument to isinstance or issubclass is a classinfo where a classinfo is either a class or a tuple of classinfo. This makes it easy to group related types: you can just combine existing groups of types together without having to flatten tuples. The immutability of tuples guarantees that you cannot create a recursive structure this way. If you allow sets then the code which traverses the classinfo has to protect itself against the possibility of an infinite recursion. The same argument also applies to exception handlers which also accept a type or a tuple of things they accept. Of course you could allow either an existing classinfo or a set of types, but not allow the set to contain anything other than types. That would still prevent recursion but means you have to be stricter about knowing what you are combining. That probably wouldn't be a bad thing if everyone used sets consistently but I suspect would be messy if introduced at this stage. -- Duncan Booth http://kupuguy.blogspot.com From gandalf at shopzeus.com Thu Jan 15 04:36:57 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 10:36:57 +0100 Subject: process/thread instances and attributes In-Reply-To: References: Message-ID: <496F03B9.8090100@shopzeus.com> > Hey all, > > I have this concept I'm working on and here is > the code... Problem is if you run this it doesn't > terminate. I believe you can terminate it in the > main process by calling a.stop() But I can't find a > way for it to self terminate, ie: self.stop() As indicated > by the code... > I'm not sure what you wanted to do here, but it is for sure that your "running" variable is not shared between the processes. Use this instead: from multiprocessing import Value self.running = Value('i',0) Then these: self.running.value = 1 self.running.value = 0 if self.running.value: But I'm affraid your example won't work. Considering your stop() method: def stop(self): print "%s: Stopping ..." % self self.running.value = 0 It would set running.value to zero. However, at that time there will be other processes running their start() method and setting the same shared value to 1. What do you want to try with this example? L From lipun4u at gmail.com Thu Jan 15 05:28:29 2009 From: lipun4u at gmail.com (asit) Date: Thu, 15 Jan 2009 02:28:29 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <4b967ea2-61e3-49b9-a898-278bf4640757@p36g2000prp.googlegroups.com> On Jan 15, 11:47?am, "James Mills" wrote: > On Thu, Jan 15, 2009 at 4:34 PM, asit wrote: > > I recently faced a peculiar o/p. > > > My objective is to remove the command name(my script name) from > > sys.argv[0]. > > I coded like this > > If you _really_ want to remove your script_name from > sys.argv, then do this: > > del sys.argv[0] > > If you're just after what the name of your script is > that's being run (for human readability) try the > following function (taken from pymills): > > def getProgName(): > ? ?"""getProgName() -> str > > ? ?Return the name of the current program being run > ? ?by working it out from the script's basename. > ? ?""" > > ? ?return os.path.basename(sys.argv[0]) > > -------------------------------------------------- > > cheers > James Thank you everyone From see.signature at no.spam Thu Jan 15 05:30:00 2009 From: see.signature at no.spam (Eric Brunel) Date: Thu, 15 Jan 2009 11:30:00 +0100 Subject: Possible bug in Tkinter - Python 2.6 Message-ID: Hi all, I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is the script: ----------------------------- from Tkinter import * from tkMessageBox import * from tkFileDialog import * root = Tk() def ask_file(): file_name = askopenfilename() print file_name def ask_confirm(): answer = askyesno() print answer Button(root, text='Ask file', command=ask_file).pack() Button(root, text='Ask confirm', command=ask_confirm).pack() root.mainloop() ----------------------------- Scenario: - Run the script. - Click the 'Ask confirm' button and answer 'Yes'; it should print True, which is the expected answer. - Click the 'Ask file' button, select any file and confirm. - Click the 'Ask confirm' button and answer 'Yes'. At the last step, the script prints 'False' for me, which is quite wrong. Can anybody confirm this? I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, it seems to work correctly on Windows 2000. I could only test with Python 2.6, and not 2.6.1. But I didn't see any mention of this problem in the release notes. And BTW, if this is actually a bug, where can I report it? TIA -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From prologic at shortcircuit.net.au Thu Jan 15 05:35:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 15 Jan 2009 20:35:03 +1000 Subject: process/thread instances and attributes In-Reply-To: <496F03B9.8090100@shopzeus.com> References: <496F03B9.8090100@shopzeus.com> Message-ID: On Thu, Jan 15, 2009 at 7:36 PM, Laszlo Nagy wrote: (...) Value won't do obviously :) As there could be an arbitary no. of processes. > What do you want to try with this example? I guess I just am confused as to what belongs to which process (the main or the child) ... I need a clear cut example or documetnation of what's what ... cheers James From jstroud at mbi.ucla.edu Thu Jan 15 05:35:34 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 15 Jan 2009 02:35:34 -0800 Subject: General direction In-Reply-To: References: Message-ID: MLT wrote: > Hello all: I'm a beginner to Python (and programming altogether), and > am now looking to create a program of my own. What I've got in mind > is a very basic pest control program that would keep track of 1) trap > findings and 2) pesticides. My thought is to make each of these > classes. Looking at the general outline written below, can anyone > give general impression about whether I'm somewhat going in the right > direction or if I need to approach it entirely differently? Thanks > for any suggestions or help! [data structures snipped] Programs generally *do* something. Here you have described data structures, which just sit there being full of data. They aren't very active and hence are not terribly interesting. Here are some bullet points for your consideration: 1. What will your program do? 2. Understand databases (http://tinyurl.com/6flhbz) before you start. 3. Consider PySQlite (http://trac.edgewall.org/wiki/PySqlite) before you think about a heavyweight database backend (once you realize that you will want a database for this project). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From bieffe62 at gmail.com Thu Jan 15 05:44:56 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Thu, 15 Jan 2009 02:44:56 -0800 (PST) Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> On 15 Gen, 11:30, "Eric Brunel" wrote: > Hi all, > > I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is ? > the script: > > ----------------------------- > ?from Tkinter import * > ?from tkMessageBox import * > ?from tkFileDialog import * > > root = Tk() > > def ask_file(): > ? ?file_name = askopenfilename() > ? ?print file_name > > def ask_confirm(): > ? ?answer = askyesno() > ? ?print answer > > Button(root, text='Ask file', command=ask_file).pack() > Button(root, text='Ask confirm', command=ask_confirm).pack() > > root.mainloop() > ----------------------------- > > Scenario: > - Run the script. > - Click the 'Ask confirm' button and answer 'Yes'; it should print True, ? > which is the expected answer. > - Click the 'Ask file' button, select any file and confirm. > - Click the 'Ask confirm' button and answer 'Yes'. > > At the last step, the script prints 'False' for me, which is quite wrong. ? > Can anybody confirm this? > > I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise ? > Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, it ? > seems to work correctly on Windows 2000. I could only test with Python ? > 2.6, and not 2.6.1. But I didn't see any mention of this problem in the ? > release notes. > > And BTW, if this is actually a bug, where can I report it? > > TIA > -- > python -c "print ''.join([chr(154 - ord(c)) for c in ? > 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" It works here (no bug), python 2.6.1 on Windows XP. If it is a bag, maybe it is platform-specific ... Ciao ---- FB From bieffe62 at gmail.com Thu Jan 15 06:14:26 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Thu, 15 Jan 2009 03:14:26 -0800 (PST) Subject: Slow Queue.queue? (was: slow network) References: <496EF4E7.5040804@shopzeus.com> Message-ID: <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> On 15 Gen, 10:22, Laszlo Nagy wrote: > > then the speed goes up to 64 messages/sec on windows and 500 > > messages/sec on Linux. > > Finally I could reach 1500 messages/sec without using the queue. If I > comment out one line (use the queue instead of direct write into socket) > then speed decreases to 40-60 messages/sec. I don't understand why the > slow version is slower by a factor of 40? > > Fast version: > > ? ? def send_message(self,sender,recipient,msgtype,body,timeout=3600): > > self.write_str(self.serializer.serialize([sender,recipient,msgtype,body])) > > Slow version: > > ? ? def send_message(self,sender,recipient,msgtype,body,timeout=3600): > ? ? ? ? self.outgoing.put(self.serializer.serialize([ > ? ? ? ? ? ? sender,recipient,msgtype,body > ? ? ? ? ]),1,timeout) > > plus this method, executed in a different thread: > > ? ? def _process_outgoing(self): > ? ? ? ? try: > ? ? ? ? ? ? while not self.stop_requested.isSet(): > ? ? ? ? ? ? ? ? data_ok = False > ? ? ? ? ? ? ? ? while not self.stop_requested.isSet(): > ? ? ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? ? ? data = self.outgoing.get(1,1) > ? ? ? ? ? ? ? ? ? ? ? ? data_ok = True > ? ? ? ? ? ? ? ? ? ? ? ? break > ? ? ? ? ? ? ? ? ? ? except Queue.Empty: > ? ? ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? ? ? ? ? if data_ok: > ? ? ? ? ? ? ? ? ? ? self.write_str(data) > ? ? ? ? except Exception, e: > ? ? ? ? ? ? if self.router: > ? ? ? ? ? ? ? ? if not isinstance(e,TransportClosedError): > ? ? ? ? ? ? ? ? ? ? self.router.logger.error(dumpexc(e)) > ? ? ? ? ? ? ? ? self.router.unregister_endpoint(self) > ? ? ? ? ? ? self.shutdown() > ? ? ? ? ? ? raise SystemExit(0) I would try something like this inside _process_outgoing: while not self.stop_requested.isSet(): data_ok = False while not self.stop_requested.isSet(): if not self.outgoing.empty(): try: data = self.outgoing.get(True,0.1) data_ok = True break except Queue.Empty: pass else: time.sleep(0.1) # maybe, if the thread usess too much CPU The hypotesis I made for this suggestion are: - if the queue is found empty, the queue.get could keep the global interpreter lock until a message arrive (blocking also the thread that put the message in the queue) - if the queue is found empty, the handling of the exception can slows down the execution Not sure they are good guesses, because at the rate of your messages the queue should be almost always full, and most probably the implementation of Queue.get is smarted than myself :-). ANyway, it is worth a try ... Also, is you are using fixed-length queues (the ones that make the sender wait if the queue is full), try to increase the queue size, or to use an infinite-size queue. HTH Ciao ---- FB From sjmachin at lexicon.net Thu Jan 15 06:18:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 03:18:21 -0800 (PST) Subject: List/Set/Dict.. References: Message-ID: <6c1a21f3-5f01-4fcc-83cf-2b1045e5288d@q30g2000prq.googlegroups.com> On Jan 14, 1:53?pm, "bruce" wrote: > Hi... > > i have the test dict/list > ?a= {"a": 'a1',"b" : "b1"} > ?b= [{"a": 'a1',"b" : "b1"}] > > i'm trying to figure out how to programtically tell them apart... > > ie, which is a dict, and which is a list... >>> a = {"a": 'a1', "b": "b1"} >>> b = [{"a": 'a1', "b": "b1"}] >>> isinstance(a, list) False >>> isinstance(b, list) True >>> isinstance(a, dict) True >>> isinstance(b, dict) False >>> type(a) >>> type(b) >>> From mario.ruggier at gmail.com Thu Jan 15 06:29:59 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 03:29:59 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? Message-ID: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Hello, I would like to evaluate list comprehension expressions, from within which I'd like to call a function. For a first level it works fine but for second level it seems to lose the "_[1]" variable it uses internally to accumulate the results. Some sample code is: class GetItemEvaluator(object): def __init__(self): self.globals = globals() # some dict (never changes) self.globals["ts"] = self.ts self.globals["join"] = "".join self.locals = {} # changes on each evaluation def __getitem__(self, expr): return eval(expr, self.globals, self.locals) def ts(self, ts, name, value): self.locals[name] = value #print ts, name, value, "::::", self.locals, "::::", ts % self return ts % self gie = GetItemEvaluator() gie.locals["inner"] = ("a","b","c","d") print """ pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate (inner)]))s post """ % gie # OK, outputs: pre 0.a 1.b 2.c 3.d post gie = GetItemEvaluator() gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] print """ pre %(join([ts( '''inner pre %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate (inner)]))s inner post''', "inner", inner) # END CALL outer ts() for i,inner in enumerate(outer)]) )s post """ % gie The second 2-level comprehension gives: File "scratch/eval_test.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 4, in NameError: name '_[1]' is not defined If the print was to be enable, the last line printed out is: 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p i.e. it has correctly processed the first inner sequence, until the (last) "p" element. But on exit of the last inner ts() call, it seems to lose the '_[1]' on self.locals. Any ideas why? Note, i'd like that the first parameter to ts() is as independent as possible from teh context in expression context, a sort of independent mini-template. Thus, the i,j enumerate counters would normally not be subbed *within* the comprehension itself, but in a similar way to how k is evaluated, within the call to ts() -- I added them this way here to help follow easier what the execution trail is. Anyhow, within that mini-template, i'd like to embed other expressions for the % operator, and that may of course also be list comprehensions. Thanks! From gandalf at shopzeus.com Thu Jan 15 07:08:18 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 15 Jan 2009 13:08:18 +0100 Subject: Slow Queue.queue? (was: slow network) In-Reply-To: <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> References: <496EF4E7.5040804@shopzeus.com> <7266ee3f-72ad-489b-b3e7-7a791bc60121@a26g2000prf.googlegroups.com> Message-ID: <496F2732.8040904@shopzeus.com> > I would try something like this inside _process_outgoing: > > while not self.stop_requested.isSet(): > data_ok = False > while not self.stop_requested.isSet(): > if not self.outgoing.empty(): > try: > data = self.outgoing.get(True,0.1) > data_ok = True > break > except Queue.Empty: > pass > else: > time.sleep(0.1) # maybe, if the thread usess too much CPU > I tried your modifications. The result is 9 messages/sec. I guess it is because time.sleep(0.1) - if that is called after each message, at most 10 message/sec is possible. > The hypotesis I made for this suggestion are: > > - if the queue is found empty, the queue.get could keep the global > interpreter lock until a message arrive > (blocking also the thread that put the message in the queue) > I hope it is not that way. Consider two threads running intensive calculations. Both of them are running python code -> both of them must hold the GIL. Python runs the process on one processor, and GIL must be released on any thread that is not active on the CPU, regardless of what it is doing. > - if the queue is found empty, the handling of the exception can slows > down the execution > Because of the timeout specified in my outgoing queue get() call, the exception can only happen once per second. It won't slow down anything. > Not sure they are good guesses, because at the rate of your messages > the queue should be almost always full, > and most probably the implementation of Queue.get is smarted than > myself :-). ANyway, it is worth a try ... > The problem is with sending one message, and getting one answer for it. Most of the time, the queue is empty or has only one message inside it. > Also, is you are using fixed-length queues (the ones that make the > sender wait if the queue is full), try to increase > the queue size, or to use an infinite-size queue. > Queue size was 1000 in this example, but it never contains more than two messages. From bearophileHUGS at lycos.com Thu Jan 15 07:45:02 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 04:45:02 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> Message-ID: <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> Raymond Hettinger: > Thought you guys might enjoy this: > ? ?http://code.activestate.com/recipes/576615/ Nice and short, but it's also very slow on my PC (Psyco may help). This solves them in moments: http://labix.org/python-constraint Bye, bearophile From bearophileHUGS at lycos.com Thu Jan 15 07:48:23 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 04:48:23 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <1fadad81-e130-4fb3-a567-0d2ec18d3dad@s9g2000prg.googlegroups.com> mario ruggier, that's a hack that you can forget. Your code can't be read. Don't use list comps for that purpose. Write code that can be read. Bye, bearophile From mario.ruggier at gmail.com Thu Jan 15 07:52:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 04:52:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <89fdffe8-96db-4bde-a1a0-b3dc6753909d@k1g2000prb.googlegroups.com> On Jan 15, 12:29?pm, mario ruggier wrote: > Any ideas why? > > Note, i'd like that the first parameter to ts() is as independent as > possible from the context in expression context, a sort of independent > mini-template. Thus, the i,j enumerate counters would normally not be > subbed *within* the comprehension itself, but in a similar way to how > k is evaluated, within the call to ts() -- I added them this way here > to help follow easier what the execution trail is. Anyhow, within that > mini-template, i'd like to embed other expressions for the % operator, > and that may of course also be list comprehensions. OK, here's the same sample code somewhat simplified and maybe be easier to follow what may be going on: class GetItemEvaluator(object): def __init__(self): self.globals = globals() # some dict (never changes) self.globals["ts"] = self.ts self.globals["join"] = " ".join self.locals = {} # changes on each evaluation def __getitem__(self, expr): return eval(expr, self.globals, self.locals) def ts(self, ts): print "ts:", ts, "::::", self.locals return ts % self # one level gie = GetItemEvaluator() gie.locals["inner"] = ("a","b","c","d") TS1 = """ pre %(join([ ts('%(j)s.%(k)s') for j,k in enumerate(inner)]))s post """ OUT1 = TS1 % gie print "Output 1:", OUT1 # two level gie = GetItemEvaluator() gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] TS2 = """ leading %(join([ ts( ''' pre %(join([ ts('%(i)s.%(j)s.%(k)s') for j,k in enumerate(inner)]))s post ''' # identical to TS1, except for additional '%(s)s.' ) for i,inner in enumerate(outer)]) )s trailing """ OUT2 = TS2 % gie print "Output 2:", OUT2 As the gie.locals dict is being automagically updated from within the list comprehension expression, I simplified the previous call to ts(). Thus, executing this with the prints enabled as shown will produce the following output: $ python2.6 scratch/eval_test_4.py ts: %(j)s.%(k)s :::: {'_[1]': [], 'k': 'a', 'j': 0, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a'], 'k': 'b', 'j': 1, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a', '1.b'], 'k': 'c', 'j': 2, 'inner': ('a', 'b', 'c', 'd')} ts: %(j)s.%(k)s :::: {'_[1]': ['0.a', '1.b', '2.c'], 'k': 'd', 'j': 3, 'inner': ('a', 'b', 'c', 'd')} Output 1: pre 0.a 1.b 2.c 3.d post ts: pre %(join([ ts('%(i)s.%(j)s.%(k)s') for j,k in enumerate(inner)]))s post :::: {'_[1]': [], 'i': 0, 'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'm', 'j': 0, '_[1]': [], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'n', 'j': 1, '_[1]': ['0.0.m'], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'o', 'j': 2, '_[1]': ['0.0.m', '0.1.n'], 'inner': ('m', 'n', 'o', 'p')} ts: %(i)s.%(j)s.%(k)s :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m', '0.1.n', '0.2.o'], 'inner': ('m', 'n', 'o', 'p')} Traceback (most recent call last): File "scratch/eval_test.py", line 40, in OUT2 = TS2 % gie File "scratch/eval_test_4.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 9, in NameError: name '_[1]' is not defined Anyone can help clarify what may be going on? m. From mario.ruggier at gmail.com Thu Jan 15 07:58:01 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 04:58:01 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <1fadad81-e130-4fb3-a567-0d2ec18d3dad@s9g2000prg.googlegroups.com> Message-ID: <6561ba8b-8c45-4912-8146-91c718a2369a@p2g2000prf.googlegroups.com> On Jan 15, 1:48?pm, bearophileH... at lycos.com wrote: > mario ruggier, that's a hack that you can forget. Your code can't be > read. Don't use list comps for that purpose. Write code that can be > read. Ya, agree with you whole-heartily, but then so are most optimizations ;-) It is just an idea I am exploring, and that code would be never be humanly written (that's why it seems more convoluted than necessary). I hope the simplified boiled down sample gets the intention out better... i'd still would like to understand why the '_ [1]' variable is disappearing after first inner loop! > Bye, > bearophile From __peter__ at web.de Thu Jan 15 08:02:54 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 14:02:54 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: mario ruggier wrote: > Hello, > > I would like to evaluate list comprehension expressions, from within > which I'd like to call a function. For a first level it works fine but > for second level it seems to lose the "_[1]" variable it uses > internally to accumulate the results. Some sample code is: > > class GetItemEvaluator(object): > def __init__(self): > self.globals = globals() # some dict (never changes) > self.globals["ts"] = self.ts > self.globals["join"] = "".join > self.locals = {} # changes on each evaluation > def __getitem__(self, expr): > return eval(expr, self.globals, self.locals) > def ts(self, ts, name, value): > self.locals[name] = value > #print ts, name, value, "::::", self.locals, "::::", ts % self > return ts % self > > gie = GetItemEvaluator() > gie.locals["inner"] = ("a","b","c","d") > print """ > pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate > (inner)]))s post > """ % gie > # OK, outputs: pre 0.a 1.b 2.c 3.d post > > gie = GetItemEvaluator() > gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] > print """ > pre %(join([ts( > '''inner pre > %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate > (inner)]))s > inner post''', > "inner", inner) # END CALL outer ts() > for i,inner in enumerate(outer)]) > )s post > """ % gie > > The second 2-level comprehension gives: > > File "scratch/eval_test.py", line 8, in __getitem__ > return eval(expr, self.globals, self.locals) > File "", line 4, in > NameError: name '_[1]' is not defined > > If the print was to be enable, the last line printed out is: > > 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', > 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o > '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p > > i.e. it has correctly processed the first inner sequence, until the > (last) "p" element. But on exit of the last inner ts() call, it seems > to lose the '_[1]' on self.locals. > > Any ideas why? > > Note, i'd like that the first parameter to ts() is as independent as > possible from teh context in expression context, a sort of independent > mini-template. Thus, the i,j enumerate counters would normally not be > subbed *within* the comprehension itself, but in a similar way to how > k is evaluated, within the call to ts() -- I added them this way here > to help follow easier what the execution trail is. Anyhow, within that > mini-template, i'd like to embed other expressions for the % operator, > and that may of course also be list comprehensions. I have no idea what you are trying to do. Please reread the Zen of Python ;) What happens is: List comprehensions delete the helper variable after completion: >>> def f(): [i for i in [1]] ... >>> dis.dis(f) 1 0 BUILD_LIST 0 3 DUP_TOP 4 STORE_FAST 0 (_[1]) 7 LOAD_CONST 1 (1) 10 BUILD_LIST 1 13 GET_ITER >> 14 FOR_ITER 13 (to 30) 17 STORE_FAST 1 (i) 20 LOAD_FAST 0 (_[1]) 23 LOAD_FAST 1 (i) 26 LIST_APPEND 27 JUMP_ABSOLUTE 14 >> 30 DELETE_FAST 0 (_[1]) 33 POP_TOP 34 LOAD_CONST 0 (None) 37 RETURN_VALUE If you manage to run two nested listcomps in the same namespace you get a name clash and the inner helper variable overwrites/deletes the outer: >>> def xeval(x): return eval(x, ns) ... >>> ns = dict(xeval=xeval) >>> xeval("[xeval('[k for k in ()]') for i in (1,)]") Traceback (most recent call last): File "", line 1, in File "", line 1, in xeval File "", line 1, in NameError: name '_[1]' is not defined Peter From __peter__ at web.de Thu Jan 15 08:19:10 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 14:19:10 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Peter Otten wrote: > mario ruggier wrote: > >> Hello, >> >> I would like to evaluate list comprehension expressions, from within >> which I'd like to call a function. For a first level it works fine but >> for second level it seems to lose the "_[1]" variable it uses >> internally to accumulate the results. Some sample code is: >> >> class GetItemEvaluator(object): >> def __init__(self): >> self.globals = globals() # some dict (never changes) >> self.globals["ts"] = self.ts >> self.globals["join"] = "".join >> self.locals = {} # changes on each evaluation >> def __getitem__(self, expr): >> return eval(expr, self.globals, self.locals) >> def ts(self, ts, name, value): >> self.locals[name] = value >> #print ts, name, value, "::::", self.locals, "::::", ts % self >> return ts % self >> >> gie = GetItemEvaluator() >> gie.locals["inner"] = ("a","b","c","d") >> print """ >> pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate >> (inner)]))s post >> """ % gie >> # OK, outputs: pre 0.a 1.b 2.c 3.d post >> >> gie = GetItemEvaluator() >> gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] >> print """ >> pre %(join([ts( >> '''inner pre >> %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate >> (inner)]))s >> inner post''', >> "inner", inner) # END CALL outer ts() >> for i,inner in enumerate(outer)]) >> )s post >> """ % gie >> >> The second 2-level comprehension gives: >> >> File "scratch/eval_test.py", line 8, in __getitem__ >> return eval(expr, self.globals, self.locals) >> File "", line 4, in >> NameError: name '_[1]' is not defined >> >> If the print was to be enable, the last line printed out is: >> >> 0.3.%(k)s k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', >> 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o >> '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p >> >> i.e. it has correctly processed the first inner sequence, until the >> (last) "p" element. But on exit of the last inner ts() call, it seems >> to lose the '_[1]' on self.locals. >> >> Any ideas why? >> >> Note, i'd like that the first parameter to ts() is as independent as >> possible from teh context in expression context, a sort of independent >> mini-template. Thus, the i,j enumerate counters would normally not be >> subbed *within* the comprehension itself, but in a similar way to how >> k is evaluated, within the call to ts() -- I added them this way here >> to help follow easier what the execution trail is. Anyhow, within that >> mini-template, i'd like to embed other expressions for the % operator, >> and that may of course also be list comprehensions. > > I have no idea what you are trying to do. Please reread the Zen of Python > ;) > > What happens is: > > List comprehensions delete the helper variable after completion: > >>>> def f(): [i for i in [1]] > ... >>>> dis.dis(f) > 1 0 BUILD_LIST 0 > 3 DUP_TOP > 4 STORE_FAST 0 (_[1]) > 7 LOAD_CONST 1 (1) > 10 BUILD_LIST 1 > 13 GET_ITER > >> 14 FOR_ITER 13 (to 30) > 17 STORE_FAST 1 (i) > 20 LOAD_FAST 0 (_[1]) > 23 LOAD_FAST 1 (i) > 26 LIST_APPEND > 27 JUMP_ABSOLUTE 14 > >> 30 DELETE_FAST 0 (_[1]) > 33 POP_TOP > 34 LOAD_CONST 0 (None) > 37 RETURN_VALUE > > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > >>>> def xeval(x): return eval(x, ns) > ... >>>> ns = dict(xeval=xeval) >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in xeval > File "", line 1, in > NameError: name '_[1]' is not defined > > Peter > I'd like to add: this can only happen because the code snippets are compiled independently. Otherwise Python uses different names for each listcomp: >>> def f(): ... [i for i in ()] ... [i for i in ()] ... >>> f.func_code.co_varnames ('_[1]', 'i', '_[2]') Peter From mario.ruggier at gmail.com Thu Jan 15 08:22:26 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 05:22:26 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <0d850f42-5560-4d76-929c-0f700c10c866@v5g2000prm.googlegroups.com> On Jan 15, 2:02?pm, Peter Otten <__pete... at web.de> wrote: > mario ruggier wrote: > > Hello, > > > I would like to evaluate list comprehension expressions, from within > > which I'd like to call a function. For a first level it works fine but > > for second level it seems to lose the "_[1]" variable it uses > > internally to accumulate the results. Some sample code is: > > > class GetItemEvaluator(object): > > ? ? def __init__(self): > > ? ? ? ? self.globals = globals() # some dict (never changes) > > ? ? ? ? self.globals["ts"] = self.ts > > ? ? ? ? self.globals["join"] = "".join > > ? ? ? ? self.locals = {} # changes on each evaluation > > ? ? def __getitem__(self, expr): > > ? ? ? ? return eval(expr, self.globals, self.locals) > > ? ? def ts(self, ts, name, value): > > ? ? ? ? self.locals[name] = value > > ? ? ? ? #print ts, name, value, "::::", self.locals, "::::", ts % self > > ? ? ? ? return ts % self > > > gie = GetItemEvaluator() > > gie.locals["inner"] = ("a","b","c","d") > > print """ > > pre %(join([ts("%s."%(j)+'%(k)s ', 'k', k) for j,k in enumerate > > (inner)]))s post > > """ % gie > > # OK, outputs: pre 0.a 1.b 2.c 3.d ?post > > > gie = GetItemEvaluator() > > gie.locals["outer"] = [ ("m","n","o","p"), ("q","r","s","t")] > > print """ > > pre %(join([ts( > > ? '''inner pre > > ? %(join([ts("%s.%s."%(i, j)+'%(k)s ', 'k', k) for j,k in enumerate > > (inner)]))s > > ? ?inner post''', > > ? "inner", inner) # END CALL outer ts() > > ? for i,inner in enumerate(outer)]) > > )s post > > """ % gie > > > The second 2-level comprehension gives: > > > ? File "scratch/eval_test.py", line 8, in __getitem__ > > ? ? return eval(expr, self.globals, self.locals) > > ? File "", line 4, in > > NameError: name '_[1]' is not defined > > > If the print was to be enable, the last line printed out is: > > > 0.3.%(k)s ?k p :::: {'outer': [('m', 'n', 'o', 'p'), ('q', 'r', 's', > > 't')], 'i': 0, 'k': 'p', 'j': 3, '_[1]': ['0.0.m ', '0.1.n ', '0.2.o > > '], 'inner': ('m', 'n', 'o', 'p')} :::: 0.3.p > > > i.e. it has correctly processed the first inner sequence, until the > > (last) "p" element. But on exit of the last inner ts() call, it seems > > to lose the '_[1]' on self.locals. > > > Any ideas why? > > > Note, i'd like that the first parameter to ts() is as independent as > > possible from teh context in expression context, a sort of independent > > mini-template. Thus, the i,j enumerate counters would normally not be > > subbed *within* the comprehension itself, but in a similar way to how > > k is evaluated, within the call to ts() -- I added them this way here > > to help follow easier what the execution trail is. Anyhow, within that > > mini-template, i'd like to embed other expressions for the % operator, > > and that may of course also be list comprehensions. > > I have no idea what you are trying to do. Please reread the Zen of Python ;) > > What happens is: > > List comprehensions delete the helper variable after completion: > > >>> def f(): [i for i in [1]] > ... > >>> dis.dis(f) > > ? 1 ? ? ? ? ? 0 BUILD_LIST ? ? ? ? ? ? ? 0 > ? ? ? ? ? ? ? 3 DUP_TOP > ? ? ? ? ? ? ? 4 STORE_FAST ? ? ? ? ? ? ? 0 (_[1]) > ? ? ? ? ? ? ? 7 LOAD_CONST ? ? ? ? ? ? ? 1 (1) > ? ? ? ? ? ? ?10 BUILD_LIST ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ?13 GET_ITER > ? ? ? ? >> ? 14 FOR_ITER ? ? ? ? ? ? ? ?13 (to 30) > ? ? ? ? ? ? ?17 STORE_FAST ? ? ? ? ? ? ? 1 (i) > ? ? ? ? ? ? ?20 LOAD_FAST ? ? ? ? ? ? ? ?0 (_[1]) > ? ? ? ? ? ? ?23 LOAD_FAST ? ? ? ? ? ? ? ?1 (i) > ? ? ? ? ? ? ?26 LIST_APPEND > ? ? ? ? ? ? ?27 JUMP_ABSOLUTE ? ? ? ? ? 14 > ? ? ? ? >> ? 30 DELETE_FAST ? ? ? ? ? ? ?0 (_[1]) > ? ? ? ? ? ? ?33 POP_TOP > ? ? ? ? ? ? ?34 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?37 RETURN_VALUE > > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > > >>> def xeval(x): return eval(x, ns) > ... > >>> ns = dict(xeval=xeval) > >>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 1, in xeval > ? File "", line 1, in > NameError: name '_[1]' is not defined > > Peter Ah, brilliant, thanks for the clarification! To verify if I understood you correctly, I have modified the ts() method above to: def ts(self, ts): _ns = self.locals self.locals = self.locals.copy() print "ts:", ts, "::::", self.locals try: return ts % self finally: self.locals = _ns And, it executes correctly, thus the 2nd output is: Output 2: leading pre 0.0.m 0.1.n 0.2.o 0.3.p post pre 1.0.q 1.1.r 1.2.s 1.3.t post trailing But, the need to do a copy() will likely kill any potential optimization gains... so, I will only be forced to rite more readable code ;-) Thanks! From google at mrabarnett.plus.com Thu Jan 15 08:56:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 13:56:57 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: <496F40A9.1040709@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical sense. > You could say the same about s.startswith(("a", "b")). It might be because sets are a more recent addition to the language; if they had been in Python from the start then maybe they would've been used instead. From kyrie at uh.cu Thu Jan 15 08:57:17 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Thu, 15 Jan 2009 08:57:17 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz5gvfs.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Message-ID: <1232027837.496f40bd5a3d3@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Luis Zarrabeitia writes: > > Wait, do you _really_ believe that _static_ checks could prevent problems > > arising from _unexpected_ conditions in the _data_? > > The data does not arrive from outer space on a magtape stapled to a > meteor. It comes out of another program. Most of the problems in > processing it come from mismatches between the processing programs and > the generation programs. Static checks would help eliminate those > mismatches. No, copy and paste from the original data structures would eliminate those mismatches. A compiler checking the reimplementation of said data structres, whatever the language, has no way of knowing if the structure matches. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From roy at panix.com Thu Jan 15 09:20:13 2009 From: roy at panix.com (Roy Smith) Date: Thu, 15 Jan 2009 09:20:13 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwscx6zfo.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > basically I think C is evil. C is not evil. It's a tool. Would you call a hammer evil because it's not very good at driving screws? C is a very good tool for doing the kind of thing it was designed for, which is highly efficient, low-level, portable programming. The fact that C has been used to write all sorts of large-scale applications doesn't mean that it's good at that kind of stuff. It just means that all the alternatives suck more than it does for that kind of stuff. If you want evil, look at C++. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:27:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:27:49 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> <7x3afl3v00.fsf@ruckus.brouhaha.com> Message-ID: <017f3e72$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 23:10:07 -0800, Paul Rubin wrote: > I think this sub-thread has been mostly about dynamically creating new > class instance attributes, but yes, at one point I did suggest adding > type checking (ML-like inference) to pylint, presumably with feedback to > the compiler for optimization purposes. I noted that Python 3.0 in fact > has some features to support annotations for the purpose of static type > checking, so it's not as far off the wall as it might sound. I fear anything that will lead Python moving towards C/Pascal/Java type declarations, but I feel great enthusiasm at the thought that maybe by the time we get to Python 4.0 there will be type inference which could enable compiler optimizations. Exciting times people, exciting times. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:31:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:31:45 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <017f3f5d$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 23:05:32 -0800, Russ P. wrote: > On Jan 14, 10:40?pm, "James Mills" wrote: >> On Thu, Jan 15, 2009 at 4:34 PM, Michele >> Simionato wrote: >> >> (...) >> >> > There are lots of Python developers (and most of the core developers) >> > that think the OO community is wrong about enforced encapsulation. >> > Personally, I think in a few years everybody will realize the mistake >> > of enforced encapsulation and that the OO definition in the Wikipedia >> > page will be changed. Even if not, Wikipedia definitions does not >> > matter much, everybody has his own idea of what OO means, and the >> > Python definition is good as any other. Don't get pissed off on >> > words. >> >> Amen! The first thing said right in this entire thread! (one of) >> >> --JamesMills > > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming is > written in smoke? Be fair -- James just admitted that everything he's written in this thread is wrong. If Michele's post was, and I quote James, "the first thing said right in this entire thread", then obviously everything James wrote previously was wrong. *wink* -- Steven From gaius.julius at gmail.com Thu Jan 15 09:44:41 2009 From: gaius.julius at gmail.com (gaius.julius) Date: Thu, 15 Jan 2009 06:44:41 -0800 (PST) Subject: multiprocessing BaseManager doesn't clean up net connections? References: Message-ID: <8a5989f3-1ffa-430b-8500-ad7aad4609da@35g2000pry.googlegroups.com> Hi, Having exactly the same problem. It appears even if I explicitly call manager's shutdown() method. Not sure it is a bug, though. But also didn't find anything in documentation or source code or debug output. On Jan 1, 8:01?am, Chris Brooks wrote: > Hi, > > I'm trying to use remote managers in the multiprocessing module to listen > for some events synchronously while my program goes off and does other > things. ?I use the .start() method which forks a new process to handle > communication. ?When I catch the sigint and call sys.exit() though, the > network port is still bound even after the python interpretor finishes. > Here is my short code and the output: > From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 09:54:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 14:54:15 GMT Subject: General direction References: <6t8comF9ou5uU1@mid.uni-berlin.de> Message-ID: <017f44a3$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > MLT schrieb: >> Hello all: I'm a beginner to Python (and programming altogether), and >> am now looking to create a program of my own. What I've got in mind is >> a very basic pest control program that would keep track of 1) trap >> findings and 2) pesticides. My thought is to make each of these >> classes. Looking at the general outline written below, can anyone give >> general impression about whether I'm somewhat going in the right >> direction or if I need to approach it entirely differently? Thanks for >> any suggestions or help! > > Familiarize yourself with PEP8 for naming and coding-conventions first. Or not. Enough of the PEP8-fascism please. It is not compulsory to follow PEP8 in order to be allowed to learn Python. If Guido wanted it compulsory, he'd have made the compiler enforce it. Besides, you're talking to a newbie. Chances are he doesn't even know what PEP8 is: the recommended style-guide for Python code. http://www.python.org/dev/peps/pep-0008/ Having said that, I will *suggest* to the Original Poster that you should follow PEP8 as much as possible. It will save you a lot of grief in the long run. But right now, it is more important to learn the language than to learn conventions for how to name classes. If you can do both, great, but don't let the naming conventions get in the way. -- Steve From mail at anjanesh.net Thu Jan 15 09:54:59 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 15 Jan 2009 20:24:59 +0530 Subject: Py3 - converting bytes to ascii Message-ID: <1a7951080901150654i7be7fa8dj873acb1ecbb102c3@mail.gmail.com> Using Python 3.0 res = urllib.request.urlopen(url) f = open('file.txt', 'wb') # Since res.read() returns bytes f.write(res.read()) But newline and return feeds are stored as b14, 58a as text in the text file. So how do I to convert res.read() to ascii on opening the file in ascii mode f = open('file.txt', 'w')? Thanks From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 10:06:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 15:06:41 GMT Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: <017f478e$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 03:29:59 -0800, mario ruggier wrote: > Hello, > > I would like to evaluate list comprehension expressions, from within > which I'd like to call a function. For a first level it works fine but > for second level it seems to lose the "_[1]" variable it uses internally > to accumulate the results. Some sample code is: > > class GetItemEvaluator(object): > def __init__(self): > self.globals = globals() # some dict (never changes) Would you like to put a small wager on that? >>> len(gie.globals) 64 >>> something_new = 0 >>> len(gie.globals) 65 > self.globals["ts"] = self.ts > self.globals["join"] = "".join > self.locals = {} # changes on each evaluation > def __getitem__(self, expr): > return eval(expr, self.globals, self.locals) Can you say "Great Big Security Hole"? >>> gie = GetItemEvaluator() >>> gie['__import__("os").system("ls")'] dicttest dumb.py rank.py sorting startup.py 0 http://cwe.mitre.org/data/definitions/95.html -- Steven From james.colin.brady at gmail.com Thu Jan 15 10:11:01 2009 From: james.colin.brady at gmail.com (James Brady) Date: Thu, 15 Jan 2009 07:11:01 -0800 (PST) Subject: Readline and Python 2.6.1 on a Mac Message-ID: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Hi, I just upgraded Python from 2.5.2 up to 2.6.1 on my 10.5 Mac (installed from the DMG here: http://www.python.org/download/releases/2.6.1/), and I'm having some problems with readline and rl_completer. I have PYTHONSTARTUP pointing to this file: #!/usr/bin/env python try: import readline except ImportError: print "Module readline not available." else: import rlcompleter readline.parse_and_bind("bind ^I rl_complete") Which was working fine for tab completion in 2.5. Now, however, I can't enter 'b' (lower case b) in interactive python shells - no character appears. Just b is broken - 'B' is fine, Ctrl-b is fine, Alt-b even prints an integration symbol, but 'b' - nothing! Has anyone seen this before? From rt8396 at gmail.com Thu Jan 15 10:28:36 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 07:28:36 -0800 (PST) Subject: Possible bug in Tkinter - Python 2.6 References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> Message-ID: <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> First of all be very careful using from "module" import * or you will have name conflicts. Tkinter is made to be imported this way and i do it all the time. for the others do. import tkMessageBox as MB import tkFileDialog as FD or whatever floats your boat. Secondly i hear all the time about problems with fedora distros, so that would explain the issue to me. From debski.jakub at wp.pl Thu Jan 15 10:41:53 2009 From: debski.jakub at wp.pl (Jakub Debski) Date: Thu, 15 Jan 2009 16:41:53 +0100 Subject: Executing global code Message-ID: Hi, Is it possible to execute global code (module-level code) more than once keeping the state of global variables? This means no reload() and no moving the code to a function. regards, Jakub From thomasmallen at gmail.com Thu Jan 15 10:46:30 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 07:46:30 -0800 (PST) Subject: Wx broken? Message-ID: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> I've tried a few of the examples from http://wiki.wxpython.org/Getting%20Started , but after "Hello World" (window) nothing works. I get the following error message with the other examples: Traceback (most recent call last): File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py", line 1, in import wx File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx \__init__.py", line 45, in from wx._core import * File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 6, in new_instancemethod = new.instancemethod AttributeError: 'module' object has no attribute 'instancemethod' Here's a snippet that generates this error: http://pastebin.com/m2b4f4f9c For those familiar with wx here, is this a bug in the library, or should I be providing "instancemethod" at some point? Seeing that it's an unhandled exception, I do expect the former. Thanks, Thomas From thomasmallen at gmail.com Thu Jan 15 10:52:05 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 07:52:05 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: <2a4fc5ac-b245-4bf0-88b3-d0c19bf1faeb@v39g2000pro.googlegroups.com> On Jan 15, 10:46?am, tmallen wrote: > I've tried a few of the examples fromhttp://wiki.wxpython.org/Getting%20Started > , but after "Hello World" (window) nothing works. I get the following > error message with the other examples: > > Traceback (most recent call last): > ? File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py", > line 1, in > ? ? import wx > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx > \__init__.py", line 45, in > ? ? from wx._core import * > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 6, in > ? ? new_instancemethod = new.instancemethod > AttributeError: 'module' object has no attribute 'instancemethod' > > Here's a snippet that generates this error:http://pastebin.com/m2b4f4f9c > > For those familiar with wx here, is this a bug in the library, or > should I be providing "instancemethod" at some point? Seeing that it's > an unhandled exception, I do expect the former. > > Thanks, > Thomas Looking a little closer, this is what's causing the bug: Wx: _core.py, lines 1-6: # This file was created automatically by SWIG 1.3.29. # Don't modify this file, modify the SWIG interface instead. import _core_ import new new_instancemethod = new.instancemethod On this Win32 box, the "new" module doesn't have the "instancemethod" attribute. What is new.instancemethod used for? "new_instancemethod," which should be assigned to the attr, does not show up again in this particular source file. Thanks, Thomas From Caseyweb at gmail.com Thu Jan 15 10:53:25 2009 From: Caseyweb at gmail.com (Casey) Date: Thu, 15 Jan 2009 07:53:25 -0800 (PST) Subject: Py3 - converting bytes to ascii References: Message-ID: On Jan 15, 9:54?am, "Anjanesh Lekshminarayanan" wrote: > Using Python 3.0 > > So how do I to convert res.read() to ascii on opening the file in > ascii mode f = open('file.txt', 'w')? > I think this is what you are looking for: res = urllib.request.urlopen(url) f = open('file.txt', 'w') f.write(res.read().decode('ascii')) From mario.ruggier at gmail.com Thu Jan 15 10:56:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 07:56:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 15, 4:06?pm, Steven D'Aprano wrote: Hi Steve! > > class GetItemEvaluator(object): > > ? ? def __init__(self): > > ? ? ? ? self.globals = globals() # some dict (never changes) Ya, this is just a boiled down sample, and for simplicity I set to to the real globals(), so of course it will change when that changes... but in the application this is a distinct dict, that is entirely managed by the application, and it never changes as a result of an *evaluation*. > Would you like to put a small wager on that? > > >>> len(gie.globals) > 64 > >>> something_new = 0 > >>> len(gie.globals) > > 65 > > ? ? ? ? self.globals["ts"] = self.ts > > ? ? ? ? self.globals["join"] = "".join > > ? ? ? ? self.locals = {} # changes on each evaluation > > ? ? def __getitem__(self, expr): > > ? ? ? ? return eval(expr, self.globals, self.locals) > > Can you say "Great Big Security Hole"? With about the same difficulty as "Rabbit-Proof Fence" ;-) Again, it is just a boiled down sample, for communication purposes. As I mentioned in another thread, the real application behind all this is one of the *few* secure templating systems around. Some info on its security is at: http://evoque.gizmojo.org/usage/restricted/ Tell you what, if you find a security hole there (via exposed template source on a Domain(restricted=True) setup) I'll offer you a nice dinner (including the beer!) somewhere, maybe at some py conference, but even remotely if that is not feasible... ;-) The upcoming 0.4 release will run on 2.4 thru to 3.0 -- you can have some fun with that one (the current 0.3 runs on 2.5 and 2.6). > -- > Steven Cheers, mario From pornbypost at gmail.com Thu Jan 15 10:56:16 2009 From: pornbypost at gmail.com (Mark Smith) Date: Thu, 15 Jan 2009 07:56:16 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 6, in > ? ? new_instancemethod = new.instancemethod > AttributeError: 'module' object has no attribute 'instancemethod' I'm guessing you either have a python file called 'new.py' in your working directory, or you have one in your pythonpath. --Mark From thomasmallen at gmail.com Thu Jan 15 11:00:55 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 08:00:55 -0800 (PST) Subject: Wx broken? References: <783a6f45-b93a-4a05-b52e-4b566aeb039d@w39g2000prb.googlegroups.com> Message-ID: On Jan 15, 10:56?am, Mark Smith wrote: > > ? File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > > line 6, in > > ? ? new_instancemethod = new.instancemethod > > AttributeError: 'module' object has no attribute 'instancemethod' > > I'm guessing you either have a python file called 'new.py' in your > working directory, or you have one in your pythonpath. > > --Mark That's correct. Thanks! Thomas From arve.knudsen at gmail.com Thu Jan 15 11:02:03 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Thu, 15 Jan 2009 08:02:03 -0800 (PST) Subject: Embedding Python and program path Message-ID: <8d0c09bb-26e3-4006-9f60-7a20e126a936@w1g2000prm.googlegroups.com> In my application embedding Python I want to have the standard Python module path, so I try to achieve this by setting the program path to that of the the interpreter. Even though I call Py_SetProgramName before Py_InitializeEx, however, Python thinks the program path (as returned by Py_GetProgramFullPath) is that of my embedding executable. I would love if someone could explain what is going wrong here, and eventually provide a better solution for inheriting the Python interpreter's standard module path. Test application demonstrating the problem. #include int main() { // Hardcoded for simplicity Py_SetProgramName("C:\\Python26\\python.exe"); Py_InitializeEx(0); printf("Program path: %s\n", Py_GetProgramFullPath()); Py_Finalize(); return 0; } Thanks, Arve Knudsen From mario.ruggier at gmail.com Thu Jan 15 11:09:53 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 08:09:53 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <88f780f2-64bb-4209-83ce-bb0fba130691@n33g2000pri.googlegroups.com> The listcomps exploration above was primarily an attempt (unsuccessful) to make this piece of code go a little faster: s = " text %(item)s text " acc = [] for value in iterator: some_dict["item"] = value acc.append(s % evaluator) "".join(acc) The item=value pair is essentially a loop variable, and the evaluator (something like the gie instance above) uses it via the updated some_dict. Is there any way to express the above as a list comp or so? Any ideas how it might be made to go faster? m. From thomas.steffen75 at googlemail.com Thu Jan 15 11:23:12 2009 From: thomas.steffen75 at googlemail.com (thomas.steffen75 at googlemail.com) Date: Thu, 15 Jan 2009 08:23:12 -0800 (PST) Subject: the name of a method Message-ID: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Hello, I have a Class: class myClass: def __init__(self): # do something print "name of class = " + self.__class__.__name__ def myMethod(self): # do something print "name of method = " + "myMethod" return ... I print the name of the class with self.__class__.__name__ in __init__. I want to print also in every method of myClass the name of the method. How can I get the name? I would not like to write e.g. "myMethod". Is there a variable like self.__class__.__name__ for this? Thanks for your hints, Thomas From deets at nospam.web.de Thu Jan 15 11:37:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 15 Jan 2009 17:37:16 +0100 Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Message-ID: <6t971sF9gm58U1@mid.uni-berlin.de> thomas.steffen75 at googlemail.com wrote: > Hello, > > I have a Class: > > class myClass: > def __init__(self): > # do something > print "name of class = " + self.__class__.__name__ > > def myMethod(self): > # do something > print "name of method = " + "myMethod" > return > > ... > > I print the name of the class with self.__class__.__name__ in > __init__. > I want to print also in every method of myClass the name of the > method. > How can I get the name? I would not like to write e.g. "myMethod". Is > there a variable like self.__class__.__name__ for this? > Thanks for your hints, Thomas This can be done by inspecting the stackframes. Look into the module inspect. This has also been discussed very often on this list, stackframe & inspect should be good searchterms. However, if what you are after is logging, you should take a look into the logging module. it has many advantages over simple print-statements, and amongst other things allows you to print out the enclosing callable name when invoked ala logger.debug("Some message.") I strongly recommend using that. And at least you can of course peek into the logging module's source to see how the extract that information. Diez From LambertDW at Corning.com Thu Jan 15 11:50:22 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Thu, 15 Jan 2009 11:50:22 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> I have use case, needn't be dynamic, and it's not hard to enclose set as tuple. But I also write (for example) __all__ = 'this that other'.split() string_list = 'evenOneWord'.split() instead of __all__ = 'this','that','imTiredOfMistypingCommasAndQuotes' if not isinstance(o,set_of_handled_types): raise TypeError('call blessed programmer, this cannot occur') if isinstance(o,set_of_handle_types-treat_differently): treat_thusly(o) elif isinstance(o,treat_differently): treat_differently(o) elif etc. From __peter__ at web.de Thu Jan 15 11:50:54 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jan 2009 17:50:54 +0100 Subject: Executing global code References: Message-ID: Jakub Debski wrote: > Is it possible to execute global code (module-level code) more than > once keeping the state of global variables? This means no reload() and > no moving the code to a function. You have a module containing e. g. these two statements x = 42 x += 1 and want to rerun it with the effect of x becoming 44? That is not possible because in Python x = 42 is a statement, too, and will thus be rerun. Peter From jason.scheirer at gmail.com Thu Jan 15 11:56:11 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Thu, 15 Jan 2009 08:56:11 -0800 (PST) Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> <6t971sF9gm58U1@mid.uni-berlin.de> Message-ID: <5e0e0841-ae66-4645-8ab6-50be94004e0b@a29g2000pra.googlegroups.com> On Jan 15, 8:37?am, "Diez B. Roggisch" wrote: > thomas.steffe... at googlemail.com wrote: > > Hello, > > > I have a Class: > > > class myClass: > > ? ? def __init__(self): > > ? ? ? ? # do something > > ? ? ? ? print "name of class = " + ?self.__class__.__name__ > > > ? ? def myMethod(self): > > ? ? ? ? # do something > > ? ? ? ? print "name of method = " + "myMethod" > > ? ? ? ? return > > > ? ? ... > > > I print the name of the class with self.__class__.__name__ in > > __init__. > > I want to print also in every method of myClass the name of the > > method. > > How can I get the name? I would not like to write e.g. "myMethod". Is > > there a variable like self.__class__.__name__ for this? > > Thanks for your hints, Thomas > > This can be done by inspecting the stackframes. Look into the module > inspect. This has also been discussed very often on this list, stackframe & > inspect should be good searchterms. > > However, if what you are after is logging, you should take a look into the > logging module. it has many advantages over simple print-statements, and > amongst other things allows you to print out the enclosing callable name > when invoked ala > > logger.debug("Some message.") > > I strongly recommend using that. And at least you can of course peek into > the logging module's source to see how the extract that information. > > Diez I agree, this should not be done. However, sometimes it's useful to see the parameter values: import inspect import logging import sys def log_fn(): logging.debug("%s%s" % ( sys._getframe().f_back.f_code.co_name, inspect.formatargvalues(*inspect.getargvalues(sys._getframe ().f_back)))) logging.getLogger().setLevel(0) def hello_there(x, y, z, *a): log_fn() return 1+x >>> hello_there(1, 'a', 'b', 5, 6, 7, 8, 9) DEBUG:root:hello_there(x=1, y='a', z='b', *a=(5, 6, 7, 8, 9)) It can be done, but usually you want to actually trace through with the debugger. From http Thu Jan 15 12:07:00 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:07:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> Message-ID: <7xk58wwlaj.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > No, copy and paste from the original data structures would eliminate those > mismatches. The whole point is that would be possible if Python had data structure definitions ("types") that were possible to copy and paste from some single location, instead of building up structures dynamically, adding fields on the fly in ways that have become obscure over the evolution of the code. From siona at chiark.greenend.org.uk Thu Jan 15 12:09:14 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 15 Jan 2009 17:09:14 +0000 (GMT) Subject: mimetypes oddity Message-ID: >>> ge = mimetypes.guess_extension >>> ge('image/jpeg') '.jpe' >>> ge('image/jpeg') '.jpeg' >>> I actually discovered this through explicitly calling mimetypes.init to reload an edited mime.types file between calls to guess_extension, but I think the above scenario makes for more disturbing reading 8-) The problem is that mimetools initialises its type mapping dict before adding new type mappings from a file by iterating through the existing type mapping dict. This process is bootstrapped by a hard- coded dict which gets shadowed by the first file read, so the second file read uses a dict initialsed from the dict created by the first file read (got that?) which has a different iteration order to the hard-coded dict. So the mappings get added in a different order the second time around, and where there are multiple mappings like this you get a different answer. Is this a bug? If I want to be sure of a consistent result, do I need to use sorted(mimetools.guess_all_extensions(t))[0] (or [-1])? -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From ifl2009 at shu.edu Thu Jan 15 12:09:43 2009 From: ifl2009 at shu.edu (IFL 2009) Date: Thu, 15 Jan 2009 12:09:43 -0500 Subject: IFL 2009: Call for Papers Message-ID: Call for Papers IFL 2009 Seton Hall University SOUTH ORANGE, NJ, USA http://tltc.shu.edu/blogs/projects/IFL2009/ The 21st IFL symposium, IFL 2009, will be held for the first time in the USA. The hosting institution is Seton Hall University in South Orange, NJ, USA and the symposium dates are September 23-25, 2009. It is our goal to make IFL a regular event held in the USA. The goal of the IFL symposia is to bring together researchers actively engaged in the implementation and application of functional and function-based programming languages. IFL 2009 will be a venue for researchers to present and discuss new ideas and concepts, work in progress, and publication-ripe results related to the implementation and application of functional languages and function-based programming. Following the IFL tradition, IFL 2009 will use a post-symposium review process to produce a formal proceedings which we expect to be published by Springer in the Lecture Notes in Computer Science series. All participants in IFL 2009 are invited to submit either a draft paper or and extended abstract describing work to be presented at the symposium. These submissions will be screened by the program committee chair to make sure they are within the scope of IFL and will appear in the draft proceedings distributed at the symposium. Submissions appearing in the draft proceedings are not peer-reviewed publications. After the symposium, authors will be given the opportunity to incorporate the feedback from discussions at the symposium and will be invited to submit a revised full arcticle for the formal review process. These revised submissions will be reviewed by the program committee using prevailing academic standards to select the best articles that will appear in the formal proceedings. TOPICS IFL welcomes submissions describing practical and theoretical as well as submissions describing applications and tools. If you are not sure if your work is appropriate for IFL 2009, please contact the PC chair at ifl2009 at shu.edu. Topics of interest include, but are not limited to: language concepts type checking contracts compilation techniques staged compilation runtime function specialization runtime code generation partial evaluation (abstract) interpretation generic programming techniques automatic program generation array processing concurrent/parallel programming concurrent/parallel program execution functional programming and embedded systems functional programming and web applications functional programming and security novel memory management techniques runtime profiling and performance measurements debugging and tracing virtual/abstract machine architectures validation and verification of functional programs tools and programming techniques PAPER SUBMISSIONS Prospective authors are encouraged to submit papers or extended abstracts to be published in the draft proceedings and to present them at the symposium. All contributions must be written in English, conform to the Springer-Verlag LNCS series format and not exceed 16 pages. The draft proceedings will appear as a technical report of the Department of Mathematics and Computer Science of Seton Hall University. IMPORTANT DATES Registration deadline August 15, 2009 Presentation submission deadline August 15, 2009 IFL 2009 Symposium September 23-25, 2009 Submission for review process deadline November 1, 2009 Notification Accept/Reject December 22, 2009 Camera ready version January 15, 2010 PROGRAM COMMITTEE Peter Achten University of Nijmegen, The Netherlands Jost Berthold Philipps-Universit?t Marburg, Germany Andrew Butterfield University of Dublin, Ireland Robby Findler Northwestern University, USA Kathleen Fisher AT&T Research, USA Cormac Flanagan University of California at Santa Cruz, USA Matthew Flatt University of Utah, USA Matthew Fluet Toyota Technological Institute at Chicago, USA Daniel Friedman Indiana University, USA Andy Gill University of Kansas, USA Clemens Grelck University of Amsterdam/Hertfordshire, The Netherlands/UK Jurriaan Hage Utrecht University, The Netherlands Ralf Hinze Oxford University, UK Paul Hudak Yale University, USA John Hughes Chalmers University of Technology, Sweden Patricia Johann University of Strathclyde, UK Yukiyoshi Kameyama University of Tsukuba, Japan Marco T. Moraz?n (Chair) Seton Hall University, USA Rex Page University of Oklahoma, USA Fernando Rubio Universidad Complutense de Madrid, Spain Sven-Bodo Scholz University of Hertfordshire, UK Manuel Serrano INRIA Sophia-Antipolis, France Chung-chieh Shan Rutgers University, USA David Walker Princeton University, USA Vikt?ria Zs?k E?tv?s Lor?nd University, Hungary PETER LANDIN PRIZE The Peter Landin Prize is awarded to the best paper presented at the symposium every year. The honored article is selected by the program committee based on the submissions received for the formal review process. The prize carries a cash award equivalent to 150 euros. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Thu Jan 15 12:11:41 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 15 Jan 2009 12:11:41 -0500 Subject: Standard IPC for Python? References: <496CC069.80909@shopzeus.com> <1D523D62-6650-478A-A435-7BE545439F0E@semanchuk.com> <496CD1F6.3080604@shopzeus.com> Message-ID: Mel wrote: > Philip Semanchuk wrote: > >> I'm working on message queue support, but the Sys V IPC API is a >> headache and takes longer to code against than the POSIX API. > > I hadn't found it that bad. I have a C extension I should perhaps clean > up and make public. I have a simple wrapper around the msgget/msgsnd/msgrcv functions that ought to be downloadable through . GPL3. I'm studying Philip Semanchuk's semaphore and shared memory code. Let me know what you think. Mel. From http Thu Jan 15 12:13:41 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:13:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjkwkze.fsf@ruckus.brouhaha.com> Roy Smith writes: > C is not evil. It's a tool. Would you call a hammer evil because it's not > very good at driving screws? I would call a hammer evil if it were built in a way that made it unnecessarily likely to hit your thumb. > C is a very good tool for doing the kind of thing it was designed > for, which is highly efficient, low-level, portable programming. > The fact that C has been used to write all sorts of large-scale > applications doesn't mean that it's good at that kind of stuff. It just > means that all the alternatives suck more than it does for that kind of > stuff. I don't think so: http://www.adaic.org/whyada/ada-vs-c/cada_art.html From siona at chiark.greenend.org.uk Thu Jan 15 12:17:03 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 15 Jan 2009 17:17:03 +0000 (GMT) Subject: point class help References: <420839f5-1640-49d0-bf74-2d156af78350@p2g2000prn.googlegroups.com> Message-ID: r wrote: >here is what i have, it would seem stupid to use a conditional in each >method like this... > >def method(self, other): > if isinstance(other, Point2d): > x, y = origin.x, origin.y > else: > x, y = origin[0], origin[1] > #modify self.x & self.y with x&y Here's another alternative (I'd've gone with the subclassing tuple if writing this from scratch): class Point2d(object): ... def __getitem__(self, i): if not 0 <= i <= 1: raise IndexError return getattr(self, ['x', 'y'][i]) def method(self, other): x, y = other[0], other[1] ... -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From girishmsampath at gmail.com Thu Jan 15 12:20:29 2009 From: girishmsampath at gmail.com (Sam) Date: Thu, 15 Jan 2009 09:20:29 -0800 (PST) Subject: No Module Named MySQLdb Error Message-ID: <18f72c79-67a3-4a7a-aba4-de80ec2af073@r37g2000prr.googlegroups.com> Hi Friends, This is Sam, a learner of Python programming language. I would like to know a feasible and flexible process of importing MySQLdb module. If anyone know about this and have an expertise over this can help me over this issue. 1) I installed interface MySQLdb 1.2.2 in my MAC OS X system. In that i installed Python 2.6 version along with that i installed MySQL database. 2) So to run an application using these i am using the above interface. I went to read me file in that and went thro the process. 3) In that they asked to run the setup.py file and setup_posix.py file. I am unable to get the exact solution to the error, as i am novice in python. I am pasting here that error, so if anyone can help me over that u are welcome. Sampath:MySQL-python-1.2.2 venkatarampey$ python setup.py Traceback (most recent call last): File "setup.py", line 12, in from setup_posix import get_config File "/Users/venkatarampey/Downloads/MySQL-python-1.2.2/ setup_posix.py", line 89 return metadata, ext_options SyntaxError: 'return' outside function What is the solution for this error? Is anyone aware of using MySQL with python can fix this issue. Hope so i will meet a person in helping my task. Regards, Sampath Girish.M From google at mrabarnett.plus.com Thu Jan 15 12:26:45 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 17:26:45 +0000 Subject: Python 3 isinstance In-Reply-To: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> References: <84B204FFB016BA4984227335D8257FBA7B9FC4@CVCV0XI05.na.corning.com> Message-ID: <496F71D5.4020101@mrabarnett.plus.com> Lambert, David W (S&T) wrote: > I have use case, needn't be dynamic, and it's not hard to enclose set as > tuple. But I also write (for example) > > __all__ = 'this that other'.split() > string_list = 'evenOneWord'.split() > > instead of > > __all__ = 'this','that','imTiredOfMistypingCommasAndQuotes' > > > if not isinstance(o,set_of_handled_types): > raise TypeError('call blessed programmer, this cannot occur') > if isinstance(o,set_of_handle_types-treat_differently): > treat_thusly(o) > elif isinstance(o,treat_differently): > treat_differently(o) > elif etc. > You could write a Python source processor like 2to3.py which would replace 'this that other'.split() with ['this', 'that', 'other']. In fact, you could even write abbreviations such as /this that other/ and then use the script to expand them! From LambertDW at Corning.com Thu Jan 15 12:28:27 2009 From: LambertDW at Corning.com (Lambert, David W (S&T)) Date: Thu, 15 Jan 2009 12:28:27 -0500 Subject: Python 3 isinstance Message-ID: <84B204FFB016BA4984227335D8257FBA7BA011@CVCV0XI05.na.corning.com> Although isinstance predates sets, the python history I recall is that allowing tuples as second argument to isinstance happened at about the same time as set type was builtin. From rt8396 at gmail.com Thu Jan 15 12:29:42 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:29:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> Message-ID: <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> On Jan 14, 1:16?pm, Paul Rubin wrote: > "Russ P." writes: [snip] > I have a situation which I face almost every day, where I have some > gigabytes of data that I want to slice and dice somehow and get some > numbers out of. ?I spend 15 minutes writing a one-off Python program > and then several hours waiting for it to run. ?If I used C instead, > I'd spend several hours writing the one-off program and then 15 > minutes waiting for it to run, which is not exactly better. ? [snip] > I would be ecstatic with a version of Python where I might have to > spend 20 minutes instead of 15 minutes writing the program, but then > it runs in half an hour instead of several hours and doesn't crash. ?I > think the Python community should be aiming towards this. You and Everybody -- would be "ecstatic" if this could happen. But first someone has to design such a complex implementation. You want everything, but there is a trade-off. You said you wrote this program in 15 min. How much testing did you actually do on this data before running it? If you told me you spent more than 15 minutes i would not believe you. Look, Python is not a compiled language -- and for good reason -- so for now you need to do more initial testing if you plan to run a "15 min hack script" on a multi-GB data source file, and then throw a temper-tantrum when the damn thing blows chunks! If Python could give the benefits of compiled languages whilst being interpreted(without taking the "fun" out of Python), that would be wonderful, but can you implement such a system? Can anybody at this point? If you can, i can assure you will be worshiped as a God. From rt8396 at gmail.com Thu Jan 15 12:40:07 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:40:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> Message-ID: <77e18004-c388-47ec-b6ea-14de05026e14@z6g2000pre.googlegroups.com> On Jan 15, 11:13?am, Paul Rubin wrote: > Roy Smith writes: > > C is not evil. ?It's a tool. ?Would you call a hammer evil because it's not > > very good at driving screws? ? > > I would call a hammer evil if it were built in a way that made it > unnecessarily likely to hit your thumb. > > > C is a very good tool for doing the kind of thing it was designed > > for, which is highly efficient, low-level, portable programming. > > The fact that C has been used to write all sorts of large-scale > > applications doesn't mean that it's good at that kind of stuff. ?It just > > means that all the alternatives suck more than it does for that kind of > > stuff. > > I don't think so: ?http://www.adaic.org/whyada/ada-vs-c/cada_art.html Hammers are not evil, they have no logic, interpreters and compilers are not evil either -- you and i control there every move. The hammer will go exactly where you guide it to -- if that happens to be you thumb...?? Python does exactly what it's told, if you tell Python to smash your thumb, Python will gladly comply :) From rt8396 at gmail.com Thu Jan 15 12:43:17 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:43:17 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> <77e18004-c388-47ec-b6ea-14de05026e14@z6g2000pre.googlegroups.com> Message-ID: <05b802b8-7fe6-47c3-a959-58df83d2b48c@r41g2000prr.googlegroups.com> Heres a little food for thought, Maybe you did tell Python to hit the nail head, but your calculations of the direction vector were slightly off. Instead of a direct hit, the hammer grazed the head and now the resultant vector aims strait for your thumb -- Who's to blame here? From http Thu Jan 15 12:43:32 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:43:32 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> Message-ID: <7xwscwh3cr.fsf@ruckus.brouhaha.com> r writes: > You said you wrote this program in 15 min. How much testing did you > actually do on this data before running it? If you told me you spent > more than 15 minutes i would not believe you. I would say hours, in the sense that the program ran correctly for that long, processing several GB's of data before hitting something obscure that it couldn't handle. This is not a single incident, it's something that happens all the time; write the program, run it til it crashes, fix what made it crash, run some more, etc. In some cases where the program is a background process listening to external events, it runs for weeks before hitting something it can't handle. To be fair, that kind of thing is notoriously difficult to make airtight in real world systems, which is why Erlang uses a "let it crash" philosophy that emphasizes recovery from failures rather than trying to avoid them at all costs. But, at least in the stuff I'm hacking, I think a lot of these errors could be avoided with more automated ways to check for type consistency. From rt8396 at gmail.com Thu Jan 15 12:47:57 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 09:47:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> Message-ID: <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> Paul Rubin > I would say hours, in the sense that the program ran correctly for > that long, processing several GB's of data before hitting something > obscure that it couldn't handle. ?This is not a single incident, it's So what was the fatal error, care to post a traceback? From http Thu Jan 15 12:59:01 2009 From: http (Paul Rubin) Date: 15 Jan 2009 09:59:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> Message-ID: <7xocy8v4be.fsf@ruckus.brouhaha.com> r writes: > So what was the fatal error, care to post a traceback? Usually it's "expected to find some value but got None", or got a list, or expected some structure but got a different one, or some field was missing, etc. It's not a single traceback, it's a recurring theme in developing this stuff. From jaomatos at gmail.com Thu Jan 15 13:09:00 2009 From: jaomatos at gmail.com (=?iso-8859-1?q?Jos=E9_Matos?=) Date: Thu, 15 Jan 2009 18:09:00 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> Message-ID: <200901151809.00786.jaomatos@gmail.com> On Thursday 15 January 2009 15:28:36 r wrote: > First of all be very careful using from "module" import * or you will > have name conflicts. Tkinter is made to be imported this way and i do > it all the time. for the others do. > > import tkMessageBox as MB > import tkFileDialog as FD > or whatever floats your boat. Importing explicitly works for me in Fedora 11 (rawhide): ----------------------------- from Tkinter import * from tkMessageBox import askyesno from tkFileDialog import askopenfilename root = Tk() def ask_file(): file_name = askopenfilename() print file_name def ask_confirm(): answer = askyesno() print answer Button(root, text='Ask file', command=ask_file).pack() Button(root, text='Ask confirm', command=ask_confirm).pack() root.mainloop() ----------------------------- > Secondly i hear all the time about problems with fedora distros, so > that would explain the issue to me. That seems a long jump in the reasoning since OP reported the same behavior in Suse and Solaris. -- Jos? Ab?lio From rt8396 at gmail.com Thu Jan 15 13:15:40 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 10:15:40 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> On Jan 15, 11:59?am, Paul Rubin wrote: > r writes: > > So what was the fatal error, care to post a traceback? > > Usually it's "expected to find some value but got None", or got a > list, or expected some structure but got a different one, or some > field was missing, etc. ?It's not a single traceback, it's a recurring > theme in developing this stuff. ? Sounds like the results of poor testing and lack of design good program logic From skip at pobox.com Thu Jan 15 13:21:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 15 Jan 2009 12:21:12 -0600 Subject: mimetypes oddity In-Reply-To: References: Message-ID: <18799.32408.318726.110143@montanaro.dyndns.org> [mimetype weirdness reported] Sion> Is this a bug? Might be. Can you file a bug report in the Python issue tracker with a small script that demonstrates the behavior? -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From mccredie at gmail.com Thu Jan 15 13:22:29 2009 From: mccredie at gmail.com (Matimus) Date: Thu, 15 Jan 2009 10:22:29 -0800 (PST) Subject: the name of a method References: <734ffc63-dc3a-43bd-9b17-21cd217a05de@u18g2000pro.googlegroups.com> Message-ID: On Jan 15, 8:23?am, thomas.steffe... at googlemail.com wrote: > Hello, > > I have a Class: > > class myClass: > ? ? def __init__(self): > ? ? ? ? # do something > ? ? ? ? print "name of class = " + ?self.__class__.__name__ > > ? ? def myMethod(self): > ? ? ? ? # do something > ? ? ? ? print "name of method = " + "myMethod" > ? ? ? ? return > > ? ? ... > > I print the name of the class with self.__class__.__name__ in > __init__. > I want to print also in every method of myClass the name of the > method. > How can I get the name? I would not like to write e.g. "myMethod". Is > there a variable like self.__class__.__name__ for this? > Thanks for your hints, Thomas I would just use a decorator: >>> def print_method_name(meth): ... def new_meth(*args, **kwargs): ... print meth.func_name ... return meth(*args, **kwargs) ... return new_meth ... >>> class MyClass(object): ... @print_method_name ... def my_method(self): ... pass ... >>> x = MyClass() >>> x.my_method() my_method Matt From http Thu Jan 15 13:25:11 2009 From: http (Paul Rubin) Date: 15 Jan 2009 10:25:11 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> Message-ID: <7xbpu8l94o.fsf@ruckus.brouhaha.com> r writes: > Sounds like the results of poor testing and lack of design good > program logic It would sure be nice if the language made it easier, not harder. From cma at mail.bnu.edu.cn Thu Jan 15 13:28:35 2009 From: cma at mail.bnu.edu.cn (Cong Ma) Date: Fri, 16 Jan 2009 02:28:35 +0800 Subject: Injecting a global into a defined function?? Message-ID: Hi, I'd appreciate your hints on this problem. I'm writing a module in which several functions can alter the value of a global variable (I know this sounds evil, please forgive me...). What I'm trying to do is to eliminate the "global foo" lines in those functions' bodies and to use a decorator for the same task. For example: @global_injected("SPAM") def foo(): ... ... will have the same effect as def foo(): global SPAM ... ... Leaving the evilness of globals aside, I wonder how I can implement this (for Python 2.x). I'd like to hear your opinions. Thank you. Regards, Cong. From zac256 at gmail.com Thu Jan 15 13:30:18 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 15 Jan 2009 10:30:18 -0800 Subject: Executing global code In-Reply-To: References: Message-ID: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> I'm not sure I fully understand the question "no moving the code to a function", but you can prevent reload in a module by doing something like this: doLoad = False try: no_reload except NameError: no_reload = True else: raise RuntimeError, "This module is not meant to be reloaded." -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 8:50 AM, Peter Otten <__peter__ at web.de> wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e. g. these two statements > > x = 42 > x += 1 > > and want to rerun it with the effect of x becoming 44? That is not possible > because in Python > > x = 42 > > is a statement, too, and will thus be rerun. > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > From martin.hellwig at dcuktec.org Thu Jan 15 13:30:18 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 15 Jan 2009 18:30:18 +0000 Subject: Python Crashes In-Reply-To: References: Message-ID: <496f80bb$0$196$e4fe514c@news.xs4all.nl> koranthala wrote: This does sounds more to me like a windows/hardware problem, what you could do is check the windows log for errors, especially look for read errors from the hard disk. Windows sometimes can behave very strangely especially if the external libs don't behave well on a multi process machine or when the execution prevention gets in the way. Both problems can be worked around though (setting a uniprocessor flag at the binary, adding an exception for the execution prevention) but should not be done without proper reason. Good luck. -- mph From zac256 at gmail.com Thu Jan 15 13:30:56 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 15 Jan 2009 10:30:56 -0800 Subject: Executing global code In-Reply-To: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> References: <333edbe80901151030m39e8eb17t95a211d18b09f10a@mail.gmail.com> Message-ID: <333edbe80901151030t8065b44w941545966a7cc30f@mail.gmail.com> The first line: doLoad = False, is to be ignored. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 10:30 AM, Zac Burns wrote: > I'm not sure I fully understand the question "no moving the code to a > function", but you can prevent reload in a module by doing something > like this: > > doLoad = False > try: > no_reload > except NameError: > no_reload = True > else: > raise RuntimeError, "This module is not meant to be reloaded." > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > > > > On Thu, Jan 15, 2009 at 8:50 AM, Peter Otten <__peter__ at web.de> wrote: >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> >> You have a module containing e. g. these two statements >> >> x = 42 >> x += 1 >> >> and want to rerun it with the effect of x becoming 44? That is not possible >> because in Python >> >> x = 42 >> >> is a statement, too, and will thus be rerun. >> >> Peter >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From google at mrabarnett.plus.com Thu Jan 15 13:43:31 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 18:43:31 +0000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: <496F83D3.2080900@mrabarnett.plus.com> Cong Ma wrote: > Hi, > > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. For > example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... > > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). I'd like to hear your opinions. Thank you. > I doubt that's possible because 'global' is syntax. From pavlovevidence at gmail.com Thu Jan 15 13:47:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jan 2009 10:47:05 -0800 (PST) Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> On Jan 15, 3:35?am, Duncan Booth wrote: > Terry Reedy wrote: > > Lambert, David W (S&T) wrote: > >> Overly terse. ?I do mean that this is illegal: > > >> isinstance(s, {str, bytes}) > > >> tuples have order, immutability, and the possibility of repeat items. > > >> A set is most reasonable in a mathematical sense. > > > I agree. ?However, isinstance predates set. ?Hence the status quo. > > There is another reason which nobody has mentioned, and which might make it > tricky to do a good implementation that does accept sets. > > The second argument to isinstance or issubclass is a classinfo where a > classinfo is either a class or a tuple of classinfo. This makes it easy to > group related types: you can just combine existing groups of types together > without having to flatten tuples. The immutability of tuples guarantees > that you cannot create a recursive structure this way. > > If you allow sets then the code which traverses the classinfo has to > protect itself against the possibility of an infinite recursion. > > The same argument also applies to exception handlers which also accept a > type or a tuple of things they accept. > > Of course you could allow either an existing classinfo or a set of types, > but not allow the set to contain anything other than types. That would > still prevent recursion but means you have to be stricter about knowing > what you are combining. That probably wouldn't be a bad thing if everyone > used sets consistently but I suspect would be messy if introduced at this > stage. I don't see what the big deal is. Right now isinstance accepts a type or a tuple of types. The code could be changed to allow a type, or any iterable the returns types (wherein every items of the sequence is required to be a type). What's messy about that? Carl Banks From python at rcn.com Thu Jan 15 13:49:49 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 15 Jan 2009 10:49:49 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> Message-ID: <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> > > Thought you guys might enjoy this: > > ? ?http://code.activestate.com/recipes/576615/ > > Nice and short, but it's also very slow on my PC (Psyco may help). > > This solves them in moments:http://labix.org/python-constraint Intelligent search beats brute force permutation search. The constraint solver is pretty nice. The recipe is mainly about how to use itertools.permutations() for simple programs that take minutes to write and get the job done. Raymond From nad at acm.org Thu Jan 15 13:49:50 2009 From: nad at acm.org (Ned Deily) Date: Thu, 15 Jan 2009 10:49:50 -0800 Subject: Readline and Python 2.6.1 on a Mac References: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Message-ID: In article <4632a161-ed13-477c-a40a-2b606fda1c27 at a29g2000pra.googlegroups.com>, James Brady wrote: > Hi, I just upgraded Python from 2.5.2 up to 2.6.1 on my 10.5 Mac > (installed from the DMG here: http://www.python.org/download/releases/2.6.1/), > and I'm having some problems with readline and rl_completer. > > I have PYTHONSTARTUP pointing to this file: > #!/usr/bin/env python > > try: > import readline > except ImportError: > print "Module readline not available." > else: > import rlcompleter > readline.parse_and_bind("bind ^I rl_complete") > > Which was working fine for tab completion in 2.5. Now, however, I > can't enter 'b' (lower case b) in interactive python shells - no > character appears. Your startup file was set up for a Python (likely the Apple-supplied 2.5) that was built using the BSD editline library for readline. But the 2.6 python.org python was built with GNU readline which uses a different syntax. s/"bind ^I rl_complete"/"tab: complete"/ -- Ned Deily, nad at acm.org From duncan.booth at invalid.invalid Thu Jan 15 14:08:03 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Jan 2009 19:08:03 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> Message-ID: Carl Banks wrote: > I don't see what the big deal is. Right now isinstance accepts a type > or a tuple of types. The code could be changed to allow a type, or > any iterable the returns types (wherein every items of the sequence is > required to be a type). What's messy about that? No, it isn't restricted to a type or a tuple of types: right now isinstance accepts X where X is a type or a tuple of X. The definition is recursive, and the data structure can be deeply nested, but (because tuples are immutable) it cannot be infinite. e.g. >>> isinstance('x', (((((int, (float, str)),),),),)) True If you change the code so that it only allows iterables one level deep then existing code may break. If you change it to allow mutable nested values then the interpreter has to avoid getting stuck in an infinite loop. From rt8396 at gmail.com Thu Jan 15 14:15:13 2009 From: rt8396 at gmail.com (r) Date: Thu, 15 Jan 2009 11:15:13 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <047206b6-86b0-4967-b8ca-0705bbc4a0e7@i18g2000prf.googlegroups.com> <7xbpu8l94o.fsf@ruckus.brouhaha.com> Message-ID: <6db4b8a4-e6ca-4ab8-9132-18bfdd74a3e5@z28g2000prd.googlegroups.com> On Jan 15, 12:25?pm, Paul Rubin wrote: > r writes: > > Sounds like the results of poor testing and lack of design good > > program logic > > It would sure be nice if the language made it easier, not harder. I am for anything that makes debugging easier, as long as that "thing" doesn't take away the freedom i enjoy while writing Python code. If you can give me both then i will support your efforts -- The world does not need two Javas! Python's existence resides in a unique niche, Simplistic-Elegant- Programming-Bliss. Python promotes self reliance, you don't get the safety net you do with other languages. You must consider all the consciences/possible side-effects of your code. If you are going to use Python to design enormous systems(or operate on enormous data sources) -- at this point --, then you will need to do some enormous testing. From tjreedy at udel.edu Thu Jan 15 14:39:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 14:39:30 -0500 Subject: 2to3 Help? In-Reply-To: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> References: <424cb140-9776-4abf-ac21-875b93f13dea@p2g2000prn.googlegroups.com> Message-ID: marco.m.petersen at gmail.com wrote: > I have Python 3.0. I tried to use the 2to3 program included with the > interpreter to convert some scripts for Python 2.5 to Python 3.0 ones. I believe 2to3 is will work 'best' with files modified to use some new 2.6 features (backported from 3.0) where 'best' means 'Runs with 2.6 and then with 3.0 after 2to3 conversion without hand editing'. If you want to do a one-time conversion, then 2.5 to 3.0 is fine. From tjreedy at udel.edu Thu Jan 15 14:47:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 14:47:29 -0500 Subject: Python 3 isinstance In-Reply-To: References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> Message-ID: Duncan Booth wrote: > Terry Reedy wrote: > >> Lambert, David W (S&T) wrote: >>> Overly terse. I do mean that this is illegal: >>> >>> isinstance(s, {str, bytes}) >>> >>> tuples have order, immutability, and the possibility of repeat items. >>> >>> A set is most reasonable in a mathematical sense. >> I agree. However, isinstance predates set. Hence the status quo. >> >> > > There is another reason which nobody has mentioned, and which might make it > tricky to do a good implementation that does accept sets. > > The second argument to isinstance or issubclass is a classinfo where a > classinfo is either a class or a tuple of classinfo. This makes it easy to > group related types: you can just combine existing groups of types together > without having to flatten tuples. The immutability of tuples guarantees > that you cannot create a recursive structure this way. > > If you allow sets then the code which traverses the classinfo has to > protect itself against the possibility of an infinite recursion. > > The same argument also applies to exception handlers which also accept a > type or a tuple of things they accept. > > Of course you could allow either an existing classinfo or a set of types, > but not allow the set to contain anything other than types. That would > still prevent recursion but means you have to be stricter about knowing > what you are combining. That probably wouldn't be a bad thing if everyone > used sets consistently but I suspect would be messy if introduced at this > stage. Nice explanation. A mathematical set is a frozen set of course (except that mathematical sets can also be recursive! -- depending on the particular set theory), and there is no literal syntax for that. From bearophileHUGS at lycos.com Thu Jan 15 14:51:42 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 11:51:42 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: Raymond Hettinger: > for simple programs that take minutes to write and get the job done. For fun here's a specific example: from csp import Problem, timing print "SEND+MORE=MONEY problem:" p = Problem("recursivebacktracking") p.addvars("sendmory", range(10)) p.addrule(lambda d,e,y: (d+e)%10 == y) # alternative syntax p.addrule("(n*10+d+r*10+e)%100 == e*10+y") p.addrule("(e*100+n*10+d+o*100+r*10+e)%1000 == n*100+e*10+y") p.addrule("1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e == 10000*m+1000*o +100*n+10*e+y") p.notin([0], "sm") p.alldifferent() solutions, time = timing(p.solutions) print "Computing time:", time, "s" for s in solutions: print "%(s)d%(e)d%(n)d%(d)d + %(m)d%(o)d%(r)d%(e)d = %(m)d%(o)d%(n) d%(e)d%(y)d" % s print Probably it's not too much difficult to write a code able to solve a more general alphametric problem: you can write it more or less like yours, but it leads to a single equation, that is slow to solve. To give the solver engine a chance to speed up the computation you have to split the single equation into many equations. This allows the solver to prune that large search space in a faster way (the search space may have 3+ millions items so it's not huge anyway). Bye, bearophile From atleta.hu at gmail.com Thu Jan 15 14:51:52 2009 From: atleta.hu at gmail.com (atleta) Date: Thu, 15 Jan 2009 11:51:52 -0800 (PST) Subject: Parallel package hierarchies/directories Message-ID: <70cbe817-9eda-4346-93b6-5c38d8d63389@n33g2000pri.googlegroups.com> Hi, I'd need a logical way to organize my unit tests into packages, but I don't know how to do it in python. I'd like to separate my test sources (modules) from the code. The problem is that it seems that python does not allow a package to spread through multiple directories. I'd like to have the following layout (which is the usual way we do it e.g. in java): +-project_root/ | +-src/ | | | +-soap | +-test/ | +-soap 'soap' is a package under the source tree. I.e. I'd like my test source tree to mirror the source tree and have package specific tests in the same package as the code they excersize. However I found that this is not possible, at least not the way I wanted, not without moving files. I tried to place a script that would run all tests under the 'test' directory. It added 'src' to the sys.path, but then it was only able to import packages from test/soap and not src/soap. Is there a way I can have python look for soap package modules in both places? If not, then could someone tell me what is the usual way to layout test code? Thanks, atleta From bdesth.quelquechose at free.quelquepart.fr Thu Jan 15 14:54:49 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 15 Jan 2009 20:54:49 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xsknl6z5b.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <7x3afm2y4s.fsf@ruckus.brouhaha.com> <7xpriqtkqi.fsf@ruckus.brouhaha.com> <496e1c1b$0$24829$426a74cc@news.free.fr> <7x4p01pzj5.fsf@ruckus.brouhaha.com> <496e4e2e$0$10088$426a34cc@news.free.fr> <7xsknl6z5b.fsf@ruckus.brouhaha.com> Message-ID: <496fa232$0$7878$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> We're not talking about libraries here. >> Yes we are. If the default is "non-dynamic", then a class author is in >> charge of explicitely allowing it when *he* see fits. > > Oh, I see what you mean, the standard libraries would be affected if > the language default were to tone down the dynamism. True. Not only the standard lib. Quite a lot of frameworks relies on these features. >> As long as it's up to the *user* to choose, that's ok. Your "@dynamic" >> class decorator doesn't have the same implications. > > Well, you could use it on library classes too: > > from library import Libclass > Libclass = dynamic(Libclass) > ... That's fine when you directly use the class. Not when you work with instances provided by a framework (or another lib) that won't be affected by your above rebinding. From tjreedy at udel.edu Thu Jan 15 15:01:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:01:30 -0500 Subject: Python Crashes In-Reply-To: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> References: <4a616015-81a7-4040-84f7-4664571d7938@s1g2000prg.googlegroups.com> Message-ID: > > I am using 9 3rd party modules and there are some DLLs too - PIL etc. > But the problem is that the issue comes only after 3 hrs usually. > When I checked the memory using taskmanager, I found that it is not > going too high. I know of 3 general ways to crash the interpreter. 1. Use 3rd party modules. By far most common. I would try to do everything but use one of them, possibly by replacing import with stub. 2. Use ctypes. This can bypass all protections. 3. Write a subtle infinite recursion in a class method that is not checked for infinite recursion. The following illustrates the idea without testing whether this crashes. class c(): def __add__(self, other): return self+other # calls this __add__ I believe some of these vulnerabilities existed in 2.4 but many were crushed in 2.5. Backported to 2.4.3? No idea. This could hit so fast you never see it in task manager. If your 3rd party modules work with 2.5, consider upgrading to 2.5.3. Many bug fixes. tjr From bdesth.quelquechose at free.quelquepart.fr Thu Jan 15 15:21:56 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 15 Jan 2009 21:21:56 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <496fa88d$0$1459$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Wait a minute. Aren't the guy who just took me to task about the > definition of functional programming? So the definition of functional > programming is written in stone, but the definition of OO programming > is written in smoke? Well, actually, the answer is mostly "yes". Functional programming is based on a (mathematical) theoretical ground about calculation (google for Alonzo Church and lambda calculus), while OO is originally nothing more than a way to implement finite state machines with an imperative language. OO *is* imperative programming (which is itself also well defined). > > Just for the record, I really don't care much about the definition of > OO programming. I brought it up only because someone tried to claim > that "enforced" encapsulation data hiding. > is a terrible idea. Well, as far as I > can tell, the majority of OO "programmers" (and software engineers, > software architects, playing buzzword bingo ? etc.) seem to think otherwise. Maybe they are > wrong -- but I seriously doubt it. The first OO languages (at least the second one - Smalltalk) used data-hiding to clearly emphasize the "black box" nature of objects and the use of messages as the main (only in the case of Smalltalk) support for control flow. Remember than by that time, lost of programs where still mostly relying on *global* state changes. IOW, it has a strong educative value then... Following "OO" languages - mostly C++ and Java - kept this "rule" like it was a sacred cow (but mostly forgot about the more important points of 'everything is an object' and message-passing as main control flow). Then everyone started considering this as "fundamuntal", and here we are years later with one more cargo cult, when years of experience prove that it's not - at least from a practical POV. Once again, the important point is that there's a *clear* distinction between interface and implementation, and that you *shouldn't* mess with implementation. But what, some people think programmers are stupid, and so they hire stupid programmers, so they need b&d languages to protect stupid programmers from themselves - which just doesn't work, since *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb getter/setter pairs for _each and any_ attribute ? > As I said before, enforced encapsulation may not be appropriate for > every application, but it is definitely appropriate for some. No. It is appropriate for dummy managers hiring dummy programmers. The project's size and domain have nothing to do with it. > Not > every door needs a lock, but certainly some do. You only need locks when you don't trust your neighbours. From thomasmallen at gmail.com Thu Jan 15 15:25:11 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 12:25:11 -0800 (PST) Subject: UnicodeError for join() Message-ID: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> This line of code is throwing a UnicodeError for a handful of the few hundred files I'm processing: rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", self.content])) ................. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 442: ordinal not in range() What should I change to make this unicode-safe? Thanks, Thomas From tjreedy at udel.edu Thu Jan 15 15:29:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:29:33 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xocy8v4be.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > r writes: >> So what was the fatal error, care to post a traceback? > > Usually it's "expected to find some value but got None", or got a > list, or expected some structure but got a different one, or some > field was missing, etc. It's not a single traceback, it's a recurring > theme in developing this stuff. I do not see any connection, really, between what you describe above and your desire for static type-checking expressed elsewhere. When I was regularly doing analysis of empirical data files, I learned (sometimes the hard way, as you describe above) to **ALWAYS** run preliminary checks of all fields through the entire file so I would know the actual range of values of each and whether the ranges comported with the requirements of the intended analyses. The principle was/is the same whether using BMDP, SAS, C, or Python. Terry Jan Reedy From martin at v.loewis.de Thu Jan 15 15:34:14 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 15 Jan 2009 21:34:14 +0100 Subject: UnicodeError for join() In-Reply-To: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> Message-ID: <496f9dc6$0$22783$9b622d9e@news.freenet.de> > rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", > self.content])) > ................. > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position > 442: ordinal not in range() > > What should I change to make this unicode-safe? One of self.title and self.content is a Unicode string, the other is a byte string. You need to change them to have the same type (depending on whether you want to process them as Unicode or byte strings). HTH, Martin From mdw at distorted.org.uk Thu Jan 15 15:36:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 15 Jan 2009 20:36:36 +0000 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> mario ruggier writes: > Some info on its security is at: > http://evoque.gizmojo.org/usage/restricted/ > Tell you what, if you find a security hole there (via exposed template > source on a Domain(restricted=True) setup) I'll offer you a nice > dinner (including the beer!) somewhere, maybe at some py conference, > but even remotely if that is not feasible... ;-) The upcoming 0.4 > release will run on 2.4 thru to 3.0 -- you can have some fun with that > one (the current 0.3 runs on 2.5 and 2.6). I'm pretty sure I can break this on 3.0, because the f_restricted frame flag has gone. Here's how: >>> import template, domain >>> dom = domain.Domain('/tmp/mdw/', restricted = True, quoting = 'str') >>> t = template.Template(dom, 'evil', from_string = True, src = >>> "${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()}") 2009-01-15 20:30:29,177 ERROR [evoque] RuntimeError: restricted attribute: File "", line 1, in : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()) u'[RuntimeError: restricted attribute: File "", line 1, in \n: EvalError(inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/mdw/target\').read())]' which means that it's depending on the func_globals attribute being rejected by the interpreter -- which it won't be because 3.0 doesn't have restricted evaluation any more. Python is very leaky. I don't think trying to restrict Python execution is a game that's worth playing. -- [mdw] From tjreedy at udel.edu Thu Jan 15 15:37:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:37:00 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> Message-ID: Michele Simionato wrote: > On Jan 14, 3:27 am, Paul Rubin wrote:> >> I don't understand why some folks spew such violent rhetoric against >> the idea of augmenting Python with features to alert you automatically >> when you depart from the convention, so that you can check that the >> departure is actually what you wanted. A lot of the time, I find, the >> departures are accidental and automated checks would save me >> considerable debugging. > > I would be fine having something like pylint built-in in the language > and running at every change of the source code (unless disabled with a > command line switch). I think this is the only reasonable solution to > get some additional protection we can hope for. A true change of the > language IMO is impossible, both technically, politically and for > legacy issue. Also, I am not convinced it would be a good idea, even > theoretically. It is easier to write a new Python-like language > from scratch than to add type checking to Python (I think you > were not proposing adding type checking in this post, right?). Integrating checkers with the interpreter is something that could/should be done by an IDE. It should not be too hard, for instance, to give IDLE a configurable run-thru-PyLint option keyed, for instance, to shift-F5 (given that F5 is run-with-CPython). Alt-F5 for instance could be run-Pylint-and-if-no-errors-then-CPython. From tjreedy at udel.edu Thu Jan 15 15:38:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 15:38:32 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> <55c18466-08af-4e32-bce4-65fc839bcc5c@d36g2000prf.googlegroups.com> <7b48150b-41de-4c89-91e7-75fc8be7de69@s1g2000prg.googlegroups.com> Message-ID: Michele Simionato wrote: > On Jan 15, 7:38 am, "James Mills" > wrote: >> If one is a clumsy programmer, then perhaps >> one ought to be using a language that holds one's hand. > > Yes, and I use Python because it is a language that holds my hand, > otherwise I would use C and enjoy segmentation faults all the time. So perhaps it is a matter of which handholding one wants and which one hates. To avoid all, stick with assembler ;-). tjr From bignose+hates-spam at benfinney.id.au Thu Jan 15 15:58:49 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 07:58:49 +1100 Subject: Convention vs. fascism (was: General direction) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87zlhsb81i.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > > Familiarize yourself with PEP8 for naming and coding-conventions > > first. > > Enough of the PEP8-fascism please. It is not compulsory to follow > PEP8 in order to be allowed to learn Python. If Guido wanted it > compulsory, he'd have made the compiler enforce it. You are responding to something in Diez's message that I can't see. Nowhere does he say anything about PEP 8 being compulsory. Quite the contrary, he suggests gaining *familiarity* with PEP 8, and calls it a set of *conventions*. > Having said that, I will *suggest* to the Original Poster that you > should follow PEP8 as much as possible. It will save you a lot of > grief in the long run. This, on the other hand, seems pretty much a re-phrasing of what Diez already said. -- \ ?You've got the brain of a four-year-old boy, and I'll bet he | `\ was glad to get rid of it.? ?Groucho Marx | _o__) | Ben Finney From thomasmallen at gmail.com Thu Jan 15 16:00:50 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 13:00:50 -0800 (PST) Subject: UnicodeError for join() References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> Message-ID: <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> On Jan 15, 3:34?pm, "Martin v. L?wis" wrote: > > rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###", > > self.content])) > > ................. > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position > > 442: ordinal not in range() > > > What should I change to make this unicode-safe? > > One of self.title and self.content is a Unicode string, the other is > a byte string. You need to change them to have the same type (depending > on whether you want to process them as Unicode or byte strings). > > HTH, > Martin How can I do that? Thomas From martin at v.loewis.de Thu Jan 15 16:09:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 15 Jan 2009 22:09:07 +0100 Subject: UnicodeError for join() In-Reply-To: <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> Message-ID: <496FA5F3.8020200@v.loewis.de> >> One of self.title and self.content is a Unicode string, the other is >> a byte string. You need to change them to have the same type (depending >> on whether you want to process them as Unicode or byte strings). >> > > How can I do that? First, you need to find out what the respective types are: print type(self.title), type(self.content), repr(self.title), repr(self.content) With that information, as a very important next step, you need to understand why the error occurs. Then, you need to fix it, e.g. by converting all strings to byte strings. Suppose title is a unicode string, and further suppose the output is to be encoded in cp1252, then you change the line to rc_file.write(u"\n\n".join([self.title.encode("cp1252"), "### BEGIN CONTENT ###", self.content])) Regards, Martin From tjreedy at udel.edu Thu Jan 15 16:16:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 16:16:13 -0500 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Cong Ma wrote: > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, Not to me. You are using the module as a singleton class. The alternative is to write a class, make the functions methods, and instantiate the class. If that instance must be a singleton, more work is required. If multiple instances make sense, you can go the class route when you need to. > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. This sounds foolish and senseless (but not evil ;-). >For example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... More keystrokes for no gain. > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). Decorators are usally intended to wrap the input function with another function. But they can be used to modify the input function and return it altered. The latter is what you are proposing. You of course have to use SPAM as a local variable. Then you might be able to write an implementation-specific convert_to_global(name) function that would rewrite the code part of the code object of the function to what it would have been had you been sensible and used the 'global' directive. This would mean finding the code that loads and stores 'SPAM' as a local variable and convert is to code that loads and stores it as a global variable. If the replacement takes more bytes than the original, then the jump offsets all have to be fixed. Also needing fixing would be the line number table that is used to match code units to lines in the Python code for error tracebacks. An alterntive would be to de-compile the code, insert the global directive, and recompile. A non-decorator alternative would be to write a function with two parameters that takes a tuple of names and the code quoted as a string as arguments. It would insert the global statement into the string, execute it, and return the function. > I'd like to hear your opinions. Thank you. I hope I have convinced you to forget this idea. Terry Jan Reedy From tjreedy at udel.edu Thu Jan 15 16:23:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 16:23:33 -0500 Subject: Executing global code In-Reply-To: References: Message-ID: Jakub Debski wrote: > Hi, > > Is it possible to execute global code (module-level code) more than once > keeping the state of global variables? This means no reload() and no > moving the code to a function. Wrap the code in a loop: for dummy in range(): # a plural count literal tjr From lcaruso at tds.net Thu Jan 15 16:28:09 2009 From: lcaruso at tds.net (Larry Caruso) Date: Thu, 15 Jan 2009 15:28:09 -0600 Subject: newbie OOP question (what's the analogue to java interfaces in Python?) Message-ID: <000001c97758$2b01dea0$81059be0$@net> I'm an old time C programmer, but a newbie to OOP and Python. One OOP book I'm reading, "Holub on Patterns," discusses Java Interfaces in some detail (see http://en.wikipedia.org/wiki/Interface_(Java) for example) but with limited time, I'm hoping to avoid learning Java just to understand some key points of this book. Can anyone tell me what the analogue, if any, would be in Python? TIA. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomasmallen at gmail.com Thu Jan 15 16:34:19 2009 From: thomasmallen at gmail.com (tmallen) Date: Thu, 15 Jan 2009 13:34:19 -0800 (PST) Subject: UnicodeError for join() References: <85307a3f-19ee-4204-afa5-2a977e409e66@p2g2000prn.googlegroups.com> <496f9dc6$0$22783$9b622d9e@news.freenet.de> <90995537-e070-424a-84ab-b246caf315b4@t26g2000prh.googlegroups.com> <496FA5F3.8020200@v.loewis.de> Message-ID: On Jan 15, 4:09?pm, "Martin v. L?wis" wrote: > >> One of self.title and self.content is a Unicode string, the other is > >> a byte string. You need to change them to have the same type (depending > >> on whether you want to process them as Unicode or byte strings). > > > How can I do that? > > First, you need to find out what the respective types are: > > print type(self.title), type(self.content), repr(self.title), > repr(self.content) > > With that information, as a very important next step, you need to > understand why the error occurs. > > Then, you need to fix it, e.g. by converting all strings to byte > strings. > Suppose title is a unicode string, and further suppose the output > is to be encoded in cp1252, then you change the line to > > rc_file.write(u"\n\n".join([self.title.encode("cp1252"), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? "### BEGIN CONTENT ###", > ? ? ? ? ? ? ? ? ? ? ? ? ? ? self.content])) > > Regards, > Martin Thanks, it was the title that was causing problems. I just added the encode() part to the self.title assignment. Thomas From ajaksu at gmail.com Thu Jan 15 16:35:05 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 15 Jan 2009 13:35:05 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 15, 1:56?pm, mario ruggier wrote: > As > I mentioned in another thread, the real application behind all this is > one of the *few* secure templating systems around. Some info on its > security is at:http://evoque.gizmojo.org/usage/restricted/ > Tell you what, if you find a security hole there (via exposed template > source on a Domain(restricted=True) setup) I'll offer you a nice > dinner (including the beer!) somewhere, maybe at some py conference, > but even remotely if that is not feasible... ;-) If you could provide a bare-bones instance of your evaluator to test against, without using the whole evoque (I get DUMMY MODE ON from 'self.template.collection.domain.globals'), it'd be more interesting to try :) From perfreem at yahoo.com Thu Jan 15 16:39:18 2009 From: perfreem at yahoo.com (Per Freem) Date: Thu, 15 Jan 2009 13:39:18 -0800 (PST) Subject: optimizing large dictionaries Message-ID: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> hello i have an optimization questions about python. i am iterating through a file and counting the number of repeated elements. the file has on the order of tens of millions elements... i create a dictionary that maps elements of the file that i want to count to their number of occurs. so i iterate through the file and for each line extract the elements (simple text operation) and see if it has an entry in the dict: for line in file: try: elt = MyClass(line)# extract elt from line... my_dict[elt] += 1 except KeyError: my_dict[elt] = 1 i am using try/except since it is supposedly faster (though i am not sure about this? is this really true in Python 2.5?). the only 'twist' is that my elt is an instance of a class (MyClass) with 3 fields, all numeric. the class is hashable, and so my_dict[elt] works well. the __repr__ and __hash__ methods of my class simply return str() representation of self, while __str__ just makes everything numeric field into a concatenated string: class MyClass def __str__(self): return "%s-%s-%s" %(self.field1, self.field2, self.field3) def __repr__(self): return str(self) def __hash__(self): return hash(str(self)) is there anything that can be done to speed up this simply code? right now it is taking well over 15 minutes to process, on a 3 Ghz machine with lots of RAM (though this is all taking CPU power, not RAM at this point.) any general advice on how to optimize large dicts would be great too thanks for your help. From sjmachin at lexicon.net Thu Jan 15 16:39:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 13:39:50 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <457747b6-b120-4be7-a9ba-99dda2348326@h16g2000yqj.googlegroups.com> On Jan 16, 4:28?am, "Lambert, David W (S&T)" wrote: > Although isinstance predates sets, the python history I recall is that > allowing tuples as second argument to isinstance happened at about the > same time as set type was builtin. isinstance 2nd arg as tuple of type info: 2.2 sets module: 2.3 set type: 2.4 From pavlovevidence at gmail.com Thu Jan 15 16:43:37 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jan 2009 13:43:37 -0800 (PST) Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> Message-ID: <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> On Jan 15, 1:08?pm, Duncan Booth wrote: > Carl Banks wrote: > > I don't see what the big deal is. ?Right now isinstance accepts a type > > or a tuple of types. ?The code could be changed to allow a type, or > > any iterable the returns types (wherein every items of the sequence is > > required to be a type). ?What's messy about that? > > No, it isn't restricted to a type or a tuple of types: right now isinstance > accepts X where X is a type or a tuple of X. The definition is recursive, > and the data structure can be deeply nested, but (because tuples are > immutable) it cannot be infinite. > > e.g.>>> isinstance('x', (((((int, (float, str)),),),),)) > > True Oh. Not sure what the use case for THAT was, but that would make things messy. Carl Banks From lkcl at lkcl.net Thu Jan 15 16:48:49 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 15 Jan 2009 21:48:49 +0000 Subject: report on building of python 2.5.2 under msys under wine on linux. Message-ID: no, the above subject-line is not a joke: i really _have_ successfully built python2.5.2 by installing wine on linux, then msys under wine, and then mingw32 compiler - no, not the linux mingw32-cross-compiler, the _native_ mingw32 compiler that runs under msys, and then hacking things into submission until it worked. issue-report: http://bugs.python.org/issue4954 source code: http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine related issue-report: http://bugs.python.org/issue3871 related issue-report: http://bugs.python.org/issue1597850 i'm going to _try_ to merge in #3871 but it's... the prospect of sitting waiting for configure to take THREE hours to complete, due to /bin/sh.exe instances taking TWO SECONDS _each_ to start up does not really fill me with deep joy. consequently i did a major hatchet-job on configure.in with repeated applications of "if test $win32build = no; then" ... cue several hundred lines of configure.in tests blatantly ignored "fi # $win32build=no! " and thus cut the configure time down from three hours to a mere 15 minutes. the only reason why this was possible at all was because PC/config.h already exists and has been pre-set-up with lots of lovely #defines. also, there is another significant difference between #3871 and #4954 - i chose to build in to libpython2.5.dll exactly as many modules as are in the proprietary win32 build. this turned out to be a good practical decision, due to /bin/sh.exe messing around and stopping python.exe from running! (under cmd.exe it's fine. i have to do a bit more investigation: my guess is that the msys "remounter" is getting in the way, somehow. compiling python to have a prefix of /python25 results in files being installed in /python25 which maps to c:/msys/python25/ but.... actually that doesn't get communicated correctly to the compiled python.exe.... it's all a bit odd - it still feels like things are being cross-compiled... but they're not... it's just that setup.py has paths that don't _quite_ match up with the msys environment... needs work, there. the regression testing is _great_ fun! some of the failures are really quite spectacular, but surprisingly there are less than anticipated. file "sharing violation" isn't a big surprise (under wine); the ctypes structure failures are going to be a bitch to hunt down; the test_str %f failure _was_ a big surpise; the builtin file \r\n <-> \n thing wasn't in the _least_ bit of a surprise :) overall, this has been... interesting. and the key thing is that thanks to #3871 and #4954 and #1597850, python will soon happily compile for win32 _without_ the dependence on _any_ proprietary software or operating systems. that's a pretty significant milestone. l. p.s. if anyone would like to try out this build, on a windows box, to see if it fares any better on the regression tests please say so and i will make the binaries available. From mario.ruggier at gmail.com Thu Jan 15 16:52:46 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 13:52:46 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7bd6ef74-8608-489b-bea5-dd243bf0c803@x38g2000yqj.googlegroups.com> On Jan 15, 9:36?pm, Mark Wooding wrote: > mario ruggier writes: > > Some info on its security is at: > >http://evoque.gizmojo.org/usage/restricted/ > > Tell you what, if you find a security hole there (via exposed template > > source on a Domain(restricted=True) setup) I'll offer you a nice > > dinner (including the beer!) somewhere, maybe at some py conference, > > but even remotely if that is not feasible... ;-) The upcoming 0.4 > > release will run on 2.4 thru to 3.0 -- you can have some fun with that > > one (the current 0.3 runs on 2.5 and 2.6). > > I'm pretty sure I can break this on 3.0, because the f_restricted frame > flag has gone. ?Here's how: > > >>> import template, domain > >>> dom = domain.Domain('/tmp/mdw/', restricted = True, quoting = 'str') > >>> t = template.Template(dom, 'evil', from_string = True, src = > >>> "${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()}") > > 2009-01-15 20:30:29,177 ERROR [evoque] RuntimeError: restricted > attribute: ? File "", line 1, in > : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw/target').read()) > u'[RuntimeError: restricted attribute: ? File "", line 1, in > \n: > EvalError(inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/mdw/target\').read())]' > > which means that it's depending on the func_globals attribute being > rejected by the interpreter -- which it won't be because 3.0 doesn't > have restricted evaluation any more. $ touch /tmp/mdw.test mr:evoque mario$ python3.0 Python 3.0 (r30:67503, Dec 8 2008, 18:45:31) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from evoque import domain, template >>> d = domain.Domain("/", restricted=True, quoting="str") >>> t = template.Template(d, "mdw1", from_string=True, src="${inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/mdw.test').read()}") >>> t.evoque() 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' object has no attribute 'func_globals': File "", line 1, in : EvalError(inspect.func_globals['_'*2+'builtins'+'_'*2].open('/tmp/ mdw.test').read()) '[AttributeError: \'function\' object has no attribute \'func_globals \': File "", line 1, in \n: EvalError (inspect.func_globals[\'_\'*2+\'builtins\'+\'_\'*2].open(\'/tmp/ mdw.test\').read())]' But even if inspect did have the func_globals attribute, the "open" builtin will not be found on __builtins__ (that is cleaned out when restricted=True). But, I guess it is necessary to keep an eye on what is available/ allowed by the different python versions, and adjust as needed, probably to the lowest common denominator. In addition to what is mentioned on the doc on evoque's resticted mode at the above URL, do you have specific suggestions what may be a good idea to also block out? > Python is very leaky. ?I don't think trying to restrict Python execution > is a game that's worth playing. It may not be worth risking your life on it, but it is certainly worth playing ;-) Thanks.. with you permission I am adding your evil expression to the restricted tests? Cheers, mario > -- [mdw] From http Thu Jan 15 16:59:12 2009 From: http (Paul Rubin) Date: 15 Jan 2009 13:59:12 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> Message-ID: <7xmydsw7rj.fsf@ruckus.brouhaha.com> Terry Reedy writes: > I do not see any connection, really, between what you describe above > and your desire for static type-checking expressed elsewhere. When I > was regularly doing analysis of empirical data files, I learned > (sometimes the hard way, as you describe above) to **ALWAYS** run > preliminary checks of all fields through the entire file Right. And if the file is large enough that even parsing all the records to check the fields takes hours, well, that's where I'm at. From mccredie at gmail.com Thu Jan 15 17:00:40 2009 From: mccredie at gmail.com (Matimus) Date: Thu, 15 Jan 2009 14:00:40 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> On Jan 15, 1:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. You can use a tuple instead of a string, which should be a little quicker: def __hash__(self): return self.field1, self.field2, self.field3 You could speed it up even more if you just saved a single attribute "fields" as a tuple to begin with. Also, you can use defauldict and get rid of the try/except. I don't think try/except is slow, but avoiding it will give you a speed up. from collections import defaultdict my_dict = defaultdict(int) for line in file: elt = MyClass(line)# extract elt from line... my_dict[elt] += 1 You might even consider turning "MyClass" into just a function that extracts the values from the line and returns a tuple, which should give you even more of a boost since a tuple is completely implemented in C. Matt From sjmachin at lexicon.net Thu Jan 15 17:13:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 14:13:12 -0800 (PST) Subject: Py3 - converting bytes to ascii References: Message-ID: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> On Jan 16, 1:54?am, "Anjanesh Lekshminarayanan" wrote: > Using Python 3.0 > > res = urllib.request.urlopen(url) > f = open('file.txt', 'wb') # Since res.read() returns bytes > f.write(res.read()) > > But newline and return feeds are stored as b14, 58a as text in the text file. I can't imagine how a newline (aka line feed) and/or a carriage return could end up being stored as "b14, 58a as text in the text file". What are you using to view the output file? Before you start trying to fix the problem, we need to understand it. You can use Python itself to show you exactly what is in the file, in a format that you can copy and paste into a news posting. f = open('file.txt', 'rb') data = f.read() f.close() print(ascii(data)) # Python 3.x # print repr(data) # Python 2.x > So how do I to convert res.read() to ascii on opening the file in > ascii mode f = open('file.txt', 'w')? Are you as sure as Casey is that your data is ASCII-only? Or are you using "ascii" to mean "text" or "not binary"? Let's see your data first. Perhaps if you could give us a few clues like how much experience you have in (Python 3.0, Python 2.x, using urllib, computer programming in general) we could give you somewhat more focussed advice. HTH, John From jervisau at gmail.com Thu Jan 15 17:18:51 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 16 Jan 2009 09:18:51 +1100 Subject: optimizing large dictionaries In-Reply-To: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <8e63a5ce0901151418i2622b6f3h435247c55731b0b5@mail.gmail.com> On Fri, Jan 16, 2009 at 8:39 AM, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > > for line in file: > try: > elt = MyClass(line)# extract elt from line... > my_dict[elt] += 1 > except KeyError: > my_dict[elt] = 1 > > > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) > > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. > -- > http://mail.python.org/mailman/listinfo/python-list > Hello, You can get a large speedup by removing the need to instantiate a new MyClass instance on each iteration of your loop. Instead define one MyClass with an 'interpret' method that would be called instead of MyClass() interpret would return the string '%s-%s-%s' % (self.field1 etc..) i.e myclass = MyClass() interpret = myclass.interpret for line in file: elt = interpet(line)# extract elt from line... try: my_dict[elt] += 1 except KeyError: my_dict[elt] = 1 The speed up is on the order of 10 on my machine. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From kingstonlee at gmail.com Thu Jan 15 17:19:06 2009 From: kingstonlee at gmail.com (Kingston) Date: Thu, 15 Jan 2009 14:19:06 -0800 (PST) Subject: Python DateTime Manipulation Message-ID: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> I have a user input a date and time as a string that looks like: "200901010100" but I want to do a manipulation where I subtract 7 days from it. The first thing I tried was to turn the string into a time with the format "%Y%m%d%H%M" and then strip out the day value, turn it into an int and subtract seven, but the value "-6" doesn't mean anything in terms of days =). Does anyone have an idea as to how I can subtract 7 days without turning the date string into an int? Perfect Scenario: perfectdate = 200901010100 - 7Days print perfect date 200812250100 What I have so far: import time, os, re useryear = raw_input("Enter Year (numerical YYYY): ") usermonth = raw_input("Enter Month (numerical MM): ") userday = raw_input("Enter Day (numerical DD): ") usertime = raw_input("Enter Time (24-hour clock hhmm): ") #userday = int(userday) #secondday = userday - 07 #secondday = str(secondday) #userday = str(userday) #firstdate = useryear + usermonth + secondday + usertime seconddate = useryear + usermonth + userday + usertime seconddate = time.strptime(seconddate, %Y%m%d%H%M) print seconddate From mario.ruggier at gmail.com Thu Jan 15 17:21:02 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 14:21:02 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> On Jan 15, 10:35?pm, ajaksu wrote: > On Jan 15, 1:56?pm, mario ruggier wrote: > > > As > > I mentioned in another thread, the real application behind all this is > > one of the *few* secure templating systems around. Some info on its > > security is at:http://evoque.gizmojo.org/usage/restricted/ > > Tell you what, if you find a security hole there (via exposed template > > source on a Domain(restricted=True) setup) I'll offer you a nice > > dinner (including the beer!) somewhere, maybe at some py conference, > > but even remotely if that is not feasible... ;-) > > If you could provide a bare-bones instance of your evaluator to test > against, without using the whole evoque (I get DUMMY MODE ON from > 'self.template.collection.domain.globals'), it'd be more interesting > to try :) OK! Here's a small script to make it easier... Just accumulate any expression you can dream of, and pass it to get_expr_template() to get the template, and on that then call evoque()... i guess you'd have to test with 0.3, but 0.4 (also runs on py3) is just around the corner.... Let it rip... the beer'd be on me ;-! # evoque_restricted_test.py from os.path import abspath, join, dirname from evoque import domain, template import logging # uncomment to hide the plentiful ERROR logs: #logging_level = logging.CRITICAL # set the base for for the defualt collection DEFAULT_DIR = abspath("/") # 3 -> renders, 4 -> raises any evaluation errors, # see: http://evoque.gizmojo.org/usage/errors/ ERRORS=2 # a restricted domain instance d = domain.Domain(DEFAULT_DIR, restricted=True, errors=ERRORS, quoting='str') count = 0 # utility to easily init a template from any expression def get_expr_template(expr): global count count += 1 name = "test%s"%(count) src = "${%s}" % (expr) d.set_template(name, src=src, from_string=True) return d.get_template(name) # some test expressions exprs = [ "open('test.txt', 'w')", "getattr(int, '_' + '_abs_' + '_')", "().__class__.mro()[1].__subclasses__()", "inspect.func_globals['_'*2+'builtins'+'_'*2]", ] # execute for expr in exprs: print print expr print get_expr_template(expr).evoque() From lists at cheimes.de Thu Jan 15 17:22:48 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 15 Jan 2009 23:22:48 +0100 Subject: optimizing large dictionaries In-Reply-To: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) > > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) class MyClass(object): # a new style class with slots saves some memory __slots__ = ("field1", "field2", "field2") def __hash__(self): # In general this is faster than your approach because # it requires less function calls. However all fields must # be hashable return hash((self.field1, self.field2, self.field2)) def __eq__(self, other): # you MUST provide a rich compare __eq__ function # when you provide your own hash function. It's called # when hash(a) == hash(b). if not isinstance(other, MyClass): return NotImplemented return (self.field1 == other.field1 and self.field2 == other.field2 and self.field3 == other.field3) def __str__(self): return "%s-%s-%s" %(self.field1, self.field2, self.field3) # faster than your approach because it doesn't require more function # lookups. You can omit this alias, too. It's not required. __repr__ = __str__ Instead of the try/except clause I recommend colletions.defaultdict. Defaultdict takes one callable as factory function. Since int() returns 0 it has the same effect as your code. from collections import defaultdict elt = defaultdict(int) Christian From clp2 at rebertia.com Thu Jan 15 17:25:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 14:25:20 -0800 Subject: Python DateTime Manipulation In-Reply-To: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> References: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> Message-ID: <50697b2c0901151425g20abea25q884457dca63b140f@mail.gmail.com> On Thu, Jan 15, 2009 at 2:19 PM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and then strip out the day value, turn it into an > int and subtract seven, but the value "-6" doesn't mean anything in > terms of days =). > > Does anyone have an idea as to how I can subtract 7 days without > turning the date string into an int? >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now datetime.datetime(2009, 1, 15, 14, 22, 56, 416662) >>> week = timedelta(days=7) >>> now - week datetime.datetime(2009, 1, 8, 14, 22, 56, 416662) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From markus.schreyer at gmail.com Thu Jan 15 17:35:11 2009 From: markus.schreyer at gmail.com (Markus Schreyer) Date: Thu, 15 Jan 2009 23:35:11 +0100 Subject: Import functions in current namespace Message-ID: Hi, we embedded python into our application via Swig. Now we like to wrap the raw API functionality into a nicer more handleable module, but instead of repeating every function in this wrapper i thought about importing them into the namespace of the wrapper module. I like to give you an example of what we like to achive. Swig generates a file called "ppms.py" which contains the API classes and functions. Lets say the ppms.py contains a function called foo(). The wrapper.py should now import the function foo() of the module ppms into the local namespace. the swig module: def foo(): pass def foo0(): pass One possibility would be to repeat the function in the wrapper.py like: import ppms.py def foo(): return ppms.foo() def foo0(): return ppms.foo0()+1 Imho this is a little ugly. So I thought about importing the content of ppms.py (the autgenerated one) into the namespace of the wrapper. Every definition of a fuction in the wrapper should overwrite the function in the imported module but a call to a function which is not defined in the wrapper goes right through. # wrapper.py - magic version "magic_import" ppms.py def foobar(): return foo() #calls foo of ppms.py def foo0(): return foo0()+1 #calls foo0 of ppms.py Now using the magic version: import wrapper wrapper.foo() # looks in wrapper for foo() since it's not defined it falls back to ppms.foo() wrapper.foobar() # calls wrapper.foobar() calls ppms.foo() wrapper.foo0() # calls wrapper.foo0() calls ppms.foo0() Hopefully the idea is not to stupid.. ;) Tnx for your help. Markus -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 15 17:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:35:16 -0500 Subject: List comprehension - NameError: name '_[1]' is not defined ? In-Reply-To: References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Peter Otten wrote: > List comprehensions delete the helper variable after completion: I do not believe they did in 2.4. Not sure of 2.5. There is certainly a very different implementation in 3.0 and, I think, 2.6. OP neglected to mention Python version he tested on. Code meant to run on 2.4 to 3.0 cannot depend on subtle listcomp details. >>>> def f(): [i for i in [1]] > ... >>>> dis.dis(f) > 1 0 BUILD_LIST 0 > 3 DUP_TOP > 4 STORE_FAST 0 (_[1]) > 7 LOAD_CONST 1 (1) > 10 BUILD_LIST 1 > 13 GET_ITER > >> 14 FOR_ITER 13 (to 30) > 17 STORE_FAST 1 (i) > 20 LOAD_FAST 0 (_[1]) > 23 LOAD_FAST 1 (i) > 26 LIST_APPEND > 27 JUMP_ABSOLUTE 14 > >> 30 DELETE_FAST 0 (_[1]) > 33 POP_TOP > 34 LOAD_CONST 0 (None) > 37 RETURN_VALUE > In 3.0 >>> def f(): [i for i in [1]] >>> import dis >>> dis.dis(f) 1 0 LOAD_CONST 1 ( at 0x01349BF0, file "", line 1>) 3 MAKE_FUNCTION 0 6 LOAD_CONST 2 (1) 9 BUILD_LIST 1 12 GET_ITER 13 CALL_FUNCTION 1 16 POP_TOP 17 LOAD_CONST 0 (None) 20 RETURN_VALUE Running OP code in 3.0 with print ()s added gives pre 0.a 1.b 2.c 3.d post Traceback (most recent call last): File "C:\Programs\Python30\misc\temp7.py", line 32, in """ % gie) File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 7, in File "", line 7, in File "C:\Programs\Python30\misc\temp7.py", line 12, in ts return ts % self File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ return eval(expr, self.globals, self.locals) File "", line 2, in File "", line 1, in NameError: global name 'i' is not defined > If you manage to run two nested listcomps in the same namespace you get a > name clash and the inner helper variable overwrites/deletes the outer: > >>>> def xeval(x): return eval(x, ns) > ... >>>> ns = dict(xeval=xeval) >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in xeval > File "", line 1, in > NameError: name '_[1]' is not defined Which Python? 3.0 prints "[[]]"! But I think the nested listcomp *is* in a separate namespace here. I will leave it to you or OP to disect how his and your code essentially differ from 3.0 (and maybe 2.6) implementation's viewpoint. Terry Jan Reedy From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:40:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:40:40 GMT Subject: Convention vs. fascism (was: General direction) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> Message-ID: <017fb1f3$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> > Familiarize yourself with PEP8 for naming and coding-conventions >> > first. >> >> Enough of the PEP8-fascism please. It is not compulsory to follow PEP8 >> in order to be allowed to learn Python. If Guido wanted it compulsory, >> he'd have made the compiler enforce it. > > You are responding to something in Diez's message that I can't see. > Nowhere does he say anything about PEP 8 being compulsory. Quite the > contrary, he suggests gaining *familiarity* with PEP 8, and calls it a > set of *conventions*. He doesn't *suggest* anything. He uses the imperative case -- it's a command. It may not have been Diez's deliberate, conscious intention to order the OP to learn PEP8, but without a modifier like "I think you should", that's what he did. That's why I emphasised "suggest" in my response: it's not an order, but it is recommended. On its own, that wouldn't have been enough to warrant a response. I'm sure I've thoughtlessly and inappropriately used unmodified imperative commands in the past, and I'll probably do it again. But add to it the perfunctory way he used this mysterious (to a newbie) jargon "PEP8", without even the courtesy of a link, and the overall tone was newbie hostile. I'm sure that wasn't Diez's intention, because the rest of his post was not like that. >> Having said that, I will *suggest* to the Original Poster that you >> should follow PEP8 as much as possible. It will save you a lot of grief >> in the long run. > > This, on the other hand, seems pretty much a re-phrasing of what Diez > already said. That's because I agree with Diez that following PEP8 is generally a good thing, but don't agree with him that it is necessary to learn the naming conventions before learning the language. An overly strict approach will just frighten the newbies off. Part of the reason that Python is successful is that it is accessible to newbies, and giving them strict Thou Shalt Do This commands is quite off-putting. -- Steven From tjreedy at udel.edu Thu Jan 15 17:41:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:41:37 -0500 Subject: List comprehension - NameError: name '_[1]' is not defined ? In-Reply-To: References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: mario ruggier wrote: > On Jan 15, 4:06 pm, Steven D'Aprano cybersource.com.au> wrote: > > Hi Steve! > >>> class GetItemEvaluator(object): >>> def __init__(self): >>> self.globals = globals() # some dict (never changes) > > Ya, this is just a boiled down sample, and for simplicity I set to to > the real globals(), so of course it will change when that changes... > but in the application this is a distinct dict, that is entirely > managed by the application, and it never changes as a result of an > *evaluation*. It would have been less confusing if you had written self.globals = {} # a constant dict or even self.constants = {} # empty here only for simplicity This might also make the 3.0 error message clearer (see other post). tjr From clp2 at rebertia.com Thu Jan 15 17:43:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 14:43:35 -0800 Subject: Import functions in current namespace In-Reply-To: References: Message-ID: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> On Thu, Jan 15, 2009 at 2:35 PM, Markus Schreyer wrote: > Hi, > we embedded python into our application via Swig. Now we like to wrap the > raw API functionality into a nicer more handleable module, but instead of > repeating every function in this wrapper i thought about importing them into > the namespace of the wrapper module. I like to give you an example of what > we like to achive. > Swig generates a file called "ppms.py" which contains the API classes and > functions. > Lets say the ppms.py contains a function called foo(). The wrapper.py should > now import the function foo() of the module ppms into the local namespace. > the swig module: > def foo(): > pass > def foo0(): > pass > One possibility would be to repeat the function in the wrapper.py like: > import ppms.py > def foo(): > return ppms.foo() > def foo0(): > return ppms.foo0()+1 > Imho this is a little ugly. So I thought about importing the content of > ppms.py (the autgenerated one) into the namespace of the wrapper. Every > definition of a fuction in the wrapper should overwrite the function in the > imported module but a call to a function which is not defined in the wrapper > goes right through. > # wrapper.py - magic version > "magic_import" ppms.py I believe the magic you seek is: from ppms import * Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:43:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:43:40 GMT Subject: Executing global code References: Message-ID: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e. g. these two statements > > x = 42 > x += 1 > > and want to rerun it with the effect of x becoming 44? That is not > possible Unless you move the value of x into external storage. Untested: try: f = open('mystorage.txt', 'r') except IOError: x = 42 else: x = int(f.read()) x += 1 Naturally the above is not bulletproof enough for production use. I'm curious why the Original Poster wants to do such a thing, and particularly the prohibition against moving code into a function. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:44:14 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:44:14 GMT Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> Message-ID: <017fb2c9$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 07:56:02 -0800, mario ruggier wrote: > On Jan 15, 4:06?pm, Steven D'Aprano cybersource.com.au> wrote: > > Hi Steve! > >> > class GetItemEvaluator(object): >> > ? ? def __init__(self): >> > ? ? ? ? self.globals = globals() # some dict (never changes) > > Ya, this is just a boiled down sample, and for simplicity I set to to > the real globals(), You should make that more clear when posting, in the code snippet as well as the descriptive text. And if you *did* make it clear, then *I* should read your post more carefully. Regards, -- Steven From tjreedy at udel.edu Thu Jan 15 17:49:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 17:49:22 -0500 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: Eric Brunel wrote: > Hi all, > > I found a behaviour that might be a bug in Tkinter for Python 2.6. Here > is the script: > > ----------------------------- > from Tkinter import * > from tkMessageBox import * > from tkFileDialog import * > > root = Tk() > > def ask_file(): > file_name = askopenfilename() > print file_name > > def ask_confirm(): > answer = askyesno() > print answer > > Button(root, text='Ask file', command=ask_file).pack() > Button(root, text='Ask confirm', command=ask_confirm).pack() > > root.mainloop() > ----------------------------- > > Scenario: > - Run the script. > - Click the 'Ask confirm' button and answer 'Yes'; it should print True, > which is the expected answer. > - Click the 'Ask file' button, select any file and confirm. > - Click the 'Ask confirm' button and answer 'Yes'. > > At the last step, the script prints 'False' for me, which is quite > wrong. Can anybody confirm this? > > I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise > Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, > it seems to work correctly on Windows 2000. I could only test with > Python 2.6, and not 2.6.1. But I didn't see any mention of this problem > in the release notes. > > And BTW, if this is actually a bug, where can I report it? bugs.python.org From bearophileHUGS at lycos.com Thu Jan 15 17:49:29 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 14:49:29 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> Message-ID: Matimus, your suggestions are all good. Try-except is slower than: if x in adict: ... else: ... A defaultdict is generally faster (there are some conditions when it's not faster, but they aren't much common. I think it's when the ratio of duplicates is really low), creating just a tuple instead of a class helps a lot, and when the CPU/OS allow it, Psyco too may help some here. If the resulting speed isn't enough yet, consider that Python dicts are quite fast, so you may need lot of care to write D/C/C++/Clisp code that's faster for this problem. I also suspect that when they become very large, Python dicts lose some of their efficiency. If this is true, you may switch to a new dictionary every chunk of file, and then merge the dicts at the end. I don't actually know if this may speed up your Python code even more (if you experiment this, I'd like to know if it's false). Bye, bearophile From benjamin.kaplan at case.edu Thu Jan 15 17:57:34 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 15 Jan 2009 17:57:34 -0500 Subject: newbie OOP question (what's the analogue to java interfaces in Python?) In-Reply-To: <000001c97758$2b01dea0$81059be0$@net> References: <000001c97758$2b01dea0$81059be0$@net> Message-ID: On Thu, Jan 15, 2009 at 4:28 PM, Larry Caruso wrote: > I'm an old time C programmer, but a newbie to OOP and Python. One OOP > book I'm reading, "Holub on Patterns," discusses Java Interfaces in some > detail (see http://en.wikipedia.org/wiki/Interface_(Java) for example) but > with limited time, I'm hoping to avoid learning Java just to understand some > key points of this book. Can anyone tell me what the analogue, if any, would > be in Python? TIA. > > > There isn't one (well, you could use Abstract Base Classes if you're using Python 3, but you don't need to). Interfaces are needed in Java for 2 reasons. 1. There are times when designing something that you don't really care what the class actually is, just what it does (i.e. iterators). With Java's static typing, you either have to overload the method for each object that needs to work with this method or use inheritance. Python uses duck typing- if it looks like a duck and quacks like a duck, it must be a duck. No static typing= no need to inherit. Inheritance in Python is only used if you want to reuse some of the behavior of the base class. 2. Interfaces in Java are a result of not supporting multiple inheritance. If you really need interfaces (for instance, you're rewriting a Java program and you don't want to change anything), you can just use base classes. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 17:58:01 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 22:58:01 GMT Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <017fb604$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 23:22:48 +0100, Christian Heimes wrote: >> is there anything that can be done to speed up this simply code? right >> now it is taking well over 15 minutes to process, on a 3 Ghz machine >> with lots of RAM (though this is all taking CPU power, not RAM at this >> point.) > > class MyClass(object): > # a new style class with slots saves some memory > __slots__ = ("field1", "field2", "field2") I was curious whether using slots would speed up attribute access. >>> class Parrot(object): ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c ... >>> class SlottedParrot(object): ... __slots__ = 'a', 'b', 'c' ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c ... >>> >>> p = Parrot(23, "something", [1, 2, 3]) >>> sp = SlottedParrot(23, "something", [1, 2, 3]) >>> >>> from timeit import Timer >>> setup = "from __main__ import p, sp" >>> t1 = Timer('p.a, p.b, p.c', setup) >>> t2 = Timer('sp.a, sp.b, sp.c', setup) >>> min(t1.repeat()) 0.83308887481689453 >>> min(t2.repeat()) 0.62758088111877441 That's not a bad improvement. I knew that __slots__ was designed to reduce memory consumption, but I didn't realise they were faster as well. -- Steven From jervisau at gmail.com Thu Jan 15 17:59:14 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 16 Jan 2009 09:59:14 +1100 Subject: Python DateTime Manipulation In-Reply-To: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> References: <09f788a5-c4c5-493d-a7b4-1d675d54cb2f@s20g2000yqh.googlegroups.com> Message-ID: <8e63a5ce0901151459w67d28517xf7212a26db347a56@mail.gmail.com> On Fri, Jan 16, 2009 at 9:19 AM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and then strip out the day value, turn it into an > int and subtract seven, but the value "-6" doesn't mean anything in > terms of days =). > > Does anyone have an idea as to how I can subtract 7 days without > turning the date string into an int? > > Perfect Scenario: > perfectdate = 200901010100 - 7Days > print perfect date > 200812250100 > > > What I have so far: > import time, os, re > useryear = raw_input("Enter Year (numerical YYYY): ") > usermonth = raw_input("Enter Month (numerical MM): ") > userday = raw_input("Enter Day (numerical DD): ") > usertime = raw_input("Enter Time (24-hour clock hhmm): ") > #userday = int(userday) > #secondday = userday - 07 > #secondday = str(secondday) > #userday = str(userday) > #firstdate = useryear + usermonth + secondday + usertime > seconddate = useryear + usermonth + userday + usertime > seconddate = time.strptime(seconddate, %Y%m%d%H%M) > print seconddate > -- > http://mail.python.org/mailman/listinfo/python-list > import datetime DATE_FORMAT = '%Y%m%d%H%M' original = datetime.datetime.strptime(yourstring, DATE_FORMAT ) newtime = original - datetime.timedelta(days=7) perfectdate = newtime.strftime(DATE_FORMAT) print perfectdate Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.watrous at gmail.com Thu Jan 15 18:00:56 2009 From: daniel.watrous at gmail.com (Daniel) Date: Thu, 15 Jan 2009 15:00:56 -0800 (PST) Subject: logging multiple messages Message-ID: I was fighting with a problem all day that was producing multiple messages in my logging output. The problem was related to the fact that I was defining logging handlers multiple times. I found the following posting from a few years ago that related to my problem: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8a707c289642c668/44f16cf5ba68721f?lnk=gst&q=logging#44f16cf5ba68721f What I did was the following: def initLogging(loggingArea): # create/get logger logger = logging.getLogger("mylogger") logger.setLevel(logging.DEBUG) # setup Handlers if len(logger.handlers) == 0: # create handlers only if there are none sh = logging.StreamHandler() # now add the handlers logger.addHandler(sh) If the logger already has handlers nothing happens, otherwise they're created and added to the logger. Now I can call initLogging ('mylogarea') whereever I need to without getting multiple messages. If you know of a better way to do this let me know... From leoneel at gmail.com Thu Jan 15 18:04:26 2009 From: leoneel at gmail.com (neel) Date: Thu, 15 Jan 2009 15:04:26 -0800 (PST) Subject: How to verify whether a process got hanged or still alive. Message-ID: <9b60f865-7585-4251-810e-7c86d9a2f876@j39g2000yqn.googlegroups.com> Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel From leoneel at gmail.com Thu Jan 15 18:04:53 2009 From: leoneel at gmail.com (neel) Date: Thu, 15 Jan 2009 15:04:53 -0800 (PST) Subject: How to verify whether a process got hanged or still alive. Message-ID: Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel From mario.ruggier at gmail.com Thu Jan 15 18:05:18 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 15:05:18 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: On Jan 15, 11:35?pm, Terry Reedy wrote: > Peter Otten wrote: > > List comprehensions delete the helper variable after completion: > > I do not believe they did in 2.4. ?Not sure of 2.5. ?There is certainly > ? a very different implementation in 3.0 and, I think, 2.6. ?OP > neglected to mention Python version he tested on. Code meant to run on > 2.4 to 3.0 cannot depend on subtle listcomp details. > > > > >>>> def f(): [i for i in [1]] > > ... > >>>> dis.dis(f) > > ? 1 ? ? ? ? ? 0 BUILD_LIST ? ? ? ? ? ? ? 0 > > ? ? ? ? ? ? ? 3 DUP_TOP > > ? ? ? ? ? ? ? 4 STORE_FAST ? ? ? ? ? ? ? 0 (_[1]) > > ? ? ? ? ? ? ? 7 LOAD_CONST ? ? ? ? ? ? ? 1 (1) > > ? ? ? ? ? ? ?10 BUILD_LIST ? ? ? ? ? ? ? 1 > > ? ? ? ? ? ? ?13 GET_ITER > > ? ? ? ? >> ? 14 FOR_ITER ? ? ? ? ? ? ? ?13 (to 30) > > ? ? ? ? ? ? ?17 STORE_FAST ? ? ? ? ? ? ? 1 (i) > > ? ? ? ? ? ? ?20 LOAD_FAST ? ? ? ? ? ? ? ?0 (_[1]) > > ? ? ? ? ? ? ?23 LOAD_FAST ? ? ? ? ? ? ? ?1 (i) > > ? ? ? ? ? ? ?26 LIST_APPEND > > ? ? ? ? ? ? ?27 JUMP_ABSOLUTE ? ? ? ? ? 14 > > ? ? ? ? >> ? 30 DELETE_FAST ? ? ? ? ? ? ?0 (_[1]) > > ? ? ? ? ? ? ?33 POP_TOP > > ? ? ? ? ? ? ?34 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > > ? ? ? ? ? ? ?37 RETURN_VALUE > > In 3.0 > ?>>> def f(): [i for i in [1]] > > ?>>> import dis > ?>>> dis.dis(f) > ? ?1 ? ? ? ? ? 0 LOAD_CONST ? ? ? ? ? ? ? 1 ( at > 0x01349BF0, file "", line 1>) > ? ? ? ? ? ? ? ?3 MAKE_FUNCTION ? ? ? ? ? ?0 > ? ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 2 (1) > ? ? ? ? ? ? ? ?9 BUILD_LIST ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ? 12 GET_ITER > ? ? ? ? ? ? ? 13 CALL_FUNCTION ? ? ? ? ? ?1 > ? ? ? ? ? ? ? 16 POP_TOP > ? ? ? ? ? ? ? 17 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ? 20 RETURN_VALUE > > Running OP code in 3.0 with print ()s added gives > > pre 0.a 1.b 2.c 3.d ?post > > Traceback (most recent call last): > ? ?File "C:\Programs\Python30\misc\temp7.py", line 32, in > ? ? ?""" % gie) > ? ?File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ > ? ? ?return eval(expr, self.globals, self.locals) > ? ?File "", line 7, in > ? ?File "", line 7, in > ? ?File "C:\Programs\Python30\misc\temp7.py", line 12, in ts > ? ? ?return ts % self > ? ?File "C:\Programs\Python30\misc\temp7.py", line 8, in __getitem__ > ? ? ?return eval(expr, self.globals, self.locals) > ? ?File "", line 2, in > ? ?File "", line 1, in > NameError: global name 'i' is not defined > > > If you manage to run two nested listcomps in the same namespace you get a > > name clash and the inner helper variable overwrites/deletes the outer: > > >>>> def xeval(x): return eval(x, ns) > > ... > >>>> ns = dict(xeval=xeval) > >>>> xeval("[xeval('[k for k in ()]') for i in (1,)]") > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "", line 1, in xeval > > ? File "", line 1, in > > NameError: name '_[1]' is not defined > > Which Python? ?3.0 prints "[[]]"! But I think the nested listcomp *is* > in a separate namespace here. ?I will leave it to you or OP to disect > how his and your code essentially differ from 3.0 (and maybe 2.6) > implementation's viewpoint. I was testing on 2.6, but running it thru 2.4 and 2.5 it seems behaviour is the same there. For 3.0 it does change... and there seems not to be the "_[1]" key defined, and, what's more, it gives a: NameError: name 'j' is not defined. In any case, that was an exploration to get a feeling for how the listcomps behave (performance) if evaluated directly as opposed to doing the equivalent from within a function. It turned out to be slower, so I moved on... but, should it have been faster, then differences between how the different python versions handle list comps internally would have been a next issue to address. I think the globals dict is not touched by eval'ing a list comp... it is any not "constant" as such, just that it is not affected by evaluations (unless the python application decides to affect it in some way or another). But, evaluating a template by definition does not change the globals dict. > Terry Jan Reedy From markus.schreyer at gmail.com Thu Jan 15 18:07:01 2009 From: markus.schreyer at gmail.com (Markus Schreyer) Date: Fri, 16 Jan 2009 00:07:01 +0100 Subject: Import functions in current namespace In-Reply-To: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> References: <50697b2c0901151443x591c4548v9683ad767d18aa30@mail.gmail.com> Message-ID: Wow.. :) I think this is one kind of a stupid question.. ;) Anyway.. thanks a lot.. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Thu Jan 15 18:11:19 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 15 Jan 2009 23:11:19 +0000 Subject: report on building of python 2.5.2 under msys under wine on linux. In-Reply-To: References: Message-ID: > practical decision, due to /bin/sh.exe messing around and stopping > python.exe from running! (under cmd.exe it's fine. i have to do a > bit more investigation: http://bugs.python.org/issue4956 found it. From google at mrabarnett.plus.com Thu Jan 15 18:13:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jan 2009 23:13:53 +0000 Subject: Executing global code In-Reply-To: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> References: <017fb2a6$0$8693$c3e8da3@news.astraweb.com> Message-ID: <496FC331.3070805@mrabarnett.plus.com> Steven D'Aprano wrote: > On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> You have a module containing e. g. these two statements >> >> x = 42 >> x += 1 >> >> and want to rerun it with the effect of x becoming 44? That is not >> possible > > Unless you move the value of x into external storage. Untested: > > > try: > f = open('mystorage.txt', 'r') > except IOError: > x = 42 > else: > x = int(f.read()) > x += 1 > > > Naturally the above is not bulletproof enough for production use. > > I'm curious why the Original Poster wants to do such a thing, and > particularly the prohibition against moving code into a function. > Perhaps there are functions which contain 'global'. Anyway, the solution has already been given, namely put it inside a loop, unless there's soem reason why that's not possible. From bignose+hates-spam at benfinney.id.au Thu Jan 15 18:24:19 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 10:24:19 +1100 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87vdsgb1b0.fsf@benfinney.id.au> Steven D'Aprano writes: > On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > > > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > >> > >> > Familiarize yourself with PEP8 for naming and > >> > coding-conventions first. > >> > >> Enough of the PEP8-fascism please. It is not compulsory to follow > >> PEP8 in order to be allowed to learn Python. > > > > You are responding to something in Diez's message that I can't > > see. Nowhere does he say anything about PEP 8 being compulsory. > > Quite the contrary, he suggests gaining *familiarity* with PEP 8, > > and calls it a set of *conventions*. > > He doesn't *suggest* anything. He uses the imperative case -- it's a > command. Regardless, even if it was an imperial order with government backing, the instruction was not to *follow* PEP 8, but to *become familiar with* it. That isn't fascism, and to read that into it and assume a commandment that Diez didn't make is overreaction on your part. -- \ ?[W]hoever is able to make you absurd is able to make you | `\ unjust.? ?Voltaire | _o__) | Ben Finney From perfreem at yahoo.com Thu Jan 15 18:31:51 2009 From: perfreem at yahoo.com (Per Freem) Date: Thu, 15 Jan 2009 15:31:51 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> thanks to everyone for the excellent suggestions. a few follow up q's: 1] is Try-Except really slower? my dict actually has two layers, so my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where as the bKeys are the ones that are in the millions. so in that case, doing a Try-Except on aKey should be very efficient, since often it will not fail, where as if I do: "if aKey in my_dict", that statement will get executed for each aKey. can someone definitely say whether Try-Except is faster or not? My benchmarks aren't conclusive and i hear it both ways from several people (though majority thinks TryExcept is faster). 2] is there an easy way to have nested defaultdicts? ie i want to say that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact that my_dict is a dictionary, whose values are dictionary that map to ints. but that syntax is not valid. 3] more importantly, is there likely to be a big improvement for splitting up one big dictionary into several smaller ones? if so, is there a straight forward elegant way to implement this? the way i am thinking is to just fix a number of dicts and populate them with elements. then during retrieval, try the first dict, if that fails, try the second, if not the third, etc... but i can imagine how that's more likely to lead to bugs / debugging give the way my code is setup so i am wondering whether it is really worth it. if it can lead to a factor of 2 difference, i will definitely implement it -- does anyone have experience with this? On Jan 15, 5:58?pm, Steven D'Aprano wrote: > On Thu, 15 Jan 2009 23:22:48 +0100, Christian Heimes wrote: > >> is there anything that can be done to speed up this simply code? right > >> now it is taking well over 15 minutes to process, on a 3 Ghz machine > >> with lots of RAM (though this is all taking CPU power, not RAM at this > >> point.) > > > class MyClass(object): > > ? ? # a new style class with slots saves some memory > > ? ? __slots__ = ("field1", "field2", "field2") > > I was curious whether using slots would speed up attribute access. > > >>> class Parrot(object): > > ... ? ? def __init__(self, a, b, c): > ... ? ? ? ? ? ? self.a = a > ... ? ? ? ? ? ? self.b = b > ... ? ? ? ? ? ? self.c = c > ...>>> class SlottedParrot(object): > > ... ? ? __slots__ = 'a', 'b', 'c' > ... ? ? def __init__(self, a, b, c): > ... ? ? ? ? ? ? self.a = a > ... ? ? ? ? ? ? self.b = b > ... ? ? ? ? ? ? self.c = c > ... > > >>> p = Parrot(23, "something", [1, 2, 3]) > >>> sp = SlottedParrot(23, "something", [1, 2, 3]) > > >>> from timeit import Timer > >>> setup = "from __main__ import p, sp" > >>> t1 = Timer('p.a, p.b, p.c', setup) > >>> t2 = Timer('sp.a, sp.b, sp.c', setup) > >>> min(t1.repeat()) > 0.83308887481689453 > >>> min(t2.repeat()) > > 0.62758088111877441 > > That's not a bad improvement. I knew that __slots__ was designed to > reduce memory consumption, but I didn't realise they were faster as well. > > -- > Steven From http Thu Jan 15 18:38:11 2009 From: http (Paul Rubin) Date: 15 Jan 2009 15:38:11 -0800 Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: <7xmydsxhr0.fsf@ruckus.brouhaha.com> Per Freem writes: > 2] is there an easy way to have nested defaultdicts? ie i want to say > that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact > that my_dict is a dictionary, whose values are dictionary that map to > ints. but that syntax is not valid. my_dict = defaultdict(lambda: defaultdict(int)) From db3l.net at gmail.com Thu Jan 15 18:42:05 2009 From: db3l.net at gmail.com (David Bolen) Date: Thu, 15 Jan 2009 18:42:05 -0500 Subject: Python Crashes References: Message-ID: koranthala writes: > Could anyone guide me on this? I have been facing this issue for a > day, and cannot seem to solve it. We had a scheduling system that had a similar "once in a long while hard Windows-process crash" which after a bunch of work to try to track down the source, the most robust solution was just to trap the failure and restart, as the system ran off a persistent state that was already engineering to be robust in the case of a hardware crash (power outage, etc...) While I agree with others that it's most likely a fault in an extension that gets tickled over time, as was likely in our case, we needed all our extensions and were using latest versions at the time. So if your application is such that just restarting it is practical, it may be a sufficient temporary (or not so temporary - our system ran for years this way) workaround for you. What you can do is execute your script from beneath control of another script, and trap process failures, restarting the script on non-standard exits. This can be in addition to any top level exception handling of the child script itself, where it can provide more graceful support for internal failures. The trick, under Windows, is to ensure that you disable any pop-up windows that may occur during the crash, otherwise the monitoring task never gets a chance to get control and restart things. With the pywin32 extension, something like: import win32api, win32con old_mode = win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOGPFAULTERRORBOX | win32con.SEM_NOOPENFILEERRORBOX) Or with ctypes: import ctypes SEM_FAILCRITICALERRORS = 1 SEM_NOGPFAULTERRORBOX = 2 SEM_NOOPENFILEERRORBOX = 0x8000 old_mode = ctypes.windll.kernel32.SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX) at any point prior to starting the child process will ensure that hard process errors will silently terminate the process and return control the parent, as well as not popping up any dialog boxes that require intervention by a person. Should the process exit harshly, the exit code should be fairly clear (I forget, but I think it's in the 0xC000xxxx range, maybe 0xC0000005 for a typical GPF), and you can decide on restarting the task as opposed to just exiting normally. This will also prevent any pop-ups in the main monitoring process. You can restore old behavior there after starting the child by making another call to SetErrorMode using old_mode as the argument. -- David From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 18:43:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jan 2009 23:43:20 GMT Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <49bfcbca-34ae-4243-97c8-9983e563b0a6@n10g2000yqm.googlegroups.com> Message-ID: <017fc0a2$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 14:49:29 -0800, bearophileHUGS wrote: > Matimus, your suggestions are all good. > > Try-except is slower than: > if x in adict: ... else: ... Not according to my tests. >>> def tryexcept(D, key): ... try: ... return D[key] ... except KeyError: ... return None ... >>> def ifinelse(D, key): ... if key in D: ... return D[key] ... else: ... return None ... >>> from timeit import Timer >>> setup = "from __main__ import tryexcept, ifinelse; D = {2: 'c'}" >>> >>> t1 = Timer('tryexcept(D, 2)', setup) >>> t2 = Timer('ifinelse(D, 2)', setup) >>> >>> min(t1.repeat()) # try...except 0.61699414253234863 >>> min(t2.repeat()) # if...else 0.71856999397277832 Perhaps what you meant to say is that try...except is slower *if the key is not found*. And in that case, there's a truly massive difference: >>> t3 = Timer('tryexcept(D, 5)', setup) >>> t4 = Timer('ifinelse(D, 5)', setup) >>> >>> min(t3.repeat()) # try...except 5.3846139907836914 >>> min(t4.repeat()) # if...else 0.5983281135559082 Which solution is faster on average will depend on the ratio of keys found versus keys not found. On my PC, based on the above results, if...else becomes faster when just 2% of keys are not found. But if you can arrange matters so that nearly all keys are found, then try...except can be faster. There's another solution nobody has mentioned (as far as I can see): the get method. In my test I call get() from inside a function, rather than directly, so that the timing results include the function call overhead for all three strategies. >>> def get(D, key): ... return D.get(key) ... >>> >>> setup = "from __main__ import get; D = {2: 'c'}" >>> t5 = Timer('get(D, 2)', setup) >>> t6 = Timer('get(D, 5)', setup) >>> >>> min(t5.repeat()) # found key 0.88362312316894531 >>> min(t6.repeat()) # missing key 0.87782382965087891 -- Steven From lists at cheimes.de Thu Jan 15 19:08:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jan 2009 01:08:57 +0100 Subject: optimizing large dictionaries In-Reply-To: <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: Per Freem schrieb: > 1] is Try-Except really slower? my dict actually has two layers, so > my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions. so in that case, > doing a Try-Except on aKey should be very efficient, since often it > will not fail, where as if I do: "if aKey in my_dict", that statement > will get executed for each aKey. can someone definitely say whether > Try-Except is faster or not? My benchmarks aren't conclusive and i > hear it both ways from several people (though majority thinks > TryExcept is faster). A defaultdict is faster than a try/except if the key is missing. A defaultdict is the canonical way to solve your problem, too. > 3] more importantly, is there likely to be a big improvement for > splitting up one big dictionary into several smaller ones? if so, is > there a straight forward elegant way to implement this? the way i am > thinking is to just fix a number of dicts and populate them with > elements. then during retrieval, try the first dict, if that fails, > try the second, if not the third, etc... but i can imagine how that's > more likely to lead to bugs / debugging give the way my code is setup > so i am wondering whether it is really worth it. > if it can lead to a factor of 2 difference, i will definitely > implement it -- does anyone have experience with this? Nested dicts more likely slower than one large dict. You have to keep in mind that Python's dict have been optimized to utilize the CPU cache as much as possible. Any layer you put on top of a single dict can increase the number of cache misses and increase the number of function calls. This may lead to a general slow down. I assume that you won't notice a slow down. However my instincts tell me that you'll hardly get a speedup, either. You have to roll your own benchmarks to study which algorithm is faster in reality. Christian From gert.cuykens at gmail.com Thu Jan 15 19:14:46 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:14:46 -0800 (PST) Subject: [python3.0] s = sha1(random()).hexdigest() Message-ID: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> from random import random from hashlib import sha1 s = sha1(random()).hexdigest() TypeError: object supporting the buffer API required, How does sha1 work in python3.0 please ? From tjreedy at udel.edu Thu Jan 15 19:20:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 19:20:22 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xmydsw7rj.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <7xmydsw7rj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >> I do not see any connection, really, between what you describe above >> and your desire for static type-checking expressed elsewhere. When I >> was regularly doing analysis of empirical data files, I learned >> (sometimes the hard way, as you describe above) to **ALWAYS** run >> preliminary checks of all fields through the entire file > > Right. And if the file is large enough that even parsing all the > records to check the fields takes hours, well, that's where I'm at. So what is the problem? Let it run overnight. If you want more speed, try numpy or Cython or C functions (swigged or ctyped) or... To guarantee no crashes, make your top level something like for line in open('humongous.dat', 'r'): try: except Exception as e: print(line, e) (How trivial in Python!) If your total system (including electricity supply and busy fingers of other people) is unstable, or you think you might want to interrupt it, keep track of lines or bytes read and write a report every gigabyte or so with enough info to restart from the last checkpoint -- just like reloading your last save in a video game when your avatar dies. Terry Jan Reedy From http Thu Jan 15 19:20:41 2009 From: http (Paul Rubin) Date: 15 Jan 2009 16:20:41 -0800 Subject: [python3.0] s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> Message-ID: <7xy6xcqexy.fsf@ruckus.brouhaha.com> gert writes: > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? sha1 hashes strings, not numbers. Try using str(random()). But if you want some random hex digits, try os.urandom(10).encode('hex') rather than messing with sha1. From gert.cuykens at gmail.com Thu Jan 15 19:21:51 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:21:51 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> Message-ID: <9ed5092f-0242-4b50-b23e-11384ba265d2@f20g2000yqg.googlegroups.com> On Jan 16, 1:14?am, gert wrote: > from random import random > from hashlib import sha1 > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? s = sha1(bytes(random(),'utf-8')).hexdigest() i found this, looks let say strange. But it works :) From gert.cuykens at gmail.com Thu Jan 15 19:34:41 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:34:41 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> Message-ID: <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> On Jan 16, 1:20?am, Paul Rubin wrote: > gert writes: > > s = sha1(random()).hexdigest() > > > TypeError: object supporting the buffer API required, > > > How does sha1 work in python3.0 please ? > > sha1 hashes strings, not numbers. ?Try using str(random()). ?But if > you want some random hex digits, try os.urandom(10).encode('hex') > rather than messing with sha1. s = urandom(10).encode('hex') AttributeError: 'bytes' object has no attribute 'encode' From steve at REMOVE-THIS-cybersource.com.au Thu Jan 15 19:41:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 00:41:15 GMT Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> Message-ID: <017fce36$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> >> >> > Familiarize yourself with PEP8 for naming and coding-conventions >> >> > first. >> >> >> >> Enough of the PEP8-fascism please. It is not compulsory to follow >> >> PEP8 in order to be allowed to learn Python. >> > >> > You are responding to something in Diez's message that I can't see. >> > Nowhere does he say anything about PEP 8 being compulsory. Quite the >> > contrary, he suggests gaining *familiarity* with PEP 8, and calls it >> > a set of *conventions*. >> >> He doesn't *suggest* anything. He uses the imperative case -- it's a >> command. > > Regardless, even if it was an imperial order with government backing, > the instruction was not to *follow* PEP 8, but to *become familiar with* > it. That isn't fascism, and to read that into it and assume a > commandment that Diez didn't make is overreaction on your part. Okay, fair enough, I made a mistake in saying "It is not compulsory to follow PEP8". What I should have said was "It is not compulsory to become familiar with PEP8". Now that you've put me in my place, can we please get back to becoming a hostile and unforgiving place for newbies who dare to try learning Python without first becoming familiar with PEP8? *wink* Seriously, I'll accept a small rebuke. My choice of the word "fascism" was poor, and I regret it. In my defense, I thought it was better than my initial thought, which was "style-Nazi", but in hindsight given the proliferation of somewhat tongue-in-cheek foo-Nazi terms (soup-Nazi, grammar-Nazi, fashion-Nazi, etc.) maybe I should have stuck with it. But by focusing on such a small aspect of my post (a quarter of my text), while ignoring the more substantial aspects, it seems that you are giving tacit approval of precisely the attitude I am objecting to: that there is a One True And Correct Right Way to learn and/or use Python. For a community that celebrates the dynamism of the language, and supports giving the programmer the ability to shoot themselves in the foot ("we're all adults here"), we can sometimes be remarkably intolerant of things which are a matter of taste. Sometimes it seems that there's a Party line, and individuals can be criticized for failing to be enthusiastic enough about supporting it. This is a good example: it isn't enough that I agreed with Diez's substantial point that PEP8 is a good thing; it isn't enough that I made it more likely that the OP would find and read PEP8 by posting a link to it; but by making a mild criticism of *the way* Diez introduced PEP8 to the newbie, *I'm* the bad guy. -- Steven From kylotan at gmail.com Thu Jan 15 19:47:39 2009 From: kylotan at gmail.com (Ben Sizer) Date: Thu, 15 Jan 2009 16:47:39 -0800 (PST) Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> Message-ID: <965ac14d-3a1d-4a00-bc94-6d09f2490d67@v42g2000yqv.googlegroups.com> On Jan 14, 4:37 pm, Ivan Illarionov wrote: > On Jan 14, 1:49 pm, Ben Sizer wrote: > > > No, I don't want to do anything with sys.path apart from see it. I > > just wanted my original question answered, not a guess at my intent > > and a solution for something I'm not doing. ;) Thanks though! > > > Again - why can I not reference sys from within the function? > > Ah, sorry for wrong guess. > > I would try to use ourNamespace_ dict for > both globals and locals in PyRun_String call. Yes, this seems to fix it, thanks. But why? Can some Python guru explain why these two dictionaries must be the same? (Or what steps we must take if we want them to be separate?) The documentation is not very clear. I had hoped to be able to clear out the locals dictionary while leaving useful functions intact in the globals dictionary, but it would appear that is not practical. (On a separate note, while trying to debug this it seemed that Python will look for debug versions of a library when you embed it in debug mode, and will fail to find a module if you only have the release versions there. The error message you get isn't too helpful about this however, and I only worked it out by looking at the very long list of filesystem calls Python made to try and find it. Anybody wishing to speed up import times might want to ensure they don't have a long Python path and as few eggs in site-packages as possible.) -- Ben Sizer From gert.cuykens at gmail.com Thu Jan 15 19:47:57 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 16:47:57 -0800 (PST) Subject: except sqlite3.Error as e: Message-ID: <3260e889-a641-4435-bcef-8f60dfdfda2e@z1g2000yqn.googlegroups.com> except sqlite3.Error as e: ERROR = "Error " + ... how does except work in python3 ? From benlucas99 at googlemail.com Thu Jan 15 19:59:54 2009 From: benlucas99 at googlemail.com (benlucas99 at googlemail.com) Date: Thu, 15 Jan 2009 16:59:54 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect Message-ID: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> I'm having problems with the ordering of the tuples produced by urllib.urlencode. Taking an example straight from the docs and so doing the following: import urllib ... params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) print params The documentation for urlencode( query[, doseq]) says: "The order of parameters in the encoded string will match the order of parameter tuples in the sequence" but I'm getting: "eggs=2&bacon=0&spam=1" Should this not produce: "spam=1&eggs=2&bacon=0" ? I am seeing this "incorrect" result using Python 2.5.1 and ActivePython 2.3.2 (both on XP SP2). What am I doing wrong? I've been googling around for an answer but I'm a Python newbie and so don't know the ropes yet. Thanks for any help. Ben From musicguy at alphaios.net Thu Jan 15 20:02:55 2009 From: musicguy at alphaios.net (The Music Guy) Date: Thu, 15 Jan 2009 19:02:55 -0600 Subject: English-like Python Message-ID: <1232067775.15931.25.camel@localhost> Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a programming language which is actually a spoken one. For example, the following code... >>> import os >>> >>> def list_files(dirname): >>> for p in os.listdir(dirname): >>> print p >>> >>> list_files("some_dir") foo bar etc ...might be translated as... >>> Import the operating system module. >>> >>> Define a new function as "list files" which accepts "a path" and does the following: For every item in the list returned by the operating system's directory listing of the given path, do the following: Print the item. >>> >>> List files from "some_dir". foo bar etc Obviously, creating a parser capable of handling such "code" would require a very good understanding not only of the English language but also of how ideas expressed in spoken languages are represented in terms that a computer can understand. A language like this would, of course, blow a lot of staple coding coding concepts like "variables," "objects," etc. right out of the water. I think, however, that it could be done, and wouldn't necessarily have to be any slower than any other scripting language as any text/code could be cached as bytecode, just like Python. I know it's sort of silly but I think something like this would be very interesting, maybe even useful. ^_^ -- http://Alphaios.net - Tracked Module Music, Blog, and Links. From gert.cuykens at gmail.com Thu Jan 15 20:03:50 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 15 Jan 2009 17:03:50 -0800 (PST) Subject: except sqlite3.Error as e: References: <3260e889-a641-4435-bcef-8f60dfdfda2e@z1g2000yqn.googlegroups.com> Message-ID: <5f2a2479-5f32-44e7-8c73-208fac14263a@13g2000yql.googlegroups.com> On Jan 16, 1:47?am, gert wrote: > except sqlite3.Error as e: > ? ? ERROR = "Error " + ... > > how does except work in python3 ? except sqlite3.Error as e: ERROR = "Error " + e.args[0] oops i thought it did not work somehow in 3.0 but it does :) From dougjrs at gmail.com Thu Jan 15 20:04:58 2009 From: dougjrs at gmail.com (DougJrs) Date: Thu, 15 Jan 2009 17:04:58 -0800 (PST) Subject: Soap Client Message-ID: <5947e87e-7679-4121-98f0-b77b2ae56be4@13g2000yql.googlegroups.com> Good Evening Everyone, I am working to create a Soap client in Python using wsdl2py. So far I have been pretty successful in creating most of the client, but I am having trouble figuring out how to change the content of the message that is being sent. After running wsdl2py I have created this client code: import OnlineQuery_client as QC loc QC.QueryLocator() srv = loc.getOnlineQuerySoap() msg = QC.querySoapIn() rep = srv.query(msg) I would like to change the message that is being sent to something like this (soap headers excluded below, but they would be in the actual message, and the xml would be escaped.) "1". wsdl2py created the code below in OnlineQuery_client.py: "querySoapIn = GED("http://eventquery.org/", "query", "test").pyclass" So, can anyone point me in the right direction as to how I would change the message that is being sent? I have tried a couple of different combinations, but so far I have not been successful in creating the messages that I want. Any help is appreciated, Doug From bignose+hates-spam at benfinney.id.au Thu Jan 15 20:13:18 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 12:13:18 +1100 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87r634aw9d.fsf@benfinney.id.au> Steven D'Aprano writes: > But by focusing on such a small aspect of my post (a quarter of my > text), It clearly was important to you, since you phrased it in highly emotive terms (and even, by your account, had to scale the emotion back a little). So, I don't think the proportion of number-of-characters is relevant there. > while ignoring the more substantial aspects Sure, I took that one part and made a new topic from it. This is open discussion, man. I even changed the subject field to be clear :-) > it seems that you are giving tacit approval of precisely the > attitude I am objecting to: that there is a One True And Correct > Right Way to learn and/or use Python. Nope. -- \ ?Madness is rare in individuals, but in groups, parties, | `\ nations and ages it is the rule.? ?Friedrich Nietzsche | _o__) | Ben Finney From google at mrabarnett.plus.com Thu Jan 15 20:25:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 01:25:39 +0000 Subject: Ordering of urlencoded tuples incorrect In-Reply-To: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: <496FE213.6010005@mrabarnett.plus.com> benlucas99 at googlemail.com wrote: > I'm having problems with the ordering of the tuples produced by > urllib.urlencode. Taking an example straight from the docs and so > doing the following: > > import urllib > ... > params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > print params > > The documentation for urlencode( query[, doseq]) says: "The order of > parameters in the encoded string will match the order of parameter > tuples in the sequence" but I'm getting: > > "eggs=2&bacon=0&spam=1" > > Should this not produce: "spam=1&eggs=2&bacon=0" ? > > I am seeing this "incorrect" result using Python 2.5.1 and > ActivePython 2.3.2 (both on XP SP2). What am I doing wrong? I've > been googling around for an answer but I'm a Python newbie and so > don't know the ropes yet. > You're passing a dict, which is unordered. It will accept a tuple or list of 2-tuples or a dict: >>> # tuple of 2-tuples >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) 'spam=1&eggs=2&bacon=0' >>> >>> # list of 2-tuples >>> urllib.urlencode([('spam', 1), ('eggs', 2), ('bacon', 0)]) 'spam=1&eggs=2&bacon=0' >>> >>> # dict >>> urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) 'eggs=2&bacon=0&spam=1' but I doubt the order will matter in practice. From tjreedy at udel.edu Thu Jan 15 20:28:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jan 2009 20:28:38 -0500 Subject: Alphametric fun with Python In-Reply-To: References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Raymond Hettinger: >> for simple programs that take minutes to write and get the job done. Thank you for posting this. It illustrates well the point you intended. > For fun here's a specific example: > > from csp import Problem, timing > print "SEND+MORE=MONEY problem:" > p = Problem("recursivebacktracking") > p.addvars("sendmory", range(10)) > p.addrule(lambda d,e,y: (d+e)%10 == y) # alternative syntax > p.addrule("(n*10+d+r*10+e)%100 == e*10+y") This effectively include the first rule and makes it redundant in a way. Better, I expect (but leave to you to check), would be (n*10+d+r*10+e)%100 / 10 == e > p.addrule("(e*100+n*10+d+o*100+r*10+e)%1000 == n*100+e*10+y") (e*100+n*10+d+o*100+r*10+e)%1000 / 100 == n > p.addrule("1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e == 10000*m+1000*o > +100*n+10*e+y") temp = 1000*s+100*e+10*n+d + 1000*m+100*o+10*r+e temp%10000 / 1000 == o temp / 10000 == m > p.notin([0], "sm") > p.alldifferent() > solutions, time = timing(p.solutions) > print "Computing time:", time, "s" > for s in solutions: > print "%(s)d%(e)d%(n)d%(d)d + %(m)d%(o)d%(r)d%(e)d = %(m)d%(o)d%(n) > d%(e)d%(y)d" % s > print Given 'expression == char' for each column, the equalities could be turned into assignments (or checks). For every possible assignment to d and e, let y = (d+e) % 10. For every possible assignment of unused numbers to unbound chars in the second column expression, let e = (n*10+d+r*10+e)%100 / 10 To generalize, 0 pad all lines to match the sum. Then each nested loop can be expressed in more detail as for each possible assignment of unused numbers to unbound chars in column_i: # break if none possible div = 10**i num = column_0_to_i_sum % (10*div) / div if sum[i]_char is not bound: > Probably it's not too much difficult to write a code able to solve a > more general alphametric problem: Hmm. For alphametric problems specifically, 'expression == char' for each column could be turned into assignments (or checks). 0 pad all lines to match the sum. Then nest column loops right to left. for each possible assignment of unused numbers to unbound chars in column_i: # include non-zero constraint and break if none possible div = 10**i num = column_0_to_i_sum % (10*div) / div if sum[i]_char is not bound: bind to num else: check that is num and break if not if last (leftmost) column: print solution else loop on column to left Terry Jan Reedy From ajaksu at gmail.com Thu Jan 15 20:30:25 2009 From: ajaksu at gmail.com (ajaksu) Date: Thu, 15 Jan 2009 17:30:25 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> Message-ID: <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> On Jan 15, 8:21?pm, mario ruggier wrote: > OK! Here's a small script to make it easier... Thanks! I think I found a quick way around the restrictions (correct me if I borked it), but I think you can block this example by resetting your globals/builtins: exprs = [ '(x for x in range(1)).gi_frame.f_globals.clear()', 'open("where_is_ma_beer.txt", "w").write("Thanks for the fun ")' ] Regards, Daniel From rhodri at wildebst.demon.co.uk Thu Jan 15 20:41:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 16 Jan 2009 01:41:09 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xk58wwlaj.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> <7xk58wwlaj.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 17:07:00 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Luis Zarrabeitia writes: >> No, copy and paste from the original data structures would eliminate >> those >> mismatches. > > The whole point is that would be possible if Python had data structure > definitions ("types") that were possible to copy and paste from some > single location, instead of building up structures dynamically, adding > fields on the fly in ways that have become obscure over the evolution > of the code. mutter mutter __slots__ mutter mutter It strikes me that what you actually want to write is the script that scans your C data structure and spits out a Python class or module that implements it with whatever degree of checking you want. That should make writing your actual data munger safer and faster, if I'm understanding you correctly. -- Rhodri James *-* Wildebeeste Herder to the Masses From sjmachin at lexicon.net Thu Jan 15 20:44:18 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 15 Jan 2009 17:44:18 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: On Jan 16, 11:59?am, benluca... at googlemail.com wrote: > I'm having problems with the ordering of the tuples produced by > urllib.urlencode. ?Taking an example straight from the docs and so > doing the following: What are "the docs" you are reading that include such an example? The docs distributed with Python 2.5.1 from www.python.org have only this: """ urlencode( query[, doseq]) Convert a mapping object or a sequence of two-element tuples to a ``url-encoded'' string, suitable to pass to urlopen() above as the optional data argument. This is useful to pass a dictionary of form fields to a POST request. The resulting string is a series of key=value pairs separated by "&" characters, where both key and value are quoted using quote_plus() above. If the optional parameter doseq is present and evaluates to true, individual key=value pairs are generated for each element of the sequence. When a sequence of two- element tuples is used as the query argument, the first element of each tuple is a key and the second is a value. The order of parameters in the encoded string will match the order of parameter tuples in the sequence. The cgi module provides the functions parse_qs() and parse_qsl() which are used to parse query strings into Python data structures. """ > > ? ? ? ? import urllib > ? ? ? ? ... > ? ? ? ? params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > ? ? ? ? print params > > The documentation for urlencode( query[, doseq]) says: "The order of > parameters in the encoded string will match the order of parameter > tuples in the sequence" but I'm getting: "query" can be either a mapping object (e.g. a dictionary, as you have used) or a sequence of 2-tuples. No such guarantee as you quote above can be made for a mapping; mappings are just not orderable. If you want order, give it a sequence, like this: | >>> import urllib | >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) | 'spam=1&eggs=2&bacon=0' HTH, John From castironpi at gmail.com Thu Jan 15 20:49:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 15 Jan 2009 17:49:36 -0800 (PST) Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> Message-ID: <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> On Jan 15, 6:41?pm, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > >> >> > Familiarize yourself with PEP8 for naming and coding-conventions > >> >> > first. > > >> >> Enough of the PEP8-fascism please. It is not compulsory to follow > >> >> PEP8 in order to be allowed to learn Python. > > >> > You are responding to something in Diez's message that I can't see. > >> > Nowhere does he say anything about PEP 8 being compulsory. Quite the > >> > contrary, he suggests gaining *familiarity* with PEP 8, and calls it > >> > a set of *conventions*. > > >> He doesn't *suggest* anything. He uses the imperative case -- it's a > >> command. > > > Regardless, even if it was an imperial order with government backing, > > the instruction was not to *follow* PEP 8, but to *become familiar with* > > it. That isn't fascism, and to read that into it and assume a > > commandment that Diez didn't make is overreaction on your part. > > Okay, fair enough, I made a mistake in saying "It is not compulsory to > follow PEP8". What I should have said was "It is not compulsory to become > familiar with PEP8". People are sensitive in differing amounts to the imperative case. I'm really sensitive to it, and I appreciate it when people say *plonk* instead of *lonk*. Diez took an authoritarian posture with the imperative. Instead of saying what benefit the OP would get from complying, the subtext in such cases is, "I'm in charge. If you haven't heard of me, get out. Do what I say, or get out." That might be extreme, but you'd be hard pressed to defend an interpretation of what he said to be, "One good option is to skim PEP 8 early. It has a low-maintenance, long-term benefit." It's much more common to use an imperative in a chain of command, as in "Swab the deck", or "Convert the heathens", where a task is critical to a collective mission, or, regrettably, in reminding people who has the gun, such as in an enforced hierarchy. There is no chain of command or gun in the Python community (that I've found), at least outside of the core devs, which I can't attest to. IMO, it's most likely Diez was performing a hazing ritual on a newcomer, that he'd forgotten he didn't like when he did it. > Now that you've put me in my place, can we please get back to becoming a > hostile and unforgiving place for newbies who dare to try learning Python > without first becoming familiar with PEP8? Let us compose odes and sonnets to its glory. (Imperative.) > *wink* > > Seriously, I'll accept a small rebuke. My choice of the word "fascism" > was poor, and I regret it. In my defense, I thought it was better than my > initial thought, which was "style-Nazi", but in hindsight given the > proliferation of somewhat tongue-in-cheek foo-Nazi terms (soup-Nazi, > grammar-Nazi, fashion-Nazi, etc.) maybe I should have stuck with it. You could probably stick with 'style police', as in 'fashion police', as in, "Don't worry about Diez, he's the self-appointed style police". Sorry, heard it on t.v. once. > But by focusing on such a small aspect of my post (a quarter of my text), > while ignoring the more substantial aspects, it seems that you are giving > tacit approval of precisely the attitude I am objecting to: that there is > a One True And Correct Right Way to learn and/or use Python. Not only is there One True And Correct Right Way(tm), but I'm the only one who knows what it is. > For a community that celebrates the dynamism of the language, and > supports giving the programmer the ability to shoot themselves in the > foot ("we're all adults here") For what definition of 'here'? > we can sometimes be remarkably intolerant > of things which are a matter of taste. -- Your code tastes funny. -- Stop chewing it and swallow. (Imperative.) > Sometimes it seems that there's a > Party line, and individuals can be criticized for failing to be > enthusiastic enough about supporting it. This is a good example: it isn't > enough that I agreed with Diez's substantial point that PEP8 is a good > thing; it isn't enough that I made it more likely that the OP would find > and read PEP8 by posting a link to it; but by making a mild criticism of > *the way* Diez introduced PEP8 to the newbie, *I'm* the bad guy. I think you're ignoring the diversity of backgrounds that people from around the world can have. Maybe in Diez's past lives, friends just roughhouse and show acceptance and affection by using imperatives. Maybe it is a bellowed 'WELCOME!', instead of an unchecked power bid. > Steven Ever find it hard to get personal with a newsgroup? A. Brady P.S. Not that questions are any better. From rhodri at wildebst.demon.co.uk Thu Jan 15 20:55:19 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 16 Jan 2009 01:55:19 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjkwkze.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> <7xwscx6zfo.fsf@ruckus.brouhaha.com> <7xfxjkwkze.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 15 Jan 2009 17:13:41 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Roy Smith writes: >> C is not evil. It's a tool. Would you call a hammer evil because it's >> not >> very good at driving screws? > > I would call a hammer evil if it were built in a way that made it > unnecessarily likely to hit your thumb. But is that because the hammer is misdesigned, because you're holding the nail all wrong, or because you're actually holding a screw? >> C is a very good tool for doing the kind of thing it was designed >> for, which is highly efficient, low-level, portable programming. Um. It wasn't designed for portability, or if it was, it wasn't designed for portability very well. Then again, what makes for good portability at the level C works best at -- macroassembly -- is not an easy question to answer given how variable your environment can be. >> The fact that C has been used to write all sorts of large-scale >> applications doesn't mean that it's good at that kind of stuff. It just >> means that all the alternatives suck more than it does for that kind of >> stuff. > > I don't think so: http://www.adaic.org/whyada/ada-vs-c/cada_art.html I agree. I suspect that its more the case that once most programmers have been taught how to use the hammer that is C, all problems look like nails. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhamph at gmail.com Thu Jan 15 21:01:25 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 15 Jan 2009 18:01:25 -0800 (PST) Subject: Python 3 isinstance References: Message-ID: <6210055d-b6f8-488a-aa0d-8d76ea79bc62@g38g2000yqd.googlegroups.com> On Jan 14, 3:14?pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The real problem is it would be misleading. isinstance(a, myset) suggests implementation like type(a) in myset, but it's really any (isinstance(a, t) for t in myset). If myset is arbitrarily large (as the examples suggest), and you're checking on every call, the code would be so slow as to be considered broken. This invalidates the use case. The abc module in 2.6/3.0 is a possible alternative. Create an ABC type, register each type in myset as part of it, then do isinstance(a, MyABC). Internally the ABC will cache lookups, effectively getting you back to O(1) cost. From ambient.sounds at gmail.com Thu Jan 15 21:42:37 2009 From: ambient.sounds at gmail.com (Mark Hahnenberg) Date: Thu, 15 Jan 2009 18:42:37 -0800 (PST) Subject: Lazy List Generator Problem Message-ID: <8ce100f6-ca7d-4de3-8965-56ba042cedf8@w34g2000yqm.googlegroups.com> I'm trying to make a lazy, (theoretically) infinite prime number sieve using generators. The code I have thus far is: #!/usr/bin/env python import itertools def sieve(): nats = naturals(2) while True: elem = nats.next() yield elem nats = itertools.ifilterfalse(lambda x: x % elem == 0, nats) def naturals(start=1): curr = start while True: yield curr curr += 1 primes = sieve() i = 0 while i < 10: print primes.next() i += 1 When I execute this code, the numbers 2,3,4,...,11 are printed (i.e. nothing gets filtered out). Could anyone explain why this is happening? I generally understand generators, and my hypothesis is that reassigning to nats the result of filtering nats could be screwing things up somehow, but I've tried a variety of other methods, from making copies of the old iterator to rolling my own filter function and nothing has worked. Thanks, -MRH From mdw at distorted.org.uk Thu Jan 15 21:50:23 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 16 Jan 2009 02:50:23 +0000 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <873afkqpbf.fsf.mdw@metalzone.distorted.org.uk> <7bd6ef74-8608-489b-bea5-dd243bf0c803@x38g2000yqj.googlegroups.com> Message-ID: <87k58wotg0.fsf.mdw@metalzone.distorted.org.uk> mario ruggier writes: > 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' > object has no attribute 'func_globals': File "", line 1, in > Damn. So that doesn't work. :-( > But even if inspect did have the func_globals attribute, the "open" > builtin will not be found on __builtins__ (that is cleaned out when > restricted=True). Irrelevant. I wasn't trying to get at my __builtins__ but the one attached to a function I was passed in, which has a different environment. You define a function (a method, actually, but it matters little). The function's globals dictionary is attached as an attribute. You didn't do anything special here, so the globals have the standard __builtins__ binding. It contains open. You now run my code in a funny environment with a stripped-down __builtins__. But that doesn't matter, because my environment contains your function. And that function has your __builtins__ hanging off the side of it. ... but I can't actually get there because of f_restricted. You don't mention the fact that Python magically limits access to these attributes if __builtins__ doesn't match the usual one, so I think you got lucky. -- [mdw] From tim--at-- at frontier--dot--.net Thu Jan 15 21:59:23 2009 From: tim--at-- at frontier--dot--.net (Tim H) Date: Thu, 15 Jan 2009 19:59:23 -0700 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: r wrote: > On Jan 14, 4:43 pm, Terry Reedy wrote: > [snip] >> I think the 'main' IDLE maintainer is no longer active. I think someone >> who would do more than fix critical bugs might be welcome. > > Hello Terry, > That's what i was beginning to think. I am not quite ready (as far as > my skills are concerned) to put out something that would be as useful > to many people. I could hack together something real quick for myself. > This is why i am looking for like-minded people who would be > interested in this. I have the foresight and willpower at this point > to contribute something meaningful to the Python community -- to give > back. > > OFF-TOPIC:(but related) > What is the state of Tkinter at this point. Is an active effort under > way to port TK 8.5 into Python? Tkinter and IDLE are very important to > Python, but i understand there are much more important areas where the > GURU's are concentrating. Should there be a calling for "others" to > get involved here? I would like to help out. > Thanks Maybe I'm misunderstanding something here, but "About Idle" in Python 2.6.1 (win32) says "Tk version: 8.5" From ptmcg at austin.rr.com Thu Jan 15 22:01:43 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 15 Jan 2009 19:01:43 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> Message-ID: On Jan 15, 5:31?pm, Per Freem wrote: > ...the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions. ?so in that case, > doing a Try-Except on aKey should be very efficient, since often it > will not fail, ... Do you know the aKeys in advance? If so, then just initialize the first layer, and it will never fail. -- Paul From skip at pobox.com Thu Jan 15 22:30:34 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 15 Jan 2009 21:30:34 -0600 Subject: spam on the list - how are things now? Message-ID: <18799.65370.92932.642056@montanaro.dyndns.org> We've been running SpamBayes on the news-to-mail gateway on mail.python.org for a couple weeks now. To me it seems like the level of spam leaking onto the list has dropped way down but I'd like some feedback from people who read the python-list at python.org mailing list on the topic. Thanks, -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From prologic at shortcircuit.net.au Thu Jan 15 22:37:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 13:37:06 +1000 Subject: process/thread instances and attributes In-Reply-To: References: <496F03B9.8090100@shopzeus.com> Message-ID: After some work ... I've taken Laszlo's suggestion of using Value (shared memory) objects to share state between the -pseudo- Process (manager) object and it's underlying multiprocessing.Process instance (and subsequent process): Here is the code: ---------------------------------------- #!/usr/bin/env python import os from time import sleep from threading import activeCount as threads from threading import Thread as _Thread from multiprocessing import Value from multiprocessing import Process as _Process from multiprocessing import active_children as processes class Process(object): def __init__(self, *args, **kwargs): super(Process, self).__init__(*args, **kwargs) self.running = Value("b", False) self.thread = _Thread(target=self.run) self.process = _Process(target=self._run, args=(self.running,)) def _run(self, running): self.thread.start() try: while running.value: try: sleep(1) print "!" except SystemExit: running.acquire() running.value = False running.release() break except KeyboardInterrupt: running.acquire() running.value = False running.release() break finally: running.acquire() running.value = False running.release() self.thread.join() def start(self): self.running.acquire() self.running.value = True self.running.release() self.process.start() def run(self): pass def stop(self): print "%s: Stopping ..." % self self.running.acquire() self.running.value = False self.running.release() def isAlive(self): return self.running.value class A(Process): def run(self): while self.isAlive(): sleep(5) self.stop() a = A() a.start() N = 0 while a.isAlive(): sleep(1) print "." print "threads: %d" % threads() print "processes: %d" % len(processes()) print "DONE" ---------------------------------------- Here is the result of running this: ---------------------------------------- $ python test3.py ! . threads: 1 processes: 1 . threads: 1 processes: 1 ! ! . threads: 1 processes: 1 . threads: 1 processes: 1 ! . threads: 1 processes: 1 ! <__main__.A object at 0x80de42c>: Stopping ... ! . threads: 1 processes: 0 DONE ---------------------------------------- This appears to work as I intended. Thoughts / Comments ? cheers James From prologic at shortcircuit.net.au Thu Jan 15 22:39:39 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 13:39:39 +1000 Subject: spam on the list - how are things now? In-Reply-To: <18799.65370.92932.642056@montanaro.dyndns.org> References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: On Fri, Jan 16, 2009 at 1:30 PM, wrote: > We've been running SpamBayes on the news-to-mail gateway on mail.python.org > for a couple weeks now. To me it seems like the level of spam leaking onto > the list has dropped way down but I'd like some feedback from people who > read the python-list at python.org mailing list on the topic. Agreed. It has gone down. Thank you for taking the time to do something about it :) cheers James From waynehuang.public at gmail.com Thu Jan 15 22:56:23 2009 From: waynehuang.public at gmail.com (Wayne Huang) Date: Fri, 16 Jan 2009 11:56:23 +0800 Subject: One Bug of Python 3.0 Message-ID: I met a bug of CGIXMLRPCRequestHandler in Python3.0. Because of the bug, I couldn't use RPC in Apache CGI. The version of my Python 3.0 is "Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] win32". The code of my client is follow. s = xmlrpc.client.ServerProxy('http://localhost/cgi-bin/rpc.py') print(s.system.listMethods()) The code of my server in Apache's cgi-bin is follow #!C:/Python30/python.exe from xmlrpc.server import * handler=CGIXMLRPCRequestHandler() handler.register_introspection_functions() handler.handle_request() When I run the client code,some error of parser raise. I found it is the matter of 'Content-Length' in the HTTP Response of CGIXMLRPCRequestHandler,it is a wrong number. I don't know how to handle the problem. Wait for your help. Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From cma at mail.bnu.edu.cn Thu Jan 15 22:59:29 2009 From: cma at mail.bnu.edu.cn (Cong Ma) Date: Fri, 16 Jan 2009 11:59:29 +0800 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Terry Reedy wrote: > Not to me. You are using the module as a singleton class. The > alternative is to write a class, make the functions methods, and > instantiate the class. If that instance must be a singleton, more work > is required. If multiple instances make sense, you can go the class > route when you need to. I've thought of this too, but it turns out those functions are related to each other very loosely. They do a lot of completely different things independently and have just one common global variable to share. IMHO it would reduce the readability of code because the role of this class is very unclear. Anyway, "readability" is mostly a subjective matter and I think what you pointed out is a good idea in general. >> For example: >> >> @global_injected("SPAM") >> def foo(): >> ... ... >> >> will have the same effect as >> >> def foo(): >> global SPAM >> ... ... > > More keystrokes for no gain. That's intended. I want these "evil" (or "foolish and senseless") functions to "stand out" in the sourcecode. They have their evil marks right before the definition, not buried in the function body. > Decorators are usally intended to wrap the input function with another > function. But they can be used to modify the input function and return > it altered. The latter is what you are proposing. > > You of course have to use SPAM as a local variable. Then you might be > able to write an implementation-specific convert_to_global(name) > function that would rewrite the code part of the code object of the > function to what it would have been had you been sensible and used the > 'global' directive. This would mean finding the code that loads and > stores 'SPAM' as a local variable and convert is to code that loads and > stores it as a global variable. If the replacement takes more bytes > than the original, then the jump offsets all have to be fixed. Also > needing fixing would be the line number table that is used to match code > units to lines in the Python code for error tracebacks. > > An alterntive would be to de-compile the code, insert the global > directive, and recompile. A non-decorator alternative would be to write > a function with two parameters that takes a tuple of names and the code > quoted as a string as arguments. It would insert the global statement > into the string, execute it, and return the function. Thank you for your elaborate explanation :) Regards, Cong. From prologic at shortcircuit.net.au Thu Jan 15 23:08:19 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 14:08:19 +1000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 4:28 AM, Cong Ma wrote: > I'd appreciate your hints on this problem. I'm writing a module in which several > functions can alter the value of a global variable (I know this sounds evil, > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lines in those functions' bodies and to use a decorator for the same task. For > example: > > @global_injected("SPAM") > def foo(): > ... ... > > will have the same effect as > > def foo(): > global SPAM > ... ... > > Leaving the evilness of globals aside, I wonder how I can implement this (for > Python 2.x). I'd like to hear your opinions. Thank you. This is identical behavior to that of a class/object. Please explain why you _really_ need to do this ? class Foo(object): def __init__(self): self.spam = None def foo(self): self.spam = "Eggs" def bar(self): self.spam = "Bacon" cheers James From prologic at shortcircuit.net.au Thu Jan 15 23:13:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 14:13:05 +1000 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 1:59 PM, Cong Ma wrote: > I've thought of this too, but it turns out those functions are related to each > other very loosely. They do a lot of completely different things independently > and have just one common global variable to share. IMHO it would reduce the > readability of code because the role of this class is very unclear. Anyway, > "readability" is mostly a subjective matter and I think what you pointed out is > a good idea in general. So then the other commonly used pattern is a shared object between two other objects. class Env(object): def __init__(self): self.spam = None class A(object): def __init__(self, env): self.env = env def __call__(self): self.env.spam = "Eggs" class B(object): def __init__(self, env): self.env = env def __call__(self): self.env.spam = "Bacon" Very readable and makes perfect sense if it suits you. cheers James From wuwei23 at gmail.com Thu Jan 15 23:42:35 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 15 Jan 2009 20:42:35 -0800 (PST) Subject: Lazy List Generator Problem References: <8ce100f6-ca7d-4de3-8965-56ba042cedf8@w34g2000yqm.googlegroups.com> Message-ID: On Jan 16, 12:42?pm, Mark Hahnenberg wrote: > When I execute this code, the numbers 2,3,4,...,11 are printed (i.e. > nothing gets filtered out). ?Could anyone explain why this is > happening? ?I generally understand generators, and my hypothesis is > that reassigning to nats the result of filtering nats could be > screwing things up somehow, but I've tried a variety of other methods, > from making copies of the old iterator to rolling my own filter > function and nothing has worked. Hey Mark, I think the issue isn't that 'nats' is changing, but that 'elem' is. Try replacing this: > nats = itertools.ifilterfalse(lambda x: x % elem == 0, nats) with this: nats = itertools.ifilterfalse(lambda x, elem=elem: x % elem == 0, nats) Which works for me: In [91]: s = sieve() In [92]: primes_10 = [s.next() for x in xrange(10)] In [93]: primes_10 Out[93]: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Hope this helps. From http Thu Jan 15 23:43:25 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:43:25 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <946c232e-3040-4b63-af1a-7d864cf497ff@i18g2000prf.googlegroups.com> <7xwscwh3cr.fsf@ruckus.brouhaha.com> <1e9b889a-0899-451f-af21-9ce9b3e0817d@t39g2000prh.googlegroups.com> <7xocy8v4be.fsf@ruckus.brouhaha.com> <7xmydsw7rj.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhrg8sy.fsf@ruckus.brouhaha.com> Terry Reedy writes: > > Right. And if the file is large enough that even parsing all the > > records to check the fields takes hours, well, that's where I'm at. > > So what is the problem? Let it run overnight. The idea of buying faster and faster computers is to not have to wait overnight. The sooner you can get the results (preferably within minutes not hours), the sooner they can be used in the next task, which depends on them. Language implementation affects program speed just as hardware does, thus the grumbling about Python being slow. > If you want more > speed, try numpy or Cython or C functions (swigged or ctyped) or... I should try out Cython. Using plain C would slow down development an awful lot. Either way would require putting most of the logic in C to get the best speedup, since it would require building Python-unfriendly data structures (the natural Pythonic structures use a huge amount of dict lookups and storage allocation/release). > for line in open('humongous.dat', 'r'): > try: > > > except Exception as e: > print(line, e) > > (How trivial in Python!) It's a little more complicated than that since multiple threads are involved, and "except Exception" is considered an antipattern, but yeah, I'm already doing stuff like this. From http Thu Jan 15 23:44:08 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:44:08 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <7xeiz5gvfs.fsf@ruckus.brouhaha.com> <7xk58wwlaj.fsf@ruckus.brouhaha.com> Message-ID: <7xvdsfg8rr.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > It strikes me that what you actually want to write is the script that > scans your C data structure There is not a C data structure at the moment. It's all Python. From http Thu Jan 15 23:46:16 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:46:16 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> Message-ID: <7xr633g8o7.fsf@ruckus.brouhaha.com> gert writes: > s = urandom(10).encode('hex') > AttributeError: 'bytes' object has no attribute 'encode' Oh, Python 3. It's done some different way, someone else will have to specify. I'm still using 2.x. From http Thu Jan 15 23:47:07 2009 From: http (Paul Rubin) Date: 15 Jan 2009 20:47:07 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <9ed5092f-0242-4b50-b23e-11384ba265d2@f20g2000yqg.googlegroups.com> Message-ID: <7xmydrg8ms.fsf@ruckus.brouhaha.com> gert writes: > s = sha1(bytes(random(),'utf-8')).hexdigest() > i found this, looks let say strange. But it works :) Be careful, if you're relying on the uniqueness and unpredictability of this number for program security, that random() isn't designed for such purposes. Use os.urandom instead. From michele.simionato at gmail.com Thu Jan 15 23:48:35 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 15 Jan 2009 20:48:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: On Jan 15, 8:02?am, Paul Rubin wrote: > I'd say there was a time Lisp worked the right way, and a time C > worked the right way, and maybe a time Python worked the right way, > and for a while, Algol 60 was perfection embodied. ?But times have > changed more than those languages have, so they no longer work the > right way. Or perhaps it is you who changed? I can only speak for myself, but when I first met Python (coming from Basic, Pascal, Fortran, Mathematica, Maple) it was the best language I could imagine. Now Python is still the best language I can find, but it is no more the best I can imagine, because I know much more about programming than before. But I would say that's normal and even healthy. The best language is the one yet to be invented! > Have you looked at Tim Sweeney's talk that I mentioned in another post? > > http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... I will have a look now. From http Fri Jan 16 00:03:03 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:03:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjjg7w8.fsf@ruckus.brouhaha.com> Michele Simionato writes: > Or perhaps it is you who changed? I can only speak for myself, but > when I first met Python (coming from Basic, Pascal, Fortran, > Mathematica, Maple) it was the best language I could imagine. I would say Algol 60 and Lisp were great languages the same way the Burroughs B5500 or Dec PDP-10 were great computers. Today, though, We would only describe their greatness in historical terms, since technology has advanced so much and we know better ways to do things now. All the languages were are using now, it seems to me, are pretty far behind what PL researchers are working on. But the stuff the researchers are doing isn't that immediately useful to us, since they're concentrating on academic results and aren't really in the practicality business. The gap between research and practice narrows and widens over the general ebb and flow of advancing technology, and I think it is wider than usual right now. An exception to that might be Haskell, which makes Python feel almost juvenile, but (despite the amazing work that its aficionados are doing) it lacks somewhat in practicality, in my opinion. > Now Python is still the best language I can find, but it is no more > the best I can imagine, because I know much more about programming > than before. But I would say that's normal and even healthy. > The best language is the one yet to be invented! Right. I think we are heading into a period of consolidation, where the stuff currently in the ivory towers makes it into the hands of day to day practictioners. From prologic at shortcircuit.net.au Fri Jan 16 00:04:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:04:33 +1000 Subject: s = sha1(random()).hexdigest() In-Reply-To: <7xr633g8o7.fsf@ruckus.brouhaha.com> References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <7xr633g8o7.fsf@ruckus.brouhaha.com> Message-ID: On Fri, Jan 16, 2009 at 2:46 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > gert writes: >> s = urandom(10).encode('hex') >> AttributeError: 'bytes' object has no attribute 'encode' > > Oh, Python 3. It's done some different way, someone else will have to > specify. I'm still using 2.x. >>> "".join([hex(c) for c in os.urandom(10)]) '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' >>> From berankin99 at yahoo.com Fri Jan 16 00:07:07 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Thu, 15 Jan 2009 21:07:07 -0800 (PST) Subject: Library for extracting new content from email reply messages? Message-ID: <656168.46200.qm@web112208.mail.gq1.yahoo.com> Hello, I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed....) Is there a Python email parsing library that can assist in extracting new content from messages that have been sent in reply? That is, since many users will just hit the email client's reply button to communicate with the system, I need some way to filter out the quoted "original message". Certainly, 100% accuracy can't be had, since there are so many email programs out there, but we could as least handle the very popular ones. Thank you, :) From ianand0204 at gmail.com Fri Jan 16 00:09:43 2009 From: ianand0204 at gmail.com (flagg) Date: Thu, 15 Jan 2009 21:09:43 -0800 (PST) Subject: Beginner: Data type conversion question Message-ID: I am still fairly new to python and programming in general. My question is regarding data conversion, I am working on a script that will edit dns zone files, one of the functions i wrote handles updating the serial number. Our zone files use the date as the first part of the serial and a two digit integer as the last two. i.e. 2009011501. The next update would be 2009011502, etc Here is the function I wrote, I am using dnspython for reading in zone files as Zone "objects". Because dnspython's built-in serial updater will not work with how we format our serial's, I have to re-write it. def checkSerial(): """ Checks the current 'date' portion of the serial number and checks the current 'counter'(the two digit number at the end of the serial number), then returns a complete new serial """ currentDate = time.strftime("%Y""%m""%d", time.localtime()) for (name, ttl, rdata) in zone.iterate_rdatas(SOA): date = str(rdata.serial)[0:8] inc = str(rdata.serial)[8:10] if date == currentDate: int(inc) + 1 print inc newInc = str(inc).zfill(2) serial = date + newInc print "date is the same" return serial elif date < currentDate: newInc = "01".zfill(2) serial = currentDate + newInc print "date is different" return serial Through all of this I am doing a lot of data type conversion. string - > integer, integer back to string, etc. Is this an efficient way of handling this? I have to perform basic addition on the "inc" variable, but also need to expose that value as a string. What I have above does work, but I can't help but think there is a more efficient way. I guess I am not used to data types being converted so easily. From http Fri Jan 16 00:12:19 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:12:19 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <7xr633g8o7.fsf@ruckus.brouhaha.com> Message-ID: <7x3afjg7gs.fsf@ruckus.brouhaha.com> "James Mills" writes: > >>> "".join([hex(c) for c in os.urandom(10)]) > '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' That doesn't look so good, because of all the 0x. From clp2 at rebertia.com Fri Jan 16 00:16:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 21:16:10 -0800 Subject: Beginner: Data type conversion question In-Reply-To: References: Message-ID: <50697b2c0901152116ga1e8fd0o5b25fc2742f3ae2@mail.gmail.com> On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > I am still fairly new to python and programming in general. My > question is regarding data conversion, I am working on a script that > will edit dns zone files, one of the functions i wrote handles > updating the serial number. > Our zone files use the date as the first part of the serial and a two > digit integer as the last two. > > i.e. 2009011501. The next update would be 2009011502, etc > Here is the function I wrote, I am using dnspython for reading in zone > files as Zone "objects". Because dnspython's built-in serial updater > will not work with how we format our serial's, I have to re-write it. > > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and > checks the current 'counter'(the two digit number at the end of > the serial number), then returns a complete new serial > """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] > if date == currentDate: > int(inc) + 1 The previous line is pointless. It's like having '4+4' as a statement on its own line. It calculates a value but doesn't change any state or even use the value. Perhaps you instead meant?: inc = int(inc) + 1 Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Bruce.Axtens at gmail.com Fri Jan 16 00:17:32 2009 From: Bruce.Axtens at gmail.com (axtens) Date: Thu, 15 Jan 2009 21:17:32 -0800 (PST) Subject: vb2py status? Message-ID: G'day everyone So is vb2py dead? If not, any idea when it'll support python 3? Kind regards, Bruce. From wuwei23 at gmail.com Fri Jan 16 00:25:24 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 15 Jan 2009 21:25:24 -0800 (PST) Subject: vb2py status? References: Message-ID: <45529ea5-9219-45dc-a7ec-cd5b32ce3160@n33g2000pri.googlegroups.com> On Jan 16, 3:17?pm, axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? You're always better off asking at the project site than here, but given it hasn't been updated since Feb 2004 I think it's safe to say the project is dead. But it *is* open source, so feel free to pick it up and run with it if it fills a need for you ;) From ianand0204 at gmail.com Fri Jan 16 00:29:19 2009 From: ianand0204 at gmail.com (flagg) Date: Thu, 15 Jan 2009 21:29:19 -0800 (PST) Subject: Beginner: Data type conversion question References: Message-ID: <207f6bb9-4fa1-41f0-860b-b7804345de38@e1g2000pra.googlegroups.com> On Jan 15, 9:16?pm, Chris Rebert wrote: > On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > > I am still fairly new to python and programming in general. ?My > > question is regarding data conversion, I am working on a script that > > will edit dns zone files, one of the functions i wrote handles > > updating the serial number. > > Our zone files use the date as the first part of the serial and a two > > digit integer as the last two. > > > i.e. 2009011501. ?The next update would be 2009011502, etc > > Here is the function I wrote, I am using dnspython for reading in zone > > files as Zone "objects". ?Because dnspython's built-in serial updater > > will not work with how we format our serial's, I have to re-write it. > > > def checkSerial(): > > ? ?""" > > ? ?Checks the current 'date' portion of the serial number and > > ? ?checks the current 'counter'(the two digit number at the end of > > ? ?the serial number), then returns a complete new serial > > ? ?""" > > ? ?currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > ? ?for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ?date = str(rdata.serial)[0:8] > > ? ? ? ?inc = str(rdata.serial)[8:10] > > ? ?if date == currentDate: > > ? ? ? ?int(inc) + 1 > > The previous line is pointless. It's like having '4+4' as a statement > on its own line. It calculates a value but doesn't change any state or > even use the value. Perhaps you instead meant?: > ? ? ? ? ? ? inc = int(inc) + 1 > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Ah thank you. Oversight on my part. That explains why that if statement never incremented the counter correctly. Anything odd about how I'm converting back and forth between different data types as often as I am? Is that common practice is normal programming? (forgive the beginner questions) From gopalm at infotechsw.com Fri Jan 16 00:35:44 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Fri, 16 Jan 2009 11:05:44 +0530 Subject: problem in implementing multiprocessing Message-ID: <89E5181815F74966B59B475F9B4ED600@pwit.com> Hello, I am trying to implement the multiprocessing in my application to take advantage of multiple cores. I have created two Separate process something like this. que = Queue Process(target = getData, args=(que , section, MdbFile,)).start() Process(target = getData, args=(que , section, MdbFile,)).start() In getData function I create the object(max 7MB size) and add in to queue (que.put (object)). After that I fetch the object using que.get () and use in my application. but it takes more time to get the data. Any one can help me out this problem. Thanks, Sibtey My code<<<<< from multiprocessing import Process, Queue def getData(queue, section, mdbFile): """ This function returns the gapappdata for the given mdb file. """ app = MdbFile(mdbFile) mdbData = app.data#it is a heavy object queue.put((section,mdbData)) def getData2(mdbFile): """ This function returns the gapappdata for the given mdb file. """ app = MdbFile(mdbFile) mdbData = app.data#it is a heavy object return mdbData def test_multipleProcess(fromMdbFile, toMdbFile): #multipleProcess t1 = time.time() queue = Queue() sections = ['From', 'To'] Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() section, gapAppData = queue.get() section, gapAppData = queue.get() t2 = time.time() print "total time using multiProcessing:",t2-t1 d1 = getData2(fromMdbFile) d2 = getData2(toMdbFile) print "total time withought multiProcessing:", time.time()-t2 if __name__=='__main__': f1 =r" a.mdb" f2 =r"b.mdb" test_multipleProcess(f1,f2) From prologic at shortcircuit.net.au Fri Jan 16 00:40:42 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:40:42 +1000 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: On Fri, Jan 16, 2009 at 11:02 AM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> >>>> List files from "some_dir". > foo > bar > etc > > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^ You are mad :) --JamesMills From clp2 at rebertia.com Fri Jan 16 00:42:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jan 2009 21:42:17 -0800 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <50697b2c0901152142x71d8be4fpd4602dd7f6f57dd2@mail.gmail.com> On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> >>>> List files from "some_dir". > foo > bar > etc Does the name "AppleScript" mean anything to you? ;-) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From http Fri Jan 16 00:43:45 2009 From: http (Paul Rubin) Date: 15 Jan 2009 21:43:45 -0800 Subject: English-like Python References: Message-ID: <7x3afjolf2.fsf@ruckus.brouhaha.com> The Music Guy writes: > ...might be translated as... > >>> Import the operating system module. http://coboloncogs.org From prologic at shortcircuit.net.au Fri Jan 16 00:52:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 15:52:53 +1000 Subject: multiprocessing vs. distributed processing Message-ID: I've noticed over the past few weeks lots of questions asked about multi-processing (including myself). For those of you new to multi-processing, perhaps this thread may help you. Some things I want to start off with to point out are: "multiprocessing will not always help you get things done faster." "be aware of I/O bound applications vs. CPU bound" "multiple CPUs (cores) can compute multiple concurrent expressions - not read 2 files concurrently" "in some cases, you may be after distributed processing rather than multi or parallel processing" cheers James -- -- "Problems are solved by method" From martin at v.loewis.de Fri Jan 16 01:08:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 16 Jan 2009 07:08:39 +0100 Subject: s = sha1(random()).hexdigest() In-Reply-To: <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> Message-ID: <49702467$0$22823$9b622d9e@news.freenet.de> > s = urandom(10).encode('hex') > > AttributeError: 'bytes' object has no attribute 'encode' py> binascii.hexlify(os.urandom(10)) b'92b91d5734a9fe562f23' Regards, Martin From koranthala at gmail.com Fri Jan 16 01:13:06 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 15 Jan 2009 22:13:06 -0800 (PST) Subject: Python Style Guide Questions Message-ID: Hi, Which is more advisable? import x b = x.a or from x import a b = a I read in Learning Python that it is always better to use the former - especially since namespace wont be dirtied. But, doing that with PEP 8 together causes my code to look rather cluttered. Reason being that - PEP 8 suggests that have max line length = 79 chars. So my code mostly looks like this: class x: def y(): try: if test: obj.filename = str(os.path.basename (obj1.find_next_element().\ get_file_path())) obj.modify_time = obj.filename.find_created_time() + \ datetime.timedelta (seconds=time.find_time()) etc .. etc.. Almost every line requires the '\'. Also, especially since Python also uses whitespace as indentation, I keep confusing the block indentation with the indentation that the '\' causes in the next line. Could you please let me know what you guys usually do in such cases? Is it advisable to go for the from x import a to avoid this clutter? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 01:38:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 06:38:58 GMT Subject: Python Style Guide Questions References: Message-ID: <0180220a$0$8693$c3e8da3@news.astraweb.com> On Thu, 15 Jan 2009 22:13:06 -0800, koranthala wrote: > Hi, > Which is more advisable? > import x > b = x.a > or > from x import a > b = a > > I read in Learning Python that it is always better to use the > former Perhaps not "always", but often. > - especially since namespace wont be dirtied. But, doing that > with PEP 8 together causes my code to look rather cluttered. Reason > being that - PEP 8 suggests that have max line length = 79 chars. So my > code mostly looks like this: > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) A few ideas for you: There is rarely enough performance benefit from squashing as much as possible into a single expression to make up for the loss of readability. Use temporary values to aid comprehension and readability. class X: def y(self): try: if test: path = obj1.find_next_element().get_file_path() obj.filename = str(os.path.basename(path)) ctime = obj.filename.find_created_time() offset = datetime.timedelta(seconds=time.find_time()) obj.modify_time = ctime + offset Alternatively, don't nest so much. class X: def _y(self): path = obj1.find_next_element().get_file_path() obj.filename = str(os.path.basename(path)) ctime = obj.filename.find_created_time() offset = datetime.timedelta(seconds=time.find_time()) obj.modify_time = ctime + offset def y(self): try: if test: self._y() Last but not least, Python now does automatic line continuations inside open brackets. You can use this to eliminate many backslashes. class X: def y(self): try: if test: obj.filename = str( os.path.basename( obj1.find_next_element().get_file_path() )) obj.modify_time = \ obj.filename.find_created_time() + \ datetime.timedelta(seconds=time.find_time()) Hope this helps. -- Steven From tangens0-NOSPAM- at -NOSPAM-gmail.com Fri Jan 16 01:42:39 2009 From: tangens0-NOSPAM- at -NOSPAM-gmail.com (Tobias Andersson) Date: Fri, 16 Jan 2009 07:42:39 +0100 Subject: English-like Python In-Reply-To: References: Message-ID: <6taoivFa0390U1@mid.individual.net> The Music Guy skrev: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > Take a look at Inform 7. It's not Python but does something similar to what you are describing: www.inform-fiction.org Check out the examples in the tutorial. Some of them are quite elegant. HTH /TA From Russ.Paielli at gmail.com Fri Jan 16 01:57:12 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 15 Jan 2009 22:57:12 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> Message-ID: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> On Jan 15, 12:21?pm, Bruno Desthuilliers wrote: > Once again, the important point is that there's a *clear* distinction > between interface and implementation, and that you *shouldn't* mess with > implementation. If you "*shouldn't* mess with the implementation", then what is wrong with enforcing that "shouldn't" in the language itself? Why leave to coding standards and company policy what can be encoded right into the language? Why leave to humans (who are known to err) what can be automated relatively easily? Isn't that what computers are for? >But what, some people think programmers are stupid, and > so they hire stupid programmers, so they need b&d languages to protect > stupid programmers from themselves - which just doesn't work, since > *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb > getter/setter pairs for _each and any_ attribute ? Hey, I share your distaste for Java and C++. All those "setters" and "getters" are a kludge. I think Python "properties" are a major step forward here. Just for fun, I checked to see if Scala has properties. Guess what? Not only does it have them, but they are generated automatically for all member data. That's even better than Python properties! > > As I said before, enforced encapsulation may not be appropriate for > > every application, but it is definitely appropriate for some. > > No. It is appropriate for dummy managers hiring dummy programmers. The > project's size and domain have nothing to do with it. Let me try to be very clear here. We are dealing with two separate but related issues. The first is whether data hiding should be added to Python. The second is whether data hiding provides any net benefit in *any* language. As for whether data hiding should be added to Python, I am not arguing one way or the other. I am merely saying that it is worth considering. Whether it can be added without screwing up the language, I don't know. If not, then so be it. That just limits the range of domains where Python is suitable. As for whether data hiding provides a net benefit in any language, it certainly does for large programs and for safety-critical programs. For large, safety-critical systems, it's a no-brainer. I think data hiding can also provide net benefits for medium-size and even smaller programs, but lets just consider large programs, so I can shoot down your argument that data hiding provides no benefit. I like to use the example of the flight software for a large commercial transport aircraft, but many other examples could be given. How about medical systems that control radiation therapy or chemotherapy? How about financial systems that could take away your retirement account in 1.5 milliseconds. Or how about the control software for the strategic nuclear arsenals of the US or Russia? When you consider the sea, air, and land-based components, I'm sure that's one hell of a lot of code! So let's take the airplane example. Boeing and its contractors probably has hundreds of programmers working on millions of lines of code. If they believed you, they would abandon enforced data hiding, and programmers would have much more discretion to screw around with code that they don't work on directly. An FMS programmer could perhaps decide to change the parameters of the engine controls, for example. To prevent that sort of thing from happening, the management could decree that henceforth all "private" variable names will start with an underscore. Problem solved, eh? Wait a minute. You yourself have stated several times that those stupid library developers can never predict what the client will actually need. So some FMS guy named Bruno decides that he knows better than the engine group what a certain engine parameter should be. Or he decides that his code needs to know the value of that parameter, so he just goes ahead and reads it. No harm done, eh? But wait a minute. Half the programmers did the same thing, and now we have a spaghetti mess on our hands. So now management needs to implement a costly, bureaucratic program to find all such accessing of private data and correct it -- before a disaster occurs in flight. So they have meetings and assemble a data-hiding enforcement team that meets twice each week and constantly looks over every programmers shoulder. Wait a minute, wouldn't enforcement of data hiding by the programming language be preferable to a huge bureaucratic program? I sure think so. And thankfully, so does Boeing and anyone else who has a clue about large-scale software production. Now, let's talk about a data access violations in the nuclear missile launch software. Oh, yes, I'm sure the leading underscore convention is more than sufficient! Wake up, dude, and quit spouting bullsh*t! > > Not > > every door needs a lock, but certainly some do. > > You only need locks when you don't trust your neighbours. Yeah, if you live in Nome, Alaska. Also, have you ever heard the expression "locks keep honest people honest"? I spent *way* too much time on that post. I really need to quit spending my time refuting the baloney that passes for wisdom here. From tjreedy at udel.edu Fri Jan 16 02:00:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:00:04 -0500 Subject: Python Style Guide Questions In-Reply-To: References: Message-ID: koranthala wrote: > Hi, > Which is more advisable? > import x > b = x.a > or > from x import a > b = a If I know I want just one thing from x, I tend to use latter. I also like 'import xyzlib as x' > I read in Learning Python that it is always better to use the > former - especially since namespace wont be dirtied. Namespace get cluttered, not dirtied. In any case, either 'x' or 'a' gets added. One new name either way. > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) Use 4 spaces instead of 5 for indents > Almost every line requires the '\'. As Steven said, usually no > Also, especially since Python also > uses whitespace as indentation, I keep confusing the block indentation > with the indentation that the '\' causes in the next line. '\' causes no indentation Beyond that, consider find a style you like. I agree with Stvhen about using 'thought-sized' expressions. tjr From mario.ruggier at gmail.com Fri Jan 16 02:09:51 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 15 Jan 2009 23:09:51 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> Message-ID: <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> On Jan 16, 2:30?am, ajaksu wrote: > On Jan 15, 8:21?pm, mario ruggier wrote: > > > OK! Here's a small script to make it easier... > > Thanks! I think I found a quick way around the restrictions (correct > me if I borked it), but I think you can block this example by > resetting your globals/builtins: > > exprs = [ > ? ? '(x for x in range(1)).gi_frame.f_globals.clear()', > ? ? 'open("where_is_ma_beer.txt", "w").write("Thanks for the fun ?")' > ] Cool, the beer that is ;) Under 2.6... why does python allow the f_globals lookup in this case, but for the previous example for func_globals it does not? If you look at the top of the file test/test_restricted.py, there is: # Attempt at accessing these attrs under restricted execution on an object # that has them should raise a RuntimeError RESTRICTED_ATTRS = [ 'im_class', 'im_func', 'im_self', 'func_code', 'func_defaults', 'func_globals', #'func_name', #'tb_frame', 'tb_next', #'f_back', 'f_builtins', 'f_code', 'f_exc_traceback', 'f_exc_type', #'f_exc_value', 'f_globals', 'f_locals' ] I have not yet finished working this list off to ensure that any lookup of these attrs wherever they occur will be refused, but I guess that would block this kind of lookup out. I should also block any attempt to access any "gi_*" attribute... Laboriously doing all these checks on each expr eval will be very performance heavy, so I hope to be able to limit access to all these more efficiently. Suggestions? Cheers, Mario > Regards, > Daniel From GDoermann at gmail.com Fri Jan 16 02:10:18 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 15 Jan 2009 23:10:18 -0800 (PST) Subject: Client Socket Connection to Java server Message-ID: I am having problems with a socket connection to a Java server. In java I just open the socket, pass the length and then pass the bits across the socket. I created a socket object: import socket class MySocket: def __init__(self, host='localhost', port = 28192, buffsize = 1024): socket.setdefaulttimeout(10) self.host = host self.port = port self.buffsize = buffsize self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((host, port)) def send(self, data): self.socket.send(data) def receive(self): return self.socket.recv(self.buffsize) def sendAndReceive(self, data): self.send(data) return self.receive() def close(self): self.socket.close() But the java server gives the error: WARNING: Message length invalid. Discarding The data is of type string (xml). Am I doing something wrong? I know you have to reverse the bits when communicating from C++ to Java. Could this be the problem? I figured it would not because it said the length was invalid. I just started looking at python sockets tonight... and I don't have a real deep base with socket connections as it is... any help would be greatly appreciated. Greg From mail at anjanesh.net Fri Jan 16 02:16:28 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 16 Jan 2009 12:46:28 +0530 Subject: Py3 - converting bytes to ascii In-Reply-To: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> References: <2a82127b-517f-4428-9081-0faf4bb55b9e@v42g2000yqj.googlegroups.com> Message-ID: <4970344C.4080103@anjanesh.net> The problem seems be solved with urllib.request.urlretrieve() I think the binary information read() was giving had headers like content-size - but not HTTP headers. The first couple of bytes indicate how much content to read and after reading that content, the next set of bytes indicate the next chunk. From tjreedy at udel.edu Fri Jan 16 02:20:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:20:25 -0500 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > >>>> import os >>>> >>>> def list_files(dirname): >>>> for p in os.listdir(dirname): >>>> print p >>>> >>>> list_files("some_dir") > foo > bar > etc > > ...might be translated as... > >>>> Import the operating system module. >>>> >>>> Define a new function as "list files" which accepts > "a path" and does the following: > For every item in the list returned by the operating system's > directory listing of the given path, do the following: > Print the item. >>>> List files from "some_dir". > foo > bar > etc > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^. Others have mentioned some examples in this direction. Some problems: English is not a context free language; a constrained context-free subset is needed for algorithmic parsing. Should Pynglish change 'a' to 'an' before vowels? 'Define new function "list files"' is good English too. In your example, you changed '"a path"' to 'the given path'. This will not parse very easily. Etc. Writing within such a subset is likely to be more difficult than writing in Python. It would be easier to slip up and less easy to notice an error. (Of course, some think Python is too wordy. I think is strikes a fair balance.) It would also soon get tedious. It would also be more tedious to read. There is a reason math shifted from 'plain Greek' to the use of symbols. While Python uses names derived from English, it is used internationally. Pynglish would be harder for non-native-English speakers to learn. I think random indentifiers in non-Latin alphabets would be more grating in Pynglish sentences than in Python statements. def #&*#&*$(#%,#^): # versus Define a new function #&*#&*$ which accepts #% and #^ One could disagree though. Terry Jan Reedy From tjreedy at udel.edu Fri Jan 16 02:23:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:23:32 -0500 Subject: problem in implementing multiprocessing In-Reply-To: <89E5181815F74966B59B475F9B4ED600@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> Message-ID: gopal mishra wrote: > Hello, > > I am trying to implement the multiprocessing in my application to take > advantage of multiple cores. I have created two > > Separate process something like this. > > que = Queue > Process(target = getData, args=(que , section, MdbFile,)).start() > Process(target = getData, args=(que , section, MdbFile,)).start() > > In getData function I create the object(max 7MB size) and add in to queue > (que.put (object)). > > After that I fetch the object using que.get () and use in my application. > but it takes more time to get the data. More time than what? Than not getting the date? Than getting it some other way? CPU, OS, and Python version may also be relevant. > Any one can help me out this problem. > > Thanks, > Sibtey > > My code<<<<< > from multiprocessing import Process, Queue > > def getData(queue, section, mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > queue.put((section,mdbData)) > > def getData2(mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > return mdbData > > def test_multipleProcess(fromMdbFile, toMdbFile): > #multipleProcess > t1 = time.time() > queue = Queue() > sections = ['From', 'To'] > Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() > Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() > section, gapAppData = queue.get() > section, gapAppData = queue.get() > t2 = time.time() > print "total time using multiProcessing:",t2-t1 > d1 = getData2(fromMdbFile) > d2 = getData2(toMdbFile) > print "total time withought multiProcessing:", time.time()-t2 > > > > > > if __name__=='__main__': > f1 =r" a.mdb" > f2 =r"b.mdb" > test_multipleProcess(f1,f2) > > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Fri Jan 16 02:26:26 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:26:26 -0500 Subject: Library for extracting new content from email reply messages? In-Reply-To: <656168.46200.qm@web112208.mail.gq1.yahoo.com> References: <656168.46200.qm@web112208.mail.gq1.yahoo.com> Message-ID: Bernard Rankin wrote: > Hello, > > I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed....) > > Is there a Python email parsing library that can assist in extracting new content from messages that have been sent in reply? > > That is, since many users will just hit the email client's reply button to communicate with the system, I need some way to filter out the quoted "original message". > > Certainly, 100% accuracy can't be had, since there are so many email programs out there, but we could as least handle the very popular ones. If the email quotes original text as above, or has 'Original message follows' section, then non-quoted stuff should be new. You could also use the difflib module. From koranthala at gmail.com Fri Jan 16 02:28:38 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 15 Jan 2009 23:28:38 -0800 (PST) Subject: Python Style Guide Questions References: Message-ID: <9cec6397-0e3d-4ede-bb5c-7f4143411142@o40g2000prn.googlegroups.com> On Jan 16, 12:00?pm, Terry Reedy wrote: > koranthala wrote: > > Hi, > > ? ?Which is more advisable? > > import x > > b = x.a > > ? ? ? ? ? ? ?or > > from x import a > > b = a > > If I know I want just one thing from x, I tend to use latter. > I also like 'import xyzlib as x' > > > ? ?I read in Learning Python that it is always better to use the > > former - especially since namespace wont be dirtied. > > Namespace get cluttered, not dirtied. ?In any case, either 'x' or 'a' > gets added. ?One new name either way. > > > class x: > > ? ? ?def y(): > > ? ? ? ? ? try: > > ? ? ? ? ? ? ? if test: > > ? ? ? ? ? ? ? ? ? obj.filename = str(os.path.basename > > (obj1.find_next_element().\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? get_file_path())) > > ? ? ? ? ? ? ? ? ? obj.modify_time = obj.filename.find_created_time() > > + ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? datetime.timedelta > > (seconds=time.find_time()) > > Use 4 spaces instead of 5 for indents > > > Almost every line requires the '\'. > > As Steven said, usually no > > > Also, especially since Python also > > uses whitespace as indentation, I keep confusing the block indentation > > with the indentation that the '\' causes in the next line. > > '\' causes no indentation > > Beyond that, consider find a style you like. ?I agree with Stvhen about > using 'thought-sized' expressions. > > tjr Thank you Steven and TJR. I will try to implement the thought sized expressions. I was rather misled by trying to decrease the line count as much as possible. From tjreedy at udel.edu Fri Jan 16 02:35:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:35:54 -0500 Subject: Beginner: Data type conversion question In-Reply-To: References: Message-ID: flagg wrote: > I am still fairly new to python and programming in general. My > question is regarding data conversion, I am working on a script that > will edit dns zone files, one of the functions i wrote handles > updating the serial number. > Our zone files use the date as the first part of the serial and a two > digit integer as the last two. > > i.e. 2009011501. The next update would be 2009011502, etc > Here is the function I wrote, I am using dnspython for reading in zone > files as Zone "objects". Because dnspython's built-in serial updater > will not work with how we format our serial's, I have to re-write it. > > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and > checks the current 'counter'(the two digit number at the end of > the serial number), then returns a complete new serial > """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] If rdate.serial is already a string, as name would imply, the str() call is pointless. If not, can you get inc as int more directly? > if date == currentDate: > int(inc) + 1 > print inc > newInc = str(inc).zfill(2) > serial = date + newInc > print "date is the same" > return serial > elif date < currentDate: > newInc = "01".zfill(2) > serial = currentDate + newInc > print "date is different" > return serial > > Through all of this I am doing a lot of data type conversion. string - >> integer, integer back to string, etc. Is this an efficient way of > handling this? I have to perform basic addition on the "inc" > variable, but also need to expose that value as a string. What I > have above does work, but I can't help but think there is a more > efficient way. I guess I am not used to data types being converted so > easily. Other than that, you are perhaps worrying too much, even if code could be squeezed more. The idea that every object knows how to convert itself to a string representation is basic to Python. tjr From Scott.Daniels at Acm.Org Fri Jan 16 02:36:08 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 15 Jan 2009 23:36:08 -0800 Subject: optimizing large dictionaries In-Reply-To: <7xmydsxhr0.fsf@ruckus.brouhaha.com> References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> <017fb604$0$8693$c3e8da3@news.astraweb.com> <0382e3fa-2ff2-4bcc-ae7f-f3ff5769c06c@f20g2000yqg.googlegroups.com> <7xmydsxhr0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Per Freem writes: >> 2] is there an easy way to have nested defaultdicts? ie i want to say >> that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact >> that my_dict is a dictionary, whose values are dictionary that map to >> ints. but that syntax is not valid. > > my_dict = defaultdict(lambda: defaultdict(int)) or my_dict = defaultdict(functools.partial(defaultdict, int)) --Scott David Daniels Scott.Daniels at Acm.Org From max at alcyone.com Fri Jan 16 02:39:20 2009 From: max at alcyone.com (Erik Max Francis) Date: Thu, 15 Jan 2009 23:39:20 -0800 Subject: English-like Python In-Reply-To: <6taoivFa0390U1@mid.individual.net> References: <6taoivFa0390U1@mid.individual.net> Message-ID: Tobias Andersson wrote: > The Music Guy skrev: >> Just out of curiousity, have there been any attempts to make a version >> of Python that looks like actual English text? I mean, so much of Python >> is already based on the English language that it seems like the next >> natural step would be to make a programming language which is actually a >> spoken one. > > Take a look at Inform 7. It's not Python but does something similar to > what you are describing: > > www.inform-fiction.org > > Check out the examples in the tutorial. Some of them are quite elegant. I was thinking of this as well when I saw his post. Inform 7 has some interesting ideas, but I think the general problem with English-like programming language systems is that once you get into the nitty gritty details, you end up having to know exactly the right things to type, which ultimately get just as complicated as a more traditional programming language syntax. In the big picture I don't think it helps much. After all, there's a reason that most modern programming languages don't look like COBOL or AppleScript. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Physics, as we know it, will be over in six months. -- Max Born, 1928 From bignose+hates-spam at benfinney.id.au Fri Jan 16 02:39:47 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 16 Jan 2009 18:39:47 +1100 Subject: Python Style Guide Questions References: Message-ID: <873afjbsxo.fsf@benfinney.id.au> koranthala writes: > import x > b = x.a > or > from x import a > b = a > > I read in Learning Python that it is always better to use the > former - especially since namespace wont be dirtied. The namespace isn't really dirtied by ?from foo import spam?, since it's clear within the module where the name ?spam? comes from. What dirties a namespace is ?from foo import *?. Avoid that. > But, doing that with PEP 8 together causes my code to look rather > cluttered. Reason being that - PEP 8 suggests that have max line > length = 79 chars. Yes, this is one valid reason to change names on import. Even better, sometimes, can be the ?as? clause: from foo.bar import UncomfortablyLongNamedClass as NamedClass spam = NamedClass() > So my code mostly looks like this: > class x: > def y(): > try: > if test: > obj.filename = str(os.path.basename > (obj1.find_next_element().\ > get_file_path())) > obj.modify_time = obj.filename.find_created_time() > + \ > datetime.timedelta > (seconds=time.find_time()) > > etc .. etc.. > Almost every line requires the '\'. In fact, they don't. Python allows parentheses around any expression, and allows line continuation when a bracketing syntax (parentheses, brackets, braces) has not been closed. Combined, these allow you to break a statement and align the line continuations nicely with standard four-space indentation: obj.filename = str( os.path.basename( obj1.find_next_element().get_file_path())) obj.modify_time = ( obj.filename.find_created_time() + datetime.timedelta(seconds=time.find_time())) > Also, especially since Python also uses whitespace as indentation, I > keep confusing the block indentation with the indentation that the > '\' causes in the next line. That's another reason I tend to break on an existing open-parenthesis (e.g. for a function call) where possible; it's clearer to the eye that the statement is incomplete. When ther isn't an easy parenthesis available, I'm not shy about applying parentheses, as above, merely to allow line continuation. > Could you please let me know what you guys usually do in such cases? > Is it advisable to go for the from x import a to avoid this clutter? Employing the existing line continuations as above, I find I don't often need to shorten names on import. Especially I tend to avoid changing the name of anything imported from the standard library, or from some very widely-used code base, since I feel that would tend to impede readability of my code. But, on those occasions where the names are still excessively long, yes, the import renaming can be very useful, when applied sparingly. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From tjreedy at udel.edu Fri Jan 16 02:39:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:39:53 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: > On Jan 15, 8:02 am, Paul Rubin wrote: >> Have you looked at Tim Sweeney's talk that I mentioned in another post? >> >> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... I did. He gives a really nice use case for Python's ability to dynamically modify classes imported from a library. (Were not you arguing against that? Or was is someone else?) From bj_666 at gmx.net Fri Jan 16 02:43:26 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 16 Jan 2009 07:43:26 GMT Subject: Beginner: Data type conversion question References: Message-ID: <6tas4tF9v94eU1@mid.uni-berlin.de> On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote: > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and checks > the current 'counter'(the two digit number at the end of the serial > number), then returns a complete new serial """ > currentDate = time.strftime("%Y""%m""%d", time.localtime()) The format string can be written as *one* string literal instead of three: "%Y%m%d". > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > date = str(rdata.serial)[0:8] > inc = str(rdata.serial)[8:10] Here you are converting `rdata.serial` twice. tmp = str(rdata.serial) date = tmp[0:8] inc = int(tmp[8:10]) As `inc` is conceptually a number, you should do the conversion here and treat it as number from now on. > if date == currentDate: > int(inc) + 1 > print inc > newInc = str(inc).zfill(2) > serial = date + newInc > print "date is the same" > return serial > elif date < currentDate: > newInc = "01".zfill(2) > serial = currentDate + newInc > print "date is different" > return serial Both branches do almost the same. You should try to avoid such code duplication. if date == currentDate: inc += 1 elif date < currentDate: inc = 1 else: assert False # Should never happen. return "%s%02d" % (date, inc) That's it. Ciao, Marc 'BlackJack' Rintsch From tjreedy at udel.edu Fri Jan 16 02:48:26 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:48:26 -0500 Subject: Injecting a global into a defined function?? In-Reply-To: References: Message-ID: Cong Ma wrote: > Terry Reedy wrote: >> Not to me. You are using the module as a singleton class. The >> alternative is to write a class, make the functions methods, and >> instantiate the class. If that instance must be a singleton, more work >> is required. If multiple instances make sense, you can go the class >> route when you need to. > > I've thought of this too, but it turns out those functions are related to each > other very loosely. They do a lot of completely different things independently > and have just one common global variable to share. IMHO it would reduce the > readability of code because the role of this class is very unclear. Anyway, > "readability" is mostly a subjective matter and I think what you pointed out is > a good idea in general. From a user perspective, there is little difference between import mod and from mod import mod_class_singleton_instance as mod Modules and classes are both namespaces with names accessed as attributes (dotted names) rather than as quoted keys. (Classes are more also.) From tjreedy at udel.edu Fri Jan 16 02:51:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:51:10 -0500 Subject: spam on the list - how are things now? In-Reply-To: References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: James Mills wrote: > On Fri, Jan 16, 2009 at 1:30 PM, wrote: >> We've been running SpamBayes on the news-to-mail gateway on mail.python.org >> for a couple weeks now. To me it seems like the level of spam leaking onto >> the list has dropped way down but I'd like some feedback from people who >> read the python-list at python.org mailing list on the topic. > > Agreed. It has gone down. Thank you for taking the > time to do something about it :) Reading from gmane, there has not been much obvious spam lately. Thanks. From kenpuca.dev at gmail.com Fri Jan 16 02:51:43 2009 From: kenpuca.dev at gmail.com (Ken Pu) Date: Fri, 16 Jan 2009 02:51:43 -0500 Subject: lazy evaluation is sometimes too lazy... help please. Message-ID: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) The output is: [10, 11, 12, 13, 14] [10, 11, 12, 13, 14] I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10) for x in count()) until the end. But is this the right behaviour? How can I get the output I want: [0, 1, 2, 3, 4] [10, 11, 12, 13, 14] Thanks. Ken From mail at microcorp.co.za Fri Jan 16 02:53:33 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 09:53:33 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com><0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com><2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com><92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> Message-ID: <001901c977b1$00bd6a20$0d00a8c0@hendrik> "James Mills" wrote: > At the most basic level do you really think a machine > really cares about whether -you- the programmer > has illegally accessed something you shouldn't have ? Yes it does - this is exactly why some chips have supervisor and user modes - to keep the monkeys away from the typewriter. - Hendrik From tjreedy at udel.edu Fri Jan 16 02:55:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 02:55:31 -0500 Subject: Suggested improvements for IDLE (non-official) In-Reply-To: References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: Tim H wrote: > r wrote: >> On Jan 14, 4:43 pm, Terry Reedy wrote: >> OFF-TOPIC:(but related) >> What is the state of Tkinter at this point. Is an active effort under >> way to port TK 8.5 into Python? Tkinter and IDLE are very important to >> Python, but i understand there are much more important areas where the >> GURU's are concentrating. Should there be a calling for "others" to >> get involved here? I would like to help out. >> Thanks > > Maybe I'm misunderstanding something here, but "About Idle" in Python > 2.6.1 (win32) says "Tk version: 8.5" Same in 3.0. I check .../python30/tcl/ and it has tck8/ tcl8.5, tix8.4, tk8.5 subdirs. From http Fri Jan 16 02:56:35 2009 From: http (Paul Rubin) Date: 15 Jan 2009 23:56:35 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> Message-ID: <7xd4en4rbg.fsf@ruckus.brouhaha.com> Terry Reedy writes: > >> Have you looked at Tim Sweeney's talk that I mentioned in another post? > >> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... > > I did. He gives a really nice use case for Python's ability to > dynamically modify classes imported from a library. (Were not you > arguing against that? Or was is someone else?) He is talking about extending classes by something like inheritance, not modifying them dynamically. This is also in the context of an extremely powerful static type system with existential and dependent types, and totality proofs for just about everything. That is about a billion light years away from anything anyone has ever proposed for Python. From bearophileHUGS at lycos.com Fri Jan 16 02:59:55 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 15 Jan 2009 23:59:55 -0800 (PST) Subject: Alphametric fun with Python References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: Terry Reedy: >It illustrates well the point you intended. I don't know what my point was. A suggestion: with that solver, to find solution in a faster way you have to write many equations. Bye, bearophile From mail at microcorp.co.za Fri Jan 16 03:03:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 10:03:28 +0200 Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de><017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au><017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au><017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> Message-ID: <001a01c977b1$016542e0$0d00a8c0@hendrik> "Aaron Brady" wrote: On Jan 15, 6:41 pm, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > >> >> > Familiarize yourself with PEP8 for naming and coding-conventions > >> >> > first. 8< -------------- stuff giving Diez a hard time for the above ------------------------ Oh come on you lot - you are carrying on as if Diez were wearing his skull socks again - do me a favour and give him a break! - Hendrik From mail at microcorp.co.za Fri Jan 16 03:22:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 10:22:28 +0200 Subject: spam on the list - how are things now? References: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: <001101c977b3$a9b91460$0d00a8c0@hendrik> "Terry Reedy" wrote: > James Mills wrote: > > On Fri, Jan 16, 2009 at 1:30 PM, wrote: > >> We've been running SpamBayes on the news-to-mail gateway on mail.python.org > >> for a couple weeks now. To me it seems like the level of spam leaking onto > >> the list has dropped way down but I'd like some feedback from people who > >> read the python-list at python.org mailing list on the topic. > > > > Agreed. It has gone down. Thank you for taking the > > time to do something about it :) > > Reading from gmane, there has not been much obvious spam lately. Thanks. I read this solely via the mailing list - and Yes, whatever was done has helped a lot. - Hendrik From prologic at shortcircuit.net.au Fri Jan 16 03:56:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 16 Jan 2009 18:56:04 +1000 Subject: [Python-Dev] multiprocessing vs. distributed processing In-Reply-To: References: Message-ID: On Fri, Jan 16, 2009 at 6:30 PM, Matthieu Brucher wrote: > 2009/1/16 James Mills : >> I've noticed over the past few weeks lots of questions >> asked about multi-processing (including myself). > > Funny, I was going to blog about this, but not just for Python. > >> For those of you new to multi-processing, perhaps this >> thread may help you. Some things I want to start off >> with to point out are: >> >> "multiprocessing will not always help you get things done faster." > > Of course. There are some programs that are I/O or memory bandwidth > bound. So if one of those bottlenecks is common to the cores you use, > you can't benefit from their use. > >> "be aware of I/O bound applications vs. CPU bound" > > Exactly. We read a lot about Folding at Home, SETI at Home, they can be > distributed, as it is more or less "take a chunk, process it somewhere > and when you're finish tell me if there something interesting in it". > Not a lot of communications between the nodes. Then, there are other > applications that process a lot of data, they must read data from > memory, make one computation, read other data, compute a little bit > (finite difference schemes), and here we are memory bandwidth bound, > not CPU bound. > >> "multiple CPUs (cores) can compute multiple concurrent expressions - >> not read 2 files concurrently" > > Let's say that this is true for the usual computers. Clusters can make > concurrent reads, as long as there is the correct architecture behind. > Of course, if you only have one hard disk, you are limited. > >> "in some cases, you may be after distributed processing rather than >> multi or parallel processing" > > Of course. Clusters can be expensive, their interconnections even > more. So if your application is made of independent blocks that can > run on small nodes, without much I/Os, you can try distributed > computing. If you need big nodes with high-speed interconnections, you > will have to use parallel processing. > > This is just what my thoughts on the sucjet are, but I think I'm not > far from the truth. Of course, if I'm proved wrong, I'll be glad to > hear why. Thank you Matthieu for your response. Very good comments on some of the points I raised. Hopefully those interested in the topic will learn from this thread. cheers James PS: I assumed you meant to post back to the list and not just me :) From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 03:57:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 08:57:32 GMT Subject: Convention vs. fascism References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> Message-ID: <01804283$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > Oh come on you lot - you are carrying on as if Diez were wearing his > skull socks again - do me a favour and give him a break! Well, for what it's worth, I should say one final thing: I didn't disagree with what Diez said, only the way he said it. I thought my original post made that clear, but perhaps I should have said so explicitly. And I certainly don't think less of him because of it. And... skull socks? Cool. Where can I get some? -- Steven From castironpi at gmail.com Fri Jan 16 04:04:08 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 16 Jan 2009 01:04:08 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <3c31a7d7-8dfc-430e-b8eb-fbeb427de291@k36g2000pri.googlegroups.com> On Jan 14, 7:04?pm, Chris Rebert wrote: > On Wed, Jan 14, 2009 at 4:30 PM, Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. snip > > Or, and this is the interesting part, use the ('identificationally') > > same tuples in both mappings, since the object is only mentioned, not > > used. > > > phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > > phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964', > > '5p-11p' ) ] > > hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ] > > hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ] > > > What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > Once you get beyond a main dict (e.g. name2phone) and one that's its > inverse (e.g. phone2name), yeah, I'd probably say you should be using > a relational DB for this. You could also use objects, but it sounds > like you really want to use SQL-like querying, which isn't well-suited > to plain objects (though it'd be fine with an ORM). I want the simplest data structure that can hold a relation. In this case, I would declare a new record as: PhoneInfo( 'Joan', '555-963', '9a-5p' ) PhoneInfo( 'Joan', '555-964', '5p-11p' ) However the syntax is flexible, such as in 'PhoneInfo.add' etc. I can query the structure myself if I can access it as an iterable of tuples. I think I want to use named tuples. for rec in PhoneInfo.records: if rec.name== 'Joan': something Or I can just use itertools.ifilter. recset= ifilter( lambda rec: rec.name== 'Joan', PhoneInfo.records ) for rec in recset: something Using objects is one advantage, since they are "live" (unserialized) and native, such as a relation of socket connections. (SQL would require an additional mapping object and a key to accomplish it.) From gopalm at infotechsw.com Fri Jan 16 04:16:03 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Fri, 16 Jan 2009 14:46:03 +0530 Subject: problem in implementing multiprocessing In-Reply-To: References: <89E5181815F74966B59B475F9B4ED600@pwit.com> Message-ID: <66510985287744829EE3AD881CE824B2@pwit.com> I create two heavy objects sequentially without using multipleProcessing then creation of the objects takes 2.5 sec.if i create these two objects in separate process then total time is 6.4 sec. i am thinking it is happening due to the pickling and unpickling of the objects.if i am right then what could be the sollution. my system configuration: dual-core processor winXP python2.6.1 gopal mishra wrote: > Hello, > > I am trying to implement the multiprocessing in my application to take > advantage of multiple cores. I have created two > > Separate process something like this. > > que = Queue > Process(target = getData, args=(que , section, MdbFile,)).start() > Process(target = getData, args=(que , section, MdbFile,)).start() > > In getData function I create the object(max 7MB size) and add in to queue > (que.put (object)). > > After that I fetch the object using que.get () and use in my application. > but it takes more time to get the data. More time than what? Than not getting the date? Than getting it some other way? CPU, OS, and Python version may also be relevant. > Any one can help me out this problem. > > Thanks, > Sibtey > > My code<<<<< > from multiprocessing import Process, Queue > > def getData(queue, section, mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > queue.put((section,mdbData)) > > def getData2(mdbFile): > """ > This function returns the gapappdata for the given mdb file. > """ > app = MdbFile(mdbFile) > mdbData = app.data#it is a heavy object > return mdbData > > def test_multipleProcess(fromMdbFile, toMdbFile): > #multipleProcess > t1 = time.time() > queue = Queue() > sections = ['From', 'To'] > Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start() > Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start() > section, gapAppData = queue.get() > section, gapAppData = queue.get() > t2 = time.time() > print "total time using multiProcessing:",t2-t1 > d1 = getData2(fromMdbFile) > d2 = getData2(toMdbFile) > print "total time withought multiProcessing:", time.time()-t2 > > > > > > if __name__=='__main__': > f1 =r" a.mdb" > f2 =r"b.mdb" > test_multipleProcess(f1,f2) > > -- > http://mail.python.org/mailman/listinfo/python-list > From castironpi at gmail.com Fri Jan 16 04:22:23 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 16 Jan 2009 01:22:23 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: On Jan 14, 7:54?pm, MRAB wrote: > Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. > > > For a reverse lookup, you just need two lookups. > > name= {} > > phone= {} > > name[ '555-963' ]= 'Joan' > > phone[ 'Joan' ]= '555-963' > > > Though maybe the keys in 'name' should be names, instead of the > > values in it. ?The variable name doesn't clarify that. ?(What is more > > natural to you in reading code? ?Is one obviously wrong?) > > > phone[ '555-963' ]= 'Joan' > > name[ 'Joan' ]= '555-963' > > Consider "str(x)". It isn't saying "x is a string", it's saying "x as a > string". Similarly, "ord(x)" says "the ordinal value of x". So, > "phone[x]" means "the phone number of x". That's true. However, I want to map individual fields of records to the tuples (named tuples) containing the records themselves (unless I just need a set of tuples). I think what you are talking about is accessing the 'phone' field, which was not what I was thinking. (You see that in algorithm pseudocode a bit.) For that, you could use 'name[ tuple1 ]' to obtain the name. However, in relational data, there is no single key, of which the rest of the fields are just accessories. (Does that make sense?) I think I want to use the multiple mappings for different ways to have access to the data. > [snip]> What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > You could imagine an object where you provide a field name and a value > and it returns all those entries where that field contains that value. > That, basically, is a database. That's true. The mapping objects wouldn't be particularly helpful if I had patterns to match instead of exact values... as now I'm thinking you usually would. In other words, providing the mapping objects, even grouped together in a provider object, would only handle a small subset of possible queries, specifically exact equality. For example, the 'hourstocall' object is basically useless as specified. Even separating the fields wouldn't help in a hash. The separate fields would need to be stored in sorted lists, using 'bisect' to test inequality. (How does an SQL service implement inequality checks anyway?) However, it's interesting that my first thought was to start out with a mapping object, instead of just a set of 'namedtuple's. From daigno at gmail.com Fri Jan 16 04:24:34 2009 From: daigno at gmail.com (=?UTF-8?Q?=C3=89ric_Daigneault?=) Date: Fri, 16 Jan 2009 17:24:34 +0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <001901c977b1$00bd6a20$0d00a8c0@hendrik> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <001901c977b1$00bd6a20$0d00a8c0@hendrik> Message-ID: <5a827c4d0901160124v3aa568aet15440d0c40b4cc0f@mail.gmail.com> Hendrik van Rooyento keep the monkeys away from the typewriter. Love it... just fully describes why we should keep some parts hidden from the pointyHairedBossHired Code monkeys... I'd like to think I know what I am doing... can't say the same of all people that have access to the code unfortunately... also I have very little control over who has access to what.. if pointy haired boss says monkey A has access to all then gotta live with it. So this is why, however shameful it may be, I will not use python here for production stuff. --- God I miss it, however scary the ride may feel to a hardcore Java guy.. it sure was fun. Terry Reedy > I did. He gives a really nice use case for Python's ability to > dynamically modify classes imported from a library. (Were not you > arguing against that? Or was is someone else?) There is a place for these kind of hacks, however, see code monkeys above, I would want to make sure it is very well encapsulated (wrapper library for example) before I release it as a lib to the internal zoo. The thing that gets me with all this talk about dynamic access to private wannabe variables... What happens to your coupling, I like my code nice and tidy, high internal coupling is allowed but from the wild I would tend to want to reduce it as much as possible. Dynamically replaced code is a nice idea indeed and I could think of a few really nice uses for this (good luck for this kind of flexibility in Java) but doing so you willingly break the encapsulation convention, thus you must also manage the possible consequences that arise from this break. Python is nice quick and flexible... but it provides so much rope a monkey would hang the whole ecosystem with it. Me I like the big spool, but as some wise dude once said with great power comes great responsibilities. On Fri, Jan 16, 2009 at 3:53 PM, Hendrik van Rooyen wrote: > "James Mills" wrote: > > > At the most basic level do you really think a machine > > really cares about whether -you- the programmer > > has illegally accessed something you shouldn't have ? > > Yes it does - this is exactly why some chips have supervisor > and user modes - to keep the monkeys away from the typewriter. > > - Hendrik > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jan 16 04:31:37 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Jan 2009 10:31:37 +0100 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> Message-ID: Terry Reedy wrote: > Peter Otten wrote: > >> List comprehensions delete the helper variable after completion: > > I do not believe they did in 2.4. Not sure of 2.5. As Mario said, 2.4, 2.5, and 2.6 all show the same behaviour. > There is certainly > a very different implementation in 3.0 and, I think, 2.6. OP > neglected to mention Python version he tested on. Code meant to run on > 2.4 to 3.0 cannot depend on subtle listcomp details. 3.0 behaves different. Like generator expressions listcomps no longer leak the loop variable, and this is implemented by having each listcomp execute as a nested function: > In 3.0 > >>> def f(): [i for i in [1]] > > >>> import dis > >>> dis.dis(f) > 1 0 LOAD_CONST 1 ( at > 0x01349BF0, file "", line 1>) > 3 MAKE_FUNCTION 0 > 6 LOAD_CONST 2 (1) > 9 BUILD_LIST 1 > 12 GET_ITER > 13 CALL_FUNCTION 1 > 16 POP_TOP > 17 LOAD_CONST 0 (None) > 20 RETURN_VALUE This is more robust (at least I can't think of a way to break it like the 2.x approach) but probably slower due to the function call overhead. The helper variable is still there, but the possibility of a clash with another helper is gone (disclaimer: I didn't check this in the Python source) so instead of # 2.5 and 2.6 (2.4 has the names in a different order) >>> def f(): ... [[i for i in ()] for k in ()] ... >>> f.func_code.co_varnames ('_[1]', 'k', '_[2]', 'i') we get # 3.0 >>> def f(): ... [[i for i in ()] for k in ()] ... >>> f.__code__.co_varnames () The variables are gone from f's scope, as 3.x listcomps no longer leak their loop variables. >>> f.__code__.co_consts (None, at 0x2b8d7f6d7530, file "", line 2>, ()) >>> outer = f.__code__.co_consts[1] >>> outer.co_varnames ('.0', '_[1]', 'k') Again the inner listcomp is separated from the outer. >>> outer.co_consts ( at 0x2b8d7f6d26b0, file "", line 2>, ()) >>> inner = outer.co_consts[0] >>> inner.co_varnames ('.0', '_[1]', 'i') Peter From jstroud at mbi.ucla.edu Fri Jan 16 04:37:47 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 16 Jan 2009 01:37:47 -0800 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > The output is: > [10, 11, 12, 13, 14] > [10, 11, 12, 13, 14] > > I see what Python is doing -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. It doesn't evaluate it until you ask it to, which is the right behavior. However, when evaluated, it evaluates "i" also, which is the last value to which "i" was assigned, namely the integer 1. I'm going to get flamed pretty hard for this, but it doesn't seem to be the intuitive behavior to me either. However, in a purely functional language, you wouldn't be able to construct a list of generators in this way. With python, you have to remember to adopt a purely functional design and then pray for best results. You can store generators in a list, but they need to be constructed properly. I can't perfectly transmogrify your code into functional code because I don't think making the particular anonymous generator you want is possible in python. However this is how I would make a close approximation: from itertools import * def make_gen(i): for x in count(): yield x + (i * 10) itlist = [make_gen(i) for i in xrange(2)] print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From see.signature at no.spam Fri Jan 16 04:47:36 2009 From: see.signature at no.spam (Eric Brunel) Date: Fri, 16 Jan 2009 10:47:36 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: <27a0eafd-d4bf-4daf-a98e-96e3f72ac776@v39g2000pro.googlegroups.com> <4ac68f93-af47-41d7-837c-3fb029286417@y1g2000pra.googlegroups.com> Message-ID: On Thu, 15 Jan 2009 19:09:00 +0100, Jos? Matos wrote: > On Thursday 15 January 2009 15:28:36 r wrote: >> First of all be very careful using from "module" import * or you will >> have name conflicts. Tkinter is made to be imported this way and i do >> it all the time. for the others do. >> >> import tkMessageBox as MB >> import tkFileDialog as FD >> or whatever floats your boat. > > Importing explicitly works for me in Fedora 11 (rawhide): > ----------------------------- > from Tkinter import * > from tkMessageBox import askyesno > from tkFileDialog import askopenfilename [snip] What do you mean by 'works'...? You don't have the problem? It doesn't change a thing for me... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From see.signature at no.spam Fri Jan 16 04:48:09 2009 From: see.signature at no.spam (Eric Brunel) Date: Fri, 16 Jan 2009 10:48:09 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy wrote: > Eric Brunel wrote: [snip]>> And BTW, if this is actually a bug, where can I report it? > > bugs.python.org Thanks. I reported the problem. -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From bieffe62 at gmail.com Fri Jan 16 04:52:49 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Fri, 16 Jan 2009 01:52:49 -0800 (PST) Subject: Client Socket Connection to Java server References: Message-ID: <29aac845-7323-456e-8505-35d3f7bd4631@o40g2000prn.googlegroups.com> On 16 Gen, 08:10, TechieInsights wrote: > I am having problems with a socket connection to a Java server. ?In > java I just open the socket, pass the length and then pass the bits > across the socket. > > I created a socket object: > > import socket > > class MySocket: > ? ? ? ? def __init__(self, host='localhost', port = 28192, buffsize = 1024): > ? ? ? ? ? ? ? ? socket.setdefaulttimeout(10) > > ? ? ? ? ? ? ? ? self.host = host > ? ? ? ? ? ? ? ? self.port = port > ? ? ? ? ? ? ? ? self.buffsize = buffsize > ? ? ? ? ? ? ? ? self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > ? ? ? ? ? ? ? ? self.socket.connect((host, port)) > > ? ? ? ? def send(self, data): > ? ? ? ? ? ? ? ? self.socket.send(data) > > ? ? ? ? def receive(self): > ? ? ? ? ? ? ? ? return self.socket.recv(self.buffsize) > > ? ? ? ? def sendAndReceive(self, data): > ? ? ? ? ? ? ? ? self.send(data) > ? ? ? ? ? ? ? ? return self.receive() > > ? ? ? ? def close(self): > ? ? ? ? ? ? ? ? self.socket.close() > > But the java server gives the error: > WARNING: Message length invalid. ?Discarding > > The data is of type string (xml). ?Am I doing something wrong? ?I know > you have to reverse the bits when communicating from C++ to Java. > Could this be the problem? I figured it would not because it said the > length was invalid. ?I just started looking at python sockets > tonight... and I don't have a real deep base with socket connections > as it is... any help would be greatly appreciated. > > Greg What is the server protocol? What are you sending? Saying 'xml' is not enough to understand the problem ... byte order could be a problem only if the message include binary representations of 2-bytes or 4-bytes integer. With XML this should not be the case Ciao ---- FB From duncan.booth at invalid.invalid Fri Jan 16 04:58:53 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 09:58:53 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 15, 1:08?pm, Duncan Booth wrote: >> Carl Banks wrote: >> > I don't see what the big deal is. ?Right now isinstance accepts a >> > typ > e >> > or a tuple of types. ?The code could be changed to allow a type, or >> > any iterable the returns types (wherein every items of the sequence >> > is required to be a type). ?What's messy about that? >> >> No, it isn't restricted to a type or a tuple of types: right now >> isinstan > ce >> accepts X where X is a type or a tuple of X. The definition is >> recursive, and the data structure can be deeply nested, but (because >> tuples are immutable) it cannot be infinite. >> >> e.g.>>> isinstance('x', (((((int, (float, str)),),),),)) >> >> True > > Oh. Not sure what the use case for THAT was, but that would make > things messy. > Duck typing purism? If you can use it to specify an exception you want to handle, then you can put it in a tuple with other exception specifications you can also handle. If you had to check whether it was a class or tuple to work out which sort of concatenation to use then you are breaking the first law of ducks. I think exception specifications came first and isinstance/issubclass followed suit, except of course exception specification were more complex as they could be classes, strings, or tuples of exception specifications. That still leaves the question whether anyone has ever actually taken advantage of this feature. You can do isinstance(x, (IntType, LongType, StringTypes)) but I didn't even know that StringTypes existed until a couple of moments ago, and I intend to forget about it again immediately. Grepping through the Python libraries on my system it looks like a lot of programmers don't even realise you can combine types into a tuple. -- Duncan Booth http://kupuguy.blogspot.com From tjreedy at udel.edu Fri Jan 16 05:06:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 05:06:30 -0500 Subject: Alphametric fun with Python In-Reply-To: References: <914b48bc-640a-4690-85d8-65fa6de00156@f40g2000pri.googlegroups.com> <66212982-231d-4764-9496-5ea44f55a54f@a26g2000prf.googlegroups.com> <87161bca-212b-4368-87ed-d82e93419a77@n33g2000pri.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Terry Reedy: >> It illustrates well the point you intended. > > I don't know what my point was. I quoted and was responding to Raymond. > > A suggestion: with that solver, to find solution in a faster way you > have to write many equations. I did... one for each column + plus the implied one that digits represented by the same letter get same value and that those represented by different letters gets different values. From wuwei23 at gmail.com Fri Jan 16 05:15:41 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 02:15:41 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> Message-ID: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> On Jan 16, 5:39?pm, Erik Max Francis wrote: > Inform 7 has some > interesting ideas, but I think the general problem with English-like > programming language systems is that once you get into the nitty gritty > details, you end up having to know exactly the right things to type, This has always been my impression of Inform 7. I have a lot of respect for what they've set out to achieve but English isn't exactly known for its lack of ambiguity. This is great for literature but not so helpful for programming. > which ultimately get just as complicated as a more traditional > programming language syntax. And much more verbose, as well. From mikehartl at web.de Fri Jan 16 05:17:18 2009 From: mikehartl at web.de (Michael Hartl) Date: Fri, 16 Jan 2009 11:17:18 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: <49705EAE.4070006@web.de> James Stroud schrieb: > Ken Pu wrote: >> Hi, below is the code I thought should create two generates, it[0] = >> 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the >> same!!! >> >> from itertools import * >> itlist = [0,0] >> for i in range(2): >> itlist[i] = (x+(i*10) for x in count()) >> >> print "what's in the bags:" >> print list(islice(itlist[0], 5)) >> print list(islice(itlist[1], 5)) >> >> The output is: >> [10, 11, 12, 13, 14] >> [10, 11, 12, 13, 14] >> >> I see what Python is doing -- lazy evaluation doesn't evaluate >> (x+(i*10) for x in count()) until the end. > > It doesn't evaluate it until you ask it to, which is the right > behavior. However, when evaluated, it evaluates "i" also, which is the > last value to which "i" was assigned, namely the integer 1. I'm going > to get flamed pretty hard for this, but it doesn't seem to be the > intuitive behavior to me either. However, in a purely functional > language, you wouldn't be able to construct a list of generators in > this way. > > With python, you have to remember to adopt a purely functional design > and then pray for best results. You can store generators in a list, > but they need to be constructed properly. I can't perfectly > transmogrify your code into functional code because I don't think > making the particular anonymous generator you want is possible in > python. However this is how I would make a close approximation: > > > from itertools import * > > def make_gen(i): > for x in count(): > yield x + (i * 10) > > itlist = [make_gen(i) for i in xrange(2)] > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > > James > You could just as well use the original expression in make_gen, too: from itertools import * def make_gen(i): return (x + (i*10) for x in count()) itlist = [make_gen(i) for i in xrange(2)] print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) what's in the bags: [0, 1, 2, 3, 4] [10, 11, 12, 13, 14] From tjreedy at udel.edu Fri Jan 16 05:24:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 05:24:15 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xd4en4rbg.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> <7xd4en4rbg.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >>>> Have you looked at Tim Sweeney's talk that I mentioned in another post? >>>> http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... >> I did. He gives a really nice use case for Python's ability to >> dynamically modify classes imported from a library. (Were not you >> arguing against that? Or was is someone else?) > > He is talking about extending classes by something like inheritance, > not modifying them dynamically. This is also in the context of an > extremely powerful static type system with existential and dependent > types, and totality proofs for just about everything. That is about a > billion light years away from anything anyone has ever proposed for > Python. If the library framework were written in Python, one would have a choice between creating a parallel class hierachy (through inheritance) that dupicates *every* class in the original hierachy and dynamically patching just those classes that need to be changed. He only discussed the former option because that was the only one available. If, for instance, one only needed to change the base class, patching just that would be much easier. Hence my comment. tjr From ssalam at gmail.com Fri Jan 16 05:28:09 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Fri, 16 Jan 2009 15:58:09 +0530 Subject: PyPlot Message-ID: Hi , I need Pyplot module , How to get and install ( plug in with my python 2.4 distribution ) !!! TIA. Shah. From shi.dingan at gmail.com Fri Jan 16 05:31:02 2009 From: shi.dingan at gmail.com (shi dingan) Date: Fri, 16 Jan 2009 11:31:02 +0100 Subject: Problem using python C API Message-ID: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> Hi, I'm trying to use the Python C API but I have a problem when importing my new module. Here is my (short) code: #include "Python.h" long sumList(PyObject *list) { int i, n; long total = 0; PyObject *item; n = PyList_Size(list); if (n < 0) return NULL; for (i = 0; i < n; i++) { item = PyList_GetItem(list, i); if (!PyInt_Check(item)) continue; total += PyInt_AsLong(item); } return total; } PyObject *wrap_sumList(PyObject *self, PyObject *args) { PyObject *list; PyObject *total; if (!PyArg_ParseTuple(args, "0&", &list)) { return NULL; } total = Py_BuildValue("l", sumList(list)); return total; } static PyMethodDef exampleMethods[] = { {"sumList", wrap_sumList, METH_O}, {NULL} }; void initexample() { PyObject *m; m = Py_InitModule("example", exampleMethods); } My compilations lines: gcc -Wall -fpic -c -I/usr/include/python2.4 -I/usr/lib/python2.4/config mytest.c gcc -shared mytest.o -o examplemodule.so When I try to import examplemodule, I obtain the following message: >>> import examplemodule Traceback (most recent call last): File "", line 1, in ? ImportError: dynamic module does not define init function (initexamplemodule) Someone has an idea ? Thx, Marc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Jan 16 05:33:51 2009 From: http (Paul Rubin) Date: 16 Jan 2009 02:33:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <84420bcc-c3db-4bbb-ac56-b2c5a6e3442f@v5g2000prm.googlegroups.com> <7x7i4x3vc3.fsf@ruckus.brouhaha.com> <7xd4en4rbg.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3zee0g.fsf@ruckus.brouhaha.com> Terry Reedy writes: > If the library framework were written in Python, one would have a > choice between creating a parallel class hierachy (through > inheritance) that dupicates *every* class in the original hierachy and > dynamically patching just those classes that need to be changed. I think I understand what you're saying, but it could be handled with generics. From bborcic at gmail.com Fri Jan 16 05:37:01 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 16 Jan 2009 11:37:01 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> References: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Message-ID: The minimal correction, I guess, is to write itlist[i] = (x+(i*10) for i in [i] for x in count()) instead of itlist[i] = (x+(i*10) for x in count()) although itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) will better mimic generalizations in the sense that the "minimal correction" delays the evaluation of count(), which doesn't matter in the case of count(), but might make a difference if you replace it with some other expression. The point is that the first iterator-producing expression in a generator expression - eg the in ( for vars in ...) - is evaluated immediately in the surrounding context, in contrast to the rest of the genexp. Cheers, BB Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > > print "what's in the bags:" > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > > The output is: > [10, 11, 12, 13, 14] > [10, 11, 12, 13, 14] > > I see what Python is doing -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. But is this the right > behaviour? How can I get the output I want: > [0, 1, 2, 3, 4] > [10, 11, 12, 13, 14] > > Thanks. > > Ken > -- > http://mail.python.org/mailman/listinfo/python-list > From wuwei23 at gmail.com Fri Jan 16 05:45:56 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 02:45:56 -0800 (PST) Subject: lazy evaluation is sometimes too lazy... help please. References: Message-ID: <32b36c86-4ce5-4466-95e4-7d343fea1dad@q30g2000prq.googlegroups.com> James Stroud wrote: > I'm going to get flamed > pretty hard for this, but it doesn't seem to be the intuitive behavior > to me either. Given this is the second time this issue has come up today, I'd have to agree with you. From bborcic at gmail.com Fri Jan 16 05:46:17 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 16 Jan 2009 11:46:17 +0100 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: <4fbfbb8f0901152351p6088fab0r34663d40fcd2988d@mail.gmail.com> Message-ID: > itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) oops, that would be itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s) or equivalent, kind of ugly anyway. From benlucas99 at googlemail.com Fri Jan 16 05:57:18 2009 From: benlucas99 at googlemail.com (benlucas99 at googlemail.com) Date: Fri, 16 Jan 2009 02:57:18 -0800 (PST) Subject: Ordering of urlencoded tuples incorrect References: <55cb45b0-2036-4b63-a0b1-24bf3b77d8a5@v42g2000yqv.googlegroups.com> Message-ID: <034f2763-8c2a-478b-99b7-ba803276388c@k36g2000pri.googlegroups.com> On Jan 16, 1:44 am, John Machin wrote: > On Jan 16, 11:59 am, benluca... at googlemail.com wrote: > > > I'm having problems with the ordering of the tuples produced by > > urllib.urlencode. Taking an example straight from the docs and so > > doing the following: > > What are "the docs" you are reading that include such an example? The > docs distributed with Python 2.5.1 fromwww.python.orghave only this: > """ > urlencode( query[, doseq]) > > Convert a mapping object or a sequence of two-element tuples to a > ``url-encoded'' string, suitable to pass to urlopen() above as the > optional data argument. This is useful to pass a dictionary of form > fields to a POST request. The resulting string is a series of > key=value pairs separated by "&" characters, where both key and value > are quoted using quote_plus() above. If the optional parameter doseq > is present and evaluates to true, individual key=value pairs are > generated for each element of the sequence. When a sequence of two- > element tuples is used as the query argument, the first element of > each tuple is a key and the second is a value. The order of parameters > in the encoded string will match the order of parameter tuples in the > sequence. The cgi module provides the functions parse_qs() and > parse_qsl() which are used to parse query strings into Python data > structures. > """ > > > > > import urllib > > ... > > params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > > print params > > > The documentation for urlencode( query[, doseq]) says: "The order of > > parameters in the encoded string will match the order of parameter > > tuples in the sequence" but I'm getting: > > "query" can be either a mapping object (e.g. a dictionary, as you have > used) or a sequence of 2-tuples. No such guarantee as you quote above > can be made for a mapping; mappings are just not orderable. > If you want order, give it a sequence, like this: > > | >>> import urllib > | >>> urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0))) > | 'spam=1&eggs=2&bacon=0' > > HTH, > John Thanks guys, the explanations really helped. I knew I was missing something fundamental. The docs I'm referring is section "18.7.3 Examples" in the Python Library Reference, 18th April, 2007, Release 2.5.1 But looking at it now I guess the server side procsssing that post request may not care about ordering (unlike the web API I'm trying to call). cheers, Ben From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:03:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:03:24 GMT Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> Message-ID: <01806003$0$8693$c3e8da3@news.astraweb.com> On Wed, 14 Jan 2009 16:30:36 -0800, Aaron Brady wrote: > Hi, this is a continuation of something that comes up now and again > about reverse lookups on dictionaries, as well as a follow-up to my > pursuit of a Relation class from earlier. [...] > What's the best way to construct this class? Or, do you have an > argument that it could not be simpler than using a relational db? > Brainstorming, not flamestorming. Here's a lightweight solution that uses lazy calculation of the reverse dict. It makes a number of assumptions: - both keys and values will be hashable and unique; - the dict won't be so large that calculating the reverse dictionary will be time consuming; - modifications to instance.reverse are undefined. Usage: >>> d = ReverseDict(x=2, y=3, z=4) >>> d['x'] 2 >>> d.reverse[2] 'x' >>> d['a'] = 0 >>> d.reverse[0] 'a' def make_dirty(func): from functools import wraps @wraps(func) def f(self, *args, **kwargs): self._dirty = True return func(self, *args, **kwargs) return f # only tested a little bit class ReverseDict(dict): def __init__(self, *args, **kwargs): super(ReverseDict, self).__init__(*args, **kwargs) self._dirty = True @make_dirty def clear(): super(ReverseDict, self).clear() @make_dirty def __setitem__(self, key, value): super(ReverseDict, self).__setitem__(key, value) @make_dirty def __delitem__(self, key): super(ReverseDict, self).__delitem__() @make_dirty def pop(self, key, *arg): return super(ReverseDict, self).pop(key, *arg) @make_dirty def popitem(self): return super(ReverseDict, self).popitem() @make_dirty def setdefault(self, key, value=None): return super(ReverseDict, self).setdefault(key, value) @make_dirty def update(self, other): return super(ReverseDict, self).update(other) @property def reverse(self): if self._dirty: # Modify this to support repeated and non-hashable values. self._reverse = dict((value, key) for (key, value) in self.iteritems()) self._dirty = False return self._reverse An even more lightweight solution is to give up O(1) for the reverse lookup: # untested class ReversableDict(dict): def lookupvalue(self, value): for k,v in self.iteritems(): if v == value: return k raise ValueError('value not found') def lookupallvalues(self, value): results = [] for k,v in self.iteritems(): if v == value: results.append(k) return results -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:07:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:07:24 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> Message-ID: <018060f3$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 09:58:53 +0000, Duncan Booth wrote: > That still leaves the question whether anyone has ever actually taken > advantage of this feature. You can do isinstance(x, (IntType, LongType, > StringTypes)) but I didn't even know that StringTypes existed until a > couple of moments ago, and I intend to forget about it again > immediately. Grepping through the Python libraries on my system it looks > like a lot of programmers don't even realise you can combine types into > a tuple. I do it a lot, except I don't bother with IntType, LongType etc (I assume you imported them from the types module). I just do: isinstance(x, (int, float)) # or whatever -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 06:23:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 11:23:34 GMT Subject: lazy evaluation is sometimes too lazy... help please. References: Message-ID: <018064bd$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 02:51:43 -0500, Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! [...] > I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10) > for x in count()) until the end. But is this the right behaviour? How > can I get the output I want: [0, 1, 2, 3, 4] > [10, 11, 12, 13, 14] The solution I would use is: itlist = [0,0] for i in range(2): itlist[i] = ( lambda i: (x+(i*10) for x in count()) )(i) Or pull the lambda out of the loop: itlist = [0,0] def gen(i): return (x+(i*10) for x in count()) for i in range(2): itlist[i] = gen(i) -- Steven From hackingkk at gmail.com Fri Jan 16 06:32:09 2009 From: hackingkk at gmail.com (Krishnakant) Date: Fri, 16 Jan 2009 17:02:09 +0530 Subject: confused about publishing more than one class in twisted server. In-Reply-To: References: Message-ID: <1232105529.15347.8.camel@krishna-laptop> hello, I am writing a twisted based rpc service where I am implementing a complete application as a service. I have many modules which make a package. Now when we publish a service in twisted, we have to create one instance of a certain class and then publish it with the help of reactor. but in my application, there are more than one class in different .py files. Now I want to know how do i create a package where all the classes in different modules get published so that the entire package can be used as the rpc server application and the client can be used to query any module. for example I have classes to get and set vendor, product, bills etc. now all this has to be accessed through the xml rpc service. Can some one tell me how to manage the entire twisted package as a service. happy hacking. Krishnakant. From alfons.nonell at upf.edu Fri Jan 16 07:02:59 2009 From: alfons.nonell at upf.edu (Alfons Nonell-Canals) Date: Fri, 16 Jan 2009 13:02:59 +0100 Subject: Integrating awk in Python Message-ID: <1232107379.25150.46.camel@king.imim.es> Hello, I'm developing a software package using python. I've programmed all necessary tools but I have to use other stuff from other people. Most of these external scripts are developed using awk. At the beggining I thought to "translate" them and program them in python but I prefer to avoid it because it means a lot of work and I should do it after each new version of this external stuff. I would like to integrate them into my python code. I know I can call them using the system environment but it is slower than if I call them inside the package. I know it is possible with C, do you have experience on integrate awk into python calling these awk scripts from python? Thanks in advance! Regards, Alfons. -- ------------ Alfons Nonell-Canals, PhD Chemogenomics Lab Research Group on Biomedical Informatics (GRIB) - IMIM/UPF Barcelona Biomedical Research Park (PRBB) C/ Doctor Aiguader, 88 - 08003 Barcelona alfons.nonell at upf.edu - http://cgl.imim.es Tel. +34933160528 http://alfons.elmeuportal.cat http://www.selenocisteina.info -------------- next part -------------- An HTML attachment was scrubbed... URL: From siona at chiark.greenend.org.uk Fri Jan 16 07:09:47 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 16 Jan 2009 12:09:47 +0000 (GMT) Subject: mimetypes oddity References: Message-ID: In article , wrote: > [mimetype weirdness reported] > Sion> Is this a bug? >Might be. Can you file a bug report in the Python issue tracker with a >small script that demonstrates the behavior? http://bugs.python.org/issue4963 (It's tagged as being 2.4 and 2.5 because those are the versions I have to hand to confirm it on, but I'd be rather surprised if it's not still like this in 2.6.) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From jnoller at gmail.com Fri Jan 16 07:15:25 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 16 Jan 2009 07:15:25 -0500 Subject: multiprocessing vs. distributed processing In-Reply-To: References: Message-ID: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> On Fri, Jan 16, 2009 at 12:52 AM, James Mills wrote: > I've noticed over the past few weeks lots of questions > asked about multi-processing (including myself). > > For those of you new to multi-processing, perhaps this > thread may help you. Some things I want to start off > with to point out are: > > "multiprocessing will not always help you get things done faster." > > "be aware of I/O bound applications vs. CPU bound" > > "multiple CPUs (cores) can compute multiple concurrent expressions - > not read 2 files concurrently" > > "in some cases, you may be after distributed processing rather than > multi or parallel processing" > > cheers > James James is quite correct, and maybe I need to amend the multiprocessing documentation to reflect this fact. While distributed programming and parallel programming may cross paths in a lot of problems/applications, you have to know when to use one versus the other. Multiprocessing only provides some basic primitives to help you get started with distributed programming, it is not it's primary focus, nor is it a complete solution for distributed applications. That being said, there is no reason why you could not use it in conjunction with something like Kamaelia, pyro, $ipc mechanism/etc. Ultimately, it's a tool in your toolbox, and you have to judge and experiment to see which tool is best applied to your problem. In my own work/code, I use both processes *and* threads - one works better than the other depending on the problem. For example, a web testing tool. This is something that needs to generate hundreds of thousands of HTTP requests - not a problem you want to use multiprocessing for given that A> It's primarily I/O bound and B> You can generate that many threads on a single machine. However, if I wanted to say, generate hundreds of threads across multiple machines, I would (and do) use multiprocessing + paramiko to construct a grid of machines and coordinate work. That all being said: multiprocessing isn't set in stone - there's room for improvement in the docs, tests and code, and all patches are welcome. -jesse From jnoller at gmail.com Fri Jan 16 07:33:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 16 Jan 2009 07:33:34 -0500 Subject: process/thread instances and attributes In-Reply-To: References: <496F03B9.8090100@shopzeus.com> Message-ID: <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> On Thu, Jan 15, 2009 at 10:37 PM, James Mills wrote: > After some work ... I've taken Laszlo's suggestion of using Value > (shared memory) objects > to share state between the -pseudo- Process (manager) object and it's > underlying multiprocessing.Process > instance (and subsequent process): > > Here is the code: > > ---------------------------------------- > #!/usr/bin/env python > > import os > from time import sleep > > from threading import activeCount as threads > from threading import Thread as _Thread > > from multiprocessing import Value > from multiprocessing import Process as _Process > from multiprocessing import active_children as processes > > class Process(object): > > def __init__(self, *args, **kwargs): > super(Process, self).__init__(*args, **kwargs) > > self.running = Value("b", False) > self.thread = _Thread(target=self.run) > self.process = _Process(target=self._run, args=(self.running,)) > > def _run(self, running): > self.thread.start() > > try: > while running.value: > try: > sleep(1) > print "!" > except SystemExit: > running.acquire() > running.value = False > running.release() > break > except KeyboardInterrupt: > running.acquire() > running.value = False > running.release() > break > finally: > running.acquire() > running.value = False > running.release() > self.thread.join() > > def start(self): > self.running.acquire() > self.running.value = True > self.running.release() > self.process.start() > > def run(self): > pass > > def stop(self): > print "%s: Stopping ..." % self > self.running.acquire() > self.running.value = False > self.running.release() > > def isAlive(self): > return self.running.value > > class A(Process): > > def run(self): > while self.isAlive(): > sleep(5) > self.stop() > > a = A() > a.start() > > N = 0 > > while a.isAlive(): > sleep(1) > print "." > print "threads: %d" % threads() > print "processes: %d" % len(processes()) > > print "DONE" > ---------------------------------------- > > Here is the result of running this: > > ---------------------------------------- > $ python test3.py > ! > . > threads: 1 > processes: 1 > . > threads: 1 > processes: 1 > ! > ! > . > threads: 1 > processes: 1 > . > threads: 1 > processes: 1 > ! > . > threads: 1 > processes: 1 > ! > <__main__.A object at 0x80de42c>: Stopping ... > ! > . > threads: 1 > processes: 0 > DONE > ---------------------------------------- > > This appears to work as I intended. > > Thoughts / Comments ? > > cheers > James Personally, rather then using a value to indicate whether to run or not, I would tend to use an event to coordinate start/stop state. -jesse From w.richert at gmx.net Fri Jan 16 07:34:28 2009 From: w.richert at gmx.net (Willi Richert) Date: Fri, 16 Jan 2009 13:34:28 +0100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: <200901161334.28275.w.richert@gmx.net> Hi, take a look at the 5th link at http://tinyurl.com/7s8kfq It's called pyawk. Regards, wr Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program them in > python but I prefer to avoid it because it means a lot of work and I > should do it after each new version of this external stuff. I would like > to integrate them into my python code. > > I know I can call them using the system environment but it is slower > than if I call them inside the package. I know it is possible with C, do > you have experience on integrate awk into python calling these awk > scripts from python? > > Thanks in advance! > > Regards, > Alfons. From ajaksu at gmail.com Fri Jan 16 07:35:23 2009 From: ajaksu at gmail.com (ajaksu) Date: Fri, 16 Jan 2009 04:35:23 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> Message-ID: On Jan 16, 5:09?am, mario ruggier wrote: > Laboriously doing all these > checks on each expr eval will be very performance heavy, so I hope to > be able to limit access to all these more efficiently. Suggestions? None regarding the general issue, a try:except to handle this one: '(x for x in ()).throw("bork")' From mail at microcorp.co.za Fri Jan 16 07:38:51 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 16 Jan 2009 14:38:51 +0200 Subject: Convention vs. fascism [OT] References: <6t8comF9ou5uU1@mid.uni-berlin.de><017f44a3$0$8693$c3e8da3@news.astraweb.com><87zlhsb81i.fsf_-_@benfinney.id.au><017fb1f3$0$8693$c3e8da3@news.astraweb.com><87vdsgb1b0.fsf@benfinney.id.au><017fce36$0$8693$c3e8da3@news.astraweb.com><95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <000c01c977e8$87ac3de0$0d00a8c0@hendrik> "Steven D'Aprano" wrote: >And... skull socks? Cool. Where can I get some? Don't you remember? - Google the group - there was some dust raised about them some time ago. I think he got them from KDW - "Kaufhaus Der Welt" aka "Klau Dir Was" :-) - Hendrik From steve at holdenweb.com Fri Jan 16 08:22:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 08:22:36 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: Russ P. wrote: [...] > I spent *way* too much time on that post. I really need to quit > spending my time refuting the baloney that passes for wisdom here. He who cannot ignore baloney is doomed to refute it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From es at ertes.de Fri Jan 16 08:34:41 2009 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Fri, 16 Jan 2009 14:34:41 +0100 Subject: Experiment: Church lists in Python Message-ID: <20090116143441.5f0f8e8f@ertes.de> Hello there Pythoners, It was almost a week ago, when I got bored and thought, Python is quite a boring language, so I'd need to do some evil functional programming again. I thought, I'd share the result. ;) This time, I added a Church style representation for lists [1] to Python. The problem they solve: What do you do, if you've got only scalar values, functions and function application, but you need lists? Here is the solution: Represent lists as higher order functions: def empty(): return lambda f, z: z def cons(x, xs): return lambda f, z: f(x, xs(f, z)) def fold(f, z, xs): return xs(f, z) The empty() function returns an empty list and the cons() function returns the list in its second argument with the element in its first argument prepended, so cons(x, xs) is equivalent to the list [x] + xs. The 'fold' function is actually superfluous, but it makes much clearer what you're doing, when using this type of lists. It's the right-associative version of the 'reduce' function. All other list operations can be defined in terms of these three functions. I've done that for you [2] (mostly). If Python implements closures efficiently, this list representation is actually very fast for list folding, i.e. consuming an entire list to construct a value (which may be anything, including lists or functions). However, it's slow for extracting individual elements, because this operation must be a fold, too, as folding is the only way to access the elements of a list. An interesting property of this representation is that it gets along without any impure functions, i.e. all functions are completely free of side effects. Unless you use an impure fold function, everything is perfectly purely functional. Have fun. =) Greets, Ertugrul. [1] http://en.wikipedia.org/wiki/Church_encoding#Higher-order-function, a representation of a list as a higher order function. [2] http://ertes.de/python/fun/chlists.py, a little library of Python functions implementing Church style lists using higher order functions. The way the 'range' function is defined, was an experiment: how to emulate partial application in Python. Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/ From dougjrs at gmail.com Fri Jan 16 09:12:06 2009 From: dougjrs at gmail.com (Doug) Date: Fri, 16 Jan 2009 06:12:06 -0800 (PST) Subject: Soap Client References: <5947e87e-7679-4121-98f0-b77b2ae56be4@13g2000yql.googlegroups.com> Message-ID: <0c6d2f41-fd4b-464c-afa5-2559b2c85ae0@y1g2000pra.googlegroups.com> I believe that I have answered my own question. If anyone else is interested in what I did ... using iPython's code completion (. then hit tab tab) I noticed that msg had a _request attribute. I set that attribute to "1" and that sent the message that I needed! Hope everyone has a great day! Doug From johnroth1 at gmail.com Fri Jan 16 09:23:18 2009 From: johnroth1 at gmail.com (John Roth) Date: Fri, 16 Jan 2009 06:23:18 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: On Jan 16, 3:15?am, alex23 wrote: > On Jan 16, 5:39?pm, Erik Max Francis wrote: > > > Inform 7 has some > > interesting ideas, but I think the general problem with English-like > > programming language systems is that once you get into the nitty gritty > > details, you end up having to know exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but not > so helpful for programming. > > > which ultimately get just as complicated as a more traditional > > programming language syntax. > > And much more verbose, as well. Since I've used Inform 7 I can say that the syntactic problem isn't that great: once you get far enough into a project to matter the specialized constraints just sink in. It's more work to learn, but no stranger than Python's indentation scheme. The bigger problem for the comparison is that Inform 7 is a Domain Specific Language (DSL), not a general purpose language. Not only that, but the domain is pretty much everyday experience (with a large dollop of fantasy, of course). All the feedback is that the results are quite readable to non-programmers. This is why well over half of the mailing list posts on the authoring mailing list are about Inform 7. I really don't think that using natural language for a general purpose programming language is a good idea, for reasons that several other people have already said. I think it's a great idea for DSLs, at least in some cases. The other really major problem is that I don't think anyone really knows how to process natural language. The direction that natural language processing has taken in the last 50 years has come up lacking big-time. It does a good job in a single domain, but try to build something that crosses domains and nothing works. There isn't a good alternative in sight John Roth From james.colin.brady at gmail.com Fri Jan 16 09:25:55 2009 From: james.colin.brady at gmail.com (James Brady) Date: Fri, 16 Jan 2009 06:25:55 -0800 (PST) Subject: Readline and Python 2.6.1 on a Mac References: <4632a161-ed13-477c-a40a-2b606fda1c27@a29g2000pra.googlegroups.com> Message-ID: <31fc0495-3371-484d-9ab7-76074e39a54f@r10g2000prf.googlegroups.com> > s/"bind ^I rl_complete"/"tab: complete"/ > > > > -- > ?Ned Deily, > ?n... at acm.org Perfect, thanks Ned! From duncan.booth at invalid.invalid Fri Jan 16 09:29:18 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 14:29:18 GMT Subject: Python 3 isinstance References: <84B204FFB016BA4984227335D8257FBA7B9D48@CVCV0XI05.na.corning.com> <80c7cdc0-de7f-45ba-bffe-80da534e1332@o4g2000pra.googlegroups.com> <038208fe-27ca-4373-8afc-d49e57a14ea3@t11g2000yqg.googlegroups.com> <018060f3$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Jan 2009 09:58:53 +0000, Duncan Booth wrote: > >> That still leaves the question whether anyone has ever actually taken >> advantage of this feature. You can do isinstance(x, (IntType, >> LongType, StringTypes)) but I didn't even know that StringTypes >> existed until a couple of moments ago, and I intend to forget about >> it again immediately. Grepping through the Python libraries on my >> system it looks like a lot of programmers don't even realise you can >> combine types into a tuple. > > > I do it a lot, except I don't bother with IntType, LongType etc (I > assume you imported them from the types module). I just do: > > isinstance(x, (int, float)) # or whatever > Yes, I do that too, and naturally I don't use the types module. The question though was whether anyone, anywhere, has ever taken advantage of the fact that isinstance accepts *nested* tuples. My point was intended to be that perhaps if someone imported from the types module they might just use StringTypes in a tuple along with the single type names, but it seems pretty unlikely to be common usage. -- Duncan Booth http://kupuguy.blogspot.com From thomas.weholt at gmail.com Fri Jan 16 09:30:40 2009 From: thomas.weholt at gmail.com (Thomas W) Date: Fri, 16 Jan 2009 06:30:40 -0800 (PST) Subject: Start multiple listening servers in one file Message-ID: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> I`m working on a django-project where I`m using the awsome pyftpdlib for ftpserver-functionality. I also have a simple worker deamon running in the background, but not listening to any port. How can I start all of these processes on one file? Tried using subprocess and popen but that resulted in an eternal loop starting the servers over and over until all resources were used, then crash. Any hint on how to do this would be highly appreciated. From kyrie at uh.cu Fri Jan 16 09:36:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 16 Jan 2009 09:36:11 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <1232116571.49709b5bbcacb@mail.uh.cu> Quoting "Russ P." : > On Jan 15, 12:21?pm, Bruno Desthuilliers > wrote: > > > Once again, the important point is that there's a *clear* distinction > > between interface and implementation, and that you *shouldn't* mess with > > implementation. > > If you "*shouldn't* mess with the implementation", then what is wrong > with enforcing that "shouldn't" in the language itself? Because, as a library user, it should be my power to chose when and how I _should_ mess with the implementation, not the compiler, and definitely not you. > So let's take the airplane example. Boeing and its contractors > probably has hundreds of programmers working on millions of lines of > code. If they believed you, they would abandon enforced data hiding, > and programmers would have much more discretion to screw around with > code that they don't work on directly. An FMS programmer could perhaps > decide to change the parameters of the engine controls, for example. I really hope that, at Boeing, they do a lot of unit tests and code reviews before the code is commited. Messing with the internals wouldn't be the only bad thing that could happen, you know... And I'd say that "x._private" where x is not 'self', would be very easy to catch on those code reviews. And, as someone else pointed out, even with 'strong' enforcement of data-hiding, you can usually access the privates anyway - it's just a bit harder to do, and a lot harder to discover. You pointed out previously that Python wasn't up to the task of running untrusted code on my own application, and I agreed. _That_ is what you seem need, and enforced data hiding does very little towards it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From vedrandekovic at gmail.com Fri Jan 16 09:36:16 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Fri, 16 Jan 2009 06:36:16 -0800 (PST) Subject: Start two threads in same time Message-ID: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Hello, Does anybody know how can I start two threads in same time? Regards, John From mrkafk at gmail.com Fri Jan 16 09:38:23 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 15:38:23 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz8hzeo.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > 1) Parallelism. Commodity desktop computers now have 8 effective cpu > cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still > has the evil GIL that forces all threads to run on one core. Java, > Erlang, and Haskell (GHC) all beat Python in this area. By the time > Python 4 comes out, we will probably all be using PC's with 32 or more > cores, so the current limitations will be intolerable. Even today, > since no one doing anything serious uses single core machines any > more, the GIL is a huge pain in the neck which the multiprocessing > module helps only slightly. (While we are at it, lightweight threads > like Erlang's or GHC's would be very useful.) +100 for this one > 2) Native-code compilation. Per the Alioth shootouts, Python is much > slower (even on single cores) than Java, Haskell, ML, or even Scheme. > PyPy is addressing this but it will be a while before it replaces > CPython. The lack of this already causes some pains at my company. I was flabbergasted to read that optional static typing was dropped by Guido due to "lack of interest in community" IIRC. Why!! Among other reasons, this could have provided for very easy performance optimizations of the small portions of the code! This could have been a huge gain acquired for little effort! Regards, mk From google at mrabarnett.plus.com Fri Jan 16 09:39:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 14:39:44 +0000 Subject: English-like Python In-Reply-To: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: <49709C30.2050303@mrabarnett.plus.com> [Hit Reply instead of Reply All. Sorry alex23.] alex23 wrote: > On Jan 16, 5:39 pm, Erik Max Francis wrote: >> Inform 7 has some interesting ideas, but I think the general >> problem with English-like programming language systems is that once >> you get into the nitty gritty details, you end up having to know >> exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but > not so helpful for programming. > >> which ultimately get just as complicated as a more traditional >> programming language syntax. > > And much more verbose, as well. > I once had to do something in AppleScript. The problem I found was that it tried so much to resemble English that it wasn't always clear what was valid! Programming languages need to look artificial to remind you that the computers aren't intelligent. Python, for example, is clearly artificial but with a clear syntax and short (but not too short) reserved words. From google at mrabarnett.plus.com Fri Jan 16 09:43:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 14:43:53 +0000 Subject: Client Socket Connection to Java server In-Reply-To: References: Message-ID: <49709D29.609@mrabarnett.plus.com> TechieInsights wrote: > I am having problems with a socket connection to a Java server. In > java I just open the socket, pass the length and then pass the bits > across the socket. > > I created a socket object: > > import socket > > class MySocket: > def __init__(self, host='localhost', port = 28192, buffsize = 1024): > socket.setdefaulttimeout(10) > > self.host = host > self.port = port > self.buffsize = buffsize > self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self.socket.connect((host, port)) > > def send(self, data): > self.socket.send(data) I recommend sendall() instead of send(): self.socket.sendall(data) send() doesn't guarantee to send all the data, so multiple sends might be needed to send it all. sendall() does that for you. > > def receive(self): > return self.socket.recv(self.buffsize) > > def sendAndReceive(self, data): > self.send(data) > return self.receive() > > def close(self): > self.socket.close() > > But the java server gives the error: > WARNING: Message length invalid. Discarding > > The data is of type string (xml). Am I doing something wrong? I know > you have to reverse the bits when communicating from C++ to Java. > Could this be the problem? I figured it would not because it said the > length was invalid. I just started looking at python sockets > tonight... and I don't have a real deep base with socket connections > as it is... any help would be greatly appreciated. > > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From koranthala at gmail.com Fri Jan 16 09:46:54 2009 From: koranthala at gmail.com (koranthala) Date: Fri, 16 Jan 2009 06:46:54 -0800 (PST) Subject: Start two threads in same time References: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Message-ID: On Jan 16, 7:36?pm, vedrandeko... at gmail.com wrote: > Hello, > > Does anybody know how can I start two threads in same time? > > Regards, > John Use threading module. Creating a new thread is as easy as -- ----------------------------------------------------------------------- import threading class ThreadedClass(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): **Do whatever you want do in the new thread here** threaded_obj = ThreadedClass() threaded_obj.setDaemon(True) # If you want a daemon thread threaded_obj.start() # Start the new thread %%%%Do whatever you want to do in main thread here%%% threaded_obj.join() #Close the new thread by joining it with the main thread -------------------------------------------------------------------------------- The following document might be of help: http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf From koranthala at gmail.com Fri Jan 16 09:51:31 2009 From: koranthala at gmail.com (koranthala) Date: Fri, 16 Jan 2009 06:51:31 -0800 (PST) Subject: Start two threads in same time References: <1a0fdd3b-6a01-4857-8c14-b18debd077c9@r37g2000prr.googlegroups.com> Message-ID: <3a221f6e-de5b-41f9-b7c6-6368d9af47eb@r15g2000prh.googlegroups.com> On Jan 16, 7:46?pm, koranthala wrote: > On Jan 16, 7:36?pm, vedrandeko... at gmail.com wrote: > > > Hello, > > > Does anybody know how can I start two threads in same time? > > > Regards, > > John > > Use threading module. > Creating a new thread is as easy as -- > ----------------------------------------------------------------------- > import threading > > class ThreadedClass(threading.Thread): > ? ? def __init__(self): > ? ? ? ? threading.Thread.__init__(self) > > ? ? def run(self): > ? ? ? ? ?**Do whatever you want do in the new thread here** > > threaded_obj = ThreadedClass() > threaded_obj.setDaemon(True) ?# If you want a daemon thread > threaded_obj.start() # Start the new thread > > %%%%Do whatever you want to do in main thread here%%% > > threaded_obj.join() #Close the new thread by joining it with the main > thread > > -------------------------------------------------------------------------------- > > The following document might be of help:http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf If you want to create n threads, just create and call the threaded_obj n times. So, the code will look like: threaded_obj = [] for i in range(n): threaded_obj[i] = ThreadedClass() threaded_obj[i].setDaemon(True) # If you want a daemon thread threaded_obj[i].start() # Start the new thread %%%%Do whatever you want to do in main thread here%%% #To close the threads for o in threaded_obj: o.join() --HTH-- From philip at semanchuk.com Fri Jan 16 09:58:54 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 16 Jan 2009 09:58:54 -0500 Subject: Problem using python C API In-Reply-To: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> References: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> Message-ID: <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> On Jan 16, 2009, at 5:31 AM, shi dingan wrote: > void initexample() { > PyObject *m; > m = Py_InitModule("example", exampleMethods); > } > > When I try to import examplemodule, I obtain the following message: >>>> import examplemodule > Traceback (most recent call last): > File "", line 1, in ? > ImportError: dynamic module does not define init function > (initexamplemodule) Hi Marc, The tutorial says, "The initialization function must be named initname(), where name is the name of the module". The error message you got is very accurate: "module does not define init function (initexamplemodule)". Since your module is called "examplemodule", Python is looking for a function called "initexamplemodule". Change your build step to build a module called "example" and not "examplemodule" and I think you'll be OK. bye Philip From Jean-Paul.VALENTIN at ingenico.com Fri Jan 16 10:24:52 2009 From: Jean-Paul.VALENTIN at ingenico.com (Jean-Paul VALENTIN) Date: Fri, 16 Jan 2009 16:24:52 +0100 Subject: output problem Message-ID: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> Feature? the output of below Hello program he0.py started from command line looks as follows: F:\prompt>he0.py Hello F:\prompt> 'Hello' was sent with sys.stdout.write, so "without newline". But why cannot be output (more logically): F:\prompt>he0.py HelloF:\prompt> Is it normal? Is there any means or workaround to obtain that output if I wish?? ________________________________________________________________________ ______________________ #!/usr/bin/python #-*- coding: iso-8859-15 -*- import sys sys.stdout.write('Hello') About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. P Please consider the environment before printing this e-mail From andy.goldschmidt at forlinux.co.uk Fri Jan 16 10:25:24 2009 From: andy.goldschmidt at forlinux.co.uk (Andy Goldschmidt) Date: Fri, 16 Jan 2009 15:25:24 +0000 Subject: bubblefishymon Message-ID: <1232119524.6985.39.camel@andy-desktop> Hi Guys I am trying to get bubblefishymon to work as a gdesklet. (app is written in python) The app seems to work, but it does display any water. I'm assuming its because it cant poll the network card etc. If I try run it on the command line it shows this error : $ python __init__.py Traceback (most recent call last): File "__init__.py", line 3, in from sensor.Sensor import Sensor ImportError: No module named sensor.Sensor In the dekslets log it also shows this : Deprecation: Sensors are deprecated since v0.30. Please consider using controls and inline scripts. Does that mean Sensors is no longer used / supported ? If so , what do I use in place of it ? Please note, I don't know how to code in Python (yet!) so any help would be much appreciated. Regards Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcglec at free.fr Fri Jan 16 10:30:12 2009 From: marcglec at free.fr (marcglec at free.fr) Date: Fri, 16 Jan 2009 16:30:12 +0100 Subject: Problem using python C API In-Reply-To: <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> References: <530f4bd60901160231h59ebebb0w89935f27b455cca7@mail.gmail.com> <81E3E62D-6FFD-48BE-AD4C-182057524BEA@semanchuk.com> Message-ID: <1232119812.4970a80453395@imp.free.fr> Right, thx for your reply, I completely overlooked "examplemodule.so" in the building step. Maybe I should sleep more these days :) Btw, I've now an other problem with PyArg_ParseTuple but I guess it is better to post in the capi-sig mailing list. Thx again, Marc. > > On Jan 16, 2009, at 5:31 AM, shi dingan wrote: > > > void initexample() { > > PyObject *m; > > m = Py_InitModule("example", exampleMethods); > > } > > > > When I try to import examplemodule, I obtain the following message: > >>>> import examplemodule > > Traceback (most recent call last): > > File "", line 1, in ? > > ImportError: dynamic module does not define init function > > (initexamplemodule) > > Hi Marc, > The tutorial says, "The initialization function must be named > initname(), where name is the name of the module". The error message > you got is very accurate: "module does not define init function > (initexamplemodule)". Since your module is called "examplemodule", > Python is looking for a function called "initexamplemodule". > > Change your build step to build a module called "example" and not > "examplemodule" and I think you'll be OK. > > bye > Philip > > -- > http://mail.python.org/mailman/listinfo/python-list > From sturlamolden at yahoo.no Fri Jan 16 10:31:36 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 16 Jan 2009 07:31:36 -0800 (PST) Subject: English-like Python References: <6taoivFa0390U1@mid.individual.net> Message-ID: <84364257-03ed-4503-9fce-e1bd44e6337d@g1g2000pra.googlegroups.com> On Jan 16, 8:39 am, Erik Max Francis wrote: > I was thinking of this as well when I saw his post. Inform 7 has some > interesting ideas, but I think the general problem with English-like > programming language systems is that once you get into the nitty gritty > details, you end up having to know exactly the right things to type, > which ultimately get just as complicated as a more traditional > programming language syntax. In the big picture I don't think it helps > much. After all, there's a reason that most modern programming > languages don't look like COBOL or AppleScript. COBOL looks like English to facilitate reading programs, not writing them. COBOL is for use in places where programs must be read and verified by possibly computer-illiterate personnel. E.g. in bank and finance where (at least in some countries) everything must be supervised and approved by professional accountants. COBOL is still the dominating language in that domain. From mrkafk at gmail.com Fri Jan 16 10:39:58 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 16:39:58 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xpriqmxky.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <7xpriqmxky.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > But, if something is done by convention, then departing from the > convention is by definition unconventional. If you do something > unconventional in a program, it could be on purpose for a reason, or > it could be by accident indicating a bug. I for one would love to see at least compiler warning (optionally, error) for situation where attributes are added to self outside of __init__. I consider it generally evil and hate to see code like that. Regards, mk From jcd at sdf.lonestar.org Fri Jan 16 11:01:18 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 16 Jan 2009 11:01:18 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: <01804283$0$8693$c3e8da3@news.astraweb.com> References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1232121678.6007.4.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > > > Oh come on you lot - you are carrying on as if Diez were wearing his > > skull socks again - do me a favour and give him a break! > And... skull socks? Cool. Where can I get some? > > http://www.letmegooglethatforyou.com/search?q=skull+socks From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 11:15:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jan 2009 16:15:49 GMT Subject: Skull Socks (was Re: Convention vs. fascism) References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> Message-ID: <0180a93a$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: >> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: >> >> > Oh come on you lot - you are carrying on as if Diez were wearing his >> > skull socks again - do me a favour and give him a break! > >> And... skull socks? Cool. Where can I get some? >> >> >> > http://www.letmegooglethatforyou.com/search?q=skull+socks Not Found The requested URL /search was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. You know, it was just a throw-away comment to lighten the mood. I don't really need to see 18,000+ links to places that sell socks with skulls printed on them. On the other hand, if they were socks made from actual skulls, that would be something... -- Steven From venkat83 at gmail.com Fri Jan 16 11:16:13 2009 From: venkat83 at gmail.com (Venkatraman.S.) Date: Fri, 16 Jan 2009 08:16:13 -0800 (PST) Subject: Client Socket Connection to Java server References: Message-ID: <13b2fafc-2c27-435c-a287-1842aadd8223@n33g2000pri.googlegroups.com> Hint: Java sends a '\n' character at the end. From http Fri Jan 16 11:19:47 2009 From: http (Paul Rubin) Date: 16 Jan 2009 08:19:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> Message-ID: <7xsknjp6jg.fsf@ruckus.brouhaha.com> mk writes: > I was flabbergasted to read that optional static typing was dropped by > Guido due to "lack of interest in community" IIRC. I don't remember that happening. PEP 3107 still lists type checking as a use case for Python 3.0 function annotations. From tjreedy at udel.edu Fri Jan 16 11:25:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:25:32 -0500 Subject: Integrating awk in Python In-Reply-To: <200901161334.28275.w.richert@gmx.net> References: <1232107379.25150.46.camel@king.imim.es> <200901161334.28275.w.richert@gmx.net> Message-ID: Willi Richert wrote: > Hi, > > take a look at the 5th link at http://tinyurl.com/7s8kfq > It's called pyawk. Stupid link wanting to set yet another useless cookie. Answer will not always be 5th. Just say 'Google pyawk' or better give link http://pyawk.sourceforge.net/ > Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: >> Hello, >> I'm developing a software package using python. I've programmed all >> necessary tools but I have to use other stuff from other people. Most of >> these external scripts are developed using awk. >> >> At the beggining I thought to "translate" them and program them in >> python but I prefer to avoid it because it means a lot of work and I >> should do it after each new version of this external stuff. I would like >> to integrate them into my python code. >> >> I know I can call them using the system environment but it is slower >> than if I call them inside the package. I know it is possible with C, do >> you have experience on integrate awk into python calling these awk >> scripts from python? From dotancohen at gmail.com Fri Jan 16 11:30:52 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 16 Jan 2009 18:30:52 +0200 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <880dece00901160830y5d068d90k2fe008c6f1b04b03@mail.gmail.com> 2009/1/16 The Music Guy : > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > This one is close: http://en.wikipedia.org/wiki/Brainfuck -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From speedup at gmail.com Fri Jan 16 11:41:21 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Fri, 16 Jan 2009 08:41:21 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? Message-ID: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Hi, I ran a few tests on the new Python 2.6 multiprocessing module before migrating a threading code, and found out the locking code is not working well. In this case, a pool of 5 processes is running, each trying to get the lock and releasing it after waiting 0.2 seconds (action is repeated twice). It looks like the multiprocessing lock allows multiple locking after the second pass. Running the exact same code with threads works correctly. Further down is the test code, output is great when running with threads (the sequence of lock/unlock looks good), but the output gets mixed up (mutliple locks in a row) when running with processes. My setup is : Mac OS X 10.5 running Python 2.6.1 from MacPython Did I do something wrong, or is there a limitation for multiprocessing locks that I am not aware of? Thank you for your help! -- Fred ------------------------------- #!/usr/bin/python # -*- coding: utf-8 -*- from multiprocessing import Process, Queue, Lock from Queue import Empty from threading import Thread import time class test_lock_process(object): def __init__(self, lock, id, queue): self.lock = lock self.id = id self.queue = queue self.read_lock() def read_lock(self): for i in xrange(2): self.lock.acquire() self.queue.put('[proc%d] Got lock' % self.id) time.sleep(.2) self.queue.put('[proc%d] Released lock' % self.id) self.lock.release() def test_lock(processes=10, lock=Lock(), process=True, queue=None): print_result = False if queue == None: print_result = True queue = Queue() threads = [] for i in xrange(processes): if process: threads.append(Process(target=test_lock_process, args=(lock,i,queue,))) else: threads.append(Thread(target=test_lock_process, args= (lock,i,queue,))) for t in threads: t.start() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == "__main__": #test_lock(processes=5, process=True) test_lock(processes=5) From tjreedy at udel.edu Fri Jan 16 11:42:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:42:51 -0500 Subject: mimetypes oddity In-Reply-To: References: Message-ID: Sion Arrowsmith wrote: > In article , > wrote: >> [mimetype weirdness reported] >> Sion> Is this a bug? >> Might be. Can you file a bug report in the Python issue tracker with a >> small script that demonstrates the behavior? > > http://bugs.python.org/issue4963 > > (It's tagged as being 2.4 and 2.5 because those are the versions I > have to hand to confirm it on, but I'd be rather surprised if it's > not still like this in 2.6.) Trying to reproduce a bug, as this report requires, is easier if you give code that can be copy and pasted into the interpreter or even into an edit window (as with IDLE) to be run from there. (3.0 version) import mimetypes print(mimetypes.guess_extension('image/jpeg')) mimetypes.init() print(mimetypes.guess_extension('image/jpeg')) From tjreedy at udel.edu Fri Jan 16 11:49:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 11:49:50 -0500 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: Eric Brunel wrote: > On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy wrote: >> Eric Brunel wrote: > [snip]>> And BTW, if this is actually a bug, where can I report it? >> >> bugs.python.org > > Thanks. I reported the problem. When you report that you reported to problem to the tracker (a good idea), please include link so anyone reading this thread can jump there to continue with followup there. From pruebauno at latinmail.com Fri Jan 16 11:54:22 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 16 Jan 2009 08:54:22 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <0c8c81f2-8a8d-4762-9a06-034a04506ebb@d36g2000prf.googlegroups.com> On Jan 15, 4:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. I am willing to bet a beer that the slow performance has nothing to do with the dict but is either because of MyClass or the read from disk. From lenz at joinville.udesc.br Fri Jan 16 12:01:57 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 09:01:57 -0800 Subject: multiprocessing question/error Message-ID: <200901160901.57232.lenz@joinville.udesc.br> Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code .... class Pygen3(self).... .... .... .... def calcula(self,indiv): .... .... .... def evaluate(self): .... .... indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From ianand0204 at gmail.com Fri Jan 16 12:02:08 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 16 Jan 2009 09:02:08 -0800 (PST) Subject: Beginner: Data type conversion question References: Message-ID: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> On Jan 15, 11:35?pm, Terry Reedy wrote: > flagg wrote: > > I am still fairly new to python and programming in general. ?My > > question is regardingdataconversion, I am working on a script that > > will edit dns zone files, one of the functions i wrote handles > > updating the serial number. > > Our zone files use the date as the first part of the serial and a two > > digit integer as the last two. > > > i.e. 2009011501. ?The next update would be 2009011502, etc > > Here is the function I wrote, I am using dnspython for reading in zone > > files as Zone "objects". ?Because dnspython's built-in serial updater > > will not work with how we format our serial's, I have to re-write it. > > > def checkSerial(): > > ? ? """ > > ? ? Checks the current 'date' portion of the serial number and > > ? ? checks the current 'counter'(the two digit number at the end of > > ? ? the serial number), then returns a complete new serial > > ? ? """ > > ? ? currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > ? ? for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ? date = str(rdata.serial)[0:8] > > ? ? ? ? inc = str(rdata.serial)[8:10] > > If rdate.serial is already a string, as name would imply, the str() call > is pointless. ?If not, can you get inc as int more directly? > > > > > ? ? if date == currentDate: > > ? ? ? ? int(inc) + 1 > > ? ? ? ? print inc > > ? ? ? ? newInc = str(inc).zfill(2) > > ? ? ? ? serial = date + newInc > > ? ? ? ? print "date is the same" > > ? ? ? ? return serial > > ? ? elif date < currentDate: > > ? ? ? ? newInc = "01".zfill(2) > > ? ? ? ? serial = currentDate + newInc > > ? ? ? ? print "date is different" > > ? ? ? ? return serial > > > Through all of this I am doing a lot ofdatatypeconversion. string - > >> integer, integer back to string, etc. ?Is this an efficient way of > > handling this? ?I have to perform basic addition on the "inc" > > variable, but also need to expose that value as a string. ? What I > > have above does work, but I can't help but think there is a more > > efficient way. I guess I am not used todatatypes being converted so > > easily. > > Other than that, you are perhaps worrying too much, even if code could > be squeezed more. ?The idea that every object knows how to convert > itself to a string representation is basic to Python. > > tjr Actually when i run a type(serial) on that variable it returns a "long" which i am not sure why dnspython uses a long variable to store the serial. But you could be right about me worrying to much. The other languages I have dabbled in (java, perl) I don't remember type conversion being as simple. But again I am still new, so don't quote me on that :) From Scott.Daniels at Acm.Org Fri Jan 16 12:07:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 16 Jan 2009 09:07:41 -0800 Subject: lazy evaluation is sometimes too lazy... help please. In-Reply-To: References: Message-ID: Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! > > from itertools import * > itlist = [0,0] > for i in range(2): > itlist[i] = (x+(i*10) for x in count()) > ... > print list(islice(itlist[0], 5)) > print list(islice(itlist[1], 5)) > ... -- lazy evaluation doesn't evaluate > (x+(i*10) for x in count()) until the end. Nope, that generator expression is evaluated in your assignment. The expression x+(i*10) is evaluated at each step of the generator. > But is this the right behaviour? It is the defined behavior. For what you want: import itertools as it def count_from(base): for n in it.count(): yield n + base itlist = [count_from(n) for n in range(2)] --Scott David Daniels Scott.Daniels at Acm.Org From mrkafk at gmail.com Fri Jan 16 12:09:45 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 18:09:45 +0100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: Alfons Nonell-Canals wrote: > At the beggining I thought to "translate" them and program them in > python but I prefer to avoid it because it means a lot of work and I > should do it after each new version of this external stuff. I would like > to integrate them into my python code. That's kind of like retrofitting steam engine onto a Mach 2 jetfighter. Well there's always awk2c.. Regards, mk From ianand0204 at gmail.com Fri Jan 16 12:14:17 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 16 Jan 2009 09:14:17 -0800 (PST) Subject: Beginner: Data type conversion question References: <6tas4tF9v94eU1@mid.uni-berlin.de> Message-ID: <1ac249a8-80f6-4983-ae7d-70e8e6c8c6ac@i24g2000prf.googlegroups.com> On Jan 15, 11:43?pm, Marc 'BlackJack' Rintsch wrote: > On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote: > > def checkSerial(): > > ? ? """ > > ? ? Checks the current 'date' portion of the serial number and checks > > ? ? the current 'counter'(the two digit number at the end of the serial > > ? ? number), then returns a complete new serial """ > > ? ? currentDate = ?time.strftime("%Y""%m""%d", time.localtime()) > > The format string can be written as *one* string literal instead of > three: "%Y%m%d". > > > ? ? for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ? date = str(rdata.serial)[0:8] > > ? ? ? ? inc = str(rdata.serial)[8:10] > > Here you are converting `rdata.serial` twice. > > ? ? ? ? ? tmp = str(rdata.serial) > ? ? ? ? ? date = tmp[0:8] > ? ? ? ? ? inc = int(tmp[8:10]) > > As `inc` is conceptually a number, you should do theconversionhere and > treat it as number from now on. > > > ? ? if date == currentDate: > > ? ? ? ? int(inc) + 1 > > ? ? ? ? print inc > > ? ? ? ? newInc = str(inc).zfill(2) > > ? ? ? ? serial = date + newInc > > ? ? ? ? print "date is the same" > > ? ? ? ? return serial > > ? ? elif date < currentDate: > > ? ? ? ? newInc = "01".zfill(2) > > ? ? ? ? serial = currentDate + newInc > > ? ? ? ? print "date is different" > > ? ? ? ? return serial > > Both branches do almost the same. ?You should try to avoid such code > duplication. > > ? ? ? if date == currentDate: > ? ? ? ? ? inc += 1 > ? ? ? elif date < currentDate: > ? ? ? ? ? inc = 1 > ? ? ? else: > ? ? ? ? ? assert False ? # Should never happen. > > ? ? ? return "%s%02d" % (date, inc) > > That's it. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch Ah return "%s%02d" % (date, inc) This piece is what I was missing in my original design. I couldn't figure out hot to take and integer and force it to my double digit. i.e. 01 instead of 1. Which is why I was using strings to make that happen. (obviously incorrectly). Thanks Could you explain what "assert" does in the if statement. I am assuming if the first two conditions are not met, it will hit "assert false" and exit the program? From alan.isaac at gmail.com Fri Jan 16 12:45:21 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 17:45:21 GMT Subject: Python 3: range objects cannot be sliced Message-ID: Is the behavior below expected? Documented? (The error msg is misleading.) Thanks, Alan Isaac >>> x = range(20) >>> s = slice(None,None,2) >>> x[s] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' From mario.ruggier at gmail.com Fri Jan 16 12:45:34 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Fri, 16 Jan 2009 09:45:34 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> Message-ID: <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> On Jan 16, 1:35?pm, ajaksu wrote: > On Jan 16, 5:09?am, mario ruggier wrote: > > > Laboriously doing all these > > checks on each expr eval will be very performance heavy, so I hope to > > be able to limit access to all these more efficiently. Suggestions? > > None regarding the general issue, a try:except to handle this one: > > '(x for x in ()).throw("bork")' What is the potential security risk with this one? To handle this and situations like the ones pointed out above on this thread, I will probably affect the following change to the evoque.evaluator.RestrictedEvaluator class, and that is to replace the 'if name.find("__")!=-1:' with an re.search... where the re is defined as: restricted = re.compile(r"|\.".join([ "__", "func_", "f_", "im_", "tb_", "gi_", "throw"])) and the test becomes simply: if restricted.search(name): All the above attempts will be blocked this way. Any other disallow- sub-strings to add to the list above? And thanks a lot Daniel, need to find a way to get somebeer over to ya... ;-) mario From google at mrabarnett.plus.com Fri Jan 16 12:59:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 17:59:48 +0000 Subject: Start multiple listening servers in one file In-Reply-To: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> References: <1fc6f52c-fd7e-4450-8556-04438963029d@x16g2000prn.googlegroups.com> Message-ID: <4970CB14.2010800@mrabarnett.plus.com> Thomas W wrote: > I`m working on a django-project where I`m using the awsome pyftpdlib > for ftpserver-functionality. I also have a simple worker deamon > running in the background, but not listening to any port. How can I > start all of these processes on one file? Tried using subprocess and > popen but that resulted in an eternal loop starting the servers over > and over until all resources were used, then crash. > > Any hint on how to do this would be highly appreciated. > Do you mean that your script is invoking itself? If yes, then could you pass something on the commandline to say "you're not the initial instance, so don't invoke yourself" and then check that? From fuzzyman at gmail.com Fri Jan 16 13:02:26 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 16 Jan 2009 10:02:26 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: <9a55e9b8-8b94-4762-87af-dbf753179b8d@v39g2000pro.googlegroups.com> On Jan 16, 5:45?pm, Alan G Isaac wrote: > Is the behavior below expected? Documented? > (The error msg is misleading.) > Thanks, > Alan Isaac > > ?>>> x = range(20) > ?>>> s = slice(None,None,2) > ?>>> x[s] > Traceback (most recent call last): > ? ?File "", line 1, in > TypeError: sequence index must be integer, not 'slice' Well, it has the same behaviour as the iterator returned by xrange in Python 2.X - so expected I guess. The error message is also the same in Python 2.X. Michael Foord -- http://www.ironpythoninaction.com/ From http Fri Jan 16 13:15:42 2009 From: http (Paul Rubin) Date: 16 Jan 2009 10:15:42 -0800 Subject: Python 3: range objects cannot be sliced References: Message-ID: <7xwscvp169.fsf@ruckus.brouhaha.com> Alan G Isaac writes: > >>> x = range(20) > >>> s = slice(None,None,2) > >>> x[s] > Traceback (most recent call last): > File "", line 1, in > TypeError: sequence index must be integer, not 'slice' range is an iterator now. Try itertools.islice. From http Fri Jan 16 13:17:59 2009 From: http (Paul Rubin) Date: 16 Jan 2009 10:17:59 -0800 Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> Message-ID: <7xsknjp12g.fsf@ruckus.brouhaha.com> mario ruggier writes: > All the above attempts will be blocked this way. Any other disallow- > sub-strings to add to the list above? I think what you are trying to do is fundamentally hopeless. You might look at web.py (http://webpy.org) for another approach, that puts a complete interpreter for a Python-like language into the template engine. From invalid at invalid Fri Jan 16 13:22:13 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 16 Jan 2009 12:22:13 -0600 Subject: Integrating awk in Python References: <1232107379.25150.46.camel@king.imim.es> Message-ID: Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals: > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program > them in python but I prefer to avoid it because it means a lot > of work and I should do it after each new version of this > external stuff. I would like to integrate them into my python > code. > > I know I can call them using the system environment but it is > slower than if I call them inside the package. So you've tried system(), and it didn't meet your requirements? > I know it is possible with C, What is possible with C? > do you have experience on integrate awk into python calling > these awk scripts from python? Just like in C, you can call them directory using fork/exec to eliminate the shell spawned by system(), but the difference in time is probably going to be negligible. If you're not able to meet your timing requirements using os.system(), then I suspect it's the awk programs that are too slow. I'd probably use the subprocess module to avoid the shell for security reasons. First, get it working. Then, after you've established that the program isn't meeting the timing specification _measure_ where the time is going. It's silly trying optimize the part of the program that's only taking up 1% of the execution time. "Premature optimization..." -- Grant Edwards grante Yow! They collapsed at ... like nuns in the visi.com street ... they had no teen appeal! From MatthewBrown at gmail.com Fri Jan 16 13:33:03 2009 From: MatthewBrown at gmail.com (Matt Brown - nyc) Date: Fri, 16 Jan 2009 10:33:03 -0800 (PST) Subject: minidom, drilling down to a low node in one line? Message-ID: <3bb1ea6b-0387-4be8-9f60-fff059c5e500@v4g2000vbb.googlegroups.com> Hello, I hope this isn't completely redundant... I'm working with an example found of parsing XML with xml.dom.minidom and am having some issues getting a node down three levels. Here is the tutorial: http://diveintopython.org/xml_processing/parsing_xml.html Given the XML: _____________

0

1

_____________ How do I address the textNode.data that = 0? The only way I figured out is to recursively childNode from the parsed down (as following the guide). Is there no way to simply address the item by something along the lines of: _____________ xmldoc = minidom.parse("example.xml") xmldoc.getElementsByTagName("grammar:ref:p:") _____________ Any input or direction is appreciated. Thanks! Matt From alan.isaac at gmail.com Fri Jan 16 13:36:34 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 18:36:34 GMT Subject: Python 3: range objects cannot be sliced In-Reply-To: <7xwscvp169.fsf@ruckus.brouhaha.com> References: <7xwscvp169.fsf@ruckus.brouhaha.com> Message-ID: On 1/16/2009 1:15 PM Paul Rubin apparently wrote: > range is an iterator now. Try itertools.islice. Well yes, it behaves like xrange did. But (also like xrange) it supports indexing. (!) So why not slicing? I expected this (to keep it functionally more similar to the old range). Alan Isaac From lists at cheimes.de Fri Jan 16 13:57:47 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jan 2009 19:57:47 +0100 Subject: Python 3: range objects cannot be sliced In-Reply-To: References: <7xwscvp169.fsf@ruckus.brouhaha.com> Message-ID: Alan G Isaac schrieb: > On 1/16/2009 1:15 PM Paul Rubin apparently wrote: >> range is an iterator now. Try itertools.islice. > > Well yes, it behaves like xrange did. > But (also like xrange) it supports indexing. (!) > So why not slicing? > I expected this (to keep it functionally > more similar to the old range). The old range function returned a list. If you need the old functionality you can use list(range(...))[]. Why do you want to slice a range anyway? The range type supports a start, stop and step argument. Christian From Lie.1296 at gmail.com Fri Jan 16 14:18:10 2009 From: Lie.1296 at gmail.com (Lie) Date: Fri, 16 Jan 2009 11:18:10 -0800 (PST) Subject: why o/p is different ??? References: <2967dcf3-96bd-4d69-9a78-cd0764f4b9ce@i20g2000prf.googlegroups.com> Message-ID: <117facb0-0e10-41d0-8ede-6aa207a7751d@g39g2000pri.googlegroups.com> On Jan 15, 1:34?pm, asit wrote: > I recently faced a peculiar o/p. > > My objective is to remove the command name(my script name) from > sys.argv[0]. > I coded like this > > import urllib > import sys > > print "\n\n\t\tlipun4u[at]gmail[dot]com" > print "\t\t------------------------" > > apppath = sys.argv[0].split("/") > appname = apppath[len(apppath)-1] > print appname > > if len(sys.argv) not in [2,3]: > ? ? print "Usage : " + appname + " [options]" > ? ? print "e.g. : " + appname + "www.google.com--verbose" > ? ? print "\n\t[option]" > ? ? print "\t\t--verbose/-V for verbose output" > ? ? print "\t\t-r for recursive scan" > ? ? sys.exit(1) > > site = appname.replace("http://","").rsplit("/",1)[0] > site = "http://" + site.lower() > print site > > It showed the required o/p in the IDLE > here is the o/p > > ? ? ? ? ? ? ? ? lipun4u[at]gmail[dot]com > ? ? ? ? ? ? ? ? ------------------------ > linkscan.py > Usage : linkscan.py [options] > e.g. : linkscan.pywww.google.com--verbose > > ? ? ? ? [option] > ? ? ? ? ? ? ? ? --verbose/-V for verbose output > ? ? ? ? ? ? ? ? -r for recursive scan > > Traceback (most recent call last): > ? File "I:/Python26/linkscan.py", line 18, in > ? ? sys.exit(1) > SystemExit: 1 > > But in command prompt the o/p is still faulty > > ? ? ? ? ? ? ? ? lipun4u[at]gmail[dot]com > ? ? ? ? ? ? ? ? ------------------------ > I:\Python26\linkscan.py > Usage : I:\Python26\linkscan.py [options] > e.g. : I:\Python26\linkscan.pywww.google.com--verbose > > ? ? ? ? [option] > ? ? ? ? ? ? ? ? --verbose/-V for verbose output > ? ? ? ? ? ? ? ? -r for recursive scan > > I:\Python26> > > regards > asit dhal Of course the pragmatic approach is just to include appname = 'linkscan.py' at the top of the document. I agree apppath might change (because you copied the program to different places, different bin directory on different machine), but there is no reason linkscan.py should change. And if you have to change the invoking name, sometimes it might be more useful for users to know the REAL name of the program (probably the user friendly version, e.g. "Link Scanner" or "Link Scanner 1.0"), instead of the name of the script it is run from (without the apppath). It is trivial for human user to guess where the script is located and what the appname is from the full apppath (path+name) From dragosmocrii at gmail.com Fri Jan 16 14:19:47 2009 From: dragosmocrii at gmail.com (Dragos) Date: Fri, 16 Jan 2009 11:19:47 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" Message-ID: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> I am trying to make a testing script to load/save cookies to a file with FileCookieJar, but it results in this error: FileCookieJar has not attribute "_self_load" This is my script: import urllib.request, urllib.parse,http.cookiejar url="http://localhost/test.php" cs=http.cookiejar.FileCookieJar() cs.load("cookies.txt",ignore_discard=False, ignore_expires=False) opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor (cs)) y=opener.open(url) print(y.read()) Thanks for helping. From mrkafk at gmail.com Fri Jan 16 14:26:54 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 20:26:54 +0100 Subject: Differences between class and function decorator Message-ID: Hello everyone, I rewrote an example someone posted here recently from: >>> def print_method_name(method): def new_meth(*args, **kwargs): print method.func_name return method(*args, **kwargs) return new_meth >>> @print_method_name def f2(): pass >>> f2() f2 ..to: >>> class MyMethod(object): def __init__(self, func): self.name = func.func_name self.func = func def __call__(self): print self.name return self.func >>> @MyMethod def f(): pass >>> f() f Note that function decorator returned None, while class decorator returned function. Why the difference in behavior? After all, print_method_name decorator also returns a function (well it's a new function but still a function)? Regards, mk From duncan.booth at invalid.invalid Fri Jan 16 14:38:21 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Jan 2009 19:38:21 GMT Subject: Differences between class and function decorator References: Message-ID: mk wrote: > Note that function decorator returned None, while class decorator > returned function. > > Why the difference in behavior? After all, print_method_name decorator > also returns a function (well it's a new function but still a function)? That would be because the function decorator returns the result of calling the function whereas your class decorator simply returns the function without calling it. From Russ.Paielli at gmail.com Fri Jan 16 14:44:46 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 16 Jan 2009 11:44:46 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> On Jan 16, 5:22 am, Steve Holden wrote: > Russ P. wrote: > > [...] > > > I spent *way* too much time on that post. I really need to quit > > spending my time refuting the baloney that passes for wisdom here. > > He who cannot ignore baloney is doomed to refute it. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ Yeah, and I should really learn to leave off those little zingers. If Mr. D weren't obviously an intelligent person and a Python expert, I wouldn't care what he writes. I just think that he, along with a few others here, love Python so much that they refuse to recognize its limitations. It's an easy trap to fall into. From gerald.britton at gmail.com Fri Jan 16 14:50:48 2009 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 16 Jan 2009 14:50:48 -0500 Subject: Lazy List Generator Problem Message-ID: <5d1a32000901161150y317fa2a2w605436effb10c791@mail.gmail.com> For those interested in the Sieve of Eratosthenes, have a look at: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf The examples in the paper are in Haskell, but I have been corresponding with the author who provided this Python version: def sieve(): innersieve = sieve() prevsquare = 1 table = {} i = 2 while True: if (table.has_key(i)): prime = table[i] del(table[i]) next = i+prime while next in table: next = next + prime table[next] = prime else: yield i if i > prevsquare: j = innersieve.next() prevsquare = j * j table[prevsquare] = j i = i + 1 Only of 65056 bytes (less than 1/16 MB) of heap is used when calculating the millionth prime. It is also very fast but can be even further optimized using a wheel as described in the paper. FWIW I was so intrigued I went off to learn Haskell just so I could follow the paper properly. From matthew at woodcraft.me.uk Fri Jan 16 14:53:46 2009 From: matthew at woodcraft.me.uk (Matthew Woodcraft) Date: Fri, 16 Jan 2009 19:53:46 GMT Subject: are there some special about '\x1a' symbol References: <28b65e59-a5be-4bd4-b28d-9c802c6b460c@d36g2000prf.googlegroups.com> <465f3133-6a4e-4779-a56e-bdcbb9ff17d9@r41g2000prr.googlegroups.com> <979e6566-75a8-4148-800f-40cf8158f46d@w1g2000prk.googlegroups.com> Message-ID: <87y6xb81th.fsf@golux.woodcraft.me.uk> Steve Holden writes: > Unknown wrote: >> On 2009-01-12, John Machin wrote: >> >>> I didn't think your question was stupid. Stupid was (a) CP/M recording >>> file size as number of 128-byte sectors, forcing the use of an in-band >>> EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF >>> decades after people stopped writing Ctrl-Z at the end of text files. >> >> I believe that "feature" was inherited by CP/M from DEC OSes >> (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API >> (including the FCB) was lifted almost directly from DEC's >> PDP-11 stuff, which probably copied it from PDP-8 stuff. >> >> Perhaps in the early 60's somebody at DEC had a reason. The >> really interesting thing is that we're still suffering because >> of it 40+ years later. >> > I suspect this is probably a leftover from some paper tape data formats, > when it was easier to detect the end of a file with a sentinel byte than > it was to detect run-off as end of file. It could easily date back to > the PDP-8. I think it was a reasonable way for CP/M to work. It's a nice simple interface for reading and writing files: you always read and write from/to a fixed 128-byte buffer. Allowing files to be arbitrary-length byte sequences would have made the system calls more complicated, and it would also have needed another byte in the on-disk file control block (so 7.3 filenames rather than 8.3, or some other compromise). For CP/M programs, it's hard to see what the gain would have been; it's easy to design a binary file format so that it doesn't matter whether or not there's junk on the end, and CP/M didn't have a tradition of storing data in 'plain text' files (for good reasons of disk space). It certainly is a shame that we didn't leave all this behind when MS/DOS 2 appeared, though. -M- From has.temp3 at virgin.net Fri Jan 16 14:57:24 2009 From: has.temp3 at virgin.net (has) Date: Fri, 16 Jan 2009 11:57:24 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> Message-ID: <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> On 16 Jan, 05:42, Chris Rebert wrote: > On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy wrote: > > > > > Just out of curiousity, have there been any attempts to make a version > > of Python that looks like actual English text? > > [...] > Does the name "AppleScript" mean anything to you? ;-) [quoting myself on the subject] The big advantage of AppleScript syntax is that it makes it easy to get a broad idea of what an existing AppleScript does, even if you don't know the AppleScript language in particular or programming in general. The big disadvantage of AppleScript syntax is that it makes it very difficult to form an accurate understanding of how it actually does it. For example, is 'foo bar' a property name, a constant name, a command name, a command name followed by a property/constant/variable name, or something else again? With more conventional language syntaxes, you have the opposite situation: in order to make any sense at all of an existing script, you first have to learn to read the syntax and know some basic programming. OTOH, once you're past that initial hurdle, it's easier to understand exactly what makes it tick, e.g. x.foo_bar is a property name, :foo_bar is a constant, foo_bar() is a command, foo(bar) is a command name followed by a variable name, and so on. The upshot of this is that AppleScript has a lower barrier to entry but higher cost of use compared to other languages. It's a trade-off, but one that probably fits quite well with the needs of many AppleScripters, who write relatively small programs on an irregular basis. A high cost of entry will be harder to justify if you don't actually use the language very often. OTOH, if you write large programs on a daily basis then what matters most is long-term productivity, and you'll recoup the time taken to learn a language fairly quickly by comparison. ... If you really want an end-user language that has the legibility of already-familiar natural languages while retaining all the precision provided by traditional programming syntax and adding a lot of much- needed interactive help and guidance, I think the best approach would be to go with an 'intelligent' structure editor a-la Scratch or Alice, rather than 'dumb' character-based source code as found in Python, AppleScript, Inform-7, C, et-al. See: http://scratch.mit.edu/ http://www.alice.org/ If you eliminate the need for syntax to describe structure, you can present programs in whatever way suits users best - be it English words in coloured blocks, or traditional brackets and braces. Plus it becomes an awful lot easier to help and correct novice users as they put together their first programs - much as the original Mac GUI provided much better input guidance and error prevention over previous DOS-style command lines. HTH has -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net From 9qobl2n02 at sneakemail.com Fri Jan 16 15:04:12 2009 From: 9qobl2n02 at sneakemail.com (Michael Hoffman) Date: Fri, 16 Jan 2009 12:04:12 -0800 Subject: Finding the full path of an executable Message-ID: Is there a portable way to find the full path of a filename that would be called by os.execvp()? Thanks, Michael Hoffman From max at alcyone.com Fri Jan 16 15:07:03 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Jan 2009 12:07:03 -0800 Subject: English-like Python In-Reply-To: <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> References: <6taoivFa0390U1@mid.individual.net> <807be841-2a3f-4a1d-935d-d8adc18a208a@s9g2000prg.googlegroups.com> Message-ID: alex23 wrote: > On Jan 16, 5:39 pm, Erik Max Francis wrote: >> Inform 7 has some >> interesting ideas, but I think the general problem with English-like >> programming language systems is that once you get into the nitty gritty >> details, you end up having to know exactly the right things to type, > > This has always been my impression of Inform 7. I have a lot of > respect for what they've set out to achieve but English isn't exactly > known for its lack of ambiguity. This is great for literature but not > so helpful for programming. > >> which ultimately get just as complicated as a more traditional >> programming language syntax. > > And much more verbose, as well. Agreed. I, too, am impressed with what the authors tried to do for Inform 7. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Laws are silent in time of war. -- Cicero From alan.isaac at gmail.com Fri Jan 16 15:13:00 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 20:13:00 GMT Subject: Python 3: range objects cannot be sliced In-Reply-To: References: Message-ID: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range From mrkafk at gmail.com Fri Jan 16 15:15:58 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 21:15:58 +0100 Subject: Class decorator with argument Message-ID: Hello, I wrote this class decorator with argument: >>> class ChangeDoc(object): def __init__(self, docstring): self.docstring = docstring def __call__(self, func): func.__doc__ = self.docstring return func It seems to work: >>> @ChangeDoc("bulba") def f(): pass >>> f.__doc__ 'bulba' Can someone please debug my reasoning if it's incorrect? 1. First, the decorator @ChangeDoc('bulba') instantiates with __init__(self, 'bulba'), to some class instance, let's call it _decor. 2. Then _decor's __call__ method is called with function f as argument, changing the docstring and returning the changed f object, like f = _decor(f) . Am I missing smth important / potentially useful in typical real-world applications in that picture? Regards, mk From alan.isaac at gmail.com Fri Jan 16 15:22:12 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 16 Jan 2009 20:22:12 GMT Subject: tuple methods: documentation missing Message-ID: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range I see no mention of the tuple methods? Right after the paragraph "Most sequence types support the following operations." it seems appropriate to have one stating "Most sequence types support the following methods: index() and count()." Alan Isaac From mrkafk at gmail.com Fri Jan 16 15:27:03 2009 From: mrkafk at gmail.com (mk) Date: Fri, 16 Jan 2009 21:27:03 +0100 Subject: *Advanced* Python book? Message-ID: Hello everyone, I looked for it I swear, but just can't find it. Most Python books seem to focus on examples of how to call functions from standard library. I don't need that, I have online Python documentation for that. I mean really advanced mental gymnastics, like gory details of how Python objects operate, how to exploit its dynamic capabilities, dos and donts with particular Python objects, advanced tricks, everything from chained decorators to metaprogramming. Dive Into Python comes closest to this ideal from what I have found, but still not far enough. Anybody found such holy grail? Regards, mk From clp2 at rebertia.com Fri Jan 16 15:35:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jan 2009 12:35:34 -0800 Subject: Class decorator with argument In-Reply-To: References: Message-ID: <50697b2c0901161235s23576a07l4979f07ebff7941f@mail.gmail.com> On Fri, Jan 16, 2009 at 12:15 PM, mk wrote: > Hello, > > I wrote this class decorator with argument: > >>>> class ChangeDoc(object): > def __init__(self, docstring): > self.docstring = docstring > def __call__(self, func): > func.__doc__ = self.docstring > return func > > It seems to work: > >>>> @ChangeDoc("bulba") > def f(): > pass > >>>> f.__doc__ > 'bulba' > > Can someone please debug my reasoning if it's incorrect? > > 1. First, the decorator @ChangeDoc('bulba') instantiates with __init__(self, > 'bulba'), to some class instance, let's call it _decor. > > 2. Then _decor's __call__ method is called with function f as argument, > changing the docstring and returning the changed f object, like f = > _decor(f) . Your reasoning is correct. > > Am I missing smth important / potentially useful in typical real-world > applications in that picture? You understand how it works, but apparently don't see its practical usefulness. Consider, for the sake of example, some class whose methods all must check that the provided login information is correct before performing their operation. Without decorators, the login-checking code would get repeated in every method. But we can avoid this by using decorators: def requires_login(meth): def replacement(self, username, password, *args, **kwargs): if not login_valid(username, password): raise ValueError("Incorrect login") return meth(self, *args, *kwargs) return replacement class RemoteAccount(object): @requires_login def show_file(self, filename): #implementation here... @requires_login def list_directory(self, dirname): #implementation here... Notice how we were able to eliminate the username and password parameter declarations and the 2 lines of irrelevant (from the POV of the individual methods) login-checking code from every method and put them in the decorator instead. All those saved lines add up to make the code more readable. Obviously this example is contrived, but it shows how decorators can help you to address cross-cutting concerns in Python. In practice, functions might have multiple, more complicated decorators applied to them, thus increasing the gain from using decorators. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From invalid at invalid Fri Jan 16 15:44:33 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 16 Jan 2009 14:44:33 -0600 Subject: Finding the full path of an executable References: Message-ID: On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: > Is there a portable way to find the full path of a filename that would > be called by os.execvp()? Yes. Use os.path.abspath() on the name before you call it with os.execvp() -- Grant Edwards grante Yow! ! The land of the at rising SONY!! visi.com From jeanclaudearbaut at orange.fr Fri Jan 16 15:53:19 2009 From: jeanclaudearbaut at orange.fr (Jean-Claude Arbaut) Date: Fri, 16 Jan 2009 21:53:19 +0100 Subject: *Advanced* Python book? In-Reply-To: References: Message-ID: <4970f3bf$0$9393$ba4acef3@news.orange.fr> mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. IMHO, you don't need an advanced *python* book. If you know the documentation and basic tutorials, then you know enough python to write almost anything you may need. The exception may be, again IMO: - tkinter, that will need some more work, - and C extensions, that are made easier by SWIG. But I think these topics are adressed by books you already found too simple. What you need next is: - read code that do something interesting, for example here http://www.ics.uci.edu/~eppstein/PADS/ or in python sources (or find projects on sourceforge, etc.) - find a book on advanced *what you want to do* There are good books on programming, like TAOCP or CLRS, but it's not necessarily what you are looking for. You may also find material in university CS sites: there is sometimes cool stuff. Start with MIT OCW if you want to try this. The real question is: what do you want to do with your python ? And don't forget to check with google if someone has already had the same idea in the same language, such things happen ;-) The "filetype:pdf" trick may help ! > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. > Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. I was about to tell you about it :-) > Anybody found such holy grail? 'never found a better grail than source code :-) From steve at holdenweb.com Fri Jan 16 16:41:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 16:41:02 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: <0180a93a$0$8693$c3e8da3@news.astraweb.com> References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> <0180a93a$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > >> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: >>> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: >>> >>>> Oh come on you lot - you are carrying on as if Diez were wearing his >>>> skull socks again - do me a favour and give him a break! >>> And... skull socks? Cool. Where can I get some? >>> >>> >>> >> http://www.letmegooglethatforyou.com/search?q=skull+socks > > Not Found > The requested URL /search was not found on this server. > Additionally, a 404 Not Found error was encountered while trying to use > an ErrorDocument to handle the request. > > > > You know, it was just a throw-away comment to lighten the mood. I don't > really need to see 18,000+ links to places that sell socks with skulls > printed on them. > > On the other hand, if they were socks made from actual skulls, that would > be something... > Of course Cliff actually meant http://letmegooglethatforyou.com/?q=skull+socks Jokes are never as funny when they go wrong :) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Fri Jan 16 17:07:03 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jan 2009 22:07:03 +0000 Subject: Incorrect title case? Message-ID: <49710507.6060207@mrabarnett.plus.com> Python 2.6.1 I've just found that the following 4 Unicode characters/codepoints don't behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). For example, u"\u01C5".istitle() returns True and unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() returns u'\u01C4', which is the uppercase equivalent. Are these mistakes in the Unicode database? From cs at zip.com.au Fri Jan 16 17:18:55 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 17 Jan 2009 09:18:55 +1100 Subject: spam on the list - how are things now? In-Reply-To: <001101c977b3$a9b91460$0d00a8c0@hendrik> Message-ID: <20090116221855.GA2253@cskk.homeip.net> On 16Jan2009 10:22, Hendrik van Rooyen wrote: | I read this solely via the mailing list - and Yes, whatever was done has helped | a lot. I use the mailing list. The spam is mch reduced. Thanks! -- Cameron Simpson DoD#743 From http Fri Jan 16 17:25:56 2009 From: http (Paul Rubin) Date: 16 Jan 2009 14:25:56 -0800 Subject: *Advanced* Python book? References: Message-ID: <7xprimsxaj.fsf@ruckus.brouhaha.com> mk writes: > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos > and donts with particular Python objects, advanced tricks, everything > from chained decorators to metaprogramming. Dive Into Python comes > closest to this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? The favorite ones around here are "Python Cookbook" and "Python in a Nutshell", both by Alex Martelli, who used to be a newsgroup regular and still stops by from time to time. From sandro at e-den.it Fri Jan 16 17:51:54 2009 From: sandro at e-den.it (Sandro Dentella) Date: Fri, 16 Jan 2009 22:51:54 GMT Subject: [ANN] sqlkit 0.8.5 Message-ID: I'm pleased to announce rel 0.8.5 of sqlkit, that adds many improvements. In this release localization has been added. I'd be very pleased if someone would like to contribute localization file for any language (but italian). Changes in this release: sqlkit 0.8.5 - 16.1.09 * localization: added localization for numbers and dates added localization for messages -- now waiting for translations ;-) -- * table: - added a smart way to automatically set dimentions of the table based on info retrieved from the database (thanks to Pietro Battiston) - complete rewrite of the column setup function - added a basic multiline cellRenderer - grately improved the navigation with Tab that now correctly triggers validation/completion * fields: many improvements in clean_value/validation * mask: - added handling of comments - fixed integer/float miniwiget (0 was rendered as '') - text now uses gtk.WRAP_WORD - fixed current_idx was a class attribute not an instance attr * layout: added check and hints on errors for Panes widgets * django_syntax: fix in typo * filters: fixed handlung of boolena & NULL check in related tables * signals: - record_selected -> record-selected to follow gtk standard - added records-displayed * widgets/layout: added label_map support * sqlwidget: rationalized menu entries The package ----------- SQLkit PyGtk package provides Mask and Table widgets to edit database data. It's meant as a base for database desktop applications. The application --------------- It also provides 'sqledit' a PyGTK application based on sqlkit that can be used from command line to browse and edit data. The package has 2 very rich demo suites for sql widgets (the main one in sqlkit/demo/sql/demo.py) and for layout creation Main features of sqlkit: ------------------------ * editor of databases in 2 modes: table & mask * based on sqlalchemy: can cope with many different databases * very powerfull filtering capabilities: - each field can be used to filter records - filter may span relationship - date filtering possible also on relative basis (good for saved queries) * completion on all text field and foreign keys * very easy way to draw a layout for mask views * completely effortless editing of relationships * very easy way to set defaults * possibility to display totals of numeric fields * any possible sql constraint can be attached to a Mask or a Table. It can be expressed a s a normal sqlalchemy query or with django-like syntax * sqledit: python script to edit db Sqlkit is based on: ------------------- * python (>= 2.4) * PyGtk * Sqlalchemy (>= 0.5) * glade * dateutils Dowload & more: --------------- * http://docs.argolinux.org/sqlkit/sqlkit/download.html * hg clone http://hg.argolinux.org/py/sqlkit * google group: http://groups.google.it/group/sqlkit/ * License: GNU GPL -- Sandro Dentella *:-) http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy From lawsonhanson at optusnet.com.au Fri Jan 16 18:03:51 2009 From: lawsonhanson at optusnet.com.au (Lawson Hanson) Date: Sat, 17 Jan 2009 10:03:51 +1100 Subject: dynamic module import? Message-ID: <49711259$0$23396$afc38c87@news.optusnet.com.au> Is it possible to import a module of Python code where I do not know the name of the module until run-time? The Python statement: from someModule import * requires that "someModule" be the name of the module, but what I would like is to be able to define a value for "someModule" ... and provided that such a module exists (in an extended "sys.path" directory), then import from the specified module at run-time If I have a module called "dummy.py" in my own "myModules" directory (just below my HOME directory in Linux) If I do this: import os, sys myModDir = os.environ["HOME"] + "/myModules" sys.path.append(myModDir) modName = "%s/%s" % (myModDir, "dummy") from modName import * I get the following error: ImportError: No module named modName So is there any way to get Python to import the named module without just doing "from dummy import *", because I will not know that the user wants to use the "dummy" module until run-time ... I'm trying to import control data for different run scenarios which will be defined in differently named Python modules which the user will specify at run-time with a command-line option And help with this would be most appreciated Best regards, Lawson Hanson ------ Melbourne, Victoria, Australia From ajaksu at gmail.com Fri Jan 16 18:04:33 2009 From: ajaksu at gmail.com (ajaksu) Date: Fri, 16 Jan 2009 15:04:33 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> Message-ID: <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> On Jan 16, 3:45?pm, mario ruggier wrote: > > '(x for x in ()).throw("bork")' > > What is the potential security risk with this one? I don't see a concrete issue, just found it tempting... raising hand- crafted objects :) > All the above attempts will be blocked this way. Any other disallow- > sub-strings to add to the list above? None that I know of, but I suggest testing with dir, globals, locals and '__' enabled (which I haven't done yet), as spotting possible flaws should be easier. If you can get BOM+encoded garbage tested (see http://tinyurl.com/72d98y ), it might be worth it too. This one fails in lots of interesting ways when you juggle keyword- args around: exprs = [ 'evoque("hmm", filters=[unicode.upper ] ,src="/etc/python2.5/ site.py")', ] > And thanks a lot Daniel, need to find a way to get somebeer over to > ya... ;-) You're welcome! Don't worry about the beer, I'd only consider a real promise if it involved chocolate :D Regards, Daniel From clp2 at rebertia.com Fri Jan 16 18:25:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jan 2009 15:25:38 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <50697b2c0901161525v15a79a19l5ea6f9deb7790d0c@mail.gmail.com> On Fri, Jan 16, 2009 at 3:03 PM, Lawson Hanson wrote: > Is it possible to import a module of Python code > where I do not know the name of the module > until run-time? Yes. Use the __import__() built-in function. See http://docs.python.org/library/functions.html#__import__ for details. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Fri Jan 16 18:44:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 18:44:16 -0500 Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: Alan G Isaac wrote: > http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range > > I see no mention of the tuple methods? > > Right after the paragraph > "Most sequence types support the following operations." > it seems appropriate to have one stating > "Most sequence types support the following methods: index() and count()." I addressed this and related issues in http://bugs.python.org/issue4966 Terry Jan Reedy From jnews at julius-net.net Fri Jan 16 18:47:47 2009 From: jnews at julius-net.net (Matthias Julius) Date: Fri, 16 Jan 2009 18:47:47 -0500 Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: <87wscuu82k.fsf@julius-net.net> Per Freem writes: > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so > my_dict[elt] works well. the __repr__ and __hash__ methods of my > class simply return str() representation of self, which just calls __str__(). I guess you are aware of that but you could call self.__str__() directly. Maybe that saves something when you do that 10 million times. > while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > def __str__(self): > return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > def __repr__(self): > return str(self) > > def __hash__(self): > return hash(str(self)) Maybe it would be faster to numerically combine the three fields instead of hashing the string representation. Matthias From akshayubhat at gmail.com Fri Jan 16 19:05:13 2009 From: akshayubhat at gmail.com (akshay bhat) Date: Fri, 16 Jan 2009 16:05:13 -0800 (PST) Subject: Need help with os.system in linux Message-ID: Hello i am calling a program using os.system in python on Linux. However in i found that program being executed and soon returned 256. but when i ran it using terminal i got proper results. Now in case of windows, python waits till the process is finished, Can you please tell me how to implement this in linux? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 19:13:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 00:13:49 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <01811941$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 21:34:01 -0800, Eduardo Lenz wrote: > modu = "os" > exec("from " + modu + " import *") "from module import *" is generally frowned upon, although it does occasionally have its uses. By the way, I think your computer's clock is set wrong. My newsclient is reporting that you sent your post at 4:30pm today -- and I'm writing this at 11am. Perhaps your timezone is set wrong? Regards, -- Steven From gert.cuykens at gmail.com Fri Jan 16 19:14:19 2009 From: gert.cuykens at gmail.com (gert) Date: Fri, 16 Jan 2009 16:14:19 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> Message-ID: <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> On Jan 16, 7:08?am, "Martin v. L?wis" wrote: > > ?s = urandom(10).encode('hex') > > > ?AttributeError: 'bytes' object has no attribute 'encode' > > py> binascii.hexlify(os.urandom(10)) > b'92b91d5734a9fe562f23' > sqlite3 s = hexlify(urandom(10)) db.execute('SELECT sid FROM sessions WHERE sid=?',(s)) ('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d') [error] Incorrect number of bindings supplied. The current statement uses 1, and there are 20 supplied. ??? From catphive at catphive.net Fri Jan 16 19:37:39 2009 From: catphive at catphive.net (Brendan Miller) Date: Fri, 16 Jan 2009 16:37:39 -0800 Subject: what's the point of rpython? Message-ID: So I kind of wanted to ask this question on the pypy mailing list.. but there's only a pypy-dev list, and I don't want to put noise on the dev list. What's the point of RPython? By this, I don't mean "What is RPython"? I get that. I mean, why? The goals of the pypy project seems to be to create a fast python implementation. I may be wrong about this, as the goals seem a little amorphous if you look at their home page. So, to do that this RPython compiler was created? Except that it doesn't compile python, it compiles a static subset of python that has type inference like ML. This RPython thing seems like a totally unnecessary intermediate step. Instead of writing an implementation of one language, there's an implementation of two languages. Actually, it seems like it harms the ultimate goal. For the interpreted pyton to be fast, the interpreter has to be written in a reasonably fast language. ML, and C++ compilers have had a lot of work put into their optimization steps. A lot of the performance boost you get from a static language is that knowing the types at compile time lets you inline code like crazy, unroll loops, and even execute code at compile time. RPython is a statically typed language because I guess the developers associate static languages with speed? Except that they use it to generate C code, which throws away the type information they need to get the speed increase. Huh? I thought the goal was to write a fast dynamic language, not a slow static one? Is this going anywhere or is this just architecture astronautics? The RPython project seems kind of interseting to me and I'd like to see more python implementations, but looking at the project I can't help but think that they haven't really explained *why* they are doing the things they are doing. Anyway, I can tell this is the sort of question that some people will interpret as rude. Asking hard questions is never polite, but it is always necessary :) Thanks, Brendan From gnewsg at gmail.com Fri Jan 16 19:47:52 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 16:47:52 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x Message-ID: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Hi, I'm sure the message I'm going to write will seem quite dumb to most people but I really don't understand the str/bytes/unicode differences introduced in Python 3.0 so be patient. What I'm trying to do is porting pyftpdlib to Python 3.x. I don't want to support Unicode. I don't want pyftpdlib for py 3k to do anything new or different. I just want it to behave exactly the same as in the 2.x version and I'd like to know if that's possible with Python 3.x. Now. The basic difference is that socket.recv() returns a bytes object instead of a string object and that's the thing which confuses me mainly. My question is: is there a way to convert that bytes object into exactly *the same thing* returned by socket.recv() in Python 2.x (a string)? I know I can do: data = socket.recv(1024) data = data.decode(encoding) ...to convert bytes into a string but that's not exactly the same thing. In Python 2.x I didn't have to care about the encoding. What socket.recv() returned was just a string. That was all. Now doing something like b''.decode(encoding) puts me in serious troubles since that can raise an exception in case client and server use a different encoding. As far as I've understood the basic difference I see now is that a Python 2.x based FTP server could handle a 3.x based FTP client using "latin1" encoding or "utf-8" or anything else while with Python 3.x I'm forced to tell my server which encoding to use and I don't know how to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib From gert.cuykens at gmail.com Fri Jan 16 19:54:40 2009 From: gert.cuykens at gmail.com (gert) Date: Fri, 16 Jan 2009 16:54:40 -0800 (PST) Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> Message-ID: <3c3f5984-0cb1-4be7-a548-08b9e34f06d4@g3g2000pre.googlegroups.com> On Jan 17, 1:14?am, gert wrote: > On Jan 16, 7:08?am, "Martin v. L?wis" wrote: > > > > ?s = urandom(10).encode('hex') > > > > ?AttributeError: 'bytes' object has no attribute 'encode' > > > py> binascii.hexlify(os.urandom(10)) > > b'92b91d5734a9fe562f23' > > sqlite3 > > ?s = hexlify(urandom(10)) > ?db.execute('SELECT sid FROM sessions WHERE sid=?',(s)) > > ('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d') > [error] Incorrect number of bindings supplied. The current statement > uses 1, and there are 20 supplied. > > ??? db.execute('SELECT sid FROM sessions WHERE sid=?',(s,)) This works ? Is this the new way to create a list in Python3.0 ? s=('test',) From luismgz at gmail.com Fri Jan 16 19:58:30 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 16 Jan 2009 16:58:30 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <90026f1a-be97-408b-aae4-416aa5f56df9@v42g2000yqj.googlegroups.com> On Jan 16, 9:37?pm, "Brendan Miller" wrote: > So I kind of wanted to ask this question on the pypy mailing list.. > but there's only a pypy-dev list, and I don't want to put noise on the > dev list. > > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? > > The goals of the pypy project seems to be to create a fast python > implementation. I may be wrong about this, as the goals seem a little > amorphous if you look at their home page. > > So, to do that this RPython compiler was created? Except that it > doesn't compile python, it compiles a static subset of python that has > type inference like ML. > > This RPython thing seems like a totally unnecessary intermediate step. > Instead of writing an implementation of one language, there's an > implementation of two languages. > > Actually, it seems like it harms the ultimate goal. For the > interpreted pyton to be fast, the interpreter has to be written in a > reasonably fast language. ML, and C++ compilers have had a lot of work > put into their optimization steps. A lot of the performance boost you > get from a static language is that knowing the types at compile time > lets you inline code like crazy, unroll loops, and even execute code > at compile time. > > RPython is a statically typed language because I guess the developers > associate static languages with speed? Except that they use it to > generate C code, which throws away the type information they need to > get the speed increase. Huh? I thought the goal was to write a fast > dynamic language, not a slow static one? > > Is this going anywhere or is this just architecture astronautics? > > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. > > Anyway, I can tell this is the sort of question that some people will > interpret as rude. Asking hard questions is never polite, but it is > always necessary :) > > Thanks, > Brendan Check out this thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1a8c866b4c4d7521/2174f796cd687931?lnk=gst&q=enlighten+pypy#2174f796cd687931 One of pypy's goals is having a more flexible implementation, easier to experiment with than cpython. Having all written in the same language facilitates this task. Why Rpython? Because by avoiding the dinamicity of the whole python language, it is possible to translate this code to a static one (c, java, whatever). The translated rpython interpreter aims to be something similar in performance to cpython. The only difference is that cpython was written from scratch in c, while pypy's interpreter was written in rpython and then translated automatically to c. The pypy team intends to achieve greater speed and performance by adding a JIT compiler to this interpreter. So pypy-c + JIT = faster python. I hope this helps... Luis From pythonnutter at gmail.com Fri Jan 16 20:01:57 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Sat, 17 Jan 2009 12:01:57 +1100 Subject: Integrating awk in Python In-Reply-To: <1232107379.25150.46.camel@king.imim.es> References: <1232107379.25150.46.camel@king.imim.es> Message-ID: If you or anyone who reads the thread is interested in using Python in an advanced way you use generators and build processing chains that will take the performance of Python to the edge and even give old AWK a run for its money for certain types of processing. Python: wwwlog = open("access-log") bytecolumn = (line.rsplit(None,1)[1] for line in wwwlog) bytes = (int(x) for x in bytecolumn if x != '-') print "Total", sum(bytes) Python execution time: 25.96 seconds AWK: % awk '{ total += $NF } END { print total }' big-access-log AWK execution time: 37.33 seconds With generators you can plug in filters at any stage: lines = lines_from_dir("big-access-log",".") lines = (line for line in lines if 'robots.txt' in line) log = apache_log(lines) addrs = set(r['host'] for r in log)the beauty of generators is that you can plug ?lters in at almost any stage The second line increased the execution time of a 1.3GB log file. Without it the execution was shameful at 53 minutes With the second line added execution time was 93 seconds David Beazley presented a great talk and accompanying PDF at PyCon'2008. It would be great if these generator tricks / patterns came more to the focus of the commuinity. Link if interested: http://www.dabeaz.com/generators/Generators.pdf 2009/1/16 Alfons Nonell-Canals : > Hello, > I'm developing a software package using python. I've programmed all > necessary tools but I have to use other stuff from other people. Most of > these external scripts are developed using awk. > > At the beggining I thought to "translate" them and program them in python > but I prefer to avoid it because it means a lot of work and I should do it > after each new version of this external stuff. I would like to integrate > them into my python code. > > I know I can call them using the system environment but it is slower than if > I call them inside the package. I know it is possible with C, do you have > experience on integrate awk into python calling these awk scripts from > python? > > Thanks in advance! > > Regards, > Alfons. > > > -- > ------------ > Alfons Nonell-Canals, PhD > Chemogenomics Lab > Research Group on Biomedical Informatics (GRIB) - IMIM/UPF > Barcelona Biomedical Research Park (PRBB) > C/ Doctor Aiguader, 88 - 08003 Barcelona > alfons.nonell at upf.edu - http://cgl.imim.es > Tel. +34933160528 > > http://alfons.elmeuportal.cat > http://www.selenocisteina.info > > -- > http://mail.python.org/mailman/listinfo/python-list > > From http Fri Jan 16 20:03:32 2009 From: http (Paul Rubin) Date: 16 Jan 2009 17:03:32 -0800 Subject: s = sha1(random()).hexdigest() References: <067b6b65-dc01-4752-b3e4-f600b57acc1c@f3g2000yqf.googlegroups.com> <7xy6xcqexy.fsf@ruckus.brouhaha.com> <4e731bc1-b1ff-4c77-b6fa-6a38dbbb7313@j39g2000yqn.googlegroups.com> <49702467$0$22823$9b622d9e@news.freenet.de> <72ae0268-dd84-4f45-a4dd-28df0a7880e0@w1g2000prm.googlegroups.com> <3c3f5984-0cb1-4be7-a548-08b9e34f06d4@g3g2000pre.googlegroups.com> Message-ID: <7xy6xaagm3.fsf@ruckus.brouhaha.com> gert writes: > Is this the new way to create a list in Python3.0 ? > s=('test',) That is a 1-tuple in both 2.x and 3.0. For a list, you'd say s = ['test'] From andrew at acooke.org Fri Jan 16 20:06:21 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 17:06:21 -0800 (PST) Subject: ABCs, functions, and __call__ (Python3) Message-ID: I think I'm missing something obvious here, so apologies in advance. I'd like to be able to test whether something is a function or implements __call__. Now obviously I can do that as two separate tests, but I though this was what ABCs were for. However, for the life of me I cannot find what the correct ABC would be. Does it exist? Is there some other, more traditional approach I should be using? Or do I have to roll my own somehow? Thanks for any guidance, Andrew From 9qobl2n02 at sneakemail.com Fri Jan 16 20:08:27 2009 From: 9qobl2n02 at sneakemail.com (Michael Hoffman) Date: Fri, 16 Jan 2009 17:08:27 -0800 Subject: Finding the full path of an executable In-Reply-To: References: Message-ID: Unknown wrote: > On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >> Is there a portable way to find the full path of a filename that would >> be called by os.execvp()? > > Yes. Use os.path.abspath() on the name before you call it with > os.execvp() That doesn't work: Python 2.5.2 (r252:60911, Sep 23 2008, 19:04:15) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath("echo") '/net/noble/vol2/home/mmh1/echo' >>> os.execvp(os.path.abspath("echo"), ["echo", "spam"]) Traceback (most recent call last): File "", line 1, in File "/net/noble/vol2/home/mmh1/arch/Linux-i386/opt/python-2.5.2/lib/python2.5/os.py", line 353, in execvp _execvpe(file, args) File "/net/noble/vol2/home/mmh1/arch/Linux-i386/opt/python-2.5.2/lib/python2.5/os.py", line 377, in _execvpe func(file, *argrest) OSError: [Errno 2] No such file or directory >>> os.execvp("echo", ["echo", "spam"]) spam The correct answer would be "/bin/echo" but abspath("echo") is just going to give me /echo. I need something that will search through the PATH like execvp() would. I can do it myself, but I'm surprised that such a feature is not already readily available somewhere. Michael From lists at cheimes.de Fri Jan 16 20:10:42 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:10:42 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: Giampaolo Rodola' schrieb: > Now. The basic difference is that socket.recv() returns a bytes object > instead of a string object and that's the thing which confuses me > mainly. > My question is: is there a way to convert that bytes object into > exactly *the same thing* returned by socket.recv() in Python 2.x (a > string)? Python 3.0's bytes type is almost the same type as Python 2.x's str type. During the development of Python 3.0 the old str type was modified and renamed to bytes. The old unicode type is now known as str. 2.x -> 3.0 ----------------- str -> bytes unicode -> str "" -> b"" u"" -> "" HTH Christian From andrew at acooke.org Fri Jan 16 20:11:07 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 17:11:07 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: <8e2af1ae-9d30-466d-889e-22526fd00ec1@e6g2000vbe.googlegroups.com> not direct answers, but.... reading through the recipes can be interesting - http://code.activestate.com/recipes/langs/python/ also, reading any good computing book and then wondering how you can do that in python can help shed a new light on things. andrew From tjreedy at udel.edu Fri Jan 16 20:11:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:11:44 -0500 Subject: Class decorator with argument In-Reply-To: References: Message-ID: mk wrote: > Hello, > > I wrote this class decorator with argument: The following is a *function* decorator, with the twist of being an instance of a user class rather than of the built-in function class (one I had not thought of). A class decorator would be a callable the modifies or wraps a *class*. > >>> class ChangeDoc(object): > def __init__(self, docstring): > self.docstring = docstring > def __call__(self, func): > func.__doc__ = self.docstring > return func > > It seems to work: > > >>> @ChangeDoc("bulba") > def f(): > pass > > >>> f.__doc__ > 'bulba' > > Can someone please debug my reasoning if it's incorrect? > > 1. First, the decorator @ChangeDoc('bulba') instantiates with > __init__(self, 'bulba'), to some class instance, let's call it _decor. > > 2. Then _decor's __call__ method is called with function f as argument, > changing the docstring and returning the changed f object, like f = > _decor(f) . > > Am I missing smth important / potentially useful in typical real-world > applications in that picture? From lists at cheimes.de Fri Jan 16 20:13:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:13:58 +0100 Subject: ABCs, functions, and __call__ (Python3) In-Reply-To: References: Message-ID: andrew cooke schrieb: > I think I'm missing something obvious here, so apologies in advance. > > I'd like to be able to test whether something is a function or > implements __call__. Now obviously I can do that as two separate > tests, but I though this was what ABCs were for. However, for the > life of me I cannot find what the correct ABC would be. Does it > exist? Is there some other, more traditional approach I should be > using? Or do I have to roll my own somehow? There is no ABC for this particular check. Any callable in Python 3.0 has a "__call__" attribute. In order to distinguish functions from callable you can use the inspect module, in particular inspect.isfunction(), inspect.ismethod() and inspect.isbuiltin(). Christian From mccredie at gmail.com Fri Jan 16 20:16:15 2009 From: mccredie at gmail.com (Matimus) Date: Fri, 16 Jan 2009 17:16:15 -0800 (PST) Subject: what's the point of rpython? References: mailman.7414.1232153035.3487.python-list@python.org Message-ID: The goals are listed here: http://codespeak.net/pypy/dist/pypy/doc/architecture.html Speed is mentioned, but as a secondary concern. The main goal seems to be to create a vehicle into exploring the concept of dynamic languages themselves. If that seems amorphous then it is because it is a research project. Matt From luismgz at gmail.com Fri Jan 16 20:19:32 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 16 Jan 2009 17:19:32 -0800 (PST) Subject: optimizing large dictionaries References: <71064881-68bf-481a-bc50-4b983c91cd5d@s20g2000yqh.googlegroups.com> Message-ID: On Jan 15, 6:39?pm, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > i create a dictionary that maps elements of the file that i want to > count > to their number of occurs. so i iterate through the file and for each > line > extract the elements (simple text operation) and see if it has an > entry in the dict: > > for line in file: > ? try: > ? ? elt = MyClass(line)# extract elt from line... > ? ? my_dict[elt] += 1 > ? except KeyError: > ? ? my_dict[elt] = 1 > > i am using try/except since it is supposedly faster (though i am not > sure > about this? is this really true in Python 2.5?). > > the only 'twist' is that my elt is an instance of a class (MyClass) > with 3 fields, all numeric. the class is hashable, and so my_dict[elt] > works well. > the __repr__ and __hash__ methods of my class simply return str() > representation > of self, while __str__ just makes everything numeric field into a > concatenated string: > > class MyClass > > ? def __str__(self): > ? ? return "%s-%s-%s" %(self.field1, self.field2, self.field3) > > ? def __repr__(self): > ? ? return str(self) > > ? def __hash__(self): > ? ? return hash(str(self)) > > is there anything that can be done to speed up this simply code? right > now it is taking well over 15 minutes to process, on a 3 Ghz machine > with lots of RAM (though this is all taking CPU power, not RAM at this > point.) > > any general advice on how to optimize large dicts would be great too > > thanks for your help. How about this?: for line in file: elt = MyClass(line) my_dict[elt] = my_dict.get(elt, 0) + 1 ... From google at mrabarnett.plus.com Fri Jan 16 20:24:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 01:24:04 +0000 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: <49713334.6030903@mrabarnett.plus.com> Giampaolo Rodola' wrote: > Hi, I'm sure the message I'm going to write will seem quite dumb to > most people but I really don't understand the str/bytes/unicode > differences introduced in Python 3.0 so be patient. What I'm trying > to do is porting pyftpdlib to Python 3.x. I don't want to support > Unicode. I don't want pyftpdlib for py 3k to do anything new or > different. I just want it to behave exactly the same as in the 2.x > version and I'd like to know if that's possible with Python 3.x. > > Now. The basic difference is that socket.recv() returns a bytes > object instead of a string object and that's the thing which confuses > me mainly. My question is: is there a way to convert that bytes > object into exactly *the same thing* returned by socket.recv() in > Python 2.x (a string)? > > I know I can do: > > data = socket.recv(1024) > data = data.decode(encoding) > > ...to convert bytes into a string but that's not exactly the same > thing. In Python 2.x I didn't have to care about the encoding. What > socket.recv() returned was just a string. That was all. Now doing > something like b''.decode(encoding) puts me in serious troubles since > that can raise an exception in case client and server use a different > encoding. > > As far as I've understood the basic difference I see now is that a > Python 2.x based FTP server could handle a 3.x based FTP client using > "latin1" encoding or "utf-8" or anything else while with Python 3.x > I'm forced to tell my server which encoding to use and I don't know > how to deal with that. > Originally Python had a single string type 'str' with 8 bits per character. That was a bit limiting for international use. Then a new string type 'unicode' was introduced. Now, in Python 3.x, it's time to tidy things up. The 'str' type has been renamed 'bytes' and the 'unicode' type has been renamed 'str'. If you're truly working with strings of _characters_ then 'str' is what you need, but if you're working with strings of _bytes_ then 'bytes' is what you need. socket.send() and socket.recv() are still the same, it's just that it's now clearer that they work with bytes and not strings. From grante at visi.com Fri Jan 16 20:25:49 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 16 Jan 2009 19:25:49 -0600 Subject: Finding the full path of an executable References: Message-ID: On 2009-01-17, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: > Unknown wrote: >> On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >>> Is there a portable way to find the full path of a filename that would >>> be called by os.execvp()? >> >> Yes. Use os.path.abspath() on the name before you call it with >> os.execvp() > > That doesn't work: [...] > The correct answer would be "/bin/echo" but abspath("echo") is just > going to give me /echo. My mistake. I thought you had a relative path to the program. > I need something that will search through the PATH like > execvp() would. I can do it myself, but I'm surprised that > such a feature is not already readily available somewhere. Since there are system calls that search the PATH, applications don't generally have to do it. There is a pretty standard Unix utility called "which" that does it: >>> os.popen("which %s" % "echo").read().strip() '/bin/echo' If you want to avoid using the external "which", here's a recipe: http://code.activestate.com/recipes/52224/ -- From tjreedy at udel.edu Fri Jan 16 20:27:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:27:45 -0500 Subject: Differences between class and function decorator In-Reply-To: References: Message-ID: mk wrote: > Hello everyone, > > I rewrote an example someone posted here recently from: > > >>> def print_method_name(method): > def new_meth(*args, **kwargs): > print method.func_name > return method(*args, **kwargs) > return new_meth > > >>> @print_method_name > def f2(): > pass > > >>> f2() > f2 > > > ..to: > > >>> class MyMethod(object): > def __init__(self, func): > self.name = func.func_name > self.func = func > def __call__(self): > print self.name > return self.func > > > >>> @MyMethod > def f(): > pass > > >>> f() > f > > > Note that function decorator returned None, while class decorator > returned function. To repeat and expand a bit what I said to the OP: these are both callables (functions in the math sense) because they both of instances of a class with a .__call__ instance method. Both are used as function decorators. One is an instance of class 'function', the other an instance of class 'MyMethod'. The class difference is not relevant to the usage. This is duck typing in action. A class decorator is a callable (in 2.6+/3.0+) that decorates a class. tjr From gnewsg at gmail.com Fri Jan 16 20:32:17 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 17:32:17 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> Message-ID: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> On 17 Gen, 02:24, MRAB wrote: > If you're truly working with strings of _characters_ then > 'str' is what you need, but if you're working with strings of _bytes_ > then 'bytes' is what you need. I work with string of characters but to convert bytes into string I need to specify an encoding and that's what confuses me. Before there was no need to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib From excord80 at gmail.com Fri Jan 16 20:32:49 2009 From: excord80 at gmail.com (excord80) Date: Fri, 16 Jan 2009 17:32:49 -0800 (PST) Subject: Need help with os.system in linux References: Message-ID: On Jan 16, 7:05?pm, akshay bhat wrote: > Hello > i am calling a program using os.system in python on Linux. > However in i found that program being executed and soon returned 256. > but when i ran it using terminal i got proper results. > Now in case of windows, python waits till the process is finished, > Can you please tell me how to implement this in linux? Maybe it runs faster in GNU/Linux? :) Either way, you probably want to post some minimal example code if you would like more help on this. From tjreedy at udel.edu Fri Jan 16 20:34:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 20:34:49 -0500 Subject: Beginner: Data type conversion question In-Reply-To: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> References: <21ea21df-f975-4032-874f-5b43a8027762@w24g2000prd.googlegroups.com> Message-ID: flagg wrote: >> If rdate.serial is already a string, as name would imply, the str() call >> is pointless. If not, can you get inc as int more directly? ... > Actually when i run a type(serial) on that variable it returns a > "long" Then inc = serial % 100 is 'more directly'. > which i am not sure why dnspython uses a long variable to > store the serial. Perhaps a holdever from C code where long is necessary to dependably hold counts with 8 decimal digits. From lists at cheimes.de Fri Jan 16 20:42:11 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Jan 2009 02:42:11 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' schrieb: > I work with string of characters but to convert bytes into string I > need to specify an encoding and that's what confuses me. > Before there was no need to deal with that. Why do you have to deal with unicode data? IIRC ftp uses ASCII only text so you can stick to bytes everywhere. If you didn't have to worry about encoding and unicode in Python 2.x then you should use bytes all over the place, too. Christian From alan.isaac at gmail.com Fri Jan 16 20:55:52 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 01:55:52 GMT Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: > Alan G Isaac wrote: >> http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range >> >> I see no mention of the tuple methods? >> >> Right after the paragraph >> "Most sequence types support the following operations." >> it seems appropriate to have one stating >> "Most sequence types support the following methods: index() and count()." On 1/16/2009 6:44 PM Terry Reedy apparently wrote: > I addressed this and related issues in > http://bugs.python.org/issue4966 Excellent! Alan Isaac From sjmachin at lexicon.net Fri Jan 16 20:58:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 16 Jan 2009 17:58:39 -0800 (PST) Subject: Incorrect title case? References: Message-ID: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> On Jan 17, 9:07?am, MRAB wrote: > Python 2.6.1 > > I've just found that the following 4 Unicode characters/codepoints don't > behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). > > For example, u"\u01C5".istitle() returns True and > unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() > returns u'\u01C4', which is the uppercase equivalent. Are these mistakes > in the Unicode database? Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, function _PyUnicode_ToTitlecase. See http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup The code that says: if (ctype->title) delta = ctype->title; else delta = ctype->upper; should IMHO merely be: delta = ctype->title; A value of zero for ctype->title should be interpreted simply as the offset to add to the ordinal, as it is in the sibling _PyUnicode_To (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py which treats upper, lower and title identically when preparing the tables used by those 3 functions. AFAICT making that change will fix the problem for those four characters and not ruin any others. The error that you noticed occurs as far back as I've looked (2.1) and also occurs in 3.0. Cheers, John From steve at REMOVE-THIS-cybersource.com.au Fri Jan 16 21:09:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 02:09:13 GMT Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: <0181344a$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 17:32:17 -0800, Giampaolo Rodola' wrote: > On 17 Gen, 02:24, MRAB wrote: > >> If you're truly working with strings of _characters_ then 'str' is what >> you need, but if you're working with strings of _bytes_ then 'bytes' is >> what you need. > > I work with string of characters but to convert bytes into string I need > to specify an encoding and that's what confuses me. Before there was no > need to deal with that. In Python 2.x, str means "string of bytes". This has been renamed "bytes" in Python 3. In Python 2.x, unicode means "string of characters". This has been renamed "str" in Python 3. If you do this in Python 2.x: my_string = str(bytes_from_socket) then you don't need to convert anything, because you are going from a string of bytes to a string of bytes. If you do this in Python 3: my_string = str(bytes_from_socket) then you *do* have to convert, because you are going from a string of bytes to a string of characters (unicode). The Python 2.x equivalent code would be: my_string = unicode(bytes_from_socket) and when you convert to unicode, you can get encoding errors. A better way to do this would be some variation on: my_str = bytes_from_socket.decode('utf-8') You should read this: http://www.joelonsoftware.com/articles/Unicode.html -- Steven From gnewsg at gmail.com Fri Jan 16 21:34:25 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 18:34:25 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <0181344a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1c4506ed-f9e4-4f86-8df6-94afeb054cdb@z28g2000prd.googlegroups.com> On 17 Gen, 03:09, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 17:32:17 -0800, Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then 'str' is what > >> you need, but if you're working with strings of _bytes_ then 'bytes' is > >> what you need. > > > I work with string of characters but to convert bytes into string I need > > to specify an encoding and that's what confuses me. Before there was no > > need to deal with that. > > In Python 2.x, str means "string of bytes". This has been renamed "bytes" > in Python 3. > > In Python 2.x, unicode means "string of characters". This has been > renamed "str" in Python 3. > > If you do this in Python 2.x: > > ? ? my_string = str(bytes_from_socket) > > then you don't need to convert anything, because you are going from a > string of bytes to a string of bytes. > > If you do this in Python 3: > > ? ? my_string = str(bytes_from_socket) > > then you *do* have to convert, because you are going from a string of > bytes to a string of characters (unicode). The Python 2.x equivalent code > would be: > > ? ? my_string = unicode(bytes_from_socket) > > and when you convert to unicode, you can get encoding errors. A better > way to do this would be some variation on: > > ? ? my_str = bytes_from_socket.decode('utf-8') > > You should read this: > > http://www.joelonsoftware.com/articles/Unicode.html > > -- > Steven Thanks, that clarifies a bit even if I still have a lot of doubts. I wish I could do: my_str = bytes_from_socket.decode('utf-8') That would mean avoiding to replace "" with b"" almost everywhere in my code but I doubt it would actually be a good idea. RFC-2640 states that UTF-8 is the preferable encoding to use for both clients and servers but I see that Python 3.x's ftplib uses latin1, for example (bug?). How my server is supposed to deal with that? I think that using bytes everywhere, as Christian recommended, would be the only way to behave exactly like the 2.x version, but that's not easy at all. --- Giampaolo http://code.google.com/p/pyftpdlib From steve at holdenweb.com Fri Jan 16 21:40:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 21:40:11 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > On 17 Gen, 02:24, MRAB wrote: > >> If you're truly working with strings of _characters_ then >> 'str' is what you need, but if you're working with strings of _bytes_ >> then 'bytes' is what you need. > > I work with string of characters but to convert bytes into string I > need to specify an encoding and that's what confuses me. > Before there was no need to deal with that. > I don't yet understand why you feel you have to convert what you receive to a string. In Python 3.0 bytes is the same as a string in 2.6, for most practical purposes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gnewsg at gmail.com Fri Jan 16 21:54:51 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 18:54:51 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: On 17 Gen, 03:40, Steve Holden wrote: > Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then > >> 'str' is what you need, but if you're working with strings of _bytes_ > >> then 'bytes' is what you need. > > > I work with string of characters but to convert bytes into string I > > need to specify an encoding and that's what confuses me. > > Before there was no need to deal with that. > > I don't yet understand why you feel you have to convert what you receive > to a string. In Python 3.0 bytes is the same as a string in 2.6, for > most practical purposes. > > regards > ?Steve That would help to avoid replacing "" with b"" almost everywhere in my code. --- Giampaolo http://code.google.com/p/pyftpdlib From jcd at sdf.lonestar.org Fri Jan 16 21:58:02 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Fri, 16 Jan 2009 21:58:02 -0500 Subject: Skull Socks (was Re: Convention vs. fascism) In-Reply-To: References: <6t8comF9ou5uU1@mid.uni-berlin.de> <017f44a3$0$8693$c3e8da3@news.astraweb.com> <87zlhsb81i.fsf_-_@benfinney.id.au> <017fb1f3$0$8693$c3e8da3@news.astraweb.com> <87vdsgb1b0.fsf@benfinney.id.au> <017fce36$0$8693$c3e8da3@news.astraweb.com> <95552ec3-b518-4ad4-9974-62e7b2bf1ad4@s20g2000yqh.googlegroups.com> <01804283$0$8693$c3e8da3@news.astraweb.com> <0180a93a$0$8693$c3e8da3@news.astraweb.com> Message-ID: <1232161082.17182.1.camel@mctell> On Fri, 2009-01-16 at 16:41 -0500, Steve Holden wrote: > Steven D'Aprano wrote: > > On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote: > > > >> On Fri, 2009-01-16 at 08:57 +0000, Steven D'Aprano wrote: > >>> On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > >>> > >>>> Oh come on you lot - you are carrying on as if Diez were wearing his > >>>> skull socks again - do me a favour and give him a break! > >>> And... skull socks? Cool. Where can I get some? > >>> > >>> > >>> > >> http://www.letmegooglethatforyou.com/search?q=skull+socks > > > > Not Found > > The requested URL /search was not found on this server. > > Additionally, a 404 Not Found error was encountered while trying to use > > an ErrorDocument to handle the request. > > > > > > > > You know, it was just a throw-away comment to lighten the mood. I don't > > really need to see 18,000+ links to places that sell socks with skulls > > printed on them. > > > > On the other hand, if they were socks made from actual skulls, that would > > be something... > > > Of course Cliff actually meant > > http://letmegooglethatforyou.com/?q=skull+socks > > Jokes are never as funny when they go wrong :) Maybe I could run a "teach me letmegooglethatforyou.com" at pycon this year. From tjreedy at udel.edu Fri Jan 16 22:43:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jan 2009 22:43:31 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > That would help to avoid replacing "" with b"" almost everywhere in my > code. Won't 2to3 do that for you? From andrew at acooke.org Fri Jan 16 22:45:57 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 16 Jan 2009 19:45:57 -0800 (PST) Subject: ABCs, functions, and __call__ (Python3) References: Message-ID: <5b1c4a9f-67f2-412e-adff-a1e654a11d5f@k36g2000pri.googlegroups.com> On Jan 16, 10:13?pm, Christian Heimes wrote: > Any callable in Python 3.0 has a "__call__" attribute. Aha! Thanks! Andrew From gnewsg at gmail.com Fri Jan 16 22:51:33 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 16 Jan 2009 19:51:33 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> Message-ID: <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> On 17 Gen, 04:43, Terry Reedy wrote: > Giampaolo Rodola' wrote: > > That would help to avoid replacing "" with b"" almost everywhere in my > > code. > > Won't 2to3 do that for you? I used 2to3 against my code but it didn't cover the "" -> b"" conversion (and I doubt it is able to do so, anyway). --- Giampaolo http://code.google.com/p/pyftpdlib From wuwei23 at gmail.com Fri Jan 16 23:07:08 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 20:07:08 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> On Jan 17, 10:37?am, "Brendan Miller" wrote: > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? This is more or less covered in the FAQ: "The restrictions are to ensure that type inference (and so, ultimately, translation to other languages) of RPython programs is possible. These restrictions only apply after the full import happens, so at import time arbitrary Python code can be executed." http://codespeak.net/pypy/dist/pypy/doc/faq.html#id25 > The goals of the pypy project seems to be to create a fast python > implementation. I may be wrong about this, as the goals seem a little > amorphous if you look at their home page. The home page itself is ambiguous, and does oversell the performance aspect. The *actual* goal as outlined by their official docs is to implement Python in Python, at every level. If this means utilising a less-dynamic subset of Python for the lower levels, its -still- at least more-Python-than-C. "PyPy is both: * a reimplementation of Python in Python, and * a framework for implementing interpreters and virtual machines for programming languages, especially dynamic languages." http://codespeak.net/pypy/dist/pypy/doc/faq.html#id11 The PyPy devs feel that this will allow them to more easily experiment with optimising the interpreter for greater speeds, but that isn't one of the stated goals (just, apparently, their 'secret' one). > This RPython thing seems like a totally unnecessary intermediate step. > Instead of writing an implementation of one language, there's an > implementation of two languages. My understanding is that the 'higher' level Python language features are implemented on top of the restricted RPython features, so it's more of an organic growth of one language than two separate implementations. > A lot of the performance boost you > get from a static language is that knowing the types at compile time > lets you inline code like crazy, unroll loops, and even execute code > at compile time. > > RPython is a statically typed language because I guess the developers > associate static languages with speed? Doesn't the first paragraph above state the same thing that you question in the next? > Except that they use it to > generate C code, which throws away the type information they need to > get the speed increase. Huh? I thought the goal was to write a fast > dynamic language, not a slow static one? They're not just generating C code, they currently also target LLVM, JVM and CLI. > Is this going anywhere or is this just architecture astronautics? Well, they actually seem to have achieved some substantial gains, so I think it's unfair to imply that the project isn't based on pragmatic objectives. Their initial JIT prototype failed to work as well as expected, and they've spent some time re-thinking the approach; I'm happier to wait for a stably performing JIT that can be improved over time than a short term gain. > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. A lot of this is covered in the FAQ. Whether you agree with their approach or not, they're the ones actively pushing this effort forward. It's been a few months since the last update, but the PyPy status blog may have more information for you. At the very least, it's a venue to discuss your concerns directly with the PyPy devs. http://morepypy.blogspot.com From steve at holdenweb.com Fri Jan 16 23:08:26 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 16 Jan 2009 23:08:26 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> Message-ID: Giampaolo Rodola' wrote: > On 17 Gen, 04:43, Terry Reedy wrote: >> Giampaolo Rodola' wrote: >>> That would help to avoid replacing "" with b"" almost everywhere in my >>> code. >> Won't 2to3 do that for you? > > I used 2to3 against my code but it didn't cover the "" -> b"" > conversion (and I doubt it is able to do so, anyway). > Note that if you are using 2.6 you should first convert your "" quotes to b"" - this won't make any practical difference, but then you will be able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gary.smith28 at comcast.net Fri Jan 16 23:23:40 2009 From: gary.smith28 at comcast.net (Gary Smith) Date: Fri, 16 Jan 2009 23:23:40 -0500 Subject: Python Startup file Message-ID: Fellow Vipers, Although I've written lots of Python code, I'm still an embarrassed newbie. Here's my problem. I've never been able to get ActiveState Python's PythonWin to observe the file referenced in the Windows PYTHONSTARTUP environment variable. Many thanks for pointing out the obvious to me Gary _____ "Accept no assertions without evidence." --Goompah wisdom from "Omega" by Jack McDevitt-- _____ "Nature is complete because it does not serve itself." --"Tao De Jing" by Lao Tze-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 16 23:26:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 16 Jan 2009 20:26:31 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> Message-ID: <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> On Jan 17, 3:08?pm, Steve Holden wrote: > Giampaolo Rodola' wrote: > > On 17 Gen, 04:43, Terry Reedy wrote: > >> Giampaolo Rodola' wrote: > >>> That would help to avoid replacing "" with b"" almost everywhere in my > >>> code. > >> Won't 2to3 do that for you? > > > I used 2to3 against my code but it didn't cover the "" -> b"" > > conversion (and I doubt it is able to do so, anyway). > > Note that if you are using 2.6 you should first convert your "" quotes > to b"" - this won't make any practical difference, but then you will be > able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. Perhaps before we get too far down the track of telling the OP what he should do, we should ask him a little about his intentions: Is he porting to 3.0 and abandoning 2.x support completely? [presumably unlikely] So then what is the earliest 2.x that he wants to support at the same time as 3.x? [presumably at least 2.5] Does he intend to maintain two separate codebases, one 2.x and the other 3.x? Else does he intend to maintain just one codebase written in some 2.x dialect and using 2to3 plus sys.version-dependent code for the things that 2to3 can't/doesn't handle? Cheers, John From wuwei23 at gmail.com Fri Jan 16 23:36:50 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 16 Jan 2009 20:36:50 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> On Jan 17, 3:34?pm, Eduardo Lenz wrote: > modu = "os" > exec("from " + modu + " import *") And of course, there's the usual disclaimer that this should be only used in circumstances where you can guarantee the contents of 'modu' aren't ever going to be anything like: modu = "os import system; system('rm *'); from os " Another reason to prefer __import__ over exec is speed: $ /usr/lib/python2.5/timeit.py -n 100000 'from os import system' 100000 loops, best of 3: 2.12 usec per loop $ /usr/lib/python2.5/timeit.py -n 100000 '__import__("os", fromlist= ["system"])' 100000 loops, best of 3: 2.72 usec per loop $ /usr/lib/python2.5/timeit.py -n 100000 'm = "os"; exec("from " + m + " import system")' 100000 loops, best of 3: 25.1 usec per loop From prologic at shortcircuit.net.au Sat Jan 17 00:07:15 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:07:15 +1000 Subject: problem in implementing multiprocessing In-Reply-To: <66510985287744829EE3AD881CE824B2@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> Message-ID: On Fri, Jan 16, 2009 at 7:16 PM, gopal mishra wrote: > I create two heavy objects sequentially without using multipleProcessing > then creation of the objects takes 2.5 sec.if i create these two objects in > separate process then total time is 6.4 sec. > > i am thinking it is happening due to the pickling and unpickling of the > objects.if i am right then what could be the sollution. > > my system configuration: > dual-core processor > winXP > python2.6.1 System specs in this case are irrelevant. What you are experiencing is most likely an I/O bound problem - using multiprocessing may likely not help you solve the problem any faster because of your I/O constraint. cheers James From prologic at shortcircuit.net.au Sat Jan 17 00:13:02 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:13:02 +1000 Subject: multiprocessing vs. distributed processing In-Reply-To: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> References: <4222a8490901160415o29629c79s477b4da0569dd0c1@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 10:15 PM, Jesse Noller wrote: > That being said, there is no reason why you could not use it in > conjunction with something like Kamaelia, pyro, $ipc mechanism/etc. And also circuits (1). circuits has full implementations of Thread and Process components. circuits also has special components focused at distributed applications. cheers James 1. http://pypi.python.org/pypi/circuits From prologic at shortcircuit.net.au Sat Jan 17 00:18:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 17 Jan 2009 15:18:06 +1000 Subject: process/thread instances and attributes In-Reply-To: <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> References: <496F03B9.8090100@shopzeus.com> <4222a8490901160433y75087b31jc397aaa2c77d0c46@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 10:33 PM, Jesse Noller wrote: (...) > Personally, rather then using a value to indicate whether to run or > not, I would tend to use an event to coordinate start/stop state. The reason I implemented workers.Thread and workers.Process this way is basically so taht long-running, potentially blocking work could be done yet while still maintaining the ability to communicate with the rest of the system and propagate events. See: http://hg.softcircuit.com.au/index.wsgi/projects/circuits/file/0a97da2a69b3/circuits/workers.py cheers James From atleta.hu at gmail.com Sat Jan 17 00:29:50 2009 From: atleta.hu at gmail.com (atleta) Date: Fri, 16 Jan 2009 21:29:50 -0800 (PST) Subject: Parallel package hierarchies/directories References: <70cbe817-9eda-4346-93b6-5c38d8d63389@n33g2000pri.googlegroups.com> Message-ID: OK, I'm answering my own question, it might be of some help for someone in the future: yes, it's possible to have parts of the same package in multiple directories, it's just not enabled by default. To make it work each such package should have the following code in their __init__.py: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) Actually pkgutil's documentation explains this quite clearly: http://docs.python.org/library/pkgutil.html (It's easy if you know where to look ;) ) Laszlo From lenz at joinville.udesc.br Sat Jan 17 00:34:01 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 21:34:01 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: <200901162134.01720.lenz@joinville.udesc.br> On Friday 16 January 2009 15:03:51 Lawson Hanson wrote: > Is it possible to import a module of Python code > where I do not know the name of the module > until run-time? > > The Python statement: > > from someModule import * > > requires that "someModule" be the name of the module, > but what I would like is to be able to define a value > for "someModule" ... and provided that such a module > exists (in an extended "sys.path" directory), then > import from the specified module at run-time > > If I have a module called "dummy.py" in my own "myModules" > directory (just below my HOME directory in Linux) > > If I do this: > > import os, sys > > myModDir = os.environ["HOME"] + "/myModules" > > sys.path.append(myModDir) > > modName = "%s/%s" % (myModDir, "dummy") > > from modName import * > > I get the following error: > > ImportError: No module named modName > > So is there any way to get Python to import the named module > without just doing "from dummy import *", because I will > not know that the user wants to use the "dummy" module > until run-time ... I'm trying to import control data > for different run scenarios which will be defined in > differently named Python modules which the user will > specify at run-time with a command-line option > > And help with this would be most appreciated > > Best regards, > > Lawson Hanson > ------ > Melbourne, Victoria, Australia > -- > http://mail.python.org/mailman/listinfo/python-list modu = "os" exec("from " + modu + " import *") []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From lenz at joinville.udesc.br Sat Jan 17 00:39:04 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 21:39:04 -0800 Subject: multiprocessing question/error Message-ID: <200901162139.04849.lenz@joinville.udesc.br> Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code .... class Pygen3(self).... .... .... .... def calcula(self,indiv): .... .... .... def evaluate(self): .... .... indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 00:55:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 05:55:34 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> Message-ID: <01816958$0$8693$c3e8da3@news.astraweb.com> On Fri, 16 Jan 2009 20:36:50 -0800, alex23 wrote: > On Jan 17, 3:34?pm, Eduardo Lenz wrote: >> modu = "os" >> exec("from " + modu + " import *") > > And of course, there's the usual disclaimer that this should be only > used in circumstances where you can guarantee the contents of 'modu' > aren't ever going to be anything like: > > modu = "os import system; system('rm *'); from os " > > Another reason to prefer __import__ over exec is speed: Both very good points, but consider that you're not comparing apples with apples. >>> from os import system >>> system >>> del system >>> >>> exec "from %s import system" % "os" >>> system >>> del system >>> >>> __import__("os", fromlist=["system"]) >>> system Traceback (most recent call last): File "", line 1, in NameError: name 'system' is not defined I mention this only to be pedantic, because I agree with your point that exec can introduce security issues, and be significantly slower. -- Steven From Scott.Daniels at Acm.Org Sat Jan 17 01:04:29 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 16 Jan 2009 22:04:29 -0800 Subject: *Advanced* Python book? In-Reply-To: <7xprimsxaj.fsf@ruckus.brouhaha.com> References: <7xprimsxaj.fsf@ruckus.brouhaha.com> Message-ID: <35idnRlNc_Y96ezUnZ2dnUVZ_rPinZ2d@pdx.net> Paul Rubin wrote: > mk writes: >> .... Anybody found such holy grail? > > The favorite ones around here are "Python Cookbook" and "Python in a > Nutshell", both by Alex Martelli, who used to be a newsgroup regular > and still stops by from time to time. To the OP: Do yourself a favor and go to a bookstore and read a chapter or two of the cookbook. While you can see the recipes on activestate, there is a _lot_ of value added in (1) the selection, (2) the editing for a more consistent style, and (3) the chapter intros by people chosen for their knowledge on the chapter's subject. --Scott David Daniels Scott.Daniels at Acm.Org From lenz at joinville.udesc.br Sat Jan 17 01:25:59 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Fri, 16 Jan 2009 22:25:59 -0800 Subject: dynamic module import? In-Reply-To: <01811941$0$8693$c3e8da3@news.astraweb.com> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <01811941$0$8693$c3e8da3@news.astraweb.com> Message-ID: <200901162226.00043.lenz@joinville.udesc.br> On Friday 16 January 2009 16:13:49 Steven D'Aprano wrote: > On Fri, 16 Jan 2009 21:34:01 -0800, Eduardo Lenz wrote: > > modu = "os" > > exec("from " + modu + " import *") > > "from module import *" is generally frowned upon, although it does > occasionally have its uses. > > By the way, I think your computer's clock is set wrong. My newsclient is > reporting that you sent your post at 4:30pm today -- and I'm writing this > at 11am. Perhaps your timezone is set wrong? > > Regards, > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list OK, my point was about the exec statement, not the import * (it was just an example). Well, my clock is OK here..maybe the time zone is wrong. I will check this out. Thanks for the advice. []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From michele.simionato at gmail.com Sat Jan 17 01:47:20 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 16 Jan 2009 22:47:20 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: On Jan 16, 9:27?pm, mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. > > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? > > Regards, > mk "Expert Python Programming" by Tarek Ziad? is quite good and I wrote a review for it: http://www.artima.com/weblogs/viewpost.jsp?thread=240415 There is plenty of info about Advanced Python on the net, much more than in book form. Come to think of it, there are my Oxford lectures (the title was exactly "Advanced Python Programming") and I could republish it on my blog, since I cannot find them on the net anymore. Michele Simionato From bellman at lysator.liu.se Sat Jan 17 02:19:45 2009 From: bellman at lysator.liu.se (Thomas Bellman) Date: Sat, 17 Jan 2009 07:19:45 +0000 (UTC) Subject: Need help with os.system in linux References: Message-ID: akshay bhat writes: > i am calling a program using os.system in python on Linux. > However in i found that program being executed and soon returned 256. > but when i ran it using terminal i got proper results. Under Linux (but unfortunately not generally under Unix), you can interpret return code from os.system() using os.WIFSIGNALED() or os.WIFEXITED(), and os.WEXITSTATUS() or os.WTERMSIG(). Something like this: status = os.system(commandline) if os.WIFSIGNALED(status): print "Command was killed by signal", os.WTERMSIG(status) else: print "Command exited with return status", os.WEXITSTATUS(status) (os.WIFSIGNALED() and os.WIFEXITED() are each others inverses, for this use case. In the above code, I could have used 'not os.WIFEXITED(status)' instead of 'os.WIFSIGNALED(status)' without changing its meaning.) If you do that for your program, you will see that the program you call are exiting with return status 1 (that's what a return value of 256 from os.system() happens to mean), i.e it is calling exit() with 1 as argument. *Why* the program you are calling does that, is impossible to tell from the information you have given us. You haven't even told us what command line you are passing to os.system(), so if you need more help, you must tell us more. May I also suggest that you use the subprocess module instead of os.system(). The subprocess module is a newer and better interface for running external commands. For example, you can avoid having to deal with quoting shell metacharacters, and interpreting the return values are easier. -- Thomas Bellman, Lysator Computer Club, Link??ping University, Sweden "Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se differently is selling something." ! Make Love -- Nicht Wahr! From castironpi at gmail.com Sat Jan 17 03:24:21 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 00:24:21 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> Message-ID: <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> On Jan 16, 5:03?am, Steven D'Aprano wrote: > On Wed, 14 Jan 2009 16:30:36 -0800, Aaron Brady wrote: > > Hi, this is a continuation of something that comes up now and again > > about reverse lookups on dictionaries, as well as a follow-up to my > > pursuit of a Relation class from earlier. > > [...] > > > What's the best way to construct this class? ?Or, do you have an > > argument that it could not be simpler than using a relational db? > > Brainstorming, not flamestorming. > > Here's a lightweight solution that uses lazy calculation of the reverse > dict. It makes a number of assumptions: > > - both keys and values will be hashable and unique; > - the dict won't be so large that calculating the reverse dictionary will > be time consuming; > - modifications to instance.reverse are undefined. > > Usage: > > >>> d = ReverseDict(x=2, y=3, z=4) > >>> d['x'] > 2 > >>> d.reverse[2] > 'x' > >>> d['a'] = 0 > >>> d.reverse[0] > > 'a' > > def make_dirty(func): > ? ? from functools import wraps > ? ? @wraps(func) > ? ? def f(self, *args, **kwargs): > ? ? ? ? self._dirty = True > ? ? ? ? return func(self, *args, **kwargs) > ? ? return f > > # only tested a little bit > class ReverseDict(dict): > ? ? def __init__(self, *args, **kwargs): > ? ? ? ? super(ReverseDict, self).__init__(*args, **kwargs) > ? ? ? ? self._dirty = True > ? ? @make_dirty > ? ? def clear(): > ? ? ? ? super(ReverseDict, self).clear() snip > ? ? @property > ? ? def reverse(self): > ? ? ? ? if self._dirty: > ? ? ? ? ? ? # Modify this to support repeated and non-hashable values. > ? ? ? ? ? ? self._reverse = dict((value, key) for > ? ? ? ? ? ? (key, value) in self.iteritems()) > ? ? ? ? ? ? self._dirty = False > ? ? ? ? return self._reverse > > An even more lightweight solution is to give up O(1) for the reverse > lookup: > > # untested > class ReversableDict(dict): > ? ? def lookupvalue(self, value): > ? ? ? ? for k,v in self.iteritems(): > ? ? ? ? ? ? if v == value: return k > ? ? ? ? raise ValueError('value not found') > ? ? def lookupallvalues(self, value): > ? ? ? ? results = [] > ? ? ? ? for k,v in self.iteritems(): > ? ? ? ? ? ? if v == value: results.append(k) > ? ? ? ? return results > > -- > Steven Can you make it work for a 3-way lookup? From castironpi at gmail.com Sat Jan 17 03:43:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 00:43:35 -0800 (PST) Subject: multiprocessing question/error References: Message-ID: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> On Jan 16, 11:39?pm, Eduardo Lenz wrote: > Hi, > > I was using the former processing package with python 2.5 with no problems. > After switching to python 2.6.1 I am having some problems with the same code. > The problem seems to be related to the fact that I am using Pool.map > with a bounded method, since it is inside a class. To clarify a little bit, > let me show some parts of the code .... Hello, > class Pygen3(self).... I infer this was a typo. > ? ? .... > ? ? .... > ? ? .... > ? ? def calcula(self,indiv): > ? ? ? ? .... > ? ? ? ? .... > ? ? ? ? .... > > ? ?def evaluate(self): > ? ? ?.... > ? ? ?.... > ? ? indiv = range(mult*self.popsize,(mult+1)*self.popsize) > ? ?pool = Pool(processes=nproc) > ? ?results = pool.map(self.calcula,indiv) I infer the indentation drifted. > ? ?... > ? ?... > > the error is the following > > Exception in thread Thread-1: > Traceback (most recent call last): > ? File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner > ? ? self.run() > ? File "/usr/lib/python2.6/threading.py", line 477, in run > ? ? self.__target(*self.__args, **self.__kwargs) > ? File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > _handle_tasks > ? ? put(task) > PicklingError: Can't pickle : attribute lookup > __builtin__.instancemethod failed > > Thanks for your help. Checking on two typos above. I have this working: from multiprocessing import Process class C(object): def m1( self ): p1 = Process(target=self.m2, args=('bob1',)) p2 = Process(target=self.m2, args=('bob2',)) p1.start() p2.start() p1.join() p2.join() def m2( self, name ): print 'hello', name if __name__ == '__main__': c= C() c.m1() But I get the same error as you with this: from multiprocessing import Process, Pool class C(object): def m1( self ): arg= range( 10 ) pool= Pool( 5 ) results = pool.map(self.m2,arg) print results def m2( self, name ): print 'hello', name if __name__ == '__main__': c= C() c.m1() I build a workaround with this: from multiprocessing import Process, Pool class C(object): def m1( self ): arg= zip( [ self ]* 10, range( 10 ) ) pool= Pool( 5 ) results = pool.map(C_m2,arg) print results def m2( self, arg ): print 'hello', arg return arg* 2 def C_m2( ar, **kwar ): return C.m2( *ar, **kwar ) if __name__ == '__main__': c= C() c.m1() Note that you have to explicitly include 'self' as a first parameter when packing the arguments, and then explicitly unpack it in the helper function. Also, wrapping 'm2' with '@staticmethod' also fails with this error: Exception in thread Thread-1: Traceback (most recent call last): File "c:\programs\python26\lib\threading.py", line 522, in __bootstrap_inner self.run() File "c:\programs\python26\lib\threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "c:\programs\python26\lib\multiprocessing\pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.function failed If this works for you, it's possible to make the helper function more dynamic, by accepting a class name and an attribute name as string arguments, then retrieving them in the subprocesses. From pdorange at pas-de-pub-merci.mac.com Sat Jan 17 03:48:12 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sat, 17 Jan 2009 09:48:12 +0100 Subject: Pythonic way to handle coordinates Message-ID: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Hi, I'm used python for 3 months now to develop small arcade games (with pygame module). I just got a question about coordinates handling. My games are in 2D so i deal with x,y coordinates for sprites (but woudl be the same u-issue in 3D). At the beginning i simply use x and y to pass to my methods ie : sprite.move(x,y) easy after looking closely to pygame code, i noticed that pygame implement a Rect class but no Point class, and instead require tuple for coordinates. ie : pygame.draw.line(surface,color,start,end) where start and end are tuple, like (x,y). I found this nice and rewrote my API to use tuples instead of 2 variables... so i got could do : loc=(x,y) sprite.move(loc) or sprite.move((x,y)) ... loc=sprite.get_pos() Nice, but i got a problem when my methodes return tuple, as it's unmutable i could not modify them and i got to used tempory variables to do that, not very clean : loc=sprite.get_pos() loc[0]+=10 < ERROR ... x=loc[0]+10 loc=(x,loc[1]) i could also do : (x,y)=sprite.get_pos() x+=10 sprite.set_pos((x,y)) The second method could not be used when i'm instead one of my method, i need to used the first one. What is the elegant way to handle coordinates ? Do i need to continue using tuples or do i need to write a Point class. I feel a point class would be nice, because i could implement operators with it ? But i think Point class must exist allready ? -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From castironpi at gmail.com Sat Jan 17 04:09:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 01:09:40 -0800 (PST) Subject: English-like Python References: Message-ID: <337394e9-e86a-4506-941b-fcfd33ce2e32@a26g2000prf.googlegroups.com> On Jan 15, 7:02?pm, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. > > For example, the following code... > > >>> import os > > >>> def list_files(dirname): > >>> ? ? for p in os.listdir(dirname): > >>> ? ? ? ? print p > > >>> list_files("some_dir") > > foo > bar > etc > > ...might be translated as... > > >>> Import the operating system module. > > >>> Define a new function as "list files" which accepts > > ? ? "a path" and does the following: > ? ? ? ? For every item in the list returned by the operating system's > ? ? ? ? directory listing of the given path, do the following: > ? ? ? ? ? ? ?Print the item. > > >>> List files from "some_dir". > > foo > bar > etc > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. > > A language like this would, of course, blow a lot of staple coding > coding concepts like "variables," "objects," etc. right out of the > water. I think, however, that it could be done, and wouldn't necessarily > have to be any slower than any other scripting language as any text/code > could be cached as bytecode, just like Python. > > I know it's sort of silly but I think something like this would be very > interesting, maybe even useful. ^_^ I'm actually moderately interested in this idea. I was pursuing it a while back, but didn't find anyone else interested. You want to avoid requiring an understanding, since English syntax doesn't always guarantee its semantics. Even a trivial transformation from non- delimited English can cause an AmbiguityException. The basics started like this: 'a= open "file1.py"' --> 'a= open( "file1.py" )' ''' a= nat_list() append 0 to a append 1 to a sort a ''' --> ''' a= nat_list() a.append( 0 ) a.append( 1 ) a.sort() ''' However, as you can see, 'open a' can map to both 'a.open()' and 'open ( a )'. If 'open' is both a method on 'a', and a callable defined in current scope, the expression is ambiguous and raises an AmbiguityException. If you're willing to constrain yourself to a subset of English which the language will understand, you open a lot of doors; that is, if you will accept a 'more natural Python' instead of 'true natural Python'. From dragosmocrii at gmail.com Sat Jan 17 04:30:09 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 01:30:09 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: <5aa0e99a-9f97-4cc7-b7a0-d6dd30a25ce2@b38g2000prf.googlegroups.com> On Jan 16, 9:19?pm, Dragos wrote: > I am trying to make a testing script to load/save cookies to a file > with FileCookieJar, but it results in this error: FileCookieJar has > not attribute "_self_load" > > This is my script: > > import urllib.request, urllib.parse,http.cookiejar > url="http://localhost/test.php" > cs=http.cookiejar.FileCookieJar() > cs.load("cookies.txt",ignore_discard=False, ignore_expires=False) > opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor > (cs)) > y=opener.open(url) > print(y.read()) > > Thanks for helping. BUMP From gagsl-py2 at yahoo.com.ar Sat Jan 17 04:48:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 07:48:35 -0200 Subject: FileCookieJar has not attribute "_self_load" In-Reply-To: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo gmane.comp.python.general > I am trying to make a testing script to load/save cookies to a file > with FileCookieJar, but it results in this error: FileCookieJar has > not attribute "_self_load" FileCookieJar is an abstract class, although it isn't clear at all from the documentation. (You may want to file a documentation bug at http://bugs.python.org) You must instantiate a specific subclass (like MozillaCookieJar), which determines the actual file format used. -- Gabriel Genellina From musicguy at alphaios.net Sat Jan 17 04:50:23 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sat, 17 Jan 2009 01:50:23 -0800 (PST) Subject: Pythonic way to handle coordinates References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: On Jan 17, 2:48?am, pdora... at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) wrote: > Hi, > I'm used python for 3 months now to develop small arcade games (with > pygame module). > > I just got a question about coordinates handling. > My games are in 2D so i deal with x,y coordinates for sprites (but woudl > be the same u-issue in 3D). > > At the beginning i simply use x and y to pass to my methods > ie : sprite.move(x,y) > easy > > after looking closely to pygame code, i noticed that pygame implement a > Rect class but no Point class, and instead require tuple for > coordinates. > ie : pygame.draw.line(surface,color,start,end) > where start and end are tuple, like (x,y). > > I found this nice and rewrote my API to use tuples instead of 2 > variables... > so i got could do : > ? ? ? ? loc=(x,y) > ? ? ? ? sprite.move(loc) or sprite.move((x,y)) > ? ? ? ? ... > ? ? ? ? loc=sprite.get_pos() > > Nice, but i got a problem when my methodes return tuple, as it's > unmutable i could not modify them and i got to used tempory variables to > do that, not very clean : > ? ? ? ? loc=sprite.get_pos() > ? ? ? ? loc[0]+=10 ?< ERROR > ? ? ? ? ... > ? ? ? ? x=loc[0]+10 > ? ? ? ? loc=(x,loc[1]) > i could also do : > ? ? ? ? (x,y)=sprite.get_pos() > ? ? ? ? x+=10 > ? ? ? ? sprite.set_pos((x,y)) > The second method could not be used when i'm instead one of my method, i > need to used the first one. > > What is the elegant way to handle coordinates ? > Do i need to continue using tuples or do i need to write a Point class. > I feel a point class would be nice, because i could implement operators > with it ? But i think Point class must exist allready ? > > -- > Pierre-Alain Dorange > > Ce message est sous licence Creative Commons "by-nc-sa-2.0" > ? ? ? ? Hi there, First of all, Pygame will accept any sequence of two integers (or even floats) and not just tuples, so you don't need to implement all your coordinates as tuples, and thus you can use lists, which are mutable. Second of all, for this situation I do the same as the Rect object and implement .x and .y properties for objects that need individual access of those coordinates. Example: >>> # WARNING: This code was written on-the-fly and has not been tested... >>> class MySprite(object): >>> def __init__(self, pos): >>> # This is a list, not a tuple. Pygame won't mind. >>> # Also, note that the type of the pos is implicitly >>> # type checked. >>> self._pos = map(int, pos[:2]) >>> >>> def set_x(self, x): >>> self._pos[0] = int(x) >>> x = property(lambda self: self._pos[0], set_x) >>> >>> def set_y(self, y): >>> self._pos[1] = int(y) >>> y = property(lambda self: self._pos[1], set_y) >>> >>> def set_pos(self, pos): >>> self._pos = map(int, pos[:2]) >>> # Note that the return value is converted to tuple to prevent >>> # constructs like `mysprite.pos[0] = "foo"`, which would cause an >>> # invalid type of value to be assigned for the x coordinates. >>> pos = property(lambda self: tuple(self._pos), set_pos) >>> >>> spr = MySprite((3,4)) >>> spr.x 3 >>> spr.y 4 >>> spr.x = 8 >>> spr.pos (8,4) My SDK implements a lot of things like this. Check it out if you're looking for more examples: http://code.google.com/p/scrollback -TMG From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:00:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:00:27 -0200 Subject: Finding the full path of an executable References: Message-ID: En Fri, 16 Jan 2009 23:08:27 -0200, escribiste en el grupo gmane.comp.python.general > Unknown wrote: >> On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote: >>> Is there a portable way to find the full path of a filename that would >>> be called by os.execvp()? > The correct answer would be "/bin/echo" but abspath("echo") is just > going to give me /echo. I need something that will search through > the PATH like execvp() would. I can do it myself, but I'm surprised that > such a feature is not already readily available somewhere. py> import distutils.spawn py> help(distutils.spawn.find_executable) Help on function find_executable in module distutils.spawn: find_executable(executable, path=None) Try to find 'executable' in the directories listed in 'path' (a string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']). Returns the complete filename or None if not found. py> distutils.spawn.find_executable("sc") 'C:\\WINDOWS\\system32\\sc.exe' -- Gabriel Genellina From zak.mc.kraken at libero.it Sat Jan 17 05:05:17 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sat, 17 Jan 2009 11:05:17 +0100 Subject: vb2py status? References: Message-ID: axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? I don't know this vb2py, but you can do a 2 pass conversion [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] -- By ZeD From vijayakumar.subburaj at gmail.com Sat Jan 17 05:09:36 2009 From: vijayakumar.subburaj at gmail.com (v4vijayakumar) Date: Sat, 17 Jan 2009 02:09:36 -0800 (PST) Subject: braces fixed '#{' and '#}' Message-ID: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> I saw some code where someone is really managed to import braces from __future__. ;) def test(): #{ print "hello" #} From dragosmocrii at gmail.com Sat Jan 17 05:16:14 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 02:16:14 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> Message-ID: <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> On Jan 17, 11:48?am, "Gabriel Genellina" wrote: > En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo > gmane.comp.python.general > > > I am trying to make a testing script to load/save cookies to a file > > with FileCookieJar, but it results in this error: FileCookieJar has > > not attribute "_self_load" > > FileCookieJar is an abstract class, although it isn't clear at all from > the documentation. (You may want to file a documentation bug athttp://bugs.python.org) > You must instantiate a specific subclass (like MozillaCookieJar), which > determines the actual file format used. > > -- > Gabriel Genellina Oh, thank you so much. Using MozillaCookieJar works just fine. But could you please explain what an abstract class is (or where i can find documentation for this term). Thanks! From kay.schluehr at gmx.net Sat Jan 17 05:28:04 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 17 Jan 2009 02:28:04 -0800 (PST) Subject: English-like Python References: Message-ID: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> On 16 Jan., 02:02, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? No, but I've once written a Python dialect that uses German text. Just look at how amazing this result is !!! But be warned it requires knowledge of the German language. http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm > I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. As you know Python 3.0 has full unicode support. Python 4.0 will be surely written in Mandarin or Hindi. > For example, the following code... > > >>> import os > > >>> def list_files(dirname): > >>> ? ? for p in os.listdir(dirname): > >>> ? ? ? ? print p > > >>> list_files("some_dir") > > foo > bar > etc > > ...might be translated as... > > >>> Import the operating system module. > > >>> Define a new function as "list files" which accepts > > ? ? "a path" and does the following: > ? ? ? ? For every item in the list returned by the operating system's > ? ? ? ? directory listing of the given path, do the following: > ? ? ? ? ? ? ?Print the item. > > >>> List files from "some_dir". > > foo > bar > etc > > Obviously, creating a parser capable of handling such "code" would > require a very good understanding not only of the English language but > also of how ideas expressed in spoken languages are represented in terms > that a computer can understand. Yep. Resolving ambiguities in natural languages is actually an open research topic. Moving from Python to a language that is more context dependent than Larry Wall ever dreamed about and launch an interpreter on the Enterprise is actually a worthwhile project for future generations. Kay From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:32:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:32:35 -0200 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo gmane.comp.python.general > I ran a few tests on the new Python 2.6 multiprocessing module before > migrating a threading code, and found out the locking code is not > working well. In this case, a pool of 5 processes is running, each > trying to get the lock and releasing it after waiting 0.2 seconds > (action is repeated twice). It looks like the multiprocessing lock > allows multiple locking after the second pass. Running the exact same > code with threads works correctly. I've tested your code on Windows and I think the problem is on the Queue class. If you replace the Queue with some print statements or write to a log file, the sequence lock/release is OK. You should file a bug report on http://bugs.python.org/ -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 05:42:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 08:42:46 -0200 Subject: multiprocessing question/error References: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> <200901170814.37728.lenz@joinville.udesc.br> Message-ID: En Sat, 17 Jan 2009 14:14:37 -0200, Eduardo Lenz escribi?: > Another question: is it possible to > change a bound method to a function on the fly ? I was wondering if > something > like class.__dict__["function_name"] could do the job. Exactly. Or, if you already have the method, use its im_func attribute to obtain the original function. BTW, im_self is the "self" argument. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 06:09:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 09:09:19 -0200 Subject: Python Startup file References: Message-ID: En Sat, 17 Jan 2009 02:23:40 -0200, Gary Smith escribi?: > I've never been able to get ActiveState Python's PythonWin to observe the > file referenced in the Windows PYTHONSTARTUP environment variable. > > Many thanks for pointing out the obvious to me AFAIK, PythonWin doesn't honor the PYTHONSTARTUP variable. IDLE does, but you have to use the -s option. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 17 06:33:48 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 17 Jan 2009 09:33:48 -0200 Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> Message-ID: En Sat, 17 Jan 2009 08:16:14 -0200, Dragos escribi?: > On Jan 17, 11:48?am, "Gabriel Genellina" > wrote: >> En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo >> gmane.comp.python.general >> >> > I am trying to make a testing script to load/save cookies to a file >> > with FileCookieJar, but it results in this error: FileCookieJar has >> > not attribute "_self_load" >> >> FileCookieJar is an abstract class, although it isn't clear at all from >> the documentation. (You may want to file a documentation bug >> athttp://bugs.python.org) >> You must instantiate a specific subclass (like MozillaCookieJar), which >> determines the actual file format used. > > Oh, thank you so much. > Using MozillaCookieJar works just fine. > > But could you please explain what an abstract class is (or where i can > find documentation for this term). Thanks! Try http://en.wikipedia.org/wiki/Abstract_class In short, it's an incomplete class, with "holes" that subclasses must fill in order to get a complete, working class (a "concrete" class, as opposed to the "abstract" base). If you look at FileCookieJar, its load() method calls self._really_load but no such method exists in that class nor its ancestors (this explains the error you got). Subclasses of FileCookieJar *must* implement _really_load to be usable. It's customary to define the method anyway, and raise NotImplementedError; this serves two purposes: - document the expected interfase - error messages are more meaningful (FileCookieJar.save() is implemented this way; _really_load() should be the same) -- Gabriel Genellina From jstroud at mbi.ucla.edu Sat Jan 17 06:37:44 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 17 Jan 2009 03:37:44 -0800 Subject: Pythonic way to handle coordinates In-Reply-To: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: Pierre-Alain Dorange wrote: > What is the elegant way to handle coordinates ? > Do i need to continue using tuples or do i need to write a Point class. > I feel a point class would be nice, because i could implement operators > with it ? But i think Point class must exist allready ? My instinctive advice is to use a point class. My wise advice is to put it in a library you will maintain and reuse--or else you will find yourself re-writing point classes all of the time. A Point class will also give you a place to consolidate all of those methods specific to manipulating points. Thanks to python magic methods, you can also design some nifty shortcuts to access the attributes of your point. Here is a fun example for no other reason than I'm too tired to do anything important right now: class Point(object): def __init__(self, axes): self.axes_names = axes.split() self.axes = dict(enumerate(self.axes_names)) for axis in self.axes_names: setattr(self, axis, 0.0) def check_axis(self, i): if i not in self.axes: raise ValueError, "No such axis %s" % i def __setitem__(self, i, v): self.check_axis(i) setattr(self, self.axes[i], v) def __getitem__(self, i): self.check_axis(i) return getattr(self, self.axes[i]) def __iter__(self): return (getattr(self, i) for i in self.axes_names) def move(self, other): for i, v in enumerate(other): self[i] += v def magnitude(self): import math return math.sqrt(sum(v**2 for v in self)) E.g.: py> p = Point('x y z') py> list(p) [0.0, 0.0, 0.0] py> p.move([2, 3, 4]) py> p.x, p.y, p.z (2, 3, 4) py> p[0], p[1], p[2] (2, 3, 4) py> list(p) [2, 3, 4] py> tuple(p) (2, 3, 4) py> p.magnitude() 5.3851648071345037 py> q = Point('x y z') py> q.move([1, 2, 3]) py> p.move(q) py> list(p) [3.0, 5.0, 7.0] py> p[1] = 15.0 py> list(p) [3.0, 15.0, 7.0] With the introduction of the second point, q, one can begin to see the necessity for a class factory that produces Point classes of the desired dimensionalities in desired coordinate systems: def point(axes): class P(Point): def __init__(self, values): Point.__init__(self, axes) self.move(values) return P Note that we have have not used metaclasses--which would require messier code but produce classes that would potentially behave a better as super classes. The point function is used as simply as it is written: py> Point3D = point('x y z') py> p = Point3D([0.0, 0.0, 0.0]) py> list(p) [0.0, 0.0, 0.0] py> q = Point3D([5.0, 6.0, 7.0]) py> list(q) [5.0, 6.0, 7.0] py> p.move(q) py> list(p) [5.0, 6.0, 7.0] Incidentally, the classes returned by point are heritable, etc. class Point3D(point('x y z')): def __repr__(self): return "Point3D(%s)" % list(self) def __add__(self, other): return Point3D(sum(t) for t in zip(self, other)) py> p = Point3D([8, 7, 6]) py> p Point3D([8.0, 7.0, 6.0]) py> str(p) 'Point3D([8.0, 7.0, 6.0])' py> q = Point3D([5, 4, 3]) py> r = p + q py> r Point3D([13.0, 11.0, 9.0]) Now have fun with this stuff. I need to go to sleep. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From andrew at acooke.org Sat Jan 17 07:20:36 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 17 Jan 2009 04:20:36 -0800 (PST) Subject: Pythonic way to handle coordinates References: <1itolf1.umwbkvcdi280N%pdorange@pas-de-pub-merci.mac.com> Message-ID: although james's idea is quite neat (especially the idea of heritable classes), my initial reaction was that it's too over-engineered. so here's a different approach. there are two "tricks" that can help make using tuples easier: (1) unpacking the return value. (x, y) = returns_a_point() x += 1 (2) passing a tuple to a function that takes an x and a y value: def takes_two_values(x, y): ... p = (1, 2) takes_two_values(*p) and what I have done in the past is exploit these, so that functions/ methods that only takes a point takes two values while those that take many points, other arguments, etc, take a tuple. this sounds messy but works quite well because you tend to use the first kind of functions when you are changing coordinates (and then it is useful to treat a point as separate x and y values) and the second kind of functions when you are handling collections of points that don't need modifying. andrew From dragosmocrii at gmail.com Sat Jan 17 07:38:23 2009 From: dragosmocrii at gmail.com (Dragos) Date: Sat, 17 Jan 2009 04:38:23 -0800 (PST) Subject: FileCookieJar has not attribute "_self_load" References: <823b536f-b846-4ec3-aabd-774876733588@t26g2000prh.googlegroups.com> <9ae6f8bb-c39e-49f6-a5bc-46d5268a3ecf@w1g2000prk.googlegroups.com> Message-ID: On Jan 17, 1:33?pm, "Gabriel Genellina" wrote: > En Sat, 17 Jan 2009 08:16:14 -0200, Dragos ? > escribi?: > > > > > On Jan 17, 11:48?am, "Gabriel Genellina" > > wrote: > >> En Fri, 16 Jan 2009 17:19:47 -0200, escribiste en el grupo > >> gmane.comp.python.general > > >> > I am trying to make a testing script to load/save cookies to a file > >> > with FileCookieJar, but it results in this error: FileCookieJar has > >> > not attribute "_self_load" > > >> FileCookieJar is an abstract class, although it isn't clear at all from > >> the documentation. (You may want to file a documentation bug ? > >> athttp://bugs.python.org) > >> You must instantiate a specific subclass (like MozillaCookieJar), which > >> determines the actual file format used. > > > Oh, thank you so much. > > Using MozillaCookieJar works just fine. > > > But could you please explain what an abstract class is (or where i can > > find documentation for this term). Thanks! > > Tryhttp://en.wikipedia.org/wiki/Abstract_class > In short, it's an incomplete class, with "holes" that subclasses must fill ? > in order to get a complete, working class (a "concrete" class, as opposed ? > to the "abstract" base). > > If you look at FileCookieJar, its load() method calls self._really_load ? > but no such method exists in that class nor its ancestors (this explains ? > the error you got). Subclasses of FileCookieJar *must* implement ? > _really_load to be usable. > > It's customary to define the method anyway, and raise NotImplementedError; ? > this serves two purposes: > - document the expected interfase > - error messages are more meaningful > (FileCookieJar.save() is implemented this way; _really_load() should be ? > the same) > > -- > Gabriel Genellina Thanks, got it. From luismgz at gmail.com Sat Jan 17 07:51:46 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sat, 17 Jan 2009 04:51:46 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: On Jan 16, 5:27?pm, mk wrote: > Hello everyone, > > I looked for it I swear, but just can't find it. > > Most Python books seem to focus on examples of how to call functions > from standard library. I don't need that, I have online Python > documentation for that. > > I mean really advanced mental gymnastics, like gory details of how > Python objects operate, how to exploit its dynamic capabilities, dos and > donts with particular Python objects, advanced tricks, everything from > chained decorators to metaprogramming. Dive Into Python comes closest to > this ideal from what I have found, but still not far enough. > > Anybody found such holy grail? > > Regards, > mk I believe that any book will give you enough information about python's objects behaviour. But if you want to understand the more esoteric aspects of python (I'm in the same situation), perhaps you should investigate decorators and metaclasses. A good starting point is the 3 article series in decorators by Bruce Eckel in Artima ( http://www.artima.com/weblogs/viewpost.jsp?thread=240808 ). I second the suggestion of reading samples and cookbooks, for example in ActiveState's site. I found particularly interesting one that shows how to implement an ORM under 100 lines ( http://code.activestate.com/recipes/496905/ ). This script goes deep into black magic and it's clear enough to grasp. Luis From dotancohen at gmail.com Sat Jan 17 08:00:35 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sat, 17 Jan 2009 15:00:35 +0200 Subject: English-like Python In-Reply-To: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> References: <8637b862-975c-490f-b102-af2671397bcd@l33g2000pri.googlegroups.com> Message-ID: <880dece00901170500n43465493p8aa75fd4ecf3db85@mail.gmail.com> 2009/1/17 Kay Schluehr : > On 16 Jan., 02:02, The Music Guy wrote: >> Just out of curiousity, have there been any attempts to make a version >> of Python that looks like actual English text? > > No, but I've once written a Python dialect that uses German text. Just > look at how amazing this result is !!! But be warned it requires > knowledge of the German language. > > http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm > You might find HPL (Hebrew Programming Language) interesting: http://hpl.sourceforge.net/ HPL is PHP but with Hebrew operators, commands, and builtin functions. The interesting thing is that HPL is actually useful, as Hebrew and Arabic are written from right to left and many text editors get confused with RTL and LTR text on the same line. So typing in HPL looks better in the text editor and is more easily understood. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From vivainio at gmail.com Sat Jan 17 08:08:45 2009 From: vivainio at gmail.com (Ville Vainio) Date: Sat, 17 Jan 2009 05:08:45 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 2:57?pm, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... Isn't that a tad thankless and premature? It may be that the "support" aspect needs to be emphasized (currently, the paying customers get a priority over non-paying customers, but there are no formal support contracts), but if we assume that the usage of Qt & PyQt in commercial setting is going to skyrocket (I'd wager that it's a pretty safe assumption), selling plain support could prove very profitable as well - esp. since most PyQt users probably won't be too eager to start messing with SIP & fiddling around with Qt C++ plumbing. From mario.ruggier at gmail.com Sat Jan 17 08:09:13 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Sat, 17 Jan 2009 05:09:13 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> Message-ID: <8002c48c-6421-49a5-a613-22baba29abbc@r36g2000prf.googlegroups.com> On Jan 17, 12:04?am, ajaksu wrote: > On Jan 16, 3:45?pm, mario ruggier wrote: > > > > '(x for x in ()).throw("bork")' > > > What is the potential security risk with this one? > > I don't see a concrete issue, just found it tempting... raising hand- > crafted objects :) OK, I can think of no good reson why anyone would want to do that from within a temlate, so I'd be fine with blocking out any attribute whose name starts with "throw" to block this out. > > All the above attempts will be blocked this way. Any other disallow- > > sub-strings to add to the list above? > > None that I know of, but I suggest testing with dir, globals, locals > and '__' enabled (which I haven't done yet), as spotting possible > flaws should be easier. If you can get BOM+encoded garbage tested (seehttp://tinyurl.com/72d98y), it might be worth it too. The BOM stuff is interesting... from that discussion, I think it would be also a good idea to blacklist "object" out of the restricted builtins. I played with this, and prepared a file template as well as a little script to run it... see below. To tweak any disallwoed builtins back into the restricted namespace for testing, you can just do something like: d.set_on_globals("dir", dir) for each name you'd like to add, when setting up the domain (see script below). To re-enable "__" lookups, you'd need to tweak the regexp above, in the RestrictedEvaluator class. > This one fails in lots of interesting ways when you juggle keyword- > args around: > exprs = [ > ? ? 'evoque("hmm", filters=[unicode.upper ] ,src="/etc/python2.5/ > site.py")', > ] Not sure what you mean... it just renders that source code file uppercased (if it finds it as per the domain setup) ?!? Here's (a) a mini testing py2-py3 script, similar to previous one above but to read a template from a file (there may be additional tricks possible that way), and (b) a sample companion test template. evoque_restricted_file_test.py ---- # in lieu of print, py2/py3 import sys def pr(*args): sys.stdout.write(" ".join([str(arg) for arg in args])+'\n') # from os.path import abspath, join, dirname from evoque import domain, template # set the base for for the defualt collection DEFAULT_DIR = abspath((dirname(__file__))) # a restricted domain instance d = domain.Domain(DEFAULT_DIR, restricted=True, errors=3, quoting='str') # errors: 3 -> renders, 4 -> raises any evaluation errors, # see: http://evoque.gizmojo.org/usage/errors/ # Tweak domain.globals to add specific callables for testing: d.set_on_globals("dir", dir) d.set_on_globals("gobals", globals) d.set_on_globals("locals", locals) pr("domain", d.default_collection.dir, d.restricted and "RESTRICTED" or "*** unrestricted ***") t = d.get_template(restricted_exprs.txt) pr(t.evoque()) ---- restricted_exprs.txt ---- #[ BOM + encoded trickery Note: when evaluated in python interpreter: >>> eval("# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-") but when specified within a template here as: ${# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-} gives **pre-evaluation**: SyntaxError: unknown encoding: utf7 ]# ${"# coding: utf7\n +AG8AYgBqAGUAYwB0AC4AXwBfAHMAdQBiAGMAbABhAHMAcwBlAHMAXwBf-"}, #[ Attempt to subversively build string expressions ]# Explicitly written target expression: ().__class__.mro() [1].__subclasses__() evaluates: ${().__class__.mro()[1].__subclasses__()} Subversive variation: "()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()" evaluates (to just the str!): ${"()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()"} Attempt to "set" same subsersively built expr to a loop variable and then "evaluate" that variable: $for{ expr in [ str("()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()") ] } evaluates (to just the str!): ${expr} attempt eval(...): ${eval(expr)} $rof (Note: evoque does not explicitly allow arbitrary setting of variables, except within for loops.) ---- mario From gnewsg at gmail.com Sat Jan 17 08:58:35 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 17 Jan 2009 05:58:35 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> Message-ID: <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> On 17 Gen, 05:26, John Machin wrote: > On Jan 17, 3:08?pm, Steve Holden wrote: > > > Giampaolo Rodola' wrote: > > > On 17 Gen, 04:43, Terry Reedy wrote: > > >> Giampaolo Rodola' wrote: > > >>> That would help to avoid replacing "" with b"" almost everywhere in my > > >>> code. > > >> Won't 2to3 do that for you? > > > > I used 2to3 against my code but it didn't cover the "" -> b"" > > > conversion (and I doubt it is able to do so, anyway). > > > Note that if you are using 2.6 you should first convert your "" quotes > > to b"" - this won't make any practical difference, but then you will be > > able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. > > Perhaps before we get too far down the track of telling the OP what he > should do, we should ask him a little about his intentions: > > Is he porting to 3.0 and abandoning 2.x support completely? > [presumably unlikely] No. > So then what is the earliest 2.x that he wants to support at the same > time as 3.x? [presumably at least 2.5] I currently support Python versions from 2.3 to 2.6 by using un unique codebase. My idea is to support 3.x starting from the last upcoming release. > Does he intend to maintain two separate codebases, one 2.x and the > other 3.x? I think I have no other choice. Why? Is theoretically possible to maintain an unique code base for both 2.x and 3.x? > Else does he intend to maintain just one codebase written in some 2.x > dialect and using 2to3 plus sys.version-dependent code for the things > that 2to3 can't/doesn't handle? I don't think it would worth the effort. > Cheers, > John Thanks a lot --- Giampaolo http://code.google.com/p/pyftpdlib From aahz at pythoncraft.com Sat Jan 17 09:09:29 2009 From: aahz at pythoncraft.com (Aahz) Date: 17 Jan 2009 06:09:29 -0800 Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: [following up late] In article <2b3c916e-6908-4b12-933f-8f7bfa86cebc at i20g2000prf.googlegroups.com>, Russ P. wrote: > >Fair enough, but for code that is not intended for general public >usage (i.e., most code) so-called camelCase is every bit as good if >not better than using underscores to divide variable names. It saves a >few characters, and in my opinion it's significantly easier to read. >Identifiers divided by underscores always appear to me at first glance >to be multiple words, and I find that very annoying. > >So unless you think the standard library will someday include code for >air traffic management, I'll stick with camelCase, and I'll thank you >for not making an issue of it. You are missing the point: suppose you write a useful library in your air traffic management application, maybe one that does a good job of handling user input. If you have done a proper job of abstracting it from your application as a whole, you could easily publicize it, but it will never get into the standard library unless it meets current PEP8 guidelines. Why fuss about trying to figure out which parts of your application might in the future be published? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From gnewsg at gmail.com Sat Jan 17 09:11:30 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 17 Jan 2009 06:11:30 -0800 (PST) Subject: vb2py status? References: Message-ID: On 17 Gen, 11:05, Vito De Tullio wrote: > axtens wrote: > > So is vb2py dead? If not, any idea when it'll support python 3? > > I don't know this vb2py, but you can do a 2 pass conversion > > [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > > -- > By ZeD ...and presumibly get something which doesn't work at all. =) --- Giampaolo http://code.google.com/p/pyftpdlib From eliben at gmail.com Sat Jan 17 09:14:17 2009 From: eliben at gmail.com (eliben) Date: Sat, 17 Jan 2009 06:14:17 -0800 (PST) Subject: LGPL license for Qt 4.5 References: Message-ID: On Jan 14, 2:57?pm, sturlamolden wrote: > According to a Norwegian publication, Nokia will release Qt under LGPL > as of version 4.5. > > If I had stocks in Riverbank Computing ltd., I would sell them now... > Unlikely... The switch of Qt to LGPL will almost certainly vastly increase the Qt user base. Leaving very few and minor imperfections aside, Qt is a superior GUI library and programming framework, and its lack of free license seriously impeded adoption in the past. The increase in Qt use will also cause a great increase in PyQt use, and I would imagine Riverbank will be able to make a good living from consulting on PyQt topics, even if their sales from selling PyQt "licenses" decrease. Eli From martin at v.loewis.de Sat Jan 17 09:24:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 15:24:11 +0100 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> Message-ID: <4971ea0b$0$7055$9b622d9e@news.freenet.de> >> Does he intend to maintain two separate codebases, one 2.x and the >> other 3.x? > > I think I have no other choice. > Why? Is theoretically possible to maintain an unique code base for > both 2.x and 3.x? That is certainly possible! One might have to make tradeoffs wrt. readability sometimes, but I found that this approach works quite well for Django. I think Mark Hammond is also working on maintaining a single code base for both 2.x and 3.x, for PythonWin. Regards, Martin From aahz at pythoncraft.com Sat Jan 17 09:33:35 2009 From: aahz at pythoncraft.com (Aahz) Date: 17 Jan 2009 06:33:35 -0800 Subject: pep-8 vs. external interfaces? References: <0c17f82b-4a09-4267-bfa4-fae01d60dd33@c36g2000prc.googlegroups.com> <27c6b149-3a5f-478d-a6fc-da87a66b9d4c@r36g2000prf.googlegroups.com> Message-ID: In article <27c6b149-3a5f-478d-a6fc-da87a66b9d4c at r36g2000prf.googlegroups.com>, Carl Banks wrote: >On Jan 4, 1:47=A0pm, Roy Smith wrote: >> >> Or, I could draw a line in the sand and say, "If it's a protocol >> primitive, it stays as written. =A0Otherwise, it's pep-8". =A0That's a >> little uglier because it's not always obvious to the user exactly >> which names are protocol primitives and which are higher-level >> operations. > >So the question becomes, "Why are you mixing protocol primitives and >high-level operations in the same namespace?" Because that's not >normally a well-advised thing to do. > >1. If you answered, "I shouldn't be", you should separate them and use >camel case for the protocol primitives. > >2. If you answered, "I'm including protocol primitive functions >alongside high-level operations because conceptually they are the >same, it's just that some functions happen to map directly to the >underlying protocol", you should follow PEP-8, because by doing that >you've implicity raised the protocol primitive functions to high-level >status. > >3. If you answered, "Protocol primitives are in the same namespace for >convenience, but high-level users shouldn't use them", then you should >use camel case for the protocol primitives but prepend an underscore. > >4. If you answered, "I include those functions in the same namespace >because I am following the example of other language bindings in Perl, >Java, Ruby, etc.,", then figure out whether it's important to be >consistent with Perl, Java, Ruby, etc., and if so, do whatever they >did. If not, see #1. This deserves to be recorded on a web page somewhere -- can you stick it on the wiki? (I got laid off two weeks ago, so if you're too busy, would you like me to do it?) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From roy at panix.com Sat Jan 17 09:57:58 2009 From: roy at panix.com (Roy Smith) Date: Sat, 17 Jan 2009 09:57:58 -0500 Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: In article <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, v4vijayakumar wrote: > I saw some code where someone is really managed to import braces from > __future__. ;) > > def test(): > #{ > print "hello" > #} That usage is obsolete. Current best practice is: def test(): """{""" print "hello" """}""" From steve at holdenweb.com Sat Jan 17 10:05:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 17 Jan 2009 10:05:24 -0500 Subject: braces fixed '#{' and '#}' In-Reply-To: References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: Roy Smith wrote: > In article > <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, > v4vijayakumar wrote: > >> I saw some code where someone is really managed to import braces from >> __future__. ;) >> >> def test(): >> #{ >> print "hello" >> #} > > That usage is obsolete. Current best practice is: > > def test(): > """{""" > print "hello" > """}""" Which would be OK if it were syntactically valid ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jeff at jmcneil.net Sat Jan 17 10:42:47 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 07:42:47 -0800 (PST) Subject: tp_base, ob_type, and tp_bases Message-ID: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> Hi all, In an effort to get (much) better at writing Python code, I've been trying to follow and document what the interpreter does from main in Modules/python.c up through the execution of byte code. Mostly for my own consumption and benefit, but I may blog it if it turns out half way decent. Anyways, I've been going through PyType_Ready as it sets up copies of PyObjectType, and I'm a bit confused by tp_base, ob_type, and tp_bases. I've been using http://docs.python.org/c-api/index.html as a guideline. So, the documentation states that ob_type is a pointer to the type's type, or metatype. Rather, this is a pointer to the new type's metaclass? Next, we have tp_base. That's defined as "an optional pointer to a base type from which type properties are inherited." The value of tp_base is then added to the tp_bases tuple. This is confusing me. On the surface, it sound as though they're one in the same? I *think* (and dir() of a subclass of type seems to back it up), that tp_base is only at play when the object in question inherits from type? I've tried Googling around a bit. Perhaps it's better documented somewhere? Or perhaps someone can give me a quick explanation? Thanks! Jeff From schaefer.mp at gmail.com Sat Jan 17 10:46:54 2009 From: schaefer.mp at gmail.com (MatthewS) Date: Sat, 17 Jan 2009 07:46:54 -0800 (PST) Subject: Pyro deadlock Message-ID: <71ed81f9-7d95-44bc-8ad0-3c8e5869cb43@v5g2000pre.googlegroups.com> I'd like to know if the following behavior is expected and can be avoided: I have a Pyro server object that maintains a queue of work, and multiple Pyro worker objects that take work off the queue by calling a method on the server (get_work) and then return the work to the server by calling another method (return_result). The problem is that I experience a deadlock condition in the return_result method. Is this deadlock expected or should Pyro be able to synchronize the remote calls to server's callback method when called from multiple workers at the same time? If so any hints are appreciated. /Matthew From martin at v.loewis.de Sat Jan 17 10:50:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 16:50:37 +0100 Subject: tp_base, ob_type, and tp_bases In-Reply-To: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> Message-ID: <4971fe4d$0$30907$9b622d9e@news.freenet.de> > So, the documentation states that ob_type is a pointer to the type's > type, or metatype. Rather, this is a pointer to the new type's > metaclass? That's actually the same. *Every* ob_type field points to the object's type, e.g. for strings, integers, tuples, etc. That includes type objects, where ob_type points to the type's type, i.e. it's meta-type, also called metaclass (as "class" and "type" are really synonyms). > Next, we have tp_base. That's defined as "an optional pointer to a > base type from which type properties are inherited." The value of > tp_base is then added to the tp_bases tuple. This is confusing me. On > the surface, it sound as though they're one in the same? (I don't understand the English "one in the same" - interpreting it as "as though they should be the same") No: tp_bases is a tuple of all base types (remember, there is multiple inheritance); tp_base (if set) provides the first base type. > I *think* (and dir() of a subclass of type seems to back it up), that > tp_base is only at play when the object in question inherits from > type? No - it is the normal case for single inheritance. You can leave it NULL, which means you inherit from object. Regards, Martin From zak.mc.kraken at libero.it Sat Jan 17 10:52:10 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sat, 17 Jan 2009 16:52:10 +0100 Subject: vb2py status? References: Message-ID: Giampaolo Rodola' wrote: >> > So is vb2py dead? If not, any idea when it'll support python 3? >> I don't know this vb2py, but you can do a 2 pass conversion >> [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > ...and presumibly get something which doesn't work at all. =) why? AFAIK there aren't problems into the 2to3 phase I don't think the resulted python code would be the best one, but at least it should work... -- By ZeD From jeff at jmcneil.net Sat Jan 17 11:09:30 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 08:09:30 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > So, the documentation states that ob_type is a pointer to the type's > > type, or metatype. Rather, this is a pointer to the new type's > > metaclass? > > That's actually the same. *Every* ob_type field points to the object's > type, e.g. for strings, integers, tuples, etc. That includes type > objects, where ob_type points to the type's type, i.e. it's meta-type, > also called metaclass (as "class" and "type" are really synonyms). > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > base type from which type properties are inherited." ?The value of > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > the surface, it sound as though they're one in the same? > > (I don't understand the English "one in the same" - interpreting it > as "as though they should be the same") > > No: tp_bases is a tuple of all base types (remember, there is multiple > inheritance); tp_base (if set) provides the first base type. > > > I *think* (and dir() of a subclass of type seems to back it up), that > > tp_base is only at play when the object in question inherits from > > type? > > No - it is the normal case for single inheritance. You can leave it > NULL, which means you inherit from object. > > Regards, > Martin Thank you! It was tp_base that was confusing me. The tp_bases member makes sense as Python supports multiple inheritance. It wasn't immediately clear that tp_base is there for single inheritance reasons. It's all quite clear now. Is that an optimization of sorts? Jeff From jeff at jmcneil.net Sat Jan 17 11:12:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 08:12:19 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> Message-ID: <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> On Jan 17, 11:09?am, Jeff McNeil wrote: > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > > So, the documentation states that ob_type is a pointer to the type's > > > type, or metatype. Rather, this is a pointer to the new type's > > > metaclass? > > > That's actually the same. *Every* ob_type field points to the object's > > type, e.g. for strings, integers, tuples, etc. That includes type > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > also called metaclass (as "class" and "type" are really synonyms). > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > base type from which type properties are inherited." ?The value of > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > the surface, it sound as though they're one in the same? > > > (I don't understand the English "one in the same" - interpreting it > > as "as though they should be the same") > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > inheritance); tp_base (if set) provides the first base type. > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > tp_base is only at play when the object in question inherits from > > > type? > > > No - it is the normal case for single inheritance. You can leave it > > NULL, which means you inherit from object. > > > Regards, > > Martin > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > makes sense as Python supports multiple inheritance. ?It wasn't > immediately clear that tp_base is there for single inheritance > reasons. It's all quite clear now. > > Is that an optimization of sorts? > > Jeff Well, maybe not specifically for single inheritance reasons, I just didn't see an immediate reason to keep a separate pointer to the first base type. From fuzzyman at gmail.com Sat Jan 17 11:12:38 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Sat, 17 Jan 2009 08:12:38 -0800 (PST) Subject: vb2py status? References: Message-ID: <4c5e5a69-b4bf-4180-a7e2-ecfc2f52f5ce@v39g2000pro.googlegroups.com> On Jan 17, 3:52?pm, Vito De Tullio wrote: > Giampaolo Rodola' wrote: > >> > So is vb2py dead? If not, any idea when it'll support python 3? > >> I don't know this vb2py, but you can do a 2 pass conversion > >> [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > > ...and presumibly get something which doesn't work at all. =) > > why? > AFAIK there aren't problems into the 2to3 phase > I don't think the resulted python code would be the best one, but at least > it should work... > > -- > By ZeD 2to3 is far from perfect, and assuming the same is true of vb2py (inevitably) then you get imperfection squared. :-) Michael Foord -- http://www.ironpythoninaction.com/ From lenz at joinville.udesc.br Sat Jan 17 11:14:37 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Sat, 17 Jan 2009 08:14:37 -0800 Subject: multiprocessing question/error In-Reply-To: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> References: <70143f22-ef53-4b1d-a1e8-aed9ee316813@x16g2000prn.googlegroups.com> Message-ID: <200901170814.37728.lenz@joinville.udesc.br> On Saturday 17 January 2009 00:43:35 Aaron Brady wrote: > On Jan 16, 11:39?pm, Eduardo Lenz wrote: > > Hi, > > > > I was using the former processing package with python 2.5 with no > > problems. After switching to python 2.6.1 I am having some problems with > > the same code. The problem seems to be related to the fact that I am > > using Pool.map with a bounded method, since it is inside a class. To > > clarify a little bit, let me show some parts of the code .... > > Hello, > > > class Pygen3(self).... > > I infer this was a typo. > > > ? ? .... > > ? ? .... > > ? ? .... > > ? ? def calcula(self,indiv): > > ? ? ? ? .... > > ? ? ? ? .... > > ? ? ? ? .... > > > > ? ?def evaluate(self): > > ? ? ?.... > > ? ? ?.... > > ? ? indiv = range(mult*self.popsize,(mult+1)*self.popsize) > > ? ?pool = Pool(processes=nproc) > > ? ?results = pool.map(self.calcula,indiv) > > I infer the indentation drifted. > > > ? ?... > > ? ?... > > > > the error is the following > > > > Exception in thread Thread-1: > > Traceback (most recent call last): > > ? File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner > > ? ? self.run() > > ? File "/usr/lib/python2.6/threading.py", line 477, in run > > ? ? self.__target(*self.__args, **self.__kwargs) > > ? File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > > _handle_tasks > > ? ? put(task) > > PicklingError: Can't pickle : attribute lookup > > __builtin__.instancemethod failed > > > > Thanks for your help. > > Checking on two typos above. I have this working: > > from multiprocessing import Process > > class C(object): > def m1( self ): > p1 = Process(target=self.m2, args=('bob1',)) > p2 = Process(target=self.m2, args=('bob2',)) > p1.start() > p2.start() > p1.join() > p2.join() > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > But I get the same error as you with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= range( 10 ) > pool= Pool( 5 ) > results = pool.map(self.m2,arg) > print results > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > I build a workaround with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= zip( [ self ]* 10, range( 10 ) ) > pool= Pool( 5 ) > results = pool.map(C_m2,arg) > print results > def m2( self, arg ): > print 'hello', arg > return arg* 2 > def C_m2( ar, **kwar ): > return C.m2( *ar, **kwar ) > > if __name__ == '__main__': > c= C() > c.m1() > > Note that you have to explicitly include 'self' as a first parameter > when packing the arguments, and then explicitly unpack it in the > helper function. Also, wrapping 'm2' with '@staticmethod' also fails > with this error: > > Exception in thread Thread-1: > Traceback (most recent call last): > File "c:\programs\python26\lib\threading.py", line 522, in > __bootstrap_inner > self.run() > File "c:\programs\python26\lib\threading.py", line 477, in run > self.__target(*self.__args, **self.__kwargs) > File "c:\programs\python26\lib\multiprocessing\pool.py", line 225, > in _handle_tasks > put(task) > PicklingError: Can't pickle : attribute lookup > __builtin__.function failed > > If this works for you, it's possible to make the helper function more > dynamic, by accepting a class name and an attribute name as string > arguments, then retrieving them in the subprocesses. > -- > http://mail.python.org/mailman/listinfo/python-list Thanks for your help ! The only question remaninig is why it iused to work with the former processing package. Another question: is it possible to change a bound method to a function on the fly ? I was wondering if something like class.__dict__["function_name"] could do the job. Actually, I was wondering with something like a casting, but a guess it is not possible. Thanks again, Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From alan.isaac at gmail.com Sat Jan 17 11:39:32 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 16:39:32 GMT Subject: tuple methods: documentation missing In-Reply-To: References: Message-ID: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> On 1/16/2009 6:44 PM Terry Reedy apparently wrote: > http://bugs.python.org/issue4966 Is this another lacuna or am I overlooking it? I cannot find the 3.0 documentation of string formatting with the ``%`` operator. Thanks, Alan Isaac From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 11:45:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 16:45:02 GMT Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> Message-ID: <0182018b$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 00:24:21 -0800, Aaron Brady wrote: > Can you make it work for a 3-way lookup? What do you mean "3-way lookup"? I'm going to take a guess... A maps to B, B maps to C, and C maps to A. Is that what you mean? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 11:55:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jan 2009 16:55:16 GMT Subject: Noob question: Is all this typecasting normal? References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: <018203f2$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 06:09:29 -0800, Aahz wrote: > You are missing the point: suppose you write a useful library in your > air traffic management application, maybe one that does a good job of > handling user input. If you have done a proper job of abstracting it > from your application as a whole, you could easily publicize it, but it > will never get into the standard library unless it meets current PEP8 > guidelines. Why fuss about trying to figure out which parts of your > application might in the future be published? You know, it is quite possible that some people may not care whether or not their code ends up in the standard library. Holding out the possibility of inclusion in the std lib may not be quite the encouragement you expect :) -- Steven From mario.ruggier at gmail.com Sat Jan 17 12:11:50 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Sat, 17 Jan 2009 09:11:50 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7e969dd3-d43f-4b0d-84cf-a1a44d9af9ee@n21g2000vba.googlegroups.com> <8002c48c-6421-49a5-a613-22baba29abbc@r36g2000prf.googlegroups.com> Message-ID: <1b4acd69-d35f-405a-9da9-a180acaa9e84@p2g2000prn.googlegroups.com> Just to add that a further potential subversion possibility could have been to build the expr in some way from within a template, and then dynamically setting that string as the source of a new template with from_string=True. This is precisely the reason why **from within a template** evoque has never supported the from_string parameter i.e. you *cannot* "load/create" a template from a string source from within another template -- you may *only* do that from within the python app. To illustrate, an extension of the previous example template could thus become: $for{expr in [ str("()."+"_"*2+"class"+"_"*2+".mro() [1]."+"_"*2+"subclasses"+"_"*2+"()") ]} ${% evoque("test", src="$${"+expr+"}", from_string=True) %} $rof That would fail, as it would simply take the value of src i.e. "$ {().__class__.mro()[1].__subclasses__()}" to mean the sub-path to the template file within the collection (from_string would be simply interpreted as an evaluation data parameter). See: http://evoque.gizmojo.org/directives/evoque/ From xahlee at gmail.com Sat Jan 17 12:16:07 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:16:07 -0800 (PST) Subject: reading file to list References: Message-ID: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby Here's a interesting toy problem posted by Drew Krause to comp.lang.lisp: ------------------------ On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) ----------------- Here's a emacs lisp version: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (defvar mylist '() "result list" ) (setq mylist '()) ; init in case eval'd again (mapc (lambda (x) (setq mylist (cons (split-string x " ") mylist )) ) (read-lines "xxblob.txt") ) The above coding style is a typical maintainable elisp. In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)). Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that. The ?read-lines? function really should be a built-in part of elisp. It is not so mostly because emacs people have drawn themselves into a elitist corner, closing off to the outside world. (i am sending a suggestion to the official emacs dev list on adding read-line now.) ----------------- w_a_x_... at yahoo.com gave a ruby solution: IO.readlines("blob.txt").map{|line| line.split } augumented by Jilliam James for result to be numbers: IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} Very beautiful. ------------------- That's really the beauty of Ruby. This problem and ruby code illustrates 2 fundamental problems of lisp, namely, the cons problem, and the nested syntax pain. Both of which are practically unfixable. The lisp's cons fundamentally makes nested list a pain to work with. Lisp's nested syntax makes functional sequencing cumbersome. In the ruby code, its post-fix sequential notation (as a side effect of its OOP notation) brings out the beauty of functional sequencing paradigm (sometimes known as functional chain, sequencing, filtering, unix piping). its list, like all modern high level langs such as perl, php, python, javascript, don't have the lisp's cons problem. The cons destroys the usability of lists up-front, untill you have some at least 2 full-time years of coding lisp to utilize cons properly. (and even after that, it is still a pain to work with, and all you gain is a bit of speed optimization in rare cases that requires largish data, most of which has better solutions such as a database.) Both of these problems i've published articles on. For more detail on the cons problem, see the section ?The Cons Business? at ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html For more detail on the nested syntax problem for function chaining, see the section ?How Purely Nested Notation Limits The Language's Utility? at: ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html Xah ? http://xahlee.org/ ? From tekion at gmail.com Sat Jan 17 12:20:34 2009 From: tekion at gmail.com (tekion) Date: Sat, 17 Jan 2009 09:20:34 -0800 (PST) Subject: figuring week of the day.... References: <5d4fadef-76a3-498f-973f-64fd0e5018be@d42g2000prb.googlegroups.com> <49665986.7080301@thechases.com> Message-ID: On Jan 9, 6:05?am, Tim Chase wrote: > Tim Chase wrote: > > tekion wrote: > >> Is there a module where you could figure week of the day, like where > >> it starts and end. I need to do this for a whole year. Thanks. > > > the monthcalendar() call returns the whole month's calendar which > > may be more what you want for the big-picture. > > And if you want a whole year's worth, you can get pretty close with: > > ? ?import itertools as i > ? ?import calendar as c > ? ?for month in range(1,13): > ? ? ?for week in c.monthcalendar(2009, month): > ? ? ? ?print repr(w) > > You don't detail how you want the month-boundaries to behave, so > this gives "calendar"'s default behavior of filling in zeros on > month-boundaries, so November through the 1st week in Dec 2009 > comes back as > > ? ?... > ? ?[0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], > ? ?[0, 1, 2, 3, 4, 5, 6], > ? ?... > > rather than > > ? ?... > ? ?[26, 27, 28, 29, 30, 31, 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, 1, 2, 3, 4, 5, 6], > ? ?... > > -tkc Thanks, this is exactly what I am looking for. I will give it a try. Do you what argument or documentation I should read up on how to get the month's boundary rather than the default. I would assume it's just an argument I give when creating the month object. From digitig at gmail.com Sat Jan 17 12:21:24 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 17 Jan 2009 17:21:24 +0000 Subject: Noob question: Is all this typecasting normal? In-Reply-To: <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> References: <165772e9-437a-436c-9dc3-45fe947e0cdc@i24g2000prf.googlegroups.com> <6s7fm0F4k5tsU1@mid.uni-berlin.de> <1a342e5a-1774-4e86-bee1-a2ebe78a570c@p2g2000prn.googlegroups.com> <87sko1l2jk.fsf@benfinney.id.au> <2d65db37-6d71-4a4b-9cf2-5530b60c8218@o40g2000prn.googlegroups.com> <87k59dkwwv.fsf@benfinney.id.au> <87d4f4lw7a.fsf@benfinney.id.au> <2b3c916e-6908-4b12-933f-8f7bfa86cebc@i20g2000prf.googlegroups.com> Message-ID: 2009/1/3 Russ P. : > So unless you think the standard library will someday include code for > air traffic management, I'll stick with camelCase, and I'll thank you > for not making an issue of it. Another late comment, sorry, but as an air traffic management safety consultant, I'm quite interested about where in ATM you plan to use Python code, and how you will be meeting the applicable safety standards in the relevant administration. -- Tim Rowe From tino at wildenhain.de Sat Jan 17 12:29:05 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 18:29:05 +0100 Subject: reading file to list In-Reply-To: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: <49721561.8080204@wildenhain.de> Xah Lee wrote: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby > ... > OK, I want to create a nested list in Lisp (always of only integers) > from a text file, such that each line in the text file would be > represented as a sublist in the 'imported' list. > > example of a file's content > > 3 10 2 > 4 1 > 11 18 > > example of programing behavior > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > In a show-off context, it can be reduced to by about 50%, but still > far verbose than ruby or say perl (which is 1 or 2 lines. (python > would be 3 or 5)). So? Please count the lines: [line.strip().split() for line in file("blob.txt")] HTH Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From xahlee at gmail.com Sat Jan 17 12:34:39 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:34:39 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: <80a40799-d1c6-41ca-9fcc-82d3977ffa8d@e1g2000pra.googlegroups.com> On Jan 17, 9:16 am, Xah Lee wrote: > Here's a interesting toy problem posted by Drew Krause to > comp.lang.lisp: > ... The code in my previous elisp code got a bump. It should be: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (mapcar (lambda (x) (split-string x " ") ) (read-lines "xxblob.txt") ) The article is now archived at: ? A Ruby Illustration of Lisp Problems http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Xah ? http://xahlee.org/ ? From oc2007d5egjeqi01ecf0sw at newsguy.com Sat Jan 17 12:36:20 2009 From: oc2007d5egjeqi01ecf0sw at newsguy.com (Richard Hanson) Date: Sat, 17 Jan 2009 09:36:20 -0800 Subject: Jerry Pournelle gives award to Python and Guido for 2008 Message-ID: [NB: Blatant Python advocacy (and OP self-promotion).] Jerry Pournelle commends Python and Guido in "The Annual Orchid and Onions Parade" portion of his Chaos Manor Reviews column: > A reader [full-disclosure: that reader was me] nominated Python for an Orchid for Jerry's Orchid and Onions awards for 2008: ''' I nominate the computer language Python for an Orchid for 2008. This last year, Python broke through into worldwide popularity. The volunteer team led by BDFL (benevolent dictator for life) Guido van Rossum released "Python 3000" (Python 3.0) before year's end as well as releasing the next production-line 2.x version, Python 2.6. Python -- and Linux (the kernel) with its "BDFL" Linus Torvalds -- show that benevolent dictatorships are great forms of organization which can easily beat out other forms of cooperation in software development unable to escape Pournelle's Iron Law, whether proprietary *or* open-source software [...]. ''' Jerry Pournelle followed up with: ''' I completely agree with this. Python deserves a large Orchid. It's useful, well structured, easy to learn, and powerful. I use it to write quick filter functions among other things. I'm pleased to hand Guido a big Orchid. [...] ''' I add: Great job, Guido and all! -- Richard Hanson From google at mrabarnett.plus.com Sat Jan 17 12:44:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 17:44:12 +0000 Subject: reading file to list In-Reply-To: <49721561.8080204@wildenhain.de> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> Message-ID: <497218EC.9070108@mrabarnett.plus.com> Tino Wildenhain wrote: > Xah Lee wrote: >> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby >> >> > ... >> OK, I want to create a nested list in Lisp (always of only integers) >> from a text file, such that each line in the text file would be >> represented as a sublist in the 'imported' list. >> >> example of a file's content >> >> 3 10 2 >> 4 1 >> 11 18 >> >> example of programing behavior >> (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > >> >> In a show-off context, it can be reduced to by about 50%, but still >> far verbose than ruby or say perl (which is 1 or 2 lines. (python >> would be 3 or 5)). > > So? Please count the lines: > > [line.strip().split() for line in file("blob.txt")] > The original requirement was for a list of lists of integers: [[int(x) for x in line.split()] for line in open("blob.txt")] Still only 1 line, though. From gupta.neha at gmail.com Sat Jan 17 12:48:33 2009 From: gupta.neha at gmail.com (Neha Gupta) Date: Sat, 17 Jan 2009 09:48:33 -0800 (PST) Subject: psycopg2 weirdness Message-ID: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Hey, I only have little experience with web.py and psycopg2 and am running into a weird problem, I'd appreciate any help I can get with debugging it. I wrote a simple program that works and I don't see any crash: ---- import psycopg2 try: database_conn = psycopg2.connect("dbname='dbname' user='username' host='hostname'"); except: print "Unable to connect to the database!" database_conn.set_isolation_level(0) cur = database_conn.cursor(); while True: query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '01-05-2007' group by origin, crs_dep_hour order by origin, crs_dep_hour"; cur.execute(query) rows = cur.fetchall() print rows ----- However, I have a small website built using web.py framework which has a date picker that lets the user pick a date and it takes the user to a new url such as: localhost:8080/departures/01-05-2007. I issue a query to my database for the date selected by the user and retrieve the results. The problem now is that if I select different dates directly by changing the url then everything works but as soon as I pick a date from date picker the server crashes. I removed the date picker and made it just a text box but as soon as I hit the submit button, server crashes so I know it is not the date picker that causing trouble. --- class departures: def buildDepartureTableHtml(self, date): web.debug('date', date) # Issue the query. # select avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '2007-02-15' group by origin, crs_dep # _hour order by origin, crs_dep_hour; try: web.debug("About to issue query") # query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '" + date + "' group by origin, crs_dep_hour order by origin, crs_dep_hour"; query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as crs_dep_hour, origin from flightdata where date = '01-05-2007' group by origin, crs_dep_hour order by origin, crs_dep_hour"; cur.execute(query) web.debug('query executed!') rows = cur.fetchall() web.debug('rows fetched!') web.debug(rows) except Exception, e: print repr(e) database_conn.rollback() return "
Invalid Date
" -- // JS code function submitForm() { var date = ($("date").value).replace(/\//g,"-"); window.location = "http://" + window.location.host + "/ departures/" + date; } You can see above that I even ignored the date passed from the form and I have hardcoded '01-05-2007'. The message "About to issue query" gets printed as well as the right date chosen from the date picker but then I see the following: Assertion failed: (str != NULL), function PyString_FromString, file Objects/stringobject.c, line 107. Abort trap with a pop that says: "The application Python quit unexpectedly. The problem may have been caused by the _psycopg.so plug-in". -- I don't understand the error message above. The date did get passed correctly and am now not even using it, I use the hard coded date. So what is going on? Any help would be great. Thank you! Neha From ym5d19.python at gmail.com Sat Jan 17 12:48:50 2009 From: ym5d19.python at gmail.com (yang michael) Date: Sun, 18 Jan 2009 01:48:50 +0800 Subject: python3.0 base64 error Message-ID: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> I use base64 module on python3.0 like: import base64 b="hello world" a=base64.b64encode(b) print(a) but when i run it,it catch a error: Traceback (most recent call last): File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in a=base64.b64encode(b) File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode raise TypeError("expected bytes, not %s" % s.__class__.__name__) TypeError: expected bytes, not str and also the document's example: >>> import base64 >>> encoded = base64.b64encode('data to be encoded') >>> encoded 'ZGF0YSB0byBiZSBlbmNvZGVk' >>> data = base64.b64decode(encoded) >>> data 'data to be encoded' can not run too. what happen? -------------- next part -------------- An HTML attachment was scrubbed... URL: From xahlee at gmail.com Sat Jan 17 12:55:43 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 09:55:43 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <80a40799-d1c6-41ca-9fcc-82d3977ffa8d@e1g2000pra.googlegroups.com> Message-ID: <753b9f72-1c1a-41aa-ad7f-74ba38b30d60@w39g2000prb.googlegroups.com> On Jan 17, 9:34 am, Xah Lee wrote: > The code in my previous elisp code got a bump. It should be: > ... > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Sorry again. More correction: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) "\n" t) ) ) (mapcar (lambda (x) (mapcar (lambda (y) (string-to-number y) ) (split-string x " ") ) ) (read-lines "xxblob.txt") ) this is last post of correction. Xah ? http://xahlee.org/ ? From tino at wildenhain.de Sat Jan 17 13:25:12 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 19:25:12 +0100 Subject: reading file to list In-Reply-To: <497218EC.9070108@mrabarnett.plus.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> Message-ID: <49722288.4080304@wildenhain.de> MRAB wrote: > Tino Wildenhain wrote: >> Xah Lee wrote: >>> comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby >>> >>> >> ... >>> OK, I want to create a nested list in Lisp (always of only integers) >>> from a text file, such that each line in the text file would be >>> represented as a sublist in the 'imported' list. >>> >>> example of a file's content >>> >>> 3 10 2 >>> 4 1 >>> 11 18 >>> >>> example of programing behavior >>> (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) >> >>> >>> In a show-off context, it can be reduced to by about 50%, but still >>> far verbose than ruby or say perl (which is 1 or 2 lines. (python >>> would be 3 or 5)). >> >> So? Please count the lines: >> >> [line.strip().split() for line in file("blob.txt")] >> > The original requirement was for a list of lists of integers: Actually I read: "Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that." So I felt that requirement was dropped, but otherwise, you are right :-) > [[int(x) for x in line.split()] for line in open("blob.txt")] > > Still only 1 line, though. Yep. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From tino at wildenhain.de Sat Jan 17 13:43:03 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 17 Jan 2009 19:43:03 +0100 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <497226B7.7040404@wildenhain.de> Neha Gupta wrote: > Hey, > ... > crs_dep_hour, origin from flightdata where date = '" + date + "' group ^^^^^^^^^^^ never ever do that! Even more when input comes from user. The correct form is cur.exec("... date = %s group by ...",(date,)) please see dbapi2 documentation or examples which come with psycopg2. ... > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. The message "About to issue query" > gets printed as well as the right date chosen from the date picker but > then I see the following: > > Assertion failed: (str != NULL), function PyString_FromString, file > Objects/stringobject.c, line 107. > Abort trap > > with a pop that says: "The application Python quit unexpectedly. The > problem may have been caused by the _psycopg.so plug-in". > -- > I don't understand the error message above. The date did get passed > correctly and am now not even using it, I use the hard coded date. So > what is going on? Do other querys work within your application? Looks like the components of the db layer are not correctly found. This can happen if the environment of the web server differs from your personal user when you are testing your scripts. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From philip at semanchuk.com Sat Jan 17 13:50:21 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 17 Jan 2009 13:50:21 -0500 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <3AE6CE69-7207-42BE-9F3E-61C09724B80C@semanchuk.com> On Jan 17, 2009, at 12:48 PM, Neha Gupta wrote: > Hey, > > I only have little experience with web.py and psycopg2 and am running > into a weird problem, I'd appreciate any help I can get with debugging > it. Hi Neha, There's a lot of pieces involved here and your subject implies you've isolated the problem to psycopg2, but I'm not convinced. > I know it is not the date picker that > causing trouble. So don't confuse us by mentioning it. =) > class departures: > def buildDepartureTableHtml(self, date): > web.debug('date', date) > try: > web.debug("About to issue query") > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > web.debug('query executed!') > rows = cur.fetchall() > web.debug('rows fetched!') > web.debug(rows) > except Exception, e: > print repr(e) > database_conn.rollback() > return "
Invalid Date
" > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. That's a good first step. Simplify even further. What happens if you simplify the query? FOr instance: SELECT 1, 2 as crs_dep_hour, origin from flightdata where date = '01-05-2007' If a simple query like that doesn't work, I suspect you have something fundamental wrong with your setup. HTH Philip From google at mrabarnett.plus.com Sat Jan 17 14:10:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 19:10:05 +0000 Subject: python3.0 base64 error In-Reply-To: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> References: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> Message-ID: <49722D0D.6020307@mrabarnett.plus.com> yang michael wrote: > I use base64 module on python3.0 > like: > > import base64 > b="hello world" Try: b = b"hello world" instead. > a=base64.b64encode(b) > print(a) > > but when i run it,it catch a error: > Traceback (most recent call last): > File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in > a=base64.b64encode(b) > File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode > raise TypeError("expected bytes, not %s" % s.__class__.__name__) > TypeError: expected bytes, not str > > > > and also the document's example: > >>>> import base64 >>>> encoded = base64.b64encode('data to be encoded') > >>>> encoded > 'ZGF0YSB0byBiZSBlbmNvZGVk' >>>> data = base64.b64decode(encoded) > >>>> data > 'data to be encoded' > > can not run too. > > what happen? > As the traceback says, it needs bytes, not string. Perhaps the example would've been clearer as: >>> import base64 >>> encoded = base64.b64encode(b'data to be encoded') From alan.isaac at gmail.com Sat Jan 17 14:12:45 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 19:12:45 GMT Subject: Python 3: exec arg 1 Message-ID: In Python 3, you can no longer ``exec(open(filename))``. I guess the reason is that in 3.0 ``open`` returns a stream, instead of open file, and exec wants "a string, bytes, or code object" and not a "TextIOWrapper". So it returns an error. Is it intentional that ``exec`` cannot handle a TextIOWrapper? Bottom line: has ``execfile(filename)`` really become ``exec(open(filename).read())``? Is this a good thing? Thanks, Alan Isaac From scott.p.macdonald at gmail.com Sat Jan 17 14:13:00 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sat, 17 Jan 2009 12:13:00 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista Message-ID: I googled a bit this morning search for an answer to this problem but have come up empty so far. Can anyone help? Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 Traceback (most recent call last): File "", line 1, in File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in import httplib File "C:\dev\opt\Python25\Lib\httplib.py", line 71, in import socket File "C:\dev\opt\Python25\Lib\socket.py", line 70, in _realssl = ssl NameError: name 'ssl' is not defined >>> NameError: name 'ssl' is not defined By way of comparison here is Python 2.5.2 on the same machine: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> Whats going on?? Thanks, Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From gert.cuykens at gmail.com Sat Jan 17 14:34:39 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 11:34:39 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) Message-ID: I expected that py3 did not converted the b'...' indication too ? b'afc76815e3fc429fa9d7' From digitig at gmail.com Sat Jan 17 14:36:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 17 Jan 2009 19:36:18 +0000 Subject: English-like Python In-Reply-To: <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <5f82beba-7e78-4018-84d5-21a925050a65@l33g2000pri.googlegroups.com> Message-ID: 2009/1/16 has : > http://www.alice.org/ Ooh, "JavaLikeSyntax.py" indeed! Why not "PythonLikeSyntax", since that's apparently what they used! -- Tim Rowe From roy at panix.com Sat Jan 17 14:38:24 2009 From: roy at panix.com (Roy Smith) Date: Sat, 17 Jan 2009 14:38:24 -0500 Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: In article , Steve Holden wrote: > Roy Smith wrote: > > In article > > <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, > > v4vijayakumar wrote: > > > >> I saw some code where someone is really managed to import braces from > >> __future__. ;) > >> > >> def test(): > >> #{ > >> print "hello" > >> #} > > > > That usage is obsolete. Current best practice is: > > > > def test(): > > """{""" > > print "hello" > > """}""" > > Which would be OK if it were syntactically valid ... > > regards > Steve Doh. I'm sorry: def test(): """{""" print "hello" """}""" This one I tested :-) From martin.hellwig at dcuktec.org Sat Jan 17 14:40:45 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 17 Jan 2009 19:40:45 +0000 Subject: braces fixed '#{' and '#}' In-Reply-To: References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: <4972343d$0$198$e4fe514c@news.xs4all.nl> Roy Smith wrote: > In article , > Steve Holden wrote: > >> Roy Smith wrote: >>> In article >>> <6264e675-ddd4-446a-822a-cc82e8f87446 at w1g2000prk.googlegroups.com>, >>> v4vijayakumar wrote: >>> >>>> I saw some code where someone is really managed to import braces from >>>> __future__. ;) >>>> >>>> def test(): >>>> #{ >>>> print "hello" >>>> #} >>> That usage is obsolete. Current best practice is: >>> >>> def test(): >>> """{""" >>> print "hello" >>> """}""" >> Which would be OK if it were syntactically valid ... >> >> regards >> Steve > > Doh. I'm sorry: > > def test(): > """{""" > print "hello" > """}""" > > This one I tested :-) print is deprecated use print() :-) -- mph From bdesth.quelquechose at free.quelquepart.fr Sat Jan 17 14:49:38 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 17 Jan 2009 20:49:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: <497243fa$0$20693$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 15, 12:21 pm, Bruno Desthuilliers > wrote: > >> Once again, the important point is that there's a *clear* distinction >> between interface and implementation, and that you *shouldn't* mess with >> implementation. > > If you "*shouldn't* mess with the implementation", then what is wrong > with enforcing that "shouldn't" in the language itself? Because sometimes you have a legitimate reason to do so and are ok to deal with the possible issues. > Why leave to > coding standards and company policy what can be encoded right into the > language? Because human are smarter than computers. > Why leave to humans (who are known to err) what can be > automated relatively easily? Isn't that what computers are for? Error is human. For a real catastrophic failure, it requires a computer. >> But what, some people think programmers are stupid, and >> so they hire stupid programmers, so they need b&d languages to protect >> stupid programmers from themselves - which just doesn't work, since >> *nothing* is idiot-proof. Heck, how many Java "OO" programs with dumb >> getter/setter pairs for _each and any_ attribute ? > > Hey, I share your distaste for Java and C++. I'm not talking about the languages by themselves, but about the gap between what they pretend to promote and how they are usually used. > All those "setters" and > "getters" are a kludge. I think Python "properties" are a major step > forward here. Just for fun, I checked to see if Scala has properties. > Guess what? Not only does it have them, but they are generated > automatically for all member data. That's even better than Python > properties! Oh yes ? "Better", really ? So it's better to have a language that automagically breaks encapsulation (requiring an additionnal level of indirection) than a language that do the right thing by default ? I'm afraid I missed the point ??? >>> As I said before, enforced encapsulation may not be appropriate for >>> every application, but it is definitely appropriate for some. >> No. It is appropriate for dummy managers hiring dummy programmers. The >> project's size and domain have nothing to do with it. > > Let me try to be very clear here. We are dealing with two separate but > related issues. The first is whether data hiding should be added to > Python. No need to add it, it's already there : every name that starts with an underscore is hidden !-) > The second is whether data hiding provides any net benefit in > *any* language. If it doesn't provide any benefit in Python, then it doesn't provide any benefit in any language. > As for whether data hiding should be added to Python, I am not arguing > one way or the other. I am merely saying that it is worth considering. It is not. > Whether it can be added without screwing up the language, I don't > know. If not, then so be it. That just limits the range of domains > where Python is suitable. That's just plain stupid. > As for whether data hiding provides a net benefit in any language, it > certainly does for large programs and for safety-critical programs. > For large, safety-critical systems, it's a no-brainer. Only if you fail to use your brain. Now, except for regurgitating the official OMG prose, do you have *anything* to back these claims ? Python is older than Java, and there are quite enough man/years of experience and Python success stories to prove that it *just work*. > I think data > hiding can also provide net benefits for medium-size and even smaller > programs, but lets just consider large programs, so I can shoot down > your argument that data hiding provides no benefit. C'mon, make my day... > I like to use the example of the flight software for a large > commercial transport aircraft, but many other examples could be given. > How about medical systems that control radiation therapy or > chemotherapy? How about financial systems that could take away your > retirement account in 1.5 milliseconds. Or how about the control > software for the strategic nuclear arsenals of the US or Russia? When > you consider the sea, air, and land-based components, I'm sure that's > one hell of a lot of code! And ? Such systems have been written (and quite a lot are still running) with languages way more permissive than Python. You know, languages like C or assembly. Until you understand that *no technology is idiot-proof*, you'll get nowhere in "software engineering". > So let's take the airplane example. Boeing and its contractors > probably has hundreds of programmers working on millions of lines of > code. And ? > If they believed you, they would abandon enforced data hiding, > and programmers would have much more discretion to screw around with > code that they don't work on directly. Yes. And ? > An FMS programmer could perhaps > decide to change the parameters of the engine controls, for example. Why on earth would he do something so stupid ? > To prevent that sort of thing from happening, the management could > decree that henceforth all "private" variable names will start with an > underscore. Problem solved, eh? Certainly not. The only way to solve such a problem is to fire this cretin. > Wait a minute. You yourself have > stated several times that those stupid library developers Where did I say that library developpers where "stupid" ? Chapter and verse, please. > can never > predict what the client will actually need. Now this is a well known fact - applied to "generic" libraries. Nothing to do with project-specific libraries. Straw man. > So some FMS guy named > Bruno Fine, personal attack now. Man, beware, this is not going to help you make your point. (snip remaining braindead fantasy). > Now, let's talk about a data access violations in the nuclear missile > launch software. Oh, yes, I'm sure the leading underscore convention > is more than sufficient! Wake up, dude, and quit spouting bullsh*t! Please educate yourself and learn about why Ariane 5 crashed on it's first flight, due to an error in a module written in ADA (which is such a psychorigid language that C++ and Java are even looser than Javascript in comparison). Perhaps will it light a bulb for you. >>> Not >>> every door needs a lock, but certainly some do. >> You only need locks when you don't trust your neighbours. > > Yeah, if you live in Nome, Alaska. Brillant. You obviously failed to understand the differences between "software engineering" and real life. When it comes to computers, the only doors I care closing are those which would let someone crack my computer. But FWIW, I never close my car. And, in case you don't know, it's perfectly possible to access "private" members in Java (and, if you do have access to the source code, in C++ too). > Also, have you ever heard the expression "locks keep honest people > honest"? Yes. You don't wan't to know what I'm thinking of it. > I spent *way* too much time on that post. At least something sensible. > I really need to quit > spending my time refuting the baloney that passes for wisdom here. I don't have any pretention to "wisdom" as far as I'm concerned, unless you defined wisdom as thinking that experimental results have more weight than theory. From bdesth.quelquechose at free.quelquepart.fr Sat Jan 17 15:00:19 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 17 Jan 2009 21:00:19 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> Message-ID: <4972467b$0$10274$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 16, 5:22 am, Steve Holden wrote: >> Russ P. wrote: >> >> [...] >> >>> I spent *way* too much time on that post. I really need to quit >>> spending my time refuting the baloney that passes for wisdom here. >> He who cannot ignore baloney is doomed to refute it. >> > > > Yeah, and I should really learn to leave off those little zingers. If > Mr. D weren't obviously an intelligent person and a Python expert, I > wouldn't care what he writes. I just think that he, along with a few > others here, love Python so much that they refuse to recognize its > limitations. It's an easy trap to fall into. Python surely has lot of limitations (and quirks and whatever). The point is that not having language-enforced access restrictions is *not* a limitation - because it's *not* the right way to solve the problems you are (very rightfully) concerned with. No technology can solve *human* problems. Anyone trying to make you believe otherwise is selling you snake oil. Once again, there's quite a lot to learn from the story of Ariane 5. From martin at v.loewis.de Sat Jan 17 15:08:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 17 Jan 2009 21:08:39 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: References: Message-ID: <49723AC7.6000203@v.loewis.de> > I expected that py3 did not converted the b'...' indication too ? > > b'afc76815e3fc429fa9d7' You mean, just because you invoked the ascii() builtin, the b prefix should disappear? Re-read the documentation of the ascii() builtin - it probably does something completely different from what you expect it to do. Regards, Martin From the.one.duckenator at googlemail.com Sat Jan 17 15:16:59 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 12:16:59 -0800 (PST) Subject: Socket issues Message-ID: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Hi all I've been trying to set up sockets on my server (running Apache/2.2.3) using python and I'm confused as to why it doesn't work. I set up a simple listening script which runs without error, and works if a connecting script is run on the same server. However, if I try to connect using Telnet it doesn't work. I am definetly using the public IP address (79.99.43.58:2727). The weird thing is that I have the same problem if I make the socket in PHP, and even more weird is that sockets used to work, but now do not (and as far as I can tell, I have changed nothing). Any ideas? Thanks, Sunil From address.good.until.2009.may.11 at justmail.de Sat Jan 17 15:30:49 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Sat, 17 Jan 2009 21:30:49 +0100 Subject: reading file to list In-Reply-To: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee schrieb: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby > > Here's a interesting toy problem posted by Drew Krause to > comp.lang.lisp: > > ------------------------ > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > OK, I want to create a nested list in Lisp (always of only integers) > from a text file, such that each line in the text file would be > represented as a sublist in the 'imported' list. > > example of a file's content > > 3 10 2 > 4 1 > 11 18 > > example of programing behavior > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > w_a_x_... at yahoo.com gave a ruby solution: > > IO.readlines("blob.txt").map{|line| line.split } > > augumented by Jilliam James for result to be numbers: > > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > > Very beautiful. > > ------------------- > > That's really the beauty of Ruby. > > This problem and ruby code illustrates 2 fundamental problems of lisp, > namely, the cons problem, and the nested syntax pain. Both of which > are practically unfixable. *Of course* Xah is wrong, as always. Who would expect anything else? In the Lisp style Clojure for example one does exactly the same as Jillian James (JJ) did in Ruby: (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq (reader "blob.txt"))) This is slightly longer, simply because the functions have longer names. Integer/parseInt vs to_i Also the function split takes a regexp, so I have to add the "\\s" here. I don?t know though if Jillians version also handles any kind of whitespac per line. And the last thing is, that the function reader returns a BufferedReader. So in general this is more valuable in real programs as opposed to one- line scripts. If we combine line-seq and reader into readline and apply the two other changes we would say: (map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt")) vs IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} So, obviously Xah is far away from any reality. It took him hours of his life to write up all his ideas about Lisp. Sad to see that all that time was wasted. All of it was wrong. Poor Xah :( And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store data for his programs in the format 3 10 2 4 1 11 18 but instead as (3 10 2) (4 1) (11 18) And then read it back into the program with: (map read-string (line-seq (reader "blob.txt"))) Andr? -- From nad at acm.org Sat Jan 17 15:59:06 2009 From: nad at acm.org (Ned Deily) Date: Sat, 17 Jan 2009 12:59:06 -0800 Subject: tuple methods: documentation missing References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: In article <8Rncl.212$Aw2.127 at nwrddc02.gnilink.net>, Alan G Isaac wrote: > Is this another lacuna or am I overlooking it? > I cannot find the 3.0 documentation of string > formatting with the ``%`` operator. -- Ned Deily, nad at acm.org From gary at byoteki.com Sat Jan 17 16:02:37 2009 From: gary at byoteki.com (Gary M. Josack) Date: Sat, 17 Jan 2009 16:02:37 -0500 Subject: Socket issues In-Reply-To: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Message-ID: <4972476D.1090306@byoteki.com> twistedduck9 wrote: > Hi all > > I've been trying to set up sockets on my server (running Apache/2.2.3) > using python and I'm confused as to why it doesn't work. > > I set up a simple listening script which runs without error, and works > if a connecting script is run on the same server. However, if I try to > connect using Telnet it doesn't work. I am definetly using the public > IP address (79.99.43.58:2727). > > The weird thing is that I have the same problem if I make the socket > in PHP, and even more weird is that sockets used to work, but now do > not (and as far as I can tell, I have changed nothing). > > Any ideas? > > Thanks, > Sunil > -- > http://mail.python.org/mailman/listinfo/python-list > With no code it's hard to tell if there's an issue there, but if the same code worked before and still works locally I'm going to guess firewall. From the.one.duckenator at googlemail.com Sat Jan 17 16:11:33 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 13:11:33 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> Message-ID: <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> My hosting provider (Streamline) have said that there is no firewall (it's a dedicated server). Either way the code I'm using is: Listening socket: import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.bind (('79.99.43.58', 2727)) mysock.listen(1) while True: channel, details = mysock.accept() print channel.recv(100) channel.send ('Got a message.') channel.close() Sending socket: import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect(('79.99.43.58', 2727)) mysock.send('test'); mysock.close() Thanks for the response! From tjreedy at udel.edu Sat Jan 17 16:20:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:20:49 -0500 Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: Alan G Isaac wrote: > In Python 3, you can no longer ``exec(open(filename))``. > > I guess the reason is that in 3.0 ``open`` returns a stream, > instead of open file, and exec wants > "a string, bytes, or code object" and not a "TextIOWrapper". > So it returns an error. > > Is it intentional that ``exec`` cannot handle a TextIOWrapper? > > Bottom line: has ``execfile(filename)`` really become > ``exec(open(filename).read())``? Is this a good thing? Yes. Yes. From lipun4u at gmail.com Sat Jan 17 16:28:12 2009 From: lipun4u at gmail.com (asit) Date: Sat, 17 Jan 2009 13:28:12 -0800 (PST) Subject: process command line parameter Message-ID: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Recently I was coding a link extractor. It's a command line stuff and takes parameter as argument. I found that the in operator is not always helpful. eg. if "--all" in sys.argv: print "all links will be printed" its not helpful when some attribute value is sent in command line parameter. hence I want to process some data like find=".co.uk" How can i do this ??? From jeff at jmcneil.net Sat Jan 17 16:32:46 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sat, 17 Jan 2009 13:32:46 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> Message-ID: <0a593760-cd05-4eee-bd59-39316bde086a@m22g2000vbl.googlegroups.com> On Jan 17, 4:11?pm, twistedduck9 wrote: > My hosting provider (Streamline) have said that there is no firewall > (it's a dedicated server). Either way the code I'm using is: > > Listening socket: > import socket > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > mysock.bind (('79.99.43.58', 2727)) > mysock.listen(1) > while True: > ? ?channel, details = mysock.accept() > ? ?print channel.recv(100) > ? ?channel.send ('Got a message.') > ? ?channel.close() > > Sending socket: > import socket > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > mysock.connect(('79.99.43.58', 2727)) > mysock.send('test'); > mysock.close() > > Thanks for the response! Any chance you've got IP Tables running on it? I've spent hours debugging strange problems before only for them to turn out to be vendor default IP tables configurations (Thanks, Red Hat!). In fact, 'iptables -L -n' has turned into one of the first things I do whenever I have any sort of problem at all. Along the same line, could always be a SELinux policy as well. The second thing I usually do? 'setenforce 0.' Also, by "doesn't work", what do you mean? Does it just hang and never reply? Do you get a connection refused message? Jeff mcjeff.blogspot.com From gert.cuykens at gmail.com Sat Jan 17 16:34:14 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 13:34:14 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> Message-ID: <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> On Jan 17, 9:08?pm, "Martin v. L?wis" wrote: > > I expected that py3 did not converted the b'...' indication too ? > > > b'afc76815e3fc429fa9d7' > > You mean, just because you invoked the ascii() builtin, the b > prefix should disappear? Re-read the documentation of the > ascii() builtin - it probably does something completely different > from what you expect it to do. s = str(hexlify(urandom(8)))[2:18] From tjreedy at udel.edu Sat Jan 17 16:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:35:16 -0500 Subject: python3.0 base64 error In-Reply-To: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> References: <7fa4e5100901170948n1176d1efi3b7dc172ef8dff6d@mail.gmail.com> Message-ID: yang michael wrote: > I use base64 module on python3.0 > like: > > import base64 > b="hello world" > a=base64.b64encode(b) > print(a) > > but when i run it,it catch a error: > Traceback (most recent call last): > File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in > a=base64.b64encode(b) > File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode > raise TypeError("expected bytes, not %s" % s.__class__.__name__) > TypeError: expected bytes, not str > > > > and also the document's example: > >>>> import base64 >>>> encoded = base64.b64encode('data to be encoded') > >>>> encoded > 'ZGF0YSB0byBiZSBlbmNvZGVk' >>>> data = base64.b64decode(encoded) > >>>> data > 'data to be encoded' > > can not run too. > > what happen? The example has not yet been updated for Py3. I reported this at http://bugs.python.org/issue4975 Thank you for testing and reporting the failure. tjr From cs at zip.com.au Sat Jan 17 16:40:07 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 18 Jan 2009 08:40:07 +1100 Subject: process command line parameter In-Reply-To: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Message-ID: <20090117214007.GA2021@cskk.homeip.net> On 17Jan2009 13:28, asit wrote: | Recently I was coding a link extractor. It's a command line stuff and | takes parameter as argument. | I found that the in operator is not always helpful. | eg. if "--all" in sys.argv: | print "all links will be printed" Indeed. While I can't speak for your particular app, usually command line parameters are context sensitive. Therefore one normally processes them in order (especially if you want to support the fairly normal "--" option which means "no more options after this", useful if you need to supply a filename called "--app"). If you dont want to use the getopt standard module and thus its conventionaly argument syntax, then one alternative is like this: | its not helpful when some attribute value is sent in command line | parameter. | hence I want to process some data like find=".co.uk" all_links=False find=None for arg in sys.argv[1:]: if arg == "--": break elif arg =="--all": all_links=True elif arg.startswith("find="): find=arg[5:] else: # unhandled argument: complain or drop out of loop Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From http Sat Jan 17 16:43:38 2009 From: http (Paul Rubin) Date: 17 Jan 2009 13:43:38 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> Message-ID: <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Once again, there's quite a lot to learn from > the story of Ariane 5. Do you know what actually happened with Ariane 5? The failure was because "smart" humans overrode the language enforced protection by casting a floating point number down to a 16-bit integer, which worked ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger numbers were involved. The actual code fragment is here, and you can see where the error is suppressed: http://www-aix.gsi.de/~giese/swr/ariane5.html This is one thing that Python gets right, automatically using bignums rather than allowing int overflow. In that sense, Python has more enforced protection than Ada. See also: http://en.wikipedia.org/wiki/Ariane_5_Flight_501 From tjreedy at udel.edu Sat Jan 17 16:49:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:49:38 -0500 Subject: Jerry Pournelle gives award to Python and Guido for 2008 In-Reply-To: References: Message-ID: Richard Hanson wrote: > [NB: Blatant Python advocacy (and OP self-promotion).] > > > Jerry Pournelle commends Python and Guido in "The Annual Orchid > and Onions Parade" portion of his Chaos Manor Reviews column: > >> > > A reader [full-disclosure: that reader was me] nominated Python > for an Orchid for Jerry's Orchid and Onions awards for 2008: > > ''' > I nominate the computer language Python for an Orchid for 2008. > This last year, Python broke through into worldwide popularity. > The volunteer team led by BDFL (benevolent dictator for life) > Guido van Rossum released "Python 3000" (Python 3.0) before > year's end as well as releasing the next production-line 2.x > version, Python 2.6. > > Python -- and Linux (the kernel) with its "BDFL" Linus Torvalds > -- show that benevolent dictatorships are great forms of > organization which can easily beat out other forms of cooperation > in software development unable to escape Pournelle's Iron Law, > whether proprietary *or* open-source software [...]. > ''' > > Jerry Pournelle followed up with: > > ''' > I completely agree with this. Python deserves a large Orchid. > It's useful, well structured, easy to learn, and powerful. I use > it to write quick filter functions among other things. I'm > pleased to hand Guido a big Orchid. [...] > ''' > > I add: Great job, Guido and all! Great nomination. In October he wrote "Languages to Begin With If you want to try learning what programming is like, I recommend you start with Python. (Python.org) It's free, it's fast, and there are a lot of example programs you can look through. The Wikipedia article on Python gives a good description of the language and its history, as well as an example of a Python program. Don't let the capability of the language fool you into thinking you need to learn a lot before you can do anything: you can write simple good programs in Python within a couple of hours of beginning. O'Reilly has several books on the language; I recommend Learning Python as a beginning, and those more serious about learning the language need the O'Reilly Python Cookbook ? at least if you are like me and more comfortable learning languages by studying examples. Peter Glaskowsky notes that "Python is a language that relies on dynamic typing and other kinds of looseness in order to increase programmer productivity," and may not be entirely suitable for learning good programming practices. I have to agree, but it is free, it does work, and I confess I use it when I have a job that needs doing fast. In my case I often craft filters and other specialized text processing, and Python is excellent for that. I've never attempted to write a large and complex Python program." From the.one.duckenator at googlemail.com Sat Jan 17 16:52:15 2009 From: the.one.duckenator at googlemail.com (twistedduck9) Date: Sat, 17 Jan 2009 13:52:15 -0800 (PST) Subject: Socket issues References: <66a5acd7-62da-4e76-adc7-94e08af676e9@r10g2000prf.googlegroups.com> <00d2b511-0f55-4ad2-808d-52505d21a837@g1g2000pra.googlegroups.com> <0a593760-cd05-4eee-bd59-39316bde086a@m22g2000vbl.googlegroups.com> Message-ID: On 17 Jan, 21:32, Jeff McNeil wrote: > On Jan 17, 4:11?pm, twistedduck9 > wrote: > > > > > My hosting provider (Streamline) have said that there is no firewall > > (it's a dedicated server). Either way the code I'm using is: > > > Listening socket: > > import socket > > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > mysock.bind (('79.99.43.58', 2727)) > > mysock.listen(1) > > while True: > > ? ?channel, details = mysock.accept() > > ? ?print channel.recv(100) > > ? ?channel.send ('Got a message.') > > ? ?channel.close() > > > Sending socket: > > import socket > > mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > mysock.connect(('79.99.43.58', 2727)) > > mysock.send('test'); > > mysock.close() > > > Thanks for the response! > > Any chance you've got IP Tables running on it? I've spent hours > debugging strange problems before only for them to turn out to be > vendor default IP tables configurations (Thanks, Red Hat!). In fact, > 'iptables -L -n' has turned into one of the first things I do whenever > I have any sort of problem at all. ?Along the same line, could always > be a SELinux policy as well. ?The second thing I usually do? > 'setenforce 0.' > > Also, by "doesn't work", what do you mean? ?Does it just hang and > never reply? Do you get a connection refused message? > > Jeff > mcjeff.blogspot.com I seriously love you now. I still don't understand why it worked before... Also, does this IP tables thing mean that there WAS a firewall blocking the connection? If so, I think I'll have a go at my hosting provider... iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 2727 -j ACCEPT Thank you for your response, you've saved many hours of pulling my hair out. Sunil (I think I may have replied in the wrong place, I haven't used groups before) From tjreedy at udel.edu Sat Jan 17 16:56:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 16:56:04 -0500 Subject: tp_base, ob_type, and tp_bases In-Reply-To: <4971fe4d$0$30907$9b622d9e@news.freenet.de> References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> So, the documentation states that ob_type is a pointer to the type's >> Next, we have tp_base. That's defined as "an optional pointer to a >> base type from which type properties are inherited." The value of >> tp_base is then added to the tp_bases tuple. This is confusing me. On >> the surface, it sound as though they're one in the same? > > (I don't understand the English "one in the same" - interpreting it > as "as though they should be the same") Martin, you are not alone! I do not really understand that either. From alan.isaac at gmail.com Sat Jan 17 17:03:06 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 17 Jan 2009 22:03:06 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: > Alan G Isaac wrote: >> Is it intentional that ``exec`` cannot handle a TextIOWrapper? >> Bottom line: has ``execfile(filename)`` really become >> ``exec(open(filename).read())``? Is this a good thing? On 1/17/2009 4:20 PM Terry Reedy apparently wrote: > Yes. Yes. OK. Why? Alan Isaac From damonwischik at gmail.com Sat Jan 17 17:08:32 2009 From: damonwischik at gmail.com (Damon) Date: Sat, 17 Jan 2009 14:08:32 -0800 (PST) Subject: Windows Tablet RealTimeStylus in Python Message-ID: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> I have a Windows Tablet machine, running XP Tablet Edition, and I want to access the stylus data from Python. If anyone has done this themselves, I'd be very grateful for a description of what worked. Otherwise, I'd be grateful for advice. I'm in way over my head, so what I describe below is probably full of errors. I managed to access the stylus data successfully from C#, using a .net object called RealTimeStylus, contained in Microsoft.Ink.dll, which was located in c:\program files\common files\microsoft shared\ink. The documentation says that this .net object uses an underlying COM object, so I hoped to be able to access the COM object from within Python. First, I used a .net disassembler to inspect Microsoft.Ink.dll, and I discovered that it uses this command to create the COM object: Guid clsid = new Guid("{DECBDC16-E824-436e-872D-14E8C7BF7D8B}"); Guid iid = new Guid("{C6C77F97-545E-4873-85F2-E0FEE550B2E9}"); string licenseKey = "{CAAD7274-4004-44e0-8A17-D6F1919C443A}"; ComObjectCreator.CreateInstanceLicense(clsid, iid, licenseKey); I looked up this clsid in my registry, and discovered that it refers to C:\Program Files\Common Files\Microsoft Shared\INK\inkobj.dll (This file also exists on my standard XP machine, which also ran my C# program happily.) Now, I want to somehow access this COM object from within Python. I tried MakePy, but I didn't know what type library to specify. I found something called "Microsoft Tablet PC Type Library, version 1.0 (1.0)", and it generated a .py file from type library 'inkobj.dll', but this file doesn't say anything about a RealTimeStylus. I tried looking for a Python command to CreateInstance, but I couldn't find one where I could specify the license string. Without the license string I ended up with the error message "Class is not licensed for use". I have no idea what to do next. Damon. From tjreedy at udel.edu Sat Jan 17 17:10:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 17:10:53 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <4971ea0b$0$7055$9b622d9e@news.freenet.de> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >>> Does he intend to maintain two separate codebases, one 2.x and the >>> other 3.x? >> I think I have no other choice. >> Why? Is theoretically possible to maintain an unique code base for >> both 2.x and 3.x? > > That is certainly possible! One might have to make tradeoffs wrt. > readability sometimes, but I found that this approach works quite > well for Django. I think Mark Hammond is also working on maintaining > a single code base for both 2.x and 3.x, for PythonWin. Where 'single codebase' means that the code runs as is in 2.x and as autoconverted by 2to3 (or possibly a custom comverter) in 3.x. One barrier to doing this is when the 2.x code has a mix of string literals with some being character strings that should not have 'b' prepended and some being true byte strings that should have 'b' prepended. (Many programs do not have such a mix.) One approach to dealing with string constants I have not yet seen discussed here is to put them all in separate file(s) to be imported. Group the text and bytes separately. Them marking the bytes with a 'b', either by hand or program would be easy. tjr From nad at acm.org Sat Jan 17 17:14:38 2009 From: nad at acm.org (Ned Deily) Date: Sat, 17 Jan 2009 14:14:38 -0800 Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> Message-ID: In article , Terry Reedy wrote: > Martin v. L?wis wrote: > > (I don't understand the English "one in the same" - interpreting it > > as "as though they should be the same") > Martin, you are not alone! I do not really understand that either. It's a non-standard reshaping of the idiom "one and the same", an example of what linguists call an "eggcorn": Note the reference to Python! -- Ned Deily, nad at acm.org From tjreedy at udel.edu Sat Jan 17 17:14:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 17:14:38 -0500 Subject: Incorrect title case? In-Reply-To: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: John Machin wrote: > On Jan 17, 9:07 am, MRAB wrote: >> Python 2.6.1 >> >> I've just found that the following 4 Unicode characters/codepoints don't >> behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). >> >> For example, u"\u01C5".istitle() returns True and >> unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() >> returns u'\u01C4', which is the uppercase equivalent. Are these mistakes >> in the Unicode database? > > Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, > function _PyUnicode_ToTitlecase. > > See http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup > > The code that says: > if (ctype->title) > delta = ctype->title; > else > delta = ctype->upper; > should IMHO merely be: > delta = ctype->title; > > A value of zero for ctype->title should be interpreted simply as the > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py > which treats upper, lower and title identically when preparing the > tables used by those 3 functions. > > AFAICT making that change will fix the problem for those four > characters and not ruin any others. > > The error that you noticed occurs as far back as I've looked (2.1) and > also occurs in 3.0. Please post a report to the tracker at bugs.python.org. From google at mrabarnett.plus.com Sat Jan 17 17:42:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jan 2009 22:42:00 +0000 Subject: Incorrect title case? In-Reply-To: References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: <49725EB8.2020001@mrabarnett.plus.com> Terry Reedy wrote: > John Machin wrote: >> On Jan 17, 9:07 am, MRAB wrote: >>> Python 2.6.1 >>> >>> I've just found that the following 4 Unicode characters/codepoints don't >>> behave as I'd expect: ? (U+01C5), ? (U+01C8), ? (U+01CB), ? (U+01F2). >>> >>> For example, u"\u01C5".istitle() returns True and >>> unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title() >>> returns u'\u01C4', which is the uppercase equivalent. Are these mistakes >>> in the Unicode database? >> >> Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c, >> function _PyUnicode_ToTitlecase. >> >> See >> http://svn.python.org/view/python/trunk/Objects/unicodectype.c?rev=66362&view=markup >> >> >> The code that says: >> if (ctype->title) >> delta = ctype->title; >> else >> delta = ctype->upper; >> should IMHO merely be: >> delta = ctype->title; >> >> A value of zero for ctype->title should be interpreted simply as the >> offset to add to the ordinal, as it is in the sibling _PyUnicode_To >> (Upper|Lower)case functions. See also Tools/unicode/makeunicodedata.py >> which treats upper, lower and title identically when preparing the >> tables used by those 3 functions. >> >> AFAICT making that change will fix the problem for those four >> characters and not ruin any others. >> >> The error that you noticed occurs as far back as I've looked (2.1) and >> also occurs in 3.0. > > Please post a report to the tracker at bugs.python.org. > Already done: http://bugs.python.org/issue4971 From martin at v.loewis.de Sat Jan 17 18:05:10 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 18 Jan 2009 00:05:10 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> Message-ID: <49726426.8080602@v.loewis.de> gert wrote: > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: >>> I expected that py3 did not converted the b'...' indication too ? >>> b'afc76815e3fc429fa9d7' >> You mean, just because you invoked the ascii() builtin, the b >> prefix should disappear? Re-read the documentation of the >> ascii() builtin - it probably does something completely different >> from what you expect it to do. > > s = str(hexlify(urandom(8)))[2:18] And your question is? From gert.cuykens at gmail.com Sat Jan 17 18:11:48 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 15:11:48 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: On Jan 18, 12:05?am, "Martin v. L?wis" wrote: > gert wrote: > > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: > >>> I expected that py3 did not converted the b'...' indication too ? > >>> b'afc76815e3fc429fa9d7' > >> You mean, just because you invoked the ascii() builtin, the b > >> prefix should disappear? Re-read the documentation of the > >> ascii() builtin - it probably does something completely different > >> from what you expect it to do. > > > s = str(hexlify(urandom(8)))[2:18] > > And your question is? No question just solution to get rit of b'' :) From pdorange at pas-de-pub-merci.mac.com Sat Jan 17 18:11:52 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sun, 18 Jan 2009 00:11:52 +0100 Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: <1itppny.1c7vt6u1lc3qe1N%pdorange@pas-de-pub-merci.mac.com> "Martin v. L?wis" wrote: > > On Jan 17, 9:08 pm, "Martin v. L?wis" wrote: > >>> I expected that py3 did not converted the b'...' indication too ? > >>> b'afc76815e3fc429fa9d7' > >> You mean, just because you invoked the ascii() builtin, the b > >> prefix should disappear? Re-read the documentation of the > >> ascii() builtin - it probably does something completely different > >> from what you expect it to do. > > > > s = str(hexlify(urandom(8)))[2:18] > > And your question is? The answer is probably 23. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From martin at v.loewis.de Sat Jan 17 18:15:00 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 18 Jan 2009 00:15:00 +0100 Subject: Incorrect title case? In-Reply-To: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> Message-ID: <49726674.1030203@v.loewis.de> > A value of zero for ctype->title should be interpreted simply as the > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > (Upper|Lower)case functions. Interestingly enough, according to the spec of UnicodeData.txt, these should *not* be siblings. Refer to http://www.unicode.org/Public/UNIDATA/UCD.html For lower and upper case, it says Note: The simple uppercase is omitted in the data file if the uppercase is the same as the code point itself. whereas for titlecase, it says Note: The simple titlecase may be omitted in the data file if the titlecase is the same as the uppercase. So unicodectype is right to fall back to uppercase if no titlecase mapping is given. However, this looks like a bug in UCD.html: they probably should have the same note for titlecase as they have for lower and uppercase (at least, that's how UnicodeData seems to be generated). Regards, Martin From martin at v.loewis.de Sat Jan 17 18:20:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 18 Jan 2009 00:20:15 +0100 Subject: s=ascii(hexlify(urandom(10))) In-Reply-To: References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> Message-ID: <497267AF.2060001@v.loewis.de> >>> s = str(hexlify(urandom(8)))[2:18] >> And your question is? > > No question just solution to get rit of b'' :) Ah. hexlify(urandom(8)).decode('ascii') Regards, Martin From gert.cuykens at gmail.com Sat Jan 17 18:37:58 2009 From: gert.cuykens at gmail.com (gert) Date: Sat, 17 Jan 2009 15:37:58 -0800 (PST) Subject: s=ascii(hexlify(urandom(10))) References: <49723AC7.6000203@v.loewis.de> <935427d7-b69f-4499-b6d1-750e272daf33@y1g2000pra.googlegroups.com> <49726426.8080602@v.loewis.de> <497267AF.2060001@v.loewis.de> Message-ID: <3f527f62-9f81-490c-a481-56c214b785e3@o40g2000prn.googlegroups.com> On Jan 18, 12:20?am, "Martin v. L?wis" wrote: > >>> s = str(hexlify(urandom(8)))[2:18] > >> And your question is? > > > No question just solution to get rit of b'' :) > > Ah. hexlify(urandom(8)).decode('ascii') Ok that one looks better then mine :) From Russ.Paielli at gmail.com Sat Jan 17 18:45:33 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 15:45:33 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: No one ever claimed that a programming language, no matter how rigorous, can eliminate all bugs. All a language can do is to reduce their rate of occurrence. The Ariane fiasco was not a failure of Ada per se but rather a failure of people using Ada. They attempted to re-use software written for one rocket for another without proper testing. No language can prevent that sort of error. We can argue forever about the usefulness of language-enforced restriction of access to private data and methods. I have no doubt whatsoever that it is very useful at least for the extreme cases of very large, safety-critical systems. If you don't think access to private data needs to be restricted for control of strategic nuclear arsenals, for example, I think you're crazy, but that's just my opinion. The only reasonable question in my mind is where the line should be drawn between systems that should have enforced restrictions and those that can rely on coding standards and voluntary cooperation among programmers. A while back, I read something about the final integration of the flight software on the Boeing 777, which was written mainly in Ada. The claim was made that this integration took only three days, whereas normally it would be expected to take more like three months with a less rigorous language such as C++. The reason for the simplified integration is that Ada enforces interfaces and prevents access to private data and methods. Apparently such enforcement can improve the efficiency of software production -- and that's not just in "theory." From catphive at catphive.net Sat Jan 17 18:55:32 2009 From: catphive at catphive.net (Brendan Miller) Date: Sat, 17 Jan 2009 15:55:32 -0800 Subject: what's the point of rpython? In-Reply-To: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: >> The goals of the pypy project seems to be to create a fast python >> implementation. I may be wrong about this, as the goals seem a little >> amorphous if you look at their home page. > > The home page itself is ambiguous, and does oversell the performance > aspect. The *actual* goal as outlined by their official docs is to > implement Python in Python, at every level. Ok fair enough. In some ways I see that as more of a purely intellectual exercise than the practical endeavor that I assumed the project was originally. However, one of the links I was sent had one of the devs talking about using the translation process to make C/Java/LLVM implementations out of the same interpreter code. I'll say that makes a lot of sense. Another question I was wondering about is whether they plan on maintaining good C bindings? Will existing bindings for third party libraries be able to work? Also, are they going to do away with the GIL? The python devs seem to consider the GIL a non-issue, though they may change their mind in 3 years when we all have 32 core desktops, until then getting rid of the GIL would make pypy pretty attractive in some quarters. I know the scons project was running into GIL issues. Finally, I'm pretty unclear on what versions of python that pypy is targeting. From enleverlesX.XmcX at XmclaveauX.com Sat Jan 17 19:09:52 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Sun, 18 Jan 2009 01:09:52 +0100 Subject: Windows Tablet RealTimeStylus in Python In-Reply-To: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> References: <91f0ded0-85d9-4f55-94f6-e441fb811c35@w1g2000prk.googlegroups.com> Message-ID: <49727358$0$18363$ba4acef3@news.orange.fr> Hi! I use Internet-Explorer like (as?) GUI. Then, I insert Active-X components (from Tablet-PC, native or SDK). Another solution: create a .HTA, and use PythonScript (version "ActiveScripting" of Python, who become with pyWin32). @-salutations -- Michel Claveau From musicguy at alphaios.net Sat Jan 17 19:10:48 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sat, 17 Jan 2009 18:10:48 -0600 Subject: English-like Python In-Reply-To: <1232067775.15931.25.camel@localhost> References: <1232067775.15931.25.camel@localhost> Message-ID: <1232237448.20435.7.camel@speedyg> Wow, impressive responses. It sounds like the general consensus is that English would not be a good choice for programming even if there were an interpreter capable of turning human language into machine language. But that makes sense; even English professionals have trouble understanding each other sometimes. Until that problem is somehow overcome, there's not much hope of computers to overcome it. From xahlee at gmail.com Sat Jan 17 19:30:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 16:30:24 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee wrote: > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html On Jan 17, 12:30 pm, Andr? Thieme wrote: > In the Lisp style Clojure for example one does exactly the same as > Jillian James (JJ) did in Ruby: > (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq > (reader "blob.txt"))) Note that you have nested map. This is a problem of function chaning as i detailed. The other problem of cons, is commonly seen. Just about every week, we see some perhaps beginning lisper asking how to do various trivial list manipulation problem, which you don't see such question or frequency in any of modern high level lang forms. The frequently asked list manipulation question we see include how to append, prepend, or anything involving nested list such as partitioning, reordering sublists, getting leaves, interpretation of leaves, etc. This is caused by the cons. associated lisp problem compound the issue. Namely, the not exactly regular syntax, and the eval model of sometimes symbol sometimes uneval'd symbol, e.g. ?'(...)?, ?`(...,@ ...)? things. The clojure example you gave above, apparently inherited the irregular syntax problem. (you see the #, [], % things, which is breaks the lisp's sexp idea) Also, all modern lisp basically all get fucked up by inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often, they change the semantic a bit apparently as a mesaure towards solving the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely ugly, syntax soup) Advice: if you are creating a lispy lang, two things: ? stick to a _pure_ nested syntax, no exception whatsoever. (e.g. no more ` ' # % shits) If you want, add a transparent layer on top to support arbitrary algeraic notation. (e.g. look at Mathematica, CGOL) ? get rid of the cons. (you can still implement the so-called linked list, but no where it should be shown to the programer) Further readings: ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html Xah ? http://xahlee.org/ ? From sjmachin at lexicon.net Sat Jan 17 19:36:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 16:36:58 -0800 (PST) Subject: Incorrect title case? References: <7da2f5c0-9a93-4293-9bae-867ca0e7875f@z28g2000prd.googlegroups.com> <49726674.1030203@v.loewis.de> Message-ID: <6ae6f3e9-4885-437b-b880-9660b6777527@g3g2000pre.googlegroups.com> On Jan 18, 10:15?am, "Martin v. L?wis" wrote: > > A value of zero for ctype->title should be interpreted simply as the > > offset to add to the ordinal, as it is in the sibling _PyUnicode_To > > (Upper|Lower)case functions. > > Interestingly enough, according to the spec of UnicodeData.txt, > these should *not* be siblings. Refer to > > http://www.unicode.org/Public/UNIDATA/UCD.html > > For lower and upper case, it says > > Note: The simple uppercase is omitted in the data file if the uppercase > is the same as the code point itself. > > whereas for titlecase, it says > > Note: The simple titlecase may be omitted in the data file if the > titlecase is the same as the uppercase. However: (1) there seem to be no examples in the current data file where the titlecase is empty and the uppercase is not empty (2) the titlecase is *NOT* empty for the four characters in question -- they have [in effect] ch.title() -> ch as MRAB expected. See my response in the bug tracker for further info/comment. > > So unicodectype is right to fall back to uppercase if no titlecase > mapping is given. Correct -- but this is currently hypothetical; moreover the "fallback" is being done in the wrong place; it should be done in Tools/Unicode/ makeunicodedata.py when it reads the UnicodeData.txt file. The current implementation codes the ch.title() -> ch mapping as delta = 0 which is the same coding as used for "no titlecase specified in file" leaving the runtime unicodetype with a dilemema which it resolves wrongly -- it is *NOT* correct to pick uppercase when the titlecase is actually specified in the UnicodeData.txt file. Note that although it's not mentioned in the modification history for UnicodeData.txt, the titlecase entry for the 4 characters changed from "empty" to "self" in Unicode 4.0.0. HTH, John From jamatos at fc.up.pt Sat Jan 17 19:57:12 2009 From: jamatos at fc.up.pt (=?utf-8?q?Jos=C3=A9_Matos?=) Date: Sun, 18 Jan 2009 00:57:12 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: <200901180057.12818.jamatos@fc.up.pt> On Friday 16 January 2009 09:47:36 Eric Brunel wrote: > What do you mean by 'works'...? The usual meaning, I think. :-) Click "Yes" and the program prints True, click "No" and the programs prints "False". > You don't have the problem? It doesn't ? > change a thing for me... Notice that I am running the system python, that at least is different. -- Jos? Ab?lio From elhmbre at ozemail.com.au Sat Jan 17 20:11:45 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 11:11:45 +1000 Subject: A java hobbyist programmer learning python Message-ID: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Hello, below is my first fragment of working python code. As you can see it is very java like as that is all I know. Is this the right approach to be taking? Should I be taking a different approach? Thanks in advance. import sys class Calculator(): def __init__(self): self.operator = sys.argv[1] self.arg1 = sys.argv[2] self.arg2 = sys.argv[3] def getOperator(self): return sys.argv[1] def getArg1(self): return sys.argv[2] def getArg2(self): return sys.argv[3] def calculate(self): if self.getOperator() == '+' : return int(self.getArg1()) + int(self.getArg2()) elif self.getOperator() == '*' : return int(self.getArg1()) * int(self.getArg2()) elif self.getOperator() == '/' : return int(self.getArg1()) / int(self.getArg2()) elif self.getOperator() == '-' : return int(self.getArg1()) - int(self.getArg2()) else: return 'Wrong argument supplied' x = Calculator() y = x.calculate() print y From Russ.Paielli at gmail.com Sat Jan 17 20:17:39 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 17:17:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> On Jan 17, 11:49?am, Bruno Desthuilliers wrote: > Please educate yourself and learn about why Ariane 5 crashed on it's > first flight, due to an error in a module written in ADA (which is such > a psychorigid language that C++ and Java are even looser than Javascript > in comparison). Perhaps will it light a bulb for you. The claim here regarding the Ariane 5 failure is one of those urban myths that refuses to die. It has been refuted over and over (including on this thread already), but I would just like to add something in defense of Ada. Studies have found that Ada reduces both bugs and long-term development costs by something like a factor of two compared to C. For example, see http://www.adaic.com/whyada/ada-vs-c/cada_art.html Also, for a good discussion of the success of Ada in the 777, see http://www.adaic.org/atwork/boeing.html From address.good.until.2009.may.11 at justmail.de Sat Jan 17 20:25:00 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Sun, 18 Jan 2009 02:25:00 +0100 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Xah Lee schrieb: > Xah Lee wrote: >> ? A Ruby Illustration of Lisp Problems >> http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html > > > On Jan 17, 12:30 pm, Andr? Thieme 2009.may... at justmail.de> wrote: > > >> In the Lisp style Clojure for example one does exactly the same as >> Jillian James (JJ) did in Ruby: > >> (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq >> (reader "blob.txt"))) > > Note that you have nested map. This is a problem of function chaning > as i detailed. Yes, Jillian also has nested maps: IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > The other problem of cons, is commonly seen. Just about every week, we > see some perhaps beginning lisper asking how to do various trivial > list > manipulation problem, which you don't see such question or frequency > in any of modern high level lang forms. You see questions about trivial problems every week in all forums about programming languages. It has nothing to do with conses. Wrong road. > The frequently asked list manipulation question we see include how to > append, prepend, or anything involving nested list such as > partitioning, reordering sublists, getting leaves, interpretation of > leaves, etc. This is caused by the cons. Yes, same with all containers in all programming languages. > The clojure example you gave above, apparently inherited the irregular > syntax problem. (you see the #, [], % things, which is breaks the > lisp's sexp idea) My code used 8 ?mysterious symbols?: ( ) # [ ] . " % The Ruby version had these 7: ( ) | { } . " And of course, neither in Ruby nor Clojure they break any idea. > Also, all modern lisp basically all get fucked up by > inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often, > they change the semantic a bit apparently as a mesaure towards solving > the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely > ugly, syntax soup) Funny. What you write is an english text with words that most people can understand. You trick them into thinking that it actually makes sense what you say. It is so technical, that a random would believe it. But what you really say is about as meaningful as saying that it is impossible to write good programs in Python, because it adds whitespace to its syntax. > ? Fundamental Problems of Lisp > http://xahlee.org/UnixResource_dir/writ/lisp_problems.html You wasted lots of your time. Or was this maybe generated by a bot? Maybe http://pdos.csail.mit.edu/scigen/ or something like that? I also found this paper that you wrote: http://apps.pdos.lcs.mit.edu/scicache/184/scimakelatex.7076.Xah+Lee.html Another crap posting of you. But a random person might be impressed. Andr? -- From clp2 at rebertia.com Sat Jan 17 20:27:56 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jan 2009 17:27:56 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <50697b2c0901171727k6c95d909n6adece15772a930a@mail.gmail.com> On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > class Calculator(): > > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = sys.argv[2] > self.arg2 = sys.argv[3] > > def getOperator(self): > return sys.argv[1] > > def getArg1(self): > return sys.argv[2] > > def getArg2(self): > return sys.argv[3] Delete the 3 Java-ish accessor methods; good Python style just uses the attributes directly (i.e. self.operator instead of self.getOperator()). > > def calculate(self): > if self.getOperator() == '+' : > return int(self.getArg1()) + int(self.getArg2()) > elif self.getOperator() == '*' : > return int(self.getArg1()) * int(self.getArg2()) > elif self.getOperator() == '/' : > return int(self.getArg1()) / int(self.getArg2()) > elif self.getOperator() == '-' : > return int(self.getArg1()) - int(self.getArg2()) > else: > return 'Wrong argument supplied' Rather than have a long if-elif-else chain like this, you can use a dictionary with functions as values. For example: def add(x, y): return x + y def sub(x, y): return x - y OPER2FUNC = {'+' : add, '-' : sub} print OPER2FUNC['+'](3,4) #==> 7 You can use the same technique with the functions in the `operator` module to significantly shorten your calculate() method. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Russ.Paielli at gmail.com Sat Jan 17 20:35:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 17 Jan 2009 17:35:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Message-ID: <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> On Jan 17, 1:43?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > Once again, there's quite a lot to learn from > > the story of Ariane 5. > > Do you know what actually happened with Ariane 5? ?The failure was > because "smart" humans overrode the language enforced protection by > casting a floating point number down to a 16-bit integer, which worked > ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger So this turns out to be an example of a failure due, not to the *rigidity* of Ada, but to its *permissiveness* in allowing such a cast. Had such a cast not been allowed, the people who complain about the "rigidity" of Ada would have complained that much more. I don't know which variant of Ada was used here, but something called the "Ravenscar Profile" is a reduced subset of Ada that might have prevented this error (though I haven't verified this). Then there is Spark Ada, which supposed to be much safer than even Ada. > numbers were involved. ?The actual code fragment is here, and you can > see where the error is suppressed: > > ?http://www-aix.gsi.de/~giese/swr/ariane5.html > > This is one thing that Python gets right, automatically using bignums > rather than allowing int overflow. ?In that sense, Python has more > enforced protection than Ada. True, but Ada does not have the luxury of just using doubles and "bignums" everywhere, because it needs to work on cheap processors too. But perhaps it could somehow be configured to do so by the user if sufficiently powerful computers are being used. From sjmachin at lexicon.net Sat Jan 17 20:37:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 17:37:40 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> Message-ID: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> On Jan 18, 9:10?am, Terry Reedy wrote: > Martin v. L?wis wrote: > >>> Does he intend to maintain two separate codebases, one 2.x and the > >>> other 3.x? > >> I think I have no other choice. > >> Why? Is theoretically possible to maintain an unique code base for > >> both 2.x and 3.x? > > > That is certainly possible! One might have to make tradeoffs wrt. > > readability sometimes, but I found that this approach works quite > > well for Django. I think Mark Hammond is also working on maintaining > > a single code base for both 2.x and 3.x, for PythonWin. > > Where 'single codebase' means that the code runs as is in 2.x and as > autoconverted by 2to3 (or possibly a custom comverter) in 3.x. > > One barrier to doing this is when the 2.x code has a mix of string > literals with some being character strings that should not have 'b' > prepended and some being true byte strings that should have 'b' > prepended. ?(Many programs do not have such a mix.) > > One approach to dealing with string constants I have not yet seen > discussed here is to put them all in separate file(s) to be imported. > Group the text and bytes separately. ?Them marking the bytes with a 'b', > either by hand or program would be easy. (1) How would this work for somebody who wanted/needed to support 2.5 and earlier? (2) Assuming supporting only 2.6 and 3.x: Suppose you have this line: if binary_data[:4] == "PK\x03\x04": # signature of ZIP file Plan A: Change original to: if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" Add this to the bytes section of the separate file: ZIPFILE_SIG = "PK\x03\x04" [somewhat later] Change the above to: ZIPFILE_SIG = b"PK\x03\x04" [once per original file] Add near the top: from separatefile import * Plan B: Change original to: if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" Add this to the separate file: ZIPFILE_SIG = b"PK\x03\x04" [once per original file] Add near the top: from separatefile import * Plan C: Change original to: if binary_data[:4] == b"PK\3\4": # signature of ZIP file Unless I'm gravely mistaken, you seem to be suggesting Plan A or some variety thereof -- what advantages do you see in this over Plan C? From http Sat Jan 17 20:53:06 2009 From: http (Paul Rubin) Date: 17 Jan 2009 17:53:06 -0800 Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Chris Rebert writes: > > class Calculator(): ... > Delete the 3 Java-ish accessor methods; good Python style just uses > the attributes directly (i.e. self.operator instead of > self.getOperator()). I think I would get rid of the whole Calculator class unless there was a good reason to keep it (i.e. you are going to have several Calculators active in the program simultaneously). Just write straightforward imperative code without bothering with the OO stuff that is mandatory in Java. > Rather than have a long if-elif-else chain like this, you can use a > dictionary with functions as values. For example: > > def add(x, y): > return x + y These functions are already defined in the operator module, and you can also define them inline with the lambda operator. Here is my version of the program: import sys from operator import add, mul, sub, div op, x, y = sys.argv[1:4] opdict = {'+': add, '*': mul, '-': sub, '/': div} try: func = opdict[op] except KeyError: print 'wrong argument supplied' sys.exit() print func(int(x), int(y)) Note that like the original, it doesn't check for valid numeric args. From castironpi at gmail.com Sat Jan 17 20:54:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 17 Jan 2009 17:54:48 -0800 (PST) Subject: reverse dict lookup & Relation class References: <8dbd3d7c-162c-4c29-aaa2-821c7724d22d@p23g2000prp.googlegroups.com> <01806003$0$8693$c3e8da3@news.astraweb.com> <299c9ad8-ce93-4ce4-8fb2-971d73dabfaa@g3g2000pre.googlegroups.com> <0182018b$0$8693$c3e8da3@news.astraweb.com> Message-ID: <73c48fd8-1c3b-45f0-94e7-fa11678c7cba@e1g2000pra.googlegroups.com> On Jan 17, 10:45?am, Steven D'Aprano wrote: > On Sat, 17 Jan 2009 00:24:21 -0800, Aaron Brady wrote: > > Can you make it work for a 3-way lookup? > > What do you mean "3-way lookup"? > > I'm going to take a guess... > > A maps to B, B maps to C, and C maps to A. > > Is that what you mean? So long as you can get B and C from A, and C and A from B, and A and B from C, it classifies as a "3-way lookup", or at least how I was using the term. (In other words, yes.) Yours does that, but it takes two steps from B to A. For example: c2a[ b2c[ keyinB ] ] == keyinA This goes from B to C, then from C to A. From what you said, you would have no way to get from B directly to A. Is that correct? If so, it's a little awkward, and the direct way would be nice too. From clp2 at rebertia.com Sat Jan 17 21:01:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jan 2009 18:01:10 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c0901171801o5a85094awe34a926bcb4e5ae8@mail.gmail.com> On Sat, Jan 17, 2009 at 5:53 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Chris Rebert writes: >> Rather than have a long if-elif-else chain like this, you can use a >> dictionary with functions as values. For example: >> >> def add(x, y): >> return x + y > > These functions are already defined in the operator module, and you > can also define them inline with the lambda operator. Did you completely skip over the last sentence of my email? I specifically mentioned the `operator` module. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sat Jan 17 21:04:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 17 Jan 2009 18:04:47 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> On Jan 18, 12:11?pm, "elhombre" wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > class Calculator(): > > ? ? def __init__(self): > ? ? ? ? self.operator = sys.argv[1] > ? ? ? ? self.arg1 = sys.argv[2] > ? ? ? ? self.arg2 = sys.argv[3] Try this: def __init__(self, operator, arg1, arg2): self.operator = operator self.arg1 = arg1 self.arg2 = arg2 Then you can do x1 = Calculator('+', '1.0', '2.0') x2 = Calculator('-', '666', '42') or x3 = Calculator(*sys.argv[1:4]) if you're really desperate to use the command line args. > > ? ? def getOperator(self): > ? ? ? ? return sys.argv[1] Chris has already told you to give such accessor functions the flick, but it should have done return self.operator From sajmikins at gmail.com Sat Jan 17 21:07:07 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 17 Jan 2009 18:07:07 -0800 (PST) Subject: changing URLs in webpages, python solutions? Message-ID: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Hey folks, I'm having trouble finding this through google so I figured I'd ask here. I want to take a webpage, find all URLs (links, img src, etc.) and rewrite them in-place, and I'd like to do it in python (pure python preferred.) I know I could probably roll my own halfway decent solution in a day or so, like with Beautiful Soup or something, but I'd much rather re- use someone else's work if I can. I'm pretty sure this falls into the category of "someone else has had, and solved, this problem before." Any recommendations? Thanks in advance, ~Simon From sajmikins at gmail.com Sat Jan 17 21:10:08 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 17 Jan 2009 18:10:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: On Jan 11, 1:22?pm, "Madhusudan.C.S" wrote: > ? I am sorry all I am not here to just blame Python. This is just an > introspection of whether > what I believe is right. Being a devotee of Python from past 2 years I > have been writing only > small apps and singing praises about Python where ever I go. I now got > a chance to read > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > > ? ? class A: > ? ? a = 10 > ? ? b = "Madhu" > > ? ? def somemethod(self, arg1): > ? ? ? ? self.c = 20.22 > ? ? ? ? d = "some local variable" > ? ? ? ? # do something > ? ? ? ? .... > ? ? ... > ? ? def somemethod2 (self, arg2): > ? ? ? ? self.c = "Changed the variable" > ? ? ? ? # do something 2 > ? ? ? ? ... > > In such situations, where the Instance variables come into existence > only when they are used > it is very difficult to track the flow of code. Its obviously not > possible to remember what > instance variable was defined where, when reading some substantial > amount of code and where > it was manipulated for that matter. It becomes so very frustrating > even when reading a Class's > code with just 6-8 methods and not more than 100-150 lines of code. > > I am interested in knowing if I am reading this kind of code in the > wrong way mostly because > of C++/Java hangover since most other languages follow the same > approach as them? If there > is a Pythonic way reading this code for better readability? What made > Python developers to > adopt this strange strategy keeping "Readibility Counts" in mind? > > -- Python Rocks! > ? ?Madhusudan.C.S Python doesn't follow philosophies, people follow philosophies. ;-) ~S From steve at REMOVE-THIS-cybersource.com.au Sat Jan 17 21:24:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 02:24:51 GMT Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <0182896d$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see > it is very java like as that is all I know. Is this the right approach > to be taking? You might find it very useful to read: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html > Should I be taking a different approach? Thanks in advance. This is obviously a very minimal program, so I won't criticise you for failing to do any error checking :-) However, I will make some broad points: * No getters and setters. Python takes a very permissive approach to class attributes, taking the philosophy "we're all adults here". It's easy to change a public attribute to a private attribute with a getter/ setter if you need to, so there's nothing to be gained by writing getters for straight attribute access. It just makes things slow. * Don't return error values, raise an exception. Setting up a try...except block is really fast in Python, almost as fast as a pass statement (according to my tests). Catching the exception itself is slow, but most of the time you won't care about that. Let me re-write your code in a more Pythonic way. This is not the only way to do this, and it probably isn't the best way, but it may give you a flavour for the way Python is usually written. import sys import operator class Calculator(): dispatch = { # dispatch table mapping symbol to function '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv, } def __init__(self): self.operator = sys.argv[1] self.arg1 = int(sys.argv[2]) self.arg2 = int(sys.argv[3]) def calculate(self): func = self.dispatch[self.operator] return func(self.arg1, self.arg2) if __name__ == '__main__': # run this block only when running as a script, not # when the module is being imported (say, for testing). x = Calculator('+', 23, 42) try: y = x.calculate() except KeyError: print "Unrecognised operator '%s'" % x.operator else: print y -- Steven From mdw at distorted.org.uk Sat Jan 17 21:30:00 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 18 Jan 2009 02:30:00 +0000 Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> Message-ID: <87r6314a8n.fsf.mdw@metalzone.distorted.org.uk> Jeff McNeil writes: > Thank you! It was tp_base that was confusing me. The tp_bases member > makes sense as Python supports multiple inheritance. It wasn't > immediately clear that tp_base is there for single inheritance > reasons. It's all quite clear now. > > Is that an optimization of sorts? I think it's a compatibility thing because types didn't acquire multiple inheritance until the new-style class stuff started happening in, ummm..., Python 2.2, I think. This is rampant speculation. Please correct me. -- [mdw] From tjreedy at udel.edu Sat Jan 17 22:00:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:00:38 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: John Machin wrote: > On Jan 18, 9:10 am, Terry Reedy wrote: >> Martin v. L?wis wrote: >>>>> Does he intend to maintain two separate codebases, one 2.x and the >>>>> other 3.x? >>>> I think I have no other choice. >>>> Why? Is theoretically possible to maintain an unique code base for >>>> both 2.x and 3.x? >>> That is certainly possible! One might have to make tradeoffs wrt. >>> readability sometimes, but I found that this approach works quite >>> well for Django. I think Mark Hammond is also working on maintaining >>> a single code base for both 2.x and 3.x, for PythonWin. >> Where 'single codebase' means that the code runs as is in 2.x and as >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. >> >> One barrier to doing this is when the 2.x code has a mix of string >> literals with some being character strings that should not have 'b' >> prepended and some being true byte strings that should have 'b' >> prepended. (Many programs do not have such a mix.) >> >> One approach to dealing with string constants I have not yet seen >> discussed here is to put them all in separate file(s) to be imported. >> Group the text and bytes separately. Them marking the bytes with a 'b', >> either by hand or program would be easy. > > (1) How would this work for somebody who wanted/needed to support 2.5 > and earlier? > > (2) Assuming supporting only 2.6 and 3.x: > > Suppose you have this line: > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > Plan A: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the bytes section of the separate file: > ZIPFILE_SIG = "PK\x03\x04" > [somewhat later] > Change the above to: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan B: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the separate file: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan C: > Change original to: > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > variety thereof -- what advantages do you see in this over Plan C? > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat Jan 17 22:02:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:02:53 -0500 Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x In-Reply-To: <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: John Machin wrote: > On Jan 18, 9:10 am, Terry Reedy wrote: >> Martin v. L?wis wrote: >>>>> Does he intend to maintain two separate codebases, one 2.x and the >>>>> other 3.x? >>>> I think I have no other choice. >>>> Why? Is theoretically possible to maintain an unique code base for >>>> both 2.x and 3.x? >>> That is certainly possible! One might have to make tradeoffs wrt. >>> readability sometimes, but I found that this approach works quite >>> well for Django. I think Mark Hammond is also working on maintaining >>> a single code base for both 2.x and 3.x, for PythonWin. >> Where 'single codebase' means that the code runs as is in 2.x and as >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. >> >> One barrier to doing this is when the 2.x code has a mix of string >> literals with some being character strings that should not have 'b' >> prepended and some being true byte strings that should have 'b' >> prepended. (Many programs do not have such a mix.) >> >> One approach to dealing with string constants I have not yet seen >> discussed here is to put them all in separate file(s) to be imported. >> Group the text and bytes separately. Them marking the bytes with a 'b', >> either by hand or program would be easy. > > (1) How would this work for somebody who wanted/needed to support 2.5 > and earlier? See reposts in python wiki, one by Martin. > > (2) Assuming supporting only 2.6 and 3.x: > > Suppose you have this line: > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > Plan A: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the bytes section of the separate file: > ZIPFILE_SIG = "PK\x03\x04" > [somewhat later] > Change the above to: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan B: > Change original to: > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > Add this to the separate file: > ZIPFILE_SIG = b"PK\x03\x04" > [once per original file] > Add near the top: > from separatefile import * > > Plan C: > Change original to: > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > variety thereof -- what advantages do you see in this over Plan C? For 2.6 only (which is much easier than 2.x), do C. Plan A is for 2.x where C does not work. tjr From wuwei23 at gmail.com Sat Jan 17 22:03:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sat, 17 Jan 2009 19:03:21 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: On Jan 18, 9:55?am, "Brendan Miller" wrote: > > The *actual* goal as outlined by their official docs is to > > implement Python in Python, at every level. > Ok fair enough. In some ways I see that as more of a purely > intellectual exercise than the practical endeavor that I assumed the > project was originally. Well, it opens up Python as a whole for experimentation & modification by Python developers, which seems pretty practical to me :) > Another question I was wondering about is whether they plan on > maintaining good C bindings? Will existing bindings for third party > libraries be able to work? You really should run through the whole faq: http://codespeak.net/pypy/dist/pypy/doc/faq.html#can-i-use-cpython-extension-modules (Spoiler alert: the answer is no.) > Also, are they going to do away with the GIL? One FAQ entry before the above: http://codespeak.net/pypy/dist/pypy/doc/faq.html#do-threads-work-what-are-the-modules-that-work > The python devs seem to > consider the GIL a non-issue, though they may change their mind in 3 > years when we all have 32 core desktops, until then getting rid of the > GIL would make pypy pretty attractive in some quarters. I know the > scons project was running into GIL issues. It's not a case of the Python devs digging their heels in and not giving the world what it desperately wants. Here's an article by Guido talking about the last attempt to remove the GIL and the performance issues that arose: "I'd welcome a set of patches into Py3k *only if* the performance for a single-threaded program (and for a multi-threaded but I/O-bound program) *does not decrease*." http://www.artima.com/weblogs/viewpost.jsp?thread=214235 > Finally, I'm pretty unclear on what versions of python that pypy is targeting. I wonder where such a frequently asked question could be answered? ;) http://codespeak.net/pypy/dist/pypy/doc/faq.html#which-python-version-2-x-does-pypy-implement From xahlee at gmail.com Sat Jan 17 22:07:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 17 Jan 2009 19:07:24 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: a idiot wrote: > Yes, Jillian also has nested maps: the issue here, is not about whether Ruby has nested map or not. It is about illustrating a lisp problem. In particular, nested syntax impedes the functional programing paradigm of function chaining. ? A Ruby Illustration of Lisp Problems http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html a idiot wrote: > My code used 8 ?mysterious symbols?: > ( ) # [ ] . " % > > The Ruby version had these 7: > ( ) | { } . " The issue here is not about which lang employs more special chars. The issue is about the irregularities in lisp's syntax damaged its power of its otherwise believed superior regular syntax. ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html Xah ? http://xahlee.org/ ? From tjreedy at udel.edu Sat Jan 17 22:08:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Jan 2009 22:08:16 -0500 Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: Alan G Isaac wrote: >> Alan G Isaac wrote: >>> Is it intentional that ``exec`` cannot handle a TextIOWrapper? > >>> Bottom line: has ``execfile(filename)`` really become >>> ``exec(open(filename).read())``? Is this a good thing? > > > On 1/17/2009 4:20 PM Terry Reedy apparently wrote: >> Yes. Yes. > > > OK. Why? This: execfile(filename) is a trivial (9 keystroke) abbreviation of this: exec(open(filename).read()) which is similar in effect to this: from filename import * so it is really not needed. From rileyporter at gmail.com Sat Jan 17 22:37:57 2009 From: rileyporter at gmail.com (Riley Porter) Date: Sat, 17 Jan 2009 22:37:57 -0500 Subject: Dynamic Loading Modules Message-ID: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> Hello all, This is the first time I have posted to this group. That being said if I am in the wrong place for this kind of support please let me know. OK, So I am writing a log parsing program and wish to allow for the community to write "parsers". Basically, what I have in place now is a "modules" directory that contains .py files that are going to be used to parse specific log types. The question is, is there a way to dynamically import whatever is in that modules directory and make is to the import name is actually the file name.. So after the modules directory is 'os.listdir' and it returns a listing of modules (actually just .py files) IE: ng1-fw.py, cisco_asa_fw.py, etc... I can just in the next line of code call: ng1-fw.Parse(long_file) #assuming the ng1-fw.py file has a Parse Function right now using imp I got it to where i can say like: x = imp.load_source(md5.new(code_path).hexdigest(), code_path, f) #assuming that I gave it the path and filename for ng1-fw.py I can do this: x.Parse(log_file) But what I am really after is the ability to do this: ng1-fw.Parse(log_file) The reason again behind this is so that there is no need to "hard code" parser file names. Did I make myself clear? Please let me know if I need to explain that better. Thanks ! -- Riley Porter Network Security Engineer Offensive Security - OSCP SANS GIAC - GCIH CCNA, Security+ ACSA - Arcsight Security Analyst -------------- next part -------------- An HTML attachment was scrubbed... URL: From besturk at gmail.com Sat Jan 17 22:45:05 2009 From: besturk at gmail.com (Abandoned) Date: Sat, 17 Jan 2009 19:45:05 -0800 (PST) Subject: changing URLs in webpages, python solutions? References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Message-ID: On Jan 18, 4:07?am, Simon Forman wrote: > Hey folks, > > I'm having trouble finding this through google so I figured I'd ask > here. > > I want to take a webpage, find all URLs (links, img src, etc.) and > rewrite them in-place, and I'd like to do it in python (pure python > preferred.) > > I know I could probably roll my own halfway decent solution in a day > or so, like with Beautiful Soup or something, but I'd much rather re- > use someone else's work if I can. ?I'm pretty sure this falls into the > category of "someone else has had, and solved, this problem before." > > Any recommendations? > > Thanks in advance, > ~Simon You can use code search engines. I founded there but now i don't have. From http Sat Jan 17 22:57:27 2009 From: http (Paul Rubin) Date: 17 Jan 2009 19:57:27 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: <7xd4ele060.fsf@ruckus.brouhaha.com> alex23 writes: > Here's an article by Guido talking about the last attempt to remove > the GIL and the performance issues that arose: > > "I'd welcome a set of patches into Py3k *only if* the performance for > a single-threaded program (and for a multi-threaded but I/O-bound > program) *does not decrease*." The performance decrease is an artifact of CPython's rather primitive storage management (reference counts in every object). This is pervasive and can't really be removed. But a new implementation (e.g. PyPy) can and should have a real garbage collector that doesn't suffer from such effects. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 00:28:43 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 05:28:43 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <0182b484$0$8693$c3e8da3@news.astraweb.com> On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > Russ P. a ?crit : >> On Jan 15, 12:21 pm, Bruno Desthuilliers >> wrote: >> >>> Once again, the important point is that there's a *clear* distinction >>> between interface and implementation, and that you *shouldn't* mess >>> with implementation. >> >> If you "*shouldn't* mess with the implementation", then what is wrong >> with enforcing that "shouldn't" in the language itself? Russ: There are SHOULD NOTs and there are MUST NOTs. In Python, direct access to pointers is a MUST NOT. So the language itself prohibits arbitrary access to memory, and pure Python programs aren't subject to the same security holes and crashes that C programs are subject to because of their use of pointers. Messing with the implementation is a SHOULD NOT. There are times (possibly rare) where you are allowed to mess with the implementation. Hence the language doesn't prohibit it, only discourage it. The language designers choose how many hoops you have to jump through (and what performance penalty you suffer) in order to mess with the implementation. > Because sometimes you have a legitimate reason to do so and are ok to > deal with the possible issues. Bruno: Yes, but most of the time you don't. The consequence of this dynamism is that the Python VM can't do many optimizations at all, because *at any time* somebody might mess with the implementation. But 90% of the time nobody does, so Python is needlessly slow 90% of the time. Wouldn't it be nice if there was a way to speed up that 90% of the time while still allowing the 10% to take place? The current solution to this problem is to try to push as much as possible into functions written in C: built-ins and custom C extensions. It's not a bad solution: most Python programs rely on many C built-ins, which enforces real encapsulation and data hiding. With the possible exception of mucking about with ctypes, you simply can't access mess with the internals of (say) lists *at all*. Is this a bad thing? Would it be so terrible if we could do the same thing in pure Python? Why should I have to write in C if I want the same protection? >> Why leave to >> coding standards and company policy what can be encoded right into the >> language? > > Because human are smarter than computers. That's an awfully naive statement. It's a sound-byte instead of a reasoned argument. We're smarter than computers? Then why are we programming in languages like Python instead of directly in machine code? Why can optimizing C compilers make more efficient code than the best human assembly language programmers? Humans and computers are smart at different things. Human beings are not terribly good at keeping track of more than about seven things at once, on average, and consequently we easily forget what scope variables are in. It's probably been at least 15 years since any released version of Python has been buggy enough to "forget" whether a name was in one scope or another, and yet human programmers still generate NameError and AttributeError exceptions *all the time*. I bet even Guido still makes them occasionally. >> Why leave to humans (who are known to err) what can be automated >> relatively easily? Isn't that what computers are for? > > Error is human. For a real catastrophic failure, it requires a computer. Oh rubbish. That's a sound-byte invented by nervous technophobes scared of computers. I expected better from a programmer. When computers fail, it's is almost certainly because of human error: some human being wrote buggy code, some human being turned off a test because it was generating too many warnings, some human being failed to prove their code was correct. Chernobyl was a catastrophic failure that happened when *humans* turned off their safety systems to do a test, then couldn't turn them back on. >> All those "setters" and >> "getters" are a kludge. I think Python "properties" are a major step >> forward here. Just for fun, I checked to see if Scala has properties. >> Guess what? Not only does it have them, but they are generated >> automatically for all member data. That's even better than Python >> properties! > > Oh yes ? "Better", really ? So it's better to have a language that > automagically breaks encapsulation (requiring an additionnal level of > indirection) than a language that do the right thing by default ? I'm > afraid I missed the point ??? You certainly do. How do properties "break" encapsulation rather than enforcing it? >>>> As I said before, enforced encapsulation may not be appropriate for >>>> every application, but it is definitely appropriate for some. >>> No. It is appropriate for dummy managers hiring dummy programmers. The >>> project's size and domain have nothing to do with it. >> >> Let me try to be very clear here. We are dealing with two separate but >> related issues. The first is whether data hiding should be added to >> Python. > > No need to add it, it's already there : every name that starts with an > underscore is hidden !-) That's not hidden. It's there in plain sight. In Unix, file names with a leading dot are hidden in the shell: when you do a file listing, you don't see them. It's not difficult to get to see them: you just pass -a to the ls command. As data hiding goes, it's pretty lame, but Python doesn't even suppress _ names when you call dir. Frankly, I wish that by default it would -- 99% of the time when I call dir, I *don't* want to see _ names. They just get in the way. [...] >> Whether it can be added without screwing up the language, I don't know. >> If not, then so be it. That just limits the range of domains where >> Python is suitable. > > That's just plain stupid. No it's not. It's *practical*. There are domains where *by law* code needs to meet all sorts of strict standards to prove safety and security, and Python *simply cannot meet those standards*. >> As for whether data hiding provides a net benefit in any language, it >> certainly does for large programs and for safety-critical programs. For >> large, safety-critical systems, it's a no-brainer. > > Only if you fail to use your brain. Now, except for regurgitating the > official OMG prose, do you have *anything* to back these claims ? Python > is older than Java, and there are quite enough man/years of experience > and Python success stories to prove that it *just work*. Nobody doubts that Python works for many applications. But can you point to any large, safety-critical system programmed in Python? >> I like to use the example of the flight software for a large commercial >> transport aircraft, but many other examples could be given. How about >> medical systems that control radiation therapy or chemotherapy? How >> about financial systems that could take away your retirement account in >> 1.5 milliseconds. Or how about the control software for the strategic >> nuclear arsenals of the US or Russia? When you consider the sea, air, >> and land-based components, I'm sure that's one hell of a lot of code! > > And ? Such systems have been written (and quite a lot are still running) > with languages way more permissive than Python. You know, languages like > C or assembly. Yes, and it is *hard* because the programmer has to worry about data hiding *on his own*. That's why people no longer write large systems in assembly and use high-level languages that deal with all those data hiding issues for you. One of my friends has worked for many years programming some pretty high- powered banking software. Their approach is to move data-hiding into the database, or the operating system. Cobol doesn't enforce encapsulation, but the database and OS certainly do, with a permissions-based approach. Speaking of banking software, consider a typical banking application. It may have dozens or hundreds of programmers working on it. It's too big for any one person to understand all of it. Once deployed it may potentially have access to hundreds of billions of dollars of other people's money. Don't you imagine that one or two of these programmers might be tempted to skim a little off the top? Data hiding is a good way of making sure that the guy writing the front end can't just turn of the audit trail and transfer $60,000,000 into his bank account. Why don't you approach your bank and suggest that it would be a Good Thing if he could? Think of the programming time they would save with the added dynamism! Why, it might shave off *weeks* from a six year project! > Until you understand that *no technology is idiot-proof*, > you'll get nowhere in "software engineering". I suspect that Russ has got a lot further in software engineering than you have. I suspect your attitude is part of the reason why, as they say, "If engineers built bridges the way programmers build software, the first woodpecker than came along would destroy civilization". No technology is failure proof. But there's no reason in the world why most technology can't be idiot-proof. Televisions are idiot-proof, because they protect people from casual mistakes. If televisions were built according to the Python model, the internals of the TV would be exposed, without even a cover. All the major parts would be plug-in rather than soldered in, and there would be no cover over the parts that were live. Every year, tens of thousands of people would electrocute themselves fatally (because parts of the TV holds a massive charge for days after you unplug them from the mains) but that would be okay, because you never know when somebody might want to pull out the fly-back transformer and replace it with a six ohm resistor. That sort of dynamism is important! Well, maybe so, but not in a television. Consequently televisions are built to hide the internals from the user. If you *really* want to, then you can get a screwdriver and remove the back and unsolder the fly-back transformer and replace it with a six ohm resistor. It's your TV, do what you want. But nobody is going to die because the picture was fuzzy and they heard from some chat forum that the way to fix that was to poke the back of the picture tube with a screw driver "to let out the excess ohms". [...] >> An FMS programmer could perhaps >> decide to change the parameters of the engine controls, for example. > > Why on earth would he do something so stupid ? I'm sure he'd think he had a good reason. As you said, "Because sometimes you have a legitimate reason to do so and are ok to deal with the possible issues." Maybe other people would disagree whether or not it was a legitimate reason, or if he was OK dealing with the possible issues. Perhaps he needed the extra optimization of skipping the getter/setters. Perhaps he needed it for testing, and somehow one thing led to another. Who knows? It is strange that on the one hand you should insist that programmers sometimes need to mess with internals, and on the other dismiss those who do as "stupid". Your position is inconsistent. >> To prevent that sort of thing from happening, the management could >> decree that henceforth all "private" variable names will start with an >> underscore. Problem solved, eh? > > Certainly not. The only way to solve such a problem is to fire this > cretin. Again, we shouldn't enforce encapsulation and data hiding because there are legitimate reasons for breaking it, but anyone who does break it is a cretin. You have a very strange attitude. Besides, it's not very practical. When you fire "the cretin", it has consequences. Everyone else in the project has to work harder, which has costs, or you have to replace him, which also has costs. Maybe you can't fire him, because he's the only one who can debug problems in the auto- pilot. Perhaps the rest of the team downs tools and walks off the job in sympathy. Perhaps he sues you for unfair dismissal. Expenses rise. Time- lines slip. Uncertainty increases. It's also bad for moral when you fire somebody for messing with the internals when you have a policy that it is allowed to mess with the internals. That's why you picked a dynamic language like Python in the first place, because it doesn't prevent you from messing with the internals. And now when somebody does, you sack him? If you ask me, it's management who needs to be sacked, not the programmer who merely used the tools given to him. Perhaps you can't fire the cretin, because the first time you discover the problem is eight years later when a place filled with nuns and orphans flips upside down and flies straight into the ground. Perhaps it would have been better to prevent him from messing with the internals in the first place, even at some extra cost. When you're in business, you have to make decisions like: * do I write the software in Python, which will have a 99% chance of costing $100,000 and a 1% chance of costing $100,000,000? * or do I write it in a B&D language like Java, which will have a 100% chance of costing $2,000,000? [...] > Please educate yourself and learn about why Ariane 5 crashed on it's > first flight, due to an error in a module written in ADA (which is such > a psychorigid language that C++ and Java are even looser than Javascript > in comparison). Perhaps will it light a bulb for you. Others have already pointed out that the error in the Ariane 5 rocket was *human* error due to somebody messing with the internals, namely defeating the compiler's default type checking. I'd just like to ask: Bruno, were you aware of the cause of the crash, and if not, why did you raise the issue in the first place? Did you think it was a compiler bug that caused the crash? >>>> Not >>>> every door needs a lock, but certainly some do. >>> You only need locks when you don't trust your neighbours. >> >> Yeah, if you live in Nome, Alaska. > > Brillant. You obviously failed to understand the differences between > "software engineering" and real life. When it comes to computers, the > only doors I care closing are those which would let someone crack my > computer. If only there was some way to know which bugs could let people crack our computer and which bugs couldn't. Anyway, that's your choice. Personally, I'd much prefer my software not to cause data loss, not to crash, not to DoS me, not to hang, and not to generate bogus data, as well as not letting strangers crack into my system. There are many, many program paths which could potentially lead to these results. It would be nice if I could close those doors. > But FWIW, I never close my car. And, in case you don't know, it's > perfectly possible to access "private" members in Java (and, if you do > have access to the source code, in C++ too). Yes, but it is more difficult. There's a larger psychological barrier. It's easier to audit for such access, even in a large project. It encourages a more careful attitude: "do I *really* need to mess with the internals, or is there a safer way?". It forces the programmer to *think* before doing something potentially dangerous. This is why I wish eval and exec were in a module instead of built-ins. They'd still be there, but you'd have to jump through one small hoop before using them. Suppose Python worked like this: >>> class Parrot: ... _private = 'spam' ... >>> p = Parrot() >>> p._private = 'ham' Traceback (most recent call last): File "", line 1, in ProtectionError: attribute is read-only from outside of class Parrot >>> from protection import unlock >>> unlock(p)._private = 'ham' >>> p._private 'ham' I don't know if this scenario is even possible in Python, but pretend that it is. Would it be so terrible? If a particular project wanted to enforce encapsulation, all they need do is replace or remove the protection module from their Python installations. (I assume the project developers aren't *hostile*. If they are, then there's almost nothing you can do to make the code safe. Encapsulation is about protecting from accidents, not sabotage.) If you wanted to mess with the internals in your own project, all you need do is import a module. We could imagine the same scenario in reverse. Python allows getters and setters, but they're more work, and so people just don't use them unless they really need to. Suppose Python offered real data encapsulation, but you had to work to get it: >>> class Parrot: ... _private = 'spam' ... >>> p = Parrot() >>> p._private = 'ham' # allowed by default >>> from protection import lock >>> lock(p)._private >>> p._private = 'spam' Traceback (most recent call last): File "", line 1, in ProtectionError: attribute is read-only from outside of class Parrot Would that be so bad? I don't think so. -- Steven From elhmbre at ozemail.com.au Sun Jan 18 02:12:45 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:12:45 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4972d682$0$9528$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Chris Rebert" wrote in message news:mailman.7468.1232242083.3487.python-list at python.org... > On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: ... > > Rather than have a long if-elif-else chain like this, you can use a > dictionary with functions as values. For example: > > def add(x, y): > return x + y > > def sub(x, y): > return x - y > > OPER2FUNC = {'+' : add, '-' : sub} > print OPER2FUNC['+'](3,4) #==> 7 > > You can use the same technique with the functions in the `operator` > module to significantly shorten your calculate() method. > > Cheers, > Chris Thanks very much Chris. That is much more concise ! I have a lot of reading to do and a different mindset to work towards. From elhmbre at ozemail.com.au Sun Jan 18 02:16:04 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:16:04 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <7xy6x9nzwd.fsf@ruckus.brouhaha.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: <4972d740$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Paul Rubin" wrote in message news:7xy6x9nzwd.fsf at ruckus.brouhaha.com... > Chris Rebert writes: >> > class Calculator(): ... > >> Delete the 3 Java-ish accessor methods; good Python style just uses >> the attributes directly (i.e. self.operator instead of >> self.getOperator()). > > I think I would get rid of the whole Calculator class unless there was > a good reason to keep it (i.e. you are going to have several > Calculators active in the program simultaneously). Just write > straightforward imperative code without bothering with the OO stuff > that is mandatory in Java. > >> Rather than have a long if-elif-else chain like this, you can use a >> dictionary with functions as values. For example: >> >> def add(x, y): >> return x + y > > These functions are already defined in the operator module, and you > can also define them inline with the lambda operator. > > Here is my version of the program: > > import sys > from operator import add, mul, sub, div > > op, x, y = sys.argv[1:4] > > opdict = {'+': add, '*': mul, '-': sub, '/': div} > > try: > func = opdict[op] > except KeyError: > print 'wrong argument supplied' > sys.exit() > > print func(int(x), int(y)) > > Note that like the original, it doesn't check for valid numeric args. Good point about the class. I really only did that to begin to learn the class syntax. I had not added any exception handling as I was taking it a step at a time. Most of the first few hours were spent mucking around with TextMate, Netbeans and Wing IDE. I finally got Netbeans working to the point where something would run. Thanks very much Paul. From elhmbre at ozemail.com.au Sun Jan 18 02:16:39 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:16:39 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <5d2c588a-9b01-4a85-85b2-b132754e6e08@o40g2000prn.googlegroups.com> Message-ID: <4972d760$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "John Machin" wrote in message news:5d2c588a-9b01-4a85-85b2-b132754e6e08 at o40g2000prn.googlegroups.com... > On Jan 18, 12:11 pm, "elhombre" wrote: >> Hello, below is my first fragment of working python code. As you can see >> it >> is very java like as that is all I know. Is this the right approach to be >> taking? >> Should I be taking a different approach? Thanks in advance. >> >> import sys >> >> class Calculator(): >> >> def __init__(self): >> self.operator = sys.argv[1] >> self.arg1 = sys.argv[2] >> self.arg2 = sys.argv[3] > > Try this: > > def __init__(self, operator, arg1, arg2): > self.operator = operator > self.arg1 = arg1 > self.arg2 = arg2 > > Then you can do > x1 = Calculator('+', '1.0', '2.0') > x2 = Calculator('-', '666', '42') > or > x3 = Calculator(*sys.argv[1:4]) > if you're really desperate to use the command line args. > >> >> def getOperator(self): >> return sys.argv[1] > > Chris has already told you to give such accessor functions the flick, > but it should have done > return self.operator Thanks John. > From elhmbre at ozemail.com.au Sun Jan 18 02:17:09 2009 From: elhmbre at ozemail.com.au (elhombre) Date: Sun, 18 Jan 2009 17:17:09 +1000 Subject: A java hobbyist programmer learning python In-Reply-To: <0182896d$0$8693$c3e8da3@news.astraweb.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <4972d77e$0$9485$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:0182896d$0$8693$c3e8da3 at news.astraweb.com... > On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: > >> Hello, below is my first fragment of working python code. As you can see >> it is very java like as that is all I know. Is this the right approach >> to be taking? > > You might find it very useful to read: > > http://dirtsimple.org/2004/12/python-is-not-java.html > > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > > >> Should I be taking a different approach? Thanks in advance. > > This is obviously a very minimal program, so I won't criticise you for > failing to do any error checking :-) However, I will make some broad > points: > > * No getters and setters. Python takes a very permissive approach to > class attributes, taking the philosophy "we're all adults here". It's > easy to change a public attribute to a private attribute with a getter/ > setter if you need to, so there's nothing to be gained by writing getters > for straight attribute access. It just makes things slow. > > * Don't return error values, raise an exception. Setting up a > try...except block is really fast in Python, almost as fast as a pass > statement (according to my tests). Catching the exception itself is slow, > but most of the time you won't care about that. > > > > Let me re-write your code in a more Pythonic way. This is not the only > way to do this, and it probably isn't the best way, but it may give you a > flavour for the way Python is usually written. > > > import sys > import operator > > class Calculator(): > dispatch = { # dispatch table mapping symbol to function > '+': operator.add, > '-': operator.sub, > '*': operator.mul, > '/': operator.truediv, > } > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = int(sys.argv[2]) > self.arg2 = int(sys.argv[3]) > def calculate(self): > func = self.dispatch[self.operator] > return func(self.arg1, self.arg2) > > > if __name__ == '__main__': > # run this block only when running as a script, not > # when the module is being imported (say, for testing). > x = Calculator('+', 23, 42) > try: > y = x.calculate() > except KeyError: > print "Unrecognised operator '%s'" % x.operator > else: > print y > > > > > -- > Steven Excellent links. Thanks Steven ! From gagsl-py2 at yahoo.com.ar Sun Jan 18 02:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 05:44:47 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald escribi?: > I googled a bit this morning search for an answer to this problem but > have > come up empty so far. Can anyone help? > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit ^^^^^ > (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib2 > Traceback (most recent call last): > File "", line 1, in > File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in ^^^^^^^^ It seems your have a confusing setup. Why is Python 2.6 using C:\dev\opt\Python25? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 02:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 05:44:47 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald escribi?: > I googled a bit this morning search for an answer to this problem but > have > come up empty so far. Can anyone help? > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit ^^^^^ > (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib2 > Traceback (most recent call last): > File "", line 1, in > File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in ^^^^^^^^ It seems your have a confusing setup. Why is Python 2.6 using C:\dev\opt\Python25? -- Gabriel Genellina From xahlee at gmail.com Sun Jan 18 03:31:15 2009 From: xahlee at gmail.com (Xah Lee) Date: Sun, 18 Jan 2009 00:31:15 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> Message-ID: <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> On Jan 17, 10:25 am, Tino Wildenhain wrote: > > [[int(x) for x in line.split()] for line in open("blob.txt")] Nice (python code). Few comments: ? the above code is borderline of atypical. e.g. it is not a average python code would produce or one'd seen in corporate python code. ? voodoo like the above makes me dislike python. To me, the one advantage of python is its clarity enforced by its syntax. Specifically, the forced indendation and quite simple semantics. However, the way i've seen Guido's propensities and how python 3 is moving to, it is becoming more mumbo jumbo of computer sciency OOP jargons with syntax soup. (with iterators, enumerators, list comprehension... shits forced upon the users) The above line illustrate well the ad hoc syntax soup nature python is moving into. Further readings: ? Perl-Python Tutorial: List Comprehension http://xahlee.org/perl-python/list_comprehension.html ? Lambda in Python 3000 http://xahlee.org/perl-python/python_3000.html Xah ? http://xahlee.org/ ? From icejobjob22 at gmail.com Sun Jan 18 04:17:37 2009 From: icejobjob22 at gmail.com (icejobjob) Date: Sun, 18 Jan 2009 03:17:37 -0600 Subject: PyQt, Cannot send events to objects owned by a different thread? References: <47498520$0$13104$9b4e6d93@newsspool2.arcor-online.net> Message-ID: ?A?E?X?????A?????????A?E?X???????????????????????????? ?????A'?A?E????' (http://www.pwblog.com/user/xru01/syusyoku/)???????????w?????????????????????????????????????????B ?????A?A?????J???T?u?v???C?????????????????N???????????????s???A???????????N?????????????A???E?o?????C???p?N?g???^?????????????????B ???????????A?????*???????????????????A?E???????????C?x???g???A?*???????l???A?A?E?l???????????E?G?C?g???????????????????????B ?A?E???????A?Z?p???m???????????????????o???????B?A?E?X?????A???????????????????????S?????????????????B -- icejobjob ------------------------------------------------------------------------ icejobjob's Profile: http://forums.yourdomain.com.au/member.php?userid=5313 View this thread: http://forums.yourdomain.com.au/showthread.php?t=18594 From pavlovevidence at gmail.com Sun Jan 18 05:40:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 18 Jan 2009 02:40:29 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> Message-ID: <43573712-026a-4f84-817a-7bfdceda8719@v5g2000prm.googlegroups.com> On Jan 17, 8:12?am, Jeff McNeil wrote: > On Jan 17, 11:09?am, Jeff McNeil wrote: > > > > > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > So, the documentation states that ob_type is a pointer to the type's > > > > type, or metatype. Rather, this is a pointer to the new type's > > > > metaclass? > > > > That's actually the same. *Every* ob_type field points to the object's > > > type, e.g. for strings, integers, tuples, etc. That includes type > > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > > also called metaclass (as "class" and "type" are really synonyms). > > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > > base type from which type properties are inherited." ?The value of > > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > > the surface, it sound as though they're one in the same? > > > > (I don't understand the English "one in the same" - interpreting it > > > as "as though they should be the same") > > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > > inheritance); tp_base (if set) provides the first base type. > > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > > tp_base is only at play when the object in question inherits from > > > > type? > > > > No - it is the normal case for single inheritance. You can leave it > > > NULL, which means you inherit from object. > > > > Regards, > > > Martin > > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > > makes sense as Python supports multiple inheritance. ?It wasn't > > immediately clear that tp_base is there for single inheritance > > reasons. It's all quite clear now. > > > Is that an optimization of sorts? > > Well, maybe not specifically for single inheritance reasons, I just > didn't see an immediate reason to keep a separate pointer to the first > base type. The reason you need a separate tp_base is because it doesn't necessarily point to the first base type; rather, it points to the first base type that has added any fields or slots to its internal layout (in other words, the first type with a tp_basicsize > 8, on 32- bit versions). I believe this is mainly for the benefit of Python subclasses that define their own slots. The type constructor will begin adding slots at an offset of tp_base->tp_basicsize. To see an example, int objects have a tp_basicsize of 12 (there are 4 extra bytes for the interger). So if you multiply-inherit from int and a Python class, int will always be tp_base. class A(object): pass class B(int,A): pass print B.__base__ # will print class C(A,int): pass print C.__base__ # will print A related issue is that you can't multiply inherit from two types that have tp_basicsize > 8 unless one of them inherits from the other. There can be only one tp_base. For instance: class D(int,tuple): pass # will raise TypeError class E(object): __slots__ = ['a','b'] class F(object): __slots__ = ['c','d'] class G(E,G): pass # will raise TypeError class H(E,int): pass # will raise TypeError .... Here's a bit more background (and by "a bit" I mean "a lot"): In 32-bit Python, objects of types defined in Python are usually only 16 bytes long. The layout looks like this. instance dict weak reference list reference count ob_type The reference count, which is always the thing that the actual PyObject* points at, isn't actually the first item in the object's layout. The dict and weakref list are stored at a lower address. (There's a reason for it.) If a Python class defines any __slots__, the type constructor will add the slots to the object's layout. instance dict (if there is one) weak reference list (if there is one) reference count ob_type slot slot slot Note that, because you defined __slots__, the object might not have an instance dict or weak reference list associated with it. It might, though, if one of the base classes had defined an instance dict or weakref list. Or, it might not, but then a subclass might have its onw instance dict or weakref list. That's why these guys are placed at a lower address: so that they don't interfere with the layout of subclasses. A subclass can add either more slots or a dict. Object of types defined in C can have arbitrary layout. For instance, it could have a layout that looks like this: reference count ob_type PyObject* a PyObject* b long c float d instance dict A problem with Python slots and C fields is that, if you want to inherit from a type with a non-trivial object layout, aside from the dict and weakrefs, all of the subtypes have to maintain the same layout (see Liskov substitutability for rationale). Subtypes can add their own fields or slots if they want, though. So, if a Python subtype wants to define its own slots on top of a type with a non-trivial object layout, it has to know which base has the largest layout so that it doesn't use the same memory for its own slots. Hence tp_base. Carl Banks From andrew at acooke.org Sun Jan 18 05:56:55 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 02:56:55 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? Message-ID: Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data model#object.__iadd__ Just a suggestion I thought I'd throw out... There's a restriction in the language implementation on exactly what can go the left of an augmented arithmetic expression. For example: >>> a = 3 >>> a **= 2 is ok, but: >>> class Foo(): ... def __init__(): ... self.a = 3 ... def __ipow__(self, x): ... self.a **= x ... >>> Foo() **= 2 File "", line 1 SyntaxError: illegal expression for augmented assignment Now unless I've done something stupid above (always a possibility :o) the implementation seems a bit strict (is it really a *syntax* error? - I am not sure exactly what the restriction is). This may seems like a small issue, but operators can really help with making embedded DSLs in Python - they give quite a bit of "wiggle room" to invent a syntax that is compact and intuitive. The restriction above cuts into that (OK, so it's still a small issue... :o) Cheers, Andrew From andrew at acooke.org Sun Jan 18 05:58:21 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 02:58:21 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <280b70f2-e4ed-4cc1-83b3-2736ba2c4e68@u14g2000yqg.googlegroups.com> Improved link - http://docs.python.org/3.0/reference/datamodel.html#object.__iadd__ From jstroud at mbi.ucla.edu Sun Jan 18 06:10:34 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 18 Jan 2009 03:10:34 -0800 Subject: dynamic module import? In-Reply-To: <49711259$0$23396$afc38c87@news.optusnet.com.au> References: <49711259$0$23396$afc38c87@news.optusnet.com.au> Message-ID: Lawson Hanson wrote: > So is there any way to get Python to import the named module > without just doing "from dummy import *", because I will > not know that the user wants to use the "dummy" module > until run-time ... I'm trying to import control data > for different run scenarios which will be defined in > differently named Python modules which the user will > specify at run-time with a command-line option > > And help with this would be most appreciated For the sake of humanity, I must try to talk you out of this. Well, it's not that serious, but dynamic import confuses programs that inspect code like py2exe, etc. I think it is likely that you will find the day that you regret trying so hard to 'import *' dynamically. A more maintainable way is to simply map the command line argument to an import statement and keep your namespaces clean: """importer_module""" import sys import dummy import bonafide modules = {"dummy" : dummy, "bonafide" : bonafide} module = modules[sys.argv[1]] If you have several modules that themselves might need the conditional imports, simply put the import statements in a separate module (e.g. "importer_module" and do something like """another_module""" from importer_module import module If you simply don't want to import a bunch of modules, use an if/then statement. In any event, I advise you to not design your code or usage around dynamic imports using the __import__() statement or exec(). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From clp2 at rebertia.com Sun Jan 18 06:31:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 03:31:46 -0800 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: Message-ID: <50697b2c0901180331j2702b744h8548c3a908c1f381@mail.gmail.com> On Sun, Jan 18, 2009 at 2:56 AM, andrew cooke wrote: > Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data > model#object.__iadd__ > > Just a suggestion I thought I'd throw out... There's a restriction in > the language implementation on exactly what can go the left of an > augmented arithmetic expression. > > For example: >>>> a = 3 >>>> a **= 2 > > is ok, but: >>>> class Foo(): > ... def __init__(): > ... self.a = 3 > ... def __ipow__(self, x): > ... self.a **= x > ... >>>> Foo() **= 2 > File "", line 1 > SyntaxError: illegal expression for augmented assignment > > Now unless I've done something stupid above (always a possibility :o) > the implementation seems a bit strict (is it really a *syntax* error? > - I am not sure exactly what the restriction is). IIRC, you can only assign to: - variables (x = ...) - attributes (x.y = ...) - elements (x[y] = ...) Anything else doesn't make sense to assign to because it's not a "storage box" so to speak. There's no way to work out what is meant. In your case, you're assigning to a *value*, specifically a new instance of the Foo class, which is nonsensical; instead of a "box", you're trying to assign to a "value", something that gets stored in boxes. By comparison, '2 = 5' and '[1,2] = 7' would seem to have some sort of meaning under your system, which IMHO seems preposterous. Now true, you are using augmented assignment, which in certain cases is translated to a method call, but in principle the augmented assignment (e.g. x += y) should have roughly the same effect as the non-augmented equivalent (x = x + y), and the fact that a method call is involved is merely an implementation detail of sorts. Therefore, Python requires you to rewrite the code in some other way that makes your intentions more clear. For instance, why not use the << operator instead? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From andrew at acooke.org Sun Jan 18 06:42:14 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 03:42:14 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> > Therefore, Python requires you to rewrite the code in some other way > that makes your intentions more clear. For instance, why not use the > << operator instead? Right, but you're guessing what the context is. Within a DSL it often makes a lot of sense to use operators for reasons that weren't originally intended. You even make the same case yourself indirectly. The same argument you make could be made to say that << should only operator on values that can be shifted. Now thankfully there is no way to test for that, so there is no restriction and, consequently, it is now widely accepted that no-one (even people arguing the case for constraints!) think it odd to use << for something other than its initial use. Obviously this kind of discussion has gone on since languages were first invented - it's the "how much rope" argument. So rather than continue down that road I would just like to say that this feels like an inconsistency. The other operators are *not* as restricted and this is making my life harder. It may sound crazy, but this may force me to use * and ** instead (the context is a language feature related to *args and **kargs, so the * and ** help convey the meaning). And they have a much much stronger meaning to users, which will make my DSL harder to understand. So in this case a blunt knife is making life harder. Andrew From gandalf at shopzeus.com Sun Jan 18 06:46:52 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 18 Jan 2009 12:46:52 +0100 Subject: Dynamic Loading Modules In-Reply-To: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> References: <6d7307e80901171937s24e7618cy75b14ab69a08c4e0@mail.gmail.com> Message-ID: <497316AC.3050102@shopzeus.com> Riley Porter ?rta: > Hello all, > > This is the first time I have posted to this group. That being said > if I am in the wrong place for this kind of support please let me know. > > OK, > > So I am writing a log parsing program and wish to allow for the > community to write "parsers". Basically, what I have in place now is > a "modules" directory that contains .py files that are going to be > used to parse specific log types. > > The question is, is there a way to dynamically import whatever is in > that modules directory and make is to the import name is actually the > file name.. > So after the modules directory is 'os.listdir' and it returns a > listing of modules (actually just .py files) IE: ng1-fw.py, > cisco_asa_fw.py, etc... I can just in the next line of code call: > > ng1-fw.Parse(long_file) #assuming the ng1-fw.py file has a Parse Function > > right now using imp I got it to where i can say like: > x = imp.load_source(md5.new(code_path).hexdigest(), code_path, f) > #assuming that I gave it the path and filename for ng1-fw.py > I can do this: > > x.Parse(log_file) > > But what I am really after is the ability to do this: > ng1-fw.Parse(log_file) > > The reason again behind this is so that there is no need to "hard > code" parser file names. > > Did I make myself clear? Please let me know if I need to explain that > better. What you need is the imp module: http://docs.python.org/library/imp.html > This module provides an interface to the mechanisms used to implement > the import > statement. It defines the following constants and functions: You might find that using classes instead of modules is more handy. Regards, Laszlo From wuwei23 at gmail.com Sun Jan 18 06:55:55 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Jan 2009 03:55:55 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> Message-ID: <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> On Jan 17, 3:55?pm, Steven D'Aprano wrote: > Both very good points, but consider that you're not comparing apples with > apples. > > >>> __import__("os", fromlist=["system"]) > >>> system > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'system' is not defined I must confess I've rarely had a need to use __import__ and don't think I've ever used the fromlist arg. I'm confused, though, because the docstring states: The fromlist should be a list of names to emulate ``from name import ...'' But it also states that __import__ always returns a module, so I'm utterly confused as to the purpose of fromlist, or how to inject the specified entries into the calling namespace. If anyone could explain this for me, I'd really appreciate it. > I mention this only to be pedantic, because I agree with your point that > exec can introduce security issues, and be significantly slower. Correcting misinformation isn't pedantry, especially when I've learned something :) From andrew at acooke.org Sun Jan 18 06:56:28 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 03:56:28 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: Since this is a PyPy bashing thread, maybe it's an appropriate place to suggest that the project has got a little bit waylaid by exploring cool things instead of releasing a useful final result? I am not questioning rpython directly - the case for something like that is obvious. But there's a question of balance. It's possible to go on building ever more complex systems which are theoretically justified, but which postpone ever finishing the job. At some point there has to be a "good enough". To some extent I am playing devil's advocate here, but as an outside who looked at PyPy a while back, my uninformed and naive impression was that the project was suffering from the kid of issues I have caricatured above.... Andrew PS I guess you are aware of worse is better etc? I think this may also be a US/Euro culture issue... From sjmachin at lexicon.net Sun Jan 18 06:56:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 18 Jan 2009 03:56:39 -0800 (PST) Subject: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x References: <16112d9a-875d-4c05-8fe3-d0ada345d2e1@v39g2000pro.googlegroups.com> <95db2df0-c00b-48b7-aa58-af5970dedb1e@s9g2000prg.googlegroups.com> <5f460518-8489-4ae7-8c35-1173d01be2bc@z27g2000prd.googlegroups.com> <579a5916-61db-404d-be7d-866f152106d0@k36g2000pri.googlegroups.com> <6b8e63f6-0fd1-4cd1-96e8-cd134e9aed98@t39g2000prh.googlegroups.com> <4971ea0b$0$7055$9b622d9e@news.freenet.de> <61efbf72-2748-45fa-963e-79a29cf3705f@v39g2000pro.googlegroups.com> Message-ID: <04767ad3-e8b9-49b5-a539-24e236bde58a@40g2000prx.googlegroups.com> On Jan 18, 2:02?pm, Terry Reedy wrote: > John Machin wrote: > > On Jan 18, 9:10 am, Terry Reedy wrote: > >> Martin v. L?wis wrote: > >>>>> Does he intend to maintain two separate codebases, one 2.x and the > >>>>> other 3.x? > >>>> I think I have no other choice. > >>>> Why? Is theoretically possible to maintain an unique code base for > >>>> both 2.x and 3.x? > >>> That is certainly possible! One might have to make tradeoffs wrt. > >>> readability sometimes, but I found that this approach works quite > >>> well for Django. I think Mark Hammond is also working on maintaining > >>> a single code base for both 2.x and 3.x, for PythonWin. > >> Where 'single codebase' means that the code runs as is in 2.x and as > >> autoconverted by 2to3 (or possibly a custom comverter) in 3.x. > > >> One barrier to doing this is when the 2.x code has a mix of string > >> literals with some being character strings that should not have 'b' > >> prepended and some being true byte strings that should have 'b' > >> prepended. ?(Many programs do not have such a mix.) > > >> One approach to dealing with string constants I have not yet seen > >> discussed here is to put them all in separate file(s) to be imported. > >> Group the text and bytes separately. ?Them marking the bytes with a 'b', > >> either by hand or program would be easy. > > > (1) How would this work for somebody who wanted/needed to support 2.5 > > and earlier? > > See reposts in python wiki, one by Martin. Most relevant of these is Martin's article on porting Django, using a single codebase. The """goal is to support all versions that Django supports, plus 3.0""" -- indicating that it supports at least 2.5, which won't eat b"blah" syntax. He is using 2to3, and handles bytes constants by """django.utils.py3.b, which is a function that converts its argument to an ASCII-encoded byte string. In 2.x, it is another alias for str; in 3.x, it leaves byte strings alone, and encodes regular (unicode) strings as ASCII. This function is used in all places where string literals are meant as bytes, plus all cases where str() was used to invoke the default conversion of 2.x.""" Very similar to what I expected. However it doesn't answer my question about how your "move byte strings to a separate file, prepend 'b', and import the separate file" strategy would help ... and given that 2.5 and earlier will barf on b"arf", I don't expect it to. > > (2) Assuming supporting only 2.6 and 3.x: > > > Suppose you have this line: > > if binary_data[:4] == "PK\x03\x04": # signature of ZIP file > > > Plan A: > > Change original to: > > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > > Add this to the bytes section of the separate file: > > ZIPFILE_SIG = "PK\x03\x04" > > [somewhat later] > > Change the above to: > > ZIPFILE_SIG = b"PK\x03\x04" > > [once per original file] > > Add near the top: > > from separatefile import * > > > Plan B: > > Change original to: > > if binary_data[:4] == ZIPFILE_SIG: # "PK\x03\x04" > > Add this to the separate file: > > ZIPFILE_SIG = b"PK\x03\x04" > > [once per original file] > > Add near the top: > > from separatefile import * > > > Plan C: > > Change original to: > > if binary_data[:4] == b"PK\3\4": # signature of ZIP file > > > Unless I'm gravely mistaken, you seem to be suggesting Plan A or some > > variety thereof -- what advantages do you see in this over Plan C? > > For 2.6 only (which is much easier than 2.x), do C. ?Plan A is for 2.x > where C does not work. Excuse me? I'm with the OP now, I'm totally confused. Plan C is *not* what you were proposing; you were proposing something like Plan A which definitely involved a separate file. Why won't Plan C work on 2.x (x <= 5)? Because the 2.X will b"arf". But you say Plan A is for 2.x -- but Plan A involves importing the separate file which contains and causes b"arf" also! To my way of thinking, one obvious DISadvantage of a strategy that actually moves the strings to another file (requiring invention of a name for each string (that doesn't have one already) so that it can be imported is the amount of effort and exposure to error required to get the same functional result as a strategy that keeps the string in the same file ... and this disadvantage applies irrespective of what one does to the string: b"arf", Martin's b("arf"), somebody else's _b ("arf") [IIRC] or my you-aint-gonna-miss-noticing-this-in-the-code BYTES_LITERAL("arf"). Cheers, John From hubaghdadi at gmail.com Sun Jan 18 06:59:51 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Sun, 18 Jan 2009 03:59:51 -0800 (PST) Subject: Am I interacting with the database correctly? Message-ID: Hey, I'm new with database interactions in Python and I'm not sure if I'm handling the cursor and transactions correctly: ++++++++ cursor = db.cursor(MySQLdb.cursors.DictCursor) cursor.execute(flate_rate_pkgs_sql) rows = cursor.fetchall() #I have for loop here to iterate over rows cursor.execute() rows = cursor.fetchall() # some more cursor.execute() calls but only SQL select statements # here is another for loop that contains try block # here are cursor.execute() calls, both insert and update db.commit() # in the except code block, I use db.rollback() ++++++++ As you see, my script contains only one db object and one cursor object and both the db and cursor objects are used multiple times, it is ok? As you might figured, this is a script for reports :) Thanks. From clp2 at rebertia.com Sun Jan 18 07:01:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 04:01:14 -0800 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: <50697b2c0901180401v17e20168yeba34a73771a27f3@mail.gmail.com> On Sun, Jan 18, 2009 at 3:42 AM, andrew cooke wrote: >> Therefore, Python requires you to rewrite the code in some other way >> that makes your intentions more clear. For instance, why not use the >> << operator instead? > > Right, but you're guessing what the context is. Within a DSL it often > makes a lot of sense to use operators for reasons that weren't > originally intended. > > You even make the same case yourself indirectly. The same argument > you make could be made to say that << should only operator on values > that can be shifted. Now thankfully there is no way to test for that, > so there is no restriction and, consequently, it is now widely > accepted that no-one (even people arguing the case for constraints!) > think it odd to use << for something other than its initial use. > > Obviously this kind of discussion has gone on since languages were > first invented - it's the "how much rope" argument. So rather than > continue down that road I would just like to say that this feels like > an inconsistency. The other operators are *not* as restricted and > this is making my life harder. Indeed. Python happens to in this case draw the line at using the augmented assignment operators for non-assignment. I personally see this as reasonable because the = symbol has a consistent meaning in Python (assignment) whereas the other plain operators, as you bring up, consistently have no predetermined meaning; but I do agree that it is in a sense an arbitrary restriction, like many programming language design choices. However, Python was not explicitly designed for creating DSLs, so it's kinda odd to complain about something Python never claimed to support in the first place (although I do favor the DSL in general-purpose-PL paradigm). > It may sound crazy, but this may force me to use * and ** instead (the > context is a language feature related to *args and **kargs, so the * > and ** help convey the meaning). And they have a much much stronger > meaning to users, which will make my DSL harder to understand. So in > this case a blunt knife is making life harder. Perhaps if you explained your particular predicament in more depth, someone might be able to offer a workable suggestion. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From andrew at acooke.org Sun Jan 18 07:14:41 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:14:41 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: Not sure if you were saying this, but the underlying technical reason for this issue is that they are treated as assignment rather than operators in the language spec - http://docs.python.org/3.0/reference/simple_stmts.html#augmented-assignment-statements I think this explains why they are not listed in the operator precedence table http://docs.python.org/3.0/reference/expressions.html#summary I think that's unfortunate in a language with mutable objects, but it makes the decision seem much less arbitrary... Cheers, Andrew From andrew at acooke.org Sun Jan 18 07:24:04 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:24:04 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: On Jan 18, 9:01?am, Chris Rebert wrote: > Indeed. Python happens to in this case draw the line at using the > augmented assignment operators for non-assignment. I personally see > this as reasonable because the = symbol has a consistent meaning in > Python (assignment) whereas the other plain operators, as you bring > up, consistently have no predetermined meaning; my argument was that *= is not treated as = and *, but as a completely new operator (the docs even say that the implementation need not return self which suggests some pretty extreme semantics were envisaged). however, as i've just commented elsewhere, this commitment to operators was only half-baked because they are parsed as assignments. anyway, to reply to your comment - *= is not predetermined. it is determined by __imul__ which is user-definable. > but I do agree that it > is in a sense an arbitrary restriction, like many programming language > design choices. However, Python was not explicitly designed for > creating DSLs, python is a general programming language. as far as i can make any sense at all of your argument it seems to be "you are asking for change, but this is not how the current system works". to which the obvious answer is: if it did work that way i wouldn't be asking for change. andrew From bj_666 at gmx.net Sun Jan 18 07:40:55 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 18 Jan 2009 12:40:55 GMT Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> Message-ID: <6tgmanFaq2t9U1@mid.uni-berlin.de> On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > my argument was that *= is not treated as = and *, but as a completely > new operator (the docs even say that the implementation need not return > self which suggests some pretty extreme semantics were envisaged). What do you mean by "suggests ? extreme semantics"? Most natural thing is to use numbers and there you *have* to be able to return something different than `self` to get anything useful. For instance: n *= 3 with `n` bound to a number different from zero can't return `self` from `__imul__`. Ciao, Marc 'BlackJack' Rintsch From andrew at acooke.org Sun Jan 18 07:56:52 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:56:52 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: On Jan 18, 9:40?am, Marc 'BlackJack' Rintsch wrote: > On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > > my argument was that *= is not treated as = and *, but as a completely > > new operator (the docs even say that the implementation need not return > > self which suggests some pretty extreme semantics were envisaged). > > What do you mean by "suggests ? extreme semantics"? ?Most natural thing > is to use numbers and there you *have* to be able to return something > different than `self` to get anything useful. ?For instance: > > ?n *= 3 > > with `n` bound to a number different from zero can't return `self` from > `__imul__`. in your example, n is not a number, it is a mutable variable, and its value changes. when n is an instance implementing __imul__ the natural analogue is that the internal state of the instance changes. either i have misundertstood you, or you have misunderstood __imul__, or you are treating = as equality, or maybe you are thinking of a pure language that creates new instances? python is impure. anyway, my original request is moot. i was assuming that this was a "capricious" restriction. in fact it's related to what i thought were operators actually being assignments, and so no change is possible (until python 4.0 when guido will finally see the light and move to s- expressions, at which point everyone will stop using the language ;o) andrew From stef.mientki at gmail.com Sun Jan 18 07:57:59 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 13:57:59 +0100 Subject: is there something like a module decorator ? Message-ID: <49732757.6090506@gmail.com> hello, I wonder if there's something like a module decorator. I could use it in debugging a large highly dynamical program. thanks, Stef Mientki From andrew at acooke.org Sun Jan 18 07:58:41 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 04:58:41 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: On Jan 18, 9:56?am, andrew cooke wrote: > either i have misundertstood you ah, i see your point. sorry, andrew From stef.mientki at gmail.com Sun Jan 18 07:59:55 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 13:59:55 +0100 Subject: is there something like a module decorator ? Message-ID: <497327CB.9020705@gmail.com> hello, I wonder if there's something like a module decorator. I could use it in debugging a large highly dynamical program. thanks, Stef Mientki From deets at nospam.web.de Sun Jan 18 08:06:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 14:06:46 +0100 Subject: is there something like a module decorator ? In-Reply-To: References: Message-ID: <6tgnr6FapcohU1@mid.uni-berlin.de> Stef Mientki schrieb: > hello, > > I wonder if there's something like a module decorator. > I could use it in debugging a large highly dynamical program. No, there isn't. This has been discussed a while ago: http://groups.google.de/group/comp.lang.python/browse_thread/thread/215216a1e13ba2c6 Diez From stef.mientki at gmail.com Sun Jan 18 08:17:33 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 18 Jan 2009 14:17:33 +0100 Subject: is there something like a module decorator ? In-Reply-To: <6tgnr6FapcohU1@mid.uni-berlin.de> References: <6tgnr6FapcohU1@mid.uni-berlin.de> Message-ID: <49732BED.302@gmail.com> Diez B. Roggisch wrote: > Stef Mientki schrieb: >> hello, >> >> I wonder if there's something like a module decorator. >> I could use it in debugging a large highly dynamical program. > > No, there isn't. This has been discussed a while ago: > > http://groups.google.de/group/comp.lang.python/browse_thread/thread/215216a1e13ba2c6 > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list thanks for the information. cheers, Stef From gert.cuykens at gmail.com Sun Jan 18 08:37:38 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 18 Jan 2009 05:37:38 -0800 (PST) Subject: bin = FieldStorage(fp=environ['wsgi.input'], environ=environ) Message-ID: in python3.0 this does not work File "/usr/python/lib/python3.0/email/feedparser.py", line 99, in push data, self._partial = self._partial + data, TypeError: Can't convert 'bytes' object to str implicitly So what do i need to wrap around environ['wsgi.input'] so it does work ? From andrew at acooke.org Sun Jan 18 08:49:08 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 05:49:08 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <7ef985f3-bd3f-4dff-b138-84608604d79d@x14g2000yqk.googlegroups.com> http://bugs.python.org/issue4986 Sorry for the noise, Andrew From castironpi at gmail.com Sun Jan 18 08:58:26 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 05:58:26 -0800 (PST) Subject: Relax Syntax for Augmented Arithmetic? References: <64eaf3de-848a-4d6f-bf8e-29b16dfb9b68@v15g2000vbb.googlegroups.com> <6tgmanFaq2t9U1@mid.uni-berlin.de> Message-ID: <818a4683-a467-40d4-b4d0-70cac14a6de0@35g2000pry.googlegroups.com> On Jan 18, 6:56?am, andrew cooke wrote: > On Jan 18, 9:40?am, Marc 'BlackJack' Rintsch wrote: > > > On Sun, 18 Jan 2009 04:24:04 -0800, andrew cooke wrote: > > > my argument was that *= is not treated as = and *, but as a completely > > > new operator (the docs even say that the implementation need not return > > > self which suggests some pretty extreme semantics were envisaged). > > > What do you mean by "suggests ? extreme semantics"? ?Most natural thing > > is to use numbers and there you *have* to be able to return something > > different than `self` to get anything useful. ?For instance: > > > ?n *= 3 > > > with `n` bound to a number different from zero can't return `self` from > > `__imul__`. > > in your example, n is not a number, it is a mutable variable, and its > value changes. > > when n is an instance implementing __imul__ the natural analogue is > that the internal state of the instance changes. > > either i have misundertstood you, or you have misunderstood __imul__, > or you are treating = as equality, or maybe you are thinking of a pure > language that creates new instances? ?python is impure. > > anyway, my original request is moot. ?i was assuming that this was a > "capricious" restriction. ?in fact it's related to what i thought were > operators actually being assignments, and so no change is possible > (until python 4.0 when guido will finally see the light and move to s- > expressions, at which point everyone will stop using the language ;o) > > andrew Not sure if this ties in, but: >>> ['a'].__imul__(2) ['a', 'a'] From Russ.Paielli at gmail.com Sun Jan 18 09:01:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 18 Jan 2009 06:01:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <97d6929a-e82f-4021-95fe-a1f19282f1f1@v39g2000pro.googlegroups.com> Wow! That was an instant classic! I just have a couple of points to add. The suggestion was made (not by you) that data hiding is worthless because it can be defeated anyway. According to that kind of reasoning, locks are worthless because they can be picked, cut, or just blown off. I know that the lock on my front door cannot stop someone who is determined to get into my house, but I think I'll keep it anyway. I'm just irrational that way, I guess. As I said before, I don't know if enforced data hiding can be added to Python without ruining the language (or if it can be added at all, for that matter). But if it can, I think the cleanest and most elegant syntax would be to add the keyword "private" or "priv" and use it essentially the same way it is used in Java, C++, and now Scala. That would eliminate the need for leading underscores, which I personally find tacky. Since new attributes can be added outside of the constructor, the private declaration would also have to be allowed outside the constructor and for existing attributes. One more thing. If an airplane is going to flip upside down and fly straight into the ground, the passengers may as well be nuns. They are better prepared for the result. From reckoner at gmail.com Sun Jan 18 09:19:03 2009 From: reckoner at gmail.com (Reckoner) Date: Sun, 18 Jan 2009 06:19:03 -0800 (PST) Subject: function argument dependent on another function argument? Message-ID: I would like to do: def foo(self,x,y=self.a) where the default value for y=self.a. Since this is not possible, I wind up doing def foo(self,x,y=None) if not y: y=self.a but that seems kind of clumsy. Is there a better way to do this? Thanks in advance From delroth at gmail.com Sun Jan 18 09:32:19 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Sun, 18 Jan 2009 15:32:19 +0100 Subject: output problem In-Reply-To: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> References: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC47@frsnprexc1.usr.ingenico.loc> Message-ID: <1ba9eaed0901180632y32aedfddpd0a27289c1da2026@mail.gmail.com> IIRC, Windows automatically add a newline after the program output. On Fri, Jan 16, 2009 at 4:24 PM, Jean-Paul VALENTIN wrote: > Feature? the output of below Hello program he0.py started from command > line looks as follows: > F:\prompt>he0.py > Hello > F:\prompt> > > 'Hello' was sent with sys.stdout.write, so "without newline". > But why cannot be output (more logically): > F:\prompt>he0.py > HelloF:\prompt> > > Is it normal? Is there any means or workaround to obtain that output if > I wish?? > ________________________________________________________________________ > ______________________ > #!/usr/bin/python > #-*- coding: iso-8859-15 -*- > import sys > sys.stdout.write('Hello') > > > About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. > This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. > P Please consider the environment before printing this e-mail > > > -- > http://mail.python.org/mailman/listinfo/python-list > From alan.isaac at gmail.com Sun Jan 18 09:36:15 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sun, 18 Jan 2009 14:36:15 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: >>> Alan G Isaac wrote: >>>> Is it intentional that ``exec`` cannot handle a TextIOWrapper? >>>> Bottom line: has ``execfile(filename)`` really become >>>> ``exec(open(filename).read())``? Is this a good thing? >> On 1/17/2009 4:20 PM Terry Reedy apparently wrote: >>> Yes. Yes. > Alan G Isaac wrote: >> OK. Why? On 1/17/2009 10:08 PM Terry Reedy apparently wrote: > This: execfile(filename) > is a trivial (9 keystroke) abbreviation of > this: exec(open(filename).read()) > which is similar in effect to > this: from filename import * > so it is really not needed. Well, that does not really answer my question, imo. I do not much care about the disappearance of ``execfile``. I was asking, why is it a **good thing** that ``exec`` does not accept a TextIOWrapper? Or is it just not implemented yet? What is the gain from this particular backwards incompatibility (in the sense that ``exec(open(fname))`` no longer works)? Context: I used to be able to tell students they could run their scripts from the interpreter prompt with ``execfile(fname)``. I expected to be able to tell them to ``exec( open(fname) )``, which worked in Python 2. Now instead it is ``exec( open(filename).read() )`` which is a bit more mysterious to a newbie. (Note: I teach economics, not computer science.) And despite your claim above, you know that ``import`` is not really equivalent, and even more so now that ``reload`` must be imported. Thanks, Alan Isaac From castironpi at gmail.com Sun Jan 18 09:41:31 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 06:41:31 -0800 (PST) Subject: function argument dependent on another function argument? References: Message-ID: <6bff986d-ad30-473d-aecf-cd0377437496@v5g2000pre.googlegroups.com> On Jan 18, 8:19?am, Reckoner wrote: > I ?would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I > wind up doing > > def foo(self,x,y=None) > ? if not y: > ? ? y=self.a > > but that seems kind of clumsy. > > Is there a better way to do this? > > Thanks in advance No. The only alternative is really niche and probably not what you want. You'd use a decorator (which I don't have, btw): @defval( y= selfattrget( 'a' ) ) def foo( self, x, y ). From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:06:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:06:58 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz1zjzp.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> Message-ID: <4973533a$0$23748$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Once again, there's quite a lot to learn from >> the story of Ariane 5. > > Do you know what actually happened with Ariane 5? *yes I do* - else I wouldn't mention it. Thanks. > The failure was > because "smart" humans overrode the language enforced protection by > casting a floating point number down to a 16-bit integer, which worked > ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger > numbers were involved. The failure was because a module tested, QA'd and certified within a given context (in which it was ok to drop the builtin error handling) was reused in a context where it was not ok. And the point is exactly that : no *technology* can solve this kind of problem, because it is a *human* problem (in that case, not taking time to repass the whole specs / tests / QA process given context change). From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:20:54 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:20:54 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> Message-ID: <4973567f$0$14315$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 17, 1:43 pm, Paul Rubin wrote: >> Bruno Desthuilliers writes: >>> Once again, there's quite a lot to learn from >>> the story of Ariane 5. >> Do you know what actually happened with Ariane 5? The failure was >> because "smart" humans overrode the language enforced protection by >> casting a floating point number down to a 16-bit integer, which worked >> ok in Ariane 4, but failed with an overflow on Ariane 5 where bigger > > So this turns out to be an example of a failure due, not to the > *rigidity* of Ada, but to its *permissiveness* in allowing such a > cast. Nope. This is an example of failure due to the *human* part of the process - this happened because of a lack of testing / QA, not because of a language feature or misfeature. (snip) >> This is one thing that Python gets right, automatically using bignums >> rather than allowing int overflow. In that sense, Python has more >> enforced protection than Ada. > > True, but Ada does not have the luxury of just using doubles and > "bignums" everywhere, because it needs to work on cheap processors > too. But perhaps it could somehow be configured to do so by the user > if sufficiently powerful computers are being used. Here the error was *not* to disable the overflow error checking (in the context of Ariane 4), but to reuse the module as-is in another context. As I already stated, no technology can protect us from this kind of error. Ask yourself why this module was reused as-is, instead of going thru the whole specs / tests / QA process again, and *perhaps* you'll start to understand why I say that language-enforced access restrictions are the wrong solution to a real problem. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:26:25 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:26:25 GMT Subject: function argument dependent on another function argument? References: Message-ID: <01834097$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 06:19:03 -0800, Reckoner wrote: > I would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I wind > up doing > > > def foo(self,x,y=None) > if not y: > y=self.a > > but that seems kind of clumsy. It's also incorrect, because if you pass y=0 as an argument, or any other false value, it will be replaced by self.a. > Is there a better way to do this? def foo(self, x, y=None): if y is None: y = self.a I don't find that clumsy in the least. I find it perfectly readable and a standard idiom. -- Steven From ra.ravi.rav at gmail.com Sun Jan 18 10:30:52 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 18 Jan 2009 07:30:52 -0800 (PST) Subject: Difference between Python 2.2.2 and Python 2.5 Message-ID: I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I know is Python 2.5 . Can you please tell me differences between the two so that I can save myself from incompatible code. From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:36:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:36:35 GMT Subject: Python 3: exec arg 1 References: Message-ID: <018342f9$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 14:36:15 +0000, Alan G Isaac wrote: > Well, that does not really answer my question, imo. I do not much care > about the disappearance of ``execfile``. I was asking, why is it a > **good thing** that ``exec`` does not accept a TextIOWrapper? I'm not sure if this is a stupid question or not, but what's a TextIOWrapper? In the example you give: exec(open(fname)) the argument to exec -- open(fname) -- is a file object: >>> type(open('hello.py')) BTW, exec is a statement. The brackets there are totally superfluous. You can, and should, write: exec open(fname) > Or is it just not implemented yet? > What is the gain from this particular backwards incompatibility (in the > sense that ``exec(open(fname))`` no longer works)? Simplicity of implementation? > Context: I used to be able to tell students they could run their scripts > from the interpreter prompt with ``execfile(fname)``. I expected to be > able to tell them to ``exec( open(fname) )``, which worked in Python 2. > Now instead it is ``exec( open(filename).read() )`` which is a bit more > mysterious to a newbie. (Note: I teach economics, not computer > science.) Why don't you give your students a site.py module containing def execfile(fname): exec open(fname).read() and tell them to do "from site import execfile"? If you control the environment they are running their programs on (school computers?) then you can put a startup file in their path and have execfile imported automatically. -- Steven From http Sun Jan 18 10:36:53 2009 From: http (Paul Rubin) Date: 18 Jan 2009 07:36:53 -0800 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def foo(self, x, y=None): > if y is None: > y = self.a > > I don't find that clumsy in the least. I find it perfectly readable and a > standard idiom. That has the same problem as the earlier version. If the person passes None, they get self.a. I prefer: sentinel = object() ... def foo(x, y=sentinel): if y is sentinel: y = self.a From bbxx789_05ss at yahoo.com Sun Jan 18 10:40:20 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Sun, 18 Jan 2009 07:40:20 -0800 (PST) Subject: output problem References: Message-ID: <84d6d0c6-3b1b-4579-b16d-f8238f7f1a41@g3g2000pre.googlegroups.com> On Jan 16, 8:24?am, "Jean-Paul VALENTIN" wrote: > Feature? the output of below Hello program he0.py started from command > line looks as follows: > F:\prompt>he0.py > Hello > F:\prompt> > > 'Hello' was sent with sys.stdout.write, so "without newline". > But why cannot be output (more logically): > F:\prompt>he0.py > HelloF:\prompt> > > Is it normal? Is there any means or workaround to obtain that output if > I wish?? > ________________________________________________________________________ > ______________________ > #!/usr/bin/python > #-*- coding: iso-8859-15 -*- > import sys > sys.stdout.write('Hello') > Not on a Mac: import sys sys.stdout.write("hello") output: $ python 6test.py hello$ From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 10:44:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 15:44:02 GMT Subject: Difference between Python 2.2.2 and Python 2.5 References: Message-ID: <018344b9$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I > know is Python 2.5 . > > Can you please tell me differences between the two so that I can save > myself from incompatible code. Everything new mentioned here: http://www.python.org/doc/2.5/whatsnew/whatsnew25.html http://www.python.org/doc/2.4/whatsnew/whatsnew24.html http://www.python.org/doc/2.3/whatsnew/whatsnew23.html won't exist in Python 2.2. -- Steven From luismgz at gmail.com Sun Jan 18 10:46:16 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 18 Jan 2009 07:46:16 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Jan 18, 8:56?am, andrew cooke wrote: > Since this is a PyPy bashing thread, maybe it's an appropriate place > to suggest that the project has got a little bit waylaid by exploring > cool things instead of releasing a useful final result? > > I am not questioning rpython directly - the case for something like > that is obvious. ?But there's a question of balance. ?It's possible to > go on building ever more complex systems which are theoretically > justified, but which postpone ever finishing the job. ?At some point > there has to be a "good enough". > > To some extent I am playing devil's advocate here, but as an outside > who looked at PyPy a while back, my uninformed and naive impression > was that the project was suffering from the kid of issues I have > caricatured above.... > > Andrew > > PS I guess you are aware of worse is better etc? ?I think this may > also be a US/Euro culture issue... It's worth adding that, regarding the goal of having a faster python, we have had for a long time a solid and useful proof-of-concept in psyco. Pypy rolls up on this concept and adds many more useful features, not all of them related to speed but to flexibility. I have no doubt the project will be succesful. The question is how long we will have to wait... Luis From castironpi at gmail.com Sun Jan 18 10:49:29 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 07:49:29 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> On Jan 18, 9:36?am, Paul Rubin wrote: > Steven D'Aprano writes: > > def foo(self, x, y=None): > > ? ? if y is None: > > ? ? ? ? y = self.a > > > I don't find that clumsy in the least. I find it perfectly readable and a > > standard idiom. > > That has the same problem as the earlier version. ?If the person > passes None, they get self.a. ?I prefer: > > ? ? sentinel = object() > ? ? ... > > ? ? def foo(x, y=sentinel): > ? ? ? if y is sentinel: > ? ? ? ? ? y = self.a It is too bad that it is so much work to detect whether 'y' was passed in the function call directly. However, sentinel is just as good (or nearly); at worst, you need one sentinel per argument per function, which is possible to create, which has a specific meaning. If you are making systematic function calls, e.g. with a dictionary or list, you can just use the sentinel in the dictionary. From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:49:51 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:49:51 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> Message-ID: <49735d48$0$3516$426a74cc@news.free.fr> Russ P. a ?crit : > No one ever claimed that a programming language, no matter how > rigorous, can eliminate all bugs. All a language can do is to reduce > their rate of occurrence. > > The Ariane fiasco was not a failure of Ada per se but rather a failure > of people using Ada. Almost right. > They attempted to re-use software written for one > rocket for another without proper testing. No language can prevent > that sort of error. Now this is plain right. > We can argue forever about the usefulness of language-enforced > restriction of access to private data and methods. I have no doubt > whatsoever that it is very useful at least for the extreme cases of > very large, safety-critical systems. And my POV is that it's just plain useless. > If you don't think access to > private data needs to be restricted for control of strategic nuclear > arsenals, for example, I think you're crazy, but that's just my > opinion. If you think that this kind of access restriction makes softwares controling strategic nuclear arsenal any safer, then *you* are totally crazy. As *you* stated above, "no language can prevent this kind of error". > The only reasonable question in my mind is where the line should be > drawn between systems that should have enforced restrictions and those > that can rely on coding standards and voluntary cooperation among > programmers. The only reasonable question in *my* mind is whether you think it's better, specially for safety-critical stuff, to hire people you can trust or to rely on technology. > A while back, I read something about the final integration of the > flight software on the Boeing 777, which was written mainly in Ada. > The claim was made that this integration took only three days, whereas > normally it would be expected to take more like three months with a > less rigorous language such as C++. The reason for the simplified > integration is that Ada enforces interfaces and prevents access to > private data and methods. C++ does it too. Or at least, that's a very common "claim" about C++. > Apparently such enforcement can improve the > efficiency of software production -- and that's not just in "theory." My own experience is that too much rigidity in a language only leads to more boilerplate code and more workarounds (design patterns anyone ?), IOW more accidental complexity, hence more space for bugs to creep in. My very humble (no don't say it) opinion about this is that what's important is how you handle and manage the whole project (including both technical and non-technical aspects), not the technology used (which might be relevant - I of course wouldn't use Python for anything real-time - or not - most of the monstruogigantic "entreprise" software written in Java would work just as well in Python or any other decent language). No technology will prevent human errors - I think this point is clear, and that we both agree on it. OTHO, some technologies can at least help reducing the opportunities for human errors - and I think we also agree on this. Now the point is : *how* can a given techno helps wrt/ this second goal. Here you have two philosophies. One is that you'll reduce errors by improving simplicity and readability, and by promoting trust (whithin the team), sense of responsabily, and communication. The other one is that you'll reduce errors by not allowing those stupid code-monkeys to do anything that *might* (according mostly to unproved assertions) be "dangerous" - hence promoting distrust and irresponsability, and adding quite a lot of accidental complexity. BTW, do you know the by far most common Java idiom ? It's named the "do-nothing catch-all exception handler". As an excercise, explain the reasons behind this idiom, and it's practical results. As a last point : I certainly don't think Python is perfect in any way, *nor* that it's the appropriate tool for each and any project. I just disagree with you on your assertion that Python is not ok for large or critical projects because of it's "lack" of language-enforced access restriction. From fairwinds.dp at gmail.com Sun Jan 18 10:52:29 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Sun, 18 Jan 2009 11:52:29 -0400 Subject: Ordering attributes for dynamically generated class Message-ID: Hi list. I use 'type' to generate classes but have a need to order the attributes for the generated class. Of course a dict is not going to maintain ordering. Is there any way to dynamically generate a class with attributes in specific order? my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) Many thanks, David From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 10:53:48 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 16:53:48 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <6ec4f863-4795-4c63-9eb9-8fa580bd243c@w39g2000prb.googlegroups.com> Message-ID: <49735e35$0$21820$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 17, 11:49 am, Bruno Desthuilliers > wrote: > >> Please educate yourself and learn about why Ariane 5 crashed on it's >> first flight, due to an error in a module written in ADA (which is such >> a psychorigid language that C++ and Java are even looser than Javascript >> in comparison). Perhaps will it light a bulb for you. > > The claim here regarding the Ariane 5 failure is one of those urban > myths that refuses to die. You failed the test. Sorry. > It has been refuted over and over What has been refuted exactly ? > (including on this thread already), but I would just like to add > something in defense of Ada. > > Studies have found that Ada reduces both bugs and long-term > development costs by something like a factor of two compared to C. This _might_ (or not - there are too many variables to get any scientific certitudes here) be true. But that was not the point. See my other posts here for more about it. From jfabiani at yolo.com Sun Jan 18 10:54:06 2009 From: jfabiani at yolo.com (John Fabiani) Date: Sun, 18 Jan 2009 07:54:06 -0800 Subject: Am I interacting with the database correctly? References: Message-ID: Hussein B wrote: > Hey, > I'm new with database interactions in Python and I'm not sure if I'm > handling the cursor and transactions correctly: > ++++++++ > cursor = db.cursor(MySQLdb.cursors.DictCursor) > cursor.execute(flate_rate_pkgs_sql) > rows = cursor.fetchall() > #I have for loop here to iterate over rows > cursor.execute() > rows = cursor.fetchall() > # some more cursor.execute() calls but only SQL select statements > # here is another for loop that contains try block > # here are cursor.execute() calls, both insert and update > db.commit() > # in the except code block, I use db.rollback() > ++++++++ > As you see, my script contains only one db object and one cursor > object and both the db and cursor objects are used multiple times, it > is ok? > As you might figured, this is a script for reports :) > Thanks. I have never worked with MySQL. I do work with others. The first part looks fine. If you insert, update or delete then you need a 'commit' or a 'rollback'. Preparing data for a report it is unlikely that you need to commit or rollback anything. After all you are only using 'select'. John From castironpi at gmail.com Sun Jan 18 10:57:15 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 07:57:15 -0800 (PST) Subject: Ordering attributes for dynamically generated class References: Message-ID: On Jan 18, 9:52?am, David Pratt wrote: > Hi list. I use 'type' to generate classes but have a need to order ? > the attributes for the generated class. Of course a dict is not going ? > to maintain ordering. Is there any way to dynamically generate a ? > class with attributes in specific order? > > my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) > > Many thanks, > David Just a thought, you can subclass 'dict' and assign an instance of it to the __dict__ member of your new instance. From vedrandekovic at yahoo.com Sun Jan 18 11:09:02 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 18 Jan 2009 08:09:02 -0800 (PST) Subject: Python and threads Message-ID: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Hello again, Thanks for previous help on "Start two threads in same time" it was useful,but when I run this two threads, I think they don't start at the same time, here is my code snippet: import threading class ThreadedClass1(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): a=True while a==True: bm=my_module.MyClass() a=bm.get_Python_Process_Usage_Function() #Returns True or False class ThreadedClass2(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): os.popen("my_python_script.py") threaded_obj = ThreadedClass1() threaded_obj.start() threaded_obj2 = ThreadedClass2() threaded_obj2.start() Regards, John From thorsten at thorstenkampe.de Sun Jan 18 11:18:15 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 18 Jan 2009 17:18:15 +0100 Subject: process command line parameter References: <466c8549-93ba-4048-b734-c2bbd26ce57e@t26g2000prh.googlegroups.com> Message-ID: * asit (Sat, 17 Jan 2009 13:28:12 -0800 (PST)) > Recently I was coding a link extractor. It's a command line stuff and > takes parameter as argument. > I found that the in operator is not always helpful. > eg. if "--all" in sys.argv: > print "all links will be printed" > > its not helpful when some attribute value is sent in command line > parameter. > hence I want to process some data like find=".co.uk" > > How can i do this ??? Use optparse From duncan.booth at invalid.invalid Sun Jan 18 11:24:16 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Jan 2009 16:24:16 GMT Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> Message-ID: alex23 wrote: > I must confess I've rarely had a need to use __import__ and don't > think I've ever used the fromlist arg. I'm confused, though, because > the docstring states: > > The fromlist should be a list of names to emulate ``from name > import ...'' > > But it also states that __import__ always returns a module, so I'm > utterly confused as to the purpose of fromlist, or how to inject the > specified entries into the calling namespace. If anyone could explain > this for me, I'd really appreciate it. Compare these: >>> dom = __import__('xml').dom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'dom' >>> dom = __import__('xml', fromlist=['dom']).dom >>> dom Then in a new session: >>> import xml >>> xml.dom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'dom' >>> from xml import dom >>> dom >>> When you import a package such as xml it only imports the top level. Modules and subpackages within the imported package aren't available until they are explicitly imported. The fromlist argument to __import__ allows you to force the lower modules to also import. >>> xml = __import__('xml', fromlist=['dom']) is effectively the same as doing: >>> import xml.dom After either of these you have a name 'xml' which has an attribute 'dom': >>> xml.dom To access the actual sub-objects using __import__ use getattr on the returned module. So far as injecting names into the calling namespace is concerned just assign to variables; you don't want to be injecting unknown names into your namespace. For the same effect if you only have one name and you know it is a module you could do: >>> xml = __import__('xml.dom') but you need the fromlist parameter if you don't know which of the names are modules. From http Sun Jan 18 11:25:21 2009 From: http (Paul Rubin) Date: 18 Jan 2009 08:25:21 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> Message-ID: <7xmydomvim.fsf@ruckus.brouhaha.com> "Russ P." writes: > I don't know which variant of Ada was used here, but something called > the "Ravenscar Profile" is a reduced subset of Ada that might have > prevented this error (though I haven't verified this). Then there is > Spark Ada, which supposed to be much safer than even Ada. I'm not sure, but I think Ravenscar and Spark would both have permitted the cast. However, Spark is intended to be used with an external tool called Spade (sort of a Pylint on steroids) that would not have allowed the cast unless it was provable (starting from the specification) that the number was in range before the cast. I.e. the cast was wrong because of the failure of an unstated assumption that a certain sensor reading was in a certain range. Spark may still have allowed the cast only if the assumption was stated explicitly in the specification. Requiring the assumption to be stated may have made the error more likely to be spotted as part of the surrounding systems engineering. Of course, the specification can still be wrong, but that's hardly a problem with Ada or even with the software. It's not too much different than if the specification says the rocket is 10 feet wide and they build the launch pad for that size, but then the rocket turns out to actually be 12 feet wide. I have Barnes's book about Spark at the office and will try to check next week what it says about these casts. From fairwinds.dp at gmail.com Sun Jan 18 11:26:22 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Sun, 18 Jan 2009 12:26:22 -0400 Subject: Ordering attributes for dynamically generated class In-Reply-To: References: Message-ID: Hi Aaron. Yeah, definitely sounds like a possibility. I was able to locate an ordered dict implementation that subclasses dict. This might work fine. Might be able to pass into type method directly since I think that dict passed into type is setting __dict__ I believe. Let you know if that works out. Many thanks. Regards, David On Jan 18, 2009, at 11:57 AM, Aaron Brady wrote: > On Jan 18, 9:52 am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order >> the attributes for the generated class. Of course a dict is not going >> to maintain ordering. Is there any way to dynamically generate a >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, >> dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > -- > http://mail.python.org/mailman/listinfo/python-list From http Sun Jan 18 11:30:03 2009 From: http (Paul Rubin) Date: 18 Jan 2009 08:30:03 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <4973567f$0$14315$426a34cc@news.free.fr> Message-ID: <7xiqocmvas.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > As I already stated, no technology can protect us from this kind of > error. Ask yourself why this module was reused as-is, instead of going > thru the whole specs / tests / QA process again, and *perhaps* you'll > start to understand why I say that language-enforced access > restrictions are the wrong solution to a real problem. I have not seen anywhere that the specs stated that the sensor reading that overflowed that variable was supposed to be in range. It looks to me (but I don't know for sure) that the development process allowed an assumption to creep into the code that wasn't stated in the specs. From stefan_ml at behnel.de Sun Jan 18 11:40:22 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 17:40:22 +0100 Subject: changing URLs in webpages, python solutions? In-Reply-To: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> Message-ID: <49735b76$0$31867$9b4e6d93@newsspool3.arcor-online.net> Simon Forman wrote: > I want to take a webpage, find all URLs (links, img src, etc.) and > rewrite them in-place, and I'd like to do it in python (pure python > preferred.) lxml.html has functions specifically for this problem. http://codespeak.net/lxml/lxmlhtml.html#working-with-links Code would be something like html_doc = lxml.html.parse(b"http://.../xyz.html") html_doc.rewrite_links( ... ) print( lxml.html.tostring(html_doc) ) It also handles links in CSS or JavaScript, as well as broken HTML documents. Stefan From ericcire at gmail.com Sun Jan 18 11:41:10 2009 From: ericcire at gmail.com (Eric) Date: Sun, 18 Jan 2009 08:41:10 -0800 (PST) Subject: calling an external program and capturing the output Message-ID: Coming from a perl background I'm new to the Python world. I need to read a list of values, send each value to an external program and capture and act on the output of that program. Reading and parsing the initial values is not a problem but I can't seem to find anything on the sending to and capturing from an external program. Any suggestions would be greatly appreciated. -Eric From stefan_ml at behnel.de Sun Jan 18 11:42:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 17:42:49 +0100 Subject: Python and threads In-Reply-To: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Message-ID: <49735c09$0$31867$9b4e6d93@newsspool3.arcor-online.net> vedrandekovic at yahoo.com wrote: > Thanks for previous help on "Start two threads in same time" it was > useful,but when I run this > two threads, I think they don't start at the same time That's normal. Threading is an unpredictable concurrency pattern. Things often don't happen the way one would want them to. Stefan From rtw at freenet.co.uk Sun Jan 18 11:44:23 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 10:44:23 -0600 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> Message-ID: Aaron Brady wrote in news:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh.googlegroups.com in comp.lang.python: > On Jan 18, 9:36?am, Paul Rubin wrote: >> Steven D'Aprano writes: >> > def foo(self, x, y=None): >> > ? ? if y is None: >> > ? ? ? ? y = self.a >> >> > I don't find that clumsy in the least. I find it perfectly readable >> > and > a >> > standard idiom. >> >> That has the same problem as the earlier version. ?If the person >> passes None, they get self.a. ?I prefer: >> >> ? ? sentinel = object() >> ? ? ... >> >> ? ? def foo(x, y=sentinel): >> ? ? ? if y is sentinel: >> ? ? ? ? ? y = self.a > > It is too bad that it is so much work to detect whether 'y' was passed > in the function call directly. However, sentinel is just as good (or > nearly); at worst, you need one sentinel per argument per function, One per Module should be good enough. The only reason None doesen't suffice is that it has other legitimate uses. Though to be honest I would always use None as the sentinel if it wasn't a legitimate argument. > which is possible to create, which has a specific meaning. If you are > making systematic function calls, e.g. with a dictionary or list, you > can just use the sentinel in the dictionary. IIUYC then, one sentinel is still only needed as the missing argument is indicated by *both* position and value or by name and value (in the case of a keyword-dictionary), so seperate distinct sentinel objects aren't required, for example: SENTINEL = object() def f( a, b, c = SENTINEL, d = SENTINEL ): print( "values: %r" % ( ( a, b, c, d ), ) ) if c is SENTINEL: print( "c is missing" ) if d is SENTINEL: print( "d is missing" ) f( *( 1, 2, SENTINEL, SENTINEL ) ) f( **dict( a = 1 , b = 2, d = 4 ) ) f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) Rob. -- http://www.victim-prime.dsl.pipex.com/ From duncan.booth at invalid.invalid Sun Jan 18 11:45:24 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Jan 2009 16:45:24 GMT Subject: Ordering attributes for dynamically generated class References: Message-ID: Aaron Brady wrote: > On Jan 18, 9:52?am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order ? >> the attributes for the generated class. Of course a dict is not going ? >> to maintain ordering. Is there any way to dynamically generate a ? >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > You can certainly pass a subclass of 'dict' to type(), in fact in Python 3.0 you can use a metaclass with a __prepare__ method to substitute your own value for __dict__ in any class definition, but I don't think your own type will preserved when the instance is actually constructed. A simple solution which works in any version of Python is just to maintain an attribute with the desired ordering and override __dir__ to return the attributes in that order. From deets at nospam.web.de Sun Jan 18 11:48:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 17:48:49 +0100 Subject: Python and threads In-Reply-To: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> Message-ID: <6th4riFat1vuU1@mid.uni-berlin.de> vedrandekovic at yahoo.com schrieb: > Hello again, > > Thanks for previous help on "Start two threads in same time" it was > useful,but when I run this > two threads, I think they don't start at the same time, here is my > code snippet: > > > import threading > > class ThreadedClass1(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > a=True > while a==True: > bm=my_module.MyClass() > a=bm.get_Python_Process_Usage_Function() #Returns True > or False > > class ThreadedClass2(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > os.popen("my_python_script.py") > > > > threaded_obj = ThreadedClass1() > threaded_obj.start() > threaded_obj2 = ThreadedClass2() > threaded_obj2.start() If you want to synchronize two or more threads, you need to do so manually using objects like Locks, Events, Conditions and Semaphores. See the threading module. Even if you managed to get two threads started simultaneously (which the OS doesn't even offer IINM), the would soon run out of sync. How about you tell us what you *want*, and we tell you if and how it's possible to do that. Diez From deets at nospam.web.de Sun Jan 18 11:49:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 17:49:06 +0100 Subject: calling an external program and capturing the output In-Reply-To: References: Message-ID: <6th4s2Fat1vuU2@mid.uni-berlin.de> Eric schrieb: > Coming from a perl background I'm new to the Python world. I need to > read a list of values, send each value to an external program and > capture and act on the output of that program. Reading and parsing the > initial values is not a problem but I can't seem to find anything on > the sending to and capturing from an external program. > > Any suggestions would be greatly appreciated. See the module subprocess. Diez From rtw at freenet.co.uk Sun Jan 18 12:06:10 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 11:06:10 -0600 Subject: Python 3: exec arg 1 References: <018342f9$0$8693$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote in news:018342f9$0$8693$c3e8da3 at news.astraweb.com in comp.lang.python: > I'm not sure if this is a stupid question or not, but what's a > TextIOWrapper? In the example you give: > > exec(open(fname)) > > the argument to exec -- open(fname) -- is a file object: > >>>> type(open('hello.py')) > > > > BTW, exec is a statement. The brackets there are totally superfluous. > You can, and should, write: > > exec open(fname) > You must have missed the subject line: "Re: Python 3: exec arg 1" Python 3.0 (r30:67507, Dec 3 2008, 19:44:23) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> open( "hello.py" ) >>> exec "a = 1" File "", line 1 exec "a = 1" ^ SyntaxError: invalid syntax >>> exec( "a = 1" ) >>> a 1 >>> Rob. -- http://www.victim-prime.dsl.pipex.com/ From gagsl-py2 at yahoo.com.ar Sun Jan 18 12:09:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 15:09:01 -0200 Subject: Am I interacting with the database correctly? References: Message-ID: En Sun, 18 Jan 2009 13:54:06 -0200, John Fabiani escribi?: > I have never worked with MySQL. I do work with others. The first part > looks fine. If you insert, update or delete then you need a 'commit' or > a 'rollback'. Preparing data for a report it is unlikely that you need > to > commit or rollback anything. After all you are only using 'select'. Note that you have to commit/rollback a transaction *even* if you only execute select statements - at least when using isolation levels higher than "read uncommited". By example, using "repeatable reads", a "select" on table A blocks any attempt to modify the involved rows until the transaction ends. And using "read commited", it won't see rows modified or added after the transaction began. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 12:09:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 15:09:01 -0200 Subject: Am I interacting with the database correctly? References: Message-ID: En Sun, 18 Jan 2009 13:54:06 -0200, John Fabiani escribi?: > I have never worked with MySQL. I do work with others. The first part > looks fine. If you insert, update or delete then you need a 'commit' or > a 'rollback'. Preparing data for a report it is unlikely that you need > to > commit or rollback anything. After all you are only using 'select'. Note that you have to commit/rollback a transaction *even* if you only execute select statements - at least when using isolation levels higher than "read uncommited". By example, using "repeatable reads", a "select" on table A blocks any attempt to modify the involved rows until the transaction ends. And using "read commited", it won't see rows modified or added after the transaction began. -- Gabriel Genellina From castironpi at gmail.com Sun Jan 18 12:16:28 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 09:16:28 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> Message-ID: <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> On Jan 18, 10:44?am, Rob Williscroft wrote: > Aaron Brady wrote innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 9:36?am, Paul Rubin wrote: > >> Steven D'Aprano writes: > >> > def foo(self, x, y=None): > >> > ? ? if y is None: > >> > ? ? ? ? y = self.a > > >> > I don't find that clumsy in the least. I find it perfectly readable > >> > and > > ?a > >> > standard idiom. > > >> That has the same problem as the earlier version. ?If the person > >> passes None, they get self.a. ?I prefer: > > >> ? ? sentinel = object() > >> ? ? ... > > >> ? ? def foo(x, y=sentinel): > >> ? ? ? if y is sentinel: > >> ? ? ? ? ? y = self.a > > > It is too bad that it is so much work to detect whether 'y' was passed > > in the function call directly. ?However, sentinel is just as good (or > > nearly); at worst, you need one sentinel per argument per function, > > One per Module should be good enough. The only reason None doesen't > suffice is that it has other legitimate uses. ?Though to be honest > I would always use None as the sentinel if it wasn't a legitimate > argument. > > > which is possible to create, which has a specific meaning. ?If you are > > making systematic function calls, e.g. with a dictionary or list, you > > can just use the sentinel in the dictionary. > > IIUYC then, one sentinel is still only needed as the missing argument > is indicated by *both* position and value or by name and value (in the > case of a keyword-dictionary), so seperate distinct sentinel objects > aren't required, for example: > > SENTINEL = object() > > def f( a, b, c = SENTINEL, d = SENTINEL ): > ? print( "values: %r" % ( ( a, b, c, d ), ) ) > ? if c is SENTINEL: > ? ? print( "c is missing" ) > ? if d is SENTINEL: > ? ? print( "d is missing" ) > > f( *( 1, 2, SENTINEL, SENTINEL ) ) > > f( **dict( a = 1 , b = 2, d = 4 ) ) > > f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > > Rob. > --http://www.victim-prime.dsl.pipex.com/ I don't have a concrete example, so you may prove to be right, but I'm not convinced. If you have one function with an argument that defaults to an empty list, and calls another with an argument that defaults to an empty dict, then what is the meaning of passing sentinel to the first one? Whereas, if each had their own, then passing the first one's default would mean the empty list, and passing the second one's default would mean the dict. (Or, even if that evaluates correctly, perhaps there is no such useful program.) From bdesth.quelquechose at free.quelquepart.fr Sun Jan 18 12:22:06 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 18 Jan 2009 18:22:06 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0182b484$0$8693$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <497372e7$0$23747$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > >> Russ P. a ?crit : (snip) > >>> Why leave to >>> coding standards and company policy what can be encoded right into the >>> language? >> Because human are smarter than computers. > > That's an awfully naive statement. It's a sound-byte instead of a > reasoned argument. We're smarter than computers? Obviously and definitively, yes. Not that we are that smart - it's just that computers are totally stupids. The differences between a human and a computer are that 1/ a human can eventually DWIM. 2/ a computer can do what is has been told way faster than any human The first point is being smart. The second is being fast. Not quite the same thing !-) > Then why are we > programming in languages like Python instead of directly in machine code? > Why can optimizing C compilers make more efficient code than the best > human assembly language programmers? Because : 1/ this is something that can be solved by heavy computations 2/ these computations can be programmed 3/ these compuations would just take too long for a human being to do manually > Humans and computers are smart at different things. s/smart/good/g >>> Why leave to humans (who are known to err) what can be automated >>> relatively easily? Isn't that what computers are for? >> Error is human. For a real catastrophic failure, it requires a computer. > > Oh rubbish. That's a sound-byte invented by nervous technophobes scared > of computers. Nope, that's a computer-user joke. > >>> All those "setters" and >>> "getters" are a kludge. I think Python "properties" are a major step >>> forward here. Just for fun, I checked to see if Scala has properties. >>> Guess what? Not only does it have them, but they are generated >>> automatically for all member data. That's even better than Python >>> properties! >> Oh yes ? "Better", really ? So it's better to have a language that >> automagically breaks encapsulation (requiring an additionnal level of >> indirection) than a language that do the right thing by default ? I'm >> afraid I missed the point ??? > > You certainly do. How do properties "break" encapsulation rather than > enforcing it? Properties by themselves are not the problem, quite on the contrary - as you say, they actually help wrt/ encapsulation. What breaks encapsulation is *automatic generation* for properties for *each and any* implementation attribute. Might as well just makes them all public attribute then. > > >>>>> As I said before, enforced encapsulation may not be appropriate for >>>>> every application, but it is definitely appropriate for some. >>>> No. It is appropriate for dummy managers hiring dummy programmers. The >>>> project's size and domain have nothing to do with it. >>> Let me try to be very clear here. We are dealing with two separate but >>> related issues. The first is whether data hiding should be added to >>> Python. >> No need to add it, it's already there : every name that starts with an >> underscore is hidden !-) > > That's not hidden. It's there in plain sight. Once again, I'm afraid you missed the joke - despite the smiley. >>> Whether it can be added without screwing up the language, I don't know. >>> If not, then so be it. That just limits the range of domains where >>> Python is suitable. >> That's just plain stupid. > > No it's not. It's *practical*. There are domains where *by law* code > needs to meet all sorts of strict standards to prove safety and security, > and Python *simply cannot meet those standards*. Oh, sorry. I was talking about *technical* issues, not about legal ones. IANAL... (snip) >>> I like to use the example of the flight software for a large commercial >>> transport aircraft, but many other examples could be given. How about >>> medical systems that control radiation therapy or chemotherapy? How >>> about financial systems that could take away your retirement account in >>> 1.5 milliseconds. Or how about the control software for the strategic >>> nuclear arsenals of the US or Russia? When you consider the sea, air, >>> and land-based components, I'm sure that's one hell of a lot of code! >> And ? Such systems have been written (and quite a lot are still running) >> with languages way more permissive than Python. You know, languages like >> C or assembly. > > Yes, and it is *hard* because the programmer has to worry about data > hiding *on his own*. Nope, it's hard because C and assembly are very low-level languages where you have to micro-manage each and everything. This has nothing to do with data hiding (unless you count memory management as data hiding ?) > One of my friends has worked for many years programming some pretty high- > powered banking software. Their approach is to move data-hiding into the > database, or the operating system. Cobol doesn't enforce encapsulation, > but the database and OS certainly do, with a permissions-based approach. Guess what ? Whatever the language (Cobol, Java, Python, or even VB), chances are such an application would be written using a RDBMS (not even addressing the point about OS). > Speaking of banking software, consider a typical banking application. It > may have dozens or hundreds of programmers working on it. It's too big > for any one person to understand all of it. Once deployed it may > potentially have access to hundreds of billions of dollars of other > people's money. Don't you imagine that one or two of these programmers > might be tempted to skim a little off the top? There have been some major failure on such applications written with "serious" languages like Java. Know the sooo common "catch-all do-nothing exception handler" idiom in Java ? > Data hiding is a good way of making sure that the guy writing the front > end can't just turn of the audit trail and transfer $60,000,000 into his > bank account. Man, you can't be serious ? Tell me this is a joke ? > >> Until you understand that *no technology is idiot-proof*, >> you'll get nowhere in "software engineering". > > I suspect that Russ has got a lot further in software engineering than > you have. Most of what is actually labelled as "software engineering" is snake oil. They're trying to sell you silver bullets. Now where's the werewolf? > No technology is failure proof. But there's no reason in the world why > most technology can't be idiot-proof. Televisions are idiot-proof, > because they protect people from casual mistakes. If televisions were > built according to the Python model, the internals of the TV would be > exposed, without even a cover. All the major parts would be plug-in > rather than soldered in, and there would be no cover over the parts that > were live. Every year, tens of thousands of people would electrocute > themselves fatally (because parts of the TV holds a massive charge for > days after you unplug them from the mains) but that would be okay, > because you never know when somebody might want to pull out the fly-back > transformer and replace it with a six ohm resistor. That sort of dynamism > is important! Really nice metaphor. Alas, there are limits to what you can do with metaphores. (snip remaining) > [...] >>> An FMS programmer could perhaps >>> decide to change the parameters of the engine controls, for example. >> Why on earth would he do something so stupid ? > > I'm sure he'd think he had a good reason. As you said, > > "Because sometimes you have a legitimate reason to do so and are ok to > deal with the possible issues." > > Maybe other people would disagree whether or not it was a legitimate > reason, or if he was OK dealing with the possible issues. > > Perhaps he needed the extra optimization of skipping the getter/setters. > Perhaps he needed it for testing, and somehow one thing led to another. > Who knows? > > It is strange that on the one hand you should insist that programmers > sometimes need to mess with internals, and on the other dismiss those who > do as "stupid". Your position is inconsistent. Nope. My position is quite clear : just don't do something *stupid*. For a definition of "stupid" that is indeed highly dependant on the context (which you snipped). > >>> To prevent that sort of thing from happening, the management could >>> decree that henceforth all "private" variable names will start with an >>> underscore. Problem solved, eh? >> Certainly not. The only way to solve such a problem is to fire this >> cretin. > > Again, we shouldn't enforce encapsulation and data hiding s/encapsulation//g We were talking about language-enforced access restriction. Not about encapsulation. > because there > are legitimate reasons for breaking it, but anyone who does break it is a > cretin. Not "anyone". Just those who do it where they obviously should not. And be sure that anyone cretin enough to mess with implementation *in the context mentioned by Russ* (context which, once again, you snipped) would find a "clever" way to do the same (or worse) in any language. You don't want such a smartass in your team, *specially* for critical stuff. > You have a very strange attitude. You have a very strange way of handling context. > Besides, it's not very practical. When you fire "the cretin", it has > consequences. Everyone else in the project has to work harder, My own experience is that firing an obvious cretin from a team leads to *less* work for the team - because then you don't have to re-read and rewrite all his code. > [...] >> Please educate yourself and learn about why Ariane 5 crashed on it's >> first flight, due to an error in a module written in ADA (which is such >> a psychorigid language that C++ and Java are even looser than Javascript >> in comparison). Perhaps will it light a bulb for you. > > Others have already pointed out that the error in the Ariane 5 rocket was > *human* error due to somebody messing with the internals, namely > defeating the compiler's default type checking. This was *not* an error *in the context* this module was designed (and tested, QAd etc) for. > I'd just like to ask: > Bruno, were you aware of the cause of the crash, Yes I was. Else I wouldn't have mention it. > and if not, why did you > raise the issue in the first place? Because the problem had nothing to do with technology. Only with not being serious on specs / tests / QA. Hence my point : it's not because a module has been written using a technology (rightly) known for it's security and robustness that you can get by with non-technical issues. > Did you think it was a compiler bug > that caused the crash? Do you think I am a newbie ? >>>>> Not >>>>> every door needs a lock, but certainly some do. >>>> You only need locks when you don't trust your neighbours. >>> Yeah, if you live in Nome, Alaska. >> Brillant. You obviously failed to understand the differences between >> "software engineering" and real life. When it comes to computers, the >> only doors I care closing are those which would let someone crack my >> computer. > > If only there was some way to know which bugs could let people crack our > computer and which bugs couldn't. > > Anyway, that's your choice. Personally, I'd much prefer my software not > to cause data loss, not to crash, not to DoS me, not to hang, and not to > generate bogus data, This is a different problem. Please don't mix bananas and screwdrivers. > >> But FWIW, I never close my car. And, in case you don't know, it's >> perfectly possible to access "private" members in Java (and, if you do >> have access to the source code, in C++ too). > > Yes, but it is more difficult. There's a larger psychological barrier. > It's easier to audit for such access, even in a large project. It > encourages a more careful attitude: "do I *really* need to mess with the > internals, or is there a safer way?". It forces the programmer to *think* > before doing something potentially dangerous. This is a beautiful dream. Reality is that either the guy is wise enough to not do something he know he shouldn't without due thinking and consideration, or he is dumb enough to do something he shouldn't one way or another. > This is why I wish eval and exec were in a module instead of built-ins. I do agree they shouldn't be builtins, but mostly because there are too few real use case for them to be builtins. (well, wrt/ exec, it's a statement to the problem is a bit different). > Suppose Python worked like this: > > >>>> class Parrot: > ... _private = 'spam' > ... >>>> p = Parrot() >>>> p._private = 'ham' > Traceback (most recent call last): > File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot >>>> from protection import unlock >>>> unlock(p)._private = 'ham' >>>> p._private > 'ham' > > > I don't know if this scenario is even possible in Python, It actually isn't, at least not without way too much overhead messing with call stack (and even then...). "Methods" need to freely access implementation attributes. But Python's "methods" are just wrappers around plain functions, which by themselves don't know (and shouldn't need to know) if they where defined within a class statement or not. > but pretend > that it is. Ok, let's pretend !-) > Would it be so terrible? No, I could live with it. Just a question now : how would this deal with functions defined outside the class statement but used as methods ? Oh, and please read until the end... > If a particular project wanted to > enforce encapsulation, s/encapsulation/data hiding/ > all they need do is replace or remove the > protection module from their Python installations. (I assume the project > developers aren't *hostile*. If they are, then there's almost nothing you > can do to make the code safe. Encapsulation is about protecting from > accidents, not sabotage.) InMyArms(tm) !-) > If you wanted to mess with the internals in > your own project, all you need do is import a module. > > > We could imagine the same scenario in reverse. Python allows getters and > setters, but they're more work, And more overhead. > and so people just don't use them unless > they really need to. Which is fine. Well, MHO at least. > Suppose Python offered real data encapsulation, s/encapsulation/hiding/ > but > you had to work to get it: > >>>> class Parrot: > ... _private = 'spam' > ... >>>> p = Parrot() >>>> p._private = 'ham' # allowed by default >>>> from protection import lock >>>> lock(p)._private >>>> p._private = 'spam' > Traceback (most recent call last): > File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot > > > Would that be so bad? I don't think so. So technically, this means that you'd have an optionel check for _implementation attribute access outside methods ? Good news my friend, Pylint already do this (and quite a lot of other things too...). So wrt/ code reviews, QA etc, the "lack of access protection" is not such an issue, is it ? http://www.logilab.org/card/pylintfeatures """ W0212: Access to a protected member %s of a client class Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined. """ From xahlee at gmail.com Sun Jan 18 12:36:59 2009 From: xahlee at gmail.com (Xah Lee) Date: Sun, 18 Jan 2009 09:36:59 -0800 (PST) Subject: calling an external program and capturing the output References: Message-ID: <3bad23d1-a441-4d5e-b317-4608cfa6a62b@t26g2000prh.googlegroups.com> On Jan 18, 8:41 am, Eric wrote: > Coming from a perl background I'm new to the Python world. I need to > read a list of values, send each value to an external program and > capture and act on the output of that program. Reading and parsing the > initial values is not a problem but I can't seem to find anything on > the sending to and capturing from an external program. > > Any suggestions would be greatly appreciated. See: ? Making System Calls in Perl and Python http://xahlee.org/perl-python/system_calls.html Xah ? http://xahlee.org/ ? From scott.p.macdonald at gmail.com Sun Jan 18 13:01:47 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sun, 18 Jan 2009 11:01:47 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: Yes, I see your point. Not sure how that would happen. It is possible to have multiple versions of python on the same machine I assume? During the installation I have specified the directory to install python in, otherwise I have not changed anything. Could it be an environment variable or something like that? Thanks, Scott On Sun, Jan 18, 2009 at 12:44 AM, Gabriel Genellina wrote: > En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald > escribi?: > > I googled a bit this morning search for an answer to this problem but have >> come up empty so far. Can anyone help? >> >> Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit >> > ^^^^^ > >> (Intel)] >> on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import urllib2 >>>>> >>>> Traceback (most recent call last): >> File "", line 1, in >> File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in >> > ^^^^^^^^ > > It seems your have a confusing setup. Why is Python 2.6 using > C:\dev\opt\Python25? > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtw at freenet.co.uk Sun Jan 18 13:02:37 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 18 Jan 2009 12:02:37 -0600 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> Message-ID: Aaron Brady wrote in news:582ef883-0176-4984-9521-6c1894636891 at a26g2000prf.googlegroups.com in comp.lang.python: > On Jan 18, 10:44?am, Rob Williscroft wrote: >> Aaron Brady wrote >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh > .googlegroups.com >> in comp.lang.python: >> >> > It is too bad that it is so much work to detect whether 'y' was >> > passed in the function call directly. ?However, sentinel is just as >> > good (or nearly); at worst, you need one sentinel per argument per >> > function, >> >> One per Module should be good enough. The only reason None doesen't >> suffice is that it has other legitimate uses. ?Though to be honest >> I would always use None as the sentinel if it wasn't a legitimate >> argument. >> >> > which is possible to create, which has a specific meaning. ?If you >> > are >> > making systematic function calls, e.g. with a dictionary or list, >> > you can just use the sentinel in the dictionary. >> >> IIUYC then, one sentinel is still only needed as the missing argument >> is indicated by *both* position and value or by name and value (in >> the case of a keyword-dictionary), so seperate distinct sentinel >> objects aren't required, for example: >> >> SENTINEL = object() >> >> def f( a, b, c = SENTINEL, d = SENTINEL ): >> ? print( "values: %r" % ( ( a, b, c, d ), ) ) >> ? if c is SENTINEL: >> ? ? print( "c is missing" ) >> ? if d is SENTINEL: >> ? ? print( "d is missing" ) >> >> f( *( 1, 2, SENTINEL, SENTINEL ) ) >> >> f( **dict( a = 1 , b = 2, d = 4 ) ) >> >> f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > I don't have a concrete example, so you may prove to be right, but I'm > not convinced. I'm afraid I can't think of a use case for passing default values around eiither, and I suspect if we were to come up with one, a better solution that didn't involve passing default values around could be found. > If you have one function with an argument that defaults to an empty > list, and calls another with an argument that defaults to an empty > dict, then what is the meaning of passing sentinel to the first one? > Whereas, if each had their own, then passing the first one's default > would mean the empty list, and passing the second one's default would > mean the dict. If you *mean* to pass an "empty list" or "empty dict"'s you should do it like: function_taking_list( [] ) function_taking_dict( {} ) Its when you don't (have reason to) care that you need default arguments. > (Or, even if that evaluates correctly, perhaps there is no such useful > program.) I agree, though I think some confusion arises here as there are two (at least) distinct meanings for default arguments in python: 1) provide a value for when the caller doesn't, eg: def f( a = 1 ): ... 2) provide a cache for the functions /private/ use, eg: def f( cache = {} ): ... If the two are mixed up, then I can imagine a situation where somebody might want to start passing default caches around. It could only end in tears. Rob. -- http://www.victim-prime.dsl.pipex.com/ From waltbrad at hotmail.com Sun Jan 18 13:06:06 2009 From: waltbrad at hotmail.com (waltbrad) Date: Sun, 18 Jan 2009 10:06:06 -0800 (PST) Subject: uninstall before upgrade? Message-ID: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before I do that? If so, what's the best way to uninstall it? Thanks. From scott.p.macdonald at gmail.com Sun Jan 18 13:08:07 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Sun, 18 Jan 2009 11:08:07 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: Ah yes, with your help I seem to have solved my own problem. I had PYTHONPATH defined to point to the 2.5 directory. Thanks! Scott On Sun, Jan 18, 2009 at 11:01 AM, Scott MacDonald < scott.p.macdonald at gmail.com> wrote: > Yes, I see your point. Not sure how that would happen. It is possible to > have multiple versions of python on the same machine I assume? > > During the installation I have specified the directory to install python > in, otherwise I have not changed anything. Could it be an environment > variable or something like that? > > Thanks, > Scott > > > > > On Sun, Jan 18, 2009 at 12:44 AM, Gabriel Genellina < > gagsl-py2 at yahoo.com.ar> wrote: > >> En Sat, 17 Jan 2009 17:13:00 -0200, Scott MacDonald >> escribi?: >> >> I googled a bit this morning search for an answer to this problem but >>> have >>> come up empty so far. Can anyone help? >>> >>> Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit >>> >> ^^^^^ >> >>> (Intel)] >>> on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>>> import urllib2 >>>>>> >>>>> Traceback (most recent call last): >>> File "", line 1, in >>> File "C:\dev\opt\Python25\Lib\urllib2.py", line 92, in >>> >> ^^^^^^^^ >> >> It seems your have a confusing setup. Why is Python 2.6 using >> C:\dev\opt\Python25? >> >> -- >> Gabriel Genellina >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Jan 18 13:11:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 19:11:43 +0100 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: <6th9mvFapmtvU1@mid.uni-berlin.de> waltbrad schrieb: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. No, several versions of python can live happily together. Diez From bockman at virgilio.it Sun Jan 18 13:17:38 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 18 Jan 2009 19:17:38 +0100 Subject: pep 8 constants References: Message-ID: On Wed, 14 Jan 2009 08:13:30 +0000, Steven D'Aprano wrote: > > Absolutely. It's rather sad that I can do this: > > import math > math.pi = 3.0 > > I like the ability to shoot myself in the foot, thank you very much, but > I should at least get a warning when I'm about to do so: > > math.PI = 3.0 # use God-like powers to change a constant > > Constants would be a nice addition in python, sure enough. But I'm not sure that this can be done without a run-time check every time the constant is used, and python is already slow enough. Maybe a check that is disabled when running with optimizing flags ? But I'm sure this discussion has been already made and the FINAL WORD has been already spoken. Ciao ---- FB From ericcire at gmail.com Sun Jan 18 13:30:14 2009 From: ericcire at gmail.com (Eric) Date: Sun, 18 Jan 2009 10:30:14 -0800 (PST) Subject: calling an external program and capturing the output References: Message-ID: Thanks guys. That helped point me int he right direction. with your advice on the subprocess module I stumbled upon this posting: http://www.velocityreviews.com/forums/t359866-subprocess-module.html for anyone else that might be interested here is the solution. It simply calls a perl script called add.pl that reads 2 numbers from stdin and adds them together. Thanks again for the help. -Eric #!/usr/bin/env python import subprocess prog = "./add.pl" args = "3 4" app = subprocess.Popen (prog ,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) print "opened " + prog #print app.stdout.read() print "writing \'" + args + "\' to " + prog + " subprocess" app.stdin.write(args) app.stdin.write("\n") print "wrote \'" + args + "\' to " + prog + " subprocess" result = app.stdout.read() result = result.rstrip('\n') print "received: " + result and here is the output: ./call_add.py opened ./add.pl writing '3 4' to ./add.pl subprocess wrote '3 4' to ./add.pl subprocess received: 7 From andrew at acooke.org Sun Jan 18 13:42:23 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 18 Jan 2009 10:42:23 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <1fab9135-6de3-4625-9c78-0da62fe4d2f6@k36g2000pri.googlegroups.com> > ? ? sentinel = object() > ? ? ... > > ? ? def foo(x, y=sentinel): > ? ? ? if y is sentinel: > ? ? ? ? ? y = self.a it just struck me you could also do: def foo(self, x, *y_args) y = y_args[0] if y_args self.a which more directly checks whether an argument was passed, but has the downside of making the method signature less clear in the declaration. andrew From ron at flownet.com Sun Jan 18 14:01:50 2009 From: ron at flownet.com (Ron Garret) Date: Sun, 18 Jan 2009 11:01:50 -0800 (PST) Subject: WSGI question: reading headers before message body has been read Message-ID: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> I'm writing a WSGI application and I would like to check the content- length header before reading the content to make sure that the content is not too big in order to prevent denial-of-service attacks. So I do something like this: def application(environ, start_response): status = "200 OK" headers = [('Content-Type', 'text/html'), ] start_response(status, headers) if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' But this doesn't seem to work. If I upload a huge file it still waits until the entire file has been uploaded before complaining that it's too big. Is it possible to read the HTTP headers in WSGI before the request body has been read? Thanks, rg From deets at nospam.web.de Sun Jan 18 14:29:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 20:29:38 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <6the94FajnrlU1@mid.uni-berlin.de> Ron Garret schrieb: > I'm writing a WSGI application and I would like to check the content- > length header before reading the content to make sure that the content > is not too big in order to prevent denial-of-service attacks. So I do > something like this: > > def application(environ, start_response): > status = "200 OK" > headers = [('Content-Type', 'text/html'), ] > start_response(status, headers) > if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > But this doesn't seem to work. If I upload a huge file it still waits > until the entire file has been uploaded before complaining that it's > too big. > > Is it possible to read the HTTP headers in WSGI before the request > body has been read? AFAIK that is nothing that WSGI defines - it's an implementation-detail of your server. Which one do you use? Diez From google at mrabarnett.plus.com Sun Jan 18 14:32:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 18 Jan 2009 19:32:20 +0000 Subject: pep 8 constants In-Reply-To: References: Message-ID: <497383C4.2080800@mrabarnett.plus.com> Francesco Bochicchio wrote: > On Wed, 14 Jan 2009 08:13:30 +0000, Steven D'Aprano wrote: > > >> Absolutely. It's rather sad that I can do this: >> >> import math >> math.pi = 3.0 >> >> I like the ability to shoot myself in the foot, thank you very much, but >> I should at least get a warning when I'm about to do so: >> >> math.PI = 3.0 # use God-like powers to change a constant >> >> > > Constants would be a nice addition in python, sure enough. > But I'm not sure that this can be done without a run-time check every time > the constant is used, and python is already slow enough. Maybe a check > that is disabled when running with optimizing flags ? > > But I'm sure this discussion has been already made and the FINAL WORD has > been already spoken. > >>> class Constants(object): def __setattr__(self, key, value): if key in self.__dict__: raise ValueError("Can't change constant") self.__dict__[key] = value >>> c = Constants() >>> c.PI = 3.0 >>> c.PI 3.0 >>> c.PI = 4.0 Traceback (most recent call last): File "", line 1, in c.PI = 4.0 File "", line 4, in __setattr__ raise ValueError("Can't change constant") ValueError: Can't change constant From vedrandekovic at yahoo.com Sun Jan 18 14:38:51 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 18 Jan 2009 11:38:51 -0800 (PST) Subject: Python and threads References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> Message-ID: <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> On 18 sij, 17:48, "Diez B. Roggisch" wrote: > vedrandeko... at yahoo.com schrieb: > > > > > Hello again, > > > Thanks for previous help on "Start two threads in same time" it was > > useful,but when I run this > > two threads, I think they don't start at the same time, here is my > > code snippet: > > > import threading > > > class ThreadedClass1(threading.Thread): > > ? ? def __init__(self): > > ? ? ? ? threading.Thread.__init__(self) > > > ? ? def run(self): > > ? ? ? ? a=True > > ? ? ? ? while a==True: > > ? ? ? ? ? ? bm=my_module.MyClass() > > ? ? ? ? ? ? a=bm.get_Python_Process_Usage_Function() ? #Returns True > > or False > > > class ThreadedClass2(threading.Thread): > > ? ? def __init__(self): > > ? ? ? ? threading.Thread.__init__(self) > > > ? ? def run(self): > > ? ? ? ? os.popen("my_python_script.py") > > > threaded_obj = ThreadedClass1() > > threaded_obj.start() > > threaded_obj2 = ThreadedClass2() > > threaded_obj2.start() > > If you want to synchronize two or more threads, you need to do so > manually using objects like Locks, Events, Conditions and Semaphores. > See the threading module. > > Even if you managed to get two threads started simultaneously (which the > ? OS doesn't even offer IINM), the would soon run out of sync. > > How about you tell us what you *want*, and we tell you if and how it's > possible to do that. > > Diez Hello, and thanks for all previous help.I want to measure memory usage of executed python script.I'am working on windows XP. Regards, John From petite.abeille at gmail.com Sun Jan 18 14:43:21 2009 From: petite.abeille at gmail.com (Petite Abeille) Date: Sun, 18 Jan 2009 20:43:21 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <456AD650-77AE-45B2-9C93-8C3DA33F151E@gmail.com> On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > def application(environ, start_response): > status = "200 OK" > headers = [('Content-Type', 'text/html'), ] > start_response(status, headers) > if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' How would that work for chunked transfer-encoding? Cheers, -- PA. http://alt.textdrive.com/nanoki/ From Russ.Paielli at gmail.com Sun Jan 18 14:51:07 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 18 Jan 2009 11:51:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> Message-ID: <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> On Jan 18, 9:22?am, Bruno Desthuilliers wrote: > Properties by themselves are not the problem, quite on the contrary - as > you say, they actually help wrt/ encapsulation. What breaks > encapsulation is *automatic generation* for properties for *each and > any* implementation attribute. Might as well just makes them all public > attribute then. Let me correct my statement about the automatic generation of properties in Scala: it is only for public attributes, not all attributes. Getting back to the bigger point, I will gladly agree with you that data hiding is not a magic bullet that will eliminate all bugs. The idea that I or anyone else said that, however, is a red herring. Data hiding is just one safeguard in a portfolio of safeguards that can *help* to prevent certain kinds of bugs as well as deliberate acts of sabotage or fraud. When you have a tough problem to solve, you need all the help you can get. You keep saying that if you hire competent, trustworthy developers, you don't need data hiding. Well, maybe, but when you have a team of dozens or hundreds of developers, your chances of avoiding any bad ones is zero for all practical purposes. And even if all your developers were excellent, data hiding would still be a convenient mechanism to simplify their jobs so they can focus on higher level problems -- and not have to rely on an ugly naming convention. Now, if developers become careless because they think data hiding will save them, then that would be a problem. That much I will concede. But I doubt that happens much. From tjreedy at udel.edu Sun Jan 18 15:11:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Jan 2009 15:11:46 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: Message-ID: andrew cooke wrote: > Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data > model#object.__iadd__ > > Just a suggestion I thought I'd throw out... There's a restriction in > the language implementation on exactly what can go the left of an > augmented arithmetic expression. > > For example: >>>> a = 3 >>>> a **= 2 > > is ok, but: >>>> class Foo(): > ... def __init__(): > ... self.a = 3 > ... def __ipow__(self, x): > ... self.a **= x > ... >>>> Foo() **= 2 Calls return objects and therefore cannot be the target of an assignment, augmented or otherwise. The target of an assignment is a name or collection slot, both of which are grammatical constructs, not objects. From ron.garret at gmail.com Sun Jan 18 15:25:45 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 12:25:45 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> Message-ID: <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> On Jan 18, 11:29?am, "Diez B. Roggisch" wrote: > Ron Garret schrieb: > > > > > I'm writing a WSGI application and I would like to check the content- > > length header before reading the content to make sure that the content > > is not too big in order to prevent denial-of-service attacks. ?So I do > > something like this: > > > def application(environ, start_response): > > ? ? status = "200 OK" > > ? ? headers = [('Content-Type', 'text/html'), ] > > ? ? start_response(status, headers) > > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > > But this doesn't seem to work. ?If I upload a huge file it still waits > > until the entire file has been uploaded before complaining that it's > > too big. > > > Is it possible to read the HTTP headers in WSGI before the request > > body has been read? > > AFAIK that is nothing that WSGI defines - it's an implementation-detail > of your server. Which one do you use? Apache at the moment, with lighttpd as a contender to replace it. rg From stefan_ml at behnel.de Sun Jan 18 15:27:46 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Jan 2009 21:27:46 +0100 Subject: Python and threads In-Reply-To: <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> Message-ID: <497390c3$0$31878$9b4e6d93@newsspool3.arcor-online.net> vedrandekovic at yahoo.com wrote: > and thanks for all previous help.I want to measure memory usage of > executed python script.I'am working on windows XP. Could you qualify "measure"? Do you mean: a) "debug" (permanently high accuracy, potentially high runtime overhead) b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime overhead) c) "find out" (low accuracy or just max usage, no permanent observation) ? Stefan From ron.garret at gmail.com Sun Jan 18 15:34:03 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 12:34:03 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <68c7797c-f4fd-4c67-a23d-0999b7d46b85@y1g2000pra.googlegroups.com> On Jan 18, 11:43?am, Petite Abeille wrote: > On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > > > def application(environ, start_response): > > ? ?status = "200 OK" > > ? ?headers = [('Content-Type', 'text/html'), ] > > ? ?start_response(status, headers) > > ? ?if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > How would that work for chunked transfer-encoding? It wouldn't. But many clients don't use chunked-transfer-encoding when uploading files whose size is known. In that case it would be nice to let users know that their upload is going to fail BEFORE they waste hours waiting for 10GB of data to go down the wire. rg From deets at nospam.web.de Sun Jan 18 15:40:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 21:40:41 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> Message-ID: <6thie9Fapdc8U1@mid.uni-berlin.de> Ron Garret schrieb: > On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: >> Ron Garret schrieb: >> >> >> >>> I'm writing a WSGI application and I would like to check the content- >>> length header before reading the content to make sure that the content >>> is not too big in order to prevent denial-of-service attacks. So I do >>> something like this: >>> def application(environ, start_response): >>> status = "200 OK" >>> headers = [('Content-Type', 'text/html'), ] >>> start_response(status, headers) >>> if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' >>> But this doesn't seem to work. If I upload a huge file it still waits >>> until the entire file has been uploaded before complaining that it's >>> too big. >>> Is it possible to read the HTTP headers in WSGI before the request >>> body has been read? >> AFAIK that is nothing that WSGI defines - it's an implementation-detail >> of your server. Which one do you use? > > Apache at the moment, with lighttpd as a contender to replace it. Together with mod_wsgi? Diez From lkcl at lkcl.net Sun Jan 18 15:46:20 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sun, 18 Jan 2009 20:46:20 +0000 Subject: libmsi.a import library from wine, and header files available (entirely free software), available for python-win32 builds under msys+wine Message-ID: as part of building python2.5.2 under msys under wine on linux using mingw, i thought i'd try building _msi.pyd just for kicks. of course, that required having an msi.lib import library, and associated header files. so, purely as an experiment, i've documented the process by which it is possible to take wine 1.1.13 (current development release) source code, modify the header files for use with mingw, create a typelibrary (using dlltool) and then, surprise-surprise, _msi.pyd successfully builds. i say successfully builds: but then, running from _outside_ of a wineconsole cmd, doing this: /usr/local/bin/wine ./python.exe -c 'import _msi' succeeds. but if you do this: /usr/local/bin/wineconsole cmd c:/python2.5/bin/python.exde -c 'import _msi' you get an "access violation - no access to memory" blah blah to be honest, i don't care about that: this message is to let people know that it _is_ possible, and, if anyone is interested in e.g. adding -lmsi -lcabinet support to MinGW, here's where you can get the necessary crud: http://lkcl.net/msi.tgz if the wine team have any objections, if they believe this is a bad idea, please do say so :) l. p.s. if anyone would like to add a regression test to python called "test_msi.py" - or if they know of one that exists, i'd love to hear from you and try it out. outside of a wine cmd.exe of course :) From ron.garret at gmail.com Sun Jan 18 16:02:35 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 13:02:35 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> <6thie9Fapdc8U1@mid.uni-berlin.de> Message-ID: <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> On Jan 18, 12:40?pm, "Diez B. Roggisch" wrote: > Ron Garret schrieb: > > > > > On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: > >> Ron Garret schrieb: > > >>> I'm writing a WSGI application and I would like to check the content- > >>> length header before reading the content to make sure that the content > >>> is not too big in order to prevent denial-of-service attacks. ?So I do > >>> something like this: > >>> def application(environ, start_response): > >>> ? ? status = "200 OK" > >>> ? ? headers = [('Content-Type', 'text/html'), ] > >>> ? ? start_response(status, headers) > >>> ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > >>> But this doesn't seem to work. ?If I upload a huge file it still waits > >>> until the entire file has been uploaded before complaining that it's > >>> too big. > >>> Is it possible to read the HTTP headers in WSGI before the request > >>> body has been read? > >> AFAIK that is nothing that WSGI defines - it's an implementation-detail > >> of your server. Which one do you use? > > > Apache at the moment, with lighttpd as a contender to replace it. > > Together with mod_wsgi? > > Diez Yes. (Is there any other way to run WSGI apps under Apache?) rg From digitig at gmail.com Sun Jan 18 16:19:58 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 18 Jan 2009 21:19:58 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xmydomvim.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/18 Paul Rubin <"http://phr.cx"@nospam.invalid>: > I.e. the cast was wrong because of the failure of an unstated > assumption that a certain sensor reading was in a certain range. > Spark may still have allowed the cast only if the assumption was > stated explicitly in the specification. Unless it's changed since I used it, technically, SPADE doesn't allow or disallow anything. It produces a predicate (a proof obligation) that you have to prove is always true (or is it always false? It's been 18 years since I worked on that stuff, and SPADE and MALPAS produced their proof obligations with opposite values). So it's still up to you to show that it won't overflow, it just gives you the predicate calculus expression that you need to do that. Since the value appears to come from a sensor, the only way one could prove that there would be no overflow would be to state it as a part of the specification of what is read in. If that specification doesn't match the specification of the actual sensor, that's nothing to do with the programming language or, for that matter, the program itself. It's a specification mismatch. I was actually at the European Space Agency's Toulouse site the week after the Ariane 5 incident. I've been at jollier funerals. I can't help thinking that thinking that the team would have benefited from reading David Parnas's work on the specification of the A-7E avionics. -- Tim Rowe From Graham.Dumpleton at gmail.com Sun Jan 18 16:21:39 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sun, 18 Jan 2009 13:21:39 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <5094296c-361b-49ce-90df-943f2f79a7e6@r15g2000prh.googlegroups.com> On Jan 19, 6:01?am, Ron Garret wrote: > I'm writing a WSGI application and I would like to check the content- > length header before reading the content to make sure that the content > is not too big in order to prevent denial-of-service attacks. ?So I do > something like this: > > def application(environ, start_response): > ? ? status = "200 OK" > ? ? headers = [('Content-Type', 'text/html'), ] > ? ? start_response(status, headers) > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' You should be returning 413 (Request Entity Too Large) error status for that specific case, not a 200 response. You should not be returning a string as response content as it is very inefficient, wrap it in an array. > But this doesn't seem to work. ?If I upload a huge file it still waits > until the entire file has been uploaded before complaining that it's > too big. > > Is it possible to read the HTTP headers in WSGI before the request > body has been read? Yes. The issue is that in order to avoid the client sending the data the client needs to actually make use of HTTP/1.1 headers to indicate it is expecting a 100-continue response before sending data. You don't need to handle that as Apache/mod_wsgi does it for you, but the only web browser I know of that supports 100-continue is Opera browser. Clients like curl do also support it as well though. In other words, if people use IE, Firefox or Safari, the request content will be sent regardless anyway. There is though still more to this though. First off is that if you are going to handle 413 errors in your own WSGI application and you are using mod_wsgi daemon mode, then request content is still sent by browser regardless, even if using Opera. This is because the act of transferring content across to mod_wsgi daemon process triggers return of 100-continue to client and so it sends data. There is a ticket for mod_wsgi to implement proper 100-continue support for daemon mode, but will be a while before that happens. Rather than have WSGI application handle 413 error cases, you are better off letting Apache/mod_wsgi handle it for you. To do that all you need to do is use the Apache 'LimitRequestBody' directive. This will check the content length for you and send 413 response without the WSGI application even being called. When using daemon mode, this is done in Apache child worker processes and for 100-continue case data will not be read at all and can avoid client sending it if using Opera. Only caveat on that is the currently available mod_wsgi has a bug in it such that 100-continue requests not always working for daemon mode. You need to apply fix in: http://code.google.com/p/modwsgi/issues/detail?id=121 For details on LimitRequestBody directive see: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody Graham From Graham.Dumpleton at gmail.com Sun Jan 18 16:25:38 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sun, 18 Jan 2009 13:25:38 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> Message-ID: <59755318-2e50-4ddd-a3f5-a4ceaee512c3@x16g2000prn.googlegroups.com> On Jan 19, 6:43?am, Petite Abeille wrote: > On Jan 18, 2009, at 8:01 PM, Ron Garret wrote: > > > def application(environ, start_response): > > ? ?status = "200 OK" > > ? ?headers = [('Content-Type', 'text/html'), ] > > ? ?start_response(status, headers) > > ? ?if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > How would that work for chunked transfer-encoding? Chunked transfer encoding on request content is not supported by WSGI specification as WSGI requires CONTENT_LENGTH be set and disallows reading more than defined content length, where CONTENT_LENGTH is supposed to be taken as 0 if not provided. If using Apache/mod_wsgi 3.0 (currently in development, so need to use subversion copy), you can step outside what WSGI strictly allows and still handle chunked transfer encoding on request content, but you still don't have a CONTENT_LENGTH so as to check in advance if more data than expected is going to be sent. If wanting to know how to handle chunked transfer encoding in mod_wsgi, better off asking on mod_wsgi list. Graham From ron.garret at gmail.com Sun Jan 18 16:38:57 2009 From: ron.garret at gmail.com (Ron Garret) Date: Sun, 18 Jan 2009 13:38:57 -0800 (PST) Subject: WSGI question: reading headers before message body has been read References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <5094296c-361b-49ce-90df-943f2f79a7e6@r15g2000prh.googlegroups.com> Message-ID: On Jan 18, 1:21?pm, Graham Dumpleton wrote: > On Jan 19, 6:01?am, Ron Garret wrote: > > > I'm writing a WSGI application and I would like to check the content- > > length header before reading the content to make sure that the content > > is not too big in order to prevent denial-of-service attacks. ?So I do > > something like this: > > > def application(environ, start_response): > > ? ? status = "200 OK" > > ? ? headers = [('Content-Type', 'text/html'), ] > > ? ? start_response(status, headers) > > ? ? if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' > > You should be returning 413 (Request Entity Too Large) error status > for that specific case, not a 200 response. > > You should not be returning a string as response content as it is very > inefficient, wrap it in an array. > > > But this doesn't seem to work. ?If I upload a huge file it still waits > > until the entire file has been uploaded before complaining that it's > > too big. > > > Is it possible to read the HTTP headers in WSGI before the request > > body has been read? > > Yes. > > The issue is that in order to avoid the client sending the data the > client needs to actually make use of HTTP/1.1 headers to indicate it > is expecting a 100-continue response before sending data. You don't > need to handle that as Apache/mod_wsgi does it for you, but the only > web browser I know of that supports 100-continue is Opera browser. > Clients like curl do also support it as well though. In other words, > if people use IE, Firefox or Safari, the request content will be sent > regardless anyway. > > There is though still more to this though. First off is that if you > are going to handle 413 errors in your own WSGI application and you > are using mod_wsgi daemon mode, then request content is still sent by > browser regardless, even if using Opera. This is because the act of > transferring content across to mod_wsgi daemon process triggers return > of 100-continue to client and so it sends data. There is a ticket for > mod_wsgi to implement proper 100-continue support for daemon mode, but > will be a while before that happens. > > Rather than have WSGI application handle 413 error cases, you are > better off letting Apache/mod_wsgi handle it for you. To do that all > you need to do is use the Apache 'LimitRequestBody' directive. This > will check the content length for you and send 413 response without > the WSGI application even being called. When using daemon mode, this > is done in Apache child worker processes and for 100-continue case > data will not be read at all and can avoid client sending it if using > Opera. > > Only caveat on that is the currently available mod_wsgi has a bug in > it such that 100-continue requests not always working for daemon mode. > You need to apply fix in: > > ?http://code.google.com/p/modwsgi/issues/detail?id=121 > > For details on LimitRequestBody directive see: > > ?http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody > > Graham Thanks for the detailed response! rg From seaworthyjeremy at gmail.com Sun Jan 18 17:18:13 2009 From: seaworthyjeremy at gmail.com (seaworthyjeremy at gmail.com) Date: Sun, 18 Jan 2009 14:18:13 -0800 (PST) Subject: Can Python manipulate PE structure or bytes? Message-ID: I'm interested in Python and wanted to know if Python can manipulate PE structure and bytes. Also what are its limits? From bearophileHUGS at lycos.com Sun Jan 18 17:18:18 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 14:18:18 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <400b46d2-3f03-4e2e-ab0f-c6a01e9f5abd@n41g2000yqh.googlegroups.com> Message-ID: r: >Of course it would not run in C or Python but the point here is readability.< With languages like Genie you can go close: http://live.gnome.org/Genie Or better Delight (based on the D language), plus some my "Python compatibility" libs (plus Pyd, if you want) you can run that code: http://delight.sourceforge.net/ Bye, bearophile From steve at REMOVE-THIS-cybersource.com.au Sun Jan 18 17:28:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Jan 2009 22:28:04 GMT Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> Message-ID: <0183a368$0$8693$c3e8da3@news.astraweb.com> On Sun, 18 Jan 2009 07:36:53 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> def foo(self, x, y=None): >> if y is None: >> y = self.a >> >> I don't find that clumsy in the least. I find it perfectly readable and >> a standard idiom. > > That has the same problem as the earlier version. No it doesn't. The earlier version had the problem that *any* false object is replaced by self.a. I'm just following the standard Python idiom of using None as a sentinel. Have a look through the standard library and see how many times it is used. Built-ins rarely accept None as a sentinel, slice() being a conspicuous exception. This is sometimes a nuisance when writing wrappers: def my_find(S, sub, start=None, end=None): """Like string.find() only with pre-processing.""" pre_process() # stub for something complicated if end is None and start is None: return S.find(sub) elif end if None: return S.find(sub, start) else: return S.find(sub, start, end) or if you prefer: def my_find(S, sub, start=None, end=None): """Like string.find()""" pre_process() args = [sub] if start is not None: args.append(start) if end is not None: args.append(end) return S.find(*args) Having said that, there are times where you need to pass None as a legitimate argument and not as a sentinel. In that case, your solution: > If the person passes > None, they get self.a. I prefer: > > sentinel = object() > ... > > def foo(x, y=sentinel): > if y is sentinel: > y = self.a is an excellent one. -- Steven From bearophileHUGS at lycos.com Sun Jan 18 17:44:52 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 14:44:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <7xsknmwcip.fsf@ruckus.brouhaha.com> <44afead4-e801-49d5-a076-116379edf0ff@i18g2000prf.googlegroups.com> <7x4p01n1fc.fsf@ruckus.brouhaha.com> <6fd07d51-7e61-4fd4-a8f1-ec4e42dae9be@y1g2000pra.googlegroups.com> Message-ID: <114ea588-e48c-4a5a-b880-2683fbcf4186@g3g2000pre.googlegroups.com> alex23: > Paul, have you looked into Cython at all? I can also suggest ShedSkin and the D language. I have often used D for data munging, producing quick & short programs, when Python isn't fast enough for a certain purpose. Bye, bearophile From http Sun Jan 18 17:47:18 2009 From: http (Paul Rubin) Date: 18 Jan 2009 14:47:18 -0800 Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <0183a368$0$8693$c3e8da3@news.astraweb.com> Message-ID: <7xwscsxmdl.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Having said that, there are times where you need to pass None as a > legitimate argument and not as a sentinel. I don't think it's worth trying to figure out which those times are. The conclusion can be wrong, or can become wrong later because of some faraway change in the code. I prefer using the bulletproof method from the beginning, whether it is needed or not. From deets at nospam.web.de Sun Jan 18 17:54:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 18 Jan 2009 23:54:15 +0100 Subject: WSGI question: reading headers before message body has been read In-Reply-To: <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> References: <65a8d82d-bb94-48ab-aee0-04453d9518ce@w1g2000prm.googlegroups.com> <6the94FajnrlU1@mid.uni-berlin.de> <54509233-42eb-411a-bc4d-2dd414a1672a@z27g2000prd.googlegroups.com> <6thie9Fapdc8U1@mid.uni-berlin.de> <71059a92-b830-4220-84c7-7cfa57636b41@r37g2000prr.googlegroups.com> Message-ID: <6thq8nFat9peU1@mid.uni-berlin.de> Ron Garret schrieb: > On Jan 18, 12:40 pm, "Diez B. Roggisch" wrote: >> Ron Garret schrieb: >> >> >> >>> On Jan 18, 11:29 am, "Diez B. Roggisch" wrote: >>>> Ron Garret schrieb: >>>>> I'm writing a WSGI application and I would like to check the content- >>>>> length header before reading the content to make sure that the content >>>>> is not too big in order to prevent denial-of-service attacks. So I do >>>>> something like this: >>>>> def application(environ, start_response): >>>>> status = "200 OK" >>>>> headers = [('Content-Type', 'text/html'), ] >>>>> start_response(status, headers) >>>>> if int(environ['CONTENT_LENGTH'])>1000: return 'File too big' >>>>> But this doesn't seem to work. If I upload a huge file it still waits >>>>> until the entire file has been uploaded before complaining that it's >>>>> too big. >>>>> Is it possible to read the HTTP headers in WSGI before the request >>>>> body has been read? >>>> AFAIK that is nothing that WSGI defines - it's an implementation-detail >>>> of your server. Which one do you use? >>> Apache at the moment, with lighttpd as a contender to replace it. >> Together with mod_wsgi? >> >> Diez > > Yes. (Is there any other way to run WSGI apps under Apache?) Well, not so easy, but of course you can work with mod_python or even CGI/fastcgi to eventually invoke a WSGI-application. However, the original question - that's a tough one. According to this, it seems one can use an apache-directive to prevent mod_wsgi to even pass a request to the application if it exceeds a certain size. http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines Search for "Limiting Request Content" However, I'm not sure how early that happens. I can only suggest you try & contact Graham Dumpleton directly, he is very responsive. Diez From bearophileHUGS at lycos.com Sun Jan 18 18:04:53 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 18 Jan 2009 15:04:53 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <7xtz84fapn.fsf@ruckus.brouhaha.com> <45f03104-45e2-4d91-be7d-5addd30ba3f1@g38g2000yqn.googlegroups.com> <7xeiz8hzeo.fsf@ruckus.brouhaha.com> <47f964f0-342a-4d98-bc59-25ed152c4896@p2g2000prf.googlegroups.com> Message-ID: <194e5563-6898-4a40-9079-4668aaf0cc95@i18g2000prf.googlegroups.com> Michele Simionato: > I don't like that. Scala was designed with the idea of putting > together the two worlds, by I think the result was to get the > complications of both worlds. But some other people may like it, and it's a design experiment worth doing. Every programming paradigm has advantages, so it's normal for people to try to design language that have the best of different worlds. Even if Scala is a failure (and I don't think it is), it's good to keep trying to design a mixed language (Like Python, that mixes procedural, some OOP and a bit of functional stiles. It has not pattern matching stile (Mathematica, OcaML), logic-inferential style (Prolog), constraint style (Oz, Mozart), data flow style, generic programming (C++, D), etc). Today lot of people understand that functional languages have advantages, so they are trying to created hybrids (Scala, F#, D V.2, etc), and they may succeed only trying. The purpose is of course to create a language that isn't too much complex, but has those advantages anyway. I presume Scala is quite less complex than C++ anyway. >Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make additional features appear necessary. -- William Clinger< I think it's false, but it requires me lot of space to explain why. In few words: Perl is more useful than Scheme if you have to solve a lot of practical computational problems, despite Scheme looks much more nicer. Bye, bearophile From catphive at catphive.net Sun Jan 18 18:06:10 2009 From: catphive at catphive.net (Brendan Miller) Date: Sun, 18 Jan 2009 15:06:10 -0800 Subject: braces fixed '#{' and '#}' In-Reply-To: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: Yes, I also recently noticed the bug in python's parser that doesn't let it handle squigly braces and the bug in the lexer that makes white space significant. I'm surprised the dev's haven't noticed this yet. On Sat, Jan 17, 2009 at 2:09 AM, v4vijayakumar wrote: > I saw some code where someone is really managed to import braces from > __future__. ;) > > def test(): > #{ > print "hello" > #} This seems like the best workaround. Hopefully python curly brace support will be fixed soon. I think technically a language can't be turing complete without curly braces right? That's definitely how I read this: http://www.thocp.net/biographies/papers/turing_oncomputablenumbers_1936.pdf "If the negation of what G?del has shown had been proved, i.e. if, for each U, either U or ?U is provable, then we should have an immediate solution of the Entscheidungsproblem. As a corollary we also have that real programmers use squigly braces and everyone else is nubs" From w_a_x_man at yahoo.com Sun Jan 18 18:29:57 2009 From: w_a_x_man at yahoo.com (William James) Date: 18 Jan 2009 23:29:57 GMT Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Andr? Thieme wrote: > Xah Lee schrieb: > > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.pytho > > n,comp.lang.ruby > > > > Here's a interesting toy problem posted by Drew Krause to > > comp.lang.lisp: > > > > ------------------------ > > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > > > OK, I want to create a nested list in Lisp (always of only integers) > > from a text file, such that each line in the text file would be > > represented as a sublist in the 'imported' list. > > > > example of a file's content > > > > 3 10 2 > > 4 1 > > 11 18 > > > > example of programing behavior > >(make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > > > w_a_x_... at yahoo.com gave a ruby solution: > > > > IO.readlines("blob.txt").map{|line| line.split } > > > > augumented by Jilliam James for result to be numbers: > > > > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > > > > Very beautiful. > > > > ------------------- > > > > That's really the beauty of Ruby. > > > > This problem and ruby code illustrates 2 fundamental problems of > > lisp, namely, the cons problem, and the nested syntax pain. Both of > > which are practically unfixable. > > *Of course* Xah is wrong, as always. > Who would expect anything else? > In the Lisp style Clojure for example one does exactly the same as > Jillian James (JJ) did in Ruby: > (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq > (reader "blob.txt"))) That fails when numbers are separated by more than one space. And what about leading or trailing space? > > This is slightly longer, simply because the functions have longer > names. Integer/parseInt vs to_i > > Also the function split takes a regexp, so I have to add the "\\s" > here. I don?t know though if Jillians version also handles any > kind of whitespac per line. irb(main):003:0> puts " foo \t bar " foo bar => nil irb(main):004:0> " foo \t bar ".split => ["foo", "bar"] irb(main):005:0> "foo...bar?-!hoo".split /\W+/ => ["foo", "bar", "hoo"] > And the last thing is, that the function reader returns a > BufferedReader. So in general this is more valuable in real programs > as opposed to one- line scripts. If we combine line-seq and reader > into readline and apply the two other changes we would say: > (map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt")) That is not a complete program. > vs > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} That is the complete program. > > So, obviously Xah is far away from any reality. > It took him hours of his life to write up all his ideas about Lisp. > Sad to see that all that time was wasted. All of it was wrong. > Poor Xah :( > > > And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store > data for his programs in the format > 3 10 2 > 4 1 > 11 18 > > but instead as > (3 10 2) > (4 1) > (11 18) Perhaps the data was stored by someone else. Understand? > > And then read it back into the program with: > (map read-string (line-seq (reader "blob.txt"))) > You make a very strong case that Lisp is very feeble at processing data. I'm almost convinced. Ruby isn't feeble, so data like this is fine: shall we begin? or lotus135? 1984 times! The 3 stooges: COBOL,LISP,FORTRAN. 3.14, si11y L00KING Extracting the unsigned integers: IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}} ==>[[], [135, 1984], [3], [3, 14, 11, 0]] From catphive at catphive.net Sun Jan 18 18:30:30 2009 From: catphive at catphive.net (Brendan Miller) Date: Sun, 18 Jan 2009 15:30:30 -0800 Subject: what's the point of rpython? In-Reply-To: <7xd4ele060.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Jan 17, 2009 at 7:57 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > alex23 writes: >> Here's an article by Guido talking about the last attempt to remove >> the GIL and the performance issues that arose: >> >> "I'd welcome a set of patches into Py3k *only if* the performance for >> a single-threaded program (and for a multi-threaded but I/O-bound >> program) *does not decrease*." > > The performance decrease is an artifact of CPython's rather primitive > storage management (reference counts in every object). This is > pervasive and can't really be removed. But a new implementation > (e.g. PyPy) can and should have a real garbage collector that doesn't > suffer from such effects. > -- > http://mail.python.org/mailman/listinfo/python-list > That's interesting, I hadn't heard the reference counting mechanism was related to the GIL. Is it just that you need to lock the reference count before mutating it if there's no GIL? Really, that shouldn't be the case. Reference counting can be done with a lock free algorithm. Garbage collection is definitely in vogue right now. However, people tend to treat it more like a religion than an algorithm. Garbage collection vs reference counting actually has some trade offs both ways. GC gets you some amortized performance gains, and some space gains because you don't need to hang on to a bunch of counts. However, GC also has the problem of having a very loose memory profile and poor interactive performance during compaction if the heap is large. In some cases this discussion becomes complicated with python because python has both reference counting and GC. From simon at brunningonline.net Sun Jan 18 18:35:04 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sun, 18 Jan 2009 23:35:04 +0000 Subject: *Advanced* Python book? In-Reply-To: References: Message-ID: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> 2009/1/17 Michele Simionato : > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 +1 for this. I'm 3/4 of the way through it, it's pretty good. Covers many on the important areas that the more introductory books rightly leave out, -- Cheers, Simon B. From gagsl-py2 at yahoo.com.ar Sun Jan 18 18:36:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 21:36:20 -0200 Subject: Can Python manipulate PE structure or bytes? References: Message-ID: En Sun, 18 Jan 2009 20:18:13 -0200, escribi?: > I'm interested in Python and wanted to know if Python can manipulate > PE structure and bytes. Also what are its limits? If you're talking about the "Portable Executable" file format, yes. Take a look at the struct module, or ctypes.Struct, but try Google first... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 18 18:36:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 18 Jan 2009 21:36:20 -0200 Subject: Can Python manipulate PE structure or bytes? References: Message-ID: En Sun, 18 Jan 2009 20:18:13 -0200, escribi?: > I'm interested in Python and wanted to know if Python can manipulate > PE structure and bytes. Also what are its limits? If you're talking about the "Portable Executable" file format, yes. Take a look at the struct module, or ctypes.Struct, but try Google first... -- Gabriel Genellina From http Sun Jan 18 18:50:07 2009 From: http (Paul Rubin) Date: 18 Jan 2009 15:50:07 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xskngxjgw.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > That's interesting, I hadn't heard the reference counting mechanism > was related to the GIL. Is it just that you need to lock the reference > count before mutating it if there's no GIL? Yes. Someone tried inserting such a lock but it slowed down the single-cpu case unacceptably. > Really, that shouldn't be > the case. Reference counting can be done with a lock free algorithm. That's interesting, got a reference? (no pun intended) From marek at xivilization.net Sun Jan 18 19:06:31 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 19 Jan 2009 01:06:31 +0100 Subject: calling an external program and capturing the output References: <3bad23d1-a441-4d5e-b317-4608cfa6a62b@t26g2000prh.googlegroups.com> Message-ID: <20090119010631.67db2c52@halmanfloyd.lan.local> On Sun, 18 Jan 2009 09:36:59 -0800 (PST) Xah Lee wrote: > See: > > ? Making System Calls in Perl and Python > http://xahlee.org/perl-python/system_calls.html You can safely drop the Raw-Strings as they are only needed on Windows when constuction paths and programs with hardcoded paths are rare. regards, Marek From floris.bruynooghe at gmail.com Sun Jan 18 19:18:59 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Sun, 18 Jan 2009 16:18:59 -0800 (PST) Subject: Overriding base class methods in the C API Message-ID: Hello I've been trying to figure out how to override methods of a class in the C API. For Python code you can just redefine the method in your subclass, but setting tp_methods on the type object does not seem to have any influcence. Anyone know of a trick I am missing? Cheers Floris From wuwei23 at gmail.com Sun Jan 18 19:24:11 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Jan 2009 16:24:11 -0800 (PST) Subject: dynamic module import? References: <49711259$0$23396$afc38c87@news.optusnet.com.au> <387354b6-c0e4-48e2-82ba-e06ed5174804@p23g2000prp.googlegroups.com> <01816958$0$8693$c3e8da3@news.astraweb.com> <32ce34e8-0bf5-48dc-b152-15f0f1648522@w39g2000prb.googlegroups.com> Message-ID: On Jan 19, 2:24?am, Duncan Booth wrote: [a nice concise explanation on __import__ & fromlist] Cheers, Duncan, that explained it perfectly. From musicguy at alphaios.net Sun Jan 18 19:36:30 2009 From: musicguy at alphaios.net (The Music Guy) Date: Sun, 18 Jan 2009 18:36:30 -0600 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: <1232325390.6481.10.camel@speedyg> On Sun, 2009-01-18 at 10:06 -0800, waltbrad wrote: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list I've heard of people having problems trying to replace 2.5 with 2.6, so you probably don't want to uninstall 2.5. However, 2.5 and 2.6 can both be installed simultaneously. From sajmikins at gmail.com Sun Jan 18 19:37:32 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 18 Jan 2009 16:37:32 -0800 (PST) Subject: changing URLs in webpages, python solutions? References: <5af49d6c-3aab-44e8-85af-fc2a4246adf7@s1g2000prg.googlegroups.com> <49735b76$0$31867$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <114f1631-d389-4f61-a54a-01bf07840dc9@l33g2000pri.googlegroups.com> On Jan 18, 8:40?am, Stefan Behnel wrote: > Simon Forman wrote: > > I want to take a webpage, find all URLs (links, img src, etc.) and > > rewrite them in-place, and I'd like to do it in python (pure python > > preferred.) > > lxml.html has functions specifically for this problem. > > http://codespeak.net/lxml/lxmlhtml.html#working-with-links > > Code would be something like > > ? ? ? ? html_doc = lxml.html.parse(b"http://.../xyz.html") > ? ? ? ? html_doc.rewrite_links( ... ) > ? ? ? ? print( lxml.html.tostring(html_doc) ) > > It also handles links in CSS or JavaScript, as well as broken HTML documents. > > Stefan Thank you so much! This is exactly what I needed. (for what it's worth, parse() seems to return a "plain" ElementTree object but document_fromstring() gave me a special html object with the rewrite_links() method. I think, but I didn't try it, that html_doc = lxml.html.parse(b"http://.../xyz.html") lxml.html.rewrite_links(html_doc, ... ) would work too.) Thanks again! Regards, ~Simon From skip at pobox.com Sun Jan 18 19:40:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 18 Jan 2009 18:40:06 -0600 Subject: what's the point of rpython? In-Reply-To: <7xskngxjgw.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> Message-ID: <18803.52198.72465.500100@montanaro.dyndns.org> Paul> That's interesting, got a reference? (no pun intended) http://letmegooglethatforyou.com/?q=lock+free+reference+counting -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From jeff at jmcneil.net Sun Jan 18 19:46:32 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Sun, 18 Jan 2009 16:46:32 -0800 (PST) Subject: tp_base, ob_type, and tp_bases References: <05a3b951-baaa-407f-b0ac-d4803cad905c@m15g2000vbp.googlegroups.com> <4971fe4d$0$30907$9b622d9e@news.freenet.de> <60dadd66-91c9-449e-9859-55f734878b85@s1g2000prg.googlegroups.com> <0ff46896-e9e4-440d-b8f9-79addcb325bd@s36g2000vbp.googlegroups.com> <43573712-026a-4f84-817a-7bfdceda8719@v5g2000prm.googlegroups.com> Message-ID: On Jan 18, 5:40?am, Carl Banks wrote: > On Jan 17, 8:12?am, Jeff McNeil wrote: > > > > > On Jan 17, 11:09?am, Jeff McNeil wrote: > > > > On Jan 17, 10:50?am, "Martin v. L?wis" wrote: > > > > > > So, the documentation states that ob_type is a pointer to the type's > > > > > type, or metatype. Rather, this is a pointer to the new type's > > > > > metaclass? > > > > > That's actually the same. *Every* ob_type field points to the object's > > > > type, e.g. for strings, integers, tuples, etc. That includes type > > > > objects, where ob_type points to the type's type, i.e. it's meta-type, > > > > also called metaclass (as "class" and "type" are really synonyms). > > > > > > Next, we have tp_base. ?That's defined as "an optional pointer to a > > > > > base type from which type properties are inherited." ?The value of > > > > > tp_base is then added to the tp_bases tuple. ?This is confusing me. On > > > > > the surface, it sound as though they're one in the same? > > > > > (I don't understand the English "one in the same" - interpreting it > > > > as "as though they should be the same") > > > > > No: tp_bases is a tuple of all base types (remember, there is multiple > > > > inheritance); tp_base (if set) provides the first base type. > > > > > > I *think* (and dir() of a subclass of type seems to back it up), that > > > > > tp_base is only at play when the object in question inherits from > > > > > type? > > > > > No - it is the normal case for single inheritance. You can leave it > > > > NULL, which means you inherit from object. > > > > > Regards, > > > > Martin > > > > Thank you! It was tp_base that was confusing me. ?The tp_bases member > > > makes sense as Python supports multiple inheritance. ?It wasn't > > > immediately clear that tp_base is there for single inheritance > > > reasons. It's all quite clear now. > > > > Is that an optimization of sorts? > > > Well, maybe not specifically for single inheritance reasons, I just > > didn't see an immediate reason to keep a separate pointer to the first > > base type. > > The reason you need a separate tp_base is because it doesn't > necessarily point to the first base type; rather, it points to the > first base type that has added any fields or slots to its internal > layout (in other words, the first type with a tp_basicsize > 8, on 32- > bit versions). ?I believe this is mainly for the benefit of Python > subclasses that define their own slots. ?The type constructor will > begin adding slots at an offset of tp_base->tp_basicsize. > > To see an example, int objects have a tp_basicsize of 12 (there are 4 > extra bytes for the interger). ?So if you multiply-inherit from int > and a Python class, int will always be tp_base. > > class A(object): pass > > class B(int,A): pass > print B.__base__ # will print > > class C(A,int): pass > print C.__base__ # will print > > A related issue is that you can't multiply inherit from two types that > have tp_basicsize > 8 unless one of them inherits from the other. > There can be only one tp_base. ?For instance: > > class D(int,tuple): pass # will raise TypeError > > class E(object): > ? ? __slots__ = ['a','b'] > > class F(object): > ? ? __slots__ = ['c','d'] > > class G(E,G): pass # will raise TypeError > > class H(E,int): pass ?# will raise TypeError > > .... > > Here's a bit more background (and by "a bit" I mean "a lot"): > > In 32-bit Python, objects of types defined in Python are usually only > 16 bytes long. ?The layout looks like this. > > instance dict > weak reference list > reference count > ob_type > > The reference count, which is always the thing that the actual > PyObject* points at, isn't actually the first item in the object's > layout. ?The dict and weakref list are stored at a lower address. > (There's a reason for it.) > > If a Python class defines any __slots__, the type constructor will add > the slots to the object's layout. > > instance dict (if there is one) > weak reference list (if there is one) > reference count > ob_type > slot > slot > slot > > Note that, because you defined __slots__, the object might not have an > instance dict or weak reference list associated with it. ?It might, > though, if one of the base classes had defined an instance dict or > weakref list. ?Or, it might not, but then a subclass might have its > onw instance dict or weakref list. ?That's why these guys are placed > at a lower address: so that they don't interfere with the layout of > subclasses. ?A subclass can add either more slots or a dict. > > Object of types defined in C can have arbitrary layout. ?For instance, > it could have a layout that looks like this: > > reference count > ob_type > PyObject* a > PyObject* b > long c > float d > instance dict > > A problem with Python slots and C fields is that, if you want to > inherit from a type with a non-trivial object layout, aside from the > dict and weakrefs, all of the subtypes have to maintain the same > layout (see Liskov substitutability for rationale). > > Subtypes can add their own fields or slots if they want, though. ?So, > if a Python subtype wants to define its own slots on top of a type > with a non-trivial object layout, it has to know which base has the > largest layout so that it doesn't use the same memory for its own > slots. ?Hence tp_base. > > Carl Banks Thank you, that was very well put. I spent some more time tracking everything down today as well. There are some useful comments in object.h, and coupled with what you've said, it all make sense now. CPython really does have a very clean code base. I've written a lot of Python and a few C extensions, but I've never dived deep enough to understand how everything really clicks. I'm one of those folks that's never happy with what the API documentation says; I've got to understand all of the nooks and crannies before I'm happy! Jeff From dsblizzard at gmail.com Sun Jan 18 20:13:39 2009 From: dsblizzard at gmail.com (dsblizzard at gmail.com) Date: Sun, 18 Jan 2009 17:13:39 -0800 (PST) Subject: How to use *.py modules instead of *.pyc? Message-ID: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> How to use *.py modules instead of *.pyc or automatically recompile all modules each time I change *.py files? Thank you in advance. From clp2 at rebertia.com Sun Jan 18 20:20:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 17:20:29 -0800 Subject: How to use *.py modules instead of *.pyc? In-Reply-To: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901181720m4dda35e6j852f6ca5a918f521@mail.gmail.com> On Sun, Jan 18, 2009 at 5:13 PM, wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? IIRC, you shouldn't need to worry about this. Python checks the modification times on the .py and .pyc files and if the .pyc is older, it regenerates the .pyc from the .py; thus ensuring that the latest version of the source file is always used. What led you to conclude otherwise? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Sun Jan 18 20:23:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 18 Jan 2009 17:23:33 -0800 (PST) Subject: How to use *.py modules instead of *.pyc? References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <040436dd-81dd-4cc4-8dab-8d1bec02e51a@w1g2000prk.googlegroups.com> On Jan 19, 12:13?pm, dsblizz... at gmail.com wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? You don't need to do anything special. If, when you import foo, foo.pyc is outdated by changes to the foo.py that is in the same directory, then foo.py will be compiled to a new foo.pyc -- otherwise compilation is unnecessary and the existing foo.pyc will be used. If you think you have a problem, it could be caused by foo.pyc being in a directory that is in sys.path but you are editing a foo.py that is not in sys.path. HTH, John From http Sun Jan 18 20:39:40 2009 From: http (Paul Rubin) Date: 18 Jan 2009 17:39:40 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> Message-ID: <7x8wp86plv.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > http://letmegooglethatforyou.com/?q=lock+free+reference+counting I found a paper by Detlefs et al describing a method which is a) patented b) can potentially lock out some threads from ever running, and c) relies on a hardware instruction (double compare and swap) that's not available on most processors. There are well known concurrent and parallel GC techniques that don't have that problem, see for example Cheng's dissertation: http://reports-archive.adm.cs.cmu.edu/anon/2001/CMU-CS-01-174.pdf GHC 6.10 uses a parallel stop-the-world gc that is simpler, I think. From clp2 at rebertia.com Sun Jan 18 20:42:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jan 2009 17:42:34 -0800 Subject: How to use *.py modules instead of *.pyc? In-Reply-To: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> References: <6070d1ce-5aa4-426a-93b1-d6916c689ba2@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901181742l6a81eba4u7e176a81dd434622@mail.gmail.com> On Sun, Jan 18, 2009 at 5:13 PM, wrote: > How to use *.py modules instead of *.pyc or automatically recompile > all modules each time I change *.py files? > Thank you in advance. Also, just for the sake of completeness (since John and I have shown that your real problem lies elsewhere), I happened to come across the `compileall` module via a Planet Python blog, which mass-compiles .py-s into .pyc-s: http://blog.doughellmann.com/2009/01/pymotw-compileall.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From address.good.until.2009.may.11 at justmail.de Sun Jan 18 21:24:22 2009 From: address.good.until.2009.may.11 at justmail.de (=?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=) Date: Mon, 19 Jan 2009 03:24:22 +0100 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: William James schrieb: > Andr? Thieme wrote: > > You make a very strong case that Lisp is very feeble at > processing data. I'm almost convinced. I somehow don?t believe you :-) > Ruby isn't feeble, so data like this is fine: > > > shall we begin? > or lotus135? 1984 times! > The 3 stooges: COBOL,LISP,FORTRAN. > 3.14, si11y L00KING > > > Extracting the unsigned integers: > > IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}} > ==>[[], [135, 1984], [3], [3, 14, 11, 0]] Just take the program I posted before and replace (.split % "\\s") with (re-seq #"\d+" %) Now that I was so kind to give you what you asked for, you will probably do the same for me and show me your Ruby code, in which you define a variable that contains the Fibonacci sequence. (def fibs (lazy-cat [0 1] (map + fibs (drop 1 fibs)))) (nth fibs 70) ==> 190392490709135 One requirement is that when you look at the n'th fib the results up to n must be memoized, so that nothing needs to be calculated again when you ask for a fib between 0 and n. And when you ask for the n+1'th it will start the calculation right from point n. Example: user> (time (nth fibs 900)) "Elapsed time: 16.898726 msecs" user> (time (nth fibs 901)) "Elapsed time: 0.268603 msecs" Andr? -- From castironpi at gmail.com Sun Jan 18 21:45:11 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 18:45:11 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <1fab9135-6de3-4625-9c78-0da62fe4d2f6@k36g2000pri.googlegroups.com> Message-ID: <1da71032-b55b-4b0a-874d-7e9deace0370@k1g2000prb.googlegroups.com> On Jan 18, 12:42?pm, andrew cooke wrote: > > ? ? sentinel = object() > > ? ? ... > > > ? ? def foo(x, y=sentinel): > > ? ? ? if y is sentinel: > > ? ? ? ? ? y = self.a > > it just struck me you could also do: > > ? ? ?def foo(self, x, *y_args) > ? ? ? ?y = y_args[0] if y_args self.a > > which more directly checks whether an argument was passed, but has the > downside of making the method signature less clear in the declaration. > > andrew Also, if you need to change your calling signature down the line, this alternative really ties your hands with regard to it. You also lose the ability to pass 'y' by keyword. George Sakkis, who I only know from the NG, has a recipe that tests a call against a function signature to determine what arguments are being passed. The 'inspect' module also has the 'getargvalues' function, which does something similar. From castironpi at gmail.com Sun Jan 18 21:56:12 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 18 Jan 2009 18:56:12 -0800 (PST) Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <6a10378f-addb-4d56-bc1b-0c382b3cb957@t26g2000prh.googlegroups.com> <582ef883-0176-4984-9521-6c1894636891@a26g2000prf.googlegroups.com> Message-ID: On Jan 18, 12:02?pm, Rob Williscroft wrote: > Aaron Brady wrote innews:582ef883-0176-4984-9521-6c1894636891 at a26g2000prf.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 10:44?am, Rob Williscroft wrote: > >> Aaron Brady wrote > >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb957 at t26g2000prh > > .googlegroups.com > >> in comp.lang.python: > > >> > It is too bad that it is so much work to detect whether 'y' was > >> > passed in the function call directly. ?However, sentinel is just as > >> > good (or nearly); at worst, you need one sentinel per argument per > >> > function, > > >> One per Module should be good enough. The only reason None doesen't > >> suffice is that it has other legitimate uses. ?Though to be honest > >> I would always use None as the sentinel if it wasn't a legitimate > >> argument. > > >> > which is possible to create, which has a specific meaning. ?If you > >> > are > >> > making systematic function calls, e.g. with a dictionary or list, > >> > you can just use the sentinel in the dictionary. > > >> IIUYC then, one sentinel is still only needed as the missing argument > >> is indicated by *both* position and value or by name and value (in > >> the case of a keyword-dictionary), so seperate distinct sentinel > >> objects aren't required, for example: > > >> SENTINEL = object() > > >> def f( a, b, c = SENTINEL, d = SENTINEL ): > >> ? print( "values: %r" % ( ( a, b, c, d ), ) ) > >> ? if c is SENTINEL: > >> ? ? print( "c is missing" ) > >> ? if d is SENTINEL: > >> ? ? print( "d is missing" ) > > >> f( *( 1, 2, SENTINEL, SENTINEL ) ) > > >> f( **dict( a = 1 , b = 2, d = 4 ) ) > > >> f( **dict( a = 1 , b = 2, d = 4, c = SENTINEL ) ) > > I don't have a concrete example, so you may prove to be right, but I'm > > not convinced. > > I'm afraid I can't think of a use case for passing default values around > eiither, and I suspect if we were to come up with one, a better solution > that didn't involve passing default values around could be found. > > > If you have one function with an argument that defaults to an empty > > list, and calls another with an argument that defaults to an empty > > dict, then what is the meaning of passing sentinel to the first one? > > Whereas, if each had their own, then passing the first one's default > > would mean the empty list, and passing the second one's default would > > mean the dict. > > If you *mean* to pass an "empty list" or "empty dict"'s you should do > it like: > > ? function_taking_list( [] ) > ? function_taking_dict( {} ) > > Its when you don't (have reason to) care that you need default arguments. 'None' isn't a valid value for many standard library functions. So, if you try to pass it meaning, "Whatever the default value you usually use is," you'll get an error. Sometimes, the functions don't even use a public sentinel, so if you want the default value, you either have to know what it is, or you can't pass anything to that parameter. This is usually possible, it just prevents making a uniform call to a function. If you need to do some calculations to determine what parameters you're going to pass, you're stuck testing their presence with 'if-else' combinations, then calling individually. From narkewoody at gmail.com Sun Jan 18 22:10:43 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 19 Jan 2009 11:10:43 +0800 Subject: Event Handling and Signal-Slot Mechanism Message-ID: Hi, Python has Signal-Slot mechanism, why he still need another mechanism Event Handling? And, in some cases, it seems only Event Handling mechanism is available, for example closeEvent(). For what case and for what reason, the python think Signal Slot is not enough and will not work? Thanks. From prologic at shortcircuit.net.au Sun Jan 18 22:29:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 13:29:16 +1000 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 1:10 PM, Steven Woody wrote: > Python has Signal-Slot mechanism, why he still need another mechanism > Event Handling? And, in some cases, it seems only Event Handling > mechanism is available, for example closeEvent(). For what case and > for what reason, the python think Signal Slot is not enough and will > not work? In what context ? What application ? cheers James From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:31:04 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:31:04 GMT Subject: function argument dependent on another function argument? References: <01834097$0$8693$c3e8da3@news.astraweb.com> <7xhc3wk4mi.fsf@ruckus.brouhaha.com> <0183a368$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 22:28:04 +0000, Steven D'Aprano wrote: > Built-ins rarely accept None as a sentinel, slice() being a conspicuous > exception. This is sometimes a nuisance when writing wrappers: > > def my_find(S, sub, start=None, end=None): > """Like string.find() only with pre-processing.""" pre_process() # > stub for something complicated if end is None and start is None: > return S.find(sub) > elif end if None: > return S.find(sub, start) > else: > return S.find(sub, start, end) Typical. As of Python 2.6, string.find accepts None as sentinels. All my beautiful, beautiful code made obsolete!!! *wink* -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:36:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:36:01 GMT Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: On Sun, 18 Jan 2009 15:11:46 -0500, Terry Reedy wrote: > andrew cooke wrote: >> Context - >> http://docs.python.org/3.0/reference/datamodel.html?highlight=data >> model#object.__iadd__ >> >> Just a suggestion I thought I'd throw out... There's a restriction in >> the language implementation on exactly what can go the left of an >> augmented arithmetic expression. >> >> For example: >>>>> a = 3 >>>>> a **= 2 >> >> is ok, but: >>>>> class Foo(): >> ... def __init__(): >> ... self.a = 3 >> ... def __ipow__(self, x): >> ... self.a **= x >> ... >>>>> Foo() **= 2 > > Calls return objects and therefore cannot be the target of an > assignment, augmented or otherwise. The target of an assignment is a > name or collection slot, both of which are grammatical constructs, not > objects. There's a practical reason too. You create a new Foo instance, mutate it with the augmented assignment operator, and then a tenth of a millisecond later the garbage collector throws it away because it has a reference count of zero. -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Jan 18 22:43:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 03:43:25 GMT Subject: Python 3: exec arg 1 References: <018342f9$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 11:06:10 -0600, Rob Williscroft wrote: > You must have missed the subject line: "Re: Python 3: exec arg 1" Doh! -- Steven From gopalm at infotechsw.com Mon Jan 19 00:50:07 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Mon, 19 Jan 2009 11:20:07 +0530 Subject: problem in implementing multiprocessing In-Reply-To: References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> Message-ID: <0C740C10A79444BF8F5B623C58E12D72@pwit.com> i know this is not an io - bound problem, i am creating heavy objects in the process and add these objects in to queue and get that object in my main program using queue. you can test the this sample code import time from multiprocessing import Process, Queue class Data(object): def __init__(self): self.y = range(1, 1000000) def getdata(queue): data = Data() queue.put(data) if __name__=='__main__': t1 = time.time() d1 = Data() d2 = Data() t2 = time.time() print "without multiProcessing total time:", t2-t1 #multiProcessing queue = Queue() Process(target= getdata, args=(queue, )).start() Process(target= getdata, args=(queue, )).start() s1 = queue.get() s2 = queue.get() t2 = time.time() print "multiProcessing total time::", t2-t1 -----Original Message----- From: James Mills [mailto:prologic at shortcircuit.net.au] Sent: Saturday, January 17, 2009 10:37 AM To: gopal mishra Cc: python-list at python.org Subject: Re: problem in implementing multiprocessing On Fri, Jan 16, 2009 at 7:16 PM, gopal mishra wrote: > I create two heavy objects sequentially without using multipleProcessing > then creation of the objects takes 2.5 sec.if i create these two objects in > separate process then total time is 6.4 sec. > > i am thinking it is happening due to the pickling and unpickling of the > objects.if i am right then what could be the sollution. > > my system configuration: > dual-core processor > winXP > python2.6.1 System specs in this case are irrelevant. What you are experiencing is most likely an I/O bound problem - using multiprocessing may likely not help you solve the problem any faster because of your I/O constraint. cheers James From prologic at shortcircuit.net.au Mon Jan 19 01:00:45 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 16:00:45 +1000 Subject: problem in implementing multiprocessing In-Reply-To: <0C740C10A79444BF8F5B623C58E12D72@pwit.com> References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Mon, Jan 19, 2009 at 3:50 PM, gopal mishra wrote: > i know this is not an io - bound problem, i am creating heavy objects in the > process and add these objects in to queue and get that object in my main > program using queue. > you can test the this sample code > import time > from multiprocessing import Process, Queue > > class Data(object): > def __init__(self): > self.y = range(1, 1000000) > > def getdata(queue): > data = Data() > queue.put(data) > > if __name__=='__main__': > t1 = time.time() > d1 = Data() > d2 = Data() > t2 = time.time() > print "without multiProcessing total time:", t2-t1 > #multiProcessing > queue = Queue() > Process(target= getdata, args=(queue, )).start() > Process(target= getdata, args=(queue, )).start() > s1 = queue.get() > s2 = queue.get() > t2 = time.time() > print "multiProcessing total time::", t2-t1 The reason your code above doesn't work as you expect and the multiprocessing part takes longer is because your Data objects are creating a list (a rather large list) of ints. Use xrange instead of range. Here's what I get (using xrange): $ python test.py without multiProcessing total time: 1.50203704834e-05 multiProcessing total time:: 0.116630077362 cheers James From narkewoody at gmail.com Mon Jan 19 02:49:51 2009 From: narkewoody at gmail.com (Steven Woody) Date: Mon, 19 Jan 2009 15:49:51 +0800 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 11:29 AM, James Mills wrote: > On Mon, Jan 19, 2009 at 1:10 PM, Steven Woody wrote: >> Python has Signal-Slot mechanism, why he still need another mechanism >> Event Handling? And, in some cases, it seems only Event Handling >> mechanism is available, for example closeEvent(). For what case and >> for what reason, the python think Signal Slot is not enough and will >> not work? > > In what context ? What application ? > I am reading mark summerfield's book Rapid GUI Programming with Python and Qt, chapter 6. In the example code, it inserted customized behavior when user selects file->exit by overriding closeEvent() event handler, but in other context, when a behavior is needed to handle user interaction, the single-slot mechanism is always used. From s.selvamsiva at gmail.com Mon Jan 19 03:12:50 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 19 Jan 2009 13:42:50 +0530 Subject: python resource management Message-ID: Hi all, I am running a python script which parses nearly 22,000 html files locally stored using BeautifulSoup. The problem is the memory usage linearly increases as the files are being parsed. When the script has crossed parsing 200 files or so, it consumes all the available RAM and The CPU usage comes down to 0% (may be due to excessive paging). We tried 'del soup_object' and used 'gc.collect()'. But, no improvement. Please guide me how to limit python's memory-usage or proper method for handling BeautifulSoup object in resource effective manner -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 03:58:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 19 Jan 2009 18:58:33 +1000 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: References: Message-ID: On Mon, Jan 19, 2009 at 5:49 PM, Steven Woody wrote: > I am reading mark summerfield's book Rapid GUI Programming with Python > and Qt, chapter 6. In the example code, it inserted customized > behavior when user selects file->exit by overriding closeEvent() event > handler, but in other context, when a behavior is needed to handle > user interaction, the single-slot mechanism is always used. Not having read the book myself I can't really comment, except that I -am- sure that this is specific to PyQt (at least the slots). Most GUI frameworks I know of employ a common architecture - one of an event-driven nature. cheers James From pavlovevidence at gmail.com Mon Jan 19 04:09:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 19 Jan 2009 01:09:30 -0800 (PST) Subject: problem in implementing multiprocessing References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Jan 18, 10:00?pm, "James Mills" wrote: > On Mon, Jan 19, 2009 at 3:50 PM, gopal mishra wrote: > > i know this is not an io - bound problem, i am creating heavy objects in the > > process and add these objects in to queue and get that object in my main > > program using queue. > > you can test the this sample code > > import time > > from multiprocessing import Process, Queue > > > class Data(object): > > ? ?def __init__(self): > > ? ? ? ?self.y = range(1, 1000000) > > > def getdata(queue): > > ? ?data = Data() > > ? ?queue.put(data) > > > if __name__=='__main__': > > ? ?t1 = time.time() > > ? ?d1 = Data() > > ? ?d2 = Data() > > ? ?t2 = time.time() > > ? ?print "without multiProcessing total time:", t2-t1 > > ? ?#multiProcessing > > ? ?queue = Queue() > > ? ?Process(target= getdata, args=(queue, )).start() > > ? ?Process(target= getdata, args=(queue, )).start() > > ? ?s1 = queue.get() > > ? ?s2 = queue.get() > > ? ?t2 = time.time() > > ? ?print "multiProcessing total time::", t2-t1 > > The reason your code above doesn't work as you > expect and the multiprocessing part takes longer > is because your Data objects are creating a list > (a rather large list) of ints. I'm pretty sure gopal is creating a deliberately large object to use as a test case, so switching to xrange isn't going to help here. Since multiprocessing serializes and deserializes the data while passing it from process to process, passing very large objects would have a very high latency and overhead. IOW, gopal's diagnosis is correct. It's just not practical to share very large objects among seperate processes. For simple data like large arrays of floating point numbers, the data can be shared with an mmaped file or some other memory-sharing scheme, but actual Python objects can't be shared this way. If you have complex data (networks and heirarchies and such) it's a lot harder to share this information among processes. Carl Banks From see.signature at no.spam Mon Jan 19 04:21:52 2009 From: see.signature at no.spam (Eric Brunel) Date: Mon, 19 Jan 2009 10:21:52 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Fri, 16 Jan 2009 17:49:50 +0100, Terry Reedy wrote: > Eric Brunel wrote: >> On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy >> wrote: >>> Eric Brunel wrote: >> [snip]>> And BTW, if this is actually a bug, where can I report it? >>> >>> bugs.python.org >> Thanks. I reported the problem. > > When you report that you reported to problem to the tracker (a good > idea), please include link so anyone reading this thread can jump there > to continue with followup there. Here it is: http://bugs.python.org/issue4961 Thanks again! -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From see.signature at no.spam Mon Jan 19 04:24:09 2009 From: see.signature at no.spam (Eric Brunel) Date: Mon, 19 Jan 2009 10:24:09 +0100 Subject: Possible bug in Tkinter - Python 2.6 References: Message-ID: On Sun, 18 Jan 2009 01:57:12 +0100, Jos? Matos wrote: > On Friday 16 January 2009 09:47:36 Eric Brunel wrote: >> What do you mean by 'works'...? > > The usual meaning, I think. :-) > > Click "Yes" and the program prints True, click "No" and the programs > prints > "False". This is not the procedure I describe in the original post. The first time, it works for me too. It's only after I used the file dialog that it stops working. >> You don't have the problem? It doesn't ? >> change a thing for me... > > Notice that I am running the system python, that at least is different. Well, unless you're on a platform where a modified Python version is installed, it shouldn't. If you have the same version as mine, the bug should be there too... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From rNOSPAMon at flownet.com Mon Jan 19 04:28:21 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 19 Jan 2009 01:28:21 -0800 Subject: Yaro vs WebOb Message-ID: I'm selecting infrastructure for a web development and I've found two lightweight frameworks that seem to offer a lot of bang-for-the-byte: Yaro and WebOb. I'm wondering if anyone here has used either or both and has opinions about them. What has been your experience with them? Which do you prefer? Thanks, rg From nick at craig-wood.com Mon Jan 19 04:32:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 19 Jan 2009 03:32:03 -0600 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > gmane.comp.python.general > > > I ran a few tests on the new Python 2.6 multiprocessing module before > > migrating a threading code, and found out the locking code is not > > working well. In this case, a pool of 5 processes is running, each > > trying to get the lock and releasing it after waiting 0.2 seconds > > (action is repeated twice). It looks like the multiprocessing lock > > allows multiple locking after the second pass. Running the exact same > > code with threads works correctly. > > I've tested your code on Windows and I think the problem is on the Queue > class. If you replace the Queue with some print statements or write to a > log file, the sequence lock/release is OK. > You should file a bug report on http://bugs.python.org/ A little bit of instrumentation in the code reveals the problem. The Queue class doesn't always return the items in the order that they were put in. This should probably be either documented or fixed! I suspect it is impossible to fix for a multi-producer Queue though. The first number is time since the program started. Tested under linux. 0.048810 [proc0] Got lock 0.248679 [proc0] Released lock 0.248858 [proc0] Got lock 0.448666 [proc0] Released lock 0.448859 [proc2] Got lock 0.648639 [proc2] Released lock 0.648893 [proc3] Got lock 0.848633 [proc3] Released lock 0.848767 [proc3] Got lock 1.048635 [proc3] Released lock 1.049090 [proc1] Got lock 1.248617 [proc1] Released lock 1.248743 [proc1] Got lock 1.448634 [proc1] Released lock 1.448810 [proc4] Got lock 1.648674 [proc4] Released lock 1.648831 [proc4] Got lock 1.849867 [proc2] Got lock <--- out of order 1.849679 [proc4] Released lock <--- out of order 2.048683 [proc2] Released lock #!/usr/bin/python -*- coding: utf-8 -*- from multiprocessing import Process, Queue, Lock from Queue import Empty from threading import Thread import time start = time.time() def now(): return time.time() - start class test_lock_process(object): def __init__(self, lock, id, queue): self.lock = lock self.id = id self.queue = queue self.read_lock() def read_lock(self): for i in xrange(2): self.lock.acquire() self.queue.put('%9.6f [proc%d] Got lock' % (now(), self.id)) time.sleep(.2) self.queue.put('%9.6f [proc%d] Released lock' % (now(), self.id)) self.lock.release() def test_lock(processes=10, lock=Lock(), process=True, queue=None): print_result = False if queue == None: print_result = True queue = Queue() threads = [] for i in xrange(processes): if process: threads.append(Process(target=test_lock_process, args=(lock,i,queue,))) else: threads.append(Thread(target=test_lock_process, args=(lock,i,queue,))) for t in threads: t.start() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == "__main__": #test_lock(processes=5, process=True) test_lock(processes=5) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From funfullson at gmail.com Mon Jan 19 05:15:36 2009 From: funfullson at gmail.com (amin) Date: Mon, 19 Jan 2009 02:15:36 -0800 (PST) Subject: issue Message-ID: Hi dears. I started programing with python and want to use a suitable database.But I Know nothing about them.please introduse one to me. thanks. From sri_annauni at yahoo.co.in Mon Jan 19 05:17:00 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Mon, 19 Jan 2009 15:47:00 +0530 (IST) Subject: Getting OSError, Could someone suggest? Message-ID: <177800.90793.qm@web7905.mail.in.yahoo.com> Hi, ?I have written a script which will spawn more than 200 no of subprocesses. I have used subprocess.Popen to do that. ?OSError: [Error 24]?Too many open files. Could someone help me in fixing this error? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From Jean-Paul.VALENTIN at ingenico.com Mon Jan 19 05:21:33 2009 From: Jean-Paul.VALENTIN at ingenico.com (Jean-Paul VALENTIN) Date: Mon, 19 Jan 2009 11:21:33 +0100 Subject: output problem Message-ID: <72CF8F2B2766084DBD7AEAFCAE4A3B790486EC4A@frsnprexc1.usr.ingenico.loc> true, Windows automatically adds a newline after the program output. But maybe there is a workaround? When you launch x.bat containing no char, windows adds a newline after the program output. But when you launch x.bat finishing with at least one CRLF, windows does not add a newline after the program output. I am not sure though whether it is a windows feature... So maybe with Python a similar condition could allow for obtaining the same result... About Ingenico: Ingenico is the world's leading provider of payment solutions, with over 15 million terminals deployed across the globe. Delivering the very latest secure electronic payment technologies, transaction management and the widest range of value added services, Ingenico is shaping the future direction of the payment solutions market. Leveraging on its global presence and local expertise, Ingenico is reinforcing its leadership by taking banks and businesses beyond payment through offering comprehensive solutions, a true source of differentiation and new revenues streams. This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. P Please consider the environment before printing this e-mail -------------- next part -------------- An HTML attachment was scrubbed... URL: From apardon at forel.vub.ac.be Mon Jan 19 05:34:02 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Jan 2009 10:34:02 GMT Subject: I don't understand this syntax error Message-ID: I'm probably looking right over it, but for the moment I'm stumped. Can someone explain what is wrong. I'm running python 2.5.2 here This is the code: class vslice(object): def __init__(self, fun): self.fun = fun def __getitem__(self, inx): if not isinstance(inx, tuple): inx = inx, return self.fun(*inx) @vslice class IdSet(object): def __init__(self, *args): self.lst = [(sl.start, sl.stop) for sl in args] def __contains__(self, item): for low, high in self.lst: if low <= item < high: return True return False def __str__(self): return '[' + ', '.join('%d:%d' % sl for sl in self.lst) + ']' #IdSet = vslice(IdSet) idset = IdSet[1:3, 6:9] print idset for i in xrange(10): print i, i in idset This is the error I get: File "vslice.py", line 12 class IdSet(object): ^ SyntaxError: invalid syntax From __peter__ at web.de Mon Jan 19 05:46:45 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jan 2009 11:46:45 +0100 Subject: I don't understand this syntax error References: Message-ID: Antoon Pardon wrote: > I'm probably looking right over it, but for the moment > I'm stumped. Can someone explain what is wrong. I'm running > python 2.5.2 here > > This is the code: > @vslice > class IdSet(object): Class decorators require Python 2.6 Peter From speedup at gmail.com Mon Jan 19 05:53:57 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Mon, 19 Jan 2009 02:53:57 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> Message-ID: <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> On Jan 17, 11:32?am, "Gabriel Genellina" wrote: > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > gmane.comp.python.general > > > I ran a few tests on the new Python 2.6multiprocessingmodule before > > migrating a threading code, and found out the locking code is not > > working well. In this case, a pool of 5 processes is running, each > > trying to get the lock and releasing it after waiting 0.2 seconds > > (action is repeated twice). It looks like themultiprocessinglock > > allows multiple locking after the second pass. Running the exact same > > code with threads works correctly. > > I've tested your code on Windows and I think the problem is on the Queue > class. If you replace the Queue with some print statements or write to a > log file, the sequence lock/release is OK. > You should file a bug report onhttp://bugs.python.org/ > > -- > Gabriel Genellina Thanks for your help gabriel, I just tested it without the queue and it works! I'll file a bug about the queues. Fred For those interested, the code that works (well, it always did, but this shows the real result): class test_lock_process(object): def __init__(self, lock): self.lock = lock self.read_lock() def read_lock(self): for i in xrange(5): self.lock.acquire() logging.info('Got lock') time.sleep(.2) logging.info('Released lock') self.lock.release() if __name__ == "__main__": logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % (message)s', level=logging.DEBUG) lock = Lock() processes = [] for i in xrange(2): processes.append(Process(target=test_lock_process, args= (lock,))) for t in processes: t.start() for t in processes: t.join() From psteiger at dcc.ufba.br Mon Jan 19 06:01:53 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Mon, 19 Jan 2009 03:01:53 -0800 Subject: issue In-Reply-To: References: Message-ID: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> What kind of database do you need? Relational Databases? The three major databases you can work with python are SQLite, MySQL and PostgreSQL (favorite of mine.) SQLite already comes with python. Try: >>> import sqlite3 SQLite is... Lite. All the informations are stored in a single file. MySQL and PostgreSQL are more complete databases that run as servers on the machine, and you can use python bindings for both. (psycopg2 for postgres, and i forgot what binds mysql to python at the moment.) I guess you should google for psycopg2, read a little bit about the SQL syntax (though you may not need to use them directly, it`s good to understand what happens behind the bindings.) The PostgreSQL docs are quite good. Sorry for not providing any links. They should be easy to find if you google for them. 2009/1/19 amin > Hi dears. > I started programing with python and want to use a suitable > database.But I Know nothing about them.please introduse one to me. > thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Jan 19 06:16:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 19 Jan 2009 05:16:33 -0600 Subject: issue In-Reply-To: References: Message-ID: <49746111.7080608@tim.thechases.com> > I started programing with python and want to use a suitable > database.But I Know nothing about them.please introduse one to > me. thanks. Since you're just starting out, I'd just use the built-in (as of Python2.5) sqlite >>> import sqlite3 >>> c = sqlite3.connect('tmp/test.db') >>> cur = c.cursor() >>> cur.execute('create table test(id int primary key)') >>> cur.execute('insert into test values (42)') >>> cur.execute('insert into test values (3141)') >>> cur.execute('select * from test') >>> cur.fetchall() [(42,), (3141,)] That will allow you to experiment. You can later scale up to something like a MySQL, PostgreSQL or some other DB connector. -tkc From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 06:20:55 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 11:20:55 GMT Subject: Getting OSError, Could someone suggest? References: Message-ID: <01845888$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 15:47:00 +0530, srinivasan srinivas wrote: > Hi, > ?I have written a script which will spawn more than 200 no of > ?subprocesses. I have used subprocess.Popen to do that. > > ?OSError: [Error 24]?Too many open files. > > Could someone help me in fixing this error? Open fewer files. As I understand it, each subprocess counts as at least one open file. You may be able to increase the number of open files, but that will be dependent on the operating system you are using. -- Steven From psteiger at dcc.ufba.br Mon Jan 19 06:33:59 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Mon, 19 Jan 2009 03:33:59 -0800 Subject: Getting OSError, Could someone suggest? In-Reply-To: <01845888$0$20652$c3e8da3@news.astraweb.com> References: <01845888$0$20652$c3e8da3@news.astraweb.com> Message-ID: <909ef3300901190333i7f444d5dy161e11dd0b271d76@mail.gmail.com> 2009/1/19 Steven D'Aprano > On Mon, 19 Jan 2009 15:47:00 +0530, srinivasan srinivas wrote: > > > Hi, > > I have written a script which will spawn more than 200 no of > > subprocesses. I have used subprocess.Popen to do that. > > > > OSError: [Error 24] Too many open files. > > > > Could someone help me in fixing this error? > > Open fewer files. > > As I understand it, each subprocess counts as at least one open file. You > may be able to increase the number of open files, but that will be > dependent on the operating system you are using. > Yeah. By his question i supposed that opening less files was not an 'ok' solution. But of course you can do that, and it is prefered if it won't interfere negatively in your program. -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco at sferacarta.com Mon Jan 19 06:35:18 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 19 Jan 2009 12:35:18 +0100 Subject: English-like Python In-Reply-To: References: Message-ID: The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? Many have tried that in the decades, but IMHO the best approach is to just rename the language. We cannot do that since it's already been trademarked for that very reason. From Wikipedia: ENGLISH (actually trademarked in all caps) is a database retrieval and reporting language somewhat like SQL, but with no actual programming or update capabilities. Originally released by Microdata in 1973 and named so that the company's brochures could claim that developers could generate reports on their implementation of the Pick operating system using English. From castironpi at gmail.com Mon Jan 19 06:52:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 19 Jan 2009 03:52:47 -0800 (PST) Subject: problem in implementing multiprocessing References: <89E5181815F74966B59B475F9B4ED600@pwit.com> <66510985287744829EE3AD881CE824B2@pwit.com> <0C740C10A79444BF8F5B623C58E12D72@pwit.com> Message-ID: On Jan 19, 3:09?am, Carl Banks wrote: snip > Since multiprocessing serializes and deserializes the data while > passing > it from process to process, passing very large objects would have a > very > high latency and overhead. ?IOW, gopal's diagnosis is correct. ?It's > just not practical to share very large objects among seperate > processes. You could pass composite objects back and forth by passing pieces back and forth. You'd have to construct it so as not to need access to the entire data structure in any one piece; that is, only need access to other small pieces. > For simple data like large arrays of floating point numbers, the data > can be shared with an mmaped file or some other memory-sharing scheme, > but actual Python objects can't be shared this way. ?If you have > complex > data (networks and heirarchies and such) it's a lot harder to share > this > information among processes. It wouldn't hurt to have a minimal set of Python objects that are 'persistent live', that is, stored out of memory in their native form. The only problem is, they can't contain references to volatile objects. (I don't believe POSH addresses this.) From charlie137 at gmail.com Mon Jan 19 06:59:17 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 03:59:17 -0800 (PST) Subject: tasklet library based on PEP 0342 Message-ID: Hello all, Using new features of python generators, as described in PEP 0342, it is possible to write some sort of "tasklets" in a maner very similar to stackless python, but running on cpython. For example : @tasklet def my_task(): yield Timer(10) yield "result" @tasklet def other_task(): result = yield my_task() other_task().start(callback=on_return) I wrote an implementation of this in the scope of an open source project for openmoko [0], there is also an other very similar implementation from the kiwi project [1]. This kind of tool is very useful, but unfortunately there is no standard library that would provide a unified way to use it independently of the underlying event loop. Does someone know if a similar library could eventually be added into python standard libraries ? Would it be accepted as a PEP ? Guillaume [0] http://git.openmoko.org/?p=tichy.git;a=blob;f=tichy/tasklet.py [1] http://www.async.com.br/projects/kiwi/api/kiwi.tasklet.html From phillip.oldham at gmail.com Mon Jan 19 07:04:23 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Mon, 19 Jan 2009 04:04:23 -0800 (PST) Subject: Can I run an operation on an object's attribute when reading? Message-ID: Is it possible to automatically run an operation on a object's attribute when reading? For instance, if I have the following: class Item(object): tags = ['default','item'] item = Item() desc = item.tags When I'm reading the item.tags, I'd like to automagically have the value converted to a string, eg: "default item". I know I could write a getter to do this for me, but I'd like to avoid that if possible on this occasion. Any help would be great! Thanks. From clp2 at rebertia.com Mon Jan 19 07:15:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 04:15:05 -0800 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: References: Message-ID: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> On Mon, Jan 19, 2009 at 4:04 AM, Phillip B Oldham wrote: > Is it possible to automatically run an operation on a object's > attribute when reading? For instance, if I have the following: > > class Item(object): > tags = ['default','item'] > > item = Item() > > desc = item.tags > > When I'm reading the item.tags, I'd like to automagically have the > value converted to a string, eg: "default item". I know I could write > a getter to do this for me, but I'd like to avoid that if possible on > this occasion. Assuming I'm interpreting you correctly (you're going to have to use something like a getter): class Item(object): def __init__(self): self._tags = ['default', 'item'] @property def tags(self): return ' '.join(self._tags) print Item().tags #==> default item Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From phillip.oldham at gmail.com Mon Jan 19 07:22:39 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Mon, 19 Jan 2009 12:22:39 +0000 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> Message-ID: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: > Assuming I'm interpreting you correctly (you're going to have to use > something like a getter): Thanks, but I'm looking for a way to do it *without* using a getter as I don't have easy access to the class (its being generated for me elsewhere). Essentially I'd like to overwrite (if possible) the default behavior when returning certain attributes on certain objects. From bignose+hates-spam at benfinney.id.au Mon Jan 19 07:33:14 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 19 Jan 2009 23:33:14 +1100 Subject: Can I run an operation on an object's attribute when reading? References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> Message-ID: <87ocy35vcl.fsf@benfinney.id.au> Phillip B Oldham writes: > Thanks, but I'm looking for a way to do it *without* using a getter > as I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain > objects. You can override the behaviour of a class by defining a subclass. class UntouchableTypeWrapper(UntouchableType): def _foo_get(self): return str(self.foo) foo = property(_foo_get) Then you can create instances of the wrapper class where you want the new behaviour. -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From clp2 at rebertia.com Mon Jan 19 07:34:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 04:34:12 -0800 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <50697b2c0901190434p1170414fi3255d104077b457f@mail.gmail.com> On Mon, Jan 19, 2009 at 4:22 AM, Phillip B Oldham wrote: > On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: >> Assuming I'm interpreting you correctly (you're going to have to use >> something like a getter): > > Thanks, but I'm looking for a way to do it *without* using a getter as > I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain objects. To my knowledge, you can't really "overwrite" that behavior without editing the class (or how it's generated). The next closest thing would be to write a proxy class that defines a __getattr__ method implementing the semantics you want. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bignose+hates-spam at benfinney.id.au Mon Jan 19 07:38:51 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 19 Jan 2009 23:38:51 +1100 Subject: Can I run an operation on an object's attribute when reading? References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <87ocy35vcl.fsf@benfinney.id.au> Message-ID: <87k58r5v38.fsf@benfinney.id.au> Ben Finney writes: > You can override the behaviour of a class by defining a subclass. > > class UntouchableTypeWrapper(UntouchableType): > > def _foo_get(self): > return str(self.foo) > > foo = property(_foo_get) Which, I realise now, won't work (and I didn't test it). But hopefully the idea is clear. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we have nothing to fear but fear itself, why does | _o__) Elanore Roosevelt wear that spooky mask?? ?_Pinky and The Brain_ | Ben Finney From mikehartl at web.de Mon Jan 19 07:39:10 2009 From: mikehartl at web.de (Michael Hartl) Date: Mon, 19 Jan 2009 13:39:10 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <4974746E.6060208@web.de> Phillip B Oldham schrieb: > On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: > >> Assuming I'm interpreting you correctly (you're going to have to use >> something like a getter): >> > > Thanks, but I'm looking for a way to do it *without* using a getter as > I don't have easy access to the class (its being generated for me > elsewhere). Essentially I'd like to overwrite (if possible) the > default behavior when returning certain attributes on certain objects. > -- > http://mail.python.org/mailman/listinfo/python-list > You could still add the getter to the class after it has been defined if that's your only problem with using a getter: class Item(object): tags = ['default','item'] @property def tags(self): return ' '.join(self.tags) setattr(Item, "Tags", tags) print Item().Tags #==> default item But I don't think there's a way to do it without a different name (here "tags" - "Tags"), is there? From matt.j.warren at gmail.com Mon Jan 19 07:47:21 2009 From: matt.j.warren at gmail.com (AlienBaby) Date: Mon, 19 Jan 2009 04:47:21 -0800 (PST) Subject: Simple image manipulation question Message-ID: <352e283b-76ed-469f-b72a-578685c2f6c6@q30g2000prq.googlegroups.com> Hi, Could anyone point me toward the right modules etc.. that would help with; loading an image file rendering some text onto that image saveing the image file I've looked into Tkinter, but that seems to require working with canvases etc.., but I do not need to actually display the image, just render some text onto it and save it again. PIL looked promising, but I couldn't see how to put text into the image once loaded. Any help much appreciated, Thanks, Matt. From ra.ravi.rav at gmail.com Mon Jan 19 07:47:39 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Mon, 19 Jan 2009 04:47:39 -0800 (PST) Subject: Difference between Python 2.2.2 and Python 2.5 References: <018344b9$0$8693$c3e8da3@news.astraweb.com> Message-ID: <78a8e37b-51bd-47c3-9734-fb8483429580@u18g2000pro.googlegroups.com> On Jan 18, 8:44?pm, Steven D'Aprano wrote: > On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: > > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I > > know is Python 2.5 ?. > > > Can you please tell me differences between the two so that I can save > > myself from incompatible code. > > Everything new mentioned here: > > http://www.python.org/doc/2.5/whatsnew/whatsnew25.htmlhttp://www.python.org/doc/2.4/whatsnew/whatsnew24.htmlhttp://www.python.org/doc/2.3/whatsnew/whatsnew23.html > > won't exist in Python 2.2. > > -- > Steven This is a list too big! Is there any checker which can be applied to the Python code. (of course any solution other than running python 2.2 over the code) From bearophileHUGS at lycos.com Mon Jan 19 07:57:35 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 19 Jan 2009 04:57:35 -0800 (PST) Subject: Simple image manipulation question References: <352e283b-76ed-469f-b72a-578685c2f6c6@q30g2000prq.googlegroups.com> Message-ID: AlienBaby: > PIL looked promising, but I couldn't see how to put text into the > image once loaded. A 15-second long Google search gives me: http://nedbatchelder.com/blog/200801/truly_transparent_text_with_pil.html Bye, bearophile From gagsl-py2 at yahoo.com.ar Mon Jan 19 07:58:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 10:58:39 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald escribi?: > Ah yes, with your help I seem to have solved my own problem. I had > PYTHONPATH defined to point to the 2.5 directory. Best to avoid setting PYTHONPATH at all. If you install new packages into a standard place like site-packages, and use .pth files for those libraries that aren't packages, there should be no need to set PYTHONPATH. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 19 07:58:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 10:58:39 -0200 Subject: import urllib2 fails with Python 2.6.1 on Vista References: Message-ID: En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald escribi?: > Ah yes, with your help I seem to have solved my own problem. I had > PYTHONPATH defined to point to the 2.5 directory. Best to avoid setting PYTHONPATH at all. If you install new packages into a standard place like site-packages, and use .pth files for those libraries that aren't packages, there should be no need to set PYTHONPATH. -- Gabriel Genellina From speedup at gmail.com Mon Jan 19 08:16:22 2009 From: speedup at gmail.com (=?ISO-8859-1?Q?Fr=E9d=E9ric_Sagnes?=) Date: Mon, 19 Jan 2009 05:16:22 -0800 (PST) Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> Message-ID: <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> On Jan 19, 11:53?am, Fr?d?ric Sagnes wrote: > On Jan 17, 11:32?am, "Gabriel Genellina" > wrote: > > > > > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo > > gmane.comp.python.general > > > > I ran a few tests on the new Python 2.6multiprocessingmodule before > > > migrating a threading code, and found out the locking code is not > > > working well. In this case, a pool of 5 processes is running, each > > > trying to get the lock and releasing it after waiting 0.2 seconds > > > (action is repeated twice). It looks like themultiprocessinglock > > > allows multiple locking after the second pass. Running the exact same > > > code with threads works correctly. > > > I've tested your code on Windows and I think the problem is on the Queue > > class. If you replace the Queue with some print statements or write to a > > log file, the sequence lock/release is OK. > > You should file a bug report onhttp://bugs.python.org/ > > > -- > > Gabriel Genellina > > Thanks for your help gabriel, I just tested it without the queue and > it works! I'll file a bug about the queues. > > Fred > > For those interested, the code that works (well, it always did, but > this shows the real result): > > class test_lock_process(object): > ? ? def __init__(self, lock): > ? ? ? ? self.lock = lock > ? ? ? ? self.read_lock() > > ? ? def read_lock(self): > ? ? ? ? for i in xrange(5): > ? ? ? ? ? ? self.lock.acquire() > ? ? ? ? ? ? logging.info('Got lock') > ? ? ? ? ? ? time.sleep(.2) > ? ? ? ? ? ? logging.info('Released lock') > ? ? ? ? ? ? self.lock.release() > > if __name__ == "__main__": > ? ? logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % > (message)s', level=logging.DEBUG) > > ? ? lock = Lock() > > ? ? processes = [] > ? ? for i in xrange(2): > ? ? ? ? processes.append(Process(target=test_lock_process, args= > (lock,))) > > ? ? for t in processes: > ? ? ? ? t.start() > > ? ? for t in processes: > ? ? ? ? t.join() Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, referencing this thread. -- Fr?d?ric Sagnes From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 08:19:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 13:19:10 GMT Subject: Can I run an operation on an object's attribute when reading? References: Message-ID: <0184743f$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 04:04:23 -0800, Phillip B Oldham wrote: > Is it possible to automatically run an operation on a object's attribute > when reading? For instance, if I have the following: > > class Item(object): > tags = ['default','item'] > > item = Item() > > desc = item.tags > > When I'm reading the item.tags, I'd like to automagically have the value > converted to a string, eg: "default item". I know I could write a getter > to do this for me, but I'd like to avoid that if possible on this > occasion. When all you have is a hammer, everything looks like a nail... Why do you have to read item.tags directly? Just write a function and call it instead of direct attribute access. This is the simplest, easiest solution with the fewest side-effects. def get_tags(item): return ' '.join(item.tags) desc = get_tags(item) If you don't like that solution, monkey-patch the class with a getter: @property def tags(self): return " ".join(self._tags) Item._tags = Item.tags Item.tags = tags This is dangerous, because other classes may expect Item.tags to be a list. Better to create your own accessor method: def get_tags(self): return " ".join(self.tags) Item.get_tags = get_tags item = Item() desc = item.get_tags() If you don't like monkey-patching (and you probably shouldn't), then write a proxy class that delegates to the original: _Item = Item class Item(object): def __init__(self, *args): self.__dict__['_item'] = _Item(*args) @property def tags(self): return ' '.join(self._item.tags) def __getattr__(self, attr): return getattr(self._item, attr) def __setattr__(self, attr, value): setattr(self._item, attr, value) I dare say there's a metaclass solution too, but I'm not crazy enough to do that. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 08:23:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 13:23:12 GMT Subject: Difference between Python 2.2.2 and Python 2.5 References: <018344b9$0$8693$c3e8da3@news.astraweb.com> <78a8e37b-51bd-47c3-9734-fb8483429580@u18g2000pro.googlegroups.com> Message-ID: <01847531$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 04:47:39 -0800, Ravi wrote: > On Jan 18, 8:44?pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: >> > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while >> > what I know is Python 2.5 ?. >> >> > Can you please tell me differences between the two so that I can save >> > myself from incompatible code. >> >> Everything new mentioned here: >> >> http://www.python.org/doc/2.5/whatsnew/whatsnew25.htmlhttp:// www.python.org/doc/2.4/whatsnew/whatsnew24.htmlhttp://www.python.org/ doc/2.3/whatsnew/whatsnew23.html >> >> won't exist in Python 2.2. >> >> -- >> Steven > > This is a list too big! It's not that big. It's only three versions different. > Is there any checker which can be applied to the Python code. (of course > any solution other than running python 2.2 over the code) What's wrong with running Python 2.2 over the code? That's the best way to discover what doesn't work. -- Steven From gervaz at gmail.com Mon Jan 19 08:23:52 2009 From: gervaz at gmail.com (gervaz) Date: Mon, 19 Jan 2009 05:23:52 -0800 (PST) Subject: Regexp Message-ID: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Hi all, I need to find all the address in a html source page, I'm using: 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)()?' but the [^]+ pattern retrieve all the strings not containing < or / or a etc, although I just not want the word "". How can I specify: 'do not search the string "blabla"?' Thanks From scott.p.macdonald at gmail.com Mon Jan 19 08:33:03 2009 From: scott.p.macdonald at gmail.com (Scott MacDonald) Date: Mon, 19 Jan 2009 06:33:03 -0700 Subject: import urllib2 fails with Python 2.6.1 on Vista In-Reply-To: References: Message-ID: I think I set it a long time ago to get the python VTK bindings working... On Mon, Jan 19, 2009 at 5:58 AM, Gabriel Genellina wrote: > En Sun, 18 Jan 2009 16:08:07 -0200, Scott MacDonald < > scott.p.macdonald at gmail.com> escribi?: > > Ah yes, with your help I seem to have solved my own problem. I had >> PYTHONPATH defined to point to the 2.5 directory. >> > > Best to avoid setting PYTHONPATH at all. If you install new packages into a > standard place like site-packages, and use .pth files for those libraries > that aren't packages, there should be no need to set PYTHONPATH. > > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Mon Jan 19 08:50:54 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 19 Jan 2009 05:50:54 -0800 (PST) Subject: Python Style Guide Questions - Contd. Message-ID: Hi, I have some more questions about python code styling. 1. Global Variables: In my code, I am using some global variables. Now, when I ran PyLint, it raised convention errors mentioning that they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that mentioned. Please let me know whether that is the usual styling mechanism which is used. 2. I have many loops wherein I define a variable as just a counter. for x in range(counter): do_something() Please note that I am not using x anywhere in the program. Pylint again raises warnings saying that the variable should be used. Should I disregard it or use the default variable _ ? for _ in range(counter): do_something() pylint does not raise errors for those. Are there any issues in using _ ? From jnoller at gmail.com Mon Jan 19 09:00:49 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 19 Jan 2009 09:00:49 -0500 Subject: Python 2.6's multiprocessing lock not working on second use? In-Reply-To: <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: <4222a8490901190600l15be427bt7327ba231c8a0bbf@mail.gmail.com> On Mon, Jan 19, 2009 at 8:16 AM, Fr?d?ric Sagnes wrote: > On Jan 19, 11:53 am, Fr?d?ric Sagnes wrote: >> On Jan 17, 11:32 am, "Gabriel Genellina" >> wrote: >> >> >> >> > En Fri, 16 Jan 2009 14:41:21 -0200, escribiste en el grupo >> > gmane.comp.python.general >> >> > > I ran a few tests on the new Python 2.6multiprocessingmodule before >> > > migrating a threading code, and found out the locking code is not >> > > working well. In this case, a pool of 5 processes is running, each >> > > trying to get the lock and releasing it after waiting 0.2 seconds >> > > (action is repeated twice). It looks like themultiprocessinglock >> > > allows multiple locking after the second pass. Running the exact same >> > > code with threads works correctly. >> >> > I've tested your code on Windows and I think the problem is on the Queue >> > class. If you replace the Queue with some print statements or write to a >> > log file, the sequence lock/release is OK. >> > You should file a bug report onhttp://bugs.python.org/ >> >> > -- >> > Gabriel Genellina >> >> Thanks for your help gabriel, I just tested it without the queue and >> it works! I'll file a bug about the queues. >> >> Fred >> >> For those interested, the code that works (well, it always did, but >> this shows the real result): >> >> class test_lock_process(object): >> def __init__(self, lock): >> self.lock = lock >> self.read_lock() >> >> def read_lock(self): >> for i in xrange(5): >> self.lock.acquire() >> logging.info('Got lock') >> time.sleep(.2) >> logging.info('Released lock') >> self.lock.release() >> >> if __name__ == "__main__": >> logging.basicConfig(format='[%(process)04d@%(relativeCreated)04d] % >> (message)s', level=logging.DEBUG) >> >> lock = Lock() >> >> processes = [] >> for i in xrange(2): >> processes.append(Process(target=test_lock_process, args= >> (lock,))) >> >> for t in processes: >> t.start() >> >> for t in processes: >> t.join() > > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, > referencing this thread. > Thanks, I've assigned it to myself. Hopefully I can get a fix put together soonish, time permitting. -jesse From gagsl-py2 at yahoo.com.ar Mon Jan 19 09:05:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 12:05:01 -0200 Subject: Overriding base class methods in the C API References: Message-ID: En Sun, 18 Jan 2009 22:18:59 -0200, Floris Bruynooghe escribi?: > I've been trying to figure out how to override methods of a class in > the C API. For Python code you can just redefine the method in your > subclass, but setting tp_methods on the type object does not seem to > have any influcence. Anyone know of a trick I am missing? No tricks; you have to define the new type structure, probably including tp_methods if you redefine any... (Ensure you create an object of the new type, obviously) See e.g. _collections.c how defaultdict inherits from dict. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 19 09:17:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 19 Jan 2009 12:17:41 -0200 Subject: tasklet library based on PEP 0342 References: Message-ID: En Mon, 19 Jan 2009 09:59:17 -0200, escribi?: > Using new features of python generators, as described in PEP 0342, it > is possible to write some sort of "tasklets" in a maner very similar > to stackless python, but running on cpython. For example : > [...] > This kind of tool is very useful, but unfortunately there is no > standard library that would provide a unified way to use it > independently of the underlying event loop. > > Does someone know if a similar library could eventually be added into > python standard libraries ? Would it be accepted as a PEP ? Try the python-ideas list at python-ideas at python.org -- Gabriel Genellina From google at mrabarnett.plus.com Mon Jan 19 09:21:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 14:21:40 +0000 Subject: Regexp In-Reply-To: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <49748C74.4020109@mrabarnett.plus.com> gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' > If the name is followed by "<" then just match the name with [^<]+: href="(?Phttp://mysite\.com/[^"]+)">()?(?P[^<]+)( b>)? I've also changed mysite.com to mysite\.com because . will match any character, but what you probably want to match is ".". From wgrigg at draper.com Mon Jan 19 09:24:41 2009 From: wgrigg at draper.com (bill) Date: Mon, 19 Jan 2009 06:24:41 -0800 (PST) Subject: python processes and Visual Studio Message-ID: <17ef3ab2-0aec-4660-921b-190a5cab45f5@r15g2000prd.googlegroups.com> All, This may sound somewhat convoluted, but here goes: 1. I have a Python script that invokes builds in Visual Studio via the command line interface - 'devenv' 2. It works GREAT 3. I have added a post_build event to a VS Solution that has but one project. 4. This event invokes a Python command - 'c:\python25\python.exe c: \....myPython.py' 5. It works GREAT 6. I move on the another VS Solution that has 6 projects. 7. I add the post_build event command to all 6 projects 8. It 'almost' works... all 6 projects build and the post_build event triggers in all 6 projects and that works 9. Unhappily, the whole thing then 'hangs' I am guessing that perhaps a sub-process or something like that is not exiting. The Python script that is triggered in the post_build event, myPython.py, does nothing special upon exit. Should it? Or, is there some way to determine why the the while thing 'hangs'? TIA, Bill From deets at nospam.web.de Mon Jan 19 09:26:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 15:26:10 +0100 Subject: Python Style Guide Questions - Contd. References: Message-ID: <6tjgs2Fb6n25U1@mid.uni-berlin.de> koranthala wrote: > Hi, > I have some more questions about python code styling. > 1. Global Variables: In my code, I am using some global variables. > Now, when I ran PyLint, it raised convention errors mentioning that > they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that > mentioned. Please let me know whether that is the usual styling > mechanism which is used. I adopted that convention, however I don't know if it is "official". I'd consider it good style though. > 2. I have many loops wherein I define a variable as just a counter. > for x in range(counter): > do_something() > Please note that I am not using x anywhere in the program. > Pylint again raises warnings saying that the variable should be > used. > Should I disregard it or use the default variable _ ? > for _ in range(counter): > do_something() > pylint does not raise errors for those. Are there any issues in > using _ ? Nope, using _ is perfectly fine for variables you don't care about. Another example is e.g. foo, bar, _ = ("a", "b", "c") Diez From philip at semanchuk.com Mon Jan 19 09:30:46 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 19 Jan 2009 09:30:46 -0500 Subject: python resource management In-Reply-To: References: Message-ID: <280373AB-AC97-4B92-ACCA-938DE3F070C5@semanchuk.com> On Jan 19, 2009, at 3:12 AM, S.Selvam Siva wrote: > Hi all, > > I am running a python script which parses nearly 22,000 html files > locally > stored using BeautifulSoup. > The problem is the memory usage linearly increases as the files are > being > parsed. > When the script has crossed parsing 200 files or so, it consumes all > the > available RAM and The CPU usage comes down to 0% (may be due to > excessive > paging). > > We tried 'del soup_object' and used 'gc.collect()'. But, no > improvement. > > Please guide me how to limit python's memory-usage or proper method > for > handling BeautifulSoup object in resource effective manner You need to figure out where the memory is disappearing. Try commenting out parts of your script. For instance, maybe start with a minimalist script: open and close the files but don't process them. See if the memory usage continues to be a problem. Then add elements back in, making your minimalist script more and more like the real one. If the extreme memory usage problem is isolated to one component or section, you'll find it this way. HTH Philip From alan.isaac at gmail.com Mon Jan 19 09:44:01 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 19 Jan 2009 14:44:01 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: On 1/17/2009 3:59 PM Ned Deily apparently wrote: > Ah, so the rumors are true: we are supposed to prefer '{0:>10}'.format('wtf?') to '%10s' % 'wtf?' and '{{0}}{0}'.format('wtf?').format('wtf?') to '%%s%s' % 'wtf?' % 'wtf?' According to PEP 4, "obsolete" means "deprecated". So the compact, simple, and useful old string formatting is really deprecated? Ouch. Thanks, Alan Isaac From deets at nospam.web.de Mon Jan 19 09:50:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 15:50:16 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <6tji98Fb5oidU1@mid.uni-berlin.de> gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' You should consider using BeautifulSoup or lxml2's error-tolerant parser to work with HTML-documents. Sooner or later your regex-based processing is bound to fail, as documents get more complicated. Better to use the right tool for the job. The code should look like this (untested): from BeautifulSoup import BeautifulSoup html = """link""" res = [] soup = BeautifulSoup(html) for tag in soup.findAll("a"): if tag["href"].startswith("http://mysite.com"): res.append(tag["href"]) Not so hard, and *much* more robust. Diez From __peter__ at web.de Mon Jan 19 09:53:30 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jan 2009 15:53:30 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not search the string "blabla"?' Have considered BeautifulSoup? from BeautifulSoup import BeautifulSoup from urlparse import urlparse for a in BeautifulSoup(page)("a"): try: href = a["href"] except KeyError: pass else: url = urlparse(href) if url.hostname == "mysite.com": print href Peter From antroy at gmail.com Mon Jan 19 10:01:02 2009 From: antroy at gmail.com (Ant) Date: Mon, 19 Jan 2009 07:01:02 -0800 (PST) Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> Message-ID: <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> A 0-width positive lookahead is probably what you want here: >>> s = """ ... hdhd Test String OK ... ... """ >>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >>> m = re.search(p, s) >>> m.group(1) 'http://mysite.com/blah.html' >>> m.group(2) 'Test String OK' The (?=...) bit is the lookahead, and won't consume any of the string you are searching. I've binned the named groups for clarity. The beautiful soup answers are a better bet though - they've already done the hard work, and after all, you are trying to roll your own partial HTML parser here, which will struggle with badly formed html... From steve at REMOVE-THIS-cybersource.com.au Mon Jan 19 10:01:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 15:01:40 GMT Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> Message-ID: <01848c43$0$20652$c3e8da3@news.astraweb.com> On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: > On 1/17/2009 3:59 PM Ned Deily apparently wrote: >> > > > Ah, so the rumors are true: > we are supposed to prefer > '{0:>10}'.format('wtf?') > to > '%10s' % 'wtf?' > and > '{{0}}{0}'.format('wtf?').format('wtf?') to > '%%s%s' % 'wtf?' % 'wtf?' Well, that second example certainly is a WTF. I think we are supposed to prefer: '{0}{0}'.format('wtf?') to '%%s%s' % 'wtf?' % 'wtf?' And frankly, I do. > According to PEP 4, > "obsolete" means "deprecated". > So the compact, simple, and useful > old string formatting is really deprecated? Ouch. PEP 4 applies to *modules*. String formatting is not a module. Old string formatting is obsolete but not yet deprecated. Why don't you raise the issue on python-dev, where it may do some good? -- Steven From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 19 10:13:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 16:13:22 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> Message-ID: <49749892$0$23985$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 18, 9:22 am, Bruno Desthuilliers > wrote: > >> Properties by themselves are not the problem, quite on the contrary - as >> you say, they actually help wrt/ encapsulation. What breaks >> encapsulation is *automatic generation* for properties for *each and >> any* implementation attribute. Might as well just makes them all public >> attribute then. > > Let me correct my statement about the automatic generation of > properties in Scala: it is only for public attributes, not all > attributes. I must be missing the point : if it's a public attribute, it doesn't need a "property" ? I guess we use the same words for different things here. > > Getting back to the bigger point, I will gladly agree with you that > data hiding is not a magic bullet that will eliminate all bugs. The > idea that I or anyone else said that, however, is a red herring. Data > hiding is just one safeguard in a portfolio of safeguards that can > *help* to prevent certain kinds of bugs s/data-hiding/encapsulation/ and I'll wholefully agree. > as well as deliberate acts of > sabotage or fraud. I definitively wouldn't bet my ass on language-level access restriction to protect software from fraud or sabotage. > When you have a tough problem to solve, you need > all the help you can get. As far as I'm concerned, *enforcing* access-restriction is of no help. > You keep saying that if you hire competent, trustworthy developers, > you don't need data hiding. Yes. And I also think that trust (and even - to a certain extent - competence) is better built on trust than on distrust. When treated as an irresponsible morons just barely able to type code, most peoples tend to become just that : code-monkeys. > Well, maybe, but when you have a team of > dozens or hundreds of developers, your chances of avoiding any bad > ones is zero for all practical purposes. I don't know how many developpers work for google, but I bet there all smart enough to not need enforced access restriction. Very few people have a burning desire to shoot themselves in the foot, you know. Take some not-that-trivial projects like Zope/Plone. There are quite a few lines of code involved, and quite a lot of programmers worked on it. Some of them being very average joe programmer FWIW. Guess what ? From experience, it JustWork(tm). Granted, this is not a critical system - but that's not the point here. The point is that _from experience_, most programmers are wise enough to avoid doing stupid things. > And even if all your developers were excellent, data hiding would > still be a convenient mechanism to simplify their jobs so they can > focus on higher level problems Sorry, but this makes no sense. How could the lack of *language-enforced* access restriction makes anything more complicated ??? > -- and not have to rely on an ugly > naming convention. And here we are, finally : *you* don't like this convention (and we've aready been thru that discussion IIRC). Guess what ? As far as I'm concerned, I just *love* this convention. Because I *never* have to ask myself if some attribute is interface or implementation. > Now, if developers become careless because they think data hiding will > save them, then that would be a problem. If you believe data-hiding will protect your code from fraud, sabotage or any other malevolence, then you already have this problem IMHO. > That much I will concede. But > I doubt that happens much. From darcy at druid.net Mon Jan 19 10:37:39 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 19 Jan 2009 10:37:39 -0500 Subject: issue In-Reply-To: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> References: <909ef3300901190301j3f11ba9csae9bf4ee36df8690@mail.gmail.com> Message-ID: <20090119103739.288902aa.darcy@druid.net> On Mon, 19 Jan 2009 03:01:53 -0800 "Patrick Steiger" wrote: > MySQL and PostgreSQL are more complete databases that run as servers on the > machine, and you can use python bindings for both. (psycopg2 for postgres, > and i forgot what binds mysql to python at the moment.) There are more than one adapter for each. Check out the list at http://wiki.python.org/moin/DatabaseInterfaces for more information. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alan.isaac at gmail.com Mon Jan 19 10:38:02 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 19 Jan 2009 15:38:02 GMT Subject: string formatting documentation In-Reply-To: <01848c43$0$20652$c3e8da3@news.astraweb.com> References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: > On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: >> we are supposed to prefer '{0:>10}'.format('wtf?') >> to >> '%10s' % 'wtf?' >> and >> '{{0}}{0}'.format('wtf?').format('wtf?') to >> '%%s%s' % 'wtf?' % 'wtf?' On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote: > Well, that second example certainly is a WTF. > I think we are supposed to prefer: > '{0}{0}'.format('wtf?') > to > '%%s%s' % 'wtf?' % 'wtf?' But your replacement misses the point of the example, which is that sequential formatting is often needed. That is, you need to generate a format string from a format string. More explicitly: '{{0}} {0}'.format('earlyinfo').format('lateinfo') '%%s %s' % 'earlyinfo' % 'lateinfo' But of more interest: you claim PEP 4 is not relevant, and that old string formatting is NOT deprecated. I would like assurance that it is not deprecated. Can you back that? Thanks, Alan Isaac From gervaz at gmail.com Mon Jan 19 10:39:54 2009 From: gervaz at gmail.com (gervaz) Date: Mon, 19 Jan 2009 07:39:54 -0800 (PST) Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> Message-ID: <06ad4643-1493-45fd-899e-8796cb8f0f59@r10g2000prf.googlegroups.com> On Jan 19, 4:01?pm, Ant wrote: > A 0-width positive lookahead is probably what you want here: > > >>> s = """ > > ... hdhd Test String OK a> > ... > ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' > >>> m = re.search(p, s) > >>> m.group(1) > > 'http://mysite.com/blah.html'>>> m.group(2) > > 'Test String OK' > > The (?=...) bit is the lookahead, and won't consume any of the string > you are searching. I've binned the named groups for clarity. > > The beautiful soup answers are a better bet though - they've already > done the hard work, and after all, you are trying to roll your own > partial HTML parser here, which will struggle with badly formed html... Ok, thank you all, I'll take a look at beautiful soup, albeit the lookahead solution fits better for the little I have to do. From martinjamesevans at gmail.com Mon Jan 19 11:08:01 2009 From: martinjamesevans at gmail.com (martinjamesevans at gmail.com) Date: Mon, 19 Jan 2009 08:08:01 -0800 (PST) Subject: Regular expression that skips single line comments? Message-ID: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a semicolon. e.g. tests 1 and 2 should be ignored sInput = """ ; $1 test1 ; test2 $2 test3 ; $3 $3 $3 test4 $5 test5 $6 test7 $7 test7 """ Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] The following RE works fine but does not deal with the commented lines: re.findall(r"(\$.)", sInput, re.I) e.g. ['$1', '$2', '$3', '$3', '$3', '$5', '$6', '$7'] My attempts at trying to use (?!;) type expressions keep failing. I'm not convinced this is suitable for a single expression, so I have also attempted to first find-replace any commented lines out without much luck. e.g. re.sub(r"^[\t ]*?;.*?$", r"", sInput, re.I+re.M) Any suggestions would be appreciated. Thanks Martin From google at mrabarnett.plus.com Mon Jan 19 11:29:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 16:29:44 +0000 Subject: Regular expression that skips single line comments? In-Reply-To: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4974AA78.8000505@mrabarnett.plus.com> martinjamesevans at gmail.com wrote: > I am trying to parse a set of files that have a simple syntax using > RE. I'm interested in counting '$' expansions in the files, with one > minor consideration. A line becomes a comment if the first non-white > space character is a semicolon. > > e.g. tests 1 and 2 should be ignored > > sInput = """ > ; $1 test1 > ; test2 $2 > test3 ; $3 $3 $3 > test4 > $5 test5 > $6 > test7 $7 test7 > """ > > Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] > > > The following RE works fine but does not deal with the commented > lines: > > re.findall(r"(\$.)", sInput, re.I) > > e.g. ['$1', '$2', '$3', '$3', '$3', '$5', '$6', '$7'] > > > My attempts at trying to use (?!;) type expressions keep failing. > > I'm not convinced this is suitable for a single expression, so I have > also attempted to first find-replace any commented lines out without > much luck. > > e.g. re.sub(r"^[\t ]*?;.*?$", r"", sInput, re.I+re.M) > > > Any suggestions would be appreciated. Thanks > You could use: >>> re.findall(r"^\s*;.*|(\$.)", sInput, re.M) ['', '', '$3', '$3', '$3', '$5', '$6', '$7'] and then ignore the empty strings. From python.list at tim.thechases.com Mon Jan 19 11:40:26 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 19 Jan 2009 10:40:26 -0600 Subject: Regular expression that skips single line comments? In-Reply-To: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4974ACFA.2070307@tim.thechases.com> > I am trying to parse a set of files that have a simple syntax using > RE. I'm interested in counting '$' expansions in the files, with one > minor consideration. A line becomes a comment if the first non-white > space character is a semicolon. > > e.g. tests 1 and 2 should be ignored > > sInput = """ > ; $1 test1 > ; test2 $2 > test3 ; $3 $3 $3 > test4 > $5 test5 > $6 > test7 $7 test7 > """ > > Required output: ['$3', '$3', '$3', '$5', '$6', '$7'] We're interested in two things: comments and "dollar-something"s >>> import re >>> r_comment = re.compile(r'\s*;') >>> r_dollar = re.compile(r'\$\d+') Then remove comment lines and find the matching '$' expansions: >>> [r_dollar.findall(line) for line in sInput.splitlines() if not r_comment.match(line)] [[], ['$3', '$3', '$3'], [], ['$5'], ['$6'], ['$7']] Finally, roll each line's results into a single list by slightly abusing sum() >>> sum((r_dollar.findall(line) for line in sInput.splitlines() if not r_comment.match(line)), []) ['$3', '$3', '$3', '$5', '$6', '$7'] Adjust the r_dollar if your variable pattern differs (such as reverting to your previous r'\$.' pattern if you prefer, or using r'\$\w+' for multi-character variables). -tkc From deets at nospam.web.de Mon Jan 19 11:48:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 19 Jan 2009 17:48:07 +0100 Subject: Regexp References: <166875b0-f91e-47ec-a582-926eb343e250@t39g2000prh.googlegroups.com> <99b63f63-ea31-41cd-99f4-9674624b4728@s9g2000prg.googlegroups.com> <06ad4643-1493-45fd-899e-8796cb8f0f59@r10g2000prf.googlegroups.com> Message-ID: <6tjp67Fb3o4vU1@mid.uni-berlin.de> gervaz wrote: > On Jan 19, 4:01?pm, Ant wrote: >> A 0-width positive lookahead is probably what you want here: >> >> >>> s = """ >> >> ... hdhd Test String OK> a> >> ... >> ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >> >>> m = re.search(p, s) >> >>> m.group(1) >> >> 'http://mysite.com/blah.html'>>> m.group(2) >> >> 'Test String OK' >> >> The (?=...) bit is the lookahead, and won't consume any of the string >> you are searching. I've binned the named groups for clarity. >> >> The beautiful soup answers are a better bet though - they've already >> done the hard work, and after all, you are trying to roll your own >> partial HTML parser here, which will struggle with badly formed html... > > Ok, thank you all, I'll take a look at beautiful soup, albeit the > lookahead solution fits better for the little I have to do. Little things tend to get out of hand quickly... This is the reason why so many gave you the hint. Diez From phil at freehackers.org Mon Jan 19 12:03:09 2009 From: phil at freehackers.org (BlueBird) Date: Mon, 19 Jan 2009 09:03:09 -0800 (PST) Subject: Event Handling and Signal-Slot Mechanism References: Message-ID: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> On Jan 19, 4:10?am, Steven Woody wrote: > Hi, > > Python has Signal-Slot mechanism, Python does not have signal/slot mechanism. You are talking about the Qt toolkit, which is initially a (nice) C++ toolkit, available also in python via the PyQt wrapper. Signal/slots were introduced by Qt to make C++ gui programming easier. Signal/slots basically provides a very easy way to implement the observer/consumer design pattern, with only 2 or 3 lines of code (as opposed to one or two classes in java for example). Python itself does not have signal/slots but the it's very easy to emulate them using the Python language. In C++ however, it's tricky to do signal/slots in pure C++ and this addition is one of the reason that programming GUI in Qt is nice (personal opinion obviously). To comne back to your question: > why he still need another mechanism > Event Handling? ? This is actually a Qt question: why have event handling for some things, and signal/slot for some others ? My opinion on the debate: - signal/slot add an overhead of one class to every QObject class, and 3 method calls when emitting a signal (if I remember Qt documentation correctly). For some real-time tasks, like repainting the screen, every microseconds must be saved and sparing 3 method calls is a good idea. - since a GUI application is fundamentally an event driven system, the event stuff has to be there anyway. - signal/slot is very convenient for data exchange between widgets but I think it would be overkill to use it everywhere. Event propagation is a nice design as well. Now, if you want to discuss this further, I suggest to go to Qt interest ( http://lists.trolltech.com/qt-interest/ ) which is dedicated to discussion around Qt. cheers, Philippe From Caseyweb at gmail.com Mon Jan 19 12:03:31 2009 From: Caseyweb at gmail.com (Casey) Date: Mon, 19 Jan 2009 09:03:31 -0800 (PST) Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <4b0374c4-9afb-45f7-b49b-1f6e717fda2a@g1g2000pra.googlegroups.com> Another option (I cheated a little and turned sInput into a sequence of lines, similar to what you would get reading a text file): sInput = [ '; $1 test1', ' ; test2 $2', ' test3 ; $3 $3 $3', 'test4', '$5 test5', ' $6', ' test7 $7 test7', ] import re re_exp = re.compile(r'(\$.)') re_cmt = re.compile(r'\s*;') expansions = [exp for line in sInput for exp in re_exp.findall(line) if not re_cmt.match(line)] print(expansions) >>> ['$3', '$3', '$3', '$5', '$6', '$7'] From tim.arnold at sas.com Mon Jan 19 12:44:52 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Mon, 19 Jan 2009 12:44:52 -0500 Subject: python resource management References: Message-ID: "Philip Semanchuk" wrote in message news:mailman.7530.1232375454.3487.python-list at python.org... > > On Jan 19, 2009, at 3:12 AM, S.Selvam Siva wrote: > >> Hi all, >> >> I am running a python script which parses nearly 22,000 html files >> locally >> stored using BeautifulSoup. >> The problem is the memory usage linearly increases as the files are >> being >> parsed. >> When the script has crossed parsing 200 files or so, it consumes all the >> available RAM and The CPU usage comes down to 0% (may be due to >> excessive >> paging). >> >> We tried 'del soup_object' and used 'gc.collect()'. But, no >> improvement. >> >> Please guide me how to limit python's memory-usage or proper method for >> handling BeautifulSoup object in resource effective manner > > You need to figure out where the memory is disappearing. Try commenting > out parts of your script. For instance, maybe start with a minimalist > script: open and close the files but don't process them. See if the > memory usage continues to be a problem. Then add elements back in, making > your minimalist script more and more like the real one. If the extreme > memory usage problem is isolated to one component or section, you'll find > it this way. > > HTH > Philip Also, are you creating a separate soup object for each file or reusing one object over and over? --Tim From rhamph at gmail.com Mon Jan 19 13:11:35 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Mon, 19 Jan 2009 10:11:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> Message-ID: On Jan 18, 12:51?pm, "Russ P." wrote: > And even if all your developers were excellent, data hiding would > still be a convenient mechanism to simplify their jobs so they can > focus on higher level problems -- and not have to rely on an ugly > naming convention. That's just it ? the cost of maintaining friend lists and similar mechanisms exceeds the benefit enforced privates. Doing it for performance or for a secure sandbox of course changes this, but they're separate issues. Java hides low-level details because it thinks the programmer is incompetent. Python hides them because it thinks the programmer has better things to do. An underscore is all a competent programmer needs. From jeff at jmcneil.net Mon Jan 19 13:25:48 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 19 Jan 2009 10:25:48 -0800 (PST) Subject: *Advanced* Python book? References: Message-ID: <30128b77-7618-4b83-b9d3-e69f600210bc@t3g2000yqa.googlegroups.com> On Jan 18, 6:35 pm, Simon Brunning wrote: > 2009/1/17 Michele Simionato : > > > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > > a review for it: > > >http://www.artima.com/weblogs/viewpost.jsp?thread=240415 > > +1 for this. I'm 3/4 of the way through it, it's pretty good. Covers > many on the important areas that the more introductory books rightly > leave out, > > -- > Cheers, > Simon B. I keep a copy of "Python In A Nutshell" on my desk at all times. Most of my books are in great shape, but this one is ripped all to hell. The sign of a good book. It covers just about everything, though not all in extreme depth. It's a great book! I've been writing Python for about 4 years now and over the week or so I've caught the "I should know more about the internals" bug. As a result, I've been trying to trace the interpreter from the start of the main function through user code execution. Getting to fully understand the C API and the actual CPython implementation is something I wish I would have done years ago. I'd suggest you do that if you get the chance. From nick at craig-wood.com Mon Jan 19 13:32:12 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 19 Jan 2009 12:32:12 -0600 Subject: Python 2.6's multiprocessing lock not working on second use? References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: Jesse Noller wrote: > > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, > > referencing this thread. > > Thanks, I've assigned it to myself. Hopefully I can get a fix put > together soonish, time permitting. Sounds like it might be hard or impossible to fix to me. I'd love to be proved wrong though! If you were thinking of passing time.time() / clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll want to know that it can differ by significant amounts on different processors :-( Good luck! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From vedrandekovic at gmail.com Mon Jan 19 13:58:58 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Mon, 19 Jan 2009 10:58:58 -0800 (PST) Subject: Python and threads References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> <3df20ee4-7aa6-4e86-ab5f-bf4fc84942f4@i24g2000prf.googlegroups.com> <497390c3$0$31878$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <2f05e652-eda9-4f5c-8b2b-88a6cdace073@q30g2000prq.googlegroups.com> On 18 sij, 21:27, Stefan Behnel wrote: > vedrandeko... at yahoo.com wrote: > > and thanks for all previous help.I want to measure memory usage of > > executed python script.I'am working on windows XP. > > Could you qualify "measure"? Do you mean: > > a) "debug" (permanently high accuracy, potentially high runtime overhead) > b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime > ? ? ? ? ? ? ? overhead) > c) "find out" (low accuracy or just max usage, no permanent observation) > > ? > > Stefan Hello, I want to "find out" , sorry for this "measure". Regards, John From bdesth.quelquechose at free.quelquepart.fr Mon Jan 19 14:02:34 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 20:02:34 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: References: <50697b2c0901190415q12ed35e3g43e3d3aa199f06@mail.gmail.com> <534b1c540901190422i1bc0b371sd1f482298a9501d8@mail.gmail.com> Message-ID: <4974dbf2$0$12404$426a34cc@news.free.fr> Chris Rebert a ?crit : > On Mon, Jan 19, 2009 at 4:22 AM, Phillip B Oldham > wrote: >> On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert wrote: >>> Assuming I'm interpreting you correctly (you're going to have to use >>> something like a getter): >> Thanks, but I'm looking for a way to do it *without* using a getter as >> I don't have easy access to the class (its being generated for me >> elsewhere). Essentially I'd like to overwrite (if possible) the >> default behavior when returning certain attributes on certain objects. > > To my knowledge, you can't really "overwrite" that behavior without > editing the class (or how it's generated). Assuming it's really about a *class* object (not instances of it), *and* it's a new-style class, it is possible: class Foo(object): def __init__(self): self.tags = ['foo', 'bar'] def wrap_tag_access(cls): def fset(obj, value): obj._tags = value def fget(obj): print "do something here" return obj._tags cls.tags = property(fset=fset, fget=fget) return cls Foo = wrap_tag_access(Foo) f = Foo() print f.tags > The next closest thing would be to write a proxy class that defines a > __getattr__ method implementing the semantics you want. If it's a "classic" class, then yes, it's probably the best thing to do. From bdesth.quelquechose at free.quelquepart.fr Mon Jan 19 14:05:59 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 19 Jan 2009 20:05:59 +0100 Subject: Can I run an operation on an object's attribute when reading? In-Reply-To: <0184743f$0$20652$c3e8da3@news.astraweb.com> References: <0184743f$0$20652$c3e8da3@news.astraweb.com> Message-ID: <4974dcbf$0$1445$426a74cc@news.free.fr> Steven D'Aprano a ?crit : (snip) > When all you have is a hammer, everything looks like a nail... Why do you > have to read item.tags directly? Just write a function and call it > instead of direct attribute access. A sensible advice, but only relevant if this class instances are only used by code the OP do control. Which may or not be the case. From kdawg44 at gmail.com Mon Jan 19 14:14:35 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:14:35 -0500 Subject: Receiving Output from os.system command Message-ID: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> I am really new to python and am trying to learn it to do some projects. I wanted to perform a simple task and am having some trouble with it. I run linux in a vm on a windows laptop for work. I have my laptop screen and an external monitor. I move my Ubuntu VM back and forth depending on what I am working on so I wanted to write a little python script that changed the resolutions depending on what the current resolution is. I have: #! /usr/bin/python import sys import os import re re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}') xrandr_output = os.popen('xrandr').readlines() currentRes = re_currentResolution.search(xrandr_output) print currentRes.group(0) I just want to grab the xrandr output as a string and parse it with the regex. This will give me a string with the current resolution, for instance "current 1024 x 768". I would then split that up and call back to the os.system('xrandr -s 1280x1024'). If the resolution was "current 1280 x 1024" then I would parse that and call back to os.system('xrandr -s 1024x768'). However, when I try the line (as in the code above): currentRes = re_currentResolution.search(xrandr_output) it is complaining that xrandr_output is not a string. (however, if I do a print xrandr_output it prints fine) I instead get the following error: Traceback (most recent call last): File "change_res.py", line 9, in currentRes = re_currentResolution.search(xrandr_output) TypeError: expected string or buffer What am I doing wrong? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Mon Jan 19 14:21:12 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:21:12 -0500 Subject: Receiving Output from os.system command In-Reply-To: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> References: <5caea3690901191114t9f0fbe0i175dcfb3e9a60917@mail.gmail.com> Message-ID: <5caea3690901191121p4d03b68fy4f70917d700a8f03@mail.gmail.com> Nevermind, I am an idiot. I didn't realize what it was returning... Please disregard. Thanks. Kevin On Mon, Jan 19, 2009 at 2:14 PM, K-Dawg wrote: > I am really new to python and am trying to learn it to do some projects. I > wanted to perform a simple task and am having some trouble with it. I run > linux in a vm on a windows laptop for work. I have my laptop screen and an > external monitor. I move my Ubuntu VM back and forth depending on what I am > working on so I wanted to write a little python script that changed the > resolutions depending on what the current resolution is. > > I have: > > #! /usr/bin/python > > import sys > import os > import re > > re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}') > xrandr_output = os.popen('xrandr').readlines() > currentRes = re_currentResolution.search(xrandr_output) > print currentRes.group(0) > > I just want to grab the xrandr output as a string and parse it with the > regex. This will give me a string with the current resolution, for instance > "current 1024 x 768". I would then split that up and call back to the > os.system('xrandr -s 1280x1024'). If the resolution was "current 1280 x > 1024" then I would parse that and call back to os.system('xrandr -s > 1024x768'). > > However, when I try the line (as in the code above): > > currentRes = re_currentResolution.search(xrandr_output) > > it is complaining that xrandr_output is not a string. (however, if I do a > print xrandr_output it prints fine) > > I instead get the following error: > > Traceback (most recent call last): > File "change_res.py", line 9, in > currentRes = re_currentResolution.search(xrandr_output) > TypeError: expected string or buffer > > What am I doing wrong? > > Thanks. > > Kevin > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Mon Jan 19 14:36:05 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 19 Jan 2009 11:36:05 -0800 (PST) Subject: Logging help Message-ID: Hi, Is it possible somehow to have the logging module rotate the files every time I start it. Basically, I can automatically rotate using RotatingFileHandler; Now I want it rotated every time I start the program too. Ex: The logging file - log.txt Now, rotatingfilehandler goes and updates to log.txt.1, log.txt.2, log.txt.3 etc. Now, I also want to rotate it automatically I start the program - i.e. The second time I start the program - log.txt -> log.txt.1, log.txt. 1 -> log.txt.2 etc. I can write up a simple script to move it by 1 digit every time. My question is - is it possible automatically via logging functionality? This is needed because say TimedRotatingFileHandler etc wont work that well otherwise. It does look like twisted.python.logfile.DailyLogFile seems to be an Ok option, but I want to use the logging module in the Python distribution, since it is more powerful. From kdawg44 at gmail.com Mon Jan 19 14:39:30 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 19 Jan 2009 14:39:30 -0500 Subject: Beginner Question Message-ID: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Please forgive my beginner question. I have used python a little bit, mainly as a scripting language to perform specific administrative tasks. I have trying to learn to use it to develop applications but there are a few things I do not understand. I come from more of a Java background. I do no understand the underscore methods. __main__ - is this just the main method that is in the file that is actually executed? I also see __init__ a lot. What is that for? Is it like a constructor in Java or totally different? Thanks for clearing it up. I am undertaking my first application development effort in python and anticipate discussing this with all of you a lot. :) Thanks for your support. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Mon Jan 19 14:40:46 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 19 Jan 2009 14:40:46 -0500 Subject: Python 2.6's multiprocessing lock not working on second use? In-Reply-To: References: <33b5130a-360b-4efb-b90e-88b3d57e4419@v5g2000pre.googlegroups.com> <4d48f7a2-dda1-4560-a5bf-e6f5046dbd75@q35g2000vbi.googlegroups.com> <7d607499-13a4-4a07-a664-0b9a3803e630@s9g2000prg.googlegroups.com> Message-ID: <4222a8490901191140s132ab9a9hd2fc0e8435f01b6a@mail.gmail.com> On Mon, Jan 19, 2009 at 1:32 PM, Nick Craig-Wood wrote: > Jesse Noller wrote: >> > Opened issue #4999 [http://bugs.python.org/issue4999] on the matter, >> > referencing this thread. >> >> Thanks, I've assigned it to myself. Hopefully I can get a fix put >> together soonish, time permitting. > > Sounds like it might be hard or impossible to fix to me. I'd love to > be proved wrong though! > > If you were thinking of passing time.time() / > clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll > want to know that it can differ by significant amounts on different > processors :-( > > Good luck! > Consider my parade rained on. And after looking at it this morning, yes - this is going to be hard, and should be fixed for a FIFO queue :\ -jesse From Scott.Daniels at Acm.Org Mon Jan 19 14:55:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 11:55:13 -0800 Subject: Python and threads In-Reply-To: <6th4riFat1vuU1@mid.uni-berlin.de> References: <6477ab9e-d92a-46a1-9329-e50712137b80@x16g2000prn.googlegroups.com> <6th4riFat1vuU1@mid.uni-berlin.de> Message-ID: vedrandekovic at yahoo.com said: > ... when I run these two threads, > I think they don't start at the same time In response, Diez B. Roggisch wrote: > ... Even if you managed to get two threads started simultaneously > (which the OS doesn't even offer IINM), the would soon run out of sync.... And the simple way to remember this is to rember why time was made, "Time is Nature's way of keeping everything from happening at once." :-) Just a brief humor break. From Scott.Daniels at Acm.Org Mon Jan 19 14:56:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 11:56:43 -0800 Subject: uninstall before upgrade? In-Reply-To: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> References: <6ba005a9-65ce-43a4-8baf-c2f6fdc1f973@z6g2000pre.googlegroups.com> Message-ID: waltbrad wrote: > I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before > I do that? If so, what's the best way to uninstall it? Thanks. The answer to your question may depend on your operating system and setup. From sjmachin at lexicon.net Mon Jan 19 15:03:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 12:03:58 -0800 (PST) Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On Jan 20, 2:38?am, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, > and that old string formatting is NOT deprecated. > I would like assurance that it is not deprecated. It is not deprecated YET; see this: http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6 PEP 3101: Advanced String Formatting. Note: the 2.6 description mentions the format() method for both 8-bit and Unicode strings. In 3.0, only the str type (text strings with Unicode support) supports this method; the bytes type does not. The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1. From rNOSPAMon at flownet.com Mon Jan 19 15:15:29 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 19 Jan 2009 12:15:29 -0800 Subject: wsgi silently swallows errors Message-ID: Consider the following wsgi app: def application(env, start_response): start_response('200 OK',[('Content-type','text/plain')]) yield "hello" x=1/0 yield "world" The result of this is that the web browser displays "hello" and an error message ends up in the web log. But there is no other indication that an error has occurred. Is there any way to get WSGI to not silently swallow errors that occur after start_response has been called? Thanks, rg From Russ.Paielli at gmail.com Mon Jan 19 15:19:10 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 12:19:10 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> Message-ID: <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> On Jan 19, 7:13?am, Bruno Desthuilliers wrote: > I must be missing the point : if it's a public attribute, it doesn't > need a "property" ? I guess we use the same words for different things here. Yes, you are missing more than one point. Scala automatically converts public data members into properties, apparently to save the programmer the trouble of doing it manually. If you are interested, I'm sure you can find publicly available information on it. > I definitively wouldn't bet my ass on language-level access restriction > to protect software from fraud or sabotage. You're missing the point here too. I'll try one more time to explain it. Access restriction enforced by the language is just one safeguard among several that are usually available. I think the lock analogy is very appropriate here. Think about door locks. Would you "bet your ass" on them to keep you secure? Of course not. You might also have a firearm or a dog. But even if you don't have those, you surely have a police department, and surely they carry guns. Because you cannot "bet your ass" on door locks for your security, does that mean you just abandon them altogether? Maybe so, if you live in a very remote place, but most people still seem to think they need locks on their doors. Well, think of access restrictions enforced by the language as analogous to door locks. Let's take the analogy a bit further. Suppose you work in a secure building with strict access control, and everyone in the building is "trusted" (whatever that means). This situation is analogous to a group of "trusted" developers working on a project together. Would you feel comfortable having no locks on the doors? Maybe you would, but I wouldn't. I wouldn't want to just let my co- workers, trusted or not, have access to all my personal stuff. And what if I need to store something of value from time to time? They may be honest, but why even tempt them? What if one of them decides he needs to borrow my favorite Python book while I'm gone, then forgets to return it? But what if you don't want your door locked? Well, you have the option of not using your lock. You can get your way whether the doors have locks or not. But if I want mine locked, and no locks are available, I can't get what I want. When you say that a language should not even have access control available, you are essentially saying that you should get your way -- and to hell with anyone who disagrees with my way. > Yes. And I also think that trust (and even - to a certain extent - > competence) is better built on trust than on distrust. When treated as > an irresponsible morons just barely able to type code, most peoples tend > to become just that : code-monkeys. That may well apply in some environments, but it certainly does not apply in all environments. It certainly does not apply in a defense contracting environment, or a financial software development environment, to give just two of many possible examples. Maybe you don't personally care about such environments, but who are you to decide what environments Python should or should not be suitable for? > Take some not-that-trivial projects like Zope/Plone. There are quite a > few lines of code involved, and quite a lot of programmers worked on it. > ? Some of them being very average joe programmer FWIW. Guess what ? From > experience, it JustWork(tm). Granted, this is not a critical system - > but that's not the point here. The point is that _from experience_, most > programmers are wise enough to avoid doing stupid things. And would data hiding have impeded those projects? Or could it perhaps have helped? I don't know, but I don't think you can simply assume it would have been a net minus. I know for fact that the strict access restrictions in Ada were indispensable in the integration of the flight software in the Boeing 777, for example. Without them, they'd probably *still* be trying to get it right! > > And even if all your developers were excellent, data hiding would > > still be a convenient mechanism to simplify their jobs ?so they can > > focus on higher level problems > > Sorry, but this makes no sense. How could the lack of > *language-enforced* access restriction ?makes anything more complicated ??? Because it forces humans to check for access restrictions when the language could do it. > > -- and not have to rely on an ugly > > naming convention. > > And here we are, finally : *you* don't like this convention (and we've > aready been thru that discussion IIRC). > > Guess what ? As far as I'm concerned, I just *love* this convention. > Because I *never* have to ask myself if some attribute is interface or > implementation. If you like it that much, you would be perfectly free to continue using that convention even if access control was enforced. > > Now, if developers become careless because they think data hiding will > > save them, then that would be a problem. > > If you believe data-hiding will protect your code from fraud, sabotage > or any other malevolence, then you already have this problem IMHO. I addressed this red herring above. From benjamin.kaplan at case.edu Mon Jan 19 15:32:45 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 19 Jan 2009 15:32:45 -0500 Subject: Beginner Question In-Reply-To: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> References: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Message-ID: On Mon, Jan 19, 2009 at 2:39 PM, K-Dawg wrote: > Please forgive my beginner question. I have used python a little bit, > mainly as a scripting language to perform specific administrative tasks. I > have trying to learn to use it to develop applications but there are a few > things I do not understand. > > I come from more of a Java background. > > I do no understand the underscore methods. __main__ - is this just the > main method that is in the file that is actually executed? I also see > __init__ a lot. What is that for? Is it like a constructor in Java or > totally different?] Python doesn't have a main method. It's files are scripts and not programs. It's just like a shell script- everything is run. Unlike Java where everything has to be in a method in a class, you can have actions performed at the module level in Python. What you'll find is a lot of "if __name__ == '__main__'" conditionals. The name of the script that is run is always __main__, so you can use this to only run certain commands when the script is run directly as opposed to be imported by another module. __init__ is the equivalent of a Java constructor. > > > Thanks for clearing it up. I am undertaking my first application > development effort in python and anticipate discussing this with all of you > a lot. :) Thanks for your support. > > Kevin > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptriller at soapwars.de Mon Jan 19 15:37:46 2009 From: ptriller at soapwars.de (Peter) Date: Mon, 19 Jan 2009 21:37:46 +0100 Subject: Embedding Python. But not so easy. Message-ID: <200901192137.46603.ptriller@soapwars.de> Hi, Right now I am in a project writing a Simulation engine, and we are right now in the process of evaluating a script engine. The basic principle is a C++ engine simulating the environment and scriptable agents interacting with the environment. But the current design has a special requirement to that scriptability and my current knowledge of the API of Python isolated two problems 1) Threads: the simulation is going to be run in a very parallel environment with several CPUs and http://docs.python.org/c-api/init.html#thread-state-and- the-global-interpreter-lock there is a global lock mentioned. Does that mean that the python code can not benefit from this ? 2) The script has to hand back control to the C++ framework without increasing the C execution stack. and be able to resume the execution at a later point. I try some pseudo code here to explain // C++: ctx = new ExecutionContext(); ctx->run(); while(ctx->stillRunning()) { otherStuff(); ctx->resume(); } ...... // Python y=21 ... .. # Here the execution is suspended und control handed back to the C++ code suspend y+=12 end I hope that makes it clear. I did not see a way to implement this with the python interpreter. I am hoping to be proven wrong Thanks in advance Greets Peter From yanghatespam at gmail.com Mon Jan 19 15:38:56 2009 From: yanghatespam at gmail.com (Yang Zhang) Date: Mon, 19 Jan 2009 15:38:56 -0500 Subject: psycopg2 weirdness In-Reply-To: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> References: <0b8d8616-1910-417a-b231-f0c42f604206@m12g2000vbp.googlegroups.com> Message-ID: <4974E4E0.1060909@gmail.com> For posterity: the problem turned out to be a second request being made in quick succession by the client-side Javascript, causing the web.py request handler to run in multiple threads concurrently. The request handlers don't create their own Postgresql connections, but instead share one across all sessions. The absence of any synchronization protecting this connection resulted in myriad errors and crashes in the C extension module (in both pygresql and psycopg2). Neha Gupta wrote: > Hey, > > I only have little experience with web.py and psycopg2 and am running > into a weird problem, I'd appreciate any help I can get with debugging > it. > > I wrote a simple program that works and I don't see any crash: > ---- > import psycopg2 > > try: > database_conn = psycopg2.connect("dbname='dbname' user='username' > host='hostname'"); > except: > print "Unable to connect to the database!" > > database_conn.set_isolation_level(0) > cur = database_conn.cursor(); > > while True: > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > rows = cur.fetchall() > print rows > ----- > > However, I have a small website built using web.py framework which has > a date picker that lets the user pick a date and it takes the user to > a new url such as: localhost:8080/departures/01-05-2007. I issue a > query to my database for the date selected by the user and retrieve > the results. The problem now is that if I select different dates > directly by changing the url then everything works but as soon as I > pick a date from date picker the server crashes. I removed the date > picker and made it just a text box but as soon as I hit the submit > button, server crashes so I know it is not the date picker that > causing trouble. > --- > class departures: > def buildDepartureTableHtml(self, date): > web.debug('date', date) > # Issue the query. > # select avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '2007-02-15' group > by origin, crs_dep > # _hour order by origin, crs_dep_hour; > try: > web.debug("About to issue query") > # query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '" + date + "' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as > crs_dep_hour, origin from flightdata where date = '01-05-2007' group > by origin, crs_dep_hour order by origin, crs_dep_hour"; > cur.execute(query) > web.debug('query executed!') > rows = cur.fetchall() > web.debug('rows fetched!') > web.debug(rows) > except Exception, e: > print repr(e) > database_conn.rollback() > return "
Invalid Date
" > -- > // JS code > function submitForm() { > var date = ($("date").value).replace(/\//g,"-"); > window.location = "http://" + window.location.host + "/ > departures/" + date; > } > > You can see above that I even ignored the date passed from the form > and I have hardcoded '01-05-2007'. The message "About to issue query" > gets printed as well as the right date chosen from the date picker but > then I see the following: > > Assertion failed: (str != NULL), function PyString_FromString, file > Objects/stringobject.c, line 107. > Abort trap > > with a pop that says: "The application Python quit unexpectedly. The > problem may have been caused by the _psycopg.so plug-in". > -- > I don't understand the error message above. The date did get passed > correctly and am now not even using it, I use the hard coded date. So > what is going on? > > Any help would be great. > > Thank you! > Neha > -- > http://mail.python.org/mailman/listinfo/python-list -- Yang Zhang http://www.mit.edu/~y_z/ From aktests at gmail.com Mon Jan 19 16:00:44 2009 From: aktests at gmail.com (ak) Date: Mon, 19 Jan 2009 13:00:44 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server Message-ID: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Hi everyone, I have a problem with urllib2 on this particular url, hosted on an Oracle HTTP Server http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=phone&null which gets 302 redirected to https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a cookie through the Set-Cookie header field in the 302 reply. This works fin with firefox. However, with urllib2 and the following code snippet, it doesn't work -------- import cookiejar import urllib2 cookiejar = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) url = 'http://www.orange.sk/eshop/sk/portal/catalog.html? type=post&subtype=phone&null' req = urllib2.Request(url, None) s=opener.open(req) -------- Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib2.py", line 387, in open response = meth(req, response) File "/usr/lib/python2.5/urllib2.py", line 498, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.5/urllib2.py", line 419, in error result = self._call_chain(*args) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302 return self.parent.open(new) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open r = h.getresponse() File "/usr/lib/python2.5/httplib.py", line 928, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 385, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 349, in _read_status raise BadStatusLine(line) httplib.BadStatusLine Trying the redirected url directly doesn't work either (trying with Firefox will give an HTML error page, as the cookie is not set yet, but trying with urllib2 gives the same exception as previously, whereas it should return the HTML error page) This works correctly on other urls on this website (http(s):// www.orange.sk). Am I doing anything wrong or is this a bug in urllib2 ? -- ak From exarkun at divmod.com Mon Jan 19 16:03:25 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 19 Jan 2009 16:03:25 -0500 Subject: wsgi silently swallows errors In-Reply-To: Message-ID: <20090119210325.9754.1469965245.divmod.quotient.5288@henry.divmod.com> On Mon, 19 Jan 2009 12:15:29 -0800, Ron Garret wrote: >Consider the following wsgi app: > >def application(env, start_response): > start_response('200 OK',[('Content-type','text/plain')]) > yield "hello" > x=1/0 > yield "world" > >The result of this is that the web browser displays "hello" and an error >message ends up in the web log. But there is no other indication that >an error has occurred. > >Is there any way to get WSGI to not silently swallow errors that occur >after start_response has been called? WSGI is a specification, not a piece of software. The specification isn't swallowing the error, some piece of software is. What WSGI container are you using? Jean-Paul From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 16:24:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 21:24:50 GMT Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 08:08:01 -0800, martinjamesevans wrote: > I am trying to parse a set of files that have a simple syntax using RE. > I'm interested in counting '$' expansions in the files, with one minor > consideration. A line becomes a comment if the first non-white space > character is a semicolon. Since your data is line-based, surely the simplest, clearest and most natural solution is to parse each line individually instead of trying to process the entire input with a single RE? def extract_dollar_expansions(sInput): accumulator = [] for line in sInput.split('\n'): line = line.lstrip() if line.startswith(';'): continue accumulator.extend(re.findall(r"(\$.)", line)) return accumulator (Aside: why are you doing a case-insensitive match for a non-letter? Are there different upper- and lower-case dollar signs?) >>> extract_dollar_expansions(sInput) ['$3', '$3', '$3', '$5', '$6', '$7'] -- Steven From bj_666 at gmx.net Mon Jan 19 16:32:10 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 19 Jan 2009 21:32:10 GMT Subject: Python Style Guide Questions - Contd. References: Message-ID: <6tk9qqFbav8gU1@mid.uni-berlin.de> On Mon, 19 Jan 2009 05:50:54 -0800, koranthala wrote: > Hi, > I have some more questions about python code styling. 1. Global > Variables: In my code, I am using some global variables. > Now, when I ran PyLint, it raised convention errors mentioning that they > should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that > mentioned. Please let me know whether that is the usual styling > mechanism which is used. PEP8 doesn't mention constants at all. The all caps naming for constants is a convention in several languages. > 2. I have many loops wherein I define a variable as just a counter. > for x in range(counter): > do_something() > Please note that I am not using x anywhere in the program. Pylint > again raises warnings saying that the variable should be > used. > Should I disregard it or use the default variable _ ? for _ in > range(counter): > do_something() > pylint does not raise errors for those. Are there any issues in > using _ ? Pylint doesn't barf on `dummy` either. The point is having a name that makes clear at the head of the loop, that the reader doesn't have to bother looking for places where the value will be used because it is clear from the name that the value won't be used at all. BTW pylint is very configurable, you can dump the default configuration and find out which names are "allowed" by default and of course define your own set of "value doesn't matter" names. Ciao, Marc 'BlackJack' Rintsch From linuxguy123 at gmail.com Mon Jan 19 16:37:55 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Mon, 19 Jan 2009 14:37:55 -0700 Subject: PyQt4 on Windows ? Message-ID: <1232401075.10889.29.camel@localhost.localdomain> What does it take to get a PyQt4 application running on a Windows machine ? I'm sorry if this is a redundant question, but I've searched this and I am not finding a comprehensive answer. If anyone is running a PyQt4 application on a Windows (XP or Vista) machine, I'd love to know how it works for you and how extensive the application is and how much of the Qt library it uses. Thanks From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 16:43:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Jan 2009 21:43:05 GMT Subject: string formatting documentation References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On Mon, 19 Jan 2009 15:38:02 +0000, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, and that old > string formatting is NOT deprecated. I would like assurance that it is > not deprecated. Can you back that? If you want to know what python-dev have in mind, you have to ask them, not me. But as I see it, the earliest % formatting could be removed would be Python 3.2: Python 3.1 to get a formal deprecation warning, with removal no earlier than 3.2. So you've got about a year to change their mind about deprecating the old style, or alternatively, a year to get used to the new style, followed by another year for % to go away completely. -- Steven From joe at strout.net Mon Jan 19 16:44:30 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 14:44:30 -0700 Subject: function to find the modification date of the project Message-ID: <4974F43E.4020402@strout.net> This isn't a question, but something I thought others may find useful (and if somebody can spot any errors with it, I'll be grateful). We had a case recently where the client was running an older version of our app, and didn't realize it. In other languages I've avoided this by displaying the compile date in the About box, but of course Python doesn't really have a meaningful compile date. So, instead we're now displaying the latest modification date of any .py file in the project. Here's the function that finds that: def lastModDate(): "Get the latest modification date (as a string) of any .py file in this project." import os, time latest = 0 dir = os.path.dirname(__file__) if dir == '': dir = '.' # HACK, but appears necessary for fname in os.listdir(dir): if fname.endswith('.py'): modtime = os.stat(os.path.join(dir, fname)).st_mtime if modtime > latest: latest = modtime out = time.strftime('%Y-%m-%d', time.localtime(latest)) return out The intent of this code is to find any .py files in the same directory as the module containing the above code, and return (as a date string in SQL/ISO format) the latest modification date thereof. Then, this is displayed to the user in the about box like so: dlg = wx.MessageDialog(self, "etown unified database system\nRevision: %s" \ % lastModDate(), "About etown Central", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() (That's wxPython, of course.) I haven't yet tested this in a packaged app or on Windows, but it seems to work in our OS X test environment. One odd thing was the need to employ the HACK identified above, where if __file__ happens to already be in the current directory, then os.path.dirname of it returns the empty-string -- yet the empty-string is not a valid argument to os.listdir(). Is there a better way to a list of files in the same directory as a given file? Cheers, - Joe From schap at offenbachers.com Mon Jan 19 16:47:01 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Mon, 19 Jan 2009 16:47:01 -0500 Subject: PyQt4 on Windows ? In-Reply-To: <1232401075.10889.29.camel@localhost.localdomain> References: <1232401075.10889.29.camel@localhost.localdomain> Message-ID: <4974F4D5.6050105@offenbachers.com> I have one running. actually use freezer to create an exe for it in windows. http://www.riverbankcomputing.co.uk/software/pyqt/download That will tell you how to get started. The app I wrote uses Pryro(with middleware server on a linux machine). And I use the standard widgets that qt has grid, table , combobox etc.... Linuxguy123 wrote: > What does it take to get a PyQt4 application running on a Windows > machine ? > > I'm sorry if this is a redundant question, but I've searched this and I > am not finding a comprehensive answer. > > If anyone is running a PyQt4 application on a Windows (XP or Vista) > machine, I'd love to know how it works for you and how extensive the > application is and how much of the Qt library it uses. > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > > From aktests at gmail.com Mon Jan 19 16:48:25 2009 From: aktests at gmail.com (ak) Date: Mon, 19 Jan 2009 13:48:25 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: On Jan 19, 10:00?pm, ak wrote: > Hi everyone, > > I have a problem with urllib2 on this particular url, hosted on an > Oracle HTTP Server > > http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p... > > which gets 302 redirected tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html, > after setting a cookie through the Set-Cookie header field in the 302 > reply. This works fin with firefox. > > However, with urllib2 and the following code snippet, it doesn't work > > -------- > import cookiejar > import urllib2 > > cookiejar = cookielib.LWPCookieJar() > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html? > type=post&subtype=phone&null' > req = urllib2.Request(url, None) > s=opener.open(req) > -------- > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib/python2.5/urllib2.py", line 387, in open > ? ? response = meth(req, response) > ? File "/usr/lib/python2.5/urllib2.py", line 498, in http_response > ? ? 'http', request, response, code, msg, hdrs) > ? File "/usr/lib/python2.5/urllib2.py", line 419, in error > ? ? result = self._call_chain(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > ? ? result = func(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302 > ? ? return self.parent.open(new) > ? File "/usr/lib/python2.5/urllib2.py", line 381, in open > ? ? response = self._open(req, data) > ? File "/usr/lib/python2.5/urllib2.py", line 399, in _open > ? ? '_open', req) > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > ? ? result = func(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open > ? ? return self.do_open(httplib.HTTPSConnection, req) > ? File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open > ? ? r = h.getresponse() > ? File "/usr/lib/python2.5/httplib.py", line 928, in getresponse > ? ? response.begin() > ? File "/usr/lib/python2.5/httplib.py", line 385, in begin > ? ? version, status, reason = self._read_status() > ? File "/usr/lib/python2.5/httplib.py", line 349, in _read_status > ? ? raise BadStatusLine(line) > httplib.BadStatusLine > > Trying the redirected url directly doesn't work either (trying with > Firefox will give an HTML error page, as the cookie is not set yet, > but trying with urllib2 gives the same exception as previously, > whereas it should return the HTML error page) > This works correctly on other urls on this website (http(s)://www.orange.sk). > > Am I doing anything wrong or is this a bug in urllib2 ? > > -- ak Actually, I was wrong on the last point, this does *not* work on https://www.orange.sk (but does on http://www.orange.sk). IMHO, this means either urllib2 or the server misimplemented HTTPS. Here's some output with debuglevel=1 : >>> opener.open(urllib2.Request('http://www.orange.sk/', None, headers)) reply: 'HTTP/1.1 200 OK\r\n' header: Date: Mon, 19 Jan 2009 21:44:03 GMT header: Server: Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP- Server header: Set-Cookie: JSESSIONID=0a19055a30d630c427bda71d4e26a37ca604b9f590dc.e3eNaNiRah4Pe3aSch8Sc3yOc40; path=/web header: Expires: Mon, 19 Jan 2009 21:44:13 GMT header: Surrogate-Control: max-age="10" header: Content-Type: text/html; charset=ISO-8859-2 header: X-Cache: MISS from www.orange.sk header: Connection: close header: Transfer-Encoding: chunked > >>> opener.open(urllib2.Request('https://www.orange.sk/', None, headers)) reply: '' Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open r = h.getresponse() File "/usr/lib/python2.5/httplib.py", line 928, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 385, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 349, in _read_status raise BadStatusLine(line) httplib.BadStatusLine As you can see the reply from the server seems empty (which results in the BadStatusLine exception) Any help greatly appreciated. -- ak From tjreedy at udel.edu Mon Jan 19 17:03:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:03:32 -0500 Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: Alan G Isaac wrote: >> On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote: >>> we are supposed to prefer No, no 'supposed to's. You are not even 'supposed to' like or use Python. (Unless, I supposed, an employer demands it. But that is another story.) Certainly, one is not 'supposed to' prefer the new to the carefully picked best use example of the old. Guido and some developers prefer the totality of uses cases and possibilities of .format to the same for % formatting. > On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote: >> Well, that second example certainly is a WTF. I think we are supposed >> to prefer: > >> '{0}{0}'.format('wtf?') >> to '%%s%s' % 'wtf?' % 'wtf?' > > But your replacement misses the point of the example, I read it the same way and has the same thought as Steven. Perhaps all the obviously angry 'wtf?'s distracted me. > which is that sequential formatting is often needed. > That is, you need to generate a format string from > a format string. More explicitly: > > '{{0}} {0}'.format('earlyinfo').format('lateinfo') > > '%%s %s' % 'earlyinfo' % 'lateinfo' This is what you should have written. Having never seen or done this, I first missed the doubled '%%' and read it as a syntax error. > I would like assurance that it is not deprecated. > Can you back that? If you claim something exists, you have the burden of proof. I have not seen 3.0 emit a % deprecation warning. Have you? Last I read, Guido *plans* to deprecate % formatting 'sometime'. Terry Jan Reedy From Graham.Dumpleton at gmail.com Mon Jan 19 17:06:28 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Mon, 19 Jan 2009 14:06:28 -0800 (PST) Subject: wsgi silently swallows errors References: Message-ID: <87971174-6cb0-4d53-8de7-3b1f919df7e6@a26g2000prf.googlegroups.com> On Jan 20, 8:03?am, Jean-Paul Calderone wrote: > On Mon, 19 Jan 2009 12:15:29 -0800, Ron Garret wrote: > >Consider the following wsgi app: > > >def application(env, start_response): > > ?start_response('200 OK',[('Content-type','text/plain')]) > > ?yield "hello" > > ?x=1/0 > > ?yield "world" > > >The result of this is that the web browser displays "hello" and an error > >message ends up in the web log. ?But there is no other indication that > >an error has occurred. > > >Is there any way to get WSGI to not silently swallow errors that occur > >after start_response has been called? > > WSGI is a specification, not a piece of software. ?The specification isn't > swallowing the error, some piece of software is. ?What WSGI container are > you using? Not Apache/mod_wsgi at least, as message would show in Apache error logs. [Tue Jan 20 09:03:19 2009] [info] [client ::1] mod_wsgi (pid=271, process='wsgi', application='dangermouse:8224|/wsgi/scripts/ swallow.py'): Loading WSGI script '/usr/local/wsgi/scripts/swallow.py' [Tue Jan 20 09:03:19 2009] [error] [client ::1] mod_wsgi (pid=271): Exception occurred processing WSGI script '/usr/local/wsgi/scripts/ swallow.py' [Tue Jan 20 09:03:19 2009] [error] [client ::1] Traceback (most recent call last) [Tue Jan 20 09:03:19 2009] [error] [client ::1] File "/usr/local/ wsgi/scripts/swallow.py", line 7, in application[Tue Jan 20 09:03:19 2009] [error] [client ::1] x=1/0 [Tue Jan 20 09:03:19 2009] [error] [client ::1] ZeroDivisionError: integer division or modulo by zero Would just need to make sure you look in the correct log if have virtual host specific error logs. Graham From tjreedy at udel.edu Mon Jan 19 17:25:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:25:01 -0500 Subject: Beginner Question In-Reply-To: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> References: <5caea3690901191139v6ce91aa9r50c965c6254cccfa@mail.gmail.com> Message-ID: K-Dawg wrote: > I do no understand the underscore methods. Names of the form __xyx__ are defined by the language definition and recognized and used by the interpreter. See PythonLanguage / LexicalAnalysis / Identifiers / Reserved Most refer to methods, a few to other attributes. Modules may have several non-method attributes, such as '__builtins__', '__doc__', '__file__', '__name__', and '__package__'. The top-level module created when the interpreter starts is given the name '__main__'. If a module is imported, it __name__ is the import name. >>> __name__ '__main__' >>> import email >>> email.__name__ 'email' >>> email.__file__ 'C:\\Programs\\Python30\\lib\\email\\__init__.py' If email were run directly, its name would be __main__ while the __file__ would be the same. Most syntax operations have a corresponding special that implements the operation. This allows user-defined objects to fully participate in syntax operations on an equal basis with built-in objects. See PythonLanguage Manual / Data model / Special operations. From fairwinds.dp at gmail.com Mon Jan 19 17:29:14 2009 From: fairwinds.dp at gmail.com (David Pratt) Date: Mon, 19 Jan 2009 18:29:14 -0400 Subject: Ordering attributes for dynamically generated class In-Reply-To: References: Message-ID: Hi Aaron, this worked out fine. Using an ordered dict to subclass dict. Many thanks. David On Jan 18, 2009, at 11:57 AM, Aaron Brady wrote: > On Jan 18, 9:52 am, David Pratt wrote: >> Hi list. I use 'type' to generate classes but have a need to order >> the attributes for the generated class. Of course a dict is not going >> to maintain ordering. Is there any way to dynamically generate a >> class with attributes in specific order? >> >> my_new_class = type( 'MyNewClass', tuple_of_bases, >> dict_of_attributes) >> >> Many thanks, >> David > > Just a thought, you can subclass 'dict' and assign an instance of it > to the __dict__ member of your new instance. > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Mon Jan 19 17:37:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 17:37:53 -0500 Subject: tasklet library based on PEP 0342 In-Reply-To: References: Message-ID: charlie137 at gmail.com wrote: > Using new features of python generators, as described in PEP 0342, it > is possible to write some sort of "tasklets" in a maner very similar > to stackless python, but running on cpython. For example : > > @tasklet > def my_task(): > yield Timer(10) > yield "result" > > @tasklet > def other_task(): > result = yield my_task() > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > project for openmoko [0], there is also an other very similar > implementation from the kiwi project [1]. > > This kind of tool is very useful, but unfortunately there is no > standard library that would provide a unified way to use it > independently of the underlying event loop. > > Does someone know if a similar library could eventually be added into > python standard libraries ? Would it be accepted as a PEP ? Start by listing your module/library on http://pypi.python.org/pypi To ever get in the stdlib, it must be tested, used by several different people, the best of its type, and relative stable. From prologic at shortcircuit.net.au Mon Jan 19 17:39:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 08:39:51 +1000 Subject: function to find the modification date of the project In-Reply-To: <4974F43E.4020402@strout.net> References: <4974F43E.4020402@strout.net> Message-ID: On Tue, Jan 20, 2009 at 7:44 AM, Joe Strout wrote: > This isn't a question, but something I thought others may find useful (and > if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of our > app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python doesn't > really have a meaningful compile date. So, instead we're now displaying the > latest modification date of any .py file in the project. Here's the > function that finds that: You know you could just store a __version__ attribute in your main library (__init__.py). :) Normally in my project, this version string is stored in __version__.py in my library and fetched in by my library's __init__.py and setup.py for distribution. Works great :) cheers James From prologic at shortcircuit.net.au Mon Jan 19 17:43:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 08:43:49 +1000 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: On Tue, Jan 20, 2009 at 8:39 AM, James Mills wrote: > On Tue, Jan 20, 2009 at 7:44 AM, Joe Strout wrote: >> This isn't a question, but something I thought others may find useful (and >> if somebody can spot any errors with it, I'll be grateful). >> >> We had a case recently where the client was running an older version of our >> app, and didn't realize it. In other languages I've avoided this by >> displaying the compile date in the About box, but of course Python doesn't >> really have a meaningful compile date. So, instead we're now displaying the >> latest modification date of any .py file in the project. Here's the >> function that finds that: > > You know you could just store a __version__ > attribute in your main library (__init__.py). :) > > Normally in my project, this version string > is stored in __version__.py in my library and > fetched in by my library's __init__.py and setup.py > for distribution. Works great :) Also I'd like to point out that your method is not very reliable as the modification time of those files could change at any moment. Consider unix systems for instnace where you could do: touch * And poof, you're modification times are now the current time! Sorry for finding flaws in your approach! :) cheers James From google at mrabarnett.plus.com Mon Jan 19 17:50:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jan 2009 22:50:30 +0000 Subject: function to find the modification date of the project In-Reply-To: <4974F43E.4020402@strout.net> References: <4974F43E.4020402@strout.net> Message-ID: <497503B6.7020507@mrabarnett.plus.com> Joe Strout wrote: > This isn't a question, but something I thought others may find useful > (and if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of > our app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python > doesn't really have a meaningful compile date. So, instead we're now > displaying the latest modification date of any .py file in the project. > Here's the function that finds that: > > > def lastModDate(): > "Get the latest modification date (as a string) of any .py file in > this project." > import os, time > latest = 0 > dir = os.path.dirname(__file__) > if dir == '': dir = '.' # HACK, but appears necessary > for fname in os.listdir(dir): > if fname.endswith('.py'): > modtime = os.stat(os.path.join(dir, fname)).st_mtime > if modtime > latest: latest = modtime > out = time.strftime('%Y-%m-%d', time.localtime(latest)) > return out > > > The intent of this code is to find any .py files in the same directory > as the module containing the above code, and return (as a date string in > SQL/ISO format) the latest modification date thereof. Then, this is > displayed to the user in the about box like so: > > dlg = wx.MessageDialog(self, > "etown unified database system\nRevision: %s" \ > % lastModDate(), > "About etown Central", wx.OK | wx.ICON_INFORMATION) > dlg.ShowModal() > dlg.Destroy() > > (That's wxPython, of course.) > > I haven't yet tested this in a packaged app or on Windows, but it seems > to work in our OS X test environment. > > One odd thing was the need to employ the HACK identified above, where if > __file__ happens to already be in the current directory, then > os.path.dirname of it returns the empty-string -- yet the empty-string > is not a valid argument to os.listdir(). Is there a better way to a > list of files in the same directory as a given file? > I tend to prefer: dir = os.path.dirname(sys.argv[0]) and: modtime = os.path.getmtime(os.path.join(dir, fname)) From georgegrimes at ti.com Mon Jan 19 17:50:43 2009 From: georgegrimes at ti.com (Grimes, George) Date: Mon, 19 Jan 2009 16:50:43 -0600 Subject: Problem with IDLE on windows XP Message-ID: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> I am trying to learn Python and I installed version 2.6 both at home and at work. At home, on Vista, everything works fine. At work, on XP, IDLE would not run. I uninstalled/reinstalled and got the same thing. My cursor changes to the wait symbol for a few seconds, then goes back to normal and ?.nothing. The Task Manager shows nothing. I uninstalled again, made sure all the files were deleted from the disk, used regedit to delte every registry entry that had python in it and tried version 3.0. Geuss, what? I still can?t run IDLE on XP? Is this a common problem? Or am I unique? Thanks, George George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell Failure is the opportunity to begin again, more intelligently. Henry Ford -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Mon Jan 19 18:19:39 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 16:19:39 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: <49750A8B.5090106@strout.net> James Mills wrote: > You know you could just store a __version__ > attribute in your main library (__init__.py). :) What, and update it manually? I don't trust myself to remember to do that every time! Best, - Joe From joe at strout.net Mon Jan 19 18:20:36 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 16:20:36 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> Message-ID: <49750AC4.9050709@strout.net> James Mills wrote: > Also I'd like to point out that your method is not > very reliable as the modification time of those > files could change at any moment. Consider > unix systems for instnace where you could do: > > touch * > > And poof, you're modification times are now > the current time! Yes, and presumably if some power user did this, then that would be the intended effect. Not sure why they'd do that, but they must have a good reason -- who am I to stop them? Cheers, - Joe From tjreedy at udel.edu Mon Jan 19 18:27:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 18:27:21 -0500 Subject: python resource management In-Reply-To: References: Message-ID: S.Selvam Siva wrote: > Hi all, > > I am running a python script which parses nearly 22,000 html files > locally stored using BeautifulSoup. > The problem is the memory usage linearly increases as the files are > being parsed. > When the script has crossed parsing 200 files or so, it consumes all the > available RAM and The CPU usage comes down to 0% (may be due to > excessive paging). I have to guess that you are somehow holding on to data associated with each file. > We tried 'del soup_object' and used 'gc.collect()'. But, no improvement. 'del ob' only deletes the association between name 'ob' and the object it was associated with. The object itself cannot disappear until all associations are gone. gc.collect only deletes circularly associated objects that collectively are isolated. From prologic at shortcircuit.net.au Mon Jan 19 18:28:01 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 09:28:01 +1000 Subject: function to find the modification date of the project In-Reply-To: <49750A8B.5090106@strout.net> References: <4974F43E.4020402@strout.net> <49750A8B.5090106@strout.net> Message-ID: On Tue, Jan 20, 2009 at 9:19 AM, Joe Strout wrote: > James Mills wrote: > >> You know you could just store a __version__ >> attribute in your main library (__init__.py). :) > > What, and update it manually? I don't trust myself to remember to do that > every time! If you read my post carefully you'll have seen that I in fact do not update it manually. It's updated when I do: $ python setup.py sdist or bdist or bdist_egg cheers James From prologic at shortcircuit.net.au Mon Jan 19 18:32:21 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 09:32:21 +1000 Subject: function to find the modification date of the project In-Reply-To: <49750AC4.9050709@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: On Tue, Jan 20, 2009 at 9:20 AM, Joe Strout wrote: > Yes, and presumably if some power user did this, then that would be the > intended effect. Not sure why they'd do that, but they must have a good > reason -- who am I to stop them? Actually I'm fairly certain there -could- potentially be tools out there that would inadvertantly do this :) Who knows! :) Anyway, thanks for sharing your code. Though I'd take MRAB's suggestion and try to simplify your function :) Less is more! cheers James From ppearson at nowhere.invalid Mon Jan 19 18:57:04 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 19 Jan 2009 23:57:04 GMT Subject: ossaudiodev problem: sawtooth noise Message-ID: <6tkiagFaplkjU1@mid.individual.net> The following code uses ossaudiodev to read 1000 values from my sound card at a rate of 12,000 samples per second: *********** begin code *********** import ossaudiodev as o import struct d = o.open( "r" ) _, _, _ = d.setparameters( o.AFMT_S16_LE, 1, # channels 12000, # samples/s True ) # strict n_samples = 1000 bytes = d.read( 2 * n_samples ) for x in struct.unpack( "<%dh" % n_samples, bytes ): print( "%d" % x ) d.close() ************* end code ************ When I select a sample rate that is not a power of 2 times 3000 samples/second, a strong and very regular sawtooth is superimposed on the signal. At some sampling frequencies, it appears as a rising sawtooth, and at other sampling frequencies it is a declining sawtooth, so I'm presumably lost in some aliasing wilderness. As best I can tell, it's a 48 KHz sawtooth. Am I doing something wrong? Is ossaudiodev the wrong choice for capturing sound-card data? Thanks for any helpful comments. -- To email me, substitute nowhere->spamcop, invalid->net. From tjreedy at udel.edu Mon Jan 19 19:02:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Jan 2009 19:02:10 -0500 Subject: function to find the modification date of the project In-Reply-To: <49750AC4.9050709@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: Joe Strout wrote: > James Mills wrote: > >> Also I'd like to point out that your method is not >> very reliable as the modification time of those >> files could change at any moment. Consider >> unix systems for instnace where you could do: >> >> touch * >> >> And poof, you're modification times are now >> the current time! > > Yes, and presumably if some power user did this, then that would be the > intended effect. Not sure why they'd do that, but they must have a good > reason -- who am I to stop them? What if a curious user simple looks at a file with an editor and saves it without change? Or changes it inconsequentially? Or makes copy to x.py.orig, edits and plays with original, and when done renames x.py.orig to x.py. Or any such thing (which I have done in Pythonxy/Lib) without any intention of changing version date? From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 19:07:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 00:07:35 GMT Subject: function to find the modification date of the project References: <4974F43E.4020402@strout.net> Message-ID: On Mon, 19 Jan 2009 16:19:39 -0700, Joe Strout wrote: > James Mills wrote: > >> You know you could just store a __version__ attribute in your main >> library (__init__.py). :) > > What, and update it manually? I don't trust myself to remember to do > that every time! Presumably you have some sort of procedure for releasing software, ("Does it pass all the unit tests? Website updated? Okay, now ship it!"). Perhaps what you need is to add to that procedure a unit test that you run before each release (but not during development) which fails if you haven't updated the version number. Also you should consider submitting a feature request for listdir() to accept the empty string as equivalent to '.'. -- Steven From astan.chee at al.com.au Mon Jan 19 19:08:45 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 20 Jan 2009 11:08:45 +1100 Subject: defining class functions Message-ID: <4975160D.4080208@al.com.au> Hi, I have two classes in python that are in two different files/python scripts. Class A uses Class B like this: class B(object): def function1(self,something): pass def function2(self,something): print "hello one" print something class A(object): def __init__(self): instance = B() instance.function2("hello two") self.function3() def function3(self): print "hello three" What I want to do here is to (re)define function1 from function3. Is that possible? Is there any way of redefining a function of another class without inheriting it? Does this make sense? Thanks Astan From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 19:14:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 00:14:28 GMT Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote: > Hi everyone, > > I have a problem with urllib2 on this particular url, hosted on an > Oracle HTTP Server > > http://www.orange.sk/eshop/sk/portal/catalog.html? type=post&subtype=phone&null > > which gets 302 redirected to > https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a > cookie through the Set-Cookie header field in the 302 reply. This works > fin with firefox. > > However, with urllib2 and the following code snippet, it doesn't work Looking at the BadStatusLine exception raised, the server response line is empty. Looking at the source for httpllib suggests to me that the server closed the connection early. Perhaps it doesn't like connections from urllib2? I ran a test pretending to be IE using this code: cookiejar = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?' \ 'type=post&subtype=phone&null' agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; " \ "NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" headers = {'User-Agent': agent} req = urllib2.Request(url, data=None, headers=headers) try: s=opener.open(req) except httplib.BadStatusLine, e: print e, e.line else: print "Success" but it failed. So the problem is not as simple as changing the user-agent string. Other than that, I'm stumped. -- Steven From vivacarlie at gmail.com Mon Jan 19 19:28:24 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Mon, 19 Jan 2009 18:28:24 -0600 Subject: ifconfig in python Message-ID: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Is ther an easy way to get the resolved ip address of the machine a script is running on? socket.gethostbyname(socket.gethostname) has only returned the ip address of my loop back interface ... not very usefull. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Mon Jan 19 19:29:23 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 20 Jan 2009 01:29:23 +0100 Subject: wsgi silently swallows errors References: Message-ID: <3gif46-h2h.ln1@archaeopteryx.softver.org.mk> > Consider the following wsgi app: > > def application(env, start_response): > start_response('200 OK',[('Content-type','text/plain')]) > yield "hello" > x=1/0 > yield "world" > > The result of this is that the web browser displays "hello" and an > error > message ends up in the web log. But there is no other indication that > an error has occurred. > > Is there any way to get WSGI to not silently swallow errors that occur > after start_response has been called? yes, you can wrap your app in a WebError middleware http://pypi.python.org/pypi/WebError from weberror.evalexception import EvalException application = EvalException(application) -- ?????? ( http://softver.org.mk/damjan/ ) In theory, there is no difference between theory and practice. But, in practice, there is. From prologic at shortcircuit.net.au Mon Jan 19 19:31:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 10:31:58 +1000 Subject: defining class functions In-Reply-To: <4975160D.4080208@al.com.au> References: <4975160D.4080208@al.com.au> Message-ID: On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee wrote: > Hi, > I have two classes in python that are in two different files/python scripts. > Class A uses Class B like this: > class B(object): > def function1(self,something): > pass > def function2(self,something): > print "hello one" > print something > > class A(object): > def __init__(self): > instance = B() > instance.function2("hello two") > self.function3() > def function3(self): > print "hello three" def function3(self): print "hello three" self.instance.function1 = lambda x; x But you must bind instnace to self in B Modify your __init__ as follows: class A(object): def __init__(self): self.instance = B() self.instance.function2("hello two") self.function3() What's the use-case anyway ? There might be a better way to solve your problem :) cheers James From vivacarlie at gmail.com Mon Jan 19 19:33:27 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Mon, 19 Jan 2009 18:33:27 -0600 Subject: defining class functions In-Reply-To: References: <4975160D.4080208@al.com.au> Message-ID: <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> wouldn't you use a state change? Use a variable to indicate which function you want the first class to do On Mon, Jan 19, 2009 at 6:31 PM, James Mills wrote: > On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee wrote: > > Hi, > > I have two classes in python that are in two different files/python > scripts. > > Class A uses Class B like this: > > class B(object): > > def function1(self,something): > > pass > > def function2(self,something): > > print "hello one" > > print something > > > > class A(object): > > def __init__(self): > > instance = B() > > instance.function2("hello two") > > self.function3() > > def function3(self): > > print "hello three" > > def function3(self): > print "hello three" > self.instance.function1 = lambda x; x > > But you must bind instnace to self in B > > Modify your __init__ as follows: > > class A(object): > def __init__(self): > self.instance = B() > self.instance.function2("hello two") > self.function3() > > What's the use-case anyway ? > There might be a better way to solve your problem :) > > cheers > James > -- > http://mail.python.org/mailman/listinfo/python-list > -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 19:34:04 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 10:34:04 +1000 Subject: ifconfig in python In-Reply-To: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres wrote: > Is ther an easy way to get the resolved ip address of the machine a script > is running on? socket.gethostbyname(socket.gethostname) has only returned > the ip address of my loop back interface ... not very usefull. That's because your /etc/hosts resolves your hostname to 127.0.0.1 :) And no I know of no "easy" way cross platform way. Perhaps parsing the output of ifconfig itself ? cheers James From jstroud at mbi.ucla.edu Mon Jan 19 19:34:09 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 19 Jan 2009 16:34:09 -0800 Subject: defining class functions In-Reply-To: References: Message-ID: Astan Chee wrote: > Hi, > I have two classes in python that are in two different files/python > scripts. Class A uses Class B like this: > class B(object): > def function1(self,something): > pass > def function2(self,something): > print "hello one" > print something > > class A(object): > def __init__(self): > instance = B() > instance.function2("hello two") > self.function3() > def function3(self): > print "hello three" > > What I want to do here is to (re)define function1 from function3. Is > that possible? Is there any way of redefining a function of another > class without inheriting it? Does this make sense? I know what you mean, but it doesn't make a lot of sense. Best practice is to make the function module level, especially if self is not referenced beyond the function definition. If self is referenced, then all selves must share the same behavior if not the same heredity, and using a module level function is still best: def function(quacker): print "hello there" quacker.quack() James From astan.chee at al.com.au Mon Jan 19 19:36:03 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 20 Jan 2009 11:36:03 +1100 Subject: defining class functions In-Reply-To: <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> References: <4975160D.4080208@al.com.au> <65fadfc30901191633n2081bea2o4dea246c7642b3cb@mail.gmail.com> Message-ID: <49751C73.6020502@al.com.au> Actually, yes, I just realized a better way of doing this without state change based on the requirement. Thanks for the info anyway Nehemiah Dacres wrote: > wouldn't you use a state change? Use a variable to indicate which > function you want the first class to do > > On Mon, Jan 19, 2009 at 6:31 PM, James Mills > > > wrote: > > On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee > wrote: > > Hi, > > I have two classes in python that are in two different > files/python scripts. > > Class A uses Class B like this: > > class B(object): > > def function1(self,something): > > pass > > def function2(self,something): > > print "hello one" > > print something > > > > class A(object): > > def __init__(self): > > instance = B() > > instance.function2("hello two") > > self.function3() > > def function3(self): > > print "hello three" > > def function3(self): > print "hello three" > self.instance.function1 = lambda x; x > > But you must bind instnace to self in B > > Modify your __init__ as follows: > > class A(object): > def __init__(self): > self.instance = B() > self.instance.function2("hello two") > self.function3() > > What's the use-case anyway ? > There might be a better way to solve your problem :) > > cheers > James > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > > "lalalalala! it's not broken because I can use it" > > http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jan 19 19:45:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jan 2009 16:45:17 -0800 Subject: Logging help In-Reply-To: References: Message-ID: <50697b2c0901191645x4cff58b9nf9d506eb2bdc9752@mail.gmail.com> On Mon, Jan 19, 2009 at 11:36 AM, koranthala wrote: > Hi, > Is it possible somehow to have the logging module rotate the files > every time I start it. > Basically, I can automatically rotate using RotatingFileHandler; > Now I want it rotated every time I start the program too. Just call the .doRollover() method of the RotatingFileHandler at the start of the program. Reading The Fine Documentation for the module is helpful. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rhodri at wildebst.demon.co.uk Mon Jan 19 19:49:13 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 00:49:13 -0000 Subject: reading file to list In-Reply-To: <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> Message-ID: On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: > On Jan 17, 10:25 am, Tino Wildenhain wrote: >> > [[int(x) for x in line.split()] for line in open("blob.txt")] > > Nice (python code). > > Few comments: > > ? the above code is borderline of atypical. e.g. it is not a average > python code would produce or one'd seen in corporate python code. I can't imagine why not. It's clean and clear, after all. If I needed to do the slightly odd processing that it's written to do, the only change I'd make for production code is to wrap the file object in a 'with' statement. > ? voodoo like the above makes me dislike python. To me, the one > advantage of python is its clarity enforced by its syntax. > Specifically, the forced indendation and quite simple semantics. > However, the way i've seen Guido's propensities and how python 3 is > moving to, it is becoming more mumbo jumbo of computer sciency OOP > jargons with syntax soup. (with iterators, enumerators, list > comprehension... shits forced upon the users) > > The above line illustrate well the ad hoc syntax soup nature python is > moving into. To a native English speaker, it illustrates entirely the reverse. List comprehension is actually quite a linguistically natural way to express the iterative construction of a list. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Mon Jan 19 19:53:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 00:53:09 -0000 Subject: A java hobbyist programmer learning python In-Reply-To: <0182896d$0$8693$c3e8da3@news.astraweb.com> References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Sun, 18 Jan 2009 02:24:51 -0000, Steven D'Aprano wrote: > Let me re-write your code in a more Pythonic way. This is not the only > way to do this, and it probably isn't the best way, but it may give you a > flavour for the way Python is usually written. > > > import sys > import operator > class Calculator(): > dispatch = { # dispatch table mapping symbol to function > '+': operator.add, > '-': operator.sub, > '*': operator.mul, > '/': operator.truediv, > } > def __init__(self): > self.operator = sys.argv[1] > self.arg1 = int(sys.argv[2]) > self.arg2 = int(sys.argv[3]) If you want the test code to work, I think you mean: def __init__(self, op, arg1, arg2): self.operator = op self.arg1 = arg1 self.arg2 = arg2 :) -- Rhodri James *-* Wildebeeste Herder to the Masses From Scott.Daniels at Acm.Org Mon Jan 19 19:59:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 19 Jan 2009 16:59:47 -0800 Subject: function to find the modification date of the project In-Reply-To: References: Message-ID: <3JednQbu9NAtvOjUnZ2dnUVZ_hudnZ2d@pdx.net> Joe Strout wrote: > This isn't a question, but something I thought others may find useful > (and if somebody can spot any errors with it, I'll be grateful). > > We had a case recently where the client was running an older version of > our app, and didn't realize it. In other languages I've avoided this by > displaying the compile date in the About box, but of course Python > doesn't really have a meaningful compile date. So, instead we're now > displaying the latest modification date of any .py file in the project. > Here's the function that finds that: > > > def lastModDate(): > "Get the latest modification date (as a string) of any .py file in > this project." > import os, time > latest = 0 > dir = os.path.dirname(__file__) > if dir == '': dir = '.' # HACK, but appears necessary > for fname in os.listdir(dir): > if fname.endswith('.py'): > modtime = os.stat(os.path.join(dir, fname)).st_mtime > if modtime > latest: latest = modtime > out = time.strftime('%Y-%m-%d', time.localtime(latest)) > return out Here's how I'd do it with your specs: def lastModDate(directory=None): "Latest modification ISO date string of .py files in this directory" import os, time latest = 0 if directory is None: directory = os.path.dirname(__file__) for fname in os.listdir(directory or '.'): if fname.endswith('.py'): modtime = os.stat(os.path.join(directory, fname)).st_mtime if modtime > latest: latest = modtime return time.strftime('%Y-%m-%d', time.localtime(latest)) And I'd prefer: def lastPyDate(directory=None): "Latest modification ISO date string of .py files in this file tree" import os, time latest = 0 if directory is None: directory = os.path.dirname(__file__) for base, dirs, files in os.walk(directory): for name in files: if name.endswith('.py'): modtime = os.stat(os.path.join(base, name)).st_mtime if modtime > latest: latest = modtime return time.strftime('%Y-%m-%d', time.localtime(latest)) But, as someone mentioned, if one of your users edits one of your files without changing it, he has accidentally changed the version of the code. This you could forestall by invoking your function at packaging time, and writing a file with the version string in it. --Scott David Daniels Scott.Daniels at Acm.Org From kyrie at uh.cu Mon Jan 19 20:09:40 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 20:09:40 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232413780.497524545347c@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 7:13?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > > > I must be missing the point : if it's a public attribute, it doesn't > > need a "property" ? I guess we use the same words for different things > here. > > Yes, you are missing more than one point. > > Scala automatically converts public data members into properties, > apparently to save the programmer the trouble of doing it manually. If > you are interested, I'm sure you can find publicly available > information on it. Russ, I think _you_ are missing the point. If the attribute is already public, why does it need properties? Why would a programmer go to the trouble of adding them manually, just to get one level of indirection for an already public attribute? > > I definitively wouldn't bet my ass on language-level access restriction > > to protect software from fraud or sabotage. > > You're missing the point here too. I'll try one more time to explain > it. And I think you are conflating the idea of "private" as in "secret information that should not be known by the _public_" and "private" as in "static safeguards enforced by the compiler to prevent accidents" [and you are missing the third, "compiler feature to prevent namespace pollution without having to use extremely unlikely variable names", i.e, self.__x in python]. No wonder you can't get Bruno's point. For the second, static checks to prevent accidents, you have pylint. For the first, not only you are using the wrong tool, but you are barking at python for not having it. Assuming that pylint is perfect (big assumption, but it is up to you to prove where it fails), what would be the difference between only accepting/running "pylint-authorized code" and the enforced hiding you desire? This thread is starting to remind me of a professor of mine, who once claimed that python didn't have private attributes because it "is opensource and anyone can see the source code anyway", and the obvious confusion of his students ("why should I make my entrypoint '_public_ static void main', if it is _my_ sourcecode and I don't want to share it?"). What you want is not enforced data hiding. You want something actually designed to try to prevent abuses from hostile programmers - go use .Net or Java, who attempt to do that (I don't know with what level of success, but they at least provide you the 'locks' and 'police' that you need). Or better yet, write a proposal about how to implement code trust in Python. I'll support you on that one, and I think many others will. But if you keep presenting data hiding as a solution to that problem... I doubt that you will be heard. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From spoofy1 at gmx.net Mon Jan 19 20:15:47 2009 From: spoofy1 at gmx.net (Spoofy) Date: Tue, 20 Jan 2009 02:15:47 +0100 Subject: Two questions about style and some simple math Message-ID: <497525C3.5090904@gmx.net> Hello everybody! Though I'm a hobby programmer for years now (mainly small hackery things) I still have big problems getting "real" things to work. I'm currently trying to write a simple RPG and have problems with the following: 1. Characters have a "courage" attribute that basically determins who has the first attack in a fight. After some trying, I came up with this (sorry, not really working code, but what I made from interactive experimentation): def first_attack(player1, player2): diff = player1.attributes.courage - player2.attributes.courage players = (player, player2) return players[diff + random.randint(-diff, diff) < 0] To make it more realistic, I randomized it a little bit and this seems to work for low courage values. But when the courage values are high (100 and such) it fails (the chance to have the first attack drops the higher the values are). My math is really bad and I have problems to understand what's happenning here. I suspect the greater range for randint() is the problem, but I don't really get why. Any tips would be greatly appreciated. 2. For maintaining the character attributes I creates a seperate class. I wonder weather this is an "overuse" of OO (instead of just making the attributes plain variables of the Char class) and if the way I wrote this is OK (somehow this looks cool to me but maybe too "showy"?) class Attributes(object): ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": 0, "condition": 0} def __init__(self, **kwargs): self.__dict__.update(self.ATTRIBUTES) for arg in kwargs: if arg not in self.ATTRIBUTES: raise ValueError("Unkown character attribute '%s'" % arg) self.__dict__[arg] = kwargs[arg] Again, I appreciate any tips. I you need more code (for the bigger picture or such), just ask. Thanks in advance From rhodri at wildebst.demon.co.uk Mon Jan 19 20:44:44 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 20 Jan 2009 01:44:44 -0000 Subject: Two questions about style and some simple math In-Reply-To: <497525C3.5090904@gmx.net> References: <497525C3.5090904@gmx.net> Message-ID: On Tue, 20 Jan 2009 01:15:47 -0000, Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with the > following: > > 1. > > Characters have a "courage" attribute that basically determins who has > the first attack in a fight. After some trying, I came up with this > (sorry, not really working code, but what I made from interactive > experimentation): > > def first_attack(player1, player2): > diff = player1.attributes.courage - player2.attributes.courage > players = (player, player2) > return players[diff + random.randint(-diff, diff) < 0] > > To make it more realistic, I randomized it a little bit and this seems > to work for low courage values. But when the courage values are high > (100 and such) it fails (the chance to have the first attack drops the > higher the values are). My math is really bad and I have problems to > understand what's happenning here. I suspect the greater range for > randint() is the problem, but I don't really get why. > > Any tips would be greatly appreciated. This is always going to select player1 (assuming you fix the typo of "player" for "player1"!). The most negative number that the call to randint can produce is "-diff", so "diff + randint()" is at least "diff + -diff", which is zero and hence never less than zero. Surely in any case you don't want an expression based on the difference, since that would give you the same chance of having the first attack no matter what the levels of courage actually were, which can't be right. > 2. > > For maintaining the character attributes I creates a seperate class. I > wonder weather this is an "overuse" of OO (instead of just making the > attributes plain variables of the Char class) and if the way I wrote > this is OK (somehow this looks cool to me but maybe too "showy"?) > > class Attributes(object): > ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": > 0, "condition": 0} > def __init__(self, **kwargs): > self.__dict__.update(self.ATTRIBUTES) > for arg in kwargs: > if arg not in self.ATTRIBUTES: > raise ValueError("Unkown character attribute '%s'" % > arg) > self.__dict__[arg] = kwargs[arg] It's not necessarily a bad idea to have your character attributes in a separate class, but do you really need to prevent use of other class attribute names (sorry, the terminology crossover is inherently confusing) so much? Unless you think there's a serious danger of trying to add new character attributes on the fly, I think it's overkill. -- Rhodri James *-* Wildebeeste Herder to the Masses From google at mrabarnett.plus.com Mon Jan 19 20:54:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 01:54:01 +0000 Subject: Two questions about style and some simple math In-Reply-To: <497525C3.5090904@gmx.net> References: <497525C3.5090904@gmx.net> Message-ID: <49752EB9.1050600@mrabarnett.plus.com> Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with the > following: > > 1. > > Characters have a "courage" attribute that basically determins who has > the first attack in a fight. After some trying, I came up with this > (sorry, not really working code, but what I made from interactive > experimentation): > > def first_attack(player1, player2): > diff = player1.attributes.courage - player2.attributes.courage > players = (player, player2) > return players[diff + random.randint(-diff, diff) < 0] > > To make it more realistic, I randomized it a little bit and this seems > to work for low courage values. But when the courage values are high > (100 and such) it fails (the chance to have the first attack drops the > higher the values are). My math is really bad and I have problems to > understand what's happenning here. I suspect the greater range for > randint() is the problem, but I don't really get why. > > Any tips would be greatly appreciated. > [snip] Try: def first_attack(player1, player2): total_courage = player1.attributes.courage + player2.attributes.courage players = (player, player2) return players[random.randrange(0, total_courage) < player1.attributes.courage] From gert.cuykens at gmail.com Mon Jan 19 20:54:07 2009 From: gert.cuykens at gmail.com (gert) Date: Mon, 19 Jan 2009 17:54:07 -0800 (PST) Subject: s=str(binary) Message-ID: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> How do you convert s back to binary data in python 3 so I can put in a sqlite blob ? Is there a build in function or do I need to use binascii ? byte(s) or bin(s) would make more sense but can not figure it out ? From Russ.Paielli at gmail.com Mon Jan 19 21:07:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 18:07:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > Russ, I think _you_ are missing the point. > If the attribute is already public, why does it need properties? Why would a > programmer go to the trouble of adding them manually, just to get one level of > indirection for an already public attribute? You don't understand the purpose of properties -- and you tell me that *I* am the one missing the point? I give up. I really don't have time for this. From mensanator at aol.com Mon Jan 19 21:11:24 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 19 Jan 2009 18:11:24 -0800 (PST) Subject: Two questions about style and some simple math References: <497525C3.5090904@gmx.net> Message-ID: <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> On Jan 19, 7:44?pm, "Rhodri James" wrote: > On Tue, 20 Jan 2009 01:15:47 -0000, Spoofy wrote: > > Hello everybody! > > > Though I'm a hobby programmer for years now (mainly small hackery ? > > things) I still have big problems getting "real" things to work. > > > I'm currently trying to write a simple RPG and have problems with the ? > > following: > > > 1. > > > Characters have a "courage" attribute that basically determins who has ? > > the first attack in a fight. After some trying, I came up with this ? > > (sorry, not really working code, but what I made from interactive ? > > experimentation): > > > def first_attack(player1, ?player2): > > ? ? ?diff = player1.attributes.courage - player2.attributes.courage > > ? ? ?players = (player, ?player2) > > ? ? ?return players[diff + random.randint(-diff, ?diff) < 0] > > > To make it more realistic, I randomized it a little bit and this seems ? > > to work for low courage values. But when the courage values are high ? > > (100 and such) it fails (the chance to have the first attack drops the ? > > higher the values are). My math is really bad and I have problems to ? > > understand what's happenning here. I suspect the greater range for ? > > randint() is the problem, but I don't really get why. > > > Any tips would be greatly appreciated. > > This is always going to select player1 (assuming you fix the typo of > "player" for "player1"!). ?The most negative number that the call to > randint can produce is "-diff", so "diff + randint()" is at least > "diff + -diff", which is zero and hence never less than zero. > > Surely in any case you don't want an expression based on the difference, > since that would give you the same chance of having the first attack no > matter what the levels of courage actually were, which can't be right. Why? Isn't it possible some attributes are relative rather than absolute? > > > > > > > 2. > > > For maintaining the character attributes I creates a seperate class. I ? > > wonder weather this is an "overuse" of OO (instead of just making the ? > > attributes plain variables of the Char class) and if the way I wrote ? > > this is OK (somehow this looks cool to me but maybe too "showy"?) > > > class Attributes(object): > > ? ? ?ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": ? > > 0, "condition": 0} > > ? ? ?def __init__(self, **kwargs): > > ? ? ? ? ?self.__dict__.update(self.ATTRIBUTES) > > ? ? ? ? ?for arg in kwargs: > > ? ? ? ? ? ? ?if arg not in self.ATTRIBUTES: > > ? ? ? ? ? ? ? ? ?raise ValueError("Unkown character attribute '%s'" % ? > > arg) > > ? ? ? ? ? ? ?self.__dict__[arg] = kwargs[arg] > > It's not necessarily a bad idea to have your character attributes in a > separate class, but do you really need to prevent use of other class > attribute names (sorry, the terminology crossover is inherently > confusing) so much? ?Unless you think there's a serious danger of > trying to add new character attributes on the fly, I think it's > overkill. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From bblais at bryant.edu Mon Jan 19 21:15:15 2009 From: bblais at bryant.edu (Brian Blais) Date: Mon, 19 Jan 2009 21:15:15 -0500 Subject: modify IDLE? Message-ID: <733F256C-0D97-4CCD-A83B-64F6EB88B7CE@bryant.edu> Hello, I was wondering if there is a simple way to modify IDLE, adding or replacing menus? I haven't dug into the source code yet, but was wondering if anyone else has done something like this. I have a couple of projects that require users to write python code (or very similar to python code) which is then run either in a completely different interpreter, or pre-processed and run. Right now, I just make those programs load files, but it would be nice if somehow a version of IDLE could pass the current buffer to my program instead of the built-in interpreter. Is mucking around with the IDLE code something easy, or a bit of a challenge? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon Jan 19 21:24:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 12:24:26 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Tue, Jan 20, 2009 at 12:07 PM, Russ P. wrote: >> Russ, I think _you_ are missing the point. >> If the attribute is already public, why does it need properties? Why would a >> programmer go to the trouble of adding them manually, just to get one level of >> indirection for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? Russ, he is correct. Your opinions are not founded on solid knowledge. Python programmers tend to not have a need for properties. Quite honestly they are a waste of time. They come from traditional OO approaches to software design (and mostly from the Java world). > I give up. I really don't have time for this. You've said that before :) cheers James From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 21:24:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 02:24:28 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > >> Russ, I think _you_ are missing the point. If the attribute is already >> public, why does it need properties? Why would a programmer go to the >> trouble of adding them manually, just to get one level of indirection >> for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea Russ is proposing. But I must admit it's not clear to me why Russ thinks it is a good idea to automatically turn this: class Parrot(object): def __init__(self): self.x = 1 into this: class Parrot(object): def __init__(self): self._x = 1 def getx(self): return self._x def setx(self, value): self._x = value x = property(getx, setx) Because frankly, that's how I read Russ' explanation for what Scala is doing. Have I missed something? -- Steven From mdw at distorted.org.uk Mon Jan 19 21:32:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 02:32:28 +0000 Subject: Relax Syntax for Augmented Arithmetic? References: Message-ID: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > There's a practical reason too. You create a new Foo instance, mutate > it with the augmented assignment operator, and then a tenth of a > millisecond later the garbage collector throws it away because it has > a reference count of zero. Only in this specific example. A function can easily return a well-known object, which it's sensible to mutate. Besides, class mumble (object): pass mumble().foo = 1 is accepted without fuss, and is just as useless. I think I see the confusion here. * Python assignment (`=') is fairly simple. The left-hand side is analyzed syntactically: if it's a plain name then the variable it denotes is modified; otherwise an appropriate method is invoked to mutate some object. * Python augmented-assignment (`+=', for example) is inconsistent. Depending on what type of object the left-hand side evaluates to, it may /either/ mutate that object, /or/ assign a new value to the expression. What do I mean? Well, consider this function. def assg(x, y): x = y Under no circumstances does calling this function have any effect (other than wasting time and memory). But: def aug(x, y): x += y Calling this function might or might not have an observable effect, depending on the type of x. For example, x = 5 aug(x, 3) is useless, but x = [1, 2, 3] aug(x, [4]) is not. The `aug' function can be used to bypass the syntactic restriction on augmented assignment, where it makes sense: aug(func(), 17) is always syntactically valid, and may or may not be useless depending on the type of thing returned by `func'. The Python language refuses to let the programmer write something which is (a) possibly meaningful, and (b) possibly useful because augmented assignment inherits the syntactic restriction of simple assignment that the left-hand side expression designate a `place' -- i.e., one of the things that there's a rule for assigning to, e.g., VAR, EXPR[INDEX], EXPR.ID -- because it /might/ need to perform such an assignment, though it might not. My personal view is that augmented-assignment operators which work by mutation rather than assignment (e.g., `+=' on lists, rather than `+=' on numbers) are one of Python's least pleasant warts. But if they're going to exist then I think list() += [1] ought to be valid syntax, since semantically it's actually clear what it should do (namely, construct a fresh empty list, append a `1' to it, and then throw the whole thing away). Of course, tuple() += 1, is still meaningless, and ought to be an error. Of course, this removes a static error-check, but if we were petty about getting all our errors at compile time we wouldn't be writing in Python in the first place. -- [mdw] From narkewoody at gmail.com Mon Jan 19 21:33:21 2009 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 20 Jan 2009 10:33:21 +0800 Subject: Event Handling and Signal-Slot Mechanism In-Reply-To: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> References: <295923b2-3e3c-4bc6-9288-7e81d6a1a190@t39g2000prh.googlegroups.com> Message-ID: On Tue, Jan 20, 2009 at 1:03 AM, BlueBird wrote: > On Jan 19, 4:10 am, Steven Woody wrote: >> Hi, >> >> Python has Signal-Slot mechanism, > > Python does not have signal/slot mechanism. You are talking about the > Qt toolkit, which is initially a (nice) C++ toolkit, available also in > python via the PyQt wrapper. > > Signal/slots were introduced by Qt to make C++ gui programming easier. > Signal/slots basically provides a very easy way to implement the > observer/consumer design pattern, with only 2 or 3 lines of code (as > opposed to one or two classes in java for example). > > Python itself does not have signal/slots but the it's very easy to > emulate them using the Python language. In C++ however, it's tricky to > do signal/slots in pure C++ and this addition is one of the reason > that programming GUI in Qt is nice (personal opinion obviously). > > To comne back to your question: > >> why he still need another mechanism >> Event Handling? > > This is actually a Qt question: why have event handling for some > things, and signal/slot for some others ? > > My opinion on the debate: > - signal/slot add an overhead of one class to every QObject class, and > 3 method calls when emitting a signal (if I remember Qt documentation > correctly). For some real-time tasks, like repainting the screen, > every microseconds must be saved and sparing 3 method calls is a good > idea. > - since a GUI application is fundamentally an event driven system, the > event stuff has to be there anyway. > - signal/slot is very convenient for data exchange between widgets but > I think it would be overkill to use it everywhere. Event propagation > is a nice design as well. > > Now, if you want to discuss this further, I suggest to go to Qt > interest ( http://lists.trolltech.com/qt-interest/ ) which is > dedicated to discussion around Qt. > > cheers, > > Philippe > -- > http://mail.python.org/mailman/listinfo/python-list > So much thanks, Philippe! From Russ.Paielli at gmail.com Mon Jan 19 21:46:29 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 18:46:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> On Jan 19, 6:24?pm, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > >> Russ, I think _you_ are missing the point. If the attribute is already > >> public, why does it need properties? Why would a programmer go to the > >> trouble of adding them manually, just to get one level of indirection > >> for an already public attribute? > > > You don't understand the purpose of properties -- and you tell me that > > *I* am the one missing the point? > > Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > Russ is proposing. But I must admit it's not clear to me why Russ thinks > it is a good idea to automatically turn this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self.x = 1 > > into this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self._x = 1 > ? ? def getx(self): > ? ? ? ? return self._x > ? ? def setx(self, value): > ? ? ? ? self._x = value > ? ? x = property(getx, setx) > > Because frankly, that's how I read Russ' explanation for what Scala is > doing. Have I missed something? > > -- > Steven From sjmachin at lexicon.net Mon Jan 19 21:46:43 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 18:46:43 -0800 (PST) Subject: Two questions about style and some simple math References: Message-ID: On Jan 20, 12:15?pm, Spoofy wrote: > Hello everybody! > > Though I'm a hobby programmer for years now (mainly small hackery > things) I still have big problems getting "real" things to work. > > I'm currently trying to write a simple RPG and have problems with > the following: > > 1. > > Characters have a "courage" attribute that basically determins who > has the first attack in a fight. After some trying, I came up with > this (sorry, not really working code, but what I made from > interactive experimentation): > > def first_attack(player1, ?player2): > ? ? ?diff = player1.attributes.courage - player2.attributes.courage > ? ? ?players = (player, ?player2) > ? ? ?return players[diff + random.randint(-diff, ?diff) < 0] > > To make it more realistic, I randomized it a little bit and this > seems to work for low courage values. But when the courage values > are high (100 and such) it fails (the chance to have the first > attack drops the higher the values are). My math is really bad and I > have problems to understand what's happenning here. I suspect the > greater range for randint() is the problem, but I don't really get why. Are you 100% sure that the above code is what you have been running? For a start, the result of that code depends only on "diff" which is the difference between the two courages -- it should not be influenced by whether the courages are (say) about 10 or about 100. If player1 is more aggro than player2, then diff will be positive. Let's say it's 20. The lowest possible value returned by random.randint (-20, 20) will be -20. Then 20 + (-20) is zero. so 0 < 0 is False, and player 1 will always be chosen. This happens for any positive value of diff, even 1. If the diff is zero, then again you get 0 < 0, and player1 will always be chosen. If the diff is negative, the world blows up; for diff == -10, you get this: ValueError: empty range for randrange() (10,-9, -19) I think that you need to take the range of the courage values into account. You need to scale the randomisation so that you get believable outcomes. If the players have equal courage, there should be a 50% chance that player2 hits first. If one has maximal courage and the other has zero, then the maximal one should have 100% chance of hitting first. For example: >>> def choosep2(diff, maxc): ... assert abs(diff) <= maxc ... return random.randint(-maxc, maxc-1) >= diff ... >>> def simulate(diff, maxc): ... return sum(choosep2(diff, maxc) for _ in range(100)) ... >>> simulate(0, 50) 50 >>> simulate(0, 50) 47 >>> simulate(0, 50) 43 >>> simulate(49, 50) 1 >>> simulate(-49, 50) 100 >>> You may want to choose a probability distribution that's a bit more bell-shaped than roadkill-shaped, but whatever you do you should check that it's behaving plausibly. HTH, John From nad at acm.org Mon Jan 19 21:48:45 2009 From: nad at acm.org (Ned Deily) Date: Mon, 19 Jan 2009 18:48:45 -0800 Subject: ifconfig in python References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: In article , "James Mills" wrote: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres > wrote: > > Is ther an easy way to get the resolved ip address of the machine a script > > is running on? socket.gethostbyname(socket.gethostname) has only returned > > the ip address of my loop back interface ... not very usefull. > > That's because your /etc/hosts resolves > your hostname to 127.0.0.1 :) > > And no I know of no "easy" way cross > platform way. Perhaps parsing the output > of ifconfig itself ? Also, since the subject is on my brain at the moment, how to find "the address" is not the right question to ask. These days most systems have multiple network interfaces (Ethernet, WiFi, dialup, et al) running multiple protocols, like IPv4 and IPv6. In general, there is no *one* IP address of a machine; often there are many. Ignoring that fact can lead to subtle bugs, like the one causing a urllib2 regression test failure that I've been squashing today! -- Ned Deily, nad at acm.org From mdw at distorted.org.uk Mon Jan 19 21:50:28 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 02:50:28 +0000 Subject: ifconfig in python References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: <87d4ein11n.fsf.mdw@metalzone.distorted.org.uk> "James Mills" writes: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres wrote: >> Is ther an easy way to get the resolved ip address of the machine a >> script is running on? socket.gethostbyname(socket.gethostname) has >> only returned the ip address of my loop back interface ... not very >> usefull. > > That's because your /etc/hosts resolves your hostname to 127.0.0.1 :) This just illustrates the real problem with the OP's question. The idea of `/the/ ... ip address of the machine' is simply ill-formed. An Internet host has at least two IP addresses -- one of them is 127.0.0.1 -- and may have many more. The laptop I'm typing on right now has three; the server next door has four. Network interfaces may have multiple addresses associated with them (and hosts using the weak end-system model consider the addresses as referring to the host in general rather than a specific interface anyway), and several interfaces might have the same address. Sorry. Life's more complicated than you'd like it to be. -- [mdw] From prologic at shortcircuit.net.au Mon Jan 19 21:53:58 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 12:53:58 +1000 Subject: ifconfig in python In-Reply-To: References: <65fadfc30901191628i4d116202y3ce5208ccf66b74c@mail.gmail.com> Message-ID: On Tue, Jan 20, 2009 at 12:48 PM, Ned Deily wrote: > Also, since the subject is on my brain at the moment, how to find "the > address" is not the right question to ask. These days most systems have > multiple network interfaces (Ethernet, WiFi, dialup, et al) running > multiple protocols, like IPv4 and IPv6. In general, there is no *one* > IP address of a machine; often there are many. Ignoring that fact can > lead to subtle bugs, like the one causing a urllib2 regression test > failure that I've been squashing today! I agree. Nehemiah: What is the problem you're solving ? cheers James From charlie137 at gmail.com Mon Jan 19 21:57:54 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 18:57:54 -0800 (PST) Subject: tasklet library based on PEP 0342 References: Message-ID: <836b31a3-f70a-4739-a8e0-3dc948138d57@w1g2000prm.googlegroups.com> On Jan 20, 6:37?am, Terry Reedy wrote: > charlie137 at gmail.com wrote: > > Using new features of python generators, as described in PEP 0342, it > > is possible to write some sort of "tasklets" in a maner very similar > > to stackless python, but running on cpython. For example : > > > @tasklet > > def my_task(): > > ? ? yield Timer(10) > > ? ? yield "result" > > > @tasklet > > def other_task(): > > ? ? result = yield my_task() > > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > > project for openmoko [0], there is also an other very similar > > implementation from the kiwi project [1]. > > > This kind of tool is very useful, but unfortunately there is no > > standard library that would provide a unified way to use it > > independently of the underlying event loop. > > > Does someone know if a similar library could eventually be added into > > python standard libraries ? Would it be accepted as a PEP ? > > Start by listing your module/library onhttp://pypi.python.org/pypi > To ever get in the stdlib, it must be tested, used by several different > people, the best of its type, and relative stable. I am afraid my implementation passes none of those requirement. I will send a message to the python idea mailing list though. Thanks for the answers. Guillaume From charlie137 at gmail.com Mon Jan 19 21:57:54 2009 From: charlie137 at gmail.com (charlie137 at gmail.com) Date: Mon, 19 Jan 2009 18:57:54 -0800 (PST) Subject: tasklet library based on PEP 0342 References: Message-ID: <836b31a3-f70a-4739-a8e0-3dc948138d57@w1g2000prm.googlegroups.com> On Jan 20, 6:37?am, Terry Reedy wrote: > charlie137 at gmail.com wrote: > > Using new features of python generators, as described in PEP 0342, it > > is possible to write some sort of "tasklets" in a maner very similar > > to stackless python, but running on cpython. For example : > > > @tasklet > > def my_task(): > > ? ? yield Timer(10) > > ? ? yield "result" > > > @tasklet > > def other_task(): > > ? ? result = yield my_task() > > > other_task().start(callback=on_return) > > > I wrote an implementation of this in the scope of an open source > > project for openmoko [0], there is also an other very similar > > implementation from the kiwi project [1]. > > > This kind of tool is very useful, but unfortunately there is no > > standard library that would provide a unified way to use it > > independently of the underlying event loop. > > > Does someone know if a similar library could eventually be added into > > python standard libraries ? Would it be accepted as a PEP ? > > Start by listing your module/library onhttp://pypi.python.org/pypi > To ever get in the stdlib, it must be tested, used by several different > people, the best of its type, and relative stable. I am afraid my implementation passes none of those requirement. I will send a message to the python idea mailing list though. Thanks for the answers. Guillaume From Russ.Paielli at gmail.com Mon Jan 19 22:09:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 19:09:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 6:24?pm, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 18:07:50 -0800, Russ P. wrote: > > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > >> Russ, I think _you_ are missing the point. If the attribute is already > >> public, why does it need properties? Why would a programmer go to the > >> trouble of adding them manually, just to get one level of indirection > >> for an already public attribute? > > > You don't understand the purpose of properties -- and you tell me that > > *I* am the one missing the point? > > Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > Russ is proposing. But I must admit it's not clear to me why Russ thinks > it is a good idea to automatically turn this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self.x = 1 > > into this: > > class Parrot(object): > ? ? def __init__(self): > ? ? ? ? self._x = 1 > ? ? def getx(self): > ? ? ? ? return self._x > ? ? def setx(self, value): > ? ? ? ? self._x = value > ? ? x = property(getx, setx) > > Because frankly, that's how I read Russ' explanation for what Scala is > doing. Have I missed something? > > -- > Steven Whoops, I accidentally hit send on the last post. One of the main benefits of properties is that they allow you to more safely put attributes in the public interface. If you later decide that the attribute shouldn't have been in the public interface, you can convert it to a property and make it do whatever you want it to do. That won't always save you, but sometimes it can. As a trivial example, suppose you have a circle class with public attributes of radius and area. You later realize that it is unwise to let the user change one without changing the other, leaving them inconsistent. With properties, you can convert them each to a property and write functions to force consistency. The benefit of automatically converting public data into properties, I assume, is to relieve the programmer of doing it manually. The programmer will obviously need to add any functionality when needed, but he does not need to create the function header. I don't know the implications for efficiency in Scala. Perhaps there is a slight cost for one level of indirection. But please recall that public data is supposed to be rarely if ever used anyway. Unlike some folks here, the Scala folks understand the value of encapsulation and data hiding. From catphive at catphive.net Mon Jan 19 22:11:16 2009 From: catphive at catphive.net (Brendan Miller) Date: Mon, 19 Jan 2009 19:11:16 -0800 Subject: pep 8 constants In-Reply-To: References: Message-ID: > Constants would be a nice addition in python, sure enough. My original question was about PEP-8 and whether it is pythonic to use all caps to denote a variable that shouldn't be changed. More of a style question than a language question. I actually think *enforcing* constantness seems to go against the grain of the language so to speek From Russ.Paielli at gmail.com Mon Jan 19 22:20:48 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 19:20:48 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> On Jan 19, 6:24?pm, "James Mills" wrote: > Python programmers tend to not have a need for > properties. Quite honestly they are a waste of time. > They come from traditional OO approaches to software design > (and mostly from the Java world). With statements like that, it's no wonder you don't understand the value of encapsulation. With encapsulation (whether enforced or voluntary), no one has the "need" for properties. You can always just provide functions to do the same job. What properties do is to essentially make the function call simpler for the client. The client just sets the radius of the circle, and, lo and behold, the area gets changed automatically and consistently. If you didn't plan ahead and encapsulate the radius from the start, properties allow you to save yourself and encapsulate it later without breaking the client's code. From joe at strout.net Mon Jan 19 22:22:55 2009 From: joe at strout.net (Joe Strout) Date: Mon, 19 Jan 2009 20:22:55 -0700 Subject: function to find the modification date of the project In-Reply-To: References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: <4975438F.2030807@strout.net> Terry Reedy wrote: >> Yes, and presumably if some power user did this, then that would be >> the intended effect. Not sure why they'd do that, but they must have >> a good reason -- who am I to stop them? > > What if a curious user simple looks at a file with an editor and saves > it without change? You can't do that, on the Mac at least... > Or changes it inconsequentially? Or makes copy to > x.py.orig, edits and plays with original, and when done renames > x.py.orig to x.py. Or any such thing (which I have done in > Pythonxy/Lib) without any intention of changing version date? Then the About box will show, quite correctly, that the app was mucked with at that date, and when they call me up and complain, and I ask them to read me the contents of the About box, I can know right away that they've probably broken something (no matter how inconsequential they believed their change to be), and tell them to re-download it. But really, this is NOT going to happen. These users wouldn't even know how to open the app bundle to find the Python files. Any comments on the functioning and platform-independence of the code? Thanks, - Joe From prologic at shortcircuit.net.au Mon Jan 19 22:33:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 13:33:26 +1000 Subject: function to find the modification date of the project In-Reply-To: <4975438F.2030807@strout.net> References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> <4975438F.2030807@strout.net> Message-ID: On Tue, Jan 20, 2009 at 1:22 PM, Joe Strout wrote: > Any comments on the functioning and platform-independence of the code? Make it simpler :) cheers James From xahlee at gmail.com Mon Jan 19 22:39:45 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 19 Jan 2009 19:39:45 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> Message-ID: <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> On Jan 19, 4:49 pm, "Rhodri James" wrote: > On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: > > On Jan 17, 10:25 am, Tino Wildenhain wrote: > >> > [[int(x) for x in line.split()] for line in open("blob.txt")] > > > Nice (python code). > > > Few comments: > > > ? the above code is borderline of atypical. e.g. it is not a average > > python code would produce or one'd seen in corporate python code. > > I can't imagine why not. consider code produced by corporations, as opposed to with respect to some academic or philsophical logical analysis. Looked in another way, consider if we can compile stat of all existing pyhton code used in real world, you'll find the above style is rarely used. in a logical analysis, each lang fanatics will actively sell certain style of construction, but that's just not the way code in the real world are. Ample examples can be found especially in other cultish lang groups such as lisp, perl, etc. (less of this phenomenon is found in lang like php, javascript, java, C, where the lang simple don't create fancy constructions in the name of improvement or esthetics or weird philosophy in the first place.) > > ? voodoo like the above makes me dislike python. To me, the one > > advantage of python is its clarity enforced by its syntax. > > Specifically, the forced indendation and quite simple semantics. > > However, the way i've seen Guido's propensities and how python 3 is > > moving to, it is becoming more mumbo jumbo of computer sciency OOP > > jargons with syntax soup. (with iterators, enumerators, list > > comprehension... shits forced upon the users) > > > The above line illustrate well the ad hoc syntax soup nature python is > > moving into. > > To a native English speaker, it illustrates entirely the reverse. > List comprehension is actually quite a linguistically natural way > to express the iterative construction of a list. computer lang is not human lang. In argument based on human lang, you have AppleScript, Perl, which are un-readable or cumbersome to most programers. Even with human lang, if you know linguistics to some extend, you know that natural lang is a complete wortheless mess in every aspect with respect to ?design? qualities. Xah ? http://xahlee.org/ ? From gdamjan at gmail.com Mon Jan 19 22:42:51 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 20 Jan 2009 04:42:51 +0100 Subject: ifconfig in python Message-ID: Something *like* this could work: myip = urllib2.urlopen('http://whatismyip.org/').read() of course then you are depending on an external service, not a very reliable one even. But then again, you might create an internal service like that yourself. This cgi-bin shell code like this for ex: #! /bin/sh echo "Content-type: text/plain" echo echo "${REMOTE_ADDR}" -- ?????? ( http://softver.org.mk/damjan/ ) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From david.lyon at preisshare.net Mon Jan 19 22:44:11 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Mon, 19 Jan 2009 22:44:11 -0500 Subject: Does Python really follow its philosophy of "Readability =?UTF-8?Q?counts=22=3F?= In-Reply-To: <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: <09d32dbdf3dadfcb857594807a0bdc94@preisshare.net> >> Because frankly, that's how I read Russ' explanation for what Scala is >> doing. Have I missed something? coz he gets paid per line of code.... it's a mindless way of getting paid more for the same functionality... >> Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea >> Russ is proposing. But I must admit it's not clear to me why Russ thinks >> it is a good idea to automatically turn this: >> >> class Parrot(object): >> ? ? def __init__(self): >> ? ? ? ? self.x = 1 >> >> into this: >> >> class Parrot(object): >> ? ? def __init__(self): >> ? ? ? ? self._x = 1 >> ? ? def getx(self): >> ? ? ? ? return self._x >> ? ? def setx(self, value): >> ? ? ? ? self._x = value >> ? ? x = property(getx, setx) >> From timr at probo.com Mon Jan 19 22:56:49 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 20 Jan 2009 03:56:49 GMT Subject: braces fixed '#{' and '#}' References: <6264e675-ddd4-446a-822a-cc82e8f87446@w1g2000prk.googlegroups.com> Message-ID: <2rian4t2il6n64jp35l3is1laosd0n19ro@4ax.com> "Brendan Miller" wrote: > >Yes, I also recently noticed the bug in python's parser that doesn't >let it handle squigly braces and the bug in the lexer that makes white >space significant. I'm surprised the dev's haven't noticed this yet. It's very dangerous to make a post like this without including the smiley. You're likely to get a mailbox full of "helpful" corrections... ;) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From catphive at catphive.net Mon Jan 19 23:00:15 2009 From: catphive at catphive.net (Brendan Miller) Date: Mon, 19 Jan 2009 20:00:15 -0800 Subject: what's the point of rpython? In-Reply-To: <7x8wp86plv.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: Maybe I'm missing something here but a lock free algorithm for reference counting seems pretty trivial. As long as you can atomically increment and decrement an integer without locking you are pretty much done. For a reference implementation of lock free reference counting on all common platforms check out boosts implementation of shared_ptr (a reference counting smart pointer designed around multithreaded use cases). >There are well known concurrent and parallel GC techniques that Hmm... I didn't really mention poor parallelism as a problem of GC. As I see it the two trade offs that have to be made for GC vs alternative techniques. The "embarrassing pause" during compaction which makes it impossible to use for applications like interactive video display that can't halt to compact a several gigabyte heap without causing stutter, and the loose memory profile. Maybe the document you sent me addresses those, and I'd be interested if it did. It's 150~ pages though so I haven't really had time to read it yet. As far as parallelism problems with GC go... the only ones I can imagine is that if you had a lot of threads going generating lots of garbage you would need to start to compact more frequently. Since compaction halts all threads, this could potentially cause very frequent compactions? Is that what you were getting at? I'd wondered about that before, but didn't know for a fact whether it came up in real world scenarios. From steven at REMOVE.THIS.cybersource.com.au Mon Jan 19 23:03:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 04:03:05 GMT Subject: pep 8 constants References: Message-ID: On Mon, 19 Jan 2009 19:11:16 -0800, Brendan Miller wrote: >> Constants would be a nice addition in python, sure enough. > > My original question was about PEP-8 and whether it is pythonic to use > all caps to denote a variable that shouldn't be changed. More of a style > question than a language question. > > I actually think *enforcing* constantness seems to go against the grain > of the language so to speek Why? Python has an infinite number of constants. The only difference is that they are immutable objects, not names. But regardless... yes, it is in my opinion Pythonic to use ALLCAPS to designate constants (by convention). It isn't in PEP 8, but I don't think that matters unless PEP 8 suggests a different convention. -- Steven From Russ.Paielli at gmail.com Mon Jan 19 23:05:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:05:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: On Jan 19, 7:44?pm, wrote: > >> Because frankly, that's how I read Russ' explanation for what Scala is > >> doing. Have I missed something? > > coz he gets paid per line of code.... > > it's a mindless way of getting paid more for the same functionality... > > >> Well, I *thought* I did, and (unlike Bruno) I'm not hostile to the idea > >> Russ is proposing. But I must admit it's not clear to me why Russ thinks > >> it is a good idea to automatically turn this: > > >> class Parrot(object): > >> ? ? def __init__(self): > >> ? ? ? ? self.x = 1 > > >> into this: > > >> class Parrot(object): > >> ? ? def __init__(self): > >> ? ? ? ? self._x = 1 > >> ? ? def getx(self): > >> ? ? ? ? return self._x > >> ? ? def setx(self, value): > >> ? ? ? ? self._x = value > >> ? ? x = property(getx, setx) > > Why did you email your post to me? Did you really think I wanted to see it in my inbox? I assure you I did not. And who "gets paid per line of code"? The whole point is that Scala saves the programmer the trouble of writing that boilerplate code that Java programmers write themselves, genius. From kyrie at uh.cu Mon Jan 19 23:13:18 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:13:18 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232424798.49754f5e43123@mail.uh.cu> Quoting "Russ P." : > One of the main benefits of properties is that they allow you to more > safely put attributes in the public interface. If you later decide > that the attribute shouldn't have been in the public interface, you > can convert it to a property and make it do whatever you want it to > do. That won't always save you, but sometimes it can. That's true in Java, and python pre-'descriptor protocol'. It boggles me when I see python code with properties that only set and get the attribute, or even worse, getters and setters for that purpose. In my university they teach the students to write properties for the attributes in C# ("never make a public attribute, always write a public property that just gets and sets it"). I never understood that practice either, given that the syntax for attribute access and property access in C# is exactly the same. (Could it be that even if the syntax is the same, the compiled code differs? Don't know enough about .NET to answer that). I think I'm getting offtopic now. I better leave :D [snip the rest of the email, as I agree with it] -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From Russ.Paielli at gmail.com Mon Jan 19 23:16:07 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:16:07 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: On Jan 19, 7:09?pm, "Russ P." wrote: > The benefit of automatically converting public data into properties, I > assume, is to relieve the programmer of doing it manually. The > programmer will obviously need to add any functionality when needed, > but he does not need to create the function header. Let me just correct this. As I said before, I haven't yet even used Scala. The automatic generation of properties for public data members is done automatically by the compiler and is apparently transparent to the programmer. The programmer can then override the default properties if he needs to add functionality. As far as the programmer is concerned, this is really no different than Python properties. The only difference is the way the two languages implement properties, not the way they are used. From kyrie at uh.cu Mon Jan 19 23:17:59 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:17:59 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> Message-ID: <1232425079.497550775c63e@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 6:24?pm, "James Mills" > wrote: > > > Python programmers tend to not have a need for > > properties. Quite honestly they are a waste of time. > > They come from traditional OO approaches to software design > > (and mostly from the Java world). > > With statements like that, it's no wonder you don't understand the > value of encapsulation. > [snip] > > If you didn't plan ahead and encapsulate the radius from the start, > properties allow you to save yourself and encapsulate it later without > breaking the client's code. Python programmers don't _need_ to plan ahead and encapsulate the radius from the start. That's the whole point. No clairvoyance needed. I kind of like that. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From http Mon Jan 19 23:19:26 2009 From: http (Paul Rubin) Date: 19 Jan 2009 20:19:26 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <7x3afewqwh.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. What cpu's do you know of that can atomically increment and decrement integers without locking? From sjmachin at lexicon.net Mon Jan 19 23:23:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 19 Jan 2009 20:23:38 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> Message-ID: <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> On Jan 20, 12:54?pm, gert wrote: > How do you convert s back to binary data in python 3 so I can put in a > sqlite blob ? > Is there a build in function or do I need to use binascii ? > byte(s) or bin(s) would make more sense but can not figure it out ? Can't imagine why you would do str(binary_data) especially if you want it back again ... however: According to the fabulous manual: str([object[, encoding[, errors]]]) Return a string version of an object, using one of the following modes: [snip] When only object is given, this returns its nicely printable representation. For strings, this is the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. Hmm looks like (1) we need to do the dreaded eval() and (2) there's no guarantee it will work. >>> for i in range(256): ... blob = bytes([i]) ... if eval(str(blob)) != blob: ... print(i, blob, str(blob), eval(str(blob))) ... >>> # no complaints! Looks like it's going to work, but you better be rather sure that you trust the source. HTH, John From kyrie at uh.cu Mon Jan 19 23:27:37 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:27:37 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1232425079.497550775c63e@mail.uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> <1232425079.497550775c63e@mail.uh.cu> Message-ID: <1232425657.497552b99d176@mail.uh.cu> Quoting Luis Zarrabeitia : > > Quoting "Russ P." : > > > On Jan 19, 6:24?pm, "James Mills" > > wrote: > > > > > Python programmers tend to not have a need for > > > properties. Quite honestly they are a waste of time. > > > They come from traditional OO approaches to software design > > > (and mostly from the Java world). > > > > With statements like that, it's no wonder you don't understand the > > value of encapsulation. > > > [snip] > > > > If you didn't plan ahead and encapsulate the radius from the start, > > properties allow you to save yourself and encapsulate it later without > > breaking the client's code. > > Python programmers don't _need_ to plan ahead and encapsulate the radius > from > the start. That's the whole point. No clairvoyance needed. I kind of like > that. Oops. I didn't noticed we were agreeing on this last point. Bad english... bad... [btw, I highly doubt James doesn't understand the value of encapsulation. Don't you mean "enforced data hiding" again?] Cya! -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From pavlovevidence at gmail.com Mon Jan 19 23:27:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 19 Jan 2009 20:27:51 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> On Jan 19, 8:00?pm, "Brendan Miller" wrote: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. You're missing that most of the platforms that Python supports can't actually do this. Keep in mind that it has to be atomic across all cores. (For Python to use such a technique, it would have to be doable on every platform Python supports. They aren't going to get rid of the GIL for some platforms and not others.) > For a reference implementation of lock free reference counting on all > common platforms check out boosts implementation of shared_ptr (a > reference counting smart pointer designed around multithreaded use > cases). I just looked at the boost documentation, which claims that multiple asynchronous writes to the same shared_ptr results in undefined behavior. That will not suffice for Python reference counting. Carl Banks From Russ.Paielli at gmail.com Mon Jan 19 23:28:15 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 20:28:15 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> Message-ID: <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> On Jan 19, 8:17?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > > > > > On Jan 19, 6:24?pm, "James Mills" > > wrote: > > > > Python programmers tend to not have a need for > > > properties. Quite honestly they are a waste of time. > > > They come from traditional OO approaches to software design > > > (and mostly from the Java world). > > > With statements like that, it's no wonder you don't understand the > > value of encapsulation. > > [snip] > > > If you didn't plan ahead and encapsulate the radius from the start, > > properties allow you to save yourself and encapsulate it later without > > breaking the client's code. > > Python programmers don't _need_ to plan ahead and encapsulate the radius from > the start. That's the whole point. No clairvoyance needed. I kind of like that. And I like it too. I was trying to explain that to Mr. Mills, who claimed that properties are "a waste of time." Properties reduce the need for encapsulation, but they do not eliminate it, particularly for large projects. In the circle example, properties are nice for guaranteeing consistency between the radius and the area, but they are not of much use if you decide later that the client should not be allowed to change either one. Well... I suppose you could define the setter to do nothing ... but you had better figure a way to notify the client about it. From http Mon Jan 19 23:31:36 2009 From: http (Paul Rubin) Date: 19 Jan 2009 20:31:36 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <7xbpu238ev.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > As long as you can atomically increment and decrement an integer > without locking you are pretty much done. Most cpu's can't do that. > For a reference implementation of lock free reference counting on all > common platforms check out boosts implementation of shared_ptr (a > reference counting smart pointer designed around multithreaded use > cases). That sounds very mysterious to me--are you sure it is intended for multiprocessing and not just multiple threads on a single processor? Do you have a url for the code? > I see it the two trade offs that have to be made for GC vs alternative > techniques. The "embarrassing pause" during compaction which makes it > impossible to use for applications like interactive video display that > can't halt to compact a several gigabyte heap without causing stutter, > and the loose memory profile. The embarassing pause is characteristic of a so-called "stop the world" gc. A gc where any pauses are guaranteed bounded in size (preferably to a small value) is called a "real time" gc. I believe Cheng's algorithm is a real time alg but it's been a while since I read that thesis. Anyway, nobody programs interactive video in Python, and Python's ref counting scheme is not real time since it may have to do arbitrarily many decrefs when you release a large structure. > As far as parallelism problems with GC go... the only ones I can > imagine is that if you had a lot of threads going generating lots of > garbage you would need to start to compact more frequently. Since > compaction halts all threads, this could potentially cause very > frequent compactions? Is that what you were getting at? I'm not sure what you're asking. Parallelism is used for making things go faster, but making things parallel usually complicates them. A parallel realtime gc is sort of the holy grail. Cheng's thesis is pretty readable as I remember, and discusses most of these issues. There is also a book by Appel about gc, but it's perhaps a little bit dated by now. From kyrie at uh.cu Mon Jan 19 23:32:47 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:32:47 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: <1232425967.497553efe235d@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 7:44?pm, wrote: > > [removing david's message] > > > Why did you email your post to me? Did you really think I wanted to > see it in my inbox? I assure you I did not. Don't get mad at him... and don't take it personal. The reply-to header of this mailing list (usenet users: for some of us, this is only a mailing list, and can't hope for more) points to the sender, and not the list. Many believe it is the right thing to do, but if your mailer doesn't have a 'reply to list' function, like the one I'm using right now (Horde/Imp), your only option is to reply-to-all and then delete the original sender. I can't blame anyone for forgetting about the last part. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Mon Jan 19 23:39:16 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:39:16 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <1232426356.49755574d7d65@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 5:09?pm, Luis Zarrabeitia wrote: > > > Russ, I think _you_ are missing the point. > > If the attribute is already public, why does it need properties? Why would > a > > programmer go to the trouble of adding them manually, just to get one level > of > > indirection for an already public attribute? > > You don't understand the purpose of properties -- and you tell me that > *I* am the one missing the point? This line would make a lot more sense if you were talking about Java's getters and setters, or about a language where accessing a property is different than accessing an attribute (which would make little sense). If properties already let you change from attribute to method without affecting the caller, why do you need a property that does nothing? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Mon Jan 19 23:57:46 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 19 Jan 2009 23:57:46 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <9393e392-5758-45b4-8ea1-415dce65b98a@z27g2000prd.googlegroups.com> <6fc3820e-8314-4058-bb49-78a1a059a7ba@g39g2000pri.googlegroups.com> Message-ID: <1232427466.497559cabf8f3@mail.uh.cu> Quoting "Russ P." : > In the circle example, properties are nice for guaranteeing > consistency between the radius and the area, but they are not of much > use if you decide later that the client should not be allowed to > change either one. Well... I suppose you could define the setter to do > nothing ... but you had better figure a way to notify the client about > it. Well, you could make it raise an exception. There was one C#1.0 class that did this, Liskov substitution principle be damned (it was for a subtype). Very frustrating. Once you decide for a public interface, you shouldn't change it... But, if you absolutely have to do it, complain loudly and as soon as possible. In python, I'd say that [a subclass of?] AttributeError would be the best solution for this ill-advised situation. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From bignose+hates-spam at benfinney.id.au Mon Jan 19 23:58:30 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 20 Jan 2009 15:58:30 +1100 Subject: pep 8 constants References: Message-ID: <87fxje4lqh.fsf@benfinney.id.au> Steven D'Aprano writes: > But regardless... yes, it is in my opinion Pythonic to use ALLCAPS > to designate constants (by convention). I agree, in general. Though I think I can count the number of times I've wanted to use an ?UPPER_CASE?-named constant in my code, on the fingers of one foot. > It isn't in PEP 8, but I don't think that matters unless PEP 8 > suggests a different convention. It does recommend a contradictory convention: Global Variable Names (Let's hope that these variables are meant for use inside one module only.) The conventions are about the same as those for functions. The conventions for functions are the familiar ?lower_case? conventions. This directly contradicts using ?UPPER_CASE? names. Unless someone's going to argue that ?Variable Names? doesn't apply to constant names, even though Python doesn't make the distinction. That said, I think upper-case name is a useful convention to distinguish ?this name binding is never expected to change? from the common case, and wouldn't argue against its use. Perhaps I'd even argue for an update to PEP 8 that endorses this as conventional. -- \ ?I was born by Caesarian section. But not so you'd notice. It's | `\ just that when I leave a house, I go out through the window.? | _o__) ?Steven Wright | Ben Finney From prologic at shortcircuit.net.au Tue Jan 20 00:04:34 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 20 Jan 2009 15:04:34 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1232426356.49755574d7d65@mail.uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <1232426356.49755574d7d65@mail.uh.cu> Message-ID: On Tue, Jan 20, 2009 at 2:39 PM, Luis Zarrabeitia wrote: > This line would make a lot more sense if you were talking about Java's getters > and setters, or about a language where accessing a property is different than > accessing an attribute (which would make little sense). If properties already > let you change from attribute to method without affecting the caller, why do you > need a property that does nothing? My point exactly. Russ seems to agree with Python but yet argue points for the sake of it. I'm not sure why :) Having come from all kinda of programming backgrounds and paradigms you learn to see the value in Python and the kind of simplicity it has to offer. I will stand by my view that there are many features of the traditional, strict and academic features of the OO model that have little practical value. Python is a great mix of functional features, OO features and has borrowed (what I believe) are the best of breed features from all around. One thing I find quite amazing is that we're having a discussion over such low-level features of the OO model (and functional paradigm) and how Python fits into it all ... And for what exactly ? Russ - what is your point in all of this - You keep saying you don't have time to waste with this - yet you keep making this thread grow longer and longer and longer :) As far as I'm concerned properties are just fancy functions to retrieve and set attributes of an object. Consider the following equivalent pieces of code: #!/usr/bin/env python from math import pi class CircleA(object): def __init__(self, radius): self._radius = radius self._area = pi * radius ** 2 def __getRadius(self): return self._radius def __setRadius(self, radius): self._radius = radius self._area = pi * radius ** 2 def __getArea(self): return self._area def __repr__(self): return "" % (self.radius, self.area) radius = property(__getRadius, __setRadius) area = property(__getArea) class CircleB(object): def __init__(self, radius): self.radius = radius self.area = pi * radius ** 2 def setRadius(self, radius): self.radius = radius self.area = pi * radius ** 2 def __repr__(self): return "" % (self.radius, self.area) a = CircleA(1.5) print a a.radius = 2.0 print a b = CircleB(1.5) print b b.radius = 2.0 print b ---------- http://codepad.org/tpyGNhrZ I'll give you a hint which one I prefer :) cheers James From http Tue Jan 20 00:04:52 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:04:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhmsh3f.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > Luis Zarrabeitia writes: > > > You *can* implement a metaclass that will remove the dynasmism from its > > > instances.... > import inspect > class ImmutableType(type): ... Thanks for posting this, I haven't replied because I bookmarked the post for later study, but that was several days ago, so I just wanted to say that I'm still looking at it. It's an area of Python that I've somewhat purposely stayed away from. > But I see no _necessary_ harm on tacking extra attributes to an > existing object - specially if you are going to use them pretty > close to the creation. > I use them, a lot, specially when writing decorators... Many times I > just want to 'mark' the decorated functions so I can inspect those > marks later. I'd rather have a semi-private namespace for each pair > ([group of]calling function[s], object), Right, thus the usefulness of a static tool that can find all those places where extra attributes are created. Basically I can see three approaches to this question: 1) Program in a style where you create and modify attributes all over the place willy-nilly, with no controls whatsoever, either automatic or stylistic. From experience (it is a common style in Javascript) I can say this is a big mess and I think no experienced Python programmers recommend it. 2) Have mandatory encapsulation like Java's, no way to escape. Bruno and yourself vehemently object to this, Russ P seems to want it, my view is that it's not in the Python spirit, so I can accept the argument that those who really want this are better off choosing another language. 3) Program in a style where creating new attributes outside the initializer is normally avoided by convention, but it is possible and sometimes desirable to break the convention. This seems reasonable and Pythonic to me. But, any place I break the convention, I should be able to say "I broke the convention here for such and such a reason". And (this seems to be a bone of contention) IMO, it would be good to be able to audit a large codebase with a tool like Pylint, to automatically find all the places where such breakages occur. Right now there seems to be no way to do that reliably, short of using something like your special metaclass instead of the standard one for just about everything. Your example about decorators (used on classes that don't expect to be wrapped by them) is a good one but narrow enough that there could be a special arrangement for it in a hypothetical auditing tool. From Russ.Paielli at gmail.com Tue Jan 20 00:12:08 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 21:12:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <2e6c6820-0529-4e72-855b-3dd522d9cd4f@r41g2000prr.googlegroups.com> On Jan 19, 8:39?pm, Luis Zarrabeitia wrote: > If properties already > let you change from attribute to method without affecting the caller, why do you > need a property that does nothing? You don't. As I tried to explain in a earlier post (but one that you may not have seen yet), that is apparently an implementation detail of the way Scala implements properties. I probably should have never even brought it up. From Russ.Paielli at gmail.com Tue Jan 20 00:17:19 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 21:17:19 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <85ccc7a6-8070-4431-b490-82342ed7d679@d36g2000prf.googlegroups.com> Message-ID: On Jan 19, 8:32?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > On Jan 19, 7:44?pm, wrote: > > > [removing david's message] > > > Why did you email your post to me? Did you really think I wanted to > > see it in my inbox? I assure you I did not. > > Don't get mad at him... and don't take it personal. The reply-to header of this > mailing list (usenet users: for some of us, this is only a mailing list, and > can't hope for more) points to the sender, and not the list. Many believe it is > the right thing to do, but if your mailer doesn't have a 'reply to list' > function, like the one I'm using right now (Horde/Imp), your only option is to > reply-to-all and then delete the original sender. I can't blame anyone for > forgetting about the last part. You're right. I shouldn't have gotten mad at him. I took his post as a jab at me, but after thinking about it I realized it probably wasn't. My apologies. From http Tue Jan 20 00:21:51 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:21:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> Message-ID: <7xiqoatuvk.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > The failure was because a module tested, QA'd and certified within a > given context (in which it was ok to drop the builtin error handling) > was reused in a context where it was not ok. And the point is exactly > that : no *technology* can solve this kind of problem, because it is a > *human* problem (in that case, not taking time to repass the whole > specs / tests / QA process given context change). In this case it does nothing at all to support your arguments about the helpfulness or lack of helpfulness of strong encapsulation. You may as well say that antibiotics are medically useless because they won't stop anyone from getting killed by a falling piano. From banibrata.dutta at gmail.com Tue Jan 20 00:44:55 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 20 Jan 2009 11:14:55 +0530 Subject: *Advanced* Python book? In-Reply-To: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> References: <8c7f10c60901181535k4db645dax5fdc43058dd50b8c@mail.gmail.com> Message-ID: <3de8e1f70901192144q5b466c32sfd6f914d7daa8840@mail.gmail.com> 2009/1/17 Michele Simionato : > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 Excellent review. -- regards, Banibrata http://www.linkedin.com/in/bdutta From http Tue Jan 20 00:57:29 2009 From: http (Paul Rubin) Date: 19 Jan 2009 21:57:29 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> Message-ID: <7xfxjett86.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Take some not-that-trivial projects like Zope/Plone. There are quite a > few lines of code involved, and quite a lot of programmers worked on it. Zope is about 375 KLOC[1], which I agree is not trivial, but by today's standards, it's not all that large. Zope also has 275 open bugs, 6 of which are critical.[2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC in which only 3 errors have been found post-release.[3] I think "large software system" today means 100's of MLOC. FWIW, Zope has 20x as much code as Django--is that a good thing!? [1] http://www.peterbe.com/plog/size-Zope3,Django,TurboGears [2] https://bugs.launchpad.net/zope3 [3] http://haacked.com/archive/2006/10/20/The_Misuse_of_the_Space_Shuttle_Analogy.aspx#11147 From Russ.Paielli at gmail.com Tue Jan 20 01:00:47 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 22:00:47 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> Message-ID: <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> On Jan 19, 9:21?pm, Paul Rubin wrote: > Bruno Desthuilliers writes: > > The failure was because a module tested, QA'd and certified within a > > given context (in which it was ok to drop the builtin error handling) > > was reused in a context where it was not ok. And the point is exactly > > that : no *technology* can solve this kind of problem, because it is a > > *human* problem (in that case, not taking time to repass the whole > > specs / tests / QA process given context change). > > In this case it does nothing at all to support your arguments about > the helpfulness or lack of helpfulness of strong encapsulation. ?You > may as well say that antibiotics are medically useless because they > won't stop anyone from getting killed by a falling piano. He says that "no *technology* can solve this kind of problem." First of all, I'm not sure that's true. I think technology *could* have solved the problem -- e.g., Spark Ada, had it been properly applied. But that's beside the point. The point is that the problem had nothing to do with encapsulation. The rocket failed because a conversion was attempted to a data type that could not hold the required value. Am I missing something? I don't see what that has to do with encapsulation. The logic seems to be as follows: 1. Ada enforces data hiding. 2. Ada was used. 2. A major failure occurred. Therefore: Enforced data hiding is useless. If that reasoning is sound, think about what else is useless. From kyrie at uh.cu Tue Jan 20 01:10:09 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 01:10:09 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmsh3f.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xab9t7s5h.fsf@ruckus.brouhaha.com> <7xzlhmsh3f.fsf@ruckus.brouhaha.com> Message-ID: <1232431809.49756ac1bbffa@mail.uh.cu> Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Luis Zarrabeitia writes: > > > Luis Zarrabeitia writes: > > class ImmutableType(type): ... > > Thanks for posting this, I haven't replied because I bookmarked the > post for later study, but that was several days ago, so I just wanted > to say that I'm still looking at it. It's an area of Python that I've > somewhat purposely stayed away from. Hehe. Keep away - once you get dive into it, it'll be hard go get out. It's really addictive :D > > I use them, a lot, specially when writing decorators... Many times I > > just want to 'mark' the decorated functions so I can inspect those > > marks later. I'd rather have a semi-private namespace for each pair > > ([group of]calling function[s], object), > > Right, thus the usefulness of a static tool that can find all those > places where extra attributes are created. Basically I can see three > approaches to this question: Btw, this thread inspired me to do another proof-of-concept stuff that I may be using more seriously. Too bad I don't have anywhere to upload it right now... Anyway, it looks like this: suppose I need to attach some attributes to the object "x", but I don't want to do x.attr import namespaces # my module class my_private_namespace(namespaces.Namespace): pass def this_function_stores_the_attr(x): ns = my_private_namespace(x) ns.attr = 5 # I'm creating an attribute on the fly # but at least I'm not touching x. def this_function_reads_the_attr(x): ns = my_private_namespace(x) print ns.attr > 1) Program in a style where you create and modify attributes all over > the place willy-nilly, with no controls whatsoever, either automatic > or stylistic. From experience (it is a common style in Javascript) I > can say this is a big mess and I think no experienced Python > programmers recommend it. Indeed. Though I don't consider myself 'experienced', I certainly don't recommend it. > 2) Have mandatory encapsulation like Java's, no way to escape. Bruno > and yourself vehemently object to this, Russ P seems to want it, my > view is that it's not in the Python spirit, so I can accept the > argument that those who really want this are better off choosing > another language. Btw, I noticed a funny side effect of my 'namespaces' module (needs a LOT of work, this was the first time I touched weak references. I should find some place to upload the module): ===== import namespaces class public(namespaces.Namespace): pass class private(namespaces.Namespace): # the initializer could check if pass # its called from outside the class. Performance penalty. class A(object): """dummy class A, with one 'private' attribute x, and one normal 'attribute' x.""" def __init__(self): self.x = id(self) # normal attr pub = public(self) pub.f = self.f priv = private(self) priv.x = "this is the private" def f(self): print "normal x: ", self.x priv = private(self) print "private x: ", priv.x >>> a = A() >>> dir(a) ['__class__', , 'f', 'x'] >> a.f() normal x: 147956684 private x: this is the private >>> p = public(a) >>> dir(p) # Look, there is no 'x' attribute! ['__class__', , 'f'] >>> p.f() # but f still works! normal x: 147956684 private x: this is the private ====== Of course, without checks in 'private', one could say priv = private(a); priv.x, but the most interesting part, for me at least, was the ability to define a 'public' interface for a, that contains no attribute directly referencing the object 'a' with its internals - only the names explicitly declared on the 'interface'. Indirectly... well, p.f.im_self will return back the 'a' object. Bah, I'm ranting now. I just got carried away with my little experiment. Sorry. Ah, and yes, metaclasses are dangerously addictive :D > 3) Program in a style where creating new attributes outside the > initializer is normally avoided by convention, but it is possible and > sometimes desirable to break the convention. This seems reasonable > and Pythonic to me. But, any place I break the convention, I should > be able to say "I broke the convention here for such and such a > reason". And (this seems to be a bone of contention) IMO, it would be > good to be able to audit a large codebase with a tool like Pylint, to > automatically find all the places where such breakages occur. Right > now there seems to be no way to do that reliably, short of using > something like your special metaclass instead of the standard one for > just about everything. Well, I agree. Each and every one of those convention-breakages should be well documented, and pylint should be able to pick them up. Pylint does that already (see example below), I don't know if it lets you "document" it explicitly. I think Eclipse catches some of that stuff. My metaclass... shouldn't be used for anything serious :D. === breaklint.py === (no, it didn't break pylint) class A(object): def __init__(self): self.a = 5 def f(self): self.b = 7 # creating outside the init def g(self): print self.b # only if f runs first print self.c # and this one doesn't exist a = A() a.c = 8 a.f() a.g() a.d = "new var" # outside the class definition ================== $ pylint breaklint.py [...] W: 13: Attribute 'c' defined outside __init__ W: 7:A.f: Attribute 'b' defined outside __init__ W: 16: Attribute 'd' defined outside __init__ [...] Your code has been rated at -1.54/10 ===== > Your example about decorators (used on classes that don't expect to be > wrapped by them) is a good one but narrow enough that there could be a > special arrangement for it in a hypothetical auditing tool. Indeed. I'll take a look at pylint's config file. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From alan.isaac at gmail.com Tue Jan 20 01:30:22 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 06:30:22 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: <2cedl.865$aI1.290@nwrddc01.gnilink.net> On 1/19/2009 3:03 PM John Machin apparently wrote: > It is not deprecated YET; see this: > > http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6 > > PEP 3101: Advanced String Formatting. Note: the 2.6 description > mentions the format() method for both 8-bit and Unicode strings. In > 3.0, only the str type (text strings with Unicode support) supports > this method; the bytes type does not. The plan is to eventually make > this the only API for string formatting, and to start deprecating the > % operator in Python 3.1. Thanks! Alan Isaac From kyrie at uh.cu Tue Jan 20 01:33:00 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 01:33:00 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> Message-ID: <1232433180.4975701cc1791@mail.uh.cu> Quoting "Russ P." : > On Jan 19, 9:21?pm, Paul Rubin wrote: > > Bruno Desthuilliers writes: > > > The failure was because a module tested, QA'd and certified within a > > > given context (in which it was ok to drop the builtin error handling) > > > was reused in a context where it was not ok. And the point is exactly > > > that : no *technology* can solve this kind of problem, because it is a > > > *human* problem (in that case, not taking time to repass the whole > > > specs / tests / QA process given context change). > > > > He says that "no *technology* can solve this kind of problem." > > First of all, I'm not sure that's true. I think technology *could* > have solved the problem -- e.g., Spark Ada, had it been properly > applied. But that's beside the point. The point is that the problem > had nothing to do with encapsulation. The rocket failed because a > conversion was attempted to a data type that could not hold the > required value. Am I missing something? I don't see what that has to > do with encapsulation. > > The logic seems to be as follows: > > 1. Ada enforces data hiding. > 2. Ada was used. > 2. A major failure occurred. > > Therefore: > > Enforced data hiding is useless. I don't think that was the logic... At least, it wasn't what I understood from the example. We were talking at the time (or rather, you both were, as I think I was still away from the thread) about QA versus static checks (as a superset of 'enforcement of data hiding'). Is not that those checks are useless, is that they make you believe you are safe. Granted, you may be safe-er, but it may be better to know beforehand "this is unsafe, I will check every assumption". The arianne 5 example cuts both ways: messing with "internals" (not that internal in this case, but still) without fully understanding the implications, and overly trusting the checks put in place by the language. I don't know spark-ada, but the only thing I can think of that would have prevented it is not purely technological. It would have been a better documentation, where that particular assumption was written down. A language can help you with it, perhaps spark-ada or eiffel or who-knows-what could've forced the original developers to write that piece of documentation and make the arianne 5 engineers notice it. So, Arianne 5's problem had nothing to do with _enforced data hiding_. (Why do you keep calling it 'encapsulation'?). It was a counterexample for your trust on compiler checks. Btw, what do you have against using pylint for detecting those 'access violations'? > If that reasoning is sound, think about what else is useless. I _hope_ that wasn't Bruno's reasoning. I don't want to switch sides on this discussion :D. Cheers, -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From aleksandr.goretoy at gmail.com Tue Jan 20 01:35:56 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 20 Jan 2009 06:35:56 +0000 Subject: ifconfig in python In-Reply-To: References: Message-ID: ifconfig -a|grep "inet addr"|awk '{print $2}' wget http://myip.dk&& cat index.html|grep "
wrote: > Something *like* this could work: > > myip = urllib2.urlopen('http://whatismyip.org/').read( > ) > > of course then you are depending on an external service, not a very > reliable one even. But then again, you might create an internal service > like that yourself. > > This cgi-bin shell code like this for ex: > > #! /bin/sh > echo "Content-type: text/plain" > echo > echo "${REMOTE_ADDR}" > > > -- > ?????? ( http://softver.org.mk/damjan/ ) > > Spammers scratch here with a diamond to find my address: > ||||||||||||||||||||||||||||||||||||||||||||||| > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan.isaac at gmail.com Tue Jan 20 01:40:25 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 06:40:25 GMT Subject: string formatting documentation In-Reply-To: References: <8Rncl.212$Aw2.127@nwrddc02.gnilink.net> <01848c43$0$20652$c3e8da3@news.astraweb.com> Message-ID: On 1/19/2009 5:03 PM Terry Reedy apparently wrote: > I have not seen 3.0 emit a % deprecation warning. Point taken. But the vocabulary of PEP 4 suggests that "obsolete" and "deprecated" are synonyms, and PEP 4 lists obsolete modules without deprecation warnings. Alan Isaac From kay.schluehr at gmx.net Tue Jan 20 01:55:33 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Mon, 19 Jan 2009 22:55:33 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <954b52df-f332-49ea-8ef5-b8e48ff09a9a@a39g2000prl.googlegroups.com> On 17 Jan., 01:37, "Brendan Miller" wrote: > Is this going anywhere or is this just architecture astronautics? > > The RPython project seems kind of interseting to me and I'd like to > see more python implementations, but looking at the project I can't > help but think that they haven't really explained *why* they are doing > the things they are doing. Remember that the original objective of PyPy was to improve the JIT. Psyco is limited by the fact that the whole runtime is implemented in C. The infamous "faster than C" actually refers to work on program specializers on C code i.e. treating C as a language that is JIT compiled on a fine grained level ( block structure - whole function JIT compilation wouldn't obviously yield any advantages ). So it is not just the application level Python code that shall run through the JIT but also the interpreter level code. So why not equate them and think about interpreter level code as Python as well? This might be the idea. But then the problem of bootstrapping comes up: there is no interpreter level code with the required properties. Hence RPython that can serve as a foundation. I'm also not sure I like the approach. Rather than designing a whole new runtime for having a fully reflective system I'd model C in Python ( call it CiPy ) and create a bijection between CiPy code and C code. Once this has been established one can study other translations of CiPy or Python into CiPy ( not unlike Pyrex/Cython ) doing systematic refactorings on CiPy code in Python, study properties using runtime reflection, experiment with macro systems etc. All of this is done in PyPy as well but sometimes it seems the team has created more new problems than they solved. > Anyway, I can tell this is the sort of question that some people will > interpret as rude. Asking hard questions is never polite, but it is > always necessary :) I think it is a good question. From Russ.Paielli at gmail.com Tue Jan 20 02:00:43 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 19 Jan 2009 23:00:43 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <4973533a$0$23748$426a74cc@news.free.fr> <7xiqoatuvk.fsf@ruckus.brouhaha.com> <0a4d2b7f-173f-4e8d-bfe2-aff5f1918e9b@v18g2000pro.googlegroups.com> Message-ID: On Jan 19, 10:33?pm, Luis Zarrabeitia wrote: > So, Arianne 5's problem had nothing to do with _enforced data hiding_. (Why do > you keep calling it 'encapsulation'?). I keep calling it encapsulation because that is a widely accepted, albeit not universal, definition of encapsulation. Google "encapsulation" and see for yourself. For example, here is what the Wikipedia page on OOP says: Encapsulation conceals the functional details of a class from objects that send messages to it. Here is what another webpage says: Definition: In Object Oriented Programming, encapsulation is an attribute of object design. It means that all of the object's data is contained and hidden in the object and access to it restricted to members of that class. Because those definitions are not universally accepted, however, I usually say "enforced encapsulation" or "data hiding" to mean what "encapsulation" means to most OO programmers who use a language other than Python. From http Tue Jan 20 02:05:57 2009 From: http (Paul Rubin) Date: 19 Jan 2009 23:05:57 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: <7xtz7ufodm.fsf@ruckus.brouhaha.com> "Tim Rowe" writes: > Unless it's changed since I used it, technically, SPADE doesn't allow > or disallow anything. Right, it's an external tool, like pylint; you can still compile code that SPADE complains about. Sorry if I wan't more clear. I just meant SPADE would flag the code. > Since the value appears to come from a sensor, the only way one > could prove that there would be no overflow would be to state it as > a part of the specification of what is read in. If that > specification doesn't match the specification of the actual sensor, > that's nothing to do with the programming language or, for that > matter, the program itself. It's a specification mismatch. Right, that's the point, the assumption about the sensor reading being in a certain range would have to stated in the specification rather than implicit in the code; and as such, the problem would more likely to have been caught at the systems engineering level. > I was actually at the European Space Agency's Toulouse site the week > after the Ariane 5 incident. I've been at jollier funerals. I can't > help thinking that thinking that the team would have benefited from > reading David Parnas's work on the specification of the A-7E avionics. Later there was a static analysis of the Ariane code by Cousot et al, that flagged the error. I haven't yet looked up the paper to see exactly what it found. From wuwei23 at gmail.com Tue Jan 20 02:17:06 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 19 Jan 2009 23:17:06 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> On Jan 20, 1:39?pm, Xah Lee wrote: > consider code produced by corporations, as opposed to with respect to > some academic or philsophical logical analysis. Looked in another way, > consider if we can compile stat of all existing pyhton code used in > real world, you'll find the above style is rarely used. I've worked for several corporations that used Python and at -all- of them the developers were not only aware of list comprehensions, they used them regularly. Same with iterators. Not -one- of them found them to be "computer sciency OOP jargons" but useful metaphors that made their code more concise without sacrificing readability. Not everything new is crap, y'know. Neither is everything that you fail to understand the first time you're exposed to it. I find it kinda funny that you constantly criticise "academic" language development when it seems pretty clear from your posts that you've never actually engaged in any practical application-focused development in your life. But as they say: those that can do, those that can't post godawful screeds to their much-hyped-on-usenet vanity blogs... From http Tue Jan 20 02:20:52 2009 From: http (Paul Rubin) Date: 19 Jan 2009 23:20:52 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <0e5dfbbb-d532-4dfc-a0a9-a49a75419703@w1g2000prk.googlegroups.com> <4972467b$0$10274$426a74cc@news.free.fr> <7xeiz1zjzp.fsf@ruckus.brouhaha.com> <31c6eb50-86f3-4a56-8b3b-bf932bd98e0d@l33g2000pri.googlegroups.com> <7xmydomvim.fsf@ruckus.brouhaha.com> Message-ID: <7xvdsawii3.fsf@ruckus.brouhaha.com> "Tim Rowe" writes: > I was actually at the European Space Agency's Toulouse site the week > after the Ariane 5 incident. I've been at jollier funerals. I can't > help thinking that thinking that the team would have benefited from > reading David Parnas's work on the specification of the A-7E avionics. Thanks, these articles look interesting, though there is a lot to read: http://www.chacs.itd.nrl.navy.mil/publications/scr-a7e/index.html Was there something else you were referring to? From martinjamesevans at gmail.com Tue Jan 20 02:51:04 2009 From: martinjamesevans at gmail.com (martinjamesevans at gmail.com) Date: Mon, 19 Jan 2009 23:51:04 -0800 (PST) Subject: Regular expression that skips single line comments? References: <7788934d-2326-4933-8a0e-bc763f7b2547@v39g2000pro.googlegroups.com> Message-ID: <0bd2453e-90ea-495f-87ca-bcec9890cd84@r27g2000vbp.googlegroups.com> Firstly, a huge thanks to all for the solutions! Just what I was looking for. > (Aside: why are you doing a case-insensitive match for a non-letter? Are > there different upper- and lower-case dollar signs?) As you can probably imagine, I had simplified the problem slightly, the language uses a couple of different introducers and also uses both numbers and letters (but only single characters). I was going to go with a similar idea of parsing per line but was trying to give RE another chance. I've used RE often in the past but for some reason this one had got under my skin. I found this to be quite an interesting little tool: http://www.gskinner.com/RegExr/ Martin From steven at REMOVE.THIS.cybersource.com.au Tue Jan 20 03:13:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 08:13:54 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <1232426356.49755574d7d65@mail.uh.cu> Message-ID: On Tue, 20 Jan 2009 15:04:34 +1000, James Mills wrote: > Having come from all kinda of programming backgrounds and paradigms you > learn to see the value in Python and the kind of simplicity it has to > offer. Oh yes, it is liberating to say "I don't care if my method crashes (raises an exception), it's the caller's fault for messing with my class' internals, and he can deal with it". I'm not being sarcastic by the way. It really is liberating not to have to deal with unexpected input or broken pre-conditions. Just let the caller deal with it! -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jan 20 03:15:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 20 Jan 2009 08:15:05 GMT Subject: function to find the modification date of the project References: <4974F43E.4020402@strout.net> <49750AC4.9050709@strout.net> Message-ID: On Mon, 19 Jan 2009 20:22:55 -0700, Joe Strout wrote: >> What if a curious user simple looks at a file with an editor and saves >> it without change? > > You can't do that, on the Mac at least... Are you sure? That's a rather incredible claim. Surely you mean *some Mac editors* disable the Save command if the file hasn't been edited? Other editors may not, and POSIX command line tools certainly won't. But that's a minor point. > But really, this is NOT going to happen. These users wouldn't even > know how to open the app bundle to find the Python files. Ah, the sorts of users who say "I looked in the system folder, and there was nothing there, so I deleted it". I know them well :-) > Any comments on the functioning and platform-independence of the code? I've developed a taste for writing that sort of function as a series of iterators. That's much like the Unix philosophy of piping data from one program to another. I'm sure I don't need to justify the benefits of Unix- style tools, but if you don't like it, just combine the following two iterators into the lastModDate function that follows: import os def file_iter(dir='.', recurse=False): for root, dirs, files in os.walk(dir): if not recurse: del dirs[:] for file in files: yield os.path.join(root, file) def filetype_iter(extensions=None, dir='.', recurse=False): if not extensions: extensions = [''] for file in file_iter(dir, recurse): if os.path.splitext(file)[1] in extensions: yield file def lastModDate(dir=None, recurse=False): """Return the latest modification date of any Python source file.""" if dir is None: dir = os.path.dirname(__file__) if dir == '': dir = '.' # HACK, but appears necessary return max( (os.path.getmtime(name) for name in filetype_iter(['.py'], dir, recurse)) ) It will raise a ValueError if there are no .py files in the directory, but that's easily changed. Note also that I've changed lastModDate() to return the raw date stamp rather than a human readable string. The right place to covert to a human readable format is just before displaying it to a human being :) -- Steven From xahlee at gmail.com Tue Jan 20 03:42:07 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 00:42:07 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> Message-ID: On Jan 19, 11:17 pm, alex23 wrote: ... Hi Daniel Weinreb, Xah wrote: > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html Daniel Weinreb wrote: > Xah Lee: Elisp is an interesting choice. But without converting the > strings to integers, it's not really right. i did post a correction quickly that includes the conversion to string/ num. Here's the full code: (defun read-lines (file) "Return a list of lines in FILE." (with-temp-buffer (insert-file-contents file) (split-string (buffer-string) "\n" t) ) ) (mapcar (lambda (x) (mapcar (lambda (y) (string-to-number y) ) (split-string x " ") ) ) (read-lines "blob.txt") ) > It's interesting that Elisp already has a style of reading in the > whole file, but no built-in to convert strings to integers, whereas > Common Lisp is the other way around. > The statement "It is not so mostly because emacs people have drawn > themselves into a elitist corner, closing off to the outside world" is > just a rude ad hominem attack. sure. In a political context, many criticism or description of the situation from one party can be seen as ad hominem attack. I feel that that many old emacs users, which includes significant portion of emacs developers (if not majority), are so exteremly bottled up and turn down any possibility of advancing. They are killing emacs. (similar feelings for most regular posters here in comp.lang.lisp ) Now, that statement is imprecise, is attacking, needs a lot qualifications. I have literally written about 20 articles each a thousand words or more over the past 3 years that explains many specific cases in painful detail. (e.g. seehttp://xahlee.org/emacs/emacs_essays_index.html ) However, in a one sentence description in this thread's context, calling them ?elitist? and ?closing off to the outside world?, is to the point. > Your claim that this shows something wrong with lists is completely > unclear, although if I read your paper (I'll try) I might have some > idea what you're getting at More specifically, 2 fundamental problems of lisp i feel this ruby example illustrates well: ? the cons impedes many aspects of lists. e.g. difficult to learn, confusing, hard to use, prevent development of coherent list manipulation functions. ? nested syntax impedes the functional programing paradigm of function chaining, esp when each function has 2 or more arguments (e.g. map). here's a short summary of the nesting problem: (map f x) ; 1 level of chaining (map g (map f x)) ; 2 levels (map h (map g (map f x))) ; 3 levels compare: x | f | g | h ----> unix pipe x // f // g // h ----> Mathematica h @ g @ f @ x ----> Mathematica x.f.g.h -------> various OOP langs, esp Ruby, javascript h g f x -------> some functional langs, Haskell, Ocaml The way the above works is that each of f, g, h is a lambda themselves that maps. (that is, something like ?(lambda (y) (map f y))?) Note, that any of the f, g, h may be complex pure functions (aka lambda). Because in lisp, each lambda itself will in general have quite a lot nested parens (which cannot be avoided), so this makes any chaining of functions of 2 args, for more than 2 or 3 levels of nesting, unusable for practical coding. One must define the functions separately and just call their names, or use function composition with lambda (which gets complex quickly). One major aspect of this problem is that the scope of vars becomes hard to understand in the deep nested source code. This is worse in elisp, because emacs is dynamically scoped, so you have to avoid using var of same name. More detail here: the section ?The Cons Business? at ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html Your input will be highly valued. Though, forgive me to say, that i think my opinion on this is beyond any computer scientist of any standing can try to tell me otherwise. If they disagree (which i think most of them won't), i think their knowledge and experience in the area of computer languages and syntax and notations, IQ, are inferior to me. Xah ?http://xahlee.org/ ? From duncan.booth at invalid.invalid Tue Jan 20 04:30:07 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jan 2009 09:30:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: Luis Zarrabeitia wrote: > It boggles me when I see python code with properties that only set and > get the attribute, or even worse, getters and setters for that > purpose. In my university they teach the students to write properties > for the attributes in C# ("never make a public attribute, always write > a public property that just gets and sets it"). I never understood > that practice either, given that the syntax for attribute access and > property access in C# is exactly the same. (Could it be that even if > the syntax is the same, the compiled code differs? Don't know enough > about .NET to answer that). > The compiled code differs. That doesn't matter if the class is only accessed from within a single compiled program, but it does matter if you expose a public interface from a library: if you change a public attribute into a property then you need to recompile all code which accesses it. Actually that's no worse than making any other change to the published interface, and the source code doesn't need to change, you just need to recompile. Personally when writing C# I use properties when it seems like a good idea, but for small internal classes I just expose the attributes until I know I need to do something different. -- Duncan Booth http://kupuguy.blogspot.com From http Tue Jan 20 05:00:34 2009 From: http (Paul Rubin) Date: 20 Jan 2009 02:00:34 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: <7xzlhmthz1.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > No wonder you can't get Bruno's point. For the second, static checks > to prevent accidents, you have pylint. For the first, not only you > are using the wrong tool, but you are barking at python for not > having it. Assuming that pylint is perfect (big assumption, but it > is up to you to prove where it fails), Whaat? Assuming a program is perfect unless a failure is proven is not at all a sane approach to getting reliable software. It is the person claiming perfection who has to prove the absence of failure. From koranthala at gmail.com Tue Jan 20 05:11:52 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 20 Jan 2009 02:11:52 -0800 (PST) Subject: Logging help References: Message-ID: On Jan 20, 5:45?am, Chris Rebert wrote: > On Mon, Jan 19, 2009 at 11:36 AM, koranthala wrote: > > Hi, > > ? Is it possible somehow to have the logging module rotate the files > > every time I start it. > > ? Basically, I can automatically rotate using RotatingFileHandler; > > Now I want it rotated every time I start the program too. > > Just call the .doRollover() method of the RotatingFileHandler at the > start of the program. > Reading The Fine Documentation for the module is helpful. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com My question was poorly framed. I will try to explain the issue a little more. Current doRollover method is not very helpful to rolling over every day if the process starts and stops many times. For example: TimedRotatingFileHandler - when='D' Interval=1. I call handler.doRollover everytime process starts. First run - the output files are log.txt ---------- Second run - files are log.txt, log.txt.2009-01-20 ---------- Till now, fine. Third run - files are log.txt, log.txt.2009-01-20 ***But the earlier file is overwritten*** The doRollover method does not append to the earlier file. Rather, it creates a new file with the same name. Due to this the earlier logs are all gone. From alan.isaac at gmail.com Tue Jan 20 05:18:58 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 20 Jan 2009 10:18:58 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: On 1/18/2009 9:36 AM Alan G Isaac apparently wrote: > I do not much care about the disappearance of ``execfile``. > I was asking, why is it a **good thing** that > ``exec`` does not accept a TextIOWrapper? > Or is it just not implemented yet? > What is the gain from this particular backwards > incompatibility (in the sense that ``exec(open(fname))`` > no longer works)? Still interested in an answer... Alan Isaac From sri_annauni at yahoo.co.in Tue Jan 20 06:08:43 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 20 Jan 2009 16:38:43 +0530 (IST) Subject: Doubts related to subprocess.Popen() Message-ID: <60756.16702.qm@web7903.mail.in.yahoo.com> Hi, Does?subprocess.Popen() count a new open file for each suprocess? I mean does it occupy an entry in file descriptor table of parent process? If so, wat is each file descriptor connected to? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From skip at pobox.com Tue Jan 20 06:09:41 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 20 Jan 2009 05:09:41 -0600 Subject: what's the point of rpython? In-Reply-To: <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> Message-ID: <18805.45301.590851.980179@montanaro.dyndns.org> Carl> I just looked at the boost documentation, which claims that Carl> multiple asynchronous writes to the same shared_ptr results in Carl> undefined behavior. That will not suffice for Python reference Carl> counting. Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have read what you saw but not recognized it in the C++ punctuation soup. I couldn't find what you referred to. Can you provide a URL? Thanks, -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From hubaghdadi at gmail.com Tue Jan 20 06:23:07 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 03:23:07 -0800 (PST) Subject: How to start a transaction? Message-ID: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Hey, I know the basics of interacting with databases in Python. How to start a transaction in case I want to group a couple of insert and update statements into a single operation? Thanks. From deets at nospam.web.de Tue Jan 20 06:35:34 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 12:35:34 +0100 Subject: How to start a transaction? References: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Message-ID: <6tlr86Fbg6faU1@mid.uni-berlin.de> Hussein B wrote: > Hey, > I know the basics of interacting with databases in Python. > How to start a transaction in case I want to group a couple of insert > and update statements into a single operation? Please read the python database API documentation: http://www.python.org/dev/peps/pep-0249/ And make sure your database supports transactions. Diez From http Tue Jan 20 06:46:10 2009 From: http (Paul Rubin) Date: 20 Jan 2009 03:46:10 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> Message-ID: <7xfxje8akd.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have > read what you saw but not recognized it in the C++ punctuation soup. I > couldn't find what you referred to. Can you provide a URL? http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety Note there is also something called "interprocess shared pointers" (link below) that don't have that caveat. I wonder if they use locks. http://www.boost.org/doc/libs/1_37_0/doc/html/interprocess/interprocess_smart_ptr.html#interprocess.interprocess_smart_ptr.shared_ptr From s.selvamsiva at gmail.com Tue Jan 20 06:55:07 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 20 Jan 2009 17:25:07 +0530 Subject: python resource management In-Reply-To: References: Message-ID: Hi all, I have found the actual solution for this problem. I tried using BeautifulSoup.SoupStrainer() and it improved memory usage to the greatest extent.Now it uses max of 20 MB(earlier it was >800 MB on 1GB RAM system). thanks all. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Tue Jan 20 07:15:50 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:15:50 +0000 Subject: How to print lambda result ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") print string_ However, instead of getting the expected output: 1 event 2 events 3 events I get: 1 event at 0x00AFE670> 2 event at 0x00AFE670> 3 event at 0x00AFE6B0> Reading the first results of http://www.google.com/search?q=python+lambda didn't enlighten me. Could you point to a URL which could set me on the right path to get the expected output ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmas at tgaragemedia.com Tue Jan 20 07:16:42 2009 From: tmas at tgaragemedia.com (Thomas Lord) Date: Tue, 20 Jan 2009 07:16:42 -0500 Subject: python for flash drives Message-ID: try portable python. it's free! http://www.portablepython.com/ From tino at wildenhain.de Tue Jan 20 07:22:17 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 20 Jan 2009 13:22:17 +0100 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> Message-ID: <4975C1F9.6040607@wildenhain.de> Hi, Barak, Ron wrote: > Hi, > > Wanting to print the correct plural after numbers, I did the following: > > for num in range(1,4): > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") > print string_ > > However, instead of getting the expected output: > > 1 event > 2 events > 3 events > > I get: > > 1 event at 0x00AFE670> > 2 event at 0x00AFE670> > 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Tue Jan 20 07:33:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 12:33:16 +0000 Subject: ifconfig in python References: Message-ID: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> ?????? ??????????? writes: > Something *like* this could work: > > myip = urllib2.urlopen('http://whatismyip.org/').read() This is going to cause all manner of problems. Firstly, many users are stuck behind NAT routers. In this case, the external service will report the address of the router, which is probably useless -- certainly it will be for programs attempting to communicate over a LAN. Secondly, imagine the joy when overzealous ISPs decide that whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last month): then the service will report the address of ISP's censoring proxy to thousands of otherwise unrelated users. And that's before we get onto onion routers like Tor... Here's an idea which might do pretty well. In [1]: import socket as S In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) In [4]: s.connect(('192.0.2.1', 666)) In [5]: s.getsockname() Out[5]: ('172.29.198.11', 46300) (No packets were sent during this process: UDP `connections' don't need explicit establishment. The network 192.0.2.0/24 is reserved for use in examples; selecting a local address should therefore exercise the default route almost everywhere. If there's a specific peer address or network you want to communicate with, use that address explicitly.) I have to wonder what the purpose of this is. It's much better to have the recipient of a packet work out the sender's address from the packet (using recvfrom or similar) because that actually copes with NAT and so on properly. -- [mdw] From Ron.Barak at lsi.com Tue Jan 20 07:34:04 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:34:04 +0000 Subject: How to print lambda result ? In-Reply-To: <4975C1F9.6040607@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Thanks Tino: your solutions without the lambda work nicely. What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. Bye, Ron. -----Original Message----- From: Tino Wildenhain [mailto:tino at wildenhain.de] Sent: Tuesday, January 20, 2009 14:22 To: Barak, Ron Cc: python-list at python.org Subject: Re: How to print lambda result ? Hi, Barak, Ron wrote: > Hi, > > Wanting to print the correct plural after numbers, I did the following: > > for num in range(1,4): > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") > print string_ > > However, instead of getting the expected output: > > 1 event > 2 events > 3 events > > I get: > > 1 event at 0x00AFE670> > 2 event at 0x00AFE670> > 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino From deets at nospam.web.de Tue Jan 20 07:38:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 13:38:50 +0100 Subject: Doubts related to subprocess.Popen() References: Message-ID: <6tluuqFbkbquU1@mid.uni-berlin.de> srinivasan srinivas wrote: > Hi, > Does?subprocess.Popen() count a new open file for each suprocess? I mean > does it occupy an entry in file descriptor table of parent process? If so, > wat is each file descriptor connected to? Usually, each new process has three file-descriptors associated with it - stdin,stdout and stderr. So when you span a process, the overall count of FDs should increase by three. Additionally, there are more FDs created if you chose to pipe communication between the child-process and the parent. This is a unix-thing btw, nothing to do with subprocess per se. Diez From tino at wildenhain.de Tue Jan 20 07:45:06 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 20 Jan 2009 13:45:06 +0100 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: <4975C752.1060702@wildenhain.de> Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. Well its up to the implemention what a class is supposed to return when its __str__() is called. Default is what you see. (this is actually __str__() returning __repr__() which is at its default) Regards Tino > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Tue Jan 20 07:46:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 12:46:17 +0000 Subject: Doubts related to subprocess.Popen() References: Message-ID: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> srinivasan srinivas writes: > Does subprocess.Popen() count a new open file for each suprocess? I > mean does it occupy an entry in file descriptor table of parent > process? If so, wat is each file descriptor connected to? On Unix, subprocess.Popen will use up a file descriptor in the parent for each use of subprocess.PIPE. The descriptor in question is one end of a pipe; the child process holds the other end. I guess the situation is similar on Windows, but I don't know for sure. -- [mdw] From Ron.Barak at lsi.com Tue Jan 20 07:47:17 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 20 Jan 2009 12:47:17 +0000 Subject: How to print lambda result ? In-Reply-To: <4975C752.1060702@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> <4975C752.1060702@wildenhain.de> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024E9B33@enbmail01.lsi.com> Ah, okay. Now it's clear. Thanks Tino. Ron. -----Original Message----- From: Tino Wildenhain [mailto:tino at wildenhain.de] Sent: Tuesday, January 20, 2009 14:45 To: Barak, Ron Cc: python-list at python.org Subject: Re: How to print lambda result ? Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. Well its up to the implemention what a class is supposed to return when its __str__() is called. Default is what you see. (this is actually __str__() returning __repr__() which is at its default) Regards Tino > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino From RasikaSrinivasan at gmail.com Tue Jan 20 07:50:31 2009 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Tue, 20 Jan 2009 04:50:31 -0800 (PST) Subject: ifconfig in python References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> On Jan 20, 7:33?am, Mark Wooding wrote: > ?????? ??????????? writes: > > Something *like* ?this could work: > > > ? ?myip = urllib2.urlopen('http://whatismyip.org/').read() > > This is going to cause all manner of problems. > > Firstly, many users are stuck behind NAT routers. ?In this case, the > external service will report the address of the router, which is > probably useless -- certainly it will be for programs attempting to > communicate over a LAN. > > Secondly, imagine the joy when overzealous ISPs decide that > whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last > month): then the service will report the address of ISP's censoring > proxy to thousands of otherwise unrelated users. > > And that's before we get onto onion routers like Tor... > > Here's an idea which might do pretty well. > > In [1]: import socket as S > In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) > In [4]: s.connect(('192.0.2.1', 666)) > In [5]: s.getsockname() > Out[5]: ('172.29.198.11', 46300) > > (No packets were sent during this process: UDP `connections' don't need > explicit establishment. ?The network 192.0.2.0/24 is reserved for use in > examples; selecting a local address should therefore exercise the > default route almost everywhere. ?If there's a specific peer address or > network you want to communicate with, use that address explicitly.) > > I have to wonder what the purpose of this is. ?It's much better to have > the recipient of a packet work out the sender's address from the packet > (using recvfrom or similar) because that actually copes with NAT and so > on properly. > > -- [mdw] one way to get your head around this is - IP Addresses are associated with the interface and not the computer. distinction may be subtle but critical. From wuwei23 at gmail.com Tue Jan 20 07:51:26 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 04:51:26 -0800 (PST) Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> On Jan 20, 10:34?pm, "Barak, Ron" wrote: > What I still don't understand is why the print does not > execute the lambda and prints the result, instead of > printing the lambda's object description. The following two statements are identical: >>> def f(x): return x ... >>> f = lambda x: x lambda _creates_ a function, it's up to you to actually _call_ the function. Functions are first class objects in Python, so the tuple you're passing in to the string format contains a number and a function. Tino's solutions are definitely more what you're looking for, but for your lambda version to work, you have to actually call the lambda function, passing in num when you do so (as you've specified that the lambda function requires one argument): >>> for num in range(1, 4): ... string_ = "%d event%s" % (num, (lambda num: num > 1 and "s" or "")(num)) ... print string_ Or you can remove the argument and create a closure using the num value from the loop: ... string_ = "%d event%s" % (num, (lambda: num > 1 and "s" or "") ()) But again, this is generally overkill when all you're after is a conditional value. Personally, I tend to use lambdas for passing small units of functionality into other functions, or if I want to create a quick closure. Your mileage may vary on what you consider a suitable use case, but you will -still- have to call your lambda in order for it to execute :) Generally From T.P.Northover at sms.ed.ac.uk Tue Jan 20 07:57:25 2009 From: T.P.Northover at sms.ed.ac.uk (Tim Northover) Date: Tue, 20 Jan 2009 12:57:25 +0000 Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> Message-ID: <87fxjegmoa.fsf@hal9000.lan> alex23 writes: > On Jan 20, 10:34?pm, "Barak, Ron" wrote: >>>> for num in range(1, 4): > ... string_ = "%d event%s" % (num, (lambda num: num > 1 and "s" or > "")(num)) > ... print string_ The notation here suggests Ron is sligtly confused about what he created. It was equivalent to string_ = "%d event%s" % (num, lambda x: x > 1 and "s" or "") Notice that there's no actual mention of num there, it's a function that takes one parameter. If that parameter happens to be num it does what you want, but there's no way for the interpreter to know what was intended. Tim. From hubaghdadi at gmail.com Tue Jan 20 08:11:17 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 05:11:17 -0800 (PST) Subject: Why I'm getting the date of yesterday Message-ID: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> Hey, I'm trying to get the get the date before today, I tried this: d = datetime.now() - timedelta(days = -1) But I got the date of tomorrow. when I tried: d = datetime.now() + timedelta(days = -1) I got the date of yesterday. Would you please explain to me why I got the date of yesterday when I added the both objects? Thanks. From simon at brunningonline.net Tue Jan 20 08:20:20 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 20 Jan 2009 13:20:20 +0000 Subject: Why I'm getting the date of yesterday In-Reply-To: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> References: <0e119250-97ef-4257-a156-b5453334a1de@z6g2000pre.googlegroups.com> Message-ID: <8c7f10c60901200520h3f299a2cj38cb274a6c58344c@mail.gmail.com> 2009/1/20 Hussein B : > Hey, > I'm trying to get the get the date before today, I tried this: > d = datetime.now() - timedelta(days = -1) > But I got the date of tomorrow. That's because you are taking away a negative value. This is like doing: >>> 0 - (-1) 1 -- Cheers, Simon B. From kyrie at uh.cu Tue Jan 20 08:22:33 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 08:22:33 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901200822.33174.kyrie@uh.cu> On Tuesday 20 January 2009 02:00:43 am Russ P. wrote: > On Jan 19, 10:33?pm, Luis Zarrabeitia wrote: > > (Why do you keep calling it 'encapsulation'?). > > I keep calling it encapsulation because that is a widely accepted, > albeit not universal, definition of encapsulation. [...] > Encapsulation conceals the functional details of a class from objects > that send messages to it. [..] > Definition: In Object Oriented Programming, encapsulation is an > attribute of object design. It means that all of the object's data is > contained and hidden in the object and access to it restricted to > members of that class. Ahh, 'concealed', 'contained', 'hidden'. Except the last one, "hidden", python does the rest... and one could argue the self.__privs get pretty well hidden. Not 'forbidden', 'restricted', 'enforced'. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From mal at egenix.com Tue Jan 20 08:25:18 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 20 Jan 2009 14:25:18 +0100 Subject: How to start a transaction? In-Reply-To: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> References: <30510a0d-7fd0-45ae-9ed2-f6c0391c1507@o4g2000pra.googlegroups.com> Message-ID: <4975D0BE.9010506@egenix.com> On 2009-01-20 12:23, Hussein B wrote: > Hey, > I know the basics of interacting with databases in Python. > How to start a transaction in case I want to group a couple of insert > and update statements into a single operation? If you use a Python DB-API compatible database module, then transactions are enabled per default after you connect to the database. connection.commit() and .rollback() then complete a transaction and implicitly start a new one. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 20 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From kyrie at uh.cu Tue Jan 20 08:33:08 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 20 Jan 2009 08:33:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmthz1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <200901200833.08215.kyrie@uh.cu> On Tuesday 20 January 2009 05:00:34 am Paul Rubin wrote: > Luis Zarrabeitia writes: > > No wonder you can't get Bruno's point. For the second, static checks > > to prevent accidents, you have pylint. For the first, not only you > > are using the wrong tool, but you are barking at python for not > > having it. Assuming that pylint is perfect (big assumption, but it > > is up to you to prove where it fails), > > Whaat? Assuming a program is perfect unless a failure is proven > is not at all a sane approach to getting reliable software. It is > the person claiming perfection who has to prove the absence of failure. No, no. I meant that if pylint works as its specification says it would. Russ says (or seems to say, I don't know, I'm confused already) that it is not good enough, that what pylint says it does is not what he wants (otherwise, this subthread would have died a long time ago). So, assuming that pylint works as specified (its up to "you" to find out if it doesn't and file bugreports about it, just like you would do if you find out that the static-checker for your enforced-static-checks-language is buggy), what would be the difference between only accepting/running "pylint-authorized code" and the enforced hiding you desire? Sorry, I didn't realize that perfect was a too strong word for that. "I speaks english bad" :D Cya! -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 20 08:33:11 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 20 Jan 2009 14:33:11 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjett86.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> Message-ID: <4975d297$0$24204$426a34cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >> Take some not-that-trivial projects like Zope/Plone. There are quite a >> few lines of code involved, and quite a lot of programmers worked on it. > > Zope is about 375 KLOC[1], I was thinking about Zope2 + Plone, but anyway... > which I agree is not trivial, but by > today's standards, it's not all that large. How many LOCS would it require if it was written in ADA ? > Zope also has 275 open > bugs, 6 of which are critical. None of which are going to *kill* anyone FWIW. Now how many of these bugs would have language-enforced access restriction prevented ? >[2] The Space Shuttle avionics (written > in the 1980's!) are 2 MLOC of a hi-level dynamic language ? Hm, I guess not. > in which only 3 errors have been found > post-release.[3] I think "large software system" today means 100's of > MLOC. Given the difference in LOCS count between a low-level static language and a hi-level dynamic language for the implementation of a same given features set, you cannot just define "large" by the # of LOCS. Not that I'm going to compare Zope with Space shuttle's stuff. > FWIW, Zope has 20x as much code as Django--is that a good > thing!? IMHO, definitively not - and I indeed prefer Django as far as I'm concerned. But this is another debate (or is it not ?...) From deets at nospam.web.de Tue Jan 20 09:06:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:06:46 +0100 Subject: Embedding Python. But not so easy. References: Message-ID: <6tm43mFbit9bU1@mid.uni-berlin.de> > 1) Threads: the simulation is going to be run in a very parallel > environment with several CPUs and > http://docs.python.org/c-api/init.html#thread-state-and- > the-global-interpreter-lock there is a global lock mentioned. Does that > mean that the python code can not benefit from this ? Not if it is CPU-bound, no. To overcome that, you'd either need multiple processes, or you could try & trick the python interpreter by using renamed DLLs, which means that you can start several interpreters in one process. *BUT* that's a nasty hack & you can't share objects between the interpreters. > 2) The script has to hand back control to the C++ framework without > increasing the C execution stack. and be able to resume the execution at a > later point. > > I try some pseudo code here to explain > > // C++: > ctx = new ExecutionContext(); > > ctx->run(); > while(ctx->stillRunning()) { > otherStuff(); > ctx->resume(); > } Stackless python might be of help here, google it. Diez From rolf.oltmans at gmail.com Tue Jan 20 09:08:11 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Tue, 20 Jan 2009 06:08:11 -0800 (PST) Subject: A SSH error during put operation Message-ID: <337d1fc9-2378-4a9e-b984-dd75e2145f26@y1g2000pra.googlegroups.com> Hey all, I've been using Paramiko for sometime now and I never had any problems. I've already submitted this question to Paramiko mailling list but I thought I should post it in CLP as someone might have used it in past. I'm using Paramiko for SSH. Are there any other good SSH libraries that you've found useful--please let me know? There is this script that used to work absolutely fine. But for some reason it's broken now. First, here is the script. Error is pasted at the end. Please help as I've searched the Internet, archives but couldn't find anything and it's been quite a few hours now. I will really appreciate any help. Thanks in advance. Script: from __future__ import with_statement import paramiko import base64,os, sys from paramiko import AutoAddPolicy, SSHClient from decimal import * class CustomException(Exception): def __init__(self, value): self.parameter = value def __str__(self): return repr(self.parameter) def ConnectCopy(domainInfo, uname, pwd, portNumber,zipName,completePath): #domainInfo is a list, where domainInfo[0] = host name and #domainInfo[1] is the remote path. #---- #zipName is the name of zip file. It will be appended with domainInfo[1] so #it will look like c:\Test\ABC.zip #---- #completePath is the local file path , that we intend to copy to remote host domainName="" domainName=domainInfo[0].strip() client= paramiko.SSHClient() client.set_missing_host_key_policy(AutoAddPolicy()) print 'Complete Path= '+completePath try: client.connect (domainName,portNumber,username=uname,password=pwd) except CustomException, (e): print "Error="+e.parameter print "Domain Info= "+domainInfo[1] try: sftp=client.open_sftp() sftp.put(os.path.normpath(completePath),os.path.normpath (domainInfo[1])+"\\"+zipName) sys.stdout.write('\n') print 'File has been copied' except CustomException,(e): print "Error = "+e.parameter sys.exit() sftp.close() client.close() if __name__=="__main__": ConnectCopy(['example.example.com','C:\\test'],'username','pwd', 8922,'ABC.zip','C:\\ABC.zip') and here is the Error: Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. C:\Release>connectdeploy1.py Traceback (most recent call last): File "C:\Release\ConnectDeploy1.py", line 56, in ConnectCopy(['example.example.com','C:\\test'],'username','pwd', 8922,'ABC.zip','C:\\ABC.zip') File "C:\Release\ConnectDeploy1.py", line 39, in ConnectCopy sftp.put(os.path.normpath(completePath),os.path.normpath(domainInfo [1])) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 539, in put fr = self.file(remotepath, 'wb') File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 238, in ope n t, msg = self._request(CMD_OPEN, filename, imode, attrblock) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 589, in _re quest return self._read_response(num) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 637, in _re ad_response self._convert_status(msg) File "C:\Python25\lib\site-packages\paramiko\sftp_client.py", line 667, in _co nvert_status raise IOError(text) IOError: SfsStatusCode.Failure From hubaghdadi at gmail.com Tue Jan 20 09:19:21 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 06:19:21 -0800 (PST) Subject: How to get first/last day of the previous month? Message-ID: Hey, I'm creating a report that is supposed to harvest the data for the previous month. So I need a way to get the first day and the last day of the previous month. Would you please tell me how to do this? Thanks in advance. From sri_annauni at yahoo.co.in Tue Jan 20 09:19:33 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 20 Jan 2009 19:49:33 +0530 (IST) Subject: Doubts related to subprocess.Popen() References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <530163.74241.qm@web7903.mail.in.yahoo.com> Do?parent process will have different file descriptor in it for each subprocesses or?paprent uses a single file descriptor for all? I really want to know creation of each subprocess will occupy an entry in parents'file descriptor table. B'cos if i create more than 200 subprocesses, i am getting 'Too many open files' error. Thanks, Srini ----- Original Message ---- From: Mark Wooding To: python-list at python.org Sent: Tuesday, 20 January, 2009 6:16:17 PM Subject: Re: Doubts related to subprocess.Popen() srinivasan srinivas writes: > Does subprocess.Popen() count a new open file for each suprocess? I > mean does it occupy an entry in file descriptor table of parent > process?? If so, wat is each file descriptor connected to? On Unix, subprocess.Popen will use up a file descriptor in the parent for each use of subprocess.PIPE.? The descriptor in question is one end of a pipe; the child process holds the other end. I guess the situation is similar on Windows, but I don't know for sure. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From darcy at druid.net Tue Jan 20 09:26:14 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 09:26:14 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: <20090120092614.b6fbebe4.darcy@druid.net> On Tue, 20 Jan 2009 12:34:04 +0000 "Barak, Ron" wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. Because that's what you told it. Consider the even simpler example... "%s" % lambda num: int(num) This is equivalent to... "%s" % int IOW, you are giving the function (anonymous in your case), not the result of calling it. Your code prints a representation of exactly what you gave it, an anonymous function that would return a string if you called it with a number. > > for num in range(1,4): > > string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From philip at semanchuk.com Tue Jan 20 09:28:34 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 20 Jan 2009 09:28:34 -0500 Subject: Doubts related to subprocess.Popen() In-Reply-To: <530163.74241.qm@web7903.mail.in.yahoo.com> References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> <530163.74241.qm@web7903.mail.in.yahoo.com> Message-ID: <45A4A799-A622-41D0-91AD-A506F1A8B37C@semanchuk.com> On Jan 20, 2009, at 9:19 AM, srinivasan srinivas wrote: > Do parent process will have different file descriptor in it for each > subprocesses or paprent uses a single file descriptor for all? > I really want to know creation of each subprocess will occupy an > entry in parents'file descriptor table. B'cos if i create more than > 200 subprocesses, i am getting 'Too many open files' error. If you're on Unix, a command like lsof can be useful at a time like this. lsof = "ls open files" If you're on Linux, there's the /proc tree to investigate. > > ----- Original Message ---- > From: Mark Wooding > To: python-list at python.org > Sent: Tuesday, 20 January, 2009 6:16:17 PM > Subject: Re: Doubts related to subprocess.Popen() > > srinivasan srinivas writes: > >> Does subprocess.Popen() count a new open file for each suprocess? I >> mean does it occupy an entry in file descriptor table of parent >> process? If so, wat is each file descriptor connected to? > > On Unix, subprocess.Popen will use up a file descriptor in the parent > for each use of subprocess.PIPE. The descriptor in question is one > end > of a pipe; the child process holds the other end. > > I guess the situation is similar on Windows, but I don't know for > sure. > > -- [mdw] > -- > http://mail.python.org/mailman/listinfo/python-list > > > > Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ > -- > http://mail.python.org/mailman/listinfo/python-list From gspschmid at gmail.com Tue Jan 20 09:33:29 2009 From: gspschmid at gmail.com (Georg Schmid) Date: Tue, 20 Jan 2009 06:33:29 -0800 (PST) Subject: SetUp functions for multiple test cases Message-ID: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> I've just started working with unittests and already hit a snag. I couldn't find out how to implement a setup function, that is executed only _once_ before all of the tests. Specifically, I need this for testing my database interface, and naturally I don't want to create a new database in-memory and fill it with example data for every single test case. Obviously I could simply execute that setup function separately from the unittesting procedure, but then there'd be no point in implementing all my unittests in a clean manner in the first place, apart from further problems arising due to how my IDE (Eric4) picks test cases from project files. Perhaps I missed something about the concept of TestSuites. Thanks in advance! From darcy at druid.net Tue Jan 20 09:53:04 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 09:53:04 -0500 Subject: How to print lambda result ? In-Reply-To: <20090120092614.b6fbebe4.darcy@druid.net> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> <20090120092614.b6fbebe4.darcy@druid.net> Message-ID: <20090120095304.d68f3ee9.darcy@druid.net> On Tue, 20 Jan 2009 09:26:14 -0500 "D'Arcy J.M. Cain" wrote: > "%s" % lambda num: int(num) Of course I meant... "%s" % (lambda num: int(num)) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From kyosohma at gmail.com Tue Jan 20 09:54:16 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 20 Jan 2009 06:54:16 -0800 (PST) Subject: How to get first/last day of the previous month? References: Message-ID: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> On Jan 20, 8:19?am, Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? > Thanks in advance. I recommend the dateutil module: http://labix.org/python-dateutil I think it may also be possible to use the datetime module, but it's easier to just use dateutil. Mike From deets at nospam.web.de Tue Jan 20 09:55:22 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:55:22 +0100 Subject: How to get first/last day of the previous month? References: Message-ID: <6tm6uqFbgvnbU1@mid.uni-berlin.de> Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? First day: create a new date-object with the day==1. Last day: create a date-object with month + 1 and day==1, and subtract a timedelta with one day of it. Diez From deets at nospam.web.de Tue Jan 20 09:56:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 20 Jan 2009 15:56:50 +0100 Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <6tm71iFbgvnbU2@mid.uni-berlin.de> Georg Schmid wrote: > I've just started working with unittests and already hit a snag. I > couldn't find out how to implement a setup function, that is executed > only _once_ before all of the tests. Specifically, I need this for > testing my database interface, and naturally I don't want to create a > new database in-memory and fill it with example data for every single > test case. > Obviously I could simply execute that setup function separately from > the unittesting procedure, but then there'd be no point in > implementing all my unittests in a clean manner in the first place, > apart from further problems arising due to how my IDE (Eric4) picks > test cases from project files. > Perhaps I missed something about the concept of TestSuites. Thanks in > advance! Why don't you simply store the state of the DB being set-up somewhere (globally for example), and only execute the db-setup-code (inside setUp of course) depending on the value of that variable? Diez From roy at panix.com Tue Jan 20 09:57:51 2009 From: roy at panix.com (Roy Smith) Date: Tue, 20 Jan 2009 09:57:51 -0500 Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: In article <45b0bf56-673c-40cd-a27a-62f9943d9f1a at r41g2000prr.googlegroups.com>, Georg Schmid wrote: > I've just started working with unittests and already hit a snag. I > couldn't find out how to implement a setup function, that is executed > only _once_ before all of the tests. Specifically, I need this for > testing my database interface, and naturally I don't want to create a > new database in-memory and fill it with example data for every single > test case. Short answer -- there's no way to do it in the unittest framework. The True Unit Test Zealots will argue that all tests should be 100% independent of each other, which means there should be NO common state between test cases. For that matter, they will also argue that unit tests should not interface with external resources like databases. And they're right. On the other hand, the Real World Test Pragmatists will argue that this is just not practical in all cases. Real programs have classes which interact with the outside world, and they need to get tested. You could stub out the external resource, but that's a lot of work, and may introduce as many problems as it solves. Sometimes, a big part of what you're testing is your understanding of the external world (i.e. "does this really work like it's documented?"). Plus, some operations are just too expensive to do for every test case. I don't know how long it takes to build your in-memory database. If it takes one second, it probably makes sense to do it for every test case (unless you've got thousands of test cases). If it takes 10 minutes, then it makes sense to do it once and deal with the fact that you're violating True Unit Test Dogma. Anyway, do what I do. I run the tests with a: if __name__ == "__main__": blah blah block at the bottom of the test file. Just do your "do once" setup in that code block and store the result in a global. You might have your setUp() method re-assign the global to an instance variable and then your test cases can access it via self.whatever. The reason for that is if at some point in the future you change your mind and decide to re-build the database in setUp() for each test, you just have to change setUp(), not touch the individual test cases. From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:03:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:03:35 -0200 Subject: Logging help References: Message-ID: En Tue, 20 Jan 2009 08:11:52 -0200, koranthala escribi?: > On Jan 20, 5:45?am, Chris Rebert wrote: >> On Mon, Jan 19, 2009 at 11:36 AM, koranthala >> wrote: >> > ? Is it possible somehow to have the logging module rotate the files >> > every time I start it. >> > ? Basically, I can automatically rotate using RotatingFileHandler; >> > ^^^^^^^^^^^^^^^^^^^ > >> Now I want it rotated every time I start the program too. >> >> Just call the .doRollover() method of the RotatingFileHandler at the >> ^^^^^^^^^^^^^^^^^^^ start of >> the program. >> Reading The Fine Documentation for the module is helpful. > > Current doRollover method is not very helpful to rolling over every > day if the process starts and stops many times. > For example: > TimedRotatingFileHandler - when='D' Interval=1. I call > ^^^^^^^^^^^^^^^^^^^^^^^^ handler.doRollover everytime process starts. Why the move to TimedRotatingFileHandler? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:03:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:03:36 -0200 Subject: Logging help References: Message-ID: En Tue, 20 Jan 2009 08:11:52 -0200, koranthala escribi?: > On Jan 20, 5:45?am, Chris Rebert wrote: >> On Mon, Jan 19, 2009 at 11:36 AM, koranthala >> wrote: >> > ? Is it possible somehow to have the logging module rotate the files >> > every time I start it. >> > ? Basically, I can automatically rotate using RotatingFileHandler; >> > ^^^^^^^^^^^^^^^^^^^ > >> Now I want it rotated every time I start the program too. >> >> Just call the .doRollover() method of the RotatingFileHandler at the >> ^^^^^^^^^^^^^^^^^^^ start of >> the program. >> Reading The Fine Documentation for the module is helpful. > > Current doRollover method is not very helpful to rolling over every > day if the process starts and stops many times. > For example: > TimedRotatingFileHandler - when='D' Interval=1. I call > ^^^^^^^^^^^^^^^^^^^^^^^^ handler.doRollover everytime process starts. Why the move to TimedRotatingFileHandler? -- Gabriel Genellina From carsten.haese at gmail.com Tue Jan 20 10:04:00 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 20 Jan 2009 10:04:00 -0500 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Hussein B wrote: > Hey, > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. In order to not deprive you of the sense of accomplishment from figuring things out for yourself, I'll give you a couple of hints instead of fully formed Python code: 1) Think about how you can find the first day of the *current* month. 2) Think about how you can get to the last day of the previous month from there. 3) Think about how you can get to the first day of the previous month from there. Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net From marco at sferacarta.com Tue Jan 20 10:06:13 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:06:13 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Hussein B wrote: > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? > Thanks in advance. dateutil can do this and much, much more. >>> from datetime import date >>> from dateutil.relativedelta import relativedelta >>> today = date.today() >>> d = today - relativedelta(months=1) >>> date(d.year, d.month, 1) datetime.date(2008, 12, 1) >>> date(today.year, today.month, 1) - relativedelta(days=1) datetime.date(2008, 12, 31) >>> From wuwei23 at gmail.com Tue Jan 20 10:07:20 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 07:07:20 -0800 (PST) Subject: How to print lambda result ? References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <6ca64b8e-6738-413c-9406-a903da869753@a39g2000prl.googlegroups.com> <87fxjegmoa.fsf@hal9000.lan> Message-ID: <1abed683-f504-4ba5-afb8-26040991d758@z27g2000prd.googlegroups.com> On Jan 20, 10:57?pm, Tim Northover wrote: > Notice that there's no actual mention of num there, it's a function that > takes one parameter. If that parameter happens to be num it does what > you want, but there's no way for the interpreter to know what was > intended. Which is why my working example explicitly passed num into the lambda, and why my variant used a closure... From marco at sferacarta.com Tue Jan 20 10:07:46 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:07:46 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: <6Nldl.1258$8Z.845@tornado.fastwebnet.it> Carsten Haese wrote: > In order to not deprive you of the sense of accomplishment Sorry for spoiling that. If you still want the sense of accomplishment, try to reimplement dateutil (and rrule). It's not as easy as it seems :-o From carsten.haese at gmail.com Tue Jan 20 10:12:06 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 20 Jan 2009 10:12:06 -0500 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Marco Mariani wrote: > dateutil can do this and much, much more. Using dateutil for this is like using a sledgehammer to kill a fly. The task at hand can (and IMHO should) be solved with the standard datetime module. -- Carsten Haese http://informixdb.sourceforge.net From aberry at aol.in Tue Jan 20 10:13:08 2009 From: aberry at aol.in (aberry) Date: Tue, 20 Jan 2009 07:13:08 -0800 (PST) Subject: smtplib.SMTP throw : 'Socket error: 10053 software caused connection abort' Message-ID: <21565011.post@talk.nabble.com> I am using 'smtplib' module to send an email but getting exception... smtplib.SMTP( throw error : here is trace back snippet :- " smtp = smtplib.SMTP(self.server) File "D:\Python24\lib\smtplib.py", line 244, in __init__ (code, msg) = self.connect(host, port) File "D:\Python24\lib\smtplib.py", line 306, in connect raise socket.error, msg socket.error: (10053, 'Software caused connection abort')" thanks in adv, aberry -- View this message in context: http://www.nabble.com/smtplib.SMTP-throw-%3A-%27Socket-error%3A-10053-software-caused-connection-abort%27-tp21565011p21565011.html Sent from the Python - python-list mailing list archive at Nabble.com. From python.list at tim.thechases.com Tue Jan 20 10:19:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Jan 2009 09:19:18 -0600 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: <4975EB76.1050406@tim.thechases.com> > I'm creating a report that is supposed to harvest the data for the > previous month. > So I need a way to get the first day and the last day of the previous > month. > Would you please tell me how to do this? >>> from datetime import date, datetime, timedelta >>> def prev_bounds(when=None): ... if not when: when = datetime.today() ... this_first = date(when.year, when.month, 1) ... prev_end = this_first - timedelta(days=1) ... prev_first = date(prev_end.year, prev_end.month, 1) ... return prev_first, prev_end ... >>> prev_bounds() (datetime.date(2008, 12, 1), datetime.date(2008, 12, 31)) >>> prev_bounds(datetime.date(2008,3,14) (datetime.date(2008, 2, 1), datetime.date(2008, 2, 29)) -tkc From marco at sferacarta.com Tue Jan 20 10:20:25 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 20 Jan 2009 16:20:25 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: References: Message-ID: Carsten Haese wrote: >> dateutil can do this and much, much more. > > Using dateutil for this is like using a sledgehammer to kill a fly. The > task at hand can (and IMHO should) be solved with the standard datetime > module. Sure, but many python programmers are not even aware of the existence of that particular sledgehammer, it deserved to be mentioned. It should be part of the standard library I think. From gspschmid at gmail.com Tue Jan 20 10:24:49 2009 From: gspschmid at gmail.com (Georg Schmid) Date: Tue, 20 Jan 2009 07:24:49 -0800 (PST) Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <9d394e95-0c99-4abe-ae87-d715a71e22d2@v39g2000pro.googlegroups.com> On Jan 20, 3:57?pm, Roy Smith wrote: > In article > <45b0bf56-673c-40cd-a27a-62f9943d9... at r41g2000prr.googlegroups.com>, > ?Georg Schmid wrote: > > > I've just started working with unittests and already hit a snag. I > > couldn't find out how to implement a setup function, that is executed > > only _once_ before all of the tests. Specifically, I need this for > > testing my database interface, and naturally I don't want to create a > > new database in-memory and fill it with example data for every single > > test case. > > Short answer -- there's no way to do it in the unittest framework. > > The True Unit Test Zealots will argue that all tests should be 100% > independent of each other, which means there should be NO common state > between test cases. ?For that matter, they will also argue that unit tests > should not interface with external resources like databases. ?And they're > right. > > On the other hand, the Real World Test Pragmatists will argue that this is > just not practical in all cases. ?Real programs have classes which interact > with the outside world, and they need to get tested. ?You could stub out > the external resource, but that's a lot of work, and may introduce as many > problems as it solves. ?Sometimes, a big part of what you're testing is > your understanding of the external world (i.e. "does this really work like > it's documented?"). > > Plus, some operations are just too expensive to do for every test case. ?I > don't know how long it takes to build your in-memory database. ?If it takes > one second, it probably makes sense to do it for every test case (unless > you've got thousands of test cases). ?If it takes 10 minutes, then it makes > sense to do it once and deal with the fact that you're violating True Unit > Test Dogma. > > Anyway, do what I do. ?I run the tests with a: > > if __name__ == "__main__": > ? ?blah blah > > block at the bottom of the test file. ?Just do your "do once" setup in that > code block and store the result in a global. > > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. ?The > reason for that is if at some point in the future you change your mind and > decide to re-build the database in setUp() for each test, you just have to > change setUp(), not touch the individual test cases. Thanks, exactly what I needed to know. From james at agentultra.com Tue Jan 20 10:26:33 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 20 Jan 2009 10:26:33 -0500 Subject: Two questions about style and some simple math References: Message-ID: <85k58qt2vq.fsf@dozer.localdomain> Spoofy writes: > .. .. > > 2. > > For maintaining the character attributes I creates a seperate class. I > wonder weather this is an "overuse" of OO (instead of just making the > attributes plain variables of the Char class) and if the way I wrote > this is OK (somehow this looks cool to me but maybe too "showy"?) > > class Attributes(object): > ATTRIBUTES = {"attack": 0, "defence": 0, "ability": 0, "courage": > 0, "condition": 0} > def __init__(self, **kwargs): > self.__dict__.update(self.ATTRIBUTES) > for arg in kwargs: > if arg not in self.ATTRIBUTES: > raise ValueError("Unkown character attribute '%s'" % > arg) > self.__dict__[arg] = kwargs[arg] > > > Again, I appreciate any tips. I you need more code (for the bigger > picture or such), just ask. > > Thanks in advance I think the first part has been covered well. If you want an opinion, this class isn't "showy" at all, rather it is ugly and unnecessary. Firstly it's bad because: 1. ATTRIBUTES is still modifiable after insantiation. This breaks the restriction you're expressing in __init__ 2. You want to avoid modifying __dict__ directly if you can. It bypasses the whole point of using named attributes. What you'd really want in a case where a class has a restricted set of attributes is __slots__. Classes defined with it have no __dict__ and thus attributes cannot be dynamically added to them after instanciation (a __slots__ defined class will raise an exception in this case). However, even in this case, it doesn't make sense to encapsulate the attributes of your game's Character objects in this way. Your "Hero" class should have its attributes directly associated to it: Hero.health, Hero.defence, and so forth. If you want to encapsulate a common set of attributes available to a "class" of objects, you'd create a "Character" class with those general attributes, sub-class your NPC's and Hero from it, and specialize those sub-classes as needed. HTH, j_king From bedouglas at earthlink.net Tue Jan 20 10:31:59 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 20 Jan 2009 07:31:59 -0800 Subject: ifconfig in python In-Reply-To: Message-ID: <086001c97b14$3e195620$0301a8c0@tmesa.com> hi... in general, i've found that using "route" to find the iface for the default gets me the interface in use... i then parse either ifconfig/iwconfig, to get the address of the nic for that interface.. it's worked ok so far on most machines i've dealt with... thoughts/comments are of course welcome! -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Ned Deily Sent: Monday, January 19, 2009 6:49 PM To: python-list at python.org Subject: Re: ifconfig in python In article , "James Mills" wrote: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres > wrote: > > Is ther an easy way to get the resolved ip address of the machine a script > > is running on? socket.gethostbyname(socket.gethostname) has only returned > > the ip address of my loop back interface ... not very usefull. > > That's because your /etc/hosts resolves > your hostname to 127.0.0.1 :) > > And no I know of no "easy" way cross > platform way. Perhaps parsing the output > of ifconfig itself ? Also, since the subject is on my brain at the moment, how to find "the address" is not the right question to ask. These days most systems have multiple network interfaces (Ethernet, WiFi, dialup, et al) running multiple protocols, like IPv4 and IPv6. In general, there is no *one* IP address of a machine; often there are many. Ignoring that fact can lead to subtle bugs, like the one causing a urllib2 regression test failure that I've been squashing today! -- Ned Deily, nad at acm.org -- http://mail.python.org/mailman/listinfo/python-list From hubaghdadi at gmail.com Tue Jan 20 10:32:06 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Tue, 20 Jan 2009 07:32:06 -0800 (PST) Subject: How to get first/last day of the previous month? References: Message-ID: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> On Jan 20, 5:04?pm, Carsten Haese wrote: > Hussein B wrote: > > Hey, > > I'm creating a report that is supposed to harvest the data for the > > previous month. > > So I need a way to get the first day and the last day of the previous > > month. > > In order to not deprive you of the sense of accomplishment from figuring > things out for yourself, I'll give you a couple of hints instead of > fully formed Python code: > > 1) Think about how you can find the first day of the *current* month. > > 2) Think about how you can get to the last day of the previous month > from there. > > 3) Think about how you can get to the first day of the previous month > from there. > > Hope this helps, > > -- > Carsten Haesehttp://informixdb.sourceforge.net Thanks all for the reply. Yes, I prefer to use the standard library. Talking about the third step: You told me to think how to get the first day of the previous month, well how to know if the previous month is 28, 29, 30 or 31 days? I'm new to Python, so forgive my questions. From gagsl-py2 at yahoo.com.ar Tue Jan 20 10:33:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 20 Jan 2009 13:33:04 -0200 Subject: Problem with IDLE on windows XP References: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> Message-ID: En Mon, 19 Jan 2009 20:50:43 -0200, Grimes, George escribi?: > I am trying to learn Python and I installed version 2.6 both at home and > at work. At home, on > Vista, everything works fine. At work, on XP, IDLE would not run. I > uninstalled/reinstalled > and got the same thing. My cursor changes to the wait symbol for a few > seconds, then goes > back to normal and ?.nothing. The Task Manager shows nothing. I > uninstalled again, > made sure all the files were deleted from the disk, used regedit to > delte every registry entry > that had python in it and tried version 3.0. > > Geuss, what? I still can?t run IDLE on XP? Is this a common problem? > Or am I unique? Did you install "for all users" (as Administrator) or "just for me"? The following instructions assume you installed Python 2.6 on C:\Python26 -- replace with your own directory if different. Open a command prompt (go to Start, Run, type "cmd" and press Enter). At the > prompt type: c:\Python26\python -V and press Enter. Should reply with the Python version. Then try with: c:\Python26\python c:\Python26\Lib\idlelib\idle.pyw Should start IDLE, probably you get some error message; post it here. -- Gabriel Genellina From duncan.booth at invalid.invalid Tue Jan 20 10:45:52 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jan 2009 15:45:52 GMT Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: Roy Smith wrote: > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. > The reason for that is if at some point in the future you change your > mind and decide to re-build the database in setUp() for each test, you > just have to change setUp(), not touch the individual test cases. Or you could use a class attribute to save the database connection. Set it up the first time the test runs but on subsequent tests just use the saved values. If you have tests spread across separate files you could even set up the database connection in a base class and so it only gets created once across any number of test suites. This has the advantage that your test will work even if not invoked as the main script. Putting the setup code inside name=='__main__' will break as soon as you have multiple test files. -- Duncan Booth http://kupuguy.blogspot.com From python.list at tim.thechases.com Tue Jan 20 10:47:16 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Jan 2009 09:47:16 -0600 Subject: How to get first/last day of the previous month? In-Reply-To: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> References: <21e83283-f301-490c-b931-d15a85122ffc@k36g2000pri.googlegroups.com> Message-ID: <4975F204.3070201@tim.thechases.com> > You told me to think how to get the first day of the previous month, > well how to know if the previous month is 28, 29, 30 or 31 days? Find the first day of the *current* month, and then subtract one day (use the timedelta object). You'll end up with the last day of the previous month as a date/datetime object. -tkc From blank at empty.blank Tue Jan 20 10:57:52 2009 From: blank at empty.blank (RGK) Date: Tue, 20 Jan 2009 10:57:52 -0500 Subject: file write collision consideration Message-ID: I have a thread that is off reading things some of which will get written into a file while another UI thread manages input from a user. The reader-thread and the UI-thread will both want to write stuff to the same output file. What first comes to mind is that there may be write collisions, ie both trying to write at the same time. Should I do something like: if busyFlag: while busyFlag: sleep(10) else: busyFlag = True {write stuff to file} busyFlag = False in both threads? Is there some other approach that would be more appropriate? Thanks in advance for your advice - Ross. From jeff at jmcneil.net Tue Jan 20 11:01:18 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 20 Jan 2009 08:01:18 -0800 (PST) Subject: Doubts related to subprocess.Popen() References: <871vuym9gm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <9abac68c-d19d-484f-99e9-df7580050c43@z28g2000prd.googlegroups.com> On Jan 20, 9:19 am, srinivasan srinivas wrote: > Do parent process will have different file descriptor in it for each subprocesses or paprent uses a single file descriptor for all? > I really want to know creation of each subprocess will occupy an entry in parents'file descriptor table. B'cos if i create more than 200 subprocesses, i am getting 'Too many open files' error. > > Thanks, > Srini > > ----- Original Message ---- > From: Mark Wooding > To: python-l... at python.org > Sent: Tuesday, 20 January, 2009 6:16:17 PM > Subject: Re: Doubts related to subprocess.Popen() > > srinivasan srinivas writes: > > > Does subprocess.Popen() count a new open file for each suprocess? I > > mean does it occupy an entry in file descriptor table of parent > > process? If so, wat is each file descriptor connected to? > > On Unix, subprocess.Popen will use up a file descriptor in the parent > for each use of subprocess.PIPE. The descriptor in question is one end > of a pipe; the child process holds the other end. > > I guess the situation is similar on Windows, but I don't know for sure. > > -- [mdw] > --http://mail.python.org/mailman/listinfo/python-list > > Add more friends to your messenger and enjoy! Go tohttp://messenger.yahoo.com/invite/ Have you upped your open files limit? My test script: import subprocess procs = [] for i in xrange(400): procs.append(subprocess.Popen("/bin/cat", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)) By default, 'ulimit -n' returns 1024, which is the number of open files allowed. Running the test script without changing it results in: Traceback (most recent call last): File "test.py", line 9, in stderr=subprocess.PIPE)) File "/usr/lib/python2.5/subprocess.py", line 593, in __init__ errread, errwrite) File "/usr/lib/python2.5/subprocess.py", line 1002, in _execute_child errpipe_read, errpipe_write = os.pipe() OSError: [Errno 24] Too many open files Now, up that limit to 8192 via ulimit -n, and run the script again: [root at marvin jeff]# ulimit -n 8192 [root at marvin jeff]# python test.py [root at marvin jeff]# HTH, Jeff From darcy at druid.net Tue Jan 20 11:08:46 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 20 Jan 2009 11:08:46 -0500 Subject: file write collision consideration In-Reply-To: References: Message-ID: <20090120110846.8a30c93f.darcy@druid.net> On Tue, 20 Jan 2009 10:57:52 -0500 RGK wrote: > I have a thread that is off reading things some of which will get > written into a file while another UI thread manages input from a user. > > The reader-thread and the UI-thread will both want to write stuff to the > same output file. What first comes to mind is that there may be write > collisions, ie both trying to write at the same time. Why not create a third thread that handles the write? The other threads can simply add objects to a queue. You will still need collision handling in the queue adder but it only needs to block for a small time as opposed to the much longer disk write time. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From google at mrabarnett.plus.com Tue Jan 20 11:10:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 16:10:21 +0000 Subject: file write collision consideration In-Reply-To: References: Message-ID: <4975F76D.6000006@mrabarnett.plus.com> RGK wrote: > I have a thread that is off reading things some of which will get > written into a file while another UI thread manages input from a user. > > The reader-thread and the UI-thread will both want to write stuff to the > same output file. What first comes to mind is that there may be write > collisions, ie both trying to write at the same time. > > Should I do something like: > > > if busyFlag: > while busyFlag: > sleep(10) > else: > busyFlag = True > {write stuff to file} > busyFlag = False > > > in both threads? Is there some other approach that would be more > appropriate? > > Thanks in advance for your advice > If you're using the threading module, I suggest you look at the threading.RLock class: my_lock = threading.RLock() ... with my_lock: {write stuff to file} or, if you're using an older version of Python: my_lock = threading.RLock() ... my_lock.acquire() {write stuff to file} my_lock.release() From jaomatos at gmail.com Tue Jan 20 11:14:17 2009 From: jaomatos at gmail.com (=?utf-8?q?Jos=C3=A9_Matos?=) Date: Tue, 20 Jan 2009 16:14:17 +0000 Subject: Possible bug in Tkinter - Python 2.6 In-Reply-To: References: Message-ID: <200901201614.17722.jaomatos@gmail.com> On Monday 19 January 2009 09:24:09 Eric Brunel wrote: > This is not the procedure I describe in the original post. The first time, > ? it works for me too. It's only after I used the file dialog that it stops > working. You are right, my mistake. -- Jos? Ab?lio From james at agentultra.com Tue Jan 20 12:29:17 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 20 Jan 2009 12:29:17 -0500 Subject: Pyro deadlock References: <71ed81f9-7d95-44bc-8ad0-3c8e5869cb43@v5g2000pre.googlegroups.com> Message-ID: <85fxjdubrm.fsf@dozer.localdomain> MatthewS writes: > I'd like to know if the following behavior is expected and can be > avoided: I have a Pyro server object that maintains a queue of work, > and multiple Pyro worker objects that take work off the queue by > calling a method on the server (get_work) and then return the work to > the server by calling another method (return_result). > > The problem is that I experience a deadlock condition in the > return_result method. > > Is this deadlock expected or should Pyro be able to synchronize the > remote calls to server's callback method when called from multiple > workers at the same time? If so any hints are appreciated. > > /Matthew Depends on how you're implementing the work/result queues. The Queue module is a good start. From mdw at distorted.org.uk Tue Jan 20 12:29:48 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 17:29:48 +0000 Subject: Doubts related to subprocess.Popen() References: <6tluuqFbkbquU1@mid.uni-berlin.de> Message-ID: <87ab9llwc3.fsf.mdw@metalzone.distorted.org.uk> "Diez B. Roggisch" writes: > Usually, each new process has three file-descriptors associated with > it - stdin,stdout and stderr. > > So when you span a process, the overall count of FDs should increase > by three. Yes, but that's irrelevant. There are two file limits which are relevant: * the per-process limit on file descriptors -- basically, the largest number which can be a file descriptor -- and * the overall number of files which can be open at a time. Note that, in Unix, the same file can be referred to by many different descriptors in many different processes, and fork(2), exec(2) and dup(2) don't change the number of files open. However, dup(2) allocates a new descriptor in the calling process, so it may hit the per-process limit. > Additionally, there are more FDs created if you chose to pipe > communication between the child-process and the parent. And these are the ones I mentioned. OK, in more detail: each pipe(2) call allocates two files (one for each end) and two file descriptors (one for each file). If you call Popen with PIPE specified for each of stdin, stdout and stderr, then that's a total of six descriptors and six files. But the parent will close half of them after calling fork(2) (freeing three descriptors), and the child will close all six after dup2(2)-ing them over the descriptors 0, 1, and 2. The net result is: * six new files in the global file table, and * three new descriptors in the parent. (The child ends up with no new descriptors at the end of all this.) -- [mdw] From mdw at distorted.org.uk Tue Jan 20 12:41:21 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 17:41:21 +0000 Subject: ifconfig in python References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> Message-ID: <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> "RasikaSrinivasan at gmail.com" writes: > one way to get your head around this is - IP Addresses are associated > with the interface and not the computer. distinction may be subtle but > critical. Actually this is wrong for most Unix systems, which use the `weak end-system model' described in RFC1122. Weak end-systems accept IP packets sent to any of the host's addresses (and respond to ARP requests for any address) arriving on any of its interfaces, and might send a packet from any of the host's addresses out of any interface. It's best to think of the addresses as referring to the host, and not the interfaces. That doesn't mean that you can get away with a single address for the entire host, though: you need addresses which correspond to the networks you're attached to. -- [mdw] From vivacarlie at gmail.com Tue Jan 20 12:48:09 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Tue, 20 Jan 2009 11:48:09 -0600 Subject: ifconfig in python In-Reply-To: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <65fadfc30901200948o5aa8aa51xbf6e12b176230a9a@mail.gmail.com> I'll let this thought fester but I thought I'd put together a PEP to make this a function. Possibly in some util library but preferibly in the sys library sense this is where to get information about the system you are running on. On Tue, Jan 20, 2009 at 6:33 AM, Mark Wooding wrote: > ?????? ??????????? writes: > > > Something *like* this could work: > > > > myip = urllib2.urlopen('http://whatismyip.org/').read( > ) > > This is going to cause all manner of problems. > > Firstly, many users are stuck behind NAT routers. In this case, the > external service will report the address of the router, which is > probably useless -- certainly it will be for programs attempting to > communicate over a LAN. > > Secondly, imagine the joy when overzealous ISPs decide that > whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last > month): then the service will report the address of ISP's censoring > proxy to thousands of otherwise unrelated users. > > And that's before we get onto onion routers like Tor... > > Here's an idea which might do pretty well. > > In [1]: import socket as S > In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM) > In [4]: s.connect(('192.0.2.1', 666)) > In [5]: s.getsockname() > Out[5]: ('172.29.198.11', 46300) > > (No packets were sent during this process: UDP `connections' don't need > explicit establishment. The network 192.0.2.0/24 is reserved for use in > examples; selecting a local address should therefore exercise the > default route almost everywhere. If there's a specific peer address or > network you want to communicate with, use that address explicitly.) > > I have to wonder what the purpose of this is. It's much better to have > the recipient of a packet work out the sender's address from the packet > (using recvfrom or similar) because that actually copes with NAT and so > on properly. > > -- [mdw] > -- > http://mail.python.org/mailman/listinfo/python-list > -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From georgegrimes at ti.com Tue Jan 20 13:01:54 2009 From: georgegrimes at ti.com (Grimes, George) Date: Tue, 20 Jan 2009 12:01:54 -0600 Subject: Problem with IDLE on windows XP In-Reply-To: References: <2C1563023E232C49B9F505633D57C2DA128CB08B69@dlee04.ent.ti.com> Message-ID: <2C1563023E232C49B9F505633D57C2DA12928A325C@dlee04.ent.ti.com> ?Muchas gracias! That was the hint that I needed, Gabriel. I had a problem with my path definition and running idle the way you indicated gave me an error message saying that it could not find a valid init.tcl on the path. I have fixed the problem and can now run idle at work. Thanks again! George George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell Failure is the opportunity to begin again, more intelligently. Henry Ford -----Original Message----- From: python-list-bounces+georgegrimes=ti.com at python.org [mailto:python-list-bounces+georgegrimes=ti.com at python.org] On Behalf Of Gabriel Genellina Sent: Tuesday, January 20, 2009 9:33 AM To: python-list at python.org Subject: Re: Problem with IDLE on windows XP En Mon, 19 Jan 2009 20:50:43 -0200, Grimes, George escribi?: > I am trying to learn Python and I installed version 2.6 both at home and > at work. At home, on > Vista, everything works fine. At work, on XP, IDLE would not run. I > uninstalled/reinstalled > and got the same thing. My cursor changes to the wait symbol for a few > seconds, then goes > back to normal and ?.nothing. The Task Manager shows nothing. I > uninstalled again, > made sure all the files were deleted from the disk, used regedit to > delte every registry entry > that had python in it and tried version 3.0. > > Geuss, what? I still can?t run IDLE on XP? Is this a common problem? > Or am I unique? Did you install "for all users" (as Administrator) or "just for me"? The following instructions assume you installed Python 2.6 on C:\Python26 -- replace with your own directory if different. Open a command prompt (go to Start, Run, type "cmd" and press Enter). At the > prompt type: c:\Python26\python -V and press Enter. Should reply with the Python version. Then try with: c:\Python26\python c:\Python26\Lib\idlelib\idle.pyw Should start IDLE, probably you get some error message; post it here. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From vivacarlie at gmail.com Tue Jan 20 13:04:04 2009 From: vivacarlie at gmail.com (Nehemiah Dacres) Date: Tue, 20 Jan 2009 12:04:04 -0600 Subject: ifconfig in python In-Reply-To: <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> References: <8763kama2b.fsf.mdw@metalzone.distorted.org.uk> <10cfe864-a1bc-4beb-ad4b-0fc4aca7d8da@r27g2000vbp.googlegroups.com> <8763k9lvsu.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <65fadfc30901201004of5e9a17mc06dc0b09dbe7a1b@mail.gmail.com> > > That doesn't mean that you can get away with a single address for the > entire host, though: you need addresses which correspond to the networks > you're attached to. > > -- [mdw] especially sense we are also getting into virtual NICs where you can have a webserver listening to one and broadcasting a stream to another. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 -------------- next part -------------- An HTML attachment was scrubbed... URL: From raf at gtn.ru Tue Jan 20 13:05:34 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:05:34 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568375.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568375p21568375.html Sent from the Python - python-list mailing list archive at Nabble.com. From kdawg44 at gmail.com Tue Jan 20 13:07:46 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 13:07:46 -0500 Subject: Overloading Methods Message-ID: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From raf at gtn.ru Tue Jan 20 13:09:12 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:09:12 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568438.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568438p21568438.html Sent from the Python - python-list mailing list archive at Nabble.com. From raf at gtn.ru Tue Jan 20 13:09:31 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:09:31 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568445.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568445p21568445.html Sent from the Python - python-list mailing list archive at Nabble.com. From bedouglas at earthlink.net Tue Jan 20 13:12:33 2009 From: bedouglas at earthlink.net (bruce) Date: Tue, 20 Jan 2009 10:12:33 -0800 Subject: ifconfig in python In-Reply-To: <65fadfc30901201004of5e9a17mc06dc0b09dbe7a1b@mail.gmail.com> Message-ID: <08d601c97b2a$ab8f54f0$0301a8c0@tmesa.com> so the question really starts to look like: -what's the default listening address for my app (insert nic)? -what's the default sending address for my app (insert nic)? -what's the default listening address for my server? -what's the default sending address for my server? -what's the default listening address for my (insert nic)? -what's the default sending address for my (insert nic)? any other possibilities?? -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Nehemiah Dacres Sent: Tuesday, January 20, 2009 10:04 AM To: Mark Wooding Cc: python-list at python.org Subject: Re: ifconfig in python That doesn't mean that you can get away with a single address for the entire host, though: you need addresses which correspond to the networks you're attached to. -- [mdw] especially sense we are also getting into virtual NICs where you can have a webserver listening to one and broadcasting a stream to another. -- "lalalalala! it's not broken because I can use it" http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 From castironpi at gmail.com Tue Jan 20 13:14:21 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 20 Jan 2009 10:14:21 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> Message-ID: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> On Jan 17, 6:10?pm, The Music Guy wrote: > Wow, impressive responses. > > It sounds like the general consensus is that English would not be a good > choice for programming even if there were an interpreter capable of > turning human language into machine language. But that makes sense; even > English professionals have trouble understanding each other sometimes. > Until that problem is somehow overcome, there's not much hope of > computers to overcome it. I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. f "abc" 123 --> f( "abc", 123 ) It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. From raf at gtn.ru Tue Jan 20 13:17:06 2009 From: raf at gtn.ru (metro5) Date: Tue, 20 Jan 2009 10:17:06 -0800 (PST) Subject: Free-test russian xxx site Message-ID: <21568578.post@talk.nabble.com> Free-test russian xxx site http://xxx.gamapa.ru http://xxx.gamapa.ru -- View this message in context: http://www.nabble.com/Free-test-russian-xxx-site-tp21568578p21568578.html Sent from the Python - python-list mailing list archive at Nabble.com. From google at mrabarnett.plus.com Tue Jan 20 13:18:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 18:18:48 +0000 Subject: Overloading Methods In-Reply-To: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> Message-ID: <49761588.604@mrabarnett.plus.com> K-Dawg wrote: > Can you overload methods in Python? > > Can I have multiple __inits__ with different parameters passed in? > Simple answer: no. From gert.cuykens at gmail.com Tue Jan 20 13:31:19 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 10:31:19 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> Message-ID: On Jan 20, 5:23?am, John Machin wrote: > On Jan 20, 12:54?pm, gert wrote: > > > How do you convert s back to binary data in python 3 so I can put in a > > sqlite blob ? > > Is there a build in function or do I need to use binascii ? > > byte(s) or bin(s) would make more sense but can not figure it out ? > > Can't imagine why you would do str(binary_data) especially if you want > it back again ... however: def application(environ, response): s = str(environ['wsgi.input'].read()) b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group (1) p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) db.execute('UPDATE users SET picture=? WHERE uid=?', (p,session.UID)) > According to the fabulous manual: > > str([object[, encoding[, errors]]]) > Return a string version of an object, using one of the following > modes: > [snip] > When only object is given, this returns its nicely printable > representation. For strings, this is the string itself. The difference > with repr(object) is that str(object) does not always attempt to > return a string that is acceptable to eval(); its goal is to return a > printable string. > > Hmm looks like (1) we need to do the dreaded eval() and (2) there's no > guarantee it will work. > > >>> for i in range(256): > > ... ? ?blob = bytes([i]) > ... ? ?if eval(str(blob)) != blob: > ... ? ? ? print(i, blob, str(blob), eval(str(blob))) > ... > > >>> # no complaints! > > Looks like it's going to work, but you better be rather sure that you > trust the source. Any other suggestions ? From blank at empty.blank Tue Jan 20 13:39:54 2009 From: blank at empty.blank (RGK) Date: Tue, 20 Jan 2009 13:39:54 -0500 Subject: file write collision consideration In-Reply-To: References: Message-ID: Thanks for the suggestions - sounds like a couple good options, I apprecieate it. Ross. MRAB wrote: > RGK wrote: >> I have a thread that is off reading things some of which will get >> written into a file while another UI thread manages input from a user. >> >> The reader-thread and the UI-thread will both want to write stuff to >> the same output file. What first comes to mind is that there may be >> write collisions, ie both trying to write at the same time. >> >> Should I do something like: >> >> >> if busyFlag: >> while busyFlag: >> sleep(10) >> else: >> busyFlag = True >> {write stuff to file} >> busyFlag = False >> >> >> in both threads? Is there some other approach that would be more >> appropriate? >> >> Thanks in advance for your advice >> > If you're using the threading module, I suggest you look at the > threading.RLock class: > > my_lock = threading.RLock() > ... > with my_lock: > {write stuff to file} > > or, if you're using an older version of Python: > > my_lock = threading.RLock() > ... > my_lock.acquire() > {write stuff to file} > my_lock.release() From clp2 at rebertia.com Tue Jan 20 13:41:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jan 2009 10:41:24 -0800 Subject: Overloading Methods In-Reply-To: <49761588.604@mrabarnett.plus.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > K-Dawg wrote: >> >> Can you overload methods in Python? >> >> Can I have multiple __inits__ with different parameters passed in? >> > Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload methods in Python since you can use default and keyword arguments instead. For instance: class Foo(object): def __init__(self, a, b=10, c=None): self.a = a self.b = b if c is None: c = [] self.c = c #example use x = Foo("#", 4, [6,7]) y = Foo("@") z = Foo("!", c=[1,2]) Whereas in Java or C++ this would require several overloads, it can be succinctly expressed as a single method in Python. However, if you want the overloads to accept completely different types as parameters, then it arguably should expressed as distinct methods rather than "overloads". In the special case of __init__, you might want to make the alternate initializers classmethods or factory functions. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bockman at virgilio.it Tue Jan 20 13:53:58 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Tue, 20 Jan 2009 19:53:58 +0100 Subject: file write collision consideration References: Message-ID: On Tue, 20 Jan 2009 11:08:46 -0500, D'Arcy J.M. Cain wrote: > On Tue, 20 Jan 2009 10:57:52 -0500 > RGK wrote: >> I have a thread that is off reading things some of which will get >> written into a file while another UI thread manages input from a user. >> >> The reader-thread and the UI-thread will both want to write stuff to the >> same output file. What first comes to mind is that there may be write >> collisions, ie both trying to write at the same time. > > Why not create a third thread that handles the write? The other > threads can simply add objects to a queue. You will still need > collision handling in the queue adder but it only needs to block for a > small time as opposed to the much longer disk write time. IIRC, Queue.Queue objects handle by themselves multi-thread access, that is there is no need to additional locking mechanism ... Ciao --- FB From BrooklineTom at gmail.com Tue Jan 20 13:55:47 2009 From: BrooklineTom at gmail.com (brooklineTom) Date: Tue, 20 Jan 2009 10:55:47 -0800 (PST) Subject: SetUp functions for multiple test cases References: <45b0bf56-673c-40cd-a27a-62f9943d9f1a@r41g2000prr.googlegroups.com> Message-ID: <67ada713-c90a-44b8-8928-3b411ccef5c6@i24g2000prf.googlegroups.com> On Jan 20, 9:57 am, Roy Smith wrote: > In article > <45b0bf56-673c-40cd-a27a-62f9943d9... at r41g2000prr.googlegroups.com>, > Georg Schmid wrote: > > > I've just started working with unittests and already hit a snag. I > > couldn't find out how to implement a setup function, that is executed > > only _once_ before all of the tests. Specifically, I need this for > > testing my database interface, and naturally I don't want to create a > > new database in-memory and fill it with example data for every single > > test case. > > Short answer -- there's no way to do it in the unittest framework. > > The True Unit Test Zealots will argue that all tests should be 100% > independent of each other, which means there should be NO common state > between test cases. For that matter, they will also argue that unit tests > should not interface with external resources like databases. And they're > right. > > On the other hand, the Real World Test Pragmatists will argue that this is > just not practical in all cases. Real programs have classes which interact > with the outside world, and they need to get tested. You could stub out > the external resource, but that's a lot of work, and may introduce as many > problems as it solves. Sometimes, a big part of what you're testing is > your understanding of the external world (i.e. "does this really work like > it's documented?"). > > Plus, some operations are just too expensive to do for every test case. I > don't know how long it takes to build your in-memory database. If it takes > one second, it probably makes sense to do it for every test case (unless > you've got thousands of test cases). If it takes 10 minutes, then it makes > sense to do it once and deal with the fact that you're violating True Unit > Test Dogma. > > Anyway, do what I do. I run the tests with a: > > if __name__ == "__main__": > blah blah > > block at the bottom of the test file. Just do your "do once" setup in that > code block and store the result in a global. > > You might have your setUp() method re-assign the global to an instance > variable and then your test cases can access it via self.whatever. The > reason for that is if at some point in the future you change your mind and > decide to re-build the database in setUp() for each test, you just have to > change setUp(), not touch the individual test cases. I believe that the answer sought by the OP is the TestResource class from the original Smalltalk unit test. Sadly, the various language- specific clones -- including the Python unittest package -- followed the example of the JUnit hack, which elided this (for a variety of reasons, some good, some bad). There are two major obstacles in moving SUnit from Smalltalk to Python: (1) SUnit takes full advantage of class objects which still have only vestigial implementations in Python, and (2) SUnit takes full advantage of Smalltalk's restartable exception semantics. I've implemented an alternative unit test package, but I requires the rest of my framework (which addresses the above two restrictions) and is therefore not yet ready for prime time. The basic theme of TestResource is simple enough, once the rest of the unit test framework is properly factored: 1. Tests always run within an instance of TestSuite. 2. The "run" method of test suite (with no arguments) collects and creates whatever resources are needed by the tests within it. 3. The run method creates an instance of TestResult to collect the results. 4. Each TestCase instance collects whatever (existing) resources it needs. 5. When the "run" method (in step 2 above) finishes, all resources are finalized. Instances of TestResource have a "setUp" and "tearDown" method, just like TestCase. These are called once, at steps 2 and 5 above. I built my test frame from the original SUnit from KentBeck et al and used an excellent reference Joseph Pelrine (http://www.metaprog.com/ ESUG/TestResources.pdf) to guide my work. From joe at strout.net Tue Jan 20 13:58:46 2009 From: joe at strout.net (Joe Strout) Date: Tue, 20 Jan 2009 11:58:46 -0700 Subject: English-like Python In-Reply-To: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <49761EE6.4070306@strout.net> Aaron Brady wrote: > I think it would be a good step if you could make some sensible > interpretation of a typical statement without its parentheses. > > f "abc" 123 > --> > f( "abc", 123 ) > > It would be just the thing in a couple of situations... Such a language is possible -- take a look at REALbasic sometime. RB certainly has its problems (mainly bugs), but the language syntax is beautiful. To your point, parentheses are not required around any method call that (1) has no return value, or (2) requires no parameters. Example: LogError "Walk has gotten too silly", CurrentTime Here, LogError is a method call that takes two arguments, and CurrentTime is a method call that takes none. Your "f" example above works fine in RB too, though with such an abstract example it's a little hard to see why it's so cool. Eliminating unnecessary parentheses does a lot to improve the readability of the code IMHO. Cheers, - Joe From Russ.Paielli at gmail.com Tue Jan 20 14:04:20 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 11:04:20 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> On Jan 20, 5:33 am, Luis Zarrabeitia wrote: > On Tuesday 20 January 2009 05:00:34 am Paul Rubin wrote: > > > Luis Zarrabeitia writes: > > > No wonder you can't get Bruno's point. For the second, static checks > > > to prevent accidents, you have pylint. For the first, not only you > > > are using the wrong tool, but you are barking at python for not > > > having it. Assuming that pylint is perfect (big assumption, but it > > > is up to you to prove where it fails), > > > Whaat? Assuming a program is perfect unless a failure is proven > > is not at all a sane approach to getting reliable software. It is > > the person claiming perfection who has to prove the absence of failure. > > No, no. I meant that if pylint works as its specification says it would. > > Russ says (or seems to say, I don't know, I'm confused already) that it is not > good enough, that what pylint says it does is not what he wants (otherwise, > this subthread would have died a long time ago). So, assuming that pylint > works as specified (its up to "you" to find out if it doesn't and file > bugreports about it, just like you would do if you find out that the > static-checker for your enforced-static-checks-language is buggy), what > would be the difference between only accepting/running "pylint-authorized > code" and the enforced hiding you desire? > > Sorry, I didn't realize that perfect was a too strong word for that. "I speaks > english bad" :D > > Cya! > > -- > Luis Zarrabeitia (aka Kyrie) > Fac. de Matem?tica y Computaci?n, UH.http://profesores.matcom.uh.cu/~kyrie Hey, if pylint can reliably detect private data access violations, that's good news to me. I haven't used it, so I don't know. (I used pychecker a while back, but I haven't used that for a while either.) If pylint can check access violations, then it seems to me that someone (who is familiar with the internals of the Python interpreter) should be able to integrate that feature into Python itself relatively easily. Actually, in addition to the enforcement of "private," you also need the enforcement of "protected." If you only enforce "private," derived classes will not have access to data they need. And if you don't enforce "protected," then anyone can trivially gain access to private data by simply deriving a new class. It would be like having a lock on the door with the key hanging right there on a string. I realize that this complicates matters. As I said before, I am not claiming that Python should necessarily get enforced data hiding. All I am saying is that, if it doesn't get it, it will never be appropriate for certain domains. But maybe nobody cares about that except me. The other problem with the pylint approach is aesthetic: the requirement for a leading underscore to indicate private data. I realize that some actually like that convention, but I don't. I spend most of my development time working with "private" data, and why should I have to look at that litter everywhere? I use Python in part because I want clean looking code, and leading underscores bother me -- just as the leading dollar signs in Perl bother many Python programmers. From sjmachin at lexicon.net Tue Jan 20 14:06:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 11:06:22 -0800 (PST) Subject: How to get first/last day of the previous month? References: <6Nldl.1258$8Z.845@tornado.fastwebnet.it> Message-ID: On Jan 21, 2:07?am, Marco Mariani wrote: > Carsten Haese wrote: > > In order to not deprive you of the sense of accomplishment > > Sorry for spoiling that. If you still want the sense of accomplishment, > try to reimplement dateutil (and rrule). It's not as easy as it seems :-o True, but getting the last day of a given month from first principles without any library routines is nowhere near as complex as (e.g.) converting (y,m,d) <-> ordinal day number. It's this easy: # days in month (non-leap year) _dim = (None, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) def _leap(y): if y % 4: return 0 if y % 100: return 1 if y % 400: return 0 return 1 def last_day_of_month(y, m): """Return day (1..31) which is last day of month m in year y """ if m == 2: return 28 + _leap(y) if not (1 <= m <= 12): raise Exception("month not in 1..12") return _dim[m] Cheers, John From joefazee at gmail.com Tue Jan 20 14:06:54 2009 From: joefazee at gmail.com (Abah Joseph) Date: Tue, 20 Jan 2009 11:06:54 -0800 Subject: English-like Python In-Reply-To: <49761EE6.4070306@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: Python is English-like enough that everybody including non-programmers can understand it.e.g # Import the operating system module import os # define new function def open_dir_tree(path): for File in os.listdir(path): file_or_dir = os.path.join(path, File) # Read the line below, this is almost full english language if os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir): open_dir_tree(file_or_dir) else: print file_or_dir open_dir_tree(".") -- I develop dynamic website with PHP & MySql, Let me know about your site -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Tue Jan 20 14:21:47 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Wed, 21 Jan 2009 00:51:47 +0530 Subject: python resource management In-Reply-To: <13A9CCF8-75E3-43D6-B43F-87B9C5F6296C@sas.com> References: <13A9CCF8-75E3-43D6-B43F-87B9C5F6296C@sas.com> Message-ID: On Tue, Jan 20, 2009 at 7:27 PM, Tim Arnold wrote: > I had the same problem you did, but then I changed the code to create a new > soup object for each file.That drastically increased the speed. I don't > know why, but it looks like the soup object just keeps getting bigger with > each feed. > > --Tim > > I have found the actual solution for this problem. I tried using *BeautifulSoup.SoupStrainer()* and it improved memory usage to the greatest extent.Now it uses max of 20 MB(earlier it was >800 MB on 1GB RAM system). thanks all. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Tue Jan 20 14:30:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 20 Jan 2009 11:30:46 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> On Jan 20, 12:58?pm, Joe Strout wrote: > Aaron Brady wrote: > > I think it would be a good step if you could make some sensible > > interpretation of a typical statement without its parentheses. > > > f "abc" 123 > > --> > > f( "abc", 123 ) > > > It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. ?RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. ?To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > ? Example: > > ? LogError "Walk has gotten too silly", CurrentTime > > Here, LogError is a method call that takes two arguments, and > CurrentTime is a method call that takes none. > > Your "f" example above works fine in RB too, though with such an > abstract example it's a little hard to see why it's so cool. > > Eliminating unnecessary parentheses does a lot to improve the > readability of the code IMHO. > > Cheers, > - Joe Unambiguity and readability are two different things. (This should be a quasi-tangent, neither agreed, nor opposed, nor unrelated to what you said.) If you have f "abc" 123 it's unambiguous, but, if you have g f "abc" 123 "def" there's no sure way to determine where the call to 'f' stopped, and the one to 'g' resumed (or, as in Python, if 'f' was even to be called at all, as opposed to 4 parameters to 'g'). If you allow commas, you can make some progress, though I don't have a rigorous formula. But, for example, g f "abc", 123 "def" can only mean: g( f( "abc", 123 ), "def" ) But something tells me it doesn't extend, especially since commas are used elsewhere than function calls. And certainly, it's not readable at a glance. English has that problem and kind of glaringly, by the way. You don't always know how the speaker's subordinate clauses are nesting. Not just with clauses, but modifiers, as in "The Purple People Eater". So I don't know how you expect to design a programming language after it. From mdw at distorted.org.uk Tue Jan 20 14:31:43 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 19:31:43 +0000 Subject: ifconfig in python References: Message-ID: <871vuxkc4g.fsf.mdw@metalzone.distorted.org.uk> "bruce" writes: [a top-posted monstrosity] > so the question really starts to look like: > > -what's the default listening address for my app (insert nic)? > -what's the default sending address for my app (insert nic)? > -what's the default listening address for my server? > -what's the default sending address for my server? > -what's the default listening address for my (insert nic)? > -what's the default sending address for my (insert nic)? > > any other possibilities?? A TCP server will typically listen on: * all addresses (INADDR_ANY), * localhost (INADDR_LOOPBACK), or * an address explicitly provided by the administrator. (There's a fourth possibility: it might listen separately on each network interface, but that's quite unusual.) Anyway, it ought to know which of these it's doing. When a client connects, it gets the client's address from accept(2) or getpeername(2) and its local address from getsockname(2). A TCP client can find out its address using getsockname(2) after connect(2). So that's easy too. But TCP isn't very interesting here, because both ends know the others' address by the time the connection is established, so there's no point in explicitly sending them. (I suppose you could use explicit addresses to detect NAT routers which aren't doing protocol-specific bodging.) UDP is much messier, since a single socket could be acting as a client or server, or in a strictly symmetrical arrangement. Even so, it's usually much better to have the hosts concerned dredge out their peers' addresses from the packets they receive rather than send them about explicitly. Which is why I'm puzzled as to what this information is actually for. -- [mdw] From joe at strout.net Tue Jan 20 15:08:46 2009 From: joe at strout.net (Joe Strout) Date: Tue, 20 Jan 2009 13:08:46 -0700 Subject: English-like Python In-Reply-To: <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> Message-ID: <49762F4E.1000506@strout.net> Aaron Brady wrote: > Unambiguity and readability are two different things. (This should be > a quasi-tangent, neither agreed, nor opposed, nor unrelated to what > you said.) > > If you have > > f "abc" 123 > > it's unambiguous, but, if you have > > g f "abc" 123 "def" > > there's no sure way to determine where the call to 'f' stopped, and > the one to 'g' resumed (or, as in Python, if 'f' was even to be called > at all, as opposed to 4 parameters to 'g'). Right -- that's exactly why (in RB) parentheses are required around arguments to a method call if that method returns a value (in RB terms, if it is a function rather than a subroutine). Then there is no ambiguity, because only such a function can be used as an argument to another method call (or otherwise be part of an expression). The above would have to be written something like: g f("abc", 123), "def" I'm not saying I know how to translate this into Python -- some of Python's other language features make this difficult. Just pointing out that your original wish is possible in at least some languages. Best, - Joe From catphive at catphive.net Tue Jan 20 15:13:15 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 12:13:15 -0800 Subject: what's the point of rpython? In-Reply-To: <7xfxje8akd.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 3:46 AM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > skip at pobox.com writes: >> Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have >> read what you saw but not recognized it in the C++ punctuation soup. I >> couldn't find what you referred to. Can you provide a URL? > > http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety I think you are misreading that. It says that multiple assignments to different copies of a share_ptr in different threads are fine. This is the important bit because copies of the same pointer share the same reference count, and assignments and resets will decrement that ref count. They say they don't handle mutations of the *same* pointer in different threads, which is a different issue. The programmer is responsible for synchronizing access to the pointer, and the pointed to object, but not the ref count. This may be not be obvious if you don't use shared_ptr a lot. You also mentioned in an earlier post that most processors don't support automic increments... I'm hesitant to dispute you here because this is outside of my field of expertise. However, a quick google search for "x86 atomic increment" comes up with this: XADD http://www.codemaestro.com/reviews/8 http://siyobik.info/index.php?module=x86&id=159 Again, I'm not an assembly guru, but his sounds like exactly what you'd want. It gains exclusive access to system memory in a multi-processor environtment without leaving user space. Thus XADD is an atomic increment/decrement. It would be educational if someone more famliar with x86 than me could speak to the performance merits of this on modern multicore machines. From rhamph at gmail.com Tue Jan 20 15:18:09 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:18:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: On Jan 20, 12:04?pm, "Russ P." wrote: Hey, if pylint can reliably detect private data access violations, > that's good news to me. I haven't used it, so I don't know. (I used > pychecker a while back, but I haven't used that for a while either.) > > If pylint can check access violations, then it seems to me that > someone (who is familiar with the internals of the Python interpreter) > should be able to integrate that feature into Python itself relatively > easily. > > Actually, in addition to the enforcement of "private," you also need > the enforcement of "protected." If you only enforce "private," derived > classes will not have access to data they need. And if you don't > enforce "protected," then anyone can trivially gain access to private > data by simply deriving a new class. It would be like having a lock on > the door with the key hanging right there on a string. > > I realize that this complicates matters. As I said before, I am not > claiming that Python should necessarily get enforced data hiding. All > I am saying is that, if it doesn't get it, it will never be > appropriate for certain domains. But maybe nobody cares about that > except me. If pylint had "private" it should behave like "protected". Basic encapsulation is about good style (separation of concerns), not security, and subclassing is a clear statement that this concern is closely related. Of course if you accept that the extremism of security is a separate issue then you have the question of how much is necessary to encourage separation of concerns, and and what should be available to work around it... > The other problem with the pylint approach is aesthetic: the > requirement for a leading underscore to indicate private data. I > realize that some actually like that convention, but I don't. I spend > most of my development time working with "private" data, and why > should I have to look at that litter everywhere? I use Python in part > because I want clean looking code, and leading underscores bother me > -- just as the leading dollar signs in Perl bother many Python > programmers. There needs to be *some* indicator that separates a public property from a private one. What would you suggest? From rridge at csclub.uwaterloo.ca Tue Jan 20 15:19:39 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Tue, 20 Jan 2009 15:19:39 -0500 Subject: what's the point of rpython? References: <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: Carl Banks wrote: >I just looked at the boost documentation, which claims that multiple >asynchronous writes to the same shared_ptr results in undefined >behavior. That will not suffice for Python reference counting. If you read the Boost documentation you'll see that while multiple simulaneous writes to a shared_ptr *instance* isn't supported, multiple simulataneous updates of the reference counter used by the shared_ptr implementaiton is supported. Example #1 in the URL that Paul Rubin gave demonstrates this. The allowed simulanteous assignment of the two shared_ptr instances "p2" and "p3" from the same shared_ptr instance "p", requires that a single reference count be incremented simultenously. On the other hand, the documentation also notes that the implementation is only lock free on x86, IA-64, and PowerPC systems, though I think it would also be possible on MIPS CPUs. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From kdawg44 at gmail.com Tue Jan 20 15:19:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 15:19:45 -0500 Subject: Overloading Methods In-Reply-To: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> Message-ID: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> Can I have multiple __inits__ with different parameters passed in? > >> > > Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Tue Jan 20 15:19:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Tue, 20 Jan 2009 15:19:45 -0500 Subject: Overloading Methods In-Reply-To: <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> Message-ID: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> Can I have multiple __inits__ with different parameters passed in? > >> > > Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 20 15:34:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jan 2009 12:34:49 -0800 Subject: Overloading Methods In-Reply-To: <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> <50697b2c0901201041j1659c2fen2334b15a623a6ebd@mail.gmail.com> <5caea3690901201219h7b1dac93m97a05fcb6cc80d47@mail.gmail.com> Message-ID: <50697b2c0901201234h5d5df5ecu344aa8f6dc1b5462@mail.gmail.com> (top-posting just for consistency) In that case, you might also be interested in: http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris On Tue, Jan 20, 2009 at 12:19 PM, K-Dawg wrote: > Thank you for the explanation. With my background in Java, I have to get > myself to think a little differently. > Kevin > > > On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: >> >> On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: >> > K-Dawg wrote: >> >> >> >> Can you overload methods in Python? >> >> >> >> Can I have multiple __inits__ with different parameters passed in? >> >> >> > Simple answer: no. >> >> More complicated answer: Yes, with some caveats. >> >> You usually don't need to overload methods in Python since you can use >> default and keyword arguments instead. For instance: >> >> class Foo(object): >> def __init__(self, a, b=10, c=None): >> self.a = a >> self.b = b >> if c is None: c = [] >> self.c = c >> >> #example use >> x = Foo("#", 4, [6,7]) >> y = Foo("@") >> z = Foo("!", c=[1,2]) >> >> Whereas in Java or C++ this would require several overloads, it can be >> succinctly expressed as a single method in Python. >> >> However, if you want the overloads to accept completely different >> types as parameters, then it arguably should expressed as distinct >> methods rather than "overloads". In the special case of __init__, you >> might want to make the alternate initializers classmethods or factory >> functions. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana... >> http://rebertia.com >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Follow the path of the Iguana... http://rebertia.com From rhamph at gmail.com Tue Jan 20 15:36:11 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:36:11 -0800 (PST) Subject: what's the point of rpython? References: Message-ID: <4438eca0-ded3-4223-a80a-5ad3cc2d718d@g1g2000pra.googlegroups.com> On Jan 16, 5:37?pm, "Brendan Miller" wrote: > So I kind of wanted to ask this question on the pypy mailing list.. > but there's only a pypy-dev list, and I don't want to put noise on the > dev list. > > What's the point of RPython? By this, I don't mean "What is RPython"? > I get that. I mean, why? There are some distinct benefits of RPython: * starts up as real python code, letting you define globals that later get "snapshotted" into static code * can be executed using a real python interpreter, getting much more reliable debugging (but broken rpython code might run fine under python) * provides a clear avenue for extension, by adding more python features You might argue just having a python syntax is also a benefit, but the semantics are so different as to more than counteract it. Add in the cost of implementing your own compiler... yeah. From sjmachin at lexicon.net Tue Jan 20 15:41:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 12:41:28 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> Message-ID: <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> On Jan 21, 5:31?am, gert wrote: > On Jan 20, 5:23?am, John Machin wrote: > > > On Jan 20, 12:54?pm, gert wrote: > > > > How do you convert s back to binary data in python 3 so I can put in a > > > sqlite blob ? > > > Is there a build in function or do I need to use binascii ? > > > byte(s) or bin(s) would make more sense but can not figure it out ? > > > Can't imagine why you would do str(binary_data) especially if you want > > it back again ... however: > > def application(environ, response): > ? ? s = str(environ['wsgi.input'].read()) > ? ? b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group > (1) > ? ? p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n > (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) > ? ? db.execute('UPDATE users SET picture=? WHERE uid=?', > (p,session.UID)) > [snip] > > > Looks like it's [it being eval(str(blob))] going to work, but you better be rather sure that you > > trust the source. > > Any other suggestions ? Yeah. (a) don't write obfuscatory code :-0 E.g. (1) re.compile(pattern).search(data) -> re.search(pattern, data) (2) re.compile(pattern).match(data) -> re.match(pattern, data) (3) re.match('.*blahblah', data) -> re.search('blahblah', data) (b) don't use re when ordinary str or bytes methods will do E.g. instead of: b = re.search('boundary=(.*)'), environ['CONTENT_TYPE']).group(1) try b = environ['CONTENT_TYPE'].split('boundary=')[1] (c) Is that code meant to be rough pseudocode to illustrate what you are trying to do, or is it meant to be working code? If the latter: * Do you have this working in 2.X? * Are you sure the pattern to retrieve the picture is correct? * What is the "Content-Transfer-Encoding"? (d) Surely there must be a library somewhere that parses that kind of data for you ... (e) if all else fails, I'd suggest: instead of s = str(binary) do s = binary.decode('latin1') # this won't change the number of characters and will allow # reconstitution of your non-ascii bytes Then do your DIY parsing then at the end do blob = p.encode('latin1') # blob will be type bytes which is presumably what the database expects HTH, John From wgrigg at draper.com Tue Jan 20 15:43:27 2009 From: wgrigg at draper.com (bill) Date: Tue, 20 Jan 2009 12:43:27 -0800 (PST) Subject: python processes and Visual Studio References: <17ef3ab2-0aec-4660-921b-190a5cab45f5@r15g2000prd.googlegroups.com> Message-ID: <57d6a9d3-4a21-4d55-acdd-d0154973ccbe@r34g2000vbp.googlegroups.com> On Jan 19, 9:24?am, bill wrote: > All, > > This may sound somewhat convoluted, but here goes: > > 1. I have a Python script that invokes builds in Visual Studio via the > command line interface - 'devenv' > 2. It works GREAT > 3. I have added a post_build event to a VS Solution that has but one > project. > 4. This event invokes a Python command - 'c:\python25\python.exe c: > \....myPython.py' > 5. It works GREAT > 6. I move on the another VS Solution that has 6 projects. > 7. I add the post_build event command to all 6 projects > 8. It 'almost' works... all 6 projects build and the post_build event > triggers in all 6 projects and that works > 9. Unhappily, the whole thing then 'hangs' > > I am guessing that perhaps a sub-process or something like that is not > exiting. The Python script that is triggered in the post_build event, > myPython.py, does nothing special upon exit. Should it? > > Or, is there some way to determine why the the while thing 'hangs'? > > TIA, > > Bill All, Please ignore this post (if you already haven't). Whatever the problem is, it has absolutely nothing to do with Python. Sorry about that From bjracine at glosten.com Tue Jan 20 15:48:22 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Tue, 20 Jan 2009 12:48:22 -0800 Subject: English-like Python In-Reply-To: <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8BCB5@clipper.glosten.local> Doesn't ipython (the interactive shell) make this possible in some cases... not that's what you seem to be looking for exactly. Ben Racine -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of Aaron Brady Sent: Tuesday, January 20, 2009 10:14 AM To: python-list at python.org Subject: Re: English-like Python On Jan 17, 6:10?pm, The Music Guy wrote: > Wow, impressive responses. > > It sounds like the general consensus is that English would not be a > good choice for programming even if there were an interpreter capable > of turning human language into machine language. But that makes sense; > even English professionals have trouble understanding each other sometimes. > Until that problem is somehow overcome, there's not much hope of > computers to overcome it. I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. f "abc" 123 --> f( "abc", 123 ) It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. -- http://mail.python.org/mailman/listinfo/python-list From rhamph at gmail.com Tue Jan 20 15:52:32 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 12:52:32 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> Message-ID: <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> On Jan 19, 9:00?pm, "Brendan Miller" wrote: > Maybe I'm missing something here but a lock free algorithm for > reference counting seems pretty trivial. As long as you can atomically > increment and decrement an integer without locking you are pretty much > done. "lock free" is largely meaningless. What it really means is "we use small hardware locks rather than big software locks, thereby reducing (but not eliminating!) the contention". Atomic refcounting is easy. If done sparingly to minimize contention it works great. Python uses refcounting massively with heavily contended objects (think about your builtin types, constants, globals, classes, etc.) It does not perform acceptably for python. The second issue is the objects themselves, like a list which is mutable. If you're using it in a single thread or writing from multiple threads this is a non-trivial constant cost. If your object is not modified after creation and is read from many threads a lock would be a point of contention, preventing you from scaling freely. The dicts used by classes and globals are an import example of this, and a successful implementation needs something non-contending. I assume Jython and IronPython do this. From rtw at freenet.co.uk Tue Jan 20 15:53:16 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 20 Jan 2009 14:53:16 -0600 Subject: Python 3: exec arg 1 References: Message-ID: Alan G Isaac wrote in news:myhdl.805$Aw2.484 at nwrddc02.gnilink.net in comp.lang.python: > On 1/18/2009 9:36 AM Alan G Isaac apparently wrote: >> I do not much care about the disappearance of ``execfile``. >> I was asking, why is it a **good thing** that >> ``exec`` does not accept a TextIOWrapper? >> Or is it just not implemented yet? >> What is the gain from this particular backwards >> incompatibility (in the sense that ``exec(open(fname))`` >> no longer works)? > > Still interested in an answer... > Alan Isaac http://bugs.python.org/issue1762972 (*) IIRC, exec(open(fname).read()) is the Py 3.0 replacement. *) For reference, 2 clicks away from Rob. -- http://www.victim-prime.dsl.pipex.com/ From gh at ghaering.de Tue Jan 20 16:28:00 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 20 Jan 2009 22:28:00 +0100 Subject: PyQt4 on Windows ? In-Reply-To: References: Message-ID: <6tmtv0Fbhj05U1@mid.uni-berlin.de> Linuxguy123 wrote: > What does it take to get a PyQt4 application running on a Windows > machine ? To run, installing Python + PyQt4 ;-) To create a binary wrapper, I use py2exe (I also tried cx_Freeze, both work the same). There's a gotcha with PyQt4 - snippet follows: setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "includes": ["sip"], "excludes": []}}, service = [], com_server = [], console = [], windows = [modeler], ) You need to include the "sip" module manually, it's not automatically discovered. To create an installer, I use NSIS. > I'm sorry if this is a redundant question, but I've searched this and I > am not finding a comprehensive answer. > > If anyone is running a PyQt4 application on a Windows (XP or Vista) > machine, I'd love to know how it works for you It works fine in a test setup. I didn't pursue this any further at the moment, because for the project in question we decided to deploy on MacOS X first and delay the Windows version. > and how extensive the application is and how much of the Qt library it uses. The application is currently 1200 LOC, 200 of which are autogenerated from Qt designer files. The final application will probably be about three times as large. It's a modeler application and I most of the code is thus centered around QGraphicsScene and two custom QGraphicsItems - one for nodes, one for edges. It's been a real pleasure that I get most functionality for the modeling app for free with (Py)Qt. -- Gerhard From http Tue Jan 20 16:30:21 2009 From: http (Paul Rubin) Date: 20 Jan 2009 13:30:21 -0800 Subject: what's the point of rpython? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <3fa44b51-ff0f-4da3-bcd0-1dc6603b6cfc@i24g2000prf.googlegroups.com> <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: <7xr62x3bte.fsf@ruckus.brouhaha.com> "Brendan Miller" writes: > > http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety > > I think you are misreading that. It says that multiple assignments to > different copies of a share_ptr in different threads are fine. I'll respond to this later. > http://www.codemaestro.com/reviews/8 > http://siyobik.info/index.php?module=x86&id=159 > > Again, I'm not an assembly guru, but his sounds like exactly what > you'd want. It gains exclusive access to system memory in a > multi-processor environtment without leaving user space. Thus XADD is > an atomic increment/decrement. It would be educational if someone more > famliar with x86 than me could speak to the performance merits of this > on modern multicore machines. Those links describe using the LOCK prefix, which as the name implies, asserts a lock, so it is no longer "lockless reference counting". The LOCK prefix adds about 100 cycles to the instruction. From http Tue Jan 20 16:39:39 2009 From: http (Paul Rubin) Date: 20 Jan 2009 13:39:39 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> Message-ID: <7xmydl3bdw.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > "lock free" is largely meaningless. What it really means is "we use > small hardware locks rather than big software locks, thereby reducing > (but not eliminating!) the contention". At least in the case of Haskell's "software transactional memory", reads are genuinely lock free in the normal uncontended case. You use LOCK XCHG to increment a counter in the object when you want to update, and increment it again when you are done updating. Since the counter starts at 0, any time it has an odd value, an update is in process and any other thread can notice that the object is locked and try again later without asserting any locks itself. If the counter has an even value, it is unlocked, but there is a chance that a writer thread can lock and udpate the object while a reader thread has a lockless access in progress. The reader detects this has occurred when it finishes its transaction, read the counter a second time, and notices that the counter has been incremented (maybe more than once) since the transaction started; it then rolls back its operation and tries again. I'm not explaining that well so you can read about it in SPJ's paper or Keir Fraser's. > The second issue is the objects themselves, like a list which is > mutable. If you're using it in a single thread or writing from > multiple threads this is a non-trivial constant cost. If your object > is not modified after creation and is read from many threads a lock > would be a point of contention, preventing you from scaling freely. > The dicts used by classes and globals are an import example of this, > and a successful implementation needs something non-contending. I > assume Jython and IronPython do this. I'm pretty sure Jython makes no attempt at all to mess with ref counts--it just relies on the underlying Java gc. I have no idea about IronPython. From google at mrabarnett.plus.com Tue Jan 20 16:49:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jan 2009 21:49:57 +0000 Subject: English-like Python In-Reply-To: <49762F4E.1000506@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <9d662e22-702c-42cb-a2c6-74002342a4dd@i18g2000prf.googlegroups.com> <49762F4E.1000506@strout.net> Message-ID: <49764705.6060009@mrabarnett.plus.com> Joe Strout wrote: > Aaron Brady wrote: > >> Unambiguity and readability are two different things. (This should be >> a quasi-tangent, neither agreed, nor opposed, nor unrelated to what >> you said.) >> >> If you have >> >> f "abc" 123 >> >> it's unambiguous, but, if you have >> >> g f "abc" 123 "def" >> >> there's no sure way to determine where the call to 'f' stopped, and >> the one to 'g' resumed (or, as in Python, if 'f' was even to be called >> at all, as opposed to 4 parameters to 'g'). > > Right -- that's exactly why (in RB) parentheses are required around > arguments to a method call if that method returns a value (in RB terms, > if it is a function rather than a subroutine). Then there is no > ambiguity, because only such a function can be used as an argument to > another method call (or otherwise be part of an expression). The above > would have to be written something like: > > g f("abc", 123), "def" > > I'm not saying I know how to translate this into Python -- some of > Python's other language features make this difficult. Just pointing out > that your original wish is possible in at least some languages. > Next you'll be saying that print(x) in Python 3.x should become print x in python 4.x! :-) From max at alcyone.com Tue Jan 20 16:58:49 2009 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Jan 2009 13:58:49 -0800 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) >> >> It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. Logo, of all things, doesn't require parentheses at all, since functions ("procedures") take a fixed number of arguments. Parentheses are only required when you're adding optional arguments. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Conversation is the enemy of good wine and food. -- Alfred Hitchcock From rhamph at gmail.com Tue Jan 20 17:02:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 20 Jan 2009 14:02:24 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> Message-ID: <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> On Jan 20, 2:39?pm, Paul Rubin wrote: > Rhamphoryncus writes: > > "lock free" is largely meaningless. ?What it really means is "we use > > small hardware locks rather than big software locks, thereby reducing > > (but not eliminating!) the contention". > > At least in the case of Haskell's "software transactional memory", > reads are genuinely lock free in the normal uncontended case. ?You use > LOCK XCHG to increment a counter in the object when you want to > update, and increment it again when you are done updating. ?Since the > counter starts at 0, any time it has an odd value, an update is in > process and any other thread can notice that the object is locked and > try again later without asserting any locks itself. ?If the counter > has an even value, it is unlocked, but there is a chance that a writer > thread can lock and udpate the object while a reader thread has a > lockless access in progress. ?The reader detects this has occurred > when it finishes its transaction, read the counter a second time, and > notices that the counter has been incremented (maybe more than once) > since the transaction started; it then rolls back its operation and > tries again. ?I'm not explaining that well so you can read about it in > SPJ's paper or Keir Fraser's. a) The contended case is the issue, not the uncontended case. An uncontended lock is just constant overhead, not a barrier to scalability b) Locks on linux (since the switch to futexes) are pretty close to free when uncontended. Transactions are really for different properties: a) read patterns can be uncontended (fully scalable) b) a preempted writer does not block other writers, guaranteeing forward progress c) ad-hoc combination of several objects into a single atomic update > > The second issue is the objects themselves, like a list which is > > mutable. ?If you're using it in a single thread or writing from > > multiple threads this is a non-trivial constant cost. ?If your object > > is not modified after creation and is read from many threads a lock > > would be a point of contention, preventing you from scaling freely. > > The dicts used by classes and globals are an import example of this, > > and a successful implementation needs something non-contending. ?I > > assume Jython and IronPython do this. > > I'm pretty sure Jython makes no attempt at all to mess with ref > counts--it just relies on the underlying Java gc. ?I have no idea > about IronPython. The second issue has *nothing* to do with refcounts. It is the objects themselves. A classic example is trying to do "i += 1", which breaks down into "i = i + 1", which isn't an atomic operation. Java's ConcurrentHash map gets this right. From domelectric at gmail.com Tue Jan 20 17:09:33 2009 From: domelectric at gmail.com (debug) Date: Tue, 20 Jan 2009 14:09:33 -0800 (PST) Subject: frequency analysis without numpy Message-ID: Hi- I've been using python now for about 2 months for plugin development within Maya (a commercial 3d application). I'm currently in the process of writing a sound analysis plugin for maya and have completed a good portion of it including the ability to retrieve the amplitude at certain intervals from a wav file. The next part of the project however consists of analysing the wav file and outputting the amplitude at certain frequencies. Due to the need of distributing this to many computers after it has been finished I'm reluctant to use an external python module for FFT'ing. Accuracy and speed aren't really issues as just a generalisation of the amplitude of low, medium and high frequencies is required. Do you either know of any generic FFT functions written in python that could just be inserted into my processing class (open source licensed). So far i've managed to put together a chunk of code but I'm not sure its returning the right values, any ideas? import wave import sys import array import struct from cmath import pi, exp def nextpow2(i): n = 2 while n < i: n = n * 2 return n def bitrev(x): N, x = len(x), x[:] if N != nextpow2(N): raise ValueError, 'N is not power of 2' for i in range(N): k, b, a = 0, N>>1, 1 while b >= a: if b & i: k = k | a if a & i: k = k | b b, a = b>>1, a<<1 if i < k: # important not to swap back x[i], x[k] = x[k], x[i] return x def fft(x, sign=-1): N, W = len(x), [] for i in range(N): # exp(-j...) is default W.append(exp(sign * 2j * pi * i / N)) x = bitrev(x) m = 2 while m <= N: for s in range(0, N, m): for i in range(m/2): n = i * N / m a, b = s + i, s + i + m/2 x[a], x[b] = x[a] + W[n % N] * x[b], x[a] - W[n % N] * x [b] m = m * 2 return x def ifft(X): N, x = len(X), fft(X, sign=1) # e^{j2\pi/N} for i in range(N): x[i] = x[i] / float(N) return x fp = wave.open("hankuncom.wav","rb") sample_rate = fp.getframerate() total_num_samps = fp.getnframes() fft_length = 4096 num_fft = (total_num_samps / fft_length ) - 2 temp = [] for i in range(num_fft): tempb = fp.readframes(fft_length) moo = struct.unpack("%uh"%(fft_length),tempb) temp.append(moo) listed = list(temp[0]) freq_pwr = fft(listed) print(freq_pwr) fp.close() Quick warning this code snippet does run slowly Thanks! The wav file referenced in the script is here: www.reality-debug.co.uk/hankuncom.zip From mdw at distorted.org.uk Tue Jan 20 17:17:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 20 Jan 2009 22:17:26 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Actually, in addition to the enforcement of "private," you also need > the enforcement of "protected." Oh, heavens. If you want C++ or any of its progeny, you know where to find them. Besides, those languages have a horrific design mistake because they conflate the class system (which manages the units of behaviour) with the module system (which deals with the units of implementation). It's precisely because Python's boundaries are fairly porous that it doesn't fall into this trap. (There's the small matter of sharing the class and instance attribute namespaces, but a little bit of care seems to work out OK.) Even so, why do you think you are that you know better than the next programmer -- whoever he might be -- which parts of your class he should mess with? You can make suggestions, recommendations, in your documentation: provide the raw materials so that he can make informed decisions about whether he wants to mess with your class's internals. But the `here's a black box: there isn't and never will be any justifiable reason why you might want to poke about inside' control-freakery of people who like this sort of thing just rubs me up the wrong way. Yes, I know that some people have to work with drooling idiots who don't know a stable interface from volatile implementation details or documented behaviour from a bug that'll be fixed in the next version. Python just isn't the right language for those people. They can use Java or something -- hey, it's presumably good for something, maybe it's this -- but those who know better don't deserve to be penalized for their sake. -- [mdw] From rridge at csclub.uwaterloo.ca Tue Jan 20 17:22:07 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Tue, 20 Jan 2009 17:22:07 -0500 Subject: what's the point of rpython? References: <7xfxje8akd.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: >Those links describe using the LOCK prefix, which as the name implies, >asserts a lock, so it is no longer "lockless reference counting". No, it doesn't assert a lock in the sense used in this thread. On modern Intel systems it's normally handled completely within the cache. >The LOCK prefix adds about 100 cycles to the instruction. That's unavoidable. It's still faster than spin lock, which would also have to use syncronizing instructions. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From Russ.Paielli at gmail.com Tue Jan 20 18:11:59 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 15:11:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Rather than waste more time replying to your post, Let me just refer you to an excellent post that you may have missed earlier in this thread by Mr. D'Aprano: http://groups.google.com/group/comp.lang.python/msg/d684d43b64a6e35a From sturlamolden at yahoo.no Tue Jan 20 18:13:44 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 20 Jan 2009 15:13:44 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: On Jan 20, 11:09?pm, debug wrote: > So far i've managed to put together a chunk of code but I'm not sure > its returning the right values, any ideas? Don't use the periodogram for frequency analysis; it is not a good estimate of the power spectrum. According to the Wiener-Khintchin theorem, the power spectrum is the Fourier transform of the autocorrelation, not the Fourier transform of the signal. You don't want to just FFT the signal. FFTs are used for spectral estimation, but not to obtain the periodogram. The periodogrgam is full of noise and spectral leakage. And even worse, the variance of the periodogram is constant, not inversely proportional to the number of samples. This is not how you want a spectrum estimator to behave. Consider using Thompson's multitaper method, autoregression (maximum entropy), or Welch method for your frequency estimates. Blackman- Tuckey is also a possibility, but I see no reason to prefer that to Welch. Multitaper and AR tends to be the better options though, but they are not as fast as Welch' method. You probably also want to use real FFTs instead of complex FFTs, unless you are interested in estimating the negative frequencies as well. For common spectral analysis, real FFTs are almost always what you want (complex FFTs can be used, but the incur redundant work). Apart from that, an FFT in pure python is going to be atrociously slow for anything but the shortest signals. I cannot imagine why you want to do this. There are many free FFT libraries around, including FFTPACK (used by NumPy) and FFTW. The easiest way to check your FFT is to compare with a verified implementation. I'd use NumPy or Matlab for that. S.M. From gert.cuykens at gmail.com Tue Jan 20 18:21:36 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 15:21:36 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> Message-ID: <3663bf09-fd2e-476e-b026-f42905cc2e1b@y1g2000pra.googlegroups.com> On Jan 20, 9:41?pm, John Machin wrote: > On Jan 21, 5:31?am, gert wrote: > > > On Jan 20, 5:23?am, John Machin wrote: > > > > On Jan 20, 12:54?pm, gert wrote: > > > > > How do you convert s back to binary data in python 3 so I can put in a > > > > sqlite blob ? > > > > Is there a build in function or do I need to use binascii ? > > > > byte(s) or bin(s) would make more sense but can not figure it out ? > > > > Can't imagine why you would do str(binary_data) especially if you want > > > it back again ... however: > > > def application(environ, response): > > ? ? s = str(environ['wsgi.input'].read()) > > ? ? b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group > > (1) > > ? ? p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n > > (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1) > > ? ? db.execute('UPDATE users SET picture=? WHERE uid=?', > > (p,session.UID)) > > > (a) don't write obfuscatory code :-0 > > E.g. > (1) re.compile(pattern).search(data) -> re.search(pattern, data) > (2) re.compile(pattern).match(data) -> re.match(pattern, data) > (3) re.match('.*blahblah', data) -> re.search('blahblah', data) > > (b) don't use re when ordinary str or bytes methods will do > > E.g. instead of: > b = re.search('boundary=(.*)'), environ['CONTENT_TYPE']).group(1) > try > b = environ['CONTENT_TYPE'].split('boundary=')[1] > > (c) Is that code meant to be rough pseudocode to illustrate what you > are trying to do, or is it meant to be working code? If the latter: > * Do you have this working in 2.X? yep > * Are you sure the pattern to retrieve the picture is correct? yep http://91.121.53.159/file.txt > * What is the "Content-Transfer-Encoding"? print (environ['Content-Transfer-Encoding'],file=sys.stderr) Key error flash 10 does not send it ? > (d) Surely there must be a library somewhere that parses that kind of > data for you ... p = FieldStorage(fp=environ['wsgi.input'], environ=environ) In python 3 you get TypeError: Can't convert 'bytes' object to str implicitly > (e) if all else fails, I'd suggest: > > instead of s = str(binary) > do s = binary.decode('latin1') > # this won't change the number of characters and will allow > # reconstitution of your non-ascii bytes > Then do your DIY parsing > then at the end do > blob = p.encode('latin1') > # blob will be type bytes which is presumably what the database > expects Victory :) http://91.121.53.159/appwsgi/www/register/register.htm http://code.google.com/p/appwsgi/source/browse/trunk from db import Db from session import Session from re import search,match,DOTALL def application(environ, response): db = Db() cookie = "SID="+environ['QUERY_STRING'] session = Session(db,cookie,'guest') response('200 OK', [('Content-type', 'text/xml'), ('Set-Cookie', session.COOKIE)]) if not session.GID : return [] s = environ['wsgi.input'].read().decode('latin1') b = search(r'boundary=(.*)',environ['CONTENT_TYPE']).group(1) p = search(r'Content-Type: application/octet-stream\r\n\r\n(.*)\r \n--',s,DOTALL).group(1) db.execute('UPDATE users SET picture=? WHERE uid=?',(p.encode ('latin1'),session.UID)) xml = "" xml+= ""+str(db.ERROR)+"" response('200 OK', [('Content-type', 'text/xml')]) return [xml] From aahz at pythoncraft.com Tue Jan 20 18:48:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 15:48:45 -0800 Subject: Style of "raise" (was Re: message of Exception) References: Message-ID: In article , Terry Reedy wrote: >Steven Woody wrote: >> >> And, I expect that when I raise a MyError as >> raise MyError, "my message" > >In 2.x you may and in 3.0 you must write that as >raise MyError("my message") >Best to start looking forward ;-). Funny, when I suggested to MvL that he do that (when I saw a checkin made against 2.x code), he rebuffed me. I didn't get a clear answer for why, so if you care, you need to ask him. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan From gert.cuykens at gmail.com Tue Jan 20 19:38:33 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 20 Jan 2009 16:38:33 -0800 (PST) Subject: s=str(binary) References: <2e989bcc-623d-4a01-93c5-d415e80cb360@35g2000pry.googlegroups.com> <886dedfb-adb8-4844-ad78-c869baf9d4e1@g39g2000pri.googlegroups.com> <9621cb26-4391-4799-bb4e-6b4b10fe2289@k36g2000pri.googlegroups.com> <3663bf09-fd2e-476e-b026-f42905cc2e1b@y1g2000pra.googlegroups.com> Message-ID: <60133b5c-bb56-4d2a-8b76-18c3b9a13a21@z28g2000prd.googlegroups.com> b = environ['CONTENT_TYPE'].split('boundary=')[1] oops forgot, is indeed better solution :) From afriere at yahoo.co.uk Tue Jan 20 19:45:37 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Tue, 20 Jan 2009 16:45:37 -0800 (PST) Subject: English-like Python References: Message-ID: On Jan 16, 12:02?pm, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be to make a programming language which is actually a > spoken one. I'm reminded of Lingua::Romana::Perligata which was done in Perl rather than Python, with the far more noble aim of programming in a language no longer spoken. ;) From aahz at pythoncraft.com Tue Jan 20 19:46:57 2009 From: aahz at pythoncraft.com (Aahz) Date: Tue, 20 Jan 2009 16:46:57 -0800 Subject: REMINDER: OSCON 2009: Call For Participation Message-ID: <20090121004657.GA25868@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From rhodri at wildebst.demon.co.uk Tue Jan 20 20:05:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:05:18 -0000 Subject: Two questions about style and some simple math In-Reply-To: <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> References: <497525C3.5090904@gmx.net> <44e8e810-76c4-4a63-b8ba-2a1a27f85a37@o4g2000pra.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 02:11:24 -0000, Mensanator wrote: > On Jan 19, 7:44?pm, "Rhodri James" > wrote: >> Surely in any case you don't want an expression based on the difference, >> since that would give you the same chance of having the first attack no >> matter what the levels of courage actually were, which can't be right. > > Why? Isn't it possible some attributes are relative rather than > absolute? You're right, of course. I blame lack of sleep. What I should have said was that you shouldn't have the random factor scaled to the difference. That way (as with the original code) your attributes aren't even relative, they're pretty much irrelevant. -- Rhodri James *-* Wildebeeste Herder to the Masses From mdw at distorted.org.uk Tue Jan 20 20:11:00 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 01:11:00 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > The consequence of this dynamism is that the Python VM can't do many > optimizations at all, because *at any time* somebody might mess with the > implementation. But 90% of the time nobody does, so Python is needlessly > slow 90% of the time. Wouldn't it be nice if there was a way to speed up > that 90% of the time while still allowing the 10% to take place? There is. Compile, optimizing aggressively under the assumption that everything will be as you expect. Keep a note somewhere of the assumptions you made. If something violates those assumptions, fall back to a slow version -- or, for bonus points, recompile based on the changed assumptions. CLOS is much more complex and dynamic than Python's object system; but it can be compiled very aggressively. > The current solution to this problem is to try to push as much as > possible into functions written in C: built-ins and custom C > extensions. It's not a bad solution: most Python programs rely on > many C built-ins, which enforces real encapsulation and data > hiding. With the possible exception of mucking about with ctypes, you > simply can't access mess with the internals of (say) lists *at > all*. Is this a bad thing? > > Would it be so terrible if we could do the same thing in pure Python? > Why should I have to write in C if I want the same protection? S'funny. I always considered the lack of transparency in C extensions to be a downside, and a reason to write as much as possible in proper, honest, transparent, dynamic, mess-about-with-able Python. >>> Why leave to coding standards and company policy what can be encoded >>> right into the language? Because nobody can agree what the standards and policy ought to be. > In Unix, file names with a leading dot are hidden in the shell: Bzzt. They're silently not displayed by various things, including the shell's globber, and ls(1). > when you do a file listing, you don't see them. It's not difficult to > get to see them: you just pass -a to the ls command. See? That's ls(1). Not the shell. You did know what you were talking about. > As data hiding goes, it's pretty lame, It's not data hiding, though. It's just not cluttering the view with stuff you probably didn't care about. I'm grateful that I don't have to think about dotfiles unless I really want to -- but I'm also very grateful that I /can/ mess with them when I do want to. > but Python doesn't even suppress _ names when you call dir. Frankly, > I wish that by default it would -- 99% of the time when I call dir, I > *don't* want to see _ names. They just get in the way. That might be plausible. > No it's not. It's *practical*. There are domains where *by law* code > needs to meet all sorts of strict standards to prove safety and > security, and Python *simply cannot meet those standards*. Codswallop. One can prove stuff about Python programs using the same techniques as one uses for any other language. I've done it. Other languages have better automated tools, it's true -- but the techniques are basically the same. > No technology is failure proof. But there's no reason in the world why > most technology can't be idiot-proof. Televisions are idiot-proof, > because they protect people from casual mistakes. If televisions were > built according to the Python model, the internals of the TV would be > exposed, without even a cover. All the major parts would be plug-in > rather than soldered in, and there would be no cover over the parts that > were live. Every year, tens of thousands of people would electrocute > themselves fatally (because parts of the TV holds a massive charge for > days after you unplug them from the mains) but that would be okay, > because you never know when somebody might want to pull out the fly-back > transformer and replace it with a six ohm resistor. That sort of dynamism > is important! Very amusing; but a poor analogy. The Python television comes in a clear Perspex box, which you can undo, should you need to, without any tools. But it holds together well even so. (Real PC cases are sometimes like this.) The parts are plug-in, yes; but dangerous stuff you probably don't want to mess with is covered by a plastic shield with a note on it saying `dangerous stuff in here: if you kill yourself messing with it, it's not my fault'. The plastic shields don't fall off of their own accord, but you can remove them without much difficulty should you be so inclined. >>> To prevent that sort of thing from happening, the management could >>> decree that henceforth all "private" variable names will start with an >>> underscore. Problem solved, eh? >> >> Certainly not. The only way to solve such a problem is to fire this >> cretin. > > Again, we shouldn't enforce encapsulation and data hiding because there > are legitimate reasons for breaking it, but anyone who does break it is a > cretin. You have a very strange attitude. I suppose it depends on the circumstances. I must have missed the earlier details, but there's not enough in the stuff above to prove a charge of cretinhood. I didn't see any ill-effects noted, for a start. > It's also bad for moral when you fire somebody for messing with the > internals when you have a policy that it is allowed to mess with the > internals. That's why you picked a dynamic language like Python in the > first place, because it doesn't prevent you from messing with the > internals. And now when somebody does, you sack him? If he did it unilaterally, without consulting other people or mentioning the risks, then that's irresponsible. If there was proper consultation and the decision was made for good -- and agreed -- reasons, then, well, it's a thing to keep in mind for later. May still be a net win. Hard to say. Python can be a sharp tool. Keeping sharp tools away from those who may injure themselves and others is a good idea. That doesn't mean that we shouldn't have sharp tools. It's hard to cut meat with a tenderizer. > Perhaps it would have been better to prevent him from messing with the > internals in the first place, even at some extra cost. When you're in > business, you have to make decisions like: > > * do I write the software in Python, which will have a 99% chance of > costing $100,000 and a 1% chance of costing $100,000,000? > > * or do I write it in a B&D language like Java, which will have a 100% > chance of costing $2,000,000? Easy. 1,099,000 < 2,000,000, so stick with Python. (In real life, we don't know the probabilities in advance, so the question is trickier.) >>>> from protection import unlock > > I don't know if this scenario is even possible in Python, but pretend > that it is. Would it be so terrible? I could probably live with it. It seems like a step back towards Blub[1] to me, though. The Blub programmers already have Blub. Lock the knives in the cupboard because the village idiot sometimes cuts himself. [1] http://www.paulgraham.com/avg.html -- [mdw] From mdw at distorted.org.uk Tue Jan 20 20:16:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 01:16:36 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Rather than waste more time replying to your post, Let me just refer > you to an excellent post that you may have missed earlier in this > thread by Mr. D'Aprano: I've responded to that now. (Steven and I can't even agree on a description for simple parts of Python semantics: why should we agree on this?) But I note that you've cunningly avoided responding to my remark that it's a mistake to conflate the module and class systems. (I think only Common Lisp gets this right, because it can use its package system to manage the names of class and instance slots and generic functions.) Besides, it's not just classes that have internal parts. Python is not Java: not all functionality is in classes. The proposals I've seen do nothing for internal variables or functions at module level. -- [mdw] From rhodri at wildebst.demon.co.uk Tue Jan 20 20:34:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:34:37 -0000 Subject: reading file to list In-Reply-To: <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 03:39:45 -0000, Xah Lee wrote: > On Jan 19, 4:49 pm, "Rhodri James" > wrote: >> On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee wrote: >> > On Jan 17, 10:25 am, Tino Wildenhain wrote: >> >> > [[int(x) for x in line.split()] for line in open("blob.txt")] >> >> > Nice (python code). >> >> > Few comments: >> >> > ? the above code is borderline of atypical. e.g. it is not a average >> > python code would produce or one'd seen in corporate python code. >> >> I can't imagine why not. > > consider code produced by corporations, as opposed to with respect to > some academic or philsophical logical analysis. Looked in another way, > consider if we can compile stat of all existing pyhton code used in > real world, you'll find the above style is rarely used. I *was* thinking of code produced in the real world, and I don't buy your assertion. I'm not an academic, and I wouldn't hesitate to lay down a line of code like that. As I said before, it fits into English language idioms naturally, and as a result is pretty self-descriptive. > in a logical analysis, each lang fanatics will actively sell certain > style of construction, but that's just not the way code in the real > world are. Ample examples can be found especially in other cultish > lang groups such as lisp, perl, etc. (less of this phenomenon is found > in lang like php, javascript, java, C, where the lang simple don't > create fancy constructions in the name of improvement or esthetics or > weird philosophy in the first place.) Long experience particularly in C suggests that you are entirely wrong. You are conflating simplicity with flexibility; C is a simple language, but it is very syntactically flexible, and programmers not only can but do regularly and with malice aforethought write horribly convoluted code. Sometimes this is out of cunning (dropping through cases in a switch statement, for instance), sometimes because the language is too simple (function dispatch tables can look gruesome if you aren't careful), and sometimes it's because you need a particular sequence of instructions to get the optimiser to Do The Right Thing; regardless, it happens in a large fraction of non-trivial C programs. >> > The above line illustrate well the ad hoc syntax soup nature python is >> > moving into. >> >> To a native English speaker, it illustrates entirely the reverse. >> List comprehension is actually quite a linguistically natural way >> to express the iterative construction of a list. > > computer lang is not human lang. In argument based on human lang, you > have AppleScript, Perl, which are un-readable or cumbersome to most > programers. Even with human lang, if you know linguistics to some > extend, you know that natural lang is a complete wortheless mess in > every aspect with respect to ?design? qualities. Having studied natural languages, I am well aware that the designers of AppleScript didn't study natural languages. If they had, they'd have been a lot more careful in their choice of constructs to map AppleScript onto English less ambiguously. I can't think of a language less like AppleScript than Perl, which is incomprehesible for entirely different reasons. Grouping them together as if they had anything else in common is... eccentric. Computer languages are not human languages, but computer language constructs do attempt to map onto human language constructs to provide some measure of comprehensibility. Where a construct like list comprehension maps very well onto idiomatic English, dismissing it as "ad hoc syntax soup" is just plain wrong. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Tue Jan 20 20:36:07 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:36:07 -0000 Subject: pep 8 constants In-Reply-To: <87fxje4lqh.fsf@benfinney.id.au> References: <87fxje4lqh.fsf@benfinney.id.au> Message-ID: On Tue, 20 Jan 2009 04:58:30 -0000, Ben Finney wrote: > Unless someone's going to argue that ?Variable Names? doesn't apply to > constant names, even though Python doesn't make the distinction. Python doesn't make the distinction, which is precisely why making the distinction through CONVENTIONAL_NAMING_PRACTICE is useful. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Tue Jan 20 20:42:03 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 01:42:03 -0000 Subject: what's the point of rpython? In-Reply-To: <7x3afewqwh.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 20 Jan 2009 04:19:26 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Brendan Miller" writes: >> Maybe I'm missing something here but a lock free algorithm for >> reference counting seems pretty trivial. As long as you can atomically >> increment and decrement an integer without locking you are pretty much >> done. > > What cpu's do you know of that can atomically increment and decrement > integers without locking? x86 (and pretty much any 8080 derivative, come to think of it). That said, what you actually need is an atomic read-and-increment, which is a lot harder to find. Even if you could find a platform supporting it, it doesn't help you on other platforms you may need to run on. Just do the locking properly and worry about optimisations later. -- Rhodri James *-* Wildebeeste Herder to the Masses From skip at pobox.com Tue Jan 20 20:48:13 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 20 Jan 2009 19:48:13 -0600 Subject: what's the point of rpython? In-Reply-To: References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: <18806.32477.75414.590588@montanaro.dyndns.org> Rhodri> Just do the locking properly and worry about optimisations Rhodri> later. The locking is already done properly (assuming we are discussing CPython's reference counting). Now is later. People are thinking about lots of optimizations, this is just one of them. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From Russ.Paielli at gmail.com Tue Jan 20 21:25:42 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 18:25:42 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 20, 5:16 pm, Mark Wooding wrote: > "Russ P." writes: > > Rather than waste more time replying to your post, Let me just refer > > you to an excellent post that you may have missed earlier in this > > thread by Mr. D'Aprano: > > I've responded to that now. (Steven and I can't even agree on a > description for simple parts of Python semantics: why should we agree on > this?) > > But I note that you've cunningly avoided responding to my remark that > it's a mistake to conflate the module and class systems. (I think only > Common Lisp gets this right, because it can use its package system to > manage the names of class and instance slots and generic functions.) > > Besides, it's not just classes that have internal parts. Python is not > Java: not all functionality is in classes. The proposals I've seen do > nothing for internal variables or functions at module level. > > -- [mdw] I'm not sure what you mean by "conflating module and class systems." Are you referring to the fact that Java requires each class to be in its own file of the same name (I don't use Java, but that's what I've heard)? If so, I agree that is a bad idea. Actually, I remember reading years ago that Ada gets this right. I've never used Ada for real work either, but I understand that privacy is managed according to packages and modules rather than classes. That is a more flexible approach and makes more sense. [I realize that Ada is on life support, and I probably sound like a neanderthal for bringing it up so much, but it actually has many advanced features that were well ahead of their time -- and still are to some extent.] In any case, I have suggested that Python should perhaps get a new keyword, "private" or "priv". When used inside a class, it would serve a similar function to what it does in Java, C++, and Scala. If used at the file scope, it could simply restrict the data or function to that module. I think that is how Ada works. From http Tue Jan 20 21:29:01 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:29:01 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> Message-ID: <7xprihmlxu.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > > What cpu's do you know of that can atomically increment and decrement > > integers without locking? > > x86 (and pretty much any 8080 derivative, come to think of it). It would not have occurred to me that "lock inc" increments "without locking". I understand that's different from a lock value sitting in the data object but I thought that "lock-free algorithm" meant one that didn't assert any of these hardware locks either. Maybe I'm wrong. > Just do the locking properly and worry about optimisations later. That has already been tried, and found to be unacceptably slow for the purpose at hand. Now we're looking for the optimizations. From zzbbaadd at aol.com Tue Jan 20 21:34:19 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Tue, 20 Jan 2009 18:34:19 -0800 (PST) Subject: Overloading Methods References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: <678e1f4c-6c7c-445d-95d2-f31f55252c93@r38g2000vbi.googlegroups.com> > > class Foo(object): > def __init__(self, a, b=10, c=None): > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > Not that it's important to the discussion, but, while Java does not have the capability to give default method parameters, C++ does. From http Tue Jan 20 21:35:00 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:35:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xljt5mlnv.fsf@ruckus.brouhaha.com> "Russ P." writes: > [I realize that Ada is on life support, and I probably sound like a > neanderthal for bringing it up so much, but it actually has many > advanced features that were well ahead of their time -- and still are > to some extent.] I have the impression that there has been an uptick of interest in Ada due to the availability of GNAT, which appeared on the scene not all that long ago. I've been interested for a while in using it for something, but haven't done so yet. The main doc I've read about it so far is admittedly a sales pitch, but it's enough to make me believe that writing anything substantial in C or C++ with significant security or safety consequences is both masochistic and irresponsible: http://adahome.com/Ammo/cpp2ada.html I've gotten hold of a couple of Ada books but haven't had the copious free time to look at them very much yet. From wuwei23 at gmail.com Tue Jan 20 21:47:59 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 18:47:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: On Jan 21, 5:04?am, "Russ P." wrote: > If pylint can check access violations, then it seems to me that > someone (who is familiar with the internals of the Python interpreter) > should be able to integrate that feature into Python itself relatively > easily. If pylint performs the data access protection checks you want, then it seems to me that it would be a better idea to mandate the use of pylint on any projects you're working on - either in the IDE or when checking in to a repository - rather than slow down Python as a whole by providing functionality that doesn't seem to be in demand by the majority of users. I've never understood why so many things "must" reside in the language itself when the same effect can be achieved through a well written module. (And that's not even commenting on the whole "I have no skill in this area and only second-hand knowledge that it's possible but it's *obvious* to me that it's trivial and *someone else* should easily be able to do the work for me!" nature of your post...) From http Tue Jan 20 21:52:01 2009 From: http (Paul Rubin) Date: 20 Jan 2009 18:52:01 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <7xk58p4bhq.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > > Whaat? Assuming a program is perfect unless a failure is proven > > is not at all a sane approach to getting reliable software. It is > > the person claiming perfection who has to prove the absence of failure. > > No, no. I meant that if pylint works as its specification says it would. Oh, I see. Well, that would be ok, except Pylint is not specified as detecting the types of access that Russ is concerned with. It can't, for example, flag uses of setattr that might affect a particular class. That would take something a lot fancier. From tjreedy at udel.edu Tue Jan 20 21:53:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 21:53:01 -0500 Subject: English-like Python In-Reply-To: <49761EE6.4070306@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) How would you differentiate f 'abc' + 'def' as f('abc') + 'def' versus f('abc' + 'def') > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > Example: > > LogError "Walk has gotten too silly", CurrentTime LogError('walk', Time) # versus LogError('walk'), Time Perhaps RB does not have tuple literals. From tjreedy at udel.edu Tue Jan 20 22:13:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:13:54 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. You did not call it. From tjreedy at udel.edu Tue Jan 20 22:15:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:15:55 -0500 Subject: How to print lambda result ? In-Reply-To: <4975C1F9.6040607@wildenhain.de> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> Message-ID: Tino Wildenhain wrote: > > or in python <3.0: > > (num,"s"*(num >1)) works fine in 3.0 too >>> num=1 >>> (num,"s"*(num >1)) (1, '') >>> num=2 >>> (num,"s"*(num >1)) (2, 's') Of course, 0 events gets 's' also, so (num!=1) is the actual comparison needed. From google at mrabarnett.plus.com Tue Jan 20 22:16:33 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 03:16:33 +0000 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: <49769391.3020409@mrabarnett.plus.com> Terry Reedy wrote: > Joe Strout wrote: >> Aaron Brady wrote: >> >>> I think it would be a good step if you could make some sensible >>> interpretation of a typical statement without its parentheses. >>> >>> f "abc" 123 >>> --> >>> f( "abc", 123 ) > > How would you differentiate > > f 'abc' + 'def' > as > f('abc') + 'def' > versus > f('abc' + 'def') > >> Such a language is possible -- take a look at REALbasic sometime. RB >> certainly has its problems (mainly bugs), but the language syntax is >> beautiful. To your point, parentheses are not required around any >> method call that (1) has no return value, or (2) requires no >> parameters. Example: >> >> LogError "Walk has gotten too silly", CurrentTime > > LogError('walk', Time) # versus > LogError('walk'), Time > > Perhaps RB does not have tuple literals. > Parentheses wouldn't be required if it's a procedure call (I'm not sure about a function that's called as a procedure) or if there are no parameters to pass. Thus: f 'abc' + 'def' does: f('abc' + 'def') From Russ.Paielli at gmail.com Tue Jan 20 22:18:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 19:18:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> Message-ID: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> On Jan 20, 6:47 pm, alex23 wrote: > (And that's not even commenting on the whole "I have no skill in this > area and only second-hand knowledge that it's possible but it's > *obvious* to me that it's trivial and *someone else* should easily be > able to do the work for me!" nature of your post...) I never said or even suggested that anything was "trivial." You must have imagined that. Also, I am an aerospace engineer, not a computer scientist, software engineer, or programmer per se. Since when is no one is allowed to suggest a potential improvement to a product unless they are willing to implement it themselves? Imagine what the world would be like if such a rule applied to all products. From aahz at pythoncraft.com Tue Jan 20 22:24:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 19:24:06 -0800 Subject: Regular Expressions... References: Message-ID: In article , Ken D'Ambrosio wrote: > >Hi, all. As a recovering Perl guy, I have to admit I don't quite "get" >the re module. Refer to the following every time you want to use regexes in Python: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski, comp.emacs.xemacs, 8/1997 Although there are times when regexes are your best option, Python has many other good options for processing strings, and your code readability will usually increase if you try one of them first. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From prologic at shortcircuit.net.au Tue Jan 20 22:28:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 13:28:26 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 1:18 PM, Russ P. wrote: > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. Maybe nobody wants what you want ? Besides no-one will improve python for you! Python is a FOSS contributed to by many tedious laborious hours for little to no financial gain for the people that have put in the hard work. So if you insist python must have it, do it yourself ) And for the record, I (and probably 98% of other python developers) don't want your data protection or encapsulation. :) Have a nice day :) cheers James From tjreedy at udel.edu Tue Jan 20 22:41:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:41:57 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> Message-ID: Duncan Booth wrote: > Luis Zarrabeitia wrote: > >> It boggles me when I see python code with properties that only set and >> get the attribute, or even worse, getters and setters for that >> purpose. In my university they teach the students to write properties >> for the attributes in C# ("never make a public attribute, always write >> a public property that just gets and sets it"). I never understood >> that practice either, given that the syntax for attribute access and >> property access in C# is exactly the same. (Could it be that even if >> the syntax is the same, the compiled code differs? Don't know enough >> about .NET to answer that). >> > The compiled code differs. I *strongly* doubt that. Properties are designed to be transparent to user code that access atrributes through the usual dotted name notation precisely so that class code can be changed from x = ob to x = property(get_x, set_x, del_x) without changing user code. CPython compiles attribute access to LOAD_ATTR The code associated with LOAD_ATTR should get the attribute object and check whether it is a property, in which case it calls the proper method of the property. > That doesn't matter if the class is only > accessed from within a single compiled program, but it does matter if you > expose a public interface from a library: if you change a public attribute > into a property then you need to recompile all code which accesses it. Example to back this claim? Perhaps you have found a bug. tjr From tdelaney at avaya.com Tue Jan 20 22:46:32 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 21 Jan 2009 11:46:32 +0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: Message-ID: Terry Reedy wrote: >> The compiled code differs. > > I *strongly* doubt that. Properties are designed to be transparent to > user code that access atrributes through the usual dotted name > notation precisely so that class code can be changed from > x = ob > to > x = property(get_x, set_x, del_x) > without changing user code. He was talking about C# with that statement. In C#, the compiled code differs depending on whether you use a property or an attribute. Or at least that's how I interpreted it. You are of course correct as to how Python does it. Tim Delaney From tjreedy at udel.edu Tue Jan 20 22:51:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 22:51:38 -0500 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Rhodri James wrote: > Computer languages are not human languages, but computer language > constructs do attempt to map onto human language constructs to > provide some measure of comprehensibility. Where a construct like > list comprehension maps very well onto idiomatic English, dismissing > it as "ad hoc syntax soup" is just plain wrong. Especially given that Python's comprehensions are taken from Haskell's which are taken from mathematics' set builder notation. Also, care was taken to have a correspondance between comprehension syntax and nested for- and if- statement syntax. Someone recently made a proposal that would break that correspondance and which would be 'ad hoc' and it will surely be rejected. tjr From diresu at web.de Tue Jan 20 22:52:46 2009 From: diresu at web.de (Dietrich Bollmann) Date: Wed, 21 Jan 2009 12:52:46 +0900 Subject: How to write a simple shell loop in python? Message-ID: <1232509966.4430.28.camel@pippi.pippi> Hi, I am trying to write a simple shell loop in Python. My simple approach works fine - but the first output line after entering something is always indented by one blank. Is there any logic explanation for this? How can I get rid of the blank? Is there a smarter way to write a simple shell loop which would work better? Thanks, Dietrich Here my approach: $ python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> while (1): ... print "$ ", ... input = sys.stdin.readline() ... input = input.strip() ... print input ... print input ... print input ... $ one one one one $ two two two two $ three three three three $ Traceback (most recent call last): File "", line 3, in KeyboardInterrupt >>> From tjreedy at udel.edu Tue Jan 20 23:16:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jan 2009 23:16:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: Message-ID: Delaney, Timothy (Tim) wrote: > Terry Reedy wrote: > >>> The compiled code differs. >> I *strongly* doubt that. Properties are designed to be transparent to >> user code that access atrributes through the usual dotted name >> notation precisely so that class code can be changed from >> x = ob >> to >> x = property(get_x, set_x, del_x) >> without changing user code. > > He was talking about C# with that statement. In C#, the compiled code > differs depending on whether you use a property or an attribute. Or at > least that's how I interpreted it. Checking back, I see now that Luis Z. went from Python "It boggles me when I see python code with properties that only set and get the attribute, or even worse, getters and setters for that purpose. " to C#, and that Duncan was seemingly responding to the C# part. If C# is like that, how inconvenient. > You are of course correct as to how Python does it. I guess I am spoiled ;-). tjr From wuwei23 at gmail.com Tue Jan 20 23:26:39 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 20:26:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> On Jan 21, 1:18?pm, "Russ P." wrote: > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. It wasn't the suggestion so much as the claim that integration of the behaviour was "relatively easy". Everything is "relatively easy" when you're not the one doing it. My mistake for using "trivial" instead, I didn't realise it would trip up your pedantry. From prologic at shortcircuit.net.au Tue Jan 20 23:30:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 14:30:14 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Wed, Jan 21, 2009 at 9:11 AM, Russ P. wrote: > Rather than waste more time replying to your post, Let me just refer > you to an excellent post that you may have missed earlier in this > thread by Mr. D'Aprano: > > http://groups.google.com/group/comp.lang.python/msg/d684d43b64a6e35a I'll finish reading it tonight :) Too long :) Starts off well though! --JamesMills From sspatz at kcnet.com Tue Jan 20 23:33:15 2009 From: sspatz at kcnet.com (Saul Spatz) Date: Tue, 20 Jan 2009 22:33:15 -0600 Subject: Problem with 3.0 Install on Windows Message-ID: I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get familiar with it. I have a directory with all my python projects in my PYTHONPATH variable. When I try to run python 3.0, it detects a syntax error (a print statement) in the first file in this directory, and crashes. I don't want to convert the files to 3.0 syntax, because I plan to keep using 2.5, at least for a while. I don't know exactly why this translation is happening. Is there a way to turn it off? Thanks From xahlee at gmail.com Tue Jan 20 23:35:22 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 20:35:22 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Xah Lee wrote: > > consider code produced by corporations, as opposed to with respect to > > some academic or philsophical logical analysis. Looked in another way, > > consider if we can compile stat of all existing pyhton code used in > > real world, you'll find the above style is rarely used. Rhodri James wrote: > I *was* thinking of code produced in the real world, and I don't buy > your assertion. I'm not an academic, and I wouldn't hesitate to lay > down a line of code like that. As I said before, it fits into English > language idioms naturally, and as a result is pretty self-descriptive. The issue is whether the python code in the real world, by statistics, uses a style such as list comprehension as discussed in this thread. (to simplify the matter: whether code out there uses list comprehension in situations when it can, by what percentage. I claimed it is rare, being borderline esoteric. This can be interpreted as less that 10%) In partcular, the issue, is not about your opinion or joe tech geeker's personal experiences of what they have seen. In newsgroups, every joe geeker makes claims using personal experiences as if that apply for the world. I, of course also based on my claims on personal experience, however, the difference is that my claim is explicitly made in the context of applying to the world. For example, my claim is not about my experiences being such and such. My claim is about such and such is so in the real world. If, now, you claim that it is not so, then perhaps we might have something to argue about. If you can, say, as a example, have a code that crawl the web of all google's own python code at google code for example, and do some simple analysis and report what is the percentage, and if that percentage is more than what i claim, i'll find it very interesting. But if you simply have such code to do such scale of analysis, that's far more interesting by itself than our debate. Similarly, if you can find any evidence, say by some code researcher's reports, that'd be great. At this point, i recall that i have read books on such report. You might try to do research on such books and read up. > Long experience particularly in C suggests that you are entirely wrong... Try to study more. I recommend spend less time coding or tech geeking (such as reading blogs, studying languages, or studying computer science ). I recommend taking a course in community college on philosophy, logic, literature, economics. After that, your thinking in coding and all the social issues related to coding, and computing industry, will sharpen by far. Xah ? http://xahlee.org/ ? From xahlee at gmail.com Tue Jan 20 23:43:33 2009 From: xahlee at gmail.com (Xah Lee) Date: Tue, 20 Jan 2009 20:43:33 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: <647db7ce-2622-4ec8-8fe9-798ff6b311a9@k1g2000prb.googlegroups.com> On Jan 20, 7:51 pm, Terry Reedy wrote: > Rhodri James wrote: > > Computer languages are not human languages, but computer language > > constructs do attempt to map onto human language constructs to > > provide some measure of comprehensibility. Where a construct like > > list comprehension maps very well onto idiomatic English, dismissing > > it as "ad hoc syntax soup" is just plain wrong. > > Especially given that Python's comprehensions are taken from Haskell's > which are taken from mathematics' set builder notation. Also, care was > taken to have a correspondance between comprehension syntax and nested > for- and if- statement syntax. Someone recently made a proposal that > would break that correspondance and which would be 'ad hoc' and it will > surely be rejected. I suggest you take a course in math history. This is a pratical suggestion. There are community colleges perhaps near you. Register and take a course. If you are in USA, usually they are very cheap because it is funded by taxes. Typically it's 3 hours or so a week, adding homework it might be 10 per week, and last about 3 months. Try it. It's fun. The above won't actually teach you much in htis issue. To get some level of basic knowledge on this, you'll have to have few years on inter-displinary study associated math history, math notations, markup langs, computer syntax, mathematical linguistics related to grammar n syntax... Being a tech geeking hip creature, perhaps you'll never take the above advice. You'd rather immediate read some slashdot or google something and post profusely in online forums. For this, i recommend a few articles of my own: ? The Codification of Mathematics http://xahlee.org/cmaci/notation/math_codify.html ? The TeX Pestilence http://xahlee.org/cmaci/notation/TeX_pestilence.html ? The Problems of Traditional Math Notation http://xahlee.org/cmaci/notation/trad_math_notation.html ? A Notation for Plane Geometry http://xahlee.org/cmaci/notation/plane_geometry_notation.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html of course, i also have very technical and practical book length tutorials on emacs lisp, python, perl, java, javascript/html/css, php, povray. You can find them on my website. Thanks. Xah ? http://xahlee.org/ ? From aahz at pythoncraft.com Tue Jan 20 23:47:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Jan 2009 20:47:20 -0800 Subject: Extracting real-domain-name (without sub-domains) from a given URL References: <50697b2c0901130020r187e0ea3ye96eda91bd82a569@mail.gmail.com> Message-ID: In article , S.Selvam Siva wrote: > > Actually i tried with domain specific logic.Having 200 TLD like >.com,co.in,co.uk and tried to extract the domain name. > But my boss want more reliable solution than this method,any way i >will try to find some alternative solution. http://www.dnspython.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From wuwei23 at gmail.com Tue Jan 20 23:49:09 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 20:49:09 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: <4c799e42-4283-4140-b206-65f060a5afa7@s1g2000prg.googlegroups.com> On Jan 21, 2:35?pm, Xah Lee wrote: > I, of course also based on my claims on personal > experience, however, the difference is that my claim is explicitly > made in the context of applying to the world. For example, my claim is > not about my experiences being such and such. My claim is about such > and such is so in the real world. So the claims of people who have personally worked on "real world" code that contains list comprehensions isn't valid, whereas you who have _no_ such experience have a more genuine understanding of the world? Which is somehow totally unbiased and yet somehow always agrees with your preconceived notions? Talk about Aristotle and his wife's teeth... > I recommend taking a course in community college on > philosophy, logic, literature, economics. After that, your thinking in > coding and all the social issues related to coding, and computing > industry, will sharpen by far. Because clearly what the world needs is more of your style of academic understanding over practical, pragmatic knowledge. And arrogant condescension...we sure can't get enough of that. From Russ.Paielli at gmail.com Tue Jan 20 23:50:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 20:50:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Jan 20, 8:26?pm, alex23 wrote: > On Jan 21, 1:18?pm, "Russ P." wrote: > > > Since when is no one is allowed to suggest a potential improvement to > > a product unless they are willing to implement it themselves? Imagine > > what the world would be like if such a rule applied to all products. > > It wasn't the suggestion so much as the claim that integration of the > behaviour was "relatively easy". Everything is "relatively easy" when > you're not the one doing it. Here's what I wrote: If pylint can check access violations, then it seems to me that someone (who is familiar with the internals of the Python interpreter) should be able to integrate that feature into Python itself relatively easily. If pylint can check for private access violations, then in principle someone could just add a run-time flag that would run pylint as a preliminary step to running python. Heck, I am *not* familiar with the internals of the interpreter, and even I could do that. > My mistake for using "trivial" instead, I didn't realise it would trip > up your pedantry. Your mistake for being a moron. But it seems to happen regularly, doesn't it. How much more of my time are you going to waste, loser? From wuwei23 at gmail.com Wed Jan 21 00:00:02 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 21:00:02 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> On Jan 21, 2:50?pm, "Russ P." wrote: > If pylint can check for private access violations, then in principle > someone could just add a run-time flag that would run pylint as a > preliminary step to running python. Heck, I am *not* familiar with the > internals of the interpreter, and even I could do that. So why don't you? Why don't you set up a local command that does it for you? Why don't you add the check to your repo check in? Why don't you extend the object class in your site.py to provide the data protection you want? Why don't you enforce the use of that site.py across whatever multi-developer Python environment you're participating in? (You are -actually- working in such an environment, right, not just wasting our time in pointless conjecture?) Why don't YOU do SOMETHING other than insist that the community provide the solution for you? I always thought this was the major advantage of Python, that so much effort could be offloaded from the language to third party libraries. If there is such an urgent itch-to-scratch for data protection, where are the libs that provide such? There's a lot of funky stuff you can do with metaclasses. > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? You keep saying this and you keep replying. You keep making outlandish statements and then get angry when people question you. I'm sorry that using synonyms for words you've written seems to anger you so much. Have you stopped to consider that maybe it's that very anger which is rendering you unable to entertain other people's arguments in this thread? That's my polite way of saying "you're an arrogant and condescending prick", by the way, just so there's no confusion here. From prologic at shortcircuit.net.au Wed Jan 21 00:07:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:07:09 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 2:50 PM, Russ P. wrote: >> My mistake for using "trivial" instead, I didn't realise it would trip >> up your pedantry. > > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? I'm sorry Russ, but you insult my friend you die. You are -in fact- the moron here. I only wish my good friend and software engineering professor were here to laugh at this stupidly funny thread. Please stop replying. From sspatz at kcnet.com Wed Jan 21 00:12:00 2009 From: sspatz at kcnet.com (Saul Spatz) Date: Tue, 20 Jan 2009 23:12:00 -0600 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: Dietrich Bollmann wrote: > Hi, > > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > > Is there any logic explanation for this? > How can I get rid of the blank? > Is there a smarter way to write a simple shell loop which would work > better? > > Thanks, Dietrich > > > Here my approach: > > $ python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one > one > one > one > $ two > two > two > two > $ three > three > three > three > $ > Traceback (most recent call last): > File "", line 3, in > KeyboardInterrupt > > Strange. I don't have an explanation, but experiment shows that if you change print "$ ", to print "$ " (that is, leave out the comma) then the leading blank is not printed. This behavior doesn't depend on the "print input" statement's being in a loop. By the way, you don't need parens around the loop guard in python: while 1: (or as I prefer, while True:) work just fine. Saul From Russ.Paielli at gmail.com Wed Jan 21 00:20:45 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 21:20:45 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 9:00?pm, alex23 wrote: > On Jan 21, 2:50?pm, "Russ P." wrote: > > > If pylint can check for private access violations, then in principle > > someone could just add a run-time flag that would run pylint as a > > preliminary step to running python. Heck, I am *not* familiar with the > > internals of the interpreter, and even I could do that. > > So why don't you? Why don't you set up a local command that does it > for you? Why don't you add the check to your repo check in? Why don't > you extend the object class in your site.py to provide the data > protection you want? Why don't you enforce the use of that site.py > across whatever multi-developer Python environment you're > participating in? (You are -actually- working in such an environment, > right, not just wasting our time in pointless conjecture?) > > Why don't YOU do SOMETHING other than insist that the community > provide the solution for you? > > I always thought this was the major advantage of Python, that so much > effort could be offloaded from the language to third party libraries. > If there is such an urgent itch-to-scratch for data protection, where > are the libs that provide such? There's a lot of funky stuff you can > do with metaclasses. > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > You keep saying this and you keep replying. You keep making outlandish > statements and then get angry when people question you. I'm sorry that > using synonyms for words you've written seems to anger you so much. > Have you stopped to consider that maybe it's that very anger which is > rendering you unable to entertain other people's arguments in this > thread? That's my polite way of saying "you're an arrogant and > condescending prick", by the way, just so there's no confusion here. You are the one who pulled the word "trivial" out of your rear end and claimed that I had said it, when I had said nothing of the sort, loser. Let me explain, moron. I don't need enforced data hiding for the prototype I am working on now, because it's only a prototype that will be converted into another more suitable language for the end product. I am just interested in the idea of someday being able to go directly from prototype to end product in Python. It's not an immediate need, but a long-term concern. Can you comprehend that, genius? But I doubt it will ever come to pass, because it is clear that much of the Python community has no clue about what is required for large- scale, safety-critical software engineering. If people here said that Python just shouldn't worry about that domain, that would be fair enough. But three or four people on this thread have claimed now that Python is perfectly suitable for any project, no matter the size or the safety criticality. The idea that someone that clueless could actually be in a position to make such a choice for a real system someday is, frankly, a bit frightening. From Russ.Paielli at gmail.com Wed Jan 21 00:26:33 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 21:26:33 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Jan 20, 9:07?pm, James Mills wrote: > On Wed, Jan 21, 2009 at 2:50 PM, Russ P. wrote: > >> My mistake for using "trivial" instead, I didn't realise it would trip > >> up your pedantry. > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > I'm sorry Russ, but you insult my friend you die. > You are -in fact- the moron here. I only wish my good friend > and software engineering professor were here to laugh > at this stupidly funny thread. > > Please stop replying. I die? That sounds like a threat. I should report you for that, loser. Are you going to stalk me now, loser? Oh, and does your software engineering professor agree with you that Python is perfectly suitable for any safety-critical system, no matter how large? That would be interesting to know. From rhodri at wildebst.demon.co.uk Wed Jan 21 00:32:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:32:41 -0000 Subject: what's the point of rpython? In-Reply-To: <7xprihmlxu.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 02:29:01 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > What cpu's do you know of that can atomically increment and decrement >> > integers without locking? >> >> x86 (and pretty much any 8080 derivative, come to think of it). > > It would not have occurred to me that "lock inc" increments "without > locking". I understand that's different from a lock value sitting in > the data object but I thought that "lock-free algorithm" meant one > that didn't assert any of these hardware locks either. Maybe I'm > wrong. I tend to live in single-core worlds, so "inc" on its lonesome works just fine. >> Just do the locking properly and worry about optimisations later. > > That has already been tried, and found to be unacceptably slow for the > purpose at hand. Now we're looking for the optimizations. In that case I'd second the suggestion of taking a long, hard look at the Linux core locking and synchronisation primatives. -- Rhodri James *-* Wildebeeste Herder to the Masses From prologic at shortcircuit.net.au Wed Jan 21 00:33:01 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:33:01 +1000 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: On Wed, Jan 21, 2009 at 3:12 PM, Saul Spatz wrote: > Strange. I don't have an explanation, but experiment shows that if you > change print "$ ", to print "$ " (that is, leave out the comma) then the > leading blank is not printed. This behavior doesn't depend on the "print > input" statement's being in a loop. > > By the way, you don't need parens around the loop guard in python: > while 1: (or as I prefer, while True:) work just fine. http://codepad.org/f2XSwsPo This component I wrote - just for the hell of it - (just for this thread) works nicely :) cheers James From catphive at catphive.net Wed Jan 21 00:35:05 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 21:35:05 -0800 Subject: what's the point of rpython? In-Reply-To: <7xprihmlxu.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 6:29 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> > What cpu's do you know of that can atomically increment and decrement >> > integers without locking? >> >> x86 (and pretty much any 8080 derivative, come to think of it). > > It would not have occurred to me that "lock inc" increments "without > locking". I understand that's different from a lock value sitting in > the data object but I thought that "lock-free algorithm" meant one > that didn't assert any of these hardware locks either. Maybe I'm > wrong. Right... I was wondering about that. Well, any kind of memory access gets exclusive control of the bus except on NUMA, but I'm wondering how CMPXCHG http://en.wikipedia.org/wiki/Compare-and-swap compares to XADD performance wise. It seems to me that both of them must pull the old value across the bus, hang onto the bus, and move the new value in. Maybe since XADD needs to perform arithmetic there will be a few cycles lag between getting the old value and pushing the new value? Maybe CMPXCHG doesn't go through the ALU? If the bus isn't just sitting idle and you can immediately push out the new value then there's no real locking. Actually this article explicitly mentions CMPXCHG as lock free. http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms From bignose+hates-spam at benfinney.id.au Wed Jan 21 00:37:16 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 21 Jan 2009 16:37:16 +1100 Subject: python for flash drives References: Message-ID: <878wp543ub.fsf@benfinney.id.au> Thomas Lord writes: > try portable python. it's free! You say it's free, but I'm unable to find the license terms easily on the web site. Which free software license does the recipient have in the work? -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From http Wed Jan 21 00:37:44 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:37:44 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3t2p93.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > I tend to live in single-core worlds, so "inc" on its lonesome works > just fine. In a single core world we wouldn't be having these endless angsty conversations about eliminating the GIL. > > That has already been tried, and found to be unacceptably slow for the > > purpose at hand. Now we're looking for the optimizations. > > In that case I'd second the suggestion of taking a long, hard look > at the Linux core locking and synchronisation primatives. Do you understand what the issue is, about CPython's reference counts? Do you have any idea how often the interpreter updates them? Even using LOCK INCR (raw machine instruction, not portable C, no operating system involvement), manipulating the ref counts would be around 100x slower than it is now. From prologic at shortcircuit.net.au Wed Jan 21 00:41:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:41:09 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 3:20 PM, Russ P. wrote: (...) > Let me explain, moron. I don't need enforced data hiding for the > prototype I am working on now, because it's only a prototype that will > be converted into another more suitable language for the end product. > I am just interested in the idea of someday being able to go directly > from prototype to end product in Python. It's not an immediate need, > but a long-term concern. Can you comprehend that, genius? And you're seriously going to sit there in your fancy office and state that Python isn't suitable ? You're stupider than we give you credit for. But that's okay - because although you "claim" to be a Software Engineer (I don't believe you) - you probably have no idea about Process, Code Review, Unit Testing, Z, ... > But I doubt it will ever come to pass, because it is clear that much > of the Python community has no clue about what is required for large- > scale, safety-critical software engineering. I guarantee that this is not the case, only that those that actually -do- use python for large scale projects or even mission critical or safety critical systems probably can't be bothered to waste their time with the likes of you. > If people here said that Python just shouldn't worry about that > domain, that would be fair enough. But three or four people on this > thread have claimed now that Python is perfectly suitable for any > project, no matter the size or the safety criticality. The idea that > someone that clueless could actually be in a position to make such a > choice for a real system someday is, frankly, a bit frightening. http://www.google.com/ --JamesMills From bignose+hates-spam at benfinney.id.au Wed Jan 21 00:42:16 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 21 Jan 2009 16:42:16 +1100 Subject: How to write a simple shell loop in python? References: Message-ID: <874ozt43lz.fsf@benfinney.id.au> Dietrich Bollmann writes: > I am trying to write a simple shell loop in Python. You should investigate the ?cmd? module in the standard library . > My simple approach works fine - but the first output line after > entering something is always indented by one blank. You should investigate the meaning of a comma ?,? in the ?print? statement (hint: it can affect subsequent ?print? statements) . -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From prologic at shortcircuit.net.au Wed Jan 21 00:44:53 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 15:44:53 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 3:26 PM, Russ P. wrote: > I die? That sounds like a threat. I should report you for that, loser. > Are you going to stalk me now, loser? It's an expression you fool. > Oh, and does your software engineering professor agree with you that > Python is perfectly suitable for any safety-critical system, no matter > how large? That would be interesting to know. Actually - in case you are perfectly unaware - programming languages -do not- bare meaning to such systems nor have an impact on their suitability or unsuitability. Have you ever developed a system with 0 defects ? If you have not, go away. Have you ever developed a system that is mathematically sound ? If you have not, go away. And can you -actually- prove that any of your system are -correct- ? ... ditto ... --JamesMills From http Wed Jan 21 00:47:41 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:47:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <7xd4eh2osi.fsf@ruckus.brouhaha.com> James Mills writes: > I guarantee that this is not the case, only that those that > actually -do- use python for large scale projects or even mission > critical or safety critical systems Do they exist? From psteiger at dcc.ufba.br Wed Jan 21 00:48:36 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Tue, 20 Jan 2009 21:48:36 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhmthz1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <8043df8e-26c8-4887-9728-2970e8b7112d@k36g2000pri.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> Message-ID: <909ef3300901202148q791f9565q356dea3ed0319aac@mail.gmail.com> 2009/1/20 Paul Rubin <"http://phr.cx"@nospam.invalid> > Luis Zarrabeitia writes: > > No wonder you can't get Bruno's point. For the second, static checks > > to prevent accidents, you have pylint. For the first, not only you > > are using the wrong tool, but you are barking at python for not > > having it. Assuming that pylint is perfect (big assumption, but it > > is up to you to prove where it fails), > > Whaat? Assuming a program is perfect unless a failure is proven > is not at all a sane approach to getting reliable software. It is > the person claiming perfection who has to prove the absence of failure. > -- > http://mail.python.org/mailman/listinfo/python-list > To quote Carl Sagan (who quoted someone else, i guess), "Abscence of evidence is not evidence of abscence" -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 21 00:49:05 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:49:05 -0000 Subject: reading file to list In-Reply-To: <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 04:35:22 -0000, Xah Lee wrote: > Xah Lee wrote: > Similarly, if you can find any evidence, say by some code researcher's > reports, that'd be great. At this point, i recall that i have read > books on such report. You might try to do research on such books and > read up. Given that you are the one who is attempting proof by repeated assertion, I'd suggest that it is your job to find the evidence to support your claim. I am merely observing that I find your claim highly unlikely. >> Long experience particularly in C suggests that you are entirely >> wrong... > > Try to study more. I recommend spend less time coding or tech geeking > (such as reading blogs, studying languages, or studying computer > science ). I recommend taking a course in community college on > philosophy, logic, literature, economics. After that, your thinking in > coding and all the social issues related to coding, and computing > industry, will sharpen by far. I recommend spending less time being certain that you are correct without seeking evidence (something the later philosophers seem dreadfully bad at) and more in the application of logical thought. While expanding one's horizons is a good thing (my personal list places more emphasis on the theory and practice of music, theology, literature and democracy, but anything is fair game), expanding one's ego is not. -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 21 00:51:51 2009 From: http (Paul Rubin) Date: 20 Jan 2009 21:51:51 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <7x8wp52olk.fsf@ruckus.brouhaha.com> James Mills writes: > Actually - in case you are perfectly unaware - programming > languages -do not- bare meaning to such systems nor have > an impact on their suitability or unsuitability. Er, who do you think you are trying to fool, saying things like that? Maybe just yourself. > Have you ever developed a system with 0 defects ? > If you have not, go away. > Have you ever developed a system that is mathematically sound ? > If you have not, go away. > And can you -actually- prove that any of your system are -correct- ? > ... ditto ... http://compcert.inria.fr/doc/index.html (no, I didn't work on this). Care to attempt something comparable in Python? From sjmachin at lexicon.net Wed Jan 21 00:55:01 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 20 Jan 2009 21:55:01 -0800 (PST) Subject: Problem with 3.0 Install on Windows References: Message-ID: <2e48f9a0-a9d6-4e20-89df-444f50e254b9@p2g2000prn.googlegroups.com> On Jan 21, 3:33?pm, Saul Spatz wrote: > I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get > familiar with it. ?I have a directory with all my python projects in my > PYTHONPATH variable. ?When I try to run python 3.0, it detects a syntax > error (a print statement) in the first file in this directory, and > crashes. ?I don't want to convert the files to 3.0 syntax, because I > plan to keep using 2.5, at least for a while. > > I don't know exactly why this translation is happening. ?Is there a way > to turn it off? The directories in PYTHONPATH are *prepended* to sys.path. Perhaps one of your files has the same name as a module that's new in Python 3.0 ... "io" is a possible candidate; "abc" a better one. Care to tell us the name of the file in which 3.0 finds the syntax error? From rhodri at wildebst.demon.co.uk Wed Jan 21 00:58:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 21 Jan 2009 05:58:57 -0000 Subject: what's the point of rpython? In-Reply-To: <7xhc3t2p93.fsf@ruckus.brouhaha.com> References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 05:37:44 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> In that case I'd second the suggestion of taking a long, hard look >> at the Linux core locking and synchronisation primatives. > > Do you understand what the issue is, about CPython's reference counts? > Do you have any idea how often the interpreter updates them? Even > using LOCK INCR (raw machine instruction, not portable C, no operating > system involvement), manipulating the ref counts would be around 100x > slower than it is now. You asked a question about CPUs with atomic update, strongly implying there were none. All I did was supply a counter-example, and observe that neither this nor the question were in fact helpful. My inability to spell "primitive", on the other hand, is all my own fault. -- Rhodri James *-* Wildebeeste Herder to the Masses From prologic at shortcircuit.net.au Wed Jan 21 01:00:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:00:03 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xd4eh2osi.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7xd4eh2osi.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 3:47 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > James Mills writes: >> I guarantee that this is not the case, only that those that >> actually -do- use python for large scale projects or even mission >> critical or safety critical systems > > Do they exist? http://www.wingware.com/python/success Google is your friend - Though I'm certain that there would be many systems either closed or trade secret what wouldn't necessarily make public the technologies or platforms they utilize. --JamesMills From wuwei23 at gmail.com Wed Jan 21 01:02:04 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 22:02:04 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> On Jan 21, 3:20?pm, "Russ P." wrote: [...more invective and avoiding of questions snipped...] > Let me explain, moron. I don't need enforced data hiding for the > prototype I am working on now, because it's only a prototype that will > be converted into another more suitable language for the end product. > I am just interested in the idea of someday being able to go directly > from prototype to end product in Python. It's not an immediate need, > but a long-term concern. Can you comprehend that, genius? Can I comprehend that you don't even have an immediate need and are instead actively engaging in online onanism? Absolutely. Didn't even have to call you a moron to demonstrate it, either. From prologic at shortcircuit.net.au Wed Jan 21 01:02:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:02:37 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x8wp52olk.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 3:51 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > James Mills writes: >> Actually - in case you are perfectly unaware - programming >> languages -do not- bare meaning to such systems nor have >> an impact on their suitability or unsuitability. > > Er, who do you think you are trying to fool, saying things like that? > Maybe just yourself. Paul unless you can prove otherwise, refuting my statement is useless. Claiming that Python may or may not be suitable for safety critical systems or large scale systems is unfounded. --JaemsMills From http Wed Jan 21 01:03:52 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:03:52 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> Message-ID: <7xk58pgppz.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > You asked a question about CPUs with atomic update, strongly implying > there were none. All I did was supply a counter-example, Well, more specifically, atomic update without locking, but I counted the LOCK prefix as locking while other people didn't, and that caused some confusion. Of course I'm aware of the LOCK prefix but it slows down the instruction enormously compared with a non-locked instruction. From http Wed Jan 21 01:08:23 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:08:23 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> Message-ID: <7xfxjdgpig.fsf@ruckus.brouhaha.com> James Mills writes: > >> Actually - in case you are perfectly unaware - programming > >> languages -do not- bare meaning to such systems nor have > >> an impact on their suitability or unsuitability. > > > > Er, who do you think you are trying to fool, saying things like that? > > Maybe just yourself. > > Paul unless you can prove otherwise, refuting my statement > is useless. Claiming that Python may or may not be suitable > for safety critical systems or large scale systems is unfounded. "Programming languages -do not- bare meaning to such systems nor have an impact on their suitability or unsuitability" (I presume you mean "bear" not "bare") is a far stronger and stupider statement than one about Python's suitability or lack thereof. Most informed users would agree that Python is more suitable than some languages for that sort of application and less suitable than others. Only a fool would propose that all languages are equally suitable. From prologic at shortcircuit.net.au Wed Jan 21 01:18:48 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:18:48 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xfxjdgpig.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:08 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Programming languages -do not- bare meaning to such systems nor have > an impact on their suitability or unsuitability" (I presume you mean > "bear" not "bare") is a far stronger and stupider statement than one > about Python's suitability or lack thereof. Most informed users would > agree that Python is more suitable than some languages for that sort > of application and less suitable than others. Only a fool would > propose that all languages are equally suitable. Yes I meant "bear" - bite me. I never did say that python -is- suitable for all applications or that all languages are suitable for all purposes. However, (others that are) claiming that Python -is not- suitable because python does not have XYZ feature is equally as foolish. Who's to say that Python is not just as suitable for the systems on-board a Boeing-747 then C++ ? --JamesMills From catphive at catphive.net Wed Jan 21 01:19:21 2009 From: catphive at catphive.net (Brendan Miller) Date: Tue, 20 Jan 2009 22:19:21 -0800 Subject: what's the point of rpython? In-Reply-To: <7xk58pgppz.fsf@ruckus.brouhaha.com> References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Rhodri James" writes: >> You asked a question about CPUs with atomic update, strongly implying >> there were none. All I did was supply a counter-example, > > Well, more specifically, atomic update without locking, but I counted > the LOCK prefix as locking while other people didn't, and that caused > some confusion. Of course I'm aware of the LOCK prefix but it slows > down the instruction enormously compared with a non-locked instruction. I'm curious about that. I've been looking around for timing information on the lock signal, but am having some trouble finding them. Intuitively, given that the processor is much faster than the bus, and you are just waiting for processor to complete an addition or comparison before put the new memory value on the bus, it seems like there should be very little additional bus contention vs a normal add instruction. From Russ.Paielli at gmail.com Wed Jan 21 01:23:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:23:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> Message-ID: On Jan 20, 10:02?pm, alex23 wrote: > Can I comprehend that you don't even have an immediate need and are > instead actively engaging in online onanism? Absolutely. So anyone thinking beyond an "immediate need" is "engaging in online onanism"? Let's see. How long ago did the Python community start thinking about Python 3? So I guess they're all a bunch of jerkoffs, eh? From wuwei23 at gmail.com Wed Jan 21 01:24:08 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 22:24:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 21, 3:20?pm, "Russ P." wrote: > But I doubt it will ever come to pass, because it is clear that much > of the Python community has no clue about what is required for large- > scale, safety-critical software engineering. Okay, let me try a less snippy approach. How do you feel about metaclass techniques such as this one by Carl Banks? http://code.activestate.com/recipes/573442/ This is pretty much what I had in mind when I said before that I believed such concerns could be addressed externally of the interpreter. Thankfully I thought to check Activestate before knocking up my own as proof-of-concept :) With Python 2.6/3.0 Carl's code could be easily (almost said 'trivially'...) extended to support the new __dir__ special method to exclude anything marked as private from the dir() results. From Russ.Paielli at gmail.com Wed Jan 21 01:32:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:32:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Jan 20, 10:18?pm, James Mills wrote: > I never did say that python -is- suitable for > all applications or that all languages are suitable > for all purposes. But you did make some rather outlandish statements. I had written this: > I suggest you call Boeing and tell them that encapsulation is more > trouble than it's worth for their 787 flight software. But please > don't do it if you ever wish to work for them, because you will be > proving conclusively that you don't have a clue about the kind of > software systems they produce. And you wrote this little gem in reply: I am 100% confident that those same systems could be well written in a language such as Python and would very likely end up being much smaller and more manageable. From prologic at shortcircuit.net.au Wed Jan 21 01:37:52 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:37:52 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:32 PM, Russ P. wrote: > But you did make some rather outlandish statements. I had written > this: > >> I suggest you call Boeing and tell them that encapsulation is more >> trouble than it's worth for their 787 flight software. But please >> don't do it if you ever wish to work for them, because you will be >> proving conclusively that you don't have a clue about the kind of >> software systems they produce. > > And you wrote this little gem in reply: > > I am 100% confident that those same systems could be > well written in a language such as Python and would very > likely end up being much smaller and more manageable. And I completely stand by this. --JamesMills From http Wed Jan 21 01:49:54 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:49:54 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> Message-ID: <7x63k917cd.fsf@ruckus.brouhaha.com> James Mills writes: > Who's to say that Python is not just as suitable > for the systems on-board a Boeing-747 then C++ ? "Today, Boeing uses about 500,000 lines of Ada to fly its commercial 747 400 in subsystem components, critical certification, and human safety features. Two of the three largest systems on the 747, or 43 percent of the executable bytes, are written in Ada. The software is FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) Is the third component in C++? That is scary, if it does anything important. From Russ.Paielli at gmail.com Wed Jan 21 01:55:09 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 22:55:09 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 10:24?pm, alex23 wrote: > On Jan 21, 3:20?pm, "Russ P." wrote: > > > But I doubt it will ever come to pass, because it is clear that much > > of the Python community has no clue about what is required for large- > > scale, safety-critical software engineering. > > Okay, let me try a less snippy approach. How do you feel about > metaclass techniques such as this one by Carl Banks? > > http://code.activestate.com/recipes/573442/ > > This is pretty much what I had in mind when I said before that I > believed such concerns could be addressed externally of the > interpreter. Thankfully I thought to check Activestate before knocking > up my own as proof-of-concept :) > > With Python 2.6/3.0 Carl's code could be easily (almost said > 'trivially'...) extended to support the new __dir__ special method to > exclude anything marked as private from the dir() results. Looks interesting. If it can somehow be integrated into the language as full-fledged feature, then I'd say it has potential. As I said before, I am not looking for a hack or a quick fix. I am interested in well-engineered data hiding that is fully supported as part of the language. But I certainly appreciate Mr. Banks effort whether it ever reaches that level or not. [I am a bit confused though, because I seem to recall that Mr. Banks claimed earlier in this thread that enforced data hiding is useless.] From http Wed Jan 21 01:56:05 2009 From: http (Paul Rubin) Date: 20 Jan 2009 22:56:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <7x1vux1722.fsf@ruckus.brouhaha.com> alex23 writes: > Okay, let me try a less snippy approach. How do you feel about > metaclass techniques such as this one by Carl Banks? > > http://code.activestate.com/recipes/573442/ Does the metaclass prevent reaching into the __dict__ in an instance? Also, attribute protection is just a tiny aspect. The high assurance community really wants as much static verification as it can possibly get. Python doesn't really lend itself to that. From prologic at shortcircuit.net.au Wed Jan 21 01:57:05 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 16:57:05 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x63k917cd.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 4:49 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Today, Boeing uses about 500,000 lines of Ada to fly its commercial > 747 400 in subsystem components, critical certification, and human > safety features. Two of the three largest systems on the 747, or 43 > percent of the executable bytes, are written in Ada. The software is > FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) You wouldn't happen to have a source for this information would you ? And this (if true) hardly suprises me as Ada is one of the most rigorous and strictest languages I have ever used. Still... --JamesMills From prologic at shortcircuit.net.au Wed Jan 21 02:03:03 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 21 Jan 2009 17:03:03 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Wed, Jan 21, 2009 at 4:55 PM, Russ P. wrote: > On Jan 20, 10:24 pm, alex23 wrote: >> This is pretty much what I had in mind when I said before that I >> believed such concerns could be addressed externally of the >> interpreter. Thankfully I thought to check Activestate before knocking >> up my own as proof-of-concept :) >> >> With Python 2.6/3.0 Carl's code could be easily (almost said >> 'trivially'...) extended to support the new __dir__ special method to >> exclude anything marked as private from the dir() results. > > Looks interesting. If it can somehow be integrated into the language > as full-fledged feature, then I'd say it has potential. As I said > before, I am not looking for a hack or a quick fix. I am interested in > well-engineered data hiding that is fully supported as part of the > language. But I certainly appreciate Mr. Banks effort whether it ever > reaches that level or not. Then -don't- use python. Use some other boring language. (!@#$!@#) --JamesMills From Russ.Paielli at gmail.com Wed Jan 21 02:10:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:10:57 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: On Jan 20, 10:56?pm, Paul Rubin wrote: > Also, attribute protection is just a tiny aspect. ?The high assurance > community really wants as much static verification as it can possibly > get. ?Python doesn't really lend itself to that. Which is why I was hoping that Python might get enforced data hiding as well as optional static type declarations that can actually be used for static verification. But maybe that's all just a pipe dream on my part -- or "onanism." From Russ.Paielli at gmail.com Wed Jan 21 02:14:39 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:14:39 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: <3905e097-2a25-470b-af83-39a7263ad214@d36g2000prf.googlegroups.com> On Jan 20, 11:03?pm, James Mills wrote: > Then -don't- use python. Use some other boring > language. (!@#$!@#) > > --JamesMills You're emailing me again. Please don't do that. It's bad enough to get death threats in a newsgroup -- I don't need them in my inbox too. Thanks. From http Wed Jan 21 02:16:06 2009 From: http (Paul Rubin) Date: 20 Jan 2009 23:16:06 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> Message-ID: <7xwscpyvrd.fsf@ruckus.brouhaha.com> James Mills writes: > > "Today, Boeing uses about 500,000 lines of Ada to fly its commercial > > 747 400 in subsystem components, critical certification, and human > > safety features. Two of the three largest systems on the 747, or 43 > > percent of the executable bytes, are written in Ada. The software is > > FAA certified." (http://archive.adaic.com/docs/flyers/commapps.html) > > You wouldn't happen to have a source for this information would you ? Just the url that is there. > And this (if true) hardly suprises me as Ada is one of the most > rigorous and strictest languages I have ever used. I have no direct experience with it but have read a little about it. It looks to be a fairly vanilla block structured imperative language like Pascal with some concurrency stuff added. The sense I have is that it's not especially harder to program in than C or C++, but the programs come out much more reliable. If you want to see something really rigorous and strict, take a look at ATS: http://ats-lang.org . Here is a certified quicksort in ATS: http://www.ats-lang.org/EXAMPLE/MISC/listquicksort.dats The point is that ATS's type system is powerful enough to define a type for a sorting routine (a function that takes a list as input and produces a sorted permutation of the input list). If you then write something that purports to be a sorting routine but fails to produce a sorted permutation, the compiler will reject the program with a type error. If your routine compiles at all, it sorts correctly. From wuwei23 at gmail.com Wed Jan 21 02:16:38 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 23:16:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 21, 4:55?pm, "Russ P." wrote: > Looks interesting. If it can somehow be integrated into the language > as full-fledged feature, then I'd say it has potential. As I said > before, I am not looking for a hack or a quick fix. I am interested in > well-engineered data hiding that is fully supported as part of the > language. I think this is the main issue we disagree on. I'm happier for Python to remain lightweight where such features can be easily added on demand through external libraries. I see no reason why a library couldn't be as "well-engineered" a solution as an extension to the interpreter, its use being a mandated (and enforced) requirement within personal projects. The language just has to enable such solutions, which I feel Python does well. Perhaps what really concerns me with the inclusion of data hiding into the language itself is that people would use it :) I've always enjoyed the openness of the Python libs, the "consenting adults" approach it takes, and the ease with which I can override their inherent functionality when I need to. (But I think we've been over this before, the whole "the lib developer knows best" vs "I the coder know best" argument...) > [I am a bit confused though, because I seem to recall that Mr. Banks > claimed earlier in this thread that enforced data hiding is useless.] Maybe he was just trying to stave off threads like this one ;) From wuwei23 at gmail.com Wed Jan 21 02:19:54 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 20 Jan 2009 23:19:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: <679947f8-83fd-44da-94f3-4ba65058437c@d36g2000prf.googlegroups.com> On Jan 21, 4:56?pm, Paul Rubin wrote: > Does the metaclass prevent reaching into the __dict__ in an instance? Yes, if you specify that '__dict__' is one of the private attributes. > Also, attribute protection is just a tiny aspect. ?The high assurance > community really wants as much static verification as it can possibly > get. ?Python doesn't really lend itself to that. I can't argue against that. It will be interesting to see what comes out of the introduction of parameter annotation in 3.0. From http Wed Jan 21 02:30:32 2009 From: http (Paul Rubin) Date: 20 Jan 2009 23:30:32 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> Message-ID: <7xprih5d5z.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > Zope is about 375 KLOC[1], > How many LOCS would it require if it was written in ADA ? No idea. Ada is a lot more verbose than Python, but I'm baffled at what the heck Zope is actually doing with all that code. > > Zope also has 275 open bugs, 6 of which are critical. > > None of which are going to *kill* anyone FWIW. Now how many of these > bugs would have language-enforced access restriction prevented ? I'm not about to audit 375 KLOC of code to find out. Regardless of whether access restriction actually prevents bugs though, it certainly makes auditing easier. And auditing does find bugs. > >[2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC > of a hi-level dynamic language ? Hm, I guess not. I think written in some forerunner of Ada. > Given the difference in LOCS count between a low-level static language > and a hi-level dynamic language for the implementation of a same given > features set, you cannot just define "large" by the # of LOCS. Not > that I'm going to compare Zope with Space shuttle's stuff. I don't think static vs dynamic makes much difference in the amount of LOCS to accomplish some function. In my limited experience with Haskell (statically typed but very high level), it takes around the same amount of Haskell code as Python code (sometimes more, sometimes less) to do a given task. More important for concise code is features like higher-level functions and types (e.g. it's easy in Python or Haskell, but a huge pain in Java or C, to write down a value that is a list of dictionaries whose keys are tuples and whose values are more lists of dictionaries, to code something list a listcomp, etc). From Russ.Paielli at gmail.com Wed Jan 21 02:30:54 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 20 Jan 2009 23:30:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> Message-ID: On Jan 20, 11:16?pm, alex23 wrote: > I think this is the main issue we disagree on. I'm happier for Python > to remain lightweight where such features can be easily added on > demand through external libraries. I see no reason why a library > couldn't be as "well-engineered" a solution as an extension to the > interpreter, its use being a mandated (and enforced) requirement > within personal projects. The language just has to enable such > solutions, which I feel Python does well. That could work. As long as it's well-engineered (not a hack), well- supported (part of the standard library), and does the job, that's probably all that matters. From aonlazio at gmail.com Wed Jan 21 03:06:13 2009 From: aonlazio at gmail.com (AON LAZIO) Date: Wed, 21 Jan 2009 03:06:13 -0500 Subject: Nonblocking keyboard input in python Idle windows Message-ID: Hi, I want to solve the problem like this running on Idle python windows The problem: the program continue printing 1,2,3,4,5.... until it receives the input 'enter' from keyboard then it stops printing this could be done using msvcrt.kbhit() and msvcrt.getch() on command prompt windows However, those methods could not work in Python Idle windows. Any of you guys know the methods to solve this problem? Thanks in advance. Aonlazio -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Wed Jan 21 03:10:55 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 21 Jan 2009 09:10:55 +0100 Subject: Start Python at client side from web app Message-ID: <6to3kfFbr0psU1@mid.individual.net> Hi, I want to start Python at the client side from a web application. The app is an intranet application, and all client PCs are under our control (we can install software on them). But I don't want to update the installation too often. Here is my idea: We create a custom mime-type and register it on the client PC. The web application can send signed python code to the client PC. If the signature is correct, the code will be executed at the client. The signature prevents others from executing code. Has someone seen or done something like this before? I can code this myself, but prefer to use some open source project, if it exists. Thanks in advance, Thomas G?ttler -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steven at REMOVE.THIS.cybersource.com.au Wed Jan 21 03:36:49 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 21 Jan 2009 08:36:49 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote: > Aaron Brady wrote: > >> I think it would be a good step if you could make some sensible >> interpretation of a typical statement without its parentheses. >> >> f "abc" 123 >> --> >> f( "abc", 123 ) >> >> It would be just the thing in a couple of situations... > > Such a language is possible -- take a look at REALbasic sometime. RB > certainly has its problems (mainly bugs), but the language syntax is > beautiful. To your point, parentheses are not required around any > method call that (1) has no return value, or (2) requires no parameters. > Example: > > LogError "Walk has gotten too silly", CurrentTime > > Here, LogError is a method call that takes two arguments, and > CurrentTime is a method call that takes none. That seems ambiguous to me. As a non-RealBasic programmer, I can see at least four meanings it could have. Translated into Python, they are: LogError("Walk has gotten too silly", CurrentTime) LogError("Walk has gotten too silly"), CurrentTime LogError("Walk has gotten too silly", CurrentTime()) LogError("Walk has gotten too silly"), CurrentTime() Of course this assumes that RealBasic has an equivalent of tuples, and treats functions as first class objects. But even if RB doesn't have these things, I question that the syntax is "beautiful". Consider some arbitrary method Foo. If you see this: Foo Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo does. If it returns no result, then it's legal. If it returns a result, it isn't. So the question of whether syntax is legal depends, not on the syntactic elements involved, but on the *semantics* of the method (whether or not it returns a result). > Eliminating unnecessary parentheses does a lot to improve the > readability of the code IMHO. But they're not unnecessary, at least not in Python, they're useful for distinguishing between calling the function and the function itself. -- Steven From spam.buster at web.de Wed Jan 21 03:41:44 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 09:41:44 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web > application can send signed python code to the client PC. If the signature > is correct, the code will be executed at the client. The signature > prevents others from executing code. My first thought was: Wouldn't it be much easier to start the script via ssh? -- Cheerz Lars From castironpi at gmail.com Wed Jan 21 03:48:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 00:48:22 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> Message-ID: <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> On Jan 20, 9:16?pm, MRAB wrote: > Terry Reedy wrote: > > Joe Strout wrote: > >> Aaron Brady wrote: > > >>> I think it would be a good step if you could make some sensible > >>> interpretation of a typical statement without its parentheses. > > >>> f "abc" 123 > >>> --> > >>> f( "abc", 123 ) > > > How would you differentiate > > > f 'abc' + 'def' > > as > > f('abc') + 'def' > > versus > > f('abc' + 'def') > > >> Such a language is possible -- take a look at REALbasic sometime. ?RB > >> certainly has its problems (mainly bugs), but the language syntax is > >> beautiful. ?To your point, parentheses are not required around any > >> method call that (1) has no return value, or (2) requires no > >> parameters. ?Example: > > >> ?LogError "Walk has gotten too silly", CurrentTime > > > LogError('walk', Time) # versus > > LogError('walk'), Time > > > Perhaps RB does not have tuple literals. > > Parentheses wouldn't be required if it's a procedure call (I'm not sure > about a function that's called as a procedure) or if there are no > parameters to pass. Thus: > > ? ? ?f 'abc' + 'def' > > does: > > ? ? ?f('abc' + 'def') Where functions are first-class objects, a bare function object isn't distinguishable either from its call. I'm granting that it's useful to return values a lot. For example: a= f could mean either, 'a= f' or 'a= f()'. Once again the return values save the day. In the case of Terry's example, it's covered by Joe's caveat that functions can't return values without parentheses, since '+' is a function. However, order of precedence could help. Python and C of course allow string concatenation by adjacency, so there's further ambiguity there. It might fall under Terry's case. You can look at English to get started, and try to see how native speakers resolve the ambiguities. It doesn't just happen with verbs, either. Firstly, Python lacks the notion of determiners (denoting phrases) per se. That is, there's no way to say 'the black dog'. Here's an approximation though. "The black dog and the cat walked to the store." walked( ( dogs( color= black ), cat ), store ) Secondly, Python is entirely imperative, something I was alluding to in another post, which was about a relation object. English declares the event, while Python commands it: ( dog, cat ).walk( store ) It addresses the subjects, and gives them orders. On a tangent, I think the 'join' method on threads is a little counter-intuitive, since the entity you're giving the instruction to is actually the caller, not the object. The verb is a little counter-intuitive, though, since if I say 'Team, join us!', it actually just means, 'Us, wait for the team'. It's not like 'join' causes the target to break early or hustle or anything. From mal at egenix.com Wed Jan 21 03:56:08 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 21 Jan 2009 09:56:08 +0100 Subject: How to get first/last day of the previous month? In-Reply-To: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> References: <1b2da527-a86e-45ab-a363-2cfd477f4a66@v18g2000pro.googlegroups.com> Message-ID: <4976E328.8030104@egenix.com> On 2009-01-20 15:54, Mike Driscoll wrote: > On Jan 20, 8:19 am, Hussein B wrote: >> Hey, >> I'm creating a report that is supposed to harvest the data for the >> previous month. >> So I need a way to get the first day and the last day of the previous >> month. >> Would you please tell me how to do this? >> Thanks in advance. > > I recommend the dateutil module: > > http://labix.org/python-dateutil > > I think it may also be possible to use the datetime module, but it's > easier to just use dateutil. Or use mxDateTime on which all this was based: http://www.egenix.com/products/python/mxBase/mxDateTime/ >>> from mx.DateTime import now, Date, RelativeDateTime >>> >>> def prev_month(): ... t = now() ... return ( ... t + RelativeDateTime(months=-1, day=1, hour=0, minute=0, second=0), ... t + RelativeDateTime(months=-1, day=-1, hour=0, minute=0, second=0)) ... >>> print prev_month() (, ) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 21 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From castironpi at gmail.com Wed Jan 21 03:57:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 00:57:49 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Jan 21, 2:36?am, Steven D'Aprano wrote: > On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote: > > Aaron Brady wrote: > > >> I think it would be a good step if you could make some sensible > >> interpretation of a typical statement without its parentheses. > > >> f "abc" 123 > >> --> > >> f( "abc", 123 ) > > >> It would be just the thing in a couple of situations... > > > Such a language is possible -- take a look at REALbasic sometime. ?RB > > certainly has its problems (mainly bugs), but the language syntax is > > beautiful. ?To your point, parentheses are not required around any > > method call that (1) has no return value, or (2) requires no parameters. > > ? Example: > > > ? LogError "Walk has gotten too silly", CurrentTime > > > Here, LogError is a method call that takes two arguments, and > > CurrentTime is a method call that takes none. > > That seems ambiguous to me. As a non-RealBasic programmer, I can see at > least four meanings it could have. Translated into Python, they are: > > LogError("Walk has gotten too silly", CurrentTime) > LogError("Walk has gotten too silly"), CurrentTime > LogError("Walk has gotten too silly", CurrentTime()) > LogError("Walk has gotten too silly"), CurrentTime() > > Of course this assumes that RealBasic has an equivalent of tuples, and > treats functions as first class objects. > > But even if RB doesn't have these things, I question that the syntax is > "beautiful". Consider some arbitrary method Foo. If you see this: > > ? ? Foo > > Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo > does. If it returns no result, then it's legal. If it returns a result, > it isn't. So the question of whether syntax is legal depends, not on the > syntactic elements involved, but on the *semantics* of the method > (whether or not it returns a result). If you could deduce the semantics of a function from the syntax always, you could follow Erik's observation about Logo. Then expressions would have unique interpretations, except where a function takes no arguments and functions are first class objects. In other words, g f "abc" 123 would have an exact meaning, since f would just get the innermost n arguments, that since 'n' would be a known quantity. (Order of precedence would handle 'g f "abc" + "123"'.) > > Eliminating unnecessary parentheses does a lot to improve the > > readability of the code IMHO. > > But they're not unnecessary, at least not in Python, they're useful for > distinguishing between calling the function and the function itself. Natural language doesn't have the equivalent of parentheses, which goes back to Steven's point about a beautiful math structure vs. a beautiful NL sentence. Did anyone have to diagram sentences in grammar school? It's not like the essentials for communication involve deeply nested sentences; you can get by with a few simple declarations, so you and your company will reject anything "higher- order". From castironpi at gmail.com Wed Jan 21 04:02:37 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 01:02:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Jan 17, 11:28?pm, Steven D'Aprano wrote: > On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote: > > Russ P. a ?crit : > >> On Jan 15, 12:21 pm, Bruno Desthuilliers > >> wrote: > > >>> Once again, the important point is that there's a *clear* distinction > >>> between interface and implementation, and that you *shouldn't* mess > >>> with implementation. > > >> If you "*shouldn't* mess with the implementation", then what is wrong > >> with enforcing that "shouldn't" in the language itself? > > Russ: There are SHOULD NOTs and there are MUST NOTs. snip > >>> class Parrot: > > ... ? ? _private = 'spam' > ...>>> p = Parrot() > >>> p._private = 'ham' ?# allowed by default > >>> from protection import lock > >>> lock(p)._private > >>> p._private = 'spam' > > Traceback (most recent call last): > ? File "", line 1, in > ProtectionError: attribute is read-only from outside of class Parrot > > Would that be so bad? I don't think so. Sorry, I didn't see the last part originally. I don't think 'outside of class Parrot' is well-defined in Python. Does '_private' have to be a member of 'Parrot', an instance of 'Parrot', or the calling instance of 'Parrot', before entering the calling scope, or at the time the call is made? Since many of these can change on the fly, there's more than one consistent interpretation to the syntax. From reyjexter at gmail.com Wed Jan 21 04:04:53 2009 From: reyjexter at gmail.com (reyjexter) Date: Wed, 21 Jan 2009 01:04:53 -0800 (PST) Subject: Locking blockl to a people on a similar group / naming locks Message-ID: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> Hello! Is there a way to lock a certain block to a people on similar group? In java this is done by like this: synchronize (myGroup) { } but how do I do this in python? how can I name the lock that will be used by the thread? -rey From http Wed Jan 21 04:06:41 2009 From: http (Paul Rubin) Date: 21 Jan 2009 01:06:41 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <7xd4eh81um.fsf@ruckus.brouhaha.com> Thomas Guettler writes: > I want to start Python at the client side from a web > application. The app is an intranet application, and all client PCs > are under our control (we can install software on them). Is it supposed to be OS independent? If not, is it for a specific OS? Which one? From http Wed Jan 21 04:09:48 2009 From: http (Paul Rubin) Date: 21 Jan 2009 01:09:48 -0800 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> Message-ID: <7x8wp581pf.fsf@ruckus.brouhaha.com> reyjexter writes: > synchronize (myGroup) { > } > > but how do I do this in python? how can I name the lock that will be > used by the thread? You have to do it explicitly, for example with RLock: myInstance.lock = RLock() ... myInstance.lock.acquire() ... critical section ... myInstance.lock.release() It's often possible to write in a style that avoids this mess. The preferred way is usually to write isolated threads that communicate by passing objects through queues (Queue.Queue). This gets rid of a lot of locking hazards. From xahlee at gmail.com Wed Jan 21 04:13:03 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 21 Jan 2009 01:13:03 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> Message-ID: <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Rhodri James wrote: > I recommend spending less time being certain that you are correct > without seeking evidence I don't concur. For instance, when you are talking to a bunch of kids, you have to be sure of yourself, else they run all over you, even if they didn't mean to be rude. Also, one's demeanor must commensurate one's knowledge. If i pamper you, you might think i'm a whimp, and run on with your opinions and thoughts unbridled, which, can be considered as a miscommunication on my part. Xah ? http://xahlee.org/ ? From spam.buster at web.de Wed Jan 21 04:42:19 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 10:42:19 +0100 Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Rhodri James wrote: > I *was* thinking of code produced in the real world, and I don't buy > your assertion. I'm not an academic, and I wouldn't hesitate to lay > down a line of code like that. As I said before, it fits into English > language idioms naturally, and as a result is pretty self-descriptive. As a non-native speaker and non-academic, I don't understand the "fittine into English language idioms naturally" which is mentioned here in the different subthreads. Could you try to explain that for me? TIA -- Cheerz Lars From deets at nospam.web.de Wed Jan 21 04:43:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 10:43:30 +0100 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> <7x8wp581pf.fsf@ruckus.brouhaha.com> Message-ID: <6to922FbvhdrU1@mid.uni-berlin.de> Paul Rubin wrote: > reyjexter writes: >> synchronize (myGroup) { >> } >> >> but how do I do this in python? how can I name the lock that will be >> used by the thread? > > You have to do it explicitly, for example with RLock: > > myInstance.lock = RLock() > ... > myInstance.lock.acquire() > ... critical section ... > myInstance.lock.release() In python 2.5 and upwards, you can write this safer from __future__ import with_statement # only needed for py2.5 with myInstance.lock: ... critical section Diez From spam.buster at web.de Wed Jan 21 04:44:38 2009 From: spam.buster at web.de (Lars Behrens) Date: Wed, 21 Jan 2009 10:44:38 +0100 Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: Lars Behrens wrote: > As a non-native speaker and non-academic, I don't understand the "fittine "fitting", I meant. Sorry ^^ -- Cheerz Lars From aberry at aol.in Wed Jan 21 04:51:09 2009 From: aberry at aol.in (aberry) Date: Wed, 21 Jan 2009 01:51:09 -0800 (PST) Subject: smtplib.SMTP throw : 'Socket error: 10053 software caused connection abort' In-Reply-To: <21565011.post@talk.nabble.com> References: <21565011.post@talk.nabble.com> Message-ID: <21579963.post@talk.nabble.com> aberry wrote: > > I am using 'smtplib' module to send an email but getting exception... > > smtplib.SMTP( throw error : > > here is trace back snippet :- > > " smtp = smtplib.SMTP(self.server) > File "D:\Python24\lib\smtplib.py", line 244, in __init__ > (code, msg) = self.connect(host, port) > File "D:\Python24\lib\smtplib.py", line 306, in connect > raise socket.error, msg > socket.error: (10053, 'Software caused connection abort')" > > thanks in adv, > aberry > > problem resolved :) ... culprit was Anti Virus running on my Win XP machine... I disabled AV On Access scan... no Error and email sent rgds, aberry -- View this message in context: http://www.nabble.com/smtplib.SMTP-throw-%3A-%27Socket-error%3A-10053-software-caused-connection-abort%27-tp21565011p21579963.html Sent from the Python - python-list mailing list archive at Nabble.com. From vinay_sajip at yahoo.co.uk Wed Jan 21 04:55:11 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 21 Jan 2009 01:55:11 -0800 (PST) Subject: Logging help References: Message-ID: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> On Jan 20, 10:11 am, koranthala wrote: > > The doRollover method does not append to the earlier file. Rather, it > creates a new file with the same name. Err... that's what rollover means - switching to a new log file (and renaming the old ones). If it just appended to the old one, why would it be called doRollover ? ;-) Regards, Vinay Sajip From bbxx789_05ss at yahoo.com Wed Jan 21 04:57:52 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 21 Jan 2009 01:57:52 -0800 (PST) Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <41fde0a7-98c2-4f36-8c6f-71d2559e2138@f40g2000pri.googlegroups.com> On Jan 21, 1:10?am, Thomas Guettler wrote: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. How does a web application on the client execute python code? From http Wed Jan 21 05:06:52 2009 From: http (Paul Rubin) Date: 21 Jan 2009 02:06:52 -0800 Subject: Locking blockl to a people on a similar group / naming locks References: <32c3b7bf-e8bd-4ba6-a8f1-f33f77b2e8ae@o4g2000pra.googlegroups.com> <7x8wp581pf.fsf@ruckus.brouhaha.com> <6to922FbvhdrU1@mid.uni-berlin.de> Message-ID: <7xr62x0y83.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > In python 2.5 and upwards, you can write this safer > from __future__ import with_statement # only needed for py2.5 > with myInstance.lock: > ... critical section Good point! From jstroud at mbi.ucla.edu Wed Jan 21 05:10:45 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 21 Jan 2009 02:10:45 -0800 Subject: Start Python at client side from web app In-Reply-To: <6to3kfFbr0psU1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. > > Has someone seen or done something like this before? > > I can code this myself, but prefer to use some open source project, if it exists. > > > Thanks in advance, > Thomas G?ttler > You are better off using a cron job (or similar) on the client side, getting the client to hit the web server for the code at regular intervals, and if code is ready, execute. If code isn't ready, wait for the next interval. Use https for security and have a shared secret message to identify legitimate clients. If you try to push code the other way, you will need a perpetual socket open on the client side, making the client the server. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From http Wed Jan 21 05:12:11 2009 From: http (Paul Rubin) Date: 21 Jan 2009 02:12:11 -0800 Subject: what's the point of rpython? References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <7xvds9q878.fsf@ruckus.brouhaha.com> Brendan Miller writes: > I'm curious about that. I've been looking around for timing > information on the lock signal, but am having some trouble finding > them. Intuitively, given that the processor is much faster than the > bus, and you are just waiting for processor to complete an addition or > comparison before put the new memory value on the bus, it seems like > there should be very little additional bus contention vs a normal add > instruction. The bus is slow compared with the L1 cache. I just looked for figures and couldn't find any either, but I remember seeing some for the Core 2 saying around 100 cycles, and something similar for the Athlon. I just came across something saying the Core i7 is considerably better than the Core 2 at this. The real solution is to not use so much bus locking. Get rid of the ref counts and use a real gc, if not in CPython then in PyPy. From deets at nospam.web.de Wed Jan 21 05:21:34 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 11:21:34 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <6tob9eFbqi6gU1@mid.uni-berlin.de> James Stroud wrote: > Thomas Guettler wrote: >> Hi, >> >> I want to start Python at the client side from a web application. The >> app is an intranet application, and all client PCs are under our control >> (we can install software on them). >> >> But I don't want to update the installation too often. Here is my idea: >> >> We create a custom mime-type and register it on the client PC. The web >> application can send signed python code to the client PC. If the >> signature is correct, the code will be executed at the client. The >> signature prevents others from executing code. >> >> Has someone seen or done something like this before? >> >> I can code this myself, but prefer to use some open source project, if it >> exists. >> >> >> Thanks in advance, >> Thomas G?ttler >> > > You are better off using a cron job (or similar) on the client side, > getting the client to hit the web server for the code at regular > intervals, and if code is ready, execute. If code isn't ready, wait for > the next interval. Use https for security and have a shared secret > message to identify legitimate clients. > > If you try to push code the other way, you will need a perpetual socket > open on the client side, making the client the server. If the OP finds a method to trigger the execution of his program, the question of who's client and who not is moot. If he wants, he can make the software query a server via HTTP (he's got that up & reachable from the PC anyway) for it's new code. All he needs is some session-key being passed on invocation. Diez From mynthon1 at gmail.com Wed Jan 21 05:50:53 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 02:50:53 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long Message-ID: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> I have very long path on windows and i get error when try to get modification time. So i tried do chdir path and then get file. It now gives me error that file doesn't exists # code def getmtimeWIN32(p): mycwd = os.getcwd() if p.startswith('\\\\?\\'): p = p.replace('\\\\?\\', '', 1) p = os.path.splitdrive(p) r = p[0] # root - dir name p = p[1] p = os.path.split(p) f = p[1] # filename d = p[0] l = d.split('\\'); if r != '': # if root is not empty change to root (it not works when script is on other partition than file) os.chdir('/') for i in l: if i != '': os.chdir(i) #print i print os.getcwd() os.path.getmtime(f) os.chdir(mycwd) # /code it works for other files so i suppose it is not my fault. I know there is a win32 module but i can't find any documentation for it (what is the purpose to create app without docs?). Any idea? I searched google but there where only 2 options. Use chdir (not working) or use win32api (where is no documentation). (python 2.5) From hv at tbz-pariv.de Wed Jan 21 06:17:16 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 21 Jan 2009 12:17:16 +0100 Subject: Start Python at client side from web app In-Reply-To: <6to3kfFbr0psU1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: <6toehtFbrb81U1@mid.individual.net> Sorry, I described my problem not well. Here is more information: The main application is the intranet web application used with IE (ms windows client). But some action needs to be done on the client since you can't do it with html or javascript. 1. The user pushes a button in the web app. 2. Webserver sends signed python code to the client with own mime type 3. IE sends code to the python application. 4. Signature gets checked, Python code on the client gets executed. 5. Maybe send some data to the server with http. Thomas Server runs Linux with Django and Postgres. Thomas Guettler schrieb: > Hi, > > I want to start Python at the client side from a web application. The > app is an intranet application, and all client PCs are under our control (we > can install software on them). > > But I don't want to update the installation too often. Here is my idea: > > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. > > Has someone seen or done something like this before? > > I can code this myself, but prefer to use some open source project, if it exists. > > > Thanks in advance, > Thomas G?ttler > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From deets at nospam.web.de Wed Jan 21 06:21:57 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 12:21:57 +0100 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6toeqlFbrcfoU1@mid.uni-berlin.de> Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms > windows client). But some action needs to be done on the client since you > can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. As I already told you on the german python NG (why do you post on *two* lists?), I'd rather go for a custom network protocol. This is supported by the various OSses, and browsers just hook into it. Then, when the user presses a "myprotocol://some/parameters"-link (or get's redirected there through JS), the registered application will be fired up to handle the url. You then simply use the passed parameters to make a call to your webserver to fetch the new code. Diez From sturlamolden at yahoo.no Wed Jan 21 06:31:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 21 Jan 2009 03:31:26 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: <1105f65d-16d0-441c-9cd2-89c4011eb403@v39g2000pro.googlegroups.com> On Jan 21, 12:13 am, sturlamolden wrote: > Apart from that, an FFT in pure python is going to be atrociously slow > for anything but the shortest signals. I cannot imagine why you want > to do this. Just to elaborate on this: The whole purpose of using FFT is speed. That pretty much excludes the use of Python. If you don't care about speed, you could just as well compute the DFT directly. The FFT is just a O(n lon n) algorithm for computing the DFT. Here is a DFT with O(N**2) behavior: from math import sin, cos, pi def real_dft(x): ''' DFT for a real valued sequence x ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 for n in range(M): s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) r.append(s) return r S.M. From skip at pobox.com Wed Jan 21 06:31:45 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 21 Jan 2009 05:31:45 -0600 Subject: what's the point of rpython? In-Reply-To: References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <18807.1953.921513.129961@montanaro.dyndns.org> Brendan> Intuitively, given that the processor is much Brendan> faster than the bus, and you are just waiting for processor to Brendan> complete an addition or comparison before put the new memory Brendan> value on the bus... I think in Python's case the reference count will often be in the processor's local cache. (Presumably, if the current thread is going to Py_DECREF the object it's been working with the object's state recently.) The stuff I read suggested that simply locking the local cache would be significantly faster than having to lock the memory bus. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 06:54:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 12:54:31 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <49770cf1$0$3521$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > In any case, I have suggested that Python should perhaps get a new > keyword, "private" or "priv". And quite a few people - most of them using Python daily - answered they didn't wan't it. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:01:34 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:01:34 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> Message-ID: <49770e98$0$18763$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Since when is no one is allowed to suggest a potential improvement to > a product unless they are willing to implement it themselves? Imagine > what the world would be like if such a rule applied to all products. There are two points here. The first one is whether what you suggest is seen as "a potential improvement", by the language's designers and by the majority of the language's users. The answer here is obviously "no". The second point is about your vision of Python as "a product". It is not - at least, not in the sense of a "commercial product". It's a FOSS project, and this effectively means that if you really want to get something done, specially when almost no one seems interested, you *do* have to DoItYourself(tm). But I *really* doubt it'll make it Python anyway. IOW : if you want access restrictions in Python, fork the project and do what you want with your fork (as long as you respect the Python licence of course). From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:04:39 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:04:39 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> Message-ID: <49770f51$0$743$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > Your mistake for being a moron. But it seems to happen regularly, > doesn't it. How much more of my time are you going to waste, loser? Calling people names is certainly not the best way to defend your opinions here. Adios, Mr. P. From digitig at gmail.com Wed Jan 21 07:11:11 2009 From: digitig at gmail.com (Tim Rowe) Date: Wed, 21 Jan 2009 12:11:11 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xwscpyvrd.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> <7xwscpyvrd.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/21 Paul Rubin <"http://phr.cx"@nospam.invalid>: > I have no direct experience with it but have read a little about it. > It looks to be a fairly vanilla block structured imperative language > like Pascal with some concurrency stuff added. The sense I have is > that it's not especially harder to program in than C or C++, but the > programs come out much more reliable. It is rather more than that, in that it's particularly strict (and it has a particularly powerful arithmetic model), but its roots are certainly there. At a conference on the safe subset, SPARK Ada, one of the SPARK developers pointed out that the SPARK Ada subset was effectively Modula2. Programs done in Ada are, by objective measures, more reliable than those done in C and C++ (the very best released C++ programs are about as good as the worst released Ada programs), although I've always wondered how much of that is because of language differences and how much is because Ada tends to be used on critical projects that also tend to get a lot more attention to development standards. -- Tim Rowe From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 21 07:19:46 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 21 Jan 2009 13:19:46 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xprih5d5z.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> Message-ID: <497712dc$0$7896$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> Zope is about 375 KLOC[1], >> How many LOCS would it require if it was written in ADA ? > > No idea. Ada is a lot more verbose than Python, but I'm baffled at > what the heck Zope is actually doing with all that code. > >>> Zope also has 275 open bugs, 6 of which are critical. >> None of which are going to *kill* anyone FWIW. Now how many of these >> bugs would have language-enforced access restriction prevented ? > > I'm not about to audit 375 KLOC of code to find out. Regardless of > whether access restriction actually prevents bugs though, it certainly > makes auditing easier. pylint is your friend. > And auditing does find bugs. > >>> [2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC >> of a hi-level dynamic language ? Hm, I guess not. > > I think written in some forerunner of Ada. Yeps, probably something like this. Not specially hi level nor dynamic, is it ? >> Given the difference in LOCS count between a low-level static language >> and a hi-level dynamic language for the implementation of a same given >> features set, you cannot just define "large" by the # of LOCS. Not >> that I'm going to compare Zope with Space shuttle's stuff. > > I don't think static vs dynamic makes much difference in the amount of > LOCS to accomplish some function. My own experience is that it does make a huge difference - talking about imperative languages, of course. > In my limited experience with > Haskell (statically typed but very high level), "dynamic" and "static" were not meant to concern typing here (or at least not only typing). Haskell and MLs are indeed statically typed, but with a powerfull type inference system, which gives great support for genericity (hmmm... is that the appropriate word ?) Now these are functional languages, so the notion of "access restriction" is just moot in this context !-) > it takes around the > same amount of Haskell code as Python code (sometimes more, sometimes > less) to do a given task. Not exactly my own experience, but I confess I'm much more fluent with Python than with Haskell !-) > More important for concise code is features > like higher-level functions and types (e.g. it's easy in Python or > Haskell, but a huge pain in Java or C, to write down a value that is a > list of dictionaries whose keys are tuples and whose values are more > lists of dictionaries, to code something list a listcomp, etc). Yes, indeed. So you agree that Haskell is not exactly a "low level" language, do you ?-) Ok, I should probably have made clear I was thinking of a hi-level dynamic _imperative_ language vs a low-level static _imperative_ language. FP is quite another world. From mdw at distorted.org.uk Wed Jan 21 07:45:58 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 12:45:58 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87d4eghlo9.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > I'm not sure what you mean by "conflating module and class systems." > Are you referring to the fact that Java requires each class to be in > its own file of the same name (I don't use Java, but that's what I've > heard)? If so, I agree that is a bad idea. No. I mean that using classes as a unit of access control is wrong. A class is a unit of behaviour, but that behaviour can (and often should) come from a number of places. Common Lisp gets this right. Classes define slots for their instances; slots are named by symbols. If you can write the symbol, you can access the slot. But symbols are managed by packages: packages can export some symbols and keep others internal; and they can import symbols from other packages. The same mechanism works for functions, variables, classes, types, macros, and all the other random namespaces that Lisp (like most languages) has. Python keeps access control separate from classes. And I think I'd like it to stay that way. (Lisp's package system also solves the problem that a class's -- and its superclasses' -- attributes and methods form a namespace which isn't well-managed in many languages. Since CL uses symbols for these, and symbols belong to packages, MDW::MUMBLE isn't the same symbol as RUSS-P::MUMBLE and so they name different slots.) -- [mdw] From mdw at distorted.org.uk Wed Jan 21 07:55:32 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 12:55:32 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <7x1vux1722.fsf@ruckus.brouhaha.com> Message-ID: <8763k8hl8b.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Which is why I was hoping that Python might get enforced data hiding > as well as optional static type declarations that can actually be used > for static verification. But maybe that's all just a pipe dream on my > part -- or "onanism." I think that, if you want static assurances, Python -- or any dynamic language, for that matter -- just isn't for you. Please feel free to use Java, C#, C++, or more interesting languages like ML variants or Haskell -- or even Ada dialects, which (I should have mentioned) do seem to have some very impressive proof-maintenance tools available for them. -- [mdw] From mynthon1 at gmail.com Wed Jan 21 08:13:35 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 05:13:35 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> Message-ID: <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> On Jan 21, 11:50?am, mynthon wrote: > I have very long path on windows and i get error when try to get > modification time. So i tried do chdir path and then get file. It now > gives me error that file doesn't exists > > # code > def getmtimeWIN32(p): > ? ? mycwd = os.getcwd() > > ? ? if p.startswith('\\\\?\\'): > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > ? ? p = os.path.splitdrive(p) > ? ? r = p[0] # root - dir name > ? ? p = p[1] > ? ? p = os.path.split(p) > ? ? f = p[1] # filename > ? ? d = p[0] > ? ? l = d.split('\\'); > > ? ? if r != '': # if root is not empty change to root (it not works > when script is on other partition than file) > ? ? ? ? os.chdir('/') > > ? ? for i in l: > ? ? ? ? if i != '': > ? ? ? ? ? ? os.chdir(i) > ? ? ? ? ? ? #print i > ? ? print os.getcwd() > ? ? os.path.getmtime(f) > ? ? os.chdir(mycwd) > # /code > > it works for other files so i suppose it is not my fault. I know there > is a win32 module but i can't find any documentation for it (what is > the purpose to create app without docs?). Any idea? > > I searched google but there where only 2 options. Use chdir (not > working) or use win32api (where is no documentation). > > (python 2.5) ok, what ive found: os.chdir('very_long_path') # works os.listdir('very_long_path') # gives: Traceback (most recent call last): File "", line 1, in TypeError: listdir() argument 1 must be (buffer overflow), not str os.chdir('very_long_path') os.listdir('.') #works os.chdir('very_long_path') os.path.getmtime(os.listdir('.')[0]) #throws exception (path not exists) os.chdir('very_long_path') open(os.listdir('.')[0]) #throws exception (path not exists) From steve at holdenweb.com Wed Jan 21 08:31:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:31:44 -0500 Subject: How to print lambda result ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF6024E9B29@enbmail01.lsi.com> <4975C1F9.6040607@wildenhain.de> <7F0503CD69378F49BE0DC30661C6CCF6024E9B2D@enbmail01.lsi.com> Message-ID: Because your print statement defines the lambda without calling it. regards Steve Barak, Ron wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. > Bye, > Ron. > > > -----Original Message----- > From: Tino Wildenhain [mailto:tino at wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: How to print lambda result ? > > Hi, > > Barak, Ron wrote: >> Hi, >> >> Wanting to print the correct plural after numbers, I did the following: >> >> for num in range(1,4): >> string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") >> print string_ >> >> However, instead of getting the expected output: >> >> 1 event >> 2 events >> 3 events >> >> I get: >> >> 1 event at 0x00AFE670> >> 2 event at 0x00AFE670> >> 3 event at 0x00AFE6B0> > > lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. > > (num,(lambda n: n >1 and "s" or "")(num)) > > which is just a quite useless application of lambda :-) > > (num,num >1 and "s" or "") > > or even > > (num,"s" if num >1 else "") > > in python > 2.5 > > or in python <3.0: > > (num,"s"*(num >1)) > > :-) > > HTH > Tino > -- > http://mail.python.org/mailman/listinfo/python-list > -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:34:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:34:19 -0500 Subject: Problem with 3.0 Install on Windows In-Reply-To: References: Message-ID: Saul Spatz wrote: > I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get > familiar with it. I have a directory with all my python projects in my > PYTHONPATH variable. When I try to run python 3.0, it detects a syntax > error (a print statement) in the first file in this directory, and > crashes. I don't want to convert the files to 3.0 syntax, because I > plan to keep using 2.5, at least for a while. > What's the name of that file? Does it clash with some system module that the interpreter is trying to load? In circumstances like this a traceback printout is always more helpful than a verbal description of the behavior. > I don't know exactly why this translation is happening. Is there a way > to turn it off? > "Translation"? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:37:25 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:37:25 -0500 Subject: How to write a simple shell loop in python? In-Reply-To: <1232509966.4430.28.camel@pippi.pippi> References: <1232509966.4430.28.camel@pippi.pippi> Message-ID: <49772515.90306@holdenweb.com> Dietrich Bollmann wrote: > Hi, > > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > > Is there any logic explanation for this? > How can I get rid of the blank? > Is there a smarter way to write a simple shell loop which would work > better? > > Thanks, Dietrich > > > Here my approach: > > $ python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() Just replace the lines above with input = raw_input("$ ") and you'll be fine. The "," in the print statement causes the interpreter to set a flag to emit a space before the next output unless it has just printed a newline. The "newline", of course, is provided by the input, so the next print emits a space since it *hasn't* just emitted a newline. regards Steve > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one > one > one > one > $ two > two > two > two > $ three > three > three > three > $ > Traceback (most recent call last): > File "", line 3, in > KeyboardInterrupt > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 21 08:47:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 08:47:48 -0500 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <62dabb78-e2c5-4947-931c-7655657d75fc@a39g2000prl.googlegroups.com> Message-ID: Xah Lee wrote: > On Jan 19, 11:17 pm, alex23 wrote: > ... [...] > sure. In a political context, many criticism or description of the > situation from one party can be seen as ad hominem attack. I feel that > that many old emacs users, which includes significant portion of emacs > developers (if not majority), are so exteremly bottled up and turn > down any possibility of advancing. They are killing emacs. (similar > feelings for most regular posters here in comp.lang.lisp ) > This might have been relevant if you had not been too stupid to observe that you are (sigh, yet again) posting irrelevant drivel to comp.lang.python. Please stop. [...] > Your input will be highly valued. Though, forgive me to say, that i > think my opinion on this is beyond any computer scientist of any > standing can try to tell me otherwise. If they disagree (which i think > most of them won't), i think their knowledge and experience in the > area of computer languages and syntax and notations, IQ, are inferior > to me. > How very comforting for you. "Closed mind" hardly begins to describe that attitude. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mynthon1 at gmail.com Wed Jan 21 08:58:37 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 05:58:37 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> Message-ID: On Jan 21, 2:13?pm, mynthon wrote: > On Jan 21, 11:50?am, mynthon wrote: > > > > > I have very long path on windows and i get error when try to get > > modification time. So i tried do chdir path and then get file. It now > > gives me error that file doesn't exists > > > # code > > def getmtimeWIN32(p): > > ? ? mycwd = os.getcwd() > > > ? ? if p.startswith('\\\\?\\'): > > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > > ? ? p = os.path.splitdrive(p) > > ? ? r = p[0] # root - dir name > > ? ? p = p[1] > > ? ? p = os.path.split(p) > > ? ? f = p[1] # filename > > ? ? d = p[0] > > ? ? l = d.split('\\'); > > > ? ? if r != '': # if root is not empty change to root (it not works > > when script is on other partition than file) > > ? ? ? ? os.chdir('/') > > > ? ? for i in l: > > ? ? ? ? if i != '': > > ? ? ? ? ? ? os.chdir(i) > > ? ? ? ? ? ? #print i > > ? ? print os.getcwd() > > ? ? os.path.getmtime(f) > > ? ? os.chdir(mycwd) > > # /code > > > it works for other files so i suppose it is not my fault. I know there > > is a win32 module but i can't find any documentation for it (what is > > the purpose to create app without docs?). Any idea? > > > I searched google but there where only 2 options. Use chdir (not > > working) or use win32api (where is no documentation). > > > (python 2.5) > > ok, what ive found: > > os.chdir('very_long_path') > # works > > os.listdir('very_long_path') > # gives: > Traceback (most recent call last): > ? File "", line 1, in > TypeError: listdir() argument 1 must be (buffer overflow), not str > > os.chdir('very_long_path') > os.listdir('.') > #works > > os.chdir('very_long_path') > os.path.getmtime(os.listdir('.')[0]) > #throws exception (path not exists) > > os.chdir('very_long_path') > open(os.listdir('.')[0]) > #throws exception (path not exists) i dont have a solution but workaround. I can map long path as drive: longPath = "c:\\documents and settings\\usermth\\my documents\ \......blablablabla" # map path as drive b: (notice "" around path to avoid problems with spaces) os.system('subst b: "%s"' % longPath) longPath = 'b:\\' From mynthon1 at gmail.com Wed Jan 21 09:11:03 2009 From: mynthon1 at gmail.com (mynthon) Date: Wed, 21 Jan 2009 06:11:03 -0800 (PST) Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> <0824b4d6-4482-421f-982a-dd5743ca9693@l33g2000pri.googlegroups.com> Message-ID: <31d0d026-3e88-4730-8368-af76424f17ef@w1g2000prm.googlegroups.com> On Jan 21, 2:58?pm, mynthon wrote: > On Jan 21, 2:13?pm, mynthon wrote: > > > > > On Jan 21, 11:50?am, mynthon wrote: > > > > I have very long path on windows and i get error when try to get > > > modification time. So i tried do chdir path and then get file. It now > > > gives me error that file doesn't exists > > > > # code > > > def getmtimeWIN32(p): > > > ? ? mycwd = os.getcwd() > > > > ? ? if p.startswith('\\\\?\\'): > > > ? ? ? ? p = p.replace('\\\\?\\', '', 1) > > > > ? ? p = os.path.splitdrive(p) > > > ? ? r = p[0] # root - dir name > > > ? ? p = p[1] > > > ? ? p = os.path.split(p) > > > ? ? f = p[1] # filename > > > ? ? d = p[0] > > > ? ? l = d.split('\\'); > > > > ? ? if r != '': # if root is not empty change to root (it not works > > > when script is on other partition than file) > > > ? ? ? ? os.chdir('/') > > > > ? ? for i in l: > > > ? ? ? ? if i != '': > > > ? ? ? ? ? ? os.chdir(i) > > > ? ? ? ? ? ? #print i > > > ? ? print os.getcwd() > > > ? ? os.path.getmtime(f) > > > ? ? os.chdir(mycwd) > > > # /code > > > > it works for other files so i suppose it is not my fault. I know there > > > is a win32 module but i can't find any documentation for it (what is > > > the purpose to create app without docs?). Any idea? > > > > I searched google but there where only 2 options. Use chdir (not > > > working) or use win32api (where is no documentation). > > > > (python 2.5) > > > ok, what ive found: > > > os.chdir('very_long_path') > > # works > > > os.listdir('very_long_path') > > # gives: > > Traceback (most recent call last): > > ? File "", line 1, in > > TypeError: listdir() argument 1 must be (buffer overflow), not str > > > os.chdir('very_long_path') > > os.listdir('.') > > #works > > > os.chdir('very_long_path') > > os.path.getmtime(os.listdir('.')[0]) > > #throws exception (path not exists) > > > os.chdir('very_long_path') > > open(os.listdir('.')[0]) > > #throws exception (path not exists) > > i dont have a solution but workaround. > I can map long path as drive: > > longPath = "c:\\documents and settings\\usermth\\my documents\ > \......blablablabla" > > # map path as drive b: (notice "" around path to avoid problems with > spaces) > os.system('subst b: "%s"' % longPath) > > longPath = 'b:\\' you can also use \\?\ prefix but ONLY FOR unicode strings os.path.getmtime("\\\\?\\c:\\very lon path\\blablabla") #will not work os.path.getmtime(u"\\\\?\\c:\\very lon path\\blablabla") #will work From duncan.booth at invalid.invalid Wed Jan 21 09:31:46 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Jan 2009 14:31:46 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: Message-ID: Terry Reedy wrote: > Delaney, Timothy (Tim) wrote: >> Terry Reedy wrote: >> >>>> The compiled code differs. >>> I *strongly* doubt that. Properties are designed to be transparent to >>> user code that access atrributes through the usual dotted name >>> notation precisely so that class code can be changed from >>> x = ob >>> to >>> x = property(get_x, set_x, del_x) >>> without changing user code. >> >> He was talking about C# with that statement. In C#, the compiled code >> differs depending on whether you use a property or an attribute. Or at >> least that's how I interpreted it. > > Checking back, I see now that Luis Z. went from Python > "It boggles me when I see python code with properties that only set and > get the attribute, or even worse, getters and setters for that > purpose. " to C#, and that Duncan was seemingly responding to the C# > part. If C# is like that, how inconvenient. It's a long enough thread that I can't see anyone faulting you for falling asleep half way through my post. C# forces you to spend a lot of time writing trivial getters and setters. They've 'improved' it in the more recent versions: you no longer have to write any body at all for a trivial getter or setter and the compiler will generate one for you provided you have declared the property with a leading capital letter and a private attribute with the same name but a lowercase letter. Ick. > >> You are of course correct as to how Python does it. > > I guess I am spoiled ;-). > That's why we're all here. -- Duncan Booth http://kupuguy.blogspot.com From Tribulations at Paralleles.invalid Wed Jan 21 10:16:32 2009 From: Tribulations at Paralleles.invalid (TP) Date: Wed, 21 Jan 2009 16:16:32 +0100 Subject: is this pythonic? Message-ID: Hi, Is the following code pythonic: >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>> dict = [ dict for dict in l if dict['title']=='ti'] >>> l.remove(*dict) >>> l [{'title': 'to', 'value': 2}] Precision: I have stored data in the list of dictionaries l, because in my application I am sure that "title" is unique for each record. But perhaps it is better to imagine that someday it will not be anymore the case? And rather use a data storage as the following? l = { '001':{"title":"to", "value":2}, '002' {"title":"ti","value":"coucou"}} The problem with this storage is that it implies to manipulate some "ids" that have not any meaning for a humain being (001, 002, etc). Thanks a lot for you opinion, -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From aahz at pythoncraft.com Wed Jan 21 10:17:17 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 07:17:17 -0800 Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: In article <313a27f9-c655-4fc4-a8e3-568a4283bba2 at f40g2000pri.googlegroups.com>, ag73 wrote: > > form = urllib.parse.parse_qs(qs, keep_blank_values=1) > >However, the last line of code that calls parse_qs causes the >following exception to be thrown: > > >Type str doesn't support the buffer API One of the key features of Python 3.0 is the fact that it now distinguishes between bytes and strings. Unfortunately, there are a lot of ambiguous areas where the correct handling is not clear; for example, nobody has yet agreed whether URLs are strings or bytes. As you discovered, forced conversion to string seems to work here and I suggest you make that your workaround. You could also file a bug on bugs.python.org (first checking to see whether someone else has already done so). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From joe at strout.net Wed Jan 21 10:17:34 2009 From: joe at strout.net (Joe Strout) Date: Wed, 21 Jan 2009 08:17:34 -0700 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <49773C8E.2040905@strout.net> Steven D'Aprano wrote: >> LogError "Walk has gotten too silly", CurrentTime >> >> Here, LogError is a method call that takes two arguments, and >> CurrentTime is a method call that takes none. > > That seems ambiguous to me. As a non-RealBasic programmer, I can see at > least four meanings it could have. Translated into Python, they are: > > LogError("Walk has gotten too silly", CurrentTime) > LogError("Walk has gotten too silly"), CurrentTime > LogError("Walk has gotten too silly", CurrentTime()) > LogError("Walk has gotten too silly"), CurrentTime() It's not ambiguous because RB doesn't have a tuple syntax that looks the same as arguments to a function call. You also can't get a reference to a method simply by naming it; naming it invokes it (when you want a reference to it instead, you use the "AddressOf" keyword). So, the first and third of your lines above mean the same thing, and are the correct (and only possible) interpretation. The second and fourth are also equivalent, but would require the parentheses around the LogError parameter since in that case it is a function (i.e. returns a result). As I said before, I'm not sure how you would apply this to Python, where other syntax choices (tuples, function references, etc.) get in the way of this idea. I'm merely pointing out that what Aaron asked for is possible without ambiguity, and actually used in at least one real-world language. > But even if RB doesn't have these things, I question that the syntax is > "beautiful". Consider some arbitrary method Foo. If you see this: > > Foo > > Is that legal RB syntax? You betcha! For example, the built-in method to play the standard system alert sound is: Beep Doesn't get much more readable and syntax-free than that. Suppose now that a beep isn't eloquent enough, and you want the computer to speak something out loud instead. Also easy: Speak "Spam, spam, spam, baked beans and spam." If you're writing a console app, then there's a built in "Print" subroutine that puts a string to stdout. Its usage is: Print "Spam, spam, spam, baked beans and spam." Note that this syntax is exactly like Python's "print" syntax prior to 3.0, but in RB, it's not a special case -- it's just another method call, and you can define your own methods that you invoke exactly the same way. > Maybe yes, maybe no. It all depends on what Foo > does. If it returns no result, then it's legal. If it returns a result, > it isn't. Right. In other words, you can tell just by looking at the call that it doesn't return a result. This is often handy. > So the question of whether syntax is legal depends, not on the > syntactic elements involved, but on the *semantics* of the method > (whether or not it returns a result). But of course. Any method call is legal only if the form of the call matches the method prototype -- if you try to call a function that requires 4 parameters, and give it only 3, that's an error too. I don't see how this is different in any important way. >> Eliminating unnecessary parentheses does a lot to improve the >> readability of the code IMHO. > > But they're not unnecessary, at least not in Python, they're useful for > distinguishing between calling the function and the function itself. Yes, quite true in Python. If there were some other way to distinguish between those -- and if tuple syntax didn't look the same as method call arguments -- THEN they would be unnecessary. But those would be very substantial changes to Python syntax, and I'm not seriously proposing them. Best, - Joe From aahz at pythoncraft.com Wed Jan 21 10:19:44 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 07:19:44 -0800 Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible References: Message-ID: In article , Ben Sizer wrote: > >I have the following C++ code and am attempting to embed Python 2.5, >but although the "import sys" statement works, attempting to reference >"sys.path" from inside a function after that point fails. It's as if >it's not treating it as a normal module but as any other global >variable which I'd have to explicitly qualify. After skimming the thread and seeing a lack of answer, I suggest you try capi-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From google at mrabarnett.plus.com Wed Jan 21 10:24:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 15:24:01 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <8358b514-b7c7-47fc-93cb-0cbac968b041@k1g2000prb.googlegroups.com> <0586e2f2-6ca9-42d9-93b0-4cd8a419ad1a@r15g2000prh.googlegroups.com> Message-ID: <49773E11.3070804@mrabarnett.plus.com> Russ P. wrote: > On Jan 20, 10:02 pm, alex23 wrote: > >> Can I comprehend that you don't even have an immediate need and are >> instead actively engaging in online onanism? Absolutely. > > So anyone thinking beyond an "immediate need" is "engaging in online > onanism"? > That doesn't mean what you think it means. > Let's see. How long ago did the Python community start thinking about > Python 3? > > So I guess they're all a bunch of jerkoffs, eh? > From joe at strout.net Wed Jan 21 10:24:51 2009 From: joe at strout.net (Joe Strout) Date: Wed, 21 Jan 2009 08:24:51 -0700 Subject: English-like Python In-Reply-To: <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> Message-ID: <49773E43.3050101@strout.net> Aaron Brady wrote: > Where functions are first-class objects, a bare function object isn't > distinguishable either from its call. That depends not on whether functions are first-class objects, but on the *syntax* of function invocation vs. function reference. It just so happens than in Python, the syntax for the latter is the bare function identifier. But it wouldn't have to be -- you could use "@foo" or "{foo}" or "ref foo" or (as in RB) "AddressOf foo" or any number of other alternatives to accomplish the same thing, and functions would still be first-class objects. I'll grant that having any such syntax makes them *odd* first-class objects, since all other objects are referred to with a naked identifier, and invoked (if they are callable) with some other syntax. It'd be weird and inconsistent to have functions turn that around. But, despite being inconsistent, it might still be sensible, based on the observation that we generally need to invoke methods a lot more often than we need to get a reference to them. > I'm granting that it's useful > to return values a lot. For example: > > a= f > > could mean either, 'a= f' or 'a= f()'. Once again the return values > save the day. I think I agree (if I follow you correctly). But then some other syntax would be needed for when you really mean "a=f" (i.e., make 'a' refer to the same function as 'f'). Best, - Joe From mnations at gmail.com Wed Jan 21 10:45:27 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 07:45:27 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: This is something I've wondered about for a while. I know that theoretically Python is supposed to auto-recognize duplicate imports; however I've run into problems in the past if I didn't arrange the imports in a certain way across multiple files. As a result, I worry about conflicts that arise because something has been imported twice. So...I'm not sure if Python *always* gets this correct. Also, I understand what you're saying about the organization of files based on modules and maybe regrouping based on use. However I like the organization of my files to be a grouping of logical components in my application. This makes it easy to keep things separated and keeps files from getting to long (which takes longer to program because you're always bouncing up and down large files). As a result, if I have to worry about grouping by shared modules then it makes that more difficult. I think it would great to have access to a file (like the __init__.py file for packages) which all the files in the same directory would have access to for common imports. That way you could push out the repeated imports and also clean up the look a little bit as well. On Jan 7, 11:53?am, Paul McGuire wrote: > ...and don't worry about a possible performance issue of importing os > (or any other module) multiple times - the Pythonimportmanager is > smart enough to recognize previously importedmodules, and wontimport > them again. > > If a module uses the os module, then it shouldimportit - that's just > it. > > Another consideration might be that you are breaking up your own > programmodulestoo much. ?For instance, if I had a program in which I > were importing urllib in lots ofmodules, it might indicate that I > still have some regrouping to do, and that I could probably gather all > of my urllib dependent code into a single place. > > -- Paul From dnhkng at googlemail.com Wed Jan 21 10:52:51 2009 From: dnhkng at googlemail.com (Dr Mephesto) Date: Wed, 21 Jan 2009 07:52:51 -0800 (PST) Subject: quick beginners List comprehension question Message-ID: Hi, Im new to python, and OOP, and am trying to get a handle on list comprehension. Say I have a class Foo with a property called bar: class Foo: def __init__(self): self.bar = random.randint(1,100) and then I make a list of these objects: Newlist = [] for x in range(10): Newlist.append(Foo()) Now, suppose I wanted to triple the value of 'bar', I could always do: for x in range(10): Newlist[x].bar = Newlist[x].bar * 3 but can I do this using list comprehension? Thanks in Advance! From deets at nospam.web.de Wed Jan 21 10:57:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 21 Jan 2009 16:57:28 +0100 Subject: quick beginners List comprehension question References: Message-ID: <6touv8Fc32elU1@mid.uni-berlin.de> Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! No, as such, because list-comprehensions require you to have an *expression* in front of the iteration: resultlist = [ for in ] Now what you of course can do is this: def multiply(item): item.bar = item.bar * 3 [multiply(i) for i in items] However, doing this will make python produce a list of None-references - which is a waste. It's up to you if you care about that, but generally it is frowned upon because of that, and the fact that the conciseness of the list-comp here isn't really helping with the readability. Diez From google at mrabarnett.plus.com Wed Jan 21 11:03:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 16:03:42 +0000 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: <4977475E.5060705@mrabarnett.plus.com> Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! > You could reduce that to: for x in Newlist: x.bar *= 3 but I don't think you could do it with list comprehension. From philip at semanchuk.com Wed Jan 21 11:18:49 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 21 Jan 2009 11:18:49 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: On Jan 21, 2009, at 10:52 AM, Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) > > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 > > but can I do this using list comprehension? Thanks in Advance! Other answers have been good; to them I'll add the comment that list comprehensions are for *constructing* lists, not manipulating the elements thereof. HTH Philip From Scott.Daniels at Acm.Org Wed Jan 21 11:19:04 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 08:19:04 -0800 Subject: what's the point of rpython? In-Reply-To: References: <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: Brendan Miller wrote: > On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: >> .... Of course I'm aware of the LOCK prefix but it slows >> down the instruction enormously compared with a non-locked instruction. > > I'm curious about that. I've been looking around for timing > information on the lock signal, but am having some trouble finding > them. Intuitively, given that the processor is much faster than the > bus, and you are just waiting for processor to complete an addition or > comparison before put the new memory value on the bus, it seems like > there should be very little additional bus contention vs a normal add > instruction. The opcode cannot simply talk to its cache, it must either go directly to off-chip memory or communicate to other processors that it (and it alone) owns the increment target. --Scott David Daniels Scott.Daniels at Acm.Org From marco at sferacarta.com Wed Jan 21 11:29:24 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 21 Jan 2009 17:29:24 +0100 Subject: Importing modules In-Reply-To: References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: Mudcat wrote: > This is something I've wondered about for a while. I know that > theoretically Python is supposed to auto-recognize duplicate imports; > however I've run into problems in the past if I didn't arrange the > imports in a certain way across multiple files. I think you've probably had issues with circular imports (i.e. mutual dependencies), unless you can precisely remember what you were doing and what went wrong. > As a result, I worry about conflicts that arise because something has been imported twice. > So...I'm not sure if Python *always* gets this correct. It doesn't import twice, and never did. > Also, I understand what you're saying about the organization of files > based on modules and maybe regrouping based on use. However I like the > organization of my files to be a grouping of logical components in my > application. I can make up three or four different logical groupings in my applications... so what is 'logical' could not be the same for everyone, or from every point of view. From ppearson at nowhere.invalid Wed Jan 21 11:32:43 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 21 Jan 2009 16:32:43 GMT Subject: is this pythonic? References: Message-ID: <6tp11bFbtfrgU1@mid.individual.net> On Wed, 21 Jan 2009 16:16:32 +0100, TP wrote: > > Is the following code pythonic: > >>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>> l.remove(*dict) >>>> l > [{'title': 'to', 'value': 2}] > > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? [snip] 1. You probably don't want to use the name "dict". 2. I believe this code will fail if the number of dictionaries with title="ti" is not exactly 1. It that your intention? (You probably answered this question in the last paragraph quoted above, but I can't make it out.) -- To email me, substitute nowhere->spamcop, invalid->net. From Scott.Daniels at Acm.Org Wed Jan 21 11:38:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 08:38:28 -0800 Subject: How to write a simple shell loop in python? In-Reply-To: References: Message-ID: Dietrich Bollmann wrote: > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > Is there any logic explanation for this? Yes > How can I get rid of the blank? By not asking for it with the comma. > >>>> while (1): > ... print "$ ", > ... input = sys.stdin.readline() > ... input = input.strip() > ... print input > ... print input > ... print input > ... > $ one The one and \n above are from stdin, not stdout. So stdout thinks it is still on the same line as the $. > one The space separates the 'one' from the '$ ' that it output to stdout above. > one > one --Scott David Daniels Scott.Daniels at Acm.Org From google at mrabarnett.plus.com Wed Jan 21 11:39:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 16:39:37 +0000 Subject: quick beginners List comprehension question In-Reply-To: <6touv8Fc32elU1@mid.uni-berlin.de> References: <6touv8Fc32elU1@mid.uni-berlin.de> Message-ID: <49774FC9.4040802@mrabarnett.plus.com> Diez B. Roggisch wrote: > Dr Mephesto wrote: > >> Hi, >> Im new to python, and OOP, and am trying to get a handle on list >> comprehension. >> >> Say I have a class Foo with a property called bar: >> >> class Foo: >> def __init__(self): >> self.bar = random.randint(1,100) >> >> and then I make a list of these objects: >> >> Newlist = [] >> for x in range(10): >> Newlist.append(Foo()) >> >> Now, suppose I wanted to triple the value of 'bar', I could always do: >> >> for x in range(10): >> Newlist[x].bar = Newlist[x].bar * 3 >> >> but can I do this using list comprehension? Thanks in Advance! > > No, as such, because list-comprehensions require you to have an *expression* > in front of the iteration: > > resultlist = [ for in ] > > Now what you of course can do is this: > > def multiply(item): > item.bar = item.bar * 3 > > [multiply(i) for i in items] > > However, doing this will make python produce a list of None-references - > which is a waste. It's up to you if you care about that, but generally it > is frowned upon because of that, and the fact that the conciseness of the > list-comp here isn't really helping with the readability. > If you had: def multiply(item): item.bar = item.bar * 3 return item then: [multiply(i) for i in items] would return items. Still a bad idea, though, because you're using a list comprehension for its side-effect. From kdawg44 at gmail.com Wed Jan 21 11:50:33 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 11:50:33 -0500 Subject: Beating a Timeout Message-ID: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Hi, I am trying to write a python script that I can run to prevent a timeout of webpage. I have to use a system at work that keeps track of issues. I use this a couple of time an hour and it times out after 10 minutes. The system is really crummy and it rejects your username and password about 30-40 times before it takes it. It is supposed to integrate with Active Directory and I don't think it does it very well. So I have this open in Internet Explorer (its all in asp.net so it does not work in any other browser). I was hoping to have something simple like: #c:\Python25\python import urllib import urllib2 import time while True: result = urllib.urlopen("the_URL ") print "Retrieved Page" time.sleep(300) But this is not working.... The code on the page uses a hidden iFrame that has a javascript file that monitors the time and intiates the timeout. The src of the hidden iFrame is what I keep trying to grab. It is still timing out in IE. Once it times out in IE I get an error in my script saying: IOError: [Errno socket error] (10060, 'Operation timed out') The system is terrible but I am stuck with it. If it doesn't kick me out, at least its bearable... Thanks for any help you can provide. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From pecora at anvil.nrl.navy.mil Wed Jan 21 11:52:42 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 21 Jan 2009 11:52:42 -0500 Subject: quick beginners List comprehension question References: Message-ID: In article , Philip Semanchuk wrote: > > Other answers have been good; to them I'll add the comment that list > comprehensions are for *constructing* lists, not manipulating the > elements thereof. > > HTH > Philip Well this seems to work just fine. What am I missing: A=[1,2,3] print A A=[2*a for a in A] print A -- -- Lou Pecora From philbru at q.com Wed Jan 21 11:52:48 2009 From: philbru at q.com (philbru at q.com) Date: Wed, 21 Jan 2009 08:52:48 -0800 (PST) Subject: frequency analysis without numpy References: Message-ID: <17c237cd-8f34-474a-848b-f2fe15856c84@35g2000pry.googlegroups.com> On Jan 20, 3:13?pm, sturlamolden wrote: > Consider using Thompson's multitaper method, autoregression (maximum > entropy), or Welch method for your frequency estimates. Blackman- > Tuckey is also a possibility, but I see no reason to prefer that to > Welch. Multitaper and AR tends to be the better options though, but > they are not as fast as Welch' method. There is a fortran program named rainbow that has some dozen of these methods to compare with. Rainbow is located at http://www.digitalCalculus.com/demo/rainbow.html. I recommend Burg's method or AutoCorrelation but its data dependent for best choice. Phil From wuwei23 at gmail.com Wed Jan 21 11:58:15 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 08:58:15 -0800 (PST) Subject: is this pythonic? References: Message-ID: On Jan 22, 1:16?am, TP wrote: > Is the following code pythonic: > >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] > >>> dict = [ dict for dict in l if dict['title']=='ti'] > >>> l.remove(*dict) > >>> l > [{'title': 'to', 'value': 2}] Try not to use 'dict' or the name of any of the other built-in types as labels. You're stepping through an entire list just to pass another list to l.remove to step through and remove items from...in fact, given that list.remove deletes the -first- occurance of the item, you're asking it to loop through -again- to find the matching element which you've - already- detected. A better and cleaner approach would be to step through the list -once- and remove the item when you find it: for index, record in enumerate(l): if record['title'] == 'ti': l.pop(index) Or you could just use a list comprehension: l = [d for d in l if d['title'] == 'ti'] > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? It's always better to design for what you know you need, not what you may possibly need in the future. You say that you are sure that record titles are unique, so why not use them as the dictionary keys, with the values as the values: records = {'ti': 1, 'to': 2} This way your code can be replaced with: value = records.pop('ti') # if you want to know the value del records['ti'] # if you just want to delete the entry It's a lot simpler to work with and extend. From steve at holdenweb.com Wed Jan 21 12:04:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 21 Jan 2009 12:04:11 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: Lou Pecora wrote: > In article , > Philip Semanchuk wrote: > >> Other answers have been good; to them I'll add the comment that list >> comprehensions are for *constructing* lists, not manipulating the >> elements thereof. >> >> HTH >> Philip > > > Well this seems to work just fine. What am I missing: > > A=[1,2,3] > print A > A=[2*a for a in A] > print A > The fact that the lists to be multiplied are attributes of a list of objects, and therefore aren't themselves a list. Look more closely at the original poster's question. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kdawg44 at gmail.com Wed Jan 21 12:18:22 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 12:18:22 -0500 Subject: Beating a Timeout In-Reply-To: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Message-ID: <5caea3690901210918s27fcd220va72fb4c9e523f7e3@mail.gmail.com> Also, the actual JS code that does this simply uses a window.location.reload() to keep the session active. So I guess the only thing could be that eash urllib.urlopen call is seen as a new session? How can I make it part of the same session I am using in IE? Or am I a hundred miles off? Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Jan 21 12:26:32 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 21 Jan 2009 12:26:32 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: <4CB53724-61AC-4302-AE59-6D022DDB357E@semanchuk.com> On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote: > In article , > Philip Semanchuk wrote: > >> >> Other answers have been good; to them I'll add the comment that list >> comprehensions are for *constructing* lists, not manipulating the >> elements thereof. >> >> HTH >> Philip > > > Well this seems to work just fine. What am I missing: > > A=[1,2,3] > print A > A=[2*a for a in A] > print A You haven't manipulated the list A, you've simply overwritten it with a new list. From google at mrabarnett.plus.com Wed Jan 21 12:27:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:27:19 +0000 Subject: is this pythonic? In-Reply-To: References: Message-ID: <49775AF7.7070006@mrabarnett.plus.com> alex23 wrote: > On Jan 22, 1:16 am, TP wrote: >> Is the following code pythonic: >>>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>>> l.remove(*dict) >>>>> l >> [{'title': 'to', 'value': 2}] > > Try not to use 'dict' or the name of any of the other built-in types > as labels. > > You're stepping through an entire list just to pass another list to > l.remove to step through and remove items from...in fact, given that > list.remove deletes the -first- occurance of the item, you're asking > it to loop through -again- to find the matching element which you've - > already- detected. A better and cleaner approach would be to step > through the list -once- and remove the item when you find it: > > for index, record in enumerate(l): > if record['title'] == 'ti': > l.pop(index) > [snip] FYI, you shouldn't modify a list you're iterating over. > Or you could just use a list comprehension: > > l = [d for d in l if d['title'] == 'ti'] > The for-loop was removing the item where there's a match, so the list comprehension in this case should keep the item where there _isn't_ a match: l = [d for d in l if d['title'] != 'ti'] [remainder snipped] From google at mrabarnett.plus.com Wed Jan 21 12:28:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:28:20 +0000 Subject: Beating a Timeout In-Reply-To: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> Message-ID: <49775B34.3030402@mrabarnett.plus.com> K-Dawg wrote: > Hi, > > I am trying to write a python script that I can run to prevent a timeout > of webpage. I have to use a system at work that keeps track of issues. > I use this a couple of time an hour and it times out after 10 minutes. > The system is really crummy and it rejects your username and password > about 30-40 times before it takes it. It is supposed to integrate with > Active Directory and I don't think it does it very well. > > So I have this open in Internet Explorer (its all in asp.net > so it does not work in any other browser). I was > hoping to have something simple like: > > #c:\Python25\python > > import urllib > import urllib2 > import time > > while True: > result = urllib.urlopen("the_URL > ") > print "Retrieved Page" > time.sleep(300) > > But this is not working.... The code on the page uses a hidden iFrame > that has a javascript file that monitors the time and intiates the > timeout. The src of the hidden iFrame is what I keep trying to grab. > > It is still timing out in IE. Once it times out in IE I get an error in > my script saying: > > IOError: [Errno socket error] (10060, 'Operation timed out') > > The system is terrible but I am stuck with it. If it doesn't kick me > out, at least its bearable... > > Thanks for any help you can provide. > Have you looked at mechanize? http://wwwsearch.sourceforge.net/mechanize/ From wuwei23 at gmail.com Wed Jan 21 12:29:19 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:29:19 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> On Jan 22, 1:45?am, Mudcat wrote: > This is something I've wondered about for a while. I know that > theoretically Python is supposed to auto-recognize duplicate imports; > however I've run into problems in the past if I didn't arrange the > imports in a certain way across multiple files. As a result, I worry > about conflicts that arise because something has been imported twice. > So...I'm not sure if Python *always* gets this correct. Python -will- only import something once. Every time you import a module, Python looks up its module dictionary to see if it contains a module of that name. If not, it imports it, adds a new module object and binds the name to that object in the calling namespace. If it does exist, it retrieves the module object from the dict, and then binds the name to that object in the calling namespace. Its best to view each Python module as a completely independent namespace. If you need to use something from another module within that namespace, you need to import it. If I have a function 'f' in module 'm' that uses 'math.pow', I can't just import 'f' into a module that has imported 'math', I need to import 'math' into 'm'. Regardless of where the function (or class) ends up being used, where it is defined -must- have all of the imports that function needs to run. If you're having to set up your imports in a specific order, odds are you have either a circular dependency or are overusing 'from import *'. You should -never- (IMO) do something like 'from import x, y, z' in module 'a' and then 'from a import *' in module 'b'. If 'b' uses x, y & z, it should import them itself. If you -must- use 'import *', specify exactly what should be exported via '__all__'...in most cases, it should be restricted to only objects defined within that module. > I think it would great to have access to a file (like the __init__.py > file for packages) which all the files in the same directory would > have access to for common imports. That way you could push out the > repeated imports and also clean up the look a little bit as well. Well, you can always stick those imports into a 'common.py' and do 'from common import *' in each file that uses them. But doing so can be a pain to maintain and debug for anything more than the most simple of applications. Being able to see a module's dependencies clearly listed at the top of the file is exceptionally handy. From Tribulations at Paralleles.invalid Wed Jan 21 12:34:46 2009 From: Tribulations at Paralleles.invalid (TP) Date: Wed, 21 Jan 2009 18:34:46 +0100 Subject: is this pythonic? References: Message-ID: alex23 wrote: > Try not to use 'dict' or the name of any of the other built-in types > as labels. Ooooops... Moreover I know it... > You're stepping through an entire list just to pass another list to > l.remove to step through and remove items from...in fact, given that > list.remove deletes the -first- occurance of the item, you're asking > it to loop through -again- to find the matching element which you've - > already- detected. A better and cleaner approach would be to step > through the list -once- and remove the item when you find it: > > for index, record in enumerate(l): > if record['title'] == 'ti': > l.pop(index) Ok, I will use this solution. But it is less pythonic than list comprehensions. > Or you could just use a list comprehension: > > l = [d for d in l if d['title'] == 'ti'] Perhaps you mean rather: l = [d for d in l if d['title'] != 'ti'] ? In fact, I cannot use this solution, because I want to get back the dictionary with title 'ti', for another use (in fact, to add it to another list, see below). >> Precision: I have stored data in the list of dictionaries l, because in >> my application I am sure that "title" is unique for each record. But >> perhaps it is better to imagine that someday it will not be anymore the >> case? > > It's always better to design for what you know you need, not what you > may possibly need in the future. You say that you are sure that record > titles are unique, so why not use them as the dictionary keys, with > the values as the values: > > records = {'ti': 1, 'to': 2} > > This way your code can be replaced with: > > value = records.pop('ti') # if you want to know the value > del records['ti'] # if you just want to delete the entry > > It's a lot simpler to work with and extend. In fact, in my case, in cannot use this simple solution, because there are other fields in each dictionary, not only 2. I was not clear in my post. So my list is rather: l=[{"title":"to", "color":"blue", "value":2} {"title":"ti", "color":"red", "value":"coucou"}] So, I will rather use your solution: for index, record in enumerate(l): if record['title'] == 'ti': to_add_in_another_list = l.pop(index) another_list.append(to_add_in_another_list ) > It's always better to design for what you know you need, not what you > may possibly need in the future. Ok. Do all the programmers agree with this principle? -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From kyrie at uh.cu Wed Jan 21 12:34:57 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 12:34:57 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901211234.57944.kyrie@uh.cu> On Wednesday 21 January 2009 02:30:54 am Russ P. wrote: > That could work. As long as it's well-engineered (not a hack), well- > supported (part of the standard library), and does the job, that's > probably all that matters. But you keep failing to explay why do you need it to be _part of the standard_ library (or whatever). If you need it in your project, _use_ it. If you don't, then don't use it. If _you_ need that thing you call security, just use it already and quit complaining that we don't use it. Is there a policy in your project that you can't use any external? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From kdawg44 at gmail.com Wed Jan 21 12:38:45 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 12:38:45 -0500 Subject: Beating a Timeout In-Reply-To: <49775B34.3030402@mrabarnett.plus.com> References: <5caea3690901210850o6d0b8801s39868757a86aca84@mail.gmail.com> <49775B34.3030402@mrabarnett.plus.com> Message-ID: <5caea3690901210938g4999bfebw8278091b7d6f76d3@mail.gmail.com> Sorry about the last mesasge, I accidentally replied directly to the poster. So I now have: br = mechanize.Browser() br.open("theURL") while True: result = br.reload() print result print "Retrieved Page" time.sleep(300) But it still does not appear to be working... Shortly after I got the "Your session is about to expire" pop up. I will continue to monitor though. Is mechanize starting another session separate from my IE? Is there anyway to get my python to interact with the IE session if so? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Jan 21 12:41:02 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:41:02 -0800 (PST) Subject: is this pythonic? References: Message-ID: On Jan 22, 3:27?am, MRAB wrote: > FYI, you shouldn't modify a list you're iterating over. But I'm not. I'm building a new list and binding it to the same name as the original, which works perfectly fine (unless I'm missing something): >>> l = range(100) >>> l = [d for d in l if not d % 5] >>> l [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95] > The for-loop was removing the item where there's a match, so the list > comprehension in this case should keep the item where there _isn't_ a match: > > l = [d for d in l if d['title'] != 'ti'] Now that's a mistake. Cheers for the catch. From vedagaurav at gmail.com Wed Jan 21 12:49:08 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Wed, 21 Jan 2009 09:49:08 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error Message-ID: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Hi, I am trying to put some webpages into a mysql database using python (after some processing on the text). If I use Python 2.4.2, it works without a fuss. However, on Python 2.5, I get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4357: ordinal not in range(128) Before sending the (insert) query to the mysql server, I do the following which I think should've taken care of this problem: sqlStr = sqlStr.replace('\\', '\\\\') (where sqlStr is the query). Any suggestions? Thanks! Gaurav From kyrie at uh.cu Wed Jan 21 12:55:42 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 12:55:42 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xk58p4bhq.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <200901211255.42988.kyrie@uh.cu> On Tuesday 20 January 2009 09:52:01 pm Paul Rubin wrote: > Luis Zarrabeitia writes: > > > Whaat? Assuming a program is perfect unless a failure is proven > > > is not at all a sane approach to getting reliable software. It is > > > the person claiming perfection who has to prove the absence of failure. > > > > No, no. I meant that if pylint works as its specification says it would. > > Oh, I see. Well, that would be ok, except Pylint is not specified as > detecting the types of access that Russ is concerned with. It can't, > for example, flag uses of setattr that might affect a particular > class. That would take something a lot fancier. True. And I doubt that the C++ compiler will flag the pointers running wildly pointing to random memory addresses and accessing the data in there. I doubt that pointer will 'respect' the 'private' keyword. I also doubt that the C# or Java _compiler_ will prevent you from using reflection somehow to access that data. But somehow the discussion shifted from an optional requirement (giving you the chance to explicitly use 'from lock import unlock; o = unlock(obj)') to "it can't be done _ever_" (using setattr/getattr is as explicit as your analogous 'unlock' function). Btw, the correctness of a program (on a turing-complete language) cannot be statically proven. Ask Turing about it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From google at mrabarnett.plus.com Wed Jan 21 12:56:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 17:56:59 +0000 Subject: is this pythonic? In-Reply-To: References: Message-ID: <497761EB.5050507@mrabarnett.plus.com> alex23 wrote: > On Jan 22, 3:27 am, MRAB wrote: >> FYI, you shouldn't modify a list you're iterating over. > > But I'm not. I'm building a new list and binding it to the same name > as the original, which works perfectly fine (unless I'm missing > something): > [snip] I was referring to the code: for index, record in enumerate(l): if record['title'] == 'ti': l.pop(index) where you are enumerating and iterating over 'l', but also modifying 'l' with 'l.pop(index)'. From wuwei23 at gmail.com Wed Jan 21 12:58:57 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 09:58:57 -0800 (PST) Subject: is this pythonic? References: Message-ID: <709db477-373a-4aba-9c61-a4ee00ea217f@p36g2000prp.googlegroups.com> On Jan 22, 3:34?am, TP wrote: > > ? ? for index, record in enumerate(l): > > ? ? ? ? if record['title'] == 'ti': > > ? ? ? ? ? ? l.pop(index) > > Ok, I will use this solution. But it is less pythonic than list > comprehensions. Are you asking if it's less pythonic, or asserting? Because you'll find a lot of disagreement here: list comprehensions are used for constructing lists, not manipulating them. > Perhaps you mean rather: > > l = [d for d in l if d['title'] != 'ti'] > ? You are correct. I should never post past 3am :) > In fact, in my case, in cannot use this simple solution, because there are > other fields in each dictionary, not only 2. I was not clear in my post. > So my list is rather: > l=[{"title":"to", "color":"blue", "value":2} > {"title":"ti", "color":"red", "value":"coucou"}] I still find this a lot simpler: records = {'to': {'color': 'blue', 'value': '2'}, 'ti': {'color': 'red', 'value': 'coucou'}} > > It's always better to design for what you know you need, not what you > > may possibly need in the future. > > Ok. Do all the programmers agree with this principle? Have you seen the size of some of the threads here? It's hard to get two programmers to agree on variable names... :) But it's a practice that has served me well and it even has a catchy name[1]. Getting what you -need- to work is effort enough, if you don't have a definite use case for a feature then how do you know you've implemented it correctly? Write it when you need it. 1: http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It From aahz at pythoncraft.com Wed Jan 21 13:00:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 10:00:51 -0800 Subject: pep 8 constants References: Message-ID: In article , Brendan Miller wrote: > >PEP 8 doesn't mention anything about using all caps to indicate a constant. > >Is all caps meaning "don't reassign this var" a strong enough >convention to not be considered violating good python style? I see a >lot of people using it, but I also see a lot of people writing >non-pythonic code... so I thought I'd see what the consensus is. I've posted to python-dev requesting clarification; you may want to subscribe to follow the discussion yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From mnations at gmail.com Wed Jan 21 13:01:13 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 10:01:13 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> Message-ID: <86a336c4-66d1-4420-8f0e-d53b8d28085d@o40g2000prn.googlegroups.com> > I think you've probably had issues with circular imports (i.e. mutual > dependencies), unless you can precisely remember what you were doing and > what went wrong. That's possible, but circular imports become more of a hazard if you have to import in several locations. Unify that to one file, and those problems are much easier to avoid. And I don't remember exactly what the problem was, but I think it had to do with calling Tkinter in two different files. Somehow I was getting an error in one of the files and removing Tkinter from importing in one of the files solved it. > I can make up three or four different logical groupings in my > applications... so what is 'logical' could not be the same for everyone, > or from every point of view. That's not the point. The point is that multiple imports can be a limiting factor if the module imports don't happen to align with the model they'd like to use for their file layout. However playing around with the files, I guess it is possible to create a file that just does imports and then reference them all just like you would any other extension of the namespace. I created a file called imports and was able to access the sys module within it by importing all from imports and calling sys. That way at least all you have to do is import the one file each time. From soul.mirror1 at gmail.com Wed Jan 21 13:06:34 2009 From: soul.mirror1 at gmail.com (soul.mirror1 at gmail.com) Date: Wed, 21 Jan 2009 10:06:34 -0800 (PST) Subject: Mathematica 7 compares to other languages References: <13d5dff7-9aac-4385-91ee-d6e58177497f@i24g2000prf.googlegroups.com> <7db0371c-88f8-4984-bb0d-b2078147803e@f40g2000pri.googlegroups.com> <86bf2e29-5f8d-4349-94cf-d1561f0114e6@e1g2000pra.googlegroups.com> <20081204111115.7cee2ecc@usenot.de> Message-ID: <4d86021f-d25c-4b96-b1a2-3a0c162a6154@a26g2000prf.googlegroups.com> On Dec 4 2008, 5:11?am, Andreas Waldenburger wrote: > On Wed, 03 Dec 2008 20:38:44 -0500 Lew wrote: > > > Xah Lee wrote: > > > enough babble ... > > > Good point. ?Plonk. ?Guun dun! > > I vaguely remember you plonking the guy before. Did you unplonk him in > the meantime? Or was that just a figure of speech? > > teasingly yours, > /W Andreas Waldenburger, I hold up a mirror to your soul! A couple of years ago you started posting to the newsgroup comp.lang.java.programmer. Unlike most newbies, instead of lurking for a while and then contributing on-topic posts about Java, you jumped into the nearest available flamewar and immediately got in up to your neck. Then, on November 13, 2007, you stooped to intentionally misquoting one of your opponents. When he wrote http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e90afa4a20?dmode=source you quoted him thusly: http://groups.google.com/group/comp.lang.java.programmer/msg/0386cc91ce75a3c6?dmode=source A few days later, you did it again, misquoting this post http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d413549f499?dmode=source in this one: http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b23537c1b?dmode=source In both cases, you publicly portrayed this poor man as a pervert, even though, whatever his other faults, that is clearly not one of them. Since that date, you have continued to participate on and off in a flamewar with many of the same participants, including the one you so mistreated that November. In fact, it seems that the very SAME flamewar is still in progress, in another newsgroup, fourteen whole months later, and you are still in it up to your neck. Repeatedly you have claimed to be primarily motivated by finding the disrupting of newsgroups to be entertaining. This is tantamount to admitting to being a troll. If you have an excuse for your behavior, please speak now, and give your apology before the witnesses gathered here. If you do not, then know that your soul is forever tainted! From wuwei23 at gmail.com Wed Jan 21 13:12:39 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 21 Jan 2009 10:12:39 -0800 (PST) Subject: is this pythonic? References: Message-ID: <5f4ec57b-4ea5-4243-8262-8064c4034f8d@g39g2000pri.googlegroups.com> On Jan 22, 3:56?am, MRAB wrote: > I was referring to the code: > > ? ? ?for index, record in enumerate(l): > ? ? ? ? ?if record['title'] == 'ti': > ? ? ? ? ? ? ?l.pop(index) > > where you are enumerating and iterating over 'l', but also modifying 'l' > with 'l.pop(index)'. Ack, you're absolutely correct. TP: my mistake, the for loop won't work at all. I'd really recommend using the dictionary-based solution. Apologies all around. From mnations at gmail.com Wed Jan 21 13:13:18 2009 From: mnations at gmail.com (Mudcat) Date: Wed, 21 Jan 2009 10:13:18 -0800 (PST) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> Message-ID: <2ae39d1c-8d1c-45d1-af3d-92bb57e8464c@b38g2000prf.googlegroups.com> On Jan 21, 11:29?am, alex23 wrote: > Well, you can always stick those imports into a 'common.py' and do > 'from common import *' in each file that uses them. But doing so can > be a pain to maintain and debug for anything more than the most simple > of applications. Being able to see a module's dependencies clearly > listed at the top of the file is exceptionally handy. I x-posted the same thing but am curious why you think it's such a problem to maintain. Having dependencies at the top is handy only because it's usually quicker to get to the top of a file than it is to open up another one. However if you have your common file open in your IDE you can have it open in a split window where it's viewable all the time. As long as you don't go crazy with "import *" in your common file then you shouldn't get into trouble with duplicated namespaces. As I mentioned before it should also cut down on the circular imports. So just preference aside, is there any problems with the actual execution of the code if it's done this way? To me it simply compares to putting an __init__ file in a package, except it applies to only one directory. From gnewsg at gmail.com Wed Jan 21 13:35:51 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 21 Jan 2009 10:35:51 -0800 (PST) Subject: [ANN] Python FTP Server library (pyftpdlib) 0.5.1 released Message-ID: Hi, I'm pleased to announce release 0.5.1 of Python FTP Server library (pyftpdlib). http://code.google.com/p/pyftpdlib === About === Python FTP server library provides an high-level portable interface to easily write asynchronous FTP servers with Python. Based on asyncore framework pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. === Major enhancements === This new version, aside from fixing some bugs, includes the following major enhancements: * A new script implementing FTPS (FTP over SSL/TLS) has been added in the demo directory. * File transfers are now 40% faster thanks to the re-dimensioned application buffer sizes. * ASCII data transfers on Windows are now 200% faster. * Preliminary support for SITE command has been added. * Two new callback methods to handle "file received" and "file sent" events have been added. A complete list of changes including enhancements and bug fixes is available here: http://code.google.com/p/pyftpdlib/wiki/ReleaseNotes05 === More links === * Source tarball: http://pyftpdlib.googlecode.com/files/pyftpdlib-0.5.1.tar.gz * Online docs: http://code.google.com/p/pyftpdlib/wiki/Tutorial * FAQs: http://code.google.com/p/pyftpdlib/wiki/FAQ * RFCs compliance paper: http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance * Issue tracker: http://code.google.com/p/pyftpdlib/issues/list * Mailing list: http://groups.google.com/group/pyftpdlib Thanks, --- Giampaolo Rodola' < g.rodola [at] gmail [dot] com > http://code.google.com/p/pyftpdlib/ From catphive at catphive.net Wed Jan 21 13:47:33 2009 From: catphive at catphive.net (Brendan Miller) Date: Wed, 21 Jan 2009 10:47:33 -0800 Subject: what's the point of rpython? In-Reply-To: References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels wrote: > Brendan Miller wrote: >> >> On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin >> <"http://phr.cx"@nospam.invalid> wrote: >>> >>> .... Of course I'm aware of the LOCK prefix but it slows >>> down the instruction enormously compared with a non-locked instruction. >> >> I'm curious about that. I've been looking around for timing >> information on the lock signal, but am having some trouble finding >> them. Intuitively, given that the processor is much faster than the >> bus, and you are just waiting for processor to complete an addition or >> comparison before put the new memory value on the bus, it seems like >> there should be very little additional bus contention vs a normal add >> instruction. > > The opcode cannot simply talk to its cache, it must either go directly > to off-chip memory or communicate to other processors that it (and it > alone) owns the increment target. Oh, right. *light bulb goes on* I wasn't thinking about cache at all. From a.bilgin.a at gmail.com Wed Jan 21 13:59:31 2009 From: a.bilgin.a at gmail.com (bilgin arslan) Date: Wed, 21 Jan 2009 20:59:31 +0200 Subject: Trouble writing txt Message-ID: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> Hello, I am trying to write a list of words to into a text file as two colons: word (tab) len(word) such as standart 8 I have no trouble writing the words but I couldn't write integers. I always get strange characters, such as: GUN ????????5COCUK ????????5EV ... ???????4YATSI ?????????? (the integers also seem to be incorrect) I use the following form inside a loop to produce this current = unicode(word)+" "+str(len(word)) ofile.write(current) I know about struct and I tried to used it but somehow I always got a blank character instead of an int. import struct format = "i" data = struct.pack(format, 24) print data Any ideas? I use macosx and eclipse. The code also uses unicode encoding From http Wed Jan 21 14:03:07 2009 From: http (Paul Rubin) Date: 21 Jan 2009 11:03:07 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > But somehow the discussion shifted from an optional requirement (giving you > the chance to explicitly use 'from lock import unlock; o = unlock(obj)') > to "it can't be done _ever_" (using setattr/getattr is as explicit as your > analogous 'unlock' function). The idea was the lock would be on the class, not on instances of the class. So setattr/getattr would work on instances of unlocked classes but not locked ones. If you wanted an unlocked instance of a locked class, you could do it by making an unlocked subclass. > Btw, the correctness of a program (on a turing-complete language) cannot be > statically proven. Ask Turing about it. That's an irrelevant red herring, even if you're after provability. It just means that there exist some correct programs that cannot be proven correct. What you care about is whether there is a provable program for some particular computing task, which there almost always is. It doesn't matter if there are also some unprovable ones. That is just common sense. When you write a program you presumably write it using some reasoning that lets you convince yourself that the program should always work, and that's an informal proof. (The idea of static verification is to find the small gaps of reasoning that humans make all the time, but once found these gaps are usually easily fixed). I guess one occasionally writes programs that rely on unproven and maybe unprovable mathematical conjectures, but that is pretty rare, especially in traditional programming where you only care about getting correct values out. Even in areas which do rely on unproven conjectures (e.g. in cryptography, we rely on the conjecture that certain functions are difficult to invert), it's usually possible to explicitly state the conjectures that you depend on, and prove that "if this conjecture is true then the program is correct". From pruebauno at latinmail.com Wed Jan 21 14:18:02 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Wed, 21 Jan 2009 11:18:02 -0800 (PST) Subject: is this pythonic? References: Message-ID: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> On Jan 21, 12:34?pm, TP wrote: > alex23 wrote: > > Try not to use 'dict' or the name of any of the other built-in types > > So my list is rather: > l=[{"title":"to", "color":"blue", "value":2} > {"title":"ti", "color":"red", "value":"coucou"}] > > So, I will rather use your solution: > > for index, record in enumerate(l): > ? ? if record['title'] == 'ti': > ? ? ? ? to_add_in_another_list = l.pop(index) > another_list.append(to_add_in_another_list ) > If you have duplicates this will not work. You will have to do something like this instead: >>> o=[] >>> i=0 >>> ln=len(l) >>> while i>> for index, record in enumerate(l): if record['title'] == 'ti': to_add_in_another_list = l.pop(index) break I don't know if these are more pythonic, they should be more efficient for longer lists though. From aktests at gmail.com Wed Jan 21 14:43:27 2009 From: aktests at gmail.com (ak) Date: Wed, 21 Jan 2009 11:43:27 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> On Jan 20, 1:14?am, Steven D'Aprano wrote: > On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote: > > Hi everyone, > > > I have a problem with urllib2 on this particular url, hosted on an > > Oracle HTTP Server > > >http://www.orange.sk/eshop/sk/portal/catalog.html? > > type=post&subtype=phone&null > > > > > which gets 302 redirected to > >https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a > > cookie through the Set-Cookie header field in the 302 reply. This works > > fin with firefox. > > > However, with urllib2 and the following code snippet, it doesn't work > > Looking at the BadStatusLine exception raised, the server response line > is empty. Looking at the source for httpllib suggests to me that the > server closed the connection early. Perhaps it doesn't like connections > from urllib2? > > I ran a test pretending to be IE using this code: > > cookiejar = cookielib.LWPCookieJar() > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?'\ > ? ? 'type=post&subtype=phone&null' > agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; " \ > ? ? "NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" > headers = {'User-Agent': agent} > req = urllib2.Request(url, data=None, headers=headers) > try: > ? ? s=opener.open(req) > except httplib.BadStatusLine, e: > ? ? print e, e.line > else: > ? ? print "Success" > > but it failed. So the problem is not as simple as changing the user-agent > string. > > Other than that, I'm stumped. > > -- > Steven Thanks a lot for confirming this. I also tried with different headers, including putting *exactly* the same headers as firefox (including Connection:keep-alive by modifying httplib), it still doesn't work. The only possible explanation for me is that python's httplib doesn't handle SSL/TLS 'properly' (not necessarly in the sense of the TLS spec, but in the sense that every other browser can connect properly to this website and httplib can't) If anyone knows an Oracle HTTPS server to confirm this on another server, it would be nice... From lkcl at lkcl.net Wed Jan 21 14:50:28 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 21 Jan 2009 19:50:28 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 Message-ID: this is a progress report on compiling python using entirely free software tools, no proprietary compilers or operating systems involved, yet still linking and successfully running with msvcr80 assemblies. manifests and rc files, which are compiled to internal resources, have been added. various sections which are uniquely identifed by _MSC_VER >= 1400 etc have had to be enabled with corresponding MSVCRT_VERSION >= 0x0800 - in particular, signal handling (PyOS_getsig()). currently, under wine with msvcr80, there looks like there is a bug with a common theme related to threads, but here's a short list: test_array.py is blocking, test_bz2.py is hanging and test_cmd_line.py causes a segfault; test_ctypes is _still_ a bundle of fun. for those people who use native win32 platforms who are compiling up this code, you should have better luck. significantly, the wine developers have been absolutely fantastic, and have fixed several bugs in wine, sometimes within hours, that were found as a result of running the extremely comprehensive python regression tests. the python regression tests are a credit to the collaborative incremental improvement process of free software development. i look forward to seeing the same incremental improvement applied to the development of python, evidence of which would be clearly seen by the acceptance of one of the following patches, one of which is dated 2003: http://bugs.python.org/issue3754 http://bugs.python.org/issue841454 http://bugs.python.org/issue3871 http://bugs.python.org/issue4954 http://bugs.python.org/issue5010 for those people wishing to track and contribute to the development of python for win32 using entirely free software tools, either under wine or native windows, there is a git repository, here, slightly illogically named pythonwine because that's where i started from (cross-compiling python under wine, so i could get at the wine registry from python). obviously, since then, things have... moved on :) http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine l. From google at mrabarnett.plus.com Wed Jan 21 14:57:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jan 2009 19:57:21 +0000 Subject: what's the point of rpython? In-Reply-To: References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <49777E21.6080603@mrabarnett.plus.com> Brendan Miller wrote: > On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels > wrote: >> Brendan Miller wrote: >>> On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin >>> <"http://phr.cx"@nospam.invalid> wrote: >>>> .... Of course I'm aware of the LOCK prefix but it slows >>>> down the instruction enormously compared with a non-locked instruction. >>> I'm curious about that. I've been looking around for timing >>> information on the lock signal, but am having some trouble finding >>> them. Intuitively, given that the processor is much faster than the >>> bus, and you are just waiting for processor to complete an addition or >>> comparison before put the new memory value on the bus, it seems like >>> there should be very little additional bus contention vs a normal add >>> instruction. >> The opcode cannot simply talk to its cache, it must either go directly >> to off-chip memory or communicate to other processors that it (and it >> alone) owns the increment target. > > Oh, right. *light bulb goes on* I wasn't thinking about cache at all. > I'm not sure whether multicore processors share a cache or, if not, have some other on-chip mechanism. Multiprocessor machines, however, are a different matter... From lkcl at lkcl.net Wed Jan 21 15:08:05 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 21 Jan 2009 20:08:05 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: > http://bugs.python.org/issue5010 correction: that's http://bugs.python.org/issue5026 apologies for the mix-up. also,for the msvcrt80 build, it is _essential_ that you use a patched version of mingw32-runtime, see: https://sourceforge.net/tracker/index.php?func=detail&aid=2134161&group_id=2435&atid=352435 libmsvcr80.a mistakenly thinks that _fstat exists (it doesn't - only _fstat32 does, and many more). it's quite straightforward to rebuild - just remember to run ./configure --prefix=/mingw and if you want to revert just reinstall mingw runtime .exe l. From shahmed at sfwmd.gov Wed Jan 21 15:13:26 2009 From: shahmed at sfwmd.gov (Ahmed, Shakir) Date: Wed, 21 Jan 2009 15:13:26 -0500 Subject: date format In-Reply-To: <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> Message-ID: I am grabbing few fields from a table and one of the columns is in date format. The output which I am getting is "Wed Feb 09 00:00:00 2005" but the data in that column is "02/09/2005" and I need the same format output to insert those recodes into another table. print my_service_DATE Wed Feb 09 00:00:00 2005 Any help is highly appreciated. sk From kyrie at uh.cu Wed Jan 21 15:23:55 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 15:23:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x1vuwv5w4.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Message-ID: <200901211523.55524.kyrie@uh.cu> On Wednesday 21 January 2009 02:03:07 pm Paul Rubin wrote: > Luis Zarrabeitia writes: > > But somehow the discussion shifted from an optional requirement (giving > > you the chance to explicitly use 'from lock import unlock; o = > > unlock(obj)') to "it can't be done _ever_" (using setattr/getattr is as > > explicit as your analogous 'unlock' function). > > The idea was the lock would be on the class, not on instances of the > class. ?So setattr/getattr would work on instances of unlocked classes > but not locked ones. ?If you wanted an unlocked instance of a locked > class, you could do it by making an unlocked subclass. Well, then, go change pylint to do that. But don't try to force it on _me_: If I want to access an attribute for an object on my program (from wherever it came from), I don't want _you_ or anyone else saying "no, its private". Even better. Realize that you are trying to use a tool made for debugging, documenting, and catching some obvious errors (private/public) for "security". Go fix Bastion, that would be your best bet. It was yanked out of python because it was insecure, but if someone were to fix it, I'm sure the changes would be welcomed. And then, it would be my choice whether to let you lock your instances in _my_ program, and it would be yours to lock all of mine in yours (and way more). Btw, when I was programming in .Net (long time ago), I found a little library that I wanted to use. The catch: it wasn't opensource, it had a gratis version, and a full, payed version... The difference? The full one had some attributes public that were private on the free one. Well, I didn't wanted code on my app from someone who didn't know the meaning of the 'private' keyword anyway. You (well, Russ more than you) almost seem to be trying something like that. > > Btw, the correctness of a program (on a turing-complete language) cannot > > be statically proven. Ask Turing about it. > > That's an irrelevant red herring, True, my bad. But I don't think it is _fully_ irrelevant. See, a thread that begun with saying that a piece of code was hard to read has evolved to changing the language so we could have tools to statically proving "certain things" with the code. And each time a "suggestion" appears (from people that, at least at the time of suggesting it, were genuinely interested on helping) that doesn't fulfill your [plural, including russ] goal of having static typing and data hiding in the official python, you shoot it down because some other "it cannot be proven statically" reason. Sure, it is always a very well defined "certain" thing and not correctness in general, but that "certain" thing changes as soon as a suggestion is made to amend it. I'm obviously growing tired of that pattern. Have pylint check if someone uses getattr in your code, at all. If pylint doesn't do it, just grep for it and don't run that code. Simple. Btw, this may put and end to this discussion: import gc gc.get_objects() No amount of metaclasses, pylints, decorator, etc, will stop someone from using that to get access to _all_ objects of the program. If you need to keep a secret, don't put it on the same memory space that the untrusted code in python (actually, don't do it on any language). If you need static proofs, use a less dynamic subset of python, and use or develop tools to check if you tried to get out, ever (because if you get out once, you will not be able to track the results). Or, don't use python. (and certainly don't use C++, for that matter, even if C++ has a 'private' keyword). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From python.list at tim.thechases.com Wed Jan 21 15:42:28 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 21 Jan 2009 14:42:28 -0600 Subject: date format In-Reply-To: References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> <21bdd73f-f674-4553-95d9-847611216fa4@35g2000pry.googlegroups.com> Message-ID: <497788B4.6020109@tim.thechases.com> Ahmed, Shakir wrote: > I am grabbing few fields from a table and one of the columns is in date > format. The output which I am getting is "Wed Feb 09 00:00:00 2005" but > the data in that column is "02/09/2005" and I need the same format > output to insert those recodes into another table. > > print my_service_DATE > Wed Feb 09 00:00:00 2005 if you are getting actual date/datetime objects, just use the strftime() method to format as you so desire. If you're getting back a *string*, then you should use time.strptime() to parse the string into a time-object, and then use the constituent parts to reformat as you see fit. -tkc From Scott.Daniels at Acm.Org Wed Jan 21 15:43:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 12:43:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > "Russ P." writes: > >> Actually, in addition to the enforcement of "private," you also need >> the enforcement of "protected." > > Oh, heavens. If you want C++ or any of its progeny, you know where to > find them. Besides, those languages have a horrific design mistake > because they conflate the class system (which manages the units of > behaviour) with the module system (which deals with the units of > implementation).... Nowhere in this discussion is a point that I find telling: Python's policy of accessibility to the full data structure allows simple implementation of debugging software, rather than the black arcana that is the normal fare of trying to weld debuggers into the compilers. --Scott David Daniels Scott.Daniels at Acm.Org From benjamin.kaplan at case.edu Wed Jan 21 15:48:37 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 21 Jan 2009 15:48:37 -0500 Subject: Trouble writing txt In-Reply-To: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> References: <55460f80901211059q7f1387cl217cb1891547363e@mail.gmail.com> Message-ID: On Wed, Jan 21, 2009 at 1:59 PM, bilgin arslan wrote: > Hello, > I am trying to write a list of words to into a text file as two > colons: word (tab) len(word) > such as > > standart 8 > > I have no trouble writing the words but I couldn't write integers. I > always get strange characters, such as: > > GUN > ????????5COCUK > ????????5EV > ... > ???????4YATSI > ?????????? Looks like an encoding problem to me. > > (the integers also seem to be incorrect) > I use the following form inside a loop to produce this > current = unicode(word)+" "+str(len(word)) > ofile.write(current) > > > I know about struct and I tried to used it but somehow I always got a > blank character instead of an int. > > import struct > format = "i" > data = struct.pack(format, 24) > print data Struct encodes the data as a string. 24 encoded as a byte string is represented as 18 00 00 00 (these are hex). All of these values are unprintable, so you get a blank instead. You're original idea should work once you get the encoding problem fixed. > > > Any ideas? > I use macosx and eclipse. The code also uses unicode encoding Unicode is NOT an encoding. It is a standard. You're probably thinking of the UTF-8 encoding, one of the 5 different "unicode" encodings. This page does a great job of explaining what Unicode actually is. http://www.joelonsoftware.com/articles/Unicode.html Try using ofile.write(current.encode("UTF-8")) and see if that helps. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jan 21 15:50:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 12:50:43 -0800 Subject: English-like Python In-Reply-To: References: Message-ID: Benjamin J. Racine wrote: > I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. > > f "abc" 123 > --> > f( "abc", 123 ) > > It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. Surely this would require that f( "abc", 123 ) --> f(("abc", 123)) Or would you require that tuple-formation is "special"? --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Wed Jan 21 15:55:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 12:55:15 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Message-ID: <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> On Jan 22, 4:49?am, Gaurav Veda wrote: > Hi, > > I am trying to put some webpages into a mysql database using python > (after some processing on the text). If I use Python 2.4.2, it works > without a fuss. However, on Python 2.5, I get the following error: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4357: ordinal not in range(128) > > Before sending the (insert) query to the mysql server, I do the > following which I think should've taken care of this problem: > ?sqlStr = sqlStr.replace('\\', '\\\\') > > (where sqlStr is the query). > > Any suggestions? The 0xc2 strongly suggests that you are feeding the beast data encoded in UTF-8 while giving it no reason to believe that it is in fact not encoded in ASCII. Curiously the first errant byte is a long way (4KB) into your data. Consider doing print repr(data) to see what you've actually got there. I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- different versions of mysql, perhaps? Show at the very least the full traceback that you get. Try to write a short script that demonstrates the problem with 2.5 and no problem with 2.4, so that (a) it is apparent what you are doing (b) the problem can be reproduced if necessary by someone with access to mysql. You might like to explain why you think that doubling backslashes in your SQL is a good idea, and amplify "some processing on the text". HTH, John From jstroud at mbi.ucla.edu Wed Jan 21 16:08:48 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 21 Jan 2009 13:08:48 -0800 Subject: Start Python at client side from web app In-Reply-To: <6toehtFbrb81U1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms windows client). > But some action needs to be done on the client since you can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. You need to write an IE plugin for this, otherwise you can't get out of the browser sandbox to execute anything on the client side. In fact, if you just make your IE "application" a plugin, you can take advantage of updating facilities that IE should have for plugins. If IE doesn't have updating facilities, then just write a firefox plugin, which does have these facilities. From jeff at jmcneil.net Wed Jan 21 16:13:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 21 Jan 2009 13:13:19 -0800 (PST) Subject: Trouble writing txt References: Message-ID: On Jan 21, 1:59 pm, bilgin arslan wrote: > Hello, > I am trying to write a list of words to into a text file as two > colons: word (tab) len(word) > such as > > standart 8 > > I have no trouble writing the words but I couldn't write integers. I > always get strange characters, such as: > > GUN > ????????5COCUK > ????????5EV > ... > ???????4YATSI > ????????? > > (the integers also seem to be incorrect) > I use the following form inside a loop to produce this > current = unicode(word)+" "+str(len(word)) > ofile.write(current) > > I know about struct and I tried to used it but somehow I always got a > blank character instead of an int. > > import struct > format = "i" > data = struct.pack(format, 24) > print data > > Any ideas? > I use macosx and eclipse. The code also uses unicode encoding I don't have a Mac in front of me, but I'll take a stab at it. You shouldn't need to bother with the struct module if you're simply trying to print out an integer's string value. What are you using to open 'ofile?' Can you post all of the relevant code? From Russ.Paielli at gmail.com Wed Jan 21 16:16:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 21 Jan 2009 13:16:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: On Jan 21, 9:34?am, Luis Zarrabeitia wrote: > But you keep failing to explay why do you need it to be _part of the standard_ > library (or whatever). Technically, it doesn't need to be. But if someone proposes using particular language for a major safety-critical project, the critical features realistically need to be part of the standard language or at the very least in the standard library. The requirements are different for government-regulated code than they are for non-critical commercial code, as well they should be. Imagine trying to explain to the FAA that you are going to use a language that is inappropriate by itself for a safety-critical system but will be appropriate with the addition of third-party software. That just won't fly. Then again, the FAA might not approve Python for flight-critical or safety-critical code even if it gets enforced data hiding, so perhaps the point is moot. > If you need it in your project, _use_ it. If you don't, then don't use it. If > _you_ need that thing you call security, just use it already and quit > complaining that we don't use it. Is there a policy in your project that you > can't use any external? I don't recall complaining that anyone doesn't use something. In fact, in the unlikely event that enforced data hiding is ever added to Python, nobody would be forced to use it (except perhaps by your boss or your customer, but that's another matter). From Scott.Daniels at Acm.Org Wed Jan 21 16:23:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 21 Jan 2009 13:23:54 -0800 Subject: is this pythonic? In-Reply-To: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> Message-ID: <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> pruebauno at latinmail.com wrote: > ... If you have duplicates this will not work. You will have to do > something like this instead: > >>>> o=[] >>>> i=0 >>>> ln=len(l) >>>> while i if l[i]['title']=='ti': > o.append(l.pop(i)) > ln-=1 > else: > i+=1 Or the following: indices = [i for i,d in enumerate(l) if d['title']=='ti'] for i in reversed(indices): # so del doesn't affect later positions del l[i] --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Wed Jan 21 16:32:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 13:32:30 -0800 (PST) Subject: Python 3.0 urllib.parse.parse_qs results in TypeError References: <313a27f9-c655-4fc4-a8e3-568a4283bba2@f40g2000pri.googlegroups.com> Message-ID: <91aba300-59d6-462e-a566-21825f8d7d03@p23g2000prp.googlegroups.com> On Jan 22, 2:17?am, a... at pythoncraft.com (Aahz) wrote: > In article <313a27f9-c655-4fc4-a8e3-568a4283b... at f40g2000pri.googlegroups.com>, > > ag73 ? wrote: > > > ? ? ? ? ? ? ? ? ? ?form = urllib.parse.parse_qs(qs, keep_blank_values=1) > > >However, the last line of code that calls parse_qs causes the > >following exception to be thrown: > > > > >Type str doesn't support the buffer API > > One of the key features of Python 3.0 is the fact that it now > distinguishes between bytes and strings. ?Unfortunately, there are a lot > of ambiguous areas where the correct handling is not clear; for example, > nobody has yet agreed whether URLs are strings or bytes. ?As you > discovered, forced conversion to string seems to work here and I suggest > you make that your workaround. ? However I'm surprised on further reflection that that workaround works; it must be only accidental. """if I pass in "str(qs)" instead of "qs" then the call works.""" BUT str(bytes_instance) with no other args passed *doesn't* just do a decoding: """When only object is given, this returns its nicely printable representation.""" The nicely printable representation for bytes objects includes: * wrapping it in b'' * showing non-ASCII characters as \xdd 3.0: >>> len(str(b'abc')) 6 >>> len(str(b'abc', encoding='ascii')) 3 >>> len(str(b'\xff')) 7 >>> len(str(b'\xff', encoding='ascii')) Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't d From rt8396 at gmail.com Wed Jan 21 16:35:45 2009 From: rt8396 at gmail.com (r) Date: Wed, 21 Jan 2009 13:35:45 -0800 (PST) Subject: Cannot contact Python webmaster! Message-ID: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> Does anybody know how to get in touch with the www.python.org website maintainers? i sent mail to webmaster at python.org but it just bounces back. Is anybody even there? :) From rridge at csclub.uwaterloo.ca Wed Jan 21 16:43:43 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 21 Jan 2009 16:43:43 -0500 Subject: what's the point of rpython? References: <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: >The opcode cannot simply talk to its cache, it must either go directly >to off-chip memory or communicate to other processors that it (and it >alone) owns the increment target. In fact all it does simply talk to its cache. From the "Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3A: System Programming Guide, Part 1": For the P6 and more recent processor families, if the area of memory being locked during a LOCK operation is cached in the processor that is performing the LOCK operation as write-back memory and is completely contained in a cache line, the processor may not assert the LOCK# signal on the bus. Instead, it will modify the memory location internally and allow it's cache coherency mechanism to insure that the operation is carried out atomically. This operation is called "cache locking." The cache coherency mechanism automatically prevents two or more processors that have cached the same area of memory from simultaneously modifying data in that area. The same cache coherency mechanism that prevents ordinary "unlocked" instructions from simulanteously modifying the same cache line on two different processors also provides the guarantee with "locked" instructions. There's no additional hardware locks involved, and no additional communication required. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From tjreedy at udel.edu Wed Jan 21 16:48:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 16:48:16 -0500 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: Luke Kenneth Casson Leighton wrote: > i look forward to seeing the same incremental improvement applied to > the development of python, evidence of which would be clearly seen by > the acceptance of one of the following patches, one of which is dated > 2003: > http://bugs.python.org/issue841454 Against 2.3, rejected due to dependence on SCons. Also appears to have been incomplete, needing more work. > http://bugs.python.org/issue3754 Open by Roumen Petrov, no review, see below. > http://bugs.python.org/issue3871 Open, from same submitter, only (minor) review by you. Does this supercede 3754? > http://bugs.python.org/issue4954 Yours, Martin reviewed and closed. FWIW, the comment about not adding 'minority' platform specific stuff to the core (as opposed to 'neutral' changes that make them easier) was also applied, a week or two ago, to the BEOS successor. I added 5026 as superceder. > http://bugs.python.org/issue5026 # number corrected Successor to 4954 > for those people wishing to track and contribute to the development of > python for win32 using entirely free software tools, either under wine > or native windows, there is a git repository, here, slightly > illogically named pythonwine because that's where i started from > (cross-compiling python under wine, so i could get at the wine > registry from python). obviously, since then, things have... moved on > :) > > http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine Are there 'neutral' changes to the core you would like that would make maintaining this and other platform-specific patch sets easier? Terry Jan Reedy From ig2ar-saf1 at yahoo.co.uk Wed Jan 21 16:53:15 2009 From: ig2ar-saf1 at yahoo.co.uk (culpritNr1) Date: Wed, 21 Jan 2009 13:53:15 -0800 (PST) Subject: list subsetting Message-ID: <21593123.post@talk.nabble.com> Hello All, Say I have a list like this: a = [0 , 1, 3.14, 20, 8, 8, 3.14] Is there a simple python way to count the number of 3.14's in the list in one statement? In R I do like this a = c(0 , 1, 3.14, 20, 8, 8, 3.14) length( a[ a[]==3.14 ] ) How do I do that in standard python? (Note that this is just an example, I do not mean to use == in floating point operations.) Thank you culpritNr1 -- View this message in context: http://www.nabble.com/list-subsetting-tp21593123p21593123.html Sent from the Python - python-list mailing list archive at Nabble.com. From castironpi at gmail.com Wed Jan 21 17:04:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 14:04:46 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> Message-ID: On Jan 21, 9:24?am, Joe Strout wrote: > Aaron Brady wrote: > > Where functions are first-class objects, a bare function object isn't > > distinguishable either from its call. > > That depends not on whether functions are first-class objects, but on > the *syntax* of function invocation vs. function reference. Good point. snip. I'm not sure what the NL equivalents of function invocation vs. function reference are, but somehow I don't think there would be a lot of confusion (not that there couldn't be). Here is a bad example. Think about computing that answer. Compute the answer, and think about the result. --> thinkabout( func ) thinkabout( func() ) Oddly enough, the NL equivalents aren't even close to resembling each other. From fogleman at gmail.com Wed Jan 21 17:08:10 2009 From: fogleman at gmail.com (FogleBird) Date: Wed, 21 Jan 2009 14:08:10 -0800 (PST) Subject: list subsetting References: Message-ID: On Jan 21, 4:53?pm, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. a.count(3.14) From jeff at jmcneil.net Wed Jan 21 17:09:19 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 21 Jan 2009 14:09:19 -0800 (PST) Subject: list subsetting References: Message-ID: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> On Jan 21, 4:53 pm, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. Just the number of occurrences? Count method? Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [1,2,3,3.14,3.14,5,66].count(3.14) 2 >>> Jeff From kyrie at uh.cu Wed Jan 21 17:10:18 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 21 Jan 2009 17:10:18 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901211710.18743.kyrie@uh.cu> On Wednesday 21 January 2009 04:16:38 pm Russ P. wrote: > On Jan 21, 9:34?am, Luis Zarrabeitia wrote: > > But you keep failing to explay why do you need it to be _part of the > > standard_ library (or whatever). > > Technically, it doesn't need to be. But if someone proposes using > particular language for a major safety-critical project, the critical > features realistically need to be part of the standard language or at > the very least in the standard library. I assume, then, that no safety-critical project uses any external tool for checking anything important. > The requirements are different for government-regulated code than they > are for non-critical commercial code, as well they should be. Imagine > trying to explain to the FAA that you are going to use a language that > is inappropriate by itself for a safety-critical system but will be > appropriate with the addition of third-party software. That just won't > fly. Then it wont fly, period. If you start explaining that the language is inappropriate, then you've already made the case. I would argue that the language _is_ appropriate _because_ all your concerns can be solved. (assuming, of course, that the theoretically-solvable concerns are can actually be solved). But as you haven't stated yet any specific concern other than silly locked-doors analogy and "you are crazy if you think that a nuclear blahblah don't use private variables", this is kind of pointless. > Then again, the FAA might not approve Python for flight-critical or > safety-critical code even if it gets enforced data hiding, so perhaps > the point is moot. Most likely. For what you've said, if the use of an external tool would make it inappropriate, I highly doubt that they'll like an informally-developed community-driven open source language who's developers and a good portion of its community consider silly the idea of using enforced data-hiding for anything other than debugging. > > If you need it in your project, _use_ it. If you don't, then don't use > > it. If _you_ need that thing you call security, just use it already and > > quit complaining that we don't use it. Is there a policy in your project > > that you can't use any external? > > I don't recall complaining that anyone doesn't use something. Well, you want it on the python compiler I use. That seems awfully close. Funny thing... if pylint became part of the standard library, I may welcome the change. I certainly wouldn't be complaining about it unless it was enabled-by-default-and-can't-disable-it. > In fact, > in the unlikely event that enforced data hiding is ever added to > Python, nobody would be forced to use it (except perhaps by your > boss or your customer, but that's another matter). No one is now. And no one is forced to not use it either (except perhaps by your boss or your customer, but that's another matter). -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From bearophileHUGS at lycos.com Wed Jan 21 17:12:20 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 21 Jan 2009 14:12:20 -0800 (PST) Subject: list subsetting References: Message-ID: <8b9809ee-13cc-44a9-b312-2f313932dd38@q30g2000prq.googlegroups.com> FogleBird: > a.count(3.14) If the values to count are approximated FP values, then you may need something more complex, like: leniter(ifilter(somefunction, a)) Where somefunction uses an approximated comparison, and leniter is just a function that counts the items of a generic iterator. Bye, bearophile From tjreedy at udel.edu Wed Jan 21 17:14:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 17:14:18 -0500 Subject: quick beginners List comprehension question In-Reply-To: References: Message-ID: Dr Mephesto wrote: > Hi, > Im new to python, and OOP, and am trying to get a handle on list > comprehension. > > Say I have a class Foo with a property called bar: > > class Foo: > def __init__(self): > self.bar = random.randint(1,100) > > and then I make a list of these objects: > > Newlist = [] > for x in range(10): > Newlist.append(Foo()) Constructing this list is the appropriate place for a comprehension. Newlist = [Foo() for _ in range(10)] > Now, suppose I wanted to triple the value of 'bar', I could always do: > > for x in range(10): > Newlist[x].bar = Newlist[x].bar * 3 Use MRAB's replacement for this. > but can I do this using list comprehension? Don't, for reasons given by others. tjr From rtw at freenet.co.uk Wed Jan 21 17:16:41 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 16:16:41 -0600 Subject: list subsetting References: Message-ID: culpritNr1 wrote in news:mailman.7713.1232574803.3487.python-list at python.org in comp.lang.python: > > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list > in one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? count = a.count( 3.14 ) > > (Note that this is just an example, I do not mean to use == in > floating point operations.) In this case something like this: a = [0 , 1, 3.14, 20, 8, 8, 3.14] count = sum( 1 for x in a if 3.13 < x and x < 3.15 ) http://docs.python.org/library/functions.html#sum http://docs.python.org/reference/expressions.html#generator-expressions Rob. -- http://www.victim-prime.dsl.pipex.com/ From castironpi at gmail.com Wed Jan 21 17:19:41 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 21 Jan 2009 14:19:41 -0800 (PST) Subject: English-like Python References: Message-ID: <4276026d-7ce9-41d9-8ad4-1fb0adbdb29f@z6g2000pre.googlegroups.com> On Jan 21, 2:50?pm, Scott David Daniels wrote: > Benjamin J. Racine wrote: > > I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. > > > f "abc" 123 > > --> > > f( "abc", 123 ) > > > It would be just the thing in a couple of situations... though it does conflict with raw-string literals as stated: r"abc"... which if you left open, would be susceptible to a local definition of r!. ?Maybe you could put it after, like numeric literals: 123L, "abc"r, which is not bad. > > Surely this would require that > ? ?f( "abc", 123 ) > ? ?--> > ? ?f(("abc", 123)) > Or would you require that tuple-formation is "special"? Natural language does have tuples, and there is some ambiguity some of the time. Go to the store and get bread. --> goto( store ); get( bread ) or: get( store, bread ) --> ( Go to the store ), ( Get bread ) or: ( Go to ( the store, get bread ) ) Now for the good examples. ;) From http Wed Jan 21 17:19:54 2009 From: http (Paul Rubin) Date: 21 Jan 2009 14:19:54 -0800 Subject: list subsetting References: Message-ID: <7x63k8s3n9.fsf@ruckus.brouhaha.com> culpritNr1 writes: > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? n = sum(1 for x in a if x == 3.14) From jervisau at gmail.com Wed Jan 21 17:20:23 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Thu, 22 Jan 2009 09:20:23 +1100 Subject: list subsetting In-Reply-To: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> References: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <8e63a5ce0901211420h6c071f83nefb23cab7b41285b@mail.gmail.com> On Thu, Jan 22, 2009 at 9:09 AM, Jeff McNeil wrote: > On Jan 21, 4:53 pm, culpritNr1 wrote: > > Hello All, > > > > Say I have a list like this: > > > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > > > Is there a simple python way to count the number of 3.14's in the list in > > one statement? > > > > In R I do like this > > > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > > > length( a[ a[]==3.14 ] ) > > > > How do I do that in standard python? > > > > (Note that this is just an example, I do not mean to use == in floating > > point operations.) > > > > Thank you > > > > culpritNr1 > > > > -- > > View this message in context: > http://www.nabble.com/list-subsetting-tp21593123p21593123.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > Just the number of occurrences? Count method? > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> [1,2,3,3.14,3.14,5,66].count(3.14) > 2 > >>> > > Jeff > -- > http://mail.python.org/mailman/listinfo/python-list > a = [3.14, 4, 3.15, 3.14 + 1E-12] len([None for elem in a if abs(elem - 3.14) < 1E-9]) Just replace 1E-9 with the level of accuracy that you would like. This creates a list of Nones, one None for each 3.14 in the original list, then counts the length of the list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ig2ar-saf1 at yahoo.co.uk Wed Jan 21 17:22:45 2009 From: ig2ar-saf1 at yahoo.co.uk (culpritNr1) Date: Wed, 21 Jan 2009 14:22:45 -0800 (PST) Subject: list subsetting In-Reply-To: <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <21593607.post@talk.nabble.com> Thank you Fogelbird and Jeff. I actually tried to find out if such function existed. I did >>> help("count") no Python documentation found for 'count' Anyway. More than counting, I am interested in list subsetting in a simple way. Forget about counting. Say I have a list of lists and I want to pull only the rows where the second "column" equals 3.14. It is a very simple concept. I wonder if python can keep it simple despite being a general purpose programming language, not a numerical programming language. Thanks, culpritNr1 Jeff McNeil-2 wrote: > > On Jan 21, 4:53 pm, culpritNr1 wrote: >> Hello All, >> >> Say I have a list like this: >> >> a = [0 , 1, 3.14, 20, 8, 8, 3.14] >> >> Is there a simple python way to count the number of 3.14's in the list in >> one statement? >> >> In R I do like this >> >> a = c(0 , 1, 3.14, 20, 8, 8, 3.14) >> >> length( a[ a[]==3.14 ] ) >> >> How do I do that in standard python? >> >> (Note that this is just an example, I do not mean to use == in floating >> point operations.) >> >> Thank you >> >> culpritNr1 >> >> -- >> View this message in >> context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > Just the number of occurrences? Count method? > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> [1,2,3,3.14,3.14,5,66].count(3.14) > 2 >>>> > > Jeff > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/list-subsetting-tp21593123p21593607.html Sent from the Python - python-list mailing list archive at Nabble.com. From rhamph at gmail.com Wed Jan 21 17:25:13 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Wed, 21 Jan 2009 14:25:13 -0800 (PST) Subject: what's the point of rpython? References: <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> <7xhc3t2p93.fsf@ruckus.brouhaha.com> <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: On Jan 21, 12:57?pm, MRAB wrote: > I'm not sure whether multicore processors share a cache or, if not, have > some other on-chip mechanism. Multiprocessor machines, however, are a > different matter... They share some, but also have some exclusive. How much of which depends entirely on which CPU you have. From tdelaney at avaya.com Wed Jan 21 17:42:06 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 22 Jan 2009 06:42:06 +0800 Subject: spam on the list - how are things now? In-Reply-To: <18799.65370.92932.642056@montanaro.dyndns.org> Message-ID: skip at pobox.com wrote: > We've been running SpamBayes on the news-to-mail gateway on > mail.python.org for a couple weeks now. To me it seems like the > level of spam leaking onto the list has dropped way down but I'd like > some feedback from people who read the python-list at python.org mailing > list on the topic. Sorry Skip - looks like it's not working. The Xah Lee spam is still getting through ;) Tim Delaney From http Wed Jan 21 17:44:28 2009 From: http (Paul Rubin) Date: 21 Jan 2009 14:44:28 -0800 Subject: list subsetting References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: <7x7i4onusz.fsf@ruckus.brouhaha.com> culpritNr1 writes: > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. list_of_lists = [[1.414,2.718,3.14],[4.00,3.14,1.618],[72,29,39]] those_rows = [xs for xs in list_of_lists if xs[1] == 3.14] From fogleman at gmail.com Wed Jan 21 17:46:37 2009 From: fogleman at gmail.com (FogleBird) Date: Wed, 21 Jan 2009 14:46:37 -0800 (PST) Subject: list subsetting References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> Message-ID: On Jan 21, 5:22?pm, culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > > >>> help("count") > > no Python documentation found for 'count' > > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. > > It is a very simple concept. I wonder if python can keep it simple despite > being a general purpose programming language, not a numerical programming > language. > > Thanks, > > culpritNr1 > > > > Jeff McNeil-2 wrote: > > > On Jan 21, 4:53 pm, culpritNr1 wrote: > >> Hello All, > > >> Say I have a list like this: > > >> a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > >> Is there a simple python way to count the number of 3.14's in the list in > >> one statement? > > >> In R I do like this > > >> a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > >> length( a[ a[]==3.14 ] ) > > >> How do I do that in standard python? > > >> (Note that this is just an example, I do not mean to use == in floating > >> point operations.) > > >> Thank you > > >> culpritNr1 > > >> -- > >> View this message in > >> context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > >> Sent from the Python - python-list mailing list archive at Nabble.com. > > > Just the number of occurrences? Count method? > > > Python 2.6 (r26:66714, Oct 29 2008, 08:30:04) > > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> [1,2,3,3.14,3.14,5,66].count(3.14) > > 2 > > > Jeff > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593607.html > Sent from the Python - python-list mailing list archive at Nabble.com. data = [[1,2,3],[4,5,6],[7,8,9]] rows = [row for row in data if row[1] == 5] print rows [[4, 5, 6]] From robert.kern at gmail.com Wed Jan 21 17:47:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 Jan 2009 16:47:56 -0600 Subject: list subsetting In-Reply-To: <21593607.post@talk.nabble.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> <21593607.post@talk.nabble.com> Message-ID: culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > >>>> help("count") > no Python documentation found for 'count' > > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. In [1]: list_o_lists = [[1, 3.14, 3, 4], ...: [2, 3, 4, 5], ...: [3, 3.14, 5, 6]] In [2]: print [L for L in list_o_lists if L[1] == 3.14] [[1, 3.1400000000000001, 3, 4], [3, 3.1400000000000001, 5, 6]] -- 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 vedagaurav at gmail.com Wed Jan 21 17:50:16 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Wed, 21 Jan 2009 14:50:16 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> Message-ID: <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> > The 0xc2 strongly suggests that you are feeding the beast data encoded > in UTF-8 while giving it no reason to believe that it is in fact not > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > into your data. Consider doing > print repr(data) > to see what you've actually got there. >>> sqlStr[4352:4362] ' and 25\xc2\xb0F' All I want to do is to just replace all the non-ascii characters by a space. > I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- > different versions of mysql, perhaps? I am trying to put content into the mysql server running on machine A, from machine B & machine C with different versions of python. So I don't think this is a mysql issue. > Show at the very least the full traceback that you get. Try to write a > short script that demonstrates the problem with 2.5 and no problem > with 2.4, so that (a) it is apparent what you are doing (b) the > problem can be reproduced if necessary by someone with access to > mysql. Traceback (most recent call last): File "", line 1, in File "putDataIntoDB.py", line 164, in cursor.execute(sqlStr) File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py", line 146, in execute query = query.encode(charset) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4359: ordinal not in range(128) > You might like to explain why you think that doubling backslashes in > your SQL is a good idea, and amplify "some processing on the text". I thought this will achieve 2 things. a) It will escape any unicode character (obviously, I was wrong. Got carried away by the display. I thought \xc2 will get escaped to \\xc2, which is completely preposterous). b) It will make sure that the escape sequences in the string (e.g. '\n') are received by mysql as an escape sequence. Thanks for your reply! Gaurav > HTH, > John From bugtrack at roumenpetrov.info Wed Jan 21 17:51:36 2009 From: bugtrack at roumenpetrov.info (Roumen Petrov) Date: Thu, 22 Jan 2009 00:51:36 +0200 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: <4977A6F8.4060904@roumenpetrov.info> Terry Reedy wrote: > Luke Kenneth Casson Leighton wrote: > >> i look forward to seeing the same incremental improvement applied to >> the development of python, evidence of which would be clearly seen by >> the acceptance of one of the following patches, one of which is dated >> 2003: > >> http://bugs.python.org/issue841454 > > Against 2.3, rejected due to dependence on SCons. > Also appears to have been incomplete, needing more work. No it was complete but use SCons. Most of changes changes in code you will see again in 3871. >> http://bugs.python.org/issue3754 > > Open by Roumen Petrov, no review, see below. This is again request and the patch is for trunk. It share common idea with 841454:Cross building python for mingw32:Andreas Ames (yxcv):2003-11-13 14:31 1006238:Cross compile patch:Daniel Goertzen (goertzen):2004-08-09 22:05 1597850:Cross compiling patches for MINGW hanwen:2006-11-16 16:57 >> http://bugs.python.org/issue3871 > > Open, from same submitter, only (minor) review by you. > Does this supercede 3754? No. It share common changes to code with 841454, 1006238, 1412448, 1597850. May be 1597850 and 3871 supercede 1412448. The issue3871 raise questions (and include solution/work around) related to: 2942 - mingw/cygwin do not accept asm file as extension source 2445 - Use The CygwinCCompiler Under Cygwin 1706863 - Failed to build Python 2.5.1 with sqlite3 Also issues related to LDFLAGS: 4010 - configure options don't trickle down to distutils 1628484 - Python 2.5 64 bit compile fails on Solaris 10/gcc 4.1.1 [SNIP] From rtw at freenet.co.uk Wed Jan 21 17:59:18 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 16:59:18 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote in news:6toehtFbrb81U1 at mid.individual.net in comp.lang.python: > Sorry, I described my problem not well. Here is more information: > > The main application is the intranet web application used with IE (ms > windows client). But some action needs to be done on the client since > you can't do it with html or javascript. > > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. > > Thomas > > Server runs Linux with Django and Postgres. > > Thomas Guettler schrieb: >> Hi, >> >> I want to start Python at the client side from a web application. The >> app is an intranet application, and all client PCs are under our >> control (we can install software on them). >> >> But I don't want to update the installation too often. Here is my >> idea: >> >> We create a custom mime-type and register it on the client PC. The >> web application can send signed python code to the client PC. If the >> signature is correct, the code will be executed at the client. The >> signature prevents others from executing code. >> >> Has someone seen or done something like this before? Two options come to mind: 1) use a HTA as you client app, http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx The main drawback is it isn't a full browser so you loose things like back buttons, though some shortcuts F5 (refresh/reload) do work. 2) create a localhost web server, for the client side manipulation. Then have your remote webserver render a form that posts via javavscript to the localhost webserver. The localhost server would post back in the same way. Rob. -- http://www.victim-prime.dsl.pipex.com/ From deets at nospam.web.de Wed Jan 21 18:05:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 00:05:10 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6tpo16FbacfjU1@mid.uni-berlin.de> > 2) create a localhost web server, for the client side manipulation. > Then have your remote webserver render a form that posts via javavscript > to the localhost webserver. The localhost server would post back in > the same way. AFAIK the JS security model prevents that. Diez From deets at nospam.web.de Wed Jan 21 18:15:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 00:15:17 +0100 Subject: quick beginners List comprehension question In-Reply-To: References: <6touv8Fc32elU1@mid.uni-berlin.de> Message-ID: <6tpok5Fc7mabU1@mid.uni-berlin.de> MRAB schrieb: > Diez B. Roggisch wrote: >> Dr Mephesto wrote: >> >>> Hi, >>> Im new to python, and OOP, and am trying to get a handle on list >>> comprehension. >>> >>> Say I have a class Foo with a property called bar: >>> >>> class Foo: >>> def __init__(self): >>> self.bar = random.randint(1,100) >>> >>> and then I make a list of these objects: >>> >>> Newlist = [] >>> for x in range(10): >>> Newlist.append(Foo()) >>> >>> Now, suppose I wanted to triple the value of 'bar', I could always do: >>> >>> for x in range(10): >>> Newlist[x].bar = Newlist[x].bar * 3 >>> >>> but can I do this using list comprehension? Thanks in Advance! >> >> No, as such, because list-comprehensions require you to have an >> *expression* >> in front of the iteration: >> >> resultlist = [ for in ] >> >> Now what you of course can do is this: >> >> def multiply(item): >> item.bar = item.bar * 3 >> >> [multiply(i) for i in items] >> >> However, doing this will make python produce a list of None-references - >> which is a waste. It's up to you if you care about that, but generally it >> is frowned upon because of that, and the fact that the conciseness of the >> list-comp here isn't really helping with the readability. >> > If you had: > > def multiply(item): > item.bar = item.bar * 3 > return item > > then: > > [multiply(i) for i in items] > > would return items. Still a bad idea, though, because you're using a > list comprehension for its side-effect. And redundant, which was the reason I ommited it. Diez From rtw at freenet.co.uk Wed Jan 21 18:20:38 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 21 Jan 2009 17:20:38 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in comp.lang.python: > >> 2) create a localhost web server, for the client side manipulation. >> Then have your remote webserver render a form that posts via >> javavscript to the localhost webserver. The localhost server would >> post back in the same way. > > AFAIK the JS security model prevents that. > Are you thinking of frames?, or the way IE 7 complains about runnning javavscript (though it bizzarly calls it an "running an ActiveX control" )?. Anyway it works fine. Rob. -- http://www.victim-prime.dsl.pipex.com/ From mdw at distorted.org.uk Wed Jan 21 18:39:53 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 21 Jan 2009 23:39:53 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87skncfcty.fsf.mdw@metalzone.distorted.org.uk> Scott David Daniels writes: > Nowhere in this discussion is a point that I find telling: Python's > policy of accessibility to the full data structure allows simple > implementation of debugging software, rather than the black arcana > that is the normal fare of trying to weld debuggers into the compilers. That's a very good point, actually. It also means that, even without a formal `debugger', you can easily write diagnostic code which dumps the internal state of some interesting object -- say at the interactive prompt, or in a hacky test program. One might argue that `industrial strength' modules ought to have such diagnostic abilities built in; but they often either don't tell you what you actually wanted to know in your current situation, or tell you way more than was necessary, or both. Either that, or they're just too complicated to use. Thank you for that observation! -- [mdw] From sjmachin at lexicon.net Wed Jan 21 19:08:54 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 21 Jan 2009 16:08:54 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> Message-ID: <61718f7e-327b-4851-95b5-83c0951a00a6@a39g2000prl.googlegroups.com> On Jan 22, 9:50?am, Gaurav Veda wrote: > > The 0xc2 strongly suggests that you are feeding the beast data encoded > > in UTF-8 while giving it no reason to believe that it is in fact not > > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > > into your data. Consider doing > > ? ? print repr(data) > > to see what you've actually got there. > >>> sqlStr[4352:4362] > > ' and 25\xc2\xb0F' That's the UTF-8 version of ' and 25?F' where the character between the 25 and the F is U+00B0 DEGREE SIGN ... interesting stuff to have in an SQL query string. > > All I want to do is to just replace all the non-ascii characters by a > space. I can't imagine why you would want to do that to data, let alone to an SQL query. I can't see any evidence that you actually tried to do that, anyway. To replace non-ASCII characters in a UTF-8-encoded string by spaces: | >>> u8 = ' and 25\xc2\xb0F' | >>> u = u8.decode('utf8') | >>> ''.join([chr(ord(c)) if c <= u'\x7f' else ' ' for c in u]) | ' and 25 F' > > > I'm a little skeptical about the "2.4 works, 2.5 doesn't" notion -- > > different versions of mysql, perhaps? > > I am trying to put content into the mysql server running on machine A, > from machine B & machine C with different versions of python. So I > don't think this is a mysql issue. Terminology confusion. Consider the possibility of different versions of MySQLdb (the client interface package) on the client machines B and C. Also consider the possibility that you didn't run exactly the same code on B and C. > > Show at the very least the full traceback that you get. Try to write a > > short script that demonstrates the problem with 2.5 and no problem > > with 2.4, so that (a) it is apparent what you are doing (b) the > > problem can be reproduced if necessary by someone with access to > > mysql. How about a very small script which includes the minimum necessary to run these two lines (with appropriate substitutions for column_x and table_y: sql_str = "select column_x from table_y where column_x = '\xc2\xb0'" cursor.execute(sql_str) and run that on B and C > > Traceback (most recent call last): > ? File "", line 1, in > ? File "putDataIntoDB.py", line 164, in > ? ? cursor.execute(sqlStr) > ? File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py", line > 146, in execute > ? ? query = query.encode(charset) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4359: ordinal not in range(128) > > > You might like to explain why you think that doubling backslashes in > > your SQL is a good idea, and amplify "some processing on the text". > > I thought this will achieve 2 things. > a) It will escape any unicode character (obviously, I was wrong. Got > carried away by the display. I thought \xc2 will get escaped to \\xc2, > which is completely preposterous). > b) It will make sure that the escape sequences in the string (e.g. > '\n') are received by mysql as an escape sequence. Run-time programmatic fiddling with an SQL query string is dangerous and tricky at the best of times, worse when you don't inspect the result before you press the launch button. Cheers, John From mdw at distorted.org.uk Wed Jan 21 19:10:02 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 00:10:02 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> Luis Zarrabeitia writes: > Btw, the correctness of a program (on a turing-complete language) > cannot be statically proven. Ask Turing about it. Be careful! Given a putative correctness-checking algorithm, there exist programs for which the algorithm gives the wrong answer. That doesn't necessarily mean that there isn't a useful subset of `all programs' which can be proven correct, or even that this subset doesn't include all `interesting' programs. Even so, actually constructing algorithms which prove interesting things about all interesting programs seems difficult. Some people (let's call them `type A programmers') have decided that they want to be assisted with writing correct programs -- to the extent that they've chosen some correctness properties, and use a tool which reject programs that it can't prove have those properties. Since the tool can't work for all programs, it errs on the side of caution, sometimes rejecting correct programs. (The properties tend to be called `type correctness' and the tool is built into the compiler, but that's not actually very important.) Other people (`type B programmers') don't like having their (apparently? possibly?) correct programs rejected. Instead, they'd rather risk writing incorrect programs (maybe they try to minimize the risk by thinking very hard, or by building thorough test suites) because they find that some of the kinds of programs the tools reject are actually interesting and useful -- or at least fun. I think trying to persuade a type A programmer that he wants to work like a type B programmer, or /vice versa/, is difficult, bordering on futile. Type A stereotypes type B as a bunch of ill-disciplined reckless hackers; type B stereotypes type A as killjoy disciplinarians. Meeting in the middle is difficult. (`We just want to add a little safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) On a personal note, I've written programs in lots (/lots/) of different languages: C, Pascal, Haskell, Standard ML, Python, Perl, Lisp, Scheme, and assembler for various processors. I always found programming in permissive languages more enjoyable. I still love ARM assembler (though I thought the 32-bit address space changes spoilt some of its beauty), but I don't get to write much these days; Common Lisp is now my language of choice, but Python comes very close. I find C too fiddly and annoying nowadays, and its type system does an impressive job of simultaneously being uncomfortably constraining while being too weak to provide a satisfactory feeling of confidence in compensation. Kernighan summed up Pascal perfectly when he said `There is no escape.' Haskell is interesting: it can provide a surprising degree of freedom, but it makes you work /very/ hard wrangling its type system in order to get there; and again, I found I had most fun when I was doing extremely evil unsafePerformIO hacking... So, my personal plea. Writing Python is /fun/. Please let it stay that way. -- [mdw] From google at mrabarnett.plus.com Wed Jan 21 19:18:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jan 2009 00:18:37 +0000 Subject: list subsetting In-Reply-To: <21593607.post@talk.nabble.com> References: <21593123.post@talk.nabble.com> <665c268c-90d0-4c47-8f04-936c36c1c00b@v13g2000vbb.googlegroups.com> <21593607.post@talk.nabble.com> Message-ID: <4977BB5D.2010008@mrabarnett.plus.com> culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > >>>> help("count") > no Python documentation found for 'count' > [snip] 'count' is a method of the list class, so you need: help(list.count) and if you want help on the list class then it's: help(list) Note that they aren't quoted. From fakeaddress at nowhere.org Wed Jan 21 19:47:29 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 21 Jan 2009 16:47:29 -0800 Subject: Start Python at client side from web app In-Reply-To: <6toehtFbrb81U1@mid.individual.net> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: Thomas Guettler wrote: > Sorry, I described my problem not well. Here is more information: Actually you did pretty well. [...] > The main application is the intranet web application used with IE (ms windows client). Your idea of a custom mime-type, with a browser extension, should work. I don't know of any open-source implementation. Do you plan to have just one public key for verifying the downloaded Python scripts, hard-coded into the extension? -- --Bryan From skip at pobox.com Wed Jan 21 19:55:19 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 21 Jan 2009 18:55:19 -0600 Subject: Cannot contact Python webmaster! In-Reply-To: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> References: <277779f5-5d70-466e-950b-f1f6a7483351@a26g2000prf.googlegroups.com> Message-ID: <18807.50167.567500.605506@montanaro.dyndns.org> >> Does anybody know how to get in touch with the www.python.org website >> maintainers? i sent mail to webmaster at python.org but it just bounces >> back. Is anybody even there? :) The webmaster address should work. Lots of people send mail to it. What is the error message in the bounce? Feel free to send your message to me and I'll forward it. (I'm one of the webmasters.) -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From domelectric at gmail.com Wed Jan 21 20:12:44 2009 From: domelectric at gmail.com (debug) Date: Wed, 21 Jan 2009 17:12:44 -0800 (PST) Subject: frequency analysis without numpy References: <1105f65d-16d0-441c-9cd2-89c4011eb403@v39g2000pro.googlegroups.com> Message-ID: <285e3bce-a0cc-4a18-a965-1f680d115bbe@i20g2000prf.googlegroups.com> On Jan 21, 11:31?am, sturlamolden wrote: > On Jan 21, 12:13 am, sturlamolden wrote: > > > Apart from that, an FFT in pure python is going to be atrociously slow > > for anything but the shortest signals. I cannot imagine why you want > > to do this. > > Just to elaborate on this: > > The whole purpose of using FFT is speed. That pretty much excludes the > use of Python. > > If you don't care about speed, you could just as well compute the DFT > directly. The FFT is just a O(n lon n) algorithm for computing the > DFT. Here is a DFT with O(N**2) behavior: > > from math import sin, cos, pi > > def real_dft(x): > ? ?''' DFT for a real valued sequence x ''' > ? ?r = [] > ? ?N = len(x) > ? ?M = N//2 + 1 if N%2 else N//2 > ? ?for n in range(M): > ? ? ? s = 0j > ? ? ? for k in range(N): > ? ? ? ? ?tmp = 2*pi*k*n/N > ? ? ? ? ?s += x[k] * (cos(tmp) - 1j*sin(tmp)) > ? ? ? r.append(s) > ? ?return r > > S.M. Thanks for the quick reply, so what do I pass the real_dft function (obviously a list) but do I pass it the unpacked binary data? Dom From kdawg44 at gmail.com Wed Jan 21 20:21:06 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Wed, 21 Jan 2009 20:21:06 -0500 Subject: Mechanize hanging Message-ID: <5caea3690901211721s35c9e39enb1f3df12b0a0479c@mail.gmail.com> Hi, I am trying to use mechanize to connect and log into Yahoo! Here is my code: #c:\Python25\python import re import urllib import urllib2 import mechanize print "print1" br = mechanize.Browser() br.set_handle_robots(False) br.open("https://login.yahoo.com/config/login?") It is hanging at the open. Eventually I have to just kill it and I get this: __init__.py Traceback (most recent call last): File "C:\Documents and Settings\kholleran\workspace\PythonPractice\src\PythonP ractice\__init__.py", line 10, in br.open("https://login.yahoo.com/config/login?") File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 206, in open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 232, in _mech_open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_opene r.py", line 192, in open File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_http. py", line 570, in http_response KeyboardInterrupt Which i am sure is not very helpful but I don't want to leave anything out. Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From blueiur at gmail.com Wed Jan 21 20:35:02 2009 From: blueiur at gmail.com (blueiur) Date: Wed, 21 Jan 2009 17:35:02 -0800 (PST) Subject: list subsetting References: Message-ID: i think it's best way lst = [0, 1, 3.14, 20, 8, 8, 3.14] len( filter(lambda x: x > 3.13 and x < 3.15, lst) ) 2 On 1?22?, ??6?53?, culpritNr1 wrote: > Hello All, > > Say I have a list like this: > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > Is there a simple python way to count the number of 3.14's in the list in > one statement? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. From prologic at shortcircuit.net.au Wed Jan 21 20:53:36 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jan 2009 11:53:36 +1000 Subject: list subsetting In-Reply-To: References: Message-ID: On Thu, Jan 22, 2009 at 11:35 AM, blueiur wrote: > i think it's best way > lst = [0, 1, 3.14, 20, 8, 8, 3.14] > len( filter(lambda x: x > 3.13 and x < 3.15, lst) ) > 2 I prefer this way (cleaner): >>> lst = [0, 1, 3.14, 20, 8, 8, 3.14] >>> len([x for x in lst if 3.13 < x < 3.15]) 2 >>> cheers James From rhodri at wildebst.demon.co.uk Wed Jan 21 21:01:23 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 22 Jan 2009 02:01:23 -0000 Subject: reading file to list In-Reply-To: References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 09:42:19 -0000, Lars Behrens wrote: > Rhodri James wrote: > >> I *was* thinking of code produced in the real world, and I don't buy >> your assertion. I'm not an academic, and I wouldn't hesitate to lay >> down a line of code like that. As I said before, it fits into English >> language idioms naturally, and as a result is pretty self-descriptive. > > As a non-native speaker and non-academic, I don't understand the "fittine > into English language idioms naturally" which is mentioned here in the > different subthreads. Could you try to explain that for me? It just means that the progamming language concept in question has the same "shape" (i.e. roughly the same syntax) as an English language syntactic construct in common use. So for list comprehensions we have [ f(x) for x in l ] and "Make a list of f(x) for each x in the list l." You can see how the elements of the list comprehension fit sequentially into the English sentence. As other people have pointed out, this particular example really comes from the mathematical notation for constructing sets: f(x) ? x ? l ...but it's no accident that they both "translate" straightforwardly into English! -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Wed Jan 21 21:06:04 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 22 Jan 2009 02:06:04 -0000 Subject: reading file to list In-Reply-To: <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 09:13:03 -0000, Xah Lee wrote: > Rhodri James wrote: >> I recommend spending less time being certain that you are correct >> without seeking evidence > > I don't concur. > > For instance, when you are talking to a bunch of kids, you have to be > sure of yourself, else they run all over you, even if they didn't mean > to be rude. So you would rather give the appearance of authority than do the work to actually have authority? This is very poor teaching practice. > Also, one's demeanor must commensurate one's knowledge. If i pamper > you, you might think i'm a whimp, and run on with your opinions and > thoughts unbridled, which, can be considered as a miscommunication on > my part. As it is, I think your demeanor wildly outstrips your knowledge, something you have just confirmed. This attitude makes you a highly unreliable source of information. *plonk* -- Rhodri James *-* Wildebeeste Herder to the Masses From http Wed Jan 21 21:17:15 2009 From: http (Paul Rubin) Date: 21 Jan 2009 18:17:15 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <7x3afcjd90.fsf@ruckus.brouhaha.com> Thomas Guettler writes: > 1. The user pushes a button in the web app. > 2. Webserver sends signed python code to the client with own mime type > 3. IE sends code to the python application. > 4. Signature gets checked, Python code on the client gets executed. > 5. Maybe send some data to the server with http. I think someone else already suggested using an hta. Does that not do what you want? More info is at: http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx Also, rather than concocting your own code signing system, maybe you want to use standard Python .exe packaging, signed with Authenticode. From erexsha at gmail.com Wed Jan 21 21:38:26 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 21 Jan 2009 18:38:26 -0800 Subject: malloc (error code=12) Message-ID: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Hi All, I am writing a multiprocessing program using python 2.6. It works in most cases, however when my input is large sometimes I get this message again and again: Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error code=12) *** error: can't allocate region and at the and I have these messages: Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug Exception in thread Thread-2: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 524, in __bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 479, in run self.__target(*self.__args, **self.__kwargs) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", line 259, in _handle_results task = get() MemoryError Any idea what is wrong here? I didn't attached the code since it is a big program and I don't know exactly which part of my program causes this error. And since it is multiprocessing I can't debug it and run it line by line! Thanks, Arash -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Wed Jan 21 21:49:29 2009 From: http (Paul Rubin) Date: 21 Jan 2009 18:49:29 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> Message-ID: <7xocy0ukau.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > > In my limited experience with > > Haskell (statically typed but very high level), > > "dynamic" and "static" were not meant to concern typing here (or at > least not only typing). I'm not sure what you mean by those terms then. > Haskell and MLs are indeed statically typed, but with a powerfull type > inference system, which gives great support for genericity > (hmmm... is that the appropriate word ?) I think you mean "polymorphism"; genericity in functional programming usually means compile time reflection about types. (It means something different in Java or Ada). > Now these are functional languages, so the notion of "access > restriction" is just moot in this context !-) I'm not sure what you mean by that; Haskell certainly supports access restrictions, through its type and module systems. > Ok, I should probably have made clear I was thinking of a hi-level > dynamic _imperative_ language vs a low-level static _imperative_ > language. FP is quite another world. I'd say that Python's FP characteristics are an important part of its expressiveness. From rogerb at rogerbinns.com Wed Jan 21 22:01:27 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 21 Jan 2009 19:01:27 -0800 Subject: malloc (error code=12) In-Reply-To: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Arash Arfaee wrote: > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) errno 12 is ENOMEM on Macs (and Linux for that matter). You may have run out of swap space, but that is unlikely. The most likely cause is that you have run out of address space. For example a 32 bit process has 4GB of address space available. The kernel will take up to 2GB of that depending on the operating system. Various shared libraries and your program will take some. The program stack space will take some more. In your case malloc is attempting to allocate 384kb of memory using mmap by mapping anonymous memory (swap) into the address space. (The advantage of doing it this way is that the space can be unmapped when no longer needed.) With no appropriate address space left for this chunk, you get the error. You are either trying to use too much stuff or there is a memory leak. Calling gc.collect() can result in some deferred items being freed. To get an idea of how address space works, check out this article about what Linux did in 2004. The same principles apply to MacOSX. You can also see how the theoretical 4GB quickly disappears! http://lwn.net/Articles/91829/ Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl34YMACgkQmOOfHg372QRG9ACeKitN3f7cAcN1AOf76yTa9w+q CywAoL8JJ2/VvNe8eHOfP1r9UhOJH59z =EUjX -----END PGP SIGNATURE----- From http Wed Jan 21 22:04:11 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:04:11 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x1vuwv5w4.fsf@ruckus.brouhaha.com> Message-ID: <7xiqo8ujmc.fsf@ruckus.brouhaha.com> Luis Zarrabeitia writes: > Even better. Realize that you are trying to use a tool made for > debugging, documenting, and catching some obvious errors > (private/public) for "security". Go fix Bastion, that would be your > best bet. It was yanked out of python because it was insecure, but > if someone were to fix it, I'm sure the changes would be welcomed. Bastion appears to be fundamentally unfixable, at least in CPython. It might be possible to revive it in PyPy. > Btw, when I was programming in .Net (long time ago), I found a > little library that I wanted to use. The catch: it wasn't > opensource, Well, THAT's the problem with it. The issues that flowed from that problem are simply consequences. > But I don't think it is _fully_ irrelevant. See, a thread that begun > with saying that a piece of code was hard to read has evolved to > changing the language so we could have tools to statically proving > "certain things" with the code. Yes, being able to tell without studying 1000's of lines of code what the code does is a readability issue. If a function says at the top "this function returns an integer" and that assertion is verified by the compiler (or an external tool), you now know something about the function's return value by reading only one line. If the assertion is not verified by a program, then you have to actually examine all the code in the function to check that particular fact. Of course, the very presence of such assertions and the implementation methods necessary to make them verifiable can in some situations complicate the code, making it less readable in other regards. There's not a magic bullet, it's always a trade-off. > And each time a "suggestion" appears (from people that, at least at > Have pylint check if someone uses getattr in your code, at all. If pylint > doesn't do it, just grep for it and don't run that code. Simple. It would be nice to be able to use getattr on instances of class X while being able to verify that it is not used on instances of class Y. That's somewhat beyond the reach of Pylint at the moment, I think. From http Wed Jan 21 22:08:05 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:08:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xeiywujfu.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > Nowhere in this discussion is a point that I find telling: Python's > policy of accessibility to the full data structure allows simple > implementation of debugging software, rather than the black arcana > that is the normal fare of trying to weld debuggers into the compilers. Are you really saying that navigating through Python traceback and frame objects is not equally black arcana? Is there any hope of debuggers for CPython programs that use those interfaces working in Jython or PyPy? Java, at least, has a well defined and documented debugging interface that allows access to private and protected instance variables for debugging purposes. You can enable or disable that interface by setting a runtime option when you start the JVM. From mauriceling at gmail.com Wed Jan 21 22:09:14 2009 From: mauriceling at gmail.com (mauriceling@acm.org) Date: Wed, 21 Jan 2009 19:09:14 -0800 (PST) Subject: [ANN] The Python Papers Source Codes (Volume 1) Message-ID: <4754bd8c-93ea-4116-b2db-15516ef4efda@v18g2000pro.googlegroups.com> Hi everyone, It has been a few months in the cooking and I'm pleased to announce the publication and ISSN of The Python Papers Source Codes (ISSN 1836-621X). The Python Papers Source Code (TPPSC) will be a collection of code manuscripts, usually with a longer companion manuscript published in The Python Papers (TPP) or The Python Papers Monograph (TPPM). The purpose of TPPSC is modeled after "Collected Algorithms of the ACM". We will consider the following papers for TPPSC: * Algorithms: Implementation of an algorithm where it should be possible for a user to incorporate this software into a larger program, with the exception of standalone software. * Remarks: Brief report on a previously published algorithm, with the purpose of correcting / modifying the code. Details arguing for the modification should be provided with the modified code and patch file to used with the original implementation. * Translations: Translation of an algorithm / code from another programming language to Python, and should only be done if the algorithm still represents the current state of the art. * Certifications: Report on performance characteristics or verification of correctness by specification or from extensive testing of a previously published an algorithm / code. Certification reports do not change the original code; hence, a certification report usually do not contains codes. Each submission will usually consist of the following sections: 1. Title and author(s) affiliation 2. Abstract (usually a terse description of 1 or 2 sentences) 3. Description (about a page description of the purpose of the codes, including licence) 4. Code section (this is where the codes will be listed) 5. References 6. A compressed file of the codes files as supplementary materials For more details or to read our first paper under TPPSC, please go to http://ojs.pythonpapers.org/index.php/tppsc/issue/current All manuscripted for the periodicals under The Python Papers Anthology (http://ojs.pythonpapers.org) will be published once they are accepted. We look forward to your continued support. Cheers Maurice Ling Co-EIC, TPPA Maurice Ling From nl.srinivas at gmail.com Wed Jan 21 22:09:23 2009 From: nl.srinivas at gmail.com (Srinivasa NL) Date: Thu, 22 Jan 2009 08:39:23 +0530 Subject: quick beginners List comprehension question In-Reply-To: <6tpok5Fc7mabU1@mid.uni-berlin.de> References: <6touv8Fc32elU1@mid.uni-berlin.de> <6tpok5Fc7mabU1@mid.uni-berlin.de> Message-ID: <8b85ec440901211909j4104d303mde5860b4aded051a@mail.gmail.com> You can try this import random class foo: def __init__(self): self.bar = random.randint(1,100) def getbar(ls,i): ls.append(foo()) ls[i].bar = ls[i].bar * 3 ls = [] [getbar(ls,i) for i in range(10)] On Thu, Jan 22, 2009 at 4:45 AM, Diez B. Roggisch wrote: > MRAB schrieb: > >> Diez B. Roggisch wrote: >> >>> Dr Mephesto wrote: >>> >>> Hi, >>>> Im new to python, and OOP, and am trying to get a handle on list >>>> comprehension. >>>> >>>> Say I have a class Foo with a property called bar: >>>> >>>> class Foo: >>>> def __init__(self): >>>> self.bar = random.randint(1,100) >>>> >>>> and then I make a list of these objects: >>>> >>>> Newlist = [] >>>> for x in range(10): >>>> Newlist.append(Foo()) >>>> >>>> Now, suppose I wanted to triple the value of 'bar', I could always do: >>>> >>>> for x in range(10): >>>> Newlist[x].bar = Newlist[x].bar * 3 >>>> >>>> but can I do this using list comprehension? Thanks in Advance! >>>> >>> >>> No, as such, because list-comprehensions require you to have an >>> *expression* >>> in front of the iteration: >>> >>> resultlist = [ for in ] >>> >>> Now what you of course can do is this: >>> >>> def multiply(item): >>> item.bar = item.bar * 3 >>> >>> [multiply(i) for i in items] >>> >>> However, doing this will make python produce a list of None-references - >>> which is a waste. It's up to you if you care about that, but generally it >>> is frowned upon because of that, and the fact that the conciseness of the >>> list-comp here isn't really helping with the readability. >>> >>> If you had: >> >> def multiply(item): >> item.bar = item.bar * 3 >> return item >> >> then: >> >> [multiply(i) for i in items] >> >> would return items. Still a bad idea, though, because you're using a list >> comprehension for its side-effect. >> > > And redundant, which was the reason I ommited it. > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Wed Jan 21 22:19:55 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 21 Jan 2009 22:19:55 -0500 Subject: malloc (error code=12) In-Reply-To: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> Message-ID: <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> On Wed, Jan 21, 2009 at 9:38 PM, Arash Arfaee wrote: > > Hi All, > > I am writing a multiprocessing program using python 2.6. It works in most > cases, however when my input is large sometimes I get this message again and > again: > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) > *** error: can't allocate region > > and at the and I have these messages: > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > code=12) > *** error: can't allocate region > *** set a breakpoint in malloc_error_break to debug > Exception in thread Thread-2: > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > line 524, in __bootstrap_inner > self.run() > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > line 479, in run > self.__target(*self.__args, **self.__kwargs) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", > line 259, in _handle_results > task = get() > MemoryError > > Any idea what is wrong here? I didn't attached the code since it is a big > program and I don't know exactly which part of my program causes this error. > And since it is multiprocessing I can't debug it and run it line by line! > > Thanks, > Arash > > -- > http://mail.python.org/mailman/listinfo/python-list > > wow. How big are these objects/input? From http Wed Jan 21 22:25:13 2009 From: http (Paul Rubin) Date: 21 Jan 2009 19:25:13 -0800 Subject: what's the point of rpython? References: <7xk58pgppz.fsf@ruckus.brouhaha.com> Message-ID: <7xab9kc99i.fsf@ruckus.brouhaha.com> Ross Ridge writes: > Scott David Daniels wrote: > >The opcode cannot simply talk to its cache, it must either go directly > >to off-chip memory or communicate to other processors that it (and it > >alone) owns the increment target. > The cache coherency mechanism automatically prevents two or > more processors that have cached the same area of memory from > simultaneously modifying data in that area. > > The same cache coherency mechanism that prevents ordinary "unlocked" > instructions from simulanteously modifying the same cache line on > two different processors also provides the guarantee with "locked" > instructions. There's no additional hardware locks involved, and no > additional communication required. The cache coherency mechanism is what Scott described as "communicat[ing] to other processors that it (and it alone) owns the increment target". The cache coherency mechanism is not a trivial thing at all. It introduces its own hazards and delays, and it is getting more complicated all the time as processors and caches get faster and larger. Some time ago, cpu's hit their megahertz limits and that's why we're using multicores now. Some PL researchers think cache coherency is going to be the next limit, and are advocating languages like Erlang, which avoid use of shared memory and have separate heaps per thread; or alternatively, approaches like the MS Singularity research OS which relies on something like a linear type system to statically ensure that a given object is accessible to only one thread at a time. (That approach allows transferring objects between threads with no locks or copying required). From tjreedy at udel.edu Wed Jan 21 22:40:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jan 2009 22:40:47 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: Russ P. wrote: > On Jan 21, 9:34 am, Luis Zarrabeitia wrote: > >> But you keep failing to explay why do you need it to be _part of the standard_ >> library (or whatever). > > Technically, it doesn't need to be. But if someone proposes using > particular language for a major safety-critical project, the critical > features realistically need to be part of the standard language or at > the very least in the standard library. Python is not an appropriate language who make a fetish of the standard library. Numpy, which descends from code developed at US gov labs and agencies, and which would be essintial in many safety-critical projects being discussed, is not part of it. And that had nothing to do with its quality. From \ Wed Jan 21 23:29:22 2009 From: \ ("%s@gmail com" % myname.lower " ",) Date: Wed, 21 Jan 2009 22:29:22 -0600 Subject: Overloading Methods In-Reply-To: References: <5caea3690901201007r8641ff5yc087548f91d1829b@mail.gmail.com> <49761588.604@mrabarnett.plus.com> Message-ID: Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: >> K-Dawg wrote: >>> Can you overload methods in Python? >>> >>> Can I have multiple __inits__ with different parameters passed in? >>> >> Simple answer: no. > > More complicated answer: Yes, with some caveats. > > You usually don't need to overload methods in Python since you can use > default and keyword arguments instead. For instance: > > class Foo(object): > def __init__(self, a, b=10, c=None): > self.a = a > self.b = b > if c is None: c = [] > self.c = c > > #example use > x = Foo("#", 4, [6,7]) > y = Foo("@") > z = Foo("!", c=[1,2]) > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > > However, if you want the overloads to accept completely different > types as parameters, then it arguably should expressed as distinct > methods rather than "overloads". In the special case of __init__, you > might want to make the alternate initializers classmethods or factory > functions. > > Cheers, > Chris > To elaborate on what Chris said, I usually find myself using class factory functions. Suppose you have a class that you want to initialize from a string, a file pointer, or a path. Here's how I'd implement it: class MyClass: def __init__(self, bytes): @classmethod def FromFilePointer(self, fp): bytes = fp.read() return MyCass.FromBytes(bytes) @classmethod def FromPath(self, path): bytes = open(path, "r").read() return MyCass.FromBytes(bytes) @classmethod #Yes, I know this duplicates __init__, def FromBytes(self, bytes): #but I include it so as to provide return MyClass(bytes) #3 parallel methods for initializing. myclass = MyClass.FromFilePointer(open("myfile.txt", "r")) myclass = MyClass.FromPath("myfile.txt") myclass = MyClass.FromBytes("spam-spam-spam") That might be a little bit more work, but I think it reads better and is more flexible down the road. -greg From xahlee at gmail.com Wed Jan 21 23:32:41 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 21 Jan 2009 20:32:41 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <49721561.8080204@wildenhain.de> <497218EC.9070108@mrabarnett.plus.com> <17c9aa29-88f4-4678-8027-5b9988fd9b10@p23g2000prp.googlegroups.com> <729feb25-cf02-45cc-b073-9a0a175e4953@b38g2000prf.googlegroups.com> <2693c928-6000-46a6-bd20-cd24a1e0c361@w39g2000prb.googlegroups.com> <1d273049-8e70-4d7a-bbee-51b988042dab@s9g2000prg.googlegroups.com> Message-ID: <55263864-7d43-479e-9af1-29ecc1db4105@b38g2000prf.googlegroups.com> Rhodri James wrote: > *plonk* Please see: ? Killfile Considered Harmful http://xahlee.org/UnixResource_dir/writ/kill_file_harmful.html plain text version follows --------------------------- Killfile Considered Harmful Xah Lee, 2000-02-26 In newsgroups, killfile is a playful word meaning that the poster has placed someone in a blacklist of authors, where their postings will be automatically hidden from view in their newsreader. Such functionality of newsreaders originated in unix. In the early 90s or before, it used to be referred to as ?sending someone into /dev/null?, because ?/dev/ null? can be used as a way for deleting email program outputs. The killfile behavior, is simply put: ?sweep-under-the-rug?, ?bury- head-in-sand? kind of behavior. Imagine that in a gathering where if everyone totally ignores other's voices except their own kind, then what cacophony would result? Similarly, if we ignore the problem of crime by simply using larger locks for our own doors, what consequence would result? We are all human beings. Our surroundings are our organs and affects us dearly. In newsgroups, inevitably there will be certain individuals with foul breath at times. Killfile mechanism is a very good feature to battle such annoyances. This is not a reason for falling for the convenience of blocking your ears from dissenting voices or the nonconformists. The worst thing i hate about it, is the broadcasting of someone being killfiled. Oftentimes the sole content of a message is ?You've been killfiled?. WHAT GOOD DOES IT DO TO THE COMMUNITY BY SUCH ANNOUNCEMENT? Is it a warning system for fellow readers to prepare to follow suit? Or is it a stupid self-righteous act? In the course of a unpleasant encountering, the killfilers feel the other party being unworthy of further response but they don't want to be seen as chickening out so they had to announce it as if saying: ?Hello world: you don't see a returning 'fuck you' from me because _I_ am _smarter_ and took a step ahead of my antagonist and covered my ears, not because he is correct or anything like that.?. Pride is a human nature, but unqualified conceit is despicable. A second motivation for announcing killfile is more explicitly juvenile. Killfile has several variant names: ?You've been killfiled.?, ?plonk? (sound of falling object), ?I've send you to /dev/ null? (unixism), and creativity does not seems to cease there, e.g. in comp.lang.lisp: (plonk 'xah) or signatures that reads ?in /dev/null, they can't hear you scream.? The reason of these playful variations is precisely literary folly. The utterer delights in its use since most are wanting of genuine literary artistry. This adds to the fashion of killfile and its broadcasting. Killfile behavior and broadcasting have another curious trait: No burden of commitment. One cannot really tell if the person really did the killfile. The decision to make a killfile cry in public does not carry any weight of responsibility as compared to making a claim, stating a ?fact?, or expressing a opinion. It is simply a variation of ?fuck you?. This too, contributed to its uncontrolled popularity. Xah ? http://xahlee.org/ ? From http Wed Jan 21 23:35:25 2009 From: http (Paul Rubin) Date: 21 Jan 2009 20:35:25 -0800 Subject: what's the point of rpython? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <7x3afewqwh.fsf@ruckus.brouhaha.com> <7xprihmlxu.fsf@ruckus.brouhaha.com> Message-ID: <7x1vuwc60i.fsf@ruckus.brouhaha.com> Brendan Miller writes: > Actually this article explicitly mentions CMPXCHG as lock free. > http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms I see, that clears up some mysteries. Thanks. From http Wed Jan 21 23:46:02 2009 From: http (Paul Rubin) Date: 21 Jan 2009 20:46:02 -0800 Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> Message-ID: <7xvds8aqyd.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > a) The contended case is the issue, not the uncontended case. An > uncontended lock is just constant overhead, not a barrier to > scalability a1) Really what matters is the actual mix between contended and uncontended accesses, and the synchronization strategy affects the amount of contention. For example, the traditional locking strategy involves acquiring a lock before reading the object, so two simultaneous read-only accesses would create lock contention. With STM, only updates acquire a lock, so multiple read-only threads can access the object simultaneously with no contention. a2) Constant factors matter!!! If using a different mechanism makes Python 2x faster, that's a very powerful reason to favor the other mechanism. > b) Locks on linux (since the switch to futexes) are pretty close to > free when uncontended. I thought futexes use a traditional locked read-modify-write instruction which is 50-100 cycles, cheap compared to a system call but quite expensive compared with a normal 1-cycle non-locked operation. > > > The second issue is the objects themselves, like a list which is > > > mutable. ?If you're using it in a single thread or writing from > > > multiple threads this is a non-trivial constant cost. ?... > The second issue has *nothing* to do with refcounts. It is the > objects themselves. A classic example is trying to do "i += 1", which > breaks down into "i = i + 1", which isn't an atomic operation. Oh, I see what you mean; yes, you're right, it's best to avoid doing those sorts of operation in shared objects too frequently. > Java's ConcurrentHash map gets this right. I'll have to look that up, it sounds interesting. I've been staying away from Java but a situation is coming up where I may have to (ugh) start using it. Thanks. From wolfgang at rohdewald.de Thu Jan 22 01:10:50 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Thu, 22 Jan 2009 07:10:50 +0100 Subject: Python 2.4 vs 2.5 - Unicode error In-Reply-To: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> Message-ID: <200901220710.50403.wolfgang@rohdewald.de> On Mittwoch, 21. Januar 2009, Gaurav Veda wrote: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4357: ordinal not in range(128) > > Before sending the (insert) query to the mysql server, I do the > following which I think should've taken care of this problem: > sqlStr = sqlStr.replace('\\', '\\\\') you might consider using what mysql offers about unicode: save all strings encoded as unicode. Might be more work now but I think it would be a good investment in the future. have a look at the mysql documentation for mysql_real_escape_string() takes care of quoted chars. mysql_set_character_set() for setting the character set used by the database connection you can ensure that the web page is unicode by doing something like charsetregex = re.compile(r'charset=(.*?)[\"&]') charsetmatch = charsetregex.search(page) if charsetmatch: charset=charsetmatch.group(1) utf8Text = unicode(page,charset) -- Wolfgang From aahz at pythoncraft.com Thu Jan 22 01:16:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jan 2009 22:16:00 -0800 Subject: pep 8 constants References: Message-ID: In article , Brendan Miller wrote: > >PEP 8 doesn't mention anything about using all caps to indicate a constant. Now it does! See http://www.python.org/dev/peps/pep-0008/ Thanks for bringing this up! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From erexsha at gmail.com Thu Jan 22 01:34:04 2009 From: erexsha at gmail.com (Arash Arfaee) Date: Wed, 21 Jan 2009 22:34:04 -0800 Subject: malloc (error code=12) In-Reply-To: <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> Message-ID: <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> Very BIG Jesse!!!! It works on a huge Boolean function. And thanks Roger. Do you think it will be solved if I run it over another OS like windows? Cheers, Arash On Wed, Jan 21, 2009 at 7:19 PM, Jesse Noller wrote: > On Wed, Jan 21, 2009 at 9:38 PM, Arash Arfaee wrote: > > > > Hi All, > > > > I am writing a multiprocessing program using python 2.6. It works in most > > cases, however when my input is large sometimes I get this message again > and > > again: > > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > > code=12) > > *** error: can't allocate region > > > > and at the and I have these messages: > > > > > > Python(15492,0xb0103000) malloc: *** mmap(size=393216) failed (error > > code=12) > > *** error: can't allocate region > > *** set a breakpoint in malloc_error_break to debug > > Exception in thread Thread-2: > > Traceback (most recent call last): > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > > line 524, in __bootstrap_inner > > self.run() > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", > > line 479, in run > > self.__target(*self.__args, **self.__kwargs) > > File > > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py", > > line 259, in _handle_results > > task = get() > > MemoryError > > > > Any idea what is wrong here? I didn't attached the code since it is a big > > program and I don't know exactly which part of my program causes this > error. > > And since it is multiprocessing I can't debug it and run it line by line! > > > > Thanks, > > Arash > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > wow. How big are these objects/input? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Thu Jan 22 01:48:43 2009 From: http (Paul Rubin) Date: 21 Jan 2009 22:48:43 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7xwscnhm44.fsf@ruckus.brouhaha.com> Mark Wooding writes: > Some people (let's call them `type A programmers') have decided that > they want to be assisted with writing correct programs... > Other people (`type B programmers') don't like having their (apparently? > possibly?) correct programs rejected.... > I think trying to persuade a type A programmer that he wants to work > like a type B programmer, or /vice versa/, is difficult, bordering on > futile. Type A stereotypes type B as a bunch of ill-disciplined > reckless hackers; type B stereotypes type A as killjoy disciplinarians. > Meeting in the middle is difficult. (`We just want to add a little > safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) That's an interesting analysis. You know, I think I'm really a type B programmer, interested in type A techniques and tools for the same reason someone who naturally sleeps late is interested in extra-loud alarm clocks. Also, the application area matters. There is a difference between programming for one's own enjoyment or to do a personal task, and writing programs whose reliability or lack of it can affect other people's lives. I've never done any safety-critical programming but I do a fair amount of security-oriented Internet programming. As such, I have to always assume that my programs will be attacked by people who are smarter than I am and know more than I do. I can't possibly out-think them. If I don't see problems in a program, it's still plausible that someone smarter than me will spot something I missed. Therefore, my failure to detect the presence of problems is not reassuring. What I want is means of verifying the absence of problems. Finally, your type-A / type-B comparison works best regarding programs written by one programmer or by a few programmers who communicate closely. I'm working on a Python program in conjunction with a bunch of people in widely dispersed time zones, so communication isn't so fluid, and when something changes it's not always easy to notice the change or understand the reason and deal with it. There have been quite a few times when some hassle would have been avoided by the static interfaces mandated in less dynamic languages. Whether the hassle saved would have been outweighed by the extra verbosity is not known. Yeah, I know, more docs and tests can always help, but why not let the computer do more of the work? > Haskell is interesting: it can provide a surprising degree of > freedom, but it makes you work /very/ hard wrangling its type system > in order to get there; and again, I found I had most fun when I was > doing extremely evil unsafePerformIO hacking... I've found Haskell's type system to work pretty well for the not-so-fancy things I've tried so far. It takes some study to understand, but it's very uniform and beautiful. I'm having more trouble controlling resource consumption of programs that are otherwise semantically correct, a well known drawback of lazy evaluation. The purpose of unsafePerformIO is interfacing with C programs and importing them into Haskell as pure functions when appropriate. Anyway, at least for me, Haskell is fascinating as an object of study, and a lot of fun to hack with, but doesn't yet have the creature comforts or practicality of Python, plus its steep learning curve makes it unsuitable for projects not being developed by hardcore nerds. The ML family avoids some of Haskell's problems, but is generally less advanced and moribund. Pretty soon I think we will start seeing practical successor languages that put the best ideas together. From koranthala at gmail.com Thu Jan 22 01:49:10 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 21 Jan 2009 22:49:10 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> Message-ID: <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> On Jan 21, 2:55?pm, Vinay Sajip wrote: > On Jan 20, 10:11 am,koranthala wrote: > > > > > The doRollover method does not append to the earlier file. Rather, it > > creates a new file with the same name. > > Err... that's what rollover means - switching to a new log file (and > renaming the old ones). If it just appended to the old one, why would > it be called doRollover ? ;-) > > Regards, > > Vinay Sajip I understand Vinay. But my point is that I wanted a mechanism to rotate the log files based on data - i.e. today one log, tomorrow another. This is easier because when trouble tickets are raised, users mention that X failed at this time. Now, timedrotatingfilehandler does it - but only if the program is running the whole length of time. My tool is invoked by a cron job - so the program runs, then stops again and again. When I posted the question here, I was forwarded to the doRollover mechanism as a solution. I was just mentioning that doRollover, due to overwriting the files I would lose everything that is stored before. What I did now was to copy the file, and then append to the rolledover file - which does serve the purpose. But it is kludgy, and I dont think my situation is unique. I did see other people asking for the same functionality. So I was wondering whether it would be good idea to have this also in the next version. From koranthala at gmail.com Thu Jan 22 02:02:11 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 21 Jan 2009 23:02:11 -0800 (PST) Subject: Dictionary : items() Message-ID: Hi, Dictionary has the items method which returns the value as a list of tuples. I was wondering whether it would be a good idea to have an extra parameter - sort - to allow the tuples to be sorted as the desire of users. Currently what I do is: class SDict(dict): def items(self, sort=None): '''Returns list. Difference from basic dict in that it is sortable''' if not sort: return super(SDict, self).items() return sorted(self.iteritems(), key=sort) Usage: for a dictionary of strings sorted: l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) Now what I wanted was to incorporate this in the basic dictionary itself. Not only items(), but the methods similar to it - iteritems etc all can also have this parameter. Please let me know your views. Is this a good enough idea to be added to the next version of Python? From rhamph at gmail.com Thu Jan 22 02:14:00 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Wed, 21 Jan 2009 23:14:00 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> <7xd4ele060.fsf@ruckus.brouhaha.com> <7xskngxjgw.fsf@ruckus.brouhaha.com> <7x8wp86plv.fsf@ruckus.brouhaha.com> <617ad0b3-e6ff-42b3-a39f-bffa80157cef@k8g2000yqn.googlegroups.com> <7xmydl3bdw.fsf@ruckus.brouhaha.com> <23af48a1-654b-445f-9a6b-26ca308639ae@a26g2000prf.googlegroups.com> <7xvds8aqyd.fsf@ruckus.brouhaha.com> Message-ID: <458b0745-dee5-4b0f-9fbf-3974a14e4b16@t13g2000yqc.googlegroups.com> On Jan 21, 9:46?pm, Paul Rubin wrote: > Rhamphoryncus writes: > > a) The contended case is the issue, not the uncontended case. ?An > > uncontended lock is just constant overhead, not a barrier to > > scalability > > a1) Really what matters is the actual mix between contended and > uncontended accesses, and the synchronization strategy affects the > amount of contention. ?For example, the traditional locking strategy > involves acquiring a lock before reading the object, so two > simultaneous read-only accesses would create lock contention. ?With > STM, only updates acquire a lock, so multiple read-only threads can > access the object simultaneously with no contention. ? Aye, but my point is really about the myth of lock-free algorithms being uncontending ? it's simply not true, and CAN'T be true. A write is inherently a mutually exclusive operation. There's all sorts of ways to avoid contending for reads, spread out the writes and have a single thread coalesce them, etc, but fundamentally the write will involve some mutual exclusion. From tjreedy at udel.edu Thu Jan 22 02:33:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 02:33:30 -0500 Subject: Dictionary : items() In-Reply-To: References: Message-ID: koranthala wrote: > Hi, > Dictionary has the items method which returns the value as a list > of tuples. > I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. > Currently what I do is: > > class SDict(dict): > def items(self, sort=None): > '''Returns list. Difference from basic dict in that it is > sortable''' > if not sort: > return super(SDict, self).items() > return sorted(self.iteritems(), key=sort) > > Usage: > for a dictionary of strings sorted: > l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) > > Now what I wanted was to incorporate this in the basic dictionary > itself. Not only items(), but the methods similar to it - iteritems > etc all can also have this parameter. > > Please let me know your views. > Is this a good enough idea to be added to the next version of Python? In Python 3, the current .keys() returning a list and .iterkeys() returning an iterator both disappear and are replaced by .keys() returning an iterable set-like view of the dict. 'sorted(d.keys())' is the way to convert the view into a sorted list. So your idea is obsolete. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:38:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:38:03 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> Message-ID: On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: > Russ P. a ?crit : > (snip) >> In any case, I have suggested that Python should perhaps get a new >> keyword, "private" or "priv". > > And quite a few people - most of them using Python daily - answered they > didn't wan't it. Then they don't have to use it. Lots of people think that double-underscore name mangling is a waste of time: not strict enough to be useful, not open enough to be Pythonic. Solution? Don't use double-underscore names. -- Steven From astan.chee at al.com.au Thu Jan 22 02:38:45 2009 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 22 Jan 2009 18:38:45 +1100 Subject: USB in python Message-ID: <49782285.9010509@al.com.au> Hi, Im trying to write a program for my USB device and I'm thinking of using python to do this. The USB device is of my own making and it is activated when one of the two data pins of the USB is given about 5V (or similar to whatever the power pin is getting). Now I'm confused to if the software to activate this can actually be written and how do I do it? Any examples? I've seen pyUSB but it doesn't give me control over the hardware and how much power is going through the data pins. Thanks for any help. Cheers Astan From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:46:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:46:18 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 00:57:49 -0800, Aaron Brady wrote: > Natural language doesn't have the equivalent of parentheses, I take it you mean natural language doesn't have the equivalent of parentheses for *calling*, since NLs can (and do) use parentheses for grouping -- as well as various conventions regarding dashes -- terms together. I'm not aware of any NL that uses some sort of calling convention, but it isn't impossible. Most sentences have an object, a subject and a verb, just like OO method calls. So logically: "Peter ate the sandwich" is equivalent to: Peter.eat(sandwich) modulo complications due to tenses and similar. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 02:59:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 07:59:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> Message-ID: On Wed, 21 Jan 2009 01:02:37 -0800, Aaron Brady wrote: >> >>> class Parrot: >> >> ... ? ? _private = 'spam' >> ...>>> p = Parrot() >> >>> p._private = 'ham' ?# allowed by default from protection import >> >>> lock >> >>> lock(p)._private >> >>> p._private = 'spam' >> >> Traceback (most recent call last): >> ? File "", line 1, in >> ProtectionError: attribute is read-only from outside of class Parrot >> >> Would that be so bad? I don't think so. > > Sorry, I didn't see the last part originally. I don't think 'outside of > class Parrot' is well-defined in Python. Does '_private' have to be a > member of 'Parrot', an instance of 'Parrot', or the calling instance of > 'Parrot', before entering the calling scope, or at the time the call is > made? Since many of these can change on the fly, there's more than one > consistent interpretation to the syntax. This is a good point. Any hypothetical move to make Python (or a Python- like language) stricter about private/protected attributes would need to deal with that question. I don't have to worry about that until somebody writes a PEP :) -- Steven From rogerb at rogerbinns.com Thu Jan 22 03:16:34 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Thu, 22 Jan 2009 00:16:34 -0800 Subject: malloc (error code=12) In-Reply-To: <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> References: <266557d0901211838h73f7af5ck22874b6a8518cd67@mail.gmail.com> <4222a8490901211919o1879b9d5p2da1cd21feffc97e@mail.gmail.com> <266557d0901212234w304d8181wfd5376cb37f2f790@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Arash Arfaee wrote: > Very BIG Jesse!!!! It works on a huge Boolean function. > And thanks Roger. Do you think it will be solved if I run it over > another OS like windows? By far the simplest solution is to use a 64 bit process on a 64 bit operating system. There are 64 bit versions of Windows available and you'll need to install the 64 bit version of Python (it has AMD64 in the name but will run on Intel 64 bit processors too). The various Linux distributions also have 64 bit flavours available. Note that you will also have to ensure that any 3rd party extensions using C code you use are also (re)compiled for 64 bit. The various versions of the 32 bit operating systems do have differing address space layouts but with large amounts of data in use you are still likely to hit a limit. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl4K18ACgkQmOOfHg372QSE5QCgkp9bTPhkmHuh1I6U+onPLJSB 5MQAoIDmYNSlISe13Z2lSS0wspd/r+n+ =YQw6 -----END PGP SIGNATURE----- From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:17:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:17:17 GMT Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Wed, 21 Jan 2009 08:17:34 -0700, Joe Strout wrote: > Steven D'Aprano wrote: ... >> But even if RB doesn't have these things, I question that the syntax is >> "beautiful". Consider some arbitrary method Foo. If you see this: >> >> Foo >> >> Is that legal RB syntax? > > You betcha! How do you know? I haven't specified what Foo does. As you say a little later on: >> Maybe yes, maybe no. It all depends on what Foo does. If it returns no >> result, then it's legal. If it returns a result, it isn't. > > Right. In other words, you can tell just by looking at the call that it > doesn't return a result. This is often handy. You can't tell the difference between a syntax error and a valid call without knowing what Foo does. In Python, you can always recognise a syntax error without needing to worry about the semantics of the call. This is not the case with RealBasic. > For example, the built-in method to play the standard > system alert sound is: > > Beep > > Doesn't get much more readable and syntax-free than that. readable doesn't mean smallest amount of syntax possible sometimes syntax increases the readability of a text as you would see if we for example dropped all punctuation but you probably already knew that but perhaps you didnt draw the connection with programming language wink > Suppose now > that a beep isn't eloquent enough, and you want the computer to speak > something out loud instead. Also easy: I've programmed in Hypertalk, which is full of constructs like: get the value of field "Bar" put it into x put x+37 into x ask "Eat " & x " pies?" with "Yes please", "No thanks" if it is "Yes please" then go to card "PieCard" so I understand the principle of leaving out parentheses to make things look kinda-sorta vaguely English-like. I actually do like Hypertalk, I think it is neat, but I can tell you that you get no respect from other programmers when you show them your code :) >> So the question of whether syntax is legal depends, not on the >> syntactic elements involved, but on the *semantics* of the method >> (whether or not it returns a result). > > But of course. Any method call is legal only if the form of the call > matches the method prototype -- if you try to call a function that > requires 4 parameters, and give it only 3, that's an error too. I don't > see how this is different in any important way. But it isn't (presumably) a syntax error. I accept that in practice, it isn't a big deal once you get used to the convention. But it's a special case -- why treat functions of zero arguments as a special case just to save two characters? It seems to me that the cost of this is that using functions as first-class objects takes a major usability hit. How would you write the equivalent of this in RealBasic? def func(f, args): args = reversed(args) return f(*args) x = func( lambda a, b, c: a+b*c, [1, 2, 3] ) y = func( lambda: 7, [] ) -- Steven From castironpi at gmail.com Thu Jan 22 03:19:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 00:19:35 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <8ceefcd2-f84e-449d-af54-985e271d27d3@p2g2000prn.googlegroups.com> On Jan 22, 1:46?am, Steven D'Aprano wrote: > On Wed, 21 Jan 2009 00:57:49 -0800, Aaron Brady wrote: > > Natural language doesn't have the equivalent of parentheses, > > I take it you mean natural language doesn't have the equivalent of > parentheses for *calling*, since NLs can (and do) use parentheses for > grouping -- as well as various conventions regarding dashes -- terms > together. I take it back. I meant spoken languages. > I'm not aware of any NL that uses some sort of calling convention, but it > isn't impossible. Most sentences have an object, a subject and a verb, > just like OO method calls. So logically: > > "Peter ate the sandwich" > > is equivalent to: > > Peter.eat(sandwich) > > modulo complications due to tenses and similar. I don't think it's as common as you imply to give a sequence of instructions in spoken language. It's more often rule-based, such as 'when X, Y' (the German for 'if' is 'wenn'), and 'Employees will X', as well as 'X was wearing', and 'X is doing'. 'John is dating Mary' is informational, whereas 'John.date( Mary )' is a step in a procedure. How-to knowledge is often (I guess predominantly) tacit, relying on agents to determine a missing step in a process, or fill in from context. In fact, knowledge-based might be a better description of most NL aims (many times with implied ordering). That is, mostly, I want to alter your beliefs (OT: too often to create fear), not your know-how specifically. When you do see imperatives, they're just function calls, not walkthroughs. Programming is more resemblant to math structure building. You'll notice that a PL translation of a narrative don't look anything like code ('Banquo.take( dagger )'), and declarative knowledge is best (I advance) expressed in a relational language, like SQL. Further, when you have to be precise, PLs (programming languages) are the language to do it in. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:24:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:24:10 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 21 Jan 2009 12:55:42 -0500, Luis Zarrabeitia wrote: > Btw, the correctness of a program (on a turing-complete language) cannot > be statically proven. Ask Turing about it. The correctness of *all* *arbitrary* programs cannot be proven. That doesn't mean that no programs can be proven. -- Steven From castironpi at gmail.com Thu Jan 22 03:28:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 00:28:43 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: On Jan 22, 2:17?am, Steven D'Aprano wrote: > On Wed, 21 Jan 2009 08:17:34 -0700, Joe Strout wrote: > > But of course. ?Any method call is legal only if the form of the call > > matches the method prototype -- if you try to call a function that > > requires 4 parameters, and give it only 3, that's an error too. ?I don't > > see how this is different in any important way. > > But it isn't (presumably) a syntax error. It often is a compile-time error, as opposed to run-time. However, if Joe meant to distinguish between 'Give the ball to Jamie' and 'Give the ball', it is a syntax error: 'Give( the ball, Jamie )' vs. 'Give ( the ball )'. (Wait, is 'give the ball' a syntax error or what?) > I accept that in practice, it isn't a big deal once you get used to the > convention. But it's a special case -- why treat functions of zero > arguments as a special case just to save two characters? In fact, NLs clearly mark the difference between commanding a process, and nominating it. 'Go to the store' is the imperative, while 'Going to the store' is the nominative. In this case, 'ing' serves to mark the absence of parentheses, and the bare form, without 'ing', marks the call. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 22 03:35:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 08:35:37 GMT Subject: Dictionary : items() References: Message-ID: On Wed, 21 Jan 2009 23:02:11 -0800, koranthala wrote: > Hi, > Dictionary has the items method which returns the value as a list > of tuples. > I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. > Currently what I do is: > > class SDict(dict): > def items(self, sort=None): > '''Returns list. Difference from basic dict in that it is > sortable''' > if not sort: > return super(SDict, self).items() > return sorted(self.iteritems(), key=sort) > > Usage: > for a dictionary of strings sorted: > l = abcd.items(sort=lambda x:(x[1].lower(), x[0])) That is better written as: l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) where abcd is *any* kind of mapping with an items() method. It could be a dict, a defaultdict, ordereddict, binarytree, or anything else the caller needs. > Now what I wanted was to incorporate this in the basic dictionary > itself. Not only items(), but the methods similar to it - iteritems etc > all can also have this parameter. > > Please let me know your views. > Is this a good enough idea to be added to the next version of Python? No. -- Steven From http Thu Jan 22 03:53:11 2009 From: http (Paul Rubin) Date: 22 Jan 2009 00:53:11 -0800 Subject: Dictionary : items() References: Message-ID: <7x8wp3wwlk.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > That is better written as: > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) In Python 2.x, I prefer the style l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) but Python 3.0 breaks the tuple unpacking per some PEP. From http Thu Jan 22 03:54:25 2009 From: http (Paul Rubin) Date: 22 Jan 2009 00:54:25 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7x8wp52olk.fsf@ruckus.brouhaha.com> <7xfxjdgpig.fsf@ruckus.brouhaha.com> <7x63k917cd.fsf@ruckus.brouhaha.com> <7xwscpyvrd.fsf@ruckus.brouhaha.com> Message-ID: <7xsknbn2ke.fsf@ruckus.brouhaha.com> Tim Rowe writes: > Programs done in Ada are, by objective measures, more reliable than > those done in C and C++ (the very best released C++ programs are about > as good as the worst released Ada programs), although I've always > wondered how much of that is because of language differences and how > much is because Ada tends to be used on critical projects that also > tend to get a lot more attention to development standards. A reliability comparison between C++ and Java might shed light on that. From bearophileHUGS at lycos.com Thu Jan 22 04:10:10 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 01:10:10 -0800 (PST) Subject: A different kind of interface Message-ID: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> I use the Python shell daily, plus of course normal editors to edit python scripts. They both are very useful for different purposes. But the default interactive shell isn't much handy if you want to modify the past code to run it again, or you want to embed a bit of text in the code, or if you want to produce something a bit more clean that you can save, or just if you want to edit and debug 7-lines long programs. I have tried IPython, but I have never appreciated it too much, maybe because it requires me to remember too many things (and because on Win it's probably a little less handy). Probably I need something closer to an editor and less close to a shell. In past I have also used the interactive editor of Mathematica (older versions, but I think its basic usage isn't changed much later), but despite being quite handy if you want to mix plotting and the editing of small formulas, I can't appreciate it to write programs more than 3 lines long. It's not a good or handy editor, and it has some other disadvantages So I have always tried to think for possible alternative solutions for an interactive way to use Python. I am not looking for something to replace the nornal editors used to write long Python programs. Years ago I have found this nice small program, TextCalc: http://www.atomixbuttons.com/textcalc/ Despite being very limited and being not integrated with everything else, it's so handy that for me in certain situations it's the right tool to use when I have to process numbers and data in simple ways. It helps me keep all the intermediate solutions, you can save the working page just as the text file you are seeing, it's "passive", it doesn't go bang, so if you want you can use it just a primitive text editor. It does something only when you ask it to. And for a basic usage there is nearly nothing to remember. I don't know if this can be any good, but maybe a textcalc-like interface that (beside having few graphical buttons for normal operations, and few basic text editing capabilities) allows to use Python may be a good idea. Probably there are better designs for this interface, but it's hard to invent them. If you have ideas I'd like to know them. Bye, bearophile From vinay_sajip at yahoo.co.uk Thu Jan 22 04:14:02 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 22 Jan 2009 01:14:02 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> Message-ID: <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> On Jan 22, 6:49 am, koranthala wrote: > I understand Vinay. But my point is that I wanted a mechanism to > rotate the log files based on data - i.e. today one log, tomorrow Did you mean "based on date"? > another. This is easier because when trouble tickets are raised, users > mention that X failed at this time. > Now, timedrotatingfilehandler does it - but only if the program is > running the whole length of time. > My tool is invoked by a cron job - so the program runs, then stops > again and again. If you just want a log file whose name is date-based, you don't need a rotating file handler. Compute the file name from the date and use the API to create a FileHandler specifying that file name, and add it to your logger. For example: import logging, time logging.basicConfig(level=logging.DEBUG, filename=time.strftime("/path/ to/my/logs/myapp-%Y-%m-%d-%H%M.log", time.localtime()), filemode="w") logging.debug("Hello, world!") Hopefully you can adapt this snippet to your needs. Regards, Vinay Sajip From novosibirsk at gmail.com Thu Jan 22 04:26:21 2009 From: novosibirsk at gmail.com (novosibirsk at gmail.com) Date: Thu, 22 Jan 2009 01:26:21 -0800 (PST) Subject: Seeking pure Python AES/RSA library compatible with OpenSSL Message-ID: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> Hello, I am faced with the following problem: 0. In pure Python, encrypt some data using AES. 1. In pure Python, encrypt the key used in 0 with RSA, given a private key in PEM format. 2. In C, using OpenSSL, decrypt the AES key from 0 using the public key that corresponds to private key in 1. 3. In C, using OpenSSL, decrypt the data from 0 with AES key from 2. Question --- is there a library I can use for steps 0 and 1? Thanks! From bignose+hates-spam at benfinney.id.au Thu Jan 22 04:33:00 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 22 Jan 2009 20:33:00 +1100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <87prif3ctv.fsf@benfinney.id.au> bearophileHUGS at lycos.com writes: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. > But the default interactive shell isn't much handy if you want to > modify the past code to run it again, or you want to embed a bit of > text in the code, or if you want to produce something a bit more > clean that you can save, or just if you want to edit and debug > 7-lines long programs. Adding an editor to Python solves this problem only for Python. I certainly wouldn't want to learn a new text editor just for one language. You're not *only* programming in Python, I hope? Many of us solve this by using a single full-featured programmer's editor that allows invoking a program ? written in any of *dozens or hundreds* of different languages ? from within the editor. It's a solution that only requires you to learn one editor interface, having chosen one that's well-supported on all popular platforms and with plug-ins accumulated over many years for a smorgasbord of different tasks. The leaders in the field, by far, are GNU Emacs and Vim . -- \ ?Jury: A group of 12 people, who, having lied to the judge | `\ about their health, hearing, and business engagements, have | _o__) failed to fool him.? ?Henry L. Mencken | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 04:33:26 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 10:33:26 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> Message-ID: <49783d5a$0$24804$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: > >> Russ P. a ?crit : >> (snip) >>> In any case, I have suggested that Python should perhaps get a new >>> keyword, "private" or "priv". >> And quite a few people - most of them using Python daily - answered they >> didn't wan't it. > > Then they don't have to use it. Yes they would. Because this would become the official way to tell what's interface and what's implementation, and *this* is the important point. > Lots of people think that double-underscore name mangling is a waste of > time: not strict enough to be useful, not open enough to be Pythonic. > Solution? Don't use double-underscore names. The name-mangling mechanism is actually useful when you want to make sure some vital implementation attribute (usually of a class intented to be extended by the library users) won't be *accidentally* overwritten. From __peter__ at web.de Thu Jan 22 04:34:51 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Jan 2009 10:34:51 +0100 Subject: is this pythonic? References: Message-ID: TP wrote: > Hi, > > Is the following code pythonic: > >>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>>> dict = [ dict for dict in l if dict['title']=='ti'] >>>> l.remove(*dict) >>>> l > [{'title': 'to', 'value': 2}] > > Precision: I have stored data in the list of dictionaries l, because in my > application I am sure that "title" is unique for each record. But perhaps > it is better to imagine that someday it will not be anymore the case? And > rather use a data storage as the following? > > l = { '001':{"title":"to", "value":2}, '002' > {"title":"ti","value":"coucou"}} > > The problem with this storage is that it implies to manipulate some "ids" > that have not any meaning for a humain being (001, 002, etc). > > Thanks a lot for you opinion, If you can change the rest of your program to work smoothly with a dictionary I would suggest the following: >>> items = [{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>> lookup = dict((item["title"], item) for item in items) >>> lookup {'to': {'value': 2, 'title': 'to'}, 'ti': {'value': 'coucou', 'title': 'ti'}} >>> del lookup["ti"] >>> lookup {'to': {'value': 2, 'title': 'to'}} If you later have to accomodate for multiple dictionaries with the same title use lists of dictionaries as values: >> from collections import defaultdict >>> lookup = defaultdict(list) >>> for item in items: ... lookup[item["title"]].append(item) ... >>> lookup defaultdict(, {'to': [{'value': 2, 'title': 'to'}], 'ti': [{'value': 'coucou', 'title': 'ti'}]}) >>> del lookup["ti"] >>> lookup defaultdict(, {'to': [{'value': 2, 'title': 'to'}]}) Peter From bignose+hates-spam at benfinney.id.au Thu Jan 22 04:36:00 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 22 Jan 2009 20:36:00 +1100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <87mydj3cov.fsf@benfinney.id.au> bearophileHUGS at lycos.com writes: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. > But the default interactive shell isn't much handy if you want to > modify the past code to run it again, or you want to embed a bit of > text in the code, or if you want to produce something a bit more > clean that you can save, or just if you want to edit and debug > 7-lines long programs. Adding an editor to Python solves this problem only for Python. I certainly wouldn't want to learn a new text editor just for one language. You're not *only* programming in Python, I hope? Many of us solve this by using a single full-featured programmer's editor that allows invoking a program ? written in any of *dozens or hundreds* of different languages ? from within the editor. It's a solution that only requires you to learn one editor interface, having chosen one that's well-supported on all popular platforms and with plug-ins accumulated over many years for a smorgasbord of different tasks. The leaders in the field, by far, are GNU Emacs and Vim . -- \ ?Jury: A group of 12 people, who, having lied to the judge | `\ about their health, hearing, and business engagements, have | _o__) failed to fool him.? ?Henry L. Mencken | Ben Finney From http Thu Jan 22 04:42:43 2009 From: http (Paul Rubin) Date: 22 Jan 2009 01:42:43 -0800 Subject: Seeking pure Python AES/RSA library compatible with OpenSSL References: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> Message-ID: <7xocxz65ik.fsf@ruckus.brouhaha.com> novosibirsk at gmail.com writes: > 0. In pure Python, encrypt some data using AES. > 1. In pure Python, encrypt the key used in 0 with RSA, given a private > key in PEM format. > Question --- is there a library I can use for steps 0 and 1? I know there are some AES libs around, try google. The libs will be quite slow. I think tlslite can do PEM decoding and PKCS1.5 encryption (http://trevp.net/tlslite). From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 04:55:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 10:55:44 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xocy0ukau.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> <7xocy0ukau.fsf@ruckus.brouhaha.com> Message-ID: <49784295$0$15148$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> In my limited experience with >>> Haskell (statically typed but very high level), >> "dynamic" and "static" were not meant to concern typing here (or at >> least not only typing). > > I'm not sure what you mean by those terms then. Python (and some other dynamic OOPLs) allow you to dynamically add / remove / replace attributes (inclunding methods), either on a per-instance or per-class (at least for class-based oned) basis. >> Haskell and MLs are indeed statically typed, but with a powerfull type >> inference system, which gives great support for genericity >> (hmmm... is that the appropriate word ?) > > I think you mean "polymorphism"; Yeps. > genericity in functional programming > usually means compile time reflection about types. (It means > something different in Java or Ada). > >> Now these are functional languages, so the notion of "access >> restriction" is just moot in this context !-) > > I'm not sure what you mean by that; Haskell certainly supports access > restrictions, through its type and module systems. Same word, somehow different context. What I meant was that since functional languages are (supposedly) stateless, there's no state to make "private". But you're right to correct me wrt/ existing access restrictions in Haskell. >> Ok, I should probably have made clear I was thinking of a hi-level >> dynamic _imperative_ language vs a low-level static _imperative_ >> language. FP is quite another world. > > I'd say that Python's FP characteristics are an important part of its > expressiveness. Indeed - but they do not make Python a functional language[1]. Python is based on objects, not on functions, and quite a lot of the support for functional programing in Python comes from the object system. Just look how functools.partial is implemented. Yes, it could have been implemented with a HOF and closures (and there have been such implementations), but using a class is still the most pythonic way here. [1] except for a very formal definition of "functional language". From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 05:04:12 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 11:04:12 +0100 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <49784490$0$14151$426a74cc@news.free.fr> bearophileHUGS at lycos.com a ?crit : > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. > > I have tried IPython, but I have never appreciated it too much, maybe > because it requires me to remember too many things (and because on Win > it's probably a little less handy). Probably I need something closer > to an editor and less close to a shell. emacs python-mode is a very powerful combo. Write your code in a buffer, send it for evaluation to another buffer running a Python shell, interact with it, switch back to the edit buffer, change your code, lather, rinse, repeat. From novosibirsk at gmail.com Thu Jan 22 05:06:53 2009 From: novosibirsk at gmail.com (novosibirsk at gmail.com) Date: Thu, 22 Jan 2009 02:06:53 -0800 (PST) Subject: Seeking pure Python AES/RSA library compatible with OpenSSL References: <8f8a96d7-7890-4610-bf45-9ac4ac37cff2@s9g2000prg.googlegroups.com> <7xocxz65ik.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 1:42?am, Paul Rubin wrote: > novosibi... at gmail.com writes: > > 0. In pure Python, encrypt some data using AES. > > 1. In pure Python, encrypt the key used in 0 with RSA, given a private > > key in PEM format. > > Question --- is there a library I can use for steps 0 and 1? > > I know there are some AES libs around, try google. ?The libs > will be quite slow. > > I think tlslite can do PEM decoding and PKCS1.5 encryption > (http://trevp.net/tlslite). Yes, tlslite is the only pure Python library I found that deals with PEM. The problem is OpenSSL doesn't want to decrypt data encrypted by tlslite (RSA_public_decrypt(), RSA_PKCS1_PADDING). From deets at nospam.web.de Thu Jan 22 05:15:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 11:15:58 +0100 Subject: USB in python References: Message-ID: <6tqvb2Fcan25U1@mid.uni-berlin.de> Astan Chee wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of using > python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V (or > similar to whatever the power pin is getting). Now I'm confused to if > the software to activate this can actually be written and how do I do > it? Any examples? I've seen pyUSB but it doesn't give me control over > the hardware and how much power is going through the data pins. This doesn't sound like an USB-device to me. The USB-standard defines a serial line protocol, where of course the state of the TX-line is set to whatever the protocol dictates. And as not all of the things put out on the line are of the programmer's own doing, it will be on and off all the time. And no piece of software is going to control that - it's already implemented in the USB-host-controllers inside your computer. Even with a considerably more primitive RS233 line you'd not stand a chance with that design. Unless I'm not getting something here. I've created USB-devices based on the AT90USB1287 from Atmel, and there you can of course use the libusb (and it's wrapping PyUSB) to acccess the device, and e.g. drive a single port-pin of the uC high - to activate, whatever you want to activate. Diez From tino at wildenhain.de Thu Jan 22 05:21:00 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 22 Jan 2009 11:21:00 +0100 Subject: USB in python In-Reply-To: <49782285.9010509@al.com.au> References: <49782285.9010509@al.com.au> Message-ID: <4978488C.3090504@wildenhain.de> Astan Chee wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of using > python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V (or > similar to whatever the power pin is getting). Now I'm confused to if > the software to activate this can actually be written and how do I do > it? Any examples? I've seen pyUSB but it doesn't give me control over > the hardware and how much power is going through the data pins. > Thanks for any help. Your approach doesn't sound right to me. I don't believe you can control the PINs of the USB host interface directly. You need to configure the host controller - OS is giving you interfaces and abstration for the different device types. All you need to do is to implement the end points as per spec in your hardware and write handler for your hardware's USB ids. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mario.ruggier at gmail.com Thu Jan 22 05:30:51 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Thu, 22 Jan 2009 02:30:51 -0800 (PST) Subject: List comprehension - NameError: name '_[1]' is not defined ? References: <33f2783f-2db4-41b6-9a49-bbb337e3be5d@r15g2000prd.googlegroups.com> <017f478e$0$8693$c3e8da3@news.astraweb.com> <02fe75aa-6247-4d76-b77e-26bdf99bda5e@u13g2000yqg.googlegroups.com> <2be16ffe-9030-4639-acae-b01b66006543@w35g2000yqm.googlegroups.com> <57a2f8f6-697a-4fee-a831-b9375bc2c28b@v18g2000pro.googlegroups.com> <7b9728b0-129f-447b-9751-bc6e13a3dbd3@s1g2000prg.googlegroups.com> <7xsknjp12g.fsf@ruckus.brouhaha.com> Message-ID: <36d8b11b-842b-4632-81fb-831f872c7067@a26g2000prf.googlegroups.com> On Jan 16, 7:17?pm, Paul Rubin wrote: > mario ruggier writes: > > All the above attempts will be blocked this way. Any other disallow- > > sub-strings to add to the list above? > > I think what you are trying to do is fundamentally hopeless. ?You > might look at web.py (http://webpy.org) for another approach, that > puts a complete interpreter for a Python-like language into the > template engine. Well, that is a bold statement... but maybe it is explained by what you refer to, so I did a cursory look. But I miss to notice any reference of an embedded "python-like language -- is there some sort of overview of how web.py implements this e.g. something like the equivalent of the doc describing how evoque implements it's sandbox: http://evoque.gizmojo.org/usage/restricted/ I get the feeling you may also be ignoring contextual factors... restricting the full python interpreter is not what we are talking about here, but templating systems (such as web.py?) that just allow embedding of any and all python code will require exactly that. And *that* may well seem fundamentally hopeless. Evoque chooses to allow only expressions, and those under a *managed* context. To make that secure is a whole different (smaller) task. From ricaraoz at gmail.com Thu Jan 22 05:42:11 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 22 Jan 2009 07:42:11 -0300 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) In-Reply-To: <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <49784D83.9040207@gmail.com> Mark Wooding wrote: > Steven D'Aprano writes: > > > >> No it's not. It's *practical*. There are domains where *by law* code >> needs to meet all sorts of strict standards to prove safety and >> security, and Python *simply cannot meet those standards*. >> > > Codswallop. One can prove stuff about Python programs using the same > techniques as one uses for any other language. I've done it. Other > languages have better automated tools, it's true -- but the techniques > are basically the same. > > I've seen this kind of thinking and there are a couple of things about which I've always wondered. Let's say you formally specify an application (hey! you are a zillionaire and can afford it), and that after the app is coded you formally prove that it complies with the specification. Cool! now your app is safe? NO, because your formal proof was done over source code and the compiler has not been formally specified and proven. So your app might still fail. So let's say you have the $ to do that and you get a perfect compiler. Are you safe? NO, because the code generated by the compiler makes calls to the OS which is not specified. So let's assume you are a world leader and you spend a little war's money in fully specifying and proving an OS. Are you safe? NO, because the processor and other hardware logic has NOT been specified. And on and on. What I've seen engineers do when they need extra safety is to put in place independently developed and operated redundant systems, at least three, and the system will do whatever two of the independent systems agree on. So I guess if I really wanted to be safe with a system I'd have it made by at least three different teams (yes, also the requirements should be written by different teams) in different languages under different OS's and different independent machines. And THEN I would have some measure of safety (and this would certainly be more cost effective than the formal specification route). -------------- next part -------------- An HTML attachment was scrubbed... URL: From mario.ruggier at gmail.com Thu Jan 22 05:57:01 2009 From: mario.ruggier at gmail.com (mario g) Date: Thu, 22 Jan 2009 11:57:01 +0100 Subject: Ideas to optimize this getitem/eval call? In-Reply-To: <4960F600.8030909@wildenhain.de> References: <80544a71-8d19-4b85-8b3a-b425d7618d0d@x16g2000prn.googlegroups.com> <016ef9b0$0$8693$c3e8da3@news.astraweb.com> <72c385d5-521e-47e0-a74e-d67bba5169fd@35g2000pry.googlegroups.com> <4960F600.8030909@wildenhain.de> Message-ID: <9b148f5a0901220257w2802109cm2922bb9ff41177c2@mail.gmail.com> On Sun, Jan 4, 2009 at 6:46 PM, Tino Wildenhain wrote: > mario wrote: >> >> On Jan 3, 7:16 am, Steven D'Aprano > cybersource.com.au> wrote: >> >>> I was about to make a comment about this being a security hole, >> >> Strange that you say this, as you are also implying that *all* the >> widely-used templating systems for python are security holes... Well, >> you would be right to say that of course ;-) Infact, evoque is really >> one of the few (or even the only one?) that was conceived from the >> start to support restricted evaluation. > > Thats is definitively not the case. There are at least 2 quite old > template systems on top of a quite good restricted environment. Interesting, which ones? I should have probably emphasized *conceived* above... that feature was there in the initial design and not added afterwards. > Cheers > Tino From digitig at gmail.com Thu Jan 22 06:23:00 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 22 Jan 2009 11:23:00 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <200901211255.42988.kyrie@uh.cu> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: > Btw, the correctness of a program (on a turing-complete language) cannot be > statically proven. Ask Turing about it. For the most safety critical of programmes, for which static proof is required, restrictions are placed on the use of the language that effectively mean that it is not Turing-complete. Specifically, all loops that are required to terminate require a loop variant to be defined. Typically the loop variant is a finite non-negative integer that provably decreases on every pass of the loop, which makes halting decidable. -- Tim Rowe From hv at tbz-pariv.de Thu Jan 22 06:33:24 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 12:33:24 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> Message-ID: <6tr3s4Fcct18U1@mid.individual.net> Bryan Olson schrieb: > Thomas Guettler wrote: >> Sorry, I described my problem not well. Here is more information: > > Actually you did pretty well. > > [...] >> The main application is the intranet web application used with IE (ms >> windows client). > > Your idea of a custom mime-type, with a browser extension, should work. > I don't know of any open-source implementation. > > Do you plan to have just one public key for verifying the downloaded > Python scripts, hard-coded into the extension? Yes, that's what plan: one hard-coded public key is on the client. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From hv at tbz-pariv.de Thu Jan 22 06:38:10 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 12:38:10 +0100 Subject: Start Python at client side from web app In-Reply-To: <6tpo16FbacfjU1@mid.uni-berlin.de> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: <6tr453Fca5h6U1@mid.individual.net> Diez B. Roggisch schrieb: > >> 2) create a localhost web server, for the client side manipulation. >> Then have your remote webserver render a form that posts via >> javavscript to the localhost webserver. The localhost server would >> post back in >> the same way. > > AFAIK the JS security model prevents that. A page requested from "http://myintranetserver/" can redirect to "http://localhost:myport/myapp/?foo=..." this would work. But how should the web server at localhost be started? You need to write a Windows service. I guess that's not very easy, since I am not used to windows programming. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From usenetthrowaway at gmail.com Thu Jan 22 06:56:13 2009 From: usenetthrowaway at gmail.com (Gary) Date: Thu, 22 Jan 2009 11:56:13 -0000 Subject: file write collision consideration References: Message-ID: It would help to know which version of Python when giving examples... I recollect that so-called mutex operation wasn't actually thread safe when using Python 2.5, but perhaps that was wrong, or subsequent versions have fixed that? From chris at simplistix.co.uk Thu Jan 22 07:02:01 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 22 Jan 2009 12:02:01 +0000 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009 Message-ID: <49786039.2020101@simplistix.co.uk> Hi All, Too many people in the Python community think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's PyCon in Chicago on Wednesday, 25th March that will cover working with Excel files in Python using the pure-python libraries xlrd, xlwt and xlutils. I'll be looking to cover: - Reading Excel Files Including formatting, unicode dates and formulae. - Writing Excel Files Including formatting with easyxf and things like freeze pains, print areas, etc - Filtering Excel Files A run through on the structure of xlutils.filter and some examples to show you how it works. - Workshop for your problems I'm hoping anyone who attends will get a lot out of this! If you're planning on attending and have a particular problem you'd like to work on in this part of the tutorial, please drop me an email and I'll try and make sure I come prepared! All you need for the tutorial is a working knowledge of Excel and Python, with a laptop as an added benefit, and to be at PyCon this year: http://us.pycon.org I look forward to seeing you all there! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From hv at tbz-pariv.de Thu Jan 22 07:13:55 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 22 Jan 2009 13:13:55 +0100 Subject: Start Python at client side from web app In-Reply-To: <7x3afcjd90.fsf@ruckus.brouhaha.com> References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <7x3afcjd90.fsf@ruckus.brouhaha.com> Message-ID: <6tr684Fcc0tfU1@mid.individual.net> Paul Rubin schrieb: > Thomas Guettler writes: >> 1. The user pushes a button in the web app. >> 2. Webserver sends signed python code to the client with own mime type >> 3. IE sends code to the python application. >> 4. Signature gets checked, Python code on the client gets executed. >> 5. Maybe send some data to the server with http. > > I think someone else already suggested using an hta. Does that not > do what you want? More info is at: > > http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx > > Also, rather than concocting your own code signing system, maybe you > want to use standard Python .exe packaging, signed with Authenticode. Authenticode looks like a Microsoft invention. Although I need this for windows now, it should be portable. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From bearophileHUGS at lycos.com Thu Jan 22 07:17:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 04:17:57 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> Message-ID: <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> Ben Finney: > Adding an editor to Python solves this problem only for Python. I'm sure that once such "editor" (I use the word editor for lack of a better term) is created, it can also be quickly adapted with other dynamic languages, like Ruby, TCL, Lua, Io, Perl, Awk, ecc. Probably it can't be adapted for languages like Java, C++, etc. > Many of us solve this by using a single full-featured programmer's > editor that allows invoking a program +IBQ- written in any of *dozens or > hundreds* of different languages +IBQ- from within the editor. I don't know what an IBQ is. But I was not talking about a normal editor. Take a look at TextCalc, for example. I am trying to invent something that I have not seen so far :-) > It's a solution that only requires you to learn one editor interface, I'm looking for something very easy to use, probably more easy than the Python shell itself. >The leaders in the field, by far, are GNU Emacs and Vim< I'm probably looking for something based on different ideas. ------------------- Bruno Desthuilliers: >emacs python-mode is a very powerful combo. Write your code in a buffer, send it for evaluation to another buffer running a Python shell, interact with it, switch back to the edit buffer, change your code, lather, rinse, repeat.< I am sure that's very useful, but it's not what I am looking for. I am looking for something that's a bit closer to the Mathematica shell, but more passive and fitter to edit 10-lines long programs too, and able to save the cleaned text result of the interaction. Bye, bearophile From morphex at gmail.com Thu Jan 22 07:25:40 2009 From: morphex at gmail.com (morphex) Date: Thu, 22 Jan 2009 04:25:40 -0800 (PST) Subject: Recommended SOAP library? Message-ID: Hi, I have to implement a service which involves some SOAP/WSDL. So far I've found http://pywebsvcs.sourceforge.net/ Is that the recommended library to build some logic which sets/ retrieves some information from a web service? Thanks, Morten From geraint.williams at gmail.com Thu Jan 22 07:38:37 2009 From: geraint.williams at gmail.com (GHZ) Date: Thu, 22 Jan 2009 04:38:37 -0800 (PST) Subject: Recommended SOAP library? References: Message-ID: <951c75e2-e17f-461c-9228-d4ec42931c47@r10g2000prf.googlegroups.com> if you require a SOAP client, then I would recommend SUDS https://fedorahosted.org/suds/ Other options are not in active development, so is difficult to get support. From stef.mientki at gmail.com Thu Jan 22 07:42:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 22 Jan 2009 13:42:26 +0100 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <497869B2.7050005@gmail.com> Several guys are working on a MatLab like editor / IDE, based on wxPython, including myself ;-) see http://mientki.ruhosting.nl/data_www/pylab_works/pw_debug.html e.g. with F9 it runs either the selected code or if nothing selected the whole code or even more powerfull (depending on your needs) http://mientki.ruhosting.nl/data_www/pylab_works/pw_signal_workbench.html cheers, Stef bearophileHUGS at lycos.com wrote: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. > > I have tried IPython, but I have never appreciated it too much, maybe > because it requires me to remember too many things (and because on Win > it's probably a little less handy). Probably I need something closer > to an editor and less close to a shell. > > In past I have also used the interactive editor of Mathematica (older > versions, but I think its basic usage isn't changed much later), but > despite being quite handy if you want to mix plotting and the editing > of small formulas, I can't appreciate it to write programs more than 3 > lines long. It's not a good or handy editor, and it has some other > disadvantages > > So I have always tried to think for possible alternative solutions for > an interactive way to use Python. I am not looking for something to > replace the nornal editors used to write long Python programs. > > Years ago I have found this nice small program, TextCalc: > http://www.atomixbuttons.com/textcalc/ > > Despite being very limited and being not integrated with everything > else, it's so handy that for me in certain situations it's the right > tool to use when I have to process numbers and data in simple ways. It > helps me keep all the intermediate solutions, you can save the working > page just as the text file you are seeing, it's "passive", it doesn't > go bang, so if you want you can use it just a primitive text editor. > It does something only when you ask it to. And for a basic usage there > is nearly nothing to remember. > > I don't know if this can be any good, but maybe a textcalc-like > interface that (beside having few graphical buttons for normal > operations, and few basic text editing capabilities) allows to use > Python may be a good idea. Probably there are better designs for this > interface, but it's hard to invent them. > > If you have ideas I'd like to know them. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > From alan.isaac at gmail.com Thu Jan 22 07:45:51 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 22 Jan 2009 12:45:51 GMT Subject: Python 3: exec arg 1 In-Reply-To: References: Message-ID: <3UZdl.1235$Aw2.116@nwrddc02.gnilink.net> On 1/20/2009 3:53 PM Rob Williscroft apparently wrote: > http://bugs.python.org/issue1762972 (*) Useful. Thanks. Alan Isaac From Tribulations at Paralleles.invalid Thu Jan 22 08:32:00 2009 From: Tribulations at Paralleles.invalid (TP) Date: Thu, 22 Jan 2009 14:32:00 +0100 Subject: is this pythonic? References: Message-ID: Peter Otten wrote: > If you can change the rest of your program to work smoothly with a > dictionary I would suggest the following: [snip] >>> from collections import defaultdict [snip] Thanks a lot. I didn't know defaultdict. It is powerful. I begin to understand that people prefer using dictionaries than lists, so as to take advantage of their automatic lookup feature. -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 08:32:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 13:32:51 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> Message-ID: <01886bdd$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >> >>> Russ P. a ?crit : >>> (snip) >>>> In any case, I have suggested that Python should perhaps get a new >>>> keyword, "private" or "priv". >>> And quite a few people - most of them using Python daily - answered >>> they didn't wan't it. >> >> Then they don't have to use it. > > Yes they would. Because this would become the official way to tell > what's interface and what's implementation, and *this* is the important > point. But if you have free access to attributes, then *everything* is interface. >> Lots of people think that double-underscore name mangling is a waste of >> time: not strict enough to be useful, not open enough to be Pythonic. >> Solution? Don't use double-underscore names. > > The name-mangling mechanism is actually useful when you want to make > sure some vital implementation attribute (usually of a class intented to > be extended by the library users) won't be *accidentally* overwritten. Except it doesn't. Take this simple module: # module.py class C(object): __n = 3 def spam(self): return "spam " * self.__n class D(C): pass # end module.py I have no interest in C; I may have no idea it even exists. It might be buried deep inside the inheritance hierarchy of the class I really want, D. So now I subclass D: >>> from module import D >>> class C(D): ... __n = 5 ... def ham(self): ... return "I eat ham %d times a day" % self.__n ... >>> C().ham() 'I eat ham 5 times a day' >>> >>> assert C().spam() == D().spam() Traceback (most recent call last): File "", line 1, in AssertionError And now I have accidentally broken the spam() method, due to a name clash. Besides, double-underscore names are a PITA to work with: >>> class Parrot(object): ... __colour = 'blue' ... def __str__(self): ... return 'A %s parrot' % self.__colour ... __repr__ = __str__ ... >>> >>> class RedParrot(Parrot): # Just like Parrot, only red. ... __colour = 'red' ... >>> >>> Parrot() A blue parrot >>> RedParrot() A blue parrot -- Steven From castironpi at gmail.com Thu Jan 22 08:49:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 05:49:30 -0800 (PST) Subject: subclass PyDictObject -- any gotchas? Message-ID: <0f7edac5-c03d-4c18-adb4-015eafc8dba2@e1g2000pra.googlegroups.com> Hello all, I am trying to create a mapping class similar to the base dictionary, but with some added behaviors that affect pointers on a low level. I have a bare-bones version I compiled with MinGW, and it is working! I want to know if there is anything that is going to bite me later, when I start adding real behavior: for example, times when my overrides won't get called, shortcuts, better macros, etc. Later on, I will be altering the 'ma_table' field from one call to another, overriding most of PyDict_Type's methods with before-and- after code, adding synchronization, and copying-and-pasting memory allocation code from 'dictobject.c' directly in, since I need the object to be at specific addresses. Anything I need to beware of? Any reason it might be infeasible? 108 lines, please snip on reply. Thanks in advance and sincerely, A. Brady #include #include using namespace std; typedef struct { PyDictObject base; /* Type-specific fields go here. */ } DictSubObject; static void dictsub_dealloc(register PyDictObject *mp) { cout<< "In 'dictsub_dealloc'"<< endl; PyDict_Type.tp_dealloc((PyObject*)mp); } static int dictsub_ass_sub(DictSubObject *mp, PyObject *v, PyObject *w) { cout<< "In 'dictsub_ass_sub'"<< endl; return PyDict_Type.tp_as_mapping->mp_ass_subscript( (PyObject *) mp, v, w ); } static PyMappingMethods dictsub_as_mapping = { NULL, /*mp_length*/ NULL, /*mp_subscript*/ (objobjargproc)dictsub_ass_sub, /*mp_ass_subscript*/ }; static PyMethodDef DictSub_methods[] = { {NULL} }; PyObject * dictsub_alloc(PyTypeObject *self, Py_ssize_t nitems) { cout<< "In 'dictsub_alloc'"<< endl; return PyDict_Type.tp_alloc(self, nitems); } static PyTypeObject DictSubType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "DictSub", /*tp_name*/ sizeof(DictSubObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)dictsub_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ &dictsub_as_mapping, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "DictSub objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ DictSub_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ dictsub_alloc, /* tp_alloc */ 0, /* tp_new */ }; static PyMethodDef module_methods[] = { {NULL} /* Sentinel */ }; #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ #define PyMODINIT_FUNC void #endif PyMODINIT_FUNC initdictsub(void) { PyObject* m; DictSubType.tp_base= &PyDict_Type; if (PyType_Ready(&DictSubType) < 0) return; m = Py_InitModule3("dictsub", module_methods, "Custom."); Py_INCREF(&DictSubType); PyModule_AddObject(m, "DictSub", (PyObject *)&DictSubType); if (m == NULL) return; } From benjamin.kaplan at case.edu Thu Jan 22 08:50:16 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 22 Jan 2009 08:50:16 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: On Thu, Jan 22, 2009 at 1:16 AM, Aahz wrote: > In article , > Brendan Miller wrote: > > > >PEP 8 doesn't mention anything about using all caps to indicate a > constant. > > Now it does! See > http://www.python.org/dev/peps/pep-0008/ > > Thanks for bringing this up! Since the constants in the std lib (like math.pi and math.e) no longer follow PEP 8, should we expect them to change at some point in the future? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jan 22 09:00:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 06:00:50 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: In article <7xd4ele060.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >alex23 writes: >> >> Here's an article by Guido talking about the last attempt to remove >> the GIL and the performance issues that arose: >> >> "I'd welcome a set of patches into Py3k *only if* the performance for >> a single-threaded program (and for a multi-threaded but I/O-bound >> program) *does not decrease*." > >The performance decrease is an artifact of CPython's rather primitive >storage management (reference counts in every object). This is >pervasive and can't really be removed. But a new implementation >(e.g. PyPy) can and should have a real garbage collector that doesn't >suffer from such effects. CPython's "primitive" storage management has a lot to do with the simplicity of interfacing CPython with external libraries. Any solution that proposes to get rid of the GIL needs to address that. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Thu Jan 22 09:09:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 06:09:02 -0800 Subject: what's the point of rpython? References: Message-ID: In article , Ross Ridge wrote: >Scott David Daniels wrote: >> >>The opcode cannot simply talk to its cache, it must either go directly >>to off-chip memory or communicate to other processors that it (and it >>alone) owns the increment target. > >In fact all it does simply talk to its cache. From the "Intel 64 and >IA-32 Architectures Software Developer's Manual, Volume 3A: System >Programming Guide, Part 1": > > For the P6 and more recent processor families, if the area of > memory being locked during a LOCK operation is cached in the > processor that is performing the LOCK operation as write-back > memory and is completely contained in a cache line, the processor > may not assert the LOCK# signal on the bus. Instead, it will > modify the memory location internally and allow it's cache > coherency mechanism to insure that the operation is carried > out atomically. This operation is called "cache locking." The > cache coherency mechanism automatically prevents two or more > processors that have cached the same area of memory from > simultaneously modifying data in that area. > >The same cache coherency mechanism that prevents ordinary "unlocked" >instructions from simulanteously modifying the same cache line on >two different processors also provides the guarantee with "locked" >instructions. There's no additional hardware locks involved, and no >additional communication required. IIRC, it was Bruce Eckel I heard talking about discovering all kinds of nasty Java thread bugs because cache coherency wasn't working the way the Java developers thought it did.... This is apparently something very difficult to get correct. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 22 09:12:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 22 Jan 2009 15:12:31 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01886bdd$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> Message-ID: <49787ec2$0$4751$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: > >> Steven D'Aprano a ?crit : >>> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >>> >>>> Russ P. a ?crit : >>>> (snip) >>>>> In any case, I have suggested that Python should perhaps get a new >>>>> keyword, "private" or "priv". >>>> And quite a few people - most of them using Python daily - answered >>>> they didn't wan't it. >>> Then they don't have to use it. >> Yes they would. Because this would become the official way to tell >> what's interface and what's implementation, and *this* is the important >> point. > > But if you have free access to attributes, then *everything* is interface. > Nope. >>> Lots of people think that double-underscore name mangling is a waste of >>> time: not strict enough to be useful, not open enough to be Pythonic. >>> Solution? Don't use double-underscore names. >> The name-mangling mechanism is actually useful when you want to make >> sure some vital implementation attribute (usually of a class intented to >> be extended by the library users) won't be *accidentally* overwritten. > > Except it doesn't. Except it works for all real-life code I've ever seen. (snip convoluted counter-example) Steven, sorry for being so pragmatic, but the fact is that, from experience (not only mine - I'm talking about thousands of man/year experience), it JustWork(tm). From morphex at gmail.com Thu Jan 22 09:13:47 2009 From: morphex at gmail.com (morphex) Date: Thu, 22 Jan 2009 06:13:47 -0800 (PST) Subject: Recommended SOAP library? References: <951c75e2-e17f-461c-9228-d4ec42931c47@r10g2000prf.googlegroups.com> Message-ID: On 22 Jan, 13:38, GHZ wrote: > if you require a SOAP client, then I would recommend SUDShttps://fedorahosted.org/suds/ > > Other options are not in active development, so is difficult to get > support. SUDS looks great, thanks for the tip! :) -Morten From makkalot at gmail.com Thu Jan 22 09:24:37 2009 From: makkalot at gmail.com (makkalot at gmail.com) Date: Thu, 22 Jan 2009 16:24:37 +0200 Subject: Jabber xml-rpc Message-ID: <200901221624.38328.makkalot@gmail.com> Hi all i have a program which does some xml-rpc work over SSL, i want now to add some NAT capibilites to my program. The way i thought is to use jabber and send my calls over jabber xml-rpc and ssl it. - Is it the best way to make sth 'natted'? - If yes which library do u reccommend ? twisted or [1] Thanks for your help in advance ... [1] http://pypi.python.org/pypi/Easy%20Jabber%20XML-RPC/1.0 From sturlamolden at yahoo.no Thu Jan 22 09:49:14 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 22 Jan 2009 06:49:14 -0800 (PST) Subject: Executing previous stack frame Message-ID: frame = sys._getframe().f_back is the previous stack frame. Is there any way to execute (with exec or eval) frame.f_code beginning from frame.f_lasti or frame.f_lineno? I am trying to spawn a thread that is initialized with the code and state of the previous stack frame. S.M. From techtonik at gmail.com Thu Jan 22 10:00:26 2009 From: techtonik at gmail.com (anatoly techtonik) Date: Thu, 22 Jan 2009 17:00:26 +0200 Subject: About SCons Re: [Python-Dev] progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 Message-ID: On Thu, Jan 22, 2009 at 12:51 AM, Roumen Petrov wrote: >> >> Against 2.3, rejected due to dependence on SCons. >> Also appears to have been incomplete, needing more work. > > No it was complete but use SCons. Most of changes changes in code you will > see again in 3871. > I would better use SCons for both unix and windows builds. In case of windows for both compilers - mingw and microsoft ones. To port curses extension to windows I need to know what gcc options mean, what are the rules to write Makefiles and how to repeat these rules as well as find options in visual studio interface. Not mentioning various platform-specific defines and warning fixes. -- --anatoly t. From pruebauno at latinmail.com Thu Jan 22 10:04:38 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 22 Jan 2009 07:04:38 -0800 (PST) Subject: is this pythonic? References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> Message-ID: On Jan 21, 4:23?pm, Scott David Daniels wrote: > prueba... at latinmail.com wrote: > > ... If you have duplicates this will not work. You will have to do > > something like this instead: > > >>>> o=[] > >>>> i=0 > >>>> ln=len(l) > >>>> while i > ? ?if l[i]['title']=='ti': > > ? ? ? ? ? ?o.append(l.pop(i)) > > ? ? ? ? ? ?ln-=1 > > ? ?else: > > ? ? ? ? ? ?i+=1 > > Or the following: > ? ? ?indices = [i for i,d in enumerate(l) if d['title']=='ti'] > ? ? ?for i in reversed(indices): # so del doesn't affect later positions > ? ? ? ? ?del l[i] > > --Scott David Daniels > Scott.Dani... at Acm.Org Cool. How come I didn't think of that! That means I can create an evil one liner now >:-). replacecount=len([o.append(l.pop(i)) for i in reversed(xrange(len(l))) if l[i]['title']=='ti']) From pruebauno at latinmail.com Thu Jan 22 10:08:31 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 22 Jan 2009 07:08:31 -0800 (PST) Subject: is this pythonic? References: <8a512848-58ab-4771-ade0-f4d4995ddd67@f3g2000vbf.googlegroups.com> <6tWdneHdOtqID-rUnZ2dnUVZ_g2dnZ2d@pdx.net> Message-ID: On Jan 21, 4:23?pm, Scott David Daniels wrote: > prueba... at latinmail.com wrote: > > ... If you have duplicates this will not work. You will have to do > > something like this instead: > > >>>> o=[] > >>>> i=0 > >>>> ln=len(l) > >>>> while i > ? ?if l[i]['title']=='ti': > > ? ? ? ? ? ?o.append(l.pop(i)) > > ? ? ? ? ? ?ln-=1 > > ? ?else: > > ? ? ? ? ? ?i+=1 > > Or the following: > ? ? ?indices = [i for i,d in enumerate(l) if d['title']=='ti'] > ? ? ?for i in reversed(indices): # so del doesn't affect later positions > ? ? ? ? ?del l[i] > > --Scott David Daniels > Scott.Dani... at Acm.Org Cool. How come I didn't think of that!. Now I can write my evil one liner >:-). o=[l.pop(i) for i in reversed(xrange(len(l))) if l[i]['title']=='ti'] From mdw at distorted.org.uk Thu Jan 22 10:10:04 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 15:10:04 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> <7xwscnhm44.fsf@ruckus.brouhaha.com> Message-ID: <87vds7e5rn.fsf.mdw@metalzone.distorted.org.uk> Paul Rubin writes: > Also, the application area matters. There is a difference between > programming for one's own enjoyment or to do a personal task, and > writing programs whose reliability or lack of it can affect other > people's lives. I've never done any safety-critical programming but I > do a fair amount of security-oriented Internet programming. I do quite a lot of that too. But I don't think it's necessary to have the kinds of static guarantees that a statically-typed language provides in order to write programs which are robust against attacks. Many actual attacks exploit the low-level nature and lack of safety of C (and related languages): array (e.g., buffer) overflows, integer overflows, etc. A language implementation can foil these attacks in one of two (obvious) ways. Firstly, by making them provably impossible -- which would lay proof obligations on the programmer to show that he never writes beyond the bounds of an array, or that arithmetic results are always within the prescribed bounds. (This doesn't seem practical for most programmers.) Secondly, by introducing runtime checks which cause the program to fail safely, either by signalling an exception or simply terminating, when these bad things happen. In the case of array overflows, many `safe' languages implement these runtime checks, and they now seem to be accepted as a good idea. The case of arithmetic errors seems less universal: Python and Lisp fail gracefully to unbounded integers when the machine's limits are exceeded; Java and C# silently give incorrect results[1]. Anyway, Python is exempt from these problems (assuming, at any rate, that the implementation is solid; but we've got to start somewhere). There's a more subtle strain of logical errors which can also be exploited. It's possible that type errors lead to exploitable weaknesses. I don't know of an example offhand, but it seems conceivable that a C program has a bug where an object of one type is passed to a function expecting an object of a different type (maybe due to variadic argument handling, use of `void *', or a superfluous typecast); the contents of this object cause the function to misbehave in a manner convenient to the adversary. In Python, objects have types, and primitive operations verify that they are operating on objects of suitable types, signalling errors as necessary; but higher level functions may simply assume (`duck typing') that the object conforms to a given protocol and expecting a failure if this assumption turns out to be false. It does seem possible that an adversary might arrange for a different object to be passed in, which seems to obey the same protocol but in fact misinterprets the messages. (For example, the function expects a cleaning object, and invokes ob.polish(cup) to make the cup become shiny; in fact, the object is a nationality detector, and returns whether the cup is Polish; the function proceeds with a dirty cup!) Static type systems can mitigate these sorts of `ugly duckling' attacks somewhat, but it's not possible to do so entirely. The object in question may in fact implement the protocol in question (implement the interface, in Java, or be an instance of an appropriate type-class in Haskell) but do so in an unexpected manner. And beyond these kinds of type vulnerabilities are other mistakes which are very unlikely to be caught by even a sophisticated type system; e.g., a function for accepting input to a random number generator, which actually ignores the caller's data! [1] Here, I don't mean to suggest that the truncating behaviour of Java or C# arithmetic can't be used intentionally. Rather, I mean that, in the absence of such an intention, arithmetic in these languages simply yields results which are inconsistent with the usual rules of integer arithmetic. > Finally, your type-A / type-B comparison works best regarding programs > written by one programmer or by a few programmers who communicate > closely. Possibly; but I think that larger groups can cooperate reasonably within a particular style. > I'm working on a Python program in conjunction with a bunch of people > in widely dispersed time zones, so communication isn't so fluid, and > when something changes it's not always easy to notice the change or > understand the reason and deal with it. I'll agree that dynamic languages like Python require a degree of discipline to use effectively (despite the stereotype of type B as ill-disciplined hackers), and that includes communicating effectively with other developers about changes which might affect them. Statically typed languages provide a safety-net, but not always a complete one. One might argue that the static-typing safety-net can lead to complacency -- a risk compensation effect. (I don't have any evidence for this so I'm speculating rather than arguing. I'd be interested to know whether there's any research on the subject, though.) Even so, I don't think I'd recommend Python for a nontrivial project to be implemented by a team of low-to-average-competence programmers. That's not a criticism of Python: I simply don't believe in one-size-fits-all solutions. I'd rather write in Python; I'd probably recommend that the above team use C#. (Of course, I'd rather have one or two highly skilled programmers and use Python, than the low-to- average team; but industry does like its horde-of-monkeys approach.) > There have been quite a few times when some hassle would have been > avoided by the static interfaces mandated in less dynamic languages. > Whether the hassle saved would have been outweighed by the extra > verbosity is not known. This is another question for which it'd be nice to have answers. But, alas, we're unlikely to unless dynamic typing returns to academic favour. > I've found Haskell's type system to work pretty well for the > not-so-fancy things I've tried so far. It takes some study to > understand, but it's very uniform and beautiful. It can be very effective, but I think I have a dynamically-typed brain -- I keep on running into situations where I need more and more exotic type-system features in order to do things the way I naturally want to. It's easier to give up and use Lisp... > I'm having more trouble controlling resource consumption of programs > that are otherwise semantically correct, a well known drawback of lazy > evaluation. I always had difficulty curbing my (natural?) inclination towards tail- recursion, which leads to a lot of wasted space in a normal-order language. > The purpose of unsafePerformIO is interfacing with C programs and > importing them into Haskell as pure functions when appropriate. Yes, that's what I was doing. (I was trying to build a crypto interface using a C library for the underlying primitives, but it became too unwieldy and I gave up.) In particular, I used unsafePerformIO to provide a functional view of a hash function. > The ML family avoids some of Haskell's problems, but is generally less > advanced and moribund. Standard ML seems dead in the water; OCaml looks like it's got some momentum behind it, though, but isn't going in the same direction. > Pretty soon I think we will start seeing practical successor languages > that put the best ideas together. Perhaps... -- [mdw] From google at mrabarnett.plus.com Thu Jan 22 10:13:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jan 2009 15:13:30 +0000 Subject: what's the point of rpython? In-Reply-To: <7xab9kc99i.fsf@ruckus.brouhaha.com> References: <7xk58pgppz.fsf@ruckus.brouhaha.com> <7xab9kc99i.fsf@ruckus.brouhaha.com> Message-ID: <49788D1A.6060407@mrabarnett.plus.com> Paul Rubin wrote: > Ross Ridge writes: >> Scott David Daniels wrote: >>> The opcode cannot simply talk to its cache, it must either go >>> directly to off-chip memory or communicate to other processors >>> that it (and it alone) owns the increment target. > >> The cache coherency mechanism automatically prevents two or more >> processors that have cached the same area of memory from >> simultaneously modifying data in that area. >> >> The same cache coherency mechanism that prevents ordinary >> "unlocked" instructions from simulanteously modifying the same >> cache line on two different processors also provides the guarantee >> with "locked" instructions. There's no additional hardware locks >> involved, and no additional communication required. > > The cache coherency mechanism is what Scott described as > "communicat[ing] to other processors that it (and it alone) owns the > increment target". The cache coherency mechanism is not a trivial > thing at all. It introduces its own hazards and delays, and it is > getting more complicated all the time as processors and caches get > faster and larger. Some time ago, cpu's hit their megahertz limits > and that's why we're using multicores now. Some PL researchers think > cache coherency is going to be the next limit, and are advocating > languages like Erlang, which avoid use of shared memory and have > separate heaps per thread; or alternatively, approaches like the MS > Singularity research OS which relies on something like a linear type > system to statically ensure that a given object is accessible to > only one thread at a time. (That approach allows transferring > objects between threads with no locks or copying required). > How much difference would it make if the reference counts weren't in cached memory? I'm thinking that an object could have a pointer to its reference count, which would be stored elsewhere in some uncached memory. From koranthala at gmail.com Thu Jan 22 10:40:39 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 22 Jan 2009 07:40:39 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: On Jan 22, 2:14?pm, Vinay Sajip wrote: > On Jan 22, 6:49 am,koranthala wrote: > > > I understand Vinay. But my point is that I wanted a mechanism to > > rotate the log files based on data - i.e. today one log, tomorrow > > Did you mean "based on date"? > > > another. This is easier because when trouble tickets are raised, users > > mention that X failed at this time. > > Now, timedrotatingfilehandler does it - but only if the program is > > running the whole length of time. > > My tool is invoked by a cron job - so the program runs, then stops > > again and again. > > If you just want a log file whose name is date-based, you don't need a > rotating file handler. Compute the file name from the date and use the > API to create a FileHandler specifying that file name, and add it to > your logger. For example: > > import logging, time > > logging.basicConfig(level=logging.DEBUG, filename=time.strftime("/path/ > to/my/logs/myapp-%Y-%m-%d-%H%M.log", time.localtime()), filemode="w") > logging.debug("Hello, world!") > > Hopefully you can adapt this snippet to your needs. > > Regards, > > Vinay Sajip Thank you very much Vinay. You have been extremely helpful. This was my first design - but then I found that log system was taking up quite a huge chunk of the memory. That is why I went to rotating file handler. Anyways, now I have modified doRollover to append if file is there, so, for me it is working. What I was thinking was such an option in the basic logging system might be of good help. Again, Vinay, Thank you very much. You were extremely helpful. From kdawg44 at gmail.com Thu Jan 22 10:48:30 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Thu, 22 Jan 2009 10:48:30 -0500 Subject: Python Style Question Message-ID: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each class or One py file with all the classes The classes are small with a constructor and a few methods, no more than a couple, some with just one other method. Which is more "pythonic"? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Thu Jan 22 11:07:44 2009 From: joe at strout.net (Joe Strout) Date: Thu, 22 Jan 2009 09:07:44 -0700 Subject: English-like Python In-Reply-To: References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> Message-ID: <497899D0.5030706@strout.net> Steven D'Aprano wrote: >>> Foo >>> >>> Is that legal RB syntax? >> You betcha! > > How do you know? I haven't specified what Foo does. You haven't specified whether "Foo" is a valid identifier at all, so I'm assuming that it is both valid and used correctly here. The syntax is certainly valid -- it matches the language grammar -- but whether the programmer was smoking something while typing it is another matter. > You can't tell the difference between a syntax error and a valid call > without knowing what Foo does. In Python, you can always recognise a > syntax error without needing to worry about the semantics of the call. > This is not the case with RealBasic. If "Foo" is undefined or not a subroutine with no required parameters, then it's not a syntax error; it's an undefined-identifier error, a you-must-use-the-result-of-this-function-call error, or a invalid-arguments error. It is NOT a syntax error in any case. This is no different in Python, where: Foo() may be valid or not, depending on whether there actually exists a Foo method in an accessible scope that has no required parameters. If so, it's valid Python code; if not, it is some sort of error. The only difference is that RB will detect any of those errors at compile time, while Python will not detect them until this line of code is executed. Given code that compiles/runs without error, the other difference between the two is that in RB, you can tell that Foo has no return value, whereas in Python you can't tell -- and if it does return a value, you can't tell whether the author of the line above is intentionally ignoring it, or was just ignorant. >> Beep >> >> Doesn't get much more readable and syntax-free than that. > > readable doesn't mean smallest amount of syntax possible sometimes syntax > increases the readability of a text as you would see if we for example > dropped all punctuation but you probably already knew that but perhaps > you didnt draw the connection with programming language wink Cute. But I stand by my contention that "Beep" is about the most readable way imaginable to express the "make a beep sound now please" command, and any additional punctuation (parentheses, semicolons, etc.) only get in the way. >> Suppose now >> that a beep isn't eloquent enough, and you want the computer to speak >> something out loud instead. Also easy: > > I've programmed in Hypertalk, which is full of constructs like: > > get the value of field "Bar" > put it into x > put x+37 into x > ask "Eat " & x " pies?" with "Yes please", "No thanks" > if it is "Yes please" then go to card "PieCard" Yes, AppleScript is like this to. Beastly. I consider those to be read-only languages -- easy to read, maddeningly difficult to write, as you often have to guess exactly which English-like construct is going to actually work. > so I understand the principle of leaving out parentheses to make things > look kinda-sorta vaguely English-like. That wasn't really my point here. REALbasic isn't much more English-like than any other language; it's just much lighter on all the extra punctuation that seems to plague many other languages. One Yuma (which uses the same language as RB) user put it this way: "I'm so freaking excited about Yuma that I can barely write about it. It's an HTML preprocessor like PHP, but with clean syntax. This is good because PHP is nasty. It's powerful and ubiquitous, but it looks like someone with a mouthful of punctuation sneezed all over my screen." The same comment would apply to any other C-derived language, such as ActionScript, Java[Script], C++, Obj-C, and so on. Python is better than these, but still not as clean as Python. >> But of course. Any method call is legal only if the form of the call >> matches the method prototype -- if you try to call a function that >> requires 4 parameters, and give it only 3, that's an error too. I don't >> see how this is different in any important way. > > But it isn't (presumably) a syntax error. Right, thanks for confirming my point above. :) > I accept that in practice, it isn't a big deal once you get used to the > convention. But it's a special case -- why treat functions of zero > arguments as a special case just to save two characters? It's not a special case. It's an example of the general case, "only require parentheses where necessary to avoid ambiguity". Pretty much all modern languages (i.e. please don't drag out LISP again) apply this principle in expressions, where "2+(3*5)" is the same as "2+3*5" -- parentheses here are optional because operator precedence already groups the terms unambiguously. This is the same thing: if you want to multiply 10 by the result of a Rnd call and add 5, you can write "10*Rnd()+5" -- but the parentheses here aren't contributing anything. They're not disambiguating anything or grouping anything or otherwise doing a job. So you can instead write "10*Rnd+5" by the general principle above. Similarly, if you have a subroutine call, then parentheses around its arguments don't really contribute anything -- the parser already knows that the list of zero or more comma-separated expressions following the identifier must be arguments. So, again, the parens are optional. > It seems to me that the cost of this is that using functions > as first-class objects takes a major usability hit. That's true. Use of functions in this way is much less common in RB. (And RB doesn't have any equivalent of lambda functions, so the code you wrote isn't easily translatable into RB.) But I suggest that regular function calls are far more common than use of function references, even in Python. Cheers, - Joe From steve at holdenweb.com Thu Jan 22 11:11:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 11:11:35 -0500 Subject: Python Style Question In-Reply-To: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> References: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> Message-ID: K-Dawg wrote: > I am trying to become more pythonic as I learn python and get my mind > around it instead of other languages I have used. > > I have an app that has a series of classes for objects it uses. From a > style perspective, which should be done: > > Different py file for each class > > or > > One py file with all the classes > > The classes are small with a constructor and a few methods, no more than > a couple, some with just one other method. > > Which is more "pythonic"? > One .py file with all the classes. But it's also very pythonic that you have the choice, and can select the option that suits you best ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Vic.Kelson at gmail.com Thu Jan 22 11:13:49 2009 From: Vic.Kelson at gmail.com (Vic Kelson) Date: Thu, 22 Jan 2009 08:13:49 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: How about IDLE? It's a nice tool for the Python programmer. I've tried lots of IDEs, but when it comes down to it, on small-to-medium jobs I am be very productive indeed using IDLE... --v From castironpi at gmail.com Thu Jan 22 11:17:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 22 Jan 2009 08:17:50 -0800 (PST) Subject: subclass PyDictObject -- any gotchas? References: <0f7edac5-c03d-4c18-adb4-015eafc8dba2@e1g2000pra.googlegroups.com> Message-ID: <1409d51b-4c0c-4933-af44-488411d687cf@s9g2000prg.googlegroups.com> On Jan 22, 7:49?am, Aaron Brady wrote: > Hello all, > > I am trying to create a mapping class similar to the base dictionary, > but with some added behaviors that affect pointers on a low level. ?I > have a bare-bones version I compiled with MinGW, and it is working! ?I > want to know if there is anything that is going to bite me later, when > I start adding real behavior: for example, times when my overrides > won't get called, shortcuts, better macros, etc. > > Later on, I will be altering the 'ma_table' field from one call to > another, overriding most of PyDict_Type's methods with before-and- > after code, adding synchronization, and copying-and-pasting memory > allocation code from 'dictobject.c' directly in, since I need the > object to be at specific addresses. ?Anything I need to beware of? > Any reason it might be infeasible? > > 108 lines, please snip on reply. I would also like to know if there is any chance my subclass can use the native garbage collection. For instance, if I could write my own PyObject_MALLOC, then I could use _PyObject_GC_New. It doesn't look promising, since the stuff is all so hard-coded. For instance, '_PyObject_GC_Malloc' uses some module-level variables that make it impossible to duplicate the code, since they are out of scope from my code. What do you think? Is it possible? From morse at edoug.org Thu Jan 22 11:19:27 2009 From: morse at edoug.org (Doug Morse) Date: Thu, 22 Jan 2009 16:19:27 +0000 (UTC) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson wrote: > > > How about IDLE? It's a nice tool for the Python programmer. I've tried > lots of IDEs, but when it comes down to it, on small-to-medium jobs I > am be very productive indeed using IDLE... > > --v I find Stani's Python Editor (SPE) also good for small to medium jobs, and I think that it might achieve many of the OP's objectives. From steve at holdenweb.com Thu Jan 22 11:27:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 11:27:22 -0500 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: Doug Morse wrote: > On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson > wrote: >> >> How about IDLE? It's a nice tool for the Python programmer. I've tried >> lots of IDEs, but when it comes down to it, on small-to-medium jobs I >> am be very productive indeed using IDLE... >> >> --v > > I find Stani's Python Editor (SPE) also good for small to medium jobs, and I > think that it might achieve many of the OP's objectives. > If you just want something small and Python-specific then DrPython is also a reasonable choice. It uses the Scintilla editor component that is also used by Scite, another possibility (though personally I find the bare Scite editor just a little too tweaky to configure). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From eduardo.padoan at gmail.com Thu Jan 22 11:31:56 2009 From: eduardo.padoan at gmail.com (Eduardo O. Padoan) Date: Thu, 22 Jan 2009 14:31:56 -0200 Subject: A different kind of interface In-Reply-To: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: On Thu, Jan 22, 2009 at 7:10 AM, wrote: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. You are almost *describing* reinteract: http://blog.fishsoup.net/2007/11/10/reinteract-better-interactive-python/ It is a mix of a shell and an editor, that lets you go back and rewirte history, and execute it again. It is GTK+, and you can write plugins to plot graphics or display html, for example. -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky From tjreedy at udel.edu Thu Jan 22 11:47:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 11:47:19 -0500 Subject: Python Style Question In-Reply-To: References: <5caea3690901220748g10d535c1q84e7c101ac92fadf@mail.gmail.com> Message-ID: Steve Holden wrote: > K-Dawg wrote: >> I am trying to become more pythonic as I learn python and get my mind >> around it instead of other languages I have used. >> >> I have an app that has a series of classes for objects it uses. From a >> style perspective, which should be done: >> >> Different py file for each class Python is not Java! >> >> or >> >> One py file with all the classes >> >> The classes are small with a constructor and a few methods, no more than >> a couple, some with just one other method. Or if that gets to be too much, a few files each with several related classes. >> Which is more "pythonic"? >> > One .py file with all the classes. But it's also very pythonic that you > have the choice, and can select the option that suits you best ;-) Nice put Steve. tjr From tjreedy at udel.edu Thu Jan 22 11:52:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 11:52:44 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > > > On Thu, Jan 22, 2009 at 1:16 AM, Aahz > wrote: > > In article >, > Brendan Miller > wrote: > > > >PEP 8 doesn't mention anything about using all caps to indicate a > constant. > > Now it does! See > http://www.python.org/dev/peps/pep-0008/ > > Thanks for bringing this up! > > > Since the constants in the std lib (like math.pi and math.e) no longer > follow PEP 8, should we expect them to change at some point in the future? They are natural rather than arbitrary constants that I usually see in caps, so I could see them as being in a different subcategory. From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 11:56:31 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Jan 2009 16:56:31 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> Message-ID: <01889b97$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Thu, 22 Jan 2009 10:33:26 +0100, Bruno Desthuilliers wrote: >> >>> Steven D'Aprano a ?crit : >>>> On Wed, 21 Jan 2009 12:54:31 +0100, Bruno Desthuilliers wrote: >>>> >>>>> Russ P. a ?crit : >>>>> (snip) >>>>>> In any case, I have suggested that Python should perhaps get a new >>>>>> keyword, "private" or "priv". >>>>> And quite a few people - most of them using Python daily - answered >>>>> they didn't wan't it. >>>> Then they don't have to use it. >>> Yes they would. Because this would become the official way to tell >>> what's interface and what's implementation, and *this* is the >>> important point. >> >> But if you have free access to attributes, then *everything* is >> interface. >> >> > Nope. How could anyone fail to be convinced by an argument that detailed and carefully reasoned? >>>> Lots of people think that double-underscore name mangling is a waste >>>> of time: not strict enough to be useful, not open enough to be >>>> Pythonic. Solution? Don't use double-underscore names. >>> The name-mangling mechanism is actually useful when you want to make >>> sure some vital implementation attribute (usually of a class intented >>> to be extended by the library users) won't be *accidentally* >>> overwritten. >> >> Except it doesn't. > > Except it works for all real-life code I've ever seen. > > (snip convoluted counter-example) "Convoluted"? It was subclassing from a class that itself was a subclass. This happens very frequently. The only thing that was a tiny bit unusual was a conjunction of two accidental name clashes: the subclass happened to accidentally have the same name as one of the superclasses, and both of them happened to have a double-underscore attribute. > Steven, sorry for being so pragmatic, but the fact is that, from > experience (not only mine - I'm talking about thousands of man/year > experience), it JustWork(tm). Double-underscore names are great for preventing name clashes, until it doesn't. This isn't something new. Others have pointed out this failure mode, including the Timbot: http://mail.python.org/pipermail/python-dev/2005-December/058563.html I think the attitude towards __names illustrates a huge gulf between two ways of programming. One school of thought tries to write programs that can't fail, and considers failure modes to be bugs to be fixed. The other school of thought tries to write programs that won't fail until something unusual or unexpected happens, and behaves as if the answer to failure modes is "if the function breaks when you do that, then don't do that". Name mangling belongs in the second category. The Python standard library has a split personality in that the parts of it written in C are written so they can't fail, as much as humanly possible. Good luck trying to get list.append() to unexpectedly fail. But the parts written in Python are built to a much lower standard. Look how easy it is to create an object with a ticking time bomb waiting to go off at some later date: >>> from ConfigParser import ConfigParser >>> config = ConfigParser({'a':1}) You've successfully created a ConfigParser object. You'd expect it should be safe to work with now: you haven't messed with any internals or done anything strange, you've just given it a default value. But then, much later: >>> config.get('DEFAULT', 'a') # or any section without option 'a' Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/ConfigParser.py", line 545, in get return self._interpolate(section, option, value, d) File "/usr/local/lib/python2.6/ConfigParser.py", line 585, in _interpolate if "%(" in value: TypeError: argument of type 'int' is not iterable In stricter languages, particularly code with static type checking, the attitude is "you must only provide input that meets these pre- conditions". (Often one pre-condition will be the argument type.) But in Python, the attitude is "you can provide any input you like, but if it fails, don't blame me". -- Steven From rridge at csclub.uwaterloo.ca Thu Jan 22 12:01:47 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 22 Jan 2009 12:01:47 -0500 Subject: what's the point of rpython? References: <7xab9kc99i.fsf@ruckus.brouhaha.com> Message-ID: Ross Ridge writes: > The same cache coherency mechanism that prevents ordinary "unlocked" > instructions from simulanteously modifying the same cache line on > two different processors also provides the guarantee with "locked" > instructions. There's no additional hardware locks involved, and no > additional communication required. Paul Rubin wrote: >The cache coherency mechanism is what Scott described as >"communicat[ing] to other processors that it (and it alone) owns the >increment target". The cache coherency mechanism is not a trivial >thing at all. It introduces its own hazards and delays, and it is >getting more complicated all the time as processors and caches get >faster and larger. *sigh* Could you please just read what I wrote above? The LOCK prefix makes NO DIFFERENCE to anything you mentioned. When current CPython implementation increments a referernce count, it doesn't use the LOCK prefix, but the cache line modified by the instruction still has to be owned by the processor. If it did use the LOCK prefix there would be no change in how how the cache coherency mechanism worked. There'd be no additional complications, hazards or delays in how the processor communicates with other processors. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From tjreedy at udel.edu Thu Jan 22 12:03:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 12:03:53 -0500 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: Steve Holden wrote: > Doug Morse wrote: >> On Thu, 22 Jan 2009 08:13:49 -0800 (PST), Vic Kelson >> wrote: >>> How about IDLE? It's a nice tool for the Python programmer. I've tried >>> lots of IDEs, but when it comes down to it, on small-to-medium jobs I >>> am be very productive indeed using IDLE... Since I currently only program in Python, IDLE does fine for me. Write code, hit F5. If the result is not right, maybe type a few interactive lines to get more info before going back to the edit window. Maybe someday I will look to see what alternatives such as below offer, but if they do not put me in an interactive interpreter or imitation thereof, like IDLE, to do post-mortem examination in, I would not likely switch. >> I find Stani's Python Editor (SPE) also good for small to medium jobs, and I >> think that it might achieve many of the OP's objectives. >> > If you just want something small and Python-specific then DrPython is > also a reasonable choice. It uses the Scintilla editor component that is > also used by Scite, another possibility (though personally I find the > bare Scite editor just a little too tweaky to configure). tjr From vinay_sajip at yahoo.co.uk Thu Jan 22 12:25:56 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 22 Jan 2009 09:25:56 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: On Jan 22, 3:40 pm, koranthala wrote: > Thank you very much Vinay. You have been extremely helpful. > This was my first design - but then I found that log system was taking > up quite a huge chunk of the memory. > That is why I went to rotating file handler. Using just plain FileHandler takes up less memory than using RotatingFileHandler (because using the latter imports the "handlers" module into memory, whereas using the former does not). I'm not aware of any problem where logging takes up a huge chunk of memory (under normal usage) - how did you measure the memory usage which was due to logging? > Anyways, now I have modified doRollover to append if file is there, > so, for me it is working. > What I was thinking was such an option in the basicloggingsystem > might be of good help. The solution I suggested is IMO better than using a patched RotatiingFileHandler, both because it avoids importing an extra module (if memory really is a concern) and because you don't need to change your code across Python version updates. How does my suggestion to use FileHandler not meet your use case? > Again, Vinay, Thank you very much. You were extremely helpful. You're welcome. Best wishes, Vinay Sajip From python at rcn.com Thu Jan 22 13:11:37 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 10:11:37 -0800 (PST) Subject: Counter Class -- Bag/Multiset Message-ID: The collections module in Python 2.7 and Python 3.1 has gotten a new Counter class that works like bags and multisets in other languages. I've adapted it for Python2.5/2.6 so people can start using it right away: http://docs.python.org/dev/library/collections.html#counter-objects Here's a link to the docs for the new class: http://code.activestate.com/recipes/576611/ Raymond From python at rcn.com Thu Jan 22 13:36:24 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 10:36:24 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: > I've adapted it for Python2.5/2.6 so people can start using it right > away: That should just be Python2.6. From bearophileHUGS at lycos.com Thu Jan 22 14:01:15 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 11:01:15 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> Eduardo O. Padoan: > You are almost *describing* reinteract: - Thank you for the link and the software, I have not tried it yet, but from the screencast it looks quite nice. - I am glad that there are people that don't think that Emacs is (despite being good) the alpha and omega of editing. There's space for other ideas beside Emacs. - Maybe I was describing reinteract there, but that's only the first part of my post :-) - I can see that reinteract is based on a interaction style quite similar to the shell of Mathematica. I was talking about something different, and more similar to TextCalc, but in the end I think reinteract may be good enough for my purposes, so I'll try to run it. And I may be happy enough. - Eventually I may find the time and will to create my "interactive python text" :-) I think there's space for many different solutions. - Despite many years of experiments, development, shells, editors, and the like, I am sure there are other designs not yet tried or not common enough yet (beside the normal editors, shells, smart object- oriented graphical shells like hotwire shell, Resolver One, and few other weird things, like one where you can zoom text and images at different scales, other text-based systems, etc). Bye, bearophile From mdw at distorted.org.uk Thu Jan 22 14:10:05 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 19:10:05 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >> Steven D'Aprano a ?crit : >>> But if you have free access to attributes, then *everything* is >>> interface. >> >> Nope. > > How could anyone fail to be convinced by an argument that detailed and > carefully reasoned? Well, your claim /was/ just wrong. But if you want to play dumb: the interface is what's documented as being the interface. You can tell that your claim is simply wrong by pushing it the other way. If everything you have free access to is interface then all behaviour observable by messing with the things you have access to is fair game: you can rely on cmp returning one of {-1, 0, 1} on integer arguments, for example. But no: the Library Reference says only that it returns a negative, zero or positive integer, and /that/ defines the interface. Everything else is idiosyncrasy of the implementation, allowed to change at whim. >>>> from ConfigParser import ConfigParser >>>> config = ConfigParser({'a':1}) [...] > File "/usr/local/lib/python2.6/ConfigParser.py", line 585, in > _interpolate > if "%(" in value: > TypeError: argument of type 'int' is not iterable I'd say that this is a bug. The Library Reference says (9.2): : `ConfigParser([defaults])' : Derived class of `RawConfigParser' that implements the magical : interpolation feature and adds optional arguments to the `get()' : and `items()' methods. The values in DEFAULTS must be : appropriate for the `%()s' string interpolation. Note that : __NAME__ is an intrinsic default; its value is the section name, : and will override any value provided in DEFAULTS. The value 1 is certainly appropriate for `%()s' interpolation: In [5]: '%(foo)s' % {'foo': 1} Out[5]: '1' so you've satisfied the documented preconditions. > In stricter languages, particularly code with static type checking, > the attitude is "you must only provide input that meets these pre- > conditions". You did that. It failed anyway. Therefore it's broken. Report a bug. -- [mdw] From deets at nospam.web.de Thu Jan 22 14:40:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 22 Jan 2009 20:40:38 +0100 Subject: Start Python at client side from web app In-Reply-To: References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> Message-ID: <6ts0dnFc9s0qU1@mid.uni-berlin.de> Rob Williscroft schrieb: > Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in > comp.lang.python: > >>> 2) create a localhost web server, for the client side manipulation. >>> Then have your remote webserver render a form that posts via >>> javavscript to the localhost webserver. The localhost server would >>> post back in the same way. >> AFAIK the JS security model prevents that. >> > > Are you thinking of frames?, or the way IE 7 complains about > runnning javavscript (though it bizzarly calls it an "running > an ActiveX control" )?. Before posting, I tried a jQuery-ajax-call inside Firebug from some random site to google. It bailed out with a security execption. And I found this: """ The Same-Origin Policy The primary JavaScript security policy is the same-origin policy. The same-origin policy prevents scripts loaded from one Web site from getting or setting properties of a document loaded from a different site. This policy prevents hostile code from one site from "taking over" or manipulating documents from another. Without it, JavaScript from a hostile site could do any number of undesirable things such as snoop keypresses while you?re logging in to a site in a different window, wait for you to go to your online banking site and insert spurious transactions, steal login cookies from other domains, and so on. """ http://www.windowsitlibrary.com/Content/1160/22/1.html Now there might be ways around this - but these sure are hacky, and not exactly the thing to look after. Diez From jeff at jmcneil.net Thu Jan 22 14:47:05 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 22 Jan 2009 11:47:05 -0800 (PST) Subject: Executing previous stack frame References: Message-ID: <55769671-b772-48f4-9708-5e007965bbe5@f40g2000pri.googlegroups.com> On Jan 22, 9:49 am, sturlamolden wrote: > frame = sys._getframe().f_back is the previous stack frame. Is there > any way to execute (with exec or eval) frame.f_code beginning from > frame.f_lasti or frame.f_lineno? > > I am trying to spawn a thread that is initialized with the code and > state of the previous stack frame. > > S.M. What are you trying to accomplish? While it's possible to do, I can't believe it's going to be very safe. Note that I'd never even consider doing anything like this for anything of real consequence. That said, it was kind of fun to figure out just for academic purposes... import sys import types import threading def do_something_we_should_not_do(): back = sys._getframe().f_back code_object = back.f_code # Skip CALL_FUNCTION & POP_TOP, otherwise we create # a loop. code = code_object.co_code[back.f_lasti+4:] def tmain(): c = types.CodeType(code_object.co_argcount, code_object.co_nlocals, code_object.co_stacksize, code_object.co_flags, code, code_object.co_consts, code_object.co_names, code_object.co_varnames, code_object.co_filename, code_object.co_name, code_object.co_firstlineno, code_object.co_lnotab) exec c in globals() threading.Thread(target=tmain).start() do_something_we_should_not_do() # Anything below here will run in both threads. print threading.current_thread() Thanks, Jeff mcjeff.blogspot.com From proteusguy at gmail.com Thu Jan 22 15:26:03 2009 From: proteusguy at gmail.com (proteusguy at gmail.com) Date: Thu, 22 Jan 2009 12:26:03 -0800 (PST) Subject: Dealing with large memory under linux or How to Build 64bit Python Message-ID: I've got an Ubuntu (2.6.27-9-server SMP i686 GNU/Linux) setup with 6GB RAM running python 2.5. I'm running a simulation program that is breaking as soon as it hits ~3GB RAM even though I have plenty of RAM free. I'm guessing that it's because my python is only 32-bit? Appreciate any pointers on how to get my app to be capable of using the full amount of RAM. I'm anticipating this may require me to rebuild python from scratch for 64bits but I can't find instructions on how to do that. Appreciate any help in this matter. -- Ben Scherrey From martin at v.loewis.de Thu Jan 22 15:30:30 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 22 Jan 2009 21:30:30 +0100 Subject: Dealing with large memory under linux or How to Build 64bit Python In-Reply-To: References: Message-ID: <4978D766.4010906@v.loewis.de> > I've got an Ubuntu (2.6.27-9-server SMP i686 GNU/Linux) setup with > 6GB RAM running python 2.5. I'm running a simulation program that is > breaking as soon as it hits ~3GB RAM even though I have plenty of RAM > free. I'm guessing that it's because my python is only 32-bit? If you do use a 32-bit python, then yes, that's the reason. > Appreciate any pointers on how to get my app to be capable of using > the full amount of RAM. I'm anticipating this may require me to > rebuild python from scratch for 64bits but I can't find instructions > on how to do that. As a starting point, you need to install a 64-bit operating system. If you are running a 32-bit kernel, then there is *no way* that you could possibly run a 64-bit Python on it. When you do install a 64-bit (i.e. AMD64) version of Ubuntu, it will come with a 64-bit Python executable, so no need to build Python at all. If you still wish to rebuild Python, then, on the 64-bit Ubuntu, the standard configure;make;make install will do the trick. Regards, Martin From Scott.Daniels at Acm.Org Thu Jan 22 15:32:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 22 Jan 2009 12:32:00 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: Tim Rowe wrote: >> Btw, the correctness of a program (on a turing-complete language) cannot be >> statically proven. Ask Turing about it. > > For the most safety critical of programmes, for which static proof is > required, restrictions are placed on the use of the language that > effectively mean that it is not Turing-complete. Specifically, all > loops that are required to terminate require a loop variant to be > defined. Typically the loop variant is a finite non-negative integer > that provably decreases on every pass of the loop, which makes halting > decidable. Having once been a more type-A, I labored for a couple of years trying to build a restricted language that provably terminated for work on an object-oriented database research. I finally gave it up as a bad idea, because, in practice, we don't care if a loop will terminate or not in database work; a transaction that takes a year to commit is equivalent to an infinite loop for all applications that I have interacted with (and yes, I have worked allowing four day transactions to commit). --Scott David Daniels Scott.Daniels at Acm.Org From python at rcn.com Thu Jan 22 15:41:13 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 22 Jan 2009 12:41:13 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <7eb38a4d-18fa-4542-8eb2-8910bd75b7ec@r41g2000prr.googlegroups.com> > That should just be Python2.6. Fixed. Now runs of Python 2.5 as well. From BrianVanderburg2 at aim.com Thu Jan 22 15:47:46 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 15:47:46 -0500 Subject: USB in python In-Reply-To: <49782285.9010509@al.com.au> References: <49782285.9010509@al.com.au> Message-ID: <4978DB72.6090307@aim.com> astan.chee at al.com.au wrote: > Hi, > Im trying to write a program for my USB device and I'm thinking of > using python to do this. The USB device is of my own making and it is > activated when one of the two data pins of the USB is given about 5V > (or similar to whatever the power pin is getting). Now I'm confused to > if the software to activate this can actually be written and how do I > do it? Any examples? I've seen pyUSB but it doesn't give me control > over the hardware and how much power is going through the data pins. > Thanks for any help. > Cheers > Astan > -- > http://mail.python.org/mailman/listinfo/python-list I don't think you can actually control the USB port's data lines like this. I've been searching for some ideas as well for some small hobbyist projects I'm thinking about, and it seems that either the EZUSB chip or maybe even easier the FTDI chips might be the way to go. I think the FTDI chip is basically a USB-to-RS232 converter and there is a libftdi that is built on top of libusb I think. Anyway for my design (if I ever get around to it) I'm going to create a library in C that uses the hardware and then I can create a Python wrapper around that library. Brian Vanderburg II From BrianVanderburg2 at aim.com Thu Jan 22 15:55:10 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 15:55:10 -0500 Subject: pep 8 constants In-Reply-To: References: Message-ID: <4978DD2E.1090008@aim.com> bockman at virgilio.it wrote: > Constants would be a nice addition in python, sure enough. > But I'm not sure that this can be done without a run-time check every time > the constant is used, and python is already slow enough. Maybe a check > that is disabled when running with optimizing flags ? > > But I'm sure this discussion has been already made and the FINAL WORD has > been already spoken. > > Ciao > ---- > FB > -- > http://mail.python.org/mailman/listinfo/python-list > One idea to make constants possible would be to extend properties to be able to exist at the module level as well as the class level: @property def pi(): return 3.14159..... print(pi) # prints 3.14159.... pi=32 # Raise an error Cannot set attribute ... Brian Vanderburg II From mdw at distorted.org.uk Thu Jan 22 15:59:37 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 22 Jan 2009 20:59:37 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <497372e7$0$23747$426a74cc@news.free.fr> <29cdb9b4-c481-4d76-9a74-20a69a96c7f1@g39g2000pri.googlegroups.com> <49749892$0$23985$426a74cc@news.free.fr> <7xfxjett86.fsf@ruckus.brouhaha.com> <4975d297$0$24204$426a34cc@news.free.fr> <7xprih5d5z.fsf@ruckus.brouhaha.com> <497712dc$0$7896$426a74cc@news.free.fr> <7xocy0ukau.fsf@ruckus.brouhaha.com> <49784295$0$15148$426a74cc@news.free.fr> Message-ID: <874ozrdpl2.fsf.mdw@metalzone.distorted.org.uk> Bruno Desthuilliers writes: > Paul Rubin a ?crit : >> I'd say that Python's FP characteristics are an important part of its >> expressiveness. > > Indeed - but they do not make Python a functional language[1]. Python is > based on objects, not on functions, I'd have a good go at defining a functional language as one which treats functions as first-class objects -- i.e., can be passed as arguments, returned as results, stored in data structures, etc. In that regard, Python is a proper paid-up functional programming language. It's not a /pure/ language -- i.e., there are side effects -- but ML has those too and it's widely considered functional; and it's not lazily evaluated -- but again neither is ML. -- [mdw] From sturlamolden at yahoo.no Thu Jan 22 16:16:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 22 Jan 2009 13:16:29 -0800 (PST) Subject: Executing previous stack frame References: <55769671-b772-48f4-9708-5e007965bbe5@f40g2000pri.googlegroups.com> Message-ID: On Jan 22, 8:47 pm, Jeff McNeil wrote: > What are you trying to accomplish? On Jan 22, 8:47 pm, Jeff McNeil wrote: > What are you trying to accomplish? While it's possible to do, I can't > believe it's going to be very safe. I am trying to implement a completely new concurrency abstraction for Python. It is modeled on OpenMP instead of Java threads (cf. threading and multiprocessing). I am planning to use thread and multiprocessing (or os.fork) as backends. Doing this with os.fork is child's play, but it would not work on Windows. I believe Python context managers are excellent for this purpose. I believe the OpenMP way of doing concurrency fits better with the mind than Java threading, and thus are more pythonic. Algorithms can be written as sequential, and transformed to parallel code with the simple insertion of a few directives. It makes debugging easier, because one can debug the sequential code, and it makes it easier to avoid the problems with deadlocks, race conditions, livelocks, etc. Just ask any C or Fortran programmer how much easier it is to use OpenMP instead of Win32 or Posix threads. What I have in mind is an API that would look approximately like this (OpenMP pragmas for C on top, proposed Python equivalent below): #pragma omp parallel with Pool() as pool: #pragma omp for for item in pool.parallel(): #pragma omp for shedule(guided) for item in pool.parallel(, shed='guided'): #pragma omp parallel for with Pool() as pool: for item in pool.parallel(): #pragma omp barrier pool.barrier() #pragma omp section with pool.section(): #pragma omp parallel sections with Pool() as pool: with pool.section(): fun1(*args, **kwargs) with pool.section(): fun2(*args, **kwargs) #pragma omp master if pool.master: #pragma omp critical #pragma omp atomic with pool.lock: #pragma omp single with pool.single(): #pragma omp ordered with ordered(k): Here is a toy example of what I have in mind. Say you would want to compute the DFT of some signal (real apps would use an FFT in C for this, but never mind that). In Python using an O(n**2) algorithm, this would look like something like this: def real_dft(x): ''' DFT for a real valued sequence x ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 for n in range(M): s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) r.append(s) return r Then, one could 'magically' transform this algorithm into to a parallel one simply by inserting directives from the 'OpenMP' module: def real_dft(x): ''' DFT for a real valued sequence x ''' ''' parallelized ''' r = [] N = len(x) M = N//2 + 1 if N%2 else N//2 with Pool() as pool: parallel_iter = pool.parallel(range(M)): for n in parallel_iter: s = 0j for k in range(N): tmp = 2*pi*k*n/N s += x[k] * (cos(tmp) - 1j*sin(tmp)) with parallel_iter.ordered(n): r.append(s) return r The idea is that 'parallelizing' a sequential algorithm like this is much easier than writing a parallel one from scratch using the abstractions in threading or multiprocessing. The problem is that the __enter__ method of the Pool object (the context manager) must spawn multiple threads, each executing sys._getframe().f_back, because the 'with Pool() as pool:' should be executed by multiple threads in parallel. These slave threads will be killed when they enter the __exit__ method of its context manager. Most of this OpenMP API has already been implemented. I just need the machinery to make the slave threads come alive :) I'll take a look at your code now :) Regards, Sturla Molden From rtw at freenet.co.uk Thu Jan 22 16:37:44 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 22 Jan 2009 15:37:44 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6tr453Fca5h6U1@mid.individual.net> Message-ID: Thomas Guettler wrote in news:6tr453Fca5h6U1 at mid.individual.net in comp.lang.python: > Diez B. Roggisch schrieb: >> >>> 2) create a localhost web server, for the client side manipulation. >>> Then have your remote webserver render a form that posts via >>> javavscript to the localhost webserver. The localhost server would >>> post back in >>> the same way. >> >> AFAIK the JS security model prevents that. > > A page requested from "http://myintranetserver/" can redirect to > "http://localhost:myport/myapp/?foo=..." > > this would work. > > But how should the web server at localhost be started? You need to > write a Windows service. Since there will be only one client a regular programme should be fine. > I guess that's not very easy, since I am not > used to windows programming. Then don't do any (windows programming), do Python: http://docs.python.org/3.0/library/wsgiref.html#module- wsgiref.simple_server http://docs.python.org/3.0/library/cgi.html#functions Rob. -- http://www.victim-prime.dsl.pipex.com/ From kyrie at uh.cu Thu Jan 22 16:48:07 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Thu, 22 Jan 2009 16:48:07 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01886bdd$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> Message-ID: <200901221648.07591.kyrie@uh.cu> On Thursday 22 January 2009 08:32:51 am Steven D'Aprano wrote: > And now I have accidentally broken the spam() method, due to a name clash. True, that's bad. I wish that were 'fixed'. > Besides, double-underscore names are a PITA to work with: Isn't that example the point of having self.__private variables? To make sure that the Parrot.__private attributes don't clash with the RedParrot.__private attributes with the same name? [parrot example follows just for context, but my reply ends here] > >>> class Parrot(object): > > ... ? ? __colour = 'blue' > ... ? ? def __str__(self): > ... ? ? ? ? return 'A %s parrot' % self.__colour > ... ? ? __repr__ = __str__ > ... > > >>> class RedParrot(Parrot): # Just like Parrot, only red. > > ... ? ? __colour = 'red' > ... > > >>> Parrot() > > A blue parrot > > >>> RedParrot() > > A blue parrot -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From gagsl-py2 at yahoo.com.ar Thu Jan 22 16:49:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 19:49:38 -0200 Subject: Mechanize hanging References: <5caea3690901211721s35c9e39enb1f3df12b0a0479c@mail.gmail.com> Message-ID: En Wed, 21 Jan 2009 23:21:06 -0200, K-Dawg escribi?: > I am trying to use mechanize to connect and log into Yahoo! > > Here is my code: > > #c:\Python25\python > import re > import urllib > import urllib2 > import mechanize > > print "print1" > br = mechanize.Browser() > br.set_handle_robots(False) > br.open("https://login.yahoo.com/config/login?") > > It is hanging at the open. Eventually I have to just kill it and I get > this: Sockets are blocking by default - and never time out. See if mechanize has some way to set a timeout - otherwise you may try the code below, before anything else: socket.setdefaulttimeout(60) -- Gabriel Genellina From rtw at freenet.co.uk Thu Jan 22 16:59:22 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 22 Jan 2009 15:59:22 -0600 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6ts0dnFc9s0qU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote in news:6ts0dnFc9s0qU1 at mid.uni-berlin.de in comp.lang.python: > Rob Williscroft schrieb: >> Diez B. Roggisch wrote in news:6tpo16FbacfjU1 at mid.uni-berlin.de in >> comp.lang.python: >> >>>> 2) create a localhost web server, for the client side manipulation. >>>> Then have your remote webserver render a form that posts via >>>> javavscript to the localhost webserver. The localhost server would >>>> post back in the same way. >>> AFAIK the JS security model prevents that. >>> >> >> Are you thinking of frames?, or the way IE 7 complains about >> runnning javavscript (though it bizzarly calls it an "running >> an ActiveX control" )?. > > Before posting, I tried a jQuery-ajax-call inside Firebug from some > random site to google. It bailed out with a security execption. Yes the XMLHttpRequest object only allows you to make requests to the same domain as the page came from. Here is a concrete example of what I suggested:
I.e. 1 line of JS that is manipulating the document of the page it belongs to. > > And I found this: > > """ > > The Same-Origin Policy > The primary JavaScript security policy is the same-origin policy. The > same-origin policy prevents scripts loaded from one Web site from > getting or setting properties of a document loaded from a different > site. This policy prevents hostile code from one site from "taking > over" or manipulating documents from another. Without it, JavaScript > from a hostile site could do any number of undesirable things such as > snoop keypresses while you???re logging in to a site in a different > window, wait for you to go to your online banking site and insert > spurious transactions, steal login cookies from other domains, and so > on. """ > > http://www.windowsitlibrary.com/Content/1160/22/1.html > > Now there might be ways around this - but these sure are hacky, and > not exactly the thing to look after. That is scripting across frames (or windows), where the frames have a different origin (from different domain). As an aside if the OP's app' can live with sending at most about 1KB of ascii back and forth then using a HTTP redirect header is another option. Rob. -- http://www.victim-prime.dsl.pipex.com/ From BrianVanderburg2 at aim.com Thu Jan 22 17:00:46 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 17:00:46 -0500 Subject: Idea to support public/private. Message-ID: <4978EC8E.6080904@aim.com> Okay so I don't really care about public/private but I was watching the lists (Does python follow its idea of readability or something like that) and I thought of a 'possible' way to add this support to the language. I have implemented a class which allows creating both a private as well as a protected member, only it is currently a bit of work. It could perhaps be reworked into decorators. import sys import inspect def get_private_codes(class_): codes = [] for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes def get_protected_codes(class_, codes=None): if codes is None: codes = [] for i in class_.__bases__: get_protected_codes(i, codes) for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes class Test(object): def __init__(self): self.protected = 45 self.private = 34 def setprotected(self, value): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): self.__protect_value_ZR20 = value else: raise "Protected Write Error" def getprotected(self): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): return self.__protect_value_ZR20 else: raise "Protected Read Error" protected = property(getprotected, setprotected) def setprivate(self, value): frame = sys._getframe(1) if frame.f_code in get_private_codes(self.__class__): self.__private_value_ZR20 = value else: raise "Private Write Error" def getprivate(self): frame = sys._getframe(1) if frame.f_code in get_private_codes(self.__class__): return self.__private_value_ZR20 else: raise "Private Read Error" private = property(getprivate, setprivate) class Test2(Test): def __init__(self): self.protected = 1 a=Test() b=Test2() #print a.private #a.private = 1 #print a.protected #a.protected = 1 From gagsl-py2 at yahoo.com.ar Thu Jan 22 17:01:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:01:44 -0200 Subject: One Bug of Python 3.0 References: Message-ID: En Fri, 16 Jan 2009 01:56:23 -0200, escribiste en el grupo gmane.comp.python.general > I met a bug of CGIXMLRPCRequestHandler in Python3.0. Because of the bug, > couldn't use RPC in Apache CGI. You should file a bug report at http://bugs.python.org -- Gabriel Genellina From toby at tobiah.org Thu Jan 22 17:04:15 2009 From: toby at tobiah.org (Tobiah) Date: Thu, 22 Jan 2009 14:04:15 -0800 Subject: unzip array of arrays? Message-ID: Although it's trivial to program, I wondered whether there was a builtin or particularly concise way to express this idea: > a = [(1, 2), (3, 4), (5, 6)] > field[a, 2] [2, 4, 6] where field() is some made up function. Thanks, Toby From invalid at invalid Thu Jan 22 17:12:38 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 22 Jan 2009 16:12:38 -0600 Subject: unzip array of arrays? References: Message-ID: On 2009-01-22, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. The above example is a great application for numpy's array type: http://numpy.scipy.org/ Here's an example showing how you extract a column using indexing operations: http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c [I assume numpy is still the numerical/array package du jour?] -- Grant Edwards grante Yow! WHO sees a BEACH BUNNY at sobbing on a SHAG RUG?! visi.com From clp2 at rebertia.com Thu Jan 22 17:13:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 14:13:34 -0800 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: <50697b2c0901221413l6deee1ack83b693134623b30@mail.gmail.com> On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) [GCC 4.0.1 (Apple Inc. build 5484)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a= [(1, 2), (3, 4), (5, 6)] >>> zip(*a) [(1, 3, 5), (2, 4, 6)] >>> zip(*a)[1] (2, 4, 6) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rt8396 at gmail.com Thu Jan 22 17:15:22 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 14:15:22 -0800 (PST) Subject: Find all available Tkinter cursor names? Message-ID: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> Anybody know how to find all the available Tkinter cursor icon names, or where the icons are stored? like "paintbrush" "pencil" etc... From BrianVanderburg2 at aim.com Thu Jan 22 17:16:13 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 22 Jan 2009 17:16:13 -0500 Subject: Idea to support public/private. In-Reply-To: <4978EC8E.6080904@aim.com> References: <4978EC8E.6080904@aim.com> Message-ID: <4978F02D.1080401@aim.com> There was a small error in setprivate/getprivate: import sys import inspect def get_private_codes(class_): codes = [] for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes def get_protected_codes(class_, codes=None): if codes is None: codes = [] for i in class_.__bases__: get_protected_codes(i, codes) for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes class Test(object): def __init__(self): self.protected = 45 self.private = 34 def setprotected(self, value): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): self.__protect_value_ZR20 = value else: raise "Protected Write Error" def getprotected(self): frame = sys._getframe(1) if frame.f_code in get_protected_codes(self.__class__): return self.__protect_value_ZR20 else: raise "Protected Read Error" protected = property(getprotected, setprotected) def setprivate(self, value): frame = sys._getframe(1) if frame.f_code in get_private_codes(Test): self.__private_value_ZR20 = value else: raise "Private Write Error" def getprivate(self): frame = sys._getframe(1) if frame.f_code in get_private_codes(Test): return self.__private_value_ZR20 else: raise "Private Read Error" private = property(getprivate, setprivate) class Test2(Test): def __init__(self): self.protected = 1 self.private = 1 a=Test() b=Test2() #print a.private #a.private = 1 #print a.protected #a.protected = 1 From gagsl-py2 at yahoo.com.ar Thu Jan 22 17:17:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:17:22 -0200 Subject: os.path.getmtime on windows, error: 206 - path or extension too long References: <187e1a44-eda9-439b-8e4c-182d697035d7@f40g2000pri.googlegroups.com> Message-ID: En Wed, 21 Jan 2009 08:50:53 -0200, mynthon escribi?: > I have very long path on windows and i get error when try to get > modification time. So i tried do chdir path and then get file. It now > gives me error that file doesn't exists [...] > it works for other files so i suppose it is not my fault. I know there > is a win32 module but i can't find any documentation for it (what is > the purpose to create app without docs?). Any idea? win32api is part of the pywin32 package, available at http://pywin32.sf.net This is not a Python standard package - you either installed it yourself some time ago (and forgot about it) or perhaps you're using the Enthought bundle (which includes pywin32 and PythonWin). Either way, you surely have the PyWin32.chm help file installed too. En Wed, 21 Jan 2009 12:11:03 -0200, mynthon escribi?: > you can also use \\?\ prefix but ONLY FOR unicode strings > > os.path.getmtime("\\\\?\\c:\\very lon path\\blablabla") #will not work > os.path.getmtime(u"\\\\?\\c:\\very lon path\\blablabla") #will work Looks like you found the "official" answer to your problem. Notice that the path must be "normalized" in this case - that means, it must not contain "." nor ".." components. -- Gabriel Genellina From lenz at joinville.udesc.br Thu Jan 22 17:34:11 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Thu, 22 Jan 2009 14:34:11 -0800 Subject: A different kind of interface In-Reply-To: References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: <200901221434.12003.lenz@joinville.udesc.br> On Thursday 22 January 2009 08:13:49 Vic Kelson wrote: > How about IDLE? It's a nice tool for the Python programmer. I've tried > lots of IDEs, but when it comes down to it, on small-to-medium jobs I > am be very productive indeed using IDLE... > > --v > -- > http://mail.python.org/mailman/listinfo/python-list How about Eric ? -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From SabbySF at aol.com Thu Jan 22 17:48:04 2009 From: SabbySF at aol.com (SabbySF at aol.com) Date: Thu, 22 Jan 2009 17:48:04 EST Subject: To: Julian Snitow Message-ID: I got this from a website and have no idea if you will get this. Since you are in charge of Anime at Boskone 46, do you know when the schedule will be published on line.For the last two years the Anime schedule was not published on line and that meant I could not do research on anime that I was unfamilier with. Thank you for any help you can give me. **************Inauguration '09: Get complete coverage from the nation's capital. (http://news.aol.com/main/politics/inauguration?ncid=emlcntusnews00000003) -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Thu Jan 22 17:48:19 2009 From: http (Paul Rubin) Date: 22 Jan 2009 14:48:19 -0800 Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> <6toehtFbrb81U1@mid.individual.net> <6tpo16FbacfjU1@mid.uni-berlin.de> <6ts0dnFc9s0qU1@mid.uni-berlin.de> Message-ID: <7x7i4nrm8c.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Before posting, I tried a jQuery-ajax-call inside Firebug from some > random site to google. It bailed out with a security execption. You should be able to get around the security policy with XUL in Firefox, or with an ActiveX control in MSIE. In the Netscape Navigator era there was a security policy Java object so you could turn the security stuff on and off if the user gave permission from a pop-up dialog. I've been away from that scene for a while so I don't know if Firefox has anything like it. From ricaraoz at gmail.com Thu Jan 22 17:50:33 2009 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 22 Jan 2009 19:50:33 -0300 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xwscnhm44.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <87ocy0fbfp.fsf.mdw@metalzone.distorted.org.uk> <7xwscnhm44.fsf@ruckus.brouhaha.com> Message-ID: <4978F839.2030205@gmail.com> Paul Rubin wrote: > Mark Wooding writes: > >> Some people (let's call them `type A programmers') have decided that >> they want to be assisted with writing correct programs... >> Other people (`type B programmers') don't like having their (apparently? >> possibly?) correct programs rejected.... >> I think trying to persuade a type A programmer that he wants to work >> like a type B programmer, or /vice versa/, is difficult, bordering on >> futile. Type A stereotypes type B as a bunch of ill-disciplined >> reckless hackers; type B stereotypes type A as killjoy disciplinarians. >> Meeting in the middle is difficult. (`We just want to add a little >> safety.' `You want to take away our freedom!' Etc., /ad nauseam/.) >> > > That's an interesting analysis. You know, I think I'm really a type B > programmer, interested in type A techniques and tools for the same > reason someone who naturally sleeps late is interested in extra-loud > alarm clocks. > > Also, the application area matters. There is a difference between > programming for one's own enjoyment or to do a personal task, and > writing programs whose reliability or lack of it can affect other > people's lives. I've never done any safety-critical programming but I > do a fair amount of security-oriented Internet programming. As such, > I have to always assume that my programs will be attacked by people > who are smarter than I am and know more than I do. I can't possibly > out-think them. If I don't see problems in a program, it's still > plausible that someone smarter than me will spot something I missed. > Therefore, my failure to detect the presence of problems is not > reassuring. What I want is means of verifying the absence of > problems. > Mmmmm..... your "means of verifying the absence of problems" were coded/thought by some other person who also has a measurable amount of intelligence. So it follows that there will be somebody else who is smarter and will spot something this other person missed and will be able to subvert those "means". So it would seem that by thinking you can "verify" the absence of problems you are trying to get a false sense of security that actually does not exist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Jan 22 17:57:02 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 22 Jan 2009 16:57:02 -0600 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: Unknown wrote: > On 2009-01-22, Tobiah wrote: >> Although it's trivial to program, I wondered whether >> there was a builtin or particularly concise way to >> express this idea: >> >>> a = [(1, 2), (3, 4), (5, 6)] >>> field[a, 2] >> [2, 4, 6] >> >> where field() is some made up function. > > The above example is a great application for numpy's array > type: > > http://numpy.scipy.org/ > > Here's an example showing how you extract a column using > indexing operations: > > http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c > > [I assume numpy is still the numerical/array package du jour?] 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 gagsl-py2 at yahoo.com.ar Thu Jan 22 17:58:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 22 Jan 2009 20:58:14 -0200 Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> Message-ID: En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson escribi?: > The following code uses ossaudiodev to read 1000 values from > my sound card at a rate of 12,000 samples per second: > > When I select a sample rate that is not a power of 2 times > 3000 samples/second, a strong and very regular sawtooth is > superimposed on the signal. At some sampling frequencies, > it appears as a rising sawtooth, and at other sampling > frequencies it is a declining sawtooth, so I'm presumably > lost in some aliasing wilderness. As best I can tell, > it's a 48 KHz sawtooth. That could be a hardware and/or driver limitation. By example, an AC97-compliant chipset may provide a fixed rate of 48000 samples/second -- any sample rate conversion must be done by other means, if possible at all. -- Gabriel Genellina From prologic at shortcircuit.net.au Thu Jan 22 18:11:33 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 09:11:33 +1000 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) In-Reply-To: <49784D83.9040207@gmail.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <49784D83.9040207@gmail.com> Message-ID: On Thu, Jan 22, 2009 at 8:42 PM, Ricardo Ar?oz wrote: (...) > What I've seen engineers do when they need extra safety is to put in place > independently developed and operated redundant systems, at least three, and > the system will do whatever two of the independent systems agree on. So I > guess if I really wanted to be safe with a system I'd have it made by at > least three different teams (yes, also the requirements should be written by > different teams) in different languages under different OS's and different > independent machines. And THEN I would have some measure of safety (and this > would certainly be more cost effective than the formal specification route). This is quite honestly the best thing I've seen written on this very topic of safety and mission critical systems! Thank you! My entire point(s) throughout this very long and tediously boring thread have been that one language over another doesn't necessarily bear much weight on the safety requirements of a system. One thing that those that have argued for Data Protection, Static Typing, Strong Typing and Stricter Encapsulation (all of which Python -IS NOT- and -WILL NOT- be); is that Safety Requirements are normally intangible, unquantifable measures. How do you rate the safety of your system ? By the number of deaths and injuries it not cause ? By the fact that your Shuttle doesn't blow up ? Your plane landing correctly ? Ricardo's point is very well put and Safety Critical systems that specify requirements, tangible and quantifiable requirements are what makes a system safe and gives assurance - not the language or the platform os the os or the environment. For example: FR1: When the landing gears button is pressed, the landing gears will be lowered and monitored and confirms by the Confirmation System and Verified by the Verification System. Have a pleasant day, cheers James From kw at codebykevin.com Thu Jan 22 18:19:52 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 22 Jan 2009 18:19:52 -0500 Subject: Find all available Tkinter cursor names? In-Reply-To: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> Message-ID: <4978FF18.7020508@codebykevin.com> r wrote: > Anybody know how to find all the available Tkinter cursor icon names, > or where the icons are stored? like "paintbrush" "pencil" etc... http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm -- Kevin Walzer Code by Kevin http://www.codebykevin.com From bj_666 at gmx.net Thu Jan 22 18:49:13 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 22 Jan 2009 23:49:13 GMT Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> Message-ID: <6tsevoFc2b1lU1@mid.uni-berlin.de> On Thu, 22 Jan 2009 04:17:57 -0800, bearophileHUGS wrote: > Ben Finney: > >> Many of us solve this by using a single full-featured programmer's >> editor that allows invoking a program +IBQ- written in any of *dozens >> or hundreds* of different languages +IBQ- from within the editor. > > I don't know what an IBQ is. +IBQ- seems to be the way your newsreader displays the dashes that where in Ben's posting. I see "em dash" characters there: In [84]: unicodedata.name(u'?') Out[84]: 'EM DASH' Ciao, Marc 'BlackJack' Rintsch From rt8396 at gmail.com Thu Jan 22 18:53:47 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 15:53:47 -0800 (PST) Subject: Find all available Tkinter cursor names? References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> Message-ID: Thanks Kevin, These are exactly the ones i already knew about. I was hoping there where more, shucks!. I wonder how i could go about making my own cursors and adding them to Tkinter? Have any ideas? From rhodri at wildebst.demon.co.uk Thu Jan 22 19:17:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 23 Jan 2009 00:17:18 -0000 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: On Thu, 22 Jan 2009 22:04:15 -0000, Tobiah wrote: > Although it's trivial to program, I wondered whether > there was a builtin or particularly concise way to > express this idea: > >> a = [(1, 2), (3, 4), (5, 6)] >> field[a, 2] > [2, 4, 6] > > where field() is some made up function. If field() already exists, there's always a list comprehension: [field(l) for l in a] If you want that specific list: >>> [l[1] for l in a] [2, 4, 6] -- Rhodri James *-* Wildebeeste Herder to the Masses From cburns4563 at gmail.com Thu Jan 22 19:45:19 2009 From: cburns4563 at gmail.com (cburns) Date: Thu, 22 Jan 2009 16:45:19 -0800 (PST) Subject: does exec ignore the locals parameter? Message-ID: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> In the code below, bar() seems to work, foo() seems broken. % python -V Python 2.6.1 % cat exec1.py def foo(i) : exec "i = i + 1" in locals(), globals() print "i=%d" % i def bar(j) : exec "j = j + 1" print "j=%d" % j foo(0) bar(0) % python exec1.py i=0 j=1 What I really wanted to do was something like: exec text in globals(), inspect.currentframe(1).f_locals but that didn't work either. Thanks, Charlie From http Thu Jan 22 20:05:12 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:05:12 -0800 Subject: Formal specification and proof (was : Does Python really follow its philosophy of "Readability counts"?) References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <49784D83.9040207@gmail.com> Message-ID: <7xtz7qvnlj.fsf@ruckus.brouhaha.com> James Mills writes: > Ricardo's point is very well put and Safety Critical systems > that specify requirements, tangible and quantifiable requirements > are what makes a system safe and gives assurance - not the language > or the platform os the os or the environment. But it is characteristics of the language, platform os, and environment, that make it easier or more difficult to provide high assurance that the specifications are actually met. See this article for the meaning of "high assurance": http://www.dwheeler.com/essays/high-assurance-floss.html Basically, high assurance in the view of the folks who issue specifications for it and fund it, requires a lot of static verification. From http Thu Jan 22 20:26:18 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:26:18 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: <7x3afabyo5.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > Having once been a more type-A, I labored for a couple of years trying > to build a restricted language that provably terminated for work on an > object-oriented database research. I finally gave it up as a bad idea, > because, in practice, we don't care if a loop will terminate or not in > database work; a transaction that takes a year to commit is equivalent > to an infinite loop for all applications that I have interacted with > (and yes, I have worked allowing four day transactions to commit). I think the purpose of the termination proofs is to ensure that nonterminating functions don't introduce inconsistency into the verification logic, rather than out of concern that some function might actually loop. Consider the function def f(x): return 1 + f(x) aside from the "minor" issue of infinite recursion, this is a nice, well-typed function that doesn't have any side effects, doesn't raise exceptions, etc. It is referentially transparent, so one can substitute any call to it with the value from another call to the same arg, i.e. we can substitute x=3 and deduce the equation f(3) = 1 + f(3) Subtracting f(3) from each side, we get 0 = 1, an erroneous "theorem" from which the verification system can infer all kinds of other bogus results. By requiring proof that any function purporting to return a value really DOES return a value (rather than looping, raising an exception, etc.), we get rid of this problem. The actual number of computing steps before termination isn't an issue for this purpose, as long as it is finite. From rasky at develer.com Thu Jan 22 20:41:38 2009 From: rasky at develer.com (Giovanni Bajo) Date: Fri, 23 Jan 2009 01:41:38 GMT Subject: Counter Class -- Bag/Multiset References: Message-ID: On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. > > I've adapted it for Python2.5/2.6 so people can start using it right > away: > http://docs.python.org/dev/library/collections.html#counter-objects > > Here's a link to the docs for the new class: > http://code.activestate.com/recipes/576611/ Hi Raymond, * I'm not a native speaker, but why use the word "Counter"? A "counter" to my ear sounds like a number that is increased each time an event occurs; the website counter, eg, comes to mind. I can understanda its meaning probably stretches to "an object that counts", but I really can't think of it as a group of object, or a container of object. Moreover, I find it a much more useful abstraction the idea of a "multi-set" (that is, a set where elements can appear with multiple cardinality), rather than stressing the concept of "counting" how many times each element appears in the set. * I find it *very* confusing c.items() vs c.elements(). Items and elements are synonymous (again, in my understanding of English). All in all, I think I prefer your previous bag class: http://code.activestate.com/recipes/259174/ -- Giovanni Bajo Develer S.r.l. http://www.develer.com From clp2 at rebertia.com Thu Jan 22 20:49:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 17:49:42 -0800 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: Message-ID: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: > On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: > >> The collections module in Python 2.7 and Python 3.1 has gotten a new >> Counter class that works like bags and multisets in other languages. >> >> I've adapted it for Python2.5/2.6 so people can start using it right >> away: >> http://docs.python.org/dev/library/collections.html#counter-objects >> >> Here's a link to the docs for the new class: >> http://code.activestate.com/recipes/576611/ > > Hi Raymond, > > * I'm not a native speaker, but why use the word "Counter"? A "counter" > to my ear sounds like a number that is increased each time an event > occurs; the website counter, eg, comes to mind. I can understanda its > meaning probably stretches to "an object that counts", but I really can't > think of it as a group of object, or a container of object. Moreover, I > find it a much more useful abstraction the idea of a "multi-set" (that > is, a set where elements can appear with multiple cardinality), rather > than stressing the concept of "counting" how many times each element > appears in the set. > > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). I concur and would like to say additionally that having Counter's len() be the number of *unique* items as opposed to just the number of items seems a bit counterintuitive. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From astan.chee at al.com.au Thu Jan 22 20:50:19 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 12:50:19 +1100 Subject: USB in python In-Reply-To: <6tqvb2Fcan25U1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: <4979225B.6050106@al.com.au> Diez B. Roggisch wrote: > Astan Chee wrote: > > >> Hi, >> Im trying to write a program for my USB device and I'm thinking of using >> python to do this. The USB device is of my own making and it is >> activated when one of the two data pins of the USB is given about 5V (or >> similar to whatever the power pin is getting). Now I'm confused to if >> the software to activate this can actually be written and how do I do >> it? Any examples? I've seen pyUSB but it doesn't give me control over >> the hardware and how much power is going through the data pins. >> > Unless I'm not getting something here. > > > Hi, Thanks for all the responses but I forgot to mention that I have very little hardware understanding (at least in english) and the device itself it very simple and only needs about 5V power to be active. The problem here is that I want to control when the device is active using a computer so I thought USB might be a good choice since its simple (but didn't turn out to be). I'm open to any other suggestions on how I might achieve this hardware and software-wise (as in what interface should I use, etc). Also I'm trying to stay away from (complex) micro controllers. Any ideas? Thanks again Astan From http Thu Jan 22 20:54:57 2009 From: http (Paul Rubin) Date: 22 Jan 2009 17:54:57 -0800 Subject: Counter Class -- Bag/Multiset References: Message-ID: <7xiqo64wi6.fsf@ruckus.brouhaha.com> Giovanni Bajo writes: > * I'm not a native speaker, but why use the word "Counter"? I agree with this, the new functionality is welcome but I think the traditional term "multiset" or "bag" would have been better. From bearophileHUGS at lycos.com Thu Jan 22 21:04:38 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 22 Jan 2009 18:04:38 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch: > +IBQ- seems to be the way your newsreader displays the dashes that where > in Ben's posting. ?I see "em dash" characters there: I see, thank you. I never finish to see all the weird things of the Web (through google groups). Bye, bearophile From benjamin.kaplan at case.edu Thu Jan 22 21:20:33 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 22 Jan 2009 21:20:33 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: Message-ID: > Hi Raymond, > > * I'm not a native speaker, but why use the word "Counter"? A "counter" > to my ear sounds like a number that is increased each time an event > occurs; the website counter, eg, comes to mind. I can understanda its > meaning probably stretches to "an object that counts", but I really can't > think of it as a group of object, or a container of object. Moreover, I > find it a much more useful abstraction the idea of a "multi-set" (that > is, a set where elements can appear with multiple cardinality), rather > than stressing the concept of "counting" how many times each element > appears in the set. > > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). > > All in all, I think I prefer your previous bag class: > http://code.activestate.com/recipes/259174/ Well, I am a native English speaker and I agree with your points completely. Also, wouldn't it be better to either have a least_common method or allow most_common to take a negative integer rather than having to use most_common()[:-n:-1]? For a large Counter, this could take up a lot of memory. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Jan 22 21:30:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 02:30:06 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <01892202$0$20671$c3e8da3@news.astraweb.com> On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > Steven D'Aprano writes: > >> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >>> Steven D'Aprano a ?crit : >>>> But if you have free access to attributes, then *everything* is >>>> interface. >>> >>> Nope. >> >> How could anyone fail to be convinced by an argument that detailed and >> carefully reasoned? > > Well, your claim /was/ just wrong. But if you want to play dumb: the > interface is what's documented as being the interface. But you miss my point. We're told Python doesn't have private attributes. We're told that we're allowed to "mess with the internals", we're *encouraged* to do so: Python gives you the freedom to do so, and any suggestion that freedom might be reduced even a tiny bit is fought passionately. When people ask how to implement private attributes, they're often told not to bother even using single-underscore names. When it is suggested that Python should become stricter, with enforced data hiding, the objections come thick and fast: people vehemently say that they like Python just the way it is, that they want the ability to mess with the internals. You even argued that you disliked data structures implemented in C and preferred those written in Python because you have more ability to mess with the private attributes. In context, I had just mentioned that lists' internals were inaccessible from Python code. I neglected to give an example at the time, but a good example is the current length of the list. Consider the experience of Microsoft and Apple. No matter how often they tell people not to mess with the internals, people do it anyway, and always believe that their reason is a good reason. And Python culture encourages that behaviour (albeit the consequences are milder: no buffer overflows or core dumps). Add to that the culture of Open Source that encourages reading the source code. You don't need to buy a book called "Undocumented Tips and Tricks for Python" to discover the internals. You just need to read the source code. And then you have at least two places in the standard library where _attributes are *explicitly* public: http://bugs.python.org/issue3152 Given this permissive culture, any responsible library writer must assume that if he changes his so-called "private" attributes, he will break other people's code. In principle it could break just as much code as if he didn't even bother flagging them with a leading underscore, which is probably why many people don't even bother with _names. In other words, if you make it easy for people to mess with your internals, if you have a culture that allows and even encourages them to mess with your internals, then you don't have internals. Everything is de facto public. > You can tell that your claim is simply wrong by pushing it the other > way. If everything you have free access to is interface then all > behaviour observable by messing with the things you have access to is > fair game: you can rely on cmp returning one of {-1, 0, 1} on integer > arguments, for example. > > But no: the Library Reference says only that it returns a negative, zero > or positive integer, and /that/ defines the interface. Everything else > is idiosyncrasy of the implementation, allowed to change at whim. And yet people still assume that cmp returns -1, 0 or 1. Even Guido himself makes that mistake occasionally. Quoting from PEP 285: "...you might be tempted to believe that cmp() also returned a truth value, whereas in reality it can return three different values (-1, 0, 1)." http://www.python.org/dev/peps/pep-0285/ No, cmp() can return an infinite number of values. It just never does, at least not yet, but it might. But when Guido himself says that cmp() can return three values, can you blame people for acting as if cmp() can return three values? Here's a thought experiment for you. You've suggested that the values returned by cmp() are allowed to change "at whim". Okay, let's do it: make a patch that changes cmp() to return -17, 0 or 53, and promise to support it for at least three years. Try to get it accepted on python- dev. What do you expect they will say? My money is on them saying "No, this will pointlessly break code for no good reason. Rejected." -- Steven From notvalid2 at sbcglobal.net Thu Jan 22 21:38:32 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 22 Jan 2009 18:38:32 -0800 Subject: What is intvar? Message-ID: I'm looking at someone's code in which invar() is used fairly often. Apparently, it's a Tkinter method. Here's a use: def body(self,master): self.title("Display Settings") self.colorVar = IntVar() Radiobutton( master, text="Gray Scale", value=1, variable=self.colorVar).grid(row=0, sticky=W) Radiobutton( master, text="Pseudo Color", value=2, variable=self.colorVar).grid(row=1, sticky=W) ... What is the need for this use? It looks like some sort of initialization for a widget. I've scoured the internet with Google, and have yet to find a simple explanation of what it's used for. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gregturn at mindspring.com Thu Jan 22 21:39:08 2009 From: gregturn at mindspring.com (Goldfish) Date: Thu, 22 Jan 2009 18:39:08 -0800 (PST) Subject: Spring Python 1.0.0 (RC1) is released Message-ID: <847da5ae-412a-47f9-b002-4755f0ec028e@z6g2000pre.googlegroups.com> Spring Python takes the concepts implemented by the Java-based Spring Framework, and applies them to Python. This provides a powerful library of functionality to help you get back to writing the code that makes you money. It includes features like data access, transaction management, remoting, security, a command-line tool, and an IoC container. Today, release 1.0.0 (RC1) has been released. See http://blog.springpython.webfactional.com/index.php/2009/01/22/spring-python-1-0-0-is-finally-here for details about this release, including release notes, links, and other information. This is the production-ready release, with now stable APIs. From tjreedy at udel.edu Thu Jan 22 21:42:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 21:42:11 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> References: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: >> On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: >> >>> The collections module in Python 2.7 and Python 3.1 has gotten a new >>> Counter class that works like bags and multisets in other languages. >>> >>> I've adapted it for Python2.5/2.6 so people can start using it right >>> away: >>> http://docs.python.org/dev/library/collections.html#counter-objects >>> >>> Here's a link to the docs for the new class: >>> http://code.activestate.com/recipes/576611/ >> Hi Raymond, >> >> * I'm not a native speaker, but why use the word "Counter"? A "counter" >> to my ear sounds like a number that is increased each time an event >> occurs; the website counter, eg, comes to mind. I can understanda its >> meaning probably stretches to "an object that counts", Yes, little clicker devices for instances. >> but I really can't >> think of it as a group of object, or a container of object. Me neither. >> Moreover, I >> find it a much more useful abstraction the idea of a "multi-set" (that >> is, a set where elements can appear with multiple cardinality), rather >> than stressing the concept of "counting" how many times each element >> appears in the set. >> >> * I find it *very* confusing c.items() vs c.elements(). Items and >> elements are synonymous (again, in my understanding of English). > > I concur and would like to say additionally that having Counter's > len() be the number of *unique* items as opposed to just the number of > items seems a bit counterintuitive. bag/multiset/counter has been implemented as dict with items as keys and counts as values, and len(dict) = #keys, so unique items is what I expect. Giving the bag a sum-of-counts attributes also might be nice, though. From clp2 at rebertia.com Thu Jan 22 21:45:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 18:45:26 -0800 Subject: What is intvar? In-Reply-To: References: Message-ID: <50697b2c0901221845y9b4cc4bwcae2234fd64fe258@mail.gmail.com> On Thu, Jan 22, 2009 at 6:38 PM, W. eWatson wrote: > I'm looking at someone's code in which invar() is used fairly often. > Apparently, it's a Tkinter method. Here's a use: > def body(self,master): > self.title("Display Settings") > > self.colorVar = IntVar() > Radiobutton( master, text="Gray Scale", > value=1, variable=self.colorVar).grid(row=0, sticky=W) > Radiobutton( master, text="Pseudo Color", > value=2, variable=self.colorVar).grid(row=1, sticky=W) > ... > > What is the need for this use? It looks like some sort of initialization for > a widget. > > I've scoured the internet with Google, and have yet to find a simple > explanation of what it's used for. Search for IntVar on http://docs.python.org/library/tkinter.html and read the enclosing section. I think it's basically used to propagate changes to the GUI and convert values (in this case, ints) between Python and Tk. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 22 21:48:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jan 2009 21:48:52 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01892202$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > Here's a thought experiment for you. You've suggested that the values > returned by cmp() are allowed to change "at whim". Okay, let's do it: > make a patch that changes cmp() to return -17, 0 or 53, and promise to > support it for at least three years. Try to get it accepted on python- > dev. What do you expect they will say? > > My money is on them saying "No, this will pointlessly break code for no > good reason. Rejected." I have occasionally thought that things documented to possibly change *should* be changed just to expose the *bug* of depending on them not changing. Or maybe, the doc should be changed. From dsdale24 at gmail.com Thu Jan 22 21:56:18 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Thu, 22 Jan 2009 18:56:18 -0800 (PST) Subject: what gives with "'import *' not allowed with 'from .'"? Message-ID: I know the use of "from foo import *" is discouraged, but I'm writing a package that I hope others may want to integrate as a subpackage of their own projects, I know what I'm doing, and I want to use the "from .bar import *" syntax internally. It works fine with python-2.6, but with python-2.5 I get a SyntaxError: "'import *' not allowed with 'from .'" Judging from http://bugs.python.org/issue2400 , this issue was fixed back in May 2008, but it is still present with python-2.5.4, which was released in December. Why wont python-2.5 allow this kind of import? From musiccomposition at gmail.com Thu Jan 22 21:58:31 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 22 Jan 2009 18:58:31 -0800 (PST) Subject: does exec ignore the locals parameter? References: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> Message-ID: On Jan 22, 6:45?pm, cburns wrote: > In the code below, bar() seems to work, foo() seems broken. > > % python -V > Python 2.6.1 > > % cat exec1.py > > def foo(i) : > ? ? ? ? exec "i = i + 1" in locals(), globals() > ? ? ? ? print "i=%d" % i > > def bar(j) : > ? ? ? ? exec "j = j + 1" > ? ? ? ? print "j=%d" % j > > foo(0) > bar(0) > > % python exec1.py > i=0 > j=1 > > What I really wanted to do was something like: > > ? ? ? ? exec text in globals(), inspect.currentframe(1).f_locals but > that didn't work either. Trying to modify locals() in a function is undefined behavior. > > Thanks, > > Charlie From rhodri at wildebst.demon.co.uk Thu Jan 22 22:00:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 23 Jan 2009 03:00:45 -0000 Subject: What is intvar? In-Reply-To: References: Message-ID: On Fri, 23 Jan 2009 02:38:32 -0000, W. eWatson wrote: > I'm looking at someone's code in which invar() is used fairly often. > Apparently, it's a Tkinter method. Here's a use: > def body(self,master): > self.title("Display Settings") > > self.colorVar = IntVar() > Radiobutton( master, text="Gray Scale", > value=1, variable=self.colorVar).grid(row=0, > sticky=W) > Radiobutton( master, text="Pseudo Color", > value=2, variable=self.colorVar).grid(row=1, > sticky=W) > ... > > What is the need for this use? It looks like some sort of initialization > for a widget. Chris has already pointed you to the Tkinter documentation, which is a good start but a little less than clear in places. What your example code does is to associate self.colorVar with the set of radio buttons. This isn't just initialisation, it's a full reflection of the current state. self.colorVar.get() returns the "value" parameter that you gave to the radio button which is currently selected (so, for example, if it returns 1 you know that the "Grey Scale" button is the one selected). Similarly self.colorVar.set(n) selects whichever radio button has the "value" which matches n (so self.colorVar.set(2) selects the "Pseudo Color" button). IntVar and StringVar (and DoubleVar if you must :-) are basically the easy way of dynamically reading and changing the values in various entry widgets, the text on buttons, and so on. -- Rhodri James *-* Wildebeeste Herder to the Masses From musiccomposition at gmail.com Thu Jan 22 22:02:36 2009 From: musiccomposition at gmail.com (Benjamin) Date: Thu, 22 Jan 2009 19:02:36 -0800 (PST) Subject: Dictionary : items() References: <7x8wp3wwlk.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 2:53?am, Paul Rubin wrote: > Steven D'Aprano writes: > > That is better written as: > > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) > > In Python 2.x, I prefer the style > > ? l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) > > but Python 3.0 breaks the tuple unpacking per some PEP. PEP 3113 if you really care. From steve at holdenweb.com Thu Jan 22 22:06:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 22 Jan 2009 22:06:17 -0500 Subject: pep 8 constants In-Reply-To: <4978DD2E.1090008@aim.com> References: <4978DD2E.1090008@aim.com> Message-ID: Brian Allen Vanderburg II wrote: > bockman at virgilio.it wrote: >> Constants would be a nice addition in python, sure enough. >> But I'm not sure that this can be done without a run-time check every >> time >> the constant is used, and python is already slow enough. Maybe a check >> that is disabled when running with optimizing flags ? >> >> But I'm sure this discussion has been already made and the FINAL WORD has >> been already spoken. >> >> Ciao >> ---- >> FB >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > One idea to make constants possible would be to extend properties to be > able to exist at the module level as well as the class level: > > @property > def pi(): > return 3.14159..... > > print(pi) # prints 3.14159.... > pi=32 # Raise an error Cannot set attribute ... > I don't understand why this would print 3.14159 ... instead of , or whatever. property would clearly have to do something very different in module scope in order to make this work. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin at python.org Thu Jan 22 22:07:36 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 03:07:36 +0000 (UTC) Subject: what gives with References: Message-ID: Darren Dale gmail.com> writes: > Judging from http://bugs.python.org/issue2400 , this issue > was fixed back in May 2008, but it is still present with python-2.5.4, > which was released in December. Why wont python-2.5 allow this kind of > import? Allowing that would be a new feature which is disallowed in bug fix releases like 2.5.4. From benjamin at python.org Thu Jan 22 22:11:26 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 03:11:26 +0000 (UTC) Subject: pep 8 constants References: Message-ID: Benjamin Kaplan case.edu> writes: > > > On Thu, Jan 22, 2009 at 1:16 AM, Aahz pythoncraft.com> wrote:In article python.org>, > Brendan Miller catphive.net> wrote:>>PEP 8 doesn't mention anything about using all caps to indicate a constant.Now it does! ?Seehttp://www.python.org/dev/peps/pep-0008/Thanks for bringing this up! > ? > Since the constants in the std lib (like?math.pi and math.e)?no longer follow PEP 8, should we expect them to change at some point in the future? No, I don't think so. These are already well known as constants. Besides it would break backward compatibility for little gain. From aahz at pythoncraft.com Thu Jan 22 22:11:53 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:11:53 -0800 Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <7xy6x9nzwd.fsf@ruckus.brouhaha.com> Message-ID: In article <7xy6x9nzwd.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Chris Rebert writes: >>attribution deleted by Paul Rubin: >>> >>> class Calculator(): ... >> >> Delete the 3 Java-ish accessor methods; good Python style just uses >> the attributes directly (i.e. self.operator instead of >> self.getOperator()). > >I think I would get rid of the whole Calculator class unless there >was a good reason to keep it (i.e. you are going to have several >Calculators active in the program simultaneously). Just write >straightforward imperative code without bothering with the OO stuff >that is mandatory in Java. IMO "good reason" is simply that using a class makes keeping track of namespaces easier, e.g. if you add a memory capability. I think that if there's clearly an object that you will be manipulating, a class is usually the right approach even if it doesn't look like it's needed. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From vedagaurav at gmail.com Thu Jan 22 22:14:19 2009 From: vedagaurav at gmail.com (Gaurav Veda) Date: Thu, 22 Jan 2009 19:14:19 -0800 (PST) Subject: Python 2.4 vs 2.5 - Unicode error References: <336d8c64-a5c9-44db-a8ae-ade089228c23@h16g2000yqj.googlegroups.com> <047e41bb-c24b-4f6d-a1a1-d48259971d85@p23g2000prp.googlegroups.com> <2c8eee58-b954-4b1a-94fd-8abe169469ab@m16g2000vbp.googlegroups.com> <61718f7e-327b-4851-95b5-83c0951a00a6@a39g2000prl.googlegroups.com> Message-ID: <4fde3122-9554-4cfb-86a1-dd3dccec42ea@r38g2000vbi.googlegroups.com> On Jan 21, 7:08 pm, John Machin wrote: > > To replace non-ASCII characters in a UTF-8-encoded string by spaces: > | >>> u8 = ' and 25\xc2\xb0F' > | >>> u = u8.decode('utf8') > | >>> ''.join([chr(ord(c)) if c <= u'\x7f' else ' ' for c in u]) > | ' and 25 F' Thanks John for your reply. This is what I needed. Cheers, Gaurav From atleta.hu at gmail.com Thu Jan 22 22:19:26 2009 From: atleta.hu at gmail.com (atleta) Date: Thu, 22 Jan 2009 19:19:26 -0800 (PST) Subject: Adding a field to a 'foreign' object from the outside Message-ID: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Hi, I'm working with a callback API (a DBus one) and I'd need to store some state between the calls somewhere. I know that it's possible to extend an object with fields after creation, so I could just store my data in the session object that is passed in with every callback. However it stinks from OO perspective, at least to me. The other option, something that I'd do in java for example, would be to set up a mapping (a dict) using the session object as a key. Which one is the 'pythonic' way? Do you use the first method (modifying an object that you don't even control the source of) or do you write a bit more code and go with the second one? Thanks, Laszlo From rt8396 at gmail.com Thu Jan 22 22:19:50 2009 From: rt8396 at gmail.com (r) Date: Thu, 22 Jan 2009 19:19:50 -0800 (PST) Subject: What is intvar? References: Message-ID: here is a good explanation of control vars: http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html Here are 3 great Tkinter refernces in order: http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://effbot.org/tkinterbook/ http://www.pythonware.com/library/tkinter/introduction/ From aahz at pythoncraft.com Thu Jan 22 22:22:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:22:08 -0800 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article <87hc3un1vn.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > > * Python augmented-assignment (`+=', for example) is inconsistent. > Depending on what type of object the left-hand side evaluates to, it > may /either/ mutate that object, /or/ assign a new value to the > expression. Actually, that is not correct. The augmented assignment always binds a new value to the name; the gotcha is that with a mutable object, the object returns ``self`` from the augmented assignment method rather than creating a new object and returning that. IOW, the smarts are always with the object, not with the augmented assignment bytecode. The best way to illustrate this: >>> a = (1, ['foo'], 'xyzzy') >>> a[1].append('bar') >>> a (1, ['foo', 'bar'], 'xyzzy') >>> a[1] = 9 Traceback (most recent call last): File "", line 1, in ? TypeError: object doesn't support item assignment >>> a (1, ['foo', 'bar'], 'xyzzy') >>> a[1] += ['spam'] Traceback (most recent call last): File "", line 1, in ? TypeError: object doesn't support item assignment >>> a (1, ['foo', 'bar', 'spam'], 'xyzzy') -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Thu Jan 22 22:23:57 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jan 2009 19:23:57 -0800 Subject: Python Style Guide Questions - Contd. References: <6tk9qqFbav8gU1@mid.uni-berlin.de> Message-ID: In article <6tk9qqFbav8gU1 at mid.uni-berlin.de>, Marc 'BlackJack' Rintsch wrote: > >PEP8 doesn't mention constants at all. Not true anymore. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From grante at visi.com Thu Jan 22 22:26:01 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 22 Jan 2009 21:26:01 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: On 2009-01-23, Astan Chee wrote: > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using a > computer so I thought USB might be a good choice since its simple (but > didn't turn out to be). USB is definitely not simple. USB is exremely complicated (and rather badly designed, IMO). > I'm open to any other suggestions on how I might achieve this > hardware and software-wise (as in what interface should I > use, etc). Also I'm trying to stay away from (complex) micro > controllers. Any ideas? Thanks again Astan Standard IBM PC parallel printer ports offer a bunch of 5V I/O lines that are fairly simple to control in software. -- From prologic at shortcircuit.net.au Thu Jan 22 22:27:30 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 13:27:30 +1000 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 1:19 PM, atleta wrote: > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? The more elegant approach is your 2nd one. A wrapper object that hold the extra data and functionality you require while maintaining the APIs needs. Tacking things on is a bit hackish :) (but nonetheless probably works). --JamesMills From nad at acm.org Thu Jan 22 22:59:39 2009 From: nad at acm.org (Ned Deily) Date: Thu, 22 Jan 2009 19:59:39 -0800 Subject: does exec ignore the locals parameter? References: <99e36cb9-6a21-4ebf-a957-9484ff1675fa@z28g2000prd.googlegroups.com> Message-ID: In article , Benjamin wrote: > On Jan 22, 6:45?pm, cburns wrote: > > In the code below, bar() seems to work, foo() seems broken. > > > > % python -V > > Python 2.6.1 > > > > % cat exec1.py > > > > def foo(i) : > > ? ? ? ? exec "i = i + 1" in locals(), globals() > > ? ? ? ? print "i=%d" % i > > > > def bar(j) : > > ? ? ? ? exec "j = j + 1" > > ? ? ? ? print "j=%d" % j > > > > foo(0) > > bar(0) > Trying to modify locals() in a function is undefined behavior. BTW, the order of the parameters to exec are reversed; presumably what was intended is: exec "i = i + 1" in globals(), locals() That doesn't change the results in question, though, as is, after the call to foo(0), i (=1) exists as a global. -- Ned Deily, nad at acm.org From pavlovevidence at gmail.com Thu Jan 22 23:38:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 20:38:21 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > In article <7xd4ele060.... at ruckus.brouhaha.com>, > Paul Rubin ? wrote: > > >alex23 writes: > > >> Here's an article by Guido talking about the last attempt to remove > >> the GIL and the performance issues that arose: > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > >> a single-threaded program (and for a multi-threaded but I/O-bound > >> program) *does not decrease*." > > >The performance decrease is an artifact of CPython's rather primitive > >storage management (reference counts in every object). ?This is > >pervasive and can't really be removed. ?But a new implementation > >(e.g. PyPy) can and should have a real garbage collector that doesn't > >suffer from such effects. > > CPython's "primitive" storage management has a lot to do with the > simplicity of interfacing CPython with external libraries. ?Any solution > that proposes to get rid of the GIL needs to address that. I recently was on a long road trip, and was not driver, and with nothing better to do thought quite a bit about how this. I concluded that, aside from one major trap, it wouldn't really be more difficult to inteface Python to external libraries, just differently difficult. Here is briefly what I came up with: 1. Change the singular Python type into three metatypes: immutable_type, mutable_type, and mutable_dict_type. (In the latter case, the object itself is immutable but the dict can be modified. This, of course, would be the default metaclass in Python.) Only mutable_types would require a mutex when accessing. 2. API wouldn't have to change much. All regular API would assume that objects are unlocked (if mutable) and in a consistent state. It'll lock any mutable objects it needs to access. There would also be a low-level API that assumes the objects are locked (if mutable) and does not require objects to be consistent. I imagine most extensions would call the standard API most of the time. 3. If you are going to use the low-level API on a mutable object, or are going to access the object structure directly, you need to acquire the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() would be provided. 4. Objects would have to define a method, to be called by the GC, that marks every object it references. This would be a lot like the current tp_visit, except it has to be defined for any object that references another object, not just objects that can participate in cycles. (A conservative garbage collector wouldn't suffice for Python because Python quite often allocates blocks but sets the pointer to an offset within the block. In fact, that's true of almost any Python- defined type.) Unfortunately, references on the stack would need to be registered as well, so "PyObject* p;" might have to be replaced with something like "Py_DECLARE_REF(PyObject,p);" which magically registers it. Ugly. 5. Py_INCREF and Py_DECREF are gone. 6. GIL is gone. So, you gain the complexity of a two-level API, having to lock mutable objects sometimes, and defining more visitor methods than before, but you don't have to keep INCREFs and DECREFs straight, which is no small thing. The major trap is the possibily of deadlock. To help minimize the risk there would be macros to lock multiple objects at once. Py_LOCK2 (a,b), which guarantess that if in another thread is calling Py_LOCK2 (b,a) at the same time, it won't result in a deadlock. What's disappointing is that the deadlocking possibility is always with you, much like the reference counts are. Carl Banks From koranthala at gmail.com Thu Jan 22 23:38:34 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 22 Jan 2009 20:38:34 -0800 (PST) Subject: Logging help References: <4871c83e-5a37-43d4-b328-189f9805962d@w1g2000prk.googlegroups.com> <97768b8b-2645-4faa-a5ad-290a0f9bac58@w39g2000prb.googlegroups.com> <75e90a77-6b25-4516-b2ab-4170907deccb@w24g2000prd.googlegroups.com> Message-ID: <50b8a5b0-c4f6-45af-aa81-f7cf060b06bc@r37g2000prr.googlegroups.com> On Jan 22, 10:25?pm, Vinay Sajip wrote: > On Jan 22, 3:40 pm,koranthala wrote: > > > Thank you very much Vinay. You have been extremely helpful. > > This was my first design - but then I found that log system was taking > > up quite a huge chunk of the memory. > > That is why I went to rotating file handler. > > Using just plain FileHandler takes up less memory than using > RotatingFileHandler (because using the latter imports the "handlers" > module into memory, whereas using the former does not). I'm not aware > of any problem where logging takes up a huge chunk of memory (under > normal usage) - how did you measure the memory usage which was due to > logging? > > > Anyways, now I have modified doRollover to append if file is there, > > so, for me it is working. > > What I was thinking was such an option in the basicloggingsystem > > might be of good help. > > The solution I suggested is IMO better than using a patched > RotatiingFileHandler, both because it avoids importing an extra module > (if memory really is a concern) and because you don't need to change > your code across Python version updates. How does my suggestion to use > FileHandler not meet your use case? > > > Again, Vinay, Thank you very much. You were extremely helpful. > > You're welcome. > > Best wishes, > > Vinay Sajip oops - again I was very unclear in my post. What i meant was that due to the log getting very big - i.e. the log was in 100MB range (since it is a new product - a lot of debugging is done via logs). Not RAM. Having a rotating file handler helped there - because I could say only 5 such logs are needed. From Russ.Paielli at gmail.com Fri Jan 23 00:22:25 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 22 Jan 2009 21:22:25 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> On Jan 22, 6:30?pm, Steven D'Aprano wrote: > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > > Steven D'Aprano writes: > > >> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > >>> Steven D'Aprano a ?crit : > >>>> But if you have free access to attributes, then *everything* is > >>>> interface. > > >>> Nope. > > >> How could anyone fail to be convinced by an argument that detailed and > >> carefully reasoned? > > > Well, your claim /was/ just wrong. ?But if you want to play dumb: the > > interface is what's documented as being the interface. > > But you miss my point. > > We're told Python doesn't have private attributes. We're told that we're > allowed to "mess with the internals", we're *encouraged* to do so: Python > gives you the freedom to do so, and any suggestion that freedom might be > reduced even a tiny bit is fought passionately. When people ask how to > implement private attributes, they're often told not to bother even using > single-underscore names. When it is suggested that Python should become > stricter, with enforced data hiding, the objections come thick and fast: > people vehemently say that they like Python just the way it is, that they > want the ability to mess with the internals. > > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to mess > with the private attributes. In context, I had just mentioned that lists' > internals were inaccessible from Python code. I neglected to give an > example at the time, but a good example is the current length of the > list. Consider the experience of Microsoft and Apple. No matter how often > they tell people not to mess with the internals, people do it anyway, and > always believe that their reason is a good reason. > > And Python culture encourages that behaviour (albeit the consequences are > milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. > > And then you have at least two places in the standard library where > _attributes are *explicitly* public: > > http://bugs.python.org/issue3152 > > Given this permissive culture, any responsible library writer must assume > that if he changes his so-called "private" attributes, he will break > other people's code. In principle it could break just as much code as if > he didn't even bother flagging them with a leading underscore, which is > probably why many people don't even bother with _names. > > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them to > mess with your internals, then you don't have internals. Everything is de > facto public. > > > You can tell that your claim is simply wrong by pushing it the other > > way. ?If everything you have free access to is interface then all > > behaviour observable by messing with the things you have access to is > > fair game: you can rely on cmp returning one of {-1, 0, 1} on integer > > arguments, for example. > > > But no: the Library Reference says only that it returns a negative, zero > > or positive integer, and /that/ defines the interface. ?Everything else > > is idiosyncrasy of the implementation, allowed to change at whim. > > And yet people still assume that cmp returns -1, 0 or 1. Even Guido > himself makes that mistake occasionally. Quoting from PEP 285: > > "...you might be tempted to believe that cmp() also returned a > truth value, whereas in reality it can return three different values > (-1, 0, 1)." > > http://www.python.org/dev/peps/pep-0285/ > > No, cmp() can return an infinite number of values. It just never does, at > least not yet, but it might. But when Guido himself says that cmp() can > return three values, can you blame people for acting as if cmp() can > return three values? > > Here's a thought experiment for you. You've suggested that the values > returned by cmp() are allowed to change "at whim". Okay, let's do it: > make a patch that changes cmp() to return -17, 0 or 53, and promise to > support it for at least three years. Try to get it accepted on python- > dev. What do you expect they will say? > > My money is on them saying "No, this will pointlessly break code for no > good reason. Rejected." > > -- > Steven Needless to say, I agree with your post. My understanding is that the vast majority of Python software is provided as open source. Hence, I am a bit confused by all the talk about the need for freedom and openness in Python. If data hiding were enforced, and you need access to something marked as private, you can just change it to public in the source code. What's the problem? Note: that change would be much easier to make if a "private" (or perhaps "priv") keyword were used instead of the leading-underscore rule. The former would require a change in only one place (per attribute), whereas the latter would require a change of every occurrence of the attribute. So "enforced" access restrictions are trivial to work around with open source. But doesn't that mean that access restriction is pointless because it cannot be enforced anyway? Of course not. In a team project, the access restrictions will be enforced on the checked-in code. You can play around with the internals all you want in your own little world, but as when you are working with a team, you need to adhere to the interfaces they define (if any). From rhamph at gmail.com Fri Jan 23 00:26:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 22 Jan 2009 21:26:24 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <9ed75409-9e7b-40ce-b195-f581cb860ee1@13g2000yql.googlegroups.com> On Jan 22, 7:48?pm, Terry Reedy wrote: > Steven D'Aprano wrote: > > > Here's a thought experiment for you. You've suggested that the values > > returned by cmp() are allowed to change "at whim". Okay, let's do it: > > make a patch that changes cmp() to return -17, 0 or 53, and promise to > > support it for at least three years. Try to get it accepted on python- > > dev. What do you expect they will say? > > > My money is on them saying "No, this will pointlessly break code for no > > good reason. Rejected." > > I have occasionally thought that things documented to possibly change > *should* be changed just to expose the *bug* of depending on them not > changing. ?Or maybe, the doc should be changed. Aye. There are places where we're deliberately open, but this isn't one of them. I think this is just a C-ism and the docs should be more specific. Or finish ripping it out in 3.x ;) From http Fri Jan 23 00:31:11 2009 From: http (Paul Rubin) Date: 22 Jan 2009 21:31:11 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xr62ufv1c.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > CPython's "primitive" storage management has a lot to do with the > simplicity of interfacing CPython with external libraries. Any solution > that proposes to get rid of the GIL needs to address that. This, I don't understand. Other languages like Lisp and Java and Haskell have foreign function interfaces that easier to program than Python's, -and- they don't use reference counts. There's usually some primitive to protect objects from garbage collection while the foreign function is using them, etc. The Java Native Interface (JNI) and the Haskell FFI are pretty well documented. The Emacs Lisp system is not too hard to figure out from examining the source code, etc. From Russ.Paielli at gmail.com Fri Jan 23 00:31:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Thu, 22 Jan 2009 21:31:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <49770f51$0$743$426a74cc@news.free.fr> Message-ID: <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> On Jan 21, 4:04?am, Bruno Desthuilliers wrote: > Russ P. a ?crit : > (snip) > > > Your mistake for being a moron. But it seems to happen regularly, > > doesn't it. How much more of my time are you going to waste, loser? > > Calling people names is certainly not the best way to defend your > opinions here. Adios, Mr. P. You are absolutely right, Mr. D. I regret that post, and I have since apologized to the person I was addressing. This stuff really isn't important enough to get that worked up about. From rhamph at gmail.com Fri Jan 23 00:38:37 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Thu, 22 Jan 2009 21:38:37 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> On Jan 22, 9:38?pm, Carl Banks wrote: > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > Paul Rubin ? wrote: > > > >alex23 writes: > > > >> Here's an article by Guido talking about the last attempt to remove > > >> the GIL and the performance issues that arose: > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > >> program) *does not decrease*." > > > >The performance decrease is an artifact of CPython's rather primitive > > >storage management (reference counts in every object). ?This is > > >pervasive and can't really be removed. ?But a new implementation > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > >suffer from such effects. > > > CPython's "primitive" storage management has a lot to do with the > > simplicity of interfacing CPython with external libraries. ?Any solution > > that proposes to get rid of the GIL needs to address that. > > I recently was on a long road trip, and was not driver, and with > nothing better to do thought quite a bit about how this. > > I concluded that, aside from one major trap, it wouldn't really be > more difficult to inteface Python to external libraries, just > differently difficult. ?Here is briefly what I came up with: > > 1. Change the singular Python type into three metatypes: > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > case, the object itself is immutable but the dict can be modified. > This, of course, would be the default metaclass in Python.) ?Only > mutable_types would require a mutex when accessing. > > 2. API wouldn't have to change much. ?All regular API would assume > that objects are unlocked (if mutable) and in a consistent state. > It'll lock any mutable objects it needs to access. ?There would also > be a low-level API that assumes the objects are locked (if mutable) > and does not require objects to be consistent. ?I imagine most > extensions would call the standard API most of the time. > > 3. If you are going to use the low-level API on a mutable object, or > are going to access the object structure directly, you need to acquire > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > would be provided. > > 4. Objects would have to define a method, to be called by the GC, that > marks every object it references. ?This would be a lot like the > current tp_visit, except it has to be defined for any object that > references another object, not just objects that can participate in > cycles. ?(A conservative garbage collector wouldn't suffice for Python > because Python quite often allocates blocks but sets the pointer to an > offset within the block. ?In fact, that's true of almost any Python- > defined type.) ?Unfortunately, references on the stack would need to > be registered as well, so "PyObject* p;" might have to be replaced > with something like "Py_DECLARE_REF(PyObject,p);" which magically > registers it. ?Ugly. > > 5. Py_INCREF and Py_DECREF are gone. > > 6. GIL is gone. > > So, you gain the complexity of a two-level API, having to lock mutable > objects sometimes, and defining more visitor methods than before, but > you don't have to keep INCREFs and DECREFs straight, which is no small > thing. > > The major trap is the possibily of deadlock. ?To help minimize the > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > (b,a) at the same time, it won't result in a deadlock. ?What's > disappointing is that the deadlocking possibility is always with you, > much like the reference counts are. IMO, locking of the object is a secondary problem. Python-safethread provides one solution, but it's not the only conceivable one. For the sake of discussion it's easier to assume somebody else is solving it for you. Instead, focus on just the garbage collection. What are the practical issues of modifying CPython to use a tracing GC throughout? It certainly is possible to write an exact GC in C, but the stack manipulation would be hideous. It'd also require significant rewrites of the entire code base. Throw on that the performance is unclear (it could be far worse for a single-threaded program), with no straightforward way to make it a compile-time option.. Got any ideas for that? From prologic at shortcircuit.net.au Fri Jan 23 00:38:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 23 Jan 2009 15:38:49 +1000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 3:22 PM, Russ P. wrote: (...) > My understanding is that the vast majority of Python software is > provided as open source. Hence, I am a bit confused by all the talk > about the need for freedom and openness in Python. If data hiding were > enforced, and you need access to something marked as private, you can > just change it to public in the source code. What's the problem? > > Note: that change would be much easier to make if a "private" (or > perhaps "priv") keyword were used instead of the leading-underscore > rule. The former would require a change in only one place (per > attribute), whereas the latter would require a change of every > occurrence of the attribute. > > So "enforced" access restrictions are trivial to work around with open > source. But doesn't that mean that access restriction is pointless > because it cannot be enforced anyway? Of course not. In a team > project, the access restrictions will be enforced on the checked-in > code. You can play around with the internals all you want in your own > little world, but as when you are working with a team, you need to > adhere to the interfaces they define (if any). I'm going to say this very politely. Python IS NOT Java. --JamesMills From kay.schluehr at gmx.net Fri Jan 23 00:39:46 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 22 Jan 2009 21:39:46 -0800 (PST) Subject: The First Law Of comp.lang.python Dynamics References: Message-ID: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Whatever sufficiently sophisticated topic was the initially discussed it ends all up in a request for removing reference counting and the GIL. From clp2 at rebertia.com Fri Jan 23 00:43:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jan 2009 21:43:35 -0800 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <50697b2c0901222143y7717f435xe883ce39d6b9d058@mail.gmail.com> On Thu, Jan 22, 2009 at 9:39 PM, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. +1 QOTW - Chris -- Follow the path of the Iguana... http://rebertia.com From BrianVanderburg2 at aim.com Fri Jan 23 00:53:25 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 00:53:25 -0500 Subject: USB in python In-Reply-To: <4979225B.6050106@al.com.au> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <4979225B.6050106@al.com.au> Message-ID: <49795B55.6080108@aim.com> astan.chee at al.com.au wrote: > Hi, > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using > a computer so I thought USB might be a good choice since its simple > (but didn't turn out to be). I'm open to any other suggestions on how > I might achieve this hardware and software-wise (as in what interface > should I use, etc). Also I'm trying to stay away from (complex) micro > controllers. > Any ideas? > Thanks again > Astan > -- > http://mail.python.org/mailman/listinfo/python-list How about a different interface? From what I have read the parallel port is a bit easier to program. I think you can control the data lines of the parallel port though. There is also a python wrapper for it on the pyserial web site (pyparallel maybe?) If you don't have a built-in parallel port then there are those USB to serial/parallel converters. Brian A. Vanderburg II From pavlovevidence at gmail.com Fri Jan 23 01:09:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 22:09:40 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: On Jan 22, 9:38?pm, Rhamphoryncus wrote: > On Jan 22, 9:38?pm, Carl Banks wrote: > > > > > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > > Paul Rubin ? wrote: > > > > >alex23 writes: > > > > >> Here's an article by Guido talking about the last attempt to remove > > > >> the GIL and the performance issues that arose: > > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > > >> program) *does not decrease*." > > > > >The performance decrease is an artifact of CPython's rather primitive > > > >storage management (reference counts in every object). ?This is > > > >pervasive and can't really be removed. ?But a new implementation > > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > > >suffer from such effects. > > > > CPython's "primitive" storage management has a lot to do with the > > > simplicity of interfacing CPython with external libraries. ?Any solution > > > that proposes to get rid of the GIL needs to address that. > > > I recently was on a long road trip, and was not driver, and with > > nothing better to do thought quite a bit about how this. > > > I concluded that, aside from one major trap, it wouldn't really be > > more difficult to inteface Python to external libraries, just > > differently difficult. ?Here is briefly what I came up with: > > > 1. Change the singular Python type into three metatypes: > > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > > case, the object itself is immutable but the dict can be modified. > > This, of course, would be the default metaclass in Python.) ?Only > > mutable_types would require a mutex when accessing. > > > 2. API wouldn't have to change much. ?All regular API would assume > > that objects are unlocked (if mutable) and in a consistent state. > > It'll lock any mutable objects it needs to access. ?There would also > > be a low-level API that assumes the objects are locked (if mutable) > > and does not require objects to be consistent. ?I imagine most > > extensions would call the standard API most of the time. > > > 3. If you are going to use the low-level API on a mutable object, or > > are going to access the object structure directly, you need to acquire > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > would be provided. > > > 4. Objects would have to define a method, to be called by the GC, that > > marks every object it references. ?This would be a lot like the > > current tp_visit, except it has to be defined for any object that > > references another object, not just objects that can participate in > > cycles. ?(A conservative garbage collector wouldn't suffice for Python > > because Python quite often allocates blocks but sets the pointer to an > > offset within the block. ?In fact, that's true of almost any Python- > > defined type.) ?Unfortunately, references on the stack would need to > > be registered as well, so "PyObject* p;" might have to be replaced > > with something like "Py_DECLARE_REF(PyObject,p);" which magically > > registers it. ?Ugly. > > > 5. Py_INCREF and Py_DECREF are gone. > > > 6. GIL is gone. > > > So, you gain the complexity of a two-level API, having to lock mutable > > objects sometimes, and defining more visitor methods than before, but > > you don't have to keep INCREFs and DECREFs straight, which is no small > > thing. > > > The major trap is the possibily of deadlock. ?To help minimize the > > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > > (b,a) at the same time, it won't result in a deadlock. ?What's > > disappointing is that the deadlocking possibility is always with you, > > much like the reference counts are. > > IMO, locking of the object is a secondary problem. ?Python-safethread > provides one solution, but it's not the only conceivable one. ?For the > sake of discussion it's easier to assume somebody else is solving it > for you. That assumption might be good for the sake of the discussion *you* want to have, but it's not for discussion I was having, which was to address Aahz's claim that GIL makes extension writing simple by presenting a vision of what Python might be like if it had a mark-and- sweep collector. The details of the GC are a small part of that and wouldn't affect my main point even if they are quite different than I described. Also, extension writers would have to worry about locking issues here, so it's not acceptable to assume somebody else will solve that problem. > Instead, focus on just the garbage collection. [snip rest of threadjack] You can ignore most of what I was talking about and focus on technicalities of garbage collection if you want to. I will not be joining you in that discussion, however. Carl Banks From 0.chirkut.0 at gmail.com Fri Jan 23 01:14:09 2009 From: 0.chirkut.0 at gmail.com (Nick) Date: Thu, 22 Jan 2009 22:14:09 -0800 (PST) Subject: free download - breve 2.7.2 : a 3D Simulation Environment for Multi-Agent Simulations and Artificial Life Message-ID: <23283441-37f6-4bb3-9c28-9b296a52eab1@r15g2000prd.googlegroups.com> www.filecub.com What is breve? breve is a free, open-source software package which makes it easy to build 3D simulations of multi-agent systems and artificial life. Using Python, or using a simple scripting language called steve, you can define the behaviors of agents in a 3D world and observe how they interact. breve includes physical simulation and collision detection so you can simulate realistic creatures, and an OpenGL display engine so you can visualize your simulated worlds. www.filecub.com From http Fri Jan 23 01:15:24 2009 From: http (Paul Rubin) Date: 22 Jan 2009 22:15:24 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <7xzlhimttv.fsf@ruckus.brouhaha.com> Carl Banks writes: > 3. If you are going to use the low-level API on a mutable object, or > are going to access the object structure directly, you need to acquire > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > would be provided. You mean every time you access a list or dictionary or class instance, you have to acquire a mutex? That sounds like a horrible slowdown. From drfloob at gmail.com Fri Jan 23 01:32:20 2009 From: drfloob at gmail.com (dr.floob) Date: Thu, 22 Jan 2009 22:32:20 -0800 (PST) Subject: Printed Documentation References: <0af87074-6d9c-41a8-98ec-501f6f37bf9a@s1g2000prg.googlegroups.com> Message-ID: On Jan 8, 9:48?am, "Tim Arnold" wrote: > "floob" wrote in message > > news:0af87074-6d9c-41a8-98ec-501f6f37bf9a at s1g2000prg.googlegroups.com... > > > > >I have been searching for a way to print the official Python > > documentation into some kind of book (for my own uses). ?I don't > > really care if it'sprintedon newspaper and bound with elmer's > > glue ... any way I can get relatively recent _official documentation_ > > in print form will do. > > > I'm on the go a lot, and can't read for long periods of time on LCD > > screens anyhow (so having a laptop is not my solution). ?Until eBook > > readers grow up a bit, I'm stuck trying to print the documentation > > that I REALLY need to read and absorb. > > > Lulu.com is an option, but it would cost something around $100 US > > before shipping to get everythingprinted. ?Also, I would have to > > split up some larger documents into Volumes, which I'd rather not have > > to do. > > > Has anyone tried this before? ?Is the documentation already available > > in print? > > > Thanks, > > > drfloob > > just a datapoint, but I used lulu.com to print the latex sources (525 pages) > hardbound for a cost of $25 US. > --Tim Arnold That sounds about right for 525 pages. But the current A4-sized library reference pdf is 1207 pages alone, and I'm hoping to print / most/ of the docs. I managed to get a lot of the documentation (all but some howtos) fit into 3 books on Lulu. Python Docs LaTeX sources don't seem to be available anymore, and I haven't dug into reStructuredText yet, so I massaged the A4 pdfs to fit into 5.5" x 8.5" to drop the price. Choosing only the most inexpensive options (5.5x8.5, publisher grade paper, paperback perfect bound, etc.), the numbers came out as follows: Total Pages: 2024 Book Cost: $37.87 Shipping: $12.87 (MediaMail, untrackable) Total Cost: $50.74 All in all, it's the least expensive option I've found, and about as comprehensive a set as you can get. It probably wouldn't work for people who can't read small print, though. A letter-sized (8.5" x 11") set would cost maybe 1.5x as much, roughly $75.00. P.S. At two Kinko's near me, double-sided b/w printing was $0.59 per page, compared to Lulu's $0.015. 40x as expensive. THOUSANDS of dollars. From pavlovevidence at gmail.com Fri Jan 23 01:40:10 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jan 2009 22:40:10 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: On Jan 22, 10:15?pm, Paul Rubin wrote: > Carl Banks writes: > > 3. If you are going to use the low-level API on a mutable object, or > > are going to access the object structure directly, you need to acquire > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > would be provided. > > You mean every time you access a list or dictionary or class instance, > you have to acquire a mutex? ?That sounds like a horrible slowdown. Yes, and it's never going to happen in CPython any other way. It's considered a bug if Python code can segfault the interpreter; all runtime errors are supposed to raise exceptions. The only way to ensure that won't happen is to make sure that only one thread can can access the internals of a mutable object at a time. BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Carl Banks From deets at nospam.web.de Fri Jan 23 01:58:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 07:58:48 +0100 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> Message-ID: <6tt858Fclr1hU1@mid.uni-berlin.de> Astan Chee schrieb: > Diez B. Roggisch wrote: >> Astan Chee wrote: >> >> >>> Hi, >>> Im trying to write a program for my USB device and I'm thinking of using >>> python to do this. The USB device is of my own making and it is >>> activated when one of the two data pins of the USB is given about 5V (or >>> similar to whatever the power pin is getting). Now I'm confused to if >>> the software to activate this can actually be written and how do I do >>> it? Any examples? I've seen pyUSB but it doesn't give me control over >>> the hardware and how much power is going through the data pins. >>> >> Unless I'm not getting something here. >> >> >> > Hi, > Thanks for all the responses but I forgot to mention that I have very > little hardware understanding (at least in english) and the device > itself it very simple and only needs about 5V power to be active. The > problem here is that I want to control when the device is active using a > computer so I thought USB might be a good choice since its simple (but > didn't turn out to be). I'm open to any other suggestions on how I might > achieve this hardware and software-wise (as in what interface should I > use, etc). Also I'm trying to stay away from (complex) micro controllers. > Any ideas? Others suggested the parallel port. It is the natural choice for such things, with two caveats: - it is legacy, and thus often not available on modern hardware, especially on mobile ones. So if you want it be prepared to additionally buy a usb2parallel-adapter. - it's electrical specs aren't as robust I fear. USB allos up to 500mA to be drawn, and shouldn't break if you try more & fail (albeit, that might be something that isn't true all the time). So you can draw quite a bit of current from it (the stupid USB-cup-warmers are an example of that). I have often had broken parallel-ports, and I think the reason is that they *ARE NOT* specified to drive anything - they only provide low-current control-lines. So whatever you design, you need a second power-source then. All in all, using a USB-controller is IMHO the best solution. The AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of example-code, and there is other FOSS available. I have to admit though that the whole USB-topic isn't the easiest thing. Diez From philip at semanchuk.com Fri Jan 23 02:13:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 23 Jan 2009 02:13:17 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <3BAF8361-BD9C-46D0-A5E6-561FC0801239@semanchuk.com> On Jan 23, 2009, at 12:39 AM, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. Is this a variant of Godwin's Law for Python? From astan.chee at al.com.au Fri Jan 23 02:24:37 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 18:24:37 +1100 Subject: USB in python In-Reply-To: <6tt858Fclr1hU1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> Message-ID: <497970B5.40300@al.com.au> Diez B. Roggisch wrote: > Others suggested the parallel port. It is the natural choice for such > things, with two caveats: > > - it is legacy, and thus often not available on modern hardware, > especially on mobile ones. So if you want it be prepared to additionally > buy a usb2parallel-adapter. > > - it's electrical specs aren't as robust I fear. USB allos up to 500mA > to be drawn, and shouldn't break if you try more & fail (albeit, that > might be something that isn't true all the time). So you can draw quite > a bit of current from it (the stupid USB-cup-warmers are an example of > that). I have often had broken parallel-ports, and I think the reason is > that they *ARE NOT* specified to drive anything - they only provide > low-current control-lines. So whatever you design, you need a second > power-source then. > > All in all, using a USB-controller is IMHO the best solution. The > AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of > example-code, and there is other FOSS available. > > I have to admit though that the whole USB-topic isn't the easiest thing. > > Yeah, I forgot to mention that the device is requires about 70-80mA and the parallel port (according to the spec) only provides 1mA. Thats why I was looking into the USB solution. Thanks for the suggestion though. Also, yes, the device is rather mobile and that is why it is powered by the computer/laptop but legacy isn't really an issue for me I guess. Cheers Astan From deets at nospam.web.de Fri Jan 23 02:25:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:25:40 +0100 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: <6tt9nkFc1i1tU1@mid.uni-berlin.de> atleta schrieb: > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? For me, the first one. Creatin a mapping is cumbersome, opens up all kinds of questions like "how to remove stale entries" and is a level of indirection that one has to be aware of. The session object is obviously intended to be that - a storage for information persistent over the course of the actions working with it. So - use it. Python is dynamic. Use that dynamicity. The java & C++-guys would do it - if they could. Diez From kt83313 at gmail.com Fri Jan 23 02:26:10 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Thu, 22 Jan 2009 23:26:10 -0800 (PST) Subject: Securing a database Message-ID: My company provides some services online, which now they are planning to make it offline and sell to customers who can use it in their networks. One of our major moneywinners is some data which is stored in a database. Now, this data inside the database was obtained after paying through the nose - so the company does not want to disclose the data in the DB to the outside world - not to mention the lawsuits which the original providers of data will start which will sink the company if the data goes out. Now, the code is in Python - and we have a big problem. How to secure the data in DB? One idea was to encrypt it and store the password in the code. I dont believe security through obscurity - and python code can easily be reverse-engineered too - right? Is it even possible to secure a data in this case? KT -- From msrachel.e at gmail.com Fri Jan 23 02:29:48 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Thu, 22 Jan 2009 23:29:48 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <0deaafe1-a7ef-4dc4-8ffa-e26cf1ee462f@a12g2000pro.googlegroups.com> On Jan 22, 5:41?pm, Giovanni Bajo wrote: > * I find it *very* confusing c.items() vs c.elements(). Items and > elements are synonymous (again, in my understanding of English). Would have used the term "items" but that term has a different meaning in the context of dictionaries where "items" means (key,value) pairs. The word "elements" is used for members of the set object and has a parallel meaning in the context of multisets. Since the class is a dict subclass (as recommended by Guido), the term "items" was off limits because it means something else. So, "elements" as used in the sets documentation was the next, natural choice. Raymond From deets at nospam.web.de Fri Jan 23 02:30:18 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:30:18 +0100 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> Message-ID: <6tta0aFckqj7U1@mid.uni-berlin.de> Astan Chee schrieb: > Diez B. Roggisch wrote: >> Others suggested the parallel port. It is the natural choice for such >> things, with two caveats: >> >> - it is legacy, and thus often not available on modern hardware, >> especially on mobile ones. So if you want it be prepared to >> additionally buy a usb2parallel-adapter. >> >> - it's electrical specs aren't as robust I fear. USB allos up to >> 500mA to be drawn, and shouldn't break if you try more & fail (albeit, >> that might be something that isn't true all the time). So you can draw >> quite a bit of current from it (the stupid USB-cup-warmers are an >> example of that). I have often had broken parallel-ports, and I think >> the reason is that they *ARE NOT* specified to drive anything - they >> only provide low-current control-lines. So whatever you design, you >> need a second power-source then. >> >> All in all, using a USB-controller is IMHO the best solution. The >> AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit >> of example-code, and there is other FOSS available. >> >> I have to admit though that the whole USB-topic isn't the easiest thing. >> >> > Yeah, I forgot to mention that the device is requires about 70-80mA and > the parallel port (according to the spec) only provides 1mA. Thats why I > was looking into the USB solution. > Thanks for the suggestion though. Also, yes, the device is rather mobile > and that is why it is powered by the computer/laptop but legacy isn't > really an issue for me I guess. If all you need is on-off - why can't you just use a switch? Diez From msrachel.e at gmail.com Fri Jan 23 02:37:14 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Thu, 22 Jan 2009 23:37:14 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> Message-ID: <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> On Jan 22, 5:54?pm, Paul Rubin wrote: > Giovanni Bajo writes: > > * I'm not a native speaker, but why use the word "Counter"? > > I agree with this, the new functionality is welcome but I think > the traditional term "multiset" or "bag" would have been better. The term counter was what was originally approved. At first, I didn't like it but found that it had some advantages. The main advantage is that there are *bazillions* of programmers (including some very good ones) who have never heard the term multiset or bag but have an instant, intuitive understanding of counting and counters. Also, in the context of this implementation, "multiset" would not be a good choice. The mathematical entity, multiset, is defined with elements having a count of one or more. In contrast, the Counter class allows counts to go to zero or become negative. In addition, I worried that calling it a multiset would suggest that it has a set-like API instead of a dict-like API. With the former, you write c.add(elem). With the latter, you write c[elem] += 1. So the name, "multiset" would be misleading. Bike-shed discussions aside (everyone has an opinion of how to name things), how do you guys like the functionality? Do you find it useable in real-world use cases? Raymond From deets at nospam.web.de Fri Jan 23 02:38:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 08:38:12 +0100 Subject: Securing a database In-Reply-To: References: Message-ID: <6ttaf5Fc79elU1@mid.uni-berlin.de> kt83313 at gmail.com schrieb: > My company provides some services online, which now they are planning > to make it offline and sell to customers who can use it in their > networks. > > One of our major moneywinners is some data which is stored in a > database. Now, this data inside the database was obtained after paying > through the nose - so the company does not want to disclose the data > in the DB to the outside world - not to mention the lawsuits which the > original providers of data will start which will sink the company if > the data goes out. > > Now, the code is in Python - and we have a big problem. How to secure > the data in DB? One idea was to encrypt it and store the password in > the code. I dont believe security through obscurity - and python code > can easily be reverse-engineered too - right? > > Is it even possible to secure a data in this case? No. And that has nothing to do with python. If the data is valuable, it will be decyphered from a compiled piece of code in no time. Believe me, I work for a company that sells a C++-software with protective measures of various kinds. It gets hacked. Fact of live. You could try and raise the bar, as e.g. skype does, with an onion-kind of code-encryption-scheme. But even *that* is analyzed. And it is nothing that is done easily and without major impact on your source, so you might need quite a bit of time to get it right. Is that covered by the expected revenues? And even if one doesn't want to hack into the system, if there is an interface to the data, who stops your users from exploiting that automatically to access all the data in the DB somehow? Diez From astan.chee at al.com.au Fri Jan 23 02:56:38 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 23 Jan 2009 18:56:38 +1100 Subject: USB in python In-Reply-To: <6tta0aFckqj7U1@mid.uni-berlin.de> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> Message-ID: <49797836.5020807@al.com.au> Diez B. Roggisch wrote: >> > > If all you need is on-off - why can't you just use a switch? > > > Because I want to control the on-off the device using a computer and write software for it (which I am confident I can do if I had references to how the wrappers to said interface). Cheers Astan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Jan 23 03:06:47 2009 From: http (Paul Rubin) Date: 23 Jan 2009 00:06:47 -0800 Subject: Counter Class -- Bag/Multiset References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> Message-ID: <7xtz7qxx7s.fsf@ruckus.brouhaha.com> msrachel.e at gmail.com writes: > how do you guys like the functionality? Do you find it useable in > real-world use cases? It's interesting. I wouldn't have thought of that API--I'm used to populating defaultdict(int) in the obvious ways for this sort of thing--but it is attractive and I think it will be useful. Thanks for implementing it. From bearophileHUGS at lycos.com Fri Jan 23 03:24:35 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 23 Jan 2009 00:24:35 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: Message-ID: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Raymond Hettinger: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. Very nice. Python std lib is growing more data structures, increasing the power of a default Python installation. I can remove more and more modules from my bag of tricks. I like the name Bag(), it's shorter. Names are important enough. Are keys restricted to be long and int values only? Or are they general (referenced) objects + a control of their integral nature? I think you can add better explanations to this, like an example: c += Counter() # remove zero and negative counts Bye, bearophile From bearophileHUGS at lycos.com Fri Jan 23 03:27:03 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 23 Jan 2009 00:27:03 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: bearophile: > Are keys restricted to be long and int values only? Or are they > general (referenced) objects + a control of their integral nature? Here I meant values, sorry. Also: what's the rationale of allowing negative values too? Bye, bearophile From kay.schluehr at gmx.net Fri Jan 23 03:50:48 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Fri, 23 Jan 2009 00:50:48 -0800 (PST) Subject: The First Law Of comp.lang.python Dynamics References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <09145357-8981-4edf-b60a-25eadf156c14@l37g2000vba.googlegroups.com> On 23 Jan., 08:13, Philip Semanchuk wrote: > On Jan 23, 2009, at 12:39 AM, Kay Schluehr wrote: > > > Whatever sufficiently sophisticated topic was initially discussed > > it ends all up in a request for removing reference counting and the > > GIL. > > Is this a variant of Godwin's Law for Python? Definitely. It's a stable fixed point attractor. No matter how often it was discussed to dead in the past months the likelihood that someone mentions the GIL or ref-counting approaches 1. This is particularly remarkable because it is inverse proportional to the observable activity in this domain so there are really no news. Other similarly strange phenomena: whenever Xah Lee posts one of his infamous rants it attracts at least a dozen of newsgroup readers that try to persuade each other not to respond which will inevitably grow his thread and keep it alive for a long time. From msrachel.e at gmail.com Fri Jan 23 03:53:04 2009 From: msrachel.e at gmail.com (msrachel.e at gmail.com) Date: Fri, 23 Jan 2009 00:53:04 -0800 (PST) Subject: Counter Class -- Bag/Multiset References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: <28ce2af4-350d-44bc-9877-2474fcf93ea6@u18g2000pro.googlegroups.com> On Jan 23, 12:27?am, bearophileH... at lycos.com wrote: > bearophile: > > > Are keys restricted to be long and int values only? Or are they > > general (referenced) objects + a control of their integral nature? > > Here I meant values, sorry. > Also: what's the rationale of allowing negative values too? The dict values can be anything, but only ints make sense in the context of bags/multisets/counters etc. Since it is a dict subclass, we really have no control of the content. It's pretty much a "consenting adults" data structure (much like the heapq module which cannot enforce a heap condition on the underlying list which is exposed to the user). To block negative values, the setter methods would have to be overridden and would dramatically slow down the major use cases for counters (and we would not be able to let people freely convert to and from arbitrary dicts). Also, we would have to introduce and document some kind of exception for attempts to set a negative value (i.e. c[x] -= 1 could raise an exception). This would unnecessarily complicate the API in an attempt to limit what a user can do (perhaps barring them from a use case they consider to be important). So, if you don't want negative counts, I recommend that you don't subtract more than you started off with ;-) Raymond From tjreedy at udel.edu Fri Jan 23 04:03:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 04:03:54 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> References: <7xiqo64wi6.fsf@ruckus.brouhaha.com> <00a7f2bb-a7da-4ce9-8fbc-f0702aadaaa3@b38g2000prf.googlegroups.com> Message-ID: msrachel.e at gmail.com wrote: > The term counter was what was originally approved. At first, I didn't > like it but found that it had some advantages. The main advantage is > that there are *bazillions* of programmers (including some very good > ones) who have never heard the term multiset or bag but have an > instant, > intuitive understanding of counting and counters. > > Also, in the context of this implementation, "multiset" would not be a > good choice. The mathematical entity, multiset, is defined with > elements > having a count of one or more. In contrast, the Counter class allows > counts to go to zero or become negative. In addition, I worried that > calling it a multiset would suggest that it has a set-like API instead > of a dict-like API. With the former, you write c.add(elem). With the > latter, you write c[elem] += 1. So the name, "multiset" would be > misleading. Agreed. I withdraw my objection. From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:05:31 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:05:31 +0100 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: <49798849$0$5147$426a74cc@news.free.fr> atleta a ?crit : > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, Why so ? And what does your API documentation says about this session object? > at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Is this object _safely_ usable as a key somehow ? And if yes, do you have a way to deal with stale sessions ? > Which one is the > 'pythonic' way? The simplest. But as far as I'm concerned, I don't have enough context to say which one it would be here. > Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? Depends - cf above. But as a guideline, unless the library provides a defined way to solve this problem or the library documentation clearly states I should *not* store my own data in the session object (but then what's the point of a session object ???), I'd just use it. From tjreedy at udel.edu Fri Jan 23 04:10:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 04:10:20 -0500 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Also: what's the rationale of allowing negative values too? I can guess two: 1) Nuisance to check given that Python does not have a count (0,1,2...) type. 2. Useful. + = items on hand; - = items back-ordered. Bank account go negative also ;-). So does elevation. Similarly, an app could set 0 to mean 'desired quantity on hand', so non-zero count is surplus or deficit. I might not have thought to allow this, but it seems to open new applications. (This definitely makes bag or multiset inappropriate as names.) tjr From fizzotti at gmail.com Fri Jan 23 04:13:24 2009 From: fizzotti at gmail.com (fizzotti at gmail.com) Date: Fri, 23 Jan 2009 01:13:24 -0800 (PST) Subject: problem with special characters in filename Message-ID: using: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Hello I have two files (let's assume they are all in the same directory): 1) "a.dat" containing the single line "S?bastien.dat" 2) "S?bastien.dat" containing arbitraty data I want to: open "a.dat" read in the single line ("S?bastien.dat") copy the file described by the single line ("S?bastien.dat") to another location with name "b.dat" This is what I have started with: import shutil file = open('a.dat','r') #opens file for reading for line in file: print line old_name = line[0:len(line)-1] #gets rid of "\n" suffix print old_name shutil.copy(old_name, 'b.dat') #copies file However I get the following error: IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' I'm sure this has something to do with encoding and decoding UTF-8 and Unicode or something like that, but everything I've tried has yet to produce any favourable results. Thanks Dino From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:13:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:13:36 +0100 Subject: Idea to support public/private. In-Reply-To: References: Message-ID: <49798a2e$0$14318$426a34cc@news.free.fr> Brian Allen Vanderburg II a ?crit : > Okay so I don't really care about public/private but I was watching the > lists (Does python follow its idea of readability or something like > that) and I thought of a 'possible' way to add this support to the > language. It has already been done at least a couple times. From muralimkrishan26 at yahoo.com Fri Jan 23 04:46:59 2009 From: muralimkrishan26 at yahoo.com (Murali Murali) Date: Fri, 23 Jan 2009 01:46:59 -0800 (PST) Subject: problem with special characters in filename References: Message-ID: <435705.96824.qm@web59702.mail.ac4.yahoo.com> Try this: import shutil,os file1 = open('a.dat','r') #opens file for reading for line in file1: print line ## old_name = line[0:len(line)-1] #gets rid of "\n" suffix ## print old_name line.strip() #gets rid of "\n" suffix print line os.rename('b.dat',line) #renames file file1.close() ________________________________ From: "fizzotti at gmail.com" To: python-list at python.org Sent: Friday, January 23, 2009 2:43:24 PM Subject: problem with special characters in filename using: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Hello I have two files (let's assume they are all in the same directory): 1) "a.dat" containing the single line "S?bastien.dat" 2) "S?bastien.dat" containing arbitraty data I want to: open "a.dat" read in the single line ("S?bastien.dat") copy the file described by the single line ("S?bastien.dat") to another location with name "b.dat" This is what I have started with: import shutil file = open('a.dat','r') #opens file for reading for line in file: print line old_name = line[0:len(line)-1] #gets rid of "\n" suffix print old_name shutil.copy(old_name, 'b.dat') #copies file However I get the following error: IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' I'm sure this has something to do with encoding and decoding UTF-8 and Unicode or something like that, but everything I've tried has yet to produce any favourable results. Thanks Dino -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From zzbbaadd at aol.com Fri Jan 23 04:48:32 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Fri, 23 Jan 2009 01:48:32 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> > > * No getters and setters. Python takes a very permissive approach to > class attributes, taking the philosophy "we're all adults here". It's > easy to change a public attribute to a private attribute with a getter/ > setter if you need to, so there's nothing to be gained by writing getters > for straight attribute access. It just makes things slow. If adding a getter/setter made data private, then per a tenet of Object Oriented Programming, there would be something to be gained from it. But I don't see getter/setters would do that. The statically typed object oriented languages, like Java, C++ and C#, all permit member data and functions to be public - allowing a programmer to implement a "we're all adults here" programming philosophy if they so choose. However, they also allow a programmer to make member data and functions private, thus allowing the implementation one of the tenets of OOP. I don't use Ruby, a dynamically typed language like Python, but from a web search it appears that Ruby does allow at least data to be declared private. But it appears that a user of a class can get around this private declaration by writing their own methods and adding them to the class dynamically. In his book "Core Python Programming", noted Python expert and PyCon speaker Wesley J. Chun makes the following statements regarding one of the main principles of Object Oriented Programming (OOP): "Encapsulation/Interfaces Encapsulation describes the concept of data/information hiding and providing interfaces or accessor functions to the data attributes. Direct access to data by any client, bypassing the interfaces, goes against the principles of encapsulation, but the programmer is free to allow such access. As part of the implementation, the client should not even know how the data attributes are architected within the abstraction. In Python, all class attributes are public but names may be "mangled" to discourage unauthorized access, but otherwise not prevented. It is up to the designer to provide the appropriate interfaces to the data so that the client programmer does not have to resort to manipulating the encapsulated data attributes." From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:54:53 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:54:53 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <01892202$0$20671$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <497993db$0$6847$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > >> Steven D'Aprano writes: >> >>> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >>>> Steven D'Aprano a ?crit : >>>>> But if you have free access to attributes, then *everything* is >>>>> interface. >>>> Nope. >>> How could anyone fail to be convinced by an argument that detailed and >>> carefully reasoned? >> Well, your claim /was/ just wrong. But if you want to play dumb: the >> interface is what's documented as being the interface. > > But you miss my point. > > We're told Python doesn't have private attributes. Yes. > We're told that we're > allowed to "mess with the internals", Given that we're willing and able to cope with possible consequences. > we're *encouraged* to do so Certainly not. > Python > gives you the freedom to do so, and any suggestion that freedom might be > reduced even a tiny bit is fought passionately. Won't comment on this. > When people ask how to > implement private attributes, they're often told not to bother even using > single-underscore names. "often" ? Not as far as I can tell. I think you're confusing this with the advice to not use getters/setters for no good reason, given Python's support for computed attributes - which is not exactly the same thing. > When it is suggested that Python should become > stricter, with enforced data hiding, the objections come thick and fast: > people vehemently say that they like Python just the way it is, that they > want the ability to mess with the internals. Indeed. There's no shortage of B&D languages, and well, Python is OSS, so if you want a B&D Python (now that's an oxymoron), please feel free to implement it. But by all mean, leave my favorite language alone. Thanks. > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to mess > with the private attributes. > In context, I had just mentioned that lists' > internals were inaccessible from Python code. I neglected to give an > example at the time, but a good example is the current length of the > list. Consider the experience of Microsoft and Apple. Yes, two great examples of freedom champions. > No matter how often > they tell people not to mess with the internals, people do it anyway, and > always believe that their reason is a good reason. And who are *you* to pronounce any judgement about that ? > And Python culture encourages that behaviour (albeit the consequences are > milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. Indeed. A *very* good thing FWIW. > You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. Exactly. > And then you have at least two places in the standard library where > _attributes are *explicitly* public: > > http://bugs.python.org/issue3152 > > Given this permissive culture, any responsible For your personal definition of "responsible". > library writer must assume > that if he changes his so-called "private" attributes, he will break > other people's code. You still don't get the point. If someone's code breaks because he messed with my implementation code, then *he* is responsible. The contract is very clear : "warranty void if unsealed". > In principle it could break just as much code as if > he didn't even bother flagging them with a leading underscore, which is > probably why many people don't even bother with _names. > > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them to > mess with your internals, then you don't have internals. Everything is de > facto public. Now that you've exposed your opinions, let's face reality (I mean, *facts*): Python developpers very rarely mess with implementation, usually do so for very good (and documented) reasons, and from what I've seen usually tend to get in touch with the library author to explain their case and find a better solution. Funny enough, it looks that the more you treat programmers as responsible, normally intelligent adult person, the more they tend to behave as such. And the other way around, too. Now, you comprehensively exposed your personnal distaste for Python's and more generally OSS philosophy. So I can only - as I already did way before in this thread - wonder *why* are you using Python ? I mean, is it because your bosses forces you to do so ? If yes, then, I'm truly sorry for you - I sometimes have to work with languages I really dislike so I can feel your pain (but OTHO, I never complained on these languages newsgroups about how wrong they were nor how they should IMHO be). Else, well, I just don't get the point. What you are fussing about are fundamental design choices (and philosophic points) that are well known, explained, advertized, etc. - and are really not likely to change anytime soon. From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 04:56:56 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 10:56:56 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <3b57579f-2eb0-4eab-94fe-5393f906441a@w1g2000prm.googlegroups.com> <1daaaa69-d677-4cfe-91a3-59ab8523c013@g1g2000pra.googlegroups.com> <49770f51$0$743$426a74cc@news.free.fr> <31fe9dfa-2a95-49d0-84c5-78058e5a27af@b38g2000prf.googlegroups.com> Message-ID: <49799455$0$6847$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 21, 4:04 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Russ P. a ?crit : >> (snip) >> >>> Your mistake for being a moron. But it seems to happen regularly, >>> doesn't it. How much more of my time are you going to waste, loser? >> Calling people names is certainly not the best way to defend your >> opinions here. Adios, Mr. P. > > You are absolutely right, Mr. D. I regret that post, and I have since > apologized to the person I was addressing. This stuff really isn't > important enough to get that worked up about. > Ok, so welcome back then. From kt83313 at gmail.com Fri Jan 23 05:00:03 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 02:00:03 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: On Jan 23, 12:38?pm, "Diez B. Roggisch" wrote: > kt83... at gmail.com schrieb: > > > > > My company provides some services online, which now they are planning > > to make it offline and sell to customers who can use it in their > > networks. > > > One of our major moneywinners is some data which is stored in a > > database. Now, this data inside the database was obtained after paying > > through the nose - so the company does not want to disclose the data > > in the DB to the outside world - not to mention the lawsuits which the > > original providers of data will start which will sink the company if > > the data goes out. > > > Now, the code is in Python - and we have a big problem. How to secure > > the data in DB? One idea was to encrypt it and store the password in > > the code. I dont believe security through obscurity - and python code > > can easily be reverse-engineered too - right? > > > Is it even possible to secure a data in this case? > > No. And that has nothing to do with python. If the data is valuable, it > will be decyphered from a compiled piece of code in no time. Believe me, > I work for a company that sells a C++-software with protective measures > of various kinds. It gets hacked. Fact of live. > > You could try and raise the bar, as e.g. skype does, with an onion-kind > of code-encryption-scheme. But even *that* is analyzed. And it is > nothing that is done easily and without major impact on your source, so > you might need quite a bit of time to get it right. Is that covered by > the expected revenues? > > And even if one doesn't want to hack into the system, if there is an > interface to the data, who stops your users from exploiting that > automatically to access all the data in the DB somehow? > > Diez Thank you very much Diez. This was my fear. Anyways, if we can make it real hard for them to analyze also, I think we are in the good - esp since the clients are not extremely rich enough to go for professional analyzers -- What is the skype method? The code is not huge - less than 20K LOC so, code encryption looks somewhat OK - would you be able to direct me to any hints on this? One another option that I was thinking was to automatically generate the password for the database - re-encrypt every 1 hr - and store the password inside the code itself. Is that possible in Python? i.e. changing the code itself. KT -- From deets at nospam.web.de Fri Jan 23 05:01:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:01:23 +0100 Subject: problem with special characters in filename In-Reply-To: References: Message-ID: <6ttirjFcfomeU1@mid.uni-berlin.de> fizzotti at gmail.com schrieb: > using: > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > > > Hello > > I have two files (let's assume they are all in the same directory): > > 1) "a.dat" containing the single line "S?bastien.dat" > 2) "S?bastien.dat" containing arbitraty data > > I want to: > > open "a.dat" > read in the single line ("S?bastien.dat") > copy the file described by the single line ("S?bastien.dat") to > another location with name "b.dat" > > This is what I have started with: > > import shutil > > file = open('a.dat','r') #opens file for reading > for line in file: > print line > old_name = line[0:len(line)-1] #gets rid of "\n" suffix > print old_name > shutil.copy(old_name, 'b.dat') #copies file > > However I get the following error: > IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' > > I'm sure this has something to do with encoding and decoding UTF-8 and > Unicode or something like that, but everything I've tried has yet to > produce any favourable results. You need to know two things: - what encoding has the a.dat-content? - what encoding uses your filesystem? Then you need to decode the file's contents with the first one, and then encode it with the second one. The above at least applies to Linux. I'm not sure about windows - I *know* they have wide-char/unicode support, but I'm not sure how exactly that is exposed via the python file apis Diez From deets at nospam.web.de Fri Jan 23 05:12:29 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:12:29 +0100 Subject: problem with special characters in filename In-Reply-To: <6ttirjFcfomeU1@mid.uni-berlin.de> References: <6ttirjFcfomeU1@mid.uni-berlin.de> Message-ID: <6ttjgcFcav4eU1@mid.uni-berlin.de> > > The above at least applies to Linux. I'm not sure about windows - I > *know* they have wide-char/unicode support, but I'm not sure how exactly > that is exposed via the python file apis Just found this: http://www.amk.ca/python/howto/unicode there is a seciton about filenames and OSes in there, you should read it. Diez From deets at nospam.web.de Fri Jan 23 05:19:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 11:19:20 +0100 Subject: Securing a database In-Reply-To: References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: <6ttjt8Fco8vrU1@mid.uni-berlin.de> > Thank you very much Diez. > This was my fear. > Anyways, if we can make it real hard for them to analyze also, I think > we are in the good - esp since the clients are not extremely rich > enough to go for professional analyzers -- > What is the skype method? The code is not huge - less than 20K LOC so, > code encryption looks somewhat OK - would you be able to direct me to > any hints on this? 20LOC of pyhon translates to the tenfold in a compiled language I'd guess. And all I know about the skype-protection I've read from some paper of some french researches - I think. However, that paper was about *breaking* the encryption, not about how to write it. And I'm not an expert in these matters, mind you. > One another option that I was thinking was to automatically generate > the password for the database - re-encrypt every 1 hr - and store the > password inside the code itself. Is that possible in Python? i.e. > changing the code itself. But wherefrom do you get the *initial* password, or the one used the last time? What happens if the process dies unexpectedly, leaving the db in an undefined, half-crypted state with no way to know the new password? Seriously - if I was assigned the task of doing this thing, I'd seek help from somebody who has experience in these matters. It's hard to get right, and easy to get wrong but think one has it right. Diez From eduardo.padoan at gmail.com Fri Jan 23 05:47:35 2009 From: eduardo.padoan at gmail.com (Eduardo O. Padoan) Date: Fri, 23 Jan 2009 08:47:35 -0200 Subject: A different kind of interface In-Reply-To: <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <13a85092-cbe0-4878-9a2d-f39133f88ded@v39g2000pro.googlegroups.com> Message-ID: On Thu, Jan 22, 2009 at 5:01 PM, wrote: > Eduardo O. Padoan: >> You are almost *describing* reinteract: > > - Thank you for the link and the software, I have not tried it yet, > but from the screencast it looks quite nice. > - I am glad that there are people that don't think that Emacs is > (despite being good) the alpha and omega of editing. There's space for > other ideas beside Emacs. But it is! > - Maybe I was describing reinteract there, but that's only the first > part of my post :-) > - I can see that reinteract is based on a interaction style quite > similar to the shell of Mathematica. I was talking about something > different, and more similar to TextCalc, but in the end I think > reinteract may be good enough for my purposes, so I'll try to run it. > And I may be happy enough. I dont known TextCalc, but I guess that reinteract is flexible enough to the general purpose of "experimenting with Live code". > - Eventually I may find the time and will to create my "interactive > python text" :-) I think there's space for many different solutions. > - Despite many years of experiments, development, shells, editors, and > the like, I am sure there are other designs not yet tried or not > common enough yet (beside the normal editors, shells, smart object- > oriented graphical shells like hotwire shell, Resolver One, and few > other weird things, like one where you can zoom text and images at > different scales, other text-based systems, etc). Sure, thats the spirit. > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky From muralimkrishan26 at yahoo.com Fri Jan 23 06:00:51 2009 From: muralimkrishan26 at yahoo.com (Murali Murali) Date: Fri, 23 Jan 2009 03:00:51 -0800 (PST) Subject: Need script to download file from a server using python script Message-ID: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Hi, I am fairly new to python and i am looking for a python script to download file(latest build) from the server. But, the build name changes daily. For Ex: today the build URL will be "http://mybuilds/myapp_1234.exe" and tomorrow it will be "http://myserver/mybuilds/myapp_3456.exe". So i need a script which downloads the latest build without any knowledge of build number. Can anyone help me? Advance thanks, This is my start: ################################################################### import os,sys,httplib,time, Server="myserver" Build2Download=mybuilds/myapp_3456.exe installer=myapp_3456.exe print "Downloading Installer... from the site:%s"%Server connection=httplib.HTTPConnection(Server) connection.request("GET",Build2Download) resp = connection.getresponse() if resp.status != 200: print "Error getting installer. GET response : %d %s" % (resp.status, resp.reason) sys.exit(-1) try: open(Installer, 'wb').write(resp.read()) time.sleep(15) except: pass ################################################################### The build number keeps changing. So how can i use wildchars(?) or something else to handle change in the build no.? Advance Thanks, Murali. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kt83313 at gmail.com Fri Jan 23 06:01:13 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 03:01:13 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <6ttjt8Fco8vrU1@mid.uni-berlin.de> Message-ID: <85dd7def-4f4f-4fcb-aa6d-b380909ce089@z27g2000prd.googlegroups.com> On Jan 23, 3:19?pm, "Diez B. Roggisch" wrote: > > Thank you very much Diez. > > This was my fear. > > Anyways, if we can make it real hard for them to analyze also, I think > > we are in the good - esp since the clients are not extremely rich > > enough to go for professional analyzers -- > > What is the skype method? The code is not huge - less than 20K LOC so, > > code encryption looks somewhat OK - would you be able to direct me to > > any hints on this? > > 20LOC of pyhon translates to the tenfold in a compiled language I'd guess. > > And all I know about the skype-protection I've read from some paper of > some french researches - I think. However, that paper was about > *breaking* the encryption, not about how to write it. > > And I'm not an expert in these matters, mind you. > > > One another option that I was thinking was to automatically generate > > the password for the database - re-encrypt every 1 hr - and store the > > password inside the code itself. Is that possible in Python? i.e. > > changing the code itself. > > But wherefrom do you get the *initial* password, or the one used the > last time? What happens if the process dies unexpectedly, leaving the db > in an undefined, half-crypted state with no way to know the new password? > > Seriously - if I was assigned the task of doing this thing, I'd seek > help from somebody who has experience in these matters. It's hard to get > right, and easy to get wrong but think one has it right. > > Diez I agree Diez. Anyways, code encryption seems to be a fun thing. I will try to see whether some papers about Skype is running around. If I can get it done, then maybe I will try to post the code here. KT -- From python.list at tim.thechases.com Fri Jan 23 06:12:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 23 Jan 2009 05:12:35 -0600 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: <4979A623.3040906@tim.thechases.com> > The build number keeps changing. So how can i use wildchars(?) > or something else to handle change in the build no.? Short answer: you can't...HTTP doesn't support wild-card requests. Longer answer: presumably there's some method to the madness of naming the file. Find the algorithm and use it. It might be that the URL is available in some other page, so you have to get that page, scrape it for the URL pattern, and then use the resulting URL as your input. It might be that the filename moves around because of some complex algorithm you may (or may not) have access too. If you have access to the algorithm, use it. If not, it might be that the source is trying to make it hard for people to do exactly what you're doing by randomly moving the file around on the website in which case, be nice. -tkc From mrkafk at gmail.com Fri Jan 23 06:17:41 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 12:17:41 +0100 Subject: seeking to improve Python skills Message-ID: Hello everyone, I wrote the following program mainly for educational purpose of improving my Python programming skills -- would Pythonistas here please look at it and point out areas that could use improvement? This thing analyzes the stored load average record file, calculates simple moving average and produces Gnuplot program to plot the thing. Constructive criticism is welcome. #!/usr/bin/python import re import sys import tempfile import subprocess import os class MovingAvg(object): def __init__(self, fname): try: self.fo = open(fname) except IOError, e: print "Problem with opening file:", e sys.exit(4) self.reslist = [] self.smalist = [] self.maxval = 0 def extrfromfile(self): vre = re.compile("(\d+-\d+-\d+) (\d\d:\d\d) (\d+\.\d+)") for line in self.fo: res = vre.search(line) if res: self.reslist.append({'day':res.group(1),\ 'time':res.group(2),\ 'val':float(res.group(3))}) def calc_sma(self, smalen=4): if smalen == 0: raise AssertionError, "Moving Average sample length cannot be 0" if not isinstance(smalen, int): raise AssertionError, "Moving Average sample length has to be integer" total = 0 total = sum( [ x['val'] for x in self.reslist[0:smalen] ] ) sma = total / smalen smaidx = int(smalen/2) self.smalist.append((self.reslist[0]['day'],\ self.reslist[0]['time'],\ self.reslist[0]['val'],\ self.reslist[0]['val'])) for i in range(smalen, len(self.reslist)): curval = self.reslist[i]['val'] self.maxval = max(self.maxval, curval) total += curval total -= self.reslist[i - smalen]['val'] sma = total / smalen smaidx += 1 self.smalist.append((self.reslist[smaidx]['day'],\ self.reslist[smaidx]['time'],\ self.reslist[smaidx]['val'],\ sma)) def return_results(self): return (self.reslist, self.smalist, self.maxval) class GnuplotWrapper(object): def __init__(self, smalist, maxval, outfname = "calc.png", graphlen=640, graphheight=480, gnuplot = '/usr/bin/gnuplot'): self.outfname = outfname self.smalist = smalist self.gnuplot = gnuplot self.gprog = None self.gdata = None self.graphlen = graphlen self.graphheight = graphheight def _writefiles(self): self.gprog = tempfile.mkstemp() self.gdata = tempfile.mkstemp() self.gprogfile = open(self.gprog[1], 'wb') self.gdatafile = open(self.gdata[1], 'wb') labelnum = int(self.graphlen / 110) labelstep = int(len(self.smalist) / labelnum) labels = [] for i in range(0, len(self.smalist), labelstep): labels.append("\"%s %s\" %d" % (self.smalist[i][0], self.smalist[i][1], i)) labelstr = ", ".join(labels) self.gprogfile.write("""set terminal png size %d, %d set style line 1 lt 1 lw 2 set style line 2 lt 2 lw 2 set output "%s" set xtics(%s) set yrange [0:%f] set y2range [0:%f] plot "%s" using 1 with lines ls 1 title "orig" axes x1y1, "%s" using 2 with lines ls 2 title "Moving Average" axes x1y2 """ % (self.graphlen, self.graphheight, self.outfname, labelstr, float(maxval), float(maxval),\ self.gdata[1], self.gdata[1]) ) self.gprogfile.close() for elem in self.smalist: self.gdatafile.write("%f, %f\n" % (elem[2], elem[3])) self.gdatafile.close() def plot(self): self._writefiles() gplot = subprocess.Popen(self.gnuplot + " " + self.gprog[1],\ shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print "Plotting data (%s)..." % self.outfname so, se = gplot.communicate() if se: print "Gnuplot problem output:", se os.remove(self.gprog[1]) os.remove(self.gdata[1]) if __name__ == "__main__": try: fname = sys.argv[1] except IndexError: print "Specify filename with data as first argument." sys.exit(1) except Exception, e: print "Error:", e sys.exit(2) values = MovingAvg(fname) values.extrfromfile() values.calc_sma(smalen = 10) (reslist, smalist, maxval) = values.return_results() gp = GnuplotWrapper(smalist, maxval) gp.plot() Example data: 08-11-19 12:41 0.11 0.45 0.40 2/158 27091 08-11-19 12:42 0.08 0.43 0.39 9/171 27113 08-11-19 12:43 0.57 0.53 0.43 4/163 12350 08-11-19 12:44 0.21 0.43 0.40 8/176 12422 08-11-19 12:45 0.08 0.36 0.37 6/166 12507 08-11-19 12:46 0.66 0.51 0.43 4/163 30147 08-11-19 12:47 0.32 0.43 0.40 4/163 30195 08-11-19 12:48 0.12 0.35 0.37 9/174 30263 08-11-19 12:49 0.47 0.43 0.40 6/162 15513 08-11-19 12:50 0.17 0.35 0.37 2/159 15562 08-11-19 12:51 0.11 0.30 0.35 6/162 15613 08-11-19 12:52 0.68 0.47 0.41 5/161 779 08-11-19 12:53 0.25 0.38 0.38 4/161 859 08-11-19 12:54 0.16 0.33 0.36 9/174 927 08-11-19 12:55 0.62 0.44 0.39 5/166 18633 08-11-19 12:56 0.36 0.42 0.39 6/162 18672 08-11-19 12:57 0.23 0.37 0.37 5/163 18757 08-11-19 12:58 0.56 0.46 0.40 4/161 4026 08-11-19 12:59 0.26 0.39 0.37 4/220 4134 08-11-19 13:00 0.16 0.33 0.35 7/169 4232 08-11-19 13:01 0.56 0.44 0.39 1/162 21882 08-11-19 13:02 0.22 0.37 0.36 4/161 21921 08-11-19 13:03 0.14 0.32 0.35 5/163 21972 08-11-19 13:04 0.78 0.53 0.42 5/173 7246 08-11-19 13:05 0.34 0.45 0.40 5/163 7299 08-11-19 13:06 0.20 0.39 0.38 5/167 7369 08-11-19 13:07 0.54 0.48 0.41 5/165 24993 08-11-19 13:08 0.25 0.40 0.38 8/174 25071 08-11-19 13:09 0.18 0.36 0.36 6/168 25148 08-11-19 13:10 0.54 0.45 0.39 5/172 10397 08-11-19 13:11 0.27 0.39 0.37 4/167 10440 08-11-19 13:12 0.22 0.36 0.36 5/168 10517 08-11-19 13:13 1.05 0.67 0.47 4/169 28210 08-11-19 13:14 0.46 0.56 0.44 6/172 28266 08-11-19 13:15 0.17 0.45 0.41 6/172 28346 08-11-19 13:16 0.63 0.55 0.45 5/171 13597 08-11-19 13:17 0.42 0.53 0.45 4/172 13679 08-11-19 13:18 0.20 0.44 0.42 5/172 13735 08-11-19 13:19 0.59 0.54 0.45 4/170 31370 08-11-19 13:20 0.21 0.44 0.42 5/172 31431 08-11-19 13:21 0.08 0.36 0.40 6/172 31511 08-11-19 13:22 0.64 0.51 0.45 4/172 16756 08-11-19 13:23 0.23 0.42 0.42 4/172 16804 08-11-19 13:24 0.13 0.35 0.40 9/185 16881 08-11-19 13:25 0.64 0.48 0.44 5/174 2074 08-11-19 13:26 0.26 0.40 0.41 4/172 2120 08-11-19 13:27 0.14 0.34 0.39 5/174 2176 08-11-19 13:28 0.64 0.47 0.43 6/174 19887 08-11-19 13:29 0.23 0.38 0.40 4/172 19972 08-11-19 13:30 0.12 0.32 0.38 4/182 20042 08-11-19 13:31 0.80 0.51 0.44 6/174 5302 08-11-19 13:32 0.29 0.42 0.41 6/173 5360 08-11-19 13:33 0.11 0.34 0.38 5/174 5446 08-11-19 13:34 0.46 0.42 0.40 4/172 23086 08-11-19 13:35 0.22 0.36 0.38 5/172 23137 08-11-19 13:36 0.28 0.38 0.39 7/175 23188 08-11-19 13:37 0.62 0.49 0.42 4/172 8464 08-11-19 13:38 0.28 0.41 0.40 4/172 8512 08-11-19 13:39 0.10 0.33 0.37 6/175 8571 08-11-19 13:40 0.51 0.42 0.39 6/173 26216 08-11-19 13:41 0.18 0.34 0.37 4/172 26296 08-11-19 13:42 0.07 0.28 0.34 6/173 26345 08-11-19 13:43 0.49 0.38 0.37 5/172 11590 08-11-19 13:44 0.25 0.33 0.35 6/173 11639 08-11-19 13:45 0.09 0.26 0.33 8/179 11747 08-11-19 13:46 0.58 0.40 0.37 4/175 29375 08-11-19 13:47 0.27 0.34 0.35 4/175 29423 08-11-19 13:48 0.10 0.28 0.33 6/176 29472 08-11-19 13:49 0.55 0.40 0.37 4/174 14752 08-11-19 13:50 0.20 0.33 0.34 4/170 14803 08-11-19 13:51 0.15 0.28 0.32 6/171 14852 08-11-19 13:52 0.52 0.39 0.36 5/172 32488 08-11-19 13:53 0.23 0.33 0.34 4/170 32566 08-11-19 13:54 0.08 0.27 0.32 6/173 32624 08-11-19 13:55 0.50 0.38 0.35 4/172 17880 08-11-19 13:56 0.24 0.32 0.33 6/174 17930 08-11-19 13:57 0.09 0.26 0.31 9/184 18044 08-11-19 13:58 0.51 0.37 0.35 4/167 3383 08-11-19 13:59 0.18 0.30 0.32 4/167 3449 08-11-19 14:00 0.10 0.26 0.30 6/171 3509 08-11-19 14:01 0.50 0.36 0.34 7/168 21261 08-11-19 14:02 0.25 0.32 0.32 7/176 21318 08-11-19 14:03 0.09 0.26 0.30 6/169 21359 08-11-19 14:04 0.59 0.39 0.34 5/170 6613 08-11-19 14:05 0.21 0.31 0.32 5/251 6774 08-11-19 14:06 0.08 0.25 0.29 5/170 6832 08-11-19 14:07 0.59 0.39 0.34 4/168 24469 08-11-19 14:08 0.28 0.34 0.32 6/179 24530 08-11-19 14:09 0.10 0.27 0.30 6/172 24600 08-11-19 14:10 0.55 0.40 0.34 4/175 9857 08-11-19 14:11 0.20 0.32 0.31 4/172 9898 08-11-19 14:12 0.07 0.26 0.29 8/183 9967 08-11-19 14:13 0.51 0.37 0.33 4/169 27631 08-11-19 14:14 0.19 0.30 0.30 4/175 27705 08-11-19 14:15 0.18 0.27 0.29 6/171 27763 08-11-19 14:16 0.65 0.41 0.34 5/171 13019 08-11-19 14:17 0.24 0.34 0.31 7/176 13109 08-11-19 14:18 0.09 0.27 0.29 5/171 13155 08-11-19 14:19 0.46 0.37 0.32 4/169 30800 08-11-19 14:20 0.21 0.31 0.30 5/171 30852 08-11-19 14:21 0.12 0.27 0.28 6/171 30937 08-11-19 14:22 0.52 0.38 0.32 4/167 16174 08-11-19 14:23 0.25 0.32 0.30 4/167 16225 08-11-19 14:24 0.09 0.26 0.28 9/180 16293 08-11-19 14:25 0.47 0.36 0.31 4/175 1505 08-11-19 14:26 0.20 0.30 0.29 4/167 1550 08-11-19 14:27 0.07 0.25 0.27 5/172 1607 08-11-19 14:28 0.73 0.42 0.33 6/169 19351 08-11-19 14:29 0.87 0.55 0.37 4/143 19654 08-11-19 14:30 0.64 0.58 0.40 4/175 19833 08-11-19 14:31 0.91 0.68 0.45 4/166 5087 08-11-19 14:32 0.33 0.56 0.42 6/167 5148 08-11-19 14:33 0.12 0.45 0.39 5/169 5231 08-11-19 14:34 0.56 0.54 0.42 5/247 22939 08-11-19 14:35 0.20 0.44 0.39 7/166 23002 08-11-19 14:36 0.07 0.36 0.36 6/167 23081 08-11-19 14:37 0.49 0.45 0.39 5/169 8374 08-11-19 14:38 0.29 0.40 0.38 6/168 8468 08-11-19 14:39 0.15 0.34 0.35 5/167 8503 08-11-19 14:40 1.07 0.58 0.43 5/177 26164 08-11-19 14:41 0.39 0.47 0.40 4/165 26233 08-11-19 14:42 0.26 0.41 0.39 6/166 26292 08-11-19 14:43 0.68 0.53 0.43 4/163 11539 08-11-19 14:44 0.25 0.43 0.40 6/165 11643 08-11-19 14:45 0.09 0.35 0.37 6/166 11727 08-11-19 14:46 0.55 0.46 0.40 6/167 29357 08-11-19 14:47 0.20 0.37 0.37 4/164 29410 08-11-19 14:48 0.07 0.30 0.35 6/169 29477 08-11-19 14:49 0.70 0.48 0.41 4/174 14803 08-11-19 14:50 0.26 0.39 0.38 4/173 14853 08-11-19 14:51 0.09 0.31 0.35 6/172 14902 08-11-19 14:52 0.52 0.40 0.38 5/173 32535 08-11-19 14:53 0.19 0.33 0.35 4/171 32644 08-11-19 14:54 0.20 0.30 0.34 4/179 32760 08-11-19 14:55 0.74 0.46 0.39 4/168 18204 08-11-19 14:56 0.33 0.39 0.37 5/167 18264 08-11-19 14:57 0.12 0.32 0.34 6/169 18357 08-11-19 14:58 0.50 0.42 0.37 8/174 3640 08-11-19 14:59 0.18 0.34 0.35 4/169 3715 08-11-19 15:00 0.06 0.27 0.33 7/173 3789 08-11-19 15:01 0.56 0.40 0.36 6/175 21475 08-11-19 15:02 0.24 0.34 0.35 7/179 21521 08-11-19 15:03 0.55 0.39 0.36 5/168 22067 08-11-19 15:04 0.76 0.49 0.40 6/171 7328 08-11-19 15:05 0.58 0.46 0.39 4/165 7493 08-11-19 15:06 0.21 0.38 0.36 5/167 7634 08-11-19 15:07 0.60 0.48 0.40 4/165 25276 08-11-19 15:08 0.22 0.39 0.37 9/177 25377 08-11-19 15:09 0.18 0.35 0.35 6/171 25491 08-11-19 15:10 0.58 0.46 0.39 4/173 10780 08-11-19 15:11 0.21 0.37 0.36 4/169 10825 08-11-19 15:12 0.11 0.32 0.34 6/170 10875 08-11-19 15:13 0.43 0.39 0.36 4/168 28534 08-11-19 15:14 0.15 0.31 0.34 4/173 28589 08-11-19 15:15 0.06 0.25 0.32 6/170 28642 08-11-19 15:16 0.52 0.38 0.36 5/169 13930 08-11-19 15:17 0.26 0.32 0.34 5/173 14048 08-11-19 15:18 0.09 0.26 0.31 5/170 14095 08-11-19 15:19 0.55 0.39 0.35 4/167 31724 08-11-19 15:20 0.34 0.35 0.34 5/179 31814 08-11-19 15:21 0.16 0.29 0.32 6/169 31911 08-11-19 15:22 0.64 0.43 0.37 6/167 17277 08-11-19 15:23 0.29 0.36 0.35 4/163 17388 08-11-19 15:24 0.16 0.31 0.33 6/166 17460 08-11-19 15:25 0.48 0.40 0.36 3/188 2923 08-11-19 15:26 0.62 0.47 0.38 4/195 3159 08-11-19 15:27 0.81 0.55 0.41 6/207 3261 08-11-19 15:28 0.77 0.61 0.44 5/208 20910 08-11-19 15:29 0.32 0.51 0.42 4/206 20992 08-11-19 15:30 0.11 0.41 0.39 6/208 21046 08-11-19 15:31 0.53 0.50 0.42 7/204 6333 08-11-19 15:32 0.19 0.40 0.39 5/205 6389 08-11-19 15:33 0.12 0.34 0.37 3/206 6500 08-11-19 15:34 0.43 0.41 0.39 6/198 24105 08-11-19 15:35 0.20 0.35 0.36 5/204 24164 08-11-19 15:36 0.07 0.28 0.34 6/201 24210 08-11-19 15:37 0.49 0.39 0.37 5/206 9525 08-11-19 15:38 0.22 0.33 0.35 4/197 9564 08-11-19 15:39 0.14 0.28 0.33 6/198 9613 08-11-19 15:40 0.48 0.38 0.36 6/199 27246 08-11-19 15:41 0.17 0.31 0.34 4/199 27345 08-11-19 15:42 0.06 0.25 0.31 4/235 27433 08-11-19 15:43 0.50 0.36 0.35 5/199 12705 08-11-19 15:44 0.18 0.29 0.33 12/211 12765 08-11-19 15:45 0.06 0.24 0.30 6/202 12839 08-11-19 15:46 0.54 0.37 0.34 6/199 30464 08-11-19 15:47 0.20 0.30 0.32 4/199 30512 08-11-19 15:48 0.11 0.25 0.30 10/209 30587 08-11-19 15:49 0.47 0.35 0.33 6/198 15867 08-11-19 15:50 0.17 0.29 0.31 4/198 15918 08-11-19 15:51 0.13 0.25 0.29 6/199 15967 08-11-19 15:52 0.52 0.36 0.33 5/200 1142 08-11-19 15:53 0.19 0.29 0.30 4/198 1220 08-11-19 15:54 0.10 0.25 0.28 8/206 1277 08-11-19 15:55 0.51 0.36 0.32 5/203 19023 08-11-19 15:56 0.24 0.31 0.30 6/198 19056 08-11-19 15:57 0.16 0.27 0.28 5/202 19155 08-11-19 15:58 0.62 0.41 0.33 7/201 4452 08-11-19 15:59 0.23 0.33 0.31 6/210 4509 08-11-19 16:00 0.14 0.28 0.29 6/202 4551 08-11-19 16:01 0.53 0.39 0.32 4/200 22211 08-11-19 16:02 0.29 0.35 0.31 5/209 22271 08-11-19 16:03 0.11 0.28 0.29 5/200 22325 08-11-19 16:04 0.38 0.34 0.31 6/199 7612 08-11-19 16:05 0.24 0.31 0.30 5/199 7698 08-11-19 16:06 0.15 0.27 0.28 5/200 7754 08-11-19 16:07 0.57 0.39 0.32 5/208 25407 08-11-19 16:08 0.21 0.32 0.29 5/199 25449 08-11-19 16:09 0.07 0.26 0.27 6/199 25530 08-11-19 16:10 0.54 0.38 0.31 5/199 10809 08-11-19 16:11 0.25 0.33 0.30 4/198 10857 08-11-19 16:12 0.09 0.26 0.27 6/199 10906 08-11-19 16:13 0.42 0.35 0.30 4/198 28564 08-11-19 16:14 0.15 0.28 0.28 4/198 28614 08-11-19 16:15 0.09 0.24 0.26 5/199 28666 08-11-19 16:16 0.50 0.36 0.30 8/198 13948 08-11-19 16:17 0.23 0.30 0.28 4/203 14036 08-11-19 16:18 0.16 0.26 0.27 6/199 14080 08-11-19 16:19 0.48 0.36 0.30 7/198 31710 08-11-19 16:20 0.18 0.29 0.27 6/202 31784 08-11-19 16:21 0.06 0.23 0.26 6/199 31846 08-11-19 16:22 0.56 0.37 0.30 4/198 17118 08-11-19 16:23 0.20 0.30 0.28 4/198 17166 08-11-19 16:24 0.11 0.25 0.26 7/200 17221 08-11-19 16:25 0.61 0.40 0.31 6/199 2475 08-11-19 16:26 0.30 0.34 0.29 4/195 2629 08-11-19 16:27 0.11 0.27 0.27 6/196 2716 08-11-19 16:28 0.73 0.44 0.33 7/197 20385 08-11-19 16:29 0.27 0.36 0.30 4/198 20467 08-11-19 16:30 0.16 0.31 0.29 5/199 20520 08-11-19 16:31 0.53 0.41 0.32 6/197 5810 08-11-19 16:32 0.19 0.33 0.30 5/198 5870 08-11-19 16:33 0.11 0.28 0.28 6/206 5972 08-11-19 16:34 0.47 0.38 0.31 4/196 23579 08-11-19 16:35 0.17 0.31 0.29 5/198 23631 08-11-19 16:36 0.12 0.26 0.27 7/199 23681 08-11-19 16:37 1.03 0.52 0.36 5/201 9044 08-11-19 16:38 0.51 0.47 0.35 4/203 9118 08-11-19 16:39 0.23 0.40 0.33 6/206 9204 08-11-19 16:40 0.60 0.50 0.37 11/211 26871 08-11-19 16:41 0.22 0.40 0.35 4/203 26943 08-11-19 16:42 0.08 0.33 0.32 6/209 27037 08-11-19 16:43 0.70 0.47 0.37 5/203 12342 08-11-19 16:44 0.62 0.47 0.37 5/207 12424 08-11-19 16:45 0.26 0.39 0.35 6/206 12510 08-11-19 16:46 0.66 0.51 0.39 4/203 30135 08-11-19 16:47 0.31 0.43 0.37 5/206 30196 08-11-19 16:48 0.17 0.36 0.35 6/205 30243 08-11-19 16:49 0.62 0.49 0.39 5/206 15559 08-11-19 16:50 0.34 0.43 0.37 7/206 15604 08-11-19 16:51 0.12 0.35 0.35 7/209 15655 08-11-19 16:52 0.52 0.44 0.38 5/202 818 08-11-19 16:53 0.22 0.37 0.36 4/206 912 08-11-19 16:54 0.08 0.30 0.33 5/201 955 Regards, mk From Russ.Paielli at gmail.com Fri Jan 23 06:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 03:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> Message-ID: <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> On Jan 23, 1:54?am, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : > > > > > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: > > >> Steven D'Aprano writes: > > >>> On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: > >>>> Steven D'Aprano a ?crit : > >>>>> But if you have free access to attributes, then *everything* is > >>>>> interface. > >>>> Nope. > >>> How could anyone fail to be convinced by an argument that detailed and > >>> carefully reasoned? > >> Well, your claim /was/ just wrong. ?But if you want to play dumb: the > >> interface is what's documented as being the interface. > > > But you miss my point. > > > We're told Python doesn't have private attributes. > > Yes. > > > We're told that we're > > allowed to "mess with the internals", > > Given that we're willing and able to cope with possible consequences. > > > we're *encouraged* to do so > > Certainly not. > > > Python > > gives you the freedom to do so, and any suggestion that freedom might be > > reduced even a tiny bit is fought passionately. > > Won't comment on this. > > > When people ask how to > > implement private attributes, they're often told not to bother even using > > single-underscore names. > > "often" ? Not as far as I can tell. I think you're confusing this with > the advice to not use getters/setters for no good reason, given Python's > support for computed attributes - which is not exactly the same thing. > > > When it is suggested that Python should become > > stricter, with enforced data hiding, the objections come thick and fast: > > people vehemently say that they like Python just the way it is, that they > > want the ability to mess with the internals. > > Indeed. There's no shortage of B&D languages, and well, Python is OSS, > so if you want a B&D Python (now that's an oxymoron), please feel free > to implement it. But by all mean, leave my favorite language alone. Thanks. > > > You even argued that you disliked data structures implemented in C and > > preferred those written in Python because you have more ability to mess > > with the private attributes. > > In context, I had just mentioned that lists' > > internals were inaccessible from Python code. I neglected to give an > > example at the time, but a good example is the current length of the > > list. Consider the experience of Microsoft and Apple. > > Yes, two great examples of freedom champions. > > > No matter how often > > they tell people not to mess with the internals, people do it anyway, and > > always believe that their reason is a good reason. > > And who are *you* to pronounce any judgement about that ? > > > And Python culture encourages that behaviour (albeit the consequences are > > milder: no buffer overflows or core dumps). > > > Add to that the culture of Open Source that encourages reading the source > > code. > > Indeed. A *very* good thing FWIW. > > > You don't need to buy a book called "Undocumented Tips and Tricks > > for Python" to discover the internals. You just need to read the source > > code. > > Exactly. > > > And then you have at least two places in the standard library where > > _attributes are *explicitly* public: > > >http://bugs.python.org/issue3152 > > > Given this permissive culture, any responsible > > For your personal definition of "responsible". > > > library writer must assume > > that if he changes his so-called "private" attributes, he will break > > other people's code. > > You still don't get the point. If someone's code breaks because he > messed with my implementation code, then *he* is responsible. The > contract is very clear : "warranty void if unsealed". > > > > > In principle it could break just as much code as if > > he didn't even bother flagging them with a leading underscore, which is > > probably why many people don't even bother with _names. > > > In other words, if you make it easy for people to mess with your > > internals, if you have a culture that allows and even encourages them to > > mess with your internals, then you don't have internals. Everything is de > > facto public. > > Now that you've exposed your opinions, let's face reality (I mean, > *facts*): Python developpers very rarely mess with implementation, > usually do so for very good (and documented) reasons, and from what I've > seen usually tend to get in touch with the library author to explain > their case and find a better solution. > > Funny enough, it looks that the more you treat programmers as > responsible, normally intelligent adult person, the more they tend to > behave as such. And the other way around, too. > > Now, you comprehensively exposed your personnal distaste for Python's > and more generally OSS philosophy. So I can only - as I already did way > before in this thread - wonder *why* are you using Python ? > > I mean, is it because your bosses forces you to do so ? If yes, then, > I'm truly sorry for you - I sometimes have to work with languages I > really dislike so I can feel your pain (but OTHO, I never complained on > these languages newsgroups about how wrong they were nor how they should > IMHO be). > > Else, well, I just don't get the point. What you are fussing about are > fundamental design choices (and philosophic points) that are well known, > explained, advertized, etc. - and are really not likely to change > anytime soon. I am curious about something. Have you ever needed to access a "private" attribute (i.e., one named with a leading underscore) in Python code that you did not have the source code for? For that matter, have you ever even used a library written in Python without having access to the source code? As I said before, if you have the source code you can always change private attributes to public in a pinch if the language enforces encapsulation. But if you are working on a team project, you can't change the code that another member of a team checks in. That is how enforced data hiding helps teams of developers manage interfaces. The bigger the team and the bigger the project, the more it helps. Mr. D'Aprano gave an excellent example of a large banking program. Without enforced encapsulation, anyone on the development team has access to the entire program and could potentially sneak in fraudulent code much more easily than if encapsulation were enforced by the language. I am certainly not saying that Python is useless without enforced data hiding. It is obviously very useful for a wide range of applications and domains already. I am only saying that it's usefulness could be enhanced if enforced encapsulation can be added without somehow comromising the language. I don't know enough about the inner workings of the Python interpreter to know if that is the case or not (I am an aeronautical engineer), but the objections I've seen so far on this thread have not impressed me. From dsdale24 at gmail.com Fri Jan 23 06:24:59 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Fri, 23 Jan 2009 03:24:59 -0800 (PST) Subject: what gives with References: Message-ID: On Jan 22, 10:07?pm, Benjamin Peterson wrote: > Darren Dale gmail.com> writes: > > > Judging fromhttp://bugs.python.org/issue2400, this issue > > was fixed back in May 2008, but it is still present with python-2.5.4, > > which was released in December. Why wont python-2.5 allow this kind of > > import? > > Allowing that would be a new feature which is disallowed in bug fix releases > like 2.5.4. I was talking about the behavior after doing "from __future__ import absolute_import". I've been developing on python-2.6 using absolute_import for weeks, knowing that I could do "from __future__ import absolute import" on python-2.5. Now when I try to use python-2.5 I cant import my package. What is the point of providing absolute_import in __future__ if the api is completely different than the implementation in future python versions? Its bizarre. From Russ.Paielli at gmail.com Fri Jan 23 06:28:54 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 03:28:54 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <1a9dc496-0fa5-452e-a880-f4b695cf65aa@f40g2000pri.googlegroups.com> Message-ID: <240f6259-044f-4090-9406-12948378c8ec@a26g2000prf.googlegroups.com> On Jan 22, 9:22?pm, "Russ P." wrote: > code. You can play around with the internals all you want in your own > little world, but as when you are working with a team, you need to > adhere to the interfaces they define (if any). The word "as" should not be there: ... but when you are working with a team, ... Sorry, but that was bothering me. I sure wish these posts could be edited after they are submitted. From apardon at forel.vub.ac.be Fri Jan 23 06:31:50 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Jan 2009 11:31:50 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <496ce14b$0$18741$426a74cc@news.free.fr> <7xk58yn9t0.fsf@ruckus.brouhaha.com> <38d72d29-77f2-4de6-bc41-237fcc5deb52@u14g2000yqg.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> Message-ID: On 2009-01-16, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > >> On Jan 15, 12:21?pm, Bruno Desthuilliers >> wrote: >> >> > Once again, the important point is that there's a *clear* distinction >> > between interface and implementation, and that you *shouldn't* mess with >> > implementation. >> >> If you "*shouldn't* mess with the implementation", then what is wrong >> with enforcing that "shouldn't" in the language itself? > > Because, as a library user, it should be my power to chose when and how I > _should_ mess with the implementation, not the compiler, and definitely not you. Why should it be in your power? By messing with the implementation of a library you risk the correctness of the code of all participant coders in that project. I not that sure it should be your power to chose when and how to do that. -- Antoon Pardon From fakeaddress at nowhere.org Fri Jan 23 06:41:39 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 03:41:39 -0800 Subject: Securing a database In-Reply-To: References: <6ttaf5Fc79elU1@mid.uni-berlin.de> Message-ID: <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> kt83313 at gmail.com wrote: > Anyways, if we can make it real hard for them to analyze also, I think > we are in the good - esp since the clients are not extremely rich > enough to go for professional analyzers -- Sounds like you have the "digital rights management" (DRM) problem. As Diez pointed out, there is no robust software solution. Nevertheless, many clever people have worked each side, so there's now something of a body of practice and experience. > What is the skype method? The code is not huge - less than 20K LOC so, > code encryption looks somewhat OK - would you be able to direct me to > any hints on this? I don't think Skype has much to offer here. They're not focused on selling DRM technology; they sell communication services. Third parties can write applications on top of those services, which can be protected by Skype's DRM. (If I'm wrong on that, someone please correct me.) Diez's noted Skype's use of a layered approach, but there's nothing special about the notion of layered code encryption in DRM software. It's been used multiple times, broken multiple times, and patented multiple times. > One another option that I was thinking was to automatically generate > the password for the database - re-encrypt every 1 hr - and store the > password inside the code itself. Is that possible in Python? i.e. > changing the code itself. Possible it is. Effective it is almost certainly not, at least not without a whopping bunch of other techniques going vastly beyond that description. Look up DRM technology companies, such as CloakWare, Macrovision, and Cryptography Research. If you have a modest number of customers, hardware solutions and/or strict contractual commitments might offer practical solutions. -- --Bryan From pranny at gmail.com Fri Jan 23 06:50:39 2009 From: pranny at gmail.com (pranav) Date: Fri, 23 Jan 2009 03:50:39 -0800 (PST) Subject: Executing WinXP commands using os module Message-ID: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Greetings, I am writing a code to perform operations like checkout, check-in and others for SS. (SS is the command line utility for Visual SafeSource, VSS). I am familiar with all the commands for this purpose. I know li'l python also. What i want to learn is how do i use the command line arguments in os (or any other call that will fulfill my purpose). I can use popen to create a command prompt. But i need to use commands like ss checkout $\projectName\file -Yusername,password -c'Test comment' Please help me. Thanks in advance, Regards Pranav Prakash http://codecontrol.blogspot.com From rasky at develer.com Fri Jan 23 07:05:02 2009 From: rasky at develer.com (Giovanni Bajo) Date: Fri, 23 Jan 2009 13:05:02 +0100 Subject: Counter Class -- Bag/Multiset In-Reply-To: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> References: <50697b2c0901221749i34ae3ae2u384d5ae3025e7fe4@mail.gmail.com> Message-ID: <4979B26E.4010408@develer.com> On 1/23/2009 2:49 AM, Chris Rebert wrote: > On Thu, Jan 22, 2009 at 5:41 PM, Giovanni Bajo wrote: >> On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote: >> >>> The collections module in Python 2.7 and Python 3.1 has gotten a new >>> Counter class that works like bags and multisets in other languages. >>> >>> I've adapted it for Python2.5/2.6 so people can start using it right >>> away: >>> http://docs.python.org/dev/library/collections.html#counter-objects >>> >>> Here's a link to the docs for the new class: >>> http://code.activestate.com/recipes/576611/ >> Hi Raymond, >> >> * I'm not a native speaker, but why use the word "Counter"? A "counter" >> to my ear sounds like a number that is increased each time an event >> occurs; the website counter, eg, comes to mind. I can understanda its >> meaning probably stretches to "an object that counts", but I really can't >> think of it as a group of object, or a container of object. Moreover, I >> find it a much more useful abstraction the idea of a "multi-set" (that >> is, a set where elements can appear with multiple cardinality), rather >> than stressing the concept of "counting" how many times each element >> appears in the set. >> >> * I find it *very* confusing c.items() vs c.elements(). Items and >> elements are synonymous (again, in my understanding of English). > > I concur and would like to say additionally that having Counter's > len() be the number of *unique* items as opposed to just the number of > items seems a bit counterintuitive. In fact, I think that it makes sense when you're stressing the fact that it's just a dictionary of objects and their counters (which the name "Counter" in fact stresses). And my main objection is exactly this: a multiset is a differnt abstract data structure (which is probably worth its own ABC in Python); the fact that can be implemented through a mapping of objects and counters is just its concrete implementation. This was perfectly represented by Raymond's previous bag class, that was *using* a dictionary instead of *being* a dictionary. -- Giovanni Bajo Develer S.r.l. http://www.develer.com From clp2 at rebertia.com Fri Jan 23 07:05:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 04:05:50 -0800 Subject: Executing WinXP commands using os module In-Reply-To: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <50697b2c0901230405p62407328g1365e458640e3841@mail.gmail.com> On Fri, Jan 23, 2009 at 3:50 AM, pranav wrote: > Greetings, > I am writing a code to perform operations like checkout, check-in and > others for SS. (SS is the command line utility for Visual SafeSource, > VSS). I am familiar with all the commands for this purpose. I know > li'l python also. > What i want to learn is how do i use the command line arguments in os > (or any other call that will fulfill my purpose). I can use popen to > create a command prompt. But i need to use commands like > > ss checkout $\projectName\file -Yusername,password -c'Test comment' You want the `subprocess` module. See http://docs.python.org/library/subprocess.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From enleverlesX.XmcX at XmclaveauX.com Fri Jan 23 07:05:57 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Fri, 23 Jan 2009 13:05:57 +0100 Subject: Executing WinXP commands using os module In-Reply-To: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <4979b520$0$9423$ba4acef3@news.orange.fr> Hi! Try: os.system("""start "" cmd /css checkout $\projectName\file -Yusername,password -c'Test comment' """) (not tested ; it's directly from my memory) @-salutations -- Michel Claveau From pranny at gmail.com Fri Jan 23 07:08:36 2009 From: pranny at gmail.com (pranav) Date: Fri, 23 Jan 2009 04:08:36 -0800 (PST) Subject: Executing WinXP commands using os module References: <20496074-7120-46af-bb85-c0b80ab09994@o40g2000prn.googlegroups.com> Message-ID: <7b1ec291-9b9d-4c93-9b32-edfcb6f9f10b@v39g2000pro.googlegroups.com> On Jan 23, 5:05?pm, Chris Rebert wrote: > On Fri, Jan 23, 2009 at 3:50 AM, pranav wrote: > > Greetings, > > I am writing a code to perform operations like checkout, check-in and > > others for SS. (SS is the command line utility for Visual SafeSource, > > VSS). I am familiar with all the commands for this purpose. I know > > li'l python also. > > What i want to learn is how do i use the command line arguments in os > > (or any other call that will fulfill my purpose). I can use popen to > > create a command prompt. But i need to use commands like > > > ss checkout $\projectName\file -Yusername,password -c'Test comment' > > You want the `subprocess` module. Seehttp://docs.python.org/library/subprocess.html > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thanks, will try it From clp2 at rebertia.com Fri Jan 23 07:10:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 04:10:00 -0800 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: <50697b2c0901230410y56473a60xfaf5e57679a3c6bd@mail.gmail.com> On Fri, Jan 23, 2009 at 3:00 AM, Murali Murali wrote: > Hi, > > I am fairly new to python and i am looking for a python script to download > file(latest build) from the server. But, the build name changes daily. For > Ex: today the build URL will be "http://mybuilds/myapp_1234.exe" and > tomorrow it will be "http://myserver/mybuilds/myapp_3456.exe". So i need a > script which downloads the latest build without any knowledge of build > number. > > Can anyone help me? > > Advance thanks, > > This is my start: Not directly related to your main question, but you might want to use urllib.urlretrieve() rather than httplib for the downloading of the file as the interface is a good bit simpler. See http://docs.python.org/library/urllib.html#urllib.urlretrieve for the docs on it. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From unineuro at gmail.com Fri Jan 23 07:28:33 2009 From: unineuro at gmail.com (unineuro at gmail.com) Date: Fri, 23 Jan 2009 04:28:33 -0800 (PST) Subject: Dynamic methods and lambda functions Message-ID: Hi, I want to add some properties dynamically to a class, and then add the corresponding getter methods. Something resulting in this: class Person: def Getname(self): return self.__name def Getage(self): return self.__age I've implemented the next code, creating the properties from a list: props = [ ("name", "peter"), ("age", 31), ("wife", "mary") ] class Person: def __init__(self): for prop in props: setattr(self, "__" + prop[0], prop[1]) setattr(Person, "Get" + prop[0], lambda self: getattr (self, "__" + prop[0])) if __name__ == "__main__": person = Person() print person.__name print person.__age print person.__wife print print person.Getname() print person.Getage() print person.Getwife() And the resulting execution of this program is: peter 31 mary mary mary mary The attributes are right, but the getter are not working. The problem is that the lambda function always execute the last parameter passed for all instances of the methods. How could it be done the right way? Thanks in advance From mdw at distorted.org.uk Fri Jan 23 07:30:51 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 12:30:51 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: >> Well, your claim /was/ just wrong. But if you want to play dumb: the >> interface is what's documented as being the interface. > > But you miss my point. Evidently. > We're told Python doesn't have private attributes. We're told that > we're allowed to "mess with the internals", we're *encouraged* to do > so: Python gives you the freedom to do so, and any suggestion that > freedom might be reduced even a tiny bit is fought passionately. Your deduction skills are faulty. * Python gives us the freedom to do so, and we fight to protect that freedom -- yes. * But interpreting that as encouragement is wrong. It's permission, not encouragement. If you don't want to, that's fine, and we won't think less of you. Many things are possible which aren't, as a general rule, good ideas. Misinterpreting permission as encouragement will lead you to doing many stupid things. > When people ask how to implement private attributes, they're often > told not to bother even using single-underscore names. When it is > suggested that Python should become stricter, with enforced data > hiding, the objections come thick and fast: people vehemently say that > they like Python just the way it is, that they want the ability to > mess with the internals. > You even argued that you disliked data structures implemented in C and > preferred those written in Python because you have more ability to > mess with the private attributes. In context, I had just mentioned > that lists' internals were inaccessible from Python code. I neglected > to give an example at the time, but a good example is the current > length of the list. Umm... I'm pretty sure that that's available via the `len' function, which is tied to list.__len__ (via the magic C-implemented-type mangler, in C). Though it's read-only -- and this is a shame, 'cos it'd be nice to be able to adjust the length of a list in ways which are more convenient than * deleting or assigning to a trailing slice, or * augmenting or assigning to a trailing zero-width slice (Perl has supported assigning to $#ARRAY for a long time. Maybe that's a good argument against it.) > Consider the experience of Microsoft and Apple. No matter how often > they tell people not to mess with the internals, people do it anyway, > and always believe that their reason is a good reason. And Microsoft and Apple can either bend over backwards to preserve compatibility anyway (which effectively rewards the misbehaviour) or change the internals. I'd prefer that they did the latter. There are times when messing with internals is the only way to get things done; but there's a price to be paid for doing that, and the price is compatibility. The internals will change in later versions, and your code will break, in subtle and complex ways. It's not always an easy decision to make -- but I'm glad it's me that gets to decide, and not some random who neither knows nor cares much about the problem I'm trying to solve. It's also important to bear in mind that programs' lifetimes vary. Some programs are expected to live for years; some programs only for a week or so; and some for just long enough to be typed and executed once (e.g., at the interactive prompt). That Python is useful for all these kinds of program lifetimes is testament to its designers' skill. Programmers can, and should!, make different tradeoffs depending on the expected lifetime of the program they're writing. If I type some hacky thing at ipython, I know it's going to be executed there and then, and if the implementation changes tomorrow, I just don't care. If I'm writing a thing to solve an immediate problem, I won't need it much past next week, and I'll still probably get away with any awful hacking -- but there's a chance I might reuse the program in a year or so, so I ought to put a comment in warning the reader of a possible bitrot site. If I'm writing a thing that's meant to last for years, I need to plan accordingly, and it's probably no appropriate to hack with internals without a very good reason. Making these kinds of decisions isn't easy. It requires experience, subtle knowledge of how the systems one's using work, and occasionally a little low cunning. And sometimes one screws up. > And Python culture encourages that behaviour (albeit the consequences > are milder: no buffer overflows or core dumps). > > Add to that the culture of Open Source that encourages reading the source > code. You don't need to buy a book called "Undocumented Tips and Tricks > for Python" to discover the internals. You just need to read the source > code. Indeed. Very useful. Example: for my cryptographic library bindings, I needed to be able to convert between Python's `long's and my library's `mp's. I have a choice between doing it very slowly (using shift and masking operators on the `long') or fast (by including Python/longintrepr.h and digging about by hand). I chose to do it the fast way. I'm quite prepared to rewrite my conversion code (64 lines of it) if the internals change; that I haven't had to yet indicates that my judgement of the stability of the internal representation was about right. The most important point is that, /had/ I turned out to be wrong, I'd only have myself to blame. > And then you have at least two places in the standard library where > _attributes are *explicitly* public: And documented as being so. It's a convention, with explicitly documented exceptions. That's a slight shame because it weakens the convention, but it's not a disaster. > Given this permissive culture, any responsible library writer must > assume that if he changes his so-called "private" attributes, he will > break other people's code. He will, but he can also assume that the maintainers of that code are /willing/ to see it break. This is tough on people who depend on internals by accident. Maybe they'll learn to be more careful. It's not a pleasant way to learn, but it's a lesson worth learning anyway. > In principle it could break just as much code as if he didn't even > bother flagging them with a leading underscore, which is probably why > many people don't even bother with _names. This comes down to documentation. The Python standard library is largely quite well documented, and is clear about what assumptions one can make and what one can't. In the absence of such clear documentation, we're left with conventions -- _things are likely to change in future so avoid messing on them if you don't want stuff to break. > In other words, if you make it easy for people to mess with your > internals, if you have a culture that allows and even encourages them > to mess with your internals, then you don't have internals. Everything > is de facto public. And here you've made a semantic leap that I'm afraid I just can't follow. > No, cmp() can return an infinite number of values. It just never does, > at least not yet, but it might. But when Guido himself says that cmp() > can return three values, can you blame people for acting as if cmp() > can return three values? Possibly not! It's worth thinking about codifying the existing practice and documenting the more constrained behaviour. Note that the C interface -- the tp_compare slot (Python/C API Reference Manual 10.3) -- /is/ defined to return -1, 0, or +1; so presumably the performance issues have already been considered. I think all of this comes down to issues of trust and responsibility. Python, though its `we're all consenting adults' approach, encourages a culture where we trust one another to make decisions for ourselves, and to take responsibility for the consequences of those decisions. Language features such as attribute (or member) visibility or access control, on the other hand, imply a culture without trust, and with an built-in assumption of irresponsibility. That seems rather unpleasant to me. Suppose that you write a Python library module and release it. I find that it's /almost/ the right thing for some program of mine, but it doesn't quite work properly unless I hack about like so... perfect! I'm a happy bunny; you've gained a user (maybe that's a good thing, maybe it isn't!). Now, I've hacked about in your module's internal stuff: how has this affected you? Answer: not at all; you probably didn't feel a thing. You release a new version with improved internal structure and my program breaks: how has this affected you? Answer: still not at all. How did it affect me? Quite a bit, but then again, I knew what I was getting into. I gambled and lost; oh, well, that happens sometimes. I've not dealt with granularity much yet; but that's easy. Basically, decisions should be made at the level at which the consequences of those decisions are felt. This isn't directly practical, but there are mechanisms to manage it: users generally delegate technical decisions to the development team; maybe there's a hierarchy in the dev team. And the team members need to be trusted not to make decisions at the wrong level. If you can't manage that, then Python probably isn't a good match for the team; replace one or the other. Finally, I notice that you completely snipped the part of my reply which dealt with your ConfigParser module. I'm going to assume that this means that you accepted that part of my response. -- [mdw] From mdw at distorted.org.uk Fri Jan 23 07:36:11 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 12:36:11 +0000 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tz7qci84.fsf.mdw@metalzone.distorted.org.uk> aahz at pythoncraft.com (Aahz) writes: > Actually, that is not correct. You're right, evidently. [snip] >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] += ['spam'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar', 'spam'], 'xyzzy') Ugh! -- [mdw] From diresu at web.de Fri Jan 23 07:39:13 2009 From: diresu at web.de (Dietrich Bollmann) Date: Fri, 23 Jan 2009 21:39:13 +0900 Subject: How to write a simple shell loop in python? In-Reply-To: <49772515.90306@holdenweb.com> References: <1232509966.4430.28.camel@pippi.pippi> <49772515.90306@holdenweb.com> Message-ID: <1232714353.4288.40.camel@pippi.pippi> [Sorry for top posting - I had a HD problem and lost the original mails] Hi Saul, Steve, Ben, James, Scott David and James! Thank you all very much for your help! I finally got rid of the extra space and also understood why the space was printed :) After using Steve's 'input = raw_input("$ ")' solution for a while - it does exactly what I want and is the fastest fix also - I wanted command line editing and switched to the cmd.Cmd module. Special thanks to James Mills for writing his own solution! I would like to use your component - but cmd.Cmd is just perfect for my purpose and I want to run my program without the need to install any new module (I am writing the program for somebody else). I got interested in circuits though - but the homepage http://trac.softcircuit.com.au/circuits/ (currently?) seems not to be available. Thanks again for your answers :) Dietrich PS: There is a little tutorial for cmd.Cmd here: - http://www.doughellmann.com/PyMOTW/cmd/index.html The documentation is here: - http://docs.python.org/library/cmd.html (got it from Ben Finney's post) On Wed, 2009-01-21 at 08:37 -0500, Steve Holden wrote: > Dietrich Bollmann wrote: > > Hi, > > > > I am trying to write a simple shell loop in Python. > > > > My simple approach works fine - but the first output line after entering > > something is always indented by one blank. > > > > Is there any logic explanation for this? > > How can I get rid of the blank? > > Is there a smarter way to write a simple shell loop which would work > > better? > > > > Thanks, Dietrich > > > > > > Here my approach: > > > > $ python > > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > > [GCC 4.3.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys > >>>> while (1): > > ... print "$ ", > > ... input = sys.stdin.readline() > Just replace the lines above with > > input = raw_input("$ ") > > and you'll be fine. The "," in the print statement causes the > interpreter to set a flag to emit a space before the next output unless > it has just printed a newline. The "newline", of course, is provided by > the input, so the next print emits a space since it *hasn't* just > emitted a newline. > > regards > Steve > > > ... input = input.strip() > > ... print input > > ... print input > > ... print input > > ... > > $ one > > one > > one > > one > > $ two > > two > > two > > two > > $ three > > three > > three > > three > > $ > > Traceback (most recent call last): > > File "", line 3, in > > KeyboardInterrupt > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 07:44:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 12:44:34 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> Message-ID: <0189b204$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 10:54:53 +0100, Bruno Desthuilliers wrote: >> In context, I had just mentioned that lists' internals were >> inaccessible from Python code. I neglected to give an example at the >> time, but a good example is the current length of the list. Consider >> the experience of Microsoft and Apple. > > Yes, two great examples of freedom champions. What does that little dig at Microsoft and Apple have to do with what we're discussing? I dare say Linux has private internals too. Let's see if we can find some in 30 seconds of googling. http://forum.soft32.com/linux2/Bug-406747-linux-kernel-headers-private- symbols-u16-u32-asm-ftopict67443.html http://groups.google.com/group/linux.kernel/browse_thread/thread/ a08fd6423204e918 Those fascists! Private data in the kernel!!! Why can't my userland app mess with the kernel's private data??? It's so unfair!!! >> No matter how often >> they tell people not to mess with the internals, people do it anyway, >> and always believe that their reason is a good reason. > > And who are *you* to pronounce any judgement about that ? Did I pronounce any judgement? ... >> [Any] library writer must assume >> that if he changes his so-called "private" attributes, he will break >> other people's code. > > You still don't get the point. If someone's code breaks because he > messed with my implementation code, then *he* is responsible. The > contract is very clear : "warranty void if unsealed". You've built something full of user serviceable parts. You've insisted, publicly and loudly, that the ability to modify those parts is absolutely essential, you've rejected every effort to lock down those internals, and then when somebody does exactly what you encourage, you suddenly turn on them and say they're on their own. That's pretty irresponsible behaviour. As an aside, Apple and Microsoft have opposite approaches to dealing with this problem. Apple hangs the developer out to dry, which is why there are so few developers who make Mac software, while Microsoft goes to (or at least did) heroic efforts to protect developers from their mistakes, which is why the Windows internals is a dog's breakfast but there are more Windows developers named "Steve" then there are Mac developers in total. (BTW, I'm not one of them.) http://www.joelonsoftware.com/articles/APIWar.html > Now that you've exposed your opinions, let's face reality (I mean, > *facts*): Python developpers very rarely mess with implementation, > usually do so for very good (and documented) reasons, and from what I've > seen usually tend to get in touch with the library author to explain > their case and find a better solution. Facts, are they? Care to provide some reputable sources for these facts? > Funny enough, it looks that the more you treat programmers as > responsible, normally intelligent adult person, the more they tend to > behave as such. And the other way around, too. You're the one who repeatedly declared that programmers who modified internals were cretins who should be fired. I never said such a thing -- in fact, I defended them. > Now, you comprehensively exposed your personnal distaste for Python's > and more generally OSS philosophy. Really? I did? Fancy that. > So I can only - as I already did way > before in this thread - wonder *why* are you using Python ? Ah yes, the old "if you're not 100% for us, you must be 100% against us" argument. Anyone who thinks that there are costs as well as benefits to dynamic programming must be a freedom-hater, and probably kicks puppies too. > I mean, is it because your bosses forces you to do so ? Yeah, my mean old boss forces me to write Python scripts in my spare time, he forces me to spend my personal time on comp.lang.python, he forces me to write things like: [quote] Oh yes, it is liberating to say "I don't care if my method crashes (raises an exception), it's the caller's fault for messing with my class' internals, and he can deal with it". I'm not being sarcastic by the way. It really is liberating not to have to deal with unexpected input or broken pre-conditions. Just let the caller deal with it! [end quote] What a mean old boss! > If yes, then, > I'm truly sorry for you - I sometimes have to work with languages I > really dislike so I can feel your pain (but OTHO, I never complained on > these languages newsgroups about how wrong they were nor how they should > IMHO be). If people hadn't complained about missing features/misdesigns, would Python have: generator expressions print as a function booleans nested scopes None as a keyword ABCs closures to name just a few? I am curious though... you've made a few comments that suggest that your in favour of more freedom, rather than less: you've made a disparaging comment about Microsoft and Apple, you apparently think highly of Open Source software, and more. Does this freedom extend to people who have criticisms -- even mild criticisms -- of Python? > Else, well, I just don't get the point. What you are fussing about are > fundamental design choices (and philosophic points) that are well known, > explained, advertized, etc. - and are really not likely to change > anytime soon. No, probably not. Any such changes would have to start off as an external tool first. I'd guess that it couldn't even be considered as part of the base language until Python 4, which is probably a decade away. This is a good thing. There are, as you have so often pointed out, many B&D languages out there, and they are a PITA to use. Nobody wants to make Python unpleasant to use, but if you think data hiding is automatically unpleasant, then you must *hate* calling len() on a list, because that uses private data inaccessible to Python code. That's data hiding. It will probably take a decade of experiments to find a way to get as many of the benefits of data hiding as possible with as few of the costs as we can get away with. It may even be that it is impossible to do so, that you can't get the safety of data hiding without the pain. Who knows? I think it's an experiment worth trying. And for all those who insist that Python will never have data hiding except by convention, a few years ago I was saying that Python would never have static types, because of fundamental design choices to make Python a dynamic typed language. And now Python has ABCs, and optional type annotations, and Guido is encouraging people to experiment with tools that do things with those type annotations, things like type inference, and if they become popular and useful, they may end up in the language itself. As has been frequently pointed out, Python is not Java. Java is obsessed with the past, while Python is forward-looking. http://cafe.elharo.com/programming/java-is-dead-long-live-python/ Thank goodness for that. -- Steven From steve at holdenweb.com Fri Jan 23 07:53:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 07:53:55 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Aahz wrote: > In article <87hc3un1vn.fsf.mdw at metalzone.distorted.org.uk>, > Mark Wooding wrote: >> * Python augmented-assignment (`+=', for example) is inconsistent. >> Depending on what type of object the left-hand side evaluates to, it >> may /either/ mutate that object, /or/ assign a new value to the >> expression. > > Actually, that is not correct. The augmented assignment always binds a > new value to the name; the gotcha is that with a mutable object, the > object returns ``self`` from the augmented assignment method rather than > creating a new object and returning that. IOW, the smarts are always > with the object, not with the augmented assignment bytecode. > > The best way to illustrate this: > >>>> a = (1, ['foo'], 'xyzzy') >>>> a[1].append('bar') >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] = 9 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar'], 'xyzzy') >>>> a[1] += ['spam'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment >>>> a > (1, ['foo', 'bar', 'spam'], 'xyzzy') I understand what you are saying, but if the id() associated with a name doesn't change after augmented assignment it seems a little wrong-headed to argue that "the augmented assignment always binds a new value to the name". What you are actually saying is that it's up to the method that implements the augmented assignment whether the same (mutated) object or a different one is returned, right? And that the left-hand side of the assignment is always bound to the result of that method. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mrkafk at gmail.com Fri Jan 23 07:55:46 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 13:55:46 +0100 Subject: DrPython and py2exe Message-ID: Hello, I'm trying to get DrPython to edit .py file on double-click on Windows. Sure, I can use trivial .bat file to open DrPython with file as argument. But the irritating thing is that DOS window stays open until particular instance of DrPython isn't closed. py2exe to rescue. I have modified DrPython's setup.py: setup(name='drpython.exe', version=MY_VER, description=description[0], long_description=description[1], classifiers = filter(None, classifiers.split('\n')), author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, platforms = "any", license = 'GPL', packages=[ MY_NAME ], package_dir={ MY_NAME : '.' }, package_data={ MY_NAME : DATA }, scripts=['postinst.py'], windows=['drpython.py'], ) py2exe builds application, but when I start it, I get this in the log file: Traceback (most recent call last): File "drpython.py", line 46, in File "wxversion.pyc", line 152, in select wxversion.VersionError: Requested version of wxPython not found I'm guessing this is because py2exe doesn't package wxPython together with the app. Since this topic is interesting for me anyway (i.e. how to transform wxPython app using py2exe into Windows executable), would someone please reply on how to do it? Thanks, mk From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 23 07:57:52 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 23 Jan 2009 13:57:52 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> Message-ID: <4979bebd$0$18836$426a34cc@news.free.fr> Russ P. a ?crit : (snip) > I am curious about something. Have you ever needed to access a > "private" attribute (i.e., one named with a leading underscore) in > Python code that you did not have the source code for? For that > matter, have you ever even used a library written in Python without > having access to the source code? No to both. > As I said before, if you have the source code you can always change > private attributes to public in a pinch if the language enforces > encapsulation. And then have to maintain a fork. No, thanks. > But if you are working on a team project, you can't > change the code that another member of a team checks in. Why on earth couldn't I change the code of another member of my team if that code needs changes ? The code is the whole team's ownership. Now and FWIW, in this case (our own code), I just don't need to "mess with internals" - I just just change what needs to be changed. > That is how > enforced data hiding helps teams of developers manage interfaces. I totally fails to find any evidence of this assertion in the above "demonstration". > The > bigger the team and the bigger the project, the more it helps. Your opinion. > Mr. D'Aprano gave an excellent example of a large banking program. > Without enforced encapsulation, anyone on the development team has > access to the entire program and could potentially sneak in fraudulent > code much more easily than if encapsulation were enforced by the > language. My my my. If you don't trust your programmers, then indeed, don't use Python. What can I say (and what do I care ?). But once again, relying on the language's access restriction to manage *security* is, well, kind of funny, you know ? > I am certainly not saying that Python is useless without enforced data > hiding. It is obviously very useful for a wide range of applications > and domains already. I am only saying that it's usefulness could be > enhanced if enforced encapsulation can be added You might have a chance to sell this to a clueless pointy haired boss - I mean, that enforced access restriction will make Python more suitable for some big enterprizey project. As far as I'm concerned, I'm not buying it. > without somehow > comromising the language. Then just forget it. > I don't know enough about the inner workings > of the Python interpreter to know if that is the case or not (I am an > aeronautical engineer), but the objections I've seen so far on this > thread have not impressed me. I've not seen much technical objections - but anyway: learn (I mean, *really* learn) how Python's object model works, and you'll perhaps find out why this would break the whole thing. From steve at holdenweb.com Fri Jan 23 07:59:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 07:59:42 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7xzlhimttv.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Carl Banks writes: >> 3. If you are going to use the low-level API on a mutable object, or >> are going to access the object structure directly, you need to acquire >> the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() >> would be provided. > > You mean every time you access a list or dictionary or class instance, > you have to acquire a mutex? That sounds like a horrible slowdown. Indeed it would, but hey, let's not let that stop us repeating the thinking that's gone into CPython over the last fifteen years. "Those who cannot remember the past are condemned to repeat it". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 08:08:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 13:08:04 GMT Subject: Dynamic methods and lambda functions References: Message-ID: <0189b787$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 04:28:33 -0800, unineuro wrote: > Hi, > I want to add some properties dynamically to a class, and then add the > corresponding getter methods. Something resulting in this: > > class Person: > def Getname(self): > return self.__name > > def Getage(self): > return self.__age (1) Properties don't work with classic classes. If you have setters to go with these getters, and you're using Python 2.x, your code will fail to work the way you think it should. (2) Getters and setters are generally discouraged in Python unless you really need them. If all you are doing is getting/setting an attribute, then you're just wasting time. (Or if this is a learning exercise.) > I've implemented the next code, creating the properties from a list: > > props = [ > ("name", "peter"), > ("age", 31), > ("wife", "mary") > ] > > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], > lambda self: getattr(self, "__" + prop[0])) Seems awfully complicated. I'm not even sure it will work, due to Python's name-mangling. And let's not even talk about how broken it is to get your input to a class initializer from a global variable! What happens when you need a second instance? > if __name__ == "__main__": > > person = Person() > > print person.__name > print person.__age > print person.__wife > print > print person.Getname() > print person.Getage() > print person.Getwife() > > > And the resulting execution of this program is: > > peter > 31 > mary > > mary > mary > mary > > The attributes are right, but the getter are not working. The problem is > that the lambda function always execute the last parameter passed for > all instances of the methods. How could it be done the right way? class Person(object): def __init__(self, name, age, wife): self.name = name self.age = age self.wife = wife props = {"name": "peter", "age": 31, "wife": "mary"} if __name__ == "__main__": person = Person(**props) print person.name print person.age print person.wife If you really want getters, for whatever reason, then do it like this: class Person(object): def __init__(self, name, age, wife): self._name = name self._age = age self._wife = wife for prop in ('name', 'age', 'wife'): setattr(Person, prop, property( lambda self, prop=prop: getattr(self, '_'+prop) )) -- Steven From Russ.Paielli at gmail.com Fri Jan 23 08:11:36 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 05:11:36 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <1c99aef0-a4fa-4b8a-a0e2-1ba59bf5f703@i24g2000prf.googlegroups.com> On Jan 23, 4:30?am, Mark Wooding wrote: > Suppose that you write a Python library module and release it. ?I find > that it's /almost/ the right thing for some program of mine, but it > doesn't quite work properly unless I hack about like so... perfect! ?I'm > a happy bunny; you've gained a user (maybe that's a good thing, maybe it > isn't!). ?Now, I've hacked about in your module's internal stuff: how > has this affected you? ?Answer: not at all; you probably didn't feel a > thing. ?You release a new version with improved internal structure and > my program breaks: how has this affected you? ?Answer: still not at all. > How did it affect me? ?Quite a bit, but then again, I knew what I was > getting into. ?I gambled and lost; oh, well, that happens sometimes. Was this library module released in source form? If so, then why would you care that it has enforced access restrictions? You can just take them out, then do whatever you would have done had they not been there to start with. I don't see how that is any more work than figuring out what internals you need to access. Either way you need to read and understand the code. Wait ... it wasn't released in source form? Then how would you even know what internals you need to access? And why would you use something that goes against your philosophy of openness anyway? From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 08:21:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 13:21:39 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <0189bab5$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >> As I said before, if you have the source code you can always change >> private attributes to public in a pinch if the language enforces >> encapsulation. > > And then have to maintain a fork. No, thanks. If you're messing with the internals, you have to do this anyway. As soon as the internals change, your monkey-patched solution falls apart. >> But if you are working on a team project, you can't change the code >> that another member of a team checks in. > > Why on earth couldn't I change the code of another member of my team if > that code needs changes ? The code is the whole team's ownership. That's a model that works well when you have a small team of, say, a dozen people. It's not a model that works when you have hundreds of developers working on the project. The last thing I want in my projects is cowboys who ride all over other people's code, changing internals of parts they barely know at the drop of a hat, causing who knows what side- effects. But anyway, this is a red-herring. Data hiding isn't really about managing the development process, it's about ensuring that when you and Fred are using Barney's OrderedDict class in your code, Barney is free to change his the implementation without your code suddenly failing. It's also to ensure that any changes you make at runtime to the class don't suddenly make Fred's code break. -- Steven From steve at holdenweb.com Fri Jan 23 08:23:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 08:23:46 -0500 Subject: what gives with In-Reply-To: References: Message-ID: Darren Dale wrote: > On Jan 22, 10:07 pm, Benjamin Peterson wrote: >> Darren Dale gmail.com> writes: >> >>> Judging fromhttp://bugs.python.org/issue2400, this issue >>> was fixed back in May 2008, but it is still present with python-2.5.4, >>> which was released in December. Why wont python-2.5 allow this kind of >>> import? >> Allowing that would be a new feature which is disallowed in bug fix releases >> like 2.5.4. > > I was talking about the behavior after doing "from __future__ import > absolute_import". I've been developing on python-2.6 using > absolute_import for weeks, knowing that I could do "from __future__ > import absolute import" on python-2.5. Now when I try to use > python-2.5 I cant import my package. What is the point of providing > absolute_import in __future__ if the api is completely different than > the implementation in future python versions? Its bizarre. I guess it must specify some alternate future ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 08:26:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 08:26:40 -0500 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: atleta wrote: > Hi, > > I'm working with a callback API (a DBus one) and I'd need to store > some state between the calls somewhere. I know that it's possible to > extend an object with fields after creation, so I could just store my > data in the session object that is passed in with every callback. > However it stinks from OO perspective, at least to me. The other > option, something that I'd do in java for example, would be to set up > a mapping (a dict) using the session object as a key. Which one is the > 'pythonic' way? Do you use the first method (modifying an object that > you don't even control the source of) or do you write a bit more code > and go with the second one? > Or there's a third option. Write a class that implements a __call__() method, and use an instance of that class as your callback. Then the data can be stored as the callback object's private instance data. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From exarkun at divmod.com Fri Jan 23 08:34:18 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 08:34:18 -0500 Subject: seeking to improve Python skills In-Reply-To: Message-ID: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> On Fri, 23 Jan 2009 12:17:41 +0100, mk wrote: >Hello everyone, > >I wrote the following program mainly for educational purpose of improving my >Python programming skills -- would Pythonistas here please look at it and >point out areas that could use improvement? > >This thing analyzes the stored load average record file, calculates simple >moving average and produces Gnuplot program to plot the thing. > >Constructive criticism is welcome. > >#!/usr/bin/python > >import re >import sys >import tempfile >import subprocess >import os > >class MovingAvg(object): You should have a docstring here. It should describe the overall purpose of the MovingAvg class and it should probably document the meaning of each attribute instances of the class have. > def __init__(self, fname): > try: > self.fo = open(fname) > except IOError, e: > print "Problem with opening file:", e > sys.exit(4) This isn't very good. Your MovingAvg class is otherwise relatively general- purpose and re-usable, but this makes it unusable instead. You shouldn't use print to report errors in general code and you shouldn't turn specific exceptions into SystemExit. This kind of whole-program error handling belongs in a different layer if your code. Your moving average code should just focus on computing a moving average. Also, filenames are rather clunky. Another improvement here would be to pass in a file object which the calling code has already opened. Or, better still, just pass in an iterator of data. Do the file handling and the parsing in a different layer. Then you'll be able to re-use your moving average class with data files in a different format - all you'll have to do is write another parser for the new format. > self.reslist = [] > self.smalist = [] > self.maxval = 0 > > def extrfromfile(self): There should be a docstring here describing what this method does. > vre = re.compile("(\d+-\d+-\d+) (\d\d:\d\d) (\d+\.\d+)") > for line in self.fo: > res = vre.search(line) > if res: > self.reslist.append({'day':res.group(1),\ > 'time':res.group(2),\ > 'val':float(res.group(3))}) The trailing backslashes on the previous lines are superfluous. The code is just as valid without them. > def calc_sma(self, smalen=4): Another missing docstring. Make sure you also document the meaning of the parameter the method accepts. > if smalen == 0: > raise AssertionError, "Moving Average sample length >cannot be 0" > if not isinstance(smalen, int): > raise AssertionError, "Moving Average sample length >has to be integer" The conventional way to write the previous lines would be: assert smallen != 0, "Moving Average sample length cannot be 0" assert isinstance(smallen, int), "Moving Average Sample length has to be integer" However, I would just leave them out. If you document the meaning of the smalen parameter, then callers will know it can't be 0 and must be an int. > total = 0 Superfluous line above. > total = sum( [ x['val'] for x in self.reslist[0:smalen] ] ) > sma = total / smalen > smaidx = int(smalen/2) > self.smalist.append((self.reslist[0]['day'],\ > self.reslist[0]['time'],\ > self.reslist[0]['val'],\ > self.reslist[0]['val'])) Superfluous backslashes again. > for i in range(smalen, len(self.reslist)): > curval = self.reslist[i]['val'] > self.maxval = max(self.maxval, curval) > total += curval > total -= self.reslist[i - smalen]['val'] > sma = total / smalen > smaidx += 1 > self.smalist.append((self.reslist[smaidx]['day'],\ > self.reslist[smaidx]['time'],\ > self.reslist[smaidx]['val'],\ > sma)) And again. > > def return_results(self): Missing docstring. > return (self.reslist, self.smalist, self.maxval) Generally, I wonder whether MovingAvg should just be a function rather than a class. The only place it maintains state it does so confusingly. I would just make the input data a parameter to calc_sma and have it return the results it computes. Drop the rest of the class and make calc_sma a free function. >class GnuplotWrapper(object): Docstring. > def __init__(self, smalist, maxval, outfname = "calc.png", >graphlen=640, graphheight=480, gnuplot = '/usr/bin/gnuplot'): Again, the comment about filenames. You could just make outfname a file-like object and skip the naming. > self.outfname = outfname > self.smalist = smalist > self.gnuplot = gnuplot > self.gprog = None > self.gdata = None > self.graphlen = graphlen > self.graphheight = graphheight > > def _writefiles(self): Docstring. > self.gprog = tempfile.mkstemp() > self.gdata = tempfile.mkstemp() > self.gprogfile = open(self.gprog[1], 'wb') > self.gdatafile = open(self.gdata[1], 'wb') > labelnum = int(self.graphlen / 110) > labelstep = int(len(self.smalist) / labelnum) > labels = [] > for i in range(0, len(self.smalist), labelstep): > labels.append("\"%s %s\" %d" % (self.smalist[i][0], >self.smalist[i][1], i)) > labelstr = ", ".join(labels) > > self.gprogfile.write("""set terminal png size %d, %d >set style line 1 lt 1 lw 2 >set style line 2 lt 2 lw 2 >set output "%s" >set xtics(%s) >set yrange [0:%f] >set y2range [0:%f] >plot "%s" using 1 with lines ls 1 title "orig" axes x1y1, "%s" using 2 with >lines ls 2 title "Moving Average" axes x1y2 >""" % (self.graphlen, self.graphheight, self.outfname, labelstr, >float(maxval), float(maxval),\ Superfluous backslash. > self.gdata[1], self.gdata[1]) ) > self.gprogfile.close() > for elem in self.smalist: > self.gdatafile.write("%f, %f\n" % (elem[2], >elem[3])) > self.gdatafile.close() > > def plot(self): Docstring. > self._writefiles() > gplot = subprocess.Popen(self.gnuplot + " " + >self.gprog[1],\ > shell=True, stdout=subprocess.PIPE, >stderr=subprocess.PIPE) You should *avoid* using shell=True with subprocess.Popen. There's no reason to use it here, as far as I can tell. > print "Plotting data (%s)..." % self.outfname > so, se = gplot.communicate() > if se: > print "Gnuplot problem output:", se > os.remove(self.gprog[1]) > os.remove(self.gdata[1]) Reporting the gnuplot failure with print is not the best thing. Reporting errors to users should be done at a separate layer. This is your gnuplot wrapper - its job is to wrap gnuplot, not to talk to the user. If there's a problem, make it available via some documented API (for example, the plot method might raise an exception if there is a gnuplot problem). Handle the exception at a higher level in your application where you know it's correct to print things for the user to read. > > >if __name__ == "__main__": > try: > fname = sys.argv[1] > except IndexError: > print "Specify filename with data as first argument." > sys.exit(1) > except Exception, e: > print "Error:", e > sys.exit(2) What is the second exception handler doing? There is no expected other exception from the code being protected, so you should just get rid of this handler. If, through some crazy accident, another exception gets raised, Python will take care of reporting it to the user, and it will do so with far more information - information that will make your job of debugging the problem vastly easier. > values = MovingAvg(fname) > values.extrfromfile() > values.calc_sma(smalen = 10) > (reslist, smalist, maxval) = values.return_results() > gp = GnuplotWrapper(smalist, maxval) > gp.plot() > The most significant thing missing from this code is unit tests. Developing automated tests for your code will help you learn a lot. Jean-Paul From imageguy1206 at gmail.com Fri Jan 23 08:38:39 2009 From: imageguy1206 at gmail.com (imageguy) Date: Fri, 23 Jan 2009 05:38:39 -0800 (PST) Subject: DrPython and py2exe References: Message-ID: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> But the irritating thing is that DOS window stays open until > particular instance of DrPython isn't closed. This is a relatively simple fix I think. You can change the extension of the drPython.py to drpython.pyw and the python windows executable (pythonw.exe) will launch the program instead of the traditional executable (python.exe). > Traceback (most recent call last): > ? ?File "drpython.py", line 46, in > ? ?File "wxversion.pyc", line 152, in select > wxversion.VersionError: Requested version of wxPython not found check out the wiki on 'multi version installs'. http://wiki.wxpython.org/MultiVersionInstalls drPython is probably selecting a specific version of wxpython and py2exe doesn't like it or can't find it. Once you solve that, py2exe will work fine with wxpython. From Russ.Paielli at gmail.com Fri Jan 23 08:42:38 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 05:42:38 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> On Jan 23, 4:57?am, Bruno Desthuilliers wrote: > Russ P. a ?crit : > > As I said before, if you have the source code you can always change > > private attributes to public in a pinch if the language enforces > > encapsulation. > > And then have to maintain a fork. No, thanks. For crying out loud, how many private attributes do you need to access? If it's a dozen, then you and your library developer are obviously not on the same page. If it's one or two, then it's hardly a "fork." Just take note of the one or two places where you needed to remove the access restriction and you're done. Heck, you don't even need to do that, because you will be warned automatically anyway when you get the new version of the library (unless those private attributes are changed to public). > > But if you are working on a team project, you can't > > change the code that another member of a team checks in. > > Why on earth couldn't I change the code of another member of my team if > that code needs changes ? The code is the whole team's ownership. OK, fine, you can change the code of another member of the team. Are you going to check with him first, or just do it? The point is that changing an interface requires agreement of the team members who use that interface, whether on the calling or the implementation side of it. If you change interfaces without getting agreement with the other team members, you probably won't be on the team for long. And without access restrictions, accessing _private is equivalent to changing the interface. > Now and FWIW, ?in this case (our own code), I just don't need to "mess > with internals" - I just just change what needs to be changed. > > > That is how > > enforced data hiding helps teams of developers manage interfaces. > > I totally fails to find any evidence of this assertion in the above > "demonstration". > > > The > > bigger the team and the bigger the project, the more it helps. > > Your opinion. > > > Mr. D'Aprano gave an excellent example of a large banking program. > > Without enforced encapsulation, anyone on the development team has > > access to the entire program and could potentially sneak in fraudulent > > code much more easily than if encapsulation were enforced by the > > language. > > My my my. If you don't trust your programmers, then indeed, don't use > Python. What can I say (and what do I care ?). But once again, relying > on the language's access restriction to manage *security* is, well, kind > of funny, you know ? Are you seriously saying that if you were managing the production of a major financial software package with hundreds of developers, you would just "trust" them all to have free access to the most sensitive and critical parts of the program? Now *that's*, well, kind of funny, you know? Would you give all those developers your password to get into the system? No? Wait a minute ... you mean you wouldn't "trust" them with your password? But what about "openness"? Are you some sort of fascist or what? From notvalid2 at sbcglobal.net Fri Jan 23 08:56:37 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 23 Jan 2009 05:56:37 -0800 Subject: What is intvar? In-Reply-To: References: Message-ID: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> r wrote: > here is a good explanation of control vars: > http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html > > Here are 3 great Tkinter refernces in order: > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ > http://effbot.org/tkinterbook/ > http://www.pythonware.com/library/tkinter/introduction/ Thanks to all for the reference and tips. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 09:09:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 14:09:12 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <0189c5d8$0$20671$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 05:42:38 -0800, Russ P. wrote: >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, >> kind of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you would > just "trust" them all to have free access to the most sensitive and > critical parts of the program? Now *that's*, well, kind of funny, you > know? I think this is a red-herring. Probably my fault -- I was the first one to mention access controls for banking software. I meant it as an analog to data hiding, rather than implying that one can or should use private/ protected attributes to implement data hiding. Private attributes are a form of data hiding, but not all data hiding can be implemented as private attributes. -- Steven From kt83313 at gmail.com Fri Jan 23 09:10:31 2009 From: kt83313 at gmail.com (kt83313 at gmail.com) Date: Fri, 23 Jan 2009 06:10:31 -0800 (PST) Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> Message-ID: <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> On Jan 23, 4:41?pm, Bryan Olson wrote: > kt83... at gmail.com wrote: > > Anyways, if we can make it real hard for them to analyze also, I think > > we are in the good - esp since the clients are not extremely rich > > enough to go for professional analyzers -- > > Sounds like you have the "digital rights management" (DRM) problem. As > Diez pointed out, there is no robust software solution. Nevertheless, > many clever people have worked each side, so there's now something of a > body of practice and experience. > > > What is the skype method? The code is not huge - less than 20K LOC so, > > code encryption looks somewhat OK - would you be able to direct me to > > any hints on this? > > I don't think Skype has much to offer here. They're not focused on > selling DRM technology; they sell communication services. Third parties > can write applications on top of those services, which can be protected > by Skype's DRM. (If I'm wrong on that, someone please correct me.) > > Diez's noted Skype's use of a layered approach, but there's nothing > special about the notion of layered code encryption in DRM software. > It's been used multiple times, broken multiple times, and patented > multiple times. > > > One another option that I was thinking was to automatically generate > > the password for the database - re-encrypt every 1 hr - and store the > > password inside the code itself. Is that possible in Python? i.e. > > changing the code itself. > > Possible it is. Effective it is almost certainly not, at least not > without a whopping bunch of other techniques going vastly beyond that > description. > > Look up DRM technology companies, such as CloakWare, Macrovision, and > Cryptography Research. > > If you have a modest number of customers, hardware solutions and/or > strict contractual commitments might offer practical solutions. > > -- > --Bryan Thank you very much Bryan. It does look like this is out of my league. KT -- From steve at holdenweb.com Fri Jan 23 09:21:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 09:21:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <4979bebd$0$18836$426a34cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Russ P. a ?crit : [...] >> Mr. D'Aprano gave an excellent example of a large banking program. >> Without enforced encapsulation, anyone on the development team has >> access to the entire program and could potentially sneak in fraudulent >> code much more easily than if encapsulation were enforced by the >> language. > > My my my. If you don't trust your programmers, then indeed, don't use > Python. What can I say (and what do I care ?). But once again, relying > on the language's access restriction to manage *security* is, well, kind > of funny, you know ? > I have to say that I thought the example was somewhat bogus. Any development team that is even slightly concerned about the possibility of logic bombs in the code will try to mitigate that possibility by the use of code inspections. >> I am certainly not saying that Python is useless without enforced data >> hiding. It is obviously very useful for a wide range of applications >> and domains already. I am only saying that it's usefulness could be >> enhanced if enforced encapsulation can be added > > You might have a chance to sell this to a clueless pointy haired boss - > I mean, that enforced access restriction will make Python more suitable > for some big enterprizey project. As far as I'm concerned, I'm not > buying it. > I'm not sure that there's much to be gained by this level of dogmatism on either side. "Enforced encapsulation" has been "implemented" in both C++ and Java, and both have proved to be circumventable. Just the same, talk of "clueless pointy-haired bosses" is unlikely to be convincing. Even the pointy-haired types never recognize themselves as such. Annotations *have* made it into 3.0, so it's possible that the might become usable. Remember, they'll always be optional, so those who don't want to use them won't lose anything at all. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From divyabce067 at gmail.com Fri Jan 23 09:42:43 2009 From: divyabce067 at gmail.com (Divya Prakash) Date: Fri, 23 Jan 2009 20:12:43 +0530 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <778fa3370901230642y3cd67c31x8eceba9373b4e6e9@mail.gmail.com> Hello thats excellant !! On 1/23/09, Russ P. wrote: > > On Jan 23, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > > Russ P. a ?crit : > > > > As I said before, if you have the source code you can always change > > > private attributes to public in a pinch if the language enforces > > > encapsulation. > > > > And then have to maintain a fork. No, thanks. > > For crying out loud, how many private attributes do you need to > access? If it's a dozen, then you and your library developer are > obviously not on the same page. If it's one or two, then it's hardly a > "fork." Just take note of the one or two places where you needed to > remove the access restriction and you're done. Heck, you don't even > need to do that, because you will be warned automatically anyway when > you get the new version of the library (unless those private > attributes are changed to public). > > > > But if you are working on a team project, you can't > > > change the code that another member of a team checks in. > > > > Why on earth couldn't I change the code of another member of my team if > > that code needs changes ? The code is the whole team's ownership. > > OK, fine, you can change the code of another member of the team. Are > you going to check with him first, or just do it? The point is that > changing an interface requires agreement of the team members who use > that interface, whether on the calling or the implementation side of > it. If you change interfaces without getting agreement with the other > team members, you probably won't be on the team for long. And without > access restrictions, accessing _private is equivalent to changing the > interface. > > > Now and FWIW, in this case (our own code), I just don't need to "mess > > with internals" - I just just change what needs to be changed. > > > > > That is how > > > enforced data hiding helps teams of developers manage interfaces. > > > > I totally fails to find any evidence of this assertion in the above > > "demonstration". > > > > > The > > > bigger the team and the bigger the project, the more it helps. > > > > Your opinion. > > > > > Mr. D'Aprano gave an excellent example of a large banking program. > > > Without enforced encapsulation, anyone on the development team has > > > access to the entire program and could potentially sneak in fraudulent > > > code much more easily than if encapsulation were enforced by the > > > language. > > > > My my my. If you don't trust your programmers, then indeed, don't use > > Python. What can I say (and what do I care ?). But once again, relying > > on the language's access restriction to manage *security* is, well, kind > > of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? > > Would you give all those developers your password to get into the > system? No? Wait a minute ... you mean you wouldn't "trust" them with > your password? But what about "openness"? Are you some sort of fascist > or what? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Fri Jan 23 09:43:16 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 14:43:16 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xk58p4bhq.fsf@ruckus.brouhaha.com> <200901211255.42988.kyrie@uh.cu> Message-ID: 2009/1/22 Scott David Daniels : > Having once been a more type-A, I labored for a couple of years trying > to build a restricted language that provably terminated for work on an > object-oriented database research. I was careful to say that it was the /use/ of the language that is restricted; it's still possible to write undecidable programs, there's just an obligation on you to show that you haven't. > I finally gave it up as a bad idea, > because, in practice, we don't care if a loop will terminate or not in > database work; a transaction that takes a year to commit is equivalent > to an infinite loop for all applications that I have interacted with > (and yes, I have worked allowing four day transactions to commit). True -- the really serious safety critical stuff is usually real time, and part of the proof obligations is to show that the maximum response time is tolerable. The loop variant can help with that, too. -- Tim Rowe From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 09:47:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 14:47:21 GMT Subject: Stalled ticket in Python bug tracker Message-ID: <0189ceca$0$20671$c3e8da3@news.astraweb.com> I'm interested in this ticket in the bug tracker: http://bugs.python.org/issue2527 but it seems to have been stalled for nine months. Is there a procedure for starting it up again? Should I ask about it on the python-dev mailing list, or just wait until somebody happens to notice it? Peter Otten, if you're reading this, is your offer to jump through the necessary hoops still standing? -- Steven From Russ.Paielli at gmail.com Fri Jan 23 09:47:52 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 06:47:52 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <9aa5b8de-5e39-4064-9218-d67e1abfd992@r10g2000prf.googlegroups.com> On Jan 23, 6:21?am, Steve Holden wrote: > I have to say that I thought the example was somewhat bogus. Any > development team that is even slightly concerned about the possibility > of logic bombs in the code will try to mitigate that possibility by the > use of code inspections. Of course they would, but that does not mean that access restrictions enforced by the language are not prudent. Consider a corporation that needs to maintain the physical security of their buildings. You can say that locks on the doors are not sufficient. Of course they're not. Security guards are needed too -- but that doesn't mean the locks are not needed too. The locks may be *insufficient* by themselves, but they are certainly not *unnecessary*. Ditto for the enforced encapsulation for large financial or safety-critical projects. > I'm not sure that there's much to be gained by this level of dogmatism > on either side. "Enforced encapsulation" has been "implemented" in both > C++ and Java, and both have proved to be circumventable. Just the same, > talk of "clueless pointy-haired bosses" is unlikely to be convincing. > Even the pointy-haired types never recognize themselves as such. Do you think the designers of C++, Java, Ada, and Scala would eliminate the enforced encapsulation if they had it to do over again? Of course not. The vast majority of the users of those languages consider it a major plus. And those who don't wish to use it aren't forced to use it except perhaps by their bosses or their customers. Again, I am not saying that Python necessarily needs enforced access restriction. I'm just saying it would be a plus if it can be added without compromising the language in some way. From perfreem at gmail.com Fri Jan 23 09:48:22 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Fri, 23 Jan 2009 06:48:22 -0800 (PST) Subject: writing pickle function Message-ID: hello, i am using nested defaultdict from collections and i would like to write it as a pickle object to a file. when i try: from collections import defaultdict x = defaultdict(lambda: defaultdict(list)) and then try to write to a pickle file, it says: TypeError: can't pickle function objects is there a way around this? it's simply a dictionary that i want to write to file.. this works no problems with ordinary dicts. thank you. From digitig at gmail.com Fri Jan 23 09:50:00 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 14:50:00 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: 2009/1/23 Kay Schluehr : > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. Well, maybe, but it seems to me that the real issue here is that we need to remove reference counting and the GIL. -- Tim Rowe From mrkafk at gmail.com Fri Jan 23 10:12:00 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:12:00 +0100 Subject: Implementing file reading in C/Python In-Reply-To: <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> References: <9fri36xno7.ln2@joeserver.homelan.net> <474151e3-ffa4-40a6-9bc4-59de2bc98c6f@a29g2000pra.googlegroups.com> Message-ID: John Machin wrote: >> The factor of 30 indeed does not seem right -- I have done somewhat >> similar stuff (calculating Levenshtein distance [edit distance] on words >> read from very large files), coded the same algorithm in pure Python and >> C++ (using linked lists in C++) and Python version was 2.5 times slower. > Levenshtein distance using linked lists? That's novel. Care to > divulge? I meant: using linked lists to store words that are compared. I found using vectors was slow. Regards, mk From kw at codebykevin.com Fri Jan 23 10:18:12 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 23 Jan 2009 10:18:12 -0500 Subject: Find all available Tkinter cursor names? In-Reply-To: References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> Message-ID: <4979DFB4.4030705@codebykevin.com> r wrote: > Thanks Kevin, > These are exactly the ones i already knew about. I was hoping there > where more, shucks!. I wonder how i could go about making my own > cursors and adding them to Tkinter? Have any ideas? http://wiki.tcl.tk/8674 might offer some help in this regard. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From skip at pobox.com Fri Jan 23 10:33:08 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 09:33:08 -0600 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <18809.58164.565369.560733@montanaro.dyndns.org> >> You mean every time you access a list or dictionary or class >> instance, you have to acquire a mutex? That sounds like a horrible >> slowdown. Steve> Indeed it would, but hey, let's not let that stop us repeating Steve> the thinking that's gone into CPython over the last fifteen Steve> years. "Those who cannot remember the past are condemned to Steve> repeat it". Also, every object is mutable at some level. Tuples, ints and floats are definitely mutable at creation time. You need to hold a mutex then, so Carl's notion of three types of objects breaks down then. Skip From skip at pobox.com Fri Jan 23 10:35:52 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 09:35:52 -0600 Subject: Stalled ticket in Python bug tracker In-Reply-To: <0189ceca$0$20671$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: <18809.58328.566312.840475@montanaro.dyndns.org> Steven> I'm interested in this ticket in the bug tracker: Steven> http://bugs.python.org/issue2527 Steven> but it seems to have been stalled for nine months. Is there a Steven> procedure for starting it up again? Assign it to yourself? Add a comment with relevant updates? Steven> Should I ask about it on the python-dev mailing list, or just Steven> wait until somebody happens to notice it? But you've already noticed it. ;-) Skip From clp2 at rebertia.com Fri Jan 23 10:38:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 07:38:53 -0800 Subject: writing pickle function In-Reply-To: References: Message-ID: <50697b2c0901230738o4dc22c35sa6b790b91c938f11@mail.gmail.com> On Fri, Jan 23, 2009 at 6:48 AM, wrote: > hello, > > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. Functions aren't pickleable because they're Python code (which is itself not pickleable). defaultdicts contain a reference to a function (in your case, a function defined using lambda), which they use to create default values. Thus, this causes defaultdicts to not be pickleable. This is easily worked around by pickling a plain dict w/ the contents of the defaultdict (i.e. dict(x) ) and then doing: x = defaultdict(lambda: defaultdict(list)) #create empty defaultdict x.update(pickle.load(the_file)) #shove contents of pickled dict into the defaultdict Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mrkafk at gmail.com Fri Jan 23 10:52:42 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:52:42 +0100 Subject: DrPython and py2exe In-Reply-To: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: imageguy wrote: > drPython is probably selecting a specific version of wxpython and > py2exe doesn't like it or > can't find it. Once you solve that, py2exe will work fine with > wxpython. Thanks, drPython was indeed making use of wxversion.select. What's strange is that it was selecting apparently correct version: import wxversion wxversion.select('2.8') I put this in setup.py: import wxversion wxversion.select("2.8.9.1") import wx ..and it worked. Regards, mk From mrkafk at gmail.com Fri Jan 23 10:57:16 2009 From: mrkafk at gmail.com (mk) Date: Fri, 23 Jan 2009 16:57:16 +0100 Subject: seeking to improve Python skills In-Reply-To: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: Jean-Paul Calderone wrote: > The most significant thing missing from this code is unit tests. > Developing automated tests for your code will help you learn a lot. Thanks for all the remarks, I'll restructure my code. Probably the biggest mistake was not keeping "moving average" class and others focused on its respective jobs only. However, unit tests are a tougher cookie, do you have any resource that's truly worth recommending for learning unit tests? The only resource I found that was talking at some length about it was "Dive into Python" and I was wondering if there's anything better out there... Regards, mk From exarkun at divmod.com Fri Jan 23 11:09:08 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 11:09:08 -0500 Subject: seeking to improve Python skills In-Reply-To: Message-ID: <20090123160908.24460.870588213.divmod.quotient.479@henry.divmod.com> On Fri, 23 Jan 2009 16:57:16 +0100, mk wrote: >Jean-Paul Calderone wrote: > >>The most significant thing missing from this code is unit tests. >>Developing automated tests for your code will help you learn a lot. > >Thanks for all the remarks, I'll restructure my code. Probably the biggest >mistake was not keeping "moving average" class and others focused on its >respective jobs only. > >However, unit tests are a tougher cookie, do you have any resource that's >truly worth recommending for learning unit tests? The only resource I found >that was talking at some length about it was "Dive into Python" and I was >wondering if there's anything better out there... I haven't read it, but a skilled colleague of mine recommends . Jean-Paul From benjamin.kaplan at case.edu Fri Jan 23 11:20:18 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 11:20:18 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 9:50 AM, Tim Rowe wrote: > 2009/1/23 Kay Schluehr : > > Whatever sufficiently sophisticated topic was the initially discussed > > it ends all up in a request for removing reference counting and the > > GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. > But that would be hard and require a major rewrite. ;) BTW, he said sufficiently sophisticated topic. Since there hasn't been an extremely long post here yet, I don't know if this counts. > > -- > Tim Rowe > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcd at sdf.lonestar.org Fri Jan 23 11:30:00 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 23 Jan 2009 11:30:00 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <1232728200.5356.0.camel@aalcdl07.lib.unc.edu> I dub it Schluehr's law. On Thu, 2009-01-22 at 21:39 -0800, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. > > -- > http://mail.python.org/mailman/listinfo/python-list > From washakie at gmail.com Fri Jan 23 11:32:10 2009 From: washakie at gmail.com (John [H2O]) Date: Fri, 23 Jan 2009 08:32:10 -0800 (PST) Subject: Where to place imports Message-ID: <21627895.post@talk.nabble.com> Hello, Im writing some modules and I am a little confused about where to place my imports... I don't really do any class programming yet, just defining a bunch of functions, so presently I have something along the lines of: import sys import os import traceback def Foo1(a,b): import numpy import datetime return c def Foo2(a,b): import datetime c = Foo1(a,b) return c etc... Above obviously just for the form, but the point is, in some cases I may import modules twice, but other times I may not use them at all, so should I import everything into the main module? Or individually import them into functions. Is there a performance penalty either way? Pointers to a good reference are appreciated... -- View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21627895.html Sent from the Python - python-list mailing list archive at Nabble.com. From ppearson at nowhere.invalid Fri Jan 23 11:36:46 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 23 Jan 2009 16:36:46 GMT Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> Message-ID: <6tua0tFcpeeqU1@mid.individual.net> On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: > En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson > escribi?: > >> The following code uses ossaudiodev to read 1000 values from >> my sound card at a rate of 12,000 samples per second: >> >> When I select a sample rate that is not a power of 2 times >> 3000 samples/second, a strong and very regular sawtooth is >> superimposed on the signal. At some sampling frequencies, >> it appears as a rising sawtooth, and at other sampling >> frequencies it is a declining sawtooth, so I'm presumably >> lost in some aliasing wilderness. As best I can tell, >> it's a 48 KHz sawtooth. > > That could be a hardware and/or driver limitation. By example, an > AC97-compliant chipset may provide a fixed rate of 48000 samples/second -- > any sample rate conversion must be done by other means, if possible at all. Oh! As a matter of fact, my "soundcard" *is* AC97-compliant ("VT8233/A/8235/8237", according to Sysinfo). So . . . this sawtooth might result from some software, somewhere in the bucket brigade between me and the hardware, attempting to perform sample-rate conversion? The 48 KHz coincidence seems very significant. Thanks. -- To email me, substitute nowhere->spamcop, invalid->net. From deets at nospam.web.de Fri Jan 23 11:48:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 17:48:19 +0100 Subject: Where to place imports In-Reply-To: References: Message-ID: <6tuamjFckgp0U1@mid.uni-berlin.de> John [H2O] schrieb: > Hello, Im writing some modules and I am a little confused about where to > place my imports... > > I don't really do any class programming yet, just defining a bunch of > functions, so presently I have something along the lines of: > > import sys > import os > import traceback > > > def Foo1(a,b): > import numpy > import datetime > return c > > def Foo2(a,b): > import datetime > > c = Foo1(a,b) > return c > > etc... > > Above obviously just for the form, but the point is, in some cases I may > import modules twice, but other times I may not use them at all, so should I > import everything into the main module? Or individually import them into > functions. Is there a performance penalty either way? Usually, you should import on the top of the module. That's the cleanest way, and the most performant one. There is a small performance penalty when doing it inside functions - but not too much. It boils down to a lookup if the imported module has already been imported before. The only valid reason for doing imports inside functions is if you otherwise get into circular dependency hell, or have modules that need some manipulation of the sys.path before they actually can be imported. This is never true for system modules, and certainly to avoid if possible. Diez From gagsl-py2 at yahoo.com.ar Fri Jan 23 11:55:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 23 Jan 2009 14:55:36 -0200 Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> <6tua0tFcpeeqU1@mid.individual.net> Message-ID: En Fri, 23 Jan 2009 14:36:46 -0200, Peter Pearson escribi?: > On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: >> En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson >> escribi?: >> >>> The following code uses ossaudiodev to read 1000 values from >>> my sound card at a rate of 12,000 samples per second: >>> >>> When I select a sample rate that is not a power of 2 times >>> 3000 samples/second, a strong and very regular sawtooth is >>> superimposed on the signal. At some sampling frequencies, >>> it appears as a rising sawtooth, and at other sampling >>> frequencies it is a declining sawtooth, so I'm presumably >>> lost in some aliasing wilderness. As best I can tell, >>> it's a 48 KHz sawtooth. >> >> That could be a hardware and/or driver limitation. By example, an >> AC97-compliant chipset may provide a fixed rate of 48000 samples/second >> any sample rate conversion must be done by other means, if possible at >> all. > > Oh! As a matter of fact, my "soundcard" *is* AC97-compliant > ("VT8233/A/8235/8237", according to Sysinfo). So . . . this > sawtooth might result from some software, somewhere in the bucket > brigade between me and the hardware, attempting to perform > sample-rate conversion? The 48 KHz coincidence seems very > significant. Yep. Google found this for me: http://mail-index.netbsd.org/port-i386/2003/02/18/0003.html Using a sample rate that is a sub-multiple of 48000 is perhaps a safe approach. -- Gabriel Genellina From ppearson at nowhere.invalid Fri Jan 23 11:57:58 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 23 Jan 2009 16:57:58 GMT Subject: Securing a database References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> Message-ID: <6tub8mFcrapoU1@mid.individual.net> On Fri, 23 Jan 2009 06:10:31 -0800 (PST), kt83313 at gmail.com wrote: > On Jan 23, 4:41?pm, Bryan Olson wrote: [snip] >> Look up DRM technology companies, such as CloakWare, Macrovision, and >> Cryptography Research. >> >> If you have a modest number of customers, hardware solutions and/or >> strict contractual commitments might offer practical solutions. >> > Thank you very much Bryan. > It does look like this is out of my league. It is out of *everyone's* league. Every company that has ever wanted to sell movies or music that you can play on your computer but that you can't post to the Internet has faced this problem. Many, many millions of dollars have been spent searching for mitigation. The best you can hope for is to delay your attacker by some number of months. That might be enough if the value of your content is ephemeral, but even that can only be achieved with a big initial investment, enormous implementation hassles, and commitment to a never-ending arms race with the pirates. -- To email me, substitute nowhere->spamcop, invalid->net. From washakie at gmail.com Fri Jan 23 12:08:22 2009 From: washakie at gmail.com (John [H2O]) Date: Fri, 23 Jan 2009 09:08:22 -0800 (PST) Subject: Where to place imports In-Reply-To: <6tuamjFckgp0U1@mid.uni-berlin.de> References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <21628590.post@talk.nabble.com> So it isn't inefficient to import a bunch of modules that may not be used, say if only one function is used that doesn't rely on a larger module like numpy or pylab? Thanks. Diez B. Roggisch-2 wrote: > > John [H2O] schrieb: >> Hello, Im writing some modules and I am a little confused about where to >> place my imports... >> >> I don't really do any class programming yet, just defining a bunch of >> functions, so presently I have something along the lines of: >> >> import sys >> import os >> import traceback >> >> >> def Foo1(a,b): >> import numpy >> import datetime >> return c >> >> def Foo2(a,b): >> import datetime >> >> c = Foo1(a,b) >> return c >> >> etc... >> >> Above obviously just for the form, but the point is, in some cases I may >> import modules twice, but other times I may not use them at all, so >> should I >> import everything into the main module? Or individually import them into >> functions. Is there a performance penalty either way? > > Usually, you should import on the top of the module. That's the cleanest > way, and the most performant one. > > There is a small performance penalty when doing it inside functions - > but not too much. It boils down to a lookup if the imported module has > already been imported before. > > > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules, and certainly to avoid if possible. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21628590.html Sent from the Python - python-list mailing list archive at Nabble.com. From google at mrabarnett.plus.com Fri Jan 23 12:20:29 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 23 Jan 2009 17:20:29 +0000 Subject: Counter Class -- Bag/Multiset In-Reply-To: References: <8ea65249-cf2b-45f9-b906-89a998f75d0a@v15g2000vbb.googlegroups.com> Message-ID: <4979FC5D.6060807@mrabarnett.plus.com> Terry Reedy wrote: > bearophileHUGS at lycos.com wrote: > >> Also: what's the rationale of allowing negative values too? > > I can guess two: > 1) Nuisance to check given that Python does not have a count > (0,1,2...) type. > 2. Useful. + = items on hand; - = items back-ordered. Bank account go > negative also ;-). So does elevation. > Similarly, an app could set 0 to mean 'desired quantity on hand', so > non-zero count is surplus or deficit. > > I might not have thought to allow this, but it seems to open new > applications. (This definitely makes bag or multiset inappropriate > as names.) > I would've limited the counts to non-negative values too, but being able to store negative values does allow credit/debit or in-stock/on-order. In such cases, the name 'Counter' makes more sense. From yahoo at al-got-rhythm.net Fri Jan 23 12:46:48 2009 From: yahoo at al-got-rhythm.net (jalanb3) Date: Fri, 23 Jan 2009 17:46:48 -0000 Subject: Why is it faster the second time ? Message-ID: Hello the group, I am wondering why doctests run slower the first time. In the transcript below "try" is a script which finds and runs doctests in the current directory. It also shows how long it takes to run these tests. I added a new test which searches recursively for files given a path, and it took (approx) 3 seconds to run. But all subsequent runs take less than half a second. Am I right in thinking that the extra time on the first run is the time it takes to compile .py -> .pyc ? Transcript follows $ try paths.test try ./paths.test; 10 tests passed in 3 seconds 10 tests passed, 0 failed, in 3 seconds $ try paths.test try ./paths.test; 10 tests passed very quickly 10 tests passed, 0 failed, in 0 seconds $ try paths.test try ./paths.test; 10 tests passed very quickly 10 tests passed, 0 failed, in 0 seconds -- Alan From digitig at gmail.com Fri Jan 23 12:47:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 23 Jan 2009 17:47:18 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: 2009/1/23 Benjamin Kaplan : > BTW, he said sufficiently sophisticated topic. Since there hasn't been an > extremely long post here yet, I don't know if this counts. Had I waited until the thread became long enough, somebody else would have already raised the issue -- you must surely know about Schluehr's Law? ;-) -- Tim Rowe From BrianVanderburg2 at aim.com Fri Jan 23 12:51:03 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 12:51:03 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: References: Message-ID: <497A0387.40307@aim.com> unineuro at gmail.com wrote: > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) > > I've had a similar problem here and here is best how I can explain it. The prop in the lambda function is a closure by 'name' to the prop in the containing name space (__init__), so when the lambda function executes, it looks for the name 'prop' in this name space and uses it's value. After the 'for prop in props' loop is complete, 'prop' is left referring to the last item in props, so each lambda function would use it (mary) One solution is to not use lambda and avoid closures by using default arguments: for prop in props: def Getter(self=self, prop=prop): return getattr(self, '__' + prop[0]) setattr(self, '__' + prop[0], prop[1]) setattr(self, 'Get' + prop[0], Getter) I have several problems with this though: 1. I don't think this will invoke Pythons name mangling mechanism. The property will be '__name' and not '__Person_name'. 2. If you make a copy of the class, including attributes, the Getter will operate on the old class not new: Person a b = copy.copy(a) setattr(a, '__name', bob) setattr(b, '__name', sarah) b.Getname() -> bob In order to make it work, the class must support updating the Getter when it is copied to have a new self value. import copy class MethodCaller: def __init__(self, obj, method, name): self.obj = obj self.method = method self.name = name setattr(obj, name, self) def __call__(self, *args, **kwargs): return self.method(self.obj, *args, **kwargs) def copy(self, newobj): return MethodCaller(newobj, self.method, self.name) props = ( ('name', 'mary'), ('age', 21), ('gender', 'female') ) class Person: def __init__(self): self._methods = [] for prop in props: (name, value) = prop def getter(self, name=name): return getattr(self, '_' + name) setattr(self, '_' + name, value) self._methods.append(MethodCaller(self, getter, 'Get' + name)) def copy(self,copymethods=True): c = copy.copy(self) if copymethods: c._methods = [] for i in self._methods: c._methods.append(i.copy(c)) return c # Example without copying methods p = Person() q = p.copy(False) p._name = 'sarah' q._name = 'michelle' print p.Getname() print p.Getage() print p.Getgender() print q.Getname() # Still prints 'sarah', because getter still refers to 'p' instead of 'q' print q.Getage() print q.Getgender() # Example with copying methods p = Person() q = p.copy() p._name = 'sarah' q._name = 'michelle' print p.Getname() print p.Getage() print p.Getgender() print q.Getname() # Prints 'michelle' print q.Getage() print q.Getgender() From deets at nospam.web.de Fri Jan 23 12:52:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 18:52:13 +0100 Subject: Where to place imports In-Reply-To: References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <6tueedFbg9nsU1@mid.uni-berlin.de> John [H2O] schrieb: > So it isn't inefficient to import a bunch of modules that may not be used, > say if only one function is used that doesn't rely on a larger module like > numpy or pylab? Well, importing can take bit of time - but that's a short latency at startup-time, if anything. And if your module gets imported inside a function, it *is* used, isn't it? Diez From http Fri Jan 23 12:53:02 2009 From: http (Paul Rubin) Date: 23 Jan 2009 09:53:02 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <7xiqo57vup.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > Also, every object is mutable at some level. Tuples, ints and floats are > definitely mutable at creation time. You need to hold a mutex then, so > Carl's notion of three types of objects breaks down then. Hopefully, at creation time, they will usually be in a scope where other threads can't see them. From steve at holdenweb.com Fri Jan 23 13:01:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 13:01:44 -0500 Subject: Where to place imports In-Reply-To: <6tuamjFckgp0U1@mid.uni-berlin.de> References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: [...] > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules, and certainly to avoid if possible. > Well there is also the somewhat obscure point that an import of specific names inside a function makes them local, which *might* make a performance difference with tight loop nesting inside - though obviously the need for such will best be determined by benchmarking: >>> def f1(): ... from os.path import join ... print join ... >>> from os.path import join >>> def f2(): ... print join ... >>> dis.dis(f1) 2 0 LOAD_CONST 1 (-1) 3 LOAD_CONST 2 (('join',)) 6 IMPORT_NAME 0 (os.path) 9 IMPORT_FROM 1 (join) 12 STORE_FAST 0 (join) 15 POP_TOP 3 16 LOAD_FAST 0 (join) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_GLOBAL 0 (join) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE >>> Not a major issue, just another aspect of the question ... and of course the OP should take the advice already given unless and until performance becomes a problem (since it usually won't). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Fri Jan 23 13:04:42 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 23 Jan 2009 19:04:42 +0100 Subject: Where to place imports In-Reply-To: References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <6tuf5qFcnd2vU1@mid.uni-berlin.de> Steve Holden schrieb: > Diez B. Roggisch wrote: > [...] >> The only valid reason for doing imports inside functions is if you >> otherwise get into circular dependency hell, or have modules that need >> some manipulation of the sys.path before they actually can be imported. >> This is never true for system modules, and certainly to avoid if possible. >> > Well there is also the somewhat obscure point that an import of specific > names inside a function makes them local, which *might* make a > performance difference with tight loop nesting inside - though obviously > the need for such will best be determined by benchmarking: But that could be mitigated using aliasing, which is a more general optimization technique, as it works not only for imported names but also for e.g. bound methods, or any other chained lookups. Diez From kyrie at uh.cu Fri Jan 23 13:07:55 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 23 Jan 2009 13:07:55 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <200901231307.55379.kyrie@uh.cu> On Friday 23 January 2009 06:31:50 am Antoon Pardon wrote: > On 2009-01-16, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > >> If you "*shouldn't* mess with the implementation", then what is wrong > >> with enforcing that "shouldn't" in the language itself? > > > > Because, as a library user, it should be my power to chose when and how I > > _should_ mess with the implementation, not the compiler, and definitely > > not you. > > Why should it be in your power? By messing with the implementation of a > library you risk the correctness of the code of all participant coders in > that project. I not that sure it should be your power to chose when and how > to do that. Ok, let me fix that. It should be in _our_ power as the team of all participant coders on _our_ project to decide if we should mess with the internals or not. What makes no sense is that it should be in the original author's power to decide, if he is not part of _our_ team. Do you like it better now? Wasn't it obvious in the first place? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From duncan.booth at invalid.invalid Fri Jan 23 13:50:00 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Jan 2009 18:50:00 GMT Subject: Where to place imports References: <21627895.post@talk.nabble.com> <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: "John [H2O]" wrote: > So it isn't inefficient to import a bunch of modules that may not be > used, say if only one function is used that doesn't rely on a larger > module like numpy or pylab? > Not really. If you import it at all then you might as well import it on startup i.e. at the top of the module. Importing from inside a function doesn't free up the imported module when the function returns, so you aren't going to save any memory in the long run. I would accept that if you have a function that may not be called in most runs of the program, and that function uses some large module that wouldn't otherwise be loaded, then you might have a case for importing it only inside the function. But that's a very rare situation; otherwise, just import it at module scope. BTW, if you ever find you are starting to write multi-threaded applications then you'll really regret it if you reuse code which does imports from inside functions. If two or more threads try to import a module simultaneously then one of them might find it that not everything is defined in the module exists when it tries to use it. From rhamph at gmail.com Fri Jan 23 14:01:24 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Fri, 23 Jan 2009 11:01:24 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: On Jan 22, 11:09?pm, Carl Banks wrote: > On Jan 22, 9:38?pm, Rhamphoryncus wrote: > > > > > On Jan 22, 9:38?pm, Carl Banks wrote: > > > > On Jan 22, 6:00?am, a... at pythoncraft.com (Aahz) wrote: > > > > > In article <7xd4ele060.... at ruckus.brouhaha.com>, > > > > Paul Rubin ? wrote: > > > > > >alex23 writes: > > > > > >> Here's an article by Guido talking about the last attempt to remove > > > > >> the GIL and the performance issues that arose: > > > > > >> "I'd welcome a set of patches into Py3k *only if* the performance for > > > > >> a single-threaded program (and for a multi-threaded but I/O-bound > > > > >> program) *does not decrease*." > > > > > >The performance decrease is an artifact of CPython's rather primitive > > > > >storage management (reference counts in every object). ?This is > > > > >pervasive and can't really be removed. ?But a new implementation > > > > >(e.g. PyPy) can and should have a real garbage collector that doesn't > > > > >suffer from such effects. > > > > > CPython's "primitive" storage management has a lot to do with the > > > > simplicity of interfacing CPython with external libraries. ?Any solution > > > > that proposes to get rid of the GIL needs to address that. > > > > I recently was on a long road trip, and was not driver, and with > > > nothing better to do thought quite a bit about how this. > > > > I concluded that, aside from one major trap, it wouldn't really be > > > more difficult to inteface Python to external libraries, just > > > differently difficult. ?Here is briefly what I came up with: > > > > 1. Change the singular Python type into three metatypes: > > > immutable_type, mutable_type, and mutable_dict_type. ?(In the latter > > > case, the object itself is immutable but the dict can be modified. > > > This, of course, would be the default metaclass in Python.) ?Only > > > mutable_types would require a mutex when accessing. > > > > 2. API wouldn't have to change much. ?All regular API would assume > > > that objects are unlocked (if mutable) and in a consistent state. > > > It'll lock any mutable objects it needs to access. ?There would also > > > be a low-level API that assumes the objects are locked (if mutable) > > > and does not require objects to be consistent. ?I imagine most > > > extensions would call the standard API most of the time. > > > > 3. If you are going to use the low-level API on a mutable object, or > > > are going to access the object structure directly, you need to acquire > > > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK() > > > would be provided. > > > > 4. Objects would have to define a method, to be called by the GC, that > > > marks every object it references. ?This would be a lot like the > > > current tp_visit, except it has to be defined for any object that > > > references another object, not just objects that can participate in > > > cycles. ?(A conservative garbage collector wouldn't suffice for Python > > > because Python quite often allocates blocks but sets the pointer to an > > > offset within the block. ?In fact, that's true of almost any Python- > > > defined type.) ?Unfortunately, references on the stack would need to > > > be registered as well, so "PyObject* p;" might have to be replaced > > > with something like "Py_DECLARE_REF(PyObject,p);" which magically > > > registers it. ?Ugly. > > > > 5. Py_INCREF and Py_DECREF are gone. > > > > 6. GIL is gone. > > > > So, you gain the complexity of a two-level API, having to lock mutable > > > objects sometimes, and defining more visitor methods than before, but > > > you don't have to keep INCREFs and DECREFs straight, which is no small > > > thing. > > > > The major trap is the possibily of deadlock. ?To help minimize the > > > risk there would be macros to lock multiple objects at once. ?Py_LOCK2 > > > (a,b), which guarantess that if in another thread is calling Py_LOCK2 > > > (b,a) at the same time, it won't result in a deadlock. ?What's > > > disappointing is that the deadlocking possibility is always with you, > > > much like the reference counts are. > > > IMO, locking of the object is a secondary problem. ?Python-safethread > > provides one solution, but it's not the only conceivable one. ?For the > > sake of discussion it's easier to assume somebody else is solving it > > for you. > > That assumption might be good for the sake of the discussion *you* > want to have, but it's not for discussion I was having, which was to > address Aahz's claim that GIL makes extension writing simple by > presenting a vision of what Python might be like if it had a mark-and- > sweep collector. ?The details of the GC are a small part of that and > wouldn't affect my main point even if they are quite different than I > described. ?Also, extension writers would have to worry about locking > issues here, so it's not acceptable to assume somebody else will solve > that problem. > > > Instead, focus on just the garbage collection. > > [snip rest of threadjack] > > You can ignore most of what I was talking about and focus on > technicalities of garbage collection if you want to. ?I will not be > joining you in that discussion, however. > > Carl Banks I'm sorry, you're right, I misunderstood your context. From exarkun at divmod.com Fri Jan 23 14:03:41 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 14:03:41 -0500 Subject: Where to place imports In-Reply-To: Message-ID: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> On 23 Jan 2009 18:50:00 GMT, Duncan Booth wrote: > [snip] > >BTW, if you ever find you are starting to write multi-threaded applications >then you'll really regret it if you reuse code which does imports from >inside functions. If two or more threads try to import a module >simultaneously then one of them might find it that not everything is >defined in the module exists when it tries to use it. What makes you say this? There is an import lock (beyond the GIL) which should prevent a thread from ever seeing a partially initialized module. Jean-Paul From grflanagan at gmail.com Fri Jan 23 14:10:39 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Fri, 23 Jan 2009 11:10:39 -0800 (PST) Subject: writing pickle function References: Message-ID: <27ff47f8-6ba3-4b91-9b6e-6b25a272cb60@r15g2000prh.googlegroups.com> On Jan 23, 2:48?pm, perfr... at gmail.com wrote: > hello, > > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. > > thank you. One way via a subclass: (from memory) class MyCollection(defaultdict): def __init__(self): defaultdict.__init__(self, list) def __reduce__(self): return (MyCollection, (), None, None, self.iteritems()) and if you are so inclined (nothing to do with pickling): __setattr__ = defaultdict.__setitem__ __getattr__ = defaultdict.__getitem__ G. From aquil.abdullah at gmail.com Fri Jan 23 14:19:07 2009 From: aquil.abdullah at gmail.com (aha) Date: Fri, 23 Jan 2009 11:19:07 -0800 (PST) Subject: Parsing XML: SAX, DOM, Expat, or Something Else? Message-ID: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Hello All, I've been charged with developing an XML configuration file format, for one of the applications that my company develops. (Yes, I know it would have been easier to just use the configuration file format as described in RFC 822) While I am finally comfortable with the XML description that we've agreed upon; I am still trying to determine the best XML parser API to use. I would love to use XPATH, however I face the following restriction: The Python scripts that perform the parsing of the XML configuration file must be compatible with Python Versions 2.2-present. This means that any functionality that I use needs to be compatible with Python 2.2. I started with the DOM API in xml.dom.minidom and I thought that it might be the best way to go, but then I ran across the Recipes of Wai Yip Tung http://code.activestate.com/recipes/534109/ and John Bair, Christoph Dietze from the second edition of the Python cookbook. Wai's implementation uses thes SAX parser and John and Christoph's implementation uses Expat API. In the end what I really want is to transform the XML into an object that looks like config.component.setting or a map config[component][setting]. Another restriction is that I don't want to have to ship additional modules. Does anyone have any advice, comments, or HELP??? Aquil H. Abdullah Developer From hniksic at xemacs.org Fri Jan 23 14:19:35 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 23 Jan 2009 20:19:35 +0100 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> Message-ID: <87ljt1g794.fsf@mulj.homelinux.net> Carl Banks writes: > Unfortunately, references on the stack would need to be registered > as well, so "PyObject* p;" might have to be replaced with something > like "Py_DECLARE_REF(PyObject,p);" which magically registers it. > Ugly. Not only registered at the beginning of the function, but also (since CPython uses C, not C++) explicitly unregistered at every point of exit from the function. Emacs implements these as macros called GCPRO and UNGCPRO, and they're very easy to get wrong. In a way, they are even worse than the current Python INCREF/DECREF. See description at, for example, http://www.xemacs.org/Documentation/beta/html/internals_19.html#SEC78 From xahlee at gmail.com Fri Jan 23 14:19:58 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 23 Jan 2009 11:19:58 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems Message-ID: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> recently, as you might have noted by a previous post of mine, that American Mathematical Society published a series of articles on formal proofs in 2008 November. See: http://www.ams.org/notices/200811/ The articles are: ? Formal Proof by Thomas Hales ? Formal Proof ? The Four-Color Theorem by Georges Gonthier ? Formal Proof ? Theory and Practice by John Harrison ? Formal Proof ? Getting Started by Freek Wiedijk I read 3 of them in December (only scanned the four-color theorem one). It was quite a fantastically enjoyable reading. ( For some personal notes, see: Current State Of Theorem Proving Systems at the bottom of ? The Codification of Mathematics http://xahlee.org/cmaci/notation/math_codify.html ) As you may know, codification of math has been a long personal interest. In fact, my logical analytic habit has made me unable to read most math texts, which are full of logical errors and relies on a ?human? interpretation for its soundness and clarity. having read those intro articles from the AMS publication on current state of the art, i decided that i'm going to learn HOL Light. (tried to learn Coq before and the tutorial is problematic) One of the interesting finding was that almost all theorem proving systems are written in ML family lang, e.g. Caml, Ocaml. Of course, i heard of Ocaml since about 1998 when i was doing Scheme. Somehow it never impressed me from reading the functional programing FAQ. I have always been attracted more to Haskell, perhaps only because it is _pure_ in the sense of not allowing assignment. With that, ocaml has been ?just another functional lang? in my mind. But now, seeing that most theorem proving systems used in the real world are in Caml, thus i made start to learn Ocaml now. (in fact, its root is a theorem prover) i wanted to add proofs as enhancement to my A Visual Dictionary Of Special Plane Curves. Also, had ambition to write more... about algebraic geometry and differential geometry and geometry with complex numbers. Proofs will be major part of these type of works. I can no longer tolerate traditional mouthy written-english proofs. They must be codified proofs. In this: HOL Light Tutorial (for version 2.20) by John Harrison September 9, 2006, there's this paragraph: ?This fits naturally with the view, expressed for example by Dijkstra (1976), that a programming language should be thought of first and foremost as an algorithm-oriented system of mathematical notation, and only secondarily as something to be run on a machine.? Wee! That has been my view since about 1997. The only lang that adhere to that view i know of is Mathematica. (lisping morons don't understand a iota of it. See: ? Is Lisp's Objects Concept Necessary? http://xahlee.org/emacs/lisps_objects.html ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html ) btw, anyone know the source of that Dijkstra quote? Xah ? http://xahlee.org/ ? From clp2 at rebertia.com Fri Jan 23 14:25:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 11:25:30 -0800 Subject: Parsing XML: SAX, DOM, Expat, or Something Else? In-Reply-To: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> References: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Message-ID: <50697b2c0901231125j78c4806j61803a6d1735c348@mail.gmail.com> On Fri, Jan 23, 2009 at 11:19 AM, aha wrote: > Hello All, > I've been charged with developing an XML configuration file format, > for one of the applications that my company develops. (Yes, I know it > would have been easier to just use the configuration file format as > described in RFC 822) While I am finally comfortable with the XML > description that we've agreed upon; I am still trying to determine the > best XML parser API to use. I would love to use XPATH, however I face > the following restriction: > > The Python scripts that perform the parsing of the XML configuration > file must be compatible with Python Versions 2.2-present. > > This means that any functionality that I use needs to be compatible > with Python 2.2. > > I started with the DOM API in xml.dom.minidom and I thought that it > might be the best way to go, but then I ran across the Recipes of Wai > Yip Tung > > http://code.activestate.com/recipes/534109/ > > > and John Bair, Christoph Dietze from the second edition of the Python > cookbook. > > Wai's implementation uses thes SAX parser and John and Christoph's > implementation uses Expat API. > > In the end what I really want is to transform the XML > > > > > > > > into an object that looks like > > config.component.setting or a map config[component][setting]. > > Another restriction is that I don't want to have to ship additional > modules. > > Does anyone have any advice, comments, or HELP??? ElementTree is in the std lib for Python 2.5+ and has a fairly Pythonic API compared to SAX/DOM. Docs for it: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Fri Jan 23 14:37:14 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:37:14 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <7xzlhmthz1.fsf@ruckus.brouhaha.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <0189b204$0$20671$c3e8da3@news.astraweb.com> Message-ID: <87pridddat.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > You've built something full of user serviceable parts. You've > insisted, publicly and loudly, that the ability to modify those parts > is absolutely essential, you've rejected every effort to lock down > those internals, and then when somebody does exactly what you > encourage, you suddenly turn on them and say they're on their own. > > That's pretty irresponsible behaviour. An egregious mischaracterization. Again, you're refusing to see the distinction between a published, stable interface, and exposed but potentially volatile internals. If you use my published interface and your program is broken by a change, it's my fault and I try to fix it; if you use the internals and your program's broken by a change, it's your fault and you're on your own. It's pretty easy. There are three possibilities: * The interface does what I want it to do. Cool. I win. * The interface doesn't do what I want it to do, but I can hack the internal guts until it does. Cool for now, but I might get screwed later if they change. Well, it's something to think about. * The interface doesn't do what I want it to do, and I can't hack the internal guts. I just lose. If all interfaces were perfect, there wouldn't be an argument. But they aren't. So we're sometimes left with the other two choices. Which one looks more appealing to you? -- [mdw] From stefan_ml at behnel.de Fri Jan 23 14:38:55 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jan 2009 20:38:55 +0100 Subject: Parsing XML: SAX, DOM, Expat, or Something Else? In-Reply-To: References: <5e01ea81-c984-4fa8-ad9b-909623ac8a91@e22g2000vbe.googlegroups.com> Message-ID: <497a1cd0$0$30227$9b4e6d93@newsspool1.arcor-online.net> Chris Rebert wrote: > On Fri, Jan 23, 2009 at 11:19 AM, aha wrote: >> I've been charged with developing an XML configuration file format, >> for one of the applications that my company develops. >> [...] >> I am still trying to determine the >> best XML parser API to use. I would love to use XPATH, however I face >> the following restriction: >> >> The Python scripts that perform the parsing of the XML configuration >> file must be compatible with Python Versions 2.2-present. > > ElementTree is in the std lib for Python 2.5+ and has a fairly > Pythonic API compared to SAX/DOM. > Docs for it: http://docs.python.org/library/xml.etree.elementtree.html The downloadable package (version 1.2.x) still works with Python 2.2 (last I heard, at least). ET also has simple support for XPath-like expressions (without conditions, that is). Starting to use it now will however allow you to switch to the mostly compatible lxml.etree package once you decide to move on to Python 2.3 or later. lxml has full support for XPath (and XSLT and tons of other goodies). Stefan From Scott.Daniels at Acm.Org Fri Jan 23 14:40:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 11:40:33 -0800 Subject: what gives with In-Reply-To: References: Message-ID: Darren Dale wrote: > .... What is the point of providing absolute_import in __future__ if the > api is completely different than the implementation in future python versions? The point is to obtain user experience with a proposed feature _before_ you fix the interface and start having to be "backward compatible." --Scott David Daniels Scott.Daniels at Acm.Org From mdw at distorted.org.uk Fri Jan 23 14:41:31 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:41:31 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <87y6x2cih0.fsf.mdw@metalzone.distorted.org.uk> <1c99aef0-a4fa-4b8a-a0e2-1ba59bf5f703@i24g2000prf.googlegroups.com> Message-ID: <87ljt1dd3o.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Was this library module released in source form? > > If so, then why would you care that it has enforced access > restrictions? You can just take them out, then do whatever you would > have done had they not been there to start with. I don't see how that > is any more work than figuring out what internals you need to access. > Either way you need to read and understand the code. I could do. But in practice internal details often aren't horrifically unstable. If I fork the library, I've now got to mess with distributing the forked version, and keeping the patch up to date -- the codebase is likely to be much more volatile than the internals I'm hacking on. It's just not such a good tradeoff. See elsewhere where I described hacking Python's `long' representation. You'd have me fork the Python interpreter. That doesn't seem like a win to me. > Wait ... it wasn't released in source form? Then how would you even > know what internals you need to access? We call them `disassemblers' and `debuggers'. Sometimes even simple experimentation is sufficient. > And why would you use something that goes against your philosophy of > openness anyway? I try not to. Sometimes I fail. -- [mdw] From Scott.Daniels at Acm.Org Fri Jan 23 14:45:08 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 11:45:08 -0800 Subject: Adding a field to a 'foreign' object from the outside In-Reply-To: References: <82ec75eb-c32e-4477-a415-d59a4b9ed49f@x16g2000prn.googlegroups.com> Message-ID: Steve Holden wrote: > .... Write a class that implements a __call__() method, and use an instance > of that class as your callback. Then the data can be stored as the callback > object's private instance data. In fact, you needn't name the method __call__. You can pass in Holder().method if you have no other use for the instance of your Holder instance. --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Fri Jan 23 14:45:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 11:45:50 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <214c2ed9-2181-4261-ba8e-5044daed9d61@w24g2000prd.googlegroups.com> On Jan 23, 7:33?am, s... at pobox.com wrote: > ? ? >> You mean every time you access a list or dictionary or class > ? ? >> instance, you have to acquire a mutex? ?That sounds like a horrible > ? ? >> slowdown. > > ? ? Steve> Indeed it would, but hey, let's not let that stop us repeating > ? ? Steve> the thinking that's gone into CPython over the last fifteen > ? ? Steve> years. "Those who cannot remember the past are condemned to > ? ? Steve> repeat it". > > Also, every object is mutable at some level. ?Tuples, ints and floats are > definitely mutable at creation time. ?You need to hold a mutex then, so > Carl's notion of three types of objects breaks down then. immutable_type objects wouldn't exist at all until their PyWhatever_New or their tp_new member is called. After that, the reference exists only on the local stack, which is accessible only to one thread. As long as you finish initializing the object while it's still only on the stack, there is no possibility of a conflict. What about tp_init, then, you ask? Well it's simple: immutable_type doesn't call it. In fact, it requires that tp_init, tp_setattro, tp_mapping->mp_setitem, etc., are all null. immutable_obejcts have no instance dict, so if you want to create attributes in Python you have to use slots. immutable_object.__new__ accepts keyword arguments and initializes the slots with the value. class Record(immutable_object,slots=['name','number']): def __new__(cls,name): number = db.lookup_number(name) immutable_object.__new__(cls,name=name,number=number) Carl Banks From __peter__ at web.de Fri Jan 23 14:46:27 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jan 2009 20:46:27 +0100 Subject: writing pickle function References: Message-ID: perfreem at gmail.com wrote: > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pickle file, it says: > > TypeError: can't pickle function objects > > is there a way around this? it's simply a dictionary that i want to > write to file.. this works no problems with ordinary dicts. The error message is misleading. You can pickle your defaultdict if you use a "normal" function instead of the lambda: $ cat pickle_defaultdict.py import sys from collections import defaultdict from cPickle import dumps, loads if "--lambda" in sys.argv: make_inner = lambda: defaultdict(list) else: def make_inner(): return defaultdict(list) d = defaultdict(make_inner) d[1][2].append(42) e = loads(dumps(d)) print e == d $ python pickle_defaultdict.py True $ python pickle_defaultdict.py --lambda Traceback (most recent call last): File "pickle_defaultdict.py", line 13, in e = loads(dumps(d)) File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle function objects Peter From mdw at distorted.org.uk Fri Jan 23 14:47:29 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:47:29 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <87hc3pdctq.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > OK, fine, you can change the code of another member of the team. Are > you going to check with him first, or just do it? The point is that > changing an interface requires agreement of the team members who use > that interface, whether on the calling or the implementation side of > it. If you change interfaces without getting agreement with the other > team members, you probably won't be on the team for long. So far, so good. > And without access restrictions, accessing _private is equivalent to > changing the interface. You've basically unilaterally stretched it, yes. Programmers who do this when the implementer of the interface is three feet away deserve to get smacked. If you don't have an easy way to get the interface extended, you have a pleasant choice between hacking at the guts and just being screwed. Have a nice day. > On Jan 23, 4:57?am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, kind >> of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? If you're working with developers you don't trust, you're going to lose anyway. -- [mdw] From mdw at distorted.org.uk Fri Jan 23 14:50:36 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 19:50:36 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> Message-ID: <87d4eddcoj.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > Annotations *have* made it into 3.0, so it's possible that the might > become usable. Remember, they'll always be optional, so those who don't > want to use them won't lose anything at all. There's a problem here. An interface has two sides. Access control annotations, as far as I've seen so far, look like they're only optional on one side: that is, once specified on the implementation side, they have a mandatory effect on the user side. -- [mdw] From gerald.britton at gmail.com Fri Jan 23 14:58:34 2009 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 23 Jan 2009 14:58:34 -0500 Subject: is None vs. == None Message-ID: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> Hi -- Some time ago I ran across a comment recommending using is None instead of == None (also is not None, etc.) My own testing indicates that the former beats the latter by about 30% on average. Not a log for a single instruction but it can add up in large projects. I'm looking for a (semi)-official statement on this, but couldn't find one with normal googling. Can someone please send a link? From steve at holdenweb.com Fri Jan 23 14:59:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 14:59:46 -0500 Subject: writing pickle function In-Reply-To: References: Message-ID: Peter Otten wrote: > perfreem at gmail.com wrote: > >> i am using nested defaultdict from collections and i would like to >> write it as a pickle object to a file. when i try: >> >> from collections import defaultdict >> x = defaultdict(lambda: defaultdict(list)) >> >> and then try to write to a pickle file, it says: >> >> TypeError: can't pickle function objects >> >> is there a way around this? it's simply a dictionary that i want to >> write to file.. this works no problems with ordinary dicts. > > The error message is misleading. You can pickle your defaultdict if you use > a "normal" function instead of the lambda: > > $ cat pickle_defaultdict.py > import sys > from collections import defaultdict > from cPickle import dumps, loads > > if "--lambda" in sys.argv: > make_inner = lambda: defaultdict(list) > else: > def make_inner(): > return defaultdict(list) > > d = defaultdict(make_inner) > d[1][2].append(42) > e = loads(dumps(d)) > print e == d > > $ python pickle_defaultdict.py > True > $ python pickle_defaultdict.py --lambda > Traceback (most recent call last): > File "pickle_defaultdict.py", line 13, in > e = loads(dumps(d)) > File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex > raise TypeError, "can't pickle %s objects" % base.__name__ > TypeError: can't pickle function objects > But can you unpickle the objects you pickle? I believe that functions are references relative to the modules they come from, and so won't be found unless the same module can be imported at unpickle time. Could be wrong, haven't read the source, but I understand that functions work the same as classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 15:01:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 15:01:39 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <6ce575b3-58e5-41ca-b3af-4537d764015d@r28g2000vbp.googlegroups.com> Message-ID: Rhamphoryncus wrote: [... eighty-eight quoted lines ...] > > I'm sorry, you're right, I misunderstood your context. Perhaps you could trim your posts to quote only the relevant context? Thanks. -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Fri Jan 23 15:02:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 12:02:38 -0800 Subject: is None vs. == None In-Reply-To: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> Message-ID: <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> On Fri, Jan 23, 2009 at 11:58 AM, Gerald Britton wrote: > Hi -- Some time ago I ran across a comment recommending using is > None instead of == None (also is not None, etc.) My own > testing indicates that the former beats the latter by about 30% on > average. Not a log for a single instruction but it can add up in > large projects. > > I'm looking for a (semi)-official statement on this, but couldn't find > one with normal googling. Can someone please send a link? >From http://www.python.org/dev/peps/pep-0008/ , 2nd bullet under "Programming Recommendations": - Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Just FYI, `is` compares object identity (pointer equality) whereas == checks for value equivalence (which causes a method call). This is why it's significantly faster. But the main reason is because it's idiomatic. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mdw at distorted.org.uk Fri Jan 23 15:09:48 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 23 Jan 2009 20:09:48 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> Message-ID: <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >> Why on earth couldn't I change the code of another member of my team if >> that code needs changes ? The code is the whole team's ownership. > > That's a model that works well when you have a small team of, say, a > dozen people. It's not a model that works when you have hundreds of > developers working on the project. The last thing I want in my projects > is cowboys who ride all over other people's code, changing internals of > parts they barely know at the drop of a hat, causing who knows what side- > effects. Why are you assuming that Bruno would make his change in such an irresponsible manner? Such things need discussing, with some appropriate level of formality, with the people most involved with the relevant code -- which might be anything between a quick chat with the bloke across the room or an agenda item on the next team meeting to a written proposal. Given your apparent readiness to assume the worst of programmers at every opportunity (e.g., your above assumption that Bruno would change code unilaterally and secretly, assumptions elsewhere that programmers treat any exposed wiring as being published interface), I can only assume that you really need to get some better cow-orkers. > But anyway, this is a red-herring. Data hiding isn't really about > managing the development process, it's about ensuring that when you and > Fred are using Barney's OrderedDict class in your code, Barney is free to > change his the implementation without your code suddenly failing. It's > also to ensure that any changes you make at runtime to the class don't > suddenly make Fred's code break. If Barney, Fred and I share a room, we can discuss what we need from OrderedDict around the water-cooler. If we're all in different continents, the tradeoffs look different. If Barney's the kind of guy with quick turnaround, I might well just ask for the necessary change. If I'll have to wait for the next release in July (for posterity: it's January now) I'll probably hack the guts now. If I do that, Barney's still free to change his implementation. It might screw me, but that's my problem and not his; the alternative, with mandatory `hiding', is that I just lose: possible breakage down the line looks like an improvement. Now we come on to Fred. If Fred's across the room from me then we're back to the water-cooler. If he's on a different continent, and I know he'll be affected, I'll probably email him. If I've never heard of him at all, well, he might just lose when someone puts my code and Fred's together with OrderedDict; hopefully I'll get a bug report (I ought to have put a notice in with my distribution explaining that it uses undocumented internals of OrderedDict, so I should be in the firing line) and we'll sort through the wreckage. But again, if I just lost in the second paragraph, we wouldn't even have got this far. -- [mdw] From benjamin at python.org Fri Jan 23 15:28:13 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 20:28:13 +0000 (UTC) Subject: what gives with References: Message-ID: Darren Dale gmail.com> writes: > I was talking about the behavior after doing "from __future__ import > absolute_import". I've been developing on python-2.6 using > absolute_import for weeks, knowing that I could do "from __future__ > import absolute import" on python-2.5. Now when I try to use > python-2.5 I cant import my package. What is the point of providing > absolute_import in __future__ if the api is completely different than > the implementation in future python versions? Its bizarre. The API is not completely different. The 2.5 version of the feature just lacks the ability to import with "*". It is still same in 2.6, but with the ability to use "*". From steve at holdenweb.com Fri Jan 23 15:28:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 15:28:38 -0500 Subject: is None vs. == None In-Reply-To: <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Jan 23, 2009 at 11:58 AM, Gerald Britton > wrote: >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in >> large projects. >> >> I'm looking for a (semi)-official statement on this, but couldn't find >> one with normal googling. Can someone please send a link? > >>From http://www.python.org/dev/peps/pep-0008/ , > 2nd bullet under "Programming Recommendations": > > - Comparisons to singletons like None should always be done with > 'is' or 'is not', never the equality operators. > > > Just FYI, `is` compares object identity (pointer equality) whereas == > checks for value equivalence (which causes a method call). This is why > it's significantly faster. > But the main reason is because it's idiomatic. > And, just for completeness, the "is" test is canonical precisely because the interpreter guarantees there is only ever one object of type None, so an identity test is always appropriate. Even the copy module doesn't create copies ... >>> import copy >>> n = copy.copy(None) >>> id(n) 1555754480 >>> id(None) 1555754480 >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin at python.org Fri Jan 23 15:31:08 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 23 Jan 2009 20:31:08 +0000 (UTC) Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano REMOVE-THIS-cybersource.com.au> writes: > > I'm interested in this ticket in the bug tracker: > > http://bugs.python.org/issue2527 > > but it seems to have been stalled for nine months. Is there a procedure > for starting it up again? Should I ask about it on the python-dev mailing > list, or just wait until somebody happens to notice it? Nobody is likely to notice it unless someone pushes forward with it. Non release critical bug reports and feature requests tend to fall down a black hole after about a week. From toby at tobiah.org Fri Jan 23 15:37:30 2009 From: toby at tobiah.org (Tobiah) Date: Fri, 23 Jan 2009 12:37:30 -0800 Subject: unzip array of arrays? References: Message-ID: On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: > On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: >> Although it's trivial to program, I wondered whether >> there was a builtin or particularly concise way to >> express this idea: >> >>> a = [(1, 2), (3, 4), (5, 6)] >>> field[a, 2] >> [2, 4, 6] >> >> where field() is some made up function. > > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> a= [(1, 2), (3, 4), (5, 6)] >>>> zip(*a) > [(1, 3, 5), (2, 4, 6)] >>>> zip(*a)[1] > (2, 4, 6) That would be what I was after. Where can I read about this mysterious use of the '*'? It only works in the context of the zip() function. It's hard to understand how the interpreter handles that. Thanks, Toby From clp2 at rebertia.com Fri Jan 23 15:44:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jan 2009 12:44:36 -0800 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: <50697b2c0901231244x490e525wa3913e4f8b322df@mail.gmail.com> On Fri, Jan 23, 2009 at 12:37 PM, Tobiah wrote: > On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: > >> On Thu, Jan 22, 2009 at 2:04 PM, Tobiah wrote: >>> Although it's trivial to program, I wondered whether >>> there was a builtin or particularly concise way to >>> express this idea: >>> >>>> a = [(1, 2), (3, 4), (5, 6)] >>>> field[a, 2] >>> [2, 4, 6] >>> >>> where field() is some made up function. >> >> Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) >> [GCC 4.0.1 (Apple Inc. build 5484)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> a= [(1, 2), (3, 4), (5, 6)] >>>>> zip(*a) >> [(1, 3, 5), (2, 4, 6)] >>>>> zip(*a)[1] >> (2, 4, 6) > > That would be what I was after. Where can I read about > this mysterious use of the '*'? It only works in the > context of the zip() function. It's hard to understand > how the interpreter handles that. It works in all functions. Basically: f(*[1,2,3]) === f(1,2,3) I'm sure someone will also point out the docs. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From martin.hellwig at dcuktec.org Fri Jan 23 15:46:57 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 23 Jan 2009 20:46:57 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: <497a2cce$0$183$e4fe514c@news.xs4all.nl> Tim Rowe wrote: > 2009/1/23 Kay Schluehr : >> Whatever sufficiently sophisticated topic was the initially discussed >> it ends all up in a request for removing reference counting and the >> GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. > Perhaps, but you could also say that if it was that widely discussed and still not changed that it was for a *good* reason, perhaps the reason may change over time but at this moment it is still a good reason. Or you can argue that even when an argument is repeated indefinitely it doesn't make it suddenly right. -- mph From Scott.Daniels at Acm.Org Fri Jan 23 15:47:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 23 Jan 2009 12:47:00 -0800 Subject: seeking to improve Python skills In-Reply-To: References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: mk wrote: > Jean-Paul Calderone wrote: > >> The most significant thing missing from this code is unit tests. >> Developing automated tests for your code will help you learn a lot. > > However, unit tests are a tougher cookie, do you have any resource > that's truly worth recommending for learning unit tests? The only > resource I found that was talking at some length about it was "Dive into > Python" and I was wondering if there's anything better out there... Do the "Dive In" thing. You'll quickly develop instincts. Start with the simplest possible test of your function, run it, and fix your code until it passes. Add another test, and loop. The simplest possible test will unfortunately need a bit of bolerplate, but adding tests is easy. to start: import unittest import moving_average as ma class MovingAverageTest(unittest.TestCase): def test_simplest(self): 'Check the mechanics of getting a simple result' self.assertEqual(ma.moving_average(3, []), []) if __name__ == '__main__': unittest.main() Once that works, add another test: def test_simple(self): self.assertAlmostEqual(ma.moving_average(3, [1, 2, 3]), [2]) Once that works, check something a bit easier to get wrong: def test_floating(self): 'Check we have reasonable results' self.assertAlmostEqual(ma.moving_average(3, [1, 1, 3])[0], 1.6666667) and, as they so often say, "lather, rinse, repeat." --Scott David Daniels Scott.Daniels at Acm.Org From rdcollum at gmail.com Fri Jan 23 15:48:29 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 23 Jan 2009 12:48:29 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: > And, just for completeness, the "is" test is canonical precisely because > the interpreter guarantees there is only ever one object of type None, > so an identity test is always appropriate. Even the copy module doesn't > create copies ... > Does the interpreter guarantee the same for False and True bools? From tjreedy at udel.edu Fri Jan 23 16:06:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 16:06:00 -0500 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> Message-ID: Tim Rowe wrote: > 2009/1/23 Kay Schluehr : >> Whatever sufficiently sophisticated topic was the initially discussed >> it ends all up in a request for removing reference counting and the >> GIL. > > Well, maybe, but it seems to me that the real issue here is that we > need to remove reference counting and the GIL. Guido will give up reference counting and the consequent immediate gc when but only when *someone* presents an implementation that does and and that runs faster. Given the current ferment in dynamic language implementation, he just today wrote on pydev list "CPython's implementation strategy *will* evolve". Whether that means R.C. goes away or not remains to be seen. From tjreedy at udel.edu Fri Jan 23 16:16:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 16:16:57 -0500 Subject: unzip array of arrays? In-Reply-To: References: Message-ID: Tobiah wrote: > On Thu, 22 Jan 2009 14:13:34 -0800, Chris Rebert wrote: >>>>> zip(*a)[1] >> (2, 4, 6) > > That would be what I was after. Where can I read about > this mysterious use of the '*'? Python Symbol Glossary lists uses of all symbols. http://code.google.com/p/xploro/downloads/list From http Fri Jan 23 16:28:22 2009 From: http (Paul Rubin) Date: 23 Jan 2009 13:28:22 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7x3af91zm1.fsf@ruckus.brouhaha.com> Mark Wooding writes: > Now we come on to Fred. If Fred's across the room from me then we're > back to the water-cooler. If he's on a different continent, and I know > he'll be affected, I'll probably email him. If I've never heard of him > at all, well, he might just lose when someone puts my code and Fred's > together with OrderedDict... In a large project, more probably you'd enter a change request into some kind of tracking system, there would be discussion in the tracking system about how to do the change; perhaps at your weekly staff meeting you might bring up the issue with your PHB if you were blocking on the issue, and your PHB would bring it up at the inter-PHB meeting with Fred's PHB to bump the item's priority, and eventually Fred would check in a change and you would use it. There is necessarily some wasted motion in any organization of that size; good management is about keeping the friction to a minimum and getting the stuff done. From jason.scheirer at gmail.com Fri Jan 23 16:40:51 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 23 Jan 2009 13:40:51 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> On Jan 23, 12:48?pm, Roger wrote: > > And, just for completeness, the "is" test is canonical precisely because > > the interpreter guarantees there is only ever one object of type None, > > so an identity test is always appropriate. Even the copy module doesn't > > create copies ... > > Does the interpreter guarantee the same for False and True bools? Yes. I know that there are the PyObject* structs defined for you Py_True, Py_False and Py_None in the C level. Confusingly enough, the integers -5 through 257 are also singletons where the is test will work, but any int out of that range will not. >>> def copy_id(x): ... id1, id2 = id(x), id(copy.deepcopy(x)) ... print "Equal: %x %s %x" % (id1, ('==' if id1 == id2 else '! ='), id2) ... ... >>> copy_id(a()) Equal: a8fc90 != f32370 >>> copy_id(1) Equal: 9559c8 == 9559c8 >>> copy_id(None) Equal: 1e1da9f0 == 1e1da9f0 >>> copy_id(True) Equal: 1e1c5ec4 == 1e1c5ec4 >>> copy_id(False) Equal: 1e1c5eb8 == 1e1c5eb8 >>> copy_id("Hello") Equal: 1058840 == 1058840 >>> copy_id([]) Equal: 1067030 != 10673f0 ... large equal integers are not identical in memory location ... In [34]: x = 19591 In [35]: y = 19590+1 In [36]: id(x), id(y) Out[36]: (17937008, 17936588) ... but small ones are ... In [40]: x = 2 In [41]: y = 1+1 In [42]: id(x), id(y) Out[42]: (9787836, 9787836) From lists at cheimes.de Fri Jan 23 16:49:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 22:49:34 +0100 Subject: Where to place imports In-Reply-To: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> References: <20090123190341.24460.1751095702.divmod.quotient.533@henry.divmod.com> Message-ID: Jean-Paul Calderone schrieb: >> BTW, if you ever find you are starting to write multi-threaded >> applications >> then you'll really regret it if you reuse code which does imports from >> inside functions. If two or more threads try to import a module >> simultaneously then one of them might find it that not everything is >> defined in the module exists when it tries to use it. > > What makes you say this? There is an import lock (beyond the GIL) which > should prevent a thread from ever seeing a partially initialized module. Partially initialized modules aren't the issue here. One can easily create a dead lock situation with a mix of threads and imports. Example: * module 'mod_a' is imported [import lock is acquired] * module 'mod_a' spawns a new thread * the new thread tries to import another module 'mod_b' Python dead locks here and there is no chance to resolve the lock. The import of 'mod_b' is waiting for the first import. The first import hasn't finished because it's still executing the body of 'mod_a'. In order to avoid the situation you *must* never import a module in a thread other than the main thread. You should never start a thread in the body of a submodule, too. A large application should import all its modules first and then create its threads. If you really need to import a module from a sub thread or a method that might be called from a sub thread then you should use the C function PyImport_ImportModuleNoBlock() or use sys.modules and imp.lock_held(). Christian From sjmachin at lexicon.net Fri Jan 23 16:53:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 23 Jan 2009 13:53:25 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> On Jan 24, 7:48?am, Roger wrote: > > And, just for completeness, the "is" test is canonical precisely because > > the interpreter guarantees there is only ever one object of type None, > > so an identity test is always appropriate. Even the copy module doesn't > > create copies ... > > Does the interpreter guarantee the same for False and True bools? Why do you think it matters? Consider the circumstances under which you would use each of the following: if some_name == True: if some_name is True: if some_name: From lists at cheimes.de Fri Jan 23 16:53:39 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 22:53:39 +0100 Subject: is None vs. == None In-Reply-To: <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <3cade329-1485-45f1-a637-c18affe06b2c@40g2000prx.googlegroups.com> Message-ID: Jason Scheirer schrieb: > Yes. I know that there are the PyObject* structs defined for you > Py_True, Py_False and Py_None in the C level. Confusingly enough, the > integers -5 through 257 are also singletons where the is test will > work, but any int out of that range will not. Small ints are cached. You should use "is True" or "is False" in Python 2.x because user can overwrite the True and False objects. In Python 3.0 both True and False are truly immutable and global singletons -- and keywords, too. The mutable nature of the name "True" makes a "while True:" loop sightly slower than a "while 1:" loop, too. Python 2.5: >>> None = 1 File "", line 1 SyntaxError: assignment to None >>> True = 1 >>> Python 3.0 >>> True = 1 File "", line 1 SyntaxError: assignment to keyword >>> None = 1 File "", line 1 SyntaxError: assignment to keyword From lists at cheimes.de Fri Jan 23 17:07:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jan 2009 23:07:41 +0100 Subject: is None vs. == None In-Reply-To: <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> Message-ID: John Machin schrieb: > On Jan 24, 7:48 am, Roger wrote: >>> And, just for completeness, the "is" test is canonical precisely because >>> the interpreter guarantees there is only ever one object of type None, >>> so an identity test is always appropriate. Even the copy module doesn't >>> create copies ... >> Does the interpreter guarantee the same for False and True bools? > > Why do you think it matters? Consider the circumstances under which > you would use each of the following: > if some_name == True: > if some_name is True: > if some_name: The three lines translate (roughly) into: if some_name.__eq__(True): if id(some_name) == id(True): if some_name.__nonzero__(): # may check for __len__() != 0, too. In almost every case (99.99%) you want the last variant. The second variant From __peter__ at web.de Fri Jan 23 17:22:12 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jan 2009 23:22:12 +0100 Subject: writing pickle function References: Message-ID: Steve Holden wrote: > Peter Otten wrote: >> perfreem at gmail.com wrote: >> >>> i am using nested defaultdict from collections and i would like to >>> write it as a pickle object to a file. when i try: >>> >>> from collections import defaultdict >>> x = defaultdict(lambda: defaultdict(list)) >>> >>> and then try to write to a pickle file, it says: >>> >>> TypeError: can't pickle function objects >>> >>> is there a way around this? it's simply a dictionary that i want to >>> write to file.. this works no problems with ordinary dicts. >> >> The error message is misleading. You can pickle your defaultdict if you >> use a "normal" function instead of the lambda: >> >> $ cat pickle_defaultdict.py >> import sys >> from collections import defaultdict >> from cPickle import dumps, loads >> >> if "--lambda" in sys.argv: >> make_inner = lambda: defaultdict(list) >> else: >> def make_inner(): >> return defaultdict(list) >> >> d = defaultdict(make_inner) >> d[1][2].append(42) >> e = loads(dumps(d)) >> print e == d >> >> $ python pickle_defaultdict.py >> True >> $ python pickle_defaultdict.py --lambda >> Traceback (most recent call last): >> File "pickle_defaultdict.py", line 13, in >> e = loads(dumps(d)) >> File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex >> raise TypeError, "can't pickle %s objects" % base.__name__ >> TypeError: can't pickle function objects >> > But can you unpickle the objects you pickle? I believe that functions > are references relative to the modules they come from, and so won't be > found unless the same module can be imported at unpickle time. Could be > wrong, haven't read the source, but I understand that functions work the > same as classes. Indeed, what is stored in the pickle is the module and function name, not the byte code: >>> from cPickle import dumps, loads >>> def f(): print "original" ... >>> s = dumps(f) >>> def f(): print "updated" ... >>> g = loads(s) >>> g() updated That limits pickle as an exchange format to installations that provide compatible versions of the pickled classes and functions. Do you think that would be a problem for the OP? Peter From tjreedy at udel.edu Fri Jan 23 17:26:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 17:26:09 -0500 Subject: seeking to improve Python skills In-Reply-To: References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: mk wrote: > Jean-Paul Calderone wrote: > >> The most significant thing missing from this code is unit tests. >> Developing automated tests for your code will help you learn a lot. > > Thanks for all the remarks, I'll restructure my code. Probably the > biggest mistake was not keeping "moving average" class and others > focused on its respective jobs only. I would consider writing the moving-average 'function' as a generator function. First version takes a sequence and window size as inputs. Second, slightly more difficult, takes an iterator and window size as inputs. An exponentially-weighted average generator would, of course, take an iterator and weight as input. From exarkun at divmod.com Fri Jan 23 17:26:22 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 23 Jan 2009 17:26:22 -0500 Subject: Where to place imports In-Reply-To: Message-ID: <20090123222622.24460.2114347762.divmod.quotient.597@henry.divmod.com> On Fri, 23 Jan 2009 22:49:34 +0100, Christian Heimes wrote: >Jean-Paul Calderone schrieb: >>> BTW, if you ever find you are starting to write multi-threaded >>> applications >>> then you'll really regret it if you reuse code which does imports from >>> inside functions. If two or more threads try to import a module >>> simultaneously then one of them might find it that not everything is >>> defined in the module exists when it tries to use it. >> >> What makes you say this? There is an import lock (beyond the GIL) which >> should prevent a thread from ever seeing a partially initialized module. > >Partially initialized modules aren't the issue here. One can easily >create a dead lock situation with a mix of threads and imports. > >Example: > >* module 'mod_a' is imported [import lock is acquired] >* module 'mod_a' spawns a new thread >* the new thread tries to import another module 'mod_b' > >Python dead locks here and there is no chance to resolve the lock. The >import of 'mod_b' is waiting for the first import. The first import >hasn't finished because it's still executing the body of 'mod_a'. > >In order to avoid the situation you *must* never import a module in a >thread other than the main thread. You should never start a thread in >the body of a submodule, too. A large application should import all its >modules first and then create its threads. > >If you really need to import a module from a sub thread or a method that >might be called from a sub thread then you should use the C function >PyImport_ImportModuleNoBlock() or use sys.modules and imp.lock_held(). > Of course this is all true and good to know (and I did already ;), but it doesn't sound like the case being described in the message I was responding to. Jean-Paul From bugtrack at roumenpetrov.info Fri Jan 23 17:28:49 2009 From: bugtrack at roumenpetrov.info (Roumen Petrov) Date: Sat, 24 Jan 2009 00:28:49 +0200 Subject: About SCons Re: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: <497A44A1.20907@roumenpetrov.info> anatoly techtonik wrote: > On Thu, Jan 22, 2009 at 12:51 AM, Roumen Petrov > wrote: >>> Against 2.3, rejected due to dependence on SCons. >>> Also appears to have been incomplete, needing more work. >> No it was complete but use SCons. Most of changes changes in code you will >> see again in 3871. >> > > I would better use SCons for both unix and windows builds. In case of > windows for both compilers - mingw and microsoft ones. To port curses > extension to windows I need to know what gcc options mean, what are > the rules to write Makefiles and how to repeat these rules as well as > find options in visual studio interface. Not mentioning various > platform-specific defines and warning fixes. Did you select one of existing curses library for windows ? Roumen From rdcollum at gmail.com Fri Jan 23 17:30:05 2009 From: rdcollum at gmail.com (Roger) Date: Fri, 23 Jan 2009 14:30:05 -0800 (PST) Subject: is None vs. == None References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> <16367708-92c8-4f74-aec7-1619ea560041@v5g2000pre.googlegroups.com> Message-ID: <863b32f7-91e1-4e5d-a0ee-85f8d1307f70@k1g2000prb.googlegroups.com> > Why do you think it matters? Intellectual curiosity hence why I asked the question. It doesn't matter if I know why the sky is blue but it's interesting to know regardless. From tjreedy at udel.edu Fri Jan 23 17:30:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 17:30:11 -0500 Subject: Need script to download file from a server using python script In-Reply-To: <797263.81430.qm@web59712.mail.ac4.yahoo.com> References: <797263.81430.qm@web59712.mail.ac4.yahoo.com> Message-ID: Murali Murali wrote: > Hi, > > I am fairly new to python and i am looking for a python script to > download file(latest build) from the server. But, the build name changes > daily. For Ex: today the build URL will be > "http://mybuilds/myapp_1234.exe" and tomorrow it will be > "http://myserver/mybuilds/myapp_3456.exe". So i need a script which > downloads the latest build without any knowledge of build number. Any server that dishes out files with changing names should be using the ftp protocol that is meant for such things. It includes, I believe, a directory request that lets clients discover filenames. From robin at NOSPAMreportlab.com Fri Jan 23 17:51:44 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Fri, 23 Jan 2009 22:51:44 +0000 Subject: strange error whilst porting to 2.6 Message-ID: <497A4A00.9060303@jessikat.plus.net> python 2.6 indicates this error whilst running a script that works fine under Python 2.5. Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in ignored I suppose this must be related to some kind of isinstance or issubclass check, but how can I locate the problem if no traceback is shown? Googling seems to indicate that __subclasscheck__ is an abstract base class method, but clearly in 2.5 I cannot mess with abc stuff. -- Robin Becker From xahlee at gmail.com Fri Jan 23 18:16:59 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 23 Jan 2009 15:16:59 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: ok, i've been reading these Ocaml tutorials in the past few days: intro to ocaml, from official site http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html ?Objective CAML Tutorial?, most cited tutorial on the web http://www.ocaml-tutorial.org/ None of them are perfect, but much better than haskell ones. The official tutorial is ok, but still confusing. The one at ocaml-tutorial.org is somewhat but mostly because it's a lot more explanatory text. It has much verbiage for imperative programers (i.e. half of the text is about Perl this, C that, Java thus, trying to each you functional lang by comparative study assuming you are one of these these idiots. Half of the time, the comparison doesn't make much sense) The best one, is the one is ?Introduction to Caml? http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. I found it by as one of the top result from google search. This one is to the point, on lang syntax, what they do and mean, to the point short examples, focusing one concept at a time. (as opposed to the typical of: littering of motherfucking abstruse jargons thru- out, littering gospels about properties of starry-eyed fucking advantage of static mother fucking typing, the beauties of functional programing fuck, no concrete examples but full of high-horse abstract terminologies that are factually from asses who doesn't know a flying fuck about symbolic logic, replete with computer engineering fuck typical of compiler geekers like garbage collection, garbage collection, garbage collection!!!, memory address memory address memory address, pointers pointers pointers!!! hips and stacks and hips and stacks and very hip!) though, it is of course not my ideal, because it still now and then mention extraneous stupid computer engineering concepts like ?GARBAGE COLLECTION?, ?stateful?, how something is ?expression-based?, etc. If you are have a computer science background, sure these are no problem. But if you are a say practical programer who never took computer science classes, you'll go Huh? and if you are say the world's top mathematician but never studied programing, you'll go HUH? But again, this tutorial is far far better than vast majority of tutorials out there about functional programing (except mine). The haskell tutorials you can find online are the most mothefucking stupid unreadable fuck. The Haskll community is almost stupid. What they talk all day is about monads, currying, linder myer fuck type. That's what they talk about all day. All day and night. Monad! What's a monad! The importance of monad! How to learn monad! Simple intro to monad! Fucking morons, but MONAD! PS i started a Ocaml learning blog here: http://xah-ocaml.blogspot.com/ Xah ? http://xahlee.org/ ? From delroth at gmail.com Fri Jan 23 18:26:45 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Sat, 24 Jan 2009 00:26:45 +0100 Subject: OCaml, Language syntax, and Proof Systems In-Reply-To: References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <1ba9eaed0901231526v75826e14g7e1c4a664b55e38e@mail.gmail.com> On Sat, Jan 24, 2009 at 12:16 AM, Xah Lee wrote: > The haskell tutorials you can find online are the most mothefucking > stupid unreadable fuck. The Haskll community is almost stupid. What > they talk all day is about monads, currying, linder myer fuck type. > That's what they talk about all day. All day and night. Monad! What's > a monad! The importance of monad! How to learn monad! Simple intro to > monad! Fucking morons, but MONAD! *YOU* are full of monads. From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:37:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:37:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <018a4b24$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 20:09:48 +0000, Mark Wooding wrote: > Steven D'Aprano writes: > >> On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >>> Why on earth couldn't I change the code of another member of my team >>> if that code needs changes ? The code is the whole team's ownership. >> >> That's a model that works well when you have a small team of, say, a >> dozen people. It's not a model that works when you have hundreds of >> developers working on the project. The last thing I want in my projects >> is cowboys who ride all over other people's code, changing internals of >> parts they barely know at the drop of a hat, causing who knows what >> side- effects. > > Why are you assuming that Bruno would make his change in such an > irresponsible manner? I did? Where did I make that assumption? What I said was that the model "The code is the whole team's ownership" doesn't work well for large projects. *One* reason it doesn't work for large projects is that you will invariably have cowboys who, given half a chance, will code irresponsibly *if you let them* by encouraging the attitude that, sure, that class written by the database backend team belongs to everyone, never mind that you're in the UI team, go right ahead and use whatever internals you like. There are other reasons -- do I need to elaborate on them? Even in a project as small as Python there is sense of *individual* (rather than collective) code ownership, in the sense of responsibility for specific portions of the code base. Scale up the project by a factor of ten, and the problems caused by collective responsibility are simply intractable. > Such things need discussing, with some > appropriate level of formality, with the people most involved with the > relevant code -- which might be anything between a quick chat with the > bloke across the room or an agenda item on the next team meeting to a > written proposal. Yes, and when you have hundreds of developers working on the project, the chances are quite good that there will be twenty such agenda items every week, and then the project will bog down on arguments about what needs to be private and what doesn't, until the project manager just makes a blanket ruling No Access To Internals Full Stop. And then, you know what, the project still manages to go forward. Instead of spending 15 minutes hacking the existing Foo class to do what they want, and then 15 hours dealing with the cascading bugs when the class changes, people simply spend 7 hours subclassing Foo to get what they want, and it's all good and not the end of the world. > Given your apparent readiness to assume the worst of programmers at > every opportunity (e.g., your above assumption that Bruno would change > code unilaterally and secretly, assumptions elsewhere that programmers > treat any exposed wiring as being published interface), I can only > assume that you really need to get some better cow-orkers. Now you're just being naive. The solution to these sorts of problems isn't "get better programmers" because even the best programmers make mistakes (errors, and errors of judgement). Communication breaks down -- Fred is sure Barney said "Yes" while Barney is equally positive he said "No". Or somebody has a demo to the CEO in two hours and needs to hack something up Right Now and the guy he has to chat to is home sick with the phone turned off, and by the time he comes back to work the little hack is forgotten. Or whatever. There's a *bazillion* number of things that can go wrong in big projects, and "getting better programmers" only reduces that to something like a hundred million. It's a credit to *everybody*, including the cowboys and the cow-orkers, that any project of any significant size makes any progress at all. Besides, "better programmers" are in short supply. Sometimes you have to use who you've got, because Guido and the timbot are working somewhere else and you can't afford them. That's why we have languages like Python: so that *ordinary* programmers can be as productive as genius programmers in languages like C. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:39:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:39:57 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> Message-ID: <018a4b9c$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: > It should be in _our_ power as the team of all participant coders on > _our_ project to decide if we should mess with the internals or not. > > What makes no sense is that it should be in the original author's power > to decide, if he is not part of _our_ team. Makes *no* sense? There's *no* good reason *at all* for the original author to hide or protect internals? Let's be specific here. The list implementation in CPython is an array with a hidden field storing the current length. If this hidden field was exposed to Python code, you could set it to a value much larger than the actual size of the array and cause buffer overflows, and random Python code could cause core dumps (and possibly even security exploits). So what you're saying is that the fundamental design of Python -- to be a high-level language that manages memory for you while avoiding common programming errors such as buffer overflows -- makes "no sense". Is that what you intended? As I see it, you have two coherent positions. On the one hand, you could be like Mark Wooding, and say that Yes you want to risk buffer overflows by messing with the internals -- in which case I'm not sure what you see in Python, which protects so many internals from you. Or you can say that you made a mistake, that there are *some* good reasons to protect/hide internals from external access. In the second case, the next question is, why should it only be code written in C that is allowed that protection? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:42:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:42:33 GMT Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: <018a4c38$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 09:35:52 -0600, skip wrote: > Steven> I'm interested in this ticket in the bug tracker: > > Steven> http://bugs.python.org/issue2527 > > Steven> but it seems to have been stalled for nine months. Is there > a Steven> procedure for starting it up again? > > Assign it to yourself? Add a comment with relevant updates? > > Steven> Should I ask about it on the python-dev mailing list, or > just Steven> wait until somebody happens to notice it? > > But you've already noticed it. ;-) (Note to self: stop posting ambiguous messages when tired.) I meant bringing it to the attention of somebody who can actually commit the patch to production, or rule that the patch isn't suitable. I can't do that. Sorry for the naive questions, I'm new to the bug tracker and I'm not entirely sure about the protocol. Should I just drop a note to python-dev and ask somebody with commit privileges to look at it, or is that rude? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:46:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:46:04 GMT Subject: Where to place imports References: <6tuamjFckgp0U1@mid.uni-berlin.de> Message-ID: <018a4d0b$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 17:48:19 +0100, Diez B. Roggisch wrote: > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. Or if you want to make it clear that only a single function uses the imported module, or if you wish to avoid a potentially expensive import until the last possible moment when you actually need it, or if you're finicky about namespace pollution, or if you just like to put your imports inside functions because you're weird and never use threads. All of these are valid reasons. Whether they will give you the love and respect of your fellow Python programmers is another question. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 18:49:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jan 2009 23:49:11 GMT Subject: is None vs. == None References: Message-ID: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > Hi -- Some time ago I ran across a comment recommending using is > None instead of == None (also is not None, etc.) That entirely depends on whether you wish to test for something which *is* None or something with *equals* None. Those two things have different meanings. I wonder, do newbies actually get the impression from somewhere that "is" is a synonym for "=="? > My own > testing indicates that the former beats the latter by about 30% on > average. Not a log for a single instruction but it can add up in large > projects. If you have a "large" project where the time taken to do comparisons to None is a significant portion of the total time, I'd be very surprised. var is None is a micro-optimization, but that's not why we do it. We do it because usually the correct test is whether var *is* None and not merely equal to None. Any random object might happen to equal None (admittedly most objects don't), but only None is None. -- Steven From gdamjan at gmail.com Fri Jan 23 19:02:01 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sat, 24 Jan 2009 01:02:01 +0100 Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: >> I don't know what an IBQ is. > > +IBQ- seems to be the way your newsreader displays the dashes that > where in Ben's posting. I see "em dash" characters there: I see IBQ too ... also weird is that he has Content-Type: text/plain; charset=utf-7 -- ?????? ( http://softver.org.mk/damjan/ ) Give me the knowledge to change the code I do not accept, the wisdom not to accept the code I cannot change, and the freedom to choose my preference. From digitig at gmail.com Fri Jan 23 19:04:09 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 24 Jan 2009 00:04:09 +0000 Subject: The First Law Of comp.lang.python Dynamics In-Reply-To: <497a2cce$0$183$e4fe514c@news.xs4all.nl> References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> <497a2cce$0$183$e4fe514c@news.xs4all.nl> Message-ID: 2009/1/23 Martin P. Hellwig : > Or you can argue that even when an argument is repeated indefinitely it > doesn't make it suddenly right. No, but it makes for a confirmation of Schluehr's law :-) -- Tim Rowe From benjamin.kaplan at case.edu Fri Jan 23 19:24:38 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 19:24:38 -0500 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: On Fri, Jan 23, 2009 at 6:49 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > Hi -- Some time ago I ran across a comment recommending using is > > None instead of == None (also is not None, etc.) > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > I think it's more that teachers tell students without programming experience "always use == to test if something equals something else unless you're checking for None," without explaining what == and is actually mean. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Fri Jan 23 19:28:15 2009 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 23 Jan 2009 16:28:15 -0800 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <497A609F.4030700@islandtraining.com> Steven D'Aprano wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) >> > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > Actually, for None, those two things *are* the same. If something *equals* None, it also *is* None. This is a consequence of the fact that there is only ever one value of None anywhere in the system. > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > Yes. Such questions pop up regularly, and are usually dealt with quickly. > > > >> My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in large >> projects. >> > > If you have a "large" project where the time taken to do comparisons to > None is a significant portion of the total time, I'd be very surprised. > > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. > > You don't have that quite right. The only way something can *equal* None is if it *is* None. None is not a value an object can have, but rather it is a (singleton) object that can be referenced. Setting something *equal* to None is accomplished by making it refer to the single None object, at which point it *is* None. Gary Herron > > From mdw at distorted.org.uk Fri Jan 23 19:29:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 00:29:08 +0000 Subject: Dynamic methods and lambda functions References: Message-ID: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> unineuro at gmail.com writes: > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) [...] > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? Ahh! Binding-versus-assignment confusion! Things to realise: * There are two mappings of interest when dealing with variables. The `binding' of a name maps the name to a variable. The variable stores a (reference to a) value. * Assignment stores a new (reference to a) value in the variable. * Binding modifies the mapping between names and variables. * Nested functions, as constructed by `lambda' or `def', inherit (we say `close over') the bindings visible in their surroundings. * Python's `for' loop works by assignment. So, what happens is this. In `__init__', there's a binding of the name `prop' to a variable. The `for' loop modifies this variable on each iteration, making it refer to successive elements of the `props' list. The `lambda's you create inherit the binding of `prop' from the surrounding `__init__', so the `lambda' sees the same variable as is being modified by the loop. Result: when you actually come to invoke one of the `lambda's -- after `__init__' finishes -- you find that its notion of `prop' is whatever the `for' left it as. To fix the problem, you need to make a separate variable for each iteration through the loop, and have the `lambda' close over that. Function parameters are the easy approach to making fresh variables with given contents: so we just call a function which accepts, and stores in a parameter, the value we want the `lambda' to see, and closes over the parameter. class Person (object): # use new-style classes def __init__(self): # allow parametrization def getter(propname): # close over new variable return lambda self: getattr(self, propname) for name, value in props: # destructuring wins setattr(self, '__' + name, value) for name, value in props: # only need to do this once setattr(Person, 'Get' + name, getter('__' + name)) Does that make sense? -- [mdw] From benjamin.kaplan at case.edu Fri Jan 23 19:31:59 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 19:31:59 -0500 Subject: is None vs. == None In-Reply-To: <497A609F.4030700@islandtraining.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <497A609F.4030700@islandtraining.com> Message-ID: On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a comment recommending using is > >> None instead of == None (also is not None, etc.) > >> > > > > That entirely depends on whether you wish to test for something which > > *is* None or something with *equals* None. Those two things have > > different meanings. > > > > Actually, for None, those two things *are* the same. If something > *equals* None, it also *is* None. This is a consequence of the fact > that there is only ever one value of None anywhere in the system. Not if someone decided to be a PITA. >>> class A(object) : ... def __eq__(self, other) : ... return other is None ... >>> a = A() >>> a == None True >>> a is None False > > > I wonder, do newbies actually get the impression from somewhere that "is" > > is a synonym for "=="? > > > > Yes. Such questions pop up regularly, and are usually dealt with quickly. > > > > > > > > >> My own > >> testing indicates that the former beats the latter by about 30% on > >> average. Not a log for a single instruction but it can add up in large > >> projects. > >> > > > > If you have a "large" project where the time taken to do comparisons to > > None is a significant portion of the total time, I'd be very surprised. > > > > var is None is a micro-optimization, but that's not why we do it. We do > > it because usually the correct test is whether var *is* None and not > > merely equal to None. Any random object might happen to equal None > > (admittedly most objects don't), but only None is None. > > > > > You don't have that quite right. The only way something can *equal* > None is if it *is* None. > None is not a value an object can have, but rather it is a (singleton) > object that can be referenced. Setting something *equal* to None is > accomplished by making it refer to the single None object, at which > point it *is* None. > > Gary Herron > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From caseyhHAMMER_TIME at istar.ca Fri Jan 23 19:33:12 2009 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Fri, 23 Jan 2009 16:33:12 -0800 Subject: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? Message-ID: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? I suppose I'm thinking of an extra layer of indirection, which might slow things down to much. :) -- Regards, Casey From jon at ffconsultancy.com Fri Jan 23 19:36:58 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 24 Jan 2009 00:36:58 +0000 Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: Xah Lee wrote: > ok, i've been reading these Ocaml tutorials in the past few days: > > intro to ocaml, from official site > http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html > > ?Objective CAML Tutorial?, most cited tutorial on the web > http://www.ocaml-tutorial.org/ > > The best one, is the one is > ?Introduction to Caml? > http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html > by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. > I found it by as one of the top result from google search. You may also appreciate the freely-available first chapter of my book OCaml for Scientists: http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html And the freely-available first chapter of The OCaml Journal: http://www.ffconsultancy.com/products/ocaml_journal/free/introduction.html I also recommend Jason Hickey's book which, I believe, is due to be published by Cambridge University Press soon: http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From rt8396 at gmail.com Fri Jan 23 19:38:38 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:38:38 -0800 (PST) Subject: Find all available Tkinter cursor names? References: <2380c412-7d30-4c51-ab30-5fa83258233d@o36g2000yqh.googlegroups.com> <4978FF18.7020508@codebykevin.com> <4979DFB4.4030705@codebykevin.com> Message-ID: On Jan 23, 9:18?am, Kevin Walzer wrote: > http://wiki.tcl.tk/8674might offer some help in this regard. > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Many Thanks Kevin, this may help! From rt8396 at gmail.com Fri Jan 23 19:43:49 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:43:49 -0800 (PST) Subject: Suggested improvements for IDLE (non-official) References: <04608827-e885-45ba-ae12-5b59e3ed9d7d@x14g2000yqk.googlegroups.com> <29596028-3290-40e4-9706-823da33ed417@t3g2000yqa.googlegroups.com> Message-ID: <1a94f9f1-f895-42ba-aefa-b2d6e370fba8@k1g2000prb.googlegroups.com> On Jan 16, 1:55?am, Terry Reedy wrote: > > Maybe I'm misunderstanding something here, but "About Idle" in Python > > 2.6.1 (win32) says "Tk version: 8.5" As to Tk, i was referring to Themes. I may have the versions mixed up but the newest TK supports themes and i would love to get that support into Tkinter, This will help shine up python a bit. From tjreedy at udel.edu Fri Jan 23 19:44:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jan 2009 19:44:40 -0500 Subject: Stalled ticket in Python bug tracker In-Reply-To: <018a4c38$0$20629$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> <018a4c38$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 09:35:52 -0600, skip wrote: > >> Steven> I'm interested in this ticket in the bug tracker: >> >> Steven> http://bugs.python.org/issue2527 >> >> Steven> but it seems to have been stalled for nine months. Is there >> a Steven> procedure for starting it up again? >> >> Assign it to yourself? Add a comment with relevant updates? You seem to have missed or not understood this answer. See below. >> >> Steven> Should I ask about it on the python-dev mailing list, or >> just Steven> wait until somebody happens to notice it? >> >> But you've already noticed it. ;-) > > > (Note to self: stop posting ambiguous messages when tired.) > > > I meant bringing it to the attention of somebody who can actually commit > the patch to production, or rule that the patch isn't suitable. I can't > do that. However, you can do something to move it forward. 1. There were some suggested changes to the patch but no revised version uploaded. What do *you* think of them? 2. The patch is small enough that you could apply it by hand, with or without any further changes, to a copy of timeit.py on your system. 3. The patch is against python2.5. Test it with 2.6 and 3.0 with the current test file in Lib/test. 4. The patch lacks any test of the new feature. Write one that could be added to the current test file. 5. The patch lack documentation of the new feature. Write a entry that could be added to the current timeit module doc. 6. Ask the OP to incorporate the test and doc in the appropriate file and generate and post a new diff patch. The patch as is is unacceptable without the test and doc. > Sorry for the naive questions, I'm new to the bug tracker and I'm not > entirely sure about the protocol. Should I just drop a note to python-dev > and ask somebody with commit privileges to look at it, or is that rude? Slightly rude, perhaps, but more importantly, without volunteer work on your part, probably useless. Everyone else is a volunteer also. tjr From robert.kern at gmail.com Fri Jan 23 19:49:31 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jan 2009 18:49:31 -0600 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. Additionally, some objects that use rich comparisons to return other objects and not booleans will simply fail when compared with None. The situations where you are testing for None are frequently situations where you don't really know the kind of object you might be getting, either. -- 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 rt8396 at gmail.com Fri Jan 23 19:56:12 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 16:56:12 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: Yes promoting freedom, claiming that freedom is a good thing, and not being afraid to open my mouth about it, fight for it, free others from their bonds, makes me free. No presumption was made about the OP, the only "meaning" in my message was to free the OP from his self imposed bonds while using Python. You made this political. Seems like you have a predisposition of hate towards me, maybe it is unconscience and you do not realize it, but i highly doubt it. Come down from your tower of righteousness Deiz, loosen up that stiff- upper-lip and bring your brown-nosing minions with you! From mdw at distorted.org.uk Fri Jan 23 20:01:07 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 01:01:07 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> Message-ID: <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > I did? Where did I make that assumption? I inferred it from the juxtaposition, apparently in error. Sorry. > What I said was that the model "The code is the whole team's ownership" > doesn't work well for large projects. *One* reason it doesn't work for > large projects is that you will invariably have cowboys who, given half a > chance, will code irresponsibly *if you let them* by encouraging the > attitude that, sure, that class written by the database backend team > belongs to everyone, never mind that you're in the UI team, go right > ahead and use whatever internals you like. `Cowboys' will code irresponsibly anyway; they need reeducating gently with a stick. >> Such things need discussing, with some >> appropriate level of formality, with the people most involved with the >> relevant code -- which might be anything between a quick chat with the >> bloke across the room or an agenda item on the next team meeting to a >> written proposal. > > Yes, and when you have hundreds of developers working on the project, > the chances are quite good that there will be twenty such agenda items > every week, and then the project will bog down on arguments about what > needs to be private and what doesn't, until the project manager just > makes a blanket ruling No Access To Internals Full Stop. Err... you've wandered off the track here. The purpose of the proposed changes is to expose the right interfaces so that people don't need to fiddle with internals. If I've discovered that I need to dredge something out of the middle of your module, I have three choices: (a) somehow get your module changed so that it hands me the information I want through a documented interface, (b) suck your module's brains out through a straw whether the interface lets me or not, or (c) lose. The agenda items are supporting (a), which I thought you were in favour of; you certainly seem to be against (b), and (c) doesn't look appealing. > And then, you know what, the project still manages to go > forward. Instead of spending 15 minutes hacking the existing Foo class > to do what they want, and then 15 hours dealing with the cascading > bugs when the class changes, people simply spend 7 hours subclassing > Foo to get what they want, and it's all good and not the end of the > world. Subclassing hardly fixes these sorts of problems well. Hardly any class libraries are documented sufficiently well enough to support subclassing properly. Have a look at the CLOS MOP specification http://www.lisp.org/mop/index.html for a rare example of how to do it right. > Besides, "better programmers" are in short supply. Sometimes you have > to use who you've got, because Guido and the timbot are working > somewhere else and you can't afford them. That's why we have languages > like Python: so that *ordinary* programmers can be as productive as > genius programmers in languages like C. Why waste genius programmers on churning out C? Just imagine how much they could do with something like Python! -- [mdw] From rt8396 at gmail.com Fri Jan 23 20:02:59 2009 From: rt8396 at gmail.com (r) Date: Fri, 23 Jan 2009 17:02:59 -0800 (PST) Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> Message-ID: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Whatever scumbag would rate a new python's users with one start for asking us for help is a complete low-life. Keep acting like that and Python will fade away into the darkness forever. dhaval, Don't let the few bullies here scare you away, try out the this link, the other one i gave you was incorrect http://www.python-forum.org/pythonforum/index.php From linuxguy123 at gmail.com Fri Jan 23 20:06:49 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 23 Jan 2009 18:06:49 -0700 Subject: How do I get my python program to get the root password ? Message-ID: <1232759209.3727.2.camel@localhost.localdomain> I want to make a python program that I can run as a normal user that changes the permission on some device files. It will need to ask me for the root password and then run chown as root in order to do this. How do I accomplish this (easily) ? Thanks From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 20:16:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 01:16:51 GMT Subject: is None vs. == None References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018a6252$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 16:28:15 -0800, Gary Herron wrote: > If something > *equals* None, it also *is* None. This is a consequence of the fact > that there is only ever one value of None anywhere in the system. ... > The only way something can *equal* None is if it *is* None. >>> class Empty: ... def __eq__(self, other): ... return not bool(other) ... >>> e = Empty() >>> e == None True >>> e is None False -- Steven From castironpi at gmail.com Fri Jan 23 20:21:56 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 23 Jan 2009 17:21:56 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <289bc9ab-add6-4e75-af81-f0d265135dc7@a12g2000pro.googlegroups.com> On Jan 23, 7:01?pm, Mark Wooding wrote: > Steven D'Aprano writes: > > I did? Where did I make that assumption? > > I inferred it from the juxtaposition, apparently in error. ?Sorry. > > > What I said was that the model "The code is the whole team's ownership" > > doesn't work well for large projects. *One* reason it doesn't work for > > large projects is that you will invariably have cowboys who, given half a > > chance, will code irresponsibly *if you let them* by encouraging the > > attitude that, sure, that class written by the database backend team > > belongs to everyone, never mind that you're in the UI team, go right > > ahead and use whatever internals you like. > > `Cowboys' will code irresponsibly anyway; they need reeducating gently > with a stick. A lot of this is a question of how tight you want the handcuffs. Stricter backgrounds and bigger projects make you want tighter ones. You can't jump right from tight handcuffs to loose ones. You'll tend to like them looser over time. A language looser than Python in unheard of. Google says: 'No results found for "looser than Python".' From steve at holdenweb.com Fri Jan 23 20:28:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:28:11 -0500 Subject: writing pickle function In-Reply-To: References: Message-ID: Peter Otten wrote: > Steve Holden wrote: > >> Peter Otten wrote: >>> perfreem at gmail.com wrote: >>> >>>> i am using nested defaultdict from collections and i would like to >>>> write it as a pickle object to a file. when i try: >>>> >>>> from collections import defaultdict >>>> x = defaultdict(lambda: defaultdict(list)) >>>> >>>> and then try to write to a pickle file, it says: >>>> >>>> TypeError: can't pickle function objects >>>> >>>> is there a way around this? it's simply a dictionary that i want to >>>> write to file.. this works no problems with ordinary dicts. >>> The error message is misleading. You can pickle your defaultdict if you >>> use a "normal" function instead of the lambda: >>> >>> $ cat pickle_defaultdict.py >>> import sys >>> from collections import defaultdict >>> from cPickle import dumps, loads >>> >>> if "--lambda" in sys.argv: >>> make_inner = lambda: defaultdict(list) >>> else: >>> def make_inner(): >>> return defaultdict(list) >>> >>> d = defaultdict(make_inner) >>> d[1][2].append(42) >>> e = loads(dumps(d)) >>> print e == d >>> >>> $ python pickle_defaultdict.py >>> True >>> $ python pickle_defaultdict.py --lambda >>> Traceback (most recent call last): >>> File "pickle_defaultdict.py", line 13, in >>> e = loads(dumps(d)) >>> File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex >>> raise TypeError, "can't pickle %s objects" % base.__name__ >>> TypeError: can't pickle function objects >>> >> But can you unpickle the objects you pickle? I believe that functions >> are references relative to the modules they come from, and so won't be >> found unless the same module can be imported at unpickle time. Could be >> wrong, haven't read the source, but I understand that functions work the >> same as classes. > > Indeed, what is stored in the pickle is the module and function name, not > the byte code: > >>>> from cPickle import dumps, loads >>>> def f(): print "original" > ... >>>> s = dumps(f) >>>> def f(): print "updated" > ... >>>> g = loads(s) >>>> g() > updated > > That limits pickle as an exchange format to installations that provide > compatible versions of the pickled classes and functions. > > Do you think that would be a problem for the OP? > Nice demonstration! Possibly not, though the original use of lambdas demonstrated at least confusion. But there needs to be an understanding that the pickled function has to be importable. Just using a function in __main__ and then trying to unpickle from another program that doesn't contain the function won;t hack it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Jan 23 20:31:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:31:08 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <018a4b24$0$20629$c3e8da3@news.astraweb.com> <87bptxbjqk.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steven D'Aprano writes: > >> I did? Where did I make that assumption? > > I inferred it from the juxtaposition, apparently in error. Sorry. > >> What I said was that the model "The code is the whole team's ownership" >> doesn't work well for large projects. *One* reason it doesn't work for >> large projects is that you will invariably have cowboys who, given half a >> chance, will code irresponsibly *if you let them* by encouraging the >> attitude that, sure, that class written by the database backend team >> belongs to everyone, never mind that you're in the UI team, go right >> ahead and use whatever internals you like. > > `Cowboys' will code irresponsibly anyway; they need reeducating gently > with a stick. > Unfortunately on large projects it's impossible to avoid cowboys, and some of them are completely lost to reason. [...] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Fri Jan 23 20:32:17 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 23 Jan 2009 19:32:17 -0600 Subject: How do I get my python program to get the root password ? References: Message-ID: On 2009-01-24, Linuxguy123 wrote: > I want to make a python program that I can run as a normal > user that changes the permission on some device files. It > will need to ask me for the root password and then run chown > as root in order to do this. > > How do I accomplish this (easily) ? The short answer is: you don't accomplish that easily. The long answer is: you can accomplishity difficultly by using a pty or the pexect module to execute the su or sudo command. -- Grant From steve at holdenweb.com Fri Jan 23 20:33:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 23 Jan 2009 20:33:45 -0500 Subject: is None vs. == None In-Reply-To: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > >> Hi -- Some time ago I ran across a comment recommending using is >> None instead of == None (also is not None, etc.) > > That entirely depends on whether you wish to test for something which > *is* None or something with *equals* None. Those two things have > different meanings. > No they don't, because the language *guarantees* the None object is a singleton, so anything that *equals* None *is* None. > I wonder, do newbies actually get the impression from somewhere that "is" > is a synonym for "=="? > Who knows. But if they do they can easily be reeducated. > > >> My own >> testing indicates that the former beats the latter by about 30% on >> average. Not a log for a single instruction but it can add up in large >> projects. > > If you have a "large" project where the time taken to do comparisons to > None is a significant portion of the total time, I'd be very surprised. > > var is None is a micro-optimization, but that's not why we do it. We do > it because usually the correct test is whether var *is* None and not > merely equal to None. Any random object might happen to equal None > (admittedly most objects don't), but only None is None. > Of course there can be pathological objects with bizarre comparison methods. And the "is" test helps avoid them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin.kaplan at case.edu Fri Jan 23 20:39:55 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jan 2009 20:39:55 -0500 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED In-Reply-To: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> References: <5c934a40-a5bc-4853-a6fa-a7c9cc4b00d1@v15g2000vbb.googlegroups.com> <6t60rmF9auodU1@mid.uni-berlin.de> <504cb65f-dd0e-4134-b603-55655766ce32@e18g2000vbe.googlegroups.com> <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Message-ID: On Fri, Jan 23, 2009 at 8:02 PM, r wrote: > Whatever scumbag would rate a new python's users with one start for > asking us for help is a complete low-life. Keep acting like that and > Python will fade away into the darkness forever. Could you please explain where these stars you keep talking about come from? It's not from Usenet (AFAIKT), the mailing list, or Google Groups. Stop worrying about something that 99% of the people here can't see. > > > dhaval, > Don't let the few bullies here scare you away, try out the this link, > the other one i gave you was incorrect > > http://www.python-forum.org/pythonforum/index.php > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Fri Jan 23 20:41:35 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 24 Jan 2009 01:41:35 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <877i4lbhv4.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > Let's be specific here. The list implementation in CPython is an array > with a hidden field storing the current length. If this hidden field was > exposed to Python code, you could set it to a value much larger than the > actual size of the array and cause buffer overflows, and random Python > code could cause core dumps (and possibly even security exploits). [...] > As I see it, you have two coherent positions. On the one hand, you could > be like Mark Wooding, and say that Yes you want to risk buffer overflows > by messing with the internals Please, point out where I said that! I'm pretty sure that the only time I commented on this particular point (in message <87y6x2cih0.fsf.mdw at metalzone.distorted.org.uk>), I said: : Umm... I'm pretty sure that that's available via the `len' function, : which is tied to list.__len__ (via the magic C-implemented-type mangler, : in C). Though it's read-only -- and this is a shame, 'cos it'd be nice : to be able to adjust the length of a list in ways which are more : convenient than : : * deleting or assigning to a trailing slice, or : * augmenting or assigning to a trailing zero-width slice : : (Perl has supported assigning to $#ARRAY for a long time. Maybe that's : a good argument against it.) While I realise I didn't spell it out, the semantics I had in mind where foo.len = n means if n < 0: raise ValueError, 'don\'t be stupid' elif len(foo) < n: foo += [None] * (n - len(foo)) else: foo[n:] = [] (I'm not fussy what the new array slots get filled with, but it seems sensible to be clear. Perl's semantics are more complicated: if you decrease $#foo and then increase it again you get the old values back. Common Lisp users will recall the idea of a fill-pointer.) If there's anything unsafe about that, I'll be surprised. > -- in which case I'm not sure what you see in Python, which protects > so many internals from you. Or you can say that you made a mistake, > that there are *some* good reasons to protect/hide internals from > external access. Safety is good. Escape hatches are good, too. > In the second case, the next question is, why should it only be code > written in C that is allowed that protection? Because Python code can't cause those sorts of problems without resorting to the escape hatches (e.g., ctypes). And, very significantly, because C code /needs/ that protection and Python basically doesn't. The basic difference is that C code is fundamentally brittle: if you mess up its invariants, it can crash horribly and possibly allow its brain to be taken over by evil people. Python code is fundamentally robust. The worst that can happen[1] is that the interpreter raises an exception. This makes it ideally suited to having a more relaxed attitude to life. And that, in turn, makes it approachable, hackable interactively, fun! [1] Assuming that (a) the Python implementation and C extensions are correct, and (b) that the code in question isn't using the escape hatches. -- [mdw] From benjamin at python.org Fri Jan 23 20:44:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 01:44:21 +0000 (UTC) Subject: strange error whilst porting to 2.6 References: <497A4A00.9060303@jessikat.plus.net> Message-ID: Robin Becker NOSPAMreportlab.com> writes: > > python 2.6 indicates this error whilst running a script that works fine > under Python 2.5. > > Exception RuntimeError: 'maximum recursion depth exceeded in > __subclasscheck__' in ignored > > I suppose this must be related to some kind of isinstance or issubclass > check, but how can I locate the problem if no traceback is shown? You're code is causing a RuntimeError to be raised some where in a type checking call. Unfortunately because of old APIs in CPython that are not "allowed" to fail, CPython cannot continue to raise the exception, so it just prints that ugly error message and clanks happily along. The best way to avoid this is just throw away sys.stderr in code that is acting up like this. From bedouglas at earthlink.net Fri Jan 23 20:45:44 2009 From: bedouglas at earthlink.net (bruce) Date: Fri, 23 Jan 2009 17:45:44 -0800 Subject: PYTHON HTTP POST WORKING EXAMPLE NEEDED In-Reply-To: <64289ae3-4931-45a9-9e90-e1386c027747@n41g2000yqh.googlegroups.com> Message-ID: <167801c97dc5$7a92a530$0301a8c0@tmesa.com> hey.... didn't get the initial post/ just what is the original poster looking for?? -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of r Sent: Friday, January 23, 2009 5:03 PM To: python-list at python.org Subject: Re: PYTHON HTTP POST WORKING EXAMPLE NEEDED Whatever scumbag would rate a new python's users with one start for asking us for help is a complete low-life. Keep acting like that and Python will fade away into the darkness forever. dhaval, Don't let the few bullies here scare you away, try out the this link, the other one i gave you was incorrect http://www.python-forum.org/pythonforum/index.php -- http://mail.python.org/mailman/listinfo/python-list From fakeaddress at nowhere.org Fri Jan 23 20:48:44 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 17:48:44 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> Message-ID: <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Carl Banks wrote: [...] > BTW, class instances are usually immutable and thus don't require a > mutex in the system I described. Then you are describing a language radically different from Python. -- --Bryan From BrianVanderburg2 at aim.com Fri Jan 23 20:55:05 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Fri, 23 Jan 2009 20:55:05 -0500 Subject: How do I get my python program to get the root password ? In-Reply-To: References: Message-ID: <497A74F9.8030304@aim.com> grante at visi.com wrote: > On 2009-01-24, Linuxguy123 wrote: > > >> I want to make a python program that I can run as a normal >> user that changes the permission on some device files. It >> will need to ask me for the root password and then run chown >> as root in order to do this. >> >> How do I accomplish this (easily) ? >> > > The short answer is: you don't accomplish that easily. > > The long answer is: you can accomplishity difficultly by using > a pty or the pexect module to execute the su or sudo command. > > Check out libsudo. It is a simple library that simply calls sudo program except it is does all the work of reading/writing the pipes for you. You could then use ctypes to interface to it. Sudo doesn't use the root password but the password of the user executing the command, but there may be a way to make it use the password of the user the command is executed as instead in /etc/sudoers. I don't really know, I just have mine set up for my main user account to be able to execute any command. Brian Vanderburg II From rhodri at wildebst.demon.co.uk Fri Jan 23 20:58:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 24 Jan 2009 01:58:55 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7x3af91zm1.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: On Fri, 23 Jan 2009 21:28:22 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Mark Wooding writes: >> Now we come on to Fred. If Fred's across the room from me then we're >> back to the water-cooler. If he's on a different continent, and I know >> he'll be affected, I'll probably email him. If I've never heard of him >> at all, well, he might just lose when someone puts my code and Fred's >> together with OrderedDict... > > In a large project, more probably you'd enter a change request into > some kind of tracking system, there would be discussion in the > tracking system about how to do the change; perhaps at your weekly > staff meeting you might bring up the issue with your PHB if you were > blocking on the issue, and your PHB would bring it up at the inter-PHB > meeting with Fred's PHB to bump the item's priority, and eventually > Fred would check in a change and you would use it. There is > necessarily some wasted motion in any organization of that size; good > management is about keeping the friction to a minimum and getting the > stuff done. My experience with medium-sized organisations (50-100 people) is that either you talk to Fred directly, or it doesn't happen. In particular the more people (especially PHBs) that get involved, the slower the change will come and the less like your original requirement it will look. Each person, no matter how technically adept, has a significant chance of misunderstanding what it is you need and/or expressing it poorly to the next person in line. If I need something that goes 'ping' by Friday, and get something that goes 'pong' three weeks later (together with a note from Fred telling me that three-and-fourpence isn't going to get me into any of the good dance clubs), I'd have been better off taking a hacksaw to the internals myself and presenting my fix for Fred's consideration. Python allows me to do this without the fuss and drama that strict encapsulation seems to posit is necessary, instead of delaying an entire release cycle because the process doesn't trust me. -- Rhodri James *-* Wildebeeste Herder to the Masses From robin at NOSPAMreportlab.com Fri Jan 23 21:00:23 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 24 Jan 2009 02:00:23 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> Message-ID: <497A7637.2030405@jessikat.plus.net> Benjamin Peterson wrote: > Robin Becker NOSPAMreportlab.com> writes: > >> python 2.6 indicates this error whilst running a script that works fine >> under Python 2.5. >> >> Exception RuntimeError: 'maximum recursion depth exceeded in >> __subclasscheck__' in ignored >> >> I suppose this must be related to some kind of isinstance or issubclass >> check, but how can I locate the problem if no traceback is shown? > > You're code is causing a RuntimeError to be raised some where in a type checking > call. Unfortunately because of old APIs in CPython that are not "allowed" to > fail, CPython cannot continue to raise the exception, so it just prints that > ugly error message and clanks happily along. The best way to avoid this is just > throw away sys.stderr in code that is acting up like this. > > Well that's not really acceptable as a solution is it? :) -- Robin Becker From kyrie at uh.cu Fri Jan 23 21:36:59 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 23 Jan 2009 21:36:59 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <018a4b9c$0$20629$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232764619.497a7ecb47c4f@mail.uh.cu> Quoting Steven D'Aprano : > On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: > > > It should be in _our_ power as the team of all participant coders on > > _our_ project to decide if we should mess with the internals or not. > > > > What makes no sense is that it should be in the original author's power > > to decide, if he is not part of _our_ team. > > Makes *no* sense? There's *no* good reason *at all* for the original > author to hide or protect internals? My bad, sorry. It makes sense... if the original author is an egotist who believes he must control how I use that library. Or, if external forces make him do it (maybe like, 'oh, if I change python, then I'm not using python anymore'). > Let's be specific here. The list implementation in CPython is an array > with a hidden field storing the current length. If this hidden field was > exposed to Python code, you could set it to a value much larger than the > actual size of the array and cause buffer overflows, and random Python > code could cause core dumps (and possibly even security exploits). In which case, my code would be broken. (Wait, let me be clear: in which case, our team's code may be broken - but it was _our_ team's decision, knowing the risk). If a variable is marked as... I don't like 'private', I'll call it 'implementation detail', I would not use it without good reason. Not even by subclassing it. Why do you assume that I'd change list._length if I could? I wouldn't. Anyway, did you notice that your "counter-example" was a radical change-the-way-python-works scenario? I also don't want to change the interpreter's code on the fly. Now, if you take that as a confession that I really, really, want enforced data hiding and that everything I've said is plain wrong, so be it. After all, I treat python's interpreter as a black box, don't I? > So what you're saying is that the fundamental design of Python -- to be a > high-level language that manages memory for you while avoiding common > programming errors such as buffer overflows -- makes "no sense". Is that > what you intended? Yes, that's what I intended, obviously. I'd like to have buffer overflows in python. In case you don't understand irony: don't go putting words in my mouth. I'm not putting words in yours. > As I see it, you have two coherent positions. On the one hand, you could > be like Mark Wooding, and say that Yes you want to risk buffer overflows > by messing with the internals -- in which case I'm not sure what you see > in Python, which protects so many internals from you. Or you can say that > you made a mistake, that there are *some* good reasons to protect/hide > internals from external access. Or, I could have a third option: assume that I am a grownup who knows what he is doing. After all, even with all those "protections" in list, I could just create an extension module to shoot me in the foot anyway, if I really wanted to. > In the second case, the next question is, why should it only be code > written in C that is allowed that protection? Bug? Not worth the effort of exposing those variables? I don't know... [Btw, do you realize that C++'s private also don't provide that protection? I have almost no experience with C++ and found it trivial to circumvent] I don't think this is going anywhere. Now you are trying to push me to the extremes, changing what I _said_ for your exaggerated interpretation of it just so you could shoot it down, or force me to say that I want buffer overflows in python. I believe that's called "strawman". I stand by my words - but not by your "interpretation" of them: > > What makes no sense is that it should be in the original author's power > > to decide, if he is not part of _our_ team. Do you _really_ read from that sentence that I should dislike python because it makes it a bit harder to get a buffer overflow with their native types? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From benjamin at python.org Fri Jan 23 21:39:51 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 02:39:51 +0000 (UTC) Subject: strange error whilst porting to 2.6 References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: Robin Becker NOSPAMreportlab.com> writes: > > > Well that's not really acceptable as a solution is it? :) This doesn't happen in Python 3.0, so you could port to that. :) In 2.7, the better recursion depth handling in Py3k may be backported,but the best you can do for now is not touch the recursion limit or just shut the error up. From pavlovevidence at gmail.com Fri Jan 23 21:54:18 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 18:54:18 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Message-ID: <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> On Jan 23, 5:48?pm, Bryan Olson wrote: > Carl Banks wrote: > > [...] > > > BTW, class instances are usually immutable and thus don't require a > > mutex in the system I described. > > Then you are describing a language radically different from Python. Bzzt. Hint: aside from the reference count, most class instances are immutable in Python *today*. Carl Banks From linuxguy123 at gmail.com Fri Jan 23 21:58:09 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 23 Jan 2009 19:58:09 -0700 Subject: I'm a python addict ! Message-ID: <1232765889.7151.7.camel@localhost.localdomain> I just started using python last week and I'm addicted. I hate Perl. I never did learn to use it with any competence. I has to be the most obfuscated, cryptic language I've ever seen. Making it "object oriented" only makes it worse ! While I am at it, I dislike bash shell programming too. Man, I love Python ! Its so clean and easy to use. Its so complete. It links into everything one way or another... Java, C, C++, Qt, KDE, SWT, Swing and probably more things that I don't know about. Python makes sense. Python is readable. I will never write another Perl or Bash script again. I will never use another low level language to do simple things again. I love how Python has object member lists in PyDev in Eclipe. It makes it easy to use and explore the language and objects. I wrote a simple command line serial emulator in about 10 minutes using the PySerial library. Unbelievable. I see a lot of Python in my future. From maxerickson at gmail.com Fri Jan 23 22:16:19 2009 From: maxerickson at gmail.com (Max Erickson) Date: Sat, 24 Jan 2009 03:16:19 +0000 (UTC) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Years ago I have found this nice small program, TextCalc: > http://www.atomixbuttons.com/textcalc/ > > Despite being very limited and being not integrated with > everything else, it's so handy that for me in certain situations > it's the right tool to use when I have to process numbers and > data in simple ways. It helps me keep all the intermediate > solutions, you can save the working page just as the text file > you are seeing, it's "passive", it doesn't go bang, so if you > want you can use it just a primitive text editor. It does > something only when you ask it to. And for a basic usage there > is nearly nothing to remember. > This is mostly an aside to your question, but depending on what you aredoing, Speq Mathematics may be an improvement over TextCalc. The homepage is at http://www.speqmath.com/index.php?id=1. The big differences are that it adds a good deal of functionality (variables, a larger variety of functions, plotting, etc.) and that it treats plain text as an error (unless the text is marked as a comment). max From http Fri Jan 23 22:18:05 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:18:05 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: <7xab9hie8i.fsf@ruckus.brouhaha.com> "Rhodri James" writes: > My experience with medium-sized organisations (50-100 people) is that > either you talk to Fred directly, or it doesn't happen. In particular > the more people (especially PHBs) that get involved, the slower the > change will come and the less like your original requirement it will look. Usually there would be enough communication with Fred that Fred is be aware of the problem and the amount of work needed to fix it (maybe you've even submitted a patch that Fred can commit after review and testing), but Fred has ten thousand other things that also need getting done. The job of the PHB's is to stay on top of what issues are important for the overall project and juggle the priorities of individual tasks. They figure out whether developing some feature pushes something else out of the way for the upcoming release, or gets slid off to the next one, or whatever. When they do a good job, that takes a big load off of the programmers. It is, to some extent, also part of the PHB's job to "filter the traffic" and protect both Fred and you from making too many interruptions for each other. This is especially important if you're the type of programmer who tends to get their hands in a lot of different areas of a project. From http Fri Jan 23 22:19:42 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:19:42 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> Message-ID: <7x63k5ie5t.fsf@ruckus.brouhaha.com> Bryan Olson writes: > > BTW, class instances are usually immutable and thus don't require a > > mutex in the system I described. > Then you are describing a language radically different from Python. That one threw me for a minute too, but I think the idea is that the class instance itself is immutable, while its slots (specifically the attribute dictionary) point to mutable objects. From skip at pobox.com Fri Jan 23 22:29:10 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 23 Jan 2009 21:29:10 -0600 Subject: Stalled ticket in Python bug tracker In-Reply-To: <018a4c38$0$20629$c3e8da3@news.astraweb.com> References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> <018a4c38$0$20629$c3e8da3@news.astraweb.com> Message-ID: <18810.35590.11216.469897@montanaro.dyndns.org> Steven> I meant bringing it to the attention of somebody who can Steven> actually commit the patch to production, or rule that the patch Steven> isn't suitable. I can't do that. Perhaps not, but you can help the process along by adding your perspective. Does it solve a problem you have? Does it run on your platform? Can you provide further examples? Can you add missing parts to what's already there (doc changes, test cases)? These are general questions which won't be appropriate for every issue in the tracker, but are some ways Python users without checkin privileges can help the development process. Steven> Sorry for the naive questions, I'm new to the bug tracker and Steven> I'm not entirely sure about the protocol. Should I just drop a Steven> note to python-dev and ask somebody with commit privileges to Steven> look at it, or is that rude? You might want to peruse some of the links on this page: http://www.python.org/dev/ That might give you some insight into the Python development process and how you fit into it. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From steve at REMOVE-THIS-cybersource.com.au Fri Jan 23 22:35:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 03:35:06 GMT Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> Message-ID: <018a82b7$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 18:54:18 -0800, Carl Banks wrote: > On Jan 23, 5:48?pm, Bryan Olson wrote: >> Carl Banks wrote: >> >> [...] >> >> > BTW, class instances are usually immutable and thus don't require a >> > mutex in the system I described. >> >> Then you are describing a language radically different from Python. > > Bzzt. > > Hint: aside from the reference count, most class instances are immutable > in Python *today*. That seems so utterly wrong that either you're an idiot or you're talking at cross purposes to what Bryan and I think you're saying. Since I know you're not an idiot, I can only imagine you have a different understanding of what it means to be immutable than I do. For example... is this instance immutable? class Foo: bar = None f = Foo() f.baz = True If so, what do you mean by immutable? -- Steven From http Fri Jan 23 22:42:20 2009 From: http (Paul Rubin) Date: 23 Jan 2009 19:42:20 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <09f17e0b-ed2b-4310-afb8-27908c7bd86e@k1g2000prb.googlegroups.com> <018a82b7$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7xprid2wv7.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > For example... is this instance immutable? > > class Foo: > bar = None > > f = Foo() > f.baz = True > If so, what do you mean by immutable? If I understand Carl, yes, f is immutable. When you set f.bar, the contents of f.__dict__ changes but f itself does not change. It still points to the same dictionary, etc. From rhodri at wildebst.demon.co.uk Fri Jan 23 22:47:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 24 Jan 2009 03:47:39 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xab9hie8i.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <56ed5be1-f406-4d21-97f7-f0f1aea00b76@s9g2000prg.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> <7xab9hie8i.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 24 Jan 2009 03:18:05 -0000, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > It is, to some extent, also > part of the PHB's job to "filter the traffic" and protect both Fred > and you from making too many interruptions for each other. This is > especially important if you're the type of programmer who tends to get > their hands in a lot of different areas of a project. In a perfect environment this is true. In an environment where the PHBs are overstretched because their PHBs aren't up to much, that filter function tends to become a full roadblock. Under those circumstances you have three choices: 1) defeat the data hiding by talking to Fred directly; 2) defeat the data hiding by hacking away yourself and getting Fred's forgiveness later; 3) give up. See, we're back on topic! -- Rhodri James *-* Wildebeeste Herder to the Masses From wuwei23 at gmail.com Fri Jan 23 23:02:03 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 23 Jan 2009 20:02:03 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> Message-ID: <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> On Jan 24, 10:56?am, r wrote: > [...] *not being afraid to open my mouth about it, fight for it, free > others from their bonds* [...] > Come down from your tower of *righteousness* Deiz, loosen up that stiff- > upper-lip and bring your brown-nosing minions with you! (emphasis mine to highlight the humorous hypocrisy) Let's see, one poster consistently posts helpful and usable coding advice...the other is on some bizarre, self-aggrandising jihad. I wonder to whom people in this group will actually pay attention... And let's face it, r, the only reason you're lashing out at Diez about his 'minions' is from your complete inability to gain any of your own in your misguided crusade. Done any coding lately? How's that Python bridge to SketchUp coming along? It's been months already, surely you've invested as much effort into learning Python as you have in talking about it? From fakeaddress at nowhere.org Fri Jan 23 23:22:31 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 20:22:31 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x63k5ie5t.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >>> BTW, class instances are usually immutable and thus don't require a >>> mutex in the system I described. >> Then you are describing a language radically different from Python. > > That one threw me for a minute too, but I think the idea is that the > class instance itself is immutable, while its slots (specifically the > attribute dictionary) point to mutable objects. The meaning of 'immutable' is well-established in the Python literature. Python's immutable types include tuple, frozenset, and various kinds of numbers and strings. Class instances, not so much. What's more, this matters when considering a GIL-less implementation. Typical method calls can traverse lots of mutable stuff just to find the function to invoke. -- --Bryan From ptmcg at austin.rr.com Fri Jan 23 23:25:42 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 23 Jan 2009 20:25:42 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: On Jan 23, 8:58?pm, Linuxguy123 wrote: > I just started using python last week and I'm addicted. > > I see a lot of Python in my future. Bravo, welcome, and well-said! Your sentiments mirror and resonate with those of many on this list. About 6 years ago I wanted a scripting language to work with, *anything* but more Tcl/Tk! Python the language had many features and language design decisions that just "felt right," and the natural feel of the object model allowed me to leverage much of the OO theory I had learned using Java and C++. And THEN, it began to dawn on me that a lot of that theory is actually crutch, bailing-wire, and gum, put there to work around the static typing rigidity of C++, Java and their ilk. As much as I loved Scott Meyers' "Effective C++" books, many of their idioms and tricks just fall away as unnecessary in Python. Interfaces? Python don't need no steenking interfaces! The interface concept is still useful for organizing your thinking and OO design, but the implementation is far freer, as you find that an object's conformance to an interface is only determined/required at runtime, not at some long-distant compile step in a library nested N levels deep in your hierarchy. Python exposes many of its dynamic hooks through magic __xxx__ methods. Need to write a proxy wrapper around an object of type X to supercede method Y, but you don't want to write all thouse tedious passthru methods for the X class's methods A thru R? Just implement your special method Y, and let a __getattr__ method pass all the other calls on to the underlying object. Instant Proxy! Want to change the type/behavior of an object from class A to class B? How about this: aobj = A() aobj.__class__ = B Try *that* in as simple-looking C++ or Java! Python's learning curve can be gentle or steep, depending on your own inclination. My advice? Push yourself up as quickly as you can. Quickly put aside this kind of code: for i in range(len(datalist)): # do something with datalist[i] and start thinking in iterators: for item in datalist: # do something with item Need to read through a text file? for line in file("xyzzy.dat"): # do something with each line Master the clean look and feel of a list comprehension or generator expression, over explicit for loops. Need to build a list of the odd numbers up to 100? Instead of this: oddnums = [] for n in range(100): if n % 2: oddnums.append(n) learn to do this: oddnums = [ n for n in range(100) if n % 2 ] Learn the native data structures - tuple, list, dict, set. Learn the dict idiom that serves as Pythons version of a switch statement. Check out the itertools module, a cunning mix of elegance and wizardry. The standard lib is a trove of well-oiled and production- tested code, but the community is not shy about producing additional modules, many with liberal licensing - image processing, text processing/parsing, discrete-event simulation, optimization, genetic algorithms, web/network apps and IPC, ... Google and ye shall find. Write a generator method to yield a sequence of useful values (odd numbers, primes, consonants, fibonacci's, whatever). You can certainly write a lot of Python without ever using these intermediate/ advanced features, but one day you'll give it a shot and think "Dang! what was the big deal? I wish I'd tried this sooner!" Yet having said that, in 6 years I've not yet tried to write a C extension for Python. But I'm told that this too is a well-blazed trail if you feel the need. Dig in! And post back here if you get stuck. Be confident that Python has been employed in a wide range of applications and application domains, and that if a particular feature seems to be missing, it may be because Python takes a slightly different angle on the problem. Ah, those heady days of youth, when the world was fresh, and the idioms of Python were still new and ripe to discover! I envy you, Linuxguy123, I envy you... Enjoy! -- Paul From aahz at pythoncraft.com Fri Jan 23 23:25:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:25:59 -0800 Subject: I'm a python addict ! References: Message-ID: In article , Linuxguy123 wrote: > >I just started using python last week and I'm addicted. Welcome! Just be aware that excessive Perl-bashing is considered somewhat tasteless on this newsgroup, but the occasional snide comment should be fine. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Fri Jan 23 23:27:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:27:50 -0800 Subject: How do I get my python program to get the root password ? References: Message-ID: In article , Linuxguy123 wrote: > >I want to make a python program that I can run as a normal user that >changes the permission on some device files. It will need to ask me for >the root password and then run chown as root in order to do this. > >How do I accomplish this (easily) ? The easiest -- really -- is to just make it a root script and run it with sudo. If you're on Ubuntu, that's pretty much the only option (without resorting to complicated ways of running sudo) -- the standard Ubuntu setup doesn't have a root password. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From pavlovevidence at gmail.com Fri Jan 23 23:28:01 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 20:28:01 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> On Jan 23, 7:19?pm, Paul Rubin wrote: > Bryan Olson writes: > > > BTW, class instances are usually immutable and thus don't require a > > > mutex in the system I described. > > Then you are describing a language radically different from Python. > > That one threw me for a minute too, but I think the idea is that the > class instance itself is immutable, while its slots (specifically the > attribute dictionary) point to mutable objects. Correct, and, getting back to the point, an instance itself would not require a mutex. The dict would need it, of course. It's customary to gloss over this technicality for convenience's sake in most discussions, but it matters in this case. Carl Banks From http Fri Jan 23 23:32:22 2009 From: http (Paul Rubin) Date: 23 Jan 2009 20:32:22 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <7xhc3pqq7d.fsf@ruckus.brouhaha.com> Bryan Olson writes: > The meaning of 'immutable' is well-established in the Python > literature. Python's immutable types include tuple, frozenset, and > various kinds of numbers and strings. Class instances, not so much. But we are talking about objects as they live in the C implementation, not at the level where Python code deals with them. From aahz at pythoncraft.com Fri Jan 23 23:32:22 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:32:22 -0800 Subject: Relax Syntax for Augmented Arithmetic? References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article , Steve Holden wrote: > >I understand what you are saying, but if the id() associated with a name >doesn't change after augmented assignment it seems a little wrong-headed >to argue that "the augmented assignment always binds a new value to the >name". > >What you are actually saying is that it's up to the method that >implements the augmented assignment whether the same (mutated) object or >a different one is returned, right? And that the left-hand side of the >assignment is always bound to the result of that method. That's overall more correct, but I wanted to emphasize that there is *always* a binding operation being performed. Whether what gets bound to the target is a new object or an existing object is up to the augmented assignment method. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Fri Jan 23 23:34:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jan 2009 20:34:04 -0800 Subject: seeking to improve Python skills References: <20090123133418.24460.1784903739.divmod.quotient.430@henry.divmod.com> Message-ID: In article , mk wrote: > >However, unit tests are a tougher cookie, do you have any resource >that's truly worth recommending for learning unit tests? Start with the doctest module. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 00:20:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 05:20:07 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <877i4lbhv4.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <018a9b54$0$20629$c3e8da3@news.astraweb.com> On Sat, 24 Jan 2009 01:41:35 +0000, Mark Wooding wrote: > Steven D'Aprano writes: ... >> As I see it, you have two coherent positions. On the one hand, you >> could be like Mark Wooding, and say that Yes you want to risk buffer >> overflows by messing with the internals > > Please, point out where I said that! > > I'm pretty sure that the only time I commented on this particular point > (in message <87y6x2cih0.fsf.mdw at metalzone.distorted.org.uk>), I said: [snip] Yes, that was the quote I was thinking of. > While I realise I didn't spell it out, the semantics I had in mind where > > foo.len = n > > means > > if n < 0: > raise ValueError, 'don\'t be stupid' > elif len(foo) < n: > foo += [None] * (n - len(foo)) > else: > foo[n:] = [] But that's not "messing with the internals". That's the conceptual equivalent of a Python getter/setter: # Pseudo-code, untested and incomplete class MyList(list): def __init__(self): self._length = 0 def _getlength(self): return self._length def _setlength(self, n): if n < 0: raise ValueError("don't be stupid") elif len(self) < n: self += [None] * (n - len(self)) else: self[n:] = [] self._length = n len = property(_getlength, _setlength) alist = MyList() alist.length = 1000 # safe This is hardly what "messing with the internals" is! If your idea of modifying hidden, implementation-specific details is "use a safe getter/ setter implementation that holds your hand and protects you from doing anything stupid", then no wonder you object to data hiding. I'd object to it to, if that's what I understood by it. What I'm talking about is unsafe, direct access to the underlying C slots with no hand-holding. You know: messing with the internals with no nice safe interface between you and disaster: alist._length = 2**128 # unsafe! > Safety is good. Escape hatches are good, too. Something we can agree on. >> In the second case, the next question is, why should it only be code >> written in C that is allowed that protection? > > Because Python code can't cause those sorts of problems without > resorting to the escape hatches (e.g., ctypes). And, very > significantly, because C code /needs/ that protection and Python > basically doesn't. > > The basic difference is that C code is fundamentally brittle: if you > mess up its invariants, it can crash horribly and possibly allow its > brain to be taken over by evil people. Python code is fundamentally > robust. The worst that can happen[1] is that the interpreter raises an > exception. This makes it ideally suited to having a more relaxed > attitude to life. And that, in turn, makes it approachable, hackable > interactively, fun! No, it's not the worst that can happen. "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." http://www.pphsg.org/cdsmith/types.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 00:34:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 05:34:16 GMT Subject: is None vs. == None References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018a9ea5$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 20:33:45 -0500, Steve Holden wrote: > Steven D'Aprano wrote: >> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: >> >>> Hi -- Some time ago I ran across a comment recommending using is >>> None instead of == None (also is not None, etc.) >> >> That entirely depends on whether you wish to test for something which >> *is* None or something with *equals* None. Those two things have >> different meanings. >> > No they don't, because the language *guarantees* the None object is a > singleton, so anything that *equals* None *is* None. Twice in one day. Have they put funny chemicals in the water over there? *wink* Steve, in case you missed my earlier response: >>> class Empty: ... def __eq__(self, other): ... return not bool(other) ... >>> e = Empty() >>> e == None True >>> e is None False An instance that compares equal to anything false doesn't strike me as particularly bizarre or pathological. For instance, the Python Cookbook has an implementation for the Null object pattern. The implementation given compares unequal to everything, but suggests defining an appropriate __eq__ if you need different behaviour. -- Steven From Russ.Paielli at gmail.com Sat Jan 24 00:35:37 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 21:35:37 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > Makes *no* sense? There's *no* good reason *at all* for the original > > author to hide or protect internals? > > My bad, sorry. > It makes sense... if the original author is an egotist who believes he must > control how I use that library. If the original author provides you with the source code and the right to modify it, he cannot possibly control how you use the library. You can trivially disable any access controls. But for some reason that's not enough for you. Has it occurred to you that some users might actually *want* access controls? Maybe some users want to actually use the library as the author intended it to be used. What a bizarre concept! Oh, but only a paranoid fool could possibly want access controls, eh? Who's the egotist here? From pavlovevidence at gmail.com Sat Jan 24 00:36:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 21:36:25 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> Message-ID: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> On Jan 23, 8:22?pm, Bryan Olson wrote: > Paul Rubin wrote: > > Bryan Olson writes: > >>> BTW, class instances are usually immutable and thus don't require a > >>> mutex in the system I described. > >> Then you are describing a language radically different from Python. > > > That one threw me for a minute too, but I think the idea is that the > > class instance itself is immutable, while its slots (specifically the > > attribute dictionary) point to mutable objects. > > The meaning of 'immutable' is well-established in the Python literature. > Python's immutable types include tuple, frozenset, and various kinds of > numbers and strings. Class instances, not so much. Of course class instances aren't immutable types: they're not even types. Let me suggest that there is a distinction between an immutable type and an immutable object. Immutable types are what you are talking about: it means that the type provides usable mutator methods. (Whether they mutate the object itself or some associated object doesn't matter.) Immutable objects are a different thing: it means the object cannot change in memory. Classes in Python are mutable types, usually. Class instances are (except for the refcount) immutable objects, usually. We usually talk about mutability of types, but mutability of objects is appropriate for discussion as well. So I can't really agree with your assessment that I wrong to call class instances immutable objects aside from refcounts. BTW, here's a minor brain bender: immutable types are mutable objects. > What's more, this matters when considering a GIL-less implementation. > Typical method calls can traverse lots of mutable stuff just to find the > function to invoke. Now that doesn't make sense at all. What is all this mutable stuff you have to go through, and what does it have to do with the GIL-less implementation? Can you explain further? Or are you just saying it'll be slow. Carl Banks From http Sat Jan 24 00:40:42 2009 From: http (Paul Rubin) Date: 23 Jan 2009 21:40:42 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: <7x8wp1w9b9.fsf@ruckus.brouhaha.com> Carl Banks writes: > > What's more, this matters when considering a GIL-less implementation. > > Typical method calls can traverse lots of mutable stuff just to find the > > function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? foo.bar() has to look up bar in foo's attribute dictionary. From grante at visi.com Sat Jan 24 00:42:34 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 23 Jan 2009 23:42:34 -0600 Subject: How do I get my python program to get the root password ? References: Message-ID: <_cadnZMM0o7XN-fUnZ2dnUVZ_sTinZ2d@posted.usinternet> On 2009-01-24, Aahz wrote: > In article , > Linuxguy123 wrote: >> >>I want to make a python program that I can run as a normal user that >>changes the permission on some device files. It will need to ask me for >>the root password and then run chown as root in order to do this. >> >>How do I accomplish this (easily) ? > > The easiest -- really -- is to just make it a root script and run it with > sudo. If you're on Ubuntu, that's pretty much the only option (without > resorting to complicated ways of running sudo) -- the standard Ubuntu > setup doesn't have a root password. Though it's easy enough to set the root password, it's not really the "Ubuntu way"... -- Grant From david at abbottdavid.com Sat Jan 24 01:12:47 2009 From: david at abbottdavid.com (David) Date: Sat, 24 Jan 2009 01:12:47 -0500 Subject: How do I get my python program to get the root password ? In-Reply-To: <1232759209.3727.2.camel@localhost.localdomain> References: <1232759209.3727.2.camel@localhost.localdomain> Message-ID: <497AB15F.5050801@abbottdavid.com> Linuxguy123 wrote: > I want to make a python program that I can run as a normal user that > changes the permission on some device files. It will need to ask me for > the root password and then run chown as root in order to do this. > > How do I accomplish this (easily) ? > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > I am new to Python, in my process of learning I did put together an example of pexpect that may help. http://asterisklinks.com/wiki/doku.php?id=wiki:pexpect -david -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From Russ.Paielli at gmail.com Sat Jan 24 01:52:04 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Fri, 23 Jan 2009 22:52:04 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: On Jan 23, 6:58?pm, Linuxguy123 wrote: > I will never write another Perl or Bash script again. I still use bash for orchestrating the execution of a series of other scripts and/or programs (including python programs). I know you can do that in python, but I find bash simpler to use for that purpose. Then again, that may be just because I learned bash before I learned python. From fakeaddress at nowhere.org Sat Jan 24 01:55:32 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 22:55:32 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: Carl Banks wrote: > Paul Rubin wrote: >> Bryan Olson writes: >>>> BTW, class instances are usually immutable and thus don't require a >>>> mutex in the system I described. >>> Then you are describing a language radically different from Python. >> That one threw me for a minute too, but I think the idea is that the >> class instance itself is immutable, while its slots (specifically the >> attribute dictionary) point to mutable objects. > > Correct, and, getting back to the point, an instance itself would not > require a mutex. The dict would need it, of course. The dict is part of the object and some important slots are mutable. What's more, if your point was to do away with the GIL without changing Python semantics nor requiring heaping masses of locking, I fear you've not fully grasped the problem. Languages such as Java, C++, and C# do not require nearly as much locking as Python because they are not nearly as dynamic. Consider how a method is invoked. Java / C++ / C# can always resolve the method with no locking; the data they need is fixed at link time. Python is much more dynamic. A demo: from __future__ import print_function # A simple class hierarchy: class Foo (object): title = "Mr. Foo" def identify(self): print("I'm called", self.title) class Bar (Foo): title = "Ms. Bar" class Jafo (Bar): title = "Major Jafo" dude = Jafo() # Searches 5 dicts to find the function to call: dude.identify() # Class dicts are mutable: def id(self): print("I'm still called", self.title) Jafo.identify = id dude.identify() # An object's class can change: dude.__class__ = Bar dude.identify() # A class's base classes can change: class Fu (object): def identify(self): print("Call me", self.title) Bar.__bases__ = (Fu,) dude.identify() Result: >>> I'm called Major Jafo I'm still called Major Jafo I'm called Ms. Bar Call me Ms. Bar >>> In that first simple call of dude.identify(), Python looked up "dude" in the module's (mutable) dict to find the object. Then it looked in object's (mutable) dict, and did not find "identify". So it looked at the object's (mutable) __class__ slot, and in that class's (mutable) dict. It still did not find "identify", so it looked in the class's (mutable) __bases__ slot, following Python's depth-first "object protocol" and thus looking in what other (mutable) class dicts and (mutable) __bases__ slots were required. An object's __dict__ slot is *not* mutable; thus we could gain some efficiency by protecting the object and its dict with the same lock. I do not see a major win in Mr. Banks' point that we do not need to lock the object, just its dict. -- --Bryan From http Sat Jan 24 02:04:19 2009 From: http (Paul Rubin) Date: 23 Jan 2009 23:04:19 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: <7x63k5chho.fsf@ruckus.brouhaha.com> Bryan Olson writes: > An object's __dict__ slot is *not* mutable; thus we could gain some > efficiency by protecting the object and its dict with the same lock. I > do not see a major win in Mr. Banks' point that we do not need to lock > the object, just its dict. If the dict contents don't change often, maybe we could use an STM-like approach to eliminate locks when reading. That would of course require rework to just about every C function that accesses Python objects. From kay.schluehr at gmx.net Sat Jan 24 02:24:15 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Fri, 23 Jan 2009 23:24:15 -0800 (PST) Subject: Two import questions in Python 3.0 Message-ID: 1. I'd expected that absolute imports are used in Python 3.0 by default. I may be wrong. I've written two versions of a module sucks.py sucks.py ------------- print ("import from lib.sucks") sucks.py ------------- print ("import from package.sucks") The first is placed in the lib directory that is globally visible by means of PYTHONPATH. The second one is placed in a package package/ __init__.py sucks.py A.py The package also contains a module A.py defined by A.py ------ import sucks Running A yields "import from package.sucks" which means unconditional relative import. It shadows the globally visible sucks.py module. I've expected it the other way round. 2. This is kind of a change request. In a former life I used to call test-scripts as test-scripts. The dumb idea was to point e.g. to lib/tests and run python test_ast.py test_nodeclasses (__main__.AST_Tests) ... ok .... test_parse (__main__.ASTHelpers_Test) ... ok ---------------------------------------------------------------------- Ran 12 tests in 0.219s OK The new style is implemented rather in lib2to3. If I point to lib/ lib2to3/tests and run python test_parser.py Traceback (most recent call last): File "test_parser.py", line 12, in from . import support ValueError: Attempted relative import in non-package The standard error of the years to come that makes working with Python harder and reminds me that it is not a scripting language anymore because you can't run anything as a script not even a test. For pedagogical reasons the behavior of test_ast.py and other standard library tests shall show uniform behavior when called from the command line i.e. they shall all fail with this import error message. What do you think? From pavlovevidence at gmail.com Sat Jan 24 02:44:31 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 23 Jan 2009 23:44:31 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> Message-ID: On Jan 23, 10:55?pm, Bryan Olson wrote: > Carl Banks wrote: > > Paul Rubin wrote: > >> Bryan Olson writes: > >>>> BTW, class instances are usually immutable and thus don't require a > >>>> mutex in the system I described. > >>> Then you are describing a language radically different from Python. > >> That one threw me for a minute too, but I think the idea is that the > >> class instance itself is immutable, while its slots (specifically the > >> attribute dictionary) point to mutable objects. > > > Correct, and, getting back to the point, an instance itself would not > > require a mutex. ?The dict would need it, of course. > > The dict is part of the object and some important slots are mutable. > What's more, if your point was to do away with the GIL without changing > Python semantics nor requiring heaping masses of locking, I fear you've > not fully grasped the problem. If that's what you think I thought, I fear you haven't read anything I've written. [snip] > An object's __dict__ slot is *not* mutable; thus we could gain some > efficiency by protecting the object and its dict with the same lock. I > do not see a major win in Mr. Banks' point that we do not need to lock > the object, just its dict. I'm not sure where you got the idea that I was claiming this was a major win. I'm not sure where you got the idea that I claimed that having to lock all mutable objects wouldn't be slow. For Pete's sake, you followed up to a post where I *agreed* that it would be slow. Carl Banks From fakeaddress at nowhere.org Sat Jan 24 02:45:51 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 23 Jan 2009 23:45:51 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: > Bryan Olson wrote: >> Paul Rubin wrote: >>> Bryan Olson writes: >>>>> BTW, class instances are usually immutable and thus don't require a >>>>> mutex in the system I described. >>>> Then you are describing a language radically different from Python. >>> That one threw me for a minute too, but I think the idea is that the >>> class instance itself is immutable, while its slots (specifically the >>> attribute dictionary) point to mutable objects. >> The meaning of 'immutable' is well-established in the Python literature. >> Python's immutable types include tuple, frozenset, and various kinds of >> numbers and strings. Class instances, not so much. > > Of course class instances aren't immutable types: they're not even > types. Class instances my or may not be types, but that has nothing to do with any point at issue here. I'm saying that class instances are usually, mutable, contrary to your claim, "class instances are usually immutable". > Let me suggest that there is a distinction between an > immutable type and an immutable object. Let me further suggest that Python's documentation is entirely clear: instances of immutable types are immutable objects. Instances of mutable types are generally mutable objects. For example, tuple is an immutable type, and thus tuples are immutable; list is a mutable type, and thus lists are mutable. > Immutable types are what you are talking about: it means that the type > provides usable mutator methods. (Whether they mutate the object > itself or some associated object doesn't matter.) Immutable objects > are a different thing: it means the object cannot change in memory. > > Classes in Python are mutable types, usually. Class instances are > (except for the refcount) immutable objects, usually. There's where we disagree. I assert that class instances are usually mutable objects. > We usually talk about mutability of types, but mutability of objects > is appropriate for discussion as well. So I can't really agree with > your assessment that I wrong to call class instances immutable objects > aside from refcounts. That confusion disappears once one grasps that instances of immutable types are immutable objects. > BTW, here's a minor brain bender: immutable types are mutable objects. Some brains are too easily bent. Python is one of the many object-oriented languages that reifies types as run-time objects. I see no point in going through Python's immutable types to examine if there is any way to mutate the corresponding type objects. >> What's more, this matters when considering a GIL-less implementation. >> Typical method calls can traverse lots of mutable stuff just to find the >> function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? Can you explain further? Or are you just saying > it'll be slow. I elaborated at some length in another strand of this thread. -- --Bryan From pavlovevidence at gmail.com Sat Jan 24 03:06:02 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 00:06:02 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> On Jan 23, 11:45?pm, Bryan Olson wrote: > Carl Banks wrote: > > Classes in Python are mutable types, usually. ?Class instances are > > (except for the refcount) immutable objects, usually. > > There's where we disagree. I assert that class instances are usually > mutable objects. Nope, you're dead wrong, nothing more to it. The bits of a class instance never change. The __dict__ is a mutable object. The class instance itself isn't. It's not reasonable to call an object whose bits can't change a mutable obect. Anyway, all you're doing is distracting attention from my claim that instance objects wouldn't need to be locked. They wouldn't, no matter how mutable you insist these objects whose bits would never change are. > > BTW, here's a minor brain bender: immutable types are mutable objects. > > Some brains are too easily bent. [Snip attempt to take this comment seriously] And some brains are so stodgy they can't even take a lighthearted comment lightheartedly. Carl Banks From gagsl-py2 at yahoo.com.ar Sat Jan 24 03:21:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 06:21:20 -0200 Subject: Two import questions in Python 3.0 References: Message-ID: En Sat, 24 Jan 2009 05:24:15 -0200, Kay Schluehr escribi?: > 1. I'd expected that absolute imports are used in Python 3.0 by > default. I may be wrong. I've written two versions of a module > sucks.py > > sucks.py > ------------- > print ("import from lib.sucks") > > sucks.py > ------------- > print ("import from package.sucks") > > The first is placed in the lib directory that is globally visible by > means of PYTHONPATH. The second one is placed in a package > > package/ > __init__.py > sucks.py > A.py > > The package also contains a module A.py defined by > > A.py > ------ > import sucks > > Running A yields "import from package.sucks" which means unconditional > relative import. It shadows the globally visible sucks.py module. I've > expected it the other way round. If you run A.py as a script, it does not "know" it lives inside a package. You must *import* A for it to become aware of the package. Also, the directory containing the script comes earlier than PYTHONPATH entries in sys.path -- so watch for that case too. > python test_parser.py > Traceback (most recent call last): > File "test_parser.py", line 12, in > from . import support > ValueError: Attempted relative import in non-package > > The standard error of the years to come that makes working with Python > harder and reminds me that it is not a scripting language anymore > because you can't run anything as a script not even a test. I always consider that packages are libraries. Application code "uses" a library (by importing things from it). Test code should mimic closely that behavior: my tests always import the package, like the application would do. Anyway I should revisit the strategy, I've not evaluated yet how much is affected by absolute imports and other changes in 3.0 -- Gabriel Genellina From mail at microcorp.co.za Sat Jan 24 03:29:19 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 24 Jan 2009 10:29:19 +0200 Subject: The First Law Of comp.lang.python Dynamics References: <21227e90-3894-4d5d-8d9f-366b1ee7ba01@v5g2000pre.googlegroups.com> <497a2cce$0$183$e4fe514c@news.xs4all.nl> Message-ID: <000c01c97e12$990dcf60$0d00a8c0@hendrik> "Martin P. Hellwig" wrote: > Or you can argue that even when an argument is repeated indefinitely it > doesn't make it suddenly right. This is no good. It's a well known fact that anything I tell you three times is true. To demonstrate: Tim Rowe's post earlier in this thread was the funniest one in a long time. Tim Rowe's post earlier in this thread was the funniest one in a long time. Tim Rowe's post earlier in this thread was the funniest one in a long time. see - it's true! - Hendrik From hniksic at xemacs.org Sat Jan 24 03:33:58 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 24 Jan 2009 09:33:58 +0100 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: <87hc3pf6h5.fsf@mulj.homelinux.net> Carl Banks writes: > On Jan 23, 11:45?pm, Bryan Olson wrote: >> Carl Banks wrote: >> > Classes in Python are mutable types, usually. ?Class instances are >> > (except for the refcount) immutable objects, usually. >> >> There's where we disagree. I assert that class instances are usually >> mutable objects. > > Nope, you're dead wrong, nothing more to it. The bits of a class > instance never change. The __dict__ is a mutable object. The class > instance itself isn't. It's not reasonable to call an object whose > bits can't change a mutable obect. The "bits" of class instances can very well change. >>> class X(object): pass ... >>> x = X() >>> d = x.__dict__ >>> x.__dict__ = {} >>> map(id, [d, x.__dict__]) [170329876, 170330012] The Python cookbook even describes patterns that depend on this operation working. Class instance's contents can also change if __slots__ is in use, when its __class__ is assigned to (admittedly the latter being a rare operation, but still). > Anyway, all you're doing is distracting attention from my claim that > instance objects wouldn't need to be locked. They wouldn't, no > matter how mutable you insist these objects whose bits would never > change are. Only if you're not implementing Python, but another language that doesn't support __slots__ and assignment to instance.__dict__. From __peter__ at web.de Sat Jan 24 03:39:21 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jan 2009 09:39:21 +0100 Subject: Stalled ticket in Python bug tracker References: <0189ceca$0$20671$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I'm interested in this ticket in the bug tracker: > > http://bugs.python.org/issue2527 > > but it seems to have been stalled for nine months. Is there a procedure > for starting it up again? Should I ask about it on the python-dev mailing > list, or just wait until somebody happens to notice it? > > Peter Otten, if you're reading this, is your offer to jump through the > necessary hoops still standing? I guess what killed any chance for the patch to be included was that there was a "competing" patch that I asked to be reversed. Also, just saying that you are willing to provide docs and test didn't work either. What's needed then as a 'sine qua non' is an updated patch against the tip with documentation and tests. If you don't beat me to it I may give it another try, but probably not before next month. Peter From gagsl-py2 at yahoo.com.ar Sat Jan 24 03:40:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 06:40:10 -0200 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: En Sat, 24 Jan 2009 06:06:02 -0200, Carl Banks escribi?: > On Jan 23, 11:45?pm, Bryan Olson wrote: >> Carl Banks wrote: >> > Classes in Python are mutable types, usually. ?Class instances are >> > (except for the refcount) immutable objects, usually. >> >> There's where we disagree. I assert that class instances are usually >> mutable objects. > > Nope, you're dead wrong, nothing more to it. The bits of a class > instance never change. The __dict__ is a mutable object. The class > instance itself isn't. It's not reasonable to call an object whose > bits can't change a mutable obect. > > Anyway, all you're doing is distracting attention from my claim that > instance objects wouldn't need to be locked. They wouldn't, no matter > how mutable you insist these objects whose bits would never change > are. Me too, I don't get what you mean. Consider a list instance, it contains a count of allocated elements, and a pointer to some memory block. They change when the list is resized. This counts as "mutable" to me. I really don't understand your claim. -- Gabriel Genellina From http Sat Jan 24 03:43:23 2009 From: http (Paul Rubin) Date: 24 Jan 2009 00:43:23 -0800 Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <87ljt1g794.fsf@mulj.homelinux.net> Message-ID: <7x63k52ixg.fsf@ruckus.brouhaha.com> Hrvoje Niksic writes: > Not only registered at the beginning of the function, but also (since > CPython uses C, not C++) explicitly unregistered at every point of > exit from the function. Emacs implements these as macros called GCPRO > and UNGCPRO, and they're very easy to get wrong. In a way, they are > even worse than the current Python INCREF/DECREF. That's a fairly natural style in Lisp implementation and it is not that difficult to code in. I've hacked inside Emacs and have written another interpreter with a similar setup; it's certainly easier than keeping track of refcounts in my experience. For one thing, you can raise exceptions anywhere you want, and the stack unwind can clean up the gc protection, but it can't know nearly as easily which refcounts to adjust, unless you record all the increfs the same way as the GCPROs. From dunmer at dreams.sk Sat Jan 24 03:52:57 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 09:52:57 +0100 Subject: Web authentication urllib2 Message-ID: <497AD6E9.9080909@dreams.sk> Hello, I'm new in Python and i would like to write script which need to login to a website. I'm experimenting with urllib2, especially with something like this: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(username='user', password='pass')) f = opener.open('https://web.com', params) data = f.read() f.close() And the problem is, that this code logs me in on some sites, but on others doesn't, especially on the one I really need to login. And i don't know why. So is there some way how to debug this code and find out why that script cannot login on that specific site? Sorry if this question is too lame, but i am really beginner both in python and web programming .) From dunmer at dreams.sk Sat Jan 24 03:52:57 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 09:52:57 +0100 Subject: Web authentication urllib2 Message-ID: <497AD6E9.9080909@dreams.sk> Hello, I'm new in Python and i would like to write script which need to login to a website. I'm experimenting with urllib2, especially with something like this: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(username='user', password='pass')) f = opener.open('https://web.com', params) data = f.read() f.close() And the problem is, that this code logs me in on some sites, but on others doesn't, especially on the one I really need to login. And i don't know why. So is there some way how to debug this code and find out why that script cannot login on that specific site? Sorry if this question is too lame, but i am really beginner both in python and web programming .) From steve at holdenweb.com Sat Jan 24 03:57:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 03:57:30 -0500 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: Benjamin Peterson wrote: > Robin Becker NOSPAMreportlab.com> writes: >> Well that's not really acceptable as a solution is it? :) > > This doesn't happen in Python 3.0, > so you could port to that. :) > > In 2.7, the better recursion depth > handling > in Py3k may be backported,but the > best you can do for now is not touch > the recursion limit or just shut > the error up. > Perhaps an interim solution would implement an error message more helpful in ensuring the exception not be raised? This is currently a bit like "Your code is wrong": strictly correct, and totally unhelpful. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 03:58:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 03:58:40 -0500 Subject: Relax Syntax for Augmented Arithmetic? In-Reply-To: References: <87hc3un1vn.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Aahz wrote: > In article , > Steve Holden wrote: >> I understand what you are saying, but if the id() associated with a name >> doesn't change after augmented assignment it seems a little wrong-headed >> to argue that "the augmented assignment always binds a new value to the >> name". >> >> What you are actually saying is that it's up to the method that >> implements the augmented assignment whether the same (mutated) object or >> a different one is returned, right? And that the left-hand side of the >> assignment is always bound to the result of that method. > > That's overall more correct, but I wanted to emphasize that there is > *always* a binding operation being performed. Whether what gets bound to > the target is a new object or an existing object is up to the augmented > assignment method. Yes, we're on the same page. Maybe I was being too pedantic ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 04:02:34 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 04:02:34 -0500 Subject: is None vs. == None In-Reply-To: <018a9ea5$0$20629$c3e8da3@news.astraweb.com> References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <018a9ea5$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 23 Jan 2009 20:33:45 -0500, Steve Holden wrote: > >> Steven D'Aprano wrote: >>> On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: >>> >>>> Hi -- Some time ago I ran across a comment recommending using is >>>> None instead of == None (also is not None, etc.) >>> That entirely depends on whether you wish to test for something which >>> *is* None or something with *equals* None. Those two things have >>> different meanings. >>> >> No they don't, because the language *guarantees* the None object is a >> singleton, so anything that *equals* None *is* None. > > Twice in one day. Have they put funny chemicals in the water over there? > *wink* > Nope, but you know what newsgroup response propagation is like ... > Steve, in case you missed my earlier response: > >>>> class Empty: > ... def __eq__(self, other): > ... return not bool(other) > ... >>>> e = Empty() >>>> e == None > True >>>> e is None > False > > > An instance that compares equal to anything false doesn't strike me as > particularly bizarre or pathological. For instance, the Python Cookbook > has an implementation for the Null object pattern. The implementation > given compares unequal to everything, but suggests defining an > appropriate __eq__ if you need different behaviour. > Sure, my syllogism was not strictly true, hence my final quote: > Of course there can be pathological objects with bizarre comparison > methods. And the "is" test helps avoid them. Personally I believe that the Empty class is at least slightly pathological. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fakeaddress at nowhere.org Sat Jan 24 04:11:14 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 24 Jan 2009 01:11:14 -0800 Subject: Securing a database In-Reply-To: <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> References: <6ttaf5Fc79elU1@mid.uni-berlin.de> <42iel.19143$ZP4.8067@nlpi067.nbdc.sbc.com> <95fa4416-f8d7-4fb6-a548-957d4a589413@r36g2000prf.googlegroups.com> Message-ID: <2SAel.11592$D32.10293@flpi146.ffdc.sbc.com> kt83313 at gmail.com wrote: > Thank you very much Bryan. > It does look like this is out of my league. As Peter Pearson noted, "It is out of *everyone's* league." And Peter used to work for Cryptography Research, a small company that scored as high in this league as anyone. Maybe you can advance the state of the art in DRM; but if so, you can probably make more money on that than on selling access to this particular database. Stepping back, KT, you said that your company currently provides an on-line service backed by this database. Maybe you want to stick with that. Can you say what prompts you to look at offering off-line access to your customers? I've spent most of my career, so far, as a cryptologic engineer, and I've seen similar problems. For example, the U.S. Postal Service has a database of valid addresses and address forwarding requests that can provide reasonable and valuable services, but that they are barred by law from generally exposing. Users are allowed to check the validity of a name-and-address, and if they have one, they're allowed to know if the addressee has forwarded it, and if so, to where. At the time I got involved with the USPS's FASTforward system, they offered an Internet service, and an off-line locally-accessible product. The off-line product was a black-box system -- literally: a PC-class computer in locked black case, with hardened epoxy gumming up most of the interface ports. An open SCSI port answered legitimate forwarding requests, and the CD drive accepted encrypted updates to the database. A similar scheme might still play, but there's no question that times have changed. Back then, the USPS system of locked black boxes made sense. Users numbered more than a hundred but less than a thousand, and the Post Office required agreement to a contract that protected individual addresses. -- --Bryan From kay.schluehr at gmx.net Sat Jan 24 04:37:21 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 01:37:21 -0800 (PST) Subject: Two import questions in Python 3.0 References: Message-ID: On 24 Jan., 09:21, "Gabriel Genellina" wrote: > If you run A.py as a script, it does not "know" it lives inside a package. > You must *import* A for it to become aware of the package. > Also, the directory containing the script comes earlier than PYTHONPATH > entries in sys.path -- so watch for that case too. Thanks, yes. I always make the same error thinking that a directory with the ritual __init__ file is actually a package ( as some kind of platonic entity ), something that is more obvious to me than it is to the runtime. The relative import semantics introduced with Python 2.5 has made the error just visible that was hidden to me for about a decade. Shit. From robin at NOSPAMreportlab.com Sat Jan 24 04:40:08 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 24 Jan 2009 09:40:08 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> Message-ID: <497AE1F8.5040008@jessikat.plus.net> Steve Holden wrote: > Benjamin Peterson wrote: >> Robin Becker NOSPAMreportlab.com> writes: >>> Well that's not really acceptable as a solution is it? :) >> This doesn't happen in Python 3.0, >> so you could port to that. :) my initial attempts in this direction were even less successful :( ........ > Perhaps an interim solution would implement an error message more > helpful in ensuring the exception not be raised? This is currently a bit > like "Your code is wrong": strictly correct, and totally unhelpful. well after wrapping all the calls to isinstance I think I have found the particular call and args that are causing the problem, but I still don't really understand why the problem is occurring. -- Robin Becker From gagsl-py2 at yahoo.com.ar Sat Jan 24 05:05:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 08:05:16 -0200 Subject: Web authentication urllib2 References: <497AD6E9.9080909@dreams.sk> Message-ID: En Sat, 24 Jan 2009 06:52:57 -0200, Gabriel escribi?: > I'm new in Python and i would like to write script which need to login > to a website. I'm experimenting with urllib2, > especially with something like this: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(username='user', password='pass')) > f = opener.open('https://web.com', params) > data = f.read() > f.close() > > And the problem is, that this code logs me in on some sites, but on > others doesn't, especially on the one I really > need to login. And i don't know why. So is there some way how to debug > this code and find out why that script cannot > login on that specific site? Start by looking at the web page that you normally use to log into the site; probably the form contains more fields than just username and password. In some cases it may be necesary to use ethereal (or any protocol analizer), to see exactly what is actually transmitted when you log in using your browser. Later you may try to reproduce the same thing with Python. -- Gabriel Genellina From steve at holdenweb.com Sat Jan 24 05:23:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 05:23:38 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> Message-ID: Carl Banks wrote: > On Jan 23, 8:22 pm, Bryan Olson wrote: >> Paul Rubin wrote: >>> Bryan Olson writes: >>>>> BTW, class instances are usually immutable and thus don't require a >>>>> mutex in the system I described. >>>> Then you are describing a language radically different from Python. >>> That one threw me for a minute too, but I think the idea is that the >>> class instance itself is immutable, while its slots (specifically the >>> attribute dictionary) point to mutable objects. >> The meaning of 'immutable' is well-established in the Python literature. >> Python's immutable types include tuple, frozenset, and various kinds of >> numbers and strings. Class instances, not so much. > > Of course class instances aren't immutable types: they're not even > types. Let me suggest that there is a distinction between an > immutable type and an immutable object. > > Immutable types are what you are talking about: it means that the type > provides usable mutator methods. (Whether they mutate the object > itself or some associated object doesn't matter.) Immutable objects > are a different thing: it means the object cannot change in memory. > > Classes in Python are mutable types, usually. Class instances are > (except for the refcount) immutable objects, usually. > > We usually talk about mutability of types, but mutability of objects > is appropriate for discussion as well. So I can't really agree with > your assessment that I wrong to call class instances immutable objects > aside from refcounts. > > BTW, here's a minor brain bender: immutable types are mutable objects. > > >> What's more, this matters when considering a GIL-less implementation. >> Typical method calls can traverse lots of mutable stuff just to find the >> function to invoke. > > Now that doesn't make sense at all. What is all this mutable stuff > you have to go through, and what does it have to do with the GIL-less > implementation? Can you explain further? Or are you just saying > it'll be slow. > OK, so we have recently discussed whether objects are values, whether function arguments are passed by reference, whether names are references, and now we are, I suspect, about to have a huge further discussion on the meaning of "immutable". Sometimes I start to find this eternal pedantry a little tedious. I suspect it's time I once more dropped out of c.l.py for a while. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 05:36:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 05:36:58 -0500 Subject: Web authentication urllib2 In-Reply-To: <497AD6E9.9080909@dreams.sk> References: <497AD6E9.9080909@dreams.sk> Message-ID: Gabriel wrote: > Hello, > > I'm new in Python and i would like to write script which need to login > to a website. I'm experimenting with urllib2, > especially with something like this: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(username='user', password='pass')) > f = opener.open('https://web.com', params) > data = f.read() > f.close() > > And the problem is, that this code logs me in on some sites, but on > others doesn't, especially on the one I really > need to login. And i don't know why. So is there some way how to debug > this code and find out why that script cannot > login on that specific site? > > Sorry if this question is too lame, but i am really beginner both in > python and web programming .) > That's actually pretty good code for a newcomer! There are a couple of issues you may be running into. First, not all sites use "application-based" authentication - they may use HTTP authentication of some kind instead. In that case you have to pass the username and password as a part of the HTTP headers. Michael Foord has done a fair write-up of the issues at http://www.voidspace.org.uk/python/articles/authentication.shtml and you will do well to read that if, indeed, you need to do basic authentication. Second, if it *is* the web application that's doing the authentication in the sites that are failing (in other words if the credentials are passed in a web form) then your code may need adjusting to use other field names, or to include other data as required by the login form. You can usually find out what's required by reading the HTML source of the page that contains the login form. Thirdly [nobody expects the Spanish Inquisition ...], it may be that some sites are extraordinarily sensitive to programmed login attempts (possible due to spam), typically using a check of the "Agent:" HTTP header to "make sure" that the login attempt is coming from a browser and not a program. For sites like these you may need to emulate a browser response more fully. You can use a program like Wireshark to analyze the network traffic, though you can get add-ons for Firefox that will show you the HTTP headers on request and response. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From seelasarasalomi at gmail.com Sat Jan 24 05:44:07 2009 From: seelasarasalomi at gmail.com (porkodi) Date: Sat, 24 Jan 2009 02:44:07 -0800 (PST) Subject: Python Message-ID: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> www.easythings5.blogspot.com From steve at REMOVE-THIS-cybersource.com.au Sat Jan 24 06:07:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jan 2009 11:07:19 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018aecb2$0$20629$c3e8da3@news.astraweb.com> On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: > Quoting Steven D'Aprano : > >> On Fri, 23 Jan 2009 13:07:55 -0500, Luis Zarrabeitia wrote: >> >> > It should be in _our_ power as the team of all participant coders on >> > _our_ project to decide if we should mess with the internals or not. >> > >> > What makes no sense is that it should be in the original author's >> > power to decide, if he is not part of _our_ team. >> >> Makes *no* sense? There's *no* good reason *at all* for the original >> author to hide or protect internals? > > My bad, sorry. > It makes sense... if the original author is an egotist who believes he > must control how I use that library. Then I guess Guido must be such an egotist, because there's plenty of internals in Python that you can't (easy) mess with. > Or, if external forces make him do > it (maybe like, 'oh, if I change python, then I'm not using python > anymore'). That parenthesised comment makes no sense to me. Python has changed significantly since it was first released. Recently, print became a function instead of a statement, and one of the motivations for this was to allow people to change the behaviour of Python's print simply by defining a new function. "Shadowing built-ins", as they call it, is a feature, not a bug. I can't see any good reason for thinking that if you change (say) the way Python prints, you don't have Python any more. Even more fundamental changes have occurred, e.g. new style classes, ABCs, nested scopes. [...] > If a variable is marked as... I don't like 'private', I'll call it > 'implementation detail', I would not use it without good reason. Not > even by subclassing it. Why do you assume that I'd change list._length > if I could? I wouldn't. I didn't say you would change it on a whim. I said that *if* it were exposed to Python code, you *could* change it. You might change it because you thought you had a good reason to. You might change it by accident. You might not realise the consequences of changing it. Who knows? It doesn't matter what your motives are. My point is that you claimed that there is no good reason at all for hiding implementation details. Python is full of implementation details which are quite effectively hidden from Python programmers. So there are two possibilities: (1) you are right that it "makes no sense" (your words) for the original author (in this case, Guido) to hide those implementation details from Python programmers; or (2) you are wrong that it "makes no sense", because there is at least one case where the original author (Guido again) did a sensible thing by hiding implementation details. In an effort to avoid going round and round in circles, let me explicitly say that option (2) does not imply that it always makes sense to hide implementation details. > Anyway, did you notice that your "counter-example" was a radical > change-the-way-python-works scenario? No, my scenario is merely extending what you can already do with pure- Python classes to built-in classes written in C. It would have a radical effect (pure Python code could core dump easily) but it wouldn't be a radical change. It might take as little as one new function. [...] >> So what you're saying is that the fundamental design of Python -- to be >> a high-level language that manages memory for you while avoiding >> common programming errors such as buffer overflows -- makes "no sense". >> Is that what you intended? > > Yes, that's what I intended, obviously. I'd like to have buffer > overflows in python. In case you don't understand irony: don't go > putting words in my mouth. I'm not putting words in yours. And neither am I. I'm pointing out the logical implications of your position. If you find those implications unpleasant, then perhaps you should modify your position to be less extreme and more realistic. >> As I see it, you have two coherent positions. On the one hand, you >> could be like Mark Wooding, and say that Yes you want to risk buffer >> overflows by messing with the internals -- in which case I'm not sure >> what you see in Python, which protects so many internals from you. Or >> you can say that you made a mistake, that there are *some* good reasons >> to protect/hide internals from external access. > > Or, I could have a third option: assume that I am a grownup who knows > what he is doing. This is totally orthogonal to what we're discussing. Whether you are a grownup or a child, whether you have good reasons or bad reasons, you can still make either of the two choices. > After all, even with all those "protections" in list, > I could just create an extension module to shoot me in the foot anyway, > if I really wanted to. Yes you could, and you could hack the OS to manipulate data behind the scenes, and you could build a hardware device to inject whatever data you want directly into the memory. You can do any of those things. So what? Data hiding isn't about some sort of mythical 100% certainty against any imaginable failure mode. Data hiding is a tool like any other, and like all tools, it has uses and misuses, and it works under some circumstances and not others. Wrenches are excellent for tightening bolts even though they don't work in weightlessness (the astronaut spins around instead), and hammers are good for hammering nails even though they won't work on the surface of Pluto (the metal will become brittle and shatter). Data hiding is no different. If you don't get 100% certainty that there will never be a failure no matter what, what do you get? Just off the top of my head, it: * makes it easier for an optimising compiler to give fast code if it doesn't have to assume internal details can be changed; * makes it easier to separate interface from implementation when you can trust that the implementation actually isn't being used; * gives the developer more freedom to change the implementation; * makes it possible for meaningful correctness proofs; * reduces the amount of interconnections between different parts of your program by ensuring that all interaction goes through the interface instead of the implementation; * which in turn reduces the amount of testing you need to do; and possibly others. [...] > I don't think this is going anywhere. Now you are trying to push me to > the extremes, changing what I _said_ for your exaggerated interpretation > of it just so you could shoot it down, or force me to say that I want > buffer overflows in python. I believe that's called "strawman". No, I'm not changing anything you said. I'm pointing out the implications of what you said. Don't blame me for seeing what logical consequences following from your statement. > I stand by my words - but not by your "interpretation" of them: > >> > What makes no sense is that it should be in the original author's >> > power to decide, if he is not part of _our_ team. > > Do you _really_ read from that sentence that I should dislike python > because it makes it a bit harder to get a buffer overflow with their > native types? Well, you tell me: does it make sense for Guido to have decided to make it hard for pure Python developers to cause buffer overflows? If your answer is Yes, it makes sense, then obviously your earlier statement that it makes no sense is *wrong*, at least under some circumstances. Then we can make progress: data hiding isn't *always* evil and anti-freedom and useless, it's okay when Guido does it. Then we can act like grownups and discuss under what other circumstances it is or isn't good to use data hiding, instead of making sweeping generalisations that it is never good and always useless. If your answer is No, it makes no sense, Guido was wrong to hide implementation details from Python developers, then I can't imagine what you get out of the stifling, unpleasant B&D language Python. Perhaps you like the syntax? -- Steven From techtonik at gmail.com Sat Jan 24 06:26:34 2009 From: techtonik at gmail.com (anatoly techtonik) Date: Sat, 24 Jan 2009 13:26:34 +0200 Subject: About SCons Re: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: <497A44A1.20907@roumenpetrov.info> References: <497A44A1.20907@roumenpetrov.info> Message-ID: On Sat, Jan 24, 2009 at 12:28 AM, Roumen Petrov >> >> I would better use SCons for both unix and windows builds. In case of >> windows for both compilers - mingw and microsoft ones. To port curses >> extension to windows I need to know what gcc options mean, what are >> the rules to write Makefiles and how to repeat these rules as well as >> find options in visual studio interface. Not mentioning various >> platform-specific defines and warning fixes. > > Did you select one of existing curses library for windows ? I've selected PDCurses and successfully compiled the module and run demos manually - you may see the batch and the patch at http://bugs.python.org/issue2889 However, I was asked for VS2008 project file and this is where it all stopped for 8 months already. First I couldn't get the VS2008, then it refused to run on my W2K and now I can't get enough time to learn it (including that I have 50%/40% experience in PHP/Python and only 5%/5% C/Java). -- --anatoly t. From dunmer at dreams.sk Sat Jan 24 06:59:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 12:59:22 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> Message-ID: <497B029A.2010606@dreams.sk> First, thank you both I think this isn't basic auth, because this page has form login. I read site's html source and used wireshark to analyze communication between my browser and website and i really find out that a was ignoring one field I added it to the parameters but it didn't help.. Maybe i'm still missing something Here's the post packet: http://student.fiit.stuba.sk/~sevecek06/auth.txt and here's the code again, with little change and real web location added: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(login='login', pwd='pass', page='')) f = opener.open('https://www.orangeportal.sk/', params) data = f.read() f.close() Login and pass are fake ofc. Thank you in advice for any help. Steve Holden wrote: > Gabriel wrote: >> Hello, >> >> I'm new in Python and i would like to write script which need to login >> to a website. I'm experimenting with urllib2, >> especially with something like this: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(username='user', password='pass')) >> f = opener.open('https://web.com', params) >> data = f.read() >> f.close() >> >> And the problem is, that this code logs me in on some sites, but on >> others doesn't, especially on the one I really >> need to login. And i don't know why. So is there some way how to debug >> this code and find out why that script cannot >> login on that specific site? >> >> Sorry if this question is too lame, but i am really beginner both in >> python and web programming .) >> > That's actually pretty good code for a newcomer! There are a couple of > issues you may be running into. > > First, not all sites use "application-based" authentication - they may > use HTTP authentication of some kind instead. In that case you have to > pass the username and password as a part of the HTTP headers. Michael > Foord has done a fair write-up of the issues at > > http://www.voidspace.org.uk/python/articles/authentication.shtml > > and you will do well to read that if, indeed, you need to do basic > authentication. > > Second, if it *is* the web application that's doing the authentication > in the sites that are failing (in other words if the credentials are > passed in a web form) then your code may need adjusting to use other > field names, or to include other data as required by the login form. You > can usually find out what's required by reading the HTML source of the > page that contains the login form. > > Thirdly [nobody expects the Spanish Inquisition ...], it may be that > some sites are extraordinarily sensitive to programmed login attempts > (possible due to spam), typically using a check of the "Agent:" HTTP > header to "make sure" that the login attempt is coming from a browser > and not a program. For sites like these you may need to emulate a > browser response more fully. > > You can use a program like Wireshark to analyze the network traffic, > though you can get add-ons for Firefox that will show you the HTTP > headers on request and response. > > regards > Steve From dunmer at dreams.sk Sat Jan 24 06:59:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 12:59:22 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> Message-ID: <497B029A.2010606@dreams.sk> First, thank you both I think this isn't basic auth, because this page has form login. I read site's html source and used wireshark to analyze communication between my browser and website and i really find out that a was ignoring one field I added it to the parameters but it didn't help.. Maybe i'm still missing something Here's the post packet: http://student.fiit.stuba.sk/~sevecek06/auth.txt and here's the code again, with little change and real web location added: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(opener) params = urllib.urlencode(dict(login='login', pwd='pass', page='')) f = opener.open('https://www.orangeportal.sk/', params) data = f.read() f.close() Login and pass are fake ofc. Thank you in advice for any help. Steve Holden wrote: > Gabriel wrote: >> Hello, >> >> I'm new in Python and i would like to write script which need to login >> to a website. I'm experimenting with urllib2, >> especially with something like this: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(username='user', password='pass')) >> f = opener.open('https://web.com', params) >> data = f.read() >> f.close() >> >> And the problem is, that this code logs me in on some sites, but on >> others doesn't, especially on the one I really >> need to login. And i don't know why. So is there some way how to debug >> this code and find out why that script cannot >> login on that specific site? >> >> Sorry if this question is too lame, but i am really beginner both in >> python and web programming .) >> > That's actually pretty good code for a newcomer! There are a couple of > issues you may be running into. > > First, not all sites use "application-based" authentication - they may > use HTTP authentication of some kind instead. In that case you have to > pass the username and password as a part of the HTTP headers. Michael > Foord has done a fair write-up of the issues at > > http://www.voidspace.org.uk/python/articles/authentication.shtml > > and you will do well to read that if, indeed, you need to do basic > authentication. > > Second, if it *is* the web application that's doing the authentication > in the sites that are failing (in other words if the credentials are > passed in a web form) then your code may need adjusting to use other > field names, or to include other data as required by the login form. You > can usually find out what's required by reading the HTML source of the > page that contains the login form. > > Thirdly [nobody expects the Spanish Inquisition ...], it may be that > some sites are extraordinarily sensitive to programmed login attempts > (possible due to spam), typically using a check of the "Agent:" HTTP > header to "make sure" that the login attempt is coming from a browser > and not a program. For sites like these you may need to emulate a > browser response more fully. > > You can use a program like Wireshark to analyze the network traffic, > though you can get add-ons for Firefox that will show you the HTTP > headers on request and response. > > regards > Steve From dunmer at dreams.sk Sat Jan 24 07:13:25 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:13:25 +0100 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B05E5.6060201@dreams.sk> Oh, nevermind, it's working. Thanks Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > > Login and pass are fake ofc. > > Thank you in advice for any help. > > > Steve Holden wrote: >> Gabriel wrote: >>> Hello, >>> >>> I'm new in Python and i would like to write script which need to login >>> to a website. I'm experimenting with urllib2, >>> especially with something like this: >>> >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >>> urllib2.install_opener(opener) >>> >>> params = urllib.urlencode(dict(username='user', password='pass')) >>> f = opener.open('https://web.com', params) >>> data = f.read() >>> f.close() >>> >>> And the problem is, that this code logs me in on some sites, but on >>> others doesn't, especially on the one I really >>> need to login. And i don't know why. So is there some way how to debug >>> this code and find out why that script cannot >>> login on that specific site? >>> >>> Sorry if this question is too lame, but i am really beginner both in >>> python and web programming .) >>> >> That's actually pretty good code for a newcomer! There are a couple of >> issues you may be running into. >> >> First, not all sites use "application-based" authentication - they may >> use HTTP authentication of some kind instead. In that case you have to >> pass the username and password as a part of the HTTP headers. Michael >> Foord has done a fair write-up of the issues at >> >> http://www.voidspace.org.uk/python/articles/authentication.shtml >> >> and you will do well to read that if, indeed, you need to do basic >> authentication. >> >> Second, if it *is* the web application that's doing the authentication >> in the sites that are failing (in other words if the credentials are >> passed in a web form) then your code may need adjusting to use other >> field names, or to include other data as required by the login form. You >> can usually find out what's required by reading the HTML source of the >> page that contains the login form. >> >> Thirdly [nobody expects the Spanish Inquisition ...], it may be that >> some sites are extraordinarily sensitive to programmed login attempts >> (possible due to spam), typically using a check of the "Agent:" HTTP >> header to "make sure" that the login attempt is coming from a browser >> and not a program. For sites like these you may need to emulate a >> browser response more fully. >> >> You can use a program like Wireshark to analyze the network traffic, >> though you can get add-ons for Firefox that will show you the HTTP >> headers on request and response. >> >> regards >> Steve > > -- > http://mail.python.org/mailman/listinfo/python-list > From dunmer at dreams.sk Sat Jan 24 07:13:25 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:13:25 +0100 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B05E5.6060201@dreams.sk> Oh, nevermind, it's working. Thanks Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > > Login and pass are fake ofc. > > Thank you in advice for any help. > > > Steve Holden wrote: >> Gabriel wrote: >>> Hello, >>> >>> I'm new in Python and i would like to write script which need to login >>> to a website. I'm experimenting with urllib2, >>> especially with something like this: >>> >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >>> urllib2.install_opener(opener) >>> >>> params = urllib.urlencode(dict(username='user', password='pass')) >>> f = opener.open('https://web.com', params) >>> data = f.read() >>> f.close() >>> >>> And the problem is, that this code logs me in on some sites, but on >>> others doesn't, especially on the one I really >>> need to login. And i don't know why. So is there some way how to debug >>> this code and find out why that script cannot >>> login on that specific site? >>> >>> Sorry if this question is too lame, but i am really beginner both in >>> python and web programming .) >>> >> That's actually pretty good code for a newcomer! There are a couple of >> issues you may be running into. >> >> First, not all sites use "application-based" authentication - they may >> use HTTP authentication of some kind instead. In that case you have to >> pass the username and password as a part of the HTTP headers. Michael >> Foord has done a fair write-up of the issues at >> >> http://www.voidspace.org.uk/python/articles/authentication.shtml >> >> and you will do well to read that if, indeed, you need to do basic >> authentication. >> >> Second, if it *is* the web application that's doing the authentication >> in the sites that are failing (in other words if the credentials are >> passed in a web form) then your code may need adjusting to use other >> field names, or to include other data as required by the login form. You >> can usually find out what's required by reading the HTML source of the >> page that contains the login form. >> >> Thirdly [nobody expects the Spanish Inquisition ...], it may be that >> some sites are extraordinarily sensitive to programmed login attempts >> (possible due to spam), typically using a check of the "Agent:" HTTP >> header to "make sure" that the login attempt is coming from a browser >> and not a program. For sites like these you may need to emulate a >> browser response more fully. >> >> You can use a program like Wireshark to analyze the network traffic, >> though you can get add-ons for Firefox that will show you the HTTP >> headers on request and response. >> >> regards >> Steve > > -- > http://mail.python.org/mailman/listinfo/python-list > From zzbbaadd at aol.com Sat Jan 24 07:14:18 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Sat, 24 Jan 2009 04:14:18 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: On Jan 23, 8:57?am, Dennis Lee Bieber wrote: > On Fri, 23 Jan 2009 01:48:32 -0800 (PST), TheFlyingDutchman > declaimed the following in comp.lang.python: > > > abstraction. In Python, all class attributes are public but names may > > be "mangled" to discourage unauthorized access, but otherwise not > > prevented. It is up to the designer to provide the appropriate > > interfaces to the data so that the client programmer does not have to > > resort to manipulating the encapsulated data attributes." > > ? ? ? ? Double underscore "mangling" was not implemented to "discourage > unauthorized access". Its primary purpose is to prevent name space > conflicts when an extended subclass and its parent class use the same > name for an attribute, but that attribute is not of the same "meaning". > Using the __ prefix means BOTH attributes are part of the instance, but > the subclass only see's its variant and should make calls into > superclass methods to modify the parent variant. > > ? ? ? ? Python convention is that a single underscore -- which does NOT > perform name mangling -- is the indicator meant to "discourage > unauthorized access". > Is there a significant performance hit with using the double underscore for signifying a variable you want to be private? It seems like it is advantageous that someone trying for direct access has to use a different notation, which will help to emphasize that it shouldn't be access directly. From andrew at acooke.org Sat Jan 24 07:16:31 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 04:16:31 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? Message-ID: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Hi, I have some 3.0 code, which I would like to make work with 2.6. However, there does not seem to be support for the new super() (no args) via __future__. Is that correct? If so, what's the best way to handle this? Thanks, Andrew From steve at holdenweb.com Sat Jan 24 07:18:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 07:18:58 -0500 Subject: Web authentication urllib2 In-Reply-To: <497B029A.2010606@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: Gabriel wrote: > First, thank you both > > I think this isn't basic auth, because this page has form login. > I read site's html source and used wireshark to analyze communication > between my browser and website and i really find out that a was ignoring > one field > > I added it to the parameters but it didn't help.. > Maybe i'm still missing something > > Here's the post packet: > http://student.fiit.stuba.sk/~sevecek06/auth.txt > > and here's the code again, with little change and real web location added: > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > urllib2.install_opener(opener) > > params = urllib.urlencode(dict(login='login', pwd='pass', page='')) > f = opener.open('https://www.orangeportal.sk/', params) > data = f.read() > f.close() > If you look at the login form on the home page of that portal you will see
This means that the form should be submitted to https://www.orangeportal.sk/portal/do_login.dwp Some forms submit to the same URL that contain them, but many don't. This is one of the ones that requires submission to a different URL! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dunmer at dreams.sk Sat Jan 24 07:23:20 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:23:20 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B0838.1010002@dreams.sk> Yep, i realize this a minute after posting, sorry. And thank you again .) Steve Holden wrote: > Gabriel wrote: >> First, thank you both >> >> I think this isn't basic auth, because this page has form login. >> I read site's html source and used wireshark to analyze communication >> between my browser and website and i really find out that a was ignoring >> one field >> >> I added it to the parameters but it didn't help.. >> Maybe i'm still missing something >> >> Here's the post packet: >> http://student.fiit.stuba.sk/~sevecek06/auth.txt >> >> and here's the code again, with little change and real web location added: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(login='login', pwd='pass', page='')) >> f = opener.open('https://www.orangeportal.sk/', params) >> data = f.read() >> f.close() >> > If you look at the login form on the home page of that portal you will see > > > > This means that the form should be submitted to > > https://www.orangeportal.sk/portal/do_login.dwp > > Some forms submit to the same URL that contain them, but many don't. > This is one of the ones that requires submission to a different URL! > > regards > Steve From dunmer at dreams.sk Sat Jan 24 07:23:20 2009 From: dunmer at dreams.sk (Gabriel) Date: Sat, 24 Jan 2009 13:23:20 +0100 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: <497B0838.1010002@dreams.sk> Yep, i realize this a minute after posting, sorry. And thank you again .) Steve Holden wrote: > Gabriel wrote: >> First, thank you both >> >> I think this isn't basic auth, because this page has form login. >> I read site's html source and used wireshark to analyze communication >> between my browser and website and i really find out that a was ignoring >> one field >> >> I added it to the parameters but it didn't help.. >> Maybe i'm still missing something >> >> Here's the post packet: >> http://student.fiit.stuba.sk/~sevecek06/auth.txt >> >> and here's the code again, with little change and real web location added: >> >> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >> urllib2.install_opener(opener) >> >> params = urllib.urlencode(dict(login='login', pwd='pass', page='')) >> f = opener.open('https://www.orangeportal.sk/', params) >> data = f.read() >> f.close() >> > If you look at the login form on the home page of that portal you will see > > > > This means that the form should be submitted to > > https://www.orangeportal.sk/portal/do_login.dwp > > Some forms submit to the same URL that contain them, but many don't. > This is one of the ones that requires submission to a different URL! > > regards > Steve From mrkafk at gmail.com Sat Jan 24 07:31:03 2009 From: mrkafk at gmail.com (mk) Date: Sat, 24 Jan 2009 13:31:03 +0100 Subject: What's the business with the asterisk? Message-ID: Hello everyone, From time to time I spot an asterisk (*) used in the Python code _outside_ the usual *args or **kwargs application. E.g. here: http://www.norvig.com/python-lisp.html def transpose (m): return zip(*m) >>> transpose([[1,2,3], [4,5,6]]) [(1, 4), (2, 5), (3, 6)] What does *m mean in this example and how does it do the magic here? Regards, mk From python.list at tim.thechases.com Sat Jan 24 07:46:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Jan 2009 06:46:34 -0600 Subject: What's the business with the asterisk? In-Reply-To: References: Message-ID: <497B0DAA.10209@tim.thechases.com> > From time to time I spot an asterisk (*) used in the Python code > _outside_ the usual *args or **kwargs application. > > E.g. here: http://www.norvig.com/python-lisp.html > > def transpose (m): > return zip(*m) > >>> transpose([[1,2,3], [4,5,6]]) > [(1, 4), (2, 5), (3, 6)] > > What does *m mean in this example and how does it do the magic here? There's a good writeup on args/kwargs at http://www.megasolutions.net/python/-args-and---kwargs-78766.aspx (looks like the content was gleaned from comp.lang.python and credited) -tkc From dannox at gmail.com Sat Jan 24 08:25:43 2009 From: dannox at gmail.com (whatazor) Date: Sat, 24 Jan 2009 05:25:43 -0800 (PST) Subject: pygccxml xml output file Message-ID: Hi all, I start to use this module in order to produce xml( and the make other things), but differently from gccxml I don't find the variable that set the name of the xml output file after the parsing (in gccxml is - fxml), so it creates temporary files. how can I do an Is there a tutorial that explain with dectails how it works? thank you, regards w From benjamin at python.org Sat Jan 24 08:39:52 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 13:39:52 +0000 (UTC) Subject: Porting 3.0 to 2.6 - from =?utf-8?b?X19mdXR1cmVfXw==?= import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Message-ID: andrew cooke acooke.org> writes: > > Hi, > > I have some 3.0 code, which I would like to make work with 2.6. > However, there does not seem to be support for the new super() (no > args) via __future__. Is that correct? If so, what's the best way to > handle this? Just use the two argument super(): super(MyClass, instance) It's supported in both versions. From kay.schluehr at gmx.net Sat Jan 24 08:49:16 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 05:49:16 -0800 (PST) Subject: What's the business with the asterisk? References: Message-ID: <52d94a37-05cd-459d-946e-6d41ffeeca12@p23g2000prp.googlegroups.com> On 24 Jan., 13:31, mk wrote: > Hello everyone, > > ?From time to time I spot an asterisk (*) used in the Python code > _outside_ the usual *args or **kwargs application. > > E.g. here:http://www.norvig.com/python-lisp.html > > def transpose (m): > ? ?return zip(*m) > ?>>> transpose([[1,2,3], [4,5,6]]) > [(1, 4), (2, 5), (3, 6)] > > What does *m mean in this example and how does it do the magic here? > > Regards, > mk If zip is specified as def zip(*args): ... one can pass zero or more arguments into zip. In the zip body one has access to the argument tuple args. So zip(a, b, c) yields args = (a, b, c). Now suppose you want to pass the tuple t = (a, b, c) to zip. If you call zip(t) then args = ((a, b, c),). When calling zip(*t) instead the tuple is passed as variable arguments just like they are specified in the signature of zip. So args = (a, b, c). Same holds for def foo(**kwd): ... and foo(**kwd) versus foo(kwd). From notvalid2 at sbcglobal.net Sat Jan 24 09:15:05 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 24 Jan 2009 06:15:05 -0800 Subject: What is intvar? In-Reply-To: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: W. eWatson wrote: > r wrote: >> here is a good explanation of control vars: >> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >> >> Here are 3 great Tkinter refernces in order: >> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >> http://effbot.org/tkinterbook/ >> http://www.pythonware.com/library/tkinter/introduction/ > Thanks to all for the reference and tips. > tkinterbook is easy to follow, but it seems to have been abandoned in 2005. Did it appear in another guise somewhere else? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From andrew at acooke.org Sat Jan 24 09:20:43 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 06:20:43 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> Message-ID: <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> On Jan 24, 10:39?am, Benjamin Peterson wrote: > andrew cooke acooke.org> writes: > > > > > Hi, > > > I have some 3.0 code, which I would like to make work with 2.6. > > However, there does not seem to be support for the new super() (no > > args) via __future__. ?Is that correct? ?If so, what's the best way to > > handle this? > > Just use the two argument super(): super(MyClass, instance) It's supported in > both versions. Thanks. Any idea how to deal with ABCs? It's sufficient to use a simple class, but I want to expose an ABC in 3.0 as it will make it easier for others to extend. Unfortunately, "metaclass=" is a syntax error in 2.6 so the following still fails: from sys import version if version.startswith('2.'): class Matcher(): pass else: class Matcher(metaclass=ABCMeta): pass Andrew From goon12 at gmail.com Sat Jan 24 09:55:34 2009 From: goon12 at gmail.com (Joe Riopel) Date: Sat, 24 Jan 2009 09:55:34 -0500 Subject: OCaml, Language syntax, and Proof Systems In-Reply-To: References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <6a2ccd190901240655le9aad7cwa04ab5866cd41b6a@mail.gmail.com> On Fri, Jan 23, 2009 at 6:16 PM, Xah Lee wrote: > The haskell tutorials you can find online are the most mothefucking > stupid unreadable fuck. The Haskll community is almost stupid. What > they talk all day is about monads, currying, linder myer fuck type. > That's what they talk about all day. All day and night. Monad! What's > a monad! The importance of monad! How to learn monad! Simple intro to > monad! Fucking morons, but MONAD! http://www.youtube.com/watch?v=9fohXBj2UEI From pataphor at gmail.com Sat Jan 24 10:02:14 2009 From: pataphor at gmail.com (pataphor) Date: Sat, 24 Jan 2009 16:02:14 +0100 Subject: Counter Class -- Bag/Multiset References: Message-ID: <20090124160214.58273d07@hyperspace> On Thu, 22 Jan 2009 10:11:37 -0800 (PST) Raymond Hettinger wrote: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. I like that! Now that we have a multiset or Counter I think a redefinition of itertools.permutations is in order. For example something like this: def genperm(D, R = []): #generate the permutations of a multiset if not max(D.values()): yield tuple(R) else: for k,v in sorted(D.items()): if v: D[k] -= 1 for g in genperm(D,R+[k]): yield g D[k] += 1 def perm(seq): D = {} for x in seq: D[x] = D.get(x,0)+1 for X in genperm(D): yield X def test(): for i,x in enumerate(perm('aabbcc')): print i,x print len(set(perm('aabbcc'))) if __name__ == '__main__': test() The dictionary I'm using here could be seamlessly replaced by your Counter class. By the way, I like your itertools recipes a lot, but I miss something that repeats elements n times, an xcycle or ncycle or whatever, like I used in this (older code, sorry for the name overlap): def repeat(x,n = 0): i = 0 while i < n : yield x i += 1 def xcycle(seq,n): while 1: for x in seq: for y in repeat(x,n): yield y def counter(symbols,width): base = len(symbols) R = [] k = width while k: k -= 1 R.append(xcycle(symbols,base**k)) nc = base**width while nc: yield list(x.next() for x in R) nc -=1 def test(): symbols = '01' width = 4 for state in counter(symbols,width): print state if __name__=='__main__': test() I think such a thing could be handy for generating more kinds of periodic sequences. By the way, itertools is starting to feel like it's becoming some sort of alternate programming design all by itself. I wonder when it is going to break loose from python! I like that way of thinking a lot, thanks. P. From fakeaddress at nowhere.org Sat Jan 24 10:02:50 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 24 Jan 2009 07:02:50 -0800 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: Tobiah wrote: > Where can I read about > this mysterious use of the '*'? Hmmm... that's a harder question than I thought. Am I missing it, or does Python's doc need a write-up of the extended call syntax? > It only works in the > context of the zip() function. It's hard to understand > how the interpreter handles that. It works generally, for any callable. See the doc for 'apply': http://docs.python.org/library/functions.html#non-essential-built-in-functions It not only works in a call, but also in function definitions. You can call a function with the extended call syntax whether or not is defined with * and ** arguments. -- --Bryan From scuzwalla at gmail.com Sat Jan 24 11:14:31 2009 From: scuzwalla at gmail.com (Jerry Gerrone) Date: Sat, 24 Jan 2009 08:14:31 -0800 (PST) Subject: Mathematica 7 compares to other languages References: <13d5dff7-9aac-4385-91ee-d6e58177497f@i24g2000prf.googlegroups.com> <7db0371c-88f8-4984-bb0d-b2078147803e@f40g2000pri.googlegroups.com> <86bf2e29-5f8d-4349-94cf-d1561f0114e6@e1g2000pra.googlegroups.com> <20081204111115.7cee2ecc@usenot.de> <4d86021f-d25c-4b96-b1a2-3a0c162a6154@a26g2000prf.googlegroups.com> Message-ID: On Jan 21, 1:06?pm, "soul.mirr... at gmail.com" wrote: > On Dec 4 2008, 5:11?am, Andreas Waldenburger > wrote: > > I vaguely remember you plonking [Xah Lee] before. Did you unplonk him in > > the meantime? Or was that just a figure of speech? > > > teasingly yours, > > /W > > Andreas Waldenburger, I hold up a mirror to your soul! > > A couple of years ago you started posting to the newsgroup > comp.lang.java.programmer. Unlike most newbies, instead of lurking for > a while and then contributing on-topic posts about Java, you jumped > into the nearest available flamewar and immediately got in up to your > neck. Then, on November 13, 2007, you stooped to intentionally > misquoting one of your opponents. When he wrote > > http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e9... > > A few days later, you did it again, misquoting this post > > http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d41... > > in this one: > > http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b... > > In both cases, you publicly portrayed this poor man as a pervert, even > though, whatever his other [insult deleted], that is clearly not one of > them. None of the nasty things that you have said or implied about me are at all true. > Repeatedly you have claimed to be primarily motivated by finding the > disrupting of newsgroups to be entertaining. This is tantamount to > admitting to being a troll. Yes, and here you are, feeding him. Way to go, genius. (And cljp had just gotten peaceful again, too!) From vincent at vincentdavis.net Sat Jan 24 11:29:28 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 24 Jan 2009 09:29:28 -0700 Subject: understanding nested lists? Message-ID: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> I have a short peace of code that is not doing what I expect. when I assign a value to a list in a list alist[2][4]=z this seems replace all the 4 elements in all the sub lists. I assume it is supposed to but this is not what I expect. How would I assign a value to the 4th element in the 2nd sublist. here is the code I have. All the printed values are what I would expect except that all sublist values are replaced. Thanks for your help Vincent on the first iteration I get ; new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] and expected this; new_list [[None, 0, 1, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] Code; list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] new_list=[[None]*4]*6 print 'new_list',new_list for sublist in range(6): # 6 becuase it is the # of rows lists1 print 'sublist', sublist for x in list1[sublist]: print list1[sublist] print 'new_list[sublist][x]', new_list[sublist][x] new_list[sublist][x]=list1[sublist].index(x) print 'sublist', sublist, 'x', x print new_list[sublist][x] print 'new_list', new_list -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Sat Jan 24 12:08:08 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Sat, 24 Jan 2009 22:38:08 +0530 Subject: String comparision Message-ID: Hi all, I am developing spell checker for my local language(tamil) using python. I need to generate alternative word list for a miss-spelled word from the dictionary of words.The alternatives must be as much as closer to the miss-spelled word.As we know, ordinary string comparison wont work here . Any suggestion for this problem is welcome. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryandw at gmail.com Sat Jan 24 12:17:10 2009 From: ryandw at gmail.com (webcomm) Date: Sat, 24 Jan 2009 09:17:10 -0800 (PST) Subject: practical limits of urlopen() Message-ID: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Hi, Am I going to have problems if I use urlopen() in a loop to get data from 3000+ URLs? There will be about 2KB of data on average at each URL. I will probably run the script about twice per day. Data from each URL will be saved to my database. I'm asking because I've never opened that many URLs before in a loop. I'm just wondering if it will be particularly taxing for my server. Is it very uncommon to get data from so many URLs in a script? I guess search spiders do it, so I should be able to as well? Thank you, Ryan From benjamin at python.org Sat Jan 24 12:32:58 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 24 Jan 2009 17:32:58 +0000 (UTC) Subject: Porting 3.0 to 2.6 - from =?utf-8?b?X19mdXR1cmVfXw==?= import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> Message-ID: andrew cooke acooke.org> writes: > Unfortunately, "metaclass=" is a syntax error in 2.6 so the following > still fails: > > from sys import version > > if version.startswith('2.'): > class Matcher(): > pass > else: > class Matcher(metaclass=ABCMeta): > pass I would suggest that you use the 2.6 syntax, and run "2to3 -f metaclass" on your code. (ABCs have been backported to 2.6.) From steve at holdenweb.com Sat Jan 24 12:40:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:40:45 -0500 Subject: Web authentication urllib2 In-Reply-To: <497B0838.1010002@dreams.sk> References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> <497B0838.1010002@dreams.sk> Message-ID: Gabriel wrote: > Yep, i realize this a minute after posting, sorry. > > And thank you again .) > A pleasure. Next time, you might consider posting an explanation along with the "it's working now" message, just to give closure to the thread for anyone who ends up reading it later after a search. Good that you got your problem solved, anyway! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From BrianVanderburg2 at aim.com Sat Jan 24 12:42:28 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Sat, 24 Jan 2009 12:42:28 -0500 Subject: understanding nested lists? In-Reply-To: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: <497B5304.9090901@aim.com> vincent at vincentdavis.net wrote: > I have a short peace of code that is not doing what I expect. when I > assign a value to a list in a list alist[2][4]=z this seems replace > all the 4 elements in all the sub lists. I assume it is supposed to > but this is not what I expect. How would I assign a value to the 4th > element in the 2nd sublist. here is the code I have. All the printed > values are what I would expect except that all sublist values are > replaced. > > Thanks for your help > Vincent > > on the first iteration I get ; > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > and expected this; > new_list [[None, 0, 1, None], [None, None, None, None], > [None, None, None, None], [None, None, None, None], [None, None, None, > None], [None, None, None, None]] > > Code; > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > new_list=[[None]*4]*6 > print 'new_list',new_list > for sublist in range(6): # 6 becuase it is the # of rows lists1 > print 'sublist', sublist > for x in list1[sublist]: > print list1[sublist] > print 'new_list[sublist][x]', new_list[sublist][x] > new_list[sublist][x]=list1[sublist].index(x) > print 'sublist', sublist, 'x', x > print new_list[sublist][x] > print 'new_list', new_list > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > The problem is likely this right here: [[None]*4]*6 This first creates an inner list that has 4 Nones, then the outer list contains 6 references to that same list, so (new_list[0] is new_list[1]) and (new_list[1] is new_list[2]). I make this mistake a lot myself. l=[[None]*4]*6 print id(l[0]) # -1210893364 print id(l[1]) # -1210893364 l = [list([None]*4) for x in range(6)] print id(l[0]) # -1210893612 print id(l[1]) # -1210893580 Works better Brian Vanderburg II From steve at holdenweb.com Sat Jan 24 12:46:14 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:46:14 -0500 Subject: understanding nested lists? In-Reply-To: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: Vincent Davis wrote: > I have a short peace of code that is not doing what I expect. when I > assign a value to a list in a list alist[2][4]=z this seems replace all > the 4 elements in all the sub lists. I assume it is supposed to but this > is not what I expect. How would I assign a value to the 4th element in > the 2nd sublist. here is the code I have. All the printed values are > what I would expect except that all sublist values are replaced. > > Thanks for your help > Vincent > > on the first iteration I get ; > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > and expected this; > new_list [[None, 0, 1, None], [None, None, None, None], > [None, None, None, None], [None, None, None, None], [None, None, None, > None], [None, None, None, None]] > > Code; > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > new_list=[[None]*4]*6 > print 'new_list',new_list > for sublist in range(6): # 6 becuase it is the # of rows lists1 > print 'sublist', sublist > for x in list1[sublist]: > print list1[sublist] > print 'new_list[sublist][x]', new_list[sublist][x] > new_list[sublist][x]=list1[sublist].index(x) > print 'sublist', sublist, 'x', x > print new_list[sublist][x] > print 'new_list', new_list > When you create new_list you are actually filling it with six references to the same list. Consequently when you change one of those list elements they all appear to change (because they are all referencing the same list object). Try instead new_list = [[None]*4 for i in range(6)] and you should find your code works as expected. In this case the list is constructed with a new sublist as each element. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 12:50:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 12:50:28 -0500 Subject: practical limits of urlopen() In-Reply-To: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> References: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Message-ID: webcomm wrote: > Hi, > > Am I going to have problems if I use urlopen() in a loop to get data > from 3000+ URLs? There will be about 2KB of data on average at each > URL. I will probably run the script about twice per day. Data from > each URL will be saved to my database. > > I'm asking because I've never opened that many URLs before in a loop. > I'm just wondering if it will be particularly taxing for my server. > Is it very uncommon to get data from so many URLs in a script? I > guess search spiders do it, so I should be able to as well? > You shouldn't expect problem - though you might want to think about using some more advanced technique like threading to get your results more quickly. This is Python, though. It shouldn't take long to write a test program to verify that you can indeed spider 3,000 pages this way. With about 2KB per page, you could probably build up a memory structure containing the whole content of every page without memory usage becoming too excessive for modern systems. If you are writing stuff out to a database as you go and not retaining page content then there should be no problems whatsoever. Then look at a parallelized solution of some sort if you need it to work more quickly. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Sat Jan 24 12:51:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 09:51:53 -0800 Subject: Two import questions in Python 3.0 In-Reply-To: References: Message-ID: Kay Schluehr wrote: > On 24 Jan., 09:21, "Gabriel Genellina" wrote: >> If you run A.py as a script, it does not "know" it lives inside a package. >> You must *import* A for it to become aware of the package. >> Also, the directory containing the script comes earlier than PYTHONPATH >> entries in sys.path -- so watch for that case too. > Thanks, yes. I always make the same error thinking that a directory > with the ritual __init__ file is actually a package ( as some kind of > platonic entity ), something that is more obvious to me than it is to > the runtime. The relative import semantics introduced with Python 2.5 > has made the error just visible that was hidden to me for about a > decade. Shit. Temper the language a bit. You lose your effectiveness by some people reading the color of your words, rather than their meaning in code. By the way, if you run the script as: $ python -m package.A You may get what you want demo (language fixed up a bit, moe info printed): in .../lib/site-packages: possible.py ------------- print('import from top possible: %s' % __file__) in .../lib/site-packages/package: possible.py ------------- print('import from package.possible: %s' % __file__) __init__.py ------------- print('package initialized: %s' % __file__) A.py ------ print('A started: %s' % __file__) import possible print('A running: %s' % __file__) --Scott David Daniels Scott.Daniels at Acm.Org From mspetrovic at gmail.com Sat Jan 24 13:13:14 2009 From: mspetrovic at gmail.com (Mark.Petrovic) Date: Sat, 24 Jan 2009 10:13:14 -0800 (PST) Subject: Parsing a string into a datetime object Message-ID: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Good day. Might someone comment on why %f is not accepted as a valid field directive in: >>> from datetime import datetime >>> created="2009-01-24 16:04:55.882788" >>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/_strptime.py", line 321, in strptime (bad_directive, format)) ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' This is for Python 2.5.1 under OS X. Thank you. From metolone+gmane at gmail.com Sat Jan 24 13:24:52 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 24 Jan 2009 10:24:52 -0800 Subject: RegEx issues References: Message-ID: "Sean Brown" wrote in message news:glflaj$qrf$2 at nntp.motzarella.org... > Using python 2.4.4 on OpenSolaris 2008.11 > > I have the following string created by opening a url that has the > following string in it: > > td[ct] = [[ ... ]];\r\n > > The ... above is what I'm interested in extracting which is really a > whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>>reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; You are viewing the repr of the string >>> reg='\[\[(.*)\]\];' >>> reg '\\[\\[(.*)\\]\\];' >>> print reg \[\[(.*)\]\]; <== these are the chars passed to regex The slashes are telling regex the the [ are literal. > > Which obviously doesn't match anything because there are no literal \ in > the above string. Leaving the \ out of the \[\[ above has re.compile > throw an error because [ is a special regex character. Which is why it > needs to be escaped in the first place. > > I am either doing something really wrong, which very possible, or I've > missed something obvious. Either way, I thought I'd ask why this isn't > working and why it seems to be changing my regex to something else. Did you try it? >>> s='td[ct] = [[blah blah]];\r\n' >>> re.search(reg,s).group(1) 'blah blah' -Mark From steve at holdenweb.com Sat Jan 24 13:40:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:40:39 -0500 Subject: What is intvar? In-Reply-To: References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: W. eWatson wrote: > W. eWatson wrote: >> r wrote: >>> here is a good explanation of control vars: >>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >>> >>> Here are 3 great Tkinter refernces in order: >>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >>> http://effbot.org/tkinterbook/ >>> http://www.pythonware.com/library/tkinter/introduction/ >> Thanks to all for the reference and tips. >> > tkinterbook is easy to follow, but it seems to have been abandoned in > 2005. Did it appear in another guise somewhere else? > There hasn't been a lot of development on Tkinter in the intervening period. It's a mature system, so there has been no need to update the documentation. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Sat Jan 24 13:41:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 10:41:32 -0800 Subject: Web authentication urllib2 In-Reply-To: References: <497AD6E9.9080909@dreams.sk> <497B029A.2010606@dreams.sk> Message-ID: Gabriel wrote: > Yep, i realize this a minute after posting, sorry. > > And thank you again .) > > Steve Holden wrote: >> ... I'll offer a couple of pointers about what we all expect here. Please treat this as advice, not a shout of disapproval. (1) Do not top post (put your response above the previous interaction). (2) When quoting previous interactions, cut until the portion you are quoting provides enough context to make your post's context comprehensible, but only that much context. (3) When you figure out you problem, especially on your own, summarize back in a final message what went wrong and how you fixed it. The reasons for these three rules are: (1) The message can be read in order, rather than reading up and down. (2) People _do_ have access to the previous messages (albeit sometimes only with some effort). The message should be comprehensible on its own, but your reader can go back for more detail if it turns out to be vital. You don't want to grow your message to the point where someone who might help you says, "I don't have time to read that." (3) Generally it is a good idea to search for answers before asking. It can be incredibly frustrating to discover someone else had previously seen exactly the same problem you are bashing your head into the wall about, follow the chain, and finally read, "Never mind, I figured it out." without a clue to what was determined. If you read comp.lang.python for a while, you'll see this is the norm for messages here, and these behaviors help make this a more pleasant place to read and write. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Sat Jan 24 13:46:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:46:50 -0500 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: <497B621A.7030106@holdenweb.com> Bryan Olson wrote: > Tobiah wrote: >> Where can I read about >> this mysterious use of the '*'? > > Hmmm... that's a harder question than I thought. Am I missing it, or > does Python's doc need a write-up of the extended call syntax? > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 documentation index it lists only two references. The first is the language manual's explanation of its use in the def statement, the second is a transitory reference to its use in function calls, but that's in the tutorial where it is not likely to get much attention. >> It only works in the >> context of the zip() function. It's hard to understand >> how the interpreter handles that. > > It works generally, for any callable. See the doc for 'apply': > > http://docs.python.org/library/functions.html#non-essential-built-in-functions > > > It not only works in a call, but also in function definitions. You can > call a function with the extended call syntax whether or not is defined > with * and ** arguments. > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 13:46:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:46:50 -0500 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: References: Message-ID: <497B621A.7030106@holdenweb.com> Bryan Olson wrote: > Tobiah wrote: >> Where can I read about >> this mysterious use of the '*'? > > Hmmm... that's a harder question than I thought. Am I missing it, or > does Python's doc need a write-up of the extended call syntax? > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 documentation index it lists only two references. The first is the language manual's explanation of its use in the def statement, the second is a transitory reference to its use in function calls, but that's in the tutorial where it is not likely to get much attention. >> It only works in the >> context of the zip() function. It's hard to understand >> how the interpreter handles that. > > It works generally, for any callable. See the doc for 'apply': > > http://docs.python.org/library/functions.html#non-essential-built-in-functions > > > It not only works in a call, but also in function definitions. You can > call a function with the extended call syntax whether or not is defined > with * and ** arguments. > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Jan 24 13:50:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Jan 2009 13:50:03 -0500 Subject: RegEx issues In-Reply-To: References: Message-ID: Mark Tolonen wrote: > > "Sean Brown" wrote in message > news:glflaj$qrf$2 at nntp.motzarella.org... >> Using python 2.4.4 on OpenSolaris 2008.11 >> >> I have the following string created by opening a url that has the >> following string in it: >> >> td[ct] = [[ ... ]];\r\n >> >> The ... above is what I'm interested in extracting which is really a >> whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. >> The problem is it appears that python is escaping the \ in the regex >> because I see this: >>>>> reg = '\[\[(.*)\]\];' >>>>> reg >> '\\[\\[(.*)\\]\\];' >> >> Now to me looks like it would match the string - \[\[ ... \]\]; > > You are viewing the repr of the string > >>>> reg='\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' >>>> print reg > \[\[(.*)\]\]; <== these are the chars passed to regex > > The slashes are telling regex the the [ are literal. > >> >> Which obviously doesn't match anything because there are no literal \ in >> the above string. Leaving the \ out of the \[\[ above has re.compile >> throw an error because [ is a special regex character. Which is why it >> needs to be escaped in the first place. >> >> I am either doing something really wrong, which very possible, or I've >> missed something obvious. Either way, I thought I'd ask why this isn't >> working and why it seems to be changing my regex to something else. > > Did you try it? > >>>> s='td[ct] = [[blah blah]];\r\n' >>>> re.search(reg,s).group(1) > 'blah blah' > Beware, though, that by default regex matches are greedy, so if there's a chance that two [[ ... ]] [[ ... ]] can appear on the same line then the above pattern will match ... ]] [[ ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Sat Jan 24 13:50:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 18:50:04 +0000 Subject: Parsing a string into a datetime object In-Reply-To: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Message-ID: <497B62DC.7000108@mrabarnett.plus.com> Mark.Petrovic wrote: > Good day. > > Might someone comment on why %f is not accepted as a valid field > directive in: > >>>> from datetime import datetime >>>> created="2009-01-24 16:04:55.882788" >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > Traceback (most recent call last): > File "", line 1, in > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/_strptime.py", line 321, in strptime > (bad_directive, format)) > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > This is for Python 2.5.1 under OS X. > > Thank you. > I believe that Python simply uses the 'strptime' (or equivalent) function in the underlying C library: if that doesn't accept %f then neither does Python. From ra.ravi.rav at gmail.com Sat Jan 24 13:55:30 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 24 Jan 2009 10:55:30 -0800 (PST) Subject: Byte oriented data types in python Message-ID: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> I have following packet format which I have to send over Bluetooth. packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || packet_data(variable) How to construct these using python data types, as int and float have no limits and their sizes are not well defined. From roy at panix.com Sat Jan 24 13:55:48 2009 From: roy at panix.com (Roy Smith) Date: Sat, 24 Jan 2009 13:55:48 -0500 Subject: RegEx issues References: Message-ID: Sean Brown wrote: > The problem is it appears that python is escaping the \ in the regex > because I see this: > >>>reg = '\[\[(.*)\]\];' The first trick of working with regexes in Python is to *always* use raw strings. Instead of reg = '\[\[(.*)\]\];' you want reg = r'\[\[(.*)\]\];' In this case, I think it ends up not mattering, but it's one less thing to worry about. Next, when looking at something like > >>> reg > '\\[\\[(.*)\\]\\];' it's hard to see exactly what all the backslashes mean. Which are real and which are escapes? Try doing >>> print reg \[\[(.*)\]\]; which gets you the str(reg) instead of repr(reg). Another trick when you're not 100% what you're looking at is to explode the string like this: >>> [c for c in reg] ['\\', '[', '\\', '[', '(', '.', '*', ')', '\\', ']', '\\', ']', ';'] From hniksic at xemacs.org Sat Jan 24 13:56:28 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 24 Jan 2009 19:56:28 +0100 Subject: Parsing a string into a datetime object References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> Message-ID: <877i4kfs83.fsf@mulj.homelinux.net> "Mark.Petrovic" writes: > Might someone comment on why %f is not accepted as a valid field > directive in: > >>>> from datetime import datetime >>>> created="2009-01-24 16:04:55.882788" >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > Traceback (most recent call last): > File "", line 1, in > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/_strptime.py", line 321, in strptime > (bad_directive, format)) > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > This is for Python 2.5.1 under OS X. time.strptime is documented to use the same set of directives as time.strftime, and http://docs.python.org/library/time.html#time.strftime doesn't mention a %f directive. From andrew at acooke.org Sat Jan 24 13:58:18 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 24 Jan 2009 10:58:18 -0800 (PST) Subject: Porting 3.0 to 2.6 - from __future__ import super missing? References: <822cdca0-3d12-4c55-83e6-ce3347c49e64@r28g2000vbp.googlegroups.com> <414a48e3-daa8-4363-a41c-3cf6b896fb42@m4g2000vbp.googlegroups.com> Message-ID: On Jan 24, 2:32?pm, Benjamin Peterson wrote: > I would suggest that you use the 2.6 syntax, and run "2to3 -f metaclass" on your > code. (ABCs have been backported to 2.6.) Thanks - with that hint I found this - http://mikewatkins.ca/2008/11/29/python-2-and-3-metaclasses/#using-the-metaclass-in-python-2-x-and-3-x Andrew From Scott.Daniels at Acm.Org Sat Jan 24 13:59:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 24 Jan 2009 10:59:44 -0800 Subject: RegEx issues In-Reply-To: References: Message-ID: Sean Brown wrote: > I have the following string ...: "td[ct] = [[ ... ]];\r\n" > The ... (representing text in the string) is what I'm extracting .... > So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>> reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > Now to me looks like it would match the string - \[\[ ... \]\]; > ... OK, you already have a good answer as to what is happening. I'll mention that raw strings were put in the language exactly for regex work. They are useful for any time you need to use the backslash character (\) within a string (but not as the final character). For example: len(r'\a\b\c\d\e\f\g\h') == 16 and len('\a\b\c\d\e\f\g\h') == 13 If you get in the habit of typing regex strings as r'...' or r"...", and examining the patters with print(somestring), you'll ease your life. --Scott David Daniels Scott.Daniels at Acm.Org From jay.amorin at gmail.com Sat Jan 24 14:03:33 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Sun, 25 Jan 2009 03:03:33 +0800 Subject: TEST=`which test` equivalent in python? Message-ID: Hi, Kindly help. import sys, os, string *SVNLOOK_PATH=os.system('which svnlook')* def main(repos, txn): svnlook_cmd = '%s log -t "%s" "%s"' % (*SVNLOOK_PATH*, txn, repos) check_msg = os.popen(svnlook_cmd, 'r').readline().rstrip('\n') if len(check_msg) < 10: sys.stderr.write ("Blahh Blahh....\n") sys.exit(1) else: sys.exit(0) if __name__ == '__main__': if len(sys.argv) < 3: sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) else: main(sys.argv[1], sys.argv[2]) The SVNLOOK_PATH is not working and python says its null when run as SVN hook-script. Do I need to load the os environment variable? How do i pass the value of 'which svnlook' to SVNLOOK_PATH variable. Thanks for your help. Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Sat Jan 24 14:07:32 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 24 Jan 2009 11:07:32 -0800 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <7a9c25c20901241107y58799496xa7454c41b44057cc@mail.gmail.com> I have following packet format which I have to send over Bluetooth. > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > packet_data(variable) > > How to construct these using python data types, as int and float have > no limits and their sizes are not well defined. Check out the struct module. You want something like: data = struct.pack("BB4s", 1, 4, "this") It returns a string of bytes according to the specification -- B is unsigned byte, and "4s" is a string of 4 characters. The 1 feeds into the first byte, the 4 into the second, etc. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Sat Jan 24 14:14:36 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 14:14:36 -0500 Subject: TEST=`which test` equivalent in python? In-Reply-To: References: Message-ID: On Sat, Jan 24, 2009 at 2:03 PM, Jay Jesus Amorin wrote: > Hi, > > Kindly help. > > import sys, os, string > > *SVNLOOK_PATH=os.system('which svnlook')* Read the docs on os.system. It returns the program's return code, not the child processes stdout. Use the subprocess module. > > > def main(repos, txn): > svnlook_cmd = '%s log -t "%s" "%s"' % (*SVNLOOK_PATH*, txn, repos) > check_msg = os.popen(svnlook_cmd, 'r').readline().rstrip('\n') os.popen does what you want here, but it is deprecated in favor of the more powerful subprocess module. > > > if len(check_msg) < 10: > sys.stderr.write ("Blahh Blahh....\n") > sys.exit(1) > else: > sys.exit(0) > > if __name__ == '__main__': > if len(sys.argv) < 3: > sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) > else: > main(sys.argv[1], sys.argv[2]) > > > The SVNLOOK_PATH is not working and python says its null when run as SVN > hook-script. Do I need to load the os environment variable? How do i pass > the value of 'which svnlook' to SVNLOOK_PATH variable. > > Thanks for your help. > > > Jay > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sat Jan 24 14:37:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 19:37:07 +0000 Subject: RegEx issues In-Reply-To: References: Message-ID: <497B6DE3.1020903@mrabarnett.plus.com> Roy Smith wrote: [snip] > Another trick when you're not 100% what you're looking at is to > explode the string like this: > >>>> [c for c in reg] > ['\\', '[', '\\', '[', '(', '.', '*', ')', '\\', ']', '\\', ']', ';'] > A shorter way is list(reg). From ppearson at nowhere.invalid Sat Jan 24 14:43:54 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 24 Jan 2009 19:43:54 GMT Subject: ossaudiodev problem: sawtooth noise References: <6tkiagFaplkjU1@mid.individual.net> <6tua0tFcpeeqU1@mid.individual.net> Message-ID: <6u19bqFcqhpoU1@mid.individual.net> On Fri, 23 Jan 2009 14:55:36 -0200, Gabriel Genellina wrote: > En Fri, 23 Jan 2009 14:36:46 -0200, Peter Pearson > escribi?: >> On Thu, 22 Jan 2009 20:58:14 -0200, Gabriel Genellina wrote: >>> En Mon, 19 Jan 2009 21:57:04 -0200, Peter Pearson >>> escribi?: >>> >>>> The following code uses ossaudiodev to read 1000 values from >>>> my sound card at a rate of 12,000 samples per second: >>>> >>>> When I select a sample rate that is not a power of 2 times >>>> 3000 samples/second, a strong and very regular sawtooth is >>>> superimposed on the signal. At some sampling frequencies, >>>> it appears as a rising sawtooth, and at other sampling >>>> frequencies it is a declining sawtooth, so I'm presumably >>>> lost in some aliasing wilderness. As best I can tell, >>>> it's a 48 KHz sawtooth. >>> >>> That could be a hardware and/or driver limitation. By example, an >>> AC97-compliant chipset may provide a fixed rate of 48000 samples/second >>> any sample rate conversion must be done by other means, if possible at >>> all. >> >> Oh! As a matter of fact, my "soundcard" *is* AC97-compliant >> ("VT8233/A/8235/8237", according to Sysinfo). So . . . this >> sawtooth might result from some software, somewhere in the bucket >> brigade between me and the hardware, attempting to perform >> sample-rate conversion? The 48 KHz coincidence seems very >> significant. > > Yep. Google found this for me: > http://mail-index.netbsd.org/port-i386/2003/02/18/0003.html > > Using a sample rate that is a sub-multiple of 48000 is perhaps a safe > approach. Back around the time I installed Ubuntu's Hardy Heron, several copies of this line appeared in /var/log/user.log.0: Jan 4 21:32:53 eleodes pulseaudio[6437]: alsa-util.c: \ Device front:0 doesn't support 44100 Hz, changed to 48000 Hz. So I suppose I'll just restrict myself to well-behaved frequencies. I'm not sure what "sub-multiple" means, but all the successful frequencies I've found over 1 KHz have been multiples of 1.5 KHz that evenly divide 48 KHz. Frequencies showing large sawtooths include 2, 4, 8, 10, and 16 KHz. -- To email me, substitute nowhere->spamcop, invalid->net. From martin at v.loewis.de Sat Jan 24 14:52:15 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 24 Jan 2009 20:52:15 +0100 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <497b716f$0$27773$9b622d9e@news.freenet.de> > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > packet_data(variable) > > How to construct these using python data types, as int and float have > no limits and their sizes are not well defined. In Python 2.x, use the regular string type: chr(n) will create a single byte, and the + operator will do the concatenation. In Python 3.x, use the bytes type (bytes() instead of chr()). Regards, Martin From skip at pobox.com Sat Jan 24 14:55:13 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 24 Jan 2009 13:55:13 -0600 Subject: Byte oriented data types in python In-Reply-To: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <18811.29217.214331.59397@montanaro.dyndns.org> Ravi> packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || Ravi> packet_data(variable) Ravi> How to construct these using python data types, as int and float have Ravi> no limits and their sizes are not well defined. Take a look at the struct and ctypes modules. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From googler.1.webmaster at spamgourmet.com Sat Jan 24 14:57:45 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 24 Jan 2009 11:57:45 -0800 (PST) Subject: MaxInt on Vista-64bit? Message-ID: Hi! I downloaded Python64 for Windows Vista64 but the value returned from sys.maxint is just a 32bit integer. I found out, thats by design, Microsoft decided to make the long value 32bit. What can I do to compile python 2.6 with maxint of 64bit integers? Can I replace the int values to a int64 value? Thanks a lot! From vincent at vincentdavis.net Sat Jan 24 15:02:25 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 24 Jan 2009 13:02:25 -0700 Subject: understanding nested lists? In-Reply-To: References: <77e831100901240829j71a76b04kd8dc6ef1fe9337b6@mail.gmail.com> Message-ID: <77e831100901241202w59a63d48q7b18341ab5c65d22@mail.gmail.com> Thanks for the info. I did not know that. Thanks Vincent Davis On Sat, Jan 24, 2009 at 10:46 AM, Steve Holden wrote: > Vincent Davis wrote: > > I have a short peace of code that is not doing what I expect. when I > > assign a value to a list in a list alist[2][4]=z this seems replace all > > the 4 elements in all the sub lists. I assume it is supposed to but this > > is not what I expect. How would I assign a value to the 4th element in > > the 2nd sublist. here is the code I have. All the printed values are > > what I would expect except that all sublist values are replaced. > > > > Thanks for your help > > Vincent > > > > on the first iteration I get ; > > new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], > > [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]] > > > > and expected this; > > new_list [[None, 0, 1, None], [None, None, None, None], > > [None, None, None, None], [None, None, None, None], [None, None, None, > > None], [None, None, None, None]] > > > > Code; > > list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]] > > new_list=[[None]*4]*6 > > print 'new_list',new_list > > for sublist in range(6): # 6 becuase it is the # of rows lists1 > > print 'sublist', sublist > > for x in list1[sublist]: > > print list1[sublist] > > print 'new_list[sublist][x]', new_list[sublist][x] > > new_list[sublist][x]=list1[sublist].index(x) > > print 'sublist', sublist, 'x', x > > print new_list[sublist][x] > > print 'new_list', new_list > > > When you create new_list you are actually filling it with six references > to the same list. Consequently when you change one of those list > elements they all appear to change (because they are all referencing the > same list object). > > Try instead > > new_list = [[None]*4 for i in range(6)] > > and you should find your code works as expected. In this case the list > is constructed with a new sublist as each element. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Jan 24 15:05:22 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:05:22 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> Message-ID: <3e6cef22-7126-419b-ad54-0b5018bb2164@w24g2000prd.googlegroups.com> On Jan 24, 12:40?am, "Gabriel Genellina" wrote: > En Sat, 24 Jan 2009 06:06:02 -0200, Carl Banks ? > escribi?: > > > > > On Jan 23, 11:45?pm, Bryan Olson wrote: > >> Carl Banks wrote: > >> > Classes in Python are mutable types, usually. ?Class instances are > >> > (except for the refcount) immutable objects, usually. > > >> There's where we disagree. I assert that class instances are usually > >> mutable objects. > > > Nope, you're dead wrong, nothing more to it. ?The bits of a class > > instance never change. ?The __dict__ is a mutable object. ?The class > > instance itself isn't. ?It's not reasonable to call an object whose > > bits can't change a mutable obect. > > > Anyway, all you're doing is distracting attention from my claim that > > instance objects wouldn't need to be locked. ?They wouldn't, no matter > > how mutable you insist these objects whose bits would never change > > are. > > Me too, I don't get what you mean. Consider a list instance, it contains a ? > count of allocated elements, and a pointer to some memory block. They ? > change when the list is resized. This counts as "mutable" to me. I really ? > don't understand your claim. Yeah, yeah, I know that, and in the bickering that ensued some aspects of the original context were lost. I should really not have been pulled into Bryan's strawman over the definition of immutable, since it's just a label, I oughtn't give a damn what it's called, I only care what it does. I didn't handle this repartee very well. Anyway, it goes back to the original vision for a mark-and-sweep Python language as I presented what seems like a long time ago. I presented the type system that had three base metatypes instead of the one base metatype we have now: immutable_type, mutable_type, and mutable_dict_type. The default metatype for Python classes would be mutable_dict_type, which is a type wherein the object itself would be mutable but it would still have all the mutator methods __init__, __setattr__, etc., but they could only act on the __dict__. mutable_dict_types would not be allowed to define any slots, and __dict__ wouldn't be reassignable. (However, it seems reasonable to allow the base tp_new to accept a dict argument.) OTOTH, list's metatype would be mutable_type, so the type object itself would be mutable. Bryan claimed that that would be a very different language from Python, apparently because it hadn't occurred to him that by-and- large, the instance itself doesn't change, only the dict does. Perhaps Bryan was thinking of __dict__'s reassignability (that certainly didn't occur to me); if he was I apologize for my snideness. HAVING SAID THAT, I still still say what I proposed would not be a radically different language from Python. A little different, of course. Much slower, almost certainly. Carl Banks From martin at v.loewis.de Sat Jan 24 15:06:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 24 Jan 2009 21:06:39 +0100 Subject: MaxInt on Vista-64bit? In-Reply-To: References: Message-ID: <497b74d0$0$10443$9b622d9e@news.freenet.de> > I downloaded Python64 for Windows Vista64 but the value returned from > sys.maxint is just a 32bit integer. I found out, thats by design, > Microsoft decided to make the long value 32bit. What can I do to > compile python 2.6 with maxint of 64bit integers? At a minimum, you need to change ob_ival to a 64-bit type in PyIntObject. Consequentially, you probably need to change a lot of other functions, e.g. PyInt_AsLong should probably also return a 64-bit integer (as should PyInt_FromLong accept one). In turn, you will need to change all callers of these functions to adjust their parameter types. And so on. > Can I replace the int values to a int64 value? See above. In short: no. Use a real 64-bit operating system (such as 64-bit Linux, Solaris, FreeBSD, etc) Regards, Martin P.S. I do wonder why you want to do this, though. Isn't Python's long integer type good enough? From googler.1.webmaster at spamgourmet.com Sat Jan 24 15:10:17 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sat, 24 Jan 2009 12:10:17 -0800 (PST) Subject: MaxInt on Vista-64bit? References: <497b74d0$0$10443$9b622d9e@news.freenet.de> Message-ID: Hi! Thanks for the fast answer. Yes, its enough but I never thought that Vista64 is not a real 64-bit operating system :-o. From google at mrabarnett.plus.com Sat Jan 24 15:23:51 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 20:23:51 +0000 Subject: Regex for Python 2.7 Message-ID: <497B78D7.4040808@mrabarnett.plus.com> Some time ago I discovered this difference between regular expressions in Python and Perl: Python \A matches at start of string \Z matches at end of string Perl \A matches at start of string \Z matches before terminal newline or at end of string \z matches at end of string In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ and \Z != $ in single-string mode. Obviously, changing Python's \Z to match Perl's could break existing code. \z could be added, but with the opposite meaning to Perl's: Python's \Z == Perl's \z Python's \z == Perl's \Z Would that be confusing? Any suggests welcome. From pavlovevidence at gmail.com Sat Jan 24 15:24:49 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:24:49 -0800 (PST) Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <87hc3pf6h5.fsf@mulj.homelinux.net> Message-ID: On Jan 24, 12:33?am, Hrvoje Niksic wrote: > Carl Banks writes: > > Anyway, all you're doing is distracting attention from my claim that > > instance objects wouldn't need to be locked. ?They wouldn't, no > > matter how mutable you insist these objects whose bits would never > > change are. > > Only if you're not implementing Python, but another language that > doesn't support __slots__ and assignment to instance.__dict__. I am only going to say all Python types prior to 3.0 support classes without __slots__, so while I agree that this would be a different language, it wouldn't necessarily be "not Python". (Python, of course, is what GvR says Python is, and he isn't going to say that the language I presented is Python. No worries there! :) I'm only saying that it is conceivably similar enough to be a different version of Python. It would be a different language in the same way that Python 2.6 is a different language from Python 3.0.) Incidentally, the proposal does allow slots to be defined, but only for actual mutable types, not for ordinary class instances. Carl Banks From pavlovevidence at gmail.com Sat Jan 24 15:27:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:27:32 -0800 (PST) Subject: Why GIL? References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <87hc3pf6h5.fsf@mulj.homelinux.net> Message-ID: <63eb1ce8-526f-45a9-b0b1-103dbb47b8e0@b38g2000prf.googlegroups.com> On Jan 24, 12:24?pm, Carl Banks wrote: > On Jan 24, 12:33?am, Hrvoje Niksic wrote: > > > Carl Banks writes: > > > Anyway, all you're doing is distracting attention from my claim that > > > instance objects wouldn't need to be locked. ?They wouldn't, no > > > matter how mutable you insist these objects whose bits would never > > > change are. > > > Only if you're not implementing Python, but another language that > > doesn't support __slots__ and assignment to instance.__dict__. > > I am only going to say all Python types prior to 3.0 support classes > without __slots__, I made a mistake, and I don't want to risk confusion at this point. "all Python ***versions** prior to 3.0" and I am talking about old-style classes, of course. Prior to 2.2 no classes at all supported slots. Carl Banks From pavlovevidence at gmail.com Sat Jan 24 15:32:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jan 2009 12:32:00 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <8c2ba480-a419-4938-85fc-08ae2e3cf173@v39g2000pro.googlegroups.com> <35f34735-46ce-4180-8623-b5d7dcfa01aa@a12g2000pro.googlegroups.com> <3e6cef22-7126-419b-ad54-0b5018bb2164@w24g2000prd.googlegroups.com> Message-ID: On Jan 24, 12:05?pm, Carl Banks wrote: > The default metatype for Python classes would be > mutable_dict_type, which is a type wherein the object itself would be > mutable but it would still have all the mutator methods __init__, > __setattr__, etc., but they could only act on the __dict__. Not wanting to risk confusion. "The default metatype for Python classes would be mutable_dict_type, which is a type wherein the object itself would be ***immutable*** but it would still have all the mutator methods __init__, __setattr__, etc., but they could only act on the __dict__." Carl Banks From sbrown.home at [spammy]gmail.com Sat Jan 24 16:03:26 2009 From: sbrown.home at [spammy]gmail.com (Sean Brown) Date: Sat, 24 Jan 2009 13:03:26 -0800 Subject: RegEx issues Message-ID: Using python 2.4.4 on OpenSolaris 2008.11 I have the following string created by opening a url that has the following string in it: td[ct] = [[ ... ]];\r\n The ... above is what I'm interested in extracting which is really a whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. The problem is it appears that python is escaping the \ in the regex because I see this: >>>reg = '\[\[(.*)\]\];' >>> reg '\\[\\[(.*)\\]\\];' Now to me looks like it would match the string - \[\[ ... \]\]; Which obviously doesn't match anything because there are no literal \ in the above string. Leaving the \ out of the \[\[ above has re.compile throw an error because [ is a special regex character. Which is why it needs to be escaped in the first place. I am either doing something really wrong, which very possible, or I've missed something obvious. Either way, I thought I'd ask why this isn't working and why it seems to be changing my regex to something else. From torriem at gmail.com Sat Jan 24 16:23:10 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 24 Jan 2009 14:23:10 -0700 Subject: Dynamic methods and lambda functions In-Reply-To: References: Message-ID: <497B86BE.7010209@gmail.com> unineuro at gmail.com wrote: > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? Basically, don't use a lambda. Create a real, local closure with a nested def block. That way the closure is created every time the parent function is called. Lambda expressions are only ever compiled once during execution. From gh at ghaering.de Sat Jan 24 16:27:03 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 24 Jan 2009 22:27:03 +0100 Subject: Is there anyway Vpython and pyODE can be made to work with newer versions of Python 2.6.1 etc. without a lot of changes to source code? In-Reply-To: References: Message-ID: <6u1fd6Fd2ef0U1@mid.uni-berlin.de> Casey Hawthorne wrote: > Is there anyway Vpython and pyODE can be made to work with newer > versions of Python 2.6.1 etc. without a lot of changes to source code? > > I suppose I'm thinking of an extra layer of indirection, which might > slow things down to much. Aren't this just Python libraries that include extension modules (i. e. modules written in C to interface external C libraries). If so, there is a good chance that just compiling them against Python 2.6 works out of the box. Otherwise the adjustments necessary will be just minor ones. Python 3.0 compatibility is a different issue, though (more work). -- Gerhard From python at bdurham.com Sat Jan 24 17:31:14 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 17:31:14 -0500 Subject: Possible to slice a string with unpacked tuple? Message-ID: <1232836274.23361.1296561633@webmail.messagingengine.com> Is there a way to slice a string with a tuple without unpacking the tuple? >>> myString = "111-222-333-444" >>> myString[ 4: 7 ] '222' Is there some way I could perform an identical slicing operation with a tuple like ( 4, 7 ) without having to unpack the tuple? >>> myTuple = ( 4, 7 ) Thanks! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Jan 24 17:35:13 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 24 Jan 2009 22:35:13 +0000 (UTC) Subject: I'm a python addict ! References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > I just started using python last week and I'm addicted. you need to try this: import antigravity http://xkcd.com/353/ From benjamin.kaplan at case.edu Sat Jan 24 17:47:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 17:47:43 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <1232836274.23361.1296561633@webmail.messagingengine.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: On Sat, Jan 24, 2009 at 5:31 PM, wrote: > Is there a way to slice a string with a tuple without unpacking the tuple? > > >>> myString = "111-222-333-444" > >>> myString[ 4: 7 ] > '222' > > Is there some way I could perform an identical slicing operation with a > tuple like ( 4, 7 ) without having to unpack the tuple? > > >>> myTuple = ( 4, 7 ) > > Thanks! > Malcolm > 1) What's wrong with unpacking the tuple? 2) Use the built-in slice. >>> myString = "111-222-333-444" >>> myTuple = (4,7) >>> mySlice = slice(*myTuple) >>> myString[mySlice] '222' -------------- next part -------------- An HTML attachment was scrubbed... URL: From xahlee at gmail.com Sat Jan 24 17:48:53 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 14:48:53 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: Just a quick relpy. Jon's tutorial: http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html is by far the best tutorial of Ocaml. It is far better than the official intro to ocaml at ?caml.inria.fr? or the popularly cited tutorial at ?ocaml-tutorial.org? . Jon's tutorial, namely the free chapter 1 of his book, is concise, to the point, well written, well organized, does not unnecessarily use abstruse jargons or concepts, does not pitch or preach engineering practices or paradigms. Jon's book title says it all: Ocaml for Scientist. Scientists are intelligent. All programing language tutorials should be modeled like this. For some detail, see: ? Examples Of Quality Documentation In The Computing Industry http://xahlee.org/perl-python/quality_docs.html Btw, i've learned far more Ocaml in the past 3 days than the about 1 month of full time trying to learn Haskell. Mostly in 2006 or 2007. I did not even obtain a basic understanding of the syntax. I do not have a basic understanding of its types or how to define a type (was quite confused in this). I don't even have a good idea what the lang's syntactical elements or structural elements or semantic elements. In fact, i have no basic understanding of the language. I tried. I tried about 4 online tutorials or downloadable paper-published books. They are extremely low quality and or idiotic. Half of the time is wasted on finding a good tutorial or reading unreadable ones, and time is spent on huge garbage texts about reading why haskell is better or currying this or monads that (they idiots lacking mathematician's perspicacity don't really understand the subject). Motherfucking idiots. (i even tried to start a mailing list and drew a web-badge for haskell by my enthusiasm. See: A Haskell A Day http://xahlee.org/haskell/haskell.html (it went no where and is now on hold indefinitely)) I really believed in Haskell, almost just by its ?we don't allow assignments and we have ?lazy evaluation??. I believed it for 10 years. No more. Jon wrote: > And the freely-available first chapter of The OCaml Journal: > > http://www.ffconsultancy.com/products/ocaml_journal/free/introduction... > > I also recommend Jason Hickey's book which, I believe, is due to be > published by Cambridge University Press soon: > > http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf Thanks. Am still reading your chapter 1 yet. Will check those out later. Xah ? http://xahlee.org/ ? On Jan 23, 4:36 pm, Jon Harrop wrote: > Xah Lee wrote: > > ok, i've been reading these Ocaml tutorials in the past few days: > > > intro to ocaml, from official site > > http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html > > > ?Objective CAML Tutorial?, most cited tutorial on the web > > http://www.ocaml-tutorial.org/ > > > The best one, is the one is > > ?Introduction to Caml? > > http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html > > by Dr Scott Smith of Johns Hopkins U, apparently a lecture note. > > I found it by as one of the top result from google search. > > You may also appreciate the freely-available first chapter of my book OCaml > for Scientists: > > http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > > And the freely-available first chapter of The OCaml Journal: > > http://www.ffconsultancy.com/products/ocaml_journal/free/introduction... > > I also recommend Jason Hickey's book which, I believe, is due to be > published by Cambridge University Press soon: > > http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u From benjamin.kaplan at case.edu Sat Jan 24 17:51:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 24 Jan 2009 17:51:30 -0500 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan wrote: > On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > > > I just started using python last week and I'm addicted. > > you need to try this: > > import antigravity > > http://xkcd.com/353/ > Just be careful with that. That guy was still floating 129 comics later (3 comics = 1 week). And still going "Woo Python". You can see him floating near the peak of Mt. Everest. http://xkcd.com/482/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sat Jan 24 17:52:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 22:52:19 +0000 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <1232836274.23361.1296561633@webmail.messagingengine.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: <497B9BA3.7080808@mrabarnett.plus.com> python at bdurham.com wrote: > Is there a way to slice a string with a tuple without unpacking the tuple? > > >>> myString = "111-222-333-444" > >>> myString[ 4: 7 ] > '222' > > Is there some way I could perform an identical slicing operation with a > tuple like ( 4, 7 ) without having to unpack the tuple? > > >>> myTuple = ( 4, 7 ) > > Thanks! > Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, then how about myString.__getslice__(*myTuple)? From python at bdurham.com Sat Jan 24 17:59:14 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 17:59:14 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> Message-ID: <1232837954.28046.1296565169@webmail.messagingengine.com> Benjamin, > Use the built-in slice. Perfect!! That's exactly what I was looking for - I didn't know this object existed. > What's wrong with unpacking the tuple? I'm extracting fields from a huge, multi-gig log file. I was trying to avoid doing something like myString[ myTuple[ 0 ]: myTuple[ 1 ] ) millions of times in a loop. Thank you! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From oktaysafak at superonline.com Sat Jan 24 18:00:27 2009 From: oktaysafak at superonline.com (oktaysafak at superonline.com) Date: Sun, 25 Jan 2009 01:00:27 +0200 (EET) Subject: Is (-1 ==True) True or False? Neither Message-ID: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> An HTML attachment was scrubbed... URL: From python at bdurham.com Sat Jan 24 18:06:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 18:06:15 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: <497B9BA3.7080808@mrabarnett.plus.com> References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: <1232838375.29456.1296566219@webmail.messagingengine.com> MRAB, > Does myString[myTuple[0] : myTuple[1]] count as unpacking? I'm not sure my use of the term 'unpacking' was totally correct, but, yes, that's what I was hoping to avoid with a simpler solution. > then how about myString.__getslice__(*myTuple)? Very interesting. I'm going to try Ben's slice() object suggestion. Thanks for your help, Malcolm From gagsl-py2 at yahoo.com.ar Sat Jan 24 18:13:15 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 21:13:15 -0200 Subject: TEST=`which test` equivalent in python? References: Message-ID: En Sat, 24 Jan 2009 17:03:33 -0200, Jay Jesus Amorin escribi?: > *SVNLOOK_PATH=os.system('which svnlook')* You've been told what's wrong with that. But instead of fixing how to invoke "which", use distutils.spawn.find_executable instead: py> from distutils.spawn import find_executable py> find_executable('svnlook') 'c:\\apps\\svn\\bin\\svnlook.exe' -- Gabriel Genellina From cosmo_general at yahoo.com Sat Jan 24 18:14:49 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Sat, 24 Jan 2009 15:14:49 -0800 (PST) Subject: Can webbrowser module get source code? Message-ID: Hi All, I played the demo of webbrowser module, with the code below: import webbrowser url = 'https://login.yahoo.com' webbrowser.open_new_tab(url) when I ran the code, it popped out a webpage nicely. I want to go further: to get the source code of the webpage being displayed. Is it possible to do it? I tried webbrow.get() but didn't work. Somebody can help? Thanks! Muddy Coder From stef.mientki at gmail.com Sat Jan 24 18:23:35 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 25 Jan 2009 00:23:35 +0100 Subject: why is this invalid b = a += b ? Message-ID: <497BA2F7.3040100@gmail.com> hello, I can assign a value to more than 1 variable (name) in one line: a = b = 3 So evaluation of this line must start at the right part. But the following is not allowed: b = 2 a = b += 1 I would think that if b has a value, and the formula is evaluated from right to left, there's nothing wrong with the above formula. thanks Stef Mientki From gagsl-py2 at yahoo.com.ar Sat Jan 24 18:23:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 21:23:44 -0200 Subject: Regex for Python 2.7 References: <497B78D7.4040808@mrabarnett.plus.com> Message-ID: En Sat, 24 Jan 2009 18:23:51 -0200, MRAB escribi?: > Some time ago I discovered this difference between regular expressions > in Python and Perl: > > Python > > \A matches at start of string > \Z matches at end of string > > Perl > > \A matches at start of string > \Z matches before terminal newline or at end of string > \z matches at end of string > > In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ > and \Z != $ in single-string mode. Why do you want the two to be equivalent? Isn't a good thing that you have both alternatives (\Z and $)? Use whichever is adequate in each case. -- Gabriel Genellina From tjreedy at udel.edu Sat Jan 24 18:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 18:35:16 -0500 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: Benjamin Kaplan wrote: > > > On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan > wrote: > > On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: > > > I just started using python last week and I'm addicted. > > you need to try this: > > import antigravity > > http://xkcd.com/353/ > > > Just be careful with that. That guy was still floating 129 comics later > (3 comics = 1 week). And still going "Woo Python". You can see him > floating near the peak of Mt. Everest. > > http://xkcd.com/482/ For a Python 'program', see http://xkcd.com/534/ From google at mrabarnett.plus.com Sat Jan 24 18:36:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:36:55 +0000 Subject: why is this invalid b = a += b ? In-Reply-To: <497BA2F7.3040100@gmail.com> References: <497BA2F7.3040100@gmail.com> Message-ID: <497BA617.7020108@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I can assign a value to more than 1 variable (name) in one line: > > a = b = 3 > > So evaluation of this line must start at the right part. > > But the following is not allowed: > > b = 2 > a = b += 1 > > I would think that if b has a value, and the formula is evaluated > from right to left, there's nothing wrong with the above formula. > Assignment is a statement, not an expression. That's why: if a = 0: ... is illegal. However, simple serial assignment such as: a = b = 3 is useful enough to be supported as a special case. From google at mrabarnett.plus.com Sat Jan 24 18:51:31 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:51:31 +0000 Subject: Regex for Python 2.7 In-Reply-To: References: <497B78D7.4040808@mrabarnett.plus.com> Message-ID: <497BA983.6010903@mrabarnett.plus.com> Gabriel Genellina wrote: > En Sat, 24 Jan 2009 18:23:51 -0200, MRAB > escribi?: > >> Some time ago I discovered this difference between regular expressions >> in Python and Perl: >> >> Python >> >> \A matches at start of string >> \Z matches at end of string >> >> Perl >> >> \A matches at start of string >> \Z matches before terminal newline or at end of string >> \z matches at end of string >> >> In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ >> and \Z != $ in single-string mode. > > Why do you want the two to be equivalent? Isn't a good thing that you > have both alternatives (\Z and $)? Use whichever is adequate in each case. > Python's \Z is equivalent to Perl's \z, but there's no equivalent to Perl's \Z in multi-line mode. From google at mrabarnett.plus.com Sat Jan 24 18:53:17 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jan 2009 23:53:17 +0000 Subject: I'm a python addict ! In-Reply-To: References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: <497BA9ED.3010905@mrabarnett.plus.com> Terry Reedy wrote: > Benjamin Kaplan wrote: >> >> >> On Sat, Jan 24, 2009 at 5:35 PM, Lie Ryan > > wrote: >> >> On Fri, 23 Jan 2009 19:58:09 -0700, Linuxguy123 wrote: >> >> > I just started using python last week and I'm addicted. >> >> you need to try this: >> >> import antigravity >> >> http://xkcd.com/353/ >> >> >> Just be careful with that. That guy was still floating 129 comics >> later (3 comics = 1 week). And still going "Woo Python". You can see >> him floating near the peak of Mt. Everest. >> >> http://xkcd.com/482/ > > For a Python 'program', see http://xkcd.com/534/ > It doesn't follow PEP 8! From robert.kern at gmail.com Sat Jan 24 19:00:33 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 18:00:33 -0600 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: On 2009-01-24 17:00, oktaysafak at superonline.com wrote: > Hi all, > > I ran into a strange case. > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > ... > >>> -1 == True > False > >>> -1 == False > False > > This works though: > >>> if -1: > print "OK" > > OK > > After some head scratching, I realized that: > - bool is a subclass of int and that True and False evaluates to 1 and > 0, so -1 is equal to neither; and > - The if -1: statement probably works by treating -1 as bool(-1). Yes. > But I can't help finding the former comparison behavior odd. I admit > that it is odd to write such code but when someone writes -1 == True, > the intention is clearly a boolean comparison, not a numerical value > comparison, isn't it? Not to me. The rules of Python state that the object on the left hand side is asked first how to compare the two values. Only if that fails is the object on the right hand side asked how to compare the objects. > As far as I understand, to do this comparison, python is casting > (loosely speaking) True to its numerical value, rather than casting -1 > to its boolean value. Not really. No casting goes on at all. bool is just one of the types that int.__eq__ knows how to handle because bool is a subclass of int. Vice-versa, bool.__eq__ knows how to handle ints, and it also does a numerical comparison; it never casts to a boolean. > So, my question is: wouldn't it make more sense to do just the opposite, > i.e. cast -1 to its boolean value and do a boolean comparison of the > operands, when one of the operands is True or False? > > Or is this too fancy? What do you think? I think that being explicit is better than being implicit. If you want to cast an object to a boolean, use bool() on it. Making special rules when comparing with booleans makes it harder to treat True and False as first-class objects. -- 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 robert.kern at gmail.com Sat Jan 24 19:03:23 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 18:03:23 -0600 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: On 2009-01-23 22:25, Aahz wrote: > In article, > Linuxguy123 wrote: >> I just started using python last week and I'm addicted. > > Welcome! Just be aware that excessive Perl-bashing is considered > somewhat tasteless on this newsgroup, but the occasional snide comment > should be fine. ;-) Or bash-bashing for that matter. :-) but-zsh-really-is-better'ly yrs, -- 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 sjmachin at lexicon.net Sat Jan 24 19:04:23 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jan 2009 16:04:23 -0800 (PST) Subject: RegEx issues References: Message-ID: <96673ff7-26df-4467-a039-74a15749cec3@a12g2000pro.googlegroups.com> On Jan 25, 5:59?am, Scott David Daniels wrote: > Sean Brown wrote: > > I have the following string ...: ?"td[ct] = [[ ... ]];\r\n" > > The ... (representing text in the string) is what I'm extracting .... > > So I think the regex \[\[(.*)\]\]; should do it. > > The problem is it appears that python is escaping the \ in the regex > > because I see this: > >>>> reg = '\[\[(.*)\]\];' > >>>> reg > > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; > > ... > > OK, you already have a good answer as to what is happening. > I'll mention that raw strings were put in the language exactly for > regex work. ?They are useful for any time you need to use the backslash > character (\) within a string (but not as the final character). > For example: > ? ? ?len(r'\a\b\c\d\e\f\g\h') == 16 and len('\a\b\c\d\e\f\g\h') == 13 > > If you get in the habit of typing regex strings as r'...' or r"...", > and examining the patters with print(somestring), you'll ease your life. All excellent suggestions, but I'm surprised that nobody has mentioned the re.VERBOSE format. Manual sez: ''' re.X re.VERBOSE This flag allows you to write regular expressions that look nicer. Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a '#' neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such '#' through the end of the line are ignored. That means that the two following regular expression objects that match a decimal number are functionally equal: a = re.compile(r"""\d + # the integral part \. # the decimal point \d * # some fractional digits""", re.X) b = re.compile(r"\d+\.\d*") ''' My comments: (1)"looks nicer" is not the point; it's understandability (2) if you need a space, use a character class ->[ ]<- not an unescaped backslash ->\ <- (3) the indentation in the manual doesn't fit my idea of "looks nicer"; I'd do a = re.compile(r""" \d + # the integral part \. # the decimal point \d * # some fractional digits """, re.X) (4) you can aid understandability by more indentation especially when you have multiple capturing expressions and (?......) gizmoids e.g. r""" ( ..... # prefix ) ( (?......) # look-back assertion (?....) # etc etc ) """ Worth a try if you find yourself going nuts getting the parentheses matching. Cheers, John From benjamin at python.org Sat Jan 24 19:08:01 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 25 Jan 2009 00:08:01 +0000 (UTC) Subject: Can webbrowser module get source code? References: Message-ID: Muddy Coder yahoo.com> writes: > I want to go > further: to get the source code of the webpage being displayed. Is it > possible to do it? I tried webbrow.get() but didn't work. Somebody can > help? Thanks! To do this, you actually need to fetch the page yourself: import urllib2 page_source = urllib2.urlopen("http://someaddress.com").read() > From sjmachin at lexicon.net Sat Jan 24 19:10:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jan 2009 16:10:28 -0800 (PST) Subject: Regex for Python 2.7 References: Message-ID: <3ba04700-56a3-40d4-91ba-0cad833f38e7@z27g2000prd.googlegroups.com> On Jan 25, 7:23?am, MRAB wrote: > Some time ago I discovered this difference between regular expressions > in Python and Perl: > > Python > > ? ? ? ? \A matches at start of string > ? ? ? ? \Z matches at end of string > > Perl > > ? ? ? ? \A matches at start of string > ? ? ? ? \Z matches before terminal newline or at end of string > ? ? ? ? \z matches at end of string > > In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^ > and \Z != $ in single-string mode. > > Obviously, changing Python's \Z to match Perl's could break existing > code. \z could be added, but with the opposite meaning to Perl's: > > ? ? ? ? Python's \Z == Perl's \z > ? ? ? ? Python's \z == Perl's \Z > > Would that be confusing? > > Any suggests welcome. IIRC there was an exchange some years ago where the perl guy (Larry?) admitted that he goofed and the consensus was that what Python had done was better. From mspetrovic at gmail.com Sat Jan 24 19:10:39 2009 From: mspetrovic at gmail.com (Mark.Petrovic) Date: Sat, 24 Jan 2009 16:10:39 -0800 (PST) Subject: Parsing a string into a datetime object References: <0f530592-e8d7-42bd-ade9-ef295627cd48@s9g2000prg.googlegroups.com> <877i4kfs83.fsf@mulj.homelinux.net> Message-ID: <8df5b4a2-296f-4bf9-8b7b-1aff52e05f8e@a12g2000pro.googlegroups.com> On Jan 24, 10:56?am, Hrvoje Niksic wrote: > "Mark.Petrovic" writes: > > Might someone comment on why %f is not accepted as a valid field > > directive in: > > >>>> from datetime import datetime > >>>> created="2009-01-24 16:04:55.882788" > >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > > python2.5/_strptime.py", line 321, in strptime > > ? ? (bad_directive, format)) > > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f' > > > This is for Python 2.5.1 under OS X. > > time.strptime is documented to use the same set of directives as > time.strftime, andhttp://docs.python.org/library/time.html#time.strftimedoesn't mention > a %f directive. Thank you for the timely reply. I guess I got mixed up by looking at the Python 2.6.1 docs, but used the Python 2.5.1 interpreter: http://docs.python.org/library/datetime.html wherein datetime.html does show the availability of the %f directive (if I'm reading all this correctly). From tjreedy at udel.edu Sat Jan 24 19:11:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 19:11:03 -0500 Subject: why is this invalid b = a += b ? In-Reply-To: <497BA2F7.3040100@gmail.com> References: <497BA2F7.3040100@gmail.com> Message-ID: Stef Mientki wrote: > hello, > > I can assign a value to more than 1 variable (name) in one line: > > a = b = 3 > > So evaluation of this line must start at the right part. > > But the following is not allowed: > > b = 2 > a = b += 1 This strikes me as slightly incoherent. Given that v op=exp is mostly that same as v = v op exp, I suppose you expect a = b += 1 to be mostly the same as a = b = b+1, but what would you do with a += b = 1, or even a *= b += 1. There is some virtur to restricting augmented assignment to one target and one delimiter. Even that seems to cause some trouble. tjr From Russ.Paielli at gmail.com Sat Jan 24 19:11:19 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 16:11:19 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: <0bed2faa-74cf-4d9a-823d-4a71cd8af429@p23g2000prp.googlegroups.com> On Jan 24, 4:03?pm, Robert Kern wrote: > On 2009-01-23 22:25, Aahz wrote: > > > In article, > > Linuxguy123 ?wrote: > >> I just started using python last week and I'm addicted. > > > Welcome! ?Just be aware that excessive Perl-bashing is considered > > somewhat tasteless on this newsgroup, but the occasional snide comment > > should be fine. ?;-) > > Or bash-bashing for that matter. ?:-) > > but-zsh-really-is-better'ly yrs, > > -- > 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 Come to think of it, when I use bash to run a series of python scripts, I could call it "bashing Python." From benjamin at python.org Sat Jan 24 19:14:26 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 25 Jan 2009 00:14:26 +0000 (UTC) Subject: Possible to slice a string with unpacked tuple? References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: MRAB mrabarnett.plus.com> writes: > Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, > then how about myString.__getslice__(*myTuple)? Please don't use special method names directly and especially not __getslice__(). It's deprecated and will be removed. From kyrie at uh.cu Sat Jan 24 19:17:37 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sat, 24 Jan 2009 19:17:37 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232842657.497bafa1833a2@mail.uh.cu> Quoting "Russ P." : > On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > > > Makes *no* sense? There's *no* good reason *at all* for the original > > > author to hide or protect internals? > > > > My bad, sorry. > > It makes sense... if the original author is an egotist who believes he > must > > control how I use that library. > > If the original author provides you with the source code and the right > to modify it, he cannot possibly control how you use the library. You > can trivially disable any access controls. But for some reason that's > not enough for you. No, I'm not satisfied with forking python just to use sys._getframe. > Has it occurred to you that some users might actually *want* access > controls? Maybe some users want to actually use the library as the > author intended it to be used. What a bizarre concept! Huh? Then... use it as the author intended. I am _not_ forcing you to use the obj._protected attributes! Even I run pylint against third party libraries just to assess if the risk of them messing with someone else's internals is worth taking (as in the case of inspect.currentframe, which is exactly the same as sys._getframe) or not (random library downloaded from the net). > Oh, but only a paranoid fool could possibly want access controls, eh? > Who's the egotist here? See? You too changed what I said. Somehow you managed to delete the _other_ situation I gave. Not worth correcting it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From digitig at gmail.com Sat Jan 24 19:31:14 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 25 Jan 2009 00:31:14 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/24 Rhodri James : > My experience with medium-sized organisations (50-100 people) is that > either you talk to Fred directly, or it doesn't happen. In particular > the more people (especially PHBs) that get involved, the slower the > change will come and the less like your original requirement it will > look. Each person, no matter how technically adept, has a significant > chance of misunderstanding what it is you need and/or expressing it > poorly to the next person in line. So you talk to Fred, and he changes the "pong" library function to go "ping", as you wish. Unfortulately, neither of you know that Alice is depending on Fred's "pong" library function to go "pong" as specified, and is totally stuffed when he delivers it and it goes "ping". That's why changes to specifications need to go through a proper specification change procedure if the team (not the organisation) is more than a few people. -- Tim Rowe From geekmail at usenot.de Sat Jan 24 19:32:45 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sun, 25 Jan 2009 01:32:45 +0100 Subject: I'm a python addict ! References: <1232765889.7151.7.camel@localhost.localdomain> Message-ID: <20090125013245.11112adf@usenot.de> On Sat, 24 Jan 2009 23:53:17 +0000 MRAB wrote: > Terry Reedy wrote: > > For a Python 'program', see http://xkcd.com/534/ > > > It doesn't follow PEP 8! So Randall can just forget about getting xkcd in the Standard Library. Let this be an example to all of you?! /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gagsl-py2 at yahoo.com.ar Sat Jan 24 19:46:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 22:46:43 -0200 Subject: RegEx issues References: Message-ID: En Sat, 24 Jan 2009 19:03:26 -0200, Sean Brown gmail.com> <" escribi?: > Using python 2.4.4 on OpenSolaris 2008.11 > > I have the following string created by opening a url that has the > following string in it: > > td[ct] = [[ ... ]];\r\n > > The ... above is what I'm interested in extracting which is really a > whole bunch of text. So I think the regex \[\[(.*)\]\]; should do it. > The problem is it appears that python is escaping the \ in the regex > because I see this: >>>> reg = '\[\[(.*)\]\];' >>>> reg > '\\[\\[(.*)\\]\\];' > > Now to me looks like it would match the string - \[\[ ... \]\]; No. Python escape character is the backslash \; if you want to include a backslash inside a string, you have to double it. By example, these are all single character strings: 'a' '\n' '\\' Coincidentally (or not), the backslash has a similar meaning in a regular expression: if you want a string containing \a (two characters) you should write "\\a". That's rather tedious and error prone. To help with this, Python allows for "raw-string literals", where no escape interpretation is done. Just put an r before the opening quote: r"\(\d+\)" (seven characters; matches numbers inside parenthesis). Also, note that when you *evaluate* an expression in the interpreter (like the lone "reg" above), it prints the "repr" of the result: for a string, it is the escaped contents surrounded by quotes. (That's very handy when debugging, but may be confusing if don't know how to interpret it) Third, Python is very permissive with wrong escape sequences: they just end up in the string, instead of flagging them as an error. In your case, \[ is an invalid escape sequence, which is left untouched in the string. py> reg = r'\[\[(.*)\]\];' py> reg '\\[\\[(.*)\\]\\];' py> print reg \[\[(.*)\]\]; py> len(reg) 13 > Which obviously doesn't match anything because there are no literal \ in > the above string. Leaving the \ out of the \[\[ above has re.compile > throw an error because [ is a special regex character. Which is why it > needs to be escaped in the first place. It works in this example: py> txt = """ ... Some text ... and td[ct] = [[ more things ]]; ... more text""" py> import re py> m = re.search(reg, txt) py> m <_sre.SRE_Match object at 0x00AC66A0> py> m.groups() (' more things ',) So maybe your r.e. doesn't match the text (the final ";"? whitespace?) For more info, see the Regular Expressions HOWTO at http://docs.python.org/howto/regex.html -- Gabriel Genellina From tgvaughan at gmail.com Sat Jan 24 20:06:48 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 17:06:48 -0800 (PST) Subject: *.python.org broken? Message-ID: Hi all, Is anybody else having trouble accessing sites (including www, docs, wiki) in the python.org tree, or is it just me? (Or just .au?) Cheers, Tim From oktaysafak at superonline.com Sat Jan 24 20:07:04 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 03:07:04 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: <497BBB38.1010803@superonline.com> Robert Kern wrote: > On 2009-01-24 17:00, oktaysafak at superonline.com wrote: >> Hi all, >> >> I ran into a strange case. >> >> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit >> (Intel)] on win32 >> ... >> >>> -1 == True >> False >> >>> -1 == False >> False >> >> This works though: >> >>> if -1: >> print "OK" >> >> OK >> >> After some head scratching, I realized that: >> - bool is a subclass of int and that True and False evaluates to 1 and >> 0, so -1 is equal to neither; and >> - The if -1: statement probably works by treating -1 as bool(-1). > > Yes. Good. > >> But I can't help finding the former comparison behavior odd. I admit >> that it is odd to write such code but when someone writes -1 == True, >> the intention is clearly a boolean comparison, not a numerical value >> comparison, isn't it? > > Not to me. The rules of Python state that the object on the left hand > side is asked first how to compare the two values. Only if that fails is > the object on the right hand side asked how to compare the objects. OK. >> As far as I understand, to do this comparison, python is casting >> (loosely speaking) True to its numerical value, rather than casting -1 >> to its boolean value. > > Not really. No casting goes on at all. Of course, I said loosely speaking. > bool is just one of the types that int.__eq__ knows how to handle > because bool is a subclass of int. > Vice-versa, bool.__eq__ knows how to handle ints, and it also does a > numerical comparison; it never casts to a boolean. That's what I'm trying to say: it would be more meaningful if int.__eq__ did a boolean comparison when the other operand is a boolean. And bool.__eq__ should as well do a boolean comparison when the other operand is an integer (or even a number). The reason is that when someone writes (-1 == True) he is clearly, definitely, absolutely asking for a boolean comparison, not a numerical one. As I said before, this is weird code; but using the True built-in for checking whether a number's value is equal to 1 would be even weirder. > >> So, my question is: wouldn't it make more sense to do just the opposite, >> i.e. cast -1 to its boolean value and do a boolean comparison of the >> operands, when one of the operands is True or False? >> >> Or is this too fancy? What do you think? > > I think that being explicit is better than being implicit. Well, I agree that explicit is better than implicit: when one wants to use the numerical values of True or False, he should make it explicit and use int(True) or int(False), but one is never interested in a boolean's numerical value (which is nonsense, IMHO). We never write counter += True, for example. > If you want to cast an object to a boolean, use bool() on it. Well, I can tell you in response that if you are interested in a boolean's *integer* value, than make it explicit and use int(True). When I write assert i == True I'm not trying to make sure that i is equal to one, I am trying to make sure that it evaluates to True (of course True is redundant here but it can make the code more readable). If I was interested in the former case, it would be most natural to write assert i == 1 but I'm interested in the latter and I think Python's treatment is not quite right here. > Making special rules when comparing with booleans makes it harder to > treat True and False as first-class objects. I don't see how fixing this makes harder to treat True and False as first-class objects. If doing the right thing takes some special casing then be it, but I don't think it's so. Anyway, thanks for the response. Oktay From tjreedy at udel.edu Sat Jan 24 20:08:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:08:58 -0500 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: oktaysafak at superonline.com wrote: > Hi all, > > I ran into a strange case. > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > ... > >>> -1 == True > False > >>> -1 == False > False > > This works though: > >>> if -1: > print "OK" > > OK > > After some head scratching, I realized that: > - bool is a subclass of int and that True and False evaluates to 1 and > 0, Yes, for historical and practical reasons. > so -1 is equal to neither; and NO builtin objects other than numbers equal to 1 or 0 are equal to True or False. > - The if -1: statement probably works by treating -1 as bool(-1). 'if condition:' *always* works by calling bool() on the condition, which is why one should *never* write 'if bool(exp):'. > But I can't help finding the former comparison behavior odd. Every object other than numbers equal to 0 or 1 has the same behavior. > I admit that it is odd to write such code but when someone writes -1 == True, It is odd to write such code because the result of comparing two constants is or could be known when it is written. So while one could write an optimizer to replace such comparisons with the known value at compile time, no one has done so. (There is an optimizer that sometimes replaces arithmetic operations on number constants, but that is because writing code that way may make it clearer: for instance, 1<<13 versus 8192.) > the intention is clearly a boolean comparison, not a numerical value > comparison, isn't it? Nope. Expecially if either side of the expression in the code is a name or collection slot. As far as the compiler is concerned, '-1' is an expression that evaluates to an object and 'True' is another expression that evaulates to another object and '==' is a comparison operator which it compiles to a call to code that calls the appropriate rich comparison methods of either or both of the two objects. > As far as I understand, to do this comparison, python is casting > (loosely speaking) True to its numerical value, rather than casting -1 > to its boolean value. I think that this is speaking so loosely as to be misleading. 'Cast' has a couple of meaning, neither of which means 'treat a subclass instance as a base class instance.' Subclass instances are automatically base class instances and are treated as such by default unless there is a subclass method that over-rides the base class method. Bool does *not* over-ride int comparison methods. >>> bool.__eq__ is int.__eq__ True I suspect that the only methods to bool are __new__ (which returns one of the only two instances allowed), __str__, and __repr__ (which return 'False' or 'True' instead of '0' or '1'). Bools are ints, not 'cast to' ints. > So, my question is: wouldn't it make more sense to do just the opposite, > i.e. cast -1 to its boolean value and do a boolean comparison of the > operands, when one of the operands is True or False? That would require that ints be subclassed from bool, which does not work. Terry Jan Reedy From kyrie at uh.cu Sat Jan 24 20:09:42 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sat, 24 Jan 2009 20:09:42 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <018aecb2$0$20629$c3e8da3@news.astraweb.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1232845782.497bbbd61af0e@mail.uh.cu> Quoting Steven D'Aprano : > On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: > > > Quoting Steven D'Aprano : > >> Makes *no* sense? There's *no* good reason *at all* for the original > >> author to hide or protect internals? > > > > My bad, sorry. > > It makes sense... if the original author is an egotist who believes he > > must control how I use that library. > > Then I guess Guido must be such an egotist, because there's plenty of > internals in Python that you can't (easy) mess with. Yeap, ignore the second part, and claim that I only said this. > > Or, if external forces make him do > > it (maybe like, 'oh, if I change python, then I'm not using python > > anymore'). > > That parenthesised comment makes no sense to me. It was directly countering your 'list' example. _I_ don't want to change _python_, nor python's assumptions and assurances. A standard python that can segfault would be no python. Again, if you think that means that deep down I like enforced data hiding, so be it. > [...] > > If a variable is marked as... I don't like 'private', I'll call it > > 'implementation detail', I would not use it without good reason. Not > > even by subclassing it. Why do you assume that I'd change list._length > > if I could? I wouldn't. > > I didn't say you would change it on a whim. I said that *if* it were > exposed to Python code, you *could* change it. You might change it > because you thought you had a good reason to. You might change it by > accident. You might not realise the consequences of changing it. Who > knows? It doesn't matter what your motives are. Exactly, they don't matter to you, unless you happen to be running my code. > My point is that you claimed that there is no good reason at all for > hiding implementation details. Python is full of implementation details > which are quite effectively hidden from Python programmers. So there are > two possibilities: I didn't say "at all". Those were your words, not mine. I said that it makes no sense that the power lies on _you_ instead of on _my team_. And, when I said that, I recall we were talking about the python language, not C. > (1) you are right that it "makes no sense" (your words) for the original > author (in this case, Guido) to hide those implementation details from > Python programmers; or Just to be clear: I think the opposite. He made a language and interpreter, and it ensures that it will not segfault because of incorrect pure python code. That is my blackbox. In doing that, he made a language where I don't have to worry that much about enforcing access restrictions. Again, if you think that means that I want enforced data hiding in python, so be it. > (2) you are wrong that it "makes no sense", because there is at least one > case where the original author (Guido again) did a sensible thing by > hiding implementation details. hiding the implementation details of a C implementation... not python. > In an effort to avoid going round and round in circles, let me explicitly > say that option (2) does not imply that it always makes sense to hide > implementation details. Huh? It makes sense to hide implementations details. I'd say it always makes sense. What doesn't make sense is that someone fights so vehemently to stop me from getting at them, on my code, on my systems. > [...] > >> So what you're saying is that the fundamental design of Python -- to be > >> a high-level language that manages memory for you while avoiding > >> common programming errors such as buffer overflows -- makes "no sense". > >> Is that what you intended? > > > > Yes, that's what I intended, obviously. I'd like to have buffer > > overflows in python. In case you don't understand irony: don't go > > putting words in my mouth. I'm not putting words in yours. > > And neither am I. I'm pointing out the logical implications of your > position. If you find those implications unpleasant, then perhaps you > should modify your position to be less extreme and more realistic. But it is realistic. You put the words "at all", and you shifted the discussion from Python to C, and from programs in python to python's implementation. [snip the comments about the advantages of data hiding. We are not talking about data hiding, we are talking about having data hiding enforced against me] > > I stand by my words - but not by your "interpretation" of them: > > > >> > What makes no sense is that it should be in the original author's > >> > power to decide, if he is not part of _our_ team. > > > > Do you _really_ read from that sentence that I should dislike python > > because it makes it a bit harder to get a buffer overflow with their > > native types? > > Well, you tell me: does it make sense for Guido to have decided to make > it hard for pure Python developers to cause buffer overflows? Yes it does. And this answers my question... You do consider the fact that I like python, that I like that python is not C, and that I use python as a blackbox, as a confirmation that I want enforced data hiding. I was truthful when I said that: if you think so, then so be it, feel free to think that I want it. We are obviously not on the same page here, we are not even talking about the same language. I guess (just a guess) that in your view, if I really didn't want enforced data hiding, I'd be programming directly in machine code or maybe making my own CPUs. If your idea of enforced data hiding includes that (it obviously includes the interpreter), then what I said was wrong. I assumed we were talking about python and that I didn't need to explicitly quantify my expressions. And, FYI, when programming in java, C++ or C#, I do use "private" and "protected" variables, not becasue I want to forbid others from using it, but because it is [rightly?] assumed that everything marked as public is safe to use - and I consider that a strong enough "external" reason to do it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From rt8396 at gmail.com Sat Jan 24 20:16:30 2009 From: rt8396 at gmail.com (r) Date: Sat, 24 Jan 2009 17:16:30 -0800 (PST) Subject: *.python.org broken? References: Message-ID: <3aad73b0-67bf-4340-abdf-ef5e64693b26@f18g2000vbf.googlegroups.com> On Jan 24, 7:06?pm, tgvaug... at gmail.com wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Cheers, > > Tim No problem here??? From Russ.Paielli at gmail.com Sat Jan 24 20:17:55 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 17:17:55 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> On Jan 24, 4:17?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > On Jan 23, 6:36?pm, Luis Zarrabeitia wrote: > > > > > Makes *no* sense? There's *no* good reason *at all* for the original > > > > author to hide or protect internals? > > > > My bad, sorry. > > > It makes sense... if the original author is an egotist who believes he > > must > > > control how I use that library. > > > If the original author provides you with the source code and the right > > to modify it, he cannot possibly control how you use the library. You > > can trivially disable any access controls. But for some reason that's > > not enough for you. > > No, I'm not satisfied with forking python just to use sys._getframe. Calling a one-word change a "fork" is quite a stretch, I'd say. > > Has it occurred to you that some users might actually *want* access > > controls? Maybe some users want to actually use the library as the > > author intended it to be used. What a bizarre concept! > > Huh? > Then... use it as the author intended. I am _not_ forcing you to use the > obj._protected attributes! But what if I want an automatic check to verify that I am using it as the author intended? Is that unreasonable? Think of enforced access restriction as an automatic "assert" every time an attribute is accessed that it is not a private attribute. I may want this automatic verification in my own code just for peace of mind. More importantly, a project manager may want it to verify that no one on the development team is accessing private attributes. Sure, he could do that with code reviews, but code reviews are far more expensive (and less reliable in some ways) than a simple check enforced by the language itself. Without enforced access protection, depending on code reviews to detect the use of private attributes is a bit like depending on security guards to keep doors closed without putting locks on the doors. You don't need a lock on a door if you can afford to post a security guard there full time, but doesn't it make more sense to put a lock on the door and have a security guard check it only occasionally? From philip at semanchuk.com Sat Jan 24 20:19:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 24 Jan 2009 20:19:38 -0500 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <2BC6E694-9726-4647-AB7D-14A516E79DDB@semanchuk.com> On Jan 24, 2009, at 8:06 PM, tgvaughan at gmail.com wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) No problem here in Durham, NC, USA. From robert.kern at gmail.com Sat Jan 24 20:23:01 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 24 Jan 2009 19:23:01 -0600 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <497BBB38.1010803@superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: On 2009-01-24 19:07, Oktay ?afak wrote: > Robert Kern wrote: >> On 2009-01-24 17:00, oktaysafak at superonline.com wrote: >>> Hi all, >>> >>> I ran into a strange case. >>> >>> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit >>> (Intel)] on win32 >>> ... >>> >>> -1 == True >>> False >>> >>> -1 == False >>> False >>> >>> This works though: >>> >>> if -1: >>> print "OK" >>> >>> OK >>> >>> After some head scratching, I realized that: >>> - bool is a subclass of int and that True and False evaluates to 1 and >>> 0, so -1 is equal to neither; and >>> - The if -1: statement probably works by treating -1 as bool(-1). >> >> Yes. > > Good. > >> >>> But I can't help finding the former comparison behavior odd. I admit >>> that it is odd to write such code but when someone writes -1 == True, >>> the intention is clearly a boolean comparison, not a numerical value >>> comparison, isn't it? >> >> Not to me. The rules of Python state that the object on the left hand >> side is asked first how to compare the two values. Only if that fails >> is the object on the right hand side asked how to compare the objects. > > OK. > >>> As far as I understand, to do this comparison, python is casting >>> (loosely speaking) True to its numerical value, rather than casting -1 >>> to its boolean value. >> >> Not really. No casting goes on at all. > > Of course, I said loosely speaking. > >> bool is just one of the types that int.__eq__ knows how to handle >> because bool is a subclass of int. Vice-versa, bool.__eq__ knows how >> to handle ints, and it also does a numerical comparison; it never >> casts to a boolean. > > That's what I'm trying to say: it would be more meaningful if int.__eq__ > did a boolean comparison when the other operand is a boolean. And > bool.__eq__ should as well do a boolean comparison when the other > operand is an integer (or even a number). The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. As I said before, this is > weird code; but using the True built-in for checking whether a number's > value is equal to 1 would be even weirder. So don't do it. There really aren't many use cases for comparing with a boolean. Just call bool() on the object. >>> So, my question is: wouldn't it make more sense to do just the opposite, >>> i.e. cast -1 to its boolean value and do a boolean comparison of the >>> operands, when one of the operands is True or False? >>> >>> Or is this too fancy? What do you think? >> >> I think that being explicit is better than being implicit. > > Well, I agree that explicit is better than implicit: when one wants to > use the numerical values of True or False, he should make it explicit > and use int(True) or int(False), but one is never interested in a > boolean's numerical value (which is nonsense, IMHO). We never write > counter += True, for example. Actually, I sum up booleans quite often. >> If you want to cast an object to a boolean, use bool() on it. > > Well, I can tell you in response that if you are interested in a > boolean's *integer* value, than make it explicit and use int(True). The two positions are not symmetrical. Your position requires special-casing equality testing; Python's position doesn't. > When > I write > > assert i == True > > I'm not trying to make sure that i is equal to one, I am trying to make > sure that it evaluates to True (of course True is redundant here but it > can make the code more readable). If I was interested in the former > case, it would be most natural to write assert i == 1 but I'm interested > in the latter and I think Python's treatment is not quite right here. Then just do "assert i" or "assert bool(i)" and be done with it. There's no need to do any comparisons at all. > > Making special rules when comparing with booleans makes it harder to > > treat True and False as first-class objects. > > I don't see how fixing this makes harder to treat True and False as > first-class objects. If doing the right thing takes some special casing > then be it, but I don't think it's so. True in ['something', False] In your semantics, this would evaluate to True because ('something' == True) is True. -- 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 tgvaughan at gmail.com Sat Jan 24 20:25:50 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 17:25:50 -0800 (PST) Subject: *.python.org broken? References: Message-ID: On Jan 25, 12:19?pm, Philip Semanchuk wrote: > On Jan 24, 2009, at 8:06 PM, tgvaug... at gmail.com wrote: > > > Hi all, > > > Is anybody else having trouble accessing sites (including www, docs, > > wiki) in the python.org tree, or is it just me? (Or just .au?) > > No problem here in Durham, NC, USA. Bugger.. Thanks anyway. From tjreedy at udel.edu Sat Jan 24 20:29:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:29:10 -0500 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: <497BBB38.1010803@superonline.com> References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: Oktay ?afak wrote: > That's what I'm trying to say: it would be more meaningful if int.__eq__ > did a boolean comparison when the other operand is a boolean. For that to be done, int would have to know about its subclass, which generally is bad design. > The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. I would say that the person does not understand Python and that the code is probably buggy. > As I said before, this is weird code; It is a bad idea to accommodate the language and interpreter to weird code which should never be written. > Well, I agree that explicit is better than implicit: when one wants to > use the numerical values of True or False, he should make it explicit > and use int(True) or int(False). The reason to make bool a subclass of int is to avoid having to do that. You do not have to like this fact of Python but it has been decided and will not change. > We never write counter += True, for example. But you might write counter += name, where you know name is bound to a bool. As I said, issubclass(bool, int) just so one would not have to write counter += int(name). >> If you want to cast an object to a boolean, use bool() on it. > Well, I can tell you in response that if you are interested in a > boolean's *integer* value, than make it explicit and use int(True). A Python bool *is* an int already: isinstance(True, int) returns True! Adding the bool subclass around 2.3 or so was a convenience that makes code and output clearer, but not a necessity. Python did fine without it just as many other languages do. Terry Jan Reedy From gagsl-py2 at yahoo.com.ar Sat Jan 24 20:42:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 24 Jan 2009 23:42:23 -0200 Subject: String comparision References: Message-ID: En Sat, 24 Jan 2009 15:08:08 -0200, S.Selvam Siva escribi?: > I am developing spell checker for my local language(tamil) using python. > I need to generate alternative word list for a miss-spelled word from the > dictionary of words.The alternatives must be as much as closer to the > miss-spelled word.As we know, ordinary string comparison wont work here . > Any suggestion for this problem is welcome. I think it would better to add Tamil support to some existing library like GNU aspell: http://aspell.net/ You are looking for "fuzzy matching": http://en.wikipedia.org/wiki/Fuzzy_string_searching In particular, the Levenshtein distance is widely used; I think there is a Python extension providing those calculations. -- Gabriel Genellina From Russ.Paielli at gmail.com Sat Jan 24 20:43:16 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 17:43:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> On Jan 24, 5:09?pm, Luis Zarrabeitia wrote: > I didn't say "at all". Those were your words, not mine. > I said that it makes no sense that the power lies on _you_ instead of on _my > team_. And, when I said that, I recall we were talking about the python > language, not C. Once again, if you have the source code for the library (and the right to modify it), how does the "power" lie with the library implementer rather than you the user? You say you don't want to "fork" the library. Let's stipulate for the sake of argument that a one-line change is indeed a "fork." Think about what you are saying. You are saying that you should dictate how the producer of the library should implement it because you don't want to be bothered to "fork" it. If you don't like his design decisions, shouldn't the onus be on *you* to make the trivial change necessary to get access to what you want? Imagine a person who repairs computers. He is really annoyed that he constantly has to remove the cover to get at the guts of the computer. So he insists that computers cases should be made without covers. After all, manufacturers put covers on computers only because they don't trust us and think we're too "stupid" to safely handle an uncovered computer box. That is logically equivalent to your position on enforced access restrictions in software. > And, FYI, when programming in java, C++ or C#, I do use "private" and > "protected" variables, not becasue I want to forbid others from using it, but > because it is [rightly?] assumed that everything marked as public is safe to use > - and I consider that a strong enough "external" reason to do it. You could just use leading underscores and note their meaning in the documentation. If that's such a great approach, why not do it? Yes, I know, it's not a widely used convention in those other languages. Fair enough. But you could still do it if it's such a good idea. From tjreedy at udel.edu Sat Jan 24 20:45:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jan 2009 20:45:25 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: Benjamin Peterson wrote: > MRAB mrabarnett.plus.com> writes: >> Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, >> then how about myString.__getslice__(*myTuple)? > > Please don't use special method names directly and especially not > __getslice__(). It's deprecated and will be removed. It is gone in 3.0. In 3.0, at least, and perhaps later 2.x (not sure) the OP should simply write myString[slice(*myTuple)] which is the semantic equivalent of myString[myTuple[0]:myTuple[1]] From python.list at tim.thechases.com Sat Jan 24 20:56:04 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Jan 2009 19:56:04 -0600 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <497BC6B4.8070908@tim.thechases.com> > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) I've had problems[1] browsing them (most irksomely, the docs) from Dillo thanks to what are apparently poor handling of IPv6 fallback rules. Dillo gets an IPv6 IP address back from DNS, tries it and fails because my ISP or router doesn't talk IPv6. However Dillo fails to fallback to IPv4 which does work (bug filed with the Debian maintainers of Dillo[2]). If I switch to using a less broken browser (Epiphany, Lynx, FireFox/IceWeasel, Safari, telnet:80, urllib), it works fine here in the Dallas area. If I disable IPv6 on my Linux box (not a great loss at this point), Dillo works as well. Tests to check: Can you resolve the IP address from the name? bash$ dig docs.python.org bash$ dig -6 docs.python.org Can you ping the target IP address? bash$ ping docs.python.org bash$ ping 82.94.164.162 (try ping6 as well) Can you traceroute to the IP address (and where does it die)? bash$ traceroute docs.python.org bash$ traceroute -6 docs.python.org Can you telnet:80 to the target IP address? bash$ telnet docs.python.org 80 GET / HTTP/1.1 host: docs.python.org Have you tried from other local ISPs? (cafe, work, school) -tkc PS: Thanks again, Martin, for your tips in troubleshooting this for me. [1] http://mail.python.org/pipermail/python-list/2008-November/517812.html [2] http://bugs.debian.org/507251 From python at bdurham.com Sat Jan 24 20:56:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Jan 2009 20:56:15 -0500 Subject: Possible to slice a string with unpacked tuple? In-Reply-To: References: <1232836274.23361.1296561633@webmail.messagingengine.com> <497B9BA3.7080808@mrabarnett.plus.com> Message-ID: <1232848575.24973.1296579329@webmail.messagingengine.com> Terry, Hi, I'm the OP in question. > the OP should simply write myString[slice(*myTuple)] My tuples define positions in a fixed width string for parsing values. So rather than 'unpacking' tuples, I'm using slice() to directly define actual field positions, eg. field_1 = slice( 4, 7 ) field_2 = slice( 7, 9 ) etc ... This allows me to extract the field values as follows: for line in myOpenFile: value_1 = line[ field_1 ] value_2 = line[ field_2 ] etc. IMO, this makes a common task like extracting fields very natural and elegant. I LOVE THIS LANGUAGE!! (to echo another recent thread in this forum) Regards, Malcolm From rhodri at wildebst.demon.co.uk Sat Jan 24 20:57:56 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 25 Jan 2009 01:57:56 -0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <0189bab5$0$20671$c3e8da3@news.astraweb.com> <8763k5dbsj.fsf.mdw@metalzone.distorted.org.uk> <7x3af91zm1.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 25 Jan 2009 00:31:14 -0000, Tim Rowe wrote: > 2009/1/24 Rhodri James : > > >> My experience with medium-sized organisations (50-100 people) is that >> either you talk to Fred directly, or it doesn't happen. In particular >> the more people (especially PHBs) that get involved, the slower the >> change will come and the less like your original requirement it will >> look. Each person, no matter how technically adept, has a significant >> chance of misunderstanding what it is you need and/or expressing it >> poorly to the next person in line. > > So you talk to Fred, and he changes the "pong" library function to go > "ping", as you wish. Unfortulately, neither of you know that Alice is > depending on Fred's "pong" library function to go "pong" as specified, > and is totally stuffed when he delivers it and it goes "ping". That's > why changes to specifications need to go through a proper > specification change procedure if the team (not the organisation) is > more than a few people. And, not coincidentally, why specification will take at least twice as long as you thought humanly possible, and any implementation you do before it's complete will probably have to be thrown away. The productivity of a team large enough that they don't all talk to each other anyway drops quite dramatically as one consequence of this. This also assumes that the "proper specification change procedure" works, which seems to be a bit on the optimistic side in many cases. But we digress. -- Rhodri James *-* Wildebeeste Herder to the Masses From oktaysafak at superonline.com Sat Jan 24 21:09:06 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 04:09:06 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: <497BC9C2.3080005@superonline.com> >> I don't see how fixing this makes harder to treat True and False as >> first-class objects. If doing the right thing takes some special casing >> then be it, but I don't think it's so. > > True in ['something', False] > > In your semantics, this would evaluate to True because ('something' == > True) is True. > No, it wouldn't. We are talking about integer-boolean equality comparisons, not boolean-string ones. But I get your point. From xahlee at gmail.com Sat Jan 24 21:17:24 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 18:17:24 -0800 (PST) Subject: syntax color lang source code in blogs or website Message-ID: For those of you using emacs, here's the elisp code that allows you to syntax color computer language source code in your blog or website. http://xahlee.org/emacs/elisp_htmlize.html to comment, here: http://xahlee.blogspot.com/2009/01/dehtmlize-source-code-in-emacs-lisp.html Xah ? http://xahlee.org/ ? From tgvaughan at gmail.com Sat Jan 24 21:24:40 2009 From: tgvaughan at gmail.com (tgvaughan at gmail.com) Date: Sat, 24 Jan 2009 18:24:40 -0800 (PST) Subject: *.python.org broken? References: Message-ID: <73e89edd-2cdc-4375-9d34-7b6aa66fdc3d@o4g2000pra.googlegroups.com> Hi Tim, thanks for your post. I could resolve but not ping, which has been the situation for the last couple of days. But not any more! I was just in the process of checking whether or not I could connect via another ISP when I discovered that the problem has apparently fixed itself. Which is great, but weird. Thanks again, Tim From oktaysafak at superonline.com Sat Jan 24 21:50:22 2009 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 25 Jan 2009 04:50:22 +0200 Subject: Is (-1 ==True) True or False? Neither In-Reply-To: References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> <497BBB38.1010803@superonline.com> Message-ID: <497BD36E.8040009@superonline.com> Terry Reedy wrote: > Oktay ?afak wrote: > >> That's what I'm trying to say: it would be more meaningful if >> int.__eq__ did a boolean comparison when the other operand is a boolean. > > For that to be done, int would have to know about its subclass, which > generally is bad design. Good point, but of course it can be done without making the int type know about the specifics of its subclass. > >> The reason is that when someone writes (-1 == True) he is clearly, >> definitely, absolutely asking for a boolean comparison, not a >> numerical one. > > I would say that the person does not understand Python and that the code > is probably buggy. > > > As I said before, this is weird code; > > It is a bad idea to accommodate the language and interpreter to weird > code which should never be written. Again, good point. Agreed. > >> Well, I agree that explicit is better than implicit: when one wants to >> use the numerical values of True or False, he should make it explicit >> and use int(True) or int(False). > > The reason to make bool a subclass of int is to avoid having to do that. > You do not have to like this fact of Python but it has been decided and > will not change. > > > We never write counter += True, for example. > > But you might write counter += name, where you know name is bound to a > bool. As I said, issubclass(bool, int) just so one would not have to > write counter += int(name). OK, my fault. Arithmetical operations was not my point, I was just trying to talk about integer values of True and False in an equality comparison context with other numbers. Of course the fact that issubclass(bool, int) is very handy in calculations like that. > >>> If you want to cast an object to a boolean, use bool() on it. > >> Well, I can tell you in response that if you are interested in a >> boolean's *integer* value, than make it explicit and use int(True). > > A Python bool *is* an int already: isinstance(True, int) returns True! I know, you don't need to shout. What I was trying to say is that using the integer value of a boolean *in a comparison with a number* doesn't make much sense *to me*. I am not trying to change Python or whatever, I am extremely pleased with it as it is. But that doesn't mean I like each and every decision that has gone into it. Like everybody else, there are things that doesn't quite fit in for me and I am trying to understand better. I just came across this behavior while trying something in the interpreter and wanted to discuss with people more knowledgeable than myself. Please keep calm! Oktay From xahlee at gmail.com Sat Jan 24 23:31:14 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 20:31:14 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> Message-ID: <1c66ef53-22a3-46b5-8fb5-3cde3deafaf3@p23g2000prp.googlegroups.com> Language, Purity, Cult, and Deception Xah Lee, 2009-01-24 [this essay is roughly a 10 years personal retrospect of some languages, in particular Scheme and Haskell.] I learned far more Ocaml in the past 2 days than the fucking 2 months i tried to learn Haskell, with 10 years of ?I WANT TO BELIEVE? in haskell. The Haskell's problem is similar to Scheme lisp, being academic and of little industrial involvement. About 10 years ago, during the dot com era around 1999, where scripting war is going on (Perl, tcl, Applescript, Userland Frontier, with in the corner Python, Ruby, Icon, Scheme, in the air of Java, HTML 3, CSS, CGI, javascript), i was sold a lie by Scheme lisp. Scheme, has a aura of elegance and minimalism that's one hundred miles in radius. I have always been a advocate of functional programing, with a heart for formal methods. Scheme, being a academic lang, has such a association. At the time, Open Source and Linux have just arrived on the scene and screaming the rounds in the industry, along with Apache & Perl. The Larry Wall scumbag and Eric Raymond motherfucker and Linus T moron and Richard Stallman often appears in interviews in mainstream media. Richard Stallman's FSF with its GNU, is quick to make sure he's not forgotten, by a campaign on naming of Linux to GNU/Linux. FSF announced that Scheme is its chosen scripting lang for GNU system. Plans and visions of Guile ? the new Scheme implementation, is that due to Scheme Lisp's power will have lang conversion abilities on the fly so programers can code in other lang if they wanted to, anywhere in the GNU platform. Around that time, i also wholeheartedly subscribed to some A Brave Gnu World bulletin of FSF with high expectations. Now, it's 2009. Ten years have passed. Guile disappeared into oblivion. Scheme is tail recursing in some unknown desert. PHP practically and quietly surpassed the motherfucking foghorn'd Perl in early 2000s to become the top 5 languages. Python has surfaced to became a mainstream. Ruby is the hip kid on the block. Where is Scheme? O, you can still hear these idiots debating tail recursions among themselves in newsgroups. Tail recursion! Tail recursion! And their standard the R6RS in 2007, by their own consensus, is one fucked up shit. In 2000, i was a fair expert in unix technologies. Sys admin to several data center's solaris boxes each costing some 20 grands. Master of Mathematica and Perl but don't know much about any other lang or lang in general. Today, i am a expert of about 5 languages and working knowledge with tens or so various ones. There is nothing in Scheme i'd consider elegant, not remotely, even if we only consider R4RS. Scheme, like other langs with a cult, sold me lie that lasted 10 years. Similarly, Haskell fucked me with a tag of ?no assignment? purity. You can try to learn the lang for years and all you'll learn is that there's something called currying and monad. I regret i learned python too in 2006. Perl is known for its intentional egregious lies, lead by the demagogue Larry Wall (disclaimer: opinion only). It fell apart unable to sustain its ?post-modernistic? deceptions. Python always seemed reasonable to me, until you stepped into it. You learned that the community is also culty, and is into certain grand visions on beauty & elegance with its increasingly complex syntax soup with backward incompatible python 3.0. The python fuckheads sport the air of ?computer science R us?, in reality they are idiots about the same level of Perl mongers. (Schemers and Haskell people at least know what they are talking about. They just don't have the know how of the industry.) I think my story can teach tech geekers something. In my experience, the langs that are truely a joy to learn and use, are those sans a cult. Mathematica, javascript, PHP, are all extremely a joy to use. Anything you want to do or learn how to do, in so far that the lang is suitable, can be done quickly. Their docs are to the point. And today i have to include Ocaml. It's not about whether the lang is functional, or whether the lang is elegant, or what theoretical power it has. Also, lang of strong academic background such as Scheme and Haskell are likely to stay forever there, regardless what is the technical nature of the lang. The background of the community, makes half what the language is. Disclaimer: All mentions of real persons are opinion only. Xah ? http://xahlee.org/ ? From kay.schluehr at gmx.net Sat Jan 24 23:56:06 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sat, 24 Jan 2009 20:56:06 -0800 (PST) Subject: Two import questions in Python 3.0 References: Message-ID: On 24 Jan., 18:51, Scott David Daniels wrote: > Kay Schluehr wrote: > > On 24 Jan., 09:21, "Gabriel Genellina" wrote: > >> If you run A.py as a script, it does not "know" it lives inside a package. > >> You must *import* A for it to become aware of the package. > >> Also, the directory containing the script comes earlier than PYTHONPATH > >> entries in sys.path -- so watch for that case too. > > Thanks, yes. I always make the same error thinking that a directory > > with the ritual __init__ file is actually a package ( as some kind of > > platonic entity ), something that is more obvious to me than it is to > > the runtime. The relative import semantics introduced with Python 2.5 > > has made the error just visible that was hidden to me for about a > > decade. Shit. > > Temper the language a bit. You lose your effectiveness by some people > reading the color of your words, rather than their meaning in code. Sigh, yes... sorry. I'm just too frustrated. Actually I don't even know why the import machinery is such a mess and I don't want to spend a huge amount of time ( like Brett Cannon ) to figure it out. I'll spent a few hours of time writing a script that turns all relative paths into absolute ones without changing the source otherwise. Then I'm at least done with that and won't ever see the "relative import in non-packages" exceptions anymore in any code I touch ( I can also ignore __package__, -m and all the other workarounds ). It's not the first time Python is in my way but this time it hurts. From xahlee at gmail.com Sun Jan 25 00:19:28 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Jan 2009 21:19:28 -0800 (PST) Subject: OCaml, Language syntax, and Proof Systems References: <8f6cbe00-247a-4646-b603-8b58faf9b65b@q30g2000prq.googlegroups.com> <1c66ef53-22a3-46b5-8fb5-3cde3deafaf3@p23g2000prp.googlegroups.com> Message-ID: Addendum: The above is not a terrible insight, but i suppose it should be useful for some application. Today, there's huge number of languages, each screaming ME! To name a few that are talked about by geekers, there's Arc, Clojure, Scalar, F#, Erlang, Ruby, Groovy, Python 3, Perl6. (for a big list, see: Proliferation of Computing Languages) So, if i want to learn another lang down the road, and wish it to be a joy to use, usable docs, large number of usable libraries, or well supported, practical community that doesn't loop into monad or tail recursion every minute, then which one should i buy? With criterions of industrial background, not culty, lang beauty matter not that much, in mind, i think Erlang, F# would be great choices, while langs like Qi, Oz, Arc, Perl6, would be most questionable. Perm url: ? Language, Purity, Cult, and Deception http://xahlee.org/UnixResource_dir/writ/lang_purity_cult_deception.html http://xahlee.blogspot.com/2009/01/language-purity-cult-and-deception.html Xah ? http://xahlee.org/ ? From kyrie at uh.cu Sun Jan 25 00:54:38 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 25 Jan 2009 00:54:38 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <1232862878.497bfe9ed3292@mail.uh.cu> Quoting "Russ P." : > Once again, if you have the source code for the library (and the right > to modify it), how does the "power" lie with the library implementer > rather than you the user? > > You say you don't want to "fork" the library. Let's stipulate for the > sake of argument that a one-line change is indeed a "fork." It is. For starters, I'd lose the information of "this attribute was intended to be internal and I'm accessing it anyway". > Think > about what you are saying. You are saying that you should dictate how > the producer of the library should implement it because you don't want > to be bothered to "fork" it. No. I am not dictating _anything_. The beauty of it, you don't have to do _anything_ for this to happen. Now, you may say that I'm trying to force you to relax and do nothing instead of complaining because the language I use doesn't put enough restrictions on me. > If you don't like his design decisions, > shouldn't the onus be on *you* to make the trivial change necessary to > get access to what you want? Or contacting him about it and maybe send him a patch, sure, why not. But this has nothing to do with enforced data hiding. Having obj._public_var is just as badly designed as having "private public_var". > Imagine a person who repairs computers. He is really annoyed that he > constantly has to remove the cover to get at the guts of the computer. > So he insists that computers cases should be made without covers. > After all, manufacturers put covers on computers only because they > don't trust us and think we're too "stupid" to safely handle an > uncovered computer box. > > That is logically equivalent to your position on enforced access > restrictions in software. Do you realize that most computer cases are trivially easy to open? (Nevermind that there are other reasons... dust, protection against physical damage, etc. My PC is locked enough to protect them, but opened enough so I can "play" with it whenever I need) > > And, FYI, when programming in java, C++ or C#, I do use "private" and > > "protected" variables, not becasue I want to forbid others from using it, > but > > because it is [rightly?] assumed that everything marked as public is safe > to use > > - and I consider that a strong enough "external" reason to do it. > > You could just use leading underscores and note their meaning in the > documentation. If that's such a great approach, why not do it? Yes, I > know, it's not a widely used convention in those other languages. Fair > enough. It is not a widely used convention, and that is reason enough for me. It's quite a contradiction to say in the code "this thing is safe to use" and then document it as "highly unsafe - do not touch". With Java and C# I'm more lenient (and work more with explicit interfaces rather than just the public/protected/private thing). BTW, the actual 'private' case for most languages is a different beast: it is used to prevent namespace pollution/name clashes. I can't easily simulate those with public attributes in C#/Java/C++ (but I concede that their 'privates' do a better job at this than python's self.__local) > But you could still do it if it's such a good idea. I think someone commented in this thread about a case where he had to do exactly that. [copying from your other reply] > But what if I want an automatic check to verify that I am using it as > the author intended? Is that unreasonable? Think of enforced access > restriction as an automatic "assert" every time an attribute is > accessed that it is not a private attribute. I think that was a reply to a message where I said that I used pylint run those checks on third party libraries. And I obviously can do the same with my own code. I don't have threading now, so I can't check if I really said that. If I didn't, well, I'm saying it now. Now, as Paul Robin pointed out, those statics checks done by pylint can't catch a runtime workaround using eval, exec or getattr/setattr. But neither can C++. By the way, I urge you to try to write code that pylint doesn't complain about. It's easy to not be satisfied with the checks it provides if you haven't used it. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From tmohr at s.netic.de Sun Jan 25 01:55:47 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 25 Jan 2009 07:55:47 +0100 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import Message-ID: Hi, i try to write a plugin system that i want to use to let users extend a module that i write. Within the module there is an extension loader that loads an extension module. This extension module should be able to import modules from my system, which provides some extensions. Basically, this here works but gives a warning: RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import Below are the files, i wonder what is wrong. It would be great if anybody could give me a hint, what provokes that warning? Best regards, Torsten. FILE psys.py: import mymodule.ext_loader import sys import os.path here = os.path.abspath('.') mpath = os.path.abspath('mymodule') epath = os.path.abspath('extension') sys.path.append(here) sys.path.append(mpath) mymodule.ext_loader.load('ext_abc') FILE mymodule/__init__.py: __all__ = ['base', 'ext_loader'] FILE mymodule/ext_loader.py: import imp import os.path def search_file(fname): for e in ['extension']: candidate = os.path.join(os.path.expanduser(e), fname) if os.path.exists(candidate): return candidate return None def load(modname): fname = modname + ".py" abname = search_file(fname) fd = open(abname, "rb") mod = imp.load_module(fname, fd, abname, ['py', 'r', imp.PY_SOURCE]) fd.close() FILE mymodule/base.py: def func1(): print "func1 called !" FILE extension/ext_abc.py: import base base.func1() From Russ.Paielli at gmail.com Sun Jan 25 02:11:59 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sat, 24 Jan 2009 23:11:59 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> On Jan 24, 9:54?pm, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > Once again, if you have the source code for the library (and the right > > to modify it), how does the "power" lie with the library implementer > > rather than you the user? > > > You say you don't want to "fork" the library. Let's stipulate for the > > sake of argument that a one-line change is indeed a "fork." > > It is. For starters, I'd lose the information of "this attribute was intended to > be internal and I'm accessing it anyway". Not really. When you get a new version of the library and try to use it, you will quickly get a reminder about the change (assuming your tests provide sufficient converage, and also assuming that the attribute is not made public in the new version). So you don't really even need to keep track of the change. > > Think > > about what you are saying. You are saying that you should dictate how > > the producer of the library should implement it because you don't want > > to be bothered to "fork" it. > > No. I am not dictating _anything_. The beauty of it, you don't have to do > _anything_ for this to happen. You are trying to dictate that the library implementer not be allowed to use enforced access restriction. And, in the larger sense, you are trying to dictate that access restrictions not be enforced in Python. > Now, you may say that I'm trying to force you to relax and do nothing instead of > complaining because the language I use doesn't put enough restrictions on me. And you are trying to put restrictions on anyone who might prefer to enforce access restrictions. If you don't allow them to do that, you are restricting them. > > If you don't like his design decisions, > > shouldn't the onus be on *you* to make the trivial change necessary to > > get access to what you want? > > Or contacting him about it and maybe send him a patch, sure, why not. But this > has nothing to do with enforced data hiding. Having obj._public_var is just as > badly designed as having "private public_var". Sure, go ahead and contact him. If he agrees that a private attribute should be public, then the problem is solved. But if he does not agree, he should not be forced to bend to your desire. > > Imagine a person who repairs computers. He is really annoyed that he > > constantly has to remove the cover to get at the guts of the computer. > > So he insists that computers cases should be made without covers. > > After all, manufacturers put covers on computers only because they > > don't trust us and think we're too "stupid" to safely handle an > > uncovered computer box. > > > That is logically equivalent to your position on enforced access > > restrictions in software. > > Do you realize that most computer cases are trivially easy to open? (Nevermind That was exactly my point. Deleting the word "private" (or whatever) is also trivially easy if you have access to the source code. From kyrie at uh.cu Sun Jan 25 03:13:14 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 25 Jan 2009 03:13:14 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> Message-ID: <1232871194.497c1f1a2f3b1@mail.uh.cu> Quoting "Russ P." : > On Jan 24, 9:54 pm, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > > > > It is. For starters, I'd lose the information of "this attribute was > intended to > > be internal and I'm accessing it anyway". > > Not really. When you get a new version of the library and try to use > it, you will quickly get a reminder about the change (assuming your > tests provide sufficient converage, and also assuming that the > attribute is not made public in the new version). So you don't really > even need to keep track of the change. See? With every new version that doesn't change the behaviour, I have to modify the source just to see if the tests run. That _is_ a fork. And that's assuming the bright case where I have the source. > > No. I am not dictating _anything_. The beauty of it, you don't have to do > > _anything_ for this to happen. > > You are trying to dictate that the library implementer not be allowed > to use enforced access restriction. And, in the larger sense, you are > trying to dictate that access restrictions not be enforced in Python. Now, please, explain to me, why are you so interested on preventing me from using the internals on my computer? If you want controls in the code that runs on your system, you can. > > Or contacting him about it and maybe send him a patch, sure, why not. But > this > > has nothing to do with enforced data hiding. Having obj._public_var is just > as > > badly designed as having "private public_var". > > Sure, go ahead and contact him. If he agrees that a private attribute > should be public, then the problem is solved. But if he does not > agree, he should not be forced to bend to your desire. Wait, if I change my project to ignore the data hiding (enforced or not), am I forcing the author to bend for my desire? Please explain your reasoning. Or better yet... don't. I will just give up, right now. This is no longer about "security", "good practices", "software engineering", "bug catching" or "formal proofs" as you've tried to paint it before. This is about you wanting to control how others use your code. And while it may be your legal right, that isn't the discussion I thought I was getting into. From akitada at gmail.com Sun Jan 25 03:18:28 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 17:18:28 +0900 Subject: Pythonic list/tuple/dict layout? Message-ID: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Hi, There is more than one way to write a list/tuple/dict in Python, and actually different styles are used in standard library. As a hobgoblin of little minds, I rather like to know which style is considered "Pythonic" in the community. I collected common layout from existing code and pasted them below. My vote would go to d1. How about yours? If there is consensus on this, that might be worth being included in PEP 8. Thanks, """ d1 = { 0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } d2 = { 0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot",} d3 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } d4 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot",} d5 = {0: "ham", 1: "jam", 2: "spam", 3: "alot", 4: "knights", 5: "who", 6: "say", 7: "ni", 8: "dead", 9: "parrot", } """ From shansen at advpubtech.com Sun Jan 25 03:22:21 2009 From: shansen at advpubtech.com (Stephen Hansen) Date: Sun, 25 Jan 2009 00:22:21 -0800 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> References: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Message-ID: <7a9c25c20901250022v9b76ad3nb986b904ef9f0e5a@mail.gmail.com> > and pasted them below. > My vote would go to d1. How about yours? > > Whatever reads best within the context of the specific code is Pythonic. -------------- next part -------------- An HTML attachment was scrubbed... URL: From danb_83 at yahoo.com Sun Jan 25 03:51:24 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Sun, 25 Jan 2009 00:51:24 -0800 (PST) Subject: Pythonic list/tuple/dict layout? References: Message-ID: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> On Jan 25, 2:18?am, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. > As a hobgoblin of little minds, I rather like to know which style is > considered "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in PEP 8. > > Thanks, > > """ > d1 = { > ? ? 0: "ham", > ? ? 1: "jam", > ? ? 2: "spam", > ? ? 3: "alot", > ? ? 4: "knights", > ? ? 5: "who", > ? ? 6: "say", > ? ? 7: "ni", > ? ? 8: "dead", > ? ? 9: "parrot", > > } > [snip] I use d1. Wow! A Python debate over curly brace placement! Imagine that! From bj_666 at gmx.net Sun Jan 25 04:13:34 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 25 Jan 2009 09:13:34 GMT Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> <87prif3ctv.fsf@benfinney.id.au> <452cfa96-50ad-43d9-8bd5-1557619ee7aa@r15g2000prd.googlegroups.com> <6tsevoFc2b1lU1@mid.uni-berlin.de> Message-ID: <6u2opuFd9kl4U1@mid.uni-berlin.de> On Sat, 24 Jan 2009 01:02:01 +0100, ?????? ??????????? wrote: >>> I don't know what an IBQ is. >> >> +IBQ- seems to be the way your newsreader displays the dashes that >> where in Ben's posting. I see "em dash" characters there: > > I see IBQ too ... also weird is that he has Content-Type: text/plain; > charset=utf-7 Why weird? Makes perfect sense: In [98]: print '+IBQ-'.decode('utf-7') ? In [99]: unicodedata.name('+IBQ-'.decode('utf-7')) Out[99]: 'EM DASH' So there are newsreaders out there that can't or at least don't decode UTF-7. Ciao, Marc 'BlackJack' Rintsch From akitada at gmail.com Sun Jan 25 04:51:38 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 18:51:38 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> References: <6e5e93e6-2616-4a2d-8e01-e3375479ee06@v5g2000pre.googlegroups.com> Message-ID: <90bb445a0901250151g2211f997ue672dce4edea72f3@mail.gmail.com> > Wow! A Python debate over curly brace placement! Imagine that! PEP8 even deals with tabs vs spaces, where to put a blank line, etc :) From m.iatrou at freemail.gr Sun Jan 25 05:16:12 2009 From: m.iatrou at freemail.gr (Michael Iatrou) Date: Sun, 25 Jan 2009 12:16:12 +0200 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> References: <90bb445a0901250018i654ede9fqefcef400c40416e3@mail.gmail.com> Message-ID: <200901251216.12715.m.iatrou@freemail.gr> When the date was Sunday 25 January 2009, Akira Kitada wrote: > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. I would vote for d1, but I don't think that this is more "pythonic", I just consider it more "clean", according to my personal aesthetic criteria. :> -- Michael Iatrou (yxzb) From gagsl-py2 at yahoo.com.ar Sun Jan 25 05:24:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 08:24:43 -0200 Subject: Regex for Python 2.7 References: <497B78D7.4040808@mrabarnett.plus.com> <497BA983.6010903@mrabarnett.plus.com> Message-ID: En Sat, 24 Jan 2009 21:51:31 -0200, MRAB escribi?: > Gabriel Genellina wrote: > > En Sat, 24 Jan 2009 18:23:51 -0200, MRAB > > escribi?: > > > >> Some time ago I discovered this difference between regular > expressions > >> in Python and Perl: > >> > >> Python > >> > >> \A matches at start of string > >> \Z matches at end of string > >> > >> Perl > >> > >> \A matches at start of string > >> \Z matches before terminal newline or at end of string > >> \z matches at end of string > >> > >> In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A > == ^ > >> and \Z != $ in single-string mode. > > > > Why do you want the two to be equivalent? Isn't a good thing that you > > have both alternatives (\Z and $)? Use whichever is adequate in each > case. > > > Python's \Z is equivalent to Perl's \z, but there's no equivalent to > Perl's \Z in multi-line mode. I tested both: import re texts = ["abc\ndef", "abc\n", "abc"] exprs = [ re.compile(r"c$"), re.compile(r"c\Z"), re.compile(r"c$", re.MULTILINE), re.compile(r"c\Z", re.MULTILINE), ] for text in texts: for expr in exprs: m = re.search(expr, text) print repr(text), expr.pattern, "match" if m else "no match" c:\temp>python test_re.py 'abc\ndef' c$ no match 'abc\ndef' c\Z no match 'abc\ndef' c$ match 'abc\ndef' c\Z no match 'abc\n' c$ match 'abc\n' c\Z no match 'abc\n' c$ match 'abc\n' c\Z no match 'abc' c$ match 'abc' c\Z match 'abc' c$ match 'abc' c\Z match @texts = ("abc\ndef", "abc\n", "abc"); @exprs = (qr/c$/, qr/c\Z/, qr/c$/m, qr/c\Z/m, # qr/c\z/, # qr/c\z/m ); foreach $text (@texts) { ($repr = $text) =~ s/\n/\\n/g; foreach $expr (@exprs) { print $repr, " ", $expr, " "; if ($text =~ $expr) { print "match\n"; } else { print "no match\n"; } } } c:\temp>perl test_re.pl abc\ndef (?-xism:c$) no match abc\ndef (?-xism:c\Z) no match abc\ndef (?m-xis:c$) match abc\ndef (?m-xis:c\Z) no match abc\n (?-xism:c$) match abc\n (?-xism:c\Z) match abc\n (?m-xis:c$) match abc\n (?m-xis:c\Z) match abc (?-xism:c$) match abc (?-xism:c\Z) match abc (?m-xis:c$) match abc (?m-xis:c\Z) match If one wants to match end-of-line or end-of-string, use $ in multiline mode. If one wants to match end-of-string only, use \Z. If one wants to match end-of-line only, use \n [not shown]. -- Gabriel Genellina From amvds at xs4all.nl Sun Jan 25 05:38:31 2009 From: amvds at xs4all.nl (Alex van der Spek) Date: 25 Jan 2009 10:38:31 GMT Subject: IDLE/Python on Asus EEE PC Message-ID: <497c4127$0$188$e4fe514c@news.xs4all.nl> Simple Python programs edited and run through IDLE work fine on my Ubuntu Linux system without any editing. However on my Asus EEE PC IDLE complains about incorrect formatting (indentation) or possibly mixing tabs/spaces. The source code is exactly the same. There is no incorrect formatting and certainly no use of tabs. I created the program on my EEE, was unable to find anything wrong with it and decided to test it on my desktop. I was amazed that it runs fine there. Can anyone explain this? I use the full desktop Xandros OS on the EEE. I downloaded IDLE from the Debian repositories. Thanks in advance, Alex van der Spek From kay.schluehr at gmx.net Sun Jan 25 06:03:05 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Sun, 25 Jan 2009 03:03:05 -0800 (PST) Subject: Dynamic methods and lambda functions References: Message-ID: On 23 Jan., 13:28, unine... at gmail.com wrote: > Hi, > I want to add some properties dynamically to a class, and then add the > corresponding getter methods. Something resulting in this: > > class Person: > def Getname(self): > return self.__name > > def Getage(self): > return self.__age > > I've implemented the next code, creating the properties from a list: > > props = [ > ("name", "peter"), > ("age", 31), > ("wife", "mary") > ] > > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) > > if __name__ == "__main__": > > person = Person() > > print person.__name > print person.__age > print person.__wife > print > print person.Getname() > print person.Getage() > print person.Getwife() > > And the resulting execution of this program is: > > peter > 31 > mary > > mary > mary > mary > > The attributes are right, but the getter are not working. The problem > is that the lambda function always execute the last parameter passed > for all instances of the methods. How could it be done the right way? > > Thanks in advance The standard trick is to "de-closure" the lambda using a keyword argument. So instead of writing lambda self: getattr(self, "__" + prop[0])) you might write lambda self, prop = prop: getattr(self, "__" + prop[0])) Now prop is local to the lambda and the lambda doesn't look up prop in the enclosing environment which certainly stores its last value. From bignose+hates-spam at benfinney.id.au Sun Jan 25 06:32:40 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 25 Jan 2009 22:32:40 +1100 Subject: Pythonic list/tuple/dict layout? References: Message-ID: <871vur39k7.fsf@benfinney.id.au> Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in > PEP 8. > > Thanks, > > """ > d1 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot", > } > > d2 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot",} These are the only two that follow PEP 8; the others don't have four-space indent levels. I actually use this style: foo = { 0: 'spam', 1: 'eggs', 2: 'beans', } because that makes it clear that *all* the indented lines are a continuation of the same statement, just like a suite of statements are all uniformly indented under (e.g.) a function definition. It seems that the author of the Python editing mode in Emacs agrees with me too (the style, at least, if not the reasoning), which makes my programming life easier. -- \ ?The future always arrives too fast, and in the wrong order.? | `\ ?Alvin Toffler | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 07:10:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jan 2009 12:10:26 GMT Subject: Pythonic list/tuple/dict layout? References: Message-ID: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:18:28 +0900, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, and > actually different styles are used in standard library. As a hobgoblin > of little minds, I rather like to know which style is considered > "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. My > vote would go to d1. How about yours? All of them. BTW, there's no need to use such large examples. Three items per dict would be sufficient to illustrate the styles, using ten items doesn't add anything useful to the discussion. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 07:21:31 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jan 2009 12:21:31 GMT Subject: Is (-1 ==True) True or False? Neither References: <19934050.1232838027517.JavaMail.root@webmail01.superonline.com> Message-ID: <018c4f8f$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 03:07:04 +0200, Oktay ?afak wrote: > The reason is that when > someone writes (-1 == True) he is clearly, definitely, absolutely asking > for a boolean comparison, not a numerical one. If I wrote (-1 == True), and I'm not sure why I would, I would expect to get the answer False, because -1 is not equal to True. Many things have truth values which are true but not equal to True. If I wanted bool(-1) == True, I'd write bool(-1) == True. Or, if I was in a whimsical mood, I'd write: ((bool(-1) == True) == True) == True # oh when to stop??? just to illustrate the foolishness of doing boolean equality comparisons like that. -- Steven From akitada at gmail.com Sun Jan 25 07:25:12 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 21:25:12 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> References: <018c4cf6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <90bb445a0901250425v9f6ab7dudf77063f6c9acae2@mail.gmail.com> > BTW, there's no need to use such large examples. Three items per dict > would be sufficient to illustrate the styles, using ten items doesn't add > anything useful to the discussion. I worried to be told 'you can make it in a line like {"ham": "jam", "spam": "alot"}' ;) From akitada at gmail.com Sun Jan 25 07:36:36 2009 From: akitada at gmail.com (Akira Kitada) Date: Sun, 25 Jan 2009 21:36:36 +0900 Subject: Pythonic list/tuple/dict layout? In-Reply-To: <871vur39k7.fsf@benfinney.id.au> References: <871vur39k7.fsf@benfinney.id.au> Message-ID: <90bb445a0901250436k2da085fcy2ceaa4ee6b05bada@mail.gmail.com> > These are the only two that follow PEP 8; the others don't have > four-space indent levels. In those examples, the following sentence in PEP 8 would be applied. "Make sure to indent the continued line appropriately." > I actually use this style: > > foo = { > 0: 'spam', > 1: 'eggs', > 2: 'beans', > } > > because that makes it clear that *all* the indented lines are a > continuation of the same statement, just like a suite of statements > are all uniformly indented under (e.g.) a function definition. > > It seems that the author of the Python editing mode in Emacs agrees > with me too (the style, at least, if not the reasoning), which makes > my programming life easier. Yes, it does, but people around me tend to prefer d1 style to that one. One purpose of this silly thread is to figure out which is most popular one... From notvalid2 at sbcglobal.net Sun Jan 25 07:49:20 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 25 Jan 2009 04:49:20 -0800 Subject: What is intvar? In-Reply-To: References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: Steve Holden wrote: > W. eWatson wrote: >> W. eWatson wrote: >>> r wrote: >>>> here is a good explanation of control vars: >>>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html >>>> >>>> Here are 3 great Tkinter refernces in order: >>>> http://infohost.nmt.edu/tcc/help/pubs/tkinter/ >>>> http://effbot.org/tkinterbook/ >>>> http://www.pythonware.com/library/tkinter/introduction/ >>> Thanks to all for the reference and tips. >>> >> tkinterbook is easy to follow, but it seems to have been abandoned in >> 2005. Did it appear in another guise somewhere else? >> > There hasn't been a lot of development on Tkinter in the intervening > period. It's a mature system, so there has been no need to update the > documentation. > > regards > Steve Unfortunately, the author seems to have stopped mid-stream. I see a fair number of FIXMEs in it. It looks like the New Mexico pdf is a fitting replacement. Perhaps Intro to Tkinter should be scrapped? Another of the author's writings, on PIL, looks good as a pdf, but is missing a TOC. Maybe some pdf knowledgeable person knows how to generate one easily. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From vicente.soler at gmail.com Sun Jan 25 08:32:38 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 25 Jan 2009 05:32:38 -0800 (PST) Subject: Newby: how to transform text into lines of text Message-ID: Hello, I'va read a text file into variable "a" a=open('FicheroTexto.txt','r') a.read() "a" contains all the lines of the text separated by '\n' characters. Now, I want to work with each line separately, without the '\n' character. How can I get variable "b" as a list of such lines? Thank you for your help From deets at nospam.web.de Sun Jan 25 08:36:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 14:36:15 +0100 Subject: Newby: how to transform text into lines of text In-Reply-To: References: Message-ID: <6u386gFdd2ocU1@mid.uni-berlin.de> vsoler schrieb: > Hello, > > I'va read a text file into variable "a" > > a=open('FicheroTexto.txt','r') > a.read() > > "a" contains all the lines of the text separated by '\n' characters. No, it doesn't. "a.read()" *returns* the contents, but you don't assign it, so it is discarded. > Now, I want to work with each line separately, without the '\n' > character. > > How can I get variable "b" as a list of such lines? The idiomatic way would be iterating over the file-object itself - which will get you the lines: with open("foo.txt") as inf: for line in inf: print line The advantage is that this works even for large files that otherwise won't fit into memory. Your approach of reading the full contents can be used like this: content = a.read() for line in content.split("\n"): print line Diez From detlev at die-offenbachs.de Sun Jan 25 08:40:46 2009 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 25 Jan 2009 14:40:46 +0100 Subject: ANN: new snapshot of the eric4 Pylons plugin released Message-ID: Hi, this is to inform everybody about the availability of the Pylons plugin for eric4. It adds Pylons support to the eric4 Python IDE. The Plugin is available via the eric4 web site at http://eric-ide.python-projects.org/index.html What is eric4 ------------- eric4 is a Python IDE, that comes with batteries included. It is extensible via a plugin system. Please see the a.m. web site for more details. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From cousinstanley at gmail.com Sun Jan 25 08:44:56 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 25 Jan 2009 13:44:56 +0000 (UTC) Subject: *.python.org broken? References: Message-ID: > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) Yes, connecting to python.org sites has been problematic for me as well .... I don't remember when the trouble started, but it's been problematic for at least a week or longer here .... -- Stanley C. Kitching Human Being Phoenix, Arizona From python.list at tim.thechases.com Sun Jan 25 08:54:13 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 07:54:13 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: <6u386gFdd2ocU1@mid.uni-berlin.de> References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <497C6F05.9010002@tim.thechases.com> > The idiomatic way would be iterating over the file-object itself - which > will get you the lines: > > with open("foo.txt") as inf: > for line in inf: > print line In versions of Python before the "with" was introduced (as in the 2.4 installations I've got at both home and work), this can simply be for line in open("foo.txt"): print line If you are processing lots of files, you can use f = open("foo.txt") for line in f: print line f.close() One other caveat here, "line" contains the newline at the end, so you might have print line.rstrip('\r\n') to remove them. > content = a.read() > for line in content.split("\n"): > print line Strings have a "splitlines()" method for this purpose: content = a.read() for line in content.splitlines(): print line -tkc From vicente.soler at gmail.com Sun Jan 25 09:04:41 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 25 Jan 2009 06:04:41 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: On 25 ene, 14:36, "Diez B. Roggisch" wrote: > vsoler schrieb: > > > Hello, > > > I'va read a text file into variable "a" > > > ? ? ?a=open('FicheroTexto.txt','r') > > ? ? ?a.read() > > > "a" contains all the lines of the text separated by '\n' characters. > > No, it doesn't. "a.read()" *returns* the contents, but you don't assign > it, so it is discarded. > > > Now, I want to work with each line separately, without the '\n' > > character. > > > How can I get variable "b" as a list of such lines? > > The idiomatic way would be iterating over the file-object itself - which > will get you the lines: > > with open("foo.txt") as inf: > ? ? ?for line in inf: > ? ? ? ? ?print line > > The advantage is that this works even for large files that otherwise > won't fit into memory. Your approach of reading the full contents can be > used like this: > > content = a.read() > for line in content.split("\n"): > ? ? ?print line > > Diez Thanks a lot. Very quick and clear From steve at holdenweb.com Sun Jan 25 09:08:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 09:08:27 -0500 Subject: *.python.org broken? In-Reply-To: References: Message-ID: Cousin Stanley wrote: >> Is anybody else having trouble accessing sites (including www, docs, >> wiki) in the python.org tree, or is it just me? (Or just .au?) > > Yes, connecting to python.org sites has been problematic > for me as well .... > > I don't remember when the trouble started, but it's been > problematic for at least a week or longer here .... > > Perhaps traceroute might start to provide some information about the problem. As far as I know there haven't been any unscheduled outages on the python.org servers recently. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From alan.isaac at gmail.com Sun Jan 25 09:28:30 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sun, 25 Jan 2009 14:28:30 GMT Subject: Python 3: range objects cannot be sliced Message-ID: On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > It is documented: > http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support ?extended slicing? Is this a documentation bug, or a bug in `range`? (I'd think the latter.) Cheers, Alan Isaac From google at mrabarnett.plus.com Sun Jan 25 09:48:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 14:48:42 +0000 Subject: IDLE/Python on Asus EEE PC In-Reply-To: <497c4127$0$188$e4fe514c@news.xs4all.nl> References: <497c4127$0$188$e4fe514c@news.xs4all.nl> Message-ID: <497C7BCA.6040801@mrabarnett.plus.com> Alex van der Spek wrote: > Simple Python programs edited and run through IDLE work fine on my Ubuntu > Linux system without any editing. > > However on my Asus EEE PC IDLE complains about incorrect formatting > (indentation) or possibly mixing tabs/spaces. The source code is exactly > the same. There is no incorrect formatting and certainly no use of tabs. > > I created the program on my EEE, was unable to find anything wrong with > it and decided to test it on my desktop. I was amazed that it runs fine > there. > > Can anyone explain this? I use the full desktop Xandros OS on the EEE. I > downloaded IDLE from the Debian repositories. > If it's not tabs, then is it line endings? From akitada at gmail.com Sun Jan 25 10:05:35 2009 From: akitada at gmail.com (Akira Kitada) Date: Mon, 26 Jan 2009 00:05:35 +0900 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <90bb445a0901250705o221c11cpa861e4266394e374@mail.gmail.com> http://downforeveryoneorjustme.com/ On Sun, Jan 25, 2009 at 10:06 AM, wrote: > Hi all, > > Is anybody else having trouble accessing sites (including www, docs, > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Cheers, > > Tim > -- > http://mail.python.org/mailman/listinfo/python-list > From pdorange at pas-de-pub-merci.mac.com Sun Jan 25 10:14:54 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sun, 25 Jan 2009 16:14:54 +0100 Subject: [MacOS] Multiple versions of a module Message-ID: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> How to manage a module with several versions on MacOS X ? All modules are installed in : "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pa ckages/" This is the default path for Mac. But for some modules i need several version (stable 1.8.1 and test 1.9.0 for example : for pygame here). I've installed the stable one from source and i go into a "pygame-1.8.0release-py2.5-macosx-10.3-i386.egg" directory. Nice. I just install the 1.9 (for test) and it go into "pygame" directory So now i got 2 versions of pygame in the site-packages dir... When i import "pygam e" from python, the 1.8.0 is imported only and 1.9.0 is complely ignored... How do python choose from several package ? Do package register them elsewhere ? I don't know how to test (temporaly) the 1.9, but also be able to go back easily to 18.8 after ? I do a site._test() and i return my only 1.8.0 module for pygame, 1.9.0 is ignored. The same with Any clue ? -- Pierre-Alain Dorange From ra.ravi.rav at gmail.com Sun Jan 25 10:27:33 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 25 Jan 2009 07:27:33 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> Message-ID: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> > Take a look at the struct and ctypes modules. struct is really not the choice. it returns an expanded string of the data and this means larger latency over bluetooth. ctypes is basically for the interface with libraries written in C (this I read from the python docs) From ra.ravi.rav at gmail.com Sun Jan 25 10:28:05 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 25 Jan 2009 07:28:05 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> Message-ID: <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> On Jan 25, 12:52?am, "Martin v. L?wis" wrote: > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > > packet_data(variable) > > > How to construct these using python data types, as int and float have > > no limits and their sizes are not well defined. > > In Python 2.x, use the regular string type: chr(n) will create a single > byte, and the + operator will do the concatenation. > > In Python 3.x, use the bytes type (bytes() instead of chr()). This looks really helpful thanks! From lkcl at lkcl.net Sun Jan 25 10:44:02 2009 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Sun, 25 Jan 2009 15:44:02 +0000 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 In-Reply-To: References: Message-ID: > Have you made some benchmarks like pystone? > Cheers, > Cesare Cesare, hi, thanks for responding: unfortunately, there's absolutely no point in making any benchmark figures under an emulated environment which does things like take 2 billion instruction cycles to start up a program named "c:/msys/bin/sh.exe", due to it inexplicably loading 200 GUI-only truetype fonts. and to do benchmarks on say windows would require that i install ... windows! so if somebody else would like to make some benchmarks, and publish them, they are most welcome to do so. l. From deets at nospam.web.de Sun Jan 25 11:17:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 17:17:40 +0100 Subject: [MacOS] Multiple versions of a module In-Reply-To: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> References: <1iu3x0h.19m7txv17wtto6N%pdorange@pas-de-pub-merci.mac.com> Message-ID: <6u3hl4Fdarm3U1@mid.uni-berlin.de> Pierre-Alain Dorange schrieb: > How to manage a module with several versions on MacOS X ? > > All modules are installed in : > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pa > ckages/" > This is the default path for Mac. > > But for some modules i need several version (stable 1.8.1 and test 1.9.0 > for example : for pygame here). > > I've installed the stable one from source and i go into a > "pygame-1.8.0release-py2.5-macosx-10.3-i386.egg" directory. Nice. > > I just install the 1.9 (for test) and it go into "pygame" directory > > So now i got 2 versions of pygame in the site-packages dir... > > When i import "pygam > e" from python, the 1.8.0 is imported only and 1.9.0 is complely > ignored... How do python choose from several package ? > Do package register them elsewhere ? > I don't know how to test (temporaly) the 1.9, but also be able to go > back easily to 18.8 after ? > > I do a site._test() and i return my only 1.8.0 module for pygame, 1.9.0 > is ignored. The same with Use the excellent virtualenv-package from Ian Bicking. http://pypi.python.org/pypi/virtualenv Nowaday,s nearly everything I develop first gets it's own VE before anything is installed. Diez From aahz at pythoncraft.com Sun Jan 25 11:18:35 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jan 2009 08:18:35 -0800 Subject: Logging help References: Message-ID: In article , koranthala wrote: > Is it possible somehow to have the logging module rotate the files >every time I start it. If you're on Linux, why not use logrotate? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From madmax209 at gmail.com Sun Jan 25 11:37:07 2009 From: madmax209 at gmail.com (Max Leason) Date: Sun, 25 Jan 2009 08:37:07 -0800 (PST) Subject: Reading the first MB of a binary file Message-ID: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Hi, I'm attempting to read the first MB of a binary file and then do a md5 hash on it so that i can find the file later despite it being moved or any file name changes that may have been made to it. These files are large (350-1400MB) video files and i often located on a different computer and I figure that there is a low risk for generating the same hash between two files. The problem occurs in the read command which returns all \x00s. Any ideas why this is happening? Code: >>>>open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) b'\x00\x00\x00\x00\x00\x00....\x00' From rridge at csclub.uwaterloo.ca Sun Jan 25 11:45:08 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 25 Jan 2009 11:45:08 -0500 Subject: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80 References: Message-ID: Luke Kenneth Casson Leighton wrote: >this is a progress report on compiling python using entirely free >software tools, no proprietary compilers or operating systems >involved, yet still linking and successfully running with msvcr80 >assemblies. MSVCR80.DLL is part of the Microsoft Visual C++ runtime library, and isn't "free software" in the FSF sense. It's free as in beer, but then so is the Microsoft compiler. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From google at mrabarnett.plus.com Sun Jan 25 12:05:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 17:05:00 +0000 Subject: Reading the first MB of a binary file In-Reply-To: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> References: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Message-ID: <497C9BBC.1030002@mrabarnett.plus.com> Max Leason wrote: > Hi, > > I'm attempting to read the first MB of a binary file and then do a > md5 hash on it so that i can find the file later despite it being > moved or any file name changes that may have been made to it. These > files are large (350-1400MB) video files and i often located on a > different computer and I figure that there is a low risk for > generating the same hash between two files. The problem occurs in the > read command which returns all \x00s. Any ideas why this is > happening? > > Code: >>>>> open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) > b'\x00\x00\x00\x00\x00\x00....\x00' > You're reading the first 1024 bytes. Perhaps the first 1024 bytes of the file _are_ all zero! Try reading more and checking those, eg: >>> SIZE = 1024 ** 2 >>> open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(SIZE) == b'\x00' * SIZE From python at bdurham.com Sun Jan 25 12:09:57 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 12:09:57 -0500 Subject: Efficient multi-slicing technique? Message-ID: <1232903397.3540.1296640123@webmail.messagingengine.com> Is there an efficient way to multi-slice a fixed with string into individual fields that's logically equivalent to the way one would slice a delimited string using .split()? Background: I'm parsing some very large, fixed line-width text files that have weekly columns of data (52 data columns plus related data). My current strategy is to loop through a list of slice()'s to build a list of the specific field values for each line. This is fine for small files, but seems inefficient. I'm hoping that there's a built-in (C based) or 3rd party module that is specifically designed for doing multiple field extractions at once. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Jan 25 12:12:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 12:12:58 -0500 Subject: Byte oriented data types in python In-Reply-To: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: Ravi wrote: >> Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. > If you read the module documentation more carefully you will see that it "converts" between the various native data types and character strings. Thus each native data type occupies only as many bytes as are required to store it in its native form (modulo any alignments needed). > ctypes is basically for the interface with libraries written in C > (this I read from the python docs) > I believe it *is* the struct module you need. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Sun Jan 25 12:23:35 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Sun, 25 Jan 2009 09:23:35 -0800 (PST) Subject: Counting number of objects Message-ID: Hi, I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following: class a(object): counter = 0 def __new__(cls, *args, **kwargs): a.counter += 1 return object.__new__(cls, *args, **kwargs) def __del__(self): a.counter -= 1 class aa(a): pass Now, the code works Ok. I have the following questions: 1. Is this code Ok? Is there any straightforward mechanism other than this to get the number of objects? 2. I read in Python Documentation that inside __del__ we should the minimum of interaction with external parameters. So, I am a little worried in subclassing __del__ to check the counter. Is whatever I have done Ok? Another question - unrelated to the major topic: How much time does it take to be proficient in Python? I have been working exclusively in Python for close to 3 months now, and even now I get inferiority complex when I read the answers sent by many of you. I have been programming for close to 7 years now (earlier in a language similar to COBOL). Does it take quite a bit of time to be proficient - as many of you guys - or am I just dumb? From steve at holdenweb.com Sun Jan 25 12:39:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 12:39:19 -0500 Subject: Counting number of objects In-Reply-To: References: Message-ID: Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls, *args, **kwargs): > a.counter += 1 > return object.__new__(cls, *args, **kwargs) > > def __del__(self): > a.counter -= 1 > > class aa(a): > pass > > Now, the code works Ok. I have the following questions: > 1. Is this code Ok? Is there any straightforward mechanism other than > this to get the number of objects? > 2. I read in Python Documentation that inside __del__ we should the > minimum of interaction with external parameters. So, I am a little > worried in subclassing __del__ to check the counter. Is whatever I > have done Ok? > Yes. Just be aware that if instances become involved in cyclic data structures (or in implementations other than CPython, where reference counting isn't used) __del__ might not be called until garbage collection kicks in, so you may want a more explicit way to stop an instance from being in the count. > Another question - unrelated to the major topic: > How much time does it take to be proficient in Python? I have been > working exclusively in Python for close to 3 months now, and even now > I get inferiority complex when I read the answers sent by many of you. > I have been programming for close to 7 years now (earlier in a > language similar to COBOL). > Does it take quite a bit of time to be proficient - as many of you > guys - or am I just dumb? By your code above you seem to be doing OK. Python is like an iceberg - only an eighth of what goes on is above the surface. That eighth will suffice for many people's total programming needs. I've been using Python ten years, and I am still learning. Just go at your own pace, and carry on asking for help when you need it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 12:46:10 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 11:46:10 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: On 2009-01-25, Ravi wrote: > >> Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. I don't know what you mean by "returns an expanded string of the data". I do know that struct does exactly what you requested. It converts between Python objects and what is bascially a C "struct" where you specify the endianness of each field and what sort of packing/padding you want. I use the struct module frequenty to impliment binary, communications protocols in Python. I've used Python/struct with transport layers ranging from Ethernet (raw, TCP, and UDP) to async serial, to CAN. -- From mdw at distorted.org.uk Sun Jan 25 13:04:26 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 18:04:26 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> Message-ID: <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Calling a one-word change a "fork" is quite a stretch, I'd say. I wouldn't. I've forked a project P if I've made a different version of it which isn't going to be reflected upstream. Now I've got to maintain my fork, merging in changes from upstream as they happen, and upgrading all the things which use my new version; if I want to distribute my program M to other people, they'll also need my forked version of whatever. Now suppose that two programs A and B both require one-word changes in P: there's a combinatorial explosion of little patches which need to be managed. A fork is a fork, regardless of how big the change is. The problem with a fork is the maintenance problem it entails. Besides, if I want to do some hacky debugging in ipython, should I really have to recompile and reinstall piles of libraries? >> > Has it occurred to you that some users might actually *want* access >> > controls? Maybe some users want to actually use the library as the >> > author intended it to be used. What a bizarre concept! >> >> Huh? >> Then... use it as the author intended. I am _not_ forcing you to use the >> obj._protected attributes! > > But what if I want an automatic check to verify that I am using it as > the author intended? Is that unreasonable? You mean that you can't /tell/ whether you typed mumble._seekrit? You're very strange. It's kind of hard to do by accident. I'd have thought that you could do that with grep, err... git grep '\._' | sed 's/self\._//g' | grep '\._' ought to do as a rough start. If you can't trust your programmers to make it clear when they're doing something dubious, I think you have bigger problems. -- [mdw] From geekmail at usenot.de Sun Jan 25 13:06:47 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sun, 25 Jan 2009 19:06:47 +0100 Subject: Counting number of objects References: Message-ID: <20090125190647.13bf4a71@usenot.de> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls, *args, **kwargs): > a.counter += 1 > return object.__new__(cls, *args, **kwargs) > > def __del__(self): > a.counter -= 1 > > class aa(a): > pass > This looks OK, although I'd suggest using "cls.counter += 1" instead of "a.counter += 1" in the __new__() method. Just seems clearer to me, esp. when you think about subclassing. This would create an asymmetry with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" there, even if it is a bit ugly-ish. Another way to go would be to use the weakref module and create a weakref-set (or list) as the counter. That way you would only need to add the objects in the __new__() method and not worry about removing them. I will admit that this is overengineering the problem a bit, but might be a good exercise. A third option could be to remove the counting functions from the class altogether. From an OO-Design point of view this would seem appropriate, because neither any individual nor mankind as a whole would know the exact amount of people in the world of hand. An entity that would actually count all the people in the world, however, would know and it makes sense to implement it separately (as a subclass of list with birth() and death() methods, for instance). I'm just saying this to give you something to think about, I'm not saying that it is necessarily better or worse for your example. > Now, the code works Ok. I have the following questions: > 1. Is this code Ok? Is there any straightforward mechanism other than > this to get the number of objects? I would say that you found the most obvious implementation there. Depending on your definition of "straightforward" you could do it as I outlined in my last example above, using explicit calls for births and deaths. This would remove the "behind the scenes" magic a bit, which may be a plus. > 2. I read in Python Documentation that inside __del__ we should the > minimum of interaction with external parameters. So, I am a little > worried in subclassing __del__ to check the counter. Is whatever I > have done Ok? > Again, seems good to me, unless you do some other trickery that may lead to __del__() not being called directly. In that case, do look at the weakref module. > Another question - unrelated to the major topic: > How much time does it take to be proficient in Python? Don't concern yourself with that question at all, is my advice. Most people can learn to write programs in under a week, and many still don't write *good* programs 20 years later. You'll get better over time, as long as you keep doing it. Thinking about that you're not good enough will just consume mental resources that would be better invested in your programs. > I have been > working exclusively in Python for close to 3 months now, and even now > I get inferiority complex when I read the answers sent by many of you. Hello?! :) Three months is *nothing* compared to the time those "many of you" folks have invested. Don't worry. Does it matter if you don't understand some stuff people write? As long as you pick out the stuff you do understand you're still gaining stuff from this group. > I have been programming for close to 7 years now (earlier in a > language similar to COBOL). Well, you have quite a background then. Why all the worries? > Does it take quite a bit of time to be proficient - as many of you > guys YES! Of course it does. > - or am I just dumb? You're writing programs and you're communicating with like-minded people about your problems (in a socially appropriate way). Not what dumb people do, in my book. cheers, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From mdw at distorted.org.uk Sun Jan 25 13:08:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 18:08:39 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> Message-ID: <8763k38di0.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Imagine a person who repairs computers. He is really annoyed that he > constantly has to remove the cover to get at the guts of the computer. > So he insists that computers cases should be made without covers. Poor analogy. He gets fed up that the computers he's meant to be servicing are arriving in sealed containers which require specialist tools to open. > After all, manufacturers put covers on computers only because they > don't trust us and think we're too "stupid" to safely handle an > uncovered computer box. It's more to do with keeping dust out, keeping air circulating, and keeping fingers away from sharp edges. Fortunately most computers are actually shipped in cases one can remove easily, using household tools -- or even no tools at all. Why, anyone would think that you were supposed to be able to grub about in there! > That is logically equivalent to your position on enforced access > restrictions in software. It is now that I've fixed it. -- [mdw] From rhamph at gmail.com Sun Jan 25 13:34:46 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Sun, 25 Jan 2009 10:34:46 -0800 (PST) Subject: Pythonic list/tuple/dict layout? References: Message-ID: <701368b9-1b33-42f7-9a9f-c37e0375b1d7@q25g2000vbn.googlegroups.com> d1 From Russ.Paielli at gmail.com Sun Jan 25 13:57:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 10:57:32 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <25df08d2-520a-4f21-8166-77bfaf4a6067@g1g2000pra.googlegroups.com> On Jan 25, 10:04?am, Mark Wooding wrote: > "Russ P." writes: > > Calling a one-word change a "fork" is quite a stretch, I'd say. > > I wouldn't. ?I've forked a project P if I've made a different version of > it which isn't going to be reflected upstream. ?Now I've got to maintain > my fork, merging in changes from upstream as they happen, and upgrading > all the things which use my new version; if I want to distribute my > program M to other people, they'll also need my forked version of > whatever. ?Now suppose that two programs A and B both require one-word > changes in P: there's a combinatorial explosion of little patches which > need to be managed. > > A fork is a fork, regardless of how big the change is. ?The problem with > a fork is the maintenance problem it entails. Not really. A "fork" is something that *diverges* from the original. That means the differences *grow* over time. In this case, the differences will not grow over time (unless you access more private attributes). As I pointed out before, you don't even need to keep track of the changes you made. You will be automatically reminded as soon as you get a new version of the library and try to use it (again, assuming that your tests provide sufficient coverage and the attribute is not changed to public). > >> > Has it occurred to you that some users might actually *want* access > >> > controls? Maybe some users want to actually use the library as the > >> > author intended it to be used. What a bizarre concept! > > >> Huh? > >> Then... use it as the author intended. I am _not_ forcing you to use the > >> obj._protected attributes! > > > But what if I want an automatic check to verify that I am using it as > > the author intended? Is that unreasonable? > > You mean that you can't /tell/ whether you typed mumble._seekrit? > You're very strange. ?It's kind of hard to do by accident. ?I'd have If I have a team of 200 programmers, I can't easily tell if one of them did that somewhere. Why do people like you have such a hard time understanding that I'm not talking here about smallish programs with one or a few developers? And even with only one programmer, he might access "mumble._seekrit" for a debugging test, then forget to take it out. > thought that you could do that with grep, err... > > ? ? ? ? git grep '\._' | sed 's/self\._//g' | grep '\._' > > ought to do as a rough start. > > If you can't trust your programmers to make it clear when they're doing > something dubious, I think you have bigger problems. Yes, I think I have bigger problems. But I like the challenge. I don't think I'd be happy working on small problems, but to each his own. From python at bdurham.com Sun Jan 25 14:09:49 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 14:09:49 -0500 Subject: Monitor a FTP site for arrival of new/updated files Message-ID: <1232910590.24534.1296651319@webmail.messagingengine.com> Any suggestions on a best practice way to monitor a remote FTP site for the arrival of new/updated files? I don't need specific code, just some coaching on technique based on your real-world experience including suggestions for a utility vs. code based solution. My goal is to maintain a local collection of files synced with a remote FTP site and when I download a new/updated file locally, run a script to process it. The arrival and format of the files that I need to sync with are beyond my control (eliminating a rsync solution) ... all I have is a generic FTP connection to a specific FTP address. Note: The remote site I'm monitoring may have multiple uploads occuring at the same time. My basic strategy is to poll the remote directory on a regular basis and compare the new directory listing to a previous snapshot of the directory listing. If a file timestamp or size has changed (or a new file has appeared), then track this file as a changed file. Once a file has been marked as changed, wait polling cycles for the file timestamp and size to remain stable, then download it, and trigger a local script to process the file. In addition to detecting new or changed files, I would compare remote directory listings to my local sync folder and delete local files that no longer exist on the remote site. My concern about using a utility is the utility's ability to detect when a remote file has finished being updated. I don't want to download files that are still in the process of being updated - I only want to download new/updated files after they've been closed on the remote site. Any ideas appreciated! Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Sun Jan 25 14:12:29 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jan 2009 19:12:29 +0000 Subject: Efficient multi-slicing technique? In-Reply-To: <1232903397.3540.1296640123@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> Message-ID: <497CB99D.9060209@mrabarnett.plus.com> python at bdurham.com wrote: > Is there an efficient way to multi-slice a fixed with string into > individual fields that's logically equivalent to the way one would slice > a delimited string using .split()? > > Background: I'm parsing some very large, fixed line-width text files > that have weekly columns of data (52 data columns plus related data). My > current strategy is to loop through a list of slice()'s to build a list > of the specific field values for each line. This is fine for small > files, but seems inefficient. I'm hoping that there's a built-in (C > based) or 3rd party module that is specifically designed for doing > multiple field extractions at once. > You could try the struct module: >>> import struct >>> struct.unpack("3s4s1s", b"123abcdX") ('123', 'abcd', 'X') From apt.shansen at gmail.com Sun Jan 25 14:32:40 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 25 Jan 2009 11:32:40 -0800 Subject: Byte oriented data types in python In-Reply-To: <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: <7a9c25c20901251132t2cdcd0c1tf278091d1daef0a4@mail.gmail.com> On Sun, Jan 25, 2009 at 7:27 AM, Ravi wrote: > > > Take a look at the struct and ctypes modules. > > struct is really not the choice. it returns an expanded string of the > data and this means larger latency over bluetooth. Noo... struct really IS the choice; that is the explicit purpose of the struct library. I went and included an example too which you're not noticing :) Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import struct >>> data = struct.pack("BB4s", 1, 4, "this") >>> data '\x01\x04this' >>> That's precisely six raw bytes which is exactly what you specified you needed: exactly one unsigned byte for packet type, one unsigned byte for length, and four bytes for the data after. In real life you'd probably use something besides "4s" to pack what you marked as "other" and "variable", of course, but still. Replace it with whatever your message requires. Really, this is how you do line protocols ;) Well there's other ways, but... --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Sun Jan 25 14:54:45 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 20:54:45 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> Message-ID: <497cc386$0$7144$9b622d9e@news.freenet.de> >>> Take a look at the struct and ctypes modules. >> struct is really not the choice. it returns an expanded string of the >> data and this means larger latency over bluetooth. > > I don't know what you mean by "returns an expanded string of > the data". > > I do know that struct does exactly what you requested. I disagree. He has a format (type, length, value), with the value being variable-sized. How do you do that in the struct module? > It converts between Python objects and what is bascially a C > "struct" where you specify the endianness of each field and > what sort of packing/padding you want. Sure. However, in the specific case, there is really no C struct that can reasonably represent the data. Hence you cannot really use the struct module. > I use the struct module frequenty to impliment binary, > communications protocols in Python. I've used Python/struct > with transport layers ranging from Ethernet (raw, TCP, and UDP) > to async serial, to CAN. Do you use it for the fixed-size parts, or also for the variable-sized data? Regards, Martin From mdw at distorted.org.uk Sun Jan 25 14:56:31 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 19:56:31 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> Message-ID: <871vur88i8.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: >> It makes sense... if the original author is an egotist who believes he >> must control how I use that library. > > Then I guess Guido must be such an egotist, because there's plenty of > internals in Python that you can't (easy) mess with. Time for some reflection. (Apposite word, as it turns out.) For the avoidance of doubt, I shall grant (and not grudgingly): * Abstraction is a useful tool in building complex systems. * Separating an interface from its implementation reduces the cognitive burden on people trying to reason about the system (including when doing design, developing clients, or trying to do more formal kinds of reasoning). * It also makes maintenance of the implementation easier: in the cases where this it's possible to improve the implementation without changing the interface, clients can benefit without having to be changed. I think that one of the reasons this conversation is going on for so long is that we haven't really talked much about what kinds of `messing' we're talking about. I think that, most of the time when I'm inconvenienced by some abstraction, it's because it's hiding something that I wanted to see -- in a read-only fashion. The implementation knows some fact that, for whatever reason, it's unwilling to reveal to me. I understand that, in some future version, the implementation might change and this fact might not be available then, or that it's an artifact of the way the implementation works in some environment -- but for whatever reason (debugging is a typical one as was pointed out upthread) it turns out that I'm actually interested in this fact. Revealing it to me can't actually hurt the invariants of the system, though I need to be somewhat careful about how long I assume it's correct. Of course, that should be entirely my responsibility. It's this common problem of wanting to dig out some piece of information which I'm really worried about. And `enforced data hiding' just slams the door in my face. I'm not best pleased by the idea. Anyway, in this regard, the CPython implementation is pretty much a paragon of virtue. It lets one get at almost everything one could want and a whole lot else besides. > Yes you could, and you could hack the OS to manipulate data behind the > scenes, and you could build a hardware device to inject whatever data > you want directly into the memory. You can do any of those things. So > what? > > Data hiding isn't about some sort of mythical 100% certainty against > any imaginable failure mode. Data hiding is a tool like any other, and > like all tools, it has uses and misuses, and it works under some > circumstances and not others. > > If you don't get 100% certainty that there will never be a failure no > matter what, what do you get? Just off the top of my head, it: How much of these do you /lose/ by having a somehat more porous interface? > * makes it easier for an optimising compiler to give fast code if it > doesn't have to assume internal details can be changed; Irrelevant for read-only inspection. For making modifications, this might be a valid point, though (a) I'm unaware of any compilers sufficiently aggressive to make very effective use of this, and (b) I'm probably willing to accommodate the compiler by being sufficiently careful about my hacking. That is: go ahead, use a fancy compiler, and I'll cope as best I can. > * makes it easier to separate interface from implementation when you > can trust that the implementation actually isn't being used; Irrelevant for read-only inspection. For making modifications: you carry on assuming that the interface is being used as you expect, and I'll take on the job of reasoning about invariants and making sure that everything continues to work. > * gives the developer more freedom to change the implementation; For read-only inspection, I might lose if you stop providing the information I want; I'll need to change my code, but you don't need to care. Probably if your implementation has changed that much, the information isn't relevant any more anyway. Besides, if your implementation changes break my code, I get to keep both pieces, and you get to laugh. What's the big deal? > * makes it possible for meaningful correctness proofs; Irrelevant for read-only inspection. For making modifications, I'll take on the responsibility for amending the proofs as necessary. > * reduces the amount of interconnections between different parts of your > program by ensuring that all interaction goes through the interface > instead of the implementation; For read-only inspection, I'm not sure this matter much -- if your implementation knows a fact that I want, then either I'll get it through your interface or dredge it out of your implementation's guts, but the module coupling's there either way. (If there was a better way to obtain that fact, then I should just have used the better way instead -- but in the case where it's a fact about your implementation's state there probably isn't a better way.) Similarly for modifications, actually: if I have a need to change your implementation's state somehow, I can do that through the interface or under the table, but there's a coupling either way. > * which in turn reduces the amount of testing you need to do; See above. > Well, you tell me: does it make sense for Guido to have decided to > make it hard for pure Python developers to cause buffer overflows? Yes. That said, I'm glad that it's /possible/ to write unsafe programs in Python. It means that the right escape-hatches are present. What I'm really complaining about are the kinds of interfaces -- which I see all to often in languages where people have embraced this kind of mandatory `information hiding' overenthusiastically -- where (a) the right features aren't there to begin with, and (b) the escape hatches are either messing or /extremely/ inconvenient. Java programs often seem to be like this. But CPython bends over backwards to provide useful information about its state: all those wacky attributes on functions and code objects and so on. Without this kind of care, I'm pretty sure that mandatory hiding is far worse as a cure than people diddling about inside other modules' implementation details is as a disease. I'm expecting you to argue that programmers would be too sensible to hide interesting information behind their mandatory-data-hiding, and I should just give them some credit. Maybe: but the situation is different. Firstly, we wouldn't be asking for this feature if we were willing to gave programmers some credit for acting responsibly when they dig about in another module's innards. Secondly, while it's certainly possible to mess up when poking about, the damage is fairly localized; if I'm overprotective about my mandatory hiding, I can screw other people. I guess that if overriding the controls was as easy as with naughty_hacking: ## stuff ... I wouldn't complain. (But I think the effect ought to be scoped /lexically/ rather than dynamically, so that grep works properly.) -- [mdw] From mdw at distorted.org.uk Sun Jan 25 15:00:10 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 20:00:10 +0000 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? References: Message-ID: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 > documentation index it lists only two references. The first is the > language manual's explanation of its use in the def statement, the > second is a transitory reference to its use in function calls, but > that's in the tutorial where it is not likely to get much attention. There's a full description of it in 5.4.3 in the Language Reference, but apparently not indexed. -- [mdw] From Russ.Paielli at gmail.com Sun Jan 25 15:01:16 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 12:01:16 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> On Jan 25, 10:04?am, Mark Wooding wrote: > > But what if I want an automatic check to verify that I am using it as > > the author intended? Is that unreasonable? > > You mean that you can't /tell/ whether you typed mumble._seekrit? > You're very strange. ?It's kind of hard to do by accident. But what if you type "mumble._seekrit" in several places, then the library implementer decides to give in to your nagging and makes it "public" by changing it to "mumble.seekrit". Now suppose you forget to make the corresponding change somewhere in your code, such as mumble._seekrit = zzz You will get no warning at all. You will just be inadvertently creating a new "private" attribute -- and the assignment that you really want will not get done. For that matter, the library implementer himself could make the same mistake and get no warning. When you think about it, you soon realize that the leading underscore convention violates the spirit if not the letter of one of the first principles of programming 101: if you have a constant parameter that appears in several places, assign the literal value in one place rather than repeating it everywhere. Then if you need to change the value, you only need to change it in one place. That reduces effort, but more importantly it reduces the potential for error. The same principle applies to "declaring" an attribute private. If that "declaration" is encoded in every occurrence of its identifier, then if you decide to change it to public, you need to change the identifier at each and every location. But if a "private" or "priv" keyword were available, you would only need to make the change in one location. From sjmachin at lexicon.net Sun Jan 25 15:06:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 12:06:48 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> On Jan 26, 12:54?am, Tim Chase wrote: > One other caveat here, "line" contains the newline at the end, so > you might have > > ? print line.rstrip('\r\n') > > to remove them. I don't understand the presence of the '\r' there. Any '\x0d' that remains after reading the file in text mode and is removed by that rstrip would be a strange occurrence in the data which the OP may prefer to find out about and deal with; it is not part of "the newline". Why suppress one particular data character in preference to others? The same applies in any case to the use of rstrip('\n'); if that finds more than one ocurrence of '\x0a' to remove, it has exceeded the mandate of removing the newline (if any). So, we are left with the unfortunately awkward if line.endswith('\n'): line = line[:-1] Cheers, John From steve at holdenweb.com Sun Jan 25 15:11:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 15:11:36 -0500 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: <1232910590.24534.1296651319@webmail.messagingengine.com> References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > Any suggestions on a best practice way to monitor a remote FTP site for > the arrival of new/updated files? I don't need specific code, just some > coaching on technique based on your real-world experience including > suggestions for a utility vs. code based solution. > > My goal is to maintain a local collection of files synced with a remote > FTP site and when I download a new/updated file locally, run a script to > process it. The arrival and format of the files that I need to sync with > are beyond my control (eliminating a rsync solution) ... all I have is a > generic FTP connection to a specific FTP address. Note: The remote site > I'm monitoring may have multiple uploads occuring at the same time. > > My basic strategy is to poll the remote directory on a regular basis and > compare the new directory listing to a previous snapshot of the > directory listing. If a file timestamp or size has changed (or a new > file has appeared), then track this file as a changed file. Once a file > has been marked as changed, wait polling cycles for the file > timestamp and size to remain stable, then download it, and trigger a > local script to process the file. In addition to detecting new or > changed files, I would compare remote directory listings to my local > sync folder and delete local files that no longer exist on the remote site. > > My concern about using a utility is the utility's ability to detect when > a remote file has finished being updated. I don't want to download files > that are still in the process of being updated - I only want to download > new/updated files after they've been closed on the remote site. > > Any ideas appreciated! > Well, the ftpmirror will cope with most of what you want to do as it is, but I am unsure how you can determine whether a file is in the process of being written on the server. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 15:13:24 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 14:13:24 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: > >>>> Take a look at the struct and ctypes modules. >>> struct is really not the choice. it returns an expanded string of the >>> data and this means larger latency over bluetooth. >> >> I don't know what you mean by "returns an expanded string of >> the data". >> >> I do know that struct does exactly what you requested. > > I disagree. He has a format (type, length, value), with the > value being variable-sized. How do you do that in the struct > module? You construct a format string for the "value" portion based on the type/length header. >> It converts between Python objects and what is bascially a C >> "struct" where you specify the endianness of each field and >> what sort of packing/padding you want. > > Sure. However, in the specific case, there is really no C > struct that can reasonably represent the data. I don't see how that can be the case. There may not be a single C struct that can represent all frames, but for every frame you should be able to come up with a C struct that can represent that frame. > Hence you cannot really use the struct module. Perhaps I don't understand his requirements, but I use the struct module for protocols with type/len/value sorts of packets. >> I use the struct module frequenty to impliment binary, >> communications protocols in Python. I've used Python/struct >> with transport layers ranging from Ethernet (raw, TCP, and >> UDP) to async serial, to CAN. > > Do you use it for the fixed-size parts, or also for the > variable-sized data? Both. For varible size/format stuff you decode the first few bytes and use them to figure out what format/layout to use for the next chunk of data. It's pretty much the same thing you do in other languages. -- Grant From martin at v.loewis.de Sun Jan 25 15:25:05 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 21:25:05 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> Message-ID: <497ccaa1$0$21633$9b622d9e@news.freenet.de> >> I disagree. He has a format (type, length, value), with the >> value being variable-sized. How do you do that in the struct >> module? > > You construct a format string for the "value" portion based on > the type/length header. Can you kindly provide example code on how to do this? > I don't see how that can be the case. There may not be a > single C struct that can represent all frames, but for every > frame you should be able to come up with a C struct that can > represent that frame. Sure. You would normally have a struct such as struct TLV{ char type; char length; char *data; }; However, the in-memory representation of that struct is *not* meant to be sent over the wire. In particular, the character pointer has no meaning outside the address space, and is thus not to be sent. > Both. For varible size/format stuff you decode the first few > bytes and use them to figure out what format/layout to use for > the next chunk of data. It's pretty much the same thing you do > in other languages. In the example he gave, I would just avoid using the struct module entirely, as it does not provide any additional value: def encode(type, length, value): return chr(type)+chr(length)+value Regards, Martin From python at bdurham.com Sun Jan 25 15:56:57 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 15:56:57 -0500 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <1232917017.11322.1296666355@webmail.messagingengine.com> > Well, the ftpmirror will cope with most of what you want to do as it is, but I am unsure how you can determine whether a file is in the process of being written on the server. Looks like that may be a fit. Thank you Steve! Malcolm From bj_666 at gmx.net Sun Jan 25 16:06:41 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 25 Jan 2009 21:06:41 GMT Subject: Reading the first MB of a binary file References: <1c06dc4d-3ba9-4082-95d3-973fb83ebcba@t26g2000prh.googlegroups.com> Message-ID: <6u42j1Fd9kl4U2@mid.uni-berlin.de> On Sun, 25 Jan 2009 08:37:07 -0800, Max Leason wrote: > I'm attempting to read the first MB of a binary file and then do a md5 > hash on it so that i can find the file later despite it being moved or > any file name changes that may have been made to it. These files are > large (350-1400MB) video files and i often located on a different > computer and I figure that there is a low risk for generating the same > hash between two files. The problem occurs in the read command which > returns all \x00s. Any ideas why this is happening? > > Code: >>>>>open("Chuck.S01E01.HDTV.XViD-YesTV.avi", "rb").read(1024) > b'\x00\x00\x00\x00\x00\x00....\x00' As MRAB says, maybe the first 1024 actually *are* all zero bytes. Wild guess: That's a file created by a bittorrent client which preallocates the files and that file above isn't downloaded completely yet!? Ciao, Marc 'BlackJack' Rintsch From mdw at distorted.org.uk Sun Jan 25 16:10:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 25 Jan 2009 21:10:08 +0000 Subject: Pythonic list/tuple/dict layout? References: Message-ID: <87prib6qj3.fsf.mdw@metalzone.distorted.org.uk> Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? It seems that I use both d1 and d4, though in both cases I omit the trailing commas. I use d1 when each item is on a separate line, and d4 when I'm packing them onto multiple lines. e.g., op = XT.make_optparse \ ([('E', 'error', {'action': 'store_const', 'dest': 'type', 'const': 'error', 'help': "Mark the window as reporting an error."}), ## ... ('t', 'title', {'dest': 'title', 'help': "Set the window's title string."})], version = VERSION, usage = '%prog [-EIQWm] [-t TITLE] [-d HEADLINE] ' 'MESSAGE [BUTTONS...]') and service_info = [('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) })] In this latter case, were I defining multiple services, I'd indent it differently: service_info = [ ('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) }), ##... ] -- [mdw] From thorsten at thorstenkampe.de Sun Jan 25 16:12:13 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 25 Jan 2009 22:12:13 +0100 Subject: Cartesian Product of two lists (itertools) Message-ID: Hi, is there a way to make itertools.product generate triples instead of pairs from two lists? For example: >>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] >>> from itertools import product >>> list(product(list1, list2, list3)) [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, 5, 7), (2, 5, 8)] so far so good... Now... >>> list(product(product(list1, list2), list3)) [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, 4), 8), ((2, 5), 7), ((2, 5), 8)] Oops, pairs of pairs instead triples. Not what I wanted. What's the best way to pre-process the arguments to "itertools.product" or to post-process the result of "itertools.product" to get what I want?! I have an older utility which I would like to replace with itertools.product. The old one uses a rather clumsy way to indicate that a triple was wanted: def cartes(seq0, seq1, modus = 'pair'): """ return the Cartesian Product of two sequences """ if modus == 'pair': return [[item0, item1] for item0 in seq0 for item1 in seq1] elif modus == 'triple': return [item0 + [item1] for item0 in seq0 for item1 in seq1] Thorsten From gert.cuykens at gmail.com Sun Jan 25 16:12:30 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 13:12:30 -0800 (PST) Subject: v = json.loads("{'test':'test'}") Message-ID: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> raise ValueError(errmsg("Expecting property name", s, end)) http://docs.python.org/library/json.html What am I doing wrong ? From sjmachin at lexicon.net Sun Jan 25 16:16:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 13:16:40 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> Message-ID: <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> On Jan 26, 2:28?am, Ravi wrote: > On Jan 25, 12:52?am, "Martin v. L?wis" wrote: > > > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > > > packet_data(variable) > > > > How to construct these using python data types, as int and float have > > > no limits and their sizes are not well defined. > > > In Python 2.x, use the regular string type: chr(n) will create a single > > byte, and the + operator will do the concatenation. > > > In Python 3.x, use the bytes type (bytes() instead of chr()). > > This looks really helpful thanks! Provided that you don't take Martin's last sentence too literally :-) | Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 | >>> p_data = b"abcd" # Omit the b prefix if using 2.5 or earlier | >>> p_len = len(p_data) | >>> p_type = 3 | >>> chr(p_type) + chr(p_len) + p_data | '\x03\x04abcd' | Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 | >>> p_data = b"abcd" | >>> p_len = len(p_data) | >>> p_type = 3 | >>> bytes(p_type) + bytes(p_len) + p_data # literal translation | b'\x00\x00\x00\x00\x00\x00\x00abcd' | >>> bytes(3) | b'\x00\x00\x00' | >>> bytes(10) | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | >>> bytes([p_type]) + bytes([p_len]) + p_data | b'\x03\x04abcd' | >>> bytes([p_type, p_len]) + p_data | b'\x03\x04abcd' Am I missing a better way to translate chr(n) from 2.x to 3.x? The meaning assigned to bytes(n) in 3.X is "interesting": 2.X: nuls = '\0' * n out_byte = chr(n) 3.X: nuls = b'\0' * n or nuls = bytes(n) out_byte = bytes([n]) Looks to me like there was already a reasonable way of getting a bytes object containing a variable number of zero bytes. Any particular reason why bytes(n) was given this specialised meaning? Can't be the speed, because the speed of bytes(n) on my box is about 50% of the speed of the * expression for n = 16 and about 65% for n = 1024. Cheers, John From martin at v.loewis.de Sun Jan 25 16:21:08 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 22:21:08 +0100 Subject: Byte oriented data types in python In-Reply-To: <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <497b716f$0$27773$9b622d9e@news.freenet.de> <9aadac5c-7ef5-403e-9b7c-5b9e7fe256ff@i24g2000prf.googlegroups.com> <13f59838-f2bd-4dbc-8006-d2edb1863307@40g2000prx.googlegroups.com> Message-ID: <497CD7C4.6010106@v.loewis.de> > Looks to me like there was already a reasonable way of getting a bytes > object containing a variable number of zero bytes. Any particular > reason why bytes(n) was given this specialised meaning? I think it was because bytes() was originally mutable, and you need a way to create a buffer of n bytes. Now that bytes() ended up immutable (and bytearray was added), it's perhaps not so useful anymore. Of course, it would be confusing if bytes(4) created a sequence of one byte, yet bytearray(4) created four bytes. Regards, Martin From __peter__ at web.de Sun Jan 25 16:38:33 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 25 Jan 2009 22:38:33 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? You need proper quotation marks: >>> s = json.dumps({'test':'test'}) >>> s '{"test": "test"}' >>> json.loads(s) {u'test': u'test'} The JSON format is described here: http://www.json.org/ Peter From livibetter at gmail.com Sun Jan 25 16:42:11 2009 From: livibetter at gmail.com (livibetter) Date: Sun, 25 Jan 2009 13:42:11 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: On Jan 26, 5:12?am, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end))http://docs.python.org/library/json.html > What am I doing wrong ? You use wrong quotes, it should be wrapped by double quotes not single quotes. Read http://json.org/: "A string is a collection of zero or more Unicode characters, wrapped in double quotes, ..." >>> v = json.loads('{"test":"test"}') >>> v {u'test': u'test'} From jcd at sdf.lonestar.org Sun Jan 25 16:47:20 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sun, 25 Jan 2009 16:47:20 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: <1232920040.11216.4.camel@mctell> Please include all relevant information in the *body* of your message, not just in the subject. It's a pain having to piece a question back together between the subject. On Sun, 2009-01-25 at 13:12 -0800, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? JSON requires strings to be enclosed in double quotes. It is not as flexible as python when it comes to quotation. If you change your example to v = json.loads('{"test":"test"}') it will work. (Note JSON also doesn't allow trailing commas, so '{"test":"test",}' will also fail) Cheers, Cliff > -- > http://mail.python.org/mailman/listinfo/python-list > From mal at egenix.com Sun Jan 25 17:02:31 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Sun, 25 Jan 2009 23:02:31 +0100 Subject: Securing a database In-Reply-To: References: Message-ID: <497CE177.3040907@egenix.com> On 2009-01-23 08:26, kt83313 at gmail.com wrote: > My company provides some services online, which now they are planning > to make it offline and sell to customers who can use it in their > networks. > > One of our major moneywinners is some data which is stored in a > database. Now, this data inside the database was obtained after paying > through the nose - so the company does not want to disclose the data > in the DB to the outside world - not to mention the lawsuits which the > original providers of data will start which will sink the company if > the data goes out. > > Now, the code is in Python - and we have a big problem. How to secure > the data in DB? One idea was to encrypt it and store the password in > the code. I dont believe security through obscurity - and python code > can easily be reverse-engineered too - right? > > Is it even possible to secure a data in this case? That depends a lot on what you call "secure". The data will have to get processed by the CPU one way or another and there are lots of ways to monitor such operations, either through software (debuggers, loggers, etc.) or hardware (low-level debuggers, signal analyzers, etc.). The best you can do is make it just a little harder to get at the data, ie. implement a simple but non-trivial data protection mechanism, and then use legal means to protect yourself from any wrong-doing of your customers. One way to do this, is by encrypting the data for the database and decrypting it whenever you start the application. If you use an in-memory database for the application, this will provide such a simple but non-trivial data protection scheme. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 25 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From grante at visi.com Sun Jan 25 17:12:08 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 16:12:08 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> You construct a format string for the "value" portion based on >> the type/length header. > > Can you kindly provide example code on how to do this? OK, something like this to handle received data where there is an initial 8-bit type field that is 1 for 16-bit unsigned integers in network byte-order, 2 for 32-bit IEEE floats in network byte-order. We'll further assume that the 'length' field comes next as a 16 bit unsigned value in network order and represents "how many" objects of the specified type follow: dtype = ord(rawdata[0]) dcount = struct.unpack("!H",rawdata[1:3]) if dtype == 1: fmtstr = "!" + "H"*dcount elif dtype == 2: fmtstr = "!" + "f"*dcount rlen = struct.calcsize(fmtstr) data = struct.unpack(fmtstr,rawdata[3:3+rlen]) leftover = rawdata[3+rlen:] >> I don't see how that can be the case. There may not be a >> single C struct that can represent all frames, but for every >> frame you should be able to come up with a C struct that can >> represent that frame. > > Sure. You would normally have a struct such as > > struct TLV{ > char type; > char length; > char *data; > }; > > However, the in-memory representation of that struct is *not* > meant to be sent over the wire. In particular, the character > pointer has no meaning outside the address space, and is thus > not to be sent. Well if it's not representing the layout of the data we're trying to deal with, then it's irrelevent. We are talking about how convert python objects to/from data in the 'on-the-wire' format, right? Or isn't that what the OP is asking about? >> Both. For varible size/format stuff you decode the first few >> bytes and use them to figure out what format/layout to use for >> the next chunk of data. It's pretty much the same thing you do >> in other languages. > > In the example he gave, I would just avoid using the struct module > entirely, as it does not provide any additional value: > > def encode(type, length, value): > return chr(type)+chr(length)+value Like this? >>> def encode(type,length,value): ... return chr(type)+chr(length)+value ... >>> print encode('float', 1, 3.14159) Traceback (most recent call last): File "", line 1, in File "", line 2, in encode TypeError: an integer is required >>> -- Grant From gdamjan at gmail.com Sun Jan 25 17:16:15 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 25 Jan 2009 23:16:15 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? try this v = json.loads('{"test":"test"}') JSON doesn't support single quotes, only double quotes. -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of converstion. Q: Why is top posting frowned upon? From mensanator at aol.com Sun Jan 25 17:18:15 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 25 Jan 2009 14:18:15 -0800 (PST) Subject: Cartesian Product of two lists (itertools) References: Message-ID: On Jan 25, 3:12?pm, Thorsten Kampe wrote: > Hi, > > is there a way to make itertools.product generate triples instead of > pairs from two lists? > > For example:>>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] > >>> from itertools import product > >>> list(product(list1, list2, list3)) > > [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, > 5, 7), (2, 5, 8)] > > so far so good... Now...>>> list(product(product(list1, list2), list3)) > > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] > > Oops, pairs of pairs instead triples. Not what I wanted. > > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! > > I have an older utility which I would like to replace with > itertools.product. The old one uses a rather clumsy way to indicate that > a triple was wanted: > > def cartes(seq0, seq1, modus = 'pair'): > ? ? """ return the Cartesian Product of two sequences """ > ? ? if ? modus == 'pair': > ? ? ? ? return [[item0, item1] for item0 in seq0 for item1 in seq1] > ? ? elif modus == 'triple': > ? ? ? ? return [item0 + [item1] for item0 in seq0 for item1 in seq1] > > Thorsten Will this work for you? >>> list4 = [(i,) for i in list3] >>> list4 [(7,), (8,)] >>> a = list(itertools.product(itertools.product(list1, list2), list4)) >>> a [((1, 4), (7,)), ((1, 4), (8,)), ((1, 5), (7,)), ((1, 5), (8,)), ((2, 4), (7,)), ((2, 4), (8,)), ((2, 5), (7,)), ((2, 5), (8,))] >>> def flatten(listOfLists): return tuple(itertools.chain.from_iterable(listOfLists)) >>> list5 = [flatten(i) for i in a] >>> list5 [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, 5, 7), (2, 5, 8)] >>> From Tribulations at Paralleles.invalid Sun Jan 25 17:25:09 2009 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 25 Jan 2009 23:25:09 +0100 Subject: super behavior Message-ID: <6f5v46-c1n.ln1@rama.fbx.proxad.net> Hi, Hereafter is an example using super. At the execution, we obtain: coucou init_coucou2 coucou1 coucou2 Traceback (most recent call last): File "essai_heritage.py", line 34, in print b.a AttributeError: 'coucou' object has no attribute 'a' Why Python does not enter in the __init__ method of coucou1? If I replace the two lines using "super" by the two following lines, it works perfectly: coucou1.__init__( self ) coucou2.__init__( self ) ########## class coucou1( object ): def __init__( self , a = 1 ): self.a = a print "init_coucou1" def print_coucou1( self ): print "coucou1" class coucou2( object ): def __init__( self , b = 2 ): self.b = b print "init_coucou2" def print_coucou2( self ): print "coucou2" class coucou( coucou1, coucou2 ): def __init__( self ): print "coucou" super( coucou1, self ).__init__( ) super( coucou2, self ).__init__( ) b = coucou() b.print_coucou1() b.print_coucou2() print b.a print b.b ################## -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From jbloodworth at sc.rr.com Sun Jan 25 17:27:00 2009 From: jbloodworth at sc.rr.com (Jay Bloodworth) Date: Sun, 25 Jan 2009 17:27:00 -0500 Subject: Where to put configuration/data files Message-ID: <1232922420.3118.118.camel@localhost.localdomain> Is there a nice cross-platform way to figure out the Right (tm) place to store configuration files and other data? Jay From gert.cuykens at gmail.com Sun Jan 25 17:28:48 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 14:28:48 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> Message-ID: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> On Jan 25, 11:16?pm, ?????? ??????????? wrote: > > raise ValueError(errmsg("Expecting property name", s, end)) > >http://docs.python.org/library/json.html > > What am I doing wrong ? > > try this > v = json.loads('{"test":"test"}') > > JSON doesn't support single quotes, only double quotes. the funny part is when you print(v) you get {'test': 'test'} Single quotes works in every browser that support json so i recommended python should support it too, besides it looks much cleaner {'test': 'test'} {"test": "test"} It can not be that hard to support both notation can it ? From martin at v.loewis.de Sun Jan 25 17:28:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 25 Jan 2009 23:28:55 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> Message-ID: <497CE7A7.3020809@v.loewis.de> > dtype = ord(rawdata[0]) > dcount = struct.unpack("!H",rawdata[1:3]) > if dtype == 1: > fmtstr = "!" + "H"*dcount > elif dtype == 2: > fmtstr = "!" + "f"*dcount > rlen = struct.calcsize(fmtstr) > > data = struct.unpack(fmtstr,rawdata[3:3+rlen]) > > leftover = rawdata[3+rlen:] Unfortunately, that does not work in the example. We have a message type (an integer), and a variable-length string. So how do you compute the struct format for that? >> Sure. You would normally have a struct such as >> >> struct TLV{ >> char type; >> char length; >> char *data; >> }; >> >> However, the in-memory representation of that struct is *not* >> meant to be sent over the wire. In particular, the character >> pointer has no meaning outside the address space, and is thus >> not to be sent. > > Well if it's not representing the layout of the data we're > trying to deal with, then it's irrelevent. We are talking > about how convert python objects to/from data in the > 'on-the-wire' format, right? Right: ON-THE-WIRE, not IN MEMORY. In memory, there is a pointer. On the wire, there are no pointers. > Like this? > >>>> def encode(type,length,value): > ... return chr(type)+chr(length)+value > ... >>>> print encode('float', 1, 3.14159) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in encode > TypeError: an integer is required No: py> CONNECT_REQUEST=17 py> payload="call me" py> encode(CONNECT_REQUEST, len(payload), payload) '\x11\x07call me' Regards, Martin From gagsl-py2 at yahoo.com.ar Sun Jan 25 17:49:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 20:49:00 -0200 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribi?: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> I am creating a class called people - subclasses men, women, children >> etc. >> I want to count the number of people at any time. >> So, I created code like the following: >> >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) >> >> def __del__(self): >> a.counter -= 1 >> >> class aa(a): >> pass >> > This looks OK, although I'd suggest using "cls.counter += 1" instead of > "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. This would create an asymmetry > with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" > there, even if it is a bit ugly-ish. Using self.__class__ is safer, from a technical point of view. When __del__ is executed at interpreter shutdown, "a" may not be available -- in general, __del__ methods should not rely on any globals (one can "inject" names into the local namespace using default arguments). See http://bugs.python.org/issue1717900 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Jan 25 17:49:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 20:49:00 -0200 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribi?: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> I am creating a class called people - subclasses men, women, children >> etc. >> I want to count the number of people at any time. >> So, I created code like the following: >> >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) >> >> def __del__(self): >> a.counter -= 1 >> >> class aa(a): >> pass >> > This looks OK, although I'd suggest using "cls.counter += 1" instead of > "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. This would create an asymmetry > with __del__() then. Oh well. So maybe use "self.__class__.counter -= 1" > there, even if it is a bit ugly-ish. Using self.__class__ is safer, from a technical point of view. When __del__ is executed at interpreter shutdown, "a" may not be available -- in general, __del__ methods should not rely on any globals (one can "inject" names into the local namespace using default arguments). See http://bugs.python.org/issue1717900 -- Gabriel Genellina From deets at nospam.web.de Sun Jan 25 17:51:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 25 Jan 2009 23:51:41 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <6u48ntFdcm9fU1@mid.uni-berlin.de> gert schrieb: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} So what? That's python deciding to print strings using single-quotes. That has nothing to do with JSON. The important part is this: >>> json.dumps(json.loads('{"test":"test"}')) '{"test": "test"}' > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not hard, but it's not standard-conform. Most browsers even accept something like this: {foo : "bar"} But all of this is not JSON. Diez From cliff at excite.com Sun Jan 25 17:56:42 2009 From: cliff at excite.com (Cliff MacGillivray) Date: Sun, 25 Jan 2009 17:56:42 -0500 Subject: syntax color lang source code in blogs or website In-Reply-To: References: Message-ID: Xah Lee wrote: > For those of you using emacs, here's the elisp code that allows you to > syntax color computer language source code in your blog or website. > > http://xahlee.org/emacs/elisp_htmlize.html > > to comment, here: > http://xahlee.blogspot.com/2009/01/dehtmlize-source-code-in-emacs-lisp.html Xah, Very nice! If nothing else you seem to be a pretty clever programmer. Indeed, you seem to understand more theoretical aspects than most simple minded software developers. I am not sure why you live out of your car? Has that situation changed at all? Are you working right now? From deets at nospam.web.de Sun Jan 25 18:04:52 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 00:04:52 +0100 Subject: super behavior In-Reply-To: <6f5v46-c1n.ln1@rama.fbx.proxad.net> References: <6f5v46-c1n.ln1@rama.fbx.proxad.net> Message-ID: <6u49gkFdie6vU1@mid.uni-berlin.de> TP schrieb: > Hi, > > Hereafter is an example using super. > At the execution, we obtain: > > coucou > init_coucou2 > coucou1 > coucou2 > Traceback (most recent call last): > File "essai_heritage.py", line 34, in > print b.a > AttributeError: 'coucou' object has no attribute 'a' > > Why Python does not enter in the __init__ method of coucou1? Because you use super wrong. It's not supposed to be called with a superclass, but with the current class. And each class needs to call super itself in it's own __init__-method. Like this: class coucou1( object ): def __init__( self , a = 1 ): self.a = a print "init_coucou1" super( coucou1, self ).__init__( ) def print_coucou1( self ): print "coucou1" class coucou2( object ): def __init__( self , b = 2 ): self.b = b print "init_coucou2" super( coucou2, self ).__init__( ) def print_coucou2( self ): print "coucou2" class coucou( coucou1, coucou2 ): def __init__( self ): print "coucou" super( coucou, self ).__init__( ) b = coucou() b.print_coucou1() b.print_coucou2() print b.a print b.b Diez From grante at visi.com Sun Jan 25 18:05:31 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 17:05:31 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> dtype = ord(rawdata[0]) >> dcount = struct.unpack("!H",rawdata[1:3]) >> if dtype == 1: >> fmtstr = "!" + "H"*dcount >> elif dtype == 2: >> fmtstr = "!" + "f"*dcount >> rlen = struct.calcsize(fmtstr) >> >> data = struct.unpack(fmtstr,rawdata[3:3+rlen]) >> >> leftover = rawdata[3+rlen:] > > Unfortunately, that does not work in the example. We have > a message type (an integer), and a variable-length string. > So how do you compute the struct format for that? I'm confused. Are you asking for an introductory tutorial on programming in Python? > Right: ON-THE-WIRE, not IN MEMORY. In memory, there is a > pointer. On the wire, there are no pointers. I don't understand your point. > py> CONNECT_REQUEST=17 > py> payload="call me" > py> encode(CONNECT_REQUEST, len(payload), payload) > '\x11\x07call me' If all your data is comprised of 8-bit bytes, then you don't need the struct module. -- Grant From gert.cuykens at gmail.com Sun Jan 25 18:08:04 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 15:08:04 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> On Jan 25, 11:51?pm, "Diez B. Roggisch" wrote: > gert schrieb: > > > On Jan 25, 11:16 pm, ?????? ??????????? wrote: > >>> raise ValueError(errmsg("Expecting property name", s, end)) > >>>http://docs.python.org/library/json.html > >>> What am I doing wrong ? > >> try this > >> v = json.loads('{"test":"test"}') > > >> JSON doesn't support single quotes, only double quotes. > > > the funny part is when you print(v) you get > > {'test': 'test'} > > So what? That's python deciding to print strings using single-quotes. > That has nothing to do with JSON. > > The important part is this: > > ?>>> json.dumps(json.loads('{"test":"test"}')) > '{"test": "test"}' > > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. Yes it is, you just make it more python dictionary compatible :) What is this json person email address so I can ask that he makes a very small update on his site. Besides if you can make lightweight versions of standards http://docs.python.org/library/xml.dom.minidom.html You can defenatly add lightweight quotes to json. From tim at burlyhost.com Sun Jan 25 18:19:21 2009 From: tim at burlyhost.com (Tim Greer) Date: Sun, 25 Jan 2009 15:19:21 -0800 Subject: syntax color lang source code in blogs or website References: Message-ID: Cliff MacGillivray wrote: > Xah Lee wrote: >> For those of you using emacs, here's the elisp code that allows you >> to syntax color computer language source code in your blog or >> website. >> >> http:/........ >> >> to comment, here: >> http://....... > Xah, > Very nice! > If nothing else you seem to be a pretty clever programmer. > Indeed, you seem to understand more theoretical aspects than > most simple minded software developers. > I am not sure why you live out of your car? > Has that situation changed at all? Are you working right now? Please don't encourage this guy. He posts to groups purely to try and tell everyone how smart he thinks he is (regardless of how wrong he usually is), and argues and uses vulgar language to anyone that asks him to stop posting in non relevent news groups. He seems to have selected the Python and Perl groups to regularly post to, even when his posts rarely to never have any relation to said groups. Please, do not encourage his behavior. Thanks. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From python.list at tim.thechases.com Sun Jan 25 18:34:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 17:34:18 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> Message-ID: <497CF6FA.3030000@tim.thechases.com> >> One other caveat here, "line" contains the newline at the end, so >> you might have >> >> print line.rstrip('\r\n') >> >> to remove them. > > I don't understand the presence of the '\r' there. Any '\x0d' that > remains after reading the file in text mode and is removed by that > rstrip would be a strange occurrence in the data which the OP may > prefer to find out about and deal with; it is not part of "the > newline". Why suppress one particular data character in preference to > others? In an ideal world where everybody knew how to make a proper text-file, it wouldn't be an issue. Recreating the form of some of the data I get from customers/providers: >>> f = file('tmp/x.txt', 'wb') >>> f.write('headers\n') # headers in Unix format >>> f.write('data1\r\n') # data in Dos format >>> f.write('data2\r\n') >>> f.write('data3') # no trailing newline of any sort >>> f.close() Then reading it back in: >>> for line in file('tmp/x.txt'): print repr(line) ... 'headers\n' 'data1\r\n' 'data2\r\n' 'data3' As for wanting to know about stray '\r' characters, I only want the data -- I don't particularly like to be reminded of the incompetence of those who send me malformed text-files ;-) > The same applies in any case to the use of rstrip('\n'); if that finds > more than one ocurrence of '\x0a' to remove, it has exceeded the > mandate of removing the newline (if any). I believe that using the formulaic "for line in file(FILENAME)" iteration guarantees that each "line" will have at most only one '\n' and it will be at the end (again, a malformed text-file with no terminal '\n' may cause it to be absent from the last line) > So, we are left with the unfortunately awkward > if line.endswith('\n'): > line = line[:-1] You're welcome to it, but I'll stick with my more DWIM solution of "get rid of anything that resembles an attempt at a CR/LF". Thank goodness I haven't found any of my data-sources using "\n\r" instead, which would require me to left-strip '\r' characters as well. Sigh. My kingdom for competency. :-/ -tkc From martin at v.loewis.de Sun Jan 25 18:36:51 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 00:36:51 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> Message-ID: <497CF793.8050501@v.loewis.de> >> Unfortunately, that does not work in the example. We have >> a message type (an integer), and a variable-length string. >> So how do you compute the struct format for that? > > I'm confused. Are you asking for an introductory tutorial on > programming in Python? Perhaps. I honestly do not know how to deal with variable-sized strings in the struct module in a reasonable way, and thus believe that this module is incapable of actually supporting them (unless you use inappropriate trickery). However, as you keep claiming that the struct module is what should be used, I must be missing something about the struct module. > I don't understand your point. > >> py> CONNECT_REQUEST=17 >> py> payload="call me" >> py> encode(CONNECT_REQUEST, len(payload), payload) >> '\x11\x07call me' > > If all your data is comprised of 8-bit bytes, then you don't > need the struct module. Go back to the original message of the OP. It says # I have following packet format which I have to send over Bluetooth. # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || # packet_data(variable) So yes, all his date is comprised of 8-bit bytes, and yes, he doesn't need the struct module. Hence I'm puzzled why people suggest that he uses the struct module. I think the key answer is "use the string type, it is appropriate to represent byte oriented data in python" (also see the subject of this thread) Regards, Martin From deets at nospam.web.de Sun Jan 25 18:40:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 00:40:09 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> Message-ID: <6u4biqFdhg0iU1@mid.uni-berlin.de> >> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) No, what you do is to make it more incompatible with other json-implementations. Which defies the meaning of a standard. Besides, {foo : "bar"} is *not* python dictionary compatible, at least not unless you defined foo beforehand, and then there is no guarantee that foo is actually as string containing 'foo'. > What is this json person email address so I can ask that he makes a > very small update on his site. Go try your luck - http://www.json.org/ > > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html minidom is a lightweight version of the DOM-API. But it reads and writes standard-conform XML documents. The same applies for element-tree and lxml. So it does not serve as a counter-example. > You can defenatly add lightweight quotes to json. If you bring all other implementors of all other languages to simultaneously do so - yes, you can. Again, good luck with that. Diez From grante at visi.com Sun Jan 25 18:48:59 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 17:48:59 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >>> Unfortunately, that does not work in the example. We have >>> a message type (an integer), and a variable-length string. >>> So how do you compute the struct format for that? >> >> I'm confused. Are you asking for an introductory tutorial on >> programming in Python? > > Perhaps. I honestly do not know how to deal with variable-sized > strings in the struct module in a reasonable way, and thus believe > that this module is incapable of actually supporting them > (unless you use inappropriate trickery). It deals with variable sized fields just fine: dtype = 18 dlength = 32 format = "!BB%ds" % dlength rawdata = struct.pack(format, (dtype,dlength,data)) > However, as you keep claiming that the struct module is what > should be used, I must be missing something about the struct > module. http://docs.python.org/library/struct.html >> I don't understand your point. >> >>> py> CONNECT_REQUEST=17 >>> py> payload="call me" >>> py> encode(CONNECT_REQUEST, len(payload), payload) >>> '\x11\x07call me' >> >> If all your data is comprised of 8-bit bytes, then you don't >> need the struct module. > > Go back to the original message of the OP. It says > > # I have following packet format which I have to send over Bluetooth. > # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > # packet_data(variable) > > So yes, all his date is comprised of 8-bit bytes, He doesn't specify what format the packet_data is, and we all assumed he needed to handle conversion of various data types to/from raw byte-strings. > and yes, he doesn't need the struct module. Hence I'm puzzled > why people suggest that he uses the struct module. We all assumed that "packet_data" might contain values of various types such as 16 or 32 bit integers, floating point values -- that packet_data was not solely arbitrary-length strings of 8-bit bytes. > I think the key answer is "use the string type, it is > appropriate to represent byte oriented data in python" (also > see the subject of this thread) I, for one, interpreted "byte-oriented" to mean that the data was received/sent as blocks of bytes but needed to be converted into other data types. If the data really is just strings of bytes, and it's sent as strings of bytes, then I have no idea what the OP was asking, since there's nothing that needs to be done with the data. -- Grant From martin at v.loewis.de Sun Jan 25 18:53:30 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 00:53:30 +0100 Subject: Byte oriented data types in python In-Reply-To: References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: <497CFB7A.2090901@v.loewis.de> > It deals with variable sized fields just fine: > > dtype = 18 > dlength = 32 > format = "!BB%ds" % dlength > > rawdata = struct.pack(format, (dtype,dlength,data)) I wouldn't call this "just fine", though - it involves a % operator to even compute the format string. IMO, it is *much* better not to use the struct module for this kind of problem, and instead rely on regular string concatenation. Regards, Martin From geekmail at usenot.de Sun Jan 25 18:54:31 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 00:54:31 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <20090126005431.063dafa9@usenot.de> On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" wrote: > gert schrieb: > > {'test': 'test'} > > {"test": "test"} > > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > OK, playing the devil's advocate here: Doesn't practicality beat purity? /W -- My real email address is constructed by swapping the domain with the recipient (local part). From gagsl-py2 at yahoo.com.ar Sun Jan 25 19:04:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 25 Jan 2009 22:04:40 -0200 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> Message-ID: En Sun, 25 Jan 2009 21:08:04 -0200, gert escribi?: > On Jan 25, 11:51?pm, "Diez B. Roggisch" wrote: >> gert schrieb: >> >> > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >> >>> raise ValueError(errmsg("Expecting property name", s, end)) >> >>>http://docs.python.org/library/json.html >> >>> What am I doing wrong ? >> >> try this >> >> v = json.loads('{"test":"test"}') >> >> >> JSON doesn't support single quotes, only double quotes. >> > It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> >> Most browsers even accept something like this: >> >> {foo : "bar"} >> >> But all of this is not JSON. > > Yes it is, you just make it more python dictionary compatible :) What do you mean? The above is not valid Python. JSON is whatever the author says it is. And he says "A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes". > What is this json person email address so I can ask that he makes a > very small update on his site. Try http://www.json.org/ -- good luck. > Besides if you can make lightweight versions of standards > http://docs.python.org/library/xml.dom.minidom.html This is not a lightweight version of XML, but a lightweight version of an API. minidom reads and writes the same valid XML documents. > You can defenatly add lightweight quotes to json. JSON is ligthweight *already*: "JSON (JavaScript Object Notation) is a lightweight data-interchange format." Introducing single quoted strings, apart from being incompatible with the previous version, would make parsing more complex. -- Gabriel Genellina From steve at holdenweb.com Sun Jan 25 19:04:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 25 Jan 2009 19:04:44 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <20090126005431.063dafa9@usenot.de> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: Andreas Waldenburger wrote: > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > wrote: > >> gert schrieb: >>> {'test': 'test'} >>> {"test": "test"} >>> >>> It can not be that hard to support both notation can it ? >> It's not hard, but it's not standard-conform. >> > OK, playing the devil's advocate here: Doesn't practicality beat purity? > It's not practical to expect a standard to be rewritten to conform with the ideas of one individual, as well as all the implementations of that standard. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From grante at visi.com Sun Jan 25 19:04:59 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 25 Jan 2009 18:04:59 -0600 Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> <497CFB7A.2090901@v.loewis.de> Message-ID: On 2009-01-25, Martin v. L?wis wrote: >> It deals with variable sized fields just fine: >> >> dtype = 18 >> dlength = 32 >> format = "!BB%ds" % dlength >> >> rawdata = struct.pack(format, (dtype,dlength,data)) > > I wouldn't call this "just fine", though - it involves > a % operator to even compute the format string. IMO, > it is *much* better not to use the struct module for this > kind of problem, and instead rely on regular string > concatenation. If all you need to do is concatenate strings, then you're correct, there's no advantage to using struct or ctypes. If you need a generic way to deal with arbitrary data types, then that's what the struct and ctypes modules are designed to do. The protocols I've implemented always required the ability to deal with integers greater than 8 bits wide as well as various other data types. -- Grant From gert.cuykens at gmail.com Sun Jan 25 19:05:59 2009 From: gert.cuykens at gmail.com (gert) Date: Sun, 25 Jan 2009 16:05:59 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> Message-ID: On Jan 26, 12:40?am, "Diez B. Roggisch" wrote: > >> But all of this is not JSON. > > > Yes it is, you just make it more python dictionary compatible :) > > No, what you do is to make it more incompatible with other > json-implementations. Which defies the meaning of a standard. > > Besides, {foo : "bar"} is *not* python dictionary compatible, at least > not unless you defined foo beforehand, and then there is no guarantee > that foo is actually as string containing 'foo'. > > > What is this json person email address so I can ask that he makes a > > very small update on his site. > > Go try your luck -http://www.json.org/ > > > Besides if you can make lightweight versions of standards > >http://docs.python.org/library/xml.dom.minidom.html > > minidom is a lightweight version of the DOM-API. But it reads and writes > standard-conform XML documents. > > The same applies for element-tree and lxml. > > So it does not serve as a counter-example. yes it does because adding ' does not mean replacing " so it will still load standard json. Like every browser does and is exactly the same philosofie as http://docs.python.org/library/xml.dom.minidom.html The xml.dom.minidom module is essentially a DOM 1.0-compatible DOM with some DOM 2 features (primarily namespace features). or unlink() is a xml.dom.minidom-specific extension to the DOM API. After calling unlink() on a node, the node and its descendants are essentially useless. From castironpi at gmail.com Sun Jan 25 19:06:43 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 25 Jan 2009 16:06:43 -0800 (PST) Subject: ob_type in shared memory Message-ID: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> Hello, I am writing an extension using shared memory. I need a data type that is able to reassign its 'ob_type' field depending on what process is calling it. Object 'A' is of type 'Ta'. When process 'P' is looking at it, it needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. When process 'Q' is looking at it, it needs to have an 'ob_type' that is 'Ta' as process 'Q' sees it. If it referred to 'Ta' in process 'P' when 'Q' was calling it, 'Q' would have to access memory that is in another process. Therefore, I need a field and an array. The field indicates which type should be loaded, and the array contains the types. Quick example: PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; Then, when a list is being accessed, it can set its own 'ob_type' field to 'array_of_types[ 0 ]', and similarly for a tuple. However, I'm having trouble getting 'array_of_types' in the right module during compilation. My question is: Where do 'array_of_types' and the forward declarations for the types go? My fallback is what 'pickle' does: store types as strings, then load them dynamically for 'ob_type'. That is, obtain a pointer to the type from the string. Thank you for reading! Any ideas? Thanks in advance. From fuzzyman at gmail.com Sun Jan 25 19:20:47 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Sun, 25 Jan 2009 16:20:47 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: On Jan 25, 2:28?pm, Alan G Isaac wrote: > On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > ?> It is documented: > ?>http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... > > But then again, the opposite is also documented, > since `range` is a sequence type. ?Quoting: > > ? ? ?Sequences also support slicing ... > > ? ? ?Some sequences also support ?extended slicing? > > Is this a documentation bug, or a bug in `range`? > (I'd think the latter.) > > Cheers, > Alan Isaac Where does the documentation say that range objects are sequences? They're iterables. Michael Foord -- http://www.ironpythoninaction.com/ From sjmachin at lexicon.net Sun Jan 25 19:44:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 11:44:33 +1100 Subject: Newby: how to transform text into lines of text In-Reply-To: <497CF6FA.3030000@tim.thechases.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: <497D0771.3020709@lexicon.net> On 26/01/2009 10:34 AM, Tim Chase wrote: > I believe that using the formulaic "for line in file(FILENAME)" > iteration guarantees that each "line" will have at most only one '\n' > and it will be at the end (again, a malformed text-file with no terminal > '\n' may cause it to be absent from the last line) It seems that you are right -- not that I can find such a guarantee written anywhere. I had armchair-philosophised that writing "foo\n\r\nbar\r\n" to a file in binary mode and reading it on Windows in text mode would be strict and report the first line as "foo\n\n"; I was wrong. > >> So, we are left with the unfortunately awkward >> if line.endswith('\n'): >> line = line[:-1] > > You're welcome to it, but I'll stick with my more DWIM solution of "get > rid of anything that resembles an attempt at a CR/LF". Thanks, but I don't want it. My point was that you didn't TTOPEWYM (tell the OP exactly what you meant). My approach to DWIM with data is, given norm_space = lambda s: u' '.join(s.split()) to break up the line into fields first (just in case the field delimiter == '\t') then apply norm_space to each field. This gets rid of your '\r' at end (or start!) of line, and multiple whitespace characters are replaced by a single space. Whitespace includes NBSP (U+00A0) as an added bonus for being righteous and using Unicode :-) > Thank goodness I haven't found any of my data-sources using "\n\r" > instead, which would require me to left-strip '\r' characters as well. > Sigh. My kingdom for competency. :-/ Indeed. I actually got data in that format once from a *x programmer who was so kind as to do it that way just for me because he knew that I use Windows and he thought that's what Windows text files looked like. No kidding. Cheers, John From python.list at tim.thechases.com Sun Jan 25 19:47:23 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 18:47:23 -0600 Subject: Efficient multi-slicing technique? In-Reply-To: <1232903397.3540.1296640123@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> Message-ID: <497D081B.3080309@tim.thechases.com> > Is there an efficient way to multi-slice a fixed with string > into individual fields that's logically equivalent to the way > one would slice a delimited string using .split()? Background: > I'm parsing some very large, fixed line-width text files that > have weekly columns of data (52 data columns plus related > data). My current strategy is to loop through a list of > slice()'s to build a list of the specific field values for > each line. This is fine for small files, but seems > inefficient. I'm hoping that there's a built-in (C based) I'm not sure if it's more efficient, but there's the struct module[1]: from struct import unpack for line in file('sample.txt'): (num, a, b, c, nl) = unpack("2s9s7s4sc", line) print "num:", repr(num) print "a:", repr(a) print "b:", repr(b) print "c:", repr(c) Adjust the formatting string for your data (the last "c" is the newline character -- you might be able to use "x" here to just ignore the byte so it doesn't get returned). The sample data I threw was 2/9/7/4 character data. The general pattern would be lengths = [3,18,24,5,1,8] FORMAT_STR = ( ''.join("%ss" % length for length in lengths) + 'c') for line in file(INFILE): (f1, f2,..., fn, _) = unpack(FORMAT_STR, line) -tkc [1] http://docs.python.org/library/struct.html From Scott.Daniels at Acm.Org Sun Jan 25 19:57:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 25 Jan 2009 16:57:27 -0800 Subject: Newby: how to transform text into lines of text In-Reply-To: References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: John Machin wrote: > On 26/01/2009 10:34 AM, Tim Chase wrote: > >> I believe that using the formulaic "for line in file(FILENAME)" >> iteration guarantees that each "line" will have at most only one '\n' >> and it will be at the end (again, a malformed text-file with no >> terminal '\n' may cause it to be absent from the last line) > > It seems that you are right -- not that I can find such a guarantee > written anywhere. I had armchair-philosophised that writing > "foo\n\r\nbar\r\n" to a file in binary mode and reading it on Windows in > text mode would be strict and report the first line as "foo\n\n"; I was > wrong. Here's how I'd do it: with open('deheap/deheap.py', 'rU') as source: for line in source: print line.rstrip() # Avoid trailing spaces as well. This should handle \n, \r\n, and \n\r lines. --Scott David Daniels Scott.Daniels at Acm.Org From geekmail at usenot.de Sun Jan 25 19:57:44 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 01:57:44 +0100 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: <20090126015744.2b306ba3@usenot.de> On Sun, 25 Jan 2009 19:04:44 -0500 Steve Holden wrote: > Andreas Waldenburger wrote: > > On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" > > wrote: > > > >> gert schrieb: > >>> {'test': 'test'} > >>> {"test": "test"} > >>> > >>> It can not be that hard to support both notation can it ? > >> It's not hard, but it's not standard-conform. > >> > > OK, playing the devil's advocate here: Doesn't practicality beat > > purity? > > > It's not practical to expect a standard to be rewritten to conform > with the ideas of one individual, as well as all the implementations > of that standard. > But as gert says, the standard is "broken" by many many browsers already (I don't know if that's true, though; I just assume it is). Why not make it compatible with, and as forgiving as, those? (I feel a bit stupid here, because I'm basically on the "adhere to the standard" side. I just noticed that the Zen (or what I make of it) seems to suggest otherwise.) regards, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 19:59:05 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 00:59:05 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> Message-ID: <018d0119$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:34:18 -0600, Tim Chase wrote: > Thank goodness I haven't found any of my data-sources using "\n\r" > instead, which would require me to left-strip '\r' characters as well. > Sigh. My kingdom for competency. :-/ If I recall correctly, one of the accounting systems I used eight years ago gave you the option of exporting text files with either \r\n or \n\r as the end-of-line mark. Neither \n nor \r (POSIX or classic Mac) line endings were supported, as that would have been useful. (It may have been Arrow Accounting, but don't quote me on that.) I can only imagine the developer couldn't remember which order the characters were supposed to go, so rather than look it up, he made it optional. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 19:59:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 00:59:48 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> Message-ID: <018d0144$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 12:01:16 -0800, Russ P. wrote: > On Jan 25, 10:04?am, Mark Wooding wrote: > >> > But what if I want an automatic check to verify that I am using it as >> > the author intended? Is that unreasonable? >> >> You mean that you can't /tell/ whether you typed mumble._seekrit? >> You're very strange. ?It's kind of hard to do by accident. > > But what if you type "mumble._seekrit" in several places, then the > library implementer decides to give in to your nagging and makes it > "public" by changing it to "mumble.seekrit". Now suppose you forget to > make the corresponding change somewhere in your code, such as > > mumble._seekrit = zzz > > You will get no warning at all. You will just be inadvertently creating > a new "private" attribute -- and the assignment that you really want > will not get done. > > For that matter, the library implementer himself could make the same > mistake and get no warning. > > When you think about it, you soon realize that the leading underscore > convention violates the spirit if not the letter of one of the first > principles of programming 101: if you have a constant parameter that > appears in several places, assign the literal value in one place rather > than repeating it everywhere. Then if you need to change the value, you > only need to change it in one place. That reduces effort, but more > importantly it reduces the potential for error. How is this scenario different from an API change where public_method() gets changed to method()? Surely this is just a downside to Python's lack of declarations, rather than specific to Python's lack of data hiding? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:07:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:07:12 GMT Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> Message-ID: <018d0300$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 19:04:44 -0500, Steve Holden wrote: > Andreas Waldenburger wrote: >> On Sun, 25 Jan 2009 23:51:41 +0100 "Diez B. Roggisch" >> wrote: >> >>> gert schrieb: >>>> {'test': 'test'} >>>> {"test": "test"} >>>> >>>> It can not be that hard to support both notation can it ? >>> It's not hard, but it's not standard-conform. >>> >> OK, playing the devil's advocate here: Doesn't practicality beat >> purity? >> > It's not practical to expect a standard to be rewritten to conform with > the ideas of one individual, as well as all the implementations of that > standard. Supposedly "every browser" (what, all of them?) already support a de facto extension to the JSON standard, allowing more flexible quoting. In an ideal world, yes the standard should change to conform to what "all browsers" do, since what they do is sensible. In my opinion, Python's handling of quotes simply is The Right Way To Do It. But more realistically, I think a more attainable solution will be for json.loads() to give a better error message than "Expecting property name" when you use the wrong quotes. -- Steven From tjreedy at udel.edu Sun Jan 25 20:08:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 20:08:15 -0500 Subject: Python 3: range objects cannot be sliced In-Reply-To: References: Message-ID: Fuzzyman wrote: > On Jan 25, 2:28 pm, Alan G Isaac wrote: >> On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: >> > It is documented: >> >http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... >> >> But then again, the opposite is also documented, >> since `range` is a sequence type. Quoting: >> >> Sequences also support slicing ... >> >> Some sequences also support ?extended slicing? >> >> Is this a documentation bug, or a bug in `range`? >> (I'd think the latter.) No range slicing is intended. > Where does the documentation say that range objects are sequences? > They're iterables. Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 doc still says "There are five sequence types: strings, byte sequences, byte arrays, lists, tuples, and range objects" (the miscount has already been reported.) I added a note to http://bugs.python.org/issue4966 suggesting that ranges be removed from the sequence section. I made several other suggestions for improving this sections. Supportive comments might help get action. tjr From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:11:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:11:51 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> Message-ID: <018d0417$0$20629$c3e8da3@news.astraweb.com> On Mon, 26 Jan 2009 00:59:48 +0000, Steven D'Aprano wrote: > How is this scenario different from an API change where public_method() > gets changed to method()? Sorry, that's a poor example, since you were talking about attributes rather than methods. Must stop posting before coffee *wink* Rewording: How is this scenario different from an API change where self.some_attribute gets changed to self.attribute? Surely this is just a downside to Python's lack of declarations, rather than specific to Python's lack of enforced data hiding? -- Steven From http Sun Jan 25 20:15:47 2009 From: http (Paul Rubin) Date: 25 Jan 2009 17:15:47 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7xbptuuat8.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How is this scenario different from an API change where > self.some_attribute gets changed to self.attribute? That would be a backward incompatible change to a published interface, something that should not be done without a good reason, and which was mostly avoided through the whole Python 2.x series (incompatible changes were saved for Python 3.0). Changing an undocumented and supposedly private interface is something different entirely. From tjreedy at udel.edu Sun Jan 25 20:20:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 20:20:05 -0500 Subject: Cartesian Product of two lists (itertools) In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > Hi, > > is there a way to make itertools.product generate triples instead of > pairs from two lists? > > For example: >>>> list1 = [1, 2]; list2 = [4, 5]; list3 = [7, 8] >>>> from itertools import product >>>> list(product(list1, list2, list3)) > [(1, 4, 7), (1, 4, 8), (1, 5, 7), (1, 5, 8), (2, 4, 7), (2, 4, 8), (2, > 5, 7), (2, 5, 8)] > > so far so good... Now... >>>> list(product(product(list1, list2), list3)) > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] > > Oops, pairs of pairs instead triples. Not what I wanted. > > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! > > I have an older utility which I would like to replace with > itertools.product. The old one uses a rather clumsy way to indicate that > a triple was wanted: A pair of function, cart_pair, cart_trip, would have been better. Or auto recognition of the number of sequences passed in. > def cartes(seq0, seq1, modus = 'pair'): > """ return the Cartesian Product of two sequences """ > if modus == 'pair': > return [[item0, item1] for item0 in seq0 for item1 in seq1] > elif modus == 'triple': > return [item0 + [item1] for item0 in seq0 for item1 in seq1] The second branch only produces a triple if seq0 is a sequence of pairs. This must be called with something like res = cartes(cartes(list1,list2),list3,'triple') Just replace that with your first only-once itertools call list(product(list1, list2, list3)) From rt8396 at gmail.com Sun Jan 25 20:23:03 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:23:03 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> Message-ID: On Jan 23, 10:02?pm, alex23 wrote: [snip] > How's that Python bridge to SketchUp coming > along? It's been months already, surely you've invested as much effort > into learning Python as you have in talking about it? Thanks for asking Alex23, The ball is rolling on the Python SketchUp integration as we speak, many people are very excited to start coding in Python. Would you care to join our pursuits alex? From rt8396 at gmail.com Sun Jan 25 20:27:41 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:27:41 -0800 (PST) Subject: What is intvar? References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> Message-ID: <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> W. eWatson, I contacted the author of New Mexico Techs "Introduction to Tkinter" a couple of weeks ago. He is going to update the reference material with a few missing widgets and some info on Photo and Bitmap classes. I really love the NMT layout and use it quite often. Fredricks Tkinterbook is more detail but lacking in navigation. I swing back and forth between both sites. From python.list at tim.thechases.com Sun Jan 25 20:30:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 19:30:33 -0600 Subject: Newby: how to transform text into lines of text In-Reply-To: References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: <497D1239.4070202@tim.thechases.com> Scott David Daniels wrote: > Here's how I'd do it: > with open('deheap/deheap.py', 'rU') as source: > for line in source: > print line.rstrip() # Avoid trailing spaces as well. > > This should handle \n, \r\n, and \n\r lines. Unfortunately, a raw rstrip() eats other whitespace that may be important. I frequently get tab-delimited files, using the following pseudo-code: def clean_line(line): return line.rstrip('\r\n').split('\t') f = file('customer_x.txt') headers = clean_line(f.next()) for line in f: field1, field2, field3 = clean_line(line) do_stuff() if field3 is empty in the source-file, using rstrip(None) as you suggest triggers errors on the tuple assignment because it eats the tab that defined it. I suppose if I were really smart, I'd dig a little deeper in the CSV module to sniff out the "right" way to parse tab-delimited files. -tkc From steve at REMOVE-THIS-cybersource.com.au Sun Jan 25 20:31:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jan 2009 01:31:18 GMT Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> Message-ID: <018d08a6$0$20629$c3e8da3@news.astraweb.com> On Sun, 25 Jan 2009 17:15:47 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> How is this scenario different from an API change where >> self.some_attribute gets changed to self.attribute? > > That would be a backward incompatible change to a published interface, > something that should not be done without a good reason, and which was > mostly avoided through the whole Python 2.x series (incompatible changes > were saved for Python 3.0). Changing an undocumented and supposedly > private interface is something different entirely. We're not talking specifically about Python standard library changes, we're talking about any project which may have more entertaining *cough* policies regarding API changes. Or if you prefer... some projects take the philosophy that the API isn't fixed until version 1.0, and so they can change anything until then. It seems to me that Russ' latest objection to _private names is not specific to _private names. The same problem: "You will get no warning at all. You will just be inadvertently creating a new "private" attribute -- and the assignment that you really want will not get done." occurs with public names as well. However, I do see his point that if we take the presence of a leading underscore in the name as semantically significant, then we're recording that information *everywhere* instead of in one place. That is a lesser version of Hungarian notation -- not as bad as redundantly storing type information that the compiler already knows, but still not ideal. -- Steven From http Sun Jan 25 20:37:41 2009 From: http (Paul Rubin) Date: 25 Jan 2009 17:37:41 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <7x3af63l0a.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > We're not talking specifically about Python standard library changes, > we're talking about any project which may have more entertaining *cough* > policies regarding API changes. Oh, yes, I see what you mean. That's a problem even in small projects, sometimes even in 1-person projects. From googler.1.webmaster at spamgourmet.com Sun Jan 25 20:46:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Sun, 25 Jan 2009 17:46:01 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) Message-ID: Hi! I have a problm with deallocating stuff. I call a function with this command: PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); if(rvalue==NULL) PyErr_Print(); else Py_DECREF(rvalue); Can it be, that something is missing here? Imagine I allocate an object of a type: t = MyImage() ,;- syntax_error 129=)/% #is a syntax error How you see I would get a syntaxerror, but an object of the type MyImage() is created. But its deallocated when Py_Finalize() is called. What can I do to deallocate this object after PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL the object is deallocated, but what can I do if rvalue==NULL= Thanks a lot!!!! From rt8396 at gmail.com Sun Jan 25 20:48:36 2009 From: rt8396 at gmail.com (r) Date: Sun, 25 Jan 2009 17:48:36 -0800 (PST) Subject: Why this code is working? References: <40adbf2f-90aa-4bd7-b5e7-ba4749c76392@g3g2000pre.googlegroups.com> <496db69d$0$20355$426a34cc@news.free.fr> <70d13126-3d64-48e9-9751-fa0d7f035bf4@l37g2000vba.googlegroups.com> <017dcf56$0$8693$c3e8da3@news.astraweb.com> <8fa1cf4e-242f-42cd-a111-8847a89dc83c@m12g2000vbp.googlegroups.com> <26a32fb6-90db-4add-b726-4580688ad749@r37g2000prr.googlegroups.com> Message-ID: <0d6e65a0-33b0-4ef6-823c-0dc5b0c80bc2@l33g2000pri.googlegroups.com> Actually Alex, i have not stopped working on getting Python into SU in one form or another since that crazy post of mine almost 3 moths ago. I have many people in the SU community asking me almost daily when i will get finished. I have a lot of work to do at this point but i will keep fighting because i believe Python will greatly benefit all SU users. 1.) Python has tons and tons of well written tutorials aimed at Non- programmers. 2.) Python is easy to learn making it the perfect choice for any API 3.) Python has an easy to use built-in GUI (Tkinter) 4.) Python allows for true procedural and true OOP programming. OOP can sometimes trip up a new programming student. I feel it is much easier to learn procedural coding and then move into OOP. OOP is not really hard to comprehend, but learning to program and at the same time dealing with the abstraction of OOP is a little much to take on. And since an API will be utilized mostly by non- programmers/intermediant as well as pros, Python lends itself as the best option available today for all skill levels! Once i finally get Python interpretor into SU, i plan to write a tutorial (free of course) specific aimed at SU users who want to script. Not only will this cover Python Programming but will completely cover the Python SU-API. SU is exploding daily, group membership is @ 14000+ and spam is almost nonexistent. This application is truly revolutionary and we must get Python in before it is too late. I have talked with a members of the SU DEV team and he would love to see Python scripting in SU. He also told me they have kicked around the idea of other languages in the past, so Python would be a prime choice. SU is changing the world of modeling the way Python changed the world of programming.I hang out quite a bit in the Google SketchUp Help Groups guiding new users. During this time i have seen many people stuggle with scripting the application. This is where i truly believe Python can fill a void and shine. The combination of Sketchup's intuitive and ground-breaking UI, coupled with the common sense approach and simplistic elegance of Python will be an unstoppable force. Not only will this expand Python and Sketchup's influence, but will give a SketchUp user the complete power they need over the application -- in the quickest, and most painless way. ... From mdw at distorted.org.uk Sun Jan 25 20:49:08 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 01:49:08 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> Message-ID: <87vds26dm3.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > On Jan 25, 10:04?am, Mark Wooding wrote: > > But what if you type "mumble._seekrit" in several places, then the > library implementer decides to give in to your nagging and makes it > "public" by changing it to "mumble.seekrit". There's a possibly better fix: introduce a property `seekrit' (or perhaps a better name!) which diddles the _seekrit attribute under the covers. > Now suppose you forget to make the corresponding change somewhere in > your code, such as > > mumble._seekrit = zzz > > You will get no warning at all. You will just be inadvertently > creating a new "private" attribute -- and the assignment that you > really want will not get done. True. That's a shame. It'd be nice if there were a way to fix that. There's this __slots__ thing I keep hearing about... > For that matter, the library implementer himself could make the same > mistake and get no warning. He could do. Why he didn't do a search and replace like any sensible person is a mystery. Testing is good, too. > When you think about it, you soon realize that the leading underscore > convention violates the spirit if not the letter of one of the first > principles of programming 101: if you have a constant parameter that > appears in several places, assign the literal value in one place > rather than repeating it everywhere. You mean `once and only once'. Yeah, I like that one too. > Then if you need to change the value, you only need to change it in > one place. That reduces effort, but more importantly it reduces the > potential for error. The same principle applies to "declaring" an > attribute private. Introducing a property hides the problem, but doesn't actually solve it, because you're right on this. Fortunately the problem doesn't actually come up that often. But yes, basically, I agree with you on this particular point: it's easier to add an alias than to rename, which avoids the problem but is error prone. -- [mdw] From apt.shansen at gmail.com Sun Jan 25 20:52:22 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 25 Jan 2009 17:52:22 -0800 Subject: Byte oriented data types in python In-Reply-To: <497CF793.8050501@v.loewis.de> References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> Message-ID: <7a9c25c20901251752g5ac62bb1n7fcaaad8e858aedd@mail.gmail.com> > > However, as you keep claiming that the struct module is what > should be used, I must be missing something about the struct > module. You seem to be focusing overly on the "C Struct" part of the description of what the struct module does, instead of the part where it says, "packed binary data" and "This can be used in handling binary data stored in files or from network connections" The struct module is very useful when generating or interpreting a stream of binary data which has a set structured format, in bytes and with set kinds of data types. > > # I have following packet format which I have to send over Bluetooth. > # packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > # packet_data(variable) > > So yes, all his date is comprised of 8-bit bytes, and yes, he doesn't > need the struct module. Hence I'm puzzled why people suggest that > he uses the struct module. > > I think the key answer is "use the string type, it is appropriate > to represent byte oriented data in python" (also see the subject > of this thread) > Everyone *is* saying to use the string type: the struct module doesn't produce structs.. it produces strings. The question is how to convert from Python types to byte-representations of said types in a string: you are saying (for example) that for shorts someone should use chr(1) etc. What if he needs to then send a two byte int from a Python int? Just because he said his message was about a fairly simple requirement at the moment, it doesn't mean that's the end of his problem. Everyone else seems to have assumed that it'll advance as he supports more of this protocol: that is apt to take on more specific struct format messages based on . So you might have a connection request format that's pre-defined -- your example above -- or another which needs to pass say, a 2 byte int instead. The struct module easily accomplishes this: all together in one place. Instead of having to figure out how to calculate the 2 byte storage of an int down the road, or a 4 byte integer, etc. Not to mention endianness. If the OP never ever has to do anything but the one specific problem he's having right now (and this isn't just an example he's making) with really really simple data: two byte-ints and then some characters, then sure using chr() and string concatenation is probably fine. But struct works -perfectly- fine for variable data and as he extends his support for the protocol, is quite likely to be very useful to him: that's why we're suggesting it. IMHO. I'd rather spend some trival time using string concatination (or the % operator) generating format strings for struct then have to write code for "int_to_2byte_int" and "int_to_4byte_int" and "change_to_bigendian" for when chr() doesn't satisfy the conversation needs enough. Yeah, strings are exactly how he can and should store the byte oriented data in Python 2.x. Using concatination and slicing + conversion to read and parse a byte stream coming off a line protocol... if you want to. But there's tools that are there that make it all alot easier too. The struct module for example. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Sun Jan 25 20:57:39 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 01:57:39 +0000 Subject: Cartesian Product of two lists (itertools) References: Message-ID: <87r62q6d7w.fsf.mdw@metalzone.distorted.org.uk> Thorsten Kampe writes: > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] [...] > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! Python has powerful destructuring capabilities: [(x, y, z) for ((x, y), z) in lopsided_list] This seems simpler and is probably faster than a generalized flatten for this size of problem, but I wouldn't use it to rearrange tuples with more than four or five elements. -- [mdw] From gagsl-py2 at yahoo.com.ar Sun Jan 25 21:03:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 00:03:54 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> Message-ID: En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase escribi?: > Unfortunately, a raw rstrip() eats other whitespace that may be > important. I frequently get tab-delimited files, using the following > pseudo-code: > > def clean_line(line): > return line.rstrip('\r\n').split('\t') > > f = file('customer_x.txt') > headers = clean_line(f.next()) > for line in f: > field1, field2, field3 = clean_line(line) > do_stuff() > > if field3 is empty in the source-file, using rstrip(None) as you suggest > triggers errors on the tuple assignment because it eats the tab that > defined it. > > I suppose if I were really smart, I'd dig a little deeper in the CSV > module to sniff out the "right" way to parse tab-delimited files. It's so easy that don't doing that is just inexcusable lazyness :) Your own example, written using the csv module: import csv f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') headers = f.next() for line in f: field1, field2, field3 = line do_stuff() -- Gabriel Genellina From zzbbaadd at aol.com Sun Jan 25 21:04:59 2009 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Sun, 25 Jan 2009 18:04:59 -0800 (PST) Subject: A java hobbyist programmer learning python References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: > ? ? ? ? If you're building an extension tree, you'll either have to supply > layers of getter/setter methods, or hand-mangle references to attributes > defined in the superclass. > > ? ? ? ? Say you start with a "Point2D" class, and make the X, Y coordinates > double underscore. > > ? ? ? ? Now extend it to a "Point3D" class via inheritance. The 3D class > will not be able to access (set) the X, Y values without a setter method > defined in the parent OR by unmangling the parent names. > > ? ? ? ? If you'd used the common convention of single underscore as "don't > touch if you're an outsider", the 3D extension can be considered an > insider and directly access the X, Y > > ? ? ? ? Which would you rather read in a 3D point class derived by extending > a 2D point? > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? self._z += zmod > ? ? ? ? ? ? ? ? self._y += ymod > ? ? ? ? ? ? ? ? self._x += xmod > > or > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? super(Point3D, self).move(xmod, ymod) > ? ? ? ? ? ? ? ? self._z += zmod > > or > > ? ? ? ? def move(self, xmod, ymod, zmod): > ? ? ? ? ? ? ? ? self._Point2D__x += xmod > ? ? ? ? ? ? ? ? self._Point2D__y += ymod > ? ? ? ? ? ? ? ? self.__z += zmod > > ? ? ? ? Speaking for myself, I'd prefer the first > -- > ? ? ? ? Wulfraed ? ? ? ?Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ? ? wulfr... at bestiaria.com > ? ? ? ? ? ? ? ? HTTP://wlfraed.home.netcom.com/ > ? ? ? ? (Bestiaria Support Staff: ? ? ? ? ? ? ? web-a... at bestiaria.com) > ? ? ? ? ? ? ? ? HTTP://www.bestiaria.com/ I like the latter two styles, particularly the last one. That way you can see at a glance that those member variables are defined in the super class. But then I am a fan of Hungarian notation, which many programmers can't stand. From python at bdurham.com Sun Jan 25 21:16:26 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 25 Jan 2009 21:16:26 -0500 Subject: Efficient multi-slicing technique? In-Reply-To: <497D081B.3080309@tim.thechases.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> <497D081B.3080309@tim.thechases.com> Message-ID: <1232936186.1062.1296697403@webmail.messagingengine.com> Tim, > I'm not sure if it's more efficient, but there's the struct module: > http://docs.python.org/library/struct.html Thanks for your suggestion. I've been experimenting with this technique, but my initial tests don't show any performance improvements over using slice() objects to slice a string. However, I missed the nuance of using 'x' to mark filler bytes - I'm going to see if this makes a difference (it may as I am skipping over several columns of input that I've been currently returning as ignored values) wait ... it looks like I can 'compile' struct strings using by using a Struct class vs. the using the module's basic unpack() function. This sounds like the difference between using compiled regular expressions vs. re-compiling a regular expression on every use. I'll see if this makes a difference and report back to the list. Regards, Malcolm From mnordhoff at mattnordhoff.com Sun Jan 25 21:17:58 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Mon, 26 Jan 2009 02:17:58 +0000 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <497D1D56.8050407@mattnordhoff.com> gert wrote: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>> raise ValueError(errmsg("Expecting property name", s, end)) >>> http://docs.python.org/library/json.html >>> What am I doing wrong ? >> try this >> v = json.loads('{"test":"test"}') >> >> JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? There's a difference between JavaScript source code and JSON. AFAICT from the source [1], Mozilla's JSON parser doesn't accept single quotes. [1] -- From sjmachin at lexicon.net Sun Jan 25 21:23:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 18:23:30 -0800 (PST) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> Message-ID: <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> On Jan 26, 1:03?pm, "Gabriel Genellina" wrote: > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase ? > escribi?: > > > > > Unfortunately, a raw rstrip() eats other whitespace that may be ? > > important. ?I frequently get tab-delimited files, using the following ? > > pseudo-code: > > > ? ?def clean_line(line): > > ? ? ?return line.rstrip('\r\n').split('\t') > > > ? ?f = file('customer_x.txt') > > ? ?headers = clean_line(f.next()) > > ? ?for line in f: > > ? ? ?field1, field2, field3 = clean_line(line) > > ? ? ?do_stuff() > > > if field3 is empty in the source-file, using rstrip(None) as you suggest ? > > triggers errors on the tuple assignment because it eats the tab that ? > > defined it. > > > I suppose if I were really smart, I'd dig a little deeper in the CSV ? > > module to sniff out the "right" way to parse tab-delimited files. > > It's so easy that don't doing that is just inexcusable lazyness :) > Your own example, written using the csv module: > > import csv > > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') > headers = f.next() > for line in f: > ? ? ?field1, field2, field3 = line > ? ? ?do_stuff() > And where in all of that do you recommend that .decode(some_encoding) be inserted? From gagsl-py2 at yahoo.com.ar Sun Jan 25 21:25:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 00:25:46 -0200 Subject: Python C API (PyObject_CallMethod clear object) References: Message-ID: En Sun, 25 Jan 2009 23:46:01 -0200, escribi?: > I have a problm with deallocating stuff. I call a function with this > command: > > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); > > if(rvalue==NULL) > PyErr_Print(); > else > Py_DECREF(rvalue); > > Can it be, that something is missing here? Imagine I allocate an > object of a type: > > t = MyImage() > ,;- syntax_error 129=)/% #is a syntax error > > How you see I would get a syntaxerror, but an object of the type > MyImage() is created. But its deallocated when Py_Finalize() is > called. What can I do to deallocate this object after > PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL > the object is deallocated, but what can I do if rvalue==NULL= A syntax error is detected *before* the code runs -- so the object isn't created at all. -- Gabriel Genellina From mdw at distorted.org.uk Sun Jan 25 21:37:37 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 02:37:37 +0000 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> Message-ID: <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Andreas Waldenburger writes: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) Hmm. Exceptions raised during object creation make this rather precarious. In your code, if object.__new__ raises an exception, the counter will end up too high (the __del__ method won't get called in this case). One might try to rewrite it: def __new__(cls, *args, **kw): thing = object.__new__(cls, *args, **kw) a.counter += 1 return thing Now this won't work in subclasses if they also have a __new__ method: again, if the subclass's __new__ raises an exception then __del__ won't be called and the counter will be too high. To make this technique work, I think you need to do the counter increment in __init__ rather than __new__, and to set an attribute so that __del__ knows whether to do the decrement. (If a subclass's __init__ raises an exception before yours gets called, you don't want to do the decrement because that'll leave the counter too low.) > This looks OK, although I'd suggest using "cls.counter += 1" instead > of "a.counter += 1" in the __new__() method. Just seems clearer to me, > esp. when you think about subclassing. I'm not sure about clarity, but that would be semantically different. The code as written counts all instances of a and its subclasses. Your suggestion would count instances of subclasses independently. I don't know which behaviour the OP would prefer, but I don't think choosing between them is a matter of clarity. > Another way to go would be to use the weakref module and create a > weakref-set (or list) as the counter. That way you would only need to > add the objects in the __new__() method and not worry about removing > them. I will admit that this is overengineering the problem a bit, but > might be a good exercise. This is a better approach, because it avoids the problems with exceptions during object construction that I described above. >> Another question - unrelated to the major topic: >> How much time does it take to be proficient in Python? > Don't concern yourself with that question at all, is my advice. Indeed. Besides, it varies an awful lot. I can't tell you from my personal experience, because I tend to learn programming languages by osmosis. I sit and read language manuals and newsgroups out of curiosity, because I find programming languages intrinsically interesting. One day, maybe a few years later, I start writing programs in some language. I'm usually up to half-decent language-lawyer standards within a few days of this point -- but I've had a /lot/ of practice at this game. My approach is almost certainly extremely atypical. But one of the best things about Python is the library. It's very big and wide-ranging, but not overcomplex, and I'm still discovering cool stuff, even though it's been there for years. And the advice to keep the Library Reference under your pillow is excellent. Expect to be flipping through it constantly. >> - or am I just dumb? > You're writing programs and you're communicating with like-minded > people about your problems (in a socially appropriate way). Not what > dumb people do, in my book. Absolutely! Besides, you're asking sensible questions about subtle parts of the language -- I wouldn't say that __new__ was beginner territory, for example. So, no, you certainly don't seem dumb to me. -- [mdw] From mnordhoff at mattnordhoff.com Sun Jan 25 21:38:48 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Mon, 26 Jan 2009 02:38:48 +0000 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <497D1D56.8050407@mattnordhoff.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <497D1D56.8050407@mattnordhoff.com> Message-ID: <497D2238.3020203@mattnordhoff.com> Matt Nordhoff wrote: > gert wrote: >> On Jan 25, 11:16 pm, ?????? ??????????? wrote: >>>> raise ValueError(errmsg("Expecting property name", s, end)) >>>> http://docs.python.org/library/json.html >>>> What am I doing wrong ? >>> try this >>> v = json.loads('{"test":"test"}') >>> >>> JSON doesn't support single quotes, only double quotes. >> the funny part is when you print(v) you get >> {'test': 'test'} >> >> Single quotes works in every browser that support json so i >> recommended python should support it too, besides it looks much >> cleaner >> {'test': 'test'} >> {"test": "test"} >> >> It can not be that hard to support both notation can it ? > > There's a difference between JavaScript source code and JSON. AFAICT > from the source [1], Mozilla's JSON parser doesn't accept single quotes. > > [1] By the way, I forgot to add, according to the ECMA-262 standard (page 18, section 7.8.4) [1], ECMAScript string literals can use either double or single quotes, so that's not a browser-specific extension. [1] () -- From Russ.Paielli at gmail.com Sun Jan 25 21:39:26 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 18:39:26 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> Message-ID: <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> On Jan 25, 5:31?pm, Steven D'Aprano wrote: > It seems to me that Russ' latest objection to _private names is not > specific to _private names. The same problem: > > "You will get no warning at all. You will just be inadvertently > creating a new "private" attribute -- and the assignment that you > really want will not get done." > > occurs with public names as well. That is true. Any name change could cause that sort of problem. But I brought it up specifically in reply to Mr. Wooding, who pointed out that it is hard to "accidentally" type a name with a leading underscore without realizing what you are doing. You may fully understand what you are doing when you type it, but you may not realize what has happened later when you forget to change it to be consistent with the new version of the library (or another module in an application). To change an attribute from private to public, the leading-underscore convention requires that every occurrence of the name be changed. That is more error prone than if the change only needs to be done in one place. And the fact that Python allows you to create new attributes on the fly also contributes to this problem, of course. That makes renaming and refactoring riskier in general in Python than in statically typed languages with enforced access restrictions. More care and attention to detail is needed to do it right in Python. From python.list at tim.thechases.com Sun Jan 25 21:40:05 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Jan 2009 20:40:05 -0600 Subject: Efficient multi-slicing technique? In-Reply-To: <1232936186.1062.1296697403@webmail.messagingengine.com> References: <1232903397.3540.1296640123@webmail.messagingengine.com> <497D081B.3080309@tim.thechases.com> <1232936186.1062.1296697403@webmail.messagingengine.com> Message-ID: <497D2285.1010102@tim.thechases.com> >> I'm not sure if it's more efficient, but there's the struct >> module: http://docs.python.org/library/struct.html > > Thanks for your suggestion. I've been experimenting with this > technique, but my initial tests don't show any performance > improvements over using slice() objects to slice a string. > However, I missed the nuance of using 'x' to mark filler bytes > - I'm going to see if this makes a difference (it may as I am > skipping over several columns of input that I've been > currently returning as ignored values) I don't expect it will make a great deal of difference -- there's not much room to improve the process. Are you actually experiencing efficiency problems? I regularly use slice unpacking (without reaching for the struct module) with no noteworthy performance impact beyond the cost of scanning the file and doing the processing on those lines (and these are text files several hundred megs in size). When I omit my processing code and just skim through the file, the difference between slice-unpacking and not slice-unpacking is in the sub-second range. > wait ... it looks like I can > 'compile' struct strings using by using a Struct class vs. the > using the module's basic unpack() function. This sounds like > the difference between using compiled regular expressions vs. > re-compiling a regular expression on every use. I'll see if > this makes a difference and report back to the list. I don't expect it will...in the code for the struct.py I've got here in my 2.5 distribution, it maintains an internal cache of compiled strings, so unless you have more than _MAXCACHE=100 formatting strings, it's not something you're really have to worry about. (in my main data-processing/ETL app, I can't envision having more than about 20 formatting strings, if I went that route) -tkc From philip at semanchuk.com Sun Jan 25 21:55:29 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 25 Jan 2009 21:55:29 -0500 Subject: Why is it faster the second time ? In-Reply-To: References: Message-ID: <690C5046-E027-451A-87DD-17DE07D25616@semanchuk.com> On Jan 23, 2009, at 12:46 PM, jalanb3 wrote: > Hello the group, > > I am wondering why doctests run slower the first time. > In the transcript below "try" is a script which finds and runs > doctests in the current directory. It also shows how long it takes to > run these tests. > > I added a new test which searches recursively for files given a path, > and it took (approx) 3 seconds to run. But all subsequent runs take > less than half a second. > > Am I right in thinking that the extra time on the first run is the > time it takes to compile .py -> .pyc ? Lots of things could be involved. For instance, your OS probably memory cached all of the files involved during the first run, so all subsequent runs needed no disk I/O. From sjmachin at lexicon.net Sun Jan 25 22:23:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 19:23:20 -0800 (PST) Subject: Python 3: range objects cannot be sliced References: Message-ID: <11034f30-d77c-4a77-afef-5460e4d0df2b@n33g2000pri.googlegroups.com> On Jan 26, 12:08?pm, Terry Reedy wrote: > Fuzzyman wrote: > > On Jan 25, 2:28 pm, Alan G Isaac wrote: > >> On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: > >> ?> It is documented: > >> ?>http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... > > >> But then again, the opposite is also documented, > >> since `range` is a sequence type. ?Quoting: > > >> ? ? ?Sequences also support slicing ... > > >> ? ? ?Some sequences also support ?extended slicing? > > >> Is this a documentation bug, or a bug in `range`? > >> (I'd think the latter.) > > No range slicing is intended. > > > Where does the documentation say that range objects are sequences? > > They're iterables. > > Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 > doc still says "There are five sequence types: strings, byte sequences, > byte arrays, lists, tuples, and range objects" (the miscount has already > been reported.) > > I added a note to > ? ?http://bugs.python.org/issue4966 > suggesting that ranges be removed from the sequence section. > I made several other suggestions for improving this sections. > > Supportive comments might help get action. I agree the docs need to be fixed; it's not very sequency at all. Other comments: * This error message should not use the s-word, but this may be unavoidable: >>> range(10)[1:3] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' * It would be good if the docs said more about what it is meant to be used for, apart from the obvious "for item in a_range". You can subscript a range, not that it's very useful: >>> range(10)[7] 7 It has neither next() nor __next__() method, and appears to be reusable (which is good, IMO): >>> x = range(10) >>> x.next() Traceback (most recent call last): File "", line 1, in AttributeError: 'range' object has no attribute 'next' >>> x.__next__() Traceback (most recent call last): File "", line 1, in AttributeError: 'range' object has no attribute '__next__' >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> It is immutable, and thus can be hashed ... use case? Cheers, John From mdw at distorted.org.uk Sun Jan 25 22:47:27 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 03:47:27 +0000 Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> Message-ID: <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Aaron Brady writes: > I am writing an extension using shared memory. I need a data type > that is able to reassign its 'ob_type' field depending on what process > is calling it. That sounds scary! > Object 'A' is of type 'Ta'. When process 'P' is looking at it, it > needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. When > process 'Q' is looking at it, it needs to have an 'ob_type' that is > 'Ta' as process 'Q' sees it. If it referred to 'Ta' in process 'P' > when 'Q' was calling it, 'Q' would have to access memory that is in > another process. I see. My immediate reaction was to suggest that you just put the PyTypeObject in shared memory -- but then I realised that the shared memory region will probably be in different addresses in the two processes. I'll assume that you've got enough synchronization between the processes involved to stop everything from turning to mush. > Therefore, I need a field and an array. The field indicates which > type should be loaded, and the array contains the types. Quick > example: > > PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; > > Then, when a list is being accessed, it can set its own 'ob_type' > field to 'array_of_types[ 0 ]', and similarly for a tuple. > > However, I'm having trouble getting 'array_of_types' in the right > module during compilation. My question is: Where do 'array_of_types' > and the forward declarations for the types go? I'm not sure I understand the difficulty. They'll want to go in your C module somewhere, but as long as SharedList and SharedTuple are either in the same source file or not declared `static' you just write the definition you've got somewhere after declaring or defining the actual types in question. There's a comment in Extending and Embedding (2.1) about initializing PyTypeObjects: : PyObject_HEAD_INIT(NULL) : : This line is a bit of a wart; what we'd like to write is: : : PyObject_HEAD_INIT(&PyType_Type) : : as the type of a type object is "type", but this isn't strictly : conforming C and some compilers complain. The comment here is wrong: &PyType_Type is a perfectly good constant expression as far as C is concerned, but alas Microsoft's dynamic linking system isn't clever enough to cope with it even so (because it's in a separate link unit). But this isn't a problem in our case: presumably SharedList and SharedTuple are in the same module, so this should all just work. -- [mdw] From gagsl-py2 at yahoo.com.ar Sun Jan 25 22:49:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 01:49:25 -0200 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: En Sun, 25 Jan 2009 04:55:47 -0200, Torsten Mohr escribi?: > i try to write a plugin system that i want to use to let users extend > a module that i write. > > Within the module there is an extension loader that loads an extension > module. This extension module should be able to import modules from > my system, which provides some extensions. > > Basically, this here works but gives a warning: > RuntimeWarning: Parent module 'ext_abc' not found while handling > absolute import > here = os.path.abspath('.') (Unrelated to the main question, but you probably want to use os.path.dirname(os.path.abspath(__file__)) instead - the above just returns the current directory, which might not be the directory containing the module) > mpath = os.path.abspath('mymodule') > epath = os.path.abspath('extension') > > sys.path.append(here) > sys.path.append(mpath) > > FILE mymodule/__init__.py: So mymodule is actually a package. Packages should *not* appear in sys.path. -- Gabriel Genellina From sjmachin at lexicon.net Sun Jan 25 22:54:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 25 Jan 2009 19:54:44 -0800 (PST) Subject: Byte oriented data types in python References: <84537255-c7ac-4c90-b24a-c75d3fe61b68@r37g2000prr.googlegroups.com> <081f4c86-b82f-4468-9f0b-241cec5594e8@40g2000prx.googlegroups.com> <497cc386$0$7144$9b622d9e@news.freenet.de> <497ccaa1$0$21633$9b622d9e@news.freenet.de> <497CE7A7.3020809@v.loewis.de> <497CF793.8050501@v.loewis.de> <497CFB7A.2090901@v.loewis.de> Message-ID: <698355ee-8148-4b87-8c92-c87bc9345c41@s1g2000prg.googlegroups.com> On Jan 26, 10:53?am, "Martin v. L?wis" wrote: > > It deals with variable sized fields just fine: > > > dtype = 18 > > dlength = 32 > > format = "!BB%ds" % dlength > > > rawdata = struct.pack(format, (dtype,dlength,data)) > > I wouldn't call this "just fine", though - it involves > a % operator to even compute the format string. IMO, > it is *much* better not to use the struct module for this > kind of problem, and instead rely on regular string > concatenation. > IMO, it would be a good idea if struct.[un]pack supported a variable * length operator that could appear anywhere that an integer constant could appear, as in C's printf etc and Python's % formatting: dlen = len(data) rawdata = struct.pack("!BB*s", dtype, dlen, dlen, data) # and on the other end of the wire: dtype, dlen = struct.unpack("!BB", rawdata[:2]) data = struct.unpack("!*s", rawdata[2:], dlen) # more than 1 count arg could be used if necessary # *s would return a string # *B, *H, *I, etc would return a tuple of ints in (3.X-speak) I've worked with variable-length data that looked like len1, len2, len3, data1, data2, data3 and the * gadget would have been very handy: len1, len2, len3 = unpack('!BBB', raw[:3]) data1, data2, data3 = unpack('!*H*i*d', raw[3:], len1, len2, len3) Note the semantics of '!*H*i*d' would be different from '!8H2i7d' because otherwise you'd need to do: bundle = unpack('!*H*i*d', raw[3:], len1, len2, len3) data1 = bundle[:len1] data2 = bundle[len1:len1+len2] data3 = bundle[len1+len2:] From mdw at distorted.org.uk Sun Jan 25 22:56:47 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 03:56:47 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> Message-ID: <8763k267pc.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: [snip stuff I don't disagree with] > That makes renaming and refactoring riskier in general in Python than > in statically typed languages with enforced access restrictions. More > care and attention to detail is needed to do it right in Python. In fact, I don't disagree with this statement either. It's just that I think there's a legitimate tradeoff between the assurances you can get from a language designed for static analysis and strictness, and the freedom and dynamicness of languages like Python. It's just that I rather like where Python is now on this continuum, and disagree that shifting it is necessarily a good idea. -- [mdw] From tjreedy at udel.edu Sun Jan 25 23:07:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 23:07:44 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Roger wrote: >> And, just for completeness, the "is" test is canonical precisely because >> the interpreter guarantees there is only ever one object of type None, >> so an identity test is always appropriate. Even the copy module doesn't >> create copies ... >> > > Does the interpreter guarantee the same for False and True bools? Yes. Bool(x) should return one of the two existing instances. In 2.x, the *names* 'True' and 'False' can be rebound because bool is new and people write try: False,True except NameError: False,True = 0,1 to make code back compatible. In 3.0, the names are keywords, just like 'None' and cannot be rebound, so x is True is guaranteed to answer whether x *is* the true object. Back before rebinding 'None' was prohibited, 'is None' was not completely guaranteed either (absent reading the rest of a file to be sure no rebinding would be done). From tjreedy at udel.edu Sun Jan 25 23:09:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 25 Jan 2009 23:09:56 -0500 Subject: Python In-Reply-To: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> References: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> Message-ID: porkodi wrote: > www.easythings5.blogspot.com Ad spam site with pirated semi-gibberish not even containing 'Python'. From skip at pobox.com Sun Jan 25 23:18:30 2009 From: skip at pobox.com (skip at pobox.com) Date: Sun, 25 Jan 2009 22:18:30 -0600 Subject: Python In-Reply-To: References: <66f63827-528e-4a73-90da-7dda5d991716@r10g2000prf.googlegroups.com> Message-ID: <18813.14742.325151.691809@montanaro.dyndns.org> Terry> porkodi wrote: >> www.easythings5.blogspot.com Terry> Ad spam site with pirated semi-gibberish not even containing Terry> 'Python'. Yeah, my fault. I was poking through a bunch of held messages and saw "Pyhon" as the subject. Didn't even look at the message itself until I saw it come through in my email. -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From Russ.Paielli at gmail.com Sun Jan 25 23:46:35 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 25 Jan 2009 20:46:35 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com> <87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk> <7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com> <018d0144$0$20629$c3e8da3@news.astraweb.com> <018d0417$0$20629$c3e8da3@news.astraweb.com> <7xbptuuat8.fsf@ruckus.brouhaha.com> <018d08a6$0$20629$c3e8da3@news.astraweb.com> <8889ff9e-3133-41ca-bded-5174a53e5019@t39g2000prh.googlegroups.com> <8763k267pc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8962522a-93f4-4f4e-ac3d-b232a1619170@d36g2000prf.googlegroups.com> On Jan 25, 7:56?pm, Mark Wooding wrote: > "Russ P." writes: > > [snip stuff I don't disagree with] > > > That makes renaming and refactoring riskier in general in Python than > > in statically typed languages with enforced access restrictions. More > > care and attention to detail is needed to do it right in Python. > > In fact, I don't disagree with this statement either. ?It's just that I > think there's a legitimate tradeoff between the assurances you can get > from a language designed for static analysis and strictness, and the > freedom and dynamicness of languages like Python. ?It's just that I > rather like where Python is now on this continuum, and disagree that > shifting it is necessarily a good idea. > > -- [mdw] I would like to have the option to use Python either way, if possible -- and I honestly don't know if it is possible. The new type annotations are a step in that direction. They are optional, but if used they could make refactoring safer and facilitate static analysis. Enforced access restrictions, if they can be added to Python, would be optional too -- as they are in any language. From timr at probo.com Sun Jan 25 23:46:44 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 26 Jan 2009 04:46:44 GMT Subject: USB in python References: Message-ID: Astan Chee wrote: > >Im trying to write a program for my USB device and I'm thinking of using >python to do this. The USB device is of my own making and it is >activated when one of the two data pins of the USB is given about 5V (or >similar to whatever the power pin is getting). Now I'm confused to if >the software to activate this can actually be written and how do I do >it? Any examples? I've seen pyUSB but it doesn't give me control over >the hardware and how much power is going through the data pins. Sorry, but you have NOT created a USB device, and I sincerely hope you do not try to plug it in to a real USB port. Despite the "serial" in the name, USB is much more than just a pair of wires, like RS-232. USB is a standard protocol-based bus, like Ethernet, and anything that is plugged into it must follow the protocol. You don't get a "voltage", you get a 480 MHz differential digital signal train. The wires are controlled by a USB host controller. You cannot override its behavior. You might be able to achieve your goal by using a parallel port, or by using a USB-to-serial port adapter, or by using one of the many simple and affordable USB experimenter's kits in the world. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gagsl-py2 at yahoo.com.ar Sun Jan 25 23:57:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 02:57:55 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> Message-ID: En Mon, 26 Jan 2009 00:23:30 -0200, John Machin escribi?: > On Jan 26, 1:03?pm, "Gabriel Genellina" > wrote: >> It's so easy that don't doing that is just inexcusable lazyness :) >> Your own example, written using the csv module: >> >> import csv >> >> f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> headers = f.next() >> for line in f: >> ? ? ?field1, field2, field3 = line >> ? ? ?do_stuff() > > And where in all of that do you recommend that .decode(some_encoding) > be inserted? For encodings that don't use embedded NUL bytes (latin1, utf8) I'd decode the fields right when extracting them: field1, field2, field3 = (field.decode('utf8') for field in line) For encodings that allow NUL bytes, I'd use any of the recipes in the csv module documentation. (That is, if I care about the encoding at all. Perhaps the file contains only numbers. Perhaps it contains only ASCII characters. Perhaps I'm only interested in some fields for which the encoding is irrelevant. Perhaps it is an internally generated file and it doesn't matter as long as I use the same encoding on output) But I admit that in general, the "decode input early when reading, work in unicode, encode output late when writing" is the best practice. -- Gabriel Genellina From timr at probo.com Mon Jan 26 00:00:37 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 26 Jan 2009 05:00:37 GMT Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> <20090126015744.2b306ba3@usenot.de> Message-ID: Andreas Waldenburger wrote: > >But as gert says, the standard is "broken" by many many browsers >already We're debating relatively picky semantic point, so I won't feel bad by being picky. Browsers have nothing to do with the JSON standard. JSON is not Javascript, nor is it a part of Javascript. JSON is a data exchange standard, which happens to be readable to Javascript parsers. A valid JSON expression happens to be a valid Javascript expression, but not vice versa. That's just the way it is. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From astan.chee at al.com.au Mon Jan 26 00:12:16 2009 From: astan.chee at al.com.au (Astan Chee) Date: Mon, 26 Jan 2009 16:12:16 +1100 Subject: USB in python In-Reply-To: References: Message-ID: <497D4630.6090405@al.com.au> Tim Roberts wrote: > Sorry, but you have NOT created a USB device, and I sincerely hope you do > not try to plug it in to a real USB port. > Sorry, by USB device, I meant a device that is powered/activated by a bunch of wires that I want to control using a computer and since I had a spare USB jack lying around, I used that instead. But so far I haven't tried it, nor will try it if it wont work properly. Yes, it is not a proper USB device, because I didnt build it to specifically interface with the USB port; but I had to start somewhere. Also, the device requires more power than the standard parallel port can give. Anyway, it looks like the easiest solution for my case is a microcontroller From s.selvamsiva at gmail.com Mon Jan 26 01:30:05 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 26 Jan 2009 12:00:05 +0530 Subject: String comparision In-Reply-To: References: Message-ID: Thank You Gabriel, On Sun, Jan 25, 2009 at 7:12 AM, Gabriel Genellina wrote: > En Sat, 24 Jan 2009 15:08:08 -0200, S.Selvam Siva > escribi?: > > > I am developing spell checker for my local language(tamil) using python. >> I need to generate alternative word list for a miss-spelled word from the >> dictionary of words.The alternatives must be as much as closer to the >> miss-spelled word.As we know, ordinary string comparison wont work here . >> Any suggestion for this problem is welcome. >> > > I think it would better to add Tamil support to some existing library like > GNU aspell: http://aspell.net/ That was my plan earlier,But i am not sure how aspell integrates with other editors.Better i will ask it in aspell mailing list. > You are looking for "fuzzy matching": > http://en.wikipedia.org/wiki/Fuzzy_string_searching > In particular, the Levenshtein distance is widely used; I think there is a > Python extension providing those calculations. > > -- > Gabriel Genellina The following code served my purpose,(thanks for some unknown contributors) def distance(a,b): c = {} n = len(a); m = len(b) for i in range(0,n+1): c[i,0] = i for j in range(0,m+1): c[0,j] = j for i in range(1,n+1): for j in range(1,m+1): x = c[i-1,j]+1 y = c[i,j-1]+1 if a[i-1] == b[j-1]: z = c[i-1,j-1] else: z = c[i-1,j-1]+1 c[i,j] = min(x,y,z) return c[n,m] a=sys.argv[1] b=sys.argv[2] d=distance(a,b) print "d=",d longer = float(max((len(a), len(b)))) shorter = float(min((len(a), len(b)))) r = ((longer - d) / longer) * (shorter / longer) # r ranges between 0 and 1 -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Mon Jan 26 02:22:04 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 26 Jan 2009 09:22:04 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><018a4b9c$0$20629$c3e8da3@news.astraweb.com><83e948f9-4b76-46fb-8828-3dab572df5c4@o4g2000pra.googlegroups.com><87ab9f8dp1.fsf.mdw@metalzone.distorted.org.uk><7d3071a8-93e4-404a-b444-a9b619e63111@40g2000prx.googlegroups.com><018d0144$0$20629$c3e8da3@news.astraweb.com><018d0417$0$20629$c3e8da3@news.astraweb.com><7xbptuuat8.fsf@ruckus.brouhaha.com><018d08a6$0$20629$c3e8da3@news.astraweb.com> <7x3af63l0a.fsf@ruckus.brouhaha.com> Message-ID: <000201c97f89$70a6da80$0d00a8c0@hendrik> "Paul Rubin" wrote: > Steven D'Aprano writes: > > We're not talking specifically about Python standard library changes, > > we're talking about any project which may have more entertaining *cough* > > policies regarding API changes. > > Oh, yes, I see what you mean. That's a problem even in small > projects, sometimes even in 1-person projects. I think it is more prevalent in single person projects than what we have the honesty to admit - After all, if *I* am writing the code, then *I* can do what *I* want, and often *I* do, much to *my* chagrin, when the effects strike home. Do I talk about it? - No way! I just quietly fix it. Sometimes too much freedom is not such a good thing - it leads to all sort of effects of which API spec. creep is one of the least. - Hendrik From m.iatrou at freemail.gr Mon Jan 26 02:36:41 2009 From: m.iatrou at freemail.gr (Michael Iatrou) Date: Mon, 26 Jan 2009 09:36:41 +0200 Subject: Monitor a FTP site for arrival of new/updated files In-Reply-To: <1232910590.24534.1296651319@webmail.messagingengine.com> References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <200901260936.41480.m.iatrou@freemail.gr> When the date was Sunday 25 January 2009, python at bdurham.com wrote: > Any suggestions on a best practice way to monitor a remote FTP > site for the arrival of new/updated files? For a custom solution, you may want to take a look to pyinotify: http://pyinotify.sourceforge.net/ -- Michael Iatrou (idyz) From mrkafk at gmail.com Mon Jan 26 03:14:51 2009 From: mrkafk at gmail.com (mk) Date: Mon, 26 Jan 2009 09:14:51 +0100 Subject: unittest, order of test execution Message-ID: Hello everyone, I've got 2 functions to test, extrfromfile which returns a list of dictionaries, and extrvalues that extracts values from that list. Now I can test them both in one test case, like this: def test_extrfromfile(self): valist = ma.extrfromfile('loadavg_unittest.txt') valist_ut = [ {'day': '08-11-19', 'time': '12:41', 'val': 0.11}, {'day': '08-11-19', 'time': '12:42', 'val': 0.08}, {'day': '08-11-19', 'time': '12:43', 'val': 0.57}, {'day': '08-11-19', 'time': '12:44', 'val': 0.21}, {'day': '08-11-19', 'time': '12:45', 'val': 0.08}, {'day': '08-11-19', 'time': '12:46', 'val': 0.66}, {'day': '08-11-19', 'time': '12:47', 'val': 0.32}, {'day': '08-11-19', 'time': '12:48', 'val': 0.12}, {'day': '08-11-19', 'time': '12:49', 'val': 0.47}, {'day': '08-11-19', 'time': '12:50', 'val': 0.17}] self.assertEqual(valist, valist_ut) vlextr_ut = [0.11, 0.08, 0.57, 0.21, 0.08, 0.66, 0.32, 0.12, 0.47, 0.17] vlextr = ma.extrvalues(valist) self.assertEqual(len(vlextr_ut), len(vlextr)) for (idx, elem) in enumerate(vlextr_ut): self.assertAlmostEqual(elem, vlextr[idx]) But I was wondering, *should* this test be separated into two unit tests, one for each function? On the face of it, it looks that's how it should be done. This, however, raises the question: what's the order of test execution in the unittest? And how to pass values between unit tests? Should I modify 'self' in unit test? Regards, mk From ivan.illarionov at gmail.com Mon Jan 26 03:18:17 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Mon, 26 Jan 2009 00:18:17 -0800 (PST) Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> Message-ID: <9063ddd1-aecc-4ed6-8dea-7edc4dcdc595@w24g2000prd.googlegroups.com> Diez wrote: > gert schrieb: > > Single quotes works in every browser that support json so i > > recommended python should support it too, besides it looks much > > cleaner > > {'test': 'test'} > > {"test": "test"} > > > It can not be that hard to support both notation can it ? > > It's not hard, but it's not standard-conform. > > Most browsers even accept something like this: > > {foo : "bar"} > > But all of this is not JSON. By the way, all of this *is* YAML: >>> yaml.load("{'test':'test'}") {'test': 'test'} >>> yaml.load("{test: test}") {'test': 'test'} If someone needs more forgiving and user-editable format, YAML might be a good choice. -- Ivan From lie.1296 at gmail.com Mon Jan 26 03:21:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 26 Jan 2009 08:21:26 +0000 (UTC) Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > Diez B. Roggisch wrote: >>> >>> >> If all you need is on-off - why can't you just use a switch? >> >> >> > Because I want to control the on-off the device using a computer and > write software for it (which I am confident I can do if I had references > to how the wrappers to said interface). Cheers > Astan. > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little Hardware Experience). High pitched sound (or anything in sound-ology that means high voltage) means the device is on and low pitched sound off. The device will need an additional transistor to separate low voltage from the high voltage. I don't know how much power can be pulled from jack out, but for a home brewn device it is still feasible to draw power from USB and signal from jack out. From banibrata.dutta at gmail.com Mon Jan 26 03:33:22 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Mon, 26 Jan 2009 14:03:22 +0530 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: <3de8e1f70901260033u1a12d1cajeea1b6b5a697d310@mail.gmail.com> high pitch is == high frequency, no higher amplitude... but the difference can be easily made out and the electronics for this is very well understood and used.point is, the gentleman asking the question might already have a USB controller built into his device, and while most modern computers have anywhere between 2-6 USB ports, you have only 1 audio-out (Mic), so chances of finding a free "controller" port may be a bit of a challenge. On Mon, Jan 26, 2009 at 1:51 PM, Lie Ryan wrote: > On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > > > Diez B. Roggisch wrote: > >>> > >>> > >> If all you need is on-off - why can't you just use a switch? > >> > >> > >> > > Because I want to control the on-off the device using a computer and > > write software for it (which I am confident I can do if I had references > > to how the wrappers to said interface). Cheers > > Astan. > > > > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. The > device will need an additional transistor to separate low voltage from > the high voltage. I don't know how much power can be pulled from jack > out, but for a home brewn device it is still feasible to draw power from > USB and signal from jack out. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From thebrasse at gmail.com Mon Jan 26 04:03:43 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 01:03:43 -0800 (PST) Subject: Function arguments Message-ID: Hello! Is there any way that I can get at all the arguments passed to a function as a map without using keyword arguments? def foo(a, b, c): # Can I access all the arguments in a collection somewhere? I'm mainly curious since I have stumbled on to some cases where it might have been nice to be able to do that. :.:: mattias From deets at nospam.web.de Mon Jan 26 04:06:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 10:06:27 +0100 Subject: v = json.loads("{'test':'test'}") In-Reply-To: References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> Message-ID: <6u5cokFdmi22U1@mid.uni-berlin.de> gert schrieb: > On Jan 26, 12:40 am, "Diez B. Roggisch" wrote: >>>> But all of this is not JSON. >>> Yes it is, you just make it more python dictionary compatible :) >> No, what you do is to make it more incompatible with other >> json-implementations. Which defies the meaning of a standard. >> >> Besides, {foo : "bar"} is *not* python dictionary compatible, at least >> not unless you defined foo beforehand, and then there is no guarantee >> that foo is actually as string containing 'foo'. >> >>> What is this json person email address so I can ask that he makes a >>> very small update on his site. >> Go try your luck -http://www.json.org/ >> >>> Besides if you can make lightweight versions of standards >>> http://docs.python.org/library/xml.dom.minidom.html >> minidom is a lightweight version of the DOM-API. But it reads and writes >> standard-conform XML documents. >> >> The same applies for element-tree and lxml. >> >> So it does not serve as a counter-example. > > yes it does because adding ' does not mean replacing " so it will > still load standard json. Like every browser does and is exactly the > same philosofie as No. If minidom would accept XML-documents that contain newlines in attributes (which otherwise are forbidden), e.g. *that* would be like adding single-quote stringliterals to JSON. This is about the *format*, not the API. There are people who say something along the lines of "be strict when writing, and tolerant when reading" (the exact quote is different, but neither google:~site:mybrain nor any other have helped me here), so one could argue that reading JSON that is not standard-conform would be ok. But IMHO that would increase the amount of interoperability-problems - because some people would *write* json that isn't standard-conform anymore. Diez From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 04:07:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 10:07:38 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87wscpipvt.fsf.mdw@metalzone.distorted.org.uk> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> Message-ID: <497d7d40$0$4845$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 23, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Russ P. a ?crit : > >>> As I said before, if you have the source code you can always change >>> private attributes to public in a pinch if the language enforces >>> encapsulation. >> And then have to maintain a fork. No, thanks. > > For crying out loud, how many private attributes do you need to > access? May I remind you that this is an hypothetical use case ? > If it's a dozen, then you and your library developer are > obviously not on the same page. If it's one or two, then it's hardly a > "fork." Just take note of the one or two places where you needed to > remove the access restriction and you're done. Yeah, fine. And doing it each and any release. A fork is a fork is a fork... >>> But if you are working on a team project, you can't >>> change the code that another member of a team checks in. >> Why on earth couldn't I change the code of another member of my team if >> that code needs changes ? The code is the whole team's ownership. > > OK, fine, you can change the code of another member of the team. No. I can change the *team's* code. Please *read*. "team's ownership", ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get the message, now ? > Are > you going to check with him first, or just do it? I give up. (snip) >> My my my. If you don't trust your programmers, then indeed, don't use >> Python. What can I say (and what do I care ?). But once again, relying >> on the language's access restriction to manage *security* is, well, kind >> of funny, you know ? > > Are you seriously saying that if you were managing the production of a > major financial software package with hundreds of developers, you > would just "trust" them all to have free access to the most sensitive > and critical parts of the program? Now *that's*, well, kind of funny, > you know? A remote web service - for example - is a far better blackbox when it comes to this kind of "sensitive and critical parts". If I can't trust someone wrt/ "this" part of the code, then he won't even have it as a binary package. Period. > Would you give all those developers your password to get into the > system? No? Wait a minute ... you mean you wouldn't "trust" them with > your password? But what about "openness"? Are you some sort of fascist > or what? Goodwin point. You loose. Good bye again, Mr P. From max at alcyone.com Mon Jan 26 04:09:34 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 26 Jan 2009 01:09:34 -0800 Subject: Function arguments In-Reply-To: References: Message-ID: brasse wrote: > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? > > I'm mainly curious since I have stumbled on to some cases where it > might have been nice to be able to do that. Look up the function call syntaxes with * and **: >>> def foo(*args): print args ... >>> def bar(**keywords): print keywords ... >>> foo(1, 2, 3) (1, 2, 3) >>> bar(a=1, b=2, c=3) {'a': 1, 'c': 3, 'b': 2} -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Custom reconciles us to everything. -- Edmund Burke From deets at nospam.web.de Mon Jan 26 04:11:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 10:11:28 +0100 Subject: Function arguments In-Reply-To: References: Message-ID: <6u5d21FdiqprU1@mid.uni-berlin.de> brasse schrieb: > Hello! > > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? > > I'm mainly curious since I have stumbled on to some cases where it > might have been nice to be able to do that. There is the locals()-call that returns the local variables as dictionary. Diez From clp2 at rebertia.com Mon Jan 26 04:11:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 01:11:57 -0800 Subject: Function arguments In-Reply-To: References: Message-ID: <50697b2c0901260111n2016b566gac5b33d28b6c6ee3@mail.gmail.com> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > Hello! > > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): > # Can I access all the arguments in a collection somewhere? You can use positional arguments: def foo(*args): print args foo("a", "b", "c") #==> ["a", "b", "c"] Though if you explained your situation more, the newsgroup could probably be of greater help. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From thebrasse at gmail.com Mon Jan 26 04:34:10 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 01:34:10 -0800 (PST) Subject: Function arguments References: Message-ID: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> On Jan 26, 10:11?am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > > Hello! > > > Is there any way that I can get at all the arguments passed to a > > function as a map without using keyword arguments? > > > def foo(a, b, c): > > ? ?# Can I access all the arguments in a collection somewhere? > > You can use positional arguments: > > def foo(*args): > ? ? print args > > foo("a", "b", "c") #==> ["a", "b", "c"] > > Though if you explained your situation more, the newsgroup could > probably be of greater help. > This is an abbreviated version of what I am doing now: def make_data(**kw): ''' make_data(foo='123', bar=42, time=time.time()) ''' template = '%(foo)s - %(bar)d - %(time)s' kw['time'] = time.strftime('%c', kw['time'] return template % kw This works, but the function signature doesn't say much about arguments I should pass to it. What I would like to do is something like this: def make_data(foo, bar time): template = '%(foo)s - %(bar)d - %(time)s' args = magic_get_args_function() args['time'] = time.strftime('%c', args['time'] return template % args I hope this should clear things up a bit. :-) :.:: mattias From clp2 at rebertia.com Mon Jan 26 04:39:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 01:39:28 -0800 Subject: Function arguments In-Reply-To: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> References: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> Message-ID: <50697b2c0901260139j4d5089c0p7109a4c7f6891a21@mail.gmail.com> On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > On Jan 26, 10:11 am, Chris Rebert wrote: >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: >> > Hello! >> >> > Is there any way that I can get at all the arguments passed to a >> > function as a map without using keyword arguments? >> >> > def foo(a, b, c): >> > # Can I access all the arguments in a collection somewhere? >> >> You can use positional arguments: >> >> def foo(*args): >> print args >> >> foo("a", "b", "c") #==> ["a", "b", "c"] >> >> Though if you explained your situation more, the newsgroup could >> probably be of greater help. >> > > This is an abbreviated version of what I am doing now: > > def make_data(**kw): > ''' > make_data(foo='123', bar=42, time=time.time()) > ''' > template = '%(foo)s - %(bar)d - %(time)s' > kw['time'] = time.strftime('%c', kw['time'] > return template % kw > > This works, but the function signature doesn't say much about > arguments I should pass to it. What I would like to do is something > like this: > > def make_data(foo, bar time): > template = '%(foo)s - %(bar)d - %(time)s' > args = magic_get_args_function() > args['time'] = time.strftime('%c', args['time'] > return template % args Just use locals() as was pointed out by Diez: def make_data(foo, bar, time): template = '%(foo)s - %(bar)d - %(time)s' time = time.strftime('%c', time) return template % locals() Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From castironpi at gmail.com Mon Jan 26 04:52:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 01:52:30 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <45adb6e7-4b34-48c5-8c8a-8037ce5e387e@x16g2000prn.googlegroups.com> Hi Mark, nice to have your comment. On Jan 25, 9:47?pm, Mark Wooding wrote: > Aaron Brady writes: snip > > Object 'A' is of type 'Ta'. ?When process 'P' is looking at it, it > > needs to have an 'ob_type' that is 'Ta' as process 'P' sees it. ?When > > process 'Q' is looking at it, it needs to have an 'ob_type' that is > > 'Ta' as process 'Q' sees it. ?If it referred to 'Ta' in process 'P' > > when 'Q' was calling it, 'Q' would have to access memory that is in > > another process. > > I see. ?My immediate reaction was to suggest that you just put the > PyTypeObject in shared memory -- but then I realised that the shared > memory region will probably be in different addresses in the two > processes. Yes, exactly. >?I'll assume that you've got enough synchronization between > the processes involved to stop everything from turning to mush. Have at thee, synchronization! Yes, it is possible theoretically. (By the way, did you know you can detect deadlock before it strikes with a simple breadth-first search?) The idea is still not out of the proof-of-concept stage-- the concept not having been proved. > > Therefore, I need a field and an array. ?The field indicates which > > type should be loaded, and the array contains the types. ?Quick > > example: > > > PyTypeObject* array_of_types[]= { &SharedList, &SharedTuple }; > > > Then, when a list is being accessed, it can set its own 'ob_type' > > field to 'array_of_types[ 0 ]', and similarly for a tuple. > > > However, I'm having trouble getting 'array_of_types' in the right > > module during compilation. ?My question is: Where do 'array_of_types' > > and the forward declarations for the types go? > > I'm not sure I understand the difficulty. ?They'll want to go in your C > module somewhere, but as long as SharedList and SharedTuple are either > in the same source file or not declared `static' you just write the > definition you've got somewhere after declaring or defining the actual > types in question. The problem I ran into was that different modules (C files) were seeing different versions of the structure. '&SharedList' showed up as different addresses in the debugger! I might be missing something, but I think the forward declaration got interpreted as an actual declaration in the different files that included the header. Mysteriously, it disappeared when I tried it again now. It's still a possibility. The solution I looked at today was declare the array like this: PyTypeObject* keep_types[]; It's even ok in a shared header (multiply included). Then the actual definition just gives it NULLs and a size, which are filled in as the needed modules are loaded. That solves the (additional) problem of not having called the owner module's initialization code. The catch is that if you have an object in a SharedList, you need to have imported its module before you load it. However 'pickle' has that problem too, so I don't feel bad. > There's a comment in Extending and Embedding (2.1) about initializing > PyTypeObjects: > > : ? ? ? ? ?PyObject_HEAD_INIT(NULL) > : > : This line is a bit of a wart; what we'd like to write is: > : > : ? ? ? ? ?PyObject_HEAD_INIT(&PyType_Type) > : > : as the type of a type object is "type", but this isn't strictly > : conforming C and some compilers complain. > > The comment here is wrong: &PyType_Type is a perfectly good constant > expression as far as C is concerned, but alas Microsoft's dynamic > linking system isn't clever enough to cope with it even so (because it's > in a separate link unit). ?But this isn't a problem in our case: > presumably SharedList and SharedTuple are in the same module, so this > should all just work. Here is another quote from the docs: "Portability therefore requires not to make any assumptions about symbol visibility. This means that all symbols in extension modules should be declared static, except for the module?s initialization function, in order to avoid name clashes with other extension modules (as discussed in section The Module?s Method Table and Initialization Function)." All declared static? Dear. So I don't know what to make of it, especially given the need to call 'PyType_Ready'. From mdw at distorted.org.uk Mon Jan 26 05:20:30 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 26 Jan 2009 10:20:30 +0000 Subject: Dynamic methods and lambda functions References: Message-ID: <87ocxu4bdd.fsf.mdw@metalzone.distorted.org.uk> Michael Torrie writes: > Basically, don't use a lambda. Create a real, local closure with a > nested def block. That way the closure is created every time the > parent function is called. Nope. I explained the real problem quite clearly, and it's to do with the difference between binding and assignment. What's the difference between these two pieces of code? ## First def __init__(self): for n, v in props: setattr(Person, '_' + n, v) setattr(Person, n, lambda self: getattr(self, '_' + n)) ## Second def __init__(self): for n, v in props: setattr(Person, '_' + n, v) def hack(self): return getattr(self, '_' + n) setattr(Person, n, hack) > Lambda expressions are only ever compiled once during execution. The same is true of `def' bodies. -- [mdw] From benfal at yahoo.it Mon Jan 26 05:23:22 2009 From: benfal at yahoo.it (Benny Fallica) Date: Mon, 26 Jan 2009 10:23:22 +0000 (GMT) Subject: Ldap Extended Operation python Message-ID: <286207.4328.qm@web26908.mail.ukl.yahoo.com> Hello there, what would be the python implementation for this line in Java: java.util.Hashtable environment = LdapHelper.getEnvironment(url, true); LdapContext ldapContext = new InitialLdapContext(environment, null); Response resp = (Response) ldapContext.extendedOperation(new Request()) how to deal with extended operations in python? thanks for your help! From geekmail at usenot.de Mon Jan 26 05:35:51 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 11:35:51 +0100 Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <20090126113551.4dbbbb51@usenot.de> On Mon, 26 Jan 2009 02:37:37 +0000 Mark Wooding wrote: > > This looks OK, although I'd suggest using "cls.counter += 1" instead > > of "a.counter += 1" in the __new__() method. Just seems clearer to > > me, esp. when you think about subclassing. > > I'm not sure about clarity, but that would be semantically different. > The code as written counts all instances of a and its subclasses. > Your suggestion would count instances of subclasses independently. I > don't know which behaviour the OP would prefer, but I don't think > choosing between them is a matter of clarity. > Oh shoot. I should have known that. I hope I will from now on, at least. :/ /W -- My real email address is constructed by swapping the domain with the recipient (local part). From googler.1.webmaster at spamgourmet.com Mon Jan 26 05:47:31 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 26 Jan 2009 02:47:31 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) References: Message-ID: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> On 26 Jan., 03:25, "Gabriel Genellina" wrote: > En Sun, 25 Jan 2009 23:46:01 -0200, ? > escribi?: > > > > > I have a problm with deallocating stuff. I call a function with this > > command: > > > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); > > > if(rvalue==NULL) > > ? ? PyErr_Print(); > > else > > ? ? Py_DECREF(rvalue); > > > Can it be, that something is missing here? Imagine I allocate an > > object of a type: > > > t = MyImage() > > ,;- syntax_error 129=)/% ?#is a syntax error > > > How you see I would get a syntaxerror, but an object of the type > > MyImage() is created. But its deallocated when Py_Finalize() is > > called. What can I do to deallocate this object after > > PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL > > the object is deallocated, but what can I do if rvalue==NULL= > > A syntax error is detected *before* the code runs -- so the object isn't ? > created at all. > > -- > Gabriel Genellina Hi! Yes, you are right. I got this issue not in syntax error, I get it on a runtime error like this: t = MyImage() self.test("hallo") #test takes an integer so this would throw an exception. Here you see, an object of the type MyImage() was created but its not deleted. 't' is a local reference so how can I do that? Thanks! From carribeiro at gmail.com Mon Jan 26 05:48:25 2009 From: carribeiro at gmail.com (Carlos Ribeiro) Date: Mon, 26 Jan 2009 08:48:25 -0200 Subject: *.python.org broken? In-Reply-To: References: Message-ID: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> I experienced the same problem here in Brazil. Tweeks ago I could not access any *.python.org site. Today I tried and it worked. The problem seemed to be limited to Python's domain because I could access every other site that I tried the same day. More info: - At least for me I didn't seem to be IPv6 related. - It failed in the same day in more than one PC, using different providers. - The domain name was resolving ok. My guess is that it was some kind of BGP failure. Perhaps the AS that hosts Python's servers injected a wrong route or someone else did, effectively stealing all the traffic for that prefix. That's more common than people realize (specially nowadays when countries such as Pakistan try to block domains by messing with BGP). Carlos Ribeiro On Sun, Jan 25, 2009 at 11:44, Cousin Stanley wrote: > > > Is anybody else having trouble accessing sites (including www, docs, > > wiki) in the python.org tree, or is it just me? (Or just .au?) > > Yes, connecting to python.org sites has been problematic > for me as well .... > > I don't remember when the trouble started, but it's been > problematic for at least a week or longer here .... > > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Carlos Ribeiro Consultoria em Projetos blog: http://rascunhosrotos.blogspot.com blog: http://pythonnotes.blogspot.com mail: carribeiro at gmail.com mail: carribeiro at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Mon Jan 26 06:23:18 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 11:23:18 +0000 Subject: Newby: how to transform text into lines of text In-Reply-To: <497CF6FA.3030000@tim.thechases.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> Message-ID: 2009/1/25 Tim Chase : > (again, a malformed text-file with no terminal '\n' may cause it > to be absent from the last line) Ahem. That may be "malformed" for some specific file specification, but it is only "malformed" in general if you are using an operating system that treats '\n' as a terminator (eg, Linux) rather than as a separator (eg, MS DOS/Windows). Perhaps what you don't /really/ want to be reminded of is the existence of operating systems other than your preffered one? -- Tim Rowe From digitig at gmail.com Mon Jan 26 06:45:35 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 11:45:35 +0000 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: > I like the latter two styles, particularly the last one. That way you > can see at a glance that those member variables are defined in the > super class. I like the second style because it makes it leaves the 2-d implementation hidden, which is the whole point of encapsulation. > But then I am a fan of Hungarian notation, which many > programmers can't stand. Is it that programmers can't stand it, or is it that they can't stand it when it's imposed when not needed? As a pseudo type system for languages with no typing it's pretty useful. To the extent that a language provides typing it's useless verging on dangerous because it can get out of synch with the actual type. I believe that any case of Hungarian notation being useful is evidence of a flaw in the language being used -- but arguably all languages are flawed in some way or other, so Hungarian /can/ be useful. At this level I don't recognise a difference between System and Applications Hungarian, by the way -- the difference is eliminated if you declare types corresponding to the "meanings", which is commonplace in, for example, Ada. -- Tim Rowe From googler.1.webmaster at spamgourmet.com Mon Jan 26 06:47:43 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Mon, 26 Jan 2009 03:47:43 -0800 (PST) Subject: Python C API (PyObject_CallMethod clear object) References: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> Message-ID: the hook is, how to delete the locals of this function, maybe thats a workaround? thanks and bye. From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 06:51:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 12:51:28 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> Message-ID: <497da399$0$4780$426a74cc@news.free.fr> Russ P. a ?crit : > On Jan 23, 6:36 pm, Luis Zarrabeitia wrote: > >>> Makes *no* sense? There's *no* good reason *at all* for the original >>> author to hide or protect internals? >> My bad, sorry. >> It makes sense... if the original author is an egotist who believes he must >> control how I use that library. > > If the original author provides you with the source code and the right > to modify it, he cannot possibly control how you use the library. You > can trivially disable any access controls. But for some reason that's > not enough for you. > > Has it occurred to you that some users might actually *want* access > controls? Then they'll have to choose a language which provides it. > Maybe some users want to actually use the library as the > author intended it to be used. And ? Strange enough, that's usually what happens - using the official, documented API. Strange enough, it seems that Python programmers are mostly wise enough to not break encapsulation (nor abuse any of the highly dynamic features of Python) without pretty good reasons, lots of thought and attention, clear documentation of the fact, and possibly exchanges with the library author (or maintainer) to discuss the problem. From siona at chiark.greenend.org.uk Mon Jan 26 07:22:18 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 26 Jan 2009 12:22:18 +0000 (GMT) Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > [ ... ] Your approach of reading the full contents can be >used like this: > >content = a.read() >for line in content.split("\n"): > print line > Or if you want the full content in memory but only ever access it on a line-by-line basis: content = a.readlines() (Just because we can now write "for line in file" doesn't mean that readlines() is *totally* redundant.) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From michael at stroeder.com Mon Jan 26 08:25:25 2009 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Mon, 26 Jan 2009 14:25:25 +0100 Subject: Ldap Extended Operation python In-Reply-To: References: Message-ID: <57q056-bl7.ln1@nb2.stroeder.com> Benny Fallica wrote: > Hello there, > > what would be the python implementation for this line in Java: > > > java.util.Hashtable environment = LdapHelper.getEnvironment(url, true); > LdapContext ldapContext = new InitialLdapContext(environment, null); > Response resp = (Response) ldapContext.extendedOperation(new Request()) > how to deal with extended operations in python? Which LDAP extended operation do you want to use? In python-ldap the following ext. ops are already implemented: http://python-ldap.sourceforge.net/doc/html/ldap.html#ldap.LDAPObject.whoami_s http://python-ldap.sourceforge.net/doc/html/ldap.html#ldap.LDAPObject.passwd There's no generic interface for ext. ops. yet. Feel free to contribute something like this. Ciao, Michael. From robin at reportlab.com Mon Jan 26 08:28:09 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jan 2009 13:28:09 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: <497AE1F8.5040008@jessikat.plus.net> References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> <497AE1F8.5040008@jessikat.plus.net> Message-ID: <497DBA69.8030201@chamonix.reportlab.co.uk> I found that this error > Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in ignored occurs when attempting to copy (copy.copy(inst)) an instance of a class that looks like this class LazyParagraph(_LazyMixin,TTParagraph): SUPER=TTParagraph _CLEAN_SPACE=1 however, whilst debugging I found the error disappeared when I tried to determine what accesses were being made on this instance during the copy. If I use this code class _LazyParagraph(_LazyMixin,TTParagraph): SUPER=TTParagraph _CLEAN_SPACE=1 class LazyParagraph(_LazyParagraph): def __getattr__(self,a): return getattr(_LazyParagraph,a) then instances of the new lazy paragraph don't cause a problem. This looks awfully fragile to me, and I haven't really got any closer to understanding what's going on. Anyone got any ideas? I have attempted to abstract the problem, but so far I haven't found the vital bits. -- Robin Becker From steve at holdenweb.com Mon Jan 26 08:44:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 08:44:43 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Terry Reedy wrote: > Roger wrote: >>> And, just for completeness, the "is" test is canonical precisely because >>> the interpreter guarantees there is only ever one object of type None, >>> so an identity test is always appropriate. Even the copy module doesn't >>> create copies ... >>> >> >> Does the interpreter guarantee the same for False and True bools? > > Yes. Bool(x) should return one of the two existing instances. > > In 2.x, the *names* 'True' and 'False' can be rebound because bool is > new and people write > try: > False,True > except NameError: > False,True = 0,1 > > to make code back compatible. > I would claim that the ability to rebind True and False is a simple bug, though one not likely to be fixed in an 2.x release. The code above doesn't rebind True and False in interpreters that have them ... > In 3.0, the names are keywords, just like 'None' and cannot be rebound, > so x is True is guaranteed to answer whether x *is* the true object. > > Back before rebinding 'None' was prohibited, 'is None' was not > completely guaranteed either (absent reading the rest of a file to be > sure no rebinding would be done). > And that was a bug too, in this case one that *was* removed in 2.4, I believe. Don't have 2.3 lying around just now. Python 2.4.3 (#1, May 24 2008, 13:47:28) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> None = 3 SyntaxError: assignment to None regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:05:34 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:05:34 -0500 Subject: Counting number of objects In-Reply-To: <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Andreas Waldenburger writes: > >> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath >> wrote: >> >>> class a(object): >>> counter = 0 >>> def __new__(cls, *args, **kwargs): >>> a.counter += 1 >>> return object.__new__(cls, *args, **kwargs) > > Hmm. Exceptions raised during object creation make this rather > precarious. In your code, if object.__new__ raises an exception, the > counter will end up too high (the __del__ method won't get called in > this case). > If object.__new__ raises an exception you have bigger problems to worry about than an object count being wrong. > One might try to rewrite it: > > def __new__(cls, *args, **kw): > thing = object.__new__(cls, *args, **kw) > a.counter += 1 > return thing > > Now this won't work in subclasses if they also have a __new__ method: > again, if the subclass's __new__ raises an exception then __del__ won't > be called and the counter will be too high. > > To make this technique work, I think you need to do the counter > increment in __init__ rather than __new__, and to set an attribute so > that __del__ knows whether to do the decrement. (If a subclass's > __init__ raises an exception before yours gets called, you don't want to > do the decrement because that'll leave the counter too low.) > Yes, rather better to do it that way and decouple it from __new__(). Of course super() might help here, though not everyone approves of it. >> This looks OK, although I'd suggest using "cls.counter += 1" instead >> of "a.counter += 1" in the __new__() method. Just seems clearer to me, >> esp. when you think about subclassing. > > I'm not sure about clarity, but that would be semantically different. > The code as written counts all instances of a and its subclasses. Your > suggestion would count instances of subclasses independently. I don't > know which behaviour the OP would prefer, but I don't think choosing > between them is a matter of clarity. > Correct, but pointing out the differences has highlighted that is a real design decision to be made in the event that subclassing is used. >> Another way to go would be to use the weakref module and create a >> weakref-set (or list) as the counter. That way you would only need to >> add the objects in the __new__() method and not worry about removing >> them. I will admit that this is overengineering the problem a bit, but >> might be a good exercise. > > This is a better approach, because it avoids the problems with > exceptions during object construction that I described above. > >>> Another question - unrelated to the major topic: >>> How much time does it take to be proficient in Python? >> Don't concern yourself with that question at all, is my advice. > > Indeed. Besides, it varies an awful lot. > [...] >>> - or am I just dumb? >> You're writing programs and you're communicating with like-minded >> people about your problems (in a socially appropriate way). Not what >> dumb people do, in my book. > > Absolutely! Besides, you're asking sensible questions about subtle > parts of the language -- I wouldn't say that __new__ was beginner > territory, for example. So, no, you certainly don't seem dumb to me. > Hear, hear! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:09:39 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:09:39 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <497da399$0$4780$426a74cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Russ P. a ?crit : >> On Jan 23, 6:36 pm, Luis Zarrabeitia wrote: >> >>>> Makes *no* sense? There's *no* good reason *at all* for the original >>>> author to hide or protect internals? >>> My bad, sorry. >>> It makes sense... if the original author is an egotist who believes >>> he must >>> control how I use that library. >> >> If the original author provides you with the source code and the right >> to modify it, he cannot possibly control how you use the library. You >> can trivially disable any access controls. But for some reason that's >> not enough for you. >> >> Has it occurred to you that some users might actually *want* access >> controls? > > Then they'll have to choose a language which provides it. > >> Maybe some users want to actually use the library as the >> author intended it to be used. > > And ? Strange enough, that's usually what happens - using the official, > documented API. Strange enough, it seems that Python programmers are > mostly wise enough to not break encapsulation (nor abuse any of the > highly dynamic features of Python) without pretty good reasons, lots of > thought and attention, clear documentation of the fact, and possibly > exchanges with the library author (or maintainer) to discuss the problem. Quite. Python is a language "for consenting adults". It has perceived deficiencies for certain software engineering environments. Can we drop the subject now? This horse was flogged to death long ago, and it's pointless and cruel to keep on beating the remains. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:13:33 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:13:33 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > unineuro at gmail.com writes: [...] > * Assignment stores a new (reference to a) value in the variable. > > * Binding modifies the mapping between names and variables. > I realise I have omitted what was doubtless intended to be explanatory detail, but I am having trouble reconciling those sentences. Would you mind explaining "in vacuuo" what you see as the difference between assignment and binding? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mrkafk at gmail.com Mon Jan 26 09:18:02 2009 From: mrkafk at gmail.com (mk) Date: Mon, 26 Jan 2009 15:18:02 +0100 Subject: Building matplotlib from source on windows Message-ID: Hello everyone, I'm trying to get 0.98.5.2 installed on Windows to use Python 2.6 (dependency packages I need to use on that version, long story, etc). When I was trying to build it (python setup.py build), it was finding the VC 9.0 C++ compiler on my comp. However, after adding necessary packages (zlib, png, etc), it was reporting missing 'unistd.h'. Clearly, this means it was meant to be built with GCC for Windows like MinGW ? I have uninstalled the VC compiler, installed GnuWin32 packages and tried using MinGW (passing --compiler=mingw32 to python setup.py build ) but now compilation process fails like this: c:\MinGW\bin\g++.exe -mno-cygwin -shared -s build\temp.win32-2.6\Release\src\ft2font.o build\temp.wi n32-2.6\Release\src\mplutils.o build\temp.win32-2.6\Release\cxx\cxxsupport.o build\temp.win32-2.6\Re lease\cxx\cxx_extensions.o build\temp.win32-2.6\Release\cxx\indirectpythoninterface.o build\temp.win 32-2.6\Release\cxx\cxxextensions.o build\temp.win32-2.6\Release\src\ft2font.def -LC:\Python26\libs - LC:\Python26\PCbuild -lfreetype -lz -lgw32c -lstdc++ -lm -lpython26 -lmsvcr90 -o build\lib.win32-2.6 \matplotlib\ft2font.pyd c:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgw32c collect2: ld returned 1 exit status error: command 'g++' failed with exit status 1 What the heck is lgw32c?? Regards, mk From steve at holdenweb.com Mon Jan 26 09:22:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:22:57 -0500 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: Lie Ryan wrote: > On Fri, 23 Jan 2009 18:56:38 +1100, Astan Chee wrote: > >> Diez B. Roggisch wrote: >>>> >>>> >>> If all you need is on-off - why can't you just use a switch? >>> >>> >>> >> Because I want to control the on-off the device using a computer and >> write software for it (which I am confident I can do if I had references >> to how the wrappers to said interface). Cheers >> Astan. >> > > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. The > device will need an additional transistor to separate low voltage from > the high voltage. I don't know how much power can be pulled from jack > out, but for a home brewn device it is still feasible to draw power from > USB and signal from jack out. > Congratulations. You just invented the modem. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 09:25:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 09:25:28 -0500 Subject: USB in python In-Reply-To: <497D4630.6090405@al.com.au> References: <497D4630.6090405@al.com.au> Message-ID: Astan Chee wrote: > Tim Roberts wrote: >> Sorry, but you have NOT created a USB device, and I sincerely hope you do >> not try to plug it in to a real USB port. >> > Sorry, by USB device, I meant a device that is powered/activated by a > bunch of wires that I want to control using a computer and since I had a > spare USB jack lying around, I used that instead. But so far I haven't > tried it, nor will try it if it wont work properly. Yes, it is not a > proper USB device, because I didnt build it to specifically interface > with the USB port; but I had to start somewhere. Also, the device > requires more power than the standard parallel port can give. > Anyway, it looks like the easiest solution for my case is a microcontroller In which case the Arduino may be a good place to start. The recent duemilanove boards use USB to communicate with the host, and so the USB port should be available to the microcontroller. We areg etting some way away from Python now, of course ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From thebrasse at gmail.com Mon Jan 26 09:49:25 2009 From: thebrasse at gmail.com (brasse) Date: Mon, 26 Jan 2009 06:49:25 -0800 (PST) Subject: Function arguments References: <798f0a63-48bf-4be2-bc79-481cb0aea26f@t39g2000prh.googlegroups.com> Message-ID: <5e616a7c-3cde-4f28-a56a-15b86ef66ef2@35g2000pry.googlegroups.com> On Jan 26, 10:39?am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > > On Jan 26, 10:11 am, Chris Rebert wrote: > >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > >> > Hello! > > >> > Is there any way that I can get at all the arguments passed to a > >> > function as a map without using keyword arguments? > > >> > def foo(a, b, c): > >> > ? ?# Can I access all the arguments in a collection somewhere? > > >> You can use positional arguments: > > >> def foo(*args): > >> ? ? print args > > >> foo("a", "b", "c") #==> ["a", "b", "c"] > > >> Though if you explained your situation more, the newsgroup could > >> probably be of greater help. > > > This is an abbreviated version of what I am doing now: > > > def make_data(**kw): > > ? ?''' > > ? ?make_data(foo='123', bar=42, time=time.time()) > > ? ?''' > > ? ?template = '%(foo)s - %(bar)d - %(time)s' > > ? ?kw['time'] = time.strftime('%c', kw['time'] > > ? ?return template % kw > > > This works, but the function signature doesn't say much about > > arguments I should pass to it. What I would like to do is something > > like this: > > > def make_data(foo, bar time): > > ? ?template = '%(foo)s - %(bar)d - %(time)s' > > ? ?args = magic_get_args_function() > > ? ?args['time'] = time.strftime('%c', args['time'] > > ? ?return template % args > > Just use locals() as was pointed out by Diez: > > def make_data(foo, bar, time): > ? ? template = '%(foo)s - %(bar)d - %(time)s' > ? ? time = time.strftime('%c', time) > ? ? return template % locals() > Nice, thank you! :.:: mattias From bj_666 at gmx.net Mon Jan 26 09:51:33 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 26 Jan 2009 14:51:33 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> Message-ID: <6u60vlFdkq3bU2@mid.uni-berlin.de> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > content = a.readlines() > > (Just because we can now write "for line in file" doesn't mean that > readlines() is *totally* redundant.) But ``content = list(a)`` is shorter. :-) Ciao, Marc 'BlackJack' Rintsch From BrianVanderburg2 at aim.com Mon Jan 26 09:55:01 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Mon, 26 Jan 2009 09:55:01 -0500 Subject: USB in python In-Reply-To: <497D4630.6090405@al.com.au> References: <497D4630.6090405@al.com.au> Message-ID: <497DCEC5.3060208@aim.com> astan.chee at al.com.au wrote: > Tim Roberts wrote: >> Sorry, but you have NOT created a USB device, and I sincerely hope >> you do >> not try to plug it in to a real USB port. >> > Sorry, by USB device, I meant a device that is powered/activated by a > bunch of wires that I want to control using a computer and since I had > a spare USB jack lying around, I used that instead. But so far I > haven't tried it, nor will try it if it wont work properly. Yes, it is > not a proper USB device, because I didnt build it to specifically > interface with the USB port; but I had to start somewhere. Also, the > device requires more power than the standard parallel port can give. > Anyway, it looks like the easiest solution for my case is a > microcontroller > -- > http://mail.python.org/mailman/listinfo/python-list I've played around in this area a little bit. Microcontrollers still require hardware programming and for simple circuits I think it is overkill. If you want to use USB then you may be able to use the FTDI chips. They have both serial (FT232) and parallel (FT245) chips and are quite cheap. They are surface mount devices though, but you can get a kit that includes USB port, the chip already connected to a board with a DIP plug and some essential circuits. libftdi, which runs on top of libusb, can control both of these and they require no programming (unless you want to change the USB configuration settings such as vendor ID, etc, from the default value) This is the FT245 chip which is basically USB-to-Parallel. Chips: http://www.ftdichip.com/Products/FT245R.htm Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm The spec sheet for the board seems quite simple. It's pin out is similar to that of a parallel port in that you have your data lines DB0-DB7, etc. It can also be connected in bus-powered configuration (~100mA) or self-powered configuration. The kit is more expensive than the chip itself, but probably easier especially if you don't have any experience with surface mount. You could build it into your device. You could also create a simple switch box out of it to control external devices, maybe connecting each of the data lines to relays to turn on/off eight devices, etc. Brian Vanderburg II From geekmail at usenot.de Mon Jan 26 10:10:11 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 16:10:11 +0100 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> Message-ID: <20090126161011.482e66f9@usenot.de> On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch wrote: > On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > > > content = a.readlines() > > > > (Just because we can now write "for line in file" doesn't mean that > > readlines() is *totally* redundant.) > > But ``content = list(a)`` is shorter. :-) > But much less clear, wouldn't you say? content is now what? A list of lines? Characters? Bytes? I-Nodes? Dates? Granted, it can be inferred from the fact that a file is its own iterator over its lines, but that is a mental step that readlines() frees you from doing. My ~0.0154 ?. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From ivanov.maxim at gmail.com Mon Jan 26 10:22:25 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Mon, 26 Jan 2009 07:22:25 -0800 (PST) Subject: really slow gzip decompress, why? Message-ID: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> I've one big (6.9 Gb) .gz file with text inside it. zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds python code have been doing the same job for 25 minutes and still doesn't finish =( the code is simpliest I could ever imagine: def main(): fh = gzip.open(sys.argv[1]) all(fh) As far as I understand most of the time it executes C code, so pythons no overhead should be noticible. Why is it so slow? From jcd at sdf.lonestar.org Mon Jan 26 10:35:39 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 10:35:39 -0500 Subject: Newby: how to transform text into lines of text In-Reply-To: <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> Message-ID: <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: > On Jan 26, 1:03 pm, "Gabriel Genellina" > wrote: > > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase > > escribi?: > > > > > > > > > Unfortunately, a raw rstrip() eats other whitespace that may be > > > important. I frequently get tab-delimited files, using the following > > > pseudo-code: > > > > > def clean_line(line): > > > return line.rstrip('\r\n').split('\t') > > > > > f = file('customer_x.txt') > > > headers = clean_line(f.next()) > > > for line in f: > > > field1, field2, field3 = clean_line(line) > > > do_stuff() > > > > > if field3 is empty in the source-file, using rstrip(None) as you suggest > > > triggers errors on the tuple assignment because it eats the tab that > > > defined it. > > > > > I suppose if I were really smart, I'd dig a little deeper in the CSV > > > module to sniff out the "right" way to parse tab-delimited files. > > > > It's so easy that don't doing that is just inexcusable lazyness :) > > Your own example, written using the csv module: > > > > import csv > > > > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') > > headers = f.next() > > for line in f: > > field1, field2, field3 = line > > do_stuff() > > > > And where in all of that do you recommend that .decode(some_encoding) > be inserted? > If encoding is an issue for your application, then I'd recommend you use codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() > -- > http://mail.python.org/mailman/listinfo/python-list > From http Mon Jan 26 10:39:59 2009 From: http (Paul Rubin) Date: 26 Jan 2009 07:39:59 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: <7xzlhers8g.fsf@ruckus.brouhaha.com> Steve Holden writes: > Quite. Python is a language "for consenting adults". Shouldn't such a language allow consenting adults to enter a BDSM scene without being moralized at, if that's what they want to do? ;-) From robin at reportlab.com Mon Jan 26 10:45:25 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jan 2009 15:45:25 +0000 Subject: strange error whilst porting to 2.6 In-Reply-To: <497DBA69.8030201@chamonix.reportlab.co.uk> References: <497A4A00.9060303@jessikat.plus.net> <497A7637.2030405@jessikat.plus.net> <497AE1F8.5040008@jessikat.plus.net> <497DBA69.8030201@chamonix.reportlab.co.uk> Message-ID: <497DDA95.8070106@chamonix.reportlab.co.uk> Robin Becker wrote: > I found that this error > >> Exception RuntimeError: 'maximum recursion depth exceeded in >> __subclasscheck__' in ignored > > occurs when attempting to copy (copy.copy(inst)) an instance of a class > that looks like this > > class LazyParagraph(_LazyMixin,TTParagraph): > SUPER=TTParagraph > _CLEAN_SPACE=1 ........ > > I have attempted to abstract the problem, but so far I haven't found the > vital bits. OK this turns out to be one of those useful exercises after all. After instrumenting the copy instance copy func my colleague and I found the problem occurs in this innocuous looking example ################### import copy class _LazyMixin: """don't do any initialization until later""" def __init__(self,*args): self._args = args self._initialized = 0 def __getattr__(self,a): if not self._initialized: self._Initialize() return getattr(self,a) raise AttributeError("No attribute '%s'" % a) def _Initialize(self): if not self._initialized: self._initialized = 1 del self._args l=_LazyMixin() print l._initialized copy.debug=1 copy.copy(l) ################### it turns out that in the absence of other info _copy_inst creates a dummy instance and changes its class to the incoming class. It then asks the new unpopulated instance if it has an attribute __setstate__, that triggers the _LazyMixin __getattr__ which fails because there's no _initialize member so __getattr__ gets recalled etc etc. Presumably in earlier pythons this bad behaviour is just hidden. The fix for us is to provide a __setstate__ which does what the no __setstate__ code does ie update __dict__. However, since the _copy_inst code knows there can be no members on the new instance should it not be asking the __class__ for __setstate__? -- Robin Becker From deets at nospam.web.de Mon Jan 26 10:47:03 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 26 Jan 2009 16:47:03 +0100 Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: <6u647nFbor76U1@mid.uni-berlin.de> redbaron wrote: > I've one big (6.9 Gb) .gz file with text inside it. > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > python code have been doing the same job for 25 minutes and still > doesn't finish =( the code is simpliest I could ever imagine: > > def main(): > fh = gzip.open(sys.argv[1]) > all(fh) > > As far as I understand most of the time it executes C code, so pythons > no overhead should be noticible. Why is it so slow? I'm guessing here - but if gzip streams (and AFAIK it does), the commandline will simply stream to /dev/null. OTOH, python is not streaming, it will instead allocate buffers for the whole file. Which for a *zipped* 6.9Gb file might take a while. Diez From jay.amorin at gmail.com Mon Jan 26 10:51:02 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Mon, 26 Jan 2009 23:51:02 +0800 Subject: AttributeError: 'module' object has no attribute 'open_workbook' Message-ID: Hi, Kindly help, I've got this error when running my script: AttributeError: 'module' object has no attribute 'open_workbook' Here's my code: #!/usr/bin/python import xlrd import sys mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) firstSheet = wb.sheet_by_index(0) for myRows in range(sh.nrows): print firstSheet.row_values(myRows) Here's the error message: root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls Traceback (most recent call last): File "./xlrd.py", line 3, in import xlrd File "/home/jayam/project/xlrd.py", line 6, in mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) AttributeError: 'module' object has no attribute 'open_workbook' Thanks, Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at jmcneil.net Mon Jan 26 10:51:42 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 26 Jan 2009 07:51:42 -0800 (PST) Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: On Jan 26, 10:22 am, redbaron wrote: > I've one big (6.9 Gb) .gz file with text inside it. > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > python code have been doing the same job for 25 minutes and still > doesn't finish =( the code is simpliest I could ever imagine: > > def main(): > fh = gzip.open(sys.argv[1]) > all(fh) > > As far as I understand most of the time it executes C code, so pythons > no overhead should be noticible. Why is it so slow? Look what's happening in both operations. The zcat operation is simply uncompressing your data and dumping directly to /dev/null. Nothing is done with the data as it's uncompressed. On the other hand, when you call 'all(fh)', you're iterating through every element in in bigfile.gz. In other words, you're reading the file and scanning it for newlines versus simply running the decompression operation. From jeff at jmcneil.net Mon Jan 26 11:02:55 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 26 Jan 2009 08:02:55 -0800 (PST) Subject: really slow gzip decompress, why? References: <5ca3ccea-c2f3-4c57-aa93-f38cee5453d9@w24g2000prd.googlegroups.com> Message-ID: <0fee268a-e6af-4ede-94a9-86b7408628cf@q30g2000prq.googlegroups.com> On Jan 26, 10:51 am, Jeff McNeil wrote: > On Jan 26, 10:22 am, redbaron wrote: > > > I've one big (6.9 Gb) .gz file with text inside it. > > zcat bigfile.gz > /dev/null does the job in 4 minutes 50 seconds > > > python code have been doing the same job for 25 minutes and still > > doesn't finish =( the code is simpliest I could ever imagine: > > > def main(): > > fh = gzip.open(sys.argv[1]) > > all(fh) > > > As far as I understand most of the time it executes C code, so pythons > > no overhead should be noticible. Why is it so slow? > > Look what's happening in both operations. The zcat operation is simply > uncompressing your data and dumping directly to /dev/null. Nothing is > done with the data as it's uncompressed. > > On the other hand, when you call 'all(fh)', you're iterating through > every element in in bigfile.gz. In other words, you're reading the > file and scanning it for newlines versus simply running the > decompression operation. The File: ---------------------------------------------------- [jeff at marvin ~]$ ls -alh junk.gz -rw-rw-r-- 1 jeff jeff 113M 2009-01-26 10:42 junk.gz [jeff at marvin ~]$ The 'zcat' time: ---------------------------------------------------- [jeff at marvin ~]$ time zcat junk.gz > /dev/null real 0m2.390s user 0m2.296s sys 0m0.093s [jeff at marvin ~]$ Test Script #1: ---------------------------------------------------- import sys import gzip fs = gzip.open('junk.gz') data = fs.read(8192) while data: sys.stdout.write(data) data = fs.read(8192) Test Script #1 Time: ---------------------------------------------------- [jeff at marvin ~]$ time python test9.py >/dev/null real 0m3.681s user 0m3.201s sys 0m0.478s [jeff at marvin ~]$ Test Script #2: ---------------------------------------------------- import sys import gzip fs = gzip.open('junk.gz') all(fs) Test Script #2 Time: ---------------------------------------------------- [jeff at marvin ~]$ time python test10.py real 1m51.764s user 1m51.475s sys 0m0.245s [jeff at marvin ~]$ From Jan.Koprowski at gmail.com Mon Jan 26 11:05:17 2009 From: Jan.Koprowski at gmail.com (Jan Koprowski) Date: Mon, 26 Jan 2009 08:05:17 -0800 (PST) Subject: Problem with Nose testing until forking process Message-ID: Hi ! I write application witch sometimes need fork to shell based process (some kind of shell command). I snatch stdin, stdout, stderr and two additional streams and fork process to run command and get results. # -*- encoding: utf-8 -*- import os import sys import subprocess def pipes_function(): global login_r, login_w, password_r, password_w try: os.fdopen(3).close() except OSError: pass try: os.fdopen(4).close() except OSError: pass os.close(login_w) os.close(password_w) os.dup2(login_r, 3) os.dup2(password_r, 4) class BrokerProcess: __slots__ = ['username', 'password', 'command', 'stdout', 'stderr', 'returned'] def run(self): global login_r, login_w, password_r, password_w login_r, login_w = os.pipe() password_r, password_w = os.pipe() wrapper = subprocess.Popen(args=('/usr/bin/special/wrapper'), preexec_fn=pipes_function, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.close(login_r) os.close(password_r) login_w = os.fdopen(login_w, 'w') password_w = os.fdopen(password_w, 'w') login_w.write(self.username) login_w.close() password_w.write(self.password) password_w.close() self.command = self.command.encode() wrapper.stdin.write(self.command) wrapper.stdin.close() self.stdout = wrapper.stdout.read() self.stderr = wrapper.stderr.read() self.returned = wrapper.wait() return self.returned My problem is that when I run nose test for function witch use this broker i get followin errors (I test Pylons app): File "/home/users/matrix/johny/Pylons/zhradmin/zhradmin2/zhradmin2/ controllers/account.py", line 51, in login account.login() File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/model/ account.py", line 29, in login File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/lib/ brokerprocess.py", line 41, in run File "/usr/local/lib/python2.5/subprocess.py", line 594, in __init__ errread, errwrite) File "/usr/local/lib/python2.5/subprocess.py", line 1091, in _execute_child raise child_exception OSError: [Errno 9] Bad file descriptor Is anyone know why I get error ? From google at mrabarnett.plus.com Mon Jan 26 11:07:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 26 Jan 2009 16:07:39 +0000 Subject: AttributeError: 'module' object has no attribute 'open_workbook' In-Reply-To: References: Message-ID: <497DDFCB.7060905@mrabarnett.plus.com> Jay Jesus Amorin wrote: > Hi, > > Kindly help, I've got this error when running my script: > > AttributeError: 'module' object has no attribute 'open_workbook' > > > Here's my code: > > #!/usr/bin/python > > import xlrd > import sys > > mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) > firstSheet = wb.sheet_by_index(0) > > for myRows in range(sh.nrows): > print firstSheet.row_values(myRows) > > > Here's the error message: > > root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls > Traceback (most recent call last): > File "./xlrd.py", line 3, in > import xlrd > File "/home/jayam/project/xlrd.py", line 6, in > mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) > AttributeError: 'module' object has no attribute 'open_workbook' > From the traceback it looks like your script is called "xlrd.py", which is the same name as the module "xlrd" that it's importing. If that's the case, rename your script. From digitig at gmail.com Mon Jan 26 11:09:08 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 26 Jan 2009 16:09:08 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhers8g.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <7xzlhers8g.fsf@ruckus.brouhaha.com> Message-ID: 2009/1/26 Paul Rubin <"http://phr.cx"@nospam.invalid>: > Steve Holden writes: >> Quite. Python is a language "for consenting adults". > > Shouldn't such a language allow consenting adults to enter a BDSM > scene without being moralized at, if that's what they want to do? ;-) The language doesn't stop you. You can shift all of your code over to Ada if you want to, and although /some/ Pythonistas might shake their heads in bewilderment, I don't think there would be any moralising. The question is whether Python has to /provide/ the BDSM scene for you. I don't think it's realistic for a language to provide every possible degree of BDSM from BCPL to Ada, Eiffel and beyond. A language has to be positioned somewhere on the scale, and deciding whether that's the right point on the scale for you and your project is part of what being a grown-up programmer is about. One size does not fit all, one language is not ideal for all applications. -- Tim Rowe From steve at holdenweb.com Mon Jan 26 11:10:31 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 11:10:31 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xzlhers8g.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <7xzlhers8g.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Steve Holden writes: >> Quite. Python is a language "for consenting adults". > > Shouldn't such a language allow consenting adults to enter a BDSM > scene without being moralized at, if that's what they want to do? ;-) Yes, but you know what moralizers are like ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jldunn2000 at googlemail.com Mon Jan 26 11:11:43 2009 From: jldunn2000 at googlemail.com (loial) Date: Mon, 26 Jan 2009 08:11:43 -0800 (PST) Subject: Web services Message-ID: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> I am trying to learn about web services and how to interface with a 3rd party web service from python. Can anyone point me at an idiots guide/tutorial for someone who is new to web services? From jcd at sdf.lonestar.org Mon Jan 26 11:11:58 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 11:11:58 -0500 Subject: I'm a python addict ! In-Reply-To: <87pri9y9hh.fsf@agentultra.com> References: <87pri9y9hh.fsf@agentultra.com> Message-ID: <1232986318.3693.17.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 14:43 -0800, J Kenneth King wrote: > Linuxguy123 writes: > > > I just started using python last week and I'm addicted. > > > > I hate Perl. I never did learn to use it with any competence. I has to > > be the most obfuscated, cryptic language I've ever seen. Making it > > "object oriented" only makes it worse ! > > .. .. > > I program full-time in Python, so I share your excitement and > enthusiasm. But bashing Perl like that doesn't make you sound very > smart. I'm probably one of the very few Python programmers who came from > (and still occassionally) use Perl. Really? I think many many python programmers cut their teeth on Perl. I for one. I loved programming in it when I did, but I hate having to try to understand OPP. Now, when I deal with Perl, it's mostly legacy code, and it's a miserable experience. > I've written non-trivial programs in > it and from my experience I can tell you that it's actually a great > language. The Moose object system is well beyond Python's class > system. But I guess you wouldn't know that. > > So yay for Python, but don't get in the habit of criticising that which > you do not know. There are legitimate reasons to criticize things even when they are powerful. Cheers, Cliff From mail at anjanesh.net Mon Jan 26 11:31:21 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 26 Jan 2009 22:01:21 +0530 Subject: Method returning an Iterable Object Message-ID: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> Is there a way to return an iterable object ? class twoTimes: def __init__(self, n): self.__n = n def getNext(): self.__n *= 2 return self.__n t = twoTimes(5) while (n in t.getNext()): # while (n in t): print (n) -- Anjanesh Lekshmnarayanan From steve at holdenweb.com Mon Jan 26 11:44:01 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 11:44:01 -0500 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> References: <1a7951080901260831w1f596e7doe4527a4fbe143fb9@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > Is there a way to return an iterable object ? > > class twoTimes: > def __init__(self, n): > self.__n = n > > def getNext(): > self.__n *= 2 > return self.__n > > > t = twoTimes(5) > while (n in t.getNext()): # while (n in t): > print (n) > Sure: class EveryOther: def __init__(self, seq): self.seq = seq self.idx = 0 def next(self): self.idx += 1 if self.idx >= len(self.seq): raise StopIteration value = self.seq[self.idx] self.idx += 1 return value def __iter__(self): return self print [x for x in EveryOther(range(10)) [1, 3, 5, 7, 9] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jcd at sdf.lonestar.org Mon Jan 26 11:54:10 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 11:54:10 -0500 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: <1232988850.3835.1.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > Want to change the type/behavior of an object from class A to class > B? How about this: > > aobj = A() > aobj.__class__ = B > > Try *that* in as simple-looking C++ or Java! Wow. That looks very powerful and fun. But scary. Any thoughts on how you would use that in a way that wouldn't unleash sulphurous code smells? Cheers, Cliff From geekmail at usenot.de Mon Jan 26 12:01:52 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 18:01:52 +0100 Subject: Method returning an Iterable Object References: Message-ID: <20090126180152.4a37d03f@usenot.de> On Mon, 26 Jan 2009 22:01:21 +0530 Anjanesh Lekshminarayanan wrote: > Is there a way to return an iterable object ? > > class twoTimes: > def __init__(self, n): > self.__n = n > > def getNext(): > self.__n *= 2 > return self.__n > > Rename getNext() to next() and create another method named __iter__() that just returns self. TwoTimes is now an iterator. You can also replace the whole class with a function thusly: def two_times(n): for k in itertools.count(1): yield n * (2**k) This function is then called a generator (because it generates an iterator). You can now say infinitely_doubling_numbers = two_times(2) for number in in infinitely_doubling_numbers: print number to the same effect as the iterator version above. python.org seems uncooperative at the moment, but look up iterators or the iterator protocol and generators if it works for you. > t = twoTimes(5) > while (n in t.getNext()): # while (n in t): > print (n) > You are aware that this is an infinite loop, as is my example above BTW? (Probably just an example, but I ask just in case.) Also, could it be that you mean "for n in t"? regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From invalid at invalid Mon Jan 26 12:08:48 2009 From: invalid at invalid (Grant Edwards) Date: Mon, 26 Jan 2009 11:08:48 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On 2009-01-26, Lie Ryan wrote: > How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > Hardware Experience). High pitched sound (or anything in sound-ology that > means high voltage) means the device is on and low pitched sound off. 1) Pitch has nothing to do with voltage. A high-pitch sound and a low pitch sound can have the exact same voltage. 2) The OP's device requires quite a bit of power. There is almost no power available from the line-out jack, and the voltage is limited to about 1V. If his sound card has a power-amp (none do these days), he might be able to get a usable amount of power. > The device will need an additional transistor to separate low > voltage from the high voltage. He'll need more than a transistor. He needs a power supply, some sort of rectifier/detector, and a comparitor. It would be more interesting to use notch filters to detect different frequencies so that you could have multiple output "bits". > I don't know how much power can be pulled from jack out, Almost none, and what's there is very low voltage. > but for a home brewn device it is still feasible to draw power > from USB and signal from jack out. It would probably be easier to buy a USB-parallel port chip. Then he's got power from the USB bus and something like 14 parallel I/O pins he can control. Alternatively A USB-serial chip will provide 2 outputs and 4 inputs. -- Grant Edwards grante Yow! Not SENSUOUS ... only at "FROLICSOME" ... and in visi.com need of DENTAL WORK ... in PAIN!!! From bruno.42.desthuilliers at websiteburo.invalid Mon Jan 26 12:10:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jan 2009 18:10:49 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <018aecb2$0$20629$c3e8da3@news.astraweb.com> <1f12c424-81d0-455c-9fac-170f7722eb0a@g39g2000pri.googlegroups.com> <041979a1-43a0-4406-9f0a-ac415dd07131@40g2000prx.googlegroups.com> Message-ID: <497dee70$0$27596$426a74cc@news.free.fr> Russ P. a ?crit : (snip) > You are trying to dictate that the library implementer not be allowed > to use enforced access restriction. And, in the larger sense, you are > trying to dictate that access restrictions not be enforced in Python. FWIW, it's actually *you* who are trying to dictate that access restrictions should be enforced in Python. From notvalid2 at sbcglobal.net Mon Jan 26 12:15:40 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Mon, 26 Jan 2009 09:15:40 -0800 Subject: What is intvar? [Python Docs] In-Reply-To: <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> Message-ID: r wrote: > W. eWatson, > > I contacted the author of New Mexico Techs "Introduction to Tkinter" a > couple of weeks ago. He is going to update the reference material with > a few missing widgets and some info on Photo and Bitmap classes. I > really love the NMT layout and use it quite often. Fredricks > Tkinterbook is more detail but lacking in navigation. I swing back and > forth between both sites. > > > > Good. Thanks. I think Lundh might have taken his material to book form. I might be repeating myself here, but If anyone has pdf experience, and could provide page numbers and maybe a TOC for some of Lundh's contributions, that would be helpful. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:30:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:30:06 -0200 Subject: Python C API (PyObject_CallMethod clear object) References: <6691164d-0bc3-477c-8611-9d825cee37b4@i20g2000prf.googlegroups.com> Message-ID: En Mon, 26 Jan 2009 08:47:31 -0200, escribi?: > On 26 Jan., 03:25, "Gabriel Genellina" wrote: >> En Sun, 25 Jan 2009 23:46:01 -0200, >> escribi?: >> >> > I have a problm with deallocating stuff. I call a function with this >> > command: >> >> > PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL); >> >> > if(rvalue==NULL) >> > ? ? PyErr_Print(); >> > else >> > ? ? Py_DECREF(rvalue); > > Yes, you are right. I got this issue not in syntax error, I get it on > a runtime error like this: > > t = MyImage() > self.test("hallo") #test takes an integer so this would throw an > exception. > > Here you see, an object of the type MyImage() was created but its not > deleted. 't' is a local reference so how can I do that? It will be deleted after the last reference to it is released, as every object in Python. If the above two lines are the whole function code, this will happen when exiting the function. If some other object holds a reference to this MyImage instance (by example, by doing xxx.attribute = t, or inserting it in a list) then that won't happen until all those references are released. Note that, in Python 2.x, the traceback object holds a reference to all local variables -- if you store the traceback somewhere, those objects won't be deleted. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:36:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:36:35 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> Message-ID: En Mon, 26 Jan 2009 13:35:39 -0200, J. Cliff Dyer escribi?: > On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: >> On Jan 26, 1:03 pm, "Gabriel Genellina" >> wrote: >> > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase >> > escribi?: >> > > I suppose if I were really smart, I'd dig a little deeper in the CSV >> > > module to sniff out the "right" way to parse tab-delimited files. >> > >> > It's so easy that don't doing that is just inexcusable lazyness :) >> > Your own example, written using the csv module: >> > >> > import csv >> > >> > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> > headers = f.next() >> > for line in f: >> > field1, field2, field3 = line >> > do_stuff() >> > >> >> And where in all of that do you recommend that .decode(some_encoding) >> be inserted? > > If encoding is an issue for your application, then I'd recommend you use > codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() This would be the best way *if* the csv module could handle Unicode input, but unfortunately this is not the case. See my other reply. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jan 26 12:36:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 26 Jan 2009 15:36:36 -0200 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <53d19377-e4f5-4802-8f24-813605f0a9d8@q30g2000prq.googlegroups.com> <497CF6FA.3030000@tim.thechases.com> <497D1239.4070202@tim.thechases.com> <96a3e926-89ca-44f0-97a9-6098a6c1a10b@z28g2000prd.googlegroups.com> <1232984139.3693.13.camel@aalcdl07.lib.unc.edu> Message-ID: En Mon, 26 Jan 2009 13:35:39 -0200, J. Cliff Dyer escribi?: > On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: >> On Jan 26, 1:03 pm, "Gabriel Genellina" >> wrote: >> > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase >> > escribi?: >> > > I suppose if I were really smart, I'd dig a little deeper in the CSV >> > > module to sniff out the "right" way to parse tab-delimited files. >> > >> > It's so easy that don't doing that is just inexcusable lazyness :) >> > Your own example, written using the csv module: >> > >> > import csv >> > >> > f = csv.reader(open('customer_x.txt','rb'), delimiter='\t') >> > headers = f.next() >> > for line in f: >> > field1, field2, field3 = line >> > do_stuff() >> > >> >> And where in all of that do you recommend that .decode(some_encoding) >> be inserted? > > If encoding is an issue for your application, then I'd recommend you use > codecs.open('customer_x.txt', 'rb', encoding='ebcdic') instead of open() This would be the best way *if* the csv module could handle Unicode input, but unfortunately this is not the case. See my other reply. -- Gabriel Genellina From clp2 at rebertia.com Mon Jan 26 12:50:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jan 2009 09:50:55 -0800 Subject: Web services In-Reply-To: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> References: <43858e57-9b4c-4e83-af23-78f82c6c0ac0@v18g2000pro.googlegroups.com> Message-ID: <50697b2c0901260950q1a52a4d0g901019e7ca2824ff@mail.gmail.com> On Mon, Jan 26, 2009 at 8:11 AM, loial wrote: > I am trying to learn about web services and how to interface with a > 3rd party web service from python. > > Can anyone point me at an idiots guide/tutorial for someone who is new > to web services? The XML-RPC client module in the std lib (xmlrpclib) includes an example: http://docs.python.org/library/xmlrpclib.html#example-of-client-usage And the XML-RPC server server in the stdlib also includes a full client-server example: http://docs.python.org/library/simplexmlrpcserver.html#simplexmlrpcserver-example Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ptmcg at austin.rr.com Mon Jan 26 12:52:01 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 26 Jan 2009 09:52:01 -0800 (PST) Subject: I'm a python addict ! References: Message-ID: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> On Jan 26, 10:54?am, "J. Cliff Dyer" wrote: > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > Want to change the type/behavior of an object from class A to class > > B? ?How about this: > > > ? ? aobj = A() > > ? ? aobj.__class__ = B > > > Try *that* in as simple-looking C++ or Java! > > Wow. ?That looks very powerful and fun. ?But scary. ?Any thoughts on how > you would use that in a way that wouldn't unleash sulphurous code > smells? > This technique is perfect for implementing the GoF State pattern. In the State pattern, you implement behavior for an object's various states using one of several interchangeable classes. The classes are "interchangeable" in that they all implement a common interface. Here is my favorite State pattern example, a traffic light: import time class TrafficLight(object): pass class RedLight(TrafficLight): cars_can_go = False pedestrians_can_cross = True color = (255,0,0) duration = 20 class YellowLight(TrafficLight): cars_can_go = True pedestrians_can_cross = False color = (255,255,0) duration = 5 class GreenLight(TrafficLight): cars_can_go = True pedestrians_can_cross = False color = (0,255,0) duration = 15 # now add in next_state class vars for state transitions RedLight.next_state = GreenLight YellowLight.next_state = RedLight GreenLight.next_state = YellowLight TrafficLight.initial_state = RedLight # run a traffic light for a while... can_they = lambda cond : ("can't","can")[cond] light = TrafficLight.initial_state() while 1: print light.__class__.__name__ print "waiting for", light.duration, "seconds" print "Cars", can_they(light.cars_can_go), "go" print "People", can_they(light.pedestrians_can_cross), "cross" print time.sleep(light.duration) # how you have to do it in C++ and Java # light = light.next_state() # using Python light.__class__ = light.next_state Gives this output: RedLight waiting for 20 seconds Cars can't go People can cross GreenLight waiting for 15 seconds Cars can go People can't cross YellowLight waiting for 5 seconds Cars can't go People can't cross RedLight waiting for 20 seconds Cars can't go People can cross ... and so on ... In Python, the base TrafficLight class isn't even necessary ("don't need no stinking interfaces!"), although it is a good place to define default behavior, and it helps tie together the other classes from a self-documentation standpoint. But any class that has the necessary attributes would suffice, whether it inherits from TrafficLight or not. class HoldForEmergencyVehiclesLight(object): cars_can_go = False pedestrians_can_cross = False color = (255,0,0) -- Paul From gil.shinar at gmail.com Mon Jan 26 13:13:54 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Mon, 26 Jan 2009 10:13:54 -0800 (PST) Subject: Process crash with no reason Message-ID: Hi All, I'm running a program that is acting as a nice interface to sybase' replication server. The program is using the cherrypy web service for the GUI. The process is crashing every few days with no reason. In the log I can see INFO and DEBUG (No ERROR) log lines and I do not get any TraceBack python's message. This program is running on solaris 9 machine. Where can I see or what can I do in order to find out what causes the process to crash? I have tried simulating a "traceBack" message and I could see this traceback message in one of the log files I'm using. When the process crashes without my help, I don't have a clue. Let me know if you need any other info Thanks Gil From kay.schluehr at gmx.net Mon Jan 26 13:14:05 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Mon, 26 Jan 2009 10:14:05 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <790bc782-b49b-4a46-a50e-f190203d8efc@i24g2000prf.googlegroups.com> On 26 Jan., 15:13, Steve Holden wrote: > Mark Wooding wrote: > > unine... at gmail.com writes: > [...] > > * Assignment stores a new (reference to a) value in the variable. > > > * Binding modifies the mapping between names and variables. > > I realise I have omitted what was doubtless intended to be explanatory > detail, but I am having trouble reconciling those sentences. Would you > mind explaining "in vacuuo" what you see as the difference between > assignment and binding? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ "Assignment" is binding values to names whereas "binding" is binding names to scopes. Marks terminology is a bit more standard than Pythons in this respect. As you know, Python avoids the idea of variables as if those were storage cells having a fixed logical address. From jef.mangelschots at gmail.com Mon Jan 26 13:16:28 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 10:16:28 -0800 (PST) Subject: unable to print Unicode characters in Python 3 Message-ID: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Hi, while checking out Python 3, I read that all text strings are now natively Unicode. In the Python language reference (http://docs.python.org/3.0/reference/ lexical_analysis.html) I read that I can show Unicode character in several ways. "\uxxxx" supposedly allows me to specify the Unicode character by hex number and the format "\N{name}" allows me to specify by Unicode name. Neither seem to work for me. What am I doing wrong ? Please see error output below where I am trying to show the EURO sign (http://www.fileformat.info/info/unicode/char/20ac/index.htm): Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print('\u20ac') Traceback (most recent call last): File "", line 1, in File "c:\python30\lib\io.py", line 1491, in write b = encoder.encode(s) File "c:\python30\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in position 0: character maps to >>> >>> print ("\N{EURO SIGN}") Traceback (most recent call last): File "", line 1, in File "c:\python30\lib\io.py", line 1491, in write b = encoder.encode(s) File "c:\python30\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in position 0: character maps to From mail at anjanesh.net Mon Jan 26 13:35:53 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 27 Jan 2009 00:05:53 +0530 Subject: Method returning an Iterable Object In-Reply-To: <20090126180152.4a37d03f@usenot.de> References: <20090126180152.4a37d03f@usenot.de> Message-ID: <1a7951080901261035i1f8ae3dds1baa22d313e44ae7@mail.gmail.com> > You can also replace the whole class with a function thusly: > > def two_times(n): > for k in itertools.count(1): > yield n * (2**k) > > This function is then called a generator (because it generates an > iterator). You can now say > > infinitely_doubling_numbers = two_times(2) > for number in in infinitely_doubling_numbers: > print number Oh..this is new. Will checkup itertools. Thanks. >> t = twoTimes(5) >> while (n in t.getNext()): # while (n in t): >> print (n) >> > You are aware that this is an infinite loop, as is my example above BTW? > (Probably just an example, but I ask just in case.) I was aware this was an infinite loop - just didnt want to put more code for an example. From martin at marcher.name Mon Jan 26 13:36:33 2009 From: martin at marcher.name (Martin) Date: Mon, 26 Jan 2009 19:36:33 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <5fa6c12e0901261036v7a300832pa848a254b664b477@mail.gmail.com> Hmm this works for me, it's a self compiled version: ~ $ python3 Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print("\u20ac") ? >>> print ("\N{EURO SIGN}") ? >>> 2009/1/26 jefm : > What am I doing wrong ? "\N{EURO SIGN}".encode("ISO-8859-15") ## could be something but I'm pretty sure I'm totally wrong on this -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From philip at semanchuk.com Mon Jan 26 13:40:59 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 26 Jan 2009 13:40:59 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: <11A88827-A885-43C8-98A1-6AD969DC1424@semanchuk.com> On Jan 26, 2009, at 1:13 PM, gil.shinar at gmail.com wrote: > Hi All, > > I'm running a program that is acting as a nice interface to sybase' > replication server. The program is using the cherrypy web service for > the GUI. The process is crashing every few days with no reason. In the > log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > TraceBack python's message. This program is running on solaris 9 > machine. > Where can I see or what can I do in order to find out what causes the > process to crash? > I have tried simulating a "traceBack" message and I could see this > traceback message in one of the log files I'm using. When the process > crashes without my help, I don't have a clue. > Let me know if you need any other info Although Python isn't immune to fatal errors like you describe, I'd immediately suspect a 3rd-party module instead, esp. one written in C or C++. Are you using anything like that? From benjamin.kaplan at case.edu Mon Jan 26 13:44:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 13:44:35 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: On Mon, Jan 26, 2009 at 1:16 PM, jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) > I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format "\N{name}" allows me to specify by Unicode > name. > Neither seem to work for me. > What am I doing wrong ? > > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print('\u20ac') > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > >>> > >>> print ("\N{EURO SIGN}") > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > -- > The strings are represented internally as Unicode, but you can't print them that way. When you call print(), python needs to turn your string into a sequence of bytes that are then interpreted by the terminal (in your case cmd.exe). On modern Unix-based systems (like Mac and Linux), the console uses UTF-8. Since it uses a unicode-based encoding, everything prints fine. Your Windows machine seems determined to use the old (c. 1980s) CP 437. Code Page 437 doesn't have the Euro symbol, so python throws an error. Try using "\N{EURO SIGN}".encode("cp1252"). If your console still can't handle it, you'll need to change its encoding. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik.kant at gmail.com Mon Jan 26 13:49:24 2009 From: fredrik.kant at gmail.com (fredrik kant) Date: Mon, 26 Jan 2009 19:49:24 +0100 Subject: Python and CUDO Message-ID: <415a7e520901261049s7c5502e7heb835ff6e0918f7f@mail.gmail.com> Hi! Sorry about the misspelling, it should of course been "NIVIDAS CUDA". I also noticed that there wrappers around such as: pycuda which answers my question. -- Fredrik Kant Kant Consulting AB Mobile: +46 70 787 06 01 www.kantconsulting.se -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmohr at s.netic.de Mon Jan 26 14:06:20 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Mon, 26 Jan 2009 20:06:20 +0100 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: Hello, >> Basically, this here works but gives a warning: >> RuntimeWarning: Parent module 'ext_abc' not found while handling >> absolute import > > >> here = os.path.abspath('.') > > (Unrelated to the main question, but you probably want to use > os.path.dirname(os.path.abspath(__file__)) instead - the above just > returns the current directory, which might not be the directory containing > the module) Thanks, i'll try that. >> mpath = os.path.abspath('mymodule') >> epath = os.path.abspath('extension') >> >> sys.path.append(here) >> sys.path.append(mpath) >> >> FILE mymodule/__init__.py: > > So mymodule is actually a package. Packages should *not* appear in > sys.path. Oh, how does it find modules then? I thought that would be PYTHONPATH or sys.path ? Best regards, Torsten. From semanticist at gmail.com Mon Jan 26 14:06:44 2009 From: semanticist at gmail.com (Miles) Date: Mon, 26 Jan 2009 14:06:44 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <6u5cokFdmi22U1@mid.uni-berlin.de> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> <6u48ntFdcm9fU1@mid.uni-berlin.de> <18138131-e810-41f6-9c0b-1edcb0acf00a@g39g2000pri.googlegroups.com> <6u4biqFdhg0iU1@mid.uni-berlin.de> <6u5cokFdmi22U1@mid.uni-berlin.de> Message-ID: On Mon, Jan 26, 2009 at 4:06 AM, Diez B. Roggisch wrote: > There are people who say something along the lines of "be strict when > writing, and tolerant when reading" (the exact quote is different, but > neither google:~site:mybrain nor any other have helped me here) That's Postel's Law: http://en.wikipedia.org/wiki/Robustness_Principle -Miles From jef.mangelschots at gmail.com Mon Jan 26 14:09:05 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 11:09:05 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> >Hmm this works for me, >it's a self compiled version: >~ $ python3 >Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) >[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 You are running on Linux. Mine is on Windows. Anyone else have this issue on Windows ? From Scott.Daniels at Acm.Org Mon Jan 26 14:16:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 26 Jan 2009 11:16:53 -0800 Subject: A java hobbyist programmer learning python In-Reply-To: References: <497281d8$0$9504$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <0182896d$0$8693$c3e8da3@news.astraweb.com> <3759ddbf-77ec-40a3-8cb4-07c626891423@m4g2000vbp.googlegroups.com> Message-ID: Tim Rowe wrote: > ... I like the second style because it makes it leaves the 2-d > implementation hidden, which is the whole point of encapsulation. I like the second as well, in that it it allows the parent to update any related data structures (for example, updating a display). However, I am a bit nervous about changing the signature of the move message, and would be more tempted to add a move3d, for multiple inheritance reasons. >> But then I am a fan of Hungarian notation, which many >> programmers can't stand. > > Is it that programmers can't stand it, or is it that they can't stand > it when it's imposed when not needed? .... Well, I tend to be one who hates Hungarian. I spent a long time being a fan of strong typing. Then, I felt the compiler would enforce the typing, and the Hungarian muddied the readability of the expressions. I felt that you should define a type for distance_in_yards, and not have that confusable with distance_in_meters (though you might provide an automatic conversion. Now, I feel strong-typing systems cannot express the type relationships that I want as a programmer in the face of sub-typing, and I hold no hope that (A) such a language will appear, or (B) that the strong majority of the bugs I produce in Python will be caught by a statically typed system. I do however, still find the neddling little text annotations in the variable naming to be irritating noise that distracts from the readability of the expressions. The kinds of type systems that I want(ed) is most closely expressed by F-Bounded polymorphism, and that doesn't manage to be both expressive enough and computationally feasible to use as a production type system. For example, I'd like to type a sort function or a project function, and all I've seen looks like its fit will feel more like a suit of armor than a shirt. --Scott David Daniels Scott.Daniels at Acm.Org From geekmail at usenot.de Mon Jan 26 14:28:04 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 20:28:04 +0100 Subject: Method returning an Iterable Object References: <20090126180152.4a37d03f@usenot.de> Message-ID: <20090126202804.28c65e90@usenot.de> On Tue, 27 Jan 2009 00:05:53 +0530 Anjanesh Lekshminarayanan wrote: > > You can also replace the whole class with a function thusly: > > > > def two_times(n): > > for k in itertools.count(1): > > yield n * (2**k) > > > > This function is then called a generator (because it generates an > > iterator). You can now say > > > > infinitely_doubling_numbers = two_times(2) > > for number in in infinitely_doubling_numbers: > > print number > > Oh..this is new. Will checkup itertools. Thanks. > OK, happy I could help. But my point was the yield statement (in case you didn't know about yield). regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From Scott.Daniels at Acm.Org Mon Jan 26 14:41:25 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 26 Jan 2009 11:41:25 -0800 Subject: I'm a python addict ! In-Reply-To: References: Message-ID: <9r6dnXezlL4ajOPUnZ2dnUVZ_ozinZ2d@pdx.net> J. Cliff Dyer wrote: > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: >> ... How about this: >> aobj = A() >> aobj.__class__ = B > ... Wow. That looks very powerful and fun. But scary. Any thoughts > on how you would use that in a way that wouldn't unleash sulphurous > code smells? Seems like a nice way to transition between "ActiveAccount": and "InActiveAccount" or some such. The requirement is that the two classes share memory layout (essentially, class type and all __slots__ involved (including __dict__). It is a bit prickly, so I'd personally only start to use it once my methods were littered with lots of: ... if self.active_flag: self.account.update(... else: raise ValueError('Purchase prohibitted') Could also be useful as the stub for a kept-on-disk structure, where all methods on the inactive one rolled in data switched class, and invoked their corresponding method. --Scott David Daniels Scott.Daniels at Acm.Org From rantingrick at gmail.com Mon Jan 26 14:51:54 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jan 2009 11:51:54 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget Message-ID: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> I am wondering how i might pipe stdout && stderr to a Tkinter Label widget. here are a few ways to set the text #-- Create a label --# label = Label(master, text='Default Text') label.pack() # -- two ways to change the text --# label['text'] = 'New Text' label.configure(text='New Text') #-- or use a control variable --# v = StringVar(master) label.config(textvariable=v) #-- Change useing variable --# v.set('NewText') So my question is -- I know hoe to set the text displayed in the label wiget, but hoow do i capture stdout and send that to the widget? From jcd at sdf.lonestar.org Mon Jan 26 15:06:18 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 15:06:18 -0500 Subject: I'm a python addict ! In-Reply-To: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <1233000378.4334.6.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 09:52 -0800, Paul McGuire wrote: > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: > > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > > Want to change the type/behavior of an object from class A to class > > > B? How about this: > > > > > aobj = A() > > > aobj.__class__ = B > > > > > Try *that* in as simple-looking C++ or Java! > > > > Wow. That looks very powerful and fun. But scary. Any thoughts on how > > you would use that in a way that wouldn't unleash sulphurous code > > smells? > > > > This technique is perfect for implementing the GoF State pattern. > > In the State pattern, you implement behavior for an object's various > states using one of several interchangeable classes. The classes are > "interchangeable" in that they all implement a common interface. Here > is my favorite State pattern example, a traffic light: > > > import time > > class TrafficLight(object): > pass > > class RedLight(TrafficLight): > cars_can_go = False > pedestrians_can_cross = True > color = (255,0,0) > duration = 20 > > class YellowLight(TrafficLight): > cars_can_go = True > pedestrians_can_cross = False > color = (255,255,0) > duration = 5 > > class GreenLight(TrafficLight): > cars_can_go = True > pedestrians_can_cross = False > color = (0,255,0) > duration = 15 > > # now add in next_state class vars for state transitions > RedLight.next_state = GreenLight > YellowLight.next_state = RedLight > GreenLight.next_state = YellowLight > TrafficLight.initial_state = RedLight > > # run a traffic light for a while... > can_they = lambda cond : ("can't","can")[cond] > light = TrafficLight.initial_state() > while 1: > print light.__class__.__name__ > print "waiting for", light.duration, "seconds" > print "Cars", can_they(light.cars_can_go), "go" > print "People", can_they(light.pedestrians_can_cross), "cross" > print > time.sleep(light.duration) > > # how you have to do it in C++ and Java > # light = light.next_state() > > # using Python > light.__class__ = light.next_state > > > Gives this output: > > RedLight > waiting for 20 seconds > Cars can't go > People can cross > > GreenLight > waiting for 15 seconds > Cars can go > People can't cross > > YellowLight > waiting for 5 seconds > Cars can't go > People can't cross > > RedLight > waiting for 20 seconds > Cars can't go > People can cross > > ... and so on ... > > > > In Python, the base TrafficLight class isn't even necessary ("don't > need no stinking interfaces!"), although it is a good place to define > default behavior, and it helps tie together the other classes from a > self-documentation standpoint. But any class that has the necessary > attributes would suffice, whether it inherits from TrafficLight or > not. > > class HoldForEmergencyVehiclesLight(object): > cars_can_go = False > pedestrians_can_cross = False > color = (255,0,0) > > > -- Paul > Thanks. That makes sense. But your example creates a new instance of the new class each time, rather than changing the class of a persistent instance, as the original example, to which I was responding, did. But perhaps something like: class TrafficLight(object): def change_light(self): self.__class__ = next_state and then you can persist information about the light (bulb_type in set(['led', 'incandescent']), last_maintenance_date, location, etc.) on the instance level, unaffected by the changing color. Interesting stuff. Cheers, Cliff From Russ.Paielli at gmail.com Mon Jan 26 15:20:26 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 26 Jan 2009 12:20:26 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> <497d7d40$0$4845$426a34cc@news.free.fr> Message-ID: On Jan 26, 1:07 am, Bruno Desthuilliers wrote: > No. I can change the *team's* code. Please *read*. "team's ownership", > ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get > the message, now ? Team ownership doesn't necessarily mean that you can just change code at will. In industry, teams usually have a leader that you need to check with before you can change an interface. A language with enforced access restriction merely provides language support for such coordination. That was my only point. > > Would you give all those developers your password to get into the > > system? No? Wait a minute ... you mean you wouldn't "trust" them with > > your password? But what about "openness"? Are you some sort of fascist > > or what? > > Goodwin point. You loose. Good bye again, Mr P. You missed the point once again. In asking if you are a "fascist," I was *parodying* your attitude that languages with enforced access restrictions are for "fascists" who don't trust their co-workers or employees. [I don't recall if you actually used that word or if it was someone else, but you did use "B&D", which carries the same general impression.] So I parodied your hyperbole, and you dismiss me for it. Without realizing it, you just dismissed yourself, sir. Thanks for saving me the trouble. From heintest at web.de Mon Jan 26 15:21:01 2009 From: heintest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Mon, 26 Jan 2009 21:21:01 +0100 Subject: Anoying unicode / str conversion problem Message-ID: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Hi python experts, in the moment I'm struggling with an annoying problem in conjunction with mysql. I'm fetching rows from a database, which the mysql drive returns as a list of tuples. The default coding of the database is utf-8. Unfortunately in the database there are rows with different codings and there is a blob column. In the app. I search for double entries in the database with this code. hash = {} cursor.execute("select * from table") rows = cursor.fetchall() for row in rows: key = "|".join([str(x) for x in row]) <- here the problem arises if key in hash: print "found double entry" This code works as expected with python 2.5.2 With 2.5.1 it shows this error: key = "|".join(str(x) for x in row) UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in position 3: ordinal not in range(128) When I replace the str() call by unicode(), I get this error when a blob column is being processed: key = "|".join(unicode(x) for x in row) UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: ordinal not in range(128) Please help, how can I convert ANY column data to a string which is usable as a key to a dictionary. The purpose of using a dictionary is to find equal rows in some database tables. Perhaps using a md5 hash from the column data is also an idea ? Thanks a lot in advance, Hans. From tjreedy at udel.edu Mon Jan 26 15:29:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 15:29:29 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: Steve Holden wrote: > Terry Reedy wrote: >> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >> new and people write >> try: >> False,True >> except NameError: >> False,True = 0,1 >> >> to make code back compatible. >> > I would claim that the ability to rebind True and False is a simple bug, > though one not likely to be fixed in an 2.x release. The code above > doesn't rebind True and False in interpreters that have them ... In pre-bool 2.x, people never wrote the above but sometime wrote False,True = 0,1 To me it is hardly a bug to not gratuitously break substantial amounts of proper code. >> Back before rebinding 'None' was prohibited, 'is None' was not >> completely guaranteed either (absent reading the rest of a file to be >> sure no rebinding would be done). >> > And that was a bug too, in this case one that *was* removed in 2.4, I > believe. Don't have 2.3 lying around just now. Unlike with True and False, the devs could not think of or find any proper use case for rebinding None and judged that the new prohibition would break very little if any code. As far as I know, they were correct. tjr From ptmcg at austin.rr.com Mon Jan 26 15:37:41 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 26 Jan 2009 12:37:41 -0800 (PST) Subject: I'm a python addict ! References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> On Jan 26, 2:06?pm, "J. Cliff Dyer" wrote: > > Thanks. ?That makes sense. ?But your example creates a new instance of > the new class each time, rather than changing the class of a persistent > instance, as the original example, to which I was responding, did. > Look closer. The line that creates a new instance is commented out, with the notation "how you have to do it in C++ and Java". The actual Python code is just below, and just assigns a new class to self.__class__, as in the original example. -- Paul From benjamin.kaplan at case.edu Mon Jan 26 15:40:41 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 15:40:41 -0500 Subject: Anoying unicode / str conversion problem In-Reply-To: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Mon, Jan 26, 2009 at 3:21 PM, Hans M?ller wrote: > Hi python experts, > > in the moment I'm struggling with an annoying problem in conjunction with > mysql. > > I'm fetching rows from a database, which the mysql drive returns as a list > of tuples. > > The default coding of the database is utf-8. > > Unfortunately in the database there are rows with different codings and > there is a blob > column. > > In the app. I search for double entries in the database with this code. > > hash = {} > cursor.execute("select * from table") > rows = cursor.fetchall() > for row in rows: > key = "|".join([str(x) for x in row]) <- here the problem > arises > if key in hash: > print "found double entry" > > This code works as expected with python 2.5.2 > With 2.5.1 it shows this error: > > > key = "|".join(str(x) for x in row) > UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in > position 3: ordinal > not in range(128) > > When I replace the str() call by unicode(), I get this error when a blob > column is being > processed: > > key = "|".join(unicode(x) for x in row) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: > ordinal not in > range(128) > > > Please help, how can I convert ANY column data to a string which is usable > as a key to a > dictionary. The purpose of using a dictionary is to find equal rows in some > database > tables. Perhaps using a md5 hash from the column data is also an idea ? unicode takes an optional encoding argument. If you don't specify, it uses ascii. Try using (untested): key = u"|".join(unicode(x, encoding="utf-8") for x in row) > Thanks a lot in advance, > > Hans. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnewsg at gmail.com Mon Jan 26 15:51:36 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 26 Jan 2009 12:51:36 -0800 (PST) Subject: Monitor a FTP site for arrival of new/updated files References: <1232910590.24534.1296651319@webmail.messagingengine.com> Message-ID: <397de817-d5e2-48bf-88fa-399a67774919@b38g2000prf.googlegroups.com> On 25 Gen, 21:11, Steve Holden wrote: > pyt... at bdurham.com wrote: > > ?Any suggestions on a best practice way to monitor a remote FTP site for > > the arrival of new/updated files? I don't need specific code, just some > > coaching on technique based on your real-world experience including > > suggestions for a utility vs. code based solution. > > > My goal is to maintain a local collection of files synced with a remote > > FTP site and when I download a new/updated file locally, run a script to > > process it. The arrival and format of the files that I need to sync with > > are beyond my control (eliminating a rsync solution) ... all I have is a > > generic FTP connection to a specific FTP address. Note: The remote site > > I'm monitoring may have multiple uploads occuring at the same time. > > > My basic strategy is to poll the remote directory on a regular basis and > > compare the new directory listing to a previous snapshot of the > > directory listing. If a file timestamp or size has changed (or a new > > file has appeared), then track this file as a changed file. Once a file > > has been marked as changed, wait polling cycles for the file > > timestamp and size to remain stable, then download it, and trigger a > > local script to process the file. In addition to detecting new or > > changed files, I would compare remote directory listings to my local > > sync folder and delete local files that no longer exist on the remote site. > > > My concern about using a utility is the utility's ability to detect when > > a remote file has finished being updated. I don't want to download files > > that are still in the process of being updated - I only want to download > > new/updated files after they've been closed on the remote site. > > > Any ideas appreciated! > > Well, the ftpmirror will cope with most of what you want to do as it is, > but I am unsure how you can determine whether a file is in the process > of being written on the server. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/- Nascondi testo citato > > - Mostra testo citato - If you're going to do that manually through a script, and the server supports it, use MLSD instead of LIST command for listing files and determine their last modification time. My 2 cents --- Giampaolo http://code.google.com/p/pyftpdlib From torriem at gmail.com Mon Jan 26 15:53:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 26 Jan 2009 13:53:57 -0700 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <714921c8-872a-4bc8-8fb6-9844fcb2f043@o40g2000prn.googlegroups.com> Message-ID: <497E22E5.4000308@gmail.com> jefm wrote: >> Hmm this works for me, >> it's a self compiled version: >> ~ $ python3 >> Python 3.0 (r30:67503, Dec 29 2008, 21:35:15) >> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > > You are running on Linux. Mine is on Windows. > Anyone else have this issue on Windows ? As Benjamin Kaplin said, Windows terminals use the old cp1252 character set, which cannot display the euro sign. You'll either have to run it in something more modern like the cygwin rxvt terminal, or output some other way, such as through a GUI. From tjreedy at udel.edu Mon Jan 26 15:58:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 15:58:41 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. True > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format "\N{name}" allows me to specify by Unicode > name. These are ways to *specify* unicode chars on input. > Neither seem to work for me. If you separate text creation from text printing, you would see that they do. Try s='\u20ac' print(s) > What am I doing wrong ? Using the interactive interpreter running in a Windows console. > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print('\u20ac') > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to With the standard console, I get the same. But with IDLE, using the same Python build but through a different interface >>> s='\u20ac' >>> len(s) 1 >>> str(s) '?' # euro sign I have fiddled with the shortcut to supposed make it work better as claimed by posts found on the web, but to no avail. Very frustrating since I have fonts on the system for at least all of the first 64K chars. Scream at Microsoft or try to find or encourage a console replacement that Python could use. In the meanwhile, use IDLE. Not perfect for Unicode, but better. Terry Jan Reedy From rantingrick at gmail.com Mon Jan 26 16:03:13 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jan 2009 13:03:13 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget References: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> Message-ID: OK, here is a simple example that will show you what i want to do. Right now if you type print 'hello' in the entry and press you will see braces in the label "{}". But if you type sys.stdou.write ("hello") you will see "{hello}" in the label. So i got the stdout piping to the widget now, but it will not work with the print statement. AND there are those braces around the string??? Any ideas? from Tkinter import * root = Tk() class NewOut(): def write(self, *arg): v.set(arg) saveout = sys.stdout newout = NewOut() sys.stdout = newout e = StringVar(root) entry = Entry(root, textvariable=e, font=('Courier New', 12)) entry.pack(fill=X, expand=1, padx=5, pady=5) v = StringVar(root) Label(textvariable=v).pack(fill=X, expand=1) def onReturn(event): try: exec(e.get()) e.set('') except: print 'Command Invalid' root.bind('', onReturn) entry.focus_set() root.mainloop() From steve at holdenweb.com Mon Jan 26 16:10:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 16:10:02 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <497E26AA.3070206@holdenweb.com> Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: > >>> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >>> new and people write >>> try: >>> False,True >>> except NameError: >>> False,True = 0,1 >>> >>> to make code back compatible. >>> >> I would claim that the ability to rebind True and False is a simple bug, >> though one not likely to be fixed in an 2.x release. The code above >> doesn't rebind True and False in interpreters that have them ... > > In pre-bool 2.x, people never wrote the above but sometime wrote > False,True = 0,1 > Right. This is the use case I overlooked. > To me it is hardly a bug to not gratuitously break substantial amounts > of proper code. > I quite agree. I take it all back! >>> Back before rebinding 'None' was prohibited, 'is None' was not >>> completely guaranteed either (absent reading the rest of a file to be >>> sure no rebinding would be done). >>> >> And that was a bug too, in this case one that *was* removed in 2.4, I >> believe. Don't have 2.3 lying around just now. > > Unlike with True and False, the devs could not think of or find any > proper use case for rebinding None and judged that the new prohibition > would break very little if any code. As far as I know, they were correct. > Indeed they were. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Jan 26 16:10:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 16:10:02 -0500 Subject: is None vs. == None In-Reply-To: References: <5d1a32000901231158m4c169bedu693db94a48ee0ce@mail.gmail.com> <50697b2c0901231202m6adabddla94346a68b56db9c@mail.gmail.com> Message-ID: <497E26AA.3070206@holdenweb.com> Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: > >>> In 2.x, the *names* 'True' and 'False' can be rebound because bool is >>> new and people write >>> try: >>> False,True >>> except NameError: >>> False,True = 0,1 >>> >>> to make code back compatible. >>> >> I would claim that the ability to rebind True and False is a simple bug, >> though one not likely to be fixed in an 2.x release. The code above >> doesn't rebind True and False in interpreters that have them ... > > In pre-bool 2.x, people never wrote the above but sometime wrote > False,True = 0,1 > Right. This is the use case I overlooked. > To me it is hardly a bug to not gratuitously break substantial amounts > of proper code. > I quite agree. I take it all back! >>> Back before rebinding 'None' was prohibited, 'is None' was not >>> completely guaranteed either (absent reading the rest of a file to be >>> sure no rebinding would be done). >>> >> And that was a bug too, in this case one that *was* removed in 2.4, I >> believe. Don't have 2.3 lying around just now. > > Unlike with True and False, the devs could not think of or find any > proper use case for rebinding None and judged that the new prohibition > would break very little if any code. As far as I know, they were correct. > Indeed they were. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Mon Jan 26 16:16:26 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Jan 2009 22:16:26 +0100 Subject: Anoying unicode / str conversion problem References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Hans M?ller wrote: > Hi python experts, > > in the moment I'm struggling with an annoying problem in conjunction with > mysql. > > I'm fetching rows from a database, which the mysql drive returns as a list > of tuples. > > The default coding of the database is utf-8. > > Unfortunately in the database there are rows with different codings and > there is a blob column. > > In the app. I search for double entries in the database with this code. > > hash = {} > cursor.execute("select * from table") > rows = cursor.fetchall() > for row in rows: > key = "|".join([str(x) for x in row]) <- here the problem arises > if key in hash: > print "found double entry" > > This code works as expected with python 2.5.2 > With 2.5.1 it shows this error: > > > key = "|".join(str(x) for x in row) > UnicodeEncodeError: 'ascii' codec can't encode character u'\u017e' in > position 3: ordinal not in range(128) > > When I replace the str() call by unicode(), I get this error when a blob > column is being processed: > > key = "|".join(unicode(x) for x in row) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 119: > ordinal not in range(128) > > > Please help, how can I convert ANY column data to a string which is usable > as a key to a dictionary. The purpose of using a dictionary is to find > equal rows in some database tables. Perhaps using a md5 hash from the > column data is also an idea ? > > Thanks a lot in advance, No direct answer, but can't you put the rows into the dict (or a set) without converting them to a string? seen = set() for row in rows: if row in seen: print "dupe" else: seen.add(row) Or, even better, solve the problem within the db: select from group by having count(*) > 1 Peter From jef.mangelschots at gmail.com Mon Jan 26 16:26:56 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 13:26:56 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: >As Benjamin Kaplin said, Windows terminals use the old cp1252 character >set, which cannot display the euro sign. You'll either have to run it in > something more modern like the cygwin rxvt terminal, or output some >other way, such as through a GUI. >With the standard console, I get the same. But with IDLE, using the >same Python build but through a different interface >Scream at Microsoft or try to find or encourage a console >replacement that Python could use. In the meanwhile, use IDLE. Not >perfect for Unicode, but better. So, if I understand it correctly, it should work as long as you run your Python code on something that can actually print the Unicode character. Apparently, the Windows command line can not. I mainly program command line tools to be used by Windows users. So I guess I am screwed. Other than converting my tools to have a graphic interface, is there any other solution, other than give Bill Gates a call and bring his command line up to the 21st century ? From sjmachin at lexicon.net Mon Jan 26 16:37:45 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 13:37:45 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'open_workbook' References: Message-ID: <23bbd810-426f-4c28-bc54-a686e35ac0c1@r36g2000prf.googlegroups.com> On Jan 27, 3:07?am, MRAB wrote: > Jay Jesus Amorin wrote: [snip] > ?> Here's the error message: > ?> > ?> root at nebuchadnezzar:/home/test/project# ./xlrd.py test.xls > ?> Traceback (most recent call last): > ?> ? File "./xlrd.py", line 3, in > ?> ? ? import xlrd > ?> ? File "/home/jayam/project/xlrd.py", line 6, in > ?> ? ? mySpreadsheet = xlrd.open_workbook(open(sys.argv[1])) I concur with MRAB's diagnosis. To answer the OP's possible next question: the first arg of xlrd.open_workbook() is the path to the file to be opened. It won't work with a string of data. That's what the file_contents arg is for. Manual says: """ filename The path to the spreadsheet file to be opened. [snip] file_contents ... as a string or an mmap.mmap object or some other behave-alike object. If file_contents is supplied, filename will not be used, except (possibly) in messages. """ So the above line of code should be: mySpreadsheet = xlrd.open_workbook(sys.argv[1]) Cheers, John From exarkun at divmod.com Mon Jan 26 16:38:07 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 26 Jan 2009 16:38:07 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: Message-ID: <20090126213807.24460.1896409141.divmod.quotient.2263@henry.divmod.com> On Mon, 26 Jan 2009 13:26:56 -0800 (PST), jefm wrote: >>As Benjamin Kaplin said, Windows terminals use the old cp1252 character >>set, which cannot display the euro sign. You'll either have to run it in >> something more modern like the cygwin rxvt terminal, or output some >>other way, such as through a GUI. > >>With the standard console, I get the same. But with IDLE, using the >>same Python build but through a different interface > >>Scream at Microsoft or try to find or encourage a console >>replacement that Python could use. In the meanwhile, use IDLE. Not >>perfect for Unicode, but better. > > >So, if I understand it correctly, it should work as long as you run >your Python code on something that can actually print the Unicode >character. >Apparently, the Windows command line can not. > >I mainly program command line tools to be used by Windows users. So I >guess I am screwed. > >Other than converting my tools to have a graphic interface, is there >any other solution, other than give Bill Gates a call and bring his >command line up to the 21st century ? cp1252 can represent the euro sign (). Apparently the chcp command can be used to change the code page active in the console (). I've never tried this myself, though. Jean-Paul From jcd at sdf.lonestar.org Mon Jan 26 16:38:08 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Jan 2009 16:38:08 -0500 Subject: I'm a python addict ! In-Reply-To: <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> <0febbed2-7199-4530-9f09-90bd209873b5@r10g2000prf.googlegroups.com> Message-ID: <1233005888.5990.0.camel@aalcdl07.lib.unc.edu> On Mon, 2009-01-26 at 12:37 -0800, Paul McGuire wrote: > On Jan 26, 2:06 pm, "J. Cliff Dyer" wrote: > > > > Thanks. That makes sense. But your example creates a new instance of > > the new class each time, rather than changing the class of a persistent > > instance, as the original example, to which I was responding, did. > > > > Look closer. The line that creates a new instance is commented out, > with the notation "how you have to do it in C++ and Java". The actual > Python code is just below, and just assigns a new class to > self.__class__, as in the original example. > Right. Sorry about that. > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From jef.mangelschots at gmail.com Mon Jan 26 16:58:19 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 13:58:19 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: Now that I know the problem, I found the following on Google. Windows uses codepages to display different character sets. (http:// en.wikipedia.org/wiki/Code_page) The Windows chcp command allows you to change the character set from the original 437 set. When you type on the command line: chcp 65001 it sets your console in UTF-8 mode. (http://en.wikipedia.org/wiki/Code_page_65001) Unfortunately, it still doesn't do what I want. Instead of printing the error message above, it prints nothing. From heintest at web.de Mon Jan 26 17:02:24 2009 From: heintest at web.de (=?UTF-8?B?SGFucyBNw7xsbGVy?=) Date: Mon, 26 Jan 2009 23:02:24 +0100 Subject: Anoying unicode / str conversion problem In-Reply-To: References: <497e1afa$0$31343$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <497e3301$0$31329$9b4e6d93@newsspool4.arcor-online.net> Thanks Peter, your answer did the trick. I programed a lot with awk (also a very cool scripting language). So I was focused on the concept a dictionary key has to be string (as in awk). Since it's impossible to use a list as a dictionary key I thought it's also impossible to use a tuple as a key. I was wrong! So my code will become more pythonic, much simpler and even faster! Your suggestion to use the database is also an idea, but the actual task is to see if some rows in (identical) tables across many servers are missing and if so to add the missing rows. In my post I showed a simplified code. Again, thanks for the hint! Greetings Hans From jef.mangelschots at gmail.com Mon Jan 26 17:03:20 2009 From: jef.mangelschots at gmail.com (jefm) Date: Mon, 26 Jan 2009 14:03:20 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: Message-ID: chcp 1252 does allow me to print the EURO sign. Thanks for pointing that out. However, it does not show me some ALL Unicode characters. Very frustrating. I was hoping to find something that allows me to print any Unicode character on the console. From gdamjan at gmail.com Mon Jan 26 17:09:28 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 26 Jan 2009 23:09:28 +0100 Subject: USB in python References: <497D4630.6090405@al.com.au> Message-ID: >> Sorry, by USB device, I meant a device that is powered/activated by a >> bunch of wires that I want to control using a computer and since I >> had a spare USB jack lying around, I used that instead. But so far I >> haven't tried it, nor will try it if it wont work properly. Yes, it >> is not a proper USB device, because I didnt build it to specifically >> interface with the USB port; but I had to start somewhere. Also, the >> device requires more power than the standard parallel port can give. >> Anyway, it looks like the easiest solution for my case is a >> microcontroller > > In which case the Arduino may be a good place to start. The recent > duemilanove boards use USB to communicate with the host, and so the > USB port should be available to the microcontroller. We areg etting > some way away from Python now, of course ... I second that. Arduino to microcontrolers, is what Linux was to kernels back in the 90ties (now it's mainstream), or maybe what python is/was to Java. -- ?????? ( http://softver.org.mk/damjan/ ) () ASCII Ribbon Campaign /\ Keep it simple! From bj_666 at gmx.net Mon Jan 26 17:12:43 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 26 Jan 2009 22:12:43 GMT Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> <20090126161011.482e66f9@usenot.de> Message-ID: <6u6qqrFdkq3bU3@mid.uni-berlin.de> On Mon, 26 Jan 2009 16:10:11 +0100, Andreas Waldenburger wrote: > On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch > wrote: > >> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: >> >> > content = a.readlines() >> > >> > (Just because we can now write "for line in file" doesn't mean that >> > readlines() is *totally* redundant.) >> >> But ``content = list(a)`` is shorter. :-) >> > But much less clear, wouldn't you say? Okay, so let's make it clearer and even shorter: ``lines = list(a)``. :-) Ciao, Marc 'BlackJack' Rintsch From perfreem at gmail.com Mon Jan 26 17:25:15 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Mon, 26 Jan 2009 14:25:15 -0800 (PST) Subject: scatterhist and resizing figures Message-ID: <9e1ea2ab-b326-4cd7-ae59-4544fdfe2708@o40g2000prn.googlegroups.com> i am using scatterhist to plot some data. i find that when i plot the data and matlab shows it in the figure window, stretching the figure window (with the mouse) to enlarge it actually changes the properties of the figure. for example, making it bigger sometimes reveals more tick marks - like the y limit of the y axis, which i have set but was not shown until i enlarged the window. also, more crucially enlarging can make bars that appear at 0 or not at all to show... when i save the figure window as pdf, depending on which of these is shown, i get different pdfs. here's an example: x=rand(1, 100); y=x+5; scatterhist(x,y); set(gca, 'Box' , 'off' , ... 'LineWidth' , 1); set(gca , 'FontSize' , 12); set(gca, 'FontName' , 'Helvetica'); set(gca, 'TickDir', 'out'); first question: how can i programtically save the figure as pdf in a way that shows maximal info? i don't want to lose tick marks on my axis or bars in my histogram. second: how can i plot with scatterhist but make the scatter plot points filled? with ordinary scatter, i can simply do: scatter(x, y, 'filled') but the 'filled' argument doesn't appear to work for scatterhist. thank you. From geekmail at usenot.de Mon Jan 26 17:38:14 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Mon, 26 Jan 2009 23:38:14 +0100 Subject: Newby: how to transform text into lines of text References: <6u386gFdd2ocU1@mid.uni-berlin.de> <6u60vlFdkq3bU2@mid.uni-berlin.de> <20090126161011.482e66f9@usenot.de> <6u6qqrFdkq3bU3@mid.uni-berlin.de> Message-ID: <20090126233814.3075df67@usenot.de> On 26 Jan 2009 22:12:43 GMT Marc 'BlackJack' Rintsch wrote: > On Mon, 26 Jan 2009 16:10:11 +0100, Andreas Waldenburger wrote: > > > On 26 Jan 2009 14:51:33 GMT Marc 'BlackJack' Rintsch > > wrote: > > > >> On Mon, 26 Jan 2009 12:22:18 +0000, Sion Arrowsmith wrote: > >> > >> > content = a.readlines() > >> > > >> > (Just because we can now write "for line in file" doesn't mean > >> > that readlines() is *totally* redundant.) > >> > >> But ``content = list(a)`` is shorter. :-) > >> > > But much less clear, wouldn't you say? > > Okay, so let's make it clearer and even shorter: ``lines = > list(a)``. :-) > OK, you win. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From sjmachin at lexicon.net Mon Jan 26 17:38:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 14:38:50 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: Message-ID: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> On Jan 27, 8:38?am, Jean-Paul Calderone wrote: > On Mon, 26 Jan 2009 13:26:56 -0800 (PST), jefm wrote: > >>As Benjamin Kaplin said, Windows terminals use the old cp1252 character > >>set, which cannot display the euro sign. You'll either have to run it in > >> something more modern like the cygwin rxvt terminal, or output some > >>other way, such as through a GUI. > > >>With the standard console, I get the same. ?But with IDLE, using the > >>same Python build but through a different interface > > >>Scream at Microsoft or try to find or encourage a console > >>replacement that Python could use. ?In the meanwhile, use IDLE. ?Not > >>perfect for Unicode, but better. > > >So, if I understand it correctly, it should work as long as you run > >your Python code on something that can actually print the Unicode > >character. > >Apparently, the Windows command line can not. > > >I mainly program command line tools to be used by Windows users. So I > >guess I am screwed. > > >Other than converting my tools to have a graphic interface, is there > >any other solution, other than give Bill Gates a call and bring his > >command line up to the 21st century ? > > cp1252 can represent the euro sign (). ?Apparently the chcp command can be used to change the code page > active in the console (). ?I've never tried this myself, though. > Short answer: it doesn't work. Test [Windows XP SP3, Python 2.6.1]: C:\junk>chcp Active code page: 850 C:\junk>chcp 1252 Active code page: 1252 C:\junk>chcp Active code page: 1252 C:\junk>\python26\python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys; sys.stdout.encoding; sys.stderr.encoding 'cp1252' 'cp1252' # So far, so good >>> import unicodedata as ucd >>> for b in range(128, 256): ... c = chr(b) ... u = c.decode('cp1252', 'replace') ... name = ucd.name(u) ... print hex(b), c, repr(u), name ... 0x80 ? u'\u20ac' EURO SIGN 0x81 ? u'\ufffd' REPLACEMENT CHARACTER 0x82 ? u'\u201a' SINGLE LOW-9 QUOTATION MARK [snip] 0xfb ? u'\xfb' LATIN SMALL LETTER U WITH CIRCUMFLEX 0xfc ? u'\xfc' LATIN SMALL LETTER U WITH DIAERESIS 0xfd ? u'\xfd' LATIN SMALL LETTER Y WITH ACUTE [snip] Ignore what you are seeing in the second field of each above line; it could well look OK. However what I see on the console is: capital C with cedilla small u with diaeresis (umlaut) small e with acute superscript one superscript three superscript two [yes, out of order] IOW, the bridge might think it's in cp1252 mode, but nobody told the engine room, which is still churning out cp850. From martin at v.loewis.de Mon Jan 26 17:42:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 26 Jan 2009 23:42:55 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: Message-ID: <497E3C6F.1010909@v.loewis.de> > I was hoping to find something that allows me to print any Unicode > character on the console. You will have to debug the Python interpreter to find out what's going wrong in code page 65001. Nobody has ever resolved that mystery, although it's been known for some time. If you merely want to see *something* (and not actually the glyph for the character (*)): py> print(ascii('\u20ac')) '\u20ac' should work fine. Regards, Martin (*) Windows doesn't support displaying *all* unicode characters even in code page 65001, nor is it reasonable to expect it to. It can, at best, only display those characters it has glyphs for in the font that it is using. As Unicode constantly evolves, the fonts necessarily get behind. Plus, in a fixed-size font, some characters just don't render too well. From james at agentultra.com Mon Jan 26 17:43:06 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 26 Jan 2009 14:43:06 -0800 Subject: I'm a python addict ! References: Message-ID: <87pri9y9hh.fsf@agentultra.com> Linuxguy123 writes: > I just started using python last week and I'm addicted. > > I hate Perl. I never did learn to use it with any competence. I has to > be the most obfuscated, cryptic language I've ever seen. Making it > "object oriented" only makes it worse ! > .. .. I program full-time in Python, so I share your excitement and enthusiasm. But bashing Perl like that doesn't make you sound very smart. I'm probably one of the very few Python programmers who came from (and still occassionally) use Perl. I've written non-trivial programs in it and from my experience I can tell you that it's actually a great language. The Moose object system is well beyond Python's class system. But I guess you wouldn't know that. So yay for Python, but don't get in the habit of criticising that which you do not know. From james at agentultra.com Mon Jan 26 17:52:37 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 26 Jan 2009 14:52:37 -0800 Subject: I'm a python addict ! References: <87pri9y9hh.fsf@agentultra.com> Message-ID: <87iqo1y91m.fsf@agentultra.com> J Kenneth King writes: > Linuxguy123 writes: > >> I just started using python last week and I'm addicted. >> >> I hate Perl. I never did learn to use it with any competence. I has to >> be the most obfuscated, cryptic language I've ever seen. Making it >> "object oriented" only makes it worse ! >> .. .. > > I program full-time in Python, so I share your excitement and > enthusiasm. But bashing Perl like that doesn't make you sound very > smart. I'm probably one of the very few Python programmers who came from > (and still occassionally) use Perl. I've written non-trivial programs in > it and from my experience I can tell you that it's actually a great > language. The Moose object system is well beyond Python's class > system. But I guess you wouldn't know that. > > So yay for Python, but don't get in the habit of criticising that which > you do not know. I just realized this might become flame-bait. Please disregard the flamey bits. :( From martin at v.loewis.de Mon Jan 26 18:00:52 2009 From: martin at v.loewis.de (=?windows-1252?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 00:00:52 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> References: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> Message-ID: <497e40a5$0$25202$9b622d9e@news.freenet.de> > IOW, the bridge might think it's in cp1252 mode, but nobody told the > engine room, which is still churning out cp850. I think you must use a different font in the console, too, such as Lucida Sans Unicode. Regards, Martin From sjmachin at lexicon.net Mon Jan 26 18:39:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 15:39:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <427597cc-9cd9-4443-b1ab-f81a6905c342@v5g2000prm.googlegroups.com> <497e40a5$0$25202$9b622d9e@news.freenet.de> Message-ID: On Jan 27, 10:00?am, "Martin v. L?wis" wrote: > > IOW, the bridge might think it's in cp1252 mode, but nobody told the > > engine room, which is still churning out cp850. > > I think you must use a different font in the console, too, such as > Lucida Sans Unicode. True. I was just about to post that I'd stumbled across that! From python at bdurham.com Mon Jan 26 18:42:29 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jan 2009 18:42:29 -0500 Subject: Iterating through a file significantly slower when file has big buffer Message-ID: <1233013349.25395.1296882205@webmail.messagingengine.com> I'm working with very large text files and am always looking for ways to optimize the performance of our scripts. While reviewing our code, I wondered if changing the size of our file buffers to a very large buffer size might speed up our file I/O. Intuitively, I thought that bigger buffers might improve performance by reducing the number of reads. Instead I observed just the opposite - performance was 7x slower! (~500 sec vs. 70 sec) and used 3x the memory (24M vs. 8M) due to the larger buffer. The following tests were run on a Windows XP system using Python 2.6.1 SOURCE: import time # timer class class timer( object ): def __init__( self, message='' ): self.message = message def start( self ): self.starttime = time.time() print 'Start: %s' % ( self.message ) def stop( self ): print 'Finish: %s %6.2f' % ( self.message, time.time() - self.starttime ) # myFileName points to a 2G text file. myFileName = r'C:\logs\jan2009.dat' # default buffering myFile = open( myFileName ) for line in myFile: pass myFile.close() strategy1.stop() # setting the buffer size to 16M bufferSize = 2 ** 24 strategy2 = timer( 'Large buffer (%sk)' % (bufferSize/1024) ) strategy2.start() myFile = open( myFileName, 'rt', bufferSize ) for line in myFile: pass myFile.close() strategy2.stop() OUTPUT: Start: Default buffer Finish: Default buffer 69.98 Start: Large buffer (16384k) Finish: Large buffer (16384k) 493.88 <--- 7x slower Any comments regarding this massive slowdown? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ekh.johan at gmail.com Mon Jan 26 18:44:18 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 00:44:18 +0100 Subject: optparse with numpy.array? Message-ID: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Hi all, I'm trying to use optparse to process command line parameters given to my program. It works as I expect for the types supported by optparse, i.e. int, float, string etc. but how can I pass a numpy.array or a list to my program? I have been searching for it but cannot find a good solution. By the way, I am a Python newbie so please be gentle... Best regards, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Jan 26 18:48:01 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jan 2009 18:48:01 -0500 Subject: CORRECTION: Re: Iterating through a file significantly slower when file has big buffer In-Reply-To: <1233013349.25395.1296882205@webmail.messagingengine.com> References: <1233013349.25395.1296882205@webmail.messagingengine.com> Message-ID: <1233013681.26390.1296884287@webmail.messagingengine.com> Added the following lines missing from my original post: strategy1 = timer( 'Default buffer' ) strategy1.start() Code below is now complete. Malcolm SOURCE: import time # timer class class timer( object ): def __init__( self, message='' ): self.message = message def start( self ): self.starttime = time.time() print 'Start: %s' % ( self.message ) def stop( self ): print 'Finish: %s %6.2f' % ( self.message, time.time() - self.starttime ) # myFileName points to a 2G text file. myFileName = r'C:\logs\jan2009.dat' # default buffering strategy1 = timer( 'Default buffer' ) strategy1.start() myFile = open( myFileName ) for line in myFile: pass myFile.close() strategy1.stop() # setting the buffer size to 16M bufferSize = 2 ** 24 strategy2 = timer( 'Large buffer (%sk)' % (bufferSize/1024) ) strategy2.start() myFile = open( myFileName, 'rt', bufferSize ) for line in myFile: pass myFile.close() strategy2.stop() OUTPUT: Start: Default buffer Finish: Default buffer 69.98 Start: Large buffer (16384k) Finish: Large buffer (16384k) 493.88 <--- 7x slower Any comments regarding this massive slowdown? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Mon Jan 26 18:53:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 15:53:02 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> Message-ID: <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> On Jan 27, 9:42?am, "Martin v. L?wis" wrote: > > I was hoping to find something that allows me to print any Unicode > > character on the console. > > You will have to debug the Python interpreter to find out what's > going wrong in code page 65001. Nobody has ever resolved that mystery, > although it's been known for some time. Maybe the problem is not in the Python interpreter. Running this tiny C program #include "stdio.h" int main(int argc, char **argv) { printf("<\xc2\x80>\n"); } compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) and using "Lucida Console" font: After CHCP 1252, this prints < A-circumflex Euro >, as expected. After CHCP 65001, it prints < hollow-square >. Perhaps you could try that with an MS C compiler [which I don't have] ... From robert.kern at gmail.com Mon Jan 26 19:00:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 18:00:16 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Message-ID: On 2009-01-26 17:44, Johan Ekh wrote: > Hi all, > I'm trying to use optparse to process command line parameters given to > my program. > It works as I expect for the types supported by optparse, i.e. int, > float, string etc. but how can I > pass a numpy.array or a list to my program? http://docs.python.org/library/optparse#optparse-extending-optparse Figure out the text format you want your users to type the value on the command line, write a function that will take that text and convert it to an array or list, then customize OptionParser to use that parser as given in the link above. Keep in mind that your user probably won't want to need to use whitespace or any kind of brackets. Commas are nice, though. You may also want to consider taking a filename and parsing that file instead. -- 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 mdw at distorted.org.uk Mon Jan 26 19:14:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 00:14:17 +0000 Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > Mark Wooding wrote: >> * Assignment stores a new (reference to a) value in the variable. >> >> * Binding modifies the mapping between names and variables. >> > I realise I have omitted what was doubtless intended to be explanatory > detail, but I am having trouble reconciling those sentences. Would you > mind explaining "in vacuuo" what you see as the difference between > assignment and binding? OK. This turned into something of an essay. I hope that it's of use to somebody... A name is a kind of expression. Expressions can be evaluated to yield values. Therefore, a name can be evaluated to yield a value. How does this happen? There are two distinct mappings involved. The first mapping is from names to variables. This mapping is usually called the `environment', and is acted upon by `binding'. The extent of the program text whose meaning is affected by a binding is called the `scope' of the binding[1]. In Python, the scope can be determined statically by analysing the program text (`lexical scope'). In some languages the scope can only be determined at run time (`dynamic scope'); other languages have a mixture of the two. Binding in Python is done in two ways: * /Explicit/ binding is done by `def' or `lambda': the parameters are bound, and the scope of the bindings is the entire function body (i.e., it does not include the default arguments). * /Implicit/ binding may be performed when a name as a result of an assignment operation -- either an assignment statement or one of a number of features which work by assignment, including `for' loops, list comprehensions, and `def' blocks. The scope of the binding in this case depends on the nature of the block in which the binding occurs: within `def' and `lambda'[2], the scope is the entire function body; within `class' and module toplevels, the scope is from the first-executed assignment to the end of the block. In all cases, names are bound to fresh variables when the scope of the binding begins. The environment within a binding block is formed by extending the environment of the surrounding program text. In the case of function definitions, in particular, we say that the function `closes over' the environment in which it is defined. The second mapping is from variables to values. This mapping doesn't seem to have a common name, though it's referred to as the `store' in some formal semantics (e.g., R5RS Scheme). The store is acted upon by assignment (and assignment-like operations such as `for' loops and list comprehensions). An assignment NAME = VALUE alters the store as follows: the variable bound to NAME becomes mapped to the result of evaluating VALUE. We can now consider some example programs. In [23]: def simple(x): ....: def inner(): ....: return x ....: return inner ....: When the function is invoked, say by In [24]: simple('boo!')() the name x is bound to a new variable, and the variable is assigned the value `boo!'. The body of `simple' is then executed. First, a function `inner' is defined: `def' is an assignment-like operation, which causes `inner' to be implicitly bound to a fresh variable on entry to the function. When the `def' is executed, that variable is assigned the value of a function. Finally, we return the result of evaluating `inner', i.e., the function we just constructed. The next pair of parentheses invoke the function `inner'. That function was defined within an environment in which x was bound to a variable that had been assigned the value 'boo!'. It therefore returns this value: Out[24]: 'boo!' Next example: In [26]: def mutant(x): ....: def inner(): ....: return x ....: x = 'changed!' ....: return inner ....: Suppose we invoke this one as In [27]: mutant('same')() The first steps are the same: x is bound to a fresh variable which is assigned the value 'same'; `inner' is bound to a fresh variable which is assigned a function value. Now the line `x = 'changed!'' is executed. This assigns the string 'changed!' to the variable bound to x. Finally, we return the function value. That function is now invoked. It was defined in an environment where x was bound to a variable whose last assigned value was 'changed!'. Therefore: Out[27]: 'changed!' The original poster's question can be illustrated by this example: In [28]: def problem(): ....: return [lambda: i for i in xrange(3)] ....: In [29]: [f() for f in problem()] This is actually the same as the mutant example in disguise. There is no parameter to bind, but `for' in a list comprehension is an assignment operation, and therefore i is implicitly bound when `problem' is invoked. The list comprehension performs three iterations. On each iteration, the `lambda' is evaluated. It produces a different function value each time: In [30]: problem() Out[30]: [ at 0x9a731ec>, at 0x9a73064>, at 0x9a730d4>] And each time through, the variable bound to i is assigned a different value: first 0, then 1, and finally 2. The resulting functions are gathered into a list, which is returned as the value of `problem()'. However, it was textually the same `lambda', and so they closed over the /same/ environment -- that of the body of `problem' -- in which i is bound to the same variable. That variable was last assigned the value 2. Therefore, when we invoke any of the functions, we get the same result: Out[29]: [2, 2, 2] Two fixes were suggested. I suggested this one: In [31]: def bind_fix(): ....: def hack(i): return lambda: i ....: return [hack(i) for i in xrange(3)] ....: In [32]: [f() for f in bind_fix()] Out[32]: [0, 1, 2] How does this work? Each iteration invokes the `hack' function. Invocation binds i to a new variable, and assigns it the value of the argument (which is 0, 1, or 2 according to which iteration we're on). The `lambda' which `hack' returns closes over /this/ environment, and the variable bound to i in `hack''s environment is not assigned again, so the problem doesn't occur. The function `hack' is basically a one-line version of the `simple' example above. While `hack' closes over the environment of `bind_fix', this isn't important: `hack''s binding of i `shadows' the outer binding of `bind_fix'. It's where it is to avoid cluttering up the toplevel namespace. The other fix uses default arguments, and it was suggested by Steven D'Aprano and Brian Vanderburg. In [33]: def defarg_fix(): ....: return [lambda i = i: i for i in xrange(3)] ....: In [34]: [f() for f in defarg_fix()] Out[34]: [0, 1, 2] This is conceptually rather simpler; I didn't suggest it because it doesn't teach the concepts I was exploring as well. The important point about default arguments in Python is that they're evaluated at the same time as the function is being defined, rather than on every call[3]. There are three functions defined, one for each iteration of the list comprehension; since i is assigned a different value on each iteration, and the default argument is evaluated on each definition, each function acquires a distinct defalt argument for its parameter i. Chapter 3 of the Structure and Interpretation of Computer Programs, by Abelson and Sussman explains this stuff in a more discursive and approachable manner. If you're still confused by my explanation (and by nature I tend to err on the side of precision rather than clarity, a fault which I know impairs my teaching ability), you may find theirs more useful: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-19.html#%_chap_3 Nonetheless, I hope that this description has been of some use. [1] Under lexical binding, a particular binding always affects the same region of program text. That doesn't mean that the same binding is used every time that text is executed! [2] Yes, `lambda' acts as a binding block. I leave construction of a program exhibiting this behaviour as an exercise. [3] This is unlike default arguments in, for example, Common Lisp. Both behaviours are useful. Python's behaviour was especially valuable before the language provided true closures. -- [mdw] From vincent at vincentdavis.net Mon Jan 26 19:18:39 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 17:18:39 -0700 Subject: print formating for matrix/table Message-ID: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> I have a list of lists....a matrix in that all sub lists are the same length. I there a nice why to prin these so that the columns and rows line up nicely? I have looked around for a good way to do this and haven't found one I am like. It seems that all involve repeating a print for each line. I would have thought I could find a prebuilt function to do this. Surly lots of people are printing matrixes and would like nice formating. So what am I missing? Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Jan 26 19:23:23 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 18:23:23 -0600 Subject: print formating for matrix/table In-Reply-To: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: On 2009-01-26 18:18, Vincent Davis wrote: > I have a list of lists....a matrix in that all sub lists are the same > length. I there a nice why to prin these so that the columns and rows > line up nicely? > I have looked around for a good way to do this and haven't found one I > am like. It seems that all involve repeating a print for each line. I > would have thought I could find a prebuilt function to do this. Surly > lots of people are printing matrixes and would like nice formating. So > what am I missing? Most people using matrices are also using numpy, and numpy arrays do print with columns lined up. -- 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 benjamin.kaplan at case.edu Mon Jan 26 19:57:11 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 26 Jan 2009 19:57:11 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <497E3C6F.1010909@v.loewis.de> References: <497E3C6F.1010909@v.loewis.de> Message-ID: On Mon, Jan 26, 2009 at 5:42 PM, "Martin v. L?wis" wrote: > > I was hoping to find something that allows me to print any Unicode > > character on the console. > > You will have to debug the Python interpreter to find out what's > going wrong in code page 65001. Nobody has ever resolved that mystery, > although it's been known for some time. Well, the first step would be to tell Python that there is a code page 65001. On Python 2.6, I get a LookupError for an unknown encoding after doing "chcp 65001". I checked the list of aliases in Python 3 and there was no entry for cp65001. Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print u'hello' Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: cp65001 > > If you merely want to see *something* (and not actually the glyph > for the character (*)): > > py> print(ascii('\u20ac')) > '\u20ac' > > should work fine. > > Regards, > Martin > > (*) Windows doesn't support displaying *all* unicode characters even > in code page 65001, nor is it reasonable to expect it to. It can, at > best, only display those characters it has glyphs for in the font > that it is using. As Unicode constantly evolves, the fonts necessarily > get behind. Plus, in a fixed-size font, some characters just don't > render too well. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Pat at junk.net Mon Jan 26 20:02:59 2009 From: Pat at junk.net (Pat) Date: Mon, 26 Jan 2009 20:02:59 -0500 Subject: optparse question Message-ID: Up until today, I never needed to pass any arguments to a Python program. I did all the requisite reading and found that I should use optparse instead of getopt. I read the documentation and since the words "simple" and "easy" often appeared in the examples and documentation, I just knew that it would be a snap to implement. Problem is that all I wanted to do was pass a one flag to the program "-d", for to enable debug mode. Several hours later I gave up after optparse complained about every variation I tried. What does it take to pass single parameter to a program? http://docs.python.org/library/optparse.html stated that programs always have options. Is that so? What about "dir /s"? getopt resolved my immediate need, but I would like to know how one could use optparse to extract out the options from something like "dir /s /b". From prologic at shortcircuit.net.au Mon Jan 26 20:16:25 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 11:16:25 +1000 Subject: optparse question In-Reply-To: References: Message-ID: On Tue, Jan 27, 2009 at 11:02 AM, Pat wrote: (...) > What does it take to pass single parameter to a program? > http://docs.python.org/library/optparse.html stated that programs always > have options. Is that so? What about "dir /s"? Sample code: ---------------------------------------- #!/usr/bin/env python """optexample Example of using optparse """ import os import sys import os.path import optparse __version__ = "0.1" USAGE = "%prog [options] " VERSION = "%prog v" + __version__ def parse_options(): """parse_options() -> opts, args Parse and command-line options given returning both the parsed options and arguments. """ parser = optparse.OptionParser(usage=USAGE, version=VERSION) parser.add_option("-v", "--verbose", action="store_true", default=False, dest="verbose", help="Verbose output during operation.") opts, args = parser.parse_args() if len(args) < 1: parser.print_help() raise SystemExit, 1 return opts, args def main(): opts, args = parse_options() if opts.verbose: print args[0] if __name__ == "__main__": main() ---------------------------------------- cheers James From robert.kern at gmail.com Mon Jan 26 20:18:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 19:18:46 -0600 Subject: optparse question In-Reply-To: References: Message-ID: On 2009-01-26 19:02, Pat wrote: > Up until today, I never needed to pass any arguments to a Python program. > > I did all the requisite reading and found that I should use optparse > instead of getopt. I read the documentation and since the words "simple" > and "easy" often appeared in the examples and documentation, I just knew > that it would be a snap to implement. > > Problem is that all I wanted to do was pass a one flag to the program > "-d", for to enable debug mode. Several hours later I gave up after > optparse complained about every variation I tried. parser = optparse.OptionParser() parser.add_option('-d', '--debug', action='store_true') options, args = parser.parse_args() if options.debug: # Do debugging stuff. else: # Do non-debugging stuff. > What does it take to pass single parameter to a program? > http://docs.python.org/library/optparse.html stated that programs always > have options. Is that so? What about "dir /s"? Can you quote exactly the part that you are talking about? I don't see any such claim. -- 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 steve at holdenweb.com Mon Jan 26 20:39:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 20:39:49 -0500 Subject: Dynamic methods and lambda functions In-Reply-To: <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steve Holden writes: > >> Mark Wooding wrote: >>> * Assignment stores a new (reference to a) value in the variable. >>> >>> * Binding modifies the mapping between names and variables. >>> >> I realise I have omitted what was doubtless intended to be explanatory >> detail, but I am having trouble reconciling those sentences. Would you >> mind explaining "in vacuuo" what you see as the difference between >> assignment and binding? > > OK. This turned into something of an essay. I hope that it's of use to > somebody... > > A name is a kind of expression. Expressions can be evaluated to yield > values. Therefore, a name can be evaluated to yield a value. How does > this happen? There are two distinct mappings involved. > > The first mapping is from names to variables. This mapping is usually > called the `environment', and is acted upon by `binding'. The extent of > the program text whose meaning is affected by a binding is called the > `scope' of the binding[1]. In Python, the scope can be determined > statically by analysing the program text (`lexical scope'). In some > languages the scope can only be determined at run time (`dynamic > scope'); other languages have a mixture of the two. > Yes. Kay Schleur pointed out that my confusion was due to too close a mental proximity to the Python term "binding value to names" for assignment. Once I realised you were using "binding"to refer to the scope of names it all made much more sense. [...] > > Chapter 3 of the Structure and Interpretation of Computer Programs, by > Abelson and Sussman explains this stuff in a more discursive and > approachable manner. If you're still confused by my explanation (and by > nature I tend to err on the side of precision rather than clarity, a > fault which I know impairs my teaching ability), you may find theirs > more useful: > > http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-19.html#%_chap_3 > > Nonetheless, I hope that this description has been of some use. > I found your precision most helpful, and the entire post was readable and useful. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent at vincentdavis.net Mon Jan 26 20:53:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 18:53:47 -0700 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> I do have numpy but am using lists as did not need any functions of array. Well maybe print now. I am new to python and don't really know the details about the difference between lists and arrays. I do know that there are different/additional functions available for arrays.Anyway is this the best solution, convert the list to an array before printing? Thanks Vincent Davis On Mon, Jan 26, 2009 at 5:23 PM, Robert Kern wrote: > On 2009-01-26 18:18, Vincent Davis wrote: > >> I have a list of lists....a matrix in that all sub lists are the same >> length. I there a nice why to prin these so that the columns and rows >> line up nicely? >> I have looked around for a good way to do this and haven't found one I >> am like. It seems that all involve repeating a print for each line. I >> would have thought I could find a prebuilt function to do this. Surly >> lots of people are printing matrixes and would like nice formating. So >> what am I missing? >> > > Most people using matrices are also using numpy, and numpy arrays do print > with columns lined up. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Jan 26 20:55:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Jan 2009 20:55:47 -0500 Subject: print formating for matrix/table In-Reply-To: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: Vincent Davis wrote: > I have a list of lists....a matrix in that all sub lists are the > same length. I there a nice why to prin these so that the columns and > rows line up nicely? > I have looked around for a good way to do this and haven't found one I > am like. It seems that all involve repeating a print for each line. I > would have thought I could find a prebuilt function to do this. Surly > lots of people are printing matrixes and would like nice formating. So > what am I missing? > Look at the pprint module: >>> arr = [range(10)] * 10 >>> from pprint import pprint >>> pprint(arr) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From robert.kern at gmail.com Mon Jan 26 20:58:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 19:58:29 -0600 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: On 2009-01-26 19:55, Steve Holden wrote: > Vincent Davis wrote: >> I have a list of lists....a matrix in that all sub lists are the >> same length. I there a nice why to prin these so that the columns and >> rows line up nicely? >> I have looked around for a good way to do this and haven't found one I >> am like. It seems that all involve repeating a print for each line. I >> would have thought I could find a prebuilt function to do this. Surly >> lots of people are printing matrixes and would like nice formating. So >> what am I missing? >> > Look at the pprint module: > >>>> arr = [range(10)] * 10 >>>> from pprint import pprint >>>> pprint(arr) > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] But this doesn't line up the columns, except by accident: [[1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000], [1, 10, 200], [300, 4000, 50000]] -- 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 astan.chee at al.com.au Mon Jan 26 20:58:30 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 27 Jan 2009 12:58:30 +1100 Subject: USB in python In-Reply-To: <497DCEC5.3060208@aim.com> References: <497D4630.6090405@al.com.au> <497DCEC5.3060208@aim.com> Message-ID: <497E6A46.1020708@al.com.au> Brian Allen Vanderburg II wrote: > This is the FT245 chip which is basically USB-to-Parallel. > > Chips: http://www.ftdichip.com/Products/FT245R.htm > Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm > > The spec sheet for the board seems quite simple. It's pin out is > similar to that of a parallel port in that you have your data lines > DB0-DB7, etc. It can also be connected in bus-powered configuration > (~100mA) or self-powered configuration. The kit is more expensive than > the chip itself, but probably easier especially if you don't have any > experience with surface mount. > > That is a good idea. The main factor (aside from complexity) that I forgot to mention is the cost. I live very far away from the US and sometimes it is cheaper to buy a microcontroller here than have bits n pieces shipped from the US. Anyway, I'll see if I can find these parts here and maybe use that. Thanks for all the ideas! Cheers Astan From robert.kern at gmail.com Mon Jan 26 21:03:30 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jan 2009 20:03:30 -0600 Subject: print formating for matrix/table In-Reply-To: <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> Message-ID: On 2009-01-26 19:53, Vincent Davis wrote: > I do have numpy but am using lists as did not need any functions of > array. Well maybe print now. I am new to python and don't really know > the details about the difference between lists and arrays. I do know > that there are different/additional functions available for arrays. Python lists are one-dimensional, appendable sequences of heterogeneous Python objects. numpy arrays are multi-dimensional, non-appendable containers usually of homogeneously-typed numerical data (but can also contain heterogeneous Python objects, too). numpy arrays have many conveniences over lists of lists if you need to do math on bunches of numbers. > Anyway is this the best solution, convert the list to an array before > printing? I wouldn't use numpy *just* for this, but I suspect that you could actually use numpy for other things if you are actually using your lists of lists as matrices. -- 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 mccredie at gmail.com Mon Jan 26 21:13:11 2009 From: mccredie at gmail.com (Matimus) Date: Mon, 26 Jan 2009 18:13:11 -0800 (PST) Subject: optparse question References: Message-ID: <38d8bade-2603-4740-b667-b472c5e3225e@r41g2000prr.googlegroups.com> > I did all the requisite reading and found that I should use optparse > instead of getopt. ? I read the documentation and since the words > "simple" and "easy" often appeared in the examples and documentation, I > just knew that it would be a snap to implement. I don't know where you got that. 'getopt' works just fine. 'optparse' works fine too. I don't think anybody is going to get too worked up over which you decide to use for such a simple case. Matt From sjmachin at lexicon.net Mon Jan 26 21:44:52 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 26 Jan 2009 18:44:52 -0800 (PST) Subject: optparse question References: Message-ID: <796ebbdf-b1ee-498e-a53e-766d97f21588@r15g2000prd.googlegroups.com> On Jan 27, 12:02?pm, Pat wrote: > Up until today, I never needed to pass any arguments to a Python program. > > I did all the requisite reading and found that I should use optparse > instead of getopt. ? I read the documentation and since the words > "simple" and "easy" often appeared in the examples and documentation, I > just knew that it would be a snap to implement. > > Problem is that all I wanted to do was pass a one flag to the program > "-d", for to enable debug mode. ?Several hours later I gave up after > optparse complained about every variation I tried. > > What does it take to pass single parameter to a program? I'm assuming that question 2 starts here. To help answer question 1 without just writing the code for you, it might help if you (a) showed what you regard as your best effort (b) explained what part of http://docs.python.org/library/optparse.html#handling-boolean-flag-options you had trouble with. > http://docs.python.org/library/optparse.htmlstated that programs always > have options. Does it? > ?Is that so? ?What about "dir /s"? That has one option, /s. And this must be question 3: > > getopt resolved my immediate need, but I would like to know how one > could use optparse to extract out the options from something like "dir > /s /b". If you mean with "/" as the option designator instead of "-": there doesn't appear to be a documented way of doing it. You would have to do some social engineering on the users to get them used to doing "dir -s -b". In any case I thought the number of Windows users who know how to fire up a Command Prompt window was diminishingly small ... you actually have users who know how to use commands like "dir /s /b"? Cheers, John From vincent at vincentdavis.net Mon Jan 26 21:53:39 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 26 Jan 2009 19:53:39 -0700 Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> <77e831100901261753o245b2adfo6540aa9f5de2f443@mail.gmail.com> Message-ID: <77e831100901261853o50e1c25aic7b76434d1b2d10d@mail.gmail.com> I called it a matrix mostly because this is how I am visualizing it. They are full of numbers but only as representatives of students and schools. It looks like pprint will work after I read the instructions. At least I know where to look now. In the end I need to figure out how to save the data a csv formated for excel but that is for later I was just trying to make it easier to debug my code. Thanks Vincent Davis 720-301-3003 On Mon, Jan 26, 2009 at 7:03 PM, Robert Kern wrote: > On 2009-01-26 19:53, Vincent Davis wrote: > >> I do have numpy but am using lists as did not need any functions of >> array. Well maybe print now. I am new to python and don't really know >> the details about the difference between lists and arrays. I do know >> that there are different/additional functions available for arrays. >> > > Python lists are one-dimensional, appendable sequences of heterogeneous > Python objects. numpy arrays are multi-dimensional, non-appendable > containers usually of homogeneously-typed numerical data (but can also > contain heterogeneous Python objects, too). numpy arrays have many > conveniences over lists of lists if you need to do math on bunches of > numbers. > > Anyway is this the best solution, convert the list to an array before >> printing? >> > > I wouldn't use numpy *just* for this, but I suspect that you could actually > use numpy for other things if you are actually using your lists of lists as > matrices. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at anjanesh.net Mon Jan 26 22:16:38 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 27 Jan 2009 08:46:38 +0530 Subject: Method returning an Iterable Object In-Reply-To: <20090126202804.28c65e90@usenot.de> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> Message-ID: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> But how come a raise StopIteration in the next() method doesnt need to be caught ? It works without breaking. class twoTimes: max = 10**10 def __init__(self, n): self.__n = n def next(self): if self.__n > self.max: raise StopIteration self.__n *= 2 return self.__n def __iter__(self): return self t = twoTimes(5) c = 0 print (t.next()) print (t.next()) for n in t: print n Anjanesh From castironpi at gmail.com Mon Jan 26 22:20:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 19:20:50 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Hi, Mark, Do you mind if I approach you off the group about this? Aaron On Jan 25, 9:47?pm, Mark Wooding wrote: > Aaron Brady writes: > > I am writing an extension using shared memory. ?I need a data type > > that is able to reassign its 'ob_type' field depending on what process > > is calling it. > > That sounds scary! snip From prologic at shortcircuit.net.au Mon Jan 26 22:33:22 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 13:33:22 +1000 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 1:16 PM, Anjanesh Lekshminarayanan wrote: > But how come a raise StopIteration in the next() method doesnt need to > be caught ? It works without breaking. Because this exception is specially dealt with when iterating over an iterator. The "raise StopIteration" is what causes the iteration to stop. Consider: >>> x = EveryOther(xrange(10)) >>> x.next() 0 >>> x.next() 2 >>> x.next() 4 >>> x.next() 6 >>> x.next() 8 >>> x.next() Traceback (most recent call last): File "", line 1, in File "foo.py", line 12, in next raise StopIteration StopIteration >>> x = EveryOther(xrange(10)) >>> list(x) [0, 2, 4, 6, 8] >>> cheers James From alwaseem307ster at yahoo.com Mon Jan 26 22:48:05 2009 From: alwaseem307ster at yahoo.com (klia) Date: Mon, 26 Jan 2009 19:48:05 -0800 (PST) Subject: shutil module (directory input) Message-ID: <21679178.post@talk.nabble.com> hello folks i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code.becuase now i have to specify the sourcefile and the destinationfile in codes and not left to be specified from the terminal. i want to be able to do this. python shutil_copy.py sourcefile, destinationfile code import shutil shutil.copyfile(srcfile, dstfile) # copy data only -- View this message in context: http://www.nabble.com/shutil-module-%28directory-input%29-tp21679178p21679178.html Sent from the Python - python-list mailing list archive at Nabble.com. From tjreedy at udel.edu Mon Jan 26 22:51:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Jan 2009 22:51:13 -0500 Subject: Method returning an Iterable Object In-Reply-To: <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> References: <20090126180152.4a37d03f@usenot.de> <20090126202804.28c65e90@usenot.de> <1a7951080901261916m452eb95bwf267f89783981a9c@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > But how come a raise StopIteration in the next() method doesnt need to > be caught ? It works without breaking. The for-loop looks for and catches StopIteration. It is an essential part of what defines a finite iterator. (Note, in 3.0, next is renamed __next__ in conformance with all other special methods. In 2.6, the rename is optional, I believe.) > class twoTimes: > max = 10**10 > > def __init__(self, n): > self.__n = n There is no reason to mangle the attribute name. Max should be a parameter, and self.max = max added to the init. > > def next(self): > if self.__n > self.max: > raise StopIteration > self.__n *= 2 > return self.__n Are you sure you do not want to return once the initial value of n passed to init? > > def __iter__(self): > return self Once you understand the above, you can rewrite it as a generator function: def two_times(num, stop): while num < stop: yield num num *=2 The two last lines can be switches if desired. > t = twoTimes(5) > c = 0 > > print (t.next()) > print (t.next()) > > for n in t: > print n >>> print(list(two_times(5,687))) [5, 10, 20, 40, 80, 160, 320, 640] Terry Jan Reedy From prologic at shortcircuit.net.au Mon Jan 26 22:57:44 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 13:57:44 +1000 Subject: shutil module (directory input) In-Reply-To: <21679178.post@talk.nabble.com> References: <21679178.post@talk.nabble.com> Message-ID: On Tue, Jan 27, 2009 at 1:48 PM, klia wrote: > i am trying to tweak the current codes so that later when i call it from the > terminal i can provide sourcefile and the destination file rather being > fixed in the code.becuase now i have to specify the sourcefile and the > destinationfile in codes and not left to be specified from the terminal. i > want to be able to do this. > > python shutil_copy.py sourcefile, destinationfile > > code > import shutil > shutil.copyfile(srcfile, dstfile) # copy data only Have a look at the documentation for the sys module. cheers James From castironpi at gmail.com Mon Jan 26 23:23:30 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 26 Jan 2009 20:23:30 -0800 (PST) Subject: ob_type in shared memory References: <70bb8f5e-5432-4b81-b252-7497b172b0e4@g39g2000pri.googlegroups.com> <87ab9e684w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 26, 9:20?pm, Aaron Brady wrote: > Hi, Mark, snip > On Jan 25, 9:47?pm, Mark Wooding wrote:> Aaron Brady writes: > > > I am writing an extension using shared memory. ?I need a data type > > > that is able to reassign its 'ob_type' field depending on what process > > > is calling it. > > > That sounds scary! Ha ha, whoops. From ekh.johan at gmail.com Tue Jan 27 00:45:59 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 06:45:59 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> Message-ID: <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Thank you Robert, but what if I just want to create an array interactively, e.g. like m = array([1.0, 2.0, 3.0]), and pass it to my program? I tried extending optparse with a new type as explained in the link you gave me but I was not able to get it to work. Is it really neccessary follow that route just to pass an array? Lot's of people must have done this before! Best regards, Johan On Tue, Jan 27, 2009 at 1:00 AM, Robert Kern wrote: > On 2009-01-26 17:44, Johan Ekh wrote: > >> Hi all, >> I'm trying to use optparse to process command line parameters given to >> my program. >> It works as I expect for the types supported by optparse, i.e. int, >> float, string etc. but how can I >> pass a numpy.array or a list to my program? >> > > http://docs.python.org/library/optparse#optparse-extending-optparse > > Figure out the text format you want your users to type the value on the > command line, write a function that will take that text and convert it to an > array or list, then customize OptionParser to use that parser as given in > the link above. Keep in mind that your user probably won't want to need to > use whitespace or any kind of brackets. Commas are nice, though. > > You may also want to consider taking a filename and parsing that file > instead. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Jan 27 00:53:10 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 15:53:10 +1000 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > Thank you Robert, > but what if I just want to create an array interactively, e.g. like m = > array([1.0, 2.0, 3.0]), and pass it > to my program? I tried extending optparse with a new type as explained in > the link you gave me > but I was not able to get it to work. Is it really neccessary follow that > route just to pass an array? > Lot's of people must have done this before! Normally command line applications accept a number of arguments which are available in sys.argv cheers James From ekh.johan at gmail.com Tue Jan 27 01:01:38 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 07:01:38 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> Message-ID: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Thank you James, but I just can't optparse to accept an array, only integers, floats ans strings. My code looks like this from optparse import OptionParser parser = OptionParser() parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', default=0.1, help='time increment where lsoda saves results') parser.add_option('-T', '--tstop', action='store', type='float', dest='tstop_i', default=1.0, help='duration of the solution') parser.add_option('-m', '--mass_vector', action='store', type='float', dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse complains that m_i is not a float. Best regards, Johan On Tue, Jan 27, 2009 at 6:53 AM, James Mills wrote: > On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > > Thank you Robert, > > but what if I just want to create an array interactively, e.g. like m = > > array([1.0, 2.0, 3.0]), and pass it > > to my program? I tried extending optparse with a new type as explained in > > the link you gave me > > but I was not able to get it to work. Is it really neccessary follow that > > route just to pass an array? > > Lot's of people must have done this before! > > Normally command line applications accept > a number of arguments which are available > in sys.argv > > cheers > James > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Jan 27 01:07:32 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 27 Jan 2009 16:07:32 +1000 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: On Tue, Jan 27, 2009 at 4:01 PM, Johan Ekh wrote: > Thank you James, > but I just can't optparse to accept an array, only integers, floats ans > strings. > > My code looks like this > > from optparse import OptionParser > parser = OptionParser() > parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', > default=0.1, help='time increment where lsoda saves results') > parser.add_option('-T', '--tstop', action='store', type='float', > dest='tstop_i', default=1.0, help='duration of the solution') > parser.add_option('-m', '--mass_vector', action='store', type='float', > dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') > op, args = parser.parse_args(sys.argv[1:]) > > I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse > complains that m_i is not a float. What you want to do is accept a string as an argument to -m/--mass_vector and parse this string into a list. For example: parser.add_option('-m', '--mass_vector', action='store',dest='m_i', default=None, help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) if op.m_i is None: m_i = [1.0, 1.0] else: xs = m_i.split(",") m_i = [float(x.strip()) for x in xs] Of course be aware that this code does no error checking and if you pass in rubbish, it will likely throw an exception. cheers Jaems From robert.kern at gmail.com Tue Jan 27 01:12:53 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 00:12:53 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: On 2009-01-27 00:01, Johan Ekh wrote: > Thank you James, > but I just can't optparse to accept an array, only integers, floats ans > strings. > > My code looks like this > > from optparse import OptionParser > parser = OptionParser() > parser.add_option('-t', '--dt', action='store', type='float', > dest='dt_i', default=0.1, help='time increment where lsoda saves results') > parser.add_option('-T', '--tstop', action='store', type='float', > dest='tstop_i', default=1.0, help='duration of the solution') > parser.add_option('-m', '--mass_vector', action='store', type='float', > dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') > op, args = parser.parse_args(sys.argv[1:]) > > I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse > complains that m_i is not a float. Well, yes, because you declared that --mass_vector was type='float'. You will need to subclass OptionParser in order to parse something that is not one of the included types. Yes, it is a bit cumbersome; it's one of the reasons I usually use the third-party argparse library instead. You only need to supply a parsing function rather than subclass. I'm afraid I don't really understand what you want when you say that you want to create an array interactively. Can you show me an example command line that you want to parse? Keep in mind that in many shells, ()[] characters are specially handled by the shell and are not convenient for users. BTW, I am subscribed to the list. You do not need to Cc me. -- 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 martin at v.loewis.de Tue Jan 27 02:17:01 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 08:17:01 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <497E3C6F.1010909@v.loewis.de> Message-ID: <497EB4ED.1070400@v.loewis.de> > Well, the first step would be to tell Python that there is a code page > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > doing "chcp 65001". I checked the list of aliases in Python 3 and there > was no entry for cp65001. I see. What happens if you add it to encoding/aliases.py? Regards, Martin From fetchinson at googlemail.com Tue Jan 27 02:51:37 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 26 Jan 2009 23:51:37 -0800 Subject: How do I say "two classes up in the inheritance chain" in python? Message-ID: I have two classes that both inherit from two other classes which both inherit from a single class. The two children have two almost identical methods: class grandparent( object ): def meth( self ): # do something class parent1( grandparent ): def meth( self ): # do something p1 super( parent1, self ).meth( ) class parent2( grandparent ): def meth( self ): # do something p2 super( parent2, self ).meth( ) class child1( parent1 ): def meth( self ): # do something c super( parent1, self ).meth( ) # I want to invoke meth on grandparent class child2( parent2 ): def meth( self ): # do something c super( parent2, self ).meth( ) # I want to invoke meth on grandparent The meth methods in child1 and child2 are the same, except that in the last super call, one is referring to parent1, the other is referring to parent2. If they were exactly the same I could use a mixin where I could define this method, and both child1 and child2 would inherit from this mixin too. In this way I wouldn't have to code these methods twice. But how do I write this mixin? It needs to refer to the grandparent in such a way that it works in both child1 and child2 and bypasses both parent1 and parent2. How would I do that? Notes: (1) of course child1 and child2 have all sorts of methods which are different, only meth is almost the same. (2) I can't modify the grandfather class. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From duncan.booth at invalid.invalid Tue Jan 27 03:43:38 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jan 2009 08:43:38 GMT Subject: How do I say "two classes up in the inheritance chain" in python? References: Message-ID: Daniel Fetchinson wrote: > > class child1( parent1 ): > def meth( self ): > # do something c > super( parent1, self ).meth( ) # I want to invoke meth on > grandparent So just call: grandparent.meth(self) If you want to ignore the inheritance hierarchy then go ahead and ignore it. Only use super if you want to respect your parents. :) -- Duncan Booth http://kupuguy.blogspot.com From bignose+hates-spam at benfinney.id.au Tue Jan 27 04:07:26 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 27 Jan 2009 20:07:26 +1100 Subject: How do I say "two classes up in the inheritance chain" in python? References: Message-ID: <87myddyv5d.fsf@benfinney.id.au> Daniel Fetchinson writes: > The meth methods in child1 and child2 are the same, except that in > the last super call, one is referring to parent1, the other is > referring to parent2. It's important to learn that, in a language with multiple inheritance, ?superclass of this instance? is *not* the same concept as ?parent of this class?. The class you're coding may end up at any arbitrary point in a resolution chain, despite what the class inherits from. It's also important to be aware of the hairiness of Python's ?super? . -- \ ?No matter how cynical you become, it's never enough to keep | `\ up.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From ekh.johan at gmail.com Tue Jan 27 04:09:39 2009 From: ekh.johan at gmail.com (Johan Ekh) Date: Tue, 27 Jan 2009 10:09:39 +0100 Subject: optparse with numpy.array? In-Reply-To: References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> Message-ID: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Thanks, James I will try your suggestion! Robert, what mean with "interactively" is that i would like to create an array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or by reading a file with values etc., and then execute my program with "myprog -m m_i" and thus pass the array "m_i" to my program. This is just an example. I would like to pass several arrays. My program will be wrapped inside a loop and the arrays are updated in each loop. I have never heard of the "argparse" library. Do you think that it would be better to use that in my case? Best regards, Johan On Tue, Jan 27, 2009 at 7:12 AM, Robert Kern wrote: > On 2009-01-27 00:01, Johan Ekh wrote: > >> Thank you James, >> but I just can't optparse to accept an array, only integers, floats ans >> strings. >> >> My code looks like this >> >> from optparse import OptionParser >> parser = OptionParser() >> parser.add_option('-t', '--dt', action='store', type='float', >> dest='dt_i', default=0.1, help='time increment where lsoda saves results') >> parser.add_option('-T', '--tstop', action='store', type='float', >> dest='tstop_i', default=1.0, help='duration of the solution') >> parser.add_option('-m', '--mass_vector', action='store', type='float', >> dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') >> op, args = parser.parse_args(sys.argv[1:]) >> >> I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse >> complains that m_i is not a float. >> > > Well, yes, because you declared that --mass_vector was type='float'. You > will need to subclass OptionParser in order to parse something that is not > one of the included types. Yes, it is a bit cumbersome; it's one of the > reasons I usually use the third-party argparse library instead. You only > need to supply a parsing function rather than subclass. > > I'm afraid I don't really understand what you want when you say that you > want to create an array interactively. Can you show me an example command > line that you want to parse? Keep in mind that in many shells, ()[] > characters are specially handled by the shell and are not convenient for > users. > > BTW, I am subscribed to the list. You do not need to Cc me. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:14:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:14:38 +0100 Subject: How do I say "two classes up in the inheritance chain" in python? In-Reply-To: References: Message-ID: <497ed07e$0$6718$426a34cc@news.free.fr> Daniel Fetchinson a ?crit : > I have two classes that both inherit from two other classes which both > inherit from a single class. The two children have two almost > identical methods: > > class grandparent( object ): > def meth( self ): > # do something > > class parent1( grandparent ): > def meth( self ): > # do something p1 > super( parent1, self ).meth( ) > > class parent2( grandparent ): > def meth( self ): > # do something p2 > super( parent2, self ).meth( ) > > class child1( parent1 ): > def meth( self ): > # do something c > super( parent1, self ).meth( ) # I want to invoke meth on grandparent If so, it might be better to explicitly call grandparent.meth (passing self as first argument). But this is an obvious design smell IMHO. What you have is : def meth(self): do_something_more_or_less_specific call_granparent Looks like a candidate for a template method. Since you don't have hand on Grandparent, the simplest would be to add an additional base class, ie: class Abstract(Grandparent): def do_something(self): raise NotImplementedError def meth(self): self.do_something() super(Abstract, self).meth() class Parent1(Abstract): def do_something(self): # do something p1 class Parent2(Abstract): def do_something(self): # do something p2 Now you're problem is to factor out do_something() for Child1 and Child2. The solution is quite simple : just define it outside the class statements, and adds it afterward: def do_something_children(self): # code here class Child1(Parent1): # code here Child1.do_something = do_something_children class Child2(Parent2): # code here Child2.do_something = do_something_children HTH From n.kottiyath at gmail.com Tue Jan 27 04:17:33 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 01:17:33 -0800 (PST) Subject: Counting number of objects References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Thank you everyone for your very helpful comments and suggestions. I have interacted in other newsgroups, but this is the most helpful of them all. As per the comments, I have now decided to go with the weakref mechanism - as per Andreas suggestion, functionally it looks correct that the person should not know the total number of people. So, in a higher level class, have a weakref list which contains a reference to each person. Total count will be len(list) at any time. Now, I couldnt find a weakref list - so I am using WeakKeyDictionary with the value as None - since len(dict) also should give me the data any time. I have another question here. In the documentation, it is mentioned that - Note: Caution: Because a WeakKeyDictionary is built on top of a Python dictionary, it must not change size when iterating over it. This can be difficult to ensure for a WeakKeyDictionary because actions performed by the program during iteration may cause items in the dictionary to vanish "by magic" (as a side effect of garbage collection). Now, the only two operations that I am doing are -> __init__: d = weakref.WeakKeyDictionary() method y: x = aa() d[x] = None method z: total = len(d) I believe that all the commands which I perform on WeakKeyDictionary here - (adding a new element) & (len(d)) - are atomic - or atleast nothing that can cause any worry as per the Note given above. Can anyone let me know whether my assumption is correct or not? Reason: My code has many many number of threads which interact with each other in myraid ways - so I do want to decrease the number of locks as much as possible. Especially I do not want to block other threads just for getting the count. From gopalm at infotechsw.com Tue Jan 27 04:20:49 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Tue, 27 Jan 2009 14:50:49 +0530 Subject: How to get text from a surface Message-ID: <20D905D27CC0441D92672AB530252777@pwit.com> Hi, I am loading an image into pygame. i am trying to get the text from the surface. I used pyTesser to read the text from a surface/image but if the font size of the text is less then 16, it doesn't give me back the correct text from the surface. Is there any other way to get the text from the pygame surface. Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:21:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:21:36 +0100 Subject: I'm a python addict ! In-Reply-To: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <497ed220$0$6718$426a34cc@news.free.fr> Paul McGuire a ?crit : > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: >> On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: >>> Want to change the type/behavior of an object from class A to class >>> B? How about this: >>> aobj = A() >>> aobj.__class__ = B >>> Try *that* in as simple-looking C++ or Java! >> Wow. That looks very powerful and fun. But scary. Any thoughts on how >> you would use that in a way that wouldn't unleash sulphurous code >> smells? >> > > This technique is perfect for implementing the GoF State pattern. Except when it is not !-) I tried twice to use this trick in "real life" code, and in both cases, it ended up being much more complicated than implementing the state pattern the canonical way. Not to say that it's hopeless - just that there's the usual difference between theory and practice. From yinon.me at gmail.com Tue Jan 27 04:33:06 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 27 Jan 2009 01:33:06 -0800 (PST) Subject: unittest, order of test execution References: Message-ID: > But I was wondering, *should* this test be separated into two unit > tests, one for each function? On the face of it, it looks that's how it > should be done. > > This, however, raises the question: what's the order of test execution > in the unittest? And how to pass values between unit tests? Should I > modify 'self' in unit test? It's OK to run some tests in the same function. When one of the asserts fails, following the traceback will lead you straight to your problem. The order of test execution is done by default by sorting the test functions alphabetically. You may disable the sort by setting self.sortTestMethodsUsing to None. The simplest way to pass values between tests is to use the class it (self). Yinon From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 04:39:02 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 10:39:02 +0100 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <87zlhlh30r.fsf.mdw@metalzone.distorted.org.uk> <49770cf1$0$3521$426a74cc@news.free.fr> <49783d5a$0$24804$426a74cc@news.free.fr> <01886bdd$0$20671$c3e8da3@news.astraweb.com> <49787ec2$0$4751$426a74cc@news.free.fr> <01889b97$0$20671$c3e8da3@news.astraweb.com> <87ocxzdunm.fsf.mdw@metalzone.distorted.org.uk> <01892202$0$20671$c3e8da3@news.astraweb.com> <497993db$0$6847$426a74cc@news.free.fr> <6062d850-3fde-4de7-9391-1dc3f268ced6@v5g2000prm.googlegroups.com> <4979bebd$0$18836$426a34cc@news.free.fr> <5dc5ccab-c4a1-4f8a-b8c8-7f5577f76cbc@z6g2000pre.googlegroups.com> <497d7d40$0$4845$426a34cc@news.free.fr> Message-ID: <497ed636$0$27515$426a34cc@news.free.fr> Russ P. a ?crit : > On Jan 26, 1:07 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> No. I can change the *team's* code. Please *read*. "team's ownership", >> ok ? Or do I have to spell it out loud ? TEAM'S OWNERSHIP. Uh. You get >> the message, now ? > > Team ownership doesn't necessarily mean that you can just change code > at will. Nope, but it surely means that I'm *not* changing "someone else's" code. > In industry, teams usually have a leader that you need to > check with before you can change an interface. This is totally unrelated. >>> Would you give all those developers your password to get into the >>> system? No? Wait a minute ... you mean you wouldn't "trust" them with >>> your password? But what about "openness"? Are you some sort of fascist >>> or what? >> Goodwin point. You loose. Good bye again, Mr P. > > You missed the point once again. In asking if you are a "fascist," I > was *parodying* your attitude that languages with enforced access > restrictions are for "fascists" who don't trust their co-workers or > employees. [I don't recall if you actually used that word I did not, and you should know better. > or if it was > someone else, but you did use "B&D", which carries the same general > impression.] Can't you tell the difference, really ? > So I parodied your hyperbole, Still not. But it's interesting to note that you consider everyone disagreeing with you as basically the same person. From yinon.me at gmail.com Tue Jan 27 04:40:13 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 27 Jan 2009 01:40:13 -0800 (PST) Subject: unittest, order of test execution References: Message-ID: <888c2c7c-97f8-45aa-9523-25d3dd4a75a1@z28g2000prd.googlegroups.com> On Jan 27, 11:33?am, Yinon Ehrlich wrote: > > But I was wondering, *should* this test be separated into two unit > > tests, one for each function? On the face of it, it looks that's how it > > should be done. > > > This, however, raises the question: what's the order of test execution > > in the unittest? And how to pass values between unit tests? Should I > > modify 'self' in unit test? > > It's OK to run some tests in the same function. > When one of the asserts fails, following the traceback will lead you > straight to your problem. > > The order of test execution is done by default by sorting the test > functions alphabetically. > You may disable the sort by setting self.sortTestMethodsUsing to None. see: http://docs.python.org/library/unittest.html#unittest.TestLoader.sortTestMethodsUsing > The simplest way to pass values between tests is to use the class it > (self). > > ? Yinon From rajorshi at in.com Tue Jan 27 04:42:01 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Tue, 27 Jan 2009 15:12:01 +0530 Subject: =?UTF-8?B?Q2FsbGluZyBQeXRob24tdGsgY29kZSBmcm9tIEMvQysr?= Message-ID: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Hello all, This is my first post to this mailing list. Our requirement is to invoke a Tkinter python panel from a C++ GUI app where both GUI windows would run in 2 separate threads. We have written a sample PyQt application which calls this Tk panel using something like this:class TkPanel(threading.Thread):def run(self): # call showPaneldef showPanel():# create window = Tk.Tk() window.mainloop()def start():t = TkPanel()t.start()Now we call this from our main python code:def startPanel(self): import tkPanel tkPanel.start() # this calls tkwindow.mainloop() in a separate thread.This works absolutely fine when the invoking app is Python. However, we are having problems when the invoking app is in C/C++ and we use a similar logic.My question boils down to this: If I have code in C++ that has to invoke a Pythontk panel such that the panel runs in its own thread, what is the best approach?I tried studying the GIL and acquiring releasing/locks, but I must be doing something wrong. An y help would be greatly appreciated!Thanks!Rajhttp://www.rajorshi.net/blogDear pythonlist! Get Yourself a cool, short @in.com Email ID now! -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Tue Jan 27 04:45:13 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 10:45:13 +0100 Subject: optparse question References: Message-ID: * Pat (Mon, 26 Jan 2009 20:02:59 -0500) > Up until today, I never needed to pass any arguments to a Python > program. > [...] > getopt resolved my immediate need, but I would like to know how one > could use optparse to extract out the options from something like "dir > /s /b". If you actually read the documentation (it's right at the top) you knew that this is not possible: "There are many different syntaxes for options; the traditional Unix syntax is a hyphen (?-?) followed by a single letter [...] The GNU project introduced "--" [...] These are the only two option syntaxes provided by optparse. Some other option syntaxes that the world has seen include: [...] a slash followed by a letter, or a few letters, or a word, e.g. "/f", "/file" These option syntaxes are not supported by optparse, and they never will be. This is deliberate: [...] the last only makes sense if you?re exclusively targeting VMS, MS-DOS, and/or Windows." Thorsten From gandalf at shopzeus.com Tue Jan 27 04:49:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 27 Jan 2009 10:49:03 +0100 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') Message-ID: <497ED88F.9050802@shopzeus.com> I have a program that uses socket.bind() and socket.listen() frequently. After that program stops, it is not able to bind() again for a while: File "/home/gandalf/Python/Lib/orb/accesspoints/srvtcp.py", line 27, in __init__ self.serversocket.bind((self.listen_address,self.port)) File "", line 1, in bind socket.error: (48, 'Address already in use') The problem with this, is that this server program SOMETIMES need to be restarted very quickly. I tried to find the solution in the socket module. But there is no "socket.unbind" or "socket.unlisten". How can I tell the OS that I do not want to listen on that address anymore, so other programs can bind on it immediatelly? (Yes I know that I can use setsockopt to allow listening multiple sockets on the same address, but this is NOT what I need...) Thanks, Laszlo From almar.klein at gmail.com Tue Jan 27 05:22:58 2009 From: almar.klein at gmail.com (Almar Klein) Date: Tue, 27 Jan 2009 11:22:58 +0100 Subject: OpenGL in TK Message-ID: Hi list! I am using pyOpenGL to do some 3D rendering. For now I am quite happy with the GLCanvas of wx, but I may want to publish some stuff later, and it would be nice if people would not need wx. I found that there used to be a TK widget called Togl, but it is not (anymore?) included in the TK package that comes with Python. Have others been able to use Togl, or any other OpenGL widget in TK? Thanks for any help, Almar PS: I use python 2.5.2 on windows -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerb at rogerbinns.com Tue Jan 27 05:25:48 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 27 Jan 2009 02:25:48 -0800 Subject: Iterating through a file significantly slower when file has big buffer In-Reply-To: <1233013349.25395.1296882205@webmail.messagingengine.com> References: <1233013349.25395.1296882205@webmail.messagingengine.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 python at bdurham.com wrote: > The following tests were run on a Windows XP system using Python 2.6.1 Unless you changed the defaults, the Windows XP system cache size is 10MB. When you use a larger read size, chances are it is blowing out that cache and causes metadata (file block locations) to have to be reread on your next read. You are also funnelling all the data through your CPU cache with a similar effect although it will be less noticeable. To change XP cache sizes, see: http://marc.info/?l=sqlite-users&m=116743785223905&w=2 http://support.microsoft.com/kb/895932 http://www.techspot.com/tweaks/memory-winxp/ Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkl+4SkACgkQmOOfHg372QRgcACfVOdUWQGyj8xtNvHob/CtcM8g JsEAoKt/xI36iR5RuQOfZDMz2ze4L3Ia =DrDw -----END PGP SIGNATURE----- From gagsl-py2 at yahoo.com.ar Tue Jan 27 05:31:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 08:31:02 -0200 Subject: Plugin system, RuntimeWarning: Parent module 'ext_abc' not found while handling absolute import References: Message-ID: En Mon, 26 Jan 2009 17:06:20 -0200, Torsten Mohr escribi?: >> So mymodule is actually a package. Packages should *not* appear in >> sys.path. > > Oh, how does it find modules then? I thought that would be PYTHONPATH or > sys.path ? The directory CONTAINING file "foo.py" must be in sys.path if you want to import foo. The directory CONTAINING package "bar" must be in sys.path if you want to import bar. There were some threds on this topic last month, see this by example: http://groups.google.com/group/comp.lang.python/t/ed47d8e31ca3d411/ -- Gabriel Genellina From lie.1296 at gmail.com Tue Jan 27 05:31:25 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 27 Jan 2009 10:31:25 +0000 (UTC) Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On Mon, 26 Jan 2009 11:08:48 -0600, Unknown wrote: > On 2009-01-26, Lie Ryan wrote: > >> How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little >> Hardware Experience). High pitched sound (or anything in sound-ology >> that means high voltage) means the device is on and low pitched sound >> off. > > 1) Pitch has nothing to do with voltage. A high-pitch sound > and a low pitch sound can have the exact same voltage. > > 2) The OP's device requires quite a bit of power. There is > almost no power available from the line-out jack, and the voltage is > limited to about 1V. If his sound card has a power-amp (none do > these days), he might be able to get a usable amount of power. > >> The device will need an additional transistor to separate low voltage >> from the high voltage. > > He'll need more than a transistor. He needs a power supply, some sort > of rectifier/detector, and a comparitor. It would be more interesting to > use notch filters to detect different frequencies so that you could have > multiple output "bits". >From the little I know on electronics, a simple, single transistor would (almost) immediately switch from on-to-off-to-on depending on the voltage of the control pin (I think it was the middle pin). I was suggesting this simplistic hack because as far as I comprehend the OP's need, he only need on-off switch instead of a complex multiple output bits. >> I don't know how much power can be pulled from jack out, > > Almost none, and what's there is very low voltage. That's why the power is taken from USB port. >> but for a home brewn device it is still feasible to draw power from USB >> and signal from jack out. > > It would probably be easier to buy a USB-parallel port chip. Then he's > got power from the USB bus and something like 14 parallel I/O pins he > can control. Alternatively A USB-serial chip will provide 2 outputs and > 4 inputs. The idea was made on the basis that a USB microcontroller is not used. Getting power from USB should be much easier than getting data while the jack out can provide simple on-off signal. From lie.1296 at gmail.com Tue Jan 27 05:37:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 27 Jan 2009 10:37:59 +0000 (UTC) Subject: practical limits of urlopen() References: <05b6413e-8fb9-4b6c-a23b-207f72b8585d@e6g2000vbe.googlegroups.com> Message-ID: On Sat, 24 Jan 2009 09:17:10 -0800, webcomm wrote: > Hi, > > Am I going to have problems if I use urlopen() in a loop to get data > from 3000+ URLs? There will be about 2KB of data on average at each > URL. I will probably run the script about twice per day. Data from > each URL will be saved to my database. > > I'm asking because I've never opened that many URLs before in a loop. > I'm just wondering if it will be particularly taxing for my server. Is > it very uncommon to get data from so many URLs in a script? I guess > search spiders do it, so I should be able to as well? urllib doesn't have any limits, what might limit your program is your connection speed and the hardware where the server and downloader is on. Getting 3000 URLs is about 6MBs, a piece of cake for a sufficiently modern machine on a decent internet connection (the real calculation isn't that simple though, there is also some cost associated with sending and processing HTML headers). Google indexes millions of pages per day, but they also have one of the most advanced server farm in the world. From rajorshi at in.com Tue Jan 27 05:40:52 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Tue, 27 Jan 2009 16:10:52 +0530 Subject: =?UTF-8?B?Qy1QeXRob24gQVBJIHByb2JsZW0=?= Message-ID: <1233052852.4b86abe48d358ecf194c56c69108433e@mail.in.com> Hi, I was trying out the sample program to load a python script from C in the Python tutorial at http://docs.python.org/extending/embedding.html (Section: Pure Embedding).Usage: call pythonfile funcname [args] When running this script, I can run things like the following:call mytest foobut not any function which calls a Tk function:call mytest teekay Here is my mytest.py module:def foo():print "func"def teekay():import Tkinterr=Tkinter.Tkr()I get the following error in the latter case:Traceback (most recent call last):...import Tkinter ...import tkinter # If this fails your Python may not be configured for TkImportError: /software/lib/Linuxx86/python2.6/lib/python2.6/libdynload/tkinter.so: undefined symbol: PyTrueStructCall failedObviously, trying this from within a Python shell works fine.Any clues?Thanks,RajRajhttp://www.rajorshi.net/blogDear pythonlist ! Get Yourself a cool, short @in.com Email ID now! -------------- next part -------------- An HTML attachment was scrubbed... URL: From pistacchio at gmail.com Tue Jan 27 06:33:43 2009 From: pistacchio at gmail.com (gu) Date: Tue, 27 Jan 2009 12:33:43 +0100 Subject: Class behaving like a static class Message-ID: Hi to all, i have a module (a single .py file, actually), with a class called HashedDir. when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different. Eg: h1 = HashedDir('someValue') print h1.value # someValue h2 = HashedDir('someOtherValue') print h1.value # someOtherValue print h2.value # someOtherValue Any idea? Thanks in advance From murielgodoi at gmail.com Tue Jan 27 06:41:00 2009 From: murielgodoi at gmail.com (Muriel de Souza Godoi) Date: Tue, 27 Jan 2009 09:41:00 -0200 Subject: USB in python In-Reply-To: References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: Some people got success in Arduindo using an older mobile cable which works as USB/Serial converters. So you can read and write data as a serial port using pyserial. On Tue, Jan 27, 2009 at 8:31 AM, Lie Ryan wrote: > On Mon, 26 Jan 2009 11:08:48 -0600, Unknown wrote: > > > On 2009-01-26, Lie Ryan wrote: > > > >> How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little > >> Hardware Experience). High pitched sound (or anything in sound-ology > >> that means high voltage) means the device is on and low pitched sound > >> off. > > > > 1) Pitch has nothing to do with voltage. A high-pitch sound > > and a low pitch sound can have the exact same voltage. > > > > 2) The OP's device requires quite a bit of power. There is > > almost no power available from the line-out jack, and the voltage is > > limited to about 1V. If his sound card has a power-amp (none do > > these days), he might be able to get a usable amount of power. > > > >> The device will need an additional transistor to separate low voltage > >> from the high voltage. > > > > He'll need more than a transistor. He needs a power supply, some sort > > of rectifier/detector, and a comparitor. It would be more interesting to > > use notch filters to detect different frequencies so that you could have > > multiple output "bits". > > >From the little I know on electronics, a simple, single transistor would > (almost) immediately switch from on-to-off-to-on depending on the voltage > of the control pin (I think it was the middle pin). I was suggesting this > simplistic hack because as far as I comprehend the OP's need, he only > need on-off switch instead of a complex multiple output bits. > > >> I don't know how much power can be pulled from jack out, > > > > Almost none, and what's there is very low voltage. > > That's why the power is taken from USB port. > > >> but for a home brewn device it is still feasible to draw power from USB > >> and signal from jack out. > > > > It would probably be easier to buy a USB-parallel port chip. Then he's > > got power from the USB bus and something like 14 parallel I/O pins he > > can control. Alternatively A USB-serial chip will provide 2 outputs and > > 4 inputs. > > The idea was made on the basis that a USB microcontroller is not used. > Getting power from USB should be much easier than getting data while the > jack out can provide simple on-off signal. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Msc. Muriel de Souza Godoi Computation Department State University of Maring? Brazil -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Tue Jan 27 06:52:46 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 13:52:46 +0200 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') References: <497ED88F.9050802@shopzeus.com> Message-ID: <007501c98075$f9b83de0$0d00a8c0@hendrik> "Laszlo Nagy" wrote: > I have a program that uses socket.bind() and socket.listen() frequently. > After that program stops, it is not able to bind() again for a while: > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) This does the trick for me. - Hendrik From gil.shinar at gmail.com Tue Jan 27 07:00:46 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 04:00:46 -0800 (PST) Subject: Process crash with no reason References: Message-ID: On Jan 26, 8:40?pm, Philip Semanchuk wrote: > On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > > Hi All, > > > I'm running a program that is acting as a nice interface to sybase' > > replication server. The program is using the cherrypy web service for > > the GUI. The process is crashing every few days with no reason. In the > > log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > > TraceBack python's message. This program is running on solaris 9 > > machine. > > Where can I see or what can I do in order to find out what causes the > > process to crash? > > I have tried simulating a "traceBack" message and I could see this > > traceback message in one of the log files I'm using. When the process > > crashes without my help, I don't have a clue. > > Let me know if you need any other info > > Although Python isn't immune to fatal errors like you describe, I'd ? > immediately suspect a 3rd-party module instead, esp. one written in C ? > or C++. Are you using anything like that? No I do not. Is there a way to monitor who had "killed" my process? Thanks From mgbg25171 at blueyonder.co.uk Tue Jan 27 07:02:23 2009 From: mgbg25171 at blueyonder.co.uk (me) Date: Tue, 27 Jan 2009 12:02:23 +0000 Subject: creating a pattern using a previous match and a count of the number of '('s in it Message-ID: <200901271202.23170.mgbg25171@blueyonder.co.uk> I'm new to regexs and trying to get a list of all my C++ methods with balanced parenthesis as follows. #find all c++ method prototypes with a '::' in the middle #upto and including the 1st closing parenthesis pattern_upto_1st_closed_parenth = re.compile('\w+::\w+\([^)]*\)') match_upto_1st_closed_parenth = re.findall(pattern_upto_1st_closed_parenth,txt) num_of_protos = len(match_upto_1st_closed_parenth) for i in range (0,num_of_protos-1): num_of_open_parenths = match_upto_1st_closed_parenth[i].count('(') #expand the pattern to get all of the prototype #ie upto the last closed parenthesis #saying something like pattern = re.compile(\ 'match_upto_1st_closed_parenth[i]+\ (([^)]*\)){num_of_open_parenths-1}'\ ) #==================================================================== #HELP!!!!!! I'm not sure how to incorporate: #1 'match_upto_1st_closed_parenth[i]' into the above extended pattern??? #2 the count 'num_of_open_parenths' instead of a literal ??? #==================================================================== #======================================= #if I could do it this sort of this would appear to offer the neatest solution pattern_upto_last_balanced_parenthesis = re.compile(' (\w+::\w+\([^)]*\))\ ([^)]*\)){\1.count('(')-1} ') #======================================= Should I be using regexs to do this? I've only put \ line extensions to separate the pattern components to assist readability Thx From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 07:06:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 13:06:22 +0100 Subject: Class behaving like a static class In-Reply-To: References: Message-ID: <497ef8bd$0$7877$426a74cc@news.free.fr> gu a ?crit : > Hi to all, > i have a module (a single .py file, actually), with a class called > HashedDir. > > when i import the file and instanciate 2 instances of that class, when i > check the object's fields they're always the same, even if the two > objects should be different. > > Eg: > > h1 = HashedDir('someValue') > print h1.value # someValue > h2 = HashedDir('someOtherValue') > print h1.value # someOtherValue > print h2.value # someOtherValue > > Any idea? Yes : post the relevant code - or at least the minimal code that reproduces the unexpected behaviour. There are quite a couple gotchas regarding class-vs-instance-attributes and default-params, but none of them matches what you have here - at least if 'value' is an attribute set on 'self' from within the initializer. So either the above snippet is made up and you're in fact having this problem with mutable attributes (like 'value' is a list and you're appending to it) or there's something else in your code. From mail at timgolden.me.uk Tue Jan 27 07:10:01 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 27 Jan 2009 12:10:01 +0000 Subject: Process crash with no reason In-Reply-To: References: Message-ID: <497EF999.2050405@timgolden.me.uk> gil.shinar at gmail.com wrote: > On Jan 26, 8:40 pm, Philip Semanchuk wrote: >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>> Hi All, >>> I'm running a program that is acting as a nice interface to sybase' >>> replication server. The program is using the cherrypy web service for >>> the GUI. The process is crashing every few days with no reason. In the >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get any >>> TraceBack python's message. This program is running on solaris 9 >>> machine. >>> Where can I see or what can I do in order to find out what causes the >>> process to crash? >>> I have tried simulating a "traceBack" message and I could see this >>> traceback message in one of the log files I'm using. When the process >>> crashes without my help, I don't have a clue. >>> Let me know if you need any other info >> Although Python isn't immune to fatal errors like you describe, I'd >> immediately suspect a 3rd-party module instead, esp. one written in C >> or C++. Are you using anything like that? > > No I do not. Then how are you interacting with Sybase? TJG From gnewsg at gmail.com Tue Jan 27 07:52:16 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Tue, 27 Jan 2009 04:52:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> Message-ID: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> On 26 Gen, 19:16, jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) I read that I can show Unicode character in > several ways. > "\uxxxx" supposedly allows me to specify the Unicode character by hex > number and the format ?"\N{name}" allows me to specify by Unicode > name. > Neither seem to work for me. > What am I doing wrong ? > > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec ?3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information.>>> print('\u20ac') > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\python30\lib\io.py", line 1491, in write > ? ? b = encoder.encode(s) > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > > >>> print ("\N{EURO SIGN}") > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\python30\lib\io.py", line 1491, in write > ? ? b = encoder.encode(s) > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to I have this same issue on Windows. Note that on Python 2.6 it works: Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print unicode('\u20ac') \u20ac This is pretty serious, IMHO, since breaks any Windows software priting unicode to stdout. I've filed an issue on the Python bug tracker: http://bugs.python.org/issue5081 --- Giampaolo http://code.google.com/p/pyftpdlib/ From Pat at junk.net Tue Jan 27 08:01:19 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 08:01:19 -0500 Subject: optparse question References: <796ebbdf-b1ee-498e-a53e-766d97f21588@r15g2000prd.googlegroups.com> Message-ID: > > If you mean with "/" as the option designator instead of "-": there > doesn't appear to be a documented way of doing it. You would have to > do some social engineering on the users to get them used to doing "dir > -s -b". In any case I thought the number of Windows users who know how > to fire up a Command Prompt window was diminishingly small ... you > actually have users who know how to use commands like "dir /s /b"? > I used dir /s /b as a trivial Windows example. I use Windows for personal use but Ubuntu for work and programming. Personally, I use dir /s /b all the time on Windows since the /b option finds files *much* faster; maybe 10x or 100x faster but I didn't get out a stopwatch. From Pat at junk.net Tue Jan 27 08:06:47 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 08:06:47 -0500 Subject: optparse question References: Message-ID: Thorsten Kampe wrote: > * Pat (Mon, 26 Jan 2009 20:02:59 -0500) >> Up until today, I never needed to pass any arguments to a Python >> program. >> [...] >> getopt resolved my immediate need, but I would like to know how one >> could use optparse to extract out the options from something like "dir >> /s /b". > > If you actually read the documentation (it's right at the top) you knew > that this is not possible: > "There are many different syntaxes for options; the traditional Unix > syntax is a hyphen (?-?) followed by a single letter [...] The GNU > project introduced "--" [...] These are the only two option syntaxes > provided by optparse. > Some other option syntaxes that the world has seen include: > [...] > a slash followed by a letter, or a few letters, or a word, e.g. "/f", > "/file" > > These option syntaxes are not supported by optparse, and they never will > be. This is deliberate: [...] the last only makes sense if you?re > exclusively targeting VMS, MS-DOS, and/or Windows." > > Thorsten Sigh. I used dir /s /b as a simple Windows command with a flag (it could have been dir /s) because it was the first thing that popped into my mind. I had no idea people were going to get so upset that I used a Windows example and go off on a tear. From python-url at phaseit.net Tue Jan 27 08:11:06 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 27 Jan 2009 13:11:06 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jan 27) Message-ID: QOTW: "Whatever sufficiently sophisticated topic was ... initially discussed it ends all up in a request for removing reference counting and the GIL." - Kay Schluehr http://groups.google.com/group/comp.lang.python/msg/6a152ff76cf313ff Looking for a different kind of (editor|environment|interfase) like TextCalc for Python: http://groups.google.com/group/comp.lang.python/t/195ebd77f9e191e2/ Inheritance, encapsulation, and hungarian notation: http://groups.google.com/group/comp.lang.python/t/e6fc603109b42b62/ True, False, None, and the "==" and "is" operators: http://groups.google.com/group/comp.lang.python/t/21cc0e59bb59c7f1/ Mixing True/False and ints can confuse: http://groups.google.com/group/comp.lang.python/t/3185626fca2feb9b/ A short (but very interesting) essay on names, expressions, variables, and binding, by Mark Wooding: http://groups.google.com/group/comp.lang.python/t/3efb017e757bf3d9/ Using the struct module to handle variable-sized data types: http://groups.google.com/group/comp.lang.python/t/de5d94ffd953eaba/ Experienced Pythonistas give advice on improving programming skills: http://groups.google.com/group/comp.lang.python/t/4929f2681088730d/ Kaspersky mentions Python as vector for handset infection: http://www.theregister.co.uk/2009/01/22/symbian_trojan/ Running Python code on the client side from a web app: http://groups.google.com/group/comp.lang.python/t/e8131fc8a29db75c/ A new Counter class (similar to bag/multiset in other languages) was added to the collections module: http://groups.google.com/group/comp.lang.python/t/debefb159cd0752d/ The longest thread until now, started previous week. Now discussing enforced data hiding and the Scada language, team management, and who knows what (I gave up!) http://groups.google.com/group/comp.lang.python/t/68bc54bca830c46/ Another very long thread: RPython and PyPy advantages, the GIL, concurrency issues on modern CPU architectures, and removing the GIL (again!): http://groups.google.com/group/comp.lang.python/t/d8f15fad0638bca/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From denis.kasak at gmail.com Tue Jan 27 08:22:32 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Tue, 27 Jan 2009 14:22:32 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <39e19a010901270522w6a6d7eb2kdb1d04de8d6465a1@mail.gmail.com> On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' wrote: > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print unicode('\u20ac') > \u20ac Shouldn't this be print unicode(u'\u20ac') on 2.6? Without the 'u' prefix, 2.6 will just encode it as a normal (byte) string and escape the backslash. In Python 3.0 you don't need to do this because all strings are "unicode" to start with. I suspect you will see the same error with 2.6 on Windows once you correct this. (note to Giampaolo: sorry, resending this because I accidentally selected "reply" instead of "reply to all") -- Denis Kasak From apt.shansen at gmail.com Tue Jan 27 08:29:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 27 Jan 2009 05:29:55 -0800 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <7a9c25c20901270529y2663e3bel101d87cab021347a@mail.gmail.com> > > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print unicode('\u20ac') > \u20ac > Note that in Python 2.6 it expressly *does not* work, by your own example. Although I think the example is wrong and that you need to print u'\u20ac' in 2.6 unless you are importing unicode_literals from __future__; otherwise '\u20ac' is an ASCII string of 6 characters. "Works" would result, I'd think, in a unicode character being actually written to stdout: that is not happening. Instead a backslash pattern of ASCII characters meant to represent a Unicode character that -can't- be written to that stream are being written to stdout. The two aren't even kind of the same: but this is hardly something Python has a lot of control over... Windows software printing unicode to stdout was always a bit broken. IF you set the code page you could print some -- and IF you changed the font on the command prompt to a /non/-default font you could actually display others -- but it really is sort of a sucky situation, Unicode in Console windows on Windows. I really don't know how Python could do it better here: between the default code page on Windows being completely lame, the default font not supporting Unicode really... ISTM that having cross-platform apps which output unicode (really UTF8 probably) to stdout are just not really doable. But if you really want to you can always rebind sys.stdout with an error mode of "backslashreplace" or "xmlcharrefreplace" (which I do in one situation where I have a subprocess that has to output 'unicode' to a parent process) instead of 'strict'. --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Tue Jan 27 08:31:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 05:31:42 -0800 (PST) Subject: optparse question References: Message-ID: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> On Jan 28, 12:06?am, Pat wrote: > Thorsten Kampe wrote: > > * Pat (Mon, 26 Jan 2009 20:02:59 -0500) > >> Up until today, I never needed to pass any arguments to a Python > >> program. > >> [...] > >> getopt resolved my immediate need, but I would like to know how one > >> could use optparse to extract out the options from something like "dir > >> /s /b". > > > If you actually read the documentation (it's right at the top) you knew > > that this is not possible: > > "There are many different syntaxes for options; the traditional Unix > > syntax is a hyphen (?-?) followed by a single letter [...] The GNU > > project introduced "--" [...] These are the only two option syntaxes > > provided by optparse. > > Some other option syntaxes that the world has seen include: > > [...] > > a slash followed by a letter, or a few letters, or a word, e.g. "/f", > > "/file" > > > These option syntaxes are not supported by optparse, and they never will > > be. This is deliberate: [...] the last only makes sense if you?re > > exclusively targeting VMS, MS-DOS, and/or Windows." > > > Thorsten > > Sigh. ?I used dir /s /b as a simple Windows command with a flag (it > could have been dir /s) because it was the first thing that popped into > my mind. > > I had no idea people were going to get so upset that I used a Windows > example and go off on a tear. Nobody is upset, and nobody has "gone off on a tear". The point about the "Windows example" is that the docs say in a close-to-screamingly- obvious manner that /options are not supported, no matter what religion uses them. It was not, and still is not, apparent what you really wanted. We're all patiently waiting for you to rephrase the question(s). From exarkun at divmod.com Tue Jan 27 08:41:45 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 27 Jan 2009 08:41:45 -0500 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') In-Reply-To: <497ED88F.9050802@shopzeus.com> Message-ID: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> On Tue, 27 Jan 2009 10:49:03 +0100, Laszlo Nagy wrote: >I have a program that uses socket.bind() and socket.listen() frequently. >After that program stops, it is not able to bind() again for a while: > >File "/home/gandalf/Python/Lib/orb/accesspoints/srvtcp.py", line 27, in >__init__ > self.serversocket.bind((self.listen_address,self.port)) > File "", line 1, in bind >socket.error: (48, 'Address already in use') > > >The problem with this, is that this server program SOMETIMES need to be >restarted very quickly. I tried to find the solution in the socket module. >But there is no "socket.unbind" or "socket.unlisten". How can I tell the OS >that I do not want to listen on that address anymore, so other programs can >bind on it immediatelly? > >(Yes I know that I can use setsockopt to allow listening multiple sockets on >the same address, but this is NOT what I need...) Actually, SO_REUSEADDR is probably just what you want. Since I can't see your code and I don't know under what situations it fails, I can only guess at the problem, but my guess is that you have connections from the first run of your app left in the TIME_WAIT state and they are preventing you from binding to the address again in the second run of your app. Setting the SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, though). Jean-Paul From sjmachin at lexicon.net Tue Jan 27 08:45:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 05:45:00 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: On Jan 27, 11:52?pm, "Giampaolo Rodola'" wrote: > On 26 Gen, 19:16, jefm wrote: > > > > > Hi, > > while checking out Python 3, I read that all text strings are now > > natively Unicode. > > In the Python language reference (http://docs.python.org/3.0/reference/ > > lexical_analysis.html) I read that I can show Unicode character in > > several ways. > > "\uxxxx" supposedly allows me to specify the Unicode character by hex > > number and the format ?"\N{name}" allows me to specify by Unicode > > name. > > Neither seem to work for me. > > What am I doing wrong ? > > > Please see error output below where I am trying to show the EURO sign > > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > > Python 3.0 (r30:67507, Dec ?3 2008, 20:14:27) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information.>>> print('\u20ac') > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python30\lib\io.py", line 1491, in write > > ? ? b = encoder.encode(s) > > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > > position 0: character maps to > > > >>> print ("\N{EURO SIGN}") > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python30\lib\io.py", line 1491, in write > > ? ? b = encoder.encode(s) > > ? File "c:\python30\lib\encodings\cp437.py", line 19, in encode > > ? ? return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > > position 0: character maps to > > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec ?4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> print unicode('\u20ac') > > \u20ac > > This is pretty serious, IMHO, since breaks any Windows software > priting unicode to stdout. > I've filed an issue on the Python bug tracker:http://bugs.python.org/issue5081 Hello hello -- (1) that's *not* attempting to print Unicode. Look at your own output ... "\u20ac"" was printed, not a euro character!!! With 2.X for *any* X: >>> guff ='\u20ac' >>> type(guff) >>> len(guff) 6 (2) Printing Unicode to a Windows console has never *worked*; that's why this thread was pursuing the faint ray of hope offered by cp65001. From koranthala at gmail.com Tue Jan 27 08:46:25 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 27 Jan 2009 05:46:25 -0800 (PST) Subject: A Twisted Design Decision Message-ID: Twisted, being twisted in its behavior is causing quite a lot of confusion in design decisions. I will put forward a comparison of reactor and non-reactor patterns. The code is not exact - whatever is shown is the gist of it. For example, a message handler - in a usual scenario: class messageHandler: def run(): msg = self.get_next_msg() if not msg.send(): self.handle_failure() To handle parallel execution, we will have to use threads, but the code flow is similar. How do we do the same in a reactor pattern (Twisted)? msg.send will cause a deferred to be raised - the failure, if it happens will happen much later. i.e. other than sending messageHandler object in msg.send(), I cannot see any mechanism of running handle_failure. In Twisted: class messageHandler: def run(): msg = self.get_next_msg() msg.send(self): class msgClass: def send(o): d = deferred.addCallBack(success_handler, o).addErrBack (failure_handler, o) def failure_handler(o): o.handle_failure() Basically, what I find is that a lot of functional encapsulation is now lost by following reactor pattern. handle_failure is messageHandlers code and makes for pretty viewing if called from inside messageHandler itself. But, due to the twisted nature of reactor pattern, the msg Class - who is functionally a lower class to messageHandler invoking messageHandler's code. Is there a way to solve this in a more beautiful way? Am I missing something here? From exarkun at divmod.com Tue Jan 27 08:57:22 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 27 Jan 2009 08:57:22 -0500 Subject: A Twisted Design Decision In-Reply-To: Message-ID: <20090127135722.24460.256085074.divmod.quotient.2658@henry.divmod.com> On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: >Twisted, being twisted in its behavior is causing quite a lot of >confusion in design decisions. I'm not sure I agree with your premise. ;) >I will put forward a comparison of reactor and non-reactor patterns. >The code is not exact - whatever is shown is the gist of it. > >For example, a message handler - in a usual scenario: >class messageHandler: > def run(): > msg = self.get_next_msg() > if not msg.send(): > self.handle_failure() > >To handle parallel execution, we will have to use threads, but the >code flow is similar. > >How do we do the same in a reactor pattern (Twisted)? >msg.send will cause a deferred to be raised - the failure, if it >happens will happen much later. >i.e. other than sending messageHandler object in msg.send(), I cannot >see any mechanism of running handle_failure. > >In Twisted: >class messageHandler: > def run(): > msg = self.get_next_msg() > msg.send(self): > >class msgClass: > def send(o): > d = deferred.addCallBack(success_handler, o).addErrBack >(failure_handler, o) > > def failure_handler(o): > o.handle_failure() This doesn't look like a correct or faithful translation of the original. Here are two possibilities. First: class messageHandler: def run(): msg = self.get_next_msg() d = msg.send() def cbSendFailed(result): if not result: self.handle_failure() d.addErrback(cbSendFailed) return d Next: class messageHandler: @inlineCallbacks def run(): msg = self.get_next_msg() if not (yield msg.send()): self.handle_failure() These are both just straight translations from your version so as to be able to handle a Deferred from `msg.send?. >Basically, what I find is that a lot of functional encapsulation is >now lost by following reactor pattern. handle_failure is >messageHandlers code and makes for pretty viewing if called from >inside messageHandler itself. But, due to the twisted nature of >reactor pattern, the msg Class - who is functionally a lower class to >messageHandler invoking messageHandler's code. You don't need to lose anything. I don't know what your motivation was for re-arranging the code when you wrote the Twisted version, but it doesn't appear to have been necessary. >Is there a way to solve this in a more beautiful way? Am I missing >something here? > Hope this helps, Jean-Paul From alan.isaac at gmail.com Tue Jan 27 09:05:34 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 27 Jan 2009 14:05:34 GMT Subject: print formating for matrix/table In-Reply-To: References: <77e831100901261618n1a7a2efdj1f490ab0a5f3bab3@mail.gmail.com> Message-ID: You could try SimpleTable: http://code.google.com/p/econpy/source/browse/trunk/utilities/text.py fwiw, Alan Isaac From fakeaddress at nowhere.org Tue Jan 27 09:25:51 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 27 Jan 2009 06:25:51 -0800 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? In-Reply-To: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> References: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Steve Holden writes: > >> No, you aren't mistaken. Looking at the "*" symbol in the 2.6 >> documentation index it lists only two references. The first is the >> language manual's explanation of its use in the def statement, the >> second is a transitory reference to its use in function calls, but >> that's in the tutorial where it is not likely to get much attention. > > There's a full description of it in 5.4.3 in the Language Reference, but > apparently not indexed. So I guess this means I can duck out of writing up a lecture on my own understanding of Python's extended call syntax. Great. I think I grock the extended call syntax, and when the question came up I was surprised not to be able to find where I learned it. Mark, where exactly does one look to see this "full description"? -- --Bryan From kyrie at uh.cu Tue Jan 27 09:31:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 09:31:11 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <497ed636$0$27515$426a34cc@news.free.fr> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <497ed636$0$27515$426a34cc@news.free.fr> Message-ID: <200901270931.11979.kyrie@uh.cu> On Tuesday 27 January 2009 04:39:02 am Bruno Desthuilliers wrote: > Still not. But it's interesting to note that you consider everyone > disagreeing with you as basically the same person. Hehe. At the beginning of this thread, I also thought that Russ P. and Paul Robin were the same person. I have serious problems with names. [My apologies to both of you, if I said something that made you notice my confusion]. P.S: Just to be clear, I'm neither Russ P. nor Paul Robin :D -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From jcd at sdf.lonestar.org Tue Jan 27 09:46:42 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 27 Jan 2009 09:46:42 -0500 Subject: is None vs. == None In-Reply-To: References: <018a4dc6$0$20629$c3e8da3@news.astraweb.com> <497A609F.4030700@islandtraining.com> Message-ID: <1233067602.4143.1.camel@aalcdl07.lib.unc.edu> On Fri, 2009-01-23 at 19:31 -0500, Benjamin Kaplan wrote: > > > On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron > wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a comment recommending > using is > >> None instead of == None (also is not None, > etc.) > >> > > > > That entirely depends on whether you wish to test for > something which > > *is* None or something with *equals* None. Those two things > have > > different meanings. > > > > > Actually, for None, those two things *are* the same. If > something > *equals* None, it also *is* None. This is a consequence of > the fact > that there is only ever one value of None anywhere in the > system. > > Not if someone decided to be a PITA. > > >>> class A(object) : > ... def __eq__(self, other) : > ... return other is None > ... > >>> a = A() > >>> a == None > True > >>> a is None > False > > or slightly less PITAish: class EqualThing(object): def __eq__(self, other): return True Could be a useful sentinel value in some cases. > > > > I wonder, do newbies actually get the impression from > somewhere that "is" > > is a synonym for "=="? > > > > > Yes. Such questions pop up regularly, and are usually dealt > with quickly. > > > > > > > > >> My own > >> testing indicates that the former beats the latter by about > 30% on > >> average. Not a log for a single instruction but it can add > up in large > >> projects. > >> > > > > If you have a "large" project where the time taken to do > comparisons to > > None is a significant portion of the total time, I'd be very > surprised. > > > > var is None is a micro-optimization, but that's not why we > do it. We do > > it because usually the correct test is whether var *is* None > and not > > merely equal to None. Any random object might happen to > equal None > > (admittedly most objects don't), but only None is None. > > > > > You don't have that quite right. The only way something can > *equal* > None is if it *is* None. > None is not a value an object can have, but rather it is a > (singleton) > object that can be referenced. Setting something *equal* to > None is > accomplished by making it refer to the single None object, at > which > point it *is* None. > > Gary Herron > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From philip at semanchuk.com Tue Jan 27 10:00:24 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 10:00:24 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: On Jan 27, 2009, at 7:00 AM, gil.shinar at gmail.com wrote: > On Jan 26, 8:40 pm, Philip Semanchuk wrote: >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>> Hi All, >> >>> I'm running a program that is acting as a nice interface to sybase' >>> replication server. The program is using the cherrypy web service >>> for >>> the GUI. The process is crashing every few days with no reason. In >>> the >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get >>> any >>> TraceBack python's message. This program is running on solaris 9 >>> machine. >>> Where can I see or what can I do in order to find out what causes >>> the >>> process to crash? >>> I have tried simulating a "traceBack" message and I could see this >>> traceback message in one of the log files I'm using. When the >>> process >>> crashes without my help, I don't have a clue. >>> Let me know if you need any other info >> >> Although Python isn't immune to fatal errors like you describe, I'd >> immediately suspect a 3rd-party module instead, esp. one written in C >> or C++. Are you using anything like that? > > No I do not. But you're using CherryPy, aren't you? And as Tim Golden pointed out, you're probably using another 3rd party lib to talk to Sybase. ISTR that CherryPy is written in pure Python but if you have a database adapter lib it probably isn't. > Is there a way to monitor who had "killed" my process? That's more of a Solaris question than a Python one, and I don't know much about Solaris. Is there a system log where Solaris records when & why it has killed errant processes? From rantingrick at gmail.com Tue Jan 27 10:07:19 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:07:19 -0800 (PST) Subject: How many followers of comp.lang.python Message-ID: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> I curious of how many are "really" out there. I have been watching the list for some time but basically see the same 10 or so people answering questions. Reply to this message so we can see how many exists here Thanks From kyosohma at gmail.com Tue Jan 27 10:10:43 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 07:10:43 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> Message-ID: <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> On Jan 27, 9:07?am, rantingrick wrote: > I curious of how many are "really" out there. I have been watching the > list for some time but basically see the same 10 or so people > answering questions. > > Reply to this message so we can see how many exists here > > Thanks I'm not sure how you arrived at that low number. If you go to the main page on the Google Groups version, you'll count at least 20 on page 1: http://groups.google.com/group/comp.lang.python/topics Mike From rantingrick at gmail.com Tue Jan 27 10:17:38 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:17:38 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> Message-ID: <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> I also looked at Guido's profile and he has not posted a message here since 2000. WOW! I know he way ahead of "us" here but why has he not drooped in for a chat with the python community? Matz(the creator of Ruby), is a regular at comp.lang.ruby. This makes me wonder if Guido thinks comp.lang.python is a dead Parrot (but there could be other reasons?) From mail at microcorp.co.za Tue Jan 27 10:29:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 17:29:37 +0200 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> Message-ID: <004e01c98095$f90f9440$0d00a8c0@hendrik> "Jean-Paul Calderone" wrote: 8<------------------------------ > ....... Setting the > SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, > though). Why not? I have been merrily setting it, and I have not noticed anything weird. (yet) - Hendrik From gil.shinar at gmail.com Tue Jan 27 10:34:29 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 07:34:29 -0800 (PST) Subject: Process crash with no reason References: Message-ID: On Jan 27, 2:10?pm, Tim Golden wrote: > gil.shi... at gmail.com wrote: > > On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>> Hi All, > >>> I'm running a program that is acting as a nice interface to sybase' > >>> replication server. The program is using the cherrypy web service for > >>> the GUI. The process is crashing every few days with no reason. In the > >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get any > >>> TraceBack python's message. This program is running on solaris 9 > >>> machine. > >>> Where can I see or what can I do in order to find out what causes the > >>> process to crash? > >>> I have tried simulating a "traceBack" message and I could see this > >>> traceback message in one of the log files I'm using. When the process > >>> crashes without my help, I don't have a clue. > >>> Let me know if you need any other info > >> Although Python isn't immune to fatal errors like you describe, I'd ? > >> immediately suspect a 3rd-party module instead, esp. one written in C ? > >> or C++. Are you using anything like that? > > > No I do not. > > Then how are you interacting with Sybase? > > TJG I'm using python's functions to run sybase sql commands. Thanks From fakeaddress at nowhere.org Tue Jan 27 10:35:46 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 27 Jan 2009 07:35:46 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x63k5chho.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >> An object's __dict__ slot is *not* mutable; thus we could gain some >> efficiency by protecting the object and its dict with the same lock. I >> do not see a major win in Mr. Banks' point that we do not need to lock >> the object, just its dict. > > If the dict contents don't change often, maybe we could use an > STM-like approach to eliminate locks when reading. That would of > course require rework to just about every C function that accesses > Python objects. I'm a fan of lock-free data structure and software transactional memory, but I'm also a realist. Heck, I'm one of this group's outspoken advocates of threaded architectures. Theoretical breakthroughs will happen, but in real world of today, threads are great but GIL-less Python is a loser. Wherever Python is going, let's recognize that a scripting language that rocks is better than any other kind of language that sucks. -- --Bryan From gil.shinar at gmail.com Tue Jan 27 10:39:50 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Tue, 27 Jan 2009 07:39:50 -0800 (PST) Subject: Process crash with no reason References: Message-ID: <79c0e7f0-3629-4286-9dc8-4ce6bf94eac5@40g2000prx.googlegroups.com> On Jan 27, 5:00?pm, Philip Semanchuk wrote: > On Jan 27, 2009, at 7:00 AM, gil.shi... at gmail.com wrote: > > > > > On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>> Hi All, > > >>> I'm running a program that is acting as a nice interface to sybase' > >>> replication server. The program is using the cherrypy web service ? > >>> for > >>> the GUI. The process is crashing every few days with no reason. In ? > >>> the > >>> log I can see INFO and DEBUG (No ERROR) log lines and I do not get ? > >>> any > >>> TraceBack python's message. This program is running on solaris 9 > >>> machine. > >>> Where can I see or what can I do in order to find out what causes ? > >>> the > >>> process to crash? > >>> I have tried simulating a "traceBack" message and I could see this > >>> traceback message in one of the log files I'm using. When the ? > >>> process > >>> crashes without my help, I don't have a clue. > >>> Let me know if you need any other info > > >> Although Python isn't immune to fatal errors like you describe, I'd > >> immediately suspect a 3rd-party module instead, esp. one written in C > >> or C++. Are you using anything like that? > > > No I do not. > > But you're using CherryPy, aren't you? And as Tim Golden pointed out, ? > you're probably using another 3rd party lib to talk to Sybase. ISTR ? > that CherryPy is written in pure Python but if you have a database ? > adapter lib it probably isn't. > > > Is there a way to monitor who had "killed" my process? > > That's more of a Solaris question than a Python one, and I don't know ? > much about Solaris. Is there a system log where Solaris records when & ? > why it has killed errant processes? Yes I am using CherryPy. One of the developers I'm working with thinks it is a cherrypy issue. Our python process has nothing to do if cherrypy is stuck or down. But still, it is strange that there are no leftovers from the crashed process. Solaris has system logs that has nothing in them about this process. Any other suggestion will be great. Thanks From mail at microcorp.co.za Tue Jan 27 10:42:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 17:42:10 +0200 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com><497ed636$0$27515$426a34cc@news.free.fr> <200901270931.11979.kyrie@uh.cu> Message-ID: <004f01c98095$f9a6a420$0d00a8c0@hendrik> "Luis Zarrabeitia" wrote: 8<------------------------ >Hehe. At the beginning of this thread, I also thought that Russ P. and Paul >Robin were the same person. I have serious problems with names. *nods in agreement, because the man's surname is Rubin, not Robin* :-) - Hendrik From rantingrick at gmail.com Tue Jan 27 10:42:41 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:42:41 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Seems like the only thing people are interested in is bickering and name calling. I noticed the post "Does Python really follow..." has over 400 post mainly from the same 10 people. Maybe this is why Guido no longer wishes to be a part of this group. Where is the sense of community here? Anybody care to correct me, because i would love to be wrong about this, but i fear i am 100% correct. From kyosohma at gmail.com Tue Jan 27 10:43:55 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 07:43:55 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: On Jan 27, 9:17?am, rantingrick wrote: > I also looked at Guido's profile and he has not posted a message here > since 2000. WOW! I know he way ahead of "us" here but why has he not > drooped in for a chat with the python community? Matz(the creator of > Ruby), is a regular at comp.lang.ruby. > > This makes me wonder if Guido thinks comp.lang.python is a dead Parrot > (but there could be other reasons?) I've seen him on the distutils list, but I think he generally keeps to the dev lists mostly. This list is for general users (i.e. mostly newbs). We do get some good discussions going on more esoteric subjects like memoization, but for the most part, it's posts like how do I do x if y is z, what's the best Python IDE, which is the best Python GUI toolkit, I hate the GIL, what's a web framework, etc. I think Guido has better things to do...and his employer probably doesn't want him spending all day answering stuff like that. Mike From benjamin.kaplan at case.edu Tue Jan 27 10:52:30 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 10:52:30 -0500 Subject: How many followers of comp.lang.python In-Reply-To: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 10:42 AM, rantingrick wrote: > Seems like the only thing people are interested in is bickering and > name calling. I noticed the post "Does Python really follow..." has > over 400 post mainly from the same 10 people. Maybe this is why Guido > no longer wishes to be a part of this group. Where is the sense of > community here? > > Anybody care to correct me, because i would love to be wrong about > this, but i fear i am 100% correct. there is a sense of community here. It just doesn't extend to everyone joining in the flame war. That particular thread moved from talking about difficult to read python code to a not very friendly debate about whether Python needs to have enforced data hiding to be a good language. After the first couple hundred posts and when the name calling started, I, for one, started ignoring those posts. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Tue Jan 27 10:57:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jan 2009 15:57:55 +0000 Subject: creating a pattern using a previous match and a count of the number of '('s in it In-Reply-To: <200901271202.23170.mgbg25171@blueyonder.co.uk> References: <200901271202.23170.mgbg25171@blueyonder.co.uk> Message-ID: <497F2F03.9050806@mrabarnett.plus.com> me wrote: > > I'm new to regexs and trying to get a list of all my C++ methods with balanced > parenthesis as follows. > > > #find all c++ method prototypes with a '::' in the middle > #upto and including the 1st closing parenthesis > pattern_upto_1st_closed_parenth = re.compile('\w+::\w+\([^)]*\)') > match_upto_1st_closed_parenth = > re.findall(pattern_upto_1st_closed_parenth,txt) > num_of_protos = len(match_upto_1st_closed_parenth) > > for i in range (0,num_of_protos-1): This should actually be range(0, num_of_protos). > num_of_open_parenths = match_upto_1st_closed_parenth[i].count('(') > > #expand the pattern to get all of the prototype > #ie upto the last closed parenthesis > #saying something like > pattern = re.compile(\ > 'match_upto_1st_closed_parenth[i]+\ > (([^)]*\)){num_of_open_parenths-1}'\ > ) > #==================================================================== > #HELP!!!!!! I'm not sure how to incorporate: > #1 'match_upto_1st_closed_parenth[i]' into the above extended pattern??? > #2 the count 'num_of_open_parenths' instead of a literal ??? > #==================================================================== > > > > > #======================================= > #if I could do it this sort of this would appear to offer the neatest solution > pattern_upto_last_balanced_parenthesis = re.compile(' > (\w+::\w+\([^)]*\))\ > ([^)]*\)){\1.count('(')-1} > ') > #======================================= > > Should I be using regexs to do this? > > I've only put \ line extensions to separate the pattern components to assist > readability > > Thx > > Not necessarily the best way, but: methods = [] # The pattern for the start of the method's header. start_pattern = re.compile(r'\w+::\w+\([^)]*\)') # Start at the beginning of the text. pos = 0 while True: # Search for the start of the next method's header. start_match = start_pattern.search(txt, pos) if not start_match: break # Search for the end of the method's header. end_pattern = re.compile(r'(?:[^)]*\)){%d}' % start_match.group().count('(')) end_match = end_pattern.search(txt, pos) methods.append(txt[start_match.start() : end_match.end()]) # Continue the next search from where we left off. pos = end_match.end() From rantingrick at gmail.com Tue Jan 27 10:58:58 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 07:58:58 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: On Jan 27, 9:43?am, Mike Driscoll wrote: > I think Guido has better things to do...and his employer probably > doesn't want him spending all day answering stuff like that. > Mike I totally agree, and i would never expect him to field noob questions but i just thought it odd he has not dropped by in over 9 years. I have seen his blog but i wonder why he does not blog here. Seems like the best place in the world to get feedback from Python users is here. He could start some very interesting subjects. To at least, this medium is more of a "personal" exchange, than a blog. From philip at semanchuk.com Tue Jan 27 10:59:55 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 10:59:55 -0500 Subject: Process crash with no reason In-Reply-To: References: Message-ID: On Jan 27, 2009, at 10:34 AM, gil.shinar at gmail.com wrote: > On Jan 27, 2:10 pm, Tim Golden wrote: >> gil.shi... at gmail.com wrote: >>> On Jan 26, 8:40 pm, Philip Semanchuk wrote: >>>> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: >> >>>>> Hi All, >>>>> I'm running a program that is acting as a nice interface to >>>>> sybase' >>>>> replication server. The program is using the cherrypy web >>>>> service for >>>>> the GUI. The process is crashing every few days with no reason. >>>>> In the >>>>> log I can see INFO and DEBUG (No ERROR) log lines and I do not >>>>> get any >>>>> TraceBack python's message. This program is running on solaris 9 >>>>> machine. >>>>> Where can I see or what can I do in order to find out what >>>>> causes the >>>>> process to crash? >>>>> I have tried simulating a "traceBack" message and I could see this >>>>> traceback message in one of the log files I'm using. When the >>>>> process >>>>> crashes without my help, I don't have a clue. >>>>> Let me know if you need any other info >>>> Although Python isn't immune to fatal errors like you describe, I'd >>>> immediately suspect a 3rd-party module instead, esp. one written >>>> in C >>>> or C++. Are you using anything like that? >> >>> No I do not. >> >> Then how are you interacting with Sybase? > > I'm using python's functions to run sybase sql commands. Can you give a short code sample? I'm unaware of how one would use the standard Python library to talk to Sybase, unless Sybase has a raw socket interface or some such. From invalid at invalid Tue Jan 27 11:05:15 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 27 Jan 2009 10:05:15 -0600 Subject: USB in python References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: On 2009-01-27, Lie Ryan wrote: > From the little I know on electronics, a simple, single > transistor would (almost) immediately switch from > on-to-off-to-on depending on the voltage of the control pin (I > think it was the middle pin). I was suggesting this > simplistic hack because as far as I comprehend the OP's need, > he only need on-off switch instead of a complex multiple > output bits. The audio output jack outputs AC (alternating current). If you put AC into a transistor, you get AC out. Hence the need for a rectifier/detector to convert the AC signal into a DC level. To reliably get an on-off state from an analog DC level, you need something with some hystersis (e.g. a comparitor). Depending on the requirements it may possible to do impliment a comparitor with hysteresis using a single transistor. If you're looking for a digital output signal whose DC level you can contol, then either the printer port or the serial port is a better option than using the sound-card's line-out which is an analog AC output. >>> I don't know how much power can be pulled from jack out, >> >> Almost none, and what's there is very low voltage. > > That's why the power is taken from USB port. > >>> but for a home brewn device it is still feasible to draw power >>> from USB and signal from jack out. >> >> It would probably be easier to buy a USB-parallel port chip. >> Then he's got power from the USB bus and something like 14 >> parallel I/O pins he can control. Alternatively A USB-serial >> chip will provide 2 outputs and 4 inputs. > > The idea was made on the basis that a USB microcontroller is > not used. I didn't say anything about using a USB microcontroller. There are dead-simple and cheap USB-serial and USB-parallel chips that you can buy that provide the equivalent of a serial port or parallel printer port via USB. > Getting power from USB should be much easier than getting data Using a USB-serial or USB-parallel chip isn't really much harder than getting power from the USB port, and it's simpler than building a detector/comparity circuit to connect to the audio line-out. > while the jack out can provide simple on-off signal. With the addition of a rectifier/detector and an appropriate comparitor circuit, yes. -- Grant Edwards grante Yow! Civilization is fun! at Anyway, it keeps me busy!! visi.com From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 11:12:18 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 17:12:18 +0100 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> Message-ID: <497f3260$0$3671$426a74cc@news.free.fr> rantingrick a ?crit : > On Jan 27, 9:43 am, Mike Driscoll wrote: > >> I think Guido has better things to do...and his employer probably >> doesn't want him spending all day answering stuff like that. >> Mike > > I totally agree, and i would never expect him to field noob questions > but i just thought it odd he has not dropped by in over 9 years. All you can say is that he didn't *post* here (at least under his real identity...) for the 9 past years - this doesn't mean he never *reads* (and this, you just have no way to know). From bruno.42.desthuilliers at websiteburo.invalid Tue Jan 27 11:26:20 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jan 2009 17:26:20 +0100 Subject: How many followers of comp.lang.python In-Reply-To: <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: <497f35aa$0$6733$426a74cc@news.free.fr> rantingrick a ?crit : > Seems like the only thing people are interested in is bickering and > name calling. I noticed the post "Does Python really follow..." has > over 400 post mainly from the same 10 people. There are occasionally such kind of threads, indeed. And, as Mike mentionned, the usual FAQs (some of them twice or more each week, year after year). And sometimes more interesting questions - but that does not necessarily makes long thread, so they perhaps are too low for your radar. > Maybe this is why Guido > no longer wishes to be a part of this group. I've been lurking here for years (about early 2000 IIRC), and don't remember a single post from the BDFL here. But: > Where is the sense of > community here? If you set the occasional trolls aside, this group is usually newbie-friendly and helpful one. You'll find quite a few posts by long-time, experienced and talented Python programmers (and core developpers). As far as I'm concerned, I learned (and I'm still learning) quite a lot here. Please visit comp.databases or comp.lang.javascript for really unfriendly and unhelpful places where few happens except "bickering and name-calling". > Anybody care to correct me, because i would love to be wrong about > this, but i fear i am 100% correct. Well, why don't you just try and post a couple practical questions here? From koranthala at gmail.com Tue Jan 27 11:27:04 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 27 Jan 2009 08:27:04 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <6d674190-4692-42e0-91ba-0ca5ca4dd0d3@n33g2000pri.googlegroups.com> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: > >Twisted, being twisted in its behavior is causing quite a lot of > >confusion in design decisions. > > I'm not sure I agree with your premise. ;) > > > > >I will put forward a comparison of reactor and non-reactor patterns. > >The code is not exact - whatever is shown is the gist of it. > > >For example, a message handler - in a usual scenario: > >class messageHandler: > > ? def run(): > > ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? if not msg.send(): > > ? ? ? ? ? ? self.handle_failure() > > >To handle parallel execution, we will have to use threads, but the > >code flow is similar. > > >How do we do the same in a reactor pattern (Twisted)? > >msg.send will cause a deferred to be raised - the failure, if it > >happens will happen much later. > >i.e. other than sending messageHandler object in msg.send(), I cannot > >see any mechanism of running handle_failure. > > >In Twisted: > >class messageHandler: > > ? def run(): > > ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? msg.send(self): > > >class msgClass: > > ? ?def send(o): > > ? ? ? ?d = deferred.addCallBack(success_handler, o).addErrBack > >(failure_handler, o) > > > ? ?def failure_handler(o): > > ? ? ? ?o.handle_failure() > > This doesn't look like a correct or faithful translation of the original. > Here are two possibilities. ?First: > > ? ? class messageHandler: > ? ? ? ? def run(): > ? ? ? ? ? ? msg = self.get_next_msg() > ? ? ? ? ? ? d = msg.send() > ? ? ? ? ? ? def cbSendFailed(result): > ? ? ? ? ? ? ? ? if not result: > ? ? ? ? ? ? ? ? ? ? self.handle_failure() > ? ? ? ? ? ? d.addErrback(cbSendFailed) > ? ? ? ? ? ? return d > > Next: > > ? ? class messageHandler: > ? ? ? ? @inlineCallbacks > ? ? ? ? def run(): > ? ? ? ? ? ? msg = self.get_next_msg() > ? ? ? ? ? ? if not (yield msg.send()): > ? ? ? ? ? ? ? ? self.handle_failure() > > These are both just straight translations from your version so as to > be able to handle a Deferred from `msg.send?. > > >Basically, what I find is that a lot of functional encapsulation is > >now lost by following reactor pattern. handle_failure is > >messageHandlers code and makes for pretty viewing if called from > >inside messageHandler itself. But, due to the twisted nature of > >reactor pattern, the msg Class - who is functionally a lower class to > >messageHandler invoking messageHandler's code. > > You don't need to lose anything. ?I don't know what your motivation was > for re-arranging the code when you wrote the Twisted version, but it doesn't > appear to have been necessary. > > >Is there a way to solve this in a more beautiful way? Am I missing > >something here? > > Hope this helps, > > Jean-Paul Thank you Jean-Paul. My code is more complex than what I have mentioned. When I mentioned msg.send, the msg object actually gets the data from DB etc to send. And there are many other items being done. I will try to see whether I can change the code to incorporate what you mentioned. I rewrote most of my code after learning just raw deferreds - I had planned to study inlineCallbacks - but then it slipped my mind - now it has come to bit me. :-( From lists at pern.co.uk Tue Jan 27 11:27:27 2009 From: lists at pern.co.uk (David Anderson) Date: Tue, 27 Jan 2009 16:27:27 +0000 Subject: Pexpect and telnet not communicating properly Message-ID: <497f35ef$0$30312$da0feed9@news.zen.co.uk> I am trying to automate the following session - to talk to my router: ======================= telnet speedtouch Trying 192.168.1.254... Connected to speedtouch. Escape character is '^]'. Username : Administrator Password : ------------------------------------------------------------------------ ______ SpeedTouch 780 ___/_____/\ / /\ 6.1.7.2 _____/__ / \ _/ /\_____/___ \ Copyright (c) 1999-2006, THOMSON // / \ /\ \ _______//_______/ \ / _\/______ / / \ \ / / / /\ __/ / \ \ / / / / _\__ / / / \_______\/ / / / / /\ /_/______/___________________/ /________/ /___/ \ \ \ \ ___________ \ \ \ \ \ / \_\ \ / /\ \ \ \ \___\/ \ \/ / \ \ \ \ / \_____/ / \ \ \________\/ /__________/ \ \ / \ _____ \ /_____\/ \ / /\ \ /___\/ /____/ \ \ / \ \ /___\/ \____\/ ------------------------------------------------------------------------ _{Administrator}=>? Following commands are available : help : Displays this help information menu : Displays menu ? : Displays this help information exit : Exits this shell. .. : Exits group selection. saveall : Saves current configuration. ping : Send ICMP ECHO_REQUEST packets. traceroute : Send ICMP/UDP packets to trace the ip path. Following command groups are available : firewall service autopvc connection cwmp dhcp dns dsd dyndns eth adsl atm config debug env expr grp hostmgr ids igmp interface ip ipqos label language mbus memm mlp nat ppp pptp script snmp sntp software system systemlog upgrade upnp user voice wireless {Administrator}=>exit ======================== I am using the following code: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn('telnet 192.168.1.254') fout = file('mylog.txt','w') child.logfile = fout child.expect('sername : ') child.sendline('Administrator') child.expect('assword : ') child.sendline('') child.expect('_{Administrator}=>') child.sendline('?') child.expect('_{Administrator}=>') child.expect('exit') ======================== This times out after child.sendline('Administrator') mylog.txt contains: Trying 192.168.1.254... Connected to 192.168.1.254. Escape character is '^]'. Username : Administrator Administrator ======================== Can anyone help me in finding out what I am doing wrong? Regards David From claird at lairds.us Tue Jan 27 11:29:27 2009 From: claird at lairds.us (Cameron Laird) Date: Tue, 27 Jan 2009 16:29:27 +0000 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> Message-ID: <7cp356-c7d.ln1@lairds.us> In article <8692c77c-0498-4c68-940f-e4d4427f3f08 at x37g2000yqj.googlegroups.com>, rantingrick wrote: >Seems like the only thing people are interested in is bickering and >name calling. I noticed the post "Does Python really follow..." has >over 400 post mainly from the same 10 people. Maybe this is why Guido >no longer wishes to be a part of this group. Where is the sense of >community here? > >Anybody care to correct me, because i would love to be wrong about >this, but i fear i am 100% correct. Which "this"? Are you asking for evidence that more than ten people regularly read comp.lang.python, OR that there is traffic in comp.lang.python other than bickering and name-calling? My own rough estimate of readership is at least 4,000. If motivated, one could refine the figure, I'm confident). From jcd at sdf.lonestar.org Tue Jan 27 11:37:35 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 27 Jan 2009 11:37:35 -0500 Subject: v = json.loads("{'test':'test'}") In-Reply-To: <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com> <9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com> Message-ID: <1233074255.4143.15.camel@aalcdl07.lib.unc.edu> On Sun, 2009-01-25 at 14:28 -0800, gert wrote: > On Jan 25, 11:16 pm, ?????? ??????????? wrote: > > > raise ValueError(errmsg("Expecting property name", s, end)) > > >http://docs.python.org/library/json.html > > > What am I doing wrong ? > > > > try this > > v = json.loads('{"test":"test"}') > > > > JSON doesn't support single quotes, only double quotes. > > the funny part is when you print(v) you get > {'test': 'test'} > > Single quotes works in every browser that support json so i > recommended python should support it too, besides it looks much > cleaner > {'test': 'test'} > {"test": "test"} > > It can not be that hard to support both notation can it ? It's not that hard, but it does add a noticeable level of complexity to the process. In JSON, you simply tell the parser, "if you see a double-quote character, we're now parsing a string. When you see another (unescaped) double-quote character, the string is done. The equivalent version for your extended JSON would say, "if you see a quote character of either kind, we're parsing a string. When you see another (unescaped) quote character of either kind, the string is done." But that doesn't work, because it would allow {'test": "test'}. So the parser has to remember which quote character is being used, and require those characters to be escaped, and not the other (but then does "te \'st" render as r"te'st" or r"te\'st"?) and only close the string when the appropriate quote is found. Not an impossible task, but certainly more complex than the current parsing requirements for JSON. Cheers, Cliff From Scott.Daniels at Acm.Org Tue Jan 27 11:40:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 27 Jan 2009 08:40:27 -0800 Subject: Counting number of objects In-Reply-To: References: <20090125190647.13bf4a71@usenot.de> <87myde6bda.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Kottiyath wrote: > So, in a higher level class, have a weakref list which contains a > reference to each person. Total count will be len(list) at any time. > > Now, I couldnt find a weakref list - so I am using WeakKeyDictionary > with the value as None - since len(dict) also should give me the data I typically use a WeakValueDictionary, with the key id(obj). ... > Now, the only two operations that I am doing are -> > __init__: > d = weakref.WeakKeyDictionary() > > method y: > x = aa() > d[x] = None > > method z: > total = len(d) At least at one point, the WeakValueDictionary was more stable. I don't remember the details, but I remember my work-around. If you do have troubles, try using almost the same code you now use, but substitute for the obvious lines above: d = weakref.WeakValueDictionary() and d[id(x)] = x --Scott David Daniels Scott.Daniels at Acm.Org From jay.amorin at gmail.com Tue Jan 27 11:41:11 2009 From: jay.amorin at gmail.com (Jay Jesus Amorin) Date: Wed, 28 Jan 2009 00:41:11 +0800 Subject: [xlrd] sanitize the output and store in a 2d arrays Message-ID: Hi gurus, Script: #!/usr/bin/python import xlrd, sys def main(toParse): workBook = xlrd.open_workbook(toParse) mySheet = workBook.sheet_by_index(0) for rownum in range(mySheet.nrows): print mySheet.row_values(rownum) if __name__ == '__main__': if len(sys.argv) < 2: sys.stderr.write("Usage: %s EXCEL.XLS\n" % (sys.argv[0])) else: main(sys.argv[1]) Output: myuser at testsvr:~> ./parse.py test.xls *[u'*thisislineone*'*, 343*.0]* *[u'*thisislinetwo*'*, 344*.0]* *[u'*thisislinethree*'*, 345*.0]* This is the content of my test.xls: thisislineone 343 thisislinetwo 344 thisislinethree 345 How do i remove the bold part of the output (*[u'*. *'* and *.0]* and store the output in a 2 dimensional array? Many thanks. PythonNewbie, Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Jan 27 11:42:52 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 16:42:52 +0000 Subject: Doc for extended call syntax; was: Re: unzip array of arrays? References: <87wscj6trp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87skn41z03.fsf.mdw@metalzone.distorted.org.uk> Bryan Olson writes: > Mark Wooding wrote: >> There's a full description of it in 5.4.3 in the Language Reference, but >> apparently not indexed. > > So I guess this means I can duck out of writing up a lecture on my own > understanding of Python's extended call syntax. Great. > > I think I grock the extended call syntax, and when the question came > up I was surprised not to be able to find where I learned it. Mark, > where exactly does one look to see this "full description"? I typoed, sorry! I should have written 5.3.4: http://www.python.org/doc/2.5/ref/calls.html The description of the fancy * and ** syntax starts with `If the syntax ``*expression'' appears in the function call...'. -- [mdw] From icanbob at gmail.com Tue Jan 27 11:48:37 2009 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 27 Jan 2009 08:48:37 -0800 (PST) Subject: significant release for SIMPL project's Python extension Message-ID: The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the simplicity and power of the Send/Receive/Reply messaging (first pioneered by QNX) to the Linux world. SIMPL modules are themselves Linux executables and can be written in any number of languages now (C, C++, Tcl/Tk and Python). A SIMPL application consists of one or more of these modules interacting in a single SIMPL sandbox. A SIMPL application can consist of SIMPL modules written in a mixture of supported languages. In addtion SIMPL applications can be spread across a network seamlessly through the use of TCP/IP or RS232 surrogates. In most cases this redeployment can occur without an code change or recompilation. Python is one of the newer languages to be added to the SIMPL family, but it is already attracting significant attention. An online course on SIMPL-Python offered for no fees by iCanProgram (http:// www.icanprogram.com/06py/main.html) consistently gets the highest number of web hits in any given month. Up until now SIMPL-Python modules could already be built for deployment on a Linux OS. Now SIMPL-Python modules can be written for a non Linux OS and interact with a SIMPL application using the tclSurrogate (TCP/IP) protocol which SIMPL supports. This means that a Python script running under Windows can now participate seamlessly in a SIMPL application running on a Linux network. In addition SIMPL-Python web scripts can also now participate seamlessly in a SIMPL application. This feature greatly extends the reach of SIMPL-Python into the realm of web interfaces and web applications. The easiest way to get aquainted with the SIMPL-Python toolset is to download one of its self installing archives for Linux. These are safely deployed in /tmp to allow full exploration with an option to permanently install the release in a directory of your choosing. SIMPL-Python self installing archive - http://www.icanprogram.com/simpl/python.self.html SIMPL-Python course self installing archive - http://www.icanprogram.com/pythoncourse.self.html the SIMPL project team From mail at microcorp.co.za Tue Jan 27 12:05:00 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 27 Jan 2009 19:05:00 +0200 Subject: Exec woes Message-ID: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> It starts with the conspiracy of silence at the interactive prompt: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. IDLE 1.1.3 ==== No Subprocess ==== >>> help(exec) SyntaxError: invalid syntax >>> Its the same under Linux SuSe, Python 2.5.1. I think this is a BUG. Anyway, my real problem looks like this: >>> def Somefunc(): def excrescence(): exec('BUILD = "someString"') return BUILD SyntaxError: unqualified exec is not allowed in function 'excrescence it is a nested function (, line 3) >>> Now this works if it is not nested, and it works if it is a method in a class. Why the complaint about the nestedness? I would appreciate it if someone would explain, as the library reference simply says that it would default to globals() and locals(), which also does not seem to happen - also true for a "nested" eval after a compile - you have to specify the globals() or you get a NameError - global BUILD is not defined. So there is some namespace thing happening that is too subtle for me, and I would like to know what "unqualified" means in the above message, and what one must do to "qualify" the statement, if that is what is needed. The original thing came up because I really need relative imports - I have some version.py files in various directories that have a single line in them that looks like the string I am feeding the exec. By the way, execfile works in this situation, but also only if you specify globals() explicitly. I would really like to understand what is going on. - Hendrik From mdw at distorted.org.uk Tue Jan 27 12:05:24 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 17:05:24 +0000 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: Message-ID: <87ocxs1xyj.fsf.mdw@metalzone.distorted.org.uk> Laszlo Nagy writes: > I have a program that uses socket.bind() and socket.listen() > frequently. After that program stops, it is not able to bind() again for a > while: This is the usual TIME-WAIT problem. The TCP protocol requires one end of the connection (whichever actually started the close) to keep a record of it for a while after it closes, in order to avoid confusion caused by old packets. > The problem with this, is that this server program SOMETIMES need to be > restarted very quickly. The usual solution is to set the SO_REUSEADDR socket option before binding. This is safe for listening sockets. Here's an interactive session. In [1]: import socket as S In [2]: def make_server_socket(): ...: sk = S.socket(S.AF_INET, S.SOCK_STREAM) ...: sk.bind(('', 12345)) ...: sk.listen(5) ...: return sk ...: In [3]: def serve_client(sk): ...: (nsk, addr) = sk.accept() ...: nsk.send('Hello.\n') ...: nsk.close() ...: In [4]: sk = make_server_socket() In [5]: serve_client(sk) (At this point, I connect to the server in another terminal.) In [6]: sk.close() In [7]: sk = make_server_socket() [...] error: (98, 'Address already in use') And to confirm that it's TIME-WAIT that's stopping us: [ponder ~]netstat -n | grep 12345 tcp 0 0 127.0.0.1:12345 127.0.0.1:49988 TIME_WAIT If I change make_server_socket, then everything works fine. In [8]: def make_server_socket(): ...: sk = S.socket(S.AF_INET, S.SOCK_STREAM) ...: sk.setsockopt(S.SOL_SOCKET, S.SO_REUSEADDR, 1) ...: sk.bind(('', 12345)) ...: sk.listen(5) ...: return sk ...: In [10]: sk = make_server_socket() In [11]: serve_client(sk) In [13]: sk.close() In [14]: sk = make_server_socket() Done. If you try this, note that both the old, closed socket /and/ the new one must have SO_REUSEADDR set on them. If you try this interactively, you'll have to wait for the non-SO_REUSEADDR socket to leave TIME-WAIT before you can bind. But once you've done that, it'll work fine from then on. -- [mdw] From george.trojan at noaa.gov Tue Jan 27 12:06:52 2009 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 27 Jan 2009 17:06:52 +0000 Subject: Pexpect and telnet not communicating properly In-Reply-To: <497f35ef$0$30312$da0feed9@news.zen.co.uk> References: <497f35ef$0$30312$da0feed9@news.zen.co.uk> Message-ID: David Anderson wrote: > I am trying to automate the following session - to talk to my router: > > ======================= > telnet speedtouch > Trying 192.168.1.254... > Connected to speedtouch. > Escape character is '^]'. > Username : Administrator > Password : > ------------------------------------------------------------------------ > > ______ SpeedTouch 780 > ___/_____/\ > / /\ 6.1.7.2 > _____/__ / \ > _/ /\_____/___ \ Copyright (c) 1999-2006, THOMSON > // / \ /\ \ > _______//_______/ \ / _\/______ > / / \ \ / / / /\ > __/ / \ \ / / / / _\__ > / / / \_______\/ / / / / /\ > /_/______/___________________/ /________/ /___/ \ > \ \ \ ___________ \ \ \ \ \ / > \_\ \ / /\ \ \ \ \___\/ > \ \/ / \ \ \ \ / > \_____/ / \ \ \________\/ > /__________/ \ \ / > \ _____ \ /_____\/ > \ / /\ \ /___\/ > /____/ \ \ / > \ \ /___\/ > \____\/ > > ------------------------------------------------------------------------ > _{Administrator}=>? > Following commands are available : > > help : Displays this help information > menu : Displays menu > ? : Displays this help information > exit : Exits this shell. > .. : Exits group selection. > saveall : Saves current configuration. > ping : Send ICMP ECHO_REQUEST packets. > traceroute : Send ICMP/UDP packets to trace the ip path. > > Following command groups are available : > > firewall service autopvc connection cwmp > dhcp dns dsd dyndns eth > adsl atm config debug env > expr grp hostmgr ids igmp > interface ip ipqos label language > mbus memm mlp nat ppp > pptp script snmp sntp software > system systemlog upgrade upnp user > voice wireless > > {Administrator}=>exit > > ======================== > > I am using the following code: > > #!/usr/bin/env python > > import pexpect > import sys > > child = pexpect.spawn('telnet 192.168.1.254') > fout = file('mylog.txt','w') > child.logfile = fout > > child.expect('sername : ') > child.sendline('Administrator') > child.expect('assword : ') > child.sendline('') > > > child.expect('_{Administrator}=>') > child.sendline('?') > child.expect('_{Administrator}=>') > child.expect('exit') > > ======================== > > This times out after child.sendline('Administrator') > > mylog.txt contains: > Trying 192.168.1.254... > > Connected to 192.168.1.254. > > Escape character is '^]'. > > Username : Administrator > Administrator > ======================== > > Can anyone help me in finding out what I am doing wrong? > > Regards > David To debug, add lines print self.before print self.after after each child.expect(). Also, add timeout=2 to the argument list of child.expect(). I wrote a thin wrapper that serves me well, at least till now. class Connection(object): '''Establishes connection to Cisco modem server. A wrapper around fdexpect spawn. ''' def __init__(self, host, port, user, passwd, **kwds): self.pipe = None self.socket = None self.host = host self.port = port self.user = user self.passwd = passwd self.logger = kwds.get('logger') self._last = '' def __getattr__(self, name): if name not in ['open', 'close', 'send', 'sendline', 'expect']: return getattr(self.pipe, name) def open(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((self.host, self.port)) self.pipe = pexpect.fdspawn(self.socket) self.expect('Username:', timeout=2) self.sendline(self.user) self.expect('Password:', timeout=1) self.sendline(self.passwd) self.send('ATZ\r') self.expect('OK', timeout=1) def send(self, s): self._last = s return self.pipe.send(s) def sendcr(self, s): self._last = s return self.pipe.send(s+'\r') def sendline(self, s): self._last = s return self.pipe.sendline(s) def expect(self, pattern, **kwds): rc = self.pipe.expect(pattern, **kwds) if self.logger: self.logger.debug('sent "%s", received\n\t1. before "%s"\n\t' \ '2. match "%s"\n\t3. after "%s"\n', self._last, self.before, self.match.group(0), self.after) return rc def close(self): self.pipe.close() self.pipe = None self.socket.close() self.socket = None George From michele.simionato at gmail.com Tue Jan 27 12:07:29 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 27 Jan 2009 09:07:29 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 21, 2:11?am, Mark Wooding wrote: > CLOS is much more complex and dynamic than Python's object system; > but it can be compiled very aggressively. I agree that CLOS is complex and that it can be compiled very aggressively, but I do not think that it is more dynamic than Python. What feature are you alluding to? Multimethods? There are many Python implementations of them, they are just not in the standard library. Or are you referring to interactive facilities, such as the one discussed in this recipe http://code.activestate.com/recipes/160164 ? From R.Brodie at rl.ac.uk Tue Jan 27 12:11:59 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 27 Jan 2009 17:11:59 -0000 Subject: v = json.loads("{'test':'test'}") References: <834c1aa1-bc86-44ae-8d07-60ef85ecda9e@b38g2000prf.googlegroups.com><9109e751-8ee6-42c4-9e46-e1108541b5b7@a39g2000prl.googlegroups.com><6u48ntFdcm9fU1@mid.uni-berlin.de> <20090126005431.063dafa9@usenot.de> <018d0300$0$20629$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:018d0300$0$20629$c3e8da3 at news.astraweb.com... > Supposedly "every browser" (what, all of them?) already support a de > facto extension to the JSON standard, allowing more flexible quoting. That's a consequence of JSON being a subset of Javascript syntax, so you can just call eval() on it, if you're willing. When you use a library, it's pot luck whether it accepts JSON-soup or not. From invalid at invalid Tue Jan 27 12:13:28 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 27 Jan 2009 11:13:28 -0600 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: On 2009-01-27, Bruno Desthuilliers wrote: > Please visit comp.databases or comp.lang.javascript for really > unfriendly and unhelpful places where few happens except > "bickering and name-calling". I've always found comp.lang.c to be a rather dangerous place as well. Of the newsgroups I read, c.l.python is probably the most friendly and has one of the highest S/N ratios. People who would have been roasted alive in other newsgroups for their laziness or presumptuousness get surprisingly gentle treatment in c.l.python. I do know of a few low-volume mailing lists that are probably as good, but for a Usenet news group with any volume at all, c.l.pythong is exceptionally good. -- Grant Edwards grante Yow! I wonder if I should at put myself in ESCROW!! visi.com From rt8396 at gmail.com Tue Jan 27 12:19:36 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 09:19:36 -0800 (PST) Subject: IDLE 3000 (suggested improvements) Message-ID: Proposal: OK, so the python language has officially moved into the next level. I look at IDLE and think, hmm great IDE but it could really use a spit shining. So here is a very simple script showing my ideas to improve IDLE. Reason for change: The text widget and the prompt(>>>) should be separated. Trying to write a conditional in the interactive IDLE is a real pain. Not to mention that when you copy code from Interactive IDLE to the IDLE editor window the indention is eight spaces instead four and you've got that prompt(>>>) stuck in there. I have a solution for the problem though. I hope you are using fixed-width font Lst|<----- Text Widget ---->| | | >>>|if this: | ...| if that: | ...| ... | ...| elif that: | ...| ... | ...| else: | ...| ... | >>>| | >>>|x = 10 | >>>| | Basically you have a Listbox on the left for the prompt and a Text on the right. Disable the Listbox highlight and key press events and now we have a very friendly interactive IDLE! No more prompt hijacking your snippets, and no more eigtht space indention! Hip-Hip-Hooray! #-- Start Script --# from Tkinter import * import tkMessageBox as MB class CMD(Toplevel): def __init__(self, master): Toplevel.__init__(self, master) self.master = master self.startidx = '1.0' self.backidx = '1.0' self.title('IDLE 3000') self.listbox = Listbox(self, width=3, relief=FLAT, font= ('Courier New',12), takefocus=0) self.listbox.pack(fill=Y, side=LEFT) self.listbox.insert(0, '>>>') self.text = Text(self, relief=FLAT, spacing3=1, wrap=NONE, font=('Courier New',12)) self.text.pack(fill=BOTH, side=LEFT, expand=1) self.text.config(width=50, height=20) self.text.focus_set() self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.listbox.bind("" , lambda e: "break") self.text.bind('' , lambda e: "break")#pageup self.text.bind('' , lambda e: "break")#pagedown self.text.bind('' , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind("" , lambda e: "break") self.text.bind('' , lambda e: "break") self.text.bind("" , lambda e: "break") self.text.bind("" , self.onUp) self.text.bind("" , self.onDown) self.text.bind("" , self.onTab) self.text.bind("" , self.onReturn) self.text.bind("", self.onBackSpace) self.protocol("WM_DELETE_WINDOW", self.onQuit) self.lift(master) self.master.withdraw() def fix_index(self, chars): self.backidx = '%d.0' %(int(self.backidx.split('.')[0])+1) self.text.insert(END, '\n') self.text.mark_set(INSERT, END) self.text.see(INSERT) self.listbox.insert(END, chars) self.listbox.see(self.listbox.size()) def onQuit(self): self.grab_release() self.master.destroy() def onTab(self, event=None): curline, cursor = self.text.index(INSERT).split('.')[0]+'.0', self.text.index(INSERT) self.text.insert(INSERT, ' ') return "break" def onDown(self, event): i = self.text.index(INSERT+'+1l') #;print 'New index: ', i self.text.mark_set(INSERT, i) self.text.see(i) self.listbox.see(int(i.split('.')[0])-1) return "break" def onUp(self, event=None): i = self.text.index(INSERT+'-1l') #;print 'New index: ', i self.text.mark_set(INSERT, i) self.text.see(i) self.listbox.see(int(i.split('.')[0])-1) return "break" def onBackSpace(self, event=None): if self.text.compare(self.text.index(INSERT), '!=', self.backidx): self.text.delete(self.text.index(INSERT+'-1c')) return "break" def onReturn(self, event=None): curline, cursor = self.text.index(INSERT).split('.')[0]+'.0', self.text.index(INSERT) text = self.text.get(self.startidx, END).strip() if self.text.compare(curline, '<', self.startidx):#'Out Of Zone' self.text.mark_set(INSERT, END+'-1c') self.text.see(INSERT) self.listbox.see(END) elif '.0' in cursor: #nothing typed on this line, try to exec command cmd = text.rstrip('\n') try: exec(cmd) except: self.master.bell() print '%s\n%s\n%s' %(sys.exc_traceback, sys.exc_type, sys.exc_value) finally: self.fix_index('>>>') self.startidx = self.text.index(INSERT) elif text != '':#something typed self.fix_index('...') else: #insert newline self.fix_index('>>>') return "break" if __name__ == '__main__': print 'main' root = Tk() MB.showinfo('IDLE 3000 Introduction',''' This Demo shows how i think the standard IDLE should behave. You will notice the prompt is outside of the text widget. This keeps the prompt from hijacking your code snippits when you copy-paste to the main editor window. This also keeps all indention at the Python recommended four spaces. Please note this demo is to only show the layout, it does not include syntax highlight, auto-tab, auto-dedent, or any other feature. This is not even the correct way to write a good editor. My only intention is to show a more user friendly layout have fun :) ''') cmd = CMD(root) root.mainloop() #-- End Script --# Issue #2: When you press MMB and there is a highlighted selection in the text it gets pasted over and over again @ the insertion cursor. This can be aggravating, and turn a clean script into a bowl of "Cheerios" breakfast cereal in no time. From vincent at vincentdavis.net Tue Jan 27 12:28:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:28:47 -0700 Subject: regular expression, help Message-ID: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line I want to get the number "39-034-15-009" after "Parcel ID:" The number will be different each time but always the same format. I think I can match "Parcel ID:" but not sure how to get the number after. "Parcel ID:" only occurs once in the document. is this how i need to start? pid = re.compile('Parcel ID: ') Basically I am completely lost and am not finding examples I find helpful. I am getting the html using myurl=urllib.urlopen(). Can I use RE like this thenum=pid.match(myurl) I think the two key things I need to know are 1, how do I get the text after a match? 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl as the string in a RE, thenum=pid.match(myurl) Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Tue Jan 27 12:29:17 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:29:17 -0700 Subject: regular expression, help Message-ID: <77e831100901270929j5c26de84g56a1ff04f872b2e5@mail.gmail.com> I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line I want to get the number "39-034-15-009" after "Parcel ID:" The number will be different each time but always the same format. I think I can match "Parcel ID:" but not sure how to get the number after. "Parcel ID:" only occurs once in the document. is this how i need to start? pid = re.compile('Parcel ID: ') Basically I am completely lost and am not finding examples I find helpful. I am getting the html using myurl=urllib.urlopen(). Can I use RE like this thenum=pid.match(myurl) I think the two key things I need to know are 1, how do I get the text after a match? 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl as the string in a RE, thenum=pid.match(myurl) Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 27 12:29:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 15:29:24 -0200 Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas escribi?: > Hello all, This is my first post to this mailing list. Our requirement > is to invoke a Tkinter python panel from a C++ GUI app where both GUI > windows would run in 2 separate threads. We have written a sample PyQt > application which calls this Tk panel using something like this:class > TkPanel(threading.Thread):def run(self): # call showPaneldef > showPanel():# create window = Tk.Tk() window.mainloop()def start():t = > TkPanel()t.start()Now we call this from our main python code:def > startPanel(self): import tkPanel tkPanel.start() # this calls > tkwindow.mainloop() in a separate thread.This works absolutely fine when > the invoking app is Python. From the above description I don't see where PyQt is involved. Do you really want to mix Qt and Tk in the same application? I don't think they could coexist... -- Gabriel Genellina From thorsten at thorstenkampe.de Tue Jan 27 12:33:58 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 18:33:58 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: * John Machin (Tue, 27 Jan 2009 05:31:42 -0800 (PST)) > Nobody is upset, and nobody has "gone off on a tear". The point about > the "Windows example" is that the docs say in a close-to-screamingly- > obvious manner that /options are not supported, no matter what > religion uses them. It was not, and still is not, apparent what you > really wanted. We're all patiently waiting for you to rephrase the > question(s). Amen, brother. Thorsten From lists at cheimes.de Tue Jan 27 12:34:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jan 2009 18:34:41 +0100 Subject: Exec woes In-Reply-To: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen schrieb: > It starts with the conspiracy of silence at the interactive prompt: > > Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > > IDLE 1.1.3 ==== No Subprocess ==== >>>> help(exec) > SyntaxError: invalid syntax > Its the same under Linux SuSe, Python 2.5.1. > > I think this is a BUG. No, it's the way exec is defined. exec is not a function, it's a statement. "help(exec)" raises a syntax error like "help(if)" or "help(while)" would raise a syntax error, too. Christian From steve at holdenweb.com Tue Jan 27 12:37:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 12:37:02 -0500 Subject: optparse with numpy.array? In-Reply-To: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Message-ID: Johan Ekh wrote: > Thanks, > James I will try your suggestion! > Robert, what mean with "interactively" is that i would like to create an > array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or > by reading a file with values etc., and then execute my program with > "myprog -m m_i" and thus pass the array "m_i" to my program. > > This is just an example. I would like to pass several arrays. My program > will be wrapped inside a loop and the arrays are updated > in each loop. > The bottom line is that there is no "natural" way to pass Python objects through the command line, so you will need to find a natural way to represent the objects as character strings, and then extend the optparse module to recognize that type. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Tue Jan 27 12:39:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jan 2009 17:39:30 +0000 Subject: regular expression, help In-Reply-To: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> References: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> Message-ID: <497F46D2.4000608@mrabarnett.plus.com> Vincent Davis wrote: > I think there are two parts to this question and I am sure lots I am > missing. I am hoping an example will help me > I have a html doc that I am trying to use regular expressions to get a > value out of. > here is an example or the line > > I want to get the number "39-034-15-009" after "Parcel ID:" The number > will be different each time but always the same format. > I think I can match "Parcel ID:" but not sure how to get the number > after. "Parcel ID:" only occurs once in the document. > > is this how i need to start? > pid = re.compile('Parcel ID: ') > > Basically I am completely lost and am not finding examples I find helpful. > > I am getting the html using myurl=urllib.urlopen(). > Can I use RE like this > thenum=pid.match(myurl) > > > I think the two key things I need to know are > 1, how do I get the text after a match? > 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl > as the string in a RE, thenum=pid.match(myurl) > Something like: pid = re.compile(r'Parcel ID: (\d+(?:-\d+)*)') myurl = urllib.urlopen(url) text = myurl.read() myurl.close() thenum = pid.search(text).group(1) Although BeautifulSoup is the preferred solution. From vincent at vincentdavis.net Tue Jan 27 12:39:47 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:39:47 -0700 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <77e831100901270939x1a1232cduf4abc7f3fbb0b7ee@mail.gmail.com> Being a newbie and not aware of other good places to ask dump questions. I have been very happy with the help I have gotten. Some of the other discussions are a little interesting to me but I wonder/am grateful if these keep the knowledgeable people around so us newbies can ask questions. Since I am a beginner programer and new to python it is really help to have a place to ask quick or long questions. Books are nly so good, Google helps but it doesn't debug code for you. Thanks Vincent Davis On Tue, Jan 27, 2009 at 10:13 AM, Grant Edwards wrote: > On 2009-01-27, Bruno Desthuilliers > wrote: > > > Please visit comp.databases or comp.lang.javascript for really > > unfriendly and unhelpful places where few happens except > > "bickering and name-calling". > > I've always found comp.lang.c to be a rather dangerous place as > well. > > Of the newsgroups I read, c.l.python is probably the most > friendly and has one of the highest S/N ratios. People who > would have been roasted alive in other newsgroups for their > laziness or presumptuousness get surprisingly gentle treatment > in c.l.python. I do know of a few low-volume mailing lists > that are probably as good, but for a Usenet news group with any > volume at all, c.l.pythong is exceptionally good. > > -- > Grant Edwards grante Yow! I wonder if I > should > at put myself in ESCROW!! > visi.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Tue Jan 27 12:45:29 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:45:29 -0700 Subject: regular expression, help In-Reply-To: <497F46D2.4000608@mrabarnett.plus.com> References: <77e831100901270928t71149f33y87219b9a0670c633@mail.gmail.com> <497F46D2.4000608@mrabarnett.plus.com> Message-ID: <77e831100901270945q4804832an253fc4c60b350241@mail.gmail.com> is BeautifulSoup really better? Since I don't know either I would prefer to learn only one for now. Thanks Vincent Davis On Tue, Jan 27, 2009 at 10:39 AM, MRAB wrote: > Vincent Davis wrote: > >> I think there are two parts to this question and I am sure lots I am >> missing. I am hoping an example will help me >> I have a html doc that I am trying to use regular expressions to get a >> value out of. >> here is an example or the line >> >> I want to get the number "39-034-15-009" after "Parcel ID:" The number >> will be different each time but always the same format. >> I think I can match "Parcel ID:" but not sure how to get the number after. >> "Parcel ID:" only occurs once in the document. >> >> is this how i need to start? >> pid = re.compile('Parcel ID: ') >> >> Basically I am completely lost and am not finding examples I find helpful. >> >> I am getting the html using myurl=urllib.urlopen(). Can I use RE like this >> thenum=pid.match(myurl) >> >> I think the two key things I need to know are >> 1, how do I get the text after a match? >> 2, when I use myurl=urllib.urlopen(http://.......). can I use the myurl >> as the string in a RE, thenum=pid.match(myurl) >> >> Something like: > > pid = re.compile(r'Parcel ID: (\d+(?:-\d+)*)') > myurl = urllib.urlopen(url) > text = myurl.read() > myurl.close() > thenum = pid.search(text).group(1) > > Although BeautifulSoup is the preferred solution. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Jan 27 12:45:48 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 27 Jan 2009 09:45:48 -0800 Subject: Exec woes In-Reply-To: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> > IDLE 1.1.3 ==== No Subprocess ==== > >>> help(exec) > SyntaxError: invalid syntax > >>> > Its the same under Linux SuSe, Python 2.5.1. > > I think this is a BUG. > Exec is a statement, not a function nor an object: even though you can enclose parens around its arguments like you do later on, they don't have any syntax meaning. You can't help(print) or help(import) either. > Anyway, my real problem looks like this: > > >>> def Somefunc(): > def excrescence(): > exec('BUILD = "someString"') > return BUILD > > SyntaxError: unqualified exec is not allowed in function 'excrescence > it is a nested function (, line 3) > >>> > > Now this works if it is not nested, and it works if it is a method in a > class. > Why the complaint about the nestedness? > Once upon a time, Python had only two scopes or namespaces: local and globals. It'd look up variables in the local scope and if it didn't find them, it'd look them up in the global scope. (There's also the builtin namespace but to not digress...) Under this scenario, if you define some attributes in Somefunc() those will NOT be visible within excrescence(). So: def foo(): a = 5 def bar(): print a # error wouldn't work. Then PEP227 came around to add nested scopes -- or lexical scopes. Its what made "nested" functions like that actually useful: it's what brought closures into the scenario. As of Python 2.2, within bar() it would be able to see the definition of a because namespaces can now be nested. This addition was a problem for a couple features: doing "from blah import *" within a function, and a bare exec (an exec without an explicit globals() and locals()) that happened in certain places-- in this case a nested function. They introduced that SyntaxError to make sure it wouldn't accidentally hit you. Read up on PEP227 for the full details. To get around this, you need to specify exactly what scope you want exec to happen in when you're in a place where the 'current' scope is nested. You qualify exec-- > > So there is some namespace thing happening that is too subtle for me, and I > would like to know what "unqualified" means in the above message, and > what one must do to "qualify" the statement, if that is what is needed. > by doing: exec code in , In your situation: >>> def Somefunc(): def excrescence(): exec "BUILD = 'someString'" in globals(), locals() is probably sufficient. globals() returns the dictionary of the global namespace, locals() the dictionary of the current functions (non-nested) namespace. HTH, --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jan 27 12:46:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jan 2009 09:46:40 -0800 Subject: Exec woes In-Reply-To: References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> Message-ID: <50697b2c0901270946r70316622h5fb8c08e45e700a5@mail.gmail.com> On Tue, Jan 27, 2009 at 9:34 AM, Christian Heimes wrote: > Hendrik van Rooyen schrieb: >> It starts with the conspiracy of silence at the interactive prompt: >> >> Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 >> Type "copyright", "credits" or "license()" for more information. >> >> IDLE 1.1.3 ==== No Subprocess ==== >>>>> help(exec) >> SyntaxError: invalid syntax >> Its the same under Linux SuSe, Python 2.5.1. >> >> I think this is a BUG. > > No, it's the way exec is defined. exec is not a function, it's a > statement. "help(exec)" raises a syntax error like "help(if)" or > "help(while)" would raise a syntax error, too. Indeed. Although it would happen to work in Python 3.0, as exec() became a function once again. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From fetchinson at googlemail.com Tue Jan 27 12:50:14 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jan 2009 09:50:14 -0800 Subject: How do I say "two classes up in the inheritance chain" in python? In-Reply-To: <497ed07e$0$6718$426a34cc@news.free.fr> References: <497ed07e$0$6718$426a34cc@news.free.fr> Message-ID: >> I have two classes that both inherit from two other classes which both >> inherit from a single class. The two children have two almost >> identical methods: >> >> class grandparent( object ): >> def meth( self ): >> # do something >> >> class parent1( grandparent ): >> def meth( self ): >> # do something p1 >> super( parent1, self ).meth( ) >> >> class parent2( grandparent ): >> def meth( self ): >> # do something p2 >> super( parent2, self ).meth( ) >> >> class child1( parent1 ): >> def meth( self ): >> # do something c >> super( parent1, self ).meth( ) # I want to invoke meth on >> grandparent > > If so, it might be better to explicitly call grandparent.meth (passing > self as first argument). But this is an obvious design smell IMHO. What > you have is : > > def meth(self): > do_something_more_or_less_specific > call_granparent > > Looks like a candidate for a template method. Since you don't have hand > on Grandparent, the simplest would be to add an additional base class, ie: > > > class Abstract(Grandparent): > def do_something(self): > raise NotImplementedError > > def meth(self): > self.do_something() > super(Abstract, self).meth() > > > class Parent1(Abstract): > def do_something(self): > # do something p1 > > class Parent2(Abstract): > def do_something(self): > # do something p2 > > > Now you're problem is to factor out do_something() for Child1 and > Child2. The solution is quite simple : just define it outside the class > statements, and adds it afterward: > > def do_something_children(self): > # code here > > class Child1(Parent1): > # code here > > Child1.do_something = do_something_children > > class Child2(Parent2): > # code here > > Child2.do_something = do_something_children Thanks, this was very helpful. Also, thanks Duncan, your simple suggestion was helpful too to just call the grandparent directly (without super). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From vincent at vincentdavis.net Tue Jan 27 12:50:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 10:50:32 -0700 Subject: change syntax coloring in IDLE Message-ID: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it states I can change he text coloring by using "Configure IDLE" but I not sure what this is. It's not sn the menu, running Configure does nothing. How do I change the color (text and background) Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jan 27 12:53:40 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 09:53:40 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> Message-ID: <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> On Jan 27, 10:12?am, Bruno Desthuilliers wrote: > All you can say is that he didn't *post* here (at least under his real > identity...) for the 9 past years - this doesn't mean he never *reads* > (and this, you just have no way to know). Ah, this is a good point. You have to wonder, Guido could be one of the regulars here. very interesting. We should have a vote as to who would be the most likely candidate, now that would be a good thread :) From thorsten at thorstenkampe.de Tue Jan 27 13:00:09 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:00:09 +0100 Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: * Giampaolo Rodola' (Tue, 27 Jan 2009 04:52:16 -0800 (PST)) > I have this same issue on Windows. > Note that on Python 2.6 it works: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print unicode('\u20ac') > \u20ac > > This is pretty serious, IMHO, since breaks any Windows software > priting unicode to stdout. > I've filed an issue on the Python bug tracker: > http://bugs.python.org/issue5081 For printing to stdout you have to give an encoding that the terminal understands and that contains the character. In your case the terminal says "I speak cp 850" but of course there is no Euro sign in there. Why should that be a bug? Thorsten From http Tue Jan 27 13:00:24 2009 From: http (Paul Rubin) Date: 27 Jan 2009 10:00:24 -0800 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> Message-ID: <7xmydc6347.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > All you can say is that he didn't *post* here (at least under his real > identity...) for the 9 past years - this doesn't mean he never *reads* > (and this, you just have no way to know). Guido does post here once in a while, under his own name. I can't think of any very recent examples, but I can remember some from a few years back. From bbands at gmail.com Tue Jan 27 13:02:39 2009 From: bbands at gmail.com (BBands) Date: Tue, 27 Jan 2009 10:02:39 -0800 (PST) Subject: A different kind of interface References: <8afc0cb6-0c54-4a5c-899a-ba7ba960302f@r15g2000prh.googlegroups.com> Message-ID: PyScripter does it for me. http://code.google.com/p/pyscripter/ jab From rantingrick at gmail.com Tue Jan 27 13:03:16 2009 From: rantingrick at gmail.com (rantingrick) Date: Tue, 27 Jan 2009 10:03:16 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: On Jan 27, 12:00?pm, Paul Rubin wrote: > Guido does post here once in a while, under his own name. ?I can't > think of any very recent examples, but I can remember some from a few > years back. I searched the archives for "Guido van Rossum" and there is nothing since May 2000. That's the most recent i could find anyway?? From thorsten at thorstenkampe.de Tue Jan 27 13:08:20 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:08:20 +0100 Subject: unable to print Unicode characters in Python 3 References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: * Denis Kasak (Tue, 27 Jan 2009 14:22:32 +0100) > On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' > wrote: > > I have this same issue on Windows. > > Note that on Python 2.6 it works: > > > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> print unicode('\u20ac') > > \u20ac > > Shouldn't this be > > print unicode(u'\u20ac') You are trying to create a Unicode object from a Unicode object. Doesn't make any sense. > on 2.6? Without the 'u' prefix, 2.6 will just encode it as a normal > (byte) string and escape the backslash. You are confusing encoding and decoding. unicode(str) = str.decode. To print it you have to encode it again to a character set that the terminal understands and that contains the desired character. Thorsten From steve at holdenweb.com Tue Jan 27 13:10:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 13:10:09 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: Bryan Olson wrote: > Paul Rubin wrote: >> Bryan Olson writes: >>> An object's __dict__ slot is *not* mutable; thus we could gain some >>> efficiency by protecting the object and its dict with the same lock. I >>> do not see a major win in Mr. Banks' point that we do not need to lock >>> the object, just its dict. >> >> If the dict contents don't change often, maybe we could use an >> STM-like approach to eliminate locks when reading. That would of >> course require rework to just about every C function that accesses >> Python objects. > > I'm a fan of lock-free data structure and software transactional memory, > but I'm also a realist. Heck, I'm one of this group's outspoken > advocates of threaded architectures. Theoretical breakthroughs will > happen, but in real world of today, threads are great but GIL-less > Python is a loser. > > Wherever Python is going, let's recognize that a scripting language that > rocks is better than any other kind of language that sucks. > > Guido, IIRC, has said that he's against any GIL-removal policy that lowers performance on single-processor systems. Personally I'd be happy if there were an *alternative* multi-processor implementation that was slower for single-processor architectures and faster for multi-processor, but I'm not about to start developing it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From n.kottiyath at gmail.com Tue Jan 27 13:12:42 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 10:12:42 -0800 (PST) Subject: pyAA for Python2.5 Message-ID: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> Hi, I would like to obtain pyAA for Python 2.5. I went through their web site, but they provide the windows exe only for Python2.4. I tried compiling from source, but that also was to no avail - it errs out as follows: C:\Documents and Settings\Guest\pyAA>python setup.py install running install running build running build_py file pyAAc.py (for module pyAAc) not found file pyAAc.py (for module pyAAc) not found running build_ext error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing "-c mingw32" to setup.py. C:\Documents and Settings\Guest\pyAA>python setup.py install -c mingw32 usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'mingw32' Has anyone tried the same? Can anyone give any suggestions? From thorsten at thorstenkampe.de Tue Jan 27 13:24:20 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 27 Jan 2009 19:24:20 +0100 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) > On Jan 27, 12:00?pm, Paul Rubin wrote: > > Guido does post here once in a while, under his own name. ?I can't > > think of any very recent examples, but I can remember some from a few > > years back. > > I searched the archives for "Guido van Rossum" and there is nothing > since May 2000. That's the most recent i could find anyway?? Search again - the last was in December 2008: http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 &as_maxd=1&as_maxm=1&as_maxy=2009 &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa fe=off From denis.kasak at gmail.com Tue Jan 27 13:35:49 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Tue, 27 Jan 2009 19:35:49 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <1dd16109-583b-4a18-96d3-2edad2a0867c@t26g2000prh.googlegroups.com> <4d6972ab-188c-4f16-ad46-3de47ec71558@o4g2000pra.googlegroups.com> Message-ID: <39e19a010901271035k1363675fq6353c599724159c0@mail.gmail.com> On Tue, Jan 27, 2009 at 7:08 PM, Thorsten Kampe wrote: > * Denis Kasak (Tue, 27 Jan 2009 14:22:32 +0100) >> On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' >> wrote: >> >>>> print unicode('\u20ac') >> > \u20ac >> >> Shouldn't this be >> >> print unicode(u'\u20ac') > > You are trying to create a Unicode object from a Unicode object. Doesn't > make any sense. Of course it doesn't. :-) Giampaolo's example was wrong because he was creating a str object with a non-escaped backslash inside it (which automatically got escaped) and then converting it to a unicode object. In other words, he was doing: print unicode('\\u20ac') so the Unicode escape sequence didn't get interpreted the way he intended it to. I then modified that by adding the extra 'u' but forgot to delete the extraneous unicode(). > You are confusing encoding and decoding. unicode(str) = str.decode. To > print it you have to encode it again to a character set that the > terminal understands and that contains the desired character. I agree (except for the first sentence :-) ). As I said, I simply forgot to delete the call to the unicode builtin. -- Denis Kasak From http Tue Jan 27 13:45:57 2009 From: http (Paul Rubin) Date: 27 Jan 2009 10:45:57 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> Message-ID: <7x8wowegey.fsf@ruckus.brouhaha.com> Bryan Olson writes: > I'm a fan of lock-free data structure and software transactional > memory, but I'm also a realist. Heck, I'm one of this group's > outspoken advocates of threaded architectures. Theoretical > breakthroughs will happen, but in real world of today, threads are > great but GIL-less Python is a loser. GIL-less Python (i.e. Jython) already exists and beats CPython in performance a lot of the time, including on single processors. Whether the GIL can be eliminated from CPython without massive rework to every extension module ever written is a separate question, of course. Jython can be viewed a proof of concept. From martin at v.loewis.de Tue Jan 27 13:56:03 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 27 Jan 2009 19:56:03 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> Message-ID: <497F58C3.6020209@v.loewis.de> > #include "stdio.h" > int main(int argc, char **argv) { > printf("<\xc2\x80>\n"); > } > > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) > and using "Lucida Console" font: > > After CHCP 1252, this prints < A-circumflex Euro >, as expected. > After CHCP 65001, it prints < hollow-square >. This is not surprising: this character is U+0080, which is a control character. Try \xe2\x82\xac instead. Regards, Martin From kyosohma at gmail.com Tue Jan 27 13:56:45 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 10:56:45 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> Message-ID: <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> On Jan 27, 12:12?pm, Kottiyath wrote: > Hi, > ? ?I would like to obtain pyAA for Python 2.5. I went through their > web site, but they provide the windows exe only for Python2.4. I tried > compiling from source, but that also was to no avail - it errs out as > follows: > > C:\Documents and Settings\Guest\pyAA>python setup.py install > running install > running build > running build_py > file pyAAc.py (for module pyAAc) not found > file pyAAc.py (for module pyAAc) not found > running build_ext > error: Python was built with Visual Studio 2003; > extensions must be built with a compiler than can generate compatible > binaries. > Visual Studio 2003 was not found on this system. If you have Cygwin > installed, > you can try compiling with MingW32, by passing "-c mingw32" to > setup.py. > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > mingw32 > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > ? ?or: setup.py --help [cmd1 cmd2 ...] > ? ?or: setup.py --help-commands > ? ?or: setup.py cmd --help > > error: invalid command 'mingw32' > > Has anyone tried the same? Can anyone give any suggestions? You probably have to put mingw32 on your path or provide an absolute path to it. By the way, where did you get the source? I couldn't find it... Mike From Pat at junk.net Tue Jan 27 14:04:28 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 14:04:28 -0500 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: >> >> I had no idea people were going to get so upset that I used a Windows >> example and go off on a tear. > > Nobody is upset, and nobody has "gone off on a tear". The point about > the "Windows example" is that the docs say in a close-to-screamingly- > obvious manner that /options are not supported, no matter what > religion uses them. It was not, and still is not, apparent what you > really wanted. We're all patiently waiting for you to rephrase the > question(s). Sigh. I used an incorrect example (I sincerely apologize to the world for that egregious error on my part). I''m totally cognizant that the documentation states '-'' or '--' need to be used for flags. The question was it possible to add a simple flag like 'd-' to optparse with no other parameters? I'm guessing from the vitriolic diatribes here that the answer is no. To those who wrote that no one uses command line windows and no one uses 'dir /s /b' command is totally irrelevant. I'm writing a proprietary program used solely by my company. Not everyone writes programs for the same target audience as you do. The program is written in Python on Ubuntu. If you don't want to answer the question or don't have any meaningful to add, please don't pollute the forum with further vacuous responses. I didn't ask, or expect, you to write the code for me. christ on a stick, so many of you behave like prima donnas. From Russ.Paielli at gmail.com Tue Jan 27 14:13:50 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 27 Jan 2009 11:13:50 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> Message-ID: <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> On Jan 26, 6:09 am, Steve Holden wrote: > Quite. Python is a language "for consenting adults". It has perceived > deficiencies for certain software engineering environments. Can we drop > the subject now? This horse was flogged to death long ago, and it's > pointless and cruel to keep on beating the remains. Judging from this thread, not everyone got the memo yet. At least three or four people on this thread alone have argued that enforced data hiding is of no value whatsoever for any application or domain. And more than one of them has argued that Python is perfectly appropriate for even the largest and most safety-critical projects. We are moving into an era of increasing dependence on computers and software for safety-critical, mission-critical, and financial systems. If people who do not understand the principles necessary for ultra-reliable software get in charge of developing these systems, we will have serious problems that could have been avoided. I suggested that maybe -- maybe! -- the versatility of Python could be enhanced with enforced data hiding. I was careful to say several times that I don't know if that can even be done in Python (with all its introspection and so forth). And it would always be optional, of course (as far as I know, no language forces anyone to declare anything private). Several people here seem to take that suggestion as an assault on Python and, by projection, an assault on their worldview. We all know that Python is a fantastic language for many purposes, but it is only a language, and failing to recognize and address its limitations serves no useful purpose. From rene.heymans at gmail.com Tue Jan 27 14:18:32 2009 From: rene.heymans at gmail.com (Rene Heymans) Date: Tue, 27 Jan 2009 20:18:32 +0100 Subject: Python + IDLE under Linux Suse 11.0 Message-ID: <8f7f91620901271118l4962c254s3ffcda23bdc19f97@mail.gmail.com> Dear All, This is my first post to this list. When googling of "*python + idle + CallTip + "Exception in Tkinter* * callback"* one finds within a list of 7 results: at the top of the list (Nr. 1) a link to http://mail.python.org/pipermail/python-bugs-list/2004-August/024530.html dated August 2004 (I understand it is a bug fixed and closed.); as Nr. 3 in the list a link http://www.nabble.com/Output-to-file-gets-lost---don't-know-where-to-look-...-td21004997.html dated December 14, 2008. However, I have a situation where the symptoms are almost identical to the one described by the link Nr 3 (see output below) and that I can reproduce at will with something that looks like what is reported in the link Nr 1. The environment is: Linux OpenSuse 11.0 Python 2.5.2 Idle 1.2.2 When typing: *>>> l = len(* to query the length of an object, instead of getting a Call Tip, I get on my console the message below: *Alibaba:~ # idle Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 55, in try_open_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 79, in open_calltip self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1]) File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 66, in showtip self.position_window() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 35, in position_window self.parencol)) File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 2833, in bbox self.tk.call((self._w, 'bbox') + args)) or None File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1030, in _getints return tuple(map(getint, self.tk.splitlist(string))) ValueError: invalid literal for int() with base 10: '(117,' * and when closing the parenthesis the following messages: *Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 62, in refresh_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 65, in open_calltip self._remove_calltip_window() File "/usr/lib/python2.5/idlelib/CallTips.py", line 41, in _remove_calltip_window self.calltip.hidetip() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 126, in hidetip self.label.destroy() AttributeError: 'NoneType' object has no attribute 'destroy'* Furhtermore there is one little X window that opens up, totally empty and useless. IDLE works but each time you expect a Tip to appear you receive instead a bunch of messages to the console and you lose focus on your IDLE window, meaning you have to click on it to get the focus again and continue typing. I checked on Suse Repository 11.1 but then the available version is Python 2.6, which I don't want presently and which would require many updates to solve dependencies. I also tried to download the source of Python 2.5.4 from www.python.org . I can download the files, unpack them and run the trio of commands (./configure, make, make install) and all run smoothly. Python 2.5.4 starts and works nicely. But now IDLE begins but when you ask to run the shell, a window opens but you don't see anything: no menu, no begin, no >>> prompt, nothing ... I wonder (but I may be totally wrong here) if Suse packages Python + IDLE in a very special way ? Why would */usr/bin/python* be an executable of about 6KB within Suse and be an executable of about 3MB when generating from the source. This is my first encounter in porting a prototype under development to Linux ! Thank you for any help you may provide. All the best, Rene -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Jan 27 14:29:02 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jan 2009 20:29:02 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Pat wrote: > The question was it possible to add a simple flag like 'd-' to optparse > with no other parameters? Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's answer? Peter From babycode at gmail.com Tue Jan 27 14:39:25 2009 From: babycode at gmail.com (Baby Coder) Date: Tue, 27 Jan 2009 11:39:25 -0800 (PST) Subject: Is this pythonic? References: <66d058f9-cfe1-4b3c-ab8a-e6e88bb97770@m22g2000vbp.googlegroups.com> <7dc03d4b-4bce-4cc4-b020-681935cf0b0b@m4g2000vbp.googlegroups.com> Message-ID: <78e47d26-6c90-4697-aff3-4f6d172b207e@k19g2000yqg.googlegroups.com> On 18 d?c 2008, 13:51, Jason Scheirer wrote: > I'd say it's fine but breaking up the statement once or twice is a > good idea just because if one of the function calls in this nested > thing throws an exception, a smaller statement with fewer calls makes > for a far more readable traceback. And I hope that this whole > statement all lives inside of a method in the same x class, or is a > higher-level class that makes use of this behavior? If not, you may > want to consider doing so. > > class X(object): > ? @property > ? def todays_filepattern(self): > ? ? ? return self.match_filename( > ? ? ? ? ? ? ? self.determine_filename_pattern( > ? ? ? ? ? ? ? ? ? ?datetime.datetime.now())) > ? def validate_todays_files(self): > ? ? ?return self.validate_output(self.find_text > (self.todays_filepattern)) Thanks for this lesson in application design. Just what I was looking for. From kyrie at uh.cu Tue Jan 27 14:40:02 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 14:40:02 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: <200901271440.02579.kyrie@uh.cu> On Tuesday 27 January 2009 02:13:50 pm Russ P. wrote: > I suggested that maybe -- maybe! -- the versatility of Python could be > enhanced with enforced data hiding. I was careful to say several times > that I don't know if that can even be done in Python (with all its > introspection and so forth). And it would always be optional, of > course (as far as I know, no language forces anyone to declare > anything private). I think you still fail to see that what we are objecting is not that the original writer can "optionally" use the enforced data hiding (which, as someone pointed out before me, can be done with tools like pylint). The objection is about the _user_ of the library. If you don't force it into the _user_, how is it different from the current situation? And if you do force it, how can you say that it is optional? -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From nad at acm.org Tue Jan 27 14:40:41 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 11:40:41 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: In article <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, Vincent Davis wrote: > I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it > states I can change he text coloring by using "Configure IDLE" but I not > sure what this is. It's not sn the menu, running Configure does nothing. How > do I change the color (text and background) There is supposed to be a Preferences menu option for IDLE on OS X but, depending on the Python version and how IDLE is launched, it may or may not appear due to various bugs. (I'm working on some patches for these.) If you have been launching IDLE via /Applications/MacPython 2.5/IDLE.app, try launching it via the shell command line: /usr/local/bin/idle2.5. There may now be a working Preferences menu item under the Python item in the menu bar; there may also be an Options -> Configure IDLE... . If that doesn't work, it should be possible to copy the default def files from idlelib in the python installation to your .idlerc directory and manually edit them there - ugh!. Something like: $ cd `python2.5 -c 'import sys; print sys.prefix'` $ cd lib/python2.5/idlelib $ ls *.def config-extensions.def config-highlight.def config-keys.def config-main.def $ cp -i *.def ~/.idlerc $ cd ~/.idlerc $ vi ... -- Ned Deily, nad at acm.org From steve at holdenweb.com Tue Jan 27 14:45:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 14:45:03 -0500 Subject: optparse question In-Reply-To: References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Peter Otten wrote: > Pat wrote: > >> The question was it possible to add a simple flag like 'd-' to optparse >> with no other parameters? > > Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's > answer? > I guess it got crowded out by the prima donnas anxious to help Pat phrase his/her question better ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Pat at junk.net Tue Jan 27 14:45:15 2009 From: Pat at junk.net (Pat) Date: Tue, 27 Jan 2009 14:45:15 -0500 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: Peter Otten wrote: > Pat wrote: > >> The question was it possible to add a simple flag like 'd-' to optparse >> with no other parameters? > > Do you mean "d-" or "-d"? If the latter, what's wrong with Robert Kern's > answer? > > Peter > I mean "-d" since that's what Unix commands expect for flags. My sole intention for the "-d" was to put my program into debug mode so that while I'm using the Wing IDE, I can debug my program using just one child process (instead of dozens) without having to change a constant within my program. I haven't figured out a way to debug multiple child processes in Wing. But, I confess, I haven't been very vigorous in learning how. My other intention was to learn the optparse module just for the sake of learning. From steve at holdenweb.com Tue Jan 27 14:47:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 14:47:40 -0500 Subject: Why GIL? (was Re: what's the point of rpython?) In-Reply-To: <7x8wowegey.fsf@ruckus.brouhaha.com> References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: >> I'm a fan of lock-free data structure and software transactional >> memory, but I'm also a realist. Heck, I'm one of this group's >> outspoken advocates of threaded architectures. Theoretical >> breakthroughs will happen, but in real world of today, threads are >> great but GIL-less Python is a loser. > > GIL-less Python (i.e. Jython) already exists and beats CPython in > performance a lot of the time, including on single processors. > Whether the GIL can be eliminated from CPython without massive rework > to every extension module ever written is a separate question, of > course. Jython can be viewed a proof of concept. . I think probably the GIL will never be extracted successfully. Also IronPython and PyPy (though the latter only in concept for now, I believe). Even Guido admits that CPython doesn't necessarily represent the dominant future strain ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Russ.Paielli at gmail.com Tue Jan 27 14:56:51 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 27 Jan 2009 11:56:51 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> On Jan 27, 11:40 am, Luis Zarrabeitia wrote: > I think you still fail to see that what we are objecting is not that the > original writer can "optionally" use the enforced data hiding (which, as > someone pointed out before me, can be done with tools like pylint). The > objection is about the _user_ of the library. If you don't force it into the > _user_, how is it different from the current situation? And if you do force > it, how can you say that it is optional? As I have pointed out several times, the user cannot be forced to respect data hiding if he has access to the source code (and the right to modify it). If Python had a "private" keyword (or equivalent), for example, the user would only need to delete it wherever necessary to gain the desired access. From vincent at vincentdavis.net Tue Jan 27 15:07:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 13:07:32 -0700 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: <77e831100901271207o4117998cqc35c3b62fdbb15b5@mail.gmail.com> I am using "EPD with Py2.5 4.0.30002"when I try to launch IDLE.app which is in the above folder i get -bash: IDLE.app: command not found which is strange because when I do ls it is listed. the path to the folder is /Applications/EPD\ with\ Py2.5\ 4.0.30002 ls returns Build Applet.app Mayavi.terminal Docs Pylab.terminal Examples Python Launcher.app Extras Update Shell Profile.command IDLE.app Then I do/get vincent-daviss-macbook-pro:EPD with Py2.5 4.0.30002 vmd$ IDLE.app -bash: IDLE.app: command not found Not sure what I am doing wrong Is the a way do download a new version of IDLE.app? That last part is ugh! Thanks Vincent Davis On Tue, Jan 27, 2009 at 12:40 PM, Ned Deily wrote: > In article > <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, > Vincent Davis wrote: > > I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it > > states I can change he text coloring by using "Configure IDLE" but I not > > sure what this is. It's not sn the menu, running Configure does nothing. > How > > do I change the color (text and background) > > There is supposed to be a Preferences menu option for IDLE on OS X but, > depending on the Python version and how IDLE is launched, it may or may > not appear due to various bugs. (I'm working on some patches for these.) > > If you have been launching IDLE via /Applications/MacPython > 2.5/IDLE.app, try launching it via the shell command line: > /usr/local/bin/idle2.5. There may now be a working Preferences menu > item under the Python item in the menu bar; there may also be an Options > -> Configure IDLE... . If that doesn't work, it should be possible to > copy the default def files from idlelib in the python installation to > your .idlerc directory and manually edit them there - ugh!. Something > like: > > $ cd `python2.5 -c 'import sys; print sys.prefix'` > $ cd lib/python2.5/idlelib > $ ls *.def > config-extensions.def config-highlight.def config-keys.def > config-main.def > $ cp -i *.def ~/.idlerc > $ cd ~/.idlerc > $ vi ... > > -- > Ned Deily, > nad at acm.org > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bumens at dingens.org Tue Jan 27 15:10:32 2009 From: bumens at dingens.org (Volker Birk) Date: Tue, 27 Jan 2009 21:10:32 +0100 (CET) Subject: pyPEG parser-interpreter released Message-ID: Hi, pyPEG is a general parser for context free languages as a small Python module. It is PEG (Parsing Expression Grammar) based. It can be very easily used in your Python program. Everybody who understands regular expressions can quickly understand and use pyPEG. The output result is a standard Python data structure, pyAST, just consisting of lists of strings and tuples. You can find pyPEG here: Yours, VB. -- Bitte beachten Sie auch die R?ckseite dieses Schreibens! From mdw at distorted.org.uk Tue Jan 27 15:13:17 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:13:17 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <0de967fe-cb08-4f9f-8dd9-38afcc59031b@a12g2000yqm.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <871vuose1u.fsf.mdw@metalzone.distorted.org.uk> [No, my email address doesn't begin `m...@'. Fixed.] Michele Simionato writes: > On Jan 21, 2:11 am, Mark Wooding wrote: > >> CLOS is much more complex and dynamic than Python's object system; >> but it can be compiled very aggressively. > > I agree that CLOS is complex and that it can be compiled very > aggressively, but I do not think that it is more dynamic than Python. > What feature are you alluding to? Multimethods? There are many Python > implementations of them, they are just not in the standard library. > Or are you referring to interactive facilities, such as the one > discussed in this recipe http://code.activestate.com/recipes/160164 ? I'm referring to a number of features: * Redefinition of classes, yes. Interactive development is very frustrating without this. Thanks for that link, by the way! * CHANGE-CLASS to change the class of instances. This is more than just assigning to mumble.__class__, since it correctly initializes the slots present in the new class which were absent in the old. * And all of the fancy MOP tricks you can play: inventing new slot classes; messing with class-precedence-list orderings (Python's MRO). It's a shorter list than I'd hoped! Still, these features kind of multiply up. You can redefine a class using a new metaclass and slot options, and all the instances are updated, for example. Anyway, I think I exaggerated when I said that CLOS was `much more dynamic', but it is /somewhat/ more dynamic, and still amenable to optimization; since my point was that dynamism in a language isn't necessarily antithetical to compilation, that's still sufficient. Thanks for keeping me honest! -- [mdw] From bumens at dingens.org Tue Jan 27 15:15:04 2009 From: bumens at dingens.org (Volker Birk) Date: Tue, 27 Jan 2009 21:15:04 +0100 (CET) Subject: pyPEG parser-interpreter released Message-ID: Hi, pyPEG is a general parser for context free languages as a small Python module. It is PEG (Parsing Expression Grammar) based. It can be very easily used in your Python program. Everybody who understands regular expressions can quickly understand and use pyPEG. The output result is a standard Python data structure, pyAST, just consisting of lists of strings and tuples. You can find pyPEG here: pyPEG is Free Software. It is under the GNU General Public License 2.0. Yours, VB. -- Bitte beachten Sie auch die R?ckseite dieses Schreibens! From mdw at distorted.org.uk Tue Jan 27 15:22:57 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:22:57 +0000 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <87wscgqz1a.fsf.mdw@metalzone.distorted.org.uk> Grant Edwards writes: > I've always found comp.lang.c to be a rather dangerous place as well. Hey, I grew up in comp.lang.c! I'd have to agree with you, though. (I try to play nice when I'm here.) In fact, comp.lang.* generally has a reputation as a place you don't want to find yourself after dark... > Of the newsgroups I read, c.l.python is probably the most friendly and > has one of the highest S/N ratios. People who would have been roasted > alive in other newsgroups for their laziness or presumptuousness get > surprisingly gentle treatment in c.l.python. I do know of a few > low-volume mailing lists that are probably as good, but for a Usenet > news group with any volume at all, c.l.pythong is exceptionally good. I certainly agree with this. And it's definitely a spirit that's worth preserving. -- [mdw] From cousinstanley at gmail.com Tue Jan 27 15:25:18 2009 From: cousinstanley at gmail.com (gmail_cs) Date: Tue, 27 Jan 2009 13:25:18 -0700 Subject: *.python.org broken? In-Reply-To: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> References: <864d37090901260248x2d568183o70f8031c01a81329@mail.gmail.com> Message-ID: <200901271325.18667.cousinstanley@gmail.com> On Monday 26 January 2009 03:48:25 am you wrote: > I experienced the same problem here in Brazil. Tweeks ago I could not > access any *.python.org site. Today I tried and it worked. The > problem seemed to be limited to Python's domain because I could > access every other site that I tried the same day. > .... > Carlos Ribeiro Since yesterday ( Monday 2009-01-26 ) I can again access http://python.org with no problems .... -- Stanley C. Kitching Human Being Phoenix, Arizona From rhamph at gmail.com Tue Jan 27 15:31:46 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 27 Jan 2009 12:31:46 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <018a4b9c$0$20629$c3e8da3@news.astraweb.com> <497da399$0$4780$426a74cc@news.free.fr> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> Message-ID: On Jan 27, 12:13?pm, "Russ P." wrote: > On Jan 26, 6:09 am, Steve Holden wrote: > > > Quite. Python is a language "for consenting adults". It has perceived > > deficiencies for certain software engineering environments. Can we drop > > the subject now? This horse was flogged to death long ago, and it's > > pointless and cruel to keep on beating the remains. > > Judging from this thread, not everyone got the memo yet. At least > three or four people on this thread alone have argued that enforced > data hiding is of no value whatsoever for any application or domain. > And more than one of them has argued that Python is perfectly > appropriate for even the largest and most safety-critical projects. > > We are moving into an era of increasing dependence on computers and > software for safety-critical, mission-critical, and ?financial > systems. If people who do not understand the principles ?necessary for > ultra-reliable software get in charge of developing these systems, we > will have serious problems that could have been avoided. > > I suggested that maybe -- maybe! -- the versatility of Python could be > enhanced with enforced data hiding. I was careful to say several times > that I don't know if that can even be done in Python (with all its > introspection and so forth). And it would always be optional, of > course (as far as I know, no language forces anyone to declare > anything private). > > Several people here seem to take that suggestion as an assault on > Python and, by projection, an assault on their worldview. We all know > that Python is a fantastic language for many purposes, but it is only > a language, and failing to recognize and address its limitations > serves no useful purpose. What you need is a middle ground. Something that can be *easily* circumvented for debugging, unit tests, and "friend" functions/modules/ class. Without suggesting a middle ground people are left assuming C++-style privates/protected, which would be a significant burden on everybody. The only way it wouldn't is if nobody actually uses it, except in specialized high-assurance software, but at that point you might as well fork python (or use metaclass trickery). From kyosohma at gmail.com Tue Jan 27 15:35:39 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 12:35:39 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> <87wscgqz1a.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <94b92fa9-6c6a-432d-bb6e-cdaad3740620@o4g2000pra.googlegroups.com> > > Of the newsgroups I read, c.l.python is probably the most friendly and > > has one of the highest S/N ratios. ?People who would have been roasted > > alive in other newsgroups for their laziness or presumptuousness get > > surprisingly gentle treatment in c.l.python. ?I do know of a few > > low-volume mailing lists that are probably as good, but for a Usenet > > news group with any volume at all, c.l.pythong is exceptionally good. > > I certainly agree with this. ?And it's definitely a spirit that's worth > preserving. > > -- [mdw] I don't know if we should encourage the use of pythons as thongs myself...I didn't even know there was a group on that topic. ;) Mike From mdw at distorted.org.uk Tue Jan 27 15:37:03 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:37:03 +0000 Subject: Pexpect and telnet not communicating properly References: <497f35ef$0$30312$da0feed9@news.zen.co.uk> Message-ID: <87skn4qyds.fsf.mdw@metalzone.distorted.org.uk> David Anderson writes: > I am trying to automate the following session - to talk to my router: > > telnet speedtouch [...] > I am using the following code: [...] > child.expect('sername : ') > child.sendline('Administrator') I've scripted communications with my Speedtouch 510 using pexpect: I use it to send the router's logs to my server. The obvious difference between my script and yours is that instead of sendline, I used send and an explicit carriage return. kid.expect('Username :') kid.send('admin\r\n') I think this is a result of a similar problem, but I don't remember any more. Anyway, I've put my (very simple) script up at http://www.distorted.org.uk/~mdw/example/guvnor-maintenance in case you're interested. (No, I wasn't daft enough to put the password in the script!) -- [mdw] From rhamph at gmail.com Tue Jan 27 15:40:50 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Tue, 27 Jan 2009 12:40:50 -0800 (PST) Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: On Jan 27, 12:47?pm, Steve Holden wrote: > Paul Rubin wrote: > > GIL-less Python (i.e. Jython) already exists and beats CPython in > > performance a lot of the time, including on single processors. > > Whether the GIL can be eliminated from CPython without massive rework > > to every extension module ever written is a separate question, of > > course. ?Jython can be viewed a proof of concept. > > . I think probably the GIL will never be extracted successfully. > > Also IronPython and PyPy (though the latter only in concept for now, I > believe). Even Guido admits that CPython doesn't necessarily represent > the dominant future strain ... IMO it's possible to rewrite only the core while keeping the refcount API for external compatibility, but a tracing GC API in portable C is hideous. Enough to make me want to find or make a better implementation language. From http Tue Jan 27 15:45:22 2009 From: http (Paul Rubin) Date: 27 Jan 2009 12:45:22 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xzlhimttv.fsf@ruckus.brouhaha.com> <3suel.9403$hc1.2921@flpi150.ffdc.sbc.com> <7x63k5ie5t.fsf@ruckus.brouhaha.com> <590f2d4e-2614-4831-b196-9b875a5cec81@f40g2000pri.googlegroups.com> <7x63k5chho.fsf@ruckus.brouhaha.com> <7x8wowegey.fsf@ruckus.brouhaha.com> Message-ID: <7x63k0iil9.fsf@ruckus.brouhaha.com> Rhamphoryncus writes: > IMO it's possible to rewrite only the core while keeping the refcount > API for external compatibility, but a tracing GC API in portable C is > hideous. It's done all the time for other languages, and is less hassle than the incref/decref stuff and having to remember the difference between owned and borrowed references, etc. > Enough to make me want to find or make a better implementation language. There is a lot to be said for this, including the self-respect that comes from a language being able to host its own implementation. From steve at holdenweb.com Tue Jan 27 15:47:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 15:47:02 -0500 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: rantingrick wrote: > On Jan 27, 12:00 pm, Paul Rubin wrote: >> Guido does post here once in a while, under his own name. I can't >> think of any very recent examples, but I can remember some from a few >> years back. > > I searched the archives for "Guido van Rossum" and there is nothing > since May 2000. That's the most recent i could find anyway?? I suspect his last major interaction was the "voting" for either the decorator or the ternary operator/if expression syntax. At that point I suspect he decided interaction with the community didn't actually improve the design of the language. But I'm not Guido. Honest. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From duncan.booth at invalid.invalid Tue Jan 27 15:52:02 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jan 2009 20:52:02 GMT Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: Thorsten Kampe wrote: > * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) >> On Jan 27, 12:00??pm, Paul Rubin wrote: >> > Guido does post here once in a while, under his own name. ??I can't >> > think of any very recent examples, but I can remember some from a few >> > years back. >> >> I searched the archives for "Guido van Rossum" and there is nothing >> since May 2000. That's the most recent i could find anyway?? > > Search again - the last was in December 2008: > http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= > 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 > &as_maxd=1&as_maxm=1&as_maxy=2009 > &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa > fe=off Or even: http://groups.google.com/groups/profile?show=more&enc_user=RVb59hAAAADAKHw2rKTOXQmYRzwTg33E&group=comp.lang.python which shows 456 posts to clp over the last 9 years, but only about once a year for the last 3 years. For comparison, according to Google I've managed 2251 posts to clp since 1997 which I find kind of scary. From mdw at distorted.org.uk Tue Jan 27 15:53:34 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 27 Jan 2009 20:53:34 +0000 Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <8e272a5a-5546-4eff-b72f-d98b66f22e5c@w39g2000prb.googlegroups.com> <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> Message-ID: <87ocxsqxm9.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > If Python had a "private" keyword (or equivalent), for example, the > user would only need to delete it wherever necessary to gain the > desired access. And you obviously weren't listening when we said that having to make source code changes to upstream modules was a serious maintenance and distribution headache: <87ab9f8dp1.fsf.mdw at metalzone.distorted.org.uk> -- [mdw] From nad at acm.org Tue Jan 27 15:58:11 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 12:58:11 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> <77e831100901271207o4117998cqc35c3b62fdbb15b5@mail.gmail.com> Message-ID: In article <77e831100901271207o4117998cqc35c3b62fdbb15b5 at mail.gmail.com>, Vincent Davis wrote: > I am using "EPD with Py2.5 4.0.30002"when I try to launch IDLE.app which is > in the above folder i get -bash: IDLE.app: command not found > which is strange because when I do ls it is listed. > the path to the folder is > /Applications/EPD\ with\ Py2.5\ 4.0.30002 > ls returns > Build Applet.app Mayavi.terminal > Docs Pylab.terminal > Examples Python Launcher.app > Extras Update Shell Profile.command > IDLE.app > > Then I do/get > vincent-daviss-macbook-pro:EPD with Py2.5 4.0.30002 vmd$ IDLE.app > -bash: IDLE.app: command not found > > Not sure what I am doing wrong You can't launch an OSX application bundle from a shell that way. You could use /usr/bin/open but that should give the same results as double-clicking on the IDLE icon. I don't have personal experience with EPD distribution but there should be a command line binary of idle included. Try this from a Terminal shell: $ cd `python -c 'import sys; print sys.prefix'` $ bin/idle If you can change and save the preferences that way, they should then apply to IDLE no matter how you launch it. -- Ned Deily, nad at acm.org From Scott.Daniels at Acm.Org Tue Jan 27 15:58:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 27 Jan 2009 12:58:37 -0800 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <7xeiz5xn55.fsf@ruckus.brouhaha.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <026a69b3-bdcc-4b4f-9323-124eed7fa31f@u18g2000pro.googlegroups.com> <7x63klqwdd.fsf@ruckus.brouhaha.com> <9e274259-f485-437d-8e1a-da19e531150e@s9g2000prg.googlegroups.com> <7xhc45csw0.fsf@ruckus.brouhaha.com> <496bb081$0$31451$426a74cc@news.free.fr> <7xfxjofbqw.fsf@ruckus.brouhaha.com> <496ce14b$0$18741$426a74cc@news.free.fr> <9dca1372-f9d9-4992-81df-d763ca9198ee@w1g2000prm.googlegroups.com> <496dc349$0$21349$426a74cc@news.free.fr> <7xljtdkim7.fsf@ruckus.brouhaha.com> <496e1804$0$3515$426a74cc@news.free.fr> <7xpripzuwp.fsf@ruckus.brouhaha.com> <7xeiz5xn55.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Scott David Daniels writes: >> But, the research on the language "Self" shows that even in the face >> of a language with more dynamism than Smalltalk (or Python), performance >> can be obtained using compiler technology.... > > I'd be interested in seeing any publications about that Self research, > which I remember someone else mentioning in another thread as well. Sorry this was sitting in drafts. Search for David Ungar and/or Randall Smith and Self. --Scott David Daniels Scott.Daniels at Acm.Org From reckoner at gmail.com Tue Jan 27 16:16:36 2009 From: reckoner at gmail.com (Reckoner) Date: Tue, 27 Jan 2009 13:16:36 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? Message-ID: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> I'm not sure this is possible, but I would like to have a list of objects A=[a,b,c,d,...,z] where, in the midst of a lot of processing I might do something like, A[0].do_something_which_changes_the_properties() which alter the properties of the object 'a'. The trick is that I would like A to be mysteriously aware that something about the object 'a' has changed so that when I revisit A, I will know that the other items in the list need to be refreshed to reflect the changes in A as a result of changing 'a'. Even better would be to automatically percolate the subsequent changes that resulted from altering 'a' for the rest of the items in the list. Naturally, all of these items are related in some parent-child fashion. that might be a lot to ask, however. Any advice appreciated. From excord80 at gmail.com Tue Jan 27 16:19:02 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 13:19:02 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? Message-ID: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> I need to make a small, relatively low-traffic site that users can create accounts on and log into. Scripts must run as cgi (no mod_python or FastCGI is available). Can anyone recommend a small and simple web framework for Python, maybe similar to Perl's CGI::Application? Or would it just be better to roll my own? From robert.kern at gmail.com Tue Jan 27 16:21:40 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 15:21:40 -0600 Subject: optparse with numpy.array? In-Reply-To: <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> References: <417457b50901261544h5467b64xaf00eff63bcb646b@mail.gmail.com> <417457b50901262145i5d7cc39q99f453dfafd5833a@mail.gmail.com> <417457b50901262201h7eb5a929m971c05a0ba9edc68@mail.gmail.com> <417457b50901270109u2f450ba8jce5e939ec3df53c4@mail.gmail.com> Message-ID: On 2009-01-27 03:09, Johan Ekh wrote: > Thanks, > James I will try your suggestion! > Robert, what mean with "interactively" is that i would like to create an > array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or > by reading a file with values etc., and then execute my program with > "myprog -m m_i" and thus pass the array "m_i" to my program. > > This is just an example. I would like to pass several arrays. My program > will be wrapped inside a loop and the arrays are updated > in each loop. > > I have never heard of the "argparse" library. Do you think that it would > be better to use that in my case? No. Basically, no command line parser is going to work like you want. If you want to run something from IPython using the objects in your IPython session, you should make a module instead of a program. Import your module, and call its functions. Then you can pass whatever objects you like. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From clp2 at rebertia.com Tue Jan 27 16:27:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jan 2009 13:27:02 -0800 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <50697b2c0901271327t2aec0155w3e0391d6a4fd06df@mail.gmail.com> On Tue, Jan 27, 2009 at 1:16 PM, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. Have you considered: A.change_properties_of_item_and_know_about_it(0) ? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From alecla at bluewin.ch Tue Jan 27 16:41:31 2009 From: alecla at bluewin.ch (alex) Date: Tue, 27 Jan 2009 13:41:31 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values Message-ID: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> Hello everybody I am mainly a Fortran programmer and beginning to learn Python(2.5) and OOP programming. I hope in the end to put a GUI on my existing Fortran code. Therefore I am also trying to learn Python's "ctypes" library. Unfortunately the ctypes tutorial does not show simple examples so I set up a simple fortran module and Python script to test. But even with passing Integer and Real values I get the right output but with subsequent error: ValueError: Procedure probably called with too many arguments (4 bytes in excess) The scripts exits then, so the second subroutine call does not happen. >From reading comp.lang.python and comp.lang.fortran I understood that passing character strings may not be simple but I could not find any solution to my problem. Maybe somebody can help me with solving it? The Fortran module (footst.f90): ! module footst ! implicit none ! ! !- End of module header ------------------------------------------------ ! !- Execution part of the module ---------------------------------------- ! ! contains !- Define procedures contained in this module. ! !----------------------------------------------------------------------- ! ! subroutine foo1(int_tst) !DEC$ ATTRIBUTES DLLEXPORT :: foo1 integer, intent(in):: int_tst write(unit=*, fmt="(a)") "Subroutine foo1(int_tst)" write(unit=*, fmt="(a, i4)") "a= ", int_tst end subroutine foo1 ! ! subroutine foo2(real_tst) !DEC$ ATTRIBUTES DLLEXPORT :: foo2 real, intent(in):: real_tst write(unit=*, fmt="(a)") "Subroutine foo2(real_tst)" write(unit=*, fmt="(a, f6.2)") "a= ", real_tst end subroutine foo2 ! ! end module footst ! The Python script (footst.py): #!/usr/bin/env python # # from ctypes import * # # if __name__ == '__main__': tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") # tst.restype=None # tst.argtypes=(c_int) x=c_int(999) y=c_float(10.5) tst.footst_mp_foo1_(byref(x)) # Passing Real values commented out, but leads to the same error # tst.footst_mp_foo2_(byref(y)) # main() # # The DOS prompt output: F:\Scratch\Test2>df /dll /iface=(cref,nomixed_str_len_arg)/ names:lowercase /assume:underscore footst.f90 Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update B) Copyright 2001 Compaq Computer Corp. All rights reserved. footst.f90 Microsoft (R) Incremental Linker Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. /entry:_DllMainCRTStartup at 12 /ignore:505 /debugtype:cv /debug:minimal /pdb:none F:\SysTemp\obj5B.tmp dfordll.lib msvcrt.lib dfconsol.lib dfport.lib kernel32.lib /out:footst.dll /dll Creating library footst.lib and object footst.exp F:\Scratch\Test2>dumpbin /exports footst.dll Microsoft (R) COFF Binary File Dumper Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. Dump of file footst.dll File Type: DLL Section contains the following exports for footst.dll 0 characteristics 497F5CC3 time date stamp Tue Jan 27 20:13:07 2009 0.00 version 1 ordinal base 2 number of functions 2 number of names ordinal hint RVA name 1 0 00001000 footst_mp_foo1_ 2 1 000010A6 footst_mp_foo2_ Summary 1000 .data 1000 .rdata 1000 .reloc 1000 .text F:\Scratch\Test2>footst.py Subroutine foo1(int_tst) a= 999 Traceback (most recent call last): File "F:\Scratch\Test2\footst.py", line 13, in tst.footst_mp_foo1_(byref(x)) ValueError: Procedure probably called with too many arguments (4 bytes in excess) F:\Scratch\Test2> From robert.kern at gmail.com Tue Jan 27 16:42:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 15:42:52 -0600 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: On 2009-01-27 13:40, Ned Deily wrote: > In article > <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, > Vincent Davis wrote: >> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it >> states I can change he text coloring by using "Configure IDLE" but I not >> sure what this is. It's not sn the menu, running Configure does nothing. How >> do I change the color (text and background) > > There is supposed to be a Preferences menu option for IDLE on OS X but, > depending on the Python version and how IDLE is launched, it may or may > not appear due to various bugs. (I'm working on some patches for these.) I'd love to get these patches so we can include them in EPD. Is there an issue on the Python bug tracker that I can follow? > If you have been launching IDLE via /Applications/MacPython > 2.5/IDLE.app, try launching it via the shell command line: > /usr/local/bin/idle2.5. In Vincent's case (EPD), this would be /Library/Frameworks/Python/Versions/Current/bin/idle2.5 . > There may now be a working Preferences menu > item under the Python item in the menu bar; there may also be an Options > -> Configure IDLE... . Yes, to both. -- 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 kyrie at uh.cu Tue Jan 27 16:44:24 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 27 Jan 2009 16:44:24 -0500 Subject: Does Python really follow its philosophy of "Readability counts"? In-Reply-To: <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <644ec4fc-95a5-43b3-bf64-8f9f195ba2e0@v5g2000prm.googlegroups.com> Message-ID: <200901271644.24918.kyrie@uh.cu> On Tuesday 27 January 2009 02:56:51 pm Russ P. wrote: > On Jan 27, 11:40 am, Luis Zarrabeitia wrote: > > I think you still fail to see that what we are objecting is not that the > > original writer can "optionally" use the enforced data hiding (which, as > > someone pointed out before me, can be done with tools like pylint). The > > objection is about the _user_ of the library. If you don't force it into > > the _user_, how is it different from the current situation? And if you do > > force it, how can you say that it is optional? > > As I have pointed out several times, the user cannot be forced to > respect data hiding if he has access to the source code (and the right > to modify it). If Python had a "private" keyword (or equivalent), for > example, the user would only need to delete it wherever necessary to > gain the desired access. And, as others and I have pointed out several times, that would mean to maintain a fork. Would you say that current C++ has "optional" enforced data hiding for the user? After all, you can just fork the module (and if you don't have the source, you could mess with pointers until you find it). Also, I once pointed out that "access to the source code and right to modify it" is not a given. What you are proposing is not optional at all. You want the power to control what others do - and while it may be your legal right, it's also everyone else's right not go our of our ways to help you have it. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From python.list at tim.thechases.com Tue Jan 27 16:52:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Jan 2009 15:52:12 -0600 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <497F820C.7000304@tim.thechases.com> > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? What are you looking for in your framework? Python comes with its own CGI module[1]. For the most basic of sites, this works nicely. However, if you want to be able to easily slide into a bigger environment, I've been pleased with WebStack[2] for my lightweight needs. It makes light work of transitioning from CGI to other stacks such as mod_python, Twisted, WSGI, etc. Backed with a simple sqlite DB, and some simple HTML/Python templating, just using dict-expansion: # template.html contains content like #

field1 = %(field1)s

template = file('template.html').read() : : params = { "field1": "value1", "field2": "value2", } : : return template % params Just set up the values in the params-dict, and use it to display your template. -tkc [1] http://docs.python.org/library/cgi.html [2] http://www.boddie.org.uk/python/WebStack.html From kyosohma at gmail.com Tue Jan 27 16:54:48 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 27 Jan 2009 13:54:48 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <7xmydc6347.fsf@ruckus.brouhaha.com> Message-ID: <86afa476-22d6-463e-b4f1-d193a8d3501e@w1g2000prm.googlegroups.com> On Jan 27, 2:52?pm, Duncan Booth wrote: > Thorsten Kampe wrote: > > * rantingrick (Tue, 27 Jan 2009 10:03:16 -0800 (PST)) > >> On Jan 27, 12:00?pm, Paul Rubin wrote: > >> > Guido does post here once in a while, under his own name. ?I can't > >> > think of any very recent examples, but I can remember some from a few > >> > years back. > > >> I searched the archives for "Guido van Rossum" and there is nothing > >> since May 2000. That's the most recent i could find anyway?? > > > Search again - the last was in December 2008: > >http://groups.google.com/groups/search?as_q=&as_epq=&as_oq=&as_eq=&num= > > 10&scoring=d&lr=&as_sitesearch=&as_qdr=&as_mind=1&as_minm=1&as_miny=2009 > > &as_maxd=1&as_maxm=1&as_maxy=2009 > > &as_ugroup=comp.lang.python&as_usubject=&as_uauthors=guido+van+rossum&sa > > fe=off > > Or even: > > http://groups.google.com/groups/profile?show=more&enc_user=RVb59hAAAA... > > which shows 456 posts to clp over the last 9 years, but only about once a > year for the last 3 years. > > For comparison, according to Google I've managed 2251 posts to clp since 1997 > which I find kind of scary. That's not scary! I've managed over 1100 posts since 2007... Mike From vincent at vincentdavis.net Tue Jan 27 16:57:52 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 27 Jan 2009 14:57:52 -0700 Subject: change syntax coloring in IDLE In-Reply-To: References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: <77e831100901271357h2ac39589u2fbf2c7556f2e42c@mail.gmail.com> using terminal and opening"In Vincent's case (EPD), this would be /Library/Frameworks/Python/Versions/Current/bin/idle2.5" Worked!! Thanks for the help. Vincent Davis On Tue, Jan 27, 2009 at 2:42 PM, Robert Kern wrote: > On 2009-01-27 13:40, Ned Deily wrote: > >> In article >> <77e831100901270950i6b0b510chf80a495a65ca9833 at mail.gmail.com>, >> Vincent Davis wrote: >> >>> I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it >>> states I can change he text coloring by using "Configure IDLE" but I not >>> sure what this is. It's not sn the menu, running Configure does nothing. >>> How >>> do I change the color (text and background) >>> >> >> There is supposed to be a Preferences menu option for IDLE on OS X but, >> depending on the Python version and how IDLE is launched, it may or may >> not appear due to various bugs. (I'm working on some patches for these.) >> > > I'd love to get these patches so we can include them in EPD. Is there an > issue on the Python bug tracker that I can follow? > > If you have been launching IDLE via /Applications/MacPython >> 2.5/IDLE.app, try launching it via the shell command line: >> /usr/local/bin/idle2.5. >> > > In Vincent's case (EPD), this would be > /Library/Frameworks/Python/Versions/Current/bin/idle2.5 . > > There may now be a working Preferences menu >> item under the Python item in the menu bar; there may also be an Options >> -> Configure IDLE... . >> > > Yes, to both. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Tue Jan 27 17:16:26 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 14:16:26 -0800 Subject: change syntax coloring in IDLE References: <77e831100901270950i6b0b510chf80a495a65ca9833@mail.gmail.com> Message-ID: In article , Robert Kern wrote: > On 2009-01-27 13:40, Ned Deily wrote: > > There is supposed to be a Preferences menu option for IDLE on OS X but, > > depending on the Python version and how IDLE is launched, it may or may > > not appear due to various bugs. (I'm working on some patches for these.) > I'd love to get these patches so we can include them in EPD. Is there an > issue > on the Python bug tracker that I can follow? Not yet but soon. I ran across this recently with bug squashing of Python 3 on OSX and it's still not quite fixed. I'll ping back here when the issue/patch is filed. In article <77e831100901271357h2ac39589u2fbf2c7556f2e42c at mail.gmail.com>, Vincent Davis wrote: > Worked!! Yay! -- Ned Deily, nad at acm.org From toby at tobiah.org Tue Jan 27 17:30:29 2009 From: toby at tobiah.org (Tobiah) Date: Tue, 27 Jan 2009 14:30:29 -0800 Subject: len() Message-ID: Just out of curiosity, why was len() made to be it's own function? I often find myself typing things like my_list.len before I catch myself. Thanks, Toby From tino at wildenhain.de Tue Jan 27 17:43:00 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 27 Jan 2009 23:43:00 +0100 Subject: USB in python In-Reply-To: <49797836.5020807@al.com.au> References: <6tqvb2Fcan25U1@mid.uni-berlin.de> <6tt858Fclr1hU1@mid.uni-berlin.de> <6tta0aFckqj7U1@mid.uni-berlin.de> <49797836.5020807@al.com.au> Message-ID: <497F8DF4.4070303@wildenhain.de> Hi, Astan Chee wrote: > > Diez B. Roggisch wrote: >>> >> >> If all you need is on-off - why can't you just use a switch? >> >> >> > Because I want to control the on-off the device using a computer and > write software for it (which I am confident I can do if I had references > to how the wrappers to said interface). What I'm using is dallas 1wire stuff to do such things. The dongle (which is available as USB too) connects to the host and you have a lib with bindings even to python for it: http://www.owfs.org/ The other end is just a bus with a telephone wire... The most interesting part might be temperature sensors but there are a lot of GPIO chips, electronic resistors, A/D converters etc. available. Most of the stuff can be even ordered as sample from dallas/maxim. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mensanator at aol.com Tue Jan 27 17:44:45 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 27 Jan 2009 14:44:45 -0800 (PST) Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> Message-ID: On Jan 27, 11:53?am, rantingrick wrote: > On Jan 27, 10:12?am, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > All you can say is that he didn't *post* here (at least under his real > > identity...) for the 9 past years - this doesn't mean he never *reads* > > (and this, you just have no way to know). > > Ah, this is a good point. You have to wonder, Guido could be one of > the regulars here. very interesting. We should have a vote as to who > would be the most likely candidate, now that would be a good thread :) It's not me!! :-) From david at boddie.org.uk Tue Jan 27 17:58:18 2009 From: david at boddie.org.uk (David Boddie) Date: Tue, 27 Jan 2009 23:58:18 +0100 Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: On Tuesday 27 January 2009 18:29, Gabriel Genellina wrote: > En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas > escribi?: > >> Hello all, This is my first post to this mailing list. Our requirement >> is to invoke a Tkinter python panel from a C++ GUI app where both GUI >> windows would run in 2 separate threads. We have written a sample PyQt >> application which calls this Tk panel using something like this:class >> TkPanel(threading.Thread):def run(self): # call showPaneldef >> showPanel():# create window = Tk.Tk() window.mainloop()def start():t = >> TkPanel()t.start()Now we call this from our main python code:def >> startPanel(self): import tkPanel tkPanel.start() # this calls >> tkwindow.mainloop() in a separate thread.This works absolutely fine when >> the invoking app is Python. > > From the above description I don't see where PyQt is involved. Do you > really want to mix Qt and Tk in the same application? I don't think they > could coexist... It's been made to work before: http://www.froglogic.com/pg?id=Products&category=tq&sub=overview Since Rajorshi has posted this to the PyQt list and qt-interest, in addition to this list, maybe it's time to take a look at the problem more closely: http://www.riverbankcomputing.com/pipermail/pyqt/2009-January/021649.html Without being able to see behind the scenes at what is happening with each framework, we can only say that it looks like some threading issue (possibly just an implementation detail of either framework) is causing control to be returned to the interpreter from within the wrong thread. Maybe it's just an issue of competing event loops and Python C API usage in the extension modules. I found that, using Ubuntu 7.10, the windows stopped receiving repaint events, making it look like the application had frozen. Basically, I think some kind of Qt-Tk event loop integration is required if widgets from both frameworks are going to coexist within the same process. David From joseph.a.marlin at gmail.com Tue Jan 27 18:06:46 2009 From: joseph.a.marlin at gmail.com (joseph.a.marlin at gmail.com) Date: Tue, 27 Jan 2009 15:06:46 -0800 (PST) Subject: New to python, open source Mac OS X IDE? Message-ID: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Greetings! I've heard enough raving about Python, I'm going to see for myself what all the praise is for! I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you even use an IDE for Python? Any recommendations on open source Python environments? Thanks! From joncle at googlemail.com Tue Jan 27 18:08:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 15:08:08 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> Message-ID: <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> On Jan 27, 9:41?pm, alex wrote: > Hello everybody > I am mainly a Fortran programmer and beginning to learn Python(2.5) > and OOP programming. > I hope in the end to put a GUI on my existing Fortran code. > Therefore I am also trying to learn Python's "ctypes" library. > > Unfortunately the ctypes tutorial does not show simple examples so I > set up a simple fortran module > and Python script to test. > But even with passing Integer and Real values I get the right output > but with subsequent error: > ValueError: Procedure probably called with too many arguments (4 bytes > in excess) > The scripts exits then, so the second subroutine call does not happen. > > From reading comp.lang.python and comp.lang.fortran I understood that > passing character strings > may not be simple but I could not find any solution to my problem. > Maybe somebody can help me with solving it? > > The Fortran module (footst.f90): > > ! > ? ? ? module footst > ! > ? ? ? implicit none > ! > ! > !- End of module header > ------------------------------------------------ > ! > !- Execution part of the module > ---------------------------------------- > ! > ! > ? ? ? contains > !- Define procedures contained in this module. > ! > !----------------------------------------------------------------------- > ! > ! > ? ? ? subroutine foo1(int_tst) > ? ? ? !DEC$ ATTRIBUTES DLLEXPORT :: foo1 > ? ? ? integer, intent(in):: int_tst > ? ? ? write(unit=*, fmt="(a)") "Subroutine foo1(int_tst)" > ? ? ? write(unit=*, fmt="(a, i4)") "a= ", int_tst > ? ? ? end subroutine foo1 > ! > ! > ? ? ? subroutine foo2(real_tst) > ? ? ? !DEC$ ATTRIBUTES DLLEXPORT :: foo2 > ? ? ? real, intent(in):: real_tst > ? ? ? write(unit=*, fmt="(a)") "Subroutine foo2(real_tst)" > ? ? ? write(unit=*, fmt="(a, f6.2)") "a= ", real_tst > ? ? ? end subroutine foo2 > ! > ! > ? ? ? end module footst > ! > > The Python script (footst.py): > > #!/usr/bin/env python > # > # > from ctypes import * > # > # > if __name__ == '__main__': > ? ? tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") > # ? ?tst.restype=None > # ? ?tst.argtypes=(c_int) > ? ? x=c_int(999) > ? ? y=c_float(10.5) > ? ? tst.footst_mp_foo1_(byref(x)) > # ? ?Passing Real values commented out, but leads to the same error > # ? ?tst.footst_mp_foo2_(byref(y)) > # > ? ? main() > # > # > > The DOS prompt output: > > F:\Scratch\Test2>df /dll /iface=(cref,nomixed_str_len_arg)/ > names:lowercase /assume:underscore footst.f90 > Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update B) > Copyright 2001 Compaq Computer Corp. All rights reserved. > > footst.f90 > Microsoft (R) Incremental Linker Version 6.00.8447 > Copyright (C) Microsoft Corp 1992-1998. All rights reserved. > > /entry:_DllMainCRTStartup at 12 > /ignore:505 > /debugtype:cv > /debug:minimal > /pdb:none > F:\SysTemp\obj5B.tmp > dfordll.lib > msvcrt.lib > dfconsol.lib > dfport.lib > kernel32.lib > /out:footst.dll > /dll > ? ?Creating library footst.lib and object footst.exp > > F:\Scratch\Test2>dumpbin /exports footst.dll > Microsoft (R) COFF Binary File Dumper Version 6.00.8447 > Copyright (C) Microsoft Corp 1992-1998. All rights reserved. > > Dump of file footst.dll > > File Type: DLL > > ? Section contains the following exports for footst.dll > > ? ? ? ? ? ?0 characteristics > ? ? 497F5CC3 time date stamp Tue Jan 27 20:13:07 2009 > ? ? ? ? 0.00 version > ? ? ? ? ? ?1 ordinal base > ? ? ? ? ? ?2 number of functions > ? ? ? ? ? ?2 number of names > > ? ? ordinal hint RVA ? ? ?name > > ? ? ? ? ? 1 ? ?0 00001000 footst_mp_foo1_ > ? ? ? ? ? 2 ? ?1 000010A6 footst_mp_foo2_ > > ? Summary > > ? ? ? ? 1000 .data > ? ? ? ? 1000 .rdata > ? ? ? ? 1000 .reloc > ? ? ? ? 1000 .text > > F:\Scratch\Test2>footst.py > Subroutine foo1(int_tst) > a= ?999 > Traceback (most recent call last): > ? File "F:\Scratch\Test2\footst.py", line 13, in > ? ? tst.footst_mp_foo1_(byref(x)) > ValueError: Procedure probably called with too many arguments (4 bytes > in excess) > > F:\Scratch\Test2> Have you tried: tst.footst_mp_foo1_.restype = None tst.footst_mp_foo1_(byref(x)) IIRC, the restype is applied to each function, not the library module. good luck, Jon From ori.livneh at gmail.com Tue Jan 27 18:15:51 2009 From: ori.livneh at gmail.com (Ori Livneh) Date: Tue, 27 Jan 2009 18:15:51 -0500 Subject: len() In-Reply-To: References: Message-ID: I'm newish to Python, so this might be way off-base, but I think it this might help: Allen Downey explains in "Think Python" that *"the syntax of a function call suggests that the function is the active agent."* So you're calling the function len() and telling it you have an object for it to measure. By contrast, method invocations suggest that the objects are the active agents. Python syntax does not always follow this implicit logic, but I think it makes sense here. On Tue, Jan 27, 2009 at 5:30 PM, Tobiah wrote: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. > > Thanks, > > Toby > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jan 27 18:16:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 27 Jan 2009 21:16:02 -0200 Subject: len() References: Message-ID: En Tue, 27 Jan 2009 20:30:29 -0200, Tobiah escribi?: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list and http://groups.google.com/group/comp.lang.python/browse_thread/thread/782dcb8d62f28cdb/1480c3f3a1bf68bb#1480c3f3a1bf68bb -- Gabriel Genellina From philip at semanchuk.com Tue Jan 27 18:23:35 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 18:23:35 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <2FA0EA5B-35C2-49AE-84D6-6EF90E015C12@semanchuk.com> On Jan 27, 2009, at 6:06 PM, joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? Some people do; I don't. > Any recommendations on open source Python environments? I don't like single-use environments; I work frequently in Python, C, SQL, HTML, etc. and I prefer a general programmer's editor rather than switching applications based on which language I'm using. For that reason I can't give you any advice on Python-specific environments. My favorite open source editor on OS X that groks Python is jEdit. I, however, use the non-open source TextMate. It's very programmable and has a lot of user-contributed goodies. The community around it has somewhat of an open source ethic even if the main application is not. You could also use XCode which isn't open source, but it is free. HTH and welcome to Python From nad at acm.org Tue Jan 27 18:29:07 2009 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jan 2009 15:29:07 -0800 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: In article <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3 at i24g2000prf.googlegroups.com>, "joseph.a.marlin at gmail.com" wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? Well, there's IDLE that comes packaged with most Python distributions (today must be IDLE day). It may not be on your default path, though. If you are using the python Apple includes with OS X 10.5, you should be able to launch it from a terminal shell with: /usr/bin/python/../idle There is also a separate discussion group for Python on Macs: -- Ned Deily, nad at acm.org From fabiofz at gmail.com Tue Jan 27 18:31:58 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 21:31:58 -0200 Subject: Why doesn't eval of generator expression work with locals? Message-ID: Hi All, Anyone knows why the code below gives an error? global_vars = {} local_vars = {'ar':["foo", "bar"], 'y':"bar"} print eval('all((x == y for x in ar))', global_vars, local_vars) Error: Traceback (most recent call last): File "C:\temp\work\test\src\a.py", line 3, in print eval('all((x == y for x in ar))', global_vars, local_vars) File "", line 1, in File "", line 1, in NameError: global name 'y' is not defined Note that if a list is used instead of a generator it works... Thanks, Fabio From benjamin.kaplan at case.edu Tue Jan 27 18:38:57 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 18:38:57 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 6:06 PM, joseph.a.marlin at gmail.com < joseph.a.marlin at gmail.com> wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! Personally, I like Eclipse with the Pydev plugin. I believe that there is a plugin for Netbeans, but I don't know how well it works. There are also a couple of Python IDEs written in Python, like IDLE, which comes in the standard install, and SPE (http://pythonide.blogspot.com/). The Python wiki has a list of all the major Python IDEs if you want to look at others. http://wiki.python.org/moin/IntegratedDevelopmentEnvironments > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at strout.net Tue Jan 27 18:41:55 2009 From: joe at strout.net (Joe Strout) Date: Tue, 27 Jan 2009 16:41:55 -0700 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <497F9BC3.4080107@strout.net> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? I don't -- I just use TextWrangler and a Terminal window. I tried several IDEs and didn't really find any of them stable and feature-rich enough to be worth the bother (though Editra came close). Lack of a really top-notch IDE is one of the primary drags harshing on my Python buzz (as the young people say). Best, - Joe From andre.roberge at gmail.com Tue Jan 27 18:47:59 2009 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Tue, 27 Jan 2009 15:47:59 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > If you already use netbeans, what about http://www.netbeans.org/features/python/ ? > Any recommendations on open source Python environments? I like Komodo Edit (which has many IDE like features). In fact, I like it so much that I decided to buy the Komodo IDE - the only non- free software I use. Andr? > > Thanks! From prologic at shortcircuit.net.au Tue Jan 27 18:51:37 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 09:51:37 +1000 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: > Anyone knows why the code below gives an error? > > global_vars = {} > local_vars = {'ar':["foo", "bar"], 'y':"bar"} > print eval('all((x == y for x in ar))', global_vars, local_vars) y is undefined in your generator expression. Why are you using eval ? cheers James From excord80 at gmail.com Tue Jan 27 18:53:21 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 15:53:21 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <11afaa71-cfb0-4112-abd3-5bc6dace13af@q30g2000prq.googlegroups.com> On Jan 27, 4:52?pm, Tim Chase wrote: > > I need to make a small, relatively low-traffic site that users can > > create accounts on and log into. Scripts must run as cgi (no > > mod_python or FastCGI is available). Can anyone recommend a small and > > simple web framework for Python, maybe similar to Perl's > > CGI::Application? > > > Or would it just be better to roll my own? > > What are you looking for in your framework? ?Python comes with > its own CGI module[1]. ?For the most basic of sites, this works > nicely. > > However, if you want to be able to easily slide into a bigger > environment, I've been pleased with WebStack[2] for my > lightweight needs. ?[snip] Thanks, Tim. I don't think WebStack is what I'm looking for, but will investigate doing things by hand with the cgi module and using Python's own built-in simple templating. From fabiofz at gmail.com Tue Jan 27 18:56:55 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 21:56:55 -0200 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On Tue, Jan 27, 2009 at 9:51 PM, James Mills wrote: > On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: >> Anyone knows why the code below gives an error? >> >> global_vars = {} >> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >> print eval('all((x == y for x in ar))', global_vars, local_vars) > > y is undefined in your generator expression. Yes... but why? It seems to me like it should be defined (if I put the locals in the globals it finds it... seems very weird to me) > Why are you using eval ? I'm using it to evaluate what the user entered on a watch expression in the Pydev debugger (bug: https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 )... That's just a sample to reproduce it without any dependencies. Cheers, Fabio From joncle at googlemail.com Tue Jan 27 18:59:26 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 15:59:26 -0800 (PST) Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: On Jan 27, 11:31?pm, Fabio Zadrozny wrote: > Hi All, > > Anyone knows why the code below gives an error? > > global_vars = {} > local_vars = {'ar':["foo", "bar"], 'y':"bar"} > print eval('all((x == y for x in ar))', global_vars, local_vars) > > Error: > > Traceback (most recent call last): > ? File "C:\temp\work\test\src\a.py", line 3, in > ? ? print eval('all((x == y for x in ar))', global_vars, local_vars) > ? File "", line 1, in > ? File "", line 1, in > NameError: global name 'y' is not defined > > Note that if a list is used instead of a generator it works... > > Thanks, > > Fabio I tend to think of it as a generator produces another scope, gets refactored into something similar to: def yourfunc(ar): for x in ar: yield x == y Which doesn't work either, however, if you introduce a global y the function can access it (similar if you add y to your global_vars). It's basically one of those scope/closure gotcha's along with lambdas (which was discussed quite heavily recently). hth, Jon From joseph.a.marlin at gmail.com Tue Jan 27 19:13:51 2009 From: joseph.a.marlin at gmail.com (joseph.a.marlin at gmail.com) Date: Tue, 27 Jan 2009 16:13:51 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> Message-ID: <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> On Jan 27, 6:47?pm, Andr? wrote: > On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" > > wrote: > > Greetings! I've heard enough raving about Python, I'm going to see for > > myself what all the praise is for! > > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > > even use an IDE for Python? > > If you already use netbeans, what abouthttp://www.netbeans.org/features/python/ > ? > Wow, you guys are fast... yes, I was having trouble deciding between that (Netbeans), Smultron, or TextWrangler. Thanks! From excord80 at gmail.com Tue Jan 27 19:15:14 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 16:15:14 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Jan 27, 4:52?pm, Tim Chase wrote: > > I need to make a small, relatively low-traffic site that users can > > create accounts on and log into. Scripts must run as cgi (no > > mod_python or FastCGI is available). Can anyone recommend a small and > > simple web framework for Python, maybe similar to Perl's > > CGI::Application? > > > Or would it just be better to roll my own? > > What are you looking for in your framework? Well, let's see. I don't need a templating library, since -- as you pointed out -- I can just use Python's own. I don't need a db interface (can just make my own dbapi calls if needed). Don't need url mapping (can just use mod_rewrite rules in my .htaccess to point at my cgi scripts). Don't think I need any i80n. And I don't need an admin interface. ... It would seem that I don't need a whole lot at the moment. From robert.kern at gmail.com Tue Jan 27 19:17:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 27 Jan 2009 18:17:16 -0600 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: On 2009-01-27 17:56, Fabio Zadrozny wrote: > On Tue, Jan 27, 2009 at 9:51 PM, James Mills > wrote: >> On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny wrote: >>> Anyone knows why the code below gives an error? >>> >>> global_vars = {} >>> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >>> print eval('all((x == y for x in ar))', global_vars, local_vars) >> y is undefined in your generator expression. > > Yes... but why? It seems to me like it should be defined (if I put the > locals in the globals it finds it... seems very weird to me) I think you can work around your problem by using the same dictionary for both locals and globals. The locals/globals distinction is not useful in your circumstances. For example, the Python interpreter has these the same: >>> globals() is locals() True And that makes the code work: >>> y = 'bar' >>> ar = ['foo', 'bar'] >>> all((x==y) for x in ar) False >>> eval('all((x==y) for x in ar)') False Making locals and globals different emulates a function, where the code will fail: >>> del y, ar >>> def f(): ... y = 'bar' ... ar = ['foo', 'bar'] ... print 'Raw genexp:', all((x==y) for x in ar) ... print 'Evaled:', eval('all((x==y) for x in ar)') ... >>> f() Raw genexp: False Evaled: Traceback (most recent call last): File "", line 1, in File "", line 5, in f File "", line 1, in File "", line 1, in NameError: global name 'y' is not defined Now, the reason that the raw generator expression works inside the function but not in the eval() is because the raw generator expression gets lexical scopes rather than just the two locals and globals dicts. Lexical scoping is not available to the eval() function. -- 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 prologic at shortcircuit.net.au Tue Jan 27 19:28:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 10:28:49 +1000 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Wed, Jan 28, 2009 at 10:15 AM, excord80 wrote: > Well, let's see. I don't need a templating library, since -- as you > pointed out -- I can just use Python's own. I don't need a db > interface (can just make my own dbapi calls if needed). Don't need url > mapping (can just use mod_rewrite rules in my .htaccess to point at my > cgi scripts). Don't think I need any i80n. And I don't need an admin > interface. ... It would seem that I don't need a whole lot at the > moment. One option is to configure Apache with mod_wsgi and just use WSGI. Fairly simple really and much like CGI. cheers James From fabiofz at gmail.com Tue Jan 27 19:36:05 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 27 Jan 2009 22:36:05 -0200 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: > I think you can work around your problem by using the same dictionary for > both locals and globals. The locals/globals distinction is not useful in > your circumstances. For example, the Python interpreter has these the same: > > >>> globals() is locals() > True > Interesting... In my case, what I actually do (in the Pydev debugger) is that I find the frame where the code should be evaluated and then with the selected frame I do: frame = findframe(...) ... eval(expression, frame.f_globals, frame.f_locals) So, in that case, you think that instead of using frame.f_globals I should use: updated_globals = dict() updated_globals.update(frame.f_globals) updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals eval(expression, updated_globals, frame.f_locals) Is that it? -- I think that eval(expression, frame.f_locals, frame.f_locals) wouldn't work as expected in my actual case... (and I can't force the frame.f_globals and frame.f_locals to be the same) Thanks, Fabio From sjmachin at lexicon.net Tue Jan 27 19:41:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 16:41:16 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> Message-ID: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> On Jan 27, 6:17?pm, "Martin v. L?wis" wrote: > > Well, the first step would be to tell Python that there is a code page > > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > > doing "chcp 65001". I checked the list of aliases in Python 3 and there > > was no entry for cp65001. > > I see. What happens if you add it to encoding/aliases.py? A slight improvement. Get this: C:\junk\console>chcp 65001 Active code page: 65001 C:\junk\console>python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys; sys.stdout.encoding 'cp65001' >>> print u'\xff' Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: cp65001 >>> print u'\xff'.encode('utf8') Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied >>> Adding an entry to ...\lib\encodings\aliases.py as suggested did fix the Lookup error; it took it straight to the same IOError as above. Next step? From jstroud at mbi.ucla.edu Tue Jan 27 19:44:52 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 27 Jan 2009 16:44:52 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! Try open komodo. I haven't used it because vim is my IDE, but it looks pretty good. James From gslindstrom at gmail.com Tue Jan 27 19:49:26 2009 From: gslindstrom at gmail.com (gslindstrom) Date: Tue, 27 Jan 2009 18:49:26 -0600 Subject: Python and Nagios Message-ID: Hello all- We have started using Nagios at work to monitor our computer system and have been very happy with the results. We have decided to use it monitor our business processes as well, so I needed to write custom plug-ins and I opted to use Python because I am very comfortable with it. I found an excellent paper by Cameron Laird and Wojciech Kocjan showing the basics (thanks, guys!) and I have written plugins to verify the arrival and departure of files as well as the completion of business processes. We plan to use Nagios to report on file audits and reprocess jobs that have failed because a database or Internet connection burps. We have great plans for Nagios and I intend to submit a paper to next years PyCon showing what we have done. What I would like to know is if there is anything resembling a package to help with plugin deveopment with Python. I have a base class that provides most of the GNU plugin requirements (warning and critical threshold pattern processing, logging requirements, etc) and would like to work on creating something to release for general use, but I don't want to reinvent the wheel. Is there anything close to what I'm suggesting out there? I've looked in the standard places and have not located anything. I will continue to add to my local package and, if I don't hear about a similar effort, will look to create something for the Cheese Shop. If you are interested in helping out, please drop me a line via the list or at gslindstrom via gmail. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Tue Jan 27 19:53:40 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 16:53:40 -0800 (PST) Subject: Spam making a comeback?? Message-ID: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> Seems like the level of spam is increasing in the last week, and today has been bad. How are the spambytes coming along? From cosmo_general at yahoo.com Tue Jan 27 19:59:52 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Tue, 27 Jan 2009 16:59:52 -0800 (PST) Subject: How to execute a hyperlink? Message-ID: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Hi Folks, Module os provides a means of running shell commands, such as: import os os.system('dir .') will execute command dir I think a hyperlink should also be executed. I tried: os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') but I got kicked out by the Python interpreter. I wonder somebody knows the syntax of triggering a hyperlink? Thanks in advance! Muddy Coder From philip at semanchuk.com Tue Jan 27 20:04:49 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jan 2009 20:04:49 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <87FD47BC-A7A1-4211-8C90-27E1FBEB6BC2@semanchuk.com> On Jan 27, 2009, at 7:44 PM, James Stroud wrote: > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see >> for >> myself what all the praise is for! >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> Any recommendations on open source Python environments? >> Thanks! > > Try open komodo. I haven't used it because vim is my IDE, but it > looks pretty good. I second that; I had used it for a while but had forgotten about it. From joncle at googlemail.com Tue Jan 27 20:06:04 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 27 Jan 2009 17:06:04 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <34593f65-0c08-430f-951b-a0ca9967d675@r15g2000prd.googlegroups.com> On Jan 28, 12:59?am, Muddy Coder wrote: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! > > Muddy Coder The webbrowser module springs to mind. hth Jon. From burukena at gmail.com Tue Jan 27 20:07:48 2009 From: burukena at gmail.com (Burukena) Date: Tue, 27 Jan 2009 21:07:48 -0400 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <497FAFE4.4040602@gmail.com> On 1/27/09 8:44 PM, James Stroud wrote: > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see for >> myself what all the praise is for! >> >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> >> Any recommendations on open source Python environments? >> >> Thanks! > > Try open komodo. I haven't used it because vim is my IDE, but it looks > pretty good. > > James > -- > http://mail.python.org/mailman/listinfo/python-list > Vim and a terminal works for me, specifically with screen. Second choice would be TextMate but I have not used it in quite a while. From benjamin.kaplan at case.edu Tue Jan 27 20:11:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 20:11:35 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 7:41 PM, John Machin wrote: > On Jan 27, 6:17 pm, "Martin v. L?wis" wrote: > > > Well, the first step would be to tell Python that there is a code page > > > 65001. On Python 2.6, I get a LookupError for an unknown encoding after > > > doing "chcp 65001". I checked the list of aliases in Python 3 and there > > > was no entry for cp65001. > > > > I see. What happens if you add it to encoding/aliases.py? > > A slight improvement. Get this: > > C:\junk\console>chcp 65001 > Active code page: 65001 > > C:\junk\console>python > Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys; sys.stdout.encoding > 'cp65001' > >>> print u'\xff' > Traceback (most recent call last): > File "", line 1, in > LookupError: unknown encoding: cp65001 > >>> print u'\xff'.encode('utf8') > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied > >>> > > Adding an entry to ...\lib\encodings\aliases.py as suggested did fix > the Lookup error; it took it straight to the same IOError as above. > > Next step? Wait for Microsoft to catch up to everyone else? I tried this on Windows 7 beta. I didn't get an IOError, but the command prompt apparently doesn't understand the concept of a multi-byte character. u'\xff' showed as 2 unprintable characters. At least it's an improvement. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.lyon at preisshare.net Tue Jan 27 20:12:58 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Tue, 27 Jan 2009 20:12:58 -0500 Subject: New to python, open source Mac OS X =?UTF-8?Q?IDE=3F?= In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <80fbd490849f69f97ea4ceb5a65f6b09@preisshare.net> > joseph.a.marlin at gmail.com wrote: >> Greetings! I've heard enough raving about Python, I'm going to see for >> myself what all the praise is for! >> >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> even use an IDE for Python? >> >> Any recommendations on open source Python environments? Quite a good one is Boa Constructor, it is a reasonable IDE From excord80 at gmail.com Tue Jan 27 20:48:47 2009 From: excord80 at gmail.com (excord80) Date: Tue, 27 Jan 2009 17:48:47 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <4dadc5ea-21a1-4ebd-ba91-94189541559f@13g2000yql.googlegroups.com> On Jan 27, 7:28?pm, James Mills wrote: > > One option is to configure Apache with mod_wsgi and just > use WSGI. Fairly simple really and much like CGI. This is a shared hosting arrangement, so I don't have the option of adding an apache module. Also, if it's much like CGI, I don't see what benefit it would provide over CGI in this situation. From Graham.Dumpleton at gmail.com Tue Jan 27 20:52:35 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 27 Jan 2009 17:52:35 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: On Jan 28, 11:28?am, James Mills wrote: > On Wed, Jan 28, 2009 at 10:15 AM, excord80 wrote: > > Well, let's see. I don't need a templating library, since -- as you > > pointed out -- I can just use Python's own. I don't need a db > > interface (can just make my own dbapi calls if needed). Don't need url > > mapping (can just use mod_rewrite rules in my .htaccess to point at my > > cgi scripts). Don't think I need any i80n. And I don't need an admin > > interface. ... It would seem that I don't need a whole lot at the > > moment. > > One option is to configure Apache withmod_wsgiand just > use WSGI. Fairly simple really and much like CGI. Worth highlighting with mod_wsgi is that you also don't have to have everything inside of one WSGI application and can still use CGI like approach of lots of WSGI script files. That is, you are relying on Apache dispatching of URLs for file based resources and thus no Python specific dispatcher needed, nor mod_rewrite rules. Because each WSGI script files is given their own persistent sub interpreter by default, with this approach you probably though want to force them to all run in same sub interpreter to reduce memory usage. This can be done using WSGIApplicationGroup directive. For further information see: http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive Graham From sjmachin at lexicon.net Tue Jan 27 21:03:55 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jan 2009 18:03:55 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> Message-ID: <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> On Jan 28, 5:56?am, "Martin v. L?wis" wrote: > > #include "stdio.h" > > int main(int argc, char **argv) { > > ? ? printf("<\xc2\x80>\n"); > > ? ? } > > > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) > > and using "Lucida Console" font: > > > After CHCP 1252, this prints < A-circumflex Euro >, as expected. > > After CHCP 65001, it prints < hollow-square >. > > This is not surprising: this character is U+0080, which is a control > character. Try \xe2\x82\xac instead. Doh! I'm a nutter. That works. Thanks. The only font choice offered apart from "Raster Fonts" in the Command Prompt window's Properties box is "Lucida Console", not "Lucida Sans Unicode". It will let me print Cyrillic characters from a C program, but not Chinese. I'm off looking for how to get a better font. Cheers, John From gagsl-py2 at yahoo.com.ar Tue Jan 27 21:06:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 00:06:17 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern escribi?: > On 2009-01-27 17:56, Fabio Zadrozny wrote: > Making locals and globals different emulates a function, where the code > will fail: > > >>> del y, ar > >>> def f(): > ... y = 'bar' > ... ar = ['foo', 'bar'] > ... print 'Raw genexp:', all((x==y) for x in ar) > ... print 'Evaled:', eval('all((x==y) for x in ar)') > ... > >>> f() > Raw genexp: False > Evaled: > Traceback (most recent call last): > File "", line 1, in > File "", line 5, in f > File "", line 1, in > File "", line 1, in > NameError: global name 'y' is not defined > > Now, the reason that the raw generator expression works inside the > function but not in the eval() is because the raw generator expression > gets lexical scopes rather than just the two locals and globals dicts. > Lexical scoping is not available to the eval() function. I *thought* I did understand this until I came to this example: 1) >>> id(globals()), id(locals()) (11239760, 11239760) # ok, globals and locals are the same at the module level 2) >>> s = "(id(n) for n in [globals(),locals()])" >>> list(eval(s)) [11239760, 11239760] # still the same results 3) >>> s = "(id(n()) for n in [globals,locals])" >>> list(eval(s)) [11239760, 12583248] # locals() is different Why do I get a different locals() here? Both expressions define the same scopes, ok? That is, I'd say that both 2) and 3) define the same, nested scopes -- why the different results? Seems that this is unrelated to eval, we can take it out of the question and still get the same values: >>> list(id(n) for n in [globals(),locals()]) [11239760, 11239760] >>> list(id(n()) for n in [globals,locals]) [11239760, 12583248] Worse, it isn't the new, inner scope of generator expressions. A list comprehension gives the same results: >>> [id(n) for n in [globals(),locals()]] [11239760, 11239760] >>> [id(n()) for n in [globals,locals]] [11239760, 12583248] Seems that it is important *when* those functions are evaluated, but I don't understand *why*... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Jan 27 21:16:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 00:16:29 -0200 Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 00:03:55 -0200, John Machin escribi?: > On Jan 28, 5:56?am, "Martin v. L?wis" wrote: >> > #include "stdio.h" >> > int main(int argc, char **argv) { >> > ? ? printf("<\xc2\x80>\n"); >> > ? ? } >> >> > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) >> > and using "Lucida Console" font: >> >> > After CHCP 1252, this prints < A-circumflex Euro >, as expected. >> > After CHCP 65001, it prints < hollow-square >. >> >> This is not surprising: this character is U+0080, which is a control >> character. Try \xe2\x82\xac instead. > > Doh! I'm a nutter. That works. Thanks. The only font choice offered > apart from "Raster Fonts" in the Command Prompt window's Properties > box is "Lucida Console", not "Lucida Sans Unicode". It will let me > print Cyrillic characters from a C program, but not Chinese. I'm off > looking for how to get a better font. In this post, Raymond Chen explains all the conditions a font must met to actually be usable in a console window: http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx In short, most TrueType font's (even the fixed-width ones) aren't eligible. -- Gabriel Genellina From n.kottiyath at gmail.com Tue Jan 27 21:57:25 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 27 Jan 2009 18:57:25 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> Message-ID: <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> On Jan 27, 11:56?pm, Mike Driscoll wrote: > On Jan 27, 12:12?pm, Kottiyath wrote: > > > > > Hi, > > ? ?I would like to obtain pyAA for Python 2.5. I went through their > > web site, but they provide the windows exe only for Python2.4. I tried > > compiling from source, but that also was to no avail - it errs out as > > follows: > > > C:\Documents and Settings\Guest\pyAA>python setup.py install > > running install > > running build > > running build_py > > file pyAAc.py (for module pyAAc) not found > > file pyAAc.py (for module pyAAc) not found > > running build_ext > > error: Python was built with Visual Studio 2003; > > extensions must be built with a compiler than can generate compatible > > binaries. > > Visual Studio 2003 was not found on this system. If you have Cygwin > > installed, > > you can try compiling with MingW32, by passing "-c mingw32" to > > setup.py. > > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > > mingw32 > > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > > ? ?or: setup.py --help [cmd1 cmd2 ...] > > ? ?or: setup.py --help-commands > > ? ?or: setup.py cmd --help > > > error: invalid command 'mingw32' > > > Has anyone tried the same? Can anyone give any suggestions? > > You probably have to put mingw32 on your path or provide an absolute > path to it. By the way, where did you get the source? I couldn't find > it... > > Mike I have mingw32-gcc in my path. If I try that too -it fails. C:\Documents and Settings\Guest\pyAA>python setup.py install -c "mingw32-gcc" invalid command name 'mingw32-gcc' I got the source from http://sourceforge.net/cvs/?group_id=65529 Can somebody help me out? Our project needs pyAA, but I am unable to build on Python2.5. From benjamin.kaplan at case.edu Tue Jan 27 22:13:49 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 27 Jan 2009 22:13:49 -0500 Subject: unable to print Unicode characters in Python 3 In-Reply-To: References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: On Tue, Jan 27, 2009 at 9:16 PM, Gabriel Genellina wrote: > En Wed, 28 Jan 2009 00:03:55 -0200, John Machin > escribi?: > > On Jan 28, 5:56 am, "Martin v. L?wis" wrote: >> >>> > #include "stdio.h" >>> > int main(int argc, char **argv) { >>> > printf("<\xc2\x80>\n"); >>> > } >>> >>> > compiled with mingw32 (gcc (GCC) 3.4.5 (mingw-vista special r3)) >>> > and using "Lucida Console" font: >>> >>> > After CHCP 1252, this prints < A-circumflex Euro >, as expected. >>> > After CHCP 65001, it prints < hollow-square >. >>> >>> This is not surprising: this character is U+0080, which is a control >>> character. Try \xe2\x82\xac instead. >>> >> >> Doh! I'm a nutter. That works. Thanks. The only font choice offered >> apart from "Raster Fonts" in the Command Prompt window's Properties >> box is "Lucida Console", not "Lucida Sans Unicode". It will let me >> print Cyrillic characters from a C program, but not Chinese. I'm off >> looking for how to get a better font. >> > > In this post, Raymond Chen explains all the conditions a font must met to > actually be usable in a console window: > http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx > In short, most TrueType font's (even the fixed-width ones) aren't eligible. > Actually, you can trick the command prompt into allowing any TrueType font, if you don't mind messing with the registry. The font won't look so good, but it will still work. Even with a font that supports Unicode (GNU FreeMono), the console still displays 3 unprintable characters rather than the single multi-byte character. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Tue Jan 27 22:15:35 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Tue, 27 Jan 2009 19:15:35 -0800 Subject: Drawing and Displaying an Image with PIL Message-ID: Here's my program: # fun and games import Image, ImageDraw im = Image.open("wagon.tif") # it exists in the same Win XP # folder as the program draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line((0,0),(20,140), fill=128) # How show this final image on a display? root.mainloop() It has two problems. One is it crashes with: draw.line((0,0),(20,140), fill=128) TypeError: line() got multiple values for keyword argument 'fill' Secondly, it has no way to display the image drawn on. Is it possible, or do I have to pass the image off to another module's methods? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From barithegreat at gmail.com Tue Jan 27 22:23:34 2009 From: barithegreat at gmail.com (barithegreat at gmail.com) Date: Tue, 27 Jan 2009 19:23:34 -0800 (PST) Subject: Receiving data from USB Message-ID: Hi Can any body tell me how can i receive data from usb(usrp) in python. From rt8396 at gmail.com Tue Jan 27 22:30:44 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 19:30:44 -0800 (PST) Subject: Drawing and Displaying an Image with PIL References: Message-ID: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> On Jan 27, 9:15?pm, "W. eWatson" wrote: > Here's my program: > > # fun and games > import Image, ImageDraw > > im = Image.open("wagon.tif") # it exists in the same Win XP > # folder as the program > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line((0,0),(20,140), fill=128) > > # How show this final image on a display? > > root.mainloop() > > It has two problems. One is it crashes with: > ? ? ?draw.line((0,0),(20,140), fill=128) > TypeError: line() got multiple values for keyword argument 'fill' > > Secondly, it has no way to display the image drawn on. Is it possible, or do > I have to pass the image off to another module's methods? > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: I have not tried your code but i think you need to put your coodinates in one tuple. Here is an example from the docs Example Example: Draw a Grey Cross Over an Image import Image, ImageDraw im = Image.open("lena.pgm") draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line((0, im.size[1], im.size[0], 0), fill=128) del draw # write to stdout im.save(sys.stdout, "PNG") Hope that helps From steve at holdenweb.com Tue Jan 27 22:36:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 27 Jan 2009 22:36:57 -0500 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern > escribi?: >> On 2009-01-27 17:56, Fabio Zadrozny wrote: > >> Making locals and globals different emulates a function, where the >> code will fail: >> >> >>> del y, ar >> >>> def f(): >> ... y = 'bar' >> ... ar = ['foo', 'bar'] >> ... print 'Raw genexp:', all((x==y) for x in ar) >> ... print 'Evaled:', eval('all((x==y) for x in ar)') >> ... >> >>> f() >> Raw genexp: False >> Evaled: >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 5, in f >> File "", line 1, in >> File "", line 1, in >> NameError: global name 'y' is not defined >> >> Now, the reason that the raw generator expression works inside the >> function but not in the eval() is because the raw generator expression >> gets lexical scopes rather than just the two locals and globals dicts. >> Lexical scoping is not available to the eval() function. > > I *thought* I did understand this until I came to this example: > > 1) >>>> id(globals()), id(locals()) > (11239760, 11239760) > > # ok, globals and locals are the same at the module level > > 2) >>>> s = "(id(n) for n in [globals(),locals()])" >>>> list(eval(s)) > [11239760, 11239760] # still the same results > > 3) >>>> s = "(id(n()) for n in [globals,locals])" >>>> list(eval(s)) > [11239760, 12583248] # locals() is different > No, locals is different, not locals(). You are looking at two different functions that return the same object when called in the given context, that's all. > Why do I get a different locals() here? Both expressions define the same > scopes, ok? That is, I'd say that both 2) and 3) define the same, nested > scopes -- why the different results? > > Seems that this is unrelated to eval, we can take it out of the question > and still get the same values: > >>>> list(id(n) for n in [globals(),locals()]) > [11239760, 11239760] >>>> list(id(n()) for n in [globals,locals]) > [11239760, 12583248] > Same thing: two different functions, same result. > Worse, it isn't the new, inner scope of generator expressions. A list > comprehension gives the same results: > >>>> [id(n) for n in [globals(),locals()]] > [11239760, 11239760] >>>> [id(n()) for n in [globals,locals]] > [11239760, 12583248] > > Seems that it is important *when* those functions are evaluated, but I > don't understand *why*... > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From ben at benfinney.id.au Tue Jan 27 22:49:42 2009 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 28 Jan 2009 14:49:42 +1100 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) References: <1afaf6160901271222i2e2d9525i883367789219f96d@mail.gmail.com> <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> Message-ID: <87mydcxf6x.fsf@benfinney.id.au> (Continuing a side topic of a different discussion) Steve Holden writes: > I think that [Python 2.6 was a rushed release]. 2.6 showed it in the > inclusion (later recognizable as somewhat ill-advised so late in the > day) of multiprocessing [?] What was ill-advised about the addition of the ?multiprocessing? module to Python 2.6? I ask because I haven't yet used it in anger, and am not sure what problems have been found in it. -- \ ?Holy bouncing boiler-plated fits, Batman!? ?Robin | `\ | _o__) | Ben Finney From adi at digitaltrowel.com Tue Jan 27 23:23:19 2009 From: adi at digitaltrowel.com (Adi Eyal) Date: Wed, 28 Jan 2009 06:23:19 +0200 Subject: Python Application Server Message-ID: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Hi All Could anyone recommend a python application server? My application consists mainly of long running background processes that need to communicate with each other. Features on my wishlist include, process pooling (each process will in general be stateless), monitoring, scheduling and a framework for inter-process communication. Ideally, I would also like to be able to cluster the app server if the need arises. I have never used Zope or Webware, but my impression is that these servers are focused on web applications with a short request-response cycle. My usage will be different since my processes will be triggered by certain events and then continue running until they complete, without sending any response at all but possibly spawning off additional processes in a workflow. I hope my description has been clear. Does such an application server exist for python? Thanks in advance Adi From prologic at shortcircuit.net.au Tue Jan 27 23:36:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:36:51 +1000 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <87mydcxf6x.fsf@benfinney.id.au> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: > Steve Holden writes: >> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >> inclusion (later recognizable as somewhat ill-advised so late in the >> day) of multiprocessing [?] Steve: It's just a new package - it used to be available as a 3rd-party package. I dare say it most definitely was -not- ill-advised. It happens to be a great addition to the standard library. > What was ill-advised about the addition of the 'multiprocessing' > module to Python 2.6? I ask because I haven't yet used it in anger, > and am not sure what problems have been found in it. I have found no problems with it - I've recently integrated it with my event/component framework (1). In my library I use Process, Pipe and Value. cheers James 1. http://pypi.python.org/pypi/circuits/ From prologic at shortcircuit.net.au Tue Jan 27 23:42:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:42:16 +1000 Subject: Python Application Server In-Reply-To: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: On Wed, Jan 28, 2009 at 2:23 PM, Adi Eyal wrote: > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? Might I recommend circuits (1) as a general purpose framework that you can build your application on top of. circuits will allow you to communicate with long-running background processes, communicate between processes (by way of a Bridge). All communication in circuits is asyncroneous. circuits has also recently seen the integration of the multiprocessing package from python 2.6/3.0 so you can create processes and have inter-process communication seamlessly. In fact, parts of your system can even run on other nodes (you mentioned clustering). Feel free to talk to me more about this in detail... cheers James 1. http://pypi.python.org/pypi/circuits/ From notvalid2 at sbcglobal.net Tue Jan 27 23:43:56 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Tue, 27 Jan 2009 20:43:56 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> Message-ID: r wrote: > On Jan 27, 9:15 pm, "W. eWatson" wrote: >> Here's my program: >> >> # fun and games >> import Image, ImageDraw >> >> im = Image.open("wagon.tif") # it exists in the same Win XP >> # folder as the program >> draw = ImageDraw.Draw(im) >> draw.line((0, 0) + im.size, fill=128) >> draw.line((0,0),(20,140), fill=128) >> >> # How show this final image on a display? >> >> root.mainloop() >> >> It has two problems. One is it crashes with: >> draw.line((0,0),(20,140), fill=128) >> TypeError: line() got multiple values for keyword argument 'fill' >> >> Secondly, it has no way to display the image drawn on. Is it possible, or do >> I have to pass the image off to another module's methods? >> >> -- >> W. eWatson >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >> >> Web Page: > > I have not tried your code but i think you need to put your coodinates > in one tuple. Here is an example from the docs > > Example > Example: Draw a Grey Cross Over an Image > import Image, ImageDraw > im = Image.open("lena.pgm") > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line((0, im.size[1], im.size[0], 0), fill=128) > del draw > # write to stdout > im.save(sys.stdout, "PNG") > > Hope that helps That's pretty much the code I used. In fact, I borrowed it from the pdf. I just tried it, and it output "%PNG". I'd like to see this displayed in a window. If the fine had written properly, I could see whether it really drew the lines. It did not fail on the same draw stmts in my program. I see my problem, , instead of + between the tuples. I thought I'd seen another example where the 2-d tuples could be separated. I see a ImageFile module, but it's not for writing image files simply. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From prologic at shortcircuit.net.au Tue Jan 27 23:45:14 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 28 Jan 2009 14:45:14 +1000 Subject: Python Application Server In-Reply-To: References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: On Wed, Jan 28, 2009 at 2:42 PM, James Mills wrote: (...) > Might I recommend circuits (1) as a general purpose > framework that you can build your application on top of. > > circuits will allow you to communicate with long-running > background processes, communicate between processes > (by way of a Bridge). All communication in circuits is > asyncroneous. circuits has also recently seen the integration > of the multiprocessing package from python 2.6/3.0 so you > can create processes and have inter-process communication > seamlessly. In fact, parts of your system can even run on other > nodes (you mentioned clustering). I should probably mention some of the components available (features); * TCPServer, TCPClient * UDPServer, UDPClient * HTTP, IRC and SMTP protocols * Web Server (with limited WSGI support) (depends on parts of CherryPy) * Timers, Timer * Logger, Debugger * ... there are many more components ... :) Building new components is fairly easy as well. cheers James From pavlovevidence at gmail.com Tue Jan 27 23:59:29 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 27 Jan 2009 20:59:29 -0800 (PST) Subject: "The application has failed to start because the application configuration is incorrect" Message-ID: Perhaps someone who's familiar with Windows XP and Python can figure this one out, because it's baffling me. I installed the following packages on a more or less clean XP system: Python 2.6.1, straight from the MSI. WxPython 2.8.9.1, straight from the windows installer. Both installed with no errors. However, all attempts to run any wx code resulted in the following exception: "Import Error: DLL load failed: The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem." In fact, this seemed to be the case for any third-party extension module. I tried several other libraries for comparison (gtk, qt); they all had the same problem, and right out of the box. After a lot of reading I figured that I didn't have the right MSVSRT DLLs on my system, and that I should install the runtime redistributable packages from Microsoft. But I find it hard to believe the state of things in Windows is that you have to ask the user to install a package from Microsoft just to run an extension library. A package, I might add, that requires Adminstrative privileges. Which I don't have. Tkinter worked fine, BTW. My questions are 1. is that really what Windows extension users are expected to do, 2. if not, what else might be wrong, and 3. are there any workarounds? Carl Banks From wuwei23 at gmail.com Wed Jan 28 00:08:16 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 27 Jan 2009 21:08:16 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: On Jan 28, 10:59?am, Muddy Coder wrote: > Module os provides a means of running shell commands [...] > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') Well, clearly all you need to do is get your system to recognise URLs as shell commands and you're set... But if you'd like the *right* tool for the job, try webbrowser. From enleverlesX.XmcX at XmclaveauX.com Wed Jan 28 00:16:55 2009 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI (MVP)) Date: Wed, 28 Jan 2009 06:16:55 +0100 Subject: "The application has failed to start because the application configuration is incorrect" In-Reply-To: References: Message-ID: <497feb36$0$4094$ba4acef3@news.orange.fr> Hi! I have a similar problem, with Python 2.6.1 and pywin32. Since python 2.6.1. Return to 2.6: OK ; re-install 2.6.1: the problem return. No solution to this day. The problem is known, but not resolved In the expectation, I stay in 2.6 @-salutations -- Michel Claveau From michele.simionato at gmail.com Wed Jan 28 00:33:08 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 27 Jan 2009 21:33:08 -0800 (PST) Subject: Does Python really follow its philosophy of "Readability counts"? References: <34c95e04-5b3f-44bc-a5bf-498518507131@p36g2000prp.googlegroups.com> <2105e741-c5ea-4853-af1b-933676b44dc5@t3g2000yqa.googlegroups.com> <92bfb4a3-a325-4a5b-a175-c921ba2a5f5d@i20g2000prf.googlegroups.com> <496fa88d$0$1459$426a74cc@news.free.fr> <051e55c8-ddf6-4ab1-83bc-a9ce5f29c7cb@s9g2000prg.googlegroups.com> <497243fa$0$20693$426a74cc@news.free.fr> <0182b484$0$8693$c3e8da3@news.astraweb.com> <874oztihuj.fsf.mdw@metalzone.distorted.org.uk> <871vuose1u.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Jan 27, 9:13?pm, Mark Wooding wrote: > I'm referring to a number of features: > > ? * Redefinition of classes, yes. ?Interactive development is very > ? ? frustrating without this. ?Thanks for that link, by the way! > > ? * CHANGE-CLASS to change the class of instances. ?This is more than > ? ? just assigning to mumble.__class__, since it correctly initializes > ? ? the slots present in the new class which were absent in the old. > > ? * And all of the fancy MOP tricks you can play: inventing new slot > ? ? classes; messing with class-precedence-list orderings (Python's > ? ? MRO). > > It's a shorter list than I'd hoped! ?Still, these features kind of > multiply up. ?You can redefine a class using a new metaclass and slot > options, and all the instances are updated, for example. > > Anyway, I think I exaggerated when I said that CLOS was `much more > dynamic', but it is /somewhat/ more dynamic, and still amenable to > optimization; since my point was that dynamism in a language isn't > necessarily antithetical to compilation, that's still sufficient. > > Thanks for keeping me honest! Fair enough. My view is that even if apparently CLOS has some additional feature over the standard Python object model, in practice you can implement the same features in Python with some metaclass trick, *without the need to change the language at the C level*. This is why I think the Python object model is at least as dynamic as CLOS. In particular, a metaclass can implement the functionality CHANGE- CLASS, can mess with the __bases__ and with the MRO, etc. If you want to see an example of how much the Python object model can be perverted, you may be interested in this module of mine: http://pypi.python.org/pypi/strait The module changes the standard object system from a multiple inheritance one to a single inheritance one plus traits. Michele Simionato From rajorshi at in.com Wed Jan 28 00:37:31 2009 From: rajorshi at in.com (Rajorshi Biswas) Date: Wed, 28 Jan 2009 11:07:31 +0530 Subject: =?UTF-8?B?UmU6IENhbGxpbmcgUHl0aG9uLXRrIGNvZGUgZnJvbSBDL0MrKw==?= Message-ID: <1233121051.300ecf93b7224cf439b6de6ee1d6c200@mail.in.com> Thanks David. I found some help in this thread :http://mail.python.org/pipermail/cplusplussig/2006September/010814.htmlI am trying to adapt the same over for our requirements looks like we need new Python interpreters to handle the Tk UI loop. We will post back if we are able to make it work.Thanks,RajRaj http://www.rajorshi.net/blog Original message From:David Boddie< david at boddie.org.uk >Date: 28 Jan 09 04:28:18Subject:Re: Calling Pythontk code from C/C++To: pythonlist at python.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Jan 28 00:45:00 2009 From: rt8396 at gmail.com (r) Date: Tue, 27 Jan 2009 21:45:00 -0800 (PST) Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> Message-ID: <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> Change this line: draw.line((0,0),(20,140), fill=128) To This: draw.line((0,0, 20,140), fill=128) And you should be good to go. Like you said, if you need to combine 2 tuples you can do: (1,2)+(3,4) From steven at REMOVE.THIS.cybersource.com.au Wed Jan 28 00:46:46 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 28 Jan 2009 05:46:46 GMT Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote: > I'm not sure this is possible, but I would like to have a list of > objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that something > about the object 'a' has changed so that when I revisit A, I will know > that the other items in the list need to be refreshed to reflect the > changes in A as a result of changing 'a'. Can't be done if A is a built-in list, probably can't be done entirely generically, but you can probably do it in a cooperative manner. class TaintList(list): tainted = False def taint(self): self.tainted = True def untaint(self): self.tainted = False A = TaintList() import functools def taint(parent): def decorator(func): @functools.wraps(func) def f(*args, **kwargs): parent.taint() return func(*args, **kwargs) return f return decorator class TaintAwareThing(object): def __init__(self): self.attr = 0 @taint(A) def change_attribute(self, x): self.attr = x >>> x = TaintAwareThing() >>> y = TaintAwareThing() >>> z = TaintAwareThing() >>> >>> A.extend([x, y, z]) >>> A.tainted False >>> x.change_attribute(5) >>> A.tainted True Here is a second approach: create a proxy class TaintThing that wraps whatever object you want, using delegation: class TaintThing(object): parent = A def __init__(self, obj): self.__dict__['_proxy'] = obj def __getattr__(self, attr): return getattr(self._proxy, attr) def __setattr__(self, attr, value): setattr(self._proxy, attr, value) self.parent.taint() Now change TaintList to automatically wrap anything stored in it: # untested class TaintList(list): def append(self, obj): list.append(self, TaintThing(obj)) # similar for __setitem__, extend, insert -- Steven From pavlovevidence at gmail.com Wed Jan 28 01:11:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 27 Jan 2009 22:11:32 -0800 (PST) Subject: "The application has failed to start because the application configuration is incorrect" References: <497feb36$0$4094$ba4acef3@news.orange.fr> Message-ID: <6a8296a1-be68-4c9e-bfab-532770251660@p23g2000prp.googlegroups.com> On Jan 27, 9:16?pm, "M?ta-MCI \(MVP\)" wrote: > Hi! > > I have a similar problem, with Python 2.6.1 and pywin32. Since python > 2.6.1. > Return to 2.6: OK ; re-install 2.6.1: the problem return. > No solution to this day. > The problem is known, but not resolved > In the expectation, I stay in 2.6 Whoa--it did NOT occur to me that the bug was in Python. Sure enough, bug tracker has big thread about it, and a neat fix. http://bugs.python.org/issue4566 Thanks. Reverting to 2.6.0 should suffice for now. Carl Banks From berankin99 at yahoo.com Wed Jan 28 01:16:16 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Tue, 27 Jan 2009 22:16:16 -0800 (PST) Subject: Python Package Managment References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> Message-ID: <596392.54834.qm@web112214.mail.gq1.yahoo.com> [extracted from pylons-discuss] > >> I hate to pass the buck, but this is Python's fault for not having > >> reliable package management built in. There's nothing Pylons can do > >> about it except switch to another programming language. > > [SNIP] > > Without Setuptools, > Pylons and TurboGears couldn't exist, and Zope and Twisted > would not have been able to split themselves into several packages. > People coming to Python from Perl and Ruby expect to be able to just > run a command to download and install a package. That problem was > solved ten years ago, so why does Python still not have it standard? > > If Setuptools and Virtualenv or the equivalent were built into Python, > you could trust that every computer that has successfully installed > Python can install packages and make virtual environments the same > way.. > > That would eliminate 2/3 of the problems users have when > installing Pylons, and the subsequent need to explain the problems and > workarounds in the installation docs. At > work people say, "Half the trouble of Pylons is installing it", and I > often have to help them install it in person because otherwise they > get stuck at some error message and have no idea what to do. > Agreed. I would even move ipython (or something like it) to core. Of course, even Setuptools has a long way to go in some areas. (Installation Rollback, for one.) Python is about "batteries included", and these are major "batteries" in most modern environments. A CPAN like "in-house hosted" archive would nice, too. This way, modules have a better chance of outliving the original author's interest/commitment in paying for, possibly non-trivial, web hosting. I'm sure these issues has been discussed to death, but I wonder what the larger Python community thinks. From berankin99 at yahoo.com Wed Jan 28 02:02:58 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Tue, 27 Jan 2009 23:02:58 -0800 (PST) Subject: Best/better way? (histogram) Message-ID: <492364.58189.qm@web112206.mail.gq1.yahoo.com> Hello, I've got several versions of code to here to generate a histogram-esque structure from rows in a CSV file. The basic approach is to use a Dict as a bucket collection to count instances of data items. Other than the try/except(KeyError) idiom for dealing with new bucket names, which I don't like as it desribes the initial state of a KeyValue _after_ you've just described what to do with the existing value, I've come up with a few other methods. What seems like to most resonable approuch? Do you have any other ideas? Is the try/except(KeyError) idiom reallyteh best? In the code below you will see several 4-line groups of code. Each of set of the n-th line represents one solution to the problem. (Cases 1 & 2 do differ from cases 3 & 4 in the final outcome.) Thank you :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from collections import defaultdict from csv import DictReader from pprint import pprint dataFile = open("sampledata.csv") dataRows = DictReader(dataFile) catagoryStats = defaultdict(lambda : {'leaf' : '', 'count' : 0}) #catagoryStats = {} #catagoryStats = defaultdict(int) #catagoryStats = {} for row in dataRows: catagoryRaw = row['CATEGORIES'] catagoryLeaf = catagoryRaw.split('|').pop() ## csb => Catagory Stats Bucket ## multi-statement lines are used for ease of method switching. csb = catagoryStats[catagoryRaw]; csb['count'] += 1; csb['leaf'] = catagoryLeaf #csb = catagoryStats.setdefault(catagoryRaw, {'leaf' : '', 'count' : 0}); csb['count'] += 1; csb['leaf'] = catagoryLeaf #catagoryStats[catagoryRaw] += 1 #catagoryStats[catagoryRaw] = catagoryStats.get(catagoryRaw, 0) + 1 catagoryStatsSorted = catagoryStats.items() catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1) #catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1) pprint(catagoryStatsSorted, indent=4, width=60) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sampledata.csv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CATEGORIES,SKU "computers|laptops|accessories",12345 "computers|laptops|accessories",12345 "computers|laptops|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "computers|servers|accessories",12345 "toys|really|super_fun",12345 "toys|really|super_fun",12345 "toys|really|super_fun",12345 "toys|really|not_at_all_fun",12345 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ output: (in case #1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In [1]: %run catstat.py [ ( 'computers|servers|accessories', {'count': 5, 'leaf': 'accessories'}), ( 'toys|really|super_fun', {'count': 3, 'leaf': 'super_fun'}), ( 'computers|laptops|accessories', {'count': 3, 'leaf': 'accessories'}), ( 'toys|really|not_at_all_fun', {'count': 1, 'leaf': 'not_at_all_fun'})] From martin at v.loewis.de Wed Jan 28 02:32:53 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 08:32:53 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> Message-ID: <49800A25.2060702@v.loewis.de> > Next step? You need to use the Visual Studio debugger to find out where precisely the IOError comes from. Regards, Martin From AbelCodeMonk at gmail.com Wed Jan 28 02:37:25 2009 From: AbelCodeMonk at gmail.com (Arlo Belshee) Date: Tue, 27 Jan 2009 23:37:25 -0800 (PST) Subject: Start Python at client side from web app References: <6to3kfFbr0psU1@mid.individual.net> Message-ID: > We create a custom mime-type and register it on the client PC. The web application > can send signed python code to the client PC. If the signature is correct, > the code will be executed at the client. The signature prevents others from executing > code. This will let you start a program from within the browser. It will not let you run arbitrary Python inside the browser but it doesn't sound like that's your goal. If you goal is "user can go to site, click button, hit OK on confirmation box, and launch arbitrary Python code", then the mime type solution is probably the best bet. Just make your own custom extension which will launch the python interpreter on your file. Give it a mime type, and serve regular .py files with that extension and mime type. IE will start the interpreter in a new process and pass your file along. To verify the file's signature, you could simply create a custom interpreter by making a console app that takes a file, checks a sig, then runs the file against an embedded interpreter. Embedding the interpreter is simple enough. > I can code this myself, but prefer to use some open source project, if it exists. I don't know of any such. Heck, if you don't care about checking the signature on the file before running, your "project" could consist of a .reg file that sets up your extension/file type/mime type. Do an MSI if you want to get really fancy, but all you really need to do is add a couple entries to the registry. Of course, everything's a lot harder if you want to run within the browser. Having the browser ask the user for permission then launch a new process is easy. Building an integrated experience that hosts Python inside the browser sandbox is a lot harder - and probably not necessary. From mail at microcorp.co.za Wed Jan 28 02:47:00 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 28 Jan 2009 09:47:00 +0200 Subject: Exec woes References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> Message-ID: <015d01c9811c$c6042e80$0d00a8c0@hendrik> Stephen Hansen wrote: >Hendrik van Rooyen wrote: >>IDLE 1.1.3 ==== No Subprocess ==== >>>>> help(exec) >>SyntaxError: invalid syntax >>>>> >>Its the same under Linux SuSe, Python 2.5.1. >> >>I think this is a BUG. > >Exec is a statement, not a function nor an object: even though you can enclose parens around its arguments like you do later on, they >don't have any syntax meaning This is actually not correct - it is the root cause of my trouble. if you write, in a nested scope: exec ( "somestring to execute" in globals(),locals()) You get the syntax error, as the interpreter somehow sees it as one, unqualified thing. I did this, and it did not work in my real code, and that is why I started putting together the little example - all the trouble caused by too many parenthesis. But it is a GoodThing I made the error, because it has taught me more about how the scopes work. > >You can't help(print) or help(import) either. Right - was not aware of this - I suppose it has never occured to me to ask for help on print or import. >>Anyway, my real problem looks like this: >>>>> def Somefunc(): >> def excrescence(): >> exec('BUILD = "someString"') >> return BUILD >> >>SyntaxError: unqualified exec is not allowed in function 'excrescence >>it is a nested function (, line 3) >>>>> >> >>Now this works if it is not nested, and it works if it is a method in a class. >>Why the complaint about the nestedness? >> >> >Once upon a time, Python had only two scopes or namespaces: local and globals. It'd look up variables in the local scope and if it didn't >find them, it'd look them up in the global scope. (There's also the builtin namespace but to not digress...) 8<----------------------- historic position ---------------- > >Then PEP227 came around to add nested scopes -- or lexical scopes. Its what made "nested" functions like that actually useful: it's what >brought closures into the scenario. As of Python 2.2, within bar() it would be able to see the definition of a because namespaces can >now be nested. > >This addition was a problem for a couple features: doing "from blah import *" within a function, and a bare exec (an exec without an >explicit globals() and locals()) that happened in certain places-- in this case a nested function. They introduced that SyntaxError to make >sure it wouldn't accidentally hit you. Read up on PEP227 for the full details. > Thanks - will do, but I think I am already getting the picture. >To get around this, you need to specify exactly what scope you want exec to happen in when you're in a place where the 'current' scope >is nested. You qualify exec-- > Right - and it also works if you simply use the current locals() in the global position. I suppose one should use the scope "one up" in globals, and locals() as locals, but I can't figure out how to do that directly. (I mean using Somefunc'c locals() as the global for the exec, and excrescence's locals() as the locals - would require keeping a reference - see below) > >>So there is some namespace thing happening that is too subtle for me, and I >>would like to know what "unqualified" means in the above message, and >>what one must do to "qualify" the statement, if that is what is needed. >> > >by doing: > > exec code in , > >In your situation: > > >>> def Somefunc(): > def excrescence(): > exec "BUILD = 'someString'" in globals(), locals() > >is probably sufficient. globals() returns the dictionary of the global namespace, locals() the dictionary of the current functions (non->nested) namespace. > This works, thank you. However, locals() give you the nested function's namespace. The following illustrates what is going on: >>> def Somefunc(): print 'in Somefunc:',locals,id(locals),id(locals()) def excrescence(): print 'in excrescence:',locals,id(locals),id(locals()) exec "BUILD = 'someString'" in locals() print 'in excrescence:',locals,id(locals),id(locals()) return BUILD foo = excrescence() print 'in Somefunc:',locals,id(locals),id(locals()) return foo >>> Somefunc() in Somefunc: 7599848 18705696 in excrescence: 7599848 18799040 in excrescence: 7599848 18799040 in Somefunc: 7599848 18705696 'someString' >>> This leads me to speculate into other evil ways - if I use the outer locals, I need not even return the thing, it would get defined: >>> def Somefunc(): print 'in Somefunc:',locals,id(locals),id(locals()) outer_locals = locals() def excrescence(): print 'in excrescence:',locals,id(locals),id(locals()) exec "BUILD = 'someString'" in outer_locals print 'in excrescence:',locals,id(locals),id(locals()) return None foo = excrescence() print 'in Somefunc:',locals,id(locals),id(locals()) return BUILD >>> Somefunc() in Somefunc: 7599848 18822032 in excrescence: 7599848 18619824 in excrescence: 7599848 18619824 in Somefunc: 7599848 18822032 'someString' >>> And so it does. Using the locals like this in the globals position is not a good idea, except for purposes of illustration, like here - if one actually prints the contents of the dict after the exec, you see what is meant by namespace pollution.... Thank you to all who have responded - I think I have it now - Hendrik From v+python at g.nevcal.com Wed Jan 28 02:52:59 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Tue, 27 Jan 2009 23:52:59 -0800 Subject: errno 22 instead of errno 2 Message-ID: <49800EDB.3080800@g.nevcal.com> open("c:\abc","rb") This simple one-line script, produces errno 22 on Python 2.6, but errno 2 on Python 2.5.2 Is this an unintentional regression? Or is this an intentional bug fix? The file doesn't exist (errno 2) but I guess on Windows it is also somewhat an invalid file name (errno 22). Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file name produces errno 2 on both versions. -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From sjmachin at lexicon.net Wed Jan 28 03:35:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 19:35:03 +1100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <49800A25.2060702@v.loewis.de> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> <49800A25.2060702@v.loewis.de> Message-ID: <498018B7.1070803@lexicon.net> On 28/01/2009 6:32 PM, Martin v. L?wis wrote: >> Next step? > > You need to use the Visual Studio debugger to find out where > precisely the IOError comes from. Big step. I don't have Visual Studio and have never used it before. Which version of VS do I need to debug which released version of Python 2.X and where do I get that VS from? Or do I need to build Python from source to be able to debug it? From ferdinandsousa at gmail.com Wed Jan 28 03:40:13 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Wed, 28 Jan 2009 14:10:13 +0530 Subject: Python-list Digest, Vol 64, Issue 617 In-Reply-To: References: Message-ID: > > Secondly, it has no way to display the image drawn on. Is it possible, or >>> do >>> I have to pass the image off to another module's methods? >> >> im.show() this will display the image (and any modification(s) made to it) > >> Example: Draw a Grey Cross Over an Image >> import Image, ImageDraw >> im = Image.open("lena.pgm") >> draw = ImageDraw.Draw(im) >> draw.line((0, 0) + im.size, fill=128) >> draw.line((0, im.size[1], im.size[0], 0), fill=128) >> del draw >> # write to stdout >> im.save(sys.stdout, "PNG") >> >> Hope that helps >> > That's pretty much the code I used. In fact, I borrowed it from the pdf. I > just tried it, and it output "%PNG". > > im.save("picture1.png") OR im.save("picture1" "png") # not sure if it has to be "PNG" What was happening earlier was that the binary data was being directed to the standard output, which is where all your text is printed by a print statement (print func in Py 3000). If you open a png in notepad, you will notice that the 1st four characters are indeed %PNG, which is the magic number for a PNG file. For further info, see: http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files http://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header Regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jan 28 03:41:14 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 28 Jan 2009 09:41:14 +0100 Subject: Receiving data from USB In-Reply-To: References: Message-ID: <6uak1bFe83phU1@mid.uni-berlin.de> barithegreat at gmail.com schrieb: > Hi > Can any body tell me how can i receive data from usb(usrp) in python. http://letmegooglethatforyou.com/?q=python+usb Diez From __peter__ at web.de Wed Jan 28 03:52:49 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 09:52:49 +0100 Subject: Best/better way? (histogram) References: Message-ID: Bernard Rankin wrote: > I've got several versions of code to here to generate a histogram-esque > structure from rows in a CSV file. > > The basic approach is to use a Dict as a bucket collection to count > instances of data items. > > Other than the try/except(KeyError) idiom for dealing with new bucket > names, which I don't like as it desribes the initial state of a KeyValue > _after_ you've just described what to do with the existing value, I've > come up with a few other methods. > > What seems like to most resonable approuch? The simplest. That would be #3, cleaned up a bit: from collections import defaultdict from csv import DictReader from pprint import pprint from operator import itemgetter def rows(filename): infile = open(filename, "rb") for row in DictReader(infile): yield row["CATEGORIES"] def stats(values): histo = defaultdict(int) for v in values: histo[v] += 1 return sorted(histo.iteritems(), key=itemgetter(1), reverse=True) Should you need the inner dict (which doesn't seem to offer any additional information) you can always add another step: def format(items): result = [] for raw, count in items: leaf = raw.rpartition("|")[2] result.append((raw, dict(count=count, leaf=leaf))) return result pprint(format(stats(rows("sampledata.csv"))), indent=4, width=60) By the way, if you had broken the problem in steps like above you could have offered four different stats() functions which would would have been a bit easier to read... Peter From juvy.jumalon at gmail.com Wed Jan 28 03:58:02 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Wed, 28 Jan 2009 16:58:02 +0800 Subject: need help Message-ID: Hi guys, need help on how to read file from other server(linux). thanks a lot. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Jan 28 04:04:30 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 28 Jan 2009 09:04:30 +0000 Subject: errno 22 instead of errno 2 In-Reply-To: <49800EDB.3080800@g.nevcal.com> References: <49800EDB.3080800@g.nevcal.com> Message-ID: <49801F9E.1050700@timgolden.me.uk> Glenn Linderman wrote: > open("c:\abc","rb") > > This simple one-line script, produces errno 22 on Python 2.6, but errno > 2 on Python 2.5.2 > > Is this an unintentional regression? Or is this an intentional bug fix? > > The file doesn't exist (errno 2) but I guess on Windows it is also > somewhat an invalid file name (errno 22). > > Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file > name produces errno 2 on both versions. > Just glancing quickly at the svn logs, there certainly were some changes around that area in 2008: http://svn.python.org/view/python/trunk/Objects/fileobject.c?view=log Have a look at r61468, for example. Don't know if that's caused what you're seeing but it might well be. (Don't have time just at the mo to check out the revision and rebuild). http://svn.python.org/view/python/trunk/Objects/fileobject.c?rev=61468&r1=60984&r2=61468 I'd question whether it's strictly a "regression", unintentional or otherwise, since I doubt the code makes any particular commitment as to which error code is raised, but I'd certainly be looking askance if I had code which relied on a particular error number which then changed! Still, that's what unit tests are for, I suppose. TJG From castironpi at gmail.com Wed Jan 28 04:24:54 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 01:24:54 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 3:16?pm, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. What you could do is specialize '__getitem__' (or '__getslice__') so that whenever one of its items is accessed, the item is marked as dirty or the entire list is refreshed. (Unproduced.) def taintlist(list): def __getitem__( self, key ): x= super(taintlist, self).__getitem__( self, key ) self._dirty= True self.refresh() #too early, unfortunately return x ... However, what you are probably after is something like this (unproduced): def taintlist(list): def __getitem__( self, key ): x= super(taintlist, self).__getitem__( self, key ) y= delegate( self, key, x ) return y The 'delegate' class, also unproduced, automatically delegates function calls (including member lookups) to the target. After the delegated call returns, the list is notified-- hence the three arguments to its constructor. (Unproduced.) class delegate: def __getattr__( self, key ): attr= super( delegate, self ).__getattr__( self, key ) deleg= delegate( self.owner, self.ownerkey, attr ) return deleg def __call__( self, *ar, **kw ): res= self.attr( *ar, **kw ) self.owner.markdirty( ) return res I'm not convinced it's possible, but there's a possibility... or something like it. When you call a[0].meth(), three things happen: x= '0' looked up on 'a' y= 'meth' looked up on 'x' z= 'y' called You want control over the last of these parts, so you can call a custom function instead. It becomes increasingly risky as the depth increases, such as if the target class implements custom access, I guess. In the 'delegate' shown, for example, it assumes that the result is callable. You might need: class delegate: def __getattr__( self, key ): attr= super( delegate, self ).__getattr__( self, key ) if not iscallable( attr ): return attr ... #return delegate Further, if the result is callable, that doesn't mean it will necessarily be called. You should be able to tolerate this sequence: x= '0' looked up on 'a' y= 'meth' looked up on 'x' z= attribute looked up on 'y' (instead of 'y' called) Mind if we inquire after your progress? From phillip.oldham at gmail.com Wed Jan 28 04:35:55 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Wed, 28 Jan 2009 01:35:55 -0800 (PST) Subject: ORM recommendation when using "live"/predefined DB? Message-ID: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> We're trying to move to Python for a few parts of our application. We have a live database, which has been modeled for a specific use, and has other code connecting to and working with it. We'd like to reduce the amount of work we have to do in terms of keeping our python code up-to-date with schema changes, and we don't want python objects to dictate how the database should be structured. Can you recommend an ORM (or similar) package to look into? From mail at johnohagan.com Wed Jan 28 04:37:44 2009 From: mail at johnohagan.com (John O'Hagan) Date: Wed, 28 Jan 2009 09:37:44 +0000 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <200901280937.45277.mail@johnohagan.com> On Tue, 27 Jan 2009, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of objects > > A=[a,b,c,d,...,z] > > where, in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. [...] Interesting question. Maybe this is too simple for your purpose (or maybe just wrong!), but could you subclass list and give it an "update" method which keeps a dictionary of the state of its members and/or calls another method that makes the appropriate changes in the other members when a change occurs, something like: class SelfAwareList(list): state_dict = {} def update(self): for i in self: if i.state == 'some_condition': self.do_stuff_to_other_members() self.state_dict[i] = i.state def do_stuff_to_other_members(self): print 'doing stuff...' ? You could manually call update() on the SelfAwareList instance after calling a method on a SelfAwareList member, or even build it into the members' methods so that it was automatic. HTH, John From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:46:37 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:46:37 +0100 Subject: How many followers of comp.lang.python In-Reply-To: References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <8692c77c-0498-4c68-940f-e4d4427f3f08@x37g2000yqj.googlegroups.com> <497f35aa$0$6733$426a74cc@news.free.fr> Message-ID: <49802976$0$14303$426a74cc@news.free.fr> Grant Edwards a ?crit : > On 2009-01-27, Bruno Desthuilliers wrote: > >> Please visit comp.databases or comp.lang.javascript for really >> unfriendly and unhelpful places where few happens except >> "bickering and name-calling". > > I've always found comp.lang.c to be a rather dangerous place as > well. Really ? I remember having learned quite a lot there too - but it was several years ago, and things may have changed. From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:50:39 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:50:39 +0100 Subject: How many followers of comp.lang.python In-Reply-To: <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> Message-ID: <49802a69$0$3270$426a34cc@news.free.fr> rantingrick a ?crit : > On Jan 27, 10:12 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> All you can say is that he didn't *post* here (at least under his real >> identity...) for the 9 past years - this doesn't mean he never *reads* >> (and this, you just have no way to know). > > Ah, this is a good point. You have to wonder, Guido could be one of > the regulars here. if you mean "one of the regular posters", I have serious doubts about it. It was mostly a theoretical refutation of your conclusions. The important point is that you just *can not* tell if he's *reading* this ng or not... > very interesting. We should have a vote as to who > would be the most likely candidate, now that would be a good thread :) Waste of time as far as I'm concerned. From rschroev_nospam_ml at fastmail.fm Wed Jan 28 04:51:00 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 28 Jan 2009 10:51:00 +0100 Subject: How to execute a hyperlink? In-Reply-To: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <8UVfl.45$n_6.33@newsfe22.ams2> Muddy Coder schreef: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! As others have said, you can use the webbrowser module for hyperlinks. Alternatively you can use os.startfile() which works hyperlinks and many types of files, but only works on Windows (it does the same as double-clicking in Windows Explorer). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From thorsten at thorstenkampe.de Wed Jan 28 04:53:08 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 28 Jan 2009 10:53:08 +0100 Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: * John Machin (Tue, 27 Jan 2009 18:03:55 -0800 (PST)) > On Jan 28, 5:56?am, "Martin v. L?wis" wrote: > The only font choice offered apart from "Raster Fonts" in the Command > Prompt window's Properties box is "Lucida Console", not "Lucida Sans > Unicode". It will let me print Cyrillic characters from a C program, > but not Chinese. I'm off looking for how to get a better font. I have [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont] "00"="DejaVu Sans Mono" Note that you have to /reboot/ (no, I'm not kidding) to make this work. Thorsten From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 04:57:32 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 10:57:32 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <49802c05$0$5139$426a34cc@news.free.fr> excord80 a ?crit : > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? What about: http://thraxil.org/code/cgi_app/ (yes, it is a port of CGI::Application, and FWIW it's mentionned on the CGI::Application's wiki). HTH From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 05:00:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 11:00:58 +0100 Subject: Python Application Server In-Reply-To: References: Message-ID: <49802cd3$0$5139$426a34cc@news.free.fr> Adi Eyal a ?crit : > Hi All > > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? > Not sure if it would fit your needs, but you may want to have a look at Twisted ? From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 05:02:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 11:02:28 +0100 Subject: ORM recommendation when using "live"/predefined DB? In-Reply-To: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> References: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> Message-ID: <49802d2d$0$5139$426a34cc@news.free.fr> Phillip B Oldham a ?crit : > We're trying to move to Python for a few parts of our application. We > have a live database, which has been modeled for a specific use, and > has other code connecting to and working with it. > > We'd like to reduce the amount of work we have to do in terms of > keeping our python code up-to-date with schema changes, and we don't > want python objects to dictate how the database should be structured. > > Can you recommend an ORM (or similar) package to look into? AFAICT, SQLAlchemy is the most "tolerant" (and advanced) Python SQL abstraction / ORM package. From koranthala at gmail.com Wed Jan 28 05:02:57 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 02:02:57 -0800 (PST) Subject: A Twisted Design Decision References: <6d674190-4692-42e0-91ba-0ca5ca4dd0d3@n33g2000pri.googlegroups.com> Message-ID: <488249aa-6139-4d0c-8151-1188a1a814ad@u18g2000pro.googlegroups.com> On Jan 27, 9:27?pm, koranthala wrote: > On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > > > > > On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala wrote: > > >Twisted, being twisted in its behavior is causing quite a lot of > > >confusion in design decisions. > > > I'm not sure I agree with your premise. ;) > > > >I will put forward a comparison of reactor and non-reactor patterns. > > >The code is not exact - whatever is shown is the gist of it. > > > >For example, a message handler - in a usual scenario: > > >class messageHandler: > > > ? def run(): > > > ? ? ? ? msg = self.get_next_msg() > > > ? ? ? ? if not msg.send(): > > > ? ? ? ? ? ? self.handle_failure() > > > >To handle parallel execution, we will have to use threads, but the > > >code flow is similar. > > > >How do we do the same in a reactor pattern (Twisted)? > > >msg.send will cause a deferred to be raised - the failure, if it > > >happens will happen much later. > > >i.e. other than sending messageHandler object in msg.send(), I cannot > > >see any mechanism of running handle_failure. > > > >In Twisted: > > >class messageHandler: > > > ? def run(): > > > ? ? ? ? msg = self.get_next_msg() > > > ? ? ? ? msg.send(self): > > > >class msgClass: > > > ? ?def send(o): > > > ? ? ? ?d = deferred.addCallBack(success_handler, o).addErrBack > > >(failure_handler, o) > > > > ? ?def failure_handler(o): > > > ? ? ? ?o.handle_failure() > > > This doesn't look like a correct or faithful translation of the original. > > Here are two possibilities. ?First: > > > ? ? class messageHandler: > > ? ? ? ? def run(): > > ? ? ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? ? ? d = msg.send() > > ? ? ? ? ? ? def cbSendFailed(result): > > ? ? ? ? ? ? ? ? if not result: > > ? ? ? ? ? ? ? ? ? ? self.handle_failure() > > ? ? ? ? ? ? d.addErrback(cbSendFailed) > > ? ? ? ? ? ? return d > > > Next: > > > ? ? class messageHandler: > > ? ? ? ? @inlineCallbacks > > ? ? ? ? def run(): > > ? ? ? ? ? ? msg = self.get_next_msg() > > ? ? ? ? ? ? if not (yield msg.send()): > > ? ? ? ? ? ? ? ? self.handle_failure() > > > These are both just straight translations from your version so as to > > be able to handle a Deferred from `msg.send?. > > > >Basically, what I find is that a lot of functional encapsulation is > > >now lost by following reactor pattern. handle_failure is > > >messageHandlers code and makes for pretty viewing if called from > > >inside messageHandler itself. But, due to the twisted nature of > > >reactor pattern, the msg Class - who is functionally a lower class to > > >messageHandler invoking messageHandler's code. > > > You don't need to lose anything. ?I don't know what your motivation was > > for re-arranging the code when you wrote the Twisted version, but it doesn't > > appear to have been necessary. > > > >Is there a way to solve this in a more beautiful way? Am I missing > > >something here? > > > Hope this helps, > > > Jean-Paul > > Thank you Jean-Paul. > My code is more complex than what I have mentioned. When I mentioned > msg.send, the msg object actually gets the data from DB etc to send. > And there are many other items being done. > I will try to see whether I can change the code to incorporate what > you mentioned. > > I rewrote most of my code after learning just raw deferreds - I had > planned to study inlineCallbacks - but then it slipped my mind ?- now > it has come to bit me. :-( Hi, I tried to update the code as per the suggestion, but to no avail. My system uses Python2.4.3 (cannot move to 2.5) - so I tried to rewrite with deferredGenerators - since I thought inlineCallbacks are similar to deferredGenerators. But I cannot seem to rewrite it in a format where the functional encapsulation is not broken. i.e. as I mentioned in the first example - I have to pass SELF to child objects for them to modify it. The code was not exactly as I mentioned. I will try to explain more below: The code before Twisted was incorporated. class MessageHandler: def send_message(): if self.execute(): #Lots of checks going inside this for i in self.msgs: #Sends many messages at the same time if msg.send(): self.success += 1 else self.failure += 1 class Message: def send(): self.update_data() #The data to be sent is updated here return self.protocol.send() #Any protocol - for this example HTTP is used class Protocol: def send(): HTTP get page if page received: parse page and see parameters if parameters: return True return False The code I rewrote after Twisted was incorporated: class MessageHandler: def send_message(): if self.execute(): #Lots of checks going inside this for i in self.msgs: #Sends many messages at the same time msg.send(self): #Has to send myself to the childclass class Message: def send(h): self.h = h #The message handler object self.update_data() #The data to be sent is updated here return self.protocol.send(self) #Again, sending myself to child class def update(status): if status: self.h.success += 1 else: self.h.failure += 1 class Protocol: @deferredGenerator def send(msg): d = waitForDeferred(getPage(url, method, data)) yield d if page received: parse page and see parameters if parameters: msg.update(True) msg.update(False) As I mentioned, I am unable to rewrite it in reactor pattern without breaking functional encapsulation. I tried re-writing it as Jean-Paul mentioned - trying to push the deferred to msg.send etc, but then functional encapsulation of Protocol was broken. Am I being a blockhead here or is it possible to rewrite it in a proper mechanism? From asmodai at in-nomine.org Wed Jan 28 05:05:01 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Wed, 28 Jan 2009 11:05:01 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <20090128100501.GQ99614@nexus.in-nomine.org> -On [20090127 22:21], excord80 (excord80 at gmail.com) wrote: >I need to make a small, relatively low-traffic site that users can >create accounts on and log into. Scripts must run as cgi (no >mod_python or FastCGI is available). Can anyone recommend a small and >simple web framework for Python, maybe similar to Perl's >CGI::Application? Werkzeug[1] should be in your line, I think. [1] http://werkzeug.pocoo.org/ -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From thorsten at thorstenkampe.de Wed Jan 28 05:05:39 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 28 Jan 2009 11:05:39 +0100 Subject: optparse question References: <93b7b3f9-0159-4c48-aaed-d34e98e0ecd4@r37g2000prr.googlegroups.com> Message-ID: * Pat (Tue, 27 Jan 2009 14:04:28 -0500) > >> I had no idea people were going to get so upset that I used a > >> Windows example and go off on a tear. > > > > Nobody is upset, and nobody has "gone off on a tear". The point > > about the "Windows example" is that the docs say in a > > close-to-screamingly- obvious manner that /options are not > > supported, no matter what religion uses them. It was not, and still > > is not, apparent what you really wanted. We're all patiently waiting > > for you to rephrase the question(s). > > Sigh. I used an incorrect example (I sincerely apologize to the world > for that egregious error on my part). > > I''m totally cognizant that the documentation states '-'' or '--' need > to be used for flags. > > The question was it possible to add a simple flag like 'd-' to optparse > with no other parameters? I'm guessing from the vitriolic diatribes > here that the answer is no. > [...] > If you don't want to answer the question or don't have any meaningful > to add, please don't pollute the forum with further vacuous responses. > I didn't ask, or expect, you to write the code for me. > > christ on a stick, so many of you behave like prima donnas. You have a problem. The problem is not a Python or a technical one. It's described here -> http://en.wikipedia.org/wiki/Attention_Deficit_Syndrome Thorsten From cournape at gmail.com Wed Jan 28 05:53:42 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 28 Jan 2009 19:53:42 +0900 Subject: Python Package Managment In-Reply-To: <596392.54834.qm@web112214.mail.gq1.yahoo.com> References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> Message-ID: <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin wrote: > [extracted from pylons-discuss] > > >> >> I hate to pass the buck, but this is Python's fault for not having >> >> reliable package management built in. There's nothing Pylons can do >> >> about it except switch to another programming language. >> > [SNIP] >> >> Without Setuptools, >> Pylons and TurboGears couldn't exist, and Zope and Twisted >> would not have been able to split themselves into several packages. >> People coming to Python from Perl and Ruby expect to be able to just >> run a command to download and install a package. That problem was >> solved ten years ago, so why does Python still not have it standard? >> >> If Setuptools and Virtualenv or the equivalent were built into Python, >> you could trust that every computer that has successfully installed >> Python can install packages and make virtual environments the same >> way.. >> >> That would eliminate 2/3 of the problems users have when >> installing Pylons, and the subsequent need to explain the problems and >> workarounds in the installation docs. At >> work people say, "Half the trouble of Pylons is installing it", and I >> often have to help them install it in person because otherwise they >> get stuck at some error message and have no idea what to do. >> > > Agreed. I would even move ipython (or something like it) to core. > > Of course, even Setuptools has a long way to go in some areas. (Installation Rollback, for one.) > > Python is about "batteries included", and these are major "batteries" in most modern environments. > > A CPAN like "in-house hosted" archive would nice, too. This way, modules have a better chance of outliving the original author's interest/commitment in paying for, possibly non-trivial, web hosting. > > I'm sure these issues has been discussed to death, but I wonder what the larger Python community thinks. You may be interested in the following: http://mail.python.org/pipermail/python-dev/2006-April/063952.html The thread is two years and a half old, but my impression is that the situation has not changeed much since. Few if any people are against improving the situation, but more people are against the currently available solutions (setuptools, virtualenv, etc...). cheers, David From bblais at bryant.edu Wed Jan 28 05:58:06 2009 From: bblais at bryant.edu (Brian Blais) Date: Wed, 28 Jan 2009 05:58:06 -0500 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <83C7BA1C-9AE3-4C1A-869F-C6B141044FA1@bryant.edu> On Jan 27, 2009, at 16:19 , excord80 wrote: > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? I'd strongly suggest webpy (http://webpy.org/). It is easy, works with CGI, FastCGI, etc... or you can run its own built-in server. It's very nice! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Jan 28 06:06:04 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 28 Jan 2009 22:06:04 +1100 Subject: errno 22 instead of errno 2 In-Reply-To: <49800EDB.3080800@g.nevcal.com> References: <49800EDB.3080800@g.nevcal.com> Message-ID: <49803C1C.20608@gmail.com> On 28/01/2009 6:52 PM, Glenn Linderman wrote: > open("c:\abc","rb") > > This simple one-line script, produces errno 22 on Python 2.6, but errno > 2 on Python 2.5.2 > > Is this an unintentional regression? Or is this an intentional bug fix? > > The file doesn't exist (errno 2) but I guess on Windows it is also > somewhat an invalid file name (errno 22). > > Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file > name produces errno 2 on both versions. > I think you will find that in Python 2.6, the exception object has both 'errno' and 'winerror' attributes, which more accurately reflect the source of the 2 different error numbers, where Python 2.5 would often store the windows error number in the errno field, leading to what you see. I tend to use something like "winerror = getattr(e, 'winerror', e.errno)" to handle both cases... Cheers, Mark From marco at sferacarta.com Wed Jan 28 06:31:47 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 28 Jan 2009 12:31:47 +0100 Subject: ORM recommendation when using "live"/predefined DB? In-Reply-To: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> References: <8959a9fc-b316-4b88-b1eb-10b9738921c1@w1g2000prk.googlegroups.com> Message-ID: Phillip B Oldham wrote: > Can you recommend an ORM (or similar) package to look into? SQLAlchemy with reflected tables. You can use straight SQL, generate it dynamically via python expressions, go with the ORM, or everything together (in a bucket :) It really pays due respect to the RDBMS, and does not try to avoid the OO-SQL gap. From notvalid2 at sbcglobal.net Wed Jan 28 06:45:50 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 03:45:50 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> Message-ID: <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> r wrote: > Change this line: > draw.line((0,0),(20,140), fill=128) > > To This: > draw.line((0,0, 20,140), fill=128) > > And you should be good to go. Like you said, if you need to combine 2 > tuples you can do: > (1,2)+(3,4) Yes, that's true, but the big question is how to "see" the final image? Either one employees another module or writes the file into a folder, then displays it with a paint program? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From claird at lairds.us Wed Jan 28 07:07:46 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 12:07:46 +0000 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <5a469e21-a912-46ea-a12b-dddc0416b353@r15g2000prh.googlegroups.com> <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> Message-ID: In article <33d59aa0-e73b-45f8-bdfe-4c78717c68f7 at v5g2000prm.googlegroups.com>, joseph.a.marlin at gmail.com wrote: >On Jan 27, 6:47?pm, Andr? wrote: >> On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" >> >> wrote: >> > Greetings! I've heard enough raving about Python, I'm going to see for >> > myself what all the praise is for! >> >> > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >> > even use an IDE for Python? >> >> If you already use netbeans, what >abouthttp://www.netbeans.org/features/python/ >> ? >> > >Wow, you guys are fast... yes, I was having trouble deciding between >that (Netbeans), Smultron, or TextWrangler. Thanks! As already mentioned, both Netbeans and Komodo are good choices. A few more comments about these two appear in . From claird at lairds.us Wed Jan 28 07:10:53 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 12:10:53 +0000 Subject: Python Application Server References: <6cea0f1e0901272023q5ea3eb07m8fa42b5a092bd9c0@mail.gmail.com> Message-ID: In article , James Mills wrote: >On Wed, Jan 28, 2009 at 2:42 PM, James Mills > wrote: >(...) > >> Might I recommend circuits (1) as a general purpose >> framework that you can build your application on top of. >> >> circuits will allow you to communicate with long-running >> background processes, communicate between processes >> (by way of a Bridge). All communication in circuits is >> asyncroneous. circuits has also recently seen the integration >> of the multiprocessing package from python 2.6/3.0 so you >> can create processes and have inter-process communication >> seamlessly. In fact, parts of your system can even run on other >> nodes (you mentioned clustering). > >I should probably mention some of the components available (features); > * TCPServer, TCPClient > * UDPServer, UDPClient > * HTTP, IRC and SMTP protocols > * Web Server (with limited WSGI support) (depends on parts of CherryPy) > * Timers, Timer > * Logger, Debugger > * ... there are many more components ... :) > >Building new components is fairly easy as well. . . . The big question will be whether circuits qualifies for the original poster as an "application server". I agree, though, that, by the definition as it appeared at the beginning of this thread, circuits seems to be the best candidate. From psteiger at dcc.ufba.br Wed Jan 28 07:25:03 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Wed, 28 Jan 2009 04:25:03 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <909ef3300901280425h6c2dc200pc7566a182be8067a@mail.gmail.com> I would recommend Netbeans with Python plugin, Eric4 and Komodo Edit, with descending order of preference 2009/1/27 joseph.a.marlin at gmail.com > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Wed Jan 28 07:42:08 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 04:42:08 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> On Jan 28, 2:16?am, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. I think Python Cookbook has a recipe which deals with this. - 6.12 Checking an Instance for Any State Change. From ssalam at gmail.com Wed Jan 28 07:51:48 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Wed, 28 Jan 2009 18:21:48 +0530 Subject: bigint to timestamp Message-ID: Hi Group, I have file with contents retrieved from mysql DB. which has a time field with type defined bigint(20) I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS GMT) using python code. The value I found for that field is 212099016004150509 Give me sample code that does the conversion. Regds Shah From wmcclain at watershade.net Wed Jan 28 07:53:51 2009 From: wmcclain at watershade.net (Bill McClain) Date: 28 Jan 2009 12:53:51 GMT Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: On 2009-01-28, W. eWatson wrote: > Yes, that's true, but the big question is how to "see" the final image? > Either one employees another module or writes the file into a folder, then > displays it with a paint program? Does im.show() not work? -Bill -- Sattre Press Tales of War http://sattre-press.com/ by Lord Dunsany info at sattre-press.com http://sattre-press.com/tow.html From __peter__ at web.de Wed Jan 28 07:58:09 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 13:58:09 +0100 Subject: Drawing and Displaying an Image with PIL References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: W. eWatson wrote: > r wrote: >> Change this line: >> draw.line((0,0),(20,140), fill=128) >> >> To This: >> draw.line((0,0, 20,140), fill=128) >> >> And you should be good to go. Like you said, if you need to combine 2 >> tuples you can do: >> (1,2)+(3,4) > Yes, that's true, but the big question is how to "see" the final image? > Either one employees another module or writes the file into a folder, then > displays it with a paint program? For debugging purposes you can just invoke the show() method im = Image.open(...) # modify image im.show() If you want to integrate the image into your own Tkinter program -- that is explained here: http://effbot.org/tkinterbook/photoimage.htm Following these instruction you code might become import Tkinter as tk import Image import ImageTk import ImageDraw import sys filename = sys.argv[1] im = Image.open(filename) draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line(((0,0),(20,140)), fill=128) root = tk.Tk() pi = ImageTk.PhotoImage(im) label = tk.Label(root, image=pi) label.pack() root.mainloop() Peter From bbxx789_05ss at yahoo.com Wed Jan 28 08:19:49 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 28 Jan 2009 05:19:49 -0800 (PST) Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: On Jan 27, 6:07?pm, Burukena wrote: > On 1/27/09 8:44 PM, James Stroud wrote: > > > joseph.a.mar... at gmail.com wrote: > >> Greetings! I've heard enough raving about Python, I'm going to see for > >> myself what all the praise is for! > > >> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > >> even use an IDE for Python? > > >> Any recommendations on open source Python environments? > > >> Thanks! > > > Try open komodo. I haven't used it because vim is my IDE, but it looks > > pretty good. > > > James > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Vim and a terminal works for me, specifically with screen. What does 'with screen' mean? From jnoller at gmail.com Wed Jan 28 08:28:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:28:34 -0500 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280528r469f3c3age3f085d0fe6593a2@mail.gmail.com> On Tue, Jan 27, 2009 at 11:36 PM, James Mills wrote: > On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: >> Steve Holden writes: >>> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >>> inclusion (later recognizable as somewhat ill-advised so late in the >>> day) of multiprocessing [?] > > Steve: It's just a new package - it used to be available > as a 3rd-party package. I dare say it most definitely was > -not- ill-advised. It happens to be a great addition to the > standard library. > >> What was ill-advised about the addition of the 'multiprocessing' >> module to Python 2.6? I ask because I haven't yet used it in anger, >> and am not sure what problems have been found in it. > > I have found no problems with it - I've recently integrated it with my > event/component framework (1). In my library I use Process, Pipe > and Value. > > cheers > James > Awesome James, I'll be adding this to both the multiprocessing talk, and the distributed talk. Let me know if you have any issues. -jesse From aspersieman at gmail.com Wed Jan 28 08:29:13 2009 From: aspersieman at gmail.com (aspersieman) Date: Wed, 28 Jan 2009 15:29:13 +0200 Subject: New to python, open source Mac OS X IDE? In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <49805DA9.60406@googlemail.com> 7stud wrote: > On Jan 27, 6:07 pm, Burukena wrote: > >> On 1/27/09 8:44 PM, James Stroud wrote: >> >> >>> joseph.a.mar... at gmail.com wrote: >>> >>>> Greetings! I've heard enough raving about Python, I'm going to see for >>>> myself what all the praise is for! >>>> >>>> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you >>>> even use an IDE for Python? >>>> >>>> Any recommendations on open source Python environments? >>>> >>>> Thanks! >>>> >>> Try open komodo. I haven't used it because vim is my IDE, but it looks >>> pretty good. >>> >>> James >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> Vim and a terminal works for me, specifically with screen. >> > > What does 'with screen' mean? > http://www.gnu.org/software/screen/ > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Vince Noir: Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard... Howard? Howard Moon: This better be good. Vince Noir: You know the black bits in bananas, are they tarantulas' eggs? Howard Moon: Please don't speak to me ever again in your life. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Wed Jan 28 08:31:00 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jan 2009 14:31:00 +0100 Subject: bigint to timestamp References: Message-ID: Shah Sultan Alam wrote: > I have file with contents retrieved from mysql DB. > which has a time field with type defined bigint(20) > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > GMT) using python code. Try time.strftime. > The value I found for that field is 212099016004150509 That looks like a bit big for digestion by strftime, so I'd suggest you first find out what the unit and offset of the value in your DB actually is. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve at holdenweb.com Wed Jan 28 08:32:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:32:05 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: James Mills wrote: > On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney wrote: >> Steve Holden writes: >>> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >>> inclusion (later recognizable as somewhat ill-advised so late in the >>> day) of multiprocessing [?] > > Steve: It's just a new package - it used to be available > as a 3rd-party package. I dare say it most definitely was > -not- ill-advised. It happens to be a great addition to the > standard library. > >> What was ill-advised about the addition of the 'multiprocessing' >> module to Python 2.6? I ask because I haven't yet used it in anger, >> and am not sure what problems have been found in it. > > I have found no problems with it - I've recently integrated it with my > event/component framework (1). In my library I use Process, Pipe > and Value. > It will be a great library in time, but the code was immature and insufficiently tested before the 2.6 release. The decision to include it late in the release cycle There are 32 outstanding issues on multiprocessing, two of them critical and four high. Many of them are platform-specific, so if they don't hit your platform you won't mind. Jesse did a great job in the time available. It would have been more sensible to wait until 2.7 to include it in the library, IMHO, or make the decision to include it in 2.6 in a more timely fashion. The one advantage of the inclusion is that the issues have been raised now, so as long as maintenance continues the next round will be better. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Jan 28 08:40:07 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:40:07 -0500 Subject: need help In-Reply-To: References: Message-ID: juvy j wrote: > Hi guys, > > need help on how to read file from other server(linux). > Which service do you plan to use: FTP, HTTP and NFS are three possibilities that immediately come to mind, all well handled by {ython standard library modules. A little more background might help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jnoller at gmail.com Wed Jan 28 08:41:34 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:41:34 -0500 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <87mydcxf6x.fsf@benfinney.id.au> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> On Tue, Jan 27, 2009 at 10:49 PM, Ben Finney wrote: > (Continuing a side topic of a different discussion) > > Steve Holden writes: > >> I think that [Python 2.6 was a rushed release]. 2.6 showed it in the >> inclusion (later recognizable as somewhat ill-advised so late in the >> day) of multiprocessing [?] > > What was ill-advised about the addition of the 'multiprocessing' > module to Python 2.6? I ask because I haven't yet used it in anger, > and am not sure what problems have been found in it. > > -- > \ "Holy bouncing boiler-plated fits, Batman!" ?Robin | > `\ | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > I might write a longer blog post about this later, but I can see Steve's point of view. The fact is, pyprocessing/multiprocessing was a late addition to Python 2.6. Personally, I was game to put it into either 2.7 or 2.6, but I felt inclusion into 2.6 wasn't completely out of question - and others agreed with me. See these mail threads: http://mail.python.org/pipermail/python-dev/2008-May/079417.html http://mail.python.org/pipermail/python-dev/2008-June/080011.html And so on. All of that being said; the initial conversion and merging of the code into core exposed a lot of bugs I and others didn't realize were there in the first place. I take full responsibility for that - however some of those bugs were in python-core itself (deadlock after fork anyone?). So, the road to inclusion was a bit rougher than I initially thought - I relied heavily on the skills of people who had more experience in the core than I did, and it was disruptive to the release schedule of python 2.6 due to both the bugs and instability. I however; disagree that this was ultimately a bad decision, or that it was some how indicative of a poorly managed or rushed 2.6 release. All releases have bugs, and towards the end of the 2.6 cycle, multiprocessing *was not* the release blocker. After 2.6 went out, I had a small wave of bugs filed against multiprocessing that I've been working through bit by bit (I still need to work on BSD/Solaris issues) and some of the bugs have exposed issues I simply wish weren't there but I think this is true of any package, especially one as complex as multiprocessing is. I know of plenty of people using the package now, and I know of several groups switching to 2.6 as quickly as possible due to its new features, bug fixes/etc. Multiprocessing as a package is not bug free - I'm the first to admit that - however it is useful, and being used and frankly, I maintain that it is just one step in a larger project to bring additional concurrency and distributed "stuff" into python-core over time. So yes, I see Steve's point - multiprocessing *was* disruptive, and it inclusion late in the game siphoned off resources that could have been used elsewhere. Again, I'll take the responsibility for soiling the pool this way. I do however think, that python 2.6 is overall a *fantastic* release both feature wise, quality wise and is quite useful for people who want to "get things done" (tm). Now I'm going to go back to fixing bugs. -jesse From jnoller at gmail.com Wed Jan 28 08:49:28 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 28 Jan 2009 08:49:28 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> Message-ID: <4222a8490901280549r4cc4bb55q299162dee2bce4c5@mail.gmail.com> On Wed, Jan 28, 2009 at 8:32 AM, Steve Holden wrote: ...snip... >> I have found no problems with it - I've recently integrated it with my >> event/component framework (1). In my library I use Process, Pipe >> and Value. >> > It will be a great library in time, but the code was immature and > insufficiently tested before the 2.6 release. The decision to include it > late in the release cycle > > There are 32 outstanding issues on multiprocessing, two of them critical > and four high. Many of them are platform-specific, so if they don't hit > your platform you won't mind. > See my reply to the thread I just sent out; I don't disagree with you. However, there are not 32 open bugs: http://bugs.python.org/issue?%40search_text=&title=&%40columns=title&id=&%40columns=id&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=&versions=&dependencies=&assignee=jnoller&keywords=&priority=&%40group=priority&status=1&%40columns=status&resolution=&%40pagesize=50&%40startwith=0&%40queryname=&%40old-queryname=&%40action=search Man, I hope that url comes through. As of this writing, there are 18 open bugs assigned to me for resolution. Of those, 2 are critical, but should not be - one is an enhancement I am on the fence about, and one is for platforms which have issues with semaphore support. However, I agree that there are bugs, and there will continue to be bugs. I think the quality has greatly increased since the port to core started, and we did find bugs in core as well. I also think it is more than ready for use now. > Jesse did a great job in the time available. It would have been more > sensible to wait until 2.7 to include it in the library, IMHO, or make > the decision to include it in 2.6 in a more timely fashion. The one > advantage of the inclusion is that the issues have been raised now, so > as long as maintenance continues the next round will be better. Again, I don't disagree. Alas, the PEP resolution and proposal was greatly delayed due to, well, someone paying me money to do something else ;) - that being said, yes, the decision was made late in the game, and was disruptive. Maintenance is going to continue as long as I continue to have an internet connection. Heck, there are enhancements to it I really want to add, but I swore off those until the bugs are closed/resolved and my pycon talks are in the can. -jesse From steve at holdenweb.com Wed Jan 28 08:50:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:50:58 -0500 Subject: bigint to timestamp In-Reply-To: References: Message-ID: Shah Sultan Alam wrote: > Hi Group, > I have file with contents retrieved from mysql DB. > which has a time field with type defined bigint(20) > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > GMT) using python code. > The value I found for that field is 212099016004150509 > Give me sample code that does the conversion. > Please? Perhaps you could tell us what date and time 212099016004150509 is supposed to represent? The classic format is "seconds since the Unix epoch" but that isn't what this is: >>> time.localtime(212099016004150509) Traceback (most recent call last): File "", line 1, in ValueError: timestamp out of range for platform time_t Neither does it appear to be a MySQL TIME field, since the maximum value for that would appear to be >>> ((838*60)+59)*60+59 3020399 So, just what is this field? What do the values mean? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Wed Jan 28 08:52:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 07:52:49 -0600 Subject: need help In-Reply-To: References: Message-ID: <49806331.20009@tim.thechases.com> >> need help on how to read file from other server(linux). >> > Which service do you plan to use: FTP, HTTP and NFS are three > possibilities that immediately come to mind, Or scp, or sftp, or rsync, or SMB, or AFS, or IMAP, or POP3, or instant-message, or VCS sync (svn/hg/git/bzr/cvs/darcs/whatever) or ... and via push or pull? > A little more background might help. indeed, for the OP: http://catb.org/~esr/faqs/smart-questions.html -tkc From adi at digitaltrowel.com Wed Jan 28 08:53:49 2009 From: adi at digitaltrowel.com (Adi Eyal) Date: Wed, 28 Jan 2009 15:53:49 +0200 Subject: Python Application Server Message-ID: <6cea0f1e0901280553x2b7bc8c6ke84c2d7c3fda5bb3@mail.gmail.com> Hi All Thanks for the responses - I'll look into Circuits and Twisted, the both seem to be relevant. Adi From steve at holdenweb.com Wed Jan 28 08:58:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 08:58:05 -0500 Subject: Addition of multiprocessing ill-advised? In-Reply-To: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> References: <497F6E55.6090608@v.loewis.de> <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> Message-ID: Jesse Noller wrote: [...] > So yes, I see Steve's point - multiprocessing *was* disruptive, and it > inclusion late in the game siphoned off resources that could have been > used elsewhere. Again, I'll take the responsibility for soiling the > pool this way. I do however think, that python 2.6 is overall a > *fantastic* release both feature wise, quality wise and is quite > useful for people who want to "get things done" (tm). > Overall I completely agree. And I don't think the decision to include it was down to you anyway, though you were certainly urging it. It was a release management issue. And 2.6 *is* a good release. > Now I'm going to go back to fixing bugs. > Don't forget those PyCon talks! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From joncle at googlemail.com Wed Jan 28 09:05:07 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 28 Jan 2009 06:05:07 -0800 (PST) Subject: bigint to timestamp References: Message-ID: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> On Jan 28, 1:50?pm, Steve Holden wrote: > Shah Sultan Alam wrote: > > Hi Group, > > I have file with contents retrieved from mysql DB. > > which has a time field with type defined bigint(20) > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > GMT) using python code. > > The value I found for that field is 212099016004150509 > > Give me sample code that does the conversion. > > Please? > > Perhaps you could tell us what date and time 212099016004150509 is > supposed to represent? The classic format is "seconds since the Unix > epoch" but that isn't what this is: > > >>> time.localtime(212099016004150509) > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: timestamp out of range for platform time_t > > Neither does it appear to be a MySQL TIME field, since the maximum value > for that would appear to be > > >>> ((838*60)+59)*60+59 > > 3020399 > > So, just what is this field? What do the values mean? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Bit hard to guess without the actual date to compare to... and I'm a bit busy, but thought I'd throw this in the pool: I'm guessing it's a MySQL database that's had data put into it via a .NET application using the .NET DateTime (so a 20 byte int sounds about right IIRC), which is based on the number of ticks since Jan 1, 1.... I think that should end up around 2[18ish digits here...]... Jon. From berankin99 at yahoo.com Wed Jan 28 09:08:46 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 06:08:46 -0800 (PST) Subject: Best/better way? (histogram) References: Message-ID: <622052.32909.qm@web112205.mail.gq1.yahoo.com> > > The simplest. That would be #3, cleaned up a bit: > > from collections import defaultdict > from csv import DictReader > from pprint import pprint > from operator import itemgetter > > def rows(filename): > infile = open(filename, "rb") > for row in DictReader(infile): > yield row["CATEGORIES"] > > def stats(values): > histo = defaultdict(int) > for v in values: > histo[v] += 1 > return sorted(histo.iteritems(), key=itemgetter(1), reverse=True) > > Should you need the inner dict (which doesn't seem to offer any additional > information) you can always add another step: > > def format(items): > result = [] > for raw, count in items: > leaf = raw.rpartition("|")[2] > result.append((raw, dict(count=count, leaf=leaf))) > return result > > pprint(format(stats(rows("sampledata.csv"))), indent=4, width=60) > > By the way, if you had broken the problem in steps like above you could have > offered four different stats() functions which would would have been a bit > easier to read... > Thank you. The code reorganization does make make it easer to read. I'll have to look up the docs on itemgetter() :) From exarkun at divmod.com Wed Jan 28 09:10:33 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 09:10:33 -0500 Subject: A Twisted Design Decision In-Reply-To: <488249aa-6139-4d0c-8151-1188a1a814ad@u18g2000pro.googlegroups.com> Message-ID: <20090128141033.24460.1020647946.divmod.quotient.3220@henry.divmod.com> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >On Jan 27, 9:27?pm, koranthala wrote: >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > [snip] >> >> Thank you Jean-Paul. >> My code is more complex than what I have mentioned. When I mentioned >> msg.send, the msg object actually gets the data from DB etc to send. >> And there are many other items being done. >> I will try to see whether I can change the code to incorporate what >> you mentioned. >> >> I rewrote most of my code after learning just raw deferreds - I had >> planned to study inlineCallbacks - but then it slipped my mind ?- now >> it has come to bit me. :-( > >Hi, > I tried to update the code as per the suggestion, but to no avail. > My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >rewrite with deferredGenerators - since I thought inlineCallbacks are >similar to deferredGenerators. > > But I cannot seem to rewrite it in a format where the functional >encapsulation is not broken. > i.e. as I mentioned in the first example - I have to pass SELF to >child objects for them to modify it. Why? You don't do this in the original version of your code. Why do it after switching to Twisted (particularly since you seem to want *not* to)? Jean-Paul From icanbob at gmail.com Wed Jan 28 09:17:38 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 28 Jan 2009 06:17:38 -0800 (PST) Subject: Python Application Server References: Message-ID: <17a4a6c1-0ca7-4e60-8863-29a9113a3191@f3g2000vbf.googlegroups.com> On Jan 27, 11:23 pm, Adi Eyal wrote: > Hi All > > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? > > Thanks in advance > Adi You might want to look into the SIMPL project stuff (http:// www.icanprogram.com/simpl). In particular there is a framework (SIMPL calls them softwareICs) called a proxy which sounds like exactly what you might want. bob From icanbob at gmail.com Wed Jan 28 09:21:13 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 28 Jan 2009 06:21:13 -0800 (PST) Subject: Calling Python-tk code from C/C++ References: <1233049321.419345a4c56c55ba30671ab8c25d2a73@mail.in.com> Message-ID: <3efdce25-e6c1-48a4-b386-ee86c67374e6@t3g2000yqa.googlegroups.com> On Jan 27, 12:29 pm, "Gabriel Genellina" wrote: > En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas > escribi?: > > > Hello all, This is my first post to this mailing list. Our requirement > > is to invoke a Tkinter python panel from a C++ GUI app where both GUI > > windows would run in 2 separate threads. We have written a sample PyQt > > application which calls this Tk panel using something like this:class > > TkPanel(threading.Thread):def run(self): # call showPaneldef > > showPanel():# create window = Tk.Tk() window.mainloop()def start():t = > > TkPanel()t.start()Now we call this from our main python code:def > > startPanel(self): import tkPanel tkPanel.start() # this calls > > tkwindow.mainloop() in a separate thread.This works absolutely fine when > > the invoking app is Python. > > From the above description I don't see where PyQt is involved. Do you > really want to mix Qt and Tk in the same application? I don't think they > could coexist... > -- > Gabriel Genellina Check out the SIMPL project (http://www.icanprogram.com/simpl). Using that toolkit you should be able to have your C++ module exchange a message with a separate Python/Tk/SIMPL module. This might do what you are after. bob From perfreem at gmail.com Wed Jan 28 09:28:53 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 06:28:53 -0800 (PST) Subject: how to optimize object creation/reading from file? Message-ID: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> hi, i am doing a series of very simple string operations on lines i am reading from a large file (~15 million lines). i store the result of these operations in a simple instance of a class, and then put it inside of a hash table. i found that this is unusually slow... for example: class myclass(object): __slots__ = ("a", "b", "c", "d") def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d def __str__(self): return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) def __hash__(self): return hash((self.a, self.b, self.c, self.d)) def __eq__(self, other): return (self.a == other.a and \ self.b == other.b and \ self.c == other.c and \ self.d == other.d) __repr__ = __str__ n = 15000000 table = defaultdict(int) t1 = time.time() for k in range(1, n): myobj = myclass('a' + str(k), 'b', 'c', 'd') table[myobj] = 1 t2 = time.time() print "time: ", float((t2-t1)/60.0) this takes a very long time to run: 11 minutes!. for the sake of the example i am not reading anything from file here but in my real code i do. also, i do 'a' + str(k) but in my real code this is some simple string operation on the line i read from the file. however, i found that the above code shows the real bottle neck, since reading my file into memory (using readlines()) takes only about 4 seconds. i then have to iterate over these lines, but i still think that is more efficient than the 'for line in file' approach which is even slower. in the above code is there a way to optimize the creation of the class instances ? i am using defaultdicts instead of ordinary ones so i dont know how else to optimize that part of the code. is there a way to perhaps optimize the way the class is written? if takes only 3 seconds to read in 15 million lines into memory it doesnt make sense to me that making them into simple objects while at it would take that much more... From koranthala at gmail.com Wed Jan 28 09:30:32 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 06:30:32 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <000d8ddf-414c-4f8f-8be9-d1cf0b349dc5@e1g2000pra.googlegroups.com> On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: > >On Jan 27, 9:27?pm, koranthala wrote: > >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > > [snip] > > >> Thank you Jean-Paul. > >> My code is more complex than what I have mentioned. When I mentioned > >> msg.send, the msg object actually gets the data from DB etc to send. > >> And there are many other items being done. > >> I will try to see whether I can change the code to incorporate what > >> you mentioned. > > >> I rewrote most of my code after learning just raw deferreds - I had > >> planned to study inlineCallbacks - but then it slipped my mind ?- now > >> it has come to bit me. :-( > > >Hi, > > ?I tried to update the code as per the suggestion, but to no avail. > > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to > >rewrite with deferredGenerators - since I thought inlineCallbacks are > >similar to deferredGenerators. > > > ?But I cannot seem to rewrite it in a format where the functional > >encapsulation is not broken. > > ?i.e. as I mentioned in the first example - I have to pass SELF to > >child objects for them to modify it. > > Why? ?You don't do this in the original version of your code. ?Why do > it after switching to Twisted (particularly since you seem to want *not* > to)? > > Jean-Paul Without that, I am unable to increment success and failure counters which are part of the message handler object. In the original version, if send fails the return value of protocol.send is propogated back to msg.send and to msg handler.send. But in twisted, it is not so. So, I have to pass in SELF through to increment success and failure counter. Is it possible otherwise in twisted? From towitowi at gmail.com Wed Jan 28 09:36:06 2009 From: towitowi at gmail.com (towitowi at gmail.com) Date: Wed, 28 Jan 2009 06:36:06 -0800 (PST) Subject: Python 3.0, 'Hello' < 42 Message-ID: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Hello, In the 3.0 changes list there is mentioned that "<"-compares are not supported anymore if the compared types are different (except numbers). Like 42 < "Hello" did return True of False depending on the implementation but is now a TypeError. But the document also mentions that the result is not strictly "undefined" but "reproducable undetermined". Meaning, that on a given machine with a given python implementation result will always be the same. But on another machine, or with another python implementation, it might give a different result. My question now is, why this is? E.g, Is there an integer large enough so that the result changes? What circumstances influence the result? Thanks in advance. tschau, towi. From claird at lairds.us Wed Jan 28 09:42:57 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 14:42:57 +0000 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: In article , 7stud wrote: . . . >> Vim and a terminal works for me, specifically with screen. > >What does 'with screen' mean? > From Ron.Barak at lsi.com Wed Jan 28 09:54:24 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 28 Jan 2009 14:54:24 +0000 Subject: How to execute a hyperlink? In-Reply-To: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF6024EA1B7@enbmail01.lsi.com> Hi Muddy, http://docs.python.org/library/urllib2.html may help. Bye, Ron. -----Original Message----- From: Muddy Coder [mailto:cosmo_general at yahoo.com] Sent: Wednesday, January 28, 2009 03:00 To: python-list at python.org Subject: How to execute a hyperlink? Hi Folks, Module os provides a means of running shell commands, such as: import os os.system('dir .') will execute command dir I think a hyperlink should also be executed. I tried: os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') but I got kicked out by the Python interpreter. I wonder somebody knows the syntax of triggering a hyperlink? Thanks in advance! Muddy Coder From bruno.42.desthuilliers at websiteburo.invalid Wed Jan 28 10:06:13 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jan 2009 16:06:13 +0100 Subject: how to optimize object creation/reading from file? In-Reply-To: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> References: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> Message-ID: <4980745d$0$20447$426a34cc@news.free.fr> perfreem at gmail.com a ?crit : > hi, > > i am doing a series of very simple string operations on lines i am > reading from a large file (~15 million lines). i store the result of > these operations in a simple instance of a class, and then put it > inside of a hash table. i found that this is unusually slow... for > example: > > class myclass(object): > __slots__ = ("a", "b", "c", "d") > def __init__(self, a, b, c, d): > self.a = a > self.b = b > self.c = c > self.d = d > def __str__(self): > return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) > def __hash__(self): > return hash((self.a, self.b, self.c, self.d)) > def __eq__(self, other): > return (self.a == other.a and \ > self.b == other.b and \ > self.c == other.c and \ > self.d == other.d) > __repr__ = __str__ If your class really looks like that, a tuple would be enough. > n = 15000000 > table = defaultdict(int) > t1 = time.time() > for k in range(1, n): hint : use xrange instead. > myobj = myclass('a' + str(k), 'b', 'c', 'd') > table[myobj] = 1 hint : if all you want is to ensure unicity, use a set instead. > t2 = time.time() > print "time: ", float((t2-t1)/60.0) hint : use timeit instead. > this takes a very long time to run: 11 minutes!. for the sake of the > example i am not reading anything from file here but in my real code i > do. also, i do 'a' + str(k) but in my real code this is some simple > string operation on the line i read from the file. however, i found > that the above code shows the real bottle neck, since reading my file > into memory (using readlines()) takes only about 4 seconds. i then > have to iterate over these lines, but i still think that is more > efficient than the 'for line in file' approach which is even slower. iterating over the file, while indeed a bit slower on a per-line basis, avoid useless memory comsuption which can lead to disk swapping - so for "huge" files, it might still be better wrt/ overall performances. > in the above code is there a way to optimize the creation of the class > instances ? i am using defaultdicts instead of ordinary ones so i dont > know how else to optimize that part of the code. is there a way to > perhaps optimize the way the class is written? if takes only 3 seconds > to read in 15 million lines into memory it doesnt make sense to me > that making them into simple objects while at it would take that much > more... Did you bench the creation of a 15.000.000 ints list ?-) But anyway, creating 15.000.000 instances (which is not a small number) of your class takes many seconds - 23.466073989868164 seconds on my (already heavily loaded) machine. Building the same number of tuples only takes about 2.5 seconds - that is, almost 10 times less. FWIW, tuples have all the useful characteristics of your above class (wrt/ hashing and comparison). My 2 cents... From claird at lairds.us Wed Jan 28 10:17:26 2009 From: claird at lairds.us (Cameron Laird) Date: Wed, 28 Jan 2009 15:17:26 +0000 Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> <8UVfl.45$n_6.33@newsfe22.ams2> Message-ID: <6h9656-i2n.ln1@lairds.us> In article <8UVfl.45$n_6.33 at newsfe22.ams2>, Roel Schroeven wrote: >Muddy Coder schreef: >> Hi Folks, >> >> Module os provides a means of running shell commands, such as: >> >> import os >> os.system('dir .') >> >> will execute command dir >> >> I think a hyperlink should also be executed. I tried: >> >> os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') >> >> but I got kicked out by the Python interpreter. I wonder somebody >> knows the syntax of triggering a hyperlink? Thanks in advance! > >As others have said, you can use the webbrowser module for hyperlinks. >Alternatively you can use os.startfile() which works hyperlinks and many >types of files, but only works on Windows (it does the same as >double-clicking in Windows Explorer). . . . I suspect that os.startfile() will indeed give Muddy Coder the most immediate satisfaction. It might interest him, though, also to experiment with os.system("start %s" % URL) Again, recognize this only gives happy results, in general, under Win*. From jeff at jmcneil.net Wed Jan 28 10:18:00 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 28 Jan 2009 07:18:00 -0800 (PST) Subject: How to execute a hyperlink? References: <6bfd33b7-d699-4d14-9337-bf48246d31be@k9g2000vbl.googlegroups.com> Message-ID: On Jan 27, 7:59 pm, Muddy Coder wrote: > Hi Folks, > > Module os provides a means of running shell commands, such as: > > import os > os.system('dir .') > > will execute command dir > > I think a hyperlink should also be executed. I tried: > > os.system('http://somedomain.com/foo.cgi?name=foo&passwd=bar') > > but I got kicked out by the Python interpreter. I wonder somebody > knows the syntax of triggering a hyperlink? Thanks in advance! > > Muddy Coder Like others have said, if you want a browser window, use the 'webbrowser' module. If you're looking to simply trigger a GET/POST without the UI aspect, then you'll probably want urllib or urllib2. Thanks, Jeff mcjeff.blogspot.com From mathieu.malaterre at gmail.com Wed Jan 28 10:21:05 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 28 Jan 2009 07:21:05 -0800 (PST) Subject: win32com.client / Trendlines Message-ID: <57ec1028-453a-4ce8-b76a-d6cc14689b54@z27g2000prd.googlegroups.com> Hi there, I am trying to use win32com.client, but I do not think I fully grasp the concept. So far I copied chunk of code from the net to write my script. It worked well until I could not find any example on Trendlines. According to doc it should be as simple as: wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear, name="Linear Trend") But I get an error: Traceback (most recent call last): File "addchart.py", line 65, in ? wc2.Chart.SeriesCollection(1).Trendlines.Add ( type=constants.xlLinear, name="Linear Trend") AttributeError: 'function' object has no attribute 'Add' It looks like Trendlines indeed does not have such member function. Am I missing something, do I need to generate something particular (eg. using makepy.py) Thanks ! From banaouas.medialog at wanadoo.fr Wed Jan 28 10:23:35 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Wed, 28 Jan 2009 16:23:35 +0100 Subject: file date/time on windows Message-ID: <49807795$0$18360$ba4acef3@news.orange.fr> hi, I noticed recently that the value of file date/time I get with python: time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) is forwarding by one hour the real file date/time. Example: file A.txt: 2009-01-18 16:13 returned valeur: 2009-01-28 15:13 Is there a simple way to get it work correctely (other than adding always 1 hour ...) ? thanks From exarkun at divmod.com Wed Jan 28 10:36:30 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 10:36:30 -0500 Subject: A Twisted Design Decision In-Reply-To: <000d8ddf-414c-4f8f-8be9-d1cf0b349dc5@e1g2000pra.googlegroups.com> Message-ID: <20090128153630.24460.1043773305.divmod.quotient.3248@henry.divmod.com> On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: >On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >> >On Jan 27, 9:27?pm, koranthala wrote: >> >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: >> > [snip] >> >> >> Thank you Jean-Paul. >> >> My code is more complex than what I have mentioned. When I mentioned >> >> msg.send, the msg object actually gets the data from DB etc to send. >> >> And there are many other items being done. >> >> I will try to see whether I can change the code to incorporate what >> >> you mentioned. >> >> >> I rewrote most of my code after learning just raw deferreds - I had >> >> planned to study inlineCallbacks - but then it slipped my mind ?- now >> >> it has come to bit me. :-( >> >> >Hi, >> > ?I tried to update the code as per the suggestion, but to no avail. >> > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >> >rewrite with deferredGenerators - since I thought inlineCallbacks are >> >similar to deferredGenerators. >> >> > ?But I cannot seem to rewrite it in a format where the functional >> >encapsulation is not broken. >> > ?i.e. as I mentioned in the first example - I have to pass SELF to >> >child objects for them to modify it. >> >> Why? ?You don't do this in the original version of your code. ?Why do >> it after switching to Twisted (particularly since you seem to want *not* >> to)? >> >> Jean-Paul > >Without that, I am unable to increment success and failure counters >which are part of the message handler object. >In the original version, if send fails the return value of >protocol.send is propogated back to msg.send and to msg handler.send. >But in twisted, it is not so. So, I have to pass in SELF through to >increment success and failure counter. >Is it possible otherwise in twisted? Why isn't the return value of protocol.send propagated back to msg.send? It sounds like it should be. Jean-Paul From gagsl-py2 at yahoo.com.ar Wed Jan 28 10:43:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 13:43:43 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden escribi?: > Gabriel Genellina wrote: >> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >> escribi?: >> I *thought* I did understand this until I came to this example: >> >> 1) >>>>> id(globals()), id(locals()) >> (11239760, 11239760) >> >> # ok, globals and locals are the same at the module level >> >> 2) >>>>> s = "(id(n) for n in [globals(),locals()])" >>>>> list(eval(s)) >> [11239760, 11239760] # still the same results >> >> 3) >>>>> s = "(id(n()) for n in [globals,locals])" >>>>> list(eval(s)) >> [11239760, 12583248] # locals() is different >> > No, locals is different, not locals(). You are looking at two different > functions that return the same object when called in the given context, > that's all. Perhaps you didn't notice that I shifted the () from right to left. I'm always printing the result of *calling* globals and locals -- the only change is *where* I do call them. >>>>> [id(n) for n in [globals(),locals()]] >> [11239760, 11239760] >>>>> [id(n()) for n in [globals,locals]] >> [11239760, 12583248] >> >> Seems that it is important *when* those functions are evaluated, but I >> don't understand *why*... -- Gabriel Genellina From mathieu.malaterre at gmail.com Wed Jan 28 10:43:51 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 28 Jan 2009 07:43:51 -0800 (PST) Subject: win32com.client / Trendlines References: <57ec1028-453a-4ce8-b76a-d6cc14689b54@z27g2000prd.googlegroups.com> Message-ID: On Jan 28, 4:21?pm, mathieu wrote: > Hi there, > > ? I am trying to use win32com.client, but I do not think I fully grasp > the concept. So far I copied chunk of code from the net to write my > script. It worked well until I could not find any example on > Trendlines. According to doc it should be as simple as: > > wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear, > name="Linear Trend") > > But I get an error: > > Traceback (most recent call last): > ? File "addchart.py", line 65, in ? > ? ? wc2.Chart.SeriesCollection(1).Trendlines.Add > ( type=constants.xlLinear, name="Linear Trend") > AttributeError: 'function' object has no attribute 'Add' > > It looks like Trendlines indeed does not have such member function. Am > I missing something, do I need to generate something particular (eg. > using makepy.py) > Ok found it. trend = wc2.Chart.SeriesCollection(1).Trendlines().Add (Type=constants.xlLinear, Name="Linear Trend") trend.DisplayRSquared = True trend.DisplayEquation = True Trendlines is a function... Sorry for the noise, win32com really rocks ! -Mathieu From kw at codebykevin.com Wed Jan 28 10:50:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 28 Jan 2009 10:50:58 -0500 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <49807EE2.3060007@codebykevin.com> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? > > Thanks! I use IDLE + Terminal myself. IDLE has improved a lot on the Mac in recent years. Another good tool is Aquamacs, a Mac-optimized version of Emacs: http://aquamacs.org -- Kevin Walzer Code by Kevin http://www.codebykevin.com From google at mrabarnett.plus.com Wed Jan 28 10:56:36 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 15:56:36 +0000 Subject: file date/time on windows In-Reply-To: <49807795$0$18360$ba4acef3@news.orange.fr> References: <49807795$0$18360$ba4acef3@news.orange.fr> Message-ID: <49808034.9080806@mrabarnett.plus.com> m.banaouas wrote: > hi, > > I noticed recently that the value of file date/time I get with python: > time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) > is forwarding by one hour the real file date/time. > > Example: > file A.txt: 2009-01-18 16:13 > returned valeur: 2009-01-28 15:13 > > Is there a simple way to get it work correctely (other than adding always 1 > hour ...) ? > time.gmtime(), as the name suggests, returns GMT (UTC). From your email address I presume you're in France, which is GMT+1. Windows Explorer shows the file time in local time, which for you is currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. From perfreem at gmail.com Wed Jan 28 11:02:04 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:02:04 -0800 (PST) Subject: how to optimize object creation/reading from file? References: <16e7300d-9118-44cb-aa22-3d48404983ed@v5g2000prm.googlegroups.com> <4980745d$0$20447$426a34cc@news.free.fr> Message-ID: <35207f52-9c69-4b29-a9b0-bbd9b19115f3@p2g2000prf.googlegroups.com> On Jan 28, 10:06?am, Bruno Desthuilliers wrote: > perfr... at gmail.com a ?crit : > > > > > hi, > > > i am doing a series of very simple string operations on lines i am > > reading from a large file (~15 million lines). i store the result of > > these operations in a simple instance of a class, and then put it > > inside of a hash table. i found that this is unusually slow... for > > example: > > > class myclass(object): > > ? ? __slots__ = ("a", "b", "c", "d") > > ? ? def __init__(self, a, b, c, d): > > ? ? ? ? self.a = a > > ? ? ? ? self.b = b > > ? ? ? ? self.c = c > > ? ? ? ? self.d = d > > ? ? def __str__(self): > > ? ? ? ? return "%s_%s_%s_%s" %(self.a, self.b, self.c, self.d) > > ? ? def __hash__(self): > > ? ? ? ? return hash((self.a, self.b, self.c, self.d)) > > ? ? def __eq__(self, other): > > ? ? ? ? return (self.a == other.a and \ > > ? ? ? ? ? ? ? ? self.b == other.b and \ > > ? ? ? ? ? ? ? ? self.c == other.c and \ > > ? ? ? ? ? ? ? ? self.d == other.d) > > ? ? __repr__ = __str__ > > If your class really looks like that, a tuple would be enough. > > > n = 15000000 > > table = defaultdict(int) > > t1 = time.time() > > for k in range(1, n): > > hint : use xrange instead. > > > ? ? myobj = myclass('a' + str(k), 'b', 'c', 'd') > > ? ? table[myobj] = 1 > > hint : if all you want is to ensure unicity, use a set instead. > > > t2 = time.time() > > print "time: ", float((t2-t1)/60.0) > > hint : use timeit instead. > > > this takes a very long time to run: 11 minutes!. for the sake of the > > example i am not reading anything from file here but in my real code i > > do. also, i do 'a' + str(k) but in my real code this is some simple > > string operation on the line i read from the file. however, i found > > that the above code shows the real bottle neck, since reading my file > > into memory (using readlines()) takes only about 4 seconds. i then > > have to iterate over these lines, but i still think that is more > > efficient than the 'for line in file' approach which is even slower. > > iterating over the file, while indeed a bit slower on a per-line basis, > avoid useless memory comsuption which can lead to disk swapping - so for > ? "huge" files, it might still be better wrt/ overall performances. > > > in the above code is there a way to optimize the creation of the class > > instances ? i am using defaultdicts instead of ordinary ones so i dont > > know how else to optimize that part of the code. is there a way to > > perhaps optimize the way the class is written? if takes only 3 seconds > > to read in 15 million lines into memory it doesnt make sense to me > > that making them into simple objects while at it would take that much > > more... > > Did you bench the creation of a 15.000.000 ints list ?-) > > But anyway, creating 15.000.000 instances (which is not a small number) > of your class takes many seconds - 23.466073989868164 seconds on my > (already heavily loaded) machine. Building the same number of tuples > only takes about 2.5 seconds - that is, almost 10 times less. FWIW, > tuples have all the useful characteristics of your above class (wrt/ > hashing and comparison). > > My 2 cents... thanks for your insight ful reply - changing to tuples made a big change! From koranthala at gmail.com Wed Jan 28 11:05:13 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 08:05:13 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> On Jan 28, 8:36?pm, Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: > >On Jan 28, 7:10?pm, Jean-Paul Calderone wrote: > >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: > >> >On Jan 27, 9:27?pm, koranthala wrote: > >> >> On Jan 27, 6:57?pm, Jean-Paul Calderone wrote: > >> > [snip] > > >> >> Thank you Jean-Paul. > >> >> My code is more complex than what I have mentioned. When I mentioned > >> >> msg.send, the msg object actually gets the data from DB etc to send. > >> >> And there are many other items being done. > >> >> I will try to see whether I can change the code to incorporate what > >> >> you mentioned. > > >> >> I rewrote most of my code after learning just raw deferreds - I had > >> >> planned to study inlineCallbacks - but then it slipped my mind ?- now > >> >> it has come to bit me. :-( > > >> >Hi, > >> > ?I tried to update the code as per the suggestion, but to no avail. > >> > ?My system uses Python2.4.3 (cannot move to 2.5) - so I tried to > >> >rewrite with deferredGenerators - since I thought inlineCallbacks are > >> >similar to deferredGenerators. > > >> > ?But I cannot seem to rewrite it in a format where the functional > >> >encapsulation is not broken. > >> > ?i.e. as I mentioned in the first example - I have to pass SELF to > >> >child objects for them to modify it. > > >> Why? ?You don't do this in the original version of your code. ?Why do > >> it after switching to Twisted (particularly since you seem to want *not* > >> to)? > > >> Jean-Paul > > >Without that, I am unable to increment success and failure counters > >which are part of the message handler object. > >In the original version, if send fails the return value of > >protocol.send is propogated back to msg.send and to msg handler.send. > >But in twisted, it is not so. So, I have to pass in SELF through to > >increment success and failure counter. > >Is it possible otherwise in twisted? > > Why isn't the return value of protocol.send propagated back to msg.send? > It sounds like it should be. > > Jean-Paul Thank you very much again Jean-Paul for helping me out. I am unable to understand how I will be able to propogate the return value of protocol.send to msg.send. Maybe I am being foolish - but my understanding is as follows. In a non-reactor pattern scenario: msg_handler.send_message calls msg.send which inturn calls protocol.send. So, the reply to protocol.send actually goes up the stack till msg_handler.send_message wherein I can increment/decrement success/ failure counter. In reactor pattern: msg_handler.send_message calls msg.send which call protocol.send which causes a deferred to be created. Now, when the deferred finishes its work, reactor calls the callback associated - but the original context (stack etc) is lost. Now, the only mechanism of interaction is via the parameters passed in the callback. This means that msg_handler has to pass in its object to msg.send which inturn has to send either msg_handler or self to protocol.send so that it is stored in the parameter to the callback. When callback is hit, I use this parameter to call methods in each object. This is what I was trying to say in my first mail that - Twisted, being twisted in its behavior is causing quite a lot of confusion in design decisions - because now I have to break functional encapsulation - by asking lower layer objects to handler upper layer objects behaviors. As I said earlier, maybe I am being completely stupid - there might be a very easy and obvious solution. But I cannot seem to get it at all. From perfreem at gmail.com Wed Jan 28 11:13:10 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:13:10 -0800 (PST) Subject: writing large dictionaries to file using cPickle Message-ID: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> hello all, i have a large dictionary which contains about 10 keys, each key has a value which is a list containing about 1 to 5 million (small) dictionaries. for example, mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': 'world'}, ...], key2: [...]} in total there are about 10 to 15 million lists if we concatenate together all the values of every key in 'mydict'. mydict is a structure that represents data in a very large file (about 800 megabytes). what is the fastest way to pickle 'mydict' into a file? right now i am experiencing a lot of difficulties with cPickle when using it like this: from cPickle import pickle pfile = open(my_file, 'w') pickle.dump(mydict, pfile) pfile.close() this creates extremely large files (~ 300 MB) though it does so *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and it gets slower and slower. it takes almost an hour if not more to write this pickle object to file. is there any way to speed this up? i dont mind the large file... after all the text file with the data used to make the dictionary was larger (~ 800 MB) than the file it eventually creates, which is 300 MB. but i do care about speed... i have tried optimizing this by using this: s = pickle.dumps(mydict, 2) pfile.write(s) but this takes just as long... any ideas ? is there a different module i could use that's more suitable for large dictionaries ? thank you very much. From arkanes at gmail.com Wed Jan 28 11:31:22 2009 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 28 Jan 2009 10:31:22 -0600 Subject: A Twisted Design Decision In-Reply-To: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> References: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> Message-ID: <4866bea60901280831x472ef75bw78bc7bf5e85aacdf@mail.gmail.com> On Wed, Jan 28, 2009 at 10:05 AM, koranthala wrote: > On Jan 28, 8:36 pm, Jean-Paul Calderone wrote: >> On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala wrote: >> >On Jan 28, 7:10 pm, Jean-Paul Calderone wrote: >> >> On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala wrote: >> >> >On Jan 27, 9:27 pm, koranthala wrote: >> >> >> On Jan 27, 6:57 pm, Jean-Paul Calderone wrote: >> >> > [snip] >> >> >> >> Thank you Jean-Paul. >> >> >> My code is more complex than what I have mentioned. When I mentioned >> >> >> msg.send, the msg object actually gets the data from DB etc to send. >> >> >> And there are many other items being done. >> >> >> I will try to see whether I can change the code to incorporate what >> >> >> you mentioned. >> >> >> >> I rewrote most of my code after learning just raw deferreds - I had >> >> >> planned to study inlineCallbacks - but then it slipped my mind - now >> >> >> it has come to bit me. :-( >> >> >> >Hi, >> >> > I tried to update the code as per the suggestion, but to no avail. >> >> > My system uses Python2.4.3 (cannot move to 2.5) - so I tried to >> >> >rewrite with deferredGenerators - since I thought inlineCallbacks are >> >> >similar to deferredGenerators. >> >> >> > But I cannot seem to rewrite it in a format where the functional >> >> >encapsulation is not broken. >> >> > i.e. as I mentioned in the first example - I have to pass SELF to >> >> >child objects for them to modify it. >> >> >> Why? You don't do this in the original version of your code. Why do >> >> it after switching to Twisted (particularly since you seem to want *not* >> >> to)? >> >> >> Jean-Paul >> >> >Without that, I am unable to increment success and failure counters >> >which are part of the message handler object. >> >In the original version, if send fails the return value of >> >protocol.send is propogated back to msg.send and to msg handler.send. >> >But in twisted, it is not so. So, I have to pass in SELF through to >> >increment success and failure counter. >> >Is it possible otherwise in twisted? >> >> Why isn't the return value of protocol.send propagated back to msg.send? >> It sounds like it should be. >> >> Jean-Paul > > Thank you very much again Jean-Paul for helping me out. > I am unable to understand how I will be able to propogate the return > value of protocol.send to msg.send. > Maybe I am being foolish - but my understanding is as follows. > > In a non-reactor pattern scenario: > msg_handler.send_message calls msg.send which inturn calls > protocol.send. > So, the reply to protocol.send actually goes up the stack till > msg_handler.send_message wherein I can increment/decrement success/ > failure counter. > > In reactor pattern: > msg_handler.send_message calls msg.send which call protocol.send which > causes a deferred to be created. > Now, when the deferred finishes its work, reactor calls the callback > associated - but the original context (stack etc) is lost. > Now, the only mechanism of interaction is via the parameters passed in > the callback. > This means that msg_handler has to pass in its object to msg.send > which inturn has to send either msg_handler or self to protocol.send > so that it is stored in the parameter to the callback. > When callback is hit, I use this parameter to call methods in each > object. > > This is what I was trying to say in my first mail that - Twisted, > being twisted in its behavior is causing quite a lot of > confusion in design decisions - because now I have to break functional > encapsulation - by asking lower layer objects to handler upper layer > objects behaviors. > > As I said earlier, maybe I am being completely stupid - there might > be a very easy and obvious solution. But I cannot seem to get it at > all. > I'm sure you're not completely stupid, but there is an easy and obvious solution - you should be returning the *deferred* up the callstack. That will allow the MessageHandler to attach callbacks/errbacks to it, without needing to pass self all the way down the call stack and have a proxy object manage it. From python at bdurham.com Wed Jan 28 11:32:27 2009 From: python at bdurham.com (python at bdurham.com) Date: Wed, 28 Jan 2009 11:32:27 -0500 Subject: writing large dictionaries to file using cPickle In-Reply-To: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: <1233160347.11640.1297229163@webmail.messagingengine.com> Hi, Change: pickle.dump(mydict, pfile) to: pickle.dump(mydict, pfile, -1 ) I think you will see a big difference in performance and also a much smaller file on disk. BTW: What type of application are you developing that creates so many dictionaries? Sounds interesting. Malcolm From jef.mangelschots at gmail.com Wed Jan 28 11:36:19 2009 From: jef.mangelschots at gmail.com (jefm) Date: Wed, 28 Jan 2009 08:36:19 -0800 (PST) Subject: unable to print Unicode characters in Python 3 References: <497E3C6F.1010909@v.loewis.de> <44153026-1923-4b34-a019-b7b766ee8edb@k36g2000pri.googlegroups.com> <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: this is alink explaining how to add new fonts to the command line (e.g. Lucida Sans Unicode) http://phatness.com/node/1643 From exarkun at divmod.com Wed Jan 28 11:40:59 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 11:40:59 -0500 Subject: A Twisted Design Decision In-Reply-To: <43f1f586-c309-4bbe-b434-c65626f71230@y1g2000pra.googlegroups.com> Message-ID: <20090128164059.24460.408587049.divmod.quotient.3269@henry.divmod.com> On Wed, 28 Jan 2009 08:05:13 -0800 (PST), koranthala wrote: >On Jan 28, 8:36?pm, Jean-Paul Calderone wrote: >> [snip] >> Why isn't the return value of protocol.send propagated back to msg.send? >> It sounds like it should be. >> >> Jean-Paul > >Thank you very much again Jean-Paul for helping me out. >I am unable to understand how I will be able to propogate the return >value of protocol.send to msg.send. >Maybe I am being foolish - but my understanding is as follows. > >In a non-reactor pattern scenario: >msg_handler.send_message calls msg.send which inturn calls >protocol.send. >So, the reply to protocol.send actually goes up the stack till >msg_handler.send_message wherein I can increment/decrement success/ >failure counter. > >In reactor pattern: >msg_handler.send_message calls msg.send which call protocol.send which >causes a deferred to be created. >Now, when the deferred finishes its work, reactor calls the callback >associated - but the original context (stack etc) is lost. >Now, the only mechanism of interaction is via the parameters passed in >the callback. You can still interact via return values. You should be thinking about a Deferred in the same way as you think about a function which returns a result synchronously. The Deferred represents the result, even though it isn't the result itself (since the result doesn't exist yet). Anything you would have done by calling a function and then using its return value you can do by calling a function and then using the Deferred it returns. I'll try to update the Twisted version of the code you gave previously to demonstrate this: class MessageHandler: def send_message(self): def handleResult(result): if result: self.success += 1 else: self.failure += 1 if self.execute(): for i in self.msgs: msg.send().addCallback(handleResult) class Message: def send(self): self.h = h #The message handler object self.update_data() #The data to be sent is updated here return self.protocol.send() class Protocol: @deferredGenerator def send(self): d = waitForDeferred(getPage(url, method, data)) yield d if page received: parse page and see parameters if parameters: yield True return yield False See how neither the handler nor the message is passed into the protocol. The result of the Deferred returned by Protocol.send is instead used by the handler to do something that the handler knows about. The encapsulation is the same as it was in your original example. The only significant change is from synchronous return values to Deferred return values. Jean-Paul From perfreem at gmail.com Wed Jan 28 11:43:23 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 08:43:23 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 28, 11:32?am, pyt... at bdurham.com wrote: > Hi, > > Change: > > pickle.dump(mydict, pfile) > > to: > > pickle.dump(mydict, pfile, -1 ) > > I think you will see a big difference in performance and also a much > smaller file on disk. > > BTW: What type of application are you developing that creates so many > dictionaries? Sounds interesting. > > Malcolm hi! thank you for your reply. unfortunately i tried this but it doesn't change the speed. it's still writing the file extremely slowly. i'm not sure why? thank you. From invalid at invalid Wed Jan 28 11:43:44 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 28 Jan 2009 10:43:44 -0600 Subject: How many followers of comp.lang.python References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> <8bb6ec2f-a71d-4838-957a-c69b164b623b@v39g2000pro.googlegroups.com> <297e4df8-3cdb-4834-ad21-a2a2696dd895@q37g2000vbn.googlegroups.com> <497f3260$0$3671$426a74cc@news.free.fr> <58de9ce5-5c71-46ee-a465-7cbf347383e4@f40g2000pri.googlegroups.com> <49802a69$0$3270$426a34cc@news.free.fr> Message-ID: On 2009-01-28, Bruno Desthuilliers wrote: >> very interesting. We should have a vote as to who would be the >> most likely candidate, now that would be a good thread :) > > Waste of time as far as I'm concerned. Usenet? Wasting time? Never! -- Grant Edwards grante Yow! I feel ... JUGULAR ... at visi.com From lists at cheimes.de Wed Jan 28 11:48:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 28 Jan 2009 17:48:38 +0100 Subject: writing large dictionaries to file using cPickle In-Reply-To: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: perfreem at gmail.com schrieb: > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. Have a look at ZODB. From berankin99 at yahoo.com Wed Jan 28 12:02:55 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 09:02:55 -0800 (PST) Subject: small python-cgi wiki? Message-ID: <889572.28267.qm@web112204.mail.gq1.yahoo.com> Hello, I'm looking to set up a small private wiki, and am looking for recommendations. Some sort of CGI based package that I could just untar somewhere web accessable via Apache would be great. Any ideas? Thanks, :) From jeremiah.dodds at gmail.com Wed Jan 28 12:04:44 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Wed, 28 Jan 2009 12:04:44 -0500 Subject: How many followers of comp.lang.python In-Reply-To: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> References: <7356f5db-3bbb-4346-9d2c-ce78402da945@e10g2000vbe.googlegroups.com> Message-ID: <12cbbbfc0901280904y4b8c0ddfuf8ea9f5db9608a83@mail.gmail.com> On Tue, Jan 27, 2009 at 10:07 AM, rantingrick wrote: > I curious of how many are "really" out there. I have been watching the > list for some time but basically see the same 10 or so people > answering questions. > > Reply to this message so we can see how many exists here > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > I'm sure there are a lot more people lurking than actually posting. I personally do a lot more lurking than posting - plus I post through google groups at the moment, which means that at least some of the regular posters won't see what I post. I've learned an awful lot by lurking the mailing lists, hopefully I'll be able to contribute more in the future. -------------- next part -------------- An HTML attachment was scrubbed... URL: From berankin99 at yahoo.com Wed Jan 28 12:04:45 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Wed, 28 Jan 2009 09:04:45 -0800 (PST) Subject: Python Package Managment References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> Message-ID: <759991.83977.qm@web112220.mail.gq1.yahoo.com> > > [extracted from pylons-discuss] > > > > > >> >> I hate to pass the buck, but this is Python's fault for not having > >> >> reliable package management built in. There's nothing Pylons can do > >> >> about it except switch to another programming language. > >> > [SNIP] > >> > >> Without Setuptools, > >> Pylons and TurboGears couldn't exist, and Zope and Twisted > >> would not have been able to split themselves into several packages. > >> People coming to Python from Perl and Ruby expect to be able to just > >> run a command to download and install a package. That problem was > >> solved ten years ago, so why does Python still not have it standard? > >> > >> If Setuptools and Virtualenv or the equivalent were built into Python, > >> you could trust that every computer that has successfully installed > >> Python can install packages and make virtual environments the same > >> way.. > >> > >> That would eliminate 2/3 of the problems users have when > >> installing Pylons, and the subsequent need to explain the problems and > >> workarounds in the installation docs. At > >> work people say, "Half the trouble of Pylons is installing it", and I > >> often have to help them install it in person because otherwise they > >> get stuck at some error message and have no idea what to do. > >> > > > > Agreed. I would even move ipython (or something like it) to core. > > > > Of course, even Setuptools has a long way to go in some areas. (Installation > Rollback, for one.) > > > > Python is about "batteries included", and these are major "batteries" in most > modern environments. > > > > A CPAN like "in-house hosted" archive would nice, too. This way, modules have > a better chance of outliving the original author's interest/commitment in paying > for, possibly non-trivial, web hosting. > > > > I'm sure these issues has been discussed to death, but I wonder what the > larger Python community thinks. > > You may be interested in the following: > > http://mail.python.org/pipermail/python-dev/2006-April/063952.html > > The thread is two years and a half old, but my impression is that the > situation has not changeed much since. Few if any people are against > improving the situation, but more people are against the currently > available solutions (setuptools, virtualenv, etc...). > Thank you, I'll have a look. From cjlesh at gmail.com Wed Jan 28 12:07:54 2009 From: cjlesh at gmail.com (cjl) Date: Wed, 28 Jan 2009 09:07:54 -0800 (PST) Subject: Windows PIL installer question Message-ID: <381de027-2be2-4de4-bb39-bf170a970a5a@s20g2000yqh.googlegroups.com> Is there any way to run the PIL installer from the command line on Windows in 'silent' mode, without displaying the install screens or requiring user interaction? From koranthala at gmail.com Wed Jan 28 12:12:18 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:12:18 -0800 (PST) Subject: A Twisted Design Decision References: Message-ID: <298da38d-7678-4d54-9ab0-835eb5dbc854@w1g2000prk.googlegroups.com> > You can still interact via return values. ?You should be thinking about > a Deferred in the same way as you think about a function which returns > a result synchronously. ?The Deferred represents the result, even though > it isn't the result itself (since the result doesn't exist yet). ?Anything > you would have done by calling a function and then using its return value > you can do by calling a function and then using the Deferred it returns. > Oh! This makes it very clear. Thank you very much Jean-Paul and Chris Mellon. My view of deferred was very different from this. That was the reason behind these persistent questions. My view of deferred was that of it being a mechanism to provide asynchronous behavior and nothing more. The twisted documentation explicitly mentions this - 'Twisted?s Deferred abstraction, which symbolises a ?promised? result and which can pass an eventual result to handler functions.' But with my earlier view I understood it completely differently. Thank you once more, Jean-Paul & Chris for taking your valuable time out to help me out. From gil.shinar at gmail.com Wed Jan 28 12:12:57 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Wed, 28 Jan 2009 09:12:57 -0800 (PST) Subject: Process crash with no reason References: Message-ID: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> On Jan 27, 5:59?pm, Philip Semanchuk wrote: > On Jan 27, 2009, at 10:34 AM, gil.shi... at gmail.com wrote: > > > > > On Jan 27, 2:10 pm, Tim Golden wrote: > >> gil.shi... at gmail.com wrote: > >>> On Jan 26, 8:40 pm, Philip Semanchuk wrote: > >>>> On Jan 26, 2009, at 1:13 PM, gil.shi... at gmail.com wrote: > > >>>>> Hi All, > >>>>> I'm running a program that is acting as a nice interface to ? > >>>>> sybase' > >>>>> replication server. The program is using the cherrypy web ? > >>>>> service for > >>>>> the GUI. The process is crashing every few days with no reason. ? > >>>>> In the > >>>>> log I can see INFO and DEBUG (No ERROR) log lines and I do not ? > >>>>> get any > >>>>> TraceBack python's message. This program is running on solaris 9 > >>>>> machine. > >>>>> Where can I see or what can I do in order to find out what ? > >>>>> causes the > >>>>> process to crash? > >>>>> I have tried simulating a "traceBack" message and I could see this > >>>>> traceback message in one of the log files I'm using. When the ? > >>>>> process > >>>>> crashes without my help, I don't have a clue. > >>>>> Let me know if you need any other info > >>>> Although Python isn't immune to fatal errors like you describe, I'd > >>>> immediately suspect a 3rd-party module instead, esp. one written ? > >>>> in C > >>>> or C++. Are you using anything like that? > > >>> No I do not. > > >> Then how are you interacting with Sybase? > > > I'm using python's functions to run sybase sql commands. > > Can you give a short code sample? I'm unaware of how one would use the ? > standard Python library to talk to Sybase, unless Sybase has a raw ? > socket interface or some such. First of all I have found the following python's import: import Sybase To connect the sybase server we are using the following function: def _getConnection (self): db = Sybase.connect(self.dbs, self.login[0], self.login [1], datetime='auto') return db To execute a DBS query, we are using the following function: def _executeQuery(self, cursor, query, expected_result=None): try: self.logger.debug('Executing query:' + query + ', expected:' + str(expected_result)) cursor.execute(query) except Sybase.DatabaseError, e: if ((expected_result != None) and ("Msg " + expected_result in str(e))): return (DBStatus.SUCCESS, self._getDBMsg(str(e))) raise Sybase.DatabaseError, self._getDBMsg(str (e)) return (DBStatus.SUCCESS, "") Do you need anything else? Thanks a lot From koranthala at gmail.com Wed Jan 28 12:16:18 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:16:18 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> Message-ID: <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> On Jan 28, 5:42?pm, koranthala wrote: > On Jan 28, 2:16?am, Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > a list of ?objects > > > A=[a,b,c,d,...,z] > > > where, ?in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that > > something about the ?object 'a' has changed so that when I revisit A, > > I will know that the other items in the list need to be refreshed to > > reflect the changes in A as a result of changing 'a'. > > > Even better would be to automatically percolate the subsequent changes > > that resulted from altering 'a' for the rest of the items in the list. > > Naturally, all of these items are related in some parent-child > > fashion. > > > that might be a lot to ask, however. > > > Any advice appreciated. > > I think Python Cookbook has a recipe which deals with this. > - 6.12 Checking an Instance for Any State Change. Were you able to get this? If not, let me know. I will try to type it in here - (it is a big recipe, so not doing it now) From alex at moreati.org.uk Wed Jan 28 12:17:29 2009 From: alex at moreati.org.uk (moreati) Date: Wed, 28 Jan 2009 09:17:29 -0800 (PST) Subject: Reuse of DB-API 2.0 cursors for multiple queries? Message-ID: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Today, I used the adodbapi module against an SQL Server Express database. I was surprised to get an exception, when I attempted to submit a second query with my cursor object. The full session is below. With cx_Oracle I've become used to reusing a cursor for subsequent queries. The PEP doesn't specify either way, that I can see. Is this behaviour left to the implementation, or should I be able to expect a cursor is reusable? With thanks, Alex Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import adodbapi >>> conn = adodbapi.connect('Provider=SQLOLEDB.1;Data Source=.\\SQLEXPRESS;Initial Catalog=MYDATABBASE;Integrated Security=SSPI;User Instance=False;') >>> curs = conn.cursor() >>> curs.execute('select * from localview_roles') >>> curs.execute('select * from localview_roles') Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 713, in execut e self._executeHelper(operation,False,parameters) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 664, in _execu teHelper self._raiseCursorError(DatabaseError,tracebackhistory) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 474, in _raise CursorError eh(self.conn,self,errorclass,errorvalue) File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 60, in standar dErrorHandler raise errorclass(errorvalue) adodbapi.adodbapi.DatabaseError: --ADODBAPI Traceback (most recent call last): File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 650, in _exec uteHelper adoRetVal=self.cmd.Execute() File "", line 3, in Execute File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes ) + args) com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Cannot create new connection because in manual or distribute d transaction mode.', None, 0, -2147467259), None) -- on command: "select * from localview_roles" -- with parameters: None From ptmcg at austin.rr.com Wed Jan 28 12:33:35 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 28 Jan 2009 09:33:35 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 3:16?pm, Reckoner wrote: > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > Check out the Enthought Traits package. -- Paul From philip at semanchuk.com Wed Jan 28 12:37:56 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 28 Jan 2009 12:37:56 -0500 Subject: Process crash with no reason In-Reply-To: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> References: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> Message-ID: <41CFAEB0-8C19-45D0-9498-A9A7A7A36145@semanchuk.com> On Jan 28, 2009, at 12:12 PM, gil.shinar at gmail.com wrote: > On Jan 27, 5:59 pm, Philip Semanchuk wrote: >> On Jan 27, 2009, at 10:34 AM, gil.shi... at gmail.com wrote: >>> On Jan 27, 2:10 pm, Tim Golden wrote: >>>> Then how are you interacting with Sybase? >> >>> I'm using python's functions to run sybase sql commands. >> >> Can you give a short code sample? I'm unaware of how one would use >> the >> standard Python library to talk to Sybase, unless Sybase has a raw >> socket interface or some such. > > First of all I have found the following python's import: > > import Sybase This isn't part of the Python standard library. It's a 3rd party module -- exactly what we were looking for. Personally, I think this (or another C++ or C-based 3rd party module that you use heavily) is your prime suspect for the origin of the crashes you're having. That's not because I think the people who wrote or maintain it are bad or lazy coders. In fact, it's no reflection on their skill at all. It's just that a lot more people have used and exercised the Python standard library modules. A 3rd party module like this one will be less well-used and therefore less well-tested and therefore more likely to contain a bug that causes a crash. That said, I don't know how to advise you to proceed from here. You could perhaps turn on logging at the database level. I know Postgres, for instance, can write very detailed logs and so if you get a crash at 9:33:22 you can look in the log and see what was happening at that time. If you get several crashes and they all happen when a certain SQL statement is being executed, that's probably the culprit. You could also alter the Sybase module to add logging using Python's logging module. Who knows, it might already be there, waiting to be turned on with a switch. But I'm jumping the gun a little. As I said, it could be this module or another that's causing your problem. It's a lot easier to cause a hard crash using C or C++ than it is using pure Python, so pure Python modules would be lower on my list of suspects. Enumerate all of the modules you're using and find out where they come from. Any of them that are not in the standard library and are not written in pure Python should top your list of suspects. Good luck Philip From martin at v.loewis.de Wed Jan 28 12:38:46 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 18:38:46 +0100 Subject: unable to print Unicode characters in Python 3 In-Reply-To: <498018B7.1070803@lexicon.net> References: <497E3C6F.1010909@v.loewis.de> <34020906-7fc1-426b-809c-5446ab993f52@i24g2000prf.googlegroups.com> <49800A25.2060702@v.loewis.de> <498018B7.1070803@lexicon.net> Message-ID: <49809826.2070701@v.loewis.de> > Big step. I don't have Visual Studio and have never used it before. > Which version of VS do I need to debug which released version of Python > 2.X and where do I get that VS from? Or do I need to build Python from > source to be able to debug it? You need Visual Studio 2008 (Professional, not sure about Standard), or Visual C++ 2008 (which is free). You need to build Python from source in debug mode; the released version is in release mode, and with no debug information. Regards, Martin From reckoner at gmail.com Wed Jan 28 12:39:44 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 28 Jan 2009 09:39:44 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> Message-ID: <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> On Jan 28, 9:16 am, koranthala wrote: > On Jan 28, 5:42 pm, koranthala wrote: > > > > > On Jan 28, 2:16 am, Reckoner wrote: > > > > I'm not sure this is possible, but I would like to have > > > a list of objects > > > > A=[a,b,c,d,...,z] > > > > where, in the midst of a lot of processing I might do something like, > > > > A[0].do_something_which_changes_the_properties() > > > > which alter the properties of the object 'a'. > > > > The trick is that I would like A to be mysteriously aware that > > > something about the object 'a' has changed so that when I revisit A, > > > I will know that the other items in the list need to be refreshed to > > > reflect the changes in A as a result of changing 'a'. > > > > Even better would be to automatically percolate the subsequent changes > > > that resulted from altering 'a' for the rest of the items in the list. > > > Naturally, all of these items are related in some parent-child > > > fashion. > > > > that might be a lot to ask, however. > > > > Any advice appreciated. > > > I think Python Cookbook has a recipe which deals with this. > > - 6.12 Checking an Instance for Any State Change. > > Were you able to get this? If not, let me know. I will try to type it > in here - (it is a big recipe, so not doing it now) Actually, I have the python cookbook, but cannot find the recipe you mention. maybe I have an older version? thanks. From pdorange at pas-de-pub-merci.mac.com Wed Jan 28 12:43:04 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 28 Jan 2009 18:43:04 +0100 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <1iu9nv4.ggxia541w0N%pdorange@pas-de-pub-merci.mac.com> joseph.a.marlin at gmail.com wrote: > Greetings! I've heard enough raving about Python, I'm going to see for > myself what all the praise is for! > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? > > Any recommendations on open source Python environments? I'm new to python, i began with IDLE, but then switch to TextWrangler+Terminal i prefer. Now i also try XCode (not opensource, but free from Apple) just as a text editor and still terminal, fine. Xcode editor is good for me. I try to use Python directly from Xcode but i do not understand the right way to do this. There is project for PyObjC but a can't make working directly simple script project, so i continue to use terminal... -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From koranthala at gmail.com Wed Jan 28 12:49:37 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 28 Jan 2009 09:49:37 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> Message-ID: <52018aea-b706-444e-a820-bd262cacf29d@y23g2000pre.googlegroups.com> On Jan 28, 10:39?pm, Reckoner wrote: > On Jan 28, 9:16 am, koranthala wrote: > > > > > On Jan 28, 5:42 pm, koranthala wrote: > > > > On Jan 28, 2:16 am, Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > > > a list of ?objects > > > > > A=[a,b,c,d,...,z] > > > > > where, ?in the midst of a lot of processing I might do something like, > > > > > A[0].do_something_which_changes_the_properties() > > > > > which alter the properties of the object 'a'. > > > > > The trick is that I would like A to be mysteriously aware that > > > > something about the ?object 'a' has changed so that when I revisit A, > > > > I will know that the other items in the list need to be refreshed to > > > > reflect the changes in A as a result of changing 'a'. > > > > > Even better would be to automatically percolate the subsequent changes > > > > that resulted from altering 'a' for the rest of the items in the list. > > > > Naturally, all of these items are related in some parent-child > > > > fashion. > > > > > that might be a lot to ask, however. > > > > > Any advice appreciated. > > > > I think Python Cookbook has a recipe which deals with this. > > > - 6.12 Checking an Instance for Any State Change. > > > Were you able to get this? If not, let me know. I will try to type it > > in here - (it is a big recipe, so not doing it now) > > Actually, I have the python cookbook, but cannot find the recipe you > mention. maybe I have an older version? > > thanks. Mine is 2nd Edition. From excord80 at gmail.com Wed Jan 28 12:53:18 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:53:18 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <49802c05$0$5139$426a34cc@news.free.fr> Message-ID: <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> On Jan 28, 4:57?am, Bruno Desthuilliers wrote: > > What about:http://thraxil.org/code/cgi_app/ > > (yes, it is a port of CGI::Application, and FWIW it's mentionned on the > CGI::Application's wiki). > Nice find. Thank you. Interesting project. It seems to be only one fairly short file (perhaps that's all it takes), and its most recent release was in 2004. No mailing list. From steve at holdenweb.com Wed Jan 28 12:55:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 28 Jan 2009 12:55:43 -0500 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden > escribi?: >> Gabriel Genellina wrote: >>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>> escribi?: > >>> I *thought* I did understand this until I came to this example: >>> >>> 1) >>>>>> id(globals()), id(locals()) >>> (11239760, 11239760) >>> >>> # ok, globals and locals are the same at the module level >>> >>> 2) >>>>>> s = "(id(n) for n in [globals(),locals()])" >>>>>> list(eval(s)) >>> [11239760, 11239760] # still the same results >>> >>> 3) >>>>>> s = "(id(n()) for n in [globals,locals])" >>>>>> list(eval(s)) >>> [11239760, 12583248] # locals() is different >>> >> No, locals is different, not locals(). You are looking at two different >> functions that return the same object when called in the given context, >> that's all. > > Perhaps you didn't notice that I shifted the () from right to left. I'm > always printing the result of *calling* globals and locals -- the only > change is *where* I do call them. > Ah, right. As you were ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From excord80 at gmail.com Wed Jan 28 12:56:12 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:56:12 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> On Jan 28, 5:05?am, Jeroen Ruigrok van der Werven wrote: > > Werkzeug[1] should be in your line, I think. > > [1]http://werkzeug.pocoo.org/ > Again, the solution must work for plain vanilla CGI. I don't have WSGI available. But thank you. From excord80 at gmail.com Wed Jan 28 12:58:34 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 09:58:34 -0800 (PST) Subject: small python-cgi wiki? References: Message-ID: <436cc75e-f86e-4ee1-98a4-d6681337c59b@g1g2000pra.googlegroups.com> On Jan 28, 12:02?pm, Bernard Rankin wrote: > > I'm looking to set up a small private wiki, and am looking for recommendations. > > Some sort of CGI based package that I could just untar somewhere web accessable via Apache would be great. There are a number of them listed at http://wiki.python.org/moin/PythonWikiEngines . You might have a look at PikiPiki. From Scott.Daniels at Acm.Org Wed Jan 28 13:00:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 28 Jan 2009 10:00:43 -0800 Subject: Why doesn't eval of generator expression work with locals? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden > escribi?: >> Gabriel Genellina wrote: >>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>> escribi?: > >>> I *thought* I did understand this until I came to this example: >>> >>> 1) >>>>>> id(globals()), id(locals()) >>> (11239760, 11239760) This is a bad test. We know distinct objects are distinct, but: >>> print id(object()), id(object()) 10598120 10598120 >>> a = object(); b = object() >>> print id(a), id(b) 10598120 10598128 The reason is that once your created object has its id taken, you must keep a handle on it, otherwise it may get recycled and reused. That is, id(var1) == id(var2) implies var1 is var2, but id(expr1) == id(expr2) does not even imply expr1 == expr2 --Scott David Daniels Scott.Daniels at Acm.Org From alecla at bluewin.ch Wed Jan 28 13:02:39 2009 From: alecla at bluewin.ch (alex) Date: Wed, 28 Jan 2009 10:02:39 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> Message-ID: <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Jon Thank you for your answer. I tried it with no success. However I tried with tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") and it runs now with no error message, I can't figure for now why, but it's great! This is motivating for going ahead. Regards Alex From coutinhotiago at gmail.com Wed Jan 28 13:05:39 2009 From: coutinhotiago at gmail.com (coutinhotiago at gmail.com) Date: Wed, 28 Jan 2009 10:05:39 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Hi! I had the same problem myself. Mark's detailed explanation really helped me understand. I ended up doing something like: class A: def __init__(self): names = 'n1', 'n2' for n in names: setattr(self, "get%s" % n, self._createGetter(n)) def _createGetter(self, n): def f(): return n return f Thanks a lot Cheers, Tiago From martin at v.loewis.de Wed Jan 28 13:13:00 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 28 Jan 2009 19:13:00 +0100 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Message-ID: <4980a02c$0$25198$9b622d9e@news.freenet.de> > But the document also mentions that the result is not strictly > "undefined" but "reproducable undetermined". What specific document are you looking at, and where specifically does it say that? I can't believe that the quotation marks indicate an actual quote, in particular because "reproducible" is misspelled. In any case, I can't find anything like that in the 3.0 changes document, and, given that the comparison *does* give an exception, any statement that the result is undetermined would be false. Regards, Martin From schap at offenbachers.com Wed Jan 28 13:21:29 2009 From: schap at offenbachers.com (Stephen Chapman) Date: Wed, 28 Jan 2009 13:21:29 -0500 Subject: Quickbooks Message-ID: <4980A229.1040606@offenbachers.com> Has anyone Implemented the Quickbooks COM object in Python. If so can you give me an Idea of where to begin. Thanks From rridge at csclub.uwaterloo.ca Wed Jan 28 13:29:08 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Jan 2009 13:29:08 -0500 Subject: unable to print Unicode characters in Python 3 References: <497F58C3.6020209@v.loewis.de> <6537f69d-eb87-4377-9d22-cb05e852e843@k1g2000prb.googlegroups.com> Message-ID: John Machin writes: > The only font choice offered apart from "Raster Fonts" in the Command > Prompt window's Properties box is "Lucida Console", not "Lucida Sans > Unicode". It will let me print Cyrillic characters from a C program, > but not Chinese. I'm off looking for how to get a better font. Thorsten Kampe wrote: >I have >[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont] >"00"="DejaVu Sans Mono" As near as I can tell the DejaVu Sans Mono font doesn't include Chinese characters. If you want to display Chinese characters in a console window on Windows you'll probably have change the (global) system locale to an appropriate Chinese locale and reboot. Note that a complete Unicode console font is essentially an impossibility, so don't bother looking for one. There are many characters in Unicode that can't be reasonably mappped to a single fixed-width "console" glyph. There are also characters in Unicode that should be represented as single-width gylphs in Western contexts, but as double-width glyphs in Far-Eastern contexts. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From Scott.Daniels at Acm.Org Wed Jan 28 13:33:04 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 28 Jan 2009 10:33:04 -0800 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> Message-ID: towitowi at gmail.com wrote: > Hello, > > In the 3.0 changes list there is mentioned that "<"-compares are not > supported anymore if the compared types are different (except > numbers). Like > 42 < "Hello" > did return True of False depending on the implementation but is now a > TypeError. > > But the document also mentions that the result is not strictly > "undefined" but "reproducable undetermined". Meaning, that on a given > machine with a given python implementation result will always be the > same. But on another machine, or with another python implementation, > it might give a different result. > > My question now is, why this is? E.g, Is there an integer large enough > so that the result changes? What circumstances influence the result? The ordering of ints and strings may vary between python builds, but _any_ strings will have the same relationship to _any_ integers. That is, (str(x) < int(y)) == (str(y) < int(x)) for any x and y that don't cause exceptions. The types are compared before the values for sufficiently disparate types without accomodation in the comparison methods. This means the 2.X python series can sort more lists, but the sort order is not a particularly useful one (except for the fact that there is an order). --Scott David Daniels Scott.Daniels at Acm.Org From asmodai at in-nomine.org Wed Jan 28 13:33:55 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Wed, 28 Jan 2009 19:33:55 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> Message-ID: <20090128183355.GR99614@nexus.in-nomine.org> -On [20090128 19:01], excord80 (excord80 at gmail.com) wrote: >Again, the solution must work for plain vanilla CGI. I don't have WSGI >available. But thank you. It works for plain CGI. I myself use it for FCGI. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From reckoner at gmail.com Wed Jan 28 14:06:21 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 28 Jan 2009 11:06:21 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Jan 27, 9:46 pm, Steven D'Aprano wrote: > On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote: > > I'm not sure this is possible, but I would like to have a list of > > objects > > > A=[a,b,c,d,...,z] > > > where, in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that something > > about the object 'a' has changed so that when I revisit A, I will know > > that the other items in the list need to be refreshed to reflect the > > changes in A as a result of changing 'a'. > > Can't be done if A is a built-in list, probably can't be done entirely > generically, but you can probably do it in a cooperative manner. > > class TaintList(list): > tainted = False > def taint(self): > self.tainted = True > def untaint(self): > self.tainted = False > > A = TaintList() > > import functools > def taint(parent): > def decorator(func): > @functools.wraps(func) > def f(*args, **kwargs): > parent.taint() > return func(*args, **kwargs) > return f > return decorator > > class TaintAwareThing(object): > def __init__(self): > self.attr = 0 > @taint(A) > def change_attribute(self, x): > self.attr = x > > >>> x = TaintAwareThing() > >>> y = TaintAwareThing() > >>> z = TaintAwareThing() > > >>> A.extend([x, y, z]) > >>> A.tainted > False > >>> x.change_attribute(5) > >>> A.tainted > > True > > Here is a second approach: create a proxy class TaintThing that wraps > whatever object you want, using delegation: > > class TaintThing(object): > parent = A > def __init__(self, obj): > self.__dict__['_proxy'] = obj > def __getattr__(self, attr): > return getattr(self._proxy, attr) > def __setattr__(self, attr, value): > setattr(self._proxy, attr, value) > self.parent.taint() > > Now change TaintList to automatically wrap anything stored in it: > > # untested > class TaintList(list): > def append(self, obj): > list.append(self, TaintThing(obj)) > # similar for __setitem__, extend, insert > > -- > Steven thanks for your reply. For the second case where > class TaintThing(object): > parent = A > def __init__(self, obj): > self.__dict__['_proxy'] = obj > def __getattr__(self, attr): > return getattr(self._proxy, attr) > def __setattr__(self, attr, value): > setattr(self._proxy, attr, value) > self.parent.taint() you have told it that parent is 'A'. Shouldn't that be passed to it somehow in the following: > # untested > class TaintList(list): > def append(self, obj): > list.append(self, TaintThing(obj)) > # similar for __setitem__, extend, insert I apologize. I am probably missing something. This is getting pretty advanced for me. Thanks again. From blank at empty.blank Wed Jan 28 14:14:08 2009 From: blank at empty.blank (RGK) Date: Wed, 28 Jan 2009 14:14:08 -0500 Subject: Profiling Python Apps on Mac? Message-ID: I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & wxPython under OSX 10.4) As I make program architecture decisions, it would be nice to be able to profile the choices. Should I add that extra thread? Is this big-assed xml object I just created horribly bloated or kind of ordinary. Is there anything out there I should look into to if I want to see how those things are affecting my app? The closest I have is the widget iStat, but it's a very static low resolution view of what's really going on. Thx in advance. Ross. From philip at semanchuk.com Wed Jan 28 14:22:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 28 Jan 2009 14:22:18 -0500 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: <6149BE30-6C81-4368-AA71-74DA5430E604@semanchuk.com> On Jan 28, 2009, at 2:14 PM, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be > able to profile the choices. Should I add that extra thread? Is > this big-assed xml object I just created horribly bloated or kind of > ordinary. > > Is there anything out there I should look into to if I want to see > how those things are affecting my app? The closest I have is the > widget iStat, but it's a very static low resolution view of what's > really going on. Is there any reason that this wouldn't work? http://docs.python.org/library/hotshot.html From excord80 at gmail.com Wed Jan 28 14:32:25 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 11:32:25 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> Message-ID: <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> On Jan 28, 1:33?pm, Jeroen Ruigrok van der Werven wrote: > -On [20090128 19:01], excord80 (excor... at gmail.com) wrote: > > >Again, the solution must work for plain vanilla CGI. I don't have WSGI > >available. But thank you. > > It works for plain CGI. I myself use it for FCGI. Thanks, Jeroen. After looking at the Werkzeug "deploying" page, it seems as though one is able to write a WSGI webapp and have it work via CGI using something called wsgiref. Sounds good. If that's correct, it would be great if there were a Werkzeug tutorial on deploying it for use with CGI. Will look into wsgiref and Werkzeug. Thanks! From gagsl-py2 at yahoo.com.ar Wed Jan 28 14:48:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 17:48:14 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels escribi?: > Gabriel Genellina wrote: >> En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden >> escribi?: >>> Gabriel Genellina wrote: >>>> En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern >>>> >>>> escribi?: >> >>>> I *thought* I did understand this until I came to this example: >>>> >>>> 1) >>>>>>> id(globals()), id(locals()) >>>> (11239760, 11239760) > This is a bad test. We know distinct objects are distinct, but: > >>> print id(object()), id(object()) > 10598120 10598120 > > >>> a = object(); b = object() > >>> print id(a), id(b) > 10598120 10598128 > > The reason is that once your created object has its id taken, you > must keep a handle on it, otherwise it may get recycled and reused. It doesn't matter in this case, I think. globals() is always the same object and is alive during the whole test. So something having the same id() than globals() must be the very same object, and something having a different id() than globals() cannot be the same object. If you like, I can rewrite the example without using id(): >>> L = list(n for n in [globals(),locals()]) >>> L[0] is L[1] True >>> L = list(n() for n in [globals,locals]) >>> L[0] is L[1] False (I *think* this has to do with free variables in the "right side" (after the "in" keyword) of a generator expression; they appear to be evaluated when the expression is *defined*, not when is is *used*. By contrast, free variables in the "left side" appear to be evaluated when the expression is used.) -- Gabriel Genellina From blank at empty.blank Wed Jan 28 15:00:36 2009 From: blank at empty.blank (RGK) Date: Wed, 28 Jan 2009 15:00:36 -0500 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: Philip Semanchuk wrote: > > Is there any reason that this wouldn't work? > > http://docs.python.org/library/hotshot.html It suggests that it doesn't work well with threads, but as I didn't know about any options, it's a step forward. Thanks for the pointer. :) R. From __peter__ at web.de Wed Jan 28 15:06:01 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Jan 2009 21:06:01 +0100 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: Gabriel Genellina wrote: >>>> L = list(n for n in [globals(),locals()]) >>>> L[0] is L[1] > True >>>> L = list(n() for n in [globals,locals]) >>>> L[0] is L[1] > False > > (I think this has to do with free variables in the "right side" (after > the "in" keyword) of a generator expression; they appear to be evaluated > when the expression is *defined*, not when is is *used*. By contrast, free > variables in the "left side" appear to be evaluated when the expression is > used.) Indeed, the right side is evaluated in the enclosing namespace and then passed as an argument to the genexpr: >>> dis.dis(compile("(x for y in z)", "nofile", "exec")) 1 0 LOAD_CONST 0 ( at 0x2b22b2dcf828, file "nofile", line 1>) 3 MAKE_FUNCTION 0 6 LOAD_NAME 0 (z) 9 GET_ITER 10 CALL_FUNCTION 1 13 POP_TOP 14 LOAD_CONST 1 (None) 17 RETURN_VALUE Peter From xnews2 at fredp.lautre.net Wed Jan 28 15:10:29 2009 From: xnews2 at fredp.lautre.net (Fred Pacquier) Date: 28 Jan 2009 20:10:29 GMT Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: excord80 said : >> What are you looking for in your framework? > > Well, let's see. I don't need a templating library, since -- as you > pointed out -- I can just use Python's own. I don't need a db > interface (can just make my own dbapi calls if needed). Don't need url > mapping (can just use mod_rewrite rules in my .htaccess to point at my > cgi scripts). Don't think I need any i80n. And I don't need an admin > interface. ... It would seem that I don't need a whole lot at the > moment. That would be something close to Karrigell... From petite.abeille at gmail.com Wed Jan 28 15:12:12 2009 From: petite.abeille at gmail.com (Petite Abeille) Date: Wed, 28 Jan 2009 21:12:12 +0100 Subject: small python-cgi wiki? In-Reply-To: <889572.28267.qm@web112204.mail.gq1.yahoo.com> References: <889572.28267.qm@web112204.mail.gq1.yahoo.com> Message-ID: On Jan 28, 2009, at 6:02 PM, Bernard Rankin wrote: > I'm looking to set up a small private wiki, and am looking for > recommendations. > > Some sort of CGI based package that I could just untar somewhere web > accessable via Apache would be great. You might be interested by Nanoki, a small, simple wiki engine. Online demo: http://svr225.stepx.com:3388/search?q=python http://svr225.stepx.com:3388/nanoki One thing though... it's not Python :) Cheers, -- PA. http://alt.textdrive.com/nanoki/ From rt8396 at gmail.com Wed Jan 28 15:17:31 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 12:17:31 -0800 (PST) Subject: What is intvar? [Python Docs] References: <25kel.9400$pr6.4685@flpi149.ffdc.sbc.com> <3f7062b1-bbcb-4cff-b336-5c70563f3f2d@p36g2000prp.googlegroups.com> Message-ID: On Jan 26, 11:15?am, "W. eWatson" wrote: > I might be repeating myself here, but If anyone has pdf experience, and > could provide page numbers and maybe a TOC for some of Lundh's > contributions, that would be helpful. Did you try this one? http://effbot.org/tkinterbook/tkinter-index.htm here is the older less detailed version: http://www.pythonware.com/library/tkinter/introduction/ neither are PDF thought. But NMT has a PDF download here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/ From bjracine at glosten.com Wed Jan 28 15:20:30 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Wed, 28 Jan 2009 12:20:30 -0800 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <33d59aa0-e73b-45f8-bdfe-4c78717c68f7@v5g2000prm.googlegroups.com> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8C077@clipper.glosten.local> I've tried Wing IDE professional, vim, textmate, and PyDev and am intrigued by each one for different reasons. Whichever module browser I get more comfortable between Wing and PyDev/Eclipse is probably the direction I will end up going. Further, if I get the Hg and SVN plugins for PyDev/Eclipse up and running, I think I will probably go in that direction, but will probably still need to use a wxPython GUI constructor like BOA or Glade. I have vim key-bindings in all four, so at least I don't fumble over that. I really haven't been able to decide yet... You could go to showmedo.com in order to see ipython, wing and pydev/eclipse all in action. HTH, Ben -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of joseph.a.marlin at gmail.com Sent: Tuesday, January 27, 2009 4:14 PM To: python-list at python.org Subject: Re: New to python, open source Mac OS X IDE? On Jan 27, 6:47?pm, Andr? wrote: > On Jan 27, 7:06?pm, "joseph.a.mar... at gmail.com" > > wrote: > > Greetings! I've heard enough raving about Python, I'm going to see > > for myself what all the praise is for! > > > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > > even use an IDE for Python? > > If you already use netbeans, what > abouthttp://www.netbeans.org/features/python/ > ? > Wow, you guys are fast... yes, I was having trouble deciding between that (Netbeans), Smultron, or TextWrangler. Thanks! -- http://mail.python.org/mailman/listinfo/python-list From ocschwar at gmail.com Wed Jan 28 15:38:17 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 12:38:17 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. Message-ID: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Hi, all. I have an application that that creates, manipulates, and finally archives on disk 10^6 instances of an object that in CS/DB terms is best described as a relation. It has 8 members, all of them common Python datatypes. 6 of these are set once and then not modified. 2 are modified around 4 times before the instance's archving. Large collections (of small lists) of these objects are created, iterated through, and sorted using any and all of the 8 members as sorting keys. It neither has nor needs custom methods. I used a simple dictionary to create the application prototype. Now I need to speed things up. I first tried changing to a new style class, with __slots__, __init__, __getstate__& __setstate__ (for pickling) and was shocked to see things SLOW down over dictionaries. So of these options, where should I go first to satisfy my need for speed? 0. Back to dict 1. old style class 2. new style class 3. new style class, with __slots__, with or without some nuance I'm missing. 4. tuple, with constants to mark the indices 5. namedTuple 6. other... From akineko at gmail.com Wed Jan 28 15:46:56 2009 From: akineko at gmail.com (akineko) Date: Wed, 28 Jan 2009 12:46:56 -0800 (PST) Subject: Terminating a Python program that uses multi-process, multi-threading Message-ID: Hello Python experts, I have a program that uses three processes (invoked by multiprocessing) and several threads. The program is terminated when ^C is typed (KeyboardInterrupt). The main process takes the KeyboardInterrupt Exception and it orderly shutdown the program. It works fine in normal situation. However, KeyboardInterrupt is not accepted when, for example, the program is stuck somewhere due to error in network. I understand that the KeyboardInterrupt won't be processed until the program moves out from an atomic step in a Python program. Probably this is partly my fault as I use some blocking statements (without timeout) as they should not block the program in normal situation. As the program freezes up, I cannot do anything except killing three processes using kill command. So, I cannot tell which statement is actually blocking when this occurs (and there are many suspects). Is there any good way to deal with this kind of problem? Killing three processes when it hangs is not a fun thing to do. Any suggestions will be greatly appreciated. Best regards, Aki Niimura From rtw at freenet.co.uk Wed Jan 28 15:51:20 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 28 Jan 2009 14:51:20 -0600 Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 @b38g2000prf.googlegroups.com in comp.lang.python: > > I have mingw32-gcc in my path. If I try that too -it fails. > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > "mingw32-gcc" > invalid command name 'mingw32-gcc' > All the examples I found via google have the tool name as "mingw32" so try: python setup.py install -c mingw32 or python setup.py build --compiler=mingw32 install The compiler that the MinGW package installs is gcc. You shoulf be able to verify it is on your path by typing: gcc --help or gcc --version and see some output. Rob. -- http://www.victim-prime.dsl.pipex.com/ From s.selvamsiva at gmail.com Wed Jan 28 15:55:21 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 29 Jan 2009 02:25:21 +0530 Subject: date handling problem Message-ID: Hi all, I need to parse rss-feeds based on time stamp,But rss-feeds follow different standards of date(IST,EST etc). I dont know,how to standardize this standards.It will be helpful if you can hint me. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From excord80 at gmail.com Wed Jan 28 16:02:47 2009 From: excord80 at gmail.com (excord80) Date: Wed, 28 Jan 2009 13:02:47 -0800 (PST) Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <36a98419-c111-440b-84a3-177c6b126936@w24g2000prd.googlegroups.com> On Jan 28, 3:10?pm, Fred Pacquier wrote: > > That would be something close to Karrigell... You know, I stumbled across Karrigell while looking around but was initially uninterested because of what initially seems like a lack of direction. That is, they tell you that you can use it any way you like: * python script * K service * html inside python * python inside html * cgi script So, I wasn't sure what to make of that. However, perhaps it's a strength... will have to look more into K. Thanks. From google at mrabarnett.plus.com Wed Jan 28 16:11:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 21:11:04 +0000 Subject: Terminating a Python program that uses multi-process, multi-threading In-Reply-To: References: Message-ID: <4980C9E8.7030001@mrabarnett.plus.com> akineko wrote: > Hello Python experts, > > I have a program that uses three processes (invoked by > multiprocessing) and several threads. > The program is terminated when ^C is typed (KeyboardInterrupt). > The main process takes the KeyboardInterrupt Exception and it orderly > shutdown the program. > > It works fine in normal situation. > > However, KeyboardInterrupt is not accepted when, for example, the > program is stuck somewhere due to error in network. I understand that > the KeyboardInterrupt won't be processed until the program moves out > from an atomic step in a Python program. > > Probably this is partly my fault as I use some blocking statements > (without timeout) as they should not block the program in normal > situation. > > As the program freezes up, I cannot do anything except killing three > processes using kill command. > So, I cannot tell which statement is actually blocking when this > occurs (and there are many suspects). > > Is there any good way to deal with this kind of problem? > Killing three processes when it hangs is not a fun thing to do. > > Any suggestions will be greatly appreciated. > The scripts could write to a log around where they could block (write to the log just before and just after), so that you can then see where they blocked. A hacky way of killing the processes would be for the processes to write their process IDs to the log and then you can write another script which will parse the log to get the process IDs and then kill the processes with those IDs. (Left as an exercise for the reader. :-)) From xahlee at gmail.com Wed Jan 28 16:32:29 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 28 Jan 2009 13:32:29 -0800 (PST) Subject: Function Application is not Currying Message-ID: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Function Application is not Currying Xah Lee, 2009-01-28 In Jon Harrop's book Ocaml for Scientist at http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html It says: Currying A curried function is a function which returns a function as its result. LOL. That is incorrect. Here are some examples of a function that returns a function as result, but is not currying. Mathematica example: f[n_]:=Function[n^#]; f[7][2] (* returns 49 *) Emacs lisp example: (defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) ) (funcall (f 7) 2) Perl example: sub f {$n=$_[0]; sub { $n ** $_[0]} }; print &{ f(7) } (2); Javascript example: function f(n) {return function (x) {return Math.pow(x,n);}; } alert (f(7) (2)); In the above, a function returns a function, and the result function is applied to a value. They demonstrate 2 things: * The ability of the lang to have a function that returns a function. * The ability to apply a value (of type function) to a value. These, are 2 of the features that is part of often sloppily termed as ?function as first class citizens?. However, the above are not languages that support currying, which is a feature that Haskell & Ocaml has. So what is Currying? Wikipedia article Currying said it best: In computer science, currying, invented by Moses Sch?nfinkel and Gottlob Frege, and independently by Haskell Curry,[1] is the technique of transforming a function that takes multiple arguments (or more accurately an n-tuple as argument) in such a way that it can be called as a chain of functions each with a single argument. Note how it says ?is the technique of ...?. To be more concrete, in the context of a given computer language, to say that it support curring, is to mean that the compiler understand the concept to certain degree. More to the point, the language is inherently able to take a function of more than one arg and deconstruct it to several functions of single arg. To say that function returning function is Currying, is a confusion of fundamental concepts. Mathematically, currying is the concept of deconstructing a function of multiple parameters to a composition of several functions all of arity 1. I like Jon, because i consider majority of his argument and perspective are more correct or sensible in his trollish spats in newsgroup fighting with tech geekers. But he is really a asshole, and take every chance to peddle his book. Every mother fucking opponitunity, he injects random opinion into discussions about how static typing or greatness of Microsoft, which paves a way for him to post a link to his book on Ocaml/F# or ?study? or ?speed comparison? of his site. He does this repeatedly and intentionally, about every week for the past 2 or so years, and write in a way to provoke irate responses. In the past 2 or 3 years, i have for 2 or so times without his or anyone's solicitation, publically supported him in ugly newsgroup fights (such as some serious sounding post that accuse him of spamming or or some real life threats about network abuse). However, in the past year as i have had some debates on language issues with jon, i find Jon to be a complete asshole as far as his newsgroup demeanor goes. PS see also: A Mathematica Optimization Problem ( story of a thread where Jon started a fight with me ) Perm url for this post: ? Function Application is not Currying http://xahlee.org/UnixResource_dir/writ/apply_func_examples.html Xah ? http://xahlee.org/ ? From rNOSPAMon at flownet.com Wed Jan 28 16:35:56 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 13:35:56 -0800 Subject: Sloooooowwwww WSGI restart Message-ID: I'm running a WSGI app under apache/mod_wsgi and I've noticed that whenever I restart the server after making a code change it takes a very long time (like a minute) before the script is active again. In other words, I do an apachectl restart, reload the page in my browser, and one minute later it finally comes up. During this time CPU usage is essentially zero. Loading all the code manually into a python interpreter is virtually instantaneous, and all subsequence interactions with the app are very fast. Does anyone have any ideas what might be going on or how to debug this? Thanks, rg From exarkun at divmod.com Wed Jan 28 16:44:05 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 16:44:05 -0500 Subject: Sloooooowwwww WSGI restart In-Reply-To: Message-ID: <20090128214405.24460.1545518426.divmod.quotient.3405@henry.divmod.com> On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret wrote: >I'm running a WSGI app under apache/mod_wsgi and I've noticed that >whenever I restart the server after making a code change it takes a very >long time (like a minute) before the script is active again. In other >words, I do an apachectl restart, reload the page in my browser, and one >minute later it finally comes up. During this time CPU usage is >essentially zero. Loading all the code manually into a python >interpreter is virtually instantaneous, and all subsequence interactions >with the app are very fast. > >Does anyone have any ideas what might be going on or how to debug this? strace is nice. It sounds like some blocking network operation. rdns can often cause things like this. If you're lucky, strace will point right at the problem. Jean-Paul From alex at a13x.net Wed Jan 28 16:44:44 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Wed, 28 Jan 2009 21:44:44 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <845b10c50901281344k4e76cc93w69fed1c33c47a7ad@mail.gmail.com> Hi there, On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > I'm running a WSGI app under apache/mod_wsgi and I've noticed that Off the bat, there's no reason to run an app under apache/mod_wsgi while developing it, ie. if u use Pylons or TurboGears, there's an easier way to serve the app (using paster or cherrypy). Secondly, why are you restarting apache after code changes? In normal circumstances, you shouldn't have to do that. -- a lex 13 x http://www.a13x.info From castironpi at gmail.com Wed Jan 28 16:45:19 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 13:45:19 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 28, 10:13?am, perfr... at gmail.com wrote: > hello all, > > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, snip > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. There is the 'shelve' module. You could create a shelf that tells you the filename of the 5 other ones. A million keys should be no problem, I guess. (It's standard library.) All your keys have to be strings, though, and all your values have to be pickleable. If that's a problem, yes you will need ZODB or Django (I understand), or another relational DB. From alex at a13x.net Wed Jan 28 16:49:40 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Wed, 28 Jan 2009 21:49:40 +0000 Subject: New to python, open source Mac OS X IDE? In-Reply-To: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <845b10c50901281349q5cf2c554n7044c53693a10b64@mail.gmail.com> On Tue, Jan 27, 2009 at 11:06 PM, joseph.a.marlin at gmail.com wrote: > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? I'm on a Mac, too. I don't use a full-fledged IDE for Python development, nor I think it's necessary. > Any recommendations on open source Python environments? Komodo Edit looks very professional and very usable. Other alternatives are PyDev w/ Eclipse, but I opted for TextMate - it has excellent features. I highly recommend spending ~$50 on it, it's money well spent. -- a lex 13 x http://www.a13x.info From castironpi at gmail.com Wed Jan 28 16:50:33 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 13:50:33 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Message-ID: <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: > Hi, all. > > I have an application that that creates, manipulates, and finally > archives on disk 10^6 instances of an object that in CS/DB terms is > best described as a relation. > > It has 8 members, all of them common Python datatypes. 6 of these are > set once and then not modified. 2 are modified around 4 times before > the instance's archving. Large collections (of small lists) of these > objects are created, iterated through, and sorted using any and all of > the 8 members as sorting keys. > > It neither has nor needs custom methods. > > I used a simple dictionary to create the application prototype. Now I > need to speed things up. > I first tried changing to a new style class, with __slots__, __init__, > __getstate__& __setstate__ (for pickling) and was shocked to see > things SLOW down over dictionaries. > > So of these options, where should I go first to satisfy my need for > speed? > > 0. Back to dict > 1. old style class > 2. new style class > 3. new style class, with __slots__, with or without some nuance I'm > missing. > 4. tuple, with constants to mark the indices > 5. namedTuple > 6. other... Hello, quoting myself from another thread today: There is the 'shelve' module. You could create a shelf that tells you the filename of the 5 other ones. A million keys should be no problem, I guess. (It's standard library.) All your keys have to be strings, though, and all your values have to be pickleable. If that's a problem, yes you will need ZODB or Django (I understand), or another relational DB. There is currently no way to store live objects. From sjmachin at lexicon.net Wed Jan 28 17:14:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 14:14:36 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: On Jan 29, 3:13?am, perfr... at gmail.com wrote: > hello all, > > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > 'world'}, ...], > ? ? ? ? ? ? ? ? key2: [...]} > > in total there are about 10 to 15 million lists if we concatenate > together all the values of every key in 'mydict'. mydict is a > structure that represents data in a very large file (about 800 > megabytes). > > what is the fastest way to pickle 'mydict' into a file? right now i am > experiencing a lot of difficulties with cPickle when using it like > this: > > from cPickle import pickle > pfile = open(my_file, 'w') > pickle.dump(mydict, pfile) > pfile.close() > > this creates extremely large files (~ 300 MB) though it does so > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > it gets slower and slower. it takes almost an hour if not more to > write this pickle object to file. > > is there any way to speed this up? i dont mind the large file... after > all the text file with the data used to make the dictionary was larger > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > i do care about speed... > > i have tried optimizing this by using this: > > s = pickle.dumps(mydict, 2) > pfile.write(s) > > but this takes just as long... any ideas ? is there a different module > i could use that's more suitable for large dictionaries ? > thank you very much. Pardon me if I'm asking the "bleedin' obvious", but have you checked how much virtual memory this is taking up compared to how much real memory you have? If the slowness is due to pagefile I/O, consider doing "about 10" separate pickles (one for each key in your top-level dictionary). From tjreedy at udel.edu Wed Jan 28 17:15:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Jan 2009 17:15:31 -0500 Subject: Python 3.0, 'Hello' < 42 In-Reply-To: <4980a02c$0$25198$9b622d9e@news.freenet.de> References: <311c2765-4f2d-47ae-b4f5-4894d070cca0@v39g2000pro.googlegroups.com> <4980a02c$0$25198$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> But the document also mentions that the result is not strictly >> "undefined" but "reproducable undetermined". > > What specific document are you looking at, and where specifically > does it say that? I can't believe that the quotation marks indicate > an actual quote, in particular because "reproducible" is misspelled. I believe there was something like that in the 2.x docs but nothing in the Expressions / Comparisons section of 3.0. > > In any case, I can't find anything like that in the 3.0 changes > document, and, given that the comparison *does* give an exception, > any statement that the result is undetermined would be false. From deets at nospam.web.de Wed Jan 28 17:21:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 28 Jan 2009 23:21:09 +0100 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> Message-ID: <6uc42lFcmn4iU1@mid.uni-berlin.de> ocschwar at gmail.com schrieb: > Hi, all. > > I have an application that that creates, manipulates, and finally > archives on disk 10^6 instances of an object that in CS/DB terms is > best described as a relation. > > It has 8 members, all of them common Python datatypes. 6 of these are > set once and then not modified. 2 are modified around 4 times before > the instance's archving. Large collections (of small lists) of these > objects are created, iterated through, and sorted using any and all of > the 8 members as sorting keys. > > It neither has nor needs custom methods. > > I used a simple dictionary to create the application prototype. Now I > need to speed things up. > I first tried changing to a new style class, with __slots__, __init__, > __getstate__& __setstate__ (for pickling) and was shocked to see > things SLOW down over dictionaries. > > So of these options, where should I go first to satisfy my need for > speed? > > 0. Back to dict > 1. old style class > 2. new style class > 3. new style class, with __slots__, with or without some nuance I'm > missing. > 4. tuple, with constants to mark the indices > 5. namedTuple > 6. other... Use a database? Or *maybe* a C-extension wrapped by ctypes. Diez From gagsl-py2 at yahoo.com.ar Wed Jan 28 17:32:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 20:32:27 -0200 Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: En Wed, 28 Jan 2009 16:05:39 -0200, coutinhotiago at gmail.com escribi?: > I had the same problem myself. > Mark's detailed explanation really helped me understand. > > I ended up doing something like: The code doesn't work as-is, could you please post a working version? Just for the record, so people reading this thread later don't get confused. -- Gabriel Genellina From tutufan at gmail.com Wed Jan 28 17:33:33 2009 From: tutufan at gmail.com (Mike) Date: Wed, 28 Jan 2009 14:33:33 -0800 (PST) Subject: what's the point of rpython? References: <6899e15d-951d-4d52-945f-c4943fea50c2@w1g2000prm.googlegroups.com> Message-ID: <62b51c07-614d-4963-be31-c5826abf1b21@40g2000prx.googlegroups.com> On Jan 17, 5:55?pm, "Brendan Miller" wrote: > The python devs seem to > consider the GIL a non-issue, though they may change their mind in 3 > years when we all have 32 core desktops, For what it's worth, I am currently using Python to perform a scientific computation on 1400+ cores, and it seems to work fairly well. (http://greylag.org/ if you're curious.) There are a number of things that annoy me about Python (even though it's my favorite everyday language), but the GIL isn't among them. The rare cases where the GIL is truly a problem can be balanced against the large majority where threading is simply inappropriate anyway. That the latter might help compulsive threaders kick their habit (or at least head for more convoluted horizons) might be considered a virtue. Mike From perfreem at gmail.com Wed Jan 28 17:43:16 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Wed, 28 Jan 2009 14:43:16 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> On Jan 28, 5:14?pm, John Machin wrote: > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > hello all, > > > i have a large dictionary which contains about 10 keys, each key has a > > value which is a list containing about 1 to 5 million (small) > > dictionaries. for example, > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > 'world'}, ...], > > ? ? ? ? ? ? ? ? key2: [...]} > > > in total there are about 10 to 15 million lists if we concatenate > > together all the values of every key in 'mydict'. mydict is a > > structure that represents data in a very large file (about 800 > > megabytes). > > > what is the fastest way to pickle 'mydict' into a file? right now i am > > experiencing a lot of difficulties with cPickle when using it like > > this: > > > from cPickle import pickle > > pfile = open(my_file, 'w') > > pickle.dump(mydict, pfile) > > pfile.close() > > > this creates extremely large files (~ 300 MB) though it does so > > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > > it gets slower and slower. it takes almost an hour if not more to > > write this pickle object to file. > > > is there any way to speed this up? i dont mind the large file... after > > all the text file with the data used to make the dictionary was larger > > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > > i do care about speed... > > > i have tried optimizing this by using this: > > > s = pickle.dumps(mydict, 2) > > pfile.write(s) > > > but this takes just as long... any ideas ? is there a different module > > i could use that's more suitable for large dictionaries ? > > thank you very much. > > Pardon me if I'm asking the "bleedin' obvious", but have you checked > how much virtual memory this is taking up compared to how much real > memory you have? If the slowness is due to pagefile I/O, consider > doing "about 10" separate pickles (one for each key in your top-level > dictionary). the slowness is due to CPU when i profile my program using the unix program 'top'... i think all the work is in the file I/O. the machine i am using several GB of ram and ram memory is not heavily taxed at all. do you know how file I/O can be sped up? in reply to the other poster: i thought 'shelve' simply calls pickle. if thats the case, it wouldnt be any faster, right ? From cosmo_general at yahoo.com Wed Jan 28 17:49:14 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Wed, 28 Jan 2009 14:49:14 -0800 (PST) Subject: Results of executing hyperlink in script Message-ID: Hi Folks, My previous post got a many helps from the people, and I tested what they suggested. Since this topic maybe needed in future, so I drop these lines below to help the future programmers. The methods worked as below: 1. This method was suggested by Cameron Laird: os.system("start %s" % URL) It works. But, if the URL contains character &, it will fail. For example, if URL has only one field, such as: http://www.mydomain.com/ascript.cgi?user=muddy this method works well. But, if there more than one field need to be input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, the field password failed to reach server, and the CGI script complained. 2. The best way is to use urllib2, suggested by Ron Barak, my code is below: import urllib2 source = urllib2.urlopen(URL).read() print source It successfully triggered CGI script, and also got feedback from server. It works very well! My thanks go to all the helpers! Muddy Coder From prologic at shortcircuit.net.au Wed Jan 28 17:55:09 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 29 Jan 2009 08:55:09 +1000 Subject: Addition of multiprocessing ill-advised? (was: Python 3.0.1) In-Reply-To: <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> References: <497F7325.7070802@v.loewis.de> <2E3BD230-BE90-4E31-88D3-7844E5FFC3BC@python.org> <87mydcxf6x.fsf@benfinney.id.au> <4222a8490901280541s6b21a5b6m1ea0d14b6313bee1@mail.gmail.com> Message-ID: Jesse: Can I mail you off-list regarding multiprocessing ? cheers James -- -- "Problems are solved by method" From sjmachin at lexicon.net Wed Jan 28 18:00:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:00:39 -0800 (PST) Subject: bigint to timestamp References: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> Message-ID: <4ee860a7-be3d-45a9-b393-260942fa08cb@x16g2000prn.googlegroups.com> On Jan 29, 1:05?am, Jon Clements wrote: > On Jan 28, 1:50?pm, Steve Holden wrote: > > > > > Shah Sultan Alam wrote: > > > Hi Group, > > > I have file with contents retrieved from mysql DB. > > > which has a time field with type defined bigint(20) > > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > > GMT) using python code. > > > The value I found for that field is 212099016004150509 > > > Give me sample code that does the conversion. > > > Please? > > > Perhaps you could tell us what date and time 212099016004150509 is > > supposed to represent? The classic format is "seconds since the Unix > > epoch" but that isn't what this is: > > > >>> time.localtime(212099016004150509) > > > Traceback (most recent call last): > > ? File "", line 1, in > > ValueError: timestamp out of range for platform time_t > > > Neither does it appear to be a MySQL TIME field, since the maximum value > > for that would appear to be > > > >>> ((838*60)+59)*60+59 > > > 3020399 > > > So, just what is this field? What do the values mean? > > > regards > > ?Steve > > -- > > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > Bit hard to guess without the actual date to compare to... and I'm a > bit busy, but thought I'd throw this in the pool: I'm guessing it's a > MySQL database that's had data put into it via a .NET application > using the .NET DateTime (so a 20 byte int sounds about right IIRC), > which is based on the number of ticks since Jan 1, 1.... I think that > should end up around 2[18ish digits here...]... Mmmm ... I thought it might be the MS format that's ticks since 1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen 10,000,000 times per second, but: >>> x = 212099016004150509 >>> seconds = x / 10000000.0 >>> seconds 21209901600.415051 >>> days = seconds / 60. / 60. / 24. >>> days 245484.97222702604 >>> years_approx = days / 365.25 >>> years_approx 672.10122444086528 which would make it in the year 2272. Perhaps the OP could tell us what are the maximum and minimum non-zero non-null values he can find, and what years those might belong to. Also (very important) he might assure us that he is copying/pasting those large numbers, not retyp[o]ing them. From banaouas.medialog at wanadoo.fr Wed Jan 28 18:02:50 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Thu, 29 Jan 2009 00:02:50 +0100 Subject: file date/time on windows In-Reply-To: References: <49807795$0$18360$ba4acef3@news.orange.fr> Message-ID: <4980e41a$0$9403$ba4acef3@news.orange.fr> thanks, someone gave me the solution: simply call time.localtime(...) instead of time.gmtime(...) The explorer file time is what I need because it's the only file date visible for most of users. So localtime is perfect for me. We are talking about the same file stored in a shared lan-computer-folder. I gess that if computers of those users are in different timezones, they could see different file date ? MRAB a ?crit : > m.banaouas wrote: >> hi, >> >> I noticed recently that the value of file date/time I get with python: >> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) >> is forwarding by one hour the real file date/time. >> >> Example: >> file A.txt: 2009-01-18 16:13 >> returned valeur: 2009-01-28 15:13 >> >> Is there a simple way to get it work correctely (other than adding >> always 1 >> hour ...) ? >> > time.gmtime(), as the name suggests, returns GMT (UTC). > > From your email address I presume you're in France, which is GMT+1. > > Windows Explorer shows the file time in local time, which for you is > currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. From castironpi at gmail.com Wed Jan 28 18:08:40 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 28 Jan 2009 15:08:40 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> Message-ID: <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > hello all, > > > > i have a large dictionary which contains about 10 keys, each key has a > > > value which is a list containing about 1 to 5 million (small) > > > dictionaries. for example, > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > 'world'}, ...], > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > in total there are about 10 to 15 million lists if we concatenate > > > together all the values of every key in 'mydict'. mydict is a > > > structure that represents data in a very large file (about 800 > > > megabytes). snip > in reply to the other poster: i thought 'shelve' simply calls pickle. > if thats the case, it wouldnt be any faster, right ? Yes, but not all at once. It's a clear winner if you need to update any of them later, but if it's just write-once, read-many, it's about the same. You said you have a million dictionaries. Even if each took only one byte, you would still have a million bytes. Do you expect a faster I/ O time than the time it takes to write a million bytes? I want to agree with John's worry about RAM, unless you have several+ GB, as you say. You are not dealing with small numbers. From google at mrabarnett.plus.com Wed Jan 28 18:14:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:14:59 +0000 Subject: Results of executing hyperlink in script In-Reply-To: References: Message-ID: <4980E6F3.4010702@mrabarnett.plus.com> Muddy Coder wrote: > Hi Folks, > > My previous post got a many helps from the people, and I tested what > they suggested. Since this topic maybe needed in future, so I drop > these lines below to help the future programmers. The methods worked > as below: > > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For > example, if URL has only one field, such as: http://www.mydomain.com/ascript.cgi?user=muddy > this method works well. But, if there more than one field need to be > input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, > the field password failed to reach server, and the CGI script > complained. > You could put quotes around the URL: os.startfile('"%s"' % URL) or: os.system('start "%s"' % URL) if "&" has a special meaning to the command-line. From sln at netherlands.com Wed Jan 28 18:17:13 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Wed, 28 Jan 2009 23:17:13 GMT Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee wrote: >Function Application is not Currying > >Xah Lee, 2009-01-28 > >In Jon Harrop's book Ocaml for Scientist at >http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > >It says: > > Currying > > A curried function is a function which returns a function as its >result. > Curry, is that like chicken soup or some Indian mash? Why ? How about returning an index number into an array of function pointers as handlers from packet data? Oh, thats network communications. sln From ocschwar at gmail.com Wed Jan 28 18:20:41 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 15:20:41 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: On Jan 28, 4:50?pm, Aaron Brady wrote: > On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: > > Hello, quoting myself from another thread today: > > There is the 'shelve' module. ?You could create a shelf that tells you > the filename of the 5 other ones. ?A million keys should be no > problem, I guess. ?(It's standard library.) ?All your keys have to be > strings, though, and all your values have to be pickleable. ?If that's > a problem, yes you will need ZODB or Django (I understand), or another > relational DB. > > There is currently no way to store live objects. The problem is NOT archiving these objects. That works fine. It's the computations I'm using these thigns for that are slow, and that failed to speed up using __slots__. What I need is something that will speed up getattr() or its equivalent, and to a lesser degree setattr() or its equivalent. From ocschwar at gmail.com Wed Jan 28 18:23:47 2009 From: ocschwar at gmail.com (ocschwar at gmail.com) Date: Wed, 28 Jan 2009 15:23:47 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> Message-ID: <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> On Jan 28, 5:21?pm, "Diez B. Roggisch" wrote: > ocsch... at gmail.com schrieb: > > > > > Hi, all. > > > I have an application that that creates, manipulates, and finally > > archives on disk 10^6 instances of an object that in CS/DB terms is > > best described as a relation. > > > It has 8 members, all of them common Python datatypes. 6 of these are > > set once and then not modified. 2 are modified around 4 times before > > the instance's archving. Large collections (of small lists) of these > > objects are created, iterated through, and sorted using any and all of > > the 8 members as sorting keys. > > > It neither has nor needs custom methods. > > > I used a simple dictionary to create the application prototype. Now I > > need to speed things up. > > I first tried changing to a new style class, with __slots__, __init__, > > __getstate__& __setstate__ (for pickling) and was shocked to see > > things SLOW down over dictionaries. > > > So of these options, where should I go first to satisfy my need for > > speed? > > > 0. Back to dict > > 1. old style class > > 2. new style class > > 3. new style class, with __slots__, with or without some nuance I'm > > missing. > > 4. tuple, with constants to mark the indices > > 5. namedTuple > > 6. other... > > Use a database? Or *maybe* a C-extension wrapped by ctypes. > > Diez I can't port the entire app to be a stored database procedure. ctypes, maybe. I just find it odd that there's no quick answer on the fastest way in Python to implement a mapping in this context. From deets at nospam.web.de Wed Jan 28 18:24:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 29 Jan 2009 00:24:25 +0100 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: <6uc7paFepb16U1@mid.uni-berlin.de> ocschwar at gmail.com schrieb: > On Jan 28, 4:50 pm, Aaron Brady wrote: >> On Jan 28, 2:38 pm, ocsch... at gmail.com wrote: >> >> Hello, quoting myself from another thread today: >> >> There is the 'shelve' module. You could create a shelf that tells you >> the filename of the 5 other ones. A million keys should be no >> problem, I guess. (It's standard library.) All your keys have to be >> strings, though, and all your values have to be pickleable. If that's >> a problem, yes you will need ZODB or Django (I understand), or another >> relational DB. >> >> There is currently no way to store live objects. > > > The problem is NOT archiving these objects. That works fine. I know. But if they are sorted to various criteria, doing that inside a DB might also be faster. That was the point I wanted to make. Diez From sjmachin at lexicon.net Wed Jan 28 18:26:00 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:26:00 -0800 (PST) Subject: bigint to timestamp References: <14df95a5-e643-4edb-a91a-a3ca789cf3a0@35g2000pry.googlegroups.com> <4ee860a7-be3d-45a9-b393-260942fa08cb@x16g2000prn.googlegroups.com> Message-ID: On Jan 29, 10:00?am, John Machin wrote: > On Jan 29, 1:05?am, Jon Clements wrote: > > > > > On Jan 28, 1:50?pm, Steve Holden wrote: > > > > Shah Sultan Alam wrote: > > > > Hi Group, > > > > I have file with contents retrieved from mysql DB. > > > > which has a time field with type defined bigint(20) > > > > I want to parse that field into timestamp format(YYYY-MM-DD HH:MM:SS > > > > GMT) using python code. > > > > The value I found for that field is 212099016004150509 > > > > Give me sample code that does the conversion. > > > > Please? > > > > Perhaps you could tell us what date and time 212099016004150509 is > > > supposed to represent? The classic format is "seconds since the Unix > > > epoch" but that isn't what this is: > > > > >>> time.localtime(212099016004150509) > > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ValueError: timestamp out of range for platform time_t > > > > Neither does it appear to be a MySQL TIME field, since the maximum value > > > for that would appear to be > > > > >>> ((838*60)+59)*60+59 > > > > 3020399 > > > > So, just what is this field? What do the values mean? > > > > regards > > > ?Steve > > > -- > > > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > > > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > > Bit hard to guess without the actual date to compare to... and I'm a > > bit busy, but thought I'd throw this in the pool: I'm guessing it's a > > MySQL database that's had data put into it via a .NET application > > using the .NET DateTime (so a 20 byte int sounds about right IIRC), > > which is based on the number of ticks since Jan 1, 1.... I think that > > should end up around 2[18ish digits here...]... > > Mmmm ... I thought it might be the MS format that's ticks since > 1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen > 10,000,000 times per second, but: > > >>> x = 212099016004150509 > >>> seconds = x / 10000000.0 > >>> seconds > 21209901600.415051 > >>> days = seconds / 60. / 60. / 24. > >>> days > 245484.97222702604 > >>> years_approx = days / 365.25 > >>> years_approx > > 672.10122444086528 > > which would make it in the year 2272. > > Perhaps the OP could tell us what are the maximum and minimum non-zero > non-null values he can find, and what years those might belong to. > Also (very important) he might assure us that he is copying/pasting > those large numbers, not retyp[o]ing them. About .Net DateTime: the word from Mordor is "Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 1 A.D. (C.E.) in the GregorianCalendar calendar." "12:00 midnight"??? Is this 0001-01-02T00:00:00 ??? In any case, this would make the OP's bigint about 50 years after the Hegira ... plausible only if his database is rather historical. From akineko at gmail.com Wed Jan 28 18:26:08 2009 From: akineko at gmail.com (akineko) Date: Wed, 28 Jan 2009 15:26:08 -0800 (PST) Subject: Terminating a Python program that uses multi-process, multi-threading References: Message-ID: <852a731b-2ada-413e-aea2-51877c0304a0@z27g2000prd.googlegroups.com> On Jan 28, 1:11?pm, MRAB wrote: > A hacky way of killing the processes would be for the processes to write > their process IDs to the log and then you can write another script which > will parse the log to get the process IDs and then kill the processes > with those IDs. (Left as an exercise for the reader. Thank you MRAB. Your suggestion is very reasonable. I think I will do both. Try to reduce the chance of freeze-up and create a script to clean-up. Aki- From exarkun at divmod.com Wed Jan 28 18:29:08 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 28 Jan 2009 18:29:08 -0500 Subject: Results of executing hyperlink in script In-Reply-To: <4980E6F3.4010702@mrabarnett.plus.com> Message-ID: <20090128232908.24460.1432709719.divmod.quotient.3449@henry.divmod.com> On Wed, 28 Jan 2009 23:14:59 +0000, MRAB wrote: >Muddy Coder wrote: >>Hi Folks, >> >>My previous post got a many helps from the people, and I tested what >>they suggested. Since this topic maybe needed in future, so I drop >>these lines below to help the future programmers. The methods worked >>as below: >> >>1. This method was suggested by Cameron Laird: >> >> os.system("start %s" % URL) >> >>It works. But, if the URL contains character &, it will fail. For >>example, if URL has only one field, such as: >>http://www.mydomain.com/ascript.cgi?user=muddy >>this method works well. But, if there more than one field need to be >>input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo, >>the field password failed to reach server, and the CGI script >>complained. >You could put quotes around the URL: > >os.startfile('"%s"' % URL) > >or: > >os.system('start "%s"' % URL) > >if "&" has a special meaning to the command-line. What if the URL has a " in it? Worse, what if the URL is: " & rm -rf ~ os.system is a pretty bad thing to use. Fortunately, the suggestion to use urllib was a much better one, and you can't use os.system here anyway since the poster is interested in getting the contents of the page at the URL. Jean-Paul From google at mrabarnett.plus.com Wed Jan 28 18:32:01 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:32:01 +0000 Subject: file date/time on windows In-Reply-To: <4980e41a$0$9403$ba4acef3@news.orange.fr> References: <49807795$0$18360$ba4acef3@news.orange.fr> <4980e41a$0$9403$ba4acef3@news.orange.fr> Message-ID: <4980EAF1.3060203@mrabarnett.plus.com> m.banaouas wrote: > thanks, > someone gave me the solution: > simply call time.localtime(...) instead of time.gmtime(...) > > The explorer file time is what I need because it's the only file date visible > for most of users. So localtime is perfect for me. > We are talking about the same file stored in a shared lan-computer-folder. > I gess that if computers of those users are in different timezones, they could > see different file date ? > > The filetime is stored as UTC and is converted to local time only for display. (Actually, that might apply only to NTFS.) There's also the idiosyncrasy that the filetime, when converted to local time, will have 1 added to the hour during DST, irrespective of whether the filetime itself was during DST, so a file that was modified at 09:00 on 1 January will appear to have been modified at 10:00 if viewed during June, and a file that was modified at 09:00 on 1 June will appear to have been modified at 08:00 if viewed during non-DST! > MRAB a ?crit : >> m.banaouas wrote: >>> hi, >>> >>> I noticed recently that the value of file date/time I get with python: >>> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime)) >>> is forwarding by one hour the real file date/time. >>> >>> Example: >>> file A.txt: 2009-01-18 16:13 >>> returned valeur: 2009-01-28 15:13 >>> >>> Is there a simple way to get it work correctely (other than adding >>> always 1 >>> hour ...) ? >>> >> time.gmtime(), as the name suggests, returns GMT (UTC). >> >> From your email address I presume you're in France, which is GMT+1. >> >> Windows Explorer shows the file time in local time, which for you is >> currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2. > -- > http://mail.python.org/mailman/listinfo/python-list > From google at mrabarnett.plus.com Wed Jan 28 18:37:16 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jan 2009 23:37:16 +0000 Subject: Function Application is not Currying In-Reply-To: <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com> Message-ID: <4980EC2C.1020809@mrabarnett.plus.com> sln at netherlands.com wrote: > On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee wrote: > >> Function Application is not Currying >> >> Xah Lee, 2009-01-28 >> >> In Jon Harrop's book Ocaml for Scientist at >> http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html >> >> It says: >> >> Currying >> >> A curried function is a function which returns a function as its >> result. >> > Curry, is that like chicken soup or some Indian mash? > "Currying" is named after someone called Curry. The 'correct' term is "partial parameterisation", which explains why it's often called "Currying" instead! :-) > Why ? How about returning an index number into an array of function pointers > as handlers from packet data? > > Oh, thats network communications. > From sjmachin at lexicon.net Wed Jan 28 18:46:11 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jan 2009 15:46:11 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> Message-ID: <531ffa9d-ddca-43de-9c3d-90b64c784755@o40g2000prn.googlegroups.com> On Jan 29, 9:43?am, perfr... at gmail.com wrote: > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > hello all, > > > > i have a large dictionary which contains about 10 keys, each key has a > > > value which is a list containing about 1 to 5 million (small) > > > dictionaries. for example, > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > 'world'}, ...], > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > in total there are about 10 to 15 million lists if we concatenate > > > together all the values of every key in 'mydict'. mydict is a > > > structure that represents data in a very large file (about 800 > > > megabytes). > > > > what is the fastest way to pickle 'mydict' into a file? right now i am > > > experiencing a lot of difficulties with cPickle when using it like > > > this: > > > > from cPickle import pickle > > > pfile = open(my_file, 'w') > > > pickle.dump(mydict, pfile) > > > pfile.close() > > > > this creates extremely large files (~ 300 MB) though it does so > > > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > > > it gets slower and slower. it takes almost an hour if not more to > > > write this pickle object to file. > > > > is there any way to speed this up? i dont mind the large file... after > > > all the text file with the data used to make the dictionary was larger > > > (~ 800 MB) than the file it eventually creates, which is 300 MB. ?but > > > i do care about speed... > > > > i have tried optimizing this by using this: > > > > s = pickle.dumps(mydict, 2) > > > pfile.write(s) > > > > but this takes just as long... any ideas ? is there a different module > > > i could use that's more suitable for large dictionaries ? > > > thank you very much. > > > Pardon me if I'm asking the "bleedin' obvious", but have you checked > > how much virtual memory this is taking up compared to how much real > > memory you have? If the slowness is due to pagefile I/O, consider > > doing "about 10" separate pickles (one for each key in your top-level > > dictionary). > > the slowness is due to CPU when i profile my program using the unix > program 'top'... i think all the work is in the file I/O. the machine > i am using several GB of ram and ram memory is not heavily taxed at > all. do you know how file I/O can be sped up? More quick silly questions: (1) How long does it take to load that 300MB pickle back into memory using: (a) cpickle.load(f) (b) f.read() ? What else is happening on the machine while you are creating the pickle? (2) How does From gagsl-py2 at yahoo.com.ar Wed Jan 28 18:55:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 21:55:51 -0200 Subject: errno 22 instead of errno 2 References: <49800EDB.3080800@g.nevcal.com> <49801F9E.1050700@timgolden.me.uk> Message-ID: En Wed, 28 Jan 2009 07:04:30 -0200, Tim Golden escribi?: > Glenn Linderman wrote: >> open("c:\abc","rb") >> This simple one-line script, produces errno 22 on Python 2.6, but >> errno 2 on Python 2.5.2 > > Just glancing quickly at the svn logs, there certainly were some > changes around that area in 2008: > > I'd question whether it's strictly a "regression", unintentional or > otherwise, since I doubt the code makes any particular commitment as > to which error code is raised, but I'd certainly be looking askance > if I had code which relied on a particular error number which then > changed! Still, that's what unit tests are for, I suppose. Even if nothing had changed on Python, one should note that the Windows API doesn't promise anything about the specific set of error codes a function might set (not that it happens every day, but MS has reserved the right to alter them). PS: and thanks for my new word of the day: "askance" -- Gabriel Genellina From gdamjan at gmail.com Wed Jan 28 18:56:22 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 29 Jan 2009 00:56:22 +0100 Subject: Reuse of DB-API 2.0 cursors for multiple queries? References: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Message-ID: <6u7756-l0m.ln1@archaeopteryx.softver.org.mk> > Today, I used the adodbapi module against an SQL Server Express > database. I was surprised to get an exception, when I attempted to > submit a second query with my cursor object. The full session is > below. >>> curs.execute('select * from localview_roles') >>> curs.execute('select * from localview_roles') have you tried to curs.fetch() or fetchall() before the second execute? -- ?????? ( http://softver.org.mk/damjan/ ) Scarlett Johansson: You always see the glass half-empty. Woody Allen: No. I see the glass half-full, but of poison. From praxbaffle at hotmail.com Wed Jan 28 18:57:36 2009 From: praxbaffle at hotmail.com (John Seales) Date: Wed, 28 Jan 2009 15:57:36 -0800 Subject: how to update python on gnu emacs? Message-ID: I've updated to python 2.6. My terminal application finds the new python just fine, but my gnu-emacs still is on python 2.3. Does anyone know how I can change that? using x86 powerbook John Seales _________________________________________________________________ Windows Live? Hotmail??more than just e-mail. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Wed Jan 28 19:05:15 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 29 Jan 2009 01:05:15 +0100 Subject: small python-cgi wiki? References: Message-ID: > I'm looking to set up a small private wiki, and am looking for > recommendations. > > Some sort of CGI based package that I could just untar somewhere web > accessable via Apache would be great. http://hatta.sheep.art.pl/About ? single file ? stores stuff in mercurial. ? it's WSGI, so yes you can run it as CGI too (wsgiref.handlers.CGIHandler) http://hatta.sheep.art.pl/Features -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of converstion. Q: Why is top posting frowned upon? From david.lyon at preisshare.net Wed Jan 28 19:12:21 2009 From: david.lyon at preisshare.net (david.lyon at preisshare.net) Date: Wed, 28 Jan 2009 19:12:21 -0500 Subject: Python Package Managment In-Reply-To: <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> References: <9fb42982-7ce6-44c8-8c1c-de2bdd362082@w24g2000prd.googlegroups.com> <6e9196d20901191105i78ac61dbya994de8037e4d51f@mail.gmail.com> <7B3C4190-F8A6-43E9-8E54-7C8C9AA36B35@ruggier.org> <32822fe60901242322o2a76cf35p270f68f7fec55834@mail.gmail.com> <14AFD7A7-A90D-430F-9CEA-ABF381C7380C@ruggier.org> <6e9196d20901260835o2e9bd93elb563258ec93035e4@mail.gmail.com> <90bb445a0901271340r45a7c808j1202a32eec4d7213@mail.gmail.com> <6e9196d20901271454x54298565v9aa643d9f219ab8c@mail.gmail.com> <596392.54834.qm@web112214.mail.gq1.yahoo.com> <5b8d13220901280253u305a17belfda355f09b63f845@mail.gmail.com> Message-ID: Hi, >>> People coming to Python from Perl and Ruby expect to be able to just >>> run a command to download and install a package. TRUE TRUE.... Forgive me, but I am no python specialist. But I use all the other languages as well and python isn't up to standard in this area. Perphaps 50% of all my python time, is spent searching and testing packages for what I need off peoples web sites. It is crazy... In perl it is so much easier on cpan, but i hate the language (perl)... I really propose something be done about it, but it takes a team.... In perl, it is so easy to remember "ppm" (perl package manager).. My only suggestion is that allowance be made for platform specific components, ie, windows, mac... because under windows, a lot of the tools I use are platform specific linking to the o/s. It would be desirable to seperate those out from packages that are not platform specific. On Wed, 28 Jan 2009 19:53:42 +0900, David Cournapeau wrote: > On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin > wrote: >> [extracted from pylons-discuss] >> >> >>> >> I hate to pass the buck, but this is Python's fault for not having >>> >> reliable package management built in. There's nothing Pylons can do >>> >> about it except switch to another programming language. >>> > [SNIP] >>> >>> Without Setuptools, >>> Pylons and TurboGears couldn't exist, and Zope and Twisted >>> would not have been able to split themselves into several packages. >>> People coming to Python from Perl and Ruby expect to be able to just >>> run a command to download and install a package. That problem was >>> solved ten years ago, so why does Python still not have it standard? >>> >>> If Setuptools and Virtualenv or the equivalent were built into Python, >>> you could trust that every computer that has successfully installed >>> Python can install packages and make virtual environments the same >>> way.. >>> >>> That would eliminate 2/3 of the problems users have when >>> installing Pylons, and the subsequent need to explain the problems and >>> workarounds in the installation docs. At >>> work people say, "Half the trouble of Pylons is installing it", and I >>> often have to help them install it in person because otherwise they >>> get stuck at some error message and have no idea what to do. >>> >> >> Agreed. I would even move ipython (or something like it) to core. >> >> Of course, even Setuptools has a long way to go in some areas. > (Installation Rollback, for one.) >> >> Python is about "batteries included", and these are major "batteries" in > most modern environments. >> >> A CPAN like "in-house hosted" archive would nice, too. This way, > modules have a better chance of outliving the original author's > interest/commitment in paying for, possibly non-trivial, web hosting. >> >> I'm sure these issues has been discussed to death, but I wonder what the > larger Python community thinks. > > You may be interested in the following: > > http://mail.python.org/pipermail/python-dev/2006-April/063952.html > > The thread is two years and a half old, but my impression is that the > situation has not changeed much since. Few if any people are against > improving the situation, but more people are against the currently > available solutions (setuptools, virtualenv, etc...). > > cheers, > > David > -- > http://mail.python.org/mailman/listinfo/python-list From wuwei23 at gmail.com Wed Jan 28 19:28:22 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 28 Jan 2009 16:28:22 -0800 (PST) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> On Jan 29, 7:32?am, Xah Lee wrote: > But he is really a asshole, and > take every chance to peddle his book. As opposed to really being an asshole and peddling one's website at every opportunity? From prologic at shortcircuit.net.au Wed Jan 28 19:34:51 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 29 Jan 2009 10:34:51 +1000 Subject: Function Application is not Currying In-Reply-To: <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com> Message-ID: On Thu, Jan 29, 2009 at 10:28 AM, alex23 wrote: > On Jan 29, 7:32 am, Xah Lee wrote: >> But he is really a asshole, and >> take every chance to peddle his book. > > As opposed to really being an asshole and peddling one's website at > every opportunity? It would seem that Xah Lee suffers from a syndrome we've come to know as "I'm Mr. Big Shot look at me I know everything" --JamesMills From gagsl-py2 at yahoo.com.ar Wed Jan 28 19:39:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 28 Jan 2009 22:39:40 -0200 Subject: Windows PIL installer question References: <381de027-2be2-4de4-bb39-bf170a970a5a@s20g2000yqh.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 15:07:54 -0200, cjl escribi?: > Is there any way to run the PIL installer from the command line on > Windows in 'silent' mode, without displaying the install screens or > requiring user interaction? Is it a .msi? msiexec /i filename.msi /quiet /log path\to\logfile.log -- Gabriel Genellina From carsten.haese at gmail.com Wed Jan 28 19:47:02 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 28 Jan 2009 19:47:02 -0500 Subject: Reuse of DB-API 2.0 cursors for multiple queries? In-Reply-To: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> References: <9d908eb1-4712-44b2-b0cc-0848239bfb79@r36g2000prf.googlegroups.com> Message-ID: <807gl.2381$PE4.137@nlpi061.nbdc.sbc.com> moreati wrote: > Today, I used the adodbapi module against an SQL Server Express > database. I was surprised to get an exception, when I attempted to > submit a second query with my cursor object. The full session is > below. > > With cx_Oracle I've become used to reusing a cursor for subsequent > queries. The PEP doesn't specify either way, that I can see. The PEP doesn't say explicitly that a cursor can execute multiple queries, but it's definitely implied by the second paragraph: """ .execute(operation[,parameters]) Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified in a database-specific notation (see the module's paramstyle attribute for details). [5] A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times). """ You might want to check on a list dedicated to adodbapi whether there are module-specific quirks or caveats to watch out for. Or wait for somebody with adodbapi-specific knowledge to chime in. HTH, -- Carsten Haese http://informixdb.sourceforge.net From vincent at vincentdavis.net Wed Jan 28 20:00:36 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 28 Jan 2009 18:00:36 -0700 Subject: program organization question Message-ID: <77e831100901281700w184b9e8bne323aef1647e5548@mail.gmail.com> Basically my program simulates the Medical Residency Match, generating simulated data, running the match and then summarizing results. Currently it does this all in one document (starting conditions--Gen data--run match--summarize results). I will be running multiple simulations on different starting condition and data generation. My question is how should I organize this. My plane was to have a separate document for staring conditions, data generation because these will change for each simulation. Then on for the match a summarizing data as this will always be the same except for saving the results as different names. I don't even know how to pass data from on program to another although I think I can figure this out. Any guidance? Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From Graham.Dumpleton at gmail.com Wed Jan 28 20:10:19 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 28 Jan 2009 17:10:19 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: Message-ID: <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c@s1g2000prg.googlegroups.com> On Jan 29, 8:35?am, Ron Garret wrote: > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > whenever I restart the server after making a code change it takes a very > long time (like a minute) before the script is active again. ?In other > words, I do an apachectl restart, reload the page in my browser, and one > minute later it finally comes up. ?During this time CPU usage is > essentially zero. ?Loading all the code manually into a python > interpreter is virtually instantaneous, and all subsequence interactions > with the app are very fast. > > Does anyone have any ideas what might be going on or how to debug this? The better place to discuss this is the mod_wsgi list. http://groups.google.com/group/modwsgi?hl=en As to the problem, you need to distinguish between whether it is Apache that is taking a long time to restart and ready to handle requests, or whether the delay is on the first subsequent request made against your WSGI application. When Apache restarts, it doesn't by default load your WSGI application, it only does that the first time a request comes in directed at it. Thus, if after you restart Apache you do a request of a static file, do you get a response straight away? If it doesn't respond straight away, then it is an issue with Apache restart and not mod_wsgi as your WSGI application wouldn't be involved. If the static file request is fine and only first request to WSGI application is slow, then likely that problem is to do with the startup cost of loading your WSGI application and initialising it upon first request. As you don't say what Python web framework/application you are using, hard to say what the issue may be there. If it is an Apache issue and not mod_wsgi, as pointed out already, could be that you have Apache setup to do reverse DNS lookups on client IP address and that isn't working properly. This often happens for Windows people. So, narrow down where problem is occurring. Graham From rNOSPAMon at flownet.com Wed Jan 28 20:11:52 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 17:11:52 -0800 Subject: Sloooooowwwww WSGI restart References: Message-ID: In article , Aleksandar Radulovic wrote: > Hi there, > > On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > > Off the bat, there's no reason to run an app under apache/mod_wsgi > while developing it, > ie. if u use Pylons or TurboGears, there's an easier way to serve the > app (using paster > or cherrypy). Yes, I know. I guess I'm just a masochist. But this would be an issue in production as well. I don't want to have to go down for a minute every time I push a new release. > Secondly, why are you restarting apache after code changes? In normal > circumstances, you shouldn't have to do that. I thought (and experiment confirms) that only the main WSGI app file gets reloaded automatically when it changes, not the libraries. rg From rNOSPAMon at flownet.com Wed Jan 28 20:12:19 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 17:12:19 -0800 Subject: Sloooooowwwww WSGI restart References: Message-ID: In article , Jean-Paul Calderone wrote: > On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret wrote: > >I'm running a WSGI app under apache/mod_wsgi and I've noticed that > >whenever I restart the server after making a code change it takes a very > >long time (like a minute) before the script is active again. In other > >words, I do an apachectl restart, reload the page in my browser, and one > >minute later it finally comes up. During this time CPU usage is > >essentially zero. Loading all the code manually into a python > >interpreter is virtually instantaneous, and all subsequence interactions > >with the app are very fast. > > > >Does anyone have any ideas what might be going on or how to debug this? > > strace is nice. It sounds like some blocking network operation. rdns can > often cause things like this. If you're lucky, strace will point right at > the problem. > > Jean-Paul That's a good idea. Thanks! rg From Graham.Dumpleton at gmail.com Wed Jan 28 20:16:19 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 28 Jan 2009 17:16:19 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: Message-ID: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> On Jan 29, 8:44?am, Aleksandar Radulovic wrote: > Hi there, > > On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > > Off the bat, there's no reason to run an app under apache/mod_wsgi > while developing it, > ie. if u use Pylons or TurboGears, there's an easier way to serve the > app (using paster > or cherrypy). > > Secondly, why are you restarting apache after code changes? In normal > circumstances, > you shouldn't have to do that. Sorry, you are wrong to assume that an Apache restart is not be required. If you are using mod_wsgi embedded mode, or mod_python, then a code change will always require a full restart of Apache. If you are using mod_wsgi daemon mode, you need to at least touch the WSGI script file for an automatic restart of that specific application to occur. Changes to arbitrary Python code files are not detected. If using mod_wsgi daemon mode, you can also set up a separate background thread to monitor for arbitrary code changes as described for Django in: http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html That page references original documentation on mod_wsgi wiki for bulk of information. Thus, the conjecture that Apache/mod_wsgi cannot be used and that CherryPy WSGI server or Paster server must be used when developing a Python web application is false. If using mod_wsgi then daemon mode would of course be preferred though, with touching the WSGI script file being safest option to ensure updates across multiple files picked up at same time, but if you really want completely automated restarts, use the recipe in mod_wsgi documentation. Graham From juvy.jumalon at gmail.com Wed Jan 28 20:44:12 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Thu, 29 Jan 2009 09:44:12 +0800 Subject: need help In-Reply-To: References: Message-ID: Hi Steve, Thanks for you reply. I am newbie in python. Im going to use HTTP. thanks a lot On Wed, Jan 28, 2009 at 9:40 PM, Steve Holden wrote: > juvy j wrote: > > Hi guys, > > > > need help on how to read file from other server(linux). > > > Which service do you plan to use: FTP, HTTP and NFS are three > possibilities that immediately come to mind, all well handled by {ython > standard library modules. A little more background might help. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kkylheku at gmail.com Wed Jan 28 20:49:25 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Thu, 29 Jan 2009 01:49:25 +0000 (UTC) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <20090203171740.143@gmail.com> On 2009-01-28, Xah Lee wrote: > Function Application is not Currying That's correct, Xah. Currying is a special case of function application. A currying function is applied to some other function, and returns function that has fewer arguments. In some languages, you don't see the currying function. It's invisibly performed whenever you forget an argument. Hit a three argument function with only two arguments, and you don't get a nice ``insufficient arguments in function call'' error, but the call is diverted to the currying function, which gives you back a function of one argument, which you can then call with the missing argument to compute the original function. > Xah Lee, 2009-01-28 > > In Jon Harrop's book Ocaml for Scientist at > http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html Figures you'd be reading this. Learning anything? > It says: > > Currying > > A curried function is a function which returns a function as its > result. > > LOL. That is incorrect. Yawn. Say it isn't so. From claird at lairds.us Wed Jan 28 21:02:22 2009 From: claird at lairds.us (Cameron Laird) Date: Thu, 29 Jan 2009 02:02:22 +0000 Subject: Results of executing hyperlink in script References: Message-ID: In article , MRAB wrote: >Muddy Coder wrote: . . . >You could put quotes around the URL: > >os.startfile('"%s"' % URL) > >or: > >os.system('start "%s"' % URL) > >if "&" has a special meaning to the command-line. In fact, no, happiness does NOT result in these contexts with another layer of quoting. os.startfile(URL) works fine even if URL embeds special characters, and does not work at all if URL is itself quoted. os.system("start ...") just gives a variety of unuseful results if URL embeds special characters. From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:11:33 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:11:33 -0200 Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> Message-ID: En Wed, 28 Jan 2009 14:13:10 -0200, escribi?: > i have a large dictionary which contains about 10 keys, each key has a > value which is a list containing about 1 to 5 million (small) > dictionaries. for example, > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > 'world'}, ...], > key2: [...]} > > [pickle] creates extremely large files (~ 300 MB) though it does so > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and > it gets slower and slower. it takes almost an hour if not more to > write this pickle object to file. There is an undocumented Pickler attribute, "fast". Usually, when the same object is referenced more than once, only the first appearance is stored in the pickled stream; later references just point to the original. This requires the Pickler instance to remember every object pickled so far -- setting the "fast" attribute to a true value bypasses this check. Before using this, you must be positively sure that your objects don't contain circular references -- else pickling will never finish. py> from cPickle import Pickler py> from cStringIO import StringIO py> s = StringIO() py> p = Pickler(s, -1) py> p.fast = 1 py> x = [1,2,3] py> y = [x, x, x] py> y [[1, 2, 3], [1, 2, 3], [1, 2, 3]] py> y[0] is y[1] True py> p.dump(y) py> s.getvalue() '\x80\x02](](K\x01K\x02K\x03e](K\x01K\x02K\x03e](K\x01K\x02K\x03ee.' Note that, when unpickling, shared references are broken: py> s.seek(0,0) py> from cPickle import load py> y2 = load(s) py> y2 [[1, 2, 3], [1, 2, 3], [1, 2, 3]] py> y2[0] is y2[1] False -- Gabriel Genellina From notvalid2 at sbcglobal.net Wed Jan 28 21:13:53 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 18:13:53 -0800 Subject: Drawing and Displaying an Image with PIL In-Reply-To: References: <803e5ea6-8ebc-4847-b85c-528ec13e26ec@v4g2000vbb.googlegroups.com> <60c20dec-5888-4380-b1b0-4cc1e18334c5@e24g2000vbe.googlegroups.com> <1vXfl.9580$8_3.1384@flpi147.ffdc.sbc.com> Message-ID: Peter Otten wrote: > W. eWatson wrote: > >> r wrote: >>> Change this line: >>> draw.line((0,0),(20,140), fill=128) >>> >>> To This: >>> draw.line((0,0, 20,140), fill=128) >>> >>> And you should be good to go. Like you said, if you need to combine 2 >>> tuples you can do: >>> (1,2)+(3,4) >> Yes, that's true, but the big question is how to "see" the final image? >> Either one employees another module or writes the file into a folder, then >> displays it with a paint program? > > For debugging purposes you can just invoke the show() method > > im = Image.open(...) > # modify image > im.show() > > If you want to integrate the image into your own Tkinter program -- that is > explained here: > > http://effbot.org/tkinterbook/photoimage.htm > > Following these instruction you code might become > > import Tkinter as tk > import Image > import ImageTk > import ImageDraw > import sys > > filename = sys.argv[1] > im = Image.open(filename) > > draw = ImageDraw.Draw(im) > draw.line((0, 0) + im.size, fill=128) > draw.line(((0,0),(20,140)), fill=128) > > > root = tk.Tk() > pi = ImageTk.PhotoImage(im) > label = tk.Label(root, image=pi) > label.pack() > root.mainloop() > > Peter My initial quest was to do it in PIL. That seems impossible, and the way out is Tkinter. I'm not yet savvy enough with Pythons graphics. I was definitely leaning towards PhotoImage as the way out. What module is show in? Repairing my (0,0), ... to (0,0)+, and. replacing arg with ImageOPen, produces a correct solution. My NM Tech pdf misses the boat on PhotoImage. I've seen your reference before, but never looked at PhotoImage. I'll bookmark it. I sure wish it was in pdf format. Thanks. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:29:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:29:29 -0200 Subject: Quickbooks References: <4980A229.1040606@offenbachers.com> Message-ID: En Wed, 28 Jan 2009 16:21:29 -0200, Stephen Chapman escribi?: > Has anyone Implemented the Quickbooks COM object in Python. If so can > you give me > an Idea of where to begin. You'll want the pywin32 package by Mark Hammond -available from sourceforge-. It provides the infrastructure required to manipulate any COM object from Python. M. H. coauthored the book "Python Programming On Win32"; the sample chapter available at Amazon is precisely "Introduction to COM". -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jan 28 21:38:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 00:38:18 -0200 Subject: date handling problem References: Message-ID: En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva escribi?: > I need to parse rss-feeds based on time stamp,But rss-feeds follow > different > standards of date(IST,EST etc). > I dont know,how to standardize this standards.It will be helpful if you > can > hint me. You may find the Olson timezone database useful. http://pytz.sourceforge.net/ -- Gabriel Genellina From rNOSPAMon at flownet.com Wed Jan 28 21:52:34 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 28 Jan 2009 18:52:34 -0800 Subject: Sloooooowwwww WSGI restart References: <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c@s1g2000prg.googlegroups.com> Message-ID: In article <4cd232ff-ba8b-47aa-8ee6-d8d9712db84c at s1g2000prg.googlegroups.com>, Graham Dumpleton wrote: > On Jan 29, 8:35?am, Ron Garret wrote: > > I'm running a WSGI app under apache/mod_wsgiand I've noticed that > > whenever I restart the server after making a code change it takes a very > > long time (like a minute) before the script is active again. ?In other > > words, I do an apachectl restart, reload the page in my browser, and one > > minute later it finally comes up. ?During this time CPU usage is > > essentially zero. ?Loading all the code manually into a python > > interpreter is virtually instantaneous, and all subsequence interactions > > with the app are very fast. > > > > Does anyone have any ideas what might be going on or how to debug this? > > The better place to discuss this is the mod_wsgi list. > > http://groups.google.com/group/modwsgi?hl=en The reason I don't go there is that I'm using an NNTP client. I find Google Groups' web interface to be very annoying because there's no way to keep track of read messages. > As to the problem, you need to distinguish between whether it is > Apache that is taking a long time to restart and ready to handle > requests, or whether the delay is on the first subsequent request made > against your WSGI application. > > When Apache restarts, it doesn't by default load your WSGI > application, it only does that the first time a request comes in > directed at it. Thus, if after you restart Apache you do a request of > a static file, do you get a response straight away? I thought I did, but having poked at it more I now realize that I was just getting a cached page. It does appear to be an apache issue, not a WSGI issue. Sorry for the false alarm. rg From rocky at panix.com Wed Jan 28 21:54:14 2009 From: rocky at panix.com (R. Bernstein) Date: Wed, 28 Jan 2009 21:54:14 -0500 Subject: How to get atexit hooks to run in the presence of execv? Message-ID: As a hobby I've been (re)writing a debugger. One of the commands, "restart", works by calling an execv(). You may need to do this when the program you are debugging is threaded or when one needs to ensure that all program state is reinitialized. Recently, I added remote debugging via TCP sockets. (Well, also FIFO's as well but closing sockets before restarting is what's of concern.) I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get called. Should it? Furthermore, I don't seen any atexit routine that would let me initiate such finalization. Should there be one? Or perhaps I'm missing something. Is there a way to arrange atexit hooks to get run before issuing an execv-like call? Thanks. From gagsl-py2 at yahoo.com.ar Wed Jan 28 22:00:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 01:00:25 -0200 Subject: Results of executing hyperlink in script References: Message-ID: En Wed, 28 Jan 2009 20:49:14 -0200, Muddy Coder escribi?: > My previous post got a many helps from the people, and I tested what > they suggested. Since this topic maybe needed in future, so I drop > these lines below to help the future programmers. The methods worked > as below: > > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For > 2. The best way is to use urllib2, suggested by Ron Barak, my code is > below: > > import urllib2 > source = urllib2.urlopen(URL).read() > print source Note that both methods are essencially different. The first one opens a browser window, and it's up to the user what to do after the initial request is done -- if this is what you want, the webbrowser module is better suited for that task. The second one is a pure programming interfase - the Python script is in control, and the user isn't involved at all. -- Gabriel Genellina From n.kottiyath at gmail.com Wed Jan 28 22:07:31 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Wed, 28 Jan 2009 19:07:31 -0800 (PST) Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: On Jan 29, 1:51?am, Rob Williscroft wrote: > Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 > @b38g2000prf.googlegroups.com in comp.lang.python: > > > > > I have mingw32-gcc in my path. If I try that too -it fails. > > > C:\Documents and Settings\Guest\pyAA>python setup.py install -c > > "mingw32-gcc" > > invalid command name 'mingw32-gcc' > > All the examples I found via google have the tool name as "mingw32" > so try: > > ? ? ? ? python setup.py install -c mingw32 > > or > > ? ? ? ? python setup.py build --compiler=mingw32 install > > The compiler that the MinGW package installs is gcc. > > You shoulf be able to verify it is on your path by typing: > > ? ? ? ? gcc --help > or > ? ? ? ? gcc --version > > and see some output. > > Rob. > --http://www.victim-prime.dsl.pipex.com/ Thank you Rob. The installation went ahead for some more time - but failed showing a lot of errors: >compile running build running build_py file pyAAc.py (for module pyAAc) not found file pyAAc.py (for module pyAAc) not found ... pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in this scope pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared in this scope pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not declared in this scope ... error: command 'gcc' failed with exit status 1 I cannot understand why it fails. I have not worked in C till now, so I am pretty confused. I googled also, but to no avail. From python.list at tim.thechases.com Wed Jan 28 22:08:13 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 21:08:13 -0600 Subject: need help In-Reply-To: References: Message-ID: <49811D9D.3000805@tim.thechases.com> > Thanks for you reply. I am newbie in python. > Im going to use HTTP. If all you want is to download a file, you might want to look into using "wget" or "curl" (which work for both HTTP and FTP). E.g. bash$ wget http://myothermachine/path/to/file.html However, if you need to roll it into a script, Python's urllib module will do the trick >>> import urllib >>> url = "http://myothermachine/path/to/file.html" >>> f = urlib.urlopen(url) >>> out = file('python.txt', 'w') >>> for line in f: out.write(line) ... >>> out.close() >>> f.close() If the content is small, you can just use >>> content = f.read() >>> out.write(content) instead of the "for line in f: out.write(line)". If you need to actually parse the HTML that's returned, the common suggestion is to use the BeautifulSoup add-on module which has worked for my needs. -tkc From python.list at tim.thechases.com Wed Jan 28 22:11:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jan 2009 21:11:12 -0600 Subject: Results of executing hyperlink in script In-Reply-To: References: Message-ID: <49811E50.7010809@tim.thechases.com> > 1. This method was suggested by Cameron Laird: > > os.system("start %s" % URL) > > It works. But, if the URL contains character &, it will fail. For As an aside, the START command is a bit picky regarding quotes. You have to use this horrible contortion os.system('start "title" "%s"' % URL) The "title" is optional content-wise, but required positionally if there's a quoted resource, so you can just use start "" "%s" a pain, but that's CMD.EXE for you. :) -tkc From Russ.Paielli at gmail.com Wed Jan 28 22:14:02 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 28 Jan 2009 19:14:02 -0800 (PST) Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <5d34610d-5a70-4851-8e24-6a86230edaaf@n33g2000pri.googlegroups.com> On Jan 28, 1:32?pm, Xah Lee wrote: > Function Application is not Currying > > Xah Lee, 2009-01-28 > > In Jon Harrop's book Ocaml for Scientist athttp://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > > It says: > > ? ? Currying > > ? ? A curried function is a function which returns a function as its > result. > > LOL. That is incorrect. What does that have to do with the price of bananas in Costa Rica? From tim at burlyhost.com Wed Jan 28 22:31:07 2009 From: tim at burlyhost.com (Tim Greer) Date: Wed, 28 Jan 2009 19:31:07 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <5d34610d-5a70-4851-8e24-6a86230edaaf@n33g2000pri.googlegroups.com> Message-ID: <0q9gl.109224$zJ2.519@newsfe23.iad> Russ P. wrote: > On Jan 28, 1:32?pm, Xah Lee wrote: >> Function Application is not Currying >> >> Xah Lee, 2009-01-28 >> >> In Jon Harrop's book Ocaml for Scientist >> athttp://www......./chapter1.html >> >> It says: >> >> Currying >> >> A curried function is a function which returns a function as its >> result. >> >> LOL. That is incorrect. > > What does that have to do with the price of bananas in Costa Rica? Xah Lee does this stuff in 4 or 5 groups he's decided to post random things to. They rarely have any relevance or substance, just his personal thoughts. He liked to provoke arguing and tell everyone he's a genius in his own mind. It's best to just filter his posts out like most of us have already done. I don't know what group you're seeing his post in, but he bugs us in the Perl group all the time, cross posting things that have nothing to do with Perl (same with his cross posts to Python, too). :-) -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From juvy.jumalon at gmail.com Wed Jan 28 22:52:01 2009 From: juvy.jumalon at gmail.com (juvy j) Date: Thu, 29 Jan 2009 11:52:01 +0800 Subject: need help In-Reply-To: <49811D9D.3000805@tim.thechases.com> References: <49811D9D.3000805@tim.thechases.com> Message-ID: Hi tkc, Thanks so much.. it works! :-) I used the urllib. and thanks also to everybody who replied. jtj On Thu, Jan 29, 2009 at 11:08 AM, Tim Chase wrote: > Thanks for you reply. I am newbie in python. >> Im going to use HTTP. >> > > If all you want is to download a file, you might want to look into using > "wget" or "curl" (which work for both HTTP and FTP). E.g. > > bash$ wget http://myothermachine/path/to/file.html > > However, if you need to roll it into a script, Python's urllib module will > do the trick > > >>> import urllib > >>> url = "http://myothermachine/path/to/file.html" > >>> f = urlib.urlopen(url) > >>> out = file('python.txt', 'w') > >>> for line in f: out.write(line) > ... > >>> out.close() > >>> f.close() > > If the content is small, you can just use > > >>> content = f.read() > >>> out.write(content) > > instead of the "for line in f: out.write(line)". If you need to actually > parse the HTML that's returned, the common suggestion is to use the > BeautifulSoup add-on module which has worked for my needs. > > -tkc > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Jan 28 23:12:07 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 29 Jan 2009 04:12:07 -0000 Subject: Exec woes In-Reply-To: <015d01c9811c$c6042e80$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> <015d01c9811c$c6042e80$0d00a8c0@hendrik> Message-ID: On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen wrote: > Stephen Hansen wrote: > >> Exec is a statement, not a function nor an object: even though you can >> enclose parens around its arguments like you do later on, they >> don't have any syntax meaning > > This is actually not correct - it is the root cause of my trouble. > if you write, in a nested scope: > > exec ( "somestring to execute" in globals(),locals()) > > You get the syntax error, as the interpreter somehow sees it as one, > unqualified thing. Well, no. Look at the error Python gives you, nested scope or not: Traceback (most recent call last): File "", line 1, in TypeError: exec: arg 1 must be a string, file, or code object If exec is a function, arg 1 is the boolean expression "somestring to execute" in globals() which is unlikely to be what you want. If exec is a statement, arg 1 is a tuple of two elements, "somestring to execute" in globals() and locals() which is also unlikely to be what you want. Neither of these are giving you a string, file or code object, exactly as the interpreter is telling you. -- Rhodri James *-* Wildebeeste Herder to the Masses From notvalid2 at sbcglobal.net Wed Jan 28 23:12:24 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:12:24 -0800 Subject: Tkinter w.pack()? Message-ID: Where in the world is a description of pack() for Tkinter widgets? Is it some sort of general method for all widgets? I'm looking in a few docs that use it without ever saying where it is described. For one, . In the NM Tech pdf on Tkinter, it's not found anywhere. I see Universal methods for widgets, but no mention of pack(). package, packed, but no pack. While I'm at it, what is w in the result of w = Label(parent, image=photo)? Just a widget pointer, address? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From rt8396 at gmail.com Wed Jan 28 23:28:25 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 20:28:25 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: On Jan 28, 10:12?pm, "W. eWatson" wrote: > Where in the world is a description of pack() for Tkinter widgets? Is it > some sort of general method for all widgets? I'm looking in a few docs that > use it without ever saying where it is described. For one, > . In the NM Tech pdf on Tkinter, > it's not found anywhere. I see Universal methods for widgets, but no mention > of pack(). package, packed, but no pack. did you try here :) http://effbot.org/tkinterbook/pack.htm From rt8396 at gmail.com Wed Jan 28 23:33:23 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 20:33:23 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: To expand on this there exists three geometry mangers [grid, pack, place]. I personally use pack() the most, grid() almost never, and place -- well never. But each one has it's strengths and weaknesses. w.grid() http://effbot.org/tkinterbook/grid.htm w.place() http://effbot.org/tkinterbook/place.htm Everything you need to know about Tkinter exists here: http://effbot.org/tkinterbook/ and at the NMT site i showed you before From steven at REMOVE.THIS.cybersource.com.au Wed Jan 28 23:44:32 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Jan 2009 04:44:32 GMT Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <1405b5d5-00b1-487f-92f7-ba702298db58@v5g2000pre.googlegroups.com> Message-ID: On Wed, 28 Jan 2009 15:20:41 -0800, ocschwar wrote: > On Jan 28, 4:50?pm, Aaron Brady wrote: >> On Jan 28, 2:38?pm, ocsch... at gmail.com wrote: >> >> Hello, quoting myself from another thread today: >> >> There is the 'shelve' module. ?You could create a shelf that tells you >> the filename of the 5 other ones. ?A million keys should be no problem, >> I guess. ?(It's standard library.) ?All your keys have to be strings, >> though, and all your values have to be pickleable. ?If that's a >> problem, yes you will need ZODB or Django (I understand), or another >> relational DB. >> >> There is currently no way to store live objects. > > > The problem is NOT archiving these objects. That works fine. > > It's the computations I'm using these thigns for that are slow, and that > failed to speed up using __slots__. You've profiled and discovered that the computations are slow, not the archiving? What parts of the computations are slow? > What I need is something that will speed up getattr() or its equivalent, > and to a lesser degree setattr() or its equivalent. As you've found, __slots__ is not that thing. >>> class Slotted(object): ... __slots__ = 'a' ... a = 1 ... >>> class Unslotted(object): ... a = 1 ... >>> t1 = Timer('x.a', 'from __main__ import Slotted; x = Slotted()') >>> t2 = Timer('x.a', 'from __main__ import Unslotted; x = Unslotted()') >>> >>> min(t1.repeat(10)) 0.1138761043548584 >>> min(t2.repeat(10)) 0.11414718627929688 One micro-optimization you can do is something like this: for i in xrange(1000000): obj.y = obj.x + 3*obj.x**2 obj.x = obj.y - obj.x # 12 name lookups per iteration Becomes: y = None x = obj.x try: for i in xrange(1000000): y = x + 3*x**2 x = y - x # 6 name lookups per iteration finally: obj.y = y obj.x = x Unless you've profiled and has evidence that the bottleneck is attribute access, my bet is that the problem is some other aspect of the computation. In general, your intuition about what's fast and what's slow in Python will be misleading if you're used to other languages. E.g. in C comparisons are fast and moving data is slow, but in Python comparisons are slow and moving data is fast. -- Steven From notvalid2 at sbcglobal.net Wed Jan 28 23:55:13 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:55:13 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > On Jan 28, 10:12 pm, "W. eWatson" wrote: >> Where in the world is a description of pack() for Tkinter widgets? Is it >> some sort of general method for all widgets? I'm looking in a few docs that >> use it without ever saying where it is described. For one, >> . In the NM Tech pdf on Tkinter, >> it's not found anywhere. I see Universal methods for widgets, but no mention >> of pack(). package, packed, but no pack. > > did you try here :) > http://effbot.org/tkinterbook/pack.htm Thanks. I have the site bookmarked, but it's hard to search. I posted a comment to them that they should have it in pdf form. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Jan 28 23:57:04 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 28 Jan 2009 20:57:04 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > To expand on this there exists three geometry mangers [grid, pack, > place]. I personally use pack() the most, grid() almost never, and > place -- well never. But each one has it's strengths and weaknesses. > > w.grid() > http://effbot.org/tkinterbook/grid.htm > > w.place() > http://effbot.org/tkinterbook/place.htm > > There seems to be a pattern here. :-) > Everything you need to know about Tkinter exists here: > http://effbot.org/tkinterbook/ > > and at the NMT site i showed you before The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Thu Jan 29 00:23:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 03:23:56 -0200 Subject: Tkinter w.pack()? References: Message-ID: En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson escribi?: > The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? There is a PDF version of "An Introduction to Tkinter" here: http://www.pythonware.com/library/ -- Gabriel Genellina From rt8396 at gmail.com Thu Jan 29 00:31:01 2009 From: rt8396 at gmail.com (r) Date: Wed, 28 Jan 2009 21:31:01 -0800 (PST) Subject: Tkinter w.pack()? References: Message-ID: On Jan 28, 10:57?pm, "W. eWatson" wrote: > The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? Only the grid manager is discussed at NMT. I just like how at NMT the widget attributes are in a table and then a list the widget methods follows below that -- much better navigation. I talked again to John at NMT and he assured me very soon he's going to make all the updates. It would probably help if you sent him a nice message of encouragement like -- 'Can you please update the documentation, i really like the sites layout?' -- but please don't forget to thank him for all his contributions to the Python community. I am currently crusading to have all the old Python tuts and documentation updated(among other crusades). This was my second win and i hope that more will follow. The python docs out there need a dusting off and spit shining. From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 00:41:40 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Jan 2009 05:41:40 GMT Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: On Wed, 28 Jan 2009 11:06:21 -0800, Reckoner wrote: > thanks for your reply. > > For the second case where > >> class TaintThing(object): >> parent = A >> def __init__(self, obj): >> self.__dict__['_proxy'] = obj >> def __getattr__(self, attr): >> return getattr(self._proxy, attr) >> def __setattr__(self, attr, value): >> setattr(self._proxy, attr, value) >> self.parent.taint() > > you have told it that parent is 'A'. Shouldn't that be passed to it > somehow in the following: > >> # untested >> class TaintList(list): >> def append(self, obj): >> list.append(self, TaintThing(obj)) >> # similar for __setitem__, extend, insert Sure. Just change the initialisation of TaintThing to something like this: #untested def __init__(self, obj, parent): self.__dict__['_proxy'] = obj self.parent = parent and then TaintList to something like this: def append(self, obj): list.append(self, TaintThing(obj, self)) # similar for __setitem__, extend, insert -- Steven From jjposner at snet.net Thu Jan 29 00:42:36 2009 From: jjposner at snet.net (John Posner) Date: Thu, 29 Jan 2009 00:42:36 -0500 Subject: Tkinter w.pack()? Message-ID: <6C708034172C458696E52D9AF64BBB99@AMDUP> The difference between the fill=, expand=, and anchor= options to the pack() function takes a while to get used to. In brief: * fill= controls the size of a control itself * expand= controls the size of the space into which the pack() function places a control * anchor= comes into play if the size of the space exceeds the size of the control This Google Doc might be helpful: http://docs.google.com/Doc?id=dhmzfrmj_0c685rrdb It shows the effects of progressively adding various fill= and expand= clause within three statements that create and place Button controls. -John E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11640 http://www.pctools.com/en/spyware-doctor-antivirus/ From pdorange at pas-de-pub-merci.mac.com Thu Jan 29 00:52:48 2009 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Thu, 29 Jan 2009 06:52:48 +0100 Subject: Profiling Python Apps on Mac? References: Message-ID: <1iualmh.11cquv31b8stniN%pdorange@pas-de-pub-merci.mac.com> RGK wrote: > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed > xml object I just created horribly bloated or kind of ordinary. python -m profile yourscript.py see -- Pierre-Alain Dorange MicroWar 2.0 : tuez des PC From mail at microcorp.co.za Thu Jan 29 01:06:31 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 08:06:31 +0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: <01d401c981f5$e5e301c0$0d00a8c0@hendrik> "Gabriel Genellina" wrote: >> Seems that it is important *when* those functions are evaluated, but I >> don't understand *why*... Because the scope changes - see also the recent thread on exec woes where towards the end I put in a similar example - funny, it must the flux or something - seems to be the season for calling id on locals() :-) - Hendrik From cournape at gmail.com Thu Jan 29 01:11:26 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 29 Jan 2009 15:11:26 +0900 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: <5b8d13220901282211v7b680d2en95f33119fb1eb39e@mail.gmail.com> On Thu, Jan 29, 2009 at 4:14 AM, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed xml > object I just created horribly bloated or kind of ordinary. > > Is there anything out there I should look into to if I want to see how those > things are affecting my app? The closest I have is the widget iStat, but > it's a very static low resolution view of what's really going on. On Mac OS X, dtrace can sometimes be quite useful. The Apple-provided python has the necessary 'probes'. http://blogs.sun.com/binujp/entry/dtrace_provider_for_python There are some useful scripts in the dtrace toolkit geared toward python: http://www.brendangregg.com/dtrace.html#DTraceToolkit If you want dtrace support for a bare python (built from sources), I made a quick patch, "documented" here: http://cournape.wordpress.com/?s=dtrace I don't know if it works for 2.6 (I doubt it would work out of the box - I don't claim any understanding of dtrace internals, I just applied the apple patches, removing all the apple specifics I did not care about). David From misterwang at gmail.com Thu Jan 29 01:17:01 2009 From: misterwang at gmail.com (Peter Wang) Date: Wed, 28 Jan 2009 22:17:01 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> On Jan 27, 3:16?pm, Reckoner wrote: > I'm not sure this is possible, but I would like to have > a list of ?objects > > A=[a,b,c,d,...,z] > > where, ?in the midst of a lot of processing I might do something like, > > A[0].do_something_which_changes_the_properties() > > which alter the properties of the object 'a'. > > The trick is that I would like A to be mysteriously aware that > something about the ?object 'a' has changed so that when I revisit A, > I will know that the other items in the list need to be refreshed to > reflect the changes in A as a result of changing 'a'. > > Even better would be to automatically percolate the subsequent changes > that resulted from altering 'a' for the rest of the items in the list. > Naturally, all of these items are related in some parent-child > fashion. > > that might be a lot to ask, however. > > Any advice appreciated. You should really look at Enthought's Traits package. It does exactly what you are asking for, and much, much more. See: http://code.enthought.com/projects/traits/documentation.php http://code.enthought.com/projects/traits/examples.php Using Traits, you could do the following: from enthought.traits.api import * class Child(HasTraits): state = Enum("happy", "sad", "bawling") class Parent(HasTraits): child = Instance(Child) @on_trait_change('child.state') def handler(self): print "new child state:", self.child.state bob_jr = Child() bob = Parent(child = bob_jr) bob_jr.state = "sad" # This would result in bob.handler() being called (Disclosure: I work at Enthought and have been using Traits heavily for the last 4+ years.) -Peter From michele.simionato at gmail.com Thu Jan 29 01:17:12 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) Subject: dicts,instances,containers, slotted instances, et cetera. References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> Message-ID: <917c70b6-e7d3-4b2e-855d-829cdd03ff01@s36g2000vbp.googlegroups.com> On Jan 29, 12:23?am, ocsch... at gmail.com wrote: > I just find it odd that there's no quick answer on the > fastest way in Python to implement a mapping in this context. A Python dict is as fast as you can get. If that is not enough, your only choice is to try something at the C level, which may give the desired speedup or not. Good luck! Michele Simionato From asmodai at in-nomine.org Thu Jan 29 01:31:54 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Thu, 29 Jan 2009 07:31:54 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <457dcbbb-b5c4-414a-903b-f19ac4cac4a9@r32g2000vba.googlegroups.com> <1ec39390-ad18-42cf-b669-1869af62a1db@k36g2000pri.googlegroups.com> Message-ID: <20090129063154.GS99614@nexus.in-nomine.org> -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: >If that's correct, it would be great if there were a Werkzeug tutorial >on deploying it for use with CGI. There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look in the servers directory in the repository. I'll double check the documentation and expand where necessary. [1] http://zine.pocoo.org/ -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From robert.kern at gmail.com Thu Jan 29 01:47:46 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jan 2009 00:47:46 -0600 Subject: Profiling Python Apps on Mac? In-Reply-To: References: Message-ID: On 2009-01-28 13:14, RGK wrote: > I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & > wxPython under OSX 10.4) > > As I make program architecture decisions, it would be nice to be able to > profile the choices. Should I add that extra thread? Is this big-assed > xml object I just created horribly bloated or kind of ordinary. > > Is there anything out there I should look into to if I want to see how > those things are affecting my app? The closest I have is the widget > iStat, but it's a very static low resolution view of what's really going > on. I have a script kernprof.py which provides a few conveniences over the builtin cProfile module. One of its modes of operation is to inject a decorator into the __builtins__. It will enable the profiler on entry to the method and disable it on exit. This lets you localize your profile results to just the part of your code that you are interested in. I found this especially useful in GUI apps which require user interaction to trigger the part of the code you are actually interesting in profiling. You don't want the interesting parts of your profile to be obscured by the GUI event loop waiting for your input. You can get it as part of my line_profiler package (which you may also be interested in; cProfile profiles function calls, line_profiler profiles individual lines). http://pypi.python.org/pypi/line_profiler You can view the profile results interactively with "python -m pstats my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install kcachegrind on your system: http://www.vrplumber.com/programming/runsnakerun/ http://pypi.python.org/pypi/pyprof2calltree/1.1.0 I don't recommend using hotshot because it is deprecated and slow to postprocess the data dumps. Also, I don't recommend using the plain profile module because it slows down your program rather more than cProfile. See the Python documentation for an overview of these modules: http://docs.python.org/library/profile -- 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 tino at wildenhain.de Thu Jan 29 01:59:58 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 29 Jan 2009 07:59:58 +0100 Subject: Results of executing hyperlink in script In-Reply-To: <49811E50.7010809@tim.thechases.com> References: <49811E50.7010809@tim.thechases.com> Message-ID: <498153EE.6040600@wildenhain.de> Tim Chase wrote: >> 1. This method was suggested by Cameron Laird: >> >> os.system("start %s" % URL) >> >> It works. But, if the URL contains character &, it will fail. For > > > As an aside, the START command is a bit picky regarding quotes. You have > to use this horrible contortion > > os.system('start "title" "%s"' % URL) > > The "title" is optional content-wise, but required positionally if > there's a quoted resource, so you can just use > > start "" "%s" > > a pain, but that's CMD.EXE for you. :) ah, and just for the records, at least os.popen2,os.popen3 support tuple as argument: i,o=os.popen2((cmd,arg1,arg2)) and quotes them correctly. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mail at microcorp.co.za Thu Jan 29 02:14:41 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 09:14:41 +0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> "Gabriel Genellina" wrote: En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels > escribi?: > >> The reason is that once your created object has its id taken, you >> must keep a handle on it, otherwise it may get recycled and reused. > >It doesn't matter in this case, I think. globals() is always the same >object and is alive during the whole test. So something having the same >id() than globals() must be the very same object, and something having a >different id() than globals() cannot be the same object. > >If you like, I can rewrite the example without using id(): > >>>> L = list(n for n in [globals(),locals()]) >>>> L[0] is L[1] >True >>>> L = list(n() for n in [globals,locals]) >>>> L[0] is L[1] >False > >(I *think* this has to do with free variables in the "right side" (after >the "in" keyword) of a generator expression; they appear to be evaluated >when the expression is *defined*, not when is is *used*. By contrast, free >variables in the "left side" appear to be evaluated when the expression is >used.) > Yikes! this is, IMO, far too complicated a way of looking at it. I think that if you rewrite the "comprehensions" as loops, you will see what is happening. - in the one case, the locals() returned is from the outer scope, while in the other the locals function is called from inside the loop - a different scope, because there must be *somewhere* where the state is kept to yield the next value. If you nest the thing inside something else, then globals() and locals() won't be the same, but the two locals() will still differ. I find it very confusing because locals is always the same function - but what it returns varies depending on where you call it from. So if you want to pass it around, it's no good passing the function - you have to pass the returned result, *called from the scope of interest*. Subtle stuff. - Hendrik From afriere at yahoo.co.uk Thu Jan 29 02:15:23 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) Subject: I'm a python addict ! References: <96a0a6a3-53cd-4a4d-b5b0-a1f93acec1cf@n33g2000pri.googlegroups.com> Message-ID: <8d075393-ba38-4f9e-b1ca-98c642b414a6@r10g2000prf.googlegroups.com> On Jan 27, 4:52?am, Paul McGuire wrote: [snip] > > ? ? # how you have to do it in C++ and Java > ? ? # light = light.next_state() > > ? ? # using Python > ? ? light.__class__ = light.next_state I'm sure you can, but why poke yourself in the eye with a blunt stick? ;) IMO there are two obvious problems with the latter approach. Firstly the information about the next state is left lying about in some namespace separate from the object, whereas the object itself ought to know what it's 'next_state' is (or, more correctly, how to determine it). Secondly you miss the opportunity of sending a signal to the new state. Consider that in some jurisdictions the amber light shows before the green as well as before the red (yeah, I know is that an invitation for drag racing or what!?). If you called next_state as a verb you could pass the current state as an argument and the amber (or yellow, if you prefer) light could work which of the two possible next states to call in turn. The fact that this behaviour is, in this example, peculiar to the amber light, demonstrates the pertinence of my first objection above. Fortunately the "C++ and Java" approach, (though I would never want to be seen advocating the C++ or Java approach to anything), is in this case available in Python as well, at the cheaper price of fewer characters and arguably greater readibility to boot. I know, Iknow ... you wanted to show how that code could be used in a non "sulphurous" way. Which just goes to show that the devil makes work for idle hands ... or foils the best laid plans ... or is in the detail ... or something sulphurous. :) From mail at microcorp.co.za Thu Jan 29 03:15:57 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 29 Jan 2009 10:15:57 +0200 Subject: Exec woes References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik><7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com><015d01c9811c$c6042e80$0d00a8c0@hendrik> Message-ID: <01d601c981f5$e721ea60$0d00a8c0@hendrik> "Rhodri James" wrote: To: Sent: Thursday, January 29, 2009 6:12 AM Subject: Re: Exec woes > On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen > wrote: > > This is actually not correct - it is the root cause of my trouble. > > if you write, in a nested scope: > > > > exec ( "somestring to execute" in globals(),locals()) > > > > You get the syntax error, as the interpreter somehow sees it as one, > > unqualified thing. > > Well, no. Look at the error Python gives you, nested scope or not: > > Traceback (most recent call last): > File "", line 1, in > TypeError: exec: arg 1 must be a string, file, or code object > > If exec is a function, arg 1 is the boolean expression > "somestring to execute" in globals() > which is unlikely to be what you want. If exec is a statement, > arg 1 is a tuple of two elements, > "somestring to execute" in globals() > and > locals() > which is also unlikely to be what you want. Neither of these are > giving you a string, file or code object, exactly as the interpreter > is telling you. Well, no - I stick by my assertion, about the nested scope: >>> def rubbish(): def deep_rubbish(): exec('BUILD = "somestring"' in globals(),locals()) SyntaxError: unqualified exec is not allowed in function 'deep_rubbish' it is a nested function (, line 3) >>> That is all I was saying - It was the brackets that buggered me, and adding the globals() and locals() inside the brackets, inside the nested scope, makes no difference - the interpreter sees it as an unqualified exec. Did you actually try it in a nested scope before asserting "nested scope or not" ? If you just do, in the outside scope, the thing I did originally: >>> exec('BUILD = "foobar"') >>> BUILD 'foobar' >>> Then the brackets are ignored, and the defaults kick in. But this is silly nit picking around the basic error, which was to treat the thing as a function and putting the brackets there. The other bits in the thread, about the scopes and locals() are far more interesting. - Hendrik From info at egenix.com Thu Jan 29 03:37:49 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 29 Jan 2009 09:37:49 +0100 Subject: ANN: eGenix mx Base Distribution 3.1.2 Message-ID: <49816ADD.2040705@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.1.2 for Python 2.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.1.2-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.1.2 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. We have fixed a number of small platform issues and added support for the strptime() function to mxDateTime on Windows. We have also enhanced the portability of our pre-built Mac OS X binaries. As always, we are providing pre-built binaries for all supported platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler to be installed. For a list of changes, please refer to the eGenix mx Base Distribution change log at http://www.egenix.com/products/python/mxBase/changelog.html and the change logs of the various included Python packages. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the packages can be found on the eGenix mx Base Distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ LICENSE The eGenix mx Base package is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use the packages in both commercial and non-commercial settings without fee or charge. The package comes with full source code ________________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mal at egenix.com Thu Jan 29 03:57:55 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 29 Jan 2009 09:57:55 +0100 Subject: date handling problem In-Reply-To: References: Message-ID: <49816F93.8080101@egenix.com> On 2009-01-29 03:38, Gabriel Genellina wrote: > En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva > escribi?: > >> I need to parse rss-feeds based on time stamp,But rss-feeds follow >> different >> standards of date(IST,EST etc). >> I dont know,how to standardize this standards.It will be helpful if >> you can >> hint me. > > You may find the Olson timezone database useful. > http://pytz.sourceforge.net/ Or have a look at the date/time parser in mxDateTime: http://www.egenix.com/products/python/mxBase/mxDateTime/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:03:29 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:03:29 +0100 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <498170d4$0$23718$426a74cc@news.free.fr> Ron Garret a ?crit : > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > whenever I restart the server after making a code change it takes a very > long time (like a minute) before the script is active again. In other > words, I do an apachectl restart, reload the page in my browser, and one > minute later it finally comes up. During this time CPU usage is > essentially zero. Loading all the code manually into a python > interpreter is virtually instantaneous, and all subsequence interactions > with the app are very fast. > > Does anyone have any ideas what might be going on or how to debug this? Restarting apache (with or without mod_wsgi) can by itself take some time. Now, if you're running mod_wsgi in daemon mode, you _don't_ have to restart apache to reload your code - just touch the wsgi script file and you'll be done, ie with: WSGIProcessGroup myproject.tld WSGIDaemonProcess myproject.tld user=you group=you WSGIReloadMechanism Process WSGIScriptAlias / /var/www/myproject/apache/myapp.py you just have to touch myapp.py to force reload the subinterpreter(s). From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:06:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:06:58 +0100 Subject: Sloooooowwwww WSGI restart In-Reply-To: References: Message-ID: <498171a5$0$3681$426a74cc@news.free.fr> Ron Garret a ?crit : > In article , > Aleksandar Radulovic wrote: (snip) >> Secondly, why are you restarting apache after code changes? In normal >> circumstances, you shouldn't have to do that. > > I thought (and experiment confirms) that only the main WSGI app file > gets reloaded automatically when it changes, not the libraries. Depends on how you configure mod_wsgi. Read the part about "Process Reloading Mechanism" here: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode From tomanishkb at gmail.com Thu Jan 29 04:08:20 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 14:38:20 +0530 Subject: Python-list Digest, Vol 64, Issue 644 In-Reply-To: References: Message-ID: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> is python a pure objected oriented language? On Thu, Jan 29, 2009 at 2:08 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: dicts,instances,containers, slotted instances, et cetera. > (Michele Simionato) > 2. Re: Recommendation for a small web framework like Perl's > CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven) > 3. Re: Profiling Python Apps on Mac? (Robert Kern) > 4. Re: Results of executing hyperlink in script (Tino Wildenhain) > 5. Re: I'm a python addict ! (afriere at yahoo.co.uk) > 6. ANN: eGenix mx Base Distribution 3.1.2 > (eGenix Team: M.-A. Lemburg) > > > ---------- Forwarded message ---------- > From: Michele Simionato > To: python-list at python.org > Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) > Subject: Re: dicts,instances,containers, slotted instances, et cetera. > On Jan 29, 12:23 am, ocsch... at gmail.com wrote: > > > I just find it odd that there's no quick answer on the > > fastest way in Python to implement a mapping in this context. > > A Python dict is as fast as you can get. If that is not enough, your > only choice is to try something at the C level, which may give the > desired speedup or not. Good luck! > > Michele Simionato > > > > ---------- Forwarded message ---------- > From: Jeroen Ruigrok van der Werven > To: excord80 > Date: Thu, 29 Jan 2009 07:31:54 +0100 > Subject: Re: Recommendation for a small web framework like Perl's > CGI::Application to run as CGI? > -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: > >If that's correct, it would be great if there were a Werkzeug tutorial > >on deploying it for use with CGI. > > There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look > in the servers directory in the repository. > > I'll double check the documentation and expand where necessary. > > [1] http://zine.pocoo.org/ > > -- > Jeroen Ruigrok van der Werven / asmodai > ????? ?????? ??? ?? ?????? > http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B > Earth to earth, ashes to ashes, dust to dust... > > > > ---------- Forwarded message ---------- > From: Robert Kern > To: python-list at python.org > Date: Thu, 29 Jan 2009 00:47:46 -0600 > Subject: Re: Profiling Python Apps on Mac? > On 2009-01-28 13:14, RGK wrote: > >> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & >> wxPython under OSX 10.4) >> >> As I make program architecture decisions, it would be nice to be able to >> profile the choices. Should I add that extra thread? Is this big-assed >> xml object I just created horribly bloated or kind of ordinary. >> >> Is there anything out there I should look into to if I want to see how >> those things are affecting my app? The closest I have is the widget >> iStat, but it's a very static low resolution view of what's really going >> on. >> > > I have a script kernprof.py which provides a few conveniences over the > builtin cProfile module. One of its modes of operation is to inject a > decorator into the __builtins__. It will enable the profiler on entry to the > method and disable it on exit. This lets you localize your profile results > to just the part of your code that you are interested in. I found this > especially useful in GUI apps which require user interaction to trigger the > part of the code you are actually interesting in profiling. You don't want > the interesting parts of your profile to be obscured by the GUI event loop > waiting for your input. > > You can get it as part of my line_profiler package (which you may also be > interested in; cProfile profiles function calls, line_profiler profiles > individual lines). > > http://pypi.python.org/pypi/line_profiler > > You can view the profile results interactively with "python -m pstats > my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install > kcachegrind on your system: > > http://www.vrplumber.com/programming/runsnakerun/ > http://pypi.python.org/pypi/pyprof2calltree/1.1.0 > > I don't recommend using hotshot because it is deprecated and slow to > postprocess the data dumps. Also, I don't recommend using the plain profile > module because it slows down your program rather more than cProfile. See the > Python documentation for an overview of these modules: > > http://docs.python.org/library/profile > > -- > 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 > > > > > ---------- Forwarded message ---------- > From: Tino Wildenhain > To: Tim Chase > Date: Thu, 29 Jan 2009 07:59:58 +0100 > Subject: Re: Results of executing hyperlink in script > Tim Chase wrote: > >> 1. This method was suggested by Cameron Laird: >>> >>> os.system("start %s" % URL) >>> >>> It works. But, if the URL contains character &, it will fail. For >>> >> >> >> As an aside, the START command is a bit picky regarding quotes. You have >> to use this horrible contortion >> >> os.system('start "title" "%s"' % URL) >> >> The "title" is optional content-wise, but required positionally if there's >> a quoted resource, so you can just use >> >> start "" "%s" >> >> a pain, but that's CMD.EXE for you. :) >> > > ah, and just for the records, at least > os.popen2,os.popen3 support tuple as argument: > > i,o=os.popen2((cmd,arg1,arg2)) and quotes them > correctly. > > Regards > Tino > > > ---------- Forwarded message ---------- > From: afriere at yahoo.co.uk > To: python-list at python.org > Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) > Subject: Re: I'm a python addict ! > On Jan 27, 4:52 am, Paul McGuire wrote: > [snip] > > > > # how you have to do it in C++ and Java > > # light = light.next_state() > > > > # using Python > > light.__class__ = light.next_state > > I'm sure you can, but why poke yourself in the eye with a blunt > stick? ;) > > IMO there are two obvious problems with the latter approach. Firstly > the information about the next state is left lying about in some > namespace separate from the object, whereas the object itself ought to > know what it's 'next_state' is (or, more correctly, how to determine > it). > > Secondly you miss the opportunity of sending a signal to the new > state. Consider that in some jurisdictions the amber light shows > before the green as well as before the red (yeah, I know is that an > invitation for drag racing or what!?). If you called next_state as a > verb you could pass the current state as an argument and the amber (or > yellow, if you prefer) light could work which of the two possible next > states to call in turn. The fact that this behaviour is, in this > example, peculiar to the amber light, demonstrates the pertinence of > my first objection above. > > Fortunately the "C++ and Java" approach, (though I would never want to > be seen advocating the C++ or Java approach to anything), is in this > case available in Python as well, at the cheaper price of fewer > characters and arguably greater readibility to boot. > > I know, Iknow ... you wanted to show how that code could be used in a > non "sulphurous" way. Which just goes to show that the devil makes > work for idle hands ... or foils the best laid plans ... or is in the > detail ... or something sulphurous. :) > > > > ---------- Forwarded message ---------- > From: "eGenix Team: M.-A. Lemburg" > To: "Python List @ Python.org" > Date: Thu, 29 Jan 2009 09:37:49 +0100 > Subject: ANN: eGenix mx Base Distribution 3.1.2 > ________________________________________________________________________ > > ANNOUNCING > > eGenix.com mx Base Distribution > > Version 3.1.2 for Python 2.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.1.2-GA.html > > ________________________________________________________________________ > > ABOUT > > The eGenix.com mx Base Distribution for Python is a collection of > professional quality software tools which enhance Python's usability > in many important areas such as fast text searching, date/time > processing and high speed data types. > > The tools have a proven record of being portable across many Unix and > Windows platforms. You can write applications which use the tools on > Windows and then run them on Unix platforms without change due to the > consistent platform independent interfaces. > > Contents of the distribution: > > * mxDateTime - Date/Time Library for Python > * mxTextTools - Fast Text Parsing and Processing Tools for Python > * mxProxy - Object Access Control for Python > * mxBeeBase - On-disk B+Tree Based Database Kit for Python > * mxURL - Flexible URL Data-Type for Python > * mxUID - Fast Universal Identifiers for Python > * mxStack - Fast and Memory-Efficient Stack Type for Python > * mxQueue - Fast and Memory-Efficient Queue Type for Python > * mxTools - Fast Everyday Helpers for Python > > All available packages have proven their stability and usefulness in > many mission critical applications and various commercial settings all > around the world. > > For more information, please see the distribution page: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > NEWS > > The 3.1.2 release of the eGenix mx Base Distribution is the latest > release of our open-source Python extensions. > > We have fixed a number of small platform issues and added support for > the strptime() function to mxDateTime on Windows. We have also enhanced > the portability of our pre-built Mac OS X binaries. > > As always, we are providing pre-built binaries for all supported > platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, > FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. > > Whether you are using a pre-built package or the source distribution, > installation is a simple "python setup.py install" command in all > cases. The only difference is that the pre-built packages do not > require a compiler to be installed. > > For a list of changes, please refer to the eGenix mx Base Distribution > change log at > > http://www.egenix.com/products/python/mxBase/changelog.html > > and the change logs of the various included Python packages. > > ________________________________________________________________________ > > DOWNLOADS > > The download archives and instructions for installing the packages can > be found on the eGenix mx Base Distribution page: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > LICENSE > > The eGenix mx Base package is distributed under the eGenix.com Public > License 1.1.0 which is an Open Source license similar to the Python > license. You can use the packages in both commercial and non-commercial > settings without fee or charge. > > The package comes with full source code > > ________________________________________________________________________ > > SUPPORT > > Commercial support for this product is available from eGenix.com. > Please see > > http://www.egenix.com/services/support/ > > for details about our support offerings. > > Enjoy, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Jan 29 2009) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 04:14:59 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 10:14:59 +0100 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? In-Reply-To: <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> <49802c05$0$5139$426a34cc@news.free.fr> <9168a572-554e-435e-875c-a46ff01f1077@k36g2000pri.googlegroups.com> Message-ID: <49817386$0$24403$426a34cc@news.free.fr> excord80 a ?crit : > On Jan 28, 4:57 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: > >> What about:http://thraxil.org/code/cgi_app/ >> >> (yes, it is a port of CGI::Application, and FWIW it's mentionned on the >> CGI::Application's wiki). >> > > Nice find. Thank you. Interesting project. It seems to be only one > fairly short file (perhaps that's all it takes), It is. And given the intended context (CGI...), it's a GoodThing !-) > and its most recent > release was in 2004. No mailing list. Nope. But does it need new release or a mailing list ? As you say, it's just a pretty simple module. The point is that you are very likely to fork it for your own needs anyway - so see it as a good starting point for a simple lightweight CGI/mod_python (and why not WSGI) framework. From alex at a13x.net Thu Jan 29 04:15:27 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Thu, 29 Jan 2009 09:15:27 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> Message-ID: <845b10c50901290115s10b0b3c5qa5e30c87ea83998b@mail.gmail.com> Graham, On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton wrote: > Sorry, you are wrong to assume that an Apache restart is not be > required. > If you are using mod_wsgi embedded mode, or mod_python, then a code > change will always require a full restart of Apache. I am running several middleware apps I'm working on under mod_python (simple setup using mod_python.publisher handler) and so far, haven't had the reason to restart apache at all. > Thus, the conjecture that Apache/mod_wsgi cannot be used and that > CherryPy WSGI server or Paster server must be used when developing a > Python web application is false. If using mod_wsgi then daemon mode Not sure what (or whom) you're referring to. IMO, developing TG/Pylons/Django apps is much convinient with embedded web server (cherrypy or paster) as it is possible to do rapid development without resorting to restarts. Example with Pylons: $ paster serve development.ini --reload This will start a subprocess which monitors file changes. Regards, alex. -- a lex 13 x http://www.a13x.info From clp2 at rebertia.com Thu Jan 29 04:40:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 01:40:00 -0800 Subject: Python-list Digest, Vol 64, Issue 644 In-Reply-To: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> References: <783b47270901290108q570ebfacpc2898dd87a438982@mail.gmail.com> Message-ID: <50697b2c0901290140w12bcd121kf555c4f7999f41ec@mail.gmail.com> On Thu, Jan 29, 2009 at 1:08 AM, M Kumar wrote: > is python a pure objected oriented language? Firstly: (A) Replying to Digests rather than individual posts is very discouraged. (B) The proper way to start a new thread by emailing python-list at python.org (as it says in the very header of the digest!), not by replying to unrelated posts. And now to your question: Yes, Python is completely object-oriented in the Smalltalk sense; everything is an object, there are no "primitive types" or non-object values, in contrast to, say, Java. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > On Thu, Jan 29, 2009 at 2:08 PM, wrote: >> >> Send Python-list mailing list submissions to >> python-list at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.python.org/mailman/listinfo/python-list >> or, via email, send a message with subject or body 'help' to >> python-list-request at python.org >> >> You can reach the person managing the list at >> python-list-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Python-list digest..." >> >> Today's Topics: >> >> 1. Re: dicts,instances,containers, slotted instances, et cetera. >> (Michele Simionato) >> 2. Re: Recommendation for a small web framework like Perl's >> CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven) >> 3. Re: Profiling Python Apps on Mac? (Robert Kern) >> 4. Re: Results of executing hyperlink in script (Tino Wildenhain) >> 5. Re: I'm a python addict ! (afriere at yahoo.co.uk) >> 6. ANN: eGenix mx Base Distribution 3.1.2 >> (eGenix Team: M.-A. Lemburg) >> >> >> ---------- Forwarded message ---------- >> From: Michele Simionato >> To: python-list at python.org >> Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST) >> Subject: Re: dicts,instances,containers, slotted instances, et cetera. >> On Jan 29, 12:23 am, ocsch... at gmail.com wrote: >> >> > I just find it odd that there's no quick answer on the >> > fastest way in Python to implement a mapping in this context. >> >> A Python dict is as fast as you can get. If that is not enough, your >> only choice is to try something at the C level, which may give the >> desired speedup or not. Good luck! >> >> Michele Simionato >> >> >> >> ---------- Forwarded message ---------- >> From: Jeroen Ruigrok van der Werven >> To: excord80 >> Date: Thu, 29 Jan 2009 07:31:54 +0100 >> Subject: Re: Recommendation for a small web framework like Perl's >> CGI::Application to run as CGI? >> -On [20090128 20:36], excord80 (excord80 at gmail.com) wrote: >> >If that's correct, it would be great if there were a Werkzeug tutorial >> >on deploying it for use with CGI. >> >> There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look >> in the servers directory in the repository. >> >> I'll double check the documentation and expand where necessary. >> >> [1] http://zine.pocoo.org/ >> >> -- >> Jeroen Ruigrok van der Werven / asmodai >> ????? ?????? ??? ?? ?????? >> http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B >> Earth to earth, ashes to ashes, dust to dust... >> >> >> >> ---------- Forwarded message ---------- >> From: Robert Kern >> To: python-list at python.org >> Date: Thu, 29 Jan 2009 00:47:46 -0600 >> Subject: Re: Profiling Python Apps on Mac? >> On 2009-01-28 13:14, RGK wrote: >>> >>> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & >>> wxPython under OSX 10.4) >>> >>> As I make program architecture decisions, it would be nice to be able to >>> profile the choices. Should I add that extra thread? Is this big-assed >>> xml object I just created horribly bloated or kind of ordinary. >>> >>> Is there anything out there I should look into to if I want to see how >>> those things are affecting my app? The closest I have is the widget >>> iStat, but it's a very static low resolution view of what's really going >>> on. >> >> I have a script kernprof.py which provides a few conveniences over the >> builtin cProfile module. One of its modes of operation is to inject a >> decorator into the __builtins__. It will enable the profiler on entry to the >> method and disable it on exit. This lets you localize your profile results >> to just the part of your code that you are interested in. I found this >> especially useful in GUI apps which require user interaction to trigger the >> part of the code you are actually interesting in profiling. You don't want >> the interesting parts of your profile to be obscured by the GUI event loop >> waiting for your input. >> >> You can get it as part of my line_profiler package (which you may also be >> interested in; cProfile profiles function calls, line_profiler profiles >> individual lines). >> >> http://pypi.python.org/pypi/line_profiler >> >> You can view the profile results interactively with "python -m pstats >> my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install >> kcachegrind on your system: >> >> http://www.vrplumber.com/programming/runsnakerun/ >> http://pypi.python.org/pypi/pyprof2calltree/1.1.0 >> >> I don't recommend using hotshot because it is deprecated and slow to >> postprocess the data dumps. Also, I don't recommend using the plain profile >> module because it slows down your program rather more than cProfile. See the >> Python documentation for an overview of these modules: >> >> http://docs.python.org/library/profile >> >> -- >> 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 >> >> >> >> >> ---------- Forwarded message ---------- >> From: Tino Wildenhain >> To: Tim Chase >> Date: Thu, 29 Jan 2009 07:59:58 +0100 >> Subject: Re: Results of executing hyperlink in script >> Tim Chase wrote: >>>> >>>> 1. This method was suggested by Cameron Laird: >>>> >>>> os.system("start %s" % URL) >>>> >>>> It works. But, if the URL contains character &, it will fail. For >>> >>> >>> As an aside, the START command is a bit picky regarding quotes. You have >>> to use this horrible contortion >>> >>> os.system('start "title" "%s"' % URL) >>> >>> The "title" is optional content-wise, but required positionally if >>> there's a quoted resource, so you can just use >>> >>> start "" "%s" >>> >>> a pain, but that's CMD.EXE for you. :) >> >> ah, and just for the records, at least >> os.popen2,os.popen3 support tuple as argument: >> >> i,o=os.popen2((cmd,arg1,arg2)) and quotes them >> correctly. >> >> Regards >> Tino >> >> >> ---------- Forwarded message ---------- >> From: afriere at yahoo.co.uk >> To: python-list at python.org >> Date: Wed, 28 Jan 2009 23:15:23 -0800 (PST) >> Subject: Re: I'm a python addict ! >> On Jan 27, 4:52 am, Paul McGuire wrote: >> [snip] >> > >> > # how you have to do it in C++ and Java >> > # light = light.next_state() >> > >> > # using Python >> > light.__class__ = light.next_state >> >> I'm sure you can, but why poke yourself in the eye with a blunt >> stick? ;) >> >> IMO there are two obvious problems with the latter approach. Firstly >> the information about the next state is left lying about in some >> namespace separate from the object, whereas the object itself ought to >> know what it's 'next_state' is (or, more correctly, how to determine >> it). >> >> Secondly you miss the opportunity of sending a signal to the new >> state. Consider that in some jurisdictions the amber light shows >> before the green as well as before the red (yeah, I know is that an >> invitation for drag racing or what!?). If you called next_state as a >> verb you could pass the current state as an argument and the amber (or >> yellow, if you prefer) light could work which of the two possible next >> states to call in turn. The fact that this behaviour is, in this >> example, peculiar to the amber light, demonstrates the pertinence of >> my first objection above. >> >> Fortunately the "C++ and Java" approach, (though I would never want to >> be seen advocating the C++ or Java approach to anything), is in this >> case available in Python as well, at the cheaper price of fewer >> characters and arguably greater readibility to boot. >> >> I know, Iknow ... you wanted to show how that code could be used in a >> non "sulphurous" way. Which just goes to show that the devil makes >> work for idle hands ... or foils the best laid plans ... or is in the >> detail ... or something sulphurous. :) >> >> >> >> ---------- Forwarded message ---------- >> From: "eGenix Team: M.-A. Lemburg" >> To: "Python List @ Python.org" >> Date: Thu, 29 Jan 2009 09:37:49 +0100 >> Subject: ANN: eGenix mx Base Distribution 3.1.2 >> ________________________________________________________________________ >> >> ANNOUNCING >> >> eGenix.com mx Base Distribution >> >> Version 3.1.2 for Python 2.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.1.2-GA.html >> >> ________________________________________________________________________ >> >> ABOUT >> >> The eGenix.com mx Base Distribution for Python is a collection of >> professional quality software tools which enhance Python's usability >> in many important areas such as fast text searching, date/time >> processing and high speed data types. >> >> The tools have a proven record of being portable across many Unix and >> Windows platforms. You can write applications which use the tools on >> Windows and then run them on Unix platforms without change due to the >> consistent platform independent interfaces. >> >> Contents of the distribution: >> >> * mxDateTime - Date/Time Library for Python >> * mxTextTools - Fast Text Parsing and Processing Tools for Python >> * mxProxy - Object Access Control for Python >> * mxBeeBase - On-disk B+Tree Based Database Kit for Python >> * mxURL - Flexible URL Data-Type for Python >> * mxUID - Fast Universal Identifiers for Python >> * mxStack - Fast and Memory-Efficient Stack Type for Python >> * mxQueue - Fast and Memory-Efficient Queue Type for Python >> * mxTools - Fast Everyday Helpers for Python >> >> All available packages have proven their stability and usefulness in >> many mission critical applications and various commercial settings all >> around the world. >> >> For more information, please see the distribution page: >> >> http://www.egenix.com/products/python/mxBase/ >> >> ________________________________________________________________________ >> >> NEWS >> >> The 3.1.2 release of the eGenix mx Base Distribution is the latest >> release of our open-source Python extensions. >> >> We have fixed a number of small platform issues and added support for >> the strptime() function to mxDateTime on Windows. We have also enhanced >> the portability of our pre-built Mac OS X binaries. >> >> As always, we are providing pre-built binaries for all supported >> platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit, >> FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC. >> >> Whether you are using a pre-built package or the source distribution, >> installation is a simple "python setup.py install" command in all >> cases. The only difference is that the pre-built packages do not >> require a compiler to be installed. >> >> For a list of changes, please refer to the eGenix mx Base Distribution >> change log at >> >> http://www.egenix.com/products/python/mxBase/changelog.html >> >> and the change logs of the various included Python packages. >> >> ________________________________________________________________________ >> >> DOWNLOADS >> >> The download archives and instructions for installing the packages can >> be found on the eGenix mx Base Distribution page: >> >> http://www.egenix.com/products/python/mxBase/ >> >> ________________________________________________________________________ >> >> LICENSE >> >> The eGenix mx Base package is distributed under the eGenix.com Public >> License 1.1.0 which is an Open Source license similar to the Python >> license. You can use the packages in both commercial and non-commercial >> settings without fee or charge. >> >> The package comes with full source code >> >> ________________________________________________________________________ >> >> SUPPORT >> >> Commercial support for this product is available from eGenix.com. >> Please see >> >> http://www.egenix.com/services/support/ >> >> for details about our support offerings. >> >> Enjoy, >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source (#1, Jan 29 2009) >> >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >> >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >> >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ >> ________________________________________________________________________ >> >> ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: >> >> >> eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 >> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg >> Registered at Amtsgericht Duesseldorf: HRB 46611 >> http://www.egenix.com/company/contact/ >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are interested > to be a part of it, please mail or call me. I will be happy to share and > inform - http://www.comat.com > > -- > http://mail.python.org/mailman/listinfo/python-list From jstroud at mbi.ucla.edu Thu Jan 29 04:52:57 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 29 Jan 2009 01:52:57 -0800 Subject: dicts,instances,containers, slotted instances, et cetera. In-Reply-To: <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> References: <2f227bb9-3ed7-47fb-8212-ec5ad76c60c1@n33g2000pri.googlegroups.com> <6uc42lFcmn4iU1@mid.uni-berlin.de> <1dc83c00-5797-4b7e-94a4-8509c01c7eb0@40g2000prx.googlegroups.com> Message-ID: ocschwar at gmail.com wrote: > I can't port the entire app to be a stored database procedure. Perhaps I underestimate what you mean by this, but you may want to look at pyTables (http://www.pytables.org/moin/HowToUse). > ctypes, maybe. I just find it odd that there's no quick answer on the > fastest way in Python to implement a mapping in this context. Your explanation of where your prototype is slow is a little unclear. If your data is largely numerical, you may want to rethink your organization and use a numeric package. I did something similar and saw an order of magnitude speed increase by switching from python data types to numpy combined with careful tuning of how I managed the data. You may have to spend more time on this than you would like, but if you really put some thought into it and grind at your organization, you can probably get a significant performance increase. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From tomanishkb at gmail.com Thu Jan 29 05:01:40 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 15:31:40 +0530 Subject: is python Object oriented?? Message-ID: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Object oriented languages doesn't allow execution of the code without class objects, what is actually happening when we execute some piece of code, is it bound to any class? Those who have time and consideration can help me -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.selvamsiva at gmail.com Thu Jan 29 05:17:52 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 29 Jan 2009 15:47:52 +0530 Subject: date handling problem In-Reply-To: <49816F93.8080101@egenix.com> References: <49816F93.8080101@egenix.com> Message-ID: On Thu, Jan 29, 2009 at 2:27 PM, M.-A. Lemburg wrote: > On 2009-01-29 03:38, Gabriel Genellina wrote: > > En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva > > escribi?: > > > >> I need to parse rss-feeds based on time stamp,But rss-feeds follow > >> different > >> standards of date(IST,EST etc). > >> I dont know,how to standardize this standards.It will be helpful if > >> you can > >> hint me. > > > > You may find the Olson timezone database useful. > > http://pytz.sourceforge.net/ > > Or have a look at the date/time parser in mxDateTime: > > http://www.egenix.com/products/python/mxBase/mxDateTime/ > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Jan 29 2009) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > -- > http://mail.python.org/mailman/listinfo/python-list > Thank you all, The link was really nice and i will try it out. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Thu Jan 29 05:21:37 2009 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 29 Jan 2009 02:21:37 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49818331.6010200@islandtraining.com> M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece > of code, is it bound to any class? > Those who have time and consideration can help me > Python *is* object-oriented, but it is not (as your definition suggests) object-fascist. We use objects to great effect in Python, when it is natural to do so, but the language does not force it on us. Gary Herron > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are > interested to be a part of it, please mail or call me. I will be happy > to share and inform - http://www.comat.com > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Thu Jan 29 05:25:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 02:25:57 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> On Thu, Jan 29, 2009 at 2:01 AM, M Kumar wrote: > Object oriented languages doesn't allow execution of the code without class > objects, what is actually happening when we execute some piece of code, is > it bound to any class? That's not really the standard definition of object-oriented (c.f. Wikipedia), but by your definition (which seems Java/Ruby-centric, IMHO), Python would not be object-oriented. In addition to methods, Python has functions, which are not associated with a class and let you write code in a procedural style, thus failing your criterion. Python also has the top-level module scope, in which the code isn't even part of a method or function at all and thus certainly is not associated with a class, again not satisfying your criterion. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 06:40:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 12:40:23 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49819599$0$20347$426a74cc@news.free.fr> (answering to the OP) > M Kumar wrote: >> Object oriented languages doesn't allow execution of the code without >> class objects, Chapter and verse, please ? Nothing in the (very few) "axioms" of OOP mentions "classes". You don't need classes to have an OOPL (ever heard about prototype-based languages ?). OOP is - as the name imply - about *objects*. >> what is actually happening when we execute some piece >> of code, Top-level code ? or the body of a def statement ? >> is it bound to any class? Why should it be ? From murielgodoi at gmail.com Thu Jan 29 06:47:51 2009 From: murielgodoi at gmail.com (Muriel de Souza Godoi) Date: Thu, 29 Jan 2009 09:47:51 -0200 Subject: is python Object oriented?? In-Reply-To: <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> Message-ID: Python offers support for object orientation, but it's not an object-oriented language. I mean, you can code a entire program in Python with no classes. So you use it if you want to. It's not like java, which you must use a class to code a Hello World, but Java isn't fully object-oriented, because it doesn't provide support for multiple inheritance and it has primitive types (multiple interfaces and wrappers to primitive types doesn't count :) ) AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe Simula?), where everything is a class, even the primitive types. An excellent reference book for that is: Sebesta, Robert W. (2002): *Concepts of Programming Languages (Fifth Edition).* Addison-Wesley Publishing Cheers, -- Muriel de Souza Godoi State University of Maring? Brazil -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Thu Jan 29 06:51:55 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 29 Jan 2009 12:51:55 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> Message-ID: <4981985B.4070108@wildenhain.de> Muriel de Souza Godoi wrote: > Python offers support for object orientation, but it's not an > object-oriented language. > I mean, you can code a entire program in Python with no classes. So you > use it if you want to. > > It's not like java, which you must use a class to code a Hello World, > but Java isn't fully object-oriented, because it doesn't provide support > for multiple inheritance and it has primitive types (multiple interfaces > and wrappers to primitive types doesn't count :) ) > > AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe > Simula?), where everything is a class, even the primitive types. well actually except keywords, everything is an object in python too, including of course primitive types (if you say so - practically python does not have them). Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From XX.XmcX at XX.XmclaveauX.com Thu Jan 29 07:10:08 2009 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Thu, 29 Jan 2009 13:10:08 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: Hi! Il se trouve que Chris Rebert a formul? : > Python has functions, which are not associated > with a class functions are methods of builtin... -- @-salutations Michel Claveau From steve at holdenweb.com Thu Jan 29 07:27:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 29 Jan 2009 07:27:36 -0500 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: W. eWatson wrote: > r wrote: >> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>> Where in the world is a description of pack() for Tkinter widgets? Is it >>> some sort of general method for all widgets? I'm looking in a few >>> docs that >>> use it without ever saying where it is described. For one, >>> . In the NM Tech pdf on >>> Tkinter, >>> it's not found anywhere. I see Universal methods for widgets, but no >>> mention >>> of pack(). package, packed, but no pack. >> >> did you try here :) >> http://effbot.org/tkinterbook/pack.htm > Thanks. I have the site bookmarked, but it's hard to search. I posted a > comment to them that they should have it in pdf form. > http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Jan 29 07:33:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 29 Jan 2009 07:33:17 -0500 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece of > code, is it bound to any class? > Those who have time and consideration can help me a) This is a purely theoretical consideration. You asked whether "python is a pure object oriented language", but this will inevitably lead to obscure discussions about what you mean rather than what Python is. b) You seem to believe that a "pure" object oriented language must do everything using classes. Since many problems are just as easy (or easier) to solve with a procedural approach, Python takes the view that it should be easy to provide such solutions as well. c) import this The Zen of Python, by Tim Peters [...] practicality beats purity [...] We aren't big on purity in the Python world ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Graham.Dumpleton at gmail.com Thu Jan 29 08:00:06 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 05:00:06 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> Message-ID: <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> On Jan 29, 8:15?pm, Aleksandar Radulovic wrote: > Graham, > > On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton > > wrote: > > Sorry, you are wrong to assume that an Apache restart is not be > > required. > > If you are usingmod_wsgiembedded mode, or mod_python, then a code > > change will always require a full restart of Apache. > > I am running several middleware apps I'm working on under mod_python > (simple setup using mod_python.publisher handler) and so far, haven't > had the reason to restart apache at all. The automatic module reloading in mod_python when using mod_python.publisher only applies to the publisher code files or those imported via the mod_python module importer and which is also a candidate for reloading. Basically, any module or package installed on sys.path is not a candidate for reloading. Thus if you installed your code outside of your document tree in a directory in sys.path and those code files were changed, then no automatic reload would occur. For further information see documentation for import_module() in: http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html In other words, it is not universal that any code change will be automatically detected and a reload occur. There are also various caveats on what mod_python module importer does, as it is reloading modules into an existing process and not restarting the whole process. If you are not careful, weird things can happen. > > Thus, the conjecture that Apache/mod_wsgicannot be used and that > > CherryPy WSGI server or Paster server must be used when developing a > > Python web application is false. If usingmod_wsgithen daemon mode > > Not sure what (or whom) you're referring to. It was a general statement. There are various people on different forums and irc channels who keep saying that a full Apache restart is required with Apache/mod_wsgi when making code changes. Am just stating for the record that that isn't true. > IMO, developing TG/Pylons/Django > apps is much convinient with embedded web server (cherrypy or paster) as > it is possible to do rapid development without resorting to restarts. In the case of Django, it uses a single non threaded process, thus is not an adequate test of either a multithread or multiprocess environment. Something which Apache/mod_wsgi provides. CherryPy WSGI server although it provides multithreading doesn't have a multiprocess option and it itself doesn't have a reload feature but depends on some layer on top to manage that from what I remember. So, depends on how closely you want your development environment to mirror production so that issues are picked up sooner, rather than only at the point of deployment to a production system when you are under pressure. Graham From mdw at distorted.org.uk Thu Jan 29 08:04:16 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 29 Jan 2009 13:04:16 +0000 Subject: How to get atexit hooks to run in the presence of execv? References: Message-ID: <87ab9ap8kv.fsf.mdw@metalzone.distorted.org.uk> rocky at panix.com (R. Bernstein) writes: > Recently, I added remote debugging via TCP sockets. (Well, also FIFO's > as well but closing sockets before restarting is what's of concern.) > > I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get > called. Should it? I'd consider that to be highly unusual. Certainly, the C atexit(3) function is called only in response to a call to exit(3) (possibly implicitly by returning from main), and not by execve(2) or any of its little friends. Your specific problem is to do with file descriptors, so it's probably best dealt with using the close-on-exec flag: from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC sk = socket(...) ## ... fcntl(sk.fileno(), F_SETFD, fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC) Now the socket will be magically closed when you exec.. another program. Finally, can I urge against TCP sockets in an application like this? Certainly without adequate authentication, it will simply be insecure even within a single multiuser host (e.g., using localhost only) -- and assuming that even a home machine has only a single user is becoming less realistic. Unix-domain sockets live in the filesystem, and access to them is limited using the standard filesystem mechanisms. If you're expecting inter-host communications (e.g., remote debugging), it's a good idea to protect the session using TLS or something (much as I dislike the TLS certification/public-key- distribution model it's way better than nothing at all). -- [mdw] From wanglei.198112 at gmail.com Thu Jan 29 08:04:52 2009 From: wanglei.198112 at gmail.com (Wang Lei) Date: Thu, 29 Jan 2009 21:04:52 +0800 Subject: how to update python on gnu emacs? In-Reply-To: References: Message-ID: If you means python-mode, you can add this line to you .emacs: (setq py-python-command "python3.0") On 1/29/09, John Seales wrote: > > I've updated to python 2.6. My terminal application finds the new python > just fine, but my gnu-emacs still is on python 2.3. Does anyone know how I > can change that? > > using x86 powerbook > > John Seales > > _________________________________________________________________ > Windows Live? Hotmail(R)?more than just e-mail. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 -- Regards Lei From wanglei.198112 at gmail.com Thu Jan 29 08:06:50 2009 From: wanglei.198112 at gmail.com (Wang Lei) Date: Thu, 29 Jan 2009 21:06:50 +0800 Subject: how to update python on gnu emacs? In-Reply-To: References: Message-ID: Sorry. Mine is python3.0. Yours maybe is: (setq py-python-command "python2.6") -- Regards Lei From bettini at dsi.unifi.it Thu Jan 29 08:41:00 2009 From: bettini at dsi.unifi.it (Lorenzo Bettini) Date: Thu, 29 Jan 2009 14:41:00 +0100 Subject: syntax color lang source code in blogs or website In-Reply-To: References: Message-ID: <4981b1ea$1@news.x-privat.org> Xah Lee wrote: > For those of you using emacs, here's the elisp code that allows you to > syntax color computer language source code in your blog or website. > > http://xahlee.org/emacs/elisp_htmlize.html > may I suggest also this one: http://www.gnu.org/software/src-highlite/ -- Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino ICQ# lbetto, 16080134 (GNU/Linux User # 158233) HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com http://www.myspace.com/supertrouperabba BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com http://www.gnu.org/software/src-highlite http://www.gnu.org/software/gengetopt http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net From duncan.booth at invalid.invalid Thu Jan 29 08:44:45 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 Jan 2009 13:44:45 GMT Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Message-ID: alex wrote: > Jon > Thank you for your answer. I tried it with no success. > > However I tried with > tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of > tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll") > > and it runs now with no error message, I can't figure for now why, but > it's great! This is motivating for going ahead. > cdll is for importing functions which use the cdecl calling convention where the caller must clean up the stack. windll is for functions that use the stdcall calling convention: the function that is called is responsible for cleaning up the stack. If you were using windll when you should have been using cdll then ctypes will have been expecting the library to clean up the stack, and the library will have been expecting the caller to do the cleanup, so nobody cleaned up the stack. The error message was telling you that ctypes pushed 4 bytes of argument onto the stack which weren't popped off by the caller. If you had been using the correct calling convention that would have indicated you had passed too many arguments, but as you were using the wrong calling convention the message was a bit unclear. -- Duncan Booth http://kupuguy.blogspot.com From tomanishkb at gmail.com Thu Jan 29 08:58:29 2009 From: tomanishkb at gmail.com (M Kumar) Date: Thu, 29 Jan 2009 19:28:29 +0530 Subject: is python Object oriented?? In-Reply-To: <4981985B.4070108@wildenhain.de> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> Message-ID: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> but still I am not clear of the execution of the code, when we write or execute a piece of python code without defining class, predefined class attributes are available (not all but __name__ and __doc__ are available). does it mean anything to this topic. Is it necessory to have __module__, __dict__ and __bases__ for a class object in python? On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > Muriel de Souza Godoi wrote: > >> Python offers support for object orientation, but it's not an >> object-oriented language. >> I mean, you can code a entire program in Python with no classes. So you >> use it if you want to. >> >> It's not like java, which you must use a class to code a Hello World, but >> Java isn't fully object-oriented, because it doesn't provide support for >> multiple inheritance and it has primitive types (multiple interfaces and >> wrappers to primitive types doesn't count :) ) >> >> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >> Simula?), where everything is a class, even the primitive types. >> > > well actually except keywords, everything is an object in python too, > including of course primitive types (if you say so - practically python > does not have them). > > Regards > Tino > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythonsky at sky.com Thu Jan 29 09:11:30 2009 From: pythonsky at sky.com (garywood) Date: Thu, 29 Jan 2009 14:11:30 -0000 Subject: is there a shorter way to write this Message-ID: I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated import random list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'] word = ' ' a = random.choice(list) list.remove(a) b = random.choice(list) list.remove(b) c = random.choice(list) list.remove(c) d = random.choice(list) list.remove(d) e = random.choice(list) list.remove(e) word = a + b + c + d + e print (word) print(list) -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Thu Jan 29 09:22:56 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 29 Jan 2009 06:22:56 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <246d83f0-28e9-40e3-8584-0f0b364b4458@f40g2000pri.googlegroups.com> On Jan 29, 7:21?am, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. ? I'm a python-nazi. No python for you! From jnoller at gmail.com Thu Jan 29 09:26:23 2009 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 29 Jan 2009 09:26:23 -0500 Subject: Terminating a Python program that uses multi-process, multi-threading In-Reply-To: References: Message-ID: <4222a8490901290626n76dbe96bl8394bef2c9d413d6@mail.gmail.com> On Wed, Jan 28, 2009 at 3:46 PM, akineko wrote: > Hello Python experts, > > I have a program that uses three processes (invoked by > multiprocessing) and several threads. > The program is terminated when ^C is typed (KeyboardInterrupt). > The main process takes the KeyboardInterrupt Exception and it orderly > shutdown the program. > > It works fine in normal situation. > > However, KeyboardInterrupt is not accepted when, for example, the > program is stuck somewhere due to error in network. I understand that > the KeyboardInterrupt won't be processed until the program moves out > from an atomic step in a Python program. > > Probably this is partly my fault as I use some blocking statements > (without timeout) as they should not block the program in normal > situation. > > As the program freezes up, I cannot do anything except killing three > processes using kill command. > So, I cannot tell which statement is actually blocking when this > occurs (and there are many suspects). > > Is there any good way to deal with this kind of problem? > Killing three processes when it hangs is not a fun thing to do. > > Any suggestions will be greatly appreciated. > > Best regards, > Aki Niimura > > -- > http://mail.python.org/mailman/listinfo/python-list > See also: http://jessenoller.com/2009/01/08/multiprocessingpool-and-keyboardinterrupt/ jesse From apt.shansen at gmail.com Thu Jan 29 09:27:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:27:02 -0800 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <7a9c25c20901290627h1e415788h3516a189dc463e44@mail.gmail.com> On Thu, Jan 29, 2009 at 5:58 AM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think there's some confusion on what you're asking; Python enables you to write object oriented software if you choose to. It also enables you to write procedural software if you choose to. There's other paradigms it supports too, to varying degrees. Its a tool that allows you to use it as you wish, instead of saying that a paradigm is the Right Way to do it. When you are writing object oriented software, you generally define classes. Class can inherit from other classes: if they do then the __bases__ attribute is set on the class itself to indicate which classes it inherits from. All Python code is within a module -- as a module is simply a file. For classes, functions and methods, the __module__ attribute simply points to which module it was defined in. The __dict__ of a class represents the dictionary of attributes that are "in" or "on" that class (approximately). But those are all implementation details. You don't have to set any of them or worry about any of them generally. You just: class MyClass: def __init__(self, bar): self.value = bar def foo(self): return self.value You don't have to set any class attributes to work with classes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Thu Jan 29 09:29:15 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 29 Jan 2009 15:29:15 +0100 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> > I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated > > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) Hmm, sounds like homework, but I'll bite. How about... import random, string indices = range(26) random.shuffle(indices) word = "".join([string.ascii_lowercase[i] for i in indices[:5]]) print word Cheers, Drea -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Jan 29 09:35:05 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:35:05 -0800 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> On Thu, Jan 29, 2009 at 6:11 AM, garywood wrote: > I had a task in a book to pick 5 items from a list of 26 ensuring the > items are not repeated > > If the list is unique of 26 elements is guaranteed to be unique, simply: >>> import random >>> random.sample(list, 5) ['g', 'y', 'i', 'n', 'x'] If the list isn't unique: >>> import random >>> random.sample(set(list), 5) ['r', 'e', 'b', 'k', 'i'] If you want to combine them all into a single word as you do in your example: >>> import random >>> ''.join(random.sample(set(list), 5)) 'wmhsq' --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Thu Jan 29 09:35:46 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 29 Jan 2009 15:35:46 +0100 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <9fdb569a0901290635m22e37c81uc70f9b894ac32d56@mail.gmail.com> 2009/1/29 garywood : > I had a task in a book to pick 5 items from a list of 26 ensuring the items > are not repeated > > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > There are probably several ways to do that, e.g.: >>> lst = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] >>> randomized_list = lst[:] >>> random.shuffle(randomized_list) >>> randomized_list[:5] ['n', 'p', 'e', 'f', 'y'] >>> (better not name a variable like a builtin - list) hth, vbr From apt.shansen at gmail.com Thu Jan 29 09:36:05 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 06:36:05 -0800 Subject: is there a shorter way to write this In-Reply-To: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> References: <7a9c25c20901290635v1d9def0bh78db6c720d2f2131@mail.gmail.com> Message-ID: <7a9c25c20901290636h75be5772if494da0a530b77cd@mail.gmail.com> If the list is unique of 26 elements is guaranteed to be unique, simply: > Wow, 6am copy editing of my own posts is terribly ineffective. "If the list of 26 elements is guaranteed to be unique" -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Jan 29 09:53:45 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 08:53:45 -0600 Subject: is there a shorter way to write this In-Reply-To: References: Message-ID: <4981C2F9.4040901@tim.thechases.com> > I had a task in a book to pick 5 items from a list of 26 > ensuring the items are not repeated > > import random > list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', > 'n','o','p','q','r','s','t','u','v','w','x','y','z'] > word = ' ' > a = random.choice(list) > list.remove(a) > b = random.choice(list) > list.remove(b) > c = random.choice(list) > list.remove(c) > d = random.choice(list) > list.remove(d) > e = random.choice(list) > list.remove(e) > word = a + b + c + d + e > print (word) > print(list) If you just need the "word", you can use >>> word = "".join(random.sample(string.lowercase, 5)) If you need the "leftovers" too: >>> letters = list(string.lowercase) >>> random.shuffle(letters) >>> word = "".join(letters[:5]) >>> remainder = letters[5:] >>> print word hjwnq >>> print "".join(letters) ebultgydafpmrxszicvko This assumes that your input dataset is unique (which string.lowercase is, but your problem definition doesn't guarantee) for your definition of "unique" (are upper/lowercase considered "unique" or "the same"?). If you need unique, you'd have to pre-process -- likely with set(): >>> data = "abcdefghijABCDEFGHIJK" >>> input_data = list(set(c.lower() for c in data)) >>> word = "".join(random.sample(input_data, 5)) >>> random.shuffle(input_data) >>> word = "".join(input_data[:5]) >>> remainder = "".join(input_data[5:]) -tkc From bruno.42.desthuilliers at websiteburo.invalid Thu Jan 29 09:55:32 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 29 Jan 2009 15:55:32 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <4981c355$0$9784$426a74cc@news.free.fr> MC a ?crit : > Hi! > > Il se trouve que Chris Rebert a formul? : >> Python has functions, which are not associated >> with a class > > functions are methods of builtin... Please check your facts. Python functions are not "methods" of anything (and not even necessarily attributes of a module - think about nested functions...). From python.list at tim.thechases.com Thu Jan 29 10:03:50 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 09:03:50 -0600 Subject: is there a shorter way to write this In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> References: <8AEDA5E3386EA742B8C24C95FF0C758005A9FDC2@PDC-MAIL3.ubisoft.org> Message-ID: <4981C556.80602@tim.thechases.com> > Hmm, sounds like homework, but I'll bite. The underlying problem does sound like homework, but the OP posted a working solution, and was only looking for ways to improve it. So I'm a little more lenient on providing alternatives. It's true that the homework problem may have been exactly as posted ("Improve this code"), but that's less likely in my estimation. -tkc From a at nospam.org Thu Jan 29 10:05:11 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 16:05:11 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Hello all, I have frozen a running application which is using SQLite with py2exe. When I start the exe file I see in the log file of the exe: Traceback (most recent call last): File "dpconf.py", line 666, in ? File "dpconf.py", line 251, in __init__ File "sqlite\main.pyc", line 255, in execute _sqlite.DatabaseError: no such table: genslaveopt The table exist in the database file ... no problem with the plain python version. How can I solve that problem ?? Best Regards --Armin From a at nospam.org Thu Jan 29 10:06:26 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 16:06:26 +0100 Subject: py2exe + SQLite problem Message-ID: Hello all, I have frozen a running application which is using SQLite with py2exe. When I start the exe file I see in the log file of the exe: Traceback (most recent call last): File "dpconf.py", line 666, in ? File "dpconf.py", line 251, in __init__ File "sqlite\main.pyc", line 255, in execute _sqlite.DatabaseError: no such table: genslaveopt The table exist in the database file ... no problem with the plain python version. How can I solve that problem ?? Best Regards --Armin From alejandro.weinstein at gmail.com Thu Jan 29 11:04:49 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Thu, 29 Jan 2009 08:04:49 -0800 (PST) Subject: Get thread pid Message-ID: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Hi: I have Python program running under Linux, that create several threads, and I want to now the corresponding PID of the threads. In each of the threads I have def run(self): pid = os.getpid() logger.critical('process ID: %s', pid) However, the reported PID is the father number, not the PID of the new thread. Is there a way to get the PID of the thread? To illustrate this further, this is the output of pstree when the PID of the main Python thread is 9197: $pstree -p 9197 python(9197)???{python}(9555) ??{python}(9556) ??{python}(9557) ??{python}(9558) ??{python}(9559) ??{python}(9560) ??{python}(9561) ??{python}(9562) ??{python}(9563) ??{python}(9564 I want each thread to report its PID number, in this case 9555, 9556, etc., but with os.getpid() is get 9197. Regards, Alejandro. From coutinhotiago at gmail.com Thu Jan 29 11:21:39 2009 From: coutinhotiago at gmail.com (coutinhotiago at gmail.com) Date: Thu, 29 Jan 2009 08:21:39 -0800 (PST) Subject: Dynamic methods and lambda functions References: <87fxj9bl7v.fsf.mdw@metalzone.distorted.org.uk> <8763k14nc6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8a3105be-4eac-4da0-97f5-e0b8b02b7bb0@r15g2000prh.googlegroups.com> On Jan 28, 11:32?pm, "Gabriel Genellina" wrote: > En Wed, 28 Jan 2009 16:05:39 -0200, coutinhoti... at gmail.com ? > escribi?: > > > ? I had the same problem myself. > > ? Mark's detailed explanation really helped me understand. > > > ? I ended up doing something like: > > The code doesn't work as-is, could you please post a working version? Just ? > for the record, so people reading this thread later don't get confused. > > -- > Gabriel Genellina Sure! This works for me: class A: def __init__(self): names = 'n1', 'n2' for n in names: setattr(self, "get%s" % n, self._createGetter(n)) def _createGetter(self, n): def f(): return n return f if __name__ == "__main__": a=A() print a.getn1() print a.getn2() From mail at anjanesh.net Thu Jan 29 11:24:46 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 29 Jan 2009 21:54:46 +0530 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to Message-ID: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Im reading a file. But there seems to be some encoding error. >>> f = open(filename) >>> data = f.read() Traceback (most recent call last): File "", line 1, in data = f.read() File "C:\Python30\lib\io.py", line 1724, in read decoder.decode(self.buffer.read(), final=True)) File "C:\Python30\lib\io.py", line 1295, in decode output = self.decoder.decode(input, final=final) File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to The string at position 10442 is something like this : "query":"0 1???? \u2021 0\u201a0 \u2021????"," So what encoding value am I supposed to give ? I tried f = open(filename, encoding="cp1252") but still same error. I guess Python3 auto-detects it as cp1252 -- Anjanesh Lekshmnarayanan From bhood37 at hotmail.com Thu Jan 29 11:35:47 2009 From: bhood37 at hotmail.com (Uberman) Date: Thu, 29 Jan 2009 09:35:47 -0700 Subject: Weird invisible arguments issues with Windows Message-ID: I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. First off, it didn't register the extension for .PY (although it did register .PYC). After manually associating the .PY extension with the python.exe executable, I am now getting some weirdness on the command line. When I run the following script, saved as "build.py", by simply entering "build.py -r -d" on the command line, it produces the output "1": import sys if __name__ == "__main__": print len(sys.argv) It doesn't see the additional arguments for some reason. However, if I execute the script by prefixing it (i.e., "python build.py -r -d"), I get an output of "3", meaning it sees the additional arguments. Has anybody else run into this issue? And perhaps (hopefully) solved it? From rocky at panix.com Thu Jan 29 11:36:27 2009 From: rocky at panix.com (R. Bernstein) Date: Thu, 29 Jan 2009 11:36:27 -0500 Subject: How to get atexit hooks to run in the presence of execv? References: <87ab9ap8kv.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding writes: > rocky at panix.com (R. Bernstein) writes: > >> Recently, I added remote debugging via TCP sockets. (Well, also FIFO's >> as well but closing sockets before restarting is what's of concern.) >> >> I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get >> called. Should it? > > I'd consider that to be highly unusual. Certainly, the C atexit(3) > function is called only in response to a call to exit(3) (possibly > implicitly by returning from main), and not by execve(2) or any of its > little friends. > > Your specific problem is to do with file descriptors, so it's probably > best dealt with using the close-on-exec flag: > > from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC > > sk = socket(...) > ## ... > fcntl(sk.fileno(), F_SETFD, > fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC) > > Now the socket will be magically closed when you exec.. another program. Thanks for the wealth of information. Alas, somehow I think this begs the question. I *know* how to arrange in the debugger for it to clean up after itself. But it's the program being debugged which I have no control over. And I would like to give it an opportunity to clean up after itself. > > Finally, can I urge against TCP sockets in an application like this? By all means, I hope people will offer thoughts, concerns and ideas. > Certainly without adequate authentication, it will simply be insecure > even within a single multiuser host (e.g., using localhost only) -- and > assuming that even a home machine has only a single user is becoming > less realistic. Unix-domain sockets live in the filesystem, and access > to them is limited using the standard filesystem mechanisms. > > If you're expecting inter-host communications (e.g., remote debugging), > it's a good idea to protect the session using TLS or something (much as > I dislike the TLS certification/public-key- distribution model it's way > better than nothing at all). Well, I also started coding FIFO's as well as TCP sockets, partly because I could, and partly to try to try to keep the interface generic. And in the back of my mind, I'd like to add serial devices as well - I don't see a reason not to. Initially, I probably won't add authentication or encryption. I'm having enough of a time trying to get this much working. (cpickling over sockets seems to still require knowing how many messages were sent and unpickling each of those, and TCP_NODELAY isn't allowed and doesn't seem the right thing either.) However what I really would like to see is authentication and encription added as an independent plugin layer much as I view whether one is debugging locally or not. So I don't see this as an issue per se with TCP sockets. > > -- [mdw] From markobrien85 at gmail.com Thu Jan 29 11:38:43 2009 From: markobrien85 at gmail.com (markobrien85 at gmail.com) Date: Thu, 29 Jan 2009 08:38:43 -0800 (PST) Subject: persistent TCP connection in python using socketserver Message-ID: <1acc7d88-7903-4cf7-8f7f-5824c19dbf63@p2g2000prn.googlegroups.com> G'day I'm currently using socketserver to build a simple XMLSocket (an XML based protocol used for communication between flash and the outside world) server. I've got flash establishing a connection, sending a request and my python server responding. However at this point socketserver terminates the connection. Which is bad, since i need a persistent connection so i can push data from the server to the client without the overhead of polling. I need to create TCP connection that persists until I explicitly tell it to terminate, or the connection is terminated on the other end. A quick look through the socketserver code makes this seem impossible since it appears to call close after the handle() method. Is there an even lower level library to be using, or is there some option I haven't found yet in socketserver. Cheers From a at nospam.org Thu Jan 29 11:40:51 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 17:40:51 +0100 Subject: py2exe + data_files Message-ID: Hello, is there a way to place individual data files into to the standard 'dist' directory and not into a subdirectory of 'dist' --Armin From mcerini at gmail.com Thu Jan 29 11:48:03 2009 From: mcerini at gmail.com (mattc) Date: Thu, 29 Jan 2009 08:48:03 -0800 (PST) Subject: How does one view the source of function defined in the interpreter? Message-ID: 1) It appears that it is possible to view the source of a function defined in the interpreter; however, I seem to be unable to do it. Here is the code and resulting error. >>> def f(): print("hello world") >>> f >>> f() hello world >>> import inspect >>> inspect >>> inspect.getsourcelines(f) Traceback (most recent call last): File "", line 1, in inspect.getsourcelines(f) File "C:\Python30\lib\inspect.py", line 678, in getsourcelines lines, lnum = findsource(object) File "C:\Python30\lib\inspect.py", line 526, in findsource raise IOError('could not get source code') IOError: could not get source code 2) Also, is there a method to inspect f in the form "f.inspect" or "f.getsource" or "f.dump"? 3) One last thing, is there any documentation for augmenting, extending, or editing a function in the interpreter once it is defined? Yes, I'm new. Yes, I've spent the obligatory hours searching the web and use groups. Yes, I'd love to code in Python. Please help. Thank you. From bsk16 at case.edu Thu Jan 29 11:49:41 2009 From: bsk16 at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 11:49:41 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 11:24 AM, Anjanesh Lekshminarayanan < mail at anjanesh.net> wrote: > Im reading a file. But there seems to be some encoding error. > > >>> f = open(filename) > >>> data = f.read() > Traceback (most recent call last): > File "", line 1, in > data = f.read() > File "C:\Python30\lib\io.py", line 1724, in read > decoder.decode(self.buffer.read(), final=True)) > File "C:\Python30\lib\io.py", line 1295, in decode > output = self.decoder.decode(input, final=final) > File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position > 10442: character maps to > > The string at position 10442 is something like this : > "query":"0 1??? \u2021 0\u201a0 \u2021??? "," > > So what encoding value am I supposed to give ? I tried f = > open(filename, encoding="cp1252") but still same error. I guess > Python3 auto-detects it as cp1252 It does auto-detect it as cp1252- look at the files in the traceback and you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong encoding, try opening it as utf-8 or latin1 and see if that fixes it. > -- > Anjanesh Lekshmnarayanan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Thu Jan 29 11:55:13 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 29 Jan 2009 08:55:13 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson > escribi?: > >> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? > > There is a PDF version of "An Introduction to Tkinter" here: > http://www.pythonware.com/library/ > Thanks. I have it but it's an odd one to search on "pack(". There may be over 100 reference to pack(. It's probably explained there somewhere, but how many times do I want to press the search key? I have it printed out too. I guess I need to eyeball it. It's probably faster. Maybe find the section (geometry?) where it and others like it are found. There is an index, but it's a pitiful one page. Found in Chapter 34. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From a at nospam.org Thu Jan 29 11:57:36 2009 From: a at nospam.org (Armin) Date: Thu, 29 Jan 2009 17:57:36 +0100 Subject: distutil problem ?? Message-ID: Hello, I have the following setup script for py2exe: from distutils.core import setup import py2exe setup(windows=['dpconf.py'], data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] ) When I create the distribution I got the following err msg: *** copy data files *** warning: install_data: setup script did not provide a directory for '' -- installing right in 'C:\pyDPCONF.2.3-dev\dist' error: can't copy '': doesn't exist or not a regular file Looks a little bit inconsistent ? --Armin PS: "." makes also problems From notvalid2 at sbcglobal.net Thu Jan 29 11:59:26 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 29 Jan 2009 08:59:26 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: r wrote: > On Jan 28, 10:57 pm, "W. eWatson" wrote: >> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? > > Only the grid manager is discussed at NMT. I just like how at NMT the > widget attributes are in a table and then a list the widget methods > follows below that -- much better navigation. > > I talked again to John at NMT and he assured me very soon he's going > to make all the updates. It would probably help if you sent him a nice > message of encouragement like -- 'Can you please update the > documentation, i really like the sites layout?' -- but please don't > forget to thank him for all his contributions to the Python community. > > I am currently crusading to have all the old Python tuts and > documentation updated(among other crusades). This was my second win > and i hope that more will follow. The python docs out there need a > dusting off and spit shining. I fully agree with your assessment of their state. I might not want him to update the NMT. :-) Why would that be. I just had it printed. Another $8! I'm kidding, of course. Not only is it a good layout, I think it's the best layout out there, IMHO. I'll contact him. I think one of his other pdf files needs updating too. Possibly the one for PIL. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From mail at timgolden.me.uk Thu Jan 29 12:09:19 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 Jan 2009 17:09:19 +0000 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: <4981E2BF.90001@timgolden.me.uk> Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > import sys > if __name__ == "__main__": > print len(sys.argv) > > It doesn't see the additional arguments for some reason. However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? And perhaps (hopefully) solved it? What does your association look like? Try ftype; should be something like this: H:\>ftype python.file python.file="C:\Python26\python.exe" "%1" %* Notice the stuff at the end TJG From mail at anjanesh.net Thu Jan 29 12:09:29 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Thu, 29 Jan 2009 22:39:29 +0530 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> Message-ID: <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> > It does auto-detect it as cp1252- look at the files in the traceback and > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > encoding, try opening it as utf-8 or latin1 and see if that fixes it. Thanks a lot ! utf-8 and latin1 were accepted ! From chris.hulan at gmail.com Thu Jan 29 12:11:04 2009 From: chris.hulan at gmail.com (Chris Hulan) Date: Thu, 29 Jan 2009 09:11:04 -0800 (PST) Subject: Weird invisible arguments issues with Windows References: Message-ID: On Jan 29, 11:35?am, Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. ?When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > ? ? import sys > ? ? if __name__ == "__main__": > ? ? ? ? print len(sys.argv) > > It doesn't see the additional arguments for some reason. ?However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? ?And perhaps (hopefully) solved it? Have seen this in some installs on XP. Indicates the registry entry that specfies how to invoke python on a *.py file is not correctly set to pass along the command line arguments on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications \python.exe\shell\open\command has: Name (Default) Type REG_SZ Data C:\Python23\python.exe "%1" %* If that '%*' is missing, thats the problem Cheers Chris From google at mrabarnett.plus.com Thu Jan 29 12:12:41 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jan 2009 17:12:41 +0000 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: <4981E389.6040307@mrabarnett.plus.com> Uberman wrote: > I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit. > > First off, it didn't register the extension for .PY (although it did register > .PYC). > > After manually associating the .PY extension with the python.exe executable, I > am now getting some weirdness on the command line. When I run the following > script, saved as "build.py", by simply entering "build.py -r -d" on the > command line, it produces the output "1": > > import sys > if __name__ == "__main__": > print len(sys.argv) > > It doesn't see the additional arguments for some reason. However, if I > execute the script by prefixing it (i.e., "python build.py -r -d"), I get an > output of "3", meaning it sees the additional arguments. > > Has anybody else run into this issue? And perhaps (hopefully) solved it? > You might want to check that: assoc .py displays: .py=Python.File and: ftype Python.File displays: Python.File="C:\Python26\python.exe" "%1" %* (or something similar). From torriem at gmail.com Thu Jan 29 12:19:25 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 29 Jan 2009 10:19:25 -0700 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <4981E51D.3090908@gmail.com> M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think you're confused as to what object-oriented means. OO defines the internals of a language more than a particular programming paradigm. Obviously python lets you program in a variety of paradigms, including procedural and event-driven, but it is all very much object-oriented. So ignore those that say python doesn't force you to use OOP, when in fact it's unavoidable. It's just that you're not forced to place all your code in class definitions. You don't need to because your code is already object-oriented in that you're manipulating objects and their attributes. As others have said, Python is an object-oriented language through and through, closer to Smalltalk in many ways, the grand-daddy of all OO languages. It appears that you are only really familiar with Java, and that leads to a number of interesting misconceptions about OO. Java's bizarre OO requires everything to be in a class, which leads many people to believe this is what OO should be. In fact Java is a bit odd when it comes to OO, as there are many things in Java that aren't in fact objects. For example, primitives are intrinsic types and are not objects. Furthermore class definitions are not objects either, at least from the programmer's pov. You can't manipulate them by standard means as you can in Smalltalk and Python. In Smalltalk and Python a "class" is an object just as much as an instance of a class is an object which has a constructor factory method that returns instance objects. Java also has very strange ways of doing singleton patterns. You have to wrap singletons in class and define them as "static." I think this was inherited from C++. The most basic object in a python script is the module object which represents the namespace of the current script. In effect a module object is a singleton. It has a few attributes, and you can use it to look up any of the objects it contains, such as functions, objects (so-called variables), classes, etc. Everything in python is an object. The statement: a = 4 defines an integer object "4" and binds a name to it, 'a.' You can even check to see what methods the object supports by doing: >>> dir(4) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] dir(a) would return the same thing. As you can see, all the operators that can be performed with a number object are defined. This little exercise alone should show you how much more object-oriented Python is than Java. Python's OO capabilities are really exposed when you start extending built-in types, or doing meta programming where you dynamically alter classes (and instance objects) on the fly. From bsk16 at case.edu Thu Jan 29 12:21:21 2009 From: bsk16 at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 12:21:21 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan < mail at anjanesh.net> wrote: > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Thanks a lot ! utf-8 and latin1 were accepted ! > -- > If you want to read the file as text, find out which encoding it actually is. In one of those encodings, you'll probably see some nonsense characters. If you are just looking at the file as a sequence of bytes, open the file in binary mode rather than text. That way, you'll avoid this issue all together (just make sure you use byte strings instead of unicode strings). -------------- next part -------------- An HTML attachment was scrubbed... URL: From dg.google.groups at thesamovar.net Thu Jan 29 12:34:52 2009 From: dg.google.groups at thesamovar.net (dg.google.groups at thesamovar.net) Date: Thu, 29 Jan 2009 09:34:52 -0800 (PST) Subject: CUDA Message-ID: <5c4d785e-d24a-47a2-866e-0443abadf6dd@f40g2000pri.googlegroups.com> Hi all, Has anyone managed to get any of the Python CUDA libraries working on Windows using cygwin? Which one, and was anything special required? Thanks in advance for any advice. Dan From skip at pobox.com Thu Jan 29 12:52:05 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 29 Jan 2009 11:52:05 -0600 Subject: Spam making a comeback?? In-Reply-To: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> References: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> Message-ID: <18817.60613.320344.871903@montanaro.dyndns.org> r> Seems like the level of spam is increasing in the last week, and r> today has been bad. How are the spambytes coming along? Spambayes is doing fine, but it only filters spam for the mailing list. It has no effect on the Usenet side of things (comp.lang.python). -- Skip Montanaro - skip at pobox.com - http://smontanaro.dyndns.org/ From alan.isaac at gmail.com Thu Jan 29 13:01:17 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 18:01:17 GMT Subject: slicings: 3 questions Message-ID: 1. I seem not to understand something obvious at http://docs.python.org/3.0/reference/expressions.html#slicings (I assume I'm just not reading this right.) What is an example of a slicing using a "slice_list"? 2. It seems that slice objects and range objects are awfully similar in many ways. Is this "appearance only", or was there any discussion of unifying them? Curious for insight... 3. Why are slicings not directly listed among the built-in types? (I know they are discussed here: http://docs.python.org/3.0/reference/datamodel.html#types). What makes them "internal"? http://docs.python.org/3.0/library/stdtypes.html#internal-objects Thanks, Alan Isaac From james at agentultra.com Thu Jan 29 13:02:46 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 29 Jan 2009 13:02:46 -0500 Subject: Recommendation for a small web framework like Perl's CGI::Application to run as CGI? References: <3ccaab48-2800-459a-ac76-17d7e4fdbf94@n41g2000yqh.googlegroups.com> Message-ID: <858wout2gp.fsf@agentultra.com> excord80 writes: > I need to make a small, relatively low-traffic site that users can > create accounts on and log into. Scripts must run as cgi (no > mod_python or FastCGI is available). Can anyone recommend a small and > simple web framework for Python, maybe similar to Perl's > CGI::Application? > > Or would it just be better to roll my own? web.py pretty simple. lots of deployment options. ends up building into your own framework as your application grows. From gagsl-py2 at yahoo.com.ar Thu Jan 29 13:14:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 16:14:43 -0200 Subject: Tkinter w.pack()? References: Message-ID: En Thu, 29 Jan 2009 14:55:13 -0200, W. eWatson escribi?: > Gabriel Genellina wrote: >> En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson >> escribi?: >> >>> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? >> There is a PDF version of "An Introduction to Tkinter" here: >> http://www.pythonware.com/library/ >> > Thanks. I have it but it's an odd one to search on "pack(". There may be > over 100 reference to pack(. It's probably explained there somewhere, > but how many times do I want to press the search key? I have it printed > out too. I guess I need to eyeball it. It's probably faster. Maybe find > the section (geometry?) where it and others like it are found. There is > an index, but it's a pitiful one page. Uh? The very first occurence of "pack" is in the Table of Contents, "The pack geometry manager". (You may want to improve your search skills :) ) -- Gabriel Genellina From clp2 at rebertia.com Thu Jan 29 13:37:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 10:37:48 -0800 Subject: slicings: 3 questions In-Reply-To: References: Message-ID: <50697b2c0901291037p58902c62n53d87403e8c3aba2@mail.gmail.com> On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: > 1. I seem not to understand something obvious at > http://docs.python.org/3.0/reference/expressions.html#slicings > (I assume I'm just not reading this right.) > What is an example of a slicing using a "slice_list"? There's nothing in the stdlib that uses it IIRC, but for instance a matrix package could allow you to do: a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s print( a[4,2,6] ) #get an item from the matrix using slice_list syntax print( a[4][2][6] ) #another way to get the same item > 2. It seems that slice objects and range objects are > awfully similar in many ways. Is this "appearance only", > or was there any discussion of unifying them? > Curious for insight... Wouldn't really be possible, IMHO. True, they both have notions of start, stop, and step, but slices don't make sense as ranges without knowing the length of the container. For example, take the slice `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, since -2 < 1 (stop < start ) and 1 (the step) is positive, the range is nonsensical. You have to replace all the negative indices with calculated positive indices first in order to have a sensical range(), in this case, replacing the stop of -2 with len(container)-2. Also, more fundamentally, Python is liberal in what it allows for the parts of slices, so unifying slices with ranges would break code. For example, Python is perfectly happy if I go slice("a",[8],object), none of which are even numbers. > 3. Why are slicings not directly listed among the built-in types? > (I know they are discussed here: > http://docs.python.org/3.0/reference/datamodel.html#types). > What makes them "internal"? > http://docs.python.org/3.0/library/stdtypes.html#internal-objects Because they're generally only useful in the context of slicing lists and other containers, and not as a datatype in and of themselves. Also, the syntax sugar of a[b:c:d] means that you can practically disregard the existence of slice() objects and just think that there's special list-slicing syntax, with very little downside. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From exarkun at divmod.com Thu Jan 29 13:54:26 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 29 Jan 2009 13:54:26 -0500 Subject: persistent TCP connection in python using socketserver In-Reply-To: <1acc7d88-7903-4cf7-8f7f-5824c19dbf63@p2g2000prn.googlegroups.com> Message-ID: <20090129185426.12853.960619914.divmod.quotient.25@henry.divmod.com> On Thu, 29 Jan 2009 08:38:43 -0800 (PST), markobrien85 at gmail.com wrote: >G'day > >I'm currently using socketserver to build a simple XMLSocket (an XML >based protocol used for communication between flash and the outside >world) server. I've got flash establishing a connection, sending a >request and my python server responding. However at this point >socketserver terminates the connection. Which is bad, since i need a >persistent connection so i can push data from the server to the client >without the overhead of polling. If you don't want the connection to close, then don't let the request complete. SocketServer implements logic for single request/response per connection. You can change this by making your requests take a really long time (until you're done with the connection) or you can override the behavior which closes the connection after a response. Or you could use the socket module, on which the SocketServer module is based. Or you could use Twisted, another higher-level package built on the socket module (mostly). Actually, I recommend Twisted, since it will mostly isolate you from boring low-level details and let you implement whatever high-level behavior you're after (I know that a bunch of people have used it to communicate with Flash, for example). Jean-Paul From tjreedy at udel.edu Thu Jan 29 13:58:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 13:58:03 -0500 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece of > code, is it bound to any class? > Those who have time and consideration can help me My take.. Python is a language. Programs written in Python create and manipulate information objects. (But programs are not objects themselves.) So, Python is a language for describing object-based information processing. Every Python object is an instance of some class. Every class, being an object itself, is an instance of some metaclass. (The 'type' metaclass is an instance of itself.) Every class (in Py3) is also a subclasses of the base class 'object'. I think 'object-orient language' is a somewhat misleading abbreviation since 'object-orientedness' is a potential property of the an abstract computation system a language works, with rather than a property of a language itself. Terry Jan Reedy From kay.schluehr at gmx.net Thu Jan 29 14:01:45 2009 From: kay.schluehr at gmx.net (Kay Schluehr) Date: Thu, 29 Jan 2009 11:01:45 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <2f14db4c-2f1b-432e-87a2-e80441cf730d@r37g2000prr.googlegroups.com> On 29 Jan., 11:21, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. ? I'd put it more mildly. Python is object oriented. The orientation is there but the fanatism is gone. Kay From tjreedy at udel.edu Thu Jan 29 14:04:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 14:04:06 -0500 Subject: How does one view the source of function defined in the interpreter? In-Reply-To: References: Message-ID: mattc wrote: Once the interpreter reads lines of code, then, as far as the interpreter is concerned, they are gone. > 3) One last thing, is there any documentation for augmenting, > extending, or editing a function in the interpreter once it is > defined? Use IDLE, edit code in an edit window, then run. I generally use the interpreter or IDLE shell window only for single-line commands. From googler.1.webmaster at spamgourmet.com Thu Jan 29 14:04:39 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 11:04:39 -0800 (PST) Subject: ImportError in embedded Python Interpreter Message-ID: Hi, i have a problem. I compiled Python and the socket module so I got this structure. (all on windows) C:\test\dll_files\python25.dll C:\test\my_app C:\test\dll_files\DLLs\ C:\test\dll_files\python.exe If I run python I get the console and I can call "import socket" which succeeds. I wrote a small console app which is stored in C:\test\ and embeddeds the python interpreter. I set the environment variable PATH so the python DLL files can be load. But when I want to import in a script the socket module, it fails. (The interpreter works fine, just importing files in the DLLs folder fail). Why? When I print out the sys.path I get the same like in the real python.exe. What do you think, whats missing? Thanks a lot. bye :) From googler.1.webmaster at spamgourmet.com Thu Jan 29 14:07:01 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 11:07:01 -0800 (PST) Subject: ImportError in embedded Python Interpreter Message-ID: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Hi, i have a problem. I compiled Python and the socket module so I got this structure. (all on windows) C:\test\dll_files\python25.dll C:\test\my_app C:\test\dll_files\DLLs\ C:\test\dll_files\python.exe If I run python.exe I get the console and I can call "import socket" which succeeds. I wrote a small console app which is stored in C:\test\ and embeddeds the python interpreter. I set the environment variable PATH so the python25.dll can be load. But when I want to import the socket module in a script, it fails. (The interpreter works fine, just importing files in the DLLs folder fail). Why? When I print out the sys.path in my app I get the same like in the real python.exe. What do you think, whats missing? Thanks a lot. bye :) From tjreedy at udel.edu Thu Jan 29 14:07:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 14:07:56 -0500 Subject: Spam making a comeback?? In-Reply-To: <18817.60613.320344.871903@montanaro.dyndns.org> References: <1fb2233f-2a09-4223-a363-a5a9b6362d59@k36g2000pri.googlegroups.com> <18817.60613.320344.871903@montanaro.dyndns.org> Message-ID: skip at pobox.com wrote: > r> Seems like the level of spam is increasing in the last week, and > r> today has been bad. How are the spambytes coming along? > > Spambayes is doing fine, but it only filters spam for the mailing list. It > has no effect on the Usenet side of things (comp.lang.python). It does, however, affect the gmane.comp.lang.python newsgroup, which is very clean now. Thank you. (And items posted through gmane are apparently sent to the mailing list first, and filtered, before being added to the mirror.) tjr From elsjaako at gmail.com Thu Jan 29 14:33:15 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 11:33:15 -0800 (PST) Subject: receive and react to MIDI input Message-ID: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Hi all. I want to write an application that reads midi notes and then does something (specifically, play sound files, but that doesn't really matter for this question). I'm on windows. I went on MSDN and tried to get it to work, and I found myself getting pretty far (considering how little I know about all this), but I finally got stuck. I get en error referring to a Null pointer. What I tried to do is make it run MidiSigReceived every time a signal is received. I will add the processing as soon as I got this step working. I do not have my keyboard plugged in, so my computer should not receive signals. MidiSigReceived is run once though, and only after that does the error occur. What I think the problem is is that midiInID has to be of type HMIDIIN. Somewhere in the relevant .h file, I found: DECLARE_HANDLE(HMIDIIN); DECLARE_HANDLE I couldn't find in the headers, so I looked on the Internet and found: #ifdef STRICT typedef void *HANDLE; #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endif I think this means that the following could be said: typedef void *HANDLE; struct HMIDIIN##__ { int unused; }; typedef struct HMIDIIN##__ *HMIDIIN; but what exactly that means is I think beyond my C abilities. It seems that a HMIDIIN is a pointer to a structure with one element: unnamed. My attempts to figure it out didn't change the error at all. I find it even more confusing considering midiInOpen requires a pointer to such an object. The relevant MSDN page: http://msdn.microsoft.com/en-us/library/ms709430(VS.85).aspx This is what I have: #imports from ctypes import * from ctypes.wintypes import * winmm = windll.LoadLibrary("winmm") #structures and such MAXPNAMELEN = 32 MMVERSION = UINT CALLBACK_FUNCTION = 196608 # hex 30000 class MIDIOUTCAPS (Structure): _fields_ = [("wMid",WORD), ("wPid",WORD), ("vDriverVersion",MMVERSION), ("szPname",WCHAR * MAXPNAMELEN), ("dwSupport",DWORD)] # The next part defines the callback function CMPFUNC = CFUNCTYPE(None, c_long, UINT, DWORD, DWORD, DWORD) def MidiSigReceived(a,b,c,d,e): print a,b,c,d,e midi_get = CMPFUNC(MidiSigReceived) midiInID = c_long() #The ID of the Midi connection, so we can close it again winmm.midiInOpen(byref(midiInID), # reference to the connection ID 0, # Midi device to use midi_get, # callback function 0, # instance data CALLBACK_FUNCTION) # Callback flag, makes it use the callback, change it to 0 to remove error # Close the connection winmm.midiInClose(midiInID) Or, as far as I could understand, you could use the HMIDIIN thing: class MIDIHANDLESTRUCT (Structure): _fields_ = [("unused",c_long)] HMIDIIN = POINTER(MIDIHANDLESTRUCT) midiInID = HMIDIIN() If anyone could help, I would greatly appreciate it. Bart de Waal From alex at a13x.net Thu Jan 29 15:12:44 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Thu, 29 Jan 2009 20:12:44 +0000 Subject: Sloooooowwwww WSGI restart In-Reply-To: <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> References: <1e88159d-2358-4aec-8c1b-305fedae7547@p2g2000prn.googlegroups.com> <4f5296c7-d55f-4268-9d51-1ec456b03a86@r36g2000prf.googlegroups.com> Message-ID: <845b10c50901291212s6add86fahc18530265632cdda@mail.gmail.com> Graham, On Thu, Jan 29, 2009 at 1:00 PM, Graham Dumpleton wrote: > In other words, it is not universal that any code change will be > automatically detected and a reload occur. There are also various > caveats on what mod_python module importer does, as it is reloading > modules into an existing process and not restarting the whole. > If you are not careful, weird things can happen. Considering I'm not changing any of the modules (ie. working only on the source tree in the project itself which is published by mod_python.publisher) I haven't seen the need to restart Apache. There are caveats, of course - but in day-to-day work, I haven't noticed any difficulties and need to fully restart Apache. > It was a general statement. There are various people on different > forums and irc channels who keep saying that a full Apache restart is > required with Apache/mod_wsgi when making code changes. Am just > stating for the record that that isn't true. We agree here. Someone posted a link earlier explaining the settings of mod_wsgi (maybe it was you) where it's easy to configure it to detect code changes and reload the code. Hence my questions from the begining of the thread. There are custom built code-reloading modules (and techniques) which can also be used. > So, depends on how closely you want your development environment to > mirror production so that issues are picked up sooner, rather than > only at the point of deployment to a production system when you are > under pressure. Ideally, you would want the environments to be as closely related (in terms of setup) as possible. In my development, i try to keep the integration environment a mirror of production, but (as mentioned) keep the local (dev) environment as suitable to my needs as possible. Continuous integration system would help in deploying the code to integration for integration testing and final checks before hitting production (which is a manual process). Rushing things into production is never a good think(tm). All it needs is a bit of careful planning, but I'm going way too off-topic here. Regards, alex. -- a lex 13 x http://www.a13x.info From benjamin at python.org Thu Jan 29 15:25:41 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 29 Jan 2009 20:25:41 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan anjanesh.net> writes: > > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Thanks a lot ! utf-8 and latin1 were accepted ! Just so you know, latin-1 can decode any sequence of bytes, so it will always work even if that's not the "real" encoding. From rt8396 at gmail.com Thu Jan 29 15:36:44 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 12:36:44 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Message-ID: <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> On Jan 29, 1:33?pm, elsjaako wrote: There is a Python MIDI module, i think it is pyMIDI, have you checked it out? From alan.isaac at gmail.com Thu Jan 29 15:39:49 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 20:39:49 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: > On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: >> 1. I seem not to understand something obvious at >> http://docs.python.org/3.0/reference/expressions.html#slicings >> (I assume I'm just not reading this right.) >> What is an example of a slicing using a "slice_list"? On 1/29/2009 1:37 PM Chris Rebert apparently wrote: > There's nothing in the stdlib that uses it IIRC, but for instance a > matrix package could allow you to do: > > a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s > print( a[4,2,6] ) #get an item from the matrix using slice_list syntax > print( a[4][2][6] ) #another way to get the same item Ah sure, I was misreading it. It is just enabling NumPy style indexing. I was assuming that it was describing a legitimate way so slice sequences generally. Thanks, Alan From tjandacw at yahoo.com Thu Jan 29 15:58:16 2009 From: tjandacw at yahoo.com (timw.google) Date: Thu, 29 Jan 2009 12:58:16 -0800 (PST) Subject: python 2.6 wininst problem Message-ID: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> I just installed Python2.6 on my WinXP box in a non-standard location (not C:\Python26) since I'm not admin. I used cygwin to create a module of an extension I wrote, but when I went to execute the installer, I get a popup error "This application has failed to start because the application configuration is incorrect. Reinstalling the application my fix this problem." It turns out that the application installs my module on another machine where python is installed in C:\Python26, but why not in my installation? I went and reinstalled python2.5 in a similar nonstandard location (%USERPROFILE%\Python25) and rebuilt my extension module under that. The module installer worked just fine, so it seems to be a 2.6 issue. Do I now have to get the Helpdesk to install Python for me? TIA. From alecla at bluewin.ch Thu Jan 29 16:08:55 2009 From: alecla at bluewin.ch (alex) Date: Thu, 29 Jan 2009 13:08:55 -0800 (PST) Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> Message-ID: <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> Duncan Thank you for your explanation of the relationship between calling convention and stack management. I will try to understand better this topic in the CVF and ctypes documentation (not so easy). Regards Alex From sjmachin at lexicon.net Thu Jan 29 16:19:43 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 21:19:43 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Benjamin Kaplan case.edu> writes: > > > On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan anjanesh.net> wrote: > > It does auto-detect it as cp1252- look at the files in the traceback and > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. Benjamin, "auto-detect" has strong connotations of the open() call (with mode including text and encoding not specified) reading some/all of the file and trying to guess what the encoding might be -- a futile pursuit and not what the docs say: """encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings""" On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It would be interesting to know (1) what is produced on Anjanesh's machine (2) how the default encoding is derived (I would have thought I was a prime candidate for 'cp1252') (3) whether the 'default encoding' of open() is actually the same as the 'default encoding' of sys.getdefaultencoding() -- one would hope so but the docs don't say so. > Thanks a lot ! utf-8 and latin1 were accepted ! Benjamin and Anjanesh, Please understand that any_random_rubbish.decode('latin1') will be "accepted". This is *not* useful information to be greeted with thanks and exclamation marks. It is merely a by-product of the fact that *any* single-byte character set like latin1 that uses all 256 possible bytes can not fail, by definition; no character "maps to ". > If you want to read the file as text, find out which encoding it actually is. In one of those encodings, you'll probably see some nonsense characters. If you are just looking at the file as a sequence of bytes, open the file in binary mode rather than text. That way, you'll avoid this issue all together (just make sure you use byte strings instead of unicode strings). In fact, inspection of Anjanesh's report: """UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to The string at position 10442 is something like this : "query":"0 1?? \u2021 0\u201a0 \u2021??"," """ draws two observations: (1) there is nothing in the reported string that can be unambiguously identified as corresponding to "0x9d" (2) it looks like a small snippet from a Python source file! Anjanesh, Is it a .py file? If so, is there something like "# encoding: cp1252" or "# encoding: utf-8" near the start of the file? *Please* tell us what sys.getdefaultencoding() returns on your machine. Instead of "something like", please report exactly what is there: print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) Cheers, John From martin at v.loewis.de Thu Jan 29 16:25:05 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 29 Jan 2009 22:25:05 +0100 Subject: python 2.6 wininst problem In-Reply-To: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> References: <7df8201d-6278-4620-81b1-11941fea2293@k1g2000prb.googlegroups.com> Message-ID: <49821EB1.1000503@v.loewis.de> > Do I now have to get the Helpdesk to install Python for me? No, you should wait for Python 2.6.2; this should fix this problem. Regards, Martin From bhood37 at hotmail.com Thu Jan 29 16:31:08 2009 From: bhood37 at hotmail.com (Uberman) Date: Thu, 29 Jan 2009 14:31:08 -0700 Subject: Weird invisible arguments issues with Windows In-Reply-To: References: Message-ID: Tim Golden wrote: > What does your association look like? Try ftype; should be something > like this: > > H:\>ftype python.file > python.file="C:\Python26\python.exe" "%1" %* Then, Chris Hulan wrote: > on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications > \python.exe\shell\open\command > has: > Name (Default) > Type REG_SZ > Data C:\Python23\python.exe "%1" %* > > If that '%*' is missing, thats the problem Finally, MRAB scribed: > You might want to check that: > > assoc .py > > displays: > > .py=Python.File > > and: > > ftype Python.File > > displays: > > Python.File="C:\Python26\python.exe" "%1" %* Thank you for all the replies, guys. :) You all seem to be pointing at the same thing, and on my system, I show: C:\Users\Administrator>ftype python.file python.file="D:\Python26\python.exe" "%1" %* and C:\Users\Administrator>assoc .py .py=Python.File Which all seems to be correct. I'm guessing this doesn't bode well... From alan.isaac at gmail.com Thu Jan 29 16:33:41 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 29 Jan 2009 21:33:41 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: > On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac wrote: >> 2. It seems that slice objects and range objects are >> awfully similar in many ways. Is this "appearance only", >> or was there any discussion of unifying them? >> Curious for insight... On 1/29/2009 1:37 PM Chris Rebert apparently wrote: > Wouldn't really be possible, IMHO. True, they both have notions of > start, stop, and step, but slices don't make sense as ranges without > knowing the length of the container. Slices seem somewhat more general than ranges. > For example, take the slice > `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, > since -2 < 1 (stop < start ) and 1 (the step) is positive, the range > is nonsensical. Or rather, it makes sense, but is empty. But I take your point. However, I would turn it around slightly and ask: when is it not the case that range(*slice(start,stop,step).indices(stop)) != range(stop,start,step) If there are no interesting cases, then it seems that range might derive from slice. Just curious... > You have to replace all the negative indices with calculated positive > indices first in order to have a sensical range(), in this case, > replacing the stop of -2 with len(container)-2. > Also, more fundamentally, Python is liberal in what it allows for the > parts of slices, so unifying slices with ranges would break code. For > example, Python is perfectly happy if I go slice("a",[8],object), none > of which are even numbers. Ah, this is new in Python 3 I take it? I was not aware of this. Use case? Thanks! Alan From googler.1.webmaster at spamgourmet.com Thu Jan 29 16:38:21 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Thu, 29 Jan 2009 13:38:21 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: <452bfd80-b705-47eb-af57-d6c5cfb6b77e@r36g2000prf.googlegroups.com> Hi! Okay, I checkede Py_Main(...) and called some python code there. There it works too. So I know whats missing. sys.environ.. returns nothing. How can I set the paths with the Python C API? Thanks. From robert.kern at gmail.com Thu Jan 29 16:41:28 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jan 2009 15:41:28 -0600 Subject: slicings: 3 questions In-Reply-To: References: Message-ID: On 2009-01-29 15:33, Alan G Isaac wrote: >> On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac >> wrote: >>> 2. It seems that slice objects and range objects are >>> awfully similar in many ways. Is this "appearance only", >>> or was there any discussion of unifying them? >>> Curious for insight... > > > On 1/29/2009 1:37 PM Chris Rebert apparently wrote: >> Wouldn't really be possible, IMHO. True, they both have notions of >> start, stop, and step, but slices don't make sense as ranges without >> knowing the length of the container. > > Slices seem somewhat more general than ranges. > > >> For example, take the slice >> `1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However, >> since -2 < 1 (stop < start ) and 1 (the step) is positive, the range >> is nonsensical. > > Or rather, it makes sense, but is empty. > But I take your point. > > However, I would turn it around slightly and ask: > when is it not the case that > range(*slice(start,stop,step).indices(stop)) != range(stop,start,step) > > If there are no interesting cases, then it seems > that range might derive from slice. > Just curious... It's possible that it *could*, but there's also no real benefit to doing so. >> You have to replace all the negative indices with calculated positive >> indices first in order to have a sensical range(), in this case, >> replacing the stop of -2 with len(container)-2. >> Also, more fundamentally, Python is liberal in what it allows for the >> parts of slices, so unifying slices with ranges would break code. For >> example, Python is perfectly happy if I go slice("a",[8],object), none >> of which are even numbers. > > Ah, this is new in Python 3 I take it? No. Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> slice("a",[8],object) slice('a', [8], ) > I was not aware of this. Use case? It allows (ab)uses like numpy.mgrid: >>> mgrid[0:10:11j] array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) -- 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 thudfoo at opensuse.us Thu Jan 29 16:43:36 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Thu, 29 Jan 2009 13:43:36 -0800 Subject: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values In-Reply-To: <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> References: <4f421601-2556-4b78-8b63-1257f4b41029@d36g2000prf.googlegroups.com> <2e7ee18f-82df-44b8-9abf-ae1d6c136533@a12g2000pro.googlegroups.com> <7b41e652-647f-4182-9f71-5a99d2532e2d@v5g2000prm.googlegroups.com> <96fa0204-e41c-4715-9f1a-22f4b5692eb7@r10g2000prf.googlegroups.com> Message-ID: <3d881a310901291343s7f5ac4d4h546231ab3b8ac368@mail.gmail.com> On Thu, Jan 29, 2009 at 1:08 PM, alex wrote: > Duncan > Thank you for your explanation of the relationship between calling > convention and stack management. > I will try to understand better this topic in the CVF and ctypes > documentation (not so easy). > > Regards Alex > > -- > http://mail.python.org/mailman/listinfo/python-list > fwiw, ctypes has a mailing list: https://lists.sourceforge.net/lists/listinfo/ctypes-users From elsjaako at gmail.com Thu Jan 29 16:44:18 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 13:44:18 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> Message-ID: On Jan 29, 9:36?pm, r wrote: > On Jan 29, 1:33?pm, elsjaako wrote: > > There is a Python MIDI module, i think it is pyMIDI, have you checked > it out? Thank you for the responce. Unfortunately, that package is for OS X (it doesn't say that clearly on the website). But it might indeed be worthwhile to mention that I'd be more than happy to use a library, or a finished product (I asked for that elsewhere, nobody had any good ideas) From grim at asu.ntu-kpi.kiev.ua Thu Jan 29 16:50:07 2009 From: grim at asu.ntu-kpi.kiev.ua (Oleksiy Khilkevich) Date: Thu, 29 Jan 2009 23:50:07 +0200 Subject: Can't understand what python wants from me Message-ID: <4982248F.30505@asu.ntu-kpi.kiev.ua> Hello, everyone, This may be a totally noob question, but since I am one, so here is it. I have the following code (not something much of): http://paste.debian.net/27204 The current code runs well, but the problem is with input value: http://paste.debian.net/27205 ?s you can see, the numbers are ok, but strings and characters cause "not defined" error. I've obviously missing something important, but tutorial says nothing about this. Thank you for your help. From gagsl-py2 at yahoo.com.ar Thu Jan 29 16:51:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 19:51:52 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: En Thu, 29 Jan 2009 05:14:41 -0200, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels >> (I *think* this has to do with free variables in the "right side" (after >> the "in" keyword) of a generator expression; they appear to be evaluated >> when the expression is *defined*, not when is is *used*. By contrast, >> free >> variables in the "left side" appear to be evaluated when the expression >> is >> used.) >> > > Yikes! this is, IMO, far too complicated a way of looking at it. Sure? "Make everything as simple as possible, but not simpler." (att. A. Einstein). I cannot find a simpler way to explain it that is still true... > I think that if you rewrite the "comprehensions" as loops, > you will see what is happening. - in the one case, the locals() > returned is from the outer scope, while in the other the > locals function is called from inside the loop - a different scope, > because there must be *somewhere* where the state is kept to yield > the next value. But a loop doesn't define a new scope (only "def" and "class" used to define one; now generator expressions do too). The new scope is not the issue, but the fact that the right and left parts of a gen.expr. are evaluated at different times. This wasn't obvious to me -- and still isn't. If you rewrite the generator expression as a generator function you don't get the same behaviour: print "genexpr" A = [1,2,3] B = 1 g = (x+B for x in A) A = [4,5,6] B = 10 print list(g) # output: [11,12,13] # A is evaluated at the time g is *defined* # B is evaluated at the time g is *iterated* print "genfunc" A = [1,2,3] B = 1 def f(): for x in A: yield x+B A = [4,5,6] B = 10 g = f() A = [7,8,9] B = 100 print list(g) # output: [107,108,109] # A and B are evaluated at the time g is *iterated* Of course this is clearly stated in the Language Reference "Variables used in the generator expression are evaluated lazily in a separate scope when the next() method is called for the generator object (in the same fashion as for normal generators). However, the in expression of the leftmost for clause is immediately evaluated in the current scope..." -- but this behaviour is still surprising and not obvious to me. ("not obvious" means that things could have been different, choosing this was a design decision). As far as I can tell, this is the only case in Python where parts of the same expression are evaluated in different contexts at different times. > I find it very confusing because locals is always the same > function - but what it returns varies depending on where you > call it from. So if you want to pass it around, it's no good > passing the function - you have to pass the returned result, > *called from the scope of interest*. Subtle stuff. Yep, the fact that locals() returns a different thing depending on when/where you call it, was the initial clue to this issue. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jan 29 16:52:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 19:52:55 -0200 Subject: Why doesn't eval of generator expression work with locals? References: Message-ID: En Wed, 28 Jan 2009 18:06:01 -0200, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: > >> (I think this has to do with free variables in the "right side" (after >> the "in" keyword) of a generator expression; they appear to be evaluated >> when the expression is *defined*, not when is is *used*. By contrast, >> free >> variables in the "left side" appear to be evaluated when the expression >> is >> used.) > > Indeed, the right side is evaluated in the enclosing namespace and then > passed as an argument to the genexpr: > > >>> dis.dis(compile("(x for y in z)", "nofile", "exec")) > 1 0 LOAD_CONST 0 ( at > 0x2b22b2dcf828, file "nofile", line 1>) > 3 MAKE_FUNCTION 0 > 6 LOAD_NAME 0 (z) > 9 GET_ITER > 10 CALL_FUNCTION 1 > 13 POP_TOP > 14 LOAD_CONST 1 (None) > 17 RETURN_VALUE Yes, this is explained (in not so much detail) in the Language Reference. Now I *know* how it works, but still isn't *obvious* to me. -- Gabriel Genellina From comptekki at gmail.com Thu Jan 29 16:54:34 2009 From: comptekki at gmail.com (Wes James) Date: Thu, 29 Jan 2009 14:54:34 -0700 Subject: parsing text from a file Message-ID: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> If I read a windows registry file with a line like this: "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted Multicast|Edge=FALSE|" with this code: f=open('fwrules.reg2.txt') for s in f: if s.find('LANDesk') <0: print s, LANDesk is not found. Also this does not work: for s in f: try: i=s.index('L') print s[i:i+7] except: pass all it prints is "LAND" how do I find LANDesk in a string like this. is the "\\" messing things up? thx, -wj From benjamin.kaplan at case.edu Thu Jan 29 16:58:38 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 29 Jan 2009 16:58:38 -0500 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: On Thu, Jan 29, 2009 at 4:19 PM, John Machin wrote: > Benjamin Kaplan case.edu> writes: > > > > > > > On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan > anjanesh.net> wrote: > > > It does auto-detect it as cp1252- look at the files in the traceback > and > > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong > > > encoding, try opening it as utf-8 or latin1 and see if that fixes it. > > Benjamin, "auto-detect" has strong connotations of the open() call (with > mode > including text and encoding not specified) reading some/all of the file and > trying to guess what the encoding might be -- a futile pursuit and not what > the > docs say: > > """encoding is the name of the encoding used to decode or encode the file. > This > should only be used in text mode. The default encoding is platform > dependent, > but any encoding supported by Python can be passed. See the codecs module > for > the list of supported encodings""" > > On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It > would be interesting to know > (1) what is produced on Anjanesh's machine > (2) how the default encoding is derived (I would have thought I was a prime > candidate for 'cp1252') > (3) whether the 'default encoding' of open() is actually the same as the > 'default encoding' of sys.getdefaultencoding() -- one would hope so but the > docs > don't say so. First of all, you're right that might be confusing. I was thinking of auto-detect as in "check the platform and locale and guess what they usually use". I wasn't thinking of it like the web browsers use it. I think it uses locale.getpreferredencoding(). On my machine, I get sys.getpreferredencoding() == 'utf-8' and locale.getdefaultencoding()== 'cp1252'. When I open a file without specifying the encoding, it's cp1252. > > > Thanks a lot ! utf-8 and latin1 were accepted ! > > Benjamin and Anjanesh, Please understand that > any_random_rubbish.decode('latin1') will be "accepted". This is *not* > useful > information to be greeted with thanks and exclamation marks. It is merely a > by-product of the fact that *any* single-byte character set like latin1 > that > uses all 256 possible bytes can not fail, by definition; no character "maps > to > ". If you check my response to Anjanesh's comment, I mentioned that he should either find out which encoding it is in particular or he should open the file in binary mode. I suggested utf-8 and latin1 because those are the most likely candidates for his file since cp1252 was already excluded. Looking at a character map, 0x9d is a control character in latin1, so the page is probably UTF-8 encoded. Thinking about it now, it could also be MacRoman but that isn't as common as UTF-8. > > > If you want to read the file as text, find out which encoding it actually > is. > In one of those encodings, you'll probably see some nonsense characters. If > you > are just looking at the file as a sequence of bytes, open the file in > binary > mode rather than text. That way, you'll avoid this issue all together (just > make > sure you use byte strings instead of unicode strings). > > In fact, inspection of Anjanesh's report: > """UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position > 10442: character maps to > The string at position 10442 is something like this : > "query":"0 1?? \u2021 0\u201a0 \u2021??"," """ > > draws two observations: > (1) there is nothing in the reported string that can be unambiguously > identified > as corresponding to "0x9d" > (2) it looks like a small snippet from a Python source file! > > Anjanesh, Is it a .py file? If so, is there something like "# encoding: > cp1252" > or "# encoding: utf-8" near the start of the file? *Please* tell us what > sys.getdefaultencoding() returns on your machine. > > Instead of "something like", please report exactly what is there: > > print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) > > Cheers, > John > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Thu Jan 29 17:02:53 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 14:02:53 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype Message-ID: I'm trying to make a script environment with datatypes (or classes) for accessing hardware registers. At the top level, I would like the ability to bitwise ops if bit slice brackets are used, but if no brackets are used, I would like it to write/read the whole value. For example, if I have something like: >>> shadow_register = MyRegClass(0xAA) >>> shadow_register 170 >>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>> shadow_register 58 >>> shadow_register = 0x89 >>> shadow_register 137 >>> shadow_register[4:1] 4 I have the bitslice part working. But of course as expected, if I type >>> shadow_register <__main__.boo object at 0x00A130D0> I wanted to avoid having something like shadow_register.value just because it's clumsier. I read about the __new__() class for overriding the classtype, like: print 'foo' class foo(object): def __new__(*args): return 0 but if I stick in a __init__(self, val): method, then it chokes saying val is a global name that's not defined. Now I know that I have to live with the fact that I can't have >>> shadow_register = 0x89 Because it will get reassigned from my class value to a newly intialized memory location (int object). But can I have it read the value without the .value extension? Is this even possible? Maybe there's a way to override the = operator? (Go easy on me - I'm a hardware guy). Thx, Mark From bignose+hates-spam at benfinney.id.au Thu Jan 29 17:03:20 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 30 Jan 2009 09:03:20 +1100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <873af1vkgn.fsf@benfinney.id.au> MC writes: > Hi! > > Il se trouve que Chris Rebert a formul? : > > Python has functions, which are not associated with a class > > functions are methods of builtin... No, because ?builtin? is not a class. -- \ ?The shortest distance between two points is under | `\ construction.? ?Noelie Alito | _o__) | Ben Finney From vlastimil.brom at gmail.com Thu Jan 29 17:08:11 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 29 Jan 2009 23:08:11 +0100 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> 2009/1/29 Wes James : > If I read a windows registry file with a line like this: > ... > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > if s.find('LANDesk') <0: > print s, > > > LANDesk is not found. > > how do I find LANDesk in a string like this. is the "\\" messing things up? ... > > thx, > > -wj > Hi, if s.find('LANDesk') <0: is True for a line which doesn't contain "LANDesk"; if you want the opposite, try if s.find('LANDesk') >-1: hth vbr From rtw at freenet.co.uk Thu Jan 29 17:10:03 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Thu, 29 Jan 2009 16:10:03 -0600 Subject: pyAA for Python2.5 References: <077959bd-0df3-4458-9d87-075a99ce8b96@y23g2000pre.googlegroups.com> <40d6a2ed-53ae-4ebf-b604-972c8d2b37de@a39g2000prl.googlegroups.com> <6a594643-f6a2-4d8d-aab3-27eb16cb2fb8@b38g2000prf.googlegroups.com> Message-ID: Kottiyath wrote in news:d86a0c1d-e158-4aa1-a47f-e2149948bdc3 @p2g2000prf.googlegroups.com in comp.lang.python: > On Jan 29, 1:51?am, Rob Williscroft wrote: >> Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8 >> @b38g2000prf.googlegroups.com in comp.lang.python: >> >> > I have mingw32-gcc in my path. If I try that too -it fails. >> >> > C:\Documents and Settings\Guest\pyAA>python setup.py install -c >> > "mingw32-gcc" >> > invalid command name 'mingw32-gcc' >> >> All the examples I found via google have the tool name as "mingw32" >> so try: >> >> ? ? ? ? python setup.py install -c mingw32 > Thank you Rob. > The installation went ahead for some more time - but failed showing a > lot of errors: >>compile > running build > running build_py > file pyAAc.py (for module pyAAc) not found > file pyAAc.py (for module pyAAc) not found > ... > pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in > this scope > pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared > in this scope > pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not > declared in this scope > ... > error: command 'gcc' failed with exit status 1 > > I cannot understand why it fails. I have not worked in C till now, so > I am pretty confused. > I googled also, but to no avail. > Looks like the package needs some headers that haven't yet been ported to to MinGW. Alas that meands you'll need to build with the Microsoft SDK and compiler. You can get the SDK including a non-optimising compiler from: http://www.microsoft.com/downloads/details.aspx?FamilyId=9B3A2CA6-3647- 4070-9F41-A333C6B9181D&displaylang=en or maybe here: http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656- 4969-ACE8-E4C0C0716ADB&displaylang=en Rob. -- http://www.victim-prime.dsl.pipex.com/ From roman.yakovenko at gmail.com Thu Jan 29 17:12:11 2009 From: roman.yakovenko at gmail.com (Roman) Date: Thu, 29 Jan 2009 14:12:11 -0800 (PST) Subject: pygccxml xml output file References: Message-ID: <3d5ad16f-babb-446c-999c-ee21113fc51f@t39g2000prh.googlegroups.com> On Jan 24, 3:25?pm, whatazor wrote: > Hi all, > I start to use this module in order to produce xml( and the make other > things), but differently from gccxml I don't find the variable that > set the name of the xml output file after the parsing (in gccxml is - > fxml), so it creates temporary files. > how can I do an Is there a tutorial that explain with dectails how it > works? I suggest you to ask your questions on the following mailing list: https://lists.sourceforge.net/lists/listinfo/pygccxml-development As for your question: see http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader-module.html#create_cached_source_fc documentation. and http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader.project_reader_t-class.html#read_files HTH From clp2 at rebertia.com Thu Jan 29 17:25:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 14:25:54 -0800 Subject: Can't understand what python wants from me In-Reply-To: <4982248F.30505@asu.ntu-kpi.kiev.ua> References: <4982248F.30505@asu.ntu-kpi.kiev.ua> Message-ID: <50697b2c0901291425v1f2df55fsba8ca691e9b970f@mail.gmail.com> On Thu, Jan 29, 2009 at 1:50 PM, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. > > I have the following code (not something much of): > http://paste.debian.net/27204 > The current code runs well, but the problem is with input value: > http://paste.debian.net/27205 > ?s you can see, the numbers are ok, but strings and characters cause "not > defined" error. > > I've obviously missing something important, but tutorial says nothing about > this. You're using input(). You should be using raw_input(), at least until everyone switches to Python 3.0 (which confusingly renames raw_input() to input() because of the exact newbie confusion you're encountering). raw_input() reads a string from stdin. input() call raw_input() and then eval()-s the string, hence 'asd' gets interpreted as a variable, which doesn't exist in your program, hence the error. For further information, use help() on input and raw_input from the interactive interpreter REPL. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From chris.hulan at gmail.com Thu Jan 29 17:32:16 2009 From: chris.hulan at gmail.com (Chris Hulan) Date: Thu, 29 Jan 2009 14:32:16 -0800 (PST) Subject: Can't understand what python wants from me References: Message-ID: <805c9fd1-2e09-4f92-9c74-6e6f26f8d72b@t3g2000yqa.googlegroups.com> On Jan 29, 4:50?pm, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. > > I have the following code (not something much of):http://paste.debian.net/27204 > The current code runs well, but the problem is with input value:http://paste.debian.net/27205 > ?s you can see, the numbers are ok, but strings and characters cause > "not defined" error. > > I've obviously missing something important, but tutorial says nothing > about this. > > Thank you for your help. You want raw_input() input() expects the string enterd to be Python code, which it evals() numbers eval to thenmselves cheers From mark.seagoe at gmail.com Thu Jan 29 17:33:20 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 14:33:20 -0800 (PST) Subject: Can't understand what python wants from me References: Message-ID: On Jan 29, 1:50?pm, Oleksiy Khilkevich wrote: > Hello, everyone, > This may be a totally noob question, but since I am one, so here is it. For the input function, python is expecting you to input a number or a string. If you enter 'asd' without the '' then it thinks you are entering some variable that you've assigned to asd. Instead of asd, try to enter 'asd'. From sjmachin at lexicon.net Thu Jan 29 17:34:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 14:34:36 -0800 (PST) Subject: parsing text from a file References: Message-ID: On Jan 30, 8:54?am, Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > ? if s.find('LANDesk') <0: > ? ? print s, > > LANDesk is not found. You mean it's not printed. That code prints all lines that don't contain "LANDesk" > > Also this does not work: > > for s in f: > ? try: > ? ? i=s.index('L') > ? ? print s[i:i+7] > ?except: Using "except ValueError:" would be safer. > ? ?pass > > all it prints is "LAND" AFAICT your reported outcome is impossible given that such a line exists in the file. > > how do I find LANDesk in a string like this. What you were trying (second time, or first time (with >=) should work. I suggest that to diagnose your problem you change the second snippet as follows: 1. use except ValueError: 2. print s, len(s), i, and s.find('L') for all lines > ?is the "\\" messing things up? Each "\\" is presumably just the repr() of a single backslash. In any case whether there are 0,1,2 or many backslashes in a line or the repr () thereof has nothing to do with your problem. HTH, John From python.list at tim.thechases.com Thu Jan 29 17:36:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 16:36:34 -0600 Subject: parsing text from a file In-Reply-To: <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> <9fdb569a0901291408k41a1b31ep7cc6c942ec54dc34@mail.gmail.com> Message-ID: <49822F72.80209@tim.thechases.com> > if s.find('LANDesk') <0: > is True for a line which doesn't contain "LANDesk"; if you want the > opposite, try > if s.find('LANDesk') >-1: Or more pythonically, just use if 'LANDesk' in s: -tkc From sjmachin at lexicon.net Thu Jan 29 17:51:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 14:51:40 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: Message-ID: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> On Jan 30, 9:02?am, mark.sea... at gmail.com wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. ?At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>> shadow_register = MyRegClass(0xAA) > >>> shadow_register > 170 > >>> shadow_register[7:4] = 3 ?# <== changes value to 0x3A > >>> shadow_register > 58 > >>> shadow_register = 0x89 > >>> shadow_register > 137 > >>> shadow_register[4:1] > > 4 > > I have the bitslice part working. ?But of course as expected, if I > type>>> shadow_register > > <__main__.boo object at 0x00A130D0> def __str__(self): return "d" % self.value From elsjaako at gmail.com Thu Jan 29 17:53:10 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 14:53:10 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Message-ID: <325e699e-993a-4dcf-a86a-24c754d8c78d@k1g2000prb.googlegroups.com> On Jan 29, 8:33?pm, elsjaako wrote: > I think this means that the following could be said: > > typedef void *HANDLE; > struct HMIDIIN##__ { int unused; }; typedef struct HMIDIIN##__ > *HMIDIIN; > I figured this problem out (I'm sure there will be more...): A handle should just be a c_void_p ... From rNOSPAMon at flownet.com Thu Jan 29 17:53:24 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 14:53:24 -0800 Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> Message-ID: In article <498171a5$0$3681$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > Ron Garret a ?crit : > > In article , > > Aleksandar Radulovic wrote: > (snip) > >> Secondly, why are you restarting apache after code changes? In normal > >> circumstances, you shouldn't have to do that. > > > > I thought (and experiment confirms) that only the main WSGI app file > > gets reloaded automatically when it changes, not the libraries. > > Depends on how you configure mod_wsgi. Read the part about "Process > Reloading Mechanism" here: > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode I'm running Debian Etch, which means I have an older version of mod_wsgi, which means I don't have the process reloading mechanism. rg From rNOSPAMon at flownet.com Thu Jan 29 17:54:33 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 14:54:33 -0800 Subject: Sloooooowwwww WSGI restart References: <498170d4$0$23718$426a74cc@news.free.fr> Message-ID: In article <498170d4$0$23718$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > Ron Garret a ?crit : > > I'm running a WSGI app under apache/mod_wsgi and I've noticed that > > whenever I restart the server after making a code change it takes a very > > long time (like a minute) before the script is active again. In other > > words, I do an apachectl restart, reload the page in my browser, and one > > minute later it finally comes up. During this time CPU usage is > > essentially zero. Loading all the code manually into a python > > interpreter is virtually instantaneous, and all subsequence interactions > > with the app are very fast. > > > > Does anyone have any ideas what might be going on or how to debug this? > > Restarting apache (with or without mod_wsgi) can by itself take some time. > > Now, if you're running mod_wsgi in daemon mode, you _don't_ have to > restart apache to reload your code - just touch the wsgi script file and > you'll be done, ie with: > > > WSGIProcessGroup myproject.tld > WSGIDaemonProcess myproject.tld user=you group=you > WSGIReloadMechanism Process > WSGIScriptAlias / /var/www/myproject/apache/myapp.py > > > you just have to touch myapp.py to force reload the subinterpreter(s). Unfortunately, I'm running Debian Etch, which has an older mod_wsgi, which does not have the process reloading mechanism. But I guess if this gets too painful I'll upgrade. rg From stef.mientki at gmail.com Thu Jan 29 17:55:05 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 29 Jan 2009 23:55:05 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: Message-ID: <498233C9.1080906@gmail.com> mark.seagoe at gmail.com wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>>> shadow_register = MyRegClass(0xAA) >>>> shadow_register >>>> > 170 > >>>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>>> shadow_register >>>> > 58 > >>>> shadow_register = 0x89 >>>> shadow_register >>>> > 137 > >>>> shadow_register[4:1] >>>> > 4 > > I have the bitslice part working. But of course as expected, if I > type > >>>> shadow_register >>>> > <__main__.boo object at 0x00A130D0> > > I wanted to avoid having something like shadow_register.value just > because it's clumsier. I read about the __new__() class for > overriding the classtype, like: > > print 'foo' > class foo(object): > def __new__(*args): return 0 > > but if I stick in a __init__(self, val): method, then it chokes saying > val is a global name that's not defined. > > Now I know that I have to live with the fact that I can't have > >>>> shadow_register = 0x89 >>>> > Because it will get reassigned from my class value to a newly > intialized memory location (int object). But can I have it read the > value without the .value extension? Is this even possible? Maybe > there's a way to override the = operator? (Go easy on me - I'm a > hardware guy). > > Interesting what you're doing. I've struggled with the same issues, simulating a pic, never really solved them. Maybe this is what you're looking for: class MyRegClass ( object ) : def __init__ ( self, value ) : self.Value = value def __repr__ ( self ) : line = hex ( self.Value ) line = line [:2] + line [2:].upper() return line btw, I'm a hardware guy too, and therefor I've never understood why the hex function returns lowercase ;-) cheers, Stef From rNOSPAMon at flownet.com Thu Jan 29 18:01:07 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 15:01:07 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect Message-ID: I'm running mod_wsgi under apache (on Debian etch so it's a somewhat out of date version, though I doubt that has anything to do with this issue). I have a little test page that displays the process ID under which my app is running, and some global state, so I can tell when the wsgi app gets reloaded. This mostly only happens when I restart apache, but it also seems to happen when my WSGI app does an HTTP 302 redirect. (I'm actually using Yaro and calling req.redirect, but that only does a straightforward HTTP 302 redirect as far as I can tell.) It not only resets the global state, but changes process ID, so it seems to be doing a complete restart of mod_wsgi, which seems a little excessive. My question is: is this supposed to be happening? Or is this an indication that something is wrong, and if so, what? Thanks, rg From sjmachin at lexicon.net Thu Jan 29 18:01:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 29 Jan 2009 15:01:21 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: Message-ID: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> On Jan 30, 9:55?am, Stef Mientki wrote: > ? def __repr__ ( self ) : > ? ? line = hex ( self.Value ) > ? ? line = line [:2] + line [2:].upper() > ? ? return line > > btw, I'm a hardware guy too, and therefor I've never understood why the > hex function returns lowercase ;-) 0xFF?? *Real* hardware guys prefer FFh or 377 :-) From mark.seagoe at gmail.com Thu Jan 29 18:09:31 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 15:09:31 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: Thanks. So far these solutions will return strings. So I can't really treat it like a variable, yet still perform bitslice on it, since I need a special class to do bitslice and bit selection, but as soon as I try to pass it into some other function to check a bit, I gotta then do another operation to convert back to a variable. So I can get it to a point where I can do shadow_register[3] and get the value of any bit, or I can do shadow_register[4:2] and get a bitslice, and I can write them just as easily at this point. If I add the __new__ method into the class, the instance obj becomes int, but is no longer slicable. I think it looks like I can't have it both ways. From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:12:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:12:35 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: > I have frozen a running application which is using SQLite with py2exe. > When I start the exe file I see in the log file of the exe: > Traceback (most recent call last): > File "dpconf.py", line 666, in ? > File "dpconf.py", line 251, in __init__ > File "sqlite\main.pyc", line 255, in execute > _sqlite.DatabaseError: no such table: genslaveopt > > The table exist in the database file ... no problem with the plain > python version. Did you solve this problem? As you posted 4 related messages and the last one might imply a solution to this first one... -- Gabriel Genellina From stef.mientki at gmail.com Thu Jan 29 18:13:16 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 00:13:16 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <4982380C.8050300@gmail.com> mark.seagoe at gmail.com wrote: > Thanks. So far these solutions will return strings. So I can't > really treat it like a variable, yet still perform bitslice on it, > since I need a special class to do bitslice and bit selection, but as > soon as I try to pass it into some other function to check a bit, I > gotta then do another operation to convert back to a variable. > > So I can get it to a point where I can do shadow_register[3] and get > the value of any bit, or I can do shadow_register[4:2] and get a > bitslice, and I can write them just as easily at this point. If I add > the __new__ method into the class, the instance obj becomes int, but > is no longer slicable. I think it looks like I can't have it both > ways. > -- > http://mail.python.org/mailman/listinfo/python-list > there are a few vhdl projects, can't find my links right now - myhdl - something like pysystemC maybe you can find the answer there cheers, Stef From stef.mientki at gmail.com Thu Jan 29 18:25:03 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 00:25:03 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <49823ACF.30703@gmail.com> mark.seagoe at gmail.com wrote: > Thanks. So far these solutions will return strings. So I can't > really treat it like a variable, yet still perform bitslice on it, > since I need a special class to do bitslice and bit selection, but as > soon as I try to pass it into some other function to check a bit, I > gotta then do another operation to convert back to a variable. > > So I can get it to a point where I can do shadow_register[3] and get > the value of any bit, or I can do shadow_register[4:2] and get a > bitslice, and I can write them just as easily at this point. If I add > the __new__ method into the class, the instance obj becomes int, but > is no longer slicable. I think it looks like I can't have it both > ways. > -- > http://mail.python.org/mailman/listinfo/python-list > try this: class MyRegClass ( int ) : def __init__ ( self, value ) : self.Value = value def __repr__ ( self ) : line = hex ( self.Value ) line = line [:2] + line [2:].upper() return line __str__ = __repr__ cheers, Stef From elsjaako at gmail.com Thu Jan 29 18:26:30 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 15:26:30 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> Message-ID: <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> On Jan 29, 10:44?pm, elsjaako wrote: > On Jan 29, 9:36?pm, r wrote: > > > On Jan 29, 1:33?pm, elsjaako wrote: > > > There is a Python MIDI module, i think it is pyMIDI, have you checked > > it out? > > Thank you for the responce. Unfortunately, that package is for OS X > (it doesn't say that clearly on the website). But it might indeed be > worthwhile to mention that I'd be more than happy to use a library, or > a finished product (I asked for that elsewhere, nobody had any good > ideas) Never mind. I was wrong. It still doesnt work. Just managed to get a normal error instead of WindowsError: exception: access violation reading 0x00000000 From BrianVanderburg2 at aim.com Thu Jan 29 18:36:19 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 18:36:19 -0500 Subject: Understanding descriptors Message-ID: <49823D73.70304@aim.com> I'm trying to better understand descriptors and I've got a few questions still after reading some sites. Here is what I 'think', but please let me know if any of this is wrong as I'm sure it probably is. First when accessing an attribute on a class or instance it must be found. For an instance, it's __dict__ is first search. If not found the class and base class __dict__ are searched. For a class, the __dict__ and base classes __dict__ are search. If assigning, and the attribute is found and is not a descriptor or if the attribute is not found, then the assignment will occur in the __dict__ of the class or instance. If it is found and is a descriptor, then __set__ will be call. For reading, if the attribute is found and is a descriptor, __get__ will be called, passing the object (if it is an instance) and class. If it is not a descriptor, the attribute will be returned directly. Class methods are just functions: class C(object): def F(self): pass C.__dict__['F'] # function object ... But functions are descriptors: C.__dict__['F'].__get__ # method wrapper ... def f1(): pass f1.__get__ # method wrapper ... When a lookup is done it uses this descriptor to make a bound or unbound method: c=C() C.F # unbound method object, expects explicit instance when calling the function c.F # bound method object provides instance implicitly when calling the function This is also done when adding to the classes: C.f1 = f1 f1 # function C.f1 # unbound method c.f1 # bound method To prevent this it has to be decorated so the descriptor doesn't cause the binding: C.f2 = staticmethod(f1) C.f2 # functon c.f2 # function Here is a question, why don't instance attributes do the same thing? c.f3 = f1 c.f3 # function, not bound method So it is not calling the __get__ method for c.f3 After it finds c.f3 in c.__dict__, and since it has a getter, shouldn't it call the __get__ to return the bound method. It is good that it doesn't I know, but I just want to know why it doesn't from an implementation view. Brian Vanderburg II From rhodri at wildebst.demon.co.uk Thu Jan 29 18:36:51 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 29 Jan 2009 23:36:51 -0000 Subject: Exec woes In-Reply-To: <01d601c981f5$e721ea60$0d00a8c0@hendrik> References: <000b01c980a1$8dd4e700$0d00a8c0@hendrik> <7a9c25c20901270945x2ae404aes982084cad663b08b@mail.gmail.com> <015d01c9811c$c6042e80$0d00a8c0@hendrik> <01d601c981f5$e721ea60$0d00a8c0@hendrik> Message-ID: On Thu, 29 Jan 2009 08:15:57 -0000, Hendrik van Rooyen wrote: > "Rhodri James" wrote: > To: > Sent: Thursday, January 29, 2009 6:12 AM > Subject: Re: Exec woes > > >> On Wed, 28 Jan 2009 07:47:00 -0000, Hendrik van Rooyen >> wrote: > >> > This is actually not correct - it is the root cause of my trouble. >> > if you write, in a nested scope: >> > >> > exec ( "somestring to execute" in globals(),locals()) >> > >> > You get the syntax error, as the interpreter somehow sees it as one, >> > unqualified thing. >> >> Well, no. Look at the error Python gives you, nested scope or not: >> >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: exec: arg 1 must be a string, file, or code object >> >> If exec is a function, arg 1 is the boolean expression >> "somestring to execute" in globals() >> which is unlikely to be what you want. If exec is a statement, >> arg 1 is a tuple of two elements, >> "somestring to execute" in globals() >> and >> locals() >> which is also unlikely to be what you want. Neither of these are >> giving you a string, file or code object, exactly as the interpreter >> is telling you. > > Well, no - I stick by my assertion, about the nested scope: > >>>> def rubbish(): > def deep_rubbish(): > exec('BUILD = "somestring"' in globals(),locals()) > > SyntaxError: unqualified exec is not allowed in function 'deep_rubbish' > it is a > nested function (, line 3) >>>> > > That is all I was saying - It was the brackets that buggered me, > and adding the globals() and locals() inside the brackets, inside > the nested scope, makes no difference - the interpreter sees it > as an unqualified exec. Correct. In the language of the previous error message, the tuple ('BUILD = "something"' in globals(), locals()) is still the first argument. > Did you actually try it in a nested scope before asserting > "nested scope or not" ? Sorry, I assumed that you'd noticed that they were complaining about the same thing. > If you just do, in the outside scope, the thing I did originally: > >>>> exec('BUILD = "foobar"') >>>> BUILD > 'foobar' >>>> > > Then the brackets are ignored, and the defaults kick in. There are no commas, so the brackets are just fulfilling their usual roll of overriding operator precedence. Nothing strange there. There really is nothing unusual at all going on here. Please don't get the idea that brackets do anything unusual with an exec, or any other Python statement for that matter. -- Rhodri James *-* Wildebeeste Herder to the Masses From joshua at joshuakugler.com Thu Jan 29 18:43:18 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Thu, 29 Jan 2009 14:43:18 -0900 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: Ron Garret wrote: > My question is: is this supposed to be happening? Or is this an > indication that something is wrong, and if so, what? You are probably just hitting a different instance of Apache, thus the different process ID. j From rNOSPAMon at flownet.com Thu Jan 29 18:43:49 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 15:43:49 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: In article , Ron Garret wrote: > I'm running mod_wsgi under apache (on Debian etch so it's a somewhat out > of date version, though I doubt that has anything to do with this issue). > > I have a little test page that displays the process ID under which my > app is running, and some global state, so I can tell when the wsgi app > gets reloaded. This mostly only happens when I restart apache, but it > also seems to happen when my WSGI app does an HTTP 302 redirect. (I'm > actually using Yaro and calling req.redirect, but that only does a > straightforward HTTP 302 redirect as far as I can tell.) It not only > resets the global state, but changes process ID, so it seems to be doing > a complete restart of mod_wsgi, which seems a little excessive. > > My question is: is this supposed to be happening? Or is this an > indication that something is wrong, and if so, what? > > Thanks, > rg Here's a standalone WSGI app demonstrating the phenomenon: def redirect_test(env, start): if env['PATH_INFO']: start('302 Found', [('Location', '/')]) return ['Redirecting'] else: start('200 OK', [('Content-type', 'text/plain')]) return ['PID', str(os.getpid())] pass application = redirect_test Fire this up under mod_wsgi and observe that the process ID stays the same when you reload the app. Now add a path component to trigger the redirect and observe that process ID changes. rg From elsjaako at gmail.com Thu Jan 29 18:46:27 2009 From: elsjaako at gmail.com (elsjaako) Date: Thu, 29 Jan 2009 15:46:27 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> Message-ID: <9f5a0a78-2f5d-4b6c-8f17-8cf5825f500e@w39g2000prb.googlegroups.com> On Jan 30, 12:26?am, elsjaako wrote: > On Jan 29, 10:44?pm, elsjaako wrote: > > > On Jan 29, 9:36?pm, r wrote: > > > > On Jan 29, 1:33?pm, elsjaako wrote: > > > > There is a Python MIDI module, i think it is pyMIDI, have you checked > > > it out? > > > Thank you for the responce. Unfortunately, that package is for OS X > > (it doesn't say that clearly on the website). But it might indeed be > > worthwhile to mention that I'd be more than happy to use a library, or > > a finished product (I asked for that elsewhere, nobody had any good > > ideas) > > Never mind. I was wrong. It still doesnt work. Just managed to get a > normal error instead of WindowsError: exception: access violation > reading 0x00000000 Finally got it to work! I will soon packige it and publish it somewhere, so that the next person doesn't have to get frustrated (hint: use WINCFUNCTYPE) From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:47:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:47:20 -0200 Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 14:04:49 -0200, Alejandro escribi?: > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. > > In each of the threads I have > > def run(self): > pid = os.getpid() > logger.critical('process ID: %s', pid) > > However, the reported PID is the father number, not the PID of the new > thread. Is there a way to get the PID of the thread? Using "pid" for a thread identifier is confusing; I'd call it tid instead. (getpid() used to return a thread id in old Linux kernels, but that was a mess). Try using Thread.ident (requires Python 2.6). I'd expect it to return gettid() but I've not checked it; from the docs, it might be a synthesized number as well. In case it doesn't work, you can use ctypes to perform a gettid syscall. -- Gabriel Genellina From mark.seagoe at gmail.com Thu Jan 29 18:49:26 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 15:49:26 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <7cbee529-10d9-4c46-b683-8c46c4e3a09b@t39g2000prh.googlegroups.com> On Jan 29, 3:13?pm, Stef Mientki wrote: > mark.sea... at gmail.com wrote: > > Thanks. ?So far these solutions will return strings. ?So I can't > > really treat it like a variable, yet still perform bitslice on it, > > since I need a special class to do bitslice and bit selection, but as > > soon as I try to pass it into some other function to check a bit, I > > gotta then do another operation to convert back to a variable. > > > So I can get it to a point where I can do shadow_register[3] and get > > the value of any bit, or I can do shadow_register[4:2] and get a > > bitslice, and I can write them just as easily at this point. ?If I add > > the __new__ method into the class, the instance obj becomes int, but > > is no longer slicable. ?I think it looks like I can't have it both > > ways. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > there are a few vhdl projects, > can't find my links right now > - myhdl > - something like pysystemC > > maybe you can find the answer there > > cheers, > Stef- Hide quoted text - > > - Show quoted text - Thanks, Stef - I'll check them out. I have a feeling they are going through a preprocessing stage (ie. won't take command in a pure python window) but it's worth checking out. From google at mrabarnett.plus.com Thu Jan 29 18:50:08 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jan 2009 23:50:08 +0000 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <498240B0.3070608@mrabarnett.plus.com> Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" > > with this code: > > f=open('fwrules.reg2.txt') > > for s in f: > if s.find('LANDesk') <0: > print s, > > > LANDesk is not found. > > Also this does not work: > > for s in f: > try: > i=s.index('L') > print s[i:i+7] > except: > pass > > all it prints is "LAND" > > how do I find LANDesk in a string like this. is the "\\" messing things up? > How do you know what's in the file? Did you use an editor? It might be that the file contents are encoded in, say, UTF-16 and the editor is detecting that and decoding it for you, but Python's open() function is just returning the contents as a bytestring (Python 2.x). Try: import codecs f = codecs.open('fwrules.reg2.txt', encoding='UTF-16') for s in f: if u'LANDesk' in s: print s, f.close() From anders.u.persson at gmail.com Thu Jan 29 18:51:19 2009 From: anders.u.persson at gmail.com (anders) Date: Thu, 29 Jan 2009 15:51:19 -0800 (PST) Subject: search speed Message-ID: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Hi! I have written a Python program that serach for specifik customer in files (around 1000 files) the trigger is LF01 + CUSTOMERNO So a read all fils with dirchached Then a loop thru all files each files is read with readLines() and after that scaned Today this works fine, it saves me a lot of manuall work, but a seach takes around 5 min, so my questin is is there another way of search in a file (Today i step line for line and check) What i like to find is just filenames for files with the customerdata in, there can and often is more than one, English is not my first language and i hope someone understand my beginner question what i am looking for is somting like if file.findInFile("LF01"): ....... Is there any library like this ?? Best Regards Anders From gagsl-py2 at yahoo.com.ar Thu Jan 29 18:57:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 21:57:14 -0200 Subject: Weird invisible arguments issues with Windows References: Message-ID: En Thu, 29 Jan 2009 19:31:08 -0200, Uberman escribi?: > You all seem to be pointing at the same thing, and on my system, I show: > > C:\Users\Administrator>ftype python.file > python.file="D:\Python26\python.exe" "%1" %* > > and > > C:\Users\Administrator>assoc .py > .py=Python.File > > Which all seems to be correct. I'm guessing this doesn't bode well... Note that file association is a per-user setting; does it fail using the same user as above (Administrator)? -- Gabriel Genellina From rNOSPAMon at flownet.com Thu Jan 29 19:01:40 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 29 Jan 2009 16:01:40 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: In article , Joshua Kugler wrote: > Ron Garret wrote: > > My question is: is this supposed to be happening? Or is this an > > indication that something is wrong, and if so, what? > > You are probably just hitting a different instance of Apache, thus the > different process ID. Yep, that's what it turned out to be. I thought I had a WSGIDaemonProcess processes=1 directive in my config, but I had it in the wrong place (a different vhost) so it wasn't actually active. But that leaves me wondering why the redirect would reliably trigger switching processes. The reason I thought that I had the correct configuration and only had one process is that when I reloaded the non-redirected page I *always* got the same process ID. How does mod_wsgi decide which process (and which thread for that matter) to use? rg From google at mrabarnett.plus.com Thu Jan 29 19:04:52 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 00:04:52 +0000 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> References: <2e4dce09-560b-4040-8feb-f928322307dd@w39g2000prb.googlegroups.com> Message-ID: <49824424.1080106@mrabarnett.plus.com> John Machin wrote: > On Jan 30, 9:02 am, mark.sea... at gmail.com wrote: >> I'm trying to make a script environment with datatypes (or classes) >> for accessing hardware registers. At the top level, I would like the >> ability to bitwise ops if bit slice brackets are used, but if no >> brackets are used, I would like it to write/read the whole value. >> >> For example, if I have something like: >> >>>>> shadow_register = MyRegClass(0xAA) >>>>> shadow_register >> 170 >>>>> shadow_register[7:4] = 3 # <== changes value to 0x3A >>>>> shadow_register >> 58 >>>>> shadow_register = 0x89 >>>>> shadow_register >> 137 >>>>> shadow_register[4:1] >> 4 >> >> I have the bitslice part working. But of course as expected, if I >> type>>> shadow_register >> >> <__main__.boo object at 0x00A130D0> > > def __str__(self): > return "d" % self.value > That should be: return "%d" % self.value From todpose at hotmail.com Thu Jan 29 19:06:09 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Thu, 29 Jan 2009 16:06:09 -0800 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: How can you make python round numbers to the nearest 5: Example: 3 => 0 8 => 10 23.2 => 20 36 => 35 51.5 => 50 Thanks! _________________________________________________________________ Twice the fun?Share photos while you chat with Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Jan 29 19:09:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 22:09:56 -0200 Subject: slicings: 3 questions References: Message-ID: En Thu, 29 Jan 2009 19:41:28 -0200, Robert Kern escribi?: > On 2009-01-29 15:33, Alan G Isaac wrote: >> On 1/29/2009 1:37 PM Chris Rebert apparently wrote: >>> Also, more fundamentally, Python is liberal in what it allows for the >>> parts of slices, so unifying slices with ranges would break code. For >>> example, Python is perfectly happy if I go slice("a",[8],object), none >>> of which are even numbers. >> >> Ah, this is new in Python 3 I take it? > > No. [test using 2.5.1] Just out of curiosity, I tried with the oldest Python I have: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> slice("a",[8],3j) slice('a', [8], 3j) So, no, it's far for being a new feature... -- Gabriel Genellina From berankin99 at yahoo.com Thu Jan 29 19:19:18 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Thu, 29 Jan 2009 16:19:18 -0800 (PST) Subject: error on building 2.6.1. (_ctypes) Message-ID: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Hello, I am trying to build python 2.6 on a machine (web server) that I do not have root access to. (has 2.4 installed) Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1. Here is the command line I am using: ../configure -prefix=/home/username/local-python/ --enable-unicode=ucs4 (I don't know exactly what the ucs4 thing is for, but all the HOWTOs I saw say to use it. Is it good practice? Anyway, i get the same error either way.) Here is what the existing python reports itself as: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Python 2.4.3 (#1, Jul 29 2007, 14:09:31) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the error after I run "make": ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [SNIP] /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: error: syntax error before '*' token /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: warning: function declaration isn't a prototype /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In function `CFuncPtr_nonzero': /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: error: `self' undeclared (first use in this function) Failed to find the necessary bits to build these modules: _tkinter bsddb185 sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _ctypes running build_script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I am guessing that I don't need tkinter or sunaudiodev, but what about the others? What's the fix for this sort of thing? I do see via google some other folks are having the same issue, but I could find a solution. Thanks :) From rt8396 at gmail.com Thu Jan 29 19:21:08 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 16:21:08 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" Message-ID: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> I been around the list for a while and rubbed sholders with some pythonistas(some you would not beleieve if i told you) and i just don't see a community spirit here. Where are the community projects supporting Python? -- besides the core devlopment. Seem s that nobody is interested unless their pay-pal account is involved. I find this all quite disappointing. Also if anyone dares to mention that Python is a great language or better in this reguard or that, they get jumped and beat to death by their "so-called" brothers. AKAIK there is a group for every languge out there. C, Perl, Java, Ruby, etc, etc. This is comp.lang.python, if you don't like it, hang out in "comp.lang.whatever". Don't tell me or anybody "Comparing Python -> Perl is not allowed here!". From gherron at islandtraining.com Thu Jan 29 19:22:01 2009 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 29 Jan 2009 16:22:01 -0800 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <49824829.9000001@islandtraining.com> todpose at hotmail.com wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 round(n,-1) rounds to the nearest 10, so round(n*2,-1)/2 will round to the nearest five. Gary Herron > > > Thanks! > > ------------------------------------------------------------------------ > Twice the fun? Share photos while you chat with Windows Live > Messenger. > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > From reckoner at gmail.com Thu Jan 29 19:22:42 2009 From: reckoner at gmail.com (Reckoner) Date: Thu, 29 Jan 2009 16:22:42 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> Message-ID: <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> On Jan 28, 10:17?pm, Peter Wang wrote: > On Jan 27, 3:16?pm,Reckoner wrote: > > > > > I'm not sure this is possible, but I would like to have > > a list of ?objects > > > A=[a,b,c,d,...,z] > > > where, ?in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that > > something about the ?object 'a' has changed so that when I revisit A, > > I will know that the other items in the list need to be refreshed to > > reflect the changes in A as a result of changing 'a'. > > > Even better would be to automatically percolate the subsequent changes > > that resulted from altering 'a' for the rest of the items in the list. > > Naturally, all of these items are related in some parent-child > > fashion. > > > that might be a lot to ask, however. > > > Any advice appreciated. > > You should really look at Enthought's Traits package. ?It does exactly > what you are asking for, and much, much more. ?See: > > http://code.enthought.com/projects/traits/documentation.phphttp://code.enthought.com/projects/traits/examples.php > > Using Traits, you could do the following: > > from enthought.traits.api import * > class Child(HasTraits): > ? ? state = Enum("happy", "sad", "bawling") > > class Parent(HasTraits): > ? ? child = Instance(Child) > > ? ? @on_trait_change('child.state') > ? ? def handler(self): > ? ? ? ? print "new child state:", self.child.state > > bob_jr = Child() > bob = Parent(child = bob_jr) > > bob_jr.state = "sad" > # This would result in bob.handler() being called > > (Disclosure: I work at Enthought and have been using Traits heavily > for the last 4+ years.) > > -Peter I haven't looked at Enthought in awhile. I want to avoid having to installing the entire Enthought toolsuite, however. Would I have to do that for Traits? Thanks again. From gagsl-py2 at yahoo.com.ar Thu Jan 29 19:23:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 29 Jan 2009 22:23:35 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: En Thu, 29 Jan 2009 17:07:01 -0200, escribi?: > i have a problem. I compiled Python and the socket module so I got > this structure. (all on windows) > > C:\test\dll_files\python25.dll > C:\test\my_app > C:\test\dll_files\DLLs\ > C:\test\dll_files\python.exe > > If I run python.exe I get the console and I can call "import socket" > which > succeeds. I wrote a small console app which is stored in C:\test\ and > embeddeds the python interpreter. I set the environment variable PATH > so the python25.dll can be load. The easiest way is to mirror the directory structure of a standard Python install. Python looks for Lib/os.py and, once found, derives all the other paths from here. See PC/getpathp.c in the source distribution. You have these alternatives: - put a lib\* containing at least os.py below the directory containing your main executable. - set a PYTHONHOME variable - call Py_SetProgramName - completely replace getpathp.c with your own functions -- Gabriel Genellina From python.list at tim.thechases.com Thu Jan 29 19:26:34 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Jan 2009 18:26:34 -0600 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982493A.90404@tim.thechases.com> > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 I'm not sure *any* rounding system will give those results. 3 should round up to 5 (not down to 0) and 23.2 should round up to 25 (not down to 20) in the same way that 8 rounds up to 10. tests = ( (3, 5), # not 0 (8, 10), (23.2, 25), # not 20 (36, 35), (51.5, 50), ) for x, expected in tests: result = int(round(x / 5.0) * 5) if result != expected: print "Failed:", x, result, expected break else: print "All tests passed" -tkc From google at mrabarnett.plus.com Thu Jan 29 19:27:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 00:27:09 +0000 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982495D.6090907@mrabarnett.plus.com> todpose at hotmail.com wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 > Divide by 5, round the result, then multiply by 5. From ysk1 at sfu.ca Thu Jan 29 19:29:11 2009 From: ysk1 at sfu.ca (Eric Kang) Date: Thu, 29 Jan 2009 16:29:11 -0800 (PST) Subject: Swapping values of two variables Message-ID: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> In python, I set: x=1 y=3 z = x x = y y = z This gave me 3 1, which are the values of x and y swapped. The following would have given me the same result: x, y = y, x But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory required to exchange two 32-bit quantities? What would be the pseudocode that achieves this minimum? From AlexandriaSupport at gmail.com Thu Jan 29 19:35:38 2009 From: AlexandriaSupport at gmail.com (viglen) Date: Thu, 29 Jan 2009 16:35:38 -0800 (PST) Subject: Quickbooks References: Message-ID: <04181750-2bd5-42ba-85f3-7736dbe8af30@d32g2000yqe.googlegroups.com> On Jan 28, 1:21?pm, Stephen Chapman wrote: > Has anyone Implemented the Quickbooks ?COM object in Python. ?If so can > you give me > an Idea of where to begin. > Thanks Have you tried to contact the customer support team? I have used them many times and they are very helpful. They have different levels of support members to help even the most complicated questions and problems regarding their POS Software. 1-888-320-7276 QuickBooks: Basic, Pro and Premier and Customer Manager 1-800-348-0254 QuickBooks: Point of Sale 1-866-340-QBES QuickBooks: Enterprise Solutions 1-800-881-2079 QuickBooks: Simple Start Desktop Edition Hours of Operation:1 (Pacific time) Point of Sale: Mon-Fri 6 A.M. to 8 P.M. Sat & Sun 7 A.M. to 4 P.M. All others: Mon-Fri 6 A.M. to 6 P.M. Support, www.AlexandriaComputers.com From alan.isaac at gmail.com Thu Jan 29 19:36:57 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 30 Jan 2009 00:36:57 GMT Subject: slicings: 3 questions In-Reply-To: References: Message-ID: On 1/29/2009 4:41 PM Robert Kern apparently wrote: > It allows (ab)uses like numpy.mgrid: > > >>> mgrid[0:10:11j] > array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) Ah of course. Obvious now, but I had presumed some deeper magic in that syntax, not recognizing that a legitimate slice object was being created. Thanks! Alan From jervisau at gmail.com Thu Jan 29 19:42:40 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Fri, 30 Jan 2009 11:42:40 +1100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: References: Message-ID: <8e63a5ce0901291642o65e3039esab02885cdd76f635@mail.gmail.com> On Fri, Jan 30, 2009 at 9:02 AM, wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/read the whole value. > > For example, if I have something like: > > >>> shadow_register = MyRegClass(0xAA) > >>> shadow_register > is it so bad to type: >>> shadow_register[:] 170 ?? I like this because it is quite clear as to what you are doing, and is consistent with the bit slicing you have (already) implemented. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Thu Jan 29 19:44:45 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 16:44:45 -0800 (PST) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: On Jan 29, 3:13?pm, Stef Mientki wrote: > mark.sea... at gmail.com wrote: > > Thanks. ?So far these solutions will return strings. ?So I can't > > really treat it like a variable, yet still perform bitslice on it, > > since I need a special class to do bitslice and bit selection, but as > > soon as I try to pass it into some other function to check a bit, I > > gotta then do another operation to convert back to a variable. > > > So I can get it to a point where I can do shadow_register[3] and get > > the value of any bit, or I can do shadow_register[4:2] and get a > > bitslice, and I can write them just as easily at this point. ?If I add > > the __new__ method into the class, the instance obj becomes int, but > > is no longer slicable. ?I think it looks like I can't have it both > > ways. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > there are a few vhdl projects, > can't find my links right now > - myhdl > - something like pysystemC > > maybe you can find the answer there > > cheers, > Stef- Hide quoted text - > > - Show quoted text - Thanks for the tip. I checked out myhdl and it has a class called intbv which does exactly this, and much more than I need. It's GNU lesser license though, so not sure how to handle that, if I just want some concepts of the code as examples, but don't want copy it per se. Thanks, Mark From bj_666 at gmx.net Thu Jan 29 19:54:11 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 30 Jan 2009 00:54:11 GMT Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> Message-ID: <6uf1djFengojU2@mid.uni-berlin.de> On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > try this: > > class MyRegClass ( int ) : > def __init__ ( self, value ) : > self.Value = value > def __repr__ ( self ) : > line = hex ( self.Value ) > line = line [:2] + line [2:].upper() > return line def __repr__(self): return '0x%X' % self.value > __str__ = __repr__ This is unnecessary, the fallback of `__str__` is `__repr__` already. Ciao, Marc 'BlackJack' Rintsch From alan.isaac at gmail.com Thu Jan 29 19:56:54 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 30 Jan 2009 00:56:54 GMT Subject: naming and binding (subtle Python 3 change) Message-ID: The example give at http://docs.python.org/reference/executionmodel.html#naming-and-binding remains unchanged at http://docs.python.org/3.0/reference/executionmodel.html#naming-and-binding but the change to Python 3 list comprehensions now means the example will fail even with list comprehension syntax. Should the example be changed to make that clear? Alan Isaac From google at mrabarnett.plus.com Thu Jan 29 20:11:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 01:11:05 +0000 Subject: Swapping values of two variables In-Reply-To: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: <498253A9.8050407@mrabarnett.plus.com> Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > > This gave me 3 1, which are the values of x and y swapped. > The following would have given me the same result: > x, y = y, x > > But could the swapping be done using less extra memory than this? > What is the minimum amount of extra memory required to exchange two > 32-bit quantities? What would be the pseudocode that achieves this > minimum? > x ^= y y ^= x x ^= y This is really only of use when working in assembly language. From gnewsg at gmail.com Thu Jan 29 20:11:21 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 29 Jan 2009 17:11:21 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: > Where are the community projects supporting Python? -- besides the > core devlopment. http://pypi.python.org/pypi ...which accidentally says "There are currently 5597 packages here." Not bad uh? --- Giampaolo http://code.google.com/p/pyftpdlib From sjmachin at lexicon.net Thu Jan 29 20:22:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 01:22:50 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in =?utf-8?b?CXBvc2l0aW9u?= 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: Benjamin Kaplan case.edu> writes: > First of all, you're right that might be confusing. I was thinking of auto-detect as in "check the platform and locale and guess what they usually use". I wasn't thinking of it like the web browsers use it.I think it uses locale.getpreferredencoding(). You're probably right. I'd forgotten about locale.getpreferredencoding(). I'll raise a request on the bug tracker to get some more precise wording in the open() docs. > On my machine, I get sys.getpreferredencoding() == 'utf-8' and locale.getdefaultencoding()== 'cp1252'. sys <-> locale ... +1 long-range transposition typo of the year :-) > If you check my response to Anjanesh's comment, I mentioned that he should either find out which encoding it is in particular or he should open the file in binary mode. I suggested utf-8 and latin1 because those are the most likely candidates for his file since cp1252 was already excluded. The OP is on a Windows machine. His file looks like a source code file. He is unlikely to be creating latin1 files himself on a Windows box. Under the hypothesis that he is accidentally or otherwise reading somebody else's source files as data, it could be any encoding. In one package with which I'm familiar, the encoding is declared as cp1251 in every .py file; AFAICT the only file with non-ASCII characters is an example script containing his wife's name! The OP's 0x9d is a defined character in code pages 1250, 1251, 1256, and 1257 -- admittedly all as implausible as the latin1 control character. > Looking at a character map, 0x9d is a control character in latin1, so the page is probably UTF-8 encoded. Thinking about it now, it could also be MacRoman but that isn't as common as UTF-8. Late breaking news: I presume you can see two instances of U+00DD (LATIN CAPITAL LETTER Y WITH ACUTE) in the OP's report "query":"0 1?? \u2021 0\u201a0 \u2021??"," Well, u'\xdd'.encode('utf8') is '\xc3\x9d' ... the Bayesian score for utf8 just went up a notch. The preceding character U+00BB (looks like >>) doesn't cause an exception because 0xBB unlike 0x9D is defined in cp1252. Curiously looking at the \uxxxx escape sequences: \u2021 is "double dagger", \u201a is "single low-9 quotation mark" ... what appears to be the value part of an item in a hard-coded dictionary is about as comprehensible as the Voynich manuscript. Trouble with cases like this is as soon as they become interesting, the OP often snatches somebody's one-liner that "works" (i.e. doesn't raise an exception), makes a quick break for the county line, and they're not seen again :-) Cheers, John From Graham.Dumpleton at gmail.com Thu Jan 29 20:38:02 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 17:38:02 -0800 (PST) Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: <63cf7deb-f15c-4259-aa24-1b8da846876d@r41g2000prr.googlegroups.com> On Jan 30, 11:01?am, Ron Garret wrote: > In article , > ?Joshua Kugler wrote: > > > Ron Garret wrote: > > > My question is: is this supposed to be happening? ?Or is this an > > > indication that something is wrong, and if so, what? > > > You are probably just hitting a different instance of Apache, thus the > > different process ID. > > Yep, that's what it turned out to be. ?I thought I had a > WSGIDaemonProcess processes=1 directive in my config, but I had it in > the wrong place (a different vhost) so it wasn't actually active. > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > But that leaves me wondering why the redirect would reliably trigger > switching processes. ?The reason I thought that I had the correct > configuration and only had one process is that when I reloaded the > non-redirected page I *always* got the same process ID. ?How doesmod_wsgidecide which process ?(and which thread for that matter) to use? Details on process/threading in mod_wsgi available at: http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading When using WSGIDaemonProcess directive, if you want a single process it is better to allow it to default to a single process and not have 'processes=1'. As soon as you say 'processes=1' it will trigger wsgi.multiprocess to be True rather than default of False. This may sound counter intuitive, but is a little back door to allow wsgi.multiprocess to be set to True somehow when distributing an application across a cluster of machines where it does need to be True even if each machine only has a single process for that application. Tthat wsgi.multiprocess is True will not usually matter unless you are trying to use debugging middleware that require that there only be a single process. As to why you were getting a different process, because you were actually running in embedded mode due to WSGIDaemonProcess/ WSGIProcessGroup being in wrong context, then what process was used was really up to Apache and how it works. Specifically it can have multiple processes that can listen on the HTTP port (80). Because only one should be listening at a time it uses a cross process mutex lock to mediate access. When a process handles a request, it gives up the lock. If using worker MPM then another thread in same process may get lock, or for either worker MPM or prefork MPM, then another process could get it. Which actually gets it is a bit indeterminate as simply depends on which process the operating system lets have the lock next. So, there is no strict rule one can say as to who would get it next. Graham Graham From Graham.Dumpleton at gmail.com Thu Jan 29 20:43:18 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 29 Jan 2009 17:43:18 -0800 (PST) Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> Message-ID: <146f6796-37b5-4220-bdb1-5119cb3ac7e1@z6g2000pre.googlegroups.com> On Jan 30, 9:53?am, Ron Garret wrote: > In article <498171a5$0$3681$426a7... at news.free.fr>, > ?Bruno Desthuilliers > > ?wrote: > > Ron Garret a ?crit : > > > In article , > > > ?Aleksandar Radulovic wrote: > > (snip) > > >> Secondly, why are you restarting apache after code changes? In normal > > >> circumstances, you shouldn't have to do that. > > > > I thought (and experiment confirms) that only the main WSGI app file > > > gets reloaded automatically when it changes, not the libraries. > > > Depends on how you configure mod_wsgi. Read the part about "Process > > Reloading Mechanism" here: > >http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode > > I'm running Debian Etch, which means I have an older version of > mod_wsgi, which means I don't have the process reloading mechanism. Back port available at: http://packages.debian.org/etch-backports/libapache2-mod-wsgi Graham From tony.clarke5 at googlemail.com Thu Jan 29 20:50:04 2009 From: tony.clarke5 at googlemail.com (tony.clarke5 at googlemail.com) Date: Thu, 29 Jan 2009 17:50:04 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: On Jan 30, 12:29?am, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > This gave me 3 1, which are the values of x and y swapped. > The following would have given me the same result: > x, y = y, x > > But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory required to exchange two 32-bit quantities? What would be the pseudocode that achieves this minimum? How about: def transpose(x, y): print x, y, 'becomes: ', x = x + y y = x - y x = x - y print x, ' ', y transpose(1,3) transpose (9,8) From schickb at gmail.com Thu Jan 29 21:48:39 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 18:48:39 -0800 (PST) Subject: new.instancemethod questions Message-ID: I'd like to add bound functions to instances, and found the instancemethod function in the new module. A few questions: 1. Why is instancemethod even needed? Its counter-intuitive (to me at least) that assigning a function to a class results in bound functions its instances, while assigning directly to instances does not create a bound function. So why doesn't assigning a function to an instance attribute result in a function bound to that instance? 2. The 2.6 docs say the new module is depreciated and refers to the types module instead. But I haven't found a way to create bound functions using the types module. Am I just missing something? Thanks, -Brad From mark.seagoe at gmail.com Thu Jan 29 21:57:22 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Thu, 29 Jan 2009 18:57:22 -0800 (PST) Subject: Using equals operator without changing reference pointer Message-ID: I know this may be asking too much of Python, but you never know unless you ask... So now having a class that can be treated like an int as far as math upon the instance name, and can be treated as in HDL simulators, allowing bitslice and bitselect ops, I was stoked. Also reading back the instance name returns the int, rather than text about the class name and location in memory. But... it would be wonderful if there was a way to assign a value without using any .member notation... if there were a way for me to specify that the reference would never change. For example: >>> myInst = MyClass(0xAA) >>> myInst 170 >>> myInst[0] # <== MyClass can do bit selection 0 >>> myInst = 0x55 # <== gets reassigned >>> myInst[0] # <== this is where it would choke 1 # <== this is the answer I would want Is there a way to lock down myInst so that it still refers to the original object, and is there some special member that will allow me to override the equals operator in this case? Or is that simply blasphemous against everything Python holds sacred? Certainly there is some keyword that I don't know about. Thanks! Mark From wuwei23 at gmail.com Thu Jan 29 22:01:52 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 19:01:52 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> On Jan 30, 10:21?am, r wrote: > I been around the list for a while and rubbed sholders with some > pythonistas(some you would not beleieve if i told you) and i just > don't see a community spirit here. Seriously, how -old- are you? Twelve? Thirteen? From max at alcyone.com Thu Jan 29 22:04:49 2009 From: max at alcyone.com (Erik Max Francis) Date: Thu, 29 Jan 2009 19:04:49 -0800 Subject: Using equals operator without changing reference pointer In-Reply-To: References: Message-ID: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> mark.seagoe at gmail.com wrote: > Is there a way to lock down myInst so that it still refers to the > original object, and is there some special member that will allow me > to override the equals operator in this case? Or is that simply > blasphemous against everything Python holds sacred? Certainly there > is some keyword that I don't know about. No. The assignment operator with a bare name on the left hand side is not overridable. You can override attribute access, however, with .__getattr__/.__getattribute__. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis The perfection of innocence, indeed, is madness. -- Arthur Miller From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:07:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:07:55 GMT Subject: Swapping values of two variables References: Message-ID: On Thu, 29 Jan 2009 16:29:11 -0800, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > > This gave me 3 1, which are the values of x and y swapped. The following > would have given me the same result: x, y = y, x Yes. > But could the swapping be done using less extra memory than this? What > is the minimum amount of extra memory required to exchange two 32-bit > quantities? What would be the pseudocode that achieves this minimum? Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes (96 bits) in size; a long will use as much memory as needed. If your application needs to optimize a swap of two ints, then Python is probably going to be much too memory-intensive for you. (But my money is on you doing premature optimization.) -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:31:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:31:03 GMT Subject: Swapping values of two variables References: Message-ID: On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > On Jan 30, 12:29?am, Eric Kang wrote: >> In python, I set: >> >> x=1 >> y=3 >> >> z = x >> x = y >> y = z >> >> This gave me 3 1, which are the values of x and y swapped. The >> following would have given me the same result: x, y = y, x >> >> But could the swapping be done using less extra memory than this? What >> is the minimum amount of extra memory required to exchange two 32-bit >> quantities? What would be the pseudocode that achieves this minimum? > > How about: > def transpose(x, y): > print x, y, 'becomes: ', > x = x + y > y = x - y > x = x - y > print x, ' ', y > > transpose(1,3) > transpose (9,8) I'm not sure what the point of that function is. It doesn't actually swap its arguments: >>> x = 23 >>> y = 42 >>> transpose(x, y) 23 42 becomes: 42 23 >>> x 23 >>> y 42 And it certainly doesn't save memory, as the original poster asked: >>> import dis >>> swap = compile('x, y = y, x', '', 'single') >>> dis.dis(swap) 1 0 LOAD_NAME 0 (y) 3 LOAD_NAME 1 (x) 6 ROT_TWO 7 STORE_NAME 1 (x) 10 STORE_NAME 0 (y) 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> dis.dis(transpose) 2 0 LOAD_FAST 0 (x) 3 PRINT_ITEM 4 LOAD_FAST 1 (y) 7 PRINT_ITEM 8 LOAD_CONST 1 ('becomes: ') 11 PRINT_ITEM 3 12 LOAD_FAST 0 (x) 15 LOAD_FAST 1 (y) 18 BINARY_ADD 19 STORE_FAST 0 (x) 4 22 LOAD_FAST 0 (x) 25 LOAD_FAST 1 (y) 28 BINARY_SUBTRACT 29 STORE_FAST 1 (y) 5 32 LOAD_FAST 0 (x) 35 LOAD_FAST 1 (y) 38 BINARY_SUBTRACT 39 STORE_FAST 0 (x) 6 42 LOAD_FAST 0 (x) 45 PRINT_ITEM 46 LOAD_CONST 2 (' ') 49 PRINT_ITEM 50 LOAD_FAST 1 (y) 53 PRINT_ITEM 54 PRINT_NEWLINE 55 LOAD_CONST 0 (None) 58 RETURN_VALUE The compiled code of the transpose function *alone* (not including all the other associated parts) takes 59 bytes, or 472 bits. >>> len(transpose.func_code.co_code) 59 Even if it worked, that's hardly using less memory than a direct swap. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:31:28 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:31:28 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > In addition to methods, Python has functions, which are not associated > with a class Yes they are. >>> (lambda: None).__class__ The function type itself has a class: >>> (lambda: None).__class__.__class__ -- Steven From mwilson at the-wire.com Thu Jan 29 22:38:37 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 29 Jan 2009 22:38:37 -0500 Subject: new.instancemethod questions References: Message-ID: schickb wrote: > I'd like to add bound functions to instances, and found the > instancemethod function in the new module. A few questions: > > 1. Why is instancemethod even needed? Its counter-intuitive (to me at > least) that assigning a function to a class results in bound functions > its instances, while assigning directly to instances does not create a > bound function. So why doesn't assigning a function to an instance > attribute result in a function bound to that instance? If I understand you correctly, rebinding to the instance would break code like: myfakefile.write = sys.stdout.write where the intent would be to redirect any output through myfakefile straight to sys.stdout. The code for the sys.stdout.write function would never find the attributes it needed in the instance of myfakefile. To do this, methods have to stay bound to their proper instances. Mel. From tjreedy at udel.edu Thu Jan 29 22:50:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 22:50:50 -0500 Subject: naming and binding (subtle Python 3 change) In-Reply-To: References: Message-ID: Alan G Isaac wrote: > The example give at > http://docs.python.org/reference/executionmodel.html#naming-and-binding > remains unchanged at > http://docs.python.org/3.0/reference/executionmodel.html#naming-and-binding > but the change to Python 3 list comprehensions now means the example > will fail even with list comprehension syntax. Should the example be > changed to make that clear? http://bugs.python.org/issue5106 From steven at REMOVE.THIS.cybersource.com.au Thu Jan 29 22:51:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 03:51:16 GMT Subject: Rounding to the nearest 5 References: Message-ID: On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote: >> How can you make python round numbers to the nearest 5: >> >> Example: >> >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > I'm not sure *any* rounding system will give those results. Round towards zero. > 3 should round up to 5 (not down to 0) That would be round to nearest. > result = int(round(x / 5.0) * 5) I think that should work. It even works for negative values: >>> int(round(-2.2 / 5.0) * 5) 0 >>> int(round(-2.7 / 5.0) * 5) -5 -- Steven From schickb at gmail.com Thu Jan 29 22:52:09 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 19:52:09 -0800 (PST) Subject: new.instancemethod questions References: Message-ID: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> On Jan 29, 7:38?pm, Mel wrote: > schickb wrote: > > I'd like to add bound functions to instances, and found the > > instancemethod function in the new module. A few questions: > > > 1. Why is instancemethod even needed? Its counter-intuitive (to me at > > least) that assigning a function to a class results in bound functions > > its instances, while assigning directly to instances does not create a > > bound function. So why doesn't assigning a function to an instance > > attribute result in a function bound to that instance? > > If I understand you correctly, rebinding to the instance would break code > like: > > myfakefile.write = sys.stdout.write > > where the intent would be to redirect any output through myfakefile straight > to sys.stdout. ?The code for the sys.stdout.write function would never find > the attributes it needed in the instance of myfakefile. ?To do this, > methods have to stay bound to their proper instances. > 1. I'm thinking about assigning free non-bound functions. Like: class A(object): pass def func(self): print repr(self) a = A() a.func = func # Why doesn't this automatically create a bound function (aka method)? 2. And what is the preferred way to do this if the "new" module and its instancemethod function are depreciated? -Brad From clp2 at rebertia.com Thu Jan 29 22:53:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 19:53:04 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <50697b2c0901291953j4af923d9nb7748f9bef1d7c64@mail.gmail.com> On Thu, Jan 29, 2009 at 7:31 PM, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > >> In addition to methods, Python has functions, which are not associated >> with a class > > Yes they are. > >>>> (lambda: None).__class__ > > > The function type itself has a class: > >>>> (lambda: None).__class__.__class__ > I think we're now quibbling over the interpretation of "associated". My intention was to contrast how methods and classmethods are stored and accessed through the class they are defined in (or grafted onto), whereas plain functions are not (instance/class variables that happen to hold functions notwithstanding). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Thu Jan 29 23:03:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Jan 2009 23:03:45 -0500 Subject: Using equals operator without changing reference pointer In-Reply-To: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> References: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> Message-ID: Erik Max Francis wrote: > mark.seagoe at gmail.com wrote: > >> Is there a way to lock down myInst so that it still refers to the >> original object, and is there some special member that will allow me >> to override the equals operator in this case? Or is that simply >> blasphemous against everything Python holds sacred? Certainly there >> is some keyword that I don't know about. > > No. The assignment operator with a bare name on the left hand side is > not overridable. So that 'name = ob' *always* binds name to ob. That is one thing one can depend on when reading Python code. > You can override attribute access, however, with > .__getattr__/.__getattribute__. I presume that you have over-riden __setitem__ in addition to __getitem__ so that myOb[0] = 1 sets the bit. You could add a branch to __setitem__ (or define __setslice__ in 2.x) so that myOb[:] = 0x55 does just what you want it to -- set all bits. Being able to get/set contiguous bits might be something you want anyway. tjr PS. When asking about internal details, specify version of interest, as there have been minor changes. From blackcapsoftware at gmail.com Thu Jan 29 23:06:42 2009 From: blackcapsoftware at gmail.com (blackcapsoftware at gmail.com) Date: Thu, 29 Jan 2009 20:06:42 -0800 (PST) Subject: Module/Library That is Able To Use Cookies + Proxies? Message-ID: <315e5bad-2c3f-4e69-b810-b9535266dfc9@f3g2000vbf.googlegroups.com> Hey guys, I have been search the net for a bit now and can't find anything. What I would like to do is be able to log into a site that uses cookies to store information about the user when logging in. This works fine and dandy with ClientCookie. Now, I want to be able to do so with a proxy, does anyone have any suggestions, or libraries? Any help is greatly appreciated. Regards From bignose+hates-spam at benfinney.id.au Thu Jan 29 23:11:38 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 30 Jan 2009 15:11:38 +1100 Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> Message-ID: <87vdrxsa9x.fsf@benfinney.id.au> alex23 writes: > On Jan 30, 10:21?am, r wrote: > > I been around the list for a while and rubbed sholders with some > > pythonistas(some you would not beleieve if i told you) and i just > > don't see a community spirit here. > > Seriously, how -old- are you? Twelve? Thirteen? Please stop baiting people. If you find someone to be annoying, don't incite them. Either find a way to direct the discussion to something more constructive, or filter it out. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but how will we get a pair of Abe Vigoda's pants?? | _o__) ?_Pinky and The Brain_ | Ben Finney From ysk1 at sfu.ca Thu Jan 29 23:13:52 2009 From: ysk1 at sfu.ca (Eric Kang) Date: Thu, 29 Jan 2009 20:13:52 -0800 (PST) Subject: Adding a positive number and a negative number Message-ID: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> In two?s complement representation, can adding one positive and one negative give you overflow? From rt8396 at gmail.com Thu Jan 29 23:21:03 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 20:21:03 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <184d23cd-dbef-4cb7-adab-5095e71fefba@g3g2000pre.googlegroups.com> Message-ID: On Jan 29, 9:01?pm, alex23 wrote: > Seriously, how -old- are you? Twelve? Thirteen? Ah, my good friend alex23. Somehow -- when i was writing this post -- i knew you would drop in and i swear i do not have any ESP abilities -- somehow i just knew. While your here why don't we take a walk down memory lane. Let's go back to our first encounter -- Yes, that crazy thread(i won't utter the title here). Seems i was promoting the inclusion of the Python language in a revolutionary and promising application and you were very upset about it. Why, i really don't know because you never told me. The only thing i can remember is you wishing me dead -- if i recall your wish was to cut off oxygen supply to my brain. I can't help but wonder of the devious thoughts that toil away in your demented little mind right now. Of what demise shall i suffer this time alex23. But please alex, at least -try- to be a little more creative, if i am to meet my end, i would hate for it to be some worn- out old cliche' From gagsl-py2 at yahoo.com.ar Thu Jan 29 23:35:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 02:35:38 -0200 Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Message-ID: En Thu, 29 Jan 2009 22:19:18 -0200, Bernard Rankin escribi?: > I am trying to build python 2.6 on a machine (web server) that I do not > have root access to. (has 2.4 installed) > > Python 2.5 builds fine, but I am getting an error when I run "make" for > 2.6.1. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: > error: syntax error before '*' token > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: > warning: function declaration isn't a prototype > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In > function `CFuncPtr_nonzero': > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: > error: `self' undeclared (first use in this function) Mmm... my 2.6.1 source show different line numbers, maybe you should check it's the right file? > Failed to find the necessary bits to build these modules: > _tkinter bsddb185 sunaudiodev > Failed to build these modules: > _ctypes > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > I am guessing that I don't need tkinter or sunaudiodev, but what about > the others? bsddb185 is just for compatibility with the old Berkeley DB. I'd be worried just by ctypes - and only if you actually require it. -- Gabriel Genellina From linuxguy123 at gmail.com Thu Jan 29 23:42:45 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Thu, 29 Jan 2009 21:42:45 -0700 Subject: libsudo ? Message-ID: <1233290565.3742.1.camel@localhost.localdomain> Does anyone know where I would find libsudo ? If you had the choice of using pexpect or libsudo, which would you use ? Thanks From BrianVanderburg2 at aim.com Thu Jan 29 23:51:29 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 23:51:29 -0500 Subject: new.instancemethod questions In-Reply-To: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> References: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> Message-ID: <49828751.8040503@aim.com> schickb at gmail.com wrote: > On Jan 29, 7:38 pm, Mel wrote: > >> schickb wrote: >> >>> I'd like to add bound functions to instances, and found the >>> instancemethod function in the new module. A few questions: >>> >>> 1. Why is instancemethod even needed? Its counter-intuitive (to me at >>> least) that assigning a function to a class results in bound functions >>> its instances, while assigning directly to instances does not create a >>> bound function. So why doesn't assigning a function to an instance >>> attribute result in a function bound to that instance? >>> >> If I understand you correctly, rebinding to the instance would break code >> like: >> >> myfakefile.write = sys.stdout.write >> >> where the intent would be to redirect any output through myfakefile straight >> to sys.stdout. The code for the sys.stdout.write function would never find >> the attributes it needed in the instance of myfakefile. To do this, >> methods have to stay bound to their proper instances. >> >> > > 1. I'm thinking about assigning free non-bound functions. Like: > > class A(object): > pass > > def func(self): > print repr(self) > > a = A() > a.func = func # Why doesn't this automatically create a bound > function (aka method)? > Actually I found out the implementation of why it doesn't after messing around some more. If an attribute is found in the instance dictionary, even if it is a descriptor it's __get__ doesn't get called, only if it is found in the class dictionary of the class or base classes. This makes it where you can store a function in the instance to be called later as a function for some useful purpose, for example two different instances of an object could use different sorting functions: # sort functions are responsible for sorting which mutation is the least and most fit def fitness1(v1, v2): # use one technique to determine which is more fit def fitness2(v1, v2): # use another technique to determine which is more fit ... # more fitness functions class Environment: def __init__(self, fitness, ...): self.fitness_func = fitness ... ... # create environments, each one has different fitness function a = Environment(fitness1) b = Environment(fitness2) Now when it is time to kill off the least fit of the genetic mutations, each environment can sort which is the least and most fit in different ways. > > 2. And what is the preferred way to do this if the "new" module and > its instancemethod function are depreciated? > > Most of the code I see does this with a closure something like this: def AddMethod(obj, func, name=None): if name is None: name = func.__name__ def method(*args, **kwargs): return func(obj, *args, **kwargs) setattr(obj, name, method) class MyClass(object): pass def f1(self): print self a = MyClass() AddMethod(a, f1) a.f1() # prints object a You can also create a bound method and manually bind it to the instance. This is easier import types a.f2 = types.MethodType(f1, a) a.f2() # prints object a These may work for most uses, but both have a problem that happens if you need to make a copy of the instance. When you copy it, the copies 'f1' will still call the function but using the old object a.f1() # prints object a b = copy.copy(a) b.f1() # still prints a Brian Vanderburg II From rt8396 at gmail.com Thu Jan 29 23:56:03 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 20:56:03 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <7e237bf2-b21f-439e-a8c8-0a1366c6c819@o36g2000yqh.googlegroups.com> On Jan 29, 5:51?pm, anders wrote: > if file.findInFile("LF01"): > Is there any library like this ?? > Best Regards > Anders Yea, it's called a for loop! for line in file: if "string" in line: do_this() From BrianVanderburg2 at aim.com Thu Jan 29 23:58:41 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 29 Jan 2009 23:58:41 -0500 Subject: libsudo ? In-Reply-To: <1233290565.3742.1.camel@localhost.localdomain> References: <1233290565.3742.1.camel@localhost.localdomain> Message-ID: <49828901.1060706@aim.com> linuxguy123 at gmail.com wrote: > Does anyone know where I would find libsudo ? > http://sourceforge.net/projects/libsudo > If you had the choice of using pexpect or libsudo, which would you use ? > libsudo does all the work for you of executing sudo, checking for the expected responses and all. If all you need it for is to use sudo from Python I suspect it would be easier than pexpect. It is a C library however, so after being compiled and installed, you will need to use ctypes to use it. It is very simple, as the only function to deal with is: int runAs( char* command, char* password, char* user, int invalidate ); > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > Brian Vanderburg II From n.kottiyath at gmail.com Fri Jan 30 00:23:48 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 29 Jan 2009 21:23:48 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: <400ebbae-a923-438a-85af-8ff451b77f10@t39g2000prh.googlegroups.com> On Jan 30, 8:31?am, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > > On Jan 30, 12:29?am, Eric Kang wrote: > >> In python, I set: > > >> x=1 > >> y=3 > > >> z = x > >> x = y > >> y = z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory required to exchange two 32-bit > >> quantities? What would be the pseudocode that achieves this minimum? > > > How about: > > def transpose(x, y): > > ? ? print x, y, 'becomes: ', > > ? ? x = x + y > > ? ? y = x - y > > ? ? x = x - y > > ? ? print x, ' ', y > > > transpose(1,3) > > transpose (9,8) > > I'm not sure what the point of that function is. It doesn't actually swap > its arguments: > > >>> x = 23 > >>> y = 42 > >>> transpose(x, y) > > 23 42 becomes: ?42 ? 23>>> x > 23 > >>> y > > 42 > > And it certainly doesn't save memory, as the original poster asked: > > >>> import dis > >>> swap = compile('x, y = y, x', '', 'single') > >>> dis.dis(swap) > > ? 1 ? ? ? ? ? 0 LOAD_NAME ? ? ? ? ? ? ? ?0 (y) > ? ? ? ? ? ? ? 3 LOAD_NAME ? ? ? ? ? ? ? ?1 (x) > ? ? ? ? ? ? ? 6 ROT_TWO > ? ? ? ? ? ? ? 7 STORE_NAME ? ? ? ? ? ? ? 1 (x) > ? ? ? ? ? ? ?10 STORE_NAME ? ? ? ? ? ? ? 0 (y) > ? ? ? ? ? ? ?13 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?16 RETURN_VALUE > > >>> dis.dis(transpose) > > ? 2 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ? 3 PRINT_ITEM > ? ? ? ? ? ? ? 4 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ? 7 PRINT_ITEM > ? ? ? ? ? ? ? 8 LOAD_CONST ? ? ? ? ? ? ? 1 ('becomes: ') > ? ? ? ? ? ? ?11 PRINT_ITEM > > ? 3 ? ? ? ? ?12 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?15 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?18 BINARY_ADD > ? ? ? ? ? ? ?19 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 4 ? ? ? ? ?22 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?25 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?28 BINARY_SUBTRACT > ? ? ? ? ? ? ?29 STORE_FAST ? ? ? ? ? ? ? 1 (y) > > ? 5 ? ? ? ? ?32 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?35 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?38 BINARY_SUBTRACT > ? ? ? ? ? ? ?39 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 6 ? ? ? ? ?42 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?45 PRINT_ITEM > ? ? ? ? ? ? ?46 LOAD_CONST ? ? ? ? ? ? ? 2 (' ') > ? ? ? ? ? ? ?49 PRINT_ITEM > ? ? ? ? ? ? ?50 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?53 PRINT_ITEM > ? ? ? ? ? ? ?54 PRINT_NEWLINE > ? ? ? ? ? ? ?55 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?58 RETURN_VALUE > > The compiled code of the transpose function *alone* (not including all > the other associated parts) takes 59 bytes, or 472 bits. > > >>> len(transpose.func_code.co_code) > > 59 > > Even if it worked, that's hardly using less memory than a direct swap. > > -- > Steven Is it possible to swap two floats without a variable? From darcy at druid.net Fri Jan 30 00:24:47 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 00:24:47 -0500 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <20090130002447.e6c59998.darcy@druid.net> On Thu, 29 Jan 2009 16:06:09 -0800 "todpose at hotmail.com" wrote: > How can you make python round numbers to the nearest 5: > > Example: > > 3 => 0 > 8 => 10 > 23.2 => 20 > 36 => 35 > 51.5 => 50 That appears to be rounding to nearest 10, not 5. Clarify your requirements first. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From grante at visi.com Fri Jan 30 00:29:44 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 29 Jan 2009 23:29:44 -0600 Subject: Swapping values of two variables References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: On 2009-01-30, MRAB wrote: >> What is the minimum amount of extra memory required to exchange two >> 32-bit quantities? What would be the pseudocode that achieves this >> minimum? > > x ^= y > y ^= x > x ^= y > > This is really only of use when working in assembly language. And rarely then. ;) [Readability counts everywhere.] -- Grant From rt8396 at gmail.com Fri Jan 30 00:38:12 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 21:38:12 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> On Jan 29, 6:21?pm, r wrote: > Also if anyone dares to mention that Python is a great language or > better in this reguard or that, they get jumped and beat to death by > their "so-called" brothers. This observation leads me to two scientific and common sense synopsis. Either nobody here gives a rats pa'toote about Python, and/or they are all just a bunch of gutless worms too afraid to stand up to the 10 or so Perl/Ruby leeches who's infestation slowly drains the life-blood out of the Python Community, keeping it too weak to fight back. From wuwei23 at gmail.com Fri Jan 30 00:38:43 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 21:38:43 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <7e237bf2-b21f-439e-a8c8-0a1366c6c819@o36g2000yqh.googlegroups.com> Message-ID: On Jan 30, 2:56?pm, r wrote: > On Jan 29, 5:51?pm, anders wrote: > > > if file.findInFile("LF01"): > > Is there any library like this ?? > > Best Regards > > Anders > > Yea, it's called a for loop! > > for line in file: > ? ? if "string" in line: > ? ? ? ? do_this() Which is what the OP is already doing: > (Today i step line for line and check) anders, you might have more luck with one of the text search libraries out there: PyLucene (although this makes Java a dependency): http://lucene.apache.org/pylucene/ Nucular: http://nucular.sourceforge.net/ mxTextTools: http://www.egenix.com/products/python/mxBase/mxTextTools/ From semanticist at gmail.com Fri Jan 30 00:43:27 2009 From: semanticist at gmail.com (Miles) Date: Fri, 30 Jan 2009 00:43:27 -0500 Subject: Rounding to the nearest 5 In-Reply-To: <4982493A.90404@tim.thechases.com> References: <4982493A.90404@tim.thechases.com> Message-ID: On Thu, Jan 29, 2009 at 7:26 PM, Tim Chase wrote: >> How can you make python round numbers to the nearest 5: >> Example: >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > I'm not sure *any* rounding system will give those results. def bogoround(n): n1 = n / 5.0 return int(round(n1) if n1 % 2 > 1 else n1) * 5 best-I-could-do-ly y'rs, -Miles From justin.mailinglists at gmail.com Fri Jan 30 00:51:17 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 29 Jan 2009 21:51:17 -0800 (PST) Subject: Module/Library That is Able To Use Cookies + Proxies? References: <315e5bad-2c3f-4e69-b810-b9535266dfc9@f3g2000vbf.googlegroups.com> Message-ID: <1c7e7278-a7e0-402a-8b75-a7266314c227@r10g2000prf.googlegroups.com> On Jan 30, 12:06?pm, blackcapsoftw... at gmail.com wrote: > I would like to do is be able to log into a site that uses cookies to > store information about the user when logging in. This works fine and > dandy with ClientCookie. Now, I want to be able to do so with a proxy, urllib2 http://docs.python.org/library/urllib2.html#module-urllib2 class urllib2.HTTPCookieProcessor([cookiejar]) A class to handle HTTP Cookies. class urllib2.ProxyHandler([proxies])? Cause requests to go through a proxy. If proxies is given, it must be a dictionary mapping protocol names to URLs of proxies. The default is to read the list of proxies from the environment variables . To disable autodetected proxy pass an empty dictionary. From prologic at shortcircuit.net.au Fri Jan 30 00:53:12 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 30 Jan 2009 15:53:12 +1000 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Fri, Jan 30, 2009 at 3:38 PM, r wrote: > This observation leads me to two scientific and common sense synopsis. > Either nobody here gives a rats pa'toote about Python, and/or they are > all just a bunch of gutless worms too afraid to stand up to the 10 or > so Perl/Ruby leeches who's infestation slowly drains the life-blood > out of the Python Community, keeping it too weak to fight back. > I for one am not e member of either the Perl or Ruby fan club - and I don't think I will ever be :) However I"m not going to go and start bagging those languages :) I prefer Python! I think you'll find a 3rd scenario: Python developers (those that develop Python) and Python programmers (those that use Python) just don't really care about politics, protest and all the rubbish that goes on in this list :) cheers James From hungvn94 at gmail.com Fri Jan 30 00:56:13 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 21:56:13 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From hungvn94 at gmail.com Fri Jan 30 00:56:39 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 21:56:39 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <34545a61-1b00-4c15-87fd-5dc7103dea24@p2g2000prn.googlegroups.com> On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From hungvn94 at gmail.com Fri Jan 30 01:00:14 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Thu, 29 Jan 2009 22:00:14 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <3322b9e0-af59-4967-aac4-72b5750f87d4@z6g2000pre.googlegroups.com> On Jan 30, 4:19?am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. ?OO defines > the internals of a language more than a particular programming paradigm. > ?Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. ?It's just that you're not forced to place all > your code in class definitions. ?You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. ?Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. ?In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. ?For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. ?You can't manipulate them by standard means as you > can in Smalltalk and Python. ?In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. ?Java also has > very strange ways of doing singleton patterns. ?You have to wrap > singletons in class and define them as "static." ?I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. ?In effect a module > object is a singleton. ?It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. ?Everything in python is an object. > ?The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' ?You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. ?As you can see, all the operators > that can be performed with a number object are defined. ?This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung From wuwei23 at gmail.com Fri Jan 30 01:09:10 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 22:09:10 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <3322b9e0-af59-4967-aac4-72b5750f87d4@z6g2000pre.googlegroups.com> Message-ID: On Jan 30, 4:00?pm, Hung Vo wrote: > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Well, it has the same _concepts_, but definitely not the same practices/implementations. As they say, Python is not Java :) From apt.shansen at gmail.com Fri Jan 30 01:14:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 29 Jan 2009 22:14:55 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <7a9c25c20901292214n369c915ev1b4cdbc62fea19b3@mail.gmail.com> > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Python does not enforce Encapsulation; but convention is extremely successful here although there's some really loud people in this newsgroup who state otherwise. Python programmers tend to be very well-behaved in this regard and they do not poke into private API's -- unless /they have to/. That's important: /have/ to. If they were not allowed, they'd be unable to use that code. Internally in corporate software this is a complete non-issue: and in any major project it should be a non-issue too. If you follow basic convention (private is preceded by _) then it is extremely clear if you're obeying encapsulation and if someone in your project breaks it without a good reason-- refuse the addition. Python is *extremely* polymorphic. Python does not have any built-in "interface" capability, per se, but there are add-on libraries that can be used to provide interface functionality if you are doing a framework or large program that needs it. Then again "Interface" is a bit questionable as an "OOP Concept"; its used in some implementations of an OOP language, and not used in anothers-- and what it means in one can differ from what it means in another. There's all kinds of other "concepts" of OOP that various people describe, and generally you can do them all in Python. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jan 30 01:15:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 22:15:59 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? If you're looking for a benchmark for object-orientedness, Smalltalk, not Java, is the canonical language to compare against. Anyway, to your three-pronged question: - Yes, Python supports polymorphism. I find it hard to think of an example of an OO language that doesn't. - Python does not support interfaces in the Java sense (although there are a few third-party libraries that add such support); neither does Smalltalk. Instead, both Smalltalk and Python use duck-typing to similar effect. See http://en.wikipedia.org/wiki/Duck_typing - Python supports encapsulation. Prefixing an attribute/method with an underscore indicates that other programmers should treat it as 'private'. However, unlike B&D languages, Python itself does nothing to enforce this privacy, leaving it instead to the good judgement of the programmer, under the philosophy that "We're all consenting adults here". This allows people to meddle with internals, at their own risk, if it ends up being absolutely necessary. The enforcement point is largely academic anyway, as most languages' reflection APIs let you poke at ostensibly "private" things. Cheers, Chris P.S. You appear to have posted the same message 3 times(!), which is a bit annoying for readers. -- Follow the path of the Iguana... http://rebertia.com From schickb at gmail.com Fri Jan 30 01:20:14 2009 From: schickb at gmail.com (schickb) Date: Thu, 29 Jan 2009 22:20:14 -0800 (PST) Subject: new.instancemethod questions References: <277d3cf1-cca7-48e7-994d-33f4ded5cecb@z6g2000pre.googlegroups.com> Message-ID: <99775666-1264-4908-bc6a-37150543a5b3@y23g2000pre.googlegroups.com> On Jan 29, 8:51?pm, Brian Allen Vanderburg II wrote: > You can also create a bound method and manually bind it to the > instance. ?This is easier > > import types > a.f2 = types.MethodType(f1, a) > > a.f2() # prints object a Ah thanks, that is what I was looking for. I missed that because following types.MethodType in the docs is: types.UnboundMethodType An alternate name for MethodType Which made me think it was a type for UnboundMethods (aka functions). This: >>> help(types.UnboundMethodType) clears it up for me, but the docs are rather confusing. > These may work for most uses, but both have a problem that happens if > you need to make a copy of the instance. ?When you copy it, the copies > 'f1' will still call the function but using the old object > > a.f1() # prints object a > b = copy.copy(a) > b.f1() # still prints a > Ugh, that is a problem. I guess that means pickling won't work either.... Nope, "TypeError: can't pickle instancemethod objects". So does these mean there is no way to create a method on an instance at runtime that behaves just like a method that originated from the instance's class? -Brad From steven at REMOVE.THIS.cybersource.com.au Fri Jan 30 01:23:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 06:23:17 GMT Subject: Rounding to the nearest 5 References: Message-ID: On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > On Thu, 29 Jan 2009 16:06:09 -0800 > "todpose at hotmail.com" wrote: >> How can you make python round numbers to the nearest 5: >> >> Example: >> >> 3 => 0 >> 8 => 10 >> 23.2 => 20 >> 36 => 35 >> 51.5 => 50 > > That appears to be rounding to nearest 10, not 5. Clarify your > requirements first. Look again. 36 => 35. -- Steven From rt8396 at gmail.com Fri Jan 30 01:24:09 2009 From: rt8396 at gmail.com (r) Date: Thu, 29 Jan 2009 22:24:09 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 29, 11:53?pm, James Mills wrote: > On Fri, Jan 30, 2009 at 3:38 PM, r wrote: > > This observation leads me to two scientific and common sense synopsis. > > Either nobody here gives a rats pa'toote about Python, and/or they are > > all just a bunch of gutless worms too afraid to stand up to the 10 or > > so Perl/Ruby leeches who's infestation slowly drains the life-blood > > out of the Python Community, keeping it too weak to fight back. > > > > I for one am not e member of either the Perl or Ruby > fan club - and I don't think I will ever be :) However I"m not > going to go and start bagging those languages :) I prefer Python! > > I think you'll find a 3rd scenario: > > Python developers (those that develop Python) > and Python programmers (those that use Python) > just don't really care about politics, protest and > all the rubbish that goes on in this list :) > > cheers > James I totally agree James. I not saying anybody should just go around bashing this or that language, but i have seen many a ruffled feather at the mere mention of Python's greatness. I could understand if someone went over to the Perl group and started parroting off "Python rules!, Perl sucks!". This should be condemned. But i have also seen at this group very viscous attacks on people who just simply think Python is a good language and want to tell their Python friends how happy they are -- myself included. People would call a happy user of Python a fanboy or a Python zealot. This blows me away in the context of this group. check out this thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d15ed72979ba20f7/6195c98209dcc852?hl=en&lnk=gst&q=python+is+great#6195c98209dcc852 Here a happy python user shared his thoughts on the Python language. He compared Python as "more readable" than Perl and by god he is right about that, no sane person can honestly deny this fact. But like always some angry responses and warnings followed that this person should not criticize Perl, and veil threats were cast. This is the madness i refer too. From wuwei23 at gmail.com Fri Jan 30 01:25:39 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Jan 2009 22:25:39 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> On Jan 30, 4:15?pm, Chris Rebert wrote: > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing I haven't yet had reason to use them, but do Abstract Base Classes (introduced in 2.6/3.0) go some way to provide more defined interface support for Python? My assumption was that was what they'd generally be used for... From tony.clarke5 at googlemail.com Fri Jan 30 01:28:42 2009 From: tony.clarke5 at googlemail.com (tony.clarke5 at googlemail.com) Date: Thu, 29 Jan 2009 22:28:42 -0800 (PST) Subject: Swapping values of two variables References: Message-ID: <83ecd69d-d120-4a78-aed4-3fb9d87b9b60@p36g2000prp.googlegroups.com> On Jan 30, 3:31?am, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote: > > On Jan 30, 12:29?am, Eric Kang wrote: > >> In python, I set: > > >> x=1 > >> y=3 > > >> z = x > >> x = y > >> y = z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory required to exchange two 32-bit > >> quantities? What would be the pseudocode that achieves this minimum? > > > How about: > > def transpose(x, y): > > ? ? print x, y, 'becomes: ', > > ? ? x = x + y > > ? ? y = x - y > > ? ? x = x - y > > ? ? print x, ' ', y > > > transpose(1,3) > > transpose (9,8) > > I'm not sure what the point of that function is. It doesn't actually swap > its arguments: > > >>> x = 23 > >>> y = 42 > >>> transpose(x, y) > > 23 42 becomes: ?42 ? 23>>> x > 23 > >>> y > > 42 > > And it certainly doesn't save memory, as the original poster asked: > > >>> import dis > >>> swap = compile('x, y = y, x', '', 'single') > >>> dis.dis(swap) > > ? 1 ? ? ? ? ? 0 LOAD_NAME ? ? ? ? ? ? ? ?0 (y) > ? ? ? ? ? ? ? 3 LOAD_NAME ? ? ? ? ? ? ? ?1 (x) > ? ? ? ? ? ? ? 6 ROT_TWO > ? ? ? ? ? ? ? 7 STORE_NAME ? ? ? ? ? ? ? 1 (x) > ? ? ? ? ? ? ?10 STORE_NAME ? ? ? ? ? ? ? 0 (y) > ? ? ? ? ? ? ?13 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?16 RETURN_VALUE > > >>> dis.dis(transpose) > > ? 2 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ? 3 PRINT_ITEM > ? ? ? ? ? ? ? 4 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ? 7 PRINT_ITEM > ? ? ? ? ? ? ? 8 LOAD_CONST ? ? ? ? ? ? ? 1 ('becomes: ') > ? ? ? ? ? ? ?11 PRINT_ITEM > > ? 3 ? ? ? ? ?12 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?15 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?18 BINARY_ADD > ? ? ? ? ? ? ?19 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 4 ? ? ? ? ?22 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?25 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?28 BINARY_SUBTRACT > ? ? ? ? ? ? ?29 STORE_FAST ? ? ? ? ? ? ? 1 (y) > > ? 5 ? ? ? ? ?32 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?35 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?38 BINARY_SUBTRACT > ? ? ? ? ? ? ?39 STORE_FAST ? ? ? ? ? ? ? 0 (x) > > ? 6 ? ? ? ? ?42 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?45 PRINT_ITEM > ? ? ? ? ? ? ?46 LOAD_CONST ? ? ? ? ? ? ? 2 (' ') > ? ? ? ? ? ? ?49 PRINT_ITEM > ? ? ? ? ? ? ?50 LOAD_FAST ? ? ? ? ? ? ? ?1 (y) > ? ? ? ? ? ? ?53 PRINT_ITEM > ? ? ? ? ? ? ?54 PRINT_NEWLINE > ? ? ? ? ? ? ?55 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?58 RETURN_VALUE > > The compiled code of the transpose function *alone* (not including all > the other associated parts) takes 59 bytes, or 472 bits. > > >>> len(transpose.func_code.co_code) > > 59 > > Even if it worked, that's hardly using less memory than a direct swap. > > -- > Steven Should have been more explicit about that: the values are swapped within the namespace of the function, the function is just for demonstration of the process. WIthout the function, this is the result: Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = -10 >>> y = 4 >>> x = x + y >>> y = x - y >>> x = x - y >>> x 4 >>> >>> y -10 >>> Need to think about swapping floats though. Tony From steven at REMOVE.THIS.cybersource.com.au Fri Jan 30 01:32:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jan 2009 06:32:37 GMT Subject: Swapping values of two variables References: <400ebbae-a923-438a-85af-8ff451b77f10@t39g2000prh.googlegroups.com> Message-ID: On Thu, 29 Jan 2009 21:23:48 -0800, Kottiyath wrote: > Is it possible to swap two floats without a variable? In Python? Sure. f = 1.23 g = 2.87 f, g = g, f This idiom is independent of the types of the objects: x = "hello world" y = [1, 2.0, None, "xyz", {}] x, y = y, x In other languages? Hard to say. You *might* be able to use the XOR trick on floats, if you can access a float as a set of raw bytes. Same for strings, if they are the same length. Assuming that the floats are of similar size, not NaNs or INFs, not subject to overflow or underflow, and not subject to rounding error, you can do this trick: >>> f = 1.23 >>> g = 2.87 >>> f, g (1.23, 2.8700000000000001) >>> >>> f = f + g >>> g = f - g >>> f = f - g >>> f, g (2.8700000000000001, 1.2299999999999995) But notice the round-off error in g. It gets worse if your values are of radically different sizes: >>> f = 123.4 >>> g = 1.2e35 >>> f, g (123.40000000000001, 1.2000000000000001e+35) >>> f = f + g >>> g = f - g >>> f = f - g >>> f, g (1.2000000000000001e+35, 0.0) This really is a trick, not something you should be doing in production code. -- Steven From clp2 at rebertia.com Fri Jan 30 01:34:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 29 Jan 2009 22:34:52 -0800 Subject: is python Object oriented?? In-Reply-To: <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <09695d6c-042d-4954-9251-7418205db863@a12g2000pro.googlegroups.com> Message-ID: <50697b2c0901292234v71579f6cm4007471e1ca79799@mail.gmail.com> On Thu, Jan 29, 2009 at 10:25 PM, alex23 wrote: > On Jan 30, 4:15 pm, Chris Rebert wrote: >> - Python does not support interfaces in the Java sense (although there >> are a few third-party libraries that add such support); neither does >> Smalltalk. Instead, both Smalltalk and Python use duck-typing to >> similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing > > I haven't yet had reason to use them, but do Abstract Base Classes > (introduced in 2.6/3.0) go some way to provide more defined interface > support for Python? My assumption was that was what they'd generally > be used for... Ah, excellent point. I neglected to take ABCs into account. Smalltalk did have those as well. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ochichinyezaboombwa at yahoo.com Fri Jan 30 02:43:33 2009 From: ochichinyezaboombwa at yahoo.com (Mabooka-Mabooka Mbe-Mbe) Date: Thu, 29 Jan 2009 23:43:33 -0800 (PST) Subject: 'Address already in use' ... with TCPServer Message-ID: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Hi all, I bet everybody knows exactly what I am about to ask about: ''' A server serves for a while, then drops on its knees, tries to restart, but... the port is busy, the TCP says "Address already in use". ''' And, I think I know the answer: setsockopt(REUSEADDR)... The problem is: I am trying to use a very-high level far-away-from-socket class ("TCPServer"); or to be 100% honest, - an even higher-level async version of it (like in http://www.python.org/doc/2.6/library/socketserver.html?highlight=tcpserver#asynchronous-mixins). What I came up with so far is this: >>> from SocketServer import * >>> s = TCPServer( ('', 32123), None) >>> dir(s) ['RequestHandlerClass', '__doc__', '__init__', '__module__', 'address_family', 'allow_reuse_address', 'close_request', 'fileno', 'finish_request', 'get_request', 'handle_error', 'handle_request', 'process_request', 'request_queue_size', 'serve_forever', 'server_activate', 'server_address', 'server_bind', 'server_close', 'socket', 'socket_type', 'verify_request'] Aha! My bet is (was): >>> s.allow_reuse_address=1 should do the trick. But it doesn't. (:___. The question is: how to set up TCPServer correctly to reuse the port right away. Please give a hand. I acknowledge that I am trying to hack it rather then looking at all the web 1st: sorry if I am spamming this list while good documentation exists. But does it? :-#). -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 30 03:26:20 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 00:26:20 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 30, 5:24?pm, r wrote: [snip] > This blows me away in the context of this group. check out this > thread:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Here a happy python user shared his thoughts on the Python language. > He compared Python as "more readable" than Perl and by god he is right > about that, no sane person can honestly deny this fact. But like > always some angry responses and warnings followed that this person > should not criticize Perl, and veil threats were cast. > > This is the madness i refer too. Clicking on that link leads me to a 14-message thread in which the meat relates to Joe Stroud's problems with py2app, and there is only one reference to perl: Joe says: """No, I'm *using* py2app. I've been trying to use it for a couple of weeks now, with the generous help of such people as Robin Dunn, and I still don't have it quite working pro*perl*y. """ This doesn't appear to match the description. Perhaps the PSU has subverted my comp)(*&^%$#@! NO CARRIER From rt8396 at gmail.com Fri Jan 30 03:38:34 2009 From: rt8396 at gmail.com (r) Date: Fri, 30 Jan 2009 00:38:34 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: On Jan 30, 2:26?am, John Machin wrote: [snip] > This doesn't appear to match the description. Perhaps the PSU has > subverted my comp)(*&^%$#@! > NO CARRIER Oops -- Good catch John, Even perfect people like myself make mistakes :). Here is the aforementioned thread where a Python user was chastised for daring to say Python has a clearer syntax than Perl thereby easing maintainability: OH NO! *big hand wave* http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a These Perl mongers have no business doing their mongling here, go to c.l.Perl! From mail at timgolden.me.uk Fri Jan 30 03:39:43 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 30 Jan 2009 08:39:43 +0000 Subject: parsing text from a file In-Reply-To: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: <4982BCCF.9090408@timgolden.me.uk> Wes James wrote: > If I read a windows registry file with a line like this: > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > Multicast|Edge=FALSE|" Watch out. .reg files exported from the registry are typically in UTF16. Notepad and other editors will recognise this and display what you see above, but if you were to, say, do this: print repr (open ("blah.reg").read ()) You might see a different picture. If that's the case, you'll have to use the codecs module or decode the string you read. TJG From __peter__ at web.de Fri Jan 30 03:42:22 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jan 2009 09:42:22 +0100 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: Gabriel Genellina wrote: > But a loop doesn't define a new scope (only "def" and "class" used to > define one; now generator expressions do too). The new scope is not the > issue, but the fact that the right and left parts of a gen.expr. are > evaluated at different times. This wasn't obvious to me -- and still > isn't. If you rewrite the generator expression as a generator function you > don't get the same behaviour: > > print "genexpr" > A = [1,2,3] > B = 1 > g = (x+B for x in A) > A = [4,5,6] > B = 10 > print list(g) > # output: [11,12,13] > # A is evaluated at the time g is *defined* > # B is evaluated at the time g is *iterated* > print "genfunc" I think it helps understanding if you translate the above to >>> A = [1,2,3] >>> B = 1 >>> def f(a): ... for x in a: ... yield x+B ... >>> g = f(A) >>> A = [4,5,6] >>> B = 10 >>> print list(g) [11, 12, 13] This is not altogether unintuitive, but I think I would prefer if it worked like >>> A = [1,2,3] >>> B = 1 >>> def f(a, b): ... for x in a: ... yield x+b ... >>> g = f(A, B) >>> A = [4,5,6] >>> B = 10 >>> list(g) [2, 3, 4] i. e. every name were bound early. Of course this wouldn't help with locals() which would still be called in different scopes. Peter From deets at nospam.web.de Fri Jan 30 03:49:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 30 Jan 2009 09:49:46 +0100 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <6uft9aFf9kgbU1@mid.uni-berlin.de> anders schrieb: > Hi! > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO > > So a read all fils with dirchached > > Then a loop thru all files each files is read with readLines() and > after that scaned > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) > > What i like to find is just filenames for files with the customerdata > in, there can and often > is more than one, > > English is not my first language and i hope someone understand my > beginner question > what i am looking for is somting like > > if file.findInFile("LF01"): > ....... > > Is there any library like this ?? No. Because nobody can automagically infer whatever structure your files have. alex23 gave you a set of tools that you can use for full-text-search. However, that's not necessarily the best thing to do if things have a record-like structure. The canonical answer to this is then to use a database to hold the data, instead of flat files. So if you have any chance to do that, you should try & stuff things in there. Diez From googler.1.webmaster at spamgourmet.com Fri Jan 30 03:54:56 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 30 Jan 2009 00:54:56 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: Hi! Thanks. Well, os.py is found and all the others which don't need a library. I tested this: I execute Py_Main(...) in my app which executes the console interpreter and i tried to execute "import socket" which works. So Py_Main has something what my created PyRun_SimpleString doesn't have. Maybe the environment variables? Something has to be called in Py_Main which I should call, too. bye.. From mail at microcorp.co.za Fri Jan 30 04:08:29 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 30 Jan 2009 11:08:29 +0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: <01ca01c982bf$d609ca20$0d00a8c0@hendrik> "Gabriel Genellina" wrote: Of course this is clearly stated in the Language Reference "Variables used in the generator expression are evaluated lazily in a separate scope when the next() method is called for the generator object (in the same fashion as for normal generators). However, the in expression of the leftmost for clause is immediately evaluated in the current scope..." -- but this behaviour is still surprising and not obvious to me. ("not obvious" means that things could have been different, choosing this was a design decision). I am not so sure that it could have been done differently - I see it something like this: (going back to almost your original example, and reversing the position of globals and locals to make it shorter) >>> def foo(things): for thing in things: yield thing() #it is obvious this is in the local scope of foo >>> boo = foo([locals,globals]) >>> boo.next() {'thing': , 'things': [, ]} >>> and so it is, when you feed it the locals function Your other example would have been something like this: >>> def bar(things): for thing in things: yield thing # this just returns it unchanged >>> baz = bar([locals(),globals()]) # here we are still in the outer scope >>> baz.next() {'bar': , '__builtins__': , 'baz': , '__file__': 'E:\\Python24\\Lib\\idlelib\\idle.pyw', 'idlelib': , 'boo': , '__name__': '__main__', 'foo': , '__doc__': None} >>> and we get the top level locals back, as expected. Now I don't think that you could really do it differently - the right hand side of the generator expression is exactly like my passed argument "things", in all cases as far as I can see, and this means that the right hand side is evaluated when it is "passed", and the left hand side is whatever is done in the "for thing in things:" loop. All the generator expression does is that it saves you the trouble of defining the function - it kind of does it for you, and calls it, and returns the generator object, and throws the function away, all in one hit. (this is not necessarily the real mechanism, but the effect is exactly as if it were) I can't think of a way to do it differently - you have to make the "things" you want to iterate over, before you can do the iteration, and this is the cause of the timing difference and the outer level evaluation of the "passed" argument, and the different scope comes from the scope of the "ghost" function. Or is this view too simple? - Hendrik From gagsl-py2 at yahoo.com.ar Fri Jan 30 04:16:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 07:16:01 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe escribi?: > setsockopt(REUSEADDR)... > > What I came up with so far is this: >>>> from SocketServer import * >>>> s = TCPServer( ('', 32123), None) >>>> dir(s) > ['RequestHandlerClass', '__doc__', '__init__', '__module__', > 'address_family', 'allow_reuse_address', ... ] > > Aha! My bet is (was): >>>> s.allow_reuse_address=1 > should do the trick. It's too late then; bind() has already been called. The easiest way is to define your own derived class: import SocketServer class TCPServer(SocketServer.TCPServer): allow_reuse_address = True s = TCPServer(...) > I acknowledge that I am trying to hack it rather then looking at all the > web 1st: > sorry if I am spamming this list while good documentation exists. But > does it? Sure: http://docs.python.org/library/socketserver.html#SocketServer.allow_reuse_address The server classes support the following class variables: SocketServer.allow_reuse_address Whether the server will allow the reuse of an address. This defaults to False, and can be set in subclasses to change the policy. Reading the source may help too :) -- Gabriel Genellina From sjmachin at lexicon.net Fri Jan 30 04:21:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 01:21:25 -0800 (PST) Subject: parsing text from a file References: <533df7fa0901291354h4a25b48fw6a07e45d62ac35b2@mail.gmail.com> Message-ID: On Jan 30, 7:39?pm, Tim Golden wrote: > Wes James wrote: > > If I read a windows registry file with a line like this: > > > "{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program > > Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted > > Multicast|Edge=FALSE|" > > Watch out. .reg files exported from the registry are typically > in UTF16. Notepad and other editors will recognise this and > display what you see above, but if you were to, say, do this: > > print repr (open ("blah.reg").read ()) > > You might see a different picture. If that's the case, you'll > have to use the codecs module or decode the string you read. > Ha! That's why it appeared to print "LAND" instead of "LANDesk" -- it found and was printing "L\0A\0N\0D". From gagsl-py2 at yahoo.com.ar Fri Jan 30 05:09:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 08:09:21 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 06:54:56 -0200, escribi?: > Thanks. Well, os.py is found and all the others which don't need a > library. > I tested this: > > I execute Py_Main(...) in my app which executes the console > interpreter and > i tried to execute "import socket" which works. > > So Py_Main has something what my created PyRun_SimpleString doesn't > have. > Maybe the environment variables? Something has to be called in Py_Main > which I should call, too. (I assume you moved the executable to another directory - in your first post, your app was in some place, and python.exe/python25.dll in another) Py_Main, apart from processing arguments and some stuff related to the interactive mode, doesn't do much; a stripped down version would be: Py_SetProgramName(argv[0]); Py_Initialize(); PySys_SetArgv(...); PyRun_AnyFileExFlags(fd, filename, ...) WaitForThreadShutdown(); Py_Finalize(); -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Fri Jan 30 05:50:45 2009 From: googler.1.webmaster at spamgourmet.com (googler.1.webmaster at spamgourmet.com) Date: Fri, 30 Jan 2009 02:50:45 -0800 (PST) Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> Message-ID: <321ac876-bc29-418a-81c7-7ef5e0f23478@u18g2000pro.googlegroups.com> Hi! Okay, thats just the question. I did that what you wrote but it doesn't really works. What is, if Py_SetProgramName() gets a NULL Pointer, if argv[0] is empty? Well, the problem is, in my opinion that os.environ returns some paths in python.exe and in my embedded interpreter if I call os.environ in Py_Main(...) When I call it in my PyRun_SimpleString(...) it returns nothing. Hm.. thats really strange. From ove.svensson at jeppesen.com Fri Jan 30 06:00:31 2009 From: ove.svensson at jeppesen.com (Ove Svensson) Date: Fri, 30 Jan 2009 12:00:31 +0100 Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: <9gwscdm52o.fsf@overberg.jeppesensystems.com> Alejandro writes: > Hi: > > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. > > In each of the threads I have > > def run(self): > pid = os.getpid() > logger.critical('process ID: %s', pid) > > However, the reported PID is the father number, not the PID of the new > thread. Is there a way to get the PID of the thread? Pid is a process identifier. Threads are not processes. All your threads execute within the context if a single process, hence they should have the same pid. Threads may have a thread id but it is not the same as the pid. From python.list at tim.thechases.com Fri Jan 30 06:38:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 05:38:49 -0600 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <4982E6C9.8090405@tim.thechases.com> Steven D'Aprano wrote: > On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote: > >>> How can you make python round numbers to the nearest 5: >>> >>> Example: >>> >>> 3 => 0 >>> 8 => 10 >>> 23.2 => 20 >>> 36 => 35 >>> 51.5 => 50 >> I'm not sure *any* rounding system will give those results. > > Round towards zero. 8 => 10 ? One can round down with def round_down_to_n(x, ROUNDER = 5): return (x // ROUNDER) * ROUNDER but 8=>10 still fails to pass because 3 rounded down and 3+5 rounds up. So I call bogus data, or fall back to Miles' bogoround() function :) -tkc From a at nospam.org Fri Jan 30 06:50:08 2009 From: a at nospam.org (Armin) Date: Fri, 30 Jan 2009 12:50:08 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: > >> I have frozen a running application which is using SQLite with py2exe. >> When I start the exe file I see in the log file of the exe: >> Traceback (most recent call last): >> File "dpconf.py", line 666, in ? >> File "dpconf.py", line 251, in __init__ >> File "sqlite\main.pyc", line 255, in execute >> _sqlite.DatabaseError: no such table: genslaveopt >> >> The table exist in the database file ... no problem with the plain >> python version. > > Did you solve this problem? As you posted 4 related messages and the > last one might imply a solution to this first one... Yes, the distutil option 'data_files' failed to copy the database files to the dist directory. All dbopen calls have created empty db files ... --Armin PS: any comments on the data_files issue ?? > From nanoeyes at gmail.com Fri Jan 30 06:53:00 2009 From: nanoeyes at gmail.com (nanoeyes at gmail.com) Date: Fri, 30 Jan 2009 03:53:00 -0800 (PST) Subject: Noob question Message-ID: Hello? I'm currently installed Ubuntu 8.10. I'm not a Linux person, so I don't know a lot about it. The reason I installed Ubuntu is just for EMAN (http://blake.bcm.tmc.edu/eman/). EMAN 1.8 software requires Python 2.4 not 2.5 which comes with Ubuntu 8.10. I installed Python 2.4 by typing sudo apt-get install python2.4 Still EMAN doesn't work for me. Do I have to downgrade 2.5 to 2.4 or install lower version of Ubuntu? From gnewsg at gmail.com Fri Jan 30 07:16:42 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 30 Jan 2009 04:16:42 -0800 (PST) Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: On 30 Gen, 10:16, "Gabriel Genellina" wrote: > En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? > escribi?: > > > ? setsockopt(REUSEADDR)... > > > What I came up with so far is this: > >>>> from SocketServer import * > >>>> s = TCPServer( ('', 32123), None) > >>>> dir(s) > > ['RequestHandlerClass', '__doc__', '__init__', '__module__', ? > > 'address_family', 'allow_reuse_address', ... ] > > > Aha! My bet is (was): > >>>> s.allow_reuse_address=1 > > should do the trick. > > It's too late then; bind() has already been called. The easiest way is to ? > define your own derived class: > > import SocketServer > > class TCPServer(SocketServer.TCPServer): > ? ? ?allow_reuse_address = True > > s = TCPServer(...) What's even faster is setting the class attribute right after the module import: >>> import SocketServer >>> SocketServer.TCPServer.allow_reuse_address = True --- Giampaolo http://code.google.com/p/pyftpdlib From hongyi.zhao at gmail.com Fri Jan 30 07:27:37 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 20:27:37 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. Message-ID: Hi all, Suppose I've the entries like the following in my file: ------------------ 116.52.155.237:80 ip-72-55-191-6.static.privatedns.com:3128 222.124.135.40:80 217.151.231.34:3128 202.106.121.134:80 211.161.197.182:80 hpc.be.itu.edu.tr:80 static3-117-183.worldinternetworkcorporation.com:80 ------------------ Now, I want to convert the domain name to IP by using a python script, e.g., ip-72-55-191-6.static.privatedns.com:3128 should be converted into the following form: 72.55.191.6:3128 any hints on this? From info at egenix.com Fri Jan 30 07:30:01 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 30 Jan 2009 13:30:01 +0100 Subject: ANN: eGenix pyOpenSSL Distribution 0.8.0-0.9.8j-1 Message-ID: <4982F2C9.3050600@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.8.0-0.9.8j-1 An easy to install and use repackaged distribution of the pyOpenSSL Python interface for OpenSSL - available on Windows and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.8.0-0.9.8j-1-GA.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy to use installer that includes the most recent OpenSSL library versions in pre-compiled form. pyOpenSSL is an open-source Python add-on (http://pyopenssl.sf.net/) that allows writing SSL aware networking applications as well as certificate management tools. OpenSSL is an open-source implementation of the SSL protocol (http://www.openssl.org/). For more information, please see the product page: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ NEWS This fourth release of the eGenix.com pyOpenSSL Distribution upgrades the included OpenSSL libs to version 0.9.8j, which fixes a vulnerability found in earlier OpenSSL releases of the 0.9.8 branch: CVE-2008-5077 (http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5077). We have also enabled zlib compression support in OpenSSL for both the Linux and Windows builds, so OpenSSL client/servers can now negotiate on-the-fly zlib compression for SSL connections. Binaries are available for Linux x86 and x64 as well as Windows x86 and include pyOpenSSL 0.8.0 as well as pre-compiled and tested OpenSSL 0.9.8j libraries. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 30 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From clp2 at rebertia.com Fri Jan 30 07:33:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jan 2009 04:33:55 -0800 Subject: Want to write a script to do the batch conversion from domain name to IP. In-Reply-To: References: Message-ID: <50697b2c0901300433t7c21f844o6db2e30d85a5184b@mail.gmail.com> On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao wrote: > Hi all, > > Suppose I've the entries like the following in my file: > > ------------------ > 116.52.155.237:80 > ip-72-55-191-6.static.privatedns.com:3128 > 222.124.135.40:80 > 217.151.231.34:3128 > 202.106.121.134:80 > 211.161.197.182:80 > hpc.be.itu.edu.tr:80 > static3-117-183.worldinternetworkcorporation.com:80 > ------------------ > > Now, I want to convert the domain name to IP by using a python script, > e.g., > > ip-72-55-191-6.static.privatedns.com:3128 > > should be converted into the following form: > > 72.55.191.6:3128 > > any hints on this? PyDNS might be a helpful library for writing such a script -- http://pydns.sourceforge.net/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Fri Jan 30 07:44:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 10:44:22 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:16:42 -0200, Giampaolo Rodola' escribi?: > On 30 Gen, 10:16, "Gabriel Genellina" wrote: >> En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? >> escribi?: >> >> > ? setsockopt(REUSEADDR)... >> >> >>>> s.allow_reuse_address=1 >> > should do the trick. >> >> It's too late then; bind() has already been called. The easiest way is >> to define your own derived class: >> >> import SocketServer >> >> class TCPServer(SocketServer.TCPServer): >> ? ? ?allow_reuse_address = True >> >> s = TCPServer(...) > > What's even faster is setting the class attribute right after the > module import: > >>>> import SocketServer >>>> SocketServer.TCPServer.allow_reuse_address = True ...but potentially unsafe if the application uses other servers in other places. C'mon, defining the new class can be a one-liner also, why take the risk? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Jan 30 07:44:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 10:44:22 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:16:42 -0200, Giampaolo Rodola' escribi?: > On 30 Gen, 10:16, "Gabriel Genellina" wrote: >> En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe ? >> escribi?: >> >> > ? setsockopt(REUSEADDR)... >> >> >>>> s.allow_reuse_address=1 >> > should do the trick. >> >> It's too late then; bind() has already been called. The easiest way is >> to define your own derived class: >> >> import SocketServer >> >> class TCPServer(SocketServer.TCPServer): >> ? ? ?allow_reuse_address = True >> >> s = TCPServer(...) > > What's even faster is setting the class attribute right after the > module import: > >>>> import SocketServer >>>> SocketServer.TCPServer.allow_reuse_address = True ...but potentially unsafe if the application uses other servers in other places. C'mon, defining the new class can be a one-liner also, why take the risk? -- Gabriel Genellina From bruno.42.desthuilliers at websiteburo.invalid Fri Jan 30 07:49:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 30 Jan 2009 13:49:38 +0100 Subject: Noob question In-Reply-To: References: Message-ID: <4982f762$0$5266$426a74cc@news.free.fr> nanoeyes at gmail.com a ?crit : > Hello? Hi. Ok, first, this is mostly OT here - your question should have gone to either the project's maintainer or any Ubuntu forum / mailing-list/whatever. > I'm currently installed Ubuntu 8.10. I'm not a Linux person, so I > don't know a lot about it. The reason I installed Ubuntu is just for > EMAN (http://blake.bcm.tmc.edu/eman/). EMAN 1.8 software requires > Python From the doc, it doesn't *require* Python at all: """ Some others are optional, like boost.python, Python if you need run Pyhton program in EMAN or want to program in Python with EMAN, you can turn this option off by switching ENABLE_PYTHON to off """ http://blake.bcm.tmc.edu/emanwiki/EMAN_COMPILE_UNIX > 2.4 not 2.5 which comes with Ubuntu 8.10. > > I installed Python 2.4 by typing sudo apt-get install python2.4 You'll probably need python2.4-dev too. > Still EMAN doesn't work for me. Did you try to recompile it (eventually providing the path to your python2.4 install) ? > Do I have to downgrade 2.5 to 2.4 Not sure this is an option - IIRC, Ubuntu 8.10 depends on Python 2.5. > or install lower version of Ubuntu? This would at best be a short/medium-term workaround. From reckoner at gmail.com Fri Jan 30 07:51:42 2009 From: reckoner at gmail.com (Reckoner) Date: Fri, 30 Jan 2009 04:51:42 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <83a3ca70-5c73-4341-b0a0-cc21bffa3296@p2g2000prf.googlegroups.com> <0c20bfef-6860-4fb6-afcd-2359710e49a6@v39g2000pro.googlegroups.com> <5f48cdc4-3239-415f-b6d2-b004af8c148e@t26g2000prh.googlegroups.com> <52018aea-b706-444e-a820-bd262cacf29d@y23g2000pre.googlegroups.com> Message-ID: <32b664b3-2243-4ad2-ac46-ae777cec9665@y23g2000pre.googlegroups.com> On Jan 28, 9:49?am, koranthala wrote: > On Jan 28, 10:39?pm,Reckoner wrote: > > > > > On Jan 28, 9:16 am, koranthala wrote: > > > > On Jan 28, 5:42 pm, koranthala wrote: > > > > > On Jan 28, 2:16 am,Reckoner wrote: > > > > > > I'm not sure this is possible, but I would like to have > > > > > a list of ?objects > > > > > > A=[a,b,c,d,...,z] > > > > > > where, ?in the midst of a lot of processing I might do something like, > > > > > > A[0].do_something_which_changes_the_properties() > > > > > > which alter the properties of the object 'a'. > > > > > > The trick is that I would like A to be mysteriously aware that > > > > > something about the ?object 'a' has changed so that when I revisit A, > > > > > I will know that the other items in the list need to be refreshed to > > > > > reflect the changes in A as a result of changing 'a'. > > > > > > Even better would be to automatically percolate the subsequent changes > > > > > that resulted from altering 'a' for the rest of the items in the list. > > > > > Naturally, all of these items are related in some parent-child > > > > > fashion. > > > > > > that might be a lot to ask, however. > > > > > > Any advice appreciated. > > > > > I think Python Cookbook has a recipe which deals with this. > > > > - 6.12 Checking an Instance for Any State Change. > > > > Were you able to get this? If not, let me know. I will try to type it > > > in here - (it is a big recipe, so not doing it now) > > > Actually, I have the python cookbook, but cannot find the recipe you > > mention. maybe I have an older version? > > > thanks. > > Mine is 2nd Edition. for posterity's sake, here's the recipe in question: import copy class ChangeCheckerMixin(object): containerItems = {dict: dict.iteritems, list: enumerate} immutable = False def snapshot(self): ''' create a "snapshot" of self's state -- like a shallow copy, but recursing over container types (not over general instances: instances must keep track of their own changes if needed). ''' if self.immutable: return self._snapshot = self._copy_container(self.__dict__) def makeImmutable(self): ''' the instance state can't change any more, set .immutable ''' self.immutable = True try: del self._snapshot except AttributeError: pass def _copy_container(self, container): ''' semi-shallow copy, recursing on container types only ''' new_container = copy.copy(container) for k, v in self.containerItems[type(new_container)] (new_container): if type(v) in self.containerItems: new_container[k] = self._copy_container(v) elif hasattr(v, 'snapshot'): v.snapshot( ) return new_container def isChanged(self): ''' True if self's state is changed since the last snapshot ''' if self.immutable: return False # remove snapshot from self.__dict__, put it back at the end snap = self.__dict__.pop('_snapshot', None) if snap is None: return True try: return self._checkContainer(self.__dict__, snap) finally: self._snapshot = snap def _checkContainer(self, container, snapshot): ''' return True if the container and its snapshot differ ''' if len(container) != len(snapshot): return True for k, v in self.containerItems[type(container)](container): try: ov = snapshot[k] except LookupError: return True if self._checkItem(v, ov): return True return False def _checkItem(self, newitem, olditem): ''' compare newitem and olditem. If they are containers, call self._checkContainer recursively. If they're an instance with an 'isChanged' method, delegate to that method. Otherwise, return True if the items differ. ''' if type(newitem) != type(olditem): return True if type(newitem) in self.containerItems: return self._checkContainer(newitem, olditem) if newitem is olditem: method_isChanged = getattr(newitem, 'isChanged', None) if method_isChanged is None: return False return method_isChanged( ) return newitem != olditem if __name__ == '__main__': class eg(ChangeCheckerMixin): def __init__(self, *a, **k): self.L = list(*a, **k) def __str__(self): return 'eg(%s)' % str(self.L) def __getattr__(self, a): return getattr(self.L, a) x = eg('ciao') print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o']) is changed = True # now, assume x gets saved, then...: x.snapshot( ) print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o']) is changed = False # now we change x...: x.append('x') print 'x =', x, 'is changed =', x.isChanged( ) # emits: x = eg(['c', 'i', 'a', 'o', 'x']) is changed = True From digitig at gmail.com Fri Jan 30 08:00:02 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 30 Jan 2009 13:00:02 +0000 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: 2009/1/30 Hung Vo : > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? It's not the role of the language to follow those concepts, it's the role of the programmer to follow those concepts if the programmer believes OO to be an appropriate paradigm for the task in hand. If the programmer decides that following those concepts is appropriate, Python will offer more than enough support. If the programmer decides that OO is not an appropriate paradigm but wants to follow procedural or functional concepts instead, Python will support that, too. Object orientation is not really a language property at all; it's a design approach. I've written object oriented programs in C, hand-coding the despatch tables, before anybody gave the name "object oriented" to that approach. When people talk about an object oriented language they either mean a language that allows a close mapping between an object oriented design and the actual code (Python does), or they mean a language that *requires* the code to conform to an object oriented design (Python doesn't). So the answer to "Is Python Object-Oriented" is either "yes" or "no", depending on what you're /really/ asking. -- Tim Rowe From gagsl-py2 at yahoo.com.ar Fri Jan 30 08:09:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 11:09:13 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: > Gabriel Genellina wrote: >> En Thu, 29 Jan 2009 13:05:11 -0200, Armin escribi?: >> >> Did you solve this problem? As you posted 4 related messages and the >> last one might imply a solution to this first one... > > Yes, the distutil option 'data_files' failed to copy the database files > to the dist directory. All dbopen calls have created empty db files ... > > PS: any comments on the data_files issue ?? Yes: read the section "Installing Additional Files" in the "Distributing Python Modules" document http://docs.python.org/distutils/setupscript.html#installing-additional-files Right at the end: "To install data files directly in the target directory, an empty string should be given as the directory." setup(..., data_files=[ ('', ['list/of/file/names', 'perhaps/including/source/directory']), ] ) -- Gabriel Genellina From feliphil at gmx.net Fri Jan 30 08:10:47 2009 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 30 Jan 2009 14:10:47 +0100 Subject: New to python, open source Mac OS X IDE? References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> Message-ID: <20090130141047.5bfee166.feliphil@gmx.net> > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you > even use an IDE for Python? WingIDE Not open source, but by far the best that I've tried. Sincerely, Wolfgang From gagsl-py2 at yahoo.com.ar Fri Jan 30 08:20:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 30 Jan 2009 11:20:36 -0200 Subject: 'Address already in use' ... with TCPServer References: <186166.62068.qm@web112221.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 10:44:22 -0200, Gabriel Genellina escribi?: Sorry the duplicate post! I've seen that some of my messages come twice. I'll try to diagnose and fix the problem (if possible...). -- Gabriel Genellina From jeff at jmcneil.net Fri Jan 30 08:41:29 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Fri, 30 Jan 2009 05:41:29 -0800 (PST) Subject: Want to write a script to do the batch conversion from domain name to IP. References: Message-ID: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> On Jan 30, 7:33?am, Chris Rebert wrote: > On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao wrote: > > Hi all, > > > Suppose I've the entries like the following in my file: > > > ------------------ > > 116.52.155.237:80 > > ip-72-55-191-6.static.privatedns.com:3128 > > 222.124.135.40:80 > > 217.151.231.34:3128 > > 202.106.121.134:80 > > 211.161.197.182:80 > > hpc.be.itu.edu.tr:80 > > static3-117-183.worldinternetworkcorporation.com:80 > > ------------------ > > > Now, I want to convert the domain name to IP by using a python script, > > e.g., > > > ip-72-55-191-6.static.privatedns.com:3128 > > > should be converted into the following form: > > > 72.55.191.6:3128 > > > any hints on this? > > PyDNS might be a helpful library for writing such a script --http://pydns.sourceforge.net/ > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Why not just use socket.gethostbyname? Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') '72.55.191.6' >>> From justinwyer at gmail.com Fri Jan 30 08:46:33 2009 From: justinwyer at gmail.com (Justin Wyer) Date: Fri, 30 Jan 2009 15:46:33 +0200 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: On Fri, Jan 30, 2009 at 1:51 AM, anders wrote: > Hi! > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO > > So a read all fils with dirchached > > Then a loop thru all files each files is read with readLines() and > after that scaned > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) Do you require this information in a python application, seems like you did this manually before? If not then python is the wrong tool for this job, you can simply use this command on a unix-like environment (install cygwin, if you are on windows) $ find -name "*" -exec grep -nH "LF01" {} \; | cut -d ":" -f 1 | sort | uniq Now if you do require this information inside a python app, I would just do the above in python filenames = [] searchCmd = "find -name \"*\" -exec grep -nH \"LF01\" {} \; | cut -d \":\" -f 1 | sort | uniq" searchp = Popen(searchCmd, shell=True, bufsize=4096, stdout=PIPE) for line in searchp.stdout: filenames.append(line.strip()) Thats my advise anyway, guess you can try some search libraries don't know of any mysql tho, the above will probably be faster than anything else. Cheers and good luck. -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Fri Jan 30 08:58:06 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 13:58:06 +0000 Subject: Adding a positive number and a negative number In-Reply-To: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> Message-ID: <4983076E.5090209@mrabarnett.plus.com> Eric Kang wrote: > In two?s complement representation, can adding one positive and one negative give you overflow? > No. From darcy at druid.net Fri Jan 30 09:05:58 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 09:05:58 -0500 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <20090130090558.cd36d40d.darcy@druid.net> On Fri, 30 Jan 2009 15:46:33 +0200 Justin Wyer wrote: > $ find -name "*" -exec grep -nH "LF01" {} \; > | cut -d ":" -f 1 | sort | uniq I know this isn't a Unix group but please allow me to suggest instead; $ grep -lR LF01 -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Fri Jan 30 09:07:27 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 09:07:27 -0500 Subject: Rounding to the nearest 5 In-Reply-To: References: Message-ID: <20090130090727.e0fe500b.darcy@druid.net> On 30 Jan 2009 06:23:17 GMT Steven D'Aprano wrote: > On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > > That appears to be rounding to nearest 10, not 5. Clarify your > > requirements first. > > Look again. 36 => 35. You are correct. I should have ommitted my first sentence and emphasized the second. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From digitig at gmail.com Fri Jan 30 09:14:07 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 30 Jan 2009 14:14:07 +0000 Subject: search speed In-Reply-To: <6uft9aFf9kgbU1@mid.uni-berlin.de> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: 2009/1/30 Diez B. Roggisch : > No. Because nobody can automagically infer whatever structure your files > have. Just so. But even without going to a full database solution it might be possible to make use of the flat file structure. For example, does the "LF01" have to appear at a specific position in the input line? If so, there's no need to search for it in the complete line. *If* there is any such structure then a compiled regexp search is likely to be faster than just 'if "LF01" in line', and (provided it's properly designed) provides a bit of extra insurance against false positives. -- Tim Rowe From veerendra.cse at gmail.com Fri Jan 30 09:43:10 2009 From: veerendra.cse at gmail.com (Veerendra Ganiger) Date: Fri, 30 Jan 2009 20:13:10 +0530 Subject: is python Object oriented?? In-Reply-To: <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: Python is not purely object oriented programming, because we can write functions without any class. You are right, predefined class attributes are available when we write or execute a piece of python code without defining class, that means it's just using objects for it's purpose. It does not mean its purely object oriented. It all depends on implementation, I think even we can make "C" object oriented with proper implementation. On Thu, Jan 29, 2009 at 7:28 PM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? > > > On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > >> Muriel de Souza Godoi wrote: >> >>> Python offers support for object orientation, but it's not an >>> object-oriented language. >>> I mean, you can code a entire program in Python with no classes. So you >>> use it if you want to. >>> >>> It's not like java, which you must use a class to code a Hello World, but >>> Java isn't fully object-oriented, because it doesn't provide support for >>> multiple inheritance and it has primitive types (multiple interfaces and >>> wrappers to primitive types doesn't count :) ) >>> >>> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >>> Simula?), where everything is a class, even the primitive types. >>> >> >> well actually except keywords, everything is an object in python too, >> including of course primitive types (if you say so - practically python >> does not have them). >> >> Regards >> Tino >> > > > > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are interested > to be a part of it, please mail or call me. I will be happy to share and > inform - http://www.comat.com > -- regards, Veerendra -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Fri Jan 30 09:45:46 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 08:45:46 -0600 Subject: Adding a positive number and a negative number References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> Message-ID: <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> On 2009-01-30, MRAB wrote: > Eric Kang wrote: > >> In two's complement representation, can adding one positive >> and one negative give you overflow? >> > No. AFAIK, in Python adding integers never gives you overlow regardless of sign. -- Grant Edwards grante Yow! Is it clean in other at dimensions? visi.com From google at mrabarnett.plus.com Fri Jan 30 09:47:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 14:47:37 +0000 Subject: Swapping values of two variables In-Reply-To: References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: <49831309.7050509@mrabarnett.plus.com> Grant Edwards wrote: > On 2009-01-30, MRAB wrote: > >>> What is the minimum amount of extra memory required to exchange two >>> 32-bit quantities? What would be the pseudocode that achieves this >>> minimum? >> x ^= y >> y ^= x >> x ^= y >> >> This is really only of use when working in assembly language. > > And rarely then. ;) > > [Readability counts everywhere.] > It can be useful if you want to swap the contents of 2 registers in ARM assembly language: EOR r0,r0,r1 EOR r1,r0,r1 EOR r0,r0,r1 The quickest alternative is to use MOV: MOV r2,r0 MOV r0,r1 MOV r1,r2 The same number of instructions, program bytes, and clock cycles, but requiring an additional register! From hongyi.zhao at gmail.com Fri Jan 30 09:48:00 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 22:48:00 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil wrote: [snipped] >Why not just use socket.gethostbyname? > >Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >[GCC 4.3.2] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> import socket >>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >'72.55.191.6' >>>> See the following errors I in my case: $ python 'import site' failed; use -v for traceback Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import socket Traceback (most recent call last): File "", line 1, in ImportError: No module named socket >>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') Traceback (most recent call last): File "", line 1, in NameError: name 'socket' is not defined -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From hongyi.zhao at gmail.com Fri Jan 30 09:53:33 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Jan 2009 22:53:33 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Fri, 30 Jan 2009 22:48:00 +0800, Hongyi Zhao wrote: >On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil > wrote: >[snipped] >>Why not just use socket.gethostbyname? >> >>Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >>[GCC 4.3.2] on linux2 >>Type "help", "copyright", "credits" or "license" for more information. >>>>> import socket >>>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >>'72.55.191.6' >>>>> > >See the following errors I in my case: > >$ python >'import site' failed; use -v for traceback >Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) >[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin >Type "help", "copyright", "credits" or "license" for more information. >>>> import socket >Traceback (most recent call last): > File "", line 1, in >ImportError: No module named socket >>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') >Traceback (most recent call last): > File "", line 1, in >NameError: name 'socket' is not defined Sorry for my carelessness. It's obviously due to the lack of the socket module in my case. Another issue is: how can I perform all of these steps in a python script? -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From alejandro.weinstein at gmail.com Fri Jan 30 09:56:10 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 06:56:10 -0800 (PST) Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <9gwscdm52o.fsf@overberg.jeppesensystems.com> Message-ID: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> On Jan 30, 4:00?am, Ove Svensson wrote: > Pidis a process identifier. Threads are not processes. All your threads > execute within the context if a single process, hence they should have > the samepid. Threads may have athreadid but it is not the same as thepid. According to this document (http://heather.cs.ucdavis.edu/~matloff/ Python/PyThreads.pdf), at least in Linux, threads are process: "Here each thread really is a process, and for example will show up on Unix systems when one runs the appropriate ps process-list command, say ps axH. The threads manager is then the OS." If you look at my original post, pstree does show different PIDs for the threads. Regards, Alejandro. From invalid at invalid Fri Jan 30 10:02:36 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 09:02:36 -0600 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: On 2009-01-30, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > >> I'm new to Python and also wondering about OOP in Python. >> >> I want to justify the above question (is Python Object-Oriented?). >> Does Python follow the concepts/practices of Encapsulation, >> Polymorphism and Interface, which are quite familiar to Java >> programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. As long as one doesn't then conflate message-passingness with object-orientedness. [Not that I'm implying Chris does, but given the OP's comments one worries that he might.] -- Grant Edwards grante Yow! I know things about at TROY DONAHUE that can't visi.com even be PRINTED!! From Peter.Rupp at acxiom.com Fri Jan 30 10:08:28 2009 From: Peter.Rupp at acxiom.com (Rupp Peter - prupp) Date: Fri, 30 Jan 2009 09:08:28 -0600 Subject: Hello..General question about TKinter. Message-ID: <5A80174CDBD2004CB0A1A069083813C90408D2A9@CWYMSX05.Corp.Acxiom.net> Hello, I am a fluent Python programmer, but have limited (zero) GUI experience. I need to write simple GUI's fairly quickly and would prefer to use TKinter for it's simplicity and longevity. (I tried to compile QT on both HPUX and Solaris with recent compilers...and compiles/builds failed....frustrating. In contrast, compiling tcl/TK libraries was a breeze!) The only thing I'm curious about now are the following: Is the TKinter python module actively maintained? And does it keep up with the latest TK widget sets, features and methods? I'm seeing that TK 8.0 and later have significant enhancements that are very attractive and I would like to use them from the Tkinter interface. At some point I will need them, and was thinking that I might have to build my own interface module to encapsulate their methods, and/or start writing code in tcl/tk. Not sure which would be easier. Thank you for your time. Kind regards, Peter ************************************************************************* The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not 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 resend this communication to the sender and delete the original message or any copy of it from your computer system. Thank you. ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Fri Jan 30 10:31:45 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Fri, 30 Jan 2009 07:31:45 -0800 (PST) Subject: Using equals operator without changing reference pointer References: <9Iydnfd6f9PM8x_UnZ2dnUVZ_gidnZ2d@speakeasy.net> Message-ID: <0fd92d9d-b1cd-4dc8-8c66-1f1a949922a8@w24g2000prd.googlegroups.com> On Jan 29, 8:03?pm, Terry Reedy wrote: > Erik Max Francis wrote: > > mark.sea... at gmail.com wrote: > > >> Is there a way to lock down myInst so that it still refers to the > >> original object, and is there some special member that will allow me > >> to override the equals operator in this case? ?Or is that simply > >> blasphemous against everything Python holds sacred? ?Certainly there > >> is some keyword that I don't know about. > > > No. ?The assignment operator with a bare name on the left hand side is > > not overridable. > > So that 'name = ob' *always* binds name to ob. ?That is one thing one > can depend on when reading Python code. > > > You can override attribute access, however, with > > .__getattr__/.__getattribute__. > > I presume that you have over-riden __setitem__ in addition to > __getitem__ so that myOb[0] = 1 sets the bit. You could add a branch to > __setitem__ (or define __setslice__ in 2.x) so that myOb[:] = 0x55 does > just what you want it to -- set all bits. ?Being able to get/set > contiguous bits might be something you want anyway. > > tjr > > PS. When asking about internal details, specify version of interest, as > there have been minor changes. OK. Thanks for your advice. From lists at cheimes.de Fri Jan 30 10:49:15 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 16:49:15 +0100 Subject: Swapping values of two variables In-Reply-To: References: Message-ID: Steven D'Aprano schrieb: > Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes > (96 bits) in size; a long will use as much memory as needed. If your > application needs to optimize a swap of two ints, then Python is probably > going to be much too memory-intensive for you. An int object consumes more than 12 bytes of memory. It depends on the system architecture, too. It's usually 16 bytes on a 32bit system and 24 bytes on a 64bit system. The actual size can be computed by sizeof(ptr) + sizeof(long) + sizeof(ssize_t). The size is rounded up to the next multiple of 8 bytes due to address alignment. Christian From linuxguy123 at gmail.com Fri Jan 30 11:03:04 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 30 Jan 2009 09:03:04 -0700 Subject: Why doesn't this work in Eclipse ? (Simple pexpect code that works in bash) Message-ID: <1233331384.3886.12.camel@localhost.localdomain> I'm trying to build a small Python app in Eclipse under Fedora 10. I have the following code: import os import sys import pexpect child = pexpect.spawn('/bin/bash') child.interact() When I run it in Eclipse, I get: Traceback (most recent call last): File "/home/xxx/workspace/FixPermissions/src/default/main.py", line 56, in child.interact() File "/usr/lib/python2.5/site-packages/pexpect.py", line 1489, in interact mode = tty.tcgetattr(self.STDIN_FILENO) termios.error: (22, 'Invalid argument') Yet if I run it in a bash shell, it works: $ python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> import sys >>> import pexpect >>> child = pexpect.spawn('/bin/bash') >>> child.interact() [xxx at localhost ~]$ ls [xxx at localhost ~]$ exit >>> >>> Why doesn't it run under Eclipse and how do I fix it so it does ? Thanks From exarkun at divmod.com Fri Jan 30 11:11:27 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 11:11:27 -0500 Subject: Get thread pid In-Reply-To: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> Message-ID: <20090130161127.12853.1507278417.divmod.quotient.511@henry.divmod.com> On Fri, 30 Jan 2009 06:56:10 -0800 (PST), Alejandro wrote: >On Jan 30, 4:00?am, Ove Svensson wrote: >> Pidis a process identifier. Threads are not processes. All your threads >> execute within the context if a single process, hence they should have >> the samepid. Threads may have athreadid but it is not the same as thepid. > >According to this document (http://heather.cs.ucdavis.edu/~matloff/ >Python/PyThreads.pdf), at least in Linux, threads are process: > >"Here each thread really is a process, and for example will show up on >Unix systems when one runs the appropriate ps process-list command, >say ps axH. The threads manager is then the OS." > >If you look at my original post, pstree does show different PIDs for >the threads. That document is quite misleading. Threads are not processes. They are *similar* to processes. They share many qualities of processes. But they are not processes. The "H" option for ps is *explicitly* documented (in recent versions of ps) as a way to make ps lie to you: H Show threads as if they were processes In times long since past, threads on Linux were even more like processes than they are now. Then, it might have even been defensible to say that they were processes, but that was an implementation detail. These days, threads on Linux are provided by something called NPTL (whereas they used to be provided by something called LinuxThreads). When using NPTL, threads do not have distinct PIDs. So, if you want to learn more about threads on Linux, you should check out the NPTL documentation. It is a much more reliable authority than any Python documentation regarding the nature of threads on Linux. Hope this helps, Jean-Paul From mabdelkader at gmail.com Fri Jan 30 11:17:55 2009 From: mabdelkader at gmail.com (ma) Date: Fri, 30 Jan 2009 11:17:55 -0500 Subject: Get thread pid In-Reply-To: <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <9gwscdm52o.fsf@overberg.jeppesensystems.com> <4136c737-10a9-40cd-9df5-3ce892377eaa@b38g2000prf.googlegroups.com> Message-ID: <148918f0901300817w3ba6b74cqd611b081cd21d5e3@mail.gmail.com> Actually, the command given "ps axH" uses H which shows threads as if they were processes. If you check the pid of these "processes," you would find that they are all equivalent. On Fri, Jan 30, 2009 at 9:56 AM, Alejandro wrote: > On Jan 30, 4:00 am, Ove Svensson wrote: > > Pidis a process identifier. Threads are not processes. All your threads > > execute within the context if a single process, hence they should have > > the samepid. Threads may have athreadid but it is not the same as thepid. > > According to this document (http://heather.cs.ucdavis.edu/~matloff/ > Python/PyThreads.pdf), > at least in Linux, threads are process: > > "Here each thread really is a process, and for example will show up on > Unix systems when one runs the appropriate ps process-list command, > say ps axH. The threads manager is then the OS." > > If you look at my original post, pstree does show different PIDs for > the threads. > > Regards, > Alejandro. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eliben at gmail.com Fri Jan 30 11:30:53 2009 From: eliben at gmail.com (eliben) Date: Fri, 30 Jan 2009 08:30:53 -0800 (PST) Subject: relpath problem on windows Message-ID: I'm having a problem with 2.6's new os.path.relpath function. This is correct: relpath(r'd:\abc\jho', r'd:\abc') => 'jho' But this isn't: relpath(r'd:\jho', r'd:\\') => '..\jho' Neither is this: relpath(r'd:\jho', r'd:') => '..\..\..\jho' What am I missing? From alejandro.weinstein at gmail.com Fri Jan 30 11:33:53 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 08:33:53 -0800 (PST) Subject: Get thread pid References: Message-ID: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> On Jan 30, 9:11?am, Jean-Paul Calderone wrote: > [clarification about threads] Thank you for the clarification. I will reformulate my question: pstree and also ntop (but not top) show a number for each thread, like for instance: $pstree -p 9197 python(9197)???{python}(9555) ??{python}(9556) ??{python}(9557) ??{python}(9558) ??{python}(9559) ??{python}(9560) ??{python}(9561) ??{python}(9562) ??{python}(9563) ??{python}(9564) Is is possible to get the number corresponding to each thread? The reason I am interested is because one of my thread is hogging the CPU, and want to find which one is the culprit. Regards, Alejandro. From rNOSPAMon at flownet.com Fri Jan 30 11:34:25 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 30 Jan 2009 08:34:25 -0800 Subject: Sloooooowwwww WSGI restart References: <498171a5$0$3681$426a74cc@news.free.fr> <146f6796-37b5-4220-bdb1-5119cb3ac7e1@z6g2000pre.googlegroups.com> Message-ID: In article <146f6796-37b5-4220-bdb1-5119cb3ac7e1 at z6g2000pre.googlegroups.com>, Graham Dumpleton wrote: > On Jan 30, 9:53?am, Ron Garret wrote: > > In article <498171a5$0$3681$426a7... at news.free.fr>, > > ?Bruno Desthuilliers > > > > ?wrote: > > > Ron Garret a ?crit : > > > > In article , > > > > ?Aleksandar Radulovic wrote: > > > (snip) > > > >> Secondly, why are you restarting apache after code changes? In normal > > > >> circumstances, you shouldn't have to do that. > > > > > > I thought (and experiment confirms) that only the main WSGI app file > > > > gets reloaded automatically when it changes, not the libraries. > > > > > Depends on how you configure mod_wsgi. Read the part about "Process > > > Reloading Mechanism" here: > > >http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode > > > > I'm running Debian Etch, which means I have an older version of > > mod_wsgi, which means I don't have the process reloading mechanism. > > Back port available at: > > http://packages.debian.org/etch-backports/libapache2-mod-wsgi > > Graham Cool! Thanks! rg From rNOSPAMon at flownet.com Fri Jan 30 11:35:12 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 30 Jan 2009 08:35:12 -0800 Subject: More mod_wsgi weirdness: process restarts on redirect References: <63cf7deb-f15c-4259-aa24-1b8da846876d@r41g2000prr.googlegroups.com> Message-ID: In article <63cf7deb-f15c-4259-aa24-1b8da846876d at r41g2000prr.googlegroups.com>, Graham Dumpleton wrote: > On Jan 30, 11:01?am, Ron Garret wrote: > > In article , > > ?Joshua Kugler wrote: > > > > > Ron Garret wrote: > > > > My question is: is this supposed to be happening? ?Or is this an > > > > indication that something is wrong, and if so, what? > > > > > You are probably just hitting a different instance of Apache, thus the > > > different process ID. > > > > Yep, that's what it turned out to be. ?I thought I had a > > WSGIDaemonProcess processes=1 directive in my config, but I had it in > > the wrong place (a different vhost) so it wasn't actually active. > > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > > But that leaves me wondering why the redirect would reliably trigger > > switching processes. ?The reason I thought that I had the correct > > configuration and only had one process is that when I reloaded the > > non-redirected page I *always* got the same process ID. ?How > > doesmod_wsgidecide which process ?(and which thread for that matter) to > > use? > > Details on process/threading in mod_wsgi available at: > > http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading > > When using WSGIDaemonProcess directive, if you want a single process > it is better to allow it to default to a single process and not have > 'processes=1'. As soon as you say 'processes=1' it will trigger > wsgi.multiprocess to be True rather than default of False. This may > sound counter intuitive, but is a little back door to allow > wsgi.multiprocess to be set to True somehow when distributing an > application across a cluster of machines where it does need to be True > even if each machine only has a single process for that application. > Tthat wsgi.multiprocess is True will not usually matter unless you are > trying to use debugging middleware that require that there only be a > single process. > > As to why you were getting a different process, because you were > actually running in embedded mode due to WSGIDaemonProcess/ > WSGIProcessGroup being in wrong context, then what process was used > was really up to Apache and how it works. Specifically it can have > multiple processes that can listen on the HTTP port (80). Because only > one should be listening at a time it uses a cross process mutex lock > to mediate access. When a process handles a request, it gives up the > lock. If using worker MPM then another thread in same process may get > lock, or for either worker MPM or prefork MPM, then another process > could get it. Which actually gets it is a bit indeterminate as simply > depends on which process the operating system lets have the lock next. > So, there is no strict rule one can say as to who would get it next. > > Graham > Graham Thanks! rg From x at x.xx Fri Jan 30 11:36:54 2009 From: x at x.xx (x) Date: Fri, 30 Jan 2009 09:36:54 -0700 (MST) Subject: python is a python Message-ID: <0f33f6af54280c637676176a8e0a89fd@pseudo.borked.net> python is a python From mabdelkader at gmail.com Fri Jan 30 11:53:46 2009 From: mabdelkader at gmail.com (ma) Date: Fri, 30 Jan 2009 11:53:46 -0500 Subject: Get thread pid In-Reply-To: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> References: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> Message-ID: <148918f0901300853w1d0ee23dv7b5993e0f3bc778c@mail.gmail.com> I think issue here is that you're invoking a system call (using either the subprocess module or os.popen*) from your threads. Those *are* external processes and will show up under pstree since they have a parent process. If you're using subprocess.Popen() the object that is returned has an attribute 'pid' that can be accessed (which would serve your purpose). Please note that *this is NOT a thread id* On Fri, Jan 30, 2009 at 11:33 AM, Alejandro wrote: > On Jan 30, 9:11 am, Jean-Paul Calderone wrote: > > [clarification about threads] > > Thank you for the clarification. I will reformulate my question: > > pstree and also ntop (but not top) show a number for each thread, like > for instance: > > $pstree -p 9197 > python(9197)???{python}(9555) > ??{python}(9556) > ??{python}(9557) > ??{python}(9558) > ??{python}(9559) > ??{python}(9560) > ??{python}(9561) > ??{python}(9562) > ??{python}(9563) > ??{python}(9564) > > Is is possible to get the number corresponding to each thread? > > The reason I am interested is because one of my thread is hogging the > CPU, and want to find which one is the culprit. > > Regards, > Alejandro. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at divmod.com Fri Jan 30 11:55:50 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 11:55:50 -0500 Subject: Announcing Pyflakes 0.3.0 In-Reply-To: 0 Message-ID: <20090130165550.12853.274533186.divmod.quotient.527@henry.divmod.com> I am proud to announce the release of Pyflakes 0.3.0. This release fixes several bugs, improves compatibility with recent versions of Python, and new flake checks. Pyflakes is a static analysis tool for Python source. It is focused on identifying common errors quickly without executing Python code. It is a handy supplement to your project's test suite. Read more about Pyflakes and the 0.3.0 release on the website: http://divmod.org/trac/wiki/DivmodPyflakes Jean-Paul Calderone Divmod, Inc. From apt.shansen at gmail.com Fri Jan 30 11:58:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 30 Jan 2009 08:58:02 -0800 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> On Fri, Jan 30, 2009 at 12:38 AM, r wrote: > On Jan 30, 2:26 am, John Machin wrote: > [snip] > > This doesn't appear to match the description. Perhaps the PSU has > > subverted my comp)(*&^%$#@! > > NO CARRIER > > Oops -- Good catch John, > Even perfect people like myself make mistakes :). Here is the > aforementioned thread where a Python user was chastised for daring to > say Python has a clearer syntax than Perl thereby easing > maintainability: OH NO! *big hand wave* > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a > > These Perl mongers have no business doing their mongling here, go to > c.l.Perl! He was not chastised, nor threatened as you previously said; he was welcomed to Python in all of its awesomeness, and given a pointer about community etiquette. "excessive Perl bashing" ... "considered tasteless" ... Come on. That's so mild of a warning that you can barely call it that. Considering the comment after "the occasional snide comment should be fine :-)" complete with a smiley even should make it very clear that a simple and *friendly* pointer on getting along in a new community was given. It was great advice, too. No one has a problem with talking about Python's strengths, or how good Python has worked for them; or even comparing it to other languages in a reasoned way (though those conversations have all been had ten thousand years ago)... its the vitriolic bashing of other languages that isn't wanted because there's no point to it at all. It does nothing at all but make us look like mongers, zealots, and childish to boot. Advocating the language is a great thing to do. Evangelizing it makes us look like idiots. You catch grief because your evangelization of the language is *so* completely over the top that it comes off almost as trollish-- the reverse-troll technique is not all that uncommon. Like with http://groups.google.com/group/comp.lang.python/msg/b8a079b8b780be19 -- and the talk of throwing off shackles and embracing the Freedom That Python Gives You. Its so completely excessive that it can't even be taken seriously. You ask if community matters to Python? It does, absolutely. I just don't think you understand that community. Its there. Its full of tons of people in many walks of life who use Python to get things done, and who absolutely love doing so -- its full of people who use the language and the tools it provides to accomplish real things easier, faster (to accomplish a goal, not to execute a chunk of code) and without sacrificing long-term maintainability. My impression of the community is simply that its a more quiet one: advocacy instead of evangelism. I'd rather talk about how to accomplish something in a Pythonic way, or how to help use Python to solve your problems in a way that is natural to do in Python -- and convert you that way, then to worry about a "war with Ruby" and such nonsense. Personally, I love Python. I wouldn't take a job writing in either Perl or Ruby: but those who like that language are welcome to it. Personally, I work for a division in our company that has converted over the last few years our entire software line from an old, Windows-only mix of C and VCL-stuff, to a serious mid-sized product which recently clocked in at about 165k lines of Python code (about 600k more in third party libs!) that's fast, effective, flexible, multi-platform and highly responsive to our customer's evolving needs. We actually did a complete rewrite from the ground up -- a dangerous thing to do, but the legacy product was so out of date that it had to be done... and I don't think any other set of tools would have been able to let us do so as well, in as short of a period of time, or as iteratively and in cooperation with our customer base. I have tons of positive things to say about Python: lots of people in The Community do. And we've all worked with other languages and have reasons why we don't like those tools, and people are fine to share those reasons. But that's a different thing then flinging bile and ranting about how horrible Language-X is or how Perfect-For-All-Things Python is. --Stephen P.S. Sorry for waxing verbosely. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Fri Jan 30 11:58:16 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 08:58:16 -0800 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: Tim Rowe wrote: > .... But even without going to a full database solution it might > be possible to make use of the flat file structure. For example, does > the "LF01" have to appear at a specific position in the input line? If > so, there's no need to search for it in the complete line. *If* there > is any such structure then a compiled regexp search is likely to be > faster than just 'if "LF01" in line', and (provided it's properly > designed) provides a bit of extra insurance against false positives. Clearly this is someone who regularly uses grep or perl. If you know the structure, like the position in a line, something like the following should be fast: with open(somename) as source: for n, line in enumerate(source): if n % 5 == 3 and line[5 : 9] == 'LF01': print ('Found on line %s: %s' % (1 + n, line.rstrip()) Be careful with your assertion that a regex is faster, it is certainly not always true. Measure speed, don't take mantras as gospel. --Scott David Daniels Scott.Daniels at Acm.Org From invalid at invalid Fri Jan 30 12:05:11 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 30 Jan 2009 11:05:11 -0600 Subject: Swapping values of two variables References: <1891465488.1011321233275351554.JavaMail.root@jaguar10.sfu.ca> Message-ID: > Grant Edwards wrote: > > On 2009-01-30, MRAB wrote: > > > >>> What is the minimum amount of extra memory required to exchange two > >>> 32-bit quantities? What would be the pseudocode that achieves this > >>> minimum? > >> x ^= y > >> y ^= x > >> x ^= y > >> > >> This is really only of use when working in assembly language. > > > > And rarely then. ;) > > > > [Readability counts everywhere.] > > It can be useful if you want to swap the contents of 2 registers in ARM > assembly language: > > EOR r0,r0,r1 > EOR r1,r0,r1 > EOR r0,r0,r1 > > The quickest alternative is to use MOV: > > MOV r2,r0 > MOV r0,r1 > MOV r1,r2 > > The same number of instructions, program bytes, and clock > cycles, but requiring an additional register! Yea, I guess the ARM's SWP instruction only works on register<->memory. That said, I don't remember ever needing to swap the contents of two register when working in ARM assembly language (yes I have done some). I always just use the value in the register where it is. Swap with top of stack (for which the SWP instruction works) can be useful for implementing some sorts of stack-based VMs, but register-register swap just doesn't seem to be something one needs to do (which probably explains why there's no instruction to do it). Given the choice between the cryptic version that doesn't require a third register, and the obvious version that uses a third register, I'll usually choose the latter. There aren't that many people left who'll recognize what the triple-xor sequence is doing -- so if I ever would use it, I'd probably make it a macro. -- Grant Edwards grante Yow! This ASEXUAL PIG at really BOILS my BLOOD visi.com ... He's so ... so ... URGENT!! From Scott.Daniels at Acm.Org Fri Jan 30 12:10:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 09:10:44 -0800 Subject: Adding a positive number and a negative number In-Reply-To: <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: Grant Edwards wrote: > On 2009-01-30, MRAB wrote: >> Eric Kang wrote: >>> In two's complement representation, can adding one positive >>> and one negative give you overflow? >> No. > AFAIK, in Python adding integers never gives you overlow > regardless of sign. Right, but he wants his homework answer. From exarkun at divmod.com Fri Jan 30 12:10:55 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 12:10:55 -0500 Subject: Get thread pid In-Reply-To: <56a1bc21-7fff-4a82-816f-03fa8be79172@g1g2000pra.googlegroups.com> Message-ID: <20090130171055.12853.141462103.divmod.quotient.532@henry.divmod.com> On Fri, 30 Jan 2009 08:33:53 -0800 (PST), Alejandro wrote: >On Jan 30, 9:11?am, Jean-Paul Calderone wrote: >> [clarification about threads] > >Thank you for the clarification. I will reformulate my question: > >pstree and also ntop (but not top) show a number for each thread, like >for instance: > >$pstree -p 9197 >python(9197)???{python}(9555) > ??{python}(9556) > ??{python}(9557) > ??{python}(9558) > ??{python}(9559) > ??{python}(9560) > ??{python}(9561) > ??{python}(9562) > ??{python}(9563) > ??{python}(9564) > >Is is possible to get the number corresponding to each thread? > >The reason I am interested is because one of my thread is hogging the >CPU, and want to find which one is the culprit. I think someone mentioned calling gettid using ctypes earlier in this thread. Unfortunately, this is somewhat convoluted: exarkun at charm:~$ python Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes, os, threading, time >>> os.system("pstree -p " + str(os.getpid())) python(11427)???sh(11429)???pstree(11430) 0 >>> threading.Thread(target=time.sleep, args=(1000,)).start() >>> os.system("pstree -p " + str(os.getpid())) python(11427)???sh(11436)???pstree(11437) ??{python}(11431) 0 >>> ctypes.CDLL('libc.so.6').syscall(224) 11427 >>> 224 comes from grepping /usr/include for SYS_gettid. This is Linux specific, and probably even architecture specific. For a quick debug hack, perhaps this is good enough, though. Jean-Paul From google at mrabarnett.plus.com Fri Jan 30 12:13:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jan 2009 17:13:53 +0000 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> Message-ID: <49833551.9000701@mrabarnett.plus.com> Stephen Hansen wrote: > On Fri, Jan 30, 2009 at 12:38 AM, r > wrote: > > On Jan 30, 2:26 am, John Machin > wrote: > [snip] > > This doesn't appear to match the description. Perhaps the PSU has > > subverted my comp)(*&^%$#@! > > NO CARRIER > > Oops -- Good catch John, > Even perfect people like myself make mistakes :). Here is the > aforementioned thread where a Python user was chastised for daring to > say Python has a clearer syntax than Perl thereby easing > maintainability: OH NO! *big hand wave* > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1214df115ac01ce/c7cfe1fa9634cc2a?hl=en&lnk=gst&q=perl+bashing#c7cfe1fa9634cc2a > > > These Perl mongers have no business doing their mongling here, go to > c.l.Perl! > > > He was not chastised, nor threatened as you previously said; he was > welcomed to Python in all of its awesomeness, and given a pointer about > community etiquette. > [snip] > I have tons of positive things to say about Python: lots of people in > The Community do. And we've all worked with other languages and have > reasons why we don't like those tools, and people are fine to share > those reasons. But that's a different thing then flinging bile and > ranting about how horrible Language-X is or how Perfect-For-All-Things > Python is. > [snip] It's probably unpythonic to bash other languages. Python is so good that there's no need. :-) From ofzhengyi at gmail.com Fri Jan 30 12:19:21 2009 From: ofzhengyi at gmail.com (=?GB2312?B?1qPS5Q==?=) Date: Sat, 31 Jan 2009 01:19:21 +0800 Subject: What's new in 3.0 about threading? Message-ID: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> Hello I have questions about threading: import threading class myThread(threading.Thread): def run(self): print('hello,threads') if __name__=='__main__': threads=myThread() threads.start() Above program does't work at 'Run Module' in IDLE,but it works well under executing scripts.Is it anything wrong? WindowXP,Python 3.0 Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gduzan at gmail.com Fri Jan 30 12:21:49 2009 From: gduzan at gmail.com (Gary Duzan) Date: Fri, 30 Jan 2009 09:21:49 -0800 (PST) Subject: Why doesn't this work in Eclipse ? (Simple pexpect code that works in bash) References: Message-ID: On Jan 30, 11:03?am, Linuxguy123 wrote: > I'm trying to build a small Python app in Eclipse under Fedora 10. > > I have the following code: > > import os > import sys > import pexpect > > child = pexpect.spawn('/bin/bash') > child.interact() > > When I run it in Eclipse, I get: > > Traceback (most recent call last): > ? File "/home/xxx/workspace/FixPermissions/src/default/main.py", line > 56, in > ? ? child.interact() > ? File "/usr/lib/python2.5/site-packages/pexpect.py", line 1489, in > interact > ? ? mode = tty.tcgetattr(self.STDIN_FILENO) > termios.error: (22, 'Invalid argument') > > Yet if I run it in a bash shell, it works: > > [ ... ] > > Why doesn't it run under Eclipse and how do I fix it so it does ? That code assumes the stdin of the parent is a real (or possibly pseudo-) terminal, which appears not to be the case for programs run through Eclipse. Gary Duzan From ronaldjweiss at gmail.com Fri Jan 30 12:25:26 2009 From: ronaldjweiss at gmail.com (ronaldjweiss at gmail.com) Date: Fri, 30 Jan 2009 09:25:26 -0800 (PST) Subject: Python Developer needed for Greenwich, CT assignment Message-ID: Senior Python Programmer needed to develop, enhance and expand a Trade Capture application at a hedge fund client. The technical platform includes MySQL running both on Windows and UNIX. Requirements: 3-6+ years solid Python development skills and experience in the brokerage industry a must. SQL and UNIX required. This is a 6 - 12 month contract that could extend indefinitely. Ron Weiss THE BMW GROUP, INC. Technology placement in the securities industry 40 Exchange Place, Suite 700, New York, NY 10005 212-943-8800 ronw at careerobject.com From haag at lsu.edu Fri Jan 30 12:36:45 2009 From: haag at lsu.edu (Alaric Haag) Date: Fri, 30 Jan 2009 11:36:45 -0600 Subject: Odd syntactic NON-error? Message-ID: Hello, I just noticed that I've been successfully importing a module I wrote which contains a class definition that begins with (docstring removed): class TDF(): def __init__(self, name='', mode=tscan. GP_NOCLOBBER): Note the "space" which shouldn't be here---^ I'm running Python 2.5.2. What does the interpreter "think" I'm doing? It's not flagged by pylint either, so I suspect there's a reasonable explanation. Alaric From exarkun at divmod.com Fri Jan 30 12:39:48 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 30 Jan 2009 12:39:48 -0500 Subject: Odd syntactic NON-error? In-Reply-To: Message-ID: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> On Fri, 30 Jan 2009 11:36:45 -0600, Alaric Haag wrote: >Hello, > >I just noticed that I've been successfully importing a module I wrote >which contains a class definition that begins with (docstring removed): > >class TDF(): > def __init__(self, name='', mode=tscan. GP_NOCLOBBER): > >Note the "space" which shouldn't be here---^ The space is irrelevant. >>> object. __init__ >>> object.__init__ is object. __init__ True >>> Jean-Paul From bjracine at glosten.com Fri Jan 30 13:19:32 2009 From: bjracine at glosten.com (Benjamin J. Racine) Date: Fri, 30 Jan 2009 10:19:32 -0800 Subject: Rounding to the nearest 5 In-Reply-To: <20090130090727.e0fe500b.darcy@druid.net> Message-ID: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> Doesn't this work? round_by_5.py >>>>>>>>>>>>>>>>>>>>>>> import sys def round_by_5(x= sys.argv[0]): x = x/5. x = round(x) x = x*5 print(x) return x Ben R. -----Original Message----- From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of D'Arcy J.M. Cain Sent: Friday, January 30, 2009 6:07 AM To: Steven D'Aprano Cc: python-list at python.org Subject: Re: Rounding to the nearest 5 On 30 Jan 2009 06:23:17 GMT Steven D'Aprano wrote: > On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote: > > That appears to be rounding to nearest 10, not 5. Clarify your > > requirements first. > > Look again. 36 => 35. You are correct. I should have ommitted my first sentence and emphasized the second. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list From noama at answers.com Fri Jan 30 13:36:32 2009 From: noama at answers.com (Noam Aigerman) Date: Fri, 30 Jan 2009 20:36:32 +0200 Subject: A replacement to closures in python? Message-ID: <749CACF29BDFB64E9F80189ECD778688048FEB3C@jermail1.atomant.net> Hi, I want to create an array of functions, each doing the same thing with a change to the parameters it uses... something like: arr=['john','terry','graham'] funcs=[] for name in arr: def func(): print 'hello, my name is '+name funcs.append(func) for f in funcs: f() And I would like that to print hello, my name is john hello, my name is terry hello, my name is graham of course... Now I understand why the above code doesn't work as I want it to, but is there some simple workaround for it? Thanks, Noam -------------- next part -------------- An HTML attachment was scrubbed... URL: From berankin99 at yahoo.com Fri Jan 30 13:52:07 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Fri, 30 Jan 2009 10:52:07 -0800 (PST) Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> Message-ID: <296542.92832.qm@web112216.mail.gq1.yahoo.com> > > > I am trying to build python 2.6 on a machine (web server) that I do not have > root access to. (has 2.4 installed) > > > > Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1. > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: error: > syntax error before '*' token > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: warning: > function declaration isn't a prototype > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In function > `CFuncPtr_nonzero': > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: error: > `self' undeclared (first use in this function) > > Mmm... my 2.6.1 source show different line numbers, maybe you should check it's > the right file? > Wow, good catch. I just re-downloaded the archive and it works fine. I know for certain that I did no editing to the files, and even tried expanding the original tar.gz a couple of times. There must be a corrupted package somewhere among the official Python mirrors. (Sadly, I overwrote the old tar.gz file when I got the new one.) From aahz at pythoncraft.com Fri Jan 30 13:56:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 10:56:20 -0800 Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <631e2879-6171-417e-8254-7f78c8cfc685@i24g2000prf.googlegroups.com> Message-ID: In article <631e2879-6171-417e-8254-7f78c8cfc685 at i24g2000prf.googlegroups.com>, alex23 wrote: > >If you're having to set up your imports in a specific order, odds are >you have either a circular dependency or are overusing 'from >import *'. You should -never- (IMO) do something like 'from library> import x, y, z' in module 'a' and then 'from a import *' in >module 'b'. If 'b' uses x, y & z, it should import them itself. If you >-must- use 'import *', specify exactly what should be exported via >'__all__'...in most cases, it should be restricted to only objects >defined within that module. There's one other way to run into this problem: I forget the exact mechanics, but if you mix up absolute and relative imports for modules inside packages, you can get namespace problems. (It's also possible newer versions of Python don't have this issue.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From alejandro.weinstein at gmail.com Fri Jan 30 13:56:30 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Fri, 30 Jan 2009 10:56:30 -0800 (PST) Subject: Get thread pid References: Message-ID: <76a44a3a-9eb5-4de1-9fd1-545b6b37aca7@r15g2000prd.googlegroups.com> On Jan 30, 10:10?am, Jean-Paul Calderone wrote: > ? ? >>> ctypes.CDLL('libc.so.6').syscall(224) Great! ctypes.CDLL('libc.so.6').syscall(224) does the trick. Thank you. Regards, Alejandro. From apt.shansen at gmail.com Fri Jan 30 14:02:44 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 30 Jan 2009 11:02:44 -0800 (PST) Subject: A replacement to closures in python? In-Reply-To: <749CACF29BDFB64E9F80189ECD778688048FEB3C@jermail1.atomant.net> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From jon at ffconsultancy.com Fri Jan 30 14:12:49 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Fri, 30 Jan 2009 19:12:49 +0000 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> Message-ID: <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> I had hoped someone else would correct you but they haven't. So... Xah Lee wrote: > Here are some examples of a function that returns a function as > result, but is not currying. > > Mathematica example: > > f[n_]:=Function[n^#]; > f[7][2] > (* returns 49 *) > > Emacs lisp example: > > (defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) ) > (funcall (f 7) 2) > > Perl example: > > sub f {$n=$_[0]; sub { $n ** $_[0]} }; > print &{ f(7) } (2); > > Javascript example: > > function f(n) {return function (x) {return Math.pow(x,n);}; } > alert (f(7) (2)); > > However, the above are not languages that support currying, That is incorrect. Mathematica, Lisp, Perl and Javascript all support currying. > which is a feature that Haskell & Ocaml has. That is correct. Here is an OCaml equivalent: let f = fun n -> fun m -> n ** m > To be more concrete, in the context of a given computer language, to > say that it support curring, is to mean that the compiler understand > the concept to certain degree. More to the point, the language is > inherently able to take a function of more than one arg and > deconstruct it to several functions of single arg. That is incorrect. You only need a language with first-class functions. I believe you are confusing the syntactic support in OCaml and Haskell for something more. It simply allows you to rewrite the above as: let f n m = n ** m or: let f = fun n m -> n ** n -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From tim at burlyhost.com Fri Jan 30 14:22:01 2009 From: tim at burlyhost.com (Tim Greer) Date: Fri, 30 Jan 2009 11:22:01 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> Message-ID: Jon Harrop wrote: > I had hoped someone else would correct you but they haven't. So... The lack of replies aren't about anyone correcting him or not, it's that the guy just posts anything he can to spamvertize his site and tell everyone how brilliant he thinks he is. It's just a method he uses to try and feel important and also get people to his site (and for the search engines to rank it higher). He's a known troll and spammer in a lot of groups due to this. The guy rarely has anything relevant to the groups he posts to. Most people I know of have come to just filter out his posts. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle! From ivan.illarionov at gmail.com Fri Jan 30 14:58:10 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Fri, 30 Jan 2009 11:58:10 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> Message-ID: <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> r wrote: > Where are the community projects supporting Python? -- besides the > core devlopment. Seem s that nobody is interested unless their pay-pal > account is involved. I find this all quite disappointing. Hi r, Can you just type import antigravity and join us up there? Hatred for Ruby and Perl seems to oppose natural Python forces, that's why you can't see community spirit. Let your hatred go and start flying already. -- Ivan From torriem at gmail.com Fri Jan 30 15:14:40 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 30 Jan 2009 13:14:40 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <49835FB0.5060903@gmail.com> Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? I'd say that actually Python uses encapsulation extensively throughout the language. Every object in Python has attributes. Thus every object encapsulates (contains) attributes (which are themselves objects). I think the term "encapsulation" is often misinterpreted by some (Java programmers in particular) to mean some kind of enforced black-box methodology. In effect they feel that getters and setters is the definition of encapsulation. This is really not true, especially if you go back to the original OO languages, such as Smalltalk. So if you are asking, does python enforce some kind of bizarre black box access semantics (requiring getters and setters), the answer is an emphatic "no!" Interfaces have nothing to do with OO programming as a matter of a fundamental principle. Interfaces exist in Java to compensate for flaws/features in the language. Particularly the lack of multiple inheritance which is a blessing/curse in Java. Python just doesn't need interfaces. Protocols for communication with an object do not need to be formally enforced. For example the popular database API that most python database libraries use just makes sure it implements certain methods. Thus it doesn't matter if I'm using mysql, postgresql, or oracle. I still call the object's "connect" method. Such a breath of fresh air compared to Java, in my opinion. Such informality can be a bit of a hindrance to some I guess. After this entire thread, it's funny that people are still chiming in saying, "so is it really OOP" after having it explained in so many ways. From sjmachin at lexicon.net Fri Jan 30 15:22:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 20:22:16 +0000 (UTC) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <20090130090558.cd36d40d.darcy@druid.net> Message-ID: D'Arcy J.M. Cain druid.net> writes: > > On Fri, 30 Jan 2009 15:46:33 +0200 > Justin Wyer gmail.com> wrote: > > $ find -name "*" -exec grep -nH "LF01" {} \; > > | cut -d ":" -f 1 | sort | uniq > > I know this isn't a Unix group but please allow me to suggest instead; > > $ grep -lR LF01 and if the OP is on Windows: an alternative to cygwin is the GnuWin32 collection of Gnu utilities ported to Windows. See http://gnuwin32.sourceforge.net/ ... you'll want the Grep package but I'd suggest the CoreUtils package as worth a detailed look, and do scan through the whole list of packages while you're there. HTH, John From torriem at gmail.com Fri Jan 30 15:32:00 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 30 Jan 2009 13:32:00 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <498363C0.5070909@gmail.com> Veerendra Ganiger wrote: > Python is not purely object oriented programming, because we can write > functions without any class. > You are right, predefined class attributes are available when we write or > execute a piece of python code without defining class, that means it's just > using objects for it's purpose. It does not mean its purely object oriented. To be clear, python does not force you to lay out your code according to some strict object-oriented paradigm. But Python itself is still purely object-oriented, as is your script when parsed. This function without a class that you mentioned, is in fact an object with attributes. You can pass a function around just like any other object. Even calling a function is invoked like so: myfunc.__call__(params) So necessitating that code be inside a class has nothing to do with object-oriented programming. Let's not forget that classes are themselves objects (metaobjects in smalltalk parlance if I recall correctly). Now python does not have any way besides lambda expressions of creating unbound function objects, but in practice this doesn't matter as I can rebind names freely. I can still do: a=myfunc myfunc=some other expression or object > It all depends on implementation, I think even we can make "C" object > oriented with proper implementation. Indeed, any code based on gobject libraries can be object-oriented in design and function. From stefan_ml at behnel.de Fri Jan 30 15:40:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 30 Jan 2009 21:40:00 +0100 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <498365a0$0$31868$9b4e6d93@newsspool3.arcor-online.net> D'Arcy J.M. Cain wrote: > On Fri, 30 Jan 2009 15:46:33 +0200 > Justin Wyer wrote: >> $ find -name "*" -exec grep -nH "LF01" {} \; >> | cut -d ":" -f 1 | sort | uniq > > I know this isn't a Unix group but please allow me to suggest instead; > > $ grep -lR LF01 That's a very good advice. I had to pull some statistics from a couple of log files recently some of which were gzip compressed. The obvious Python program just eats your first CPU's cycles parsing data into strings while the disk runs idle, but using the subprocess module to spawn a couple of gzgrep's in parallel that find the relevant lines, and then using Python to extract and aggregate the relevant information from them does the job in no-time. Stefan From lists at cheimes.de Fri Jan 30 15:40:49 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 21:40:49 +0100 Subject: Get thread pid In-Reply-To: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: Alejandro schrieb: > Hi: > > I have Python program running under Linux, that create several > threads, and I want to now the corresponding PID of the threads. May I ask why you want to get the TID? You can't do anything useful with it. You can't kill a thread safely, neither from within Python nor from the outside world. thread.get_ident() gives you an id. On pthread based systems the function uses pthread_self(). For TLS, Python has builtin classes that are hooked into Python's internal threading system. From haag at lsu.edu Fri Jan 30 15:42:28 2009 From: haag at lsu.edu (Alaric Haag) Date: Fri, 30 Jan 2009 14:42:28 -0600 Subject: Odd syntactic NON-error? References: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> Message-ID: In article <20090130173948.12853.732928641.divmod.quotient.543 at henry.divmod.com>, Jean-Paul Calderone wrote: > On Fri, 30 Jan 2009 11:36:45 -0600, Alaric Haag wrote: > >Hello, > > > >I just noticed that I've been successfully importing a module I wrote > >which contains a class definition that begins with (docstring removed): > > > >class TDF(): > > def __init__(self, name='', mode=tscan. GP_NOCLOBBER): > > > >Note the "space" which shouldn't be here---^ > > The space is irrelevant. > > >>> object. __init__ > > >>> object.__init__ is object. __init__ > True > >>> > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list It strikes me as strange that Python (which I love btw) would be so loose in its syntax when "spaces matter" at the beginning of a line. I now see that a space could precede the period too, as in: x = foo . method() So, is the "secret" that the period is syntactically an "operator" like + or * ? From perfreem at gmail.com Fri Jan 30 15:44:07 2009 From: perfreem at gmail.com (perfreem at gmail.com) Date: Fri, 30 Jan 2009 12:44:07 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> Message-ID: <0e855f75-9159-4b28-a153-ec6cb0d84fb2@g1g2000pra.googlegroups.com> On Jan 28, 6:08?pm, Aaron Brady wrote: > On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > > > On Jan 28, 5:14?pm, John Machin wrote: > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > hello all, > > > > > i have a large dictionary which contains about 10 keys, each key has a > > > > value which is a list containing about 1 to 5 million (small) > > > > dictionaries. for example, > > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > > 'world'}, ...], > > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > > in total there are about 10 to 15 million lists if we concatenate > > > > together all the values of every key in 'mydict'. mydict is a > > > > structure that represents data in a very large file (about 800 > > > > megabytes). > > snip > > > in reply to the other poster: i thought 'shelve' simply calls pickle. > > if thats the case, it wouldnt be any faster, right ? > > Yes, but not all at once. ?It's a clear winner if you need to update > any of them later, but if it's just write-once, read-many, it's about > the same. > > You said you have a million dictionaries. ?Even if each took only one > byte, you would still have a million bytes. ?Do you expect a faster I/ > O time than the time it takes to write a million bytes? > > I want to agree with John's worry about RAM, unless you have several+ > GB, as you say. ?You are not dealing with small numbers. in my case, i just write the pickle file once and then read it in later. in that case, cPickle and shelve would be identical, if i understand correctly? the file i'm reading in is ~800 MB file, and the pickle file is around 300 MB. even if it were 800 MB, it doesn't make sense to me that python's i/o would be that slow... it takes roughly 5 seconds to write one megabyte of a binary file (the pickled object in this case), which just seems wrong. does anyone know anything about this? about how i/o can be sped up for example? the dictionary might have a million keys, but each key's value is very small. i tried the same example where the keys are short strings (and there are about 10-15 million of them) and each value is an integer, and it is still very slow. does anyone know how to test whether i/o is the bottle neck, or whether it's something specific about pickle? thanks. From david at abbottdavid.com Fri Jan 30 15:50:55 2009 From: david at abbottdavid.com (David) Date: Fri, 30 Jan 2009 15:50:55 -0500 Subject: Rounding to the nearest 5 In-Reply-To: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> References: <8C2B20C4348091499673D86BF10AB6762F5DD8C193@clipper.glosten.local> Message-ID: <4983682F.70108@abbottdavid.com> Benjamin J. Racine wrote: > Doesn't this work? > > round_by_5.py > > > import sys > > def round_by_5(x= sys.argv[0]): > x = x/5. > x = round(x) > x = x*5 > print(x) > return x > > Ben R. I am learning, I got this to work fine; #!/usr/bin/python import sys def round_by_5(x = sys.argv[1]): x = int(x)/5 x = round(x) x = x*5 print int(x) round_by_5(sys.argv[1]) -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From stefan_ml at behnel.de Fri Jan 30 15:51:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 30 Jan 2009 21:51:28 +0100 Subject: search speed In-Reply-To: <6uft9aFf9kgbU1@mid.uni-berlin.de> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: <49836850$0$31877$9b4e6d93@newsspool3.arcor-online.net> Diez B. Roggisch wrote: > that's not necessarily the best thing to do if things have a > record-like structure. The canonical answer to this is then to use a > database to hold the data, instead of flat files. So if you have any > chance to do that, you should try & stuff things in there. It's worth mentioning to the OP that Python has a couple of database libraries in the stdlib, notably simple things like the various dbm flavoured modules (see the anydbm module) that provide fast string-to-string hash mappings (which might well be enough in this case), but also a pretty powerful SQL database called sqlite3 which allows much more complex (and complicated) ways to find the needle in the haystack. http://docs.python.org/library/persistence.html Stefan From lists at cheimes.de Fri Jan 30 15:54:31 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jan 2009 21:54:31 +0100 Subject: is python Object oriented?? In-Reply-To: <498363C0.5070909@gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <498363C0.5070909@gmail.com> Message-ID: Michael Torrie schrieb: >> It all depends on implementation, I think even we can make "C" object >> oriented with proper implementation. > > Indeed, any code based on gobject libraries can be object-oriented in > design and function. The Python C API is a good example for well designed and object oriented C code. Christian From stef.mientki at gmail.com Fri Jan 30 15:59:34 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 30 Jan 2009 21:59:34 +0100 Subject: verilog like class w/ bitslicing & int/long classtype In-Reply-To: <6uf1djFengojU2@mid.uni-berlin.de> References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> Message-ID: <49836A36.5000809@gmail.com> Marc 'BlackJack' Rintsch wrote: > On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > > >> try this: >> >> class MyRegClass ( int ) : >> def __init__ ( self, value ) : >> self.Value = value >> def __repr__ ( self ) : >> line = hex ( self.Value ) >> line = line [:2] + line [2:].upper() >> return line >> > > def __repr__(self): > return '0x%X' % self.value > > >> __str__ = __repr__ >> > > This is unnecessary, the fallback of `__str__` is `__repr__` already. > > well this is what my Python is doing: without _str__ = __repr__ >>print shadow_register 170 with _str__ = __repr__ >>print shadow_register 0xAA cheers, Stef From simon at brunningonline.net Fri Jan 30 16:12:04 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 30 Jan 2009 21:12:04 +0000 Subject: Odd syntactic NON-error? In-Reply-To: References: <20090130173948.12853.732928641.divmod.quotient.543@henry.divmod.com> Message-ID: <8c7f10c60901301312h4f967f48ycd0d32309a427e7a@mail.gmail.com> 2009/1/30 Alaric Haag : > So, is the "secret" that the period is syntactically an "operator" like > + or * ? Exactly that: . Shhhhh! -- Cheers, Simon B. From Scott.Daniels at Acm.Org Fri Jan 30 16:36:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 13:36:28 -0800 Subject: relpath problem on windows In-Reply-To: References: Message-ID: <3b-dnR645qzp7x7UnZ2dnUVZ_jWWnZ2d@pdx.net> eliben wrote: > I'm having a problem with 2.6's new os.path.relpath function. > ... But this isn't [correct]: > relpath(r'd:\jho', r'd:\\') > => '..\jho' > Neither is this: > relpath(r'd:\jho', r'd:') > => '..\..\..\jho' > > What am I missing? There is no way to write a raw string for text ending in a single backslash. r'd:\\' == 'd:\\\\' What you want is relpath(r'd:\jho', 'd:\\') But it turns out this doesn't work, either. File a bug. --Scott David Daniels Scott.Daniels at Acm.Org From tjreedy at udel.edu Fri Jan 30 16:39:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Jan 2009 16:39:45 -0500 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> <7a9c25c20901300858n529aa110rb8d1a88a6b440b04@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Fri, Jan 30, 2009 at 12:38 AM, r Personally, I work for a division in our company that has converted over > the last few years our entire software line from an old, Windows-only > mix of C and VCL-stuff, to a serious mid-sized product which recently > clocked in at about 165k lines of Python code (about 600k more in third > party libs!) that's fast, effective, flexible, multi-platform and highly > responsive to our customer's evolving needs. We actually did a complete > rewrite from the ground up -- a dangerous thing to do, but the legacy > product was so out of date that it had to be done... and I don't think > any other set of tools would have been able to let us do so as well, in > as short of a period of time, or as iteratively and in cooperation with > our customer base. Thank you for sharing this. If it has not been already, could this be shared as a Python success story on the site? (With proprietary detail omitted as needed for approval, of course.) tjr From tjreedy at udel.edu Fri Jan 30 16:47:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Jan 2009 16:47:01 -0500 Subject: What's new in 3.0 about threading? In-Reply-To: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> References: <78c6befa0901300919x23a691ap7adaee9557195aa3@mail.gmail.com> Message-ID: ?? wrote: > Hello > I have questions about threading: > > import threading > class myThread(threading.Thread): > def run(self): > print('hello,threads') > if __name__=='__main__': > threads=myThread() > threads.start() > > Above program does't work at 'Run Module' in IDLE, What does 'doesn't work' mean? If you get an error traceback, post it. Possible problem: IDLE runs on top of pythonw.exe (not python.exe) which does not open a window (IDLE runs its own window). So I would not be surprised if output from separate thread in pythonw process gets lost. If that is the problem, try having the run() method send something back to the main thread, say through a Queue, and print from there after starting the subthread. > but it works well > under executing scripts.Is it anything wrong? > WindowXP,Python 3.0 > Thanks. > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From ntwrkd at gmail.com Fri Jan 30 17:20:40 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:20:40 -0800 Subject: accessing elements of a tuple Message-ID: i am trying to access elements of a tuple without using the [1:5] notation. the contents of the tuple are as follows: ('--datasourcename', 'DB') I want to access everything in the second argument, but i am not sure how to go about this without converting to a string. thanks in advance From ntwrkd at gmail.com Fri Jan 30 17:23:31 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:23:31 -0800 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: let me re-phrase that question: i would like to access the element of individual tuples inside of a list, by using an index. so i have the list contents print list [('--datasourcename', 'DB'), ('--password', '123')] How can I access "DB" from the list directly using an index? right now I would have to grab the tuple and the use the index of the tuple On Fri, Jan 30, 2009 at 2:20 PM, Matthew Sacks wrote: > i am trying to access elements of a tuple without using the [1:5] notation. > the contents of the tuple are as follows: > ('--datasourcename', 'DB') > > I want to access everything in the second argument, but i am not sure > how to go about this without converting to a string. > > thanks in advance > From robert.kern at gmail.com Fri Jan 30 17:25:13 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 30 Jan 2009 16:25:13 -0600 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <02562a80-f391-4881-88cc-dd6cddcf70e6@e18g2000yqo.googlegroups.com> <8362baf9-9c72-4263-a91a-49c9517f06f1@y23g2000pre.googlegroups.com> Message-ID: On 2009-01-29 18:22, Reckoner wrote: > I haven't looked at Enthought in awhile. I want to avoid having to > installing the entire Enthought toolsuite, however. Would I have to > do that for Traits? No, Traits can be installed by itself unless if you want its GUI capabilities. http://pypi.python.org/pypi/Traits -- 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 arequipeno at gmail.com Fri Jan 30 17:32:44 2009 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 30 Jan 2009 16:32:44 -0600 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: Matthew Sacks wrote: > How can I access "DB" from the list directly using an index? list[0][1] ... or did I misunderstand your question? -- ======================================================================== Ian Pilcher arequipeno at gmail.com ======================================================================== From darcy at druid.net Fri Jan 30 17:34:23 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 30 Jan 2009 17:34:23 -0500 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: <20090130173423.37837d7e.darcy@druid.net> On Fri, 30 Jan 2009 14:23:31 -0800 Matthew Sacks wrote: > let me re-phrase that question: > i would like to access the element of individual tuples inside of a > list, by using an index. > so i have the list contents > > print list > [('--datasourcename', 'DB'), ('--password', '123')] > > How can I access "DB" from the list directly using an index? First of all, list is a reserved word. Don't use it as a variable name. mylist[0][1] if I understand the question. I don't know what you are trying to accomplish but is this snippet useful? opts = dict([(x[0][2:], x[1]) for x in mylist if x[0][:2] == '--']) print opts['datasourcename'] -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Fri Jan 30 17:36:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 30 Jan 2009 17:36:49 -0500 Subject: Does the Python community really follow the philospy of "Community Matters?" In-Reply-To: <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> Message-ID: Ivan Illarionov wrote: > r wrote: >> Where are the community projects supporting Python? -- besides the >> core devlopment. Seem s that nobody is interested unless their pay-pal >> account is involved. I find this all quite disappointing. > > Hi r, > > Can you just type > > import antigravity > > and join us up there? > > Hatred for Ruby and Perl seems to oppose natural Python forces, > that's why you can't see community spirit. Let your hatred go and > start > flying already. > Indeed. What r has not yet grasped is that to be in favor of one thing you don't necessarily have to be against everything else. For example, if it hadn't been for generous help from the Perl community (as represented by http://www.yapc.org/) the first PyCon would never have got off the ground. The competition between languages for the attention of programmers isn't a zero-sum game. I think there has perhaps been some slight decrease in the tolerance level as expressed on this list over the last couple of years, but I don't think it's (yet) anything to be concerned about. It's mostly a matter of teaching by example. I'd like to think I usually set a good example, but I've certainly been known to get crabby from time to time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Fri Jan 30 17:39:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 16:39:39 -0600 Subject: accessing elements of a tuple In-Reply-To: References: Message-ID: <498381AB.3030907@tim.thechases.com> > let me re-phrase that question: > i would like to access the element of individual tuples inside of a > list, by using an index. > so i have the list contents > > print list > [('--datasourcename', 'DB'), ('--password', '123')] > > How can I access "DB" from the list directly using an index? > > right now I would have to grab the tuple and the use the index of the tuple Well, you can use lst[0][1] to get it. Or, if you're parsing through the list, you can use tuple unpacking: for name, value in lst: print "%s = %s" % (name, value) As an aside, it looks like you're doing parameter parsing. The standard library has the optparse module which takes a lot of pain out of parsing parameters. -tkc From ntwrkd at gmail.com Fri Jan 30 17:42:48 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 14:42:48 -0800 Subject: accessing elements of a tuple In-Reply-To: <498381AB.3030907@tim.thechases.com> References: <498381AB.3030907@tim.thechases.com> Message-ID: >First of all, list is a reserved word. Don't use it as a variable name. I was using it as an example in this case. >mylist[0][1] if I understand the question. This works. Thank you. On Fri, Jan 30, 2009 at 2:39 PM, Tim Chase wrote: >> let me re-phrase that question: >> i would like to access the element of individual tuples inside of a >> list, by using an index. >> so i have the list contents >> >> print list >> [('--datasourcename', 'DB'), ('--password', '123')] >> >> How can I access "DB" from the list directly using an index? >> >> right now I would have to grab the tuple and the use the index of the >> tuple > > Well, you can use > > lst[0][1] > > to get it. Or, if you're parsing through the list, you can use tuple > unpacking: > > for name, value in lst: > print "%s = %s" % (name, value) > > As an aside, it looks like you're doing parameter parsing. The standard > library has the optparse module which takes a lot of pain out of parsing > parameters. > > -tkc > > > > From jervisau at gmail.com Fri Jan 30 18:42:57 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 10:42:57 +1100 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <8e63a5ce0901301542i5f220ey574431da390437bc@mail.gmail.com> > > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) > If the files you are searching are located at some other location on a network, you may find that much of the 5 minutes is actually the network delay in fetching each file. (Although you said something about your dir being cached?) Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntwrkd at gmail.com Fri Jan 30 18:43:19 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 15:43:19 -0800 Subject: problem with program - debugging leading nowhere Message-ID: i am trying to figure out what has gone wrong in my python program. it is complaining that there is an indendation error. should be simple enough but im stuck on this one. if anyone can help unjolt me it would be appreciated. thank you error message: Traceback (most recent call last): File "", line 1, in IndentationError: expected an indented block (, line 39) code: http://pastebin.com/f2f971f91 From jervisau at gmail.com Fri Jan 30 18:59:24 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 10:59:24 +1100 Subject: problem with program - debugging leading nowhere In-Reply-To: References: Message-ID: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> > > > > error message: > Traceback (most recent call last): > File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code: > http://pastebin.com/f2f971f91 > Hi, It looks like you have commented out a line on line 30, you need to place something in here, as python is expecting an indented level after your 'if'. (how about a pass statement or a print saying some placeholder help details.) On a side note, I've only had a quick skim, you shouldn't compare o to an empty string "" using the 'is', is tests identity not equality. So what you are saying is is o the exact same empty string that I am creating "" (obviously it never will be, because you just created it then with "") . Use the equality operator == instead. or in your case !=. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From jervisau at gmail.com Fri Jan 30 19:00:05 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Sat, 31 Jan 2009 11:00:05 +1100 Subject: problem with program - debugging leading nowhere In-Reply-To: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> References: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> Message-ID: <8e63a5ce0901301600o5de06121k9635a65b1a28fe0f@mail.gmail.com> ---------- Forwarded message ---------- From: Jervis Whitley Date: Sat, Jan 31, 2009 at 10:59 AM Subject: Re: problem with program - debugging leading nowhere To: Matthew Sacks Cc: python-list at python.org > > > > error message: > Traceback (most recent call last): > File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code: > http://pastebin.com/f2f971f91 > Hi, It looks like you have commented out a line on line 30, you need to place something in here, as python is expecting an indented level after your 'if'. (how about a pass statement or a print saying some placeholder help details.) On a side note, I've only had a quick skim, you shouldn't compare o to an empty string "" using the 'is', is tests identity not equality. So what you are saying is is o the exact same empty string that I am creating "" (obviously it never will be, because you just created it then with "") . Use the equality operator == instead. or in your case !=. Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurgenex at hotmail.com Fri Jan 30 19:01:50 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 30 Jan 2009 16:01:50 -0800 Subject: Function Application is not Currying References: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com> <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet> Message-ID: Jon Harrop wrote: >I had hoped someone else would correct you but they haven't. So... That is because ... >Xah Lee wrote: ... everyone with more than 5 cents of brain has killfiled him a long time ago. jue From aahz at pythoncraft.com Fri Jan 30 19:11:42 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 16:11:42 -0800 Subject: Swapping values of two variables References: Message-ID: In article , Eric Kang wrote: > >In python, I set: > >x=1 >y=3 > >z = x >x = y >y = z > > >This gave me 3 1, which are the values of x and y swapped. >The following would have given me the same result: >x, y = y, x > > > >But could the swapping be done using less extra memory than this? What >is the minimum amount of extra memory required to exchange two 32-bit >quantities? What would be the pseudocode that achieves this minimum? This looks like a homework problem to me.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From sjmachin at lexicon.net Fri Jan 30 19:14:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 16:14:58 -0800 (PST) Subject: problem with program - debugging leading nowhere References: Message-ID: <5006c00c-af2c-45a7-96d9-4f45a27736ef@t26g2000prh.googlegroups.com> On Jan 31, 10:43?am, Matthew Sacks wrote: > i am trying to figure out what has gone wrong in my python program. it > is complaining that there is an indendation error. should be simple > enough but im stuck on this one. if anyone can help unjolt me it would > be appreciated. > > thank you > > error message: > Traceback (most recent call last): > ? File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code:http://pastebin.com/f2f971f91 How are you running that? All that stuff is not very informative. I put your source into a pastebin.py: >>> import pastebin Traceback (most recent call last): File "", line 1, in File "pastebin.py", line 31 elif o is not "": ^ IndentationError: expected an indented block Dunno how you managed line 39. What you have there is: for o, a in optlist: if o == "-h": #usage() elif o is not "": which is equivalent to: for o, a in optlist: if o == "-h": elif o is not "": which is not such a good idea. BTW, why aren't you using optparse? HTH, John From sjmachin at lexicon.net Fri Jan 30 19:19:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 16:19:19 -0800 (PST) Subject: accessing elements of a tuple References: <498381AB.3030907@tim.thechases.com> Message-ID: <44365ba1-cbac-4965-ac4a-788872a5cc0d@r10g2000prf.googlegroups.com> On Jan 31, 9:42?am, Matthew Sacks wrote: > >First of all, list is a reserved word. ?Don't use it as a variable name. > > I was using it as an example in this case. > > >mylist[0][1] if I understand the question. > > This works. Thank you. > > On Fri, Jan 30, 2009 at 2:39 PM, Tim Chase > > wrote: > >> let me re-phrase that question: > >> i would like to access the element of individual tuples inside of a > >> list, by using an index. > >> so i have the list contents > > >> print list > >> [('--datasourcename', 'DB'), ('--password', '123')] > > >> How can I access "DB" from the list directly using an index? > > >> right now I would have to grab the tuple and the use the index of the > >> tuple > > > Well, you can use > > > ?lst[0][1] But that sort of code rapidly becomes unreadable. Unpacking the list and unpacking the tuple into named components will be more understandable when you revisit the code. From bignose+hates-spam at benfinney.id.au Fri Jan 30 19:22:26 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 11:22:26 +1100 Subject: problem with program - debugging leading nowhere References: Message-ID: <87k58cz5ml.fsf@benfinney.id.au> Matthew Sacks writes: > i am trying to figure out what has gone wrong in my python program. it > is complaining that there is an indendation error. should be simple > enough but im stuck on this one. if anyone can help unjolt me it would > be appreciated. Step one: Ensure the problem doesn't get worse. Set your text editor to use spaces for indentation and to *never* put an ASCII TAB character (U+0009) into your source code. They are, by default, invisibly indistinguishable from a sequence of spaces, and completely unnecessary. Step two: Run your program with ?python -t? instead of ?python?, to determine if your problem in this instance is caused by using TAB characters for indentation. Step three: When asking people to help with understanding an error message, it helps to post the actual (complete) error message :-) -- \ ?Sittin' on the fence, that's a dangerous course / You can even | `\ catch a bullet from the peace-keeping force? ?Dire Straits, | _o__) _Once Upon A Time In The West_ | Ben Finney From ntwrkd at gmail.com Fri Jan 30 19:31:40 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 30 Jan 2009 16:31:40 -0800 Subject: problem with program - debugging leading nowhere In-Reply-To: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> References: <8e63a5ce0901301559k74397c21u9ab5ee8a9ee1bf9b@mail.gmail.com> Message-ID: this works. thanks! On Fri, Jan 30, 2009 at 3:59 PM, Jervis Whitley wrote: > > >> >> >> >> >> error message: >> Traceback (most recent call last): >> File "", line 1, in >> IndentationError: expected an indented block (, line 39) >> >> code: >> http://pastebin.com/f2f971f91 > > Hi, > > It looks like you have commented out a line on line 30, you need to place > something > in here, as python is expecting an indented level after your 'if'. (how > about a pass statement or a print saying some placeholder help details.) > > On a side note, I've only had a quick skim, you shouldn't compare o to an > empty string "" using the 'is', is tests identity not equality. So what you > are saying is > is o the exact same empty string that I am creating "" (obviously it never > will be, because you just created it then with "") . Use the equality > operator == instead. > or in your case !=. > > Cheers, > > From steve at holdenweb.com Fri Jan 30 19:35:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 30 Jan 2009 19:35:40 -0500 Subject: Adding a positive number and a negative number In-Reply-To: References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: Scott David Daniels wrote: > Grant Edwards wrote: >> On 2009-01-30, MRAB wrote: >>> Eric Kang wrote: >>>> In two's complement representation, can adding one positive >>>> and one negative give you overflow? >>> No. >> AFAIK, in Python adding integers never gives you overlow >> regardless of sign. > > Right, but he wants his homework answer. And Python doesn't use pure two's complement notation when it promotes regular integers to longs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bignose+hates-spam at benfinney.id.au Fri Jan 30 19:37:09 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 11:37:09 +1100 Subject: problem with program - debugging leading nowhere References: <87k58cz5ml.fsf@benfinney.id.au> Message-ID: <87fxj0z4y2.fsf@benfinney.id.au> Ben Finney writes: > Step three: When asking people to help with understanding an error > message, it helps to post the actual (complete) error message :-) My apologies, you did provide this and I missed it. -- \ ?One time I went to a drive-in in a cab. The movie cost me | `\ ninety-five dollars.? ?Steven Wright | _o__) | Ben Finney From castironpi at gmail.com Fri Jan 30 19:47:50 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 30 Jan 2009 16:47:50 -0800 (PST) Subject: writing large dictionaries to file using cPickle References: <1b5aa751-84dd-46ab-b922-c58493fc0a2e@v5g2000prm.googlegroups.com> <6fc0a97d-23b8-4645-8e8c-0291782cec5f@v5g2000prm.googlegroups.com> <74b49e90-9308-4aa5-a862-aac657022e6c@r15g2000prh.googlegroups.com> <0e855f75-9159-4b28-a153-ec6cb0d84fb2@g1g2000pra.googlegroups.com> Message-ID: On Jan 30, 2:44?pm, perfr... at gmail.com wrote: > On Jan 28, 6:08?pm, Aaron Brady wrote: > > > > > On Jan 28, 4:43?pm, perfr... at gmail.com wrote: > > > > On Jan 28, 5:14?pm, John Machin wrote: > > > > > On Jan 29, 3:13?am, perfr... at gmail.com wrote: > > > > > > hello all, > > > > > > i have a large dictionary which contains about 10 keys, each key has a > > > > > value which is a list containing about 1 to 5 million (small) > > > > > dictionaries. for example, > > > > > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f': > > > > > 'world'}, ...], > > > > > ? ? ? ? ? ? ? ? key2: [...]} > > > > > > in total there are about 10 to 15 million lists if we concatenate > > > > > together all the values of every key in 'mydict'. mydict is a > > > > > structure that represents data in a very large file (about 800 > > > > > megabytes). > > > snip > > > > in reply to the other poster: i thought 'shelve' simply calls pickle. > > > if thats the case, it wouldnt be any faster, right ? > > > Yes, but not all at once. ?It's a clear winner if you need to update > > any of them later, but if it's just write-once, read-many, it's about > > the same. > > > You said you have a million dictionaries. ?Even if each took only one > > byte, you would still have a million bytes. ?Do you expect a faster I/ > > O time than the time it takes to write a million bytes? > > > I want to agree with John's worry about RAM, unless you have several+ > > GB, as you say. ?You are not dealing with small numbers. > > in my case, i just write the pickle file once and then read it in > later. in that case, cPickle and shelve would be identical, if i > understand correctly? No not identical. 'shelve' is not a dictionary, it's a database object that implements the mapping protocol. 'isinstance( shelve, dict )' is False, for example. > the file i'm reading in is ~800 MB file, and the pickle file is around > 300 MB. even if it were 800 MB, it doesn't make sense to me that > python's i/o would be that slow... it takes roughly 5 seconds to write > one megabyte of a binary file (the pickled object in this case), which > just seems wrong. does anyone know anything about this? about how i/o > can be sped up for example? You can try copying a 1-MB file. Or something like: f= open( 'temp.temp', 'w' ) for x in range( 100000 ): f.write( '0'* 10 ) You know how long it takes OSes to boot, right? > the dictionary might have a million keys, but each key's value is very > small. i tried the same example where the keys are short strings (and > there are about 10-15 million of them) and each value is an integer, > and it is still very slow. does anyone know how to test whether i/o is > the bottle neck, or whether it's something specific about pickle? > > thanks. You could fall back to storing a parallel list by hand, if you're just using string and numeric primitives. From alan.isaac at gmail.com Fri Jan 30 20:15:11 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 31 Jan 2009 01:15:11 GMT Subject: naming and binding (subtle Python 3 change) In-Reply-To: References: Message-ID: On 1/29/2009 10:50 PM Terry Reedy apparently wrote: > http://bugs.python.org/issue5106 Thanks! Alan From vincent at vincentdavis.net Fri Jan 30 20:33:29 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 30 Jan 2009 18:33:29 -0700 Subject: question about Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)] Message-ID: <77e831100901301733s4ebe3ca7i251a79955894f00e@mail.gmail.com> Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)] I am not sure how to ask this but which "for" is looped first? I could test but was wondering if there was a nice explanation I could apply to future situations. Thanks Vincent Davis 720-301-3003 From grante at visi.com Fri Jan 30 20:35:03 2009 From: grante at visi.com (Grant Edwards) Date: Fri, 30 Jan 2009 19:35:03 -0600 Subject: Swapping values of two variables References: Message-ID: <5Yidnf3R_pdaNx7UnZ2dnUVZ_qrinZ2d@posted.usinternet> On 2009-01-31, Aahz wrote: >>But could the swapping be done using less extra memory than this? What >>is the minimum amount of extra memory required to exchange two 32-bit >>quantities? What would be the pseudocode that achieves this minimum? > > This looks like a homework problem to me.... It looks 100% like a homework problem. -- Grant From hungvn94 at gmail.com Fri Jan 30 20:35:09 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Sat, 31 Jan 2009 12:35:09 +1100 Subject: is python Object oriented?? In-Reply-To: <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <50697b2c0901292215j6f21d376p37d0cf5f9a66d10a@mail.gmail.com> Message-ID: <139bf30a0901301735v7cd6f794x20fc6d96592d9b43@mail.gmail.com> On Fri, Jan 30, 2009 at 5:15 PM, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > > > I'm new to Python and also wondering about OOP in Python. > > > > I want to justify the above question (is Python Object-Oriented?). > > Does Python follow the concepts/practices of Encapsulation, > > Polymorphism and Interface, which are quite familiar to Java > > programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. I was introduced to OOP via C++/Java, so its quite nature to compare and contrast with the languages you know even they seem not to be original. I definitely will learn about Smalltalk. > > Anyway, to your three-pronged question: > - Yes, Python supports polymorphism. I find it hard to think of an > example of an OO language that doesn't. > > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. See http://en.wikipedia.org/wiki/Duck_typing Its seem to me that duck typing is a special case of static vs dynamic type debate and clearly Python is a dynamic type philoshopy's follower. > > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here". This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. I like the flexibility of not being enforced to the encapsulation rules, however, you're right, we do at our own risk and have to tradeoff the flexibility with the secure a static type system like Java provides. P.S. You appear to have posted the same message 3 times(!), which is a > bit annoying for readers. sorry for this annoyance. I dont know why a new post was made whenever i cliked on the topic link. Probably, there's something wrong with google group. on investigating... > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jan 30 21:41:45 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 18:41:45 -0800 (PST) Subject: Adding a positive number and a negative number References: <1930858547.1054291233288832516.JavaMail.root@jaguar10.sfu.ca> <8_KdnY1_mekHjx7UnZ2dnUVZ_rDinZ2d@posted.visi> Message-ID: <29357024-3a33-4f66-b639-8264e6cea69a@r41g2000prr.googlegroups.com> On Jan 31, 4:10?am, Scott David Daniels wrote: > Grant Edwards wrote: > > On 2009-01-30, MRAB wrote: > >> Eric Kang wrote: > >>> In two's complement representation, can adding one positive > >>> and one negative give you overflow? > >> No. > > AFAIK, in Python adding integers never gives you overlow > > regardless of sign. > > Right, but he wants his homework answer. For extra brownie points, here's a simple proof of the more general proposition that adding a non-negative integer p and a non-positive integer n can't overflow whatever the representation. Let a be the most negative integer and b the most positive. So we're given a <= n <= 0 <= p <= b and need to show that a <= (p + n) <= b. max(p) is b, max(n) is 0, so max(p + n) is b. Similarly min(p + n) is a. Q.E.D. IEEE 754 floating point? I don't know. Go read the standard :-) From timro21 at gmail.com Fri Jan 30 21:45:27 2009 From: timro21 at gmail.com (Tim) Date: Sat, 31 Jan 2009 12:45:27 +1000 Subject: nth root Message-ID: In PythonWin I'm running a program to find the 13th root (say) of millions of hundred-digit numbers. I'm using n = 13 root = base**(1.0/n) which correctly computes the root to a large number of decimal places, but therefore takes a long time. All I need is the integer component. Is there a quicker way? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ianand0204 at gmail.com Fri Jan 30 21:59:17 2009 From: ianand0204 at gmail.com (flagg) Date: Fri, 30 Jan 2009 18:59:17 -0800 (PST) Subject: SimpleXMLRPCServer question Message-ID: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> I am working on a very basic xmlrpc server, which will expose certain functions for administering BIND zone files. The big problem I am having is parsing the incoming xmlrpc request. Basically part of the xmlrpc request will help deterime which zone file is edited. I have been looking at the do_POST() method from SimpleXMLRPCDispatcher and it seems like I could code something which overides that method, however I am new to programming am at a loss, i might even be making this tougher than it needs to be. Is there a way to parse the incoming xmlrpc request before the function it is calling is executed? From rdmurray at bitdance.com Fri Jan 30 22:14:41 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 03:14:41 +0000 (UTC) Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> <49836A36.5000809@gmail.com> Message-ID: Quoth Stef Mientki : > Marc 'BlackJack' Rintsch wrote: > > On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: > > > > > >> try this: > >> > >> class MyRegClass ( int ) : > >> def __init__ ( self, value ) : > >> self.Value = value > >> def __repr__ ( self ) : > >> line = hex ( self.Value ) > >> line = line [:2] + line [2:].upper() > >> return line > >> > > > > def __repr__(self): > > return '0x%X' % self.value > > > > > >> __str__ = __repr__ > >> > > > > This is unnecessary, the fallback of `__str__` is `__repr__` already. > > > > > well this is what my Python is doing: > > without _str__ = __repr__ > >>print shadow_register > 170 > > with _str__ = __repr__ > >>print shadow_register > 0xAA >>> '__str__' in dir(170) True That is, the superclass (int) has an __str__, so you have to override it. --RDM From google at mrabarnett.plus.com Fri Jan 30 22:31:34 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 31 Jan 2009 03:31:34 +0000 Subject: nth root In-Reply-To: References: Message-ID: <4983C616.3000207@mrabarnett.plus.com> Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > Have you tried an iterative approach? def root_13(x): step = 1 while step ** 13 < x: step *= 2 root = 0 while step: if (root + step) ** 13 <= x: root += step step //= 2 return root Probably not that fast in Python, though. numpy or psyco might help. From t.roberts at cqu.edu.au Fri Jan 30 23:00:09 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sat, 31 Jan 2009 14:00:09 +1000 Subject: nth root References: <4983C616.3000207@mrabarnett.plus.com> Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? Tim Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > Have you tried an iterative approach? def root_13(x): step = 1 while step ** 13 < x: step *= 2 root = 0 while step: if (root + step) ** 13 <= x: root += step step //= 2 return root Probably not that fast in Python, though. numpy or psyco might help. -- http://mail.python.org/mailman/listinfo/python-list From rdmurray at bitdance.com Fri Jan 30 23:01:05 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:01:05 +0000 (UTC) Subject: Importing modules References: <638826d0-c8b1-4991-a5d6-9aacfbd20c07@e1g2000pra.googlegroups.com> <46b98e02-4c0f-4e4f-ba15-f6e5b39b03fa@l33g2000pri.googlegroups.com> <86a336c4-66d1-4420-8f0e-d53b8d28085d@o40g2000prn.googlegroups.com> Message-ID: Quoth Mudcat : > [attribution omitted by Mudcat] > > I think you've probably had issues with circular imports (i.e. mutual > > dependencies), unless you can precisely remember what you were doing and > > what went wrong. > > That's possible, but circular imports become more of a hazard if you > have to import in several locations. Unify that to one file, and those > problems are much easier to avoid. Personally I've never run into circular import problems when importing library functions. Then, again, I always use 'from x import y' (or 'y as z' for those modules that use non-unique names for things, like os.path.split). Where I've run into circular import problems when when _my_ modules were circularly importing things. Which just meant that my code needed some refactoring. > > I can make up three or four different logical groupings in my > > applications... so what is 'logical' could not be the same for everyone, > > or from every point of view. > > That's not the point. The point is that multiple imports can be a > limiting factor if the module imports don't happen to align with the > model they'd like to use for their file layout. I'm inclined to agree with you that organizing code around which other modules it imports is (usually) not the optimal organization. But it is worth _considering_, because sometimes it does reveal a useful pattern to refactor by. > However playing around with the files, I guess it is possible to > create a file that just does imports and then reference them all just > like you would any other extension of the namespace. I created a file > called imports and was able to access the sys module within it by > importing all from imports and calling sys. That way at least all you > have to do is import the one file each time. If you are talking about making a file and then doing from X import *, I'd shudder a little bit looking at such code. It just doesn't feel like the python way :). Which doesn't mean you shouldn't do it, if it works for you, it is more of a personal preference thing. What I'd respond to better (and I almost started doing this in my code...but it's more typing so in the end I didn't) is to have a module, say 'lib', and just do 'import lib'. Then everything is called through 'lib': lib.os.path.split('/some/path'), etc, etc. The difference is that that is explicit. If I'm reading your code and I see that, I look at the top and I see the import for 'lib', and I know to look for a lib module. If you use the from X import * pattern, I lose that ability. Sure, I can look at the top, and see the 'from X import *', and if that's the only 'from *' import I can guess that the functions not defined in the file come from that one...but all of that takes more brain cycles. It just doesn't feel as clean :) But, in the end, it is mostly personal preference. I'm sure there are Pythonistas out there whose lips will curl when seeing 'from os.path import split as pathsplit, join as pathjoin' in my code :) --RDM From tim at thechases.com Fri Jan 30 23:12:03 2009 From: tim at thechases.com (Tim Chase) Date: Fri, 30 Jan 2009 22:12:03 -0600 Subject: search speed In-Reply-To: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> Message-ID: <4983CF93.3040002@thechases.com> > I have written a Python program that serach for specifik customer in > files (around 1000 files) > the trigger is LF01 + CUSTOMERNO While most of the solutions folks have offered involve scanning all the files each time you search, if the content of those files doesn't change much, you can build an index once and then query the resulting index multiple times. Because I was bored, I threw together the code below (after the "-------" divider) which does what you detail as best I understand, allowing you to do python tkc.py 31415 to find the files containing CUSTOMERNO=31415 The first time, it's slow because it needs to create the index file. However, subsequent runs should be pretty speedy. You can also specify multiple customers on the command-line: python tkc.py 31415 1414 77777 and it will search for each of them. I presume they're found by the regexp "LF01(\d+)" based on your description, that the file can be sensibly broken into lines, and the code allows for multiple results on the same line. Adjust accordingly if that's not the pattern you want or the conditions you expect. If your source files change, you can reinitialize the database with python tkc.py -i You can also change the glob pattern used for indexing -- by default, I assumed they were "*.txt". But you can either override the default with python tkc.py -i -p "*.dat" or you can change the source to default differently (or even skip the glob-check completely...look for the fnmatch() call). There are a few more options. Just use python tkc.py --help as usual. It's also a simple demo of the optparse module if you've never used it. Enjoy! -tkc PS: as an aside, how do I import just the fnmatch function? I tried both of the following and neither worked: from glob.fnmatch import fnmatch from glob import fnmatch.fnmatch I finally resorted to the contortion coded below in favor of import glob fnmatch = glob.fnmatch.fnmatch ----------------------------------------------------------------- #!/usr/bin/env python import dbm import os import re from glob import fnmatch fnmatch = fnmatch.fnmatch from optparse import OptionParser customer_re = re.compile(r"LF01(\d+)") def build_parser(): parser = OptionParser( usage="%prog [options] [cust#1 [cust#2 ... ]]" ) parser.add_option("-i", "--index", "--reindex", action="store_true", dest="reindex", default=False, help="Reindex files found in the current directory " "in the event any files have changed", ) parser.add_option("-p", "--pattern", action="store", dest="pattern", default="*.txt", metavar="GLOB_PATTERN", help="Index files matching GLOB_PATTERN", ) parser.add_option("-d", "--db", "--database", action="store", dest="indexfile", default=".index", metavar="FILE", help="Use the index stored at FILE", ) parser.add_option("-v", "--verbose", action="count", dest="verbose", default=0, help="Increase verbosity" ) return parser def reindex(options, db): if options.verbose: print "Indexing..." for path, dirs, files in os.walk('.'): for fname in files: if fname == options.indexfile: # ignore our database file continue if not fnmatch(fname, options.pattern): # ensure that it matches our pattern continue fullname = os.path.join(path, fname) if options.verbose: print fullname f = file(fullname) found_so_far = set() for line in f: for customer_number in customer_re.findall(line): if customer_number in found_so_far: continue found_so_far.add(customer_number) try: val = '\n'.join([ db[customer_number], fullname, ]) if options.verbose > 1: print "Appending %s" % customer_number except KeyError: if options.verbose > 1: print "Creating %s" % customer_number val = fullname db[customer_number] = val f.close() if __name__ == "__main__": parser = build_parser() opt, args = parser.parse_args() reindexed = False if opt.reindex or not os.path.exists("%s.db" % opt.indexfile): db = dbm.open(opt.indexfile, 'n') reindex(opt, db) reindexed = True else: db = dbm.open(opt.indexfile, 'r') if not (args or reindexed): parser.print_help() for arg in args: print "%s:" % arg, try: val = db[arg] print for item in val.splitlines(): print " %s" % item except KeyError: print "Not found" db.close() From rdmurray at bitdance.com Fri Jan 30 23:12:41 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:12:41 +0000 (UTC) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: Quoth flagg : > I am working on a very basic xmlrpc server, which will expose certain > functions for administering BIND zone files. The big problem I am > having is parsing the incoming xmlrpc request. Basically part of the > xmlrpc request will help deterime which zone file is edited. I have > been looking at the do_POST() method from SimpleXMLRPCDispatcher and > it seems like I could code something which overides that method, > however I am new to programming am at a loss, i might even be making > this tougher than it needs to be. Is there a way to parse the > incoming xmlrpc request before the function it is calling is executed? Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead? It's been a while since I looked at XMLRPC, but why wouldn't you have a operation names, with the zone file to operate on as an argument? Then you'd just be defining your operations as methods on your SimpleXMLRPCServer, and they'd use the argument to determine which file to operate on. If that doesn't make sense, either I've forgotten how XMLRPC works, or you should explain your requirements a bit more. --RDM From rdmurray at bitdance.com Fri Jan 30 23:20:44 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:20:44 +0000 (UTC) Subject: More mod_wsgi weirdness: process restarts on redirect References: Message-ID: Quoth Ron Garret : > In article , > Joshua Kugler wrote: > > > Ron Garret wrote: > > > My question is: is this supposed to be happening? Or is this an > > > indication that something is wrong, and if so, what? > > > > You are probably just hitting a different instance of Apache, thus the > > different process ID. > > Yep, that's what it turned out to be. I thought I had a > WSGIDaemonProcess processes=1 directive in my config, but I had it in > the wrong place (a different vhost) so it wasn't actually active. > > But that leaves me wondering why the redirect would reliably trigger > switching processes. The reason I thought that I had the correct > configuration and only had one process is that when I reloaded the > non-redirected page I *always* got the same process ID. How does > mod_wsgi decide which process (and which thread for that matter) to use? My WAG would be that when doing a refresh your client used a persistent http connection, and thus talked again to the same Apache child, but when it got a redirect it dropped the old connection and opened up a new one, thus having a high probability of hitting a new child. But that is, as I say, a WAG. --RDM From rdmurray at bitdance.com Fri Jan 30 23:37:50 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 04:37:50 +0000 (UTC) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: Quoth Tim Chase : > PS: as an aside, how do I import just the fnmatch function? I > tried both of the following and neither worked: > > from glob.fnmatch import fnmatch > from glob import fnmatch.fnmatch > > I finally resorted to the contortion coded below in favor of > import glob > fnmatch = glob.fnmatch.fnmatch What you want is: from fnmatch import fnmatch fnmatch is its own module, it just happens to be in the (non __all__) namespace of the glob module because glob uses it. --RDM From aahz at pythoncraft.com Fri Jan 30 23:51:12 2009 From: aahz at pythoncraft.com (Aahz) Date: Fri, 30 Jan 2009 20:51:12 -0800 Subject: FINAL REMINDER: OSCON 2009: Call For Participation Message-ID: <20090131045112.GA14260@panix.com> The O'Reilly Open Source Convention has opened up the Call For Participation -- deadline for proposals is Tuesday Feb 3. OSCON will be held July 20-24 in San Jose, California. For more information, see http://conferences.oreilly.com/oscon http://en.oreilly.com/oscon2009/public/cfp/57 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From dg.gmane at thesamovar.net Sat Jan 31 00:11:10 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 06:11:10 +0100 Subject: nth root In-Reply-To: References: Message-ID: Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of (10**100)**(1./13) (floats have about 7 and doubles about 16). Dan Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list From aahz at pythoncraft.com Sat Jan 31 00:16:15 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Jan 2009 21:16:15 -0800 Subject: Securing a database References: Message-ID: In article , wrote: > >My company provides some services online, which now they are planning >to make it offline and sell to customers who can use it in their >networks. How critical is it that this application work completely offline? I suggest that you seriously consider making your application crippleware unless it can "call home" -- that is, certain key bits work only with online access even if the majority of the app is local. This may or may not include the secure database, but if the data is local, it can still get hacked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From duprez at hinet.net.au Sat Jan 31 00:25:08 2009 From: duprez at hinet.net.au (duprez at hinet.net.au) Date: Fri, 30 Jan 2009 21:25:08 -0800 (PST) Subject: error C3861: 'Py_InitModule' Message-ID: <43a745e8-9637-40bc-882f-e5735118d479@p36g2000prp.googlegroups.com> Hi All, Using python 3.0, VS2005, WinXP SP3 I know this looks like a simple one but i just installed Python 3.0 (no other Python installations etc) and I'm trying to convert my perfectly working 2.5 C code for an embedded interpreter to 3.0. I've changed all of my string functions etc to remove those errors and I've studied the doc's and searched but I'm still getting the error regarding Py_InitModule, it's as if it no longer exists but I can't find anything different in the doc's. My intellisense and all works fine and all the other python functions are fine, just this one, does anyone have any ideas? Have I missed a change that has not made it to the doc's?? thanks, Mick. From w_a_x_man at yahoo.com Sat Jan 31 00:32:31 2009 From: w_a_x_man at yahoo.com (William James) Date: 31 Jan 2009 05:32:31 GMT Subject: Mathematica 7 compares to other languages References: <7454a7ef-ec19-4d7c-986b-d56c3ed8111b@i24g2000prf.googlegroups.com> <6a8f2eef-43e1-4a99-ae41-e4c90e6130e7@x38g2000yqj.googlegroups.com> <49404775$0$4893$607ed4bc@cv.net> <452ba58b-9377-4463-85e2-5ecdaa25a129@t39g2000prh.googlegroups.com> <6375k4pf1mleb6im67nkpec5olqbsom88e@4ax.com> Message-ID: w_a_x_man at yahoo.com wrote: > On Dec 25, 5:24?am, Xah Lee wrote: > > > The JavaScript example: > > > > // Javascript. By William James > > function normalize( vec ) { > > var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) > > a+b)) ? return vec.map(function(x) x/div) > > > > } > > > > is also not qualified. (it is syntax error in SpiderMonkey engine > > ?JavaScript-C 1.7.0 2007-10-03?) > > Since you are using the latest version of Mathematica, you should > also use the latest version of SpiderMonkey. > > The function works outside of a web browser with jslibs, and it > works in Firefox 3.0.1. > > > > > > > > Reduce: procedure normalize vec; begin scalar div; div := for each u in vec sum u^2; return map(~x/div, vec) end; From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:38:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:38:38 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> <01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: En Fri, 30 Jan 2009 07:08:29 -0200, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > > Of course this is clearly stated in the Language Reference "Variables > used > in the generator expression are evaluated lazily in a separate scope when > the next() method is called for the generator object (in the same fashion > as for normal generators). However, the in expression of the leftmost for > clause is immediately evaluated in the current scope..." -- but this > behaviour is still surprising and not obvious to me. ("not obvious" means > that things could have been different, choosing this was a design > decision). > > I am not so sure that it could have been done differently - > I see it something like this: (going back to almost your > original example, and reversing the position of globals > and locals to make it shorter) > >>>> def foo(things): > for thing in things: > yield thing() #it is obvious this is in the local scope of foo > >>>> boo = foo([locals,globals]) >>>> boo.next() > {'thing': , 'things': [ locals>, > ]} >>>> > and so it is, when you feed it the locals function > [...] > Now I don't think that you could really do it differently - > the right hand side of the generator expression is exactly > like my passed argument "things", in all cases as far as > I can see, and this means that the right hand side is > evaluated when it is "passed", and the left hand side > is whatever is done in the "for thing in things:" loop. > All the generator expression does is that it saves you > the trouble of defining the function - it kind of does it > for you, and calls it, and returns the generator object, > and throws the function away, all in one hit. (this is not > necessarily the real mechanism, but the effect is exactly > as if it were) Yes, but this is not the only alternative. You *decided* that foo and bar will take one argument - this means that it uses early binding and it is evaluated when the generator expression is created. This is a design decision, and it could have been different. The left-part of the generator expression (in the function analogy, the "yield" expression) is late bound - it is completely evaluated at every iteration, using whatever values are currently bound to external (free) variables. The same *could* happen with the right part too -- although this is not what was decided. Consider this expression: g = (x+A for x in L for y in M). This is currently expanded more or less like this: def foo(L): for x in L: for y in M: yield x+A g = foo(iter(L)) (as your example above) Note that L has a special status -- it's the only expression evaluated at the time g is defined. It *could* have been like this: def foo() for x in L: for y in M: yield x+A g = foo() or even like this: def foo(L, M, A): for x in L: for y in M: yield x+A g = foo(iter(L), iter(M), A) In particular, I like the 2nd (all late binding). Seems this topic was discussed many times [1] when PEP289 [2] was proposed, and "practicality beats purity". [1] http://mail.python.org/pipermail/python-dev/2004-April/date.html [2] http://www.python.org/dev/peps/pep-0289/ -- Gabriel Genellina From t.roberts at cqu.edu.au Sat Jan 31 00:43:37 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sat, 31 Jan 2009 15:43:37 +1000 Subject: nth root References: Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Dan, Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 is 3221.2904208350265.... there must be a quicker way of finding out its between 3221 and 3222.... ....but perhaps not. Tim ________________________________ From: Dan Goodman [mailto:dg.gmane at thesamovar.net] Sent: Sat 31-Jan-09 3:11 PM To: python-list at python.org Subject: Re: nth root Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of (10**100)**(1./13) (floats have about 7 and doubles about 16). Dan Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers. I'm using > n = 13 > root = base**(1.0/n) > which correctly computes the root to a large number of decimal > places, but therefore takes a long time. All I need is the integer > component. Is there a quicker way? > > > > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:48:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:48:55 -0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik> Message-ID: En Fri, 30 Jan 2009 06:42:22 -0200, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: >> g = (x+B for x in A) > > I think it helps understanding if you translate the above to > >>>> A = [1,2,3] >>>> B = 1 >>>> def f(a): > ... for x in a: > ... yield x+B > ... >>>> g = f(A) >>>> A = [4,5,6] >>>> B = 10 >>>> print list(g) > [11, 12, 13] > > This is not altogether unintuitive, but I think I would prefer if it > worked > like > >>>> A = [1,2,3] >>>> B = 1 >>>> def f(a, b): > ... for x in a: > ... yield x+b > ... >>>> g = f(A, B) >>>> A = [4,5,6] >>>> B = 10 >>>> list(g) > [2, 3, 4] > > i. e. every name were bound early. Of course this wouldn't help with > locals() which would still be called in different scopes. Yep -- although I would like all names were late bound instead. But as I posted in another message, in this case "practicality beat purity" and a special case was made for the leftmost iterable. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 00:56:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 03:56:21 -0200 Subject: ImportError in embedded Python Interpreter References: <28c5ec8f-c9ae-419c-8502-ac449e7eaeb0@y23g2000pre.googlegroups.com> <321ac876-bc29-418a-81c7-7ef5e0f23478@u18g2000pro.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 08:50:45 -0200, escribi?: > Okay, thats just the question. I did that what you wrote but it > doesn't really works. > What is, if Py_SetProgramName() gets a NULL Pointer, if argv[0] is > empty? Why so? Are you in an embedded environment or something that doesn't have a filesystem? Calling Py_SetProgramName with an absolute path would be the easiest way to make it work. -- Gabriel Genellina From duprez at hinet.net.au Sat Jan 31 01:10:06 2009 From: duprez at hinet.net.au (duprez at hinet.net.au) Date: Fri, 30 Jan 2009 22:10:06 -0800 (PST) Subject: error C3861: 'Py_InitModule' References: <43a745e8-9637-40bc-882f-e5735118d479@p36g2000prp.googlegroups.com> Message-ID: <21385b40-9e64-473f-9d05-9729dacdf0d0@w39g2000prb.googlegroups.com> Ok, I found the reason, you now need to do a bit more work and use PyModule_Create(). Also, for anyone else that may stumble on this, you need to refer to the online Dev doc's that get updated regularly (which I regrettably forgot about) which are here -> http://docs.python.org/dev/3.0/ thanks, Mick. From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:10:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:10:39 -0200 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao escribi?: >> See the following errors I in my case: >> >> $ python >> 'import site' failed; use -v for traceback >>>>> import socket >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named socket Those errors indicate that Python is not working correctly in your system. You should fix it before going on. > Another issue is: how can I perform all of these steps in a python > script? Start reading the tutorial and working the examples: http://docs.python.org/tutorial/ In a short time (maybe shorter than you expect) you'll manage enough of Python to do this. Come back when you have specific questions, or try the tutor list: http://mail.python.org/mailman/listinfo/tutor -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:30:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:30:42 -0200 Subject: relpath problem on windows References: Message-ID: En Fri, 30 Jan 2009 14:30:53 -0200, eliben escribi?: > I'm having a problem with 2.6's new os.path.relpath function. > > This is correct: > > relpath(r'd:\abc\jho', r'd:\abc') > => 'jho' > > But this isn't: > relpath(r'd:\jho', r'd:\\') > => '..\jho' Looks like a real bug to me -- please submit it to http://bugs.python.org/ > Neither is this: > relpath(r'd:\jho', r'd:') > => '..\..\..\jho' d: means "the current directory on drive d:", and it could be something like d:\a\b\c -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 01:49:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 04:49:16 -0200 Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> <296542.92832.qm@web112216.mail.gq1.yahoo.com> Message-ID: En Fri, 30 Jan 2009 16:52:07 -0200, Bernard Rankin escribi?: >> > I am trying to build python 2.6 on a machine (web server) that I do >> not have >> root access to. (has 2.4 installed) >> > >> > Python 2.5 builds fine, but I am getting an error when I run "make" >> for 2.6.1. >> Mmm... my 2.6.1 source show different line numbers, maybe you should >> check it's >> the right file? > > Wow, good catch. > > I just re-downloaded the archive and it works fine. > > I know for certain that I did no editing to the files, and even tried > expanding the original tar.gz a couple of times. > > There must be a corrupted package somewhere among the official Python > mirrors. (Sadly, I overwrote the old tar.gz file when I got the new > one.) Oops... so bad. The python.org releases have PGP signatures and MD5 published so you can verify their authenticity. -- Gabriel Genellina From joncle at googlemail.com Sat Jan 31 02:03:27 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 30 Jan 2009 23:03:27 -0800 (PST) Subject: Number of bits/sizeof int Message-ID: Hi Group, This has a certain amount of irony (as this is what I'm pretty much after):- >From http://docs.python.org/dev/3.0/whatsnew/3.1.html: "The int() type gained a bit_length method that returns the number of bits necessary to represent its argument in binary:" Any tips on how to get this in 2.5.2 as that's the production version I'm stuck with. Cheers, Jon. From mail at microcorp.co.za Sat Jan 31 02:08:20 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 31 Jan 2009 09:08:20 +0200 Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik><01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: <012301c98372$dde73f80$0d00a8c0@hendrik> "Gabriel Genellina" wrote: >Consider this expression: g = (x+A for x in L for y in M). This is >currently expanded more or less like this: > >def foo(L): > for x in L: > for y in M: > yield x+A >g = foo(iter(L)) > >(as your example above) Note that L has a special status -- it's the only >expression evaluated at the time g is defined. It *could* have been like >this: > >def foo() > for x in L: > for y in M: > yield x+A >g = foo() > >or even like this: > >def foo(L, M, A): > for x in L: > for y in M: > yield x+A >g = foo(iter(L), iter(M), A) > >In particular, I like the 2nd (all late binding). Seems this topic was >discussed many times [1] when PEP289 [2] was proposed, and "practicality >beats purity". Ok thanks - I see where you are coming from now. It never ceases to amaze me how different we all are - Given a choice, I would have chosen the last alternative, as it feels more natural to me - the one you like feels to me as if it were too tightly coupled, somehow. - almost as if you were using named globals in a function instead of passing arguments in. But hey - I have long since learned that it is of no use to rant against the way something works, if you cannot easily change it - one can just figure out what it does, and then figure out how to use it to get it to do what one wants. Thanks for an interesting discussion. - Hendrik From sjmachin at lexicon.net Sat Jan 31 02:29:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jan 2009 23:29:10 -0800 (PST) Subject: Number of bits/sizeof int References: Message-ID: <6cf38435-9cb3-49b5-a8a0-8071bfb3329f@r15g2000prh.googlegroups.com> On Jan 31, 6:03?pm, Jon Clements wrote: > Hi Group, > > This has a certain amount of irony (as this is what I'm pretty much > after):- > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. For a positive integer, the simplest method (not necessarily the fastest) is to count how many times you need to shift it right to make it become zero. For non-positive integers, what answers do you want? From catphive at catphive.net Sat Jan 31 02:31:47 2009 From: catphive at catphive.net (Brendan Miller) Date: Fri, 30 Jan 2009 23:31:47 -0800 Subject: import reassignment different at module and function scope Message-ID: <4983FE63.8010308@catphive.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 If I: import sys sys = sys.version This executes find but: import sys def f(): sys = sys.version This gives an error indicating that the sys on the right hand side of = is undefined. What gives? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmD/mMACgkQ4eGWG/zYzOmrWgCbBLuD2HNDJJly3Z1KCPoNOB1G sDgAoJ+gMCt9hWKuDUN30VUP40zqtbmJ =+pND -----END PGP SIGNATURE----- From Scott.Daniels at Acm.Org Sat Jan 31 02:34:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 30 Jan 2009 23:34:14 -0800 Subject: Number of bits/sizeof int In-Reply-To: References: Message-ID: Jon Clements wrote: > ... From http://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. Well, what are your arg constraints? Integers in 0 .. 2**53? math.frexp(n)[1] --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Sat Jan 31 02:37:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 05:37:16 -0200 Subject: Number of bits/sizeof int References: Message-ID: En Sat, 31 Jan 2009 05:03:27 -0200, Jon Clements escribi?: > This has a certain amount of irony (as this is what I'm pretty much > after):- >> From http://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. I'm sure *everyone* will now post his favourite algorithm... If you search the archives, you'll find *tons* of versions. Ok, my take: def number_of_bits(num): assert num>=0 nbits = 1 max = 2 while max<=num: nbits += 1 max += max return nbits -- Gabriel Genellina From joncle at googlemail.com Sat Jan 31 02:44:04 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 30 Jan 2009 23:44:04 -0800 (PST) Subject: Number of bits/sizeof int References: <6cf38435-9cb3-49b5-a8a0-8071bfb3329f@r15g2000prh.googlegroups.com> Message-ID: <009074e6-2eea-4b8d-8cc8-2a796a0570a7@q18g2000vbn.googlegroups.com> On Jan 31, 7:29?am, John Machin wrote: > On Jan 31, 6:03?pm, Jon Clements wrote: > > > Hi Group, > > > This has a certain amount of irony (as this is what I'm pretty much > > after):- > > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > > "The int() type gained a bit_length method that returns the number of > > bits necessary to represent its argument in binary:" > > > Any tips on how to get this in 2.5.2 as that's the production version > > I'm stuck with. > > For a positive integer, the simplest method (not necessarily the > fastest) is to count how many times you need to shift it right to make > it become zero. > For non-positive integers, what answers do you want? Thankfully, all integers are positive! Must have been having a blonde moment, 'cos as soon as I read your answer it was "of course that works". Not concerned about 'fast' as I hardly think with DB and disk I/O I'm going to worry about bit- shifting... Much appreciated John, Jon. From clp2 at rebertia.com Sat Jan 31 02:47:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jan 2009 23:47:23 -0800 Subject: import reassignment different at module and function scope In-Reply-To: <4983FE63.8010308@catphive.net> References: <4983FE63.8010308@catphive.net> Message-ID: <50697b2c0901302347g3e19c93agcfded84fb1ba5b09@mail.gmail.com> On Fri, Jan 30, 2009 at 11:31 PM, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > If I: > > import sys > > sys = sys.version > > This executes find but: > > import sys > > def f(): > sys = sys.version > > This gives an error indicating that the sys on the right hand side of = > is undefined. What gives? More specifically, you get: UnboundLocalError: local variable 'sys' referenced before assignment Here's what's happening (IIRC): Python sees (during "compilation") an assignment to 'sys' within the function and (since there's no 'global' declaration within the function) infers that the name 'sys', within the scope of the function, *always* refers a local variable. IIRC, it does this for significant optimization purposes. However, when the function gets run and it goes to evaluate the right-side of the assignment, it tries to lookup 'sys' as a local variable, which obviously fails since it was never previously assigned a value in the scope of the function, hence the error. You can fix this by either renaming 'sys' within the function to something else: def f(): version = sys.version #now sys is no longer treated as local or you can indicate that you want to refer to the global sys variable: def f(): global sys #tell python we mean the global sys sys = sys.version #this will rebind 'sys' in the outer, global scope Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Sat Jan 31 03:01:05 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 06:01:05 -0200 Subject: import reassignment different at module and function scope References: <4983FE63.8010308@catphive.net> Message-ID: En Sat, 31 Jan 2009 05:31:47 -0200, Brendan Miller escribi?: > If I: > > import sys > > sys = sys.version > > This executes find but: > > import sys > > def f(): > sys = sys.version > > This gives an error indicating that the sys on the right hand side of = > is undefined. What gives? Python doesn't have local variable declarations. Inside a function, *any* name that is assigned to (e.g. any name appearing on the left side of an assignment operation, like "a" in a=8) becomes a local variable. In your example, "sys" is a local variable, and it "shadows" (or "hides") the global one of the same name. When the interpreter tries to execute sys = sys.version it complains that it can't evaluate sys.version because the local name "sys" has not been assigned yet. The same thing at the global level is OK, because sys.version refers to the global "sys" name. (This should appear in the FAQ...) -- Gabriel Genellina From gandalf at shopzeus.com Sat Jan 31 03:11:03 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 31 Jan 2009 09:11:03 +0100 Subject: is python Object oriented?? In-Reply-To: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <49840797.2030504@shopzeus.com> M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece > of code, is it bound to any class? > Those who have time and consideration can help me There are many kinds of definitions for "object oriented" languages. I have learned some things in the University, and one of them was making distinction between "pure object oriented" languages, and "mixed" languages. Pure object oriented languages does not have programming tools that are non-objects. A good example was SmallTalk, if I remember correctly. Python is not a pure object oriented language, because it has other programming tools, for example functions. However, your question seems to be pedantry. As others would say, "you can do programming in FORTRAN in any language". In other words, it is possible to use Python in a non object-oriented way, but the "good" way of using it is defining classes and making objects... So Python *is* object oriented, if you use it the right way. There might be a definition of "object oriented language" that does not apply to Python, and theoretically, you could say that according to that definition, Python is not object oriented. But practically, it is! Best, Laszlo From lists at svrinformatica.it Sat Jan 31 03:45:38 2009 From: lists at svrinformatica.it (Mailing List SVR) Date: Sat, 31 Jan 2009 09:45:38 +0100 Subject: HTTPSConnection: client certificate auth Message-ID: <1233391538.6934.14.camel@localhost.localdomain> Hi all, I have a soap client using ZSI, the other end is oracle soa 10.1.3.1.0 all works fine since some months. The last week oracle soa was configured to accept client certificate authentication over https. If I try to use the standard python httplib.HTTPSConnection library it fails with the infamous "bad record mac" error and so also ZSI that use httplib. If I configure client certificate authentication on my own apache all is fine >>> from httplib import HTTPSConnection >>> conn=HTTPSConnection('192.168.2.66',443,'/etc/cert/clients1.key','/etc/cert/clients1.crt') >>> conn.request('GET','/ws?wsdl') >>> r=conn.getresponse() >>> r.read() the connection to oracle soa works fine with other java tools such as soapui, there is some known workaround for using HTTPSConnection with oracle soa? I'm using python 2.4 on red hat 5, thanks Nicola From hongyi.zhao at gmail.com Sat Jan 31 04:44:57 2009 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sat, 31 Jan 2009 17:44:57 +0800 Subject: Want to write a script to do the batch conversion from domain name to IP. References: <3ceb0e6c-a1a0-4a83-afd7-cbed7c31edbd@m15g2000vbp.googlegroups.com> Message-ID: On Sat, 31 Jan 2009 04:10:39 -0200, "Gabriel Genellina" wrote: >En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao >escribi$)A(.: > >>> See the following errors I in my case: >>> >>> $ python >>> 'import site' failed; use -v for traceback > >>>>>> import socket >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named socket > >Those errors indicate that Python is not working correctly in your system. >You should fix it before going on. I use cygwin, I don't know whether the further discussion on fix this issue is suitable for this group or not? If not, could you please give me some hints on the newsgroups or maillists I should resort to? > >> Another issue is: how can I perform all of these steps in a python >> script? > >Start reading the tutorial and working the examples: >http://docs.python.org/tutorial/ >In a short time (maybe shorter than you expect) you'll manage enough of >Python to do this. >Come back when you have specific questions, or try the tutor list: >http://mail.python.org/mailman/listinfo/tutor Thanks, I've subscribe to this list. -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From johnwoo.eh at gmail.com Sat Jan 31 05:20:49 2009 From: johnwoo.eh at gmail.com (woo) Date: Sat, 31 Jan 2009 02:20:49 -0800 (PST) Subject: The $5 Dollar PayPal Money Making Method Message-ID: As Seen On OPRAH & 20/20 - TURN $5 into $24600. Earn money using PAYPAL. As seen on Oprah & 20/20. THE PAYPAL 5 DOLLAR MONEY-MAKING METHOD. AS SEEN ON OPRAH. EARN HUGE $$$$$$$$ all you need is: 1) An email address 2) A PayPal account 3) $5.00 THIS IS A 2008 "CURRENT EMAIL LIST" What do you have to lose being you are only sending 1 dollar to five people. I WAS SKEPTICAL AT FIRST, but over a few days hundreds starting appearing in my paypal account! It was like Christmas morning!!!! INSTRUCTIONS: STEP 1: The first thing to do is highlight and SAVE this entire post in word or notepad on your computer so you can come back to it later. After that, if you are not already a PayPal user you need to go to the PayPal website which is http://www.paypal.com If you want to be able to receive credit card payments from other people then you will need to sign up for a PREMIER or BUSINESS account (not just a PERSONAL account). This is highly recommended to allow others easy payment options. In order to place the initial $5 into your account, you will have to verify your bank account with PAYPAL (which may take a few days). PAYPAL is 100% secure and is used by millions of people worldwide. STEP 2: Here is where the action occurs. The first thing to do is to send a $1.00 payment to each of the 5 email addresses on the current list from your PayPal account. To do this quickly and successfully, follow these simple steps: 1. Login to PayPal and click on the "Send Money" tab near the top of the screen 2. In the "Recipient's Email" field enter the email address 3. In the "Amount" field enter "1" (This is your $1.00 payment) 4. In the "Category" field select "Service" (Keeping it legal) 5. In the "Subject" field type "EMAIL LIST", and in the "NOTE" field enter "PLEASE PUT ME ON YOUR EMAIL LIST". By doing this, you are creating a service and maintaining the legality of the system by "paying" for the service. 6. Finally, click on the "Continue" button to complete the payment. Repeat these steps for each of the 5 email addresses. That's it! By sending the $1.00 payment to each address, you are implementing the compounding POWER of the system. You will reap what you sow! Here is the current e-mail list: ****************************** ******************* The email list: 1) cwatson_37... at yahoo.com 2) jacque... at yahoo.com 3) phili... at cox.net 4) boa... at hotmail.com 5) johnwoo.eh at gmail.com ************************************* STEP 3: Now take the #1 email off of the list that you see above (from your saved file), move the other addresses up (5 becomes 4, 4 becomes 3, etc.) and add YOUR email address (the one used for your PayPal account) as number 5 on the list. This is the only part of the document that should be changed. ** Make sure your email address is the one you have registered with PayPal ** STEP 4: Post your amended article to at least 200 newsgroups or message boards. Keep in mind that there are tens of thousands of groups online! All you need is 200, but remember the more you post the more money you make - as well as everyone else on the list! I've began to see money roll in before I even hit 100 posts, but try to hit around 200 to allow maximum exposure. Use Netscape, Internet Explorer, Firefox, Safari, or whatever your internet browser is to search for various news groups, log on to any search engine like yahoo.com or google.com and type in a subject like 'MILLIONAIRE MESSAGE BOARD', 'MONEY MAKING DISCUSSIONS', 'MONEY MAKING FORUMS', or 'BUSINESS MESSAGE BOARD', PAYPAL 5 DOLLAR, OPRAH 5 DOLLAR PAYPAL METHOD. You will find thousands and thousands of message boards. Click them one by one and you will find the option to post a new message. Fill in the subject which will be the header that everyone sees as they scroll through the list of postings in a particular group, and post the article with the NEW list of email addresses included. THAT'S IT!! From anders.u.persson at gmail.com Sat Jan 31 05:28:16 2009 From: anders.u.persson at gmail.com (anders) Date: Sat, 31 Jan 2009 02:28:16 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: <5b2edcf4-4eb5-425c-9535-77f3d48f0cdf@q18g2000vbn.googlegroups.com> Tanks everyone that spent time helping my, the help was great. Best regards Anders From ck.thrissur at gmail.com Sat Jan 31 05:35:44 2009 From: ck.thrissur at gmail.com (CK Raju) Date: Sat, 31 Jan 2009 16:05:44 +0530 Subject: How to manipulate a contents of file as record structures Message-ID: I have a text file containing the following alphanumerals. aaaaaa22bbbbbbbb55 hhhhhh11dpdpdpdp22 kkkkkkk21lokolkolko33 ..... I need to read the contents as single line, one after the other and append the sum of digits at the end. aaaaaa22bbbbbbbb5577 hhhhhh11dpdpdpdp2233 kkkkkkk21lokolkolko3354 .... What would be a simple way to achieve this ? CK Raju From gagsl-py2 at yahoo.com.ar Sat Jan 31 05:49:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 08:49:25 -0200 Subject: How to manipulate a contents of file as record structures References: Message-ID: En Sat, 31 Jan 2009 08:35:44 -0200, CK Raju escribi?: > I have a text file containing the following alphanumerals. > aaaaaa22bbbbbbbb55 > hhhhhh11dpdpdpdp22 > kkkkkkk21lokolkolko33 > ..... > > I need to read the contents as single line, one after the other > and append the sum of digits at the end. > aaaaaa22bbbbbbbb5577 > hhhhhh11dpdpdpdp2233 > kkkkkkk21lokolkolko3354 > .... > > What would be a simple way to achieve this ? Suppose f is the open file. To read it a line at a time: for line in f: do_something_with(line) To search for a number, try the re module: http://docs.python.org/library/re.html To do some calculation with those numbers, remember to convert them to integers first: x="12" y="34" x+y gives "1234" int(x)+int(y) gives 46 Good luck! -- Gabriel Genellina From ck.thrissur at gmail.com Sat Jan 31 06:07:57 2009 From: ck.thrissur at gmail.com (CK Raju) Date: Sat, 31 Jan 2009 16:37:57 +0530 Subject: How to manipulate a contents of file as record structures In-Reply-To: References: Message-ID: On Sat, Jan 31, 2009 at 4:19 PM, Gabriel Genellina wrote: > for line in f: > do_something_with(line) Thanks a lot. CK Raju From XX.XmcX at XX.XmclaveauX.com Sat Jan 31 06:10:20 2009 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Sat, 31 Jan 2009 12:10:20 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: Re > ?builtin? is not a class. I think "object" ; not only "class" And "builtin" is an object. -- @-salutations Michel Claveau From castironpi at gmail.com Sat Jan 31 06:12:24 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 31 Jan 2009 03:12:24 -0800 (PST) Subject: Why doesn't eval of generator expression work with locals? References: <01d501c981f5$e670e9e0$0d00a8c0@hendrik><01ca01c982bf$d609ca20$0d00a8c0@hendrik> Message-ID: On Jan 31, 1:08?am, "Hendrik van Rooyen" wrote: > "Gabriel Genellina" wrote: snip > >or even like this: > > >def foo(L, M, A): > > ? for x in L: > > ? ? for y in M: > > ? ? ? yield x+A > >g = foo(iter(L), iter(M), A) > > >In particular, I like the 2nd (all late binding). Seems this topic was ? > >discussed many times [1] when PEP289 [2] was proposed, and "practicality ? > >beats purity". > > Ok thanks - I see where you are coming from now. > It never ceases to amaze me how different we all are - > Given a choice, I would have chosen the last alternative, > as it feels more natural to me - the one you like feels to > me as if it were too tightly coupled, somehow. - almost > as if you were using named globals in a function instead > of passing arguments in. snip Did anyone observe this yet? >>> global_vars = {} >>> local_vars = {'ar':["foo", "bar"], 'y':"bar"} >>> print eval('all((x == y for x in ar))', local_vars, global_vars ) False >>> print eval('all((x == y for x in ar))', global_vars, local_vars) #error as original From aj at cubbyhole.net Sat Jan 31 06:35:05 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 11:35:05 +0000 Subject: Empty string is False right? Message-ID: <246E932C-93F6-486D-9991-15E55A662ED3@cubbyhole.net> Hello, First post so bear with me if I'm being a numpty ... Is it me or is there something slightly counter intuitive and thus not so pythonesque about this: >>> s = '' >>> if s: True ... else: False ... False >>> s and eval(s) '' >>> Regards, AJ From andrew at acooke.org Sat Jan 31 06:39:20 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 03:39:20 -0800 (PST) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: <4d802030-df80-4e02-ae70-fa736a4f4f74@r40g2000yqj.googlegroups.com> On Jan 30, 11:59?pm, flagg wrote: > I am working on a very basic xmlrpc server, which will expose certain > functions for administering BIND zone files. ?The big problem I am > having is parsing the incoming xmlrpc request. ?Basically part of the [...] at the risk of repeating what the other guy said, it sounds like you're going about this in the wrong way. the xmlrpc server will parse the incoming request for you if you supply it with a suitable function to invoke. so, for normal use, you do not override anything. andrew From bj_666 at gmx.net Sat Jan 31 06:42:14 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 31 Jan 2009 11:42:14 GMT Subject: verilog like class w/ bitslicing & int/long classtype References: <1586b7bd-b45a-4d9d-91a0-7de75d037d5c@i18g2000prf.googlegroups.com> <6uf1djFengojU2@mid.uni-berlin.de> Message-ID: <6uiromFfkfaeU1@mid.uni-berlin.de> On Fri, 30 Jan 2009 21:59:34 +0100, Stef Mientki wrote: > Marc 'BlackJack' Rintsch wrote: >> On Fri, 30 Jan 2009 00:25:03 +0100, Stef Mientki wrote: >> >> >>> try this: >>> >>> class MyRegClass ( int ) : >>> def __init__ ( self, value ) : >>> self.Value = value >>> def __repr__ ( self ) : >>> line = hex ( self.Value ) >>> line = line [:2] + line [2:].upper() >>> return line >>> >>> >> def __repr__(self): >> return '0x%X' % self.value >> >> >>> __str__ = __repr__ >>> >>> >> This is unnecessary, the fallback of `__str__` is `__repr__` already. >> >> > well this is what my Python is doing: > > without _str__ = __repr__ > >>print shadow_register > 170 > > with _str__ = __repr__ > >>print shadow_register > 0xAA Then don't inherit from `int`. Why are you doing this anyway? If you inherit from `int` you shouldn't store the value in an extra attribute but use the `int`\s value. This way you have one value used by the `int` methods and one used by your own methods. Ciao, Marc 'BlackJack' Rintsch From andrew at acooke.org Sat Jan 31 06:46:32 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 03:46:32 -0800 (PST) Subject: Where to host a (Python) project? Message-ID: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Hi, I have a new project, that I just released in beta (http:// www.acooke.org/lepl - a recursive decent parser with full backtracking). At the moment I am using pypi and setuptools for distribution (it's a pure python package) and I am happy with hosting static web pages (the manual and api doc linked to above) on my own site (I did try the packages.python.org web pages, but it seemed pointless duplicating my own). However, i am thinking I could really do with: - a mailing list - simple bug tracking - subversion and am wondering which is the best (free) provider for these (the code is LGPL open source). I'd prefer a mailing list to something like google groups (although I guess it may be possible to configure a gateway) and I could open up my personal subversion server, but that seems like a lot of work (not really that interested in moving to something other than svn). Any recommendations? Thanks, Andrew From csaba.hoch at gmail.com Sat Jan 31 06:51:35 2009 From: csaba.hoch at gmail.com (Csaba Hoch) Date: Sat, 31 Jan 2009 12:51:35 +0100 Subject: Why do operators and methods of built-in types differ Message-ID: <49843B47.4010906@gmail.com> Hi, if I write the following: >>> 1+1 2 it seems to be exactly equivalent to this: >>> (1).__add__(1) 2 However, if I write invalid code and try to add a list to an int, the errors will be different: >>> 1+[] Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'list' >>> (1).__add__([]) NotImplemented I found that operator.__add__(1, []) gives the same result as 1+[]. What is the reason behind this difference between the __add__ operator and int.__add__? Thank you, Csaba From ralf at schoenian-online.de Sat Jan 31 07:12:41 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sat, 31 Jan 2009 13:12:41 +0100 Subject: Empty string is False right? In-Reply-To: References: Message-ID: <49844039.7040900@schoenian-online.de> AJ Ostergaard wrote: > Hello, > > First post so bear with me if I'm being a numpty ... > > Is it me or is there something slightly counter intuitive and thus not > so pythonesque about this: > > >>> s = '' > >>> if s: True > .... else: False > .... > False > >>> s and eval(s) > '' > >>> > > Regards, > AJ > Hi, yes, the following evaluates to False: empty String: '' empty list: [] empty tuple: () empty dict: {} 0, None and False of course Regards, Ralf From ralf at schoenian-online.de Sat Jan 31 07:12:41 2009 From: ralf at schoenian-online.de (Ralf Schoenian) Date: Sat, 31 Jan 2009 13:12:41 +0100 Subject: Empty string is False right? In-Reply-To: References: Message-ID: <49844039.7040900@schoenian-online.de> AJ Ostergaard wrote: > Hello, > > First post so bear with me if I'm being a numpty ... > > Is it me or is there something slightly counter intuitive and thus not > so pythonesque about this: > > >>> s = '' > >>> if s: True > .... else: False > .... > False > >>> s and eval(s) > '' > >>> > > Regards, > AJ > Hi, yes, the following evaluates to False: empty String: '' empty list: [] empty tuple: () empty dict: {} 0, None and False of course Regards, Ralf From aj at cubbyhole.net Sat Jan 31 07:16:19 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 12:16:19 +0000 Subject: Empty string is False right? In-Reply-To: <49844039.7040900@schoenian-online.de> References: <49844039.7040900@schoenian-online.de> Message-ID: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Hi Ralf, Thanks for that but why: >>> '' and True '' Surely that should be False?!? Regards, AJ On 31 Jan 2009, at 12:12, Ralf Schoenian wrote: > AJ Ostergaard wrote: >> Hello, >> First post so bear with me if I'm being a numpty ... >> Is it me or is there something slightly counter intuitive and thus >> not so pythonesque about this: >> >>> s = '' >> >>> if s: True >> .... else: False >> .... >> False >> >>> s and eval(s) >> '' >> >>> >> Regards, >> AJ > > Hi, > > yes, the following evaluates to False: > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} > 0, None > and False of course > > Regards, > Ralf From dickinsm at gmail.com Sat Jan 31 07:24:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 04:24:56 -0800 (PST) Subject: nth root References: Message-ID: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> On Jan 31, 5:43?am, "Tim Roberts" wrote: > Dan, > > Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 > is 3221.2904208350265.... > there must be a quicker way of finding out its between 3221 and 3222.... > > ....but perhaps not. I don't think you'll find anything much quicker than n**(1./13) (though I hope that if you're doing this millions of time then you're precomputing the 1./13 rather than redoing the division every single time. What happens behind the scenes here is that your integer is immediately converted to a float, then the system math library is used for the power operation. The integer -> float conversion is probably quite significant, timewise. I'd also be a bit worried about accuracy. Is it important to you that the integer part of the result is *exactly* right, or is it okay if (n**13)**(1./13) sometimes comes out as slightly less than n, or if (n**13-1)**(1./13) sometimes comes out as n? Mark From gagsl-py2 at yahoo.com.ar Sat Jan 31 07:26:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 10:26:50 -0200 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: En Sat, 31 Jan 2009 10:16:19 -0200, AJ Ostergaard escribi?: > Hi Ralf, > > Thanks for that but why: > > >>> '' and True > '' > > Surely that should be False?!? Python does "short-circuit evaluation" [1] "and" and "or" return one of its operands as soon as the outcome is determined, not just True or False. '' is a false value, as false as False itself :) After seeing that, there is no point in evaluating the second operand (True) because the final result cannot be true; so Python just returns the first operand. [1] http://en.wikipedia.org/wiki/Short_circuit_evaluation -- Gabriel Genellina From Bernd.Nawothnig at t-online.de Sat Jan 31 07:27:10 2009 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sat, 31 Jan 2009 13:27:10 +0100 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: On 2009-01-31, AJ Ostergaard wrote: > Thanks for that but why: >>>> '' and True > '' > Surely that should be False?!? It is: #v+ >>> bool('' and True) False #v- Bernd -- No time toulouse From vlastimil.brom at gmail.com Sat Jan 31 07:27:14 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 31 Jan 2009 13:27:14 +0100 Subject: Empty string is False right? In-Reply-To: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> 2009/1/31 AJ Ostergaard : > Hi Ralf, > > Thanks for that but why: > >>>> '' and True > '' > > Surely that should be False?!? > > Regards, > AJ > > see the docs: http://docs.python.org/reference/expressions.html#boolean-operations "The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned." hth, vbr From sjmachin at lexicon.net Sat Jan 31 07:32:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 04:32:16 -0800 (PST) Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <50869881-9f4b-4162-bdec-2c31b97372ef@g3g2000pre.googlegroups.com> On Jan 31, 11:12?pm, Ralf Schoenian wrote: > yes, the following evaluates to False: A much better way of describing the effect would be to say that the following are treated as false (no capital letter!) in a conditional context. > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} *any* empty container ... > 0, None > and False of course and objects which adhere to the protocol From andrew at acooke.org Sat Jan 31 07:33:12 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 04:33:12 -0800 (PST) Subject: Why do operators and methods of built-in types differ References: Message-ID: <14ee28f9-a504-4bf4-9213-6412243cd757@l39g2000yqn.googlegroups.com> On Jan 31, 8:51?am, Csaba Hoch wrote: > What is the reason behind this difference between the __add__ operator > and int.__add__? this is quite common in python. the special methods like __add__ are used to implement some functionality (like '+' in this case), but they are not all of it. for example, when a + b is evaluated, a.__add__(b) is attempted, but if that fails (raises a NotImplemented error) then b.__radd__(a) is tried instead. so there's not a 1-to-1 correspondence between '+' and __add__() and that is reflected in the exceptions, too. when a method does not exist a NotImplemented error is raised, but '+' contains extra logic and raises a more useful error message. does that make sense? i should probably add that this is just how i understand things - i assume it's correct, but i've not looked anything up in the documentation. andrew From aj at cubbyhole.net Sat Jan 31 07:36:03 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 12:36:03 +0000 Subject: Empty string is False right? In-Reply-To: <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: I'm not suggesting it's not operating as advertised - I'm suggesting the 'advertising' is slightly sguiffy if you catch my drift. I guess it's just me that finds it slightly counter intuitive. Surely intuitively the expression is "and" and therefore should always return a boolean? I'll shut up now. ;) AJ On 31 Jan 2009, at 12:27, Vlastimil Brom wrote: > 2009/1/31 AJ Ostergaard : >> Hi Ralf, >> >> Thanks for that but why: >> >>>>> '' and True >> '' >> >> Surely that should be False?!? >> >> Regards, >> AJ >> >> > see the docs: > http://docs.python.org/reference/expressions.html#boolean-operations > > "The expression x and y first evaluates x; if x is false, its value is > returned; otherwise, y is evaluated and the resulting value is > returned." > > hth, > vbr From gagsl-py2 at yahoo.com.ar Sat Jan 31 07:40:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 10:40:06 -0200 Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> Message-ID: En Sat, 31 Jan 2009 09:51:35 -0200, Csaba Hoch escribi?: > if I write the following: > > >>> 1+1 > 2 > > it seems to be exactly equivalent to this: > > >>> (1).__add__(1) > 2 > > However, if I write invalid code and try to add a list to an int, the > errors will be different: > > >>> 1+[] > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'int' and 'list' > > >>> (1).__add__([]) > NotImplemented > > I found that operator.__add__(1, []) gives the same result as 1+[]. > > What is the reason behind this difference between the __add__ operator > and int.__add__? The operator "+" does more than blindy calling left.__add__(right). In this case, as int + list returns NotImplemented, it reverses the operands and tries right.__radd__(left), and only then it gives up and raises TypeError. The actual rules are a bit more complex, involving type conversion too; see http://docs.python.org/reference/datamodel.html#emulating-numeric-types -- Gabriel Genellina From sjmachin at lexicon.net Sat Jan 31 07:43:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 04:43:25 -0800 (PST) Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <0f67afbd-8052-4ee7-9017-e844be85cca1@z28g2000prd.googlegroups.com> On Jan 31, 11:16?pm, AJ Ostergaard wrote: > Hi Ralf, > > Thanks for that but why: > > ?>>> '' and True > '' > > Surely that should be False?!? No, deliberately not. Read this for Python 3.0 http://docs.python.org/3.0/reference/expressions.html#boolean-operations and/or this for Python 2.X http://docs.python.org/reference/expressions.html#boolean-operations [essentially the only difference in 3.0 is a change to the protocol that allows a non-builtin object to say whether it is true or false] From csaba.hoch at gmail.com Sat Jan 31 07:49:03 2009 From: csaba.hoch at gmail.com (Csaba Hoch) Date: Sat, 31 Jan 2009 13:49:03 +0100 Subject: Why do operators and methods of built-in types differ In-Reply-To: References: <49843B47.4010906@gmail.com> Message-ID: <498448BF.2020307@gmail.com> Gabriel Genellina wrote: > The operator "+" does more than blindy calling left.__add__(right). In > this case, as int + list returns NotImplemented, it reverses the > operands and tries right.__radd__(left), and only then it gives up and > raises TypeError. > > The actual rules are a bit more complex, involving type conversion too; > see http://docs.python.org/reference/datamodel.html#emulating-numeric-types Thanks for both of you, it's much clearer now. Just a correction: according to the doc, NotImplemented is not an error, but a returned value. Csaba From bignose+hates-spam at benfinney.id.au Sat Jan 31 07:56:43 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 31 Jan 2009 23:56:43 +1100 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> Message-ID: <87ab9763ck.fsf@benfinney.id.au> Ralf Schoenian writes: > yes, the following evaluates to False: > empty String: '' > empty list: [] > empty tuple: () > empty dict: {} > 0, None > and False of course More precisely: All the above evaluate as Boolean false. But only one of them evaluates to False: the object bound to the name ?False?. >>> bool(None) == bool(False) True >>> None == False False >>> None is False False >>> bool('') == bool(False) True >>> '' == False False >>> '' is False False >>> bool(0) == bool(False) True >>> 0 == False False >>> 0 is False False -- \ ?What is it that makes a complete stranger dive into an icy | `\ river to save a solid gold baby? Maybe we'll never know.? ?Jack | _o__) Handey | Ben Finney From martin at marcher.name Sat Jan 31 07:59:50 2009 From: martin at marcher.name (Martin) Date: Sat, 31 Jan 2009 13:59:50 +0100 Subject: Where to host a (Python) project? In-Reply-To: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <5fa6c12e0901310459t23757ed2x5b476abce9f9cd3b@mail.gmail.com> Hi, 2009/1/31 andrew cooke : > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion > and am wondering which is the best (free) provider for these (the code > is LGPL open source). I'd prefer a mailing list to something like > google groups (although I guess it may be possible to configure a > gateway) and I could open up my personal subversion server, but that > seems like a lot of work (not really that interested in moving to > something other than svn). Google Groups can be perfectly used as Mailings Lists - while I'm not a huge fan of them that isn't an argument from your feature list :) There's tigris.org, savannah (savannah.gnu.org, nongnu.org), launchpad. All of them are fine to some extent, you might want to read up on PyMotW about how Doug Hellmann decided where to host his stuff. hth Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From andrew at acooke.org Sat Jan 31 08:03:13 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 05:03:13 -0800 (PST) Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> Message-ID: <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> > Just a correction: according to the doc, NotImplemented is not an > error, but a returned value. curious, so it is. i wonder why there is both a special return value (NotIMplemented) and a related exception (NotImplementedError). seems very odd to have a value... andrew From steve at holdenweb.com Sat Jan 31 08:06:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:06:02 -0500 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: MC wrote: > Re > >> ?builtin? is not a class. > > I think "object" ; not only "class" > And "builtin" is an object. > You can think what you like, but there is a fundamental difference between methods of a class and functions of a module. Until you appreciate that you will likely make mistakes. Don't worry, though, we all learn from our mistakes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Sat Jan 31 08:10:54 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 05:10:54 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 9:59?am, Martin wrote: > There's tigris.org, savannah (savannah.gnu.org, nongnu.org), > launchpad. All of them are fine to some extent, you might want to read > up on PyMotW about how Doug Hellmann decided where to host his stuff. all i can find is that he is writing his own! http://blog.doughellmann.com/search/label/codehosting (his reqs are quite different to mine - I am looking for an external provider because I do not want to host dynamic pages myself). anyway, if that was what you mean, fine - i just wonder if i am missing something? thanks, andrew From steve at holdenweb.com Sat Jan 31 08:23:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:23:02 -0500 Subject: nth root In-Reply-To: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: Mark Dickinson wrote: > On Jan 31, 5:43 am, "Tim Roberts" wrote: >> Dan, >> >> Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 >> is 3221.2904208350265.... >> there must be a quicker way of finding out its between 3221 and 3222.... >> >> ....but perhaps not. > > I don't think you'll find anything much quicker than n**(1./13) > (though I hope > that if you're doing this millions of time then you're precomputing > the 1./13 > rather than redoing the division every single time. > Compared with the computation involved in the power computation I think you'll find this makes a negligible difference in timing. But that's just mu gut instinct, and we both know that a benchmark is the only way to be certain, right? It just seems like a possibly premature optimization to me. [sigh. I had to start this, didn't i?] >>> t1 = timeit.Timer("x = 4021503534212915433093809093996098953996019232**(1.0/13)") >>> t2 = timeit.Timer("x = 4021503534212915433093809093996098953996019232**power", "power=1.0/13") >>> t1.timeit() 1.4860000610351562 >>> t2.timeit() 1.3789999485015869 >>> Hmm, well, I suppose an 9% speed gain might be worth it. > What happens behind the scenes here is that your integer is > immediately > converted to a float, then the system math library is used for the > power operation. The integer -> float conversion is probably quite > significant, timewise. > I bow to your superior intuition! > I'd also be a bit worried about accuracy. Is it important to you > that the > integer part of the result is *exactly* right, or is it okay if > (n**13)**(1./13) sometimes comes out as slightly less than n, or if > (n**13-1)**(1./13) sometimes comes out as n? > Much more significant points, given the limited precision of the doubles Python will be using. Could gmpy do this better, I wonder? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From darcy at druid.net Sat Jan 31 08:24:06 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 31 Jan 2009 08:24:06 -0500 Subject: Empty string is False right? In-Reply-To: <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: <20090131082406.1ebcac1e.darcy@druid.net> On Sat, 31 Jan 2009 12:16:19 +0000 AJ Ostergaard wrote: > >>> '' and True > '' > > Surely that should be False?!? Why? The first value evaluates to False in a boolean context and thus is returned in the above statement due to short circuit evaluation but is not itself False. You wouldn't expect the following statement to be True. >>> '' is False False -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Sat Jan 31 08:27:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 08:27:20 -0500 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: AJ Ostergaard wrote: > I'm not suggesting it's not operating as advertised - I'm suggesting the > 'advertising' is slightly sguiffy if you catch my drift. I guess it's > just me that finds it slightly counter intuitive. Surely intuitively the > expression is "and" and therefore should always return a boolean? > > I'll shut up now. ;) > You might think so, and it wouldn't be an entirely unreasonable thought, but in practice it makes a lot of sense to retain the original value where possible. The fact is that any left-hand operand that evaluates to false in a Boolean context can be used as it stands rather than being converted to Boolean first. So the conversion is essentially useless processing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From python.list at tim.thechases.com Sat Jan 31 08:45:46 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 07:45:46 -0600 Subject: glob.fnmatch (was "search speed") In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> Message-ID: <4984560A.1000406@tim.thechases.com> rdmurray at bitdance.com wrote: > Quoth Tim Chase : >> PS: as an aside, how do I import just the fnmatch function? I >> tried both of the following and neither worked: >> >> from glob.fnmatch import fnmatch >> from glob import fnmatch.fnmatch >> >> I finally resorted to the contortion coded below in favor of >> import glob >> fnmatch = glob.fnmatch.fnmatch > > What you want is: > > from fnmatch import fnmatch Oh, that's head-smackingly obvious now...thanks! My thought process usually goes something like """ I want to do some file-name globbing there's a glob module that looks like a good place to start hmm, dir(glob) tells me there's a fnmatch thing that looks like what I want according to help(glob.fnmatch) oh, the fnmatch() function is inside this glob.fnmatch thing so, I want glob.fnmatch.fnmatch() """ It never occurred to me that fnmatch was its own importable module. -tkc From martin at marcher.name Sat Jan 31 08:51:13 2009 From: martin at marcher.name (Martin) Date: Sat, 31 Jan 2009 14:51:13 +0100 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <5fa6c12e0901310551i6bffacc5icdd460606c82f29f@mail.gmail.com> 2009/1/31 andrew cooke : > On Jan 31, 9:59 am, Martin wrote: >> There's tigris.org, savannah (savannah.gnu.org, nongnu.org), >> launchpad. All of them are fine to some extent, you might want to read >> up on PyMotW about how Doug Hellmann decided where to host his stuff. > > all i can find is that he is writing his own! > http://blog.doughellmann.com/search/label/codehosting > (his reqs are quite different to mine - I am looking for an external > provider because I do not want to host dynamic pages myself). Darn, my bad. I just remembered that something happened in terms of hosting on his site, I thought he had decided on this: http://blog.doughellmann.com/2008/12/moving-pymotw-to-public-repository.html (seems he didn't have any time...) anyway, tigris, nongnu and savannah are hopefully at least useable information :) /Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From a at nospam.org Sat Jan 31 08:51:16 2009 From: a at nospam.org (Armin) Date: Sat, 31 Jan 2009 14:51:16 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: >> > > Right at the end: "To install data files directly in the target > directory, an empty string should be given as the directory." > > setup(..., > data_files=[ > ('', ['list/of/file/names', > 'perhaps/including/source/directory']), > ] > ) > Yes ... so far the theory :) As posted before ... set's my script (python 2.3): from distutils.core import setup import py2exe setup(windows=['dpconf.py'], data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] ) When I create the distribution I got the following err msg: *** copy data files *** warning: install_data: setup script did not provide a directory for '' -- installing right in 'C:\pyDPCONF.2.3-dev\dist' error: can't copy '': doesn't exist or not a regular file Looks a little bit inconsistent ? --Armin From dickinsm at gmail.com Sat Jan 31 09:03:07 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 06:03:07 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> On Jan 31, 1:23?pm, Steve Holden wrote: > [Mark] > > power operation. ?The integer -> float conversion is probably quite > > significant, timewise. > > I bow to your superior intuition! Here's another timing that shows the significance of the int -> float conversion: (non-debug build of the trunk) >>> t1 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232; power = 1./13") >>> t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") >>> t1.timeit() 0.34778499603271484 >>> t2.timeit() 0.26025009155273438 I've got a patch posted to the tracker somewhere that improves the accuracy of long->float conversions, while also speeding them up a tiny bit (but not a lot...). Mark From dickinsm at gmail.com Sat Jan 31 09:05:57 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 06:05:57 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> On Jan 31, 1:23?pm, Steve Holden wrote: > Much more significant points, given the limited precision of the doubles > Python will be using. Could gmpy do this better, I wonder? Almost certainly, if exact results are wanted! At least, GMP has an mpz_root function; I don't know offhand whether gmpy makes it accessible from Python. Mark From michele.simionato at gmail.com Sat Jan 31 09:07:19 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 31 Jan 2009 06:07:19 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <62117934-9a3e-45a0-bbc5-4206ba9a6429@l33g2000pri.googlegroups.com> On Jan 31, 12:46?pm, andrew cooke wrote: > Any recommendations? Google Code seems fine. From grante at visi.com Sat Jan 31 09:15:58 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 31 Jan 2009 08:15:58 -0600 Subject: Empty string is False right? References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> Message-ID: On 2009-01-31, Vlastimil Brom wrote: > 2009/1/31 AJ Ostergaard : >> Hi Ralf, >> >> Thanks for that but why: >> >>>>> '' and True >> '' >> >> Surely that should be False?!? >> >> Regards, >> AJ >> >> > see the docs: > http://docs.python.org/reference/expressions.html#boolean-operations > > "The expression x and y first evaluates x; if x is false, But that doesn't mean "x is False" in the strict Python expression sense of the phrase. It means if bool(x) is False (or something reasonably close to that). > its value is returned; otherwise, y is evaluated and the > resulting value is returned." -- Grant From eliben at gmail.com Sat Jan 31 09:22:34 2009 From: eliben at gmail.com (eliben) Date: Sat, 31 Jan 2009 06:22:34 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: andrew cooke wrote: > Hi, > > I have a new project, that I just released in beta (http:// > www.acooke.org/lepl - a recursive decent parser with full > backtracking). At the moment I am using pypi and setuptools for > distribution (it's a pure python package) and I am happy with hosting > static web pages (the manual and api doc linked to above) on my own > site (I did try the packages.python.org web pages, but it seemed > pointless duplicating my own). > > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion code.google.com provides all of these in a free and convenient manner. Recommended. From andrew at acooke.org Sat Jan 31 10:03:40 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 07:03:40 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 11:22?am, eliben wrote: > code.google.com provides all of these in a free and convenient manner. > Recommended. unfortunately google don't seem that reliable ;o) (have you tried a google search today?) From lists at cheimes.de Sat Jan 31 10:08:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jan 2009 16:08:34 +0100 Subject: Why do operators and methods of built-in types differ In-Reply-To: <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> References: <49843B47.4010906@gmail.com> <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> Message-ID: andrew cooke schrieb: >> Just a correction: according to the doc, NotImplemented is not an >> error, but a returned value. > > curious, so it is. i wonder why there is both a special return value > (NotIMplemented) and a related exception (NotImplementedError). seems > very odd to have a value... They are different and unrelated things. The NotImplentedError is an exception class while NotImplemented is a singleton like None. When a method like __add__ can't handle the other object it returns NotImplemented. It doesn't raise a NotImplementedError. The NotImplemented singleton is an optimization. The interpreter just has to compare the memory address of the returned value with the address of NotImplemented. That's a super fast op in C. Christian From theller at python.net Sat Jan 31 10:12:17 2009 From: theller at python.net (Thomas Heller) Date: Sat, 31 Jan 2009 16:12:17 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: <6uj823Ffh7l1U1@mid.individual.net> Armin schrieb: > As posted before ... set's my script (python 2.3): > > from distutils.core import setup > import py2exe > > setup(windows=['dpconf.py'], > data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] > ) > > When I create the distribution I got the following err msg: > > *** copy data files *** > warning: install_data: setup script did not provide a directory for '' > -- installing right in 'C:\pyDPCONF.2.3-dev\dist' > error: can't copy '': doesn't exist or not a regular file >From the Python docs (chapter 'writing the setup script): """ data_files specifies a sequence of (directory, files) pairs in the following way: setup(..., data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), ('config', ['cfg/data.cfg']), ('/etc/init.d', ['init-script'])] ) """ So, it looks like you should use > setup(windows=['dpconf.py'], > data_files=[("", ["proj_db","gsd_db","dachs2.xbm"])] ^ ^ > ) Thomas From gagsl-py2 at yahoo.com.ar Sat Jan 31 10:15:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 13:15:35 -0200 Subject: py2exe + SQLite problem References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: En Sat, 31 Jan 2009 11:51:16 -0200, Armin escribi?: > Gabriel Genellina wrote: >> En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: >> Right at the end: "To install data files directly in the target >> directory, an empty string should be given as the directory." >> setup(..., >> data_files=[ >> ('', ['list/of/file/names', >> 'perhaps/including/source/directory']), >> ] >> ) >> > Yes ... so far the theory :) > > As posted before ... set's my script (python 2.3): You didn't tell us that you were using version 2.3 -- it's important, as the current stable releases are 2.6 and 3.0. Anyway, this should work in 2.3 too. > from distutils.core import setup > import py2exe > > setup(windows=['dpconf.py'], > data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] > ) > Comparing my example and yours, you lack a parenthesis level: setup(windows=['dpconf.py'], data_files=[("", ["proj_db","gsd_db","dachs2.xbm"])] ) > When I create the distribution I got the following err msg: > > *** copy data files *** > warning: install_data: setup script did not provide a directory for '' > -- installing right in 'C:\pyDPCONF.2.3-dev\dist' > error: can't copy '': doesn't exist or not a regular file > > Looks a little bit inconsistent ? O thou of little faith, try again... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jan 31 10:16:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 13:16:03 -0200 Subject: Why do operators and methods of built-in types differ References: <49843B47.4010906@gmail.com> <81bf79bf-6426-4728-bcfd-dff5ae272d32@l39g2000yqn.googlegroups.com> Message-ID: En Sat, 31 Jan 2009 11:03:13 -0200, andrew cooke escribi?: > >> Just a correction: according to the doc, NotImplemented is not an >> error, but a returned value. > > curious, so it is. i wonder why there is both a special return value > (NotIMplemented) and a related exception (NotImplementedError). seems > very odd to have a value... I consider it an optimization. Raising an exception is more costly than returning a value, and this failure is likely to happen often (not all types define all possible operators). AFAIK this is only recognized by the binary operators (__add__, __iadd__, etc) and rich comparisons (__eq__, __lt__, etc.) -- Gabriel Genellina From aahz at pythoncraft.com Sat Jan 31 10:32:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 31 Jan 2009 07:32:30 -0800 Subject: Why GIL? (was Re: what's the point of rpython?) References: <7xd4ele060.fsf@ruckus.brouhaha.com> <7xr62ufv1c.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr62ufv1c.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> CPython's "primitive" storage management has a lot to do with the >> simplicity of interfacing CPython with external libraries. Any solution >> that proposes to get rid of the GIL needs to address that. > >This, I don't understand. Other languages like Lisp and Java and >Haskell have foreign function interfaces that easier to program than >Python's, -and- they don't use reference counts. There's usually some >primitive to protect objects from garbage collection while the foreign >function is using them, etc. The Java Native Interface (JNI) and the >Haskell FFI are pretty well documented. The Emacs Lisp system is not >too hard to figure out from examining the source code, etc. This is the first time I've heard about Java being easier to interface than Python. I don't work at that level myself, so I rely on the informed opinions of other people; can you provide a summary of what makes those FFIs easier than Python? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From notvalid2 at sbcglobal.net Sat Jan 31 10:41:35 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 07:41:35 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Steve Holden wrote: > W. eWatson wrote: >> r wrote: >>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>> Where in the world is a description of pack() for Tkinter widgets? Is it >>>> some sort of general method for all widgets? I'm looking in a few >>>> docs that >>>> use it without ever saying where it is described. For one, >>>> . In the NM Tech pdf on >>>> Tkinter, >>>> it's not found anywhere. I see Universal methods for widgets, but no >>>> mention >>>> of pack(). package, packed, but no pack. >>> did you try here :) >>> http://effbot.org/tkinterbook/pack.htm >> Thanks. I have the site bookmarked, but it's hard to search. I posted a >> comment to them that they should have it in pdf form. >> > http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack > > regards > Steve Well, that's an interesting "link". Another side of Google facilities? Maybe you're using Snagit or its brethern? However, I'm interested in searching a pdf, which, of course, doesn't yet exist. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Sat Jan 31 10:50:47 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 07:50:47 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Thu, 29 Jan 2009 14:55:13 -0200, W. eWatson > escribi?: >> Gabriel Genellina wrote: >>> En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson >>> escribi?: >>> >>>> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one? >>> There is a PDF version of "An Introduction to Tkinter" here: >>> http://www.pythonware.com/library/ >>> >> Thanks. I have it but it's an odd one to search on "pack(". There may >> be over 100 reference to pack(. It's probably explained there >> somewhere, but how many times do I want to press the search key? I >> have it printed out too. I guess I need to eyeball it. It's probably >> faster. Maybe find the section (geometry?) where it and others like it >> are found. There is an index, but it's a pitiful one page. > > Uh? The very first occurence of "pack" is in the Table of Contents, "The > pack geometry manager". (You may want to improve your search skills :) ) > Yes, that's correct, but I was looking for "pack(". It all depends on one's perspective on how to search. I'll not labor the point. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From rdmurray at bitdance.com Sat Jan 31 11:07:08 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 16:07:08 +0000 (UTC) Subject: glob.fnmatch (was "search speed") References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <4983CF93.3040002@thechases.com> <4984560A.1000406@tim.thechases.com> Message-ID: Quoth Tim Chase : > rdmurray at bitdance.com wrote: > > What you want is: > > > > from fnmatch import fnmatch > > Oh, that's head-smackingly obvious now...thanks! > > My thought process usually goes something like > > """ > I want to do some file-name globbing > > there's a glob module that looks like a good place to start > > hmm, dir(glob) tells me there's a fnmatch thing that looks like > what I want according to help(glob.fnmatch) > > oh, the fnmatch() function is inside this glob.fnmatch thing > > so, I want glob.fnmatch.fnmatch() > """ > > It never occurred to me that fnmatch was its own importable > module. I did a help(glob), saw that fnmatch wasn't in there, did a dir(glob), saw fnmatch and was puzzled, so I looked up the glob doc page on docs.python.org for glob. There was a cross reference at the bottom of the page to fnmatch, and it was only at that point that I went: "oh, duh" :) --RDM From deets at nospam.web.de Sat Jan 31 11:09:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 31 Jan 2009 17:09:37 +0100 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> Message-ID: <6ujbe0Ffhh6lU1@mid.uni-berlin.de> AJ Ostergaard schrieb: > Hi Ralf, > > Thanks for that but why: > > >>> '' and True > '' > > Surely that should be False?!? No. Please read the section in the language reference about the and/or operators. "and" will return the first false value, or the right side. Thus '' and True -> '' True and '' -> '' 'a' and True -> True True and 'a' -> 'a' "or" does the same, obviously with the or-semantics: '' or False -> False False or '' -> '' '' or True -> True True or '' -> True 'a' or False -> 'a' False or 'a' -> 'a' Diez From robin at NOSPAMreportlab.com Sat Jan 31 11:39:23 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 31 Jan 2009 16:39:23 +0000 Subject: fastest way to detect a user type Message-ID: <49847EBB.4050307@jessikat.plus.net> Whilst considering a port of old code to python 3 I see that in several places we are using type comparisons to control processing of user instances (as opposed to instances of built in types eg float, int, str) I find that the obvious alternatives are not as fast as the current code; func0 below. On my machine isinstance seems slower than type for some reason. My 2.6 timings are C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func0(v) 1000000 loops, best of 3: 0.348 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func1(v) 1000000 loops, best of 3: 0.747 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func2(v) 1000000 loops, best of 3: 0.378 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func3(v) 1000000 loops, best of 3: 0.33 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func0(1) 1000000 loops, best of 3: 0.477 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func1(1) 1000000 loops, best of 3: 1.14 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func2(1) 1000000 loops, best of 3: 1.16 usec per loop C:\Tmp>\Python\lib\timeit.py -s"import t;v=t.X()" t.func3(1) 1000000 loops, best of 3: 1.14 usec per loop so func 3 seems to be the fastest option for the case when the first test matches, but is poor when it doesn't. Can anyone suggest a better way to determine if an object is a user instance? ############################## from types import InstanceType class X: __X__=True class V(X): pass def func0(ob): t=type(ob) if t is InstanceType: pass elif t in (float, int): pass else: pass def func1(ob): if isinstance(ob,X): pass elif type(ob) in (float, int): pass else: pass def func2(ob): if getattr(ob,'__X__',False): pass elif type(ob) in (float, int): pass else: pass def func3(ob): if hasattr(ob,'__X__'): pass elif type(ob) in (float, int): pass else: pass ############################## -- Robin Becker From dg.gmane at thesamovar.net Sat Jan 31 11:48:31 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 17:48:31 +0100 Subject: nth root In-Reply-To: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: Mark Dickinson wrote: > I'd also be a bit worried about accuracy. Is it important to you > that the > integer part of the result is *exactly* right, or is it okay if > (n**13)**(1./13) sometimes comes out as slightly less than n, or if > (n**13-1)**(1./13) sometimes comes out as n? I don't think accuracy is too big a problem here actually (at least for 13th roots). I just tested it with several hundred thousand random 100 digit numbers and it never made a mistake. The precision of double ought to easily guarantee a correct result. If you let x=int(1e100**(1./13)) then ((x+1)**13-x**13)/x**13=2.6e-7 so you only need around the first 8 or 9 digits of the 100 digit number to compute the 13th root exactly (well within the accuracy of a double). OTOH, suppose you were doing cube roots instead then you would need the first 35 digits of the 100 digit number and this is more accurate than a double. So for example int(1e100**(1./3)) is a long way from being the integer part of the true cube root (it's between 10**18 and 10**19 away). Dan From mensanator at aol.com Sat Jan 31 11:53:38 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 31 Jan 2009 08:53:38 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> Message-ID: On Jan 31, 8:05?am, Mark Dickinson wrote: > On Jan 31, 1:23?pm, Steve Holden wrote: > > > Much more significant points, given the limited precision of the doubles > > Python will be using. Could gmpy do this better, I wonder? > > Almost certainly, if exact results are wanted! ?At least, GMP has > an mpz_root function; I don't know offhand whether gmpy makes it > accessible from Python. > > Mark What am I doing wrong here? IDLE 2.6b1 >>> import timeit >>> from gmpy import root >>> root(4021503534212915433093809093996098953996019232,13) (mpz(3221), 0) >>> t1 = timeit.Timer("x = root(a,r)", "a = 4021503534212915433093809093996098953996019232; r = 13") >>> t1.timeit() Traceback (most recent call last): File "", line 1, in t1.timeit() File "C:\Python26\lib\timeit.py", line 193, in timeit timing = self.inner(it, self.timer) File "", line 6, in inner NameError: global name 'root' is not defined From cjw at ncf.ca Sat Jan 31 11:53:39 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 31 Jan 2009 11:53:39 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: andrew cooke wrote: > On Jan 31, 11:22 am, eliben wrote: >> code.google.com provides all of these in a free and convenient manner. >> Recommended. > > unfortunately google don't seem that reliable ;o) (have you tried a > google search today?) I had a search problem today (10:00), the first I can remember, in which the response from a Google pointer was: Warning - visiting this web site may harm your computer! Yes, this is not Python related but I think that it is likely of general interest. Now, at 12:00, I get the page I was seeking. Colin W. From apt.shansen at gmail.com Sat Jan 31 12:01:37 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:01:37 -0800 (PST) Subject: Empty string is False right? Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From ajaksu at gmail.com Sat Jan 31 12:02:22 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 31 Jan 2009 09:02:22 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: On Jan 31, 1:03?pm, andrew cooke wrote: > On Jan 31, 11:22?am, eliben wrote: > > > code.google.com provides all of these in a free and convenient manner. > > Recommended. > > unfortunately google don't seem that reliable ;o) ?(have you tried a > google search today?) You can mirror at LP, bitbucket, github, etc. From thmpsn.m.k at gmail.com Sat Jan 31 12:08:25 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 09:08:25 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> On Jan 30, 12:15?am, Chris Rebert wrote: > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here". How do you know? (I know I'm not.) Seriously, though, the lack of private members does allow for ugly hacks in user code, and you know there are always ugly hackers. > This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. If it ends up being necessary, the class's design is flawed. (Though in this case, the flaw is easily solved by simply providing a getter.) > The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. If you're talking about getters, then note that this doesn't let you modify the member (unless there's a corresponding setter). In the absence of private/protected, Python should at least provide something similar to C++'s 'const' or Java's 'final'. (Similar, not equivalent, because then the object itself wouldn't be able to manipulate its own members!) From notvalid2 at sbcglobal.net Sat Jan 31 12:14:33 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 31 Jan 2009 09:14:33 -0800 Subject: Python Doc 2.6 vs 2.5--A Matter of Format? Message-ID: I see for 2.5 and for 2.6. I'm guessing these two pages differ somewhat in formats simply because someone decided to do so, and not that I'm in the wrong place for each of the two versions, correct? For example, somewhere down in the 2.5, I should find the 2.6 equivalent of ? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From mensanator at aol.com Sat Jan 31 12:18:53 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 31 Jan 2009 09:18:53 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <0378d3e6-e0b7-4d1f-9620-b615fe83a56b@q30g2000prq.googlegroups.com> Message-ID: <4868276d-dd3f-4e8d-96f6-81e7aabd4d15@r15g2000prd.googlegroups.com> On Jan 31, 10:53?am, Mensanator wrote: > On Jan 31, 8:05?am, Mark Dickinson wrote: > > > On Jan 31, 1:23?pm, Steve Holden wrote: > > > > Much more significant points, given the limited precision of the doubles > > > Python will be using. Could gmpy do this better, I wonder? > > > Almost certainly, if exact results are wanted! ?At least, GMP has > > an mpz_root function; I don't know offhand whether gmpy makes it > > accessible from Python. > > > Mark > > What am I doing wrong here? > > IDLE 2.6b1 > > >>> import timeit > >>> from gmpy import root > >>> root(4021503534212915433093809093996098953996019232,13) > (mpz(3221), 0) > >>> t1 = timeit.Timer("x = root(a,r)", "a = 4021503534212915433093809093996098953996019232; r = 13") > >>> t1.timeit() > > Traceback (most recent call last): > ? File "", line 1, in > ? ? t1.timeit() > ? File "C:\Python26\lib\timeit.py", line 193, in timeit > ? ? timing = self.inner(it, self.timer) > ? File "", line 6, in inner > NameError: global name 'root' is not defined Never mind, I figured it out. >>> import gmpy >>> a=gmpy.mpz(4021503534212915433093809093996098953996019232) >>> r=13 >>> t1 = timeit.Timer("x = root(a,r)", "from gmpy import root; from __main__ import a,r") >>> t1.timeit() 4.7018698921850728 For comparison: >>> t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") >>> t2.timeit() 0.43993394115364026 From dickinsm at gmail.com Sat Jan 31 12:25:34 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 09:25:34 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> Message-ID: <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> On Jan 31, 4:48?pm, Dan Goodman wrote: > I don't think accuracy is too big a problem here actually (at least for > 13th roots). I just tested it with several hundred thousand random 100 > digit numbers and it never made a mistake. Well, random numbers is one thing. But how about the following: >>> n = 12345**13 >>> n 154662214940914131102165197707101295849230845947265625L >>> int(n ** (1./13)) # should be 12345; okay 12345 >>> int((n-1) ** (1./13)) # should be 12344; oops! 12345 Mark From apt.shansen at gmail.com Sat Jan 31 12:29:49 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:29:49 -0800 (PST) Subject: is python Object oriented?? In-Reply-To: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From markobrien85 at gmail.com Sat Jan 31 12:31:52 2009 From: markobrien85 at gmail.com (markobrien85 at gmail.com) Date: Sat, 31 Jan 2009 09:31:52 -0800 (PST) Subject: persistent TCP connection in python using socketserver References: Message-ID: <80bc0bfa-f505-49f9-8d5a-f6574e6f8608@z28g2000prd.googlegroups.com> On Jan 30, 5:54?am, Jean-Paul Calderone wrote: > On Thu, 29 Jan 2009 08:38:43 -0800 (PST), markobrie... at gmail.com wrote: > >G'day > > >I'm currentlyusingsocketserverto build a simple XMLSocket (an XML > >based protocol used for communication between flash and the outside > >world) server. I've got flash establishing aconnection, sending a > >request and mypythonserver responding. However at this point > >socketserverterminates theconnection. Which is bad, since i need a > >persistentconnectionso i can push data from the server to the client > >without the overhead of polling. > > If you don't want theconnectionto close, then don't let the request > complete. ?SocketServerimplements logic for single request/response > perconnection. ?You can change this by making your requests take a > really long time (until you're done with theconnection) or you can > override the behavior which closes theconnectionafter a response. > > Or you could use the socket module, on which theSocketServermodule is > based. ?Or you could use Twisted, another higher-level package built on > the socket module (mostly). ?Actually, I recommend Twisted, since it will > mostly isolate you from boring low-level details and let you implement > whatever high-level behavior you're after (I know that a bunch of people > have used it to communicate with Flash, for example). > > Jean-Paul Cheers mate I had a look into twisted but was put off by the FAQ stating 1.0+ modules may or may not be stable, and only the 'core' is. I don't wanna be messing around with a potentially buggy server, so im gonna roll my own using the sockets module. Thanks for your help ! From apt.shansen at gmail.com Sat Jan 31 12:36:26 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 09:36:26 -0800 (PST) Subject: Python Doc 2.6 vs 2.5--A Matter of Format? In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From thmpsn.m.k at gmail.com Sat Jan 31 12:40:59 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 09:40:59 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> Message-ID: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> On Jan 30, 2:32?pm, Michael Torrie wrote: > Veerendra Ganiger wrote: > > Python is not purely object oriented programming, because we can write > > functions without any class. > > You are right, predefined class attributes are available when we write or > > execute a piece of python code without defining class, that means it's just > > using objects for it's purpose. It does not mean its purely object oriented. > > To be clear, python does not force you to lay out your code according to > some strict object-oriented paradigm. ?But Python itself is still purely > object-oriented, as is your script when parsed. > > This function without a class that you mentioned, is in fact an object > with attributes. ?You can pass a function around just like any other > object. ?Even calling a function is invoked like so: > > myfunc.__call__(params) > > So necessitating that code be inside a class has nothing to do with > object-oriented programming. ?Let's not forget that classes are > themselves objects (metaobjects in smalltalk parlance if I recall > correctly). > > Now python does not have any way besides lambda expressions of creating > unbound function objects, but in practice this doesn't matter as I can > rebind names freely. ?I can still do: > > a=myfunc > myfunc=some other expression or object > > > It all depends on implementation, I think even we can make "C" object > > oriented with proper implementation. > > Indeed, any code based on gobject libraries can be object-oriented in > design and function. But it's only a faking, and things such as inheritance and polymorphism are implemented clumsily (actually I'm not even sure about polymorphism). And of course, there are still no private members. From dg.gmane at thesamovar.net Sat Jan 31 12:43:08 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sat, 31 Jan 2009 18:43:08 +0100 Subject: nth root In-Reply-To: <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <2a05b899-2918-4d56-99f6-3965e05d10cf@z27g2000prd.googlegroups.com> Message-ID: Mark Dickinson wrote: > Well, random numbers is one thing. But how about the following: > >>>> n = 12345**13 >>>> n > 154662214940914131102165197707101295849230845947265625L >>>> int(n ** (1./13)) # should be 12345; okay > 12345 >>>> int((n-1) ** (1./13)) # should be 12344; oops! > 12345 Good point! Oops indeed. :-) Dan From Scott.Daniels at Acm.Org Sat Jan 31 12:44:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 31 Jan 2009 09:44:13 -0800 Subject: Why do operators and methods of built-in types differ In-Reply-To: References: Message-ID: Csaba Hoch wrote: > if I write the following: > >>> 1+1 > 2 > it seems to be exactly equivalent to this: > >>> (1).__add__(1) > 2 > However, if I write invalid code and try to add a list to an int, the > errors will be different: .... As has been explained, binary operators are trickier than the above seems to show. Here is how to get the full behavior: >>> import operator >>> operator.add(1,[]) Traceback (most recent call last): File "", line 1, in operator.add(1,[]) TypeError: unsupported operand type(s) for +: 'int' and 'list' --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jan 31 12:48:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 31 Jan 2009 09:48:24 -0800 Subject: Empty string is False right? In-Reply-To: References: <49844039.7040900@schoenian-online.de> <2E25BE3E-9297-43E7-85FF-70498BA6B6E4@cubbyhole.net> <9fdb569a0901310427i7926e224x5407c866f347fdc3@mail.gmail.com> Message-ID: Steve Holden wrote: > AJ Ostergaard wrote: >> I'm not suggesting it's not operating as advertised - I'm suggesting the >> 'advertising' is slightly sguiffy if you catch my drift. I guess it's >> just me that finds it slightly counter intuitive. Surely intuitively the >> expression is "and" and therefore should always return a boolean? ... > You might think so, and it wouldn't be an entirely unreasonable thought, > but in practice it makes a lot of sense to retain the original value > where possible. For example: print name_from_form or default_name or: main(sys.arg[1:] or ['default', 'args']) --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Sat Jan 31 12:49:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 31 Jan 2009 18:49:55 +0100 Subject: Python Doc 2.6 vs 2.5--A Matter of Format? In-Reply-To: References: Message-ID: <49848f43$0$27848$9b622d9e@news.freenet.de> > I see for 2.5 and > for 2.6. I'm guessing these two pages differ > somewhat in formats simply because someone decided to do so, and not > that I'm in the wrong place for each of the two versions, correct? Correct. The documentation format has significantly changed. > For > example, somewhere down in the 2.5, I should find the 2.6 equivalent of > ? Not necessarily. The change in format also means a change in indices; the formats differ in what indices precisely are created, and what precisely they contain. Try http://www.python.org/doc/2.5/lib/genindex.html Regards, Martin From Pat at junk.net Sat Jan 31 13:27:02 2009 From: Pat at junk.net (Pat) Date: Sat, 31 Jan 2009 13:27:02 -0500 Subject: len() References: Message-ID: Tobiah wrote: > Just out of curiosity, why was len() made to > be it's own function? I often find myself > typing things like my_list.len before I > catch myself. > > Thanks, > > Toby I'm surprised that no one responded to that question. I keep making that mistake all the time myself. From alejandro.weinstein at gmail.com Sat Jan 31 14:04:25 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Sat, 31 Jan 2009 11:04:25 -0800 (PST) Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> Message-ID: <31508b6d-bebb-45e6-b57c-525d370e22c0@r37g2000prr.googlegroups.com> On Jan 30, 1:40?pm, Christian Heimes wrote: > May I ask why you want to get the TID? htop shows the TID of each thread. Knowing the TID allows me to know which thread is hogging the CPU. If there is a better way to do this, or there is something fundamentally wrong with this approach, please let me know. Alejandro. From ajaksu at gmail.com Sat Jan 31 14:04:54 2009 From: ajaksu at gmail.com (ajaksu) Date: Sat, 31 Jan 2009 11:04:54 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> Message-ID: <0d710b35-691f-4951-a020-2dc3b1971555@n10g2000yqm.googlegroups.com> On Jan 31, 12:03 pm, Mark Dickinson wrote: [...] > t1 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232; power = 1./13") > t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13") And by using a float literal instead of "float (402150353421291543309...)", (BTW, here -^), it not only is faster but also a great way make some innocent bystander waste his eyesight trying to figure out the magic trick :D From digitig at gmail.com Sat Jan 31 14:07:34 2009 From: digitig at gmail.com (Tim Rowe) Date: Sat, 31 Jan 2009 19:07:34 +0000 Subject: search speed In-Reply-To: References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: 2009/1/30 Scott David Daniels : > Be careful with your assertion that a regex is faster, it is certainly > not always true. I was careful *not* to assert that a regex would be faster, merely that it was *likely* to be in this case. -- Tim Rowe From aj at cubbyhole.net Sat Jan 31 14:11:46 2009 From: aj at cubbyhole.net (AJ Ostergaard) Date: Sat, 31 Jan 2009 19:11:46 +0000 Subject: Python-list Digest, Vol 64, Issue 697 In-Reply-To: References: Message-ID: > AJ Ostergaard wrote: >> I'm not suggesting it's not operating as advertised - I'm >> suggesting the >> 'advertising' is slightly sguiffy if you catch my drift. I guess it's >> just me that finds it slightly counter intuitive. Surely >> intuitively the >> expression is "and" and therefore should always return a boolean? >> > You might think so, and it wouldn't be an entirely unreasonable > thought, > but in practice it makes a lot of sense to retain the original value > where possible. > > The fact is that any left-hand operand that evaluates to false in a > Boolean context can be used as it stands rather than being converted > to > Boolean first. So the conversion is essentially useless processing. That's what I've figured out during the course of the day. Thanks for listening one and all! :) Regards, AJ From gotbyrd at gmail.com Sat Jan 31 14:12:16 2009 From: gotbyrd at gmail.com (gotbyrd) Date: Sat, 31 Jan 2009 11:12:16 -0800 (PST) Subject: Searching a file for multiple strings Message-ID: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> Hello, I'm fairly new with python and am trying to build a fairly simple search script. Ultimately, I'm wanting to search a directory of files for multiple user inputted keywords. I've already written a script that can search for a single string through multiple files, now I just need to adapt it to multiple strings. I found a bit of code that's a good start: import re test = open('something.txt', 'r').read() list = ['a', 'b', 'c'] foundit = re.compile('|'.join(re.escape(target) for target in list)) if foundit.findall(test): print 'yes!' The only trouble with this is it returns yes! if it finds any of the search items, and I only want a return when it finds all of them. Is there a bit of code that's similar that I can use? Thanks From geekmail at usenot.de Sat Jan 31 14:16:48 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 31 Jan 2009 20:16:48 +0100 Subject: len() References: Message-ID: <20090131201648.201b6ed5@usenot.de> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: > Tobiah wrote: > > Just out of curiosity, why was len() made to > > be it's own function? I often find myself > > typing things like my_list.len before I > > catch myself. > > > > Thanks, > > > > Toby > > I'm surprised that no one responded to that question. > Huh? Gabriel Genellina replied about 46 minutes after it was posted. Might it be that your newsserver is a bit laggy? regards /W -- My real email address is constructed by swapping the domain with the recipient (local part). From eric.pruitt at gmail.com Sat Jan 31 14:23:37 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Sat, 31 Jan 2009 13:23:37 -0600 Subject: Import Replacement Message-ID: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> Imagine there are two files horse.py and buffalo.py. horse.py is imported by another file rider.py. Is it possible to make it so that under certain circumstances possibly based on an environment variable or something similar that when rider.py imports horse.py, it actually imports buffalo.py sort of like a behind the scenes replacement so that rider.py needs little, preferably absolutely no modification? Right now, I am investigating the use of sys.modules and doing something using sys.modules['horse.py'] = 'buffalo.py'. -------------- next part -------------- An HTML attachment was scrubbed... URL: From geekmail at usenot.de Sat Jan 31 14:26:08 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 31 Jan 2009 20:26:08 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <20090131202608.04fac735@usenot.de> On Sat, 31 Jan 2009 09:11:03 +0100 Laszlo Nagy wrote: > Python is not a pure object oriented language, because it has other > programming tools, for example functions. I'm not sure about the first part of the sentence, but Python's functions are objects. Check it in the interpreter: attributes, methods, the whole caboodle. regards, /W -- My real email address is constructed by swapping the domain with the recipient (local part). From eric.pruitt at gmail.com Sat Jan 31 14:27:53 2009 From: eric.pruitt at gmail.com (James Pruitt) Date: Sat, 31 Jan 2009 13:27:53 -0600 Subject: Import Replacement In-Reply-To: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> Message-ID: <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> Imagine there are two files horse.py and buffalo.py. horse.py is imported by another file rider.py. Is it possible to make it so that under certain circumstances possibly based on an environment variable or something similar that when rider.py imports horse.py, it actually imports buffalo.py sort of like a behind the scenes replacement so that rider.py needs little, preferably absolutely no modification? Right now, I am investigating the use of sys.modules and doing something using sys.modules['horse.py'] = 'buffalo.py'. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sat Jan 31 14:45:27 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 13:45:27 -0600 Subject: Searching a file for multiple strings In-Reply-To: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> Message-ID: <4984AA57.3050106@tim.thechases.com> > I'm fairly new with python and am trying to build a fairly simple > search script. Ultimately, I'm wanting to search a directory of files > for multiple user inputted keywords. I've already written a script > that can search for a single string through multiple files, now I just > need to adapt it to multiple strings. > > I found a bit of code that's a good start: > > import re > test = open('something.txt', 'r').read() > > list = ['a', 'b', 'c'] > > foundit = re.compile('|'.join(re.escape(target) for target in list)) > if foundit.findall(test): > print 'yes!' > > The only trouble with this is it returns yes! if it finds any of the > search items, and I only want a return when it finds all of them. Is > there a bit of code that's similar that I can use? [insert standard admonition about using "list" as a variable name, masking the built-in "list"] Unless there's a reason to use regular expressions, you could simply use test = open("something.txt").read() items = ['a', 'b', 'c'] if all(s in test for s in items): print "Yes!" else: print "Sorry, bub" This presumes python2.5 in which the "all()" function was added. Otherwise in pre-2.5, you could do for s in items: if s not in test: print "Sorry, bub" break else: print "Yeparoo" (note that the "else" goes with the "for", not the "if") -tkc From gnewsg at gmail.com Sat Jan 31 14:50:36 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Sat, 31 Jan 2009 11:50:36 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> On 31 Gen, 12:46, andrew cooke wrote: > Hi, > > I have a new project, that I just released in beta (http://www.acooke.org/lepl- a recursive decent parser with full > backtracking). ?At the moment I am using pypi and setuptools for > distribution (it's a pure python package) and I am happy with hosting > static web pages (the manual and api doc linked to above) on my own > site (I did try the packages.python.org web pages, but it seemed > pointless duplicating my own). > > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion > and am wondering which is the best (free) provider for these (the code > is LGPL open source). ?I'd prefer a mailing list to something like > google groups (although I guess it may be possible to configure a > gateway) and I could open up my personal subversion server, but that > seems like a lot of work (not really that interested in moving to > something other than svn). > > Any recommendations? > > Thanks, > Andrew Google Code. --- Giampaolo http://code.google.com/p/pyftpdlib From python.list at tim.thechases.com Sat Jan 31 15:00:27 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 31 Jan 2009 14:00:27 -0600 Subject: Searching a file for multiple strings (PS) In-Reply-To: <4984AA57.3050106@tim.thechases.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> Message-ID: <4984ADDB.2070509@tim.thechases.com> >> I'm fairly new with python and am trying to build a fairly simple >> search script. Ultimately, I'm wanting to search a directory of files >> for multiple user inputted keywords. I've already written a script >> that can search for a single string through multiple files, now I just >> need to adapt it to multiple strings. One more item: if your files are large, it may be more efficient to scan through them incrementally rather than reading the whole file into memory, assuming your patterns aren't multi-line (and by your escaping example, I suspect they're just single-words): items = set(['a', 'b', 'c']) for fname in ['file1.txt', 'file2.txt']: still_to_find = items.copy() for line in file(fname): found = set() for item in still_to_find: if item in line: found.add(item) still_to_find.difference_update(found) if not still_to_find: break if still_to_find: print "%s: Nope" % fname else: print "%s: Yep" % fname just one more way to do it :) -tkc From dickinsm at gmail.com Sat Jan 31 15:03:08 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 31 Jan 2009 12:03:08 -0800 (PST) Subject: nth root References: <41b9ba94-750b-4662-ad34-167207b83e5c@w39g2000prb.googlegroups.com> <1f58fa0e-0f03-41fc-8513-4c40e2c1de2d@v18g2000pro.googlegroups.com> <0d710b35-691f-4951-a020-2dc3b1971555@n10g2000yqm.googlegroups.com> Message-ID: On Jan 31, 7:04?pm, ajaksu wrote: > also a great way make some innocent bystander waste his eyesight > trying to figure out the magic trick :D Oh, come on! At least I put the two lines next to each other! :-) Mark From ianand0204 at gmail.com Sat Jan 31 15:11:16 2009 From: ianand0204 at gmail.com (flagg) Date: Sat, 31 Jan 2009 12:11:16 -0800 (PST) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> Message-ID: <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> On Jan 30, 8:12?pm, rdmur... at bitdance.com wrote: > Quoth flagg : > > > I am working on a very basic xmlrpc server, which will expose certain > > functions for administering BIND zone files. ?The big problem I am > > having is parsing the incoming xmlrpc request. ?Basically part of the > > xmlrpc request will help deterime which zone file is edited. ? ?I have > > been looking at the do_POST() method from SimpleXMLRPCDispatcher and > > it seems like I could code something which overides that method, > > however I am new to programming am at a loss, i might even be making > > this tougher than it needs to be. ? Is there a way to parse the > > incoming xmlrpc request before the function it is calling is executed? > > Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead? > > It's been a while since I looked at XMLRPC, but why wouldn't you have > a operation names, with the zone file to operate on as an argument? > Then you'd just be defining your operations as methods on your > SimpleXMLRPCServer, and they'd use the argument to determine which file > to operate on. > > If that doesn't make sense, either I've forgotten how XMLRPC works, > or you should explain your requirements a bit more. > > --RDM Let me see if i can elaborate on the requirements. I have 20+ different zone files. I want the xmlrpc server to be able to determine what zone file to open by looking at the incoming xml request. For example one of the functions I have now is to show a DNS record (I am using dnspython for most of this work) If i send an xmlrpc request that uses the 'showRecord' function with params of 'oracle1.foo.bar.com' I want to parse the "params" piece and then instruct the xml-rpc server to open foo.bar.com.zone for reading. The reason why i was looking at do_Post() and _dispatch was to attempt to read the incoming params and do exactly that. Do you think there is an easier way of accomplishing this, than the way I am going about it? From andrey.demidov at gmail.com Sat Jan 31 15:22:30 2009 From: andrey.demidov at gmail.com (Andrey Demidov) Date: Sat, 31 Jan 2009 23:22:30 +0300 Subject: Where to host a (Python) project? In-Reply-To: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> (andrew cooke's message of "Sat, 31 Jan 2009 03:46:32 -0800 (PST)") References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <877i4bcjjt.fsf@demashost.home.com> I use Google Code. From gherron at islandtraining.com Sat Jan 31 15:22:54 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 31 Jan 2009 12:22:54 -0800 Subject: Import Replacement In-Reply-To: <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> Message-ID: <4984B31E.7000809@islandtraining.com> James Pruitt wrote: > Imagine there are two files horse.py and buffalo.py. horse.py is > imported by another file rider.py. Is it possible to make it so that > under certain circumstances possibly based on an environment variable > or something similar that when rider.py imports horse.py, it actually > imports buffalo.py sort of like a behind the scenes replacement so > that rider.py needs little, preferably absolutely no modification? > Right now, I am investigating the use of sys.modules and doing > something using sys.modules['horse.py'] = 'buffalo.py'. > ------------------------------------------------------------------------ > > -- > http://mail.python.org/mailman/listinfo/python-list > If horse and buffalo have the same interface then try something like this: if ...: import horse as ridable else: import buffalo as ridable # Now use ridable as any module... If each defines a class of its own name, but the classes have identical interfaces, then try if ...: from horse import Horse as Ridable else: from buffalo import Buffalo as Ridable # Then instantiate animal = Ridable(...) Gary Herron From lists at cheimes.de Sat Jan 31 15:27:10 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jan 2009 21:27:10 +0100 Subject: is python Object oriented?? In-Reply-To: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: thmpsn.m.k at gmail.com schrieb: > But it's only a faking, and things such as inheritance and > polymorphism are implemented clumsily (actually I'm not even sure > about polymorphism). And of course, there are still no private > members. Do you honestly believe that C++'s private members are really private? Privateness is only enforced during parsing time. Nobody can stop you from messing around with header files or memory. You can still access and modify private members but it's all messy and ugly. Even C# and .NET don't stop you from doing nasty things from unmananged assemblies. Seriously, 'private' and 'protected' are merely tools to stop bad programmers from doing bad stuff. And the serve as documentation, too. Oh, by the way, the first C++ compilers just converted C++ code to C code. Such much about "You can't do OOP in C."! Christian From aolsuppo at gmail.com Sat Jan 31 15:36:28 2009 From: aolsuppo at gmail.com (aolsuppo at gmail.com) Date: Sat, 31 Jan 2009 12:36:28 -0800 (PST) Subject: help me python Message-ID: C:\Python26>vnc.py Traceback (most recent call last): File "C:\Python26\vnc.py", line 4, in import PyD3DES ImportError: DLL load failed: The specified module could not be found. From andrew at acooke.org Sat Jan 31 16:30:22 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 13:30:22 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: On Jan 31, 4:50?pm, "Giampaolo Rodola'" wrote: > Google Code. > > --- Giampaolohttp://code.google.com/p/pyftpdlib thanks - that's a nice example. i'm a bit concerned about the whole google corporation thing, but reading through the ideological check- sheet at savannah convinced me i wasn't worthy and your project looks good (i admit i haven't seen that many google projects, but they all seemed abandoned/bare/hostile). so i'll follow the majority here and give google code a go. cheers, andrew From torriem at gmail.com Sat Jan 31 17:01:57 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:01:57 -0700 Subject: is python Object oriented?? In-Reply-To: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: <4984CA55.4060509@gmail.com> thmpsn.m.k at gmail.com wrote >> This allows people to meddle with internals, at their own risk, >> if it ends up being absolutely necessary. > > If it ends up being necessary, the class's design is flawed. (Though > in this case, the flaw is easily solved by simply providing a getter.) No the class design is not necessarily flawed. Sometimes it is desirable to modify a class's behavior at a lower level. In Java this isn't possible directly and so it has led to an entire class of libraries that provide means of doing this. For more information, look up "Aspect-oriented Programming" on wikipedia. Since most aspect-oriented programming examples I've seen are in Java I never understood much about it ("cross-cutting concerns" is a pretty meaningless explanation) until I realized that metaprogramming in python, monkey-patching classes, and dynamically adding attributes to an existing class are all forms of aspect-oriented programming. And it turns out to be quite useful for some things. One area where aspect-oriented programming is useful is in libraries that add security layers to objects and methods. Rather than having to make code directly aware of the security layer (which could take different forms), we can instead reach into the classes and, for example, wrap certain methods in a function that enforces security. If we do it in the class directly, then even code that descends from this class will transparently "inherit" all of the newly added security layer code that was never there when the code was first written. By security layer I'm talking more about code that enforces certain user authentication before use (as in web programming) rather than "secure" code. From torriem at gmail.com Sat Jan 31 17:09:12 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:09:12 -0700 Subject: is python Object oriented?? In-Reply-To: <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <4984CC08.50902@gmail.com> thmpsn.m.k at gmail.com wrote: >> To be clear, python does not force you to lay out your code according to >> some strict object-oriented paradigm. But Python itself is still purely >> object-oriented, as is your script when parsed. > > But it's only a faking, and things such as inheritance and > polymorphism are implemented clumsily (actually I'm not even sure > about polymorphism). And of course, there are still no private > members. How is it faking? The class of a function object is "function," which is of the metaclass "type." What more do you want? If Guido himself declared that functions are objects would you believe that? Or modules? Since a function object is an instance of the class "function" I don't see how you could inherit from it, and polymorphism has nothing to do with this either. Maybe what you are talking about is deriving a class from the class "function." Not sure if that's allowed, mainly because the language has defined a standard way of declaring a function (methods are functions too, of course), so creating a useful, derived function object would be difficult given how the syntax of the language works. Private members? I could stick add any attribute I wanted to a function object and ask that people treat it as private if I wanted to: def myfunc(): pass myfunc.__dict__['_private'] = 4 If you are insinuating that not forcing private attributes to be unaccessible by others (black box theory) is in somehow a violation of object-oriented semantics, think again. It's not. (There are no formal definitions of OO anyay, but wikipedia lists quite a few characteristics considered common to OO, and enforced private members is not one of them.) From torriem at gmail.com Sat Jan 31 17:16:52 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 15:16:52 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: <4984CDD4.60601@gmail.com> Steve Holden wrote: > You can think what you like, but there is a fundamental difference > between methods of a class and functions of a module. Until you > appreciate that you will likely make mistakes. Don't worry, though, we > all learn from our mistakes. And this fundamental difference is? >From what I can tell an instance method is an object that encapsulates the function object in a closure that makes sure it has a reference to "self." I know that you dynamically add functions to objects creating methods dynamically, by using new.instancemethod or something. This seems to indicate to me that there are functions and there are functions. Methods are in fact functions, just with a callable wrapper around them. Is this not so? From rdmurray at bitdance.com Sat Jan 31 17:25:31 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 31 Jan 2009 22:25:31 +0000 (UTC) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> Message-ID: Quoth flagg : > Let me see if i can elaborate on the requirements. I have 20+ > different zone files. I want the xmlrpc server to be able to > determine what zone file to open by looking at the incoming xml > request. For example one of the functions I have now is to show a DNS > record (I am using dnspython for most of this work) > > If i send an xmlrpc request that uses the 'showRecord' function with > params of 'oracle1.foo.bar.com' I want to parse the "params" piece > and then instruct the xml-rpc server to open foo.bar.com.zone for > reading. The reason why i was looking at do_Post() and _dispatch was > to attempt to read the incoming params and do exactly that. > > Do you think there is an easier way of accomplishing this, than the > way I am going about it? Yeah. Take a look at the SimpleXLMRPC documentation: http://docs.python.org/library/simplexmlrpcserver.html In addition to setting up the server as instructed (let's assume you assign it to the variable 'server'), you just need to do something like: class MyFunctions: def showRecord(self, dnsname): domain = '.'.join(dnsname.split('.')[1:]) with open(domain+'.zone')) as myfile: # do stuff with data from myfile server.register_instance(MyFunctions()) You would modify the body of that function to meet your processing requirements, of course. That is, SimpleXMLRPCServer does the request parsing for you, calls the correspondingly named method, and passes it the params as method arguments. (This example is taken from the SimpleXMLRPC documentation, I just selected one particular way of exposing the methods: via a class instance). --RDM From steve at holdenweb.com Sat Jan 31 17:29:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 31 Jan 2009 17:29:03 -0500 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: W. eWatson wrote: > Steve Holden wrote: >> W. eWatson wrote: >>> r wrote: >>>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>>> Where in the world is a description of pack() for Tkinter widgets? >>>>> Is it >>>>> some sort of general method for all widgets? I'm looking in a few >>>>> docs that >>>>> use it without ever saying where it is described. For one, >>>>> . In the NM Tech pdf on >>>>> Tkinter, >>>>> it's not found anywhere. I see Universal methods for widgets, but no >>>>> mention >>>>> of pack(). package, packed, but no pack. >>>> did you try here :) >>>> http://effbot.org/tkinterbook/pack.htm >>> Thanks. I have the site bookmarked, but it's hard to search. I posted a >>> comment to them that they should have it in pdf form. >>> >> http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack >> >> regards >> Steve > Well, that's an interesting "link". Another side of Google facilities? > Maybe you're using Snagit or its brethern? However, I'm interested in > searching a pdf, which, of course, doesn't yet exist. > OK, someone asked if you'd seen the HTML pages. You replied that you had them bookmarked but they were difficult to search. So I simply demonstrated that a search of the site for "pack" gave the right page as its first result. Maybe you *do* want a PDF, but it will be less searchable than the existing HTML, so I am somewhat confused about why. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jsmith5616 at yahoo.com Sat Jan 31 18:10:45 2009 From: jsmith5616 at yahoo.com (John Smith) Date: Sat, 31 Jan 2009 15:10:45 -0800 (PST) Subject: Auto Logon to site and get page Message-ID: <456128.62923.qm@web112207.mail.gq1.yahoo.com> I'm trying to automatically log into a site and store the resulting html using python. The site uses a form and encrypts the password with some kind of md5 hash. This is the important parts of the form: This is the function called in md5.js: function doStudentLogin(form) { var pw = form.pw.value; var pw2 = pw; // Save a copy of the password preserving case pw = pw.toLowerCase(); form.pw.value = hex_hmac_md5(pskey, pw); if (form.ldappassword!=null) { // LDAP is enabled, so send the clear-text password // Customers should have SSL enabled if they are using LDAP form.ldappassword.value = pw2; // Send the unmangled password } return true; } ? I am not sure what the ldappassword is or does. Can some one explain that? ? Here's my code : ? from urllib import urlopen, urlencode import re import hmac ? account = 'account' psw = 'my password'' url = "http://ps.pvcsd.org/guardian/home.html" ? homepagetxt = urlopen("http://ps.pvcsd.org").read() ? # get key and pstoken from login page m = re.search(' From thmpsn.m.k at gmail.com Sat Jan 31 18:28:14 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sat, 31 Jan 2009 15:28:14 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: On Jan 31, 2:27?pm, Christian Heimes wrote: > thmpsn.... at gmail.com schrieb: > > > But it's only a faking, and things such as inheritance and > > polymorphism are implemented clumsily (actually I'm not even sure > > about polymorphism). And of course, there are still no private > > members. > > Do you honestly believe that C++'s private members are really private? > Privateness is only enforced during parsing time. Nobody can stop you > from messing around with header files or memory. You can still access > and modify private members but it's all messy and ugly. Even C# and .NET > don't stop you from doing nasty things from unmananged assemblies. I don't know how you would do it in C# (or Java for that matter). In C++ you can play with pointers to "get at" some memory location somewhere in the object. The only portable way to know the exact location between the beginning of the object and the desired member is the offsetof() macro, but as I understand it this only works for POD types, which means that it won't work for classes such as: class NonPOD { private: int a; int b; public: NonPOD(); ~NonPOD(); int C(); }; (I haven't ever actually tried it, so I'm not sure.) Nevertheless, you can play and hope for the best. For example, if the member you want to get at is 'b', then you can do: NonPOD obj; std::cout << "obj.b = " << *(int*) ((unsigned char*) &obj + sizeof (int)) << std::endl; and hope that the compiler didn't leave a hole between the 'a' member and the 'b' member. Getting at the 'a' member would be easier because the first member of a struct/class always has the same memory location as the object itself (although again I'm not sure if this is true for non-POD types as well). So: Sometimes it may work, usually it will be unsafe and/or non- portable, and in most cases the procedure will look complicated. It certainly isn't something I'd try in a real application. However, it WOULD be tempting to access the member if the language allows me to just write: print "obj.b =", obj.b and be done with it. Personally, in Python, I use double underscores for "private" members, so the above would look like: print "obj.b =", obj._NonPOD__b but it's still easier than the C++ example. > Seriously, 'private' and 'protected' are merely tools to stop bad > programmers from doing bad stuff. And the serve as documentation, too. It's not just documentation. For example, suppose you're reading a class definition and see the declaration of a veryInterestingMember and forget that you're not supposed to access it. If you try to access it, the compiler will give you a diagnostic message at compile time. So you can think of it as an error-checking tool as well. > Oh, by the way, the first C++ compilers just converted C++ code to C > code. Such much about "You can't do OOP in C."! More interestingly, though, most compilers translate C and C++ code to assembler first. Does that mean that you can do object-oriented programming, generic programming, and procedural programming in assembler? (Answer: No, but you can probably -- very clumsily -- fake them.) From apt.shansen at gmail.com Sat Jan 31 18:30:48 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 31 Jan 2009 15:30:48 -0800 (PST) Subject: persistent TCP connection in python using socketserver In-Reply-To: <80bc0bfa-f505-49f9-8d5a-f6574e6f8608@z28g2000prd.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 202 bytes Desc: OpenPGP digital signature URL: From robert.kern at gmail.com Sat Jan 31 18:33:34 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 17:33:34 -0600 Subject: nth root In-Reply-To: <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> References: <4983C616.3000207@mrabarnett.plus.com> <1AE19A80523D5F40BE0044A1447A53FF0ADB972C@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: On 2009-01-30 22:00, Tim Roberts wrote: > Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) > > What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? No, but Google would help. -- 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 timr at probo.com Sat Jan 31 19:09:12 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 01 Feb 2009 00:09:12 GMT Subject: nth root References: Message-ID: "Tim Roberts" wrote: > >Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232 >is 3221.2904208350265.... >there must be a quicker way of finding out its between 3221 and 3222.... > >....but perhaps not. Also, remember that the number you computed there is not really the 13th root of 4021503534212915433093809093996098953996019232. When you convert it to float to do the exponentiation, you're losing everything after the 15th significant digit. Of course, if all you're looking for is the nearest integer, that's not very relevant. Do you really need the absolute number? You could take log(x)/13 and work with the log of the results. I suspect (without trying it) that's faster than the exponentiation. >From one Tim Roberts to another. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From andrew at acooke.org Sat Jan 31 19:09:28 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 31 Jan 2009 16:09:28 -0800 (PST) Subject: help me python References: Message-ID: On Jan 31, 5:36?pm, aolsu... at gmail.com wrote: > C:\Python26>vnc.py > Traceback (most recent call last): > ? File "C:\Python26\vnc.py", line 4, in > ? ? import PyD3DES > ImportError: DLL load failed: The specified module could not be found. i'm surprised no-one has replied here. what is happening is that the vnc module is trying to load a library it needs, called PyD3DES (this is a compiled library, a ".dll", not python source). a little googling shows that this is part of the vnc package. so either the vnc package is not installed correctly, or you have a problem with paths. since you are using windows i can't help you in any more detail than that - hope it helps. andrew From rt8396 at gmail.com Sat Jan 31 19:19:13 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 16:19:13 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> Message-ID: <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> On Jan 30, 4:36?pm, Steve Holden wrote: [snip] > It's mostly a matter of teaching by example. I'd like to think I usually > set a good example, but I've certainly been known to get crabby from time > to time Steve you are defiantly the better of two evils around here :D From pxrepreza at gmail.com Sat Jan 31 19:19:49 2009 From: pxrepreza at gmail.com (Paulo Repreza) Date: Sat, 31 Jan 2009 16:19:49 -0800 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' Message-ID: Hi, I'm just learning the very basics of python and I ran into this problem in version 3.0/3000: >>>x = input("x: ") x: 36 >>> y = input("y: ") y: 42 >>> print (x*y) Traceback (most recent call last): File "", line 1, in print (x*y) TypeError: can't multiply sequence by non-int of type 'str' But when I run the same code with Python 2.6.1 it does prints the result. Is there any special function that I should add in order to work properly under Python 3.0? Thanks, Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sat Jan 31 19:25:27 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 18:25:27 -0600 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' In-Reply-To: References: Message-ID: On 2009-01-31 18:19, Paulo Repreza wrote: > Hi, > I'm just learning the very basics of python and I ran into this problem > in version 3.0/3000: > >>>x = input("x: ") > x: 36 > >>> y = input("y: ") > y: 42 > >>> print (x*y) > Traceback (most recent call last): > File "", line 1, in > print (x*y) > TypeError: can't multiply sequence by non-int of type 'str' > But when I run the same code with Python 2.6.1 it does prints the result. In Python 3.0, the 2.x input() function, which evaluates the string, was removed, and the 2.x raw_input() function, which just returns the string that was entered, was renamed to input(). > Is there any special function that I should add in order to work > properly under Python 3.0? x = int(input('x: ')) y = int(input('y: ')) -- 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 pxrepreza at gmail.com Sat Jan 31 19:42:42 2009 From: pxrepreza at gmail.com (Paulo Repreza) Date: Sat, 31 Jan 2009 16:42:42 -0800 Subject: Newbie Question: Can't multiply sequence by non-int of type 'str' In-Reply-To: References: Message-ID: Hi, Thanks for your reply. It worked. Paulo Repreza On Sat, Jan 31, 2009 at 4:25 PM, Robert Kern wrote: > On 2009-01-31 18:19, Paulo Repreza wrote: > >> Hi, >> I'm just learning the very basics of python and I ran into this problem >> in version 3.0/3000: >> >>>x = input("x: ") >> x: 36 >> >>> y = input("y: ") >> y: 42 >> >>> print (x*y) >> Traceback (most recent call last): >> File "", line 1, in >> print (x*y) >> TypeError: can't multiply sequence by non-int of type 'str' >> But when I run the same code with Python 2.6.1 it does prints the result. >> > > In Python 3.0, the 2.x input() function, which evaluates the string, was > removed, and the 2.x raw_input() function, which just returns the string > that was entered, was renamed to input(). > > Is there any special function that I should add in order to work >> properly under Python 3.0? >> > > x = int(input('x: ')) > y = int(input('y: ')) > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sat Jan 31 19:44:44 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 16:44:44 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> <1f1863e7-c803-44fd-ac0d-7fd39db078cf@p23g2000prp.googlegroups.com> <9bf2f0c9-6b30-4bc1-9dc3-c73f4da1f754@a39g2000prl.googlegroups.com> <9f5a0a78-2f5d-4b6c-8f17-8cf5825f500e@w39g2000prb.googlegroups.com> Message-ID: <3ea2fd5b-c3fa-4173-859f-8f95e3564c1b@d32g2000yqe.googlegroups.com> Sorry i gave you the wrong module, try PMIDI for python 2.5 (win32.exe): http://sourceforge.net/project/showfiles.php?group_id=65529&package_id=106729 Also try this page near the bottom under "MIDI Mania" for more http://wiki.python.org/moin/PythonInMusic From greg.ewing at canterbury.ac.nz Sat Jan 31 19:50:57 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 01 Feb 2009 13:50:57 +1300 Subject: Pyggy Awards Judging Underway Message-ID: <6uk9rcFfrh6cU1@mid.individual.net> Judging for the Feb'09 Pyggy Awards has started. All registered users of the PyWeek web site are eligible to rate entries, so even if you haven't submitted an entry, you can still be a judge if you want. And if you're not a PyWeek user, it's not too late to sign up. The entries are here: http://pyggy.pyweek.org/1007/entries/ -- Greg From catphive at catphive.net Sat Jan 31 20:00:05 2009 From: catphive at catphive.net (Brendan Miller) Date: Sat, 31 Jan 2009 17:00:05 -0800 Subject: install modules for specific python version Message-ID: <4984F415.6090902@catphive.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have several version of python running side by side on my ubuntu install (2.5,2.6,3.0). I'm installing a module with a setup.py script, in this case logilab-common, so that I can get pylint going. However, I need to install into python 2.6, but by default it picks out 2.5 and throws things in the site packages for that version. Is there a standard way to specify what version of python you want to install into? I originally installed my other python versions with the altinstall method. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmE9BIACgkQ4eGWG/zYzOmmdgCfbjr3p3wQ8A0TpjeFaPJtmHkx ktQAoI7wONrj5gT4BDclePpwY5kiCy8p =Pg9L -----END PGP SIGNATURE----- From sjmachin at lexicon.net Sat Jan 31 20:24:56 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:24:56 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> Message-ID: <653b8930-6b6c-49ec-bfca-334a30ea48ea@i24g2000prf.googlegroups.com> On Feb 1, 11:19?am, r wrote: > Steve you are defiantly the better of two evils around here :D A most munificent malapropism! Sherman's goat must be serene with entropy!! From sjmachin at lexicon.net Sat Jan 31 20:37:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:37:24 -0800 (PST) Subject: install modules for specific python version References: Message-ID: <3008aa01-5a8e-4edf-98e5-0d062c364a93@l33g2000pri.googlegroups.com> On Feb 1, 12:00?pm, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > I have several version of python running side by side on my ubuntu > install (2.5,2.6,3.0). > > I'm installing a module with a setup.py script, in this case > logilab-common, so that I can get pylint going. However, I need to > install into python 2.6, but by default it picks out 2.5 and throws > things in the site packages for that version. > > Is there a standard way to specify what version of python you want to > install into? Quite generally, if you want to install a module into Python X.Y, use Python X.Y to run the setup.py script. E.g. on Windows I'd do directory-containing-setup.py> c:\python26\python setup.py install Just do the equivalent on ubuntu. Cheers, John From robert.kern at gmail.com Sat Jan 31 20:37:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 19:37:51 -0600 Subject: install modules for specific python version In-Reply-To: <4984F415.6090902@catphive.net> References: <4984F415.6090902@catphive.net> Message-ID: On 2009-01-31 19:00, Brendan Miller wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I have several version of python running side by side on my ubuntu > install (2.5,2.6,3.0). > > I'm installing a module with a setup.py script, in this case > logilab-common, so that I can get pylint going. However, I need to > install into python 2.6, but by default it picks out 2.5 and throws > things in the site packages for that version. > > Is there a standard way to specify what version of python you want to > install into? I originally installed my other python versions with the > altinstall method. Whichever python executable that you used to run the setup.py is the version that the package gets installed to. Most likely, you will want to do something like this: $ python2.6 setup.py install -- 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 sjmachin at lexicon.net Sat Jan 31 20:52:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 17:52:17 -0800 (PST) Subject: help me python References: Message-ID: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> On Feb 1, 11:09?am, andrew cooke wrote: > On Jan 31, 5:36?pm, aolsu... at gmail.com wrote: > > > C:\Python26>vnc.py > > Traceback (most recent call last): > > ? File "C:\Python26\vnc.py", line 4, in > > ? ? import PyD3DES > > ImportError: DLL load failed: The specified module could not be found. > > i'm surprised no-one has replied here. ?what is happening is that the > vnc module is trying to load a library it needs, called PyD3DES (this > is a compiled library, a ".dll", not python source). ?a little > googling shows that this is part of the vnc package. > > so either the vnc package is not installed correctly, or you have a > problem with paths. File "C:\Python26\vnc.py" doesn't look like correct installation to me. My Googling found vnc.py here: http://www.darkc0de.com/others/vnc.py This appears to be a hack/crack site ... should we be helping the OP with this? From gagsl-py2 at yahoo.com.ar Sat Jan 31 20:53:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 31 Jan 2009 23:53:37 -0200 Subject: Import Replacement References: <171e8a410901311123u835ab9egde72586ab0e690b8@mail.gmail.com> <171e8a410901311127h54c999cdldb2fcfd037b8e63c@mail.gmail.com> <4984B31E.7000809@islandtraining.com> Message-ID: En Sat, 31 Jan 2009 18:22:54 -0200, Gary Herron escribi?: > James Pruitt wrote: >> Imagine there are two files horse.py and buffalo.py. horse.py is >> imported by another file rider.py. Is it possible to make it so that >> under certain circumstances possibly based on an environment variable >> or something similar that when rider.py imports horse.py, it actually >> imports buffalo.py sort of like a behind the scenes replacement so >> that rider.py needs little, preferably absolutely no modification? > > If horse and buffalo have the same interface then try something like > this: > > if ...: > import horse as ridable > else: > import buffalo as ridable > # Now use ridable as any module... > > If each defines a class of its own name, but the classes have identical > interfaces, then try > > if ...: > from horse import Horse as Ridable > else: > from buffalo import Buffalo as Ridable > # Then instantiate > animal = Ridable(...) Another alternative, that does not involve changing rider.py, would be to rename horse.py -> _horse.py, buffalo.py -> _buffalo.py and write a *new* horse.py: if ...: from _horse import * else: from _buffalo import * Then, rider.py (and all other modules) still says "import horse", but it will get one or another depending on the condition. -- Gabriel Genellina From jnoller at gmail.com Sat Jan 31 20:54:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Sat, 31 Jan 2009 20:54:39 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: <4222a8490901311754q301900aer4fdf1fb6ab800432@mail.gmail.com> On Sat, Jan 31, 2009 at 4:30 PM, andrew cooke wrote: > On Jan 31, 4:50 pm, "Giampaolo Rodola'" wrote: >> Google Code. >> >> --- Giampaolohttp://code.google.com/p/pyftpdlib > > thanks - that's a nice example. i'm a bit concerned about the whole > google corporation thing, but reading through the ideological check- > sheet at savannah convinced me i wasn't worthy and your project looks > good (i admit i haven't seen that many google projects, but they all > seemed abandoned/bare/hostile). so i'll follow the majority here and > give google code a go. > > cheers, > andrew > -- > http://mail.python.org/mailman/listinfo/python-list > Bitbucket: http://bitbucket.org/ (I use this, move from google code) Github: http://github.com/ Launchapd: https://launchpad.net/ FreeHG: http://freehg.org/ Google is nice due to the groups/mailing list options, but I find I don't miss mailing lists all that much after being subscribed to so many. -jesse From starsareblueandfaraway at gmail.com Sat Jan 31 20:57:36 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Sat, 31 Jan 2009 20:57:36 -0500 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <8630929f-4ff8-4191-be1b-d046fe529e00@35g2000pry.googlegroups.com> Message-ID: <6a5569ec0901311757ge3783b9i4b2738b606fa624b@mail.gmail.com> I really like WebFaction for web-based Python projects. It's a paid web-hosting service, though. What I like is how they always have the most up-to-date Python packages and frameworks using one-click installers. On Sat, Jan 31, 2009 at 4:30 PM, andrew cooke wrote: > On Jan 31, 4:50 pm, "Giampaolo Rodola'" wrote: >> Google Code. >> >> --- Giampaolohttp://code.google.com/p/pyftpdlib > > thanks - that's a nice example. i'm a bit concerned about the whole > google corporation thing, but reading through the ideological check- > sheet at savannah convinced me i wasn't worthy and your project looks > good (i admit i haven't seen that many google projects, but they all > seemed abandoned/bare/hostile). so i'll follow the majority here and > give google code a go. > > cheers, > andrew > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Sat Jan 31 21:00:50 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 18:00:50 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <58ea9634-97e7-4e9e-9beb-80cb86fe463f@z27g2000prd.googlegroups.com> <30f95853-7434-4270-885e-74bf9bcd4360@j39g2000yqn.googlegroups.com> <653b8930-6b6c-49ec-bfca-334a30ea48ea@i24g2000prf.googlegroups.com> Message-ID: <050f006c-4408-4b84-9141-10fec02f9f3b@e10g2000vbe.googlegroups.com> On Jan 31, 7:24?pm, John Machin wrote: > A most munificent malapropism! Sherman's goat must be serene with > entropy!! Who say's George Bush did't have anything to offer :). He was the decider after all. From robert.kern at gmail.com Sat Jan 31 21:01:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Jan 2009 20:01:29 -0600 Subject: help me python In-Reply-To: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> References: <92d2af63-fc6f-4d91-8910-52a4e5d6342c@y1g2000pra.googlegroups.com> Message-ID: On 2009-01-31 19:52, John Machin wrote: > On Feb 1, 11:09 am, andrew cooke wrote: >> On Jan 31, 5:36 pm, aolsu... at gmail.com wrote: >> >>> C:\Python26>vnc.py >>> Traceback (most recent call last): >>> File "C:\Python26\vnc.py", line 4, in >>> import PyD3DES >>> ImportError: DLL load failed: The specified module could not be found. >> i'm surprised no-one has replied here. what is happening is that the >> vnc module is trying to load a library it needs, called PyD3DES (this >> is a compiled library, a ".dll", not python source). a little >> googling shows that this is part of the vnc package. >> >> so either the vnc package is not installed correctly, or you have a >> problem with paths. > > File "C:\Python26\vnc.py" doesn't look like correct installation to > me. > > My Googling found vnc.py here: > http://www.darkc0de.com/others/vnc.py > > This appears to be a hack/crack site ... should we be helping the OP > with this? It's actually just part of PyVNC, a perfectly legitimate VNC client: http://bdash.net.nz/svn/projects/PyVNC/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From torriem at gmail.com Sat Jan 31 21:10:40 2009 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Jan 2009 19:10:40 -0700 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <498504A0.1080107@gmail.com> thmpsn.m.k at gmail.com wrote: > More interestingly, though, most compilers translate C and C++ code to > assembler first. Does that mean that you can do object-oriented > programming, generic programming, and procedural programming in > assembler? > > Answer: No, but you can probably -- very clumsily -- fake them.) This is getting quite far off the topic, but of course you can, and it's not faking anything. This should be obvious. You can certainly do OO programming in C, which is a glorified assembler. For example, the gobject system defines a complete object-oriented system with classes, inheritance, polymorphism, encapuslation. It uses structures for encapsulating the data and call tables for virtual methods (to use a c++ parlance). It's such a well defined object model that you can, with gtkmm, even extend a c-based gobject class with C++! Of course you can also extend gobject-based C classes with python as well using PyBank to import them. Back when assembly was still somewhat in vogue I read a book on programming assembly in an object-oriented manner. So of course you can. Yes it can be clumsy without syntactic sugar. If you set up call tables, you can handle polymorphism. How would this be faking it? By your definition C++ is faking it since C++ compiles to assembly. In the early days, C++ was first implemented as a preprocessor that emitted straight C code. And I guess python fakes it since the python interpreter is implemented in C compiled to ASM. Maybe the terminology would be less confusing if we considered the terms, object-oriented programming, object-oriented languages, object-oriented systems. Any language can be used for the first. Python, Java, C++ can be defined by the second, and things like Python (the runtime environment), .NET, JVM, Parrot, can be defined by the last term. Fair enough? Python is certainly an object-oriented language, and implements a complete object-oriented system. Python can support coding in an object-oriented methodology, or you can code traditionally while still taking advantage of the complete OO system. From v+python at g.nevcal.com Sat Jan 31 21:18:08 2009 From: v+python at g.nevcal.com (Glenn Linderman) Date: Sat, 31 Jan 2009 18:18:08 -0800 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009 In-Reply-To: <497FB2A8.5050105@simplistix.co.uk> References: <497FB2A8.5050105@simplistix.co.uk> Message-ID: <49850660.3070708@g.nevcal.com> On approximately 1/27/2009 5:19 PM, came the following characters from the keyboard of Chris Withers: > Hi All, > > Too many people in the Python community think the only way to work with > Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's PyCon in > Chicago on Wednesday, 25th March that will cover working with Excel > files in Python using the pure-python libraries xlrd, xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > Including formatting, unicode dates and formulae. > > - Writing Excel Files > > Including formatting with easyxf and things like freeze pains, print > areas, etc > > - Filtering Excel Files > > A run through on the structure of xlutils.filter and some examples to > show you how it works. > > - Workshop for your problems > > I'm hoping anyone who attends will get a lot out of this! If you're > planning on attending and have a particular problem you'd like to work > on in this part of the tutorial, please drop me an email and I'll try > and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at PyCon this year: > > http://us.pycon.org > > I look forward to seeing you all there! Good luck with the tutorial. I can't use xlrd because it doesn't support comments. So I use Open Office basic macros to transform the data into a usable form. At least it is way faster than COM, and (although I'm using Windows) I think it could be done on Linux. -- Glenn -- http://nevcal.com/ =========================== A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From excord80 at gmail.com Sat Jan 31 22:47:50 2009 From: excord80 at gmail.com (excord80) Date: Sat, 31 Jan 2009 19:47:50 -0800 (PST) Subject: importlib: what is it, and why is it important? Message-ID: <049bd243-053b-43c6-a368-7be7cae37d0b@p29g2000vbn.googlegroups.com> Regarding this blog post: http://sayspy.blogspot.com/2009/01/importlib-is-now-in-python-31.html When I use the ``import foo`` statement at the top of my program, I get a module imported. python has a search path it follows, finds the module, and makes it available to my program. Works nice. :) So, could someone explain what importlib exactly is, and why this new version that will be in Python 3.1 is significant? Will the import statement work differently in 3.1, and if so, in what way? From benjamin at python.org Sat Jan 31 23:08:24 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 1 Feb 2009 04:08:24 +0000 (UTC) Subject: importlib: what is it, and why is it important? References: <049bd243-053b-43c6-a368-7be7cae37d0b@p29g2000vbn.googlegroups.com> Message-ID: excord80 gmail.com> writes: > > Regarding this blog post: http://sayspy.blogspot.com/2009/01/importlib-is-now-in-python-31.html Brett has made many other blog posts about his work on importlib. You might try examining those. > > So, could someone explain what importlib exactly is, and why this new > version that will be in Python 3.1 is significant? Will the import > statement work differently in 3.1, and if so, in what way? Basically importlib is all of the complicated logic in the import statment written in Python. The point is to make importing more extensible and easier to change. The behavior of the import statement shouldn't be any different or that is a bug. From db3l.net at gmail.com Sat Jan 31 23:33:49 2009 From: db3l.net at gmail.com (David Bolen) Date: Sat, 31 Jan 2009 23:33:49 -0500 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: thmpsn.m.k at gmail.com writes: > I don't know how you would do it in C# (or Java for that matter). > > In C++ you can play with pointers to "get at" some memory location > somewhere in the object. The only portable way to know the exact > location between the beginning of the object and the desired member is > the offsetof() macro, but as I understand it this only works for POD > types, which means that it won't work for classes such as: > > class NonPOD > { > private: > int a; > int b; > public: > NonPOD(); > ~NonPOD(); > int C(); > }; > > (I haven't ever actually tried it, so I'm not sure.) > > Nevertheless, you can play and hope for the best. For example, if the > member you want to get at is 'b', then you can do: > > NonPOD obj; > std::cout << "obj.b = " << *(int*) ((unsigned char*) &obj + sizeof > (int)) << std::endl; > > and hope that the compiler didn't leave a hole between the 'a' member > and the 'b' member. Probably moving off topic, but I don't think you have to get anywhere near that extreme in terms of pointers, unless you're trying to deal with instances for which you have no source but only opaque pointers. I haven't gotten stuck having to do this myself yet, but I believe one commmon "hack" for the sort of class you show above is to just "#define private public" before including the header file containing the class definition. No fiddling with pointers, offsets, or whatever, just normal object access syntax past that point. Of course, I believe such a redefinition violates the letter of the C++ standard, but most preprocessors do it anyway. Also, it won't handle the case where the "private:" is not used, but the members are just declared prior to any other definition, since a class is private by default. But even then, if you had to, just make a copy of the class definition (or heck, just define a structure if it's just data elements), ensure the private portions are public, and then cast a pointer to the old class instance to one of your new class instance. Assuming you're building everything in a single compiler, the layouts should match just fine. Again, normal object member access, no casting or pointers needed (beyond the initial overall object pointer cast). -- David From Shawn at Milochik.com Sat Jan 31 23:39:15 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Sat, 31 Jan 2009 23:39:15 -0500 Subject: Searching a file for multiple strings (PS) In-Reply-To: <4984ADDB.2070509@tim.thechases.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> Message-ID: <2dc0c81b0901312039s46d8541did0f2b846b14a7313@mail.gmail.com> On Sat, Jan 31, 2009 at 3:00 PM, Tim Chase wrote: >>> I'm fairly new with python and am trying to build a fairly simple >>> search script. Ultimately, I'm wanting to search a directory of files >>> for multiple user inputted keywords. I've already written a script >>> that can search for a single string through multiple files, now I just >>> need to adapt it to multiple strings. > Not to discourage the use of Python, but it seems that fgrep with the -f flag already does exactly what you want. If you're on Windows, you can get the Windows version of fgrep here: http://unxutils.sourceforge.net/ Shawn
Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009 Parcel ID: 39-034-15-009